From 0a444e13f6905e08589d0ff19912bcb363f1132e Mon Sep 17 00:00:00 2001 From: Norihiro Watanabe Date: Mon, 4 Apr 2016 06:15:55 +0200 Subject: [PATCH] apply clang-format --- Base/BuildInfo.h | 40 +- Base/CorrectScientificNotationMain.cpp | 2 +- Base/DateTools.cpp | 59 +- Base/DateTools.h | 6 +- Base/FileFinder.h | 19 +- Base/FileTools.cpp | 66 +- Base/Histogram.h | 252 +- Base/MemWatch.cpp | 80 +- Base/MemWatch.h | 20 +- Base/StringTools.cpp | 77 +- Base/StringTools.h | 29 +- Base/binarySearch.cpp | 16 +- Base/binarySearch.h | 27 +- Base/break.cpp | 18 +- Base/break.h | 8 +- Base/display.cpp | 40 +- Base/display.h | 18 +- Base/isnan.h | 8 +- Base/makros.cpp | 4 +- Base/makros.h | 82 +- Base/memory.cpp | 43 +- Base/memory.h | 22 +- Base/printList.h | 5 +- Base/quicksort.h | 25 +- Base/swap.h | 5 +- Base/timer.cpp | 162 +- Base/timer.h | 18 +- Base/uniqueListInsert.h | 6 +- Base/wait.h | 5 +- FEM/BoundaryCondition.cpp | 18 +- FEM/BoundaryCondition.h | 15 +- FEM/CAP_IO.cpp | 1063 +- FEM/CAP_IO.h | 114 +- FEM/Constrained.h | 25 +- FEM/DUMUX.cpp | 792 +- FEM/DUMUX.h | 66 +- FEM/DistributionInfo.cpp | 13 +- FEM/DistributionInfo.h | 6 +- FEM/Eclipse.cpp | 5074 ++--- FEM/Eclipse.h | 140 +- FEM/FEMCondition.cpp | 34 +- FEM/FEMCondition.h | 45 +- FEM/FEMEnums.cpp | 477 +- FEM/FEMEnums.h | 196 +- FEM/GeoInfo.cpp | 49 +- FEM/GeoInfo.h | 14 +- FEM/InitialCondition.cpp | 9 +- FEM/InitialCondition.h | 10 +- FEM/LinearFunctionData.cpp | 28 +- FEM/LinearFunctionData.h | 10 +- FEM/Output.cpp | 2493 ++- FEM/Output.h | 160 +- FEM/OutputTools.h | 57 +- FEM/PhysicalConstant.h | 8 +- FEM/ProcessInfo.cpp | 32 +- FEM/ProcessInfo.h | 35 +- FEM/SourceTerm.cpp | 37 +- FEM/SourceTerm.h | 19 +- FEM/SparseMatrixDOK.cpp | 348 +- FEM/SparseMatrixDOK.h | 79 +- FEM/SplitMPI_Communicator.cpp | 80 +- FEM/Stiff_Bulirsch-Stoer.cpp | 68 +- FEM/Stiff_Bulirsch-Stoer.h | 2 +- FEM/SwitchBC.h | 20 +- FEM/conversion_rate.cpp | 329 +- FEM/conversion_rate.h | 75 +- FEM/eos.cpp | 4287 ++-- FEM/eos.h | 61 +- FEM/equation_class.cpp | 1157 +- FEM/equation_class.h | 102 +- FEM/fct_mpi.cpp | 379 +- FEM/fct_mpi.h | 15 +- FEM/fem_ele.cpp | 1473 +- FEM/fem_ele.h | 177 +- FEM/fem_ele_std.cpp | 9928 +++++---- FEM/fem_ele_std.h | 316 +- FEM/fem_ele_std1.cpp | 134 +- FEM/fem_ele_std_tes.cpp | 660 +- FEM/fem_ele_std_tneq.cpp | 890 +- FEM/fem_ele_vec.cpp | 4966 +++-- FEM/fem_ele_vec.h | 77 +- FEM/femlib.cpp | 232 +- FEM/femlib.h | 51 +- FEM/files0.cpp | 412 +- FEM/files0.h | 118 +- FEM/mathlib.cpp | 1716 +- FEM/mathlib.h | 174 +- FEM/matrix_class.cpp | 891 +- FEM/matrix_class.h | 365 +- FEM/matrix_routines.cpp | 2531 ++- FEM/matrix_routines.h | 44 +- FEM/par_ddc.cpp | 1918 +- FEM/par_ddc.h | 146 +- FEM/pcs_dm.cpp | 1787 +- FEM/pcs_dm.h | 53 +- FEM/problem.cpp | 2494 +-- FEM/problem.h | 161 +- FEM/prototyp.h | 26 +- FEM/rf_REACT_BRNS.cpp | 435 +- FEM/rf_REACT_BRNS.h | 46 +- FEM/rf_REACT_GEM.cpp | 3926 ++-- FEM/rf_REACT_GEM.h | 567 +- FEM/rf_bc_new.cpp | 863 +- FEM/rf_bc_new.h | 154 +- FEM/rf_fct.cpp | 301 +- FEM/rf_fct.h | 15 +- FEM/rf_fluid_momentum.cpp | 609 +- FEM/rf_fluid_momentum.h | 15 +- FEM/rf_ic_new.cpp | 596 +- FEM/rf_ic_new.h | 66 +- FEM/rf_kinreact.cpp | 11093 +++++----- FEM/rf_kinreact.h | 572 +- FEM/rf_mfp_new.cpp | 3134 +-- FEM/rf_mfp_new.h | 150 +- FEM/rf_mmp_new.cpp | 7300 ++++--- FEM/rf_mmp_new.h | 359 +- FEM/rf_msp_new.cpp | 6192 +++--- FEM/rf_msp_new.h | 747 +- FEM/rf_node.cpp | 108 +- FEM/rf_node.h | 81 +- FEM/rf_num_new.cpp | 854 +- FEM/rf_num_new.h | 110 +- FEM/rf_out_new.cpp | 605 +- FEM/rf_out_new.h | 10 +- FEM/rf_pcs.cpp | 17616 ++++++++-------- FEM/rf_pcs.h | 809 +- FEM/rf_pcs1.cpp | 687 +- FEM/rf_random_walk.cpp | 3683 ++-- FEM/rf_random_walk.h | 94 +- FEM/rf_react.cpp | 4114 ++-- FEM/rf_react.h | 107 +- FEM/rf_react_cap.cpp | 4987 +++-- FEM/rf_react_cap.h | 247 +- FEM/rf_react_int.cpp | 4771 +++-- FEM/rf_react_int.h | 225 +- FEM/rf_react_phrq.cpp | 638 +- FEM/rf_react_phrq.h | 42 +- FEM/rf_st_new.cpp | 6610 +++--- FEM/rf_st_new.h | 327 +- FEM/rf_tim_new.cpp | 1441 +- FEM/rf_tim_new.h | 126 +- FEM/rfmat_cp.cpp | 1472 +- FEM/rfmat_cp.h | 87 +- FEM/solver.cpp | 1183 +- FEM/solver.h | 78 +- FEM/tools.cpp | 392 +- FEM/tools.h | 103 +- FEM/vtk.cpp | 1437 +- FEM/vtk.h | 120 +- FileIO/FEMIO/BoundaryConditionIO.cpp | 30 +- FileIO/FEMIO/BoundaryConditionIO.h | 8 +- FileIO/FEMIO/GeoIO.cpp | 28 +- FileIO/FEMIO/GeoIO.h | 10 +- FileIO/FEMIO/ProcessIO.cpp | 4 +- FileIO/FEMIO/ProcessIO.h | 2 +- FileIO/MathIO/CRSIO.h | 56 +- FileIO/MeshIO/LegacyVtkInterface.cpp | 1008 +- FileIO/MeshIO/LegacyVtkInterface.h | 16 +- FileIO/MeshIO/OGSMeshIO.cpp | 96 +- FileIO/MeshIO/OGSMeshIO.h | 6 +- FileIO/OGSIOVer4.cpp | 701 +- FileIO/OGSIOVer4.h | 11 +- FileIO/Reader.cpp | 3 - FileIO/Reader.h | 3 +- FileIO/StationIO.cpp | 30 +- FileIO/StationIO.h | 7 +- FileIO/Writer.cpp | 6 +- FileIO/Writer.h | 4 +- FileIO/XmlIO/RapidXMLInterface.cpp | 203 +- FileIO/XmlIO/RapidXMLInterface.h | 17 +- FileIO/readNonBlankLineFromInputStream.cpp | 8 +- FileIO/readNonBlankLineFromInputStream.h | 2 +- GCC/Density.cpp | 606 +- GCC/Density.h | 26 +- GCC/DiffAL.h | 66 +- GCC/DiffOH.cpp | 24 +- GCC/DiffOH.h | 50 +- GCC/HKF.cpp | 964 +- GCC/HKF.h | 75 +- GCC/IAPWS-IF97.cpp | 511 +- GCC/IAPWS-IF97.h | 24 +- GCC/IO.cpp | 605 +- GCC/IO.h | 10 +- GCC/NR.cpp | 21 +- GCC/NR.h | 9 +- GCC/PITZdata.cpp | 139 +- GCC/PITZdata.h | 7 +- GCC/VLE.cpp | 1005 +- GCC/VLE.h | 49 +- GCC/WATEQdata.h | 56 +- GCC/eqbrm.h | 64 +- GCC/logk.cpp | 198 +- GCC/logk.h | 14 +- GCC/species.h | 193 +- GEO/AxisAlignedBoundingBox.cpp | 52 +- GEO/AxisAlignedBoundingBox.h | 28 +- GEO/BruteForceClosestPair.cpp | 11 +- GEO/BruteForceClosestPair.h | 2 +- GEO/ClosestPair.h | 7 +- GEO/Color.cpp | 19 +- GEO/Color.h | 6 +- GEO/GEOObjects.cpp | 342 +- GEO/GEOObjects.h | 82 +- GEO/GeoType.cpp | 16 +- GEO/GeoType.h | 7 +- GEO/Grid.h | 331 +- GEO/OctTree.h | 167 +- GEO/Point.cpp | 14 +- GEO/Point.h | 8 +- GEO/PointVec.cpp | 175 +- GEO/PointVec.h | 45 +- GEO/PointWithID.h | 18 +- GEO/Polygon.cpp | 446 +- GEO/Polygon.h | 49 +- GEO/Polyline.cpp | 180 +- GEO/Polyline.h | 33 +- GEO/PolylineWithSegmentMarker.cpp | 16 +- GEO/PolylineWithSegmentMarker.h | 8 +- GEO/ProjectData.cpp | 90 +- GEO/ProjectData.h | 31 +- GEO/PropertyBounds.h | 8 +- GEO/QuadTree.h | 264 +- GEO/Raster.cpp | 30 +- GEO/Raster.h | 5 +- GEO/SensorData.cpp | 122 +- GEO/SensorData.h | 33 +- GEO/SimplePolygonTree.cpp | 53 +- GEO/SimplePolygonTree.h | 33 +- GEO/Station.cpp | 153 +- GEO/Station.h | 172 +- GEO/Surface.cpp | 69 +- GEO/Surface.h | 23 +- GEO/SurfaceGrid.cpp | 271 +- GEO/SurfaceGrid.h | 14 +- GEO/TemplatePoint.h | 81 +- GEO/TemplateVec.h | 82 +- GEO/Triangle.cpp | 102 +- GEO/Triangle.h | 48 +- GEO/geo_dom.cpp | 36 +- GEO/geo_dom.h | 11 +- GEO/geo_lib.cpp | 451 +- GEO/geo_lib.h | 16 +- GEO/geo_lin.cpp | 16 +- GEO/geo_lin.h | 12 +- GEO/geo_mathlib.cpp | 217 +- GEO/geo_mathlib.h | 38 +- GEO/geo_ply.cpp | 314 +- GEO/geo_ply.h | 128 +- GEO/geo_pnt.cpp | 359 +- GEO/geo_pnt.h | 114 +- GEO/geo_sfc.cpp | 728 +- GEO/geo_sfc.h | 105 +- GEO/geo_vol.cpp | 287 +- GEO/geo_vol.h | 28 +- MSH/GridAdapter.cpp | 74 +- MSH/GridAdapter.h | 20 +- MSH/MSHEnums.cpp | 8 +- MSH/MSHEnums.h | 10 +- MSH/MeshNodesAlongPolyline.cpp | 76 +- MSH/MeshNodesAlongPolyline.h | 11 +- MSH/MshEditor.cpp | 140 +- MSH/MshEditor.h | 19 +- MSH/msh_core.cpp | 8 +- MSH/msh_core.h | 51 +- MSH/msh_edge.cpp | 39 +- MSH/msh_edge.h | 53 +- MSH/msh_elem.cpp | 1703 +- MSH/msh_elem.h | 224 +- MSH/msh_faces.cpp | 160 +- MSH/msh_faces.h | 43 +- MSH/msh_lib.cpp | 863 +- MSH/msh_lib.h | 93 +- MSH/msh_lib_ext.cpp | 1538 +- MSH/msh_mesh.cpp | 2180 +- MSH/msh_mesh.h | 312 +- MSH/msh_node.cpp | 42 +- MSH/msh_node.h | 131 +- MSH/msh_pnt.cpp | 20 +- MSHGEOTOOLS/ExtractMeshNodes.cpp | 340 +- MSHGEOTOOLS/ExtractMeshNodes.h | 50 +- MathLib/AnalyticalGeometry.cpp | 223 +- MathLib/AnalyticalGeometry.h | 37 +- MathLib/EarClippingTriangulation.cpp | 121 +- MathLib/EarClippingTriangulation.h | 17 +- .../InterpolationAlgorithms/CubicSpline.cpp | 31 +- MathLib/InterpolationAlgorithms/CubicSpline.h | 2 +- .../InverseDistanceInterpolation.h | 71 +- .../LinearIntervalInterpolation.h | 22 +- .../PiecewiseLinearInterpolation.cpp | 56 +- .../PiecewiseLinearInterpolation.h | 10 +- MathLib/LinAlg/GaussAlgorithm.cpp | 29 +- MathLib/LinAlg/GaussAlgorithm.h | 54 +- MathLib/LinAlg/TriangularSolve.cpp | 20 +- MathLib/LinAlg/TriangularSolve.h | 29 +- MathLib/LinAlg/VectorNorms.h | 4 +- MathLib/LinkedTriangle.cpp | 25 +- MathLib/LinkedTriangle.h | 23 +- MathLib/MathTools.cpp | 23 +- MathLib/MathTools.h | 23 +- MathLib/Matrix.h | 157 +- MathLib/PETSC/PETScLinearSolver.cpp | 605 +- MathLib/PETSC/PETScLinearSolver.h | 210 +- MathLib/Vector3.h | 104 +- MathLib/max.h | 3 +- OGS/ogs_display.cpp | 6 +- OGS/ogs_display.h | 4 +- OGS/rf.cpp | 213 +- UTL/GIS2FEM/main.cpp | 184 +- UTL/GIS2FEM/misc.cpp | 36 +- UTL/GIS2FEM/misc.h | 6 +- UTL/MSHGEOTOOLS/ModifyMeshProperties.cpp | 161 +- UTL/MSHGEOTOOLS/ModifyMeshProperties.h | 4 +- UTL/MSHGEOTOOLS/filterMeshNodes.cpp | 103 +- ...mainConvertGLIVerticalSurfaceToPolygon.cpp | 43 +- UTL/MSHGEOTOOLS/mainExtractMeshNodeIDs.cpp | 203 +- UTL/MSHGEOTOOLS/mainExtractMeshNodes.cpp | 33 +- UTL/MSHGEOTOOLS/mainModifyMeshProperties.cpp | 81 +- UTL/MSHGEOTOOLS/testMeshSearchAlgorithms.cpp | 309 +- UTL/benchtimer.cpp | 37 +- UTL/benchtimer.h | 2 - UTL/tokenbuf.cpp | 94 +- UTL/tokenbuf.h | 11 +- tests/GEO/TestPointInPolygon.cpp | 29 +- tests/GEO/TestPointInTriangle.cpp | 26 +- tests/Matrix/testMatrix.cpp | 317 +- tests/logging.h | 12 +- tests/testBase.cpp | 23 +- tests/testGeo.cpp | 29 +- tests/testrunner.cpp | 4 +- 329 files changed, 83337 insertions(+), 83568 deletions(-) mode change 100755 => 100644 Base/timer.cpp mode change 100755 => 100644 FEM/CAP_IO.cpp mode change 100755 => 100644 FEM/Stiff_Bulirsch-Stoer.h mode change 100755 => 100644 FEM/fem_ele.cpp mode change 100755 => 100644 FEM/fem_ele_vec.cpp mode change 100755 => 100644 FEM/fem_ele_vec.h mode change 100755 => 100644 FEM/matrix_class.h mode change 100755 => 100644 FEM/pcs_dm.cpp mode change 100755 => 100644 FEM/problem.h mode change 100755 => 100644 FEM/rf_pcs1.cpp mode change 100755 => 100644 FileIO/FEMIO/BoundaryConditionIO.cpp mode change 100755 => 100644 GEO/ProjectData.cpp mode change 100755 => 100644 MSH/MeshNodesAlongPolyline.cpp mode change 100755 => 100644 MSH/MeshNodesAlongPolyline.h mode change 100755 => 100644 MSH/msh_elem.cpp mode change 100755 => 100644 MSH/msh_lib.h mode change 100755 => 100644 MSH/msh_lib_ext.cpp mode change 100755 => 100644 OGS/rf.cpp diff --git a/Base/BuildInfo.h b/Base/BuildInfo.h index 9e84338a6..fc3e701ae 100644 --- a/Base/BuildInfo.h +++ b/Base/BuildInfo.h @@ -11,27 +11,27 @@ namespace BuildInfo { - extern const std::string GIT_COMMIT_INFO; - extern const std::string GIT_BRANCH_INFO; - extern const std::string BUILD_TIMESTAMP; - extern const std::string CMAKE_SYSTEM; - extern const std::string CMAKE_SYSTEM_PROCESSOR; - extern const std::string CMAKE_CXX_COMPILER; - extern const std::string GCC_VERSION; - extern const std::string CMAKE_GENERATOR; - extern const std::string CMAKE_BUILD_TYPE; - extern const std::string CMAKE_CXX_FLAGS; - extern const std::string CMAKE_CXX_FLAGS_RELEASE; - extern const std::string CMAKE_CXX_FLAGS_DEBUG; - extern const std::string SOLVER_PACKAGE_NAME; +extern const std::string GIT_COMMIT_INFO; +extern const std::string GIT_BRANCH_INFO; +extern const std::string BUILD_TIMESTAMP; +extern const std::string CMAKE_SYSTEM; +extern const std::string CMAKE_SYSTEM_PROCESSOR; +extern const std::string CMAKE_CXX_COMPILER; +extern const std::string GCC_VERSION; +extern const std::string CMAKE_GENERATOR; +extern const std::string CMAKE_BUILD_TYPE; +extern const std::string CMAKE_CXX_FLAGS; +extern const std::string CMAKE_CXX_FLAGS_RELEASE; +extern const std::string CMAKE_CXX_FLAGS_DEBUG; +extern const std::string SOLVER_PACKAGE_NAME; - extern const std::string SOURCEPATH; - extern const std::string BUILDPATH; - extern const std::string TESTDATAPATH; - extern const std::string OGS_VERSION; - extern const std::string OGS_DATE; - extern const std::string OGS_EXECUTABLE; - extern const std::string PUT_TMP_DIR_IN; +extern const std::string SOURCEPATH; +extern const std::string BUILDPATH; +extern const std::string TESTDATAPATH; +extern const std::string OGS_VERSION; +extern const std::string OGS_DATE; +extern const std::string OGS_EXECUTABLE; +extern const std::string PUT_TMP_DIR_IN; } #endif // BUILDINFO_H diff --git a/Base/CorrectScientificNotationMain.cpp b/Base/CorrectScientificNotationMain.cpp index ff92bca4e..4deddd369 100644 --- a/Base/CorrectScientificNotationMain.cpp +++ b/Base/CorrectScientificNotationMain.cpp @@ -9,7 +9,7 @@ */ #include "StringTools.h" -int main( int argc, const char* argv[] ) +int main(int argc, const char* argv[]) { if (argc < 2) { diff --git a/Base/DateTools.cpp b/Base/DateTools.cpp index 8f91be7fc..1265d306e 100644 --- a/Base/DateTools.cpp +++ b/Base/DateTools.cpp @@ -18,9 +18,10 @@ int date2int(int y, int m, int d) { - if ( (y < 1000 || y > 9999) || (m < 1 || m > 12) || (d < 1 || d > 31) ) + if ((y < 1000 || y > 9999) || (m < 1 || m > 12) || (d < 1 || d > 31)) { - std::cout << "Error: date2double() -- input not in expected format." << "\n"; + std::cout << "Error: date2double() -- input not in expected format." + << "\n"; return 0; } @@ -34,16 +35,16 @@ int date2int(int y, int m, int d) std::string int2date(int date) { - if (date>10000000 && date<22000000) + if (date > 10000000 && date < 22000000) { - int y = static_cast(floor(date/10000.0)); - int m = static_cast(floor((date-(y*10000))/100.0)); - int d = date-(y*10000)-(m*100); + int y = static_cast(floor(date / 10000.0)); + int m = static_cast(floor((date - (y * 10000)) / 100.0)); + int d = date - (y * 10000) - (m * 100); std::stringstream ss; - if (d<10) + if (d < 10) ss << "0"; ss << d << "."; - if (m<10) + if (m < 10) ss << "0"; ss << m << "." << y; return ss.str(); @@ -55,20 +56,23 @@ std::string date2string(double ddate) { if (ddate < 10000101 || ddate > 99991231) { - std::cout << "Error: date2String() -- input not in expected format." << "\n"; + std::cout << "Error: date2String() -- input not in expected format." + << "\n"; return "0.0.0000"; } - int rest (static_cast(ddate)); + int rest(static_cast(ddate)); int y = static_cast(floor(rest / 10000.0)); rest = rest % (y * 10000); int m = static_cast(floor(rest / 100.0)); if (m < 1 || m > 12) - std::cout << "Warning: date2String() -- month not in [1:12]" << "\n"; + std::cout << "Warning: date2String() -- month not in [1:12]" + << "\n"; rest = rest % (m * 100); int d = rest; if (d < 1 || d > 31) - std::cout << "Warning: date2String() -- day not in [1:31]" << "\n"; + std::cout << "Warning: date2String() -- day not in [1:31]" + << "\n"; std::string day = number2str(d); if (d < 10) @@ -76,35 +80,36 @@ std::string date2string(double ddate) std::string month = number2str(m); if (m < 10) month = "0" + month; - std::string s = number2str(y) + "-" + month + "-" + day; + std::string s = number2str(y) + "-" + month + "-" + day; return s; } -int strDate2int(const std::string &s) +int strDate2int(const std::string& s) { std::string str(s); if (s.length() > 10) - str = s.substr(0,10); - size_t sep ( str.find(".",0) ); - int d ( atoi(str.substr(0, sep).c_str()) ); - size_t sep2 ( str.find(".", sep + 1) ); - int m ( atoi(str.substr(sep + 1,sep2 - (sep + 1)).c_str()) ); - int y ( atoi(str.substr(sep2 + 1, s.length() - (sep2 + 1)).c_str()) ); + str = s.substr(0, 10); + size_t sep(str.find(".", 0)); + int d(atoi(str.substr(0, sep).c_str())); + size_t sep2(str.find(".", sep + 1)); + int m(atoi(str.substr(sep + 1, sep2 - (sep + 1)).c_str())); + int y(atoi(str.substr(sep2 + 1, s.length() - (sep2 + 1)).c_str())); return date2int(y, m, d); } -int xmlDate2int(const std::string &s) +int xmlDate2int(const std::string& s) { if (s.length() == 10) { - int d = atoi(s.substr(8,2).c_str()); + int d = atoi(s.substr(8, 2).c_str()); if (d < 1 || d > 31) - std::cout << "Warning: xmlDate2double() -- day not in [1:31]" << "\n"; - int m = atoi(s.substr(5,2).c_str()); + std::cout << "Warning: xmlDate2double() -- day not in [1:31]" + << "\n"; + int m = atoi(s.substr(5, 2).c_str()); if (m < 1 || m > 12) - std::cout << "Warning: xmlDate2double() -- month not in [1:12]" << - "\n"; - int y = atoi(s.substr(0,4).c_str()); + std::cout << "Warning: xmlDate2double() -- month not in [1:12]" + << "\n"; + int y = atoi(s.substr(0, 4).c_str()); return date2int(y, m, d); } return 0; diff --git a/Base/DateTools.h b/Base/DateTools.h index f3beb9814..f0f3490c4 100644 --- a/Base/DateTools.h +++ b/Base/DateTools.h @@ -40,7 +40,7 @@ std::string date2string(double ddate); * \param s String containing the date, the expected format is "dd.mm.yyyy". * \return A number representing the date as dd.mm.yyyy. */ -int strDate2int(const std::string &s); +int strDate2int(const std::string& s); /** * Converts a string containing a date into a double. @@ -48,6 +48,6 @@ int strDate2int(const std::string &s); * \param s String containing the date, the expected format is conform to the xml date type, i.e. "yyyy-mm-dd". * \return A number representing the date as yyyymmdd. */ -int xmlDate2int(const std::string &s); +int xmlDate2int(const std::string& s); -#endif //DATETOOLS_H +#endif // DATETOOLS_H diff --git a/Base/FileFinder.h b/Base/FileFinder.h index a18cd7d0d..fbb6c4e07 100644 --- a/Base/FileFinder.h +++ b/Base/FileFinder.h @@ -26,14 +26,14 @@ class FileFinder public: /// Constructor FileFinder() {} - /** * \brief Adds another directory to the search-space. * If the given directory does not end with a slash one will be appended. */ void addDirectory(std::string dir) { - if (dir[dir.size() - 1] != '/') dir.append("/"); + if (dir[dir.size() - 1] != '/') + dir.append("/"); _directories.push_back(dir); } @@ -44,21 +44,22 @@ class FileFinder */ std::string getPath(std::string filename) { - if (_directories.empty()) std::cout << - "Error: FileFinder::getPath() -- directory list is empty." << "\n"; - for (std::list::iterator it = _directories.begin(); - it != _directories.end(); ++it) + if (_directories.empty()) + std::cout << "Error: FileFinder::getPath() -- directory list is empty." + << "\n"; + for (std::list::iterator it = _directories.begin(); it != _directories.end(); ++it) { std::string testDir(*it); std::ifstream is(testDir.append(filename).c_str()); - if (is.good()) return testDir; + if (is.good()) + return testDir; } - std::cout << "Error: FileFinder::getPath() -- file not found." << "\n"; + std::cout << "Error: FileFinder::getPath() -- file not found." + << "\n"; return filename; } private: - std::list _directories; }; #endif // FILEFINDER_H diff --git a/Base/FileTools.cpp b/Base/FileTools.cpp index 789c0c8ec..7fe74b9b5 100644 --- a/Base/FileTools.cpp +++ b/Base/FileTools.cpp @@ -25,7 +25,6 @@ #include #endif - /** * Returns true if given file exists. From http://www.techbytes.ca/techbyte103.html */ @@ -36,9 +35,9 @@ bool IsFileExisting(std::string const& strFilename) int intStat; // Attempt to get the file attributes - intStat = stat(strFilename.c_str(),&stFileInfo); + intStat = stat(strFilename.c_str(), &stFileInfo); - if(intStat == 0) + if (intStat == 0) // We were able to get the file attributes // so the file obviously exists. blnReturn = true; @@ -57,20 +56,24 @@ bool IsFileExisting(std::string const& strFilename) bool HasCRInLineEnding(std::string const& strFilename) { std::ifstream is(strFilename.c_str(), std::ios::in | std::ios::binary); - if (!is) { + if (!is) + { std::cout << "*** error: could not open " << strFilename.data() << std::endl; return false; } bool foundCR = false; - while (is.good()) { + while (is.good()) + { char c; is.read(&c, sizeof(c)); - if (c == '\r') { + if (c == '\r') + { foundCR = true; break; } - else if (c == EOF || c == '\n') { + else if (c == EOF || c == '\n') + { break; } } @@ -80,21 +83,21 @@ bool HasCRInLineEnding(std::string const& strFilename) return foundCR; } - inline char getDirSep() { #ifdef WIN32 - return '\\'; + return '\\'; #else - return '/'; + return '/'; #endif } - std::string pathJoin(const std::string& path1, const std::string& path2) { - if (path1.empty()) return path2; - if (path2.empty()) return path1; + if (path1.empty()) + return path2; + if (path2.empty()) + return path1; const char dirSep = getDirSep(); @@ -103,50 +106,57 @@ std::string pathJoin(const std::string& path1, const std::string& path2) return s; } - std::string pathBasename(const std::string& path) { - if (path.empty()) return ""; + if (path.empty()) + return ""; const char dirSep = getDirSep(); const std::string p = rtrim(path, dirSep); const size_t idx = p.find_last_of(dirSep); - if (idx == std::string::npos) { + if (idx == std::string::npos) + { return path; // no dirSep in path - } else { - return p.substr(idx+1); + } + else + { + return p.substr(idx + 1); } } - std::string pathDirname(const std::string& path) { - if (path.empty()) return "."; + if (path.empty()) + return "."; const char dirSep = getDirSep(); const std::string p = rtrim(path, dirSep); const size_t idx = p.find_last_of(dirSep); - if (idx == std::string::npos) { + if (idx == std::string::npos) + { return "."; // no dirSep in path - } else if (idx == 0) { + } + else if (idx == 0) + { return std::string(1, dirSep); // only one dirSep at the beginning of path - } else { + } + else + { return p.substr(0, idx); } } - std::string getCwd() { - char cwd[FILENAME_MAX]; + char cwd[FILENAME_MAX]; #ifdef WIN32 - _getcwd(cwd, FILENAME_MAX); + _getcwd(cwd, FILENAME_MAX); #else - getcwd(cwd, FILENAME_MAX); + getcwd(cwd, FILENAME_MAX); #endif - return cwd; + return cwd; } diff --git a/Base/Histogram.h b/Base/Histogram.h index a2513a4d4..e6cd42b21 100644 --- a/Base/Histogram.h +++ b/Base/Histogram.h @@ -21,7 +21,6 @@ namespace BASELIB { - /** Basic Histogram implementation. * * Creates histogram from input data of type \c T. @@ -29,122 +28,125 @@ namespace BASELIB template class Histogram { - public: - typedef typename std::vector Data; ///< Underlying input data vector - /// type. - - public: - /** Creates histogram of the given element in the range \c [first, last). - * - * Input data is copied into \c std::vector. - * - * \param data Range of elements to create histogram from. - * \param nr_bins Number of bins in histogram. - * \param computeHistogram Compute histogram if set. If not set user must - * call \c update() before accessing data. - */ - template - Histogram(InputIterator first, InputIterator last, const int nr_bins = 16, - const bool computeHistogram = true ) - : _data(first, last), _nr_bins(nr_bins) - { - std::sort(_data.begin(), _data.end()); - _histogram.resize(_nr_bins); - _min = _data.front(); - _max = _data.back(); - _bin_width = (_max - _min)/_nr_bins; - - _dirty = true; - if (computeHistogram) - update(); - } - - /** Creates histogram from \c std::vector. - * \param data Input vector. - * \param nr_bins Number of bins in histogram. - * \param computeHistogram Compute histogram if set. If not set user must call - * \c update() before accessing data. - */ - Histogram(std::vector const& data, const unsigned int nr_bins = 16, - const bool computeHistogram = true) - : _data(data), _nr_bins(nr_bins) - { - std::sort(_data.begin(), _data.end()); - _histogram.resize(_nr_bins); - _min = _data.front(); - _max = _data.back(); - _bin_width = (_max - _min)/_nr_bins; - - _dirty = true; - if (computeHistogram) - update(); - } - - /** Updates histogram using sorted \c _data vector. - * - * Start histogram creation with first element. Then find first element in - * the next histogram bin. Number of elments in the bin is the difference - * between these two iterators. - * \verbatim - [0.1, 0.2, ..., 0.7 , ..., 0.7+binWidth = 0.9, 1.0 , ..., last] - it itEnd - 1 itEnd - \endverbatim - */ - void - update() - { - if (!_dirty) - return; - - _bin_width = (_max - _min)/_nr_bins; - - typedef typename Data::const_iterator DataCI; - DataCI it = _data.begin(); - DataCI itEnd; - for (unsigned int bin = 0; bin < _nr_bins; bin++) { - itEnd = std::upper_bound(it, (DataCI)_data.end(), - _min + (bin + 1) * _bin_width); - _histogram[bin] = std::distance(it, itEnd); - it = itEnd; - } - _dirty = false; - } - - void setMinimum(const T& minimum) { _min = minimum; _dirty = true; } - void setMaximum(const T& maximum) { _max = maximum; _dirty = true; } - - const Data& getSortedData() const { return _data; } - const std::vector& getBinCounts() const { return _histogram; } - const unsigned int& getNrBins() const { return _nr_bins; } - const T& getMinimum() const { return _min; } - const T& getMaximum() const { return _max; } - const T& getBinWidth() const { return _bin_width; } - - void - prettyPrint(std::ostream& os, const unsigned int line_width = 16) const - { - const size_t count_max = *std::max_element(_histogram.begin(), _histogram.end()); - for (unsigned int bin = 0; bin < _nr_bins; ++bin) { - os << "[" << _min + bin * _bin_width << ", " << _min + (bin + 1) * _bin_width << ")\t"; - os << _histogram[bin] << "\t"; - - const int n_stars = std::ceil(line_width * ((double)_histogram[bin]/count_max)); - for (int star = 0; star < n_stars; star++) - os << "*"; - os << "\n"; - } - } - - protected: - Data _data; - const unsigned int _nr_bins; - std::vector _histogram; - T _min, _max; ///< Minimum and maximum input data values. - T _bin_width; - - private: - bool _dirty; ///< When set \c update() will recompute histogram. - +public: + typedef typename std::vector Data; ///< Underlying input data vector + /// type. + +public: + /** Creates histogram of the given element in the range \c [first, last). + * + * Input data is copied into \c std::vector. + * + * \param data Range of elements to create histogram from. + * \param nr_bins Number of bins in histogram. + * \param computeHistogram Compute histogram if set. If not set user must + * call \c update() before accessing data. + */ + template + Histogram(InputIterator first, InputIterator last, const int nr_bins = 16, const bool computeHistogram = true) + : _data(first, last), _nr_bins(nr_bins) + { + std::sort(_data.begin(), _data.end()); + _histogram.resize(_nr_bins); + _min = _data.front(); + _max = _data.back(); + _bin_width = (_max - _min) / _nr_bins; + + _dirty = true; + if (computeHistogram) + update(); + } + + /** Creates histogram from \c std::vector. + * \param data Input vector. + * \param nr_bins Number of bins in histogram. + * \param computeHistogram Compute histogram if set. If not set user must call + * \c update() before accessing data. + */ + Histogram(std::vector const& data, const unsigned int nr_bins = 16, const bool computeHistogram = true) + : _data(data), _nr_bins(nr_bins) + { + std::sort(_data.begin(), _data.end()); + _histogram.resize(_nr_bins); + _min = _data.front(); + _max = _data.back(); + _bin_width = (_max - _min) / _nr_bins; + + _dirty = true; + if (computeHistogram) + update(); + } + + /** Updates histogram using sorted \c _data vector. + * + * Start histogram creation with first element. Then find first element in + * the next histogram bin. Number of elments in the bin is the difference + * between these two iterators. + * \verbatim + [0.1, 0.2, ..., 0.7 , ..., 0.7+binWidth = 0.9, 1.0 , ..., last] + it itEnd - 1 itEnd + \endverbatim + */ + void update() + { + if (!_dirty) + return; + + _bin_width = (_max - _min) / _nr_bins; + + typedef typename Data::const_iterator DataCI; + DataCI it = _data.begin(); + DataCI itEnd; + for (unsigned int bin = 0; bin < _nr_bins; bin++) + { + itEnd = std::upper_bound(it, (DataCI)_data.end(), _min + (bin + 1) * _bin_width); + _histogram[bin] = std::distance(it, itEnd); + it = itEnd; + } + _dirty = false; + } + + void setMinimum(const T& minimum) + { + _min = minimum; + _dirty = true; + } + void setMaximum(const T& maximum) + { + _max = maximum; + _dirty = true; + } + + const Data& getSortedData() const { return _data; } + const std::vector& getBinCounts() const { return _histogram; } + const unsigned int& getNrBins() const { return _nr_bins; } + const T& getMinimum() const { return _min; } + const T& getMaximum() const { return _max; } + const T& getBinWidth() const { return _bin_width; } + void prettyPrint(std::ostream& os, const unsigned int line_width = 16) const + { + const size_t count_max = *std::max_element(_histogram.begin(), _histogram.end()); + for (unsigned int bin = 0; bin < _nr_bins; ++bin) + { + os << "[" << _min + bin * _bin_width << ", " << _min + (bin + 1) * _bin_width << ")\t"; + os << _histogram[bin] << "\t"; + + const int n_stars = std::ceil(line_width * ((double)_histogram[bin] / count_max)); + for (int star = 0; star < n_stars; star++) + os << "*"; + os << "\n"; + } + } + +protected: + Data _data; + const unsigned int _nr_bins; + std::vector _histogram; + T _min, _max; ///< Minimum and maximum input data values. + T _bin_width; + +private: + bool _dirty; ///< When set \c update() will recompute histogram. }; /** Writes histogram to output stream. @@ -153,17 +155,13 @@ class Histogram * number of bins, minimum, maximum, bin0 count, ..., binN-1 count. */ template -std::ostream& -operator<<(std::ostream& os, const Histogram& h) +std::ostream& operator<<(std::ostream& os, const Histogram& h) { - os << h.getNrBins() << " " - << h.getMinimum() << " " - << h.getMaximum() << " "; - std::copy(h.getBinCounts().begin(), h.getBinCounts().end(), - std::ostream_iterator(os, " ")); - return os << std::endl; + os << h.getNrBins() << " " << h.getMinimum() << " " << h.getMaximum() << " "; + std::copy(h.getBinCounts().begin(), h.getBinCounts().end(), std::ostream_iterator(os, " ")); + return os << std::endl; } -} // namespace BASELIB +} // namespace BASELIB -#endif // BASELIB_HISTOGRAM_H +#endif // BASELIB_HISTOGRAM_H diff --git a/Base/MemWatch.cpp b/Base/MemWatch.cpp index 3abb0c92f..e66104428 100644 --- a/Base/MemWatch.cpp +++ b/Base/MemWatch.cpp @@ -14,59 +14,63 @@ #ifndef WIN32 -namespace BaseLib { - -MemWatch::MemWatch () +namespace BaseLib +{ +MemWatch::MemWatch() { - updateMemUsage (); + updateMemUsage(); } -unsigned MemWatch::updateMemUsage () +unsigned MemWatch::updateMemUsage() { - std::string fname ("/proc/"); - std::stringstream str_pid; - str_pid << (unsigned) getpid(); - fname += str_pid.str(); - fname += "/statm"; - unsigned pages; + std::string fname("/proc/"); + std::stringstream str_pid; + str_pid << (unsigned)getpid(); + fname += str_pid.str(); + fname += "/statm"; + unsigned pages; - std::ifstream in (fname.c_str(), std::ios::in); - if (in == NULL) { - perror( "open" ); - return 1; - } + std::ifstream in(fname.c_str(), std::ios::in); + if (in == NULL) + { + perror("open"); + return 1; + } - in >> pages; - _vmem_size = ((unsigned long) pages) * ((unsigned long) getpagesize()); - in >> pages; - _rmem_size = ((unsigned long) pages) * ((unsigned long) getpagesize()); - in >> pages; - _smem_size = ((unsigned long) pages) * ((unsigned long) getpagesize()); - in >> pages; - _cmem_size = ((unsigned long) pages) * ((unsigned long) getpagesize()); - in.close (); - return 0; + in >> pages; + _vmem_size = ((unsigned long)pages) * ((unsigned long)getpagesize()); + in >> pages; + _rmem_size = ((unsigned long)pages) * ((unsigned long)getpagesize()); + in >> pages; + _smem_size = ((unsigned long)pages) * ((unsigned long)getpagesize()); + in >> pages; + _cmem_size = ((unsigned long)pages) * ((unsigned long)getpagesize()); + in.close(); + return 0; } -unsigned long MemWatch::getVirtMemUsage () +unsigned long MemWatch::getVirtMemUsage() { - updateMemUsage (); - return _vmem_size; + updateMemUsage(); + return _vmem_size; } -unsigned long MemWatch::getResMemUsage () { - updateMemUsage (); - return _rmem_size; +unsigned long MemWatch::getResMemUsage() +{ + updateMemUsage(); + return _rmem_size; } -unsigned long MemWatch::getShrMemUsage () { - updateMemUsage (); - return _smem_size; +unsigned long MemWatch::getShrMemUsage() +{ + updateMemUsage(); + return _smem_size; } -unsigned long MemWatch::getCodeMemUsage () { - updateMemUsage (); - return _cmem_size; +unsigned long MemWatch::getCodeMemUsage() +{ + updateMemUsage(); + return _cmem_size; } } // end namespace BaseLib diff --git a/Base/MemWatch.h b/Base/MemWatch.h index a4bee7c9a..f6aec1cc8 100644 --- a/Base/MemWatch.h +++ b/Base/MemWatch.h @@ -22,24 +22,24 @@ #include #include -namespace BaseLib { - -class MemWatch { +namespace BaseLib +{ +class MemWatch +{ public: - MemWatch (); - unsigned long getVirtMemUsage (); - unsigned long getResMemUsage (); - unsigned long getShrMemUsage (); - unsigned long getCodeMemUsage (); + MemWatch(); + unsigned long getVirtMemUsage(); + unsigned long getResMemUsage(); + unsigned long getShrMemUsage(); + unsigned long getCodeMemUsage(); private: - unsigned updateMemUsage (); + unsigned updateMemUsage(); unsigned long _vmem_size; unsigned long _rmem_size; unsigned long _smem_size; unsigned long _cmem_size; }; - } #endif // not Windows diff --git a/Base/StringTools.cpp b/Base/StringTools.cpp index 99af826ba..1807a36b7 100644 --- a/Base/StringTools.cpp +++ b/Base/StringTools.cpp @@ -12,18 +12,18 @@ #include "StringTools.h" -std::list splitString(const std::string &str, char delim) +std::list splitString(const std::string& str, char delim) { std::list strList; std::stringstream ss(str); std::string item; - while(getline(ss, item, delim)) + while (getline(ss, item, delim)) strList.push_back(item); return strList; } -std::string replaceString(const std::string &searchString, - const std::string &replaceString, +std::string replaceString(const std::string& searchString, + const std::string& replaceString, std::string stringToReplace) { std::string::size_type pos = stringToReplace.find(searchString, 0); @@ -37,64 +37,72 @@ std::string replaceString(const std::string &searchString, return stringToReplace; } -void trim(std::string &str, char ch) +void trim(std::string& str, char ch) { std::string::size_type pos = str.find_last_not_of(ch); - if(pos != std::string::npos) + if (pos != std::string::npos) { str.erase(pos + 1); pos = str.find_first_not_of(ch); - if(pos != std::string::npos) + if (pos != std::string::npos) str.erase(0, pos); } else str.erase(str.begin(), str.end()); } - std::string ltrim(const std::string& str, const char c) { const size_t idx = str.find_first_not_of(c); - if (idx == std::string::npos) { + if (idx == std::string::npos) + { // string consists only of c return ""; - } else { + } + else + { return str.substr(idx); } } - std::string rtrim(const std::string& str, const char c) { const size_t idx = str.find_last_not_of(c); - if (idx == std::string::npos) { + if (idx == std::string::npos) + { // string consists only of c return ""; - } else { - return str.substr(0, idx+1); + } + else + { + return str.substr(0, idx + 1); } } - -namespace BaseLib { - -std::string getFileNameFromPath(const std::string &str, bool with_extension) +namespace BaseLib +{ +std::string getFileNameFromPath(const std::string& str, bool with_extension) { std::string::size_type beg1 = str.find_last_of('/'); std::string::size_type beg2 = str.find_last_of('\\'); std::string::size_type beg; - if (beg1 == std::string::npos && beg2 == std::string::npos) beg = -1; - else if (beg1 == std::string::npos) beg = beg2; - else if (beg2 == std::string::npos) beg = beg1; - else beg = (beg1 splitString(const std::string &str, char delim); +std::list splitString(const std::string& str, char delim); /** * Replaces a substring with another in a string @@ -32,8 +32,8 @@ std::list splitString(const std::string &str, char delim); * \param stringToReplace Search and replace in this string * \return The modified string */ -std::string replaceString(const std::string &searchString, - const std::string &replaceString, +std::string replaceString(const std::string& searchString, + const std::string& replaceString, std::string stringToReplace); /** @@ -41,7 +41,8 @@ std::string replaceString(const std::string &searchString, * \param d The number to be converted * \return The number as string */ -template std::string number2str(T d) +template +std::string number2str(T d) { std::stringstream out; out << d; @@ -54,9 +55,10 @@ template std::string number2str(T d) * \param str string to be converted * \return the number */ -template T str2number (const std::string &str) +template +T str2number(const std::string& str) { - std::stringstream strs (str, std::stringstream::in | std::stringstream::out); + std::stringstream strs(str, std::stringstream::in | std::stringstream::out); T v; strs >> v; return v; @@ -65,7 +67,7 @@ template T str2number (const std::string &str) /** * Strip whitespace (or other characters) from the beginning and end of a string. */ -void trim(std::string &str, char ch = ' '); +void trim(std::string& str, char ch = ' '); /** * Removes all occurences of c from the beginning of str. @@ -81,26 +83,25 @@ std::string ltrim(const std::string& str, const char c); */ std::string rtrim(const std::string& str, const char c); - -namespace BaseLib { - +namespace BaseLib +{ /** * Extract the filename from a path */ -std::string getFileNameFromPath(const std::string &str, bool with_extension = false); +std::string getFileNameFromPath(const std::string& str, bool with_extension = false); /** * Checks if file_name already contains a qualified path and if not copies the path from source. */ -std::string copyPathToFileName(const std::string &file_name, const std::string &source); +std::string copyPathToFileName(const std::string& file_name, const std::string& source); /** * extracts the path of a fully qualified path name of the file * @param fname [input] the fully qualified path name of the file * @param path [output] the path of the fully qualified path name of the file */ -void extractPath (std::string const& fname, std::string& path); +void extractPath(std::string const& fname, std::string& path); } // end namespace BaseLib -#endif //STRINGTOOLS_H +#endif // STRINGTOOLS_H diff --git a/Base/binarySearch.cpp b/Base/binarySearch.cpp index 068559a0e..97b22847d 100644 --- a/Base/binarySearch.cpp +++ b/Base/binarySearch.cpp @@ -13,28 +13,28 @@ #include "binarySearch.h" -size_t searchElement (double const& val, size_t beg, size_t end, const std::vector& array) +size_t searchElement(double const& val, size_t beg, size_t end, const std::vector& array) { if (beg >= end) return std::numeric_limits::max(); - size_t m ((end + beg) / 2); + size_t m((end + beg) / 2); if (array[m] - val <= 0 && array[m + 1] - val > 0) return m; if (val < array[m]) - return searchElement (val, beg, m, array); - return searchElement (val, m + 1, end, array); + return searchElement(val, beg, m, array); + return searchElement(val, m + 1, end, array); } -size_t searchElement (double const& val, size_t beg, size_t end, const std::vector& array) +size_t searchElement(double const& val, size_t beg, size_t end, const std::vector& array) { if (beg >= end) return std::numeric_limits::max(); - size_t m ((end + beg) / 2); + size_t m((end + beg) / 2); if (*(array[m]) - val <= 0 && *(array[m + 1]) - val > 0) return m; if (val < *(array[m])) - return searchElement (val, beg, m, array); - return searchElement (val, m + 1, end, array); + return searchElement(val, beg, m, array); + return searchElement(val, m + 1, end, array); } diff --git a/Base/binarySearch.h b/Base/binarySearch.h index 836329526..0e140f3f8 100644 --- a/Base/binarySearch.h +++ b/Base/binarySearch.h @@ -30,42 +30,43 @@ * the value std::numeric_limits::max() */ template -size_t searchElement (const T& key, size_t beg, size_t end, const std::vector& array) +size_t searchElement(const T& key, size_t beg, size_t end, const std::vector& array) { if (beg >= end) return std::numeric_limits::max(); - size_t m ((end + beg) / 2); + size_t m((end + beg) / 2); if (key == array[m]) return m; if (key < array[m]) - return searchElement (key, beg, m, array); - return searchElement (key, m + 1, end, array); + return searchElement(key, beg, m, array); + return searchElement(key, m + 1, end, array); } template -size_t getLargestIndexSmallerThanElement (const T& key, size_t beg, size_t end, const std::vector& array) +size_t getLargestIndexSmallerThanElement(const T& key, size_t beg, size_t end, const std::vector& array) { if (beg >= end) return std::numeric_limits::max(); - size_t m ((end + beg) / 2); + size_t m((end + beg) / 2); - if (m+1 == end) { - if (key==array[m]) + if (m + 1 == end) + { + if (key == array[m]) return m; else std::numeric_limits::max(); } - if (key >= array[m] && key < array[m+1]) + if (key >= array[m] && key < array[m + 1]) return m; if (key < array[m]) - return getLargestIndexSmallerThanElement (key, beg, m, array); - return getLargestIndexSmallerThanElement (key, m + 1, end, array); + return getLargestIndexSmallerThanElement(key, beg, m, array); + return getLargestIndexSmallerThanElement(key, m + 1, end, array); } -size_t searchElement (double const& val, size_t beg, size_t end, const std::vector& array); -size_t searchElement (double const& val, size_t beg, size_t end, const std::vector& array); +size_t searchElement(double const& val, size_t beg, size_t end, const std::vector& array); +size_t searchElement(double const& val, size_t beg, size_t end, const std::vector& array); #endif /* BINARYSEARCH_H_ */ diff --git a/Base/break.cpp b/Base/break.cpp index 3ad36b14c..096050ab1 100644 --- a/Base/break.cpp +++ b/Base/break.cpp @@ -21,7 +21,7 @@ #include "break.h" #include "makros.h" -void BreakFunc ( int sig ); +void BreakFunc(int sig); int abbruch = 0; /**************************************************************************/ @@ -40,9 +40,9 @@ int abbruch = 0; 07/1994 MSR Erste Version */ /**************************************************************************/ -void NoBreak ( void ) +void NoBreak(void) { - signal(SIGINT,SIG_IGN); + signal(SIGINT, SIG_IGN); abbruch = 0; } @@ -62,9 +62,9 @@ void NoBreak ( void ) 07/1994 MSR Erste Version */ /**************************************************************************/ -void StandardBreak ( void ) +void StandardBreak(void) { - signal(SIGINT,SIG_DFL); + signal(SIGINT, SIG_DFL); abbruch = 0; } @@ -84,9 +84,9 @@ void StandardBreak ( void ) 07/1994 MSR Erste Version */ /**************************************************************************/ -void SaveBreak ( void ) +void SaveBreak(void) { - signal(SIGINT,BreakFunc); + signal(SIGINT, BreakFunc); abbruch = 0; } @@ -106,7 +106,7 @@ void SaveBreak ( void ) 07/1994 MSR Erste Version */ /**************************************************************************/ -void ClearBreak ( void ) +void ClearBreak(void) { abbruch = 0; } @@ -127,7 +127,7 @@ void ClearBreak ( void ) 07/1994 MSR Erste Version */ /**************************************************************************/ -void BreakFunc ( int sig ) +void BreakFunc(int sig) { if (sig == SIGINT) abbruch = 1; diff --git a/Base/break.h b/Base/break.h index 81638c8cc..268d85e29 100644 --- a/Base/break.h +++ b/Base/break.h @@ -24,13 +24,13 @@ #include /* Deklarationen */ -extern void NoBreak ( void ); +extern void NoBreak(void); /* schaltet Ctrl-C aus */ -extern void StandardBreak ( void ); +extern void StandardBreak(void); /* schaltet Ctrl-C - interpretation auf Standard */ -extern void SaveBreak ( void ); +extern void SaveBreak(void); /* speichert eventuelles Ctrl-C in abbruch */ -extern void ClearBreak ( void ); +extern void ClearBreak(void); /* setzt abbruch auf 0 */ /* Weitere externe Objekte */ diff --git a/Base/display.cpp b/Base/display.cpp index 664147251..c021dd8aa 100644 --- a/Base/display.cpp +++ b/Base/display.cpp @@ -43,11 +43,11 @@ extern void CloseMsgFile(FILE*); 01/2002 MK Umleitung in MSG-Datei */ /**************************************************************************/ -void DisplayMsg ( const char* s ) +void DisplayMsg(const char* s) { FILE* f; f = OpenMsgFile(); - fprintf(f,"%s",s); + fprintf(f, "%s", s); CloseMsgFile(f); } @@ -59,10 +59,10 @@ void DisplayMsg ( const char* s ) void ScreenMessage(const char* message) { #ifdef USE_MPI - if(myrank > 0) + if (myrank > 0) return; #endif - printf("%s",message); + printf("%s", message); } /**************************************************************************/ @@ -83,11 +83,11 @@ void ScreenMessage(const char* message) 01/2002 MK Umleitung in MSG-Datei */ /**************************************************************************/ -void DisplayMsgLn ( const char* s ) +void DisplayMsgLn(const char* s) { FILE* f; f = OpenMsgFile(); - fprintf(f,"%s\n ",s); + fprintf(f, "%s\n ", s); fflush(stdout); CloseMsgFile(f); } @@ -110,11 +110,11 @@ void DisplayMsgLn ( const char* s ) 01/2002 MK Umleitung in MSG-Datei */ /**************************************************************************/ -void DisplayMsgCR ( const char* s ) +void DisplayMsgCR(const char* s) { FILE* f; f = OpenMsgFile(); - fprintf(f,"%s\r ",s); + fprintf(f, "%s\r ", s); CloseMsgFile(f); } @@ -140,15 +140,15 @@ void DisplayMsgCR ( const char* s ) 01/2002 MK Umleitung in MSG-Datei */ /**************************************************************************/ -void DisplayDouble ( double x, int i, int j ) +void DisplayDouble(double x, int i, int j) { FILE* f; f = OpenMsgFile(); if ((i == 0) && (j == 0)) /* printf("%f",x); */ - fprintf(f,"%g",x); + fprintf(f, "%g", x); else - fprintf(f,"% *.*g",i,j,x); + fprintf(f, "% *.*g", i, j, x); CloseMsgFile(f); } @@ -170,11 +170,11 @@ void DisplayDouble ( double x, int i, int j ) 01/2002 MK Umleitung in MSG-Datei */ /**************************************************************************/ -void DisplayLong ( long x ) +void DisplayLong(long x) { FILE* f; f = OpenMsgFile(); - fprintf(f,"%ld",x); + fprintf(f, "%ld", x); CloseMsgFile(f); } @@ -198,7 +198,7 @@ void DisplayLong ( long x ) 01/2002 MK Umleitung in MSG-Datei */ /**************************************************************************/ -void DisplayDoubleVector ( double* vec, long grad, char* text ) +void DisplayDoubleVector(double* vec, long grad, char* text) { FILE* f; long i; @@ -207,8 +207,8 @@ void DisplayDoubleVector ( double* vec, long grad, char* text ) f = OpenMsgFile(); for (i = 0; i < grad; i++) { - fprintf(f,"| %+e |",vec[i]); - fprintf(f,"%s\n ",""); + fprintf(f, "| %+e |", vec[i]); + fprintf(f, "%s\n ", ""); fflush(stdout); } CloseMsgFile(f); @@ -232,11 +232,11 @@ void DisplayDoubleVector ( double* vec, long grad, char* text ) 01/2002 MK Umleitung in MSG-Datei */ /**************************************************************************/ -void DisplayErrorMsg ( const char* s ) +void DisplayErrorMsg(const char* s) { FILE* f; f = OpenMsgFile(); - fprintf(f,"\n!!!!!!!! %s\n\n ",s); + fprintf(f, "\n!!!!!!!! %s\n\n ", s); CloseMsgFile(f); } @@ -258,10 +258,10 @@ void DisplayErrorMsg ( const char* s ) 01/2002 MK Umleitung in MSG-Datei */ /**************************************************************************/ -void DisplayTimeMsg ( const char* s, double d ) +void DisplayTimeMsg(const char* s, double d) { FILE* f; f = OpenMsgFile(); - fprintf(f,"\n %s%20ld s\n\n ",s,((long) d)); + fprintf(f, "\n %s%20ld s\n\n ", s, ((long)d)); CloseMsgFile(f); } diff --git a/Base/display.h b/Base/display.h index d2e558f73..47345e359 100644 --- a/Base/display.h +++ b/Base/display.h @@ -29,22 +29,22 @@ /*JT: Send output message*/ extern void ScreenMessage(const char* message); /* Gibt Programm-Abspann aus */ -extern void DisplayMsg ( const char* s ); +extern void DisplayMsg(const char* s); /* Schreibt Zeichenkette ohne Zeilenvorschub auf Standardausgabe */ -extern void DisplayMsgLn ( const char* s ); +extern void DisplayMsgLn(const char* s); /* Schreibt Zeichenkette mit Zeilenvorschub auf Standardausgabe */ -extern void DisplayMsgCR ( const char* s ); +extern void DisplayMsgCR(const char* s); /* Schreibt Zeichenkette mit Zeilenruecklauf auf Standardausgabe */ -extern void DisplayDouble ( double x, int i, int j ); +extern void DisplayDouble(double x, int i, int j); /* Schreibt Double-Wert ohne Zeilenvorschub auf Standardausgabe */ -extern void DisplayLong ( long x ); +extern void DisplayLong(long x); /* Schreibt Long-Wert ohne Zeilenvorschub auf Standardausgabe */ -extern void DisplayDoubleVector ( double* vec, long grad, char* text ); +extern void DisplayDoubleVector(double* vec, long grad, char* text); /* Schreibt Vektor auf Standardausgabe */ -//OK411 extern void DisplayDoubleMatrix ( double *mat, long m, long n, char *text ); +// OK411 extern void DisplayDoubleMatrix ( double *mat, long m, long n, char *text ); /* Schreibt Matrix auf Standardausgabe */ -extern void DisplayErrorMsg ( const char* s ); +extern void DisplayErrorMsg(const char* s); /* Schreibt Fehlermeldung auf Standardausgabe */ -extern void DisplayTimeMsg ( const char* s, double d ); +extern void DisplayTimeMsg(const char* s, double d); /* Schreibt Laufzeitmeldung auf Standardausgabe */ #endif diff --git a/Base/isnan.h b/Base/isnan.h index 07602cb48..0d42db550 100644 --- a/Base/isnan.h +++ b/Base/isnan.h @@ -17,20 +17,18 @@ namespace BASELIB { - template inline bool isNAN(T v) { #if defined(isnan) return isnan(v); #elif defined(_MSC_VER) - return _isnan(v)!=0; + return _isnan(v) != 0; #else // Remark: the following line doesn't work if compiled with --fast-math flag - return (v!=v); + return (v != v); #endif } - } -#endif //ISNAN_H +#endif // ISNAN_H diff --git a/Base/makros.cpp b/Base/makros.cpp index 4f2caad4c..9b8de008e 100644 --- a/Base/makros.cpp +++ b/Base/makros.cpp @@ -11,8 +11,8 @@ std::string FileName; std::string FilePath; -#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || \ - defined(USE_MPI_GEMS) || defined(USE_MPI_BRNS) || defined(USE_MPI_KRC) || defined(USE_PETSC) +#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_GEMS) \ + || defined(USE_MPI_BRNS) || defined(USE_MPI_KRC) || defined(USE_PETSC) int mysize; int myrank; #endif diff --git a/Base/makros.h b/Base/makros.h index 4e437939f..8a8131207 100644 --- a/Base/makros.h +++ b/Base/makros.h @@ -40,7 +40,7 @@ #define SWITCHES /* Ausgabe der Schalterstellungen zu Beginn des Programms */ #ifdef MSVCPP6 -#pragma warning (disable:4786) +#pragma warning(disable : 4786) #endif /* Laufzeitausgaben */ @@ -52,7 +52,7 @@ /**********************************************************************/ /* Speicher */ -#ifndef NO_ERROR_CONTROL /* Wird ggf. im Makefile gesetzt */ +#ifndef NO_ERROR_CONTROL /* Wird ggf. im Makefile gesetzt */ #define ERROR_CONTROL /* Fehlertests (Feldgrenzen, Existenz o.ae.), die bei sauberen Netzen und einwandfrei funktionierendem Programm nichts bringen und nur Laufzeit @@ -71,11 +71,11 @@ #define noMEMORY_ALLOCATION_TEST_SUCCESS /* Prueft, ob eine Speicheranforderung erfolgreich absolviert wurde */ -#define noMEMORY_TEST_IN_TIME /* fuer Versions-Speichertest */ +#define noMEMORY_TEST_IN_TIME /* fuer Versions-Speichertest */ /* Erstellt waehrend der Laufzeit eine Bilanz des allockierten und wieder freigegebenen Speichers. Sehr Zeitintensiv !!! */ -#define noMEMORY_STR /* fuer Versions-Speichertest */ +#define noMEMORY_STR /* fuer Versions-Speichertest */ /* Gibt Informationen bei Memory-Funktionen zur Aufrufstellenlokalisation. Funktioniert nur zusammen mit MEMORY_TEST_IN_TIME. Sehr Speicherintensiv!!! */ @@ -99,9 +99,9 @@ #endif #ifdef MEMORY_STR -#define Malloc(a) MAlloc(a,__FILE__,__LINE__) -#define Free(a) FRee(a,__FILE__,__LINE__) -#define Realloc(a,b) REalloc(a,b,__FILE__,__LINE__) +#define Malloc(a) MAlloc(a, __FILE__, __LINE__) +#define Free(a) FRee(a, __FILE__, __LINE__) +#define Realloc(a, b) REalloc(a, b, __FILE__, __LINE__) /* Ersetzt Malloc, Free und Realloc in allen *.c-Dateien durch den erweiterten Aufruf mit Dateiname und Zeilennummer */ #endif @@ -113,24 +113,24 @@ /* Listen, Baeumen, etc sind dann moeglich */ /* Definitionen der Feldgroessen */ -#define ELEM_START_SIZE 200l +#define ELEM_START_SIZE 200l /* Minimale Groesse des Elementverzeichnisses */ -#define ELEM_INC_SIZE 1000l +#define ELEM_INC_SIZE 1000l /* Bei Erreichen von ELEM_START_SIZE wird das Elementverzeichnis automatisch um ELEM_INC_SIZE vergroessert */ -#define NODE_START_SIZE 200l +#define NODE_START_SIZE 200l /* Minimale Groesse des Knotenverzeichnisses */ -#define NODE_INC_SIZE 1000l +#define NODE_INC_SIZE 1000l /* Bei Erreichen von NODE_START_SIZE wird das Knotenverzeichnis automatisch um NODE_INC_SIZE vergroessert */ -#define EDGE_START_SIZE 0l +#define EDGE_START_SIZE 0l /* Minimale Groesse des Kantenverzeichnisses */ -#define EDGE_INC_SIZE 1000l +#define EDGE_INC_SIZE 1000l /* Bei Erreichen von EDGE_START_SIZE wird das Kantenverzeichnis automatisch um EDGE_INC_SIZE vergroessert */ -#define PLAIN_START_SIZE 0l +#define PLAIN_START_SIZE 0l /* Minimale Groesse des Flaechenverzeichnisses */ -#define PLAIN_INC_SIZE 1000l +#define PLAIN_INC_SIZE 1000l /* Bei Erreichen von PLAIN_START_SIZE wird das Flaechenverzeichnis automatisch um PLAIN_INC_SIZE vergroessert */ @@ -138,34 +138,34 @@ /* Protokolle */ /* Definitionen der Dateinamen-Erweiterungen */ -#define TEXT_EXTENSION ".rfd" +#define TEXT_EXTENSION ".rfd" /* Dateinamen-Erweiterung fuer Text-Eingabedatei */ -#define PROTOCOL_EXTENSION ".rfe" +#define PROTOCOL_EXTENSION ".rfe" /* Dateinamen-Erweiterung fuer Text-Protokolldatei */ -#define RF_INPUT_EXTENSION ".rfi" +#define RF_INPUT_EXTENSION ".rfi" /* Dateinamen-Erweiterung fuer RF-Input-Dateien */ -#define RF_OUTPUT_EXTENSION ".rfo" +#define RF_OUTPUT_EXTENSION ".rfo" /* Dateinamen-Erweiterung fuer RF-Output-Dateien */ -#define RF_MESSAGE_EXTENSION ".msg" +#define RF_MESSAGE_EXTENSION ".msg" /* Dateinamen-Erweiterung fuer RF-Output-Dateien */ -#define RF_SAVE_EXTENSION1 ".sv1" +#define RF_SAVE_EXTENSION1 ".sv1" /* Dateinamen-Erweiterung fuer RF-Sicherheitskopien */ -#define RF_SAVE_EXTENSION2 ".sv2" +#define RF_SAVE_EXTENSION2 ".sv2" /* Dateinamen-Erweiterung fuer RF-Sicherheitskopien */ -#define MESH_GENERATOR_EXTENSION ".rfm" +#define MESH_GENERATOR_EXTENSION ".rfm" /* Dateinamen-Erweiterung fuer Text-Eingabedatei (Netzgenerator) */ -#define MESH_GENERATOR_PROTOCOL_EXTENSION ".rfg" +#define MESH_GENERATOR_PROTOCOL_EXTENSION ".rfg" /* Dateinamen-Erweiterung fuer Text-Protokolldatei (Netzgenerator) */ -#define INVERSE_EXTENSION ".rfv" /* ah inv */ +#define INVERSE_EXTENSION ".rfv" /* ah inv */ /* Dateinamen-Erweiterung fuer Text-Eingabedatei (Inverses Modellieren) */ -#define INVERSE_PROTOCOL_EXTENSION ".rfp" +#define INVERSE_PROTOCOL_EXTENSION ".rfp" /* Dateinamen-Erweiterung fuer Text-Eingabedatei (Inverses Modellieren) */ -#define CHEM_REACTION_EXTENSION ".pqc" +#define CHEM_REACTION_EXTENSION ".pqc" /* Dateinamen-Erweiterung fuer Text-Eingabedatei (Chemical reaction) */ -#define CHEMAPP_REACTION_EXTENSION ".chm" +#define CHEMAPP_REACTION_EXTENSION ".chm" #define REACTION_EXTENSION_CHEMAPP ".cap" // DL/SB 11.2008 #define TEC_FILE_EXTENSION ".tec" -#define VTK_FILE_EXTENSION ".vtk" //GK +#define VTK_FILE_EXTENSION ".vtk" // GK #define CSV_FILE_EXTENSION ".csv" #define noTESTFILES @@ -181,8 +181,8 @@ /* Format der Double-Ausgabe ueber FilePrintDouble --> txtinout */ #define FORMAT_DOUBLE -#define FPD_GESAMT 4 -#define FPD_NACHKOMMA 14 +#define FPD_GESAMT 4 +#define FPD_NACHKOMMA 14 /**********************************************************************/ /* C1.2 Numerik */ @@ -254,7 +254,7 @@ /**********************************************************************/ /* Parallelization */ #define noPARALLEL -#define noCHEMAPP //MX +#define noCHEMAPP // MX #define noREACTION_ELEMENT #define noSX #define noMPI @@ -274,10 +274,10 @@ #endif /* Feste Zahlen fuer Genauigkeitspruefungen etc. */ -#define Mdrittel (1.0 / 3.0) +#define Mdrittel (1.0 / 3.0) #define MKleinsteZahl DBL_EPSILON #define MFastNull DBL_MIN -#define MSqrt2Over3 sqrt(2.0 / 3.0) +#define MSqrt2Over3 sqrt(2.0 / 3.0) /* CBLAS oder MKL_CBLAS verwenden? Wenn ja, wo? */ #define noCBLAS @@ -309,7 +309,7 @@ #endif // min und max -#define Max(A,B) ((A) > (B) ? (A) : (B)) +#define Max(A, B) ((A) > (B) ? (A) : (B)) /* #ifndef min @@ -322,17 +322,17 @@ #define MAX_ZEILE 2048 /* max. Laenge einer UCD-Zeile; bei Leseproblemen vergroessern */ -//enum DIS_TYPES {CONSTANT,LINEAR}; +// enum DIS_TYPES {CONSTANT,LINEAR}; extern std::string FileName; -extern std::string FilePath; //WW +extern std::string FilePath; // WW -#define RESET_4410 // H2_ELE test +#define RESET_4410 // H2_ELE test //---- MPI Parallel -------------- -#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || \ - defined(USE_MPI_GEMS) || defined(USE_MPI_BRNS) || defined(USE_MPI_KRC) || defined(USE_PETSC) -extern int mysize; //WW +#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_GEMS) \ + || defined(USE_MPI_BRNS) || defined(USE_MPI_KRC) || defined(USE_PETSC) +extern int mysize; // WW extern int myrank; #endif //---- MPI Parallel -------------- diff --git a/Base/memory.cpp b/Base/memory.cpp index 8feba6fb8..b6c4b0f3b 100644 --- a/Base/memory.cpp +++ b/Base/memory.cpp @@ -94,7 +94,7 @@ int InitMemoryTest(void) #ifdef MEMORY_TEST_IN_TIME /* Sicherstellen, dass auch beim ersten Aufruf schon Speicher zur Verfuegung steht */ - memtab = (Memory_Table*) malloc(sizeof(Memory_Table)); + memtab = (Memory_Table*)malloc(sizeof(Memory_Table)); memory_list_size = 0; memory_alloced = 0; memory_max_alloced = 0; @@ -136,9 +136,7 @@ void StopMemoryTest(void) while (i < memory_list_size) { if (memtab[i].address > 0) - printf("Nicht freigegeben wurde: %s Zeile %d\n", - memtab[i].file, - memtab[i].line); + printf("Nicht freigegeben wurde: %s Zeile %d\n", memtab[i].file, memtab[i].line); i = i + 1; } #endif @@ -191,9 +189,9 @@ void* MAlloc(long bytes, char* datei, int zeile) return NULL; #endif - address = (void*) malloc((size_t) bytes); + address = (void*)malloc((size_t)bytes); #ifdef MEMORY_SHOW_USAGE - printf("address %8x %ld , ",address,(long)address); + printf("address %8x %ld , ", address, (long)address); #endif #ifdef MEMORY_TEST_IN_TIME @@ -208,17 +206,14 @@ void* MAlloc(long bytes, char* datei, int zeile) /* Kein freier Platz wurde gefunden, der Ueberhang wird benutzt. Fuer den naechsten Durchlauf muss ein neuer Platz erzeugt werden. */ memory_list_size = memory_list_size + 1; - memtab = - (Memory_Table*) realloc(memtab, - (memory_list_size + - 1) * sizeof(Memory_Table)); + memtab = (Memory_Table*)realloc(memtab, (memory_list_size + 1) * sizeof(Memory_Table)); memtab[memory_list_size].address = 0; memtab[memory_list_size].size = 0; } memory_alloced = memory_alloced + bytes; - memtab[i].address = (long) address; - memtab[i].size = (long) bytes; + memtab[i].address = (long)address; + memtab[i].size = (long)bytes; #ifdef MEMORY_STR memtab[i].file = datei; @@ -236,7 +231,7 @@ void* MAlloc(long bytes, char* datei, int zeile) #endif #ifdef MEMORY_ALLOCATION_TEST_SUCCESS - if ((bytes) && (address == 0)) /* Angeforderter Speicher wurde nicht geliefert */ + if ((bytes) && (address == 0)) /* Angeforderter Speicher wurde nicht geliefert */ { #ifdef MEMORY_STR printf("Malloc aufgerufen von %s Zeile %d. \n", datei, zeile); @@ -296,7 +291,7 @@ void* FRee(void* block, char* datei, int zeile) while (i >= 0) { - if (memtab[i].address == (long) block) + if (memtab[i].address == (long)block) { /* Richtiger Block wurde gefunden! Kann freigegeben werden. */ @@ -367,8 +362,8 @@ void* REalloc(void* block, long bytes, char* datei, int zeile) long new_bytes; long i; - old_block = (long) block; - new_bytes = (long) bytes; + old_block = (long)block; + new_bytes = (long)bytes; #endif #ifdef MEMORY_MANAGEMENT_NOT_ANSI_COMPLIANT @@ -395,8 +390,8 @@ void* REalloc(void* block, long bytes, char* datei, int zeile) #endif if (!(block == NULL)) { - a = (char*) address; - b = (char*) block; + a = (char*)address; + b = (char*)block; { /* beim Vergroessern wird ein laengerer Bereich gelesen, als eigentlich belegt war ! @@ -413,17 +408,17 @@ void* REalloc(void* block, long bytes, char* datei, int zeile) #ifndef MEMORY_STR block = Free(block); #else - block = FRee(block, datei, zeile); /* vorher Free msr 0796 */ + block = FRee(block, datei, zeile); /* vorher Free msr 0796 */ #endif #else // ifdef MEMORY_REALLOC - address = (void*) realloc(block, (size_t) bytes); + address = (void*)realloc(block, (size_t)bytes); #ifdef MEMORY_SHOW_USAGE - printf("address %8x %ld , ",address,(long)address); + printf("address %8x %ld , ", address, (long)address); #endif #endif #ifdef MEMORY_ALLOCATION_TEST_SUCCESS - if ((bytes) && (address == 0)) /* Angeforderter Speicher wurde nicht geliefert */ + if ((bytes) && (address == 0)) /* Angeforderter Speicher wurde nicht geliefert */ { #ifdef MEMORY_STR printf("Malloc aufgerufen von %s Zeile %d. \n", datei, zeile); @@ -446,8 +441,8 @@ void* REalloc(void* block, long bytes, char* datei, int zeile) { /* Richtiger Block wurde gefunden! Kann freigegeben werden. */ memory_alloced = memory_alloced - memtab[i].size + new_bytes; - memtab[i].address = (long) address; - memtab[i].size = (long) new_bytes; + memtab[i].address = (long)address; + memtab[i].size = (long)new_bytes; #ifdef MEMORY_STR memtab[i].file = datei; memtab[i].line = zeile; diff --git a/Base/memory.h b/Base/memory.h index 530e616bb..20f1911b4 100644 --- a/Base/memory.h +++ b/Base/memory.h @@ -31,28 +31,28 @@ /* Deklarationen */ -extern int InitMemoryTest ( void ); +extern int InitMemoryTest(void); /* Startet Memory-Test, 0 bei Fehler */ -extern void StopMemoryTest ( void ); +extern void StopMemoryTest(void); /* Beendet Memory-Test */ -extern long MemoryTestInTimeSum( void ); +extern long MemoryTestInTimeSum(void); /* Gibt Summe des aktuell allokierten Speichers zurueck */ -extern long MemoryTestInTimeMemory( void ); +extern long MemoryTestInTimeMemory(void); /* Gibt Summe des Speichers fuer den Eigenbedarf zurueck */ -extern long MemoryTestInTimeArea( void ); +extern long MemoryTestInTimeArea(void); /* Gibt Groesse des aktuell durch Addressen eingegrenzten Bereichs zurueck */ #ifndef MEMORY_STR -extern void* Malloc ( long bytes ); +extern void* Malloc(long bytes); /* Ersetzt malloc */ -extern void* Free ( void* block ); +extern void* Free(void* block); /* Ersetzt free, muss in der Form >> x = Free(x); << benutzt werden */ -extern void* Realloc ( void* block, long bytes ); +extern void* Realloc(void* block, long bytes); /* Ersetzt realloc, muss in der Form >> x = Realloc(x,i); << benutzt werden */ #else -extern void* MAlloc ( long bytes, char* datei, int zeile ); -extern void* FRee ( void* block, char* datei, int zeile ); -extern void* REalloc ( void* block, long bytes, char* datei, int zeile ); +extern void* MAlloc(long bytes, char* datei, int zeile); +extern void* FRee(void* block, char* datei, int zeile); +extern void* REalloc(void* block, long bytes, char* datei, int zeile); /* Funktionen wie oben, nur mit Aufrufstellenkennzeichnung */ #endif #endif diff --git a/Base/printList.h b/Base/printList.h index 99af276dc..400e76634 100644 --- a/Base/printList.h +++ b/Base/printList.h @@ -20,11 +20,10 @@ namespace BASELIB { -void printList (std::list const& mylist, std::string const& title) +void printList(std::list const& mylist, std::string const& title) { std::cout << title << "\n"; - for (std::list::const_iterator my_it (mylist.begin()); - my_it != mylist.end(); my_it++) + for (std::list::const_iterator my_it(mylist.begin()); my_it != mylist.end(); my_it++) std::cout << *my_it << " "; std::cout << "\n"; } diff --git a/Base/quicksort.h b/Base/quicksort.h index 87fc59635..dd26a64fc 100644 --- a/Base/quicksort.h +++ b/Base/quicksort.h @@ -29,7 +29,7 @@ size_t partition_(T* array, size_t beg, size_t end, size_t* perm) size_t j = end - 1; T m = array[beg]; - for (;; ) + for (;;) { while ((i < end) && (array[i] <= m)) i++; @@ -68,10 +68,11 @@ template class Quicksort { public: - Quicksort (std::vector& array, size_t beg, size_t end, std::vector& perm) + Quicksort(std::vector& array, size_t beg, size_t end, std::vector& perm) { - quicksort (array, beg, end, perm); + quicksort(array, beg, end, perm); } + private: size_t partition_(std::vector& array, size_t beg, size_t end, std::vector& perm) { @@ -79,7 +80,7 @@ class Quicksort size_t j = end - 1; T m = array[beg]; - for (;; ) + for (;;) { while ((i < end) && (array[i] <= m)) i++; @@ -110,17 +111,17 @@ class Quicksort // specialization for pointer types template -class Quicksort +class Quicksort { public: - Quicksort (std::vector& array, size_t beg, size_t end, std::vector& perm) + Quicksort(std::vector& array, size_t beg, size_t end, std::vector& perm) { - quicksort (array, beg, end, perm); + quicksort(array, beg, end, perm); } - Quicksort (std::vector& perm, size_t beg, size_t end, std::vector& array) + Quicksort(std::vector& perm, size_t beg, size_t end, std::vector& array) { - quicksort (perm, beg, end, array); + quicksort(perm, beg, end, array); } private: @@ -130,7 +131,7 @@ class Quicksort size_t j = end - 1; T* m = array[beg]; - for (;; ) + for (;;) { while ((i < end) && (*array[i] <= *m)) i++; @@ -158,13 +159,13 @@ class Quicksort } } - size_t partition_(std::vector &perm, size_t beg, size_t end, std::vector& array) + size_t partition_(std::vector& perm, size_t beg, size_t end, std::vector& array) { size_t i = beg + 1; size_t j = end - 1; size_t m = perm[beg]; - for (;; ) + for (;;) { while ((i < end) && (perm[i] <= m)) i++; diff --git a/Base/swap.h b/Base/swap.h index 9e3b7ec8a..7439fd9f0 100644 --- a/Base/swap.h +++ b/Base/swap.h @@ -15,7 +15,8 @@ namespace BASELIB /** * swap the content of arg0 and arg1 */ -template void swap(T& arg0, T& arg1) +template +void swap(T& arg0, T& arg1) { T temp(arg0); arg0 = arg1; @@ -23,4 +24,4 @@ template void swap(T& arg0, T& arg1) } } // end namespace BASELIB -#endif //SWAP_H_ +#endif // SWAP_H_ diff --git a/Base/timer.cpp b/Base/timer.cpp old mode 100755 new mode 100644 index 77c2a7a01..9aeb5fa0a --- a/Base/timer.cpp +++ b/Base/timer.cpp @@ -35,7 +35,7 @@ using namespace std; #ifndef WIN32 #include #include -#endif // WIN32 +#endif // WIN32 #include #endif @@ -46,7 +46,7 @@ using namespace std; static int max_zeitspeicher = -1; static long* zeit = NULL; static int* running = NULL; -vector ClockTimeVec; +vector ClockTimeVec; /************************************************************************* ROCKFLOW - Funktion: TInitTimer @@ -72,8 +72,8 @@ void TInitTimer(int speicher) /* Ggf. Liste der Speicher erweitern */ if (speicher > max_zeitspeicher) { - zeit = (long*) Realloc(zeit, sizeof(long) * (speicher + 1)); - running = (int*) Realloc(running, sizeof(int) * (speicher + 1)); + zeit = (long*)Realloc(zeit, sizeof(long) * (speicher + 1)); + running = (int*)Realloc(running, sizeof(int) * (speicher + 1)); max_zeitspeicher = speicher; } @@ -105,8 +105,8 @@ void TStartTimer(int speicher) /* Ggf. Liste der Speicher erweitern */ if (speicher > max_zeitspeicher) { - zeit = (long*) Realloc(zeit, sizeof(long) * (speicher + 1)); - running = (int*) Realloc(running, sizeof(int) * (speicher + 1)); + zeit = (long*)Realloc(zeit, sizeof(long) * (speicher + 1)); + running = (int*)Realloc(running, sizeof(int) * (speicher + 1)); max_zeitspeicher = speicher; } @@ -141,10 +141,10 @@ double TGetTimerDouble(int speicher) if (!running[speicher]) /* Der Timer war angehalten */ - time_gone_by = (double) zeit[speicher] / (double) TGetTicksPerSecond(); + time_gone_by = (double)zeit[speicher] / (double)TGetTicksPerSecond(); else /* Der Timer lief */ - time_gone_by = (double) (TGetTime() - zeit[speicher]) / (double) TGetTicksPerSecond(); + time_gone_by = (double)(TGetTime() - zeit[speicher]) / (double)TGetTicksPerSecond(); return time_gone_by; } @@ -172,15 +172,15 @@ double TGetTimerDouble(int speicher) **************************************************************************/ long TGetTimer(int speicher) { - if(!running) //OK + if (!running) // OK return -1; long time_gone_by; if (!running[speicher]) /* Der Timer war angehalten */ - time_gone_by = (long) (zeit[speicher] / TGetTicksPerSecond()); + time_gone_by = (long)(zeit[speicher] / TGetTicksPerSecond()); else /* Der Timer lief */ - time_gone_by = (long) ((TGetTime() - zeit[speicher]) / TGetTicksPerSecond()); + time_gone_by = (long)((TGetTime() - zeit[speicher]) / TGetTicksPerSecond()); return time_gone_by; } @@ -315,8 +315,8 @@ long TGetTicksPerSecond(void) void TDestroyTimers(void) { /* Speicherfreigaben */ - zeit = (long*) Free(zeit); - running = (int*) Free(running); + zeit = (long*)Free(zeit); + running = (int*)Free(running); } /************************************************************************* @@ -339,7 +339,7 @@ void ctime_(float* time) *time = (float)TGetTime() / (float)TGetTicksPerSecond(); } -//New SB time +// New SB time CClockTime::CClockTime(void) { @@ -374,10 +374,10 @@ CClockTime::~CClockTime(void) void CClockTime::StartTime(void) { start = clock(); - //WW time1=GetTickCount(); + // WW time1=GetTickCount(); } -void CClockTime::StopTime(const std::string &name) +void CClockTime::StopTime(const std::string& name) { char name1; name1 = name[0]; @@ -385,108 +385,109 @@ void CClockTime::StopTime(const std::string &name) end = clock(); this->delta_clocktime = (double)(end - start) / CLOCKS_PER_SEC; - //WW time2=GetTickCount(); + // WW time2=GetTickCount(); difftime = (time2 - time1) / 1000.0; // cout << " ClockTime: " << delta_clocktime << ", TickTime: " << difftime << "\n"; switch (name1) { - default: - break; - case ('F'): - time_flow.push_back(delta_clocktime); - time_total_flow += delta_clocktime; - break; - case ('T'): - this->time_transport.push_back(delta_clocktime); - time_total_transport += delta_clocktime; - break; - case ('K'): - this->time_kinreact.push_back(delta_clocktime); - time_total_kinreact += delta_clocktime; - break; - case ('E'): - this->time_equireact.push_back(delta_clocktime); - time_total_equireact += delta_clocktime; - break; - case ('R'): - this->time_reactdeact.push_back(delta_clocktime); - time_total_reactdeact += delta_clocktime; - break; + default: + break; + case ('F'): + time_flow.push_back(delta_clocktime); + time_total_flow += delta_clocktime; + break; + case ('T'): + this->time_transport.push_back(delta_clocktime); + time_total_transport += delta_clocktime; + break; + case ('K'): + this->time_kinreact.push_back(delta_clocktime); + time_total_kinreact += delta_clocktime; + break; + case ('E'): + this->time_equireact.push_back(delta_clocktime); + time_total_equireact += delta_clocktime; + break; + case ('R'): + this->time_reactdeact.push_back(delta_clocktime); + time_total_reactdeact += delta_clocktime; + break; } } void CClockTime::PrintTimes(void) { #ifndef OGS_OUTPUT_TIME_ALLPCS - if (time_kinreact.size() == 0 - || time_equireact.size() == 0 - || time_reactdeact.size() == 0) //WW + if (time_kinreact.size() == 0 || time_equireact.size() == 0 || time_reactdeact.size() == 0) // WW return; #endif - int i,length; + int i, length; double tot = 0., help = 0.0, tot_zeitschritt = 0.; - string outname= FileName + "_ClockTimes.txt"; + string outname = FileName + "_ClockTimes.txt"; cout.precision(2); tot = time_total_flow + time_total_transport + time_total_kinreact + time_total_equireact + time_total_reactdeact; - cout << "ClockTimes: " << "\n" << - "Unit Flow: Transport: KinReactions: EquiReactions: ReactDeact: total: " << "\n"; - cout << "[sec] " << setw(6) << time_total_flow << " " << setw(10) << - time_total_transport << " " << setw(13) << time_total_kinreact << " " << setw(14) << - time_total_equireact << " " << setw(14) << time_total_reactdeact << " " << setw(6) << tot << "\n"; - cout << "[%] " << setw(6) << time_total_flow / tot * 100 << " " << setw(10) << - time_total_transport / tot * 100 << " " << setw(13) << time_total_kinreact / tot * 100 << - " " << setw(14) << time_total_equireact / tot * 100 << " " << setw(14) << time_total_reactdeact/tot*100<< " " << setw(6) << tot/tot*100 << "\n"; - - length = (int) this->time_flow.size(); - if ((int) this->time_transport.size() > length) - length = (int) this->time_transport.size(); - if ((int) this->time_kinreact.size() > length) - length = (int) this->time_kinreact.size(); - if ((int) this->time_equireact.size() > length) - length = (int) this->time_equireact.size(); - if ((int) this->time_reactdeact.size() > length) - length = (int) this->time_reactdeact.size(); + cout << "ClockTimes: " + << "\n" + << "Unit Flow: Transport: KinReactions: EquiReactions: ReactDeact: total: " + << "\n"; + cout << "[sec] " << setw(6) << time_total_flow << " " << setw(10) << time_total_transport << " " << setw(13) + << time_total_kinreact << " " << setw(14) << time_total_equireact << " " << setw(14) << time_total_reactdeact + << " " << setw(6) << tot << "\n"; + cout << "[%] " << setw(6) << time_total_flow / tot * 100 << " " << setw(10) << time_total_transport / tot * 100 + << " " << setw(13) << time_total_kinreact / tot * 100 << " " << setw(14) << time_total_equireact / tot * 100 + << " " << setw(14) << time_total_reactdeact / tot * 100 << " " << setw(6) << tot / tot * 100 << "\n"; + + length = (int)this->time_flow.size(); + if ((int)this->time_transport.size() > length) + length = (int)this->time_transport.size(); + if ((int)this->time_kinreact.size() > length) + length = (int)this->time_kinreact.size(); + if ((int)this->time_equireact.size() > length) + length = (int)this->time_equireact.size(); + if ((int)this->time_reactdeact.size() > length) + length = (int)this->time_reactdeact.size(); ofstream out_file(outname.data(), ios::out); out_file.precision(6); - out_file << "Step Flow Transport KinReactions EquiReactions ReactDeact Total"<< "\n"; - for(i = 0; i < length; i++) + out_file << "Step Flow Transport KinReactions EquiReactions ReactDeact Total" + << "\n"; + for (i = 0; i < length; i++) { out_file << i << " "; - //flow - if((int)time_flow.size() > i) + // flow + if ((int)time_flow.size() > i) help = time_flow[i]; else help = 0.0; out_file << help << " "; tot_zeitschritt = help; - //transport - if((int)time_transport.size() > i) + // transport + if ((int)time_transport.size() > i) help = time_transport[i]; else help = 0.0; out_file << help << " "; tot_zeitschritt += help; - //kinetic reactions - if((int)time_kinreact.size() > i) + // kinetic reactions + if ((int)time_kinreact.size() > i) help = time_kinreact[i]; else help = 0.0; out_file << help << " "; tot_zeitschritt += help; - //equilibrium reactions - if((int)time_equireact.size() > i) + // equilibrium reactions + if ((int)time_equireact.size() > i) help = time_equireact[i]; else help = 0.0; out_file << help << " "; - //reaction deactivation - if ((int) time_reactdeact.size() > i) + // reaction deactivation + if ((int)time_reactdeact.size() > i) help = time_reactdeact[i]; else help = 0.0; @@ -497,9 +498,14 @@ void CClockTime::PrintTimes(void) out_file << tot_zeitschritt << "\n"; } out_file << "\n"; - out_file << "TotalFlow TotalTransport TotalKinReactions TotalEquiReactions TotalReactDeact Total"<< "\n"; - out_file << time_total_flow << " " << time_total_transport << " " << time_total_kinreact << " " << time_total_equireact << " " << time_total_reactdeact << " " << tot << " " << "\n"; - out_file << time_total_flow/tot*100 << " " << time_total_transport/tot*100 << " " << time_total_kinreact/tot*100 << " " << time_total_equireact/tot*100 << " " << time_total_reactdeact/tot*100 << " " << tot/tot*100 << "\n"; + out_file << "TotalFlow TotalTransport TotalKinReactions TotalEquiReactions TotalReactDeact Total" + << "\n"; + out_file << time_total_flow << " " << time_total_transport << " " << time_total_kinreact << " " + << time_total_equireact << " " << time_total_reactdeact << " " << tot << " " + << "\n"; + out_file << time_total_flow / tot * 100 << " " << time_total_transport / tot * 100 << " " + << time_total_kinreact / tot * 100 << " " << time_total_equireact / tot * 100 << " " + << time_total_reactdeact / tot * 100 << " " << tot / tot * 100 << "\n"; out_file.close(); } @@ -513,7 +519,7 @@ void CreateClockTime(void) void DestroyClockTime(void) { - for (size_t i=0; i time_flow; - std::vector time_transport; - std::vector time_kinreact; - std::vector time_equireact; - std::vector time_reactdeact; + std::vector time_flow; + std::vector time_transport; + std::vector time_kinreact; + std::vector time_equireact; + std::vector time_reactdeact; double time_total_flow; double time_total_transport; double time_total_kinreact; double time_total_equireact; - double time_total_reactdeact; + double time_total_reactdeact; double delta_clocktime; clock_t start; clock_t end; - void StopTime(const std::string &name = ""); + void StopTime(const std::string& name = ""); void StartTime(void); void PrintTimes(void); @@ -90,5 +90,5 @@ class CClockTime }; extern void CreateClockTime(void); extern void DestroyClockTime(void); -extern std::vector ClockTimeVec; +extern std::vector ClockTimeVec; #endif diff --git a/Base/uniqueListInsert.h b/Base/uniqueListInsert.h index db52d3987..fb1dff727 100644 --- a/Base/uniqueListInsert.h +++ b/Base/uniqueListInsert.h @@ -18,15 +18,15 @@ namespace BASELIB { -void uniqueListInsert (std::list& list, size_t element) +void uniqueListInsert(std::list& list, size_t element) { // search element std::list::const_iterator it; - for (it = list.begin (); it != list.end(); it++) + for (it = list.begin(); it != list.end(); it++) if (*it == element) return; // element not found -> insert - list.push_back (element); + list.push_back(element); } } // end namespace BASELIB diff --git a/Base/wait.h b/Base/wait.h index 9701c2db4..97043eba4 100644 --- a/Base/wait.h +++ b/Base/wait.h @@ -23,9 +23,8 @@ void wait(int seconds) do { time(&cur_time); - } - while((cur_time - start_time) < seconds); + } while ((cur_time - start_time) < seconds); } } // end namespace BASELIB -#endif //WAIT_H +#endif // WAIT_H diff --git a/FEM/BoundaryCondition.cpp b/FEM/BoundaryCondition.cpp index 901f58c85..b870a13da 100644 --- a/FEM/BoundaryCondition.cpp +++ b/FEM/BoundaryCondition.cpp @@ -12,20 +12,20 @@ #include "BoundaryCondition.h" #include "rf_bc_new.h" -BoundaryCondition::BoundaryCondition(const CBoundaryCondition &bc, const std::string &geometry_name) - : FEMCondition(geometry_name, bc.getProcessType(), bc.getProcessPrimaryVariable(), - bc.getGeoType(), bc.getGeoName(), - bc.getProcessDistributionType(), FEMCondition::BOUNDARY_CONDITION) +BoundaryCondition::BoundaryCondition(const CBoundaryCondition& bc, const std::string& geometry_name) + : FEMCondition(geometry_name, bc.getProcessType(), bc.getProcessPrimaryVariable(), bc.getGeoType(), bc.getGeoName(), + bc.getProcessDistributionType(), FEMCondition::BOUNDARY_CONDITION) { - if (this->getProcessDistributionType() == FiniteElement::CONSTANT || - this->getProcessDistributionType() == FiniteElement::CONSTANT_NEUMANN) + if (this->getProcessDistributionType() == FiniteElement::CONSTANT + || this->getProcessDistributionType() == FiniteElement::CONSTANT_NEUMANN) this->setConstantDisValue(bc.getGeoNodeValue()); - else if (this->getProcessDistributionType() == FiniteElement::LINEAR || - this->getProcessDistributionType() == FiniteElement::LINEAR_NEUMANN) + else if (this->getProcessDistributionType() == FiniteElement::LINEAR + || this->getProcessDistributionType() == FiniteElement::LINEAR_NEUMANN) { const std::vector bc_nodes(bc.getPointsWithDistribedBC()); std::vector dis_nodes(bc_nodes.size()); - for (size_t i=0; i(bc_nodes[i]); + for (size_t i = 0; i < dis_nodes.size(); i++) + dis_nodes[i] = static_cast(bc_nodes[i]); this->setDisValues(dis_nodes, bc.getDistribedBC()); } } diff --git a/FEM/BoundaryCondition.h b/FEM/BoundaryCondition.h index ca6d148e7..46d640cd1 100644 --- a/FEM/BoundaryCondition.h +++ b/FEM/BoundaryCondition.h @@ -21,18 +21,15 @@ class BoundaryCondition : public FEMCondition { public: - BoundaryCondition(const std::string &geometry_name) - : FEMCondition(geometry_name, FEMCondition::BOUNDARY_CONDITION), _tim_type(0) {}; - BoundaryCondition(const CBoundaryCondition &bc, const std::string &geometry_name); - BoundaryCondition(const FEMCondition &cond) - : FEMCondition(cond, FEMCondition::BOUNDARY_CONDITION) {}; + BoundaryCondition(const std::string& geometry_name) + : FEMCondition(geometry_name, FEMCondition::BOUNDARY_CONDITION), _tim_type(0){}; + BoundaryCondition(const CBoundaryCondition& bc, const std::string& geometry_name); + BoundaryCondition(const FEMCondition& cond) : FEMCondition(cond, FEMCondition::BOUNDARY_CONDITION){}; ~BoundaryCondition() {} - - size_t getTimType() const {return _tim_type; } + size_t getTimType() const { return _tim_type; } void setTimType(size_t value) { _tim_type = value; } - private: size_t _tim_type; }; -#endif //BOUNDARYCONDITION_H +#endif // BOUNDARYCONDITION_H diff --git a/FEM/CAP_IO.cpp b/FEM/CAP_IO.cpp old mode 100755 new mode 100644 index 48a4d7c8c..216af6b50 --- a/FEM/CAP_IO.cpp +++ b/FEM/CAP_IO.cpp @@ -15,15 +15,15 @@ #include #include #if defined(WIN32) - #include +#include #else - #include - #include +#include +#include #endif #include #ifdef OGS_FEM_CAP // CAP_REACT - #include "cacint.h" +#include "cacint.h" #endif #include "rf_react.h" @@ -33,10 +33,10 @@ using namespace std; int CAP_MODE, CAP_Time, CAP_Node, CAP_icount, CAP_count; -vector > CHEM_STATE,CHEM_STATE_AP; +vector > CHEM_STATE, CHEM_STATE_AP; vector > PHASE_CONSTI_MAP; -char getPathSepatator() //WW +char getPathSepatator() // WW { #if defined(WIN32) return '\\'; @@ -47,49 +47,51 @@ char getPathSepatator() //WW void write_file(void) { - #ifdef OGS_FEM_CAP // CAP_REACT - stringstream ss; + stringstream ss; ofstream out; string file_name, path_name, copy_file; char pcname[TQSTRLEN], name_element[TQSTRLEN]; - long int np,npc,nsc,noerror; - long int ip,ipc,isc; + long int np, npc, nsc, noerror; + long int ip, ipc, isc; DB value; - ip=ipc=isc=np=npc=nsc=noerror=0; + ip = ipc = isc = np = npc = nsc = noerror = 0; - ss << FilePath << "_CHEM_STATE"; - ss >> path_name; + ss << FilePath << "_CHEM_STATE"; + ss >> path_name; ss.clear(); - if(CAP_count==1){ + if (CAP_count == 1) + { #if defined(WIN32) - mkdir(path_name.c_str()); + mkdir(path_name.c_str()); - copy_file="copy " + FileName + ".* " + path_name; - system(copy_file.c_str()); + copy_file = "copy " + FileName + ".* " + path_name; + system(copy_file.c_str()); #else - mkdir(path_name.c_str(), S_IRWXU | S_IRWXG | S_IRWXO ); + mkdir(path_name.c_str(), S_IRWXU | S_IRWXG | S_IRWXO); #endif - } + } #if defined(WIN32) - ss << FilePath << "_CHEM_STATE\\T" << CAP_Time << "N" << CAP_Node << "C" << CAP_icount; + ss << FilePath << "_CHEM_STATE\\T" << CAP_Time << "N" << CAP_Node << "C" << CAP_icount; #else - ss << FilePath << "_CHEM_STATE\/T" << CAP_Time << "N" << CAP_Node << "C" << CAP_icount; + ss << FilePath << "_CHEM_STATE\/T" << CAP_Time << "N" << CAP_Node << "C" << CAP_icount; #endif ss >> file_name; - //cout << file_name << "\n"; - out.open(file_name.c_str(),ios::out); + // cout << file_name << "\n"; + out.open(file_name.c_str(), ios::out); out.clear(); out << "phase constituent name a ia ac G"; - tqnop(&np,&noerror); - for(ip=1;ip<=np;ip++){ - tqnopc(ip,&npc,&noerror); - for(ipc=1;ipc<=npc;ipc++){ + tqnop(&np, &noerror); + for (ip = 1; ip <= np; ip++) + { + tqnopc(ip, &npc, &noerror); + for (ipc = 1; ipc <= npc; ipc++) + { out << endl; - tqgnpc(ip,ipc,pcname,&noerror); + tqgnpc(ip, ipc, pcname, &noerror); out << ip << " " << ipc << " " << pcname; tqgetr("a", ip, ipc, &value, &noerror); out << " " << value; @@ -102,71 +104,69 @@ void write_file(void) } } out.close(); - file_name +="_AP"; - out.open(file_name.c_str(),ios::out); + file_name += "_AP"; + out.open(file_name.c_str(), ios::out); out.clear(); out << "idx element amount"; - tqnosc(&nsc,&noerror); - for(isc=1;isc<=nsc;isc++){ + tqnosc(&nsc, &noerror); + for (isc = 1; isc <= nsc; isc++) + { out << endl; - tqgnsc(isc,name_element,&noerror); + tqgnsc(isc, name_element, &noerror); out << isc << " " << name_element; - tqgetr("ap",2,isc,&value,&noerror); + tqgetr("ap", 2, isc, &value, &noerror); out << " " << value; } out.close(); #endif - } - bool CAP_check_file(void) { stringstream ss; ifstream in; string file_name; - ss.clear(); - bool success = false; + ss.clear(); + bool success = false; int f; - ss << FilePath << "_CHEM_STATE" << getPathSepatator()<< "T" << CAP_Time << "N" << CAP_Node << "C" << CAP_icount; + ss << FilePath << "_CHEM_STATE" << getPathSepatator() << "T" << CAP_Time << "N" << CAP_Node << "C" << CAP_icount; ss >> file_name; in.clear(); - in.open(file_name.c_str(),ios::in); - if(in.good()) - success=true; + in.open(file_name.c_str(), ios::in); + if (in.good()) + success = true; - in.close(); - in.clear(); + in.close(); + in.clear(); - string proj_name,in_file_new,in_file_old; + string proj_name, in_file_new, in_file_old; - std::string locfilepath, locfilename; + std::string locfilepath, locfilename; - locfilepath=FilePath; - locfilename=FileName; + locfilepath = FilePath; + locfilename = FileName; - if(locfilepath==""){ + if (locfilepath == "") + { #if defined(WIN32) - locfilepath=""; - locfilename=locfilename; + locfilepath = ""; + locfilename = locfilename; #else - locfilepath="./"; - locfilename="./"+locfilename; + locfilepath = "./"; + locfilename = "./" + locfilename; #endif - } - proj_name = locfilename.substr(locfilepath.length()); - - + } + proj_name = locfilename.substr(locfilepath.length()); cout << proj_name << endl; - cout << locfilename<< endl; - cout << locfilepath << endl; + cout << locfilename << endl; + cout << locfilepath << endl; int i; - vector< string > ext_name0,ext_name; + vector ext_name0, ext_name; ext_name0.clear(); ext_name0.push_back("bc"); @@ -188,43 +188,44 @@ bool CAP_check_file(void) ext_name0.push_back("tim"); ext_name.clear(); - for(i=0;i<(int)ext_name0.size();i++){ - in_file_new=locfilename+"."+ext_name0[i]; - in_file_old=locfilepath+getPathSepatator()+"_CHEM_STATE"+getPathSepatator()+proj_name+"."+ext_name0[i]; - if(!IO::file_compare(in_file_new,in_file_old)) + for (i = 0; i < (int)ext_name0.size(); i++) + { + in_file_new = locfilename + "." + ext_name0[i]; + in_file_old + = locfilepath + getPathSepatator() + "_CHEM_STATE" + getPathSepatator() + proj_name + "." + ext_name0[i]; + if (!IO::file_compare(in_file_new, in_file_old)) ext_name.push_back(ext_name0[i]); } - for(i=0;i<(int)ext_name.size();i++){ - in_file_new=locfilename+"."+ext_name[i]; - in_file_old=locfilepath+getPathSepatator()+"_CHEM_STATE"+getPathSepatator()+proj_name+"."+ext_name[i]; - f=OGS_keyword_check(in_file_new,in_file_old,ext_name[i]); - if(f==1) + for (i = 0; i < (int)ext_name.size(); i++) + { + in_file_new = locfilename + "." + ext_name[i]; + in_file_old + = locfilepath + getPathSepatator() + "_CHEM_STATE" + getPathSepatator() + proj_name + "." + ext_name[i]; + f = OGS_keyword_check(in_file_new, in_file_old, ext_name[i]); + if (f == 1) cout << in_file_new << " is removed " << endl; - if(f==-1) + if (f == -1) cout << in_file_new << " is added " << endl; } - - return success; } - -int OGS_keyword_check(std::string in_file_new, std::string in_file_old, std::string ext_name){ - - ifstream in_new,in_old; +int OGS_keyword_check(std::string in_file_new, std::string in_file_old, std::string ext_name) +{ + ifstream in_new, in_old; stringstream ss; - string instr_new,instr_old,instr,line_no,subkey; - int i,j,res,icount; - unsigned pos0,pos1; + string instr_new, instr_old, instr, line_no, subkey; + int i, j, res, icount; + unsigned pos0, pos1; - vector key_new,key_old,subkey_new,subkey_old,line_new,line_old,pies; + vector key_new, key_old, subkey_new, subkey_old, line_new, line_old, pies; in_new.clear(); - in_new.open(in_file_new.c_str(),ios::in); + in_new.open(in_file_new.c_str(), ios::in); in_old.clear(); - in_old.open(in_file_old.c_str(),ios::in); + in_old.open(in_file_old.c_str(), ios::in); key_new.clear(); key_old.clear(); @@ -233,14 +234,16 @@ int OGS_keyword_check(std::string in_file_new, std::string in_file_old, std::str line_new.clear(); line_old.clear(); - if(in_new.good() && in_old.good()){ - res=0; + if (in_new.good() && in_old.good()) + { + res = 0; getline(in_new, instr_new); getline(in_old, instr_old); - icount=1; + icount = 1; - while(1){ - if(in_new.eof()) + while (1) + { + if (in_new.eof()) break; icount++; ss.clear(); @@ -248,36 +251,41 @@ int OGS_keyword_check(std::string in_file_new, std::string in_file_old, std::str ss >> line_no; getline(in_new, instr_new); - pies=IO::string2vector(instr_new); - if(pies.size()>0&&pies[0].substr(0,1)!=";"){ - if(pies[0].substr(0,1)=="#"){ - instr=""; - for(i=0;i<(int)pies.size();i++) - instr=instr+" "+pies[i]; //remove more blank in one line - instr=line_no+" "+instr; + pies = IO::string2vector(instr_new); + if (pies.size() > 0 && pies[0].substr(0, 1) != ";") + { + if (pies[0].substr(0, 1) == "#") + { + instr = ""; + for (i = 0; i < (int)pies.size(); i++) + instr = instr + " " + pies[i]; // remove more blank in one line + instr = line_no + " " + instr; key_new.push_back(instr); } - else if(pies[0].substr(0,1)=="$"){ - instr=""; - for(i=0;i<(int)pies.size();i++) - instr=instr+" "+pies[i]; - subkey=instr; - instr=line_no+" "+instr; + else if (pies[0].substr(0, 1) == "$") + { + instr = ""; + for (i = 0; i < (int)pies.size(); i++) + instr = instr + " " + pies[i]; + subkey = instr; + instr = line_no + " " + instr; subkey_new.push_back(instr); } - else{ - instr=""; - for(i=0;i<(int)pies.size();i++) - instr=instr+" "+pies[i]; - instr=line_no+" "+subkey+" "+instr; + else + { + instr = ""; + for (i = 0; i < (int)pies.size(); i++) + instr = instr + " " + pies[i]; + instr = line_no + " " + subkey + " " + instr; line_new.push_back(instr); } } } - icount=1; - while(1){ - if(in_old.eof()) + icount = 1; + while (1) + { + if (in_old.eof()) break; icount++; ss.clear(); @@ -285,300 +293,325 @@ int OGS_keyword_check(std::string in_file_new, std::string in_file_old, std::str ss >> line_no; getline(in_old, instr_old); - pies=IO::string2vector(instr_old); - if(pies.size()>0&&pies[0].substr(0,1)!=";"){ - if(pies[0].substr(0,1)=="#"){ - instr=""; - for(i=0;i<(int)pies.size();i++) - instr=instr+" "+pies[i]; //remove more blank in one line - instr=line_no+" "+instr; + pies = IO::string2vector(instr_old); + if (pies.size() > 0 && pies[0].substr(0, 1) != ";") + { + if (pies[0].substr(0, 1) == "#") + { + instr = ""; + for (i = 0; i < (int)pies.size(); i++) + instr = instr + " " + pies[i]; // remove more blank in one line + instr = line_no + " " + instr; key_old.push_back(instr); } - else if(pies[0].substr(0,1)=="$"){ - instr=""; - for(i=0;i<(int)pies.size();i++) - instr=instr+" "+pies[i]; - subkey=instr; - instr=line_no+" "+instr; + else if (pies[0].substr(0, 1) == "$") + { + instr = ""; + for (i = 0; i < (int)pies.size(); i++) + instr = instr + " " + pies[i]; + subkey = instr; + instr = line_no + " " + instr; subkey_old.push_back(instr); } - else{ - instr=""; - for(i=0;i<(int)pies.size();i++) - instr=instr+" "+pies[i]; - instr=line_no+" "+subkey+" "+instr; + else + { + instr = ""; + for (i = 0; i < (int)pies.size(); i++) + instr = instr + " " + pies[i]; + instr = line_no + " " + subkey + " " + instr; line_old.push_back(instr); } } } - - if(key_new.size()>key_old.size()) + if (key_new.size() > key_old.size()) cout << " add new # key word in " << ext_name << " file!" << endl; - if(key_new.size()>key_old.size()) + if (key_new.size() > key_old.size()) cout << " remove # key word from " << ext_name << " file!" << endl; - for(i=0;i<(int)key_new.size();i++){ - for(j=0;j<(int)key_old.size();j++){ - pos1=key_new[i].find(" "); - pos0=key_old[j].find(" "); - if(key_new[i].substr(pos1)==key_old[j].substr(pos0)){ - key_new[i]=" "; - key_old[j]=" "; + for (i = 0; i < (int)key_new.size(); i++) + { + for (j = 0; j < (int)key_old.size(); j++) + { + pos1 = key_new[i].find(" "); + pos0 = key_old[j].find(" "); + if (key_new[i].substr(pos1) == key_old[j].substr(pos0)) + { + key_new[i] = " "; + key_old[j] = " "; } } } - for(i=0;i<(int)subkey_new.size();i++){ - for(j=0;j<(int)subkey_old.size();j++){ - pos1=subkey_new[i].find(" "); - pos0=subkey_old[j].find(" "); - if(subkey_new[i].substr(pos1)==subkey_old[j].substr(pos0)){ - subkey_new[i]=" "; - subkey_old[j]=" "; + for (i = 0; i < (int)subkey_new.size(); i++) + { + for (j = 0; j < (int)subkey_old.size(); j++) + { + pos1 = subkey_new[i].find(" "); + pos0 = subkey_old[j].find(" "); + if (subkey_new[i].substr(pos1) == subkey_old[j].substr(pos0)) + { + subkey_new[i] = " "; + subkey_old[j] = " "; } } } - for(i=0;i<(int)line_new.size();i++){ - for(j=0;j<(int)line_old.size();j++){ - pos1=line_new[i].find(" "); - pos0=line_old[j].find(" "); - if(line_new[i].substr(pos1)==line_old[j].substr(pos0)){ - line_new[i]=" "; - line_old[j]=" "; + for (i = 0; i < (int)line_new.size(); i++) + { + for (j = 0; j < (int)line_old.size(); j++) + { + pos1 = line_new[i].find(" "); + pos0 = line_old[j].find(" "); + if (line_new[i].substr(pos1) == line_old[j].substr(pos0)) + { + line_new[i] = " "; + line_old[j] = " "; } } } - key_new=IO::vector_reduce(key_new); - key_old=IO::vector_reduce(key_old); - subkey_new=IO::vector_reduce(subkey_new); - subkey_old=IO::vector_reduce(subkey_old); - line_new=IO::vector_reduce(line_new); - line_old=IO::vector_reduce(line_old); - - - for(i=0;i<(int)key_new.size();i++) cout << ext_name << " file: Line. " << key_new[i] << " -> not consistent !" << endl; - for(i=0;i<(int)key_old.size();i++) cout << ext_name << " file: Line. " << key_old[i] << " -> changed !" << endl; - for(i=0;i<(int)subkey_new.size();i++) cout << ext_name << " file: Line. " << subkey_new[i] << " -> not consistent !" << endl; - for(i=0;i<(int)subkey_old.size();i++) cout << ext_name << " file: Line. " << subkey_old[i] << " -> changed !" << endl; - for(i=0;i<(int)line_new.size();i++) cout << ext_name << " file: Line. " << line_new[i] << " -> not consistent !" << endl; - for(i=0;i<(int)line_old.size();i++) cout << ext_name << " file: Line. " << line_old[i] << " -> changed !" << endl; - + key_new = IO::vector_reduce(key_new); + key_old = IO::vector_reduce(key_old); + subkey_new = IO::vector_reduce(subkey_new); + subkey_old = IO::vector_reduce(subkey_old); + line_new = IO::vector_reduce(line_new); + line_old = IO::vector_reduce(line_old); + + for (i = 0; i < (int)key_new.size(); i++) + cout << ext_name << " file: Line. " << key_new[i] << " -> not consistent !" << endl; + for (i = 0; i < (int)key_old.size(); i++) + cout << ext_name << " file: Line. " << key_old[i] << " -> changed !" << endl; + for (i = 0; i < (int)subkey_new.size(); i++) + cout << ext_name << " file: Line. " << subkey_new[i] << " -> not consistent !" << endl; + for (i = 0; i < (int)subkey_old.size(); i++) + cout << ext_name << " file: Line. " << subkey_old[i] << " -> changed !" << endl; + for (i = 0; i < (int)line_new.size(); i++) + cout << ext_name << " file: Line. " << line_new[i] << " -> not consistent !" << endl; + for (i = 0; i < (int)line_old.size(); i++) + cout << ext_name << " file: Line. " << line_old[i] << " -> changed !" << endl; } - else{ - if(!in_new.good() && in_old.good()) - res=1; - else if(!in_old.good() && in_new.good()) - res=-1; - else if(!in_new.good() && !in_old.good()) - res=2; + else + { + if (!in_new.good() && in_old.good()) + res = 1; + else if (!in_old.good() && in_new.good()) + res = -1; + else if (!in_new.good() && !in_old.good()) + res = 2; } return res; } - void read_file(void) { stringstream ss; ifstream in; - string file_name,instr; + string file_name, instr; vector idx; - long int ip,i; + long int ip, i; CHEM_STATE.clear(); CHEM_STATE_AP.clear(); - ss.clear(); + ss.clear(); ss << FilePath << "_CHEM_STATE" << getPathSepatator() << "T" << CAP_Time << "N" << CAP_Node << "C" << CAP_icount; ss >> file_name; - //cout << file_name << "\n"; - //read file to vector + // cout << file_name << "\n"; + // read file to vector in.clear(); - in.open(file_name.c_str(),ios::in); - if(in.good()){ - while(1){ - if(in.eof()) break; + in.open(file_name.c_str(), ios::in); + if (in.good()) + { + while (1) + { + if (in.eof()) + break; getline(in, instr); - //CHEM_STATE.push_back(REACT_PRQ::string2vector(instr)); + // CHEM_STATE.push_back(REACT_PRQ::string2vector(instr)); CHEM_STATE.push_back(REACTINT::string2vector(instr)); - std::cout << "CHEM_STATE pushback: size: " << CHEM_STATE.size() << " CAP_Time: " << CAP_Time << " CaP_Node: " << CAP_Node << " CAP_icount: " << CAP_icount << " f:" << file_name << "\n"; + std::cout << "CHEM_STATE pushback: size: " << CHEM_STATE.size() << " CAP_Time: " << CAP_Time + << " CaP_Node: " << CAP_Node << " CAP_icount: " << CAP_icount << " f:" << file_name << "\n"; } } in.close(); - file_name +="_AP"; + file_name += "_AP"; in.clear(); - in.open(file_name.c_str(),ios::in); - if(in.good()){ - while(1){ - if(in.eof()) break; + in.open(file_name.c_str(), ios::in); + if (in.good()) + { + while (1) + { + if (in.eof()) + break; getline(in, instr); - //CHEM_STATE_AP.push_back(REACT_PRQ::string2vector(instr)); + // CHEM_STATE_AP.push_back(REACT_PRQ::string2vector(instr)); CHEM_STATE_AP.push_back(REACTINT::string2vector(instr)); } } in.close(); - if(CAP_count==1){ + if (CAP_count == 1) + { PHASE_CONSTI_MAP.clear(); idx.clear(); - ip=0; - for(i=0;i<(int)CHEM_STATE.size();i++){ - if(atoi(CHEM_STATE[i][0].c_str())>ip){ + ip = 0; + for (i = 0; i < (int)CHEM_STATE.size(); i++) + { + if (atoi(CHEM_STATE[i][0].c_str()) > ip) + { PHASE_CONSTI_MAP.push_back(idx); idx.clear(); idx.push_back(i); - ip=atoi(CHEM_STATE[i][0].c_str()); + ip = atoi(CHEM_STATE[i][0].c_str()); } else idx.push_back(i); } - PHASE_CONSTI_MAP.push_back(idx); + PHASE_CONSTI_MAP.push_back(idx); } } - #ifdef OGS_FEM_CAP // CAP_REACT -int CAP_tqce (CHP OPTION, LI INDEXP, LI INDEXC, DBP VALS, LIP NOERR) +int CAP_tqce(CHP OPTION, LI INDEXP, LI INDEXC, DBP VALS, LIP NOERR) #else -int CAP_tqce (CHP, LI, LI, DBP, LIP) +int CAP_tqce(CHP, LI, LI, DBP, LIP) #endif { CAP_count++; CAP_icount++; - if(CAP_MODE==0){ //normal chemapp + if (CAP_MODE == 0) + { // normal chemapp #ifdef OGS_FEM_CAP // CAP_REACT - return tqce(OPTION,INDEXP,INDEXC,VALS,NOERR); + return tqce(OPTION, INDEXP, INDEXC, VALS, NOERR); #else - return -1; //CB should not occur + return -1; // CB should not occur #endif - } - else if(CAP_MODE==1) //using chemapp to create chemical state files + } + else if (CAP_MODE == 1) // using chemapp to create chemical state files { #ifdef OGS_FEM_CAP // CAP_REACT - int res =tqce(OPTION,INDEXP,INDEXC,VALS,NOERR); + int res = tqce(OPTION, INDEXP, INDEXC, VALS, NOERR); write_file(); return res; #else - return -1; //CB should not occur + return -1; // CB should not occur #endif } - else if(CAP_MODE==2) //file mode, without real chemapp + else if (CAP_MODE == 2) // file mode, without real chemapp { read_file(); return 0; } - else - return -1; + else + return -1; } #ifdef OGS_FEM_CAP // CAP_REACT -int CAP_tqcel (CHP OPTION, LI INDEXP, LI INDEXC, DBP VALS, LIP NOERR) +int CAP_tqcel(CHP OPTION, LI INDEXP, LI INDEXC, DBP VALS, LIP NOERR) #else -int CAP_tqcel (CHP, LI, LI, DBP, LIP) +int CAP_tqcel(CHP, LI, LI, DBP, LIP) #endif { - CAP_count++; CAP_icount++; - if(CAP_MODE==0){ //normal chemapp + if (CAP_MODE == 0) + { // normal chemapp #ifdef OGS_FEM_CAP // CAP_REACT - return tqcel(OPTION,INDEXP,INDEXC,VALS,NOERR); + return tqcel(OPTION, INDEXP, INDEXC, VALS, NOERR); #else - return -1; //CB should not occur + return -1; // CB should not occur #endif - } - else if(CAP_MODE==1) //using chemapp to create chemical state files + } + else if (CAP_MODE == 1) // using chemapp to create chemical state files { #ifdef OGS_FEM_CAP // CAP_REACT - int res=tqcel(OPTION,INDEXP,INDEXC,VALS,NOERR); + int res = tqcel(OPTION, INDEXP, INDEXC, VALS, NOERR); write_file(); return res; #else - return -1; //CB should not occur + return -1; // CB should not occur #endif } - else if(CAP_MODE==2) //file mode, without real chemapp + else if (CAP_MODE == 2) // file mode, without real chemapp { read_file(); return 0; } - else - return -1; //CB should not occur + else + return -1; // CB should not occur } #ifdef OGS_FEM_CAP // CAP_REACT -int CAP_tqcen (CHP OPTION, LI INDEXP, LI INDEXC, DBP VALS, LIP NOERR) +int CAP_tqcen(CHP OPTION, LI INDEXP, LI INDEXC, DBP VALS, LIP NOERR) #else -int CAP_tqcen (CHP, LI, LI, DBP, LIP) +int CAP_tqcen(CHP, LI, LI, DBP, LIP) #endif { CAP_count++; CAP_icount++; - if(CAP_MODE==0){ //normal chemapp + if (CAP_MODE == 0) + { // normal chemapp #ifdef OGS_FEM_CAP // CAP_REACT - return tqcen(OPTION,INDEXP,INDEXC,VALS,NOERR); + return tqcen(OPTION, INDEXP, INDEXC, VALS, NOERR); #else - return -1; //CB should not occur + return -1; // CB should not occur #endif - } - else if(CAP_MODE==1) //using chemapp to create chemical state files + } + else if (CAP_MODE == 1) // using chemapp to create chemical state files { #ifdef OGS_FEM_CAP // CAP_REACT - int res=tqcen(OPTION,INDEXP,INDEXC,VALS,NOERR); + int res = tqcen(OPTION, INDEXP, INDEXC, VALS, NOERR); write_file(); return res; #else - return -1; //CB should not occur + return -1; // CB should not occur #endif } - else if(CAP_MODE==2) //file mode, without real chemapp + else if (CAP_MODE == 2) // file mode, without real chemapp { read_file(); return 0; } - else - return -1; //CB should not occur + else + return -1; // CB should not occur } #ifdef OGS_FEM_CAP // CAP_REACT -int CAP_tqcenl (CHP OPTION, LI INDEXP, LI INDEXC, DBP VALS, LIP NOERR) +int CAP_tqcenl(CHP OPTION, LI INDEXP, LI INDEXC, DBP VALS, LIP NOERR) #else -int CAP_tqcenl (CHP, LI, LI, DBP, LIP) +int CAP_tqcenl(CHP, LI, LI, DBP, LIP) #endif { CAP_count++; CAP_icount++; - if(CAP_MODE==0) { //normal chemapp + if (CAP_MODE == 0) + { // normal chemapp #ifdef OGS_FEM_CAP // CAP_REACT - return tqcenl(OPTION,INDEXP,INDEXC,VALS,NOERR); + return tqcenl(OPTION, INDEXP, INDEXC, VALS, NOERR); #else - return -1; //CB should not occur + return -1; // CB should not occur #endif - }//normal chemapp - else if(CAP_MODE==1) //using chemapp to create chemical state files + } // normal chemapp + else if (CAP_MODE == 1) // using chemapp to create chemical state files { #ifdef OGS_FEM_CAP // CAP_REACT - int res=tqcenl(OPTION,INDEXP,INDEXC,VALS,NOERR); + int res = tqcenl(OPTION, INDEXP, INDEXC, VALS, NOERR); write_file(); return res; #else - return -1; //CB should not occur + return -1; // CB should not occur #endif } - else if(CAP_MODE==2) //file mode, without real chemapp + else if (CAP_MODE == 2) // file mode, without real chemapp { read_file(); return 0; } - else - return -1; //CB should not occur + else + return -1; // CB should not occur } - - - #ifdef OGS_FEM_CAP // CAP_REACT int CAP_tqgetr(CHP OPTION, LI INDEXP, LI INDEX, DBP VAL, LIP NOERR) #else @@ -586,505 +619,605 @@ int CAP_tqgetr(CHP OPTION, LI INDEXP, LI INDEX, DBP VAL, LIP) #endif { int i; - if(CAP_MODE==0 || CAP_MODE==1){ //normal chemapp or //using chemapp to create chemical state files + if (CAP_MODE == 0 || CAP_MODE == 1) + { // normal chemapp or //using chemapp to create chemical state files #ifdef OGS_FEM_CAP // CAP_REACT return tqgetr(OPTION, INDEXP, INDEX, VAL, NOERR); #else - return -1; //CB should not occur + return -1; // CB should not occur #endif - } - else if(CAP_MODE==2) //file mode, without real chemapp + } + else if (CAP_MODE == 2) // file mode, without real chemapp { - if(strcmp(OPTION,"ap")==0) + if (strcmp(OPTION, "ap") == 0) VAL[0] = atof(CHEM_STATE_AP[INDEX][2].c_str()); - else{ - for(i=0;i<(int)CHEM_STATE[0].size();i++) - if(OPTION==CHEM_STATE[0][i]) + else + { + for (i = 0; i < (int)CHEM_STATE[0].size(); i++) + if (OPTION == CHEM_STATE[0][i]) break; - if(INDEX>0) - VAL[0] = atof(CHEM_STATE[PHASE_CONSTI_MAP[INDEXP][INDEX-1]][i].c_str()); - else if(INDEX==0) + if (INDEX > 0) + VAL[0] = atof(CHEM_STATE[PHASE_CONSTI_MAP[INDEXP][INDEX - 1]][i].c_str()); + else if (INDEX == 0) VAL[0] = atof(CHEM_STATE[PHASE_CONSTI_MAP[INDEXP][INDEX]][i].c_str()); } return 0; } - else - return -1; //CB should not occur + else + return -1; // CB should not occur } #ifdef OGS_FEM_CAP // CAP_REACT -int CAP_tqgdpc(CHP OPTION, LI INDEXP, LI INDEXC,DBP VAL, LIP NOERR) +int CAP_tqgdpc(CHP OPTION, LI INDEXP, LI INDEXC, DBP VAL, LIP NOERR) #else -int CAP_tqgdpc(CHP OPTION, LI INDEXP, LI INDEXC,DBP VAL, LIP) +int CAP_tqgdpc(CHP OPTION, LI INDEXP, LI INDEXC, DBP VAL, LIP) #endif { int i; - if(CAP_MODE==0 || CAP_MODE==1){ //normal chemapp or //using chemapp to create chemical state files + if (CAP_MODE == 0 || CAP_MODE == 1) + { // normal chemapp or //using chemapp to create chemical state files #ifdef OGS_FEM_CAP // CAP_REACT return tqgdpc(OPTION, INDEXP, INDEXC, VAL, NOERR); #else - return -1; //CB should not occur + return -1; // CB should not occur #endif - } - else if(CAP_MODE==2) //file mode, without real chemapp + } + else if (CAP_MODE == 2) // file mode, without real chemapp { - for(i=0;i<(int)CHEM_STATE[0].size();i++) - if(OPTION==CHEM_STATE[0][i]) + for (i = 0; i < (int)CHEM_STATE[0].size(); i++) + if (OPTION == CHEM_STATE[0][i]) break; - if(INDEXC>0) - VAL[0] = atof(CHEM_STATE[PHASE_CONSTI_MAP[INDEXP][INDEXC-1]][i].c_str()); - else if(INDEXC==0) + if (INDEXC > 0) + VAL[0] = atof(CHEM_STATE[PHASE_CONSTI_MAP[INDEXP][INDEXC - 1]][i].c_str()); + else if (INDEXC == 0) VAL[0] = atof(CHEM_STATE[PHASE_CONSTI_MAP[INDEXP][INDEXC]][i].c_str()); return 0; } - else - return -1; //CB should not occur + else + return -1; // CB should not occur } - -int CAP_tqini (LIP NOERR){ - if(CAP_MODE==0 || CAP_MODE==1){ +int CAP_tqini(LIP NOERR) +{ + if (CAP_MODE == 0 || CAP_MODE == 1) + { #ifdef OGS_FEM_CAP // CAP_REACT - return tqini (NOERR); + return tqini(NOERR); #else - return -1; //CB should not occur + return -1; // CB should not occur #endif - } - else{ + } + else + { read_file(); - *NOERR=0; + *NOERR = 0; return 0; - } + } } #ifdef OGS_FEM_CAP // CAP_REACT -int CAP_tqvers(LIP NVERS, LIP NOERR){ +int CAP_tqvers(LIP NVERS, LIP NOERR) +{ #else -int CAP_tqvers(LIP, LIP NOERR){ +int CAP_tqvers(LIP, LIP NOERR) +{ #endif - if(CAP_MODE==0 || CAP_MODE==1){ + if (CAP_MODE == 0 || CAP_MODE == 1) + { #ifdef OGS_FEM_CAP // CAP_REACT return tqvers(NVERS, NOERR); #else - return -1; //CB should not occur + return -1; // CB should not occur #endif - } - else{ - *NOERR=0; + } + else + { + *NOERR = 0; return 0; } } #ifdef OGS_FEM_CAP // CAP_REACT -int CAP_tqopna(CHP FILE, LI LUN, LIP NOERR){ +int CAP_tqopna(CHP FILE, LI LUN, LIP NOERR) +{ #else -int CAP_tqopna(CHP, LI, LIP NOERR){ +int CAP_tqopna(CHP, LI, LIP NOERR) +{ #endif - if(CAP_MODE==0 || CAP_MODE==1){ + if (CAP_MODE == 0 || CAP_MODE == 1) + { #ifdef OGS_FEM_CAP // CAP_REACT return tqopna(FILE, LUN, NOERR); #else - return -1; //CB should not occur + return -1; // CB should not occur #endif - } - else{ - *NOERR=0; + } + else + { + *NOERR = 0; return 0; } } #ifdef OGS_FEM_CAP // CAP_REACT -int CAP_tqopnb(CHP FILE, LI LUN, LIP NOERR){ +int CAP_tqopnb(CHP FILE, LI LUN, LIP NOERR) +{ #else - int CAP_tqopnb(CHP, LI, LIP NOERR){ +int CAP_tqopnb(CHP, LI, LIP NOERR) +{ #endif - if(CAP_MODE==0 || CAP_MODE==1){ + if (CAP_MODE == 0 || CAP_MODE == 1) + { #ifdef OGS_FEM_CAP // CAP_REACT return tqopnb(FILE, LUN, NOERR); #else - return -1; //CB should not occur + return -1; // CB should not occur #endif - } - else{ - *NOERR=0; + } + else + { + *NOERR = 0; return 0; } } #ifdef OGS_FEM_CAP // CAP_REACT -int CAP_tqopnt(CHP FILE, LI LUN, LIP NOERR){ +int CAP_tqopnt(CHP FILE, LI LUN, LIP NOERR) +{ #else -int CAP_tqopnt(CHP, LI, LIP NOERR){ +int CAP_tqopnt(CHP, LI, LIP NOERR) +{ #endif - if(CAP_MODE==0 || CAP_MODE==1){ + if (CAP_MODE == 0 || CAP_MODE == 1) + { #ifdef OGS_FEM_CAP // CAP_REACT return tqopnt(FILE, LUN, NOERR); #else - return -1; //CB should not occur + return -1; // CB should not occur #endif - } - else{ - *NOERR=0; + } + else + { + *NOERR = 0; return 0; } } #ifdef OGS_FEM_CAP // CAP_REACT -int CAP_tqclos(LI LUN, LIP NOERR){ +int CAP_tqclos(LI LUN, LIP NOERR) +{ #else -int CAP_tqclos(LI, LIP NOERR){ +int CAP_tqclos(LI, LIP NOERR) +{ #endif - if(CAP_MODE==0 || CAP_MODE==1){ + if (CAP_MODE == 0 || CAP_MODE == 1) + { #ifdef OGS_FEM_CAP // CAP_REACT return tqclos(LUN, NOERR); #else - return -1; //CB should not occur + return -1; // CB should not occur #endif - } - else{ - *NOERR=0; + } + else + { + *NOERR = 0; return 0; } } -int CAP_tqrfil(LIP NOERR){ - if(CAP_MODE==0 || CAP_MODE==1){ +int CAP_tqrfil(LIP NOERR) +{ + if (CAP_MODE == 0 || CAP_MODE == 1) + { #ifdef OGS_FEM_CAP // CAP_REACT return tqrfil(NOERR); #else - return -1; //CB should not occur + return -1; // CB should not occur #endif - } - else{ - *NOERR=0; + } + else + { + *NOERR = 0; return 0; } } -int CAP_tqrbin(LIP NOERR){ - if(CAP_MODE==0 || CAP_MODE==1){ +int CAP_tqrbin(LIP NOERR) +{ + if (CAP_MODE == 0 || CAP_MODE == 1) + { #ifdef OGS_FEM_CAP // CAP_REACT return tqrbin(NOERR); #else - return -1; //CB should not occur + return -1; // CB should not occur #endif - } - else{ - *NOERR=0; + } + else + { + *NOERR = 0; return 0; } } -int CAP_tqrcst(LIP NOERR){ - if(CAP_MODE==0 || CAP_MODE==1){ +int CAP_tqrcst(LIP NOERR) +{ + if (CAP_MODE == 0 || CAP_MODE == 1) + { #ifdef OGS_FEM_CAP // CAP_REACT return tqrcst(NOERR); #else - return -1; //CB should not occur + return -1; // CB should not occur #endif - } - else{ - *NOERR=0; + } + else + { + *NOERR = 0; return 0; } } -int CAP_tqnosc(LIP NSCOM, LIP NOERR){ - if(CAP_MODE==0 || CAP_MODE==1){ +int CAP_tqnosc(LIP NSCOM, LIP NOERR) +{ + if (CAP_MODE == 0 || CAP_MODE == 1) + { #ifdef OGS_FEM_CAP // CAP_REACT return tqnosc(NSCOM, NOERR); #else - return -1; //CB should not occur + return -1; // CB should not occur #endif - } - else{ - NSCOM[0]=(int)CHEM_STATE_AP.size()-1; - *NOERR=0; + } + else + { + NSCOM[0] = (int)CHEM_STATE_AP.size() - 1; + *NOERR = 0; return 0; } } #ifdef OGS_FEM_CAP // CAP_REACT -int CAP_tqgnsc(LI INDEXS, CHP NAME, LIP NOERR){ +int CAP_tqgnsc(LI INDEXS, CHP NAME, LIP NOERR) +{ #else -int CAP_tqgnsc(LI, CHP, LIP NOERR){ +int CAP_tqgnsc(LI, CHP, LIP NOERR) +{ #endif - if(CAP_MODE==0 || CAP_MODE==1){ + if (CAP_MODE == 0 || CAP_MODE == 1) + { #ifdef OGS_FEM_CAP // CAP_REACT return tqgnsc(INDEXS, NAME, NOERR); #else - return -1; //CB should not occur + return -1; // CB should not occur #endif - } - else{ - *NOERR=0; + } + else + { + *NOERR = 0; return 0; } } #ifdef OGS_FEM_CAP // CAP_REACT -int CAP_tqnop (LIP NPHASE, LIP NOERR){ +int CAP_tqnop(LIP NPHASE, LIP NOERR) +{ #else -int CAP_tqnop (LIP, LIP NOERR){ +int CAP_tqnop(LIP, LIP NOERR) +{ #endif - if(CAP_MODE==0 || CAP_MODE==1){ + if (CAP_MODE == 0 || CAP_MODE == 1) + { #ifdef OGS_FEM_CAP // CAP_REACT - return tqnop (NPHASE, NOERR); + return tqnop(NPHASE, NOERR); #else - return -1; //CB should not occur + return -1; // CB should not occur #endif - } - else{ - *NOERR=0; + } + else + { + *NOERR = 0; return 0; } } #ifdef OGS_FEM_CAP // CAP_REACT -int CAP_tqgnp (LI INDEXP, CHP NAME, LIP NOERR){ +int CAP_tqgnp(LI INDEXP, CHP NAME, LIP NOERR) +{ #else -int CAP_tqgnp (LI, CHP, LIP NOERR){ +int CAP_tqgnp(LI, CHP, LIP NOERR) +{ #endif - if(CAP_MODE==0 || CAP_MODE==1){ + if (CAP_MODE == 0 || CAP_MODE == 1) + { #ifdef OGS_FEM_CAP // CAP_REACT - return tqgnp (INDEXP, NAME, NOERR); + return tqgnp(INDEXP, NAME, NOERR); #else - return -1; //CB should not occur + return -1; // CB should not occur #endif - } - else{ - *NOERR=0; + } + else + { + *NOERR = 0; return 0; } } #ifdef OGS_FEM_CAP // CAP_REACT -int CAP_tqnopc(LI INDEXP, LIP NPCON, LIP NOERR){ +int CAP_tqnopc(LI INDEXP, LIP NPCON, LIP NOERR) +{ #else -int CAP_tqnopc(LI, LIP, LIP NOERR){ +int CAP_tqnopc(LI, LIP, LIP NOERR) +{ #endif - if(CAP_MODE==0 || CAP_MODE==1){ + if (CAP_MODE == 0 || CAP_MODE == 1) + { #ifdef OGS_FEM_CAP // CAP_REACT return tqnopc(INDEXP, NPCON, NOERR); #else - return -1; //CB should not occur + return -1; // CB should not occur #endif - } - else{ - *NOERR=0; + } + else + { + *NOERR = 0; return 0; } } #ifdef OGS_FEM_CAP // CAP_REACT -int CAP_tqgnpc(LI INDEXP, LI INDEXC, CHP NAME, LIP NOERR){ +int CAP_tqgnpc(LI INDEXP, LI INDEXC, CHP NAME, LIP NOERR) +{ #else -int CAP_tqgnpc(LI, LI, CHP, LIP NOERR){ +int CAP_tqgnpc(LI, LI, CHP, LIP NOERR) +{ #endif - if(CAP_MODE==0 || CAP_MODE==1){ + if (CAP_MODE == 0 || CAP_MODE == 1) + { #ifdef OGS_FEM_CAP // CAP_REACT return tqgnpc(INDEXP, INDEXC, NAME, NOERR); #else - return -1; //CB should not occur + return -1; // CB should not occur #endif - } - else{ - *NOERR=0; + } + else + { + *NOERR = 0; return 0; } } -int CAP_tqinp (CHP NAME, LIP INDEXP, LIP NOERR){ +int CAP_tqinp(CHP NAME, LIP INDEXP, LIP NOERR) +{ size_t i; - if(CAP_MODE==0 || CAP_MODE==1){ + if (CAP_MODE == 0 || CAP_MODE == 1) + { #ifdef OGS_FEM_CAP // CAP_REACT - return tqinp (NAME, INDEXP, NOERR); + return tqinp(NAME, INDEXP, NOERR); #else - return -1; //CB should not occur + return -1; // CB should not occur #endif - } - else{ - for(i=0;i -//using namespace std; +// using namespace std; #ifndef OGS_FEM_CAP // CAP_REACT - #ifdef UNIX - #define LI long - #define LIP long* - #define LNT long - #define DB double - #define DBP double* - #define CHP char* - #define CMT extern int - #define VDP void* - #define ftnlen long /* FORTRAN string length type */ - #else - #define LI long /* unsigned int */ - #define LIP long* /* unsigned int* */ - #define LNT long /* unsigned int */ - #define DB double /* double */ - #define DBP double* /* double* */ - #define CHP char* /* char* */ - #define CMT void __stdcall /* void __stdcall */ - #define VDP void* /* void* */ - #endif +#ifdef UNIX +#define LI long +#define LIP long* +#define LNT long +#define DB double +#define DBP double* +#define CHP char* +#define CMT extern int +#define VDP void* +#define ftnlen long /* FORTRAN string length type */ +#else +#define LI long /* unsigned int */ +#define LIP long* /* unsigned int* */ +#define LNT long /* unsigned int */ +#define DB double /* double */ +#define DBP double* /* double* */ +#define CHP char* /* char* */ +#define CMT void __stdcall /* void __stdcall */ +#define VDP void* /* void* */ +#endif #endif - - - extern int CAP_MODE, CAP_Time, CAP_Node, CAP_icount, CAP_count; -extern std::vector > CHEM_STATE,CHEM_STATE_AP; +extern std::vector > CHEM_STATE, CHEM_STATE_AP; extern std::vector > PHASE_CONSTI_MAP; extern bool CAP_check_file(void); extern int OGS_keyword_check(std::string in_file_new, std::string in_file_old, std::string ext_name); -extern int CAP_tqini (LIP NOERR); +extern int CAP_tqini(LIP NOERR); extern int CAP_tqopen(CHP FILE, LI LUN, LIP NOERR); extern int CAP_tqclos(LI LUN, LIP NOERR); -extern int CAP_tqgio (CHP OPTION, LIP IVAL, LIP NOERR); -extern int CAP_tqcio (CHP OPTION, LI IVAL, LIP NOERR); +extern int CAP_tqgio(CHP OPTION, LIP IVAL, LIP NOERR); +extern int CAP_tqcio(CHP OPTION, LI IVAL, LIP NOERR); extern int CAP_tqrfil(LIP NOERR); -extern int CAP_tqgsu (CHP OPTION, CHP UNIT, LIP NOERR); -extern int CAP_tqcsu (CHP OPTION, CHP UNIT, LIP NOERR); +extern int CAP_tqgsu(CHP OPTION, CHP UNIT, LIP NOERR); +extern int CAP_tqcsu(CHP OPTION, CHP UNIT, LIP NOERR); extern int CAP_tqinsc(CHP NAME, LIP INDEXS, LIP NOERR); extern int CAP_tqgnsc(LI INDEXS, CHP NAME, LIP NOERR); extern int CAP_tqnosc(LIP NSCOM, LIP NOERR); extern int CAP_tqstsc(LI INDEXS, DBP STOI, DBP WMASS, LIP NOERR); -extern int CAP_tqcsc (CHP NAME, LIP NOERR); -extern int CAP_tqinp (CHP NAME, LIP INDEXP, LIP NOERR); -extern int CAP_tqgnp (LI INDEXP, CHP NAME, LIP NOERR); -extern int CAP_tqnop (LIP NPHASE, LIP NOERR); +extern int CAP_tqcsc(CHP NAME, LIP NOERR); +extern int CAP_tqinp(CHP NAME, LIP INDEXP, LIP NOERR); +extern int CAP_tqgnp(LI INDEXP, CHP NAME, LIP NOERR); +extern int CAP_tqnop(LIP NPHASE, LIP NOERR); extern int CAP_tqinpc(CHP NAME, LI INDEXP, LIP INDEXC, LIP NOERR); extern int CAP_tqgnpc(LI INDEXP, LI INDEXC, CHP NAME, LIP NOERR); extern int CAP_tqnopc(LI INDEXP, LIP NPCON, LIP NOERR); extern int CAP_tqstpc(LI INDEXP, LI INDEXC, DBP STOI, DBP WMASS, LIP NOERR); -extern int CAP_tqgsp (LI INDEXP, CHP OPTION, LIP NOERR); -extern int CAP_tqcsp (LI INDEXP, CHP OPTION, LIP NOERR); +extern int CAP_tqgsp(LI INDEXP, CHP OPTION, LIP NOERR); +extern int CAP_tqcsp(LI INDEXP, CHP OPTION, LIP NOERR); extern int CAP_tqgspc(LI INDEXP, LI INDEXC, CHP OPTION, LIP NOERR); extern int CAP_tqcspc(LI INDEXP, LI INDEXC, CHP OPTION, LIP NOERR); extern int CAP_tqsetc(CHP OPTION, LI INDEXP, LI INDEX, DB VAL, LIP NUMCON, LIP NOERR); @@ -73,19 +70,20 @@ extern int CAP_tqsttp(CHP IDENTS, DBP VALS, LIP NOERR); extern int CAP_tqstca(CHP IDENTS, LI INDEXP, LI INDEXC, DB VAL, LIP NOERR); extern int CAP_tqstec(CHP OPTION, LI INDEXP, DB VAL, LIP NOERR); extern int CAP_tqstrm(CHP IDENTS, LIP NOERR); -extern int CAP_tqce (CHP OPTION, LI INDEXP, LI INDEXC, DBP VALS, LIP NOERR); -extern int CAP_tqcel (CHP OPTION, LI INDEXP, LI INDEXC, DBP VALS, LIP NOERR); +extern int CAP_tqce(CHP OPTION, LI INDEXP, LI INDEXC, DBP VALS, LIP NOERR); +extern int CAP_tqcel(CHP OPTION, LI INDEXP, LI INDEXC, DBP VALS, LIP NOERR); extern int CAP_tqclim(CHP OPTION, DB VAL, LIP NOERR); extern int CAP_tqgetr(CHP OPTION, LI INDEXP, LI INDEX, DBP VAL, LIP NOERR); -extern int CAP_tqgdpc(CHP OPTION, LI INDEXP, LI INDEXC,DBP VAL, LIP NOERR); +extern int CAP_tqgdpc(CHP OPTION, LI INDEXP, LI INDEXC, DBP VAL, LIP NOERR); extern int CAP_tqshow(LIP NOERR); -extern int CAP_tqerr (CHP MESS, LIP NOERR); +extern int CAP_tqerr(CHP MESS, LIP NOERR); extern int CAP_tqcprt(LIP NOERR); extern int CAP_tqvers(LIP NVERS, LIP NOERR); -extern int CAP_tqsize(LIP NA,LIP NB,LIP NC,LIP ND,LIP NE,LIP NF,LIP NG,LIP NH,LIP NI,LIP NJ,LIP NK,LIP NOERR); +extern int CAP_tqsize(LIP NA, LIP NB, LIP NC, LIP ND, LIP NE, LIP NF, LIP NG, LIP NH, LIP NI, LIP NJ, LIP NK, + LIP NOERR); extern int CAP_tqmodl(LI INDEXP, CHP NAME, LIP NOERR); -extern int CAP_tqstxp(CHP IDENTS,CHP OPTION, DBP VAL, LIP NOERR); +extern int CAP_tqstxp(CHP IDENTS, CHP OPTION, DBP VAL, LIP NOERR); extern int CAP_tqlite(LIP LITE, LIP NOERR); extern int CAP_tqrbin(LIP NOERR); extern int CAP_tqmap(CHP OPTION, LI INDEXP, LI INDEXC, DBP VALS, LIP ICONT, LIP NOERR); @@ -101,23 +99,22 @@ extern int CAP_tqgtlc(LI INDEXP, LI INDEXL, LI INDEXC, DBP VAL, LIP NOERR); /* extern int CAP_tqgopn (CHP FILE,LI LUN,CHP FFORM,CHP FSTAT,CHP FACC,LI RECL, - LIP IOSTAT,LIP NOERR); + LIP IOSTAT,LIP NOERR); */ -extern int CAP_tqbond(LI INDEXP, LI INDEXA, LI INDEXB, LI INDEXC, LI INDEXD, - DBP VAL, LIP NOERR); -extern int CAP_tqused(LIP NA,LIP NB,LIP NC,LIP ND,LIP NE,LIP NF,LIP NG,LIP NH,LIP NI, - LIP NJ,LIP NK,LIP NOERR); +extern int CAP_tqbond(LI INDEXP, LI INDEXA, LI INDEXB, LI INDEXC, LI INDEXD, DBP VAL, LIP NOERR); +extern int CAP_tqused(LIP NA, LIP NB, LIP NC, LIP ND, LIP NE, LIP NF, LIP NG, LIP NH, LIP NI, LIP NJ, LIP NK, + LIP NOERR); extern int CAP_tqgtrh(LIP TFHVER, - CHP TFHNWP, - LIP TFHVNW, - CHP TFHNRP, - LIP TFHVNR, - LIP TFHDTC, - LIP TFHDTE, - CHP TFHID, - CHP TFHUSR, - CHP TFHREM, - LIP NOERR); + CHP TFHNWP, + LIP TFHVNW, + CHP TFHNRP, + LIP TFHVNR, + LIP TFHDTC, + LIP TFHDTE, + CHP TFHID, + CHP TFHUSR, + CHP TFHREM, + LIP NOERR); extern int CAP_tqopnt(CHP FILE, LI LUN, LIP NOERR); extern int CAP_tqrcst(LIP NOERR); extern int CAP_tqgtid(CHP ID, LIP NOERR); @@ -126,7 +123,7 @@ extern int CAP_tqgtpi(CHP PID, LIP NOERR); extern int CAP_tqwstr(CHP OPTION, CHP CTXT, LIP NOERR); extern int CAP_tqgted(LIP EDMON, LIP EDYEAR, LIP NOERR); extern int CAP_tqgthi(CHP HASPT, LIP HASPID, LIP NOERR); -extern int CAP_tqcen (CHP OPTION, LI INDEXP, LI INDEXC, DBP VALS, LIP NOERR); +extern int CAP_tqcen(CHP OPTION, LI INDEXP, LI INDEXC, DBP VALS, LIP NOERR); extern int CAP_tqcenl(CHP OPTION, LI INDEXP, LI INDEXC, DBP VALS, LIP NOERR); extern int CAP_tqwasc(CHP FILE, LIP NOERR); extern int CAP_tqcdat(LI I1, LI I2, LI I3, LI I4, LI I5, DB VAL, LIP NOERR); @@ -134,4 +131,3 @@ extern int CAP_tqchar(LI INDEXP, LI INDEXC, DBP VAL, LIP NOERR); extern int CAP_tqcnsc(LI INDEXS, CHP NAME, LIP NOERR); extern int CAP_tqlpar(LI INDEXP, CHP OPTION, LIP NOPAR, CHP CHRPAR, LIP LGTPAR, LIP NOERR); extern int CAP_tqgpar(LI INDEXP, CHP OPTION, LI INDEXX, LIP NOEXPR, LIP NVALA, DBP VALA, LIP NOERR); - diff --git a/FEM/Constrained.h b/FEM/Constrained.h index b3ab17d89..2a11bdb98 100644 --- a/FEM/Constrained.h +++ b/FEM/Constrained.h @@ -12,7 +12,8 @@ #include "FEMEnums.h" -struct Constrained { +struct Constrained +{ double constrainedValue; FiniteElement::ProcessType constrainedProcessType; FiniteElement::PrimaryVariable constrainedPrimVar; @@ -20,22 +21,18 @@ struct Constrained { ConstrainedVariable::type constrainedVariable; bool _isCompleteConstrained; bool _completeConstrainedStateOff; - std::vector_constrainedNodes; + std::vector _constrainedNodes; bool _isConstrainedVelStable; bool _isSeepageBC; - Constrained () : - constrainedValue(0.0), - constrainedProcessType(FiniteElement::INVALID_PROCESS), - constrainedPrimVar(FiniteElement::INVALID_PV), - constrainedDirection(ConstrainedType::INVALID_CONSTRAINED_TYPE), - constrainedVariable(ConstrainedVariable::INVALID_CONSTRAINED_VARIABLE), - _isCompleteConstrained(false), - _completeConstrainedStateOff(false), - _isConstrainedVelStable(false), - _isSeepageBC(false) - {} - + Constrained() + : constrainedValue(0.0), constrainedProcessType(FiniteElement::INVALID_PROCESS), + constrainedPrimVar(FiniteElement::INVALID_PV), + constrainedDirection(ConstrainedType::INVALID_CONSTRAINED_TYPE), + constrainedVariable(ConstrainedVariable::INVALID_CONSTRAINED_VARIABLE), _isCompleteConstrained(false), + _completeConstrainedStateOff(false), _isConstrainedVelStable(false), _isSeepageBC(false) + { + } }; #endif diff --git a/FEM/DUMUX.cpp b/FEM/DUMUX.cpp index 685045128..39dcb4871 100644 --- a/FEM/DUMUX.cpp +++ b/FEM/DUMUX.cpp @@ -12,10 +12,10 @@ #include "rf_pcs.h" #include #include -#include // Datei streams -#include // Bildschirmausgabe +#include // Datei streams +#include // Bildschirmausgabe #include -#include // string streams (in) +#include // string streams (in) #include #include #include @@ -42,7 +42,7 @@ CReadTextfiles_DuMux::~CReadTextfiles_DuMux(void) using std::string; using std::vector; using std::cout; -//using std:"\n"; +// using std:"\n"; /*------------------------------------------------------------------------- GeoSys - Function: SplitStrings @@ -86,11 +86,12 @@ bool CReadTextfiles_DuMux::Read_Text(string Filename) string tempstring; // .data ... provides the filename as it is necessary for C, ios::in ... reads the file - std::ifstream in_file (Filename.data(),std::ios::in); + std::ifstream in_file(Filename.data(), std::ios::in); if (in_file.fail()) { error = true; - cout << "The file " << Filename.data() << " can not be opened!" << "\n"; + cout << "The file " << Filename.data() << " can not be opened!" + << "\n"; } else { @@ -98,17 +99,17 @@ bool CReadTextfiles_DuMux::Read_Text(string Filename) while ((abort == false) && (in_file.eof() == false)) { tempstring.clear(); - in_file.getline(Line,MAX_ZEILEN); + in_file.getline(Line, MAX_ZEILEN); tempstring = Line; // You could basically use this later to avoid line lenghts of pre-defined length only // getline(in_file,tempstring); - if(tempstring.length() == MAX_ZEILEN - 1) + if (tempstring.length() == MAX_ZEILEN - 1) { - cout << - " Error - increase MAX_ZEILEN in order to read ECLIPSE data file " + cout << " Error - increase MAX_ZEILEN in order to read ECLIPSE data file " + << "\n"; + cout << " Or shorten the line in " << Filename.data() << ": " << tempstring << " to " << MAX_ZEILEN + << " characters " << "\n"; - cout << " Or shorten the line in " << Filename.data() << ": " << - tempstring << " to " << MAX_ZEILEN << " characters " << "\n"; exit(0); } if (tempstring.compare("#STOP") != 0) @@ -138,12 +139,13 @@ bool CReadTextfiles_DuMux::Read_SeparatedText(string Filename, string delimiter) string tempstring; // .data ... provides the filename as it is necessary for C, ios::in ... reads the file - std::ifstream in_file (Filename.data(),std::ios::in); + std::ifstream in_file(Filename.data(), std::ios::in); if (in_file.fail()) { error = true; - cout << "The file " << Filename.data() << " can not be opened!" << "\n"; - //system("Pause"); + cout << "The file " << Filename.data() << " can not be opened!" + << "\n"; + // system("Pause"); } else { @@ -152,30 +154,29 @@ bool CReadTextfiles_DuMux::Read_SeparatedText(string Filename, string delimiter) while ((abort == false) && (in_file.eof() == false)) { tempstring.clear(); - in_file.getline(Line,MAX_ZEILEN); + in_file.getline(Line, MAX_ZEILEN); tempstring = Line; if ((this->NumberOfRows == 0) && (this->Header.size() == 0)) { - //Reading the header - this->SplitStrings(tempstring,delimiter); + // Reading the header + this->SplitStrings(tempstring, delimiter); for (int i = 0; i < int(this->SplittedString.size()); i++) this->Header.push_back(this->SplittedString[i]); this->SplittedString.clear(); } else { - this->SplitStrings(tempstring,delimiter); - //check if it is the same number of columns + this->SplitStrings(tempstring, delimiter); + // check if it is the same number of columns if (this->SplittedString.size() > 0) { if (this->SplittedString.size() != this->Header.size()) { error = true; - cout << - "The number of columns in the textfile is not constant!" + cout << "The number of columns in the textfile is not constant!" << "\n"; - //system("Pause"); + // system("Pause"); } else { @@ -248,15 +249,15 @@ CDUMUXData::~CDUMUXData(void) -------------------------------------------------------------------------*/ bool CDUMUXData::CheckIfFileExists(string strFilename) { -// code source: http://www.techbytes.ca/techbyte103.html (6.11.2009) no restriction for use + // code source: http://www.techbytes.ca/techbyte103.html (6.11.2009) no restriction for use struct stat stFileInfo; bool blnReturn; int intStat; // Attempt to get the file attributes - intStat = stat(strFilename.c_str(),&stFileInfo); - if(intStat == 0) + intStat = stat(strFilename.c_str(), &stFileInfo); + if (intStat == 0) // We were able to get the file attributes // so the file obviously exists. blnReturn = true; @@ -316,52 +317,51 @@ string CDUMUXData::AddZero(double Number, int Places, bool before) -------------------------------------------------------------------------*/ bool CDUMUXData::MakeNodeVector(void) { - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt -// CNode* m_node = NULL; -// CPointData_DuMux* m_NodeData = NULL; -// m_NodeData = new CPointData_DuMux; -// PointDuMux* node_data (NULL); - vector temp_q; + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt + // CNode* m_node = NULL; + // CPointData_DuMux* m_NodeData = NULL; + // m_NodeData = new CPointData_DuMux; + // PointDuMux* node_data (NULL); + vector temp_q; for (int i = 0; i < dim; i++) temp_q.push_back(-1.0E+99); - if(this->NodeData.size() < 1) + if (this->NodeData.size() < 1) for (unsigned long i = 0; i < m_msh->nod_vector.size(); i++) { // create new instance of CPointData -// m_NodeData = new CPointData_DuMux; - PointDuMux* node_data (new PointDuMux ( - m_msh->nod_vector[i]->getData(), - -1.0E+99, // temperature - -1.0E+99, // CO2 in liquid - -1.0E+99 // NaCl in liquid - )); - //Get the node -// m_node = m_msh->nod_vector[i]; -// m_NodeData->x = m_node->X(); -// m_NodeData->y = m_node->Y(); -// m_NodeData->z = m_node->Z(); -// m_NodeData->phase_pressure.resize(this->Phases.size()); -// m_NodeData->phase_saturation.resize(this->Phases.size()); -// m_NodeData->phase_density.resize(this->Phases.size()); + // m_NodeData = new CPointData_DuMux; + PointDuMux* node_data(new PointDuMux(m_msh->nod_vector[i]->getData(), + -1.0E+99, // temperature + -1.0E+99, // CO2 in liquid + -1.0E+99 // NaCl in liquid + )); + // Get the node + // m_node = m_msh->nod_vector[i]; + // m_NodeData->x = m_node->X(); + // m_NodeData->y = m_node->Y(); + // m_NodeData->z = m_node->Z(); + // m_NodeData->phase_pressure.resize(this->Phases.size()); + // m_NodeData->phase_saturation.resize(this->Phases.size()); + // m_NodeData->phase_density.resize(this->Phases.size()); for (size_t j = 0; j < this->Phases.size(); j++) -// m_NodeData->q.push_back(temp_q); + // m_NodeData->q.push_back(temp_q); node_data->getQ().push_back(temp_q); - //Set variable to zero -// m_NodeData->temperature = -1.0E+99; -// m_NodeData->CO2inLiquid = -1.0E+99; -// m_NodeData->NaClinLiquid = -1.0E+99; + // Set variable to zero + // m_NodeData->temperature = -1.0E+99; + // m_NodeData->CO2inLiquid = -1.0E+99; + // m_NodeData->NaClinLiquid = -1.0E+99; for (size_t k = 0; k < this->Phases.size(); k++) { -// m_NodeData->phase_pressure[k] = -1.0E+99; -// m_NodeData->phase_saturation[k] = -1.0E+99; + // m_NodeData->phase_pressure[k] = -1.0E+99; + // m_NodeData->phase_saturation[k] = -1.0E+99; node_data->getPhasePressure()[k] = -1.0E+99; node_data->getPhaseSaturation()[k] = -1.0E+99; } // transfer Data to node -// this->NodeData.push_back(m_NodeData); + // this->NodeData.push_back(m_NodeData); this->NodeData.push_back(node_data); } return true; @@ -381,14 +381,14 @@ int CDUMUXData::WriteInputForDuMux(CRFProcess* m_pcs, string Folder, long Timest string tempstring; string DOScommand; std::ostringstream temp; - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt double value; double timestep_length; - //CRFProcess *n_pcs = NULL; + // CRFProcess *n_pcs = NULL; int indexConcentration_DIC = 0; - //int indexConcentration_NaCl_dissolved; + // int indexConcentration_NaCl_dissolved; - //delete old input files + // delete old input files if (this->Windows_System == true) DOScommand = "del " + Folder + "\\dataForDumux.dat"; else @@ -397,7 +397,7 @@ int CDUMUXData::WriteInputForDuMux(CRFProcess* m_pcs, string Folder, long Timest if (system(DOScommand.c_str())) DisplayMsgLn("Could not delete input file! "); - //Read length of current timestep and recalculate it to days + // Read length of current timestep and recalculate it to days if (m_pcs->Tim->time_unit == "DAY") timestep_length = m_pcs->Tim->time_step_length * 60 * 60 * 24; else @@ -410,19 +410,20 @@ int CDUMUXData::WriteInputForDuMux(CRFProcess* m_pcs, string Folder, long Timest timestep_length = m_pcs->Tim->time_step_length; else { - cout << "This time unit was not considered yet" << "\n"; - //system("Pause"); + cout << "This time unit was not considered yet" + << "\n"; + // system("Pause"); exit(0); } } } // write timestep and length of timestep - //header + // header vec_string.clear(); - //tempstring = "Timestep Stepsize_[s] Restartfile"; - //vec_string.push_back(tempstring); - //timestep + // tempstring = "Timestep Stepsize_[s] Restartfile"; + // vec_string.push_back(tempstring); + // timestep temp.str(""); temp.clear(); temp << m_pcs->Tim->step_current - 1; @@ -432,36 +433,33 @@ int CDUMUXData::WriteInputForDuMux(CRFProcess* m_pcs, string Folder, long Timest temp.clear(); temp << timestep_length; tempstring += temp.str(); - //define Restart name + // define Restart name if (m_pcs->Tim->step_current > 1) - //tempstring += " Restart"; - tempstring += " " + m_pcs->simulator_path + "_time=" + this->AddZero( - this->TotalSimulationTime, - 3, - false) + "_rank=00000.drs"; - //tempstring += AddZero(m_pcs->Tim->step_current - 2,5,true) + ".txt"; + // tempstring += " Restart"; + tempstring += " " + m_pcs->simulator_path + "_time=" + this->AddZero(this->TotalSimulationTime, 3, false) + + "_rank=00000.drs"; + // tempstring += AddZero(m_pcs->Tim->step_current - 2,5,true) + ".txt"; vec_string.push_back(tempstring); this->TotalSimulationTime += timestep_length; if (m_pcs->Tim->step_current > 1) { // write dissolved CO2 and NaCl concentration of each node - //header + // header tempstring = "Node X Y Z X_CO2 X_NaCl rho_liquid rho_gas"; vec_string.push_back(tempstring); - //data + // data // get index of species concentration in nodevaluevector of this process - indexConcentration_DIC = - pcs_vector[this->ProcessIndex_CO2inLiquid]->GetNodeValueIndex( - pcs_vector[ - this-> - ProcessIndex_CO2inLiquid - ]->pcs_primary_function_name[0]) + 1; // +1: new timelevel - //indexConcentration_NaCl_dissolved = pcs_vector[indexProcess_NaCl_dissolved]->GetNodeValueIndex(pcs_vector[indexProcess_NaCl_dissolved]->pcs_primary_function_name[0]) + 1; // +1: new timelevel - for(unsigned long i = 0; i < m_msh->nod_vector.size(); i++) + indexConcentration_DIC = pcs_vector[this->ProcessIndex_CO2inLiquid]->GetNodeValueIndex( + pcs_vector[this->ProcessIndex_CO2inLiquid]->pcs_primary_function_name[0]) + + 1; // +1: new timelevel + // indexConcentration_NaCl_dissolved = + // pcs_vector[indexProcess_NaCl_dissolved]->GetNodeValueIndex(pcs_vector[indexProcess_NaCl_dissolved]->pcs_primary_function_name[0]) + // + 1; // +1: new timelevel + for (unsigned long i = 0; i < m_msh->nod_vector.size(); i++) { - double const* const pnt (m_msh->nod_vector[i]->getData()); + double const* const pnt(m_msh->nod_vector[i]->getData()); temp.precision(12); temp.str(""); temp.clear(); @@ -481,35 +479,34 @@ int CDUMUXData::WriteInputForDuMux(CRFProcess* m_pcs, string Folder, long Timest tempstring += " " + temp.str(); // TF commented out since we want to use the improved PointDuMux class -// value = pcs_vector[this->ProcessIndex_CO2inLiquid]->GetNodeValue(i, indexConcentration_DIC) * (this->Molweight_CO2 / 1000) / this->NodeData[i]->phase_density[0]; - value = pcs_vector[this->ProcessIndex_CO2inLiquid]->GetNodeValue( - i, - indexConcentration_DIC) - * - (this->Molweight_CO2 / - 1000) / this->NodeData[i]->getPhaseDensity()[0]; - //cout << i << " X_CO2 " << value << " C_CO2 " << pcs_vector[this->ProcessIndex_CO2inLiquid]->GetNodeValue(i, indexConcentration_DIC) << " Dichte " << this->NodeData[i]->phase_density[0] << " X_CO2_alt " << this->NodeData[i]->CO2inLiquid << "\n"; + // value = pcs_vector[this->ProcessIndex_CO2inLiquid]->GetNodeValue(i, indexConcentration_DIC) * + //(this->Molweight_CO2 / 1000) / this->NodeData[i]->phase_density[0]; + value = pcs_vector[this->ProcessIndex_CO2inLiquid]->GetNodeValue(i, indexConcentration_DIC) + * (this->Molweight_CO2 / 1000) / this->NodeData[i]->getPhaseDensity()[0]; + // cout << i << " X_CO2 " << value << " C_CO2 " << + // pcs_vector[this->ProcessIndex_CO2inLiquid]->GetNodeValue(i, indexConcentration_DIC) << " Dichte " << + // this->NodeData[i]->phase_density[0] << " X_CO2_alt " << this->NodeData[i]->CO2inLiquid << "\n"; temp.str(""); temp.clear(); temp << value; tempstring += " " + temp.str(); // TF commented out since we want to use the improved PointDuMux class -// value = this->NodeData[i]->NaClinLiquid; + // value = this->NodeData[i]->NaClinLiquid; value = this->NodeData[i]->getNaClInLiquid(); temp.str(""); temp.clear(); temp << value; tempstring += " " + temp.str(); // TF commented out since we want to use the improved PointDuMux class -// value = this->NodeData[i]->phase_density[0]; + // value = this->NodeData[i]->phase_density[0]; value = this->NodeData[i]->getPhaseDensity()[0]; temp.str(""); temp.clear(); temp << value; tempstring += " " + temp.str(); // TF commented out since we want to use the improved PointDuMux class -// value = this->NodeData[i]->phase_density[1]; + // value = this->NodeData[i]->phase_density[1]; value = this->NodeData[i]->getPhaseDensity()[1]; temp.str(""); temp.clear(); @@ -520,23 +517,23 @@ int CDUMUXData::WriteInputForDuMux(CRFProcess* m_pcs, string Folder, long Timest } } TextFile = new CWriteTextfiles_DuMux; - //int position = int(path.find_last_of("\\")); - //string path_new; - //path_new = path.substr(0,position); - //position = int(path_new.find_last_of("\\")); - //path_new = path_new.substr(0,position); + // int position = int(path.find_last_of("\\")); + // string path_new; + // path_new = path.substr(0,position); + // position = int(path_new.find_last_of("\\")); + // path_new = path_new.substr(0,position); if (this->Windows_System == true) TextFile->Write_Text(Folder + "\\dataForDumux.dat", vec_string); else TextFile->Write_Text(Folder + "/dataForDumux.dat", vec_string); //-------------------------------------------------------------------------------------------- - //Test output + // Test output MeshLib::CElem* m_ele = NULL; MeshLib::CNode* m_node = NULL; CMediumProperties* m_mat_mp = NULL; double node_volume; - //int position; + // int position; double porosity; double concentration_CO2_water; int group; @@ -556,10 +553,11 @@ int CDUMUXData::WriteInputForDuMux(CRFProcess* m_pcs, string Folder, long Timest for (int j = 0; j < int(m_node->getConnectedElementIDs().size()); j++) { m_ele = m_msh->ele_vector[m_node->getConnectedElementIDs()[j]]; - //get the phase volume of current element elem + // get the phase volume of current element elem group = m_ele->GetPatchIndex(); m_mat_mp = mmp_vector[group]; - porosity = m_mat_mp->Porosity(m_ele->GetIndex(), 1); // CB Now provides also heterogeneous porosity, model 11 + porosity + = m_mat_mp->Porosity(m_ele->GetIndex(), 1); // CB Now provides also heterogeneous porosity, model 11 node_volume = node_volume + m_ele->GetVolume() / 8 * porosity; } @@ -568,9 +566,9 @@ int CDUMUXData::WriteInputForDuMux(CRFProcess* m_pcs, string Folder, long Timest temp << i; tempstring = temp.str(); // TF commented out since we want to use the improved PointDuMux class -// temp.str(""); temp.clear(); temp << this->NodeData[i]->x; tempstring += "; " + temp.str(); -// temp.str(""); temp.clear(); temp << this->NodeData[i]->y; tempstring += "; " + temp.str(); -// temp.str(""); temp.clear(); temp << this->NodeData[i]->z; tempstring += "; " + temp.str(); + // temp.str(""); temp.clear(); temp << this->NodeData[i]->x; tempstring += "; " + temp.str(); + // temp.str(""); temp.clear(); temp << this->NodeData[i]->y; tempstring += "; " + temp.str(); + // temp.str(""); temp.clear(); temp << this->NodeData[i]->z; tempstring += "; " + temp.str(); for (size_t k(0); k < 3; k++) { temp.str(""); @@ -580,13 +578,25 @@ int CDUMUXData::WriteInputForDuMux(CRFProcess* m_pcs, string Folder, long Timest } // TF commented out since we want to use the improved PointDuMux class -// temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->phase_pressure[0]; tempstring += "; " + temp.str(); -// temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->phase_pressure[1]; tempstring += "; " + temp.str(); -// temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->phase_saturation[0]; tempstring += "; " + temp.str(); -// temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->phase_saturation[1]; tempstring += "; " + temp.str(); -// temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->phase_density[0]; tempstring += "; " + temp.str(); -// temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->phase_density[1]; tempstring += "; " + temp.str(); -// temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->CO2inLiquid; tempstring += "; " + temp.str(); + // temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->phase_pressure[0]; tempstring + //+= "; " + temp.str(); + // temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->phase_pressure[1]; tempstring + //+= "; " + temp.str(); + // temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->phase_saturation[0]; + // tempstring + //+= "; " + temp.str(); + // temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->phase_saturation[1]; + // tempstring + //+= "; " + temp.str(); + // temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->phase_density[0]; tempstring + //+= + //"; " + temp.str(); + // temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->phase_density[1]; tempstring + //+= + //"; " + temp.str(); + // temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->CO2inLiquid; tempstring += "; + //" + //+ temp.str(); temp.str(""); temp.clear(); temp.precision(12); @@ -623,16 +633,16 @@ int CDUMUXData::WriteInputForDuMux(CRFProcess* m_pcs, string Folder, long Timest temp << this->NodeData[i]->getCO2InLiquid(); tempstring += "; " + temp.str(); - concentration_CO2_water = pcs_vector[this->ProcessIndex_CO2inLiquid]->GetNodeValue( - i, - indexConcentration_DIC); + concentration_CO2_water = pcs_vector[this->ProcessIndex_CO2inLiquid]->GetNodeValue(i, indexConcentration_DIC); // TF commented out since we want to use the improved PointDuMux class -// mass_CO2_gas = node_volume * this->NodeData[i]->phase_saturation[1] * this->NodeData[i]->phase_density[1]; -// mass_CO2_water = node_volume * this->NodeData[i]->phase_saturation[0] * concentration_CO2_water * this->Molweight_CO2 * 0.001; - mass_CO2_gas = node_volume * this->NodeData[i]->getPhaseSaturation()[1] * - this->NodeData[i]->getPhaseDensity()[1]; - mass_CO2_water = node_volume * this->NodeData[i]->getPhaseSaturation()[0] * - concentration_CO2_water * this->Molweight_CO2 * 0.001; + // mass_CO2_gas = node_volume * this->NodeData[i]->phase_saturation[1] * + // this->NodeData[i]->phase_density[1]; + // mass_CO2_water = node_volume * this->NodeData[i]->phase_saturation[0] * concentration_CO2_water * + // this->Molweight_CO2 * 0.001; + mass_CO2_gas + = node_volume * this->NodeData[i]->getPhaseSaturation()[1] * this->NodeData[i]->getPhaseDensity()[1]; + mass_CO2_water = node_volume * this->NodeData[i]->getPhaseSaturation()[0] * concentration_CO2_water + * this->Molweight_CO2 * 0.001; temp.str(""); temp.clear(); @@ -648,27 +658,27 @@ int CDUMUXData::WriteInputForDuMux(CRFProcess* m_pcs, string Folder, long Timest vec_string.push_back(tempstring); } // end node loop - //Test Output + // Test Output int position; string aus_file; if (m_pcs->DuMuxData->Windows_System == true) position = Folder.find_last_of("\\"); else position = Folder.find_last_of("/"); - string path = Folder.substr(0,position); + string path = Folder.substr(0, position); if (m_pcs->DuMuxData->Windows_System == true) position = path.find_last_of("\\"); else position = path.find_last_of("/"); - path = path.substr(0,position); - //temp.str(""); temp.clear(); temp << timestep; tempstring = temp.str(); + path = path.substr(0, position); + // temp.str(""); temp.clear(); temp << timestep; tempstring = temp.str(); if (m_pcs->DuMuxData->Windows_System == true) { aus_file = path; aus_file += "\\CheckDataWroteIn_"; temp.str(""); temp.clear(); - temp << this->AddZero(Timestep, 4, true); + temp << this->AddZero(Timestep, 4, true); aus_file += temp.str(); aus_file += ".csv"; } @@ -682,7 +692,7 @@ int CDUMUXData::WriteInputForDuMux(CRFProcess* m_pcs, string Folder, long Timest aus_file += temp.str(); aus_file += ".csv"; } - std::ofstream aus (aus_file.data(), std::ios::out); + std::ofstream aus(aus_file.data(), std::ios::out); for (unsigned int i = 0; i < vec_string.size(); i++) aus << vec_string[i] << "\n"; aus.close(); @@ -702,102 +712,110 @@ void CDUMUXData::ReadDuMuxData(CRFProcess* m_pcs, string Filename, long Timestep vector files = vector(); CReadTextfiles_DuMux* TextFile; string tempstring; - //WW bool saturation_water, saturation_gas, bool saturation_oil; - clock_t start,finish; + // WW bool saturation_water, saturation_gas, bool saturation_oil; + clock_t start, finish; double time; int column; - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt MeshLib::CElem* m_ele = NULL; start = clock(); - //WW saturation_water = saturation_gas = saturation_oil = false; + // WW saturation_water = saturation_gas = saturation_oil = false; cout << " ReadDuMuxData() "; - //read dimension of the model + // read dimension of the model m_ele = m_msh->ele_vector[0]; // get element dim = m_ele->GetDimension(); - //create correct filename with the timestep + // create correct filename with the timestep Filename = Filename.replace(Filename.length() - 8, 4, this->AddZero(Timestep - 1, 4, true)); - //Reads the text file + // Reads the text file bool Error; TextFile = new CReadTextfiles_DuMux; - Error = TextFile->Read_SeparatedText(Filename," "); + Error = TextFile->Read_SeparatedText(Filename, " "); if (Error == true) { - cout << "The program is canceled" << "\n"; - //system("Pause"); + cout << "The program is canceled" + << "\n"; + // system("Pause"); exit(0); } - //index x y z p1 p2 S1 S2 qx1 qy1 qz1 qx2 qy2 qz2 X_CO2inBrine X_NaClInBrine T rho_liquid rho_gas - //check the header of the text file + // index x y z p1 p2 S1 S2 qx1 qy1 qz1 qx2 qy2 qz2 X_CO2inBrine X_NaClInBrine T rho_liquid + // rho_gas + // check the header of the text file if (this->Phases.size() == 1) - if ((TextFile->Header[0] != "index") || (TextFile->Header[1] != "x") || - (TextFile->Header[2] != "y") || (TextFile->Header[3] != "z") || - (TextFile->Header[4] != "p") || (TextFile->Header[5] != "qx") || - (TextFile->Header[6] != "qy") || (TextFile->Header[7] != "qz")) + if ((TextFile->Header[0] != "index") || (TextFile->Header[1] != "x") || (TextFile->Header[2] != "y") + || (TextFile->Header[3] != "z") + || (TextFile->Header[4] != "p") + || (TextFile->Header[5] != "qx") + || (TextFile->Header[6] != "qy") + || (TextFile->Header[7] != "qz")) { - cout << - "The header of the DUMUX result file does not fit to the definition!" << - "\n"; - //system("Pause"); + cout << "The header of the DUMUX result file does not fit to the definition!" + << "\n"; + // system("Pause"); exit(0); } if (this->Phases.size() == 2) - if ((TextFile->Header[0] != "index") || (TextFile->Header[1] != "x") || - (TextFile->Header[2] != "y") || (TextFile->Header[3] != "z") || - (TextFile->Header[4] != "p1") || (TextFile->Header[5] != "p2") || - (TextFile->Header[6] != "S1") || (TextFile->Header[7] != "S2") || - (TextFile->Header[8] != "qx1") || (TextFile->Header[9] != "qy1") || - (TextFile->Header[10] != "qz1") || (TextFile->Header[11] != "qx2") || - (TextFile->Header[12] != "qy2") || (TextFile->Header[13] != "qz2") || - (TextFile->Header[14] != "X_CO2inBrine") || - (TextFile->Header[15] != "X_NaClInBrine") || (TextFile->Header[16] != "T") || - (TextFile->Header[17] != "rho_liquid") || (TextFile->Header[18] != "rho_gas")) + if ((TextFile->Header[0] != "index") || (TextFile->Header[1] != "x") || (TextFile->Header[2] != "y") + || (TextFile->Header[3] != "z") + || (TextFile->Header[4] != "p1") + || (TextFile->Header[5] != "p2") + || (TextFile->Header[6] != "S1") + || (TextFile->Header[7] != "S2") + || (TextFile->Header[8] != "qx1") + || (TextFile->Header[9] != "qy1") + || (TextFile->Header[10] != "qz1") + || (TextFile->Header[11] != "qx2") + || (TextFile->Header[12] != "qy2") + || (TextFile->Header[13] != "qz2") + || (TextFile->Header[14] != "X_CO2inBrine") + || (TextFile->Header[15] != "X_NaClInBrine") + || (TextFile->Header[16] != "T") + || (TextFile->Header[17] != "rho_liquid") + || (TextFile->Header[18] != "rho_gas")) { - cout << - "The header of the DUMUX result file does not fit to the definition!" << - "\n"; - //system("Pause"); + cout << "The header of the DUMUX result file does not fit to the definition!" + << "\n"; + // system("Pause"); exit(0); } - //Create the nodeData structure and check the coordinates of the nodes between OGS and DUMUX + // Create the nodeData structure and check the coordinates of the nodes between OGS and DUMUX if (Timestep == 1) { this->MakeNodeVector(); - //check the number of nodes + // check the number of nodes if (int(this->NodeData.size()) != TextFile->NumberOfRows) { - cout << "The number of nodes is not equal between OGS and DUMUX! " << - this->NodeData.size() << ", " << TextFile->NumberOfRows << "\n"; - //system("Pause"); + cout << "The number of nodes is not equal between OGS and DUMUX! " << this->NodeData.size() << ", " + << TextFile->NumberOfRows << "\n"; + // system("Pause"); exit(0); } for (long i = 0; i < TextFile->NumberOfRows; i++) // TF commented out since we want to use the improved PointDuMux class -// if ((atof(TextFile->Data_separated[i][1].data()) != this->NodeData[i]->x) || (atof(TextFile->Data_separated[i][2].data()) != this->NodeData[i]->y) || (atof(TextFile->Data_separated[i][3].data()) != this->NodeData[i]->z)) { - if ((atof(TextFile->Data_separated[i][1].data()) != - (*(this->NodeData[i]))[0]) - || (atof(TextFile->Data_separated[i][2].data()) != - (*(this->NodeData[i]))[1]) - || (atof(TextFile->Data_separated[i][3].data()) != - (*(this->NodeData[i]))[2])) + // if ((atof(TextFile->Data_separated[i][1].data()) != this->NodeData[i]->x) || + //(atof(TextFile->Data_separated[i][2].data()) != this->NodeData[i]->y) || + //(atof(TextFile->Data_separated[i][3].data()) != this->NodeData[i]->z)) { + if ((atof(TextFile->Data_separated[i][1].data()) != (*(this->NodeData[i]))[0]) + || (atof(TextFile->Data_separated[i][2].data()) != (*(this->NodeData[i]))[1]) + || (atof(TextFile->Data_separated[i][3].data()) != (*(this->NodeData[i]))[2])) { - cout << - "The node coordinates are not equal between OGS and DUMUX!" << "\n"; - //system("Pause"); + cout << "The node coordinates are not equal between OGS and DUMUX!" + << "\n"; + // system("Pause"); exit(0); } } - //Read the DUMUX data + // Read the DUMUX data for (long i = 0; i < TextFile->NumberOfRows; i++) { column = 3; @@ -806,78 +824,73 @@ void CDUMUXData::ReadDuMuxData(CRFProcess* m_pcs, string Filename, long Timestep { column += 1; // TF commented out since we want to use the improved PointDuMux class -// this->NodeData[i]->phase_pressure[j] = atof(TextFile->Data_separated[i][column].data()) * Multiplier; - this->NodeData[i]->getPhasePressure()[j] = atof( - TextFile->Data_separated[i][column].data()) * Multiplier; + // this->NodeData[i]->phase_pressure[j] = atof(TextFile->Data_separated[i][column].data()) * + // Multiplier; + this->NodeData[i]->getPhasePressure()[j] = atof(TextFile->Data_separated[i][column].data()) * Multiplier; } if (this->Phases.size() > 1) for (int j = 0; j < int(this->Phases.size()); j++) { column += 1; // TF commented out since we want to use the improved PointDuMux class -// this->NodeData[i]->phase_saturation[j] = atof(TextFile->Data_separated[i][column].data()) * Multiplier; - this->NodeData[i]->getPhaseSaturation()[j] = atof( - TextFile->Data_separated[i][column].data()) * Multiplier; + // this->NodeData[i]->phase_saturation[j] = + // atof(TextFile->Data_separated[i][column].data()) + //* + // Multiplier; + this->NodeData[i]->getPhaseSaturation()[j] + = atof(TextFile->Data_separated[i][column].data()) * Multiplier; } for (int j = 0; j < int(this->Phases.size()); j++) for (int k = 0; k < 3; k++) { column += 1; // TF commented out since we want to use the improved PointDuMux class -// this->NodeData[i]->q[j][k] = atof(TextFile->Data_separated[i][column].data()) * Multiplier; - this->NodeData[i]->getQ()[j][k] = - atof(TextFile->Data_separated[i][column].data()) * - Multiplier; + // this->NodeData[i]->q[j][k] = atof(TextFile->Data_separated[i][column].data()) * + // Multiplier; + this->NodeData[i]->getQ()[j][k] = atof(TextFile->Data_separated[i][column].data()) * Multiplier; } column += 1; // TF commented out since we want to use the improved PointDuMux class -// this->NodeData[i]->CO2inLiquid = atof(TextFile->Data_separated[i][column].data()) * Multiplier; - this->NodeData[i]->setCO2InLiquid (atof( - TextFile->Data_separated[i][column].data( - )) * Multiplier); - //cout << i << " " << this->NodeData[i]->CO2inLiquid << "\n"; + // this->NodeData[i]->CO2inLiquid = atof(TextFile->Data_separated[i][column].data()) * Multiplier; + this->NodeData[i]->setCO2InLiquid(atof(TextFile->Data_separated[i][column].data()) * Multiplier); + // cout << i << " " << this->NodeData[i]->CO2inLiquid << "\n"; column += 1; // TF commented out since we want to use the improved PointDuMux class -// this->NodeData[i]->NaClinLiquid = atof(TextFile->Data_separated[i][column].data()) * Multiplier; - this->NodeData[i]->setNaClInLiquid (atof( - TextFile->Data_separated[i][column]. - data()) * Multiplier); + // this->NodeData[i]->NaClinLiquid = atof(TextFile->Data_separated[i][column].data()) * Multiplier; + this->NodeData[i]->setNaClInLiquid(atof(TextFile->Data_separated[i][column].data()) * Multiplier); column += 1; // TF commented out since we want to use the improved PointDuMux class -// this->NodeData[i]->temperature = atof(TextFile->Data_separated[i][column].data()) * Multiplier; - this->NodeData[i]->setTemperature (atof( - TextFile->Data_separated[i][column].data( - )) * Multiplier); + // this->NodeData[i]->temperature = atof(TextFile->Data_separated[i][column].data()) * Multiplier; + this->NodeData[i]->setTemperature(atof(TextFile->Data_separated[i][column].data()) * Multiplier); column += 1; // TF commented out since we want to use the improved PointDuMux class -// this->NodeData[i]->phase_density[0] = atof(TextFile->Data_separated[i][column].data()) * Multiplier; - this->NodeData[i]->getPhaseDensity()[0] = atof( - TextFile->Data_separated[i][column].data()) * Multiplier; + // this->NodeData[i]->phase_density[0] = atof(TextFile->Data_separated[i][column].data()) * Multiplier; + this->NodeData[i]->getPhaseDensity()[0] = atof(TextFile->Data_separated[i][column].data()) * Multiplier; column += 1; // TF commented out since we want to use the improved PointDuMux class -// this->NodeData[i]->phase_density[1] = atof(TextFile->Data_separated[i][column].data()) * Multiplier; - this->NodeData[i]->getPhaseDensity()[1] = atof( - TextFile->Data_separated[i][column].data()) * Multiplier; + // this->NodeData[i]->phase_density[1] = atof(TextFile->Data_separated[i][column].data()) * Multiplier; + this->NodeData[i]->getPhaseDensity()[1] = atof(TextFile->Data_separated[i][column].data()) * Multiplier; } // Release Textfile object delete (TextFile); finish = clock(); time = (double(finish) - double(start)) / CLOCKS_PER_SEC; - cout << " Time: " << time << " seconds." << "\n"; + cout << " Time: " << time << " seconds." + << "\n"; //-------------------------------------------------------------------------------------------- - //Test output + // Test output MeshLib::CNode* m_node = NULL; CMediumProperties* m_mat_mp = NULL; std::ostringstream temp; double mass_CO2_gas, mass_CO2_water; // unused:, mass_CO2; double node_volume; - vector vec_string; - //int position; + vector vec_string; + // int position; double porosity; double concentration_CO2_water; - //CRFProcess *n_pcs = NULL; + // CRFProcess *n_pcs = NULL; int group; tempstring = "Knoten; X; Y; Z; P1; P2; S1; S2; rho1; rho2; xCO2_liq; mCO2_gas; mCO2_liq"; @@ -892,10 +905,11 @@ void CDUMUXData::ReadDuMuxData(CRFProcess* m_pcs, string Filename, long Timestep for (int j = 0; j < int(m_node->getConnectedElementIDs().size()); j++) { m_ele = m_msh->ele_vector[m_node->getConnectedElementIDs()[j]]; - //get the phase volume of current element elem + // get the phase volume of current element elem group = m_ele->GetPatchIndex(); m_mat_mp = mmp_vector[group]; - porosity = m_mat_mp->Porosity(m_ele->GetIndex(), 1); // CB Now provides also heterogeneous porosity, model 11 + porosity + = m_mat_mp->Porosity(m_ele->GetIndex(), 1); // CB Now provides also heterogeneous porosity, model 11 node_volume = node_volume + m_ele->GetVolume() / 8 * porosity; } @@ -904,9 +918,9 @@ void CDUMUXData::ReadDuMuxData(CRFProcess* m_pcs, string Filename, long Timestep temp << i; tempstring = temp.str(); // TF commented out since we want to use the improved PointDuMux class -// temp.str(""); temp.clear(); temp << this->NodeData[i]->x; tempstring += "; " + temp.str(); -// temp.str(""); temp.clear(); temp << this->NodeData[i]->y; tempstring += "; " + temp.str(); -// temp.str(""); temp.clear(); temp << this->NodeData[i]->z; tempstring += "; " + temp.str(); + // temp.str(""); temp.clear(); temp << this->NodeData[i]->x; tempstring += "; " + temp.str(); + // temp.str(""); temp.clear(); temp << this->NodeData[i]->y; tempstring += "; " + temp.str(); + // temp.str(""); temp.clear(); temp << this->NodeData[i]->z; tempstring += "; " + temp.str(); for (size_t k(0); k < 3; k++) { temp.str(""); @@ -916,13 +930,25 @@ void CDUMUXData::ReadDuMuxData(CRFProcess* m_pcs, string Filename, long Timestep } // TF commented out since we want to use the improved PointDuMux class -// temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->phase_pressure[0]; tempstring += "; " + temp.str(); -// temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->phase_pressure[1]; tempstring += "; " + temp.str(); -// temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->phase_saturation[0]; tempstring += "; " + temp.str(); -// temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->phase_saturation[1]; tempstring += "; " + temp.str(); -// temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->phase_density[0]; tempstring += "; " + temp.str(); -// temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->phase_density[1]; tempstring += "; " + temp.str(); -// temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->CO2inLiquid; tempstring += "; " + temp.str(); + // temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->phase_pressure[0]; tempstring + //+= "; " + temp.str(); + // temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->phase_pressure[1]; tempstring + //+= "; " + temp.str(); + // temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->phase_saturation[0]; + // tempstring + //+= "; " + temp.str(); + // temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->phase_saturation[1]; + // tempstring + //+= "; " + temp.str(); + // temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->phase_density[0]; tempstring + //+= + //"; " + temp.str(); + // temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->phase_density[1]; tempstring + //+= + //"; " + temp.str(); + // temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->CO2inLiquid; tempstring += "; + //" + //+ temp.str(); temp.str(""); temp.clear(); temp.precision(12); @@ -960,16 +986,18 @@ void CDUMUXData::ReadDuMuxData(CRFProcess* m_pcs, string Filename, long Timestep tempstring += "; " + temp.str(); // TF commented out since we want to use the improved PointDuMux class -// concentration_CO2_water = this->NodeData[i]->CO2inLiquid * this->NodeData[i]->phase_density[0] / (this->Molweight_CO2 * 1e-3); -// mass_CO2_gas = node_volume * this->NodeData[i]->phase_saturation[1] * this->NodeData[i]->phase_density[1]; -// mass_CO2_water = node_volume * this->NodeData[i]->phase_saturation[0] * concentration_CO2_water * this->Molweight_CO2 * 0.001; - concentration_CO2_water = this->NodeData[i]->getCO2InLiquid() * - this->NodeData[i]->getPhaseDensity()[0] / - (this->Molweight_CO2 * 1e-3); - mass_CO2_gas = node_volume * this->NodeData[i]->getPhaseSaturation()[1] * - this->NodeData[i]->getPhaseDensity()[1]; - mass_CO2_water = node_volume * this->NodeData[i]->getPhaseSaturation()[0] * - concentration_CO2_water * this->Molweight_CO2 * 0.001; + // concentration_CO2_water = this->NodeData[i]->CO2inLiquid * this->NodeData[i]->phase_density[0] / + //(this->Molweight_CO2 * 1e-3); + // mass_CO2_gas = node_volume * this->NodeData[i]->phase_saturation[1] * + // this->NodeData[i]->phase_density[1]; + // mass_CO2_water = node_volume * this->NodeData[i]->phase_saturation[0] * concentration_CO2_water * + // this->Molweight_CO2 * 0.001; + concentration_CO2_water = this->NodeData[i]->getCO2InLiquid() * this->NodeData[i]->getPhaseDensity()[0] + / (this->Molweight_CO2 * 1e-3); + mass_CO2_gas + = node_volume * this->NodeData[i]->getPhaseSaturation()[1] * this->NodeData[i]->getPhaseDensity()[1]; + mass_CO2_water = node_volume * this->NodeData[i]->getPhaseSaturation()[0] * concentration_CO2_water + * this->Molweight_CO2 * 0.001; temp.str(""); temp.clear(); @@ -985,27 +1013,27 @@ void CDUMUXData::ReadDuMuxData(CRFProcess* m_pcs, string Filename, long Timestep vec_string.push_back(tempstring); } // end node loop - //Test Output + // Test Output int position; string aus_file; if (m_pcs->DuMuxData->Windows_System == true) position = Filename.find_last_of("\\"); else position = Filename.find_last_of("/"); - string path = Filename.substr(0,position); + string path = Filename.substr(0, position); if (m_pcs->DuMuxData->Windows_System == true) position = path.find_last_of("\\"); else position = path.find_last_of("/"); - path = path.substr(0,position); - //temp.str(""); temp.clear(); temp << timestep; tempstring = temp.str(); + path = path.substr(0, position); + // temp.str(""); temp.clear(); temp << timestep; tempstring = temp.str(); if (m_pcs->DuMuxData->Windows_System == true) { aus_file = path; aus_file += "\\CheckDataRedIn_"; temp.str(""); temp.clear(); - temp << this->AddZero(Timestep, 4, true); + temp << this->AddZero(Timestep, 4, true); aus_file += temp.str(); aus_file += ".csv"; } @@ -1015,11 +1043,11 @@ void CDUMUXData::ReadDuMuxData(CRFProcess* m_pcs, string Filename, long Timestep aus_file += "/CheckDataRedIn_"; temp.str(""); temp.clear(); - temp << this->AddZero(Timestep, 4, true); + temp << this->AddZero(Timestep, 4, true); aus_file += temp.str(); aus_file += ".csv"; } - std::ofstream aus (aus_file.data(),std::ios::out); + std::ofstream aus(aus_file.data(), std::ios::out); for (unsigned int i = 0; i < vec_string.size(); i++) aus << vec_string[i] << "\n"; aus.close(); @@ -1034,19 +1062,19 @@ void CDUMUXData::ReadDuMuxData(CRFProcess* m_pcs, string Filename, long Timestep -------------------------------------------------------------------------*/ void CDUMUXData::WriteDataToGeoSys(CRFProcess* m_pcs) { - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt MeshLib::CElem* m_ele = NULL; CFiniteElementStd* fem; long index; double value = 0; - //double n_vel_x[8], n_vel_y[8], n_vel_z[8]; - Math_Group::vec nod_index(8); + // double n_vel_x[8], n_vel_y[8], n_vel_z[8]; + Math_Group::vec nod_index(8); // ---- Gauss integral - //int gp, gp_r=0, gp_s=0, gp_t=0; - //double coef = 0.0, fkt=0.0; - //int numberGaussPoints; - //static double temp_vel[3]={0.0,0.0,0.0}; - //long Index; + // int gp, gp_r=0, gp_s=0, gp_t=0; + // double coef = 0.0, fkt=0.0; + // int numberGaussPoints; + // static double temp_vel[3]={0.0,0.0,0.0}; + // long Index; int i_ind[3]; fem = m_pcs->fem; @@ -1054,92 +1082,93 @@ void CDUMUXData::WriteDataToGeoSys(CRFProcess* m_pcs) for (unsigned long i = 0; i < m_msh->nod_vector.size(); i++) { // TF abbreviation - PointDuMux const* const pnt_dumux (this->NodeData[i]); - //pressure of wetting phase + PointDuMux const* const pnt_dumux(this->NodeData[i]); + // pressure of wetting phase index = m_pcs->GetNodeValueIndex("PRESSURE1") + 1; //+1... new time level // TF commented out since we want to use the improved PointDuMux class -// value = this->NodeData[i]->getPhasePressure()[1] - this->NodeData[i]->getPhasePressure()[0]; + // value = this->NodeData[i]->getPhasePressure()[1] - this->NodeData[i]->getPhasePressure()[0]; value = pnt_dumux->getPhasePressure()[1] - pnt_dumux->getPhasePressure()[0]; - m_pcs->SetNodeValue(i,index,value); + m_pcs->SetNodeValue(i, index, value); // transfer of velocities to OGS nodes index = m_pcs->GetNodeValueIndex("VELOCITY_X1"); //+1... new time level // TF commented out since we want to use the improved PointDuMux class -// value = this->NodeData[i]->q[0][0]; + // value = this->NodeData[i]->q[0][0]; value = pnt_dumux->getQ()[0][0]; - m_pcs->SetNodeValue(i,index,value); + m_pcs->SetNodeValue(i, index, value); // transfer of velocities to OGS nodes index = m_pcs->GetNodeValueIndex("VELOCITY_Y1"); //+1... new time level // TF commented out since we want to use the improved PointDuMux class -// value = this->NodeData[i]->q[0][1]; + // value = this->NodeData[i]->q[0][1]; value = pnt_dumux->getQ()[0][1]; - m_pcs->SetNodeValue(i,index,value); + m_pcs->SetNodeValue(i, index, value); // transfer of velocities to OGS nodes index = m_pcs->GetNodeValueIndex("VELOCITY_Z1"); //+1... new time level // TF commented out since we want to use the improved PointDuMux class -// value = this->NodeData[i]->q[0][2]; + // value = this->NodeData[i]->q[0][2]; value = pnt_dumux->getQ()[0][2]; - m_pcs->SetNodeValue(i,index,value); + m_pcs->SetNodeValue(i, index, value); index = m_pcs->GetNodeValueIndex("DENSITY1"); //+1... new time level // TF commented out since we want to use the improved PointDuMux class -// value = this->NodeData[i]->phase_density[0]; + // value = this->NodeData[i]->phase_density[0]; value = pnt_dumux->getPhaseDensity()[0]; - m_pcs->SetNodeValue(i,index,value); + m_pcs->SetNodeValue(i, index, value); if (this->Phases.size() == 2) { // pressure of nonwetting phase index = m_pcs->GetNodeValueIndex("PRESSURE2") + 1; //+1... new time level // TF commented out since we want to use the improved PointDuMux class -// value = this->NodeData[i]->phase_pressure[1]; + // value = this->NodeData[i]->phase_pressure[1]; value = pnt_dumux->getPhasePressure()[1]; - m_pcs->SetNodeValue(i,index,value); - //saturation of wetting phase + m_pcs->SetNodeValue(i, index, value); + // saturation of wetting phase index = m_pcs->GetNodeValueIndex("SATURATION1") + 1; //+1... new time level // TF commented out since we want to use the improved PointDuMux class -// value = this->NodeData[i]->phase_saturation[0]; + // value = this->NodeData[i]->phase_saturation[0]; value = pnt_dumux->getPhaseSaturation()[0]; - m_pcs->SetNodeValue(i,index,value); - //saturation of nonwetting phase - //index = m_pcs->GetNodeValueIndex("SATURATION2") + 1; //+1... new time level - //value = this->NodeData[i]->phase_saturation[1]; - //m_pcs->SetNodeValue(i,index,value); + m_pcs->SetNodeValue(i, index, value); + // saturation of nonwetting phase + // index = m_pcs->GetNodeValueIndex("SATURATION2") + 1; //+1... new time level + // value = this->NodeData[i]->phase_saturation[1]; + // m_pcs->SetNodeValue(i,index,value); // transfer of velocities to OGS nodes index = m_pcs->GetNodeValueIndex("VELOCITY_X2"); //+1... new time level // TF commented out since we want to use the improved PointDuMux class -// value = this->NodeData[i]->q[1][0]; + // value = this->NodeData[i]->q[1][0]; value = pnt_dumux->getQ()[1][0]; - m_pcs->SetNodeValue(i,index,value); + m_pcs->SetNodeValue(i, index, value); // transfer of velocities to OGS nodes index = m_pcs->GetNodeValueIndex("VELOCITY_Y2"); //+1... new time level // TF commented out since we want to use the improved PointDuMux class -// value = this->NodeData[i]->q[1][1]; + // value = this->NodeData[i]->q[1][1]; value = pnt_dumux->getQ()[1][1]; - m_pcs->SetNodeValue(i,index,value); + m_pcs->SetNodeValue(i, index, value); // transfer of velocities to OGS nodes index = m_pcs->GetNodeValueIndex("VELOCITY_Z2"); //+1... new time level // TF commented out since we want to use the improved PointDuMux class -// value = this->NodeData[i]->q[1][2]; + // value = this->NodeData[i]->q[1][2]; value = pnt_dumux->getQ()[1][2]; - m_pcs->SetNodeValue(i,index,value); + m_pcs->SetNodeValue(i, index, value); index = m_pcs->GetNodeValueIndex("DENSITY2"); //+1... new time level // TF commented out since we want to use the improved PointDuMux class -// value = this->NodeData[i]->phase_density[1]; + // value = this->NodeData[i]->phase_density[1]; value = pnt_dumux->getPhaseDensity()[1]; - m_pcs->SetNodeValue(i,index,value); + m_pcs->SetNodeValue(i, index, value); } } - //assign dissolved gas to GeoSys nodes + // assign dissolved gas to GeoSys nodes CRFProcess* n_pcs = NULL; int indexConcentration; if (this->ProcessIndex_CO2inLiquid == -1) - for(int i = 0; i < int(pcs_vector.size()); i++) + for (int i = 0; i < int(pcs_vector.size()); i++) { n_pcs = pcs_vector[i]; // identify your process and store idx of pcs-vector - //if ((n_pcs->nod_val_name_vector[0] == "C(4)") || - // (n_pcs->nod_val_name_vector[0] == "CO2_w")) // "C(4)"...Phreeqc, "CO2_w"...Chemapp + // if ((n_pcs->nod_val_name_vector[0] == "C(4)") || + // (n_pcs->nod_val_name_vector[0] == "CO2_w")) // "C(4)"...Phreeqc, + // "CO2_w"...Chemapp if (n_pcs->nod_val_name_vector[0] == this->dissolved_co2_pcs_name_DUMUX) this->ProcessIndex_CO2inLiquid = i; if ((n_pcs->nod_val_name_vector[0] == "NaClinLiquid")) @@ -1147,47 +1176,50 @@ void CDUMUXData::WriteDataToGeoSys(CRFProcess* m_pcs) } if (this->ProcessIndex_CO2inLiquid == -1) { - cout << - "In the model exists dissolved gas but there is no dissolved C in water defined. Please ad the mass transport for dissolved CO2!" + cout << "In the model exists dissolved gas but there is no dissolved C in water defined. Please ad the mass " + "transport for dissolved CO2!" << "\n"; - //system("Pause"); + // system("Pause"); exit(0); } // get index of species concentration in nodevaluevector of this process indexConcentration = pcs_vector[this->ProcessIndex_CO2inLiquid]->GetNodeValueIndex( - pcs_vector[this->ProcessIndex_CO2inLiquid]->pcs_primary_function_name[0]) + 1; // +1: new timelevel - for(unsigned long i = 0; - i < pcs_vector[this->ProcessIndex_CO2inLiquid]->nod_val_vector.size(); i++) + pcs_vector[this->ProcessIndex_CO2inLiquid]->pcs_primary_function_name[0]) + + 1; // +1: new timelevel + for (unsigned long i = 0; i < pcs_vector[this->ProcessIndex_CO2inLiquid]->nod_val_vector.size(); i++) { // TF abbreviation - PointDuMux const* const pnt_dumux (this->NodeData[i]); - //recalculate dissolve gas: c_CO2 [mol/m�] = w_CO2 [kg_CO2 / kg_liquid] * density_liq[kg/m�] / (Molweight_CO2 [g/mol] * 1e-3 [kg/g]) + PointDuMux const* const pnt_dumux(this->NodeData[i]); + // recalculate dissolve gas: c_CO2 [mol/m�] = w_CO2 [kg_CO2 / kg_liquid] * density_liq[kg/m�] / (Molweight_CO2 + // [g/mol] * 1e-3 [kg/g]) // TF commented out since we want to use the improved PointDuMux class -// value = this->NodeData[i]->CO2inLiquid * this->NodeData[i]->phase_density[0] / (this->Molweight_CO2 * 1e-3); - value = pnt_dumux->getCO2InLiquid() * pnt_dumux->getPhaseDensity()[0] / - (this->Molweight_CO2 * 1e-3); - //cout << " c_CO2 " << value << " Dichte " << this->NodeData[i]->phase_density[0] << "\n"; - pcs_vector[this->ProcessIndex_CO2inLiquid]->SetNodeValue(i, - indexConcentration, - value); - //cout << "Node: " << i << " Druck: " << m_pcs->GetNodeValue(i, index_pressure2) << " RS: " << this->NodeData[i]->Gas_dissolved << " Dichte: " << this->SurfaceCO2Density << " C(4): " << value << "\n"; + // value = this->NodeData[i]->CO2inLiquid * this->NodeData[i]->phase_density[0] / (this->Molweight_CO2 * + // 1e-3); + value = pnt_dumux->getCO2InLiquid() * pnt_dumux->getPhaseDensity()[0] / (this->Molweight_CO2 * 1e-3); + // cout << " c_CO2 " << value << " Dichte " << this->NodeData[i]->phase_density[0] << "\n"; + pcs_vector[this->ProcessIndex_CO2inLiquid]->SetNodeValue(i, indexConcentration, value); + // cout << "Node: " << i << " Druck: " << m_pcs->GetNodeValue(i, index_pressure2) << " RS: " << + // this->NodeData[i]->Gas_dissolved << " Dichte: " << this->SurfaceCO2Density << " C(4): " << value << "\n"; if (value < 0) { // TF commented out since we want to use the improved PointDuMux class -// cout << "Node: " << i << " Druck: " << this->NodeData[i]->phase_pressure[1] << " X_CO2: " << this->NodeData[i]->CO2inLiquid << " Dichte: " << this->NodeData[i]->phase_density[0] << " C(4): " << value << "\n"; - cout << "Node: " << i << " Druck: " << pnt_dumux->getPhasePressure()[1] << - " X_CO2: " << this->NodeData[i]->getCO2InLiquid() << " Dichte: " << - pnt_dumux->getPhaseDensity()[0] << " dissolved CO2: " << value << "\n"; + // cout << "Node: " << i << " Druck: " << this->NodeData[i]->phase_pressure[1] << " X_CO2: " << + // this->NodeData[i]->CO2inLiquid << " Dichte: " << this->NodeData[i]->phase_density[0] << " C(4): " << + // value + //<< "\n"; + cout << "Node: " << i << " Druck: " << pnt_dumux->getPhasePressure()[1] + << " X_CO2: " << this->NodeData[i]->getCO2InLiquid() << " Dichte: " << pnt_dumux->getPhaseDensity()[0] + << " dissolved CO2: " << value << "\n"; cout << " Fehler in Berechnung von DIC: " << value << "\n"; } } // Loop over all elements to calculate gauss point velocities from node values -//???????????????????????????????? - //warum muss Koordinatenausrichtung �berpr�ft werden - //warum ist in Cal_GP_Velocity_FM der Prozess notwendig????? -//???????????????????????????? + //???????????????????????????????? + // warum muss Koordinatenausrichtung �berpr�ft werden + // warum ist in Cal_GP_Velocity_FM der Prozess notwendig????? + //???????????????????????????? for (int k = 0; k < int(this->Phases.size()); k++) { @@ -1198,16 +1230,16 @@ void CDUMUXData::WriteDataToGeoSys(CRFProcess* m_pcs) i_ind[2] = m_pcs->GetNodeValueIndex("VELOCITY_Z1"); // get index of velocity //// check all possibilities for grid orientation (ccord_flag) - //int coordinateflag = this->m_msh->GetCoordinateFlag(); - //i_ind[0] = m_pcs_fm->GetNodeValueIndex("VELOCITY_X1")+1; // get index of velocity - //if(coordinateflag == 11) - //i_ind[0] = m_pcs_fm->GetNodeValueIndex("VELOCITY_Y1")+1; // get index of velocity - //if(coordinateflag == 12) - //i_ind[0] = m_pcs_fm->GetNodeValueIndex("VELOCITY_Z1")+1; // get index of velocity - //i_ind[1] = m_pcs_fm->GetNodeValueIndex("VELOCITY_Y1")+1; // get index of velocity - //if(coordinateflag == 22) - //i_ind[1] = m_pcs_fm->GetNodeValueIndex("VELOCITY_Z1")+1; // get index of velocity - //i_ind[2] = m_pcs_fm->GetNodeValueIndex("VELOCITY_Z1")+1; // get index of velocity + // int coordinateflag = this->m_msh->GetCoordinateFlag(); + // i_ind[0] = m_pcs_fm->GetNodeValueIndex("VELOCITY_X1")+1; // get index of velocity + // if(coordinateflag == 11) + // i_ind[0] = m_pcs_fm->GetNodeValueIndex("VELOCITY_Y1")+1; // get index of velocity + // if(coordinateflag == 12) + // i_ind[0] = m_pcs_fm->GetNodeValueIndex("VELOCITY_Z1")+1; // get index of velocity + // i_ind[1] = m_pcs_fm->GetNodeValueIndex("VELOCITY_Y1")+1; // get index of velocity + // if(coordinateflag == 22) + // i_ind[1] = m_pcs_fm->GetNodeValueIndex("VELOCITY_Z1")+1; // get index of velocity + // i_ind[2] = m_pcs_fm->GetNodeValueIndex("VELOCITY_Z1")+1; // get index of velocity } else { @@ -1216,25 +1248,27 @@ void CDUMUXData::WriteDataToGeoSys(CRFProcess* m_pcs) i_ind[2] = m_pcs->GetNodeValueIndex("VELOCITY_Z2"); // get index of velocity // check all possibilities for grid orientation (ccord_flag) - //int coordinateflag = this->m_msh->GetCoordinateFlag(); - //i_ind[0] = m_pcs_fm->GetNodeValueIndex("VELOCITY_X2")+1; // get index of velocity - //if(coordinateflag == 11) - //i_ind[0] = m_pcs_fm->GetNodeValueIndex("VELOCITY_Y2")+1; // get index of velocity - //if(coordinateflag == 12) - //i_ind[0] = m_pcs_fm->GetNodeValueIndex("VELOCITY_Z2")+1; // get index of velocity - //i_ind[1] = m_pcs_fm->GetNodeValueIndex("VELOCITY_Y2")+1; // get index of velocity - //if(coordinateflag == 22) - //i_ind[1] = m_pcs_fm->GetNodeValueIndex("VELOCITY_Z2")+1; // get index of velocity - //i_ind[2] = m_pcs_fm->GetNodeValueIndex("VELOCITY_Z2")+1; // get index of velocity + // int coordinateflag = this->m_msh->GetCoordinateFlag(); + // i_ind[0] = m_pcs_fm->GetNodeValueIndex("VELOCITY_X2")+1; // get index of velocity + // if(coordinateflag == 11) + // i_ind[0] = m_pcs_fm->GetNodeValueIndex("VELOCITY_Y2")+1; // get index of velocity + // if(coordinateflag == 12) + // i_ind[0] = m_pcs_fm->GetNodeValueIndex("VELOCITY_Z2")+1; // get index of velocity + // i_ind[1] = m_pcs_fm->GetNodeValueIndex("VELOCITY_Y2")+1; // get index of velocity + // if(coordinateflag == 22) + // i_ind[1] = m_pcs_fm->GetNodeValueIndex("VELOCITY_Z2")+1; // get index of velocity + // i_ind[2] = m_pcs_fm->GetNodeValueIndex("VELOCITY_Z2")+1; // get index of velocity } - if((i_ind[0] < 0) || (i_ind[1] < 0) || (i_ind[2] < 0)) - cout << " Error - wrong index in Cal_GP_Velocity_FM " << "\n"; + if ((i_ind[0] < 0) || (i_ind[1] < 0) || (i_ind[2] < 0)) + cout << " Error - wrong index in Cal_GP_Velocity_FM " + << "\n"; - //Test Output - //vector vec_string; - //string tempstring; - //ostringstream temp; - //vec_string.push_back("Element; X; Y; Z; v_Geosys_x; v_Geosys_y; v_Geosys_z; v_DuMux_x; v_DuMux_y; v_DuMux_z"); + // Test Output + // vector vec_string; + // string tempstring; + // ostringstream temp; + // vec_string.push_back("Element; X; Y; Z; v_Geosys_x; v_Geosys_y; v_Geosys_z; v_DuMux_x; v_DuMux_y; + // v_DuMux_z"); // Loop over all elements for (long i = 0; i < (long)m_msh->ele_vector.size(); i++) @@ -1247,23 +1281,21 @@ void CDUMUXData::WriteDataToGeoSys(CRFProcess* m_pcs) std::string tempstring; tempstring = ""; // Test Output - //temp.str(""); temp.clear(); temp << i; tempstring = temp.str(); - //double* gc = m_ele->GetGravityCenter(); - //temp.str(""); temp.clear(); temp << gc[0]; tempstring += "; " + temp.str(); - //temp.str(""); temp.clear(); temp << gc[1]; tempstring += "; " + temp.str(); - //temp.str(""); temp.clear(); temp << gc[2]; tempstring += "; " + temp.str(); + // temp.str(""); temp.clear(); temp << i; tempstring = temp.str(); + // double* gc = m_ele->GetGravityCenter(); + // temp.str(""); temp.clear(); temp << gc[0]; tempstring += "; " + temp.str(); + // temp.str(""); temp.clear(); temp << gc[1]; tempstring += "; " + temp.str(); + // temp.str(""); temp.clear(); temp << gc[2]; tempstring += "; " + temp.str(); - tempstring = tempstring + fem->Cal_GP_Velocity_DuMux(i_ind, - m_pcs, - k); + tempstring = tempstring + fem->Cal_GP_Velocity_DuMux(i_ind, m_pcs, k); - //vec_string.push_back(tempstring); + // vec_string.push_back(tempstring); } } // end element loop // Test Output - //int timestep = m_pcs->Tim->step_current; - //if (timestep == 1 || timestep % 10 == 0 ) { + // int timestep = m_pcs->Tim->step_current; + // if (timestep == 1 || timestep % 10 == 0 ) { // string path; // path = m_pcs->simulator_model_path; // int position = path.find_last_of("\\"); @@ -1294,14 +1326,15 @@ void CDUMUXData::ExecuteDuMux(CRFProcess* m_pcs, string folder) string DuMuxExe; std::ostringstream temp; string tempstring; - vector vec_string; + vector vec_string; DuMuxExe = m_pcs->simulator_path; if (CheckIfFileExists(DuMuxExe) == false) { - cout << "The DuMux executable could not be found! (" << DuMuxExe << ")" << "\n"; - //system("Pause"); + cout << "The DuMux executable could not be found! (" << DuMuxExe << ")" + << "\n"; + // system("Pause"); exit(0); } @@ -1309,8 +1342,7 @@ void CDUMUXData::ExecuteDuMux(CRFProcess* m_pcs, string folder) if (UsePrecalculatedFiles == false) if (this->Windows_System == false) { - tempstring = DuMuxExe + " " + folder + "DuMux.dgf" + " " + folder + - "dataForDumux.dat"; + tempstring = DuMuxExe + " " + folder + "DuMux.dgf" + " " + folder + "dataForDumux.dat"; cout << tempstring << "\n"; if (system(tempstring.c_str())) { @@ -1338,7 +1370,7 @@ int CDUMUXData::RunDuMux(long Timestep, CRFProcess* m_pcs) string Executable_Folder; string folder; int position; - clock_t start,finish; + clock_t start, finish; clock_t start_execute, finish_execute; double time; bool ReadPrecalculatedFiles; @@ -1367,13 +1399,12 @@ int CDUMUXData::RunDuMux(long Timestep, CRFProcess* m_pcs) Executable_Folder = Executable_Filename.substr(0, position + 1); - //Output of dissolved CO2, NaCl and timestep + // Output of dissolved CO2, NaCl and timestep if (WriteInputForDuMux(m_pcs, Executable_Folder, Timestep) == 0) { - cout << - "There are problems with writing input data for DuMux! The run is terminated." << - "\n"; - //system("Pause"); + cout << "There are problems with writing input data for DuMux! The run is terminated." + << "\n"; + // system("Pause"); exit(0); } @@ -1384,11 +1415,12 @@ int CDUMUXData::RunDuMux(long Timestep, CRFProcess* m_pcs) position = int(Filename.find_last_of("/")); folder = Filename.substr(0, position + 1); - cout << " Delete old result files " << "\n"; + cout << " Delete old result files " + << "\n"; if (ReadPrecalculatedFiles == false) { - //Delete Resultfiles + // Delete Resultfiles if (this->Windows_System == true) DOScommand = "del " + folder + "\\dataForGeoSys*.dat"; else @@ -1398,7 +1430,7 @@ int CDUMUXData::RunDuMux(long Timestep, CRFProcess* m_pcs) DisplayMsgLn("Could not delete input file! "); } - //check if dumux folder is subfolder of the geosys folder + // check if dumux folder is subfolder of the geosys folder if (Timestep == 1) { if (this->Windows_System == true) @@ -1419,21 +1451,21 @@ int CDUMUXData::RunDuMux(long Timestep, CRFProcess* m_pcs) geosys_folder = m_pcs->file_name_base.substr(0, position); if (root_folder != geosys_folder) { - cout << - "Warning: The DuMux simulator model path is not part of the GeoSys model path!!!" + cout << "Warning: The DuMux simulator model path is not part of the GeoSys model path!!!" << "\n"; cout << root_folder << "\n"; cout << geosys_folder << "\n"; - //system("Pause"); + // system("Pause"); } } - cout << " RunDuMux() called " << "\n"; + cout << " RunDuMux() called " + << "\n"; - //Execute DuMux, try several times in case of problems finding the license server + // Execute DuMux, try several times in case of problems finding the license server start_execute = clock(); - //define number of phases + // define number of phases if (Timestep == 1) { if (m_pcs->getProcessType() == FiniteElement::LIQUID_FLOW) @@ -1449,14 +1481,14 @@ int CDUMUXData::RunDuMux(long Timestep, CRFProcess* m_pcs) int maximum_loops = 10; if (ReadPrecalculatedFiles == false) { - do { - cout << number_loops + 1 << ". trial" << "\n"; + do + { + cout << number_loops + 1 << ". trial" + << "\n"; ExecuteDuMux(m_pcs, folder); - //check if DuMux has run properly + // check if DuMux has run properly number_loops += 1; - Filename = folder + "dataForGeoSys" + AddZero(m_pcs->Tim->step_current - 1, - 4, - true) + ".dat"; + Filename = folder + "dataForGeoSys" + AddZero(m_pcs->Tim->step_current - 1, 4, true) + ".dat"; } while ((CheckIfFileExists(Filename) == false) && (number_loops <= maximum_loops)); } @@ -1464,13 +1496,14 @@ int CDUMUXData::RunDuMux(long Timestep, CRFProcess* m_pcs) time = (double(finish_execute) - double(start_execute)) / CLOCKS_PER_SEC; cout << "\n"; cout << " Timestep: " << Timestep << "\n"; - cout << " RunDUMUX() called Time: " << time << " seconds." << "\n"; + cout << " RunDUMUX() called Time: " << time << " seconds." + << "\n"; if (number_loops > maximum_loops) { - cout << "The DuMux execution does not work after " << number_loops << " trials!" << - "\n"; - //system("Pause"); + cout << "The DuMux execution does not work after " << number_loops << " trials!" + << "\n"; + // system("Pause"); exit(0); } @@ -1481,17 +1514,18 @@ int CDUMUXData::RunDuMux(long Timestep, CRFProcess* m_pcs) if (ReadPrecalculatedFiles == false) { - //CleanUpEclipseFiles(folder, projectname); + // CleanUpEclipseFiles(folder, projectname); } finish = clock(); time = (double(finish) - double(start)) / CLOCKS_PER_SEC; - cout << " Time for this timestep: " << time << " seconds." << "\n"; + cout << " Time for this timestep: " << time << " seconds." + << "\n"; return 1; } -//ToDO: +// ToDO: // - Konstruktor nur einmal aufrufen // - in st-file: Masse einlesen und mit aktueller Dichte in Volumenstrom umrechnen diff --git a/FEM/DUMUX.h b/FEM/DUMUX.h index 8da60aec2..330bdb233 100644 --- a/FEM/DUMUX.h +++ b/FEM/DUMUX.h @@ -10,7 +10,7 @@ // Classes for interface GeoSys - DUMUX #include -//class CRFProcess; +// class CRFProcess; //#include "rf_pcs.h" #include "fem_ele.h" #include "fem_ele_std.h" @@ -20,14 +20,14 @@ class CReadTextfiles_DuMux { public: - std::vector Data; - std::vector > Data_separated; + std::vector Data; + std::vector > Data_separated; long NumberOfRows; - std::vector SplittedString; - std::vector Header; + std::vector SplittedString; + std::vector Header; - CReadTextfiles_DuMux(); //Konstruktor - ~CReadTextfiles_DuMux(); //Desturktor + CReadTextfiles_DuMux(); // Konstruktor + ~CReadTextfiles_DuMux(); // Desturktor bool Read_Text(std::string Filename); @@ -39,8 +39,8 @@ class CReadTextfiles_DuMux class CWriteTextfiles_DuMux { public: - CWriteTextfiles_DuMux(); //Konstruktor - ~CWriteTextfiles_DuMux(); //Desturktor + CWriteTextfiles_DuMux(); // Konstruktor + ~CWriteTextfiles_DuMux(); // Desturktor void Write_Text(std::string Filename, std::vector Text); }; @@ -48,35 +48,32 @@ class CWriteTextfiles_DuMux class PointDuMux : public GEOLIB::Point { public: - PointDuMux (double x, double y, double z, double temperature, - double CO2_in_liquid, double NaCl_in_liquid) : - GEOLIB::Point (x,y,z), _temperature (temperature), - _CO2_in_liquid (CO2_in_liquid), _NaCl_in_Liquid (NaCl_in_liquid) - {} - - PointDuMux (double const* const coords, double temperature, - double CO2_in_liquid, double NaCl_in_liquid) : - GEOLIB::Point (coords), _temperature (temperature), - _CO2_in_liquid (CO2_in_liquid), _NaCl_in_Liquid (NaCl_in_liquid) - {} + PointDuMux(double x, double y, double z, double temperature, double CO2_in_liquid, double NaCl_in_liquid) + : GEOLIB::Point(x, y, z), _temperature(temperature), _CO2_in_liquid(CO2_in_liquid), + _NaCl_in_Liquid(NaCl_in_liquid) + { + } + + PointDuMux(double const* const coords, double temperature, double CO2_in_liquid, double NaCl_in_liquid) + : GEOLIB::Point(coords), _temperature(temperature), _CO2_in_liquid(CO2_in_liquid), + _NaCl_in_Liquid(NaCl_in_liquid) + { + } double getTemperature() const { return _temperature; } double getCO2InLiquid() const { return _CO2_in_liquid; } double getNaClInLiquid() const { return _NaCl_in_Liquid; } - void setTemperature(double temperature) { _temperature = temperature; } void setCO2InLiquid(double CO2_in_liquid) { _CO2_in_liquid = CO2_in_liquid; } void setNaClInLiquid(double NaCl_in_Liquid) { _NaCl_in_Liquid = NaCl_in_Liquid; } - std::vector& getPhasePressure() { return _phase_pressure; } - std::vector const & getPhasePressure() const { return _phase_pressure; } + std::vector const& getPhasePressure() const { return _phase_pressure; } std::vector& getPhaseSaturation() { return _phase_saturation; } - std::vector const & getPhaseSaturation() const { return _phase_saturation; } + std::vector const& getPhaseSaturation() const { return _phase_saturation; } std::vector& getPhaseDensity() { return _phase_density; } - std::vector const & getPhaseDensity() const { return _phase_density; } + std::vector const& getPhaseDensity() const { return _phase_density; } std::vector >& getQ() { return _q; } - std::vector > const & getQ() const { return _q; } - + std::vector > const& getQ() const { return _q; } private: double _temperature; double _CO2_in_liquid; @@ -87,8 +84,8 @@ class PointDuMux : public GEOLIB::Point std::vector > _q; }; -//class CPointData_DuMux { -//public: +// class CPointData_DuMux { +// public: // double x; // double y; // double z; @@ -110,9 +107,9 @@ class CDUMUXData CDUMUXData(); ~CDUMUXData(); -// std::vector NodeData; - std::vector NodeData; - std::vector Phases; + // std::vector NodeData; + std::vector NodeData; + std::vector Phases; int dim; int ProcessIndex_CO2inLiquid; int ProcessIndex_NaClinLiquid; @@ -120,9 +117,10 @@ class CDUMUXData bool UsePrecalculatedFiles; double Molweight_CO2; // [g/mol] double TotalSimulationTime; - std::string dissolved_co2_pcs_name_DUMUX; // Keyword DISSOLVED_CO2_PCS_NAME; Name of MASS_TRANSPORT Process which is used to store total dissolved CO2 from DUMUX + std::string dissolved_co2_pcs_name_DUMUX; // Keyword DISSOLVED_CO2_PCS_NAME; Name of MASS_TRANSPORT Process which is + // used to store total dissolved CO2 from DUMUX - //CFiniteElementStd* GetAssembler() {return fem; } + // CFiniteElementStd* GetAssembler() {return fem; } bool CheckIfFileExists(std::string strFilename); diff --git a/FEM/DistributionInfo.cpp b/FEM/DistributionInfo.cpp index 5e1c44785..77c1ed91f 100644 --- a/FEM/DistributionInfo.cpp +++ b/FEM/DistributionInfo.cpp @@ -12,20 +12,21 @@ #include "DistributionInfo.h" -DistributionInfo::DistributionInfo(FiniteElement::DistributionType dt) : - _dis_type (dt) -{} +DistributionInfo::DistributionInfo(FiniteElement::DistributionType dt) : _dis_type(dt) +{ +} DistributionInfo::~DistributionInfo() -{} +{ +} -void DistributionInfo::setProcessDistributionType (FiniteElement::DistributionType dis_type) +void DistributionInfo::setProcessDistributionType(FiniteElement::DistributionType dis_type) { _dis_type = dis_type; } -FiniteElement::DistributionType DistributionInfo::getProcessDistributionType () const +FiniteElement::DistributionType DistributionInfo::getProcessDistributionType() const { return _dis_type; } diff --git a/FEM/DistributionInfo.h b/FEM/DistributionInfo.h index a7136fca9..0999295b2 100644 --- a/FEM/DistributionInfo.h +++ b/FEM/DistributionInfo.h @@ -26,13 +26,13 @@ class DistributionInfo * Sets the value for the distribution type * @param dis_type value for primary variable, possible values are documented in enum PrimaryVariable */ - void setProcessDistributionType (FiniteElement::DistributionType dis_type); + void setProcessDistributionType(FiniteElement::DistributionType dis_type); /** * Get the distribution type of the process. * @return the distribution type of the process */ - FiniteElement::DistributionType getProcessDistributionType () const; + FiniteElement::DistributionType getProcessDistributionType() const; private: /** @@ -41,4 +41,4 @@ class DistributionInfo FiniteElement::DistributionType _dis_type; }; -#endif /* DISTRIBUTIONINFO_H_ */ +#endif /* DISTRIBUTIONINFO_H_ */ diff --git a/FEM/Eclipse.cpp b/FEM/Eclipse.cpp index 8ff4980cd..2ef169a4e 100644 --- a/FEM/Eclipse.cpp +++ b/FEM/Eclipse.cpp @@ -7,12 +7,12 @@ * */ -//1. Eclipse starten (die Files liegen alle vorbereitet vor -//2. Daten auslesen -> Tool ecl2gs -//3. Datenumwandeln (Uebertragung auf Knoten, Geschwindigkeit berechnen) -//4. Geosys daten schreiben -//5. Berechnung Geosys -//6. Eclipse restart +// 1. Eclipse starten (die Files liegen alle vorbereitet vor +// 2. Daten auslesen -> Tool ecl2gs +// 3. Datenumwandeln (Uebertragung auf Knoten, Geschwindigkeit berechnen) +// 4. Geosys daten schreiben +// 5. Berechnung Geosys +// 6. Eclipse restart // declarations for ecl_interface ECLIPSE - GeoSys @@ -20,10 +20,10 @@ #include "Eclipse.h" #include #include -#include // Datei streams -#include // Bildschirmausgabe +#include // Datei streams +#include // Bildschirmausgabe #include -#include // string streams (in) +#include // string streams (in) #include #include #include @@ -91,11 +91,12 @@ bool CReadTextfiles_ECL::Read_Text(std::string Filename) std::string tempstring; // .data ... provides the filename as it is necessary for C, ios::in ... reads the file - ifstream in_file (Filename.data(),ios::in); + ifstream in_file(Filename.data(), ios::in); if (in_file.fail()) { error = true; - cout << "The file " << Filename.data() << " can not be opened!" << "\n"; + cout << "The file " << Filename.data() << " can not be opened!" + << "\n"; } else { @@ -103,17 +104,17 @@ bool CReadTextfiles_ECL::Read_Text(std::string Filename) while ((abort == false) && (in_file.eof() == false)) { tempstring.clear(); - in_file.getline(Line,MAX_ZEILEN); + in_file.getline(Line, MAX_ZEILEN); tempstring = Line; // You could basically use this later to avoid line lenghts of pre-defined length only // getline(in_file,tempstring); - if(tempstring.length() == MAX_ZEILEN - 1) + if (tempstring.length() == MAX_ZEILEN - 1) { - cout << - " Error - increase MAX_ZEILEN in order to read ECLIPSE data file " + cout << " Error - increase MAX_ZEILEN in order to read ECLIPSE data file " + << "\n"; + cout << " Or shorten the line in " << Filename.data() << ": " << tempstring << " to " << MAX_ZEILEN + << " characters " << "\n"; - cout << " Or shorten the line in " << Filename.data() << ": " << - tempstring << " to " << MAX_ZEILEN << " characters " << "\n"; exit(0); } if (tempstring.compare("#STOP") != 0) @@ -155,7 +156,7 @@ void CWriteTextfiles_ECL::Write_Text(std::string Filename, vector T textfile << Text[i].data(); else textfile << Text[i].data() << "\n"; - //file.write(Text[i]); + // file.write(Text[i]); } textfile.close(); } @@ -172,17 +173,17 @@ CECLIPSEData::CECLIPSEData(void) this->times = 0; this->numberOutputParameters = 0; this->activeCells = 0; - this->NodeData.clear(); //resize(1); // warum das? + this->NodeData.clear(); // resize(1); // warum das? this->Data = NULL; this->ProcessIndex_CO2inLiquid = -1; - this->ProcessIndex_CO2inGas = -1; //redo wtp + this->ProcessIndex_CO2inGas = -1; // redo wtp this->Radial_I = false; this->Radial_J = false; this->RadialModellIpos = false; this->RadialModellJpos = false; - this->phase_shift_flag = false; //redo wtp + this->phase_shift_flag = false; // redo wtp this->eclipse_ele_active_flag.clear(); // CB redo wtp - this->PoroPermIncludeFile = false; //redo wtp + this->PoroPermIncludeFile = false; // redo wtp this->dissolved_co2_pcs_name_ECL = ""; // SB_KB redo wtp this->dissolved_co2_ingas_pcs_name_ECL = ""; // SB_KB redo wtp this->TempIncludeFile = false; @@ -243,7 +244,7 @@ void CECLIPSEData::SplitStrings(const std::string str, std::string delimiter) -------------------------------------------------------------------------*/ double CECLIPSEData::Round(double Number, int Decimalplaces) { - Number *= pow( 10, double(Decimalplaces)); + Number *= pow(10, double(Decimalplaces)); Number = floor(Number + 0.5); Number *= pow(10, double(-Decimalplaces)); return Number; @@ -261,11 +262,11 @@ typeExponentialNumber CECLIPSEData::RoundEXP(double Number, int Decimalplaces) typeExponentialNumber Result; int Exponent; double tempNumber; - //WW int sign; + // WW int sign; - //WW sign = 1; - //WW if (Number < 0) - //WW sign = -1; + // WW sign = 1; + // WW if (Number < 0) + // WW sign = -1; Exponent = 0; tempNumber = fabs(Number); @@ -273,19 +274,21 @@ typeExponentialNumber CECLIPSEData::RoundEXP(double Number, int Decimalplaces) { if (tempNumber >= 1) { - do { + do + { tempNumber /= 10; Exponent -= 1; - } while(tempNumber >= 1); + } while (tempNumber >= 1); } else if (tempNumber < 0.1) { - do { + do + { tempNumber *= 10; Exponent += 1; - } while(tempNumber < 0.1); + } while (tempNumber < 0.1); } - Number *= pow( 10, double(Exponent + Decimalplaces)); + Number *= pow(10, double(Exponent + Decimalplaces)); Number = floor(Number + 0.5); Number *= pow(10, double(-Decimalplaces)); } @@ -340,7 +343,7 @@ std::string CECLIPSEData::AddZero(double Number, int Places, bool before) tempstring = tempNumberString.str(); Result = tempstring; } - //else { + // else { while (size_t(Result.length()) < Places + position + 1) { position = Result.find("."); @@ -348,9 +351,8 @@ std::string CECLIPSEData::AddZero(double Number, int Places, bool before) { position_e = Result.find("e"); if (position_e < Result.length()) - Result = Result.substr(0, position_e) + "0" + Result.substr( - position_e, - Result.length() - (position_e)); + Result = Result.substr(0, position_e) + "0" + + Result.substr(position_e, Result.length() - (position_e)); else Result = Result + "0"; } @@ -358,9 +360,8 @@ std::string CECLIPSEData::AddZero(double Number, int Places, bool before) { position_e = Result.find("e"); if (position_e < Result.length()) - Result = Result.substr(0, position_e) + "." + Result.substr( - position_e, - Result.length() - (position_e)); + Result = Result.substr(0, position_e) + "." + + Result.substr(position_e, Result.length() - (position_e)); else Result = Result + "."; } @@ -379,15 +380,15 @@ std::string CECLIPSEData::AddZero(double Number, int Places, bool before) -------------------------------------------------------------------------*/ bool CECLIPSEData::CheckIfFileExists(string strFilename) { -// code source: http://www.techbytes.ca/techbyte103.html (6.11.2009) no restriction for use + // code source: http://www.techbytes.ca/techbyte103.html (6.11.2009) no restriction for use struct stat stFileInfo; bool blnReturn; int intStat; // Attempt to get the file attributes - intStat = stat(strFilename.c_str(),&stFileInfo); - if(intStat == 0) + intStat = stat(strFilename.c_str(), &stFileInfo); + if (intStat == 0) // We were able to get the file attributes // so the file obviously exists. blnReturn = true; @@ -419,7 +420,7 @@ void CECLIPSEData::ReadEclipseGrid(std::string Filename) std::stringstream in; bool error = false; vector files = vector(); - clock_t start,finish; + clock_t start, finish; double time; start = clock(); @@ -431,30 +432,30 @@ void CECLIPSEData::ReadEclipseGrid(std::string Filename) if (error == true) { - cout << "The program is canceled" << "\n"; - //system("Pause"); + cout << "The program is canceled" + << "\n"; + // system("Pause"); exit(0); } - //Read in the Grid + // Read in the Grid for (long i = 0; i < TextFile->NumberOfRows - 1; i++) { - //cout << TextFile->Data[i] << "\n"; - tempstring = TextFile->Data[i].substr(2,8); + // cout << TextFile->Data[i] << "\n"; + tempstring = TextFile->Data[i].substr(2, 8); - //Check if the grid is radial or not + // Check if the grid is radial or not if (tempstring.compare("RADIAL ") == 0) { - if (TextFile->Data[i + 1].substr(2,8) == "FALSE ") + if (TextFile->Data[i + 1].substr(2, 8) == "FALSE ") Radialmodell = false; - else if (TextFile->Data[i + 1].substr(2,8) == "TRUE ") + else if (TextFile->Data[i + 1].substr(2, 8) == "TRUE ") Radialmodell = true; else { - cout << - "The phrase below the keyword RADIAL does not contain TRUE or FALSE! The program is aborted!" + cout << "The phrase below the keyword RADIAL does not contain TRUE or FALSE! The program is aborted!" << "\n"; - //system("Pause"); + // system("Pause"); exit(0); } } @@ -462,26 +463,27 @@ void CECLIPSEData::ReadEclipseGrid(std::string Filename) if (tempstring.compare("COORDS ") == 0) { m_eclipseblock = new CECLIPSEBlock(8, 6); // new member of eclblock - in.str((string) TextFile->Data[i + 1]); - in >> m_eclipseblock->column >> m_eclipseblock->row >> - m_eclipseblock->layer >> m_eclipseblock->index >> m_eclipseblock->active; + in.str((string)TextFile->Data[i + 1]); + in >> m_eclipseblock->column >> m_eclipseblock->row >> m_eclipseblock->layer >> m_eclipseblock->index + >> m_eclipseblock->active; in.clear(); // SB und KB - //cout << m_eclipseblock->column << "\n"; - //this->SplitStrings(TextFile->Daten[i+1]," "); - //if (this->SplittedString.size()<=4) { - // cout << "\n" << "The grid output format (GRIDFILE) for Eclipse should be set to 2 0 instead of 1 1! The run is terminated now!" << "\n"; + // cout << m_eclipseblock->column << "\n"; + // this->SplitStrings(TextFile->Daten[i+1]," "); + // if (this->SplittedString.size()<=4) { + // cout << "\n" << "The grid output format (GRIDFILE) for Eclipse should be set to 2 0 instead of 1 1! The + // run is terminated now!" << "\n"; // //system("Pause"); // exit(0); //} - //m_eclipseblock->column = atoi(this->SplittedString[0].data()); - //m_eclipseblock->row = atoi(this->SplittedString[1].data()); - //m_eclipseblock->layer = atoi(this->SplittedString[2].data()); - //m_eclipseblock->index = atoi(this->SplittedString[3].data()); - //m_eclipseblock->active = atoi(this->SplittedString[4].data()); - //index of Eclipse start with 1 -> change to 0 - //m_eclipseblock->index = m_eclipseblock->index - 1; + // m_eclipseblock->column = atoi(this->SplittedString[0].data()); + // m_eclipseblock->row = atoi(this->SplittedString[1].data()); + // m_eclipseblock->layer = atoi(this->SplittedString[2].data()); + // m_eclipseblock->index = atoi(this->SplittedString[3].data()); + // m_eclipseblock->active = atoi(this->SplittedString[4].data()); + // index of Eclipse start with 1 -> change to 0 + // m_eclipseblock->index = m_eclipseblock->index - 1; // inactive cells are not red anymore if (m_eclipseblock->active == 1) @@ -499,82 +501,69 @@ void CECLIPSEData::ReadEclipseGrid(std::string Filename) m_eclipseblock->index = this->elements - 1; - //read in alle corner coordinates - //Debug.Print(Strings.Mid(Gridfile.Daten(0, i + 2), 3, 8)) + // read in alle corner coordinates + // Debug.Print(Strings.Mid(Gridfile.Daten(0, i + 2), 3, 8)) - if (TextFile->Data[i + 2].substr(2,8).compare("CORNERS ") == 0) + if (TextFile->Data[i + 2].substr(2, 8).compare("CORNERS ") == 0) Corners_row = 0; else { - if (TextFile->Data[i + 3].substr(2, - 8).compare("CORNERS ") == - 0) + if (TextFile->Data[i + 3].substr(2, 8).compare("CORNERS ") == 0) Corners_row = 1; else - cout << - "Error in the file structure of the grid file!" << - "\n"; + cout << "Error in the file structure of the grid file!" + << "\n"; } - //Reads the corner points; order of the points (x1Data[i + 3 + Corners_row]); - in >> m_eclipseblock->x_coordinates[0] >> - m_eclipseblock->y_coordinates[0] >> - m_eclipseblock->z_coordinates[0] >> - m_eclipseblock->x_coordinates[1]; + in.str((string)TextFile->Data[i + 3 + Corners_row]); + in >> m_eclipseblock->x_coordinates[0] >> m_eclipseblock->y_coordinates[0] + >> m_eclipseblock->z_coordinates[0] >> m_eclipseblock->x_coordinates[1]; in.clear(); - in.str((string) TextFile->Data[i + 4 + Corners_row]); - in >> m_eclipseblock->y_coordinates[1] >> - m_eclipseblock->z_coordinates[1] >> - m_eclipseblock->x_coordinates[2] >> - m_eclipseblock->y_coordinates[2]; + in.str((string)TextFile->Data[i + 4 + Corners_row]); + in >> m_eclipseblock->y_coordinates[1] >> m_eclipseblock->z_coordinates[1] + >> m_eclipseblock->x_coordinates[2] >> m_eclipseblock->y_coordinates[2]; in.clear(); - in.str((string) TextFile->Data[i + 5 + Corners_row]); - in >> m_eclipseblock->z_coordinates[2] >> - m_eclipseblock->x_coordinates[3] >> - m_eclipseblock->y_coordinates[3] >> - m_eclipseblock->z_coordinates[3]; + in.str((string)TextFile->Data[i + 5 + Corners_row]); + in >> m_eclipseblock->z_coordinates[2] >> m_eclipseblock->x_coordinates[3] + >> m_eclipseblock->y_coordinates[3] >> m_eclipseblock->z_coordinates[3]; in.clear(); - in.str((string) TextFile->Data[i + 6 + Corners_row]); - in >> m_eclipseblock->x_coordinates[4] >> - m_eclipseblock->y_coordinates[4] >> - m_eclipseblock->z_coordinates[4] >> - m_eclipseblock->x_coordinates[5]; + in.str((string)TextFile->Data[i + 6 + Corners_row]); + in >> m_eclipseblock->x_coordinates[4] >> m_eclipseblock->y_coordinates[4] + >> m_eclipseblock->z_coordinates[4] >> m_eclipseblock->x_coordinates[5]; in.clear(); - in.str((string) TextFile->Data[i + 7 + Corners_row]); - in >> m_eclipseblock->y_coordinates[5] >> - m_eclipseblock->z_coordinates[5] >> - m_eclipseblock->x_coordinates[6] >> - m_eclipseblock->y_coordinates[6]; + in.str((string)TextFile->Data[i + 7 + Corners_row]); + in >> m_eclipseblock->y_coordinates[5] >> m_eclipseblock->z_coordinates[5] + >> m_eclipseblock->x_coordinates[6] >> m_eclipseblock->y_coordinates[6]; in.clear(); - in.str((string) TextFile->Data[i + 8 + Corners_row]); - in >> m_eclipseblock->z_coordinates[6] >> - m_eclipseblock->x_coordinates[7] >> - m_eclipseblock->y_coordinates[7] >> - m_eclipseblock->z_coordinates[7]; + in.str((string)TextFile->Data[i + 8 + Corners_row]); + in >> m_eclipseblock->z_coordinates[6] >> m_eclipseblock->x_coordinates[7] + >> m_eclipseblock->y_coordinates[7] >> m_eclipseblock->z_coordinates[7]; in.clear(); - //m_eclipseblock->CalcBarycentre(); // For block to node interpolation - //m_eclipseblock->CalculateFaceCentres(); + // m_eclipseblock->CalcBarycentre(); // For block to node interpolation + // m_eclipseblock->CalculateFaceCentres(); - //cout << m_eclipseblock->x_coordinates[0] << " " << m_eclipseblock->x_coordinates[1] << " " << m_eclipseblock->x_coordinates[2] << "\n"; + // cout << m_eclipseblock->x_coordinates[0] << " " << m_eclipseblock->x_coordinates[1] << " " << + // m_eclipseblock->x_coordinates[2] << "\n"; // adds 1 dataset of typ eclblocks to vec_eclblocks this->eclgrid.push_back(m_eclipseblock); - this->eclipse_ele_active_flag.push_back(true); //SB redo WTP + this->eclipse_ele_active_flag.push_back(true); // SB redo WTP } - else { - this->eclipse_ele_active_flag.push_back(false); //SB redo WTP + else + { + this->eclipse_ele_active_flag.push_back(false); // SB redo WTP } } } - //recalculate coordinates if it is a radial grid based on angle and radius + // recalculate coordinates if it is a radial grid based on angle and radius double alpha = 0; double radius = 0; if (Radialmodell == true) @@ -582,16 +571,18 @@ void CECLIPSEData::ReadEclipseGrid(std::string Filename) for (long i = 0; i < this->elements; i++) for (int j = 0; j < int(this->eclgrid[i]->x_coordinates.size()); j++) { - //coordinates are defined as radius, angle (clockwise in degree), heigth - //recalculate alpha from degree to radian (Bogenma�) - //cout << "Element: " << i << " Point: " << j << " alpha: " << this->eclgrid[i]->y_coordinates[j] << " radius: " << this->eclgrid[i]->x_coordinates[j]; + // coordinates are defined as radius, angle (clockwise in degree), heigth + // recalculate alpha from degree to radian (Bogenma�) + // cout << "Element: " << i << " Point: " << j << " alpha: " << this->eclgrid[i]->y_coordinates[j] << " + // radius: " << this->eclgrid[i]->x_coordinates[j]; alpha = this->eclgrid[i]->y_coordinates[j] * PI / 180; radius = this->eclgrid[i]->x_coordinates[j]; this->eclgrid[i]->x_coordinates[j] = sin(alpha) * radius; this->eclgrid[i]->y_coordinates[j] = cos(alpha) * radius; - //cout << " radius: " << radius << " x: " << this->eclgrid[i]->x_coordinates[j] << " y: " << this->eclgrid[i]->y_coordinates[j] << "\n"; + // cout << " radius: " << radius << " x: " << this->eclgrid[i]->x_coordinates[j] << " y: " << + // this->eclgrid[i]->y_coordinates[j] << "\n"; } - //this->eclgrid[i]->CalcBarycentre(); + // this->eclgrid[i]->CalcBarycentre(); double sum = 0; // check if radial model is in positiv I (EAST) direction (KB) for (long i = 0; i < this->elements; i++) @@ -600,13 +591,12 @@ void CECLIPSEData::ReadEclipseGrid(std::string Filename) sum = sum + this->eclgrid[i]->y_coordinates[k]; for (int j = 0; j < int(this->eclgrid[i]->x_coordinates.size()); j++) { - if ((int(this->eclgrid[i]->x_coordinates[j]) >= 0) && - ( sum > -0.00000001) && ( sum < 0.0000001)) // SB had them at *10^-1, redo wtp + if ((int(this->eclgrid[i]->x_coordinates[j]) >= 0) && (sum > -0.00000001) + && (sum < 0.0000001)) // SB had them at *10^-1, redo wtp this->RadialModellIpos = true; else { - cout << - "The Radialmodell is not perpendicular to the positive I axis (East direction)!!" + cout << "The Radialmodell is not perpendicular to the positive I axis (East direction)!!" << "\n"; cout.flush(); exit(0); @@ -615,12 +605,13 @@ void CECLIPSEData::ReadEclipseGrid(std::string Filename) } } - //Release memory + // Release memory delete (TextFile); finish = clock(); time = (double(finish) - double(start)) / CLOCKS_PER_SEC; - cout << " Time: " << time << " seconds." << "\n"; + cout << " Time: " << time << " seconds." + << "\n"; } /*------------------------------------------------------------------------- GeoSys - Function: DetermineNeighbourElements @@ -635,17 +626,17 @@ void CECLIPSEData::DetermineNeighbourElements(string Projectname) string tempstring; CReadTextfiles_ECL* TextFile; std::stringstream in; - //double Element; double X; double Y; double Z; double N1; double N2; double N3; double N4; double N5; double N6; + // double Element; double X; double Y; double Z; double N1; double N2; double N3; double N4; double N5; double N6; double X, Y, Z; - long Element, N[6]; + long Element, N[6]; bool error = false; - clock_t start,finish; + clock_t start, finish; double time; double fractpart, param, intpart; start = clock(); cout << " DetermineNeighbourElements()"; - //check if file *.neighbours exists, which stores the neighbours of each element + // check if file *.neighbours exists, which stores the neighbours of each element Filename = Projectname + ".neighbours"; TextFile = new CReadTextfiles_ECL; error = TextFile->Read_Text(Filename); @@ -653,48 +644,56 @@ void CECLIPSEData::DetermineNeighbourElements(string Projectname) double epsilon = 1e-3; if (error == false) { - //Read the neighbours of each element + // Read the neighbours of each element if ((TextFile->NumberOfRows - 2) == this->elements) for (long i = 0; i < TextFile->NumberOfRows - 2; i++) { - in.str ((string) TextFile->Data[i + 1]); + in.str((string)TextFile->Data[i + 1]); in >> Element >> X >> Y >> Z; - for(int j = 0; j < 6; j++) + for (int j = 0; j < 6; j++) in >> N[j]; in.clear(); - //string Neighbours[6]; - //Neighbours[0] = N1; - //Neighbours[1] = N2; - //Neighbours[2] = N3; - //Neighbours[3] = N4; - //Neighbours[4] = N5; - //Neighbours[5] = N6; + // string Neighbours[6]; + // Neighbours[0] = N1; + // Neighbours[1] = N2; + // Neighbours[2] = N3; + // Neighbours[3] = N4; + // Neighbours[4] = N5; + // Neighbours[5] = N6; - //this->SplittedString.clear(); - //this->SplitStrings(TextFile->Daten[i + 1], ";"); + // this->SplittedString.clear(); + // this->SplitStrings(TextFile->Daten[i + 1], ";"); - //if (atoi(this->SplittedString[0].data()) == i) {# + // if (atoi(this->SplittedString[0].data()) == i) {# if (Element == i) { - //cout << i << ": " << atof(this->SplittedString[1].data()) << " " << this->eclgrid[i]->x_barycentre << " " << atof(this->SplittedString[2].data()) << " " << this->eclgrid[i]->y_barycentre << " " << atof(this->SplittedString[3].data()) << " " << this->eclgrid[i]->z_barycentre << "\n"; - //cout << i << ": " << X << " " << this->eclgrid[i]->x_barycentre << " " << Y << " " << this->eclgrid[i]->y_barycentre << " " << Z << " " << this->eclgrid[i]->z_barycentre << "\n"; - //cout << epsilon << " " << abs(X - this->eclgrid[i]->x_barycentre) << " " << abs(Y - this->eclgrid[i]->y_barycentre) << " " << abs(Z - this->eclgrid[i]->z_barycentre) << "\n"; - //if ((abs(atof(this->SplittedString[1].data()) - this->eclgrid[i]->x_barycentre) < epsilon) && (abs(atof(this->SplittedString[2].data()) - this->eclgrid[i]->y_barycentre) < epsilon) && (abs(atof(this->SplittedString[3].data()) - this->eclgrid[i]->z_barycentre) < epsilon)) { - if ((abs(X - this->eclgrid[i]->x_barycentre) < epsilon) && - (abs(Y - this->eclgrid[i]->y_barycentre) < epsilon) && - (abs(Z - this->eclgrid[i]->z_barycentre) < epsilon)) - //if ((atof(this->SplittedString[1].data()) == this->eclgrid[i]->x_barycentre) && (atof(this->SplittedString[2].data()) == this->eclgrid[i]->y_barycentre) && (atof(this->SplittedString[3].data()) == this->eclgrid[i]->z_barycentre)) { + // cout << i << ": " << atof(this->SplittedString[1].data()) << " " << + // this->eclgrid[i]->x_barycentre << " " << atof(this->SplittedString[2].data()) << " " << + // this->eclgrid[i]->y_barycentre << " " << atof(this->SplittedString[3].data()) << " " << + // this->eclgrid[i]->z_barycentre << "\n"; + // cout << i << ": " << X << " " << this->eclgrid[i]->x_barycentre << " " << Y << " " << + // this->eclgrid[i]->y_barycentre << " " << Z << " " << this->eclgrid[i]->z_barycentre << "\n"; + // cout << epsilon << " " << abs(X - this->eclgrid[i]->x_barycentre) << " " << abs(Y - + // this->eclgrid[i]->y_barycentre) << " " << abs(Z - this->eclgrid[i]->z_barycentre) << "\n"; + // if ((abs(atof(this->SplittedString[1].data()) - this->eclgrid[i]->x_barycentre) < epsilon) && + // (abs(atof(this->SplittedString[2].data()) - this->eclgrid[i]->y_barycentre) < epsilon) && + // (abs(atof(this->SplittedString[3].data()) - this->eclgrid[i]->z_barycentre) < epsilon)) { + if ((abs(X - this->eclgrid[i]->x_barycentre) < epsilon) + && (abs(Y - this->eclgrid[i]->y_barycentre) < epsilon) + && (abs(Z - this->eclgrid[i]->z_barycentre) < epsilon)) + // if ((atof(this->SplittedString[1].data()) == this->eclgrid[i]->x_barycentre) && + // (atof(this->SplittedString[2].data()) == this->eclgrid[i]->y_barycentre) && + // (atof(this->SplittedString[3].data()) == this->eclgrid[i]->z_barycentre)) { for (int j = 0; j < 6; j++) - //this->eclgrid[i]->NeighbourElement[j] = atoi(this->SplittedString[j + 4].data()); - //for (int k = 1; k < Neighbours[6].size(); k++){ - this->eclgrid[i]->NeighbourElement[j] = - N[j]; + // this->eclgrid[i]->NeighbourElement[j] = atoi(this->SplittedString[j + 4].data()); + // for (int k = 1; k < Neighbours[6].size(); k++){ + this->eclgrid[i]->NeighbourElement[j] = N[j]; } // wtp is this bracket correct? - //atoi(Neighbours[j].data()); + // atoi(Neighbours[j].data()); else Error_NeighbourFile = true; - } // end for(i ... + } // end for(i ... else Error_NeighbourFile = true; } @@ -702,111 +701,98 @@ void CECLIPSEData::DetermineNeighbourElements(string Projectname) { Error_NeighbourFile = true; - //if (Error_NeighbourFile == true) { + // if (Error_NeighbourFile == true) { // cout << "The program is canceled because the *.neighbours file is not correct!" << "\n"; // //system("Pause"); // exit(0); //} - //Release memory - + // Release memory } delete (TextFile); if ((error == true) || (Error_NeighbourFile == true)) { - cout << " Create new *.neighbours file." << "\n"; - //Set neighbourElements to -1 + cout << " Create new *.neighbours file." + << "\n"; + // Set neighbourElements to -1 for (unsigned long i = 0; i < this->eclgrid.size(); i++) for (unsigned int j = 0; j < this->eclgrid[i]->NeighbourElement.size(); j++) this->eclgrid[i]->NeighbourElement[j] = -1; - //Determine neighboured Elements - //Order of the faces: 0..left(x); 1..right(x); 2..front(y); 3..back(y); 4..top(z); 5..bottom(z) + // Determine neighboured Elements + // Order of the faces: 0..left(x); 1..right(x); 2..front(y); 3..back(y); 4..top(z); 5..bottom(z) for (size_t i = 0; i < this->eclgrid.size(); i++) for (size_t j = i + 1; j < this->eclgrid.size(); j++) { param = static_cast(j + (i * this->eclgrid.size())); param /= 1000; - fractpart = modf (param, &intpart); + fractpart = modf(param, &intpart); if (fractpart == 0) { - param = static_cast(100 * (j + i * this->eclgrid.size()) / - (this->eclgrid.size() * this->eclgrid.size())); - //cout << " " << Round(param, 3) << " %" << "\n"; + param = static_cast(100 * (j + i * this->eclgrid.size()) + / (this->eclgrid.size() * this->eclgrid.size())); + // cout << " " << Round(param, 3) << " %" << "\n"; } if (this->eclgrid[i]->layer == this->eclgrid[j]->layer) { if (this->eclgrid[i]->row == this->eclgrid[j]->row) { - //right neighbour of the current element i - if (this->eclgrid[i]->column == - this->eclgrid[j]->column - 1) + // right neighbour of the current element i + if (this->eclgrid[i]->column == this->eclgrid[j]->column - 1) { - this->eclgrid[i]->NeighbourElement[1] = - this->eclgrid[j]->index; - this->eclgrid[j]->NeighbourElement[0] = - this->eclgrid[i]->index; + this->eclgrid[i]->NeighbourElement[1] = this->eclgrid[j]->index; + this->eclgrid[j]->NeighbourElement[0] = this->eclgrid[i]->index; } - //left neighbour of the current element i - if (this->eclgrid[i]->column == - this->eclgrid[j]->column + 1) + // left neighbour of the current element i + if (this->eclgrid[i]->column == this->eclgrid[j]->column + 1) { - this->eclgrid[i]->NeighbourElement[0] = - this->eclgrid[j]->index; - this->eclgrid[j]->NeighbourElement[1] = - this->eclgrid[i]->index; + this->eclgrid[i]->NeighbourElement[0] = this->eclgrid[j]->index; + this->eclgrid[j]->NeighbourElement[1] = this->eclgrid[i]->index; } } if (this->eclgrid[i]->column == this->eclgrid[j]->column) { - //Back neighbour of the current element i - if (this->eclgrid[i]->row == - this->eclgrid[j]->row - 1) + // Back neighbour of the current element i + if (this->eclgrid[i]->row == this->eclgrid[j]->row - 1) { - this->eclgrid[i]->NeighbourElement[3] = - this->eclgrid[j]->index; - this->eclgrid[j]->NeighbourElement[2] = - this->eclgrid[i]->index; + this->eclgrid[i]->NeighbourElement[3] = this->eclgrid[j]->index; + this->eclgrid[j]->NeighbourElement[2] = this->eclgrid[i]->index; } - //Front neighbour of the current element i - if (this->eclgrid[i]->row == - this->eclgrid[j]->row + 1) + // Front neighbour of the current element i + if (this->eclgrid[i]->row == this->eclgrid[j]->row + 1) { - this->eclgrid[i]->NeighbourElement[2] = - this->eclgrid[j]->index; - this->eclgrid[j]->NeighbourElement[3] = - this->eclgrid[i]->index; + this->eclgrid[i]->NeighbourElement[2] = this->eclgrid[j]->index; + this->eclgrid[j]->NeighbourElement[3] = this->eclgrid[i]->index; } } } if (this->eclgrid[i]->layer == this->eclgrid[j]->layer - 1) - //bottom neighbour of the current element i - if ((this->eclgrid[i]->row == this->eclgrid[j]->row) && - (this->eclgrid[i]->column == this->eclgrid[j]->column)) + // bottom neighbour of the current element i + if ((this->eclgrid[i]->row == this->eclgrid[j]->row) + && (this->eclgrid[i]->column == this->eclgrid[j]->column)) { - this->eclgrid[i]->NeighbourElement[5] = - this->eclgrid[j]->index; - this->eclgrid[j]->NeighbourElement[4] = - this->eclgrid[i]->index; + this->eclgrid[i]->NeighbourElement[5] = this->eclgrid[j]->index; + this->eclgrid[j]->NeighbourElement[4] = this->eclgrid[i]->index; } if (this->eclgrid[i]->layer == this->eclgrid[j]->layer + 1) - //top neighbour of the current element i - if ((this->eclgrid[i]->row == this->eclgrid[j]->row) && - (this->eclgrid[i]->column == this->eclgrid[j]->column)) + // top neighbour of the current element i + if ((this->eclgrid[i]->row == this->eclgrid[j]->row) + && (this->eclgrid[i]->column == this->eclgrid[j]->column)) { - this->eclgrid[i]->NeighbourElement[4] = - this->eclgrid[j]->index; - this->eclgrid[j]->NeighbourElement[5] = - this->eclgrid[i]->index; + this->eclgrid[i]->NeighbourElement[4] = this->eclgrid[j]->index; + this->eclgrid[j]->NeighbourElement[5] = this->eclgrid[i]->index; } } - //check - //cout << this->eclgrid[i]->index << ": " << this->eclgrid[i]->NeighbourElement[0] << " " << this->eclgrid[i]->NeighbourElement[1] << " " << this->eclgrid[i]->NeighbourElement[2] << " " << this->eclgrid[i]->NeighbourElement[3] << " " << this->eclgrid[i]->NeighbourElement[4] << " " << this->eclgrid[i]->NeighbourElement[5] << "\n"; - - //data output - vector vec_string; + // check + // cout << this->eclgrid[i]->index << ": " << this->eclgrid[i]->NeighbourElement[0] << " " << + // this->eclgrid[i]->NeighbourElement[1] << " " << this->eclgrid[i]->NeighbourElement[2] << " " << + // this->eclgrid[i]->NeighbourElement[3] << " " << this->eclgrid[i]->NeighbourElement[4] << " " << + // this->eclgrid[i]->NeighbourElement[5] << "\n"; + + // data output + vector vec_string; ostringstream temp; tempstring = "Element X Y Z N1 N2 N3 N4 N5 N6"; vec_string.push_back(tempstring); @@ -843,14 +829,14 @@ void CECLIPSEData::DetermineNeighbourElements(string Projectname) // Test Output Filename = Projectname + ".neighbours"; ofstream aus; - aus.open(Filename.data(),ios::out); + aus.open(Filename.data(), ios::out); for (unsigned int i = 0; i < vec_string.size(); i++) aus << vec_string[i] << "\n"; aus.close(); } // Does not work if inactive cells are neglected - //for (unsigned long i = 0; i < this->eclgrid.size(); i++) { + // for (unsigned long i = 0; i < this->eclgrid.size(); i++) { // //Calculating neighboured element in x-direction // if (this->eclgrid[i]->column > 1) { // this->eclgrid[i]->NeighbourElement[0] = this->eclgrid[i]->index - 1; @@ -873,13 +859,17 @@ void CECLIPSEData::DetermineNeighbourElements(string Projectname) // this->eclgrid[i]->NeighbourElement[5] = this->eclgrid[i]->index + (this->columns*this->rows); // } // //check - // //cout << this->eclgrid[i]->index << ": " << this->eclgrid[i]->NeighbourElement[0] << " " << this->eclgrid[i]->NeighbourElement[1] << " " << this->eclgrid[i]->NeighbourElement[2] << " " << this->eclgrid[i]->NeighbourElement[3] << " " << this->eclgrid[i]->NeighbourElement[4] << " " << this->eclgrid[i]->NeighbourElement[5] << "\n"; + // //cout << this->eclgrid[i]->index << ": " << this->eclgrid[i]->NeighbourElement[0] << " " << + // this->eclgrid[i]->NeighbourElement[1] << " " << this->eclgrid[i]->NeighbourElement[2] << " " << + // this->eclgrid[i]->NeighbourElement[3] << " " << this->eclgrid[i]->NeighbourElement[4] << " " << + // this->eclgrid[i]->NeighbourElement[5] << "\n"; //} - //cout << "i" << "\n"; + // cout << "i" << "\n"; finish = clock(); time = (double(finish) - double(start)) / CLOCKS_PER_SEC; - cout << " Time: " << time << " seconds." << "\n"; + cout << " Time: " << time << " seconds." + << "\n"; } /*------------------------------------------------------------------------- GeoSys - Function: ReadDataFromInputFile @@ -893,16 +883,16 @@ int CECLIPSEData::ReadDataFromInputFile(std::string Filename) { std::string tempstring; std::string tempstring_l; - //CBoundaryConditions* m_BoundaryConditions = NULL; // unused - CReadTextfiles_ECL *TextFile; + // CBoundaryConditions* m_BoundaryConditions = NULL; // unused + CReadTextfiles_ECL* TextFile; std::stringstream in; double density; bool error; - //WW bool success = false; - std::string dummy_rate,dummy_zeile,rest_zeile, name, phase, open_flag, control_mode; + // WW bool success = false; + std::string dummy_rate, dummy_zeile, rest_zeile, name, phase, open_flag, control_mode; int jj = 0; - std::string incl("GRID_PROPS.INC"); //SB redo wtp - size_t found; //SB redo wtp + std::string incl("GRID_PROPS.INC"); // SB redo wtp + size_t found; // SB redo wtp density = -1; TextFile = new CReadTextfiles_ECL; @@ -910,47 +900,53 @@ int CECLIPSEData::ReadDataFromInputFile(std::string Filename) if (error == true) { - cout << "The file: " << Filename << - "could not been read! The program is canceled" << "\n"; - //system("Pause"); + cout << "The file: " << Filename << "could not been read! The program is canceled" + << "\n"; + // system("Pause"); exit(0); } - //Read in the input file and search for the keyword DENSITY + // Read in the input file and search for the keyword DENSITY for (long l = 0; l < TextFile->NumberOfRows; l++) { - tempstring_l = TextFile->Data[l].substr(0,8); // WTP: This longer tempstring is needed to compare longer Keywords such as "WCONINJE" - tempstring = TextFile->Data[l].substr(0,7); + tempstring_l = TextFile->Data[l].substr( + 0, 8); // WTP: This longer tempstring is needed to compare longer Keywords such as "WCONINJE" + tempstring = TextFile->Data[l].substr(0, 7); long zeilen = 0; // SB_CB, begin redo WTP - if(tempstring.compare("INCLUDE") == 0) { - do { - zeilen = zeilen +1; - } - while (TextFile->Data[l + zeilen] == ""); // look for possible empty rows between the Keyword and the items - while ((TextFile->Data[l + zeilen] != "") && (TextFile->Data[l+ zeilen] != "/")) { - if (TextFile->Data[l + zeilen].substr(0,2) != "--") { // ignore comments - found=TextFile->Data[l + zeilen].find(incl); - if(found!=string::npos) { - PoroPermIncludeFile = true; - break; + if (tempstring.compare("INCLUDE") == 0) + { + do + { + zeilen = zeilen + 1; + } while (TextFile->Data[l + zeilen] + == ""); // look for possible empty rows between the Keyword and the items + while ((TextFile->Data[l + zeilen] != "") && (TextFile->Data[l + zeilen] != "/")) + { + if (TextFile->Data[l + zeilen].substr(0, 2) != "--") + { // ignore comments + found = TextFile->Data[l + zeilen].find(incl); + if (found != string::npos) + { + PoroPermIncludeFile = true; + break; + } } + zeilen = zeilen + 1; } - zeilen = zeilen + 1; } - } // end if (tempstring.compare("DENSITY") == 0) { - do { + do + { zeilen = zeilen + 1; - } - while (TextFile->Data[l + zeilen] == ""); // look for possible empty rows between the Keyword and the items + } while (TextFile->Data[l + zeilen] + == ""); // look for possible empty rows between the Keyword and the items - //zeilen = zeilen + 1;//End of the block is characterised with "" or "/" - while ((TextFile->Data[l + zeilen] != "") && - (TextFile->Data[l + zeilen] != "/")) + // zeilen = zeilen + 1;//End of the block is characterised with "" or "/" + while ((TextFile->Data[l + zeilen] != "") && (TextFile->Data[l + zeilen] != "/")) { string delimiter = " "; SplittedString.clear(); @@ -959,12 +955,10 @@ int CECLIPSEData::ReadDataFromInputFile(std::string Filename) { density = atof(SplittedString[2].data()); this->SurfaceCO2Density = density; - //check if the number of bc is plausibel + // check if the number of bc is plausibel if ((density > 800) || (density < 0)) { - cout << - "The surface density of CO2 seems not to be correct: " - << density << "\n"; + cout << "The surface density of CO2 seems not to be correct: " << density << "\n"; return 0; } else @@ -977,20 +971,20 @@ int CECLIPSEData::ReadDataFromInputFile(std::string Filename) if (this->existWells == true) if (tempstring_l.compare("WCONINJE") == 0) { - //WW success = true; + // WW success = true; long zeilen = 0; - do { + do + { zeilen = zeilen + 1; - } - while (TextFile->Data[l + zeilen] != ""); // look for possible empty rows between the Keyword and the items + } while (TextFile->Data[l + zeilen] + != ""); // look for possible empty rows between the Keyword and the items jj = 0; /* WTP: this loop starts at the wrong position and therefore does not read the data for(long unsigned j = l + zeilen + 1; j < (l + this->ecl_well.size() + zeilen + 1); j++)*/ - for(long unsigned j = l + 1; - j < (l + this->ecl_well.size() + 1); j++) + for (long unsigned j = l + 1; j < (l + this->ecl_well.size() + 1); j++) { if (this->actual_time == 0) { @@ -1025,29 +1019,30 @@ void CECLIPSEData::ReadWellData(std::string Filename_Wells) char Line[MAX_ZEILEN]; std::string tempstring; std::stringstream line; - //WW bool error = false; + // WW bool error = false; streampos position; std::string dollar("$"); std::string hash("#"); - //WW bool new_subkeyword = false; + // WW bool new_subkeyword = false; // bool new_keyword = false; // unused std::string tempstring_name; std::string tempvalue_rate; double tempvalue_time; - clock_t start,finish; + clock_t start, finish; double time; start = clock(); cout << " ReadWellSection()"; - ifstream in(Filename_Wells.data(),ios::in); + ifstream in(Filename_Wells.data(), ios::in); if (!in) - std::cout << "File not found." << "\n"; - //WW error = true; + std::cout << "File not found." + << "\n"; + // WW error = true; else while (!in.eof()) { @@ -1055,27 +1050,28 @@ void CECLIPSEData::ReadWellData(std::string Filename_Wells) position = in.tellg(); tempstring = Line; if (tempstring.find("#STOP") != std::string::npos) - std::cout << "ok" << "\n"; + std::cout << "ok" + << "\n"; - //if(tempstring.size() < 1) break; - //if(tempstring.find(hash)!=string::npos) { + // if(tempstring.size() < 1) break; + // if(tempstring.find(hash)!=string::npos) { // new_keyword = true; // break; //} - //NAME - if(tempstring.find("$NAME") != string::npos) //subkeyword found + // NAME + if (tempstring.find("$NAME") != string::npos) // subkeyword found { ecl_single_well = new structWell; in >> tempstring_name; ecl_single_well->name = tempstring_name; in.clear(); - //continue; + // continue; } - //TIMECURVE - if(tempstring.find("$TIMECURVE") != string::npos) //subkeyword found + // TIMECURVE + if (tempstring.find("$TIMECURVE") != string::npos) // subkeyword found { while (tempstring.find("#") != 0) { @@ -1084,15 +1080,15 @@ void CECLIPSEData::ReadWellData(std::string Filename_Wells) tempstring = Line; if (tempstring.find("#") != string::npos) break; - if(tempstring.find("$") != string::npos) - //WW new_subkeyword = true; + if (tempstring.find("$") != string::npos) + // WW new_subkeyword = true; break; in.seekg(position); in >> tempvalue_time; ecl_single_well->time.push_back(tempvalue_time); in >> tempvalue_rate; ecl_single_well->rate.push_back(tempvalue_rate); - //if ((double(ecl_single_well->time.begin())) != "0"){ + // if ((double(ecl_single_well->time.begin())) != "0"){ // cout << "Warning: first item of time in timecurve is not 0!" << "\n"; // break; //} @@ -1100,31 +1096,31 @@ void CECLIPSEData::ReadWellData(std::string Filename_Wells) in.getline(Line, MAX_ZEILEN); tempstring = Line; - //position = in.tellg(); - //in.getline(Line, MAX_ZEILEN); - //tempstring = Line; - //string delimiter=" "; - //SplittedString.clear(); + // position = in.tellg(); + // in.getline(Line, MAX_ZEILEN); + // tempstring = Line; + // string delimiter=" "; + // SplittedString.clear(); // - //SplitStrings(tempstring, delimiter); + // SplitStrings(tempstring, delimiter); - //for (unsigned int m = 0; m < SplittedString.size(); m++) { + // for (unsigned int m = 0; m < SplittedString.size(); m++) { // if (m == 0)ecl_single_well->time = atof(SplittedString[m]); // if (m == 1)ecl_single_well->time.push_back(SplittedString[m]); //} - //position = in.tellg(); - //in.getline(Line, MAX_ZEILEN); - //tempstring = Line; - //in >> tempvalue_time; - //ecl_single_well->time.push_back(tempvalue_time); - //in >> tempvalue_rate; - //ecl_single_well->rate.push_back(tempvalue_rate); - //in.clear(); - //in.seekg(position); - //in.getline(Line, MAX_ZEILEN); - - //continue; + // position = in.tellg(); + // in.getline(Line, MAX_ZEILEN); + // tempstring = Line; + // in >> tempvalue_time; + // ecl_single_well->time.push_back(tempvalue_time); + // in >> tempvalue_rate; + // ecl_single_well->rate.push_back(tempvalue_rate); + // in.clear(); + // in.seekg(position); + // in.getline(Line, MAX_ZEILEN); + + // continue; } if (!tempstring_name.empty()) // Kontrolle, dass Name nicht leer! @@ -1133,7 +1129,8 @@ void CECLIPSEData::ReadWellData(std::string Filename_Wells) } finish = clock(); time = (double(finish) - double(start)) / CLOCKS_PER_SEC; - cout << " Time: " << time << " seconds." << "\n"; + cout << " Time: " << time << " seconds." + << "\n"; } /*------------------------------------------------------------------------- @@ -1166,23 +1163,22 @@ bool CECLIPSEData::ReadPositionBoundaryCondition(std::string Filename) if (error == true) { - cout << "The file: " << Filename << - "could not been read! The program is canceled" << "\n"; - //system("Pause"); + cout << "The file: " << Filename << "could not been read! The program is canceled" + << "\n"; + // system("Pause"); exit(0); } - //Read in the input file and search for the keyword AQUANCON + // Read in the input file and search for the keyword AQUANCON for (long l = 0; l < TextFile->NumberOfRows; l++) { - tempstring = TextFile->Data[l].substr(0,8); + tempstring = TextFile->Data[l].substr(0, 8); zeile = 1; if (tempstring.compare("AQUANCON") == 0) { - //End of the block is characterised with "" or "/" + // End of the block is characterised with "" or "/" - while ((TextFile->Data[l + zeile] != "") && - (TextFile->Data[l + zeile] != "/")) + while ((TextFile->Data[l + zeile] != "") && (TextFile->Data[l + zeile] != "/")) { std::string delimiter = " "; SplittedString.clear(); @@ -1191,11 +1187,11 @@ bool CECLIPSEData::ReadPositionBoundaryCondition(std::string Filename) if (TextFile->Data[l + zeile].substr(0, 2) != "--") // ignore comments { number = atoi(SplittedString[0].data()); - //check if the number of bc is plausibel + // check if the number of bc is plausibel if (number > 200) { - cout << - "There were more than 200 bc found in the Eclipse model. Please make sure that the definitions at the keyword AQUANCON are correct!" + cout << "There were more than 200 bc found in the Eclipse model. Please make sure that the " + "definitions at the keyword AQUANCON are correct!" << "\n"; return false; } @@ -1205,50 +1201,28 @@ bool CECLIPSEData::ReadPositionBoundaryCondition(std::string Filename) j2 = atoi(SplittedString[4].data()); k1 = atoi(SplittedString[5].data()); k2 = atoi(SplittedString[6].data()); - boundary_position = SplittedString[7].substr(1,2); + boundary_position = SplittedString[7].substr(1, 2); index = -1; - //order of cells in output files: z1, y1, x1..xn; z1, y2, x1..xn; z2, y1, x1..xn + // order of cells in output files: z1, y1, x1..xn; z1, y2, x1..xn; z2, y1, x1..xn for (int k = k1; k <= k2; k++) { for (int j = j1; j <= j2; j++) for (int i = i1; i <= i2; i++) { index = index + 1; - m_BoundaryConditions = - new CBoundaryConditions(); // new member of eclblock + m_BoundaryConditions = new CBoundaryConditions(); // new member of eclblock m_BoundaryConditions->index = index; - m_BoundaryConditions->number = - number; - m_BoundaryConditions-> - boundary_position = - boundary_position; - for (long m = 0; m < this->elements; - m++) - if ((this->eclgrid[m]-> - column == i) && - (this->eclgrid[m]->row - == - j) && - (this->eclgrid[m]-> - layer == - k)) - m_BoundaryConditions - ->connected_element - = this-> - eclgrid[m - ]-> - index; - - this->BC.push_back( - m_BoundaryConditions); - long index_boundary = - long(this->BC.size() - 1); - this->eclgrid[m_BoundaryConditions - ->connected_element] - -> - ConnectedBoundaryCondition. - push_back( - index_boundary); + m_BoundaryConditions->number = number; + m_BoundaryConditions->boundary_position = boundary_position; + for (long m = 0; m < this->elements; m++) + if ((this->eclgrid[m]->column == i) && (this->eclgrid[m]->row == j) + && (this->eclgrid[m]->layer == k)) + m_BoundaryConditions->connected_element = this->eclgrid[m]->index; + + this->BC.push_back(m_BoundaryConditions); + long index_boundary = long(this->BC.size() - 1); + this->eclgrid[m_BoundaryConditions->connected_element] + ->ConnectedBoundaryCondition.push_back(index_boundary); } } if (m_BoundaryConditions->connected_element == -1) @@ -1268,14 +1242,14 @@ bool CECLIPSEData::ReadPositionBoundaryCondition(std::string Filename) Programming: 09/2009 BG Modification: -------------------------------------------------------------------------*/ -bool CECLIPSEData::ReadBoundaryData(int index_boundary, vector Data) +bool CECLIPSEData::ReadBoundaryData(int index_boundary, vector Data) { int counter; int number_values = 4; int number_cell; int number_value; - //4 numbers are given for each boundary cell (order of the cells at the moment unknown!!!) + // 4 numbers are given for each boundary cell (order of the cells at the moment unknown!!!) counter = -1; for (unsigned long i = 0; i < Data.size(); i++) { @@ -1284,30 +1258,28 @@ bool CECLIPSEData::ReadBoundaryData(int index_boundary, vector Data) { std::string SplitBoundaryData[3]; - //this->SplitBoundaryData.push_back(Data[i].substr(3,20)); - //this->SplitBoundaryData.push_back(Data[i].substr(26,20)); - //this->SplitBoundaryData.push_back(Data[i].substr(49,20)); + // this->SplitBoundaryData.push_back(Data[i].substr(3,20)); + // this->SplitBoundaryData.push_back(Data[i].substr(26,20)); + // this->SplitBoundaryData.push_back(Data[i].substr(49,20)); - SplitBoundaryData[0] = Data[i].substr(3,20); - SplitBoundaryData[1] = Data[i].substr(26,20); - SplitBoundaryData[2] = Data[i].substr(49,20); + SplitBoundaryData[0] = Data[i].substr(3, 20); + SplitBoundaryData[1] = Data[i].substr(26, 20); + SplitBoundaryData[2] = Data[i].substr(49, 20); - //cout << SplitBoundaryData.size() << "\n"; + // cout << SplitBoundaryData.size() << "\n"; - //for (unsigned int j = 0; j < this->SplittedString.size(); j++){ + // for (unsigned int j = 0; j < this->SplittedString.size(); j++){ for (unsigned int j = 0; j < 3; j++) { counter = counter + 1; number_cell = int(counter / number_values); number_value = counter - (number_cell * number_values); - //search for the corresponding BC (the same boundary number and the index indentical to the counter + // search for the corresponding BC (the same boundary number and the index indentical to the counter for (unsigned int k = 0; k < this->BC.size(); k++) - if ((this->BC[k]->number == index_boundary) && - (this->BC[k]->index == number_cell)) + if ((this->BC[k]->number == index_boundary) && (this->BC[k]->index == number_cell)) { - //this->BC[k]->value[number_value] = atof(this->SplittedString[j].data()); - this->BC[k]->value[number_value] = atof( - SplitBoundaryData[j].data()); + // this->BC[k]->value[number_value] = atof(this->SplittedString[j].data()); + this->BC[k]->value[number_value] = atof(SplitBoundaryData[j].data()); k = int(this->BC.size()); } } @@ -1315,29 +1287,27 @@ bool CECLIPSEData::ReadBoundaryData(int index_boundary, vector Data) else { this->SplittedString.clear(); - this->SplitStrings(Data[i]," "); + this->SplitStrings(Data[i], " "); if (i == 0) if (SplittedString.size() != 3) return false; - //string SplitBoundaryData[2]; + // string SplitBoundaryData[2]; - //SplitBoundaryData[0] = Data[i].substr(3,20); - //SplitBoundaryData[1] = Data[i].substr(26,20); + // SplitBoundaryData[0] = Data[i].substr(3,20); + // SplitBoundaryData[1] = Data[i].substr(26,20); - //for (unsigned int j = 0; j < 2; j++){ + // for (unsigned int j = 0; j < 2; j++){ for (unsigned int j = 0; j < this->SplittedString.size(); j++) { counter = counter + 1; number_cell = int(counter / number_values); number_value = counter - (number_cell * number_values); - //search for the corresponding BC (the same boundary number and the index indentical to the counter + // search for the corresponding BC (the same boundary number and the index indentical to the counter for (unsigned int k = 0; k < this->BC.size(); k++) - if ((this->BC[k]->number == index_boundary) && - (this->BC[k]->index == number_cell)) + if ((this->BC[k]->number == index_boundary) && (this->BC[k]->index == number_cell)) { - this->BC[k]->value[number_value] = atof( - this->SplittedString[j].data()); - //this->BC[k]->value[number_value] = atof(SplitBoundaryData[j].data()); + this->BC[k]->value[number_value] = atof(this->SplittedString[j].data()); + // this->BC[k]->value[number_value] = atof(SplitBoundaryData[j].data()); k = int(this->BC.size()); } } @@ -1360,7 +1330,7 @@ void CECLIPSEData::ReadEclipseData(std::string Filename, long Timestep) CReadTextfiles_ECL* TextFile; std::string tempstring; bool saturation_water, saturation_gas, saturation_oil; - clock_t start,finish; + clock_t start, finish; double time; start = clock(); @@ -1368,17 +1338,17 @@ void CECLIPSEData::ReadEclipseData(std::string Filename, long Timestep) saturation_water = saturation_gas = saturation_oil = false; cout << " ReadEclipseData() "; - //get memory for data structures - if(Data == NULL) // allocate first time + // get memory for data structures + if (Data == NULL) // allocate first time { - Data = (double**) malloc((this->elements) * sizeof(double*)); - for(long i = 0; i < (this->elements); i++) - Data[i] = (double*) malloc(this->numberOutputParameters * sizeof(double)); - //for(long i = 0; i < (this->elements); i++) + Data = (double**)malloc((this->elements) * sizeof(double*)); + for (long i = 0; i < (this->elements); i++) + Data[i] = (double*)malloc(this->numberOutputParameters * sizeof(double)); + // for(long i = 0; i < (this->elements); i++) // for(long j = 0; j < this->times; j++) // Data[i][j] = (double *) malloc(this->numberOutputParameters*sizeof(double)); - //Deallokieren + // Deallokieren /*Data2 = (double **) malloc(1000000 * sizeof(double*)); for(long i = 0; i < (1000000); i++) Data2[i] = (double *) malloc(100 * sizeof(double)); @@ -1388,84 +1358,75 @@ void CECLIPSEData::ReadEclipseData(std::string Filename, long Timestep) free(Data2);*/ } - //initialise data structure - for(long i = 0; i < (this->elements); i++) - for(int k = 0; k < this->numberOutputParameters; k++) + // initialise data structure + for (long i = 0; i < (this->elements); i++) + for (int k = 0; k < this->numberOutputParameters; k++) Data[i][k] = 0; - //Reads the text file (usually 60 bytes in one row of the eclipse output + // Reads the text file (usually 60 bytes in one row of the eclipse output bool Error; TextFile = new CReadTextfiles_ECL; Error = TextFile->Read_Text(Filename); if (Error == true) { - cout << "The program is canceled in ReadEclipseData()" << "\n"; - //system("Pause"); + cout << "The program is canceled in ReadEclipseData()" + << "\n"; + // system("Pause"); exit(0); } for (long j = 0; j < TextFile->NumberOfRows; j++) { - //if (j==565 || j ==1384) { + // if (j==565 || j ==1384) { // cout << TextFile->Daten[j] << "\n"; //} double Multiplier = 1; - if (TextFile->Data[j].length() > 0 && TextFile->Data[j].substr(1,1) == "'") + if (TextFile->Data[j].length() > 0 && TextFile->Data[j].substr(1, 1) == "'") { - std::string tempstring = TextFile->Data[j].substr(2,8); - tempstring = tempstring.substr(0,tempstring.find_first_of(" ")); + std::string tempstring = TextFile->Data[j].substr(2, 8); + tempstring = tempstring.substr(0, tempstring.find_first_of(" ")); for (unsigned int k = 0; k < this->Variables.size(); k++) if (tempstring.compare(this->Variables[k]) == 0) { if (this->Variables[k].compare("ACAQNUM") == 0) { - int index_boundary = atoi( - TextFile->Data[j + 1].substr(0,12).data()); + int index_boundary = atoi(TextFile->Data[j + 1].substr(0, 12).data()); this->SplittedString.clear(); this->SplitStrings(TextFile->Data[j + 2], " "); - int temprows = - int(atoi(this->SplittedString[2].data()) / - 3) + 1; - vector temp_Daten; + int temprows = int(atoi(this->SplittedString[2].data()) / 3) + 1; + vector temp_Daten; for (int l = 0; l < temprows; l++) - temp_Daten.push_back(TextFile->Data[j + 3 + - l]); - if (this->ReadBoundaryData(index_boundary, - temp_Daten) == false) + temp_Daten.push_back(TextFile->Data[j + 3 + l]); + if (this->ReadBoundaryData(index_boundary, temp_Daten) == false) { - cout << - "Error while reading boundary data." << - "\n"; - //system("Pause"); + cout << "Error while reading boundary data." + << "\n"; + // system("Pause"); exit(0); } } else { - //convert pressure units from bar to Pa - if ((this->Variables[k].compare("PRESSURE") == - 0) || - (this->Variables[k].compare("PCOW") == 0) || - (this->Variables[k].compare("PCOG") == 0) || - (this->Variables[k].compare("PWAT") == 0) || - (this->Variables[k].compare("PGAS") == 0) || - (this->Variables[k].compare("POIL") == 0)) + // convert pressure units from bar to Pa + if ((this->Variables[k].compare("PRESSURE") == 0) || (this->Variables[k].compare("PCOW") == 0) + || (this->Variables[k].compare("PCOG") == 0) + || (this->Variables[k].compare("PWAT") == 0) + || (this->Variables[k].compare("PGAS") == 0) + || (this->Variables[k].compare("POIL") == 0)) Multiplier = 100000.0; // consider different orientation of the z-axis in Eclipse and GeoSys - if ((this->Variables[k].compare("FLOWATK+") == - 0) || - (this->Variables[k].compare("FLOOILK+") == - 0) || - (this->Variables[k].compare("FLOGASK+") == 0)) + if ((this->Variables[k].compare("FLOWATK+") == 0) + || (this->Variables[k].compare("FLOOILK+") == 0) + || (this->Variables[k].compare("FLOGASK+") == 0)) Multiplier = -1.0; if (this->Variables[k].compare("RS") == 0) - Multiplier = 1.0; // Unit: m^3 gas per m^3 oil + Multiplier = 1.0; // Unit: m^3 gas per m^3 oil if (this->Variables[k].compare("GAS_DEN") == 0) - Multiplier = 1.0; // Unit: kg/m^3 + Multiplier = 1.0; // Unit: kg/m^3 - //set a flag of which phase saturation was red + // set a flag of which phase saturation was red if (this->Variables[k].compare("SWAT") == 0) saturation_water = true; if (this->Variables[k].compare("SGAS") == 0) @@ -1474,184 +1435,109 @@ void CECLIPSEData::ReadEclipseData(std::string Filename, long Timestep) saturation_oil = true; // read number of datapoints - double tempNumber = - atoi(TextFile->Data[j].substr(12,13).data()); + double tempNumber = atoi(TextFile->Data[j].substr(12, 13).data()); long temprows = 0; if (tempNumber == this->elements) { temprows = int(ceil(tempNumber / 4.0)); - //Read data for identified variable + // Read data for identified variable long rowindex = 0; - for (long l = j + 1; l < j + temprows + 1; - l++) + for (long l = j + 1; l < j + temprows + 1; l++) { if (l < (j + temprows)) { - std::string Dataline[4]; // Definition einen strings mit 4 Arrays, Arrays immer in eckigen Klammern definieren - Dataline[0] = - TextFile->Data[l]. - substr(2, - 15); - Dataline[1] = - TextFile->Data[l]. - substr(19, - 15); - Dataline[2] = - TextFile->Data[l]. - substr(36, - 15); - Dataline[3] = - TextFile->Data[l]. - substr(53, - 15); - for (unsigned int m = 0; - m < 4; m++) + std::string Dataline[4]; // Definition einen strings mit 4 Arrays, Arrays immer in + // eckigen Klammern definieren + Dataline[0] = TextFile->Data[l].substr(2, 15); + Dataline[1] = TextFile->Data[l].substr(19, 15); + Dataline[2] = TextFile->Data[l].substr(36, 15); + Dataline[3] = TextFile->Data[l].substr(53, 15); + for (unsigned int m = 0; m < 4; m++) { - rowindex = - rowindex + - 1; //zaehlt die gesplitteten Zeilen in der Zeile, in Variante KB4 entspricht das 4 - this->Data[rowindex - - 1][k] - = atof( - Dataline[m] - .data()) - * - Multiplier; //schreibt die Zeile aus Dataline mit allen m und dem Keyword k in das double Data rein - //cout << "Element: " << rowindex << " Variable: " << this->Variables[k] << " Value: " << this->Data[rowindex-1][k] << "\n"; + rowindex = rowindex + 1; // zaehlt die gesplitteten Zeilen in der Zeile, in + // Variante KB4 entspricht das 4 + this->Data[rowindex - 1][k] + = atof(Dataline[m].data()) * Multiplier; // schreibt die Zeile aus Dataline + // mit allen m und dem Keyword k in + // das double Data rein + // cout << "Element: " << rowindex << " Variable: " << this->Variables[k] << " + // Value: " << this->Data[rowindex-1][k] << "\n"; } } else { std::string delimiter = " "; SplittedString.clear(); - SplitStrings( - TextFile->Data[l], - delimiter); - //cout << TextFile->Daten[l] << "\n"; - for (unsigned int m = 0; - m < - SplittedString.size(); - m++) + SplitStrings(TextFile->Data[l], delimiter); + // cout << TextFile->Daten[l] << "\n"; + for (unsigned int m = 0; m < SplittedString.size(); m++) { - rowindex = - rowindex + - 1; - //cout << rowindex-1 << " " << k << " " << " " << this->eclgrid[rowindex-1]->x_barycentre << " " << this->eclgrid[rowindex-1]->y_barycentre << " " << this->eclgrid[rowindex-1]->z_barycentre << " " << atof(SplittedString[m].data()) << "\n"; - this->Data[rowindex - - 1][k] - = atof( - SplittedString - [m]. - data()) * - Multiplier; - //cout << "Element: " << rowindex << " Variable: " << this->Variables[k] << " Value: " << this->Data[rowindex-1][k] << "\n"; + rowindex = rowindex + 1; + // cout << rowindex-1 << " " << k << " " << " " << + // this->eclgrid[rowindex-1]->x_barycentre << " " << + // this->eclgrid[rowindex-1]->y_barycentre << " " << + // this->eclgrid[rowindex-1]->z_barycentre << " " << + // atof(SplittedString[m].data()) << "\n"; + this->Data[rowindex - 1][k] = atof(SplittedString[m].data()) * Multiplier; + // cout << "Element: " << rowindex << " Variable: " << this->Variables[k] << " + // Value: " << this->Data[rowindex-1][k] << "\n"; } } } j = j + temprows; - //a[k][1] = j + 1; + // a[k][1] = j + 1; } else { // there are inactive cells - //cout << "Error while reading the data file. The number of data points doesn't fit to the grid." << "\n"; + // cout << "Error while reading the data file. The number of data points doesn't fit to the + // grid." << "\n"; temprows = int(ceil(tempNumber / 4.0)); - //Read data for identified variable + // Read data for identified variable long rowindex = 0; - for (long l = j + 1; l < j + temprows + 1; - l++) + for (long l = j + 1; l < j + temprows + 1; l++) { - if ( l < (j + temprows)) + if (l < (j + temprows)) { - std::string Dataline[4]; // Definition einen strings mit 4 Arrays, Arrays immer in eckigen Klammern definieren - Dataline[0] = - TextFile->Data[l]. - substr(3, - 15); - Dataline[1] = - TextFile->Data[l]. - substr(20, - 15); - Dataline[2] = - TextFile->Data[l]. - substr(38, - 15); - Dataline[3] = - TextFile->Data[l]. - substr(55, - 15); - //string delimiter=" "; - //SplittedString.clear(); - //SplitStrings(TextFile->Daten[l], delimiter); - //cout << TextFile->Daten[l] << "\n"; - for (unsigned int m = 0; - m < 4; m++) + std::string Dataline[4]; // Definition einen strings mit 4 Arrays, Arrays immer in + // eckigen Klammern definieren + Dataline[0] = TextFile->Data[l].substr(3, 15); + Dataline[1] = TextFile->Data[l].substr(20, 15); + Dataline[2] = TextFile->Data[l].substr(38, 15); + Dataline[3] = TextFile->Data[l].substr(55, 15); + // string delimiter=" "; + // SplittedString.clear(); + // SplitStrings(TextFile->Daten[l], delimiter); + // cout << TextFile->Daten[l] << "\n"; + for (unsigned int m = 0; m < 4; m++) { - rowindex = - rowindex + - 1; - while (this-> - eclgrid[ - rowindex - - - 1]-> - active == - 0 && - rowindex < - this-> - elements) - rowindex = - rowindex - + 1; - if (rowindex < - this->elements) - this->Data[ - rowindex - - - 1][ - k] - = - atof( - Dataline - [ - m - ] - . - data()) - * - Multiplier; + rowindex = rowindex + 1; + while (this->eclgrid[rowindex - 1]->active == 0 && rowindex < this->elements) + rowindex = rowindex + 1; + if (rowindex < this->elements) + this->Data[rowindex - 1][k] = atof(Dataline[m].data()) * Multiplier; else - cout << - "1 data point couldn't be allocated to a grid point" - << - "\n"; + cout << "1 data point couldn't be allocated to a grid point" + << "\n"; } } else { std::string delimiter = " "; SplittedString.clear(); - SplitStrings( - TextFile->Data[l], - delimiter); - //cout << TextFile->Daten[l] << "\n"; - for (unsigned int m = 0; - m < - SplittedString.size(); - m++) + SplitStrings(TextFile->Data[l], delimiter); + // cout << TextFile->Daten[l] << "\n"; + for (unsigned int m = 0; m < SplittedString.size(); m++) { - rowindex = - rowindex + - 1; - //cout << rowindex-1 << " " << timestep << " " << k << " " << " " << this->eclgrid[rowindex-1]->x_barycentre << " " << this->eclgrid[rowindex-1]->y_barycentre << " " << this->eclgrid[rowindex-1]->z_barycentre << " " << atof(SplittedString[m].data()) << "\n"; - this->Data[rowindex - - 1][k] - = atof( - SplittedString - [m]. - data()) * - Multiplier; - // cout << "Element: " << rowindex << " Variable: " << this->Variables[k] << " Value: " << this->Data[rowindex-1][timestep][k] << "\n"; + rowindex = rowindex + 1; + // cout << rowindex-1 << " " << timestep << " " << k << " " << " " << + // this->eclgrid[rowindex-1]->x_barycentre << " " << + // this->eclgrid[rowindex-1]->y_barycentre << " " << + // this->eclgrid[rowindex-1]->z_barycentre << " " << + // atof(SplittedString[m].data()) << "\n"; + this->Data[rowindex - 1][k] = atof(SplittedString[m].data()) * Multiplier; + // cout << "Element: " << rowindex << " Variable: " << this->Variables[k] << " + // Value: " << this->Data[rowindex-1][timestep][k] << "\n"; } } } @@ -1663,7 +1549,7 @@ void CECLIPSEData::ReadEclipseData(std::string Filename, long Timestep) } // Release Textfile object - sb - //delete(TextFile->Daten); + // delete(TextFile->Daten); delete (TextFile); if (this->E100 == true) @@ -1690,7 +1576,7 @@ void CECLIPSEData::ReadEclipseData(std::string Filename, long Timestep) for (int i = 0; i < this->elements; i++) this->Data[i][index_aim] = this->Data[i][index_pressure]; } - //assumption: if water and oil -> pressure = oil pressure + // assumption: if water and oil -> pressure = oil pressure if (int(this->Phases.size()) == 2) { // water and oil @@ -1707,17 +1593,15 @@ void CECLIPSEData::ReadEclipseData(std::string Filename, long Timestep) for (int i = 0; i < this->elements; i++) { this->Data[i][index_pwat] = this->Data[i][index_pressure]; - this->Data[i][index_poil] = this->Data[i][index_pwat] + - this->Data[i][index_pcap]; + this->Data[i][index_poil] = this->Data[i][index_pwat] + this->Data[i][index_pcap]; } } if ((this->Phases[0] == "WATER") && (this->Phases[1] == "GAS")) { cout << "\n"; - cout << - "GAS-WATER System can not be considered with ECLIPSE E100 and GeoSys" + cout << "GAS-WATER System can not be considered with ECLIPSE E100 and GeoSys" << "\n"; - //system("Pause"); + // system("Pause"); exit(0); } if ((this->Phases[0] == "OIL") && (this->Phases[1] == "GAS")) @@ -1733,24 +1617,21 @@ void CECLIPSEData::ReadEclipseData(std::string Filename, long Timestep) for (int i = 0; i < this->elements; i++) { this->Data[i][index_poil] = this->Data[i][index_pressure]; - this->Data[i][index_pgas] = this->Data[i][index_poil] + - this->Data[i][index_pcap]; + this->Data[i][index_pgas] = this->Data[i][index_poil] + this->Data[i][index_pcap]; } } } if (int(this->Phases.size()) == 3) { cout << "\n"; - cout << - "Currently not more than 2 phases are considered for reading eclipse pressure" + cout << "Currently not more than 2 phases are considered for reading eclipse pressure" << "\n"; - cout << - "Three phases are only valid if a water saturation exists only at the boundaries of the model domain!!"; - //system("Pause"); - //exit(0); + cout << "Three phases are only valid if a water saturation exists only at the boundaries of the model " + "domain!!"; + // system("Pause"); + // exit(0); - int index_pwat, index_poil, index_pgas, index_pressure, - index_pcap_oil_water, index_pcap_oil_gas; + int index_pwat, index_poil, index_pgas, index_pressure, index_pcap_oil_water, index_pcap_oil_gas; index_pwat = this->GetVariableIndex("PWAT"); index_poil = this->GetVariableIndex("POIL"); index_pgas = this->GetVariableIndex("PGAS"); @@ -1762,10 +1643,8 @@ void CECLIPSEData::ReadEclipseData(std::string Filename, long Timestep) for (int i = 0; i < this->elements; i++) { this->Data[i][index_pwat] = this->Data[i][index_pressure]; - this->Data[i][index_poil] = this->Data[i][index_pwat] + - this->Data[i][index_pcap_oil_water]; - this->Data[i][index_pgas] = this->Data[i][index_poil] + - this->Data[i][index_pcap_oil_gas]; + this->Data[i][index_poil] = this->Data[i][index_pwat] + this->Data[i][index_pcap_oil_water]; + this->Data[i][index_pgas] = this->Data[i][index_poil] + this->Data[i][index_pcap_oil_gas]; } } @@ -1839,38 +1718,37 @@ void CECLIPSEData::ReadEclipseData(std::string Filename, long Timestep) } // Calculating the phase saturation for (int i = 0; i < this->elements; i++) - this->Data[i][index_aim] = 1 - this->Data[i][index_source1] - - this->Data[i][index_source2]; - //cout << "Element: " << i << " RS: " << this->Data[i][this->GetVariableIndex("RS")] << " SWAT: " << this->Data[i][index_swat]; - //cout << " SOIL: " << this->Data[i][index_soil] << " SGAS: " << this->Data[i][index_sgas] << "\n"; + this->Data[i][index_aim] = 1 - this->Data[i][index_source1] - this->Data[i][index_source2]; + // cout << "Element: " << i << " RS: " << this->Data[i][this->GetVariableIndex("RS")] << " SWAT: " << + // this->Data[i][index_swat]; + // cout << " SOIL: " << this->Data[i][index_soil] << " SGAS: " << this->Data[i][index_sgas] << "\n"; } if (this->Phases.size() > 3) { - cout << - "Currently not more than 3 phases are considered for reading eclipse data" + cout << "Currently not more than 3 phases are considered for reading eclipse data" << "\n"; - //system("Pause"); + // system("Pause"); exit(0); } } //-------------------------------------------------------------------------------------------- // output of vertical flow data - //for (unsigned long i = 0; i < this->elements; i++) { + // for (unsigned long i = 0; i < this->elements; i++) { // cout << "Q(k) " << this->Data[i][0][2] << "\n"; //} - //cout << "Fertig"; + // cout << "Fertig"; - //Test output - //vector vec_string; - //ostringstream temp; - //tempstring = "Element; X; Y; Z"; - //for (unsigned int k = 0; k < this->Variables.size(); k++) { + // Test output + // vector vec_string; + // ostringstream temp; + // tempstring = "Element; X; Y; Z"; + // for (unsigned int k = 0; k < this->Variables.size(); k++) { // tempstring = tempstring + "; " + this->Variables[k]; //} - //vec_string.push_back(tempstring); + // vec_string.push_back(tempstring); // Loop over all elements - //for (long i = 0; i < this->elements; i++){ + // for (long i = 0; i < this->elements; i++){ // CECLIPSEBlock *elem = this->eclgrid[i]; // temp.str(""); temp.clear(); temp << i; tempstring = temp.str(); // temp.str(""); temp.clear(); temp << elem->x_barycentre; tempstring += "; " + temp.str(); @@ -1886,23 +1764,24 @@ void CECLIPSEData::ReadEclipseData(std::string Filename, long Timestep) // vec_string.push_back(tempstring); //} // end element loop - //Test Output - //int position = Filename.find_last_of("\\"); - //string path = Filename.substr(0,position); - //position = path.find_last_of("\\"); - //path = path.substr(0,position); + // Test Output + // int position = Filename.find_last_of("\\"); + // string path = Filename.substr(0,position); + // position = path.find_last_of("\\"); + // path = path.substr(0,position); // //temp.str(""); temp.clear(); temp << timestep; tempstring = temp.str(); - //string aus_file = path + "\\CheckDataRedIn_0.csv"; - //ofstream aus; - //aus.open(aus_file.data(),ios::out); - //for (unsigned int i = 0; i < vec_string.size(); i++) { + // string aus_file = path + "\\CheckDataRedIn_0.csv"; + // ofstream aus; + // aus.open(aus_file.data(),ios::out); + // for (unsigned int i = 0; i < vec_string.size(); i++) { // aus << vec_string[i] << "\n"; //} - //aus.close(); + // aus.close(); finish = clock(); time = (double(finish) - double(start)) / CLOCKS_PER_SEC; - cout << " Time: " << time << " seconds." << "\n"; + cout << " Time: " << time << " seconds." + << "\n"; } /*------------------------------------------------------------------------- @@ -1914,13 +1793,13 @@ void CECLIPSEData::ReadEclipseData(std::string Filename, long Timestep) -------------------------------------------------------------------------*/ void CECLIPSEData::CalculateRSfromMassFraction_E300() { - //CElem* m_ele = NULL; - //CFEMesh* m_msh = fem_msh_vector[0]; - clock_t start,finish; + // CElem* m_ele = NULL; + // CFEMesh* m_msh = fem_msh_vector[0]; + clock_t start, finish; double time; double xw_CO2_liquid; double RS; - //WW int index_xw_CO2_liquid; + // WW int index_xw_CO2_liquid; int index_density_liquid; double rho_liquid; @@ -1928,15 +1807,15 @@ void CECLIPSEData::CalculateRSfromMassFraction_E300() cout << " CalculatePhaseFlux() "; - //WW index_xw_CO2_liquid = this->GetVariableIndex("XMF2"); + // WW index_xw_CO2_liquid = this->GetVariableIndex("XMF2"); index_density_liquid = this->GetVariableIndex("DENW"); if ((index_density_liquid < 0)) { - cout << - "Not all variables are existing in the eclipse output files that are necessary to write data back to e300!" + cout << "Not all variables are existing in the eclipse output files that are necessary to write data back to " + "e300!" << "\n"; - //system("Pause"); + // system("Pause"); exit(0); } @@ -1948,7 +1827,8 @@ void CECLIPSEData::CalculateRSfromMassFraction_E300() // porosity rho_liquid = this->Data[i][this->GetVariableIndex("DENW")]; // calculate pseudo RS value from the mass fraction of each component on the liquid phase - //RS [m�_CO2 / m�_liquid] = (V_liquid * rho_liquid * xw_CO2_liquid) / (rho_CO2_surface * V_liquid) = rho_liquid [kg_liq / m�_liq] * xw_CO2_liquid [kg_CO2 / kg_liq] / rho_CO2_surface [kg_CO2 / m�_CO2] + // RS [m�_CO2 / m�_liquid] = (V_liquid * rho_liquid * xw_CO2_liquid) / (rho_CO2_surface * V_liquid) = rho_liquid + // [kg_liq / m�_liq] * xw_CO2_liquid [kg_CO2 / kg_liq] / rho_CO2_surface [kg_CO2 / m�_CO2] RS = rho_liquid * xw_CO2_liquid / this->SurfaceCO2Density; // store RS in E100 variables @@ -1956,7 +1836,8 @@ void CECLIPSEData::CalculateRSfromMassFraction_E300() } finish = clock(); time = (double(finish) - double(start)) / CLOCKS_PER_SEC; - cout << " Time: " << time << " seconds." << "\n"; + cout << " Time: " << time << " seconds." + << "\n"; } /*------------------------------------------------------------------------- @@ -1966,64 +1847,63 @@ void CECLIPSEData::CalculateRSfromMassFraction_E300() Programming: 09/2009 BG Modification: -------------------------------------------------------------------------*/ -bool CECLIPSEData::ReplaceASectionInFile(std::string Filename, - string Keyword, - vector Data, +bool CECLIPSEData::ReplaceASectionInFile(std::string Filename, string Keyword, vector Data, bool CheckLengthOfSection) { CReadTextfiles_ECL* TextFile; std::string tempstring; bool success = false; - //Reads the text file (usually 60 bytes in one row of the eclipse output + // Reads the text file (usually 60 bytes in one row of the eclipse output bool Error; TextFile = new CReadTextfiles_ECL; Error = TextFile->Read_Text(Filename); if (Error == true) { - cout << "The program is canceled" << "\n"; - //system("Pause"); + cout << "The program is canceled" + << "\n"; + // system("Pause"); exit(0); } - //scan file for the keyword and replace the following data + // scan file for the keyword and replace the following data for (long i = 0; i < TextFile->NumberOfRows; i++) if (TextFile->Data[i].substr(0, Keyword.length()) == Keyword) { - //count data rows in the file and compare it to the rows in the new Data array, if equal than replace data - //count data rows in the file and compare it to the rows in the new Data array, if equal than replace data + // count data rows in the file and compare it to the rows in the new Data array, if equal than replace data + // count data rows in the file and compare it to the rows in the new Data array, if equal than replace data success = true; long zeilen = 0; if (CheckLengthOfSection == true) { - do { + do + { zeilen = zeilen + 1; - } - while (TextFile->Data[i + zeilen].length() > 1); + } while (TextFile->Data[i + zeilen].length() > 1); zeilen = zeilen - 1; } else zeilen = long(Data.size()); if (zeilen == long(Data.size())) - //Replace Data in TextFile variable + // Replace Data in TextFile variable for (long j = 0; j < zeilen; j++) TextFile->Data[i + 1 + j] = Data[j]; else { - cout << - "Replacing a Section in the Eclipse input file is not possible because the section length doesn't fit!" + cout << "Replacing a Section in the Eclipse input file is not possible because the section length " + "doesn't fit!" << "\n"; success = false; return success; } } - //Rewrite the file + // Rewrite the file CWriteTextfiles_ECL* OutputFile; OutputFile = new CWriteTextfiles_ECL; OutputFile->Write_Text(Filename, TextFile->Data); - //Release memory + // Release memory delete (TextFile); return success; @@ -2035,7 +1915,8 @@ bool CECLIPSEData::ReplaceASectionInFile(std::string Filename, Programming: 05/2011 CB Modification: re-added 03/2013 wtp -------------------------------------------------------------------------*/ -bool CECLIPSEData::WriteIncludeFile(std::string Filename, std::string Keyword, vector Data, bool append) { +bool CECLIPSEData::WriteIncludeFile(std::string Filename, std::string Keyword, vector Data, bool append) +{ bool success = true; ofstream aus; @@ -2045,14 +1926,15 @@ bool CECLIPSEData::WriteIncludeFile(std::string Filename, std::string Keyword, v aus.open(Filename.c_str()); aus << Keyword << "\n"; -// for (long i = 0; i < Data.size(); i++) { - for (std::size_t i = 0; i < Data.size(); i++) { // WTP + // for (long i = 0; i < Data.size(); i++) { + for (std::size_t i = 0; i < Data.size(); i++) + { // WTP aus << Data[i] << "\n"; } - aus << "/" << "\n"; + aus << "/" + << "\n"; aus.close(); return success; - }; /*------------------------------------------------------------------------- GeoSys - Function: ReplaceWellRate @@ -2067,35 +1949,36 @@ bool CECLIPSEData::ReplaceWellRate(std::string Filename, std::string Keyword_wel std::string tempstring; bool success = false; stringstream in; - std::string dummy_rate,dummy_zeile,rest_zeile, name, phase, open_flag, control_mode; + std::string dummy_rate, dummy_zeile, rest_zeile, name, phase, open_flag, control_mode; int jj = 0; - //Reads the text file (usually 60 bytes in one row of the eclipse output + // Reads the text file (usually 60 bytes in one row of the eclipse output bool Error; TextFile = new CReadTextfiles_ECL; Error = TextFile->Read_Text(Filename); if (Error == true) { - cout << "The program is canceled" << "\n"; - //system("Pause"); + cout << "The program is canceled" + << "\n"; + // system("Pause"); exit(0); } - //scan file for the keyword and replace the following data + // scan file for the keyword and replace the following data for (long i = 0; i < TextFile->NumberOfRows; i++) if (TextFile->Data[i].substr(0, Keyword_well.length()) == Keyword_well) { - //count data rows in the file and compare it to the rows in the new Data array, if equal than replace data + // count data rows in the file and compare it to the rows in the new Data array, if equal than replace data success = true; long zeilen = 0; - do { + do + { zeilen = zeilen + 1; - } - while (TextFile->Data[i + zeilen] != ""); // look for possible empty rows between the Keyword and the items + } while (TextFile->Data[i + zeilen] + != ""); // look for possible empty rows between the Keyword and the items jj = 0; - for(long unsigned j = i + zeilen + 1; - j < (i + this->ecl_well.size() + zeilen + 1); j++) + for (long unsigned j = i + zeilen + 1; j < (i + this->ecl_well.size() + zeilen + 1); j++) { if (this->actual_time == 0) { @@ -2112,37 +1995,29 @@ bool CECLIPSEData::ReplaceWellRate(std::string Filename, std::string Keyword_wel in.clear(); - std::string outline = this->ecl_well[jj]->name + " " + - this->ecl_well[jj]->phase + " " + - this->ecl_well[jj]->open_flag + - " " + - this->ecl_well[jj]->control_mode + - " " + - this->WellRates[jj] + " " + " / "; + std::string outline = this->ecl_well[jj]->name + " " + this->ecl_well[jj]->phase + " " + + this->ecl_well[jj]->open_flag + " " + this->ecl_well[jj]->control_mode + + " " + this->WellRates[jj] + " " + " / "; TextFile->Data[j] = outline; jj++; } else { - std::string outline = this->ecl_well[jj]->name + " " + - this->ecl_well[jj]->phase + " " + - this->ecl_well[jj]->open_flag + - " " + - this->ecl_well[jj]->control_mode + - " " + - this->WellRates[jj] + " " + " / "; + std::string outline = this->ecl_well[jj]->name + " " + this->ecl_well[jj]->phase + " " + + this->ecl_well[jj]->open_flag + " " + this->ecl_well[jj]->control_mode + + " " + this->WellRates[jj] + " " + " / "; TextFile->Data[j] = outline; jj++; } } } - //Rewrite the file + // Rewrite the file CWriteTextfiles_ECL* OutputFile; OutputFile = new CWriteTextfiles_ECL; OutputFile->Write_Text(Filename, TextFile->Data); - //Release memory + // Release memory delete (TextFile); return success; @@ -2160,15 +2035,15 @@ bool CECLIPSEData::CorrespondingElements() MeshLib::CElem* m_ele = NULL; CFEMesh* m_msh = fem_msh_vector[0]; - //check if number of elements is equal + // check if number of elements is equal if (long(m_msh->ele_vector.size()) != this->elements) { - cout << "Error: The number of elements between Geosys and Eclipse is not equal!" << - "\n"; + cout << "Error: The number of elements between Geosys and Eclipse is not equal!" + << "\n"; return false; } - //set element vectors to the start value -1 + // set element vectors to the start value -1 CorrespondingEclipseElement.resize(m_msh->ele_vector.size()); for (unsigned long i = 0; i < m_msh->ele_vector.size(); i++) CorrespondingEclipseElement[i] = -1; @@ -2181,170 +2056,168 @@ bool CECLIPSEData::CorrespondingElements() { m_ele = m_msh->ele_vector[i]; double const* grav_c(m_ele->GetGravityCenter()); - //check if coordinates of the gravity centre are equal - if ((grav_c[0] == this->eclgrid[j]->x_barycentre) && - (grav_c[1] == this->eclgrid[j]->y_barycentre) && - (grav_c[2] == -this->eclgrid[j]->z_barycentre)) + // check if coordinates of the gravity centre are equal + if ((grav_c[0] == this->eclgrid[j]->x_barycentre) && (grav_c[1] == this->eclgrid[j]->y_barycentre) + && (grav_c[2] == -this->eclgrid[j]->z_barycentre)) { CorrespondingEclipseElement[i] = j; CorrespondingGeosysElement[j] = i; } } - //check if all values in the correspondingElementVector are larger than -1 + // check if all values in the correspondingElementVector are larger than -1 for (unsigned long i = 0; i < m_msh->ele_vector.size(); i++) { - cout << " CorrespondingEclipseElement[" << i << "] " << - CorrespondingEclipseElement[i] << "\n"; + cout << " CorrespondingEclipseElement[" << i << "] " << CorrespondingEclipseElement[i] << "\n"; if (CorrespondingEclipseElement[i] < 0) { - cout << "Error: No Eclipse element linked to the Geosys element!" << "\n"; + cout << "Error: No Eclipse element linked to the Geosys element!" + << "\n"; return 0; } } for (long j = 0; j < this->elements; j++) if (CorrespondingGeosysElement[j] < 0) { - cout << "Error: No Geosys element linked to the Eclipse element!" << "\n"; + cout << "Error: No Geosys element linked to the Eclipse element!" + << "\n"; return 0; } return 1; } - /*------------------------------------------------------------------------- - GeoSys - Function: CompareElementsGeosysEclipse - Task: Re-worked function of CompareElementsGeosysEclipse by SB - Return: bool value if there occured an error - Programming: 09/2012 SB - Modification: re-added 03/2013 wtp - -------------------------------------------------------------------------*/ +/*------------------------------------------------------------------------- +GeoSys - Function: CompareElementsGeosysEclipse +Task: Re-worked function of CompareElementsGeosysEclipse by SB +Return: bool value if there occured an error +Programming: 09/2012 SB +Modification: re-added 03/2013 wtp +-------------------------------------------------------------------------*/ bool CECLIPSEData::CompareElementsGeosysEclipse() { MeshLib::CElem* m_ele = NULL; CFEMesh* m_msh = fem_msh_vector[0]; - //Math_Group::vec ele_nodes(8); - //std::vector ele_nodes; - MeshLib::CNode * m_cnode; - clock_t start,finish; + // Math_Group::vec ele_nodes(8); + // std::vector ele_nodes; + MeshLib::CNode* m_cnode; + clock_t start, finish; double time; double epsilon = 1e-7; - const double * pnt; + const double* pnt; // const double * gc; start = clock(); - cout << " CompareElements() "; - //check if number of elements is equal + // check if number of elements is equal if (long(m_msh->ele_vector.size()) != this->elements) { - cout << "Error: The number of elements between Geosys and Eclipse is not equal!" << - "\n"; + cout << "Error: The number of elements between Geosys and Eclipse is not equal!" + << "\n"; return false; } for (unsigned long i = 0; i < m_msh->ele_vector.size(); i++) { - m_ele = m_msh->ele_vector[i]; - //m_ele->GetNodes(ele_nodes); + // m_ele->GetNodes(ele_nodes); bool ElementIsEqual = true; // Test output - //for(int j=0;j<8;j++){ + // for(int j=0;j<8;j++){ // a_node = ele_nodes[j]; // cout << "\n"; - // cout << a_node->X() << " " << a_node->Y() << " " << a_node->Z() << " ECL " << this->eclgrid[i]->x_coordinates[j] << " " << this->eclgrid[i]->y_coordinates[j] << " " << this->eclgrid[i]->z_coordinates[j] << "\n"; + // cout << a_node->X() << " " << a_node->Y() << " " << a_node->Z() << " ECL " << + // this->eclgrid[i]->x_coordinates[j] << " " << this->eclgrid[i]->y_coordinates[j] << " " << + // this->eclgrid[i]->z_coordinates[j] << "\n"; //} - //A loop can't be used because the order of nodes is not equal + // A loop can't be used because the order of nodes is not equal - //double const* pnt (ele_nodes[0]->getData()); + // double const* pnt (ele_nodes[0]->getData()); m_cnode = m_ele->GetNode(0); - pnt = m_cnode->getData(); + pnt = m_cnode->getData(); - if (fabs(pnt[0] - this->eclgrid[i]->x_coordinates[0]) > epsilon || - fabs(pnt[1] - this->eclgrid[i]->y_coordinates[0]) > epsilon || - fabs(pnt[2] - -this->eclgrid[i]->z_coordinates[0]) > epsilon) + if (fabs(pnt[0] - this->eclgrid[i]->x_coordinates[0]) > epsilon + || fabs(pnt[1] - this->eclgrid[i]->y_coordinates[0]) > epsilon + || fabs(pnt[2] - -this->eclgrid[i]->z_coordinates[0]) > epsilon) ElementIsEqual = false; - //pnt = ele_nodes[1]->getData(); + // pnt = ele_nodes[1]->getData(); m_cnode = m_ele->GetNode(1); - pnt = m_cnode->getData(); + pnt = m_cnode->getData(); - if (fabs(pnt[0] - this->eclgrid[i]->x_coordinates[1]) > epsilon || - fabs(pnt[1] - this->eclgrid[i]->y_coordinates[1]) > epsilon || - fabs(pnt[2] - -this->eclgrid[i]->z_coordinates[1]) > epsilon) + if (fabs(pnt[0] - this->eclgrid[i]->x_coordinates[1]) > epsilon + || fabs(pnt[1] - this->eclgrid[i]->y_coordinates[1]) > epsilon + || fabs(pnt[2] - -this->eclgrid[i]->z_coordinates[1]) > epsilon) ElementIsEqual = false; - //pnt = ele_nodes[2]->getData(); + // pnt = ele_nodes[2]->getData(); m_cnode = m_ele->GetNode(2); - pnt = m_cnode->getData(); - if (fabs(pnt[0] - this->eclgrid[i]->x_coordinates[3]) > epsilon || - fabs(pnt[1] - this->eclgrid[i]->y_coordinates[3]) > epsilon || - fabs(pnt[2] - -this->eclgrid[i]->z_coordinates[3]) > epsilon) + pnt = m_cnode->getData(); + if (fabs(pnt[0] - this->eclgrid[i]->x_coordinates[3]) > epsilon + || fabs(pnt[1] - this->eclgrid[i]->y_coordinates[3]) > epsilon + || fabs(pnt[2] - -this->eclgrid[i]->z_coordinates[3]) > epsilon) ElementIsEqual = false; - //pnt = ele_nodes[3]->getData(); + // pnt = ele_nodes[3]->getData(); m_cnode = m_ele->GetNode(3); - pnt = m_cnode->getData(); - if (fabs(pnt[0] - this->eclgrid[i]->x_coordinates[2]) > epsilon || - fabs(pnt[1] - this->eclgrid[i]->y_coordinates[2]) > epsilon || - fabs(pnt[2] - -this->eclgrid[i]->z_coordinates[2]) > epsilon) + pnt = m_cnode->getData(); + if (fabs(pnt[0] - this->eclgrid[i]->x_coordinates[2]) > epsilon + || fabs(pnt[1] - this->eclgrid[i]->y_coordinates[2]) > epsilon + || fabs(pnt[2] - -this->eclgrid[i]->z_coordinates[2]) > epsilon) ElementIsEqual = false; - //pnt = ele_nodes[4]->getData(); + // pnt = ele_nodes[4]->getData(); m_cnode = m_ele->GetNode(4); - pnt = m_cnode->getData(); - if (fabs(pnt[0] - this->eclgrid[i]->x_coordinates[4]) > epsilon || - fabs(pnt[1] - this->eclgrid[i]->y_coordinates[4]) > epsilon || - fabs(pnt[2] - -this->eclgrid[i]->z_coordinates[4]) > epsilon) + pnt = m_cnode->getData(); + if (fabs(pnt[0] - this->eclgrid[i]->x_coordinates[4]) > epsilon + || fabs(pnt[1] - this->eclgrid[i]->y_coordinates[4]) > epsilon + || fabs(pnt[2] - -this->eclgrid[i]->z_coordinates[4]) > epsilon) ElementIsEqual = false; - //pnt = ele_nodes[5]->getData(); + // pnt = ele_nodes[5]->getData(); m_cnode = m_ele->GetNode(5); - pnt = m_cnode->getData(); - if (fabs(pnt[0] - this->eclgrid[i]->x_coordinates[5]) > epsilon || - fabs(pnt[1] - this->eclgrid[i]->y_coordinates[5]) > epsilon || - fabs(pnt[2] - -this->eclgrid[i]->z_coordinates[5]) > epsilon) + pnt = m_cnode->getData(); + if (fabs(pnt[0] - this->eclgrid[i]->x_coordinates[5]) > epsilon + || fabs(pnt[1] - this->eclgrid[i]->y_coordinates[5]) > epsilon + || fabs(pnt[2] - -this->eclgrid[i]->z_coordinates[5]) > epsilon) ElementIsEqual = false; - //pnt = ele_nodes[6]->getData(); + // pnt = ele_nodes[6]->getData(); m_cnode = m_ele->GetNode(6); - pnt = m_cnode->getData(); - if (fabs(pnt[0] - this->eclgrid[i]->x_coordinates[7]) > epsilon || - fabs(pnt[1] - this->eclgrid[i]->y_coordinates[7]) > epsilon || - fabs(pnt[2] - -this->eclgrid[i]->z_coordinates[7]) > epsilon) + pnt = m_cnode->getData(); + if (fabs(pnt[0] - this->eclgrid[i]->x_coordinates[7]) > epsilon + || fabs(pnt[1] - this->eclgrid[i]->y_coordinates[7]) > epsilon + || fabs(pnt[2] - -this->eclgrid[i]->z_coordinates[7]) > epsilon) ElementIsEqual = false; - //pnt = ele_nodes[7]->getData(); + // pnt = ele_nodes[7]->getData(); m_cnode = m_ele->GetNode(7); - pnt = m_cnode->getData(); - if (fabs(pnt[0] - this->eclgrid[i]->x_coordinates[6]) > epsilon || - fabs(pnt[1] - this->eclgrid[i]->y_coordinates[6]) > epsilon || - fabs(pnt[2] - -this->eclgrid[i]->z_coordinates[6]) > epsilon) + pnt = m_cnode->getData(); + if (fabs(pnt[0] - this->eclgrid[i]->x_coordinates[6]) > epsilon + || fabs(pnt[1] - this->eclgrid[i]->y_coordinates[6]) > epsilon + || fabs(pnt[2] - -this->eclgrid[i]->z_coordinates[6]) > epsilon) ElementIsEqual = false; if (ElementIsEqual == false) return 0; - - //Get the gravity centre of the element from geosys + // Get the gravity centre of the element from geosys double const* gc(m_ele->GetGravityCenter()); - //gc = m_ele->GetGravityCenter(); + // gc = m_ele->GetGravityCenter(); this->eclgrid[i]->x_barycentre = gc[0]; this->eclgrid[i]->y_barycentre = gc[1]; this->eclgrid[i]->z_barycentre = gc[2]; this->eclgrid[i]->volume = m_ele->GetVolume(); - } finish = clock(); time = (double(finish) - double(start)) / CLOCKS_PER_SEC; - cout << " Time: " << time << " seconds." << "\n"; + cout << " Time: " << time << " seconds." + << "\n"; return 1; } - /*------------------------------------------------------------------------- GeoSys - Function: CreateFaces Task: Re-worked function of CreateFaces by SB @@ -2357,33 +2230,34 @@ bool CECLIPSEData::CreateFaces(void) { CFaces* m_face = NULL; MeshLib::CElem* m_element = NULL; - vector element_indices; + vector element_indices; CFEMesh* m_msh = fem_msh_vector[0]; - //Math_Group::vec element_nodes(8); - MeshLib::CNode* Node0=NULL; - MeshLib::CNode* Node1=NULL; - MeshLib::CNode* Node2=NULL; - MeshLib::CNode* Node3=NULL; - MeshLib::CNode* Node4=NULL; - MeshLib::CNode* Node5=NULL; - MeshLib::CNode* Node6=NULL; - MeshLib::CNode* Node7=NULL; - vector vec_face_nodes; - clock_t start,finish; + // Math_Group::vec element_nodes(8); + MeshLib::CNode* Node0 = NULL; + MeshLib::CNode* Node1 = NULL; + MeshLib::CNode* Node2 = NULL; + MeshLib::CNode* Node3 = NULL; + MeshLib::CNode* Node4 = NULL; + MeshLib::CNode* Node5 = NULL; + MeshLib::CNode* Node6 = NULL; + MeshLib::CNode* Node7 = NULL; + vector vec_face_nodes; + clock_t start, finish; double time; start = clock(); - //order of nodes for each element in geosys: 0..x1,y1,zoben; 1..x2,y1,zoben; 2..x2,y2,zoben; 3..x1,y2,zoben; - //4..x1,y1,zu; 5..x2,y1,zu; 6..x2,y2,zu; 7..x1,y2,zu + // order of nodes for each element in geosys: 0..x1,y1,zoben; 1..x2,y1,zoben; 2..x2,y2,zoben; 3..x1,y2,zoben; + // 4..x1,y1,zu; 5..x2,y1,zu; 6..x2,y2,zu; 7..x1,y2,zu - // in case of radial models i+...direction of radius, j+...direction of theta -> the faces are build with the same points as for rectangular models, but its not necessarily the same direction + // in case of radial models i+...direction of radius, j+...direction of theta -> the faces are build with the same + // points as for rectangular models, but its not necessarily the same direction cout << " CreateFaces() "; for (unsigned long i = 0; i < m_msh->ele_vector.size(); i++) { m_element = m_msh->ele_vector[i]; - //m_element->GetNodes(element_nodes); + // m_element->GetNodes(element_nodes); Node0 = m_element->GetNode(0); Node1 = m_element->GetNode(1); Node2 = m_element->GetNode(2); @@ -2393,396 +2267,372 @@ bool CECLIPSEData::CreateFaces(void) Node6 = m_element->GetNode(6); Node7 = m_element->GetNode(7); - //Test output - //double *tmp_coord; - //for (int j = 0; j < 8; j++) { + // Test output + // double *tmp_coord; + // for (int j = 0; j < 8; j++) { // tmp_coord = element_nodes[j]->GetCoordinates(); // cout << "Punkt " << j << " " << tmp_coord[0] << " " << tmp_coord[1] << " " << tmp_coord[2] << "\n"; //} - //if ((i == 608) || (i == 645)) + // if ((i == 608) || (i == 645)) // cout << i << "\n"; - //non-radial elements: Right face of the Element (i-direction) (Nodes: 1,5,2,6) -> with this order of the nodes the normal vector shows automatically to the positve i-direction - //radial elements: Right face of the Element (i-direction) (Nodes: 6,5,2,1) -> with this order of the nodes the normal vector shows automatically to the positve i-direction + // non-radial elements: Right face of the Element (i-direction) (Nodes: 1,5,2,6) -> with this order of the nodes + // the normal vector shows automatically to the positve i-direction + // radial elements: Right face of the Element (i-direction) (Nodes: 6,5,2,1) -> with this order of the nodes the + // normal vector shows automatically to the positve i-direction m_face = new CFaces(int(this->Phases.size())); m_face->index = long(faces.size()); m_face->model_axis = "I+"; - //store all nodes of the face in a vector + // store all nodes of the face in a vector vec_face_nodes.clear(); if (Radialmodell == false) { - //vec_face_nodes.push_back(element_nodes[1]); + // vec_face_nodes.push_back(element_nodes[1]); vec_face_nodes.push_back(Node1); - //vec_face_nodes.push_back(element_nodes[5]); + // vec_face_nodes.push_back(element_nodes[5]); vec_face_nodes.push_back(Node5); - //vec_face_nodes.push_back(element_nodes[2]); + // vec_face_nodes.push_back(element_nodes[2]); vec_face_nodes.push_back(Node2); - //vec_face_nodes.push_back(element_nodes[6]); + // vec_face_nodes.push_back(element_nodes[6]); vec_face_nodes.push_back(Node6); } - if (this->RadialModellIpos == true ) + if (this->RadialModellIpos == true) { - //vec_face_nodes.push_back(element_nodes[6]); + // vec_face_nodes.push_back(element_nodes[6]); vec_face_nodes.push_back(Node6); - //vec_face_nodes.push_back(element_nodes[5]); + // vec_face_nodes.push_back(element_nodes[5]); vec_face_nodes.push_back(Node5); - //vec_face_nodes.push_back(element_nodes[2]); + // vec_face_nodes.push_back(element_nodes[2]); vec_face_nodes.push_back(Node2); - //vec_face_nodes.push_back(element_nodes[1]); + // vec_face_nodes.push_back(element_nodes[1]); vec_face_nodes.push_back(Node1); } - //create the face - if (m_face->CreateFace(vec_face_nodes[0], vec_face_nodes[1], vec_face_nodes[2], - vec_face_nodes[3]) == false) + // create the face + if (m_face->CreateFace(vec_face_nodes[0], vec_face_nodes[1], vec_face_nodes[2], vec_face_nodes[3]) == false) { - cout << "Error at creating face: The given points form not a plane!" << - "\n"; - //system("Pause"); + cout << "Error at creating face: The given points form not a plane!" + << "\n"; + // system("Pause"); return false; } - //add connected elements to the face (first the left (x) element, second the right element) + // add connected elements to the face (first the left (x) element, second the right element) element_indices.clear(); element_indices.push_back(i); if (this->eclgrid[i]->NeighbourElement[1] > -1) element_indices.push_back(this->eclgrid[i]->NeighbourElement[1]); m_face->SetElements(element_indices); - //add the face to the vector + // add the face to the vector faces.push_back(m_face); for (unsigned long j = 0; j < vec_face_nodes.size(); j++) { - //Connect nodes with faces - m_msh->nod_vector[vec_face_nodes[j]->GetIndex()]->connected_faces.push_back( - m_face->index); - //Calculate distance between node and gravity centre of the face and store it in a vector - //m_msh->nod_vector[vec_face_nodes[j]->GetIndex()]->distance_to_connected_faces.push_back(this->CalculateDistanceBetween2Points(vec_face_nodes[j]->getData(), m_face->GetFaceGravityCentre())); - m_msh->nod_vector[vec_face_nodes[j]->GetIndex()]-> - distance_to_connected_faces.push_back(sqrt(MathLib::sqrDist(vec_face_nodes[ - j - ]->getData(), - m_face-> - GetFaceGravityCentre()))); - } - - //non-radial elements: Upper face of the Element (j-direction) (Nodes: 3,2,7,6) -> with this order of the nodes the normal vector shows automatically to the positve j-direction - //radial elements: Upper face of the Element (j-direction) (Nodes: 6,2,7,3) -> with this order of the nodes the normal vector shows automatically to the positve j-direction + // Connect nodes with faces + m_msh->nod_vector[vec_face_nodes[j]->GetIndex()]->connected_faces.push_back(m_face->index); + // Calculate distance between node and gravity centre of the face and store it in a vector + // m_msh->nod_vector[vec_face_nodes[j]->GetIndex()]->distance_to_connected_faces.push_back(this->CalculateDistanceBetween2Points(vec_face_nodes[j]->getData(), + // m_face->GetFaceGravityCentre())); + m_msh->nod_vector[vec_face_nodes[j]->GetIndex()]->distance_to_connected_faces.push_back( + sqrt(MathLib::sqrDist(vec_face_nodes[j]->getData(), m_face->GetFaceGravityCentre()))); + } + + // non-radial elements: Upper face of the Element (j-direction) (Nodes: 3,2,7,6) -> with this order of the nodes + // the normal vector shows automatically to the positve j-direction + // radial elements: Upper face of the Element (j-direction) (Nodes: 6,2,7,3) -> with this order of the nodes the + // normal vector shows automatically to the positve j-direction m_face = new CFaces(int(this->Phases.size())); m_face->index = long(faces.size()); m_face->model_axis = "J+"; - //store all nodes of the face in a vector + // store all nodes of the face in a vector vec_face_nodes.clear(); if (Radialmodell == false) { - //vec_face_nodes.push_back(element_nodes[3]); + // vec_face_nodes.push_back(element_nodes[3]); vec_face_nodes.push_back(Node3); - //vec_face_nodes.push_back(element_nodes[2]); + // vec_face_nodes.push_back(element_nodes[2]); vec_face_nodes.push_back(Node2); - //vec_face_nodes.push_back(element_nodes[7]); + // vec_face_nodes.push_back(element_nodes[7]); vec_face_nodes.push_back(Node7); - //vec_face_nodes.push_back(element_nodes[6]); + // vec_face_nodes.push_back(element_nodes[6]); vec_face_nodes.push_back(Node6); } - if (this->RadialModellIpos == true ) + if (this->RadialModellIpos == true) { - //vec_face_nodes.push_back(element_nodes[6]); + // vec_face_nodes.push_back(element_nodes[6]); vec_face_nodes.push_back(Node6); - //vec_face_nodes.push_back(element_nodes[2]); + // vec_face_nodes.push_back(element_nodes[2]); vec_face_nodes.push_back(Node2); - //vec_face_nodes.push_back(element_nodes[7]); + // vec_face_nodes.push_back(element_nodes[7]); vec_face_nodes.push_back(Node7); - //vec_face_nodes.push_back(element_nodes[3]); + // vec_face_nodes.push_back(element_nodes[3]); vec_face_nodes.push_back(Node3); } - //create the face - if (m_face->CreateFace(vec_face_nodes[0], vec_face_nodes[1], vec_face_nodes[2], - vec_face_nodes[3]) == false) + // create the face + if (m_face->CreateFace(vec_face_nodes[0], vec_face_nodes[1], vec_face_nodes[2], vec_face_nodes[3]) == false) { - cout << "Error at creating face: The given points form not a plane!" << - "\n"; - //system("Pause"); + cout << "Error at creating face: The given points form not a plane!" + << "\n"; + // system("Pause"); return false; } - //add connected elements to the face (first the lower (y) element, second the upper element) + // add connected elements to the face (first the lower (y) element, second the upper element) element_indices.clear(); element_indices.push_back(i); if (this->eclgrid[i]->NeighbourElement[3] > -1) element_indices.push_back(this->eclgrid[i]->NeighbourElement[3]); m_face->SetElements(element_indices); - //add the face to the vector + // add the face to the vector faces.push_back(m_face); for (unsigned long j = 0; j < vec_face_nodes.size(); j++) { - //Connect nodes with faces - m_msh->nod_vector[vec_face_nodes[j]->GetIndex()]->connected_faces.push_back( - m_face->index); - //Calculate distance between node and gravity centre of the face and store it in a vector - m_msh->nod_vector[vec_face_nodes[j]->GetIndex()]-> - distance_to_connected_faces.push_back(sqrt(MathLib::sqrDist(vec_face_nodes[ - j - ]->getData(), - m_face-> - GetFaceGravityCentre()))); + // Connect nodes with faces + m_msh->nod_vector[vec_face_nodes[j]->GetIndex()]->connected_faces.push_back(m_face->index); + // Calculate distance between node and gravity centre of the face and store it in a vector + m_msh->nod_vector[vec_face_nodes[j]->GetIndex()]->distance_to_connected_faces.push_back( + sqrt(MathLib::sqrDist(vec_face_nodes[j]->getData(), m_face->GetFaceGravityCentre()))); } - //non-radial elements: Bottom face of the Element (k-direction) (Nodes: 4,5,7,6) -> with this order of the nodes the normal vector shows automatically to the positve k-direction - //radial elements: Bottom face of the Element (k-direction) (Nodes: 6,5,7,4) -> with this order of the nodes the normal vector shows automatically to the positve k-direction + // non-radial elements: Bottom face of the Element (k-direction) (Nodes: 4,5,7,6) -> with this order of the + // nodes the normal vector shows automatically to the positve k-direction + // radial elements: Bottom face of the Element (k-direction) (Nodes: 6,5,7,4) -> with this order of the nodes + // the normal vector shows automatically to the positve k-direction m_face = new CFaces(int(this->Phases.size())); m_face->index = long(faces.size()); m_face->model_axis = "K+"; - //store all nodes of the face in a vector + // store all nodes of the face in a vector vec_face_nodes.clear(); if (Radialmodell == false) { - //vec_face_nodes.push_back(element_nodes[4]); + // vec_face_nodes.push_back(element_nodes[4]); vec_face_nodes.push_back(Node4); - //vec_face_nodes.push_back(element_nodes[5]); + // vec_face_nodes.push_back(element_nodes[5]); vec_face_nodes.push_back(Node5); - //vec_face_nodes.push_back(element_nodes[7]); + // vec_face_nodes.push_back(element_nodes[7]); vec_face_nodes.push_back(Node7); - //vec_face_nodes.push_back(element_nodes[6]); + // vec_face_nodes.push_back(element_nodes[6]); vec_face_nodes.push_back(Node6); } else { - //vec_face_nodes.push_back(element_nodes[6]); + // vec_face_nodes.push_back(element_nodes[6]); vec_face_nodes.push_back(Node6); - //vec_face_nodes.push_back(element_nodes[5]); + // vec_face_nodes.push_back(element_nodes[5]); vec_face_nodes.push_back(Node5); - //vec_face_nodes.push_back(element_nodes[7]); + // vec_face_nodes.push_back(element_nodes[7]); vec_face_nodes.push_back(Node7); - //vec_face_nodes.push_back(element_nodes[4]); + // vec_face_nodes.push_back(element_nodes[4]); vec_face_nodes.push_back(Node4); } - //create the face - if (m_face->CreateFace(vec_face_nodes[0], vec_face_nodes[1], vec_face_nodes[2], - vec_face_nodes[3]) == false) + // create the face + if (m_face->CreateFace(vec_face_nodes[0], vec_face_nodes[1], vec_face_nodes[2], vec_face_nodes[3]) == false) { - cout << "Error at creating face: The given points form not a plane!" << - "\n"; - //system("Pause"); + cout << "Error at creating face: The given points form not a plane!" + << "\n"; + // system("Pause"); return false; } - //add connected elements to the face (first the top (z) element, second the bottom element, because the order of z is in Eclipse opposit) + // add connected elements to the face (first the top (z) element, second the bottom element, because the order + // of z is in Eclipse opposit) element_indices.clear(); element_indices.push_back(i); if (this->eclgrid[i]->NeighbourElement[5] > -1) element_indices.push_back(this->eclgrid[i]->NeighbourElement[5]); m_face->SetElements(element_indices); - //add the face to the vector + // add the face to the vector faces.push_back(m_face); for (unsigned long j = 0; j < vec_face_nodes.size(); j++) { - //Connect nodes with faces - m_msh->nod_vector[vec_face_nodes[j]->GetIndex()]->connected_faces.push_back( - m_face->index); - //Calculate distance between node and gravity centre of the face and store it in a vector - m_msh->nod_vector[vec_face_nodes[j]->GetIndex()]-> - distance_to_connected_faces.push_back(sqrt(MathLib::sqrDist(vec_face_nodes[ - j - ]->getData(), - m_face-> - GetFaceGravityCentre()))); - } - - //non-radial elements: Left face of the Element at the left (x) site of the grid (i-direction) (Nodes: 0,4,3,7) -> with this order of the nodes the normal vector shows automatically to the positve i-direction - //radial elements: Left face of the Element at the left (x) site of the grid (i-direction) (Nodes: 7,4,3,0) -> with this order of the nodes the normal vector shows automatically to the positve i-direction - //if (this->eclgrid[i]->column == 1){ + // Connect nodes with faces + m_msh->nod_vector[vec_face_nodes[j]->GetIndex()]->connected_faces.push_back(m_face->index); + // Calculate distance between node and gravity centre of the face and store it in a vector + m_msh->nod_vector[vec_face_nodes[j]->GetIndex()]->distance_to_connected_faces.push_back( + sqrt(MathLib::sqrDist(vec_face_nodes[j]->getData(), m_face->GetFaceGravityCentre()))); + } + + // non-radial elements: Left face of the Element at the left (x) site of the grid (i-direction) (Nodes: 0,4,3,7) + // -> with this order of the nodes the normal vector shows automatically to the positve i-direction + // radial elements: Left face of the Element at the left (x) site of the grid (i-direction) (Nodes: 7,4,3,0) -> + // with this order of the nodes the normal vector shows automatically to the positve i-direction + // if (this->eclgrid[i]->column == 1){ // if there is no element at the left site of the current element if (this->eclgrid[i]->NeighbourElement[0] == -1) { m_face = new CFaces(int(this->Phases.size())); m_face->index = long(faces.size()); m_face->model_axis = "I-"; - //store all nodes of the face in a vector + // store all nodes of the face in a vector vec_face_nodes.clear(); if (Radialmodell == false) { - //vec_face_nodes.push_back(element_nodes[0]); + // vec_face_nodes.push_back(element_nodes[0]); vec_face_nodes.push_back(Node0); - //vec_face_nodes.push_back(element_nodes[4]); + // vec_face_nodes.push_back(element_nodes[4]); vec_face_nodes.push_back(Node4); - //vec_face_nodes.push_back(element_nodes[3]); + // vec_face_nodes.push_back(element_nodes[3]); vec_face_nodes.push_back(Node3); - //vec_face_nodes.push_back(element_nodes[7]); + // vec_face_nodes.push_back(element_nodes[7]); vec_face_nodes.push_back(Node7); } - if (this->RadialModellIpos == true ) + if (this->RadialModellIpos == true) { - //vec_face_nodes.push_back(element_nodes[7]); + // vec_face_nodes.push_back(element_nodes[7]); vec_face_nodes.push_back(Node7); - //vec_face_nodes.push_back(element_nodes[4]); + // vec_face_nodes.push_back(element_nodes[4]); vec_face_nodes.push_back(Node4); - //vec_face_nodes.push_back(element_nodes[3]); + // vec_face_nodes.push_back(element_nodes[3]); vec_face_nodes.push_back(Node3); - //vec_face_nodes.push_back(element_nodes[0]); + // vec_face_nodes.push_back(element_nodes[0]); vec_face_nodes.push_back(Node0); } - //create the face - if (m_face->CreateFace(vec_face_nodes[0], vec_face_nodes[1], - vec_face_nodes[2], vec_face_nodes[3]) == false) + // create the face + if (m_face->CreateFace(vec_face_nodes[0], vec_face_nodes[1], vec_face_nodes[2], vec_face_nodes[3]) == false) { - cout << - "Error at creating face: The given points form not a plane!" << - "\n"; - //system("Pause"); + cout << "Error at creating face: The given points form not a plane!" + << "\n"; + // system("Pause"); return false; } - //add connected elements to the face + // add connected elements to the face element_indices.clear(); element_indices.push_back(i); if (this->eclgrid[i]->NeighbourElement[0] > -1) return false; m_face->SetElements(element_indices); - //add the face to the vector + // add the face to the vector faces.push_back(m_face); for (unsigned long j = 0; j < vec_face_nodes.size(); j++) { - //Connect nodes with faces - m_msh->nod_vector[vec_face_nodes[j]->GetIndex()]->connected_faces. - push_back(m_face->index); - //Calculate distance between node and gravity centre of the face and store it in a vector - m_msh->nod_vector[vec_face_nodes[j]->GetIndex()]-> - distance_to_connected_faces.push_back(sqrt(MathLib::sqrDist( - vec_face_nodes[j - ]->getData(), - m_face-> - GetFaceGravityCentre()))); + // Connect nodes with faces + m_msh->nod_vector[vec_face_nodes[j]->GetIndex()]->connected_faces.push_back(m_face->index); + // Calculate distance between node and gravity centre of the face and store it in a vector + m_msh->nod_vector[vec_face_nodes[j]->GetIndex()]->distance_to_connected_faces.push_back( + sqrt(MathLib::sqrDist(vec_face_nodes[j]->getData(), m_face->GetFaceGravityCentre()))); } } - //non-radial elements: Lower (y) face of the Element at the lower (y) site of the grid (j-direction) (Nodes: 0,1,4,5) -> with this order of the nodes the normal vector shows automatically to the positve j-direction - //radial elements: Lower (y) face of the Element at the lower (y) site of the grid (j-direction) (Nodes: 5,1,4,0) -> with this order of the nodes the normal vector shows automatically to the positve j-direction - //if (this->eclgrid[i]->row == 1){ + // non-radial elements: Lower (y) face of the Element at the lower (y) site of the grid (j-direction) (Nodes: + // 0,1,4,5) -> with this order of the nodes the normal vector shows automatically to the positve j-direction + // radial elements: Lower (y) face of the Element at the lower (y) site of the grid (j-direction) (Nodes: + // 5,1,4,0) -> with this order of the nodes the normal vector shows automatically to the positve j-direction + // if (this->eclgrid[i]->row == 1){ if (this->eclgrid[i]->NeighbourElement[2] == -1) { m_face = new CFaces(int(this->Phases.size())); m_face->index = long(faces.size()); m_face->model_axis = "J-"; - //store all nodes of the face in a vector + // store all nodes of the face in a vector vec_face_nodes.clear(); if (Radialmodell == false) { - //vec_face_nodes.push_back(element_nodes[0]); + // vec_face_nodes.push_back(element_nodes[0]); vec_face_nodes.push_back(Node0); - //vec_face_nodes.push_back(element_nodes[1]); + // vec_face_nodes.push_back(element_nodes[1]); vec_face_nodes.push_back(Node1); - //vec_face_nodes.push_back(element_nodes[4]); + // vec_face_nodes.push_back(element_nodes[4]); vec_face_nodes.push_back(Node4); - //vec_face_nodes.push_back(element_nodes[5]); + // vec_face_nodes.push_back(element_nodes[5]); vec_face_nodes.push_back(Node5); } - if (this->RadialModellIpos == true ) + if (this->RadialModellIpos == true) { - //vec_face_nodes.push_back(element_nodes[5]); + // vec_face_nodes.push_back(element_nodes[5]); vec_face_nodes.push_back(Node5); - //vec_face_nodes.push_back(element_nodes[1]); + // vec_face_nodes.push_back(element_nodes[1]); vec_face_nodes.push_back(Node1); - //vec_face_nodes.push_back(element_nodes[4]); + // vec_face_nodes.push_back(element_nodes[4]); vec_face_nodes.push_back(Node4); - //vec_face_nodes.push_back(element_nodes[0]); + // vec_face_nodes.push_back(element_nodes[0]); vec_face_nodes.push_back(Node0); } - //create the face - if (m_face->CreateFace(vec_face_nodes[0], vec_face_nodes[1], - vec_face_nodes[2], vec_face_nodes[3]) == false) + // create the face + if (m_face->CreateFace(vec_face_nodes[0], vec_face_nodes[1], vec_face_nodes[2], vec_face_nodes[3]) == false) { - cout << - "Error at creating face: The given points form not a plane!" << - "\n"; - //system("Pause"); + cout << "Error at creating face: The given points form not a plane!" + << "\n"; + // system("Pause"); return false; } - //add connected elements to the face + // add connected elements to the face element_indices.clear(); element_indices.push_back(i); if (this->eclgrid[i]->NeighbourElement[2] > -1) return false; m_face->SetElements(element_indices); - //add the face to the vector + // add the face to the vector faces.push_back(m_face); for (unsigned long j = 0; j < vec_face_nodes.size(); j++) { - //Connect nodes with faces - m_msh->nod_vector[vec_face_nodes[j]->GetIndex()]->connected_faces. - push_back(m_face->index); - //Calculate distance between node and gravity centre of the face and store it in a vector - m_msh->nod_vector[vec_face_nodes[j]->GetIndex()]-> - distance_to_connected_faces.push_back(sqrt(MathLib::sqrDist( - vec_face_nodes[j - ]->getData(), - m_face-> - GetFaceGravityCentre()))); + // Connect nodes with faces + m_msh->nod_vector[vec_face_nodes[j]->GetIndex()]->connected_faces.push_back(m_face->index); + // Calculate distance between node and gravity centre of the face and store it in a vector + m_msh->nod_vector[vec_face_nodes[j]->GetIndex()]->distance_to_connected_faces.push_back( + sqrt(MathLib::sqrDist(vec_face_nodes[j]->getData(), m_face->GetFaceGravityCentre()))); } } - //non-radial elements: Top (z) face of the Element at the top (z) site of the grid (k-direction) (Nodes: 0,1,3,2) -> with this order of the nodes the normal vector shows automatically to the positve k-direction - //radial elements: Top (z) face of the Element at the top (z) site of the grid (k-direction) (Nodes: 2,1,3,0) -> with this order of the nodes the normal vector shows automatically to the positve k-direction - //if (this->eclgrid[i]->layer == 1 /* SB->BG :changed - please check "if (this->eclgrid[i]->layer == this->layers"*/){ + // non-radial elements: Top (z) face of the Element at the top (z) site of the grid (k-direction) (Nodes: + // 0,1,3,2) -> with this order of the nodes the normal vector shows automatically to the positve k-direction + // radial elements: Top (z) face of the Element at the top (z) site of the grid (k-direction) (Nodes: 2,1,3,0) + // -> with this order of the nodes the normal vector shows automatically to the positve k-direction + // if (this->eclgrid[i]->layer == 1 /* SB->BG :changed - please check "if (this->eclgrid[i]->layer == + // this->layers"*/){ if (this->eclgrid[i]->NeighbourElement[4] == -1) { m_face = new CFaces(int(this->Phases.size())); m_face->index = long(faces.size()); m_face->model_axis = "K-"; - //store all nodes of the face in a vector + // store all nodes of the face in a vector vec_face_nodes.clear(); if (Radialmodell == false) { - //vec_face_nodes.push_back(element_nodes[0]); + // vec_face_nodes.push_back(element_nodes[0]); vec_face_nodes.push_back(Node0); - //vec_face_nodes.push_back(element_nodes[1]); + // vec_face_nodes.push_back(element_nodes[1]); vec_face_nodes.push_back(Node1); - //vec_face_nodes.push_back(element_nodes[3]); + // vec_face_nodes.push_back(element_nodes[3]); vec_face_nodes.push_back(Node3); - //vec_face_nodes.push_back(element_nodes[2]); + // vec_face_nodes.push_back(element_nodes[2]); vec_face_nodes.push_back(Node2); } else { - //vec_face_nodes.push_back(element_nodes[2]); + // vec_face_nodes.push_back(element_nodes[2]); vec_face_nodes.push_back(Node2); - //vec_face_nodes.push_back(element_nodes[1]); + // vec_face_nodes.push_back(element_nodes[1]); vec_face_nodes.push_back(Node1); - //vec_face_nodes.push_back(element_nodes[3]); + // vec_face_nodes.push_back(element_nodes[3]); vec_face_nodes.push_back(Node3); - //vec_face_nodes.push_back(element_nodes[0]); + // vec_face_nodes.push_back(element_nodes[0]); vec_face_nodes.push_back(Node0); } - //create the face - if (m_face->CreateFace(vec_face_nodes[0], vec_face_nodes[1], - vec_face_nodes[2], vec_face_nodes[3]) == false) + // create the face + if (m_face->CreateFace(vec_face_nodes[0], vec_face_nodes[1], vec_face_nodes[2], vec_face_nodes[3]) == false) { - cout << - "Error at creating face: The given points form not a plane!" << - "\n"; - //system("Pause"); + cout << "Error at creating face: The given points form not a plane!" + << "\n"; + // system("Pause"); return false; } - //add connected elements to the face + // add connected elements to the face element_indices.clear(); element_indices.push_back(i); if (this->eclgrid[i]->NeighbourElement[4] > -1) return false; m_face->SetElements(element_indices); - //add the face to the vector + // add the face to the vector faces.push_back(m_face); for (unsigned long j = 0; j < vec_face_nodes.size(); j++) { - //Connect nodes with faces - m_msh->nod_vector[vec_face_nodes[j]->GetIndex()]->connected_faces. - push_back(m_face->index); - //Calculate distance between node and gravity centre of the face and store it in a vector - m_msh->nod_vector[vec_face_nodes[j]->GetIndex()]-> - distance_to_connected_faces.push_back(sqrt(MathLib::sqrDist( - vec_face_nodes[j - ]->getData(), - m_face-> - GetFaceGravityCentre()))); + // Connect nodes with faces + m_msh->nod_vector[vec_face_nodes[j]->GetIndex()]->connected_faces.push_back(m_face->index); + // Calculate distance between node and gravity centre of the face and store it in a vector + m_msh->nod_vector[vec_face_nodes[j]->GetIndex()]->distance_to_connected_faces.push_back( + sqrt(MathLib::sqrDist(vec_face_nodes[j]->getData(), m_face->GetFaceGravityCentre()))); } } } // Test output faces - //double *n_vec; - //for(long i=0;iconnected_elements.size();j++) // cout << faces[i]->connected_elements[j] << " - " ; @@ -2796,12 +2646,12 @@ bool CECLIPSEData::CreateFaces(void) finish = clock(); time = (double(finish) - double(start)) / CLOCKS_PER_SEC; - cout << " Time: " << time << " seconds." << "\n"; + cout << " Time: " << time << " seconds." + << "\n"; return true; } - /*------------------------------------------------------------------------- GeoSys - Function: CreateFacesAtElements Task: For each element, find all faces and store them in connected_faces @@ -2811,11 +2661,11 @@ bool CECLIPSEData::CreateFaces(void) -------------------------------------------------------------------------*/ bool CECLIPSEData::ConnectFacesToElements(void) { - //CECLIPSEBlock*m_block=NULL; + // CECLIPSEBlock*m_block=NULL; CFaces* m_face = NULL; long ind_block, ind_face; - vector faces_at_block; - clock_t start,finish; + vector faces_at_block; + clock_t start, finish; double time; start = clock(); @@ -2823,92 +2673,95 @@ bool CECLIPSEData::ConnectFacesToElements(void) cout << " ConnectFacesToElements() "; // go through all faces and add them to the eclipse blocks - for(unsigned long i = 0; i < this->faces.size(); i++) + for (unsigned long i = 0; i < this->faces.size(); i++) { m_face = this->faces[i]; ind_face = m_face->index; - for(unsigned long j = 0; j < m_face->connected_elements.size(); j++) + for (unsigned long j = 0; j < m_face->connected_elements.size(); j++) { ind_block = m_face->connected_elements[j]; this->eclgrid[ind_block]->connected_faces.push_back(ind_face); } } // Test output - //for(unsigned long i=0;iindex << " : "; // for(int j=0;jconnected_faces.size();j++) cout << eclgrid[i]->connected_faces[j] << ", "; // cout << "\n"; //} - for(long i = 0; i < long(eclgrid.size()); i++) + for (long i = 0; i < long(eclgrid.size()); i++) { // Test output: all faces at one block - if(eclgrid[i]->connected_faces.size() != 6) - cout << " Error - not 6 faces at one block " << "\n"; + if (eclgrid[i]->connected_faces.size() != 6) + cout << " Error - not 6 faces at one block " + << "\n"; // initialize vector faces_at_block faces_at_block.clear(); - for(unsigned long j = 0; j < 6; j++) + for (unsigned long j = 0; j < 6; j++) faces_at_block.push_back(-1); - for(unsigned long j = 0; j < eclgrid[i]->connected_faces.size(); j++) + for (unsigned long j = 0; j < eclgrid[i]->connected_faces.size(); j++) { - //cout << eclgrid[i]->connected_faces[j] << ", "; + // cout << eclgrid[i]->connected_faces[j] << ", "; // Order faces +i, -i, +j. -j, +k , -k m_face = faces[eclgrid[i]->connected_faces[j]]; // get face - if(m_face->model_axis == "I+") + if (m_face->model_axis == "I+") { - if(m_face->connected_elements[0] == i) - faces_at_block[0] = m_face->index; // this is +i for this element + if (m_face->connected_elements[0] == i) + faces_at_block[0] = m_face->index; // this is +i for this element else - faces_at_block[1] = m_face->index; // this is -i for this element + faces_at_block[1] = m_face->index; // this is -i for this element } - if(m_face->model_axis == "I-") + if (m_face->model_axis == "I-") { - if(m_face->connected_elements[0] == i) - faces_at_block[1] = m_face->index; // for this element it is i- + if (m_face->connected_elements[0] == i) + faces_at_block[1] = m_face->index; // for this element it is i- else - faces_at_block[0] = m_face->index; // for this element it is i+ + faces_at_block[0] = m_face->index; // for this element it is i+ } - if(m_face->model_axis == "J+") + if (m_face->model_axis == "J+") { - if(m_face->connected_elements[0] == i) + if (m_face->connected_elements[0] == i) faces_at_block[2] = m_face->index; else faces_at_block[3] = m_face->index; } - if(m_face->model_axis == "J-") + if (m_face->model_axis == "J-") { - if(m_face->connected_elements[0] == i) + if (m_face->connected_elements[0] == i) faces_at_block[3] = m_face->index; else faces_at_block[2] = m_face->index; } - if(m_face->model_axis == "K+") + if (m_face->model_axis == "K+") { - if(m_face->connected_elements[0] == i) + if (m_face->connected_elements[0] == i) faces_at_block[4] = m_face->index; else faces_at_block[5] = m_face->index; } - if(m_face->model_axis == "K-") + if (m_face->model_axis == "K-") { - if(m_face->connected_elements[0] == i) + if (m_face->connected_elements[0] == i) faces_at_block[5] = m_face->index; else faces_at_block[4] = m_face->index; } } // copy sorted faces to ecl block - for(unsigned long j = 0; j < eclgrid[i]->connected_faces.size(); j++) { + for (unsigned long j = 0; j < eclgrid[i]->connected_faces.size(); j++) + { eclgrid[i]->connected_faces[j] = faces_at_block[j]; - //// Test output - //cout << " Faces at block " << eclgrid[i]->index << " : "; - //for(j=0;jconnected_faces.size();j++) cout << eclgrid[i]->connected_faces[j] << ", "; - //cout << "\n"; + //// Test output + // cout << " Faces at block " << eclgrid[i]->index << " : "; + // for(j=0;jconnected_faces.size();j++) cout << eclgrid[i]->connected_faces[j] << ", "; + // cout << "\n"; } } finish = clock(); time = (double(finish) - double(start)) / CLOCKS_PER_SEC; - cout << " Time: " << time << " seconds." << "\n"; + cout << " Time: " << time << " seconds." + << "\n"; return true; } @@ -2921,14 +2774,14 @@ bool CECLIPSEData::ConnectFacesToElements(void) -------------------------------------------------------------------------*/ bool CECLIPSEData::GetFlowForFaces(int phase_index) { - //CFEMesh* m_msh = fem_msh_vector[0]; + // CFEMesh* m_msh = fem_msh_vector[0]; CFaces* m_face = NULL; long number_elements; long element_index; long variable_index; - //WW long time_index; + // WW long time_index; double vz = 1.0; // Sign - clock_t start,finish; + clock_t start, finish; double time; start = clock(); @@ -2937,8 +2790,8 @@ bool CECLIPSEData::GetFlowForFaces(int phase_index) for (long i = 0; i < long(this->faces.size()); i++) { m_face = this->faces[i]; - //set initial values - //if (i == 4225) { + // set initial values + // if (i == 4225) { // cout << i; //} m_face->phases[phase_index]->q_norm = 0.0; @@ -2947,8 +2800,9 @@ bool CECLIPSEData::GetFlowForFaces(int phase_index) if ((number_elements < 1) || (number_elements > 2)) { - cout << "There is an error in connecting faces and elements" << "\n"; - //system("Pause"); + cout << "There is an error in connecting faces and elements" + << "\n"; + // system("Pause"); exit(0); } @@ -2956,7 +2810,7 @@ bool CECLIPSEData::GetFlowForFaces(int phase_index) if (m_face->model_axis == "I+") { element_index = m_face->connected_elements[0]; - //WW time_index = 0; + // WW time_index = 0; if (this->RadialModellJpos == true) { if (this->Phases[phase_index] == "WATER") @@ -2968,14 +2822,12 @@ bool CECLIPSEData::GetFlowForFaces(int phase_index) else { if (this->Phases[phase_index] == "OIL") - variable_index = this->GetVariableIndex( - "FLOOILJ+"); + variable_index = this->GetVariableIndex("FLOOILJ+"); else { - cout << - "This phase is not considered yet in GetFlowForFaces" + cout << "This phase is not considered yet in GetFlowForFaces" << "\n"; - //system("Pause"); + // system("Pause"); exit(0); } } @@ -2992,14 +2844,12 @@ bool CECLIPSEData::GetFlowForFaces(int phase_index) else { if (this->Phases[phase_index] == "OIL") - variable_index = this->GetVariableIndex( - "FLOOILI+"); + variable_index = this->GetVariableIndex("FLOOILI+"); else { - cout << - "This phase is not considered yet in GetFlowForFaces" + cout << "This phase is not considered yet in GetFlowForFaces" << "\n"; - //system("Pause"); + // system("Pause"); exit(0); } } @@ -3007,16 +2857,17 @@ bool CECLIPSEData::GetFlowForFaces(int phase_index) } if (variable_index < 0) { - cout << "There are no variables!" << "\n"; - //system("Pause"); + cout << "There are no variables!" + << "\n"; + // system("Pause"); exit(0); } - //calculate q [m�/m�.s] for Geosys from Q [m�/d] from Eclipse - m_face->phases[phase_index]->q_norm = - (this->Data[element_index][variable_index] / - m_face->face_area) / 86400.0; + // calculate q [m�/m�.s] for Geosys from Q [m�/d] from Eclipse + m_face->phases[phase_index]->q_norm + = (this->Data[element_index][variable_index] / m_face->face_area) / 86400.0; m_face->Calculate_components_of_a_vector(0, phase_index, Radialmodell); - //cout << " Flow through face " << m_face->index << " element " << element_index << " : " << this->Data[element_index][time_index][variable_index] << " , " << m_face->q_norm << "\n"; + // cout << " Flow through face " << m_face->index << " element " << element_index << " : " << + // this->Data[element_index][time_index][variable_index] << " , " << m_face->q_norm << "\n"; } // upper face (y) if (m_face->model_axis == "J+") @@ -3033,14 +2884,12 @@ bool CECLIPSEData::GetFlowForFaces(int phase_index) else { if (this->Phases[phase_index] == "OIL") - variable_index = this->GetVariableIndex( - "FLOOILI+"); + variable_index = this->GetVariableIndex("FLOOILI+"); else { - cout << - "This phase is not considered yet in GetFlowForFaces" + cout << "This phase is not considered yet in GetFlowForFaces" << "\n"; - //system("Pause"); + // system("Pause"); exit(0); } } @@ -3057,32 +2906,31 @@ bool CECLIPSEData::GetFlowForFaces(int phase_index) else { if (this->Phases[phase_index] == "OIL") - variable_index = this->GetVariableIndex( - "FLOOILJ+"); + variable_index = this->GetVariableIndex("FLOOILJ+"); else { - cout << - "This phase is not considered yet in GetFlowForFaces" + cout << "This phase is not considered yet in GetFlowForFaces" << "\n"; - //system("Pause"); + // system("Pause"); exit(0); } } } } - //WW time_index = 0; + // WW time_index = 0; if (variable_index < 0) { - cout << "There are no variables!" << "\n"; - //system("Pause"); + cout << "There are no variables!" + << "\n"; + // system("Pause"); exit(0); } - //calculate q [m�/m�.s] for Geosys from Q [m�/d] from Eclipse - m_face->phases[phase_index]->q_norm = - (this->Data[element_index][variable_index] / - m_face->face_area) / 86400.0; + // calculate q [m�/m�.s] for Geosys from Q [m�/d] from Eclipse + m_face->phases[phase_index]->q_norm + = (this->Data[element_index][variable_index] / m_face->face_area) / 86400.0; m_face->Calculate_components_of_a_vector(0, phase_index, Radialmodell); - //cout << " Flow through face " << m_face->index << " element " << element_index << " : " << this->Data[element_index][time_index][variable_index] << " , " << m_face->q_norm << "\n"; + // cout << " Flow through face " << m_face->index << " element " << element_index << " : " << + // this->Data[element_index][time_index][variable_index] << " , " << m_face->q_norm << "\n"; } // bottom face (z) (Eclipse has the opposite z direction -> k = + if (m_face->model_axis == "K+") @@ -3100,104 +2948,101 @@ bool CECLIPSEData::GetFlowForFaces(int phase_index) variable_index = this->GetVariableIndex("FLOOILK+"); else { - cout << - "This phase is not considered yet in GetFlowForFaces" + cout << "This phase is not considered yet in GetFlowForFaces" << "\n"; - //system("Pause"); + // system("Pause"); exit(0); } } } - //WW time_index = 0; + // WW time_index = 0; if (variable_index < 0) { - cout << "There are no variables!" << "\n"; - //system("Pause"); + cout << "There are no variables!" + << "\n"; + // system("Pause"); exit(0); } - //calculate q [m�/m�.s] for Geosys from Q [m�/d] from Eclipse - m_face->phases[phase_index]->q_norm = - (this->Data[element_index][variable_index] / - m_face->face_area) / 86400.0; + // calculate q [m�/m�.s] for Geosys from Q [m�/d] from Eclipse + m_face->phases[phase_index]->q_norm + = (this->Data[element_index][variable_index] / m_face->face_area) / 86400.0; m_face->Calculate_components_of_a_vector(0, phase_index, Radialmodell); - //cout << " Flow through face " << m_face->index << " element " << element_index << " : " << this->Data[element_index][time_index][variable_index] << " , " << m_face->q_norm << "\n"; + // cout << " Flow through face " << m_face->index << " element " << element_index << " : " << + // this->Data[element_index][time_index][variable_index] << " , " << m_face->q_norm << "\n"; } // left, lower and top faces -> now flow over these faces - if ((m_face->model_axis == "I-") || (m_face->model_axis == "J-") || - (m_face->model_axis == "K-")) + if ((m_face->model_axis == "I-") || (m_face->model_axis == "J-") || (m_face->model_axis == "K-")) { m_face->phases[phase_index]->q_norm = 0; m_face->Calculate_components_of_a_vector(0, phase_index, Radialmodell); } - //if ((element_index == 609) || (element_index == 610) || (element_index == 611) || (element_index == 646) || (element_index == 647) || (element_index == 648) || (element_index == 683) || (element_index == 684) || (element_index == 685) || (element_index == 720) || (element_index == 721) || (element_index == 722)) + // if ((element_index == 609) || (element_index == 610) || (element_index == 611) || (element_index == 646) || + // (element_index == 647) || (element_index == 648) || (element_index == 683) || (element_index == 684) || + // (element_index == 685) || (element_index == 720) || (element_index == 721) || (element_index == 722)) // cout << "Zentrum" << "\n"; // - //Get additional flow for border cells that contain boundary conditions + // Get additional flow for border cells that contain boundary conditions if (m_face->connected_elements.size() == 1) { long ele_index = m_face->connected_elements[0]; - //check if there is one BC in the element + // check if there is one BC in the element if (this->eclgrid[ele_index]->ConnectedBoundaryCondition.size() > 1) { - cout << - "There is more than 1 boundary condition assigned to the cell " << - ele_index << "\n"; - //system("Pause"); + cout << "There is more than 1 boundary condition assigned to the cell " << ele_index << "\n"; + // system("Pause"); exit(0); } if (this->eclgrid[ele_index]->ConnectedBoundaryCondition.size() == 1) { - long bc_index = - this->eclgrid[ele_index]->ConnectedBoundaryCondition[0]; - //check if the boundary inflow fits to the current face + long bc_index = this->eclgrid[ele_index]->ConnectedBoundaryCondition[0]; + // check if the boundary inflow fits to the current face if (m_face->model_axis == this->BC[bc_index]->boundary_position) { - //check if q is 0 + // check if q is 0 if (m_face->phases[phase_index]->q_norm == 0) { - //calculate q [m�/m�.s] for Geosys from Q [m�/d] from Eclipse - //cout << " BC Flow through face " << m_face->index << " : " << this->BC[bc_index]->value[0] << "\n"; + // calculate q [m�/m�.s] for Geosys from Q [m�/d] from Eclipse + // cout << " BC Flow through face " << m_face->index << " : " << this->BC[bc_index]->value[0] + // << "\n"; vz = 1.0; - //if(this->BC[bc_index]->value[0] < 0){ // outflow out of model area - //The values in I+, J+ and K+ direction have to be counted with the opposit direction + // if(this->BC[bc_index]->value[0] < 0){ // outflow out of model area + // The values in I+, J+ and K+ direction have to be counted with the opposit direction // because the flow from BC is given positive if fluid flows from the BC into the model - if(m_face->model_axis == "I+") + if (m_face->model_axis == "I+") vz = -1.0; - if(m_face->model_axis == "J+") + if (m_face->model_axis == "J+") vz = -1.0; - if(m_face->model_axis == "K+") + if (m_face->model_axis == "K+") vz = -1.0; //} - m_face->phases[phase_index]->q_norm = - (this->BC[bc_index]->value[0] * vz / - m_face->face_area) / 86400.0; - m_face->Calculate_components_of_a_vector( - 0, - phase_index, - Radialmodell); - //cout << " Flow through face " << m_face->index << " element " << element_index << " : " << this->BC[bc_index]->value[0] << " , " << m_face->q_norm << "\n"; + m_face->phases[phase_index]->q_norm + = (this->BC[bc_index]->value[0] * vz / m_face->face_area) / 86400.0; + m_face->Calculate_components_of_a_vector(0, phase_index, Radialmodell); + // cout << " Flow through face " << m_face->index << " element " << element_index << " : " << + // this->BC[bc_index]->value[0] << " , " << m_face->q_norm << "\n"; } else { - cout << - "There is already a flow assigned to the boundary face, which shouldn't happen " + cout << "There is already a flow assigned to the boundary face, which shouldn't happen " << m_face->index << "\n"; - //system("Pause"); + // system("Pause"); exit(0); } } } } - //cout << " Face " << m_face->index << ", " << m_face->connected_elements[0] ; - //if(m_face->connected_elements.size() > 1) cout << ", " << m_face->connected_elements[1]; - //cout << ": " << m_face->q_norm << ": " << m_face->q[0] << ", " << m_face->q[1] << ", " << m_face->q[2] << "\n"; + // cout << " Face " << m_face->index << ", " << m_face->connected_elements[0] ; + // if(m_face->connected_elements.size() > 1) cout << ", " << m_face->connected_elements[1]; + // cout << ": " << m_face->q_norm << ": " << m_face->q[0] << ", " << m_face->q[1] << ", " << + // m_face->q[2] << "\n"; } finish = clock(); time = (double(finish) - double(start)) / CLOCKS_PER_SEC; - cout << " Time: " << time << " seconds." << "\n"; + cout << " Time: " << time << " seconds." + << "\n"; return true; } @@ -3212,12 +3057,12 @@ bool CECLIPSEData::GetFlowForFaces(int phase_index) -------------------------------------------------------------------------*/ bool CECLIPSEData::GetVelForFaces(void) { - //CFEMesh* m_msh = fem_msh_vector[0]; + // CFEMesh* m_msh = fem_msh_vector[0]; CFaces* m_face = NULL; long number_elements; long element_index; long variable_index; - //WW long time_index; + // WW long time_index; for (unsigned long i = 0; i < this->faces.size(); i++) { @@ -3231,48 +3076,48 @@ bool CECLIPSEData::GetVelForFaces(void) if (m_face->model_axis == "I+") { element_index = m_face->connected_elements[0]; - //WW time_index = 0; + // WW time_index = 0; variable_index = this->GetVariableIndex("VELWATI+"); if (variable_index < 0) return false; m_face->v_norm = this->Data[element_index][variable_index]; - //m_face->Calculate_components_of_a_vector(1); + // m_face->Calculate_components_of_a_vector(1); } // upper face (y) if (m_face->model_axis == "J+") { element_index = m_face->connected_elements[0]; variable_index = this->GetVariableIndex("VELWATJ+"); - //WW time_index = 0; + // WW time_index = 0; if (variable_index < 0) return false; m_face->v_norm = this->Data[element_index][variable_index]; - //m_face->Calculate_components_of_a_vector(1); + // m_face->Calculate_components_of_a_vector(1); } // bottom face (z) (Eclipse has the opposite z direction -> k = + if (m_face->model_axis == "K+") { element_index = m_face->connected_elements[0]; variable_index = this->GetVariableIndex("VELWATK+"); - //WW time_index = 0; + // WW time_index = 0; if (variable_index < 0) return false; m_face->v_norm = this->Data[element_index][variable_index]; - //m_face->Calculate_components_of_a_vector(1); + // m_face->Calculate_components_of_a_vector(1); } // left, lower and top faces -> now flow over these faces - if ((m_face->model_axis == "I-") || (m_face->model_axis == "J-") || - (m_face->model_axis == "K-")) + if ((m_face->model_axis == "I-") || (m_face->model_axis == "J-") || (m_face->model_axis == "K-")) m_face->v_norm = 0; - //m_face->Calculate_components_of_a_vector(1); + // m_face->Calculate_components_of_a_vector(1); // cout << " Face " << m_face->index << ", " << m_face->connected_elements[0]; - if(m_face->connected_elements.size() > 1) + if (m_face->connected_elements.size() > 1) cout << ", " << m_face->connected_elements[1]; - //cout << ": " << m_face->q_norm << "\n"; - //if(fabs(m_face->v_norm) > MKleinsteZahl) cout << " q/v: " << m_face->q_norm/m_face->face_area/0.5 /m_face->v_norm ; - //cout << "\n"; + // cout << ": " << m_face->q_norm << "\n"; + // if(fabs(m_face->v_norm) > MKleinsteZahl) cout << " q/v: " << m_face->q_norm/m_face->face_area/0.5 + // /m_face->v_norm ; + // cout << "\n"; } return true; } @@ -3293,34 +3138,33 @@ bool CECLIPSEData::CalcBlockBudget(int phase_index) double max_error = 0; // summ budget flow terms at feces for all blocks - for(unsigned i = 0; i < this->eclgrid.size(); i++) + for (unsigned i = 0; i < this->eclgrid.size(); i++) { m_block = this->eclgrid[i]; flow = flow_max = 0.0; - //cout << " Budget for block " << i << ": " << "\n" ; - for(unsigned int j = 0; j < m_block->connected_faces.size(); j++) + // cout << " Budget for block " << i << ": " << "\n" ; + for (unsigned int j = 0; j < m_block->connected_faces.size(); j++) { m_face = faces[m_block->connected_faces[j]]; flow_face = m_face->phases[phase_index]->q_norm * m_face->face_area; - //cout << "flow_face " << flow_face << "\n"; - if(fabs(flow_face) > flow_max) + // cout << "flow_face " << flow_face << "\n"; + if (fabs(flow_face) > flow_max) flow_max = fabs(flow_face); - if((j == 1) || (j == 3) || (j == 5)) // minus faces: -i, -j or -k + if ((j == 1) || (j == 3) || (j == 5)) // minus faces: -i, -j or -k flow_face *= -1.0; - //cout << " face " << m_face->index << ": " << flow_face << " ; " << "\n"; + // cout << " face " << m_face->index << ": " << flow_face << " ; " << "\n"; flow += flow_face; } - //cout << " total flow: " << flow << "\n"; - if((fabs(flow / flow_max) > 1.0e-3) && (fabs(flow) > 1.0e-10)) + // cout << " total flow: " << flow << "\n"; + if ((fabs(flow / flow_max) > 1.0e-3) && (fabs(flow) > 1.0e-10)) { if (max_error < abs(flow / flow_max)) max_error = abs(flow / flow_max); - cout << " Error in budget for block " << i << " : Sum_flow: " << flow << - ", max_flow : " << flow_max << ", rel_error: " << flow / flow_max << - ", max_error: " << max_error << "\n"; + cout << " Error in budget for block " << i << " : Sum_flow: " << flow << ", max_flow : " << flow_max + << ", rel_error: " << flow / flow_max << ", max_error: " << max_error << "\n"; } - //cout << " max_error: " << max_error << "\n"; - //if (max_error > 0.0043) + // cout << " max_error: " << max_error << "\n"; + // if (max_error > 0.0043) // cout << "\n"; } @@ -3334,24 +3178,24 @@ bool CECLIPSEData::CalcBlockBudget(int phase_index) Programming: XXX Modification: -------------------------------------------------------------------------*/ -//bool CECLIPSEData::MakeNodeVector(CRFProcess *m_pcs, std::string path, int timestep, int phase_index) +// bool CECLIPSEData::MakeNodeVector(CRFProcess *m_pcs, std::string path, int timestep, int phase_index) bool CECLIPSEData::MakeNodeVector(void) { - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt - //CFaces *m_face=NULL; - //WW double weights_xyz[3]; + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt + // CFaces *m_face=NULL; + // WW double weights_xyz[3]; CPointData_ECL* m_NodeData = NULL; m_NodeData = new CPointData_ECL; - vector temp_q; + vector temp_q; - //double coord_v_x[3] = {1.0,0.0,0.0}; - //double coord_v_y[3] = {0.0,1.0,0.0}; - //double coord_v_z[3] = {0.0,0.0,1.0}; - //double * normal_vec_face; - //double distance; - //double weight; - //double sum_weights; - //double val; + // double coord_v_x[3] = {1.0,0.0,0.0}; + // double coord_v_y[3] = {0.0,1.0,0.0}; + // double coord_v_z[3] = {0.0,0.0,1.0}; + // double * normal_vec_face; + // double distance; + // double weight; + // double sum_weights; + // double val; for (int i = 0; i < 3; i++) temp_q.push_back(-1.0E+99); @@ -3359,51 +3203,56 @@ bool CECLIPSEData::MakeNodeVector(void) /* Go through GeoSys mesh, and creates CPointData - then Nodes in CECLIPSEData::NodeData have the same order as in the Geosys mesh, and can be used directly for interpolation to gauss points*/ - //this->NodeData.clear(); - if(this->NodeData.size() < 1) + // this->NodeData.clear(); + if (this->NodeData.size() < 1) for (unsigned long i = 0; i < m_msh->nod_vector.size(); i++) { // create new instance of CPointData - m_NodeData = new CPointData_ECL (m_msh->nod_vector[i]->getData()); - //Get the node -// TF m_node = m_msh->nod_vector[i]; -// TF m_NodeData->x = m_node->X(); -// TF m_NodeData->y = m_node->Y(); -// TF m_NodeData->z = m_node->Z(); + m_NodeData = new CPointData_ECL(m_msh->nod_vector[i]->getData()); + // Get the node + // TF m_node = m_msh->nod_vector[i]; + // TF m_NodeData->x = m_node->X(); + // TF m_NodeData->y = m_node->Y(); + // TF m_NodeData->z = m_node->Z(); m_NodeData->phase_pressure.resize(3); m_NodeData->phase_saturation.resize(3); m_NodeData->phase_density.resize(3); - //for (int j = 0; j < int(this->Phases.size()); j++) + // for (int j = 0; j < int(this->Phases.size()); j++) // m_NodeData->q.push_back(temp_q); - //Set variable to zero + // Set variable to zero m_NodeData->pressure = -1.0E+99; m_NodeData->CO2inLiquid = -1.0E+99; m_NodeData->deltaDIC = -1.0E+99; for (long k = 0; k < 3; k++) { - //m_NodeData->Flow[k] = 0.0; + // m_NodeData->Flow[k] = 0.0; m_NodeData->phase_pressure[k] = -1.0E+99; m_NodeData->phase_saturation[k] = -1.0E+99; m_NodeData->phase_density[k] = -1.0E+99; - //WW weights_xyz[k] = 0.0; + // WW weights_xyz[k] = 0.0; } // transfer Data to node this->NodeData.push_back(m_NodeData); // Test output -// cout << " Node " << i << " (X,Y,Z): (" << m_NodeData->x << ", " << m_NodeData->y << ", "<< m_NodeData->z << ") "; -// for (long k = 0; k < 3; k++){ -// cout << m_NodeData->phase_density[k] << " " << m_NodeData->phase_pressure[k] << " " << m_NodeData->phase_saturation[k] << " "; -// } -// cout << "\n"; -// // Test output -// cout << " Node " << i << " (X,Y,Z): (" << this->NodeData[this->NodeData.size()-1]->x << ", " << this->NodeData[this->NodeData.size()-1]->y << ", "<< this->NodeData[this->NodeData.size()-1]->z << ") "; -// for (long k = 0; k < 3; k++){ -// cout << this->NodeData[this->NodeData.size()-1]->phase_density[k] << " " << this->NodeData[this->NodeData.size()-1]->phase_pressure[k] << " " << this->NodeData[this->NodeData.size()-1]->phase_saturation[k] << " "; -// } -// cout << "\n"; + // cout << " Node " << i << " (X,Y,Z): (" << m_NodeData->x << ", " << m_NodeData->y << ", "<< + // m_NodeData->z << ") "; + // for (long k = 0; k < 3; k++){ + // cout << m_NodeData->phase_density[k] << " " << m_NodeData->phase_pressure[k] << " " << + // m_NodeData->phase_saturation[k] << " "; + // } + // cout << "\n"; + // // Test output + // cout << " Node " << i << " (X,Y,Z): (" << this->NodeData[this->NodeData.size()-1]->x << ", " << + // this->NodeData[this->NodeData.size()-1]->y << ", "<< this->NodeData[this->NodeData.size()-1]->z << ") "; + // for (long k = 0; k < 3; k++){ + // cout << this->NodeData[this->NodeData.size()-1]->phase_density[k] << " " << + // this->NodeData[this->NodeData.size()-1]->phase_pressure[k] << " " << + // this->NodeData[this->NodeData.size()-1]->phase_saturation[k] << " "; + // } + // cout << "\n"; } else for (unsigned long i = 0; i < m_msh->nod_vector.size(); i++) @@ -3413,101 +3262,114 @@ bool CECLIPSEData::MakeNodeVector(void) this->NodeData[i]->CO2inLiquid = -1.0E+99; for (long k = 0; k < 3; k++) { - //this->NodeData[i]->Flow[k] = 0.0; + // this->NodeData[i]->Flow[k] = 0.0; this->NodeData[i]->phase_pressure[k] = -1.0E+99; this->NodeData[i]->phase_saturation[k] = -1.0E+99; this->NodeData[i]->phase_density[k] = -1.0E+99; } } -// for (unsigned long i = 0; i < m_msh->nod_vector.size(); i++) { -// // //Get the node -// m_NodeData = this->NodeData[i]; -// m_node = m_msh->nod_vector[i]; -// m_NodeData->x = m_node->X(); -// m_NodeData->y = m_node->Y(); -// m_NodeData->z = m_node->Z(); -// //sum_weights = 0; -// // sum the distance weighted data from each connected face -// for (unsigned int j = 0; j < m_node->connected_faces.size(); j++) { -// distance = weight = 0; -// m_face = this->faces[m_node->connected_faces[j]]; -// distance = m_node->distance_to_connected_faces[j]; -// //Weight of each face depending on distance -// weight = (1.0 / distance); -// // Sum of weights -// //sum_weights += weight; -// normal_vec_face = m_face->PlaneEquation->GetNormalVector(); -// // Go through all three coordinates x, y, z and check, if face is perpendicular to axis -// for (int k = 0; k < 3; k++){ -// if(k == 0) val = fabs(PointProduction(normal_vec_face,coord_v_x)); -// if(k == 1) val = fabs(PointProduction(normal_vec_face,coord_v_y)); -// if(k == 2) val = fabs(PointProduction(normal_vec_face,coord_v_z)); -// if(val > MKleinsteZahl){ // face not perpendicular to ccordinate axis k -// //m_NodeData->Flow[k] += m_face->phases[phase_index]->q[k] * weight; -// weights_xyz[k] += weight; -// //cout << " Node " << i << " contributed by face " << m_face->index << ", " << m_face->model_axis << " , " << m_face->q_norm << ": "; -// //for(int mm=0;mm<3;mm++) cout << m_face->q[mm] << ", "; -// //cout << "\n"; -// } -// } -// } -// -// // normalize weighted sum by sum_of_weights sum_w -// for (int k = 0; k < 3; k++) { -// // if(weights_xyz[k] > 0.0) -// ////m_NodeData->Flow[k] = m_NodeData->Flow[k] / weights_xyz[k]; -// // else{ -// ////m_NodeData->Flow[k] = m_NodeData->Flow[k]; -// //cout << " Warning - no faces for direction (I=0,J=1,K=2): " << k << " at node " << i << " with non-zero contributions! " << "\n"; -// // } -// } -// } -// // TEst Output -// std::string tempstring; -// ostringstream temp; -// vector vec_string; -// double v_geosys[3]; -// vec_string.push_back("Node; X; Y; Z; v_x_ECL; v_y_ECL; v_z_ECL; v_ECL; v_x_Geos; v_y_Geos; v_z_Geos; v_Geos"); -// -// for(unsigned long i=0; i< this->NodeData.size();i++){ -// m_NodeData = this->NodeData[i]; -// //cout << " NodeData["<< i << "]: (X,Y,Z): (" << m_NodeData->x << ", " << m_NodeData->y << ", " << m_NodeData->z << "): " ; -// tempstring=""; -// temp.str(""); temp.clear(); temp << i; tempstring = temp.str(); -// temp.str(""); temp.clear(); temp << m_NodeData->x; tempstring += "; " +temp.str(); -// temp.str(""); temp.clear(); temp << m_NodeData->y; tempstring += "; " + temp.str(); -// temp.str(""); temp.clear(); temp << m_NodeData->z; tempstring += "; " + temp.str(); -// for(int k=0;k< 3;k++) { -// //temp.str(""); temp.clear(); temp << m_NodeData->Flow[k]; tempstring += "; " + temp.str(); -// //cout << m_NodeData->Data_separated[k] << " "; -// } -// //cout << "\n"; -// //calculate v -//// temp.str(""); temp.clear(); temp << sqrt(pow(m_NodeData->Flow[0],2) + pow(m_NodeData->Flow[1],2) + pow(m_NodeData->Flow[2], 2)); tempstring += "; " + temp.str(); -// -// //get node velocity of geosys -// InterpolateGeosysVelocitiesToNodes(m_pcs, v_geosys, i); -// for(int k=0;k< 3;k++) { -// temp.str(""); temp.clear(); temp << v_geosys[k]; tempstring += "; " + temp.str(); -// } -// //calculate v -// temp.str(""); temp.clear(); temp << sqrt(pow(v_geosys[0], 2) + pow(v_geosys[1], 2) + pow(v_geosys[2], 2)); tempstring += "; " + temp.str(); -// //write string -// vec_string.push_back(tempstring); -// } -// int position = int(path.find_last_of("\\")); -// path = path.substr(0,position); -// position = int(path.find_last_of("\\")); -// path = path.substr(0,position); -// temp.str(""); temp.clear(); temp << timestep; tempstring = temp.str(); -// std::string aus_file = path + "\\CheckVelocityAtNodes_" + tempstring + ".csv"; -// ofstream aus; -// aus.open(aus_file.data(),ios::out); -// for (unsigned long i = 0; i < vec_string.size(); i++) { -// aus << vec_string[i] << "\n"; -// } -// aus.close(); + // for (unsigned long i = 0; i < m_msh->nod_vector.size(); i++) { + // // //Get the node + // m_NodeData = this->NodeData[i]; + // m_node = m_msh->nod_vector[i]; + // m_NodeData->x = m_node->X(); + // m_NodeData->y = m_node->Y(); + // m_NodeData->z = m_node->Z(); + // //sum_weights = 0; + // // sum the distance weighted data from each connected face + // for (unsigned int j = 0; j < m_node->connected_faces.size(); j++) { + // distance = weight = 0; + // m_face = this->faces[m_node->connected_faces[j]]; + // distance = m_node->distance_to_connected_faces[j]; + // //Weight of each face depending on distance + // weight = (1.0 / distance); + // // Sum of weights + // //sum_weights += weight; + // normal_vec_face = m_face->PlaneEquation->GetNormalVector(); + // // Go through all three coordinates x, y, z and check, if face is perpendicular to axis + // for (int k = 0; k < 3; k++){ + // if(k == 0) val = fabs(PointProduction(normal_vec_face,coord_v_x)); + // if(k == 1) val = fabs(PointProduction(normal_vec_face,coord_v_y)); + // if(k == 2) val = fabs(PointProduction(normal_vec_face,coord_v_z)); + // if(val > MKleinsteZahl){ // face not perpendicular to ccordinate axis k + // //m_NodeData->Flow[k] += m_face->phases[phase_index]->q[k] * weight; + // weights_xyz[k] += weight; + // //cout << " Node " << i << " contributed by face " << m_face->index << ", " << + // m_face->model_axis + //<< + //" , " << m_face->q_norm << ": "; + // //for(int mm=0;mm<3;mm++) cout << m_face->q[mm] << ", "; + // //cout << "\n"; + // } + // } + // } + // + // // normalize weighted sum by sum_of_weights sum_w + // for (int k = 0; k < 3; k++) { + // // if(weights_xyz[k] > 0.0) + // ////m_NodeData->Flow[k] = m_NodeData->Flow[k] / weights_xyz[k]; + // // else{ + // ////m_NodeData->Flow[k] = m_NodeData->Flow[k]; + // //cout << " Warning - no faces for direction (I=0,J=1,K=2): " << k << " at node " << i << " + // with + // non-zero contributions! " << "\n"; + // // } + // } + // } + // // TEst Output + // std::string tempstring; + // ostringstream temp; + // vector vec_string; + // double v_geosys[3]; + // vec_string.push_back("Node; X; Y; Z; v_x_ECL; v_y_ECL; v_z_ECL; v_ECL; v_x_Geos; v_y_Geos; v_z_Geos; + // v_Geos"); + // + // for(unsigned long i=0; i< this->NodeData.size();i++){ + // m_NodeData = this->NodeData[i]; + // //cout << " NodeData["<< i << "]: (X,Y,Z): (" << m_NodeData->x << ", " << m_NodeData->y << ", " + //<< + // m_NodeData->z << "): " ; + // tempstring=""; + // temp.str(""); temp.clear(); temp << i; tempstring = temp.str(); + // temp.str(""); temp.clear(); temp << m_NodeData->x; tempstring += "; " +temp.str(); + // temp.str(""); temp.clear(); temp << m_NodeData->y; tempstring += "; " + temp.str(); + // temp.str(""); temp.clear(); temp << m_NodeData->z; tempstring += "; " + temp.str(); + // for(int k=0;k< 3;k++) { + // //temp.str(""); temp.clear(); temp << m_NodeData->Flow[k]; tempstring += "; " + temp.str(); + // //cout << m_NodeData->Data_separated[k] << " "; + // } + // //cout << "\n"; + // //calculate v + //// temp.str(""); temp.clear(); temp << sqrt(pow(m_NodeData->Flow[0],2) + + /// pow(m_NodeData->Flow[1],2) + ///+ + /// pow(m_NodeData->Flow[2], 2)); tempstring += "; " + temp.str(); + // + // //get node velocity of geosys + // InterpolateGeosysVelocitiesToNodes(m_pcs, v_geosys, i); + // for(int k=0;k< 3;k++) { + // temp.str(""); temp.clear(); temp << v_geosys[k]; tempstring += "; " + temp.str(); + // } + // //calculate v + // temp.str(""); temp.clear(); temp << sqrt(pow(v_geosys[0], 2) + pow(v_geosys[1], 2) + + // pow(v_geosys[2], + // 2)); tempstring += "; " + temp.str(); + // //write string + // vec_string.push_back(tempstring); + // } + // int position = int(path.find_last_of("\\")); + // path = path.substr(0,position); + // position = int(path.find_last_of("\\")); + // path = path.substr(0,position); + // temp.str(""); temp.clear(); temp << timestep; tempstring = temp.str(); + // std::string aus_file = path + "\\CheckVelocityAtNodes_" + tempstring + ".csv"; + // ofstream aus; + // aus.open(aus_file.data(),ios::out); + // for (unsigned long i = 0; i < vec_string.size(); i++) { + // aus << vec_string[i] << "\n"; + // } + // aus.close(); return true; } @@ -3519,37 +3381,37 @@ bool CECLIPSEData::MakeNodeVector(void) Programming: 10/2009 BG / SB Modification: -------------------------------------------------------------------------*/ -void CECLIPSEData::InterpolateDataFromFacesToNodes(long ele_nr, - double* n_vel_x, - double* n_vel_y, - double* n_vel_z, +void CECLIPSEData::InterpolateDataFromFacesToNodes(long ele_nr, double* n_vel_x, double* n_vel_y, double* n_vel_z, int phase_index) { - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt MeshLib::CElem* m_ele = NULL; CFaces* m_face = NULL; MeshLib::CNode* m_node = NULL; double distance; double weight, weights_xyz[3]; - //double sum_weights; + // double sum_weights; double val = 0; - double coord_v_x[3] = {1.0,0.0,0.0}; - double coord_v_y[3] = {0.0,1.0,0.0}; - double coord_v_z[3] = {0.0,0.0,1.0}; + double coord_v_x[3] = {1.0, 0.0, 0.0}; + double coord_v_y[3] = {0.0, 1.0, 0.0}; + double coord_v_z[3] = {0.0, 0.0, 1.0}; double data_separated[3]; double* normal_vec_face; - Math_Group::vec nod_index(8); + Math_Group::vec nod_index(8); long nod_ind; bool choose; - int face_flag = 1; // option: 0...take all faces at one node, 1...take 2 faces: only the faces which belong to the element - //todo eingabeoption + int face_flag + = 1; // option: 0...take all faces at one node, 1...take 2 faces: only the faces which belong to the element + // todo eingabeoption - //cout << " InterpolateDataFromFacesToNodes " << "\n" << "\n"; + // cout << " InterpolateDataFromFacesToNodes " << "\n" << "\n"; /* Go through GeoSys mesh, and get each element (=Eclipse block). For each block, look at all corner points - (=Nodes) of the element, as phase velocities are needed there. For each node, look at all faces connected to the node. + (=Nodes) of the element, as phase velocities are needed there. For each node, look at all faces connected to the + node. From each face, get the flow accross the face, and make a weighted sum in the nodes. - Faces are not considered, if the are perpendicular to the flow direction, as they then would always contribute zero + Faces are not considered, if the are perpendicular to the flow direction, as they then would always contribute + zero Faces can be choosen with two options: - All faces at one node, then also information of phase velocities from outside the element considered is taken into account. @@ -3561,14 +3423,15 @@ void CECLIPSEData::InterpolateDataFromFacesToNodes(long ele_nr, m_ele = m_msh->ele_vector[ele_nr]; // get element m_ele->GetNodeIndeces(nod_index); // get node indexes of nodes on element - //if ((ele_nr == 646) || (ele_nr == 647) || (ele_nr == 648) || (ele_nr == 683) || (ele_nr == 684) || (ele_nr == 685) || (ele_nr == 720) || (ele_nr == 721) || (ele_nr == 722)) + // if ((ele_nr == 646) || (ele_nr == 647) || (ele_nr == 648) || (ele_nr == 683) || (ele_nr == 684) || (ele_nr == + // 685) || (ele_nr == 720) || (ele_nr == 721) || (ele_nr == 722)) // cout << "Zentrum" << "\n"; for (long i = 0; i < long(nod_index.Size()); i++) // go through list of connected nodes of the element - { //Get the connected node + { // Get the connected node nod_ind = nod_index[i]; m_node = m_msh->nod_vector[nod_ind]; // m_node = Knoten, der gerade behandelt wird--> siehe Koordinaten - //cout << " Get Node " << nod_ind << " on element " << ele_nr << "\n"; + // cout << " Get Node " << nod_ind << " on element " << ele_nr << "\n"; // Set variable to zero, initialization for (long k = 0; k < 3; k++) { @@ -3583,57 +3446,51 @@ void CECLIPSEData::InterpolateDataFromFacesToNodes(long ele_nr, m_face = this->faces[m_node->connected_faces[j]]; // Get face on node // Consider only if face is on element choose = false; - if(m_face->connected_elements[0] == ele_nr) - choose = true; //check if face is part of the element - if(m_face->connected_elements.size() > 1) - if(m_face->connected_elements[1] == ele_nr) + if (m_face->connected_elements[0] == ele_nr) + choose = true; // check if face is part of the element + if (m_face->connected_elements.size() > 1) + if (m_face->connected_elements[1] == ele_nr) choose = true; if (face_flag == 0) choose = true; // for radial flow model - if(this->Radial_I == true) + if (this->Radial_I == true) // skip all J faces - if(m_face->model_axis.find("J") == 0) + if (m_face->model_axis.find("J") == 0) choose = false; - if(this->Radial_J == true) + if (this->Radial_J == true) // skip all I faces - if(m_face->model_axis.find("I") == 0) + if (m_face->model_axis.find("I") == 0) choose = false; - if(choose) + if (choose) { - //Testoutput - //cout << "\n"; - //cout << " Node " << nod_ind << " contributed by face " << m_face->index << ", " << m_face->model_axis << " , " << m_face->phases[phase_index]->q_norm << ": "; - //for(int mm=0;mm<3;mm++) cout << m_face->phases[phase_index]->q[mm] << ", "; - //cout << "\n"; + // Testoutput + // cout << "\n"; + // cout << " Node " << nod_ind << " contributed by face " << m_face->index << ", " << m_face->model_axis + // << " , " << m_face->phases[phase_index]->q_norm << ": "; + // for(int mm=0;mm<3;mm++) cout << m_face->phases[phase_index]->q[mm] << ", "; + // cout << "\n"; distance = m_node->distance_to_connected_faces[j]; - //Weight of each face depending on distance + // Weight of each face depending on distance weight = (1.0 / distance); // Sum of weights - //sum_weights += weight; + // sum_weights += weight; normal_vec_face = m_face->PlaneEquation->GetNormalVector(); // Go through all three coordinates x, y, z and check, if face is perpendicular to axis for (int k = 0; k < 3; k++) { - if(k == 0) - val = - fabs(PointProduction(normal_vec_face, - coord_v_x)); - if(k == 1) - val = - fabs(PointProduction(normal_vec_face, - coord_v_y)); - if(k == 2) - val = - fabs(PointProduction(normal_vec_face, - coord_v_z)); - if(val > MKleinsteZahl) // face not perpendicular to ccordinate axis k + if (k == 0) + val = fabs(PointProduction(normal_vec_face, coord_v_x)); + if (k == 1) + val = fabs(PointProduction(normal_vec_face, coord_v_y)); + if (k == 2) + val = fabs(PointProduction(normal_vec_face, coord_v_z)); + if (val > MKleinsteZahl) // face not perpendicular to ccordinate axis k { - data_separated[k] += - m_face->phases[phase_index]->q[k] * weight; + data_separated[k] += m_face->phases[phase_index]->q[k] * weight; weights_xyz[k] += weight; } } @@ -3643,22 +3500,21 @@ void CECLIPSEData::InterpolateDataFromFacesToNodes(long ele_nr, // normalize weighted sum by sum_of_weights sum_w for (int k = 0; k < 3; k++) { - if(weights_xyz[k] > 0.0) + if (weights_xyz[k] > 0.0) data_separated[k] = data_separated[k] / weights_xyz[k]; else { data_separated[k] = data_separated[k]; - if((k == 1) && (this->Radial_I == true)) + if ((k == 1) && (this->Radial_I == true)) { - } // do nothing, Radial model perpendicular x axis + } // do nothing, Radial model perpendicular x axis else if ((k == 0) && (this->Radial_J == true)) { - } // do nothing, Radial model perpendicular y axis + } // do nothing, Radial model perpendicular y axis else - cout << - " Warning - no faces for direction (I=0,J=1,K=2): " << k << - " at node " << i << " with non-zero contributions! " << - "\n"; + cout << " Warning - no faces for direction (I=0,J=1,K=2): " << k << " at node " << i + << " with non-zero contributions! " + << "\n"; } } // transfer Data to node @@ -3666,14 +3522,16 @@ void CECLIPSEData::InterpolateDataFromFacesToNodes(long ele_nr, n_vel_y[i] = data_separated[1]; n_vel_z[i] = data_separated[2]; - //Test output - //cout << " Node " << nod_ind << " (X,Y,Z): (" << m_node->X() << ", " << m_node->Y() << ", "<< m_node->Z() << ") " ; - //cout << data_separated[0] << " " << data_separated[1] << " " << data_separated[2] << " " << "\n"; + // Test output + // cout << " Node " << nod_ind << " (X,Y,Z): (" << m_node->X() << ", " << m_node->Y() << ", "<< m_node->Z() << + // ") " ; + // cout << data_separated[0] << " " << data_separated[1] << " " << data_separated[2] << " " << "\n"; } // end loop connected nodes // Test Output - //for(long i=0; i< nod_index.Size();i++){ - // cout << " Node "<< nod_index[i] << ": (X,Y,Z): (" << m_msh->nod_vector[nod_index[i]]->X() << ", " << m_msh->nod_vector[nod_index[i]]->Y() << ", "<< m_msh->nod_vector[nod_index[i]]->Z() << "): " ; + // for(long i=0; i< nod_index.Size();i++){ + // cout << " Node "<< nod_index[i] << ": (X,Y,Z): (" << m_msh->nod_vector[nod_index[i]]->X() << ", " << + // m_msh->nod_vector[nod_index[i]]->Y() << ", "<< m_msh->nod_vector[nod_index[i]]->Z() << "): " ; // cout << n_vel_x[i] << " " << n_vel_y[i] << " " << n_vel_z[i] << " " << "\n"; //}/* */ } @@ -3685,44 +3543,43 @@ void CECLIPSEData::InterpolateDataFromFacesToNodes(long ele_nr, Programming: 10/2009 SB Modification: -------------------------------------------------------------------------*/ -void CECLIPSEData::InterpolateDataFromBlocksToNodes(CRFProcess* m_pcs, - std::string path, - int phase_index) +void CECLIPSEData::InterpolateDataFromBlocksToNodes(CRFProcess* m_pcs, std::string path, int phase_index) { (void)path; // unused - clock_t start,finish; + clock_t start, finish; double time; - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt CECLIPSEBlock* m_block = NULL; MeshLib::CNode* m_node = NULL; - //CFaces *m_face=NULL; - //WW double distance; + // CFaces *m_face=NULL; + // WW double distance; double volume; double weight; - //double weights_xyz[3]; + // double weights_xyz[3]; double sum_weights, sum_weights_density; - //WW double pressure, + // WW double pressure, double saturation, sat, phase_pressure, phase_press, gas_dissolved, gas_dis; double vapor_component_mass_fraction, vap_comp_mass_frac; // SB redo WTP double den, density; - //double press; - //double velocity_x1, velo_x1, velocity_y1, velo_y1, velocity_z1, velo_z1; + // double press; + // double velocity_x1, velo_x1, velocity_y1, velo_y1, velocity_z1, velo_z1; CPointData_ECL* m_NodeData = NULL; - //m_NodeData = new CPointData; - // WW long variable_index_pressure = -1, variable_index_phase_pressure = -1, variable_index_saturation = -1, time_index = 0, variable_index_Gas_dissolved = -1, variable_index_Gas_density = -1, variable_index_Water_density = -1, variable_index_Oil_density = -1; - long variable_index_phase_pressure = -1, variable_index_saturation = -1, - variable_index_Gas_dissolved = -1, variable_index_Gas_density = -1, - variable_index_Water_density = -1, variable_index_Oil_density = -1, - variable_index_vapor_mass_fraction = -1; // SB redo wtp - //long variable_index_velocity_x1, variable_index_velocity_y1, variable_index_velocity_z1; + // m_NodeData = new CPointData; + // WW long variable_index_pressure = -1, variable_index_phase_pressure = -1, variable_index_saturation = -1, + // time_index = 0, variable_index_Gas_dissolved = -1, variable_index_Gas_density = -1, variable_index_Water_density + // = -1, variable_index_Oil_density = -1; + long variable_index_phase_pressure = -1, variable_index_saturation = -1, variable_index_Gas_dissolved = -1, + variable_index_Gas_density = -1, variable_index_Water_density = -1, variable_index_Oil_density = -1, + variable_index_vapor_mass_fraction = -1; // SB redo wtp + // long variable_index_velocity_x1, variable_index_velocity_y1, variable_index_velocity_z1; start = clock(); cout << " InterpolateDataFromBlocksToNodes()"; - //WW variable_index_pressure = this->GetVariableIndex("PRESSURE"); + // WW variable_index_pressure = this->GetVariableIndex("PRESSURE"); - //get saturation index if there are more than 1 phases + // get saturation index if there are more than 1 phases if (this->Phases[phase_index] == "WATER") { if (int(this->Phases.size()) > 1) @@ -3756,34 +3613,33 @@ void CECLIPSEData::InterpolateDataFromBlocksToNodes(CRFProcess* m_pcs, { variable_index_Gas_dissolved = this->GetVariableIndex("RS"); if (this->E100 == true) - variable_index_Gas_density = this->GetVariableIndex( - "GAS_DEN"); + variable_index_Gas_density = this->GetVariableIndex("GAS_DEN"); else - variable_index_Gas_density = this->GetVariableIndex( - "DENG"); + variable_index_Gas_density = this->GetVariableIndex("DENG"); } - //KB Vapor component mass fraction, redo wtp - if (int(this->GetVariableIndex("YFW2")) >= 0){ + // KB Vapor component mass fraction, redo wtp + if (int(this->GetVariableIndex("YFW2")) >= 0) + { variable_index_vapor_mass_fraction = this->GetVariableIndex("YFW2"); - } } else { - cout << "This phase is not considered yet!" << "\n"; - //system("Pause"); + cout << "This phase is not considered yet!" + << "\n"; + // system("Pause"); exit(0); } } } - //WW time_index = 0; + // WW time_index = 0; for (unsigned long i = 0; i < m_msh->nod_vector.size(); i++) { - //Get the node + // Get the node m_node = m_msh->nod_vector[i]; - //WW pressure = 0.0; + // WW pressure = 0.0; phase_pressure = 0.0; saturation = 0.0; sum_weights = 0.0; @@ -3795,20 +3651,20 @@ void CECLIPSEData::InterpolateDataFromBlocksToNodes(CRFProcess* m_pcs, // sum the distance weighted data from each connected block for (unsigned int j = 0; j < m_node->getConnectedElementIDs().size(); j++) { - //WW distance = 0.0; + // WW distance = 0.0; weight = 0.0; - m_block = this->eclgrid[m_node->getConnectedElementIDs()[j]]; + m_block = this->eclgrid[m_node->getConnectedElementIDs()[j]]; - //calculate representive volume of the considered node in each connected element for weighting + // calculate representive volume of the considered node in each connected element for weighting volume = m_block->volume / 8.0; // ToDo volume weighting doesn't work if element is not simple!!!!!!!!! BG weight = (1.0 / volume); // Sum of weights sum_weights += weight; - //Pressure - //press = this->Data[m_block->index][variable_index_pressure]; - //pressure += press * weight; - //Phase pressure + // Pressure + // press = this->Data[m_block->index][variable_index_pressure]; + // pressure += press * weight; + // Phase pressure phase_press = this->Data[m_block->index][variable_index_phase_pressure]; phase_pressure += phase_press * weight; @@ -3819,7 +3675,7 @@ void CECLIPSEData::InterpolateDataFromBlocksToNodes(CRFProcess* m_pcs, saturation += sat * weight; } - //dissolved gas + // dissolved gas if (variable_index_Gas_dissolved > -1) { gas_dis = this->Data[m_block->index][variable_index_Gas_dissolved]; @@ -3832,9 +3688,10 @@ void CECLIPSEData::InterpolateDataFromBlocksToNodes(CRFProcess* m_pcs, } } // KB total molare density , redo wtp - if (variable_index_vapor_mass_fraction > -1) { + if (variable_index_vapor_mass_fraction > -1) + { vap_comp_mass_frac = this->Data[m_block->index][variable_index_vapor_mass_fraction]; - vapor_component_mass_fraction += vap_comp_mass_frac *weight; + vapor_component_mass_fraction += vap_comp_mass_frac * weight; } if (variable_index_Water_density > -1) @@ -3857,22 +3714,25 @@ void CECLIPSEData::InterpolateDataFromBlocksToNodes(CRFProcess* m_pcs, } // Test output - //if ((m_block->z_barycentre == -2001.8)) { + // if ((m_block->z_barycentre == -2001.8)) { // //cout << " Node " << i << "\n"; - // //cout << " : connected block: " << m_node->connected_elements[j] << " (X,Y,Z): " << m_block->x_barycentre << ", " << m_block->y_barycentre << ", " << m_block->z_barycentre << " with saturation " << sat; - // //cout << " distance: " << distance << " weight: " << weight << " sum of weights: " << sum_weights << "\n"; - // cout << " Node " << i << " Element: " << m_node->connected_elements[j] << " SGAS: " << sat << "\n"; + // //cout << " : connected block: " << m_node->connected_elements[j] << " (X,Y,Z): " << + // m_block->x_barycentre << ", " << m_block->y_barycentre << ", " << m_block->z_barycentre << " with + // saturation " << sat; + // //cout << " distance: " << distance << " weight: " << weight << " sum of weights: " << sum_weights << + //"\n"; + // cout << " Node " << i << " Element: " << m_node->connected_elements[j] << " SGAS: " << sat << + //"\n"; //} } // for j=connected_elements - //pressure = pressure / sum_weights; - //this->NodeData[i]->pressure = pressure; + // pressure = pressure / sum_weights; + // this->NodeData[i]->pressure = pressure; phase_pressure = phase_pressure / sum_weights; this->NodeData[i]->phase_pressure[phase_index] = phase_pressure; this->NodeData[i]->pressure = phase_pressure; // the last phase pressure is the highest pressure - if (int(this->Phases.size()) > 1) { saturation = saturation / sum_weights; @@ -3880,19 +3740,20 @@ void CECLIPSEData::InterpolateDataFromBlocksToNodes(CRFProcess* m_pcs, this->NodeData[i]->phase_saturation[phase_index] = saturation; else { - cout << "The saturation is not between 0 and 1!" << "\n"; + cout << "The saturation is not between 0 and 1!" + << "\n"; if (saturation < 0.0) this->NodeData[i]->phase_saturation[phase_index] = 0.0; if (saturation > 1.0) this->NodeData[i]->phase_saturation[phase_index] = 1.0; } } - //density + // density if (sum_weights_density > 0) density = density / sum_weights_density; this->NodeData[i]->phase_density[phase_index] = density; - //dissolved gas in oil (black oil mode) + // dissolved gas in oil (black oil mode) if (variable_index_Gas_dissolved > -1) { gas_dissolved = gas_dissolved / sum_weights; @@ -3900,25 +3761,30 @@ void CECLIPSEData::InterpolateDataFromBlocksToNodes(CRFProcess* m_pcs, } // KB total molare density, redo wtp - if (variable_index_vapor_mass_fraction > -1){ + if (variable_index_vapor_mass_fraction > -1) + { vapor_component_mass_fraction = vapor_component_mass_fraction / sum_weights; this->NodeData[i]->VaporComponentMassFraction = vapor_component_mass_fraction; } - - //Test output - //if ((m_block->z_barycentre == -2001.8)) { - // //cout << " Node " << i << " (X,Y,Z): (" << m_node->X() << ", " << m_node->Y() << ", "<< m_node->X() << ") "; + // Test output + // if ((m_block->z_barycentre == -2001.8)) { + // //cout << " Node " << i << " (X,Y,Z): (" << m_node->X() << ", " << m_node->Y() << ", "<< m_node->X() << ") + //"; // //cout << " Pressure at Node " << this->NodeData[i]->pressure << "\n"; - // //cout << " Node " << i << " (X,Y,Z): (" << m_node->X() << ", " << m_node->Y() << ", "<< m_node->X() << ") "; + // //cout << " Node " << i << " (X,Y,Z): (" << m_node->X() << ", " << m_node->Y() << ", "<< m_node->X() << ") + //"; // //cout << " Saturation at Node " << this->NodeData[i]->phase_saturation[phase_index] << "\n"; // cout << " Node " << i << " SGAS: " << this->NodeData[i]->phase_saturation[phase_index] << "\n"; //} } // Test Output Nodes - //if ((m_pcs->Tim->step_current==0) || (m_pcs->Tim->step_current==1) || (m_pcs->Tim->step_current==2) || (m_pcs->Tim->step_current==5) || (m_pcs->Tim->step_current==10) || (m_pcs->Tim->step_current==20) || (m_pcs->Tim->step_current==30) || (m_pcs->Tim->step_current==40) || (m_pcs->Tim->step_current==50) || (m_pcs->Tim->step_current==100) || (m_pcs->Tim->step_current==999) || (m_pcs->Tim->step_current==1000)) { - vector vec_string; + // if ((m_pcs->Tim->step_current==0) || (m_pcs->Tim->step_current==1) || (m_pcs->Tim->step_current==2) || + // (m_pcs->Tim->step_current==5) || (m_pcs->Tim->step_current==10) || (m_pcs->Tim->step_current==20) || + // (m_pcs->Tim->step_current==30) || (m_pcs->Tim->step_current==40) || (m_pcs->Tim->step_current==50) || + // (m_pcs->Tim->step_current==100) || (m_pcs->Tim->step_current==999) || (m_pcs->Tim->step_current==1000)) { + vector vec_string; std::string tempstring; ostringstream temp; double Val; @@ -3926,13 +3792,14 @@ void CECLIPSEData::InterpolateDataFromBlocksToNodes(CRFProcess* m_pcs, { int nidx1 = m_pcs->GetNodeValueIndex("PRESSURE1") + 1; //+1... new time level vec_string.push_back("Node; X; Y; Z; P-Geosys; P-Eclipse"); - for(unsigned long i = 0; i < this->NodeData.size(); i++) + for (unsigned long i = 0; i < this->NodeData.size(); i++) { m_NodeData = this->NodeData[i]; - //Get the Pressure from the Geosys run + // Get the Pressure from the Geosys run Val = m_pcs->GetNodeValue(i, nidx1); - //cout << " NodeData[" << i << "]: (X,Y,Z): (" << m_NodeData->x << ", " << m_NodeData->y << ", " << m_NodeData->z << "): " ; - //cout << ", Geosys-P: " << Val << ", Eclipse: " << this->NodeData[i]->pressure << "\n";; + // cout << " NodeData[" << i << "]: (X,Y,Z): (" << m_NodeData->x << ", " << m_NodeData->y << ", " << + // m_NodeData->z << "): " ; + // cout << ", Geosys-P: " << Val << ", Eclipse: " << this->NodeData[i]->pressure << "\n";; temp.str(""); temp.clear(); temp << i; @@ -3968,14 +3835,17 @@ void CECLIPSEData::InterpolateDataFromBlocksToNodes(CRFProcess* m_pcs, int nidx1 = m_pcs->GetNodeValueIndex("PRESSURE1") + 1; //+1... new time level int nidx2 = m_pcs->GetNodeValueIndex("PRESSURE2") + 1; int nidx3 = m_pcs->GetNodeValueIndex("SATURATION1") + 1; - //vec_string.push_back("Node; X; Y; Z; P-Geosys_phase1; P-Geosys_phase2; Saturation_Geosys_phase1; P-Eclipse_phase1; P-Eclipse_phase2; Saturation_Eclipse_phase1"); + // vec_string.push_back("Node; X; Y; Z; P-Geosys_phase1; P-Geosys_phase2; Saturation_Geosys_phase1; + // P-Eclipse_phase1; P-Eclipse_phase2; Saturation_Eclipse_phase1"); vec_string.push_back( - "Node; X; Y; Z; P-Geosys_phase1; P-Geosys_phase2; Saturation_Geosys_phase1; P-Eclipse_phase1; P-Eclipse_phase2; Saturation_Eclipse_phase1; q_x1; q_y1; q_z1; q_x2; q_y2; q_z2"); - for(unsigned long i = 0; i < this->NodeData.size(); i++) + "Node; X; Y; Z; P-Geosys_phase1; P-Geosys_phase2; Saturation_Geosys_phase1; P-Eclipse_phase1; " + "P-Eclipse_phase2; Saturation_Eclipse_phase1; q_x1; q_y1; q_z1; q_x2; q_y2; q_z2"); + for (unsigned long i = 0; i < this->NodeData.size(); i++) { m_NodeData = this->NodeData[i]; - //cout << " NodeData[" << i << "]: (X,Y,Z): (" << m_NodeData->x << ", " << m_NodeData->y << ", " << m_NodeData->z << "): " ; - //cout << ", Geosys-P: " << Val << ", Eclipse: " << this->NodeData[i]->pressure << "\n";; + // cout << " NodeData[" << i << "]: (X,Y,Z): (" << m_NodeData->x << ", " << m_NodeData->y << ", " << + // m_NodeData->z << "): " ; + // cout << ", Geosys-P: " << Val << ", Eclipse: " << this->NodeData[i]->pressure << "\n";; temp.str(""); temp.clear(); temp << i; @@ -3993,21 +3863,21 @@ void CECLIPSEData::InterpolateDataFromBlocksToNodes(CRFProcess* m_pcs, temp << m_NodeData->z; tempstring += "; " + temp.str(); - //Get the Pressure1 from the Geosys run + // Get the Pressure1 from the Geosys run Val = m_pcs->GetNodeValue(i, nidx1); temp.str(""); temp.clear(); temp.precision(12); temp << Val; tempstring += "; " + temp.str(); - //Get the Pressure2 from the Geosys run + // Get the Pressure2 from the Geosys run Val = m_pcs->GetNodeValue(i, nidx2); temp.str(""); temp.clear(); temp.precision(12); temp << Val; tempstring += "; " + temp.str(); - //Get the Saturation1 from the Geosys run + // Get the Saturation1 from the Geosys run Val = m_pcs->GetNodeValue(i, nidx3); temp.str(""); temp.clear(); @@ -4015,7 +3885,7 @@ void CECLIPSEData::InterpolateDataFromBlocksToNodes(CRFProcess* m_pcs, temp << Val; tempstring += "; " + temp.str(); - //Eclipse data + // Eclipse data temp.str(""); temp.clear(); temp.precision(12); @@ -4033,31 +3903,38 @@ void CECLIPSEData::InterpolateDataFromBlocksToNodes(CRFProcess* m_pcs, tempstring += "; " + temp.str(); ////Velocities - //temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->q[0][0]; tempstring += "; " + temp.str(); - //temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->q[0][1]; tempstring += "; " + temp.str(); - //temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->q[0][2]; tempstring += "; " + temp.str(); - //temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->q[1][0]; tempstring += "; " + temp.str(); - //temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->q[1][1]; tempstring += "; " + temp.str(); - //temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->q[1][2]; tempstring += "; " + temp.str(); + // temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->q[0][0]; tempstring += "; + // " + temp.str(); + // temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->q[0][1]; tempstring += "; + // " + temp.str(); + // temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->q[0][2]; tempstring += "; + // " + temp.str(); + // temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->q[1][0]; tempstring += "; + // " + temp.str(); + // temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->q[1][1]; tempstring += "; + // " + temp.str(); + // temp.str(""); temp.clear(); temp.precision(12); temp << this->NodeData[i]->q[1][2]; tempstring += "; + // " + temp.str(); vec_string.push_back(tempstring); } } - //CWriteTextfiles *TextFile; - //TextFile = new CWriteTextfiles; - //int position = int(path.find_last_of("\\")); - //std::string path_new; - //path_new = path.substr(0,position); - //position = int(path_new.find_last_of("\\")); - //path_new = path_new.substr(0,position); - //temp.str(""); temp.clear(); temp << m_pcs->Tim->step_current; tempstring = temp.str(); - //TextFile->Write_Text(path_new + "\\CheckNodeValues_" + tempstring + ".csv", vec_string); + // CWriteTextfiles *TextFile; + // TextFile = new CWriteTextfiles; + // int position = int(path.find_last_of("\\")); + // std::string path_new; + // path_new = path.substr(0,position); + // position = int(path_new.find_last_of("\\")); + // path_new = path_new.substr(0,position); + // temp.str(""); temp.clear(); temp << m_pcs->Tim->step_current; tempstring = temp.str(); + // TextFile->Write_Text(path_new + "\\CheckNodeValues_" + tempstring + ".csv", vec_string); //} // End Test Output finish = clock(); time = (double(finish) - double(start)) / CLOCKS_PER_SEC; - cout << " Time: " << time << " seconds." << "\n"; + cout << " Time: " << time << " seconds." + << "\n"; } /*------------------------------------------------------------------------- @@ -4075,14 +3952,14 @@ void CECLIPSEData::InterpolateDataFromBlocksToNodes(CRFProcess* m_pcs, -------------------------------------------------------------------------*/ void CECLIPSEData::InterpolateGeosysVelocitiesToNodes(CRFProcess* m_pcs, double* vel_nod, long node_number) { - CFEMesh const* const mesh = fem_msh_vector[0]; //SB: ToDo hart gesetzt + CFEMesh const* const mesh = fem_msh_vector[0]; // SB: ToDo hart gesetzt size_t elem; double vel_ele[3]; - double distance, weight, sum_w (0.0); - double PoreVel(0.0); //WW , theta; + double distance, weight, sum_w(0.0); + double PoreVel(0.0); // WW , theta; - //double *vel_nod; - //WW theta = m_pcs->m_num->ls_theta; + // double *vel_nod; + // WW theta = m_pcs->m_num->ls_theta; // initialize data structures for (size_t i = 0; i < 3; i++) @@ -4090,7 +3967,7 @@ void CECLIPSEData::InterpolateGeosysVelocitiesToNodes(CRFProcess* m_pcs, double* // Get node coordinates MeshLib::CNode const* node(mesh->nod_vector[node_number]); - double const* const coord(node->getData()); //Coordinates(coord); + double const* const coord(node->getData()); // Coordinates(coord); // get the indices of velocity of flow process long idxVx = m_pcs->GetElementValueIndex("VELOCITY1_X") + 1; long idxVy = m_pcs->GetElementValueIndex("VELOCITY1_Y") + 1; @@ -4112,7 +3989,7 @@ void CECLIPSEData::InterpolateGeosysVelocitiesToNodes(CRFProcess* m_pcs, double* // calculate distance node <-> element center of gravity double const* grav_c(mesh->ele_vector[elem]->GetGravityCenter()); for (size_t i = 0; i < 3; i++) - distance += (coord[i] - grav_c[i]) * (coord[i] - grav_c[i]); // TF pow((coord[i]-grav_c[i]),2); + distance += (coord[i] - grav_c[i]) * (coord[i] - grav_c[i]); // TF pow((coord[i]-grav_c[i]),2); // linear inverse distance weight = 1/(distance) distance = sqrt(distance); // for quadratic interpolation uncomment this line weight = (1 / distance); @@ -4127,7 +4004,7 @@ void CECLIPSEData::InterpolateGeosysVelocitiesToNodes(CRFProcess* m_pcs, double* vel_nod[i] *= sum_w_inv; // absolute value of velocity vector for (size_t i = 0; i < 3; i++) - PoreVel += vel_nod[i] * vel_nod[i]; // TF pow(vel_nod[i],2); + PoreVel += vel_nod[i] * vel_nod[i]; // TF pow(vel_nod[i],2); PoreVel = sqrt(PoreVel); } @@ -4140,34 +4017,35 @@ void CECLIPSEData::InterpolateGeosysVelocitiesToNodes(CRFProcess* m_pcs, double* -------------------------------------------------------------------------*/ void CECLIPSEData::WriteDataToGeoSys(CRFProcess* m_pcs, std::string path) { - //Datenuebergabe: pressure, saturation (ev. kf, n) + // Datenuebergabe: pressure, saturation (ev. kf, n) long index_pressure1, index_pressure2, index_saturation1, index_water_density, - index_gas_density;// WTP index_temperature1; - //long index_saturation2, index_gas_density; + index_gas_density; // WTP index_temperature1; + // long index_saturation2, index_gas_density; int phase1, phase2, transportphase = 0; // SB redo wtp double value = 0.0, value_gas = 0.0; // SB redo wtp - //double saturation_w, + // double saturation_w, double porosity = 0.1; // SB redo wtp - //double Molweight_CO2; + // double Molweight_CO2; // Sb redo wtp - // CB_merge_0513 - REACTINT *m_rei = NULL; - if(REACTINT_vec.size()>0) - m_rei = REACTINT_vec[0]; + // CB_merge_0513 + REACTINT* m_rei = NULL; + if (REACTINT_vec.size() > 0) + m_rei = REACTINT_vec[0]; - //WTP_CB: get no of nodes in mesh + // WTP_CB: get no of nodes in mesh long nnodes = fem_msh_vector[0]->GetNodesNumber(false); // Pressure 1 is the wetting phase, Pressure 2 the non wetting phase - //Pressure + // Pressure if (int(this->Phases.size()) == 1) { index_pressure1 = m_pcs->GetNodeValueIndex("PRESSURE1") + 1; //+1... new time level - index_water_density = m_pcs->GetNodeValueIndex("DENSITY1"); //DENSITY1 is not a variable for some flow process, e.g. LIQUID_FLOW - //WTP_CB: new way to get the total number of nodes in the mesh since nod_val_vector is not suitable anymore - //for(unsigned long i = 0; i < m_pcs->nod_val_vector.size(); i++) - for(long i = 0; i < nnodes; i++) + index_water_density = m_pcs->GetNodeValueIndex( + "DENSITY1"); // DENSITY1 is not a variable for some flow process, e.g. LIQUID_FLOW + // WTP_CB: new way to get the total number of nodes in the mesh since nod_val_vector is not suitable anymore + // for(unsigned long i = 0; i < m_pcs->nod_val_vector.size(); i++) + for (long i = 0; i < nnodes; i++) { value = this->NodeData[i]->pressure; m_pcs->SetNodeValue(i, index_pressure1, value); @@ -4177,31 +4055,31 @@ void CECLIPSEData::WriteDataToGeoSys(CRFProcess* m_pcs, std::string path) } else if (int(this->Phases.size()) > 1) { - if ((this->Phases[0] == "WATER") && (this->Phases[1] == "GAS") && - (this->E100 == true)) + if ((this->Phases[0] == "WATER") && (this->Phases[1] == "GAS") && (this->E100 == true)) { - cout << - "GAS-WATER System can not be considered with ECLIPSE E100 and GeoSys" << - "\n"; - //system("Pause"); + cout << "GAS-WATER System can not be considered with ECLIPSE E100 and GeoSys" + << "\n"; + // system("Pause"); exit(0); } - switch(int(this->Phases.size())) + switch (int(this->Phases.size())) { - case 2: - phase1 = 0; - phase2 = 1; - break; - case 3: - // Assumption that there are 3 phases but water is only used for the boundaries -> the oil and gas phase are the relevant one for the exchange with OGS - phase1 = 1; - phase2 = 2; - break; - default: - cout << "There are not more than 3 phases possible!" << "\n"; - //system("Pause"); - exit(0); - break; + case 2: + phase1 = 0; + phase2 = 1; + break; + case 3: + // Assumption that there are 3 phases but water is only used for the boundaries -> the oil and gas phase + // are the relevant one for the exchange with OGS + phase1 = 1; + phase2 = 2; + break; + default: + cout << "There are not more than 3 phases possible!" + << "\n"; + // system("Pause"); + exit(0); + break; } index_pressure1 = m_pcs->GetNodeValueIndex("PRESSURE1") + 1; //+1... new time level index_pressure2 = m_pcs->GetNodeValueIndex("PRESSURE2") + 1; //+1... new time level @@ -4210,349 +4088,371 @@ void CECLIPSEData::WriteDataToGeoSys(CRFProcess* m_pcs, std::string path) index_gas_density = m_pcs->GetNodeValueIndex("DENSITY2"); // WTP: getting the index for the temperature coupling, // what is with 1 Phase Flow?, what with Dens coupling? - //index_temperature1 = m_pcs->GetNodeValueIndex("TEMPERATURE1") + 1; - + // index_temperature1 = m_pcs->GetNodeValueIndex("TEMPERATURE1") + 1; - //WTP_CB: new way to get the total number of nodes in the mesh since nod_val_vector is not suitable anymore - //for(unsigned long i = 0; i < m_pcs->nod_val_vector.size(); i++) - for(long i = 0; i < nnodes; i++) + // WTP_CB: new way to get the total number of nodes in the mesh since nod_val_vector is not suitable anymore + // for(unsigned long i = 0; i < m_pcs->nod_val_vector.size(); i++) + for (long i = 0; i < nnodes; i++) { - //if ((this->NodeData[i]->x == 499.85001) && (this->NodeData[i]->y == 599.84998) && (this->NodeData[i]->z == -2875)) + // if ((this->NodeData[i]->x == 499.85001) && (this->NodeData[i]->y == 599.84998) && (this->NodeData[i]->z + // == -2875)) // cout << "Punkt 44" << "\n"; - //calculating capillary pressure (difference of the two phase pressures) - //cout << " Node " << i << " (X,Y,Z): (" << this->NodeData[i]->x << ", " << this->NodeData[i]->y << ", "<< this->NodeData[i]->z << ") "; - //for (long k = 0; k < 3; k++){ - // cout << this->NodeData[i]->phase_density[k] << " " << this->NodeData[i]->phase_pressure[k] << " " << this->NodeData[i]->phase_saturation[k] << " "; + // calculating capillary pressure (difference of the two phase pressures) + // cout << " Node " << i << " (X,Y,Z): (" << this->NodeData[i]->x << ", " << this->NodeData[i]->y << ", "<< + // this->NodeData[i]->z << ") "; + // for (long k = 0; k < 3; k++){ + // cout << this->NodeData[i]->phase_density[k] << " " << this->NodeData[i]->phase_pressure[k] << " " << + // this->NodeData[i]->phase_saturation[k] << " "; //} - //cout << "\n"; + // cout << "\n"; - value = this->NodeData[i]->phase_pressure[phase2] - - this->NodeData[i]->phase_pressure[phase1]; + value = this->NodeData[i]->phase_pressure[phase2] - this->NodeData[i]->phase_pressure[phase1]; m_pcs->SetNodeValue(i, index_pressure1, value); value = this->NodeData[i]->phase_pressure[phase2]; m_pcs->SetNodeValue(i, index_pressure2, value); value = this->NodeData[i]->phase_density[phase1]; - if(index_water_density > 0) + if (index_water_density > 0) m_pcs->SetNodeValue(i, index_water_density, value); value = this->NodeData[i]->phase_density[phase2]; - if(index_gas_density > 0) + if (index_gas_density > 0) m_pcs->SetNodeValue(i, index_gas_density, value); //// WTP: Saving the temperature data - //value = this->NodeData[i]->temperature; - //m_pcs->SetNodeValue(i, index_temperature1, value); + // value = this->NodeData[i]->temperature; + // m_pcs->SetNodeValue(i, index_temperature1, value); if (this->Phases.size() < 3) { - //Saturation 1 is the wetting phase + // Saturation 1 is the wetting phase value = this->NodeData[i]->phase_saturation[phase1]; - //cout << " Node: " << i << " saturation1: " << value << "\n"; + // cout << " Node: " << i << " saturation1: " << value << "\n"; m_pcs->SetNodeValue(i, index_saturation1, value); } else { - // the water phase is only used for boundary conditions, the wetting phase is phase 2 and the non-wetting phase is phase 3 + // the water phase is only used for boundary conditions, the wetting phase is phase 2 and the + // non-wetting phase is phase 3 value = 1 - this->NodeData[i]->phase_saturation[phase2]; - //cout << " Node: " << i << " saturation1: " << value << "\n"; + // cout << " Node: " << i << " saturation1: " << value << "\n"; m_pcs->SetNodeValue(i, index_saturation1, value); } - //transfer the gas density - //if (this->GetVariableIndex("RS") >= 0) { + // transfer the gas density + // if (this->GetVariableIndex("RS") >= 0) { // value = this->NodeData[i]->phase_density[phase2]; // m_pcs->SetNodeValue(i, index_gas_density, value); //} } - //assign dissolved gas to GeoSys nodes + // assign dissolved gas to GeoSys nodes if (this->GetVariableIndex("RS") >= 0) { CRFProcess* n_pcs = NULL; int indexConcentration; if (this->ProcessIndex_CO2inLiquid == -1) - //DL check CO2 in liquid 2012.06.28 - for(int i = 0; i < int(pcs_vector.size()); i++) + // DL check CO2 in liquid 2012.06.28 + for (int i = 0; i < int(pcs_vector.size()); i++) { n_pcs = pcs_vector[i]; // identify your process and store idx of pcs-vector - //if ((n_pcs->nod_val_name_vector[0] == "C(4)") || + // if ((n_pcs->nod_val_name_vector[0] == "C(4)") || // (n_pcs->nod_val_name_vector[0] == "CO2_w")) // "C(4)"...Phreeqc, "CO2_w"...Chemapp - if(n_pcs->nod_val_name_vector[0] == this->dissolved_co2_pcs_name_ECL) //SB redo wtp + if (n_pcs->nod_val_name_vector[0] == this->dissolved_co2_pcs_name_ECL) // SB redo wtp this->ProcessIndex_CO2inLiquid = i; } if (this->ProcessIndex_CO2inLiquid == -1) { - cout << - "In the model exists dissolved gas but there is no dissolved C in water defined. Please ad the mass transport for immobile C(4) or CO2_w!" + cout << "In the model exists dissolved gas but there is no dissolved C in water defined. Please ad the " + "mass transport for immobile C(4) or CO2_w!" << "\n"; - //system("Pause"); // SB redo wtp + // system("Pause"); // SB redo wtp exit(0); } // get index of species concentration in nodevaluevector of this process - indexConcentration = - pcs_vector[this->ProcessIndex_CO2inLiquid]->GetNodeValueIndex( - pcs_vector[ - this - ->ProcessIndex_CO2inLiquid]-> - pcs_primary_function_name[0]) + 1; // +1: new timelevel - //WTP_CB: new way to get the total number of nodes in the mesh since nod_val_vector is not suitable anymore - //for(unsigned long i = 0; i < pcs_vector[this->ProcessIndex_CO2inLiquid]->nod_val_vector.size(); i++) - for(long i = 0; i < nnodes; i++) + indexConcentration = pcs_vector[this->ProcessIndex_CO2inLiquid]->GetNodeValueIndex( + pcs_vector[this->ProcessIndex_CO2inLiquid]->pcs_primary_function_name[0]) + + 1; // +1: new timelevel + // WTP_CB: new way to get the total number of nodes in the mesh since nod_val_vector is not suitable anymore + // for(unsigned long i = 0; i < pcs_vector[this->ProcessIndex_CO2inLiquid]->nod_val_vector.size(); i++) + for (long i = 0; i < nnodes; i++) { - //recalculate dissolve gas: c_CO2 [mol/m^3] = RS [m^3gas/m^3water] * gas_density[kg/m^3] / (Molweight_CO2 [g/mol] * 1e-3 [kg/g]) - //value = this->NodeData[i]->Gas_dissolved * this->NodeData[i]->phase_density[phase2] / Molweight_CO2; - value = this->NodeData[i]->CO2inLiquid * this->SurfaceCO2Density / - (Molweight_CO2 * 1e-3); - pcs_vector[this->ProcessIndex_CO2inLiquid]->SetNodeValue( - i, - indexConcentration, - value); + // recalculate dissolve gas: c_CO2 [mol/m^3] = RS [m^3gas/m^3water] * gas_density[kg/m^3] / + // (Molweight_CO2 [g/mol] * 1e-3 [kg/g]) + // value = this->NodeData[i]->Gas_dissolved * this->NodeData[i]->phase_density[phase2] / Molweight_CO2; + value = this->NodeData[i]->CO2inLiquid * this->SurfaceCO2Density / (Molweight_CO2 * 1e-3); + pcs_vector[this->ProcessIndex_CO2inLiquid]->SetNodeValue(i, indexConcentration, value); // CB_merge_0513 next statement?? - if(indexConcentration>0) - pcs_vector[this->ProcessIndex_CO2inLiquid]->SetNodeValue(i, indexConcentration-1, value); //2012.07.02 - //cout << "Node: " << i << " Druck: " << m_pcs->GetNodeValue(i, index_pressure2) << " RS: " << this->NodeData[i]->Gas_dissolved << " Dichte: " << this->SurfaceCO2Density << " C(4): " << value << "\n"; + if (indexConcentration > 0) + pcs_vector[this->ProcessIndex_CO2inLiquid]->SetNodeValue(i, indexConcentration - 1, + value); // 2012.07.02 + // cout << "Node: " << i << " Druck: " << m_pcs->GetNodeValue(i, index_pressure2) << " RS: " << + // this->NodeData[i]->Gas_dissolved << " Dichte: " << this->SurfaceCO2Density << " C(4): " << value << + // "\n"; if (value < 0) { - cout << "Node: " << i << " Druck: " << m_pcs->GetNodeValue( - i, - index_pressure2) << " RS: " << - this->NodeData[i]->CO2inLiquid << " Dichte: " << - this->SurfaceCO2Density << " dissolved CO2: " << value << "\n"; + cout << "Node: " << i << " Druck: " << m_pcs->GetNodeValue(i, index_pressure2) + << " RS: " << this->NodeData[i]->CO2inLiquid << " Dichte: " << this->SurfaceCO2Density + << " dissolved CO2: " << value << "\n"; cout << " Fehler in Berechnung von DIC: " << value << "\n"; } } } - //KB: e300 calculate species concentration in the gas phase - if (this->GetVariableIndex("YFW2") >= 0) { - CRFProcess *n_pcs = NULL; + // KB: e300 calculate species concentration in the gas phase + if (this->GetVariableIndex("YFW2") >= 0) + { + CRFProcess* n_pcs = NULL; int indexConcentration_gas; - if (this->ProcessIndex_CO2inGas == -1) { - for(int i = 0; i < int(pcs_vector.size()); i++) { + if (this->ProcessIndex_CO2inGas == -1) + { + for (int i = 0; i < int(pcs_vector.size()); i++) + { n_pcs = pcs_vector[i]; - if (n_pcs->nod_val_name_vector[0] == this->dissolved_co2_ingas_pcs_name_ECL) { + if (n_pcs->nod_val_name_vector[0] == this->dissolved_co2_ingas_pcs_name_ECL) + { this->ProcessIndex_CO2inGas = i; - transportphase = cp_vec[pcs_vector[this->ProcessIndex_CO2inGas]->pcs_component_number]->transport_phase; break; + transportphase + = cp_vec[pcs_vector[this->ProcessIndex_CO2inGas]->pcs_component_number]->transport_phase; + break; } } } - if (this->ProcessIndex_CO2inGas == -1) { - cout << "In the model exists dissolved gas but there is no C in the gas phase defined. Please ad the corresponding mass transport process for CO2 in gas ! " << "\n"; - //system("Pause"); + if (this->ProcessIndex_CO2inGas == -1) + { + cout << "In the model exists dissolved gas but there is no C in the gas phase defined. Please ad the " + "corresponding mass transport process for CO2 in gas ! " + << "\n"; + // system("Pause"); exit(0); } // get index of species concentration in nodevaluevector of this process - indexConcentration_gas = pcs_vector[this->ProcessIndex_CO2inGas]->GetNodeValueIndex(pcs_vector[this->ProcessIndex_CO2inGas]->pcs_primary_function_name[0]) + 1; // +1: new timelevel - //WTP_CB: new way to get the total number of nodes in the mesh since nod_val_vector is not suitable anymore - //for(unsigned long i = 0; i < pcs_vector[this->ProcessIndex_CO2inGas]->nod_val_vector.size(); i++){ - for(long i = 0; i < nnodes; i++){ - //Calculate CO2 Concentration in Gas - double mass_CO2 = this->NodeData[i]->VaporComponentMassFraction * this->NodeData[i]->phase_density[phase2]; + indexConcentration_gas = pcs_vector[this->ProcessIndex_CO2inGas]->GetNodeValueIndex( + pcs_vector[this->ProcessIndex_CO2inGas]->pcs_primary_function_name[0]) + + 1; // +1: new timelevel + // WTP_CB: new way to get the total number of nodes in the mesh since nod_val_vector is not suitable anymore + // for(unsigned long i = 0; i < pcs_vector[this->ProcessIndex_CO2inGas]->nod_val_vector.size(); i++){ + for (long i = 0; i < nnodes; i++) + { + // Calculate CO2 Concentration in Gas + double mass_CO2 + = this->NodeData[i]->VaporComponentMassFraction * this->NodeData[i]->phase_density[phase2]; value_gas = mass_CO2 / (this->Molweight_CO2 / 1000); - // CB: use correct reference volume - if(transportphase==3) {// NAPL Phase, i.e. mol/m³REV - // CB_merge_0513 - if(m_rei) - porosity = m_rei->node_porosity[i]; // CB: Todo, generalize - value_gas *= this->NodeData[i]->phase_saturation[2] * porosity; - } + // CB: use correct reference volume + if (transportphase == 3) + { // NAPL Phase, i.e. mol/m³REV + // CB_merge_0513 + if (m_rei) + porosity = m_rei->node_porosity[i]; // CB: Todo, generalize + value_gas *= this->NodeData[i]->phase_saturation[2] * porosity; + } pcs_vector[this->ProcessIndex_CO2inGas]->SetNodeValue(i, indexConcentration_gas, value_gas); // CB: also set the old TL. This is required by Satu update from NAPL dissolution - //pcs_vector[this->ProcessIndex_CO2inGas]->SetNodeValue(i, indexConcentration_gas-1, value_gas); - //cout << "Node: " << i << " Druck: " << m_pcs->GetNodeValue(i, index_pressure2) << " RS: " << this->NodeData[i]->Gas_dissolved << " Dichte: " << this->SurfaceCO2Density << " C(4): " << value << "\n"; - if (value_gas < 0) { - cout << "Node: " << i << " Druck: " << m_pcs->GetNodeValue(i, index_pressure2) << " RS: " << this->NodeData[i]->CO2inLiquid << " Dichte: " << this->SurfaceCO2Density << " dissolved CO2: " << value << "\n"; + // pcs_vector[this->ProcessIndex_CO2inGas]->SetNodeValue(i, indexConcentration_gas-1, value_gas); + // cout << "Node: " << i << " Druck: " << m_pcs->GetNodeValue(i, index_pressure2) << " RS: " << + // this->NodeData[i]->Gas_dissolved << " Dichte: " << this->SurfaceCO2Density << " C(4): " << value << + // "\n"; + if (value_gas < 0) + { + cout << "Node: " << i << " Druck: " << m_pcs->GetNodeValue(i, index_pressure2) + << " RS: " << this->NodeData[i]->CO2inLiquid << " Dichte: " << this->SurfaceCO2Density + << " dissolved CO2: " << value << "\n"; cout << " Fehler in Berechnung von C_GAS: " << value << "\n"; } } } - //CB: e100 calculate species concentration in the gas phase - if (this->E100 && this->dissolved_co2_ingas_pcs_name_ECL.size()>0) { - CRFProcess *n_pcs = NULL; + // CB: e100 calculate species concentration in the gas phase + if (this->E100 && this->dissolved_co2_ingas_pcs_name_ECL.size() > 0) + { + CRFProcess* n_pcs = NULL; int indexConcentration_gas; - if (this->ProcessIndex_CO2inGas == -1) { - for(int i = 0; i < int(pcs_vector.size()); i++) { + if (this->ProcessIndex_CO2inGas == -1) + { + for (int i = 0; i < int(pcs_vector.size()); i++) + { n_pcs = pcs_vector[i]; - if (n_pcs->nod_val_name_vector[0] == this->dissolved_co2_ingas_pcs_name_ECL) { + if (n_pcs->nod_val_name_vector[0] == this->dissolved_co2_ingas_pcs_name_ECL) + { this->ProcessIndex_CO2inGas = i; - break; + break; } } } - if (this->ProcessIndex_CO2inGas == -1) { - cout << "In the model exists dissolved gas but there is no C in the gas phase defined. Please ad the corresponding mass transport process for CO2 in gas ! " << "\n"; - //system("Pause"); + if (this->ProcessIndex_CO2inGas == -1) + { + cout << "In the model exists dissolved gas but there is no C in the gas phase defined. Please ad the " + "corresponding mass transport process for CO2 in gas ! " + << "\n"; + // system("Pause"); exit(0); } // get index of species concentration in nodevaluevector of this process - indexConcentration_gas = pcs_vector[this->ProcessIndex_CO2inGas]->GetNodeValueIndex(pcs_vector[this->ProcessIndex_CO2inGas]->pcs_primary_function_name[0]) + 1; // +1: new timelevel + indexConcentration_gas = pcs_vector[this->ProcessIndex_CO2inGas]->GetNodeValueIndex( + pcs_vector[this->ProcessIndex_CO2inGas]->pcs_primary_function_name[0]) + + 1; // +1: new timelevel transportphase = cp_vec[pcs_vector[this->ProcessIndex_CO2inGas]->pcs_component_number]->transport_phase; - //WTP_CB: new way to get the total number of nodes in the mesh since nod_val_vector is not suitable anymore - //for(unsigned long i = 0; i < pcs_vector[this->ProcessIndex_CO2inGas]->nod_val_vector.size(); i++){ - for(long i = 0; i < nnodes; i++){ - //Calculate CO2 Concentration in Gas, gas is pure CO2 so mass fraction is 1 by definition + // WTP_CB: new way to get the total number of nodes in the mesh since nod_val_vector is not suitable anymore + // for(unsigned long i = 0; i < pcs_vector[this->ProcessIndex_CO2inGas]->nod_val_vector.size(); i++){ + for (long i = 0; i < nnodes; i++) + { + // Calculate CO2 Concentration in Gas, gas is pure CO2 so mass fraction is 1 by definition double mass_CO2 = 1.0 * this->NodeData[i]->phase_density[phase2]; value_gas = mass_CO2 / (this->Molweight_CO2 / 1000); - if(transportphase==3) {// NAPL Phase, i.e. mol/m^3REV - // CB_merge_0513 - if(m_rei) - porosity = m_rei->node_porosity[i]; // CB: Todo, generalize - value_gas *= this->NodeData[i]->phase_saturation[2] * porosity; + if (transportphase == 3) + { // NAPL Phase, i.e. mol/m^3REV + // CB_merge_0513 + if (m_rei) + porosity = m_rei->node_porosity[i]; // CB: Todo, generalize + value_gas *= this->NodeData[i]->phase_saturation[2] * porosity; } pcs_vector[this->ProcessIndex_CO2inGas]->SetNodeValue(i, indexConcentration_gas, value_gas); // CB: also set the old TL. This is required by Satu update from NAPL dissolution - //pcs_vector[this->ProcessIndex_CO2inGas]->SetNodeValue(i, indexConcentration_gas-1, value_gas); - //cout << "Node: " << i << " Druck: " << m_pcs->GetNodeValue(i, index_pressure2) << " RS: " << this->NodeData[i]->Gas_dissolved << " Dichte: " << this->SurfaceCO2Density << " C(4): " << value << "\n"; - if (value_gas < 0) { - cout << "Node: " << i << " Druck: " << m_pcs->GetNodeValue(i, index_pressure2) << " RS: " << this->NodeData[i]->CO2inLiquid << " Dichte: " << this->SurfaceCO2Density << " dissolved CO2: " << value << "\n"; + // pcs_vector[this->ProcessIndex_CO2inGas]->SetNodeValue(i, indexConcentration_gas-1, value_gas); + // cout << "Node: " << i << " Druck: " << m_pcs->GetNodeValue(i, index_pressure2) << " RS: " << + // this->NodeData[i]->Gas_dissolved << " Dichte: " << this->SurfaceCO2Density << " C(4): " << value << + // "\n"; + if (value_gas < 0) + { + cout << "Node: " << i << " Druck: " << m_pcs->GetNodeValue(i, index_pressure2) + << " RS: " << this->NodeData[i]->CO2inLiquid << " Dichte: " << this->SurfaceCO2Density + << " dissolved CO2: " << value << "\n"; cout << " Fehler in Berechnung von C_GAS: " << value << "\n"; } } } - } //SB_KB - - + } // SB_KB - //Geschwindigkeiten an den Gausspunkten interpolieren + // Geschwindigkeiten an den Gausspunkten interpolieren for (int i = 0; i < int(this->Phases.size()); i++) - m_pcs->CalGPVelocitiesfromECLIPSE(path, - m_pcs->Tim->step_current, - i, - this->Phases[i]); + m_pcs->CalGPVelocitiesfromECLIPSE(path, m_pcs->Tim->step_current, i, this->Phases[i]); // Test Output Elements - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt CECLIPSEBlock* m_block = NULL; - if(1 < 0) // SB // WTP: hu? - if ((m_pcs->Tim->step_current == 0) || (m_pcs->Tim->step_current == 1) || - (m_pcs->Tim->step_current == 2) || (m_pcs->Tim->step_current == 5) || - (m_pcs->Tim->step_current == 10) || (m_pcs->Tim->step_current == 20) || - (m_pcs->Tim->step_current == 30) || (m_pcs->Tim->step_current == 40) || - (m_pcs->Tim->step_current == 50) || (m_pcs->Tim->step_current == 100) || - (m_pcs->Tim->step_current == 999) || (m_pcs->Tim->step_current == 1000)) - { - vector vec_string; - std::string tempstring; - ostringstream temp; - MeshLib::CElem* elem = NULL; - Math_Group::vec Nodes(8); - double Val; - if (this->Phases.size() == 1) + if (1 < 0) // SB // WTP: hu? + if ((m_pcs->Tim->step_current == 0) || (m_pcs->Tim->step_current == 1) || (m_pcs->Tim->step_current == 2) + || (m_pcs->Tim->step_current == 5) + || (m_pcs->Tim->step_current == 10) + || (m_pcs->Tim->step_current == 20) + || (m_pcs->Tim->step_current == 30) + || (m_pcs->Tim->step_current == 40) + || (m_pcs->Tim->step_current == 50) + || (m_pcs->Tim->step_current == 100) + || (m_pcs->Tim->step_current == 999) + || (m_pcs->Tim->step_current == 1000)) { - int nidx1 = m_pcs->GetNodeValueIndex("PRESSURE1") + 1; //+1... new time level - vec_string.push_back("Element; X; Y; Z; P-Geosys"); - for(unsigned long i = 0; i < m_msh->ele_vector.size(); i++) + vector vec_string; + std::string tempstring; + ostringstream temp; + MeshLib::CElem* elem = NULL; + Math_Group::vec Nodes(8); + double Val; + if (this->Phases.size() == 1) { - elem = m_msh->ele_vector[i]; - m_block = this->eclgrid[i]; - //Calculate the average of the pressure for all nodes of 1 element - Val = 0; - elem->GetNodes(Nodes); - for (long j = 0; j < long(Nodes.Size()); j++) - Val += - m_pcs->GetNodeValue(Nodes[j]->GetIndex(), - nidx1) / Nodes.Size(); - - temp.str(""); - temp.clear(); - temp << i; - tempstring = temp.str(); - temp.str(""); - temp.clear(); - temp << m_block->x_barycentre; - tempstring += "; " + temp.str(); - temp.str(""); - temp.clear(); - temp << m_block->y_barycentre; - tempstring += "; " + temp.str(); - temp.str(""); - temp.clear(); - temp << m_block->z_barycentre; - tempstring += "; " + temp.str(); - temp.str(""); - temp.clear(); - temp.precision(12); - temp << Val; - tempstring += "; " + temp.str(); - vec_string.push_back(tempstring); + int nidx1 = m_pcs->GetNodeValueIndex("PRESSURE1") + 1; //+1... new time level + vec_string.push_back("Element; X; Y; Z; P-Geosys"); + for (unsigned long i = 0; i < m_msh->ele_vector.size(); i++) + { + elem = m_msh->ele_vector[i]; + m_block = this->eclgrid[i]; + // Calculate the average of the pressure for all nodes of 1 element + Val = 0; + elem->GetNodes(Nodes); + for (long j = 0; j < long(Nodes.Size()); j++) + Val += m_pcs->GetNodeValue(Nodes[j]->GetIndex(), nidx1) / Nodes.Size(); + + temp.str(""); + temp.clear(); + temp << i; + tempstring = temp.str(); + temp.str(""); + temp.clear(); + temp << m_block->x_barycentre; + tempstring += "; " + temp.str(); + temp.str(""); + temp.clear(); + temp << m_block->y_barycentre; + tempstring += "; " + temp.str(); + temp.str(""); + temp.clear(); + temp << m_block->z_barycentre; + tempstring += "; " + temp.str(); + temp.str(""); + temp.clear(); + temp.precision(12); + temp << Val; + tempstring += "; " + temp.str(); + vec_string.push_back(tempstring); + } } - } - if (this->Phases.size() > 1) - { - int nidx1 = m_pcs->GetNodeValueIndex("PRESSURE1") + 1; //+1... new time level - int nidx2 = m_pcs->GetNodeValueIndex("PRESSURE2") + 1; - int nidx3 = m_pcs->GetNodeValueIndex("SATURATION1") + 1; - vec_string.push_back( - "Element; X; Y; Z; P-Geosys_phase1; P-Geosys_phase2; Saturation_Geosys_phase1"); - for(unsigned long i = 0; i < m_msh->ele_vector.size(); i++) + if (this->Phases.size() > 1) { - elem = m_msh->ele_vector[i]; - m_block = this->eclgrid[i]; - temp.str(""); - temp.clear(); - temp << i; - tempstring = temp.str(); - temp.str(""); - temp.clear(); - temp << m_block->x_barycentre; - tempstring += "; " + temp.str(); - temp.str(""); - temp.clear(); - temp << m_block->y_barycentre; - tempstring += "; " + temp.str(); - temp.str(""); - temp.clear(); - temp << m_block->z_barycentre; - tempstring += "; " + temp.str(); - Val = 0; - elem->GetNodes(Nodes); - for (long j = 0; j < long(Nodes.Size()); j++) - Val += - m_pcs->GetNodeValue(Nodes[j]->GetIndex(), - nidx1) / Nodes.Size(); - temp.str(""); - temp.clear(); - temp.precision(12); - temp << Val; - tempstring += "; " + temp.str(); - - Val = 0; - for (long j = 0; j < long(Nodes.Size()); j++) - Val += - m_pcs->GetNodeValue(Nodes[j]->GetIndex(), - nidx2) / Nodes.Size(); - temp.str(""); - temp.clear(); - temp.precision(12); - temp << Val; - tempstring += "; " + temp.str(); - - Val = 0; - for (long j = 0; j < long(Nodes.Size()); j++) - Val += - m_pcs->GetNodeValue(Nodes[j]->GetIndex(), - nidx3) / Nodes.Size(); - temp.str(""); - temp.clear(); - temp.precision(12); - temp << Val; - tempstring += "; " + temp.str(); - - vec_string.push_back(tempstring); + int nidx1 = m_pcs->GetNodeValueIndex("PRESSURE1") + 1; //+1... new time level + int nidx2 = m_pcs->GetNodeValueIndex("PRESSURE2") + 1; + int nidx3 = m_pcs->GetNodeValueIndex("SATURATION1") + 1; + vec_string.push_back("Element; X; Y; Z; P-Geosys_phase1; P-Geosys_phase2; Saturation_Geosys_phase1"); + for (unsigned long i = 0; i < m_msh->ele_vector.size(); i++) + { + elem = m_msh->ele_vector[i]; + m_block = this->eclgrid[i]; + temp.str(""); + temp.clear(); + temp << i; + tempstring = temp.str(); + temp.str(""); + temp.clear(); + temp << m_block->x_barycentre; + tempstring += "; " + temp.str(); + temp.str(""); + temp.clear(); + temp << m_block->y_barycentre; + tempstring += "; " + temp.str(); + temp.str(""); + temp.clear(); + temp << m_block->z_barycentre; + tempstring += "; " + temp.str(); + Val = 0; + elem->GetNodes(Nodes); + for (long j = 0; j < long(Nodes.Size()); j++) + Val += m_pcs->GetNodeValue(Nodes[j]->GetIndex(), nidx1) / Nodes.Size(); + temp.str(""); + temp.clear(); + temp.precision(12); + temp << Val; + tempstring += "; " + temp.str(); + + Val = 0; + for (long j = 0; j < long(Nodes.Size()); j++) + Val += m_pcs->GetNodeValue(Nodes[j]->GetIndex(), nidx2) / Nodes.Size(); + temp.str(""); + temp.clear(); + temp.precision(12); + temp << Val; + tempstring += "; " + temp.str(); + + Val = 0; + for (long j = 0; j < long(Nodes.Size()); j++) + Val += m_pcs->GetNodeValue(Nodes[j]->GetIndex(), nidx3) / Nodes.Size(); + temp.str(""); + temp.clear(); + temp.precision(12); + temp << Val; + tempstring += "; " + temp.str(); + + vec_string.push_back(tempstring); + } } - } - //CWriteTextfiles *TextFile; - //TextFile = new CWriteTextfiles; - //int position = int(path.find_last_of("\\")); - //std::string path_new; - //path_new = path.substr(0,position); - //position = int(path_new.find_last_of("\\")); - //path_new = path_new.substr(0,position); - //temp.str(""); temp.clear(); temp << m_pcs->Tim->step_current; tempstring = temp.str(); - //TextFile->Write_Text(path_new + "\\ElementValues_Geosys_" + tempstring + ".csv", vec_string); - } // End Test Output + // CWriteTextfiles *TextFile; + // TextFile = new CWriteTextfiles; + // int position = int(path.find_last_of("\\")); + // std::string path_new; + // path_new = path.substr(0,position); + // position = int(path_new.find_last_of("\\")); + // path_new = path_new.substr(0,position); + // temp.str(""); temp.clear(); temp << m_pcs->Tim->step_current; tempstring = temp.str(); + // TextFile->Write_Text(path_new + "\\ElementValues_Geosys_" + tempstring + ".csv", vec_string); + } // End Test Output } /*------------------------------------------------------------------------- GeoSys - Function: ExecuteEclipse @@ -4571,7 +4471,7 @@ std::string CECLIPSEData::ExecuteEclipse(long Timestep, CRFProcess* m_pcs, std:: std::string Keyword; std::string Keyword_well; ostringstream temp; - vector vecData; + vector vecData; CReadTextfiles_ECL* TextFile; int rateidx = 0; @@ -4583,26 +4483,27 @@ std::string CECLIPSEData::ExecuteEclipse(long Timestep, CRFProcess* m_pcs, std:: std::string root_folder, geosys_folder; EclipseExe = m_pcs->simulator_path; // path to eclipse executable - //check if file exists + // check if file exists if (this->UsePrecalculatedFiles == false) if (CheckIfFileExists(EclipseExe) == false) { - cout << "The ECLIPSE executable could not be found! (" << EclipseExe << - ")" << "\n"; - //system("Pause"); //SB redo wtp + cout << "The ECLIPSE executable could not be found! (" << EclipseExe << ")" + << "\n"; + // system("Pause"); //SB redo wtp exit(0); } Filename = m_pcs->simulator_model_path; // path to eclipse input data - //check if file exists + // check if file exists if (CheckIfFileExists(Filename) == false) { - cout << "The ECLIPSE project file could not be found! (" << Filename << ")" << "\n"; - //system("Pause"); // SB redo wtp + cout << "The ECLIPSE project file could not be found! (" << Filename << ")" + << "\n"; + // system("Pause"); // SB redo wtp exit(0); } - //check if eclipse folder is subfolder of the geosys folder + // check if eclipse folder is subfolder of the geosys folder if (Timestep == 1) { if (this->Windows_System == true) @@ -4625,12 +4526,11 @@ std::string CECLIPSEData::ExecuteEclipse(long Timestep, CRFProcess* m_pcs, std:: if (root_folder != geosys_folder) { // WTP: Why is this a problem? - cout << - "Warning: The Eclipse simulator model path is not part of the GeoSys model path!!!" + cout << "Warning: The Eclipse simulator model path is not part of the GeoSys model path!!!" << "\n"; cout << root_folder << "\n"; cout << geosys_folder << "\n"; - //system("Pause"); // SB redo wtp + // system("Pause"); // SB redo wtp } } @@ -4639,15 +4539,15 @@ std::string CECLIPSEData::ExecuteEclipse(long Timestep, CRFProcess* m_pcs, std:: else position = int(Filename.find_last_of("/")); // check if filename is given with or without extension - tempstring = Filename.substr(Filename.length() - 5,Filename.length()); - if((tempstring.compare(".data") == 0) || (tempstring.compare(".DATA") == 0)) + tempstring = Filename.substr(Filename.length() - 5, Filename.length()); + if ((tempstring.compare(".data") == 0) || (tempstring.compare(".DATA") == 0)) projectname = Filename.substr(0, Filename.length() - 5); else projectname = Filename; if (Timestep > 1) projectname = projectname + "_RESTART"; - //Read length of current timestep and recalculate it to days + // Read length of current timestep and recalculate it to days if (m_pcs->Tim->time_unit == "DAY") timestep_length = m_pcs->Tim->time_step_length; else @@ -4660,14 +4560,16 @@ std::string CECLIPSEData::ExecuteEclipse(long Timestep, CRFProcess* m_pcs, std:: timestep_length = m_pcs->Tim->time_step_length / 60 / 60 / 24; else { - cout << "This time unit was not considered yet" << "\n"; - //system("Pause"); //SB redo wtp + cout << "This time unit was not considered yet" + << "\n"; + // system("Pause"); //SB redo wtp exit(0); } } } - //Write the timestep in the eclipse file - if (this->UsePrecalculatedFiles == false || (this->UsePrecalculatedFiles == true && this->UseSaveEclipseDataFiles == true)) + // Write the timestep in the eclipse file + if (this->UsePrecalculatedFiles == false + || (this->UsePrecalculatedFiles == true && this->UseSaveEclipseDataFiles == true)) { Keyword = "TSTEP"; tempstring = "1*"; @@ -4678,13 +4580,13 @@ std::string CECLIPSEData::ExecuteEclipse(long Timestep, CRFProcess* m_pcs, std:: tempstring = tempstring + " /"; vecData.clear(); vecData.push_back(tempstring); - //std::string File = projectname + ".data"; + // std::string File = projectname + ".data"; std::string File = projectname + ".DATA"; // SB redo wtp if (ReplaceASectionInFile(File, Keyword, vecData, true) == false) { - cout << "Replacing a section in the file: " << File << - " didn't work for Keyword TSTEP!" << "\n"; - //system("Pause"); // SB redo wtp + cout << "Replacing a section in the file: " << File << " didn't work for Keyword TSTEP!" + << "\n"; + // system("Pause"); // SB redo wtp exit(0); } vecData.clear(); @@ -4695,45 +4597,46 @@ std::string CECLIPSEData::ExecuteEclipse(long Timestep, CRFProcess* m_pcs, std:: for (int ii = 0; ii < int(this->ecl_well.size()); ii++) { rateidx = -1; - for (int kk = 0; kk < int(this->ecl_well[ii]->time.size()); kk++) { - // if (this->ecl_well[ii]->time[kk] == this->actual_time) + for (int kk = 0; kk < int(this->ecl_well[ii]->time.size()); kk++) + { + // if (this->ecl_well[ii]->time[kk] == this->actual_time) if (this->ecl_well[ii]->time[kk] > this->actual_time) rateidx = kk - 1; - //this->WellRates.push_back(ecl_well[ii]->rate[kk]); - //break; + // this->WellRates.push_back(ecl_well[ii]->rate[kk]); + // break; else rateidx = kk; - } - if(rateidx > -1) - this->WellRates.push_back(ecl_well[ii]->rate[rateidx]); - // wtp - if (this->WellRates.size() != 0){ - std::string outline = this->ecl_well[ii]->name + " " + - this->ecl_well[ii]->phase + " " + - this->ecl_well[ii]->open_flag + - " " + this->ecl_well[ii]->control_mode + - " " + - this->WellRates[ii] + " " + " / "; - vecData.push_back(outline); + } + if (rateidx > -1) + this->WellRates.push_back(ecl_well[ii]->rate[rateidx]); + // wtp + if (this->WellRates.size() != 0) + { + std::string outline = this->ecl_well[ii]->name + " " + this->ecl_well[ii]->phase + " " + + this->ecl_well[ii]->open_flag + " " + this->ecl_well[ii]->control_mode + + " " + this->WellRates[ii] + " " + " / "; + vecData.push_back(outline); } } - //if (this->WellRates.size() != 0){ - // std::string outline = this->ecl_well[ii]->name + " " + this->ecl_well[ii]->phase + " " + this->ecl_well[ii]->open_flag + " " + this->ecl_well[ii]->control_mode + " " + this->WellRates[ii] + " " + " / "; + // if (this->WellRates.size() != 0){ + // std::string outline = this->ecl_well[ii]->name + " " + this->ecl_well[ii]->phase + " " + + // this->ecl_well[ii]->open_flag + " " + this->ecl_well[ii]->control_mode + " " + this->WellRates[ii] + + //" " + " / "; // vecData.push_back(outline); // } //} - if (vecData.size() != 0 ){ + if (vecData.size() != 0) + { std::string outline = "/"; vecData.push_back(outline); - Keyword = "WCONINJE"; - //std::string File = projectname + ".data"; + // std::string File = projectname + ".data"; std::string File = projectname + ".DATA"; // SB redo wtp if (ReplaceASectionInFile(File, Keyword, vecData, true) == false) { - cout << "Replacing a section in the file: " << File << - " didn't work!" << "\n"; + cout << "Replacing a section in the file: " << File << " didn't work!" + << "\n"; // //system("Pause"); // SB redo wtp exit(0); } @@ -4741,12 +4644,11 @@ std::string CECLIPSEData::ExecuteEclipse(long Timestep, CRFProcess* m_pcs, std:: } vecData.clear(); this->WellRates.clear(); // SB redo wtp - } if (Timestep == 1) { - //only if no phases exists yet + // only if no phases exists yet this->E100 = false; if (int(this->Phases.size()) == 0) { @@ -4755,14 +4657,15 @@ std::string CECLIPSEData::ExecuteEclipse(long Timestep, CRFProcess* m_pcs, std:: Error = TextFile->Read_Text(Filename); if (Error == true) { - cout << "The program is canceled in ExecuteEclipse()" << "\n"; + cout << "The program is canceled in ExecuteEclipse()" + << "\n"; // //system("Pause"); // SB redo wtp exit(0); } for (int i = 0; i < TextFile->NumberOfRows; i++) { this->SplittedString.clear(); - this->SplitStrings(TextFile->Data[i]," "); + this->SplitStrings(TextFile->Data[i], " "); if (this->SplittedString.size() > 0) { // check if one of the phases is water @@ -4787,12 +4690,10 @@ std::string CECLIPSEData::ExecuteEclipse(long Timestep, CRFProcess* m_pcs, std:: found_H2O = TextFile->Data[i + 1].find("H2O"); found_CO2 = TextFile->Data[i + 2].find("CO2"); found_NaCl = TextFile->Data[i + 3].find("NACL"); - if ((found_H2O == string::npos) || - (found_CO2 == string::npos) || - (found_NaCl == string::npos)) + if ((found_H2O == string::npos) || (found_CO2 == string::npos) || (found_NaCl == string::npos)) { - cout << - "The OGS-ECL code can currently only consider the components H2O, CO2 and NaCl in this order in E300!" + cout << "The OGS-ECL code can currently only consider the components H2O, CO2 and NaCl in " + "this order in E300!" << "\n"; // //system("Pause"); // SB redo wtp exit(0); @@ -4801,7 +4702,7 @@ std::string CECLIPSEData::ExecuteEclipse(long Timestep, CRFProcess* m_pcs, std:: } } } - //fill the phase vector with the wetting phase first + // fill the phase vector with the wetting phase first if (this->E100 == true) { if (Water_phase_exists == true) @@ -4813,19 +4714,19 @@ std::string CECLIPSEData::ExecuteEclipse(long Timestep, CRFProcess* m_pcs, std:: if (Water_phase_exists == false) { // The software is not checked if water is not the wetting phase - cout << - "The program is canceled because no water phase is defined in ECLIPSE!" + cout << "The program is canceled because no water phase is defined in ECLIPSE!" << "\n"; - //system("Pause"); + // system("Pause"); exit(0); } - //Define necessary Variables + // Define necessary Variables // WTP: To add functionalty this should be more felxible...espacially for E300 // e.g. the Variables should be read from the .DATA (under RPTRST) and written in "Variables" - // of course there should be a consistency check afterwards to check if every needed variable is applicable + // of course there should be a consistency check afterwards to check if every needed variable is + // applicable - //The total pressure is only defined once + // The total pressure is only defined once this->Variables.push_back("PRESSURE"); this->Variables.push_back("ACAQNUM"); for (unsigned int i = 0; i < this->Phases.size(); i++) @@ -4864,22 +4765,20 @@ std::string CECLIPSEData::ExecuteEclipse(long Timestep, CRFProcess* m_pcs, std:: // variable for reading capillary pressures in the case of Eclipse E100 if (int(this->Phases.size()) == 2) { - if ((this->Phases[0] == "WATER") && - (this->Phases[1] == "OIL")) + if ((this->Phases[0] == "WATER") && (this->Phases[1] == "OIL")) this->Variables.push_back("PCOW"); else { - if ((this->Phases[0] == "OIL") && - (this->Phases[1] == "GAS")) + if ((this->Phases[0] == "OIL") && (this->Phases[1] == "GAS")) { this->Variables.push_back("PCOG"); - this->Variables.push_back("RS"); //gas saturation in oil in the black oil mode - this->Variables.push_back("GAS_DEN"); //gas density in the black oil mode + this->Variables.push_back("RS"); // gas saturation in oil in the black oil mode + this->Variables.push_back("GAS_DEN"); // gas density in the black oil mode } else { - cout << - "Currently only Oil-Water or Oil-Gas is available because there is no output option in Eclipse E100 for the capillary pressure!" + cout << "Currently only Oil-Water or Oil-Gas is available because there is no output " + "option in Eclipse E100 for the capillary pressure!" << "\n"; // //system("Pause"); // SB redo wtp exit(0); @@ -4890,33 +4789,33 @@ std::string CECLIPSEData::ExecuteEclipse(long Timestep, CRFProcess* m_pcs, std:: { this->Variables.push_back("PCOW"); this->Variables.push_back("PCOG"); - this->Variables.push_back("RS"); //gas saturation in oil in the black oil mode - //this->Variables.push_back("GAS_DEN"); //gas density in the black oil mode + this->Variables.push_back("RS"); // gas saturation in oil in the black oil mode + // this->Variables.push_back("GAS_DEN"); //gas density in the black oil mode } - //SB adapt to three phase mode in black oil using oil as water and gas as co2 - if (int(this->Phases.size()) == 3) { + // SB adapt to three phase mode in black oil using oil as water and gas as co2 + if (int(this->Phases.size()) == 3) + { // three phases present, but use only oil as water and gas as CO2 this->phase_shift_flag = true; - } } else { - //E300 mode -> it is assumed that water and CO2 phase are considered - //components + // E300 mode -> it is assumed that water and CO2 phase are considered + // components this->Components.push_back("H2O"); this->Components.push_back("CO2"); this->Components.push_back("NaCl"); - //phases + // phases this->Phases.push_back("WATER"); this->Phases.push_back("GAS"); - //variables + // variables this->Variables.push_back("PRESSURE"); // Total pressure this->Variables.push_back("PWAT"); // water phase pressure this->Variables.push_back("PGAS"); // gas phase pressure - //this->Variables.push_back("TEMP"); // WTP: Grid Block Temperature + // this->Variables.push_back("TEMP"); // WTP: Grid Block Temperature this->Variables.push_back("SWAT"); // water phase saturation this->Variables.push_back("SGAS"); // gas phase saturation @@ -4933,34 +4832,33 @@ std::string CECLIPSEData::ExecuteEclipse(long Timestep, CRFProcess* m_pcs, std:: this->Variables.push_back("XFW3"); // mass fraction of component 3 in liquid phase // SB redo wtp - this->Variables.push_back("XMF1"); // mole fraction of component 1 in liquid phase - this->Variables.push_back("XMF2"); // mole fraction of component 2 in liquid phase - this->Variables.push_back("XMF3"); // mole fraction of component 3 in liquid phase - - this->Variables.push_back("YMF1"); // mole fraction of component 1 in gas phase - this->Variables.push_back("YMF2"); // mole fraction of component 2 in gas phase - this->Variables.push_back("YMF3"); // mole fraction of component 3 in gas phase + this->Variables.push_back("XMF1"); // mole fraction of component 1 in liquid phase + this->Variables.push_back("XMF2"); // mole fraction of component 2 in liquid phase + this->Variables.push_back("XMF3"); // mole fraction of component 3 in liquid phase - this->Variables.push_back("YFW1"); // mass fraction of component 1 in gas phase - this->Variables.push_back("YFW2"); // mass fraction of component 2 in gas phase - this->Variables.push_back("YFW3"); // mass fraction of component 3 in gas phase + this->Variables.push_back("YMF1"); // mole fraction of component 1 in gas phase + this->Variables.push_back("YMF2"); // mole fraction of component 2 in gas phase + this->Variables.push_back("YMF3"); // mole fraction of component 3 in gas phase + this->Variables.push_back("YFW1"); // mass fraction of component 1 in gas phase + this->Variables.push_back("YFW2"); // mass fraction of component 2 in gas phase + this->Variables.push_back("YFW3"); // mass fraction of component 3 in gas phase this->Variables.push_back("MLSC1"); // total molar density for components(moles per reservoir volume) this->Variables.push_back("MLSC2"); // total molar density for components(moles per reservoir volume) this->Variables.push_back("MLSC3"); // total molar density for components(moles per reservoir volume) - //this->Variables.push_back("FLOC1I+"); // inter-block component flow for component 1 - //this->Variables.push_back("FLOC1J+"); // inter-block component flow for component 1 - //this->Variables.push_back("FLOC1K+"); // inter-block component flow for component 1 + // this->Variables.push_back("FLOC1I+"); // inter-block component flow for component 1 + // this->Variables.push_back("FLOC1J+"); // inter-block component flow for component 1 + // this->Variables.push_back("FLOC1K+"); // inter-block component flow for component 1 - //this->Variables.push_back("FLOC2I+"); // inter-block component flow for component 2 - //this->Variables.push_back("FLOC2J+"); // inter-block component flow for component 2 - //this->Variables.push_back("FLOC2K+"); // inter-block component flow for component 2 + // this->Variables.push_back("FLOC2I+"); // inter-block component flow for component 2 + // this->Variables.push_back("FLOC2J+"); // inter-block component flow for component 2 + // this->Variables.push_back("FLOC2K+"); // inter-block component flow for component 2 - //this->Variables.push_back("FLOC3I+"); // inter-block component flow for component 3 - //this->Variables.push_back("FLOC3J+"); // inter-block component flow for component 3 - //this->Variables.push_back("FLOC3K+"); // inter-block component flow for component 3 + // this->Variables.push_back("FLOC3I+"); // inter-block component flow for component 3 + // this->Variables.push_back("FLOC3J+"); // inter-block component flow for component 3 + // this->Variables.push_back("FLOC3K+"); // inter-block component flow for component 3 this->Variables.push_back("FLOWATI+"); this->Variables.push_back("FLOWATJ+"); @@ -4975,16 +4873,15 @@ std::string CECLIPSEData::ExecuteEclipse(long Timestep, CRFProcess* m_pcs, std:: this->times = 1; } - //Run Eclipse the first time from the original *.data file + // Run Eclipse the first time from the original *.data file // make string for external program call to ECLIPSE - if (this->UsePrecalculatedFiles == false ) + if (this->UsePrecalculatedFiles == false) { if (this->Windows_System == true) { - tempstring = EclipseExe + " " + projectname; - //std::cout << " Calling Eclipse executable using : " << tempstring << "\n"; + // std::cout << " Calling Eclipse executable using : " << tempstring << "\n"; if (system(tempstring.c_str())) { DisplayMsgLn("Warnung: Eclipse doesn't run properly!!! "); @@ -4993,8 +4890,9 @@ std::string CECLIPSEData::ExecuteEclipse(long Timestep, CRFProcess* m_pcs, std:: } else { - tempstring = EclipseExe + " ." + projectname.substr(root_folder.length(),root_folder.length()); // SB redo WTP - //tempstring = EclipseExe + " " + projectname; + tempstring + = EclipseExe + " ." + projectname.substr(root_folder.length(), root_folder.length()); // SB redo WTP + // tempstring = EclipseExe + " " + projectname; if (system(tempstring.c_str())) { DisplayMsgLn("Warnung: Eclipse doesn't run properly!!! "); @@ -5006,42 +4904,46 @@ std::string CECLIPSEData::ExecuteEclipse(long Timestep, CRFProcess* m_pcs, std:: else { // change Restart file - // Changes are included in the restart File, because there it is possible to define new porosities ore permeabilties + // Changes are included in the restart File, because there it is possible to define new porosities ore + // permeabilties // every time at least the number of the time step which is used for restart has to be changed - //Run Restart with results from the previous step - //tempstring = EclipseExe + " " + projectname; // CB 2012 not necessary here redo wtp + // Run Restart with results from the previous step + // tempstring = EclipseExe + " " + projectname; // CB 2012 not necessary here redo wtp // increase the number of time steps used for restart Keyword = "RESTART"; - //tempstring = " d:\\Projekte\\MoPa\Programme\\Eclipse\\BGfirstmodel\\"; - //SB redo WTP tempstring = folder + "TemporaryResults "; + // tempstring = " d:\\Projekte\\MoPa\Programme\\Eclipse\\BGfirstmodel\\"; + // SB redo WTP tempstring = folder + "TemporaryResults "; tempstring = folder; - // For the path to the restart file, ECLIPSE under LINUX wants "\" instead of "/"; replace for this section in folder string - replace(tempstring.begin(), tempstring.end(),'/','\\'); + // For the path to the restart file, ECLIPSE under LINUX wants "\" instead of "/"; replace for this section in + // folder string + replace(tempstring.begin(), tempstring.end(), '/', '\\'); tempstring += "TEMPORARYRESULTS "; - if(this->Windows_System == false) { //CB 1012 - replace(tempstring.begin(), tempstring.end(),'\\','/'); - tempstring = "TEMPORARYRESULTS "; - } + if (this->Windows_System == false) + { // CB 1012 + replace(tempstring.begin(), tempstring.end(), '\\', '/'); + tempstring = "TEMPORARYRESULTS "; + } - //tempstring += "TemporaryResults "; + // tempstring += "TemporaryResults "; temp.str(""); temp.clear(); temp << Timestep - 1; tempstring = tempstring + temp.str(); tempstring = tempstring + " /"; - //tempstring = tempstring + " SAVE FORMATTED /"; + // tempstring = tempstring + " SAVE FORMATTED /"; vecData.clear(); vecData.push_back(tempstring); - //std::string File = projectname + ".data"; + // std::string File = projectname + ".data"; std::string File = projectname + ".DATA"; // SB redo wtp - if (this->UsePrecalculatedFiles == false || (this->UsePrecalculatedFiles == true && this->UseSaveEclipseDataFiles == true)) + if (this->UsePrecalculatedFiles == false + || (this->UsePrecalculatedFiles == true && this->UseSaveEclipseDataFiles == true)) if (ReplaceASectionInFile(File, Keyword, vecData, true) == false) { - cout << "Replacing a section in the file: " << File << - " didn't work for Keyword RESTART!" << "\n"; + cout << "Replacing a section in the file: " << File << " didn't work for Keyword RESTART!" + << "\n"; // //system("Pause"); // SB redo wtp exit(0); } @@ -5052,7 +4954,7 @@ std::string CECLIPSEData::ExecuteEclipse(long Timestep, CRFProcess* m_pcs, std:: if (this->Windows_System == true) { tempstring = EclipseExe + " " + projectname; - //std::cout << " Calling Eclipse executable using : " << tempstring << "\n"; + // std::cout << " Calling Eclipse executable using : " << tempstring << "\n"; if (system(tempstring.c_str())) { DisplayMsgLn("Warnung: Eclipse doesn't run properly!!! "); @@ -5061,12 +4963,12 @@ std::string CECLIPSEData::ExecuteEclipse(long Timestep, CRFProcess* m_pcs, std:: } else { - position = int(Filename.find_last_of("/")); // WTP - root_folder = Filename.substr(0, position); - position = int(root_folder.find_last_of("/")); - tempstring = EclipseExe + " ." + projectname.substr(position,position); //CB 1012 + position = int(Filename.find_last_of("/")); // WTP + root_folder = Filename.substr(0, position); + position = int(root_folder.find_last_of("/")); + tempstring = EclipseExe + " ." + projectname.substr(position, position); // CB 1012 - //tempstring = EclipseExe + " " + projectname; //WTP + // tempstring = EclipseExe + " " + projectname; //WTP if (system(tempstring.c_str())) { DisplayMsgLn("Warnung: Eclipse doesn't run properly!!! "); @@ -5089,97 +4991,110 @@ bool CECLIPSEData::CleanUpEclipseFiles(std::string folder, std::string projectna std::string systemcommand; std::string system_delete; std::string system_noquery; - ostringstream temp; + ostringstream temp; std::string extension; std::string laenge; - if(this->Windows_System == true){ + if (this->Windows_System == true) + { system_delete = "del "; system_noquery = " /Q"; } - else {// Linux system + else + { // Linux system system_delete = "rm "; system_noquery = " "; } // Rename files for ECLIPSE restart - //delete temporary result files + // delete temporary result files systemcommand = system_delete + folder + "TEMPORARYRESULTS.*"; - if (system(systemcommand.c_str())){ + if (system(systemcommand.c_str())) + { DisplayMsgLn("Could not delete temporary result files! "); - //SB why return return 0; + // SB why return return 0; } /* systemcommand = system_delete + projectname + ".FSAVE" + system_noquery; if (system(systemcommand.c_str())){ - // DisplayMsgLn("Could not delete result .FSAVE files! "); - //SB ?? why return return 0; + // DisplayMsgLn("Could not delete result .FSAVE files! "); + //SB ?? why return return 0; } */ - //copy original result files - //systemcommand = "copy " + projectname + ".F* " + folder + "TemporaryResults.F*"; - if(this->Windows_System == true) + // copy original result files + // systemcommand = "copy " + projectname + ".F* " + folder + "TemporaryResults.F*"; + if (this->Windows_System == true) systemcommand = "ren " + projectname + ".F* " + "TEMPORARYRESULTS.F*"; - else{ - //systemcommand = "rename " + projectname + ". " + folder + "TEMPORARYRESULTS. " + projectname + ".F*"; - extension = ".F"; - temp.str(""); temp.clear(); temp << aktueller_zeitschritt; - if(aktueller_zeitschritt < 10) - extension += "000" + temp.str() + " " ; - else if(aktueller_zeitschritt < 100) - extension += "00" + temp.str() + " " ; - else if(aktueller_zeitschritt < 1000) - extension += "0" + temp.str() + " " ; - else - extension += temp.str() + " " ; - - systemcommand = "cp " + projectname + extension + folder + "TEMPORARYRESULTS" + extension; - } - if (system(systemcommand.c_str())){ + else + { + // systemcommand = "rename " + projectname + ". " + folder + "TEMPORARYRESULTS. " + projectname + ".F*"; + extension = ".F"; + temp.str(""); + temp.clear(); + temp << aktueller_zeitschritt; + if (aktueller_zeitschritt < 10) + extension += "000" + temp.str() + " "; + else if (aktueller_zeitschritt < 100) + extension += "00" + temp.str() + " "; + else if (aktueller_zeitschritt < 1000) + extension += "0" + temp.str() + " "; + else + extension += temp.str() + " "; + + systemcommand = "cp " + projectname + extension + folder + "TEMPORARYRESULTS" + extension; + } + if (system(systemcommand.c_str())) + { DisplayMsgLn("Could not rename the temporary result files .F*! "); - //return 0; + // return 0; + } + if (this->Windows_System == false) + { + systemcommand = "rm " + projectname + extension; + if (system(systemcommand.c_str())) + { + DisplayMsgLn("Could not delete the temporary result files basename.F*! "); + // return 0; + } } - if(this->Windows_System == false){ - systemcommand = "rm " + projectname + extension ; - if (system(systemcommand.c_str())){ - DisplayMsgLn("Could not delete the temporary result files basename.F*! "); - //return 0; - } - } - //systemcommand = system_delete + projectname + ".F*" + system_noquery; - //if (system(systemcommand.c_str())){ + // systemcommand = system_delete + projectname + ".F*" + system_noquery; + // if (system(systemcommand.c_str())){ // DisplayMsgLn("Could not delete result files! "); // return 0; //} systemcommand = system_delete + projectname + ".A*" + system_noquery; - if (system(systemcommand.c_str())){ + if (system(systemcommand.c_str())) + { DisplayMsgLn("Could not delete result files .A*! "); - //return 0; + // return 0; } systemcommand = system_delete + projectname + ".P*" + system_noquery; - if (system(systemcommand.c_str())){ + if (system(systemcommand.c_str())) + { DisplayMsgLn("Could not delete result files .P*! "); - //return 0; + // return 0; } systemcommand = system_delete + projectname + ".R*" + system_noquery; - if (system(systemcommand.c_str())){ + if (system(systemcommand.c_str())) + { DisplayMsgLn("Could not delete result files .R*! "); - //return 0; + // return 0; } systemcommand = system_delete + projectname + ".M*" + system_noquery; - if (system(systemcommand.c_str())){ + if (system(systemcommand.c_str())) + { DisplayMsgLn("Could not delete result files .M*! "); - //return 0; + // return 0; } systemcommand = system_delete + projectname + ".DB*" + system_noquery; - if (system(systemcommand.c_str())){ + if (system(systemcommand.c_str())) + { DisplayMsgLn("Could not delete result files .DB*! "); - //return 0; + // return 0; } return true; - } /*------------------------------------------------------------------------- @@ -5192,164 +5107,175 @@ bool CECLIPSEData::CleanUpEclipseFiles(std::string folder, std::string projectna int CECLIPSEData::WriteDataBackToEclipse(CRFProcess* m_pcs, std::string folder) { std::string Filename; - //WW int phase1, phase2; + // WW int phase1, phase2; int /*phase1,*/ phase2; // SB redo wtp CRFProcess* n_pcs = NULL; - //int indexProcess; + // int indexProcess; int indexConcentration; MeshLib::CElem* m_element = NULL; CFEMesh* m_msh = fem_msh_vector[0]; - Math_Group::vec vec_element_nodes(8); + Math_Group::vec vec_element_nodes(8); clock_t start, finish; double time; double delta_gas_dis, delta_gas_dissolved; double weight; - vector vecString; - vector vecRS; - vector vec_T_CO2; + vector vecString; + vector vecRS; + vector vec_T_CO2; double deltaT_CO2; std::string Keyword; ostringstream temp; std::string tempstring; - int variable_index_Gas_dissolved, variable_index_porevolume, - variable_index_water_saturation, variable_index_Moles_CO2, - variable_index_Gas_saturation, variable_index_Gas_pressure; - int idx = -1; + int variable_index_Gas_dissolved, variable_index_porevolume, variable_index_water_saturation, + variable_index_Moles_CO2, variable_index_Gas_saturation, variable_index_Gas_pressure; + int idx = -1; typeExponentialNumber tempNumber; const double epsilon = 1e-7; int j_max; - double value=0.0, value_old = 0; //porosity=0.0, saturation_w=0.0, + double value = 0.0, value_old = 0; // porosity=0.0, saturation_w=0.0, double RS = 0; - vector Sats; - vector Press; - + vector Sats; + vector Press; - //get no of nodes in mesh + // get no of nodes in mesh long nnodes = fem_msh_vector[0]->GetNodesNumber(false); - //long nnodes = pcs_vector[this->ProcessIndex_CO2inLiquid]->nod_val_vector.size(); + // long nnodes = pcs_vector[this->ProcessIndex_CO2inLiquid]->nod_val_vector.size(); long nele = m_msh->ele_vector.size(); - //CB PoroPermData exchange + // CB PoroPermData exchange bool poroflag = false; bool permxxflag = false; - //bool permyyflag = false; - //bool permzzflag = false; - vector poroperm; - vector vecString2; - vector vecString3; + // bool permyyflag = false; + // bool permzzflag = false; + vector poroperm; + vector vecString2; + vector vecString3; std::string tempstring2; std::string tempstring3; - double *tensor = NULL; + double* tensor = NULL; long count; - //CB_merge_0513 - //int idx_kxx, idx_kyy, idx_kzz; //WTP + // CB_merge_0513 + // int idx_kxx, idx_kyy, idx_kzz; //WTP int idx_n = 0; std::ostringstream sstream; sstream.precision(8); - //WTP variables for temperautre coupling to ecl + // WTP variables for temperautre coupling to ecl CRFProcess* l_pcs = NULL; - int idx_T = -1; // WTP Index of temperature data in + int idx_T = -1; // WTP Index of temperature data in double temp_temp = -99.; double ele_temp = -99.; - cout << " Write DIC to Eclipse File " << "\n"; + cout << " Write DIC to Eclipse File " + << "\n"; start = clock(); - switch(int(this->Phases.size())) + switch (int(this->Phases.size())) { - case 2: - //WW phase1 = 0; - //WW phase2 = 1; - //phase1 = 0; - phase2 = 1; - break; - case 3: - // Assumption that there are 3 phases but water is only used for the boundaries -> the oil and gas phase are the relevant one for the exchange with OGS - //WW phase1 = 1; - //WW phase2 = 2; - //phase1 = 1; - phase2 = 2; - break; - default: - cout << "There are not more than 3 phases possible!" << "\n"; - // //system("Pause"); - return 0; - break; + case 2: + // WW phase1 = 0; + // WW phase2 = 1; + // phase1 = 0; + phase2 = 1; + break; + case 3: + // Assumption that there are 3 phases but water is only used for the boundaries -> the oil and gas phase are + // the relevant one for the exchange with OGS + // WW phase1 = 1; + // WW phase2 = 2; + // phase1 = 1; + phase2 = 2; + break; + default: + cout << "There are not more than 3 phases possible!" + << "\n"; + // //system("Pause"); + return 0; + break; } - //clean node vector - //this->MakeNodeVector(m_pcs); + // clean node vector + // this->MakeNodeVector(m_pcs); // get DIC and CO2 density at nodes and recalculate RS - //index_gas_density = m_pcs->GetNodeValueIndex("DENSITY2"); + // index_gas_density = m_pcs->GetNodeValueIndex("DENSITY2"); variable_index_Gas_dissolved = this->GetVariableIndex("RS"); variable_index_porevolume = this->GetVariableIndex("RPORV"); variable_index_water_saturation = this->GetVariableIndex("SWAT"); variable_index_Moles_CO2 = this->GetVariableIndex("MLSC2"); - variable_index_Gas_saturation = this->GetVariableIndex("SGAS"); // CB + variable_index_Gas_saturation = this->GetVariableIndex("SGAS"); // CB variable_index_Gas_pressure = this->GetVariableIndex("PRESSURE"); // CB if (variable_index_Gas_dissolved < 0) { - cout << - "Not all variables are existing in the eclipse output files that are necessary to write data back to e100!" + cout << "Not all variables are existing in the eclipse output files that are necessary to write data back to " + "e100!" << "\n"; return 0; } - if (((variable_index_porevolume < 0) || (variable_index_water_saturation < 0) || - (variable_index_Moles_CO2 < 0)) && (this->E100 == false)) + if (((variable_index_porevolume < 0) || (variable_index_water_saturation < 0) || (variable_index_Moles_CO2 < 0)) + && (this->E100 == false)) { - cout << - "Not all variables are existing in the eclipse output files that are necessary to write data back to e300!" + cout << "Not all variables are existing in the eclipse output files that are necessary to write data back to " + "e300!" << "\n"; return 0; } // Calculate CO2 in liquid Phase: RS kg/m³ water - //first, get the pcs - n_pcs = pcs_vector[this->ProcessIndex_CO2inLiquid]; + // first, get the pcs + n_pcs = pcs_vector[this->ProcessIndex_CO2inLiquid]; - // get index of species concentration in nodevaluevector of this process - //indexConcentration = pcs_vector[this->ProcessIndex_CO2inLiquid]->GetNodeValueIndex(pcs_vector[this->ProcessIndex_CO2inLiquid]->pcs_primary_function_name[0]) + 1; // +1: new timelevel + // get index of species concentration in nodevaluevector of this process + // indexConcentration = + // pcs_vector[this->ProcessIndex_CO2inLiquid]->GetNodeValueIndex(pcs_vector[this->ProcessIndex_CO2inLiquid]->pcs_primary_function_name[0]) + // + 1; // +1: new timelevel indexConcentration = n_pcs->GetNodeValueIndex(n_pcs->pcs_primary_function_name[0]) + 1; // +1: new timelevel - //WTP_CB: new way to get the total number of nodes in the mesh since nod_val_vector is not suitable anymore - //for(unsigned long i = 0; i < pcs_vector[this->ProcessIndex_CO2inLiquid]->nod_val_vector.size(); i++){ - for(long i = 0; i < nnodes; i++){ - - //Read CO2 density - // check if concentration are positive - //if (pcs_vector[this->ProcessIndex_CO2inLiquid]->GetNodeValue(i, indexConcentration) < 0) { - if (n_pcs->GetNodeValue(i, indexConcentration) < 0) { - cout << "The CO2 concentration after the reactions is negativ!" << "\n"; - cout << "Node: " << i << " RS_alt: " << this->NodeData[i]->CO2inLiquid << " DIC: " << n_pcs->GetNodeValue(i, indexConcentration); - //system("Pause"); - return 0; - } - if (this->NodeData[i]->CO2inLiquid < 0) { - cout << "The CO2 concentration from Eclipse is negativ!" << "\n"; - cout << "Node: " << i << " RS_alt: " << this->NodeData[i]->CO2inLiquid << " DIC: " << n_pcs->GetNodeValue(i, indexConcentration); - //system("Pause"); - return 0; - } - - - //recalculate dissolve gas: RS [m³gas/m³water] = c_CO2 [mol/m³water] * (Molweight_CO2 [g/mol] * 1e-3 [kg/g]) / gas_density[kg/m³gas] - //this->NodeData[i]->phase_density[phase2] = m_pcs->GetNodeValue(i, index_gas_density); - //this->NodeData[i]->deltaDIC = (pcs_vector[this->ProcessIndex_CO2inLiquid]->GetNodeValue(i, indexConcentration) * (Molweight_CO2 * 1e-3) / this->SurfaceCO2Density) - this->NodeData[i]->CO2inLiquid; - //RS = (pcs_vector[this->ProcessIndex_CO2inLiquid]->GetNodeValue(i, indexConcentration) * (Molweight_CO2 * 1e-3) / this->SurfaceCO2Density) ; - RS = (n_pcs->GetNodeValue(i, indexConcentration) * (Molweight_CO2 * 1e-3) / this->SurfaceCO2Density) ; - this->NodeData[i]->deltaDIC = RS - this->NodeData[i]->CO2inLiquid; - - //cout << "Node: " << i << " RS_alt: " << this->NodeData[i]->Gas_dissolved << " DIC: " << n_pcs->GetNodeValue(i, indexConcentration); + // WTP_CB: new way to get the total number of nodes in the mesh since nod_val_vector is not suitable anymore + // for(unsigned long i = 0; i < pcs_vector[this->ProcessIndex_CO2inLiquid]->nod_val_vector.size(); i++){ + for (long i = 0; i < nnodes; i++) + { + // Read CO2 density + // check if concentration are positive + // if (pcs_vector[this->ProcessIndex_CO2inLiquid]->GetNodeValue(i, indexConcentration) < 0) { + if (n_pcs->GetNodeValue(i, indexConcentration) < 0) + { + cout << "The CO2 concentration after the reactions is negativ!" + << "\n"; + cout << "Node: " << i << " RS_alt: " << this->NodeData[i]->CO2inLiquid + << " DIC: " << n_pcs->GetNodeValue(i, indexConcentration); + // system("Pause"); + return 0; + } + if (this->NodeData[i]->CO2inLiquid < 0) + { + cout << "The CO2 concentration from Eclipse is negativ!" + << "\n"; + cout << "Node: " << i << " RS_alt: " << this->NodeData[i]->CO2inLiquid + << " DIC: " << n_pcs->GetNodeValue(i, indexConcentration); + // system("Pause"); + return 0; + } + + // recalculate dissolve gas: RS [m³gas/m³water] = c_CO2 [mol/m³water] * (Molweight_CO2 [g/mol] * 1e-3 [kg/g]) / + // gas_density[kg/m³gas] + // this->NodeData[i]->phase_density[phase2] = m_pcs->GetNodeValue(i, index_gas_density); + // this->NodeData[i]->deltaDIC = (pcs_vector[this->ProcessIndex_CO2inLiquid]->GetNodeValue(i, + // indexConcentration) * (Molweight_CO2 * 1e-3) / this->SurfaceCO2Density) - this->NodeData[i]->CO2inLiquid; + // RS = (pcs_vector[this->ProcessIndex_CO2inLiquid]->GetNodeValue(i, indexConcentration) * (Molweight_CO2 * + // 1e-3) / this->SurfaceCO2Density) ; + RS = (n_pcs->GetNodeValue(i, indexConcentration) * (Molweight_CO2 * 1e-3) / this->SurfaceCO2Density); + this->NodeData[i]->deltaDIC = RS - this->NodeData[i]->CO2inLiquid; + + // cout << "Node: " << i << " RS_alt: " << this->NodeData[i]->Gas_dissolved << " DIC: " << + // n_pcs->GetNodeValue(i, indexConcentration); if (this->NodeData[i]->deltaDIC != 0) { - //neglect difference if it is too small - if (((fabs(this->NodeData[i]->deltaDIC) / - this->NodeData[i]->CO2inLiquid)) < epsilon) - //cout << " deltaDIC_alt: " << this->NodeData[i]->deltaDIC << " Fehler! " << "\n";; + // neglect difference if it is too small + if (((fabs(this->NodeData[i]->deltaDIC) / this->NodeData[i]->CO2inLiquid)) < epsilon) + // cout << " deltaDIC_alt: " << this->NodeData[i]->deltaDIC << " Fehler! " << "\n";; this->NodeData[i]->deltaDIC = 0; else /*this->NodeData[i]->CO2inLiquid = @@ -5359,13 +5285,13 @@ int CECLIPSEData::WriteDataBackToEclipse(CRFProcess* m_pcs, std::string folder) (Molweight_CO2 * 1e-3) / this->SurfaceCO2Density);*/ this->NodeData[i]->CO2inLiquid = RS; // SB redo wtp } - //cout << " RS_neu: " << this->NodeData[i]->Gas_dissolved << " deltaDIC: " << this->NodeData[i]->deltaDIC << "\n"; + // cout << " RS_neu: " << this->NodeData[i]->Gas_dissolved << " deltaDIC: " << this->NodeData[i]->deltaDIC << + // "\n"; if (this->NodeData[i]->CO2inLiquid < 0) { - cout << " RS_neu: " << this->NodeData[i]->CO2inLiquid << " deltaDIC: " << - this->NodeData[i]->deltaDIC << "\n"; - cout << " Fehler in Berechnung von DIC: " << - this->NodeData[i]->CO2inLiquid << "\n"; + cout << " RS_neu: " << this->NodeData[i]->CO2inLiquid << " deltaDIC: " << this->NodeData[i]->deltaDIC + << "\n"; + cout << " Fehler in Berechnung von DIC: " << this->NodeData[i]->CO2inLiquid << "\n"; } } @@ -5373,152 +5299,159 @@ int CECLIPSEData::WriteDataBackToEclipse(CRFProcess* m_pcs, std::string folder) // CB Return delta Gas Saturation // get index of gas sat in nodevaluevector of this process idx = m_pcs->GetNodeValueIndex("SATURATION1") + 1; // +1: new timelevel - for(long i = 0; i < nnodes; i++){ - // get the node values old and new - value_old = NodeData[i]->phase_saturation[phase2]; - value = 1 - m_pcs->GetNodeValue(i, idx); - // Check consistency - if ((value < 0) || (value > 1)) { - cout << "The CO2 Saturation after the reactions is beyond physical limts: " << "\n"; - cout << "Node: " << i << " Sgas_old: " << value_old << " Sgas_new: " << value << "\n"; - return 0; - } - if ((value_old < 0) || (value_old > 1) ) { - cout << "The CO2 Saturation from Eclipse is beyond physical limts: " << "\n"; - cout << "Node: " << i << " Sgas_old: " << value_old << " Sgas_new: " << value << "\n"; - return 0; - } - - //calculate change of Sgas - NodeData[i]->deltaSat = value - value_old; - if (NodeData[i]->deltaSat != 0) { - //neglect difference if it is too small - if ((fabs(NodeData[i]->deltaSat) / value_old) < epsilon) { - //cout << " deltaDIC_alt: " << this->NodeData[i]->deltaDIC << " Fehler! " << "\n";; - NodeData[i]->deltaSat = 0; - } - else // set the new Sgas value to NodeData - NodeData[i]->phase_saturation[phase2] = value; - } - if ((NodeData[i]->phase_saturation[phase2] < 0) || (NodeData[i]->phase_saturation[phase2] > 1)){ - cout << " Sgas_neu: " << NodeData[i]->phase_saturation[phase2] << " deltaSat: " << NodeData[i]->deltaSat << "\n"; - cout << " Fehler in Berechnung von Sgas: " << NodeData[i]->phase_saturation[phase2] << "\n"; - } + for (long i = 0; i < nnodes; i++) + { + // get the node values old and new + value_old = NodeData[i]->phase_saturation[phase2]; + value = 1 - m_pcs->GetNodeValue(i, idx); + // Check consistency + if ((value < 0) || (value > 1)) + { + cout << "The CO2 Saturation after the reactions is beyond physical limts: " + << "\n"; + cout << "Node: " << i << " Sgas_old: " << value_old << " Sgas_new: " << value << "\n"; + return 0; + } + if ((value_old < 0) || (value_old > 1)) + { + cout << "The CO2 Saturation from Eclipse is beyond physical limts: " + << "\n"; + cout << "Node: " << i << " Sgas_old: " << value_old << " Sgas_new: " << value << "\n"; + return 0; + } + + // calculate change of Sgas + NodeData[i]->deltaSat = value - value_old; + if (NodeData[i]->deltaSat != 0) + { + // neglect difference if it is too small + if ((fabs(NodeData[i]->deltaSat) / value_old) < epsilon) + { + // cout << " deltaDIC_alt: " << this->NodeData[i]->deltaDIC << " Fehler! " << "\n";; + NodeData[i]->deltaSat = 0; + } + else // set the new Sgas value to NodeData + NodeData[i]->phase_saturation[phase2] = value; + } + if ((NodeData[i]->phase_saturation[phase2] < 0) || (NodeData[i]->phase_saturation[phase2] > 1)) + { + cout << " Sgas_neu: " << NodeData[i]->phase_saturation[phase2] << " deltaSat: " << NodeData[i]->deltaSat + << "\n"; + cout << " Fehler in Berechnung von Sgas: " << NodeData[i]->phase_saturation[phase2] << "\n"; + } } // CB Return delta Pressure // get index of gas sat in nodevaluevector of this process idx = m_pcs->GetNodeValueIndex("PRESSURE2") + 1; // +1: new timelevel - for(long i = 0; i < nnodes; i++){ - // get the node values old and new - value_old = NodeData[i]->phase_pressure[phase2]; - value = m_pcs->GetNodeValue(i, idx); - // Check consistency - if (value < 0) { - cout << "The CO2 Gas Pressure after the reactions is beyond physical limts: " << "\n"; - cout << "Node: " << i << " PRESSURE2_old: " << value_old << " PRESSURE2_new: " << value << "\n"; - return 0; - } - if (value_old < 0) { - cout << "The CO2 Gas Pressure from Eclipse is beyond physical limts: " << "\n"; - cout << "Node: " << i << " PRESSURE2_old: " << value_old << " PRESSURE2_new: " << value << "\n"; - return 0; - } - - //calculate change of PRESSURE2 - NodeData[i]->deltaPress = value - value_old; - if (NodeData[i]->deltaPress != 0) { - //neglect difference if it is too small - if ((fabs(NodeData[i]->deltaPress) / value_old) < epsilon) { - //cout << " deltaDIC_alt: " << this->NodeData[i]->deltaDIC << " Fehler! " << "\n";; - NodeData[i]->deltaPress = 0; - } - else // set the new Sgas value to NodeData - NodeData[i]->phase_pressure[phase2] = value; - } - if (NodeData[i]->phase_pressure[phase2] < 0){ - cout << " PRESSURE2_neu: " << NodeData[i]->phase_pressure[phase2] << " deltaPress: " << NodeData[i]->deltaPress << "\n"; - cout << " Fehler in Berechnung von PRESSURE2: " << NodeData[i]->phase_pressure[phase2] << "\n"; - } - } + for (long i = 0; i < nnodes; i++) + { + // get the node values old and new + value_old = NodeData[i]->phase_pressure[phase2]; + value = m_pcs->GetNodeValue(i, idx); + // Check consistency + if (value < 0) + { + cout << "The CO2 Gas Pressure after the reactions is beyond physical limts: " + << "\n"; + cout << "Node: " << i << " PRESSURE2_old: " << value_old << " PRESSURE2_new: " << value << "\n"; + return 0; + } + if (value_old < 0) + { + cout << "The CO2 Gas Pressure from Eclipse is beyond physical limts: " + << "\n"; + cout << "Node: " << i << " PRESSURE2_old: " << value_old << " PRESSURE2_new: " << value << "\n"; + return 0; + } + // calculate change of PRESSURE2 + NodeData[i]->deltaPress = value - value_old; + if (NodeData[i]->deltaPress != 0) + { + // neglect difference if it is too small + if ((fabs(NodeData[i]->deltaPress) / value_old) < epsilon) + { + // cout << " deltaDIC_alt: " << this->NodeData[i]->deltaDIC << " Fehler! " << "\n";; + NodeData[i]->deltaPress = 0; + } + else // set the new Sgas value to NodeData + NodeData[i]->phase_pressure[phase2] = value; + } + if (NodeData[i]->phase_pressure[phase2] < 0) + { + cout << " PRESSURE2_neu: " << NodeData[i]->phase_pressure[phase2] + << " deltaPress: " << NodeData[i]->deltaPress << "\n"; + cout << " Fehler in Berechnung von PRESSURE2: " << NodeData[i]->phase_pressure[phase2] << "\n"; + } + } - //interpolate change of RS from nodes to elements - //for (unsigned long i = 0; i < m_msh->ele_vector.size(); i++) - for (long i = 0; i< nele; i++) // SB redo wtp + // interpolate change of RS from nodes to elements + // for (unsigned long i = 0; i < m_msh->ele_vector.size(); i++) + for (long i = 0; i < nele; i++) // SB redo wtp { m_element = m_msh->ele_vector[i]; m_element->GetNodes(vec_element_nodes); delta_gas_dissolved = 0.0; - weight = float(1.0 / vec_element_nodes.Size()); //arithmetic average SB redo wtp - //cout << "\n"; + weight = float(1.0 / vec_element_nodes.Size()); // arithmetic average SB redo wtp + // cout << "\n"; for (long j = 0; j < long(vec_element_nodes.Size()); j++) { - //cout << " Node: " << vec_element_nodes[j]->GetIndex() << " RS: " << this->NodeData[vec_element_nodes[j]->GetIndex()]->deltaDIC << "\n"; - //weight = float(1.0 / vec_element_nodes.Size()); //arithmetic average + // cout << " Node: " << vec_element_nodes[j]->GetIndex() << " RS: " << + // this->NodeData[vec_element_nodes[j]->GetIndex()]->deltaDIC << "\n"; + // weight = float(1.0 / vec_element_nodes.Size()); //arithmetic average delta_gas_dis = this->NodeData[vec_element_nodes[j]->GetIndex()]->deltaDIC; delta_gas_dissolved += delta_gas_dis * weight; } if (delta_gas_dissolved < 0) - //check if delta_gas_dissolved is not larger than the available amount of CO2 - if (fabs(delta_gas_dissolved) > - (this->Data[i][variable_index_Gas_dissolved] - epsilon)) + // check if delta_gas_dissolved is not larger than the available amount of CO2 + if (fabs(delta_gas_dissolved) > (this->Data[i][variable_index_Gas_dissolved] - epsilon)) { - cout << - "The amount of CO2 removed from water is larger than the available amount of CO2! The value is corrected!" + cout << "The amount of CO2 removed from water is larger than the available amount of CO2! The value is " + "corrected!" << "\n"; for (long j = 0; j < long(vec_element_nodes.Size()); j++) - cout << " Node: " << - vec_element_nodes[j]->GetIndex() << " RS: " << - this->NodeData[vec_element_nodes[j]->GetIndex()]->deltaDIC - << "\n"; - cout << " Element: " << i << " deltaDIC: " << - delta_gas_dissolved << " RS_alt: " << - this->Data[i][variable_index_Gas_dissolved]; + cout << " Node: " << vec_element_nodes[j]->GetIndex() + << " RS: " << this->NodeData[vec_element_nodes[j]->GetIndex()]->deltaDIC << "\n"; + cout << " Element: " << i << " deltaDIC: " << delta_gas_dissolved + << " RS_alt: " << this->Data[i][variable_index_Gas_dissolved]; delta_gas_dissolved = -this->Data[i][variable_index_Gas_dissolved]; } if (delta_gas_dissolved != 0) { - //cout << " Element: " << i << " deltaDIC: " << delta_gas_dissolved << " RS_alt: " << this->Data[i][variable_index_Gas_dissolved]; - if ((fabs(delta_gas_dissolved) / - this->Data[i][variable_index_Gas_dissolved]) < epsilon) + // cout << " Element: " << i << " deltaDIC: " << delta_gas_dissolved << " RS_alt: " << + // this->Data[i][variable_index_Gas_dissolved]; + if ((fabs(delta_gas_dissolved) / this->Data[i][variable_index_Gas_dissolved]) < epsilon) { vecRS.push_back(this->Data[i][variable_index_Gas_dissolved]); if (this->E100 == false) - //stores the change of the total moles of CO2 if e300 is used + // stores the change of the total moles of CO2 if e300 is used vec_T_CO2.push_back(this->Data[i][variable_index_Moles_CO2]); } else { - vecRS.push_back( - this->Data[i][variable_index_Gas_dissolved] + - delta_gas_dissolved); + vecRS.push_back(this->Data[i][variable_index_Gas_dissolved] + delta_gas_dissolved); if (this->E100 == false) { - //stores the change of the total moles of CO2 if e300 is used - //1. step: calculate mole of dissolved CO2 in m� liquid - //c_CO2inLiquid [mol/m�liquid] = RS [m�CO2 / m�liquid] * rho_CO2 [kgCO2 / m�CO2] * 1000 [gCO2 / kgCO2] / M_CO2 [gCO2 / molCO2] - deltaT_CO2 = delta_gas_dissolved * - this->SurfaceCO2Density * 1000 / - this->Molweight_CO2; - //2. step: calculate total moles of CO2 - //T_CO2 [mol] = c_CO2inLiquid [molCO2 / m�liquid] * s_CO2 [m�liquid / m�PV] * V_PV [m�PV] - //deltaT_CO2 = deltaT_CO2 * this->Data[i][variable_index_water_saturation] * this->Data[i][variable_index_porevolume]; - //cout << " water saturation: " << this->Data[i][variable_index_water_saturation] << " pore volume: " << this->Data[i][variable_index_porevolume] << "\n"; - //T_CO2 [mol / L PV] = c_CO2inLiquid [molCO2 / m�liquid] * s_CO2 [m�liquid / m�PV] * 0.001 [m�PV / L PV] - deltaT_CO2 = deltaT_CO2 * - this->Data[i][variable_index_water_saturation] - * 0.001; + // stores the change of the total moles of CO2 if e300 is used + // 1. step: calculate mole of dissolved CO2 in m� liquid + // c_CO2inLiquid [mol/m�liquid] = RS [m�CO2 / m�liquid] * rho_CO2 [kgCO2 / m�CO2] * 1000 [gCO2 / + // kgCO2] / M_CO2 [gCO2 / molCO2] + deltaT_CO2 = delta_gas_dissolved * this->SurfaceCO2Density * 1000 / this->Molweight_CO2; + // 2. step: calculate total moles of CO2 + // T_CO2 [mol] = c_CO2inLiquid [molCO2 / m�liquid] * s_CO2 [m�liquid / m�PV] * V_PV [m�PV] + // deltaT_CO2 = deltaT_CO2 * this->Data[i][variable_index_water_saturation] * + // this->Data[i][variable_index_porevolume]; + // cout << " water saturation: " << this->Data[i][variable_index_water_saturation] << " pore volume: + // " << this->Data[i][variable_index_porevolume] << "\n"; + // T_CO2 [mol / L PV] = c_CO2inLiquid [molCO2 / m�liquid] * s_CO2 [m�liquid / m�PV] * 0.001 [m�PV / + // L PV] + deltaT_CO2 = deltaT_CO2 * this->Data[i][variable_index_water_saturation] * 0.001; if (deltaT_CO2 < 0) - if (fabs(deltaT_CO2) > - (this->Data[i][variable_index_Moles_CO2] - - epsilon)) - deltaT_CO2 = - -this->Data[i][ - variable_index_Moles_CO2]; - deltaT_CO2 = this->Data[i][variable_index_Moles_CO2] + - deltaT_CO2; + if (fabs(deltaT_CO2) > (this->Data[i][variable_index_Moles_CO2] - epsilon)) + deltaT_CO2 = -this->Data[i][variable_index_Moles_CO2]; + deltaT_CO2 = this->Data[i][variable_index_Moles_CO2] + deltaT_CO2; vec_T_CO2.push_back(deltaT_CO2); } } @@ -5527,112 +5460,131 @@ int CECLIPSEData::WriteDataBackToEclipse(CRFProcess* m_pcs, std::string folder) { vecRS.push_back(this->Data[i][variable_index_Gas_dissolved]); if (this->E100 == false) - //stores the change of the total moles of CO2 if e300 is used + // stores the change of the total moles of CO2 if e300 is used vec_T_CO2.push_back(this->Data[i][variable_index_Moles_CO2]); } if (vecRS[vecRS.size() - 1] < 0) { - cout << "The new calculated dissolved amount of CO2 (RS) is negative!" << - "\n"; - //system("Pause"); + cout << "The new calculated dissolved amount of CO2 (RS) is negative!" + << "\n"; + // system("Pause"); return 0; } - //cout << " Element: " << i << " RS_neu: " << vecRS[vecRS.size()-1] << "\n"; + // cout << " Element: " << i << " RS_neu: " << vecRS[vecRS.size()-1] << "\n"; } // CB interpolate change of Sgas from nodes to elements - for (long i = 0; i < nele; i++) { - m_element = m_msh->ele_vector[i]; - m_element->GetNodes(vec_element_nodes); - delta_gas_dissolved = 0.0; - weight = float(1.0 / vec_element_nodes.Size()); //arithmetic average - // accumulate node contributions to element - for (long j = 0; j < long(vec_element_nodes.Size()); j++) { - delta_gas_dis = NodeData[vec_element_nodes[j]->GetIndex()]->deltaSat; - delta_gas_dissolved += delta_gas_dis * weight; - } - if (delta_gas_dissolved < 0) { // decrease in Sgas - //check if delta_gas_dissolved is not larger than the available volume of CO2 gas phase - if (fabs(delta_gas_dissolved) > (Data[i][variable_index_Gas_saturation] - epsilon)) { - cout << "The volume of CO2 gas phase (Sat) removed is larger than the available volume of CO2 gas! The value is corrected!" << "\n"; - for (long j = 0; j < long(vec_element_nodes.Size()); j++) - cout << " Node: " << vec_element_nodes[j]->GetIndex() << " Sgas: " << NodeData[vec_element_nodes[j]->GetIndex()]->deltaSat << "\n"; - cout << " Element: " << i << " deltaSat: " << delta_gas_dissolved << " Sgas_old: " << Data[i][variable_index_Gas_saturation]; - delta_gas_dissolved = - Data[i][variable_index_Gas_saturation]; // limit the delta - } - } - // here set the delta ro element - if (delta_gas_dissolved != 0) { - if ((fabs(delta_gas_dissolved) / Data[i][variable_index_Gas_saturation]) < epsilon) - Sats.push_back(Data[i][variable_index_Gas_saturation]); // old satu - else - Sats.push_back(Data[i][variable_index_Gas_saturation] + delta_gas_dissolved); - } - else - Sats.push_back(Data[i][variable_index_Gas_saturation]); - if (Sats[Sats.size() - 1] < 0) { - cout << "The new calculated Saturation of CO2 gas (SGAS) is negative!" << "\n"; - return 0; - } - } - - // CB interpolate change of PRESSURE2 from nodes to elements - for (long i = 0; i < nele; i++) { - m_element = m_msh->ele_vector[i]; - m_element->GetNodes(vec_element_nodes); - delta_gas_dissolved = 0.0; - weight = float(1.0 / vec_element_nodes.Size()); //arithmetic average - // accumulate node contributions to element - for (long j = 0; j < long(vec_element_nodes.Size()); j++) { - delta_gas_dis = NodeData[vec_element_nodes[j]->GetIndex()]->deltaPress; - delta_gas_dissolved += delta_gas_dis * weight; - } - if (delta_gas_dissolved < 0) { // decrease in Pressure2 - //check if delta_gas_dissolved is not larger than the old Pressure of CO2 gas phase - if (fabs(delta_gas_dissolved) > (Data[i][variable_index_Gas_pressure] - epsilon)) { - cout << "The pressure reduction of CO2 gas phase is larger than the old pressure of CO2 gas! The value is corrected!" << "\n"; - for (long j = 0; j < long(vec_element_nodes.Size()); j++) - cout << " Node: " << vec_element_nodes[j]->GetIndex() << " Press: " << NodeData[vec_element_nodes[j]->GetIndex()]->deltaPress << "\n"; - cout << " Element: " << i << " deltaPress: " << delta_gas_dissolved << " Press_old: " << Data[i][variable_index_Gas_pressure]; - delta_gas_dissolved = - Data[i][variable_index_Gas_pressure]; // limit the delta - } - } - // here set the delta ro element - if (delta_gas_dissolved != 0) { - if ((fabs(delta_gas_dissolved) / Data[i][variable_index_Gas_pressure]) < epsilon) - Press.push_back(Data[i][variable_index_Gas_pressure]); // old satu - else - Press.push_back(Data[i][variable_index_Gas_pressure] + delta_gas_dissolved); - } - else - Press.push_back(Data[i][variable_index_Gas_pressure]); - if (Press[Press.size() - 1] < 0) { - cout << "The new calculated Pressure of CO2 gas (PRESSURE) is negative!" << "\n"; - return 0; - } - // Pa -> bar: /10000 - Press[i] /= 1.0e+5; - } - - //write RS, SGAS, PRESSURE, POROPERM Data into the Eclipse restart file + for (long i = 0; i < nele; i++) + { + m_element = m_msh->ele_vector[i]; + m_element->GetNodes(vec_element_nodes); + delta_gas_dissolved = 0.0; + weight = float(1.0 / vec_element_nodes.Size()); // arithmetic average + // accumulate node contributions to element + for (long j = 0; j < long(vec_element_nodes.Size()); j++) + { + delta_gas_dis = NodeData[vec_element_nodes[j]->GetIndex()]->deltaSat; + delta_gas_dissolved += delta_gas_dis * weight; + } + if (delta_gas_dissolved < 0) + { // decrease in Sgas + // check if delta_gas_dissolved is not larger than the available volume of CO2 gas phase + if (fabs(delta_gas_dissolved) > (Data[i][variable_index_Gas_saturation] - epsilon)) + { + cout << "The volume of CO2 gas phase (Sat) removed is larger than the available volume of CO2 gas! The " + "value is corrected!" + << "\n"; + for (long j = 0; j < long(vec_element_nodes.Size()); j++) + cout << " Node: " << vec_element_nodes[j]->GetIndex() + << " Sgas: " << NodeData[vec_element_nodes[j]->GetIndex()]->deltaSat << "\n"; + cout << " Element: " << i << " deltaSat: " << delta_gas_dissolved + << " Sgas_old: " << Data[i][variable_index_Gas_saturation]; + delta_gas_dissolved = -Data[i][variable_index_Gas_saturation]; // limit the delta + } + } + // here set the delta ro element + if (delta_gas_dissolved != 0) + { + if ((fabs(delta_gas_dissolved) / Data[i][variable_index_Gas_saturation]) < epsilon) + Sats.push_back(Data[i][variable_index_Gas_saturation]); // old satu + else + Sats.push_back(Data[i][variable_index_Gas_saturation] + delta_gas_dissolved); + } + else + Sats.push_back(Data[i][variable_index_Gas_saturation]); + if (Sats[Sats.size() - 1] < 0) + { + cout << "The new calculated Saturation of CO2 gas (SGAS) is negative!" + << "\n"; + return 0; + } + } + + // CB interpolate change of PRESSURE2 from nodes to elements + for (long i = 0; i < nele; i++) + { + m_element = m_msh->ele_vector[i]; + m_element->GetNodes(vec_element_nodes); + delta_gas_dissolved = 0.0; + weight = float(1.0 / vec_element_nodes.Size()); // arithmetic average + // accumulate node contributions to element + for (long j = 0; j < long(vec_element_nodes.Size()); j++) + { + delta_gas_dis = NodeData[vec_element_nodes[j]->GetIndex()]->deltaPress; + delta_gas_dissolved += delta_gas_dis * weight; + } + if (delta_gas_dissolved < 0) + { // decrease in Pressure2 + // check if delta_gas_dissolved is not larger than the old Pressure of CO2 gas phase + if (fabs(delta_gas_dissolved) > (Data[i][variable_index_Gas_pressure] - epsilon)) + { + cout << "The pressure reduction of CO2 gas phase is larger than the old pressure of CO2 gas! The value " + "is corrected!" + << "\n"; + for (long j = 0; j < long(vec_element_nodes.Size()); j++) + cout << " Node: " << vec_element_nodes[j]->GetIndex() + << " Press: " << NodeData[vec_element_nodes[j]->GetIndex()]->deltaPress << "\n"; + cout << " Element: " << i << " deltaPress: " << delta_gas_dissolved + << " Press_old: " << Data[i][variable_index_Gas_pressure]; + delta_gas_dissolved = -Data[i][variable_index_Gas_pressure]; // limit the delta + } + } + // here set the delta ro element + if (delta_gas_dissolved != 0) + { + if ((fabs(delta_gas_dissolved) / Data[i][variable_index_Gas_pressure]) < epsilon) + Press.push_back(Data[i][variable_index_Gas_pressure]); // old satu + else + Press.push_back(Data[i][variable_index_Gas_pressure] + delta_gas_dissolved); + } + else + Press.push_back(Data[i][variable_index_Gas_pressure]); + if (Press[Press.size() - 1] < 0) + { + cout << "The new calculated Pressure of CO2 gas (PRESSURE) is negative!" + << "\n"; + return 0; + } + // Pa -> bar: /10000 + Press[i] /= 1.0e+5; + } + + // write RS, SGAS, PRESSURE, POROPERM Data into the Eclipse restart file if (this->E100 == true) { - //write RS into the Eclipse restart file - //Filename = folder + "TemporaryResults.F" + AddZero(m_pcs->Tim->step_current - 1, - Filename = folder + "TEMPORARYRESULTS.F" + AddZero(m_pcs->Tim->step_current - 1, - 4, - true); + // write RS into the Eclipse restart file + // Filename = folder + "TemporaryResults.F" + AddZero(m_pcs->Tim->step_current - 1, + Filename = folder + "TEMPORARYRESULTS.F" + AddZero(m_pcs->Tim->step_current - 1, 4, true); Keyword = " 'RS"; vecString.clear(); // SB redo wtp - //check consitency of data + // check consitency of data if (int(vecRS.size()) != this->elements) { - cout << - "There was not the right number of RS data found during writing to Eclipse F-File!" + cout << "There was not the right number of RS data found during writing to Eclipse F-File!" << "\n"; - //system("Pause"); // SB redo wtp + // system("Pause"); // SB redo wtp return 0; } for (long i = 0; i < this->elements; i = i + 4) @@ -5659,27 +5611,24 @@ int CECLIPSEData::WriteDataBackToEclipse(CRFProcess* m_pcs, std::string folder) } if (ReplaceASectionInFile(Filename, Keyword, vecString, false) == false) { - cout << "Replacing section " << Keyword << " in the file: " << Filename << - " didn't work!" << "\n"; - //system("Pause"); // SB redo wtp + cout << "Replacing section " << Keyword << " in the file: " << Filename << " didn't work!" + << "\n"; + // system("Pause"); // SB redo wtp return 0; } } if (this->E100 == false) { - Filename = folder + "TemporaryResults.F" + AddZero(m_pcs->Tim->step_current - 1, - 4, - true); + Filename = folder + "TemporaryResults.F" + AddZero(m_pcs->Tim->step_current - 1, 4, true); Keyword = " 'MLSC2"; vecString.clear(); - //check consitency of data + // check consitency of data if (int(vecRS.size()) != this->elements) { - cout << - "There was not the right number of RS data found during writing to Eclipse F-File!" + cout << "There was not the right number of RS data found during writing to Eclipse F-File!" << "\n"; - //system("Pause"); + // system("Pause"); return 0; } for (long i = 0; i < this->elements; i = i + 4) @@ -5707,229 +5656,287 @@ int CECLIPSEData::WriteDataBackToEclipse(CRFProcess* m_pcs, std::string folder) if (ReplaceASectionInFile(Filename, Keyword, vecString, false) == false) { - cout << "Replacing section " << Keyword << " in the file: " << Filename << - " didn't work!" << "\n"; - //system("Pause"); // SB redo wtp + cout << "Replacing section " << Keyword << " in the file: " << Filename << " didn't work!" + << "\n"; + // system("Pause"); // SB redo wtp return 0; } } // SB redo wtp // CB SGAS independent of e100 / e300 - Keyword = " 'SGAS"; - vecString.clear(); - //check consitency of data - if (int(Sats.size()) != this->elements) { - cout << "There was not the right number of SGAS data found during writing to Eclipse F-File!" << "\n"; - //system("Pause"); - return 0; - } - for (long i = 0; i < this->elements; i = i + 4) { - tempstring = ""; - j_max = 4; - if ((this->elements - i) < 4) j_max = (this->elements - i); - for (int j = 0; j < j_max; j++) { - tempstring += " "; // 1lz - tempNumber = this->RoundEXP(Sats[i + j], 8); - tempstring += this->AddZero(tempNumber.Number, 8, false); // not for poroperm - tempstring += "E"; - if (tempNumber.Exponent >= 0) { - tempstring += "+"; - tempstring += this->AddZero(tempNumber.Exponent, 2, true); - } - else - tempstring += this->AddZero(tempNumber.Exponent, 3, true); - } - vecString.push_back(tempstring); - } - if (ReplaceASectionInFile(Filename, Keyword, vecString, false) == false) { - cout << "Replacing section " << Keyword << " in the file: " << Filename << " didn't work!" << "\n"; - //system("Pause"); - return 0; - } - - // CB PRESS independent of e100 / e300 - Keyword = " 'PRESSURE"; - vecString.clear(); - //check consitency of data - if (int(Press.size()) != this->elements) { - cout << "There was not the right number of PRESSURE data found during writing to Eclipse F-File!" << "\n"; - //system("Pause"); - return 0; - } - for (long i = 0; i < this->elements; i = i + 4) { - tempstring = ""; - j_max = 4; - if ((this->elements - i) < 4) j_max = (this->elements - i); - for (int j = 0; j < j_max; j++) { - tempstring += " "; // 1lz - tempNumber = this->RoundEXP(Press[i + j], 8); - tempstring += this->AddZero(tempNumber.Number, 8, false); // not for poroperm - tempstring += "E"; - if (tempNumber.Exponent >= 0) { - tempstring += "+"; - tempstring += this->AddZero(tempNumber.Exponent, 2, true); - } - else - tempstring += this->AddZero(tempNumber.Exponent, 3, true); - } - vecString.push_back(tempstring); - } - if (ReplaceASectionInFile(Filename, Keyword, vecString, false) == false) { - cout << "Replacing section " << Keyword << " in the file: " << Filename << " didn't work!" << "\n"; - //system("Pause"); - return 0; - } - - // CB Poropermdata independent of e100 / e300 - //for (long i = 0; i < mmp_vector.size(); i++) { - for (std::size_t i = 0; i < mmp_vector.size(); i++) { // WTP - if(mmp_vector[i]->porosity_model==13){ - poroflag=true; // poro update from geochemistry - idx_n = m_pcs->GetElementValueIndex("POROSITY") + 1; - if(idx_n<0) cout << " Warning in Eclipse: No POROSITY ele index found with PCS " << m_pcs->getProcessType() << "." << "\n"; - } - if(mmp_vector[i]->permeability_porosity_model==8) { // perm update from porochange - permxxflag=true; - } - } - if (permxxflag) { //write perm into the Eclipse restart file - j_max = 4; - count = 0; - vecString.clear(); - vecString2.clear(); - vecString3.clear(); - for (long i = 0; i < long(eclipse_ele_active_flag.size()); i = i + j_max) { - tempstring = ""; - tempstring2 = ""; - tempstring3 = ""; - if (long(eclipse_ele_active_flag.size()) - i < j_max) - j_max = (long(eclipse_ele_active_flag.size()) - i); - for (int j = 0; j < j_max; j++) { - tempstring += " "; // 1lz - tempstring2 += " "; // 1lz - tempstring3 += " "; // 1lz - if(eclipse_ele_active_flag[i]){ - tensor = mmp_vector[0]->PermeabilityTensor(count); - //x - sstream << fixed << scientific << tensor[0] /9.869233e-16; // m²->mD - tempstring += sstream.str(); - sstream.str(""); sstream.clear(); - //y - sstream << fixed << scientific << tensor[4] /9.869233e-16; - tempstring2 += sstream.str(); - sstream.str(""); sstream.clear(); - //z - sstream << fixed << scientific << tensor[8] /9.869233e-16; - tempstring3 += sstream.str(); - sstream.str(""); sstream.clear(); - count++; - } - else{ - tempstring += "0.123"; - tempstring2 += "0.123"; - tempstring3 += "0.123"; - } - } - vecString.push_back(tempstring); - vecString2.push_back(tempstring2); - vecString3.push_back(tempstring3); - } - if(PoroPermIncludeFile) Filename = folder + "GRID_PROPS.INC" ; - else Filename = folder + "ECL_RESTART.DATA" ; - - if(this->Radialmodell) Keyword = "PERMR"; - else Keyword = "PERMX"; - - if(PoroPermIncludeFile) WriteIncludeFile(Filename, Keyword, vecString, false); - else if (ReplaceASectionInFile(Filename, Keyword, vecString, false) == false) { - cout << "Replacing section " << Keyword << " in the file: " << Filename << " didn't work!" << "\n"; - //system("Pause"); - return 0; - } - if(this->Radialmodell) Keyword = "PERMTHT"; - else Keyword = "PERMY"; - - if(PoroPermIncludeFile) WriteIncludeFile(Filename, Keyword, vecString2, true); - else if (ReplaceASectionInFile(Filename, Keyword, vecString2, false) == false) { - cout << "Replacing section " << Keyword << " in the file: " << Filename << " didn't work!" << "\n"; - //system("Pause"); - return 0; - } - Keyword = "PERMZ"; - if(PoroPermIncludeFile) WriteIncludeFile(Filename, Keyword, vecString3, true); - else if (ReplaceASectionInFile(Filename, Keyword, vecString3, false) == false) { - cout << "Replacing section " << Keyword << " in the file: " << Filename << " didn't work!" << "\n"; - //system("Pause"); - return 0; - } - } - if (poroflag) { //write poro into the Eclipse restart file - j_max = 4; - count = 0; - vecString.clear(); - - for (long i = 0; i < long(eclipse_ele_active_flag.size()); i = i + j_max) { - tempstring = ""; - if (long(eclipse_ele_active_flag.size()) - i < j_max) - j_max = (long(eclipse_ele_active_flag.size()) - i); - for (int j = 0; j < j_max; j++) { - tempstring += " "; // 1lz - if(eclipse_ele_active_flag[i]){ - sstream << fixed << scientific << m_pcs->GetElementValue(count, idx_n); - tempstring += sstream.str(); - count++; - sstream.str(""); sstream.clear(); - } - else - tempstring += "0.123"; - } - vecString.push_back(tempstring); - } - Keyword = "PORO"; - if(PoroPermIncludeFile) Filename = folder + "GRID_PROPS.INC" ; - else Filename = folder + "ECL_RESTART.DATA" ; - - if(PoroPermIncludeFile) WriteIncludeFile(Filename, Keyword, vecString, true); - else if (ReplaceASectionInFile(Filename, Keyword, vecString, false) == false) { - cout << "Replacing section " << Keyword << " in the file: " << Filename << " didn't work!" << "\n"; - //system("Pause"); - return 0; - } - } - - /// WTP: Write temperature file for eclipse using the 'TEMPI' keyword in Eclipse - /// if heattransport is used in OGS and the simulator is Eclipse. - /// Only works one way (OGS->Eclipse). - // should this be hard-coded or variable (heat transport in OGS but no coupling to Ecl) - if(T_Process == true) { - // setting bool flag for save function (not implemented yet) - this->TempIncludeFile = true; - // getting the process - l_pcs = PCSGet("HEAT_TRANSPORT"); - // get the correct index for the process - idx_T = l_pcs->GetNodeValueIndex("TEMPERATURE1")+1; - - // setting the correct filename for the temperature output - Filename = folder + "TEMP.INC" ; - // keyword to read the temperature within the ecl run - Keyword = "TEMPI"; - // clearing the temp storage vector - vecString.clear(); - - j_max = 4; - count = 0; - int ele_no = 0; - // running a loop over all, active and non-active elements of Eclipse - for (long i = 0; i < long(eclipse_ele_active_flag.size()); i = i + j_max) { - tempstring = ""; - if (long(eclipse_ele_active_flag.size()) - i < j_max) - j_max = (long(eclipse_ele_active_flag.size()) - i); - for (int j = 0; j < j_max; j++) { - tempstring += " "; - // if the current element is active e.g. also used in Geosys get the temperature - if(eclipse_ele_active_flag[i]){ - // here get the index of every node in the element + Keyword = " 'SGAS"; + vecString.clear(); + // check consitency of data + if (int(Sats.size()) != this->elements) + { + cout << "There was not the right number of SGAS data found during writing to Eclipse F-File!" + << "\n"; + // system("Pause"); + return 0; + } + for (long i = 0; i < this->elements; i = i + 4) + { + tempstring = ""; + j_max = 4; + if ((this->elements - i) < 4) + j_max = (this->elements - i); + for (int j = 0; j < j_max; j++) + { + tempstring += " "; // 1lz + tempNumber = this->RoundEXP(Sats[i + j], 8); + tempstring += this->AddZero(tempNumber.Number, 8, false); // not for poroperm + tempstring += "E"; + if (tempNumber.Exponent >= 0) + { + tempstring += "+"; + tempstring += this->AddZero(tempNumber.Exponent, 2, true); + } + else + tempstring += this->AddZero(tempNumber.Exponent, 3, true); + } + vecString.push_back(tempstring); + } + if (ReplaceASectionInFile(Filename, Keyword, vecString, false) == false) + { + cout << "Replacing section " << Keyword << " in the file: " << Filename << " didn't work!" + << "\n"; + // system("Pause"); + return 0; + } + + // CB PRESS independent of e100 / e300 + Keyword = " 'PRESSURE"; + vecString.clear(); + // check consitency of data + if (int(Press.size()) != this->elements) + { + cout << "There was not the right number of PRESSURE data found during writing to Eclipse F-File!" + << "\n"; + // system("Pause"); + return 0; + } + for (long i = 0; i < this->elements; i = i + 4) + { + tempstring = ""; + j_max = 4; + if ((this->elements - i) < 4) + j_max = (this->elements - i); + for (int j = 0; j < j_max; j++) + { + tempstring += " "; // 1lz + tempNumber = this->RoundEXP(Press[i + j], 8); + tempstring += this->AddZero(tempNumber.Number, 8, false); // not for poroperm + tempstring += "E"; + if (tempNumber.Exponent >= 0) + { + tempstring += "+"; + tempstring += this->AddZero(tempNumber.Exponent, 2, true); + } + else + tempstring += this->AddZero(tempNumber.Exponent, 3, true); + } + vecString.push_back(tempstring); + } + if (ReplaceASectionInFile(Filename, Keyword, vecString, false) == false) + { + cout << "Replacing section " << Keyword << " in the file: " << Filename << " didn't work!" + << "\n"; + // system("Pause"); + return 0; + } + + // CB Poropermdata independent of e100 / e300 + // for (long i = 0; i < mmp_vector.size(); i++) { + for (std::size_t i = 0; i < mmp_vector.size(); i++) + { // WTP + if (mmp_vector[i]->porosity_model == 13) + { + poroflag = true; // poro update from geochemistry + idx_n = m_pcs->GetElementValueIndex("POROSITY") + 1; + if (idx_n < 0) + cout << " Warning in Eclipse: No POROSITY ele index found with PCS " << m_pcs->getProcessType() << "." + << "\n"; + } + if (mmp_vector[i]->permeability_porosity_model == 8) + { // perm update from porochange + permxxflag = true; + } + } + if (permxxflag) + { // write perm into the Eclipse restart file + j_max = 4; + count = 0; + vecString.clear(); + vecString2.clear(); + vecString3.clear(); + for (long i = 0; i < long(eclipse_ele_active_flag.size()); i = i + j_max) + { + tempstring = ""; + tempstring2 = ""; + tempstring3 = ""; + if (long(eclipse_ele_active_flag.size()) - i < j_max) + j_max = (long(eclipse_ele_active_flag.size()) - i); + for (int j = 0; j < j_max; j++) + { + tempstring += " "; // 1lz + tempstring2 += " "; // 1lz + tempstring3 += " "; // 1lz + if (eclipse_ele_active_flag[i]) + { + tensor = mmp_vector[0]->PermeabilityTensor(count); + // x + sstream << fixed << scientific << tensor[0] / 9.869233e-16; // m²->mD + tempstring += sstream.str(); + sstream.str(""); + sstream.clear(); + // y + sstream << fixed << scientific << tensor[4] / 9.869233e-16; + tempstring2 += sstream.str(); + sstream.str(""); + sstream.clear(); + // z + sstream << fixed << scientific << tensor[8] / 9.869233e-16; + tempstring3 += sstream.str(); + sstream.str(""); + sstream.clear(); + count++; + } + else + { + tempstring += "0.123"; + tempstring2 += "0.123"; + tempstring3 += "0.123"; + } + } + vecString.push_back(tempstring); + vecString2.push_back(tempstring2); + vecString3.push_back(tempstring3); + } + if (PoroPermIncludeFile) + Filename = folder + "GRID_PROPS.INC"; + else + Filename = folder + "ECL_RESTART.DATA"; + + if (this->Radialmodell) + Keyword = "PERMR"; + else + Keyword = "PERMX"; + + if (PoroPermIncludeFile) + WriteIncludeFile(Filename, Keyword, vecString, false); + else if (ReplaceASectionInFile(Filename, Keyword, vecString, false) == false) + { + cout << "Replacing section " << Keyword << " in the file: " << Filename << " didn't work!" + << "\n"; + // system("Pause"); + return 0; + } + if (this->Radialmodell) + Keyword = "PERMTHT"; + else + Keyword = "PERMY"; + + if (PoroPermIncludeFile) + WriteIncludeFile(Filename, Keyword, vecString2, true); + else if (ReplaceASectionInFile(Filename, Keyword, vecString2, false) == false) + { + cout << "Replacing section " << Keyword << " in the file: " << Filename << " didn't work!" + << "\n"; + // system("Pause"); + return 0; + } + Keyword = "PERMZ"; + if (PoroPermIncludeFile) + WriteIncludeFile(Filename, Keyword, vecString3, true); + else if (ReplaceASectionInFile(Filename, Keyword, vecString3, false) == false) + { + cout << "Replacing section " << Keyword << " in the file: " << Filename << " didn't work!" + << "\n"; + // system("Pause"); + return 0; + } + } + if (poroflag) + { // write poro into the Eclipse restart file + j_max = 4; + count = 0; + vecString.clear(); + + for (long i = 0; i < long(eclipse_ele_active_flag.size()); i = i + j_max) + { + tempstring = ""; + if (long(eclipse_ele_active_flag.size()) - i < j_max) + j_max = (long(eclipse_ele_active_flag.size()) - i); + for (int j = 0; j < j_max; j++) + { + tempstring += " "; // 1lz + if (eclipse_ele_active_flag[i]) + { + sstream << fixed << scientific << m_pcs->GetElementValue(count, idx_n); + tempstring += sstream.str(); + count++; + sstream.str(""); + sstream.clear(); + } + else + tempstring += "0.123"; + } + vecString.push_back(tempstring); + } + Keyword = "PORO"; + if (PoroPermIncludeFile) + Filename = folder + "GRID_PROPS.INC"; + else + Filename = folder + "ECL_RESTART.DATA"; + + if (PoroPermIncludeFile) + WriteIncludeFile(Filename, Keyword, vecString, true); + else if (ReplaceASectionInFile(Filename, Keyword, vecString, false) == false) + { + cout << "Replacing section " << Keyword << " in the file: " << Filename << " didn't work!" + << "\n"; + // system("Pause"); + return 0; + } + } + + /// WTP: Write temperature file for eclipse using the 'TEMPI' keyword in Eclipse + /// if heattransport is used in OGS and the simulator is Eclipse. + /// Only works one way (OGS->Eclipse). + // should this be hard-coded or variable (heat transport in OGS but no coupling to Ecl) + if (T_Process == true) + { + // setting bool flag for save function (not implemented yet) + this->TempIncludeFile = true; + // getting the process + l_pcs = PCSGet("HEAT_TRANSPORT"); + // get the correct index for the process + idx_T = l_pcs->GetNodeValueIndex("TEMPERATURE1") + 1; + + // setting the correct filename for the temperature output + Filename = folder + "TEMP.INC"; + // keyword to read the temperature within the ecl run + Keyword = "TEMPI"; + // clearing the temp storage vector + vecString.clear(); + + j_max = 4; + count = 0; + int ele_no = 0; + // running a loop over all, active and non-active elements of Eclipse + for (long i = 0; i < long(eclipse_ele_active_flag.size()); i = i + j_max) + { + tempstring = ""; + if (long(eclipse_ele_active_flag.size()) - i < j_max) + j_max = (long(eclipse_ele_active_flag.size()) - i); + for (int j = 0; j < j_max; j++) + { + tempstring += " "; + // if the current element is active e.g. also used in Geosys get the temperature + if (eclipse_ele_active_flag[i]) + { + // here get the index of every node in the element m_element = m_msh->ele_vector[ele_no]; m_element->GetNodes(vec_element_nodes); @@ -5937,7 +5944,8 @@ int CECLIPSEData::WriteDataBackToEclipse(CRFProcess* m_pcs, std::string folder) ele_temp = 0.0; weight = float(1.0 / vec_element_nodes.Size()); // getting the correct weight for each nodal value // run a loop over the number of nodes of the element - for (long k = 0; k < long(vec_element_nodes.Size()); k++) { + for (long k = 0; k < long(vec_element_nodes.Size()); k++) + { // save the node index of the nodes long loc_nd_idx = vec_element_nodes[k]->GetIndex(); // read the corresponging temperature @@ -5946,36 +5954,37 @@ int CECLIPSEData::WriteDataBackToEclipse(CRFProcess* m_pcs, std::string folder) ele_temp += temp_temp * weight; } // depending on the temperature unit used in Geosys it has to be converted to °C for Ecl - if(ele_temp < 273.15) + if (ele_temp < 273.15) ele_temp += 273.15; // or: if(temperature_unit != Celsius) - //ele_temp += 273.15; - sstream << fixed << scientific << ele_temp; //+ 273.15; + // ele_temp += 273.15; + sstream << fixed << scientific << ele_temp; //+ 273.15; tempstring += sstream.str(); count++; - sstream.str(""); sstream.clear(); - } - else - // all inactive cells get some random number... - tempstring += "999.9"; - } - vecString.push_back(tempstring); - } - // write the data into the corresponding include file - WriteIncludeFile(Filename, Keyword, vecString, false); - } - - vecString.clear(); - vecString2.clear(); - vecString3.clear(); - - Sats.clear(); - Press.clear(); + sstream.str(""); + sstream.clear(); + } + else + // all inactive cells get some random number... + tempstring += "999.9"; + } + vecString.push_back(tempstring); + } + // write the data into the corresponding include file + WriteIncludeFile(Filename, Keyword, vecString, false); + } + vecString.clear(); + vecString2.clear(); + vecString3.clear(); + + Sats.clear(); + Press.clear(); finish = clock(); time = (double(finish) - double(start)) / CLOCKS_PER_SEC; - cout << " Time: " << time << " seconds." << "\n"; + cout << " Time: " << time << " seconds." + << "\n"; return 1; } @@ -5997,7 +6006,7 @@ int CECLIPSEData::RunEclipse(long Timestep, CRFProcess* m_pcs) std::string DOScommand; std::string folder; int position; - clock_t start,finish; + clock_t start, finish; clock_t start_execute, finish_execute; double time; @@ -6013,8 +6022,7 @@ int CECLIPSEData::RunEclipse(long Timestep, CRFProcess* m_pcs) if (m_pcs->Tim->step_current == 1) this->actual_time = 0; else - this->actual_time = this->actual_time + - m_pcs->Tim->time_step_vector[m_pcs->Tim->step_current - 2]; + this->actual_time = this->actual_time + m_pcs->Tim->time_step_vector[m_pcs->Tim->step_current - 2]; Filename = m_pcs->simulator_model_path; // path to eclipse input data if (Timestep == 1) @@ -6037,59 +6045,64 @@ int CECLIPSEData::RunEclipse(long Timestep, CRFProcess* m_pcs) folder = Filename.substr(0, position + 1); if (UsePrecalculatedFiles == false) - cout << " Delete old result files " << "\n"; + cout << " Delete old result files " + << "\n"; projectname = ""; Filename_Wells = m_pcs->simulator_well_path; // path to eclipse input data - if (Timestep == 1){ // SB redo wtp + if (Timestep == 1) + { // SB redo wtp - // Read external .well-File - if (Filename_Wells != "") - { - this->ReadWellData(Filename_Wells); - this->existWells = true; - } + // Read external .well-File + if (Filename_Wells != "") + { + this->ReadWellData(Filename_Wells); + this->existWells = true; + } - // Read Eclipse Data-File - this->ReadDataFromInputFile(Filename); - if (this->SurfaceCO2Density <= 0) - { - cout << - "The CO2 Density at surface conditions was not read properly (rho <= 0!)." << "\n"; - //system("Pause"); //SB redo wtp - return 0; - } + // Read Eclipse Data-File + this->ReadDataFromInputFile(Filename); + if (this->SurfaceCO2Density <= 0) + { + cout << "The CO2 Density at surface conditions was not read properly (rho <= 0!)." + << "\n"; + // system("Pause"); //SB redo wtp + return 0; + } } - //write dissolved amount of CO2 and and later maybe also water density back to Eclipse; ToDo: Write new Water density back to Eclipse + // write dissolved amount of CO2 and and later maybe also water density back to Eclipse; ToDo: Write new Water + // density back to Eclipse if ((Timestep > 1) && (this->GetVariableIndex("RS") >= 0)) { if (this->UsePrecalculatedFiles == true) - cout << - "Attention! If you run a simulation with precalculated Files you have no interaction between Multiphase Flow and Reactions thus you might get wrong Results for dissolved CO2 in liquid!" + cout << "Attention! If you run a simulation with precalculated Files you have no interaction between " + "Multiphase Flow and Reactions thus you might get wrong Results for dissolved CO2 in liquid!" << "\n"; else if (this->WriteDataBackToEclipse(m_pcs, folder) == 0) { - cout << - "The WriteDataBackToEclipse funktion was not finished properly! The simulation is canceled!" + cout << "The WriteDataBackToEclipse funktion was not finished properly! The simulation is canceled!" << "\n"; - //system("Pause"); + // system("Pause"); return 0; } } - cout << " RunEclipse() called " << "\n"; + cout << " RunEclipse() called " + << "\n"; - //Execute Eclipse, try several times in case of problems finding the license + // Execute Eclipse, try several times in case of problems finding the license start_execute = clock(); std::string DataFilename = ""; int number_loops = 0; int maximum_loops = 10; - do { - cout << number_loops + 1 << ". trial" << "\n"; + do + { + cout << number_loops + 1 << ". trial" + << "\n"; projectname = ExecuteEclipse(Timestep, m_pcs, folder); - //check if Eclipse has run properly -> errors in the projectname.prt file must be zero + // check if Eclipse has run properly -> errors in the projectname.prt file must be zero DataFilename = projectname + ".F" + AddZero(Timestep, 4, true); number_loops += 1; } while ((CheckIfFileExists(DataFilename) == false) && (number_loops <= maximum_loops)); @@ -6098,107 +6111,106 @@ int CECLIPSEData::RunEclipse(long Timestep, CRFProcess* m_pcs) time = (double(finish_execute) - double(start_execute)) / CLOCKS_PER_SEC; cout << "\n"; cout << " Timestep: " << Timestep << "\n"; - cout << " RunEclipse() called Time: " << time << " seconds." << - "\n"; + cout << " RunEclipse() called Time: " << time << " seconds." + << "\n"; if (number_loops > maximum_loops) { - cout << "The Eclipse execution does not work after " << number_loops << - " trials!" << "\n"; - //system("Pause"); + cout << "The Eclipse execution does not work after " << number_loops << " trials!" + << "\n"; + // system("Pause"); return 0; } if (Timestep == 1) { // Read ECLIPSE model grid, check consistency with GeoSys mesh and construct faces - //Read Eclipse model grid + // Read Eclipse model grid std::string GridFilename = ""; GridFilename = projectname + ".FGRID"; this->ReadEclipseGrid(GridFilename); - //Check if Eclipse grid is identical with Geosys grid + // Check if Eclipse grid is identical with Geosys grid if (CompareElementsGeosysEclipse() == 0) { - cout << - "The Eclipse grid is not identical to the Geosys grid! Abort Calculations!" + cout << "The Eclipse grid is not identical to the Geosys grid! Abort Calculations!" << "\n"; - //system("Pause"); + // system("Pause"); return 0; } this->DetermineNeighbourElements(projectname); - //Read boundary conditions + // Read boundary conditions tempstring = projectname + ".data"; - //this->ReadPositionBoundaryCondition(tempstring); - //Create Faces + // this->ReadPositionBoundaryCondition(tempstring); + // Create Faces this->CreateFaces(); // Connect Faces to each block this->ConnectFacesToElements(); // check for radial model and one column int count = 0, found = 0, iindex = 0; double* nvec; - if(this->Radialmodell == true) + if (this->Radialmodell == true) { - if(this->rows > 1) // check if more than one column is active in radial model + if (this->rows > 1) // check if more than one column is active in radial model { - for(long ii = 0; ii < long(this->eclgrid.size()); ii++) + for (long ii = 0; ii < long(this->eclgrid.size()); ii++) { - if((this->eclgrid[ii]->layer == 1) && - (this->eclgrid[ii]->column == 1)) + if ((this->eclgrid[ii]->layer == 1) && (this->eclgrid[ii]->column == 1)) { found++; - if(this->eclgrid[ii]->active == 1) + if (this->eclgrid[ii]->active == 1) { count++; iindex = ii; } } - if(found == this->rows) - break; // foun all cells in layer ==1 and column == 1 + if (found == this->rows) + break; // foun all cells in layer ==1 and column == 1 } - if( count > 1) - cout << "\n" << "\n" << - " Error in definition of radial flow model; Use not more than one active column " + if (count > 1) + cout << "\n" + << "\n" + << " Error in definition of radial flow model; Use not more than one active column " << "\n"; } // test if faces are perpenducular to I coordinate axis - for(int ii = 0; ii < int(this->eclgrid[iindex]->connected_faces.size()); - ii++) - if(this->faces[ii]->model_axis.find("I") == 0) + for (int ii = 0; ii < int(this->eclgrid[iindex]->connected_faces.size()); ii++) + if (this->faces[ii]->model_axis.find("I") == 0) { nvec = this->faces[ii]->PlaneEquation->GetNormalVector(); - if(nvec[0] == 1.0) + if (nvec[0] == 1.0) this->Radial_I = true; } - if(Radial_I != true) - cout << "\n" << - " Error: I Face is not perpendicular to coordinate axis " << "\n"; + if (Radial_I != true) + cout << "\n" + << " Error: I Face is not perpendicular to coordinate axis " + << "\n"; } } - //Read Eclipse model data + // Read Eclipse model data DataFilename = projectname + ".F" + AddZero(Timestep, 4, true); long EclipseTimeStep = 1; this->ReadEclipseData(DataFilename, EclipseTimeStep - 1); - //calculate phase flux if E300 is used + // calculate phase flux if E300 is used if (this->E100 == false) this->CalculateRSfromMassFraction_E300(); - //this->MakeNodeVector(m_pcs, folder, EclipseTimeStep - 1, 0); + // this->MakeNodeVector(m_pcs, folder, EclipseTimeStep - 1, 0); this->MakeNodeVector(); for (int i = 0; i < int(this->Phases.size()); i++) { - //Get the flow for each face + // Get the flow for each face this->GetFlowForFaces(i); - //this->MakeNodeVector(m_pcs, folder, EclipseTimeStep - 1, 0); - //this->CalcBlockBudget(i); - //this->GetVelForFaces(); - //interpolate face flows to nodes + // this->MakeNodeVector(m_pcs, folder, EclipseTimeStep - 1, 0); + // this->CalcBlockBudget(i); + // this->GetVelForFaces(); + // interpolate face flows to nodes this->InterpolateDataFromBlocksToNodes(m_pcs, folder, i); } WriteDataToGeoSys(m_pcs, folder); @@ -6214,14 +6226,16 @@ int CECLIPSEData::RunEclipse(long Timestep, CRFProcess* m_pcs) finish = clock(); time = (double(finish) - double(start)) / CLOCKS_PER_SEC; - cout << " Time for this timestep: " << time << " seconds." << "\n"; + cout << " Time for this timestep: " << time << " seconds." + << "\n"; return 1; } -//TODO: +// TODO: -// interpolation of pressure to nodes-> volume is just devided by the number of nodes -> not exact if shape is not a quader +// interpolation of pressure to nodes-> volume is just devided by the number of nodes -> not exact if shape is not a +// quader /*------------------------------------------------------------------------- GeoSys - Function: WriteOutput_2DSection @@ -6230,8 +6244,8 @@ Task: writes sth Programming: XX/XXXX KB / CB Modification: -------------------------------------------------------------------------*/ -void CECLIPSEData::WriteOutput_2DSection(long Timestep) { - +void CECLIPSEData::WriteOutput_2DSection(long Timestep) +{ vector pressure; vector soil; vector sgas; @@ -6245,7 +6259,7 @@ void CECLIPSEData::WriteOutput_2DSection(long Timestep) { Filename_base = " Output_2D"; // WTP to avoid getting warning due to conversion from long to string one could use a sstream - //time.push_back(Timestep); + // time.push_back(Timestep); std::stringstream strstream; strstream << Timestep; strstream >> time; @@ -6255,49 +6269,107 @@ void CECLIPSEData::WriteOutput_2DSection(long Timestep) { textfile.open(Filename.data(), ios::out); - textfile << "column row" << " " << "layer" << " " << "x-barycentre" << " " << "y-barycentre" << " " << "z-barycentre" << " " << "n1" << " " << "x1" << " " << "y1" << " " << "z1" << " " << "n2" << " " << "x2" << " " << "y2" << " " << "z2" << " " << "n3" << " " << "x3" << " " << "y3" << " " << "z3" << " " << "n4" << " " << "x4" << " " << "y4" << " " << "z4" << " " << "PRESSURE" << " " << "SOIL" << " " << "SGAS" << " " << "OIL_DEN" << " " << "GAS_DEN"; + textfile << "column row" + << " " + << "layer" + << " " + << "x-barycentre" + << " " + << "y-barycentre" + << " " + << "z-barycentre" + << " " + << "n1" + << " " + << "x1" + << " " + << "y1" + << " " + << "z1" + << " " + << "n2" + << " " + << "x2" + << " " + << "y2" + << " " + << "z2" + << " " + << "n3" + << " " + << "x3" + << " " + << "y3" + << " " + << "z3" + << " " + << "n4" + << " " + << "x4" + << " " + << "y4" + << " " + << "z4" + << " " + << "PRESSURE" + << " " + << "SOIL" + << " " + << "SGAS" + << " " + << "OIL_DEN" + << " " + << "GAS_DEN"; textfile << "\n"; - //for (int i=0; i < this->eclgrid.size(); i++){ - for (std::size_t i=0; i < this->eclgrid.size(); i++){ // WTP - if ((this->eclgrid[i]->column == 40) && (this->eclgrid[i]->layer == 1)){ - for (int k=0; k < this->rows; k++){ - textfile << this->eclgrid[i]->column << " " << " " << k << " " << this->eclgrid[i]->layer << " " << this->eclgrid[i]->x_barycentre << " " << this->eclgrid[i]->y_barycentre << " " << this->eclgrid[i]->z_barycentre << " "; - //textfile << pressure[i] << " " << soil[i] << " " sgas[i] << " " << oildens[i] << " " << gasdens[i] << " "; - textfile << this->Data[i][this->GetVariableIndex("PRESSURE")] << " " << this->Data[i][this->GetVariableIndex("SOIL")]<< " " << this->Data[i][this->GetVariableIndex("SGAS")] << " " << this->Data[i][this->GetVariableIndex("OIL_DEN")] << " " << this->Data[i][this->GetVariableIndex("GAS_DEN")]; + // for (int i=0; i < this->eclgrid.size(); i++){ + for (std::size_t i = 0; i < this->eclgrid.size(); i++) + { // WTP + if ((this->eclgrid[i]->column == 40) && (this->eclgrid[i]->layer == 1)) + { + for (int k = 0; k < this->rows; k++) + { + textfile << this->eclgrid[i]->column << " " + << " " << k << " " << this->eclgrid[i]->layer << " " << this->eclgrid[i]->x_barycentre << " " + << this->eclgrid[i]->y_barycentre << " " << this->eclgrid[i]->z_barycentre << " "; + // textfile << pressure[i] << " " << soil[i] << " " sgas[i] << " " << oildens[i] << " " << gasdens[i] << + // " "; + textfile << this->Data[i][this->GetVariableIndex("PRESSURE")] << " " + << this->Data[i][this->GetVariableIndex("SOIL")] << " " + << this->Data[i][this->GetVariableIndex("SGAS")] << " " + << this->Data[i][this->GetVariableIndex("OIL_DEN")] << " " + << this->Data[i][this->GetVariableIndex("GAS_DEN")]; textfile << "\n"; } } } - - //Write general ouput file + // Write general ouput file textfile << "\n"; textfile << "\n"; textfile.close(); - }; - /**------------------------------------------------------------------------- GeoSys - Function: SaveEclipseDataFile Task: Saves the current .data file from Eclipse for benchmarking - The names of the .data files are enumerated with the oldest - having the lowest number (analog to the stored result files of Ecl). + The names of the .data files are enumerated with the oldest + having the lowest number (analog to the stored result files of Ecl). Return: void Programming: 04/2013 WTP Modification: -------------------------------------------------------------------------*/ -void CECLIPSEData::SaveEclipseDataFile(long Timestep, CRFProcess* m_pcs) { +void CECLIPSEData::SaveEclipseDataFile(long Timestep, CRFProcess* m_pcs) +{ std::string DataFilename_save; std::string file_extension; std::string projectname; std::string Filename; - CReadTextfiles_ECL *TextFile_in; - CWriteTextfiles_ECL *TextFile_out; - clock_t start,finish; + CReadTextfiles_ECL* TextFile_in; + CWriteTextfiles_ECL* TextFile_out; + clock_t start, finish; double time; cout << " SaveEclipseDataFile()"; @@ -6308,33 +6380,35 @@ void CECLIPSEData::SaveEclipseDataFile(long Timestep, CRFProcess* m_pcs) { Filename = m_pcs->simulator_model_path; // check if filename is given with or without extension - file_extension = Filename.substr(Filename.length() - 5,Filename.length()); - if((file_extension.compare(".data") == 0) || (file_extension.compare(".DATA") == 0)) + file_extension = Filename.substr(Filename.length() - 5, Filename.length()); + if ((file_extension.compare(".data") == 0) || (file_extension.compare(".DATA") == 0)) projectname = Filename.substr(0, Filename.length() - 5); else projectname = Filename; if (Timestep > 1) projectname = projectname + "_RESTART"; - //Set Eclipse model data filename - DataFilename_save = projectname + "_" + AddZero(Timestep, 4, true)+ file_extension ; + // Set Eclipse model data filename + DataFilename_save = projectname + "_" + AddZero(Timestep, 4, true) + file_extension; // Reading the original .data File TextFile_in = new CReadTextfiles_ECL; - if(!TextFile_in->Read_Text(projectname + file_extension)) { + if (!TextFile_in->Read_Text(projectname + file_extension)) + { // Copying the content of the original .data file to a new file TextFile_out = new CWriteTextfiles_ECL; TextFile_out->Write_Text(DataFilename_save, TextFile_in->Data); } - else { - cout << " Warning: Copying eclipse .data files did not work properly" << "\n"; + else + { + cout << " Warning: Copying eclipse .data files did not work properly" + << "\n"; } - finish = clock(); time = (double(finish) - double(start)) / CLOCKS_PER_SEC; - cout << " Time: " << time << " seconds." << "\n"; + cout << " Time: " << time << " seconds." + << "\n"; return; }; - diff --git a/FEM/Eclipse.h b/FEM/Eclipse.h index f26724be3..4463825f8 100644 --- a/FEM/Eclipse.h +++ b/FEM/Eclipse.h @@ -19,18 +19,19 @@ typedef struct { double Number; int Exponent; -}typeExponentialNumber; +} typeExponentialNumber; // KB: neue Struktur zum Einlesen der Brunnendatei, siehe CECLIPSEData::ReadWellData() -struct structWell /* deklariert den Strukturtyp well, wird beim Einlesen von .well-File neu aufgerufen */ -{std::string name; - std::vector time; - std::vector rate; - std::string phase; - std::string open_flag; - std::string control_mode; - //std::string dummy_rate; - //std::string dummy_zeile; - //std::string rest_zeile; +struct structWell /* deklariert den Strukturtyp well, wird beim Einlesen von .well-File neu aufgerufen */ +{ + std::string name; + std::vector time; + std::vector rate; + std::string phase; + std::string open_flag; + std::string control_mode; + // std::string dummy_rate; + // std::string dummy_zeile; + // std::string rest_zeile; }; class CECLIPSEBlock @@ -40,37 +41,37 @@ class CECLIPSEBlock long row; long column; long layer; - std::vector x_coordinates; - std::vector y_coordinates; - std::vector z_coordinates; + std::vector x_coordinates; + std::vector y_coordinates; + std::vector z_coordinates; double x_barycentre; double y_barycentre; double z_barycentre; int active; double volume; - std::vector connected_faces; + std::vector connected_faces; - std::vector NeighbourElement; - std::vector ConnectedBoundaryCondition; + std::vector NeighbourElement; + std::vector ConnectedBoundaryCondition; CECLIPSEBlock(long Nodelength, long Facelength); ~CECLIPSEBlock(); - //void CalcBarycentre(void); + // void CalcBarycentre(void); void CalculateFaceCentres(void); }; class CReadTextfiles_ECL { public: - std::vector Data; - std::vector > Data_separated; + std::vector Data; + std::vector > Data_separated; long NumberOfRows; - std::vector SplittedString; - std::vector Header; + std::vector SplittedString; + std::vector Header; - CReadTextfiles_ECL(); //Konstruktor - ~CReadTextfiles_ECL(); //Desturktor + CReadTextfiles_ECL(); // Konstruktor + ~CReadTextfiles_ECL(); // Desturktor bool Read_Text(std::string Filename); @@ -78,21 +79,21 @@ class CReadTextfiles_ECL bool Read_SeparatedText(std::string Filename, std::string delimiter); - //vector Header; + // vector Header; // vector Data; // long NumberOfRows; - //CReadTextfiles(); //Konstruktor + // CReadTextfiles(); //Konstruktor //~CReadTextfiles(); //Desturktor - //bool Read_Text(std::string Filename); + // bool Read_Text(std::string Filename); }; class CWriteTextfiles_ECL { public: - CWriteTextfiles_ECL(); //Konstruktor - ~CWriteTextfiles_ECL(); //Desturktor + CWriteTextfiles_ECL(); // Konstruktor + ~CWriteTextfiles_ECL(); // Desturktor void Write_Text(std::string Filename, std::vector Text); }; @@ -103,20 +104,20 @@ class CPointData_ECL double x; double y; double z; - //double Flow[3]; + // double Flow[3]; double pressure; double temperature; - //double Gas_dissolved; + // double Gas_dissolved; double CO2inLiquid; double NaClinLiquid; double deltaDIC; double deltaSat; double deltaPress; double VaporComponentMassFraction; - std::vector phase_pressure; - std::vector phase_saturation; - std::vector phase_density; - std::vector > q; + std::vector phase_pressure; + std::vector phase_saturation; + std::vector phase_density; + std::vector > q; CPointData_ECL() { @@ -174,44 +175,44 @@ class CECLIPSEData bool phase_shift_flag; double sumCO2removed; int ProcessIndex_CO2inLiquid; - int ProcessIndex_CO2inGas; //KB + int ProcessIndex_CO2inGas; // KB double actual_time; bool Windows_System; bool existWells; bool UsePrecalculatedFiles; bool UseSaveEclipseDataFiles; - bool TempIncludeFile; // WTP bool flag to select temperature exchange with ecl and geosys - std::string dissolved_co2_pcs_name_ECL; // Keyword DISSOLVED_CO2_PCS_NAME, Name of MASS_TRANSPORT Process which is used to store total dissolved CO2 from ECLIPSE + bool TempIncludeFile; // WTP bool flag to select temperature exchange with ecl and geosys + std::string dissolved_co2_pcs_name_ECL; // Keyword DISSOLVED_CO2_PCS_NAME, Name of MASS_TRANSPORT Process which is + // used to store total dissolved CO2 from ECLIPSE std::string dissolved_co2_ingas_pcs_name_ECL; // KB - std::vector eclgrid; - std::vector SplittedString; - std::vector Variables; - std::vector faces; - std::vector NodeData; - std::vector BC; - std::vector ecl_well; - - double** Data; //array of points, times and variables - std::vector WellRates; // KB, abspeichern der neuen Raten f�r einen bestimmten Zeitschritt - - std::vector output_x; - std::vector output_y; - std::vector output_z; - std::vector output_time; - std::vector CorrespondingEclipseElement; - std::vector CorrespondingGeosysElement; - std::vector Phases; - std::vector Components; - long a [8][2]; //2D Array um Keywords abzuspeichern - std::vector eclipse_ele_active_flag; // CB + std::vector eclgrid; + std::vector SplittedString; + std::vector Variables; + std::vector faces; + std::vector NodeData; + std::vector BC; + std::vector ecl_well; + + double** Data; // array of points, times and variables + std::vector WellRates; // KB, abspeichern der neuen Raten f�r einen bestimmten Zeitschritt + + std::vector output_x; + std::vector output_y; + std::vector output_z; + std::vector output_time; + std::vector CorrespondingEclipseElement; + std::vector CorrespondingGeosysElement; + std::vector Phases; + std::vector Components; + long a[8][2]; // 2D Array um Keywords abzuspeichern + std::vector eclipse_ele_active_flag; // CB bool PoroPermIncludeFile; CECLIPSEData(); ~CECLIPSEData(); int GetVariableIndex(std::string Variablename); - void SplitStrings(const std::string str, - std::string delimiter); + void SplitStrings(const std::string str, std::string delimiter); double Round(double Number, int Decimalplaces); @@ -221,11 +222,9 @@ class CECLIPSEData bool CheckIfFileExists(std::string strFilename); - bool ReplaceASectionInFile(std::string Filename, - std::string Keyword, - std::vector Data, + bool ReplaceASectionInFile(std::string Filename, std::string Keyword, std::vector Data, bool CheckLengthOfSection); - bool WriteIncludeFile(std::string Filename, std::string Keyword, std::vector Data, bool append); //CB + bool WriteIncludeFile(std::string Filename, std::string Keyword, std::vector Data, bool append); // CB bool ReplaceWellRate(std::string Filename, std::string Keyword_well); int WriteDataBackToEclipse(CRFProcess* m_pcs, std::string projectname); @@ -236,7 +235,7 @@ class CECLIPSEData void DetermineNeighbourElements(std::string Filename); - bool ReadBoundaryData(int index_boundary, std::vector Data); + bool ReadBoundaryData(int index_boundary, std::vector Data); int ReadDataFromInputFile(std::string Filename); @@ -248,13 +247,13 @@ class CECLIPSEData // TF commented out method since we have already functions for computing the distance // between points - //double CalculateDistanceBetween2Points(double Point1[3], double Point2[3]); + // double CalculateDistanceBetween2Points(double Point1[3], double Point2[3]); bool CreateFaces(void); bool ConnectFacesToElements(void); - //bool MakeNodeVector(CRFProcess *m_pcs, std::string path, int timestep, int phase_index); + // bool MakeNodeVector(CRFProcess *m_pcs, std::string path, int timestep, int phase_index); bool MakeNodeVector(void); void ReadEclipseData(std::string Pathname, long timestep); @@ -267,10 +266,7 @@ class CECLIPSEData bool CalcBlockBudget(int phase_index); - void InterpolateDataFromFacesToNodes(long ele_nr, - double* n_vel_x, - double* n_vel_y, - double* n_vel_z, + void InterpolateDataFromFacesToNodes(long ele_nr, double* n_vel_x, double* n_vel_y, double* n_vel_z, int phase_index); void InterpolateDataFromBlocksToNodes(CRFProcess* m_pcs, std::string path, int phase_index); diff --git a/FEM/FEMCondition.cpp b/FEM/FEMCondition.cpp index 014181538..f7200468c 100644 --- a/FEM/FEMCondition.cpp +++ b/FEM/FEMCondition.cpp @@ -15,8 +15,8 @@ #include "GEOObjects.h" //for SourceTerm #include "GridAdapter.h" -FEMCondition::FEMCondition(const std::string &geometry_name, CondType t) - : _type(t), _geoName("[unspecified]"), _associated_geometry(geometry_name) +FEMCondition::FEMCondition(const std::string& geometry_name, CondType t) + : _type(t), _geoName("[unspecified]"), _associated_geometry(geometry_name) { this->setProcessType(FiniteElement::INVALID_PROCESS); this->setProcessPrimaryVariable(FiniteElement::INVALID_PV); @@ -24,23 +24,19 @@ FEMCondition::FEMCondition(const std::string &geometry_name, CondType t) this->setProcessDistributionType(FiniteElement::INVALID_DIS_TYPE); } -FEMCondition::FEMCondition(const std::string &geometry_name, FiniteElement::ProcessType pt, - FiniteElement::PrimaryVariable pv, GEOLIB::GEOTYPE gt, const std::string &gn, - FiniteElement::DistributionType dt, CondType ct) - : ProcessInfo(pt, pv, NULL), GeoInfo(gt, NULL), DistributionInfo(dt), _type(ct), - _geoName(gn), _associated_geometry(geometry_name) +FEMCondition::FEMCondition(const std::string& geometry_name, FiniteElement::ProcessType pt, + FiniteElement::PrimaryVariable pv, GEOLIB::GEOTYPE gt, const std::string& gn, + FiniteElement::DistributionType dt, CondType ct) + : ProcessInfo(pt, pv, NULL), GeoInfo(gt, NULL), DistributionInfo(dt), _type(ct), _geoName(gn), + _associated_geometry(geometry_name) { } -FEMCondition::FEMCondition(const FEMCondition &cond, CondType t) - : ProcessInfo(cond.getProcessType(), cond.getProcessPrimaryVariable(), NULL), - GeoInfo(cond.getGeoType(), cond.getGeoObj()), - DistributionInfo(cond.getProcessDistributionType()), - _type(t), - _geoName(cond.getGeoName()), - _disNodes(cond.getDisNodes()), - _disValues(cond.getDisValues()), - _associated_geometry(cond.getAssociatedGeometryName()) +FEMCondition::FEMCondition(const FEMCondition& cond, CondType t) + : ProcessInfo(cond.getProcessType(), cond.getProcessPrimaryVariable(), NULL), + GeoInfo(cond.getGeoType(), cond.getGeoObj()), DistributionInfo(cond.getProcessDistributionType()), _type(t), + _geoName(cond.getGeoName()), _disNodes(cond.getDisNodes()), _disValues(cond.getDisValues()), + _associated_geometry(cond.getAssociatedGeometryName()) { } @@ -56,7 +52,7 @@ std::string FEMCondition::condTypeToString(CondType type) return "Unspecified"; } -void FEMCondition::setDisValues(const std::vector< std::pair > &dis_values) +void FEMCondition::setDisValues(const std::vector >& dis_values) { std::vector nodes; std::vector values; @@ -65,6 +61,6 @@ void FEMCondition::setDisValues(const std::vector< std::pair > & nodes.push_back(dis_values[i].first); values.push_back(dis_values[i].second); } - this->_disNodes=nodes; - this->_disValues=values; + this->_disNodes = nodes; + this->_disValues = values; } diff --git a/FEM/FEMCondition.h b/FEM/FEMCondition.h index 644af5078..092348684 100644 --- a/FEM/FEMCondition.h +++ b/FEM/FEMCondition.h @@ -24,7 +24,7 @@ class CBoundaryCondition; class CInitialCondition; class CSourceTerm; -//class GEOObjects; +// class GEOObjects; class GridAdapter; #include "GEOObjects.h" @@ -35,44 +35,41 @@ class FEMCondition : public ProcessInfo, public GeoInfo, public DistributionInfo { public: /// Specifier for types of FEM Conditions - enum CondType { - UNSPECIFIED = 0, + enum CondType + { + UNSPECIFIED = 0, BOUNDARY_CONDITION = 1, - INITIAL_CONDITION = 2, - SOURCE_TERM = 3 + INITIAL_CONDITION = 2, + SOURCE_TERM = 3 }; - FEMCondition(const std::string &geometry_name, CondType t = UNSPECIFIED); - FEMCondition(const std::string &geometry_name, - FiniteElement::ProcessType pt = FiniteElement::INVALID_PROCESS, - FiniteElement::PrimaryVariable pv = FiniteElement::INVALID_PV, - GEOLIB::GEOTYPE gt = GEOLIB::INVALID, - const std::string &gn = "[unspecified]", - FiniteElement::DistributionType dt = FiniteElement::INVALID_DIS_TYPE, CondType ct = UNSPECIFIED); - FEMCondition(const FEMCondition &cond, CondType t); + FEMCondition(const std::string& geometry_name, CondType t = UNSPECIFIED); + FEMCondition(const std::string& geometry_name, FiniteElement::ProcessType pt = FiniteElement::INVALID_PROCESS, + FiniteElement::PrimaryVariable pv = FiniteElement::INVALID_PV, GEOLIB::GEOTYPE gt = GEOLIB::INVALID, + const std::string& gn = "[unspecified]", + FiniteElement::DistributionType dt = FiniteElement::INVALID_DIS_TYPE, CondType ct = UNSPECIFIED); + FEMCondition(const FEMCondition& cond, CondType t); ~FEMCondition() {} - /// Returns the type of the FEM Condition (i.e. BC, IC or ST) CondType getCondType() const { return _type; } - /// Returns the value(s) for the distribution const std::vector getDisNodes() const { return _disNodes; } - /// Returns the value(s) for the distribution const std::vector getDisValues() const { return _disValues; } - /// Returns the name of the geo-object the condition is assigned to. This object is part of the associated geometry. const std::string& getGeoName() const { return _geoName; } - /// Returns the name of the associated geometry. const std::string& getAssociatedGeometryName() const { return _associated_geometry; } - /// Convenience method for setting a single value specifying the distribution. - void setConstantDisValue(double disValue) {_disValues.clear(); _disValues.push_back(disValue); } + void setConstantDisValue(double disValue) + { + _disValues.clear(); + _disValues.push_back(disValue); + } /// Sets a vector of values specifying the distribution. - void setDisValues(const std::vector &disNodes, const std::vector &disValues) + void setDisValues(const std::vector& disNodes, const std::vector& disValues) { _disNodes = disNodes; _disValues = disValues; @@ -80,14 +77,12 @@ class FEMCondition : public ProcessInfo, public GeoInfo, public DistributionInfo /// Sets a vector of values specifying the distribution. /// The first value specifies the point id, the second the value for that point. - void setDisValues(const std::vector< std::pair > &dis_values); + void setDisValues(const std::vector >& dis_values); /// Removes all distribution values void clearDisValues() { _disValues.resize(0); }; - /// Sets the name of the geo-object the condition is assigned to. void setGeoName(std::string geoName) { _geoName = geoName; } - /// Returns the type of the FEM condition as a string. static std::string condTypeToString(CondType type); @@ -99,4 +94,4 @@ class FEMCondition : public ProcessInfo, public GeoInfo, public DistributionInfo std::string _associated_geometry; }; -#endif //FEMCONDITION_H +#endif // FEMCONDITION_H diff --git a/FEM/FEMEnums.cpp b/FEM/FEMEnums.cpp index be38bd61b..7f235563a 100644 --- a/FEM/FEMEnums.cpp +++ b/FEM/FEMEnums.cpp @@ -16,151 +16,147 @@ namespace FiniteElement { -ProcessType convertProcessType ( const std::string& pcs_type_string) +ProcessType convertProcessType(const std::string& pcs_type_string) { - if (pcs_type_string.compare ("LIQUID_FLOW") == 0) + if (pcs_type_string.compare("LIQUID_FLOW") == 0) return LIQUID_FLOW; - if (pcs_type_string.compare ("FLUID_FLOW") == 0) + if (pcs_type_string.compare("FLUID_FLOW") == 0) return FLUID_FLOW; - if (pcs_type_string.compare ("TWO_PHASE_FLOW") == 0) + if (pcs_type_string.compare("TWO_PHASE_FLOW") == 0) return TWO_PHASE_FLOW; - if (pcs_type_string.compare ("RICHARDS_FLOW") == 0) + if (pcs_type_string.compare("RICHARDS_FLOW") == 0) return RICHARDS_FLOW; - if (pcs_type_string.compare ("OVERLAND_FLOW") == 0) + if (pcs_type_string.compare("OVERLAND_FLOW") == 0) return OVERLAND_FLOW; - if (pcs_type_string.compare ("GROUNDWATER_FLOW") == 0) + if (pcs_type_string.compare("GROUNDWATER_FLOW") == 0) return GROUNDWATER_FLOW; - if (pcs_type_string.compare ("HEAT_TRANSPORT") == 0) + if (pcs_type_string.compare("HEAT_TRANSPORT") == 0) return HEAT_TRANSPORT; - if (pcs_type_string.compare ("DEFORMATION") == 0) + if (pcs_type_string.compare("DEFORMATION") == 0) return DEFORMATION; - if (pcs_type_string.compare ("DEFORMATION_FLOW") == 0) + if (pcs_type_string.compare("DEFORMATION_FLOW") == 0) return DEFORMATION_FLOW; - if (pcs_type_string.compare ("DEFORMATION_DYNAMIC") == 0) + if (pcs_type_string.compare("DEFORMATION_DYNAMIC") == 0) return DEFORMATION_DYNAMIC; - if (pcs_type_string.compare ("MASS_TRANSPORT") == 0) + if (pcs_type_string.compare("MASS_TRANSPORT") == 0) return MASS_TRANSPORT; - if (pcs_type_string.compare ("MULTI_PHASE_FLOW") == 0) + if (pcs_type_string.compare("MULTI_PHASE_FLOW") == 0) return MULTI_PHASE_FLOW; - if (pcs_type_string.compare ("DEFORMATION_H2") == 0) + if (pcs_type_string.compare("DEFORMATION_H2") == 0) return DEFORMATION_H2; - if (pcs_type_string.compare ("AIR_FLOW") == 0) + if (pcs_type_string.compare("AIR_FLOW") == 0) return AIR_FLOW; - if (pcs_type_string.compare ("FLUID_MOMENTUM") == 0) + if (pcs_type_string.compare("FLUID_MOMENTUM") == 0) return FLUID_MOMENTUM; - if (pcs_type_string.compare ("RANDOM_WALK") == 0) + if (pcs_type_string.compare("RANDOM_WALK") == 0) return RANDOM_WALK; - if (pcs_type_string.compare ("FLUX") == 0) + if (pcs_type_string.compare("FLUX") == 0) return FLUX; - if (pcs_type_string.compare ("PS_GLOBAL") == 0) + if (pcs_type_string.compare("PS_GLOBAL") == 0) return PS_GLOBAL; - if (pcs_type_string.compare ("NO_PCS") == 0) + if (pcs_type_string.compare("NO_PCS") == 0) return NO_PCS; - if (pcs_type_string.compare ("MULTI_COMPONENTIAL_FLOW") == 0) + if (pcs_type_string.compare("MULTI_COMPONENTIAL_FLOW") == 0) return MULTI_COMPONENTIAL_FLOW; - if (pcs_type_string.compare ("TNEQ") == 0) + if (pcs_type_string.compare("TNEQ") == 0) return TNEQ; - if (pcs_type_string.compare ("TES") == 0) + if (pcs_type_string.compare("TES") == 0) return TES; - //else - //std::cout << "WARNING in convertProcessType: process type #" << pcs_type_string << - //"# unknown" << "\n"; + // else + // std::cout << "WARNING in convertProcessType: process type #" << pcs_type_string << + //"# unknown" << "\n"; return INVALID_PROCESS; } - -std::string convertProcessTypeToString ( ProcessType pcs_type ) +std::string convertProcessTypeToString(ProcessType pcs_type) { switch (pcs_type) { - case LIQUID_FLOW: - return "LIQUID_FLOW"; - case FLUID_FLOW: - return "FLUID_FLOW"; - case TWO_PHASE_FLOW: - return "TWO_PHASE_FLOW"; - case RICHARDS_FLOW: - return "RICHARDS_FLOW"; - case OVERLAND_FLOW: - return "OVERLAND_FLOW"; - case GROUNDWATER_FLOW: - return "GROUNDWATER_FLOW"; - case HEAT_TRANSPORT: - return "HEAT_TRANSPORT"; - case DEFORMATION: - return "DEFORMATION"; - case DEFORMATION_FLOW: - return "DEFORMATION_FLOW"; - case DEFORMATION_DYNAMIC: - return "DEFORMATION_DYNAMIC"; - case MASS_TRANSPORT: - return "MASS_TRANSPORT"; - case MULTI_PHASE_FLOW: - return "MULTI_PHASE_FLOW"; - case DEFORMATION_H2: - return "DEFORMATION_H2"; - case AIR_FLOW: - return "AIR_FLOW"; - case FLUID_MOMENTUM: - return "FLUID_MOMENTUM"; - case RANDOM_WALK: - return "RANDOM_WALK"; - case FLUX: - return "FLUX"; - case PS_GLOBAL: - return "PS_GLOBAL"; - case MULTI_COMPONENTIAL_FLOW: - return "MULTI_COMPONENTIAL_FLOW"; - case TNEQ: - return "TNEQ"; - case TES: - return "TES"; - case NO_PCS: - return "NO_PCS"; - default: - return "INVALID_PROCESS"; + case LIQUID_FLOW: + return "LIQUID_FLOW"; + case FLUID_FLOW: + return "FLUID_FLOW"; + case TWO_PHASE_FLOW: + return "TWO_PHASE_FLOW"; + case RICHARDS_FLOW: + return "RICHARDS_FLOW"; + case OVERLAND_FLOW: + return "OVERLAND_FLOW"; + case GROUNDWATER_FLOW: + return "GROUNDWATER_FLOW"; + case HEAT_TRANSPORT: + return "HEAT_TRANSPORT"; + case DEFORMATION: + return "DEFORMATION"; + case DEFORMATION_FLOW: + return "DEFORMATION_FLOW"; + case DEFORMATION_DYNAMIC: + return "DEFORMATION_DYNAMIC"; + case MASS_TRANSPORT: + return "MASS_TRANSPORT"; + case MULTI_PHASE_FLOW: + return "MULTI_PHASE_FLOW"; + case DEFORMATION_H2: + return "DEFORMATION_H2"; + case AIR_FLOW: + return "AIR_FLOW"; + case FLUID_MOMENTUM: + return "FLUID_MOMENTUM"; + case RANDOM_WALK: + return "RANDOM_WALK"; + case FLUX: + return "FLUX"; + case PS_GLOBAL: + return "PS_GLOBAL"; + case MULTI_COMPONENTIAL_FLOW: + return "MULTI_COMPONENTIAL_FLOW"; + case TNEQ: + return "TNEQ"; + case TES: + return "TES"; + case NO_PCS: + return "NO_PCS"; + default: + return "INVALID_PROCESS"; } } - -bool isFlowProcess (ProcessType pcs_type) +bool isFlowProcess(ProcessType pcs_type) { switch (pcs_type) { - case LIQUID_FLOW: - case FLUID_FLOW: - case RICHARDS_FLOW: - case GROUNDWATER_FLOW: - case PS_GLOBAL: - case MULTI_PHASE_FLOW: - case DEFORMATION_FLOW: - case DEFORMATION_H2: - case TWO_PHASE_FLOW: - case OVERLAND_FLOW: - case AIR_FLOW: - case MULTI_COMPONENTIAL_FLOW: - case TNEQ: - case TES: - return true; - default: - return false; + case LIQUID_FLOW: + case FLUID_FLOW: + case RICHARDS_FLOW: + case GROUNDWATER_FLOW: + case PS_GLOBAL: + case MULTI_PHASE_FLOW: + case DEFORMATION_FLOW: + case DEFORMATION_H2: + case TWO_PHASE_FLOW: + case OVERLAND_FLOW: + case AIR_FLOW: + case MULTI_COMPONENTIAL_FLOW: + case TNEQ: + case TES: + return true; + default: + return false; } } -bool isMultiFlowProcess (ProcessType pcs_type) +bool isMultiFlowProcess(ProcessType pcs_type) { - if (pcs_type == PS_GLOBAL || - pcs_type == MULTI_PHASE_FLOW || - pcs_type == TWO_PHASE_FLOW || - pcs_type == DEFORMATION_H2) + if (pcs_type == PS_GLOBAL || pcs_type == MULTI_PHASE_FLOW || pcs_type == TWO_PHASE_FLOW + || pcs_type == DEFORMATION_H2) return true; return false; } -bool isDeformationProcess (ProcessType pcs_type) +bool isDeformationProcess(ProcessType pcs_type) { - if (pcs_type == DEFORMATION || pcs_type == DEFORMATION_H2 || - pcs_type == DEFORMATION_FLOW || pcs_type == DEFORMATION_DYNAMIC) + if (pcs_type == DEFORMATION || pcs_type == DEFORMATION_H2 || pcs_type == DEFORMATION_FLOW + || pcs_type == DEFORMATION_DYNAMIC) return true; return false; } @@ -172,101 +168,101 @@ const std::list getAllProcessNames() while (count != PROCESS_END) { - enum_names.push_back( convertProcessTypeToString(static_cast(count++)) ); + enum_names.push_back(convertProcessTypeToString(static_cast(count++))); } return enum_names; } -PrimaryVariable convertPrimaryVariable ( const std::string& pcs_pv_string ) +PrimaryVariable convertPrimaryVariable(const std::string& pcs_pv_string) { - if (pcs_pv_string.compare ("PRESSURE1") == 0) + if (pcs_pv_string.compare("PRESSURE1") == 0) return PRESSURE; - if (pcs_pv_string.compare ("PRESSURE2") == 0) + if (pcs_pv_string.compare("PRESSURE2") == 0) return PRESSURE2; - if (pcs_pv_string.compare ("PRESSURE_RATE1") == 0) + if (pcs_pv_string.compare("PRESSURE_RATE1") == 0) return PRESSURE_RATE1; - if (pcs_pv_string.compare ("SATURATION1") == 0) + if (pcs_pv_string.compare("SATURATION1") == 0) return SATURATION; - if (pcs_pv_string.compare ("SATURATION2") == 0) + if (pcs_pv_string.compare("SATURATION2") == 0) return SATURATION2; - if (pcs_pv_string.compare ("TEMPERATURE1") == 0) + if (pcs_pv_string.compare("TEMPERATURE1") == 0) return TEMPERATURE; - if (pcs_pv_string.compare ("TEMPERATURE2") == 0) + if (pcs_pv_string.compare("TEMPERATURE2") == 0) return TEMPERATURE2; - if (pcs_pv_string.compare ("DISPLACEMENT_X1") == 0) + if (pcs_pv_string.compare("DISPLACEMENT_X1") == 0) return DISPLACEMENT_X; - if (pcs_pv_string.compare ("DISPLACEMENT_Y1") == 0) + if (pcs_pv_string.compare("DISPLACEMENT_Y1") == 0) return DISPLACEMENT_Y; - if (pcs_pv_string.compare ("DISPLACEMENT_Z1") == 0) + if (pcs_pv_string.compare("DISPLACEMENT_Z1") == 0) return DISPLACEMENT_Z; - if (pcs_pv_string.compare ("DISPLACEMENT_N") == 0) + if (pcs_pv_string.compare("DISPLACEMENT_N") == 0) return DISPLACEMENT_N; - if (pcs_pv_string.compare ("CONCENTRATION1") == 0) + if (pcs_pv_string.compare("CONCENTRATION1") == 0) return CONCENTRATION; - if (pcs_pv_string.compare ("HEAD") == 0) + if (pcs_pv_string.compare("HEAD") == 0) return HEAD; - if (pcs_pv_string.compare ("VELOCITY_DM_X") == 0) + if (pcs_pv_string.compare("VELOCITY_DM_X") == 0) return VELOCITY_DM_X; - if (pcs_pv_string.compare ("VELOCITY_DM_Y") == 0) + if (pcs_pv_string.compare("VELOCITY_DM_Y") == 0) return VELOCITY_DM_Y; - if (pcs_pv_string.compare ("VELOCITY_DM_Z") == 0) + if (pcs_pv_string.compare("VELOCITY_DM_Z") == 0) return VELOCITY_DM_Z; - if (pcs_pv_string.compare ("VELOCITY1_X") == 0) + if (pcs_pv_string.compare("VELOCITY1_X") == 0) return VELOCITY1_X; - if (pcs_pv_string.compare ("VELOCITY1_Y") == 0) + if (pcs_pv_string.compare("VELOCITY1_Y") == 0) return VELOCITY1_Y; - if (pcs_pv_string.compare ("VELOCITY1_Z") == 0) + if (pcs_pv_string.compare("VELOCITY1_Z") == 0) return VELOCITY1_Z; - if (pcs_pv_string.compare ("STRESS_XX") == 0) + if (pcs_pv_string.compare("STRESS_XX") == 0) return STRESS_XX; - if (pcs_pv_string.compare ("STRESS_XY") == 0) + if (pcs_pv_string.compare("STRESS_XY") == 0) return STRESS_XY; - if (pcs_pv_string.compare ("STRESS_XZ") == 0) + if (pcs_pv_string.compare("STRESS_XZ") == 0) return STRESS_XZ; - if (pcs_pv_string.compare ("STRESS_YY") == 0) + if (pcs_pv_string.compare("STRESS_YY") == 0) return STRESS_YY; - if (pcs_pv_string.compare ("STRESS_YZ") == 0) + if (pcs_pv_string.compare("STRESS_YZ") == 0) return STRESS_YZ; - if (pcs_pv_string.compare ("STRESS_ZZ") == 0) + if (pcs_pv_string.compare("STRESS_ZZ") == 0) return STRESS_ZZ; - if (pcs_pv_string.compare ("ACCELERATION_X1") == 0) + if (pcs_pv_string.compare("ACCELERATION_X1") == 0) return ACCELERATION_X1; - if (pcs_pv_string.compare ("ACCELERATION_Y1") == 0) + if (pcs_pv_string.compare("ACCELERATION_Y1") == 0) return ACCELERATION_Y1; - if (pcs_pv_string.compare ("ACCELERATION_Z1") == 0) + if (pcs_pv_string.compare("ACCELERATION_Z1") == 0) return ACCELERATION_Z1; - if (pcs_pv_string.compare ("EXCAVATION") == 0) + if (pcs_pv_string.compare("EXCAVATION") == 0) return EXCAVATION; - if (pcs_pv_string.compare ("STRAIN_XX") == 0) + if (pcs_pv_string.compare("STRAIN_XX") == 0) return STRAIN_XX; - if (pcs_pv_string.compare ("STRAIN_XY") == 0) + if (pcs_pv_string.compare("STRAIN_XY") == 0) return STRAIN_XY; - if (pcs_pv_string.compare ("STRAIN_XZ") == 0) + if (pcs_pv_string.compare("STRAIN_XZ") == 0) return STRAIN_XZ; - if (pcs_pv_string.compare ("STRAIN_YY") == 0) + if (pcs_pv_string.compare("STRAIN_YY") == 0) return STRAIN_YY; - if (pcs_pv_string.compare ("STRAIN_YZ") == 0) + if (pcs_pv_string.compare("STRAIN_YZ") == 0) return STRAIN_YZ; - if (pcs_pv_string.compare ("STRAIN_ZZ") == 0) + if (pcs_pv_string.compare("STRAIN_ZZ") == 0) return STRAIN_ZZ; - if (pcs_pv_string.compare ("STRAIN_PLS") == 0) + if (pcs_pv_string.compare("STRAIN_PLS") == 0) return STRAIN_PLS; - if (pcs_pv_string.compare ("CARBON1") == 0) + if (pcs_pv_string.compare("CARBON1") == 0) return CARBON1; - if (pcs_pv_string.compare ("WATER1") == 0) + if (pcs_pv_string.compare("WATER1") == 0) return WATER1; - if (pcs_pv_string.compare ("METHANE1") == 0) + if (pcs_pv_string.compare("METHANE1") == 0) return METHANE1; - if (pcs_pv_string.compare ("NITROGEN1") == 0) + if (pcs_pv_string.compare("NITROGEN1") == 0) return NITROGEN1; - //else + // else //{ - //std::cout << "convertPrimaryVariable #" << pcs_pv_string << "# not found" << "\n"; - //exit (1); + // std::cout << "convertPrimaryVariable #" << pcs_pv_string << "# not found" << "\n"; + // exit (1); //} return INVALID_PV; } -std::string convertPrimaryVariableToString ( PrimaryVariable pcs_pv ) +std::string convertPrimaryVariableToString(PrimaryVariable pcs_pv) { if (pcs_pv == PRESSURE) return "PRESSURE1"; @@ -328,13 +324,20 @@ std::string convertPrimaryVariableToString ( PrimaryVariable pcs_pv ) return "STRESS_YZ"; if (pcs_pv == STRESS_ZZ) return "STRESS_ZZ"; - if (pcs_pv == STRAIN_XX) return "STRAIN_XX"; - if (pcs_pv == STRAIN_XY) return "STRAIN_XY"; - if (pcs_pv == STRAIN_XZ) return "STRAIN_XZ"; - if (pcs_pv == STRAIN_YY) return "STRAIN_YY"; - if (pcs_pv == STRAIN_YZ) return "STRAIN_YZ"; - if (pcs_pv == STRAIN_ZZ) return "STRAIN_ZZ"; - if (pcs_pv == STRAIN_PLS) return "STRAIN_PLS"; + if (pcs_pv == STRAIN_XX) + return "STRAIN_XX"; + if (pcs_pv == STRAIN_XY) + return "STRAIN_XY"; + if (pcs_pv == STRAIN_XZ) + return "STRAIN_XZ"; + if (pcs_pv == STRAIN_YY) + return "STRAIN_YY"; + if (pcs_pv == STRAIN_YZ) + return "STRAIN_YZ"; + if (pcs_pv == STRAIN_ZZ) + return "STRAIN_ZZ"; + if (pcs_pv == STRAIN_PLS) + return "STRAIN_PLS"; if (pcs_pv == ACCELERATION_X1) return "ACCELERATION_X1"; if (pcs_pv == ACCELERATION_Y1) @@ -353,7 +356,7 @@ const std::list getAllPrimaryVariableNames() while (count != PV_END) { - enum_names.push_back( convertPrimaryVariableToString(static_cast(count++)) ); + enum_names.push_back(convertPrimaryVariableToString(static_cast(count++))); } return enum_names; } @@ -398,10 +401,10 @@ DistributionType convertDisType(const std::string& dis_type_string) return NODESCONSTANT; if (dis_type_string.compare("CLIMATE") == 0) return CLIMATE; - if (dis_type_string.compare("RECHARGE") == 0) //MW + if (dis_type_string.compare("RECHARGE") == 0) // MW return RECHARGE; if (dis_type_string.compare("FUNCTION") == 0) - return FUNCTION; //24.08.2011. WW + return FUNCTION; // 24.08.2011. WW if (dis_type_string.compare("TRANSFER_SURROUNDING") == 0) return TRANSFER_SURROUNDING; else @@ -453,10 +456,10 @@ std::string convertDisTypeToString(DistributionType dis_type) return "DOMAIN"; if (dis_type == CLIMATE) return "CLIMATE"; - if (dis_type == RECHARGE) //MW - return "RECHARGE"; + if (dis_type == RECHARGE) // MW + return "RECHARGE"; if (dis_type == FUNCTION) - return "FUNCTION"; //24.08.2011. WW + return "FUNCTION"; // 24.08.2011. WW if (dis_type == TRANSFER_SURROUNDING) return "TRANSFER_SURROUNDING"; @@ -470,7 +473,7 @@ const std::list getAllDistributionNames() while (count != DIS_END) { - enum_names.push_back( convertDisTypeToString(static_cast(count++)) ); + enum_names.push_back(convertDisTypeToString(static_cast(count++))); } return enum_names; } @@ -489,13 +492,14 @@ ErrorMethod convertErrorMethod(const std::string& error_method_string) return BNORM; else { - std::cout << "convertErrorMethod #" << error_method_string << "# not found"<< "\n"; + std::cout << "convertErrorMethod #" << error_method_string << "# not found" + << "\n"; exit(1); } return INVALID_ERROR_METHOD; } -FrictionPhase convertFrictionPhase( const std::string& friction_string) +FrictionPhase convertFrictionPhase(const std::string& friction_string) { if (friction_string.compare("SOLID") == 0) return SOLID; @@ -506,7 +510,6 @@ FrictionPhase convertFrictionPhase( const std::string& friction_string) std::cout << "Convert error: " << friction_string << " not found. \n"; return INVALID_FRICTION_TYPE; - } std::string convertFrictionPhaseToString(FrictionPhase friction_phase) { @@ -521,7 +524,7 @@ std::string convertFrictionPhaseToString(FrictionPhase friction_phase) return "INVALID_FRICTION_TYPE"; } -SolidReactiveSystem convertSolidReactiveSystem( const std::string& reactive_string) +SolidReactiveSystem convertSolidReactiveSystem(const std::string& reactive_string) { if (reactive_string.compare("INERT") == 0) return INERT; @@ -559,103 +562,101 @@ std::string convertSolidReactiveSystemToString(SolidReactiveSystem reactive_syst TimType::type convertTimType(const std::string& str) { - if (str.compare("STEADY") == 0) - return TimType::STEADY; - if (str.compare("TRANSIENT") == 0) - return TimType::TRANSIENT; - if (str.compare("PURERWPT") == 0) - return TimType::PURERWPT; - return TimType::INVALID_TIM_TYPE; + if (str.compare("STEADY") == 0) + return TimType::STEADY; + if (str.compare("TRANSIENT") == 0) + return TimType::TRANSIENT; + if (str.compare("PURERWPT") == 0) + return TimType::PURERWPT; + return TimType::INVALID_TIM_TYPE; } std::string convertTimTypeToString(TimType::type type) { - if (type == TimType::STEADY) - return "STEADY"; - if (type == TimType::TRANSIENT) - return "TRANSIENT"; - if (type == TimType::PURERWPT) - return "PURERWPT"; - return "INVALID_TIM_TYPE"; + if (type == TimType::STEADY) + return "STEADY"; + if (type == TimType::TRANSIENT) + return "TRANSIENT"; + if (type == TimType::PURERWPT) + return "PURERWPT"; + return "INVALID_TIM_TYPE"; } IterationType::type convertIterationType(const std::string& str) { - if (str.compare("LINEAR")==0) + if (str.compare("LINEAR") == 0) return IterationType::LINEAR; - else if (str.compare("NONLINEAR")==0) + else if (str.compare("NONLINEAR") == 0) return IterationType::NONLINEAR; - else if (str.compare("COUPLED")==0) + else if (str.compare("COUPLED") == 0) return IterationType::COUPLED; else return IterationType::INVALID; - } std::string convertIterationTypeToString(IterationType::type itr_type) { - if (itr_type == IterationType::LINEAR) - return "LINEAR"; - else if (itr_type == IterationType::NONLINEAR) - return "NONLINEAR"; - else if (itr_type == IterationType::COUPLED) - return "COUPLED"; - return "INVALID"; + if (itr_type == IterationType::LINEAR) + return "LINEAR"; + else if (itr_type == IterationType::NONLINEAR) + return "NONLINEAR"; + else if (itr_type == IterationType::COUPLED) + return "COUPLED"; + return "INVALID"; } -TimeControlType::type convertTimeControlType(const std::string &str) +TimeControlType::type convertTimeControlType(const std::string& str) { - if (str == "STEPS") - return TimeControlType::FIXED_STEPS; - else if (str == "PI_AUTO_STEP_SIZE") - return TimeControlType::PI_AUTO_STEP_SIZE; - else if (str == "DYNAMIC_VARIABLE") - return TimeControlType::DYNAMIC_VARIABLE; - else if (str.find("DYNAMIC_COURANT")!=std::string::npos) - return TimeControlType::DYNAMIC_COURANT; - else if (str == "DYNAMIC_PRESSURE") - return TimeControlType::DYNAMIC_PRESSURE; - else if (str == "STEP_SIZE_RESTRICTION") - return TimeControlType::STEP_SIZE_RESTRICTION; - else if (str == "NEUMANN") - return TimeControlType::NEUMANN; - else if (str == "ERROR_CONTROL_ADAPTIVE") - return TimeControlType::ERROR_CONTROL_ADAPTIVE; - else if (str.find("SELF_ADAPTIVE")!=std::string::npos) - return TimeControlType::SELF_ADAPTIVE; - else if (str == "STABLE_ERROR_ADAPTIVE") - return TimeControlType::STABLE_ERROR_ADAPTIVE; - - return TimeControlType::INVALID; + if (str == "STEPS") + return TimeControlType::FIXED_STEPS; + else if (str == "PI_AUTO_STEP_SIZE") + return TimeControlType::PI_AUTO_STEP_SIZE; + else if (str == "DYNAMIC_VARIABLE") + return TimeControlType::DYNAMIC_VARIABLE; + else if (str.find("DYNAMIC_COURANT") != std::string::npos) + return TimeControlType::DYNAMIC_COURANT; + else if (str == "DYNAMIC_PRESSURE") + return TimeControlType::DYNAMIC_PRESSURE; + else if (str == "STEP_SIZE_RESTRICTION") + return TimeControlType::STEP_SIZE_RESTRICTION; + else if (str == "NEUMANN") + return TimeControlType::NEUMANN; + else if (str == "ERROR_CONTROL_ADAPTIVE") + return TimeControlType::ERROR_CONTROL_ADAPTIVE; + else if (str.find("SELF_ADAPTIVE") != std::string::npos) + return TimeControlType::SELF_ADAPTIVE; + else if (str == "STABLE_ERROR_ADAPTIVE") + return TimeControlType::STABLE_ERROR_ADAPTIVE; + + return TimeControlType::INVALID; } std::string convertTimeControlTypeToString(TimeControlType::type tc_type) { - if (tc_type == TimeControlType::FIXED_STEPS) - return "STEPS"; - else if (tc_type == TimeControlType::PI_AUTO_STEP_SIZE) - return "PI_AUTO_STEP_SIZE"; - else if (tc_type == TimeControlType::DYNAMIC_VARIABLE) - return "DYNAMIC_VARIABLE"; - else if (tc_type == TimeControlType::DYNAMIC_COURANT) - return "DYNAMIC_COURANT"; - else if (tc_type == TimeControlType::DYNAMIC_PRESSURE) - return "DYNAMIC_PRESSURE"; - else if (tc_type == TimeControlType::STEP_SIZE_RESTRICTION) - return "STEP_SIZE_RESTRICTION"; - else if (tc_type == TimeControlType::NEUMANN) - return "NEUMANN"; - else if (tc_type == TimeControlType::ERROR_CONTROL_ADAPTIVE) - return "ERROR_CONTROL_ADAPTIVE"; - else if (tc_type == TimeControlType::SELF_ADAPTIVE) - return "SELF_ADAPTIVE"; - else if (tc_type == TimeControlType::STABLE_ERROR_ADAPTIVE) - return "STABLE_ERROR_ADAPTIVE"; - return "INVALID"; - + if (tc_type == TimeControlType::FIXED_STEPS) + return "STEPS"; + else if (tc_type == TimeControlType::PI_AUTO_STEP_SIZE) + return "PI_AUTO_STEP_SIZE"; + else if (tc_type == TimeControlType::DYNAMIC_VARIABLE) + return "DYNAMIC_VARIABLE"; + else if (tc_type == TimeControlType::DYNAMIC_COURANT) + return "DYNAMIC_COURANT"; + else if (tc_type == TimeControlType::DYNAMIC_PRESSURE) + return "DYNAMIC_PRESSURE"; + else if (tc_type == TimeControlType::STEP_SIZE_RESTRICTION) + return "STEP_SIZE_RESTRICTION"; + else if (tc_type == TimeControlType::NEUMANN) + return "NEUMANN"; + else if (tc_type == TimeControlType::ERROR_CONTROL_ADAPTIVE) + return "ERROR_CONTROL_ADAPTIVE"; + else if (tc_type == TimeControlType::SELF_ADAPTIVE) + return "SELF_ADAPTIVE"; + else if (tc_type == TimeControlType::STABLE_ERROR_ADAPTIVE) + return "STABLE_ERROR_ADAPTIVE"; + return "INVALID"; } -ConstrainedType::type convertConstrainedType(const std::string &str) +ConstrainedType::type convertConstrainedType(const std::string& str) { if (str.compare("SMALLER") == 0) return ConstrainedType::SMALLER; @@ -681,8 +682,7 @@ std::string convertConstrainedTypeToString(ConstrainedType::type constrained_typ return "INVALID_CONSTRAINED_TYPE"; } - -ConstrainedVariable::type convertConstrainedVariable(const std::string &str) +ConstrainedVariable::type convertConstrainedVariable(const std::string& str) { if (str.compare("VELOCITY") == 0) return ConstrainedVariable::VELOCITY; @@ -695,4 +695,3 @@ std::string convertConstrainedVariableToString(ConstrainedVariable::type constra return "VELOCITY"; return "INVALID_CONSTRAINED_VARIABLE"; } - diff --git a/FEM/FEMEnums.h b/FEM/FEMEnums.h index c2b577f58..42bb1fa6b 100644 --- a/FEM/FEMEnums.h +++ b/FEM/FEMEnums.h @@ -25,38 +25,38 @@ namespace FiniteElement */ enum ProcessType { - INVALID_PROCESS = 0, //!< INVALID_PROCESS - AIR_FLOW, //!< AIR_FLOW + INVALID_PROCESS = 0, //!< INVALID_PROCESS + AIR_FLOW, //!< AIR_FLOW /// M process, single/multi-phase flow - DEFORMATION, //!< DEFORMATION - DEFORMATION_DYNAMIC, //!< ... + DEFORMATION, //!< DEFORMATION + DEFORMATION_DYNAMIC, //!< ... /// C process, single/multi-phase flow - DEFORMATION_FLOW, //!< DEFORMATION_FLOW + DEFORMATION_FLOW, //!< DEFORMATION_FLOW /// H2M monolithic - DEFORMATION_H2, //!< DEFORMATION_H2 + DEFORMATION_H2, //!< DEFORMATION_H2 FLUID_FLOW, - FLUID_MOMENTUM, // BC only + FLUID_MOMENTUM, // BC only FLUX, /// H process, incompressible flow - GROUNDWATER_FLOW, //!< GROUNDWATER_FLOW + GROUNDWATER_FLOW, //!< GROUNDWATER_FLOW /// T process, single/multi-phase flow - HEAT_TRANSPORT, //!< HEAT_TRANSPORT + HEAT_TRANSPORT, //!< HEAT_TRANSPORT /// H process, incompressible flow - LIQUID_FLOW, //!< LIQUID_FLOW - MASS_TRANSPORT, //!< MASS_TRANSPORT - MULTI_PHASE_FLOW, //!< MULTI_PHASE_FLOW - NO_PCS, //!< NO_PCS + LIQUID_FLOW, //!< LIQUID_FLOW + MASS_TRANSPORT, //!< MASS_TRANSPORT + MULTI_PHASE_FLOW, //!< MULTI_PHASE_FLOW + NO_PCS, //!< NO_PCS /// H process, incompressible flow - OVERLAND_FLOW, //!< OVERLAND_FLOW - PS_GLOBAL, //!< PS_GLOBAL - MULTI_COMPONENTIAL_FLOW, //!< Fluid flow coupled with heat transport - TNEQ, //!< reactive thermal nonequilibrium - TES, //!< reactive thermal equilibrium - RANDOM_WALK, //!< RANDOM_WALK + OVERLAND_FLOW, //!< OVERLAND_FLOW + PS_GLOBAL, //!< PS_GLOBAL + MULTI_COMPONENTIAL_FLOW, //!< Fluid flow coupled with heat transport + TNEQ, //!< reactive thermal nonequilibrium + TES, //!< reactive thermal equilibrium + RANDOM_WALK, //!< RANDOM_WALK /// H process, incompressible flow - RICHARDS_FLOW, //!< RICHARDS_FLOW + RICHARDS_FLOW, //!< RICHARDS_FLOW /// H2 process, compressible flow - TWO_PHASE_FLOW, //!< TWO_PHASE_FLOW + TWO_PHASE_FLOW, //!< TWO_PHASE_FLOW // make sure that this is always the last entry (important for iterating over the enum entries)! PROCESS_END }; @@ -66,35 +66,35 @@ enum ProcessType * @param pcs_type_string string describing a process type * @return enum value describing process type */ -ProcessType convertProcessType ( const std::string& pcs_type_string ); +ProcessType convertProcessType(const std::string& pcs_type_string); /** * \brief Convert the given enum value into the appropriate string. * @param pcs_type process type described by the enum ProcessType * @return string describing the process type */ -std::string convertProcessTypeToString ( ProcessType pcs_type ); +std::string convertProcessTypeToString(ProcessType pcs_type); /** * \brief Checks if the given pcs_type variable corresponds to a flow type of the enum ProcessType. * @param pcs_type value of enum ProcessType * @return true if pcs_type describes a flow process, else false */ -bool isFlowProcess (ProcessType pcs_type); +bool isFlowProcess(ProcessType pcs_type); /** * \brief Checks if the given pcs_type variable corresponds to a multiphase flow type of the enum ProcessType. * @param pcs_type value of enum ProcessType * @return true if pcs_type describes a flow process, else false */ -bool isMultiFlowProcess (ProcessType pcs_type); +bool isMultiFlowProcess(ProcessType pcs_type); /** * \brief Checks if the given pcs_type variable corresponds to a deformation type of the enum ProcessType. * @param pcs_type value of enum ProcessType * @return true if pcs_type describes a deformation process, else false */ -bool isDeformationProcess (ProcessType pcs_type); +bool isDeformationProcess(ProcessType pcs_type); /// Returns a list of strings containing all entries in the ProcessType enum. const std::list getAllProcessNames(); @@ -104,48 +104,48 @@ const std::list getAllProcessNames(); */ enum PrimaryVariable { - INVALID_PV = 0, //!< INVALID_PV - ACCELERATION_X1, //!< ACCELERATION_X1 - ACCELERATION_Y1, //!< ACCELERATION_Y1 - ACCELERATION_Z1, //!< ACCELERATION_Z1 + INVALID_PV = 0, //!< INVALID_PV + ACCELERATION_X1, //!< ACCELERATION_X1 + ACCELERATION_Y1, //!< ACCELERATION_Y1 + ACCELERATION_Z1, //!< ACCELERATION_Z1 /// Mass transport - CONCENTRATION, //!< CONCENTRATION + CONCENTRATION, //!< CONCENTRATION /// Deformation - DISPLACEMENT_X, //!< DISPLACEMENT_X + DISPLACEMENT_X, //!< DISPLACEMENT_X /// Deformation - DISPLACEMENT_Y, //!< DISPLACEMENT_Y + DISPLACEMENT_Y, //!< DISPLACEMENT_Y /// Deformation - DISPLACEMENT_Z, //!< DISPLACEMENT_Z + DISPLACEMENT_Z, //!< DISPLACEMENT_Z /// Deformation - DISPLACEMENT_N, //!< Normal traction (pressure type load). Only in ST - EXCAVATION, // ST - HEAD, //!< HEAD + DISPLACEMENT_N, //!< Normal traction (pressure type load). Only in ST + EXCAVATION, // ST + HEAD, //!< HEAD /// Flow (phase) - PRESSURE, //!< PRESSURE - PRESSURE2, //!< PRESSURE2 - PRESSURE_RATE1, // OUT - SATURATION, //!< SATURATION - SATURATION2, //!< SATURATION2 - STRAIN_XX, // Output - STRAIN_XY, // Output - STRAIN_XZ, // Output - STRAIN_YY, // Output - STRAIN_YZ, // Output - STRAIN_ZZ, // Output - STRAIN_PLS, // Output - STRESS_XX, // IC - STRESS_XY, // IC - STRESS_XZ, // IC - STRESS_YY, // IC - STRESS_YZ, // IC - STRESS_ZZ, // IC + PRESSURE, //!< PRESSURE + PRESSURE2, //!< PRESSURE2 + PRESSURE_RATE1, // OUT + SATURATION, //!< SATURATION + SATURATION2, //!< SATURATION2 + STRAIN_XX, // Output + STRAIN_XY, // Output + STRAIN_XZ, // Output + STRAIN_YY, // Output + STRAIN_YZ, // Output + STRAIN_ZZ, // Output + STRAIN_PLS, // Output + STRESS_XX, // IC + STRESS_XY, // IC + STRESS_XZ, // IC + STRESS_YY, // IC + STRESS_YZ, // IC + STRESS_ZZ, // IC /// Heat transport - TEMPERATURE, //!< TEMPERATURE - TEMPERATURE1, //!< for TNEQ/TES models - TEMPERATURE2, //!< for TNEQ model - VELOCITY_DM_X, //!< VELOCITY_DM_X - VELOCITY_DM_Y, //!< VELOCITY_DM_Y - VELOCITY_DM_Z, //!< VELOCITY_DM_Z + TEMPERATURE, //!< TEMPERATURE + TEMPERATURE1, //!< for TNEQ/TES models + TEMPERATURE2, //!< for TNEQ model + VELOCITY_DM_X, //!< VELOCITY_DM_X + VELOCITY_DM_Y, //!< VELOCITY_DM_Y + VELOCITY_DM_Z, //!< VELOCITY_DM_Z VELOCITY1_X, VELOCITY1_Y, VELOCITY1_Z, @@ -163,50 +163,50 @@ enum PrimaryVariable * @param pcs_pv_string string describing the primary variable * @return enum value describing the primary variable of the process */ - //!< PrimaryVariable -PrimaryVariable convertPrimaryVariable ( const std::string& pcs_pv_string ); +//!< PrimaryVariable +PrimaryVariable convertPrimaryVariable(const std::string& pcs_pv_string); /** * \brief Converts the given enum value into the appropriate string. * @param pcs_pv primary variable described by the enum ProcessType * @return string describing the process type */ -std::string convertPrimaryVariableToString ( PrimaryVariable pcs_pv ); +std::string convertPrimaryVariableToString(PrimaryVariable pcs_pv); /// Returns a list of strings containing all entries in the PrimaryVariable enum. const std::list getAllPrimaryVariableNames(); - enum DistributionType +enum DistributionType { INVALID_DIS_TYPE = 0, - ANALYTICAL, // ST + ANALYTICAL, // ST AVERAGE, - CONSTANT, // IC, BC, ST + CONSTANT, // IC, BC, ST CONSTANT_GEO, - CONSTANT_NEUMANN, // ST + CONSTANT_NEUMANN, // ST SWITCH, - CRITICALDEPTH, // ST + CRITICALDEPTH, // ST DIRECT, RECHARGE_DIRECT, FUNCTION, - GRADIENT, // IC - GREEN_AMPT, // ST - RESTART, // IC - LINEAR, // BC, ST - LINEAR_NEUMANN, // ST - NORMALDEPTH, // ST - POINT, // BC + GRADIENT, // IC + GREEN_AMPT, // ST + RESTART, // IC + LINEAR, // BC, ST + LINEAR_NEUMANN, // ST + NORMALDEPTH, // ST + POINT, // BC PRECIPITATION, - SYSTEM_DEPENDENT, // ST + SYSTEM_DEPENDENT, // ST TRANSFER_SURROUNDING, - NODESCONSTANT, // IC (for DOMAIN keyword) - CLIMATE, // climate data (by NB) - RECHARGE, // MW + NODESCONSTANT, // IC (for DOMAIN keyword) + CLIMATE, // climate data (by NB) + RECHARGE, // MW // Sort of Neumann BC //WW // make sure that this is always the last entry (important for iterating over the enum entries)! // make sure that this is always the last entry (important for iterating over the enum entries)! DIS_END - }; +}; /** * \brief Converts the given string into the appropriate enum value. @@ -229,11 +229,16 @@ const std::list getAllDistributionNames(); * If you change this enum, make sure you apply the changes to * the functions convertErrorMethod(), convertErrorMethodToString() Non-Linear and Coupling options (see also CRFProcess::CalcIterationNODError()): - --> LMAX: max(|x1-x0|) -- Infinity norm: Local max error (across all elements) of solution vector delta (absolute error). Tolerance required for each primary variable. - --> ENORM: |x1-x0| -- Euclidian norm: Norm of the solution vector delta (absolute error). Norm taken over entire solution vector (all primary variables) and checked against a single tolerance. - --> EVNORM: |x1-x0| -- Euclidian varient norm: Norm of the solution vector delta (absolute error). Norm taken over solution vector of each primary variable, checked againes a tolerence specific to each variable. - --> ERNORM: |(x1-x0)/x0)| -- Euclidian Relative norm: Norm of the solution vector delta divided by the norm of the solution vector. A single tolerance applied to all primary variables. - --> BNORM: -- OGS classic treatment of newton methods. ENORM error tolerance plus RHS ("B") control. (note: other error methods (i.e. ENORM) will also work well for NEWTON scheme) + --> LMAX: max(|x1-x0|) -- Infinity norm: Local max error (across all elements) of solution vector delta (absolute + error). Tolerance required for each primary variable. + --> ENORM: |x1-x0| -- Euclidian norm: Norm of the solution vector delta (absolute error). Norm taken over + entire solution vector (all primary variables) and checked against a single tolerance. + --> EVNORM: |x1-x0| -- Euclidian varient norm: Norm of the solution vector delta (absolute error). Norm taken + over solution vector of each primary variable, checked againes a tolerence specific to each variable. + --> ERNORM: |(x1-x0)/x0)| -- Euclidian Relative norm: Norm of the solution vector delta divided by the norm of the + solution vector. A single tolerance applied to all primary variables. + --> BNORM: -- OGS classic treatment of newton methods. ENORM error tolerance plus RHS ("B") control. + (note: other error methods (i.e. ENORM) will also work well for NEWTON scheme) */ enum ErrorMethod { @@ -250,9 +255,9 @@ enum ErrorMethod * @param pcs_type_string string describing an error method * @return enum value describing error method */ -ErrorMethod convertErrorMethod ( const std::string& error_method_string ); +ErrorMethod convertErrorMethod(const std::string& error_method_string); -//Determines into which energy balance interphase friction is integrated in TES models +// Determines into which energy balance interphase friction is integrated in TES models enum FrictionPhase { INVALID_FRICTION_TYPE = 0, @@ -261,10 +266,10 @@ enum FrictionPhase NONE }; -FrictionPhase convertFrictionPhase( const std::string& friction_string); +FrictionPhase convertFrictionPhase(const std::string& friction_string); std::string convertFrictionPhaseToString(FrictionPhase friction_phase); -//Solid Reactive System +// Solid Reactive System enum SolidReactiveSystem { INVALID_REACTIVE_SYSTEM = 0, @@ -275,7 +280,7 @@ enum SolidReactiveSystem Z13XBF }; -SolidReactiveSystem convertSolidReactiveSystem( const std::string& reactive_string); +SolidReactiveSystem convertSolidReactiveSystem(const std::string& reactive_string); std::string convertSolidReactiveSystemToString(SolidReactiveSystem reactive_system); } // end namespace FiniteElement @@ -295,7 +300,6 @@ TimType::type convertTimType(const std::string& str); std::string convertTimTypeToString(TimType::type type); - struct IterationType { enum type @@ -330,7 +334,7 @@ struct TimeControlType }; }; -TimeControlType::type convertTimeControlType(const std::string &str); +TimeControlType::type convertTimeControlType(const std::string& str); std::string convertTimeControlTypeToString(TimeControlType::type st_type); @@ -346,7 +350,7 @@ struct ConstrainedType }; }; -ConstrainedType::type convertConstrainedType(const std::string &str); +ConstrainedType::type convertConstrainedType(const std::string& str); std::string convertConstrainedTypeToString(ConstrainedType::type constrained_type); struct ConstrainedVariable @@ -358,7 +362,7 @@ struct ConstrainedVariable }; }; -ConstrainedVariable::type convertConstrainedVariable(const std::string &str); +ConstrainedVariable::type convertConstrainedVariable(const std::string& str); std::string convertConstrainedVariableToString(ConstrainedVariable::type constrained_variable); -#endif //FEMENUMS_H +#endif // FEMENUMS_H diff --git a/FEM/GeoInfo.cpp b/FEM/GeoInfo.cpp index 193b60b6c..f88ff84c7 100644 --- a/FEM/GeoInfo.cpp +++ b/FEM/GeoInfo.cpp @@ -16,52 +16,53 @@ // FEM #include "GeoInfo.h" -GeoInfo::GeoInfo() : - _geo_type(GEOLIB::INVALID), _geo_obj(NULL) -{} +GeoInfo::GeoInfo() : _geo_type(GEOLIB::INVALID), _geo_obj(NULL) +{ +} -GeoInfo::GeoInfo(GEOLIB::GEOTYPE geo_type, const GEOLIB::GeoObject* geo_obj) : - _geo_type(geo_type), _geo_obj(geo_obj) -{} +GeoInfo::GeoInfo(GEOLIB::GEOTYPE geo_type, const GEOLIB::GeoObject* geo_obj) : _geo_type(geo_type), _geo_obj(geo_obj) +{ +} GeoInfo::~GeoInfo() -{} +{ +} -GEOLIB::GEOTYPE GeoInfo::getGeoType () const +GEOLIB::GEOTYPE GeoInfo::getGeoType() const { return _geo_type; } -std::string GeoInfo::getGeoTypeAsString () const +std::string GeoInfo::getGeoTypeAsString() const { switch (_geo_type) { - case GEOLIB::POINT: - return "POINT"; - case GEOLIB::POLYLINE: - return "POLYLINE"; - case GEOLIB::SURFACE: - return "SURFACE"; - case GEOLIB::VOLUME: - return "VOLUME"; - case GEOLIB::GEODOMAIN: - return "DOMAIN"; - default: - return ""; + case GEOLIB::POINT: + return "POINT"; + case GEOLIB::POLYLINE: + return "POLYLINE"; + case GEOLIB::SURFACE: + return "SURFACE"; + case GEOLIB::VOLUME: + return "VOLUME"; + case GEOLIB::GEODOMAIN: + return "DOMAIN"; + default: + return ""; } } -void GeoInfo::setGeoType (GEOLIB::GEOTYPE geo_type) +void GeoInfo::setGeoType(GEOLIB::GEOTYPE geo_type) { _geo_type = geo_type; } -const GEOLIB::GeoObject* GeoInfo::getGeoObj () const +const GEOLIB::GeoObject* GeoInfo::getGeoObj() const { return _geo_obj; } -void GeoInfo::setGeoObj (const GEOLIB::GeoObject* geo_obj) +void GeoInfo::setGeoObj(const GEOLIB::GeoObject* geo_obj) { _geo_obj = geo_obj; } diff --git a/FEM/GeoInfo.h b/FEM/GeoInfo.h index 70fbdb906..c2617604b 100644 --- a/FEM/GeoInfo.h +++ b/FEM/GeoInfo.h @@ -30,7 +30,7 @@ class GeoInfo * standard constructor. You need to set the attributes via * setGeoType() and setGeoObj()! */ - GeoInfo (); + GeoInfo(); /** * The constructor of a GeoInfo object initializes the * attributes of the object. @@ -49,31 +49,31 @@ class GeoInfo * @sa enum GeoType * @return the geo type */ - GEOLIB::GEOTYPE getGeoType () const; + GEOLIB::GEOTYPE getGeoType() const; /** * get the type as a string for log output * @return */ - std::string getGeoTypeAsString () const; + std::string getGeoTypeAsString() const; /** * getter for the pointer to the object * @return */ - const GEOLIB::GeoObject* getGeoObj () const; + const GEOLIB::GeoObject* getGeoObj() const; /** * setter for the geo type * @sa enum GeoType * @param geo_type type of the geometric entity */ - void setGeoType (GEOLIB::GEOTYPE geo_type); + void setGeoType(GEOLIB::GEOTYPE geo_type); /** * setter for the pointer to the GeoObject object * @param geo_obj an instance of class GeoObject */ - void setGeoObj (const GEOLIB::GeoObject* geo_obj); + void setGeoObj(const GEOLIB::GeoObject* geo_obj); protected: /** @@ -85,4 +85,4 @@ class GeoInfo */ const GEOLIB::GeoObject* _geo_obj; }; -#endif /* GEOINFO_H_ */ +#endif /* GEOINFO_H_ */ diff --git a/FEM/InitialCondition.cpp b/FEM/InitialCondition.cpp index 6b5c8f05a..4201ad2ea 100644 --- a/FEM/InitialCondition.cpp +++ b/FEM/InitialCondition.cpp @@ -12,11 +12,10 @@ #include "InitialCondition.h" #include "rf_ic_new.h" -InitialCondition::InitialCondition(const CInitialCondition &ic, const std::string &geometry_name) - : FEMCondition(geometry_name, ic.getProcessType(), ic.getProcessPrimaryVariable(), - ic.getGeoType(), - (ic.getGeoType() == GEOLIB::GEODOMAIN) ? "Domain" : ic.getGeoName(), - ic.getProcessDistributionType(), FEMCondition::INITIAL_CONDITION) +InitialCondition::InitialCondition(const CInitialCondition& ic, const std::string& geometry_name) + : FEMCondition(geometry_name, ic.getProcessType(), ic.getProcessPrimaryVariable(), ic.getGeoType(), + (ic.getGeoType() == GEOLIB::GEODOMAIN) ? "Domain" : ic.getGeoName(), ic.getProcessDistributionType(), + FEMCondition::INITIAL_CONDITION) { if (this->getProcessDistributionType() == FiniteElement::CONSTANT) this->setConstantDisValue(ic.getGeoNodeValue()); diff --git a/FEM/InitialCondition.h b/FEM/InitialCondition.h index 8a4c059e6..b1a26591d 100644 --- a/FEM/InitialCondition.h +++ b/FEM/InitialCondition.h @@ -21,12 +21,10 @@ class InitialCondition : public FEMCondition { public: - InitialCondition(const std::string &geometry_name) - : FEMCondition(geometry_name, FEMCondition::INITIAL_CONDITION) {}; - InitialCondition(const CInitialCondition &ic, const std::string &geometry_name); - InitialCondition(const FEMCondition &cond) - : FEMCondition(cond, FEMCondition::INITIAL_CONDITION) {}; + InitialCondition(const std::string& geometry_name) : FEMCondition(geometry_name, FEMCondition::INITIAL_CONDITION){}; + InitialCondition(const CInitialCondition& ic, const std::string& geometry_name); + InitialCondition(const FEMCondition& cond) : FEMCondition(cond, FEMCondition::INITIAL_CONDITION){}; ~InitialCondition() {} }; -#endif //INITIALCONDITION_H +#endif // INITIALCONDITION_H diff --git a/FEM/LinearFunctionData.cpp b/FEM/LinearFunctionData.cpp index 9e011ade9..116134c78 100644 --- a/FEM/LinearFunctionData.cpp +++ b/FEM/LinearFunctionData.cpp @@ -19,8 +19,8 @@ // TF do this only in cpp files !!! using namespace std; -LinearFunctionData::LinearFunctionData(ifstream &ins, int num_var) : - _ndata(0), _subdom_index(NULL), _a0(NULL), _b0(NULL), _c0(NULL), _d0(NULL) +LinearFunctionData::LinearFunctionData(ifstream& ins, int num_var) + : _ndata(0), _subdom_index(NULL), _a0(NULL), _b0(NULL), _c0(NULL), _d0(NULL) { bool is_sub_domain = false; if (num_var > 0) @@ -60,7 +60,7 @@ LinearFunctionData::LinearFunctionData(ifstream &ins, int num_var) : else ins >> str_buff >> ws; - pch = strtok(const_cast (str_buff.c_str()), seps); + pch = strtok(const_cast(str_buff.c_str()), seps); buff << pch; buff >> _a0[i]; buff.clear(); @@ -74,25 +74,25 @@ LinearFunctionData::LinearFunctionData(ifstream &ins, int num_var) : } for (size_t k = 0; k < tokens.size(); k++) { - pch = strtok(const_cast (tokens[k].c_str()), seps1); + pch = strtok(const_cast(tokens[k].c_str()), seps1); buff << pch; buff >> f_buff; buff.clear(); pch = strtok(NULL, seps1); switch (pch[0]) { - case 'x': - _b0[i] = f_buff; - break; - case 'y': - _c0[i] = f_buff; - break; - case 'z': - _d0[i] = f_buff; - break; + case 'x': + _b0[i] = f_buff; + break; + case 'y': + _c0[i] = f_buff; + break; + case 'z': + _d0[i] = f_buff; + break; } } -// tokens.clear(); + // tokens.clear(); } } /*! diff --git a/FEM/LinearFunctionData.h b/FEM/LinearFunctionData.h index f194e657f..ed07038d8 100644 --- a/FEM/LinearFunctionData.h +++ b/FEM/LinearFunctionData.h @@ -33,22 +33,18 @@ class LinearFunctionData WW 24.08.2011 */ - LinearFunctionData(std::ifstream &ins, int num_var = -1); + LinearFunctionData(std::ifstream& ins, int num_var = -1); ~LinearFunctionData(); double getValue(size_t dom_i, double x, double y, double z) const; double getValue(double x, double y, double z) const; - size_t* getSubDomIndex() const - { - return _subdom_index; - } - + size_t* getSubDomIndex() const { return _subdom_index; } private: size_t _ndata; size_t* _subdom_index; // Coefficents for linear distribution function // f = a0+b0*x+c0*y+d0*z - double* _a0, * _b0, * _c0, * _d0; + double *_a0, *_b0, *_c0, *_d0; }; #endif /* LINEARFUNCTIONDATA_H_ */ diff --git a/FEM/Output.cpp b/FEM/Output.cpp index f7e48d110..f1f3763c2 100644 --- a/FEM/Output.cpp +++ b/FEM/Output.cpp @@ -41,13 +41,12 @@ #include "MathTools.h" #include "matrix_class.h" // JOD 2014-11-10 - #include "mathlib.h" #include "fem_ele.h" #include "tools.h" #include "FileTools.h" -extern size_t max_dim; //OK411 todo +extern size_t max_dim; // OK411 todo #ifdef CHEMAPP #include "eqlink.h" @@ -58,7 +57,7 @@ extern size_t max_dim; //OK411 todo #endif #ifdef SUPERCOMPUTER // kg44 this is usefull for io-buffering as endl flushes the buffer -#define endl '\n' // Introduced by WW. LB super bad programming style: this breaks platform independet IO +#define endl '\n' // Introduced by WW. LB super bad programming style: this breaks platform independet IO #define MY_IO_BUFSIZE 4096 #endif // SUPERCOMPUTER #ifdef GEM_REACT @@ -72,15 +71,15 @@ using MeshLib::CNode; using namespace std; -COutput::COutput() : - GeoInfo(GEOLIB::GEODOMAIN), ProcessInfo(), _id(0), out_amplifier(0.0), - m_msh(NULL), nSteps(-1), _new_file_opened(false), dat_type_name("TECPLOT") +COutput::COutput() + : GeoInfo(GEOLIB::GEODOMAIN), ProcessInfo(), _id(0), out_amplifier(0.0), m_msh(NULL), nSteps(-1), + _new_file_opened(false), dat_type_name("TECPLOT") { tim_type_name = "TIMES"; m_pcs = NULL; - vtk = NULL; //NW + vtk = NULL; // NW tecplot_zone_share = false; // 10.2012. WW - VARIABLESHARING = false; //BG + VARIABLESHARING = false; // BG #if defined(USE_PETSC) || defined(USE_MPI) //|| defined(other parallel libs)//01.3014. WW int_disp = 0; offset = 0; @@ -88,15 +87,15 @@ COutput::COutput() : #endif } -COutput::COutput(size_t id) : - GeoInfo(GEOLIB::GEODOMAIN), ProcessInfo(), _id(id), out_amplifier(0.0), - m_msh(NULL), nSteps(-1), _new_file_opened(false), dat_type_name("TECPLOT") +COutput::COutput(size_t id) + : GeoInfo(GEOLIB::GEODOMAIN), ProcessInfo(), _id(id), out_amplifier(0.0), m_msh(NULL), nSteps(-1), + _new_file_opened(false), dat_type_name("TECPLOT") { tim_type_name = "TIMES"; m_pcs = NULL; - vtk = NULL; //NW + vtk = NULL; // NW tecplot_zone_share = false; // 10.2012. WW - VARIABLESHARING = false; //BG + VARIABLESHARING = false; // BG #if defined(USE_PETSC) || defined(USE_MPI) //|| defined(other parallel libs)//01.3014. WW int_disp = 0; domain_output_counter = 0; @@ -118,61 +117,61 @@ void COutput::setMPI_Info(const int rank, const int size, std::string rank_str) void COutput::CreateVTKInstance(void) { #if defined(USE_PETSC) || defined(USE_MPI) //|| defined(other parallel libs)//03.3012. WW - vtk = new CVTK(mrank, mrank_str); + vtk = new CVTK(mrank, mrank_str); #else - vtk = new CVTK(); + vtk = new CVTK(); #endif - } void COutput::init() { - if (getProcessType () == FiniteElement::INVALID_PROCESS) + if (getProcessType() == FiniteElement::INVALID_PROCESS) { - std::cerr << - "COutput::init(): could not initialize process pointer (process type INVALID_PROCESS) and appropriate mesh" + std::cerr << "COutput::init(): could not initialize process pointer (process type INVALID_PROCESS) and " + "appropriate mesh" + << "\n"; + std::cerr << "COutput::init(): trying to fetch process pointer using msh_type_name ... " << "\n"; - std::cerr << - "COutput::init(): trying to fetch process pointer using msh_type_name ... " << - "\n"; - if(msh_type_name.size() > 0) + if (msh_type_name.size() > 0) { _pcs = PCSGet(msh_type_name); if (_pcs) - std::cerr << " successful" << "\n"; + std::cerr << " successful" + << "\n"; else { - std::cerr << " failed" << "\n"; - exit (1); + std::cerr << " failed" + << "\n"; + exit(1); } } else - std::cerr << " failed" << "\n"; + std::cerr << " failed" + << "\n"; } m_msh = FEMGet(convertProcessTypeToString(getProcessType())); - setInternalVarialbeNames(m_msh); //NW + setInternalVarialbeNames(m_msh); // NW - // For binary output of the domain data +// For binary output of the domain data #if defined(USE_PETSC) // || defined(other solver libs)//01.3014. WW - if( (getGeoType() == GEOLIB::GEODOMAIN) || (dat_type_name.compare("BINARY") != 0 ) ) - { - //dat_type_name = "BINARY"; - setDataArrayDisp(); - } + if ((getGeoType() == GEOLIB::GEODOMAIN) || (dat_type_name.compare("BINARY") != 0)) + { + // dat_type_name = "BINARY"; + setDataArrayDisp(); + } #endif - } COutput::~COutput() { - mmp_value_vector.clear(); //OK + mmp_value_vector.clear(); // OK if (this->vtk != NULL) - delete vtk; //NW + delete vtk; // NW } -const std::string& COutput::getGeoName () const +const std::string& COutput::getGeoName() const { return geo_name; } @@ -191,8 +190,8 @@ const std::string& COutput::getGeoName () const 06/2010 TF formated, restructured, signature changed, use new GEOLIB data structures 09/2010 TF signature changed, removed some variables **************************************************************************/ -ios::pos_type COutput::Read(std::ifstream& in_str, - const GEOLIB::GEOObjects& geo_obj, const std::string& unique_geo_name) +ios::pos_type COutput::Read(std::ifstream& in_str, const GEOLIB::GEOObjects& geo_obj, + const std::string& unique_geo_name) { std::string line_string; bool new_keyword = false; @@ -228,7 +227,7 @@ ios::pos_type COutput::Read(std::ifstream& in_str, while ((!new_keyword) && (!new_subkeyword)) { position_subkeyword = in_str.tellg(); - //SB input with comments in_str >> line_string>>ws; + // SB input with comments in_str >> line_string>>ws; line_string = GetLineFromFile1(&in_str); if (line_string.find("#") != string::npos) return position; @@ -238,11 +237,11 @@ ios::pos_type COutput::Read(std::ifstream& in_str, break; } if (line_string.size() == 0) - break; //SB: empty line + break; // SB: empty line in.str(line_string); in >> name; //_alias_nod_value_vector.push_back(name); - _nod_value_vector.push_back(name); + _nod_value_vector.push_back(name); in.clear(); } @@ -313,7 +312,7 @@ ios::pos_type COutput::Read(std::ifstream& in_str, break; } if (line_string.size() == 0) - break; //SB: empty line + break; // SB: empty line in.str(line_string); in >> name; _rwpt_value_vector.push_back(name); @@ -322,10 +321,10 @@ ios::pos_type COutput::Read(std::ifstream& in_str, continue; } - //subkeyword found + // subkeyword found if (line_string.find("$GEO_TYPE") != string::npos) { - FileIO::GeoIO::readGeoInfo (this, in_str, geo_name, geo_obj, unique_geo_name); + FileIO::GeoIO::readGeoInfo(this, in_str, geo_name, geo_obj, unique_geo_name); continue; } @@ -336,7 +335,7 @@ ios::pos_type COutput::Read(std::ifstream& in_str, { position_subkeyword = in_str.tellg(); in_str >> line_string; - if (line_string.size() == 0) //SB + if (line_string.size() == 0) // SB break; if (line_string.find("#") != string::npos) { @@ -351,8 +350,8 @@ ios::pos_type COutput::Read(std::ifstream& in_str, if (line_string.find("STEPS") != string::npos) { in_str >> nSteps; - tim_type_name = "STEPS"; //OK - break; //kg44 I guess that was missing..otherwise it pushes back a time_vector! + tim_type_name = "STEPS"; // OK + break; // kg44 I guess that was missing..otherwise it pushes back a time_vector! } // JT 2010, reconfigured (and added RWPT)... didn't work if (line_string.find("STEPPING") != string::npos) @@ -384,11 +383,11 @@ ios::pos_type COutput::Read(std::ifstream& in_str, } // Coordinates of each node as well as connection list is stored only for the first time step; BG: 05/2011 - if (line_string.find("$VARIABLESHARING") != string::npos) - { - this->VARIABLESHARING = true; - continue; - } + if (line_string.find("$VARIABLESHARING") != string::npos) + { + this->VARIABLESHARING = true; + continue; + } // subkeyword found if (line_string.find("$AMPLIFIER") != string::npos) @@ -428,7 +427,7 @@ ios::pos_type COutput::Read(std::ifstream& in_str, { std::string dis_type_name; in_str >> dis_type_name; - setProcessDistributionType (FiniteElement::convertDisType(dis_type_name)); + setProcessDistributionType(FiniteElement::convertDisType(dis_type_name)); in_str.ignore(MAX_ZEILE, '\n'); continue; } @@ -441,7 +440,7 @@ ios::pos_type COutput::Read(std::ifstream& in_str, continue; } - //OK + // OK if (line_string.find("$MMP_VALUES") != string::npos) { ok = true; @@ -462,7 +461,7 @@ ios::pos_type COutput::Read(std::ifstream& in_str, continue; } - //OK + // OK if (line_string.find("$MFP_VALUES") != string::npos) { ok = true; @@ -508,36 +507,43 @@ void COutput::Write(fstream* out_file) { //-------------------------------------------------------------------- // KEYWORD - *out_file << "#OUTPUT" << "\n"; + *out_file << "#OUTPUT" + << "\n"; //-------------------------------------------------------------------- // PCS_TYPE - *out_file << " $PCS_TYPE" << "\n" << " "; + *out_file << " $PCS_TYPE" + << "\n" + << " "; *out_file << convertProcessTypeToString(getProcessType()) << "\n"; //-------------------------------------------------------------------- // NOD_VALUES - *out_file << " $NOD_VALUES" << "\n"; + *out_file << " $NOD_VALUES" + << "\n"; size_t nod_value_vector_size(_nod_value_vector.size()); for (size_t i = 0; i < nod_value_vector_size; i++) *out_file << " " << _nod_value_vector[i] << "\n"; //-------------------------------------------------------------------- // ELE_VALUES - *out_file << " $ELE_VALUES" << "\n"; - size_t ele_value_vector_size (_ele_value_vector.size()); + *out_file << " $ELE_VALUES" + << "\n"; + size_t ele_value_vector_size(_ele_value_vector.size()); for (size_t i = 0; i < ele_value_vector_size; i++) *out_file << " " << _ele_value_vector[i] << "\n"; //-------------------------------------------------------------------- // GEO_TYPE - *out_file << " $GEO_TYPE" << "\n"; + *out_file << " $GEO_TYPE" + << "\n"; *out_file << " "; *out_file << getGeoTypeAsString() << " " << geo_name << "\n"; //-------------------------------------------------------------------- // TIM_TYPE - *out_file << " $TIM_TYPE" << "\n"; + *out_file << " $TIM_TYPE" + << "\n"; if (tim_type_name == "STEPS") *out_file << " " << tim_type_name << " " << nSteps << "\n"; else { - size_t time_vector_size (time_vector.size()); + size_t time_vector_size(time_vector.size()); for (size_t i = 0; i < time_vector_size; i++) *out_file << " " << time_vector[i] << "\n"; } @@ -550,21 +556,24 @@ void COutput::Write(fstream* out_file) // } if (getProcessDistributionType() != FiniteElement::INVALID_DIS_TYPE) { - *out_file << " $DIS_TYPE" << "\n"; + *out_file << " $DIS_TYPE" + << "\n"; *out_file << " "; - *out_file << convertDisTypeToString (getProcessDistributionType()) << "\n"; + *out_file << convertDisTypeToString(getProcessDistributionType()) << "\n"; } // MSH_TYPE if (msh_type_name.size() > 0) { - *out_file << " $MSH_TYPE" << "\n"; + *out_file << " $MSH_TYPE" + << "\n"; *out_file << " "; *out_file << msh_type_name << "\n"; } //-------------------------------------------------------------------- // DAT_TYPE - *out_file << " $DAT_TYPE" << "\n"; + *out_file << " $DAT_TYPE" + << "\n"; *out_file << " "; *out_file << dat_type_name << "\n"; //-------------------------------------------------------------------- @@ -587,161 +596,163 @@ void COutput::NODWriteDOMDataTEC() string tec_file_name; #if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) char tf_name[10]; - std::cout << "Process " << myrank << " in WriteDOMDataTEC" << "\n"; + std::cout << "Process " << myrank << " in WriteDOMDataTEC" + << "\n"; #endif //---------------------------------------------------------------------- // Tests - //OK4704 - if((_nod_value_vector.size() == 0) && (mfp_value_vector.size() == 0)) + // OK4704 + if ((_nod_value_vector.size() == 0) && (mfp_value_vector.size() == 0)) return; //...................................................................... // MSH - //m_msh = FEMGet(pcs_type_name); + // m_msh = FEMGet(pcs_type_name); // m_msh = GetMSH(); - if(!m_msh) + if (!m_msh) { - cout << "Warning in COutput::NODWriteDOMDataTEC() - no MSH data" << "\n"; + cout << "Warning in COutput::NODWriteDOMDataTEC() - no MSH data" + << "\n"; return; } //====================================================================== - vector mesh_type_list; //NW + vector mesh_type_list; // NW if (m_msh->getNumberOfLines() > 0) mesh_type_list.push_back(1); if (m_msh->getNumberOfQuads() > 0) mesh_type_list.push_back(2); - if (m_msh->getNumberOfHexs () > 0) + if (m_msh->getNumberOfHexs() > 0) mesh_type_list.push_back(3); - if (m_msh->getNumberOfTris () > 0) + if (m_msh->getNumberOfTris() > 0) mesh_type_list.push_back(4); - if (m_msh->getNumberOfTets () > 0) + if (m_msh->getNumberOfTets() > 0) mesh_type_list.push_back(5); - if (m_msh->getNumberOfPrisms () > 0) + if (m_msh->getNumberOfPrisms() > 0) mesh_type_list.push_back(6); if (m_msh->getNumberOfPyramids() > 0) mesh_type_list.push_back(7); // Output files for each mesh type - //NW + // NW for (int i = 0; i < (int)mesh_type_list.size(); i++) { te = mesh_type_list[i]; //---------------------------------------------------------------------- // File name handling tec_file_name = file_base_name + "_" + "domain"; - if(msh_type_name.size() > 0) // MultiMSH + if (msh_type_name.size() > 0) // MultiMSH tec_file_name += "_" + msh_type_name; - if(getProcessType() != FiniteElement::INVALID_PROCESS) // PCS + if (getProcessType() != FiniteElement::INVALID_PROCESS) // PCS tec_file_name += "_" + convertProcessTypeToString(getProcessType()); //====================================================================== - switch (te) //NW + switch (te) // NW { - case 1: - tec_file_name += "_line"; - eleType = "QUADRILATERAL"; - break; - case 2: - tec_file_name += "_quad"; - eleType = "QUADRILATERAL"; - break; - case 3: - tec_file_name += "_hex"; - eleType = "BRICK"; - break; - case 4: - tec_file_name += "_tri"; - eleType = "QUADRILATERAL"; - break; - case 5: - tec_file_name += "_tet"; - eleType = "TETRAHEDRON"; - break; - case 6: - tec_file_name += "_pris"; - eleType = "BRICK"; - break; - case 7: - tec_file_name += "_pyra"; - eleType = "BRICK"; - break; + case 1: + tec_file_name += "_line"; + eleType = "QUADRILATERAL"; + break; + case 2: + tec_file_name += "_quad"; + eleType = "QUADRILATERAL"; + break; + case 3: + tec_file_name += "_hex"; + eleType = "BRICK"; + break; + case 4: + tec_file_name += "_tri"; + eleType = "QUADRILATERAL"; + break; + case 5: + tec_file_name += "_tet"; + eleType = "TETRAHEDRON"; + break; + case 6: + tec_file_name += "_pris"; + eleType = "BRICK"; + break; + case 7: + tec_file_name += "_pyra"; + eleType = "BRICK"; + break; } - /* - if(m_msh->msh_no_line>0) - { - tec_file_name += "_line"; - eleType = "QUADRILATERAL"; - te=1; - } - else if (m_msh->msh_no_quad>0) - { - tec_file_name += "_quad"; - eleType = "QUADRILATERAL"; - te=2; - } - else if (m_msh->msh_no_hexs>0) - { - tec_file_name += "_hex"; - eleType = "BRICK"; - te=3; - } - else if (m_msh->msh_no_tris>0) - { - tec_file_name += "_tri"; - //???Who was this eleType = "TRIANGLE"; - eleType = "QUADRILATERAL"; - te=4; - } - else if (m_msh->msh_no_tets>0) - { - tec_file_name += "_tet"; - eleType = "TETRAHEDRON"; - te=5; - } - else if (m_msh->msh_no_pris>0) - { - tec_file_name += "_pris"; - eleType = "BRICK"; - te=6; - } - */ +/* + if(m_msh->msh_no_line>0) + { + tec_file_name += "_line"; + eleType = "QUADRILATERAL"; + te=1; + } + else if (m_msh->msh_no_quad>0) + { + tec_file_name += "_quad"; + eleType = "QUADRILATERAL"; + te=2; + } + else if (m_msh->msh_no_hexs>0) + { + tec_file_name += "_hex"; + eleType = "BRICK"; + te=3; + } + else if (m_msh->msh_no_tris>0) + { + tec_file_name += "_tri"; + //???Who was this eleType = "TRIANGLE"; + eleType = "QUADRILATERAL"; + te=4; + } + else if (m_msh->msh_no_tets>0) + { + tec_file_name += "_tet"; + eleType = "TETRAHEDRON"; + te=5; + } + else if (m_msh->msh_no_pris>0) + { + tec_file_name += "_pris"; + eleType = "BRICK"; + te=6; + } + */ #if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) sprintf(tf_name, "%d", myrank); tec_file_name += "_" + string(tf_name); std::cout << "Tecplot filename: " << tec_file_name << "\n"; #endif -#if defined(USE_PETSC) //|| defined(other parallel libs)//03.3012. WW - tec_file_name += "_"+mrank_str; +#if defined(USE_PETSC) //|| defined(other parallel libs)//03.3012. WW + tec_file_name += "_" + mrank_str; std::cout << "Tecplot filename: " << tec_file_name << "\n"; #endif tec_file_name += TEC_FILE_EXTENSION; - //WW - if(!_new_file_opened) + // WW + if (!_new_file_opened) remove(tec_file_name.c_str()); - fstream tec_file (tec_file_name.data(),ios::app | ios::out); - tec_file.setf(ios::scientific,ios::floatfield); + fstream tec_file(tec_file_name.data(), ios::app | ios::out); + tec_file.setf(ios::scientific, ios::floatfield); tec_file.precision(12); if (!tec_file.good()) return; #ifdef SUPERCOMPUTER // kg44 buffer the output - char mybuf1 [MY_IO_BUFSIZE * MY_IO_BUFSIZE]; - tec_file.rdbuf()->pubsetbuf(mybuf1,MY_IO_BUFSIZE * MY_IO_BUFSIZE); + char mybuf1[MY_IO_BUFSIZE * MY_IO_BUFSIZE]; + tec_file.rdbuf()->pubsetbuf(mybuf1, MY_IO_BUFSIZE * MY_IO_BUFSIZE); #endif // - WriteTECHeader(tec_file,te,eleType); + WriteTECHeader(tec_file, te, eleType); WriteTECNodeData(tec_file); // 08.2012. WW - if(tecplot_zone_share) + if (tecplot_zone_share) { - if(!_new_file_opened) - WriteTECElementData(tec_file,te); + if (!_new_file_opened) + WriteTECElementData(tec_file, te); } else { - WriteTECElementData(tec_file,te); + WriteTECElementData(tec_file, te); } - tec_file.close(); // kg44 close file + tec_file.close(); // kg44 close file //-------------------------------------------------------------------- // tri elements // ***** 07/2010 TF commented out block since the global variable is always zero @@ -878,37 +889,36 @@ void COutput::NODWriteDOMDataTEC() #if defined(USE_PETSC) // || defined(other solver libs)//01.2014. WW void COutput::setDataArrayDisp() { - // MPI_Barrier (MPI_COMM_WORLD); - // - int *i_cnt; - int *i_disp; - int *i_recv; + // MPI_Barrier (MPI_COMM_WORLD); + // + int* i_cnt; + int* i_disp; + int* i_recv; - i_cnt = new int[msize]; - i_disp = new int[msize]; - i_recv = new int[msize]; + i_cnt = new int[msize]; + i_disp = new int[msize]; + i_recv = new int[msize]; - for(int i=0; igetNumNodesLocal(); + int size_local = fem_msh_vector[0]->getNumNodesLocal(); - MPI_Allgatherv(&size_local, 1, MPI_INT, i_recv, i_cnt, i_disp, - MPI_INT, MPI_COMM_WORLD); + MPI_Allgatherv(&size_local, 1, MPI_INT, i_recv, i_cnt, i_disp, MPI_INT, MPI_COMM_WORLD); - int_disp = 0; - for(int i=0; iGetPrimaryVNumber(); - const size_t num_2nd_unknowns = m_pcs->GetSecondaryVNumber(); + const size_t num_prim_unknowns = m_pcs->GetPrimaryVNumber(); + const size_t num_2nd_unknowns = m_pcs->GetSecondaryVNumber(); - os << convertProcessTypeToString(getProcessType()) << "\n"; - os << num_prim_unknowns + num_2nd_unknowns << "\n"; + os << convertProcessTypeToString(getProcessType()) << "\n"; + os << num_prim_unknowns + num_2nd_unknowns << "\n"; - for(size_t i=0; i < num_prim_unknowns; i++) - { - os << m_pcs->GetPrimaryVName(i) << " "; - } - for(size_t i=0; i < num_2nd_unknowns; i++) - { - os << m_pcs->GetSecondaryVName(i) << " "; - } - os << "\n"; + for (size_t i = 0; i < num_prim_unknowns; i++) + { + os << m_pcs->GetPrimaryVName(i) << " "; + } + for (size_t i = 0; i < num_2nd_unknowns; i++) + { + os << m_pcs->GetSecondaryVName(i) << " "; + } + os << "\n"; - // Write number of unknowns - os << m_pcs->m_msh->getNumNodesGlobal() << "\n"; + // Write number of unknowns + os << m_pcs->m_msh->getNumNodesGlobal() << "\n"; - os.close(); + os.close(); } /* @@ -969,83 +979,84 @@ void COutput::NODDomainWriteBinary_Header() */ void COutput::NODDomainWriteBinary() { - string file_name; + string file_name; - file_name = file_base_name + "_" + convertProcessTypeToString(getProcessType()) + "_domain_variables" + ".bin"; - std::cout << "Name of the binary file for node and element data: " << file_name << "\n"; + file_name = file_base_name + "_" + convertProcessTypeToString(getProcessType()) + "_domain_variables" + ".bin"; + std::cout << "Name of the binary file for node and element data: " << file_name << "\n"; - domain_output_counter++; + domain_output_counter++; - if(!_new_file_opened) - { - remove(file_name.c_str()); - } + if (!_new_file_opened) + { + remove(file_name.c_str()); + } - m_pcs = GetPCS(); + m_pcs = GetPCS(); - MPI_Barrier (MPI_COMM_WORLD); + MPI_Barrier(MPI_COMM_WORLD); - MPI_Offset offset_new; - MPI_File fh; - int rc = 0; + MPI_Offset offset_new; + MPI_File fh; + int rc = 0; - if(!_new_file_opened) - { - rc = MPI_File_open(MPI_COMM_WORLD, &file_name[0], MPI_MODE_WRONLY | MPI_MODE_CREATE, MPI_INFO_NULL, &fh); - offset = 0; - } - else - { - rc = MPI_File_open(MPI_COMM_WORLD, &file_name[0], MPI_MODE_WRONLY | MPI_MODE_APPEND, MPI_INFO_NULL, &fh); - } + if (!_new_file_opened) + { + rc = MPI_File_open(MPI_COMM_WORLD, &file_name[0], MPI_MODE_WRONLY | MPI_MODE_CREATE, MPI_INFO_NULL, &fh); + offset = 0; + } + else + { + rc = MPI_File_open(MPI_COMM_WORLD, &file_name[0], MPI_MODE_WRONLY | MPI_MODE_APPEND, MPI_INFO_NULL, &fh); + } - if (rc ) - { - MPI_Finalize(); - cout<<"Cannot open "<GetPrimaryVNumber(); - const size_t num_2nd_unknowns = m_pcs->GetSecondaryVNumber(); - // Write unknowns - size_t n_unknowns = 0; - n_unknowns = m_pcs->m_msh->getNumNodesLocal(); - const int nn = m_pcs->m_msh->getNumNodesGlobal(); + const size_t num_prim_unknowns = m_pcs->GetPrimaryVNumber(); + const size_t num_2nd_unknowns = m_pcs->GetSecondaryVNumber(); + // Write unknowns + size_t n_unknowns = 0; + n_unknowns = m_pcs->m_msh->getNumNodesLocal(); + const int nn = m_pcs->m_msh->getNumNodesGlobal(); - // Write primary unknowns - for(size_t i=0; i < num_prim_unknowns; i++) - { - double *node_values = m_pcs->getNodeValue_per_Variable(2*i + 1); - offset_new = offset + int_disp*sizeof(double); - MPI_File_set_view(fh, offset_new, MPI_DOUBLE, MPI_DOUBLE, &ftype[0], MPI_INFO_NULL); - MPI_File_write(fh, node_values, n_unknowns, MPI_DOUBLE, MPI_STATUS_IGNORE); //_all - offset += nn * sizeof(double); - } + // Write primary unknowns + for (size_t i = 0; i < num_prim_unknowns; i++) + { + double* node_values = m_pcs->getNodeValue_per_Variable(2 * i + 1); + offset_new = offset + int_disp * sizeof(double); + MPI_File_set_view(fh, offset_new, MPI_DOUBLE, MPI_DOUBLE, &ftype[0], MPI_INFO_NULL); + MPI_File_write(fh, node_values, n_unknowns, MPI_DOUBLE, MPI_STATUS_IGNORE); //_all + offset += nn * sizeof(double); + } - // Write secondary unknowns - for(size_t i=0; i < num_2nd_unknowns; i++) - { - double *node_values = m_pcs->getNodeValue_per_Variable(2*num_prim_unknowns + i); - offset_new = offset + int_disp*sizeof(double); - MPI_File_set_view(fh, offset_new, MPI_DOUBLE, MPI_DOUBLE, &ftype[0], MPI_INFO_NULL); - MPI_File_write(fh, node_values, n_unknowns, MPI_DOUBLE, MPI_STATUS_IGNORE); //_all - offset += nn * sizeof(double); - } + // Write secondary unknowns + for (size_t i = 0; i < num_2nd_unknowns; i++) + { + double* node_values = m_pcs->getNodeValue_per_Variable(2 * num_prim_unknowns + i); + offset_new = offset + int_disp * sizeof(double); + MPI_File_set_view(fh, offset_new, MPI_DOUBLE, MPI_DOUBLE, &ftype[0], MPI_INFO_NULL); + MPI_File_write(fh, node_values, n_unknowns, MPI_DOUBLE, MPI_STATUS_IGNORE); //_all + offset += nn * sizeof(double); + } - MPI_File_sync( fh ) ; - MPI_Barrier( MPI_COMM_WORLD ) ; - MPI_File_sync( fh ) ; - MPI_File_close(&fh); + MPI_File_sync(fh); + MPI_Barrier(MPI_COMM_WORLD); + MPI_File_sync(fh); + MPI_File_close(&fh); } #endif // end of USE_PETSC @@ -1059,15 +1070,15 @@ void COutput::NODDomainWriteBinary() 12/2005 OK Mass transport specifics OK ??? too many specifics **************************************************************************/ -void COutput::WriteTECNodeData(fstream &tec_file) +void COutput::WriteTECNodeData(fstream& tec_file) { const size_t nName(_nod_value_vector.size()); - double val_n = 0.; //WW + double val_n = 0.; // WW int nidx, nidx_dm[3]; vector NodeIndex(nName); - string nod_value_name; //OK - CNode *node = NULL; - CRFProcess *deform_pcs = NULL; // 23.01.2012. WW. nulltpr + string nod_value_name; // OK + CNode* node = NULL; + CRFProcess* deform_pcs = NULL; // 23.01.2012. WW. nulltpr int timelevel; // m_msh = GetMSH(); @@ -1078,19 +1089,18 @@ void COutput::WriteTECNodeData(fstream &tec_file) m_pcs = PCSGet(_nod_value_vector[k], true); if (m_pcs != NULL) { - NodeIndex[k] = m_pcs->GetNodeValueIndex(_nod_value_vector[k],true); // JT Latest. - if( (m_pcs->getProcessType() == FiniteElement::DEFORMATION) - || (m_pcs->getProcessType() == FiniteElement::DEFORMATION_DYNAMIC) - || (m_pcs->getProcessType() == FiniteElement::DEFORMATION_FLOW) - || (m_pcs->getProcessType() == FiniteElement::DEFORMATION_H2) - ) - { - deform_pcs = m_pcs; - } - } - } + NodeIndex[k] = m_pcs->GetNodeValueIndex(_nod_value_vector[k], true); // JT Latest. + if ((m_pcs->getProcessType() == FiniteElement::DEFORMATION) + || (m_pcs->getProcessType() == FiniteElement::DEFORMATION_DYNAMIC) + || (m_pcs->getProcessType() == FiniteElement::DEFORMATION_FLOW) + || (m_pcs->getProcessType() == FiniteElement::DEFORMATION_H2)) + { + deform_pcs = m_pcs; + } + } + } - if (deform_pcs) // 23.01.2012. WW. + if (deform_pcs) // 23.01.2012. WW. { nidx_dm[0] = deform_pcs->GetNodeValueIndex("DISPLACEMENT_X1") + 1; nidx_dm[1] = deform_pcs->GetNodeValueIndex("DISPLACEMENT_Y1") + 1; @@ -1101,32 +1111,32 @@ void COutput::WriteTECNodeData(fstream &tec_file) } // 08.2012. WW bool out_coord = true; - if(tecplot_zone_share && _new_file_opened) - out_coord = false; + if (tecplot_zone_share && _new_file_opened) + out_coord = false; for (size_t j = 0; j < m_msh->GetNodesNumber(false); j++) { - node = m_msh->nod_vector[j]; // 23.01.2013. WW - const size_t n_id = node->GetIndex(); + node = m_msh->nod_vector[j]; // 23.01.2013. WW + const size_t n_id = node->GetIndex(); - if(out_coord) // 08.2012. WW - { - // XYZ - const double *x = node->getData(); // 23.01.2013. WW - - // Amplifying DISPLACEMENTs - if (deform_pcs) // 23.01.2012. WW. - { - for (size_t i = 0; i GetNodeValue(n_id, nidx_dm[i]) << " "; - for (size_t i = max_dim+1; i<3; i++) - tec_file << x[i] << " "; - } - else - { - for (size_t i = 0; i < 3; i++) - tec_file << x[i] << " "; - } - } + if (out_coord) // 08.2012. WW + { + // XYZ + const double* x = node->getData(); // 23.01.2013. WW + + // Amplifying DISPLACEMENTs + if (deform_pcs) // 23.01.2012. WW. + { + for (size_t i = 0; i < max_dim + 1; i++) + tec_file << x[i] + out_amplifier * m_pcs->GetNodeValue(n_id, nidx_dm[i]) << " "; + for (size_t i = max_dim + 1; i < 3; i++) + tec_file << x[i] << " "; + } + else + { + for (size_t i = 0; i < 3; i++) + tec_file << x[i] << " "; + } + } // NOD values // Mass transport // if(pcs_type_name.compare("MASS_TRANSPORT")==0){ @@ -1138,28 +1148,19 @@ void COutput::WriteTECNodeData(fstream &tec_file) { m_pcs = pcs_vector[l]; // if (m_pcs->pcs_type_name.compare("MASS_TRANSPORT") == 0) { - if (m_pcs->getProcessType () == FiniteElement::MASS_TRANSPORT) + if (m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) { timelevel = 0; - for (size_t m = 0; - m < m_pcs->nod_val_name_vector.size(); m++) - if (m_pcs->nod_val_name_vector[m].compare( - nod_value_name) == 0) + for (size_t m = 0; m < m_pcs->nod_val_name_vector.size(); m++) + if (m_pcs->nod_val_name_vector[m].compare(nod_value_name) == 0) { - m_pcs_out = PCSGet(FiniteElement::MASS_TRANSPORT, - nod_value_name); + m_pcs_out = PCSGet(FiniteElement::MASS_TRANSPORT, nod_value_name); if (!m_pcs_out) continue; if (timelevel == 1) { - nidx = - m_pcs_out-> - GetNodeValueIndex( - nod_value_name) - + - timelevel; - tec_file << - m_pcs_out->GetNodeValue(n_id, nidx) << " "; + nidx = m_pcs_out->GetNodeValueIndex(nod_value_name) + timelevel; + tec_file << m_pcs_out->GetNodeValue(n_id, nidx) << " "; } timelevel++; } @@ -1171,26 +1172,28 @@ void COutput::WriteTECNodeData(fstream &tec_file) for (size_t k = 0; k < nName; k++) { m_pcs = GetPCS(_nod_value_vector[k]); - if (m_pcs != NULL) { //WW + if (m_pcs != NULL) + { // WW - if (NodeIndex[k] > -1) { + if (NodeIndex[k] > -1) + { if (_nod_value_vector[k].find("DELTA") == 0) // JOD 2014-11-10 val_n = m_pcs->GetNodeValue(n_id, 1) - m_pcs->GetNodeValue(n_id, NodeIndex[k]); - else - val_n = m_pcs->GetNodeValue(n_id, NodeIndex[k]); //WW + else + val_n = m_pcs->GetNodeValue(n_id, NodeIndex[k]); // WW tec_file << val_n << " "; if ((m_pcs->type == 1212 || m_pcs->type == 42) - && _nod_value_vector[k].find("SATURATION") != string::npos) //WW + && _nod_value_vector[k].find("SATURATION") != string::npos) // WW tec_file << 1. - val_n << " "; - } } } - //OK4704 + // OK4704 for (size_t k = 0; k < mfp_value_vector.size(); k++) - //tec_file << MFPGetNodeValue(m_msh->nod_vector[j]->GetIndex(),mfp_value_vector[k]) << " "; //NB - tec_file << MFPGetNodeValue(n_id, - mfp_value_vector[k], atoi(&mfp_value_vector[k][mfp_value_vector[k].size() - 1]) - 1) << " "; //NB: MFP output for all phases + // tec_file << MFPGetNodeValue(m_msh->nod_vector[j]->GetIndex(),mfp_value_vector[k]) << " "; //NB + tec_file << MFPGetNodeValue(n_id, mfp_value_vector[k], + atoi(&mfp_value_vector[k][mfp_value_vector[k].size() - 1]) - 1) + << " "; // NB: MFP output for all phases } tec_file << "\n"; } @@ -1206,13 +1209,13 @@ void COutput::WriteTECNodeData(fstream &tec_file) 12/2005 OK GetMSH 07/2007 NW Multi Mesh Type **************************************************************************/ -void COutput::WriteTECElementData(fstream &tec_file,int e_type) +void COutput::WriteTECElementData(fstream& tec_file, int e_type) { for (size_t i = 0; i < m_msh->ele_vector.size(); i++) { if (!m_msh->ele_vector[i]->GetMark()) continue; - //NW + // NW if (m_msh->ele_vector[i]->GetElementType() == e_type) m_msh->ele_vector[i]->WriteIndex_TEC(tec_file); } @@ -1228,22 +1231,22 @@ void COutput::WriteTECElementData(fstream &tec_file,int e_type) 08/2005 WW Output by MSH 12/2005 OK GetMSH **************************************************************************/ -void COutput::WriteTECHeader(fstream &tec_file,int e_type, string e_type_name) +void COutput::WriteTECHeader(fstream& tec_file, int e_type, string e_type_name) { // MSH // m_msh = GetMSH(); - //OK411 + // OK411 size_t no_elements = 0; - const size_t mesh_ele_vector_size (m_msh->ele_vector.size()); + const size_t mesh_ele_vector_size(m_msh->ele_vector.size()); for (size_t i = 0; i < mesh_ele_vector_size; i++) if (m_msh->ele_vector[i]->GetMark()) if (m_msh->ele_vector[i]->GetElementType() == e_type) no_elements++; //-------------------------------------------------------------------- // Write Header I: variables - CRFProcess* pcs = NULL; //WW - const size_t nName (_nod_value_vector.size()); + CRFProcess* pcs = NULL; // WW + const size_t nName(_nod_value_vector.size()); tec_file << "VARIABLES = \"X\",\"Y\",\"Z\""; for (size_t k = 0; k < nName; k++) { @@ -1251,22 +1254,20 @@ void COutput::WriteTECHeader(fstream &tec_file,int e_type, string e_type_name) //-------------------------------------WW pcs = GetPCS(_nod_value_vector[k]); if (pcs != NULL) - if ((pcs->type == 1212 || - pcs->type == 42 ) && _nod_value_vector[k].find("SATURATION") - != string::npos) + if ((pcs->type == 1212 || pcs->type == 42) && _nod_value_vector[k].find("SATURATION") != string::npos) tec_file << ", SATURATION2"; //-------------------------------------WW } - const size_t mfp_value_vector_size (mfp_value_vector.size()); + const size_t mfp_value_vector_size(mfp_value_vector.size()); for (size_t k = 0; k < mfp_value_vector_size; k++) - //NB + // NB tec_file << ", \"" << mfp_value_vector[k] << "\""; // PCON - //MX - const size_t nPconName (_pcon_value_vector.size()); + // MX + const size_t nPconName(_pcon_value_vector.size()); for (size_t k = 0; k < nPconName; k++) - //MX + // MX tec_file << ", " << _pcon_value_vector[k] << ""; tec_file << "\n"; @@ -1274,30 +1275,34 @@ void COutput::WriteTECHeader(fstream &tec_file,int e_type, string e_type_name) // Write Header II: zone tec_file << "ZONE T=\""; tec_file << _time << "s\", "; - //OK411 + // OK411 tec_file << "N=" << m_msh->GetNodesNumber(false) << ", "; tec_file << "E=" << no_elements << ", "; - tec_file << "F=" << "FEPOINT" << ", "; + tec_file << "F=" + << "FEPOINT" + << ", "; tec_file << "ET=" << e_type_name; tec_file << "\n"; //-------------------------------------------------------------------- - // Write Header III: solution time ; BG 05/2011 - tec_file << "STRANDID=1, SOLUTIONTIME="; - tec_file << _time; // << "s\""; - tec_file << "\n"; - - //-------------------------------------------------------------------- - // Write Header IV: Variable sharing ; BG 05/2011 - if (this->VARIABLESHARING == true) - { - //int timestep = this->getNSteps; - //if (this-> - } + // Write Header III: solution time ; BG 05/2011 + tec_file << "STRANDID=1, SOLUTIONTIME="; + tec_file << _time; // << "s\""; + tec_file << "\n"; + + //-------------------------------------------------------------------- + // Write Header IV: Variable sharing ; BG 05/2011 + if (this->VARIABLESHARING == true) + { + // int timestep = this->getNSteps; + // if (this-> + } // - if(_new_file_opened && tecplot_zone_share) // 08.2012. WW + if (_new_file_opened && tecplot_zone_share) // 08.2012. WW { - tec_file <<"VARSHARELIST=([1-3]=1)"<<"\n"; - tec_file <<"CONNECTIVITYSHAREZONE=1"<<"\n"; + tec_file << "VARSHARELIST=([1-3]=1)" + << "\n"; + tec_file << "CONNECTIVITYSHAREZONE=1" + << "\n"; } } @@ -1311,48 +1316,48 @@ void COutput::WriteTECHeader(fstream &tec_file,int e_type, string e_type_name) void COutput::ELEWriteDOMDataTEC() { //---------------------------------------------------------------------- - if(_ele_value_vector.empty ()) + if (_ele_value_vector.empty()) return; //---------------------------------------------------------------------- // File handling //...................................................................... string tec_file_name = file_base_name + "_domain" + "_ele"; - if(getProcessType () != FiniteElement::INVALID_PROCESS) // PCS + if (getProcessType() != FiniteElement::INVALID_PROCESS) // PCS // 09/2010 TF msh_type_name; - tec_file_name += "_" + convertProcessTypeToString (getProcessType()); - if(msh_type_name.size() > 1) // MSH + tec_file_name += "_" + convertProcessTypeToString(getProcessType()); + if (msh_type_name.size() > 1) // MSH tec_file_name += "_" + msh_type_name; tec_file_name += TEC_FILE_EXTENSION; - //WW - if(!_new_file_opened) + // WW + if (!_new_file_opened) remove(tec_file_name.c_str()); //...................................................................... - fstream tec_file (tec_file_name.data(),ios::app | ios::out); - tec_file.setf(ios::scientific,ios::floatfield); + fstream tec_file(tec_file_name.data(), ios::app | ios::out); + tec_file.setf(ios::scientific, ios::floatfield); tec_file.precision(12); if (!tec_file.good()) return; - tec_file.seekg(0L,ios::beg); + tec_file.seekg(0L, ios::beg); #ifdef SUPERCOMPUTER // kg44 buffer the output - char mybuffer [MY_IO_BUFSIZE * MY_IO_BUFSIZE]; - tec_file.rdbuf()->pubsetbuf(mybuffer,MY_IO_BUFSIZE * MY_IO_BUFSIZE); - // + char mybuffer[MY_IO_BUFSIZE * MY_IO_BUFSIZE]; + tec_file.rdbuf()->pubsetbuf(mybuffer, MY_IO_BUFSIZE * MY_IO_BUFSIZE); +// #endif //-------------------------------------------------------------------- WriteELEValuesTECHeader(tec_file); WriteELEValuesTECData(tec_file); //-------------------------------------------------------------------- - tec_file.close(); // kg44 close file + tec_file.close(); // kg44 close file } -void COutput::WriteELEValuesTECHeader(fstream &tec_file) +void COutput::WriteELEValuesTECHeader(fstream& tec_file) { // Write Header I: variables tec_file << "VARIABLES = \"X\",\"Y\",\"Z\",\"VX\",\"VY\",\"VZ\""; for (size_t i = 0; i < _ele_value_vector.size(); i++) - //WW + // WW if (_ele_value_vector[i].find("VELOCITY") == string::npos) tec_file << "," << _ele_value_vector[i]; tec_file << "\n"; @@ -1360,8 +1365,9 @@ void COutput::WriteELEValuesTECHeader(fstream &tec_file) // Write Header II: zone tec_file << "ZONE T=\""; tec_file << _time << "s\", "; - tec_file << "I=" << (long) m_msh->ele_vector.size() << ", "; - tec_file << "F=POINT" << ", "; + tec_file << "I=" << (long)m_msh->ele_vector.size() << ", "; + tec_file << "F=POINT" + << ", "; tec_file << "C=BLACK"; tec_file << "\n"; } @@ -1374,35 +1380,35 @@ void COutput::WriteELEValuesTECHeader(fstream &tec_file) 11/2005 OK MSH 01/2006 OK **************************************************************************/ -void COutput::WriteELEValuesTECData(fstream &tec_file) +void COutput::WriteELEValuesTECData(fstream& tec_file) { CRFProcess* m_pcs_2 = NULL; if (_ele_value_vector.empty()) return; - vector skip; // CB + vector skip; // CB size_t no_ele_values = _ele_value_vector.size(); bool out_element_vel = false; bool out_element_transport_flux = false; // JOD 2014-11-10 - for (size_t j = 0; j < no_ele_values; j++) //WW - { - if (_ele_value_vector[j].find("VELOCITY") != string::npos) - { - out_element_vel = true; - //break; // CB: allow output of velocity AND other ele values - skip.push_back(false); + for (size_t j = 0; j < no_ele_values; j++) // WW + { + if (_ele_value_vector[j].find("VELOCITY") != string::npos) + { + out_element_vel = true; + // break; // CB: allow output of velocity AND other ele values + skip.push_back(false); } else if (_ele_value_vector[j].find("TRANSPORT_FLUX") != string::npos) // JOD 2014-11-10 { out_element_transport_flux = true; skip.push_back(false); } - else - { - m_pcs_2 = GetPCS_ELE(_ele_value_vector[j]); - skip.push_back(true); - } - } + else + { + m_pcs_2 = GetPCS_ELE(_ele_value_vector[j]); + skip.push_back(true); + } + } vector ele_value_index_vector(no_ele_values); GetELEValuesIndexVector(ele_value_index_vector); @@ -1413,24 +1419,15 @@ void COutput::WriteELEValuesTECData(fstream &tec_file) m_ele = m_msh->ele_vector[i]; double const* xyz(m_ele->GetGravityCenter()); tec_file << xyz[0] << " " << xyz[1] << " " << xyz[2] << " "; - if (out_element_vel) //WW + if (out_element_vel) // WW { if (PCSGet(FiniteElement::FLUID_MOMENTUM)) // PCH 16.11 2009 { CRFProcess* pch_pcs = PCSGet(FiniteElement::FLUID_MOMENTUM); - tec_file << pch_pcs->GetElementValue(i, - pch_pcs->GetElementValueIndex( - "VELOCITY1_X") + 1) - << " "; - tec_file << pch_pcs->GetElementValue(i, - pch_pcs->GetElementValueIndex( - "VELOCITY1_Y") + 1) - << " "; - tec_file << pch_pcs->GetElementValue(i, - pch_pcs->GetElementValueIndex( - "VELOCITY1_Z") + 1) - << " "; + tec_file << pch_pcs->GetElementValue(i, pch_pcs->GetElementValueIndex("VELOCITY1_X") + 1) << " "; + tec_file << pch_pcs->GetElementValue(i, pch_pcs->GetElementValueIndex("VELOCITY1_Y") + 1) << " "; + tec_file << pch_pcs->GetElementValue(i, pch_pcs->GetElementValueIndex("VELOCITY1_Z") + 1) << " "; } else { @@ -1449,15 +1446,13 @@ void COutput::WriteELEValuesTECData(fstream &tec_file) tec_file << gp_ele->TransportFlux(2, 0) << " "; #endif } - for (size_t j = 0; j < ele_value_index_vector.size(); j++) - { - if(skip[j]) // CB: allow output of velocity AND other ele values - { - tec_file - << m_pcs_2->GetElementValue(i, ele_value_index_vector[j]) - << " "; - } - } + for (size_t j = 0; j < ele_value_index_vector.size(); j++) + { + if (skip[j]) // CB: allow output of velocity AND other ele values + { + tec_file << m_pcs_2->GetElementValue(i, ele_value_index_vector[j]) << " "; + } + } /* int j; int eidx; @@ -1473,7 +1468,7 @@ void COutput::WriteELEValuesTECData(fstream &tec_file) } ele_value_index_vector.clear(); - skip.clear(); + skip.clear(); } /************************************************************************** @@ -1494,23 +1489,22 @@ void COutput::WriteELEValuesTECData(fstream &tec_file) **************************************************************************/ double COutput::NODWritePLYDataTEC(int number) { - //WW int nidx; + // WW int nidx; long gnode; bool bdummy = false; int stress_i[6], strain_i[6]; double ss[6]; - double val_n = 0.; //WW - //OK4704 + double val_n = 0.; // WW + // OK4704 if ((_nod_value_vector.size() == 0) && (mfp_value_vector.size() == 0)) return 0.0; // TF - GEOLIB::Polyline const* const ply ( - dynamic_cast(this->getGeoObj())); + GEOLIB::Polyline const* const ply(dynamic_cast(this->getGeoObj())); if (this->getGeoType() != GEOLIB::POLYLINE || ply == NULL) { - std::cerr << "COutput::NODWritePLYDataTEC geometric object is not a polyline" << - "\n"; + std::cerr << "COutput::NODWritePLYDataTEC geometric object is not a polyline" + << "\n"; return 0.0; } @@ -1519,8 +1513,7 @@ double COutput::NODWritePLYDataTEC(int number) const bool is_CSV = (dat_type_name.compare("CSV") == 0); // File handling - std::string tec_file_name = file_base_name + "_ply_" + geo_name + "_t" - + number2str (_id); //OK4709 + std::string tec_file_name = file_base_name + "_ply_" + geo_name + "_t" + number2str(_id); // OK4709 if (getProcessType() != FiniteElement::INVALID_PROCESS) tec_file_name += "_" + convertProcessTypeToString(getProcessType()); if (msh_type_name.size() > 0) @@ -1530,9 +1523,9 @@ double COutput::NODWritePLYDataTEC(int number) if (is_CSV) tec_file_name += CSV_FILE_EXTENSION; if (!_new_file_opened) - remove(tec_file_name.c_str()); //WW + remove(tec_file_name.c_str()); // WW - //WW + // WW fstream tec_file(tec_file_name.data(), ios::app | ios::out); tec_file.setf(ios::scientific, ios::floatfield); @@ -1542,34 +1535,35 @@ double COutput::NODWritePLYDataTEC(int number) tec_file.seekg(0L, ios::beg); #ifdef SUPERCOMPUTER // kg44 buffer the output - char mybuffer [MY_IO_BUFSIZE * MY_IO_BUFSIZE]; - tec_file.rdbuf()->pubsetbuf(mybuffer,MY_IO_BUFSIZE * MY_IO_BUFSIZE); - // + char mybuffer[MY_IO_BUFSIZE * MY_IO_BUFSIZE]; + tec_file.rdbuf()->pubsetbuf(mybuffer, MY_IO_BUFSIZE * MY_IO_BUFSIZE); +// #endif //---------------------------------------------------------------------- // Tests //...................................................................... // GEO -// CGLPolyline* m_ply = GEOGetPLYByName(geo_name);//CC -// if (!m_ply) -// { -// cout << "Warning in COutput::NODWritePLYDataTEC - no GEO data" << "\n"; -// tec_file << "Warning in COutput::NODWritePLYDataTEC - no GEO data: " -// << geo_name << "\n"; -// tec_file.close(); -// return 0.0; -// } + // CGLPolyline* m_ply = GEOGetPLYByName(geo_name);//CC + // if (!m_ply) + // { + // cout << "Warning in COutput::NODWritePLYDataTEC - no GEO data" << "\n"; + // tec_file << "Warning in COutput::NODWritePLYDataTEC - no GEO data: " + // << geo_name << "\n"; + // tec_file.close(); + // return 0.0; + // } // MSH // CFEMesh* m_msh = GetMSH(); // m_msh = GetMSH(); if (!m_msh) - cout << "Warning in COutput::NODWritePLYDataTEC - no MSH data" << "\n"; - //OKtec_file << "Warning in COutput::NODWritePLYDataTEC - no MSH data: " << geo_name << "\n"; - //OKtec_file.close(); - //OKToDo return; + cout << "Warning in COutput::NODWritePLYDataTEC - no MSH data" + << "\n"; + // OKtec_file << "Warning in COutput::NODWritePLYDataTEC - no MSH data: " << geo_name << "\n"; + // OKtec_file.close(); + // OKToDo return; else - m_msh->SwitchOnQuadraticNodes(false); //WW + m_msh->SwitchOnQuadraticNodes(false); // WW // PCS if (getProcessType() == FiniteElement::INVALID_PROCESS) @@ -1577,9 +1571,9 @@ double COutput::NODWritePLYDataTEC(int number) else m_pcs = PCSGet(getProcessType()); - CRFProcess* dm_pcs = NULL; //WW + CRFProcess* dm_pcs = NULL; // WW for (size_t i = 0; i < pcs_vector.size(); i++) - if (isDeformationProcess (pcs_vector[i]->getProcessType ())) + if (isDeformationProcess(pcs_vector[i]->getProcessType())) { dm_pcs = pcs_vector[i]; break; @@ -1605,31 +1599,32 @@ double COutput::NODWritePLYDataTEC(int number) } */ -// for (size_t i = 0; i < 3; i++) -// { -// if (v_eidx[i] < 0) -// { -// //WW cout << "Warning in COutput::NODWritePLYDataTEC() - no PCS flow data" << "\n"; -// //tec_file << "Warning in COutput::NODWritePLYDataTEC() - no PCS flow data " << "\n"; -// //tec_file.close(); -// } -// } + // for (size_t i = 0; i < 3; i++) + // { + // if (v_eidx[i] < 0) + // { + // //WW cout << "Warning in COutput::NODWritePLYDataTEC() - no PCS flow data" << "\n"; + // //tec_file << "Warning in COutput::NODWritePLYDataTEC() - no PCS flow data " << "\n"; + // //tec_file.close(); + // } + // } //-------------------------------------------------------------------- // NIDX for output variables - size_t no_variables (_nod_value_vector.size()); + size_t no_variables(_nod_value_vector.size()); std::vector NodeIndex(no_variables); GetNodeIndexVector(NodeIndex); //-------------------------------------------------------------------- // Write header - if (number == 0 || number == 1) //WW if(number==1) + if (number == 0 || number == 1) // WW if(number==1) { - if (is_TECPLOT) { - //project_title; + if (is_TECPLOT) + { + // project_title; std::string project_title_string = "Profiles along polylines"; if (dat_type_name.compare("GNUPLOT") != 0) // 5.3.07 JOD - tec_file << " TITLE = \"" << project_title_string - << "\"" << "\n"; + tec_file << " TITLE = \"" << project_title_string << "\"" + << "\n"; else tec_file << "# "; tec_file << " VARIABLES = "; @@ -1643,29 +1638,30 @@ double COutput::NODWritePLYDataTEC(int number) tec_file << "\"" << _nod_value_vector[k] << "\" "; //-------------------------------------WW m_pcs = GetPCS(_nod_value_vector[k]); - if (m_pcs && m_pcs->type == 1212 && _nod_value_vector[k].find( - "SATURATION") != string::npos) + if (m_pcs && m_pcs->type == 1212 && _nod_value_vector[k].find("SATURATION") != string::npos) tec_file << "SATURATION2 "; //-------------------------------------WW if (_nod_value_vector[k].compare("FLUX") == 0) - tec_file << "FLUX_INNER" << " "; + tec_file << "FLUX_INNER" + << " "; } //.................................................................... - //OK4709 + // OK4709 for (size_t k = 0; k < mfp_value_vector.size(); k++) tec_file << "\"" << mfp_value_vector[k] << "\" "; //.................................................................... // WW: M specific data - if (dm_pcs) //WW + if (dm_pcs) // WW - tec_file << " p_(1st_Invariant) " << " q_(2nd_Invariant) " + tec_file << " p_(1st_Invariant) " + << " q_(2nd_Invariant) " << " Effective_Strain"; tec_file << "\n"; } //.................................................................... // WW: M specific data size_t ns = 4; - if (dm_pcs) //WW + if (dm_pcs) // WW { stress_i[0] = dm_pcs->GetNodeValueIndex("STRESS_XX"); stress_i[1] = dm_pcs->GetNodeValueIndex("STRESS_YY"); @@ -1675,7 +1671,7 @@ double COutput::NODWritePLYDataTEC(int number) strain_i[1] = dm_pcs->GetNodeValueIndex("STRAIN_YY"); strain_i[2] = dm_pcs->GetNodeValueIndex("STRAIN_ZZ"); strain_i[3] = dm_pcs->GetNodeValueIndex("STRAIN_XY"); - if (max_dim == 2) // 3D + if (max_dim == 2) // 3D { ns = 6; stress_i[4] = dm_pcs->GetNodeValueIndex("STRESS_XZ"); @@ -1689,44 +1685,47 @@ double COutput::NODWritePLYDataTEC(int number) if (is_GNUPLOT) // 6/2012 JOD tec_file << "# "; if (is_TECPLOT || is_GNUPLOT) - tec_file << " ZONE T=\"TIME=" << _time << "\"" << "\n"; + tec_file << " ZONE T=\"TIME=" << _time << "\"" + << "\n"; - tec_file << " ZONE T=\"TIME=" << _time << "\"" << "\n"; + tec_file << " ZONE T=\"TIME=" << _time << "\"" + << "\n"; //---------------------------------------------------------------------- // Write data //====================================================================== - double flux_sum = 0.0; //OK + double flux_sum = 0.0; // OK double flux_nod; - m_msh->SwitchOnQuadraticNodes(false); //WW + m_msh->SwitchOnQuadraticNodes(false); // WW // NOD at PLY std::vector nodes_vector; CGLPolyline* m_ply = GEOGetPLYByName(geo_name); -// m_msh->GetNODOnPLY(m_ply, old_nodes_vector); // TF + // m_msh->GetNODOnPLY(m_ply, old_nodes_vector); // TF - double tmp_min_edge_length (m_msh->getMinEdgeLength()); - m_msh->setMinEdgeLength (m_ply->epsilon); + double tmp_min_edge_length(m_msh->getMinEdgeLength()); + m_msh->setMinEdgeLength(m_ply->epsilon); m_msh->GetNODOnPLY(ply, nodes_vector); // TF std::vector interpolation_points; - m_msh->getPointsForInterpolationAlongPolyline (ply, interpolation_points); + m_msh->getPointsForInterpolationAlongPolyline(ply, interpolation_points); m_msh->setMinEdgeLength(tmp_min_edge_length); -// std::cout << "size of nodes_vector: " << nodes_vector.size() << ", size of old_nodes_vector: " << old_nodes_vector.size() << "\n"; - //bool b_specified_pcs = (m_pcs != NULL); //NW m_pcs = PCSGet(pcs_type_name); + // std::cout << "size of nodes_vector: " << nodes_vector.size() << ", size of old_nodes_vector: " << + // old_nodes_vector.size() << "\n"; + // bool b_specified_pcs = (m_pcs != NULL); //NW m_pcs = PCSGet(pcs_type_name); for (size_t j(0); j < nodes_vector.size(); j++) { if (is_CSV) tec_file << aktuelle_zeit << " "; -// tec_file << m_ply->getSBuffer()[j] << " "; + // tec_file << m_ply->getSBuffer()[j] << " "; tec_file << interpolation_points[j] << " "; - //WW -// long old_gnode = nodes_vector[m_ply->getOrderedPoints()[j]]; + // WW + // long old_gnode = nodes_vector[m_ply->getOrderedPoints()[j]]; gnode = nodes_vector[j]; for (size_t k = 0; k < no_variables; k++) { - //if(!(_nod_value_vector[k].compare("FLUX")==0)) // removed JOD, does not work for multiple flow processes - //if (!b_specified_pcs) //NW + // if(!(_nod_value_vector[k].compare("FLUX")==0)) // removed JOD, does not work for multiple flow processes + // if (!b_specified_pcs) //NW if (msh_type_name != "COMPARTMENT") // JOD 4.10.01 m_pcs = PCSGet(_nod_value_vector[k], bdummy); @@ -1734,63 +1733,56 @@ double COutput::NODWritePLYDataTEC(int number) { cout << "Warning in COutput::NODWritePLYDataTEC - no PCS data" << "\n"; - tec_file - << "Warning in COutput::NODWritePLYDataTEC - no PCS data" - << "\n"; + tec_file << "Warning in COutput::NODWritePLYDataTEC - no PCS data" + << "\n"; return 0.0; } // WW -// double old_val_n = m_pcs->GetNodeValue(old_gnode, NodeIndex[k]); + // double old_val_n = m_pcs->GetNodeValue(old_gnode, NodeIndex[k]); if (_nod_value_vector[k].find("DELTA") == 0) // JOD 2014-11-10 val_n = m_pcs->GetNodeValue(gnode, 1) - m_pcs->GetNodeValue(gnode, NodeIndex[k]); else - val_n = m_pcs->GetNodeValue(gnode, NodeIndex[k]); -// tec_file << old_val_n << " "; + val_n = m_pcs->GetNodeValue(gnode, NodeIndex[k]); + // tec_file << old_val_n << " "; tec_file << val_n << " "; - if (m_pcs->type == 1212 && (_nod_value_vector[k].find("SATURATION") - != string::npos)) + if (m_pcs->type == 1212 && (_nod_value_vector[k].find("SATURATION") != string::npos)) tec_file << 1. - val_n << " "; if (_nod_value_vector[k].compare("FLUX") == 0) { - if (aktueller_zeitschritt == 0) //OK + if (aktueller_zeitschritt == 0) // OK flux_nod = 0.0; else flux_nod = NODFlux(gnode); tec_file << flux_nod << " "; - //flux_sum += abs(m_pcs->eqs->b[gnode]); + // flux_sum += abs(m_pcs->eqs->b[gnode]); flux_sum += abs(flux_nod); - //OK cout << gnode << " " << flux_nod << " " << flux_sum << "\n"; + // OK cout << gnode << " " << flux_nod << " " << flux_sum << "\n"; } } - if (dm_pcs) //WW + if (dm_pcs) // WW { for (size_t i = 0; i < ns; i++) ss[i] = dm_pcs->GetNodeValue(gnode, stress_i[i]); tec_file << -DeviatoricStress(ss) / 3.0 << " "; - tec_file << sqrt(3.0 * TensorMutiplication2(ss, ss, - m_msh->GetCoordinateFlag() / - 10) / 2.0) << " "; + tec_file << sqrt(3.0 * TensorMutiplication2(ss, ss, m_msh->GetCoordinateFlag() / 10) / 2.0) << " "; for (size_t i = 0; i < ns; i++) ss[i] = dm_pcs->GetNodeValue(gnode, strain_i[i]); DeviatoricStress(ss); - tec_file << sqrt(3.0 * TensorMutiplication2(ss, ss, - m_msh->GetCoordinateFlag() / - 10) / 2.0); + tec_file << sqrt(3.0 * TensorMutiplication2(ss, ss, m_msh->GetCoordinateFlag() / 10) / 2.0); } // MFP //OK4704 - //OK4704 + // OK4704 for (size_t k = 0; k < mfp_value_vector.size(); k++) // tec_file << MFPGetNodeValue(gnode,mfp_value_vector[k],0) << " "; //NB - tec_file << MFPGetNodeValue(gnode, mfp_value_vector[k], atoi( - &mfp_value_vector[k][mfp_value_vector[k - ].size() - 1]) - 1) - << " "; //NB: MFP output for all phases + tec_file << MFPGetNodeValue(gnode, mfp_value_vector[k], + atoi(&mfp_value_vector[k][mfp_value_vector[k].size() - 1]) - 1) + << " "; // NB: MFP output for all phases tec_file << "\n"; } - tec_file.close(); // kg44 close file + tec_file.close(); // kg44 close file return flux_sum; } @@ -1804,17 +1796,16 @@ double COutput::NODWritePLYDataTEC(int number) 12/2005 WW Output stress invariants 10/2010 TF changed access to process type **************************************************************************/ -void COutput::NODWritePNTDataTEC(double time_current,int time_step_number) +void COutput::NODWritePNTDataTEC(double time_current, int time_step_number) { - long msh_node_number(m_msh->GetNODOnPNT( - static_cast (getGeoObj()))); - if(msh_node_number < 0) //11.06.2012. WW - return; + long msh_node_number(m_msh->GetNODOnPNT(static_cast(getGeoObj()))); + if (msh_node_number < 0) // 11.06.2012. WW + return; CRFProcess* dm_pcs = NULL; for (size_t i = 0; i < pcs_vector.size(); i++) // if (pcs_vector[i]->pcs_type_name.find("DEFORMATION") != string::npos) { TF - if (isDeformationProcess (pcs_vector[i]->getProcessType())) + if (isDeformationProcess(pcs_vector[i]->getProcessType())) { dm_pcs = pcs_vector[i]; break; @@ -1832,7 +1823,7 @@ void COutput::NODWritePNTDataTEC(double time_current,int time_step_number) else if (is_CSV) addInfoToFileName(tec_file_name, true, true, true, CSV_FILE_EXTENSION); if (!_new_file_opened) - remove(tec_file_name.c_str()); //WW + remove(tec_file_name.c_str()); // WW //...................................................................... fstream tec_file(tec_file_name.data(), ios::app | ios::out); @@ -1843,9 +1834,9 @@ void COutput::NODWritePNTDataTEC(double time_current,int time_step_number) tec_file.seekg(0L, ios::beg); #ifdef SUPERCOMPUTER // kg44 buffer the output - char mybuffer [MY_IO_BUFSIZE * MY_IO_BUFSIZE]; - tec_file.rdbuf()->pubsetbuf(mybuffer,MY_IO_BUFSIZE * MY_IO_BUFSIZE); - // + char mybuffer[MY_IO_BUFSIZE * MY_IO_BUFSIZE]; + tec_file.rdbuf()->pubsetbuf(mybuffer, MY_IO_BUFSIZE * MY_IO_BUFSIZE); +// #endif //-------------------------------------------------------------------- // Tests @@ -1869,12 +1860,16 @@ void COutput::NODWritePNTDataTEC(double time_current,int time_step_number) GetNodeIndexVector(NodeIndex); //-------------------------------------------------------------------- // Write header - if (time_step_number == 0) //WW Old: if(time_step_number==1) + if (time_step_number == 0) // WW Old: if(time_step_number==1) { - if (is_TECPLOT) { - const std::string project_title_string ("Time curves in points"); - tec_file << " TITLE = \"" << project_title_string << "\"" << "\n"; - } else if (is_GNUPLOT) { + if (is_TECPLOT) + { + const std::string project_title_string("Time curves in points"); + tec_file << " TITLE = \"" << project_title_string << "\"" + << "\n"; + } + else if (is_GNUPLOT) + { tec_file << "# "; } @@ -1885,46 +1880,47 @@ void COutput::NODWritePNTDataTEC(double time_current,int time_step_number) // if(pcs_type_name.compare("RANDOM_WALK")==0) if (getProcessType() == FiniteElement::RANDOM_WALK) tec_file << "leavingParticles "; - for (size_t k = 0; k < no_variables; k++) //WW + for (size_t k = 0; k < no_variables; k++) // WW { tec_file << " \"" << _nod_value_vector[k] << "\" "; //-------------------------------------WW m_pcs = GetPCS(_nod_value_vector[k]); - if (m_pcs && m_pcs->type == 1212 && _nod_value_vector[k].find( - "SATURATION") != string::npos) + if (m_pcs && m_pcs->type == 1212 && _nod_value_vector[k].find("SATURATION") != string::npos) tec_file << "SATURATION2 "; //-------------------------------------WW } - //OK411 + // OK411 for (size_t k = 0; k < mfp_value_vector.size(); k++) - //NB MFP data names for multiple phases + // NB MFP data names for multiple phases tec_file << " \"" << mfp_value_vector[k] << "\" "; - // +// #ifdef RFW_FRACTURE - for(i = 0; i < (int)mmp_vector.size(); ++i) - if( mmp_vector[i]->frac_num > 0) - for(int j = 0; j < mmp_vector[i]->frac_num; ++j) - tec_file << mmp_vector[i]->frac_names[j] << "_k " << - mmp_vector[i]->frac_names[j] << "_aper " + for (i = 0; i < (int)mmp_vector.size(); ++i) + if (mmp_vector[i]->frac_num > 0) + for (int j = 0; j < mmp_vector[i]->frac_num; ++j) + tec_file << mmp_vector[i]->frac_names[j] << "_k " << mmp_vector[i]->frac_names[j] << "_aper " << mmp_vector[i]->frac_names[j] << "_closed "; #endif - if (dm_pcs) //WW - tec_file << " p_(1st_Invariant) " << " q_(2nd_Invariant) " + if (dm_pcs) // WW + tec_file << " p_(1st_Invariant) " + << " q_(2nd_Invariant) " << " Effective_Strain"; tec_file << "\n"; if (is_GNUPLOT) // 5.3.07 JOD - tec_file << "# "; // comment - if (is_TECPLOT) { + tec_file << "# "; // comment + if (is_TECPLOT) + { if (geo_name.find("POINT") == std::string::npos) tec_file << " ZONE T=\"POINT=" - //, I=" << anz_zeitschritte << ", J=1, K=1, F=POINT" << "\n"; - << getGeoTypeAsString() << geo_name << "\"" << "\n"; + //, I=" << anz_zeitschritte << ", J=1, K=1, F=POINT" << "\n"; + << getGeoTypeAsString() << geo_name << "\"" + << "\n"; else tec_file << " ZONE T=\"POINT=" << geo_name << "\"" - << "\n"; //, I=" << anz_zeitschritte << ", J=1, K=1, F=POINT" << "\n"; + << "\n"; //, I=" << anz_zeitschritte << ", J=1, K=1, F=POINT" << "\n"; } } @@ -1932,7 +1928,7 @@ void COutput::NODWritePNTDataTEC(double time_current,int time_step_number) size_t ns = 4; int stress_i[6], strain_i[6]; double ss[6]; - if (dm_pcs) //WW + if (dm_pcs) // WW { stress_i[0] = dm_pcs->GetNodeValueIndex("STRESS_XX"); stress_i[1] = dm_pcs->GetNodeValueIndex("STRESS_YY"); @@ -1966,7 +1962,7 @@ void COutput::NODWritePNTDataTEC(double time_current,int time_step_number) if (pcs_vector[0] == NULL) return; - //11.06.2012. WW// long msh_node_number(m_msh->GetNODOnPNT( + // 11.06.2012. WW// long msh_node_number(m_msh->GetNODOnPNT( // static_cast (getGeoObj()))); // Mass transport @@ -1981,25 +1977,15 @@ void COutput::NODWritePNTDataTEC(double time_current,int time_step_number) if (m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) { timelevel = 0; - for (size_t m = 0; m < m_pcs->nod_val_name_vector.size(); - m++) - if (m_pcs->nod_val_name_vector[m].compare( - nod_value_name) == 0) + for (size_t m = 0; m < m_pcs->nod_val_name_vector.size(); m++) + if (m_pcs->nod_val_name_vector[m].compare(nod_value_name) == 0) { // m_pcs_out = PCSGet(pcs_type_name, nod_value_name); - m_pcs_out - = PCSGet(FiniteElement::MASS_TRANSPORT, - nod_value_name); + m_pcs_out = PCSGet(FiniteElement::MASS_TRANSPORT, nod_value_name); if (timelevel == 1) { - int nidx = - m_pcs_out-> - GetNodeValueIndex( - nod_value_name) + - timelevel; - tec_file << m_pcs_out->GetNodeValue( - msh_node_number, - nidx) << " "; + int nidx = m_pcs_out->GetNodeValueIndex(nod_value_name) + timelevel; + tec_file << m_pcs_out->GetNodeValue(msh_node_number, nidx) << " "; } timelevel++; } @@ -2013,7 +1999,8 @@ void COutput::NODWritePNTDataTEC(double time_current,int time_step_number) { // PCS if (!(_nod_value_vector[i].compare("FLUX") == 0) - || getProcessType() == FiniteElement::OVERLAND_FLOW) //JOD separate infiltration flux output in overland flow + || getProcessType() + == FiniteElement::OVERLAND_FLOW) // JOD separate infiltration flux output in overland flow m_pcs = GetPCS(_nod_value_vector[i]); else @@ -2022,27 +2009,27 @@ void COutput::NODWritePNTDataTEC(double time_current,int time_step_number) { cout << "Warning in COutput::NODWritePLYDataTEC - no PCS data" << "\n"; - tec_file - << "Warning in COutput::NODWritePLYDataTEC - no PCS data" - << "\n"; + tec_file << "Warning in COutput::NODWritePLYDataTEC - no PCS data" + << "\n"; return; } //.................................................................. // PCS if (!(_nod_value_vector[i].compare("FLUX") == 0) - || getProcessType() == FiniteElement::OVERLAND_FLOW) // JOD separate infiltration flux output in overland flow + || getProcessType() + == FiniteElement::OVERLAND_FLOW) // JOD separate infiltration flux output in overland flow { //-----------------------------------------WW double val_n; - if (_nod_value_vector[i].find("DELTA") == 0) //JOD 2014-11-10 - val_n = m_pcs->GetNodeValue(msh_node_number, 1) - m_pcs->GetNodeValue(msh_node_number, NodeIndex[i]); + if (_nod_value_vector[i].find("DELTA") == 0) // JOD 2014-11-10 + val_n + = m_pcs->GetNodeValue(msh_node_number, 1) - m_pcs->GetNodeValue(msh_node_number, NodeIndex[i]); else - val_n = m_pcs->GetNodeValue(msh_node_number, NodeIndex[i]); + val_n = m_pcs->GetNodeValue(msh_node_number, NodeIndex[i]); tec_file << val_n << " "; m_pcs = GetPCS(_nod_value_vector[i]); - if (m_pcs->type == 1212 && (_nod_value_vector[i].find( - "SATURATION") != string::npos)) + if (m_pcs->type == 1212 && (_nod_value_vector[i].find("SATURATION") != string::npos)) tec_file << 1. - val_n << " "; //-----------------------------------------WW } @@ -2050,50 +2037,44 @@ void COutput::NODWritePNTDataTEC(double time_current,int time_step_number) { flux_nod = NODFlux(msh_node_number); tec_file << flux_nod << " "; - //flux_sum += abs(m_pcs->eqs->b[gnode]); + // flux_sum += abs(m_pcs->eqs->b[gnode]); flux_sum += abs(flux_nod); - //OK cout << gnode << " " << flux_nod << " " << flux_sum << "\n"; + // OK cout << gnode << " " << flux_nod << " " << flux_sum << "\n"; } } - //.................................................................... +//.................................................................... #ifdef RFW_FRACTURE - for(i = 0; i < (int)mmp_vector.size(); ++i) - if( mmp_vector[i]->frac_num > 0) - for(int j = 0; j < mmp_vector[i]->frac_num; ++j) - tec_file << mmp_vector[i]->frac_perm[j] << " " << - mmp_vector[i]->avg_aperture[j] << " " + for (i = 0; i < (int)mmp_vector.size(); ++i) + if (mmp_vector[i]->frac_num > 0) + for (int j = 0; j < mmp_vector[i]->frac_num; ++j) + tec_file << mmp_vector[i]->frac_perm[j] << " " << mmp_vector[i]->avg_aperture[j] << " " << mmp_vector[i]->closed_fraction[j] << " "; #endif //.................................................................... - if (dm_pcs) //WW + if (dm_pcs) // WW { for (size_t i = 0; i < ns; i++) ss[i] = dm_pcs->GetNodeValue(msh_node_number, stress_i[i]); tec_file << -DeviatoricStress(ss) / 3.0 << " "; - tec_file << sqrt(3.0 * TensorMutiplication2(ss, ss, - m_msh->GetCoordinateFlag() / - 10) / 2.0) << " "; + tec_file << sqrt(3.0 * TensorMutiplication2(ss, ss, m_msh->GetCoordinateFlag() / 10) / 2.0) << " "; for (size_t i = 0; i < ns; i++) ss[i] = dm_pcs->GetNodeValue(msh_node_number, strain_i[i]); DeviatoricStress(ss); - tec_file << sqrt(3.0 * TensorMutiplication2(ss, ss, - m_msh->GetCoordinateFlag() / - 10) / 2.0); + tec_file << sqrt(3.0 * TensorMutiplication2(ss, ss, m_msh->GetCoordinateFlag() / 10) / 2.0); } - //OK411 + // OK411 for (size_t k = 0; k < mfp_value_vector.size(); k++) tec_file << MFPGetNodeValue(msh_node_number, mfp_value_vector[k], - atoi(&mfp_value_vector[k][mfp_value_vector[k]. - size() - 1]) - - 1) << " "; //NB + atoi(&mfp_value_vector[k][mfp_value_vector[k].size() - 1]) - 1) + << " "; // NB } tec_file << "\n"; //---------------------------------------------------------------------- - tec_file.close(); // kg44 close file + tec_file.close(); // kg44 close file } -void COutput::WriteRFOHeader(fstream &rfo_file) +void COutput::WriteRFOHeader(fstream& rfo_file) { //#0#0#0#1#0.00000000000000e+000#0#3915########################################### rfo_file << "#0#0#0#1#"; @@ -2104,52 +2085,50 @@ void COutput::WriteRFOHeader(fstream &rfo_file) rfo_file << "\n"; } -void COutput::WriteRFONodes(fstream &rfo_file) +void COutput::WriteRFONodes(fstream& rfo_file) { - //0 101 100 - rfo_file << 0 << " " << m_msh->nod_vector.size() << " " - << m_msh->ele_vector.size() << "\n"; - //0 0.00000000000000 0.00000000000000 0.00000000000000 + // 0 101 100 + rfo_file << 0 << " " << m_msh->nod_vector.size() << " " << m_msh->ele_vector.size() << "\n"; + // 0 0.00000000000000 0.00000000000000 0.00000000000000 for (size_t i = 0; i < m_msh->nod_vector.size(); i++) { - double const* const pnt_i (m_msh->nod_vector[i]->getData()); - rfo_file << i << " " << pnt_i[0] << " " << pnt_i[1] << " " - << pnt_i[2] << " " << "\n"; + double const* const pnt_i(m_msh->nod_vector[i]->getData()); + rfo_file << i << " " << pnt_i[0] << " " << pnt_i[1] << " " << pnt_i[2] << " " + << "\n"; } } -void COutput::WriteRFOElements(fstream &rfo_file) +void COutput::WriteRFOElements(fstream& rfo_file) { size_t j; MeshLib::CElem* m_ele = NULL; - //0 0 -1 line 0 1 - for(long i = 0; i < (long)m_msh->ele_vector.size(); i++) + // 0 0 -1 line 0 1 + for (long i = 0; i < (long)m_msh->ele_vector.size(); i++) { m_ele = m_msh->ele_vector[i]; - rfo_file << i << " " << m_ele->GetPatchIndex() \ - << " -1 " \ - << m_ele->GetName() << " "; - for(j = 0; j < m_ele->GetNodesNumber(false); j++) + rfo_file << i << " " << m_ele->GetPatchIndex() << " -1 " << m_ele->GetName() << " "; + for (j = 0; j < m_ele->GetNodesNumber(false); j++) rfo_file << m_ele->getNodeIndices()[j] << " "; rfo_file << "\n"; } } -void COutput::WriteRFOValues(fstream &rfo_file) +void COutput::WriteRFOValues(fstream& rfo_file) { - int p,nidx; + int p, nidx; CRFProcess* m_pcs = NULL; - //1 2 4 - rfo_file << "1 1 4" << "\n"; - //2 1 1 + // 1 2 4 + rfo_file << "1 1 4" + << "\n"; + // 2 1 1 int no_processes = (int)pcs_vector.size(); rfo_file << no_processes; - for(p = 0; p < no_processes; p++) + for (p = 0; p < no_processes; p++) rfo_file << " 1"; rfo_file << "\n"; - //PRESSURE1, Pa + // PRESSURE1, Pa // Names and units - for(p = 0; p < no_processes; p++) + for (p = 0; p < no_processes; p++) { m_pcs = pcs_vector[p]; rfo_file << m_pcs->pcs_primary_function_name[0]; @@ -2157,48 +2136,50 @@ void COutput::WriteRFOValues(fstream &rfo_file) rfo_file << m_pcs->pcs_primary_function_unit[0]; rfo_file << "\n"; } - //0 0.00000000000000 0.00000000000000 + // 0 0.00000000000000 0.00000000000000 // Node values - for(long i = 0; i < (long)m_msh->nod_vector.size(); i++) + for (long i = 0; i < (long)m_msh->nod_vector.size(); i++) { rfo_file << i; - for(p = 0; p < no_processes; p++) + for (p = 0; p < no_processes; p++) { m_pcs = pcs_vector[p]; nidx = m_pcs->GetNodeValueIndex(m_pcs->pcs_primary_function_name[0]) + 1; - rfo_file << " " << m_pcs->GetNodeValue(i,nidx); + rfo_file << " " << m_pcs->GetNodeValue(i, nidx); } - rfo_file << " " << "\n"; + rfo_file << " " + << "\n"; } } void COutput::WriteRFO() { - m_msh = FEMGet(convertProcessTypeToString (getProcessType())); - if(!m_msh) + m_msh = FEMGet(convertProcessTypeToString(getProcessType())); + if (!m_msh) { - cout << "Warning in COutput::WriteRFONodes - no MSH data" << "\n"; + cout << "Warning in COutput::WriteRFONodes - no MSH data" + << "\n"; return; } //-------------------------------------------------------------------- // File handling string rfo_file_name; rfo_file_name = file_base_name + "." + "rfo"; - //WW - if(!_new_file_opened) + // WW + if (!_new_file_opened) remove(rfo_file_name.c_str()); - fstream rfo_file (rfo_file_name.data(),ios::app | ios::out); + fstream rfo_file(rfo_file_name.data(), ios::app | ios::out); - rfo_file.setf(ios::scientific,ios::floatfield); + rfo_file.setf(ios::scientific, ios::floatfield); rfo_file.precision(12); if (!rfo_file.good()) return; - rfo_file.seekg(0L,ios::beg); + rfo_file.seekg(0L, ios::beg); #ifdef SUPERCOMPUTER // kg44 buffer the output - char mybuffer [MY_IO_BUFSIZE * MY_IO_BUFSIZE]; - rfo_file.rdbuf()->pubsetbuf(mybuffer,MY_IO_BUFSIZE * MY_IO_BUFSIZE); - // + char mybuffer[MY_IO_BUFSIZE * MY_IO_BUFSIZE]; + rfo_file.rdbuf()->pubsetbuf(mybuffer, MY_IO_BUFSIZE * MY_IO_BUFSIZE); +// #endif //-------------------------------------------------------------------- WriteRFOHeader(rfo_file); @@ -2206,7 +2187,7 @@ void COutput::WriteRFO() WriteRFOElements(rfo_file); WriteRFOValues(rfo_file); // RFOWriteELEValues(); - rfo_file.close(); // kg44 close file + rfo_file.close(); // kg44 close file } void COutput::NODWriteSFCDataTEC(int number) @@ -2223,15 +2204,13 @@ void COutput::NODWriteSFCDataTEC(int number) string number_string = number_char; // string tec_file_name = pcs_type_name + "_sfc_" + geo_name + "_t" // + number_string + TEC_FILE_EXTENSION; - //std::string tec_file_name = convertProcessTypeToString (getProcessType()) + "_sfc_" + geo_name + "_t" - // + number_string + TEC_FILE_EXTENSION; - // AB SB Use Model name for output file name - // std::string tec_file_name = convertProcessTypeToString (getProcessType()) - std::string tec_file_name = file_base_name - + "_sfc_" + geo_name + "_t" - + number_string + TEC_FILE_EXTENSION; + // std::string tec_file_name = convertProcessTypeToString (getProcessType()) + "_sfc_" + geo_name + "_t" + // + number_string + TEC_FILE_EXTENSION; + // AB SB Use Model name for output file name + // std::string tec_file_name = convertProcessTypeToString (getProcessType()) + std::string tec_file_name = file_base_name + "_sfc_" + geo_name + "_t" + number_string + TEC_FILE_EXTENSION; if (!_new_file_opened) - remove(tec_file_name.c_str()); //WW + remove(tec_file_name.c_str()); // WW fstream tec_file(tec_file_name.data(), ios::app | ios::out); tec_file.setf(ios::scientific, ios::floatfield); tec_file.precision(12); @@ -2240,13 +2219,13 @@ void COutput::NODWriteSFCDataTEC(int number) tec_file.seekg(0L, ios::beg); #ifdef SUPERCOMPUTER // kg44 buffer the output - char mybuffer [MY_IO_BUFSIZE * MY_IO_BUFSIZE]; - tec_file.rdbuf()->pubsetbuf(mybuffer,MY_IO_BUFSIZE * MY_IO_BUFSIZE); - // + char mybuffer[MY_IO_BUFSIZE * MY_IO_BUFSIZE]; + tec_file.rdbuf()->pubsetbuf(mybuffer, MY_IO_BUFSIZE * MY_IO_BUFSIZE); +// #endif //-------------------------------------------------------------------- // Write header - //project_title; + // project_title; string project_title_string = "Profile at surface"; tec_file << " TITLE = \"" << project_title_string << "\"" << "\n"; @@ -2255,39 +2234,41 @@ void COutput::NODWriteSFCDataTEC(int number) tec_file << _nod_value_vector[k] << ","; tec_file << "\n"; // , I=" << NodeListLength << ", J=1, K=1, F=POINT" << "\n"; - tec_file << " ZONE T=\"TIME=" << _time << "\"" << "\n"; + tec_file << " ZONE T=\"TIME=" << _time << "\"" + << "\n"; //-------------------------------------------------------------------- // Write data std::vector nodes_vector; Surface* m_sfc = NULL; - m_sfc = GEOGetSFCByName(geo_name); //CC + m_sfc = GEOGetSFCByName(geo_name); // CC if (m_sfc) { m_msh->GetNODOnSFC(m_sfc, nodes_vector); - //for (size_t i = 0; i < m_msh->nod_vector.size(); i++) - for (size_t i = 0; i < nodes_vector.size(); i++) // AB SB + // for (size_t i = 0; i < m_msh->nod_vector.size(); i++) + for (size_t i = 0; i < nodes_vector.size(); i++) // AB SB { - double const* const pnt_i (m_msh->nod_vector[nodes_vector[i]]->getData()); + double const* const pnt_i(m_msh->nod_vector[nodes_vector[i]]->getData()); tec_file << pnt_i[0] << " "; tec_file << pnt_i[1] << " "; tec_file << pnt_i[2] << " "; for (size_t k = 0; k < _nod_value_vector.size(); k++) { - m_pcs = PCSGet(_nod_value_vector[k], true); // AB SB + m_pcs = PCSGet(_nod_value_vector[k], true); // AB SB int nidx = m_pcs->GetNodeValueIndex(_nod_value_vector[k]) + 1; if (_nod_value_vector[k].find("DELTA") == 0) // JOD 2014-11-10 - tec_file << m_pcs->GetNodeValue(nodes_vector[i], 1) - m_pcs->GetNodeValue(nodes_vector[i], nidx - 1) << " "; + tec_file << m_pcs->GetNodeValue(nodes_vector[i], 1) - m_pcs->GetNodeValue(nodes_vector[i], nidx - 1) + << " "; else - tec_file << m_pcs->GetNodeValue(nodes_vector[i], nidx) << " "; + tec_file << m_pcs->GetNodeValue(nodes_vector[i], nidx) << " "; } tec_file << "\n"; } } else - tec_file << "Error in NODWritePLYDataTEC: polyline " << geo_name - << " not found" << "\n"; - tec_file.close(); // kg44 close file + tec_file << "Error in NODWritePLYDataTEC: polyline " << geo_name << " not found" + << "\n"; + tec_file.close(); // kg44 close file } /************************************************************************** @@ -2296,7 +2277,7 @@ void COutput::NODWriteSFCDataTEC(int number) 04/2006 CMCD no mesh option & flux weighting last modification: **************************************************************************/ -void COutput::NODWriteSFCAverageDataTEC(double time_current,int time_step_number) +void COutput::NODWriteSFCAverageDataTEC(double time_current, int time_step_number) { bool no_pcs = false; double dtemp; @@ -2305,7 +2286,7 @@ void COutput::NODWriteSFCAverageDataTEC(double time_current,int time_step_number int idx = -1; double t_flux = 0.0; double node_conc = 0.0; - CRFProcess* m_pcs_gw (PCSGet(FiniteElement::GROUNDWATER_FLOW)); + CRFProcess* m_pcs_gw(PCSGet(FiniteElement::GROUNDWATER_FLOW)); if (!m_pcs_gw) PCSGet(FiniteElement::LIQUID_FLOW); //-------------------------------------------------------------------- @@ -2329,14 +2310,13 @@ void COutput::NODWriteSFCAverageDataTEC(double time_current,int time_step_number CRFProcess* m_pcs(PCSGet(getProcessType())); if (!m_pcs) no_pcs = true; - //cout << "Warning in COutput::NODWriteSFCAverageDataTEC - no PCS data" << "\n"; - //return; + // cout << "Warning in COutput::NODWriteSFCAverageDataTEC - no PCS data" << "\n"; + // return; //-------------------------------------------------------------------- // File handling - string tec_file_name = file_base_name + "_TBC_" + getGeoTypeAsString() - + "_" + geo_name + TEC_FILE_EXTENSION; + string tec_file_name = file_base_name + "_TBC_" + getGeoTypeAsString() + "_" + geo_name + TEC_FILE_EXTENSION; if (!_new_file_opened) - remove(tec_file_name.c_str()); //WW + remove(tec_file_name.c_str()); // WW fstream tec_file(tec_file_name.data(), ios::app | ios::out); tec_file.setf(ios::scientific, ios::floatfield); tec_file.precision(12); @@ -2345,24 +2325,25 @@ void COutput::NODWriteSFCAverageDataTEC(double time_current,int time_step_number tec_file.seekg(0L, ios::beg); #ifdef SUPERCOMPUTER // kg44 buffer the output - char mybuffer [MY_IO_BUFSIZE * MY_IO_BUFSIZE]; - tec_file.rdbuf()->pubsetbuf(mybuffer,MY_IO_BUFSIZE * MY_IO_BUFSIZE); - // + char mybuffer[MY_IO_BUFSIZE * MY_IO_BUFSIZE]; + tec_file.rdbuf()->pubsetbuf(mybuffer, MY_IO_BUFSIZE * MY_IO_BUFSIZE); +// #endif //-------------------------------------------------------------------- // Write header - if (time_step_number == 0) // WW Old: if(time_step_number==1) + if (time_step_number == 0) // WW Old: if(time_step_number==1) { - //project_title; + // project_title; string project_title_string = "Time curve at surface"; - tec_file << " TITLE = \"" << project_title_string - << "\"" << "\n"; + tec_file << " TITLE = \"" << project_title_string << "\"" + << "\n"; tec_file << " VARIABLES = Time "; for (size_t i = 0; i < _nod_value_vector.size(); i++) tec_file << _nod_value_vector[i] << " "; tec_file << "\n"; //, I=" << anz_zeitschritte << ", J=1, K=1, F=POINT" << "\n"; - tec_file << " ZONE T=\"SFC=" << geo_name << "\"" << "\n"; + tec_file << " ZONE T=\"SFC=" << geo_name << "\"" + << "\n"; } //-------------------------------------------------------------------- // node_value_index_vector @@ -2372,12 +2353,10 @@ void COutput::NODWriteSFCAverageDataTEC(double time_current,int time_step_number if (m_pcs) for (size_t i = 0; i < _nod_value_vector.size(); i++) { - node_value_index_vector[i] = m_pcs->GetNodeValueIndex( - _nod_value_vector[i]) + 1; + node_value_index_vector[i] = m_pcs->GetNodeValueIndex(_nod_value_vector[i]) + 1; // itemp = node_value_index_vector[i]; for (size_t n_pv = 0; n_pv < m_pcs->GetPrimaryVNumber(); n_pv++) - if (_nod_value_vector[i].compare( - m_pcs->pcs_primary_function_name[n_pv]) == 0) + if (_nod_value_vector[i].compare(m_pcs->pcs_primary_function_name[n_pv]) == 0) { node_value_index_vector[i]++; break; @@ -2390,20 +2369,17 @@ void COutput::NODWriteSFCAverageDataTEC(double time_current,int time_step_number tec_file << time_current << " "; for (size_t i = 0; i < _nod_value_vector.size(); i++) { - //Specified currently for MASS_TRANSPORT only. + // Specified currently for MASS_TRANSPORT only. m_pcs = PCSGet(FiniteElement::MASS_TRANSPORT, _nod_value_vector[i]); - node_value_index_vector[i] = m_pcs->GetNodeValueIndex( - _nod_value_vector[i]) + 1; + node_value_index_vector[i] = m_pcs->GetNodeValueIndex(_nod_value_vector[i]) + 1; m_pcs->m_msh->GetNODOnSFC(m_sfc, sfc_nodes_vector); dtemp = 0.0; t_flux = 0.0; for (size_t j = 0; j < sfc_nodes_vector.size(); j++) { idx = m_pcs_gw->GetNodeValueIndex("FLUX"); - node_flux = abs( - m_pcs_gw->GetNodeValue(sfc_nodes_vector[j], idx)); - node_conc = m_pcs->GetNodeValue(sfc_nodes_vector[j], - node_value_index_vector[i]); + node_flux = abs(m_pcs_gw->GetNodeValue(sfc_nodes_vector[j], idx)); + node_conc = m_pcs->GetNodeValue(sfc_nodes_vector[j], node_value_index_vector[i]); dtemp += (node_flux * node_conc); t_flux += node_flux; } @@ -2424,10 +2400,8 @@ void COutput::NODWriteSFCAverageDataTEC(double time_current,int time_step_number dtemp = 0.0; for (size_t j = 0; j < sfc_nodes_vector.size(); j++) { - node_flux = abs( - m_pcs_gw->GetNodeValue(sfc_nodes_vector[j], idx)); - node_conc = m_pcs->GetNodeValue(sfc_nodes_vector[j], - node_value_index_vector[i]); + node_flux = abs(m_pcs_gw->GetNodeValue(sfc_nodes_vector[j], idx)); + node_conc = m_pcs->GetNodeValue(sfc_nodes_vector[j], node_value_index_vector[i]); dtemp += (node_flux * node_conc); t_flux += node_flux; } @@ -2436,10 +2410,10 @@ void COutput::NODWriteSFCAverageDataTEC(double time_current,int time_step_number } tec_file << "\n"; } - tec_file.close(); // kg44 close file + tec_file.close(); // kg44 close file } -void COutput::GetNodeIndexVector(vector&NodeIndex) +void COutput::GetNodeIndexVector(vector& NodeIndex) { CRFProcess* pcs = NULL; const size_t nName = _nod_value_vector.size(); @@ -2448,16 +2422,14 @@ void COutput::GetNodeIndexVector(vector&NodeIndex) pcs = PCSGet(getProcessType()); for (size_t k = 0; k < nName; k++) { - if (getProcessType () == FiniteElement::MASS_TRANSPORT) + if (getProcessType() == FiniteElement::MASS_TRANSPORT) pcs = PCSGet(getProcessType(), _nod_value_vector[k]); if (!pcs) { - cout - << "Warning in COutput::GetNodeIndexVector - no PCS data: " - << _nod_value_vector[k] << "\n"; + cout << "Warning in COutput::GetNodeIndexVector - no PCS data: " << _nod_value_vector[k] << "\n"; return; } - NodeIndex[k] = pcs->GetNodeValueIndex(_nod_value_vector[k],true); // JT latest + NodeIndex[k] = pcs->GetNodeValueIndex(_nod_value_vector[k], true); // JT latest } } else if (msh_type_name.size() > 0) @@ -2471,7 +2443,7 @@ void COutput::GetNodeIndexVector(vector&NodeIndex) } for (size_t k = 0; k < nName; k++) { - NodeIndex[k] = pcs->GetNodeValueIndex(_nod_value_vector[k],true); // JT latest + NodeIndex[k] = pcs->GetNodeValueIndex(_nod_value_vector[k], true); // JT latest } } else if (fem_msh_vector.size() == 1) @@ -2482,32 +2454,30 @@ void COutput::GetNodeIndexVector(vector&NodeIndex) pcs = PCSGet(_nod_value_vector[k], bdummy); if (!pcs) { - cout - << "Warning in COutput::GetNodeIndexVector - no PCS data: " - << _nod_value_vector[k] << "\n"; + cout << "Warning in COutput::GetNodeIndexVector - no PCS data: " << _nod_value_vector[k] << "\n"; return; } - NodeIndex[k] = pcs->GetNodeValueIndex(_nod_value_vector[k],true); // JT latest + NodeIndex[k] = pcs->GetNodeValueIndex(_nod_value_vector[k], true); // JT latest } } } -CRFProcess* COutput::GetPCS(const string &var_name) +CRFProcess* COutput::GetPCS(const string& var_name) { CRFProcess* m_pcs = NULL; - if(getProcessType () != FiniteElement::INVALID_PROCESS) + if (getProcessType() != FiniteElement::INVALID_PROCESS) m_pcs = PCSGet(getProcessType()); - else if(msh_type_name.size() > 0) + else if (msh_type_name.size() > 0) m_pcs = PCSGet(msh_type_name); - if(!m_pcs) - m_pcs = PCSGet(var_name,true); + if (!m_pcs) + m_pcs = PCSGet(var_name, true); return m_pcs; } // 09/2010 TF CRFProcess* COutput::GetPCS() { - if(getProcessType () != FiniteElement::INVALID_PROCESS) + if (getProcessType() != FiniteElement::INVALID_PROCESS) { if (getProcess() != NULL) return getProcess(); @@ -2516,8 +2486,8 @@ CRFProcess* COutput::GetPCS() } else { - CRFProcess* pcs (NULL); - if(msh_type_name.size() > 0) + CRFProcess* pcs(NULL); + if (msh_type_name.size() > 0) pcs = PCSGet(msh_type_name); // if(!pcs) // pcs = PCSGet(var_name,true); @@ -2525,7 +2495,7 @@ CRFProcess* COutput::GetPCS() } } -CRFProcess* COutput::GetPCS_ELE(const string &var_name) +CRFProcess* COutput::GetPCS_ELE(const string& var_name) { string pcs_var_name; CRFProcess* m_pcs = NULL; @@ -2551,19 +2521,20 @@ CRFProcess* COutput::GetPCS_ELE(const string &var_name) return m_pcs; } -void COutput::GetELEValuesIndexVector(vector&ele_value_index_vector) +void COutput::GetELEValuesIndexVector(vector& ele_value_index_vector) { if (_ele_value_vector[0].size() == 0) return; - CRFProcess * m_pcs = NULL; + CRFProcess* m_pcs = NULL; - // CB THMBM - //m_pcs = GetPCS_ELE(_ele_value_vector[0]); // CB this is buggy: not all ele vals are defined with the same (or any) process - for (size_t i = 0; i < _ele_value_vector.size(); i++) - { - m_pcs = GetPCS_ELE(_ele_value_vector[i]); // CB - ele_value_index_vector[i] = m_pcs->GetElementValueIndex(_ele_value_vector[i]); - } + // CB THMBM + // m_pcs = GetPCS_ELE(_ele_value_vector[0]); // CB this is buggy: not all ele vals are defined with the same (or + // any) process + for (size_t i = 0; i < _ele_value_vector.size(); i++) + { + m_pcs = GetPCS_ELE(_ele_value_vector[i]); // CB + ele_value_index_vector[i] = m_pcs->GetElementValueIndex(_ele_value_vector[i]); + } } /************************************************************************** @@ -2587,14 +2558,16 @@ void COutput::SetNODFluxAtPLY() // CFEMesh* msh = GetMSH(); if (!m_msh) { - cout << "Warning in COutput::SetNODFluxAtPLY() - no MSH data" << "\n"; + cout << "Warning in COutput::SetNODFluxAtPLY() - no MSH data" + << "\n"; return; } CRFProcess* pcs = GetPCS("FLUX"); if (!pcs) { - cout << "Warning in COutput::SetNODFluxAtPLY() - no PCS data" << "\n"; + cout << "Warning in COutput::SetNODFluxAtPLY() - no PCS data" + << "\n"; return; } @@ -2607,7 +2580,7 @@ void COutput::SetNODFluxAtPLY() for (size_t i = 0; i < nodes_vector.size(); i++) node_value_vector[i] = pcs->GetNodeValue(nodes_vector[i], nidx); //---------------------------------------------------------------------- - //m_st->FaceIntegration(m_pcs,nodes_vector,node_value_vector); + // m_st->FaceIntegration(m_pcs,nodes_vector,node_value_vector); } void COutput::ELEWriteSFC_TEC() @@ -2627,7 +2600,7 @@ void COutput::ELEWriteSFC_TEC() // tec_file_name += TEC_FILE_EXTENSION; if (!_new_file_opened) - remove(tec_file_name.c_str()); //WW + remove(tec_file_name.c_str()); // WW //...................................................................... fstream tec_file(tec_file_name.data(), ios::app | ios::out); tec_file.setf(ios::scientific, ios::floatfield); @@ -2637,9 +2610,9 @@ void COutput::ELEWriteSFC_TEC() tec_file.seekg(0L, ios::beg); #ifdef SUPERCOMPUTER // kg44 buffer the output - char mybuffer [MY_IO_BUFSIZE * MY_IO_BUFSIZE]; - tec_file.rdbuf()->pubsetbuf(mybuffer,MY_IO_BUFSIZE * MY_IO_BUFSIZE); - // + char mybuffer[MY_IO_BUFSIZE * MY_IO_BUFSIZE]; + tec_file.rdbuf()->pubsetbuf(mybuffer, MY_IO_BUFSIZE * MY_IO_BUFSIZE); +// #endif //-------------------------------------------------------------------- vector tmp_ele_sfc_vector; @@ -2648,10 +2621,10 @@ void COutput::ELEWriteSFC_TEC() ELEWriteSFC_TECHeader(tec_file); ELEWriteSFC_TECData(tec_file); //-------------------------------------------------------------------- - tec_file.close(); // kg44 close file + tec_file.close(); // kg44 close file } -void COutput::ELEWriteSFC_TECHeader(fstream &tec_file) +void COutput::ELEWriteSFC_TECHeader(fstream& tec_file) { // Write Header I: variables tec_file << "VARIABLES = \"X\",\"Y\",\"Z\""; @@ -2662,15 +2635,17 @@ void COutput::ELEWriteSFC_TECHeader(fstream &tec_file) // Write Header II: zone tec_file << "ZONE T=\""; tec_file << _time << "s\", "; - tec_file << "I=" << (long) m_msh->ele_vector.size() << ", "; - tec_file << "F=POINT" << ", "; + tec_file << "I=" << (long)m_msh->ele_vector.size() << ", "; + tec_file << "F=POINT" + << ", "; tec_file << "C=BLACK"; tec_file << "\n"; } -void COutput::ELEWriteSFC_TECData(fstream &tec_file) +void COutput::ELEWriteSFC_TECData(fstream& tec_file) { - tec_file << "COutput::ELEWriteSFC_TECData - implementation not finished" << "\n"; + tec_file << "COutput::ELEWriteSFC_TECData - implementation not finished" + << "\n"; /* // Make it as comment to avoid compilation warnings. 18.082011 WW long i; @@ -2724,103 +2699,104 @@ void COutput::CalcELEFluxes() { double Test[5]; - const FiniteElement::ProcessType pcs_type (getProcessType()); - if (pcs_type == FiniteElement::INVALID_PROCESS) // WW moved it here. + const FiniteElement::ProcessType pcs_type(getProcessType()); + if (pcs_type == FiniteElement::INVALID_PROCESS) // WW moved it here. - //WW cout << "Warning in COutput::CalcELEFluxes(): no PCS data" << "\n"; + // WW cout << "Warning in COutput::CalcELEFluxes(): no PCS data" << "\n"; return; CRFProcess* pcs = PCSGet(getProcessType()); - //BG 04/2011: MASS_TRANSPORT added to get MASS FLUX for Polylines - //cout << pcs->Tim->step_current << "\n"; - if (isDeformationProcess(pcs_type) || (!isFlowProcess (pcs_type) && (pcs_type != FiniteElement::MASS_TRANSPORT)) - //if (isDeformationProcess(pcs_type) || !isFlowProcess (pcs_type) - //WW + // BG 04/2011: MASS_TRANSPORT added to get MASS FLUX for Polylines + // cout << pcs->Tim->step_current << "\n"; + if (isDeformationProcess(pcs_type) || (!isFlowProcess(pcs_type) && (pcs_type != FiniteElement::MASS_TRANSPORT)) + // if (isDeformationProcess(pcs_type) || !isFlowProcess (pcs_type) + // WW || pcs->m_msh->geo_name.find("REGIONAL") != string::npos) return; //---------------------------------------------------------------------- switch (getGeoType()) { - case GEOLIB::POLYLINE: - { - // CGLPolyline* ply = GEOGetPLYByName(geo_name); - // if (!ply) - // std::cout << "Warning in COutput::CalcELEFluxes - no GEO data" << "\n"; - - //BG 04/2011: ELEWritePLY_TEC does not work for MASS_TRANSPORT because there is no flux considered - if (pcs_type != FiniteElement::MASS_TRANSPORT) + case GEOLIB::POLYLINE: { - double f_n_sum = 0.0; - double *PhaseFlux(new double [2]); - std::string Header[2]; - int dimension = 2; - Header[0] = "q_Phase1"; - Header[1] = "q_Phase2"; - - pcs->CalcELEFluxes(static_cast (getGeoObj()), PhaseFlux); - if ((pcs_type == FiniteElement::GROUNDWATER_FLOW) || (pcs_type == FiniteElement::FLUID_FLOW)) + // CGLPolyline* ply = GEOGetPLYByName(geo_name); + // if (!ply) + // std::cout << "Warning in COutput::CalcELEFluxes - no GEO data" << "\n"; + + // BG 04/2011: ELEWritePLY_TEC does not work for MASS_TRANSPORT because there is no flux considered + if (pcs_type != FiniteElement::MASS_TRANSPORT) { - ELEWritePLY_TEC(); - f_n_sum = PhaseFlux[0]; - TIMValue_TEC(f_n_sum); + double f_n_sum = 0.0; + double* PhaseFlux(new double[2]); + std::string Header[2]; + int dimension = 2; + Header[0] = "q_Phase1"; + Header[1] = "q_Phase2"; + + pcs->CalcELEFluxes(static_cast(getGeoObj()), PhaseFlux); + if ((pcs_type == FiniteElement::GROUNDWATER_FLOW) || (pcs_type == FiniteElement::FLUID_FLOW)) + { + ELEWritePLY_TEC(); + f_n_sum = PhaseFlux[0]; + TIMValue_TEC(f_n_sum); + } + if (pcs_type == FiniteElement::MULTI_PHASE_FLOW) + { + Test[0] = PhaseFlux[0]; + Test[1] = PhaseFlux[1]; + TIMValues_TEC(Test, Header, dimension); + } + delete[] PhaseFlux; } - if (pcs_type == FiniteElement::MULTI_PHASE_FLOW) + // BG, Output for Massflux added + else { - Test[0] = PhaseFlux[0]; - Test[1] = PhaseFlux[1]; + double* MassFlux(new double[5]); + std::string Header[5]; + int dimension = 5; + Header[0] = "AdvectiveMassFlux"; + Header[1] = "DispersiveMassFlux"; + Header[2] = "DiffusiveMassFlux"; + Header[3] = "TotalMassFlux"; + Header[4] = "TotalMass_sum"; + + pcs->CalcELEMassFluxes(static_cast(getGeoObj()), geo_name, MassFlux); + Test[0] = MassFlux[0]; + Test[1] = MassFlux[1]; + Test[2] = MassFlux[2]; + Test[3] = MassFlux[3]; + Test[4] = MassFlux[4]; TIMValues_TEC(Test, Header, dimension); + delete[] MassFlux; } - delete [] PhaseFlux; + + // double f_n_sum = 0.0; + // f_n_sum = pcs->CalcELEFluxes(ply); // TF + // f_n_sum = pcs->CalcELEFluxes(static_cast (getGeoObj())); + + // ELEWritePLY_TEC(); + // BUGFIX_4402_OK_1 + // TIMValue_TEC(f_n_sum); + break; } - // BG, Output for Massflux added - else + case GEOLIB::SURFACE: { - double *MassFlux (new double[5]); - std::string Header[5]; - int dimension = 5; - Header[0] = "AdvectiveMassFlux"; - Header[1] = "DispersiveMassFlux"; - Header[2] = "DiffusiveMassFlux"; - Header[3] = "TotalMassFlux"; - Header[4] = "TotalMass_sum"; - - pcs->CalcELEMassFluxes(static_cast (getGeoObj()), geo_name, MassFlux); - Test[0] = MassFlux[0]; - Test[1] = MassFlux[1]; - Test[2] = MassFlux[2]; - Test[3] = MassFlux[3]; - Test[4] = MassFlux[4]; - TIMValues_TEC(Test, Header, dimension); - delete [] MassFlux; + // Surface* m_sfc = GEOGetSFCByName(geo_name); + // pcs->CalcELEFluxes(m_sfc); + break; } - - //double f_n_sum = 0.0; - // f_n_sum = pcs->CalcELEFluxes(ply); // TF - //f_n_sum = pcs->CalcELEFluxes(static_cast (getGeoObj())); - - //ELEWritePLY_TEC(); - //BUGFIX_4402_OK_1 - //TIMValue_TEC(f_n_sum); - break; - } - case GEOLIB::SURFACE: - { - // Surface* m_sfc = GEOGetSFCByName(geo_name); - // pcs->CalcELEFluxes(m_sfc); - break; - } - case GEOLIB::VOLUME: - { - // CGLVolume* m_vol = GEOGetVOL(geo_name); - // pcs->CalcELEFluxes(m_vol); - break; - } - case GEOLIB::GEODOMAIN: //domAin - //pcs->CalcELEFluxes(m_dom); - break; - default: - cout << "Warning in COutput::CalcELEFluxes(): no GEO type data" << "\n"; + case GEOLIB::VOLUME: + { + // CGLVolume* m_vol = GEOGetVOL(geo_name); + // pcs->CalcELEFluxes(m_vol); + break; + } + case GEOLIB::GEODOMAIN: // domAin + // pcs->CalcELEFluxes(m_dom); + break; + default: + cout << "Warning in COutput::CalcELEFluxes(): no GEO type data" + << "\n"; } // WW pcs->CalcELEFluxes(ply) changed 'mark' of elements @@ -2832,7 +2808,7 @@ void COutput::CalcELEFluxes() void COutput::ELEWritePLY_TEC() { //---------------------------------------------------------------------- - if(_ele_value_vector.size() == 0) + if (_ele_value_vector.size() == 0) return; //---------------------------------------------------------------------- // File handling @@ -2843,39 +2819,39 @@ void COutput::ELEWritePLY_TEC() tec_file_name += "_ELE"; // if(pcs_type_name.size()>1) // PCS // tec_file_name += "_" + pcs_type_name; - if(getProcessType () != FiniteElement::INVALID_PROCESS) // PCS - tec_file_name += "_" + convertProcessTypeToString (getProcessType ()); + if (getProcessType() != FiniteElement::INVALID_PROCESS) // PCS + tec_file_name += "_" + convertProcessTypeToString(getProcessType()); - if(msh_type_name.size() > 1) // MSH + if (msh_type_name.size() > 1) // MSH tec_file_name += "_" + msh_type_name; tec_file_name += TEC_FILE_EXTENSION; - if(!_new_file_opened) - remove(tec_file_name.c_str()); //WW + if (!_new_file_opened) + remove(tec_file_name.c_str()); // WW //...................................................................... - fstream tec_file(tec_file_name.data(),ios::app | ios::out); - tec_file.setf(ios::scientific,ios::floatfield); + fstream tec_file(tec_file_name.data(), ios::app | ios::out); + tec_file.setf(ios::scientific, ios::floatfield); tec_file.precision(12); if (!tec_file.good()) return; - tec_file.seekg(0L,ios::beg); + tec_file.seekg(0L, ios::beg); #ifdef SUPERCOMPUTER // kg44 buffer the output - char mybuffer [MY_IO_BUFSIZE * MY_IO_BUFSIZE]; - tec_file.rdbuf()->pubsetbuf(mybuffer,MY_IO_BUFSIZE * MY_IO_BUFSIZE); - // + char mybuffer[MY_IO_BUFSIZE * MY_IO_BUFSIZE]; + tec_file.rdbuf()->pubsetbuf(mybuffer, MY_IO_BUFSIZE * MY_IO_BUFSIZE); +// #endif //-------------------------------------------------------------------- - vectortmp_ele_ply_vector; + vector tmp_ele_ply_vector; tmp_ele_ply_vector.clear(); //-------------------------------------------------------------------- ELEWritePLY_TECHeader(tec_file); ELEWritePLY_TECData(tec_file); //-------------------------------------------------------------------- - tec_file.close(); // kg44 close file + tec_file.close(); // kg44 close file } -void COutput::ELEWritePLY_TECHeader(fstream &tec_file) +void COutput::ELEWritePLY_TECHeader(fstream& tec_file) { // Write Header I: variables tec_file << "VARIABLES = \"X\",\"Y\",\"Z\""; @@ -2895,7 +2871,7 @@ void COutput::ELEWritePLY_TECHeader(fstream &tec_file) 07/2010 TF substituted GEOGetPLYByName 10/2010 TF changed access to process type **************************************************************************/ -void COutput::ELEWritePLY_TECData(fstream &tec_file) +void COutput::ELEWritePLY_TECData(fstream& tec_file) { // CRFProcess* pcs = PCSGet(pcs_type_name); CRFProcess* pcs = PCSGet(getProcessType()); @@ -2903,11 +2879,12 @@ void COutput::ELEWritePLY_TECData(fstream &tec_file) CRFProcess* m_pcs_flow = NULL; // if (pcs->pcs_type_name.find("FLOW") != string::npos) { - if (isFlowProcess(pcs->getProcessType ())) + if (isFlowProcess(pcs->getProcessType())) m_pcs_flow = pcs; - else { + else + { m_pcs_flow = PCSGet(FiniteElement::GROUNDWATER_FLOW); - if( m_pcs_flow == NULL) + if (m_pcs_flow == NULL) m_pcs_flow = PCSGet(FiniteElement::LIQUID_FLOW); } v_eidx[0] = m_pcs_flow->GetElementValueIndex("VELOCITY1_X"); @@ -2916,8 +2893,7 @@ void COutput::ELEWritePLY_TECData(fstream &tec_file) for (size_t i = 0; i < 3; i++) if (v_eidx[i] < 0) { - cout << - "Fatal error in CRFProcess::CalcELEFluxes(CGLPolyline*m_ply) - abort"; + cout << "Fatal error in CRFProcess::CalcELEFluxes(CGLPolyline*m_ply) - abort"; abort(); } @@ -2927,12 +2903,12 @@ void COutput::ELEWritePLY_TECData(fstream &tec_file) // vector ele_vector_at_geo; // m_msh->GetELEOnPLY(m_ply, ele_vector_at_geo); std::vector ele_vector_at_geo; - m_msh->GetELEOnPLY(static_cast (getGeoObj()), ele_vector_at_geo, false); + m_msh->GetELEOnPLY(static_cast(getGeoObj()), ele_vector_at_geo, false); // helper variables Math_Group::vec ele_edges_vector(15); Math_Group::vec edge_nodes(3); - double edge_mid_vector[3] = {0.0,0.0,0.0}; + double edge_mid_vector[3] = {0.0, 0.0, 0.0}; for (size_t i = 0; i < ele_vector_at_geo.size(); i++) { @@ -2952,18 +2928,14 @@ void COutput::ELEWritePLY_TECData(fstream &tec_file) edge_mid_vector[2] = 0.5 * (pnt1[2] + pnt0[2]); } } - tec_file << edge_mid_vector[0] << " " << edge_mid_vector[1] << " " - << edge_mid_vector[2]; + tec_file << edge_mid_vector[0] << " " << edge_mid_vector[1] << " " << edge_mid_vector[2]; // ele vector values - tec_file << " " << m_pcs_flow->GetElementValue(m_ele->GetIndex(), - v_eidx[0]); - tec_file << " " << m_pcs_flow->GetElementValue(m_ele->GetIndex(), - v_eidx[1]); - tec_file << " " << m_pcs_flow->GetElementValue(m_ele->GetIndex(), - v_eidx[2]); - //tec_file << " " << pcs->GetElementValue(m_ele->GetIndex(), f_eidx[0]); - //tec_file << " " << pcs->GetElementValue(m_ele->GetIndex(), f_eidx[1]); - //tec_file << " " << pcs->GetElementValue(m_ele->GetIndex(), f_eidx[2]); + tec_file << " " << m_pcs_flow->GetElementValue(m_ele->GetIndex(), v_eidx[0]); + tec_file << " " << m_pcs_flow->GetElementValue(m_ele->GetIndex(), v_eidx[1]); + tec_file << " " << m_pcs_flow->GetElementValue(m_ele->GetIndex(), v_eidx[2]); + // tec_file << " " << pcs->GetElementValue(m_ele->GetIndex(), f_eidx[0]); + // tec_file << " " << pcs->GetElementValue(m_ele->GetIndex(), f_eidx[1]); + // tec_file << " " << pcs->GetElementValue(m_ele->GetIndex(), f_eidx[2]); tec_file << "\n"; } } @@ -2980,33 +2952,33 @@ void COutput::TIMValue_TEC(double tim_value) tec_file_name += "_TIM"; // if(pcs_type_name.size()>1) // PCS // tec_file_name += "_" + pcs_type_name; - if(getProcessType () != FiniteElement::INVALID_PROCESS) // PCS - tec_file_name += "_" + convertProcessTypeToString (getProcessType()); - if(msh_type_name.size() > 1) // MSH + if (getProcessType() != FiniteElement::INVALID_PROCESS) // PCS + tec_file_name += "_" + convertProcessTypeToString(getProcessType()); + if (msh_type_name.size() > 1) // MSH tec_file_name += "_" + msh_type_name; tec_file_name += TEC_FILE_EXTENSION; - if(!_new_file_opened) - remove(tec_file_name.c_str()); //WW + if (!_new_file_opened) + remove(tec_file_name.c_str()); // WW //...................................................................... - if(aktueller_zeitschritt==0) //BG:04/2011 deletes the content of the file at the start of the simulation - tec_file.open(tec_file_name.data(),ios::trunc|ios::out); - else - tec_file.open(tec_file_name.data(),ios::app | ios::out); + if (aktueller_zeitschritt == 0) // BG:04/2011 deletes the content of the file at the start of the simulation + tec_file.open(tec_file_name.data(), ios::trunc | ios::out); + else + tec_file.open(tec_file_name.data(), ios::app | ios::out); - tec_file.setf(ios::scientific,ios::floatfield); + tec_file.setf(ios::scientific, ios::floatfield); tec_file.precision(12); if (!tec_file.good()) return; - tec_file.seekg(0L,ios::beg); + tec_file.seekg(0L, ios::beg); #ifdef SUPERCOMPUTER // kg44 buffer the output - char mybuffer [MY_IO_BUFSIZE * MY_IO_BUFSIZE]; - tec_file.rdbuf()->pubsetbuf(mybuffer,MY_IO_BUFSIZE * MY_IO_BUFSIZE); - // + char mybuffer[MY_IO_BUFSIZE * MY_IO_BUFSIZE]; + tec_file.rdbuf()->pubsetbuf(mybuffer, MY_IO_BUFSIZE * MY_IO_BUFSIZE); +// #endif //-------------------------------------------------------------------- // Write Header I: variables - if(aktueller_zeitschritt==0) //BG:04/2011 bevor it was timestep 1 + if (aktueller_zeitschritt == 0) // BG:04/2011 bevor it was timestep 1 { tec_file << "VARIABLES = \"Time\",\"Value\""; tec_file << "\n"; @@ -3019,7 +2991,7 @@ void COutput::TIMValue_TEC(double tim_value) //-------------------------------------------------------------------- tec_file << aktuelle_zeit << " " << tim_value << "\n"; //-------------------------------------------------------------------- - tec_file.close(); // kg44 close file + tec_file.close(); // kg44 close file } /*------------------------------------------------------------------------- @@ -3029,83 +3001,83 @@ void COutput::TIMValue_TEC(double tim_value) Programming: 10/2011 BG Modification: -------------------------------------------------------------------------*/ -void COutput::TIMValues_TEC(double tim_value[5], std::string *header, int dimension) +void COutput::TIMValues_TEC(double tim_value[5], std::string* header, int dimension) { double j[10]; - for (int i = 0; i < dimension; i++) + for (int i = 0; i < dimension; i++) j[i] = tim_value[i]; - //---------------------------------------------------------------------- - // File handling - //...................................................................... - fstream tec_file; - string tec_file_name = file_base_name; // + "_ply" + "_ele"; - tec_file_name += "_" + getGeoTypeAsString(); - tec_file_name += "_" + geo_name; - tec_file_name += "_TIM"; - // if(pcs_type_name.size()>1) // PCS - // tec_file_name += "_" + pcs_type_name; - if(getProcessType () != FiniteElement::INVALID_PROCESS) // PCS - tec_file_name += "_" + convertProcessTypeToString (getProcessType()); - if(msh_type_name.size()>1) // MSH - tec_file_name += "_" + msh_type_name; - tec_file_name += TEC_FILE_EXTENSION; - - if(!_new_file_opened) - remove(tec_file_name.c_str()); //WW - //...................................................................... - if(aktueller_zeitschritt==0) //BG:04/2011 deletes the content of the file at the start of the simulation - tec_file.open(tec_file_name.data(),ios::trunc|ios::out); - else - tec_file.open(tec_file_name.data(),ios::app|ios::out); - tec_file.setf(ios::scientific,ios::floatfield); - tec_file.precision(12); - if (!tec_file.good()) return; - tec_file.seekg(0L,ios::beg); + //---------------------------------------------------------------------- + // File handling + //...................................................................... + fstream tec_file; + string tec_file_name = file_base_name; // + "_ply" + "_ele"; + tec_file_name += "_" + getGeoTypeAsString(); + tec_file_name += "_" + geo_name; + tec_file_name += "_TIM"; + // if(pcs_type_name.size()>1) // PCS + // tec_file_name += "_" + pcs_type_name; + if (getProcessType() != FiniteElement::INVALID_PROCESS) // PCS + tec_file_name += "_" + convertProcessTypeToString(getProcessType()); + if (msh_type_name.size() > 1) // MSH + tec_file_name += "_" + msh_type_name; + tec_file_name += TEC_FILE_EXTENSION; + + if (!_new_file_opened) + remove(tec_file_name.c_str()); // WW + //...................................................................... + if (aktueller_zeitschritt == 0) // BG:04/2011 deletes the content of the file at the start of the simulation + tec_file.open(tec_file_name.data(), ios::trunc | ios::out); + else + tec_file.open(tec_file_name.data(), ios::app | ios::out); + tec_file.setf(ios::scientific, ios::floatfield); + tec_file.precision(12); + if (!tec_file.good()) + return; + tec_file.seekg(0L, ios::beg); #ifdef SUPERCOMPUTER - // kg44 buffer the output - char mybuffer [MY_IO_BUFSIZE*MY_IO_BUFSIZE]; - tec_file.rdbuf()->pubsetbuf(mybuffer,MY_IO_BUFSIZE*MY_IO_BUFSIZE); - // + // kg44 buffer the output + char mybuffer[MY_IO_BUFSIZE * MY_IO_BUFSIZE]; + tec_file.rdbuf()->pubsetbuf(mybuffer, MY_IO_BUFSIZE * MY_IO_BUFSIZE); +// #endif - //-------------------------------------------------------------------- - // Write Header I: variables - if(aktueller_zeitschritt==0) //BG:04/2011 bevor it was timestep 1 - { - tec_file << "VARIABLES = \"Time\""; - for (int i = 0; i < dimension; i++) - tec_file << ",\"" << header[i] << "\""; - tec_file << "\n"; - //-------------------------------------------------------------------- - // Write Header II: zone - tec_file << "ZONE T="; - tec_file << geo_name; - tec_file << "\n"; - } - //-------------------------------------------------------------------- - tec_file << aktuelle_zeit; - for (int i = 0; i < dimension; i++) - tec_file << " " << j[i]; - tec_file << "\n"; - //-------------------------------------------------------------------- - tec_file.close(); // kg44 close file - + //-------------------------------------------------------------------- + // Write Header I: variables + if (aktueller_zeitschritt == 0) // BG:04/2011 bevor it was timestep 1 + { + tec_file << "VARIABLES = \"Time\""; + for (int i = 0; i < dimension; i++) + tec_file << ",\"" << header[i] << "\""; + tec_file << "\n"; + //-------------------------------------------------------------------- + // Write Header II: zone + tec_file << "ZONE T="; + tec_file << geo_name; + tec_file << "\n"; + } + //-------------------------------------------------------------------- + tec_file << aktuelle_zeit; + for (int i = 0; i < dimension; i++) + tec_file << " " << j[i]; + tec_file << "\n"; + //-------------------------------------------------------------------- + tec_file.close(); // kg44 close file } double COutput::NODFlux(long nod_number) { - nod_number = nod_number; //OK411 - /* - cout << gnode << " " \ - << m_pcs->GetNodeValue(gnode,NodeIndex[k]) << end - flux_sum += m_pcs->GetNodeValue(gnode,NodeIndex[k]); - */ - // All elements at node //OK -#if defined (USE_PETSC) // || defined (other parallel solver lib). 04.2012 WW + nod_number = nod_number; // OK411 +/* + cout << gnode << " " \ + << m_pcs->GetNodeValue(gnode,NodeIndex[k]) << end + flux_sum += m_pcs->GetNodeValue(gnode,NodeIndex[k]); + */ +// All elements at node //OK +#if defined(USE_PETSC) // || defined (other parallel solver lib). 04.2012 WW return 0; -#elif defined(NEW_EQS) //WW. 07.11.2008 - return 0.; //To do: m_pcs->eqs_new->b[nod_number]; +#elif defined(NEW_EQS) // WW. 07.11.2008 + return 0.; // To do: m_pcs->eqs_new->b[nod_number]; #else // Element nodal RHS contributions m_pcs->getEQSPointer()->b[nod_number] = 0.0; @@ -3118,7 +3090,7 @@ double COutput::NODFlux(long nod_number) void COutput::NODWriteLAYDataTEC(int time_step_number) { // Tests - const size_t nName (_nod_value_vector.size()); + const size_t nName(_nod_value_vector.size()); if (nName == 0) return; std::vector NodeIndex(nName); @@ -3155,9 +3127,9 @@ void COutput::NODWriteLAYDataTEC(int time_step_number) #ifdef SUPERCOMPUTER // // kg44 buffer the output - char mybuffer [MY_IO_BUFSIZE * MY_IO_BUFSIZE]; - tec_file.rdbuf()->pubsetbuf(mybuffer,MY_IO_BUFSIZE * MY_IO_BUFSIZE); - // + char mybuffer[MY_IO_BUFSIZE * MY_IO_BUFSIZE]; + tec_file.rdbuf()->pubsetbuf(mybuffer, MY_IO_BUFSIZE * MY_IO_BUFSIZE); +// #endif //-------------------------------------------------------------------- // Write Header I: variables @@ -3167,8 +3139,7 @@ void COutput::NODWriteLAYDataTEC(int time_step_number) tec_file << "\n"; long j; - long no_per_layer = m_msh->GetNodesNumber(false) - / (m_msh->getNumberOfMeshLayers() + 1); + long no_per_layer = m_msh->GetNodesNumber(false) / (m_msh->getNumberOfMeshLayers() + 1); long jl; for (size_t l = 0; l < m_msh->getNumberOfMeshLayers() + 1; l++) { @@ -3177,22 +3148,21 @@ void COutput::NODWriteLAYDataTEC(int time_step_number) //-------------------------------------------------------------------- for (j = 0l; j < no_per_layer; j++) { - jl = j + j* m_msh->getNumberOfMeshLayers() + l; + jl = j + j * m_msh->getNumberOfMeshLayers() + l; //.................................................................. // XYZ - double const* const pnt (m_msh->nod_vector[jl]->getData()); + double const* const pnt(m_msh->nod_vector[jl]->getData()); tec_file << pnt[0] << " "; tec_file << pnt[1] << " "; tec_file << pnt[2] << " "; tec_file << jl << " "; //.................................................................. for (size_t k = 0; k < nName; k++) - tec_file << m_pcs->GetNodeValue( - m_msh->nod_vector[jl]->GetIndex(), NodeIndex[k]) << " "; + tec_file << m_pcs->GetNodeValue(m_msh->nod_vector[jl]->GetIndex(), NodeIndex[k]) << " "; tec_file << "\n"; } } - tec_file.close(); // kg44 close file + tec_file.close(); // kg44 close file } /************************************************************************** @@ -3208,142 +3178,144 @@ void COutput::PCONWriteDOMDataTEC() string tec_file_name; #if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) char tf_name[10]; - std::cout << "Process " << myrank << " in WriteDOMDataTEC" << "\n"; + std::cout << "Process " << myrank << " in WriteDOMDataTEC" + << "\n"; #endif //---------------------------------------------------------------------- // Tests - if(_pcon_value_vector.size() == 0) + if (_pcon_value_vector.size() == 0) return; //...................................................................... // MSH - //m_msh = FEMGet(pcs_type_name); + // m_msh = FEMGet(pcs_type_name); // m_msh = GetMSH(); - if(!m_msh) + if (!m_msh) { - cout << "Warning in COutput::NODWriteDOMDataTEC() - no MSH data" << "\n"; + cout << "Warning in COutput::NODWriteDOMDataTEC() - no MSH data" + << "\n"; return; } //====================================================================== - vector mesh_type_list; //NW + vector mesh_type_list; // NW if (m_msh->getNumberOfLines() > 0) mesh_type_list.push_back(1); - if (m_msh->getNumberOfQuads () > 0) + if (m_msh->getNumberOfQuads() > 0) mesh_type_list.push_back(2); - if (m_msh->getNumberOfHexs () > 0) + if (m_msh->getNumberOfHexs() > 0) mesh_type_list.push_back(3); - if (m_msh->getNumberOfTris () > 0) + if (m_msh->getNumberOfTris() > 0) mesh_type_list.push_back(4); - if (m_msh->getNumberOfTets () > 0) + if (m_msh->getNumberOfTets() > 0) mesh_type_list.push_back(5); - if (m_msh->getNumberOfPrisms () > 0) + if (m_msh->getNumberOfPrisms() > 0) mesh_type_list.push_back(6); // Output files for each mesh type - //NW + // NW for (int i = 0; i < (int)mesh_type_list.size(); i++) { te = mesh_type_list[i]; //---------------------------------------------------------------------- // File name handling tec_file_name = file_base_name + "_" + "domain_PCON"; - if(msh_type_name.size() > 0) // MultiMSH + if (msh_type_name.size() > 0) // MultiMSH tec_file_name += "_" + msh_type_name; // if(pcs_type_name.size()>0) // PCS // tec_file_name += "_" + pcs_type_name; - if(getProcessType () != FiniteElement::INVALID_PROCESS) // PCS - tec_file_name += "_" + convertProcessTypeToString (getProcessType()); + if (getProcessType() != FiniteElement::INVALID_PROCESS) // PCS + tec_file_name += "_" + convertProcessTypeToString(getProcessType()); //====================================================================== - switch (te) //NW + switch (te) // NW { - case 1: - tec_file_name += "_line"; - eleType = "QUADRILATERAL"; - break; - case 2: - tec_file_name += "_quad"; - eleType = "QUADRILATERAL"; - break; - case 3: - tec_file_name += "_hex"; - eleType = "BRICK"; - break; - case 4: - tec_file_name += "_tri"; - eleType = "QUADRILATERAL"; - break; - case 5: - tec_file_name += "_tet"; - eleType = "TETRAHEDRON"; - break; - case 6: - tec_file_name += "_pris"; - eleType = "BRICK"; - break; + case 1: + tec_file_name += "_line"; + eleType = "QUADRILATERAL"; + break; + case 2: + tec_file_name += "_quad"; + eleType = "QUADRILATERAL"; + break; + case 3: + tec_file_name += "_hex"; + eleType = "BRICK"; + break; + case 4: + tec_file_name += "_tri"; + eleType = "QUADRILATERAL"; + break; + case 5: + tec_file_name += "_tet"; + eleType = "TETRAHEDRON"; + break; + case 6: + tec_file_name += "_pris"; + eleType = "BRICK"; + break; } - /* - if(m_msh->msh_no_line>0) - { - tec_file_name += "_line"; - eleType = "QUADRILATERAL"; - te=1; - } - else if (m_msh->msh_no_quad>0) - { - tec_file_name += "_quad"; - eleType = "QUADRILATERAL"; - te=2; - } - else if (m_msh->msh_no_hexs>0) - { - tec_file_name += "_hex"; - eleType = "BRICK"; - te=3; - } - else if (m_msh->msh_no_tris>0) - { - tec_file_name += "_tri"; - //???Who was this eleType = "TRIANGLE"; - eleType = "QUADRILATERAL"; - te=4; - } - else if (m_msh->msh_no_tets>0) - { - tec_file_name += "_tet"; - eleType = "TETRAHEDRON"; - te=5; - } - else if (m_msh->msh_no_pris>0) - { - tec_file_name += "_pris"; - eleType = "BRICK"; - te=6; - } - */ +/* + if(m_msh->msh_no_line>0) + { + tec_file_name += "_line"; + eleType = "QUADRILATERAL"; + te=1; + } + else if (m_msh->msh_no_quad>0) + { + tec_file_name += "_quad"; + eleType = "QUADRILATERAL"; + te=2; + } + else if (m_msh->msh_no_hexs>0) + { + tec_file_name += "_hex"; + eleType = "BRICK"; + te=3; + } + else if (m_msh->msh_no_tris>0) + { + tec_file_name += "_tri"; + //???Who was this eleType = "TRIANGLE"; + eleType = "QUADRILATERAL"; + te=4; + } + else if (m_msh->msh_no_tets>0) + { + tec_file_name += "_tet"; + eleType = "TETRAHEDRON"; + te=5; + } + else if (m_msh->msh_no_pris>0) + { + tec_file_name += "_pris"; + eleType = "BRICK"; + te=6; + } + */ #if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) sprintf(tf_name, "%d", myrank); tec_file_name += "_" + string(tf_name); std::cout << "Tecplot filename: " << tec_file_name << "\n"; #endif tec_file_name += TEC_FILE_EXTENSION; - //WW - if(!_new_file_opened) + // WW + if (!_new_file_opened) remove(tec_file_name.c_str()); - fstream tec_file (tec_file_name.data(),ios::app | ios::out); - tec_file.setf(ios::scientific,ios::floatfield); + fstream tec_file(tec_file_name.data(), ios::app | ios::out); + tec_file.setf(ios::scientific, ios::floatfield); tec_file.precision(12); if (!tec_file.good()) return; #ifdef SUPERCOMPUTER // kg44 buffer the output - char mybuf1 [MY_IO_BUFSIZE * MY_IO_BUFSIZE]; - tec_file.rdbuf()->pubsetbuf(mybuf1,MY_IO_BUFSIZE * MY_IO_BUFSIZE); + char mybuf1[MY_IO_BUFSIZE * MY_IO_BUFSIZE]; + tec_file.rdbuf()->pubsetbuf(mybuf1, MY_IO_BUFSIZE * MY_IO_BUFSIZE); #endif // - WriteTECHeader(tec_file,te,eleType); + WriteTECHeader(tec_file, te, eleType); WriteTECNodePCONData(tec_file); - WriteTECElementData(tec_file,te); - tec_file.close(); // kg44 close file + WriteTECElementData(tec_file, te); + tec_file.close(); // kg44 close file //-------------------------------------------------------------------- // tri elements // ***** 07/2010 TF commented out block since the global variable is always zero @@ -3478,13 +3450,13 @@ void COutput::PCONWriteDOMDataTEC() Programing: 08/2008 MX Implementation **************************************************************************/ -void COutput::WriteTECNodePCONData(fstream &tec_file) +void COutput::WriteTECNodePCONData(fstream& tec_file) { - const size_t nName (_pcon_value_vector.size()); + const size_t nName(_pcon_value_vector.size()); int nidx_dm[3]; std::vector PconIndex(nName); - // m_msh = GetMSH(); +// m_msh = GetMSH(); #ifdef CHEMAPP CEqlink* eq = NULL; @@ -3492,14 +3464,14 @@ void COutput::WriteTECNodePCONData(fstream &tec_file) eq = eq->GetREACTION(); if (!eq) return; - const int nPCON_aq = eq->NPCON[1]; //GetNPCON(1); + const int nPCON_aq = eq->NPCON[1]; // GetNPCON(1); eq->GetPconNameAq(); - for(i = 0; i < nName; i++) + for (i = 0; i < nName; i++) { - for(k = 0; k < nPCON_aq; k++) + for (k = 0; k < nPCON_aq; k++) // pcon_value_name = PconName_Aq[i]; - if(pcon_value_vector[i].compare(PconName_Aq[k]) == 0) + if (pcon_value_vector[i].compare(PconName_Aq[k]) == 0) { PconIndex[i] = k; break; @@ -3511,31 +3483,29 @@ void COutput::WriteTECNodePCONData(fstream &tec_file) for (size_t j = 0l; j < m_msh->GetNodesNumber(false); j++) { // XYZ - double x[3] = - {m_msh->nod_vector[j]->getData()[0], m_msh->nod_vector[j]->getData()[1], - m_msh->nod_vector[j]->getData()[2]}; -// x[0] = m_msh->nod_vector[j]->X(); -// x[1] = m_msh->nod_vector[j]->Y(); -// x[2] = m_msh->nod_vector[j]->Z(); + double x[3] = {m_msh->nod_vector[j]->getData()[0], m_msh->nod_vector[j]->getData()[1], + m_msh->nod_vector[j]->getData()[2]}; + // x[0] = m_msh->nod_vector[j]->X(); + // x[1] = m_msh->nod_vector[j]->Y(); + // x[2] = m_msh->nod_vector[j]->Z(); // Amplifying DISPLACEMENTs - if (M_Process || MH_Process) //WW + if (M_Process || MH_Process) // WW for (size_t k = 0; k < max_dim + 1; k++) - x[k] += out_amplifier * m_pcs->GetNodeValue( - m_msh->nod_vector[j]->GetIndex(), nidx_dm[k]); + x[k] += out_amplifier * m_pcs->GetNodeValue(m_msh->nod_vector[j]->GetIndex(), nidx_dm[k]); for (size_t i = 0; i < 3; i++) tec_file << x[i] << " "; - // NOD values +// NOD values #ifdef CHEMAPP - for(size_t k = 0; k < nName; k++) - tec_file << eq->GetPconAq_mol_amount(j,PconIndex[k]) << " "; + for (size_t k = 0; k < nName; k++) + tec_file << eq->GetPconAq_mol_amount(j, PconIndex[k]) << " "; #endif tec_file << "\n"; } } -void COutput::checkConsistency () +void COutput::checkConsistency() { if (!_nod_value_vector.empty()) { @@ -3543,7 +3513,7 @@ void COutput::checkConsistency () bool found = false; CRFProcess* pcs = NULL; const size_t pcs_vector_size(pcs_vector.size()); - const size_t nod_value_vector_size (_nod_value_vector.size()); + const size_t nod_value_vector_size(_nod_value_vector.size()); for (size_t j = 0; j < nod_value_vector_size; j++) { found = false; // initialize variable found @@ -3552,8 +3522,7 @@ void COutput::checkConsistency () pcs = pcs_vector[l]; for (size_t m = 0; m < pcs->nod_val_name_vector.size(); m++) { - if (pcs->nod_val_name_vector[m].compare( - _nod_value_vector[j]) == 0) + if (pcs->nod_val_name_vector[m].compare(_nod_value_vector[j]) == 0) { found = true; del_index.push_back(_nod_value_vector[j]); @@ -3562,54 +3531,53 @@ void COutput::checkConsistency () } } // end for(m...) - } // end for(l...) + } // end for(l...) if (!found) { - std::cout << "Warning - no PCS data for output variable " - << _nod_value_vector[j] << " in "; + std::cout << "Warning - no PCS data for output variable " << _nod_value_vector[j] << " in "; switch (getGeoType()) { - case GEOLIB::POINT: - std::cout << "POINT " << getGeoName() << "\n"; - break; - case GEOLIB::POLYLINE: - std::cout << "POLYLINE " << getGeoName() << "\n"; - break; - case GEOLIB::SURFACE: - std::cout << "SURFACE " << getGeoName() << "\n"; - break; - case GEOLIB::VOLUME: - std::cout << "VOLUME " << getGeoName() << "\n"; - break; - case GEOLIB::GEODOMAIN: - std::cout << "DOMAIN " << getGeoName() << "\n"; - break; - case GEOLIB::INVALID: - std::cout << - "WARNING: COutput::checkConsistency - invalid geo type" << - "\n"; - break; + case GEOLIB::POINT: + std::cout << "POINT " << getGeoName() << "\n"; + break; + case GEOLIB::POLYLINE: + std::cout << "POLYLINE " << getGeoName() << "\n"; + break; + case GEOLIB::SURFACE: + std::cout << "SURFACE " << getGeoName() << "\n"; + break; + case GEOLIB::VOLUME: + std::cout << "VOLUME " << getGeoName() << "\n"; + break; + case GEOLIB::GEODOMAIN: + std::cout << "DOMAIN " << getGeoName() << "\n"; + break; + case GEOLIB::INVALID: + std::cout << "WARNING: COutput::checkConsistency - invalid geo type" + << "\n"; + break; } } - } // end for(j...) + } // end for(j...) // Reduce vector out->_nod_value_vector by elements which have no PCS if (del_index.size() < _nod_value_vector.size()) { - std::cout << " Reducing output to variables with existing PCS-data " << - "\n"; + std::cout << " Reducing output to variables with existing PCS-data " + << "\n"; _nod_value_vector.clear(); for (size_t j = 0; j < del_index.size(); j++) _nod_value_vector.push_back(del_index[j]); - _alias_nod_value_vector.clear(); - for (size_t j = 0; j < del_index.size(); j++) - _alias_nod_value_vector.push_back(alias_del_lindex[j]); + _alias_nod_value_vector.clear(); + for (size_t j = 0; j < del_index.size(); j++) + _alias_nod_value_vector.push_back(alias_del_lindex[j]); } if (!pcs) pcs = this->GetPCS(); if (!pcs) - cout << "Warning in OUTData - no PCS data" << "\n"; - } // end if(_nod_value_vector.size()>0) + cout << "Warning in OUTData - no PCS data" + << "\n"; + } // end if(_nod_value_vector.size()>0) } /************************************************************************** @@ -3618,7 +3586,7 @@ void COutput::checkConsistency () Programing: 11/2011 NW Implementation **************************************************************************/ -void COutput::setInternalVarialbeNames(CFEMesh *msh) +void COutput::setInternalVarialbeNames(CFEMesh* msh) { #if 0 if (_alias_nod_value_vector.empty()) @@ -3657,45 +3625,54 @@ void COutput::setInternalVarialbeNames(CFEMesh *msh) } } #else - if (_nod_value_vector.empty()) - return; - bool isXZplane = (msh->GetCoordinateFlag()==22); - bool isPVD = (dat_type_name.compare("PVD") == 0); //currently only for PVD - - if (isXZplane && isPVD) { - std::cout << "-> recognized XZ plane for PVD output." << "\n"; - map map_output_variable_name; - map_output_variable_name.insert(pair("DISPLACEMENT_Y1", "DISPLACEMENT_Z1" )); - map_output_variable_name.insert(pair("DISPLACEMENT_Z1", "DISPLACEMENT_Y1" )); - map_output_variable_name.insert(pair("STRESS_XY", "STRESS_XZ" )); - map_output_variable_name.insert(pair("STRESS_YY", "STRESS_ZZ" )); - map_output_variable_name.insert(pair("STRESS_ZZ", "STRESS_YY" )); - map_output_variable_name.insert(pair("STRESS_XZ", "STRESS_XY" )); - map_output_variable_name.insert(pair("STRAIN_XY", "STRAIN_XZ" )); - map_output_variable_name.insert(pair("STRAIN_YY", "STRAIN_ZZ" )); - map_output_variable_name.insert(pair("STRAIN_ZZ", "STRAIN_YY" )); - map_output_variable_name.insert(pair("STRAIN_XZ", "STRAIN_XY" )); - map_output_variable_name.insert(pair("VELOCITY_Y1", "VELOCITY_Z1")); - map_output_variable_name.insert(pair("VELOCITY_Z1", "VELOCITY_Y1")); - map_output_variable_name.insert(pair("VELOCITY_Y2", "VELOCITY_Z2")); - map_output_variable_name.insert(pair("VELOCITY_Z2", "VELOCITY_Y2")); + if (_nod_value_vector.empty()) + return; + bool isXZplane = (msh->GetCoordinateFlag() == 22); + bool isPVD = (dat_type_name.compare("PVD") == 0); // currently only for PVD - for (size_t j = 0; j < _nod_value_vector.size(); j++) { - if (map_output_variable_name.count(_nod_value_vector[j])>0) { - _alias_nod_value_vector.push_back(map_output_variable_name[_nod_value_vector[j]]); - } else { - _alias_nod_value_vector.push_back(_nod_value_vector[j]); - } - } - } else { - for (size_t j = 0; j < _nod_value_vector.size(); j++) { - _alias_nod_value_vector.push_back(_nod_value_vector[j]); - } - } + if (isXZplane && isPVD) + { + std::cout << "-> recognized XZ plane for PVD output." + << "\n"; + map map_output_variable_name; + map_output_variable_name.insert(pair("DISPLACEMENT_Y1", "DISPLACEMENT_Z1")); + map_output_variable_name.insert(pair("DISPLACEMENT_Z1", "DISPLACEMENT_Y1")); + map_output_variable_name.insert(pair("STRESS_XY", "STRESS_XZ")); + map_output_variable_name.insert(pair("STRESS_YY", "STRESS_ZZ")); + map_output_variable_name.insert(pair("STRESS_ZZ", "STRESS_YY")); + map_output_variable_name.insert(pair("STRESS_XZ", "STRESS_XY")); + map_output_variable_name.insert(pair("STRAIN_XY", "STRAIN_XZ")); + map_output_variable_name.insert(pair("STRAIN_YY", "STRAIN_ZZ")); + map_output_variable_name.insert(pair("STRAIN_ZZ", "STRAIN_YY")); + map_output_variable_name.insert(pair("STRAIN_XZ", "STRAIN_XY")); + map_output_variable_name.insert(pair("VELOCITY_Y1", "VELOCITY_Z1")); + map_output_variable_name.insert(pair("VELOCITY_Z1", "VELOCITY_Y1")); + map_output_variable_name.insert(pair("VELOCITY_Y2", "VELOCITY_Z2")); + map_output_variable_name.insert(pair("VELOCITY_Z2", "VELOCITY_Y2")); + + for (size_t j = 0; j < _nod_value_vector.size(); j++) + { + if (map_output_variable_name.count(_nod_value_vector[j]) > 0) + { + _alias_nod_value_vector.push_back(map_output_variable_name[_nod_value_vector[j]]); + } + else + { + _alias_nod_value_vector.push_back(_nod_value_vector[j]); + } + } + } + else + { + for (size_t j = 0; j < _nod_value_vector.size(); j++) + { + _alias_nod_value_vector.push_back(_nod_value_vector[j]); + } + } #endif } -void COutput::addInfoToFileName (std::string& file_name, bool geo, bool process, bool mesh, const std::string &ext) const +void COutput::addInfoToFileName(std::string& file_name, bool geo, bool process, bool mesh, const std::string& ext) const { // add geo type name if (geo) @@ -3704,7 +3681,7 @@ void COutput::addInfoToFileName (std::string& file_name, bool geo, bool process, // add process type name if (getProcessType() != FiniteElement::INVALID_PROCESS && process) - file_name += "_" + FiniteElement::convertProcessTypeToString (getProcessType()); + file_name += "_" + FiniteElement::convertProcessTypeToString(getProcessType()); // add mesh type name if (msh_type_name.size() > 0 && mesh) @@ -3714,30 +3691,29 @@ void COutput::addInfoToFileName (std::string& file_name, bool geo, bool process, file_name += ext; } - - /************************************************************************** FEMLib-Method: 10/2014 JOD Calculates flux rectangular to polyline or surface, - the fluxes through element edges are stagged on a vector + the fluxes through element edges are stagged on a vector **************************************************************************/ -void COutput::CalculateTotalFlux(CFEMesh* msh, vector&nodes_on_geo, - vector&node_value_vector_diff, vector&node_value_vector_adv) +void COutput::CalculateTotalFlux(CFEMesh* msh, vector& nodes_on_geo, vector& node_value_vector_diff, + vector& node_value_vector_adv) { - CRFProcess* m_pcs = PCSGet(getProcessType()); - if (!msh || !m_pcs) { + if (!msh || !m_pcs) + { std::cout << "no MSH and / or PCS data for water balance"; return; } CRFProcess* m_pcs_flow = NULL; if (isFlowProcess(m_pcs->getProcessType())) m_pcs_flow = m_pcs; - else { + else + { m_pcs_flow = PCSGet(FiniteElement::GROUNDWATER_FLOW); if (m_pcs_flow == NULL) m_pcs_flow = PCSGet(FiniteElement::LIQUID_FLOW); @@ -3746,11 +3722,12 @@ void COutput::CalculateTotalFlux(CFEMesh* msh, vector&nodes_on_geo, long i, j, k, count; int nfaces, nfn; int nodesFace[8]; - double fac, nodesFVal[8], nodesFVal_adv[8], flux[3];// , poro; - //CMediumProperties *MediaProp; + double fac, nodesFVal[8], nodesFVal_adv[8], flux[3]; // , poro; + // CMediumProperties *MediaProp; int Axisymm = 1; // ani-axisymmetry - if (msh->isAxisymmetry()) Axisymm = -1; // Axisymmetry is true + if (msh->isAxisymmetry()) + Axisymm = -1; // Axisymmetry is true CElem* elem = NULL; CElem* face = new CElem(1); @@ -3768,40 +3745,43 @@ void COutput::CalculateTotalFlux(CFEMesh* msh, vector&nodes_on_geo, std::vector NVal_adv(this_number_of_nodes); // ----- initialize -------------------------------------------------------------------- - for (i = 0; i < (long)msh->nod_vector.size(); i++) { + for (i = 0; i < (long)msh->nod_vector.size(); i++) + { msh->nod_vector[i]->SetMark(false); G2L[i] = -1; } - for (i = 0; i < (long)nodes_on_geo.size(); i++) { + for (i = 0; i < (long)nodes_on_geo.size(); i++) + { NVal_diff[i] = NVal_adv[i] = 0.0; k = nodes_on_geo[i]; G2L[k] = i; } msh->GetConnectedElements(nodes_on_geo, elements_at_geo); - if ((m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) || (m_pcs->getProcessType() == FiniteElement::HEAT_TRANSPORT)) - m_pcs->CalIntegrationPointValue(); - + if ((m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) + || (m_pcs->getProcessType() == FiniteElement::HEAT_TRANSPORT)) + m_pcs->CalIntegrationPointValue(); - for (i = 0; i < (long)nodes_on_geo.size(); i++) { + for (i = 0; i < (long)nodes_on_geo.size(); i++) + { set_nodes_on_geo.insert(nodes_on_geo[i]); } // face integration - for (i = 0; i < (long)elements_at_geo.size(); i++) { - + for (i = 0; i < (long)elements_at_geo.size(); i++) + { elem = msh->ele_vector[elements_at_geo[i]]; if (!elem->GetMark()) continue; nfaces = elem->GetFacesNumber(); elem->SetOrder(msh->getOrder()); - for (j = 0; j < nfaces; j++) { - + for (j = 0; j < nfaces; j++) + { e_nei = elem->GetNeighbor(j); nfn = elem->GetElementFaceNodes(j, nodesFace); // is element face on surface? 1st check if (elem->selected < nfn) continue; - //2nd check + // 2nd check count = 0; for (k = 0; k < nfn; k++) { @@ -3816,7 +3796,7 @@ void COutput::CalculateTotalFlux(CFEMesh* msh, vector&nodes_on_geo, fac = 1.0; if (elem->GetDimension() == e_nei->GetDimension()) - fac = 0.5; // Not a surface face + fac = 0.5; // Not a surface face face->SetFace(elem, j); face->SetOrder(msh->getOrder()); face->ComputeVolume(); @@ -3831,16 +3811,20 @@ void COutput::CalculateTotalFlux(CFEMesh* msh, vector&nodes_on_geo, flux[0] = m_pcs_flow->GetNodeValue(e_node->GetIndex(), m_pcs_flow->GetNodeValueIndex("VELOCITY_X1")); flux[1] = m_pcs_flow->GetNodeValue(e_node->GetIndex(), m_pcs_flow->GetNodeValueIndex("VELOCITY_Y1")); flux[2] = m_pcs_flow->GetNodeValue(e_node->GetIndex(), m_pcs_flow->GetNodeValueIndex("VELOCITY_Z1")); - nodesFVal[k] = PointProduction(flux, face->normal_vector); // fabs(PointProduction(flux, face->normal_vector)); + nodesFVal[k] + = PointProduction(flux, face->normal_vector); // fabs(PointProduction(flux, face->normal_vector)); if (m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) nodesFVal_adv[k] = nodesFVal[k] * m_pcs->GetNodeValue(e_node->GetIndex(), 1); - else if (m_pcs->getProcessType() == FiniteElement::HEAT_TRANSPORT) // first fluid property for liquid - nodesFVal_adv[k] = nodesFVal[k] * m_pcs->GetNodeValue(e_node->GetIndex(), 1) * mfp_vector[0]->SpecificHeatCapacity() * mfp_vector[0]->Density(); + else if (m_pcs->getProcessType() == FiniteElement::HEAT_TRANSPORT) // first fluid property for liquid + nodesFVal_adv[k] = nodesFVal[k] * m_pcs->GetNodeValue(e_node->GetIndex(), 1) + * mfp_vector[0]->SpecificHeatCapacity() * mfp_vector[0]->Density(); } /// - element->FaceNormalFluxIntegration(elements_at_geo[i], nodesFVal, nodesFVal_adv, nodesFace, face, m_pcs, face->normal_vector); - for (k = 0; k < nfn; k++) { + element->FaceNormalFluxIntegration(elements_at_geo[i], nodesFVal, nodesFVal_adv, nodesFace, face, m_pcs, + face->normal_vector); + for (k = 0; k < nfn; k++) + { e_node = elem->GetNode(nodesFace[k]); // -->PETSC NVal_diff[G2L[e_node->GetIndex()]] += fac * nodesFVal[k]; @@ -3849,10 +3833,10 @@ void COutput::CalculateTotalFlux(CFEMesh* msh, vector&nodes_on_geo, } // end j, faces } // end i, elements at surface - for (i = 0; i < this_number_of_nodes; i++) { + for (i = 0; i < this_number_of_nodes; i++) + { node_value_vector_diff[i] = NVal_diff[i]; node_value_vector_adv[i] = NVal_adv[i]; - } for (i = 0; i < nSize; i++) msh->nod_vector[i]->SetMark(true); @@ -3862,12 +3846,8 @@ void COutput::CalculateTotalFlux(CFEMesh* msh, vector&nodes_on_geo, G2L.clear(); delete element; delete face; - } - - - /************************************************************************** FEMLib-Method: Task: Write output of multiple points in single file @@ -3877,29 +3857,30 @@ void COutput::CalculateTotalFlux(CFEMesh* msh, vector&nodes_on_geo, **************************************************************************/ void COutput::NODWritePointsCombined(double time_current) { - CFEMesh* m_msh = NULL; m_msh = FEMGet(convertProcessTypeToString(getProcessType())); CRFProcess* m_pcs_out = NULL; m_pcs_out = PCSGet(getProcessType()); - //std::string tec_file_name(file_base_name + "_time_"); - //addInfoToFileName(tec_file_name, true, true, true); + // std::string tec_file_name(file_base_name + "_time_"); + // addInfoToFileName(tec_file_name, true, true, true); char number_char[3]; string number_string = number_char; string tec_file_name = convertProcessTypeToString(getProcessType()) + "_time_" + "POINTS"; - if (_time < 1.e-20) { + if (_time < 1.e-20) + { remove(tec_file_name.c_str()); return; } fstream tec_file(tec_file_name.data(), ios::app | ios::out); tec_file.setf(ios::scientific, ios::floatfield); tec_file.precision(12); - if (!tec_file.good()) return; + if (!tec_file.good()) + return; tec_file.seekg(0L, ios::beg); - long msh_node_number(m_msh->GetNODOnPNT(static_cast (getGeoObj()))); + long msh_node_number(m_msh->GetNODOnPNT(static_cast(getGeoObj()))); //---------------------------------------------------------------------- // NIDX for output variables @@ -3908,23 +3889,22 @@ void COutput::NODWritePointsCombined(double time_current) GetNodeIndexVector(NodeIndex); // int no_variables = (int)nod_value_vector.size(); - //vectorNodeIndex(no_variables); - + // vectorNodeIndex(no_variables); tec_file << geo_name << " "; std::string nod_value_name; double val_n; - for (size_t i = 0; i < _nod_value_vector.size(); i++) { + for (size_t i = 0; i < _nod_value_vector.size(); i++) + { nod_value_name = _nod_value_vector[i]; val_n = m_pcs_out->GetNodeValue(msh_node_number, NodeIndex[i]); tec_file << "time " << time_current << " " << nod_value_name << " " << val_n << " " - << "\n"; + << "\n"; } tec_file.close(); - } /************************************************************************** @@ -3952,69 +3932,75 @@ void COutput::NODWritePrimaryVariableList(double time_current) if (_time < 1.e-20) // simulation must start at t= 0!!! { remove(tec_file_name.c_str()); - //return; + // return; } for (size_t j = 0; j < time_vector.size(); j++) - if ( ( fabs( time_current - time_vector[j] ) ) < MKleinsteZahl ) //WW MKleinsteZahl - { + if ((fabs(time_current - time_vector[j])) < MKleinsteZahl) // WW MKleinsteZahl + { + fstream tec_file(tec_file_name.data(), ios::app | ios::out); + tec_file.setf(ios::scientific, ios::floatfield); + tec_file.precision(12); + if (!tec_file.good()) + return; + tec_file.seekg(0L, ios::beg); + //-------------------------------------------------------------------- + Surface* m_sfc = NULL; + CGLPolyline* m_polyline = NULL; + GEOLIB::Polyline const* const ply(dynamic_cast(this->getGeoObj())); - fstream tec_file(tec_file_name.data(), ios::app | ios::out); - tec_file.setf(ios::scientific, ios::floatfield); - tec_file.precision(12); - if (!tec_file.good()) return; - tec_file.seekg(0L, ios::beg); - //-------------------------------------------------------------------- - Surface *m_sfc = NULL; - CGLPolyline* m_polyline = NULL; - GEOLIB::Polyline const* const ply( - dynamic_cast (this->getGeoObj())); + // tec_file << "TIME " << time_current << "\n"; - //tec_file << "TIME " << time_current << "\n"; + switch (getGeoType()) + { + case GEOLIB::GEODOMAIN: - switch (getGeoType()) { + for (std::size_t i = 0; i < m_msh->nod_vector.size(); i++) + tec_file << m_msh->nod_vector[i]->GetIndex() << " " + << m_pcs_out->GetNodeValue(m_msh->nod_vector[i]->GetIndex(), 1) << "\n"; - case GEOLIB::GEODOMAIN: + cout << "Data output: " << convertProcessTypeToString(getProcessType()) + << " primary variables - DOMAIN - " << m_msh->nod_vector.size() << " nodes" << endl; + break; + case GEOLIB::SURFACE: - for (std::size_t i = 0; i < m_msh->nod_vector.size(); i++) - tec_file << m_msh->nod_vector[i]->GetIndex() << " " << m_pcs_out->GetNodeValue(m_msh->nod_vector[i]->GetIndex(), 1) << "\n"; + m_sfc = GEOGetSFCByName(geo_name); + if (m_sfc) + m_msh->GetNODOnSFC(m_sfc, nodes_vector); - cout << "Data output: " << convertProcessTypeToString(getProcessType()) << " primary variables - DOMAIN - " << m_msh->nod_vector.size() << " nodes" << endl; - break; - case GEOLIB::SURFACE: + for (std::size_t i = 0; i < nodes_vector.size(); i++) + tec_file << nodes_vector[i] << " " << m_pcs_out->GetNodeValue(nodes_vector[i], 1) + << "\n"; - m_sfc = GEOGetSFCByName(geo_name); - if (m_sfc) - m_msh->GetNODOnSFC(m_sfc, nodes_vector); + cout << "Data output: " << convertProcessTypeToString(getProcessType()) + << " primary variables - SURFACE " << geo_name << " - " << nodes_vector.size() << " nodes" + << endl; + break; + case GEOLIB::POLYLINE: - for (std::size_t i = 0; i < nodes_vector.size(); i++) - tec_file << nodes_vector[i] << " " << m_pcs_out->GetNodeValue(nodes_vector[i], 1) << "\n"; + m_polyline = GEOGetPLYByName(geo_name); + if (ply) + { + double min_edge_length(m_msh->getMinEdgeLength()); + m_msh->setMinEdgeLength(m_polyline->epsilon); + m_msh->GetNODOnPLY(ply, nodes_vector); + m_msh->setMinEdgeLength(min_edge_length); + } - cout << "Data output: " << convertProcessTypeToString(getProcessType()) << " primary variables - SURFACE " << geo_name << " - " << nodes_vector.size() << " nodes" << endl; - break; - case GEOLIB::POLYLINE: + for (std::size_t i = 0; i < nodes_vector.size(); i++) + tec_file << nodes_vector[i] << " " << m_pcs_out->GetNodeValue(nodes_vector[i], 1) + << "\n"; - m_polyline = GEOGetPLYByName(geo_name); - if (ply) { - double min_edge_length(m_msh->getMinEdgeLength()); - m_msh->setMinEdgeLength(m_polyline->epsilon); - m_msh->GetNODOnPLY(ply, nodes_vector); - m_msh->setMinEdgeLength(min_edge_length); + cout << "Data output: " << convertProcessTypeToString(getProcessType()) + << " primary variables - POLYLINE " << geo_name << " - " << nodes_vector.size() << " nodes" + << endl; + break; + default: + break; } - - for (std::size_t i = 0; i < nodes_vector.size(); i++) - tec_file << nodes_vector[i] << " " << m_pcs_out->GetNodeValue(nodes_vector[i], 1) << "\n"; - - cout << "Data output: " << convertProcessTypeToString(getProcessType()) << " primary variables - POLYLINE " << geo_name << " - " << nodes_vector.size() << " nodes" << endl; - break; - default: - break; - + ////////////// + tec_file << "#STOP"; + tec_file.close(); } - ////////////// - tec_file << "#STOP"; - tec_file.close(); - } - } /************************************************************************** @@ -4027,7 +4013,6 @@ Task: Write water balance for polyline with leakance void COutput::NODWriteTotalFlux(double time_current, int time_step_number) { - CFEMesh* m_msh = NULL; m_msh = FEMGet(convertProcessTypeToString(getProcessType())); CRFProcess* m_pcs = NULL; @@ -4044,22 +4029,20 @@ void COutput::NODWriteTotalFlux(double time_current, int time_step_number) if (time_step_number == 0) { remove(tec_file_name.c_str()); - } - //if (!_new_file_opened) + // if (!_new_file_opened) // remove(tec_file_name.c_str()); //WW fstream tec_file(tec_file_name.data(), ios::app | ios::out); tec_file.setf(ios::scientific, ios::floatfield); tec_file.precision(12); - if (!tec_file.good()) return; + if (!tec_file.good()) + return; tec_file.seekg(0L, ios::beg); if (time_step_number == 0) { - - tec_file << "TIME "; if (m_pcs->getProcessType() == FiniteElement::HEAT_TRANSPORT) tec_file << "FICK FLUX ADVECTION FLUX"; @@ -4080,18 +4063,20 @@ void COutput::NODWriteTotalFlux(double time_current, int time_step_number) CalculateTotalFlux(m_msh, nodes_vector, nodes_value_vector_diffusion, nodes_value_vector_advection); total_value_diffusion = total_value_advection = 0; - for (long i = 0; i < (long)nodes_value_vector_diffusion.size(); i++) { + for (long i = 0; i < (long)nodes_value_vector_diffusion.size(); i++) + { total_value_diffusion += nodes_value_vector_diffusion[i]; // fabs(nodes_value_vector_diffusion[i]); total_value_advection += nodes_value_vector_advection[i]; // fabs(nodes_value_vector_advection[i]); } tec_file << time_current << " " << total_value_diffusion << " "; - if ((m_pcs->getProcessType() == FiniteElement::HEAT_TRANSPORT) || (m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT)) + if ((m_pcs->getProcessType() == FiniteElement::HEAT_TRANSPORT) + || (m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT)) tec_file << total_value_advection; tec_file << "\n"; - cout << "Data output: " << convertProcessTypeToString(getProcessType()) << " TOTAL_FLUX " << geo_name << " - " << nodes_vector.size() << " nodes" << endl; + cout << "Data output: " << convertProcessTypeToString(getProcessType()) << " TOTAL_FLUX " << geo_name << " - " + << nodes_vector.size() << " nodes" << endl; tec_file.close(); - } /************************************************************************** @@ -4104,19 +4089,19 @@ FEMLib-Method: void COutput::SetTotalFluxNodes(std::vector& nodes_vector) { - - switch (this->getGeoType()) { - case GEOLIB::POLYLINE: - SetTotalFluxNodesPLY(nodes_vector); - break; - case GEOLIB::SURFACE: - SetTotalFluxNodesSURF(nodes_vector); - break; - case GEOLIB::GEODOMAIN: - SetTotalFluxNodesDOM(nodes_vector); - break; - default: - cout << "Warning: Water Balance does not support this geotype" << endl; + switch (this->getGeoType()) + { + case GEOLIB::POLYLINE: + SetTotalFluxNodesPLY(nodes_vector); + break; + case GEOLIB::SURFACE: + SetTotalFluxNodesSURF(nodes_vector); + break; + case GEOLIB::GEODOMAIN: + SetTotalFluxNodesDOM(nodes_vector); + break; + default: + cout << "Warning: Water Balance does not support this geotype" << endl; } } @@ -4130,18 +4115,16 @@ FEMLib-Method: void COutput::SetTotalFluxNodesPLY(std::vector& nodes_vector) { + GEOLIB::Polyline const* const ply(dynamic_cast(this->getGeoObj())); - GEOLIB::Polyline const* const ply( - dynamic_cast (this->getGeoObj())); - - if (ply) { + if (ply) + { CGLPolyline* m_polyline = GEOGetPLYByName(geo_name); double min_edge_length(m_msh->getMinEdgeLength()); m_msh->setMinEdgeLength(m_polyline->epsilon); m_msh->GetNODOnPLY(ply, nodes_vector); m_msh->setMinEdgeLength(min_edge_length); } - } /************************************************************************** @@ -4154,14 +4137,11 @@ FEMLib-Method: void COutput::SetTotalFluxNodesSURF(std::vector& nodes_vector) { - Surface* m_sfc = NULL; m_sfc = GEOGetSFCByName(geo_name); if (m_sfc) m_msh->GetNODOnSFC(m_sfc, nodes_vector); - - } /************************************************************************** @@ -4177,14 +4157,9 @@ void COutput::SetTotalFluxNodesDOM(std::vector& nodes_vector) nodes_vector.resize(m_msh->nod_vector.size()); for (std::size_t i = 0; i < m_msh->nod_vector.size(); i++) nodes_vector[i] = m_msh->nod_vector[i]->GetIndex(); - - } - void COutput::setFileBaseName(const std::string& fn) { file_base_name = pathJoin(defaultOutputPath, pathBasename(fn)); } - - diff --git a/FEM/Output.h b/FEM/Output.h index 6e7d7d696..4e841410c 100644 --- a/FEM/Output.h +++ b/FEM/Output.h @@ -24,10 +24,12 @@ #endif namespace MeshLib -{class CFEMesh; +{ +class CFEMesh; } namespace GEOLIB -{class GEOObjects; +{ +class GEOObjects; } class CVTK; @@ -37,52 +39,43 @@ class COutput : public GeoInfo, public ProcessInfo, public DistributionInfo public: COutput(); - COutput (size_t id); + COutput(size_t id); /** * method initializes process and mesh attributes */ - void init (); - void CreateVTKInstance(void); //WW + void init(); + void CreateVTKInstance(void); // WW ~COutput(void); /** * scaling factor for values * @param amplifier - a double value for scaling data */ - void setAmplifier(double amplifier) - { - out_amplifier = amplifier; - } - - CRFProcess* GetPCS(const std::string&); //OK - CRFProcess* GetPCS(); // 09/2010 TF - CRFProcess* GetPCS_ELE(const std::string&); //OK + void setAmplifier(double amplifier) { out_amplifier = amplifier; } + CRFProcess* GetPCS(const std::string&); // OK + CRFProcess* GetPCS(); // 09/2010 TF + CRFProcess* GetPCS_ELE(const std::string&); // OK /** * checking the consistency of the output data as specified in the input file * This means up to now, that data for missing processes is not written. */ - void checkConsistency(); // CB (refactored by TF) - void setInternalVarialbeNames(MeshLib::CFEMesh *msh); + void checkConsistency(); // CB (refactored by TF) + void setInternalVarialbeNames(MeshLib::CFEMesh* msh); - void GetNodeIndexVector(std::vector&); //OK - void SetNODFluxAtPLY(); //OK + void GetNodeIndexVector(std::vector&); // OK + void SetNODFluxAtPLY(); // OK // ELE values - const std::vector& getElementValueVector () const { return _ele_value_vector; } - //OK + const std::vector& getElementValueVector() const { return _ele_value_vector; } + // OK void GetELEValuesIndexVector(std::vector&); /** * * @return */ - const std::vector& getRandomWalkParticleTracingValueVector() const - { - return - _rwpt_value_vector; - } - + const std::vector& getRandomWalkParticleTracingValueVector() const { return _rwpt_value_vector; } /** * ToDo remove after transition to new GEOLIB - REMOVE CANDIDATE * getGeoName returns a string used as id for geometric entity @@ -92,7 +85,7 @@ class COutput : public GeoInfo, public ProcessInfo, public DistributionInfo */ const std::string& getGeoName() const; // TF 05/2010 - MeshLib::CFEMesh* getMesh () // TF + MeshLib::CFEMesh* getMesh() // TF { return m_msh; } @@ -104,15 +97,14 @@ class COutput : public GeoInfo, public ProcessInfo, public DistributionInfo * @param unique_name the name of the project to access the right geometric entities * @return the new position in the stream after reading */ - std::ios::pos_type Read(std::ifstream& in, const GEOLIB::GEOObjects& geo_obj, - const std::string& unique_name); + std::ios::pos_type Read(std::ifstream& in, const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name); void Write(std::fstream*); // TF not used (at the moment?) REMOVE CANDIDATE // int GetPointClose(CGLPoint); - void WriteTimeCurveData(std::fstream &); - void WriteTimeCurveHeader(std::fstream &); + void WriteTimeCurveData(std::fstream&); + void WriteTimeCurveHeader(std::fstream&); void NODWriteDOMDataTEC(); void WriteTECHeader(std::fstream&, int, std::string); void WriteTECNodeData(std::fstream&); @@ -123,36 +115,37 @@ class COutput : public GeoInfo, public ProcessInfo, public DistributionInfo void WriteELEValuesTECHeader(std::fstream&); void WriteELEValuesTECData(std::fstream&); void NODWriteSFCDataTEC(int); - void NODWriteSFCAverageDataTEC(double, int); //OK - void WriteRFO(); //OK - void WriteRFOHeader(std::fstream&); //OK - void WriteRFONodes(std::fstream&); //OK - void WriteRFOElements(std::fstream&); //OK - void WriteRFOValues(std::fstream&); //OK - void NODWriteLAYDataTEC(int); //OK - void ELEWriteSFC_TEC(); //OK - void ELEWriteSFC_TECHeader(std::fstream&); //OK - void ELEWriteSFC_TECData(std::fstream&); //OK + void NODWriteSFCAverageDataTEC(double, int); // OK + void WriteRFO(); // OK + void WriteRFOHeader(std::fstream&); // OK + void WriteRFONodes(std::fstream&); // OK + void WriteRFOElements(std::fstream&); // OK + void WriteRFOValues(std::fstream&); // OK + void NODWriteLAYDataTEC(int); // OK + void ELEWriteSFC_TEC(); // OK + void ELEWriteSFC_TECHeader(std::fstream&); // OK + void ELEWriteSFC_TECData(std::fstream&); // OK void CalcELEFluxes(); - void ELEWritePLY_TEC(); //OK - void ELEWritePLY_TECHeader(std::fstream&); //OK - void ELEWritePLY_TECData(std::fstream&); //OK - void TIMValue_TEC(double); //OK - void TIMValues_TEC(double tim_value[5], std::string *header, int dimension); //BG 04/2011 added for more than 1 value per time - double NODFlux(long); //OK - void PCONWriteDOMDataTEC(); //MX - void WriteTECNodePCONData(std::fstream &); //MX - - - void NODWriteTotalFlux(double, int); // JOD 2014-11-10 - void NODWritePointsCombined(double); // 6/2012 JOD - void NODWritePrimaryVariableList(double); // JOD 2014-11-10 - void CalculateTotalFlux(MeshLib::CFEMesh*, std::vector&, std::vector&, std::vector&); // JOD 2014-11-10 - void SetTotalFluxNodes(std::vector& nodes_vector); //JOD 2014-11-10 + void ELEWritePLY_TEC(); // OK + void ELEWritePLY_TECHeader(std::fstream&); // OK + void ELEWritePLY_TECData(std::fstream&); // OK + void TIMValue_TEC(double); // OK + void TIMValues_TEC(double tim_value[5], std::string* header, + int dimension); // BG 04/2011 added for more than 1 value per time + double NODFlux(long); // OK + void PCONWriteDOMDataTEC(); // MX + void WriteTECNodePCONData(std::fstream&); // MX + + void NODWriteTotalFlux(double, int); // JOD 2014-11-10 + void NODWritePointsCombined(double); // 6/2012 JOD + void NODWritePrimaryVariableList(double); // JOD 2014-11-10 + void CalculateTotalFlux(MeshLib::CFEMesh*, std::vector&, std::vector&, + std::vector&); // JOD 2014-11-10 + void SetTotalFluxNodes(std::vector& nodes_vector); // JOD 2014-11-10 void SetTotalFluxNodesPLY(std::vector& nodes_vector); // JOD 2014-11-10 void SetTotalFluxNodesSURF(std::vector& nodes_vector); // JOD 2014-11-10 void SetTotalFluxNodesDOM(std::vector& nodes_vector); // JOD 2014-11-10 - //------------------------------------------------------ +//------------------------------------------------------ #if defined(USE_PETSC) || defined(USE_MPI) //|| defined(other parallel libs)//03.3012. WW void setMPI_Info(const int rank, const int size, std::string rank_str); /// Head for binary output for parallel computing. 01.2014. WW @@ -161,24 +154,22 @@ class COutput : public GeoInfo, public ProcessInfo, public DistributionInfo void NODDomainWriteBinary(); #endif - void setTime (double time) { _time = time; } + void setTime(double time) { _time = time; } /** * get time returns the value of attribute time * @return */ - double getTime () const { return _time; } - - const std::vector& getTimeVector () const { return time_vector; } - const std::string& getFileBaseName () const { return file_base_name; } - - /** - * @brief sets file_base_name to the full path corresponding to the given base name. - * - * The function internally uses the defaultOutputPath as set as a commandline argument. - */ - void setFileBaseName(const std::string& fn); + double getTime() const { return _time; } + const std::vector& getTimeVector() const { return time_vector; } + const std::string& getFileBaseName() const { return file_base_name; } + /** + * @brief sets file_base_name to the full path corresponding to the given base name. + * + * The function internally uses the defaultOutputPath as set as a commandline argument. + */ + void setFileBaseName(const std::string& fn); - size_t getNSteps () const { return nSteps; } + size_t getNSteps() const { return nSteps; } /** * constructs/adds the output file name using geo_name, * process type, mesh type @@ -187,20 +178,21 @@ class COutput : public GeoInfo, public ProcessInfo, public DistributionInfo * @param process switch on/off process info in file name (default = on) * @param mesh switch on/off mesh info in file name (default = on) */ - void addInfoToFileName(std::string& fname, bool geo = true, bool process = - true, bool mesh = true, const std::string &ext=TEC_FILE_EXTENSION) const; // 09/2010 TF + void addInfoToFileName(std::string& fname, bool geo = true, bool process = true, bool mesh = true, + const std::string& ext = TEC_FILE_EXTENSION) const; // 09/2010 TF std::vector _nod_value_vector; - std::vector _alias_nod_value_vector; + std::vector _alias_nod_value_vector; // MAT values - std::vector mmp_value_vector; //OK - std::vector mfp_value_vector; //OK + std::vector mmp_value_vector; // OK + std::vector mfp_value_vector; // OK - CRFProcess* m_pcs; //OK + CRFProcess* m_pcs; // OK // std::vector& getRWPTTimeVector () { return rwpt_time_vector; } - std::vector& getRWPTTimeVector () { return time_vector; } - bool VARIABLESHARING; // Coordinates of each node as well as connection list is stored only for the first time step; BG: 05/2011 + std::vector& getRWPTTimeVector() { return time_vector; } + bool VARIABLESHARING; // Coordinates of each node as well as connection list is stored only for the first time step; + // BG: 05/2011 private: friend void OUTData(double, int step, bool force_output); @@ -208,10 +200,10 @@ class COutput : public GeoInfo, public ProcessInfo, public DistributionInfo // std::vector rwpt_time_vector; //JT, needed because outputs are treated differently in RWPT // MSH - std::string msh_type_name; //OK + std::string msh_type_name; // OK // TIM - std::string tim_type_name; // STEPS or TIMES ? + std::string tim_type_name; // STEPS or TIMES ? std::vector time_vector; double _time; @@ -221,21 +213,21 @@ class COutput : public GeoInfo, public ProcessInfo, public DistributionInfo size_t _id; std::string file_base_name; - double out_amplifier; //WW to amplify output - //WW/OK + double out_amplifier; // WW to amplify output + // WW/OK MeshLib::CFEMesh* m_msh; - int nSteps; // After each nSteps, make output + int nSteps; // After each nSteps, make output CVTK* vtk; // GEO /** * the id of the geometric object as string REMOVE CANDIDATE */ - std::string geo_name; // TF 05/2010 + std::string geo_name; // TF 05/2010 // File status - bool _new_file_opened; //WW + bool _new_file_opened; // WW // DAT /** diff --git a/FEM/OutputTools.h b/FEM/OutputTools.h index ad01848f3..d67cfd121 100644 --- a/FEM/OutputTools.h +++ b/FEM/OutputTools.h @@ -17,7 +17,6 @@ using namespace std; - struct ELEMENT_MMP_VALUES { static double getValue(CMediumProperties* mmp, int mmp_id, long i_e, double* gp, double theta) @@ -25,23 +24,23 @@ struct ELEMENT_MMP_VALUES double mat_value = .0; switch (mmp_id) { - case 0: - mat_value = mmp->Porosity(i_e, theta); - break; - case 1: - mat_value = mmp->PermeabilityTensor(i_e)[0]; - break; - case 2: - mat_value = mmp->StorageFunction(i_e, gp, theta); - break; - default: - cout << "ELEMENT_MMP_VALUES::getValue(): no MMP values specified" << endl; - break; + case 0: + mat_value = mmp->Porosity(i_e, theta); + break; + case 1: + mat_value = mmp->PermeabilityTensor(i_e)[0]; + break; + case 2: + mat_value = mmp->StorageFunction(i_e, gp, theta); + break; + default: + cout << "ELEMENT_MMP_VALUES::getValue(): no MMP values specified" << endl; + break; } return mat_value; } - static int getMMPIndex(const std::string &mmp_name) + static int getMMPIndex(const std::string& mmp_name) { int mmp_id = -1; if (mmp_name.compare("POROSITY") == 0) @@ -71,20 +70,20 @@ struct ELEMENT_MFP_VALUES double mat_value = .0; switch (mfp_id) { - case 0: - mat_value = mfp->Density(); - break; - case 1: - mat_value = mfp->Viscosity(); - break; - default: - cout << "ELEMENT_MFP_VALUES: no MFP values specified" << endl; - break; + case 0: + mat_value = mfp->Density(); + break; + case 1: + mat_value = mfp->Viscosity(); + break; + default: + cout << "ELEMENT_MFP_VALUES: no MFP values specified" << endl; + break; } return mat_value; } - static int getMFPIndex(const std::string &mfp_name) + static int getMFPIndex(const std::string& mfp_name) { int mfp_id = -1; if (mfp_name.compare("DENSITY") == 0) @@ -105,7 +104,7 @@ struct ELEMENT_MFP_VALUES inline double getElementMMP(int mmp_id, MeshLib::CElem* ele, CRFProcess* m_pcs) { - double gp[3] = { .0, .0, .0 }; + double gp[3] = {.0, .0, .0}; double theta = 1.0; int gp_r, gp_s, gp_t; ele->SetOrder(false); @@ -121,9 +120,9 @@ inline double getElementMMP(int mmp_id, MeshLib::CElem* ele, CRFProcess* m_pcs) inline double getNodeMMP(int mmp_id, MeshLib::CFEMesh* m_msh, MeshLib::CNode* node, CRFProcess* m_pcs) { - const std::vector &connected_ele_ids = node->getConnectedElementIDs(); + const std::vector& connected_ele_ids = node->getConnectedElementIDs(); double ele_avg = .0; - for (long i_e = 0; i_e < (long) connected_ele_ids.size(); i_e++) + for (long i_e = 0; i_e < (long)connected_ele_ids.size(); i_e++) { MeshLib::CElem* ele = m_msh->ele_vector[connected_ele_ids[i_e]]; ele_avg += getElementMMP(mmp_id, ele, m_pcs); @@ -134,9 +133,9 @@ inline double getNodeMMP(int mmp_id, MeshLib::CFEMesh* m_msh, MeshLib::CNode* no inline double getNodeElementValue(int ele_value_id, MeshLib::CFEMesh* m_msh, MeshLib::CNode* node, CRFProcess* m_pcs) { - const std::vector &connected_ele_ids = node->getConnectedElementIDs(); + const std::vector& connected_ele_ids = node->getConnectedElementIDs(); double ele_avg = .0; - for (long i_e = 0; i_e < (long) connected_ele_ids.size(); i_e++) + for (long i_e = 0; i_e < (long)connected_ele_ids.size(); i_e++) { MeshLib::CElem* ele = m_msh->ele_vector[connected_ele_ids[i_e]]; ele_avg += m_pcs->GetElementValue(ele->GetIndex(), ele_value_id); diff --git a/FEM/PhysicalConstant.h b/FEM/PhysicalConstant.h index 193758aa2..2a0d37d24 100644 --- a/FEM/PhysicalConstant.h +++ b/FEM/PhysicalConstant.h @@ -60,7 +60,7 @@ const double Water = 0.018016; ///< kg mol^-1 * * According to the IUPAC report the molar mass of N is in the range [14.006 43, 14.007 28] g/mol */ -const double N2 = 0.028013; ///< kg mol^-1 +const double N2 = 0.028013; ///< kg mol^-1 /** * O_2 @@ -70,7 +70,7 @@ const double N2 = 0.028013; ///< kg mol^-1 * * According to the IUPAC report the molar mass of O is in the range [15.999 03, 15.999 77] g/mol */ -const double O2 = 0.032; ///< kg mol^-1 +const double O2 = 0.032; ///< kg mol^-1 /** * Air @@ -78,7 +78,7 @@ const double O2 = 0.032; ///< kg mol^-1 * Source: http://www.engineeringtoolbox.com/molecular-mass-air-d_679.html * */ -const double Air = 0.02897; ///< kg mol^-1 +const double Air = 0.02897; ///< kg mol^-1 } /** @@ -93,4 +93,4 @@ namespace SpecificGasConstant const double WaterVapour = IdealGasConstant / MolarMass::Water; //=461.504; } } -#endif //OGS_CONSTANTS_H +#endif // OGS_CONSTANTS_H diff --git a/FEM/ProcessInfo.cpp b/FEM/ProcessInfo.cpp index 97a491ed1..13ea92215 100644 --- a/FEM/ProcessInfo.cpp +++ b/FEM/ProcessInfo.cpp @@ -13,48 +13,50 @@ #include "rf_pcs.h" #include -ProcessInfo::ProcessInfo() : - _pcs_type (FiniteElement::INVALID_PROCESS), _pcs_pv (FiniteElement::INVALID_PV), _pcs (NULL) -{} +ProcessInfo::ProcessInfo() : _pcs_type(FiniteElement::INVALID_PROCESS), _pcs_pv(FiniteElement::INVALID_PV), _pcs(NULL) +{ +} -ProcessInfo::ProcessInfo (FiniteElement::ProcessType pcs_type, FiniteElement::PrimaryVariable pcs_pv, CRFProcess* pcs) : - _pcs_type (pcs_type), _pcs_pv (pcs_pv), _pcs (pcs) -{} +ProcessInfo::ProcessInfo(FiniteElement::ProcessType pcs_type, FiniteElement::PrimaryVariable pcs_pv, CRFProcess* pcs) + : _pcs_type(pcs_type), _pcs_pv(pcs_pv), _pcs(pcs) +{ +} -void ProcessInfo::setProcessType (FiniteElement::ProcessType pcs_type) +void ProcessInfo::setProcessType(FiniteElement::ProcessType pcs_type) { _pcs_type = pcs_type; } -void ProcessInfo::setProcessPrimaryVariable (FiniteElement::PrimaryVariable pcs_pv) +void ProcessInfo::setProcessPrimaryVariable(FiniteElement::PrimaryVariable pcs_pv) { _pcs_pv = pcs_pv; } -void ProcessInfo::setProcess (CRFProcess* pcs) +void ProcessInfo::setProcess(CRFProcess* pcs) { _pcs = pcs; } -FiniteElement::ProcessType ProcessInfo::getProcessType () const +FiniteElement::ProcessType ProcessInfo::getProcessType() const { return _pcs_type; } -FiniteElement::PrimaryVariable ProcessInfo::getProcessPrimaryVariable () const +FiniteElement::PrimaryVariable ProcessInfo::getProcessPrimaryVariable() const { return _pcs_pv; } -int ProcessInfo::getProcessCompVecIndex () const +int ProcessInfo::getProcessCompVecIndex() const { - return _pcs->pcs_component_number; + return _pcs->pcs_component_number; } -CRFProcess* ProcessInfo::getProcess () const +CRFProcess* ProcessInfo::getProcess() const { return _pcs; } ProcessInfo::~ProcessInfo() -{} +{ +} diff --git a/FEM/ProcessInfo.h b/FEM/ProcessInfo.h index 518a5b463..a08d5583e 100644 --- a/FEM/ProcessInfo.h +++ b/FEM/ProcessInfo.h @@ -41,50 +41,49 @@ class ProcessInfo * @param pcs a pointer to the process * @return */ - ProcessInfo (FiniteElement::ProcessType pcs_type, FiniteElement::PrimaryVariable pcs_pv, CRFProcess* pcs); + ProcessInfo(FiniteElement::ProcessType pcs_type, FiniteElement::PrimaryVariable pcs_pv, CRFProcess* pcs); /** * Sets the process type. * @param pcs_type the process type, for valid values see enum ProcessType */ - void setProcessType (FiniteElement::ProcessType pcs_type); + void setProcessType(FiniteElement::ProcessType pcs_type); /** * Sets the value for the primary variable * @param pcs_pv value for primary variable, possible values are documented in enum PrimaryVariable */ - void setProcessPrimaryVariable (FiniteElement::PrimaryVariable pcs_pv); + void setProcessPrimaryVariable(FiniteElement::PrimaryVariable pcs_pv); /** * Sets the value for the pointer to an object of class CRFProcess. * @param pcs the pointer to an object of class CRFProcess */ - void setProcess (CRFProcess* pcs); + void setProcess(CRFProcess* pcs); /** * Get the process type. * @return the process type */ - FiniteElement::ProcessType getProcessType () const; + FiniteElement::ProcessType getProcessType() const; /** * Get the primary variable of the process. * @return the primary variable of the process */ - FiniteElement::PrimaryVariable getProcessPrimaryVariable () const; + FiniteElement::PrimaryVariable getProcessPrimaryVariable() const; - /** CB - * Get the comp vec index of the process. - * @Return the comp vec index of the process - */ - int getProcessCompVecIndex () const; - - - /** - * Get a pointer to an object of type CRFProcess. - * @return a pointer to an object of type CRFProcess + /** CB + * Get the comp vec index of the process. + * @Return the comp vec index of the process */ - CRFProcess* getProcess () const; + int getProcessCompVecIndex() const; + + /** + * Get a pointer to an object of type CRFProcess. + * @return a pointer to an object of type CRFProcess + */ + CRFProcess* getProcess() const; virtual ~ProcessInfo(); @@ -103,4 +102,4 @@ class ProcessInfo */ CRFProcess* _pcs; }; -#endif /* PROCESSINFO_H_ */ +#endif /* PROCESSINFO_H_ */ diff --git a/FEM/SourceTerm.cpp b/FEM/SourceTerm.cpp index 042ebc856..e7fbf9592 100644 --- a/FEM/SourceTerm.cpp +++ b/FEM/SourceTerm.cpp @@ -12,42 +12,41 @@ #include "SourceTerm.h" #include "rf_st_new.h" -SourceTerm::SourceTerm(const CSourceTerm &st, const std::string &geometry_name) - : FEMCondition(geometry_name, st.getProcessType(), st.getProcessPrimaryVariable(), - st.getGeoType(), st.getGeoName(), - st.getProcessDistributionType(), FEMCondition::SOURCE_TERM) +SourceTerm::SourceTerm(const CSourceTerm& st, const std::string& geometry_name) + : FEMCondition(geometry_name, st.getProcessType(), st.getProcessPrimaryVariable(), st.getGeoType(), st.getGeoName(), + st.getProcessDistributionType(), FEMCondition::SOURCE_TERM) { - if (this->getProcessDistributionType() == FiniteElement::CONSTANT || - this->getProcessDistributionType() == FiniteElement::CONSTANT_NEUMANN) + if (this->getProcessDistributionType() == FiniteElement::CONSTANT + || this->getProcessDistributionType() == FiniteElement::CONSTANT_NEUMANN) this->setConstantDisValue(st.getGeoNodeValue()); - else if (this->getProcessDistributionType() == FiniteElement::LINEAR || - this->getProcessDistributionType() == FiniteElement::LINEAR_NEUMANN) + else if (this->getProcessDistributionType() == FiniteElement::LINEAR + || this->getProcessDistributionType() == FiniteElement::LINEAR_NEUMANN) { const std::vector st_nodes(st.getPointsWithDistribedST()); std::vector dis_nodes(st_nodes.size()); - for (size_t i=0; i(st_nodes[i]); + for (size_t i = 0; i < dis_nodes.size(); i++) + dis_nodes[i] = static_cast(st_nodes[i]); this->setDisValues(dis_nodes, st.getDistribedST()); } else if (this->getProcessDistributionType() == FiniteElement::DIRECT - || this->getProcessDistributionType() == FiniteElement::RECHARGE_DIRECT) + || this->getProcessDistributionType() == FiniteElement::RECHARGE_DIRECT) { - //this->_direct_file_name = st.fname; + // this->_direct_file_name = st.fname; } else - std::cout << "Error in SourceTerm() - Unknown Process Distribution Type \"" << - FiniteElement::convertDisTypeToString(st.getProcessDistributionType()) << - "\"..." << - "\n"; + std::cout << "Error in SourceTerm() - Unknown Process Distribution Type \"" + << FiniteElement::convertDisTypeToString(st.getProcessDistributionType()) << "\"..." + << "\n"; } // Legacy function (only required for ascii st-files): reads values for 'direct' source terms -void SourceTerm::getDirectNodeValues(const std::string &filename, - std::vector< std::pair > &node_values) +void SourceTerm::getDirectNodeValues(const std::string& filename, std::vector >& node_values) { std::ifstream in(filename.c_str()); if (!in.is_open()) { - std::cout << "Error in getNodeValues() - Could not find file for direct node values..." << "\n"; + std::cout << "Error in getNodeValues() - Could not find file for direct node values..." + << "\n"; return; } @@ -56,7 +55,7 @@ void SourceTerm::getDirectNodeValues(const std::string &filename, size_t idx(0); double val(0); - while ( getline(in, line) ) + while (getline(in, line)) { if (line.find("#STOP") != std::string::npos) return; diff --git a/FEM/SourceTerm.h b/FEM/SourceTerm.h index 950cf71f2..5a0349feb 100644 --- a/FEM/SourceTerm.h +++ b/FEM/SourceTerm.h @@ -21,22 +21,19 @@ class SourceTerm : public FEMCondition { public: - SourceTerm(const std::string &geometry_name) - : FEMCondition(geometry_name, FEMCondition::SOURCE_TERM), _tim_type(0) {} - SourceTerm(const CSourceTerm &st, const std::string &geometry_name); - SourceTerm(const FEMCondition &cond) - : FEMCondition(cond, FEMCondition::SOURCE_TERM) {}; + SourceTerm(const std::string& geometry_name) : FEMCondition(geometry_name, FEMCondition::SOURCE_TERM), _tim_type(0) + { + } + SourceTerm(const CSourceTerm& st, const std::string& geometry_name); + SourceTerm(const FEMCondition& cond) : FEMCondition(cond, FEMCondition::SOURCE_TERM){}; ~SourceTerm() {} - - size_t getTimType() const {return _tim_type; } + size_t getTimType() const { return _tim_type; } void setTimType(size_t value) { _tim_type = value; } - // Legacy function (only required for ascii st-files): reads values for 'direct' source terms - static void getDirectNodeValues(const std::string &filename, - std::vector< std::pair > &nodes_values); + static void getDirectNodeValues(const std::string& filename, std::vector >& nodes_values); private: size_t _tim_type; }; -#endif //SOURCETERM_H +#endif // SOURCETERM_H diff --git a/FEM/SparseMatrixDOK.cpp b/FEM/SparseMatrixDOK.cpp index 392cbdaac..8ef3b5d85 100644 --- a/FEM/SparseMatrixDOK.cpp +++ b/FEM/SparseMatrixDOK.cpp @@ -15,8 +15,8 @@ #include #include "SparseMatrixDOK.h" -namespace Math_Group { - +namespace Math_Group +{ // SparseMatrixDOK //:Matrix(0) SparseMatrixDOK::SparseMatrixDOK(size_t _nrows, size_t _ncols) @@ -24,7 +24,7 @@ SparseMatrixDOK::SparseMatrixDOK(size_t _nrows, size_t _ncols) nrows = _nrows; ncols = _ncols; size = nrows * ncols; - //data = new double[dim]; + // data = new double[dim]; nrows0 = nrows; ncols0 = ncols; // for(int i=0; imat_row.end(); - for (ii = this->mat_row.begin(); ii != row_end; ii++) { + for (ii = this->mat_row.begin(); ii != row_end; ii++) + { const col_iter col_end = (*ii).end(); - for (jj = (*ii).begin(); jj != col_end; jj++) { + for (jj = (*ii).begin(); jj != col_end; jj++) + { // for(jj=(*ii).second.begin(); jj!=(*ii).second.end(); jj++){ (*jj).second = a; } @@ -134,8 +139,10 @@ void SparseMatrixDOK::operator*=(double a) row_iter ii; col_iter jj; - for (ii = this->mat_row.begin(); ii != this->mat_row.end(); ii++) { - for (jj = (*ii).begin(); jj != (*ii).end(); jj++) { + for (ii = this->mat_row.begin(); ii != this->mat_row.end(); ii++) + { + for (jj = (*ii).begin(); jj != (*ii).end(); jj++) + { // for(jj=(*ii).second.begin(); jj!=(*ii).second.end(); jj++){ (*jj).second *= a; } @@ -147,9 +154,11 @@ void SparseMatrixDOK::operator+=(double a) col_iter jj; const row_iter row_end = this->mat_row.end(); - for (ii = this->mat_row.begin(); ii != row_end; ii++) { + for (ii = this->mat_row.begin(); ii != row_end; ii++) + { const col_iter col_end = (*ii).end(); - for (jj = (*ii).begin(); jj != col_end; jj++) { + for (jj = (*ii).begin(); jj != col_end; jj++) + { // for(jj=(*ii).second.begin(); jj!=(*ii).second.end(); jj++){ (*jj).second += a; } @@ -160,65 +169,70 @@ void SparseMatrixDOK::operator+=(double a) void SparseMatrixDOK::operator=(const SparseMatrixDOK& m) { #ifdef gDEBUG - if(nrows!=m.Rows()||ncols!=m.Cols()) + if (nrows != m.Rows() || ncols != m.Cols()) { - cout<<"\n The sizes of the two matrices are not matched"<<"\n"; + cout << "\n The sizes of the two matrices are not matched" + << "\n"; abort(); } #endif - const mat_t &tmp_mat = m.mat_row; - col_t *col; + const mat_t& tmp_mat = m.mat_row; + col_t* col; mat_t::const_iterator ii; col_t::const_iterator jj; - //for(ii=tmp_mat.begin(); ii!=tmp_mat.end(); ii++){ + // for(ii=tmp_mat.begin(); ii!=tmp_mat.end(); ii++){ // for(jj=(*ii).second.begin(); jj!=(*ii).second.end(); jj++){ // this->mat[(*ii).first][(*jj).first] = (*jj).second; // } //} - for (size_t i = 0; i < this->nrows; i++) { - col = const_cast (&tmp_mat[i]); - for (jj = col->begin(); jj != col->end(); jj++) { + for (size_t i = 0; i < this->nrows; i++) + { + col = const_cast(&tmp_mat[i]); + for (jj = col->begin(); jj != col->end(); jj++) + { this->mat_row[i][(*jj).first] = (*jj).second; } } - } // void SparseMatrixDOK::operator+=(const SparseMatrixDOK& m) { #ifdef gDEBUG - if(nrows!=m.Rows()) + if (nrows != m.Rows()) { - cout<<"\n The sizes of the two matrices are not matched"<<"\n"; + cout << "\n The sizes of the two matrices are not matched" + << "\n"; abort(); } #endif - const mat_t &tmp_mat = m.mat_row; - //col_t *col; - //mat_t::const_iterator ii; - //col_t::const_iterator jj; + const mat_t& tmp_mat = m.mat_row; + // col_t *col; + // mat_t::const_iterator ii; + // col_t::const_iterator jj; - //for(ii=m.mat.begin(); ii!=m.mat.end(); ii++){ + // for(ii=m.mat.begin(); ii!=m.mat.end(); ii++){ // for(jj=(*ii).second.begin(); jj!=(*ii).second.end(); jj++){ // this->mat[(*ii).first][(*jj).first] += (*jj).second; // } //} - const long n_rows = (long) this->nrows; + const long n_rows = (long)this->nrows; #ifdef _OPENMP -#pragma omp parallel for //default(none) //shared(tmp_mat) +#pragma omp parallel for // default(none) //shared(tmp_mat) #endif - for (long i = 0; i < n_rows; i++) { - col_t &this_col = this->mat_row[i]; - const col_t *col = const_cast (&tmp_mat[i]); - const col_t::const_iterator &col_end = col->end(); + for (long i = 0; i < n_rows; i++) + { + col_t& this_col = this->mat_row[i]; + const col_t* col = const_cast(&tmp_mat[i]); + const col_t::const_iterator& col_end = col->end(); - for (col_t::const_iterator jj = col->begin(); jj != col_end; jj++) { + for (col_t::const_iterator jj = col->begin(); jj != col_end; jj++) + { this_col[(*jj).first] += (*jj).second; - //this->mat_row[i][(*jj).first] += (*jj).second; + // this->mat_row[i][(*jj).first] += (*jj).second; } } } @@ -227,39 +241,42 @@ void SparseMatrixDOK::operator+=(const SparseMatrixDOK& m) void SparseMatrixDOK::operator-=(const SparseMatrixDOK& m) { #ifdef gDEBUG - if(nrows!=m.Rows()) //Assertion, will be removed + if (nrows != m.Rows()) // Assertion, will be removed { - cout<<"\n The sizes of the two matrices are not matched"<<"\n"; + cout << "\n The sizes of the two matrices are not matched" + << "\n"; abort(); } #endif - const mat_t &tmp_mat = m.mat_row; - col_t *col; + const mat_t& tmp_mat = m.mat_row; + col_t* col; mat_t::const_iterator ii; col_t::const_iterator jj; - //for(ii=m.mat.begin(); ii!=m.mat.end(); ii++){ + // for(ii=m.mat.begin(); ii!=m.mat.end(); ii++){ // for(jj=(*ii).second.begin(); jj!=(*ii).second.end(); jj++){ // this->mat[(*ii).first][(*jj).first] -= (*jj).second; // } //} - for (size_t i = 0; i < this->nrows; i++) { - col = const_cast (&tmp_mat[i]); - for (jj = col->begin(); jj != col->end(); jj++) { + for (size_t i = 0; i < this->nrows; i++) + { + col = const_cast(&tmp_mat[i]); + for (jj = col->begin(); jj != col->end(); jj++) + { this->mat_row[i][(*jj).first] -= (*jj).second; } } - } // -//const +// const double& SparseMatrixDOK::operator()(size_t i, size_t j) { #ifdef gDEBUG - if(i>=nrows||j>=nrows) + if (i >= nrows || j >= nrows) { - cout<<"\n Index exceeds the size of the matrix"<<"\n"; + cout << "\n Index exceeds the size of the matrix" + << "\n"; abort(); } #endif @@ -270,26 +287,28 @@ double& SparseMatrixDOK::operator()(size_t i, size_t j) double SparseMatrixDOK::operator()(size_t i, size_t j) const { #ifdef gDEBUG - if(i>=nrows||j>=nrows) + if (i >= nrows || j >= nrows) { - cout<<"\n Index exceeds the size of the matrix"<<"\n"; + cout << "\n Index exceeds the size of the matrix" + << "\n"; abort(); } #endif col_t::const_iterator ii = mat_row[i].find(j); - if (ii!=mat_row[i].end()) + if (ii != mat_row[i].end()) return ii->second; else return .0; } -double& SparseMatrixDOK::operator()(size_t i) //const +double& SparseMatrixDOK::operator()(size_t i) // const { #ifdef gDEBUG - if(i>=size) + if (i >= size) { - cout<<"\n Index exceeds the size of the matrix"<<"\n"; + cout << "\n Index exceeds the size of the matrix" + << "\n"; abort(); } #endif @@ -300,9 +319,10 @@ double& SparseMatrixDOK::operator()(size_t i) //const void SparseMatrixDOK::LimitSize(size_t nRows, size_t nCols) { #ifdef gDEBUG - if(nRows>nrows0||nCols>ncols0) + if (nRows > nrows0 || nCols > ncols0) { - cout<<"\n Given size exceeds the original size of the matrix"<<"\n"; + cout << "\n Given size exceeds the original size of the matrix" + << "\n"; abort(); } #endif @@ -323,41 +343,44 @@ void SparseMatrixDOK::CalculateNonZeroEntries() long cnt = 0; - for (ii = this->mat_row.begin(); ii != this->mat_row.end(); ii++) { + for (ii = this->mat_row.begin(); ii != this->mat_row.end(); ii++) + { cnt += (*ii).size(); } non_zero_entry_size = cnt; } -/*****************************************************************//** - Set - A(ii,ii) = x_i, - A(ii, j) = 0., j!=ii - A(i, ii) = 0., i!=ii - b_i -= A(i,k)b_k // b_k is given - Programm: - 10/2007 WW - ********************************************************************/ -void SparseMatrixDOK::Diagonize(size_t idiag, const double b_given, double *b) +/*****************************************************************/ /** + Set + A(ii,ii) = x_i, + A(ii, j) = 0., j!=ii + A(i, ii) = 0., i!=ii + b_i -= A(i,k)b_k // b_k is given + Programm: + 10/2007 WW + ********************************************************************/ +void SparseMatrixDOK::Diagonize(size_t idiag, const double b_given, double* b) { row_iter ii; col_iter jj; - if (!this->is_constructed) { - std::cout - << "-> Constructing colmun info in SparseMatrixDOK::Diagonize()" - << "\n"; + if (!this->is_constructed) + { + std::cout << "-> Constructing colmun info in SparseMatrixDOK::Diagonize()" + << "\n"; const size_t n_rows = this->mat_row.size(); - for (size_t i = 0; i < n_rows; i++) { - col_t &i_mat = this->mat_row[i]; + for (size_t i = 0; i < n_rows; i++) + { + col_t& i_mat = this->mat_row[i]; col_t::const_iterator itr_end = i_mat.end(); //#ifdef USE_HASHMAP // const col_id_itr colid_end = set_col_id[cnt_rows].end(); // for(col_id_itr kk=set_col_id[cnt_rows].begin(); kk!=colid_end; kk++){ // jj = ii->find(*kk); //#else - for (jj = i_mat.begin(); jj != itr_end; jj++) { + for (jj = i_mat.begin(); jj != itr_end; jj++) + { //#endif this->mat_col[(*jj).first].push_back(i); } @@ -367,26 +390,32 @@ void SparseMatrixDOK::Diagonize(size_t idiag, const double b_given, double *b) double vdiag = .0; - col_t &i_mat = this->mat_row[idiag]; - for (jj = i_mat.begin(); jj != i_mat.end(); jj++) { - if ((*jj).first == idiag) { + col_t& i_mat = this->mat_row[idiag]; + for (jj = i_mat.begin(); jj != i_mat.end(); jj++) + { + if ((*jj).first == idiag) + { vdiag = (*jj).second; - } else { + } + else + { (*jj).second = 0.0; } } mat_col_t::iterator itr_col_diag = this->mat_col.begin() + idiag; const size_t n_itr_col_diag = itr_col_diag->size(); - for (size_t i = 0; i < n_itr_col_diag; i++) { + for (size_t i = 0; i < n_itr_col_diag; i++) + { size_t row_id = (*itr_col_diag)[i]; - if (row_id == idiag) continue; + if (row_id == idiag) + continue; jj = this->mat_row[row_id].find(idiag); b[row_id] -= (*jj).second * b_given; (*jj).second = 0.0; } - //for (size_t i=0; imat_row.size(); i++) { + // for (size_t i=0; imat_row.size(); i++) { // if (i==idiag) continue; // col_t &i_mat = this->mat_row[i]; // for(jj=i_mat.begin(); jj!=i_mat.end(); jj++){ @@ -402,62 +431,68 @@ void SparseMatrixDOK::Diagonize(size_t idiag, const double b_given, double *b) b[idiag] = vdiag * b_given; } -void SparseMatrixDOK::multiVec(double *vec_s, double *vec_r) +void SparseMatrixDOK::multiVec(double* vec_s, double* vec_r) { - (void) vec_s; // unused - (void) vec_r; // unused - std::cout - << "***ERROR: SparseMatrixDOK::multiVec() is not implemented yet." - << "\n"; + (void)vec_s; // unused + (void)vec_r; // unused + std::cout << "***ERROR: SparseMatrixDOK::multiVec() is not implemented yet." + << "\n"; } -void SparseMatrixDOK::Write(std::ostream &os, int format) +void SparseMatrixDOK::Write(std::ostream& os, int format) { row_iter ii; col_iter jj; #ifdef USE_HASHMAP - if (this->set_col_id.size()==0) - this->ConstructSortedColumnID(); + if (this->set_col_id.size() == 0) + this->ConstructSortedColumnID(); #endif // - if (format == 0) { - os << "*** Non-zero entries of matrix: " << "\n"; - //os.width(25); - //os.precision(10); + if (format == 0) + { + os << "*** Non-zero entries of matrix: " + << "\n"; + // os.width(25); + // os.precision(10); os.setf(std::ios_base::scientific, std::ios_base::floatfield); os.precision(20); - for (size_t i = 0; i < this->mat_row.size(); i++) { + for (size_t i = 0; i < this->mat_row.size(); i++) + { #ifdef USE_HASHMAP - for(col_id_itr kk=set_col_id[i].begin(); kk!=set_col_id[i].end(); kk++) + for (col_id_itr kk = set_col_id[i].begin(); kk != set_col_id[i].end(); kk++) { jj = this->mat_row[i].find(*kk); #else - for (jj = this->mat_row[i].begin(); jj != this->mat_row[i].end(); jj++) { + for (jj = this->mat_row[i].begin(); jj != this->mat_row[i].end(); jj++) + { #endif - os << std::setw(10) << i + 1 << " " << std::setw(10) - << (*jj).first + 1 << " " << std::setw(15) - << (*jj).second << "\n"; + os << std::setw(10) << i + 1 << " " << std::setw(10) << (*jj).first + 1 << " " << std::setw(15) + << (*jj).second << "\n"; } } os.unsetf(std::ios_base::scientific); // } // - else if (format == 1) { + else if (format == 1) + { os << Dim() << "\n"; os.setf(std::ios::scientific); - //os.width(25); + // os.width(25); os.precision(10); - for (size_t i = 0; i < this->mat_row.size(); i++) { - for (size_t j = 0; j < this->mat_row.size(); j++) { + for (size_t i = 0; i < this->mat_row.size(); i++) + { + for (size_t j = 0; j < this->mat_row.size(); j++) + { jj = this->mat_row[i].find(j); double v = 0.0; - if (jj != this->mat_row[i].end()) { + if (jj != this->mat_row[i].end()) + { v = jj->second; } os << v << " "; @@ -474,22 +509,27 @@ bool SparseMatrixDOK::IsSymmetry() col_iter jj, jj2; #define ZERO_TOLERANCE 1.E-6 // - for (size_t i = 0; i < this->mat_row.size(); i++) { - for (jj = this->mat_row[i].begin(); jj != this->mat_row[i].end(); jj++) { - if (jj->first < i) continue; + for (size_t i = 0; i < this->mat_row.size(); i++) + { + for (jj = this->mat_row[i].begin(); jj != this->mat_row[i].end(); jj++) + { + if (jj->first < i) + continue; jj2 = this->mat_row[jj->first].find(i); - if (jj2 != this->mat_row[jj->first].end()) { + if (jj2 != this->mat_row[jj->first].end()) + { double diff = jj->second - jj2->second; - //if (jj->second != jj2->second) { - if (fabs(diff) > ZERO_TOLERANCE) { - std::cout << "->unsymmetry: " << i << " - " << jj->first - << "\n"; + // if (jj->second != jj2->second) { + if (fabs(diff) > ZERO_TOLERANCE) + { + std::cout << "->unsymmetry: " << i << " - " << jj->first << "\n"; return false; } //} else if (jj->second!=0.0) { - } else { - std::cout << "->unsymmetry: " << i << " - " << jj->first - << "\n"; + } + else + { + std::cout << "->unsymmetry: " << i << " - " << jj->first << "\n"; return false; } } @@ -501,36 +541,37 @@ bool SparseMatrixDOK::IsSymmetry() #ifdef USE_HASHMAP void SparseMatrixDOK::ConstructSortedColumnID() { - if (this->set_col_id.size()>0) + if (this->set_col_id.size() > 0) { - cout << "->SparseMatrixDOK::ConstructSortedColumnID() - Already sorted" << "\n"; + cout << "->SparseMatrixDOK::ConstructSortedColumnID() - Already sorted" + << "\n"; return; } - cout << "->SparseMatrixDOK::ConstructSortedColumnID()" << "\n"; + cout << "->SparseMatrixDOK::ConstructSortedColumnID()" + << "\n"; // Construct list of sorted col id const size_t n_row = this->mat_row.size(); this->set_col_id.resize(n_row); - for (size_t i=0; imat_row[i].end(); - col_id_t &colid = this->set_col_id[i]; - for(col_iter jj=this->mat_row[i].begin(); jj!=col_end; jj++) + col_id_t& colid = this->set_col_id[i]; + for (col_iter jj = this->mat_row[i].begin(); jj != col_end; jj++) { colid.insert((*jj).first); } } - } #endif #if defined(LIS) || defined(MKL) void SparseMatrixDOK::ConstructCRSstructure() { - // +// #ifdef USE_HASHMAP - if (this->set_col_id.size()==0) - this->ConstructSortedColumnID(); + if (this->set_col_id.size() == 0) + this->ConstructSortedColumnID(); #endif // ptr: an integer array with a length of n + 1, which stores the starting @@ -541,46 +582,45 @@ void SparseMatrixDOK::ConstructCRSstructure() const long total_matrix_length = nrows; const long total_matrix_entry_size = non_zero_entry_size; - this->ptr = new int[total_matrix_length+1]; + this->ptr = new int[total_matrix_length + 1]; this->col_idx = new int[total_matrix_entry_size]; this->entry_index = new int[total_matrix_entry_size]; long counter_ptr = 0, counter_col_idx = 0; - long J,K; + long J, K; row_iter ii; col_iter jj; long cnt_row = 0; - for (ii=this->mat_row.begin(); ii!=this->mat_row.end(); ii++) + for (ii = this->mat_row.begin(); ii != this->mat_row.end(); ii++) { ptr[cnt_row++] = counter_ptr; // starting point of the row #ifdef USE_HASHMAP - col_id_t &colid = this->set_col_id[cnt_row-1]; - for (col_id_itr kk=colid.begin(); kk!=colid.end(); kk++) + col_id_t& colid = this->set_col_id[cnt_row - 1]; + for (col_id_itr kk = colid.begin(); kk != colid.end(); kk++) { jj = ii->find(*kk); #else - for (jj=(*ii).begin(); jj!=(*ii).end(); jj++) - { + for (jj = (*ii).begin(); jj != (*ii).end(); jj++) + { #endif - J = (*jj).first; // column in global matrix - K = counter_ptr; // index in entry + J = (*jj).first; // column in global matrix + K = counter_ptr; // index in entry - this->col_idx[counter_col_idx] = J; - this->entry_index[counter_col_idx] = K; + this->col_idx[counter_col_idx] = J; + this->entry_index[counter_col_idx] = K; - ++counter_ptr; - ++counter_col_idx; - } + ++counter_ptr; + ++counter_col_idx; } - ptr[total_matrix_length] = counter_ptr; - } + ptr[total_matrix_length] = counter_ptr; +} int SparseMatrixDOK::GetCRSValue(double* v) { - int success =1; + int success = 1; row_iter ii; col_iter jj; @@ -589,25 +629,25 @@ int SparseMatrixDOK::GetCRSValue(double* v) const row_iter row_end = this->mat_row.end(); - for(ii=this->mat_row.begin(); ii!=row_end; ii++) + for (ii = this->mat_row.begin(); ii != row_end; ii++) { #ifdef USE_HASHMAP const col_id_itr colid_end = set_col_id[cnt_rows].end(); - for(col_id_itr kk=set_col_id[cnt_rows].begin(); kk!=colid_end; kk++) + for (col_id_itr kk = set_col_id[cnt_rows].begin(); kk != colid_end; kk++) { jj = ii->find(*kk); #else - const col_iter col_end = (*ii).end(); - for(jj=(*ii).begin(); jj!=col_end; jj++) - { + const col_iter col_end = (*ii).end(); + for (jj = (*ii).begin(); jj != col_end; jj++) + { #endif - v[cnt++] = (*jj).second; - } - cnt_rows++; + v[cnt++] = (*jj).second; } - - return success; + cnt_rows++; } + + return success; +} #endif } // end namespace Math_Group diff --git a/FEM/SparseMatrixDOK.h b/FEM/SparseMatrixDOK.h index c911de3fa..c4aacdfd0 100644 --- a/FEM/SparseMatrixDOK.h +++ b/FEM/SparseMatrixDOK.h @@ -17,17 +17,17 @@ #include #include - -namespace Math_Group { - +namespace Math_Group +{ /** Sparse matrix (type: Dictionary of keys) */ -class SparseMatrixDOK { +class SparseMatrixDOK +{ public: - //#define USE_HASHMAP +//#define USE_HASHMAP #ifdef USE_HASHMAP - typedef std::vector > mat_t; + typedef std::vector > mat_t; typedef stdext::hash_map col_t; - typedef std::vector> mat_id_t; + typedef std::vector > mat_id_t; typedef std::set col_id_t; typedef col_id_t::const_iterator col_id_itr; #else @@ -37,6 +37,7 @@ class SparseMatrixDOK { typedef mat_t::iterator row_iter; typedef col_t::iterator col_iter; typedef std::vector > mat_col_t; + protected: size_t nrows, nrows0; size_t ncols, ncols0; @@ -44,6 +45,7 @@ class SparseMatrixDOK { size_t non_zero_entry_size; bool Sym; bool is_constructed; + private: double dummy_zero; mat_t mat_row; @@ -58,60 +60,39 @@ class SparseMatrixDOK { SparseMatrixDOK(); explicit SparseMatrixDOK(const SparseMatrixDOK& m); - const mat_t& GetRawData() const - { - return mat_row; - } - - mat_t& GetRawData() - { - return mat_row; - } - ; + const mat_t& GetRawData() const { return mat_row; } + mat_t& GetRawData() { return mat_row; }; size_t SizeOfNonZeroEntries(); void CalculateNonZeroEntries(); - //void resize(const int dim); + // void resize(const int dim); virtual ~SparseMatrixDOK(); // Operators - SparseMatrixDOK& operator =(double a); - void operator *=(double a); - void operator +=(double a); - void operator =(const SparseMatrixDOK& m); - void operator +=(const SparseMatrixDOK& m); - void operator -=(const SparseMatrixDOK& m); - void multiVec(double *vec_s, double *vec_r); + SparseMatrixDOK& operator=(double a); + void operator*=(double a); + void operator+=(double a); + void operator=(const SparseMatrixDOK& m); + void operator+=(const SparseMatrixDOK& m); + void operator-=(const SparseMatrixDOK& m); + void multiVec(double* vec_s, double* vec_r); void LimitSize(size_t nRows, size_t nCols = 1); - void Diagonize(size_t idiag, const double b_given, double *b); + void Diagonize(size_t idiag, const double b_given, double* b); // Access to members - double& operator()(size_t i, size_t j); //const; - double operator() (size_t i, size_t j) const; //const; - double& operator()(size_t i); //const; - - size_t Rows() const - { - return nrows; - } - size_t Cols() const - { - return ncols; - } - size_t Size() const - { - return size; - } - size_t Dim() const - { - return nrows; - } - - void Write(std::ostream &os = std::cout, int format = 0); + double& operator()(size_t i, size_t j); // const; + double operator()(size_t i, size_t j) const; // const; + double& operator()(size_t i); // const; + + size_t Rows() const { return nrows; } + size_t Cols() const { return ncols; } + size_t Size() const { return size; } + size_t Dim() const { return nrows; } + void Write(std::ostream& os = std::cout, int format = 0); bool IsSymmetry(); -#if defined(LIS) || defined(MKL) // These two pointers are in need for Compressed Row Storage +#if defined(LIS) || defined(MKL) // These two pointers are in need for Compressed Row Storage int* ptr; int* col_idx; int* entry_index; diff --git a/FEM/SplitMPI_Communicator.cpp b/FEM/SplitMPI_Communicator.cpp index 1f23939c9..be3146492 100644 --- a/FEM/SplitMPI_Communicator.cpp +++ b/FEM/SplitMPI_Communicator.cpp @@ -12,52 +12,56 @@ MPI_Comm comm_DDC; bool SplitMPI_Communicator::CreateCommunicator(MPI_Comm comm_world, int np, int nb_ddc) { - int n_DDC; + int n_DDC; bool splitcomm; - if ((nb_ddc > 0) && (nb_ddc < np)){ //if the number of total cores is larger than the number of DDCs is the same, two new MPI groups will be generated will be generated + if ((nb_ddc > 0) && (nb_ddc < np)) + { // if the number of total cores is larger than the number of DDCs is the same, two new MPI groups will be +// generated will be generated #ifdef OGS_FEM_IPQC splitcomm = true; - n_DDC = nb_ddc; //number of ddc + n_DDC = nb_ddc; // number of ddc int DDC_ranks[n_DDC]; - for( int k = 0; k < n_DDC; k++ ){ - DDC_ranks[k]= k; + for (int k = 0; k < n_DDC; k++) + { + DDC_ranks[k] = k; } MPI_Comm comm_IPQC; MPI_Group group_base, group_DDC, group_IPQC; - //define MPI group and communicator for DDC related processes WH - MPI_Comm_group (comm_world, &group_base); - MPI_Group_incl (group_base, n_DDC, DDC_ranks, &group_DDC); //define group flow and mass transport - MPI_Comm_create (comm_world, group_DDC, &comm_DDC); + // define MPI group and communicator for DDC related processes WH + MPI_Comm_group(comm_world, &group_base); + MPI_Group_incl(group_base, n_DDC, DDC_ranks, &group_DDC); // define group flow and mass transport + MPI_Comm_create(comm_world, group_DDC, &comm_DDC); - //define MPI group and communicator for IPQC WH - MPI_Group_difference (group_base, group_DDC, &group_IPQC); - MPI_Comm_create (comm_world, group_IPQC, &comm_IPQC); + // define MPI group and communicator for IPQC WH + MPI_Group_difference(group_base, group_DDC, &group_IPQC); + MPI_Comm_create(comm_world, group_IPQC, &comm_IPQC); int myrank_IPQC, mysize_IPQC; - MPI_Group_size (group_DDC, &mysize); //WH - MPI_Group_rank (group_DDC, &myrank);//WH - MPI_Group_rank (group_IPQC, &myrank_IPQC); - MPI_Group_size (group_IPQC, &mysize_IPQC); - if (myrank_IPQC != MPI_UNDEFINED) //WH + MPI_Group_size(group_DDC, &mysize); // WH + MPI_Group_rank(group_DDC, &myrank); // WH + MPI_Group_rank(group_IPQC, &myrank_IPQC); + MPI_Group_size(group_IPQC, &mysize_IPQC); + if (myrank_IPQC != MPI_UNDEFINED) // WH std::cout << "After MPI_Init myrank_IPQC = " << myrank_IPQC << '\n'; - if (myrank != MPI_UNDEFINED) //WH + if (myrank != MPI_UNDEFINED) // WH std::cout << "After MPI_Init myrank_DDC = " << myrank << '\n'; - - if (myrank_IPQC != MPI_UNDEFINED) // ranks of group_IPQC will call to IPhreeqc - Call_IPhreeqc(); -#endif + if (myrank_IPQC != MPI_UNDEFINED) // ranks of group_IPQC will call to IPhreeqc + Call_IPhreeqc(); +#endif } - else { //if no -ddc is specified or the number of ddc is incorrect, make ddc = np, no new MPI groups willnot be generated; + else + { // if no -ddc is specified or the number of ddc is incorrect, make ddc = np, no new MPI groups willnot be + // generated; splitcomm = false; n_DDC = np; comm_DDC = comm_world; - MPI_Comm_size(comm_DDC,&mysize); - MPI_Comm_rank(comm_DDC,&myrank); + MPI_Comm_size(comm_DDC, &mysize); + MPI_Comm_rank(comm_DDC, &myrank); std::cout << "After MPI_Init myrank_DDC = " << myrank << '\n'; } @@ -68,34 +72,34 @@ bool SplitMPI_Communicator::CreateCommunicator(MPI_Comm comm_world, int np, int void SplitMPI_Communicator::Call_IPhreeqc(void) { int signal = 1; - for (; ;) { + for (;;) + { MPI_Status status; // signal: the length of the input character string from group_DDC MPI_Recv(&signal, 1, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status); - if (signal < 0) + if (signal < 0) break; - char string_DDC[signal+1]; - MPI_Recv(string_DDC, signal+1, MPI_CHAR, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, - &status); - std::stringstream input, output; + char string_DDC[signal + 1]; + MPI_Recv(string_DDC, signal + 1, MPI_CHAR, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status); + std::stringstream input, output; input << string_DDC; // call to IPhreeqc Call_IPQC(&input, &output); // prepare the output string std::string tmp = output.str(); - char message[tmp.length()+1]; - int strlength = tmp.length(); - for(std::size_t i=0; i - /* interne Deklarationen */ -double *dvector(long nl, long nh); -void free_dvector(double *v, long nl, long nh); -void stifbs(double y[], double dydx[], int nv, double *xx, double htry, double eps, - double yscal[], double *hdid, double *hnext, - void (*derivs)(double, double [], double [], int, long, double)); -void odeint(double ystart[], int nvar, double x1, double x2, double eps, double h1, - double hmin, double *hnext, int *nok, int *nbad, - void (*derivs)(double, double [], double [], int, long, double), - bool (*stifbs)(double [], double [], int, double *, double, double, double [], - double *, double *, void (*)(double, double [], double [], int, long, double)), - bool (*rkqs)(double [], double [], int, double *, double , double , double [], - double *, double *, void (*)(double , double [], double [], int, long, double), long), - long, int); - - +double* dvector(long nl, long nh); +void free_dvector(double* v, long nl, long nh); +void stifbs(double y[], double dydx[], int nv, double* xx, double htry, double eps, double yscal[], double* hdid, + double* hnext, void (*derivs)(double, double[], double[], int, long, double)); +void odeint(double ystart[], int nvar, double x1, double x2, double eps, double h1, double hmin, double* hnext, + int* nok, int* nbad, void (*derivs)(double, double[], double[], int, long, double), + bool (*stifbs)(double[], double[], int, double*, double, double, double[], double*, double*, + void (*)(double, double[], double[], int, long, double)), + bool (*rkqs)(double[], double[], int, double*, double, double, double[], double*, double*, + void (*)(double, double[], double[], int, long, double), long), + long, int); -double *dvector(long /*nl*/, long /*nh*/) +double* dvector(long /*nl*/, long /*nh*/) { // Removed std::cout << "Error: dvector not implemented!" << std::endl; return NULL; } - void free_dvector(double* /*v*/, long /*nl*/, long /*nh*/) { // Removed std::cout << "Error: free_dvector not implemented!" << std::endl; } - /* Input: y=current_conc, dydx=their_derivs, xx=current_time, htry=suggested_stepsize */ /* Ouput: y=updated_conc, xx=end_time, hdid=achieved_stepsize , hnext= estimated_next_ss */ -bool stifbs(double y[], double dydx[], int nv, double *xx, double htry, double eps, - double yscal[], double *hdid, double *hnext, - void (*derivs)(double, double [], double [], int, long, double), long node) +bool stifbs(double y[], double dydx[], int nv, double* xx, double htry, double eps, double yscal[], double* hdid, + double* hnext, void (*derivs)(double, double[], double[], int, long, double), long node) { // The following void type casting is just to supress warnings // Once this function is filled with using these arguments, these casting @@ -56,8 +48,8 @@ bool stifbs(double y[], double dydx[], int nv, double *xx, double htry, double e (void)y; (void)dydx; (void)nv; - (void)xx; - (void)htry; + (void)xx; + (void)htry; (void)eps; (void)yscal; (void)hdid; @@ -70,9 +62,8 @@ bool stifbs(double y[], double dydx[], int nv, double *xx, double htry, double e return false; } -bool rkqs(double y[], double dydx[], int n, double *x, double htry, double eps, - double yscal[], double *hdid, double *hnext, - void (*derivs)(double , double [], double [], int, long, double), long node) +bool rkqs(double y[], double dydx[], int n, double* x, double htry, double eps, double yscal[], double* hdid, + double* hnext, void (*derivs)(double, double[], double[], int, long, double), long node) { // The following void type casting is just to supress warnings // Once this function is filled with using these arguments, these casting @@ -80,8 +71,8 @@ bool rkqs(double y[], double dydx[], int n, double *x, double htry, double eps, (void)y; (void)dydx; (void)n; - (void)x; - (void)htry; + (void)x; + (void)htry; (void)eps; (void)yscal; (void)hdid; @@ -94,14 +85,13 @@ bool rkqs(double y[], double dydx[], int n, double *x, double htry, double eps, return false; } -bool odeint(double ystart[], int nvar, double x1, double x2, double eps, double h1, - double hmin, double *nexth, int *nok, int *nbad, - void (*derivs)(double, double [], double [], int, long, double), - bool (*stifbs)(double [], double [], int, double *, double, double, double [], - double *, double *, void (*)(double, double [], double [], int, long, double), long), - bool (*rkqs)(double [], double [], int, double *, double , double , double [], - double *, double *, void (*)(double , double [], double [], int, long, double),long), - long node, int SolverType) +bool odeint(double ystart[], int nvar, double x1, double x2, double eps, double h1, double hmin, double* nexth, + int* nok, int* nbad, void (*derivs)(double, double[], double[], int, long, double), + bool (*stifbs)(double[], double[], int, double*, double, double, double[], double*, double*, + void (*)(double, double[], double[], int, long, double), long), + bool (*rkqs)(double[], double[], int, double*, double, double, double[], double*, double*, + void (*)(double, double[], double[], int, long, double), long), + long node, int SolverType) { // The following void type casting is just to supress warnings // Once this function is filled with using these arguments, these casting @@ -109,8 +99,8 @@ bool odeint(double ystart[], int nvar, double x1, double x2, double eps, double (void)ystart; (void)nvar; (void)x1; - (void)x2; - (void)eps; + (void)x2; + (void)eps; (void)h1; (void)hmin; (void)nexth; diff --git a/FEM/Stiff_Bulirsch-Stoer.h b/FEM/Stiff_Bulirsch-Stoer.h old mode 100755 new mode 100644 index 7d76133e8..c1124ca33 --- a/FEM/Stiff_Bulirsch-Stoer.h +++ b/FEM/Stiff_Bulirsch-Stoer.h @@ -7,7 +7,7 @@ * */ - #ifndef STIFF_BULIRSCH_STOER +#ifndef STIFF_BULIRSCH_STOER #define STIFF_BULIRSCH_STOER /* Deklarationen */ diff --git a/FEM/SwitchBC.h b/FEM/SwitchBC.h index 755fd26ff..e7d20ed76 100644 --- a/FEM/SwitchBC.h +++ b/FEM/SwitchBC.h @@ -8,27 +8,21 @@ #ifndef FEM_SWITCHBC_H_ #define FEM_SWITCHBC_H_ - #include "FEMEnums.h" -struct SwitchBC { +struct SwitchBC +{ double switchValue; double switchOnValue; double switchOffValue; FiniteElement::ProcessType switchProcessType; FiniteElement::PrimaryVariable switchPrimVar; - - SwitchBC () : - switchValue(0.0), - switchOnValue(1.0), - switchOffValue(0.0), - switchProcessType(FiniteElement::INVALID_PROCESS), - switchPrimVar(FiniteElement::INVALID_PV) - {} - + SwitchBC() + : switchValue(0.0), switchOnValue(1.0), switchOffValue(0.0), switchProcessType(FiniteElement::INVALID_PROCESS), + switchPrimVar(FiniteElement::INVALID_PV) + { + } }; - - #endif /* FEM_SWITCHBC_H_ */ diff --git a/FEM/conversion_rate.cpp b/FEM/conversion_rate.cpp index 5518cb2a5..bd502fd4b 100644 --- a/FEM/conversion_rate.cpp +++ b/FEM/conversion_rate.cpp @@ -22,42 +22,40 @@ conversion_rate::conversion_rate(double T_solid, double phi_S, double delta_t, FiniteElement::SolidReactiveSystem system) - : R(PhysicalConstant::IdealGasConstant), - rho_s_0(rho_s_initial), - p_eq(1.0), - tol_l (1.0e-4), - tol_u (1.0 - tol_l), - tol_rho (0.1), - x(Eigen::VectorXd(1)) + : R(PhysicalConstant::IdealGasConstant), rho_s_0(rho_s_initial), p_eq(1.0), tol_l(1.0e-4), tol_u(1.0 - tol_l), + tol_rho(0.1), x(Eigen::VectorXd(1)) { - update_param( T_solid, T_gas, p_gas, x_reactive, rho_s_initial, phi_S, delta_t, system); + update_param(T_solid, T_gas, p_gas, x_reactive, rho_s_initial, phi_S, delta_t, system); - if (system == FiniteElement::CaOH2){ //Definition auch in void CSolidProperties::SetSolidReactiveSystemProperties() + if (system == FiniteElement::CaOH2) + { // Definition auch in void CSolidProperties::SetSolidReactiveSystemProperties() rho_low = 1656.0; rho_up = 2200.0; - reaction_enthalpy = -1.12e+05; //in J/mol; negative for exothermic composition reaction - reaction_entropy = -143.5; //in J/mol K + reaction_enthalpy = -1.12e+05; // in J/mol; negative for exothermic composition reaction + reaction_entropy = -143.5; // in J/mol K M_carrier = PhysicalConstant::MolarMass::N2; - M_react = PhysicalConstant::MolarMass::Water; + M_react = PhysicalConstant::MolarMass::Water; } - else if (system == FiniteElement::Mn3O4){//Definition auch in void CSolidProperties::SetSolidReactiveSystemProperties() + else if (system == FiniteElement::Mn3O4) + { // Definition auch in void CSolidProperties::SetSolidReactiveSystemProperties() rho_low = 4500.0; rho_up = 4860.0; - reaction_enthalpy = -1.376e+05; //in J/mol; negative for exothermic composition reaction - reaction_entropy = -114.1; //in J/mol K + reaction_enthalpy = -1.376e+05; // in J/mol; negative for exothermic composition reaction + reaction_entropy = -114.1; // in J/mol K M_carrier = PhysicalConstant::MolarMass::N2; - M_react = PhysicalConstant::MolarMass::O2; + M_react = PhysicalConstant::MolarMass::O2; } - else if (system == FiniteElement::Z13XBF){//Definition auch in void CSolidProperties::SetSolidReactiveSystemProperties() + else if (system == FiniteElement::Z13XBF) + { // Definition auch in void CSolidProperties::SetSolidReactiveSystemProperties() // TODO [CL] read those values from some input file rho_low = 1150.0; - rho_up = -1.0; //not needed - reaction_enthalpy = 0.0; //see CalcEnthalpy13XBF() - reaction_entropy = 0.0; //see CalcEntropy13XBF() - M_carrier = PhysicalConstant::MolarMass::N2; //consider switch to air - M_react = PhysicalConstant::MolarMass::Water; - W0 = 0.291/1.e3; //in m^3/kg - p_min = 0.0; //in Pa + rho_up = -1.0; // not needed + reaction_enthalpy = 0.0; // see CalcEnthalpy13XBF() + reaction_entropy = 0.0; // see CalcEntropy13XBF() + M_carrier = PhysicalConstant::MolarMass::N2; // consider switch to air + M_react = PhysicalConstant::MolarMass::Water; + W0 = 0.291 / 1.e3; // in m^3/kg + p_min = 0.0; // in Pa } } @@ -66,94 +64,94 @@ conversion_rate::~conversion_rate(void) } void conversion_rate::update_param(double T_solid, - double T_gas, - double p_gas, - double x_reactive, - double rho_s_initial, - double phi_S, - double delta_t, - FiniteElement::SolidReactiveSystem system) + double T_gas, + double p_gas, + double x_reactive, + double rho_s_initial, + double phi_S, + double delta_t, + FiniteElement::SolidReactiveSystem system) { - conversion_rate::T_s = T_solid; - conversion_rate::T = T_gas; - conversion_rate::p_gas = p_gas; // should be in unit bar - conversion_rate::x_react = x_reactive; - conversion_rate::rho_s = rho_s_initial; - x(0) = rho_s_initial; + conversion_rate::T_s = T_solid; + conversion_rate::T = T_gas; + conversion_rate::p_gas = p_gas; // should be in unit bar + conversion_rate::x_react = x_reactive; + conversion_rate::rho_s = rho_s_initial; + x(0) = rho_s_initial; conversion_rate::phi_solid = phi_S; - conversion_rate::dt = delta_t; + conversion_rate::dt = delta_t; conversion_rate::reaction_system = system; } -//determine equilibrium temperature and pressure according to van't Hoff +// determine equilibrium temperature and pressure according to van't Hoff void conversion_rate::set_chemical_equilibrium() { - X_D = (rho_s - rho_up - tol_rho)/(rho_low - rho_up - 2.0*tol_rho) ; - X_D = (X_D < 0.5) ? std::max(tol_l,X_D) : std::min(X_D,tol_u); //constrain to interval [tol_l;tol_u] + X_D = (rho_s - rho_up - tol_rho) / (rho_low - rho_up - 2.0 * tol_rho); + X_D = (X_D < 0.5) ? std::max(tol_l, X_D) : std::min(X_D, tol_u); // constrain to interval [tol_l;tol_u] X_H = 1.0 - X_D; - //calculate equilibrium + // calculate equilibrium // using the p_eq to calculate the T_eq - Clausius-Clapeyron - T_eq = (reaction_enthalpy/R) / ((reaction_entropy/R) + log(p_r_g)); // unit of p in bar - //Alternative: Use T_s as T_eq and calculate p_eq - for Schaube kinetics - p_eq = exp((reaction_enthalpy/R)/T_s - (reaction_entropy/R)); + T_eq = (reaction_enthalpy / R) / ((reaction_entropy / R) + log(p_r_g)); // unit of p in bar + // Alternative: Use T_s as T_eq and calculate p_eq - for Schaube kinetics + p_eq = exp((reaction_enthalpy / R) / T_s - (reaction_entropy / R)); } -//determine equilibrium loading according to Dubinin +// determine equilibrium loading according to Dubinin void conversion_rate::set_sorption_equilibrium() { - //determine adsorption potential + // determine adsorption potential const double A = get_potential(T_s, p_r_g); - //determine adsorbed volume + // determine adsorbed volume const double W = characteristic_curve(A); - //determine equilibrium loading - C_eq = W * get_adsorbate_density(T_s); //kg/kg + // determine equilibrium loading + C_eq = W * get_adsorbate_density(T_s); // kg/kg } double conversion_rate::get_mole_fraction(double xm) { - return M_carrier*xm/(M_carrier*xm + M_react*(1.0-xm)); - } + return M_carrier * xm / (M_carrier * xm + M_react * (1.0 - xm)); +} void conversion_rate::calculate_qR() { - //Convert mass fraction into mole fraction + // Convert mass fraction into mole fraction const double mol_frac_react = get_mole_fraction(x_react); switch (reaction_system) { - case FiniteElement::CaOH2: //Definition auch in void CSolidProperties::SetSolidReactiveSystemProperties() - { - p_r_g = std::max(mol_frac_react * p_gas, 1.0e-3); //avoid illdefined log - set_chemical_equilibrium(); - const double dXdt = Ca_hydration(); - qR = (rho_up - rho_low) * dXdt; - } + case FiniteElement::CaOH2: // Definition auch in void CSolidProperties::SetSolidReactiveSystemProperties() + { + p_r_g = std::max(mol_frac_react * p_gas, 1.0e-3); // avoid illdefined log + set_chemical_equilibrium(); + const double dXdt = Ca_hydration(); + qR = (rho_up - rho_low) * dXdt; + } break; - case FiniteElement::Mn3O4: //Definition auch in void CSolidProperties::SetSolidReactiveSystemProperties() - { - p_r_g = std::max(mol_frac_react * p_gas, 1.0e-3); //avoid illdefined log - set_chemical_equilibrium(); - const double dXdt = Mn_redox(); - qR = (rho_up - rho_low) * dXdt; - } + case FiniteElement::Mn3O4: // Definition auch in void CSolidProperties::SetSolidReactiveSystemProperties() + { + p_r_g = std::max(mol_frac_react * p_gas, 1.0e-3); // avoid illdefined log + set_chemical_equilibrium(); + const double dXdt = Mn_redox(); + qR = (rho_up - rho_low) * dXdt; + } break; - case FiniteElement::Z13XBF: - { - //partial pressure - p_r_g = std::max(mol_frac_react * p_gas * 1.0e5, p_min); //avoid illdefined log, gas pressure in Pa - set_sorption_equilibrium(); - const double dCdt = Z13XBF_adsorption(); - qR = rho_low * dCdt; - } + case FiniteElement::Z13XBF: + { + // partial pressure + p_r_g = std::max(mol_frac_react * p_gas * 1.0e5, p_min); // avoid illdefined log, gas pressure in Pa + set_sorption_equilibrium(); + const double dCdt = Z13XBF_adsorption(); + qR = rho_low * dCdt; + } break; - default: - qR = 0.; - break; + default: + qR = 0.; + break; } } @@ -172,51 +170,52 @@ void conversion_rate::get_x(Eigen::VectorXd& output_x) output_x = x; } - -void conversion_rate::eval(double /*t*/, Eigen::VectorXd const& y, Eigen::VectorXd &dydx) +void conversion_rate::eval(double /*t*/, Eigen::VectorXd const& y, Eigen::VectorXd& dydx) { - assert( y.size() == dydx.size() ); + assert(y.size() == dydx.size()); - set_rho_s( y(0) ); + set_rho_s(y(0)); calculate_qR(); dydx(0) = get_qR(); - } double conversion_rate::Ca_hydration() { double dXdt; - // step 3, calculate dX/dt +// step 3, calculate dX/dt #ifdef SIMPLE_KINETICS - if ( T_s < T_eq ) // hydration - simple model + if (T_s < T_eq) // hydration - simple model #else - if ( p_r_g > p_eq ) // hydration - Schaube model + if (p_r_g > p_eq) // hydration - Schaube model #endif { - //X_H = max(tol_l,X_H); //lower tolerance to avoid oscillations at onset of hydration reaction. Set here so that no residual reaction rate occurs at end of hydration. +// X_H = max(tol_l,X_H); //lower tolerance to avoid oscillations at onset of hydration reaction. Set here so that no +// residual reaction rate occurs at end of hydration. #ifdef SIMPLE_KINETICS // this is from P. Schmidt - dXdt = -1.0*(1.0-X_H) * (T_s - T_eq) / T_eq * 0.2 * conversion_rate::x_react; -#else //this is from Schaube + dXdt = -1.0 * (1.0 - X_H) * (T_s - T_eq) / T_eq * 0.2 * conversion_rate::x_react; +#else // this is from Schaube if (X_H == tol_u || rho_s == rho_up) dXdt = 0.0; - else if ( (T_eq-T_s) >= 50.0) - dXdt = 13945.0 * exp(-89486.0/R/T_s) * std::pow(p_r_g/p_eq - 1.0,0.83) * 3.0 * (X_D) * std::pow(-1.0*log(X_D),0.666); + else if ((T_eq - T_s) >= 50.0) + dXdt = 13945.0 * exp(-89486.0 / R / T_s) * std::pow(p_r_g / p_eq - 1.0, 0.83) * 3.0 + * (X_D)*std::pow(-1.0 * log(X_D), 0.666); else - dXdt = 1.0004e-34 * exp(5.3332e4/T_s) * std::pow(p_r_g, 6.0) * (X_D); + dXdt = 1.0004e-34 * exp(5.3332e4 / T_s) * std::pow(p_r_g, 6.0) * (X_D); #endif } else // dehydration { - //X_D = max(tol_l,X_D); //lower tolerance to avoid oscillations at onset of dehydration reaction. Set here so that no residual reaction rate occurs at end of dehydration. +// X_D = max(tol_l,X_D); //lower tolerance to avoid oscillations at onset of dehydration reaction. Set here so that no +// residual reaction rate occurs at end of dehydration. #ifdef SIMPLE_KINETICS // this is from P. Schmidt - dXdt = -1.0* (1.0-X_D) * (T_s - T_eq) / T_eq * 0.05; + dXdt = -1.0 * (1.0 - X_D) * (T_s - T_eq) / T_eq * 0.05; #else if (X_D == tol_u || rho_s == rho_low) dXdt = 0.0; else if (X_D < 0.2) - dXdt = -1.9425e12 * exp( -1.8788e5/R/T_s ) * std::pow(1.0-p_r_g/p_eq,3.0)*(X_H); + dXdt = -1.9425e12 * exp(-1.8788e5 / R / T_s) * std::pow(1.0 - p_r_g / p_eq, 3.0) * (X_H); else - dXdt = -8.9588e9 * exp( -1.6262e5/R/T_s ) * std::pow(1.0-p_r_g/p_eq,3.0)*2.0 * std::pow(X_H, 0.5); + dXdt = -8.9588e9 * exp(-1.6262e5 / R / T_s) * std::pow(1.0 - p_r_g / p_eq, 3.0) * 2.0 * std::pow(X_H, 0.5); #endif } return dXdt; @@ -226,13 +225,15 @@ double conversion_rate::Mn_redox() { double dXdt, Avrami; - if ( T_s < T_eq ) // oxidation + if (T_s < T_eq) // oxidation { if (X_H == tol_u || rho_s == rho_up) dXdt = 0.0; - else{ + else + { Avrami = 282.277 - 0.912 * T_s + 9.949e-4 * T_s * T_s - 3.620e-7 * T_s * T_s * T_s; - dXdt = 55271.0 * exp(-95.493e3 / (R * T_s)) * Avrami * (X_D) * std::pow(-1.0 * log(X_D),(Avrami - 1.0)/Avrami) * std::pow(1.0-T_s/T_eq,0.86); + dXdt = 55271.0 * exp(-95.493e3 / (R * T_s)) * Avrami + * (X_D)*std::pow(-1.0 * log(X_D), (Avrami - 1.0) / Avrami) * std::pow(1.0 - T_s / T_eq, 0.86); } if (p_r_g <= 1.0e-3) dXdt = 0.0; @@ -244,127 +245,139 @@ double conversion_rate::Mn_redox() return dXdt; } - double conversion_rate::Z13XBF_adsorption() { - const double k_rate = 6.0e-3; //to be specified - const double C = rho_s/rho_low - 1.; //current degree of loading - const double dCdt = k_rate * (C_eq - C); //scaled with mass fraction - if (dCdt > 0. && p_r_g < p_min*1.01) + const double k_rate = 6.0e-3; // to be specified + const double C = rho_s / rho_low - 1.; // current degree of loading + const double dCdt = k_rate * (C_eq - C); // scaled with mass fraction + if (dCdt > 0. && p_r_g < p_min * 1.01) return 0.; - //automatic time stepping should be used instead of the following. - //else if (dCdt > 0.) { + // automatic time stepping should be used instead of the following. + // else if (dCdt > 0.) { // double dens_guess = p_r_g*COMP_MOL_MASS_WATER/(R*T); //vapor density guess // //const double max_rate = dens_guess/(rho_low*dt); // //dCdt = min(dCdt,max_rate); //} return dCdt; - } -//Density model for water found in the works of Hauer +// Density model for water found in the works of Hauer double conversion_rate::get_adsorbate_density(const double Tads) { - //set reference state for adsorbate EOS in Hauer - const double T0 = 293.15, rho0 = 998.084, alpha0 = 2.06508e-4; //K; kg/m^3; 1/K + // set reference state for adsorbate EOS in Hauer + const double T0 = 293.15, rho0 = 998.084, alpha0 = 2.06508e-4; // K; kg/m^3; 1/K // double test = (rho0 * (1. - alpha0 * (Tads-T0))); - return (rho0 * (1. - alpha0 * (Tads-T0))); //in kg/m^3 + return (rho0 * (1. - alpha0 * (Tads - T0))); // in kg/m^3 } -//Thermal expansivity model for water found in the works of Hauer +// Thermal expansivity model for water found in the works of Hauer double conversion_rate::get_alphaT(const double Tads) { - //set reference state for adsorbate EOS in Hauer - const double T0 = 293.15, /*rho0 = 998.084,*/ alpha0 = 2.06508e-4; //K; kg/m^3; 1/K - return (alpha0/(1. - alpha0 * (Tads-T0))); //in 1/K + // set reference state for adsorbate EOS in Hauer + const double T0 = 293.15, /*rho0 = 998.084,*/ alpha0 = 2.06508e-4; // K; kg/m^3; 1/K + return (alpha0 / (1. - alpha0 * (Tads - T0))); // in 1/K } -//Saturation pressure for water used in Nunez +// Saturation pressure for water used in Nunez double conversion_rate::get_ps(const double Tads) { - //critical T and p - const double Tc = 647.3; //K - const double pc = 221.2e5; //Pa - //dimensionless T - const double Tr = Tads/Tc; + // critical T and p + const double Tc = 647.3; // K + const double pc = 221.2e5; // Pa + // dimensionless T + const double Tr = Tads / Tc; const double theta = 1. - Tr; - //empirical constants - const double c[] = {-7.69123,-26.08023,-168.17065,64.23285,-118.96462,4.16717,20.97506,1.0e9,6.0}; - const double K[] = {c[0]*theta + c[1]*pow(theta,2) + c[2]*pow(theta,3) + c[3]*pow(theta,4) + c[4]*pow(theta,5), - 1. + c[5]*theta + c[6]*pow(theta,2)}; - - const double exponent = K[0]/(K[1]*Tr) - theta/(c[7]*pow(theta,2) + c[8]); - return pc * exp(exponent); //in Pa + // empirical constants + const double c[] = {-7.69123, -26.08023, -168.17065, 64.23285, -118.96462, 4.16717, 20.97506, 1.0e9, 6.0}; + const double K[] + = {c[0] * theta + c[1] * pow(theta, 2) + c[2] * pow(theta, 3) + c[3] * pow(theta, 4) + c[4] * pow(theta, 5), + 1. + c[5] * theta + c[6] * pow(theta, 2)}; + + const double exponent = K[0] / (K[1] * Tr) - theta / (c[7] * pow(theta, 2) + c[8]); + return pc * exp(exponent); // in Pa } -//Evaporation enthalpy of water from Nunez -double conversion_rate::get_hv(double Tads) //in kJ/kg +// Evaporation enthalpy of water from Nunez +double conversion_rate::get_hv(double Tads) // in kJ/kg { Tads -= 273.15; - if (Tads <= 10.){ - const double c[] = {2.50052e3,-2.1068,-3.57500e-1,1.905843e-1,-5.11041e-2,7.52511e-3,-6.14313e-4,2.59674e-5,-4.421e-7}; + if (Tads <= 10.) + { + const double c[] = {2.50052e3, -2.1068, -3.57500e-1, 1.905843e-1, -5.11041e-2, + 7.52511e-3, -6.14313e-4, 2.59674e-5, -4.421e-7}; double hv = 0.; - for (size_t i=0; i< sizeof(c)/sizeof(c[0]);i++) + for (size_t i = 0; i < sizeof(c) / sizeof(c[0]); i++) hv += c[i] * std::pow(Tads, static_cast(i)); return hv; - } else if (Tads <= 300.){ - const double c[] = {2.50043e3,-2.35209,1.91685e-4,-1.94824e-5,2.89539e-7,-3.51199e-9,2.06926e-11,-6.4067e-14,8.518e-17,1.558e-20,-1.122e-22}; + } + else if (Tads <= 300.) + { + const double c[] = {2.50043e3, -2.35209, 1.91685e-4, -1.94824e-5, 2.89539e-7, -3.51199e-9, + 2.06926e-11, -6.4067e-14, 8.518e-17, 1.558e-20, -1.122e-22}; double hv = 0.; - for (size_t i=0; i< sizeof(c)/sizeof(c[0]);i++) + for (size_t i = 0; i < sizeof(c) / sizeof(c[0]); i++) hv += c[i] * std::pow(Tads, static_cast(i)); return hv; - } else { - const double c[] = {2.99866e3,-3.1837e-3,-1.566964e1,-2.514e-6,2.045933e-2,1.0389e-8}; - return ((c[0] + c[2]*Tads + c[4]*pow(Tads,2))/(1. + c[1]*Tads + c[3]*pow(Tads,2) + c[5]*pow(Tads,3))); + } + else + { + const double c[] = {2.99866e3, -3.1837e-3, -1.566964e1, -2.514e-6, 2.045933e-2, 1.0389e-8}; + return ((c[0] + c[2] * Tads + c[4] * pow(Tads, 2)) + / (1. + c[1] * Tads + c[3] * pow(Tads, 2) + c[5] * pow(Tads, 3))); } } - -//evaluate specific heat capacity of adsorbate follwing Nunez +// evaluate specific heat capacity of adsorbate follwing Nunez double conversion_rate::get_specific_heat_capacity(const double Tads) { - const double c[] = {4.224,-3.716e-3,9.351e-5,-7.1786e-7,-9.1266e-9,2.69247e-10,-2.773104e-12,1.553177e-14,-4.982795e-17,8.578e-20,-6.12423e-23}; + const double c[] = {4.224, -3.716e-3, 9.351e-5, -7.1786e-7, -9.1266e-9, 2.69247e-10, + -2.773104e-12, 1.553177e-14, -4.982795e-17, 8.578e-20, -6.12423e-23}; double cp = 0.; - for (unsigned i=0; i< sizeof(c)/sizeof(c[0]);i++) + for (unsigned i = 0; i < sizeof(c) / sizeof(c[0]); i++) cp += c[i] * std::pow(Tads, static_cast(i)); - return cp; //kJ/(kg*K) + return cp; // kJ/(kg*K) } -//Evaluate adsorbtion potential A +// Evaluate adsorbtion potential A double conversion_rate::get_potential(const double Tads, double pads) { pads = std::max(pads, p_min); - double A = R * Tads * log(get_ps(Tads)/pads) / (M_react*1.e3); //in kJ/kg = J/g - if (A < 0.0) { + double A = R * Tads * log(get_ps(Tads) / pads) / (M_react * 1.e3); // in kJ/kg = J/g + if (A < 0.0) + { // vapour partial pressure > saturation pressure // A = 0.0; // TODO [CL] debug output } return A; } -//Characteristic curve. Return W (A) +// Characteristic curve. Return W (A) double conversion_rate::characteristic_curve(const double A) { - //parameters from least squares fit (experimental data) - const double c[] = {0.34102920966608297, -0.0013106032830951296, -0.00060754147575378876, 3.7843404172683339e-07, 4.0107503869519016e-07, 3.1274595098338057e-10, -7.610441241719489e-11}; - double W = (c[0]+c[2]*A+c[4]*std::pow(A,2)+c[6]*std::pow(A,3))/(1.0+c[1]*A+c[3]*std::pow(A,2)+c[5]*std::pow(A,3)); //cm^3/g - if (W < 0.0) { + // parameters from least squares fit (experimental data) + const double c[] = {0.34102920966608297, -0.0013106032830951296, -0.00060754147575378876, 3.7843404172683339e-07, + 4.0107503869519016e-07, 3.1274595098338057e-10, -7.610441241719489e-11}; + double W = (c[0] + c[2] * A + c[4] * std::pow(A, 2) + c[6] * std::pow(A, 3)) + / (1.0 + c[1] * A + c[3] * std::pow(A, 2) + c[5] * std::pow(A, 3)); // cm^3/g + if (W < 0.0) + { W = 0.0; // TODO [CL] debug output } - return W/1.e3; //m^3/kg + return W / 1.e3; // m^3/kg } -//Calculate sorption entropy +// Calculate sorption entropy double conversion_rate::get_entropy(const double Tads, const double A) { const double epsilon = 1.0e-8; - const double dAdlnW = 2.0*epsilon/(log(characteristic_curve(A+epsilon)) - log(characteristic_curve(A-epsilon))); + const double dAdlnW + = 2.0 * epsilon / (log(characteristic_curve(A + epsilon)) - log(characteristic_curve(A - epsilon))); return dAdlnW * get_alphaT(Tads); } -//Calculate sorption enthalpy +// Calculate sorption enthalpy double conversion_rate::get_enthalpy(const double Tads, const double pads) { - const double A = get_potential(Tads,pads); - return (get_hv(Tads) + A - Tads * get_entropy(Tads,A))*1000.0; //in J/kg + const double A = get_potential(Tads, pads); + return (get_hv(Tads) + A - Tads * get_entropy(Tads, A)) * 1000.0; // in J/kg } diff --git a/FEM/conversion_rate.h b/FEM/conversion_rate.h index f088540a4..07c40dd7d 100644 --- a/FEM/conversion_rate.h +++ b/FEM/conversion_rate.h @@ -17,13 +17,13 @@ class conversion_rate { public: conversion_rate(double T_solid, - double T_gas, - double p_gas, - double w_water, - double rho_s_initial, - double phi_S, - double delta_t, - FiniteElement::SolidReactiveSystem system); + double T_gas, + double p_gas, + double w_water, + double rho_s_initial, + double phi_S, + double delta_t, + FiniteElement::SolidReactiveSystem system); ~conversion_rate(void); @@ -38,11 +38,11 @@ class conversion_rate double get_mole_fraction(double xm); - void eval(double t, Eigen::VectorXd const& y, Eigen::VectorXd &dydx); + void eval(double t, Eigen::VectorXd const& y, Eigen::VectorXd& dydx); - //Adsorbate EOS + // Adsorbate EOS double get_adsorbate_density(const double Tads); - //Adsorbate Dubinin stuff + // Adsorbate Dubinin stuff double get_enthalpy(const double Tads, const double pads); private: @@ -51,14 +51,14 @@ class conversion_rate void get_x(Eigen::VectorXd& output_x); void set_rho_s(double new_rho_s); - //Adsorbate EOS + // Adsorbate EOS double get_alphaT(const double Tads); double get_ps(const double Tads); double get_hv(const double Tads); double get_specific_heat_capacity(const double Tads); // TODO [CL] why unused? - //Adsorbate Dubinin stuff + // Adsorbate Dubinin stuff double get_potential(const double Tads, double pads); void set_sorption_equilibrium(); double Z13XBF_adsorption(); @@ -69,32 +69,31 @@ class conversion_rate double Mn_redox(); void set_chemical_equilibrium(); - - //const double rho_caoh2, rho_cao; // density for Ca(OH)2 and CaO - const double R; // [J/mol/K] - double rho_s; // solid phase density - const double rho_s_0; // initial solid phase density - double phi_solid; //solid volume fraction - double p_gas; // gas phase pressure; - double p_r_g; // pressure of H2O on gas phase; - double p_eq; // equilibrium pressure; // unit in bar - double T_eq; // equilibrium temperature; - double T_s; // solid phase temperature; - double T; // gas phase temperature; - double qR; // rate of solid density change; - double x_react; // mass fraction of water in gas phase; - double X_D; // mass fraction of dehydration (CaO) in the solid phase; - double X_H; // mass fraction of hydration in the solid phase; - double dt; // time step size; - double rho_low; //lower density limit - double rho_up; //upper density limit + // const double rho_caoh2, rho_cao; // density for Ca(OH)2 and CaO + const double R; // [J/mol/K] + double rho_s; // solid phase density + const double rho_s_0; // initial solid phase density + double phi_solid; // solid volume fraction + double p_gas; // gas phase pressure; + double p_r_g; // pressure of H2O on gas phase; + double p_eq; // equilibrium pressure; // unit in bar + double T_eq; // equilibrium temperature; + double T_s; // solid phase temperature; + double T; // gas phase temperature; + double qR; // rate of solid density change; + double x_react; // mass fraction of water in gas phase; + double X_D; // mass fraction of dehydration (CaO) in the solid phase; + double X_H; // mass fraction of hydration in the solid phase; + double dt; // time step size; + double rho_low; // lower density limit + double rho_up; // upper density limit double reaction_enthalpy; double reaction_entropy; - double M_carrier; //inert component molar mass - double M_react; //reactive component molar mass - double W0; //maximum specific adsorbed volume - double C_eq; //equilibrium loading of sorbens - double p_min; //minimum pressure for which we find a valid adsorption potential + double M_carrier; // inert component molar mass + double M_react; // reactive component molar mass + double W0; // maximum specific adsorbed volume + double C_eq; // equilibrium loading of sorbens + double p_min; // minimum pressure for which we find a valid adsorption potential FiniteElement::SolidReactiveSystem reaction_system; double tol_l; @@ -102,9 +101,7 @@ class conversion_rate double tol_rho; Eigen::VectorXd x; - size_t i; // iterator - + size_t i; // iterator }; #endif - diff --git a/FEM/eos.cpp b/FEM/eos.cpp index 42be0b1dd..d0b9d7930 100644 --- a/FEM/eos.cpp +++ b/FEM/eos.cpp @@ -32,129 +32,102 @@ using namespace std; /********************************************************************** Some functions and derivations as shown in [Span&Wagner 1994] ***********************************************************************/ -double theta_fn (double tau, double A, double delta, double beta) +double theta_fn(double tau, double A, double delta, double beta) { - return (1 - tau) + A* pow((delta - 1) * (delta - 1),1 / (2 * beta)); -// TF return (1-tau)+A*pow(pow(delta-1,2),1/(2*beta)); + return (1 - tau) + A * pow((delta - 1) * (delta - 1), 1 / (2 * beta)); + // TF return (1-tau)+A*pow(pow(delta-1,2),1/(2*beta)); } -double phi_fn (double C, double delta, double D, double tau) +double phi_fn(double C, double delta, double D, double tau) { return exp(-C * (delta - 1) * (delta - 1) - D * (tau - 1) * (tau - 1)); -// TF return exp (-C*pow(delta-1,2)-D*pow(tau-1,2)); + // TF return exp (-C*pow(delta-1,2)-D*pow(tau-1,2)); } -double delta_fn (double theta_fn, double B, double delta, double alpha) +double delta_fn(double theta_fn, double B, double delta, double alpha) { - return theta_fn * theta_fn + B* pow((delta - 1) * (delta - 1),alpha); -// TF return pow(theta_fn,2)+B*pow(pow(delta-1,2),alpha); + return theta_fn * theta_fn + B * pow((delta - 1) * (delta - 1), alpha); + // TF return pow(theta_fn,2)+B*pow(pow(delta-1,2),alpha); } -double dDELTApowb_ddelta (double b, double delta_fn, double dDELTA_deriv) +double dDELTApowb_ddelta(double b, double delta_fn, double dDELTA_deriv) { - return b * pow(delta_fn,b - 1) * dDELTA_deriv; + return b * pow(delta_fn, b - 1) * dDELTA_deriv; } -double dDELTA_ddelta (double delta, double A, double theta_fn, double beta, double B, double a) +double dDELTA_ddelta(double delta, double A, double theta_fn, double beta, double B, double a) { - return (delta - - 1) * - (A * theta_fn * 2 / beta * - pow((delta - 1) * (delta - 1), - (1 / (2 * beta) - 1)) + 2 * B * a * pow((delta - 1) * (delta - 1),(a - 1))); -// return ((delta-1)*(A*theta_fn*2/beta*pow(pow((delta-1),2),(1/(2*beta)-1))+2*B*a*pow(pow((delta-1),2),(a-1)))); + return (delta - 1) * (A * theta_fn * 2 / beta * pow((delta - 1) * (delta - 1), (1 / (2 * beta) - 1)) + + 2 * B * a * pow((delta - 1) * (delta - 1), (a - 1))); + // return ((delta-1)*(A*theta_fn*2/beta*pow(pow((delta-1),2),(1/(2*beta)-1))+2*B*a*pow(pow((delta-1),2),(a-1)))); } -double d2DELTA_ddelta2 (double delta, - double dDELTA_deriv, - double A, - double theta_fn, - double beta, - double B, - double a) +double d2DELTA_ddelta2(double delta, double dDELTA_deriv, double A, double theta_fn, double beta, double B, double a) { const double delta_m1(delta - 1); const double delta_m1_quad((delta_m1) * (delta_m1)); - const double t0 (pow(delta_m1_quad, (1 / (2 * beta ) - 1))); - return 1 / (delta - 1) * dDELTA_deriv + delta_m1_quad * (4 * B - * a * - (a - - 1) * - pow(delta_m1_quad, - (a - 2)) + 2 * A * A - * pow((1 / beta), - 2) * t0 * t0 + A * - theta_fn * 4 / beta * - (1 / (2 * beta ) - 1) - * pow(delta_m1_quad, - (1 / (2 * beta) - 2))); - -// return 1/(delta-1)*dDELTA_deriv+pow((delta-1),2)* -// (4*B*a*(a-1)*pow(pow((delta-1),2),(a-2))+2*pow(A,2)*pow((1/beta),2)*pow(pow(pow((delta-1),2),(1/(2*beta)-1)),2) -// +A*theta_fn*4/beta*(1/(2*beta)-1)*pow(pow((delta-1),2),(1/(2*beta)-2))); + const double t0(pow(delta_m1_quad, (1 / (2 * beta) - 1))); + return 1 / (delta - 1) * dDELTA_deriv + + delta_m1_quad + * (4 * B * a * (a - 1) * pow(delta_m1_quad, (a - 2)) + 2 * A * A * pow((1 / beta), 2) * t0 * t0 + + A * theta_fn * 4 / beta * (1 / (2 * beta) - 1) * pow(delta_m1_quad, (1 / (2 * beta) - 2))); + + // return 1/(delta-1)*dDELTA_deriv+pow((delta-1),2)* + // (4*B*a*(a-1)*pow(pow((delta-1),2),(a-2))+2*pow(A,2)*pow((1/beta),2)*pow(pow(pow((delta-1),2),(1/(2*beta)-1)),2) + // +A*theta_fn*4/beta*(1/(2*beta)-1)*pow(pow((delta-1),2),(1/(2*beta)-2))); } -double d2DELTApowb_ddelta2 (double b,double delta_fn,double d2DELTA_deriv,double dDELTA_deriv) +double d2DELTApowb_ddelta2(double b, double delta_fn, double d2DELTA_deriv, double dDELTA_deriv) { - return b * - (pow(delta_fn, - (b - - 1)) * d2DELTA_deriv + - (b - 1) * pow(delta_fn,(b - 2)) * dDELTA_deriv * dDELTA_deriv); -// return b*(pow(delta_fn,(b-1))*d2DELTA_deriv+(b-1)*pow(delta_fn,(b-2))*pow(dDELTA_deriv,2)); + return b + * (pow(delta_fn, (b - 1)) * d2DELTA_deriv + (b - 1) * pow(delta_fn, (b - 2)) * dDELTA_deriv * dDELTA_deriv); + // return b*(pow(delta_fn,(b-1))*d2DELTA_deriv+(b-1)*pow(delta_fn,(b-2))*pow(dDELTA_deriv,2)); } -double dphi_ddelta (double C,double delta, double phi) +double dphi_ddelta(double C, double delta, double phi) { return -2 * C * (delta - 1) * phi; } -double dphi_dtau (double D,double tau, double phi_fn) +double dphi_dtau(double D, double tau, double phi_fn) { return -2 * D * (tau - 1) * phi_fn; } -double d2phi_dtau2 (double D,double tau, double phi_fn) +double d2phi_dtau2(double D, double tau, double phi_fn) { - return (2 * D * pow((tau - 1),2) - 1) * 2 * D * phi_fn; + return (2 * D * pow((tau - 1), 2) - 1) * 2 * D * phi_fn; } -double d2phi_ddelta2 (double C,double delta, double phi_fn) +double d2phi_ddelta2(double C, double delta, double phi_fn) { return (2 * C * (delta - 1) * (delta - 1) - 1) * 2 * C * phi_fn; -// return (2*C*pow((delta-1),2)-1)*2*C*phi_fn; + // return (2*C*pow((delta-1),2)-1)*2*C*phi_fn; } -double dDELTA_dtau (double theta_fn, double b, double delta_fn) +double dDELTA_dtau(double theta_fn, double b, double delta_fn) { - return -2* theta_fn* b* pow(delta_fn,(b - 1)); + return -2 * theta_fn * b * pow(delta_fn, (b - 1)); } -double d2DELTA_dtau2 (double b, double delta_fn, double theta_fn) +double d2DELTA_dtau2(double b, double delta_fn, double theta_fn) { - return 2* b* pow(delta_fn, (b - 1)) + 4 * theta_fn * theta_fn * b * (b - 1) - * pow(delta_fn, (b - 2)); -// return 2*b*pow(delta_fn,(b-1))+4*pow(theta_fn,2)*b*(b-1)*pow(delta_fn,(b-2)); + return 2 * b * pow(delta_fn, (b - 1)) + 4 * theta_fn * theta_fn * b * (b - 1) * pow(delta_fn, (b - 2)); + // return 2*b*pow(delta_fn,(b-1))+4*pow(theta_fn,2)*b*(b-1)*pow(delta_fn,(b-2)); } -double d2DELTApowb_ddeltadtau (double A, - double b, - double beta, - double delta_fn, - double delta, - double theta_fn, - double dDELTA_deriv) +double d2DELTApowb_ddeltadtau( + double A, double b, double beta, double delta_fn, double delta, double theta_fn, double dDELTA_deriv) { - return -A * b * 2 / beta* pow(delta_fn, (b - 1)) * (delta - 1) * pow( - (delta - 1) * (delta - 1), - (1 / (2 * beta ) - 1)) - 2 * theta_fn * b * (b - 1) - * pow(delta_fn, (b - 2)) * dDELTA_deriv; + return -A * b * 2 / beta * pow(delta_fn, (b - 1)) * (delta - 1) + * pow((delta - 1) * (delta - 1), (1 / (2 * beta) - 1)) + - 2 * theta_fn * b * (b - 1) * pow(delta_fn, (b - 2)) * dDELTA_deriv; -// return -A*b*2/beta*pow(delta_fn,(b-1))*(delta-1)*pow(pow((delta-1),2),(1/(2*beta)-1)) -// -2*theta_fn*b*(b-1)*pow(delta_fn,(b-2))*dDELTA_deriv; + // return -A*b*2/beta*pow(delta_fn,(b-1))*(delta-1)*pow(pow((delta-1),2),(1/(2*beta)-1)) + // -2*theta_fn*b*(b-1)*pow(delta_fn,(b-2))*dDELTA_deriv; } -double d2phi_ddeltadtau (double C,double D,double delta,double tau,double phi_fn) +double d2phi_ddeltadtau(double C, double D, double delta, double tau, double phi_fn) { return 4 * C * D * (delta - 1) * (tau - 1) * phi_fn; } @@ -163,10 +136,10 @@ double d2phi_ddeltadtau (double C,double D,double delta,double tau,double phi_fn A derivation of the free energy function phi last change: NB JUN 09 ***********************************************************************/ -double CFluidProperties::phi_r_d (double rho, double T) const +double CFluidProperties::phi_r_d(double rho, double T) const { - double phi_a = 0,phi_b = 0,phi_c = 0,phi_d = 0; - double delta,tau,DELTA,THETA,PHI,DPHI,dDELTA_deriv,dDELTApowbddelta; + double phi_a = 0, phi_b = 0, phi_c = 0, phi_d = 0; + double delta, tau, DELTA, THETA, PHI, DPHI, dDELTA_deriv, dDELTApowbddelta; int i; tau = Tc / T; @@ -175,32 +148,27 @@ double CFluidProperties::phi_r_d (double rho, double T) const for (i = 0; i < limit[3]; i++) { if (i < limit[0]) - phi_a = phi_a + (K[0][i] * K[1][i] * pow(delta, (K[1][i] - 1)) - * pow(tau, K[2][i])); + phi_a = phi_a + (K[0][i] * K[1][i] * pow(delta, (K[1][i] - 1)) * pow(tau, K[2][i])); else { if (i < limit[1]) - phi_b = phi_b + (K[0][i] * exp(-pow(delta, K[3][i])) * (pow(delta, K[1][i] - 1) - * pow(tau, K[2][i]) * (K[1][i] - K[3][i] * pow(delta, K[3][i])))); + phi_b = phi_b + (K[0][i] * exp(-pow(delta, K[3][i])) * (pow(delta, K[1][i] - 1) * pow(tau, K[2][i]) + * (K[1][i] - K[3][i] * pow(delta, K[3][i])))); else if (i < limit[2]) - phi_c = phi_c + (K[0][i] * pow(delta, K[1][i]) * pow(tau, K[2][i]) * exp(-K[10][i] - * (delta - K[13][i]) * (delta - K[13][i]) - K[11][i] * (tau - - K[12][i]) * (tau - K[12][i])) * (K[1][i] / delta - 2 * K[10][i] - * (delta - K[13][i]))); + phi_c = phi_c + (K[0][i] * pow(delta, K[1][i]) * pow(tau, K[2][i]) + * exp(-K[10][i] * (delta - K[13][i]) * (delta - K[13][i]) + - K[11][i] * (tau - K[12][i]) * (tau - K[12][i])) + * (K[1][i] / delta - 2 * K[10][i] * (delta - K[13][i]))); else if (i < limit[3]) { THETA = theta_fn(tau, K[6][i], delta, K[11][i]); DELTA = delta_fn(THETA, K[7][i], delta, K[4][i]); PHI = phi_fn(K[8][i], delta, K[9][i], tau); - dDELTA_deriv = dDELTA_ddelta(delta, K[6][i], THETA, K[11][i], - K[7][i], K[4][i]); - dDELTApowbddelta = dDELTApowb_ddelta(K[5][i], DELTA, - dDELTA_deriv); + dDELTA_deriv = dDELTA_ddelta(delta, K[6][i], THETA, K[11][i], K[7][i], K[4][i]); + dDELTApowbddelta = dDELTApowb_ddelta(K[5][i], DELTA, dDELTA_deriv); DPHI = dphi_ddelta(K[8][i], delta, PHI); - phi_d = phi_d + K[0][i] * (pow(DELTA, K[5][i]) * (PHI + delta - * DPHI) + - dDELTApowbddelta * delta * PHI); + phi_d = phi_d + K[0][i] * (pow(DELTA, K[5][i]) * (PHI + delta * DPHI) + dDELTApowbddelta * delta * PHI); } } } @@ -211,14 +179,14 @@ double CFluidProperties::phi_r_d (double rho, double T) const A derivation of the free energy function phi last change: NB JUN 09 ***********************************************************************/ -double CFluidProperties::phi_r_tt (double rho, double T) const +double CFluidProperties::phi_r_tt(double rho, double T) const { - //CFluidProperties *FP; - double phi_a = 0,phi_b = 0,phi_c = 0,phi_d = 0; - double delta,tau,THETA,PHI,DELTA,DDELTA,D2DELTA,DPHI,D2PHI; + // CFluidProperties *FP; + double phi_a = 0, phi_b = 0, phi_c = 0, phi_d = 0; + double delta, tau, THETA, PHI, DELTA, DDELTA, D2DELTA, DPHI, D2PHI; int i = 0; - //FP=MFPGet(c); + // FP=MFPGet(c); tau = Tc / T; delta = rho / rhoc; @@ -226,30 +194,28 @@ double CFluidProperties::phi_r_tt (double rho, double T) const for (i = 0; i < limit[3]; i++) { if (i < limit[0]) - phi_a = phi_a + (K[0][i] * K[2][i] * (K[2][i] - 1) * pow(delta, K[1][i]) * pow(tau, - (K[2][i] - 2))); + phi_a = phi_a + (K[0][i] * K[2][i] * (K[2][i] - 1) * pow(delta, K[1][i]) * pow(tau, (K[2][i] - 2))); else if (i < limit[1]) - phi_b = phi_b + (K[0][i] * K[2][i] * (K[2][i] - 1) * pow(delta, K[1][i]) * pow(tau, - (K[2][i] - 2)) * exp(-pow(delta, K[3][i]))); + phi_b = phi_b + (K[0][i] * K[2][i] * (K[2][i] - 1) * pow(delta, K[1][i]) * pow(tau, (K[2][i] - 2)) + * exp(-pow(delta, K[3][i]))); else if (i < limit[2]) - phi_c = phi_c + (K[0][i] * pow(delta, K[1][i]) * pow(tau, K[2][i]) * exp(-K[10][i] - * ((delta - K[13][i]) * (delta - K[13][i])) - K[11][i] * ((tau - - K[12][i]) * (tau - K[12][i]))) * (pow((K[2][i] / tau - 2 * K[11][i] - * (tau - K[12][i])), 2) - K[2][i] / (tau * tau) - 2 * K[11][i])); + phi_c = phi_c + (K[0][i] * pow(delta, K[1][i]) * pow(tau, K[2][i]) + * exp(-K[10][i] * ((delta - K[13][i]) * (delta - K[13][i])) + - K[11][i] * ((tau - K[12][i]) * (tau - K[12][i]))) + * (pow((K[2][i] / tau - 2 * K[11][i] * (tau - K[12][i])), 2) - K[2][i] / (tau * tau) + - 2 * K[11][i])); else if (i < limit[3]) { - THETA = theta_fn (tau,K[6][i],delta,K[11][i]); - DELTA = delta_fn (THETA,K[7][i],delta,K[4][i]); - PHI = phi_fn (K[8][i],delta,K[9][i],tau); - - D2DELTA = d2DELTA_dtau2 (K[5][i],DELTA,THETA); - DDELTA = dDELTA_dtau (THETA, K[5][i], DELTA); - DPHI = dphi_dtau (K[9][i],tau,PHI); - D2PHI = d2phi_dtau2 (K[9][i],tau,PHI); - - phi_d = phi_d + - (K[0][i] * delta * - (D2DELTA * PHI + 2 * DDELTA * DPHI + pow(DELTA,K[5][i]) * D2PHI)); + THETA = theta_fn(tau, K[6][i], delta, K[11][i]); + DELTA = delta_fn(THETA, K[7][i], delta, K[4][i]); + PHI = phi_fn(K[8][i], delta, K[9][i], tau); + + D2DELTA = d2DELTA_dtau2(K[5][i], DELTA, THETA); + DDELTA = dDELTA_dtau(THETA, K[5][i], DELTA); + DPHI = dphi_dtau(K[9][i], tau, PHI); + D2PHI = d2phi_dtau2(K[9][i], tau, PHI); + + phi_d = phi_d + (K[0][i] * delta * (D2DELTA * PHI + 2 * DDELTA * DPHI + pow(DELTA, K[5][i]) * D2PHI)); } } return phi_a + phi_b + phi_c + phi_d; @@ -259,9 +225,9 @@ double CFluidProperties::phi_r_tt (double rho, double T) const A derivation of the free energy function phi last change: NB JUN 09 ***********************************************************************/ -double CFluidProperties::phi_0_t (double T) const +double CFluidProperties::phi_0_t(double T) const { - double phi_c = 0,phi_d = 0,phi_e = 0; + double phi_c = 0, phi_d = 0, phi_e = 0; double tau; int i; @@ -280,12 +246,12 @@ double CFluidProperties::phi_0_t (double T) const A derivation of the free energy function phi last change: NB JUN 09 ***********************************************************************/ -double CFluidProperties::phi_0_tt (double T) const +double CFluidProperties::phi_0_tt(double T) const { - if (fluid_id == 3) // N2 + if (fluid_id == 3) // N2 { double a[6]; - const double tau (Tc / T); + const double tau(Tc / T); a[0] = 2.5; a[1] = -1.934819e-4; @@ -294,63 +260,62 @@ double CFluidProperties::phi_0_tt (double T) const a[4] = 1.012941; a[5] = 26.65788; - const double exp_a8 (exp(a[5]*tau)); - const double phi_zero_tt = (-a[0] + 2.0*a[1]/tau + 6.0*a[2]/tau/tau + 12*a[3]/tau/tau/tau - a[4]*a[5]*a[5]*tau*tau*exp_a8/((exp_a8-1.0)*(exp_a8-1.0)))/(tau * tau); + const double exp_a8(exp(a[5] * tau)); + const double phi_zero_tt = (-a[0] + 2.0 * a[1] / tau + 6.0 * a[2] / tau / tau + 12 * a[3] / tau / tau / tau + - a[4] * a[5] * a[5] * tau * tau * exp_a8 / ((exp_a8 - 1.0) * (exp_a8 - 1.0))) + / (tau * tau); return phi_zero_tt; } else { - double phi_d = 0,phi_e = 0; - double tau; - int i; + double phi_d = 0, phi_e = 0; + double tau; + int i; - tau = Tc / T; - phi_d = k[0][2] / (tau * tau); - for (i = 3; i < 8; i++) - phi_e = phi_e + - (k[0][i] * - (k[1][i] * k[1][i]) * exp(-k[1][i] * tau) * pow(1 - exp(-k[1][i] * tau),-2)); + tau = Tc / T; + phi_d = k[0][2] / (tau * tau); + for (i = 3; i < 8; i++) + phi_e = phi_e + (k[0][i] * (k[1][i] * k[1][i]) * exp(-k[1][i] * tau) * pow(1 - exp(-k[1][i] * tau), -2)); - return 0 - phi_d - phi_e; - } + return 0 - phi_d - phi_e; + } } /********************************************************************** A derivation of the free energy function phi last change: NB JUN 09 ***********************************************************************/ -double CFluidProperties::phi_r_t (double rho, double T) const +double CFluidProperties::phi_r_t(double rho, double T) const { - double phi_a = 0,phi_b = 0,phi_c = 0,phi_d = 0,h; + double phi_a = 0, phi_b = 0, phi_c = 0, phi_d = 0, h; int i; - double delta,tau; - double thetafn,deltafn,ddeltatau,phifn,dphitau; + double delta, tau; + double thetafn, deltafn, ddeltatau, phifn, dphitau; tau = Tc / T; delta = rho / rhoc; for (i = 0; i < limit[0]; i++) - phi_a = phi_a + (K[0][i] * K[2][i] * pow(delta,K[1][i]) * pow(tau,(K[2][i] - 1))); + phi_a = phi_a + (K[0][i] * K[2][i] * pow(delta, K[1][i]) * pow(tau, (K[2][i] - 1))); for (i = limit[0]; i < limit[1]; i++) - phi_b = phi_b + (K[0][i] * K[2][i] * pow(delta, K[1][i]) * pow(tau, (K[2][i] - 1)) * exp( - -pow(delta, K[3][i]))); + phi_b = phi_b + (K[0][i] * K[2][i] * pow(delta, K[1][i]) * pow(tau, (K[2][i] - 1)) * exp(-pow(delta, K[3][i]))); for (i = limit[1]; i < limit[2]; i++) - phi_c = phi_c + (K[0][i] * pow(delta, K[1][i]) * pow(tau, (K[2][i])) * exp(-K[10][i] - * ((delta - K[13][i]) * (delta - K[13][i])) - K[11][i] * (tau - K[12][i]) - * (tau - K[12][i])) * (K[2][i] / tau - 2 * K[11][i] * (tau - K[12][i]))); + phi_c = phi_c + (K[0][i] * pow(delta, K[1][i]) * pow(tau, (K[2][i])) + * exp(-K[10][i] * ((delta - K[13][i]) * (delta - K[13][i])) + - K[11][i] * (tau - K[12][i]) * (tau - K[12][i])) + * (K[2][i] / tau - 2 * K[11][i] * (tau - K[12][i]))); for (i = limit[2]; i < limit[3]; i++) { - thetafn = theta_fn(tau,K[6][i],delta,K[11][i]); - deltafn = delta_fn(thetafn,K[7][i],delta,K[4][i]); - ddeltatau = dDELTA_dtau(thetafn,K[5][i],deltafn); - phifn = phi_fn(K[8][i],delta,K[9][i],tau); - dphitau = dphi_dtau(K[9][i],tau,phifn); - - phi_d = phi_d + - (K[0][i] * delta * (ddeltatau * phifn + pow(deltafn,K[5][i]) * dphitau)); + thetafn = theta_fn(tau, K[6][i], delta, K[11][i]); + deltafn = delta_fn(thetafn, K[7][i], delta, K[4][i]); + ddeltatau = dDELTA_dtau(thetafn, K[5][i], deltafn); + phifn = phi_fn(K[8][i], delta, K[9][i], tau); + dphitau = dphi_dtau(K[9][i], tau, phifn); + + phi_d = phi_d + (K[0][i] * delta * (ddeltatau * phifn + pow(deltafn, K[5][i]) * dphitau)); } h = phi_a + phi_b + phi_c + phi_d; return h; @@ -360,70 +325,55 @@ double CFluidProperties::phi_r_t (double rho, double T) const A derivation of the free energy function phi last change: NB 4.9.05 ***********************************************************************/ -double CFluidProperties::phi_r_dt (double rho, double T) const +double CFluidProperties::phi_r_dt(double rho, double T) const { - double phi_a = 0,phi_b = 0,phi_c = 0,phi_d = 0; + double phi_a = 0, phi_b = 0, phi_c = 0, phi_d = 0; int i; - double delta,tau; - double phifn,thetafn,deltafn,d2phideriv,dDELTAderiv,dDELTApowbddelta,dphidtau, - dDELTApowbdtau,dphiddelta,d2DELTApowbddeltadtau; + double delta, tau; + double phifn, thetafn, deltafn, d2phideriv, dDELTAderiv, dDELTApowbddelta, dphidtau, dDELTApowbdtau, dphiddelta, + d2DELTApowbddeltadtau; tau = Tc / T; delta = rho / rhoc; for (i = 0; i < limit[0]; i++) - phi_a = phi_a + - (K[0][i] * K[1][i] * K[2][i] * - pow(delta,(K[1][i] - 1)) * pow(tau,(K[2][i] - 1))); + phi_a = phi_a + (K[0][i] * K[1][i] * K[2][i] * pow(delta, (K[1][i] - 1)) * pow(tau, (K[2][i] - 1))); for (i = limit[0]; i < limit[1]; i++) - phi_b = phi_b + - (K[0][i] * K[2][i] * - pow(delta,(K[1][i] - 1)) * pow(tau,(K[2][i] - 1)) * (K[1][i] - K[3][i] * - pow( - delta, - K[3][i])) * - exp(-pow(delta,K[3][i]))); + phi_b = phi_b + (K[0][i] * K[2][i] * pow(delta, (K[1][i] - 1)) * pow(tau, (K[2][i] - 1)) + * (K[1][i] - K[3][i] * pow(delta, K[3][i])) + * exp(-pow(delta, K[3][i]))); for (i = limit[1]; i < limit[2]; i++) - phi_c = phi_c + ((K[0][i] * pow(delta,K[1][i]) * pow(tau,K[2][i]) * exp( - -K[10][i] * - ((delta - - K[13][i]) * - (delta - - K[13][i])) - K[11][i] * - ((tau - K[12][i]) * (tau - K[12][i])))) * + phi_c = phi_c + ((K[0][i] * pow(delta, K[1][i]) * pow(tau, K[2][i]) + * exp(-K[10][i] * ((delta - K[13][i]) * (delta - K[13][i])) + - K[11][i] * ((tau - K[12][i]) * (tau - K[12][i])))) + * - (K[1][i] / delta - 2 * K[10][i] * (delta - K[13][i])) * - (K[2][i] / tau - 2 * K[11][i] * (tau - K[12][i]))); + (K[1][i] / delta - 2 * K[10][i] * (delta - K[13][i])) + * (K[2][i] / tau - 2 * K[11][i] * (tau - K[12][i]))); for (i = limit[2]; i < limit[3]; i++) { - phifn = phi_fn(K[8][i],delta,K[9][i],tau); - thetafn = theta_fn(tau,K[6][i],delta,K[11][i]); - deltafn = delta_fn(thetafn,K[7][i],delta,K[4][i]); - d2phideriv = d2phi_ddeltadtau(K[8][i],K[9][i],delta,tau,phifn); - - dDELTAderiv = dDELTA_ddelta(delta,K[6][i],thetafn,K[11][i],K[7][i],K[4][i]); - - dDELTApowbddelta = dDELTApowb_ddelta(K[5][i],deltafn,dDELTAderiv); - dphidtau = dphi_dtau(K[9][i],tau,phifn); - dDELTApowbdtau = dDELTA_dtau(thetafn,K[5][i],deltafn); - dphiddelta = dphi_ddelta(K[8][i],delta,phifn); - d2DELTApowbddeltadtau = d2DELTApowb_ddeltadtau(K[6][i], - K[5][i], - K[11][i], - deltafn, - delta, - thetafn, - dDELTAderiv); - - phi_d = phi_d + - (K[0][i] * (pow(deltafn,K[5][i]) * (dphidtau + delta * d2phideriv) + - delta * dDELTApowbddelta * dphidtau + dDELTApowbdtau * - (phifn + delta * dphiddelta) + d2DELTApowbddeltadtau * - delta * phifn)); + phifn = phi_fn(K[8][i], delta, K[9][i], tau); + thetafn = theta_fn(tau, K[6][i], delta, K[11][i]); + deltafn = delta_fn(thetafn, K[7][i], delta, K[4][i]); + d2phideriv = d2phi_ddeltadtau(K[8][i], K[9][i], delta, tau, phifn); + + dDELTAderiv = dDELTA_ddelta(delta, K[6][i], thetafn, K[11][i], K[7][i], K[4][i]); + + dDELTApowbddelta = dDELTApowb_ddelta(K[5][i], deltafn, dDELTAderiv); + dphidtau = dphi_dtau(K[9][i], tau, phifn); + dDELTApowbdtau = dDELTA_dtau(thetafn, K[5][i], deltafn); + dphiddelta = dphi_ddelta(K[8][i], delta, phifn); + d2DELTApowbddeltadtau + = d2DELTApowb_ddeltadtau(K[6][i], K[5][i], K[11][i], deltafn, delta, thetafn, dDELTAderiv); + + phi_d = phi_d + (K[0][i] * (pow(deltafn, K[5][i]) * (dphidtau + delta * d2phideriv) + + delta * dDELTApowbddelta * dphidtau + + dDELTApowbdtau * (phifn + delta * dphiddelta) + + d2DELTApowbddeltadtau * delta * phifn)); } return phi_a + phi_b + phi_c + phi_d; @@ -433,74 +383,51 @@ double CFluidProperties::phi_r_dt (double rho, double T) const A derivation of the free energy function phi last change: NB 4.9.05 ***********************************************************************/ -double CFluidProperties::phi_r_dd (double rho, double T) const +double CFluidProperties::phi_r_dd(double rho, double T) const { - double phi_a = 0,phi_b = 0,phi_c = 0,phi_d = 0; + double phi_a = 0, phi_b = 0, phi_c = 0, phi_d = 0; int i; - double delta,tau; - double thetafn,deltafn,phifn,dphiddelta,d2phiddelta2,dDELTA_deriv,dDELTApowbddelta, - d2DELTA_deriv,d2DELTApowbddelta2; + double delta, tau; + double thetafn, deltafn, phifn, dphiddelta, d2phiddelta2, dDELTA_deriv, dDELTApowbddelta, d2DELTA_deriv, + d2DELTApowbddelta2; tau = Tc / T; delta = rho / rhoc; for (i = 0; i < limit[0]; i++) - phi_a = phi_a + - (K[0][i] * K[1][i] * - (K[1][i] - 1) * pow(delta,(K[1][i] - 2)) * pow(tau,K[2][i])); + phi_a = phi_a + (K[0][i] * K[1][i] * (K[1][i] - 1) * pow(delta, (K[1][i] - 2)) * pow(tau, K[2][i])); for (i = limit[0]; i < limit[1]; i++) - phi_b = phi_b + - ((K[0][i] * exp(-(pow(delta,K[3][i])))) * (((pow(delta,(K[1][i] - 2)) * - pow(tau, - K[2][i]))) * - (((K[1][i] - K[3][i] * - pow(delta, - K[3][i]))) * - (K[1][i] - 1 - K[3][i] * - pow( - delta, - K - [ - 3 - ][i])) - (pow(K[3][i],2) * pow(delta,K[3][i]))))); + phi_b + = phi_b + ((K[0][i] * exp(-(pow(delta, K[3][i])))) + * (((pow(delta, (K[1][i] - 2)) * pow(tau, K[2][i]))) + * (((K[1][i] - K[3][i] * pow(delta, K[3][i]))) * (K[1][i] - 1 - K[3][i] * pow(delta, K[3][i])) + - (pow(K[3][i], 2) * pow(delta, K[3][i]))))); for (i = limit[1]; i < limit[2]; i++) - phi_c = phi_c + ((K[0][i] * pow(tau,K[2][i])) * - exp(-K[10][i] * pow((delta - K[13][i]),2) - K[11][i] * - ((tau - K[12][i]) * (tau - K[12][i]))) * ( - (-2 * K[10][i] * - pow(delta, - K[1][i]) + 4 * - (K[10][i] * K[10][i]) * pow(delta,K[1][i]) * - ((delta - K[13][i]) * (delta - K[13][i]))) + - (-4 * K[1][i] * K[10][i] * - pow(delta,(K[1][i] - 1)) * (delta - K[13][i]) + - K[1][i] * (K[1][i] - 1) * pow(delta,(K[1][i] - 2))))); + phi_c = phi_c + + ((K[0][i] * pow(tau, K[2][i])) + * exp(-K[10][i] * pow((delta - K[13][i]), 2) - K[11][i] * ((tau - K[12][i]) * (tau - K[12][i]))) + * ((-2 * K[10][i] * pow(delta, K[1][i]) + + 4 * (K[10][i] * K[10][i]) * pow(delta, K[1][i]) * ((delta - K[13][i]) * (delta - K[13][i]))) + + (-4 * K[1][i] * K[10][i] * pow(delta, (K[1][i] - 1)) * (delta - K[13][i]) + + K[1][i] * (K[1][i] - 1) * pow(delta, (K[1][i] - 2))))); for (i = limit[2]; i < limit[3]; i++) { - thetafn = theta_fn(tau,K[6][i],delta,K[11][i]); - deltafn = delta_fn(thetafn,K[7][i],delta,K[4][i]); - phifn = phi_fn(K[8][i],delta,K[9][i],tau); - dphiddelta = dphi_ddelta(K[8][i],delta,phifn); - d2phiddelta2 = d2phi_ddelta2(K[8][i],delta,phifn); - dDELTA_deriv = dDELTA_ddelta(delta,K[6][i],thetafn,K[11][i],K[7][i],K[4][i]); - dDELTApowbddelta = dDELTApowb_ddelta(K[5][i],deltafn,dDELTA_deriv); - dphiddelta = dphi_ddelta(K[8][i],delta,phifn); - d2DELTA_deriv = d2DELTA_ddelta2(delta, - dDELTA_deriv, - K[6][i], - thetafn, - K[11][i], - K[7][i], - K[4][i]); - d2DELTApowbddelta2 = d2DELTApowb_ddelta2(K[5][i],deltafn,d2DELTA_deriv,dDELTA_deriv); - - phi_d = phi_d + - (K[0][i] * (pow(deltafn,K[5][i]) * (2 * dphiddelta + delta * d2phiddelta2) - + 2 * dDELTApowbddelta * - (phifn + delta * - dphiddelta) + d2DELTApowbddelta2 * delta * phifn)); + thetafn = theta_fn(tau, K[6][i], delta, K[11][i]); + deltafn = delta_fn(thetafn, K[7][i], delta, K[4][i]); + phifn = phi_fn(K[8][i], delta, K[9][i], tau); + dphiddelta = dphi_ddelta(K[8][i], delta, phifn); + d2phiddelta2 = d2phi_ddelta2(K[8][i], delta, phifn); + dDELTA_deriv = dDELTA_ddelta(delta, K[6][i], thetafn, K[11][i], K[7][i], K[4][i]); + dDELTApowbddelta = dDELTApowb_ddelta(K[5][i], deltafn, dDELTA_deriv); + dphiddelta = dphi_ddelta(K[8][i], delta, phifn); + d2DELTA_deriv = d2DELTA_ddelta2(delta, dDELTA_deriv, K[6][i], thetafn, K[11][i], K[7][i], K[4][i]); + d2DELTApowbddelta2 = d2DELTApowb_ddelta2(K[5][i], deltafn, d2DELTA_deriv, dDELTA_deriv); + + phi_d = phi_d + (K[0][i] * (pow(deltafn, K[5][i]) * (2 * dphiddelta + delta * d2phiddelta2) + + 2 * dDELTApowbddelta * (phifn + delta * dphiddelta) + + d2DELTApowbddelta2 * delta * phifn)); } return phi_a + phi_b + phi_c + phi_d; @@ -520,13 +447,13 @@ double CFluidProperties::phi_r_dd (double rho, double T) const Programming: NB Aug 2008 ***********************************************************************/ -double pressure (double rho, double T, int c) +double pressure(double rho, double T, int c) { - CFluidProperties const*const fluid_prop (MFPGet(c)); + CFluidProperties const* const fluid_prop(MFPGet(c)); const double rhoc(fluid_prop->getCriticalDensity()); const double R(fluid_prop->getSpecificGasConstant()); - return (1 + (rho / rhoc) * fluid_prop->phi_r_d(rho,T)) * rho * R * T; + return (1 + (rho / rhoc) * fluid_prop->phi_r_d(rho, T)) * rho * R * T; } /********************************************************************** @@ -549,19 +476,19 @@ double pressure (double rho, double T, int c) Aug 2008 last change: NB 4.9.05 ***********************************************************************/ -double density (double P, double rho0, double T, double prec, int c) +double density(double P, double rho0, double T, double prec, int c) { - CFluidProperties const*const fluid_prop (MFPGet(c)); + CFluidProperties const* const fluid_prop(MFPGet(c)); int iterations = 0; - double rho = 0.0,p0; //OK411 + double rho = 0.0, p0; // OK411 const double rhoc(fluid_prop->getCriticalDensity()); const double R(fluid_prop->getSpecificGasConstant()); p0 = 0; - while (fabs(P - p0) > prec) //change to fabs. 15.09.2008 WW + while (fabs(P - p0) > prec) // change to fabs. 15.09.2008 WW { - rho = P / ((1 + (rho0 / rhoc) * fluid_prop->phi_r_d(rho0,T)) * R * T); - p0 = pressure(rho0,T,c); + rho = P / ((1 + (rho0 / rhoc) * fluid_prop->phi_r_d(rho0, T)) * R * T); + p0 = pressure(rho0, T, c); rho0 = rho; iterations++; if (iterations > 50) @@ -585,15 +512,15 @@ double density (double P, double rho0, double T, double prec, int c) Programming: NB Aug 2008 ***********************************************************************/ -double enthalpy (double rho, double T, int c) +double enthalpy(double rho, double T, int c) { - CFluidProperties const*const fluid_prop (MFPGet(c)); - const double tau (fluid_prop->getCriticalTemperature()/T); + CFluidProperties const* const fluid_prop(MFPGet(c)); + const double tau(fluid_prop->getCriticalTemperature() / T); const double delta(rho / fluid_prop->getCriticalDensity()); const double R(fluid_prop->getSpecificGasConstant()); - double h = (1 + tau * (fluid_prop->phi_0_t(T) + fluid_prop->phi_r_t(rho,T)) - + delta * fluid_prop->phi_r_d(rho,T)) * R * T; + double h = (1 + tau * (fluid_prop->phi_0_t(T) + fluid_prop->phi_r_t(rho, T)) + delta * fluid_prop->phi_r_d(rho, T)) + * R * T; return h; } @@ -605,23 +532,23 @@ double enthalpy (double rho, double T, int c) double linear_heat_capacity(double T, int c) { + double Tl[2], cpl[2]; // temperature limits in K, capacity limits in J/kg/K - double Tl[2] ,cpl[2]; //temperature limits in K, capacity limits in J/kg/K - - switch (c) { - case 1: //H2O + switch (c) + { + case 1: // H2O Tl[0] = 275.0; Tl[1] = 1000.0; cpl[0] = 1859.0; cpl[1] = 2288.0; break; - case 3: //N2 1056.8+(1146.4-1056.8)/(900.0-500.0)*(variables[1]-500.0); + case 3: // N2 1056.8+(1146.4-1056.8)/(900.0-500.0)*(variables[1]-500.0); Tl[0] = 275.0; Tl[1] = 1200.0; cpl[0] = 1039.0; cpl[1] = 1204.0; break; - case 5: //O2 + case 5: // O2 Tl[0] = 275.0; Tl[1] = 1200.0; cpl[0] = 915.0; @@ -632,7 +559,7 @@ double linear_heat_capacity(double T, int c) return 1000.0; } - return (cpl[0] + (cpl[1]-cpl[0])/(Tl[1]-Tl[0])*(T-Tl[0])); + return (cpl[0] + (cpl[1] - cpl[0]) / (Tl[1] - Tl[0]) * (T - Tl[0])); } /********************************************************************** @@ -650,13 +577,13 @@ double linear_heat_capacity(double T, int c) Aug 2008 last change: NB 4.9.05 ***********************************************************************/ -double isochoric_heat_capacity (double rho, double T, int c) +double isochoric_heat_capacity(double rho, double T, int c) { - CFluidProperties const*const fluid_prop (MFPGet(c)); + CFluidProperties const* const fluid_prop(MFPGet(c)); // thermal_properties (fluid, rhoc, Tc, R); - const double h ((fluid_prop->getCriticalTemperature() / T)); - double cv = -(h * h * (fluid_prop->phi_0_tt(T) + fluid_prop->phi_r_tt(rho,T))) - * fluid_prop->getSpecificGasConstant(); + const double h((fluid_prop->getCriticalTemperature() / T)); + double cv + = -(h * h * (fluid_prop->phi_0_tt(T) + fluid_prop->phi_r_tt(rho, T))) * fluid_prop->getSpecificGasConstant(); return cv; } @@ -676,16 +603,16 @@ double isochoric_heat_capacity (double rho, double T, int c) Aug 2008 ***********************************************************************/ -double isobaric_heat_capacity (double rho, double T, int c) +double isobaric_heat_capacity(double rho, double T, int c) { - CFluidProperties const*const fluid_prop (MFPGet(c)); - const double tau (fluid_prop->getCriticalTemperature() / T); - const double delta (rho / fluid_prop->getCriticalDensity()); + CFluidProperties const* const fluid_prop(MFPGet(c)); + const double tau(fluid_prop->getCriticalTemperature() / T); + const double delta(rho / fluid_prop->getCriticalDensity()); - double cp = (-tau * tau * (fluid_prop->phi_0_tt(T) + fluid_prop->phi_r_tt(rho, T)) + - (pow((1 + delta * fluid_prop->phi_r_d(rho, T) - delta * tau * fluid_prop->phi_r_dt( - rho, T)), 2)) / ((1 + 2 * delta * fluid_prop->phi_r_d(rho, T) + delta - * delta * fluid_prop->phi_r_dd(rho,T)))) * fluid_prop->getSpecificGasConstant(); + double cp = (-tau * tau * (fluid_prop->phi_0_tt(T) + fluid_prop->phi_r_tt(rho, T)) + + (pow((1 + delta * fluid_prop->phi_r_d(rho, T) - delta * tau * fluid_prop->phi_r_dt(rho, T)), 2)) + / ((1 + 2 * delta * fluid_prop->phi_r_d(rho, T) + delta * delta * fluid_prop->phi_r_dd(rho, T)))) + * fluid_prop->getSpecificGasConstant(); return cp; } @@ -695,21 +622,21 @@ double isobaric_heat_capacity (double rho, double T, int c) Programming: NB Aug 2008 ***********************************************************************/ -double co2_viscosity (double rho, double T) +double co2_viscosity(double rho, double T) { double eta, eta_0, d_eta; - double psi,t_r; - double a[5],b[8],d[8][5]; - int i,j; + double psi, t_r; + double a[5], b[8], d[8][5]; + int i, j; // coefficients of the representation of the zero-density viscosity of co2 - a[0] = 0.235156; + a[0] = 0.235156; a[1] = -0.491266; - a[2] = 0.05211155; - a[3] = 0.05347906; + a[2] = 0.05211155; + a[3] = 0.05347906; a[4] = -0.01537102; - psi = 0; // variable for reduced effective cross-section + psi = 0; // variable for reduced effective cross-section // coefficients of the representation of the excess viscosity of co2 @@ -726,15 +653,15 @@ double co2_viscosity (double rho, double T) d[7][0] = 0.2971072e-22; d[7][1] = -0.1627888e-22; - t_r = T / 251.196; //reduced temperature + t_r = T / 251.196; // reduced temperature // deriving the zero-density viscosity eta_0(T) for (i = 0; i < 5; i++) - psi = psi + a[i] * MathLib::fastpow(log (t_r),(i)); - psi = exp (psi); + psi = psi + a[i] * MathLib::fastpow(log(t_r), (i)); + psi = exp(psi); -// TF eta_0 = 1.00697 * pow (T,0.5) / psi; + // TF eta_0 = 1.00697 * pow (T,0.5) / psi; eta_0 = 1.00697 * sqrt(T) / psi; d_eta = 0; @@ -743,13 +670,13 @@ double co2_viscosity (double rho, double T) for (i = 0; i < 8; i++) { for (j = 0; j < 5; j++) - b[i] = b[i] + d[i][j] / MathLib::fastpow(t_r,j); - d_eta = d_eta + b[i] * MathLib::fastpow(rho,i + 1); + b[i] = b[i] + d[i][j] / MathLib::fastpow(t_r, j); + d_eta = d_eta + b[i] * MathLib::fastpow(rho, i + 1); } // deriving dynamic viscosity as sum of eta_o(T) and d_eta(rho,T) - eta = (eta_0 + d_eta) * 1e-06; // eta in [Pa s] + eta = (eta_0 + d_eta) * 1e-06; // eta in [Pa s] return eta; } @@ -760,57 +687,65 @@ double co2_viscosity (double rho, double T) Programming: NB 4.8.01 Nov 2008 ***********************************************************************/ -double co2_heat_conductivity (double rho, double T) -{ - double Tc = 304.1282; - // double pc = 7377300; - double rho_c = 467.6; - // double M = 0.044098; - // double R = 8.314472; - // double NA = 6.0221353e23; - double rho_r = rho/rho_c; - double Tr = T/Tc; - double lamda_r; - double lamda; - - double a[13] = {0, 3, 6.70697, 0.94604, 0.3, 0.3, 0.39751, 0.33791, 0.77963, 0.79857, 0.9, 0.02, 0.2}; - double g[11] = {0, 0, 0, 1.5, 0, 1, 1.5, 1.5, 1.5, 3.5, 5.5}; - double h[11] = {0, 1, 5, 1, 1, 2, 0, 5, 9, 0, 0}; - double n[11] = {0, 7.69857587E+00, 1.59885811E-01, 1.56918621E+00, -6.73400790E+00, 1.63890156E+01, 3.69415242E+00, 2.23205514E+01, 6.61420950E+01, -1.71779133E-01, 4.33043347E-03}; - double nc = 0.775547504; - double lamda_r_ce; - double temp1,temp2,temp3; - - double var = 1.0+a[11]*pow(pow(1-Tr,2),a[12]); - double alpha = 1-a[10]*log(var+sqrt(var*var-1.0)); - temp1 = rho_r*exp(-pow(rho_r,a[1])/a[1]-pow(a[2]*(Tr-1),2)-pow(a[3]*(rho_r-1),2)); - temp2 = pow(pow((1-1/Tr)+a[4]*pow(pow(rho_r-1,2),1./(2.*a[5])),2),a[6]); - temp3 = pow(pow(a[7]*(rho_r-alpha),2),a[8]); - lamda_r_ce = temp1/pow(temp2+temp3,a[9]); - temp1 = 0; - temp2 = 0; - - for (int i=1;i<4;i++) - { - temp1 += n[i]*pow(Tr,g[i])*pow(rho_r,h[i]); - } - for (int i=4;i<11;i++) - { - temp2 += n[i]*pow(Tr,g[i])*pow(rho_r,h[i]); - } - - temp2 *= exp(-5.*rho_r*rho_r); - - lamda_r = temp1 + temp2 + nc*lamda_r_ce; - -// double Lamda_C=pow(R,5./6.)*pow(pc,2./3.)/pow(Tc,1./6.)/pow(M,0.5)/pow(NA,1./3.); - double Lamda_C=0.00481384; // W/m/K - - - lamda = lamda_r * Lamda_C; - - - return lamda; +double co2_heat_conductivity(double rho, double T) +{ + double Tc = 304.1282; + // double pc = 7377300; + double rho_c = 467.6; + // double M = 0.044098; + // double R = 8.314472; + // double NA = 6.0221353e23; + double rho_r = rho / rho_c; + double Tr = T / Tc; + double lamda_r; + double lamda; + + double a[13] = {0, 3, 6.70697, 0.94604, 0.3, 0.3, 0.39751, 0.33791, 0.77963, 0.79857, 0.9, 0.02, 0.2}; + double g[11] = {0, 0, 0, 1.5, 0, 1, 1.5, 1.5, 1.5, 3.5, 5.5}; + double h[11] = {0, 1, 5, 1, 1, 2, 0, 5, 9, 0, 0}; + double n[11] = {0, + 7.69857587E+00, + 1.59885811E-01, + 1.56918621E+00, + -6.73400790E+00, + 1.63890156E+01, + 3.69415242E+00, + 2.23205514E+01, + 6.61420950E+01, + -1.71779133E-01, + 4.33043347E-03}; + double nc = 0.775547504; + double lamda_r_ce; + double temp1, temp2, temp3; + + double var = 1.0 + a[11] * pow(pow(1 - Tr, 2), a[12]); + double alpha = 1 - a[10] * log(var + sqrt(var * var - 1.0)); + temp1 = rho_r * exp(-pow(rho_r, a[1]) / a[1] - pow(a[2] * (Tr - 1), 2) - pow(a[3] * (rho_r - 1), 2)); + temp2 = pow(pow((1 - 1 / Tr) + a[4] * pow(pow(rho_r - 1, 2), 1. / (2. * a[5])), 2), a[6]); + temp3 = pow(pow(a[7] * (rho_r - alpha), 2), a[8]); + lamda_r_ce = temp1 / pow(temp2 + temp3, a[9]); + temp1 = 0; + temp2 = 0; + + for (int i = 1; i < 4; i++) + { + temp1 += n[i] * pow(Tr, g[i]) * pow(rho_r, h[i]); + } + for (int i = 4; i < 11; i++) + { + temp2 += n[i] * pow(Tr, g[i]) * pow(rho_r, h[i]); + } + + temp2 *= exp(-5. * rho_r * rho_r); + + lamda_r = temp1 + temp2 + nc * lamda_r_ce; + + // double Lamda_C=pow(R,5./6.)*pow(pc,2./3.)/pow(Tc,1./6.)/pow(M,0.5)/pow(NA,1./3.); + double Lamda_C = 0.00481384; // W/m/K + + lamda = lamda_r * Lamda_C; + + return lamda; } /********************************************************************** @@ -819,18 +754,15 @@ double co2_heat_conductivity (double rho, double T) Programming: NB 4.8.01 Nov 2008 ***********************************************************************/ -double ch4_viscosity_295K (double p) +double ch4_viscosity_295K(double p) { double h; p = p / 100000; - h = - (-3.7091411E-14 * - MathLib::fastpow(p, - 4) + 9.1937114E-10 * - MathLib::fastpow(p, - 3) - 6.6099446E-06 * p * p + 4.8400147E-02 * p + - 1.0934694E+01) / 1.0e6; + h = (-3.7091411E-14 * MathLib::fastpow(p, 4) + 9.1937114E-10 * MathLib::fastpow(p, 3) - 6.6099446E-06 * p * p + + 4.8400147E-02 * p + + 1.0934694E+01) + / 1.0e6; return h; } @@ -841,12 +773,12 @@ double ch4_viscosity_295K (double p) Programming: NB Apr 2009 ***********************************************************************/ -double h2o_viscosity_IAPWS (double rho, double T) +double h2o_viscosity_IAPWS(double rho, double T) { - double my,my_0,my_1; - double H[4],h[6][7]; - double sum1 = 0,sum2 = 0,sum3 = 0; - int i,j; + double my, my_0, my_1; + double H[4], h[6][7]; + double sum1 = 0, sum2 = 0, sum3 = 0; + int i, j; T = T / 647.096; rho = rho / 322.0; @@ -881,16 +813,16 @@ double h2o_viscosity_IAPWS (double rho, double T) h[3][6] = -0.004356730; h[5][6] = -0.000593264; - for(i = 0; i < 4; i++) - sum1 = sum1 + (H[i] / (MathLib::fastpow(T,i))); + for (i = 0; i < 4; i++) + sum1 = sum1 + (H[i] / (MathLib::fastpow(T, i))); my_0 = 100 * sqrt(T) / sum1; - for(i = 0; i < 6; i++) + for (i = 0; i < 6; i++) { for (j = 0; j < 7; j++) - sum3 = sum3 + h[i][j] * MathLib::fastpow(rho - 1,j); - sum2 = sum2 + (MathLib::fastpow(1 / T - 1,i) * sum3); + sum3 = sum3 + h[i][j] * MathLib::fastpow(rho - 1, j); + sum2 = sum2 + (MathLib::fastpow(1 / T - 1, i) * sum3); sum3 = 0; } @@ -906,17 +838,16 @@ double h2o_viscosity_IAPWS (double rho, double T) Programming: NB/TN see Lemmon & Jacobson, Int J of Thermophys, 25(1), 2004 ***********************************************************************/ -double o2_viscosity (double rho, double T) +double o2_viscosity(double rho, double T) { - const double MM (32.0); // - const double sigma_squared (0.11751184); // nm^2 - const double ek (118.5); //K - const double T_c (154.581); //K - const double rho_c (13.63); + const double MM(32.0); // + const double sigma_squared(0.11751184); // nm^2 + const double ek(118.5); // K + const double T_c(154.581); // K + const double rho_c(13.63); rho /= MM; // convert density in mol/dm^3 - double b[5]; b[0] = 0.431; @@ -925,15 +856,16 @@ double o2_viscosity (double rho, double T) b[3] = 0.005341; b[4] = -0.00331; - double exponent (0); + double exponent(0); - for (unsigned i=0; i<5; i++) - exponent += b[i] * MathLib::fastpow(log(T/ek),i); + for (unsigned i = 0; i < 5; i++) + exponent += b[i] * MathLib::fastpow(log(T / ek), i); const double Omega = exp(exponent); - const double eta_0 = 0.0266958*pow(MM*T,0.5)/sigma_squared/Omega; - double rho_min (0.2); // densities lower than that do not influence eta_r (less than 1%) - if (rho < rho_min) return eta_0*1e-6; // for better efficiency near dilute gas (eta in Pa*s) + const double eta_0 = 0.0266958 * pow(MM * T, 0.5) / sigma_squared / Omega; + double rho_min(0.2); // densities lower than that do not influence eta_r (less than 1%) + if (rho < rho_min) + return eta_0 * 1e-6; // for better efficiency near dilute gas (eta in Pa*s) double N[5]; double t[5]; @@ -941,7 +873,6 @@ double o2_viscosity (double rho, double T) int l[5]; int gamma[5]; - N[0] = 17.67; N[1] = 0.4042; N[2] = 0.0001077; @@ -972,16 +903,16 @@ double o2_viscosity (double rho, double T) gamma[3] = 1; gamma[4] = 1; - const double tau = T_c/T; - const double delta = rho/rho_c; - double eta_r (0); + const double tau = T_c / T; + const double delta = rho / rho_c; + double eta_r(0); - for (unsigned i=0; i<5; i++) + for (unsigned i = 0; i < 5; i++) { - eta_r += N[i]*pow(tau,t[i])*MathLib::fastpow(delta,d[i])*exp(-gamma[i]*MathLib::fastpow(delta,l[i])); + eta_r += N[i] * pow(tau, t[i]) * MathLib::fastpow(delta, d[i]) * exp(-gamma[i] * MathLib::fastpow(delta, l[i])); } - return (eta_0+eta_r)*1e-6; // returns viscosity in Pa*s + return (eta_0 + eta_r) * 1e-6; // returns viscosity in Pa*s } /********************************************************************** @@ -990,35 +921,35 @@ double o2_viscosity (double rho, double T) Programming: NB 4.8.01 Nov 2008 ***********************************************************************/ -double Fluid_Viscosity (double rho, double T, double p, int fluid) +double Fluid_Viscosity(double rho, double T, double p, int fluid) { - p = p; //OK411 - //TODO: make a global function for all properties: Fluid_Property(int c, int property, double T, double P) (NB) + p = p; // OK411 + // TODO: make a global function for all properties: Fluid_Property(int c, int property, double T, double P) (NB) double h; switch (fluid) { - case 0: // CARBON_DIOXIDE - h = co2_viscosity (rho,T); - break; - case 1: // WATER - // h = 1E-3; - h = h2o_viscosity_IAPWS (rho,T); - break; - case 2: // METHANE - //h = ch4_viscosity_295K(p); - h = ch4_viscosity (rho,T); - break; + case 0: // CARBON_DIOXIDE + h = co2_viscosity(rho, T); + break; + case 1: // WATER + // h = 1E-3; + h = h2o_viscosity_IAPWS(rho, T); + break; + case 2: // METHANE + // h = ch4_viscosity_295K(p); + h = ch4_viscosity(rho, T); + break; - case 3: // Nitrogen - h = n2_viscosity (rho,T); - break; - case 5: - h = o2_viscosity(rho,T); // Oxygen - break; - default: - h = 1E-3; + case 3: // Nitrogen + h = n2_viscosity(rho, T); + break; + case 5: + h = o2_viscosity(rho, T); // Oxygen + break; + default: + h = 1E-3; } return h; @@ -1030,40 +961,41 @@ double Fluid_Viscosity (double rho, double T, double p, int fluid) Programming: NB 4.8.01 Nov 2008 ***********************************************************************/ -double Fluid_Heat_Conductivity (double rho, double T, int fluid) +double Fluid_Heat_Conductivity(double rho, double T, int fluid) { double h; switch (fluid) { - case 0: // CARBON_DIOXIDE - h = co2_heat_conductivity (rho,T); - break; - case 1: // WATER - // h = 0.598; // [W/m/K] at 293K and 1 bar - h = h2o_heat_conductivity_IAPWS_ind(rho,T); - break; - case 2: // METHANE - h = ch4_heat_conductivity (rho,T); - break; - case 3: // NITROGEN - h = n2_heat_conductivity (rho,T); - break; - case 4: // NITROGEN - h = n2_heat_conductivity (rho,T); - break; - case 5: - h = o2_heat_conductivity (rho,T); //OXYGEN - break; + case 0: // CARBON_DIOXIDE + h = co2_heat_conductivity(rho, T); + break; + case 1: // WATER + // h = 0.598; // [W/m/K] at 293K and 1 bar + h = h2o_heat_conductivity_IAPWS_ind(rho, T); + break; + case 2: // METHANE + h = ch4_heat_conductivity(rho, T); + break; + case 3: // NITROGEN + h = n2_heat_conductivity(rho, T); + break; + case 4: // NITROGEN + h = n2_heat_conductivity(rho, T); + break; + case 5: + h = o2_heat_conductivity(rho, T); // OXYGEN + break; - default: h = 0.5; + default: + h = 0.5; } - //if(caption.find("CARBON_DIOXIDE")!=string::npos) + // if(caption.find("CARBON_DIOXIDE")!=string::npos) // - //if(caption.find("METHANE")!=string::npos) + // if(caption.find("METHANE")!=string::npos) // h = 0.0338; // [W/m/K] at 298K and 1 bar - //if(caption.find("WATER")!=string::npos) + // if(caption.find("WATER")!=string::npos) // h = 0.598; // [W/m/K] at 293K and 1 bar return h; @@ -1079,7 +1011,7 @@ double vapour_pressure_co2(double T) double Tc = 304.128; double pc = 7377300; double p = 0; - double a[4],t[4]; + double a[4], t[4]; int i; a[0] = -7.0602087; t[0] = 1; @@ -1091,7 +1023,7 @@ double vapour_pressure_co2(double T) t[3] = 4; for (i = 0; i < 4; i++) - p = p + a[i] * pow(1 - (T / Tc),t[i]); + p = p + a[i] * pow(1 - (T / Tc), t[i]); p = exp(Tc / T * p) * pc; @@ -1103,7 +1035,7 @@ double vapour_pressure_co2(double T) * NB, Dec 08 last change: NB 4.9.05 *************************************************************/ -double sublime_pressure_co2(double T,double Tt,double pt) +double sublime_pressure_co2(double T, double Tt, double pt) { double p; double a[3]; @@ -1112,11 +1044,7 @@ double sublime_pressure_co2(double T,double Tt,double pt) a[1] = 2.4327015; a[2] = -5.3061778; - p = - exp(Tt / T * - (a[0] * - (1 - T / - Tt) + a[1] * pow((1 - T / Tt),1.9) + a[2] * pow((1 - T / Tt),2.9))) * pt; + p = exp(Tt / T * (a[0] * (1 - T / Tt) + a[1] * pow((1 - T / Tt), 1.9) + a[2] * pow((1 - T / Tt), 2.9))) * pt; return p; } @@ -1126,12 +1054,12 @@ double sublime_pressure_co2(double T,double Tt,double pt) * NB, Dec 08 last change: NB 4.9.05 *************************************************************/ -//just for CO2 -double melting_pressure_co2(double T,double Tt,double pt) +// just for CO2 +double melting_pressure_co2(double T, double Tt, double pt) { double p; double a[2]; - a[0] = 1955.539; //CO2 + a[0] = 1955.539; // CO2 a[1] = 2055.4593; p = (1 + a[0] * (T / Tt - 1) + a[1] * (T / Tt - 1) * (T / Tt - 1)) * pt; @@ -1147,45 +1075,45 @@ double melting_pressure_co2(double T,double Tt,double pt) * caption defines fluid * Programming: NB, Dec 08 **************************************************************/ -double preos(const CFluidProperties *mfp, double T, double P) +double preos(const CFluidProperties* mfp, double T, double P) { - double z1,z2,z3,h; + double z1, z2, z3, h; vector roots; // WW CFluidProperties* mfp_prop; - double a,b,Tc,pc,MM,Ru; - double omega,alpha; + double a, b, Tc, pc, MM, Ru; + double omega, alpha; - //int i; - //mfp_prop = MFPGet (c); //14.11.2012. WW + // int i; + // mfp_prop = MFPGet (c); //14.11.2012. WW Ru = mfp->getUniversalGasConstant(); MM = mfp->getMolarMass(); Tc = mfp->getCriticalTemperature(); pc = mfp->getCriticalPressure() / 1000; - omega = mfp->getAzentricFactor(); // azentric factor + omega = mfp->getAzentricFactor(); // azentric factor // Peng Robinson EOS: // P= R*T / (V-b) - a*alpha / (V^2+2bV-b^2) where V = MM/rho a = 0.457235 * Ru * Ru * Tc * Tc / pc; b = 0.077796 * Ru * Tc / pc; - P = P / 1000; //P in kPa - alpha = ((1 + (0.37464 + 1.5422 * omega - 0.26992 * omega * omega) * (1 - sqrt(T / Tc)))) * ((1 - + (0.37464 + 1.5422 * omega - 0.26992 * omega * omega) * (1 - sqrt(T / Tc)))); + P = P / 1000; // P in kPa + alpha = ((1 + (0.37464 + 1.5422 * omega - 0.26992 * omega * omega) * (1 - sqrt(T / Tc)))) + * ((1 + (0.37464 + 1.5422 * omega - 0.26992 * omega * omega) * (1 - sqrt(T / Tc)))); - //EOS in the form: 0 = rho^3 + z1*rho^2 + z2*rho + z3 + // EOS in the form: 0 = rho^3 + z1*rho^2 + z2*rho + z3 - z1 = (MM * a * alpha - 3 * MM * pow(b, 2) * P - 2 * MM * Ru * T * b) / (b * (P * pow(b, 2) + b - * Ru * T - a * alpha)); + z1 = (MM * a * alpha - 3 * MM * pow(b, 2) * P - 2 * MM * Ru * T * b) + / (b * (P * pow(b, 2) + b * Ru * T - a * alpha)); z2 = (pow(MM, 2) * (b * P - Ru * T)) / (b * (P * pow(b, 2) + b * Ru * T - a * alpha)); z3 = (MathLib::fastpow(MM, 3) * P) / (b * (P * b * b + b * Ru * T - a * alpha)); - NsPol3(z1,z2,z3,&roots); //derives the roots of the polynomial + NsPol3(z1, z2, z3, &roots); // derives the roots of the polynomial h = FindMin(roots); - return h; //returns the lowest positive root + return h; // returns the lowest positive root } /////**************************************************************************** @@ -1213,39 +1141,39 @@ double preos(const CFluidProperties *mfp, double T, double P) **************************************************************/ double rkeos(double T, double P, int c) { - double z1,z2,z3,h; + double z1, z2, z3, h; vector roots; - CFluidProperties const*const mfp_prop(MFPGet(c)); + CFluidProperties const* const mfp_prop(MFPGet(c)); - double a,b,Tc,pc,MM; + double a, b, Tc, pc, MM; double Ru; if (P < 0) - P = 100000; // set pressure to 1atm if unstable NB + P = 100000; // set pressure to 1atm if unstable NB - Ru = mfp_prop->getUniversalGasConstant() * 10; //universal gas constant [bar cm3/mol/K] + Ru = mfp_prop->getUniversalGasConstant() * 10; // universal gas constant [bar cm3/mol/K] MM = mfp_prop->getMolarMass(); Tc = mfp_prop->getCriticalTemperature(); - pc = mfp_prop->getCriticalPressure() / 100000; //critical pressure + pc = mfp_prop->getCriticalPressure() / 100000; // critical pressure // Redlich-Kwong EOS: // P= R*T (1+y+y^2-y^3)/ v(1-y^3) - a / (T^0.5*v(cv+b) where V = MM/rho and y = b / (4v) - a = 27* Ru* Ru* pow(Tc,2.5) / (64 * pc); + a = 27 * Ru * Ru * pow(Tc, 2.5) / (64 * pc); b = 0.0866 * Ru * Tc / pc; - P = P / 100000; //P in bar + P = P / 100000; // P in bar - //EOS in the form: 0 = vm^3 + z1*vm^2 + z2*vm + z3 + // EOS in the form: 0 = vm^3 + z1*vm^2 + z2*vm + z3 z1 = -Ru * T / P; z2 = -(Ru * T * b / P - a / (sqrt(T) * P) + b * b); z3 = -a * b / (sqrt(T) * P); - NsPol3(z1,z2,z3,&roots); //derives the roots of the polynomial + NsPol3(z1, z2, z3, &roots); // derives the roots of the polynomial - h = FindMax(roots); //returns the lowest positive root (molar volume) - h = MM / h * 1000; // density in kg/m3 + h = FindMax(roots); // returns the lowest positive root (molar volume) + h = MM / h * 1000; // density in kg/m3 return h; } @@ -1264,12 +1192,12 @@ double rkeos(double T, double P, int c) **************************************************************/ double rkeos(double T, double P, double MM, double a, double b) { - double z1,z2,z3,h; + double z1, z2, z3, h; vector roots; double Ru; - P = P / 100000; //P in bar - Ru = 83.14472; //universal gas constant [bar cm3/mol/K] + P = P / 100000; // P in bar + Ru = 83.14472; // universal gas constant [bar cm3/mol/K] // Redlich-Kwong EOS: // 0 = vm^3 + z1*vm^2 + z2*vm + z3 @@ -1277,10 +1205,10 @@ double rkeos(double T, double P, double MM, double a, double b) z2 = -(Ru * T * b / P - a / (sqrt(T) * P) + b * b); z3 = -a * b / (sqrt(T) * P); - NsPol3(z1,z2,z3,&roots); //derives the roots of the polynomial + NsPol3(z1, z2, z3, &roots); // derives the roots of the polynomial - h = FindMax(roots); //returns the lowest positive root (molar volume) - h = MM / h * 1000; // density in kg/m3 + h = FindMax(roots); // returns the lowest positive root (molar volume) + h = MM / h * 1000; // density in kg/m3 return h; } @@ -1291,28 +1219,28 @@ double rkeos(double T, double P, double MM, double a, double b) Programming: NB Apr 2009 ***********************************************************************/ -double h2o_heat_conductivity_IAPWS_ind (double rho, double T) +double h2o_heat_conductivity_IAPWS_ind(double rho, double T) { - double lamda,lamda_0,lamda_1,lamda_2; + double lamda, lamda_0, lamda_1, lamda_2; double sum1 = 0; - double S,Q,dT; - double a[4],b[3],B[2],d[4],C[6]; + double S, Q, dT; + double a[4], b[3], B[2], d[4], C[6]; int i; T = T / 647.096; rho = rho / 317.11; - a[0] = 0.0102811; - a[1] = 0.0299621; - a[2] = 0.0156146; + a[0] = 0.0102811; + a[1] = 0.0299621; + a[2] = 0.0156146; a[3] = -0.00422464; b[0] = -0.397070; - b[1] = 0.400302; - b[2] = 1.060000; + b[1] = 0.400302; + b[2] = 1.060000; B[0] = -0.171587; - B[1] = 2.392190; + B[1] = 2.392190; d[0] = 0.0701309; d[1] = 0.0118520; @@ -1327,25 +1255,22 @@ double h2o_heat_conductivity_IAPWS_ind (double rho, double T) C[5] = 10.0932; for (i = 0; i < 4; i++) - sum1 = sum1 + a[i] * MathLib::fastpow(T,i); + sum1 = sum1 + a[i] * MathLib::fastpow(T, i); lamda_0 = sqrt(T) * sum1; lamda_1 = b[0] + b[1] * rho + b[2] * exp(B[0] * (rho + B[1]) * (rho + B[1])); dT = fabs(T - 1) + C[3]; - Q = 2 + (C[4] / pow(dT,3. / 5.)); + Q = 2 + (C[4] / pow(dT, 3. / 5.)); if (T >= 1) S = 1 / dT; else - S = C[5] / pow(dT,3. / 5.); + S = C[5] / pow(dT, 3. / 5.); - lamda_2 = - (d[0] / - MathLib::fastpow(T, - 10) + d[1]) * pow(rho,9. / 5.) * exp(C[0] * (1 - pow(rho,14. / 5.))) - + d[2]* S* pow(rho,Q) * exp((Q / (1. + Q)) * (1 - pow(rho,(1. + Q)))) - + d[3] * exp(C[1] * pow(T,3. / 2.) + C[2] / MathLib::fastpow(rho,5)); + lamda_2 = (d[0] / MathLib::fastpow(T, 10) + d[1]) * pow(rho, 9. / 5.) * exp(C[0] * (1 - pow(rho, 14. / 5.))) + + d[2] * S * pow(rho, Q) * exp((Q / (1. + Q)) * (1 - pow(rho, (1. + Q)))) + + d[3] * exp(C[1] * pow(T, 3. / 2.) + C[2] / MathLib::fastpow(rho, 5)); lamda = (lamda_0 + lamda_1 + lamda_2); // lamda in [W/m/K] @@ -1363,27 +1288,27 @@ double h2o_heat_conductivity_IAPWS_ind (double rho, double T) Programming: NB Apr 2009 ***********************************************************************/ -double ch4_viscosity (double rho, double T) +double ch4_viscosity(double rho, double T) { double eta, eta_0, eta_ex; - double t,delta,tau,Omega = 0; - double C[9],s[11],g[11]; + double t, delta, tau, Omega = 0; + double C[9], s[11], g[11]; size_t r[11]; // TF - double sum1 = 0,sum2 = 0; + double sum1 = 0, sum2 = 0; int unsigned i; - rho = rho / 16.043; //rho in [mol/dm3] + rho = rho / 16.043; // rho in [mol/dm3] t = T / 174.; - C[0] = -3.0328138281; - C[1] = 16.918880086; + C[0] = -3.0328138281; + C[1] = 16.918880086; C[2] = -37.189364917; - C[3] = 41.288861858; + C[3] = 41.288861858; C[4] = -24.615921140; - C[5] = 8.9488430959; - C[6] = -1.8739240542; - C[7] = 0.20966101390; - C[8] = -9.6570437074e-03; + C[5] = 8.9488430959; + C[6] = -1.8739240542; + C[7] = 0.20966101390; + C[8] = -9.6570437074e-03; r[0] = 1; r[1] = 1; @@ -1430,12 +1355,12 @@ double ch4_viscosity (double rho, double T) tau = 190.551 / T; for (i = 0; i < 9; i++) - sum1 = sum1 + g[i] * MathLib::fastpow(delta,r[i]) * pow(tau,s[i]); + sum1 = sum1 + g[i] * MathLib::fastpow(delta, r[i]) * pow(tau, s[i]); for (i = 9; i < 11; i++) - sum2 = sum2 + g[i] * MathLib::fastpow(delta,r[i]) * pow(tau,s[i]); + sum2 = sum2 + g[i] * MathLib::fastpow(delta, r[i]) * pow(tau, s[i]); - eta_ex = 12.149* sum1* pow(1 + sum2,-1.0); + eta_ex = 12.149 * sum1 * pow(1 + sum2, -1.0); eta = (eta_0 + eta_ex) * 1e-6; return eta; @@ -1452,38 +1377,38 @@ double ch4_viscosity (double rho, double T) Programming: NB Apr 2009 ***********************************************************************/ -double ch4_heat_conductivity (double rho, double T) +double ch4_heat_conductivity(double rho, double T) { double lamda, eta_0, lamda_0, lamda_ex; - double t,delta,tau,Omega = 0,epsilon,beta; - double C[9],Q[6],j[7],f[2],H[6],J[5]; - size_t r[7],s[7]; - double sum = 0,phi_id_tt,f_int; - double P_sigma,Z_c,delta_star,T_star,rho_sigma_v; + double t, delta, tau, Omega = 0, epsilon, beta; + double C[9], Q[6], j[7], f[2], H[6], J[5]; + size_t r[7], s[7]; + double sum = 0, phi_id_tt, f_int; + double P_sigma, Z_c, delta_star, T_star, rho_sigma_v; int unsigned i; const double T_c = 190.551; const double rho_c = 10.139; const double P_c = 4.599200; - const double R = 8.314510; // [J/mol/K] + const double R = 8.314510; // [J/mol/K] t = T / 174.; tau = T_c / T; T_star = (T_c - T) / T_c; if (T_star < 0) T_star = 0; - rho = rho / 16.043; //rho in [mol/dm3] + rho = rho / 16.043; // rho in [mol/dm3] delta = rho / rho_c; - C[0] = -3.0328138281; - C[1] = 16.918880086; + C[0] = -3.0328138281; + C[1] = 16.918880086; C[2] = -37.189364917; - C[3] = 41.288861858; + C[3] = 41.288861858; C[4] = -24.615921140; - C[5] = 8.9488430959; - C[6] = -1.8739240542; - C[7] = 0.20966101390; - C[8] = -9.6570437074e-03; + C[5] = 8.9488430959; + C[6] = -1.8739240542; + C[7] = 0.20966101390; + C[8] = -9.6570437074e-03; Q[0] = 2.5998324; Q[1] = -3.3854083; Q[2] = 1.6900979; @@ -1533,11 +1458,10 @@ double ch4_heat_conductivity (double rho, double T) Omega = Omega + C[i] * pow(t, (i / 3. - 1)); Omega = 1 / Omega; - eta_0 = 10.5 * sqrt(t) / Omega; // (Eq. 10a) + eta_0 = 10.5 * sqrt(t) / Omega; // (Eq. 10a) - phi_id_tt = -Q[0] + 4 * Q[1] / 9 * - pow(tau,-1. / 3.) + 10 * Q[2] / 9 * pow(tau,-2. / 3.) + 2 * Q[3] * pow(tau,-1) - - Q[4] * Q[5] * Q[5]* tau* tau* exp (Q[5]* tau) * pow((exp (Q[5] * tau) - 1),-2); + phi_id_tt = -Q[0] + 4 * Q[1] / 9 * pow(tau, -1. / 3.) + 10 * Q[2] / 9 * pow(tau, -2. / 3.) + 2 * Q[3] * pow(tau, -1) + - Q[4] * Q[5] * Q[5] * tau * tau * exp(Q[5] * tau) * pow((exp(Q[5] * tau) - 1), -2); f_int = f[0] + (f[1] / t); @@ -1545,44 +1469,32 @@ double ch4_heat_conductivity (double rho, double T) lamda_0 = 0.51826 * eta_0 * (3.75 - f_int * (phi_id_tt + 1.5)); //(Eq. 3) - P_sigma = P_c * - exp(H[0] * T_star / - (1 - T_star) + H[1] * T_star + H[2] * pow(T_star,epsilon) + H[3] * pow(T_star, - 2) + - H[4] * pow(T_star,3)); + P_sigma + = P_c * exp(H[0] * T_star / (1 - T_star) + H[1] * T_star + H[2] * pow(T_star, epsilon) + H[3] * pow(T_star, 2) + + H[4] * pow(T_star, 3)); Z_c = P_c / (R * T_c * rho_c); - rho_sigma_v = P_sigma / - (R * - T) * - (1 + P_sigma * - MathLib::fastpow(tau, - 8) * - (Z_c - - 1) / P_c * - (1 + - (J[0] * - pow(T_star, - beta) + J[1] * - pow(T_star,2 * - beta) + J[2] * - (T_star + MathLib::fastpow(T_star,4)) + J[3] * MathLib::fastpow(T_star,2)) - / ( - 1 + J[4] * T_star))); // (Eq. 5) - - if ((T < T_c) && (rho < rho_c)) // (Eq. 16) + rho_sigma_v = P_sigma / (R * T) * (1 + + P_sigma * MathLib::fastpow(tau, 8) * (Z_c - 1) / P_c + * (1 + + (J[0] * pow(T_star, beta) + J[1] * pow(T_star, 2 * beta) + + J[2] * (T_star + MathLib::fastpow(T_star, 4)) + + J[3] * MathLib::fastpow(T_star, 2)) + / (1 + J[4] * T_star))); // (Eq. 5) + + if ((T < T_c) && (rho < rho_c)) // (Eq. 16) delta_star = rho_sigma_v / rho_c; else delta_star = 11; - for (i = 0; i < 7; i++) // (Eq. 17) + for (i = 0; i < 7; i++) // (Eq. 17) - sum = sum + j[i] * MathLib::fastpow(delta,r[i]) * MathLib::fastpow(tau,s[i]); + sum = sum + j[i] * MathLib::fastpow(delta, r[i]) * MathLib::fastpow(tau, s[i]); // (Eq. 17) - lamda_ex = 6.29638 * ( sum + j[6] * delta * delta / delta_star); + lamda_ex = 6.29638 * (sum + j[6] * delta * delta / delta_star); - lamda = (lamda_0 + lamda_ex) / 1000; //lamda in [W/m/K] + lamda = (lamda_0 + lamda_ex) / 1000; // lamda in [W/m/K] return lamda; } @@ -1598,26 +1510,26 @@ double ch4_heat_conductivity (double rho, double T) Programming: NB Apr 2009 ***********************************************************************/ -double n2_viscosity (double rho, double T) +double n2_viscosity(double rho, double T) { - //OK411 const double M = 28.013; - //OK411 const double T_c = 126.2; //[K] - //OK411 const double P_c = 3.4; // [MPa] - const double rho_c = 314; // [kg/m3] - //OK411 const double T_t = 63.1; //[K] - const double CVF = 14.058; // [1e-3 Pa-s] + // OK411 const double M = 28.013; + // OK411 const double T_c = 126.2; //[K] + // OK411 const double P_c = 3.4; // [MPa] + const double rho_c = 314; // [kg/m3] + // OK411 const double T_t = 63.1; //[K] + const double CVF = 14.058; // [1e-3 Pa-s] const double sigma = 0.36502496e-09; const double k = 1.38062e-23; const double eps = 138.08483e-23; - //OK411 const double N_A = 6.02213E26; - //OK411 const double pi = 3.14159; + // OK411 const double N_A = 6.02213E26; + // OK411 const double pi = 3.14159; const double c1 = 0.3125; const double c2 = 2.0442e-49; - double A[5],C[5]; + double A[5], C[5]; - double sum = 0,eta, eta_0,eta_r,T_star,Omega = 0; + double sum = 0, eta, eta_0, eta_r, T_star, Omega = 0; int i; A[0] = 0.46649; @@ -1636,20 +1548,20 @@ double n2_viscosity (double rho, double T) rho = rho / rho_c; for (i = 0; i < 5; i++) - Omega = Omega + A[i] * MathLib::fastpow(log(T_star),i); + Omega = Omega + A[i] * MathLib::fastpow(log(T_star), i); - Omega = exp (Omega); + Omega = exp(Omega); - //eta in [Pa*s] + // eta in [Pa*s] eta_0 = c1 * sqrt(c2 * T) / (sigma * sigma * Omega); for (i = 2; i < 5; i++) - sum = sum + C[i] * MathLib::fastpow(rho,i - 1); + sum = sum + C[i] * MathLib::fastpow(rho, i - 1); // eta_r = CVF * 1e-6 * (C[0] / (rho - C[1]) + C[0] / C[1] + sum); - eta = (eta_0 + eta_r); // [Pa*s] + eta = (eta_0 + eta_r); // [Pa*s] return eta; } @@ -1665,18 +1577,18 @@ double n2_viscosity (double rho, double T) Programming: TN see Lemmon & Jacobson, Int J of Thermophys, 25(1), 2004 ***********************************************************************/ -double o2_heat_conductivity (double rho, double T) +double o2_heat_conductivity(double rho, double T) { - const double MM (32.0); // - const double sigma_squared (0.11751184); // nm^2 - const double ek (118.5); //K - const double T_c (154.581); //K - const double rho_c (13.63); + const double MM(32.0); // + const double sigma_squared(0.11751184); // nm^2 + const double ek(118.5); // K + const double T_c(154.581); // K + const double rho_c(13.63); rho /= MM; // convert density in mol/dm^3 - const double tau = T_c/T; - const double delta = rho/rho_c; + const double tau = T_c / T; + const double delta = rho / rho_c; double b[5]; @@ -1686,13 +1598,13 @@ double o2_heat_conductivity (double rho, double T) b[3] = 0.005341; b[4] = -0.00331; - double exponent (0); + double exponent(0); - for (unsigned i=0; i<5; i++) - exponent += b[i] * MathLib::fastpow(log(T/ek),i); + for (unsigned i = 0; i < 5; i++) + exponent += b[i] * MathLib::fastpow(log(T / ek), i); const double Omega = exp(exponent); - const double eta_0 = 0.0266958*pow(MM*T,0.5)/sigma_squared/Omega; + const double eta_0 = 0.0266958 * pow(MM * T, 0.5) / sigma_squared / Omega; double N[9], t[8]; N[0] = 1.036; @@ -1714,7 +1626,8 @@ double o2_heat_conductivity (double rho, double T) t[6] = 0.5; t[7] = 1.8; - const double lam_0 = N[0] * eta_0 + N[1]*pow(tau,t[0]) + N[2]*pow(tau,t[1]); //note counting is different due to different array sizes + const double lam_0 = N[0] * eta_0 + N[1] * pow(tau, t[0]) + + N[2] * pow(tau, t[1]); // note counting is different due to different array sizes int d[6], l[6], gamma[6]; @@ -1739,15 +1652,15 @@ double o2_heat_conductivity (double rho, double T) gamma[4] = 1; gamma[5] = 1; - double lam_r (0); + double lam_r(0); - for (unsigned i=0; i<6; i++) + for (unsigned i = 0; i < 6; i++) { - lam_r += N[i+3]*pow(tau,t[i+2])*MathLib::fastpow(delta,d[i])*exp(-gamma[i]*MathLib::fastpow(delta,l[i])); + lam_r += N[i + 3] * pow(tau, t[i + 2]) * MathLib::fastpow(delta, d[i]) + * exp(-gamma[i] * MathLib::fastpow(delta, l[i])); } - return (lam_0 + lam_r)*1e-3; //convert mW/m/K into W/m/K - + return (lam_0 + lam_r) * 1e-3; // convert mW/m/K into W/m/K } /********************************************************************** @@ -1761,27 +1674,27 @@ double o2_heat_conductivity (double rho, double T) Programming: NB Apr 2009 ***********************************************************************/ -double n2_heat_conductivity (double rho, double T) +double n2_heat_conductivity(double rho, double T) { const double X1 = 0.95185202; const double X2 = 1.0205422; - const double rho_c = 314; // [kg/m3] + const double rho_c = 314; // [kg/m3] const double M = 28.013; const double k = 1.38062e-23; const double eps = 138.08483e-23; const double N_A = 6.02213E26; const double R = 8.31434; - const double CCF = 4.173; //mW/m/K + const double CCF = 4.173; // mW/m/K const double c1 = 0.3125; const double c2 = 2.0442e-49; const double sigma = 0.36502496e-09; double F; - double A[5],f[9],C[4]; - double sum = 0,eta_0,c_v0,T_star,Omega = 0; - double lamda_tr,lamda_in,lamda_r,lamda_0,lamda; + double A[5], f[9], C[4]; + double sum = 0, eta_0, c_v0, T_star, Omega = 0; + double lamda_tr, lamda_in, lamda_r, lamda_0, lamda; int i; @@ -1811,8 +1724,8 @@ double n2_heat_conductivity (double rho, double T) // dilute heat conductivity for (i = 0; i < 7; i++) - sum = sum + f[i] * pow(T,(i - 3)); - const double temp (exp ((f[8] / T)) - 1); + sum = sum + f[i] * pow(T, (i - 3)); + const double temp(exp((f[8] / T)) - 1); c_v0 = R * (sum + ((f[7] * (f[8] / T) * (f[8] / T) * (exp((f[8] / T)))) / (temp * temp) - 1)); sum = 0; @@ -1821,10 +1734,10 @@ double n2_heat_conductivity (double rho, double T) // dilute gas viscosity for (i = 0; i < 5; i++) - Omega = Omega + A[i] * MathLib::fastpow(log(T_star),i); - Omega = exp (Omega); + Omega = Omega + A[i] * MathLib::fastpow(log(T_star), i); + Omega = exp(Omega); - //eta in [Pa*s] + // eta in [Pa*s] eta_0 = 1e6 * (c1 * sqrt(c2 * T) / (sigma * sigma * Omega)); F = eta_0 * k * N_A / (M * 1000); @@ -1835,11 +1748,11 @@ double n2_heat_conductivity (double rho, double T) lamda_0 = F * (lamda_tr + lamda_in); sum = 0; for (i = 0; i < 4; i++) - sum = sum + C[i] * MathLib::fastpow(rho,(i + 1)); + sum = sum + C[i] * MathLib::fastpow(rho, (i + 1)); lamda_r = sum * CCF; - lamda = (lamda_0 + lamda_r) / 1000; //lamda in [W/m/K] + lamda = (lamda_0 + lamda_r) / 1000; // lamda in [W/m/K] return lamda; } @@ -1860,26 +1773,26 @@ double n2_heat_conductivity (double rho, double T) *************************************************************/ double vapour_pressure_IF97(double T) { - double A,B,C,theta,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10; - n1 = 0.11670521452767e+04; + double A, B, C, theta, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10; + n1 = 0.11670521452767e+04; n2 = -0.72421316703206e+06; n3 = -0.17073846940092e+02; - n4 = 0.12020824702470e+05; + n4 = 0.12020824702470e+05; n5 = -0.32325550322333e+07; - n6 = 0.14915108613530e+02; + n6 = 0.14915108613530e+02; n7 = -0.48232657361591e+04; - n8 = 0.40511340542057e+06; + n8 = 0.40511340542057e+06; n9 = -0.23855557567849e+00; - n10 = 0.65017534844798e+03; + n10 = 0.65017534844798e+03; theta = T + n9 / (T - n10); - double theta_sqr (theta * theta); - A = theta_sqr + n1 * theta + n2; + double theta_sqr(theta * theta); + A = theta_sqr + n1 * theta + n2; B = n3 * theta_sqr + n4 * theta + n5; C = n6 * theta_sqr + n7 * theta + n8; double h; - h = MathLib::fastpow((2.0 * C / (-B + sqrt(B * B - 4.0 * A * C))),4) * 10.0; + h = MathLib::fastpow((2.0 * C / (-B + sqrt(B * B - 4.0 * A * C))), 4) * 10.0; return h; } @@ -1897,7 +1810,7 @@ double vapour_pressure_ch4(double T) const double pc = 4592200; double theta; - double n1,n2,n3,n4,h; + double n1, n2, n3, n4, h; n1 = -6.036219; n2 = 1.409359; @@ -1905,7 +1818,7 @@ double vapour_pressure_ch4(double T) n4 = -1.443048; theta = (1 - T / Tc); - h = Tc / T * (n1 * theta + n2 * pow(theta,1.5) + n3 * theta * theta + n4 * pow(theta,4.5)); + h = Tc / T * (n1 * theta + n2 * pow(theta, 1.5) + n3 * theta * theta + n4 * pow(theta, 4.5)); return exp(h) * pc; } @@ -1924,7 +1837,7 @@ double vapour_pressure_h2o(double T) const double Tc = 647.096; const double pc = 22064000; - double a1,a2,a3,a4,a5,a6,h; + double a1, a2, a3, a4, a5, a6, h; a1 = -7.85951783; a2 = 1.84408259; a3 = -11.7866497; @@ -1934,13 +1847,9 @@ double vapour_pressure_h2o(double T) theta = (1 - T / Tc); - h = Tc / T * - (a1 * theta + a2 * - pow(theta, - 1.5) + a3 * - MathLib::fastpow(theta, - 3) + a4 * - pow(theta,3.5) + a5 * MathLib::fastpow(theta,4) + a6 * MathLib::fastpow(theta,7)); + h = Tc / T * (a1 * theta + a2 * pow(theta, 1.5) + a3 * MathLib::fastpow(theta, 3) + a4 * pow(theta, 3.5) + + a5 * MathLib::fastpow(theta, 4) + + a6 * MathLib::fastpow(theta, 7)); return exp(h) * pc; } @@ -1952,9 +1861,9 @@ double vapour_pressure_h2o(double T) May 2009 Last modification: NB Jun 2009 *************************************************************/ -double dpressure(double TT, double PP,int fluid, double ds) +double dpressure(double TT, double PP, int fluid, double ds) { - //return PP-pressure(ds, TT, fluid)*1.0E-5; + // return PP-pressure(ds, TT, fluid)*1.0E-5; return PP - pressure(ds, TT, fluid); } @@ -1963,7 +1872,7 @@ double dpressure(double TT, double PP,int fluid, double ds) May 2009 Last modification: *************************************************************/ -inline float SIGN(const double &a, const float &b) +inline float SIGN(const double& a, const float& b) { return (float)(b >= 0 ? (a >= 0 ? a : -a) : (a >= 0 ? -a : a)); } @@ -1975,103 +1884,101 @@ inline float SIGN(const double &a, const float &b) May 2009 Last modification: NB Jun 2009 *************************************************************/ -void auswahl (double T, double P, int fluid, double* x1, double* x2, double eps) +void auswahl(double T, double P, int fluid, double* x1, double* x2, double eps) { - eps = eps; //OK411 + eps = eps; // OK411 switch (fluid) { - case 0: //CO2 - *x1 = 0.0005; - *x2 = 2000.0; + case 0: // CO2 + *x1 = 0.0005; + *x2 = 2000.0; - if (T < 304.128) //gas or liquid - { - if (P < (vapour_pressure_co2(T))) // gas - { - *x1 = 5e-4; //min_density; - *x2 = vapour_saturation_density_co2(T); - } - else // liquid + if (T < 304.128) // gas or liquid { - *x1 = liquid_saturation_density_co2(T); - *x2 = 2000; //max_density; + if (P < (vapour_pressure_co2(T))) // gas + { + *x1 = 5e-4; // min_density; + *x2 = vapour_saturation_density_co2(T); + } + else // liquid + { + *x1 = liquid_saturation_density_co2(T); + *x2 = 2000; // max_density; + } } - } - - break; - case 1: //Water - if(T < 647.096 && P > (vapour_pressure_h2o(T))) - { - *x2 = 1500.0; - if(T <= 440.0) - *x1 = 9.0e+2; - if(T > 440.0 && T < 573.15) - *x1 = 7.1e+2; - if(T >= 573.15) - *x1 = 3.0e+2; - } - else - { - *x1 = 1.0e-8; - *x2 = 2000; - if(T < 423.0) - *x2 = 2.6; - if(T < 400.0) - *x2 = 1.4; - if(T < 335.0) - *x2 = 0.15; - } - - break; - case 2: //Methane - *x1 = 0.0005; //min_density - *x2 = 600; //max_density - - if (T < 190.564) //gas or liquid - { - if (P < (vapour_pressure_ch4(T))) // gas + break; + case 1: // Water + if (T < 647.096 && P > (vapour_pressure_h2o(T))) { - *x1 = 5e-4; //min_density; - *x2 = vapour_saturation_density_ch4(T); + *x2 = 1500.0; + if (T <= 440.0) + *x1 = 9.0e+2; + if (T > 440.0 && T < 573.15) + *x1 = 7.1e+2; + if (T >= 573.15) + *x1 = 3.0e+2; } - else // liquid + else { - *x1 = liquid_saturation_density_ch4(T); - *x2 = 600; //max_density; + *x1 = 1.0e-8; + *x2 = 2000; + if (T < 423.0) + *x2 = 2.6; + if (T < 400.0) + *x2 = 1.4; + if (T < 335.0) + *x2 = 0.15; } - } - break; - case 3: //Nitrogen - { - *x1 = 0.005; //min_density - *x2 = 2000; //max_density + break; - if (T < 126.192) //gas or liquid - { - if (P < (vapour_pressure_n2(T))) // gas + case 2: // Methane + *x1 = 0.0005; // min_density + *x2 = 600; // max_density + + if (T < 190.564) // gas or liquid { - *x1 = 5e-4; //min_density; - *x2 = vapour_saturation_density_n2(T); + if (P < (vapour_pressure_ch4(T))) // gas + { + *x1 = 5e-4; // min_density; + *x2 = vapour_saturation_density_ch4(T); + } + else // liquid + { + *x1 = liquid_saturation_density_ch4(T); + *x2 = 600; // max_density; + } } - else // liquid + break; + case 3: // Nitrogen + + { + *x1 = 0.005; // min_density + *x2 = 2000; // max_density + + if (T < 126.192) // gas or liquid { - *x1 = liquid_saturation_density_n2(T); - *x2 = 2000; //max_density; + if (P < (vapour_pressure_n2(T))) // gas + { + *x1 = 5e-4; // min_density; + *x2 = vapour_saturation_density_n2(T); + } + else // liquid + { + *x1 = liquid_saturation_density_n2(T); + *x2 = 2000; // max_density; + } } } - } - break; + break; } } - - //****************************************************************************80 -double zero ( double T, double P, int fluid, double t) +double zero(double T, double P, int fluid, double t) //****************************************************************************80 // @@ -2129,131 +2036,130 @@ double zero ( double T, double P, int fluid, double t) // and temperature. // { - double c; - double d; - double e; - double fa; - double fb; - double fc; - double m; - double macheps; - double p; - double q; - double r; - double s; - double sa; - double sb; - double tol; -// -// Make local copies of A and B. -// - double a, b; - auswahl(T,P,fluid,&a,&b,t); - - sa = a; - sb = b; - fa = dpressure(T, P, fluid, sa); - fb = dpressure(T, P, fluid, sb); - - c = sa; - fc = fa; - e = sb - sa; - d = e; - - macheps = std::numeric_limits::epsilon(); - - for ( ; ; ) - { - if ( std::abs ( fc ) < std::abs ( fb ) ) - { - sa = sb; - sb = c; - c = sa; - fa = fb; - fb = fc; - fc = fa; - } - - tol = 2.0 * macheps * std::abs ( sb ) + t; - m = 0.5 * ( c - sb ); - - if ( std::abs ( m ) <= tol || fb == 0.0 ) - { - break; - } - - if ( std::abs ( e ) < tol || std::abs ( fa ) <= std::abs ( fb ) ) - { - e = m; - d = e; - } - else - { - s = fb / fa; - - if ( sa == c ) - { - p = 2.0 * m * s; - q = 1.0 - s; - } - else - { - q = fa / fc; - r = fb / fc; - p = s * ( 2.0 * m * q * ( q - r ) - ( sb - sa ) * ( r - 1.0 ) ); - q = ( q - 1.0 ) * ( r - 1.0 ) * ( s - 1.0 ); - } - - if ( 0.0 < p ) - { - q = - q; - } - else - { - p = - p; - } - - s = e; - e = d; - - if ( 2.0 * p < 3.0 * m * q - std::abs ( tol * q ) && - p < std::abs ( 0.5 * s * q ) ) - { - d = p / q; - } - else - { - e = m; - d = e; - } - } - sa = sb; - fa = fb; - - if ( tol < std::abs ( d ) ) - { - sb = sb + d; - } - else if ( 0.0 < m ) - { - sb = sb + tol; - } - else - { - sb = sb - tol; - } - - fb = dpressure( T, P, fluid, sb); - - if ( ( 0.0 < fb && 0.0 < fc ) || ( fb <= 0.0 && fc <= 0.0 ) ) - { - c = sa; - fc = fa; - e = sb - sa; - d = e; - } - } - return sb; + double c; + double d; + double e; + double fa; + double fb; + double fc; + double m; + double macheps; + double p; + double q; + double r; + double s; + double sa; + double sb; + double tol; + // + // Make local copies of A and B. + // + double a, b; + auswahl(T, P, fluid, &a, &b, t); + + sa = a; + sb = b; + fa = dpressure(T, P, fluid, sa); + fb = dpressure(T, P, fluid, sb); + + c = sa; + fc = fa; + e = sb - sa; + d = e; + + macheps = std::numeric_limits::epsilon(); + + for (;;) + { + if (std::abs(fc) < std::abs(fb)) + { + sa = sb; + sb = c; + c = sa; + fa = fb; + fb = fc; + fc = fa; + } + + tol = 2.0 * macheps * std::abs(sb) + t; + m = 0.5 * (c - sb); + + if (std::abs(m) <= tol || fb == 0.0) + { + break; + } + + if (std::abs(e) < tol || std::abs(fa) <= std::abs(fb)) + { + e = m; + d = e; + } + else + { + s = fb / fa; + + if (sa == c) + { + p = 2.0 * m * s; + q = 1.0 - s; + } + else + { + q = fa / fc; + r = fb / fc; + p = s * (2.0 * m * q * (q - r) - (sb - sa) * (r - 1.0)); + q = (q - 1.0) * (r - 1.0) * (s - 1.0); + } + + if (0.0 < p) + { + q = -q; + } + else + { + p = -p; + } + + s = e; + e = d; + + if (2.0 * p < 3.0 * m * q - std::abs(tol * q) && p < std::abs(0.5 * s * q)) + { + d = p / q; + } + else + { + e = m; + d = e; + } + } + sa = sb; + fa = fb; + + if (tol < std::abs(d)) + { + sb = sb + d; + } + else if (0.0 < m) + { + sb = sb + tol; + } + else + { + sb = sb - tol; + } + + fb = dpressure(T, P, fluid, sb); + + if ((0.0 < fb && 0.0 < fc) || (fb <= 0.0 && fc <= 0.0)) + { + c = sa; + fc = fa; + e = sb - sa; + d = e; + } + } + return sb; } /********************************************************************** @@ -2274,21 +2180,15 @@ double zero ( double T, double P, int fluid, double t) Programming: NB May 2009 ***********************************************************************/ -double mixing_ternary (double* x, - double* a, - double* b, - double* MM, - double* ra, - double* rb, - double* rMM) +double mixing_ternary(double* x, double* a, double* b, double* MM, double* ra, double* rb, double* rMM) { - int unsigned i,j,k; - double a_mix = 0,b_mix = 0,MM_mix = 0; + int unsigned i, j, k; + double a_mix = 0, b_mix = 0, MM_mix = 0; for (i = 0; i < 3; i++) for (j = 0; j < 3; j++) for (k = 0; k < 3; k++) - a_mix += x[i] * x[j] * x[k] * pow(a[i] * a[j] * a[k],(1. / 3.)); + a_mix += x[i] * x[j] * x[k] * pow(a[i] * a[j] * a[k], (1. / 3.)); for (i = 0; i < 3; i++) b_mix += x[i] * b[i]; @@ -2317,14 +2217,14 @@ double liquid_saturation_density_ch4(double T) const double rhoc = 162.66; double theta; - double n1,n2,n3,h; + double n1, n2, n3, h; n1 = 1.9906389; n2 = -0.78756197; n3 = 0.036976723; theta = (1 - T / Tc); - h = (n1 * pow(theta,0.354) + n2 * sqrt(theta) + n3 * pow(theta,(5. / 2.))); + h = (n1 * pow(theta, 0.354) + n2 * sqrt(theta) + n3 * pow(theta, (5. / 2.))); return exp(h) * rhoc; } @@ -2343,7 +2243,7 @@ double vapour_saturation_density_ch4(double T) const double rhoc = 162.66; double theta; - double n1,n2,n3,n4,n5,n6,h; + double n1, n2, n3, n4, n5, n6, h; n1 = -1.880284; n2 = -2.8526531; @@ -2353,17 +2253,9 @@ double vapour_saturation_density_ch4(double T) n6 = -37.553961; theta = (1 - T / Tc); - h = - (n1 * - pow(theta, - 0.354) + n2 * - pow(theta, - (5. / - 6.)) + n3 * - pow(theta, - (3. / - 2.)) + n4 * - pow(theta,(5. / 2.)) + n5 * pow(theta,(25. / 6.)) + n6 * pow(theta,(47. / 6.))); + h = (n1 * pow(theta, 0.354) + n2 * pow(theta, (5. / 6.)) + n3 * pow(theta, (3. / 2.)) + n4 * pow(theta, (5. / 2.)) + + n5 * pow(theta, (25. / 6.)) + + n6 * pow(theta, (47. / 6.))); return exp(h) * rhoc; } @@ -2382,7 +2274,7 @@ double vapour_pressure_n2(double T) const double pc = 3395800.; double theta; - double n1,n2,n3,n4,h; + double n1, n2, n3, n4, h; n1 = -6.12445284; n2 = 1.26327220; @@ -2390,11 +2282,7 @@ double vapour_pressure_n2(double T) n4 = -1.77570564; theta = (1 - T / Tc); - h = - (Tc / - T) * - (n1 * theta + n2 * - pow(theta,(1.5)) + n3 * pow(theta,(2.5)) + n4 * MathLib::fastpow(theta,(5))); + h = (Tc / T) * (n1 * theta + n2 * pow(theta, (1.5)) + n3 * pow(theta, (2.5)) + n4 * MathLib::fastpow(theta, (5))); return exp(h) * pc; } @@ -2413,7 +2301,7 @@ double liquid_saturation_density_n2(double T) const double rhoc = 313.3; double theta; - double n1,n2,n3,n4,h; //OK411 n5,n6, + double n1, n2, n3, n4, h; // OK411 n5,n6, n1 = 1.48654237; n2 = -0.280476066; @@ -2421,11 +2309,8 @@ double liquid_saturation_density_n2(double T) n4 = -0.119879866; theta = (1 - T / Tc); - h = - (n1 * - pow(theta, - 0.3294) + n2 * - pow(theta,(2. / 3.)) + n3 * pow(theta,(8. / 3.)) + n4 * pow(theta,(35. / 6.))); + h = (n1 * pow(theta, 0.3294) + n2 * pow(theta, (2. / 3.)) + n3 * pow(theta, (8. / 3.)) + + n4 * pow(theta, (35. / 6.))); return exp(h) * rhoc; } @@ -2444,7 +2329,7 @@ double vapour_saturation_density_n2(double T) const double rhoc = 313.3; double theta; - double n1,n2,n3,n4,n5,h; //OK411 n6, + double n1, n2, n3, n4, n5, h; // OK411 n6, n1 = -1.70127164; n2 = -3.70402649; @@ -2453,16 +2338,9 @@ double vapour_saturation_density_n2(double T) n5 = -2.68505381; theta = (1 - T / Tc); - h = - (Tc / - T) * - (n1 * - pow(theta, - 0.34) + n2 * - pow(theta, - (5. / - 6.)) + n3 * - pow(theta,(7. / 6.)) + n4 * pow(theta,(13. / 6.)) + n5 * pow(theta,(14. / 3.))); + h = (Tc / T) + * (n1 * pow(theta, 0.34) + n2 * pow(theta, (5. / 6.)) + n3 * pow(theta, (7. / 6.)) + n4 * pow(theta, (13. / 6.)) + + n5 * pow(theta, (14. / 3.))); return exp(h) * rhoc; } @@ -2480,7 +2358,7 @@ double liquid_saturation_density_co2(double T) const double Tc = 304.128; const double rhoc = 467.6; - double n[4],t[4],h = 0; + double n[4], t[4], h = 0; int i; n[0] = 1.9245108; @@ -2493,7 +2371,7 @@ double liquid_saturation_density_co2(double T) t[3] = (11. / 6.); for (i = 0; i < 4; i++) - h += n[i] * pow((1 - T / Tc),t[i]); + h += n[i] * pow((1 - T / Tc), t[i]); return exp(h) * rhoc; } @@ -2511,7 +2389,7 @@ double vapour_saturation_density_co2(double T) const double Tc = 304.128; const double rhoc = 467.6; - double n[5],t[5],h = 0; + double n[5], t[5], h = 0; int i; n[0] = -1.7074879; @@ -2526,7 +2404,7 @@ double vapour_saturation_density_co2(double T) t[4] = (14. / 3.); for (i = 0; i < 5; i++) - h += n[i] * pow((1 - T / Tc),t[i]); + h += n[i] * pow((1 - T / Tc), t[i]); return exp(h) * rhoc; } @@ -2536,1055 +2414,1055 @@ double vapour_saturation_density_co2(double T) returns the thermal properties of a given fluid Programming: NB Mar09 **********************************************************************/ -void CFluidProperties::therm_prop (string caption) +void CFluidProperties::therm_prop(string caption) { // CFluidProperties fpc; char letter; - int i,j; - //TODO: Change first letter approach to an integer (NB) - done (fluid_number) NB, 2009-06-02 + int i, j; + // TODO: Change first letter approach to an integer (NB) - done (fluid_number) NB, 2009-06-02 letter = caption[0]; Ru = 8.314472; switch (letter) { - case 'C': // CARBON DIOXIDE - { - fluid_id = 0; - rhoc = 467.6; // critical density [kg/m3] - Tc = 304.1282; // critical temperature [K] - pc = 7377300; // critical pressure [Pa] - Tt = 216.592; // triple point temperature [K] - pt = 517950; // triple point pressure [Pa] - Rs = 188.9241; // specific gas constant [J/kg/K] - molar_mass = 44.0099; // [g/mol] - omega = 0.22491; // azentric factor, see PREOS - Vd = 26.9; - Zc = 0.27468; //critical super-compressibility, see PREOS - n0=0.11333; - k3=0.28996; - m0 = 0.38493912223725674; - a = 383766.38336903340; - b = 0.026666761740035457; - k1 = 0.012304583901235679; - k2 = -0.14826846628826726; - // Limits sums in FHE-derivations - - limit[0] = 7; - limit[1] = 34; - limit[2] = 39; - limit[3] = 42; - - // Coefficients for FHE-derivations - - for (i = 0; i < 2; i++) - for (j = 0; j < 8; j++) - k[i][j] = 0; - - for (i = 0; i < 14; i++) - for (j = 0; j < 56; j++) - K[i][j] = 0; - - // ideal gas part - //a - k[0][0] = 8.37304456; - k[0][1] = -3.70454304; - k[0][2] = 2.5; - k[0][3] = 1.99427042; - k[0][4] = 0.62105248; - k[0][5] = 0.41195293; - k[0][6] = 1.04028922; - k[0][7] = 0.08327678; - //theta - k[1][0] = 0; - k[1][1] = 0; - k[1][2] = 0; - k[1][3] = 3.15163; - k[1][4] = 6.1119; - k[1][5] = 6.77708; - k[1][6] = 11.32384; - k[1][7] = 27.08792; - - //real gas part - - //n - K[0][0] = 3.8856823203161E-01; - K[0][1] = 2.9385475942740E+00; - K[0][2] = -5.5867188534934E+00; - K[0][3] = -7.6753199592477E-01; - K[0][4] = 3.1729005580416E-01; - K[0][5] = 5.4803315897767E-01; - K[0][6] = 1.2279411220335E-01; - K[0][7] = 2.1658961543220E+00; - K[0][8] = 1.5841735109724E+00; - K[0][9] = -2.3132705405503E-01; - K[0][10] = 5.8116916431436E-02; - K[0][11] = -5.5369137205382E-01; - K[0][12] = 4.8946615909422E-01; - K[0][13] = -2.4275739843501E-02; - K[0][14] = 6.2494790501678E-02; - K[0][15] = -1.2175860225246E-01; - K[0][16] = -3.7055685270086E-01; - K[0][17] = -1.6775879700426E-02; - K[0][18] = -1.1960736637987E-01; - K[0][19] = -4.5619362508778E-02; - K[0][20] = 3.5612789270346E-02; - K[0][21] = -7.4427727132052E-03; - K[0][22] = -1.7395704902432E-03; - K[0][23] = -2.1810121289527E-02; - K[0][24] = 2.4332166559236E-02; - K[0][25] = -3.7440133423463E-02; - K[0][26] = 1.4338715756878E-01; - K[0][27] = -1.3491969083286E-01; - K[0][28] = -2.3151225053480E-02; - K[0][29] = 1.2363125492901E-02; - K[0][30] = 2.1058321972940E-03; - K[0][31] = -3.3958519026368E-04; - K[0][32] = 5.5993651771592E-03; - K[0][33] = -3.0335118055646E-04; - K[0][34] = -2.1365488688320E+02; - K[0][35] = 2.6641569149272E+04; - K[0][36] = -2.4027212204557E+04; - K[0][37] = -2.8341603423999E+02; - K[0][38] = 2.1247284400179E+02; - K[0][39] = -6.6642276540751E-01; - K[0][40] = 7.2608632349897E-01; - K[0][41] = 5.5068668612842E-02; - - //d - K[1][0] = 1; - K[1][1] = 1; - K[1][2] = 1; - K[1][3] = 1; - K[1][4] = 2; - K[1][5] = 2; - K[1][6] = 3; - K[1][7] = 1; - K[1][8] = 2; - K[1][9] = 4; - K[1][10] = 5; - K[1][11] = 5; - K[1][12] = 5; - K[1][13] = 6; - K[1][14] = 6; - K[1][15] = 6; - K[1][16] = 1; - K[1][17] = 1; - K[1][18] = 4; - K[1][19] = 4; - K[1][20] = 4; - K[1][21] = 7; - K[1][22] = 8; - K[1][23] = 2; - K[1][24] = 3; - K[1][25] = 3; - K[1][26] = 5; - K[1][27] = 5; - K[1][28] = 6; - K[1][29] = 7; - K[1][30] = 8; - K[1][31] = 10; - K[1][32] = 4; - K[1][33] = 8; - K[1][34] = 2; - K[1][35] = 2; - K[1][36] = 2; - K[1][37] = 3; - K[1][38] = 3; - - //t - K[2][0] = 0; - K[2][1] = 0.75; - K[2][2] = 1; - K[2][3] = 2; - K[2][4] = 0.75; - K[2][5] = 2; - K[2][6] = 0.75; - K[2][7] = 1.5; - K[2][8] = 1.5; - K[2][9] = 2.5; - K[2][10] = 0; - K[2][11] = 1.5; - K[2][12] = 2; - K[2][13] = 0; - K[2][14] = 1; - K[2][15] = 2; - K[2][16] = 3; - K[2][17] = 6; - K[2][18] = 3; - K[2][19] = 6; - K[2][20] = 8; - K[2][21] = 6; - K[2][22] = 0; - K[2][23] = 7; - K[2][24] = 12; - K[2][25] = 16; - K[2][26] = 22; - K[2][27] = 24; - K[2][28] = 16; - K[2][29] = 24; - K[2][30] = 8; - K[2][31] = 2; - K[2][32] = 28; - K[2][33] = 14; - K[2][34] = 1; - K[2][35] = 0; - K[2][36] = 1; - K[2][37] = 3; - K[2][38] = 3; - - //c - K[3][7] = 1; - K[3][8] = 1; - K[3][9] = 1; - K[3][10] = 1; - K[3][11] = 1; - K[3][12] = 1; - K[3][13] = 1; - K[3][14] = 1; - K[3][15] = 1; - K[3][16] = 2; - K[3][17] = 2; - K[3][18] = 2; - K[3][19] = 2; - K[3][20] = 2; - K[3][21] = 2; - K[3][22] = 2; - K[3][23] = 3; - K[3][24] = 3; - K[3][25] = 3; - K[3][26] = 4; - K[3][27] = 4; - K[3][28] = 4; - K[3][29] = 4; - K[3][30] = 4; - K[3][31] = 4; - K[3][32] = 5; - K[3][33] = 6; - - //a - K[4][39] = 3.5; - K[4][40] = 3.5; - K[4][41] = 3; - //b - K[5][39] = 0.875; - K[5][40] = 0.925; - K[5][41] = 0.875; - //A - K[6][39] = 0.7; - K[6][40] = 0.7; - K[6][41] = 0.7; - //B - K[7][39] = 0.3; - K[7][40] = 0.3; - K[7][41] = 1; - //C - K[8][39] = 10; - K[8][40] = 10; - K[8][41] = 12.5; - //D - K[9][39] = 275; - K[9][40] = 275; - K[9][41] = 275; - - //alpha - K[10][34] = 25; - K[10][35] = 25; - K[10][36] = 25; - K[10][37] = 15; - K[10][38] = 20; - //beta - K[11][34] = 325; - K[11][35] = 300; - K[11][36] = 300; - K[11][37] = 275; - K[11][38] = 275; - K[11][39] = 0.3; - K[11][40] = 0.3; - K[11][41] = 0.3; - //gamma - K[12][34] = 1.16; - K[12][35] = 1.19; - K[12][36] = 1.19; - K[12][37] = 1.25; - K[12][38] = 1.22; - // epsilon - K[13][34] = 1; - K[13][35] = 1; - K[13][36] = 1; - K[13][37] = 1; - K[13][38] = 1; + case 'C': // CARBON DIOXIDE + { + fluid_id = 0; + rhoc = 467.6; // critical density [kg/m3] + Tc = 304.1282; // critical temperature [K] + pc = 7377300; // critical pressure [Pa] + Tt = 216.592; // triple point temperature [K] + pt = 517950; // triple point pressure [Pa] + Rs = 188.9241; // specific gas constant [J/kg/K] + molar_mass = 44.0099; // [g/mol] + omega = 0.22491; // azentric factor, see PREOS + Vd = 26.9; + Zc = 0.27468; // critical super-compressibility, see PREOS + n0 = 0.11333; + k3 = 0.28996; + m0 = 0.38493912223725674; + a = 383766.38336903340; + b = 0.026666761740035457; + k1 = 0.012304583901235679; + k2 = -0.14826846628826726; + // Limits sums in FHE-derivations + + limit[0] = 7; + limit[1] = 34; + limit[2] = 39; + limit[3] = 42; + + // Coefficients for FHE-derivations + + for (i = 0; i < 2; i++) + for (j = 0; j < 8; j++) + k[i][j] = 0; + + for (i = 0; i < 14; i++) + for (j = 0; j < 56; j++) + K[i][j] = 0; + + // ideal gas part + // a + k[0][0] = 8.37304456; + k[0][1] = -3.70454304; + k[0][2] = 2.5; + k[0][3] = 1.99427042; + k[0][4] = 0.62105248; + k[0][5] = 0.41195293; + k[0][6] = 1.04028922; + k[0][7] = 0.08327678; + // theta + k[1][0] = 0; + k[1][1] = 0; + k[1][2] = 0; + k[1][3] = 3.15163; + k[1][4] = 6.1119; + k[1][5] = 6.77708; + k[1][6] = 11.32384; + k[1][7] = 27.08792; + + // real gas part + + // n + K[0][0] = 3.8856823203161E-01; + K[0][1] = 2.9385475942740E+00; + K[0][2] = -5.5867188534934E+00; + K[0][3] = -7.6753199592477E-01; + K[0][4] = 3.1729005580416E-01; + K[0][5] = 5.4803315897767E-01; + K[0][6] = 1.2279411220335E-01; + K[0][7] = 2.1658961543220E+00; + K[0][8] = 1.5841735109724E+00; + K[0][9] = -2.3132705405503E-01; + K[0][10] = 5.8116916431436E-02; + K[0][11] = -5.5369137205382E-01; + K[0][12] = 4.8946615909422E-01; + K[0][13] = -2.4275739843501E-02; + K[0][14] = 6.2494790501678E-02; + K[0][15] = -1.2175860225246E-01; + K[0][16] = -3.7055685270086E-01; + K[0][17] = -1.6775879700426E-02; + K[0][18] = -1.1960736637987E-01; + K[0][19] = -4.5619362508778E-02; + K[0][20] = 3.5612789270346E-02; + K[0][21] = -7.4427727132052E-03; + K[0][22] = -1.7395704902432E-03; + K[0][23] = -2.1810121289527E-02; + K[0][24] = 2.4332166559236E-02; + K[0][25] = -3.7440133423463E-02; + K[0][26] = 1.4338715756878E-01; + K[0][27] = -1.3491969083286E-01; + K[0][28] = -2.3151225053480E-02; + K[0][29] = 1.2363125492901E-02; + K[0][30] = 2.1058321972940E-03; + K[0][31] = -3.3958519026368E-04; + K[0][32] = 5.5993651771592E-03; + K[0][33] = -3.0335118055646E-04; + K[0][34] = -2.1365488688320E+02; + K[0][35] = 2.6641569149272E+04; + K[0][36] = -2.4027212204557E+04; + K[0][37] = -2.8341603423999E+02; + K[0][38] = 2.1247284400179E+02; + K[0][39] = -6.6642276540751E-01; + K[0][40] = 7.2608632349897E-01; + K[0][41] = 5.5068668612842E-02; + + // d + K[1][0] = 1; + K[1][1] = 1; + K[1][2] = 1; + K[1][3] = 1; + K[1][4] = 2; + K[1][5] = 2; + K[1][6] = 3; + K[1][7] = 1; + K[1][8] = 2; + K[1][9] = 4; + K[1][10] = 5; + K[1][11] = 5; + K[1][12] = 5; + K[1][13] = 6; + K[1][14] = 6; + K[1][15] = 6; + K[1][16] = 1; + K[1][17] = 1; + K[1][18] = 4; + K[1][19] = 4; + K[1][20] = 4; + K[1][21] = 7; + K[1][22] = 8; + K[1][23] = 2; + K[1][24] = 3; + K[1][25] = 3; + K[1][26] = 5; + K[1][27] = 5; + K[1][28] = 6; + K[1][29] = 7; + K[1][30] = 8; + K[1][31] = 10; + K[1][32] = 4; + K[1][33] = 8; + K[1][34] = 2; + K[1][35] = 2; + K[1][36] = 2; + K[1][37] = 3; + K[1][38] = 3; + + // t + K[2][0] = 0; + K[2][1] = 0.75; + K[2][2] = 1; + K[2][3] = 2; + K[2][4] = 0.75; + K[2][5] = 2; + K[2][6] = 0.75; + K[2][7] = 1.5; + K[2][8] = 1.5; + K[2][9] = 2.5; + K[2][10] = 0; + K[2][11] = 1.5; + K[2][12] = 2; + K[2][13] = 0; + K[2][14] = 1; + K[2][15] = 2; + K[2][16] = 3; + K[2][17] = 6; + K[2][18] = 3; + K[2][19] = 6; + K[2][20] = 8; + K[2][21] = 6; + K[2][22] = 0; + K[2][23] = 7; + K[2][24] = 12; + K[2][25] = 16; + K[2][26] = 22; + K[2][27] = 24; + K[2][28] = 16; + K[2][29] = 24; + K[2][30] = 8; + K[2][31] = 2; + K[2][32] = 28; + K[2][33] = 14; + K[2][34] = 1; + K[2][35] = 0; + K[2][36] = 1; + K[2][37] = 3; + K[2][38] = 3; + + // c + K[3][7] = 1; + K[3][8] = 1; + K[3][9] = 1; + K[3][10] = 1; + K[3][11] = 1; + K[3][12] = 1; + K[3][13] = 1; + K[3][14] = 1; + K[3][15] = 1; + K[3][16] = 2; + K[3][17] = 2; + K[3][18] = 2; + K[3][19] = 2; + K[3][20] = 2; + K[3][21] = 2; + K[3][22] = 2; + K[3][23] = 3; + K[3][24] = 3; + K[3][25] = 3; + K[3][26] = 4; + K[3][27] = 4; + K[3][28] = 4; + K[3][29] = 4; + K[3][30] = 4; + K[3][31] = 4; + K[3][32] = 5; + K[3][33] = 6; + + // a + K[4][39] = 3.5; + K[4][40] = 3.5; + K[4][41] = 3; + // b + K[5][39] = 0.875; + K[5][40] = 0.925; + K[5][41] = 0.875; + // A + K[6][39] = 0.7; + K[6][40] = 0.7; + K[6][41] = 0.7; + // B + K[7][39] = 0.3; + K[7][40] = 0.3; + K[7][41] = 1; + // C + K[8][39] = 10; + K[8][40] = 10; + K[8][41] = 12.5; + // D + K[9][39] = 275; + K[9][40] = 275; + K[9][41] = 275; + + // alpha + K[10][34] = 25; + K[10][35] = 25; + K[10][36] = 25; + K[10][37] = 15; + K[10][38] = 20; + // beta + K[11][34] = 325; + K[11][35] = 300; + K[11][36] = 300; + K[11][37] = 275; + K[11][38] = 275; + K[11][39] = 0.3; + K[11][40] = 0.3; + K[11][41] = 0.3; + // gamma + K[12][34] = 1.16; + K[12][35] = 1.19; + K[12][36] = 1.19; + K[12][37] = 1.25; + K[12][38] = 1.22; + // epsilon + K[13][34] = 1; + K[13][35] = 1; + K[13][36] = 1; + K[13][37] = 1; + K[13][38] = 1; - break; - } - case 'W': // WATER - { - fluid_id = 1; - rhoc = 322; //[kg/m3] - Tc = 647.096; //[K] - pc = 22064000; // [Pa] - Tt = 273.16; // [K] - pt = 611.657; // [Pa] - Rs = 461.51805; // [J/kg/K] - molar_mass = 18.01528; // [g/mol] - omega = 0.344; // azentric factor, see PREOS - Vd = 25.14; - Zc = 0.22944; //critical super-compressibility, see PREOS - n0=0.1156; - k3=0.0471; - m0 = 0.47568277359898614; - a = 943391.02482869523; - b = 0.018971230469153735; - k1 = 0.017189421358489602; - k2 = -0.029385598856191408; - - - // Limits for Sums in FHE-derivations - - limit[0] = 7; - limit[1] = 51; - limit[2] = 54; - limit[3] = 56; - - // Coefficients for FHE-derivations - - for (i = 0; i < 2; i++) - for (j = 0; j < 8; j++) - k[i][j] = 0; - - for (i = 0; i < 14; i++) - for (j = 0; j < 56; j++) - K[i][j] = 0; - - // ideal gas part - - k[0][0] = -8.32044648201; - k[0][1] = 6.6832105268; - k[0][2] = 3.00632; - k[0][3] = 0.012436; - k[0][4] = 0.97315; - k[0][5] = 1.27950; - k[0][6] = 0.96956; - k[0][7] = 0.24873; - - k[1][0] = 0; - k[1][1] = 0; - k[1][2] = 0; - k[1][3] = 1.28728967; - k[1][4] = 3.53734222; - k[1][5] = 7.74073708; - k[1][6] = 9.24437796; - k[1][7] = 27.5075105; - - //real gas part - - K[0][0] = 1.2533547935523E-02; - K[0][1] = 7.8957634722828E+00; - K[0][2] = -8.7803203303561E+00; - K[0][3] = 3.1802509345418E-01; - K[0][4] = -2.6145533859358E-01; - K[0][5] = -7.8199751687981E-03; - K[0][6] = 8.8089493102134E-03; - K[0][7] = -6.6856572307965E-01; - K[0][8] = 2.0433810950965E-01; - K[0][9] = -6.6212605039687E-05; - K[0][10] = -1.9232721156002E-01; - K[0][11] = -2.5709043003438E-01; - K[0][12] = 1.6074868486251E-01; - K[0][13] = -4.0092828925807E-02; - K[0][14] = 3.9343422603254E-07; - - K[0][15] = -7.5941377088144E-06; - K[0][16] = 5.6250979351888E-04; - K[0][17] = -1.5608652257135E-05; - K[0][18] = 1.1537996422951E-09; - K[0][19] = 3.6582165144204E-07; - K[0][20] = -1.3251180074668E-12; - K[0][21] = -6.2639586912454E-10; - K[0][22] = -1.0793600908932E-01; - K[0][23] = 1.7611491008752E-02; - K[0][24] = 2.2132295167546E-01; - K[0][25] = -4.0247669763528E-01; - K[0][26] = 5.8083399985759E-01; - K[0][27] = 4.9969146990806E-03; - K[0][28] = -3.1358700712549E-02; - K[0][29] = -7.4315929710341E-01; - - K[0][30] = 4.7807329915480E-01; - K[0][31] = 2.0527940895948E-02; - K[0][32] = -1.3636435110343E-01; - K[0][33] = 1.4180634400617E-02; - K[0][34] = 8.3326504880713E-03; - K[0][35] = -2.9052336009585E-02; - K[0][36] = 3.8615085574206E-02; - K[0][37] = -2.0393486513704E-02; - K[0][38] = -1.6554050063734E-03; - K[0][39] = 1.9955571979541E-03; - K[0][40] = 1.5870308324157E-04; - K[0][41] = -1.6388568342530E-05; - K[0][42] = 4.3613615723811E-02; - K[0][43] = 3.4994005463765E-02; - K[0][44] = -7.6788197844621E-02; - - K[0][45] = 2.2446277332006E-02; - K[0][46] = -6.2689710414685E-05; - K[0][47] = -5.5711118565645E-10; - K[0][48] = -1.9905718354408E-01; - K[0][49] = 3.1777497330738E-01; - K[0][50] = -1.1841182425981E-01; - K[0][51] = -3.1306260323435E+01; - K[0][52] = 3.1546140237781E+01; - K[0][53] = -2.5213154341695E+03; - K[0][54] = -1.4874640856724E-01; - K[0][55] = 3.1806110878444E-01; - - K[1][0] = 1; - K[1][1] = 1; - K[1][2] = 1; - K[1][3] = 2; - K[1][4] = 2; - K[1][5] = 3; - K[1][6] = 4; - K[1][7] = 1; - K[1][8] = 1; - K[1][9] = 1; - K[1][10] = 2; - K[1][11] = 2; - K[1][12] = 3; - K[1][13] = 4; - K[1][14] = 4; - K[1][15] = 5; - K[1][16] = 7; - K[1][17] = 9; - K[1][18] = 10; - K[1][19] = 11; - K[1][20] = 13; - K[1][21] = 15; - K[1][22] = 1; - K[1][23] = 2; - K[1][24] = 2; - K[1][25] = 2; - K[1][26] = 3; - K[1][27] = 4; - K[1][28] = 4; - K[1][29] = 4; - K[1][30] = 5; - K[1][31] = 6; - K[1][32] = 6; - K[1][33] = 7; - K[1][34] = 9; - K[1][35] = 9; - K[1][36] = 9; - K[1][37] = 9; - K[1][38] = 9; - K[1][39] = 10; - K[1][40] = 10; - K[1][41] = 12; - K[1][42] = 3; - K[1][43] = 4; - K[1][44] = 4; - K[1][45] = 5; - K[1][46] = 14; - K[1][47] = 3; - K[1][48] = 6; - K[1][49] = 6; - K[1][50] = 6; - K[1][51] = 3; - K[1][52] = 3; - K[1][53] = 3; - - K[2][0] = -0.5; - K[2][1] = 0.875; - K[2][2] = 1; - K[2][3] = 0.5; - K[2][4] = 0.75; - K[2][5] = 0.375; - K[2][6] = 1; - K[2][7] = 4; - K[2][8] = 6; - K[2][9] = 12; - K[2][10] = 1; - K[2][11] = 5; - K[2][12] = 4; - K[2][13] = 2; - K[2][14] = 13; - K[2][15] = 9; - K[2][16] = 3; - K[2][17] = 4; - K[2][18] = 11; - K[2][19] = 4; - K[2][20] = 13; - K[2][21] = 1; - K[2][22] = 7; - K[2][23] = 1; - K[2][24] = 9; - K[2][25] = 10; - K[2][26] = 10; - K[2][27] = 3; - K[2][28] = 7; - K[2][29] = 10; - K[2][30] = 10; - K[2][31] = 6; - K[2][32] = 10; - K[2][33] = 10; - K[2][34] = 1; - K[2][35] = 2; - K[2][36] = 3; - K[2][37] = 4; - K[2][38] = 8; - K[2][39] = 6; - K[2][40] = 9; - K[2][41] = 8; - K[2][42] = 16; - K[2][43] = 22; - K[2][44] = 23; - K[2][45] = 23; - K[2][46] = 10; - K[2][47] = 50; - K[2][48] = 44; - K[2][49] = 46; - K[2][50] = 50; - K[2][51] = 0; - K[2][52] = 1; - K[2][53] = 4; - - K[3][7] = 1; - K[3][8] = 1; - K[3][9] = 1; - K[3][10] = 1; - K[3][11] = 1; - K[3][12] = 1; - K[3][13] = 1; - K[3][14] = 1; - K[3][15] = 1; - K[3][16] = 1; - K[3][17] = 1; - K[3][18] = 1; - K[3][19] = 1; - K[3][20] = 1; - K[3][21] = 1; - K[3][22] = 2; - K[3][23] = 2; - K[3][24] = 2; - K[3][25] = 2; - K[3][26] = 2; - K[3][27] = 2; - K[3][28] = 2; - K[3][29] = 2; - K[3][30] = 2; - K[3][31] = 2; - K[3][32] = 2; - K[3][33] = 2; - K[3][34] = 2; - K[3][35] = 2; - K[3][36] = 2; - K[3][37] = 2; - K[3][38] = 2; - K[3][39] = 2; - K[3][40] = 2; - K[3][41] = 2; - K[3][42] = 3; - K[3][43] = 3; - K[3][44] = 3; - K[3][45] = 3; - K[3][46] = 4; - K[3][47] = 6; - K[3][48] = 6; - K[3][49] = 6; - K[3][50] = 6; - - K[4][54] = 3.5; - K[4][55] = 3.5; - K[5][54] = 0.85; - K[5][55] = 0.95; - K[6][54] = 0.32; - K[6][55] = 0.32; - K[7][54] = 0.2; - K[7][55] = 0.2; - K[8][54] = 28; - K[8][55] = 32; - K[9][54] = 700; - K[9][55] = 800; - - K[10][51] = 20; - K[10][52] = 20; - K[10][53] = 20; - K[11][51] = 150; - K[11][52] = 150; - K[11][53] = 250; - K[11][54] = 0.3; - K[11][55] = 0.3; - K[12][51] = 1.21; - K[12][52] = 1.21; - K[12][53] = 1.25; - K[13][51] = 1; - K[13][52] = 1; - K[13][53] = 1; + break; + } + case 'W': // WATER + { + fluid_id = 1; + rhoc = 322; //[kg/m3] + Tc = 647.096; //[K] + pc = 22064000; // [Pa] + Tt = 273.16; // [K] + pt = 611.657; // [Pa] + Rs = 461.51805; // [J/kg/K] + molar_mass = 18.01528; // [g/mol] + omega = 0.344; // azentric factor, see PREOS + Vd = 25.14; + Zc = 0.22944; // critical super-compressibility, see PREOS + n0 = 0.1156; + k3 = 0.0471; + m0 = 0.47568277359898614; + a = 943391.02482869523; + b = 0.018971230469153735; + k1 = 0.017189421358489602; + k2 = -0.029385598856191408; + + // Limits for Sums in FHE-derivations + + limit[0] = 7; + limit[1] = 51; + limit[2] = 54; + limit[3] = 56; + + // Coefficients for FHE-derivations + + for (i = 0; i < 2; i++) + for (j = 0; j < 8; j++) + k[i][j] = 0; + + for (i = 0; i < 14; i++) + for (j = 0; j < 56; j++) + K[i][j] = 0; + + // ideal gas part + + k[0][0] = -8.32044648201; + k[0][1] = 6.6832105268; + k[0][2] = 3.00632; + k[0][3] = 0.012436; + k[0][4] = 0.97315; + k[0][5] = 1.27950; + k[0][6] = 0.96956; + k[0][7] = 0.24873; + + k[1][0] = 0; + k[1][1] = 0; + k[1][2] = 0; + k[1][3] = 1.28728967; + k[1][4] = 3.53734222; + k[1][5] = 7.74073708; + k[1][6] = 9.24437796; + k[1][7] = 27.5075105; + + // real gas part + + K[0][0] = 1.2533547935523E-02; + K[0][1] = 7.8957634722828E+00; + K[0][2] = -8.7803203303561E+00; + K[0][3] = 3.1802509345418E-01; + K[0][4] = -2.6145533859358E-01; + K[0][5] = -7.8199751687981E-03; + K[0][6] = 8.8089493102134E-03; + K[0][7] = -6.6856572307965E-01; + K[0][8] = 2.0433810950965E-01; + K[0][9] = -6.6212605039687E-05; + K[0][10] = -1.9232721156002E-01; + K[0][11] = -2.5709043003438E-01; + K[0][12] = 1.6074868486251E-01; + K[0][13] = -4.0092828925807E-02; + K[0][14] = 3.9343422603254E-07; + + K[0][15] = -7.5941377088144E-06; + K[0][16] = 5.6250979351888E-04; + K[0][17] = -1.5608652257135E-05; + K[0][18] = 1.1537996422951E-09; + K[0][19] = 3.6582165144204E-07; + K[0][20] = -1.3251180074668E-12; + K[0][21] = -6.2639586912454E-10; + K[0][22] = -1.0793600908932E-01; + K[0][23] = 1.7611491008752E-02; + K[0][24] = 2.2132295167546E-01; + K[0][25] = -4.0247669763528E-01; + K[0][26] = 5.8083399985759E-01; + K[0][27] = 4.9969146990806E-03; + K[0][28] = -3.1358700712549E-02; + K[0][29] = -7.4315929710341E-01; + + K[0][30] = 4.7807329915480E-01; + K[0][31] = 2.0527940895948E-02; + K[0][32] = -1.3636435110343E-01; + K[0][33] = 1.4180634400617E-02; + K[0][34] = 8.3326504880713E-03; + K[0][35] = -2.9052336009585E-02; + K[0][36] = 3.8615085574206E-02; + K[0][37] = -2.0393486513704E-02; + K[0][38] = -1.6554050063734E-03; + K[0][39] = 1.9955571979541E-03; + K[0][40] = 1.5870308324157E-04; + K[0][41] = -1.6388568342530E-05; + K[0][42] = 4.3613615723811E-02; + K[0][43] = 3.4994005463765E-02; + K[0][44] = -7.6788197844621E-02; + + K[0][45] = 2.2446277332006E-02; + K[0][46] = -6.2689710414685E-05; + K[0][47] = -5.5711118565645E-10; + K[0][48] = -1.9905718354408E-01; + K[0][49] = 3.1777497330738E-01; + K[0][50] = -1.1841182425981E-01; + K[0][51] = -3.1306260323435E+01; + K[0][52] = 3.1546140237781E+01; + K[0][53] = -2.5213154341695E+03; + K[0][54] = -1.4874640856724E-01; + K[0][55] = 3.1806110878444E-01; + + K[1][0] = 1; + K[1][1] = 1; + K[1][2] = 1; + K[1][3] = 2; + K[1][4] = 2; + K[1][5] = 3; + K[1][6] = 4; + K[1][7] = 1; + K[1][8] = 1; + K[1][9] = 1; + K[1][10] = 2; + K[1][11] = 2; + K[1][12] = 3; + K[1][13] = 4; + K[1][14] = 4; + K[1][15] = 5; + K[1][16] = 7; + K[1][17] = 9; + K[1][18] = 10; + K[1][19] = 11; + K[1][20] = 13; + K[1][21] = 15; + K[1][22] = 1; + K[1][23] = 2; + K[1][24] = 2; + K[1][25] = 2; + K[1][26] = 3; + K[1][27] = 4; + K[1][28] = 4; + K[1][29] = 4; + K[1][30] = 5; + K[1][31] = 6; + K[1][32] = 6; + K[1][33] = 7; + K[1][34] = 9; + K[1][35] = 9; + K[1][36] = 9; + K[1][37] = 9; + K[1][38] = 9; + K[1][39] = 10; + K[1][40] = 10; + K[1][41] = 12; + K[1][42] = 3; + K[1][43] = 4; + K[1][44] = 4; + K[1][45] = 5; + K[1][46] = 14; + K[1][47] = 3; + K[1][48] = 6; + K[1][49] = 6; + K[1][50] = 6; + K[1][51] = 3; + K[1][52] = 3; + K[1][53] = 3; + + K[2][0] = -0.5; + K[2][1] = 0.875; + K[2][2] = 1; + K[2][3] = 0.5; + K[2][4] = 0.75; + K[2][5] = 0.375; + K[2][6] = 1; + K[2][7] = 4; + K[2][8] = 6; + K[2][9] = 12; + K[2][10] = 1; + K[2][11] = 5; + K[2][12] = 4; + K[2][13] = 2; + K[2][14] = 13; + K[2][15] = 9; + K[2][16] = 3; + K[2][17] = 4; + K[2][18] = 11; + K[2][19] = 4; + K[2][20] = 13; + K[2][21] = 1; + K[2][22] = 7; + K[2][23] = 1; + K[2][24] = 9; + K[2][25] = 10; + K[2][26] = 10; + K[2][27] = 3; + K[2][28] = 7; + K[2][29] = 10; + K[2][30] = 10; + K[2][31] = 6; + K[2][32] = 10; + K[2][33] = 10; + K[2][34] = 1; + K[2][35] = 2; + K[2][36] = 3; + K[2][37] = 4; + K[2][38] = 8; + K[2][39] = 6; + K[2][40] = 9; + K[2][41] = 8; + K[2][42] = 16; + K[2][43] = 22; + K[2][44] = 23; + K[2][45] = 23; + K[2][46] = 10; + K[2][47] = 50; + K[2][48] = 44; + K[2][49] = 46; + K[2][50] = 50; + K[2][51] = 0; + K[2][52] = 1; + K[2][53] = 4; + + K[3][7] = 1; + K[3][8] = 1; + K[3][9] = 1; + K[3][10] = 1; + K[3][11] = 1; + K[3][12] = 1; + K[3][13] = 1; + K[3][14] = 1; + K[3][15] = 1; + K[3][16] = 1; + K[3][17] = 1; + K[3][18] = 1; + K[3][19] = 1; + K[3][20] = 1; + K[3][21] = 1; + K[3][22] = 2; + K[3][23] = 2; + K[3][24] = 2; + K[3][25] = 2; + K[3][26] = 2; + K[3][27] = 2; + K[3][28] = 2; + K[3][29] = 2; + K[3][30] = 2; + K[3][31] = 2; + K[3][32] = 2; + K[3][33] = 2; + K[3][34] = 2; + K[3][35] = 2; + K[3][36] = 2; + K[3][37] = 2; + K[3][38] = 2; + K[3][39] = 2; + K[3][40] = 2; + K[3][41] = 2; + K[3][42] = 3; + K[3][43] = 3; + K[3][44] = 3; + K[3][45] = 3; + K[3][46] = 4; + K[3][47] = 6; + K[3][48] = 6; + K[3][49] = 6; + K[3][50] = 6; + + K[4][54] = 3.5; + K[4][55] = 3.5; + K[5][54] = 0.85; + K[5][55] = 0.95; + K[6][54] = 0.32; + K[6][55] = 0.32; + K[7][54] = 0.2; + K[7][55] = 0.2; + K[8][54] = 28; + K[8][55] = 32; + K[9][54] = 700; + K[9][55] = 800; + + K[10][51] = 20; + K[10][52] = 20; + K[10][53] = 20; + K[11][51] = 150; + K[11][52] = 150; + K[11][53] = 250; + K[11][54] = 0.3; + K[11][55] = 0.3; + K[12][51] = 1.21; + K[12][52] = 1.21; + K[12][53] = 1.25; + K[13][51] = 1; + K[13][52] = 1; + K[13][53] = 1; - break; - } - case 'M': // METHANE - { - fluid_id = 2; - rhoc = 162.66; //[kg/m3] - Tc = 190.551; //[K] - pc = 4599200; // [Pa] - Tt = 90.685; // [K] - pt = 11696; // [Pa] - Rs = 518.3; // [J/kg/K] - molar_mass = 16.04; // [g/mol] - omega = 0.011; // azentric factor, see PREOS - Vd = 25.14; - Zc = 0.286060; //critical super-compressibility, see PREOS - n0=0.08248; - k3=0.20978; - m0 = 0.21389815179757277; - a = 206793.24123880462; - b = 0.026800319421855536; - k1 = 0.0019409288415128503; - k2 = -0.11003457942904071; - // Limits sums in FHE-derivations - - limit[0] = 13; - limit[1] = 36; - limit[2] = 40; - limit[3] = 40; - - // Coefficients for FHE-derivations - - for (i = 0; i < 2; i++) - for (j = 0; j < 8; j++) - k[i][j] = 0; - - for (i = 0; i < 14; i++) - for (j = 0; j < 56; j++) - K[i][j] = 0; - - // ideal gas part - - k[0][0] = 9.91243972; - k[0][1] = -6.33270087; - k[0][2] = 3.0016; - k[0][3] = 0.008449; - k[0][4] = 4.6942; - k[0][5] = 3.4865; - k[0][6] = 1.6572; - k[0][7] = 1.4115; - - k[1][0] = 0; - k[1][1] = 0; - k[1][2] = 0; - k[1][3] = 3.4004324; - k[1][4] = 10.26951575; - k[1][5] = 20.43932747; - k[1][6] = 29.93744884; - k[1][7] = 79.13351945; - - //real gas part - - K[0][0] = 4.368E-02; - K[0][1] = 6.709E-01; - K[0][2] = -1.766E+00; - K[0][3] = 8.582E-01; - K[0][4] = -1.207E+00; - K[0][5] = 5.120E-01; - K[0][6] = -4.000E-04; - K[0][7] = -1.248E-02; - K[0][8] = 3.100E-02; - K[0][9] = 1.755E-03; - K[0][10] = -3.172E-06; - K[0][11] = -2.240E-06; - K[0][12] = 2.947E-07; - K[0][13] = 1.830E-01; - K[0][14] = 1.512E-01; - K[0][15] = -4.289E-01; - K[0][16] = 6.894E-02; - K[0][17] = -1.408E-02; - K[0][18] = -3.063E-02; - K[0][19] = -2.970E-02; - K[0][20] = -1.932E-02; - K[0][21] = -1.106E-01; - K[0][22] = 9.953E-02; - K[0][23] = 8.548E-03; - K[0][24] = -6.151E-02; - K[0][25] = -4.292E-02; - K[0][26] = -1.813E-02; - K[0][27] = 3.446E-02; - K[0][28] = -2.386E-03; - K[0][29] = -1.159E-02; - K[0][30] = 6.642E-02; - K[0][31] = -2.372E-02; - K[0][32] = -3.962E-02; - K[0][33] = -1.387E-02; - K[0][34] = 3.389E-02; - K[0][35] = -2.927E-03; - K[0][36] = 9.325E-05; - K[0][37] = -6.287E+00; - K[0][38] = 1.271E+01; - K[0][39] = -6.424E+00; - - K[3][13] = 1; - K[3][14] = 1; - K[3][15] = 1; - K[3][16] = 1; - K[3][17] = 1; - K[3][18] = 1; - K[3][19] = 1; - K[3][20] = 2; - K[3][21] = 2; - K[3][22] = 2; - K[3][23] = 2; - K[3][24] = 2; - K[3][25] = 3; - K[3][26] = 3; - K[3][27] = 3; - K[3][28] = 3; - K[3][29] = 4; - K[3][30] = 4; - K[3][31] = 4; - K[3][32] = 4; - K[3][33] = 4; - K[3][34] = 4; - K[3][35] = 4; - - K[1][0] = 1; - K[1][1] = 1; - K[1][2] = 1; - K[1][3] = 2; - K[1][4] = 2; - K[1][5] = 2; - K[1][6] = 2; - K[1][7] = 3; - K[1][8] = 4; - K[1][9] = 4; - K[1][10] = 8; - K[1][11] = 9; - K[1][12] = 10; - K[1][13] = 1; - K[1][14] = 1; - K[1][15] = 1; - K[1][16] = 2; - K[1][17] = 4; - K[1][18] = 5; - K[1][19] = 6; - K[1][20] = 1; - K[1][21] = 2; - K[1][22] = 3; - K[1][23] = 4; - K[1][24] = 4; - K[1][25] = 3; - K[1][26] = 5; - K[1][27] = 5; - K[1][28] = 8; - K[1][29] = 2; - K[1][30] = 3; - K[1][31] = 4; - K[1][32] = 4; - K[1][33] = 4; - K[1][34] = 5; - K[1][35] = 6; - K[1][36] = 2; - K[1][37] = 0; - K[1][38] = 0; - K[1][39] = 0; - - K[2][0] = -0.5; - K[2][1] = 0.5; - K[2][2] = 1; - K[2][3] = 0.5; - K[2][4] = 1; - K[2][5] = 1.5; - K[2][6] = 4.5; - K[2][7] = 0; - K[2][8] = 1; - K[2][9] = 3; - K[2][10] = 1; - K[2][11] = 3; - K[2][12] = 3; - K[2][13] = 0; - K[2][14] = 1; - K[2][15] = 2; - K[2][16] = 0; - K[2][17] = 0; - K[2][18] = 2; - K[2][19] = 2; - K[2][20] = 5; - K[2][21] = 5; - K[2][22] = 5; - K[2][23] = 2; - K[2][24] = 4; - K[2][25] = 12; - K[2][26] = 8; - K[2][27] = 10; - K[2][28] = 10; - K[2][29] = 10; - K[2][30] = 14; - K[2][31] = 12; - K[2][32] = 18; - K[2][33] = 22; - K[2][34] = 18; - K[2][35] = 14; - K[2][36] = 2; - K[2][37] = 0; - K[2][38] = 1; - K[2][39] = 2; - K[10][36] = 20; - K[10][37] = 40; - K[10][38] = 40; - K[10][39] = 40; - K[11][36] = 200; - K[11][37] = 250; - K[11][38] = 250; - K[11][39] = 250; - K[12][36] = 1.07; - K[12][37] = 1.11; - K[12][38] = 1.11; - K[12][39] = 1.11; - K[13][36] = 1; - K[13][37] = 1; - K[13][38] = 1; - K[13][39] = 1; - break; - } - case 'N': // Nitrogen - { - fluid_id = 3; - rhoc = 314.0; //[kg/m3] - Tc = 126.20; //[K] - pc = 3383000; // [Pa] - Tt = 63.148; // [K] - pt = 12500; // [Pa] - Rs = 296.8; // [J/kg/K] - molar_mass = 28.013; // [g/mol] - omega = 0.039; // azentric factor, see PREOS - Vd = 18.5; - Zc = 0.287634; //critical super-compressibility, see PREOS - n0=0.09967; - k3=0.24086; - m0 = 0.23704245415214481; - a = 0.91551836047871149; - b = 0.024130615006680459; - k1 = 0.0025206904456128499; - k2 = -0.12498696464510012; - // Limits sums in FHE-derivations - limit[0] = 6; - limit[1] = 32; - limit[2] = 36; - limit[3] = 36; - - // Coefficients for FHE-derivations - // ideal gas part - k[0][0] = 9.912644; - k[0][1] = -6.333133; - k[0][2] = 3.0016; - k[0][3] = 0.008449; - k[0][4] = 4.6942; - k[0][5] = 3.4865; - k[0][6] = 1.6572; - k[0][7] = 1.4115; - - k[1][0] = 0; - k[1][1] = 0; - k[1][2] = 0; - k[1][3] = 3.400664; - k[1][4] = 10.27022; - k[1][5] = 20.44072; - k[1][6] = 29.93949; - k[1][7] = 79.13892; - - - //real gas part - K[0][0] = 0.924803575275; - K[0][1] = -0.492448489428; - K[0][2] = 0.661883336938; - K[0][3] = -0.192902649201e1; - K[0][4] = -0.622469309629e-1; - K[0][5] = 0.349943957581; - K[0][6] = 0.564857472498; - K[0][7] = -0.161720005987e1; - K[0][8] = -0.481395031883; - K[0][9] = 0.421150636384; - K[0][10] = -0.161962230825e-1; - K[0][11] = 0.172100994165; - K[0][12] = 0.735448924933e-2; - K[0][13] = 0.168077305479e-1; - K[0][14] = -0.107626664179e-2; - K[0][15] = -0.137318088513e-1; - K[0][16] = 0.635466899859e-3; - K[0][17] = 0.304432279419e-2; - K[0][18] = -0.435762336045e-1; - K[0][19] = -0.723174889316e-1; - K[0][20] = 0.389644315272e-1; - K[0][21] = -0.212201363910e-1; - K[0][22] = 0.408822981509e-2; - K[0][23] = -0.551990017984e-4; - K[0][24] = -0.462016716479e-1; - K[0][25] = -0.300311716011e-2; - K[0][26] = 0.368825891208e-1; - K[0][27] = -0.255856846220e-2; - K[0][28] = 0.896915264558e-2; - K[0][29] = -0.441513370350e-2; - K[0][30] = 0.133722924858e-2; - K[0][31] = 0.264832491957e-3; - K[0][32] = 0.196688194015e2; - K[0][33] = -0.209115600730e2; - K[0][34] = 0.167788306989e-1; - K[0][35] = 0.262767566274e4; - - K[1][0] = 1; - K[1][1] = 1; - K[1][2] = 2; - K[1][3] = 2; - K[1][4] = 3; - K[1][5] = 3; - K[1][6] = 1; - K[1][7] = 1; - K[1][8] = 1; - K[1][9] = 3; - K[1][10] = 3; - K[1][11] = 4; - K[1][12] = 6; - K[1][13] = 6; - K[1][14] = 7; - K[1][15] = 7; - K[1][16] = 8; - K[1][17] = 8; - K[1][18] = 1; - K[1][19] = 2; - K[1][20] = 3; - K[1][21] = 4; - K[1][22] = 5; - K[1][23] = 8; - K[1][24] = 4; - K[1][25] = 5; - K[1][26] = 5; - K[1][27] = 8; - K[1][28] = 3; - K[1][29] = 5; - K[1][30] = 6; - K[1][31] = 9; - K[1][32] = 1; - K[1][33] = 1; - K[1][34] = 3; - K[1][35] = 2; - - K[2][00] = 0.25; - K[2][01] = 0.875; - K[2][02] = 0.5; - K[2][03] = 0.875; - K[2][04] = 0.375; - K[2][05] = 0.75; - K[2][6] = 0.5; - K[2][7] = 0.75; - K[2][8] = 2; - K[2][9] = 1.25; - K[2][10] = 3.5; - K[2][11] = 1; - - K[2][12] = 0.5; - K[2][13] = 3; - K[2][14] = 0; - K[2][15] = 2.75; - K[2][16] = 0.75; - K[2][17] = 2.5; - K[2][18] = 4; - K[2][19] = 6; - K[2][20] = 6; - K[2][21] = 3; - K[2][22] = 3; - K[2][23] = 6; - K[2][24] = 16; - K[2][25] = 11; - K[2][26] = 15; - K[2][27] = 12; - K[2][28] = 12; - K[2][29] = 7; - K[2][30] = 4; - K[2][31] = 16; - K[2][32] = 0; - K[2][33] = 1; - K[2][34] = 2; - K[2][35] = 3; - - K[3][00] = 0; - K[3][01] = 0; - K[3][02] = 0; - K[3][03] = 0; - K[3][04] = 0; - K[3][05] = 0; - K[3][06] = 1; - K[3][07] = 1; - K[3][8] = 1; - K[3][9] = 1; - K[3][10] = 1; - K[3][11] = 1; - K[3][12] = 1; - K[3][13] = 1; - K[3][14] = 1; - K[3][15] = 1; - K[3][16] = 1; - K[3][17] = 1; - K[3][18] = 2; - K[3][19] = 2; - K[3][20] = 2; - K[3][21] = 2; - K[3][22] = 2; - K[3][23] = 2; - K[3][24] = 3; - K[3][25] = 3; - K[3][26] = 3; - K[3][27] = 3; - K[3][28] = 4; - K[3][29] = 4; - K[3][30] = 4; - K[3][31] = 4; - K[3][32] = 2; - K[3][33] = 2; - K[3][34] = 2; - K[3][35] = 2; - - K[10][32] = 20; - K[10][33] = 20; - K[10][34] = 15; - K[10][35] = 25; - K[11][32] = 325; - K[11][33] = 325; - K[11][34] = 300; - K[11][35] = 275; - K[12][32] = 1.16; - K[12][33] = 1.16; - K[12][34] = 1.13; - K[12][35] = 1.25; - K[13][32] = 1; - K[13][33] = 1; - K[13][34] = 1; - K[13][35] = 1; - break; - } + break; + } + case 'M': // METHANE + { + fluid_id = 2; + rhoc = 162.66; //[kg/m3] + Tc = 190.551; //[K] + pc = 4599200; // [Pa] + Tt = 90.685; // [K] + pt = 11696; // [Pa] + Rs = 518.3; // [J/kg/K] + molar_mass = 16.04; // [g/mol] + omega = 0.011; // azentric factor, see PREOS + Vd = 25.14; + Zc = 0.286060; // critical super-compressibility, see PREOS + n0 = 0.08248; + k3 = 0.20978; + m0 = 0.21389815179757277; + a = 206793.24123880462; + b = 0.026800319421855536; + k1 = 0.0019409288415128503; + k2 = -0.11003457942904071; + // Limits sums in FHE-derivations + + limit[0] = 13; + limit[1] = 36; + limit[2] = 40; + limit[3] = 40; + + // Coefficients for FHE-derivations + + for (i = 0; i < 2; i++) + for (j = 0; j < 8; j++) + k[i][j] = 0; + + for (i = 0; i < 14; i++) + for (j = 0; j < 56; j++) + K[i][j] = 0; + + // ideal gas part + + k[0][0] = 9.91243972; + k[0][1] = -6.33270087; + k[0][2] = 3.0016; + k[0][3] = 0.008449; + k[0][4] = 4.6942; + k[0][5] = 3.4865; + k[0][6] = 1.6572; + k[0][7] = 1.4115; + + k[1][0] = 0; + k[1][1] = 0; + k[1][2] = 0; + k[1][3] = 3.4004324; + k[1][4] = 10.26951575; + k[1][5] = 20.43932747; + k[1][6] = 29.93744884; + k[1][7] = 79.13351945; + + // real gas part + + K[0][0] = 4.368E-02; + K[0][1] = 6.709E-01; + K[0][2] = -1.766E+00; + K[0][3] = 8.582E-01; + K[0][4] = -1.207E+00; + K[0][5] = 5.120E-01; + K[0][6] = -4.000E-04; + K[0][7] = -1.248E-02; + K[0][8] = 3.100E-02; + K[0][9] = 1.755E-03; + K[0][10] = -3.172E-06; + K[0][11] = -2.240E-06; + K[0][12] = 2.947E-07; + K[0][13] = 1.830E-01; + K[0][14] = 1.512E-01; + K[0][15] = -4.289E-01; + K[0][16] = 6.894E-02; + K[0][17] = -1.408E-02; + K[0][18] = -3.063E-02; + K[0][19] = -2.970E-02; + K[0][20] = -1.932E-02; + K[0][21] = -1.106E-01; + K[0][22] = 9.953E-02; + K[0][23] = 8.548E-03; + K[0][24] = -6.151E-02; + K[0][25] = -4.292E-02; + K[0][26] = -1.813E-02; + K[0][27] = 3.446E-02; + K[0][28] = -2.386E-03; + K[0][29] = -1.159E-02; + K[0][30] = 6.642E-02; + K[0][31] = -2.372E-02; + K[0][32] = -3.962E-02; + K[0][33] = -1.387E-02; + K[0][34] = 3.389E-02; + K[0][35] = -2.927E-03; + K[0][36] = 9.325E-05; + K[0][37] = -6.287E+00; + K[0][38] = 1.271E+01; + K[0][39] = -6.424E+00; + + K[3][13] = 1; + K[3][14] = 1; + K[3][15] = 1; + K[3][16] = 1; + K[3][17] = 1; + K[3][18] = 1; + K[3][19] = 1; + K[3][20] = 2; + K[3][21] = 2; + K[3][22] = 2; + K[3][23] = 2; + K[3][24] = 2; + K[3][25] = 3; + K[3][26] = 3; + K[3][27] = 3; + K[3][28] = 3; + K[3][29] = 4; + K[3][30] = 4; + K[3][31] = 4; + K[3][32] = 4; + K[3][33] = 4; + K[3][34] = 4; + K[3][35] = 4; + + K[1][0] = 1; + K[1][1] = 1; + K[1][2] = 1; + K[1][3] = 2; + K[1][4] = 2; + K[1][5] = 2; + K[1][6] = 2; + K[1][7] = 3; + K[1][8] = 4; + K[1][9] = 4; + K[1][10] = 8; + K[1][11] = 9; + K[1][12] = 10; + K[1][13] = 1; + K[1][14] = 1; + K[1][15] = 1; + K[1][16] = 2; + K[1][17] = 4; + K[1][18] = 5; + K[1][19] = 6; + K[1][20] = 1; + K[1][21] = 2; + K[1][22] = 3; + K[1][23] = 4; + K[1][24] = 4; + K[1][25] = 3; + K[1][26] = 5; + K[1][27] = 5; + K[1][28] = 8; + K[1][29] = 2; + K[1][30] = 3; + K[1][31] = 4; + K[1][32] = 4; + K[1][33] = 4; + K[1][34] = 5; + K[1][35] = 6; + K[1][36] = 2; + K[1][37] = 0; + K[1][38] = 0; + K[1][39] = 0; + + K[2][0] = -0.5; + K[2][1] = 0.5; + K[2][2] = 1; + K[2][3] = 0.5; + K[2][4] = 1; + K[2][5] = 1.5; + K[2][6] = 4.5; + K[2][7] = 0; + K[2][8] = 1; + K[2][9] = 3; + K[2][10] = 1; + K[2][11] = 3; + K[2][12] = 3; + K[2][13] = 0; + K[2][14] = 1; + K[2][15] = 2; + K[2][16] = 0; + K[2][17] = 0; + K[2][18] = 2; + K[2][19] = 2; + K[2][20] = 5; + K[2][21] = 5; + K[2][22] = 5; + K[2][23] = 2; + K[2][24] = 4; + K[2][25] = 12; + K[2][26] = 8; + K[2][27] = 10; + K[2][28] = 10; + K[2][29] = 10; + K[2][30] = 14; + K[2][31] = 12; + K[2][32] = 18; + K[2][33] = 22; + K[2][34] = 18; + K[2][35] = 14; + K[2][36] = 2; + K[2][37] = 0; + K[2][38] = 1; + K[2][39] = 2; + K[10][36] = 20; + K[10][37] = 40; + K[10][38] = 40; + K[10][39] = 40; + K[11][36] = 200; + K[11][37] = 250; + K[11][38] = 250; + K[11][39] = 250; + K[12][36] = 1.07; + K[12][37] = 1.11; + K[12][38] = 1.11; + K[12][39] = 1.11; + K[13][36] = 1; + K[13][37] = 1; + K[13][38] = 1; + K[13][39] = 1; + break; + } + case 'N': // Nitrogen + { + fluid_id = 3; + rhoc = 314.0; //[kg/m3] + Tc = 126.20; //[K] + pc = 3383000; // [Pa] + Tt = 63.148; // [K] + pt = 12500; // [Pa] + Rs = 296.8; // [J/kg/K] + molar_mass = 28.013; // [g/mol] + omega = 0.039; // azentric factor, see PREOS + Vd = 18.5; + Zc = 0.287634; // critical super-compressibility, see PREOS + n0 = 0.09967; + k3 = 0.24086; + m0 = 0.23704245415214481; + a = 0.91551836047871149; + b = 0.024130615006680459; + k1 = 0.0025206904456128499; + k2 = -0.12498696464510012; + // Limits sums in FHE-derivations + limit[0] = 6; + limit[1] = 32; + limit[2] = 36; + limit[3] = 36; + + // Coefficients for FHE-derivations + // ideal gas part + k[0][0] = 9.912644; + k[0][1] = -6.333133; + k[0][2] = 3.0016; + k[0][3] = 0.008449; + k[0][4] = 4.6942; + k[0][5] = 3.4865; + k[0][6] = 1.6572; + k[0][7] = 1.4115; + + k[1][0] = 0; + k[1][1] = 0; + k[1][2] = 0; + k[1][3] = 3.400664; + k[1][4] = 10.27022; + k[1][5] = 20.44072; + k[1][6] = 29.93949; + k[1][7] = 79.13892; + + // real gas part + K[0][0] = 0.924803575275; + K[0][1] = -0.492448489428; + K[0][2] = 0.661883336938; + K[0][3] = -0.192902649201e1; + K[0][4] = -0.622469309629e-1; + K[0][5] = 0.349943957581; + K[0][6] = 0.564857472498; + K[0][7] = -0.161720005987e1; + K[0][8] = -0.481395031883; + K[0][9] = 0.421150636384; + K[0][10] = -0.161962230825e-1; + K[0][11] = 0.172100994165; + K[0][12] = 0.735448924933e-2; + K[0][13] = 0.168077305479e-1; + K[0][14] = -0.107626664179e-2; + K[0][15] = -0.137318088513e-1; + K[0][16] = 0.635466899859e-3; + K[0][17] = 0.304432279419e-2; + K[0][18] = -0.435762336045e-1; + K[0][19] = -0.723174889316e-1; + K[0][20] = 0.389644315272e-1; + K[0][21] = -0.212201363910e-1; + K[0][22] = 0.408822981509e-2; + K[0][23] = -0.551990017984e-4; + K[0][24] = -0.462016716479e-1; + K[0][25] = -0.300311716011e-2; + K[0][26] = 0.368825891208e-1; + K[0][27] = -0.255856846220e-2; + K[0][28] = 0.896915264558e-2; + K[0][29] = -0.441513370350e-2; + K[0][30] = 0.133722924858e-2; + K[0][31] = 0.264832491957e-3; + K[0][32] = 0.196688194015e2; + K[0][33] = -0.209115600730e2; + K[0][34] = 0.167788306989e-1; + K[0][35] = 0.262767566274e4; + + K[1][0] = 1; + K[1][1] = 1; + K[1][2] = 2; + K[1][3] = 2; + K[1][4] = 3; + K[1][5] = 3; + K[1][6] = 1; + K[1][7] = 1; + K[1][8] = 1; + K[1][9] = 3; + K[1][10] = 3; + K[1][11] = 4; + K[1][12] = 6; + K[1][13] = 6; + K[1][14] = 7; + K[1][15] = 7; + K[1][16] = 8; + K[1][17] = 8; + K[1][18] = 1; + K[1][19] = 2; + K[1][20] = 3; + K[1][21] = 4; + K[1][22] = 5; + K[1][23] = 8; + K[1][24] = 4; + K[1][25] = 5; + K[1][26] = 5; + K[1][27] = 8; + K[1][28] = 3; + K[1][29] = 5; + K[1][30] = 6; + K[1][31] = 9; + K[1][32] = 1; + K[1][33] = 1; + K[1][34] = 3; + K[1][35] = 2; + + K[2][00] = 0.25; + K[2][01] = 0.875; + K[2][02] = 0.5; + K[2][03] = 0.875; + K[2][04] = 0.375; + K[2][05] = 0.75; + K[2][6] = 0.5; + K[2][7] = 0.75; + K[2][8] = 2; + K[2][9] = 1.25; + K[2][10] = 3.5; + K[2][11] = 1; + + K[2][12] = 0.5; + K[2][13] = 3; + K[2][14] = 0; + K[2][15] = 2.75; + K[2][16] = 0.75; + K[2][17] = 2.5; + K[2][18] = 4; + K[2][19] = 6; + K[2][20] = 6; + K[2][21] = 3; + K[2][22] = 3; + K[2][23] = 6; + K[2][24] = 16; + K[2][25] = 11; + K[2][26] = 15; + K[2][27] = 12; + K[2][28] = 12; + K[2][29] = 7; + K[2][30] = 4; + K[2][31] = 16; + K[2][32] = 0; + K[2][33] = 1; + K[2][34] = 2; + K[2][35] = 3; + + K[3][00] = 0; + K[3][01] = 0; + K[3][02] = 0; + K[3][03] = 0; + K[3][04] = 0; + K[3][05] = 0; + K[3][06] = 1; + K[3][07] = 1; + K[3][8] = 1; + K[3][9] = 1; + K[3][10] = 1; + K[3][11] = 1; + K[3][12] = 1; + K[3][13] = 1; + K[3][14] = 1; + K[3][15] = 1; + K[3][16] = 1; + K[3][17] = 1; + K[3][18] = 2; + K[3][19] = 2; + K[3][20] = 2; + K[3][21] = 2; + K[3][22] = 2; + K[3][23] = 2; + K[3][24] = 3; + K[3][25] = 3; + K[3][26] = 3; + K[3][27] = 3; + K[3][28] = 4; + K[3][29] = 4; + K[3][30] = 4; + K[3][31] = 4; + K[3][32] = 2; + K[3][33] = 2; + K[3][34] = 2; + K[3][35] = 2; + + K[10][32] = 20; + K[10][33] = 20; + K[10][34] = 15; + K[10][35] = 25; + K[11][32] = 325; + K[11][33] = 325; + K[11][34] = 300; + K[11][35] = 275; + K[12][32] = 1.16; + K[12][33] = 1.16; + K[12][34] = 1.13; + K[12][35] = 1.25; + K[13][32] = 1; + K[13][33] = 1; + K[13][34] = 1; + K[13][35] = 1; + break; + } - case 'H': // Hydrogen; BG, 03/2012 - { - fluid_id = 4; - rhoc = 313.6; // [kg/m3] - Tc = 33.30; // [K] - pc = 1297000; // [Pa] - omega = -0.215; // azentric factor, see PREOS - molar_mass = 2.015894; - // Limits sums in FHE-derivations - break; - } - case 'O': // Oxygen - { - fluid_id = 5; - //rhoc = 313.6; // [kg/m3] - //Tc = 33.30; // [K] - //pc = 1297000; // [Pa] - //omega = -0.215; // azentric factor, see PREOS - //molar_mass = 2.015894; - // Limits sums in FHE-derivations - break; - } + case 'H': // Hydrogen; BG, 03/2012 + { + fluid_id = 4; + rhoc = 313.6; // [kg/m3] + Tc = 33.30; // [K] + pc = 1297000; // [Pa] + omega = -0.215; // azentric factor, see PREOS + molar_mass = 2.015894; + // Limits sums in FHE-derivations + break; + } + case 'O': // Oxygen + { + fluid_id = 5; + // rhoc = 313.6; // [kg/m3] + // Tc = 33.30; // [K] + // pc = 1297000; // [Pa] + // omega = -0.215; // azentric factor, see PREOS + // molar_mass = 2.015894; + // Limits sums in FHE-derivations + break; + } - default: cout << "Error in eos.cpp: no fluid name specified!" << "\n"; - break; + default: + cout << "Error in eos.cpp: no fluid name specified!" + << "\n"; + break; } } @@ -3593,19 +3471,19 @@ void CFluidProperties::therm_prop (string caption) //* note: P in bar! (1e5 Pa) //* Programming: NB, Sep10 //*****************************************************************************/ -//double DuanMixCompressibility(double T,double P,double V,CVirialCoefficients w) +// double DuanMixCompressibility(double T,double P,double V,CVirialCoefficients w) double DuanMixCompressibility(double T, double P, double V, VirialCoefficients w) { double R = 83.14472; - return P * V / R / T - 1 - w.B / V - w.C / (V * V) - w.D / (V * V * V * V) - w.E / (V * V * V - * V * V) - w.F / (V * V) * (w.b + w.G / (V * V)) * exp(-w.G / (V * V)); + return P * V / R / T - 1 - w.B / V - w.C / (V * V) - w.D / (V * V * V * V) - w.E / (V * V * V * V * V) + - w.F / (V * V) * (w.b + w.G / (V * V)) * exp(-w.G / (V * V)); } //**************************************************************************** //* returns the third root of a number x, -inf < x < inf //* Programming: NB, Sep10 //*****************************************************************************/ -inline double W3( double x) +inline double W3(double x) { if (x < 0) return -pow(fabs(x), 1. / 3.); @@ -3617,118 +3495,141 @@ inline double W3( double x) //* binary mixing coefficient for water and co2 , Duan 1992 //* Programming: NB, Sep10 //*****************************************************************************/ - double k_co2_h20(int number, double T) +double k_co2_h20(int number, double T) +{ + if (T < 373.15) { - if (T < 373.15) + switch (number) { - switch (number) - { - case 1: return 0.20611 + 0.0006 * T; - case 2: return 0.8023278 - 0.0022206 * T + 184.76824 / T; - case 3: return 1.80544 - 0.0032605 * T; - default: return 1; - } + case 1: + return 0.20611 + 0.0006 * T; + case 2: + return 0.8023278 - 0.0022206 * T + 184.76824 / T; + case 3: + return 1.80544 - 0.0032605 * T; + default: + return 1; } - else if (T > 673.15) + } + else if (T > 673.15) + { + switch (number) { - switch (number) - { - case 1: return 3.131 - 5.0624e-03 * T + 1.8641e-06 * T * T - 31.409 / T; - case 2: return -46.646 + 4.2877e-02 * T - 1.0892e-05 * T * T + 1.5782e+04 / - T; - case 3: return 0.9; - default: return 1; - } + case 1: + return 3.131 - 5.0624e-03 * T + 1.8641e-06 * T * T - 31.409 / T; + case 2: + return -46.646 + 4.2877e-02 * T - 1.0892e-05 * T * T + 1.5782e+04 / T; + case 3: + return 0.9; + default: + return 1; } - else if (T < 495.15) + } + else if (T < 495.15) + { + switch (number) { - switch (number) - { - case 1: return -10084.5042 - 4.27134485 * T + 256477.783 / T + - 0.00166997474 * T * T + 1816.78 * log(T); - case 2: return 9.000263 - 0.00623494 * T - 2307.7125 / T; - case 3: return -74.1163 + 0.1800496 * T - 1.40904946e-4 * T * T + - 101305246 / T; - default: return 1; - } + case 1: + return -10084.5042 - 4.27134485 * T + 256477.783 / T + 0.00166997474 * T * T + 1816.78 * log(T); + case 2: + return 9.000263 - 0.00623494 * T - 2307.7125 / T; + case 3: + return -74.1163 + 0.1800496 * T - 1.40904946e-4 * T * T + 101305246 / T; + default: + return 1; } - else - switch (number) - { - case 1: return -0.3568 + 7.8888e-4 * T + 333.399 / T; - case 2: return -19.97444 + 0.0192515 * T + 5707.4229 / T; - case 3: return 12.1308 - 0.0099489 * T - 3042.09583 / T; - default: return 1; - } - cout << " This text should not be printed, something is wrong!" << "\n"; - return 0; } + else + switch (number) + { + case 1: + return -0.3568 + 7.8888e-4 * T + 333.399 / T; + case 2: + return -19.97444 + 0.0192515 * T + 5707.4229 / T; + case 3: + return 12.1308 - 0.0099489 * T - 3042.09583 / T; + default: + return 1; + } + cout << " This text should not be printed, something is wrong!" + << "\n"; + return 0; +} //**************************************************************************** //* binary mixing coefficient for co2 and methane , Duan 1992 //* Programming: NB, Sep10 //*****************************************************************************/ - double k_co2_ch4 (int number, double T) +double k_co2_ch4(int number, double T) +{ + if (T < 304) { - if (T < 304) + switch (number) { - switch (number) - { - case 1: return 0.38; - case 2: return 1.74094 - 0.0058903 * T; - case 3: return 1.59; - default: return 1; - } + case 1: + return 0.38; + case 2: + return 1.74094 - 0.0058903 * T; + case 3: + return 1.59; + default: + return 1; } - else if (T > 498) - return 1; - else + } + else if (T > 498) + return 1; + else + { + switch (number) { - switch (number) - { - case 1: return 1.1; - case 2: return 3.211 - 0.00158 * T - 537.814 / T; - //case 3: return -0.7; - case 3: return 1.80544 - 0.0032605 * T; // aus F90 + case 1: + return 1.1; + case 2: + return 3.211 - 0.00158 * T - 537.814 / T; + // case 3: return -0.7; + case 3: + return 1.80544 - 0.0032605 * T; // aus F90 // case 3: return 12.1308 -0.0099489*T - 3042.09583/T; aus F90 - } } - cout << " This text should not be printed, something is wrong!" << "\n"; - return 0; } + cout << " This text should not be printed, something is wrong!" + << "\n"; + return 0; +} //**************************************************************************** //* binary mixing coefficient for water and methane , Duan 1992 //* Programming: NB, Sep10 //*****************************************************************************/ - double k_ch4_h2o (int number, double T) - { - (void)number; - (void)T; - // Not implemented yet! If you feel constrained to change this, you'll find the correlation in Duan, Moller and Weare ,1992. - return 1; - } +double k_ch4_h2o(int number, double T) +{ + (void)number; + (void)T; + // Not implemented yet! If you feel constrained to change this, you'll find the correlation in Duan, Moller and + // Weare ,1992. + return 1; +} //**************************************************************************** //* Parameters for Water, CO2 and Methane for Duan EOS //* //* Programming: NB, Sep10 //*****************************************************************************/ - void DuansParameter(int fluid, double a[14], double* Tc, double* Pc, double* M) +void DuansParameter(int fluid, double a[14], double* Tc, double* Pc, double* M) +{ + switch (fluid) { - switch (fluid) - { - case 0: //CO2, Duan 1992 + case 0: // CO2, Duan 1992 *Tc = 304.1282; - *Pc = 73.77300; //bar - *M = 44.01; // g/mol - a[0] = 8.99288497e-2; + *Pc = 73.77300; // bar + *M = 44.01; // g/mol + a[0] = 8.99288497e-2; a[1] = -4.94783127e-1; - a[2] = 4.77922245e-2; - a[3] = 1.03808883e-2; + a[2] = 4.77922245e-2; + a[3] = 1.03808883e-2; a[4] = -2.82516861e-2; - a[5] = 9.49887563e-2; - a[6] = 5.20600880e-4; + a[5] = 9.49887563e-2; + a[6] = 5.20600880e-4; a[7] = -2.93540971e-4; a[8] = -1.77265112e-3; a[9] = -2.51101973e-5; @@ -3738,30 +3639,30 @@ inline double W3( double x) a[13] = 1.398; a[14] = 2.96e-2; break; - case 1: //H2O Duan 1992 + case 1: // H2O Duan 1992 *Tc = 647.25; - *Pc = 221.19000; //bar - *M = 18.01; // g/mol - a[0] = 8.64449220E-02; - a[1] = -3.96918955E-01; - a[2] = -5.73334886E-02; - a[3] = -2.93893000E-04; - a[4] = -4.15775512E-03; - a[5] = 1.99496791E-02; - a[6] = 1.18901426E-04; - a[7] = 1.55212063E-04; - a[8] = -1.06855859E-04; - a[9] = -4.93197687E-06; - a[10] = -2.73739155E-06; - a[11] = 2.65571238E-06; - a[12] = 8.96079018E-03; - a[13] = 4.02000000E+00; - a[14] = 2.57000000E-02; + *Pc = 221.19000; // bar + *M = 18.01; // g/mol + a[0] = 8.64449220E-02; + a[1] = -3.96918955E-01; + a[2] = -5.73334886E-02; + a[3] = -2.93893000E-04; + a[4] = -4.15775512E-03; + a[5] = 1.99496791E-02; + a[6] = 1.18901426E-04; + a[7] = 1.55212063E-04; + a[8] = -1.06855859E-04; + a[9] = -4.93197687E-06; + a[10] = -2.73739155E-06; + a[11] = 2.65571238E-06; + a[12] = 8.96079018E-03; + a[13] = 4.02000000E+00; + a[14] = 2.57000000E-02; break; - case 2: //CH4 Duan 1992 + case 2: // CH4 Duan 1992 *Tc = 190.6; - *Pc = 46.41000; //bar - *M = 16.04; // g/mol + *Pc = 46.41000; // bar + *M = 16.04; // g/mol a[0] = 8.72553928E-02; a[1] = -7.52599476E-01; a[2] = 3.75419887E-01; @@ -3778,10 +3679,10 @@ inline double W3( double x) a[13] = 7.5397E-01; a[14] = 7.7167E-02; break; - case 5: // h20 Duan 2006 + case 5: // h20 Duan 2006 *Tc = 647.25; *Pc = 22119000; // bar - *M = 18.01; // g/mol + *M = 18.01; // g/mol a[0] = 4.38269941e-02; a[1] = -1.68244362e-01; a[2] = -2.36923373e-01; @@ -3798,10 +3699,10 @@ inline double W3( double x) a[13] = 2.51598931e+00; a[14] = 3.94000000e-02; break; - case 6: // co2 Duan 2006 + case 6: // co2 Duan 2006 *Tc = 304.1282; *Pc = 7377300; // bar - *M = 18.01; // g/mol + *M = 18.01; // g/mol a[0] = 1.14400435e-01; a[1] = -9.38526684e-01; a[2] = 7.21857006e-01; @@ -3819,42 +3720,42 @@ inline double W3( double x) a[14] = 1.58500000e-01; break; - default: break; - } + default: + break; } - +} //**************************************************************************** //* this function calls the binary mixing parameter for a certain condition //* //* Programming: NB, Sep10 //*****************************************************************************/ -double bip (int number, int fluid_a, int fluid_b, int i, int j, int k, double T) +double bip(int number, int fluid_a, int fluid_b, int i, int j, int k, double T) { - //number : k1, k2 or k3 - //fluid_a, fluid_b: a-b, b-c, a-c have different binary interaction parameters - //i,j,k : needed for mixing rule + // number : k1, k2 or k3 + // fluid_a, fluid_b: a-b, b-c, a-c have different binary interaction parameters + // i,j,k : needed for mixing rule // T : bip depends on Temperature - if ( ((number == 1) && - (i == j)) || (((number == 2) || (number == 3)) && ((i == j) && (i == k))) ) + if (((number == 1) && (i == j)) || (((number == 2) || (number == 3)) && ((i == j) && (i == k)))) return 1; else switch (fluid_a + fluid_b) { - case (1): // 2+3=5 --> CO2+H2O (duan 1992) or 0+1=1 --> CO2+H20 fo high pressure range, duan 2006 - return k_co2_h20(number, T); - case (5): // 2+3=5 --> CO2+H2O (duan 1992) or 0+1=1 --> CO2+H20 fo high pressure range, duan 2006 - return k_co2_h20(number, T); - - case 6: // 2+4=6 --> CO2+CH4 - return k_co2_ch4(number,T); - case 7: // 3+4=7 --> CH4+H2O - return k_co2_ch4(number, T); - default: - return 1; + case (1): // 2+3=5 --> CO2+H2O (duan 1992) or 0+1=1 --> CO2+H20 fo high pressure range, duan 2006 + return k_co2_h20(number, T); + case (5): // 2+3=5 --> CO2+H2O (duan 1992) or 0+1=1 --> CO2+H20 fo high pressure range, duan 2006 + return k_co2_h20(number, T); + + case 6: // 2+4=6 --> CO2+CH4 + return k_co2_ch4(number, T); + case 7: // 3+4=7 --> CH4+H2O + return k_co2_ch4(number, T); + default: + return 1; } - cout << " This text should not be printed, something is wrong!" << "\n"; + cout << " This text should not be printed, something is wrong!" + << "\n"; return 0; } @@ -3863,14 +3764,14 @@ double bip (int number, int fluid_a, int fluid_b, int i, int j, int k, double T) //* a temperature T //* Programming: NB, Sep10 //*****************************************************************************/ -//CVirialCoefficients DuansVirialCoefficients(int Fluid, double T) +// CVirialCoefficients DuansVirialCoefficients(int Fluid, double T) VirialCoefficients DuansVirialCoefficients(int Fluid, double T) { double a[15] = {}; double Tc = 0.0, Pc = 0.0, M = 0.0; double R = 83.14467; // cm��?bar/(K* mol) - //CVirialCoefficients x; //BG - VirialCoefficients x; //BG + // CVirialCoefficients x; //BG + VirialCoefficients x; // BG DuansParameter(Fluid, a, &Tc, &Pc, &M); double Tr = T / Tc; @@ -3900,131 +3801,112 @@ VirialCoefficients DuansVirialCoefficients(int Fluid, double T) //* //* Programming: NB, Sep10 //*****************************************************************************/ -//void MixDuansVirialCoefficients(CVirialCoefficients fluid_a, CVirialCoefficients fluid_b, double T, double x_0, CVirialCoefficients*mix) - void MixDuansVirialCoefficients(VirialCoefficients fluid_a, - VirialCoefficients fluid_b, - double T, - double x_0, - VirialCoefficients* mix) +// void MixDuansVirialCoefficients(CVirialCoefficients fluid_a, CVirialCoefficients fluid_b, double T, double x_0, +// CVirialCoefficients*mix) +void MixDuansVirialCoefficients( + VirialCoefficients fluid_a, VirialCoefficients fluid_b, double T, double x_0, VirialCoefficients* mix) +{ + // this code may look weird, I tried to avoid functions like pow() to increase speed + + double Bij, Cij, Dij, Eij, Fij, Gij; + double Vcij; + double B[2], C[2], D[2], E[2], F[2], G[2], bi[2], MM[2]; + double Vc[2]; + double x[2]; + + double BVc = 0; + double CVc = 0; + double DVc = 0; + double EVc = 0; + double FVc = 0; + double b = 0; + double GVc = 0; + + double Vcr = 0; + double M = 0; + + double V2, V3, V5, V6; + + Vc[0] = fluid_a.Vc; + Vc[1] = fluid_b.Vc; + MM[0] = fluid_a.M; + MM[1] = fluid_b.M; + + B[0] = fluid_a.B; + B[1] = fluid_b.B; + C[0] = fluid_a.C; + C[1] = fluid_b.C; + D[0] = fluid_a.D; + D[1] = fluid_b.D; + E[0] = fluid_a.E; + E[1] = fluid_b.E; + F[0] = fluid_a.F; + F[1] = fluid_b.F; + bi[0] = fluid_a.b; + bi[1] = fluid_b.b; + G[0] = fluid_a.G; + G[1] = fluid_b.G; + + x[0] = x_0; + x[1] = 1 - x[0]; + + for (int i = 0; i < 2; i++) { - // this code may look weird, I tried to avoid functions like pow() to increase speed - - double Bij,Cij,Dij,Eij,Fij,Gij; - double Vcij; - double B[2],C[2],D[2],E[2],F[2],G[2],bi[2],MM[2]; - double Vc[2]; - double x[2]; - - double BVc = 0; - double CVc = 0; - double DVc = 0; - double EVc = 0; - double FVc = 0; - double b = 0; - double GVc = 0; - - double Vcr = 0; - double M = 0; - - double V2,V3,V5,V6; - - Vc[0] = fluid_a.Vc; - Vc[1] = fluid_b.Vc; - MM[0] = fluid_a.M; - MM[1] = fluid_b.M; - - B[0] = fluid_a.B; - B[1] = fluid_b.B; - C[0] = fluid_a.C; - C[1] = fluid_b.C; - D[0] = fluid_a.D; - D[1] = fluid_b.D; - E[0] = fluid_a.E; - E[1] = fluid_b.E; - F[0] = fluid_a.F; - F[1] = fluid_b.F; - bi[0] = fluid_a.b; - bi[1] = fluid_b.b; - G[0] = fluid_a.G; - G[1] = fluid_b.G; - - x[0] = x_0; - x[1] = 1 - x[0]; - - for (int i = 0; i < 2; i++) + b += x[i] * bi[i]; + Vcr += x[i] * Vc[i]; + M += x[i] * MM[i]; + for (int j = 0; j < 2; j++) { - b += x[i] * bi[i]; - Vcr += x[i] * Vc[i]; - M += x[i] * MM[i]; - for (int j = 0; j < 2; j++) + double B1 = ((W3(B[i]) + W3(B[j])) / 2); + double F1 = ((W3(F[i]) + W3(F[j])) / 2); + V2 = ((W3(Vc[i]) + W3(Vc[j])) / 2); + + Bij = B1 * B1 * B1 * bip(1, fluid_a.id, fluid_b.id, i, j, 0, T); + Fij = F1 * F1 * F1; + Vcij = V2 * V2 * V2; + BVc += x[i] * x[j] * Bij * Vcij; + FVc += x[i] * x[j] * Fij * Vcij * Vcij; + for (int k = 0; k < 2; k++) { - double B1 = ((W3(B[i]) + W3(B[j])) / 2); - double F1 = ((W3(F[i]) + W3(F[j])) / 2); - V2 = ((W3(Vc[i]) + W3(Vc[j])) / 2); - - Bij = B1 * B1 * B1 * bip(1,fluid_a.id,fluid_b.id,i,j,0,T); - Fij = F1 * F1 * F1; - Vcij = V2 * V2 * V2; - BVc += x[i] * x[j] * Bij * Vcij; - FVc += x[i] * x[j] * Fij * Vcij * Vcij; - for (int k = 0; k < 2; k++) - { - double C1 = ((W3(C[i]) + W3(C[j]) + W3(C[k])) / 3); - double G1 = ((W3(G[i]) + W3(G[j]) + W3(G[k])) / 3); - V3 = ((W3(Vc[i]) + W3(Vc[j]) + W3(Vc[k])) / 3); - Cij = C1 * C1 * C1 * bip(2,fluid_a.id,fluid_b.id,i,j,k,T); - Gij = G1 * G1 * G1 * bip(3,fluid_a.id,fluid_b.id,i,j,k,T); - Vcij = V3 * V3 * V3; - CVc += x[i] * x[j] * x[k] * Cij * Vcij * Vcij; - GVc += x[i] * x[j] * x[k] * Gij * Vcij * Vcij; - for (int l = 0; l < 2; l++) - for (int m = 0; m < 2; m++) + double C1 = ((W3(C[i]) + W3(C[j]) + W3(C[k])) / 3); + double G1 = ((W3(G[i]) + W3(G[j]) + W3(G[k])) / 3); + V3 = ((W3(Vc[i]) + W3(Vc[j]) + W3(Vc[k])) / 3); + Cij = C1 * C1 * C1 * bip(2, fluid_a.id, fluid_b.id, i, j, k, T); + Gij = G1 * G1 * G1 * bip(3, fluid_a.id, fluid_b.id, i, j, k, T); + Vcij = V3 * V3 * V3; + CVc += x[i] * x[j] * x[k] * Cij * Vcij * Vcij; + GVc += x[i] * x[j] * x[k] * Gij * Vcij * Vcij; + for (int l = 0; l < 2; l++) + for (int m = 0; m < 2; m++) + { + double D1 = ((W3(D[i]) + W3(D[j]) + W3(D[k]) + W3(D[l]) + W3(D[m])) / 5); + V5 = ((W3(Vc[i]) + W3(Vc[j]) + W3(Vc[k]) + W3(Vc[l]) + W3(Vc[m])) / 5); + Dij = D1 * D1 * D1; + Vcij = V5 * V5 * V5; + DVc += x[i] * x[j] * x[k] * x[l] * x[m] * Dij * Vcij * Vcij * Vcij * Vcij; + for (int n = 0; n < 2; n++) { - double D1 = - ((W3(D[i]) + W3(D[j]) + W3(D[k]) + - W3(D[l]) + W3(D[m])) / 5); - V5 = - ((W3(Vc[i]) + W3(Vc[j]) + - W3(Vc[k]) + - W3(Vc[l]) + W3(Vc[m])) / 5); - Dij = D1 * D1 * D1; - Vcij = V5 * V5 * V5; - DVc += x[i] * x[j] * x[k] * x[l] * x[m] * - Dij * Vcij * Vcij * Vcij * Vcij; - for (int n = 0; n < 2; n++) - { - double E1 = - ((W3(E[i]) + W3(E[j]) + - W3(E[k]) + - W3(E[l]) + W3(E[m]) + - W3(E[n])) / 6); - V6 = - ((W3(Vc[i]) + W3(Vc[j]) + - W3(Vc[k]) + W3(Vc[l]) + - W3(Vc[m]) + - W3(Vc[n])) / 6); - Eij = E1 * E1 * E1; - Vcij = V6 * V6 * V6; - EVc += x[i] * x[j] * x[k] * x[l] * - x[m] * x[n] * Eij * Vcij * - Vcij * - Vcij * Vcij * Vcij; - } //ijklmn - } //ijklm - } //ijk - } //ij - } //i - - mix->B = BVc; - mix->C = CVc; - mix->D = DVc; - mix->E = EVc; - mix->F = FVc; - mix->b = b; - mix->G = GVc; - mix->M = M; - mix->Vc = Vcr; - } + double E1 = ((W3(E[i]) + W3(E[j]) + W3(E[k]) + W3(E[l]) + W3(E[m]) + W3(E[n])) / 6); + V6 = ((W3(Vc[i]) + W3(Vc[j]) + W3(Vc[k]) + W3(Vc[l]) + W3(Vc[m]) + W3(Vc[n])) / 6); + Eij = E1 * E1 * E1; + Vcij = V6 * V6 * V6; + EVc += x[i] * x[j] * x[k] * x[l] * x[m] * x[n] * Eij * Vcij * Vcij * Vcij * Vcij * Vcij; + } // ijklmn + } // ijklm + } // ijk + } // ij + } // i + + mix->B = BVc; + mix->C = CVc; + mix->D = DVc; + mix->E = EVc; + mix->F = FVc; + mix->b = b; + mix->G = GVc; + mix->M = M; + mix->Vc = Vcr; +} //**************************************************************************** //* task: returns the density of a mixture of two gases (fluid1 and fluid2), @@ -4037,9 +3919,9 @@ VirialCoefficients DuansVirialCoefficients(int Fluid, double T) //*****************************************************************************/ double DuansMixingRule(double T, double P, double x, int fluid1, int fluid2, bool neu) { - (void) neu; // unused + (void)neu; // unused P /= 1e5; - //CVirialCoefficients u,v,w; + // CVirialCoefficients u,v,w; VirialCoefficients u, v, w; u = DuansVirialCoefficients(fluid1, T); @@ -4058,7 +3940,7 @@ double DuansMixingRule(double T, double P, double x, int fluid1, int fluid2, boo dev_1 = DuanMixCompressibility(T, P, V1, w); V = V1; - //while (true) { + // while (true) { // V = V + 2.0; // n++; // dev = DuansCompressibility(T,P,V,w); @@ -4075,10 +3957,12 @@ double DuansMixingRule(double T, double P, double x, int fluid1, int fluid2, boo // } //}*/ - for (int i = (int) V1; i < 51; i += 2) { + for (int i = (int)V1; i < 51; i += 2) + { V += 2; dev = DuanMixCompressibility(T, P, V, w); - if (dev <= dev_1) { + if (dev <= dev_1) + { V1 = V; dev_1 = dev; } @@ -4090,57 +3974,64 @@ double DuansMixingRule(double T, double P, double x, int fluid1, int fluid2, boo V = V2; n = 0; - while (true) { + while (true) + { n++; V = V + 2.0; dev = DuanMixCompressibility(T, P, V, w); - if (V <= max(R * T / P, 1000.0)) { - if (dev > dev_2) { + if (V <= max(R * T / P, 1000.0)) + { + if (dev > dev_2) + { V2 = V; dev_2 = dev; - } else - //cout << " loop 2 left after " << n << " circles "<< "\n"; + } + else + // cout << " loop 2 left after " << n << " circles "<< "\n"; + break; + // goto l400; + } + else + // cout << " loop 2 left after " << n << " circles "<< "\n"; break; - //goto l400; - } else - //cout << " loop 2 left after " << n << " circles "<< "\n"; - break; } // Get the solution of volume with divition method n = 0; - while (true) { + while (true) + { dev_1 = DuanMixCompressibility(T, P, V1, w); dev_2 = DuanMixCompressibility(T, P, V2, w); if ((dev_1 * dev_2) > 0.0) V2 = V2 + 1; - else { + else + { V = (V1 + V2) / 2.0; dev = DuanMixCompressibility(T, P, V, w); if (fabs(dev) < 1.0e-5) - //cout << " returning after " << n << " iterations " << "\n"; - return w.M / V * 1000; + // cout << " returning after " << n << " iterations " << "\n"; + return w.M / V * 1000; if ((dev_1 * dev) > 0.0) V1 = V; - else if (dev_2 * dev > 0.0) V2 = V; + else if (dev_2 * dev > 0.0) + V2 = V; n++; - if (n > 1000) { - cout << " max it reached " << "\n"; + if (n > 1000) + { + cout << " max it reached " + << "\n"; return -1; // Max it } } } - cout << "This should not happen. Call NB at TUD!" << "\n"; + cout << "This should not happen. Call NB at TUD!" + << "\n"; return -1; } - - - - diff --git a/FEM/eos.h b/FEM/eos.h index bc32e9f90..196560ced 100644 --- a/FEM/eos.h +++ b/FEM/eos.h @@ -16,33 +16,34 @@ //#include //#include -class CFluidProperties; //14.11.2012. WW -double pressure (double rho, double T, int fluid); +class CFluidProperties; // 14.11.2012. WW +double pressure(double rho, double T, int fluid); // calculates the pressure depending on density and temperature -//double density (double P, double rho0, double T, double prec, string c); +// double density (double P, double rho0, double T, double prec, string c); // calculates the density iteratively depending on pressure and temperature -double enthalpy (double rho, double T, std::string c); +double enthalpy(double rho, double T, std::string c); // calculates the density iteratively depending on pressure and temperature -double isochoric_heat_capacity (double rho, double T, int c); +double isochoric_heat_capacity(double rho, double T, int c); // calculates the isochoric heat capacity depending on density and temperature double isobaric_heat_capacity(double rho, double T, int c); // calculates the isobaric heat capacity depending on density and temperature -double linear_heat_capacity(double T, int c); //temperature dependent heat capacity for narrow range of application (fast) -double co2_viscosity (double rho, double T); +double linear_heat_capacity(double T, + int c); // temperature dependent heat capacity for narrow range of application (fast) +double co2_viscosity(double rho, double T); // calculates the viscosity depending on density and temperature !ONLY for CO2!!! -double co2_heat_conductivity (double, double); +double co2_heat_conductivity(double, double); // calculates the heat conductivity of co2 depending on density and temperature -double ch4_viscosity_295K (double); -//calculates the viscosity of O2 +double ch4_viscosity_295K(double); +// calculates the viscosity of O2 double o2_viscosity(double rho, double T); // calculates the viscosity of CH4 at 25 �C depending on pressure -double Fluid_Viscosity (double rho, double T, double p, int fluid); -//Viscosity for several fluids -double Fluid_Heat_Conductivity (double rho, double T, int fluid); -//Heat conductivity for several fluids +double Fluid_Viscosity(double rho, double T, double p, int fluid); +// Viscosity for several fluids +double Fluid_Heat_Conductivity(double rho, double T, int fluid); +// Heat conductivity for several fluids double rkeos(double T, double P, double MM, double a, double b); -double melting_pressure_co2(double T,double Tt,double pt); -double sublime_pressure_co2(double T,double Tt,double pt); +double melting_pressure_co2(double T, double Tt, double pt); +double sublime_pressure_co2(double T, double Tt, double pt); /** * Carbon dioxide vapour saturation density at a temperature, Span,1996. * @param T temperature in K @@ -50,24 +51,18 @@ double sublime_pressure_co2(double T,double Tt,double pt); */ double vapour_pressure_co2(double T); double rkeos(double T, double P, int fluid); -double preos(const CFluidProperties *mfp, double T, double P); -double h2o_viscosity_IAPWS (double rho, double T); -double h2o_heat_conductivity_IAPWS_ind (double rho, double T); -double ch4_viscosity (double rho, double T); -double ch4_heat_conductivity (double rho, double T); -double n2_viscosity (double rho, double T); -double n2_heat_conductivity (double rho, double T); -double o2_heat_conductivity (double rho, double T); -double mixing_ternary (double* x, - double* a, - double* b, - double* MM, - double* ra, - double* rb, - double* rMM); +double preos(const CFluidProperties* mfp, double T, double P); +double h2o_viscosity_IAPWS(double rho, double T); +double h2o_heat_conductivity_IAPWS_ind(double rho, double T); +double ch4_viscosity(double rho, double T); +double ch4_heat_conductivity(double rho, double T); +double n2_viscosity(double rho, double T); +double n2_heat_conductivity(double rho, double T); +double o2_heat_conductivity(double rho, double T); +double mixing_ternary(double* x, double* a, double* b, double* MM, double* ra, double* rb, double* rMM); -double dpressure(double TT, double PP,std::string cs, double ds); -double zero( double T, double P, int fluid, double t); +double dpressure(double TT, double PP, std::string cs, double ds); +double zero(double T, double P, int fluid, double t); double vapour_saturation_density_ch4(double T); double liquid_saturation_density_ch4(double T); diff --git a/FEM/equation_class.cpp b/FEM/equation_class.cpp index cc3443263..2c8236867 100644 --- a/FEM/equation_class.cpp +++ b/FEM/equation_class.cpp @@ -30,12 +30,11 @@ #include // NEW_EQS To be removed -#ifdef NEW_EQS //1.11.2007 WW +#ifdef NEW_EQS // 1.11.2007 WW #include "rf_pcs.h" #include - -#ifdef LIS // 07.02.2008 PCH +#ifdef LIS // 07.02.2008 PCH #include "lis.h" #endif #ifdef _OPENMP @@ -51,20 +50,17 @@ #ifdef MKL #ifdef _WIN32 /* PARDISO prototype. */ -extern "C" int PARDISOINIT (void*, int*, int*, int*, double*, int*); -extern "C" int PARDISO (void*, int*, int*, int*, int*, int*, - double*, int*, int*, int*, int*, int*, - int*, double*, double*, int*, double*); +extern "C" int PARDISOINIT(void*, int*, int*, int*, double*, int*); +extern "C" int PARDISO(void*, int*, int*, int*, int*, int*, double*, int*, int*, int*, int*, int*, int*, double*, + double*, int*, double*); #else #include "mkl.h" /* PARDISO prototype. */ //#define PARDISO pardiso_ extern int omp_get_max_threads(); -extern int PARDISO - (int*, int*, int*, int*, int*, int*, - double*, int*, int*, int*, int*, int*, - int*, double*, double*, int*); +extern int PARDISO(int*, int*, int*, int*, int*, int*, double*, int*, int*, int*, int*, int*, int*, double*, double*, + int*); #endif #endif @@ -86,16 +82,18 @@ namespace Math_Group Programing: 10/2007 WW/ **************************************************************************/ -Linear_EQS::Linear_EQS(const SparseTable &sparse_table, +Linear_EQS::Linear_EQS(const SparseTable& sparse_table, #ifndef JFNK_H2M - const long dof, bool messg) : message(messg) + const long dof, bool messg) + : message(messg) #else - const long dof, bool messg) : message(messg), a_pcs(NULL) + const long dof, bool messg) + : message(messg), a_pcs(NULL) #endif { - /// If JFNK method. //03.08.2010. WW +/// If JFNK method. //03.08.2010. WW #ifdef JFNK_H2M - if(dof < 0) + if (dof < 0) { size_A = abs(dof); A = NULL; @@ -126,7 +124,7 @@ Linear_EQS::Linear_EQS(const SparseTable &sparse_table, #endif b = new double[size_A]; // - for(long i = 0; i < size_A; i++) + for (long i = 0; i < size_A; i++) { #ifndef USE_MPI x[i] = 0.; @@ -156,7 +154,7 @@ Linear_EQS::Linear_EQS(const long size) size_global = size; x = new double[size]; // - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) x[i] = 0.; iter = 0; bNorm = 1.0; @@ -170,19 +168,19 @@ Linear_EQS::Linear_EQS(const long size) **************************************************************************/ Linear_EQS::~Linear_EQS() { - if(A) + if (A) delete A; - if(x) - delete [] x; - if(b) - delete [] b; + if (x) + delete[] x; + if (b) + delete[] b; // A = NULL; x = NULL; b = NULL; - ///GMRES. 30.06.2010. WW - if(solver_type == 13) + /// GMRES. 30.06.2010. WW + if (solver_type == 13) H.ReleaseMemory(); } /************************************************************************** @@ -193,62 +191,62 @@ Linear_EQS::~Linear_EQS() void Linear_EQS::ConfigNumerics(CNumerics* m_num, const long n) { (void)n; - int nbuffer = 0; // Number of temperary float arrays + int nbuffer = 0; // Number of temperary float arrays precond_type = m_num->ls_precond; solver_type = m_num->ls_method; - switch(solver_type) + switch (solver_type) { - case 1: - solver_name = "Gauss"; - break; - case 2: - solver_name = "BiCGSTab"; - nbuffer = 8; - break; - case 3: - solver_name = "BiCG"; - nbuffer = 8; //20.10.2010. WW - break; - case 4: - solver_name = "QMRCGStab"; - break; - case 5: - solver_name = "CG"; - nbuffer = 3; - break; - case 6: - solver_name = "CGNR"; - break; - case 7: - solver_name = "CGS"; - nbuffer = 9; - break; - case 8: - solver_name = "Richardson"; - break; - case 9: - solver_name = "JOR"; - break; - case 10: - solver_name = "SOR"; - break; - case 11: - solver_name = "AMG1R5"; - break; - case 12: - solver_name = "UMF"; - break; - case 13: // 06.2010. WW - solver_name = "GMRES"; - m_gmres = m_num->Get_m(); - for(int i = 0; i < 4; i++) - { - double* new_array = new double[m_gmres + 1]; - f_buffer.push_back(new_array); - } - H.resize(m_gmres + 1, m_gmres + 1); - nbuffer = m_gmres + 4; - break; + case 1: + solver_name = "Gauss"; + break; + case 2: + solver_name = "BiCGSTab"; + nbuffer = 8; + break; + case 3: + solver_name = "BiCG"; + nbuffer = 8; // 20.10.2010. WW + break; + case 4: + solver_name = "QMRCGStab"; + break; + case 5: + solver_name = "CG"; + nbuffer = 3; + break; + case 6: + solver_name = "CGNR"; + break; + case 7: + solver_name = "CGS"; + nbuffer = 9; + break; + case 8: + solver_name = "Richardson"; + break; + case 9: + solver_name = "JOR"; + break; + case 10: + solver_name = "SOR"; + break; + case 11: + solver_name = "AMG1R5"; + break; + case 12: + solver_name = "UMF"; + break; + case 13: // 06.2010. WW + solver_name = "GMRES"; + m_gmres = m_num->Get_m(); + for (int i = 0; i < 4; i++) + { + double* new_array = new double[m_gmres + 1]; + f_buffer.push_back(new_array); + } + H.resize(m_gmres + 1, m_gmres + 1); + nbuffer = m_gmres + 4; + break; } // Buffer /* @@ -257,13 +255,13 @@ void Linear_EQS::ConfigNumerics(CNumerics* m_num, const long n) #else */ //#endif - for(int i = 0; i < nbuffer; i++) + for (int i = 0; i < nbuffer; i++) { double* new_array = new double[size_A]; f_buffer.push_back(new_array); } #if defined(USE_MPI) - if(!x) + if (!x) x = new double[size_A]; #if defined(NEW_BREDUCE) // For concatenate border entries @@ -277,41 +275,41 @@ void Linear_EQS::ConfigNumerics(CNumerics* m_num, const long n) // Will be removed if topo is ready border_buffer0 = new double[A->Dof() * dom->BSize()]; border_buffer1 = new double[A->Dof() * dom->BSize()]; - // +// #endif //--------------------------------------------- - switch(precond_type) + switch (precond_type) { - case 1: - precond_name = "Jacobi"; + case 1: + precond_name = "Jacobi"; #if defined(USE_MPI) - prec_M = new double[size_A]; + prec_M = new double[size_A]; #else - /// If JFNK +/// If JFNK #ifdef JFNK_H2M - if(m_num->nls_method == 2) - prec_M = new double[size_A]; + if (m_num->nls_method == 2) + prec_M = new double[size_A]; #endif #endif - break; - case 100: - // precond_name = "ILU"; break; - // If ILU is ready, remove follows - // ---------------------------------------------- - precond_name = "ILU not available. Use Jacobi"; - precond_type = 1; + break; + case 100: + // precond_name = "ILU"; break; + // If ILU is ready, remove follows + // ---------------------------------------------- + precond_name = "ILU not available. Use Jacobi"; + precond_type = 1; #ifndef JFNK_H2M - if(m_num->nls_method == 2) - prec_M = new double[size_A]; + if (m_num->nls_method == 2) + prec_M = new double[size_A]; #endif #if defined(USE_MPI) - prec_M = new double[size_A]; + prec_M = new double[size_A]; #endif - // ---------------------------------------------- - break; - default: - precond_name = "No preconditioner"; - break; + // ---------------------------------------------- + break; + default: + precond_name = "No preconditioner"; + break; } // // @@ -326,9 +324,9 @@ void Linear_EQS::ConfigNumerics(CNumerics* m_num, const long n) **************************************************************************/ void Linear_EQS::Initialize() { - if(A) + if (A) (*A) = 0.; - for(long i = 0; i < size_A; i++) + for (long i = 0; i < size_A; i++) b[i] = 0.; error = 1.0e10; } @@ -342,23 +340,23 @@ void Linear_EQS::Clean() #if defined(USE_MPI) double cpu_time_local = -MPI_Wtime(); #endif - for(int i = 0; i < (int)f_buffer.size(); i++) + for (int i = 0; i < (int)f_buffer.size(); i++) { - if(f_buffer[i]) - delete [] f_buffer[i]; + if (f_buffer[i]) + delete[] f_buffer[i]; f_buffer[i] = NULL; } f_buffer.clear(); - if(prec_M) - delete [] prec_M; + if (prec_M) + delete[] prec_M; prec_M = NULL; #if defined(USE_MPI) // - if(border_buffer0) - delete [] border_buffer0; + if (border_buffer0) + delete[] border_buffer0; border_buffer0 = NULL; - if(border_buffer1) - delete [] border_buffer1; + if (border_buffer1) + delete[] border_buffer1; border_buffer1 = NULL; // cpu_time_local += MPI_Wtime(); @@ -370,19 +368,21 @@ void Linear_EQS::Clean() Programing: 11/2007 WW/ **************************************************************************/ -void Linear_EQS::Write(std::ostream &os) +void Linear_EQS::Write(std::ostream& os) { A->Write(os); // - os << " b ( RHS): " << "\n"; + os << " b ( RHS): " + << "\n"; os.width(10); os.precision(6); // - for(long i = 0; i < size_A; i++) + for (long i = 0; i < size_A; i++) os << setw(10) << i << " " << setw(15) << b[i] << "\n"; - os << " x : " << "\n"; - for(long i = 0; i < size_A; i++) + os << " x : " + << "\n"; + for (long i = 0; i < size_A; i++) os << setw(10) << i << " " << setw(15) << x[i] << "\n"; } /************************************************************************** @@ -390,12 +390,12 @@ void Linear_EQS::Write(std::ostream &os) Programing: 07/2010 NW **************************************************************************/ -void Linear_EQS::WriteRHS(ostream &os) +void Linear_EQS::WriteRHS(ostream& os) { os.width(10); os.precision(6); // - for(long i = 0; i < A->Dim(); i++) + for (long i = 0; i < A->Dim(); i++) os << setw(15) << b[i] << "\n"; } //************************************************************************** @@ -406,13 +406,13 @@ void Linear_EQS::WriteRHS(ostream &os) 03/2011 WW */ //************************************************************************** -void Linear_EQS::Write_BIN(ostream &os) +void Linear_EQS::Write_BIN(ostream& os) { - if((A->GetStorageType() != CRS ) || (!A)) + if ((A->GetStorageType() != CRS) || (!A)) return; A->Write_BIN(os); - os.write((char*) b, A->Dim() * sizeof(double)); + os.write((char*)b, A->Dim() * sizeof(double)); } /************************************************************************** @@ -420,12 +420,12 @@ void Linear_EQS::Write_BIN(ostream &os) Programing: 07/2010 NW **************************************************************************/ -void Linear_EQS::WriteX(ostream &os) +void Linear_EQS::WriteX(ostream& os) { os.width(10); os.precision(6); // - for(long i = 0; i < A->Dim(); i++) + for (long i = 0; i < A->Dim(); i++) os << setw(15) << x[i] << "\n"; } @@ -493,20 +493,20 @@ int Linear_EQS::Solver(double* xg, const long n) iter = 0; ComputePreconditioner(); size_global = n; - switch(solver_type) + switch (solver_type) { - case 2: - iter = BiCGStab(xg, n); - break; - case 3: - iter = BiCG(xg, n); - break; - case 5: - iter = CG(xg, n); - break; - case 7: - iter = CGS(xg, n); - break; + case 2: + iter = BiCGStab(xg, n); + break; + case 3: + iter = BiCG(xg, n); + break; + case 5: + iter = CG(xg, n); + break; + case 7: + iter = CGS(xg, n); + break; } cpu_time_local += MPI_Wtime(); cpu_time += cpu_time_local; @@ -514,22 +514,22 @@ int Linear_EQS::Solver(double* xg, const long n) } #else // if defined(USE_MPI) -#if defined(LIS) || defined(MKL) // PCH 02.2008 -//NW 01.2010 Use configuration in NUM file +#if defined(LIS) || defined(MKL) // PCH 02.2008 +// NW 01.2010 Use configuration in NUM file int Linear_EQS::Solver(CNumerics* num) { // Check the openmp solver type iterative and directive CNumerics* m_num; if (num != NULL) - m_num = num; //NW + m_num = num; // NW else m_num = num_vector[0]; - if(m_num->ls_method == 805) // Then, PARDISO parallel direct solver + if (m_num->ls_method == 805) // Then, PARDISO parallel direct solver { -#ifdef MKL // PCH 10.03.2009: Requires the system platform where Math Kernel Library is properly configured. - //cout << "---------------------------------------------------" << "\n"; - //omp_set_num_threads (1); +#ifdef MKL // PCH 10.03.2009: Requires the system platform where Math Kernel Library is properly configured. +// cout << "---------------------------------------------------" << "\n"; +// omp_set_num_threads (1); #ifdef _OPENMP cout << "->Start calling PARDISO with " << omp_get_max_threads() << " threads \n"; #else @@ -540,26 +540,26 @@ int Linear_EQS::Solver(CNumerics* num) int nonzero = A->nnz(); int numOfNode = A->Size() * A->Dof(); double* value; - value = new double [nonzero]; + value = new double[nonzero]; A->GetCRSValue(value); int* ptr = NULL; int* index = NULL; - ptr = (int*)malloc((numOfNode + 1) * sizeof( int)); - index = (int*)malloc((nonzero) * sizeof( int)); + ptr = (int*)malloc((numOfNode + 1) * sizeof(int)); + index = (int*)malloc((nonzero) * sizeof(int)); // Reindexing ptr according to Fortran-based PARDISO int i = 0; - for(i = 0; i < numOfNode; ++i) + for (i = 0; i < numOfNode; ++i) ptr[i] = A->ptr[i] + 1; - //ptr needs one more storage + // ptr needs one more storage ptr[i] = A->ptr[i] + 1; // Reindexing index according to Fortran-based PARDISO // and zonzero of Matrix A - for(i = 0; i < nonzero; ++i) + for (i = 0; i < nonzero; ++i) index[i] = A->col_idx[i] + 1; - int mtype = 11; /* Real unsymmetric matrix */ - int nrhs = 1; /* Number of right hand sides. */ + int mtype = 11; /* Real unsymmetric matrix */ + int nrhs = 1; /* Number of right hand sides. */ /* Internal solver memory pointer pt, */ /* 32-bit: int pt[64]; 64-bit: long int pt[64] */ /* or void *pt[64] should be OK on both architectures */ @@ -569,24 +569,24 @@ int Linear_EQS::Solver(CNumerics* num) int maxfct, mnum, phase, error, msglvl; /* Auxiliary variables.*/ - double ddum; /* Double dummy */ - int idum; /* Integer dummy. */ + double ddum; /* Double dummy */ + int idum; /* Integer dummy. */ #ifdef _WIN32 double dparm[64]; int solver; // Check the license and initialize the solver { - //static bool done = false; - //if (!done) { - PARDISOINIT (pt, &mtype, &solver, iparm, dparm, &error); + // static bool done = false; + // if (!done) { + PARDISOINIT(pt, &mtype, &solver, iparm, dparm, &error); if (error != 0) { - if (error == -10 ) + if (error == -10) printf("->No license file found \n"); - if (error == -11 ) + if (error == -11) printf("->License is expired \n"); - if (error == -12 ) + if (error == -12) printf("->Wrong username or hostname \n"); exit(1); } @@ -603,35 +603,35 @@ int Linear_EQS::Solver(CNumerics* num) /* --------------------------------------------------------------------*/ for (i = 0; i < 64; i++) iparm[i] = 0; - iparm[0] = 1; /* No solver default */ - iparm[1] = 2; /* Fill-in reordering from METIS */ - /* Numbers of processors, value of MKL_NUM_THREADS */ + iparm[0] = 1; /* No solver default */ + iparm[1] = 2; /* Fill-in reordering from METIS */ +/* Numbers of processors, value of MKL_NUM_THREADS */ #ifdef _WIN32 iparm[2] = omp_get_max_threads(); #else iparm[2] = mkl_get_max_threads(); #endif - iparm[3] = 0; /* No iterative-direct algorithm */ - iparm[4] = 0; /* No user fill-in reducing permutation */ - iparm[5] = 0; /* Write solution into x */ - iparm[6] = 0; /* Not in use */ - iparm[7] = 2; /* Max numbers of iterative refinement steps */ - iparm[8] = 0; /* Not in use */ - iparm[9] = 13; /* Perturb the pivot elements with 1E-13 */ - iparm[10] = 1; /* Use nonsymmetric permutation and scaling MPS */ - iparm[11] = 0; /* Not in use */ - iparm[12] = 0; /* Not in use */ - iparm[13] = 0; /* Output: Number of perturbed pivots */ - iparm[14] = 0; /* Not in use */ - iparm[15] = 0; /* Not in use */ - iparm[16] = 0; /* Not in use */ - iparm[17] = -1; /* Output: Number of nonzeros in the factor LU */ - iparm[18] = -1; /* Output: Mflops for LU factorization */ - iparm[19] = 0; /* Output: Numbers of CG Iterations */ - maxfct = 1; /* Maximum number of numerical factorizations. */ - mnum = 1; /* Which factorization to use. */ - msglvl = 0; /* Print statistical information in file */ - error = 0; /* Initialize error flag */ + iparm[3] = 0; /* No iterative-direct algorithm */ + iparm[4] = 0; /* No user fill-in reducing permutation */ + iparm[5] = 0; /* Write solution into x */ + iparm[6] = 0; /* Not in use */ + iparm[7] = 2; /* Max numbers of iterative refinement steps */ + iparm[8] = 0; /* Not in use */ + iparm[9] = 13; /* Perturb the pivot elements with 1E-13 */ + iparm[10] = 1; /* Use nonsymmetric permutation and scaling MPS */ + iparm[11] = 0; /* Not in use */ + iparm[12] = 0; /* Not in use */ + iparm[13] = 0; /* Output: Number of perturbed pivots */ + iparm[14] = 0; /* Not in use */ + iparm[15] = 0; /* Not in use */ + iparm[16] = 0; /* Not in use */ + iparm[17] = -1; /* Output: Number of nonzeros in the factor LU */ + iparm[18] = -1; /* Output: Mflops for LU factorization */ + iparm[19] = 0; /* Output: Numbers of CG Iterations */ + maxfct = 1; /* Maximum number of numerical factorizations. */ + mnum = 1; /* Which factorization to use. */ + msglvl = 0; /* Print statistical information in file */ + error = 0; /* Initialize error flag */ /* --------------------------------------------------------------------*/ /* .. Initialize the internal solver memory pointer. This is only */ @@ -646,13 +646,11 @@ int Linear_EQS::Solver(CNumerics* num) /* --------------------------------------------------------------------*/ phase = 11; #ifdef _WIN32 - PARDISO (pt, &maxfct, &mnum, &mtype, &phase, - &numOfNode, value, ptr, index, &idum, &nrhs, - iparm, &msglvl, &ddum, &ddum, &error, dparm); + PARDISO(pt, &maxfct, &mnum, &mtype, &phase, &numOfNode, value, ptr, index, &idum, &nrhs, iparm, &msglvl, &ddum, + &ddum, &error, dparm); #else - PARDISO (pt, &maxfct, &mnum, &mtype, &phase, - &numOfNode, value, ptr, index, &idum, &nrhs, - iparm, &msglvl, &ddum, &ddum, &error); + PARDISO(pt, &maxfct, &mnum, &mtype, &phase, &numOfNode, value, ptr, index, &idum, &nrhs, iparm, &msglvl, &ddum, + &ddum, &error); #endif if (error != 0) @@ -666,13 +664,11 @@ int Linear_EQS::Solver(CNumerics* num) /* --------------------------------------------------------------------*/ phase = 22; #ifdef _WIN32 - PARDISO (pt, &maxfct, &mnum, &mtype, &phase, - &numOfNode, value, ptr, index, &idum, &nrhs, - iparm, &msglvl, &ddum, &ddum, &error, dparm); + PARDISO(pt, &maxfct, &mnum, &mtype, &phase, &numOfNode, value, ptr, index, &idum, &nrhs, iparm, &msglvl, &ddum, + &ddum, &error, dparm); #else - PARDISO (pt, &maxfct, &mnum, &mtype, &phase, - &numOfNode, value, ptr, index, &idum, &nrhs, - iparm, &msglvl, &ddum, &ddum, &error); + PARDISO(pt, &maxfct, &mnum, &mtype, &phase, &numOfNode, value, ptr, index, &idum, &nrhs, iparm, &msglvl, &ddum, + &ddum, &error); #endif if (error != 0) { @@ -684,18 +680,16 @@ int Linear_EQS::Solver(CNumerics* num) /* .. Back substitution and iterative refinement. */ /* --------------------------------------------------------------------*/ phase = 33; - iparm[7] = 2; /* Max numbers of iterative refinement steps. */ + iparm[7] = 2; /* Max numbers of iterative refinement steps. */ - /* Set right hand side to one. */ +/* Set right hand side to one. */ #ifdef _WIN32 - PARDISO (pt, &maxfct, &mnum, &mtype, &phase, - &numOfNode, value, ptr, index, &idum, &nrhs, - iparm, &msglvl, b, x, &error, dparm); + PARDISO(pt, &maxfct, &mnum, &mtype, &phase, &numOfNode, value, ptr, index, &idum, &nrhs, iparm, &msglvl, b, x, + &error, dparm); #else - PARDISO (pt, &maxfct, &mnum, &mtype, &phase, - &numOfNode, value, ptr, index, &idum, &nrhs, - iparm, &msglvl, b, x, &error); + PARDISO(pt, &maxfct, &mnum, &mtype, &phase, &numOfNode, value, ptr, index, &idum, &nrhs, iparm, &msglvl, b, x, + &error); #endif if (error != 0) { @@ -703,32 +697,31 @@ int Linear_EQS::Solver(CNumerics* num) exit(3); } - phase = -1; /* Release internal memory. */ + phase = -1; /* Release internal memory. */ #ifdef _WIN32 - PARDISO (pt, &maxfct, &mnum, &mtype, &phase, - &numOfNode, value, ptr, index, &idum, &nrhs, - iparm, &msglvl, &ddum, &ddum, &error, dparm); + PARDISO(pt, &maxfct, &mnum, &mtype, &phase, &numOfNode, value, ptr, index, &idum, &nrhs, iparm, &msglvl, &ddum, + &ddum, &error, dparm); #else - PARDISO (pt, &maxfct, &mnum, &mtype, &phase, - &numOfNode, value, ptr, index, &idum, &nrhs, - iparm, &msglvl, &ddum, &ddum, &error); + PARDISO(pt, &maxfct, &mnum, &mtype, &phase, &numOfNode, value, ptr, index, &idum, &nrhs, iparm, &msglvl, &ddum, + &ddum, &error); #endif // Releasing the local memory - delete [] value; + delete[] value; free(ptr); free(index); // MKL_FreeBuffers(); - cout << "->Finished PARDISO computation" << "\n"; + cout << "->Finished PARDISO computation" + << "\n"; #endif } - else // LIS parallel solver + else // LIS parallel solver { #ifdef LIS - std::cout << - "------------------------------------------------------------------" << - "\n"; - std::cout << "*** LIS solver computation" << "\n"; + std::cout << "------------------------------------------------------------------" + << "\n"; + std::cout << "*** LIS solver computation" + << "\n"; int i, iter, ierr, size; // Fix for the fluid_momentum Dof size = A->Size() * A->Dof(); @@ -737,125 +730,117 @@ int Linear_EQS::Solver(CNumerics* num) // Establishing CRS type matrix from GeoSys Matrix data storage type int nonzero = A->nnz(); double* value; - value = new double [nonzero]; + value = new double[nonzero]; ierr = A->GetCRSValue(value); // Creating a matrix. - ierr = lis_matrix_create(0,&AA); - ierr = lis_matrix_set_type(AA,LIS_MATRIX_CRS); - ierr = lis_matrix_set_size(AA,0,size); + ierr = lis_matrix_create(0, &AA); + ierr = lis_matrix_set_type(AA, LIS_MATRIX_CRS); + ierr = lis_matrix_set_size(AA, 0, size); // Matrix solver and Precondition can be handled better way. char solver_options[MAX_ZEILE], tol_option[MAX_ZEILE]; - sprintf(solver_options, - "-i %d -p %d %s", - m_num->ls_method, - m_num->ls_precond, - m_num->ls_extra_arg.c_str()); + sprintf(solver_options, "-i %d -p %d %s", m_num->ls_method, m_num->ls_precond, m_num->ls_extra_arg.c_str()); // tolerance and other setting parameters are same - //NW add max iteration counts - sprintf(tol_option, - "-tol %e -maxiter %d", - m_num->ls_error_tolerance, - m_num->ls_max_iterations); + // NW add max iteration counts + sprintf(tol_option, "-tol %e -maxiter %d", m_num->ls_error_tolerance, m_num->ls_max_iterations); - ierr = lis_matrix_set_crs(nonzero,A->ptr,A->col_idx, value,AA); + ierr = lis_matrix_set_crs(nonzero, A->ptr, A->col_idx, value, AA); ierr = lis_matrix_assemble(AA); CHKERR(ierr); // we put this here only to avoid compiler warnings. - // one can also check erros after calling each lis functions. - -// { -// std::cout << "print some lines of matrix: " << "\n"; -// for (size_t r(0); r < 5; r++) { -// const unsigned row_end(A->ptr[r+1]); -// std::cout << r << ": " << std::flush; -// for (unsigned j(A->ptr[r]); j< row_end; j++) { -// std::cout << value[A->col_idx[j]] << " "; -// } -// std::cout << "\n"; -// } -// -// -// std::string fname("CO2MAN-Matrix.bin"); -// std::ofstream os (fname.c_str(), std::ios::binary); -// std::cout << "writing matrix in binary format to " << fname << " ... " << std::flush; -// unsigned mat_size (size); -// os.write((char*) &mat_size, sizeof(unsigned)); -// unsigned *iA(new unsigned[mat_size+1]); -// for (size_t k(0); kptr[k]; -// } -// -// unsigned mat_nnz(iA[mat_size]); -// unsigned *jA(new unsigned[mat_nnz]); -// for (size_t k(0); kcol_idx[k]; -// } -// -// double *A(new double[mat_nnz]); -// for (size_t k(0); kptr[r+1]); + // std::cout << r << ": " << std::flush; + // for (unsigned j(A->ptr[r]); j< row_end; j++) { + // std::cout << value[A->col_idx[j]] << " "; + // } + // std::cout << "\n"; + // } + // + // + // std::string fname("CO2MAN-Matrix.bin"); + // std::ofstream os (fname.c_str(), std::ios::binary); + // std::cout << "writing matrix in binary format to " << fname << " ... " << std::flush; + // unsigned mat_size (size); + // os.write((char*) &mat_size, sizeof(unsigned)); + // unsigned *iA(new unsigned[mat_size+1]); + // for (size_t k(0); kptr[k]; + // } + // + // unsigned mat_nnz(iA[mat_size]); + // unsigned *jA(new unsigned[mat_nnz]); + // for (size_t k(0); kcol_idx[k]; + // } + // + // double *A(new double[mat_nnz]); + // for (size_t k(0); kls_max_iterations); double resid = 0.0; - ierr = lis_solver_get_residualnorm(solver,&resid); + ierr = lis_solver_get_residualnorm(solver, &resid); printf("\t residuals: %e\n", resid); - // lis_vector_print(xx); - // lis_vector_print(bb); +// lis_vector_print(xx); +// lis_vector_print(bb); - // Update the solution (answer) into the x vector +// Update the solution (answer) into the x vector #ifdef _OPENMP #pragma omp parallel for #endif - for(i = 0; i < size; ++i) - lis_vector_get_value(xx,i,&(x[i])); + for (i = 0; i < size; ++i) + lis_vector_get_value(xx, i, &(x[i])); // Clear memory - delete [] value; + delete[] value; // lis_matrix_destroy(AA); lis_vector_destroy(bb); lis_vector_destroy(xx); lis_solver_destroy(solver); - std::cout << - "------------------------------------------------------------------" << - "\n"; + std::cout << "------------------------------------------------------------------" + << "\n"; #endif } - return -1; // This right now is meaningless. + return -1; // This right now is meaningless. } #else // ifdef LIS int Linear_EQS::Solver() @@ -863,36 +848,36 @@ int Linear_EQS::Solver() // iter = 0; ComputePreconditioner(); - switch(solver_type) + switch (solver_type) { - case 1: - return Gauss(); - case 2: - iter = BiCGStab(); - return iter; //kg44 only to make sure here is iter returned - case 3: - return BiCG(); - case 4: - return QMRCGStab(); - case 5: - return CG(); - case 6: - return CGNR(); - case 7: - return CGS(); - case 8: - return Richardson(); - case 9: - return JOR(); - case 10: - return SOR(); - case 11: - return AMG1R5(); - case 12: - return UMF(); - case 13: - return GMRES(); - break; + case 1: + return Gauss(); + case 2: + iter = BiCGStab(); + return iter; // kg44 only to make sure here is iter returned + case 3: + return BiCG(); + case 4: + return QMRCGStab(); + case 5: + return CG(); + case 6: + return CGNR(); + case 7: + return CGS(); + case 8: + return Richardson(); + case 9: + return JOR(); + case 10: + return SOR(); + case 11: + return AMG1R5(); + case 12: + return UMF(); + case 13: + return GMRES(); + break; } return -1; } @@ -906,18 +891,18 @@ int Linear_EQS::Solver() **************************************************************************/ void Linear_EQS::ComputePreconditioner() { - switch(precond_type) + switch (precond_type) { - case 1: + case 1: #if defined(USE_MPI) - ComputePreconditioner_Jacobi(); -#endif - return; - case 100: - ComputePreconditioner_ILU(); - return; - default: - return; + ComputePreconditioner_Jacobi(); +#endif + return; + case 100: + ComputePreconditioner_ILU(); + return; + default: + return; } } /************************************************************************** @@ -939,30 +924,30 @@ void Linear_EQS::SetKnownX_i(const long i, const double x_i) void Linear_EQS::Precond(double* vec_s, double* vec_r) { bool pre = true; - switch(precond_type) + switch (precond_type) { - case 1: + case 1: #if defined(USE_MPI) - Precond_Jacobi(vec_s, vec_r); + Precond_Jacobi(vec_s, vec_r); #else #ifdef JFNK_H2M - /// If JFNK - if(!A) - Precond_Jacobi(vec_s, vec_r); - else + /// If JFNK + if (!A) + Precond_Jacobi(vec_s, vec_r); + else #endif - A->Precond_Jacobi(vec_s, vec_r); + A->Precond_Jacobi(vec_s, vec_r); #endif - break; - case 100: - pre = false; //A->Precond_ILU(vec_s, vec_r); - break; - default: - pre = false; //A->Precond_ILU(vec_s, vec_r); - break; + break; + case 100: + pre = false; // A->Precond_ILU(vec_s, vec_r); + break; + default: + pre = false; // A->Precond_ILU(vec_s, vec_r); + break; } - if(!pre) - for(long i = 0; i < size_A; i++) + if (!pre) + for (long i = 0; i < size_A; i++) vec_r[i] = vec_s[i]; } /************************************************************************** @@ -982,16 +967,16 @@ void Linear_EQS::TransPrecond(double* vec_s, double* vec_r) 10/2007 WW 12/2007 WW Parallel ********************************************************************/ -double Linear_EQS::dot (const double* xx, const double* yy) +double Linear_EQS::dot(const double* xx, const double* yy) { double val = 0.; #if defined(USE_MPI) - double val_i = dom->Dot_Interior(xx, yy); - val_i += dom->Dot_Border_Vec(xx, yy); + double val_i = dom->Dot_Interior(xx, yy); + val_i += dom->Dot_Border_Vec(xx, yy); // - MPI_Allreduce(&val_i, &val, 1, MPI_DOUBLE,MPI_SUM,comm_DDC); + MPI_Allreduce(&val_i, &val, 1, MPI_DOUBLE, MPI_SUM, comm_DDC); #else - for(long i = 0; i < size_A; i++) + for (long i = 0; i < size_A; i++) val += xx[i] * yy[i]; #endif return val; @@ -1005,9 +990,9 @@ double Linear_EQS::dot (const double* xx, const double* yy) double Linear_EQS::NormX() { #if defined(USE_MPI) - return sqrt(dot(x, x, size_global )); + return sqrt(dot(x, x, size_global)); #else - return sqrt(dot(x, x )); + return sqrt(dot(x, x)); #endif } // @@ -1018,10 +1003,10 @@ double Linear_EQS::NormX() Programm: 12/2007 WW ********************************************************************/ -double Linear_EQS::dot (const double* xx, const double* yy, const long n) +double Linear_EQS::dot(const double* xx, const double* yy, const long n) { double val = 0.; - for(long i = 0; i < n; i++) + for (long i = 0; i < n; i++) val += xx[i] * yy[i]; return val; } @@ -1031,7 +1016,7 @@ double Linear_EQS::dot (const double* xx, const double* yy, const long n) Programm: 12/2007 WW ********************************************************************/ -inline void Linear_EQS::MatrixMulitVec(double* xx, double* yy) +inline void Linear_EQS::MatrixMulitVec(double* xx, double* yy) { // A->multiVec(xx, yy); @@ -1039,8 +1024,7 @@ inline void Linear_EQS::MatrixMulitVec(double* xx, double* yy) dom->ReduceBorderV(yy); #else dom->Local2Border(yy, border_buffer0); - MPI_Allreduce(border_buffer0, border_buffer1, A->Dof() * dom->BSize(), - MPI_DOUBLE,MPI_SUM,comm_DDC); + MPI_Allreduce(border_buffer0, border_buffer1, A->Dof() * dom->BSize(), MPI_DOUBLE, MPI_SUM, comm_DDC); dom->Border2Local(border_buffer1, yy); #endif } @@ -1051,7 +1035,7 @@ inline void Linear_EQS::MatrixMulitVec(double* xx, double* yy) 12/2007 WW 02/2010 WW Revise ********************************************************************/ -inline void Linear_EQS::TransMatrixMulitVec(double* xx, double* yy) +inline void Linear_EQS::TransMatrixMulitVec(double* xx, double* yy) { // A->Trans_MultiVec(xx, yy); @@ -1059,8 +1043,7 @@ inline void Linear_EQS::TransMatrixMulitVec(double* xx, double* yy) dom->ReduceBorderV(yy); #else dom->Local2Border(yy, border_buffer0); - MPI_Allreduce(border_buffer0, border_buffer1, A->Dof() * dom->BSize(), - MPI_DOUBLE,MPI_SUM,comm_DDC); + MPI_Allreduce(border_buffer0, border_buffer1, A->Dof() * dom->BSize(), MPI_DOUBLE, MPI_SUM, comm_DDC); dom->Border2Local(border_buffer1, yy); #endif } @@ -1074,7 +1057,7 @@ inline void Linear_EQS::TransMatrixMulitVec(double* xx, double* yy) void Linear_EQS::Message() { #ifdef USE_MPI - if(myrank > 0) + if (myrank > 0) return; #endif if (!message) @@ -1083,12 +1066,15 @@ void Linear_EQS::Message() cout.precision(3); cout.setf(ios::scientific); // - //system("color 0B"); + // system("color 0B"); cout << " ------------------------------------------------\n"; cout << " Linear solver " << solver_name << " with " << precond_name << ":\n"; - cout << " Iterations |" << " Max Iters |" << " Norm of b |" << " Error\n"; - cout << " " << setw(11) << iter << "|" << setw(11) << max_iter << "|" - << setw(11) << bNorm << "|" << setw(11) << error << "\n"; + cout << " Iterations |" + << " Max Iters |" + << " Norm of b |" + << " Error\n"; + cout << " " << setw(11) << iter << "|" << setw(11) << max_iter << "|" << setw(11) << bNorm << "|" << setw(11) + << error << "\n"; if (iter == max_iter) cout << " WARNING: Maximum iterations reached !!! \n"; cout << " ------------------------------------------------\n"; @@ -1103,8 +1089,8 @@ void Linear_EQS::Message() ********************************************************************/ inline bool Linear_EQS::CheckNormRHS(const double normb_new) { - if(bNorm > 0.0) - if((normb_new / bNorm) < tol) + if (bNorm > 0.0) + if ((normb_new / bNorm) < tol) { error = normb_new / bNorm; bNorm = normb_new; @@ -1112,7 +1098,7 @@ inline bool Linear_EQS::CheckNormRHS(const double normb_new) return true; } bNorm = normb_new; - if(bNorm < DBL_MIN) + if (bNorm < DBL_MIN) { error = 0.; Message(); @@ -1136,17 +1122,17 @@ int Linear_EQS::CG() // double bNorm_new = Norm(b); // Check if the norm of b is samll enough for convengence - if(CheckNormRHS(bNorm_new)) + if (CheckNormRHS(bNorm_new)) return 0; // // r0 = b-Ax - A->multiVec(x,s); - for(long i = 0; i < size; i++) + A->multiVec(x, s); + for (long i = 0; i < size; i++) r[i] = b[i] - s[i]; // // Preconditioning: M^{-1}r Precond(r, s); - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) p[i] = s[i]; // Check the convergence if ((error = Norm(r) / bNorm) < tol) @@ -1160,9 +1146,9 @@ int Linear_EQS::CG() for (iter = 1; iter <= max_iter; ++iter) { A->multiVec(p, s); - const double alpha = rr / dot(p,s); + const double alpha = rr / dot(p, s); // Update - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) { x[i] += alpha * p[i]; r[i] -= alpha * s[i]; @@ -1176,9 +1162,9 @@ int Linear_EQS::CG() Precond(r, s); // const double rrM1 = rr; - rr = dot(s, r); + rr = dot(s, r); const double beta = rr / rrM1; - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) p[i] = s[i] + beta * p[i]; } // @@ -1207,12 +1193,12 @@ int Linear_EQS::BiCG() double rho2 = 1.; double bNorm_new = Norm(b); // Check if the norm of b is samll enough for convengence - if(CheckNormRHS(bNorm_new)) + if (CheckNormRHS(bNorm_new)) return 0; // // r0 = b-Ax - A->multiVec(x,rt); - for(long i = 0; i < size; i++) + A->multiVec(x, rt); + for (long i = 0; i < size; i++) { r[i] = b[i] - rt[i]; rt[i] = r[i]; @@ -1238,8 +1224,8 @@ int Linear_EQS::BiCG() return iter <= max_iter; } // - if(iter == 1) - for(long i = 0; i < size; i++) + if (iter == 1) + for (long i = 0; i < size; i++) { p[i] = z[i]; pt[i] = zt[i]; @@ -1247,7 +1233,7 @@ int Linear_EQS::BiCG() else { const double beta = rho1 / rho2; - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) { p[i] = z[i] + beta * p[i]; pt[i] = zt[i] + beta * pt[i]; @@ -1256,9 +1242,9 @@ int Linear_EQS::BiCG() // A->multiVec(p, q); A->Trans_MultiVec(pt, qt); - const double alpha = rho1 / dot(pt,q); + const double alpha = rho1 / dot(pt, q); // - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) { x[i] += alpha * p[i]; r[i] -= alpha * q[i]; @@ -1302,31 +1288,31 @@ int Linear_EQS::BiCGStab() // double bNorm_new = Norm(b); // Check if the norm of b is small enough for convengence - if(CheckNormRHS(bNorm_new)) + if (CheckNormRHS(bNorm_new)) return 0; - // - //Norm of M r +// +// Norm of M r #ifdef JFNK_H2M - if(a_pcs) /// JFNK. 24.11.2010 + if (a_pcs) /// JFNK. 24.11.2010 { - for(long i = 0; i < size; i++) - r0[i] = b[i]; // r = b-Ax + for (long i = 0; i < size; i++) + r0[i] = b[i]; // r = b-Ax a_pcs->Jacobian_Multi_Vector_JFNK(x, s); - for(long i = 0; i < size; i++) - r0[i] -= s[i]; // r = b-Ax + for (long i = 0; i < size; i++) + r0[i] -= s[i]; // r = b-Ax } else { - A->multiVec(x,s); // s as buffer - for(long i = 0; i < size; i++) - r0[i] = b[i] - s[i]; // r = b-Ax + A->multiVec(x, s); // s as buffer + for (long i = 0; i < size; i++) + r0[i] = b[i] - s[i]; // r = b-Ax } #else // ifdef JFNK_H2M - A->multiVec(x,s); // s as buffer - for(long i = 0; i < size; i++) - r0[i] = b[i] - s[i]; // r = b-Ax + A->multiVec(x, s); // s as buffer + for (long i = 0; i < size; i++) + r0[i] = b[i] - s[i]; // r = b-Ax #endif - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) { r[i] = r0[i]; v[i] = 0.; @@ -1347,52 +1333,52 @@ int Linear_EQS::BiCGStab() return 0; } if (iter == 1) - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) p[i] = r[i]; else { beta = (rho_1 / rho_0) * (alpha / omega); - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) p[i] = r[i] + beta * (p[i] - omega * v[i]); } // Preconditioner Precond(p, p_h); - // A M^{-1}p-->v +// A M^{-1}p-->v #ifdef JFNK_H2M - if(a_pcs) /// JFNK. 24.11.2010 + if (a_pcs) /// JFNK. 24.11.2010 a_pcs->Jacobian_Multi_Vector_JFNK(p_h, v); else #endif - A->multiVec(p_h, v); + A->multiVec(p_h, v); // alpha = rho_1 / dot(r0, v); // - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) s[i] = r[i] - alpha * v[i]; if ((error = Norm(s) / bNorm) < tol) { - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) x[i] += alpha * p_h[i]; Message(); return iter; } // M^{-1}s, Precond(s, s_h); - // A* M^{-1}s +// A* M^{-1}s #ifdef JFNK_H2M - if(a_pcs) /// JFNK. 24.11.2010 + if (a_pcs) /// JFNK. 24.11.2010 a_pcs->Jacobian_Multi_Vector_JFNK(s_h, t); else #endif - A->multiVec(s_h, t); + A->multiVec(s_h, t); // - tt = dot(t,t); - if(tt > DBL_MIN) - omega = dot(t,s) / tt; + tt = dot(t, t); + if (tt > DBL_MIN) + omega = dot(t, s) / tt; else omega = 1.0; // Update solution - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) { x[i] += alpha * p_h[i] + omega * s_h[i]; r[i] = s[i] - omega * t[i]; @@ -1443,13 +1429,13 @@ int Linear_EQS::CGS() // double bNorm_new = Norm(b); // Check if the norm of b is samll enough for convengence - if(CheckNormRHS(bNorm_new)) + if (CheckNormRHS(bNorm_new)) return 0; // - A->multiVec(x,v); // v as buffer - for(long i = 0; i < size; i++) + A->multiVec(x, v); // v as buffer + for (long i = 0; i < size; i++) { - r0[i] = b[i] - v[i]; // r = b-Ax + r0[i] = b[i] - v[i]; // r = b-Ax r[i] = r0[i]; v[i] = 0.; } @@ -1468,12 +1454,12 @@ int Linear_EQS::CGS() return 0; } if (iter == 1) - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) p[i] = u[i] = r[i]; else { beta = rho_1 / rho_2; - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) { u[i] = r[i] + beta * q[i]; p[i] = u[i] + beta * (q[i] + beta * p[i]); @@ -1486,19 +1472,19 @@ int Linear_EQS::CGS() // alpha = rho_1 / dot(r0, v); // - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) { q[i] = u[i] - alpha * v[i]; q_h[i] = u[i] + q[i]; } // Preconditioner Precond(q_h, u_h); - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) x[i] += alpha * u_h[i]; // A->multiVec(u_h, q_h); // - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) r[i] -= alpha * q_h[i]; rho_2 = rho_1; if ((error = Norm(r) / bNorm) < tol) @@ -1525,7 +1511,7 @@ int Linear_EQS::CGS() */ //----------------------------------------------------------------- /// For GMRES -inline void Linear_EQS::Get_Plane_Rotation(double &dx, double &dy, double &cs, double &sn) +inline void Linear_EQS::Get_Plane_Rotation(double& dx, double& dy, double& cs, double& sn) { if (dy == 0.0) { @@ -1535,30 +1521,30 @@ inline void Linear_EQS::Get_Plane_Rotation(double &dx, double &dy, double &cs, d else if (fabs(dy) > fabs(dx)) { double temp = dx / dy; - sn = 1.0 / sqrt( 1.0 + temp * temp ); + sn = 1.0 / sqrt(1.0 + temp * temp); cs = temp * sn; } else { double temp = dy / dx; - cs = 1.0 / sqrt( 1.0 + temp * temp ); + cs = 1.0 / sqrt(1.0 + temp * temp); sn = temp * cs; } } /// For GMRES. -inline void Linear_EQS::Set_Plane_Rotation(double &dx, double &dy, double &cs, double &sn) +inline void Linear_EQS::Set_Plane_Rotation(double& dx, double& dy, double& cs, double& sn) { - double temp = cs * dx + sn * dy; + double temp = cs * dx + sn * dy; dy = -sn * dx + cs * dy; dx = temp; } /// Update solution in GMRES -inline void Linear_EQS::Update(double* x, int k, Matrix &h, double* s) +inline void Linear_EQS::Update(double* x, int k, Matrix& h, double* s) { long size = 0; - if(A) + if (A) size = A->Dim(); else size = size_global; @@ -1575,14 +1561,14 @@ inline void Linear_EQS::Update(double* x, int k, Matrix &h, double* s) // Back solve for (long i = k; i >= 0; i--) { - y[i] /= h(i,i); + y[i] /= h(i, i); for (long j = i - 1; j >= 0; j--) - y[j] -= h(j,i) * y[i]; + y[j] -= h(j, i) * y[i]; } for (long j = 0; j <= k; j++) { - v_j = f_buffer[v_idx0 + j]; + v_j = f_buffer[v_idx0 + j]; for (long i = 0; i < size; i++) x[i] += v_j[i] * y[j]; } @@ -1594,7 +1580,7 @@ int Linear_EQS::GMRES() { double normb = Norm(b); // Check if the norm of b is samll enough for convengence - if(CheckNormRHS(normb)) + if (CheckNormRHS(normb)) return 0; // @@ -1605,7 +1591,7 @@ int Linear_EQS::GMRES() double* sn = f_buffer[2]; double* w = f_buffer[4]; double* r = f_buffer[5]; - double* t = f_buffer[6]; // Buffer array + double* t = f_buffer[6]; // Buffer array double *v, *v_k; int v_idx0 = 7; @@ -1616,35 +1602,35 @@ int Linear_EQS::GMRES() // Here Mb-->r normb = Norm(r); - //Norm of M r +// Norm of M r #ifdef JFNK_H2M - if(a_pcs) /// JFNK. 20.10.2010 + if (a_pcs) /// JFNK. 20.10.2010 { - for(long l = 0; l < size_A; l++) + for (long l = 0; l < size_A; l++) r[l] = b[l]; a_pcs->Jacobian_Multi_Vector_JFNK(x, w); - for(long l = 0; l < size_A; l++) - r[l] -= w[l]; // r = b-Ax. + for (long l = 0; l < size_A; l++) + r[l] -= w[l]; // r = b-Ax. } else { - A->multiVec(x,w); // Ax-->w - for(long l = 0; l < size_A; l++) - r[l] = b[l] - w[l]; // r = b-Ax. + A->multiVec(x, w); // Ax-->w + for (long l = 0; l < size_A; l++) + r[l] = b[l] - w[l]; // r = b-Ax. } #else // ifdef JFNK_H2M - A->multiVec(x,w); // Ax-->w - for(long l = 0; l < size_A; l++) - r[l] = b[l] - w[l]; // r = b-Ax. + A->multiVec(x, w); // Ax-->w + for (long l = 0; l < size_A; l++) + r[l] = b[l] - w[l]; // r = b-Ax. #endif - Precond(r, w); // Mr-->w + Precond(r, w); // Mr-->w beta = Norm(w); if (normb < DBL_MIN) normb = 1; - //if ((error = Norm(r) / normb) <= tol) + // if ((error = Norm(r) / normb) <= tol) if ((error = beta / normb) <= tol) { Message(); @@ -1654,22 +1640,22 @@ int Linear_EQS::GMRES() iter = 1; while (iter <= max_iter) { - v = f_buffer[v_idx0]; - for(long l = 0; l < size_A; l++) - v[l] = r[l] / beta; // r/beta - for(long l = 0; l < m + 1; l++) + v = f_buffer[v_idx0]; + for (long l = 0; l < size_A; l++) + v[l] = r[l] / beta; // r/beta + for (long l = 0; l < m + 1; l++) s[l] = 0.0; s[0] = beta; long i; for (i = 0; i < m && iter <= max_iter; i++, iter++) { - v = f_buffer[v_idx0 + i]; + v = f_buffer[v_idx0 + i]; #ifdef JFNK_H2M - if(a_pcs) /// JFNK. + if (a_pcs) /// JFNK. a_pcs->Jacobian_Multi_Vector_JFNK(v, t); else #endif - A->multiVec(v, t); + A->multiVec(v, t); Precond(t, w); for (long k = 0; k <= i; k++) @@ -1677,19 +1663,19 @@ int Linear_EQS::GMRES() v_k = f_buffer[v_idx0 + k]; H(k, i) = dot(w, v_k); - for(long l = 0; l < size_A; l++) + for (long l = 0; l < size_A; l++) w[l] -= H(k, i) * v_k[l]; } H(i + 1, i) = Norm(w); v_k = f_buffer[v_idx0 + i + 1]; - for(long l = 0; l < size_A; l++) + for (long l = 0; l < size_A; l++) v_k[l] = w[l] / H(i + 1, i); for (long k = 0; k < i; k++) - Set_Plane_Rotation(H(k,i), H(k + 1,i), cs[k], sn[k]); + Set_Plane_Rotation(H(k, i), H(k + 1, i), cs[k], sn[k]); - Get_Plane_Rotation(H(i,i), H(i + 1,i), cs[i], sn[i]); - Set_Plane_Rotation(H(i,i), H(i + 1,i), cs[i], sn[i]); + Get_Plane_Rotation(H(i, i), H(i + 1, i), cs[i], sn[i]); + Set_Plane_Rotation(H(i, i), H(i + 1, i), cs[i], sn[i]); Set_Plane_Rotation(s[i], s[i + 1], cs[i], sn[i]); if ((error = fabs(s[i + 1]) / normb) < tol) @@ -1702,11 +1688,11 @@ int Linear_EQS::GMRES() Update(x, i - 1, H, s); #ifdef JFNK_H2M - if(a_pcs) /// JFNK. + if (a_pcs) /// JFNK. { a_pcs->Jacobian_Multi_Vector_JFNK(x, t); /// In exact Newton control. 26.01.2010. - if(a_pcs->ForceTermCriterion(t, iter)) + if (a_pcs->ForceTermCriterion(t, iter)) { Message(); return iter <= max_iter; @@ -1714,11 +1700,11 @@ int Linear_EQS::GMRES() } else #endif - A->multiVec(x, t); + A->multiVec(x, t); - for(long l = 0; l < size_A; l++) - w[l] = b[l] - t[l]; // r = b-Ax. - Precond(w, r); // M*r + for (long l = 0; l < size_A; l++) + w[l] = b[l] - t[l]; // r = b-Ax. + Precond(w, r); // M*r beta = Norm(r); if ((error = beta / normb) < tol) @@ -1733,7 +1719,7 @@ int Linear_EQS::GMRES() } //----------------------------------------------------------------- //#endif // USE_MPI -#endif //GMRES +#endif // GMRES #ifdef JFNK_H2M /*! \brief Initialize the Jacobi preconditioner fot JFNK @@ -1741,7 +1727,7 @@ int Linear_EQS::GMRES() */ void Linear_EQS::Init_Precond_Jacobi_JFNK() { - for(long i = 0; i < size_global; i++) + for (long i = 0; i < size_global; i++) prec_M[i] = 0.; } @@ -1755,18 +1741,18 @@ void Linear_EQS::Precond_Jacobi(const double* vec_s, double* vec_r) { double val; - for(long i = 0; i < size_A; i++) + for (long i = 0; i < size_A; i++) { val = prec_M[i]; // DiagonalEntries(prec_M); - // +// #if defined(NEW_BREDUCE) dom->ReduceBorderV(prec_M); #else dom->Local2Border(prec_M, border_buffer0); // to buffer - MPI_Allreduce(border_buffer0, border_buffer1, - A->Dof() * dom->BSize(), MPI_DOUBLE,MPI_SUM,comm_DDC); + MPI_Allreduce(border_buffer0, border_buffer1, A->Dof() * dom->BSize(), MPI_DOUBLE, MPI_SUM, comm_DDC); #endif dom->Border2Local(border_buffer1, prec_M); } @@ -1797,10 +1782,10 @@ void Linear_EQS::ComputePreconditioner_Jacobi() void Linear_EQS::Precond_Jacobi(const double* vec_s, double* vec_r) { double val; - for(long i = 0; i < A->Dim(); i++) + for (long i = 0; i < A->Dim(); i++) { val = prec_M[i]; - if(val > DBL_EPSILON) + if (val > DBL_EPSILON) vec_r[i] = vec_s[i] / val; else vec_r[i] = vec_s[i]; @@ -1826,29 +1811,29 @@ int Linear_EQS::CG(double* xg, const long n) //*** Norm b double bNorm_new; double buff_fl = dom->Dot_Interior(b, b); - MPI_Allreduce(&buff_fl, &bNorm_new, 1, MPI_DOUBLE,MPI_SUM,comm_DDC); + MPI_Allreduce(&buff_fl, &bNorm_new, 1, MPI_DOUBLE, MPI_SUM, comm_DDC); dom->Local2Border(b, border_buffer0); // p_b s_b as buffer - MPI_Allreduce(border_buffer0, border_buffer1, size_b, MPI_DOUBLE,MPI_SUM,comm_DDC); + MPI_Allreduce(border_buffer0, border_buffer1, size_b, MPI_DOUBLE, MPI_SUM, comm_DDC); // (rhs on border) buff_fl = bNorm_new + dot(border_buffer1, border_buffer1, size_b); bNorm_new = sqrt(buff_fl); // Check if the norm of b is samll enough for convengence - if(CheckNormRHS(bNorm_new)) + if (CheckNormRHS(bNorm_new)) return 0; //*** r = b-Ax // A*x dom->Global2Local(xg, x, n); - A->multiVec(x,s); // s as buffer - for(long i = 0; i < size; i++) - r[i] = b[i] - s[i]; // r = b-Ax + A->multiVec(x, s); // s as buffer + for (long i = 0; i < size; i++) + r[i] = b[i] - s[i]; // r = b-Ax // Collect border r dom->Local2Border(r, border_buffer0); // - MPI_Allreduce(border_buffer0, border_buffer1, size_b, MPI_DOUBLE,MPI_SUM,comm_DDC); + MPI_Allreduce(border_buffer0, border_buffer1, size_b, MPI_DOUBLE, MPI_SUM, comm_DDC); dom->Border2Local(border_buffer1, r); // // Preconditioning: M^{-1}r Precond(r, s); - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) p[i] = s[i]; // Check the convergence if ((error = Norm(r) / bNorm) < tol) @@ -1862,9 +1847,9 @@ int Linear_EQS::CG(double* xg, const long n) for (iter = 1; iter <= max_iter; ++iter) { MatrixMulitVec(p, s); - const double alpha = rr / dot(p,s); + const double alpha = rr / dot(p, s); // Update - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) { x[i] += alpha * p[i]; r[i] -= alpha * s[i]; @@ -1875,10 +1860,10 @@ int Linear_EQS::CG(double* xg, const long n) Precond(r, s); // double rrM1 = rr; - rr = dot(s, r); + rr = dot(s, r); // const double beta = rr / rrM1; - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) p[i] = s[i] + beta * p[i]; } // @@ -1916,27 +1901,27 @@ int Linear_EQS::CGS(double* xg, const long n) //*** Norm b double bNorm_new; double buff_fl = dom->Dot_Interior(b, b); - MPI_Allreduce(&buff_fl, &bNorm_new, 1, MPI_DOUBLE,MPI_SUM,comm_DDC); + MPI_Allreduce(&buff_fl, &bNorm_new, 1, MPI_DOUBLE, MPI_SUM, comm_DDC); dom->Local2Border(b, border_buffer0); // - MPI_Allreduce(border_buffer0, border_buffer1, size_b, MPI_DOUBLE,MPI_SUM,comm_DDC); + MPI_Allreduce(border_buffer0, border_buffer1, size_b, MPI_DOUBLE, MPI_SUM, comm_DDC); // (rhs on border) buff_fl = bNorm_new + dot(border_buffer1, border_buffer1, size_b); bNorm_new = sqrt(buff_fl); // Check if the norm of b is samll enough for convengence - if(CheckNormRHS(bNorm_new)) + if (CheckNormRHS(bNorm_new)) return 0; //*** r = b-Ax // A*x dom->Global2Local(xg, x, n); - A->multiVec(x,v); // v as buffer - for(long i = 0; i < size; i++) - r0[i] = b[i] - v[i]; // r = b-Ax + A->multiVec(x, v); // v as buffer + for (long i = 0; i < size; i++) + r0[i] = b[i] - v[i]; // r = b-Ax // Collect border r dom->Local2Border(r0, border_buffer0); // buffer - MPI_Allreduce(border_buffer0, border_buffer1, size_b, MPI_DOUBLE,MPI_SUM,comm_DDC); + MPI_Allreduce(border_buffer0, border_buffer1, size_b, MPI_DOUBLE, MPI_SUM, comm_DDC); dom->Border2Local(border_buffer1, r0); // - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) { r[i] = r0[i]; v[i] = 0.; @@ -1954,12 +1939,12 @@ int Linear_EQS::CGS(double* xg, const long n) break; // if (iter == 1) - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) p[i] = u[i] = r[i]; else { const double beta = rho_1 / rho_2; - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) { u[i] = r[i] + beta * q[i]; p[i] = u[i] + beta * (q[i] + beta * p[i]); @@ -1972,19 +1957,19 @@ int Linear_EQS::CGS(double* xg, const long n) // const double alpha = rho_1 / dot(r0, v); // - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) { q[i] = u[i] - alpha * v[i]; q_h[i] = u[i] + q[i]; } // Preconditioner Precond(q_h, u_h); - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) x[i] += alpha * u_h[i]; // MatrixMulitVec(u_h, q_h); // - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) r[i] -= alpha * q_h[i]; rho_2 = rho_1; if ((error = Norm(r) / bNorm) < tol) @@ -1997,7 +1982,7 @@ int Linear_EQS::CGS(double* xg, const long n) // return iter <= max_iter; } -#define TEST_MPII +#define TEST_MPII /************************************************************************* GeoSys-Function: Task: Parallel BiCGStab solver @@ -2027,11 +2012,11 @@ int Linear_EQS::BiCGStab(double* xg, const long n) double alpha = 1.0; double omega = 1.0; -#ifdef TEST_MPI - //TEST +#ifdef TEST_MPI + // TEST string test = "rank"; char stro[64]; - sprintf(stro, "%d",myrank); + sprintf(stro, "%d", myrank); string test1 = test + (string)stro + "Assemble.txt"; ofstream Dum(test1.c_str(), ios::out); Dum.width(20); @@ -2040,42 +2025,43 @@ int Linear_EQS::BiCGStab(double* xg, const long n) Dum << "Time step: " << aktueller_zeitschritt << "\n"; Dum << "Norm b inner " << dom->Dot_Interior(b, b) << "\n"; - // if(A->Dof()==1) - // Dum.close(); +// if(A->Dof()==1) +// Dum.close(); #endif //*** Norm b double bNorm_new; double buff_fl = dom->Dot_Interior(b, b); - MPI_Allreduce(&buff_fl, &bNorm_new, 1, MPI_DOUBLE,MPI_SUM,comm_DDC); + MPI_Allreduce(&buff_fl, &bNorm_new, 1, MPI_DOUBLE, MPI_SUM, comm_DDC); dom->Local2Border(b, border_buffer0); // buffer - MPI_Allreduce(border_buffer0, border_buffer1, size_b, MPI_DOUBLE,MPI_SUM,comm_DDC); + MPI_Allreduce(border_buffer0, border_buffer1, size_b, MPI_DOUBLE, MPI_SUM, comm_DDC); // (rhs on border) buff_fl = bNorm_new + dot(border_buffer1, border_buffer1, size_b); bNorm_new = sqrt(buff_fl); // Check if the norm of b is samll enough for convengence - if(CheckNormRHS(bNorm_new)) + if (CheckNormRHS(bNorm_new)) return 0; //*** r = b-Ax // A*x dom->Global2Local(xg, x, n); - A->multiVec(x,s); // s as buffer - for(long i = 0; i < size; i++) - r0[i] = b[i] - s[i]; // r = b-Ax + A->multiVec(x, s); // s as buffer + for (long i = 0; i < size; i++) + r0[i] = b[i] - s[i]; // r = b-Ax // Collect border r dom->Local2Border(r0, border_buffer0); // buffer - MPI_Allreduce(border_buffer0, border_buffer1, size_b, MPI_DOUBLE,MPI_SUM,comm_DDC); + MPI_Allreduce(border_buffer0, border_buffer1, size_b, MPI_DOUBLE, MPI_SUM, comm_DDC); dom->Border2Local(border_buffer1, r0); -#ifdef TEST_MPI - //TEST - //if(A->Dof()>1) +#ifdef TEST_MPI + // TEST + // if(A->Dof()>1) { Dum << " |r_0|= " << Norm(r0) << "\n"; Dum << " |b_0|= " << bNorm << "\n"; - Dum << " x " << "\n"; - for(long i = 0; i < n; i++) + Dum << " x " + << "\n"; + for (long i = 0; i < n; i++) Dum << xg[i] << "\n"; /* Dum<<" b "<<"\n"; @@ -2100,7 +2086,7 @@ int Linear_EQS::BiCGStab(double* xg, const long n) #endif // Initial. [0, size_i): internal; [size_i, size_i+size_b): border. - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) { r[i] = r0[i]; v[i] = 0.; @@ -2108,7 +2094,7 @@ int Linear_EQS::BiCGStab(double* xg, const long n) } if ((error = Norm(r) / bNorm) < tol) { - if(myrank == 0) // Make screen output only by processor 0 + if (myrank == 0) // Make screen output only by processor 0 Message(); return 0; } @@ -2129,21 +2115,21 @@ int Linear_EQS::BiCGStab(double* xg, const long n) if (fabs(rho_1) < DBL_MIN) break; -#ifdef TEST_MPI - //TEST +#ifdef TEST_MPI + // TEST // if(A->Dof()>1) Dum << " rho_1 " << rho_1 << "\n"; #endif if (iter == 1) // p[0, size_i): internal; p[size_i, size_i+size_b)-->p_b: border. - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) p[i] = r[i]; else { const double beta = (rho_1 / rho_0) * (alpha / omega); // [0, size_i): internal; [size_i, size_i+size_b): border. - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) p[i] = r[i] + beta * (p[i] - omega * v[i]); } // Preconditioner @@ -2153,25 +2139,25 @@ int Linear_EQS::BiCGStab(double* xg, const long n) // alpha = rho_1 / dot(r0, v); -#ifdef TEST_MPI - //TEST +#ifdef TEST_MPI + // TEST // if(A->Dof()>1) { - //TEST - Dum << " alpha " << alpha << " dot(r0, v) " << - dot(r0, v) << " dot(r0, r) " << dot(r0, r) << "\n"; + // TEST + Dum << " alpha " << alpha << " dot(r0, v) " << dot(r0, v) << " dot(r0, r) " << dot(r0, r) << "\n"; - Dum << "\n r0, r, v " << "\n"; + Dum << "\n r0, r, v " + << "\n"; } #endif // - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) s[i] = r[i] - alpha * v[i]; - const double norm_v = sqrt(dot(s,s)); + const double norm_v = sqrt(dot(s, s)); if ((error = norm_v / bNorm) < tol) { - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) x[i] += alpha * p_h[i]; break; } @@ -2181,35 +2167,35 @@ int Linear_EQS::BiCGStab(double* xg, const long n) // A* M^{-1}s MatrixMulitVec(s_h, t); // - const double tt = dot(t,t); + const double tt = dot(t, t); -#ifdef TEST_MPI - //TEST - //TEST +#ifdef TEST_MPI + // TEST + // TEST // if(A->Dof()>1) Dum << " tt " << tt << "\n"; #endif - if(tt > DBL_MIN) - omega = dot(t,s) / tt; + if (tt > DBL_MIN) + omega = dot(t, s) / tt; else omega = 1.0; // Update solution - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) { x[i] += alpha * p_h[i] + omega * s_h[i]; r[i] = s[i] - omega * t[i]; } rho_0 = rho_1; // - const double norm_v1 = sqrt(dot(r,r)); + const double norm_v1 = sqrt(dot(r, r)); -#ifdef TEST_MPI - //TEST - //TEST +#ifdef TEST_MPI + // TEST + // TEST // if(A->Dof()>1) { - Dum << " sqrt(dot(r,r)) " << norm_v1 << "\n"; + Dum << " sqrt(dot(r,r)) " << norm_v1 << "\n"; // exit(0); } #endif @@ -2222,24 +2208,25 @@ int Linear_EQS::BiCGStab(double* xg, const long n) break; } -#ifdef TEST_MPI - //TEST - // Dum.close(); - //MPI_Finalize(); - // exit(0); +#ifdef TEST_MPI +// TEST +// Dum.close(); +// MPI_Finalize(); +// exit(0); #endif } // // concancert internal x dom->CatInnerX(xg, x, n); - // Form the local to global - // dom->Border2Global(x_b, xg, n); +// Form the local to global +// dom->Border2Global(x_b, xg, n); -#ifdef TEST_MPI +#ifdef TEST_MPI // if(A->Dof()>1) { - Dum << " x " << "\n"; - for(long i = 0; i < n; i++) + Dum << " x " + << "\n"; + for (long i = 0; i < n; i++) Dum << xg[i] << "\n"; Dum.close(); // exit(0); @@ -2282,46 +2269,46 @@ int Linear_EQS::BiCG(double* xg, const long n) //*** Norm b double bNorm_new; double buff_fl = dom->Dot_Interior(b, b); - MPI_Allreduce(&buff_fl, &bNorm_new, 1, MPI_DOUBLE,MPI_SUM,comm_DDC); + MPI_Allreduce(&buff_fl, &bNorm_new, 1, MPI_DOUBLE, MPI_SUM, comm_DDC); dom->Local2Border(b, border_buffer0); // - MPI_Allreduce(border_buffer0, border_buffer1, size_b, MPI_DOUBLE,MPI_SUM,comm_DDC); + MPI_Allreduce(border_buffer0, border_buffer1, size_b, MPI_DOUBLE, MPI_SUM, comm_DDC); // (rhs on border) buff_fl = bNorm_new + dot(border_buffer1, border_buffer1, size_b); bNorm_new = sqrt(buff_fl); // Check if the norm of b is samll enough for convengence // Check if the norm of b is samll enough for convengence - if(CheckNormRHS(bNorm_new)) + if (CheckNormRHS(bNorm_new)) return 0; //*** r = b-Ax // A*x dom->Global2Local(xg, x, n); - A->multiVec(x,rt); // rt as buffer - for(long i = 0; i < size; i++) - r[i] = b[i] - rt[i]; // r = b-Ax + A->multiVec(x, rt); // rt as buffer + for (long i = 0; i < size; i++) + r[i] = b[i] - rt[i]; // r = b-Ax // Collect border r dom->Local2Border(r, border_buffer0); // buffer - MPI_Allreduce(border_buffer0, border_buffer1, size_b, MPI_DOUBLE,MPI_SUM,comm_DDC); + MPI_Allreduce(border_buffer0, border_buffer1, size_b, MPI_DOUBLE, MPI_SUM, comm_DDC); dom->Border2Local(border_buffer1, r); // // Initial. - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) { r[i] = b[i] - rt[i]; rt[i] = r[i]; } if ((error = Norm(r) / bNorm) < tol) { - if(myrank == 0) // Make screen output only by processor 0 + if (myrank == 0) // Make screen output only by processor 0 Message(); return 0; } #ifdef CG_test - //TEST + // TEST string test = "rank"; char stro[64]; - sprintf(stro, "%d",myrank); + sprintf(stro, "%d", myrank); string test1 = test + (string)stro + "_Assemble.txt"; ofstream Dum(test1.c_str(), ios::out); Dum.width(20); @@ -2351,7 +2338,7 @@ int Linear_EQS::BiCG(double* xg, const long n) } // if (iter == 1) - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) { p[i] = z[i]; pt[i] = zt[i]; @@ -2359,7 +2346,7 @@ int Linear_EQS::BiCG(double* xg, const long n) else { beta = rho1 / rho2; - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) { p[i] = z[i] + beta * p[i]; pt[i] = zt[i] + beta * pt[i]; @@ -2367,13 +2354,13 @@ int Linear_EQS::BiCG(double* xg, const long n) } MatrixMulitVec(p, q); TransMatrixMulitVec(pt, qt); - alpha = rho1 / dot(pt,q); + alpha = rho1 / dot(pt, q); #ifdef CG_test Dum << " alpha " << alpha << "\n"; #endif - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) { x[i] += alpha * p[i]; r[i] -= alpha * q[i]; @@ -2405,5 +2392,5 @@ int Linear_EQS::BiCG(double* xg, const long n) } #endif //------------------------------------------------------------------------ -} // namespace -#endif // if defined(NEW_EQS) +} // namespace +#endif // if defined(NEW_EQS) diff --git a/FEM/equation_class.h b/FEM/equation_class.h index 0a183aaea..264906c1e 100644 --- a/FEM/equation_class.h +++ b/FEM/equation_class.h @@ -17,7 +17,7 @@ #define eqs_class_INC // NEW_EQS To be removed -#ifdef NEW_EQS //1.11.2007 WW +#ifdef NEW_EQS // 1.11.2007 WW #include #include #include @@ -30,16 +30,18 @@ class CNumerics; class CRFProcess; namespace process -{class CRFProcessDeformation; +{ +class CRFProcessDeformation; } namespace FiniteElement -{class CFiniteElementStd; - class CFiniteElementVec; +{ +class CFiniteElementStd; +class CFiniteElementVec; } -using ::CRFProcess; -using process::CRFProcessDeformation; -using FiniteElement::CFiniteElementStd; -using FiniteElement::CFiniteElementVec; +using ::CRFProcess; +using process::CRFProcessDeformation; +using FiniteElement::CFiniteElementStd; +using FiniteElement::CFiniteElementVec; // #if defined(USE_MPI) class CPARDomain; @@ -54,56 +56,55 @@ class SparseTable; class Linear_EQS { public: - Linear_EQS(const SparseTable &sparse_table, - const long dof, bool messg = true); + Linear_EQS(const SparseTable& sparse_table, const long dof, bool messg = true); #if defined(USE_MPI) Linear_EQS(const long size); #endif ~Linear_EQS(); // Configure numerics - void ConfigNumerics( CNumerics* m_num, const long n = 0); + void ConfigNumerics(CNumerics* m_num, const long n = 0); // Preconditioner; void Precond(double* vec_s, double* vec_r); void TransPrecond(double* vec_s, double* vec_r); //#if defined(USE_MPI) void Precond_Jacobi(const double* vec_s, double* vec_r); - //#endif - // +//#endif +// #ifdef JFNK_H2M /// GMRES. 01.09.2010. WW - void setPCS(::CRFProcess* the_pcs) {a_pcs = the_pcs; } + void setPCS(::CRFProcess* the_pcs) { a_pcs = the_pcs; } void Init_Precond_Jacobi_JFNK(); #endif void ComputePreconditioner(); void ComputePreconditioner_Jacobi(); - void ComputePreconditioner_ILU() { } - // - // Solver + void ComputePreconditioner_ILU() {} +// +// Solver #if defined(USE_MPI) int Solver(double* xg, const long n); int CG(double* xg, const long n); - int BiCG(double* xg, const long n); //02.2010. WW + int BiCG(double* xg, const long n); // 02.2010. WW int BiCGStab(double* xg, const long n); int CGS(double* xg, const long n); - double GetCPUtime() const { return cpu_time; } + double GetCPUtime() const { return cpu_time; } #else -#if defined(LIS) || defined(MKL) //NW +#if defined(LIS) || defined(MKL) // NW int Solver(CNumerics* num = NULL); #else int Solver(); #endif int CG(); - int BiCG(); //02.2010. WW + int BiCG(); // 02.2010. WW int BiCGStab(); - int Gauss() {return -1; } - int QMRCGStab() {return -1; } - int CGNR() {return -1; } + int Gauss() { return -1; } + int QMRCGStab() { return -1; } + int CGNR() { return -1; } int CGS(); - int Richardson() {return -1; } - int JOR() {return -1; } - int SOR() {return -1; } - int AMG1R5() {return -1; } - int UMF() {return -1; } + int Richardson() { return -1; } + int JOR() { return -1; } + int SOR() { return -1; } + int AMG1R5() { return -1; } + int UMF() { return -1; } int GMRES(); #endif // @@ -111,35 +112,36 @@ class Linear_EQS void Clean(); // // Access to the members - void SetDOF(const int dof_n) // For different processes with different DOF of OPDE. _new. 02/2010. WW + void SetDOF(const int dof_n) // For different processes with different DOF of OPDE. _new. 02/2010. WW { A->SetDOF(dof_n); } void SetKnownX_i(const long i, const double x_i); - double X(const long i) const {return x[i]; } - double RHS(const long i) const {return b[i]; } + double X(const long i) const { return x[i]; } + double RHS(const long i) const { return b[i]; } double NormX(); double NormRHS() { return bNorm; } #if defined(USE_MPI) int DOF() { return A->Dof(); } long Size() { return A->Size(); } - void SetDomain(CPARDomain* a_dom) {dom = a_dom; } + void SetDomain(CPARDomain* a_dom) { dom = a_dom; } #endif // Write - void Write(std::ostream &os = std::cout); - void WriteRHS(std::ostream &os = std::cout); - void WriteX(std::ostream &os = std::cout); - void Write_BIN(ostream &os); -private: // Dot not remove this! + void Write(std::ostream& os = std::cout); + void WriteRHS(std::ostream& os = std::cout); + void WriteX(std::ostream& os = std::cout); + void Write_BIN(ostream& os); + +private: // Dot not remove this! CSparseMatrix* A; double* b; double* x; double* prec_M; - // +// #ifdef LIS // lis solver interface starts here LIS_MATRIX AA; - LIS_VECTOR bb,xx; + LIS_VECTOR bb, xx; LIS_SOLVER solver; #endif #if defined(USE_MPI) @@ -150,9 +152,9 @@ class Linear_EQS double cpu_time; friend class ::CPARDomain; // - double dot (const double* xx, const double* yy, const long n); - inline void MatrixMulitVec(double* xx, double* yy); - inline void TransMatrixMulitVec(double* xx, double* yy); + double dot(const double* xx, const double* yy, const long n); + inline void MatrixMulitVec(double* xx, double* yy); + inline void TransMatrixMulitVec(double* xx, double* yy); #endif // std::string solver_name; @@ -168,8 +170,8 @@ class Linear_EQS long size_global; long size_A; // Operators - double dot (const double* xx, const double* yy); - inline double Norm(const double* xx) { return sqrt(dot(xx, xx)); } + double dot(const double* xx, const double* yy); + inline double Norm(const double* xx) { return sqrt(dot(xx, xx)); } inline bool CheckNormRHS(const double normb_new); #ifdef JFNK_H2M /// 30.06.2010. WW @@ -178,10 +180,10 @@ class Linear_EQS /// GMRES. 30.06.2010. WW /// GMRES H matrix mutable Matrix H; - int m_gmres; /// number of columns of H matrix - void Update(double* x, int k, Matrix &h, double* s); - void Get_Plane_Rotation(double &dx, double &dy, double &cs, double &sn); - void Set_Plane_Rotation(double &dx, double &dy, double &cs, double &sn); + int m_gmres; /// number of columns of H matrix + void Update(double* x, int k, Matrix& h, double* s); + void Get_Plane_Rotation(double& dx, double& dy, double& cs, double& sn); + void Set_Plane_Rotation(double& dx, double& dy, double& cs, double& sn); // void Message(); // Friends @@ -195,5 +197,5 @@ class Linear_EQS using Math_Group::Linear_EQS; extern std::vector EQS_Vector; -#endif // NEW_EQS +#endif // NEW_EQS #endif diff --git a/FEM/fct_mpi.cpp b/FEM/fct_mpi.cpp index 7b8a9e122..0561f8afa 100644 --- a/FEM/fct_mpi.cpp +++ b/FEM/fct_mpi.cpp @@ -19,7 +19,6 @@ #include "readNonBlankLineFromInputStream.h" - namespace FCT_MPI { // definition @@ -40,7 +39,7 @@ std::ios::pos_type ReadRank(std::ifstream* is, int myrank) while (!new_keyword) { position = is->tellg(); - line_string = readNonBlankLineFromInputStream (*is); + line_string = readNonBlankLineFromInputStream(*is); if (line_string.size() < 1) break; if (line_string.find("#") != std::string::npos) @@ -54,15 +53,20 @@ std::ios::pos_type ReadRank(std::ifstream* is, int myrank) in.str(readNonBlankLineFromInputStream(*is)); in >> temp; in.clear(); - if (temp != myrank) { - std::cout << "rank "<< myrank <<": $MYRANK is wrong. Stop reading\n"; + if (temp != myrank) + { + std::cout << "rank " << myrank << ": $MYRANK is wrong. Stop reading\n"; break; } - } else if (line_string.find("$NNEIGHBORS") != std::string::npos) { + } + else if (line_string.find("$NNEIGHBORS") != std::string::npos) + { in.str(readNonBlankLineFromInputStream(*is)); in >> n_neighbors; in.clear(); - } else if (line_string.find("$NEIGHBOR") != std::string::npos) { + } + else if (line_string.find("$NEIGHBOR") != std::string::npos) + { Neighbor nei; in.str(readNonBlankLineFromInputStream(*is)); in >> nei.rank; @@ -73,7 +77,8 @@ std::ios::pos_type ReadRank(std::ifstream* is, int myrank) in.clear(); nei.overlapping_edges.resize(n_edges); int ie1, ie2; - for (size_t i_e=0; i_e> ie1 >> ie2; in.clear(); @@ -83,20 +88,23 @@ std::ios::pos_type ReadRank(std::ifstream* is, int myrank) } } - if (n_neighbors!=ct.vec_neighbors.size()) { + if (n_neighbors != ct.vec_neighbors.size()) + { std::cout << "rank " << myrank << ": Inconsistent NNEIGHBORS!\n"; } - for (size_t i=0; i overlapping_innder_nodes; - std::set overlapping_ghost_nodes; - Neighbor& nei = ct.vec_neighbors[i]; - for (size_t i_e=0; i_e overlapping_innder_nodes; + std::set overlapping_ghost_nodes; + Neighbor& nei = ct.vec_neighbors[i]; + for (size_t i_e = 0; i_e < nei.overlapping_edges.size(); i_e++) + { + overlapping_innder_nodes.insert(nei.overlapping_edges[i_e].first); + overlapping_ghost_nodes.insert(nei.overlapping_edges[i_e].second); + } + nei.overlapping_inner_nodes.assign(overlapping_innder_nodes.begin(), overlapping_innder_nodes.end()); + nei.overlapping_ghost_nodes.assign(overlapping_ghost_nodes.begin(), overlapping_ghost_nodes.end()); } return position; @@ -105,15 +113,15 @@ std::ios::pos_type ReadRank(std::ifstream* is, int myrank) void FCTCommRead(const std::string& file_base_name) { int myrank = 0; - MPI_Comm_rank(MPI_COMM_WORLD,&myrank); + MPI_Comm_rank(MPI_COMM_WORLD, &myrank); - std::string str_var = file_base_name+".cct"; + std::string str_var = file_base_name + ".cct"; std::ifstream bc_file(str_var.data(), std::ios::in); if (!bc_file.good()) { return; } - std::cout << "rank "<< myrank << ": -> Read CCT ...\n"; + std::cout << "rank " << myrank << ": -> Read CCT ...\n"; char line[MAX_ZEILE]; std::string line_string; @@ -129,7 +137,8 @@ void FCTCommRead(const std::string& file_base_name) } if (line_string.find("#COMMUNICATION_TABLE") != std::string::npos) { - if (i_table==myrank) { + if (i_table == myrank) + { std::ios::pos_type position = ReadRank(&bc_file, myrank); bc_file.seekg(position, std::ios::beg); break; @@ -140,84 +149,96 @@ void FCTCommRead(const std::string& file_base_name) bc_file.close(); - if (ct.vec_neighbors.size()>0) { - std::cout << "rank "<< myrank << ": -> CCT data loaded\n"; - } else { - std::cout << "rank "<< myrank << ": -> No CCT data loaded\n"; + if (ct.vec_neighbors.size() > 0) + { + std::cout << "rank " << myrank << ": -> CCT data loaded\n"; + } + else + { + std::cout << "rank " << myrank << ": -> No CCT data loaded\n"; } } -void gatherR(const CommunicationTable &ct, Math_Group::Vec &globalR_plus, Math_Group::Vec &globalR_min) +void gatherR(const CommunicationTable& ct, Math_Group::Vec& globalR_plus, Math_Group::Vec& globalR_min) { - int myrank = 0; - MPI_Comm_rank(MPI_COMM_WORLD,&myrank); - - // send R^+,R^- and get R^+,R^- to/from neighbors (i: inner nodes, j: ghost nodes) - int n_neighbors = ct.vec_neighbors.size(); - std::vector vec_status(n_neighbors); - std::vector vec_req(n_neighbors); - std::vector > vec_sendbuf(n_neighbors); - std::vector > vec_recvbuf(n_neighbors); - // prepare send and receive buffer - for (int i=0; i vec_status(n_neighbors); + std::vector vec_req(n_neighbors); + std::vector > vec_sendbuf(n_neighbors); + std::vector > vec_recvbuf(n_neighbors); + // prepare send and receive buffer + for (int i = 0; i < n_neighbors; i++) + { + const Neighbor& neighbor = ct.vec_neighbors[i]; + vec_sendbuf[i].resize(neighbor.overlapping_inner_nodes.size() * 2); + vec_recvbuf[i].resize(neighbor.overlapping_ghost_nodes.size() * 2); + for (size_t j = 0; j < neighbor.overlapping_inner_nodes.size(); j++) + { + const long inner_nodeID = neighbor.overlapping_inner_nodes[j]; + vec_sendbuf[i][2 * j] = globalR_plus(inner_nodeID); + vec_sendbuf[i][2 * j + 1] = globalR_min(inner_nodeID); + } + } + // send + for (int i = 0; i < n_neighbors; i++) + { + const Neighbor& neighbor = ct.vec_neighbors[i]; + int neighbor_rank = neighbor.rank; + MPI_Isend(&vec_sendbuf[i][0], vec_sendbuf[i].size(), MPI_DOUBLE, neighbor_rank, 0, MPI_COMM_WORLD, &vec_req[i]); + } + + // receive + for (int i = 0; i < n_neighbors; i++) + { + const Neighbor& neighbor = ct.vec_neighbors[i]; + int neighbor_rank = neighbor.rank; + MPI_Irecv(&vec_recvbuf[i][0], vec_recvbuf[i].size(), MPI_DOUBLE, neighbor_rank, 0, MPI_COMM_WORLD, &vec_req[i]); + } + + // wait + MPI_Waitall(n_neighbors, &vec_req[0], &vec_status[0]); + + // update R^+, R^- + for (int i = 0; i < n_neighbors; i++) + { + const Neighbor& neighbor = ct.vec_neighbors[i]; + size_t n_ghosts = neighbor.overlapping_ghost_nodes.size(); + for (size_t j = 0; j < n_ghosts; j++) + { + const long nodeID = neighbor.overlapping_ghost_nodes[j]; + globalR_plus(nodeID) = vec_recvbuf[i][2 * j]; + globalR_min(nodeID) = vec_recvbuf[i][2 * j + 1]; + } + } } -void gatherK(const CommunicationTable &ct, Math_Group::SparseMatrixDOK &globalK) +void gatherK(const CommunicationTable& ct, Math_Group::SparseMatrixDOK& globalK) { int myrank = 0; - MPI_Comm_rank(MPI_COMM_WORLD,&myrank); + MPI_Comm_rank(MPI_COMM_WORLD, &myrank); // assume K is already assembled from local elements - if (false) { + if (false) + { int n_ranks; MPI_Comm_size(MPI_COMM_WORLD, &n_ranks); MPI_Status status; int done = 0; - if (myrank>0) { - MPI_Recv(&done, 1, MPI_INT, myrank-1, 0, MPI_COMM_WORLD, &status); + if (myrank > 0) + { + MPI_Recv(&done, 1, MPI_INT, myrank - 1, 0, MPI_COMM_WORLD, &status); } std::stringstream temp_in; globalK.Write(temp_in); - if (myrank > vec_sendbuf(n_neighbors); std::vector > vec_recvbuf(n_neighbors); // prepare send and receive buffer - for (int i=0; i0) { -// MPI_Recv(&done, 1, MPI_INT, myrank-1, 0, MPI_COMM_WORLD, &status); -// } -// -// for (int i=0; i0) { + // MPI_Recv(&done, 1, MPI_INT, myrank-1, 0, MPI_COMM_WORLD, &status); + // } + // + // for (int i=0; iNodesInUsage(); - for(size_t i = 0; i < node_size; i++) + for (size_t i = 0; i < node_size; i++) { const size_t i_glob = FCT_GLOB_ADDRESS(i); col = &fct_f[i_glob]; - for(jj = col->begin(); jj != col->end(); jj++) + for (jj = col->begin(); jj != col->end(); jj++) { const size_t j = (*jj).first; - const size_t j_glob = j; //FCT_GLOB_ADDRESS(j); - if (i_glob > j_glob || i_glob==j_glob) - continue; //symmetric part, off-diagonal + const size_t j_glob = j; // FCT_GLOB_ADDRESS(j); + if (i_glob > j_glob || i_glob == j_glob) + continue; // symmetric part, off-diagonal // Get artificial diffusion operator D - double K_ij = K(i_glob,j_glob); - double K_ji = K(j_glob,i_glob); + double K_ij = K(i_glob, j_glob); + double K_ji = K(j_glob, i_glob); if (K_ij == 0.0 && K_ji == 0.0) continue; double d1 = GetFCTADiff(K_ij, K_ji); - //double d0 = d1; //TODO should use AuxMatrix at the previous time step - //if (list_bc_nodes.find(i)!=list_bc_nodes.end() || list_bc_nodes.find(j)!=list_bc_nodes.end()) { + // double d0 = d1; //TODO should use AuxMatrix at the previous time step + // if (list_bc_nodes.find(i)!=list_bc_nodes.end() || list_bc_nodes.find(j)!=list_bc_nodes.end()) { // d1 = d0 = 0.0; //} d(i_glob, j_glob) += d1; @@ -337,44 +367,45 @@ void computeD(const MeshLib::CFEMesh* m_msh, const Math_Group::SparseMatrixDOK & } } -void debugADFlux(int myrank, MeshLib::CFEMesh* m_msh, size_t node_size, Math_Group::SparseMatrixDOK::mat_t &fct_f) +void debugADFlux(int myrank, MeshLib::CFEMesh* m_msh, size_t node_size, Math_Group::SparseMatrixDOK::mat_t& fct_f) { using Math_Group::SparseMatrixDOK; - SparseMatrixDOK::col_t* col; - SparseMatrixDOK::mat_t::const_iterator ii; - SparseMatrixDOK::col_t::const_iterator jj; - int n_ranks; - MPI_Comm_size(MPI_COMM_WORLD, &n_ranks); - MPI_Status status; - int done = 0; - if (myrank>0) { - MPI_Recv(&done, 1, MPI_INT, myrank-1, 0, MPI_COMM_WORLD, &status); - } - -// for (size_t i = 0; i < node_size; i++) -// { -// const size_t i_global = FCT_GLOB_ADDRESS(i); -// std::cout << "rank= " << myrank << ": node i=" << i_global << ", ML=" << (*ML)(i_global) << "\n"; -// } - for(size_t i = 0; i < node_size; i++) - { - const size_t i_global = FCT_GLOB_ADDRESS(i); - col = &fct_f[i]; - for(jj = col->begin(); jj != col->end(); jj++) - { - const size_t j = (*jj).first; - const size_t j_global = FCT_GLOB_ADDRESS(j); - std::cout << i_global << ", " << j_global << ": " << jj->second << "\n"; - } - } - std::cout << std::flush; - - if (myrank 0) + { + MPI_Recv(&done, 1, MPI_INT, myrank - 1, 0, MPI_COMM_WORLD, &status); + } + + // for (size_t i = 0; i < node_size; i++) + // { + // const size_t i_global = FCT_GLOB_ADDRESS(i); + // std::cout << "rank= " << myrank << ": node i=" << i_global << ", ML=" << (*ML)(i_global) << "\n"; + // } + for (size_t i = 0; i < node_size; i++) + { + const size_t i_global = FCT_GLOB_ADDRESS(i); + col = &fct_f[i]; + for (jj = col->begin(); jj != col->end(); jj++) + { + const size_t j = (*jj).first; + const size_t j_global = FCT_GLOB_ADDRESS(j); + std::cout << i_global << ", " << j_global << ": " << jj->second << "\n"; + } + } + std::cout << std::flush; + + if (myrank < n_ranks - 1) + { + MPI_Send(&done, 1, MPI_INT, myrank + 1, 0, MPI_COMM_WORLD); + } + MPI_Barrier(MPI_COMM_WORLD); } } // end FCT_MPI - diff --git a/FEM/fct_mpi.h b/FEM/fct_mpi.h index a8a55e665..d96be387d 100644 --- a/FEM/fct_mpi.h +++ b/FEM/fct_mpi.h @@ -23,7 +23,6 @@ namespace FCT_MPI { - #ifndef USE_PETSC #define FCT_GLOB_ADDRESS(i) i @@ -38,10 +37,10 @@ struct Neighbor { int rank; std::vector overlapping_edges; - std::vector overlapping_inner_nodes; - std::vector overlapping_ghost_nodes; + std::vector overlapping_inner_nodes; + std::vector overlapping_ghost_nodes; - Neighbor() : rank(0) {}; + Neighbor() : rank(0){}; }; struct CommunicationTable @@ -53,13 +52,13 @@ extern FCT_MPI::CommunicationTable ct; void FCTCommRead(const std::string& file_base_name); -void gatherK(const CommunicationTable &ct, Math_Group::SparseMatrixDOK &globalK); +void gatherK(const CommunicationTable& ct, Math_Group::SparseMatrixDOK& globalK); -void gatherR(const CommunicationTable &ct, Math_Group::Vec &globalR_plus, Math_Group::Vec &globalR_min); +void gatherR(const CommunicationTable& ct, Math_Group::Vec& globalR_plus, Math_Group::Vec& globalR_min); -void computeD(const MeshLib::CFEMesh* m_msh, const Math_Group::SparseMatrixDOK &K, Math_Group::SparseMatrixDOK &d); +void computeD(const MeshLib::CFEMesh* m_msh, const Math_Group::SparseMatrixDOK& K, Math_Group::SparseMatrixDOK& d); -void debugADFlux(int myrank, MeshLib::CFEMesh* m_msh, size_t node_size, Math_Group::SparseMatrixDOK::mat_t &fct_f); +void debugADFlux(int myrank, MeshLib::CFEMesh* m_msh, size_t node_size, Math_Group::SparseMatrixDOK::mat_t& fct_f); #endif diff --git a/FEM/fem_ele.cpp b/FEM/fem_ele.cpp old mode 100755 new mode 100644 index d24804978..d4c11bd13 --- a/FEM/fem_ele.cpp +++ b/FEM/fem_ele.cpp @@ -41,17 +41,15 @@ namespace FiniteElement Last modified: **************************************************************************/ CElement::CElement(int CoordFlag, const int order) - : MeshElement(NULL), Order(order), ele_dim(1), nGaussPoints(1), nGauss(1), - ShapeFunction(NULL), ShapeFunctionHQ(NULL), - GradShapeFunction(NULL), GradShapeFunctionHQ(NULL), - T_Flag(false), C_Flag(false), F_Flag(false), D_Flag(0), RD_Flag(false), - extrapo_method(ExtrapolationMethod::EXTRAPO_LINEAR) + : MeshElement(NULL), Order(order), ele_dim(1), nGaussPoints(1), nGauss(1), ShapeFunction(NULL), + ShapeFunctionHQ(NULL), GradShapeFunction(NULL), GradShapeFunctionHQ(NULL), T_Flag(false), C_Flag(false), + F_Flag(false), D_Flag(0), RD_Flag(false), extrapo_method(ExtrapolationMethod::EXTRAPO_LINEAR) { int i; // nGauss = 3; // - if(CoordFlag < 0) // Axisymmetry + if (CoordFlag < 0) // Axisymmetry { CoordFlag *= -1; axisymmetry = true; @@ -61,72 +59,70 @@ CElement::CElement(int CoordFlag, const int order) // dim = CoordFlag / 10; coordinate_system = CoordFlag; - for(i = 0; i < 4; i++) + for (i = 0; i < 4; i++) unit[i] = 0.0; - switch(dim) + switch (dim) { - case 1: //OK - // Memory allocated for maxium 3 nodes elements - Jacobian = new double[1]; - invJacobian = new double[1]; - shapefct = new double[2]; - shapefctHQ = new double[3]; - dshapefct = new double[6]; - dshapefctHQ = new double[9]; - break; - case 2: - // Memory allocated for maxium 9 nodes elements - Jacobian = new double[4]; - invJacobian = new double[4]; - shapefct = new double[4]; - shapefctHQ = new double[9]; - dshapefct = new double[18]; - dshapefctHQ = new double[18]; - break; - case 3: - // Memory allocated for maxium 20 nodes elements - Jacobian = new double[9]; - invJacobian = new double[9]; - shapefct = new double[8]; - shapefctHQ = new double[20]; - dshapefct = new double[24]; - dshapefctHQ = new double[60]; - // - break; + case 1: // OK + // Memory allocated for maxium 3 nodes elements + Jacobian = new double[1]; + invJacobian = new double[1]; + shapefct = new double[2]; + shapefctHQ = new double[3]; + dshapefct = new double[6]; + dshapefctHQ = new double[9]; + break; + case 2: + // Memory allocated for maxium 9 nodes elements + Jacobian = new double[4]; + invJacobian = new double[4]; + shapefct = new double[4]; + shapefctHQ = new double[9]; + dshapefct = new double[18]; + dshapefctHQ = new double[18]; + break; + case 3: + // Memory allocated for maxium 20 nodes elements + Jacobian = new double[9]; + invJacobian = new double[9]; + shapefct = new double[8]; + shapefctHQ = new double[20]; + dshapefct = new double[24]; + dshapefctHQ = new double[60]; + // + break; } time_unit_factor = 1.0; - if(M_Process) + if (M_Process) D_Flag = 4; - if(MH_Process) + if (MH_Process) D_Flag = 41; F_Flag = H_Process; T_Flag = T_Process; C_Flag = MASS_TRANSPORT_Process; - PT_Flag = 0; // PCH Initialize to be no RWPT. + PT_Flag = 0; // PCH Initialize to be no RWPT. RD_Flag = RD_Process; MCF_Flag = MULTI_COMPONENTIAL_FLOW_Process; #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - idxm = NULL; //> global indices of local matrix rows - idxn = NULL; //> global indices of local matrix columns + idxm = NULL; //> global indices of local matrix rows + idxn = NULL; //> global indices of local matrix columns local_idx = NULL; //> local index for local assemble - //local_matrix = NULL; //> local matrix - //local_vec = NULL; //> local vector +// local_matrix = NULL; //> local matrix +// local_vec = NULL; //> local vector #endif - - } // Destructor of class Element CElement::~CElement() { - delete [] Jacobian; - delete [] invJacobian; - delete [] shapefct; - delete [] shapefctHQ; - delete [] dshapefct; - delete [] dshapefctHQ; + delete[] Jacobian; + delete[] invJacobian; + delete[] shapefct; + delete[] shapefctHQ; + delete[] dshapefct; + delete[] dshapefctHQ; Jacobian = NULL; shapefct = NULL; dshapefct = NULL; @@ -134,18 +130,17 @@ CElement::~CElement() shapefctHQ = NULL; #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - if(idxm) - delete [] idxm; - if(idxn) - delete [] idxn; + if (idxm) + delete[] idxm; + if (idxn) + delete[] idxn; if (local_idx) - delete [] local_idx; - //if (local_idx) - // delete [] local_matrix; - //if (local_idx) - // delete [] local_vec; + delete[] local_idx; +// if (local_idx) +// delete [] local_matrix; +// if (local_idx) +// delete [] local_vec; #endif - } /************************************************************************** @@ -156,10 +151,9 @@ CElement::~CElement() 05/2007 WW 1D in 2D Last modified: **************************************************************************/ -void CElement::ConfigElement(CElem* MElement, const int nquadrature_points, - bool FaceIntegration) +void CElement::ConfigElement(CElem* MElement, const int nquadrature_points, bool FaceIntegration) { - CNode* a_node = NULL; //07.04.2009. WW + CNode* a_node = NULL; // 07.04.2009. WW MeshElement = MElement; Index = MeshElement->GetIndex(); nnodes = MeshElement->nnodes; @@ -171,107 +165,102 @@ void CElement::ConfigElement(CElem* MElement, const int nquadrature_points, else nNodes = nnodes; // Node indices - for(int i = 0; i < nNodes; i++) + for (int i = 0; i < nNodes; i++) nodes[i] = MeshElement->nodes_index[i]; // Put coordinates of nodes to buffer to enhance the computation - if(!FaceIntegration) + if (!FaceIntegration) { - if(dim != ele_dim) + if (dim != ele_dim) { -// a_node0 = MeshElement->nodes[0]; //07.04.2007. WW - double const* const coords_node_0 (MeshElement->nodes[0]->getData()); - for(int i = 0; i < nNodes; i++) + // a_node0 = MeshElement->nodes[0]; //07.04.2007. WW + double const* const coords_node_0(MeshElement->nodes[0]->getData()); + for (int i = 0; i < nNodes; i++) { - double const* const coords_node_i (MeshElement->nodes[i]->getData()); -// a_node = MeshElement->nodes[i]; //07.04.2007. WW -// dy = dz = 0.; -// dx = a_node->X()-a_node0->X(); -// dy = a_node->Y()-a_node0->Y(); -// dz = a_node->Z()-a_node0->Z(); - double dx (coords_node_i[0] - coords_node_0[0]); - double dy (coords_node_i[1] - coords_node_0[1]); - double dz (coords_node_i[2] - coords_node_0[2]); - - X[i] = (*MeshElement->transform_tensor)(0,0) * dx - + (*MeshElement->transform_tensor)(1,0) * dy - + (*MeshElement->transform_tensor)(2,0) * dz; - Y[i] = (*MeshElement->transform_tensor)(0,1) * dx - + (*MeshElement->transform_tensor)(1,1) * dy - + (*MeshElement->transform_tensor)(2,1) * dz; -// Z[i] = a_node->Z(); + double const* const coords_node_i(MeshElement->nodes[i]->getData()); + // a_node = MeshElement->nodes[i]; //07.04.2007. WW + // dy = dz = 0.; + // dx = a_node->X()-a_node0->X(); + // dy = a_node->Y()-a_node0->Y(); + // dz = a_node->Z()-a_node0->Z(); + double dx(coords_node_i[0] - coords_node_0[0]); + double dy(coords_node_i[1] - coords_node_0[1]); + double dz(coords_node_i[2] - coords_node_0[2]); + + X[i] = (*MeshElement->transform_tensor)(0, 0) * dx + (*MeshElement->transform_tensor)(1, 0) * dy + + (*MeshElement->transform_tensor)(2, 0) * dz; + Y[i] = (*MeshElement->transform_tensor)(0, 1) * dx + (*MeshElement->transform_tensor)(1, 1) * dy + + (*MeshElement->transform_tensor)(2, 1) * dz; + // Z[i] = a_node->Z(); Z[i] = coords_node_i[2]; } done = true; } else { - switch(dim) + switch (dim) { - case 1: - if(coordinate_system % 10 == 1) - { - for(int i = 0; i < nNodes; i++) + case 1: + if (coordinate_system % 10 == 1) { - //07.04.2007. WW -// a_node = MeshElement->nodes[i]; -// X[i] = a_node->Y(); -// Y[i] = a_node->X(); -// Z[i] = a_node->Z(); - double const* const coords_node_i ( - MeshElement->nodes[i]->getData()); - X[i] = coords_node_i[1]; - Y[i] = coords_node_i[0]; - Z[i] = coords_node_i[2]; + for (int i = 0; i < nNodes; i++) + { + // 07.04.2007. WW + // a_node = MeshElement->nodes[i]; + // X[i] = a_node->Y(); + // Y[i] = a_node->X(); + // Z[i] = a_node->Z(); + double const* const coords_node_i(MeshElement->nodes[i]->getData()); + X[i] = coords_node_i[1]; + Y[i] = coords_node_i[0]; + Z[i] = coords_node_i[2]; + } + done = true; } - done = true; - } - else if(coordinate_system % 10 == 2) - { - for(int i = 0; i < nNodes; i++) + else if (coordinate_system % 10 == 2) { - //07.04.2007. WW -// a_node = MeshElement->nodes[i]; -// X[i] = a_node->Z(); -// Y[i] = a_node->Y(); -// Z[i] = a_node->X(); - double const* const coords_node_i ( - MeshElement->nodes[i]->getData()); - X[i] = coords_node_i[2]; - Y[i] = coords_node_i[1]; - Z[i] = coords_node_i[0]; + for (int i = 0; i < nNodes; i++) + { + // 07.04.2007. WW + // a_node = MeshElement->nodes[i]; + // X[i] = a_node->Z(); + // Y[i] = a_node->Y(); + // Z[i] = a_node->X(); + double const* const coords_node_i(MeshElement->nodes[i]->getData()); + X[i] = coords_node_i[2]; + Y[i] = coords_node_i[1]; + Z[i] = coords_node_i[0]; + } + done = true; } - done = true; - } - break; - case 2: - if(coordinate_system % 10 == 2) - { - for(int i = 0; i < nNodes; i++) + break; + case 2: + if (coordinate_system % 10 == 2) { - //07.04.2007. WW -// a_node = MeshElement->nodes[i]; -// X[i] = a_node->X(); -// Y[i] = a_node->Z(); -// Z[i] = a_node->Y(); - double const* const coords_node_i ( - MeshElement->nodes[i]->getData()); - X[i] = coords_node_i[0]; - Y[i] = coords_node_i[2]; - Z[i] = coords_node_i[1]; + for (int i = 0; i < nNodes; i++) + { + // 07.04.2007. WW + // a_node = MeshElement->nodes[i]; + // X[i] = a_node->X(); + // Y[i] = a_node->Z(); + // Z[i] = a_node->Y(); + double const* const coords_node_i(MeshElement->nodes[i]->getData()); + X[i] = coords_node_i[0]; + Y[i] = coords_node_i[2]; + Z[i] = coords_node_i[1]; + } + done = true; } - done = true; - } - break; + break; } } } // - if(!done) + if (!done) { - for(int i = 0; i < nNodes; i++) + for (int i = 0; i < nNodes; i++) { - a_node = MeshElement->nodes[i]; //07.04.2007. WW - double const* const coords (a_node->getData()); + a_node = MeshElement->nodes[i]; // 07.04.2007. WW + double const* const coords(a_node->getData()); X[i] = coords[0]; Y[i] = coords[1]; Z[i] = coords[2]; @@ -279,30 +268,29 @@ void CElement::ConfigElement(CElem* MElement, const int nquadrature_points, } #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - if(!FaceIntegration) - { - if(MeshElement->g_index) // ghost nodes pcs->pcs_number_of_primary_nvals - { - act_nodes = MeshElement->g_index[0]; - act_nodes_h = MeshElement->g_index[1]; - - for(int i = 0; i < act_nodes_h; i++) - { - local_idx[i] = MeshElement->g_index[i+2]; - } - } - else - { - act_nodes = nnodes; - act_nodes_h = nnodesHQ; - for(int i = 0; i < act_nodes_h; i++) - { - local_idx[i] = i; - } - } - } -#endif + if (!FaceIntegration) + { + if (MeshElement->g_index) // ghost nodes pcs->pcs_number_of_primary_nvals + { + act_nodes = MeshElement->g_index[0]; + act_nodes_h = MeshElement->g_index[1]; + for (int i = 0; i < act_nodes_h; i++) + { + local_idx[i] = MeshElement->g_index[i + 2]; + } + } + else + { + act_nodes = nnodes; + act_nodes_h = nnodesHQ; + for (int i = 0; i < act_nodes_h; i++) + { + local_idx[i] = i; + } + } + } +#endif } /************************************************************************** @@ -316,7 +304,7 @@ void CElement::CalculateRadius() { Radius = 0.0; ComputeShapefct(1); - for(int i = 0; i < nnodes; i++) + for (int i = 0; i < nnodes; i++) Radius += shapefct[i] * X[i]; } @@ -330,7 +318,7 @@ void CElement::CalculateRadius() void CElement::setOrder(const int order) { Order = order; - if(Order == 1) + if (Order == 1) nNodes = nnodes; else if (Order == 2) nNodes = nnodesHQ; @@ -347,86 +335,88 @@ void CElement::setOrder(const int order) **************************************************************************/ void CElement::ConfigNumerics(MshElemType::type ele_type, const int nquadrature_points) { - assert(nquadrature_points>0); + assert(nquadrature_points > 0); // nGauss = GetNumericsGaussPoints(ElementType); - switch(ele_type) + switch (ele_type) { - case MshElemType::LINE: - ele_dim = 1; - nGauss = 2; - nGaussPoints = nGauss; - ShapeFunction = ShapeFunctionLine; - ShapeFunctionHQ = ShapeFunctionLineHQ; - GradShapeFunction = GradShapeFunctionLine; - GradShapeFunctionHQ = GradShapeFunctionLineHQ; - extrapo_method = ExtrapolationMethod::EXTRAPO_LINEAR; - return; - case MshElemType::QUAD: - ele_dim = 2; - nGauss = nquadrature_points; - nGaussPoints = nGauss * nGauss; - ShapeFunction = ShapeFunctionQuad; - ShapeFunctionHQ = ShapeFunctionQuadHQ; - GradShapeFunction = GradShapeFunctionQuad; - GradShapeFunctionHQ = GradShapeFunctionQuadHQ; - extrapo_method = ExtrapolationMethod::EXTRAPO_LINEAR; - return; - case MshElemType::HEXAHEDRON: - ele_dim = 3; - nGauss = nquadrature_points; - nGaussPoints = nGauss * nGauss * nGauss; - ShapeFunction = ShapeFunctionHex; - ShapeFunctionHQ = ShapeFunctionHexHQ; - GradShapeFunction = GradShapeFunctionHex; - GradShapeFunctionHQ = GradShapeFunctionHexHQ; - extrapo_method = ExtrapolationMethod::EXTRAPO_LINEAR; - return; - case MshElemType::TRIANGLE: - ele_dim = 2; - nGaussPoints = nGauss = 3; // Fixed to 3 - ShapeFunction = ShapeFunctionTri; - ShapeFunctionHQ = ShapeFunctionTriHQ; - GradShapeFunction = GradShapeFunctionTri; - GradShapeFunctionHQ = GradShapeFunctionTriHQ; - extrapo_method = ExtrapolationMethod::EXTRAPO_LINEAR; - return; - case MshElemType::TETRAHEDRON: - ele_dim = 3; - // nGaussPoints = nGauss = 15; // Fixed to 15 - nGaussPoints = nGauss = 5; // Fixed to 5 - ShapeFunction = ShapeFunctionTet; - ShapeFunctionHQ = ShapeFunctionTetHQ; - GradShapeFunction = GradShapeFunctionTet; - GradShapeFunctionHQ = GradShapeFunctionTetHQ; - extrapo_method = ExtrapolationMethod::EXTRAPO_LINEAR; - return; - case MshElemType::PRISM: - ele_dim = 3; - nGaussPoints = 6; // Fixed to 6 - nGauss = 3; // Fixed to 3 - ShapeFunction = ShapeFunctionPri; - ShapeFunctionHQ = ShapeFunctionPriHQ; - GradShapeFunction = GradShapeFunctionPri; - GradShapeFunctionHQ = GradShapeFunctionPriHQ; - extrapo_method = ExtrapolationMethod::EXTRAPO_AVERAGE; - return; - case MshElemType::PYRAMID: - ele_dim = 3; - if (Order == 1) - nGaussPoints = nGauss = 5; - else - nGaussPoints = nGauss = 8; //13; - ShapeFunction = ShapeFunctionPyra; - ShapeFunctionHQ = ShapeFunctionPyraHQ13; - GradShapeFunction = GradShapeFunctionPyra; - GradShapeFunctionHQ = GradShapeFunctionPyraHQ13; - extrapo_method = ExtrapolationMethod::EXTRAPO_AVERAGE; - return; - case MshElemType::INVALID: - std::cerr << "[CElement::ConfigNumerics] invalid element type" << "\n"; - break; - default: - std::cerr << "[CElement::ConfigNumerics] unknown element type" << "\n"; + case MshElemType::LINE: + ele_dim = 1; + nGauss = 2; + nGaussPoints = nGauss; + ShapeFunction = ShapeFunctionLine; + ShapeFunctionHQ = ShapeFunctionLineHQ; + GradShapeFunction = GradShapeFunctionLine; + GradShapeFunctionHQ = GradShapeFunctionLineHQ; + extrapo_method = ExtrapolationMethod::EXTRAPO_LINEAR; + return; + case MshElemType::QUAD: + ele_dim = 2; + nGauss = nquadrature_points; + nGaussPoints = nGauss * nGauss; + ShapeFunction = ShapeFunctionQuad; + ShapeFunctionHQ = ShapeFunctionQuadHQ; + GradShapeFunction = GradShapeFunctionQuad; + GradShapeFunctionHQ = GradShapeFunctionQuadHQ; + extrapo_method = ExtrapolationMethod::EXTRAPO_LINEAR; + return; + case MshElemType::HEXAHEDRON: + ele_dim = 3; + nGauss = nquadrature_points; + nGaussPoints = nGauss * nGauss * nGauss; + ShapeFunction = ShapeFunctionHex; + ShapeFunctionHQ = ShapeFunctionHexHQ; + GradShapeFunction = GradShapeFunctionHex; + GradShapeFunctionHQ = GradShapeFunctionHexHQ; + extrapo_method = ExtrapolationMethod::EXTRAPO_LINEAR; + return; + case MshElemType::TRIANGLE: + ele_dim = 2; + nGaussPoints = nGauss = 3; // Fixed to 3 + ShapeFunction = ShapeFunctionTri; + ShapeFunctionHQ = ShapeFunctionTriHQ; + GradShapeFunction = GradShapeFunctionTri; + GradShapeFunctionHQ = GradShapeFunctionTriHQ; + extrapo_method = ExtrapolationMethod::EXTRAPO_LINEAR; + return; + case MshElemType::TETRAHEDRON: + ele_dim = 3; + // nGaussPoints = nGauss = 15; // Fixed to 15 + nGaussPoints = nGauss = 5; // Fixed to 5 + ShapeFunction = ShapeFunctionTet; + ShapeFunctionHQ = ShapeFunctionTetHQ; + GradShapeFunction = GradShapeFunctionTet; + GradShapeFunctionHQ = GradShapeFunctionTetHQ; + extrapo_method = ExtrapolationMethod::EXTRAPO_LINEAR; + return; + case MshElemType::PRISM: + ele_dim = 3; + nGaussPoints = 6; // Fixed to 6 + nGauss = 3; // Fixed to 3 + ShapeFunction = ShapeFunctionPri; + ShapeFunctionHQ = ShapeFunctionPriHQ; + GradShapeFunction = GradShapeFunctionPri; + GradShapeFunctionHQ = GradShapeFunctionPriHQ; + extrapo_method = ExtrapolationMethod::EXTRAPO_AVERAGE; + return; + case MshElemType::PYRAMID: + ele_dim = 3; + if (Order == 1) + nGaussPoints = nGauss = 5; + else + nGaussPoints = nGauss = 8; // 13; + ShapeFunction = ShapeFunctionPyra; + ShapeFunctionHQ = ShapeFunctionPyraHQ13; + GradShapeFunction = GradShapeFunctionPyra; + GradShapeFunctionHQ = GradShapeFunctionPyraHQ13; + extrapo_method = ExtrapolationMethod::EXTRAPO_AVERAGE; + return; + case MshElemType::INVALID: + std::cerr << "[CElement::ConfigNumerics] invalid element type" + << "\n"; + break; + default: + std::cerr << "[CElement::ConfigNumerics] unknown element type" + << "\n"; } } @@ -437,17 +427,17 @@ void CElement::ConfigNumerics(MshElemType::type ele_type, const int nquadrature_ 06/2004 WW Implementation Last modified: **************************************************************************/ -double CElement::interpolate(double const * const nodalVal, const int order) const +double CElement::interpolate(double const* const nodalVal, const int order) const { int nn = nnodes; double* inTerpo = shapefct; - if(order == 2) + if (order == 2) { nn = nnodes; inTerpo = shapefctHQ; } double val = 0.0; - for(int i = 0; i < nn; i++) + for (int i = 0; i < nn; i++) val += nodalVal[i] * inTerpo[i]; return val; } @@ -465,15 +455,15 @@ double CElement::interpolate(const int idx, CRFProcess* m_pcs, const int order) int nn = nnodes; double* inTerpo = shapefct; double val = 0.0; - if(order == 2) + if (order == 2) { nn = nnodes; inTerpo = shapefctHQ; } // - for(i = 0; i < nn; i++) + for (i = 0; i < nn; i++) node_val[i] = m_pcs->GetNodeValue(nodes[i], idx); - for(int i = 0; i < nn; i++) + for (int i = 0; i < nn; i++) val += node_val[i] * inTerpo[i]; return val; } @@ -484,23 +474,22 @@ double CElement::interpolate(const int idx, CRFProcess* m_pcs, const int order) 09/2005 WW Implementation Last modified: **************************************************************************/ -//double CElement::elemnt_average (const int idx, const int order) -double CElement::elemnt_average (const int idx, CRFProcess* m_pcs, const int order ) +// double CElement::elemnt_average (const int idx, const int order) +double CElement::elemnt_average(const int idx, CRFProcess* m_pcs, const int order) { int i; int nn = nnodes; double val = 0.0; - //WW double* inTerpo = shapefct; - if(order == 2) + // WW double* inTerpo = shapefct; + if (order == 2) nn = nnodes; - //WW inTerpo = shapefctHQ; + // WW inTerpo = shapefctHQ; // - for(i = 0; i < nn; i++) + for (i = 0; i < nn; i++) node_val[i] = m_pcs->GetNodeValue(nodes[i], idx); return val / (double)nn; } - /************************************************************************** The generalized Jacobian caculation @@ -521,10 +510,10 @@ double CElement::computeJacobian(const int order) double DetJac = 0.0; double* dN = dshapefct; // double *sh = shapefct; - double dx,dy,dz; + double dx, dy, dz; dx = dy = dz = 0.0; - if(order == 2) //OK4104 + if (order == 2) // OK4104 { nodes_number = nnodesHQ; dN = dshapefctHQ; @@ -532,109 +521,107 @@ double CElement::computeJacobian(const int order) } else GradShapeFunction(dN, unit); - for(size_t i = 0; i < ele_dim*ele_dim; i++) + for (size_t i = 0; i < ele_dim * ele_dim; i++) Jacobian[i] = 0.0; //-------------------------------------------------------------------- - switch(ele_dim) + switch (ele_dim) { - //................................................................ - case 1: - // If Line in X or Z direction, coordinate is saved in local X - // If Line in 3D space, a transform is applied and cast coordinate in local X - dx = X[1] - X[0]; //+Y[1]-Y[0]; - Jacobian[0] = 0.5 * dx; - invJacobian[0] = 2.0 / dx; - DetJac = Jacobian[0]; - //WW - //if(MeshElement->area>0) - DetJac *= MeshElement->area; - //WW DetJac*=MeshElement->GetFluxArea();//CMCD - if(axisymmetry) - { - CalculateRadius(); - DetJac *= Radius; //2.0*pai*Radius; - } - break; - //................................................................ - case 2: - for(int i = 0,j = nodes_number; i < nodes_number; i++,j++) - { - Jacobian[0] += X[i] * dN[i]; - Jacobian[1] += Y[i] * dN[i]; - Jacobian[2] += X[i] * dN[j]; - Jacobian[3] += Y[i] * dN[j]; - } + //................................................................ + case 1: + // If Line in X or Z direction, coordinate is saved in local X + // If Line in 3D space, a transform is applied and cast coordinate in local X + dx = X[1] - X[0]; //+Y[1]-Y[0]; + Jacobian[0] = 0.5 * dx; + invJacobian[0] = 2.0 / dx; + DetJac = Jacobian[0]; + // WW + // if(MeshElement->area>0) + DetJac *= MeshElement->area; + // WW DetJac*=MeshElement->GetFluxArea();//CMCD + if (axisymmetry) + { + CalculateRadius(); + DetJac *= Radius; // 2.0*pai*Radius; + } + break; + //................................................................ + case 2: + for (int i = 0, j = nodes_number; i < nodes_number; i++, j++) + { + Jacobian[0] += X[i] * dN[i]; + Jacobian[1] += Y[i] * dN[i]; + Jacobian[2] += X[i] * dN[j]; + Jacobian[3] += Y[i] * dN[j]; + } - DetJac = Jacobian[0] * Jacobian[3] - Jacobian[1] * Jacobian[2]; - if (fabs(DetJac) < MKleinsteZahl) - { - std::cout << "\n*** Jacobian: Det == 0 " << DetJac << "\n"; - abort(); - } - invJacobian[0] = Jacobian[3]; - invJacobian[1] = -Jacobian[1]; - invJacobian[2] = -Jacobian[2]; - invJacobian[3] = Jacobian[0]; - for(size_t i = 0; i < ele_dim * ele_dim; i++) - invJacobian[i] /= DetJac; - // - //By WW - //if(MeshElement->area>0) - DetJac *= MeshElement->area; - //WW DetJac*=MeshElement->GetFluxArea();//CMCD - if(axisymmetry) - { - CalculateRadius(); - DetJac *= Radius; //2.0*pai*Radius; - } - break; - //................................................................ - case 3: { - int j; - for(int i = 0; i < nodes_number; i++) + DetJac = Jacobian[0] * Jacobian[3] - Jacobian[1] * Jacobian[2]; + if (fabs(DetJac) < MKleinsteZahl) + { + std::cout << "\n*** Jacobian: Det == 0 " << DetJac << "\n"; + abort(); + } + invJacobian[0] = Jacobian[3]; + invJacobian[1] = -Jacobian[1]; + invJacobian[2] = -Jacobian[2]; + invJacobian[3] = Jacobian[0]; + for (size_t i = 0; i < ele_dim * ele_dim; i++) + invJacobian[i] /= DetJac; + // + // By WW + // if(MeshElement->area>0) + DetJac *= MeshElement->area; + // WW DetJac*=MeshElement->GetFluxArea();//CMCD + if (axisymmetry) + { + CalculateRadius(); + DetJac *= Radius; // 2.0*pai*Radius; + } + break; + //................................................................ + case 3: { - j = i + nodes_number; - k = i + 2 * nodes_number; + int j; + for (int i = 0; i < nodes_number; i++) + { + j = i + nodes_number; + k = i + 2 * nodes_number; - Jacobian[0] += X[i] * dN[i]; - Jacobian[1] += Y[i] * dN[i]; - Jacobian[2] += Z[i] * dN[i]; + Jacobian[0] += X[i] * dN[i]; + Jacobian[1] += Y[i] * dN[i]; + Jacobian[2] += Z[i] * dN[i]; - Jacobian[3] += X[i] * dN[j]; - Jacobian[4] += Y[i] * dN[j]; - Jacobian[5] += Z[i] * dN[j]; + Jacobian[3] += X[i] * dN[j]; + Jacobian[4] += Y[i] * dN[j]; + Jacobian[5] += Z[i] * dN[j]; - Jacobian[6] += X[i] * dN[k]; - Jacobian[7] += Y[i] * dN[k]; - Jacobian[8] += Z[i] * dN[k]; - } - DetJac = Jacobian[0] * - (Jacobian[4] * Jacobian[8] - Jacobian[7] * Jacobian[5]) - + Jacobian[6] * - (Jacobian[1] * Jacobian[5] - Jacobian[4] * Jacobian[2]) - + Jacobian[3] * - (Jacobian[2] * Jacobian[7] - Jacobian[8] * Jacobian[1]); - - if (fabs(DetJac) < MKleinsteZahl) - { - std::cout << "\n*** Jacobian: DetJac == 0 " << DetJac << "\n"; - abort(); - } - invJacobian[0] = Jacobian[4] * Jacobian[8] - Jacobian[7] * Jacobian[5]; - invJacobian[1] = Jacobian[2] * Jacobian[7] - Jacobian[1] * Jacobian[8]; - invJacobian[2] = Jacobian[1] * Jacobian[5] - Jacobian[2] * Jacobian[4]; - // - invJacobian[3] = Jacobian[5] * Jacobian[6] - Jacobian[8] * Jacobian[3]; - invJacobian[4] = Jacobian[0] * Jacobian[8] - Jacobian[6] * Jacobian[2]; - invJacobian[5] = Jacobian[2] * Jacobian[3] - Jacobian[5] * Jacobian[0]; - // - invJacobian[6] = Jacobian[3] * Jacobian[7] - Jacobian[6] * Jacobian[4]; - invJacobian[7] = Jacobian[1] * Jacobian[6] - Jacobian[7] * Jacobian[0]; - invJacobian[8] = Jacobian[0] * Jacobian[4] - Jacobian[3] * Jacobian[1]; - for(size_t i = 0; i < ele_dim * ele_dim; i++) - invJacobian[i] /= DetJac; - break; - } // end case 3 + Jacobian[6] += X[i] * dN[k]; + Jacobian[7] += Y[i] * dN[k]; + Jacobian[8] += Z[i] * dN[k]; + } + DetJac = Jacobian[0] * (Jacobian[4] * Jacobian[8] - Jacobian[7] * Jacobian[5]) + + Jacobian[6] * (Jacobian[1] * Jacobian[5] - Jacobian[4] * Jacobian[2]) + + Jacobian[3] * (Jacobian[2] * Jacobian[7] - Jacobian[8] * Jacobian[1]); + + if (fabs(DetJac) < MKleinsteZahl) + { + std::cout << "\n*** Jacobian: DetJac == 0 " << DetJac << "\n"; + abort(); + } + invJacobian[0] = Jacobian[4] * Jacobian[8] - Jacobian[7] * Jacobian[5]; + invJacobian[1] = Jacobian[2] * Jacobian[7] - Jacobian[1] * Jacobian[8]; + invJacobian[2] = Jacobian[1] * Jacobian[5] - Jacobian[2] * Jacobian[4]; + // + invJacobian[3] = Jacobian[5] * Jacobian[6] - Jacobian[8] * Jacobian[3]; + invJacobian[4] = Jacobian[0] * Jacobian[8] - Jacobian[6] * Jacobian[2]; + invJacobian[5] = Jacobian[2] * Jacobian[3] - Jacobian[5] * Jacobian[0]; + // + invJacobian[6] = Jacobian[3] * Jacobian[7] - Jacobian[6] * Jacobian[4]; + invJacobian[7] = Jacobian[1] * Jacobian[6] - Jacobian[7] * Jacobian[0]; + invJacobian[8] = Jacobian[0] * Jacobian[4] - Jacobian[3] * Jacobian[1]; + for (size_t i = 0; i < ele_dim * ele_dim; i++) + invJacobian[i] /= DetJac; + break; + } // end case 3 } //-------------------------------------------------------------------- // Use absolute value (for grids by gmsh, whose orientation is clockwise) @@ -659,12 +646,12 @@ void CElement::RealCoordinates(double* realXYZ) { int i; double* df = shapefct; - if(Order == 2) + if (Order == 2) df = shapefctHQ; - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) realXYZ[i] = 0.0; - for(i = 0; i < nNodes; i++) + for (i = 0; i < nNodes; i++) { realXYZ[0] += df[i] * X[i]; realXYZ[1] += df[i] * Y[i]; @@ -692,26 +679,26 @@ void CElement::UnitCoordinates(double* realXYZ) x1buff[1] = Y[0]; x1buff[2] = Z[0]; - for(int i = 1; i < nNodes; i++) + for (int i = 1; i < nNodes; i++) { x1buff[0] += X[i]; x1buff[1] += Y[i]; x1buff[2] += Z[i]; } - for(size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; i++) x1buff[i] /= (double)nNodes; - for(size_t i = 0; i < ele_dim; i++) + for (size_t i = 0; i < ele_dim; i++) realXYZ[i] -= x1buff[i]; - for(size_t i = 0; i < ele_dim; i++) + for (size_t i = 0; i < ele_dim; i++) { unit[i] = 0.0; - for(size_t j = 0; j < ele_dim; j++) + for (size_t j = 0; j < ele_dim; j++) unit[i] += invJacobian[j * ele_dim + i] * realXYZ[j]; } - for(size_t i = 0; i < ele_dim; i++) + for (size_t i = 0; i < ele_dim; i++) realXYZ[i] = unit[i]; } /*************************************************************************** @@ -720,50 +707,51 @@ void CElement::UnitCoordinates(double* realXYZ) **************************************************************************/ void CElement::SetGaussPoint(const int gp, int& gp_r, int& gp_s, int& gp_t) { - switch(MeshElement->GetElementType()) + switch (MeshElement->GetElementType()) { - case MshElemType::LINE: // Line - gp_r = gp; - unit[0] = MXPGaussPkt(nGauss, gp_r); - return; - case MshElemType::QUAD: // Quadralateral - gp_r = (int)(gp / nGauss); - gp_s = gp % nGauss; - unit[0] = MXPGaussPkt(nGauss, gp_r); - unit[1] = MXPGaussPkt(nGauss, gp_s); - return; - case MshElemType::HEXAHEDRON: // Hexahedra - gp_r = (int)(gp / (nGauss * nGauss)); - gp_s = (gp % (nGauss * nGauss)); - gp_t = gp_s % nGauss; - gp_s /= nGauss; - unit[0] = MXPGaussPkt(nGauss, gp_r); - unit[1] = MXPGaussPkt(nGauss, gp_s); - unit[2] = MXPGaussPkt(nGauss, gp_t); - return; - case MshElemType::TRIANGLE: // Triangle - SamplePointTriHQ(gp, unit); - break; - case MshElemType::TETRAHEDRON: // Tedrahedra - //To be flexible SamplePointTet15(gp, unit); - SamplePointTet5(gp, unit); - return; - case MshElemType::PRISM: // Prism - gp_r = gp % nGauss; - SamplePointTriHQ(gp_r, unit); - // - gp_s = nGaussPoints/nGauss; - gp_t = (int)(gp / nGauss); - unit[2] = MXPGaussPkt(gp_s, gp_t); - return; - case MshElemType::PYRAMID: // Pyramid - if (Order == 1) - SamplePointPyramid5(gp, unit); - else - SamplePointPyramid8(gp, unit); //SamplePointPyramid13(gp, unit); - return; - default: - std::cerr << "CElement::SetGaussPoint invalid mesh element type given" << "\n"; + case MshElemType::LINE: // Line + gp_r = gp; + unit[0] = MXPGaussPkt(nGauss, gp_r); + return; + case MshElemType::QUAD: // Quadralateral + gp_r = (int)(gp / nGauss); + gp_s = gp % nGauss; + unit[0] = MXPGaussPkt(nGauss, gp_r); + unit[1] = MXPGaussPkt(nGauss, gp_s); + return; + case MshElemType::HEXAHEDRON: // Hexahedra + gp_r = (int)(gp / (nGauss * nGauss)); + gp_s = (gp % (nGauss * nGauss)); + gp_t = gp_s % nGauss; + gp_s /= nGauss; + unit[0] = MXPGaussPkt(nGauss, gp_r); + unit[1] = MXPGaussPkt(nGauss, gp_s); + unit[2] = MXPGaussPkt(nGauss, gp_t); + return; + case MshElemType::TRIANGLE: // Triangle + SamplePointTriHQ(gp, unit); + break; + case MshElemType::TETRAHEDRON: // Tedrahedra + // To be flexible SamplePointTet15(gp, unit); + SamplePointTet5(gp, unit); + return; + case MshElemType::PRISM: // Prism + gp_r = gp % nGauss; + SamplePointTriHQ(gp_r, unit); + // + gp_s = nGaussPoints / nGauss; + gp_t = (int)(gp / nGauss); + unit[2] = MXPGaussPkt(gp_s, gp_t); + return; + case MshElemType::PYRAMID: // Pyramid + if (Order == 1) + SamplePointPyramid5(gp, unit); + else + SamplePointPyramid8(gp, unit); // SamplePointPyramid13(gp, unit); + return; + default: + std::cerr << "CElement::SetGaussPoint invalid mesh element type given" + << "\n"; } } /*************************************************************************** @@ -786,40 +774,40 @@ double CElement::GetGaussData(int gp, int& gp_r, int& gp_s, int& gp_t) { double fkt = 0.0; SetGaussPoint(gp, gp_r, gp_s, gp_t); - switch(MeshElement->GetElementType()) + switch (MeshElement->GetElementType()) { - case MshElemType::LINE: // Line - fkt = computeJacobian(Order) * MXPGaussFkt(nGauss, gp_r); - break; - case MshElemType::QUAD: // Quadralateral - fkt = computeJacobian(Order); - fkt *= MXPGaussFkt(nGauss, gp_r) * MXPGaussFkt(nGauss, gp_s); - break; - case MshElemType::HEXAHEDRON: // Hexahedra - fkt = computeJacobian(Order); - fkt *= MXPGaussFkt(nGauss, gp_r) * MXPGaussFkt(nGauss, gp_s) - * MXPGaussFkt(nGauss, gp_t); - break; - case MshElemType::TRIANGLE: // Triangle - fkt = computeJacobian(Order); - fkt *= unit[2]; // Weights - break; - case MshElemType::TETRAHEDRON: // Tedrahedra - //To be flexible SamplePointTet15(gp, unit); - fkt = computeJacobian(Order); - fkt *= unit[3]; // Weights - break; - case MshElemType::PRISM: // Prism - fkt = computeJacobian(Order); - // Weights - fkt *= MXPGaussFktTri(nGauss, gp_r) * MXPGaussFkt(gp_s, gp_t); - break; - case MshElemType::PYRAMID: // Pyramid - fkt = computeJacobian(Order); - fkt *= unit[3]; // Weights - break; - default: - std::cerr << "CElement::GetGaussData invalid mesh element type given" << "\n"; + case MshElemType::LINE: // Line + fkt = computeJacobian(Order) * MXPGaussFkt(nGauss, gp_r); + break; + case MshElemType::QUAD: // Quadralateral + fkt = computeJacobian(Order); + fkt *= MXPGaussFkt(nGauss, gp_r) * MXPGaussFkt(nGauss, gp_s); + break; + case MshElemType::HEXAHEDRON: // Hexahedra + fkt = computeJacobian(Order); + fkt *= MXPGaussFkt(nGauss, gp_r) * MXPGaussFkt(nGauss, gp_s) * MXPGaussFkt(nGauss, gp_t); + break; + case MshElemType::TRIANGLE: // Triangle + fkt = computeJacobian(Order); + fkt *= unit[2]; // Weights + break; + case MshElemType::TETRAHEDRON: // Tedrahedra + // To be flexible SamplePointTet15(gp, unit); + fkt = computeJacobian(Order); + fkt *= unit[3]; // Weights + break; + case MshElemType::PRISM: // Prism + fkt = computeJacobian(Order); + // Weights + fkt *= MXPGaussFktTri(nGauss, gp_r) * MXPGaussFkt(gp_s, gp_t); + break; + case MshElemType::PYRAMID: // Pyramid + fkt = computeJacobian(Order); + fkt *= unit[3]; // Weights + break; + default: + std::cerr << "CElement::GetGaussData invalid mesh element type given" + << "\n"; } return fkt; } @@ -840,10 +828,10 @@ void CElement::FaceIntegration(double* NodeVal) double* sf = shapefct; setOrder(Order); - if(Order == 2) + if (Order == 2) { sf = shapefctHQ; - if(MeshElement->GetElementType() == MshElemType::QUAD) + if (MeshElement->GetElementType() == MshElemType::QUAD) ShapeFunctionHQ = ShapeFunctionQuadHQ8; } @@ -857,27 +845,27 @@ void CElement::FaceIntegration(double* NodeVal) // Get local coordinates and weights // Compute Jacobian matrix and its determinate //--------------------------------------------------------- - switch(MeshElement->GetElementType()) + switch (MeshElement->GetElementType()) { - case MshElemType::LINE: // Line - gp_r = gp; - unit[0] = MXPGaussPkt(nGauss, gp_r); - fkt = 0.5* det* MXPGaussFkt(nGauss, gp_r); - break; - case MshElemType::TRIANGLE: // Triangle - SamplePointTriHQ(gp, unit); - fkt = 2.0 * det * unit[2]; // Weights - break; - case MshElemType::QUAD: // Quadralateral - gp_r = (int)(gp / nGauss); - gp_s = gp % nGauss; - unit[0] = MXPGaussPkt(nGauss, gp_r); - unit[1] = MXPGaussPkt(nGauss, gp_s); - fkt = 0.25* det* MXPGaussFkt(nGauss, gp_r) * MXPGaussFkt(nGauss, gp_s); - break; - default: - std::cerr << "CElement::FaceIntegration element type not handled" << - "\n"; + case MshElemType::LINE: // Line + gp_r = gp; + unit[0] = MXPGaussPkt(nGauss, gp_r); + fkt = 0.5 * det * MXPGaussFkt(nGauss, gp_r); + break; + case MshElemType::TRIANGLE: // Triangle + SamplePointTriHQ(gp, unit); + fkt = 2.0 * det * unit[2]; // Weights + break; + case MshElemType::QUAD: // Quadralateral + gp_r = (int)(gp / nGauss); + gp_s = gp % nGauss; + unit[0] = MXPGaussPkt(nGauss, gp_r); + unit[1] = MXPGaussPkt(nGauss, gp_s); + fkt = 0.25 * det * MXPGaussFkt(nGauss, gp_r) * MXPGaussFkt(nGauss, gp_s); + break; + default: + std::cerr << "CElement::FaceIntegration element type not handled" + << "\n"; } ComputeShapefct(Order); @@ -910,9 +898,9 @@ void CElement::FaceIntegration(double* NodeVal) **************************************************************************/ void CElement::ComputeShapefct(const int order) { - if(order == 1) + if (order == 1) ShapeFunction(shapefct, unit); - else if(order == 2) + else if (order == 2) ShapeFunctionHQ(shapefctHQ, unit); } @@ -939,43 +927,47 @@ void CElement::ComputeGradShapefct(int order) static double Var[3]; double* dN = dshapefct; - if(order == 2) + if (order == 2) dN = dshapefctHQ; setOrder(order); - for(int i = 0; i < nNodes; i++) + for (int i = 0; i < nNodes; i++) { size_t j(0); - for (j = 0, j_times_nNodes_plus_i = i; j < ele_dim; j++, j_times_nNodes_plus_i += nNodes) { + for (j = 0, j_times_nNodes_plus_i = i; j < ele_dim; j++, j_times_nNodes_plus_i += nNodes) + { Var[j] = dN[j_times_nNodes_plus_i]; dN[j_times_nNodes_plus_i] = 0.0; } - for (j = 0, j_times_ele_dim_plus_k = 0, j_times_nNodes_plus_i = i; j < ele_dim; j++, j_times_nNodes_plus_i - += nNodes) { - for (size_t k = 0; k < ele_dim; k++, j_times_ele_dim_plus_k++) { + for (j = 0, j_times_ele_dim_plus_k = 0, j_times_nNodes_plus_i = i; j < ele_dim; + j++, j_times_nNodes_plus_i += nNodes) + { + for (size_t k = 0; k < ele_dim; k++, j_times_ele_dim_plus_k++) + { dN[j_times_nNodes_plus_i] += invJacobian[j_times_ele_dim_plus_k] * Var[k]; } } } // 1D element in 3D - if((dim == 3 && ele_dim == 1) || (dim == 2 && ele_dim == 1)) - for(int i = 0; i < nNodes; i++) + if ((dim == 3 && ele_dim == 1) || (dim == 2 && ele_dim == 1)) + for (int i = 0; i < nNodes; i++) { - for(size_t j = 1; j < dim; j++) - dN[j * nNodes + i] = (*MeshElement->transform_tensor)(j) * dN[i]; + for (size_t j = 1; j < dim; j++) + dN[j * nNodes + i] = (*MeshElement->transform_tensor)(j)*dN[i]; dN[i] *= (*MeshElement->transform_tensor)(0); } // 2D element in 3D - if (dim == 3 && ele_dim == 2) { - const size_t n_nodes_times_ele_dim( nNodes * ele_dim); + if (dim == 3 && ele_dim == 2) + { + const size_t n_nodes_times_ele_dim(nNodes * ele_dim); for (size_t i = 0; i < n_nodes_times_ele_dim; i++) dShapefct[i] = dN[i]; for (int i = 0; i < nNodes; i++) - for (size_t j = 0; j < dim; j++) { + for (size_t j = 0; j < dim; j++) + { dN[j * nNodes + i] = 0.0; for (size_t k = 0; k < ele_dim; k++) - dN[j * nNodes + i] += (*MeshElement->transform_tensor)(j, k) * dShapefct[k - * nNodes + i]; + dN[j * nNodes + i] += (*MeshElement->transform_tensor)(j, k) * dShapefct[k * nNodes + i]; } } } @@ -988,9 +980,9 @@ void CElement::SetCenterGP() { // Center of the reference element unit[0] = unit[1] = unit[2] = 0.0; - if(MeshElement->GetElementType() == MshElemType::TRIANGLE) + if (MeshElement->GetElementType() == MshElemType::TRIANGLE) unit[0] = unit[1] = 1.0 / 3.0; - else if(MeshElement->GetElementType() == MshElemType::TETRAHEDRON) + else if (MeshElement->GetElementType() == MshElemType::TETRAHEDRON) unit[0] = unit[1] = unit[2] = 0.25; } /*************************************************************************** @@ -1008,42 +1000,16 @@ void CElement::SetCenterGP() int CElement::GetLocalIndex(const int gp_r, const int gp_s, int gp_t) { int LoIndex = -1; - double r,s,t; + double r, s, t; //--------------------------------------------------------- // Accumulate strains //--------------------------------------------------------- switch (MeshElement->GetElementType()) { - case MshElemType::QUAD: // Quadralateral - r = MXPGaussPkt(nGauss, gp_r); - s = MXPGaussPkt(nGauss, gp_s); - if (r > 0.0 && s > 0.0) - LoIndex = 0; - else if (r < 0.0 && s > 0.0) - LoIndex = 1; - else if (r < 0.0 && s < 0.0) - LoIndex = 2; - else if (r > 0.0 && s < 0.0) - LoIndex = 3; - else if (fabs(r) < MKleinsteZahl && s > 0.0) - LoIndex = 4; - else if (r < 0.0 && fabs(s) < MKleinsteZahl) - LoIndex = 5; - else if (fabs(r) < MKleinsteZahl && s < 0.0) - LoIndex = 6; - else if (r > 0.0 && fabs(s) < MKleinsteZahl) - LoIndex = 7; - else if (fabs(r) < MKleinsteZahl && fabs(s) < MKleinsteZahl) - LoIndex = 8; - break; - case MshElemType::HEXAHEDRON: // Hexahedra - r = MXPGaussPkt(nGauss, gp_r); - s = MXPGaussPkt(nGauss, gp_s); - t = MXPGaussPkt(nGauss, gp_t); - - if (t > 0.0) - { + case MshElemType::QUAD: // Quadralateral + r = MXPGaussPkt(nGauss, gp_r); + s = MXPGaussPkt(nGauss, gp_s); if (r > 0.0 && s > 0.0) LoIndex = 0; else if (r < 0.0 && s > 0.0) @@ -1053,54 +1019,80 @@ int CElement::GetLocalIndex(const int gp_r, const int gp_s, int gp_t) else if (r > 0.0 && s < 0.0) LoIndex = 3; else if (fabs(r) < MKleinsteZahl && s > 0.0) - LoIndex = 8; - else if (r < 0.0 && fabs(s) < MKleinsteZahl) - LoIndex = 9; - else if (fabs(r) < MKleinsteZahl && s < 0.0) - LoIndex = 10; - else if (r > 0.0 && fabs(s) < MKleinsteZahl) - LoIndex = 11; - else if (fabs(r) < MKleinsteZahl && fabs(s) < MKleinsteZahl) - return -1; - } - else if (fabs(t) < MKleinsteZahl) - { - if (fabs(r) < MKleinsteZahl || fabs(s) < MKleinsteZahl) - return -1; - if (r > 0.0 && s > 0.0) - LoIndex = 16; - else if (r < 0.0 && s > 0.0) - LoIndex = 17; - else if (r < 0.0 && s < 0.0) - LoIndex = 18; - else if (r > 0.0 && s < 0.0) - LoIndex = 19; - } - if (t < 0.0) - { - if (r > 0.0 && s > 0.0) LoIndex = 4; - else if (r < 0.0 && s > 0.0) - LoIndex = 5; - else if (r < 0.0 && s < 0.0) - LoIndex = 6; - else if (r > 0.0 && s < 0.0) - LoIndex = 7; - else if (fabs(r) < MKleinsteZahl && s > 0.0) - LoIndex = 12; else if (r < 0.0 && fabs(s) < MKleinsteZahl) - LoIndex = 13; + LoIndex = 5; else if (fabs(r) < MKleinsteZahl && s < 0.0) - LoIndex = 14; + LoIndex = 6; else if (r > 0.0 && fabs(s) < MKleinsteZahl) - LoIndex = 15; + LoIndex = 7; else if (fabs(r) < MKleinsteZahl && fabs(s) < MKleinsteZahl) - return -1; - } - break; - default: - std::cerr << "CElement::GetLocalIndex invalid mesh element type given" - << "\n"; + LoIndex = 8; + break; + case MshElemType::HEXAHEDRON: // Hexahedra + r = MXPGaussPkt(nGauss, gp_r); + s = MXPGaussPkt(nGauss, gp_s); + t = MXPGaussPkt(nGauss, gp_t); + + if (t > 0.0) + { + if (r > 0.0 && s > 0.0) + LoIndex = 0; + else if (r < 0.0 && s > 0.0) + LoIndex = 1; + else if (r < 0.0 && s < 0.0) + LoIndex = 2; + else if (r > 0.0 && s < 0.0) + LoIndex = 3; + else if (fabs(r) < MKleinsteZahl && s > 0.0) + LoIndex = 8; + else if (r < 0.0 && fabs(s) < MKleinsteZahl) + LoIndex = 9; + else if (fabs(r) < MKleinsteZahl && s < 0.0) + LoIndex = 10; + else if (r > 0.0 && fabs(s) < MKleinsteZahl) + LoIndex = 11; + else if (fabs(r) < MKleinsteZahl && fabs(s) < MKleinsteZahl) + return -1; + } + else if (fabs(t) < MKleinsteZahl) + { + if (fabs(r) < MKleinsteZahl || fabs(s) < MKleinsteZahl) + return -1; + if (r > 0.0 && s > 0.0) + LoIndex = 16; + else if (r < 0.0 && s > 0.0) + LoIndex = 17; + else if (r < 0.0 && s < 0.0) + LoIndex = 18; + else if (r > 0.0 && s < 0.0) + LoIndex = 19; + } + if (t < 0.0) + { + if (r > 0.0 && s > 0.0) + LoIndex = 4; + else if (r < 0.0 && s > 0.0) + LoIndex = 5; + else if (r < 0.0 && s < 0.0) + LoIndex = 6; + else if (r > 0.0 && s < 0.0) + LoIndex = 7; + else if (fabs(r) < MKleinsteZahl && s > 0.0) + LoIndex = 12; + else if (r < 0.0 && fabs(s) < MKleinsteZahl) + LoIndex = 13; + else if (fabs(r) < MKleinsteZahl && s < 0.0) + LoIndex = 14; + else if (r > 0.0 && fabs(s) < MKleinsteZahl) + LoIndex = 15; + else if (fabs(r) < MKleinsteZahl && fabs(s) < MKleinsteZahl) + return -1; + } + break; + default: + std::cerr << "CElement::GetLocalIndex invalid mesh element type given" + << "\n"; } return LoIndex; } @@ -1116,111 +1108,111 @@ void CElement::SetExtropoGaussPoints(const int i) // switch (ElementType) { - case MshElemType::TRIANGLE: // Triangle - // Compute values at verteces - // Compute values at verteces - switch (i) - { - case 0: - unit[0] = -0.1666666666667; - unit[1] = -0.1666666666667; - break; - case 1: - unit[0] = 1.6666666666667; - unit[1] = -0.1666666666667; - break; - case 2: - unit[0] = -0.1666666666667; - unit[1] = 1.6666666666667; - break; - } - break; - case MshElemType::QUAD: // Quadralateral element - // Extropolation over nodes - switch (i) - { - case 0: - unit[0] = Xi_p; - unit[1] = Xi_p; - break; - case 1: - unit[0] = -Xi_p; - unit[1] = Xi_p; - break; - case 2: - unit[0] = -Xi_p; - unit[1] = -Xi_p; - break; - case 3: - unit[0] = Xi_p; - unit[1] = -Xi_p; - break; - } - break; - case MshElemType::HEXAHEDRON: // Hexahedra - if (i < 4) - { - j = i; - unit[2] = Xi_p; - } - else - { - j = i - 4; - unit[2] = -Xi_p; - } - switch (j) - { - case 0: - unit[0] = Xi_p; - unit[1] = Xi_p; + case MshElemType::TRIANGLE: // Triangle + // Compute values at verteces + // Compute values at verteces + switch (i) + { + case 0: + unit[0] = -0.1666666666667; + unit[1] = -0.1666666666667; + break; + case 1: + unit[0] = 1.6666666666667; + unit[1] = -0.1666666666667; + break; + case 2: + unit[0] = -0.1666666666667; + unit[1] = 1.6666666666667; + break; + } break; - case 1: - unit[0] = -Xi_p; - unit[1] = Xi_p; + case MshElemType::QUAD: // Quadralateral element + // Extropolation over nodes + switch (i) + { + case 0: + unit[0] = Xi_p; + unit[1] = Xi_p; + break; + case 1: + unit[0] = -Xi_p; + unit[1] = Xi_p; + break; + case 2: + unit[0] = -Xi_p; + unit[1] = -Xi_p; + break; + case 3: + unit[0] = Xi_p; + unit[1] = -Xi_p; + break; + } break; - case 2: - unit[0] = -Xi_p; - unit[1] = -Xi_p; + case MshElemType::HEXAHEDRON: // Hexahedra + if (i < 4) + { + j = i; + unit[2] = Xi_p; + } + else + { + j = i - 4; + unit[2] = -Xi_p; + } + switch (j) + { + case 0: + unit[0] = Xi_p; + unit[1] = Xi_p; + break; + case 1: + unit[0] = -Xi_p; + unit[1] = Xi_p; + break; + case 2: + unit[0] = -Xi_p; + unit[1] = -Xi_p; + break; + case 3: + unit[0] = Xi_p; + unit[1] = -Xi_p; + break; + } break; - case 3: - unit[0] = Xi_p; - unit[1] = -Xi_p; + case MshElemType::TETRAHEDRON: // Tedrahedra + // Compute values at verteces + switch (i) + { + case 0: + unit[0] = -0.166666666666667; + unit[1] = -0.166666666666667; + unit[2] = -0.166666666666667; + break; + case 1: + unit[0] = 1.5; + unit[1] = -0.166666666666667; + unit[2] = -0.166666666666667; + break; + case 2: + unit[0] = -0.166666666666667; + unit[1] = 1.5; + unit[2] = -0.166666666666667; + break; + case 3: + unit[0] = -0.166666666666667; + unit[1] = -0.166666666666667; + unit[2] = 1.5; + } break; - } - break; - case MshElemType::TETRAHEDRON: // Tedrahedra - // Compute values at verteces - switch (i) - { - case 0: - unit[0] = -0.166666666666667; - unit[1] = -0.166666666666667; - unit[2] = -0.166666666666667; + case MshElemType::LINE: break; - case 1: - unit[0] = 1.5; - unit[1] = -0.166666666666667; - unit[2] = -0.166666666666667; + case MshElemType::PYRAMID: // WW. 09.2012. WW + SamplePointPyramid5(i, unit); break; - case 2: - unit[0] = -0.166666666666667; - unit[1] = 1.5; - unit[2] = -0.166666666666667; + default: + unit[0] = unit[1] = unit[2] = 0.; // 07.01.2011. WW break; - case 3: - unit[0] = -0.166666666666667; - unit[1] = -0.166666666666667; - unit[2] = 1.5; - } - break; - case MshElemType::LINE: - break; - case MshElemType::PYRAMID: // WW. 09.2012. WW - SamplePointPyramid5(i, unit); - break; - default: - unit[0] = unit[1] = unit[2] = 0.; //07.01.2011. WW - break; } } @@ -1239,7 +1231,7 @@ double CElement::CalcXi_p() for (gp = 0; gp < nGauss; gp++) { r = MXPGaussPkt(nGauss, gp); - if(fabs(r) > Xi_p) + if (fabs(r) > Xi_p) Xi_p = fabs(r); } r = 1.0 / Xi_p; @@ -1258,7 +1250,7 @@ double CElement::CalcAverageGaussPointValues(double* GpValues) { // average double avg = .0; - for(int j = 0; j < nGauss; j++) + for (int j = 0; j < nGauss; j++) avg += GpValues[j]; avg /= nGauss; @@ -1292,50 +1284,50 @@ void ElementMatrix::AllocateMemory(CElem* ele, int type) nnodes = ele->GetVertexNumber(); nnodesHQ = ele->GetNodesNumber_H(); dim = ele->GetDimension(); - switch(type) + switch (type) { - case 0: // H || T Process - Mass = new Matrix(nnodes, nnodes); - // Laplace = new SymMatrix(nnodes); - Laplace = new Matrix(nnodes, nnodes); - RHS = new Vec(nnodes); - break; - case 1: // HM Partioned scheme, Flow - Mass = new Matrix(nnodes, nnodes); - // Laplace = new SymMatrix(nnodes); - Laplace = new Matrix(nnodes, nnodes); - RHS = new Vec(nnodes); - CouplingB = new Matrix(nnodes, dim * nnodesHQ); - break; - case 2: // M_Process only - size = dim * nnodesHQ; - Stiffness = new Matrix(size, size); - RHS = new Vec(size); - break; - case 3: // MH Partioned scheme, M_Process - size = dim * nnodesHQ; - Stiffness = new Matrix(size, size); - RHS = new Vec(size); - CouplingA = new Matrix(dim * nnodesHQ, nnodes); - break; - case 4: // HM monothlic scheme - Mass = new Matrix(nnodes, nnodes); - // Laplace = new SymMatrix(nnodes); - Laplace = new Matrix(nnodes, nnodes); - size = dim * nnodesHQ; - Stiffness = new Matrix(size, size); - RHS = new Vec(size + nnodes); - CouplingA = new Matrix(dim * nnodesHQ, nnodes); - CouplingB = new Matrix(nnodes, dim * nnodesHQ); - break; - case 5: // Mass Transport process - Mass = new Matrix(nnodes, nnodes); - Laplace = new Matrix(nnodes, nnodes); - Advection = new Matrix(nnodes, nnodes); - Storage = new Matrix(nnodes, nnodes); - Content = new Matrix(nnodes, nnodes); - RHS = new Vec(nnodes); - break; + case 0: // H || T Process + Mass = new Matrix(nnodes, nnodes); + // Laplace = new SymMatrix(nnodes); + Laplace = new Matrix(nnodes, nnodes); + RHS = new Vec(nnodes); + break; + case 1: // HM Partioned scheme, Flow + Mass = new Matrix(nnodes, nnodes); + // Laplace = new SymMatrix(nnodes); + Laplace = new Matrix(nnodes, nnodes); + RHS = new Vec(nnodes); + CouplingB = new Matrix(nnodes, dim * nnodesHQ); + break; + case 2: // M_Process only + size = dim * nnodesHQ; + Stiffness = new Matrix(size, size); + RHS = new Vec(size); + break; + case 3: // MH Partioned scheme, M_Process + size = dim * nnodesHQ; + Stiffness = new Matrix(size, size); + RHS = new Vec(size); + CouplingA = new Matrix(dim * nnodesHQ, nnodes); + break; + case 4: // HM monothlic scheme + Mass = new Matrix(nnodes, nnodes); + // Laplace = new SymMatrix(nnodes); + Laplace = new Matrix(nnodes, nnodes); + size = dim * nnodesHQ; + Stiffness = new Matrix(size, size); + RHS = new Vec(size + nnodes); + CouplingA = new Matrix(dim * nnodesHQ, nnodes); + CouplingB = new Matrix(nnodes, dim * nnodesHQ); + break; + case 5: // Mass Transport process + Mass = new Matrix(nnodes, nnodes); + Laplace = new Matrix(nnodes, nnodes); + Advection = new Matrix(nnodes, nnodes); + Storage = new Matrix(nnodes, nnodes); + Content = new Matrix(nnodes, nnodes); + RHS = new Vec(nnodes); + break; } } @@ -1351,21 +1343,21 @@ void ElementMatrix::AllocateMemory(CElem* ele, int type) **************************************************************************/ ElementMatrix::~ElementMatrix() { - if(Mass) + if (Mass) delete Mass; - if(Laplace) + if (Laplace) delete Laplace; - if(Advection) + if (Advection) delete Advection; - if(Storage) + if (Storage) delete Storage; - if(Content) + if (Content) delete Content; - if(RHS) + if (RHS) delete RHS; - if(CouplingA) + if (CouplingA) delete CouplingA; - if(CouplingB) + if (CouplingB) delete CouplingB; Mass = NULL; Laplace = NULL; @@ -1387,13 +1379,12 @@ Used for TOTAL_FLUX calculation **************************************************************************/ -void CElement::FaceNormalFluxIntegration(long /*element_index*/, double *NodeVal, double *NodeVal_adv, +void CElement::FaceNormalFluxIntegration(long /*element_index*/, double* NodeVal, double* NodeVal_adv, int* /*nodesFace*/, CElem* /*face*/, CRFProcess* m_pcs, double* normal_vector) { - int gp, gp_r, gp_s; double fkt = 0.0, det; - double *sf = shapefct; + double* sf = shapefct; double normal_diff_flux_interpol, normal_adv_flux_interpol; double dbuff_adv[10], flux[3]; // ElementValue* gp_ele = ele_gp_value[element_index]; @@ -1406,7 +1397,8 @@ void CElement::FaceNormalFluxIntegration(long /*element_index*/, double *NodeVal ShapeFunctionHQ = ShapeFunctionQuadHQ8; } - for (int i = 0; i < nNodes; i++) { + for (int i = 0; i < nNodes; i++) + { dbuff[i] = 0.0; dbuff_adv[i] = 0.0; } @@ -1421,52 +1413,57 @@ void CElement::FaceNormalFluxIntegration(long /*element_index*/, double *NodeVal //--------------------------------------------------------- switch (MeshElement->GetElementType()) { - case MshElemType::LINE: // Line - gp_r = gp; - unit[0] = MXPGaussPkt(nGauss, gp_r); - fkt = 0.5* det* MXPGaussFkt(nGauss, gp_r); - break; - case MshElemType::TRIANGLE: // Triangle - SamplePointTriHQ(gp, unit); - fkt = 2.0 * det * unit[2]; // Weights - break; - case MshElemType::QUAD: // Quadrilateral - gp_r = (int)(gp / nGauss); - gp_s = gp % nGauss; - unit[0] = MXPGaussPkt(nGauss, gp_r); - unit[1] = MXPGaussPkt(nGauss, gp_s); - fkt = 0.25* det* MXPGaussFkt(nGauss, gp_r) * MXPGaussFkt(nGauss, gp_s); - break; - default: - std::cerr << "Error in mass balance calculation: CElement::FaceIntegration element type not supported" << "\n"; + case MshElemType::LINE: // Line + gp_r = gp; + unit[0] = MXPGaussPkt(nGauss, gp_r); + fkt = 0.5 * det * MXPGaussFkt(nGauss, gp_r); + break; + case MshElemType::TRIANGLE: // Triangle + SamplePointTriHQ(gp, unit); + fkt = 2.0 * det * unit[2]; // Weights + break; + case MshElemType::QUAD: // Quadrilateral + gp_r = (int)(gp / nGauss); + gp_s = gp % nGauss; + unit[0] = MXPGaussPkt(nGauss, gp_r); + unit[1] = MXPGaussPkt(nGauss, gp_s); + fkt = 0.25 * det * MXPGaussFkt(nGauss, gp_r) * MXPGaussFkt(nGauss, gp_s); + break; + default: + std::cerr << "Error in mass balance calculation: CElement::FaceIntegration element type not supported" + << "\n"; } //--------------------------------------------------------- ComputeShapefct(Order); normal_diff_flux_interpol = 0.0; - if ((m_pcs->getProcessType() == FiniteElement::GROUNDWATER_FLOW) || (m_pcs->getProcessType() == FiniteElement::LIQUID_FLOW)) { - - for (int i = 0; i < nNodes; i++) // Darcy flux + if ((m_pcs->getProcessType() == FiniteElement::GROUNDWATER_FLOW) + || (m_pcs->getProcessType() == FiniteElement::LIQUID_FLOW)) + { + for (int i = 0; i < nNodes; i++) // Darcy flux normal_diff_flux_interpol += NodeVal[i] * sf[i]; - for (int i = 0; i < nNodes; i++) // Integration + for (int i = 0; i < nNodes; i++) // Integration dbuff[i] += normal_diff_flux_interpol * sf[i] * fkt; } - else if ((m_pcs->getProcessType() == FiniteElement::HEAT_TRANSPORT) || (m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT)) { - + else if ((m_pcs->getProcessType() == FiniteElement::HEAT_TRANSPORT) + || (m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT)) + { normal_adv_flux_interpol = 0.0; for (int i = 0; i < nNodes; i++) normal_adv_flux_interpol += NodeVal_adv[i] * sf[i]; - for (int i = 0; i < nNodes; i++) { // Integration + for (int i = 0; i < nNodes; i++) + { // Integration #ifdef USE_TRANSPORT_FLUX // Fick or Fourier diffusion for (int l = 0; l < 3; l++) flux[l] = gp_ele->TransportFlux(l, gp); #endif - normal_diff_flux_interpol = PointProduction(flux, normal_vector); // fabs(PointProduction(flux, normal_vector)); + normal_diff_flux_interpol + = PointProduction(flux, normal_vector); // fabs(PointProduction(flux, normal_vector)); dbuff[i] += normal_diff_flux_interpol * sf[i] * fkt; // advection dbuff_adv[i] += normal_adv_flux_interpol * sf[i] * fkt; @@ -1474,13 +1471,11 @@ void CElement::FaceNormalFluxIntegration(long /*element_index*/, double *NodeVal } // end transport } // end gauss points - for (int i = 0; i < nNodes; i++) { + for (int i = 0; i < nNodes; i++) + { NodeVal[i] = dbuff[i]; NodeVal_adv[i] = dbuff_adv[i]; } } - - - -} // end namespace FiniteElement +} // end namespace FiniteElement diff --git a/FEM/fem_ele.h b/FEM/fem_ele.h index d06a1162a..e766159ca 100644 --- a/FEM/fem_ele.h +++ b/FEM/fem_ele.h @@ -21,31 +21,33 @@ //#include //#include - #if defined(USE_PETSC) // || defined(other parallel libs)//03.3012. WW #include "prototyp.h" #else // MSH -#include "par_ddc.h" //OK //Moved from fem_ele_std.h. WW +#include "par_ddc.h" //OK //Moved from fem_ele_std.h. WW #endif - - #include "MSHEnums.h" namespace Math_Group -{ class SymMatrix; - class Matrix; - typedef Matrix Vec; +{ +class SymMatrix; +class Matrix; +typedef Matrix Vec; } namespace MeshLib -{ class CElem; - class CNode; - class CEdge; +{ +class CElem; +class CNode; +class CEdge; } class CRFProcess; -namespace process { class CRFProcessDeformation;} +namespace process +{ +class CRFProcessDeformation; +} namespace FiniteElement { @@ -70,8 +72,8 @@ using MeshLib::CElem; class CElement { public: - CElement (int CoordFlag, const int order = 1); - virtual ~CElement (); + CElement(int CoordFlag, const int order = 1); + virtual ~CElement(); // void ConfigElement(CElem* MElement, const int nquadrature_points, bool FaceIntegration = false); void ConfigFaceElement(CElem* MElement, bool FaceIntegration = false); // JOD 2014-11-10 @@ -96,40 +98,41 @@ class CElement void CalculateRadius(); // void setUnitCoordinates(double* u) - { for(int i = 0; i < 3; i++) unit[i] = u[i]; } + { + for (int i = 0; i < 3; i++) + unit[i] = u[i]; + } // Finite element matrices and vectors // Compute the local finite element matrices void LocalAssembly(const long, const int) {} - // Get values; - int GetNumGaussPoints() const {return nGaussPoints; } - int GetNumGaussSamples() const {return nGauss; } - int Dim() const {return ele_dim; } - double Getdshapefct(int in) {return dshapefct[in];} - + int GetNumGaussPoints() const { return nGaussPoints; } + int GetNumGaussSamples() const { return nGauss; } + int Dim() const { return ele_dim; } + double Getdshapefct(int in) { return dshapefct[in]; } // Integrate Neumman type BC void FaceIntegration(double* NodeVal); - void FaceNormalFluxIntegration(long index, double *NodeVal_adv, double *NodeVal, int* nodesFace, CElem* face, CRFProcess* m_pcs, double* normal_vector); // JOD 2014-11-10 + void FaceNormalFluxIntegration(long index, double* NodeVal_adv, double* NodeVal, int* nodesFace, CElem* face, + CRFProcess* m_pcs, double* normal_vector); // JOD 2014-11-10 // Coupling // - bool isTemperatureCoupling() const {return T_Flag; } - bool isFluidPressureCoupling() const {return F_Flag; } - int isDeformationCoupling() const {return D_Flag; } - int isConcentrationCoupling() const {return C_Flag; } - + bool isTemperatureCoupling() const { return T_Flag; } + bool isFluidPressureCoupling() const { return F_Flag; } + int isDeformationCoupling() const { return D_Flag; } + int isConcentrationCoupling() const { return C_Flag; } // Interpolate Gauss values - double interpolate (double const * const nodalVal, const int order = 1) const; - double interpolate (const int idx, CRFProcess* m_pcs, const int order = 1); - //double elemnt_average (const int idx, const int order =1); - double elemnt_average (const int idx, CRFProcess* m_pcs, const int order = 1); + double interpolate(double const* const nodalVal, const int order = 1) const; + double interpolate(const int idx, CRFProcess* m_pcs, const int order = 1); + // double elemnt_average (const int idx, const int order =1); + double elemnt_average(const int idx, CRFProcess* m_pcs, const int order = 1); void SetCenterGP(); - int GetGPindex() const {return gp; } - int GetElementIndex() const {return Index; } - CElem* GetMeshElement() const //OK + int GetGPindex() const { return gp; } + int GetElementIndex() const { return Index; } + CElem* GetMeshElement() const // OK { return MeshElement; } @@ -137,19 +140,18 @@ class CElement int GetLocalIndex(const int gp_r, const int gp_s, int gp_t); // DDC 05/2006 - void SetElementNodesDomain(long* ele_nodes) - {element_nodes_dom = ele_nodes; } - - void SetRWPT(const int idx) // PCH + void SetElementNodesDomain(long* ele_nodes) { element_nodes_dom = ele_nodes; } + void SetRWPT(const int idx) // PCH { PT_Flag = idx; } + protected: CElem* MeshElement; #if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW - CPARDomain* m_dom; //OK + CPARDomain* m_dom; // OK #endif - long* element_nodes_dom; //Only a pointer. For domain decomposition. WW + long* element_nodes_dom; // Only a pointer. For domain decomposition. WW friend class ::CRFProcess; friend class process::CRFProcessDeformation; @@ -166,22 +168,22 @@ class CElement // Order of shape functions // Displacement, 2. Others, 1. Default, 1 int Order; - size_t ele_dim; // Dimension of element - size_t dim; // Dimension of real dimension - int nGaussPoints; // Number of Gauss points - int nGauss; // Number of sample points for Gauss integration - int gp; // Gauss point index. - mutable double unit[4]; // Local coordintes - double* Jacobian; // Jacobian matrix - double* invJacobian; // Inverse of Jacobian matrix. - double* shapefct; // Results of linear shape function at Gauss points - double* shapefctHQ; // Results of quadratic shape function at Gauss points + size_t ele_dim; // Dimension of element + size_t dim; // Dimension of real dimension + int nGaussPoints; // Number of Gauss points + int nGauss; // Number of sample points for Gauss integration + int gp; // Gauss point index. + mutable double unit[4]; // Local coordintes + double* Jacobian; // Jacobian matrix + double* invJacobian; // Inverse of Jacobian matrix. + double* shapefct; // Results of linear shape function at Gauss points + double* shapefctHQ; // Results of quadratic shape function at Gauss points // Results of derivatives of linear shape function at Gauss points double* dshapefct; // Results of derivatives of quadratic shape function at Gauss points double* dshapefctHQ; // - double x1buff[3],x2buff[3],x3buff[3],x4buff[3]; + double x1buff[3], x2buff[3], x3buff[3], x4buff[3]; // Pointer to the linear interpolation function VoidFuncDXCDX ShapeFunction; // Pointer to the quadratic interpolation function @@ -199,13 +201,13 @@ class CElement int idx_c0, idx_c1; // Coupling flag - bool T_Flag; // Temperature - bool C_Flag; // Concentration - bool F_Flag; // Fluid - int D_Flag; // Deformation - int PT_Flag; // Particle Tracking Random Walk - bool RD_Flag; // Dual Richards - bool MCF_Flag; // Pressure Temperature coupled process + bool T_Flag; // Temperature + bool C_Flag; // Concentration + bool F_Flag; // Fluid + int D_Flag; // Deformation + int PT_Flag; // Particle Tracking Random Walk + bool RD_Flag; // Dual Richards + bool MCF_Flag; // Pressure Temperature coupled process // For extropolation double Xi_p; void SetExtropoGaussPoints(const int i); // 25.2.2007 WW @@ -218,10 +220,10 @@ class CElement int nnodes; int nnodesHQ; double time_unit_factor; - double Radius; // For axisymmetrical problems + double Radius; // For axisymmetrical problems long nodes[20]; long eqs_number[20]; - double dShapefct[27]; // Auxullary + double dShapefct[27]; // Auxullary double X[20]; double Y[20]; double Z[20]; @@ -229,16 +231,16 @@ class CElement double dbuff[20]; #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - int act_nodes; //> activated nodes - int act_nodes_h; //> activated nodes for high order elements - int *idxm; //> global indices of local matrix rows - int *idxn; //> global indices of local matrix columns - int *local_idx; //> local index for local assemble - //double *local_matrix; //> local matrix - //double *local_vec; //> local vector + int act_nodes; //> activated nodes + int act_nodes_h; //> activated nodes for high order elements + int* idxm; //> global indices of local matrix rows + int* idxn; //> global indices of local matrix columns + int* local_idx; //> local index for local assemble +// double *local_matrix; //> local matrix +// double *local_vec; //> local vector #endif ExtrapolationMethod::type extrapo_method; - ExtrapolationMethod::type GetExtrapoMethod() {return extrapo_method; } + ExtrapolationMethod::type GetExtrapoMethod() { return extrapo_method; } private: void ConfigNumerics(MshElemType::type elem_type, const int nquadrature_points); }; @@ -252,10 +254,9 @@ class CElement class ElementMatrix { public: - ElementMatrix() : Mass(NULL), Laplace(NULL), - Advection(NULL), Storage(NULL), Content(NULL), - CouplingA(NULL), CouplingB(NULL), Stiffness(NULL), - RHS(NULL) //SB4200 + ElementMatrix() + : Mass(NULL), Laplace(NULL), Advection(NULL), Storage(NULL), Content(NULL), CouplingA(NULL), CouplingB(NULL), + Stiffness(NULL), RHS(NULL) // SB4200 { } ~ElementMatrix(); @@ -269,31 +270,31 @@ class ElementMatrix void SetAdvection(Matrix* x) { Advection = x; } void SetStorage(Matrix* x) { Storage = x; } void SetContent(Matrix* x) { Content = x; } - void SetCouplingMatrixA(Matrix* cplM) {CouplingA = cplM; } - void SetCouplingMatrixB(Matrix* cplM) {CouplingB = cplM; } - void SetRHS(Vec* rhs) {RHS = rhs; } + void SetCouplingMatrixA(Matrix* cplM) { CouplingA = cplM; } + void SetCouplingMatrixB(Matrix* cplM) { CouplingB = cplM; } + void SetRHS(Vec* rhs) { RHS = rhs; } // Get members - Matrix* GetMass() {return Mass; } - Matrix* GetMass_notsym() {return Mass_notsym; } - Matrix* GetLaplace() {return Laplace; } - Matrix* GetStiffness() {return Stiffness; } - Matrix* GetAdvection() //SB4200 + Matrix* GetMass() { return Mass; } + Matrix* GetMass_notsym() { return Mass_notsym; } + Matrix* GetLaplace() { return Laplace; } + Matrix* GetStiffness() { return Stiffness; } + Matrix* GetAdvection() // SB4200 { return Advection; } - Matrix* GetStorage() //SB4200 + Matrix* GetStorage() // SB4200 { return Storage; } - Matrix* GetContent() //SB4200 + Matrix* GetContent() // SB4200 { return Content; } - Matrix* GetCouplingMatrixA() {return CouplingA; } - Matrix* GetCouplingMatrixB() {return CouplingB; } - Vec* GetRHS() {return RHS; } + Matrix* GetCouplingMatrixA() { return CouplingA; } + Matrix* GetCouplingMatrixB() { return CouplingB; } + Vec* GetRHS() { return RHS; } private: - //TODO in more gernal way for the case of sym and unsym. WW SymMatrix *Mass; + // TODO in more gernal way for the case of sym and unsym. WW SymMatrix *Mass; // SymMatrix *Laplace; Matrix* Mass; Matrix* Mass_notsym; @@ -301,12 +302,12 @@ class ElementMatrix Matrix* Advection; Matrix* Storage; Matrix* Content; - Matrix* CouplingA; // Pressure coupling for M_Process - Matrix* CouplingB; // Strain coupling gor H_Process + Matrix* CouplingA; // Pressure coupling for M_Process + Matrix* CouplingB; // Strain coupling gor H_Process Matrix* Stiffness; Vec* RHS; }; -} // end namespace +} // end namespace //============================================= // For up coupling caculation in cel_*.cpp diff --git a/FEM/fem_ele_std.cpp b/FEM/fem_ele_std.cpp index abac292ae..7cf6e57cc 100644 --- a/FEM/fem_ele_std.cpp +++ b/FEM/fem_ele_std.cpp @@ -26,7 +26,7 @@ #include "eos.h" #include "SparseMatrixDOK.h" -#include "pcs_dm.h" // displacement coupled +#include "pcs_dm.h" // displacement coupled #include "rfmat_cp.h" // Steps //#include "rf_pcs.h" @@ -34,7 +34,7 @@ #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW #include "PETSC/PETScLinearSolver.h" #else -#ifndef NEW_EQS //WW. 06.11.2008 +#ifndef NEW_EQS // WW. 06.11.2008 // Sytem matrix #include "matrix_routines.h" #endif @@ -50,39 +50,35 @@ using Math_Group::CSparseMatrix; #endif #ifdef OGS_USE_CVODE -extern "C" -{ -#include /* prototypes for CVODE fcts., consts. */ -#include /* serial N_Vector types, fcts., macros */ -#include /* prototype for CVDense */ +extern "C" { +#include /* prototypes for CVODE fcts., consts. */ +#include /* serial N_Vector types, fcts., macros */ +#include /* prototype for CVDense */ #include /* definitions DlsMat DENSE_ELEM */ #include /* definition of type realtype */ } #endif -#include "pcs_dm.h" // displacement coupled +#include "pcs_dm.h" // displacement coupled #include "PhysicalConstant.h" -extern double gravity_constant; // TEST, must be put in input file +extern double gravity_constant; // TEST, must be put in input file using namespace std; -#include "Eclipse.h" //BG 09/2009 +#include "Eclipse.h" //BG 09/2009 namespace { - -static inline double time_interpolate(double const * const a, double const * const b, double theta, FiniteElement::CElement* obj) +static inline double time_interpolate(double const* const a, double const* const b, double theta, + FiniteElement::CElement* obj) { - return (1.0-theta)*obj->interpolate(a) + theta*obj->interpolate(b); + return (1.0 - theta) * obj->interpolate(a) + theta * obj->interpolate(b); } - } - namespace FiniteElement { - using namespace PhysicalConstant; //======================================================================== // Element calculation @@ -92,19 +88,18 @@ using namespace PhysicalConstant; Programmaenderungen: 01/2005 WW Erste Version **************************************************************************/ -CFiniteElementStd:: CFiniteElementStd(CRFProcess* Pcs, const int C_Sys_Flad, const int order) - : CElement(C_Sys_Flad, order), phase(0), comp(0), SolidProp(NULL), - FluidProp(NULL), MediaProp(NULL), - pcs(Pcs), dm_pcs(NULL), HEAD_Flag(false) +CFiniteElementStd::CFiniteElementStd(CRFProcess* Pcs, const int C_Sys_Flad, const int order) + : CElement(C_Sys_Flad, order), phase(0), comp(0), SolidProp(NULL), FluidProp(NULL), MediaProp(NULL), pcs(Pcs), + dm_pcs(NULL), HEAD_Flag(false) { int i; - int size_m = 64; //25.2.2007 + int size_m = 64; // 25.2.2007 string name2; char name1[MAX_ZEILE]; cpl_pcs = NULL; - //27.2.2007 WW + // 27.2.2007 WW newton_raphson = false; - //WW + // WW if (pcs->m_num->nls_method_name.compare("NEWTON_RAPHSON") == 0) newton_raphson = true; Mass = NULL; @@ -115,13 +110,13 @@ CFiniteElementStd:: CFiniteElementStd(CRFProcess* Pcs, const int C_Sys_Flad, con Content = NULL; StrainCoupling = NULL; RHS = NULL; - FCT_MassL = NULL; //NW + FCT_MassL = NULL; // NW GasProp = NULL; // - edlluse = edttuse = NULL; - idx_vel_disp = NULL; //WW - weight_func = NULL; //WW + edlluse = edttuse = NULL; + idx_vel_disp = NULL; // WW + weight_func = NULL; // WW idx_vel = new int[3]; NodalVal1 = new double[size_m]; NodalVal2 = new double[size_m]; @@ -133,41 +128,40 @@ CFiniteElementStd:: CFiniteElementStd(CRFProcess* Pcs, const int C_Sys_Flad, con NodalVal_Sat = new double[size_m]; NodalVal_SatNW = new double[size_m]; NodalVal_p2 = new double[size_m]; - NodalVal_p20 = new double [size_m]; //AKS + NodalVal_p20 = new double[size_m]; // AKS mat = new double[9]; - NodalVal_t0 = new double[size_m]; // for TEMPERATURE1 - NodalVal_t1 = new double[size_m]; //AKS - NodalVal_t2_0 = new double[size_m]; // FOR TEMPERATURE2 previous time step - NodalVal_t2_1 = new double[size_m]; // for TEMPERATURE2 current time step - NodalVal_X0 = new double[size_m]; // for CONCENTRATION previous time step + NodalVal_t0 = new double[size_m]; // for TEMPERATURE1 + NodalVal_t1 = new double[size_m]; // AKS + NodalVal_t2_0 = new double[size_m]; // FOR TEMPERATURE2 previous time step + NodalVal_t2_1 = new double[size_m]; // for TEMPERATURE2 current time step + NodalVal_X0 = new double[size_m]; // for CONCENTRATION previous time step NodalVal_X1 = new double[size_m]; - //NW + // NW switch (C_Sys_Flad / 10) { - case 1: - weight_func = new double[2]; - break; - case 2: - weight_func = new double[4]; - break; - case 3: - weight_func = new double[8]; - break; + case 1: + weight_func = new double[2]; + break; + case 2: + weight_func = new double[4]; + break; + case 3: + weight_func = new double[8]; + break; } - // - // 27.2.2007. GravityMatrix = NULL; +// +// 27.2.2007. GravityMatrix = NULL; #if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW m_dom = NULL; #endif - eqs_rhs = NULL; //08.2006 WW + eqs_rhs = NULL; // 08.2006 WW // // 12.12.2007 WW for (i = 0; i < 4; i++) NodeShift[i] = 0; // dynamic = false; - if (pcs->pcs_type_name_vector.size() && pcs->pcs_type_name_vector[0].find( - "DYNAMIC") != string::npos) + if (pcs->pcs_type_name_vector.size() && pcs->pcs_type_name_vector[0].find("DYNAMIC") != string::npos) dynamic = true; idx_vel_disp = new int[3]; @@ -180,277 +174,280 @@ CFiniteElementStd:: CFiniteElementStd(CRFProcess* Pcs, const int C_Sys_Flad, con idxS = idx3 = -1; if (pcs->primary_variable_name.compare("HEAD") == 0) HEAD_Flag = true; - //SB4218 added + // SB4218 added string pcs_primary = pcs->pcs_primary_function_name[0]; if (pcs_primary.compare("HEAD") == 0) HEAD_Flag = true; for (i = 0; i < 9; i++) mat[i] = 0.0; - idx0 = idx1 = 0; // column index in the node value data + idx0 = idx1 = 0; // column index in the node value data LocalShift = 0; switch (pcs->getProcessType()) { - default: - // case DEFORMATION: - // case DEFORMATION_DYNAMIC: - PcsType = EPT_LIQUID_FLOW; - //WW GravityMatrix = new SymMatrix(size_m); - if (dynamic) - { - idx0 = pcs->GetNodeValueIndex("PRESSURE_RATE1"); - idx1 = idx0 + 1; - idx_pres = pcs->GetNodeValueIndex("PRESSURE1"); - idx_vel_disp[0] = pcs->GetNodeValueIndex("VELOCITY_DM_X"); - idx_vel_disp[1] = pcs->GetNodeValueIndex("VELOCITY_DM_Y"); - if (dim == 3) - idx_vel_disp[2] = pcs->GetNodeValueIndex("VELOCITY_DM_Z"); - } - else - { - idx0 = pcs->GetNodeValueIndex("PRESSURE1"); - idx1 = idx0 + 1; - } - break; + default: + // case DEFORMATION: + // case DEFORMATION_DYNAMIC: + PcsType = EPT_LIQUID_FLOW; + // WW GravityMatrix = new SymMatrix(size_m); + if (dynamic) + { + idx0 = pcs->GetNodeValueIndex("PRESSURE_RATE1"); + idx1 = idx0 + 1; + idx_pres = pcs->GetNodeValueIndex("PRESSURE1"); + idx_vel_disp[0] = pcs->GetNodeValueIndex("VELOCITY_DM_X"); + idx_vel_disp[1] = pcs->GetNodeValueIndex("VELOCITY_DM_Y"); + if (dim == 3) + idx_vel_disp[2] = pcs->GetNodeValueIndex("VELOCITY_DM_Z"); + } + else + { + idx0 = pcs->GetNodeValueIndex("PRESSURE1"); + idx1 = idx0 + 1; + } + break; - // case 'L': - case LIQUID_FLOW: - case DEFORMATION_FLOW: // Liquid flow - PcsType = EPT_LIQUID_FLOW; - // 02.2.2007 GravityMatrix = new SymMatrix(size_m); - if (dynamic) - { - idx0 = pcs->GetNodeValueIndex("PRESSURE_RATE1"); - idx1 = idx0 + 1; - idx_pres = pcs->GetNodeValueIndex("PRESSURE1"); - idx_vel_disp[0] = pcs->GetNodeValueIndex("VELOCITY_DM_X"); - idx_vel_disp[1] = pcs->GetNodeValueIndex("VELOCITY_DM_Y"); - if (dim == 3) - idx_vel_disp[2] = pcs->GetNodeValueIndex("VELOCITY_DM_Z"); - } - else - { - idx0 = pcs->GetNodeValueIndex("PRESSURE1"); - idx1 = idx0 + 1; - } - idx_vel[0] = pcs->GetNodeValueIndex("VELOCITY_X1"); - idx_vel[1] = pcs->GetNodeValueIndex("VELOCITY_Y1"); - idx_vel[2] = pcs->GetNodeValueIndex("VELOCITY_Z1"); - break; + // case 'L': + case LIQUID_FLOW: + case DEFORMATION_FLOW: // Liquid flow + PcsType = EPT_LIQUID_FLOW; + // 02.2.2007 GravityMatrix = new SymMatrix(size_m); + if (dynamic) + { + idx0 = pcs->GetNodeValueIndex("PRESSURE_RATE1"); + idx1 = idx0 + 1; + idx_pres = pcs->GetNodeValueIndex("PRESSURE1"); + idx_vel_disp[0] = pcs->GetNodeValueIndex("VELOCITY_DM_X"); + idx_vel_disp[1] = pcs->GetNodeValueIndex("VELOCITY_DM_Y"); + if (dim == 3) + idx_vel_disp[2] = pcs->GetNodeValueIndex("VELOCITY_DM_Z"); + } + else + { + idx0 = pcs->GetNodeValueIndex("PRESSURE1"); + idx1 = idx0 + 1; + } + idx_vel[0] = pcs->GetNodeValueIndex("VELOCITY_X1"); + idx_vel[1] = pcs->GetNodeValueIndex("VELOCITY_Y1"); + idx_vel[2] = pcs->GetNodeValueIndex("VELOCITY_Z1"); + break; - /* TODO no enum item for this case - case 'U': // Unconfined flow - PcsType = EPT_UNCONFINED_FLOW; - break; - */ + /* TODO no enum item for this case + case 'U': // Unconfined flow + PcsType = EPT_UNCONFINED_FLOW; + break; + */ // case 'G': // Groundwater flow - case GROUNDWATER_FLOW: - PcsType = EPT_GROUNDWATER_FLOW; - idx0 = pcs->GetNodeValueIndex("HEAD"); - idx1 = idx0 + 1; - //WW - idx_vel[0] = pcs->GetNodeValueIndex("VELOCITY_X1"); - //WW - idx_vel[1] = pcs->GetNodeValueIndex("VELOCITY_Y1"); - //WW - idx_vel[2] = pcs->GetNodeValueIndex("VELOCITY_Z1"); - break; + case GROUNDWATER_FLOW: + PcsType = EPT_GROUNDWATER_FLOW; + idx0 = pcs->GetNodeValueIndex("HEAD"); + idx1 = idx0 + 1; + // WW + idx_vel[0] = pcs->GetNodeValueIndex("VELOCITY_X1"); + // WW + idx_vel[1] = pcs->GetNodeValueIndex("VELOCITY_Y1"); + // WW + idx_vel[2] = pcs->GetNodeValueIndex("VELOCITY_Z1"); + break; - // case 'T': - case TWO_PHASE_FLOW: - if (pcs->getProcessType() == FiniteElement::TNEQ) - PcsType = EPT_THERMAL_NONEQUILIBRIUM; - else if (pcs->getProcessType() == FiniteElement::TES) - PcsType = EPT_TES; - else // Two-phase flow - PcsType = EPT_TWOPHASE_FLOW; - break; + // case 'T': + case TWO_PHASE_FLOW: + if (pcs->getProcessType() == FiniteElement::TNEQ) + PcsType = EPT_THERMAL_NONEQUILIBRIUM; + else if (pcs->getProcessType() == FiniteElement::TES) + PcsType = EPT_TES; + else // Two-phase flow + PcsType = EPT_TWOPHASE_FLOW; + break; - /* TODO no enum item for this case - case 'C': // Componental flow - PcsType = EPT_COMPONENTAL_FLOW; - break; - */ + /* TODO no enum item for this case + case 'C': // Componental flow + PcsType = EPT_COMPONENTAL_FLOW; + break; + */ - // case 'H': // heat transport - case HEAT_TRANSPORT: - PcsType = EPT_HEAT_TRANSPORT; - idx0 = pcs->GetNodeValueIndex("TEMPERATURE1"); - idx1 = idx0 + 1; - break; + // case 'H': // heat transport + case HEAT_TRANSPORT: + PcsType = EPT_HEAT_TRANSPORT; + idx0 = pcs->GetNodeValueIndex("TEMPERATURE1"); + idx1 = idx0 + 1; + break; - // case 'M': // Mass transport - case MASS_TRANSPORT: - PcsType = EPT_MASS_TRANSPORT; - sprintf(name1, "%s", pcs->pcs_primary_function_name[0]); - name2 = name1; - idx0 = pcs->GetNodeValueIndex(name2); - idx1 = idx0 + 1; - break; + // case 'M': // Mass transport + case MASS_TRANSPORT: + PcsType = EPT_MASS_TRANSPORT; + sprintf(name1, "%s", pcs->pcs_primary_function_name[0]); + name2 = name1; + idx0 = pcs->GetNodeValueIndex(name2); + idx1 = idx0 + 1; + break; // case 'O': // Liquid flow - case OVERLAND_FLOW: - PcsType = EPT_OVERLAND_FLOW; - edlluse = new double [16]; //WW - edttuse = new double [16]; - break; + case OVERLAND_FLOW: + PcsType = EPT_OVERLAND_FLOW; + edlluse = new double[16]; // WW + edttuse = new double[16]; + break; // case 'R': //OK4104 Richards flow - case RANDOM_WALK: - case RICHARDS_FLOW: - // 02.2.2007 GravityMatrix = new SymMatrix(size_m); - idx0 = pcs->GetNodeValueIndex("PRESSURE1"); - idx1 = idx0 + 1; - idxS = pcs->GetNodeValueIndex("SATURATION1") + 1; - idx_vel[0] = pcs->GetNodeValueIndex("VELOCITY_X1"); - idx_vel[1] = pcs->GetNodeValueIndex("VELOCITY_Y1"); - idx_vel[2] = pcs->GetNodeValueIndex("VELOCITY_Z1"); - if ((int) pcs->dof > 1) //Dual porosity model. WW - { - idxp20 = pcs->GetNodeValueIndex("PRESSURE2"); - idxp21 = idxp20 + 1; - //WW - Advection = new Matrix(size_m, size_m); - //12.12.2007 WW - for (i = 0; i < pcs->pcs_number_of_primary_nvals; i++) - NodeShift[i] = i * pcs->m_msh->GetNodesNumber(false); - } - PcsType = EPT_RICHARDS_FLOW; - break; + case RANDOM_WALK: + case RICHARDS_FLOW: + // 02.2.2007 GravityMatrix = new SymMatrix(size_m); + idx0 = pcs->GetNodeValueIndex("PRESSURE1"); + idx1 = idx0 + 1; + idxS = pcs->GetNodeValueIndex("SATURATION1") + 1; + idx_vel[0] = pcs->GetNodeValueIndex("VELOCITY_X1"); + idx_vel[1] = pcs->GetNodeValueIndex("VELOCITY_Y1"); + idx_vel[2] = pcs->GetNodeValueIndex("VELOCITY_Z1"); + if ((int)pcs->dof > 1) // Dual porosity model. WW + { + idxp20 = pcs->GetNodeValueIndex("PRESSURE2"); + idxp21 = idxp20 + 1; + // WW + Advection = new Matrix(size_m, size_m); + // 12.12.2007 WW + for (i = 0; i < pcs->pcs_number_of_primary_nvals; i++) + NodeShift[i] = i * pcs->m_msh->GetNodesNumber(false); + } + PcsType = EPT_RICHARDS_FLOW; + break; - // case 'A': // Air (gas) flow - case AIR_FLOW: - PcsType = EPT_GAS_FLOW; - //OK - idx0 = pcs->GetNodeValueIndex("PRESSURE1"); - idx1 = idx0 + 1; //OK - break; + // case 'A': // Air (gas) flow + case AIR_FLOW: + PcsType = EPT_GAS_FLOW; + // OK + idx0 = pcs->GetNodeValueIndex("PRESSURE1"); + idx1 = idx0 + 1; // OK + break; - // case 'F': // Fluid Momentum Process - case FLUID_FLOW: - case FLUID_MOMENTUM: - case FLUX: - PcsType = EPT_RICHARDS_FLOW; // R should include L if the eqn of R is written right. - break; + // case 'F': // Fluid Momentum Process + case FLUID_FLOW: + case FLUID_MOMENTUM: + case FLUX: + PcsType = EPT_RICHARDS_FLOW; // R should include L if the eqn of R is written right. + break; - // case 'V': // 24.02.2007 WW - case DEFORMATION_H2: - case MULTI_PHASE_FLOW: - // // 02.2.2007 GravityMatrix = new SymMatrix(size_m); - //12.12.2007 WW - for (i = 0; i < pcs->pcs_number_of_primary_nvals; i++) - NodeShift[i] = i * pcs->m_msh->GetNodesNumber(false); - // - idx0 = pcs->GetNodeValueIndex("PRESSURE1"); - idx1 = idx0 + 1; - idxp20 = pcs->GetNodeValueIndex("PRESSURE2"); - idxp21 = idxp20 + 1; - idxS = pcs->GetNodeValueIndex("SATURATION1") + 1; - idx_vel[0] = pcs->GetNodeValueIndex("VELOCITY_X1"); - idx_vel[1] = pcs->GetNodeValueIndex("VELOCITY_Y1"); - idx_vel[2] = pcs->GetNodeValueIndex("VELOCITY_Z1"); - PcsType = EPT_MULTIPHASE_FLOW; - size_m = 40; - break; + // case 'V': // 24.02.2007 WW + case DEFORMATION_H2: + case MULTI_PHASE_FLOW: + // // 02.2.2007 GravityMatrix = new SymMatrix(size_m); + // 12.12.2007 WW + for (i = 0; i < pcs->pcs_number_of_primary_nvals; i++) + NodeShift[i] = i * pcs->m_msh->GetNodesNumber(false); + // + idx0 = pcs->GetNodeValueIndex("PRESSURE1"); + idx1 = idx0 + 1; + idxp20 = pcs->GetNodeValueIndex("PRESSURE2"); + idxp21 = idxp20 + 1; + idxS = pcs->GetNodeValueIndex("SATURATION1") + 1; + idx_vel[0] = pcs->GetNodeValueIndex("VELOCITY_X1"); + idx_vel[1] = pcs->GetNodeValueIndex("VELOCITY_Y1"); + idx_vel[2] = pcs->GetNodeValueIndex("VELOCITY_Z1"); + PcsType = EPT_MULTIPHASE_FLOW; + size_m = 40; + break; - // case 'P': // 04.03.2009 PCH - case PS_GLOBAL: - for (i = 0; i < pcs->pcs_number_of_primary_nvals; i++) - NodeShift[i] = i * pcs->m_msh->GetNodesNumber(false); - // - idx0 = pcs->GetNodeValueIndex("PRESSURE1"); - idx1 = idx0 + 1; - idxSn0 = pcs->GetNodeValueIndex("SATURATION2"); - idxSn1 = idxSn0 + 1; - idxS = pcs->GetNodeValueIndex("SATURATION1") + 1; - idx_vel[0] = pcs->GetNodeValueIndex("VELOCITY_X1"); - idx_vel[1] = pcs->GetNodeValueIndex("VELOCITY_Y1"); - idx_vel[2] = pcs->GetNodeValueIndex("VELOCITY_Z1"); - PcsType = EPT_PSGLOBAL; - size_m = 40; - break; + // case 'P': // 04.03.2009 PCH + case PS_GLOBAL: + for (i = 0; i < pcs->pcs_number_of_primary_nvals; i++) + NodeShift[i] = i * pcs->m_msh->GetNodesNumber(false); + // + idx0 = pcs->GetNodeValueIndex("PRESSURE1"); + idx1 = idx0 + 1; + idxSn0 = pcs->GetNodeValueIndex("SATURATION2"); + idxSn1 = idxSn0 + 1; + idxS = pcs->GetNodeValueIndex("SATURATION1") + 1; + idx_vel[0] = pcs->GetNodeValueIndex("VELOCITY_X1"); + idx_vel[1] = pcs->GetNodeValueIndex("VELOCITY_Y1"); + idx_vel[2] = pcs->GetNodeValueIndex("VELOCITY_Z1"); + PcsType = EPT_PSGLOBAL; + size_m = 40; + break; - // case 'S':// MULTI_COMPONENTIAL_FLOW - case MULTI_COMPONENTIAL_FLOW: - for (int in = 0; in < pcs->pcs_number_of_primary_nvals; in++) - { - NodeShift[in] = in * pcs->m_msh->GetNodesNumber(false); - idxMCF[in] = pcs->GetNodeValueIndex(pcs->pcs_primary_function_name[in]); - idxMCF[in + pcs->pcs_number_of_primary_nvals] = idxMCF[in] + 1; - } - idx_vel[0] = pcs->GetNodeValueIndex("VELOCITY_X1"); - idx_vel[1] = pcs->GetNodeValueIndex("VELOCITY_Y1"); - idx_vel[2] = pcs->GetNodeValueIndex("VELOCITY_Z1"); - PcsType = EPT_MULTI_COMPONENTIAL_FLOW; - size_m = 40; - break; + // case 'S':// MULTI_COMPONENTIAL_FLOW + case MULTI_COMPONENTIAL_FLOW: + for (int in = 0; in < pcs->pcs_number_of_primary_nvals; in++) + { + NodeShift[in] = in * pcs->m_msh->GetNodesNumber(false); + idxMCF[in] = pcs->GetNodeValueIndex(pcs->pcs_primary_function_name[in]); + idxMCF[in + pcs->pcs_number_of_primary_nvals] = idxMCF[in] + 1; + } + idx_vel[0] = pcs->GetNodeValueIndex("VELOCITY_X1"); + idx_vel[1] = pcs->GetNodeValueIndex("VELOCITY_Y1"); + idx_vel[2] = pcs->GetNodeValueIndex("VELOCITY_Z1"); + PcsType = EPT_MULTI_COMPONENTIAL_FLOW; + size_m = 40; + break; - // case 'N': // TNEQ - case TNEQ: - for (i = 0; i < pcs->pcs_number_of_primary_nvals; i++) - NodeShift[i] = i * pcs->m_msh->GetNodesNumber(false); - idx0 = pcs->GetNodeValueIndex("PRESSURE1"); - idx1 = idx0 + 1; - idxt0 = pcs->GetNodeValueIndex("TEMPERATURE1"); - idxt1 = idxt0 + 1; - idx_t2_0 = pcs->GetNodeValueIndex("TEMPERATURE2"); - idx_t2_1 = idx_t2_0 + 1; - idx_x0 = pcs->GetNodeValueIndex("CONCENTRATION1"); - idx_x1 = idx_x0 + 1; - idx_vel[0] = pcs->GetNodeValueIndex("VELOCITY_X1"); - idx_vel[1] = pcs->GetNodeValueIndex("VELOCITY_Y1"); - idx_vel[2] = pcs->GetNodeValueIndex("VELOCITY_Z1"); - PcsType = EPT_THERMAL_NONEQUILIBRIUM; - size_m = 64; - break; + // case 'N': // TNEQ + case TNEQ: + for (i = 0; i < pcs->pcs_number_of_primary_nvals; i++) + NodeShift[i] = i * pcs->m_msh->GetNodesNumber(false); + idx0 = pcs->GetNodeValueIndex("PRESSURE1"); + idx1 = idx0 + 1; + idxt0 = pcs->GetNodeValueIndex("TEMPERATURE1"); + idxt1 = idxt0 + 1; + idx_t2_0 = pcs->GetNodeValueIndex("TEMPERATURE2"); + idx_t2_1 = idx_t2_0 + 1; + idx_x0 = pcs->GetNodeValueIndex("CONCENTRATION1"); + idx_x1 = idx_x0 + 1; + idx_vel[0] = pcs->GetNodeValueIndex("VELOCITY_X1"); + idx_vel[1] = pcs->GetNodeValueIndex("VELOCITY_Y1"); + idx_vel[2] = pcs->GetNodeValueIndex("VELOCITY_Z1"); + PcsType = EPT_THERMAL_NONEQUILIBRIUM; + size_m = 64; + break; - case TES: - for (i = 0; i < pcs->pcs_number_of_primary_nvals; i++) - NodeShift[i] = i * pcs->m_msh->GetNodesNumber(false); - idx0 = pcs->GetNodeValueIndex("PRESSURE1"); - idx1 = idx0 + 1; - idxt0 = pcs->GetNodeValueIndex("TEMPERATURE1"); - idxt1 = idxt0 + 1; - idx_x0 = pcs->GetNodeValueIndex("CONCENTRATION1"); - idx_x1 = idx_x0 + 1; - idx_vel[0] = pcs->GetNodeValueIndex("VELOCITY_X1"); - idx_vel[1] = pcs->GetNodeValueIndex("VELOCITY_Y1"); - idx_vel[2] = pcs->GetNodeValueIndex("VELOCITY_Z1"); - PcsType = EPT_TES; - size_m = 64; - break; + case TES: + for (i = 0; i < pcs->pcs_number_of_primary_nvals; i++) + NodeShift[i] = i * pcs->m_msh->GetNodesNumber(false); + idx0 = pcs->GetNodeValueIndex("PRESSURE1"); + idx1 = idx0 + 1; + idxt0 = pcs->GetNodeValueIndex("TEMPERATURE1"); + idxt1 = idxt0 + 1; + idx_x0 = pcs->GetNodeValueIndex("CONCENTRATION1"); + idx_x1 = idx_x0 + 1; + idx_vel[0] = pcs->GetNodeValueIndex("VELOCITY_X1"); + idx_vel[1] = pcs->GetNodeValueIndex("VELOCITY_Y1"); + idx_vel[2] = pcs->GetNodeValueIndex("VELOCITY_Z1"); + PcsType = EPT_TES; + size_m = 64; + break; } - if (pcs->Memory_Type == 0) // Do not store local matrices + if (pcs->Memory_Type == 0) // Do not store local matrices { // 04.03.2009 PCH - switch(PcsType) - { - case EPT_MULTIPHASE_FLOW: case EPT_PSGLOBAL: case EPT_MULTI_COMPONENTIAL_FLOW: - case EPT_THERMAL_NONEQUILIBRIUM: case EPT_TES: - Mass2 = new Matrix(size_m, size_m); - break; - default: - Mass = new Matrix(size_m, size_m); + switch (PcsType) + { + case EPT_MULTIPHASE_FLOW: + case EPT_PSGLOBAL: + case EPT_MULTI_COMPONENTIAL_FLOW: + case EPT_THERMAL_NONEQUILIBRIUM: + case EPT_TES: + Mass2 = new Matrix(size_m, size_m); + break; + default: + Mass = new Matrix(size_m, size_m); } Laplace = new Matrix(size_m, size_m); switch (pcs->getProcessType()) { - case HEAT_TRANSPORT: - case MASS_TRANSPORT: - case AIR_FLOW: - case MULTI_COMPONENTIAL_FLOW: - case TNEQ: - case TES: - Advection = new Matrix(size_m, size_m); - Storage = new Matrix(size_m, size_m); - Content = new Matrix(size_m, size_m); - break; - default: - break; + case HEAT_TRANSPORT: + case MASS_TRANSPORT: + case AIR_FLOW: + case MULTI_COMPONENTIAL_FLOW: + case TNEQ: + case TES: + Advection = new Matrix(size_m, size_m); + Storage = new Matrix(size_m, size_m); + Content = new Matrix(size_m, size_m); + break; + default: + break; } if (D_Flag) @@ -463,7 +460,7 @@ CFiniteElementStd:: CFiniteElementStd(CRFProcess* Pcs, const int C_Sys_Flad, con AuxMatrix1 = new Matrix(size_m, size_m); if (this->pcs->m_num->fct_method > 0) - { //NW + { // NW FCT_MassL = new DiagonalMatrix(size_m); } @@ -473,26 +470,27 @@ CFiniteElementStd:: CFiniteElementStd(CRFProcess* Pcs, const int C_Sys_Flad, con // SolidProp1 = NULL; MediaProp1 = NULL; - flag_cpl_pcs = false; //OK + flag_cpl_pcs = false; // OK // size_m changed NodalVal = new double[size_m]; NodalVal0 = new double[size_m]; - if (GasMassForm) { + if (GasMassForm) + { static bool done = false; - if (!done) { + if (!done) + { done = true; std::cout << "-> Gass flow is formulated as mass balance." << '\n'; } } #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - idxm = new int[size_m]; //> global indices of local matrix rows - idxn = new int[size_m]; //> global indices of local matrix columns + idxm = new int[size_m]; //> global indices of local matrix rows + idxn = new int[size_m]; //> global indices of local matrix columns local_idx = new int[size_m]; //> local index for local assemble - //local_matrix = new double[size_m * size_m]; //> local matrix - //local_vec = new double[size_m]; //> local vector +// local_matrix = new double[size_m * size_m]; //> local matrix +// local_vec = new double[size_m]; //> local vector #endif - } /************************************************************************** @@ -506,25 +504,25 @@ CFiniteElementStd::~CFiniteElementStd() // 02.2.2007 if(GravityMatrix) delete GravityMatrix; // 02.2.2007 GravityMatrix = NULL; - if(pcs->Memory_Type == 0) // Do not store local matrices + if (pcs->Memory_Type == 0) // Do not store local matrices { - if(Mass) + if (Mass) delete Mass; - if(Mass2) + if (Mass2) delete Mass2; - if(Laplace) + if (Laplace) delete Laplace; - if(Advection) + if (Advection) delete Advection; - if(Storage) + if (Storage) delete Storage; - if(Content) + if (Content) delete Content; - if(StrainCoupling) + if (StrainCoupling) delete StrainCoupling; - if(RHS) + if (RHS) delete RHS; - if(FCT_MassL) + if (FCT_MassL) delete FCT_MassL; Mass = NULL; @@ -540,41 +538,41 @@ CFiniteElementStd::~CFiniteElementStd() delete StiffMatrix; delete AuxMatrix; delete AuxMatrix1; - if(edlluse) - delete [] edlluse; - if(edttuse) - delete [] edttuse; + if (edlluse) + delete[] edlluse; + if (edttuse) + delete[] edttuse; StiffMatrix = NULL; AuxMatrix = NULL; AuxMatrix1 = NULL; // 27.2.2007 WW - delete [] NodalVal; - delete [] NodalVal0; - delete [] NodalVal1; - delete [] NodalVal2; - delete [] NodalVal3; - delete [] NodalVal4; - delete [] NodalVal5; - delete [] NodalValC; - delete [] NodalValC1; - delete [] NodalVal_Sat; - delete [] NodalVal_SatNW; - delete [] NodalVal_p2; - delete [] mat; - delete [] NodalVal_p20; //AKS - delete [] NodalVal_t0; //AKS/NB - delete [] NodalVal_t1; //AKS/NB - delete [] NodalVal_t2_0; - delete [] NodalVal_t2_1; - delete [] NodalVal_X0; - delete [] NodalVal_X1; - if(idx_vel_disp) - delete [] idx_vel_disp; - delete [] idx_vel; //AKS - //NW - if(weight_func) - delete [] weight_func; // Remove bug. WW + delete[] NodalVal; + delete[] NodalVal0; + delete[] NodalVal1; + delete[] NodalVal2; + delete[] NodalVal3; + delete[] NodalVal4; + delete[] NodalVal5; + delete[] NodalValC; + delete[] NodalValC1; + delete[] NodalVal_Sat; + delete[] NodalVal_SatNW; + delete[] NodalVal_p2; + delete[] mat; + delete[] NodalVal_p20; // AKS + delete[] NodalVal_t0; // AKS/NB + delete[] NodalVal_t1; // AKS/NB + delete[] NodalVal_t2_0; + delete[] NodalVal_t2_1; + delete[] NodalVal_X0; + delete[] NodalVal_X1; + if (idx_vel_disp) + delete[] idx_vel_disp; + delete[] idx_vel; // AKS + // NW + if (weight_func) + delete[] weight_func; // Remove bug. WW weight_func = NULL; } /************************************************************************** @@ -589,36 +587,39 @@ CFiniteElementStd::~CFiniteElementStd() void CFiniteElementStd::SetMemory() { int Size = nnodes; - if(PcsType == EPT_MULTIPHASE_FLOW || PcsType == EPT_PSGLOBAL) //4.3.2009 PCH + if (PcsType == EPT_MULTIPHASE_FLOW || PcsType == EPT_PSGLOBAL) // 4.3.2009 PCH Size *= 2; - if(PcsType == EPT_MULTI_COMPONENTIAL_FLOW || PcsType == EPT_THERMAL_NONEQUILIBRIUM || PcsType == EPT_TES) - Size *= pcs->dof;//AKS + if (PcsType == EPT_MULTI_COMPONENTIAL_FLOW || PcsType == EPT_THERMAL_NONEQUILIBRIUM || PcsType == EPT_TES) + Size *= pcs->dof; // AKS ElementMatrix* EleMat = NULL; // Prepare local matrices // If local matrices are not stored, resize the matrix - if(pcs->Memory_Type == 0) + if (pcs->Memory_Type == 0) { if (PcsType == EPT_MULTIPHASE_FLOW || PcsType == EPT_PSGLOBAL || PcsType == EPT_MULTI_COMPONENTIAL_FLOW - || PcsType == EPT_THERMAL_NONEQUILIBRIUM || PcsType == EPT_TES) //04.3.2009 PCH + || PcsType == EPT_THERMAL_NONEQUILIBRIUM + || PcsType == EPT_TES) // 04.3.2009 PCH Mass2->LimitSize(Size, Size); else - Mass->LimitSize(nnodes, nnodes); // Mass->LimitSize(nnodes); // unsymmetric in case of Upwinding + Mass->LimitSize(nnodes, nnodes); // Mass->LimitSize(nnodes); // unsymmetric in case of Upwinding Laplace->LimitSize(Size, Size); if (PcsType == EPT_HEAT_TRANSPORT || PcsType == EPT_MASS_TRANSPORT || PcsType == EPT_GAS_FLOW - || PcsType == EPT_MULTI_COMPONENTIAL_FLOW || PcsType == EPT_THERMAL_NONEQUILIBRIUM || PcsType == EPT_TES) + || PcsType == EPT_MULTI_COMPONENTIAL_FLOW + || PcsType == EPT_THERMAL_NONEQUILIBRIUM + || PcsType == EPT_TES) { - Advection->LimitSize(Size, Size); //SB4200 - Storage->LimitSize(Size, Size); //SB4200 - Content->LimitSize(Size, Size); //SB4209 + Advection->LimitSize(Size, Size); // SB4200 + Storage->LimitSize(Size, Size); // SB4200 + Content->LimitSize(Size, Size); // SB4209 } - if(PcsType == EPT_RICHARDS_FLOW && pcs->type == 22) //dual-porosity. WW + if (PcsType == EPT_RICHARDS_FLOW && pcs->type == 22) // dual-porosity. WW Advection->LimitSize(Size, Size); - if(D_Flag > 0) + if (D_Flag > 0) StrainCoupling->LimitSize(Size, dim * nnodesHQ); RHS->LimitSize(Size); } @@ -631,25 +632,26 @@ void CFiniteElementStd::SetMemory() Laplace = EleMat->GetLaplace(); // Advection, Storage, Content SB4200 if (PcsType == EPT_MASS_TRANSPORT || PcsType == EPT_HEAT_TRANSPORT || PcsType == EPT_MULTI_COMPONENTIAL_FLOW - || PcsType == EPT_THERMAL_NONEQUILIBRIUM || PcsType == EPT_TES) + || PcsType == EPT_THERMAL_NONEQUILIBRIUM + || PcsType == EPT_TES) { Advection = EleMat->GetAdvection(); Storage = EleMat->GetStorage(); Content = EleMat->GetContent(); } RHS = EleMat->GetRHS(); - if(D_Flag > 0) + if (D_Flag > 0) StrainCoupling = EleMat->GetCouplingMatrixB(); - if(D_Flag == 41) + if (D_Flag == 41) LocalShift = dim * nnodesHQ; } - //25.2.2007.WW if(GravityMatrix) GravityMatrix->LimitSize(nnodes); + // 25.2.2007.WW if(GravityMatrix) GravityMatrix->LimitSize(nnodes); StiffMatrix->LimitSize(Size, Size); AuxMatrix->LimitSize(Size, Size); AuxMatrix1->LimitSize(Size, Size); - if (this->pcs->m_num->fct_method > 0) //NW + if (this->pcs->m_num->fct_method > 0) // NW FCT_MassL->LimitSize(Size); } @@ -673,7 +675,7 @@ void CFiniteElementStd::ConfigureCoupling(CRFProcess* pcs, const int* Shift, boo // if(pcs_vector[i]->pcs_type_name.find("DEFORMATION")!=string::npos){ if (isDeformationProcess(pcs_vector[i]->getProcessType())) { - dm_pcs = (CRFProcessDeformation*) pcs_vector[i]; + dm_pcs = (CRFProcessDeformation*)pcs_vector[i]; break; } if (dyn) @@ -697,167 +699,166 @@ void CFiniteElementStd::ConfigureCoupling(CRFProcess* pcs, const int* Shift, boo Idx_dm0[2] = dm_pcs->GetNodeValueIndex("DISPLACEMENT_Z1"); Idx_dm1[2] = Idx_dm0[2] + 1; } - if(dm_pcs->type / 10 == 4) - for(size_t i = 0; i < pcs->GetPrimaryVNumber(); i++) + if (dm_pcs->type / 10 == 4) + for (size_t i = 0; i < pcs->GetPrimaryVNumber(); i++) NodeShift[i] = Shift[i]; } - - switch(pcs->getProcessType()) + switch (pcs->getProcessType()) { - default: - if(T_Flag) - { - cpl_pcs = PCSGet("HEAT_TRANSPORT"); - idx_c0 = cpl_pcs->GetNodeValueIndex("TEMPERATURE1"); - idx_c1 = idx_c0 + 1; - } - break; + default: + if (T_Flag) + { + cpl_pcs = PCSGet("HEAT_TRANSPORT"); + idx_c0 = cpl_pcs->GetNodeValueIndex("TEMPERATURE1"); + idx_c1 = idx_c0 + 1; + } + break; - case LIQUID_FLOW: - if(T_Flag) - { - cpl_pcs = PCSGet("HEAT_TRANSPORT"); - idx_c0 = cpl_pcs->GetNodeValueIndex("TEMPERATURE1"); - idx_c1 = idx_c0 + 1; - } - break; + case LIQUID_FLOW: + if (T_Flag) + { + cpl_pcs = PCSGet("HEAT_TRANSPORT"); + idx_c0 = cpl_pcs->GetNodeValueIndex("TEMPERATURE1"); + idx_c1 = idx_c0 + 1; + } + break; - // No enum item for this case - // case 'U': // Unconfined flow - // break; + // No enum item for this case + // case 'U': // Unconfined flow + // break; - case GROUNDWATER_FLOW: - if(T_Flag) - { - cpl_pcs = PCSGet("HEAT_TRANSPORT"); - idx_c0 = cpl_pcs->GetNodeValueIndex("TEMPERATURE1"); - idx_c1 = idx_c0 + 1; - } - break; + case GROUNDWATER_FLOW: + if (T_Flag) + { + cpl_pcs = PCSGet("HEAT_TRANSPORT"); + idx_c0 = cpl_pcs->GetNodeValueIndex("TEMPERATURE1"); + idx_c1 = idx_c0 + 1; + } + break; - case TWO_PHASE_FLOW: - if(pcs->pcs_type_number == 0) - { - cpl_pcs = pcs_vector[pcs->pcs_number + 1]; - idx_c0 = cpl_pcs->GetNodeValueIndex("SATURATION2"); - idx_c1 = idx_c0 + 1; - } - else if(pcs->pcs_type_number == 1) - { - cpl_pcs = pcs_vector[pcs->pcs_number - 1]; - idx_c0 = cpl_pcs->GetNodeValueIndex("PRESSURE1"); - idx_c1 = idx_c0 + 1; - } - break; + case TWO_PHASE_FLOW: + if (pcs->pcs_type_number == 0) + { + cpl_pcs = pcs_vector[pcs->pcs_number + 1]; + idx_c0 = cpl_pcs->GetNodeValueIndex("SATURATION2"); + idx_c1 = idx_c0 + 1; + } + else if (pcs->pcs_type_number == 1) + { + cpl_pcs = pcs_vector[pcs->pcs_number - 1]; + idx_c0 = cpl_pcs->GetNodeValueIndex("PRESSURE1"); + idx_c1 = idx_c0 + 1; + } + break; // No enum item for this case // case 'C': // Componental flow // break; - case HEAT_TRANSPORT: - //SB CMCD this needs to be fixed - cpl_pcs = PCSGet("GROUNDWATER_FLOW"); - if(cpl_pcs) //WW - { - idx_c0 = cpl_pcs->GetNodeValueIndex("HEAD"); - idx_c1 = idx_c0 + 1; - } - else - { - cpl_pcs = PCSGet("LIQUID_FLOW"); - if(cpl_pcs == NULL) - { - //OK - cpl_pcs = PCSGet("RICHARDS_FLOW"); - if(cpl_pcs) - //WW - idxS = cpl_pcs->GetNodeValueIndex("SATURATION1") + 1; - } - if(cpl_pcs == NULL) + case HEAT_TRANSPORT: + // SB CMCD this needs to be fixed + cpl_pcs = PCSGet("GROUNDWATER_FLOW"); + if (cpl_pcs) // WW { - //24.042.2004 WW - cpl_pcs = PCSGet("MULTI_PHASE_FLOW"); - if(cpl_pcs) - //WW - idxS = cpl_pcs->GetNodeValueIndex("SATURATION1") + 1; + idx_c0 = cpl_pcs->GetNodeValueIndex("HEAD"); + idx_c1 = idx_c0 + 1; } - if(cpl_pcs == NULL) //CB_merge_05.13 + else { - cpl_pcs = PCSGet("PS_GLOBAL"); - if(cpl_pcs) - idxS = cpl_pcs->GetNodeValueIndex("SATURATION1")+1; + cpl_pcs = PCSGet("LIQUID_FLOW"); + if (cpl_pcs == NULL) + { + // OK + cpl_pcs = PCSGet("RICHARDS_FLOW"); + if (cpl_pcs) + // WW + idxS = cpl_pcs->GetNodeValueIndex("SATURATION1") + 1; + } + if (cpl_pcs == NULL) + { + // 24.042.2004 WW + cpl_pcs = PCSGet("MULTI_PHASE_FLOW"); + if (cpl_pcs) + // WW + idxS = cpl_pcs->GetNodeValueIndex("SATURATION1") + 1; + } + if (cpl_pcs == NULL) // CB_merge_05.13 + { + cpl_pcs = PCSGet("PS_GLOBAL"); + if (cpl_pcs) + idxS = cpl_pcs->GetNodeValueIndex("SATURATION1") + 1; + } + + if (cpl_pcs == NULL) // 23.02.2009 NB 4.9.05 + { + cpl_pcs = PCSGet("TWO_PHASE_FLOW"); + if (cpl_pcs) + idxS = cpl_pcs->GetNodeValueIndex("SATURATION1") + 1; + } + if (cpl_pcs == NULL) // 23.02.2009 NB 4.9.05 + + cpl_pcs = PCSGet("AIR_FLOW"); // 23.01.2009 NB + + if (cpl_pcs) // MX + { + idx_c0 = cpl_pcs->GetNodeValueIndex("PRESSURE1"); + idx_c1 = idx_c0 + 1; + } } + break; - if(cpl_pcs == NULL) //23.02.2009 NB 4.9.05 + case MASS_TRANSPORT: + if (T_Flag) { - cpl_pcs = PCSGet("TWO_PHASE_FLOW"); - if(cpl_pcs) - idxS = cpl_pcs->GetNodeValueIndex("SATURATION1") + 1; + cpl_pcs = PCSGet("HEAT_TRANSPORT"); + idx_c0 = cpl_pcs->GetNodeValueIndex("TEMPERATURE1"); + idx_c1 = idx_c0 + 1; } - if(cpl_pcs == NULL) //23.02.2009 NB 4.9.05 + break; - cpl_pcs = PCSGet("AIR_FLOW"); //23.01.2009 NB + // case 'O': // Liquid flow + case OVERLAND_FLOW: + break; - if (cpl_pcs) //MX + case RICHARDS_FLOW: + // case 'R': // Richards flow + if (T_Flag) // if(PCSGet("HEAT_TRANSPORT")) { - idx_c0 = cpl_pcs->GetNodeValueIndex("PRESSURE1"); + cpl_pcs = PCSGet("HEAT_TRANSPORT"); + idx_c0 = cpl_pcs->GetNodeValueIndex("TEMPERATURE1"); idx_c1 = idx_c0 + 1; } - } - break; - - case MASS_TRANSPORT: - if(T_Flag) - { - cpl_pcs = PCSGet("HEAT_TRANSPORT"); - idx_c0 = cpl_pcs->GetNodeValueIndex("TEMPERATURE1"); - idx_c1 = idx_c0 + 1; - } - break; + break; - // case 'O': // Liquid flow - case OVERLAND_FLOW: - break; + case MULTI_PHASE_FLOW: + if (T_Flag) // if(PCSGet("HEAT_TRANSPORT")) + { + cpl_pcs = PCSGet("HEAT_TRANSPORT"); + idx_c0 = cpl_pcs->GetNodeValueIndex("TEMPERATURE1"); + idx_c1 = idx_c0 + 1; + } + break; - case RICHARDS_FLOW: - // case 'R': // Richards flow - if(T_Flag) //if(PCSGet("HEAT_TRANSPORT")) - { - cpl_pcs = PCSGet("HEAT_TRANSPORT"); - idx_c0 = cpl_pcs->GetNodeValueIndex("TEMPERATURE1"); - idx_c1 = idx_c0 + 1; - } - break; + case AIR_FLOW: + if (T_Flag) // NB 23.01.2009 4.9.05 + { + cpl_pcs = PCSGet("HEAT_TRANSPORT"); + idx_c0 = cpl_pcs->GetNodeValueIndex("TEMPERATURE1"); + idx_c1 = idx_c0 + 1; + } + break; - case MULTI_PHASE_FLOW: - if(T_Flag) //if(PCSGet("HEAT_TRANSPORT")) - { - cpl_pcs = PCSGet("HEAT_TRANSPORT"); - idx_c0 = cpl_pcs->GetNodeValueIndex("TEMPERATURE1"); - idx_c1 = idx_c0 + 1; - } - break; - - case AIR_FLOW: - if(T_Flag) //NB 23.01.2009 4.9.05 - { - cpl_pcs = PCSGet("HEAT_TRANSPORT"); - idx_c0 = cpl_pcs->GetNodeValueIndex("TEMPERATURE1"); - idx_c1 = idx_c0 + 1; - } - break; - - case PS_GLOBAL: - if(T_Flag) - { - cpl_pcs = PCSGet("HEAT_TRANSPORT"); - idx_c0 = cpl_pcs->GetNodeValueIndex("TEMPERATURE1"); - idx_c1 = idx_c0 + 1; - } - break; - } -} + case PS_GLOBAL: + if (T_Flag) + { + cpl_pcs = PCSGet("HEAT_TRANSPORT"); + idx_c0 = cpl_pcs->GetNodeValueIndex("TEMPERATURE1"); + idx_c1 = idx_c0 + 1; + } + break; + } +} /************************************************************************* FEMLib-Function: @@ -876,32 +877,32 @@ void CFiniteElementStd::SetMaterial(int /*phase*/) long group = MeshElement->GetPatchIndex(); mmp_index = group; // Single continua thermal: - if(msp_vector.size() > 0) + if (msp_vector.size() > 0) { - // TODO: For multidomain meshes accessing msp_vector can result in SEGV. - // Either use checked \c at() access or ensure - // mmp_index < msp_vector.size(). + // TODO: For multidomain meshes accessing msp_vector can result in SEGV. + // Either use checked \c at() access or ensure + // mmp_index < msp_vector.size(). SolidProp = msp_vector[mmp_index]; - //KR not used: SolidProp->m_pcs = pcs; //NW - SolidProp->Fem_Ele_Std = this; //CMCD for Decovalex + // KR not used: SolidProp->m_pcs = pcs; //NW + SolidProp->Fem_Ele_Std = this; // CMCD for Decovalex } - if(pcs->type == 22) //WW/YD + if (pcs->type == 22) // WW/YD { - if(pcs->GetContinnumType() == 0) // Matrix //WW + if (pcs->GetContinnumType() == 0) // Matrix //WW mmp_index = 2 * group; - else // fracture //WW + else // fracture //WW mmp_index = 2 * group + 1; } - // TODO: For multidomain meshes accessing mmp_vector can result in SEGV, - // like above msp_vector[]. + // TODO: For multidomain meshes accessing mmp_vector can result in SEGV, + // like above msp_vector[]. MediaProp = mmp_vector[mmp_index]; MediaProp->m_pcs = pcs; MediaProp->Fem_Ele_Std = this; MeshElement->area = MediaProp->geo_area; // NW - if(MediaProp->storage_model ==7 ) // 29.11.2011. WW - SolidProp->Calculate_Lame_Constant(); + if (MediaProp->storage_model == 7) // 29.11.2011. WW + SolidProp->Calculate_Lame_Constant(); //---------------------------------------------------------------------- // MSP @@ -913,11 +914,11 @@ void CFiniteElementStd::SetMaterial(int /*phase*/) SolidProp->Fem_Ele_Std = this;//CMCD for Decovalex } */ - if(pcs->type == 22) //WW + if (pcs->type == 22) // WW { - if(pcs->GetContinnumType() == 0) // Matrix //WW + if (pcs->GetContinnumType() == 0) // Matrix //WW mmp_index = 2 * group + 1; - else // fracture //WW + else // fracture //WW mmp_index = 2 * group; MediaProp1 = mmp_vector[mmp_index]; MediaProp1->m_pcs = pcs; @@ -942,19 +943,19 @@ void CFiniteElementStd::SetMaterial(int /*phase*/) cout << "Warning: LIQUID was not found in fluid properties." << "\n"; } */ - if(mfp_vector.size() > 0) + if (mfp_vector.size() > 0) { FluidProp = mfp_vector[0]; FluidProp->Fem_Ele_Std = this; } // 03.2009 PCH // or JFNK. 10.08.2010. WW - if(pcs->type == 1212 || pcs->type == 1313 || pcs->type == 42 - || (pcs->getProcessType()==FiniteElement::HEAT_TRANSPORT && (PCSGet("PS_GLOBAL") || PCSGet("RICHARDS_FLOW")))) + if (pcs->type == 1212 || pcs->type == 1313 || pcs->type == 42 + || (pcs->getProcessType() == FiniteElement::HEAT_TRANSPORT && (PCSGet("PS_GLOBAL") || PCSGet("RICHARDS_FLOW")))) { FluidProp = MFPGet("LIQUID"); FluidProp->Fem_Ele_Std = this; - //FluidProp = mfp_vector[0]; + // FluidProp = mfp_vector[0]; GasProp = MFPGet("GAS"); if (GasProp) GasProp->Fem_Ele_Std = this; @@ -1037,12 +1038,9 @@ void CFiniteElementStd::GetOverlandBasisFunctionMatrix_Quad() 06/2005 MB Implementation 04/2007 JOD modifications **************************************************************************/ -void CFiniteElementStd::CalcOverlandNLTERMS(double* haa, - double* haaOld, - double* swval, - double* swold) +void CFiniteElementStd::CalcOverlandNLTERMS(double* haa, double* haaOld, double* swval, double* swold) { - if(MediaProp->channel == 1) + if (MediaProp->channel == 1) CalcOverlandNLTERMSChannel(haa, haaOld, swval, swold); else CalcOverlandNLTERMSRills(haa, haaOld, swval, swold); @@ -1054,43 +1052,31 @@ void CFiniteElementStd::CalcOverlandNLTERMS(double* haa, Programing: 06/2007 JOD implementation **************************************************************************/ -void CFiniteElementStd::CalcOverlandNLTERMSRills(double* haa, - double* haaOld, - double* swval, - double* swold) +void CFiniteElementStd::CalcOverlandNLTERMSRills(double* haa, double* haaOld, double* swval, double* swold) { double WDepth[4], WDepthOld[4]; double rill_height = MediaProp->rill_height; double eps = MediaProp->rill_epsilon; - for(int i = 0; i < nnodes; i++) + for (int i = 0; i < nnodes; i++) { WDepth[i] = haa[i] - Z[i]; WDepthOld[i] = haaOld[i] - Z[i]; if (MediaProp->rill_epsilon > 0) { - if(WDepth[i] > 0) - swval[i] = - (WDepth[i] + - eps) * - (WDepth[i] + eps) / ( WDepth[i] + rill_height + eps) - pow( - eps, - 2.) / (rill_height + eps); + if (WDepth[i] > 0) + swval[i] = (WDepth[i] + eps) * (WDepth[i] + eps) / (WDepth[i] + rill_height + eps) + - pow(eps, 2.) / (rill_height + eps); else swval[i] = 0; - if(WDepthOld[i] > 0) + if (WDepthOld[i] > 0) // JOD - swold[i] = - (WDepthOld[i] + - eps) * - (WDepthOld[i] + - eps) / - ( WDepthOld[i] + rill_height + - eps) - pow(eps, 2.) / (rill_height + eps); + swold[i] = (WDepthOld[i] + eps) * (WDepthOld[i] + eps) / (WDepthOld[i] + rill_height + eps) + - pow(eps, 2.) / (rill_height + eps); else swold[i] = 0; - } // end epsilon > 0 + } // end epsilon > 0 else { swval[i] = WDepth[i]; @@ -1106,17 +1092,14 @@ void CFiniteElementStd::CalcOverlandNLTERMSRills(double* haa, Programing: 06/2007 JOD Implementation **************************************************************************/ -void CFiniteElementStd::CalcOverlandNLTERMSChannel(double* haa, - double* haaOld, - double* swval, - double* swold) +void CFiniteElementStd::CalcOverlandNLTERMSChannel(double* haa, double* haaOld, double* swval, double* swold) { double WDepth[4], WDepthOld[4]; double eps = MediaProp->rill_epsilon; double ratio; double xxx; - for(int i = 0; i < 2; i++) + for (int i = 0; i < 2; i++) { WDepth[i] = haa[i] - Z[i]; WDepthOld[i] = haaOld[i] - Z[i]; @@ -1128,7 +1111,7 @@ void CFiniteElementStd::CalcOverlandNLTERMSChannel(double* haa, else if (ratio > 0.0) { xxx = 2.0 * (1.0 - ratio); - swval[i] = WDepth[i] * pow(ratio,xxx); + swval[i] = WDepth[i] * pow(ratio, xxx); } else swval[i] = 0.0; @@ -1140,17 +1123,17 @@ void CFiniteElementStd::CalcOverlandNLTERMSChannel(double* haa, else if (ratio > 0.0) { xxx = 2.0 * (1.0 - ratio); - swold[i] = WDepthOld[i] * pow(ratio,xxx); + swold[i] = WDepthOld[i] * pow(ratio, xxx); } else swold[i] = 0.0; - } // end epsilon > 0 + } // end epsilon > 0 else { swval[i] = WDepth[i]; swold[i] = WDepthOld[i]; } - } //end for + } // end for } /************************************************************************** @@ -1172,8 +1155,8 @@ void CFiniteElementStd::CalcOverlandCKWR(double* head, double* ckwr, int* iups) for (i = 0; i < nnodes; i++) for (j = 0; j < nnodes; j++) { - maxZ = MMax(Z[i],Z[j]); - if( head[i] > head[j] ) + maxZ = MMax(Z[i], Z[j]); + if (head[i] > head[j]) { iups[i * nnodes + j] = i; flow_depth = head[i] - maxZ - rill_depth; @@ -1184,19 +1167,17 @@ void CFiniteElementStd::CalcOverlandCKWR(double* head, double* ckwr, int* iups) flow_depth = head[j] - maxZ - rill_depth; } //////////////////////////////////////// - if(flow_depth < 0.0) + if (flow_depth < 0.0) ckwr[i * nnodes + j] = 0.0; else { - if(MediaProp->channel == 1) - ckwr[i * nnodes + j] = flow_depth * pow( - flow_depth * width / (2 * flow_depth + width), - depth_exp); + if (MediaProp->channel == 1) + ckwr[i * nnodes + j] = flow_depth * pow(flow_depth * width / (2 * flow_depth + width), depth_exp); else - ckwr[i * nnodes + j] = pow(flow_depth,depth_exp + 1); + ckwr[i * nnodes + j] = pow(flow_depth, depth_exp + 1); } - } //end for j - //end for i + } // end for j + // end for i } /************************************************************************** @@ -1216,19 +1197,18 @@ void CFiniteElementStd::CalcOverlandCKWRatNodes(int i, int j, double* head, doub double flow_depth; double maxZ; - maxZ = MMax(Z[i],Z[j]); - if(iups[i * nnodes + j] == i) + maxZ = MMax(Z[i], Z[j]); + if (iups[i * nnodes + j] == i) flow_depth = head[i] - maxZ - rill_depth; else flow_depth = head[j] - maxZ - rill_depth; /////////////////////////////////////// - if(flow_depth < 0.0) + if (flow_depth < 0.0) *ckwr = 0; else { - if(MediaProp->channel == 1) - *ckwr = flow_depth * pow(flow_depth * width / ( 2 * flow_depth + width), - depth_exp); + if (MediaProp->channel == 1) + *ckwr = flow_depth * pow(flow_depth * width / (2 * flow_depth + width), depth_exp); else *ckwr = pow(flow_depth, depth_exp + 1); } @@ -1241,36 +1221,30 @@ void CFiniteElementStd::CalcOverlandCKWRatNodes(int i, int j, double* head, doub Programing: 06/2007 JOD Implementation **************************************************************************/ -void CFiniteElementStd::CalcOverlandUpwindedCoefficients(double** amat, - double* ckwr, - double axx, - double ayy) +void CFiniteElementStd::CalcOverlandUpwindedCoefficients(double** amat, double* ckwr, double axx, double ayy) { - //double** amat; + // double** amat; double gammaij; - //amat = (double**) Malloc(nnodes * sizeof(double)); - //for (int i = 0; i < nnodes; i++) + // amat = (double**) Malloc(nnodes * sizeof(double)); + // for (int i = 0; i < nnodes; i++) // amat[i] = (double*) Malloc(nnodes*sizeof(double)); - //for (int i = 0; i < nnodes; i++) + // for (int i = 0; i < nnodes; i++) // for (int j = 0; j < nnodes; j++) // amat[i][j]= 0.0; for (int i = 0; i < nnodes; i++) for (int j = (i + 1); j < nnodes; j++) { - gammaij = - ckwr[i * nnodes + - j] * - ((edlluse[i * nnodes + j] * axx) + (edttuse[i * nnodes + j] * ayy)); + gammaij = ckwr[i * nnodes + j] * ((edlluse[i * nnodes + j] * axx) + (edttuse[i * nnodes + j] * ayy)); amat[i][j] = gammaij; amat[j][i] = gammaij; amat[i][i] = amat[i][i] - gammaij; amat[j][j] = amat[j][j] - gammaij; } - //return amat; + // return amat; } /************************************************************************** FEMLib-Method: @@ -1279,20 +1253,16 @@ void CFiniteElementStd::CalcOverlandUpwindedCoefficients(double** amat, Programing: 06/2007 JOD Implementation **************************************************************************/ -void CFiniteElementStd::CalcOverlandResidual(double* head, - double* swval, - double* swold, - double ast, - double* residual, +void CFiniteElementStd::CalcOverlandResidual(double* head, double* swval, double* swold, double ast, double* residual, double** amat) { double sum; double storinit[4], astor[4], rhs[4]; - MNulleVec(astor,4); - MNulleVec(rhs,nnodes); + MNulleVec(astor, 4); + MNulleVec(rhs, nnodes); - for (int i = 0; i < nnodes; i++) // storage term + for (int i = 0; i < nnodes; i++) // storage term rhs[i] = -ast * (swval[i] - swold[i]); /* if(MediaProp->channel ==1){ // channel, JOD removed, don't know what it was for @@ -1302,13 +1272,13 @@ void CFiniteElementStd::CalcOverlandResidual(double* head, rhs[1] = swold[1] * ast * HaaOld[1]; // swval ????? } */ - //Form the residual excluding the right hand side vector + // Form the residual excluding the right hand side vector - for(int i = 0; i < nnodes; i++) + for (int i = 0; i < nnodes; i++) { sum = 0.0; - for(int j = 0; j < nnodes; j++) - sum = sum + ( amat[i][j] * head[j] ); + for (int j = 0; j < nnodes; j++) + sum = sum + (amat[i][j] * head[j]); // astor = 0, rillDepth?? storinit[i] = -rhs[i] + astor[i] * (head[i] - Z[i]); residual[i] = sum + storinit[i]; @@ -1321,19 +1291,12 @@ void CFiniteElementStd::CalcOverlandResidual(double* head, Programing: 06/2007 JOD Implementation **************************************************************************/ -double CFiniteElementStd::CalcOverlandJacobiNodes(int i, - int j, - double* head, - double* headKeep, - double akrw, - double axx, - double ayy, - double** amat, - double* sumjac ) +double CFiniteElementStd::CalcOverlandJacobiNodes(int i, int j, double* head, double* headKeep, double akrw, double axx, + double ayy, double** amat, double* sumjac) { double jacobi, gammaij, amatEps, amatKeep; - gammaij = akrw * ( axx * edlluse[i * nnodes + j] + ayy * edttuse[i * nnodes + j] ); + gammaij = akrw * (axx * edlluse[i * nnodes + j] + ayy * edttuse[i * nnodes + j]); amatEps = gammaij * (head[j] - head[i]); amatKeep = amat[i][j] * (headKeep[j] - headKeep[i]); jacobi = -(amatEps - amatKeep); @@ -1349,20 +1312,17 @@ double CFiniteElementStd::CalcOverlandJacobiNodes(int i, Programing: 08/2006 JOD Implementation **************************************************************************/ -void CFiniteElementStd::CalcOverlandCoefficients(double* head, - double* axx, - double* ayy, - double* ast ) +void CFiniteElementStd::CalcOverlandCoefficients(double* head, double* axx, double* ayy, double* ast) { - if(MeshElement->geo_type == 1) + if (MeshElement->geo_type == 1) { - CalcOverlandCoefficientsLine(head, axx, ast ); + CalcOverlandCoefficientsLine(head, axx, ast); ayy = 0; } - else if(MeshElement->geo_type == 2) - CalcOverlandCoefficientsQuad(head, axx, ayy, ast ); - else if(MeshElement->geo_type == 4) - CalcOverlandCoefficientsTri(head, axx, ayy, ast ); + else if (MeshElement->geo_type == 2) + CalcOverlandCoefficientsQuad(head, axx, ayy, ast); + else if (MeshElement->geo_type == 4) + CalcOverlandCoefficientsTri(head, axx, ayy, ast); else std::cout << "Error in CFiniteElementStd::CalcOverlandCoefficients !!!"; } @@ -1372,30 +1332,30 @@ void CFiniteElementStd::CalcOverlandCoefficients(double* head, Programing: 08/2006 JOD Implementation **************************************************************************/ -void CFiniteElementStd::CalcOverlandCoefficientsLine(double* head, double* axx, double* ast ) +void CFiniteElementStd::CalcOverlandCoefficientsLine(double* head, double* axx, double* ast) { - double dx, dy; //WW, dzx; + double dx, dy; // WW, dzx; double delt, dhds; double fric, width, eslope, slope_exp; - fric = MediaProp->friction_coefficient; + fric = MediaProp->friction_coefficient; slope_exp = MediaProp->friction_exp_slope; width = MediaProp->overland_width; dx = X[1] - X[0]; dy = Y[1] - Y[0]; - //WW dzx = Z[1] - Z[0]; + // WW dzx = Z[1] - Z[0]; delt = sqrt(dx * dx + dy * dy); - dhds = fabs( (head[0] - head[1]) / delt ); + dhds = fabs((head[0] - head[1]) / delt); GetOverlandBasisFunctionMatrix_Line(); - dhds = MMax(1.0e-10,dhds); + dhds = MMax(1.0e-10, dhds); eslope = 1.0 / dhds; eslope = pow(eslope, 1 - slope_exp); *axx = eslope * fric * width / delt; - *ast = delt * width / (double) (nnodes * dt); + *ast = delt * width / (double)(nnodes * dt); } /************************************************************************** FEMLib-Method: @@ -1403,22 +1363,19 @@ void CFiniteElementStd::CalcOverlandCoefficientsLine(double* head, double* axx, Programing: 08/2006 JOD Implementation **************************************************************************/ -void CFiniteElementStd::CalcOverlandCoefficientsQuad(double* head, - double* axx, - double* ayy, - double* ast ) +void CFiniteElementStd::CalcOverlandCoefficientsQuad(double* head, double* axx, double* ayy, double* ast) { double dx, dy, dzx, dzy; double delt; double dhds, GradH[2]; double fric, eslope, slope_exp; - fric = MediaProp->friction_coefficient; + fric = MediaProp->friction_coefficient; slope_exp = MediaProp->friction_exp_slope; ///////////////////////////// - dx = X[1] - X[0]; //ell - dy = Y[3] - Y[0]; //ett + dx = X[1] - X[0]; // ell + dy = Y[3] - Y[0]; // ett dzx = Z[1] - Z[0]; dzy = Z[3] - Z[0]; dx = sqrt(dx * dx + dzx * dzx); @@ -1431,13 +1388,13 @@ void CFiniteElementStd::CalcOverlandCoefficientsQuad(double* head, GradH[1] = (head[0] + head[1] - head[2] - head[3]) / (2.0 * dy); // dh/ds (dh in the direction of maximum slope) dhds = sqrt((GradH[0] * GradH[0]) + (GradH[1] * GradH[1])); - dhds = MMax(1.0e-10,dhds); + dhds = MMax(1.0e-10, dhds); eslope = 1.0 / dhds; eslope = pow(eslope, 1 - slope_exp); - *axx = eslope * fric * dy / dx; //ett/ell + *axx = eslope * fric * dy / dx; // ett/ell *ayy = eslope * fric * dx / dy; - *ast = delt / (double) (nnodes * dt ); + *ast = delt / (double)(nnodes * dt); } /************************************************************************** FEMLib-Method: @@ -1445,17 +1402,14 @@ void CFiniteElementStd::CalcOverlandCoefficientsQuad(double* head, Programing: 08/2006 JOD Implementation **************************************************************************/ -void CFiniteElementStd::CalcOverlandCoefficientsTri(double* head, - double* axx, - double* ayy, - double* ast ) +void CFiniteElementStd::CalcOverlandCoefficientsTri(double* head, double* axx, double* ayy, double* ast) { double x2, x3, y2, y3; double delt, delt2, delt2inv, b[3], g[3]; double dhds, GradH[2]; double fric, eslope, slope_exp; - fric = MediaProp->friction_coefficient; + fric = MediaProp->friction_coefficient; slope_exp = MediaProp->friction_exp_slope; x2 = X[1] - X[0]; @@ -1474,25 +1428,25 @@ void CFiniteElementStd::CalcOverlandCoefficientsTri(double* head, g[1] = -x3 * delt2inv; g[2] = x2 * delt2inv; - for(int i = 0; i < nnodes; i++) - for(int j = 0; j < nnodes; j++) + for (int i = 0; i < nnodes; i++) + for (int j = 0; j < nnodes; j++) { edlluse[i * nnodes + j] = b[i] * b[j]; edttuse[i * nnodes + j] = g[i] * g[j]; } ////////////////////////// - GradH[0] = ( b[0] * head[0] + b[1] * head[1] + b[2] * head[2] ); - GradH[1] = ( g[0] * head[0] + g[1] * head[1] + g[2] * head[2] ); + GradH[0] = (b[0] * head[0] + b[1] * head[1] + b[2] * head[2]); + GradH[1] = (g[0] * head[0] + g[1] * head[1] + g[2] * head[2]); // dh/ds (dh in the direction of maximum slope) dhds = sqrt((GradH[0] * GradH[0]) + (GradH[1] * GradH[1])); - dhds = MMax(1.0e-10,dhds); + dhds = MMax(1.0e-10, dhds); eslope = 1.0 / dhds; eslope = pow(eslope, 1 - slope_exp); *axx = eslope * fric * delt; *ayy = eslope * fric * delt; - *ast = delt / (double) (nnodes * dt ); + *ast = delt / (double)(nnodes * dt); } /************************************************************************** @@ -1504,27 +1458,24 @@ void CFiniteElementStd::CalNodalEnthalpy() { int i; double temp, dT; - for(i = 0; i < nnodes; i++) + for (i = 0; i < nnodes; i++) { - heat_phase_change = - SolidProp->CheckTemperature_in_PhaseChange(NodalVal0[i], NodalVal1[i]); - if(heat_phase_change) + heat_phase_change = SolidProp->CheckTemperature_in_PhaseChange(NodalVal0[i], NodalVal1[i]); + if (heat_phase_change) break; } - if(!heat_phase_change) + if (!heat_phase_change) return; // Calculate node enthalpy - for(i = 0; i < nnodes; i++) + for (i = 0; i < nnodes; i++) { NodalVal_Sat[i] = pcs->GetNodeValue(nodes[i], idxS); SetCenterGP(); - temp = FluidProp->Density() - * MediaProp->Porosity(Index,pcs->m_num->ls_theta) - * NodalVal_Sat[i]; + temp = FluidProp->Density() * MediaProp->Porosity(Index, pcs->m_num->ls_theta) * NodalVal_Sat[i]; // Enthalpy dT = 0.0; NodalVal2[i] = SolidProp->Enthalpy(NodalVal0[i], temp); - if(fabs(NodalVal1[i] - NodalVal0[i]) < 1.0e-8) + if (fabs(NodalVal1[i] - NodalVal0[i]) < 1.0e-8) dT = 1.0e-8; NodalVal3[i] = SolidProp->Enthalpy(NodalVal1[i] + dT, temp); } @@ -1550,232 +1501,229 @@ double CFiniteElementStd::CalCoefMass() double rhov = 0.0; double arg[2]; double biot_val, poro_val = 0.0, rho_val = 0.0, Se; - int tr_phase = 0; // SB, BG - double saturation = 0.0; // SB, BG + int tr_phase = 0; // SB, BG + double saturation = 0.0; // SB, BG CompProperties* m_cp = NULL; - double drho_dp_rho=0.0; // drho/dp * 1/rho + double drho_dp_rho = 0.0; // drho/dp * 1/rho - if(pcs->m_num->ele_mass_lumping) + if (pcs->m_num->ele_mass_lumping) ComputeShapefct(1); - switch(PcsType) + switch (PcsType) { - default: - std::cout << "Fatal error in CalCoefMass: No valid PCS type" << "\n"; - break; - case EPT_LIQUID_FLOW: // Liquid flow - // Is this really needed? - val = MediaProp->StorageFunction(Index,unit,pcs->m_num->ls_theta); - - // get drho/dp/rho from material model or direct input - if(FluidProp->compressibility_model_pressure>0) - { - - rho_val = FluidProp->Density(); - arg[0]=interpolate(NodalVal1); // p - arg[1]=interpolate(NodalValC1); // T - drho_dp_rho=FluidProp->drhodP(arg)/rho_val; - } - else - drho_dp_rho=FluidProp->drho_dp; - - // JT 2010, needed storage term and fluid compressibility... - // We derive here the storage at constant strain, or the inverse of Biot's "M" coefficient - // Assumptions are the most general possible:: Invarience under "pi" (Detournay & Cheng) loading. - // Se = 1/M = poro/Kf + (alpha-poro)/Ks :: Cf = 1/Kf = 1/rho * drho/dp :: alpha = 1 - K/Ks - // Second term (of Se) below vanishes for incompressible grains - //WW if(D_Flag > 0 && rho_val > MKleinsteZahl) - if(dm_pcs && MediaProp->storage_model == 7) // Add MediaProp->storage_model. 29.09.2011. WW - { - biot_val = SolidProp->biot_const; - poro_val = MediaProp->Porosity(Index,pcs->m_num->ls_theta); - val = 0.;//WX:04.2013 - - //WW if(SolidProp->K == 0) //WX: if HM Partitioned, K still 0 here - if(fabs(SolidProp->K)Youngs_mode<10||SolidProp->Youngs_mode>13)//JM,WX: 2013 - SolidProp->K = SolidProp->E / 3 / (1 - 2 * SolidProp->PoissonRatio); - else - { - double E_av; // average Youngs modulus - double nu_av; // average Poisson ratio - double nu_ai; // Poisson ratio perpendicular to the plane of isotropie, due to strain in the plane of isotropie - double nu_ia; // Poisson ratio in the plane of isotropie, due to strain perpendicular to the plane of isotropie - double nu_i; // Poisson ratio in the plane of isotropy + default: + std::cout << "Fatal error in CalCoefMass: No valid PCS type" + << "\n"; + break; + case EPT_LIQUID_FLOW: // Liquid flow + // Is this really needed? + val = MediaProp->StorageFunction(Index, unit, pcs->m_num->ls_theta); - E_av = 2./3. * (*SolidProp->data_Youngs)(0) + 1./3. * (*SolidProp->data_Youngs)(1); + // get drho/dp/rho from material model or direct input + if (FluidProp->compressibility_model_pressure > 0) + { + rho_val = FluidProp->Density(); + arg[0] = interpolate(NodalVal1); // p + arg[1] = interpolate(NodalValC1); // T + drho_dp_rho = FluidProp->drhodP(arg) / rho_val; + } + else + drho_dp_rho = FluidProp->drho_dp; + + // JT 2010, needed storage term and fluid compressibility... + // We derive here the storage at constant strain, or the inverse of Biot's "M" coefficient + // Assumptions are the most general possible:: Invarience under "pi" (Detournay & Cheng) loading. + // Se = 1/M = poro/Kf + (alpha-poro)/Ks :: Cf = 1/Kf = 1/rho * drho/dp :: alpha = 1 - K/Ks + // Second term (of Se) below vanishes for incompressible grains + // WW if(D_Flag > 0 && rho_val > MKleinsteZahl) + if (dm_pcs && MediaProp->storage_model == 7) // Add MediaProp->storage_model. 29.09.2011. WW + { + biot_val = SolidProp->biot_const; + poro_val = MediaProp->Porosity(Index, pcs->m_num->ls_theta); + val = 0.; // WX:04.2013 - nu_ia=(*SolidProp->data_Youngs)(2); - nu_ai=nu_ia * (*SolidProp->data_Youngs)(1)/(*SolidProp->data_Youngs)(0); // nu_ai=nu_ia*Ea/Ei + // WW if(SolidProp->K == 0) //WX: if HM Partitioned, K still 0 here + if (fabs(SolidProp->K) < DBL_MIN) // WW 29.09.2011 + { + if (SolidProp->Youngs_mode < 10 || SolidProp->Youngs_mode > 13) // JM,WX: 2013 + SolidProp->K = SolidProp->E / 3 / (1 - 2 * SolidProp->PoissonRatio); + else + { + double E_av; // average Youngs modulus + double nu_av; // average Poisson ratio + double nu_ai; // Poisson ratio perpendicular to the plane of isotropie, due to strain in the + // plane of isotropie + double nu_ia; // Poisson ratio in the plane of isotropie, due to strain perpendicular to the + // plane of isotropie + double nu_i; // Poisson ratio in the plane of isotropy + + E_av = 2. / 3. * (*SolidProp->data_Youngs)(0) + 1. / 3. * (*SolidProp->data_Youngs)(1); + + nu_ia = (*SolidProp->data_Youngs)(2); + nu_ai + = nu_ia * (*SolidProp->data_Youngs)(1) / (*SolidProp->data_Youngs)(0); // nu_ai=nu_ia*Ea/Ei + + nu_i = SolidProp->Poisson_Ratio(); + // 12 13 21 23 31 32 + // ai ai ia ii ia ii + nu_av = 1. / 3. * (nu_ai + nu_ia + nu_i); + + SolidProp->K = E_av / 3 / (1 - 2 * nu_av); + } + } + val += poro_val * drho_dp_rho + (biot_val - poro_val) * (1.0 - biot_val) / SolidProp->K; - nu_i= SolidProp->Poisson_Ratio(); - // 12 13 21 23 31 32 - // ai ai ia ii ia ii - nu_av=1./3.*(nu_ai+nu_ia+nu_i); + // Will handle the dual porosity version later... + } + else + { + poro_val = MediaProp->Porosity(Index, pcs->m_num->ls_theta); + val += poro_val * drho_dp_rho; + } - SolidProp->K=E_av/3/(1-2*nu_av); - } + // AS,WX: 08.2012 storage function eff stress + if (MediaProp->storage_effstress_model > 0) + { + double storage_effstress = 1.; + CFiniteElementStd* h_fem; + h_fem = this; + storage_effstress = MediaProp->StorageFunctionEffStress(Index, nnodes, h_fem); + val *= storage_effstress; } - val += poro_val * drho_dp_rho \ - + (biot_val - poro_val) * (1.0 - biot_val) / SolidProp->K; - // Will handle the dual porosity version later... - } - else - { - poro_val = MediaProp->Porosity(Index,pcs->m_num->ls_theta); - val += poro_val * drho_dp_rho; - } + val /= time_unit_factor; + break; + case EPT_UNCONFINED_FLOW: // Unconfined flow + break; + case EPT_GROUNDWATER_FLOW: // MB now Groundwater flow + if (MediaProp->unconfined_flow_group > 0) // OK + val = MediaProp->Porosity(Index, pcs->m_num->ls_theta); + else + val = MediaProp->StorageFunction(Index, unit, pcs->m_num->ls_theta); + break; + case EPT_TWOPHASE_FLOW: // Two-phase flow + // val = (1/rho*n*d_rho/d_p*S + Se*S ) + if (pcs->pcs_type_number == 0) + { + // PCH cpl_pcs gives a funny process number. + // It is just the opposite of the phase. So, I get the value the other way around. + idxS = cpl_pcs->GetNodeValueIndex("SATURATION2"); + for (int i = 0; i < nnodes; i++) + NodalVal_Sat[i] = cpl_pcs->GetNodeValue(nodes[i], idxS + 1); + Sw = 1.0 - interpolate(NodalVal_Sat); + // Is this really needed? + val = MediaProp->StorageFunction(Index, unit, pcs->m_num->ls_theta) * MMax(0., Sw); - //AS,WX: 08.2012 storage function eff stress - if(MediaProp->storage_effstress_model>0) - { - double storage_effstress = 1.; - CFiniteElementStd *h_fem; - h_fem=this; - storage_effstress = MediaProp->StorageFunctionEffStress(Index, nnodes, h_fem); - val *= storage_effstress; - } + // JT 2010, generalized poroelastic storage. See single phase version in case "L". + // Se = 1/M = poro/Kf + (alpha-poro)/Ks + rho_val = FluidProp->Density(); + if (D_Flag > 0 && rho_val > MKleinsteZahl) + { + biot_val = SolidProp->biot_const; + poro_val = MediaProp->Porosity(Index, pcs->m_num->ls_theta); + Se = poro_val * FluidProp->drho_dp + (biot_val - poro_val) * (1.0 - biot_val) / SolidProp->K; + // The poroelastic portion + val += Se * MMax(0., Sw); + } - val /= time_unit_factor; - break; - case EPT_UNCONFINED_FLOW: // Unconfined flow - break; - case EPT_GROUNDWATER_FLOW: // MB now Groundwater flow - if(MediaProp->unconfined_flow_group > 0) //OK - val = MediaProp->Porosity(Index,pcs->m_num->ls_theta); - else - val = MediaProp->StorageFunction(Index,unit,pcs->m_num->ls_theta); - break; - case EPT_TWOPHASE_FLOW: // Two-phase flow - // val = (1/rho*n*d_rho/d_p*S + Se*S ) - if(pcs->pcs_type_number == 0) - { - // PCH cpl_pcs gives a funny process number. - // It is just the opposite of the phase. So, I get the value the other way around. - idxS = cpl_pcs->GetNodeValueIndex("SATURATION2"); - for(int i = 0; i < nnodes; i++) - NodalVal_Sat[i] = cpl_pcs->GetNodeValue(nodes[i],idxS + 1); - Sw = 1.0 - interpolate(NodalVal_Sat); - // Is this really needed? - val = MediaProp->StorageFunction(Index,unit,pcs->m_num->ls_theta) * MMax(0., - Sw); + // If Partial-Pressure-Based model + if (pcs->PartialPS == 1) + { + // Let's get dPcdSw and apply to the mat_fac + CMediumProperties* m_mmp = NULL; + m_mmp = mmp_vector[0]; + + // dSedPc always return positive numbers for default case + // However, the value should be negative analytically. + double dSwdPc = m_mmp->PressureSaturationDependency(Sw, true); + val += poro_val * dSwdPc; + } + } + if (pcs->pcs_type_number == 1) + val = MediaProp->Porosity(Index, pcs->m_num->ls_theta) * MediaProp->geo_area; + // PCH: geo_area is only used for 1 and 2 dimensions. + // This is originated from Old RockFlow that handles 1, 2, and 3 dimensional + // elements in seperate functions that show inconsistency in handling geo_area. + // For example, geo_area is never used for 3D even in Old RockFlow. + break; + case EPT_COMPONENTAL_FLOW: // Componental flow + // OK comp = m_pcs->pcs_type_number; + // OK coefficient = MPCCalcStorativityNumber(ele,phase,comp,gp); + break; + //.................................................................... + case EPT_HEAT_TRANSPORT: // Heat transport + TG = interpolate(NodalVal1); + val = MediaProp->HeatCapacity(Index, pcs->m_num->ls_theta, this); + val /= time_unit_factor; + break; + //.................................................................... + case EPT_MASS_TRANSPORT: // Mass transport //SB4200 + // Porosity + val = MediaProp->Porosity(Index, pcs->m_num->ls_theta); + // SB Transport in both phases + tr_phase = cp_vec[this->pcs->pcs_component_number]->transport_phase; + // Multi phase transport of components + saturation = PCSGetEleMeanNodeSecondary_2(Index, pcs->flow_pcs_type, "SATURATION1", 1); + if (tr_phase == 0) // Water phase + val *= saturation; + else if (tr_phase == 10) // non wetting phase + val *= (1.0 - saturation); + m_cp = cp_vec[pcs->pcs_component_number]; + // Retardation Factor + val *= m_cp->CalcElementRetardationFactorNew(Index, unit, pcs); + break; + case EPT_OVERLAND_FLOW: // Liquid flow + val = 1.0; + break; + case EPT_RICHARDS_FLOW: // Richards + Sw = 1.0; + dSdp = 0.; + PG = interpolate(NodalVal1); // 12.02.2007. Important! WW - // JT 2010, generalized poroelastic storage. See single phase version in case "L". - // Se = 1/M = poro/Kf + (alpha-poro)/Ks - rho_val = FluidProp->Density(); - if(D_Flag > 0 && rho_val > MKleinsteZahl) + if (PG < 0.0) // JM skip to call these two functions in saturated case { - biot_val = SolidProp->biot_const; - poro_val = MediaProp->Porosity(Index,pcs->m_num->ls_theta); - Se = poro_val * FluidProp->drho_dp \ - + (biot_val - poro_val) * (1.0 - biot_val) / SolidProp->K; - // The poroelastic portion - val += Se * MMax(0.,Sw); + Sw = MediaProp->SaturationCapillaryPressureFunction(-PG); + dSdp = -MediaProp->PressureSaturationDependency(Sw, true); // JT: dSdp now returns actual sign (i.e. <0) } - // If Partial-Pressure-Based model - if(pcs->PartialPS == 1) - { - // Let's get dPcdSw and apply to the mat_fac - CMediumProperties* m_mmp = NULL; - m_mmp = mmp_vector[0]; + poro = MediaProp->Porosity(Index, pcs->m_num->ls_theta); + rhow = FluidProp->Density(); - // dSedPc always return positive numbers for default case - // However, the value should be negative analytically. - double dSwdPc = m_mmp->PressureSaturationDependency(Sw,true); - val += poro_val * dSwdPc; + if (FluidProp->compressibility_model_pressure > 0) + { // drho_dp from rho-p-T relation + arg[0] = PG; + arg[1] = interpolate(NodalValC1); // T + drho_dp_rho = FluidProp->drhodP(arg) / rhow; } - } - if(pcs->pcs_type_number == 1) - val = MediaProp->Porosity(Index,pcs->m_num->ls_theta) * MediaProp->geo_area; - // PCH: geo_area is only used for 1 and 2 dimensions. - // This is originated from Old RockFlow that handles 1, 2, and 3 dimensional - // elements in seperate functions that show inconsistency in handling geo_area. - // For example, geo_area is never used for 3D even in Old RockFlow. - break; - case EPT_COMPONENTAL_FLOW: // Componental flow - //OK comp = m_pcs->pcs_type_number; - //OK coefficient = MPCCalcStorativityNumber(ele,phase,comp,gp); - break; - //.................................................................... - case EPT_HEAT_TRANSPORT: // Heat transport - TG = interpolate(NodalVal1); - val = MediaProp->HeatCapacity(Index,pcs->m_num->ls_theta,this); - val /= time_unit_factor; - break; - //.................................................................... - case EPT_MASS_TRANSPORT: // Mass transport //SB4200 - // Porosity - val = MediaProp->Porosity(Index,pcs->m_num->ls_theta); - // SB Transport in both phases - tr_phase = cp_vec[this->pcs->pcs_component_number]->transport_phase; - // Multi phase transport of components - saturation = PCSGetEleMeanNodeSecondary_2(Index, - pcs->flow_pcs_type, - "SATURATION1", - 1); - if(tr_phase == 0) // Water phase - val *= saturation; - else if (tr_phase == 10) // non wetting phase - val *= (1.0 - saturation); - m_cp = cp_vec[pcs->pcs_component_number]; - //Retardation Factor - val *= m_cp->CalcElementRetardationFactorNew(Index, unit, pcs); - break; - case EPT_OVERLAND_FLOW: // Liquid flow - val = 1.0; - break; - case EPT_RICHARDS_FLOW: // Richards - Sw = 1.0; - dSdp = 0.; - PG = interpolate(NodalVal1); //12.02.2007. Important! WW + else + drho_dp_rho = FluidProp->drho_dp; - if (PG<0.0) // JM skip to call these two functions in saturated case - { - Sw = MediaProp->SaturationCapillaryPressureFunction(-PG); - dSdp = -MediaProp->PressureSaturationDependency(Sw,true); // JT: dSdp now returns actual sign (i.e. <0) - } - - poro = MediaProp->Porosity(Index,pcs->m_num->ls_theta); - rhow = FluidProp->Density(); - - if(FluidProp->compressibility_model_pressure>0) - { //drho_dp from rho-p-T relation - arg[0]=PG; - arg[1]=interpolate(NodalValC1); // T - drho_dp_rho=FluidProp->drhodP(arg)/rhow; - } - else - drho_dp_rho=FluidProp->drho_dp; - - // Storativity - val = MediaProp->StorageFunction(Index,unit,pcs->m_num->ls_theta) * Sw; - - // Fluid compressibility - if(rhow > 0.0) - val += poro * Sw * drho_dp_rho; - // Capillarity - if(PG<0.0) // dSdp gives always a value>0, even if p>0! - val += poro * dSdp; - //WW - if(MediaProp->heat_diffusion_model == 1) - { - // PG = fabs(interpolate(NodalVal1)); - TG = interpolate(NodalValC) + PhysicalConstant::CelsiusZeroInKelvin; - humi = exp(PG / (SpecificGasConstant::WaterVapour * TG * rhow)); - rhov = humi * FluidProp->vaporDensity(TG); - // - val -= poro * rhov * dSdp / rhow; - val += (1.0 - Sw) * poro * rhov / (rhow * rhow * SpecificGasConstant::WaterVapour * TG); - } - break; - case EPT_FLUID_MOMENTUM: // Fluid Momentum - val = 1.0; - break; - case EPT_GAS_FLOW: // Air (gas) flow - val = MediaProp->Porosity(Index,pcs->m_num->ls_theta) / interpolate(NodalVal1); - break; + // Storativity + val = MediaProp->StorageFunction(Index, unit, pcs->m_num->ls_theta) * Sw; + + // Fluid compressibility + if (rhow > 0.0) + val += poro * Sw * drho_dp_rho; + // Capillarity + if (PG < 0.0) // dSdp gives always a value>0, even if p>0! + val += poro * dSdp; + // WW + if (MediaProp->heat_diffusion_model == 1) + { + // PG = fabs(interpolate(NodalVal1)); + TG = interpolate(NodalValC) + PhysicalConstant::CelsiusZeroInKelvin; + humi = exp(PG / (SpecificGasConstant::WaterVapour * TG * rhow)); + rhov = humi * FluidProp->vaporDensity(TG); + // + val -= poro * rhov * dSdp / rhow; + val += (1.0 - Sw) * poro * rhov / (rhow * rhow * SpecificGasConstant::WaterVapour * TG); + } + break; + case EPT_FLUID_MOMENTUM: // Fluid Momentum + val = 1.0; + break; + case EPT_GAS_FLOW: // Air (gas) flow + val = MediaProp->Porosity(Index, pcs->m_num->ls_theta) / interpolate(NodalVal1); + break; } return val; } @@ -1792,128 +1740,126 @@ double CFiniteElementStd::CalCoefMass2(int dof_index) int Index = MeshElement->GetIndex(); double val = 0.0; double expfactor = 0.0; - double dens_arg[3]; //08.05.2008 WW - double pert = sqrt(DBL_EPSILON); //15.08.2011. WW + double dens_arg[3]; // 08.05.2008 WW + double pert = sqrt(DBL_EPSILON); // 15.08.2011. WW - bool diffusion = false; //08.05.2008 WW + bool diffusion = false; // 08.05.2008 WW - if(MediaProp->heat_diffusion_model == 1 && cpl_pcs) + if (MediaProp->heat_diffusion_model == 1 && cpl_pcs) diffusion = true; dens_arg[1] = 293.15; // - if(pcs->m_num->ele_mass_lumping) + if (pcs->m_num->ele_mass_lumping) ComputeShapefct(1); - // CB_merge_0513 in case of het K, store local K in permeability_tensor - double *tensor = NULL; - tensor = MediaProp->PermeabilityTensor(Index); - MediaProp->local_permeability = tensor[0]; + // CB_merge_0513 in case of het K, store local K in permeability_tensor + double* tensor = NULL; + tensor = MediaProp->PermeabilityTensor(Index); + MediaProp->local_permeability = tensor[0]; const double Rv = SpecificGasConstant::WaterVapour; - switch(dof_index) + switch (dof_index) { - case 0: - PG = interpolate(NodalVal1); // Capillary pressure - dens_arg[0] = PG; // Should be P_w in some cases - if(diffusion) - { - TG = interpolate(NodalValC1) + PhysicalConstant::CelsiusZeroInKelvin; - dens_arg[1] = TG; - } - Sw = MediaProp->SaturationCapillaryPressureFunction(PG); - rhow = FluidProp->Density(dens_arg); - dSdp = MediaProp->PressureSaturationDependency(Sw,true); // JT: dSdp now returns actual sign (i.e. <0) - poro = MediaProp->Porosity(Index,pcs->m_num->ls_theta); - // Storativity 28.05.2008 - // val = MediaProp->StorageFunction(Index,unit,pcs->m_num->ls_theta) *Sw; - // Fluid compressibility - // val += poro *Sw* FluidProp->drho_dp / rhow; - if(SolidProp) - { - if(SolidProp->Ks > MKleinsteZahl)// Storativity WX:28.05.2008 - val -= Sw * (SolidProp->biot_const-poro) / SolidProp->Ks * Sw; - } - // Fluid compressibility - if(fabs(FluidProp->drho_dp)>MKleinsteZahl) - val -= poro * Sw * FluidProp->drho_dp; - val += poro * dSdp;//WX:04.2013 val = poro * dSdp; - - // Coupled (T) - if(diffusion) - { - // Water vapour pressure - expfactor = 1.0 / (rhow * Rv * TG); - rho_gw = FluidProp->vaporDensity(TG) * exp(-PG * expfactor); - // - val -= poro * dSdp * rho_gw / rhow; - // - val -= (1.0 - Sw) * poro * rho_gw / (rhow * Rv * TG * rhow); - } - break; - case 1: //01 - val = 0.0; - //WX:05.2012 Storgae - PG = interpolate(NodalVal1); - Sw = MediaProp->SaturationCapillaryPressureFunction(PG); - poro = MediaProp->Porosity(Index,pcs->m_num->ls_theta); - if(SolidProp) - { - if(SolidProp->Ks > MKleinsteZahl) - //WX:11.2012 - val += Sw*(SolidProp->biot_const-poro) / SolidProp->Ks; - } - //WX:05.2012 Compressibility - if(fabs(FluidProp->drho_dp)>MKleinsteZahl) - val += poro*Sw*FluidProp->drho_dp; + case 0: + PG = interpolate(NodalVal1); // Capillary pressure + dens_arg[0] = PG; // Should be P_w in some cases + if (diffusion) + { + TG = interpolate(NodalValC1) + PhysicalConstant::CelsiusZeroInKelvin; + dens_arg[1] = TG; + } + Sw = MediaProp->SaturationCapillaryPressureFunction(PG); + rhow = FluidProp->Density(dens_arg); + dSdp = MediaProp->PressureSaturationDependency(Sw, true); // JT: dSdp now returns actual sign (i.e. <0) + poro = MediaProp->Porosity(Index, pcs->m_num->ls_theta); + // Storativity 28.05.2008 + // val = MediaProp->StorageFunction(Index,unit,pcs->m_num->ls_theta) *Sw; + // Fluid compressibility + // val += poro *Sw* FluidProp->drho_dp / rhow; + if (SolidProp) + { + if (SolidProp->Ks > MKleinsteZahl) // Storativity WX:28.05.2008 + val -= Sw * (SolidProp->biot_const - poro) / SolidProp->Ks * Sw; + } + // Fluid compressibility + if (fabs(FluidProp->drho_dp) > MKleinsteZahl) + val -= poro * Sw * FluidProp->drho_dp; + val += poro * dSdp; // WX:04.2013 val = poro * dSdp; - break; - case 2: // - // (1-S)n(d rhop_c/d p_c) - PG2 = interpolate(NodalVal_p2); - dens_arg[0] = PG2; //28.05.2008. WW - val = 0.; //28.05.2008. WW - if(diffusion) //28.05.2008. WW - { - val = (1.0 - Sw) * rho_gw / (rhow * Rv * TG * rhow); - p_gw = rho_gw * Rv * TG; - dens_arg[0] -= p_gw; - dens_arg[1] = TG; - } - rho_ga = GasProp->Density(dens_arg); //28.05.2008. WW - val -= rho_ga * dSdp / rhow; - val *= poro; - //WX:11.2012.storage - if(SolidProp) - { - if(SolidProp->Ks > MKleinsteZahl) - val -= rho_ga / rhow * ( (1-Sw) * (SolidProp->biot_const-poro)\ - / SolidProp->Ks * Sw); - } + // Coupled (T) + if (diffusion) + { + // Water vapour pressure + expfactor = 1.0 / (rhow * Rv * TG); + rho_gw = FluidProp->vaporDensity(TG) * exp(-PG * expfactor); + // + val -= poro * dSdp * rho_gw / rhow; + // + val -= (1.0 - Sw) * poro * rho_gw / (rhow * Rv * TG * rhow); + } + break; + case 1: // 01 + val = 0.0; + // WX:05.2012 Storgae + PG = interpolate(NodalVal1); + Sw = MediaProp->SaturationCapillaryPressureFunction(PG); + poro = MediaProp->Porosity(Index, pcs->m_num->ls_theta); + if (SolidProp) + { + if (SolidProp->Ks > MKleinsteZahl) + // WX:11.2012 + val += Sw * (SolidProp->biot_const - poro) / SolidProp->Ks; + } + // WX:05.2012 Compressibility + if (fabs(FluidProp->drho_dp) > MKleinsteZahl) + val += poro * Sw * FluidProp->drho_dp; - break; - case 3: // - // Approximation of d dens_g/dp_g 16.08.2011. WW - dens_arg[0] = PG2 + pert; - if(diffusion) - dens_arg[1] = TG; - /// d dens_g/dp_g: - if (GasProp->density_model==2)//dens_g/dp_g = drho_dp 02.2012. WX - val = (1.0 - Sw) * poro * GasProp->rho_0 * GasProp->drho_dp / rhow; - else - val = (1.0 - Sw) * poro * (GasProp->Density(dens_arg) - rho_ga) / (pert * rhow); - //Storage WX:11.2012 - if(SolidProp) - { - if(SolidProp->Ks > MKleinsteZahl) - val += (SolidProp->biot_const-poro)/SolidProp->Ks * (1-Sw) * GasProp->Density(dens_arg) / rhow; - } + break; + case 2: // + // (1-S)n(d rhop_c/d p_c) + PG2 = interpolate(NodalVal_p2); + dens_arg[0] = PG2; // 28.05.2008. WW + val = 0.; // 28.05.2008. WW + if (diffusion) // 28.05.2008. WW + { + val = (1.0 - Sw) * rho_gw / (rhow * Rv * TG * rhow); + p_gw = rho_gw * Rv * TG; + dens_arg[0] -= p_gw; + dens_arg[1] = TG; + } + rho_ga = GasProp->Density(dens_arg); // 28.05.2008. WW + val -= rho_ga * dSdp / rhow; + val *= poro; + // WX:11.2012.storage + if (SolidProp) + { + if (SolidProp->Ks > MKleinsteZahl) + val -= rho_ga / rhow * ((1 - Sw) * (SolidProp->biot_const - poro) / SolidProp->Ks * Sw); + } - break; + break; + case 3: // + // Approximation of d dens_g/dp_g 16.08.2011. WW + dens_arg[0] = PG2 + pert; + if (diffusion) + dens_arg[1] = TG; + /// d dens_g/dp_g: + if (GasProp->density_model == 2) // dens_g/dp_g = drho_dp 02.2012. WX + val = (1.0 - Sw) * poro * GasProp->rho_0 * GasProp->drho_dp / rhow; + else + val = (1.0 - Sw) * poro * (GasProp->Density(dens_arg) - rho_ga) / (pert * rhow); + // Storage WX:11.2012 + if (SolidProp) + { + if (SolidProp->Ks > MKleinsteZahl) + val += (SolidProp->biot_const - poro) / SolidProp->Ks * (1 - Sw) * GasProp->Density(dens_arg) + / rhow; + } + + break; } return val; } - - /************************************************************************** FEMLib-Method: Task: Calculate material coefficient for mass matrix for @@ -1924,34 +1870,37 @@ double CFiniteElementStd::CalCoefMass2(int dof_index) void CFiniteElementStd::CalCoefMassMCF() { int in, nDF = pcs->dof, Index = MeshElement->GetIndex(); - double arg_PV[6], retardation_factore[4], rho, beta_T, beta_p; - for(in = 0; inDensity(arg_PV); - poro = MediaProp->Porosity(Index,pcs->m_num->ls_theta); + poro = MediaProp->Porosity(Index, pcs->m_num->ls_theta); beta_T = FluidProp->drhodT(arg_PV); beta_p = FluidProp->drhodP(arg_PV); - //Mass Matrix Elements value--start - MassMatrixElements[0] = rho*(poro*beta_p + MediaProp->StorageFunction(Index, unit, pcs->m_num->ls_theta)); - MassMatrixElements[1] = poro*rho*beta_T; - if(FluidProp->mu_JT == "ON") - MassMatrixElements[nDF] = -poro*arg_PV[1]*beta_T; // JOD - MassMatrixElements[nDF + 1] = poro*rho*FluidProp->SpecificHeatCapacity(arg_PV) + (1.0 - poro)*SolidProp->Density(0)*SolidProp->Heat_Capacity(); - if(FluidProp->cmpN > 0) - { - for(in = 0; inDensity(0)*FluidProp->Kd[in]*pow(poro, -1.0); - for(in = 2; in < nDF; in++) - MassMatrixElements[in] = poro*rho*FluidProp->drhodX(in, arg_PV); - for(in = 2; in StorageFunction(Index, unit, pcs->m_num->ls_theta)); + MassMatrixElements[1] = poro * rho * beta_T; + if (FluidProp->mu_JT == "ON") + MassMatrixElements[nDF] = -poro * arg_PV[1] * beta_T; // JOD + MassMatrixElements[nDF + 1] = poro * rho * FluidProp->SpecificHeatCapacity(arg_PV) + + (1.0 - poro) * SolidProp->Density(0) * SolidProp->Heat_Capacity(); + if (FluidProp->cmpN > 0) + { + for (in = 0; in < nDF - 2; in++) + retardation_factore[in] = 1.0 + (1.0 - poro) * SolidProp->Density(0) * FluidProp->Kd[in] * pow(poro, -1.0); + for (in = 2; in < nDF; in++) + MassMatrixElements[in] = poro * rho * FluidProp->drhodX(in, arg_PV); + for (in = 2; in < nDF; in++) + MassMatrixElements[(nDF + 1) * in] = poro * retardation_factore[in - 2] * rho; + } + // Mass Matrix Elements value--end } /************************************************************************** @@ -1964,47 +1913,48 @@ double CFiniteElementStd::CalCoefMassPSGLOBAL(int dof_index) { int Index = MeshElement->GetIndex(); double val = 0.0, variables[3]; - double P,T; - //OK411 double expfactor = 0.0; - //WW bool diffusion = false; //08.05.2008 WW - //WWif(MediaProp->heat_diffusion_model==273&&cpl_pcs) - //WW diffusion = true; + double P, T; + // OK411 double expfactor = 0.0; + // WW bool diffusion = false; //08.05.2008 WW + // WWif(MediaProp->heat_diffusion_model==273&&cpl_pcs) + // WW diffusion = true; // - if(pcs->m_num->ele_mass_lumping) + if (pcs->m_num->ele_mass_lumping) ComputeShapefct(1); - switch(dof_index) - { - case 0: - - // compressibility also for the wetting phase NB - poro = MediaProp->Porosity(Index,pcs->m_num->ls_theta); - Sw = 1.0 - interpolate(NodalVal_SatNW); //Sw = 1-Snw - P = interpolate(NodalVal1); //Pw - T = interpolate(NodalValC1); - variables[0]=P; - variables[1]=T; - val = poro * (Sw) * FluidProp->drhodP(variables) / FluidProp->Density(); - // cout << FluidProp->fluid_name << " Pressure: " << P << " Temp: " << ": drhodP: " << FluidProp->drhodP(P,T) << " density: " << FluidProp->Density() << "\n"; - break; - case 1: // Snw in the wetting equation - poro = MediaProp->Porosity(Index,pcs->m_num->ls_theta); - val = -poro; - break; - case 2: // Pw in the non-wetting equation - Sw = 1.0 - interpolate(NodalVal_SatNW); //Sw = 1 - Snw - // Pnw = Pw + Pc(Sw) - P = interpolate(NodalVal1) + MediaProp->CapillaryPressureFunction(Sw); - // P = interpolate(NodalVal1); // Pw - T = interpolate(NodalValC1); - variables[0]=P; - variables[1]=T; - val = poro * (1. - Sw) * GasProp->drhodP(variables) / GasProp->Density(); + switch (dof_index) + { + case 0: - break; - case 3: // Snw in the non-wetting equation - poro = MediaProp->Porosity(Index,pcs->m_num->ls_theta); - val = poro; - break; + // compressibility also for the wetting phase NB + poro = MediaProp->Porosity(Index, pcs->m_num->ls_theta); + Sw = 1.0 - interpolate(NodalVal_SatNW); // Sw = 1-Snw + P = interpolate(NodalVal1); // Pw + T = interpolate(NodalValC1); + variables[0] = P; + variables[1] = T; + val = poro * (Sw)*FluidProp->drhodP(variables) / FluidProp->Density(); + // cout << FluidProp->fluid_name << " Pressure: " << P << " Temp: " << ": drhodP: " << + // FluidProp->drhodP(P,T) << " density: " << FluidProp->Density() << "\n"; + break; + case 1: // Snw in the wetting equation + poro = MediaProp->Porosity(Index, pcs->m_num->ls_theta); + val = -poro; + break; + case 2: // Pw in the non-wetting equation + Sw = 1.0 - interpolate(NodalVal_SatNW); // Sw = 1 - Snw + // Pnw = Pw + Pc(Sw) + P = interpolate(NodalVal1) + MediaProp->CapillaryPressureFunction(Sw); + // P = interpolate(NodalVal1); // Pw + T = interpolate(NodalValC1); + variables[0] = P; + variables[1] = T; + val = poro * (1. - Sw) * GasProp->drhodP(variables) / GasProp->Density(); + + break; + case 3: // Snw in the non-wetting equation + poro = MediaProp->Porosity(Index, pcs->m_num->ls_theta); + val = poro; + break; } return val; @@ -2023,56 +1973,54 @@ double CFiniteElementStd::CalCoefStorage() { int Index = MeshElement->GetIndex(); double val = 0.0; - double saturation = 0.0; // SB, BG - int tr_phase = 0; // SB, BG - CompProperties* m_cp = NULL; //CMCD - //CompProperties *m_cp = cp_vec[pcs->pcs_component_number]; //SB4200 - switch(PcsType) - { - default: - std::cout << "Fatal error in CalCoefStorage: No valid PCS type" << "\n"; - break; - case EPT_LIQUID_FLOW: // Liquid flow - break; - case EPT_UNCONFINED_FLOW: // Unconfined flow - break; - case EPT_GROUNDWATER_FLOW: // MB now Groundwater flow - break; - case EPT_TWOPHASE_FLOW: // Two-phase flow - break; - case EPT_COMPONENTAL_FLOW: // Componental flow - break; - case EPT_HEAT_TRANSPORT: // heat transport - val = 0.0; - break; - case EPT_MASS_TRANSPORT: // Mass transport //SB4200 - //CMCD - m_cp = cp_vec[pcs->pcs_component_number]; - //Porosity - val = MediaProp->Porosity(Index,pcs->m_num->ls_theta); - // SB, BG - tr_phase = cp_vec[this->pcs->pcs_component_number]->transport_phase; - // Multi phase transport of components - saturation = PCSGetEleMeanNodeSecondary_2(Index, - pcs->flow_pcs_type, - "SATURATION1", - 1); - if(tr_phase == 0) // Water phase - val *= saturation; - else if (tr_phase == 10) // non wetting phase - val *= (1.0 - saturation); // SB, BG - val *= m_cp->CalcElementDecayRateNew(Index, pcs); - //Retardation Factor - val *= m_cp->CalcElementRetardationFactorNew(Index, unit, pcs); - break; - case EPT_OVERLAND_FLOW: // Liquid flow - break; - case EPT_RICHARDS_FLOW: // Richards - break; - case EPT_FLUID_MOMENTUM: // Fluid Momentum - break; - case EPT_GAS_FLOW: // Air (gas) flow - break; + double saturation = 0.0; // SB, BG + int tr_phase = 0; // SB, BG + CompProperties* m_cp = NULL; // CMCD + // CompProperties *m_cp = cp_vec[pcs->pcs_component_number]; //SB4200 + switch (PcsType) + { + default: + std::cout << "Fatal error in CalCoefStorage: No valid PCS type" + << "\n"; + break; + case EPT_LIQUID_FLOW: // Liquid flow + break; + case EPT_UNCONFINED_FLOW: // Unconfined flow + break; + case EPT_GROUNDWATER_FLOW: // MB now Groundwater flow + break; + case EPT_TWOPHASE_FLOW: // Two-phase flow + break; + case EPT_COMPONENTAL_FLOW: // Componental flow + break; + case EPT_HEAT_TRANSPORT: // heat transport + val = 0.0; + break; + case EPT_MASS_TRANSPORT: // Mass transport //SB4200 + // CMCD + m_cp = cp_vec[pcs->pcs_component_number]; + // Porosity + val = MediaProp->Porosity(Index, pcs->m_num->ls_theta); + // SB, BG + tr_phase = cp_vec[this->pcs->pcs_component_number]->transport_phase; + // Multi phase transport of components + saturation = PCSGetEleMeanNodeSecondary_2(Index, pcs->flow_pcs_type, "SATURATION1", 1); + if (tr_phase == 0) // Water phase + val *= saturation; + else if (tr_phase == 10) // non wetting phase + val *= (1.0 - saturation); // SB, BG + val *= m_cp->CalcElementDecayRateNew(Index, pcs); + // Retardation Factor + val *= m_cp->CalcElementRetardationFactorNew(Index, unit, pcs); + break; + case EPT_OVERLAND_FLOW: // Liquid flow + break; + case EPT_RICHARDS_FLOW: // Richards + break; + case EPT_FLUID_MOMENTUM: // Fluid Momentum + break; + case EPT_GAS_FLOW: // Air (gas) flow + break; } return val; } @@ -2092,66 +2040,66 @@ double CFiniteElementStd::CalCoefContent() double val = 0.0; double dS = 0.0; double nodeval0, nodeval1, porval0, porval1; - int tr_phase = 0; // SB, BG - //CompProperties *m_cp = NULL; //SB4200 + int tr_phase = 0; // SB, BG + // CompProperties *m_cp = NULL; //SB4200 string name; - switch(PcsType) + switch (PcsType) { - default: - std::cout << "Fatal error in CalCoefContent: No valid PCS type" << "\n"; - break; - case EPT_LIQUID_FLOW: // Liquid flow - break; - case EPT_UNCONFINED_FLOW: // Unconfined flow - break; - case EPT_GROUNDWATER_FLOW: // MB now Groundwater flow - break; - case EPT_TWOPHASE_FLOW: // Two-phase flow - break; - case EPT_COMPONENTAL_FLOW: // Componental flow - break; - case EPT_HEAT_TRANSPORT: // heat transport - break; - case EPT_MASS_TRANSPORT: // Mass transport //SB4200 - { - //kg44 added changing Porosity for GEMS coupling - + default: + std::cout << "Fatal error in CalCoefContent: No valid PCS type" + << "\n"; + break; + case EPT_LIQUID_FLOW: // Liquid flow + break; + case EPT_UNCONFINED_FLOW: // Unconfined flow + break; + case EPT_GROUNDWATER_FLOW: // MB now Groundwater flow + break; + case EPT_TWOPHASE_FLOW: // Two-phase flow + break; + case EPT_COMPONENTAL_FLOW: // Componental flow + break; + case EPT_HEAT_TRANSPORT: // heat transport + break; + case EPT_MASS_TRANSPORT: // Mass transport //SB4200 + { +// kg44 added changing Porosity for GEMS coupling #ifdef GEM_REACT - // kg44 for GEMS coupling this should be updated to arbitrary flow processes - porval0 = PCSGetFlow()->GetElementValue(Index,PCSGetFlow()-> - GetElementValueIndex("POROSITY")); // for GEMS we need old and new porosity! - porval1 = PCSGetFlow()->GetElementValue(Index,PCSGetFlow()-> - GetElementValueIndex( - "POROSITY") + 1); + // kg44 for GEMS coupling this should be updated to arbitrary flow processes + porval0 = PCSGetFlow()->GetElementValue( + Index, PCSGetFlow()->GetElementValueIndex("POROSITY")); // for GEMS we need old and new porosity! + porval1 = PCSGetFlow()->GetElementValue(Index, PCSGetFlow()->GetElementValueIndex("POROSITY") + 1); #else - porval0 = MediaProp->Porosity(Index,pcs->m_num->ls_theta); // get porosity..this is the "old" behaviour without GEMS coupling - porval1 = porval0; // mimic no porosity change + porval0 = MediaProp->Porosity( + Index, pcs->m_num->ls_theta); // get porosity..this is the "old" behaviour without GEMS coupling + porval1 = porval0; // mimic no porosity change #endif - // Get saturation change: - // Get saturation change, depending on phase // SB, BG - tr_phase = cp_vec[this->pcs->pcs_component_number]->transport_phase; - nodeval0 = PCSGetEleMeanNodeSecondary_2(Index, pcs->flow_pcs_type, "SATURATION1", 0); - nodeval1 = PCSGetEleMeanNodeSecondary_2(Index, pcs->flow_pcs_type, "SATURATION1", 1); - if (tr_phase == 10) - { - nodeval0 = 1.0 - nodeval0; - nodeval1 = 1.0 - nodeval1; - } // SB, BG - dS = porval1 * nodeval1 - porval0 * nodeval0; // 1/dt accounted for in assemble function - // if(Index == 195) cout << val << "Sat_old = " << nodeval0 << ", Sa_new: "<< nodeval1<< ", dS: " << dS << "\n"; - val = dS; - break; - } - case EPT_OVERLAND_FLOW: // Liquid flow - break; - case EPT_RICHARDS_FLOW: // Richards - break; - case EPT_FLUID_MOMENTUM: // Fluid Momentum - break; - case EPT_GAS_FLOW: // Air (gas) flow - break; + // Get saturation change: + // Get saturation change, depending on phase // SB, BG + tr_phase = cp_vec[this->pcs->pcs_component_number]->transport_phase; + nodeval0 = PCSGetEleMeanNodeSecondary_2(Index, pcs->flow_pcs_type, "SATURATION1", 0); + nodeval1 = PCSGetEleMeanNodeSecondary_2(Index, pcs->flow_pcs_type, "SATURATION1", 1); + if (tr_phase == 10) + { + nodeval0 = 1.0 - nodeval0; + nodeval1 = 1.0 - nodeval1; + } // SB, BG + dS = porval1 * nodeval1 - porval0 * nodeval0; // 1/dt accounted for in assemble function + // if(Index == 195) cout << val << "Sat_old = " << nodeval0 << ", Sa_new: "<< nodeval1<< ", dS: " << dS + //<< "\n"; + val = dS; + break; + } + case EPT_OVERLAND_FLOW: // Liquid flow + break; + case EPT_RICHARDS_FLOW: // Richards + break; + case EPT_FLUID_MOMENTUM: // Fluid Momentum + break; + case EPT_GAS_FLOW: // Air (gas) flow + break; } return val; } @@ -2170,7 +2118,7 @@ double CFiniteElementStd::CalCoefContent() **************************************************************************/ void CFiniteElementStd::CalCoefLaplace(bool Gravity, int ip) { - double dens_arg[3]; //AKS + double dens_arg[3]; // AKS double mat_fac = 1.0; double Dpv = 0.0; double poro = 0.0; @@ -2178,456 +2126,449 @@ void CFiniteElementStd::CalCoefLaplace(bool Gravity, int ip) double humi = 1.0; double rhow = 0.0; double* tensor = NULL; - double Hav,manning,chezy,expp,chezy4,Ss,arg; - static double Hn[9],z[9]; - double GradH[3],Gradz[3],w[3],v1[3],v2[3]; + double Hav, manning, chezy, expp, chezy4, Ss, arg; + static double Hn[9], z[9]; + double GradH[3], Gradz[3], w[3], v1[3], v2[3]; int nidx1; int Index = MeshElement->GetIndex(); double k_rel; - ComputeShapefct(1); // 12.3.2007 WW - double variables[3]; //OK4709 - int tr_phase = 0; // SB, BG - double perm_effstress=1.;//AS:08.2012 - //WX:12.2012 perm depends on p or strain, same as CalCoefLaplace2 - CFiniteElementStd *h_fem; + ComputeShapefct(1); // 12.3.2007 WW + double variables[3]; // OK4709 + int tr_phase = 0; // SB, BG + double perm_effstress = 1.; // AS:08.2012 + // WX:12.2012 perm depends on p or strain, same as CalCoefLaplace2 + CFiniteElementStd* h_fem; h_fem = this; double fac_perm = 1.0; - // For nodal value interpolation //====================================================================== - switch(PcsType) + switch (PcsType) { - default: - break; - case EPT_LIQUID_FLOW: // Liquid flow - tensor = MediaProp->PermeabilityTensor(Index); - //AS:08.2012 permeability function eff stress - if(MediaProp->permeability_effstress_model>0) - { - CFiniteElementStd *h_fem; - h_fem=this; - perm_effstress = MediaProp->PermeabilityFunctionEffStress(Index, nnodes, h_fem); - } - - //if (ele_dim != dim) - if (dim > MediaProp->geo_dimension) - { - Matrix local_tensor(dim,dim); - Matrix temp_tensor(dim,dim); - if (MeshElement->transform_tensor==NULL) { - std::cout << "***Error: Geometric dimension in MMP is not consistent with element." << "\n"; - exit(0); - } - Matrix t_transform_tensor(*MeshElement->transform_tensor); - MeshElement->transform_tensor->GetTranspose(t_transform_tensor); - Matrix global_tensor(dim,dim); - for (size_t i = 0; i < ele_dim; i++) - for (size_t j = 0; j < ele_dim; j++) - local_tensor(i,j) = tensor[j + i * ele_dim]; - //cout << "K':" << "\n"; local_tensor.Write(); - local_tensor.multi(t_transform_tensor, temp_tensor); - for (size_t i = 0; i < dim; i++) - for (size_t j = 0; j < dim; j++) - for (size_t k = 0; k < dim; k++) - global_tensor(i, j) += (*MeshElement->transform_tensor)(i, k) - * temp_tensor(k,j); - //cout << "K:" << "\n"; global_tensor.Write(); - for(size_t i = 0; i < dim; i++) - for(size_t j = 0; j < dim; j++) - tensor[dim * i + j] = global_tensor(i,j); - } - variables[0] = interpolate(NodalVal1); //OK4709 pressure - if(T_Flag) - variables[1] = interpolate(NodalValC); //OK4709 temperature - else - variables[1] = 15;//WX - - //OK4709 - mat_fac = FluidProp->Viscosity(variables); - //OK4709 mat_fac = FluidProp->Viscosity(); - if(gravity_constant < MKleinsteZahl) // HEAD version - mat_fac = 1.0; - if(HEAD_Flag) - mat_fac = 1.0; - // Modified LBNL model WW - if(MediaProp->permeability_stress_mode > 1) - { - if(cpl_pcs) - TG = interpolate(NodalValC1) + PhysicalConstant::CelsiusZeroInKelvin; + default: + break; + case EPT_LIQUID_FLOW: // Liquid flow + tensor = MediaProp->PermeabilityTensor(Index); + // AS:08.2012 permeability function eff stress + if (MediaProp->permeability_effstress_model > 0) + { + CFiniteElementStd* h_fem; + h_fem = this; + perm_effstress = MediaProp->PermeabilityFunctionEffStress(Index, nnodes, h_fem); + } + + // if (ele_dim != dim) + if (dim > MediaProp->geo_dimension) + { + Matrix local_tensor(dim, dim); + Matrix temp_tensor(dim, dim); + if (MeshElement->transform_tensor == NULL) + { + std::cout << "***Error: Geometric dimension in MMP is not consistent with element." + << "\n"; + exit(0); + } + Matrix t_transform_tensor(*MeshElement->transform_tensor); + MeshElement->transform_tensor->GetTranspose(t_transform_tensor); + Matrix global_tensor(dim, dim); + for (size_t i = 0; i < ele_dim; i++) + for (size_t j = 0; j < ele_dim; j++) + local_tensor(i, j) = tensor[j + i * ele_dim]; + // cout << "K':" << "\n"; local_tensor.Write(); + local_tensor.multi(t_transform_tensor, temp_tensor); + for (size_t i = 0; i < dim; i++) + for (size_t j = 0; j < dim; j++) + for (size_t k = 0; k < dim; k++) + global_tensor(i, j) += (*MeshElement->transform_tensor)(i, k) * temp_tensor(k, j); + // cout << "K:" << "\n"; global_tensor.Write(); + for (size_t i = 0; i < dim; i++) + for (size_t j = 0; j < dim; j++) + tensor[dim * i + j] = global_tensor(i, j); + } + variables[0] = interpolate(NodalVal1); // OK4709 pressure + if (T_Flag) + variables[1] = interpolate(NodalValC); // OK4709 temperature else - TG = 296.0; - MediaProp->CalStressPermeabilityFactor(w, TG); - for(size_t i = 0; i < dim; i++) - tensor[i * dim + i] *= w[i]; - } - for(size_t i = 0; i < dim * dim; i++) - mat[i] = tensor[i] / mat_fac * perm_effstress;//AS:perm. dependent eff stress. + variables[1] = 15; // WX + + // OK4709 + mat_fac = FluidProp->Viscosity(variables); + // OK4709 mat_fac = FluidProp->Viscosity(); + if (gravity_constant < MKleinsteZahl) // HEAD version + mat_fac = 1.0; + if (HEAD_Flag) + mat_fac = 1.0; + // Modified LBNL model WW + if (MediaProp->permeability_stress_mode > 1) + { + if (cpl_pcs) + TG = interpolate(NodalValC1) + PhysicalConstant::CelsiusZeroInKelvin; + else + TG = 296.0; + MediaProp->CalStressPermeabilityFactor(w, TG); + for (size_t i = 0; i < dim; i++) + tensor[i * dim + i] *= w[i]; + } + for (size_t i = 0; i < dim * dim; i++) + mat[i] = tensor[i] / mat_fac * perm_effstress; // AS:perm. dependent eff stress. + break; + case EPT_GROUNDWATER_FLOW: // Groundwater flow + /* SB4218 - moved to ->PermeabilityTensor(Index); + if(MediaProp->permeability_model==2){ //?efficiency + for(i=0;i<(int)pcs->m_msh->mat_names_vector.size();i++){ + if(pcs->m_msh->mat_names_vector[i].compare("PERMEABILITY")==0) + break; + } + + mat_fac = MeshElement->mat_vector(i); + mat_fac /= FluidProp->Viscosity(); + for(i=0; iflowlinearity_model > 0) + k_rel = MediaProp->NonlinearFlowFunction(index, gp, pcs->m_num->ls_theta, this); // NW - break; - case EPT_GROUNDWATER_FLOW: // Groundwater flow - /* SB4218 - moved to ->PermeabilityTensor(Index); - if(MediaProp->permeability_model==2){ //?efficiency - for(i=0;i<(int)pcs->m_msh->mat_names_vector.size();i++){ - if(pcs->m_msh->mat_names_vector[i].compare("PERMEABILITY")==0) - break; - } - - mat_fac = MeshElement->mat_vector(i); - mat_fac /= FluidProp->Viscosity(); - for(i=0; iflowlinearity_model>0) - k_rel = MediaProp->NonlinearFlowFunction(index, gp, pcs->m_num->ls_theta, this); //NW - - tensor = MediaProp->PermeabilityTensor(Index); - //TK/NW 10.10.2011 - if (dim > MediaProp->geo_dimension) - { - Matrix local_tensor(dim,dim); - Matrix temp_tensor(dim,dim); - if (MeshElement->transform_tensor==NULL) { - std::cout << "***Error: Geometric dimension in MMP is not consistent with element." << "\n"; - exit(0); - } - Matrix t_transform_tensor(*MeshElement->transform_tensor); - MeshElement->transform_tensor->GetTranspose(t_transform_tensor); - Matrix global_tensor(dim,dim); - for (size_t i=0; itransform_tensor)(i,k)*temp_tensor(k,j); - } - //cout << "K:" << "\n"; global_tensor.Write(); - if(MediaProp->unconfined_flow_group == 2) // 3D unconfined GW JOD, 5.3.07 + tensor = MediaProp->PermeabilityTensor(Index); + // TK/NW 10.10.2011 + if (dim > MediaProp->geo_dimension) + { + Matrix local_tensor(dim, dim); + Matrix temp_tensor(dim, dim); + if (MeshElement->transform_tensor == NULL) + { + std::cout << "***Error: Geometric dimension in MMP is not consistent with element." + << "\n"; + exit(0); + } + Matrix t_transform_tensor(*MeshElement->transform_tensor); + MeshElement->transform_tensor->GetTranspose(t_transform_tensor); + Matrix global_tensor(dim, dim); + for (size_t i = 0; i < ele_dim; i++) + for (size_t j = 0; j < ele_dim; j++) + local_tensor(i, j) = tensor[j + i * ele_dim]; + // cout << "K':" << "\n"; local_tensor.Write(); + local_tensor.multi(t_transform_tensor, temp_tensor); + for (size_t i = 0; i < dim; i++) { - double * pressureHead; + for (size_t j = 0; j < dim; j++) + for (size_t k = 0; k < dim; k++) + global_tensor(i, j) += (*MeshElement->transform_tensor)(i, k) * temp_tensor(k, j); + } + // cout << "K:" << "\n"; global_tensor.Write(); + if (MediaProp->unconfined_flow_group == 2) // 3D unconfined GW JOD, 5.3.07 + { + double* pressureHead; pressureHead = new double[8]; - for(int i = 0; i < nnodes; i++) - pressureHead[i] = pcs->GetNodeValue(nodes[i], 1) - pcs->m_msh->nod_vector[nodes[i]]->getData()[2]; + for (int i = 0; i < nnodes; i++) + pressureHead[i] + = pcs->GetNodeValue(nodes[i], 1) - pcs->m_msh->nod_vector[nodes[i]]->getData()[2]; PG = interpolate(pressureHead); - delete [] pressureHead; + delete[] pressureHead; - mat_fac = MediaProp->PermeabilitySaturationFunction(-PG,0); + mat_fac = MediaProp->PermeabilitySaturationFunction(-PG, 0); } - for(size_t i=0; iPermeabilityTensor(Index); - if(pcs->pcs_type_number == 0) - { - if(!Gravity) + for (size_t i = 0; i < dim; i++) + { + for (size_t j = 0; j < dim; j++) + { + tensor[dim * i + j] = global_tensor(i, j); + } + } + } + // TK/NW 10.10.2011 + for (size_t i = 0; i < dim * dim; i++) + // 16.10.2009 .WW + mat[i] = tensor[i] * time_unit_factor * k_rel; + break; + //.................................................................. + case EPT_TWOPHASE_FLOW: // Two-phase flow + // PCH Rewriting... + // PCH Laplace mat_fac is accounted for two phases here. + // thought to be related to the reference pressure. + tensor = MediaProp->PermeabilityTensor(Index); + if (pcs->pcs_type_number == 0) { - // PCH Laplace mat_fac is accounted for two phases here. - // thought to be related to the reference pressure. - int numOfPhases = 2; - double mat_fac = 0.0; - for(int p = 0; p < numOfPhases; ++p) + if (!Gravity) + { + // PCH Laplace mat_fac is accounted for two phases here. + // thought to be related to the reference pressure. + int numOfPhases = 2; + double mat_fac = 0.0; + for (int p = 0; p < numOfPhases; ++p) + { + // PCH Check if Capillary term is on + if (pcs->ML_Cap == 1) + p = 1; + + idxS = cpl_pcs->GetNodeValueIndex("SATURATION2"); + + for (int i = 0; i < nnodes; i++) + NodalVal_Sat[i] = cpl_pcs->GetNodeValue(nodes[i], idxS + 1); + + // Whatever phase, we use Sw for getting relative permeabilities + Sw = 1.0 - interpolate(NodalVal_Sat); + k_rel = MediaProp->PermeabilitySaturationFunction(Sw, p); + + // Note here mat_fac is += meaning adding two phases + mat_fac += time_unit_factor * k_rel / mfp_vector[p]->Viscosity(); + // If Partial-Pressure-Based model + if (pcs->PartialPS == 1) + p = 1; + } + for (size_t i = 0; i < dim * dim; i++) + mat[i] = tensor[i] * mat_fac; + } + else // Here is only active for Cal_Velocity { - // PCH Check if Capillary term is on - if(pcs->ML_Cap == 1) - p = 1; + // This is to calculate velocity + // WW int numOfPhases = 2; + double mat_fac = 0.0; idxS = cpl_pcs->GetNodeValueIndex("SATURATION2"); - for(int i = 0; i < nnodes; i++) - NodalVal_Sat[i] = cpl_pcs->GetNodeValue(nodes[i], - idxS + 1); + for (int i = 0; i < nnodes; i++) + NodalVal_Sat[i] = cpl_pcs->GetNodeValue(nodes[i], idxS + 1); - // Whatever phase, we use Sw for getting relative permeabilities Sw = 1.0 - interpolate(NodalVal_Sat); - k_rel = MediaProp->PermeabilitySaturationFunction(Sw,p); + k_rel = MediaProp->PermeabilitySaturationFunction(Sw, pcs->pcs_type_number); // Note here mat_fac is += meaning adding two phases - mat_fac += time_unit_factor * k_rel / - mfp_vector[p]->Viscosity(); - // If Partial-Pressure-Based model - if(pcs->PartialPS == 1) - p = 1; + mat_fac = time_unit_factor * k_rel / mfp_vector[pcs->pcs_type_number]->Viscosity(); + + for (size_t i = 0; i < dim * dim; i++) + mat[i] = tensor[i] * mat_fac; } - for(size_t i = 0; i < dim * dim; i++) - mat[i] = tensor[i] * mat_fac; } - else // Here is only active for Cal_Velocity + else if (pcs->pcs_type_number == 1) { - // This is to calculate velocity - //WW int numOfPhases = 2; - double mat_fac = 0.0; - - idxS = cpl_pcs->GetNodeValueIndex("SATURATION2"); + // PCH Check if Capillary term is on + if (pcs->ML_Cap == 1) + { + int phase = pcs->pcs_type_number; - for(int i = 0; i < nnodes; i++) - NodalVal_Sat[i] = cpl_pcs->GetNodeValue(nodes[i],idxS + 1); + idxS = pcs->GetNodeValueIndex("SATURATION2"); + for (int i = 0; i < nnodes; i++) + NodalVal_Sat[i] = pcs->GetNodeValue(nodes[i], idxS + 1); + Sw = 1.0 - interpolate(NodalVal_Sat); + k_rel = MediaProp->PermeabilitySaturationFunction(Sw, phase); + + // Here only the second phase accounted. + // Let's get dPcdSw and apply to the mat_fac + CMediumProperties* m_mmp = NULL; + m_mmp = mmp_vector[0]; + double dPcdSw = 0.0; + if (m_mmp->capillary_pressure_values[0] < MKleinsteZahl) + dPcdSw = 0.0; + else + dPcdSw = -m_mmp->PressureSaturationDependency(Sw, false); // JT: now returns correct sign. + mat_fac = time_unit_factor * k_rel / mfp_vector[phase]->Viscosity() * (-dPcdSw); + for (size_t i = 0; i < dim * dim; i++) + mat[i] = tensor[i] * mat_fac; + } + else + { + int phase = pcs->pcs_type_number; - Sw = 1.0 - interpolate(NodalVal_Sat); - k_rel = MediaProp->PermeabilitySaturationFunction( - Sw, - pcs-> - pcs_type_number); + idxS = pcs->GetNodeValueIndex("SATURATION2"); + for (int i = 0; i < nnodes; i++) + NodalVal_Sat[i] = pcs->GetNodeValue(nodes[i], idxS + 1); + Sw = 1.0 - interpolate(NodalVal_Sat); + k_rel = MediaProp->PermeabilitySaturationFunction(Sw, phase); - // Note here mat_fac is += meaning adding two phases - mat_fac = time_unit_factor * k_rel / - mfp_vector[pcs->pcs_type_number]->Viscosity(); + // Here only the second phase accounted. + mat_fac = time_unit_factor * k_rel / mfp_vector[phase]->Viscosity(); + for (size_t i = 0; i < dim * dim; i++) + mat[i] = tensor[i] * mat_fac; + } + } - for(size_t i = 0; i < dim * dim; i++) - mat[i] = tensor[i] * mat_fac; + break; + //.................................................................. + case EPT_COMPONENTAL_FLOW: // Componental flow + break; + case EPT_HEAT_TRANSPORT: // heat transport + if (SolidProp->GetConductModel() == 2) // Boiling model. DECOVALEX THM2 + { + TG = interpolate(NodalVal1); + for (size_t i = 0; i < dim * dim; i++) + mat[i] = 0.0; + for (size_t i = 0; i < dim; i++) + mat[i * dim + i] = SolidProp->Heat_Conductivity(TG); } - } - else if(pcs->pcs_type_number == 1) - { - // PCH Check if Capillary term is on - if(pcs->ML_Cap == 1) + // DECOVALEX THM1 or Curce 12.09. WW + else if (SolidProp->GetConductModel() % 3 == 0 || SolidProp->GetConductModel() == 4) { - int phase = pcs->pcs_type_number; - - idxS = pcs->GetNodeValueIndex("SATURATION2"); - for(int i = 0; i < nnodes; i++) - NodalVal_Sat[i] = pcs->GetNodeValue(nodes[i],idxS + 1); - Sw = 1.0 - interpolate(NodalVal_Sat); - k_rel = MediaProp->PermeabilitySaturationFunction(Sw,phase); - - // Here only the second phase accounted. - // Let's get dPcdSw and apply to the mat_fac - CMediumProperties* m_mmp = NULL; - m_mmp = mmp_vector[0]; - double dPcdSw = 0.0; - if (m_mmp->capillary_pressure_values[0] < MKleinsteZahl) - dPcdSw = 0.0; - else - dPcdSw = -m_mmp->PressureSaturationDependency(Sw,false); // JT: now returns correct sign. - mat_fac = time_unit_factor * k_rel / - mfp_vector[phase]->Viscosity() * (-dPcdSw); - for(size_t i = 0; i < dim * dim; i++) - mat[i] = tensor[i] * mat_fac; + // WW + PG = interpolate(NodalValC1); + if (cpl_pcs->type != 1212) + PG *= -1.0; + Sw = MediaProp->SaturationCapillaryPressureFunction(PG); + for (size_t i = 0; i < dim * dim; i++) + mat[i] = 0.0; + mat_fac = SolidProp->Heat_Conductivity(Sw); + for (size_t i = 0; i < dim; i++) + mat[i * dim + i] = mat_fac; + } + // WW else if(SolidProp->GetCapacityModel()==1 && MediaProp->heat_diffusion_model == 273){ + else if (SolidProp->GetConductModel() == 1) + { + TG = interpolate(NodalVal1); + tensor = MediaProp->HeatDispersionTensorNew(ip); + for (size_t i = 0; i < dim * dim; i++) + mat[i] = tensor[i]; } else { - int phase = pcs->pcs_type_number; - - idxS = pcs->GetNodeValueIndex("SATURATION2"); - for(int i = 0; i < nnodes; i++) - NodalVal_Sat[i] = pcs->GetNodeValue(nodes[i],idxS + 1); - Sw = 1.0 - interpolate(NodalVal_Sat); - k_rel = MediaProp->PermeabilitySaturationFunction(Sw,phase); - - // Here only the second phase accounted. - mat_fac = time_unit_factor * k_rel / mfp_vector[phase]->Viscosity(); - for(size_t i = 0; i < dim * dim; i++) - mat[i] = tensor[i] * mat_fac; + tensor = MediaProp->HeatConductivityTensor(Index); + for (size_t i = 0; i < dim * dim; i++) + mat[i] = tensor[i]; // mat[i*dim+i] = tensor[i]; } - } - - break; - //.................................................................. - case EPT_COMPONENTAL_FLOW: // Componental flow - break; - case EPT_HEAT_TRANSPORT: // heat transport - if(SolidProp->GetConductModel() == 2) // Boiling model. DECOVALEX THM2 - { - TG = interpolate(NodalVal1); - for(size_t i = 0; i < dim * dim; i++) - mat[i] = 0.0; - for(size_t i = 0; i < dim; i++) - mat[i * dim + i] = SolidProp->Heat_Conductivity(TG); - } - // DECOVALEX THM1 or Curce 12.09. WW - else if(SolidProp->GetConductModel()%3 == 0 || SolidProp->GetConductModel() == 4) - { - // WW - PG = interpolate(NodalValC1); - if(cpl_pcs->type != 1212) - PG *= -1.0; - Sw = MediaProp->SaturationCapillaryPressureFunction(PG); - for(size_t i = 0; i < dim * dim; i++) - mat[i] = 0.0; - mat_fac = SolidProp->Heat_Conductivity(Sw); - for(size_t i = 0; i < dim; i++) - mat[i * dim + i] = mat_fac; - } - //WW else if(SolidProp->GetCapacityModel()==1 && MediaProp->heat_diffusion_model == 273){ - else if(SolidProp->GetConductModel() == 1) - { - TG = interpolate(NodalVal1); - tensor = MediaProp->HeatDispersionTensorNew(ip); - for(size_t i = 0; i < dim * dim; i++) - mat[i] = tensor[i]; - } - else - { - tensor = MediaProp->HeatConductivityTensor(Index); - for(size_t i = 0; i < dim * dim; i++) - mat[i] = tensor[i]; //mat[i*dim+i] = tensor[i]; - } - break; - case EPT_MASS_TRANSPORT: // Mass transport - mat_fac = 1.0; //MediaProp->Porosity(Index,pcs->m_num->ls_theta); // porosity now included in MassDispersionTensorNew() - // Get transport phase of component, to obtain correct velocities in dispersion tensor - tr_phase = cp_vec[this->pcs->pcs_component_number]->transport_phase; - // SB, BG - tensor = MediaProp->MassDispersionTensorNew(ip, tr_phase); - //CB - //SB->CB I think this does not belong here - // mat_fac *= PCSGetEleMeanNodeSecondary_2(Index, pcs->flow_pcs_type, "SATURATION1", 1); - //if(PCSGet("RICHARDS_FLOW")) - // mat_fac *= PCSGetEleMeanNodeSecondary(Index, "RICHARDS_FLOW", "SATURATION1", 1); - for(size_t i = 0; i < dim * dim; i++) - mat[i] = tensor[i] * mat_fac * time_unit_factor; - break; - //------------------------------------------------------------------ - case EPT_OVERLAND_FLOW: // Overland flow - //................................................................ - // H - water level - nidx1 = pcs->GetNodeValueIndex("HEAD") + 1; - Hav = 0.0; - for(int i = 0; i < nnodes; i++) - { - z[i] = MeshElement->nodes[i]->getData()[2]; - Hn[i] = pcs->GetNodeValue(MeshElement->nodes_index[i],nidx1) - z[i]; - if (Hn[i] < 0.0) - Hn[i] = 0.0; - Hav += Hn[i] / (double)nnodes; - } - //................................................................ - // Friction coefficient - tensor = MediaProp->PermeabilityTensor(Index); - // Manning-coefficient: n - manning = MediaProp->permeability_tensor[0]; - // ToDo MB MMP function: m_mmp->FrictionCoefficientChezy(gp) - if (MediaProp->conductivity_model == 3) // Chezy-coefficient C - { - expp = 1.0 / 6.0; - chezy = pow(Hav,expp) / manning; // f? b >> h gilt: C = H**1/6 n**-1 - // Grad H: grad_N H J^-1 - MMultMatVec(dshapefct,dim,nnodes,Hn,nnodes,v1,dim); - MMultVecMat(v1,dim,invJacobian,dim,dim,GradH,dim); - // Grad z: ? s.Z.380ff - MMultMatVec(dshapefct,dim,nnodes,z,nnodes,v2,dim); - MMultVecMat(v2,dim,invJacobian,dim,dim,Gradz,dim); - w[0] = GradH[0] + Gradz[0]; - w[1] = GradH[1] + Gradz[1]; - chezy4 = MathLib::fastpow(chezy,4); - Ss = ((w[0] * w[0]) / chezy4) + ((w[1] * w[1]) / chezy4); - Ss = pow(Ss,0.25); - if (fabs(Ss) < 1.0e-7) - Ss = 1.0e-7; - expp = 5.0 / 3.0; - arg = (pow(Hav,expp)) / (chezy * chezy); - mat_fac = arg / Ss; - } - //................................................................ - // Tensor - for(size_t i = 0; i < dim * dim; i++) - //ToDo - mat[i] = tensor[i] / manning * mat_fac; - break; - //------------------------------------------------------------------ - case EPT_RICHARDS_FLOW: // Richards flow - // The following line only applies when Fluid Momentum is on - PG = interpolate(NodalVal1); //05.01.07 WW - //05.01.07 WW - Sw = MediaProp->SaturationCapillaryPressureFunction(-PG); - - if(MediaProp->permeability_pressure_model>0) //12.2012. WX - fac_perm = MediaProp->PermeabilityFunctionPressure(Index, PG); - if(MediaProp->permeability_strain_model>0) //12.2012 WX - fac_perm *= MediaProp->PermeabilityFunctionStrain(Index,nnodes,h_fem); + break; + case EPT_MASS_TRANSPORT: // Mass transport + mat_fac = 1.0; // MediaProp->Porosity(Index,pcs->m_num->ls_theta); // porosity now included in + // MassDispersionTensorNew() + // Get transport phase of component, to obtain correct velocities in dispersion tensor + tr_phase = cp_vec[this->pcs->pcs_component_number]->transport_phase; + // SB, BG + tensor = MediaProp->MassDispersionTensorNew(ip, tr_phase); + // CB + // SB->CB I think this does not belong here + // mat_fac *= PCSGetEleMeanNodeSecondary_2(Index, pcs->flow_pcs_type, "SATURATION1", 1); + // if(PCSGet("RICHARDS_FLOW")) + // mat_fac *= PCSGetEleMeanNodeSecondary(Index, "RICHARDS_FLOW", "SATURATION1", 1); + for (size_t i = 0; i < dim * dim; i++) + mat[i] = tensor[i] * mat_fac * time_unit_factor; + break; + //------------------------------------------------------------------ + case EPT_OVERLAND_FLOW: // Overland flow + //................................................................ + // H - water level + nidx1 = pcs->GetNodeValueIndex("HEAD") + 1; + Hav = 0.0; + for (int i = 0; i < nnodes; i++) + { + z[i] = MeshElement->nodes[i]->getData()[2]; + Hn[i] = pcs->GetNodeValue(MeshElement->nodes_index[i], nidx1) - z[i]; + if (Hn[i] < 0.0) + Hn[i] = 0.0; + Hav += Hn[i] / (double)nnodes; + } + //................................................................ + // Friction coefficient + tensor = MediaProp->PermeabilityTensor(Index); + // Manning-coefficient: n + manning = MediaProp->permeability_tensor[0]; + // ToDo MB MMP function: m_mmp->FrictionCoefficientChezy(gp) + if (MediaProp->conductivity_model == 3) // Chezy-coefficient C + { + expp = 1.0 / 6.0; + chezy = pow(Hav, expp) / manning; // f? b >> h gilt: C = H**1/6 n**-1 + // Grad H: grad_N H J^-1 + MMultMatVec(dshapefct, dim, nnodes, Hn, nnodes, v1, dim); + MMultVecMat(v1, dim, invJacobian, dim, dim, GradH, dim); + // Grad z: ? s.Z.380ff + MMultMatVec(dshapefct, dim, nnodes, z, nnodes, v2, dim); + MMultVecMat(v2, dim, invJacobian, dim, dim, Gradz, dim); + w[0] = GradH[0] + Gradz[0]; + w[1] = GradH[1] + Gradz[1]; + chezy4 = MathLib::fastpow(chezy, 4); + Ss = ((w[0] * w[0]) / chezy4) + ((w[1] * w[1]) / chezy4); + Ss = pow(Ss, 0.25); + if (fabs(Ss) < 1.0e-7) + Ss = 1.0e-7; + expp = 5.0 / 3.0; + arg = (pow(Hav, expp)) / (chezy * chezy); + mat_fac = arg / Ss; + } + //................................................................ + // Tensor + for (size_t i = 0; i < dim * dim; i++) + // ToDo + mat[i] = tensor[i] / manning * mat_fac; + break; + //------------------------------------------------------------------ + case EPT_RICHARDS_FLOW: // Richards flow + // The following line only applies when Fluid Momentum is on + PG = interpolate(NodalVal1); // 05.01.07 WW + // 05.01.07 WW + Sw = MediaProp->SaturationCapillaryPressureFunction(-PG); + if (MediaProp->permeability_pressure_model > 0) // 12.2012. WX + fac_perm = MediaProp->PermeabilityFunctionPressure(Index, PG); + if (MediaProp->permeability_strain_model > 0) // 12.2012 WX + fac_perm *= MediaProp->PermeabilityFunctionStrain(Index, nnodes, h_fem); - tensor = MediaProp->PermeabilityTensor(Index); + tensor = MediaProp->PermeabilityTensor(Index); - if(MediaProp->unconfined_flow_group == 2) // 3D unconfined GW JOD, 5.3.07 - mat_fac = time_unit_factor * MediaProp->PermeabilitySaturationFunction(-PG,0) \ - / FluidProp->Viscosity(); - else - mat_fac = time_unit_factor * MediaProp->PermeabilitySaturationFunction(Sw,0) \ - / FluidProp->Viscosity(); - // Modified LBNL model WW - if(MediaProp->permeability_stress_mode > 1) - { - if(cpl_pcs) - TG = interpolate(NodalValC1) + PhysicalConstant::CelsiusZeroInKelvin; + if (MediaProp->unconfined_flow_group == 2) // 3D unconfined GW JOD, 5.3.07 + mat_fac = time_unit_factor * MediaProp->PermeabilitySaturationFunction(-PG, 0) / FluidProp->Viscosity(); else - TG = 296.0; - MediaProp->CalStressPermeabilityFactor(w, TG); - for(size_t i = 0; i < dim; i++) - tensor[i * dim + i] *= w[i]; - } - // - for(size_t i = 0; i < dim * dim; i++) - mat[i] = tensor[i] * mat_fac *fac_perm;//WX:12.2012 - - if(MediaProp->heat_diffusion_model == 1 && !Gravity) - { - rhow = FluidProp->Density(); - //PG = fabs(interpolate(NodalVal1)); - TG = interpolate(NodalValC) + PhysicalConstant::CelsiusZeroInKelvin; - poro = MediaProp->Porosity(Index,pcs->m_num->ls_theta); - tort = MediaProp->TortuosityFunction(Index,unit,pcs->m_num->ls_theta); - humi = exp(PG / (SpecificGasConstant::WaterVapour * TG * rhow)); + mat_fac = time_unit_factor * MediaProp->PermeabilitySaturationFunction(Sw, 0) / FluidProp->Viscosity(); + // Modified LBNL model WW + if (MediaProp->permeability_stress_mode > 1) + { + if (cpl_pcs) + TG = interpolate(NodalValC1) + PhysicalConstant::CelsiusZeroInKelvin; + else + TG = 296.0; + MediaProp->CalStressPermeabilityFactor(w, TG); + for (size_t i = 0; i < dim; i++) + tensor[i * dim + i] *= w[i]; + } // - Dpv = MediaProp->base_heat_diffusion_coefficient * tort * (1 - Sw) * poro - * pow(TG / PhysicalConstant::CelsiusZeroInKelvin, 1.8); - Dpv *= time_unit_factor * FluidProp->vaporDensity(TG) * humi / - (SpecificGasConstant::WaterVapour * rhow * TG); - for(size_t i = 0; i < dim; i++) - mat[i * dim + i] += Dpv / rhow; - } - break; - //------------------------------------------------------------------ - case EPT_GAS_FLOW: // Air flow - dens_arg[0] = interpolate(NodalVal1); - dens_arg[1] = interpolate(NodalValC1) + PhysicalConstant::CelsiusZeroInKelvin; - dens_arg[2] = Index; - double vis = FluidProp->Viscosity(dens_arg); - mat_fac = vis; - tensor = MediaProp->PermeabilityTensor(Index); - k_rel = 1.0; - if (MediaProp->flowlinearity_model>0) - k_rel = MediaProp->NonlinearFlowFunction(index, gp, pcs->m_num->ls_theta, this); //NW - - //WX:09.2011 - fac_perm=1.; - if(MediaProp->permeability_pressure_model>0) - { - fac_perm = MediaProp->PermeabilityFunctionPressure(Index, dens_arg[0]); - mat_fac /= fac_perm; - } - if(MediaProp->permeability_strain_model>0) - { - fac_perm = MediaProp->PermeabilityFunctionStrain(Index,nnodes,h_fem); - mat_fac /= fac_perm; - } + for (size_t i = 0; i < dim * dim; i++) + mat[i] = tensor[i] * mat_fac * fac_perm; // WX:12.2012 - for(size_t i = 0; i < dim * dim; i++) - mat[i] = tensor[i]/mat_fac*k_rel; - break; + if (MediaProp->heat_diffusion_model == 1 && !Gravity) + { + rhow = FluidProp->Density(); + // PG = fabs(interpolate(NodalVal1)); + TG = interpolate(NodalValC) + PhysicalConstant::CelsiusZeroInKelvin; + poro = MediaProp->Porosity(Index, pcs->m_num->ls_theta); + tort = MediaProp->TortuosityFunction(Index, unit, pcs->m_num->ls_theta); + humi = exp(PG / (SpecificGasConstant::WaterVapour * TG * rhow)); + // + Dpv = MediaProp->base_heat_diffusion_coefficient * tort * (1 - Sw) * poro + * pow(TG / PhysicalConstant::CelsiusZeroInKelvin, 1.8); + Dpv *= time_unit_factor * FluidProp->vaporDensity(TG) * humi + / (SpecificGasConstant::WaterVapour * rhow * TG); + for (size_t i = 0; i < dim; i++) + mat[i * dim + i] += Dpv / rhow; + } + break; //------------------------------------------------------------------ + case EPT_GAS_FLOW: // Air flow + dens_arg[0] = interpolate(NodalVal1); + dens_arg[1] = interpolate(NodalValC1) + PhysicalConstant::CelsiusZeroInKelvin; + dens_arg[2] = Index; + double vis = FluidProp->Viscosity(dens_arg); + mat_fac = vis; + tensor = MediaProp->PermeabilityTensor(Index); + k_rel = 1.0; + if (MediaProp->flowlinearity_model > 0) + k_rel = MediaProp->NonlinearFlowFunction(index, gp, pcs->m_num->ls_theta, this); // NW + + // WX:09.2011 + fac_perm = 1.; + if (MediaProp->permeability_pressure_model > 0) + { + fac_perm = MediaProp->PermeabilityFunctionPressure(Index, dens_arg[0]); + mat_fac /= fac_perm; + } + if (MediaProp->permeability_strain_model > 0) + { + fac_perm = MediaProp->PermeabilityFunctionStrain(Index, nnodes, h_fem); + mat_fac /= fac_perm; + } + + for (size_t i = 0; i < dim * dim; i++) + mat[i] = tensor[i] / mat_fac * k_rel; + break; + //------------------------------------------------------------------ } } @@ -2639,7 +2580,7 @@ void CFiniteElementStd::CalCoefLaplace(bool Gravity, int ip) **************************************************************************/ void CFiniteElementStd::CalCoefLaplaceMultiphase(int phase, int ip) { - ip = ip; //OK411 + ip = ip; // OK411 int i = 0; double mat_fac = 1.0; @@ -2647,56 +2588,56 @@ void CFiniteElementStd::CalCoefLaplaceMultiphase(int phase, int ip) // static double Hn[9],z[9]; int Index = MeshElement->GetIndex(); double k_rel; - ComputeShapefct(1); // 12.3.2007 WW + ComputeShapefct(1); // 12.3.2007 WW // For nodal value interpolation //====================================================================== - switch(PcsType) + switch (PcsType) { - default: - break; + default: + break; - case EPT_TWOPHASE_FLOW: // Two-phase flow - // PCH Rewriting... - // PCH Laplace mat_fac is accounted for two phases here. - // thought to be related to the reference pressure. - tensor = MediaProp->PermeabilityTensor(Index); - if(pcs->pcs_type_number == 0) - { + case EPT_TWOPHASE_FLOW: // Two-phase flow + // PCH Rewriting... // PCH Laplace mat_fac is accounted for two phases here. // thought to be related to the reference pressure. - double mat_fac = 0.0; + tensor = MediaProp->PermeabilityTensor(Index); + if (pcs->pcs_type_number == 0) + { + // PCH Laplace mat_fac is accounted for two phases here. + // thought to be related to the reference pressure. + double mat_fac = 0.0; - idxS = cpl_pcs->GetNodeValueIndex("SATURATION2"); + idxS = cpl_pcs->GetNodeValueIndex("SATURATION2"); - for(i = 0; i < nnodes; i++) - NodalVal_Sat[i] = cpl_pcs->GetNodeValue(nodes[i],idxS + 1); - Sw = 1.0 - interpolate(NodalVal_Sat); + for (i = 0; i < nnodes; i++) + NodalVal_Sat[i] = cpl_pcs->GetNodeValue(nodes[i], idxS + 1); + Sw = 1.0 - interpolate(NodalVal_Sat); - k_rel = MediaProp->PermeabilitySaturationFunction(Sw,phase); + k_rel = MediaProp->PermeabilitySaturationFunction(Sw, phase); - // Note here mat_fac is += meaning adding two phases - mat_fac = time_unit_factor * k_rel / mfp_vector[phase]->Viscosity(); + // Note here mat_fac is += meaning adding two phases + mat_fac = time_unit_factor * k_rel / mfp_vector[phase]->Viscosity(); - for(size_t i = 0; i < dim * dim; i++) - mat[i] = tensor[i] * mat_fac; - } - else if(pcs->pcs_type_number == 1) - { - int phase = pcs->pcs_type_number; + for (size_t i = 0; i < dim * dim; i++) + mat[i] = tensor[i] * mat_fac; + } + else if (pcs->pcs_type_number == 1) + { + int phase = pcs->pcs_type_number; - idxS = pcs->GetNodeValueIndex("SATURATION2"); - for(i = 0; i < nnodes; i++) - NodalVal_Sat[i] = pcs->GetNodeValue(nodes[i],idxS + 1); - Sw = 1.0 - interpolate(NodalVal_Sat); - k_rel = MediaProp->PermeabilitySaturationFunction(Sw,phase); + idxS = pcs->GetNodeValueIndex("SATURATION2"); + for (i = 0; i < nnodes; i++) + NodalVal_Sat[i] = pcs->GetNodeValue(nodes[i], idxS + 1); + Sw = 1.0 - interpolate(NodalVal_Sat); + k_rel = MediaProp->PermeabilitySaturationFunction(Sw, phase); - // Here only the second phase accounted. - mat_fac = time_unit_factor * k_rel / mfp_vector[phase]->Viscosity(); - for(size_t i = 0; i < dim * dim; i++) - mat[i] = tensor[i] * mat_fac; - } - break; + // Here only the second phase accounted. + mat_fac = time_unit_factor * k_rel / mfp_vector[phase]->Viscosity(); + for (size_t i = 0; i < dim * dim; i++) + mat[i] = tensor[i] * mat_fac; + } + break; } } @@ -2709,236 +2650,231 @@ void CFiniteElementStd::CalCoefLaplaceMultiphase(int phase, int ip) 02/2007 WW Implementation last modification: **************************************************************************/ -void CFiniteElementStd::CalCoefLaplace2(bool Gravity, int dof_index) +void CFiniteElementStd::CalCoefLaplace2(bool Gravity, int dof_index) { double* tensor = NULL; double mat_fac = 1.0, m_fac = 0.; - double fac_perm = 1.; //WX: factor for Permeability as funktion of pressure, strain, etc ... 05.2010 + double fac_perm = 1.; // WX: factor for Permeability as funktion of pressure, strain, etc ... 05.2010 double expfactor, D_gw, D_ga; expfactor = D_gw = D_ga = 0.0; - double dens_arg[3]; //08.05.2008 WW - bool diffusion = false; //08.05.2008 WW - if(MediaProp->heat_diffusion_model == 1 && cpl_pcs) + double dens_arg[3]; // 08.05.2008 WW + bool diffusion = false; // 08.05.2008 WW + if (MediaProp->heat_diffusion_model == 1 && cpl_pcs) diffusion = true; // dens_arg[1] = 293.15; // int Index = MeshElement->GetIndex(); - // CB_merge_0513 in case of het K, store local K in permeability_tensor - tensor = MediaProp->PermeabilityTensor(Index); - MediaProp->local_permeability = tensor[0]; + // CB_merge_0513 in case of het K, store local K in permeability_tensor + tensor = MediaProp->PermeabilityTensor(Index); + MediaProp->local_permeability = tensor[0]; // - ComputeShapefct(1); // 12.3.2007 WW + ComputeShapefct(1); // 12.3.2007 WW - //WX: 11.05.2010 + // WX: 11.05.2010 PG = interpolate(NodalVal1); PG2 = interpolate(NodalVal_p2); - //WX: cal factor for permeability 11.05.2010 + // WX: cal factor for permeability 11.05.2010 CFiniteElementStd* h_fem; h_fem = this; - if(MediaProp->permeability_pressure_model > 0) //01.09.2011. WW + if (MediaProp->permeability_pressure_model > 0) // 01.09.2011. WW fac_perm = MediaProp->PermeabilityFunctionPressure(Index, PG2); - if(MediaProp->permeability_strain_model > 0) //01.09.2011. WW - fac_perm *= MediaProp->PermeabilityFunctionStrain(Index,nnodes,h_fem); + if (MediaProp->permeability_strain_model > 0) // 01.09.2011. WW + fac_perm *= MediaProp->PermeabilityFunctionStrain(Index, nnodes, h_fem); //====================================================================== - for(size_t i = 0; i < dim * dim; i++) + for (size_t i = 0; i < dim * dim; i++) mat[i] = 0.0; const double Mw = MolarMass::Water; - switch(dof_index) + switch (dof_index) { - case 0: { - PG = interpolate(NodalVal1); - Sw = MediaProp->SaturationCapillaryPressureFunction(PG); - // - tensor = MediaProp->PermeabilityTensor(Index); - mat_fac = MediaProp->PermeabilitySaturationFunction(Sw,0) \ - / FluidProp->Viscosity(); - for(size_t i = 0; i < dim * dim; i++) - mat[i] = -tensor[i] * mat_fac * time_unit_factor * fac_perm; //WX:05.2010 - // For velocity caculation - if(!Gravity) + case 0: { - dens_arg[0] = PG; // Shdould be Pw in some cases - if(diffusion) + PG = interpolate(NodalVal1); + Sw = MediaProp->SaturationCapillaryPressureFunction(PG); + // + tensor = MediaProp->PermeabilityTensor(Index); + mat_fac = MediaProp->PermeabilitySaturationFunction(Sw, 0) / FluidProp->Viscosity(); + for (size_t i = 0; i < dim * dim; i++) + mat[i] = -tensor[i] * mat_fac * time_unit_factor * fac_perm; // WX:05.2010 + // For velocity caculation + if (!Gravity) { - TG = interpolate(NodalValC1) + PhysicalConstant::CelsiusZeroInKelvin; - dens_arg[1] = TG; + dens_arg[0] = PG; // Shdould be Pw in some cases + if (diffusion) + { + TG = interpolate(NodalValC1) + PhysicalConstant::CelsiusZeroInKelvin; + dens_arg[1] = TG; + } + // + rhow = FluidProp->Density(dens_arg); + poro = MediaProp->Porosity(Index, pcs->m_num->ls_theta); + PG2 = interpolate(NodalVal_p2); + dens_arg[0] = PG2; + // + if (diffusion) + { + tort = MediaProp->TortuosityFunction(Index, unit, pcs->m_num->ls_theta); + tort *= MediaProp->base_heat_diffusion_coefficient * (1 - Sw) * poro + * pow(TG / PhysicalConstant::CelsiusZeroInKelvin, 1.8); + expfactor = 1.0 / (rhow * SpecificGasConstant::WaterVapour * TG); + rho_gw = FluidProp->vaporDensity(TG) * exp(-PG * expfactor); + p_gw = rho_gw * SpecificGasConstant::WaterVapour * TG; + dens_arg[0] -= p_gw; + } + // + rho_ga = GasProp->Density(dens_arg); + // + if (diffusion) + { + rho_g = rho_ga + rho_gw; + // 1/Mg + M_g = (rho_gw / Mw + rho_ga / GasProp->molar_mass) / rho_g; + D_gw = tort * rho_g * Mw * GasProp->molar_mass * M_g * M_g / rhow; + D_gw *= rho_gw / (rhow * PG2); + for (size_t i = 0; i < dim; i++) + mat[i * dim + i] -= D_gw * time_unit_factor; + } } - // - rhow = FluidProp->Density(dens_arg); - poro = MediaProp->Porosity(Index,pcs->m_num->ls_theta); - PG2 = interpolate(NodalVal_p2); - dens_arg[0] = PG2; - // - if(diffusion) + break; + } + case 1: + if (Gravity) { - tort = MediaProp->TortuosityFunction(Index, - unit, - pcs->m_num->ls_theta); - tort *= MediaProp->base_heat_diffusion_coefficient * (1 - Sw) * poro - * pow(TG / PhysicalConstant::CelsiusZeroInKelvin, 1.8); - expfactor = 1.0 / (rhow * SpecificGasConstant::WaterVapour * TG); - rho_gw = FluidProp->vaporDensity(TG) * exp(-PG * expfactor); - p_gw = rho_gw * SpecificGasConstant::WaterVapour * TG; - dens_arg[0] -= p_gw; + PG = interpolate(NodalVal1); + PG2 = interpolate(NodalVal_p2); + Sw = MediaProp->SaturationCapillaryPressureFunction(PG); + dens_arg[0] = PG; // Shdould be Pw in some cases + if (diffusion) + { + TG = interpolate(NodalValC1) + PhysicalConstant::CelsiusZeroInKelvin; + dens_arg[1] = TG; + } + // Liquid density + rhow = FluidProp->Density(dens_arg); + dens_arg[0] = PG2; + rho_gw = 0.0; + if (diffusion) + { + expfactor = 1.0 / (rhow * SpecificGasConstant::WaterVapour * TG); + rho_gw = FluidProp->vaporDensity(TG) * exp(-PG * expfactor); + p_gw = rho_gw * SpecificGasConstant::WaterVapour * TG; + dens_arg[0] -= p_gw; + } + rho_ga = GasProp->Density(dens_arg); + rho_g = rho_ga + rho_gw; } + tensor = MediaProp->PermeabilityTensor(Index); + mat_fac = MediaProp->PermeabilitySaturationFunction(Sw, 0) / FluidProp->Viscosity(); + m_fac = 0.; + if (diffusion) + m_fac = rho_gw * MediaProp->PermeabilitySaturationFunction(Sw, 1) / (GasProp->Viscosity() * rhow); + if (Gravity) + mat_fac = mat_fac + m_fac * rho_g / rhow; + else + mat_fac += m_fac; // - rho_ga = GasProp->Density(dens_arg); + for (size_t i = 0; i < dim * dim; i++) + mat[i] = tensor[i] * mat_fac * time_unit_factor * fac_perm; // WX:05.2010 // - if(diffusion) + if ((!Gravity) && diffusion) { - rho_g = rho_ga + rho_gw; - // 1/Mg - M_g = (rho_gw / Mw + rho_ga / GasProp->molar_mass) / rho_g; - D_gw = tort * rho_g * Mw * GasProp->molar_mass * M_g * M_g / rhow; - D_gw *= rho_gw / (rhow * PG2); - for(size_t i = 0; i < dim; i++) - mat[i * dim + i] -= D_gw * time_unit_factor; + D_gw = tort * Mw * GasProp->molar_mass * M_g * M_g * rho_g / rhow; + D_gw *= time_unit_factor * p_gw / (PG2 * PG2); + for (size_t i = 0; i < dim; i++) + mat[i * dim + i] -= D_gw; } - } - break; - } - case 1: - if(Gravity) - { - PG = interpolate(NodalVal1); - PG2 = interpolate(NodalVal_p2); - Sw = MediaProp->SaturationCapillaryPressureFunction(PG); - dens_arg[0] = PG; // Shdould be Pw in some cases - if(diffusion) + break; + case 2: + if (diffusion) { - TG = interpolate(NodalValC1) + PhysicalConstant::CelsiusZeroInKelvin; - dens_arg[1] = TG; + D_ga = tort * Mw * GasProp->molar_mass * M_g * M_g * rho_g / rhow; + D_ga *= time_unit_factor * rho_gw / (PG2 * rhow); } - // Liquid density - rhow = FluidProp->Density(dens_arg); + else + D_ga = 0.; + for (size_t i = 0; i < dim; i++) + mat[i * dim + i] = D_ga; + break; + case 3: + // WX: for Cal_Velocity, rho_ga muss be calculated again before used. 11.05.2010 dens_arg[0] = PG2; - rho_gw = 0.0; - if(diffusion) + rho_ga = GasProp->Density(dens_arg); + // + tensor = MediaProp->PermeabilityTensor(Index); + mat_fac = rho_ga * MediaProp->PermeabilitySaturationFunction(Sw, 1) / (GasProp->Viscosity() * rhow); + // + if (Gravity) + // mat_fac *= rhow/rho_ga; + mat_fac *= rho_ga / rhow; // 29.04.2009 WW + // + for (size_t i = 0; i < dim * dim; i++) + mat[i] = tensor[i] * mat_fac * time_unit_factor * fac_perm; // WX:05.2010 + if ((!Gravity) && diffusion) { - expfactor = 1.0 / (rhow * SpecificGasConstant::WaterVapour * TG); - rho_gw = FluidProp->vaporDensity(TG) * exp(-PG * expfactor); - p_gw = rho_gw * SpecificGasConstant::WaterVapour * TG; - dens_arg[0] -= p_gw; + D_ga = tort * rho_g * Mw * GasProp->molar_mass * M_g * M_g / rhow; + D_ga *= p_gw / (PG2 * PG2); + for (size_t i = 0; i < dim; i++) + mat[i * dim + i] += D_ga * time_unit_factor; } - rho_ga = GasProp->Density(dens_arg); - rho_g = rho_ga + rho_gw; - } - tensor = MediaProp->PermeabilityTensor(Index); - mat_fac = MediaProp->PermeabilitySaturationFunction(Sw,0) \ - / FluidProp->Viscosity(); - m_fac = 0.; - if(diffusion) - m_fac = rho_gw * MediaProp->PermeabilitySaturationFunction(Sw,1) \ - / (GasProp->Viscosity() * rhow); - if(Gravity) - mat_fac = mat_fac + m_fac * rho_g / rhow; - else - mat_fac += m_fac; - // - for(size_t i = 0; i < dim * dim; i++) - mat[i] = tensor[i] * mat_fac * time_unit_factor * fac_perm; //WX:05.2010 - // - if((!Gravity) && diffusion) - { - D_gw = tort * Mw * GasProp->molar_mass * M_g * M_g * rho_g / rhow; - D_gw *= time_unit_factor * p_gw / (PG2 * PG2); - for(size_t i = 0; i < dim; i++) - mat[i * dim + i] -= D_gw; - } - break; - case 2: - if(diffusion) - { - D_ga = tort * Mw * GasProp->molar_mass * M_g * M_g * rho_g / rhow; - D_ga *= time_unit_factor * rho_gw / (PG2 * rhow); - } - else - D_ga = 0.; - for(size_t i = 0; i < dim; i++) - mat[i * dim + i] = D_ga; - break; - case 3: - //WX: for Cal_Velocity, rho_ga muss be calculated again before used. 11.05.2010 - dens_arg[0] = PG2; - rho_ga = GasProp->Density(dens_arg); - // - tensor = MediaProp->PermeabilityTensor(Index); - mat_fac = rho_ga * MediaProp->PermeabilitySaturationFunction(Sw,1) \ - / (GasProp->Viscosity() * rhow); - // - if(Gravity) - // mat_fac *= rhow/rho_ga; - mat_fac *= rho_ga / rhow; //29.04.2009 WW - // - for(size_t i = 0; i < dim * dim; i++) - mat[i] = tensor[i] * mat_fac * time_unit_factor * fac_perm; //WX:05.2010 - if((!Gravity) && diffusion) - { - D_ga = tort * rho_g * Mw * GasProp->molar_mass * M_g * M_g / rhow; - D_ga *= p_gw / (PG2 * PG2); - for(size_t i = 0; i < dim; i++) - mat[i * dim + i] += D_ga * time_unit_factor; - } - break; - //------------------------------------------------------------------ + break; + //------------------------------------------------------------------ } } /////// /************************************************************************** FEMLib-Method: - Task: Calculate material coefficient for the Laplace matrix for - MULTI COMPONENTIAL FLOW Global Approach + Task: Calculate material coefficient for the Laplace matrix for + MULTI COMPONENTIAL FLOW Global Approach Implementaion: - 03/2011 AKS + 03/2011 AKS **************************************************************************/ void CFiniteElementStd::CalCoefLaplaceMCF(int ip) { - const int nDF=pcs->dof; + const int nDF = pcs->dof; const int Index = MeshElement->GetIndex(); double* tensor = NULL; double arg_PV[6]; poro = MediaProp->Porosity(Index, pcs->m_num->ls_theta); ComputeShapefct(1); - assert(nDF<=6); - for(int i = 0; iDensity(arg_PV); - for(int in = 0; in < nDF*nDF; in++) + for (int in = 0; in < nDF * nDF; in++) { - for(size_t k = 0; k < dim*dim; k++) + for (size_t k = 0; k < dim * dim; k++) { LaplaceMatrixElements[in][k] = 0.0; } } tensor = MediaProp->DispersionTensorMCF(ip, 0, 0, arg_PV); - for(size_t k = 0; k < dim; k++) + for (size_t k = 0; k < dim; k++) { - LaplaceMatrixElements[0][k*dim + k] = tensor[k*dim + k]*rho; + LaplaceMatrixElements[0][k * dim + k] = tensor[k * dim + k] * rho; } tensor = MediaProp->DispersionTensorMCF(ip, 1, 0, arg_PV); - for(size_t k = 0; k < dim; k++) + for (size_t k = 0; k < dim; k++) { - LaplaceMatrixElements[nDF + 1][k*dim + k] = tensor[k*dim + k]; + LaplaceMatrixElements[nDF + 1][k * dim + k] = tensor[k * dim + k]; } - if(FluidProp->cmpN > 0) + if (FluidProp->cmpN > 0) { - for(int CIndex = 2; CIndex < FluidProp->cmpN + 2; CIndex++) + for (int CIndex = 2; CIndex < FluidProp->cmpN + 2; CIndex++) { tensor = MediaProp->DispersionTensorMCF(ip, 2, CIndex, arg_PV); - for(size_t k = 0; k < dim; k++) + for (size_t k = 0; k < dim; k++) { - LaplaceMatrixElements[(nDF + 1)*CIndex][k*dim + k] = tensor[k*dim + k]*rho; + LaplaceMatrixElements[(nDF + 1) * CIndex][k * dim + k] = tensor[k * dim + k] * rho; } } -} - + } } /************************************************************************** FEMLib-Method: @@ -2948,141 +2884,144 @@ void CFiniteElementStd::CalCoefLaplaceMCF(int ip) 03/2009 PCH Implementation last modification: **************************************************************************/ -void CFiniteElementStd::CalCoefLaplacePSGLOBAL(bool Gravity, int dof_index) +void CFiniteElementStd::CalCoefLaplacePSGLOBAL(bool Gravity, int dof_index) { double* tensor = NULL; - double mat_fac = 1.0; //OK411 m_fac=0.; + double mat_fac = 1.0; // OK411 m_fac=0.; double k_rel = 0.0; double mfp_arg[2]; - double variables[3]; + double variables[3]; int Index = MeshElement->GetIndex(); // - ComputeShapefct(1); // 12.3.2007 WW + ComputeShapefct(1); // 12.3.2007 WW //====================================================================== - for(size_t i = 0; i < dim * dim; i++) + for (size_t i = 0; i < dim * dim; i++) mat[i] = 0.0; - switch(dof_index) + switch (dof_index) { - case 0: - tensor = MediaProp->PermeabilityTensor(Index); - if(pcs->m_num->ele_upwinding == 1) - { - // Doing Upwind elements for saturation by divergent of pressure. - // Pw upwind - int WhichNode = UpwindElement((int)(pcs->m_num->ele_upwind_method), 0); - Sw = 1.0 - NodalVal_SatNW[WhichNode]; - } - else - Sw = 1.0 - interpolate(NodalVal_SatNW); - k_rel = MediaProp->PermeabilitySaturationFunction(Sw,0); - - // CB_merge_0513 - variables[0] = interpolate(NodalVal1); // pressure - variables[1] = interpolate(NodalValC); // temperature - - mat_fac = k_rel / FluidProp->Viscosity(variables); - //mat_fac = k_rel / FluidProp->Viscosity(); - // Since gravity for water phase is handled directly in Assemble_Gravity, - // no need of any code for water phase here. - for(size_t i = 0; i < dim * dim; i++) - mat[i] = tensor[i] * mat_fac * time_unit_factor; - break; - case 1: - tensor = MediaProp->PermeabilityTensor(Index); - mat_fac = 0.0; // Snw has no laplace term - for(size_t i = 0; i < dim * dim; i++) - mat[i] = tensor[i] * mat_fac * time_unit_factor; - break; - case 2: - tensor = MediaProp->PermeabilityTensor(Index); - if(pcs->m_num->ele_upwinding == 1) - { - // Doing Upwind elements for saturation by divergent of pressure. - // Pnw upwind - int WhichNode = UpwindElement((int)(pcs->m_num->ele_upwind_method), 0); - Sw = 1.0 - NodalVal_SatNW[WhichNode]; - } - else - Sw = 1.0 - interpolate(NodalVal_SatNW); + case 0: + tensor = MediaProp->PermeabilityTensor(Index); + if (pcs->m_num->ele_upwinding == 1) + { + // Doing Upwind elements for saturation by divergent of pressure. + // Pw upwind + int WhichNode = UpwindElement((int)(pcs->m_num->ele_upwind_method), 0); + Sw = 1.0 - NodalVal_SatNW[WhichNode]; + } + else + Sw = 1.0 - interpolate(NodalVal_SatNW); + k_rel = MediaProp->PermeabilitySaturationFunction(Sw, 0); + + // CB_merge_0513 + variables[0] = interpolate(NodalVal1); // pressure + variables[1] = interpolate(NodalValC); // temperature + + mat_fac = k_rel / FluidProp->Viscosity(variables); + // mat_fac = k_rel / FluidProp->Viscosity(); + // Since gravity for water phase is handled directly in Assemble_Gravity, + // no need of any code for water phase here. + for (size_t i = 0; i < dim * dim; i++) + mat[i] = tensor[i] * mat_fac * time_unit_factor; + break; + case 1: + tensor = MediaProp->PermeabilityTensor(Index); + mat_fac = 0.0; // Snw has no laplace term + for (size_t i = 0; i < dim * dim; i++) + mat[i] = tensor[i] * mat_fac * time_unit_factor; + break; + case 2: + tensor = MediaProp->PermeabilityTensor(Index); + if (pcs->m_num->ele_upwinding == 1) + { + // Doing Upwind elements for saturation by divergent of pressure. + // Pnw upwind + int WhichNode = UpwindElement((int)(pcs->m_num->ele_upwind_method), 0); + Sw = 1.0 - NodalVal_SatNW[WhichNode]; + } + else + Sw = 1.0 - interpolate(NodalVal_SatNW); - k_rel = MediaProp->PermeabilitySaturationFunction(Sw,1); - // Pnw = Pw + Pc(Sw) //TODO: could cause errors in some cases - mfp_arg[0] = interpolate(NodalVal1) + MediaProp->CapillaryPressureFunction(Sw); - mfp_arg[1] = interpolate(NodalValC1); // TEMPERATURE1 in most cases + k_rel = MediaProp->PermeabilitySaturationFunction(Sw, 1); + // Pnw = Pw + Pc(Sw) //TODO: could cause errors in some cases + mfp_arg[0] = interpolate(NodalVal1) + MediaProp->CapillaryPressureFunction(Sw); + mfp_arg[1] = interpolate(NodalValC1); // TEMPERATURE1 in most cases - mat_fac = k_rel / GasProp->Viscosity(mfp_arg); + mat_fac = k_rel / GasProp->Viscosity(mfp_arg); - // The density of the non-wetting phase fluid should be considered here. - // However, the default water phase density should be canceled out simultaneously. - if(Gravity) - mat_fac *= GasProp->Density() / FluidProp->Density(); + // The density of the non-wetting phase fluid should be considered here. + // However, the default water phase density should be canceled out simultaneously. + if (Gravity) + mat_fac *= GasProp->Density() / FluidProp->Density(); - for(size_t i = 0; i < dim * dim; i++) - mat[i] = tensor[i] * mat_fac * time_unit_factor; - break; - case 3: - // Snw Laplace from Pc in Eqn 2 - tensor = MediaProp->PermeabilityTensor(Index); + for (size_t i = 0; i < dim * dim; i++) + mat[i] = tensor[i] * mat_fac * time_unit_factor; + break; + case 3: + // Snw Laplace from Pc in Eqn 2 + tensor = MediaProp->PermeabilityTensor(Index); - if(pcs->num_type_name.find("dPcdSwGradSnw") != string::npos) - { -// double Snw = -1.0; -// if(pcs->m_num->ele_upwinding == 1) -// { + if (pcs->num_type_name.find("dPcdSwGradSnw") != string::npos) + { + // double Snw = -1.0; + // if(pcs->m_num->ele_upwinding == 1) + // { // Doing Upwind elements for saturation by divergent of pressure. // Pnw upwind -// int WhichNode = UpwindElement((int)(pcs->m_num->ele_upwind_method), 1); // TF: set, but never used -// Snw = NodalVal_SatNW[WhichNode]; // TF: set, but never used -// } -// else -// Snw = interpolate(NodalVal_SatNW); // TF: set, but never used - - CMediumProperties* m_mmp = NULL; - CElem* thisEle = pcs->m_msh->ele_vector[index]; - int matgrp = thisEle->GetPatchIndex(); - m_mmp = mmp_vector[matgrp]; - k_rel = MediaProp->PermeabilitySaturationFunction(Sw,1); - - double dPcdSw = 0.0; - dPcdSw = m_mmp->PressureSaturationDependency(Sw,false); - - // Pnw = Pw + Pc(Sw) // TODO: could cause errors in some cases - mfp_arg[0] = interpolate(NodalVal1) + MediaProp->CapillaryPressureFunction(Sw); - mfp_arg[1] = interpolate(NodalValC1); - mat_fac = k_rel / GasProp->Viscosity(mfp_arg) * (-dPcdSw); - } - else - mat_fac = 0.0; + // int WhichNode = UpwindElement((int)(pcs->m_num->ele_upwind_method), 1); // TF: set, but + // never + // used + // Snw = NodalVal_SatNW[WhichNode]; // TF: set, but never used + // } + // else + // Snw = interpolate(NodalVal_SatNW); // TF: set, but never used - for(size_t i = 0; i < dim * dim; i++) - mat[i] = tensor[i] * mat_fac * time_unit_factor; - break; - case 4: - // For Vnw - tensor = MediaProp->PermeabilityTensor(Index); + CMediumProperties* m_mmp = NULL; + CElem* thisEle = pcs->m_msh->ele_vector[index]; + int matgrp = thisEle->GetPatchIndex(); + m_mmp = mmp_vector[matgrp]; + k_rel = MediaProp->PermeabilitySaturationFunction(Sw, 1); + + double dPcdSw = 0.0; + dPcdSw = m_mmp->PressureSaturationDependency(Sw, false); + + // Pnw = Pw + Pc(Sw) // TODO: could cause errors in some cases + mfp_arg[0] = interpolate(NodalVal1) + MediaProp->CapillaryPressureFunction(Sw); + mfp_arg[1] = interpolate(NodalValC1); + mat_fac = k_rel / GasProp->Viscosity(mfp_arg) * (-dPcdSw); + } + else + mat_fac = 0.0; -// double Snw = -1.0; -// if(pcs->m_num->ele_upwinding == 1) -// { + for (size_t i = 0; i < dim * dim; i++) + mat[i] = tensor[i] * mat_fac * time_unit_factor; + break; + case 4: + // For Vnw + tensor = MediaProp->PermeabilityTensor(Index); + + // double Snw = -1.0; + // if(pcs->m_num->ele_upwinding == 1) + // { // Doing Upwind elements for saturation by divergent of pressure. // Pnw upwind -// int WhichNode = UpwindElement((int)(pcs->m_num->ele_upwind_method), 1); // TF: set, but never used -// Snw = NodalVal_SatNW[WhichNode]; // TF: set, but never used -// } -// else -// Snw = interpolate(NodalVal_SatNW); // TF: set, but never used - -// CElem* thisEle = pcs->m_msh->ele_vector[index]; // TF: set, but never used -// int matgrp = thisEle->GetPatchIndex(); // TF: set, but never used -// CMediumProperties* m_mmp = mmp_vector[matgrp]; - k_rel = MediaProp->PermeabilitySaturationFunction(Sw,1); - mat_fac = k_rel / GasProp->Viscosity(); - - for(size_t i = 0; i < dim * dim; i++) - mat[i] = tensor[i] * mat_fac * time_unit_factor; - break; - //------------------------------------------------------------------ + // int WhichNode = UpwindElement((int)(pcs->m_num->ele_upwind_method), 1); // TF: set, but never + // used + // Snw = NodalVal_SatNW[WhichNode]; // TF: set, but never used + // } + // else + // Snw = interpolate(NodalVal_SatNW); // TF: set, but never used + + // CElem* thisEle = pcs->m_msh->ele_vector[index]; // TF: set, but never used + // int matgrp = thisEle->GetPatchIndex(); // TF: set, but never used + // CMediumProperties* m_mmp = mmp_vector[matgrp]; + k_rel = MediaProp->PermeabilitySaturationFunction(Sw, 1); + mat_fac = k_rel / GasProp->Viscosity(); + + for (size_t i = 0; i < dim * dim; i++) + mat[i] = tensor[i] * mat_fac * time_unit_factor; + break; + //------------------------------------------------------------------ } } /************************************************************************** @@ -3104,44 +3043,45 @@ void CFiniteElementStd::CalCoefLaplacePSGLOBAL(bool Gravity, int dof_index) **************************************************************************/ int CFiniteElementStd::UpwindElement(int option, int phase) { - int WhichNodeInTheElement = -1; // Initialized to be none of elements - double Pmin = 1.0 / DBL_MIN; // Just set to be outrageously big. - int GravityOn = 1; // Initialized to be on + int WhichNodeInTheElement = -1; // Initialized to be none of elements + double Pmin = 1.0 / DBL_MIN; // Just set to be outrageously big. + int GravityOn = 1; // Initialized to be on // If no gravity, then set GravityOn to be zero. - if((coordinate_system) % 10 != 2 && (!axisymmetry)) + if ((coordinate_system) % 10 != 2 && (!axisymmetry)) GravityOn = 0; - if(option == 1) // If upwind by divergent of pressure + if (option == 1) // If upwind by divergent of pressure { double PdivAtnode = -1.0 / DBL_MIN; // Meaningless pressure. - double Pc = 0.0; // Set to be no capillary at all. + double Pc = 0.0; // Set to be no capillary at all. int idx_p1 = pcs->GetNodeValueIndex("PRESSURE1"); int idx_pc = pcs->GetNodeValueIndex("PRESSURE_CAP"); - for(int i = 0; i < nnodes; ++i) + for (int i = 0; i < nnodes; ++i) { - double Pw = pcs->GetNodeValue(nodes[i],idx_p1 + 1); - if(phase == 0) + double Pw = pcs->GetNodeValue(nodes[i], idx_p1 + 1); + if (phase == 0) { PdivAtnode = Pw; - if(GravityOn) + if (GravityOn) PdivAtnode -= FluidProp->Density() * gravity_constant; } - else if(phase == 1) + else if (phase == 1) { - Pc = pcs->GetNodeValue(nodes[i],idx_pc); + Pc = pcs->GetNodeValue(nodes[i], idx_pc); PdivAtnode = Pw + Pc; - if(GravityOn) + if (GravityOn) PdivAtnode -= GasProp->Density() * gravity_constant; } else { - std::cout << "Phase number is wrong in UpwindElement." << "\n"; + std::cout << "Phase number is wrong in UpwindElement." + << "\n"; abort(); } - if(Pmin > PdivAtnode) + if (Pmin > PdivAtnode) { Pmin = PdivAtnode; WhichNodeInTheElement = i; @@ -3149,15 +3089,16 @@ int CFiniteElementStd::UpwindElement(int option, int phase) } } - if(WhichNodeInTheElement == -1) + if (WhichNodeInTheElement == -1) { - std::cout << "UpwindElement is failed. Impossible node index!!!" << "\n"; + std::cout << "UpwindElement is failed. Impossible node index!!!" + << "\n"; std::cout << "Pmin = " << Pmin << "\n"; abort(); } return WhichNodeInTheElement; } -//CB 090507 +// CB 090507 /************************************************************************** FEMLib-Method: Task: @@ -3165,10 +3106,10 @@ int CFiniteElementStd::UpwindElement(int option, int phase) 05/2007 CB last modification: **************************************************************************/ -//void CFiniteElementStd::UpwindUnitCoord(int p, int point, int ind, double *rupw, double *supw, double *tupw) +// void CFiniteElementStd::UpwindUnitCoord(int p, int point, int ind, double *rupw, double *supw, double *tupw) void CFiniteElementStd::UpwindUnitCoord(int p, int point, int ind) { - p = p; //OK411 + p = p; // OK411 double scale; double alpha[3]; int gp_r, gp_s, gp_t; @@ -3180,7 +3121,7 @@ void CFiniteElementStd::UpwindUnitCoord(int p, int point, int ind) // ElementValue* gp_ele = ele_gp_value[ind]; - if(pcs->pcs_type_number == 1) //WW/CB + if (pcs->pcs_type_number == 1) // WW/CB gp_ele = ele_gp_value[ind + (long)pcs->m_msh->ele_vector.size()]; // TF unused: MshElemType::type eletyp = MeshElement->GetElementType(); @@ -3195,18 +3136,18 @@ void CFiniteElementStd::UpwindUnitCoord(int p, int point, int ind) // alpha initialisieren MNulleVec(alpha, 3); // v initialisieren - MNulleVec(v,3); + MNulleVec(v, 3); // get the velocities - //gp_ele->GetEleVelocity(v); + // gp_ele->GetEleVelocity(v); // CB: not sure if this is correct, as velocity // at each Gauss point is regarded here (within GP loop) // while in cel_mmp.cpp velocity is evaluated before the GP loop: // CalcVelo3Drst(phase, index, GetTimeCollocationupwind_MMP(), 0., 0., 0., v); - //v[0] = gp_ele->Velocity(0, point); - //v[1] = gp_ele->Velocity(1, point); - //v[2] = gp_ele->Velocity(2, point); + // v[0] = gp_ele->Velocity(0, point); + // v[1] = gp_ele->Velocity(1, point); + // v[2] = gp_ele->Velocity(2, point); v[0] = gp_ele->Velocity(0, 0); v[1] = gp_ele->Velocity(1, 0); v[2] = gp_ele->Velocity(2, 0); @@ -3216,7 +3157,7 @@ void CFiniteElementStd::UpwindUnitCoord(int p, int point, int ind) // when mass matrix is assembled // hence V is at element center of gravity // otherwise use element averaged v?: - //for(i=0; iVelocity(0, i)/(double)nGaussPoints; // v[1] += gp_ele->Velocity(1, i)/(double)nGaussPoints; @@ -3226,8 +3167,8 @@ void CFiniteElementStd::UpwindUnitCoord(int p, int point, int ind) for (size_t i = 0; i < 3; i++) v[i] *= time_unit_factor; - //instead of r_upw, etc. we use unit[i], next function sets Gauss Integrals - //unit[0] = MXPGaussPkt(nGauss, gp_r); -> r_upw ; etc. for unit[i] + // instead of r_upw, etc. we use unit[i], next function sets Gauss Integrals + // unit[0] = MXPGaussPkt(nGauss, gp_r); -> r_upw ; etc. for unit[i] SetGaussPoint(point, gp_r, gp_s, gp_t); // this sets unit[] to standard coordinates // v transformation: Jacobi*v-->v_rst @@ -3249,44 +3190,41 @@ void CFiniteElementStd::UpwindUnitCoord(int p, int point, int ind) // // These need to be rewritten according to different types of elements. // PCH - if(MBtrgVec(v_rst, ele_dim) > MKleinsteZahl) + if (MBtrgVec(v_rst, ele_dim) > MKleinsteZahl) { // Upwind-Faktoren - for(size_t i = 0; i < ele_dim; i++) - alpha[i] = -upwind_para * v_rst[i] / - (MBtrgVec(v_rst, ele_dim) + MKleinsteZahl); + for (size_t i = 0; i < ele_dim; i++) + alpha[i] = -upwind_para * v_rst[i] / (MBtrgVec(v_rst, ele_dim) + MKleinsteZahl); // moving the Gauss points - if (upwind_meth == 1) // limit Gauss point moving on Element domain + if (upwind_meth == 1) // limit Gauss point moving on Element domain { scale = 1.; - for(size_t i = 0; i < ele_dim; i++) + for (size_t i = 0; i < ele_dim; i++) { // Integral over GaussPoints, not used if (mmp_element_integration_method_maximum) { if (fabs(unit[i] + alpha[i]) > 1.) - scale = - MMin(scale, - (1. - fabs(unit[i])) / fabs(alpha[i])); + scale = MMin(scale, (1. - fabs(unit[i])) / fabs(alpha[i])); } else // regard all quantities in the center of element - if (fabs(alpha[i]) > 1.) - scale = MMin(scale, (1. / fabs(alpha[i])) ); + if (fabs(alpha[i]) > 1.) + scale = MMin(scale, (1. / fabs(alpha[i]))); } - for(size_t i = 0; i < ele_dim; i++) + for (size_t i = 0; i < ele_dim; i++) { // Integral over GaussPoints, not used if (mmp_element_integration_method_maximum) - unit[i] += scale * alpha[i]; // scale is added to unit[i] (=Gaussintegral) + unit[i] += scale * alpha[i]; // scale is added to unit[i] (=Gaussintegral) else // regard all quantities in the center of element - unit[i] = scale * alpha[i]; // unit[i] (=Gaussintegral) + unit[i] = scale * alpha[i]; // unit[i] (=Gaussintegral) } } else if (upwind_meth == 2) // limit moving on -1 MKleinsteZahl) + // hier nur Methoden 1 + 2; 3 wird in CalcCoefLaplace erledigt + if ((upwind_meth == 1) || (upwind_meth == 2)) { - if (MSkalarprodukt(v, l, 3) > 0.) - // CB VZ ge?dert!!! - *rupw = MRange(-1., -upwind_para, 1.); - //*rupw = MRange(-1., upwind_para , 1.); - else - // CB VZ ge?dert!!! + if (MBtrgVec(v, 3) > MKleinsteZahl) + { + if (MSkalarprodukt(v, l, 3) > 0.) + // CB VZ ge?dert!!! + *rupw = MRange(-1., -upwind_para, 1.); + //*rupw = MRange(-1., upwind_para , 1.); + else + // CB VZ ge?dert!!! + *rupw = MRange(-1., upwind_para, 1.); + //*rupw = MRange(-1., -upwind_para , 1.); // + } + // else { // test + // cout << "-vau"; + // if (MSkalarprodukt(v, l, 3) > 0.) + // *rupw = MRange(-1., upwind_para , 1.); + // else + // *rupw = MRange(-1., -upwind_para , 1.); + //} + if (aktueller_zeitschritt == 1) // test *rupw = MRange(-1., upwind_para, 1.); - //*rupw = MRange(-1., -upwind_para , 1.); // - } - //else { // test - // cout << "-vau"; - // if (MSkalarprodukt(v, l, 3) > 0.) - // *rupw = MRange(-1., upwind_para , 1.); - // else - // *rupw = MRange(-1., -upwind_para , 1.); - //} - if(aktueller_zeitschritt == 1) // test - *rupw = MRange(-1., upwind_para, 1.); - } - // Upwind-Faktor Fully upwinding - } - break; - case 2: // Quadrilateral - { - // Elementgeometriedaten - static double detjac, * invjac, jacobi[4]; - // Elementdaten - static double v_rs[2]; - // Initialisieren - MNulleVec(v_rs,2); - - //if (mmp_element_integration_method_maximum) ?? CB: was ist das - if(1 > 0) - { - gp_r = (int)(point / nGauss); - gp_s = point % nGauss; - ur = MXPGaussPkt(nGauss, gp_r); - us = MXPGaussPkt(nGauss, gp_s); + } + // Upwind-Faktor Fully upwinding } - else + break; + case 2: // Quadrilateral { - ur = 0.0; // Alle Groessen nur in Elementmitte betrachten - us = 0.0; // Alle Groessen nur in Elementmitte betrachten - } + // Elementgeometriedaten + static double detjac, *invjac, jacobi[4]; + // Elementdaten + static double v_rs[2]; + // Initialisieren + MNulleVec(v_rs, 2); - // Geschwindigkeitstransformation: a,b -> r,s - //Calc2DElementJacobiMatrix(ind, 0., 0., invjac, &detjac); - detjac = computeJacobian(1); // order - invjac = invJacobian; - MKopierVec(invjac, jacobi, 4); - M2Invertiere(jacobi); // Jacobi-Matrix - MMultMatVec(jacobi, 2, 2, v, 2, v_rs, 2); + // if (mmp_element_integration_method_maximum) ?? CB: was ist das + if (1 > 0) + { + gp_r = (int)(point / nGauss); + gp_s = point % nGauss; + ur = MXPGaussPkt(nGauss, gp_r); + us = MXPGaussPkt(nGauss, gp_s); + } + else + { + ur = 0.0; // Alle Groessen nur in Elementmitte betrachten + us = 0.0; // Alle Groessen nur in Elementmitte betrachten + } - if(MBtrgVec(v_rs, 2) > MKleinsteZahl) - // Upwind-Faktoren - for(k = 0; k < 2; k++) - alpha[k] = -upwind_para * v_rs[k] / - (MBtrgVec(v_rs, 2) + MKleinsteZahl); + // Geschwindigkeitstransformation: a,b -> r,s + // Calc2DElementJacobiMatrix(ind, 0., 0., invjac, &detjac); + detjac = computeJacobian(1); // order + invjac = invJacobian; + MKopierVec(invjac, jacobi, 4); + M2Invertiere(jacobi); // Jacobi-Matrix + MMultMatVec(jacobi, 2, 2, v, 2, v_rs, 2); - //hier nur Methoden 1 + 2; 3 wird in CalcCoefLaplace erledigt - if (upwind_meth == 1) - { - // Verschiebungen der Gausspunkte auf Element begrenzen - scale = 1.; - if (fabs(ur + alpha[0]) > 1.) - scale = MMin(scale, (1. - fabs(ur)) / fabs(alpha[0])); - if (fabs(us + alpha[1]) > 1.) - scale = MMin(scale, (1. - fabs(us)) / fabs(alpha[1])); - *rupw = ur + scale * alpha[0]; - *supw = us + scale * alpha[1]; - } - else if (upwind_meth == 2) - { - // Verschiebungen auf -1 MKleinsteZahl) + // Upwind-Faktoren + for (k = 0; k < 2; k++) + alpha[k] = -upwind_para * v_rs[k] / (MBtrgVec(v_rs, 2) + MKleinsteZahl); - //if (mmp_element_integration_method_maximum) ?? CB: was ist das - if(1 > 0) // CB: to do ?? - { - gp_r = (int)(point / (nGauss * nGauss)); - gp_s = (point % (nGauss * nGauss)); - gp_t = gp_s % nGauss; - gp_s /= nGauss; - ur = MXPGaussPkt(nGauss, gp_r); - us = MXPGaussPkt(nGauss, gp_s); - ut = MXPGaussPkt(nGauss, gp_t); + // hier nur Methoden 1 + 2; 3 wird in CalcCoefLaplace erledigt + if (upwind_meth == 1) + { + // Verschiebungen der Gausspunkte auf Element begrenzen + scale = 1.; + if (fabs(ur + alpha[0]) > 1.) + scale = MMin(scale, (1. - fabs(ur)) / fabs(alpha[0])); + if (fabs(us + alpha[1]) > 1.) + scale = MMin(scale, (1. - fabs(us)) / fabs(alpha[1])); + *rupw = ur + scale * alpha[0]; + *supw = us + scale * alpha[1]; + } + else if (upwind_meth == 2) + { + // Verschiebungen auf -1 0) // CB: to do ?? + { + gp_r = (int)(point / (nGauss * nGauss)); + gp_s = (point % (nGauss * nGauss)); + gp_t = gp_s % nGauss; + gp_s /= nGauss; + ur = MXPGaussPkt(nGauss, gp_r); + us = MXPGaussPkt(nGauss, gp_s); + ut = MXPGaussPkt(nGauss, gp_t); + } + else + { + ur = 0.0; // Alle Groessen nur in Elementmitte betrachten + us = 0.0; // Alle Groessen nur in Elementmitte betrachten + ut = 0.0; // Alle Groessen nur in Elementmitte betrachten + } - if (MBtrgVec(v_rst, 3) > MKleinsteZahl) - /* Upwind-Faktoren */ - for (l = 0; l < 3; l++) - alpha[l] = -upwind_para * v_rst[l] / - MBtrgVec(v_rst, 3) + MKleinsteZahl; - //hier nur Methoden 1 + 2; 3 wird in CalcCoefLaplace erledigt - if (upwind_meth == 1) - { - // Verschiebungen der Gausspunkte auf Element begrenzen - scale = 1.; - if (fabs(ur + alpha[0]) > 1.) - scale = MMin(scale, (1. - fabs(ur)) / fabs(alpha[0])); - if (fabs(us + alpha[1]) > 1.) - scale = MMin(scale, (1. - fabs(us)) / fabs(alpha[1])); - if (fabs(ut + alpha[2]) > 1.) - scale = MMin(scale, (1. - fabs(ut)) / fabs(alpha[2])); - *rupw = ur + scale * alpha[0]; // ist die reihenfolge hier richtig? - *supw = us + scale * alpha[1]; // scale h?gt hier ja nur von dem letzten if ab.. - *tupw = ut + scale * alpha[2]; - } - else if (upwind_meth == 2) - { - // Verschiebungen auf -1 MKleinsteZahl) + /* Upwind-Faktoren */ + for (l = 0; l < 3; l++) + alpha[l] = -upwind_para * v_rst[l] / MBtrgVec(v_rst, 3) + MKleinsteZahl; + // hier nur Methoden 1 + 2; 3 wird in CalcCoefLaplace erledigt + if (upwind_meth == 1) + { + // Verschiebungen der Gausspunkte auf Element begrenzen + scale = 1.; + if (fabs(ur + alpha[0]) > 1.) + scale = MMin(scale, (1. - fabs(ur)) / fabs(alpha[0])); + if (fabs(us + alpha[1]) > 1.) + scale = MMin(scale, (1. - fabs(us)) / fabs(alpha[1])); + if (fabs(ut + alpha[2]) > 1.) + scale = MMin(scale, (1. - fabs(ut)) / fabs(alpha[2])); + *rupw = ur + scale * alpha[0]; // ist die reihenfolge hier richtig? + *supw = us + scale * alpha[1]; // scale h?gt hier ja nur von dem letzten if ab.. + *tupw = ut + scale * alpha[2]; + } + else if (upwind_meth == 2) + { + // Verschiebungen auf -1GetIndex(); + double dens_arg[3]; // AKS + // OK long Index = MeshElement->GetIndex(); //---------------------------------------------------------------------- - switch(PcsType) + switch (PcsType) { - default: - cout << "Fatal error in CalCoefAdvection: No valid PCS type" << "\n"; - break; - case EPT_LIQUID_FLOW: // Liquid flow - break; - case EPT_UNCONFINED_FLOW: // Unconfined flow - break; - case EPT_GROUNDWATER_FLOW: // MB now Groundwater flow - break; - case EPT_TWOPHASE_FLOW: // Two-phase flow - break; - case EPT_COMPONENTAL_FLOW: // Componental flow - break; - case EPT_HEAT_TRANSPORT: // heat transport - if(FluidProp->density_model == 14 && MediaProp->heat_diffusion_model == 1 && - cpl_pcs ) - { - dens_arg[0] = interpolate(NodalValC1); - dens_arg[1] = interpolate(NodalVal1) + PhysicalConstant::CelsiusZeroInKelvin; - dens_arg[2] = Index; - val = FluidProp->SpecificHeatCapacity(dens_arg) * FluidProp->Density(dens_arg); - } - else - val = FluidProp->SpecificHeatCapacity() * FluidProp->Density(); - break; - case EPT_MASS_TRANSPORT: // Mass transport //SB4200 - val = 1.0 * time_unit_factor; //*MediaProp->Porosity(Index,pcs->m_num->ls_theta); // Porosity; - break; - case EPT_OVERLAND_FLOW: // Liquid flow - val = 1.0; - break; - case EPT_RICHARDS_FLOW: // Richards - break; - case EPT_FLUID_MOMENTUM: // Fluid Momentum - break; - case EPT_GAS_FLOW: // Air (gas) flow - val = 1.0 / interpolate(NodalVal1); // 1/p - break; + default: + cout << "Fatal error in CalCoefAdvection: No valid PCS type" + << "\n"; + break; + case EPT_LIQUID_FLOW: // Liquid flow + break; + case EPT_UNCONFINED_FLOW: // Unconfined flow + break; + case EPT_GROUNDWATER_FLOW: // MB now Groundwater flow + break; + case EPT_TWOPHASE_FLOW: // Two-phase flow + break; + case EPT_COMPONENTAL_FLOW: // Componental flow + break; + case EPT_HEAT_TRANSPORT: // heat transport + if (FluidProp->density_model == 14 && MediaProp->heat_diffusion_model == 1 && cpl_pcs) + { + dens_arg[0] = interpolate(NodalValC1); + dens_arg[1] = interpolate(NodalVal1) + PhysicalConstant::CelsiusZeroInKelvin; + dens_arg[2] = Index; + val = FluidProp->SpecificHeatCapacity(dens_arg) * FluidProp->Density(dens_arg); + } + else + val = FluidProp->SpecificHeatCapacity() * FluidProp->Density(); + break; + case EPT_MASS_TRANSPORT: // Mass transport //SB4200 + val = 1.0 * time_unit_factor; //*MediaProp->Porosity(Index,pcs->m_num->ls_theta); // Porosity; + break; + case EPT_OVERLAND_FLOW: // Liquid flow + val = 1.0; + break; + case EPT_RICHARDS_FLOW: // Richards + break; + case EPT_FLUID_MOMENTUM: // Fluid Momentum + break; + case EPT_GAS_FLOW: // Air (gas) flow + val = 1.0 / interpolate(NodalVal1); // 1/p + break; } return val; } - /************************************************************************** FEMLib-Method: Task: Calculate material coefficient for advection matrix for @@ -3556,20 +3492,22 @@ double CFiniteElementStd::CalCoefAdvection() void CFiniteElementStd::CalCoefAdvectionMCF() { int i, nDF = pcs->dof; - double arg_PV[6], rho; - for(i = 0; i < nDF*nDF; i++) AdvectionMatrixElements[i] = 0.0; + double arg_PV[6], rho; + for (i = 0; i < nDF * nDF; i++) + AdvectionMatrixElements[i] = 0.0; ComputeShapefct(1); - for(i = 0; iDensity(arg_PV); - //Advection Matrix Elements value---start - if(FluidProp->mu_JT == "ON") - AdvectionMatrixElements[nDF] = 1.0 - arg_PV[1]*FluidProp->drhodT(arg_PV); // JOD - AdvectionMatrixElements[nDF + 1] = rho*FluidProp->SpecificHeatCapacity(arg_PV); - if(FluidProp->cmpN > 0) - for(i = 2; imu_JT == "ON") + AdvectionMatrixElements[nDF] = 1.0 - arg_PV[1] * FluidProp->drhodT(arg_PV); // JOD + AdvectionMatrixElements[nDF + 1] = rho * FluidProp->SpecificHeatCapacity(arg_PV); + if (FluidProp->cmpN > 0) + for (i = 2; i < nDF; i++) + AdvectionMatrixElements[(nDF + 1) * i] = rho; + // Advection Matrix Elements value---end +} /*************************************************************************** GeoSys - Function: CalCoefStrainCouping @@ -3588,38 +3526,38 @@ double CFiniteElementStd::CalCoefStrainCouping(const int phase) double t = unit[2]; */ - switch(PcsType) + switch (PcsType) { - default: - break; - case EPT_LIQUID_FLOW: // Liquid flow - // - val = 1.0; - break; - case EPT_UNCONFINED_FLOW: // Unconfined flow - break; - case EPT_GROUNDWATER_FLOW: // Groundwater - break; - case EPT_TWOPHASE_FLOW: // Two-phase flow - break; - case EPT_COMPONENTAL_FLOW: // Componental flow - break; - case EPT_OVERLAND_FLOW: // Overland flow - break; - case EPT_RICHARDS_FLOW: // Richard flow - return interpolate(NodalVal_Sat); // Water saturation - break; - case EPT_MULTIPHASE_FLOW: - if(phase == 0) - { - PG = interpolate(NodalVal1); - Sw = MediaProp->SaturationCapillaryPressureFunction(PG); - val = Sw; - } - else - val = 1. - Sw; - return val; - break; + default: + break; + case EPT_LIQUID_FLOW: // Liquid flow + // + val = 1.0; + break; + case EPT_UNCONFINED_FLOW: // Unconfined flow + break; + case EPT_GROUNDWATER_FLOW: // Groundwater + break; + case EPT_TWOPHASE_FLOW: // Two-phase flow + break; + case EPT_COMPONENTAL_FLOW: // Componental flow + break; + case EPT_OVERLAND_FLOW: // Overland flow + break; + case EPT_RICHARDS_FLOW: // Richard flow + return interpolate(NodalVal_Sat); // Water saturation + break; + case EPT_MULTIPHASE_FLOW: + if (phase == 0) + { + PG = interpolate(NodalVal1); + Sw = MediaProp->SaturationCapillaryPressureFunction(PG); + val = Sw; + } + else + val = 1. - Sw; + return val; + break; } return val; } @@ -3637,21 +3575,21 @@ double CFiniteElementStd::CalCoefStrainCouping(const int phase) **************************************************************************/ void CFiniteElementStd::CalcMass() { - int i, j; //OK411 k; + int i, j; // OK411 k; // ---- Gauss integral - int gp_r = 0,gp_s = 0,gp_t = 0; - double fkt,mat_fac; + int gp_r = 0, gp_s = 0, gp_t = 0; + double fkt, mat_fac; // Material mat_fac = 1.0; double alpha[3] = {}, summand[8] = {}; - double vel[3]; //NW + double vel[3]; // NW // int indice = MeshElement->GetIndex(); // int phase = pcs->pcs_type_number; int upwind_method = pcs->m_num->ele_upwind_method; - if(PcsType == EPT_TWOPHASE_FLOW) + if (PcsType == EPT_TWOPHASE_FLOW) { - if(upwind_method > 0) + if (upwind_method > 0) { // CB 11/07 this is to provide the velocity at the element center of gravity // call to his function here is also required for upwinding in CalcCoefLaplace @@ -3660,7 +3598,7 @@ void CFiniteElementStd::CalcMass() } } - ElementValue* gp_ele = ele_gp_value[Index]; //NW + ElementValue* gp_ele = ele_gp_value[Index]; // NW //---------------------------------------------------------------------- //====================================================================== @@ -3673,14 +3611,14 @@ void CFiniteElementStd::CalcMass() //--------------------------------------------------------- fkt = GetGaussData(gp, gp_r, gp_s, gp_t); // Compute geometry - //if(PcsType==T) + // if(PcsType==T) //{ // if((upwind_method == 1) || (upwind_method == 2)) // UpwindUnitCoord(phase, gp, indice); // phase 0 //} - ComputeShapefct(1); // Linear interpolation function - if (pcs->m_num->ele_supg_method > 0) //NW - ComputeGradShapefct(1); // Linear interpolation function + ComputeShapefct(1); // Linear interpolation function + if (pcs->m_num->ele_supg_method > 0) // NW + ComputeGradShapefct(1); // Linear interpolation function // Material mat_fac = CalCoefMass(); @@ -3690,91 +3628,90 @@ void CFiniteElementStd::CalcMass() // ElementVolumeMultiplyer mat_fac *= MediaProp->ElementVolumeMultiplyer; // Calculate mass matrix - if(PcsType == EPT_TWOPHASE_FLOW) - { - // upwinding: addiere SUPG-Summanden auf shapefct entsprechend Fkt. Mphi2D_SPG - if(pcs->m_num->ele_upwind_method > 0) - UpwindSummandMass(gp, gp_r, gp_s, gp_t, alpha, summand); + if (PcsType == EPT_TWOPHASE_FLOW) + { + // upwinding: addiere SUPG-Summanden auf shapefct entsprechend Fkt. Mphi2D_SPG + if (pcs->m_num->ele_upwind_method > 0) + UpwindSummandMass(gp, gp_r, gp_s, gp_t, alpha, summand); #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - for(i = 0; i < act_nodes; i++) - { - const int ia = local_idx[i]; - for(j = 0; j < nnodes; j++) - { - (*Mass)(ia, j) += mat_fac*(shapefct[ia] + summand[ia]) * shapefct[j]; - } + for (i = 0; i < act_nodes; i++) + { + const int ia = local_idx[i]; + for (j = 0; j < nnodes; j++) + { + (*Mass)(ia, j) += mat_fac * (shapefct[ia] + summand[ia]) * shapefct[j]; + } } #else - for(i = 0; i < nnodes; i++) - for(j = 0; j < nnodes; j++) - // bei CT: phi * omega; phi beinh. uw-fakt. - (*Mass)(i, j) += mat_fac * - (shapefct[i] + summand[i]) * shapefct[j]; + for (i = 0; i < nnodes; i++) + for (j = 0; j < nnodes; j++) + // bei CT: phi * omega; phi beinh. uw-fakt. + (*Mass)(i, j) += mat_fac * (shapefct[i] + summand[i]) * shapefct[j]; #endif - //TEST OUTPUT - } + // TEST OUTPUT + } else - { + { #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW for (i = 0; i < act_nodes; i++) { const int ia = local_idx[i]; - for (j = 0; j m_num->ele_supg_method == 0) - if(j > i) - continue; - (*Mass)(i,j) += mat_fac * shapefct[i] * shapefct[j]; - } + for (i = 0; i < nnodes; i++) + for (j = 0; j < nnodes; j++) + { + // NW + if (pcs->m_num->ele_supg_method == 0) + if (j > i) + continue; + (*Mass)(i, j) += mat_fac * shapefct[i] * shapefct[j]; + } #endif - if (pcs->m_num->ele_supg_method > 0) //NW - { - vel[0] = gp_ele->Velocity(0, gp); - vel[1] = gp_ele->Velocity(1, gp); - vel[2] = gp_ele->Velocity(2, gp); + if (pcs->m_num->ele_supg_method > 0) // NW + { + vel[0] = gp_ele->Velocity(0, gp); + vel[1] = gp_ele->Velocity(1, gp); + vel[2] = gp_ele->Velocity(2, gp); - double tau = 0; - CalcSUPGWeightingFunction(vel, gp, tau, weight_func); + double tau = 0; + CalcSUPGWeightingFunction(vel, gp, tau, weight_func); - // tau*({v}[dN])^T*[N] +// tau*({v}[dN])^T*[N] #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - for (i = 0; i < act_nodes; i++) - { - const int ia = local_idx[i]; - for (j = 0; j < nnodes; j++) - { - (*Mass)(ia, j) += mat_fac * tau * weight_func[ia] * shapefct[j]; - } - } + for (i = 0; i < act_nodes; i++) + { + const int ia = local_idx[i]; + for (j = 0; j < nnodes; j++) + { + (*Mass)(ia, j) += mat_fac * tau * weight_func[ia] * shapefct[j]; + } + } #else - for (i = 0; i < nnodes; i++) - for (j = 0; j < nnodes; j++) - (*Mass)(i, j) += mat_fac * tau * weight_func[i] * shapefct[j]; + for (i = 0; i < nnodes; i++) + for (j = 0; j < nnodes; j++) + (*Mass)(i, j) += mat_fac * tau * weight_func[i] * shapefct[j]; #endif - } - } //end else - } // loop gauss points + } + } // end else + } // loop gauss points - //WW/CB //NW +// WW/CB //NW #ifndef USE_PETSC - if(PcsType != EPT_TWOPHASE_FLOW && pcs->m_num->ele_supg_method == 0) - { - for(i = 0; i < nnodes; i++) - for(j = 0; j < nnodes; j++) - if(i > j) - (*Mass)(j,i) = (*Mass)(i,j); - } + if (PcsType != EPT_TWOPHASE_FLOW && pcs->m_num->ele_supg_method == 0) + { + for (i = 0; i < nnodes; i++) + for (j = 0; j < nnodes; j++) + if (i > j) + (*Mass)(j, i) = (*Mass)(i, j); + } #endif // Test Output - //Mass->Write(); + // Mass->Write(); } /************************************************************************** FEMLib-Method: @@ -3783,7 +3720,7 @@ void CFiniteElementStd::CalcMass() 12/2009 NW last modification: **************************************************************************/ -double CFiniteElementStd::CalcSUPGCoefficient(double* vel,int ip) +double CFiniteElementStd::CalcSUPGCoefficient(double* vel, int ip) { //-------------------------------------------------------------------- // Collect following information to determine SUPG coefficient @@ -3800,45 +3737,45 @@ double CFiniteElementStd::CalcSUPGCoefficient(double* vel,int ip) double ele_len = CalcSUPGEffectiveElemenetLength(vel); // Diffusivity = (effective heat conductivity) / (fluid heat capacity) double* dispersion_tensor = NULL; - if (PcsType == EPT_HEAT_TRANSPORT) //heat + if (PcsType == EPT_HEAT_TRANSPORT) // heat dispersion_tensor = MediaProp->HeatConductivityTensor(MeshElement->GetIndex()); - //mass + // mass else if (PcsType == EPT_MASS_TRANSPORT) // SB, BG dispersion_tensor = MediaProp->MassDispersionTensorNew(ip, 0); double diff = .0; switch (pcs->m_num->ele_supg_method_diffusivity) { - case 1: // min - { - double min_diff = dispersion_tensor[0]; - for (size_t i = 1; i < dim * dim; i++) - if (dispersion_tensor[i] < min_diff) - min_diff = dispersion_tensor[i]; - diff = min_diff; - } - break; - case 2: // magnitude of diagonal - { - double tmp_diff = 0.0; - for (size_t i = 0; i < dim; i++) - tmp_diff = dispersion_tensor[i + i * dim] * dispersion_tensor[i + i * dim]; - diff = sqrt(tmp_diff); - } - break; - default: //0 or any invalid number: max. in dispersion coefficient - { - double max_diff = dispersion_tensor[0]; - for (size_t i = 1; i < dim * dim; i++) - if (dispersion_tensor[i] > max_diff) - max_diff = dispersion_tensor[i]; - diff = max_diff; - } + case 1: // min + { + double min_diff = dispersion_tensor[0]; + for (size_t i = 1; i < dim * dim; i++) + if (dispersion_tensor[i] < min_diff) + min_diff = dispersion_tensor[i]; + diff = min_diff; + } + break; + case 2: // magnitude of diagonal + { + double tmp_diff = 0.0; + for (size_t i = 0; i < dim; i++) + tmp_diff = dispersion_tensor[i + i * dim] * dispersion_tensor[i + i * dim]; + diff = sqrt(tmp_diff); + } + break; + default: // 0 or any invalid number: max. in dispersion coefficient + { + double max_diff = dispersion_tensor[0]; + for (size_t i = 1; i < dim * dim; i++) + if (dispersion_tensor[i] > max_diff) + max_diff = dispersion_tensor[i]; + diff = max_diff; + } } - if (PcsType == EPT_HEAT_TRANSPORT) //heat + if (PcsType == EPT_HEAT_TRANSPORT) // heat { - diff /= (FluidProp->SpecificHeatCapacity() * FluidProp->Density()); + diff /= (FluidProp->SpecificHeatCapacity() * FluidProp->Density()); } //-------------------------------------------------------------------- @@ -3846,24 +3783,22 @@ double CFiniteElementStd::CalcSUPGCoefficient(double* vel,int ip) double tau = 0.0; switch (pcs->m_num->ele_supg_method) { - case 1: - { - // this coefficient matches with the analytical solution in 1D steady state case - double alpha = 0.5 * v_mag * ele_len / diff; // 0.5*Pe - double func = MLangevin(alpha); - tau = 0.5 * ele_len / v_mag * func; - } - break; - case 2: - { - // taking into account time step - // tau = 1.0 / sqrt(pow(2.0/dt ,2.0)+pow(2.0*v_mag/ele_len,2.0)); - tau = 1.0 / sqrt((2.0 / dt) * (2.0 / dt) - + (2.0 * v_mag / ele_len) * (2.0 * v_mag / ele_len) - + (4.0 * diff / - (ele_len * ele_len)) * (4.0 * diff / (ele_len * ele_len))); - } - break; + case 1: + { + // this coefficient matches with the analytical solution in 1D steady state case + double alpha = 0.5 * v_mag * ele_len / diff; // 0.5*Pe + double func = MLangevin(alpha); + tau = 0.5 * ele_len / v_mag * func; + } + break; + case 2: + { + // taking into account time step + // tau = 1.0 / sqrt(pow(2.0/dt ,2.0)+pow(2.0*v_mag/ele_len,2.0)); + tau = 1.0 / sqrt((2.0 / dt) * (2.0 / dt) + (2.0 * v_mag / ele_len) * (2.0 * v_mag / ele_len) + + (4.0 * diff / (ele_len * ele_len)) * (4.0 * diff / (ele_len * ele_len))); + } + break; } return tau; @@ -3875,18 +3810,17 @@ double CFiniteElementStd::CalcSUPGCoefficient(double* vel,int ip) 12/2009 NW last modification: **************************************************************************/ -void CFiniteElementStd::CalcSUPGWeightingFunction(double* vel, int ip, double &tau, double* v_dN) +void CFiniteElementStd::CalcSUPGWeightingFunction(double* vel, int ip, double& tau, double* v_dN) { if (pcs->m_num->ele_supg_method == 0) { - cout << - "***Warning in CFiniteElementStd::CalcSUPGWeightingFunction(): SUPG option is not selected" + cout << "***Warning in CFiniteElementStd::CalcSUPGWeightingFunction(): SUPG option is not selected" << "\n"; return; } // tau - tau = CalcSUPGCoefficient(vel,ip); + tau = CalcSUPGCoefficient(vel, ip); // {v}[dN] for (int i = 0; i < nnodes; i++) @@ -3904,67 +3838,66 @@ void CFiniteElementStd::CalcSUPGWeightingFunction(double* vel, int ip, double &t **************************************************************************/ double CFiniteElementStd::CalcSUPGEffectiveElemenetLength(double* vel) { - vel = vel; //OK411 + vel = vel; // OK411 double L = 0.0; switch (this->ele_dim) { - case 1: - { - L = this->MeshElement->GetVolume(); - } - break; - case 2: - case 3: - { - switch (pcs->m_num->ele_supg_method_length) - { - case 1: //min - { - double min = MeshElement->GetEdge(0)->getLength(); - for (size_t i = 1; i < MeshElement->GetEdgesNumber(); i++) - { - L = MeshElement->GetEdge(i)->getLength(); - if (L < min) - min = L; - } - L = min; - } - break; - case 2: //average - { - double tmp_L = 0.0; - for (size_t i = 1; i < MeshElement->GetEdgesNumber(); i++) - tmp_L += MeshElement->GetEdge(i)->getLength(); - L = tmp_L / MeshElement->GetEdgesNumber(); - } - break; - case 3: // stream line length + case 1: { - cout << - "***Error: ele_supg_method_length <3> has not been supported yet." << - "\n"; + L = this->MeshElement->GetVolume(); } break; - default: //0 or any invalid number: max edge length + case 2: + case 3: { - double max = MeshElement->GetEdge(0)->getLength(); - for (size_t i = 1; i < MeshElement->GetEdgesNumber(); i++) + switch (pcs->m_num->ele_supg_method_length) { - L = MeshElement->GetEdge(i)->getLength(); - if (L > max) - max = L; + case 1: // min + { + double min = MeshElement->GetEdge(0)->getLength(); + for (size_t i = 1; i < MeshElement->GetEdgesNumber(); i++) + { + L = MeshElement->GetEdge(i)->getLength(); + if (L < min) + min = L; + } + L = min; + } + break; + case 2: // average + { + double tmp_L = 0.0; + for (size_t i = 1; i < MeshElement->GetEdgesNumber(); i++) + tmp_L += MeshElement->GetEdge(i)->getLength(); + L = tmp_L / MeshElement->GetEdgesNumber(); + } + break; + case 3: // stream line length + { + cout << "***Error: ele_supg_method_length <3> has not been supported yet." + << "\n"; + } + break; + default: // 0 or any invalid number: max edge length + { + double max = MeshElement->GetEdge(0)->getLength(); + for (size_t i = 1; i < MeshElement->GetEdgesNumber(); i++) + { + L = MeshElement->GetEdge(i)->getLength(); + if (L > max) + max = L; + } + L = max; + } + break; } - L = max; } break; - } - } - break; } return L; } -//CB 090507 +// CB 090507 /************************************************************************** FEMLib-Method: Task: @@ -3974,36 +3907,36 @@ double CFiniteElementStd::CalcSUPGEffectiveElemenetLength(double* vel) **************************************************************************/ void CFiniteElementStd::UpwindAlphaMass(double* alpha) { - //Laufvariablen + // Laufvariablen static long i; - //WW int no_phases; + // WW int no_phases; - //static long *element_nodes; - //WW double gp[3], + // static long *element_nodes; + // WW double gp[3], double v_rst[3], v_tot[3]; - //WW static double zeta; - //static double *velovec, vg, v[2], vt[2], v_rs[2]; - //static double alpha_adv[3]; + // WW static double zeta; + // static double *velovec, vg, v[2], vt[2], v_rs[2]; + // static double alpha_adv[3]; double upwind_para; - //WW double upwind_meth; + // WW double upwind_meth; // Numerik - //WW zeta = 0.0; - //WW gp[0]=0.0; gp[1]=0.0; gp[2]=0.0; + // WW zeta = 0.0; + // WW gp[0]=0.0; gp[1]=0.0; gp[2]=0.0; int ind = MeshElement->GetIndex(); ElementValue* gp_ele = ele_gp_value[ind]; // TF ununsed: MshElemType::type eletyp = MeshElement->GetElementType(); // Elementdaten und globale Modellparameter - //WW no_phases =(int)mfp_vector.size(); + // WW no_phases =(int)mfp_vector.size(); // upwind_para = pcs->m_num->ele_upwinding; - //WW upwind_meth = pcs->m_num->ele_upwind_method; + // WW upwind_meth = pcs->m_num->ele_upwind_method; // alpha initialisieren MNulleVec(alpha, 3); // v initialisieren - MNulleVec(v_tot,3); + MNulleVec(v_tot, 3); // get the velocities for phase 0 v_tot[0] = gp_ele->Velocity(0, 0); @@ -4015,7 +3948,7 @@ void CFiniteElementStd::UpwindAlphaMass(double* alpha) // when mass matrix is assembled // hence v is at element center of gravity // otherwise use following approximation: - //for(i=0; iVelocity(0, i)/nGaussPoints; // v_tot[1] += gp_ele->Velocity(1, i)/nGaussPoints; @@ -4028,7 +3961,7 @@ void CFiniteElementStd::UpwindAlphaMass(double* alpha) v_tot[0] += gp_ele->Velocity(0, 0); v_tot[1] += gp_ele->Velocity(1, 0); v_tot[2] += gp_ele->Velocity(2, 0); - //for(i=0; iVelocity(0, i)/nGaussPoints; // v_tot[1] += gp_ele->Velocity(1, i)/nGaussPoints; @@ -4037,9 +3970,9 @@ void CFiniteElementStd::UpwindAlphaMass(double* alpha) for (i = 0; i < 3; i++) v_tot[i] *= time_unit_factor; - //SetGaussPoint(point, gp_r, gp_s, gp_t); + // SetGaussPoint(point, gp_r, gp_s, gp_t); // velocity transformation a,b,c -> r,s,t - computeJacobian(1); // order 1 + computeJacobian(1); // order 1 // multiply velocity vector with Jacobian matrix // Jacobi*v-->v_rst for (size_t i = 0; i < ele_dim; i++) @@ -4050,124 +3983,121 @@ void CFiniteElementStd::UpwindAlphaMass(double* alpha) } // Upwind-Factors - if(MBtrgVec(v_rst, ele_dim) > MKleinsteZahl) // if(lengthOftheVector > tolerance) + if (MBtrgVec(v_rst, ele_dim) > MKleinsteZahl) // if(lengthOftheVector > tolerance) - for(size_t i = 0; i < ele_dim; i++) - alpha[i] = -upwind_para * v_rst[i] / - (MBtrgVec(v_rst, ele_dim) + MKleinsteZahl); + for (size_t i = 0; i < ele_dim; i++) + alpha[i] = -upwind_para * v_rst[i] / (MBtrgVec(v_rst, ele_dim) + MKleinsteZahl); #ifdef OLD_UPWINDING - //test - for(i = 0; i < ele_dim; i++) + // test + for (i = 0; i < ele_dim; i++) cout << alpha[i] << " "; cout << "\n"; - switch(eletyp) - { - case 1: // Line + switch (eletyp) { - // Elementgeometriedaten - static double detjac, * invjac, jacobi[4]; - static double l[3]; - //invjac = GetElementJacobiMatrix(index, &detjac); - //Calc1DElementJacobiMatrix(ind, invjac, &detjac); //index = element id number - detjac = computeJacobian(1); // order - invjac = invJacobian; - //element_nodes = ElGetElementNodes(ind); + case 1: // Line + { + // Elementgeometriedaten + static double detjac, *invjac, jacobi[4]; + static double l[3]; + // invjac = GetElementJacobiMatrix(index, &detjac); + // Calc1DElementJacobiMatrix(ind, invjac, &detjac); //index = element id number + detjac = computeJacobian(1); // order + invjac = invJacobian; + // element_nodes = ElGetElementNodes(ind); - MNulleVec(l,3); - l[0] = X[1] - X[0]; - l[1] = Y[1] - Y[0]; - l[2] = Z[1] - Z[0]; + MNulleVec(l, 3); + l[0] = X[1] - X[0]; + l[1] = Y[1] - Y[0]; + l[2] = Z[1] - Z[0]; - if (MBtrgVec(v_tot, 3) > MKleinsteZahl) - { - if (MSkalarprodukt(v_tot, l, 3) > 0.) - zeta = 1.; // upwind_para - else - zeta = -1.; //-upwind_para - } - - //aus RF 3.5.06 CT 1D elements: { - //// detjac = A*L/2 - //vorfk = porosity * detjac * Mdrittel; - //// Massenmatrix mit SUPG ohne Zeitanteile - //mass[0] = (2.0 + 1.5 * mms_upwind_parameter * zeta) * vorfk; - //mass[1] = (1.0 + 1.5 * mms_upwind_parameter * zeta) * vorfk; - //mass[2] = (1.0 - 1.5 * mms_upwind_parameter * zeta) * vorfk; - //mass[3] = (2.0 - 1.5 * mms_upwind_parameter * zeta) * vorfk; // } - - // Upwind-Faktor Fully upwinding - //alpha[0] = m_pcs->m_num->ele_upwinding * zeta; - //alpha_adv[0] = m_pcs->m_num->ele_upwinding * zeta; - alpha[0] = 1.0 * zeta; //?? - //alpha_adv[0] = 1.0 * zeta; - // Advection upwinding - //if (MTM2_upwind_method == 2) alpha_adv[0] = ele_upwinding * zeta; / - } - break; - case 2: // Quadrilateral - { - // Elementgeometriedaten - static double detjac, * invjac, jacobi[4]; - // Elementdaten - static double v_rs[3]; - - // Geschwindigkeitstransformation: a,b -> r,s - //Calc2DElementJacobiMatrix(ind, 0., 0., invjac, &detjac); - detjac = computeJacobian(1); // order - invjac = invJacobian; - MKopierVec(invjac, jacobi, 4); - M2Invertiere(jacobi); /* Jacobi-Matrix */ - MMultMatVec(jacobi, 2, 2, v_tot, 2, v_rs, 2); - - if(MBtrgVec(v_rs, 2) > MKleinsteZahl) - // Upwind-Faktoren - for(k = 0; k < 2; k++) - alpha[k] = -upwind_para * v_rs[k] / - (MBtrgVec(v_rs, 2) + MKleinsteZahl); - } - break; - case 3: // Hexahedra - { - /* Elementgeometriedaten */ - static double* invjac, jacobi[9], detjac; - /* Elementdaten */ - //static double v_rst[3]; - - if (MBtrgVec(v_tot, 3) > MKleinsteZahl) - { - /* Geschwindigkeitstransformation: x,y,z -> r,s,t */ - //Calc3DElementJacobiMatrix(ind, 0., 0., 0., invjac, &detjac); + if (MBtrgVec(v_tot, 3) > MKleinsteZahl) + { + if (MSkalarprodukt(v_tot, l, 3) > 0.) + zeta = 1.; // upwind_para + else + zeta = -1.; //-upwind_para + } + + // aus RF 3.5.06 CT 1D elements: { + //// detjac = A*L/2 + // vorfk = porosity * detjac * Mdrittel; + //// Massenmatrix mit SUPG ohne Zeitanteile + // mass[0] = (2.0 + 1.5 * mms_upwind_parameter * zeta) * vorfk; + // mass[1] = (1.0 + 1.5 * mms_upwind_parameter * zeta) * vorfk; + // mass[2] = (1.0 - 1.5 * mms_upwind_parameter * zeta) * vorfk; + // mass[3] = (2.0 - 1.5 * mms_upwind_parameter * zeta) * vorfk; // } + + // Upwind-Faktor Fully upwinding + // alpha[0] = m_pcs->m_num->ele_upwinding * zeta; + // alpha_adv[0] = m_pcs->m_num->ele_upwinding * zeta; + alpha[0] = 1.0 * zeta; //?? + // alpha_adv[0] = 1.0 * zeta; + // Advection upwinding + // if (MTM2_upwind_method == 2) alpha_adv[0] = ele_upwinding * zeta; / + } + break; + case 2: // Quadrilateral + { + // Elementgeometriedaten + static double detjac, *invjac, jacobi[4]; + // Elementdaten + static double v_rs[3]; + + // Geschwindigkeitstransformation: a,b -> r,s + // Calc2DElementJacobiMatrix(ind, 0., 0., invjac, &detjac); detjac = computeJacobian(1); // order invjac = invJacobian; - MKopierVec(invjac, jacobi, 9); - M3Invertiere(jacobi); /* Jacobi-Matrix */ - MMultMatVec(jacobi, 3, 3, v_tot, 3, v_rst, 3); + MKopierVec(invjac, jacobi, 4); + M2Invertiere(jacobi); /* Jacobi-Matrix */ + MMultMatVec(jacobi, 2, 2, v_tot, 2, v_rs, 2); - /* Upwind-Faktoren */ - for (l = 0; l < 3; l++) - alpha[l] = -upwind_para * v_rst[l] / - (MBtrgVec(v_rst, 3) + MKleinsteZahl); + if (MBtrgVec(v_rs, 2) > MKleinsteZahl) + // Upwind-Faktoren + for (k = 0; k < 2; k++) + alpha[k] = -upwind_para * v_rs[k] / (MBtrgVec(v_rs, 2) + MKleinsteZahl); } - } - break; - case 4: // Triangle - break; - case 5: // Tedrahedra break; - case 6: // Prism + case 3: // Hexahedra + { + /* Elementgeometriedaten */ + static double *invjac, jacobi[9], detjac; + /* Elementdaten */ + // static double v_rst[3]; + + if (MBtrgVec(v_tot, 3) > MKleinsteZahl) + { + /* Geschwindigkeitstransformation: x,y,z -> r,s,t */ + // Calc3DElementJacobiMatrix(ind, 0., 0., 0., invjac, &detjac); + detjac = computeJacobian(1); // order + invjac = invJacobian; + MKopierVec(invjac, jacobi, 9); + M3Invertiere(jacobi); /* Jacobi-Matrix */ + MMultMatVec(jacobi, 3, 3, v_tot, 3, v_rst, 3); + + /* Upwind-Faktoren */ + for (l = 0; l < 3; l++) + alpha[l] = -upwind_para * v_rst[l] / (MBtrgVec(v_rst, 3) + MKleinsteZahl); + } + } break; + case 4: // Triangle + break; + case 5: // Tedrahedra + break; + case 6: // Prism + break; } - //test - for(i = 0; i < ele_dim; i++) + // test + for (i = 0; i < ele_dim; i++) cout << alpha[i] << " "; cout << "\n"; #endif } -//CB 160507 +// CB 160507 /************************************************************************** FEMLib-Method: Task: @@ -4175,24 +4105,19 @@ void CFiniteElementStd::UpwindAlphaMass(double* alpha) 05/2007 CB last modification: **************************************************************************/ -void CFiniteElementStd::UpwindSummandMass(const int gp, - int& gp_r, - int& gp_s, - int& gp_t, - double* alpha, - double* summand) +void CFiniteElementStd::UpwindSummandMass(const int gp, int& gp_r, int& gp_s, int& gp_t, double* alpha, double* summand) { int i; // - GetGaussData(gp, gp_r, gp_s, gp_t); // this sets unit[] to standard values + GetGaussData(gp, gp_r, gp_s, gp_t); // this sets unit[] to standard values GradShapeFunction(dshapefct, unit); - for(i = 0; i < nnodes; i++) + for (i = 0; i < nnodes; i++) { summand[i] = 0.0; - for(size_t k = 0; k < dim; k++) + for (size_t k = 0; k < dim; k++) summand[i] += dshapefct[nnodes * k + i] * alpha[k]; - //summand[i] /= (double)nnodes; + // summand[i] /= (double)nnodes; } #ifdef OLD_UPWINDING @@ -4201,116 +4126,84 @@ void CFiniteElementStd::UpwindSummandMass(const int gp, u1 = u2 = u3 = 0; MshElemType::type eletyp = MeshElement->GetElementType(); - switch(eletyp) - { - case MshElemType::LINE: - { - // Line - gp_r = gp; - u1 = MXPGaussPkt(nGauss, gp_r); - summand[0] = +alpha[0] * (1 + u1); //CB: ?? hab ich mir so gedacht - summand[1] = -alpha[0] * (1 - u1); //CB: ?? hab ich mir so gedacht - for(i = 0; i < 2; i++) - summand[i] *= 0.5; - } - break; - case MshElemType::QUAD: // Quadrilateral - { - gp_r = (int)(gp / nGauss); - gp_s = gp % nGauss; - u1 = MXPGaussPkt(nGauss, gp_r); - u2 = MXPGaussPkt(nGauss, gp_s); - // derived from MPhi2D_SUPG - summand[0] = +alpha[0] * (1 + u2) + alpha[1] * (1 + u1); - summand[1] = -alpha[0] * (1 + u2) + alpha[1] * (1 - u1); - summand[2] = -alpha[0] * (1 - u2) - alpha[1] * (1 - u1); - summand[3] = +alpha[0] * (1 - u2) - alpha[1] * (1 + u1); - for(i = 0; i < 4; i++) - summand[i] *= 0.25; - } - break; - case MshElemType::HEXAHEDRON: // Hexahedra - { - gp_r = (int)(gp / (nGauss * nGauss)); - gp_s = (gp % (nGauss * nGauss)); - gp_t = gp_s % nGauss; - gp_s /= nGauss; - u1 = MXPGaussPkt(nGauss, gp_r); - u2 = MXPGaussPkt(nGauss, gp_s); - u3 = MXPGaussPkt(nGauss, gp_t); - // derived from MPhi3D_SUPG - summand[0] = +alpha[0] * - (1 + - u2) * - (1 + - u3) + alpha[1] * - (1 + u1) * (1 + u3) + alpha[2] * (1 + u1) * (1 + u2); - summand[1] = -alpha[0] * - (1 + - u2) * - (1 + - u3) + alpha[1] * - (1 - u1) * (1 + u3) + alpha[2] * (1 - u1) * (1 + u2); - summand[2] = -alpha[0] * - (1 - - u2) * - (1 + - u3) - alpha[1] * - (1 - u1) * (1 + u3) + alpha[2] * (1 - u1) * (1 - u2); - summand[3] = +alpha[0] * - (1 - - u2) * - (1 + - u3) - alpha[1] * - (1 + u1) * (1 + u3) + alpha[2] * (1 + u1) * (1 - u2); - summand[4] = +alpha[0] * - (1 + - u2) * - (1 - - u3) + alpha[1] * - (1 + u1) * (1 - u3) - alpha[2] * (1 + u1) * (1 + u2); - summand[5] = -alpha[0] * - (1 + - u2) * - (1 - - u3) + alpha[1] * - (1 - u1) * (1 - u3) - alpha[2] * (1 - u1) * (1 + u2); - summand[6] = -alpha[0] * - (1 - - u2) * - (1 - - u3) - alpha[1] * - (1 - u1) * (1 - u3) - alpha[2] * (1 - u1) * (1 - u2); - summand[7] = +alpha[0] * - (1 - - u2) * - (1 - - u3) - alpha[1] * - (1 + u1) * (1 - u3) - alpha[2] * (1 + u1) * (1 - u2); - for(i = 0; i < 8; i++) - summand[i] *= 0.125; - } - break; - case MshElemType::TRIANGLE: // Triangle - { - //SamplePointTriHQ(gp, unit); - } - break; - case MshElemType::TETRAHEDRON: // Tedrahedra - { - //SamplePointTet5(gp, unit); - } - break; - case MshElemType::PRISM: // Prism - { - gp_r = gp % nGauss; - gp_s = (int)(gp / nGauss); - gp_t = (int)(nGaussPoints / nGauss); - //u1 = MXPGaussPktTri(nGauss,gp_r,0); //femlib.cpp statt mathlib.cpp, nicht verfügbar? - //u2 = MXPGaussPktTri(nGauss,gp_r,1); - //u3 = MXPGaussPkt(gp_t,gp_s); - } - break; + switch (eletyp) + { + case MshElemType::LINE: + { + // Line + gp_r = gp; + u1 = MXPGaussPkt(nGauss, gp_r); + summand[0] = +alpha[0] * (1 + u1); // CB: ?? hab ich mir so gedacht + summand[1] = -alpha[0] * (1 - u1); // CB: ?? hab ich mir so gedacht + for (i = 0; i < 2; i++) + summand[i] *= 0.5; + } + break; + case MshElemType::QUAD: // Quadrilateral + { + gp_r = (int)(gp / nGauss); + gp_s = gp % nGauss; + u1 = MXPGaussPkt(nGauss, gp_r); + u2 = MXPGaussPkt(nGauss, gp_s); + // derived from MPhi2D_SUPG + summand[0] = +alpha[0] * (1 + u2) + alpha[1] * (1 + u1); + summand[1] = -alpha[0] * (1 + u2) + alpha[1] * (1 - u1); + summand[2] = -alpha[0] * (1 - u2) - alpha[1] * (1 - u1); + summand[3] = +alpha[0] * (1 - u2) - alpha[1] * (1 + u1); + for (i = 0; i < 4; i++) + summand[i] *= 0.25; + } + break; + case MshElemType::HEXAHEDRON: // Hexahedra + { + gp_r = (int)(gp / (nGauss * nGauss)); + gp_s = (gp % (nGauss * nGauss)); + gp_t = gp_s % nGauss; + gp_s /= nGauss; + u1 = MXPGaussPkt(nGauss, gp_r); + u2 = MXPGaussPkt(nGauss, gp_s); + u3 = MXPGaussPkt(nGauss, gp_t); + // derived from MPhi3D_SUPG + summand[0] + = +alpha[0] * (1 + u2) * (1 + u3) + alpha[1] * (1 + u1) * (1 + u3) + alpha[2] * (1 + u1) * (1 + u2); + summand[1] + = -alpha[0] * (1 + u2) * (1 + u3) + alpha[1] * (1 - u1) * (1 + u3) + alpha[2] * (1 - u1) * (1 + u2); + summand[2] + = -alpha[0] * (1 - u2) * (1 + u3) - alpha[1] * (1 - u1) * (1 + u3) + alpha[2] * (1 - u1) * (1 - u2); + summand[3] + = +alpha[0] * (1 - u2) * (1 + u3) - alpha[1] * (1 + u1) * (1 + u3) + alpha[2] * (1 + u1) * (1 - u2); + summand[4] + = +alpha[0] * (1 + u2) * (1 - u3) + alpha[1] * (1 + u1) * (1 - u3) - alpha[2] * (1 + u1) * (1 + u2); + summand[5] + = -alpha[0] * (1 + u2) * (1 - u3) + alpha[1] * (1 - u1) * (1 - u3) - alpha[2] * (1 - u1) * (1 + u2); + summand[6] + = -alpha[0] * (1 - u2) * (1 - u3) - alpha[1] * (1 - u1) * (1 - u3) - alpha[2] * (1 - u1) * (1 - u2); + summand[7] + = +alpha[0] * (1 - u2) * (1 - u3) - alpha[1] * (1 + u1) * (1 - u3) - alpha[2] * (1 + u1) * (1 - u2); + for (i = 0; i < 8; i++) + summand[i] *= 0.125; + } + break; + case MshElemType::TRIANGLE: // Triangle + { + // SamplePointTriHQ(gp, unit); + } + break; + case MshElemType::TETRAHEDRON: // Tedrahedra + { + // SamplePointTet5(gp, unit); + } + break; + case MshElemType::PRISM: // Prism + { + gp_r = gp % nGauss; + gp_s = (int)(gp / nGauss); + gp_t = (int)(nGaussPoints / nGauss); + // u1 = MXPGaussPktTri(nGauss,gp_r,0); //femlib.cpp statt mathlib.cpp, nicht verfügbar? + // u2 = MXPGaussPktTri(nGauss,gp_r,1); + // u3 = MXPGaussPkt(gp_t,gp_s); + } + break; } #endif } @@ -4323,10 +4216,10 @@ void CFiniteElementStd::UpwindSummandMass(const int gp, **************************************************************************/ void CFiniteElementStd::CalcMass2() { - int i, j,in,jn; + int i, j, in, jn; // ---- Gauss integral - int gp_r = 0,gp_s = 0,gp_t = 0; - double fkt,mat_fac; + int gp_r = 0, gp_s = 0, gp_t = 0; + double fkt, mat_fac; // Material int dof_n = 2; mat_fac = 1.0; @@ -4341,10 +4234,10 @@ void CFiniteElementStd::CalcMass2() //--------------------------------------------------------- fkt = GetGaussData(gp, gp_r, gp_s, gp_t); // Compute geometry - ComputeShapefct(1); // Linear interpolation function - for(in = 0; in < dof_n; in++) + ComputeShapefct(1); // Linear interpolation function + for (in = 0; in < dof_n; in++) { - for(jn = 0; jn < dof_n; jn++) + for (jn = 0; jn < dof_n; jn++) { // Material mat_fac = CalCoefMass2(in * dof_n + jn); @@ -4358,7 +4251,7 @@ void CFiniteElementStd::CalcMass2() const int ish = ia + in * nnodes; for (j = 0; j < nnodes; j++) { - (*Mass2)(ish,j + jsh) += mat_fac * shapefct[ia] * shapefct[j]; + (*Mass2)(ish, j + jsh) += mat_fac * shapefct[ia] * shapefct[j]; } } #else @@ -4374,7 +4267,6 @@ void CFiniteElementStd::CalcMass2() } } - /*************************************************************************** FEMLib-Method: Task: Assembly of MassMatrixElements for @@ -4384,24 +4276,25 @@ void CFiniteElementStd::CalcMass2() **************************************************************************/ void CFiniteElementStd::CalcMassMCF() { - int gp_r = 0, gp_s = 0, gp_t = 0, i, j, in, jn, nDF=pcs->dof; + int gp_r = 0, gp_s = 0, gp_t = 0, i, j, in, jn, nDF = pcs->dof; double fkt; - CalCoefMassMCF(); //Calculate mass matrix + CalCoefMassMCF(); // Calculate mass matrix for (gp = 0; gp < nGaussPoints; gp++) { - fkt = GetGaussData(gp, gp_r, gp_s, gp_t); //Compute Jacobian matrix and its determinate - ComputeShapefct(1); // Linear interpolation function - for(in = 0; in < nDF; in++) + fkt = GetGaussData(gp, gp_r, gp_s, gp_t); // Compute Jacobian matrix and its determinate + ComputeShapefct(1); // Linear interpolation function + for (in = 0; in < nDF; in++) { - const int ish = in * nnodes; - for(jn = 0; jn < nDF; jn++) + const int ish = in * nnodes; + for (jn = 0; jn < nDF; jn++) { - const int jsh = jn * nnodes; + const int jsh = jn * nnodes; for (i = 0; i < nnodes; i++) { for (j = 0; j < nnodes; j++) - (*Mass2)(i + ish, j + jsh) += fkt*MassMatrixElements[in*nDF + jn]*shapefct[i] *shapefct[j]; - } + (*Mass2)(i + ish, j + jsh) + += fkt * MassMatrixElements[in * nDF + jn] * shapefct[i] * shapefct[j]; + } } } } @@ -4415,57 +4308,55 @@ void CFiniteElementStd::CalcMassMCF() **************************************************************************/ void CFiniteElementStd::CalcMassPSGLOBAL() { - int i, j,in,jn; - // ---- Gauss integral - int gp_r = 0,gp_s = 0,gp_t = 0; - double fkt,mat_fac; - // Material - int dof_n = 2; - mat_fac = 1.0; - //---------------------------------------------------------------------- - //====================================================================== - // Loop over Gauss points - for (gp = 0; gp < nGaussPoints; gp++) - { - //--------------------------------------------------------- - // Get local coordinates and weights - // Compute Jacobian matrix and its determinate - //--------------------------------------------------------- - fkt = GetGaussData(gp, gp_r, gp_s, gp_t); - // Compute geometry - ComputeShapefct(1); // Linear interpolation function - - for(in = 0; in < dof_n; in++) - { - for(jn = 0; jn < dof_n; jn++) - { - // Material - mat_fac = CalCoefMassPSGLOBAL(in * dof_n + jn); - mat_fac *= fkt; - // Calculate mass matrix + int i, j, in, jn; + // ---- Gauss integral + int gp_r = 0, gp_s = 0, gp_t = 0; + double fkt, mat_fac; + // Material + int dof_n = 2; + mat_fac = 1.0; + //---------------------------------------------------------------------- + //====================================================================== + // Loop over Gauss points + for (gp = 0; gp < nGaussPoints; gp++) + { + //--------------------------------------------------------- + // Get local coordinates and weights + // Compute Jacobian matrix and its determinate + //--------------------------------------------------------- + fkt = GetGaussData(gp, gp_r, gp_s, gp_t); + // Compute geometry + ComputeShapefct(1); // Linear interpolation function + + for (in = 0; in < dof_n; in++) + { + for (jn = 0; jn < dof_n; jn++) + { + // Material + mat_fac = CalCoefMassPSGLOBAL(in * dof_n + jn); + mat_fac *= fkt; +// Calculate mass matrix #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - for (i = 0; i < act_nodes; i++) - { - const int ia = local_idx[i]; - for (j = 0; j < nnodes; j++) - { - (*Mass2)(ia + in * nnodes,j + jn * - nnodes) += mat_fac * shapefct[ia] * shapefct[j]; - } - } + for (i = 0; i < act_nodes; i++) + { + const int ia = local_idx[i]; + for (j = 0; j < nnodes; j++) + { + (*Mass2)(ia + in * nnodes, j + jn * nnodes) += mat_fac * shapefct[ia] * shapefct[j]; + } + } #else - for (i = 0; i < nnodes; i++) - { - for (j = 0; j < nnodes; j++) - { - (*Mass2)(i + in * nnodes,j + jn * - nnodes) += mat_fac * shapefct[i] * shapefct[j]; - } - } + for (i = 0; i < nnodes; i++) + { + for (j = 0; j < nnodes; j++) + { + (*Mass2)(i + in * nnodes, j + jn * nnodes) += mat_fac * shapefct[i] * shapefct[j]; + } + } #endif - } - } - } + } + } + } } /*************************************************************************** @@ -4491,8 +4382,8 @@ void CFiniteElementStd::CalcLumpedMass() // Initialize (*Mass) = 0.0; // Volume - if(axisymmetry) - { // This calculation should be done in CompleteMesh. + if (axisymmetry) + { // This calculation should be done in CompleteMesh. // However, in order not to destroy the concise of the code, // it is put here. Anyway it is computational cheap. WW vol = 0.0; @@ -4504,26 +4395,26 @@ void CFiniteElementStd::CalcLumpedMass() vol += GetGaussData(gp, gp_r, gp_s, gp_t); } else - //NW multiply geo_area + // NW multiply geo_area vol = MeshElement->GetVolume() * MeshElement->GetFluxArea(); // Center of the reference element SetCenterGP(); factor = CalCoefMass(); // ElementVolumeMultiplyer factor *= MediaProp->ElementVolumeMultiplyer; - pcs->timebuffer = factor; // Tim Control "Neumann" + pcs->timebuffer = factor; // Tim Control "Neumann" factor *= vol / (double)nnodes; #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW for (i = 0; i < act_nodes; i++) - { - const int ia = local_idx[i]; - (*Mass)(ia, ia) = factor; - } + { + const int ia = local_idx[i]; + (*Mass)(ia, ia) = factor; + } #else for (i = 0; i < nnodes; i++) - (*Mass)(i,i) = factor; + (*Mass)(i, i) = factor; #endif - // +// #ifdef otherLumpedMass int i, j; int gp_r = 0, gp_s = 0, gp_t = 0; @@ -4531,15 +4422,15 @@ void CFiniteElementStd::CalcLumpedMass() //---------------------------------------------------------------------- for (i = 0; i < nnodes; i++) { - for(j = 0; j < ele_dim; j++) + for (j = 0; j < ele_dim; j++) x2buff[j] = nodes_xyz[j * nnodes + i]; UnitCoordinates(x2buff); fkt = GetGaussData(i, gp_r, gp_s, gp_t) * CalCoefMass(); - (*Mass)(i + in * nnodes,i + jn * nnodes) += fkt; + (*Mass)(i + in * nnodes, i + jn * nnodes) += fkt; } - //---------------------------------------------------------------------- +//---------------------------------------------------------------------- #endif - //TEST OUT + // TEST OUT // Mass->Write(); } @@ -4557,8 +4448,8 @@ void CFiniteElementStd::CalcLumpedMass2() int dof_n = 2; //---------------------------------------------------------------------- // Volume - if(axisymmetry) - { // This calculation should be done in CompleteMesh. + if (axisymmetry) + { // This calculation should be done in CompleteMesh. // However, in order not to destroy the concise of the code, // it is put here. Anyway it is computational cheap. WW vol = 0.0; @@ -4570,36 +4461,36 @@ void CFiniteElementStd::CalcLumpedMass2() vol += GetGaussData(gp, gp_r, gp_s, gp_t); } else - vol = MeshElement->GetVolume() * MeshElement->area; //WW. 24.05.2012 + vol = MeshElement->GetVolume() * MeshElement->area; // WW. 24.05.2012 //---------------------------------------------------------------------- // Initialize (*Mass2) = 0.0; // Center of the reference element SetCenterGP(); - for(in = 0; in < dof_n; in++) - { - const int ish = in * nnodes; - for(jn = 0; jn < dof_n; jn++) - { - // Factor - factor = CalCoefMass2(in * dof_n + jn); - pcs->timebuffer = factor; // Tim Control "Neumann" - // Volume - factor *= vol / (double)nnodes; - const int jsh = jn * nnodes; //WW + for (in = 0; in < dof_n; in++) + { + const int ish = in * nnodes; + for (jn = 0; jn < dof_n; jn++) + { + // Factor + factor = CalCoefMass2(in * dof_n + jn); + pcs->timebuffer = factor; // Tim Control "Neumann" + // Volume + factor *= vol / (double)nnodes; + const int jsh = jn * nnodes; // WW #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - for (i = 0; i < act_nodes; i++) - { - const int ia = local_idx[i]; - (*Mass2)(ia + ish, ia + jsh) = factor; - } + for (i = 0; i < act_nodes; i++) + { + const int ia = local_idx[i]; + (*Mass2)(ia + ish, ia + jsh) = factor; + } #else - for (i = 0; i < nnodes; i++) - (*Mass2)(i + ish,i + jsh) = factor; + for (i = 0; i < nnodes; i++) + (*Mass2)(i + ish, i + jsh) = factor; #endif - } - } - //TEST OUT + } + } + // TEST OUT // Mass2->Write(); } /*************************************************************************** @@ -4611,12 +4502,12 @@ void CFiniteElementStd::CalcLumpedMass2() **************************************************************************/ void CFiniteElementStd::CalcLumpedMassMCF() { - int i, in, jn, gp_r, gp_s, gp_t, nDF=pcs->dof; - double factor=0.0, vol = 0.0; + int i, in, jn, gp_r, gp_s, gp_t, nDF = pcs->dof; + double factor = 0.0, vol = 0.0; //---------------------------------------------------------------------- // Volume - if(axisymmetry) - { // This calculation should be done in CompleteMesh. + if (axisymmetry) + { // This calculation should be done in CompleteMesh. // However, in order not to destroy the concise of the code, // it is put here. Anyway it is computational cheap. WW vol = 0.0; @@ -4628,7 +4519,7 @@ void CFiniteElementStd::CalcLumpedMassMCF() vol += GetGaussData(gp, gp_r, gp_s, gp_t); } else - vol = MeshElement->GetVolume();//* MeshElement->area; + vol = MeshElement->GetVolume(); //* MeshElement->area; //---------------------------------------------------------------------- // Initialize (*Mass2) = 0.0; @@ -4636,22 +4527,22 @@ void CFiniteElementStd::CalcLumpedMassMCF() SetCenterGP(); ComputeShapefct(1); CalCoefMassMCF(); - for(in = 0; in < nDF; in++) - { - const int ish = in * nnodes; - for(jn = 0; jn < nDF; jn++) + for (in = 0; in < nDF; in++) { - const int jsh = jn * nnodes; - factor = MassMatrixElements[in*nDF + jn]; + const int ish = in * nnodes; + for (jn = 0; jn < nDF; jn++) + { + const int jsh = jn * nnodes; + factor = MassMatrixElements[in * nDF + jn]; pcs->timebuffer = factor; // Tim Control "Neumann" - factor *= vol; + factor *= vol; for (i = 0; i < nnodes; i++) - { - (*Mass2)(i + ish, i + jsh) = shapefct[i]*factor; + { + (*Mass2)(i + ish, i + jsh) = shapefct[i] * factor; + } + // TEST OUT + // Mass2->Write(); } - //TEST OUT - // Mass2->Write(); -} } } /*************************************************************************** @@ -4667,8 +4558,8 @@ void CFiniteElementStd::CalcLumpedMassPSGLOBAL() int dof_n = 2; //---------------------------------------------------------------------- // Volume - if(axisymmetry) - { // This calculation should be done in CompleteMesh. + if (axisymmetry) + { // This calculation should be done in CompleteMesh. // However, in order not to destroy the concise of the code, // it is put here. Anyway it is computational cheap. WW vol = 0.0; @@ -4686,30 +4577,30 @@ void CFiniteElementStd::CalcLumpedMassPSGLOBAL() (*Mass2) = 0.0; // Center of the reference element SetCenterGP(); - for(in = 0; in < dof_n; in++) - { - const int ish = in * nnodes; //WW - for(jn = 0; jn < dof_n; jn++) - { - // Factor - factor = CalCoefMassPSGLOBAL(in * dof_n + jn); - pcs->timebuffer = factor; // Tim Control "Neumann" - // Volume - factor *= vol / (double)nnodes; - const int jsh = jn * nnodes; //WW + for (in = 0; in < dof_n; in++) + { + const int ish = in * nnodes; // WW + for (jn = 0; jn < dof_n; jn++) + { + // Factor + factor = CalCoefMassPSGLOBAL(in * dof_n + jn); + pcs->timebuffer = factor; // Tim Control "Neumann" + // Volume + factor *= vol / (double)nnodes; + const int jsh = jn * nnodes; // WW #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - for (i = 0; i < act_nodes; i++) - { - const int ia = local_idx[i]; - (*Mass2)(ia + ish, ia + jsh) = factor; - } + for (i = 0; i < act_nodes; i++) + { + const int ia = local_idx[i]; + (*Mass2)(ia + ish, ia + jsh) = factor; + } #else - for (i = 0; i < nnodes; i++) - (*Mass2)(i + ish,i + jsh) = factor; + for (i = 0; i < nnodes; i++) + (*Mass2)(i + ish, i + jsh) = factor; #endif - } - } - //TEST OUT + } + } + // TEST OUT // Mass2->Write(); } @@ -4727,8 +4618,8 @@ void CFiniteElementStd::CalcStorage() { int i, j; // ---- Gauss integral - int gp_r = 0,gp_s = 0,gp_t = 0; - double fkt,mat_fac; + int gp_r = 0, gp_s = 0, gp_t = 0; + double fkt, mat_fac; // Material mat_fac = 1.0; //---------------------------------------------------------------------- @@ -4742,12 +4633,12 @@ void CFiniteElementStd::CalcStorage() //--------------------------------------------------------- fkt = GetGaussData(gp, gp_r, gp_s, gp_t); // Compute geometry - ComputeShapefct(1); // Linear interpolation function + ComputeShapefct(1); // Linear interpolation function // Material mat_fac = CalCoefStorage(); // GEO factor fkt *= mat_fac; - // Calculate mass matrix +// Calculate mass matrix #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW for (i = 0; i < act_nodes; i++) { @@ -4760,10 +4651,10 @@ void CFiniteElementStd::CalcStorage() #else for (i = 0; i < nnodes; i++) for (j = 0; j < nnodes; j++) - (*Storage)(i,j) += fkt * shapefct[i] * shapefct[j]; + (*Storage)(i, j) += fkt * shapefct[i] * shapefct[j]; #endif } - //TEST OUTPUT + // TEST OUTPUT // if(Index == 195){cout << "Storage Matrix: " << "\n"; Storage->Write(); } } @@ -4781,8 +4672,8 @@ void CFiniteElementStd::CalcContent() { int i, j; // ---- Gauss integral - int gp_r = 0,gp_s = 0,gp_t = 0; - double fkt,mat_fac; + int gp_r = 0, gp_s = 0, gp_t = 0; + double fkt, mat_fac; // Material mat_fac = 1.0; //---------------------------------------------------------------------- @@ -4796,25 +4687,25 @@ void CFiniteElementStd::CalcContent() //--------------------------------------------------------- fkt = GetGaussData(gp, gp_r, gp_s, gp_t); // Compute geometry - ComputeShapefct(1); // Linear interpolation function + ComputeShapefct(1); // Linear interpolation function // Material mat_fac = CalCoefContent(); // GEO factor fkt *= mat_fac; - // Calculate mass matrix +// Calculate mass matrix #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW for (i = 0; i < act_nodes; i++) { const int ia = local_idx[i]; for (j = 0; j < nnodes; j++) { - (*Content)(ia,j) += fkt * shapefct[ia] * shapefct[j]; + (*Content)(ia, j) += fkt * shapefct[ia] * shapefct[j]; } } #else for (i = 0; i < nnodes; i++) for (j = 0; j < nnodes; j++) - (*Content)(i,j) += fkt * shapefct[i] * shapefct[j]; + (*Content)(i, j) += fkt * shapefct[i] * shapefct[j]; #endif } } @@ -4839,11 +4730,11 @@ void CFiniteElementStd::CalcLaplace() size_t dof_n = 1; // TODO [CL] shouldn't that be equal to pcs->dof // 03.03 2009 PCH - if(PcsType == EPT_MULTIPHASE_FLOW || PcsType == EPT_PSGLOBAL) + if (PcsType == EPT_MULTIPHASE_FLOW || PcsType == EPT_PSGLOBAL) { dof_n = 2; } - else if(PcsType == EPT_THERMAL_NONEQUILIBRIUM) + else if (PcsType == EPT_THERMAL_NONEQUILIBRIUM) { dof_n = 4; } @@ -4863,15 +4754,15 @@ void CFiniteElementStd::CalcLaplace() double fkt = GetGaussData(gp, gp_r, gp_s, gp_t); //--------------------------------------------------------- // Compute geometry - ComputeGradShapefct(1); // Linear interpolation function + ComputeGradShapefct(1); // Linear interpolation function // Calculate mass matrix // The following "if" is done by WW - if(PcsType == EPT_GROUNDWATER_FLOW && MediaProp->unconfined_flow_group == 1 && MeshElement->ele_dim == - 2 && !pcs->m_msh->hasCrossSection()) + if (PcsType == EPT_GROUNDWATER_FLOW && MediaProp->unconfined_flow_group == 1 && MeshElement->ele_dim == 2 + && !pcs->m_msh->hasCrossSection()) { double water_depth = 0.0; for (int i = 0; i < nnodes; i++) - water_depth += (pcs->GetNodeValue(nodes[i],idx1) - Z[i]) * shapefct[i]; + water_depth += (pcs->GetNodeValue(nodes[i], idx1) - Z[i]) * shapefct[i]; fkt *= water_depth; } //--------------------------------------------------------- @@ -4879,24 +4770,24 @@ void CFiniteElementStd::CalcLaplace() for (size_t in = 0; in < dof_n; in++) { const int ishd = in * dof_n; - const int ish = in*nnodes; - for (size_t jn = 0; jn < dof_n; jn++) + const int ish = in * nnodes; + for (size_t jn = 0; jn < dof_n; jn++) { // Material - if(dof_n == 1) - CalCoefLaplace(false,gp); + if (dof_n == 1) + CalCoefLaplace(false, gp); else if (dof_n == 2) { if (PcsType == EPT_MULTIPHASE_FLOW) CalCoefLaplace2(false, ishd + jn); else if (PcsType == EPT_PSGLOBAL) - CalCoefLaplacePSGLOBAL(false,ishd + jn); + CalCoefLaplacePSGLOBAL(false, ishd + jn); } else if (PcsType == EPT_THERMAL_NONEQUILIBRIUM) CalCoefLaplaceTNEQ(ishd + jn); else if (PcsType == EPT_TES) CalCoefLaplaceTES(ishd + jn); - const int jsh = jn*nnodes; + const int jsh = jn * nnodes; #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW //--------------------------------------------------------- for (int i = 0; i < act_nodes; i++) @@ -4909,12 +4800,12 @@ void CFiniteElementStd::CalcLaplace() // if(j>i) continue; for (size_t k = 0; k < dim; k++) { - const int ksh = k*nnodes + ia; - const int km = dim *k ; - for(std::size_t l=0; l< dim; l++) + const int ksh = k * nnodes + ia; + const int km = dim * k; + for (std::size_t l = 0; l < dim; l++) { - (*Laplace)(iish, jjsh) += fkt * dshapefct[ksh] \ - * mat[km + l] * dshapefct[l*nnodes+j]; + (*Laplace)(iish, jjsh) + += fkt * dshapefct[ksh] * mat[km + l] * dshapefct[l * nnodes + j]; } } } // j: nodes @@ -4930,11 +4821,12 @@ void CFiniteElementStd::CalcLaplace() // if(j>i) continue; for (size_t k = 0; k < dim; k++) { - const int ksh = k*nnodes + i; - const int km = dim *k ; - for (size_t l=0; ldof; + int gp_r = 0, gp_s = 0, gp_t, i, j, in, nDF = pcs->dof; gp_t = 0; double fkt; for (gp = 0; gp < nGaussPoints; gp++) { - fkt = GetGaussData(gp, gp_r, gp_s, gp_t); - ComputeGradShapefct(1); // Linear interpolation function - CalCoefLaplaceMCF(gp); - for(in = 0; in < nDF; in++) - { - const int ish = in * nnodes; - for(i = 0; i < nnodes; i++) - { - for(j = 0; j< nnodes; j++) - { - for(size_t k = 0; k < dim; k++) - { - (*Laplace)(i + ish, j + ish) += fkt*LaplaceMatrixElements[in*nDF + in][dim*k + k] *dshapefct[k*nnodes + i]*dshapefct[k*nnodes + j]; - } - } - } - } + fkt = GetGaussData(gp, gp_r, gp_s, gp_t); + ComputeGradShapefct(1); // Linear interpolation function + CalCoefLaplaceMCF(gp); + for (in = 0; in < nDF; in++) + { + const int ish = in * nnodes; + for (i = 0; i < nnodes; i++) + { + for (j = 0; j < nnodes; j++) + { + for (size_t k = 0; k < dim; k++) + { + (*Laplace)(i + ish, j + ish) += fkt * LaplaceMatrixElements[in * nDF + in][dim * k + k] + * dshapefct[k * nnodes + i] * dshapefct[k * nnodes + j]; + } + } + } + } } - //TEST OUTPUT + // TEST OUTPUT // Laplace->Write(); } @@ -4986,24 +4879,24 @@ void CFiniteElementStd::CalcLaplaceMCF() 10/2006 YD Implementation 01/2007 WW Fundamental changes **************************************************************************/ -void CFiniteElementStd:: Assemble_DualTransfer() +void CFiniteElementStd::Assemble_DualTransfer() { - int i,j; + int i, j; int gp_r = 0, gp_s = 0, gp_t = 0; - double W, fkt,mat_fac = 0.; + double W, fkt, mat_fac = 0.; #if defined(NEW_EQS) - CSparseMatrix* A = NULL; //WW - if(m_dom) + CSparseMatrix* A = NULL; // WW + if (m_dom) A = m_dom->eqs->A; else A = pcs->eqs_new->A; #endif - //Inintialize + // Inintialize //-------------------------- WW W = pcs->continuum_vector[pcs->GetContinnumType()]; // - for(i = 0; i < nnodes; i++) + for (i = 0; i < nnodes; i++) { // Pressure 1 NodalVal3[i] = pcs->GetNodeValue(nodes[i], idx1); @@ -5020,15 +4913,15 @@ void CFiniteElementStd:: Assemble_DualTransfer() //--------------------------------------------------------- fkt = GetGaussData(gp, gp_r, gp_s, gp_t); // Material - ComputeShapefct(1); // Moved here by NW 25.10.2011 - mat_fac = CalcCoefDualTransfer(); - mat_fac *= fkt; + ComputeShapefct(1); // Moved here by NW 25.10.2011 + mat_fac = CalcCoefDualTransfer(); + mat_fac *= fkt; // Calculate mass matrix for (i = 0; i < nnodes; i++) for (j = 0; j < nnodes; j++) - (*Advection)(i,j) += mat_fac * shapefct[i] * shapefct[j]; + (*Advection)(i, j) += mat_fac * shapefct[i] * shapefct[j]; } - // Add local matrix to global matrix +// Add local matrix to global matrix #if !defined(USE_PETSC) // && !defined(other parallel libs)//03~04.3012. WW // 15.02.2007 WW long cshift = pcs->m_msh->GetNodesNumber(false); @@ -5036,30 +4929,28 @@ void CFiniteElementStd:: Assemble_DualTransfer() double fm = 1.0 / W; // - if(pcs->continuum == 0) + if (pcs->continuum == 0) { #if !defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW double ff = 1.0 / (1.0 - W); - if(MediaProp->transfer_coefficient < 0.0) // for LBNL + if (MediaProp->transfer_coefficient < 0.0) // for LBNL ff = 1.0; - for(int i = 0; i < nnodes; i++) + for (int i = 0; i < nnodes; i++) { - for(int j = 0; j < nnodes; j++) + for (int j = 0; j < nnodes; j++) { #ifdef NEW_EQS - (*A)(eqs_number[i], eqs_number[j] + - cshift) += -fm * (*Advection)(i,j); - (*A)(eqs_number[i] + cshift, - eqs_number[j]) += -ff * (*Advection)(i,j); + (*A)(eqs_number[i], eqs_number[j] + cshift) += -fm * (*Advection)(i, j); + (*A)(eqs_number[i] + cshift, eqs_number[j]) += -ff * (*Advection)(i, j); #else - MXInc(eqs_number[i], eqs_number[j] + cshift, -fm * (*Advection)(i,j)); - MXInc(eqs_number[i] + cshift, eqs_number[j], -ff * (*Advection)(i,j)); + MXInc(eqs_number[i], eqs_number[j] + cshift, -fm * (*Advection)(i, j)); + MXInc(eqs_number[i] + cshift, eqs_number[j], -ff * (*Advection)(i, j)); #endif } } #endif } - else if(MediaProp->transfer_coefficient < 0.0) // for LBNL + else if (MediaProp->transfer_coefficient < 0.0) // for LBNL fm = 1.0; // (*Advection) *= fm; @@ -5076,61 +4967,59 @@ double CFiniteElementStd::CalcCoefDualTransfer() { double Sm = 0.0, Sf = 0.0, ExFac = 0.0; double pm = 0.0, pf = 0.0, matrix_conductivity, val = 0; - //double* permeability; + // double* permeability; double* permeability = NULL; //-------------------------------------------WW CMediumProperties* m_matrix = NULL; CMediumProperties* f_matrix = NULL; - if(pcs->GetContinnumType() == 0) + if (pcs->GetContinnumType() == 0) { m_matrix = MediaProp; f_matrix = MediaProp1; } - else // fracture //WW + else // fracture //WW { m_matrix = MediaProp1; f_matrix = MediaProp; } //-------------------------------------------WW - switch(PcsType) + switch (PcsType) { - default: - break; - case EPT_RICHARDS_FLOW: - pm = interpolate(NodalVal3); - pf = interpolate(NodalVal4); - // Matrix - Sm = m_matrix->SaturationCapillaryPressureFunction(-pm); - // Fracture - Sf = f_matrix->SaturationCapillaryPressureFunction(-pf); - permeability = m_matrix->PermeabilityTensor(Index); - ExFac = m_matrix->transfer_coefficient; - // Dual by van Genuchten - if(ExFac > 0.0) - matrix_conductivity = 0.5 * (m_matrix->PermeabilitySaturationFunction(Sm,0) - + m_matrix->PermeabilitySaturationFunction(Sf, - 0)) - / FluidProp->Viscosity(); - - else // by LBNL. WW - { - double Sf_e = f_matrix->GetEffectiveSaturationForPerm(Sf,phase); - matrix_conductivity = Sf_e * m_matrix->PermeabilitySaturationFunction(Sm,0) \ - / FluidProp->Viscosity(); - ExFac *= -1.0; - } - // - val = time_unit_factor * permeability[0] * matrix_conductivity * ExFac; - break; - //--------------------------------------------------------- - case EPT_HEAT_TRANSPORT: + default: + break; + case EPT_RICHARDS_FLOW: + pm = interpolate(NodalVal3); + pf = interpolate(NodalVal4); + // Matrix + Sm = m_matrix->SaturationCapillaryPressureFunction(-pm); + // Fracture + Sf = f_matrix->SaturationCapillaryPressureFunction(-pf); + permeability = m_matrix->PermeabilityTensor(Index); + ExFac = m_matrix->transfer_coefficient; + // Dual by van Genuchten + if (ExFac > 0.0) + matrix_conductivity = 0.5 * (m_matrix->PermeabilitySaturationFunction(Sm, 0) + + m_matrix->PermeabilitySaturationFunction(Sf, 0)) + / FluidProp->Viscosity(); + + else // by LBNL. WW + { + double Sf_e = f_matrix->GetEffectiveSaturationForPerm(Sf, phase); + matrix_conductivity = Sf_e * m_matrix->PermeabilitySaturationFunction(Sm, 0) / FluidProp->Viscosity(); + ExFac *= -1.0; + } + // + val = time_unit_factor * permeability[0] * matrix_conductivity * ExFac; + break; + //--------------------------------------------------------- + case EPT_HEAT_TRANSPORT: - break; + break; } return val; } -//SB4200 +// SB4200 /*************************************************************************** GeoSys - Funktion: CFiniteElementStd:: CalcAdvection @@ -5148,34 +5037,34 @@ void CFiniteElementStd::CalcAdvection() { int i, j; int gp_r = 0, gp_s = 0, gp_t; - double fkt,mat_factor = 0.0; + double fkt, mat_factor = 0.0; double vel[3], dens_aug[3]; CFluidProperties* m_mfp_g = NULL; bool multiphase = false; - //18.02.2008, 04.09.2008 WW - - // CB _ctx_ - //bool _ctx_ = false; - //double porosity =0; - //if(pcs->type==2){ - // if (cp_vec[pcs->pcs_component_number]->_ctx_Coefficient>0){ - // _ctx_ = true; - // porosity = this->MediaProp->Porosity(Index,this->pcs->m_num->ls_theta); - // } //18.02.2008, 04.09.2008 WW - //} - if(!cpl_pcs && (pcs->type != 2) && (pcs->type != 5)) + // 18.02.2008, 04.09.2008 WW + + // CB _ctx_ + // bool _ctx_ = false; + // double porosity =0; + // if(pcs->type==2){ + // if (cp_vec[pcs->pcs_component_number]->_ctx_Coefficient>0){ + // _ctx_ = true; + // porosity = this->MediaProp->Porosity(Index,this->pcs->m_num->ls_theta); + // } //18.02.2008, 04.09.2008 WW + //} + if (!cpl_pcs && (pcs->type != 2) && (pcs->type != 5)) return; - if(cpl_pcs && cpl_pcs->type == 1212) + if (cpl_pcs && cpl_pcs->type == 1212) { multiphase = true; - m_mfp_g = mfp_vector[1]; + m_mfp_g = mfp_vector[1]; GasProp = MFPGet("GAS"); } ElementValue* gp_ele = ele_gp_value[Index]; CRFProcess* pcs_fluid_momentum = PCSGet("FLUID_MOMENTUM"); std::vector > nodal_vel(3); - if(pcs_fluid_momentum) + if (pcs_fluid_momentum) { /* * get connected nodes @@ -5192,42 +5081,41 @@ void CFiniteElementStd::CalcAdvection() { switch (coordinate_system) { - case 10: // only x-direction - nodal_vel[0][i] = pcs_fluid_momentum->GetNodeValue(connected_nodes[i], pcs_fluid_momentum->_idxVx); - break; - case 11: // only y-direction - nodal_vel[0][i] = pcs_fluid_momentum->GetNodeValue(connected_nodes[i], pcs_fluid_momentum->_idxVy); - break; - case 12: // only z-direction - nodal_vel[0][i] = pcs_fluid_momentum->GetNodeValue(connected_nodes[i], pcs_fluid_momentum->_idxVz); - break; - case 21: // x & y direction - nodal_vel[0][i] = pcs_fluid_momentum->GetNodeValue(connected_nodes[i], pcs_fluid_momentum->_idxVx); - nodal_vel[1][i] = pcs_fluid_momentum->GetNodeValue(connected_nodes[i], pcs_fluid_momentum->_idxVy); - break; - case 22: // x & z direction - nodal_vel[0][i] = pcs_fluid_momentum->GetNodeValue(connected_nodes[i], pcs_fluid_momentum->_idxVx); - nodal_vel[1][i] = pcs_fluid_momentum->GetNodeValue(connected_nodes[i], pcs_fluid_momentum->_idxVz); - break; - case 23: // y & z direction - nodal_vel[0][i] = pcs_fluid_momentum->GetNodeValue(connected_nodes[i], pcs_fluid_momentum->_idxVy); - nodal_vel[1][i] = pcs_fluid_momentum->GetNodeValue(connected_nodes[i], pcs_fluid_momentum->_idxVz); - break; - case 32: // x, y & z direction - nodal_vel[0][i] = pcs_fluid_momentum->GetNodeValue(connected_nodes[i], pcs_fluid_momentum->_idxVx); - nodal_vel[1][i] = pcs_fluid_momentum->GetNodeValue(connected_nodes[i], pcs_fluid_momentum->_idxVy); - nodal_vel[2][i] = pcs_fluid_momentum->GetNodeValue(connected_nodes[i], pcs_fluid_momentum->_idxVz); - break; - default: - std::cout << " Invalid coordinate_system: " << coordinate_system << ". Exiting now." << std::endl; - exit(0); - break; + case 10: // only x-direction + nodal_vel[0][i] = pcs_fluid_momentum->GetNodeValue(connected_nodes[i], pcs_fluid_momentum->_idxVx); + break; + case 11: // only y-direction + nodal_vel[0][i] = pcs_fluid_momentum->GetNodeValue(connected_nodes[i], pcs_fluid_momentum->_idxVy); + break; + case 12: // only z-direction + nodal_vel[0][i] = pcs_fluid_momentum->GetNodeValue(connected_nodes[i], pcs_fluid_momentum->_idxVz); + break; + case 21: // x & y direction + nodal_vel[0][i] = pcs_fluid_momentum->GetNodeValue(connected_nodes[i], pcs_fluid_momentum->_idxVx); + nodal_vel[1][i] = pcs_fluid_momentum->GetNodeValue(connected_nodes[i], pcs_fluid_momentum->_idxVy); + break; + case 22: // x & z direction + nodal_vel[0][i] = pcs_fluid_momentum->GetNodeValue(connected_nodes[i], pcs_fluid_momentum->_idxVx); + nodal_vel[1][i] = pcs_fluid_momentum->GetNodeValue(connected_nodes[i], pcs_fluid_momentum->_idxVz); + break; + case 23: // y & z direction + nodal_vel[0][i] = pcs_fluid_momentum->GetNodeValue(connected_nodes[i], pcs_fluid_momentum->_idxVy); + nodal_vel[1][i] = pcs_fluid_momentum->GetNodeValue(connected_nodes[i], pcs_fluid_momentum->_idxVz); + break; + case 32: // x, y & z direction + nodal_vel[0][i] = pcs_fluid_momentum->GetNodeValue(connected_nodes[i], pcs_fluid_momentum->_idxVx); + nodal_vel[1][i] = pcs_fluid_momentum->GetNodeValue(connected_nodes[i], pcs_fluid_momentum->_idxVy); + nodal_vel[2][i] = pcs_fluid_momentum->GetNodeValue(connected_nodes[i], pcs_fluid_momentum->_idxVz); + break; + default: + std::cout << " Invalid coordinate_system: " << coordinate_system << ". Exiting now." << std::endl; + exit(0); + break; } } } - - //Initial values + // Initial values gp_t = 0; (*Advection) = 0.0; @@ -5241,45 +5129,44 @@ void CFiniteElementStd::CalcAdvection() fkt = GetGaussData(gp, gp_r, gp_s, gp_t); //--------------------------------------------------------- // Compute geometry - ComputeGradShapefct(1); // Linear interpolation function....dNJ-1....var dshapefct - ComputeShapefct(1); // Linear interpolation N....var shapefct + ComputeGradShapefct(1); // Linear interpolation function....dNJ-1....var dshapefct + ComputeShapefct(1); // Linear interpolation N....var shapefct //--------------------------------------------------------- - mat_factor = CalCoefAdvection(); // this should be called after calculating shape functions. NW - //Velocity + mat_factor = CalCoefAdvection(); // this should be called after calculating shape functions. NW + // Velocity vel[0] = mat_factor * gp_ele->Velocity(0, gp); vel[1] = mat_factor * gp_ele->Velocity(1, gp); vel[2] = mat_factor * gp_ele->Velocity(2, gp); - // CB _ctx_ : modify v if _ctx_ flux needs to be included - //if(_ctx_){ - // vel[0] -= porosity * gp_ele->_ctx_Gauss(0,gp); - // vel[1] -= porosity * gp_ele->_ctx_Gauss(1,gp); - // vel[2] -= porosity * gp_ele->_ctx_Gauss(2,gp); - //} + // CB _ctx_ : modify v if _ctx_ flux needs to be included + // if(_ctx_){ + // vel[0] -= porosity * gp_ele->_ctx_Gauss(0,gp); + // vel[1] -= porosity * gp_ele->_ctx_Gauss(1,gp); + // vel[2] -= porosity * gp_ele->_ctx_Gauss(2,gp); + //} // If component is in non - wetting phase, as designated by transport_phase == 10 // SB, BG - if(cp_vec.size() > 0 && this->pcs->pcs_component_number>=0) + if (cp_vec.size() > 0 && this->pcs->pcs_component_number >= 0) // // SB, BG - if(cp_vec[this->pcs->pcs_component_number]->transport_phase == 10) + if (cp_vec[this->pcs->pcs_component_number]->transport_phase == 10) { vel[0] = mat_factor * gp_ele->Velocity_g(0, gp); vel[1] = mat_factor * gp_ele->Velocity_g(1, gp); vel[2] = mat_factor * gp_ele->Velocity_g(2, gp); - } // SB, BG - if(multiphase) //02/2007 WW + } // SB, BG + if (multiphase) // 02/2007 WW { dens_aug[0] = interpolate(NodalVal_p2); dens_aug[1] = interpolate(NodalVal1) + PhysicalConstant::CelsiusZeroInKelvin; rho_gw = 0.0; - if(MediaProp->heat_diffusion_model == 1) + if (MediaProp->heat_diffusion_model == 1) { - PG = interpolate(NodalValC1); + PG = interpolate(NodalValC1); TG = dens_aug[1]; rhow = FluidProp->Density(); - rho_gw = FluidProp->vaporDensity(TG) * - exp(-PG / (rhow * SpecificGasConstant::WaterVapour * TG)); + rho_gw = FluidProp->vaporDensity(TG) * exp(-PG / (rhow * SpecificGasConstant::WaterVapour * TG)); p_gw = rho_gw * SpecificGasConstant::WaterVapour * TG; dens_aug[0] -= p_gw; } - // 29.05.2008. WW/ 2 Dec 2010 AKS + // 29.05.2008. WW/ 2 Dec 2010 AKS rho_g = rho_gw + GasProp->Density(dens_aug); mat_factor = rho_g * m_mfp_g->SpecificHeatCapacity(); vel[0] += mat_factor * gp_ele->Velocity_g(0, gp); @@ -5287,67 +5174,54 @@ void CFiniteElementStd::CalcAdvection() vel[2] += mat_factor * gp_ele->Velocity_g(2, gp); } // Velocity by Fluid_Momentum - 13.11.2009 PCH - if(pcs_fluid_momentum) + if (pcs_fluid_momentum) { for (std::size_t i(0); i < dim; i++) vel[i] = mat_factor * interpolate(&nodal_vel[i][0]); } - #if defined(USE_PETSC) //|| defined (other parallel solver) for (i = 0; i < act_nodes; i++) - { - const int ia = local_idx[i]; - for (j = 0; j < nnodes; j++) - { - for (size_t k = 0; k < dim; k++) - (*Advection)(ia, j) += fkt * shapefct[ia] * vel[k] - * dshapefct[k * nnodes + j]; - } - } + { + const int ia = local_idx[i]; + for (j = 0; j < nnodes; j++) + { + for (size_t k = 0; k < dim; k++) + (*Advection)(ia, j) += fkt * shapefct[ia] * vel[k] * dshapefct[k * nnodes + j]; + } + } #else for (i = 0; i < nnodes; i++) - for (j = 0; j < nnodes; j++) - for (size_t k = 0; k < dim; k++) - (*Advection)(i,j) += fkt * shapefct[i] * vel[k] - * dshapefct[k * nnodes + j]; + for (j = 0; j < nnodes; j++) + for (size_t k = 0; k < dim; k++) + (*Advection)(i, j) += fkt * shapefct[i] * vel[k] * dshapefct[k * nnodes + j]; #endif - if (pcs->m_num->ele_supg_method > 0) //NW + if (pcs->m_num->ele_supg_method > 0) // NW { vel[0] = gp_ele->Velocity(0, gp); vel[1] = gp_ele->Velocity(1, gp); vel[2] = gp_ele->Velocity(2, gp); - if(pcs_fluid_momentum) + if (pcs_fluid_momentum) { CRFProcess* m_pcs = pcs_fluid_momentum; - vel[0] = - m_pcs->GetElementValue(index, m_pcs->GetElementValueIndex( - "VELOCITY1_X") + 1); - vel[1] = - m_pcs->GetElementValue(index, m_pcs->GetElementValueIndex( - "VELOCITY1_Y") + 1); - vel[2] = - m_pcs->GetElementValue(index, m_pcs->GetElementValueIndex( - "VELOCITY1_Z") + 1); + vel[0] = m_pcs->GetElementValue(index, m_pcs->GetElementValueIndex("VELOCITY1_X") + 1); + vel[1] = m_pcs->GetElementValue(index, m_pcs->GetElementValueIndex("VELOCITY1_Y") + 1); + vel[2] = m_pcs->GetElementValue(index, m_pcs->GetElementValueIndex("VELOCITY1_Z") + 1); } double tau = 0; CalcSUPGWeightingFunction(vel, gp, tau, weight_func); - //Calculate mat_factor*tau*({v}[dN])^T*({v}[dN]) + // Calculate mat_factor*tau*({v}[dN])^T*({v}[dN]) for (i = 0; i < nnodes; i++) for (j = 0; j < nnodes; j++) - (*Advection)(i, - j) += fkt * mat_factor * tau * - weight_func[i] * - weight_func[j]; + (*Advection)(i, j) += fkt * mat_factor * tau * weight_func[i] * weight_func[j]; } } - //TEST OUTPUT - //cout << "Advection Matrix: " << "\n"; Advection->Write(); - } - + // TEST OUTPUT + // cout << "Advection Matrix: " << "\n"; Advection->Write(); +} /*************************************************************************** FEMLib-Method: @@ -5358,7 +5232,7 @@ void CFiniteElementStd::CalcAdvection() **************************************************************************/ void CFiniteElementStd::CalcAdvectionMCF() { - int gp_r = 0, gp_s = 0, gp_t = 0, i, j, in, jn, nDF=pcs->dof, Index = MeshElement->GetIndex(); + int gp_r = 0, gp_s = 0, gp_t = 0, i, j, in, jn, nDF = pcs->dof, Index = MeshElement->GetIndex(); double fkt, vel[3]; ElementValue* gp_ele = ele_gp_value[Index]; CalCoefAdvectionMCF(); @@ -5371,27 +5245,27 @@ void CFiniteElementStd::CalcAdvectionMCF() vel[1] = gp_ele->Velocity(1, gp); vel[2] = gp_ele->Velocity(2, gp); - for (in = 0; in < nDF; in++) + for (in = 0; in < nDF; in++) { - const int ish = in * nnodes; - for (jn = 0; jn < nDF; jn++) + const int ish = in * nnodes; + for (jn = 0; jn < nDF; jn++) { - const int jsh = jn * nnodes; + const int jsh = jn * nnodes; for (i = 0; i < nnodes; i++) { for (j = 0; j < nnodes; j++) { - for (size_t k = 0; k < dim; k++) + for (size_t k = 0; k < dim; k++) { - (*Advection)(i + ish, j + jsh) += fkt*AdvectionMatrixElements[in*nDF + jn]*shapefct[i]*vel[k]*dshapefct[k*nnodes + j]; - } - } - } - } - } - } - } - + (*Advection)(i + ish, j + jsh) += fkt * AdvectionMatrixElements[in * nDF + jn] * shapefct[i] + * vel[k] * dshapefct[k * nnodes + j]; + } + } + } + } + } + } +} /*************************************************************************** FEMLib-Method: @@ -5402,49 +5276,53 @@ void CFiniteElementStd::CalcAdvectionMCF() **************************************************************************/ void CFiniteElementStd::CalcContentMCF() { - int gp_r = 0, gp_s = 0, gp_t = 0, in, i, j, nDF=pcs->dof; + int gp_r = 0, gp_s = 0, gp_t = 0, in, i, j, nDF = pcs->dof; double fkt; CalCoefContentMCF(); for (gp = 0; gp < nGaussPoints; gp++) { - fkt = GetGaussData(gp, gp_r, gp_s, gp_t); - ComputeShapefct(1); - for (in = 0; in < nDF; in++) - { - const int ish = in * nnodes; - for (i = 0; i< nnodes; i++) - { - for (j = 0; j< nnodes; j++) - { - (*Content)(i + ish, j + ish) += fkt*ContentMatrixElements[in*nDF + in]*shapefct[i]*shapefct[j]; - } - } - } + fkt = GetGaussData(gp, gp_r, gp_s, gp_t); + ComputeShapefct(1); + for (in = 0; in < nDF; in++) + { + const int ish = in * nnodes; + for (i = 0; i < nnodes; i++) + { + for (j = 0; j < nnodes; j++) + { + (*Content)(i + ish, j + ish) + += fkt * ContentMatrixElements[in * nDF + in] * shapefct[i] * shapefct[j]; + } + } + } } } - /************************************************************************** - FEMLib-Method: - Task: Calculate material coefficient for contant matrix for - MULTI COMPONENTIAL FLOW Global Approach - Implementaion: - 03/2011 AKS - **************************************************************************/ +/************************************************************************** +FEMLib-Method: +Task: Calculate material coefficient for contant matrix for +MULTI COMPONENTIAL FLOW Global Approach +Implementaion: +03/2011 AKS + **************************************************************************/ void CFiniteElementStd::CalCoefContentMCF() { - int in, nDF=pcs->dof, Index = MeshElement->GetIndex(); + int in, nDF = pcs->dof, Index = MeshElement->GetIndex(); double retardation_factore[4], arg_PV[6], rho; - for(in = 0; in < nDF * nDF; in++) ContentMatrixElements[in] = 0.0; - if(FluidProp->cmpN > 0) + for (in = 0; in < nDF * nDF; in++) + ContentMatrixElements[in] = 0.0; + if (FluidProp->cmpN > 0) { - ComputeShapefct(1); - for(in = 0; in < nDF; in++) arg_PV[in] = interpolate(NodalValue[in]); - rho = FluidProp->Density(arg_PV); - poro = MediaProp->Porosity(Index, pcs->m_num->ls_theta); - for(in = 0; inDensity(0)*FluidProp->Kd[in]*pow(poro, -1.0); - for(in = 2; in < nDF; in++) - ContentMatrixElements[(nDF + 1)*in] = poro*rho*retardation_factore[in - 2]*FluidProp->lambda[in-2]; + ComputeShapefct(1); + for (in = 0; in < nDF; in++) + arg_PV[in] = interpolate(NodalValue[in]); + rho = FluidProp->Density(arg_PV); + poro = MediaProp->Porosity(Index, pcs->m_num->ls_theta); + for (in = 0; in < nDF - 2; in++) + retardation_factore[in] = 1.0 + (1.0 - poro) * SolidProp->Density(0) * FluidProp->Kd[in] * pow(poro, -1.0); + for (in = 2; in < nDF; in++) + ContentMatrixElements[(nDF + 1) * in] + = poro * rho * retardation_factore[in - 2] * FluidProp->lambda[in - 2]; } - } /*************************************************************************** GeoSys - Funktion: @@ -5471,7 +5349,7 @@ void CFiniteElementStd::CalcRHS_by_ThermalDiffusion() double beta = 0.0; // 12.12.2007 WW long cshift = 0; - if(pcs->dof > 1) + if (pcs->dof > 1) cshift = NodeShift[pcs->continuum]; (*Laplace) = 0.0; @@ -5488,24 +5366,24 @@ void CFiniteElementStd::CalcRHS_by_ThermalDiffusion() //--------------------------------------------------------- // Compute geometry - ComputeGradShapefct(1); // Linear interpolation function + ComputeGradShapefct(1); // Linear interpolation function //--------------------------------------------------------- ComputeShapefct(1); double rhow = FluidProp->Density(); PG = interpolate(NodalVal1); TG = interpolate(NodalValC) + PhysicalConstant::CelsiusZeroInKelvin; - //WW + // WW Sw = MediaProp->SaturationCapillaryPressureFunction(-PG); - poro = MediaProp->Porosity(Index,pcs->m_num->ls_theta); - tort = MediaProp->TortuosityFunction(Index,unit,pcs->m_num->ls_theta); - beta = poro * MediaProp->StorageFunction(Index,unit,pcs->m_num->ls_theta) * Sw; + poro = MediaProp->Porosity(Index, pcs->m_num->ls_theta); + tort = MediaProp->TortuosityFunction(Index, unit, pcs->m_num->ls_theta); + beta = poro * MediaProp->StorageFunction(Index, unit, pcs->m_num->ls_theta) * Sw; humi = exp(PG / (SpecificGasConstant::WaterVapour * TG * rhow)); - Dv = MediaProp->base_heat_diffusion_coefficient * tort * (1 - Sw) * poro - * pow(TG / PhysicalConstant::CelsiusZeroInKelvin, 1.8); + Dv = MediaProp->base_heat_diffusion_coefficient * tort * (1 - Sw) * poro + * pow(TG / PhysicalConstant::CelsiusZeroInKelvin, 1.8); rhov = humi * FluidProp->vaporDensity(TG); - drdT = - (FluidProp->vaporDensity_derivative(TG) * humi - rhov * PG / - (SpecificGasConstant::WaterVapour * rhow * TG * TG)) / rhow; + drdT = (FluidProp->vaporDensity_derivative(TG) * humi + - rhov * PG / (SpecificGasConstant::WaterVapour * rhow * TG * TG)) + / rhow; Dtv = time_unit_factor * Dv * drdT; // } @@ -5514,24 +5392,20 @@ void CFiniteElementStd::CalcRHS_by_ThermalDiffusion() for (i = 0; i < nnodes; i++) for (j = 0; j < nnodes; j++) { - if(j > i) + if (j > i) continue; for (size_t k = 0; k < dim; k++) - (*Laplace)(i,j) += fkt * Dtv * dshapefct[k * nnodes + i] - * dshapefct[k * nnodes + j]; - (*Mass)(i, - j) += fkt * poro * - (beta + - (1.0 - Sw) * drdT) * shapefct[i] * shapefct[j]; + (*Laplace)(i, j) += fkt * Dtv * dshapefct[k * nnodes + i] * dshapefct[k * nnodes + j]; + (*Mass)(i, j) += fkt * poro * (beta + (1.0 - Sw) * drdT) * shapefct[i] * shapefct[j]; } } // Symmetry for (i = 0; i < nnodes; i++) for (j = 0; j < nnodes; j++) { - if(j <= i) + if (j <= i) continue; - (*Laplace)(i,j) = (*Laplace)(j,i); + (*Laplace)(i, j) = (*Laplace)(j, i); } cshift += NodeShift[problem_dimension_dm]; @@ -5539,14 +5413,13 @@ void CFiniteElementStd::CalcRHS_by_ThermalDiffusion() { for (j = 0; j < nnodes; j++) { - (*RHS)[i] -= (*Laplace)(i,j) * (NodalValC[j] + PhysicalConstant::CelsiusZeroInKelvin); - (*RHS)[i] += (*Mass)(i,j) * (NodalValC1[j] - NodalValC[j]) / dt; + (*RHS)[i] -= (*Laplace)(i, j) * (NodalValC[j] + PhysicalConstant::CelsiusZeroInKelvin); + (*RHS)[i] += (*Mass)(i, j) * (NodalValC1[j] - NodalValC[j]) / dt; } - eqs_rhs[cshift + eqs_number[i]] - += (*RHS)[i]; + eqs_rhs[cshift + eqs_number[i]] += (*RHS)[i]; } - //TEST OUTPUT + // TEST OUTPUT // Laplace->Write(); // Mass->Write(); // RHS->Write(); @@ -5566,45 +5439,45 @@ void CFiniteElementStd::SetHighOrderNodes() int i = 0; setOrder(2); // Swap cordinates in case of (x, 0.0, z) only for 2D problem - if(coordinate_system % 10 == 2) // Z has number + if (coordinate_system % 10 == 2) // Z has number { - switch(dim) + switch (dim) { - case 1: - for (i = 0; i < nNodes; i++) - { -// X[i] = MeshElement->nodes[i]->Z(); -// Y[i] = MeshElement->nodes[i]->Y(); -// Z[i] = MeshElement->nodes[i]->X(); - double const* const coords (MeshElement->nodes[i]->getData()); - X[i] = coords[2]; - Y[i] = coords[1]; - Z[i] = coords[0]; - } - break; - case 2: - for (i = 0; i < nNodes; i++) - { -// X[i] = MeshElement->nodes[i]->X(); -// Y[i] = MeshElement->nodes[i]->Z(); -// Z[i] = MeshElement->nodes[i]->Y(); - double const* const coords (MeshElement->nodes[i]->getData()); - X[i] = coords[0]; - Y[i] = coords[2]; - Z[i] = coords[1]; - } - break; - case 3: - for (i = nnodes; i < nnodesHQ; i++) - { -// X[i] = MeshElement->nodes[i]->X(); -// Y[i] = MeshElement->nodes[i]->Y(); -// Z[i] = MeshElement->nodes[i]->Z(); - double const* const coords (MeshElement->nodes[i]->getData()); - X[i] = coords[0]; - Y[i] = coords[1]; - Z[i] = coords[2]; - } + case 1: + for (i = 0; i < nNodes; i++) + { + // X[i] = MeshElement->nodes[i]->Z(); + // Y[i] = MeshElement->nodes[i]->Y(); + // Z[i] = MeshElement->nodes[i]->X(); + double const* const coords(MeshElement->nodes[i]->getData()); + X[i] = coords[2]; + Y[i] = coords[1]; + Z[i] = coords[0]; + } + break; + case 2: + for (i = 0; i < nNodes; i++) + { + // X[i] = MeshElement->nodes[i]->X(); + // Y[i] = MeshElement->nodes[i]->Z(); + // Z[i] = MeshElement->nodes[i]->Y(); + double const* const coords(MeshElement->nodes[i]->getData()); + X[i] = coords[0]; + Y[i] = coords[2]; + Z[i] = coords[1]; + } + break; + case 3: + for (i = nnodes; i < nnodesHQ; i++) + { + // X[i] = MeshElement->nodes[i]->X(); + // Y[i] = MeshElement->nodes[i]->Y(); + // Z[i] = MeshElement->nodes[i]->Z(); + double const* const coords(MeshElement->nodes[i]->getData()); + X[i] = coords[0]; + Y[i] = coords[1]; + Z[i] = coords[2]; + } } } else @@ -5612,10 +5485,10 @@ void CFiniteElementStd::SetHighOrderNodes() if (dim == 1 || dim == 2) for (i = nnodes; i < nnodesHQ; i++) { -// X[i] = MeshElement->nodes[i]->X(); -// Y[i] = MeshElement->nodes[i]->Y(); -// Z[i] = MeshElement->nodes[i]->Z(); - double const* const coords (MeshElement->nodes[i]->getData()); + // X[i] = MeshElement->nodes[i]->X(); + // Y[i] = MeshElement->nodes[i]->Y(); + // Z[i] = MeshElement->nodes[i]->Z(); + double const* const coords(MeshElement->nodes[i]->getData()); X[i] = coords[0]; Y[i] = coords[1]; Z[i] = coords[2]; @@ -5637,35 +5510,36 @@ void CFiniteElementStd::CalcStrainCoupling(int phase) double fkt, du = 0.0; SetHighOrderNodes(); // Loop over Gauss points - for (gp = 0; gp < nGaussPoints; gp++) - { - fkt = GetGaussData(gp, gp_r, gp_s, gp_t); + for (gp = 0; gp < nGaussPoints; gp++) + { + fkt = GetGaussData(gp, gp_r, gp_s, gp_t); - ComputeGradShapefct(2); - ComputeShapefct(1); - ComputeShapefct(2); - // - fkt *= CalCoefStrainCouping(phase); - for(size_t i = 0; i < dim; i++ ) - { - for (int k = 0; k < nnodes; k++) - for (int l = 0; l < nnodesHQ; l++) - { - kl = nnodesHQ * i + l; - du = dshapefctHQ[kl]; - if(i == 0 && axisymmetry) - du += shapefctHQ[l] / Radius; - (*StrainCoupling)(k, kl) += shapefct[k] * du * fkt; - } - } + ComputeGradShapefct(2); + ComputeShapefct(1); + ComputeShapefct(2); + // + fkt *= CalCoefStrainCouping(phase); + for (size_t i = 0; i < dim; i++) + { + for (int k = 0; k < nnodes; k++) + for (int l = 0; l < nnodesHQ; l++) + { + kl = nnodesHQ * i + l; + du = dshapefctHQ[kl]; + if (i == 0 && axisymmetry) + du += shapefctHQ[l] / Radius; + (*StrainCoupling)(k, kl) += shapefct[k] * du * fkt; + } } + } setOrder(1); // StrainCoupling->Write(); /// Ouput the matrix, 07.2011. WW - if(pcs->matrix_file) + if (pcs->matrix_file) { - (*pcs->matrix_file) << "---Strain couping matrix: " << "\n"; + (*pcs->matrix_file) << "---Strain couping matrix: " + << "\n"; StrainCoupling->Write(*pcs->matrix_file); } } @@ -5686,7 +5560,7 @@ void CFiniteElementStd::CalcStrainCoupling(int phase) void CFiniteElementStd::Assemble_Gravity() { int Index = MeshElement->GetIndex(); - if((coordinate_system) % 10 != 2) //NW: exclude (!axisymmetry) + if ((coordinate_system) % 10 != 2) // NW: exclude (!axisymmetry) // 27.2.2007 WW (*GravityMatrix) = 0.0; return; @@ -5694,33 +5568,32 @@ void CFiniteElementStd::Assemble_Gravity() // ---- Gauss integral int gp_r = 0, gp_s = 0, gp_t; gp_t = 0; - double fkt, rho; //, rich_f; + double fkt, rho; //, rich_f; // GEO - //NW double geo_fac = MediaProp->geo_area; - if(!FluidProp->CheckGravityCalculation()) + // NW double geo_fac = MediaProp->geo_area; + if (!FluidProp->CheckGravityCalculation()) return; - long cshift = 0; //WW + long cshift = 0; // WW // // // TODO [CL] shouldn't that be equal to pcs->dof? - int dof_n = 1; // 27.2.2007 WW - if(PcsType == EPT_MULTIPHASE_FLOW || PcsType == EPT_PSGLOBAL) + int dof_n = 1; // 27.2.2007 WW + if (PcsType == EPT_MULTIPHASE_FLOW || PcsType == EPT_PSGLOBAL) { dof_n = 2; } - else if (PcsType == EPT_THERMAL_NONEQUILIBRIUM - || PcsType == EPT_TES) + else if (PcsType == EPT_THERMAL_NONEQUILIBRIUM || PcsType == EPT_TES) { dof_n = 4; } - //WW 05.01.07 + // WW 05.01.07 cshift = 0; - if(pcs->dof > 1) + if (pcs->dof > 1) cshift = NodeShift[pcs->continuum]; - //rich_f = 1.0; - //if(PcsType==R) rich_f = -1.0; //WW + // rich_f = 1.0; + // if(PcsType==R) rich_f = -1.0; //WW for (i = 0; i < dof_n * nnodes; i++) NodalVal[i] = 0.0; @@ -5737,83 +5610,79 @@ void CFiniteElementStd::Assemble_Gravity() //--------------------------------------------------------- // Compute geometry //--------------------------------------------------------- - ComputeGradShapefct(1); // Linear interpolation function - ComputeShapefct(1); // Moved from CalCoefLaplace(). 12.3.2007 WW + ComputeGradShapefct(1); // Linear interpolation function + ComputeShapefct(1); // Moved from CalCoefLaplace(). 12.3.2007 WW // Material - if (PcsType == EPT_THERMAL_NONEQUILIBRIUM - || PcsType == EPT_TES) + if (PcsType == EPT_THERMAL_NONEQUILIBRIUM || PcsType == EPT_TES) { - double dens_arg[] = { - interpolate(NodalVal0), // pressure - interpolate(NodalVal_t0), // temperature - (double) Index - }; + double dens_arg[] = {interpolate(NodalVal0), // pressure + interpolate(NodalVal_t0), // temperature + (double)Index}; rho = FluidProp->Density(dens_arg); } else { rho = FluidProp->Density(); } - if(gravity_constant < MKleinsteZahl) // HEAD version + if (gravity_constant < MKleinsteZahl) // HEAD version rho = 1.0; - else if(HEAD_Flag) + else if (HEAD_Flag) rho = 1.0; else rho *= gravity_constant; - fkt *= rho; //*rich_f; + fkt *= rho; //*rich_f; // - for(ii = 0; ii < dof_n; ii++) + for (ii = 0; ii < dof_n; ii++) { - if(dof_n == 1) + if (dof_n == 1) { - if(PcsType == EPT_TWOPHASE_FLOW) + if (PcsType == EPT_TWOPHASE_FLOW) CalCoefLaplace(false); else CalCoefLaplace(true); } - if(dof_n == 2) + if (dof_n == 2) { - if(PcsType == EPT_MULTIPHASE_FLOW) + if (PcsType == EPT_MULTIPHASE_FLOW) CalCoefLaplace2(true, ii * dof_n + 1); - else if(PcsType == EPT_PSGLOBAL) + else if (PcsType == EPT_PSGLOBAL) CalCoefLaplacePSGLOBAL(true, ii * dof_n); } - else if(dof_n == 4) + else if (dof_n == 4) { - if(PcsType == EPT_THERMAL_NONEQUILIBRIUM) - CalCoefLaplaceTNEQ(ii*dof_n); - else if(PcsType == EPT_TES) - CalCoefLaplaceTES(ii*dof_n); + if (PcsType == EPT_THERMAL_NONEQUILIBRIUM) + CalCoefLaplaceTNEQ(ii * dof_n); + else if (PcsType == EPT_TES) + CalCoefLaplaceTES(ii * dof_n); } // Calculate mass matrix - const int iinn = ii * nnodes; //19.06.2012. WW + const int iinn = ii * nnodes; // 19.06.2012. WW #if defined(USE_PETSC) //|| defined (other parallel solver) //19.06.2012 for (int ia = 0; ia < act_nodes; ia++) - { - const int i = local_idx[ia]; + { + const int i = local_idx[ia]; #else - for (i = 0; i < nnodes; i++) - { + for (i = 0; i < nnodes; i++) + { #endif - const int ipiinn = iinn + i; //19.06.2012. WW - for (size_t k = 0; k < dim; k++) - { - NodalVal[ipiinn] -= fkt * - dshapefct[k * nnodes + i] * mat[dim * k + dim - 1]; - } - } + const int ipiinn = iinn + i; // 19.06.2012. WW + for (size_t k = 0; k < dim; k++) + { + NodalVal[ipiinn] -= fkt * dshapefct[k * nnodes + i] * mat[dim * k + dim - 1]; + } + } } } // /// 02.2011. WW int dm_shift = 0; - if(pcs->type / 10 == 4) + if (pcs->type / 10 == 4) dm_shift = problem_dimension_dm; int ii_sh = 0; - for(ii = 0; ii < dof_n; ii++) // 07.02.07 WW + for (ii = 0; ii < dof_n; ii++) // 07.02.07 WW { - if(pcs->type == 22 ) // Dual porosity model. 06.2011. WW + if (pcs->type == 22) // Dual porosity model. 06.2011. WW cshift += NodeShift[ii + dm_shift]; else cshift = NodeShift[ii + dm_shift]; @@ -5821,84 +5690,90 @@ void CFiniteElementStd::Assemble_Gravity() for (i = 0; i < nnodes; i++) { #if !defined(USE_PETSC) // && defined(other parallel libs)//03~04.3012. WW - eqs_rhs[cshift + eqs_number[i]] - += NodalVal[i + ii_sh]; // *k_rel_iteration - //NW not necessary to multiply geo_area(geo_fac) here. It's already multiplied in ComputeJacobian() through fkt. - // eqs_rhs[cshift + eqs_number[i]] - // += k_rel_iteration* geo_fac*NodalVal[i+ii_sh]; + eqs_rhs[cshift + eqs_number[i]] += NodalVal[i + ii_sh]; // *k_rel_iteration +// NW not necessary to multiply geo_area(geo_fac) here. It's already multiplied in ComputeJacobian() through fkt. +// eqs_rhs[cshift + eqs_number[i]] +// += k_rel_iteration* geo_fac*NodalVal[i+ii_sh]; #endif (*RHS)[i + LocalShift + ii_sh] += NodalVal[i + ii_sh]; } } - //TEST OUTPUT - //RHS->Write(); + // TEST OUTPUT + // RHS->Write(); } /*************************************************************************** - FEMLib-Method: - Task: Calculation of bouyancy for - MULTI COMPONENTIAL FLOW Global Approach - Implementaion: - 03/2011 AKS + FEMLib-Method: + Task: Calculation of bouyancy for + MULTI COMPONENTIAL FLOW Global Approach + Implementaion: + 03/2011 AKS **************************************************************************/ void CFiniteElementStd::Assemble_GravityMCF() { - if((coordinate_system) % 10 != 2 && (!axisymmetry)) - return; - int i, j, in, nDF=pcs->dof; + if ((coordinate_system) % 10 != 2 && (!axisymmetry)) + return; + int i, j, in, nDF = pcs->dof; // ---- Gauss integral int gp_r = 0, gp_s = 0, gp_t; gp_t = 0; double* tensor = NULL; double fkt, mat_fac, arg_PV[6], gravity_vector[3], rho; long cshift = 0; - for (in = 0; in < nDF*nnodes; in++) NodalVal[in] = 0.0; + for (in = 0; in < nDF * nnodes; in++) + NodalVal[in] = 0.0; cshift = 0; - if(nDF > 1) - cshift = NodeShift[pcs->continuum]; - for(size_t k = 0; k < dim; k++) gravity_vector[k] = 0.0; - if((coordinate_system) % 10 == 2 && (!HEAD_Flag)) - { - gravity_vector[dim - 1] = gravity_constant; - if(dim == 3 && ele_dim == 1 && MediaProp->geo_inclination > 0)//1D fractured media + if (nDF > 1) + cshift = NodeShift[pcs->continuum]; + for (size_t k = 0; k < dim; k++) + gravity_vector[k] = 0.0; + if ((coordinate_system) % 10 == 2 && (!HEAD_Flag)) { - gravity_vector[0] = gravity_constant*cos(PI*MediaProp->geo_inclination/180)*sin(PI*MediaProp->geo_inclination/180); - gravity_vector[dim - 1] = gravity_constant*sin(PI*MediaProp->geo_inclination/180)*sin(PI*MediaProp->geo_inclination/180); - } + gravity_vector[dim - 1] = gravity_constant; + if (dim == 3 && ele_dim == 1 && MediaProp->geo_inclination > 0) // 1D fractured media + { + gravity_vector[0] = gravity_constant * cos(PI * MediaProp->geo_inclination / 180) + * sin(PI * MediaProp->geo_inclination / 180); + gravity_vector[dim - 1] = gravity_constant * sin(PI * MediaProp->geo_inclination / 180) + * sin(PI * MediaProp->geo_inclination / 180); + } } ComputeShapefct(1); - for(in = 0; in < nDF; in++) arg_PV[in] = interpolate(NodalValue[in]); + for (in = 0; in < nDF; in++) + arg_PV[in] = interpolate(NodalValue[in]); mat_fac = FluidProp->Density(arg_PV); // Loop over Gauss points for (gp = 0; gp < nGaussPoints; gp++) { - fkt = GetGaussData(gp, gp_r, gp_s, gp_t); - //--------------------------------------------------------- - ComputeGradShapefct(1); // Linear interpolation function - ComputeShapefct(1); - tensor = MediaProp->DispersionTensorMCF(gp, 0, 0, arg_PV); - for (j = 0; j < nnodes; j++) - { - for(in = 0; in GetNodeValue(nodes[j], idxMCF[in + nDF]);//current PV - // - rho = FluidProp->Density(arg_PV); - // - for (i = 0; i < nnodes; i++) - { - for (size_t k = 0; k < dim; k++) - { - NodalVal[i] -= fkt*mat_fac*tensor[dim*k + dim - 1]*dshapefct[k* nnodes + i]*shapefct[j]*rho*gravity_vector[k]; - } - } - } + fkt = GetGaussData(gp, gp_r, gp_s, gp_t); + //--------------------------------------------------------- + ComputeGradShapefct(1); // Linear interpolation function + ComputeShapefct(1); + tensor = MediaProp->DispersionTensorMCF(gp, 0, 0, arg_PV); + for (j = 0; j < nnodes; j++) + { + for (in = 0; in < nDF; in++) + arg_PV[in] = pcs->GetNodeValue(nodes[j], idxMCF[in + nDF]); // current PV + // + rho = FluidProp->Density(arg_PV); + // + for (i = 0; i < nnodes; i++) + { + for (size_t k = 0; k < dim; k++) + { + NodalVal[i] -= fkt * mat_fac * tensor[dim * k + dim - 1] * dshapefct[k * nnodes + i] * shapefct[j] + * rho * gravity_vector[k]; + } + } + } } cshift += NodeShift[problem_dimension_dm]; cshift += NodeShift[0]; for (i = 0; i < nnodes; i++) { - eqs_rhs[cshift + eqs_number[i]] += NodalVal[i]; - (*RHS)[i + LocalShift] += NodalVal[i]; + eqs_rhs[cshift + eqs_number[i]] += NodalVal[i]; + (*RHS)[i + LocalShift] += NodalVal[i]; } - //RHS->Write(); + // RHS->Write(); } /*************************************************************************** @@ -5914,34 +5789,34 @@ void CFiniteElementStd::Assemble_GravityMCF() // Local assembly void CFiniteElementStd::Assemble_Gravity_Multiphase() { - if((coordinate_system) % 10 != 2 && (!axisymmetry)) + if ((coordinate_system) % 10 != 2 && (!axisymmetry)) // 27.2.2007 WW (*GravityMatrix) = 0.0; return; int i, ii; // ---- Gauss integral int gp_r = 0, gp_s = 0, gp_t; gp_t = 0; - double fkt, rho; //, rich_f; - //double k_rel_iteration; + double fkt, rho; //, rich_f; + // double k_rel_iteration; // GEO - if(!FluidProp->CheckGravityCalculation()) + if (!FluidProp->CheckGravityCalculation()) return; - long cshift = 0; //WW + long cshift = 0; // WW // // - int dof_n = 1; // 27.2.2007 WW - if(PcsType == EPT_MULTIPHASE_FLOW) + int dof_n = 1; // 27.2.2007 WW + if (PcsType == EPT_MULTIPHASE_FLOW) dof_n = 2; - //WW 05.01.07 + // WW 05.01.07 cshift = 0; - if(pcs->dof > 1) + if (pcs->dof > 1) cshift = NodeShift[pcs->continuum]; - //rich_f = 1.0; - //if(PcsType==R) rich_f = -1.0; //WW + // rich_f = 1.0; + // if(PcsType==R) rich_f = -1.0; //WW - //k_rel_iteration = 1.0; + // k_rel_iteration = 1.0; for (i = 0; i < dof_n * nnodes; i++) NodalVal[i] = 0.0; @@ -5958,8 +5833,8 @@ void CFiniteElementStd::Assemble_Gravity_Multiphase() //--------------------------------------------------------- // Compute geometry //--------------------------------------------------------- - ComputeGradShapefct(1); // Linear interpolation function - ComputeShapefct(1); // Moved from CalCoefLaplace(). 12.3.2007 WW + ComputeGradShapefct(1); // Linear interpolation function + ComputeShapefct(1); // Moved from CalCoefLaplace(). 12.3.2007 WW // Material // PCH // Pressure equation is the sum of all pressures for all the phases @@ -5967,15 +5842,15 @@ void CFiniteElementStd::Assemble_Gravity_Multiphase() // solving the pressure or saturation equation. // Thus, the gravity term for the presure equations should cover // two phases. - if(pcs->pcs_type_number == 0) // if the pressure equation, + if (pcs->pcs_type_number == 0) // if the pressure equation, { int numOfPhases = 2; - for(int p = 0; p < numOfPhases; ++p) + for (int p = 0; p < numOfPhases; ++p) { rho = mfp_vector[p]->Density(); - if(gravity_constant < MKleinsteZahl) // HEAD version + if (gravity_constant < MKleinsteZahl) // HEAD version rho = 1.0; - else if(HEAD_Flag) + else if (HEAD_Flag) rho = 1.0; else rho *= gravity_constant; @@ -5984,56 +5859,48 @@ void CFiniteElementStd::Assemble_Gravity_Multiphase() fkt = GetGaussData(gp, gp_r, gp_s, gp_t); fkt *= rho; //*rich_f; - for(ii = 0; ii < dof_n; ii++) + for (ii = 0; ii < dof_n; ii++) { // CalCoefLaplace does the sumation mat_fac for twophase flow. // This is not right for two phase gravity terms, because the equation // is not summable this way. It should be seperated. - if(dof_n == 1) + if (dof_n == 1) CalCoefLaplaceMultiphase(p); - if(dof_n == 2) + if (dof_n == 2) CalCoefLaplace2(false, ii * dof_n + 1); // Calculate mass matrix for (i = 0; i < nnodes; i++) for (size_t k = 0; k < dim; k++) - NodalVal[i + ii * - nnodes] -= fkt * - dshapefct[k * nnodes + - i] * - mat[dim * k + dim - 1]; + NodalVal[i + ii * nnodes] -= fkt * dshapefct[k * nnodes + i] * mat[dim * k + dim - 1]; } } } else { rho = mfp_vector[1]->Density(); - if(gravity_constant < MKleinsteZahl) // HEAD version + if (gravity_constant < MKleinsteZahl) // HEAD version rho = 1.0; - else if(HEAD_Flag) + else if (HEAD_Flag) rho = 1.0; else rho *= gravity_constant; - fkt *= rho; //*rich_f; + fkt *= rho; //*rich_f; - for(ii = 0; ii < dof_n; ii++) + for (ii = 0; ii < dof_n; ii++) { // CalCoefLaplace does the sumation mat_fac for twophase flow. // This is not right for two phase gravity terms, because the equation // is not summable this way. It should be seperated. - if(dof_n == 1) + if (dof_n == 1) CalCoefLaplace(false); - if(dof_n == 2) + if (dof_n == 2) CalCoefLaplace2(false, ii * dof_n + 1); // Calculate mass matrix for (i = 0; i < nnodes; i++) for (size_t k = 0; k < dim; k++) - NodalVal[i + ii * - nnodes] -= fkt * - dshapefct[k * nnodes + - i] * - mat[dim * k + dim - 1]; + NodalVal[i + ii * nnodes] -= fkt * dshapefct[k * nnodes + i] * mat[dim * k + dim - 1]; } } } @@ -6041,21 +5908,20 @@ void CFiniteElementStd::Assemble_Gravity_Multiphase() // cshift += NodeShift[problem_dimension_dm]; // 05.01.07 WW int ii_sh = 0; - for(ii = 0; ii < dof_n; ii++) // 07.02.07 WW + for (ii = 0; ii < dof_n; ii++) // 07.02.07 WW { cshift += NodeShift[ii]; ii_sh = ii * nnodes; for (i = 0; i < nnodes; i++) { #if !defined(USE_PETSC) // && defined(other parallel libs)//03~04.3012. WW - eqs_rhs[cshift + eqs_number[i]] - += MediaProp->geo_area * NodalVal[i + ii_sh]; // *k_rel_iteration + eqs_rhs[cshift + eqs_number[i]] += MediaProp->geo_area * NodalVal[i + ii_sh]; // *k_rel_iteration #endif (*RHS)[i + LocalShift + ii_sh] += NodalVal[i + ii_sh]; } } - //TEST OUTPUT - //RHS->Write(); + // TEST OUTPUT + // RHS->Write(); } //////////////////////////////////////////////////////////////// /* @@ -6146,9 +6012,9 @@ void CFiniteElementStd::Assemble_Gravity_Multiphase() /** * @brief Wrapper function to interface conversion_rate with SUNDIALS CVode solver */ -int cvRhsFn_conversion_rate(realtype t, N_Vector y, N_Vector ydot, void *user_data) +int cvRhsFn_conversion_rate(realtype t, N_Vector y, N_Vector ydot, void* user_data) { - conversion_rate& conv_rate = *(conversion_rate*) user_data; + conversion_rate& conv_rate = *(conversion_rate*)user_data; Eigen::VectorXd y_eig = Eigen::VectorXd::Zero(1); y_eig(0) = NV_Ith_S(y, 0); @@ -6170,7 +6036,8 @@ int cvRhsFn_conversion_rate(realtype t, N_Vector y, N_Vector ydot, void *user_da * @param y_fin output parameter of y at the end of integration * @param dydt_fin output parameter of dy/dt at the end of integration */ -void cvode_conversion_rate(const double y_ini, double delta_t, conversion_rate* conv_rate, double& y_fin, double& dydt_fin) +void cvode_conversion_rate(const double y_ini, double delta_t, conversion_rate* conv_rate, double& y_fin, + double& dydt_fin) { const realtype T0 = 0.0; const int NEQ = 1; @@ -6183,14 +6050,14 @@ void cvode_conversion_rate(const double y_ini, double delta_t, conversion_rate* // set initial condition // rho_s, reactive fraction - NV_Ith_S(y,0) = y_ini; + NV_Ith_S(y, 0) = y_ini; /* Set the scalar relative tolerance */ realtype reltol = 1e-10; /* Set the vector absolute tolerance */ - NV_Ith_S(abstol,1) = 1e-10; + NV_Ith_S(abstol, 1) = 1e-10; - void *cvode_mem = CVodeCreate(CV_ADAMS, CV_FUNCTIONAL); + void* cvode_mem = CVodeCreate(CV_ADAMS, CV_FUNCTIONAL); // if (check_flag((void *)cvode_mem, "CVodeCreate", 0)) return(1); /* Call CVodeInit to initialize the integrator memory and specify the @@ -6199,7 +6066,7 @@ void cvode_conversion_rate(const double y_ini, double delta_t, conversion_rate* int flag = CVodeInit(cvode_mem, cvRhsFn_conversion_rate, T0, y); // if (check_flag(&flag, "CVodeInit", 1)) return(1); - flag = CVodeSetUserData(cvode_mem, (void*) conv_rate); + flag = CVodeSetUserData(cvode_mem, (void*)conv_rate); /* Call CVodeSVtolerances to specify the scalar relative tolerance * and vector absolute tolerances */ @@ -6213,7 +6080,8 @@ void cvode_conversion_rate(const double y_ini, double delta_t, conversion_rate* realtype t; flag = CVode(cvode_mem, delta_t, y, &t, CV_NORMAL); // std::cout << "result at time " << t << " is " << NV_Ith_S(y,0) << std::endl; - if (flag != CV_SUCCESS) { + if (flag != CV_SUCCESS) + { std::cerr << "ERROR at " << __FUNCTION__ << ":" << __LINE__ << std::endl; } @@ -6233,15 +6101,15 @@ void cvode_conversion_rate(const double y_ini, double delta_t, conversion_rate* } #endif -//HS, TN 07/2013 Calculates Reaction rate +// HS, TN 07/2013 Calculates Reaction rate void CFiniteElementStd::CalcSolidDensityRate() { // ---- Gauss integral - int gp_r=0, gp_s=0, gp_t=0; + int gp_r = 0, gp_s = 0, gp_t = 0; const double theta = pcs->m_num->ls_theta; - //Find out material group - TN + // Find out material group - TN // const long group = MeshElement->GetPatchIndex(); // Get room in the memory for local matrices @@ -6249,7 +6117,6 @@ void CFiniteElementStd::CalcSolidDensityRate() // Set material SetMaterial(); - ElementValue* gp_ele = ele_gp_value[Index]; // loop over all Gauss points @@ -6266,20 +6133,25 @@ void CFiniteElementStd::CalcSolidDensityRate() // ComputeGradShapefct(1); // Linear interpolation function // get interpolated primary variable values - const double p_g = time_interpolate(NodalVal0, NodalVal1, theta, this); - const double T_g = time_interpolate(NodalVal_t0, NodalVal_t1, theta, this); + const double p_g = time_interpolate(NodalVal0, NodalVal1, theta, this); + const double T_g = time_interpolate(NodalVal_t0, NodalVal_t1, theta, this); const double w_mf = time_interpolate(NodalVal_X0, NodalVal_X1, theta, this); double T_s; - if (pcs->getProcessType() == TES) { + if (pcs->getProcessType() == TES) + { T_s = T_g; - } else if (pcs->getProcessType() == TNEQ) { + } + else if (pcs->getProcessType() == TNEQ) + { T_s = time_interpolate(NodalVal_t2_0, NodalVal_t2_1, theta, this); - } else { + } + else + { T_s = T_g; // avoid compiler warning; } - //get time step size + // get time step size const double delta_t = pcs->Tim->time_step_length; // TODO [CL] Why? @@ -6287,56 +6159,59 @@ void CFiniteElementStd::CalcSolidDensityRate() const double poro = MediaProp->Porosity(Index, pcs->m_num->ls_theta); // set parameters in the ca_hydaration class - if (this->SolidProp->getSolidReactiveSystem() != FiniteElement::INERT){ - if (this->SolidProp->getSolidReactiveSystem() == FiniteElement::SINUSOIDAL) {//For Benchmarks + if (this->SolidProp->getSolidReactiveSystem() != FiniteElement::INERT) + { + if (this->SolidProp->getSolidReactiveSystem() == FiniteElement::SINUSOIDAL) + { // For Benchmarks const double rhoSR0 = 1.0; const double rhoTil = 0.1; - const double omega = 2.0*3.1416; - gp_ele->rho_s_curr[gp] = rhoSR0 + rhoTil * sin(omega*aktuelle_zeit)/(1.0-poro); //TN Test mass transfer - gp_ele->q_R[gp] = rhoTil * omega * cos(omega*aktuelle_zeit)/(1.0-poro); //TN Test mass transfer + const double omega = 2.0 * 3.1416; + gp_ele->rho_s_curr[gp] + = rhoSR0 + rhoTil * sin(omega * aktuelle_zeit) / (1.0 - poro); // TN Test mass transfer + gp_ele->q_R[gp] = rhoTil * omega * cos(omega * aktuelle_zeit) / (1.0 - poro); // TN Test mass transfer } - else {//Fuer CaOH2 im Moment + else + { // Fuer CaOH2 im Moment - pcs->m_conversion_rate->update_param(T_s, T_g, p_g / 1.0e5, w_mf, gp_ele->rho_s_prev[gp], - 1.0-poro, delta_t, - SolidProp->getSolidReactiveSystem()); + pcs->m_conversion_rate->update_param(T_s, T_g, p_g / 1.0e5, w_mf, gp_ele->rho_s_prev[gp], 1.0 - poro, + delta_t, SolidProp->getSolidReactiveSystem()); #ifdef OGS_USE_CVODE - const double xv_NR = SolidProp->non_reactive_solid_volume_fraction; + const double xv_NR = SolidProp->non_reactive_solid_volume_fraction; const double rho_NR = SolidProp->non_reactive_solid_density; double y_new, y_dot_new; - cvode_conversion_rate((gp_ele->rho_s_prev[gp] - xv_NR * rho_NR) / (1.0-xv_NR), - delta_t, pcs->m_conversion_rate, y_new, y_dot_new); + cvode_conversion_rate((gp_ele->rho_s_prev[gp] - xv_NR * rho_NR) / (1.0 - xv_NR), delta_t, + pcs->m_conversion_rate, y_new, y_dot_new); double rho_react; - //cut off when limits are reached - if ( y_new < SolidProp->lower_solid_density_limit ) + // cut off when limits are reached + if (y_new < SolidProp->lower_solid_density_limit) rho_react = SolidProp->lower_solid_density_limit; - else if ( y_new > SolidProp->upper_solid_density_limit ) //{ + else if (y_new > SolidProp->upper_solid_density_limit) //{ rho_react = SolidProp->upper_solid_density_limit; else rho_react = y_new; - //TN - reactive fraction - gp_ele->rho_s_curr[gp] = (1.0-xv_NR) * rho_react + xv_NR * rho_NR; + // TN - reactive fraction + gp_ele->rho_s_curr[gp] = (1.0 - xv_NR) * rho_react + xv_NR * rho_NR; - gp_ele->q_R[gp] = y_dot_new * (1.0-xv_NR); + gp_ele->q_R[gp] = y_dot_new * (1.0 - xv_NR); #else std::cout << "Error: CMake option OGS_USE_CVODE needs to be set to solve this process type!" - << std::endl; + << std::endl; exit(1); #endif } } - else {//if not reactive solid + else + { // if not reactive solid gp_ele->rho_s_curr[gp] = gp_ele->rho_s_prev[gp]; gp_ele->q_R[gp] = 0.0; } } } - /*************************************************************************** GeoSys - Funktion: CFiniteElementStd:: Velocity calulation @@ -6357,11 +6232,11 @@ void CFiniteElementStd::Cal_Velocity() double coef = 0.0; // TODO [CL] shouldn't that be equal to pcs->dof int dof_n = 1; - if(PcsType == EPT_MULTIPHASE_FLOW || PcsType == EPT_PSGLOBAL) + if (PcsType == EPT_MULTIPHASE_FLOW || PcsType == EPT_PSGLOBAL) dof_n = 2; - if(PcsType == EPT_THERMAL_NONEQUILIBRIUM) + if (PcsType == EPT_THERMAL_NONEQUILIBRIUM) dof_n = 4; - if(PcsType == EPT_TES) + if (PcsType == EPT_TES) dof_n = 3; // gp_t = 0; @@ -6373,16 +6248,17 @@ void CFiniteElementStd::Cal_Velocity() ElementValue* gp_ele = ele_gp_value[Index]; - //gp_ele->Velocity = 0.0; // CB commented and inserted below due to conflict with transport calculation, needs velocities + // gp_ele->Velocity = 0.0; // CB commented and inserted below due to conflict with transport calculation, needs + // velocities // Loop over Gauss points k = (coordinate_system) % 10; - if(PcsType == EPT_TWOPHASE_FLOW) //WW/CB + if (PcsType == EPT_TWOPHASE_FLOW) // WW/CB { - if(pcs->pcs_type_number == 0) + if (pcs->pcs_type_number == 0) { // gas pressure idx1 = pcs->GetNodeValueIndex("PRESSURE1") + 1; - for(int i = 0; i < nnodes; i++) + for (int i = 0; i < nnodes; i++) NodalVal[i] = pcs->GetNodeValue(nodes[i], idx1); } else if (pcs->pcs_type_number == 1) @@ -6391,44 +6267,42 @@ void CFiniteElementStd::Cal_Velocity() // gas pressure idx1 = cpl_pcs->GetNodeValueIndex("PRESSURE1") + 1; gp_ele = ele_gp_value[Index + (long)pcs->m_msh->ele_vector.size()]; - for(int i = 0; i < nnodes; i++) + for (int i = 0; i < nnodes; i++) // P_l = P_g - P_cap - NodalVal[i] = - cpl_pcs->GetNodeValue(nodes[i], idx1) - pcs->GetNodeValue( - nodes[i], - idxp21); + NodalVal[i] = cpl_pcs->GetNodeValue(nodes[i], idx1) - pcs->GetNodeValue(nodes[i], idxp21); } } else // This should be enough for Vw in PS_GLOBAL as well, // since the first primary variable is Pw. - for(int i = 0; i < nnodes; i++) + for (int i = 0; i < nnodes; i++) { NodalVal[i] = pcs->GetNodeValue(nodes[i], idx1); NodalVal1[i] = NodalVal[i]; } // - if(PcsType == EPT_MULTIPHASE_FLOW) + if (PcsType == EPT_MULTIPHASE_FLOW) { - gp_ele->Velocity_g = 0.0; //WW - for(int i = 0; i < nnodes; i++) + gp_ele->Velocity_g = 0.0; // WW + for (int i = 0; i < nnodes; i++) { // 02.2010. WW NodalVal2[i] = pcs->GetNodeValue(nodes[i], idxp21); - NodalVal[i] = NodalVal2[i] - NodalVal[i]; + NodalVal[i] = NodalVal2[i] - NodalVal[i]; } } - if(PcsType == EPT_PSGLOBAL) + if (PcsType == EPT_PSGLOBAL) { - gp_ele->Velocity_g = 0.0; //PCH + gp_ele->Velocity_g = 0.0; // PCH // Just get Pnw, which is the secondary variable in PS_GLOBAL int idx_pn = pcs->GetNodeValueIndex("PRESSURE2"); - for(int i = 0; i < nnodes; i++) + for (int i = 0; i < nnodes; i++) NodalVal1[i] = pcs->GetNodeValue(nodes[i], idx_pn); } Matrix tmp_gp_velocity(gp_ele->Velocity); tmp_gp_velocity = 0.0; - //gp_ele->Velocity = 0.0; // CB inserted here and commented above due to conflict with transport calculation, needs + // gp_ele->Velocity = 0.0; // CB inserted here and commented above due to conflict with + // transport calculation, needs for (gp = 0; gp < nGaussPoints; gp++) { //--------------------------------------------------------- @@ -6440,53 +6314,57 @@ void CFiniteElementStd::Cal_Velocity() //--------------------------------------------------------- // Compute geometry //--------------------------------------------------------- - ComputeGradShapefct(1); // Linear interpolation function - ComputeShapefct(1); // Moved from CalCoefLaplace(). 12.3.2007 WW - //WW/CB - if((PcsType == EPT_TWOPHASE_FLOW) && (pcs->pcs_type_number == 1)) + ComputeGradShapefct(1); // Linear interpolation function + ComputeShapefct(1); // Moved from CalCoefLaplace(). 12.3.2007 WW + // WW/CB + if ((PcsType == EPT_TWOPHASE_FLOW) && (pcs->pcs_type_number == 1)) flag_cpl_pcs = true; // Material - if(dof_n == 1) + if (dof_n == 1) CalCoefLaplace(true); - else if (dof_n==4 && PcsType==EPT_THERMAL_NONEQUILIBRIUM) + else if (dof_n == 4 && PcsType == EPT_THERMAL_NONEQUILIBRIUM) CalCoefLaplaceTNEQ(0); - else if (dof_n==3 && PcsType==EPT_TES) + else if (dof_n == 3 && PcsType == EPT_TES) CalCoefLaplaceTES(0); else if (dof_n == 2 && PcsType == EPT_MULTIPHASE_FLOW) // PCH 05.2009 - CalCoefLaplace2(true,0); + CalCoefLaplace2(true, 0); else if (dof_n == 2 && PcsType == EPT_PSGLOBAL) // PCH 05.2009 - CalCoefLaplacePSGLOBAL(true,0); - //WW/CB - if((PcsType == EPT_TWOPHASE_FLOW) && (pcs->pcs_type_number == 1)) + CalCoefLaplacePSGLOBAL(true, 0); + // WW/CB + if ((PcsType == EPT_TWOPHASE_FLOW) && (pcs->pcs_type_number == 1)) flag_cpl_pcs = false; // Velocity for (size_t i = 0; i < dim; i++) { vel[i] = 0.0; - for(int j = 0; j < nnodes; j++) + for (int j = 0; j < nnodes; j++) vel[i] += NodalVal[j] * dshapefct[i * nnodes + j]; // vel[i] += fabs(NodalVal[j])*dshapefct[i*nnodes+j]; } - if(PcsType == EPT_MULTIPHASE_FLOW) { + if (PcsType == EPT_MULTIPHASE_FLOW) + { for (size_t i = 0; i < dim; i++) { vel_g[i] = 0.0; - for(int j = 0; j < nnodes; j++) + for (int j = 0; j < nnodes; j++) // Change NodalVal2 to NodalVal1. 02.2010. WW vel_g[i] += NodalVal2[j] * dshapefct[i * nnodes + j]; } - } else if(PcsType == EPT_PSGLOBAL) { // PCH 05.2009 + } + else if (PcsType == EPT_PSGLOBAL) + { // PCH 05.2009 for (size_t i = 0; i < dim; i++) { vel_g[i] = 0.0; - for(int j = 0; j < nnodes; j++) + for (int j = 0; j < nnodes; j++) vel_g[i] += NodalVal1[j] * dshapefct[i * nnodes + j]; } } // Gravity term - //NW - if (PcsType != EPT_HEAT_TRANSPORT && PcsType != EPT_MASS_TRANSPORT) { // JOD 2014-11-10 + // NW + if (PcsType != EPT_HEAT_TRANSPORT && PcsType != EPT_MASS_TRANSPORT) + { // JOD 2014-11-10 if (k == 2 && (!HEAD_Flag) && FluidProp->CheckGravityCalculation()) { if (PcsType == EPT_THERMAL_NONEQUILIBRIUM || PcsType == EPT_TES) @@ -6495,38 +6373,29 @@ void CFiniteElementStd::Cal_Velocity() eos_arg[0] = time_interpolate(NodalVal0, NodalVal1, theta, this); eos_arg[1] = time_interpolate(NodalVal_t0, NodalVal_t1, theta, this); eos_arg[2] = time_interpolate(NodalVal_X0, NodalVal_X1, theta, this); - coef = gravity_constant*FluidProp->Density(eos_arg); + coef = gravity_constant * FluidProp->Density(eos_arg); } else - coef = gravity_constant*FluidProp->Density(); + coef = gravity_constant * FluidProp->Density(); if (dim == 3 && ele_dim == 2) { - vel[dim - 1] += coef; //NW local permeability tensor is already transformed to global one in CalCoefLaplace() + vel[dim - 1] += coef; // NW local permeability tensor is already transformed to global one in + // CalCoefLaplace() if (PcsType == EPT_MULTIPHASE_FLOW || PcsType == EPT_PSGLOBAL) { for (size_t i = 0; i < dim; i++) - for (size_t j = 0; j < ele_dim; j++) - { - if(PcsType == EPT_MULTIPHASE_FLOW) - vel_g[i] += rho_g * - gravity_constant * - (*MeshElement-> - transform_tensor)(i, k) - * (*MeshElement-> - transform_tensor)(2, - k); - if(PcsType == EPT_PSGLOBAL) // PCH 05.2009 - vel_g[i] += coef * - GasProp->Density() / - FluidProp->Density() * - (*MeshElement-> - transform_tensor)(i, k) - * (*MeshElement-> - transform_tensor)(2, - k); - } + for (size_t j = 0; j < ele_dim; j++) + { + if (PcsType == EPT_MULTIPHASE_FLOW) + vel_g[i] += rho_g * gravity_constant * (*MeshElement->transform_tensor)(i, k) + * (*MeshElement->transform_tensor)(2, k); + if (PcsType == EPT_PSGLOBAL) // PCH 05.2009 + vel_g[i] += coef * GasProp->Density() / FluidProp->Density() + * (*MeshElement->transform_tensor)(i, k) + * (*MeshElement->transform_tensor)(2, k); + } } - } // To be correctted + } // To be correctted else { if (PcsType == EPT_MULTIPHASE_FLOW) @@ -6536,7 +6405,7 @@ void CFiniteElementStd::Cal_Velocity() } else if (PcsType == EPT_PSGLOBAL) // PCH 05.2009 { - //vel[dim-1] -= coef; + // vel[dim-1] -= coef; // CB_merge_0513 ?? gravity term vel[dim - 1] += coef; // CB I think this should be added vel_g[dim - 1] += gravity_constant * GasProp->Density(); @@ -6548,45 +6417,47 @@ void CFiniteElementStd::Cal_Velocity() } // end gravity term - if(PcsType == EPT_MULTIPHASE_FLOW) + if (PcsType == EPT_MULTIPHASE_FLOW) { for (size_t i = 0; i < dim; i++) // 02.2010. WW { - for(size_t j = 0; j < dim; j++) - tmp_gp_velocity(i, gp) += mat[dim*i+j]*vel[j]/time_unit_factor; - //gp_ele->Velocity(i, gp) += mat[dim*i+j]*vel[j]/time_unit_factor; + for (size_t j = 0; j < dim; j++) + tmp_gp_velocity(i, gp) += mat[dim * i + j] * vel[j] / time_unit_factor; + // gp_ele->Velocity(i, gp) += mat[dim*i+j]*vel[j]/time_unit_factor; } - CalCoefLaplace2(true,3); - double coef_tmp; //WX:08.2010. + CalCoefLaplace2(true, 3); + double coef_tmp; // WX:08.2010. coef_tmp = rhow / rho_ga; for (size_t i = 0; i < dim; i++) - for(size_t j = 0; j < dim; j++) + for (size_t j = 0; j < dim; j++) gp_ele->Velocity_g(i, gp) -= coef_tmp * mat[dim * i + j] * vel_g[j] / time_unit_factor; - //WX:modified.08.2010 + // WX:modified.08.2010 } - else if (PcsType == EPT_THERMAL_NONEQUILIBRIUM - || PcsType == EPT_TES) + else if (PcsType == EPT_THERMAL_NONEQUILIBRIUM || PcsType == EPT_TES) { const double theta = pcs->m_num->ls_theta; eos_arg[0] = time_interpolate(NodalVal0, NodalVal1, theta, this); eos_arg[1] = time_interpolate(NodalVal_t0, NodalVal_t1, theta, this); eos_arg[2] = time_interpolate(NodalVal_X0, NodalVal_X1, theta, this); - coef = gravity_constant*FluidProp->Density(eos_arg); + coef = gravity_constant * FluidProp->Density(eos_arg); for (size_t i = 0; i < dim; i++) { - for(size_t j=0; jVelocity(i, gp) -= mat[dim*i+j]*vel[j]; // unit as that given in input file - //SI Unit + // SI Unit - if (GasMassForm) { //TN otherwise wrong velocity - tmp_gp_velocity(i,gp) -= mat[dim*i+j]/FluidProp->Density(eos_arg)*vel[j]/time_unit_factor; - } else { - tmp_gp_velocity(i, gp) -= mat[dim*i+j]*vel[j]/time_unit_factor; + if (GasMassForm) + { // TN otherwise wrong velocity + tmp_gp_velocity(i, gp) + -= mat[dim * i + j] / FluidProp->Density(eos_arg) * vel[j] / time_unit_factor; + } + else + { + tmp_gp_velocity(i, gp) -= mat[dim * i + j] * vel[j] / time_unit_factor; } } - } - else // 02.2010. WW + else // 02.2010. WW { for (size_t i = 0; i < dim; i++) { @@ -6595,41 +6466,42 @@ void CFiniteElementStd::Cal_Velocity() gp_ele->TransportFlux(i, gp) = 0; #endif - for(size_t j = 0; j < dim; j++) + for (size_t j = 0; j < dim; j++) { - // gp_ele->Velocity(i, gp) -= mat[dim*i+j]*vel[j]; // unit as that given in input file - //SI Unit +// gp_ele->Velocity(i, gp) -= mat[dim*i+j]*vel[j]; // unit as that given in input file +// SI Unit #ifdef USE_TRANSPORT_FLUX if (PcsType == EPT_HEAT_TRANSPORT || PcsType == EPT_MASS_TRANSPORT) // // JOD 2014-11-10 - gp_ele->TransportFlux(i, gp) -= mat[dim*i + j] * vel[j] / time_unit_factor; + gp_ele->TransportFlux(i, gp) -= mat[dim * i + j] * vel[j] / time_unit_factor; else #endif - tmp_gp_velocity(i, gp) -= mat[dim*i+j]*vel[j]/time_unit_factor; - //gp_ele->Velocity(i, gp) -= mat[dim*i+j]*vel[j]/time_unit_factor; + tmp_gp_velocity(i, gp) -= mat[dim * i + j] * vel[j] / time_unit_factor; + // gp_ele->Velocity(i, gp) -= mat[dim*i+j]*vel[j]/time_unit_factor; } } - } - if(PcsType == EPT_PSGLOBAL) // PCH 05.2009 + if (PcsType == EPT_PSGLOBAL) // PCH 05.2009 { // Juse use the coefficient of PSGLOBAL Pressure-based velocity (4) - CalCoefLaplacePSGLOBAL(true,4); + CalCoefLaplacePSGLOBAL(true, 4); for (size_t i = 0; i < dim; i++) - for(size_t j = 0; j < dim; j++) + for (size_t j = 0; j < dim; j++) gp_ele->Velocity_g(i, gp) -= mat[dim * i + j] * vel_g[j] / time_unit_factor; } // } gp_ele->Velocity = tmp_gp_velocity; // - if(pcs->Write_Matrix) + if (pcs->Write_Matrix) { (*pcs->matrix_file) << "### Element: " << Index << "\n"; - (*pcs->matrix_file) << "---Velocity of water " << "\n"; + (*pcs->matrix_file) << "---Velocity of water " + << "\n"; gp_ele->Velocity.Write(*pcs->matrix_file); - if(gp_ele->Velocity_g.Size() > 0) + if (gp_ele->Velocity_g.Size() > 0) { - (*pcs->matrix_file) << "---Velocity of gas " << "\n"; + (*pcs->matrix_file) << "---Velocity of gas " + << "\n"; gp_ele->Velocity_g.Write(*pcs->matrix_file); } } @@ -6644,7 +6516,7 @@ void CFiniteElementStd::Cal_Velocity() **************************************************************************/ void CFiniteElementStd::Cal_VelocityMCF() { - int j, in, nDF=pcs->dof; + int j, in, nDF = pcs->dof; double* tensor = NULL; double arg_PV[6], gravity_vector[3], rho; int gp_r = 0, gp_s = 0, gp_t; @@ -6652,47 +6524,53 @@ void CFiniteElementStd::Cal_VelocityMCF() SetMemory(); SetMaterial(); ElementValue* gp_ele = ele_gp_value[Index]; - for(size_t k = 0; k < dim; k++) gravity_vector[k] = 0.0; - if((coordinate_system) % 10 == 2 && (!HEAD_Flag)) - { - gravity_vector[dim - 1] = gravity_constant; - if(dim == 3 && ele_dim == 1 && MediaProp->geo_inclination > 0) + for (size_t k = 0; k < dim; k++) + gravity_vector[k] = 0.0; + if ((coordinate_system) % 10 == 2 && (!HEAD_Flag)) { - gravity_vector[0] = gravity_constant*cos(PI*MediaProp->geo_inclination/180)*sin(PI*MediaProp->geo_inclination/180); - gravity_vector[dim - 1] = gravity_constant*sin(PI*MediaProp->geo_inclination/180)*sin(PI*MediaProp->geo_inclination/180); - } + gravity_vector[dim - 1] = gravity_constant; + if (dim == 3 && ele_dim == 1 && MediaProp->geo_inclination > 0) + { + gravity_vector[0] = gravity_constant * cos(PI * MediaProp->geo_inclination / 180) + * sin(PI * MediaProp->geo_inclination / 180); + gravity_vector[dim - 1] = gravity_constant * sin(PI * MediaProp->geo_inclination / 180) + * sin(PI * MediaProp->geo_inclination / 180); + } } ComputeShapefct(1); - for(in = 0; in < nDF; in++) arg_PV[in] = interpolate(NodalValue[in]); + for (in = 0; in < nDF; in++) + arg_PV[in] = interpolate(NodalValue[in]); gp_ele->Velocity = 0.0; for (gp = 0; gp < nGaussPoints; gp++) { + GetGaussData(gp, gp_r, gp_s, gp_t); + ComputeGradShapefct(1); + ComputeShapefct(1); + tensor = MediaProp->DispersionTensorMCF(gp, 0, 0, arg_PV); + for (j = 0; j < nnodes; j++) + { + for (in = 0; in < nDF; in++) + arg_PV[in] = pcs->GetNodeValue(nodes[j], idxMCF[in + nDF]); + // + rho = FluidProp->Density(arg_PV); + // + for (size_t k = 0; k < dim; k++) + { + gp_ele->Velocity(k, gp) + -= tensor[dim * k + k] * (dshapefct[k * nnodes + j] * pcs->GetNodeValue(nodes[j], idxMCF[0 + nDF]) + + shapefct[j] * rho * gravity_vector[k]); + } + } - GetGaussData(gp, gp_r, gp_s, gp_t); - ComputeGradShapefct(1); - ComputeShapefct(1); - tensor = MediaProp->DispersionTensorMCF(gp, 0, 0, arg_PV); - for(j = 0; jGetNodeValue(nodes[j], idxMCF[in + nDF]); - // - rho = FluidProp->Density(arg_PV); - // - for (size_t k = 0; kVelocity(k, gp) -= tensor[dim*k + k]*(dshapefct[k*nnodes + j]*pcs->GetNodeValue(nodes[j], idxMCF[0 + nDF]) + shapefct[j]*rho*gravity_vector[k]); - } - } - - // - if(pcs->Write_Matrix) - { - (*pcs->matrix_file) << "### Element: " << Index << endl; - (*pcs->matrix_file) << "---Velocity of fluid " << endl; - gp_ele->Velocity.Write(*pcs->matrix_file); + // + if (pcs->Write_Matrix) + { + (*pcs->matrix_file) << "### Element: " << Index << endl; + (*pcs->matrix_file) << "---Velocity of fluid " << endl; + gp_ele->Velocity.Write(*pcs->matrix_file); + } + // gp_ele->Velocity.Write(); } - // gp_ele->Velocity.Write(); - } } /*************************************************************************** @@ -6712,13 +6590,13 @@ void CFiniteElementStd::Cal_GP_Velocity_FM(int* i_ind) 0.0,0.0,0.0 } */ - double vel_g[3] = { 0.0, 0.0, 0.0 }; + double vel_g[3] = {0.0, 0.0, 0.0}; // ---- Gauss integral - //WW int gp_r=0, gp_s=0, gp_t=0; - //WW double fkt=0.0; //OK411 coef = 0.0 + // WW int gp_r=0, gp_s=0, gp_t=0; + // WW double fkt=0.0; //OK411 coef = 0.0 int i_idx; // Get fluid_momentum process - CRFProcess* m_pcs_fm = PCSGet("FLUID_MOMENTUM"); + CRFProcess* m_pcs_fm = PCSGet("FLUID_MOMENTUM"); ElementValue* gp_ele = ele_gp_value[Index]; @@ -6727,29 +6605,29 @@ void CFiniteElementStd::Cal_GP_Velocity_FM(int* i_ind) { // Get gauss point data // GetGaussData(gp, gp_r, gp_s, gp_t); - //WW fkt = GetGaussData(gp, gp_r, gp_s, gp_t); + // WW fkt = GetGaussData(gp, gp_r, gp_s, gp_t); // Compute the shape function for interpolation within element ComputeShapefct(1); // Save former gp velocity - //WW for(i_dim=0;i_dimVelocity(i_dim,gp); + // WW for(i_dim=0;i_dimVelocity(i_dim,gp); // Interpolate velocity from nodes to gauss point for all three velocity components - for(size_t i_dim = 0; i_dim < dim; i_dim++) + for (size_t i_dim = 0; i_dim < dim; i_dim++) { // Get velocities from FLUID_MOMENTUM process in element nodes: i_idx = i_ind[i_dim]; - for(i = 0; i < nnodes; i++) + for (i = 0; i < nnodes; i++) { NodalVal[i] = m_pcs_fm->GetNodeValue(nodes[i], i_idx); - //dirty fix for permebility to conductivity + // dirty fix for permebility to conductivity NodalVal[i] = NodalVal[i] / gravity_constant / 1000.0 * 0.001; } vel_g[i_dim] = interpolate(NodalVal); - } // end for dim + } // end for dim // Set gauss point velocity - for(size_t i_dim = 0; i_dim < dim; i_dim++) + for (size_t i_dim = 0; i_dim < dim; i_dim++) gp_ele->Velocity(i_dim, gp) = vel_g[i_dim]; /* // Write out differences: @@ -6764,7 +6642,7 @@ void CFiniteElementStd::Cal_GP_Velocity_FM(int* i_ind) cout << "\n"; } */ - } // end gauss point loop + } // end gauss point loop // Output // gp_ele->Velocity.Write(); @@ -6777,27 +6655,26 @@ void CFiniteElementStd::Cal_GP_Velocity_FM(int* i_ind) Programming: BG 11/2010 first version **************************************************************************/ -double CFiniteElementStd::InterpolatePropertyToGausspoint(int GPIndex, - CRFProcess* m_pcs, - int Variableindex) +double CFiniteElementStd::InterpolatePropertyToGausspoint(int GPIndex, CRFProcess* m_pcs, int Variableindex) { - (void)GPIndex; // unused - //double fkt = 0.0; - //int gp_r=0, gp_s=0, gp_t=0; - //ElementValue* gp_ele = ele_gp_value[Index]; + (void)GPIndex; // unused + // double fkt = 0.0; + // int gp_r=0, gp_s=0, gp_t=0; + // ElementValue* gp_ele = ele_gp_value[Index]; int i; double variable; - int size_m = 20; //assigned to the value in CFiniteElementStd(CRFProcess *Pcs, const int C_Sys_Flad, const int order=1); + int size_m + = 20; // assigned to the value in CFiniteElementStd(CRFProcess *Pcs, const int C_Sys_Flad, const int order=1); double* NodalVal_BG; - NodalVal_BG = new double [size_m]; //BG + NodalVal_BG = new double[size_m]; // BG // Get gauss point data // GetGaussData(gp, gp_r, gp_s, gp_t); - //fkt = GetGaussData(GPIndex, gp_r, gp_s, gp_t); + // fkt = GetGaussData(GPIndex, gp_r, gp_s, gp_t); // Compute the shape function for interpolation within element - //ComputeShapefct(1); - //read density from nodes - for(i = 0; i < nnodes; i++) + // ComputeShapefct(1); + // read density from nodes + for (i = 0; i < nnodes; i++) NodalVal_BG[i] = m_pcs->GetNodeValue(nodes[i], Variableindex); // Interpolate density from nodes to gauss point variable = interpolate(NodalVal_BG); @@ -6816,11 +6693,11 @@ double CFiniteElementStd::InterpolatePropertyToGausspoint(int GPIndex, string CFiniteElementStd::Cal_GP_Velocity_DuMux(int* i_ind, CRFProcess* m_pcs, int phase_index) { int i; - static double temp_val_old[3] = { 0.0, 0.0, 0.0 }, temp_val[3] = { 0.0, 0.0, 0.0 }; - double value_old[3] = { 0.0, 0.0, 0.0 }, value[3] = { 0.0, 0.0, 0.0 }; + static double temp_val_old[3] = {0.0, 0.0, 0.0}, temp_val[3] = {0.0, 0.0, 0.0}; + double value_old[3] = {0.0, 0.0, 0.0}, value[3] = {0.0, 0.0, 0.0}; // ---- Gauss integral - //WW int gp_r=0, gp_s=0, gp_t=0; - //WW double fkt=0.0; //OK411 coef = 0.0 + // WW int gp_r=0, gp_s=0, gp_t=0; + // WW double fkt=0.0; //OK411 coef = 0.0 int i_idx; ostringstream temp; string tempstring; @@ -6832,7 +6709,7 @@ string CFiniteElementStd::Cal_GP_Velocity_DuMux(int* i_ind, CRFProcess* m_pcs, i // Gauss point loop for (gp = 0; gp < nGaussPoints; gp++) { - for(size_t i_dim = 0; i_dim < dim; i_dim++) + for (size_t i_dim = 0; i_dim < dim; i_dim++) { temp_val[i_dim] = 0; temp_val_old[i_dim] = 0; @@ -6840,32 +6717,33 @@ string CFiniteElementStd::Cal_GP_Velocity_DuMux(int* i_ind, CRFProcess* m_pcs, i // Get gauss point data // GetGaussData(gp, gp_r, gp_s, gp_t); - //WW fkt = GetGaussData(gp, gp_r, gp_s, gp_t); + // WW fkt = GetGaussData(gp, gp_r, gp_s, gp_t); // Compute the shape function for interpolation within element ComputeShapefct(1); // Save former gp velocity - for(size_t i_dim = 0; i_dim < dim; i_dim++) + for (size_t i_dim = 0; i_dim < dim; i_dim++) { if (phase_index == 0) - temp_val_old[i_dim] = gp_ele->Velocity(i_dim,gp); + temp_val_old[i_dim] = gp_ele->Velocity(i_dim, gp); else - temp_val_old[i_dim] = gp_ele->Velocity_g(i_dim,gp); + temp_val_old[i_dim] = gp_ele->Velocity_g(i_dim, gp); } // Interpolate velocity from nodes to gauss point for all three velocity components - for(size_t i_dim = 0; i_dim < dim; i_dim++) + for (size_t i_dim = 0; i_dim < dim; i_dim++) { // Get velocities from FLUID_MOMENTUM process in element nodes: i_idx = i_ind[i_dim]; - for(i = 0; i < nnodes; i++) + for (i = 0; i < nnodes; i++) NodalVal[i] = m_pcs->GetNodeValue(nodes[i], i_idx); - //NodalVal[i] = NodalVal[i] /gravity_constant/1000.0*0.001; //dirty fix for permebility to conductivity + // NodalVal[i] = NodalVal[i] /gravity_constant/1000.0*0.001; //dirty fix for permebility to + // conductivity temp_val[i_dim] = interpolate(NodalVal); - } // end for dim + } // end for dim // Set gauss point velocity - for(size_t i_dim = 0; i_dim < dim; i_dim++) + for (size_t i_dim = 0; i_dim < dim; i_dim++) { if (phase_index == 0) gp_ele->Velocity(i_dim, gp) = temp_val[i_dim]; @@ -6875,8 +6753,7 @@ string CFiniteElementStd::Cal_GP_Velocity_DuMux(int* i_ind, CRFProcess* m_pcs, i gp_ele->Velocity_g(i_dim, gp) = temp_val[i_dim]; else { - cout << - "The program is canceled because there is a phase used which is not considered yet!" + cout << "The program is canceled because there is a phase used which is not considered yet!" << "\n"; system("Pause"); exit(0); @@ -6885,24 +6762,23 @@ string CFiniteElementStd::Cal_GP_Velocity_DuMux(int* i_ind, CRFProcess* m_pcs, i } // Data for Test Output - for(size_t i_dim = 0; i_dim < dim; i_dim++) + for (size_t i_dim = 0; i_dim < dim; i_dim++) // average value of all Gauss points - value_old[i_dim] = value_old[i_dim] + temp_val_old[i_dim] / - nGaussPoints; - for(size_t i_dim = 0; i_dim < dim; i_dim++) + value_old[i_dim] = value_old[i_dim] + temp_val_old[i_dim] / nGaussPoints; + for (size_t i_dim = 0; i_dim < dim; i_dim++) // average value of all Gauss points value[i_dim] = value[i_dim] + temp_val[i_dim] / nGaussPoints; - } // end gauss point loop + } // end gauss point loop // Data for Test Output - for(size_t i_dim = 0; i_dim < dim; i_dim++) + for (size_t i_dim = 0; i_dim < dim; i_dim++) { temp.str(""); temp.clear(); temp << value_old[i_dim]; tempstring += "; " + temp.str(); } - for(size_t i_dim = 0; i_dim < dim; i_dim++) + for (size_t i_dim = 0; i_dim < dim; i_dim++) { temp.str(""); temp.clear(); @@ -6933,7 +6809,7 @@ void CFiniteElementStd::Cal_Velocity_2() int gp_r = 0, gp_s = 0, gp_t; double coef = 0.0; int dof_n = 1; - if(PcsType == EPT_MULTIPHASE_FLOW) + if (PcsType == EPT_MULTIPHASE_FLOW) dof_n = 2; // gp_t = 0; @@ -6947,13 +6823,13 @@ void CFiniteElementStd::Cal_Velocity_2() // Loop over Gauss points k = (coordinate_system) % 10; - if(PcsType == EPT_TWOPHASE_FLOW) //WW/CB + if (PcsType == EPT_TWOPHASE_FLOW) // WW/CB { - if(pcs->pcs_type_number == 0) + if (pcs->pcs_type_number == 0) { // gas pressure idx1 = pcs->GetNodeValueIndex("PRESSURE1") + 1; - for(int i = 0; i < nnodes; i++) + for (int i = 0; i < nnodes; i++) NodalVal[i] = pcs->GetNodeValue(nodes[i], idx1); } else if (pcs->pcs_type_number == 1) @@ -6962,20 +6838,17 @@ void CFiniteElementStd::Cal_Velocity_2() // gas pressure idx1 = cpl_pcs->GetNodeValueIndex("PRESSURE1") + 1; gp_ele = ele_gp_value[Index + (long)pcs->m_msh->ele_vector.size()]; - for(int i = 0; i < nnodes; i++) + for (int i = 0; i < nnodes; i++) // P_l = P_g - P_cap - NodalVal[i] = - cpl_pcs->GetNodeValue(nodes[i], idx1) - pcs->GetNodeValue( - nodes[i], - idxp21); + NodalVal[i] = cpl_pcs->GetNodeValue(nodes[i], idx1) - pcs->GetNodeValue(nodes[i], idxp21); } } else - for(int i = 0; i < nnodes; i++) + for (int i = 0; i < nnodes; i++) NodalVal[i] = pcs->GetNodeValue(nodes[i], idx1); // - if(PcsType == EPT_MULTIPHASE_FLOW) - for(int i = 0; i < nnodes; i++) + if (PcsType == EPT_MULTIPHASE_FLOW) + for (int i = 0; i < nnodes; i++) { NodalVal[i] -= pcs->GetNodeValue(nodes[i], idxp21); NodalVal1[i] = pcs->GetNodeValue(nodes[i], idxp21); @@ -6986,7 +6859,7 @@ void CFiniteElementStd::Cal_Velocity_2() gp = 0; - //for (gp = 0; gp < nGaussPoints; gp++) + // for (gp = 0; gp < nGaussPoints; gp++) //{ //--------------------------------------------------------- // Get local coordinates and weights @@ -6995,59 +6868,57 @@ void CFiniteElementStd::Cal_Velocity_2() GetGaussData(gp, gp_r, gp_s, gp_t); // calculate the velocity at the element center of gravity - if(PcsType == EPT_TWOPHASE_FLOW) - SetCenterGP(); // CB 11/2007 + if (PcsType == EPT_TWOPHASE_FLOW) + SetCenterGP(); // CB 11/2007 //--------------------------------------------------------- // Compute geometry //--------------------------------------------------------- - ComputeGradShapefct(1); // Linear interpolation function - ComputeShapefct(1); // Moved from CalCoefLaplace(). 12.3.2007 WW - if((PcsType == EPT_TWOPHASE_FLOW) && (pcs->pcs_type_number == 1)) //WW/CB + ComputeGradShapefct(1); // Linear interpolation function + ComputeShapefct(1); // Moved from CalCoefLaplace(). 12.3.2007 WW + if ((PcsType == EPT_TWOPHASE_FLOW) && (pcs->pcs_type_number == 1)) // WW/CB flag_cpl_pcs = true; // Material - if(dof_n == 1) + if (dof_n == 1) CalCoefLaplace(true); else if (dof_n == 2) - CalCoefLaplace2(true,0); - if((PcsType == EPT_TWOPHASE_FLOW) && (pcs->pcs_type_number == 1)) //WW/CB + CalCoefLaplace2(true, 0); + if ((PcsType == EPT_TWOPHASE_FLOW) && (pcs->pcs_type_number == 1)) // WW/CB flag_cpl_pcs = false; // Velocity for (size_t i = 0; i < dim; i++) { vel[i] = 0.0; - for(int j = 0; j < nnodes; j++) + for (int j = 0; j < nnodes; j++) vel[i] += NodalVal[j] * dshapefct[i * nnodes + j]; // vel[i] += fabs(NodalVal[j])*dshapefct[i*nnodes+j]; } - if(PcsType == EPT_MULTIPHASE_FLOW) + if (PcsType == EPT_MULTIPHASE_FLOW) for (size_t i = 0; i < dim; i++) { vel_g[i] = 0.0; - for(int j = 0; j < nnodes; j++) + for (int j = 0; j < nnodes; j++) vel_g[i] += NodalVal1[j] * dshapefct[i * nnodes + j]; } // Gravity term - if(k == 2 && (!HEAD_Flag)) + if (k == 2 && (!HEAD_Flag)) { - coef = gravity_constant * FluidProp->Density(); - if(dim == 3 && ele_dim == 2) + coef = gravity_constant * FluidProp->Density(); + if (dim == 3 && ele_dim == 2) { - for(size_t i = 0; i < dim; i++) - for(size_t j = 0; j < ele_dim; j++) + for (size_t i = 0; i < dim; i++) + for (size_t j = 0; j < ele_dim; j++) { - vel[i] += coef * (*MeshElement->transform_tensor)(i, k) - * (*MeshElement->transform_tensor)(2, k); - if(PcsType == EPT_MULTIPHASE_FLOW) - vel_g[i] += rho_g * gravity_constant * - (*MeshElement->transform_tensor)(i, k) + vel[i] += coef * (*MeshElement->transform_tensor)(i, k) * (*MeshElement->transform_tensor)(2, k); + if (PcsType == EPT_MULTIPHASE_FLOW) + vel_g[i] += rho_g * gravity_constant * (*MeshElement->transform_tensor)(i, k) * (*MeshElement->transform_tensor)(2, k); } - } // To be correctted + } // To be correctted else { - if(PcsType == EPT_MULTIPHASE_FLOW) + if (PcsType == EPT_MULTIPHASE_FLOW) { vel[dim - 1] -= coef; vel_g[dim - 1] += gravity_constant * rho_g; @@ -7057,33 +6928,32 @@ void CFiniteElementStd::Cal_Velocity_2() } } for (size_t i = 0; i < dim; i++) - for(size_t j = 0; j < dim; j++) + for (size_t j = 0; j < dim; j++) // gp_ele->Velocity(i, gp) -= mat[dim*i+j]*vel[j]; // unit as that given in input file gp_ele->Velocity(i, gp) -= mat[dim * i + j] * vel[j] / time_unit_factor; // - if(PcsType == EPT_MULTIPHASE_FLOW) + if (PcsType == EPT_MULTIPHASE_FLOW) { - CalCoefLaplace2(true,3); + CalCoefLaplace2(true, 3); coef = rhow / rho_ga; for (size_t i = 0; i < dim; i++) - for(size_t j = 0; j < dim; j++) - gp_ele->Velocity_g(i, - gp) -= coef * - mat[dim * i + - j] * vel_g[j] / time_unit_factor; + for (size_t j = 0; j < dim; j++) + gp_ele->Velocity_g(i, gp) -= coef * mat[dim * i + j] * vel_g[j] / time_unit_factor; } // // cout << gp << " " << vel[0] << " " << vel[1] << " " << vel[2] << "\n"; //Test //} // for (gp = 0;... // - if(pcs->Write_Matrix) + if (pcs->Write_Matrix) { (*pcs->matrix_file) << "### Element: " << Index << "\n"; - (*pcs->matrix_file) << "---Velocity of water " << "\n"; + (*pcs->matrix_file) << "---Velocity of water " + << "\n"; gp_ele->Velocity.Write(*pcs->matrix_file); - if(gp_ele->Velocity_g.Size() > 0) + if (gp_ele->Velocity_g.Size() > 0) { - (*pcs->matrix_file) << "---Velocity of gas " << "\n"; + (*pcs->matrix_file) << "---Velocity of gas " + << "\n"; gp_ele->Velocity_g.Write(*pcs->matrix_file); } } @@ -7110,9 +6980,9 @@ double CFiniteElementStd::Get_Element_Velocity(int Index, CRFProcess* /*m_pcs*/, velocity[dimension] = 0; for (gp = 0; gp < nGaussPoints; gp++) { - //for(i_dim = 0; i_dim < dim; i_dim++) + // for(i_dim = 0; i_dim < dim; i_dim++) //{ - //velocity[i_dim] = 0; + // velocity[i_dim] = 0; //} // Compute the shape function for interpolation within element @@ -7121,17 +6991,17 @@ double CFiniteElementStd::Get_Element_Velocity(int Index, CRFProcess* /*m_pcs*/, // Get gp velocity if (phase_index == 0) { - //cout << " Water " << Index; + // cout << " Water " << Index; velocity[dimension] += gp_ele->Velocity(dimension, gp); - //cout << " " << gp_ele->Velocity(dimension, gp); + // cout << " " << gp_ele->Velocity(dimension, gp); } else { - //cout << " Gas " << Index; + // cout << " Gas " << Index; velocity[dimension] += gp_ele->Velocity_g(dimension, gp); - //cout << " " << gp_ele->Velocity(dimension, gp); + // cout << " " << gp_ele->Velocity(dimension, gp); } - //for(i_dim = 0; i_dim < dim; i_dim++) + // for(i_dim = 0; i_dim < dim; i_dim++) //{ // if (phase_index == 0) // velocity[i_dim] += gp_ele->Velocity(i_dim, gp); @@ -7139,12 +7009,18 @@ double CFiniteElementStd::Get_Element_Velocity(int Index, CRFProcess* /*m_pcs*/, // velocity[i_dim] += gp_ele->Velocity_g(i_dim, gp); //} } - //cout << "\n"; - //cout << gp_ele->Velocity(dimension, 0) << " " << gp_ele->Velocity(dimension, 1) << " " << gp_ele->Velocity(dimension, 2) << " " << gp_ele->Velocity(dimension, 3) << " " << gp_ele->Velocity(dimension, 4) << " " << gp_ele->Velocity(dimension, 5) << " " << gp_ele->Velocity(dimension, 6) << " " << gp_ele->Velocity(dimension, 7) << " " << gp_ele->Velocity(dimension, 8) << " " << gp_ele->Velocity(dimension, 9) << " " << gp_ele->Velocity(dimension, 10) << " " << gp_ele->Velocity(dimension,11) << " " << gp_ele->Velocity(dimension, 12) << " " << gp_ele->Velocity(dimension, 13) << " " << gp_ele->Velocity(dimension, 14) << "\n"; + // cout << "\n"; + // cout << gp_ele->Velocity(dimension, 0) << " " << gp_ele->Velocity(dimension, 1) << " " << + // gp_ele->Velocity(dimension, 2) << " " << gp_ele->Velocity(dimension, 3) << " " << gp_ele->Velocity(dimension, 4) + // << " " << gp_ele->Velocity(dimension, 5) << " " << gp_ele->Velocity(dimension, 6) << " " << + // gp_ele->Velocity(dimension, 7) << " " << gp_ele->Velocity(dimension, 8) << " " << gp_ele->Velocity(dimension, 9) + // << " " << gp_ele->Velocity(dimension, 10) << " " << gp_ele->Velocity(dimension,11) << " " << + // gp_ele->Velocity(dimension, 12) << " " << gp_ele->Velocity(dimension, 13) << " " << gp_ele->Velocity(dimension, + // 14) << "\n"; // Calculate average element velocity velocity[dimension] /= nGaussPoints; - //for(i_dim = 0; i_dim < dim; i_dim++) + // for(i_dim = 0; i_dim < dim; i_dim++) //{ // velocity[i_dim] /= nGaussPoints; //} @@ -7160,16 +7036,13 @@ double CFiniteElementStd::Get_Element_Velocity(int Index, CRFProcess* /*m_pcs*/, Programming: SB, BG 09/2010 **************************************************************************/ -string CFiniteElementStd::Cal_GP_Velocity_ECLIPSE(string tempstring, - bool output_average, - int phase_index, - string phase) +string CFiniteElementStd::Cal_GP_Velocity_ECLIPSE(string tempstring, bool output_average, int phase_index, string phase) { - static double temp_vel_old[3] = { 0.0, 0.0, 0.0 }, temp_vel[3] = { 0.0, 0.0, 0.0 }; - //double n_vel_x[8], n_vel_y[8], n_vel_z[8]; + static double temp_vel_old[3] = {0.0, 0.0, 0.0}, temp_vel[3] = {0.0, 0.0, 0.0}; + // double n_vel_x[8], n_vel_y[8], n_vel_z[8]; // ---- Gauss integral - //WW int gp_r=0, gp_s=0, gp_t=0; - //WW double fkt=0.0; + // WW int gp_r=0, gp_s=0, gp_t=0; + // WW double fkt=0.0; // int i_idx; double value[3], value_old[3]; ostringstream temp; @@ -7178,14 +7051,10 @@ string CFiniteElementStd::Cal_GP_Velocity_ECLIPSE(string tempstring, // Get velocities from ECLIPSE faces in element node: // WTP: InterpolateDataFromFacesToNodes2() vs InterpolateDataFromFacesToNodes()? - this->pcs->EclipseData->InterpolateDataFromFacesToNodes(this->Index, - NodalVal, - NodalVal1, - NodalVal2, - phase_index); + this->pcs->EclipseData->InterpolateDataFromFacesToNodes(this->Index, NodalVal, NodalVal1, NodalVal2, phase_index); // Gauss point loop - for(size_t i_dim = 0; i_dim < dim; i_dim++) + for (size_t i_dim = 0; i_dim < dim; i_dim++) { value[i_dim] = 0; value_old[i_dim] = 0; @@ -7195,17 +7064,17 @@ string CFiniteElementStd::Cal_GP_Velocity_ECLIPSE(string tempstring, { // Get gauss point data // GetGaussData(gp, gp_r, gp_s, gp_t); - //WW fkt = GetGaussData(gp, gp_r, gp_s, gp_t); + // WW fkt = GetGaussData(gp, gp_r, gp_s, gp_t); // Compute the shape function for interpolation within element ComputeShapefct(1); // Save former gp velocity for test use only - for(size_t i_dim = 0; i_dim < dim; i_dim++) + for (size_t i_dim = 0; i_dim < dim; i_dim++) { if (phase_index == 0) - temp_vel_old[i_dim] = gp_ele->Velocity(i_dim,gp); + temp_vel_old[i_dim] = gp_ele->Velocity(i_dim, gp); else - temp_vel_old[i_dim] = gp_ele->Velocity_g(i_dim,gp); + temp_vel_old[i_dim] = gp_ele->Velocity_g(i_dim, gp); } // Interpolate velocity from nodes to gauss point for all three velocity components @@ -7214,52 +7083,51 @@ string CFiniteElementStd::Cal_GP_Velocity_ECLIPSE(string tempstring, temp_vel[2] = interpolate(NodalVal2); // Set gauss point velocity //CB SB - for(size_t i_dim = 0; i_dim < dim; i_dim++){ - - if (phase == "WATER"){ - if (this->pcs->EclipseData->phase_shift_flag == false) - gp_ele->Velocity(i_dim, gp) = temp_vel[i_dim]; - } - else if (phase == "GAS") - gp_ele->Velocity_g(i_dim, gp) = temp_vel[i_dim]; - else if(phase == "OIL") - { - if (this->pcs->EclipseData->phase_shift_flag == true) - gp_ele->Velocity(i_dim, gp) = temp_vel[i_dim]; - else - gp_ele->Velocity_g(i_dim, gp) = temp_vel[i_dim]; - } - - } - // Data for Test Output - if (output_average == true) //WW - { - for(size_t i_dim = 0; i_dim < dim; i_dim++) + for (size_t i_dim = 0; i_dim < dim; i_dim++) + { + if (phase == "WATER") + { + if (this->pcs->EclipseData->phase_shift_flag == false) + gp_ele->Velocity(i_dim, gp) = temp_vel[i_dim]; + } + else if (phase == "GAS") + gp_ele->Velocity_g(i_dim, gp) = temp_vel[i_dim]; + else if (phase == "OIL") + { + if (this->pcs->EclipseData->phase_shift_flag == true) + gp_ele->Velocity(i_dim, gp) = temp_vel[i_dim]; + else + gp_ele->Velocity_g(i_dim, gp) = temp_vel[i_dim]; + } + } + // Data for Test Output + if (output_average == true) // WW + { + for (size_t i_dim = 0; i_dim < dim; i_dim++) // average value of all Gauss points - value_old[i_dim] = value_old[i_dim] + temp_vel_old[i_dim] / - nGaussPoints; - for(size_t i_dim = 0; i_dim < dim; i_dim++) + value_old[i_dim] = value_old[i_dim] + temp_vel_old[i_dim] / nGaussPoints; + for (size_t i_dim = 0; i_dim < dim; i_dim++) // average value of all Gauss points value[i_dim] = value[i_dim] + temp_vel[i_dim] / nGaussPoints; } else if (gp == 1) { - for(size_t i_dim = 0; i_dim < dim; i_dim++) + for (size_t i_dim = 0; i_dim < dim; i_dim++) value_old[i_dim] = temp_vel_old[i_dim]; - for(size_t i_dim = 0; i_dim < dim; i_dim++) + for (size_t i_dim = 0; i_dim < dim; i_dim++) value[i_dim] = temp_vel[i_dim]; } - } // end gauss point loop + } // end gauss point loop // Data for Test Output - for(size_t i_dim = 0; i_dim < dim; i_dim++) + for (size_t i_dim = 0; i_dim < dim; i_dim++) { temp.str(""); temp.clear(); temp << value_old[i_dim]; tempstring += "; " + temp.str(); } - for(size_t i_dim = 0; i_dim < dim; i_dim++) + for (size_t i_dim = 0; i_dim < dim; i_dim++) { temp.str(""); temp.clear(); @@ -7324,9 +7192,9 @@ void CFiniteElementStd::AssembleRHS(int dimension) pcs = m_pcs; int nidx1; // if (!(m_pcs->pcs_type_name.find("GROUNDWATER_FLOW") != string::npos)) // TF - if (!(m_pcs->getProcessType () == GROUNDWATER_FLOW)) + if (!(m_pcs->getProcessType() == GROUNDWATER_FLOW)) nidx1 = m_pcs->GetNodeValueIndex("PRESSURE1") + 1; - else // then, this is GROUNDWATER_FLOW + else // then, this is GROUNDWATER_FLOW { nidx1 = m_pcs->GetNodeValueIndex("HEAD") + 1; HEAD_Flag = 1; @@ -7352,8 +7220,8 @@ void CFiniteElementStd::AssembleRHS(int dimension) //--------------------------------------------------------- // Compute geometry //--------------------------------------------------------- - ComputeGradShapefct(1); // Linear interpolation function - ComputeShapefct(1); // Linear interpolation function + ComputeGradShapefct(1); // Linear interpolation function + ComputeShapefct(1); // Linear interpolation function // Material CalCoefLaplace(true); @@ -7364,35 +7232,34 @@ void CFiniteElementStd::AssembleRHS(int dimension) // Let's get the viscosity too. // 09/2010 TF compiler complains about unused value // CFluidProperties *FluidProp = mfp_vector[0]; - if(gravity_constant < MKleinsteZahl) // HEAD version + if (gravity_constant < MKleinsteZahl) // HEAD version rho = 1.0; - else if(HEAD_Flag) + else if (HEAD_Flag) // FS/WW 21.05.2010 - //fkt = fkt*rho * gravity_constant/FluidProp->Viscosity(); + // fkt = fkt*rho * gravity_constant/FluidProp->Viscosity(); rho = 1.0; else rho *= gravity_constant; - // rho *= gravity_constant/FluidProp->Viscosity(); // This seems to divide viscosity two times. Thus, wrong. + // rho *= gravity_constant/FluidProp->Viscosity(); // This seems to divide viscosity two times. + // Thus, + // wrong. fktG *= rho; for (int i = 0; i < nnodes; i++) for (int j = 0; j < nnodes; j++) for (size_t k = 0; k < dim; k++) { - NodalVal[i] -= fkt * dshapefct[k * nnodes + j] - //NW dshapefct[dimension*nnodes+j] -> dshapefct[k*nnodes+j] - * mat[dim * dimension + - k] * shapefct[i] * NodalVal1[j]; + NodalVal[i] -= fkt * dshapefct[k * nnodes + j] + // NW dshapefct[dimension*nnodes+j] -> dshapefct[k*nnodes+j] + * mat[dim * dimension + k] * shapefct[i] * NodalVal1[j]; // ************************************* - //FS/WW 21.05.2010 + // FS/WW 21.05.2010 if (HEAD_Flag) continue; //*************************************** NodalVal2[i] += fktG * dshapefct[k * nnodes + j] - //NW dshapefct[dimension*nnodes+j] -> dshapefct[k*nnodes+j] - * mat[dim * dimension + - k] * shapefct[i] * - MeshElement->nodes[j]->getData()[2]; + // NW dshapefct[dimension*nnodes+j] -> dshapefct[k*nnodes+j] + * mat[dim * dimension + k] * shapefct[i] * MeshElement->nodes[j]->getData()[2]; } } @@ -7403,40 +7270,39 @@ void CFiniteElementStd::AssembleRHS(int dimension) { m_pcs = pcs_vector[i]; // if (m_pcs->pcs_type_name.find("GROUNDWATER_FLOW") != string::npos) // TF - if (m_pcs->getProcessType () == GROUNDWATER_FLOW) + if (m_pcs->getProcessType() == GROUNDWATER_FLOW) { IsGroundwaterIntheProcesses = 1; - break; + break; } } // Checking the coordinateflag for proper solution. int checkZaxis = 0; int coordinateflag = pcs->m_msh->GetCoordinateFlag(); - if( (coordinateflag == 12) || (coordinateflag == 22 && dimension == 1) || - (coordinateflag == 32 && dimension == 2) ) - checkZaxis = 1; // Then, this gotta be z axis. + if ((coordinateflag == 12) || (coordinateflag == 22 && dimension == 1) || (coordinateflag == 32 && dimension == 2)) + checkZaxis = 1; // Then, this gotta be z axis. // Compansate the gravity term along Z direction - if(checkZaxis && IsGroundwaterIntheProcesses == 0 ) + if (checkZaxis && IsGroundwaterIntheProcesses == 0) for (int i = 0; i < nnodes; i++) NodalVal[i] -= NodalVal2[i]; // Store the influence into the global vectors. m_pcs = PCSGet("FLUID_MOMENTUM"); for (int i = 0; i < nnodes; i++) - { + { #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - //TODO -#elif defined(NEW_EQS) //WW +// TODO +#elif defined(NEW_EQS) // WW m_pcs->eqs_new->b[eqs_number[i]] += NodalVal[i]; #else m_pcs->eqs->b[eqs_number[i]] += NodalVal[i]; #endif - } + } // OK. Let's add gravity term that incorporates the density coupling term. // This is convenient. The function is already written in RF. - //Assemble_Gravity(); + // Assemble_Gravity(); } /************************************************************************** @@ -7451,24 +7317,24 @@ void CFiniteElementStd::AssembleRHS(int dimension) void CFiniteElementStd::AssembleParabolicEquation() { double relax0, relax1, pcs_time_step, dt_inverse; - long dm_shift = 0, cshift = 0; //WW 05.01.07 + long dm_shift = 0, cshift = 0; // WW 05.01.07 // // JT2012: Get the time step of this process! Now dt can be independently controlled. pcs_time_step = pcs->Tim->time_step_length; - dt_inverse = 1.0/pcs_time_step; // (also, no need to check minimum. It is handeled in Tim. + dt_inverse = 1.0 / pcs_time_step; // (also, no need to check minimum. It is handeled in Tim. - //WW 05.01.07 - relax0 = pcs->m_num->nls_relaxation; //WW + // WW 05.01.07 + relax0 = pcs->m_num->nls_relaxation; // WW relax1 = 1.0; - if(relax0 < DBL_MIN) + if (relax0 < DBL_MIN) relax0 = 1.0; relax1 = 1.0 - relax0; // - if(pcs->dof > 1) + if (pcs->dof > 1) cshift = NodeShift[pcs->continuum]; - if(pcs->type / 10 == 4) + if (pcs->type / 10 == 4) dm_shift = problem_dimension_dm; //---------------------------------------------------------------------- // Dynamic @@ -7476,30 +7342,29 @@ void CFiniteElementStd::AssembleParabolicEquation() double* p_n = NULL; double fac1, fac2; double beta1 = 0.0; - if(pcs->pcs_type_name_vector.size() && pcs->pcs_type_name_vector[0].find("DYNAMIC") == 0) + if (pcs->pcs_type_name_vector.size() && pcs->pcs_type_name_vector[0].find("DYNAMIC") == 0) { dynamic = true; - if(pcs->m_num->CheckDynamic()) // why NUM, it is PCS - beta1 = pcs->m_num->GetDynamicDamping_beta1(); + if (pcs->m_num->CheckDynamic()) // why NUM, it is PCS + beta1 = pcs->m_num->GetDynamicDamping_beta1(); } //---------------------------------------------------------------------- // Initialize. // if (pcs->Memory_Type==2) skip the these initialization if (PcsType == EPT_MULTIPHASE_FLOW || PcsType == EPT_PSGLOBAL || PcsType == EPT_MULTI_COMPONENTIAL_FLOW - || PcsType == EPT_THERMAL_NONEQUILIBRIUM || PcsType == EPT_TES) + || PcsType == EPT_THERMAL_NONEQUILIBRIUM + || PcsType == EPT_TES) (*Mass2) = 0.0; else (*Mass) = 0.0; (*Laplace) = 0.0; - if (PcsType == EPT_MULTI_COMPONENTIAL_FLOW - || PcsType == EPT_TES - || PcsType == EPT_THERMAL_NONEQUILIBRIUM) + if (PcsType == EPT_MULTI_COMPONENTIAL_FLOW || PcsType == EPT_TES || PcsType == EPT_THERMAL_NONEQUILIBRIUM) { (*Advection) = 0.0; - (*Content) = 0.0; - } + (*Content) = 0.0; + } //---------------------------------------------------------------------- // GEO @@ -7507,23 +7372,23 @@ void CFiniteElementStd::AssembleParabolicEquation() //---------------------------------------------------------------------- // Calculate matrices // Mass matrix.......................................................... - if(PcsType == EPT_MULTIPHASE_FLOW) //WW + if (PcsType == EPT_MULTIPHASE_FLOW) // WW { - if(pcs->m_num->ele_mass_lumping) + if (pcs->m_num->ele_mass_lumping) CalcLumpedMass2(); else CalcMass2(); } - else if(PcsType == EPT_PSGLOBAL) //PCH + else if (PcsType == EPT_PSGLOBAL) // PCH { - if(pcs->m_num->ele_mass_lumping) + if (pcs->m_num->ele_mass_lumping) CalcLumpedMassPSGLOBAL(); else CalcMassPSGLOBAL(); } - else if(PcsType == EPT_MULTI_COMPONENTIAL_FLOW) //AKS + else if (PcsType == EPT_MULTI_COMPONENTIAL_FLOW) // AKS { - if(pcs->m_num->ele_mass_lumping) + if (pcs->m_num->ele_mass_lumping) CalcLumpedMassMCF(); else CalcMassMCF(); @@ -7534,48 +7399,50 @@ void CFiniteElementStd::AssembleParabolicEquation() } else if (PcsType == EPT_TES) { - if(pcs->m_num->ele_mass_lumping) + if (pcs->m_num->ele_mass_lumping) CalcLumpedMassTES(); else CalcMassTES(); } else { - if(pcs->m_num->ele_mass_lumping) + if (pcs->m_num->ele_mass_lumping) CalcLumpedMass(); else CalcMass(); } // Laplace matrix....................................................... - if (PcsType==EPT_MULTI_COMPONENTIAL_FLOW) - CalcLaplaceMCF(); //AKS + if (PcsType == EPT_MULTI_COMPONENTIAL_FLOW) + CalcLaplaceMCF(); // AKS else CalcLaplace(); - if (PcsType==EPT_MULTI_COMPONENTIAL_FLOW) + if (PcsType == EPT_MULTI_COMPONENTIAL_FLOW) { CalcAdvectionMCF(); CalcContentMCF(); } - if (PcsType==EPT_THERMAL_NONEQUILIBRIUM) { //AKS/NB + if (PcsType == EPT_THERMAL_NONEQUILIBRIUM) + { // AKS/NB CalcAdvectionTNEQ(); CalcContentTNEQ(); } - if (PcsType==EPT_TES) { //AKS/NB + if (PcsType == EPT_TES) + { // AKS/NB CalcAdvectionTES(); CalcContentTES(); } - if(RD_Flag) //YD /WW + if (RD_Flag) // YD /WW Assemble_DualTransfer(); - if(pcs->Tim->time_control_type == TimeControlType::NEUMANN) - pcs->timebuffer /= mat[0]; //YD + if (pcs->Tim->time_control_type == TimeControlType::NEUMANN) + pcs->timebuffer /= mat[0]; // YD //====================================================================== // Assemble global matrix //---------------------------------------------------------------------- // Assemble local left matrix: // [C]/dt + theta [K] non_linear_function for static problems // [C] + beta1*dt [K] for dynamic problems: ? different equation type - if(dynamic) + if (dynamic) { fac1 = 1.0; fac2 = beta1 * pcs_time_step; @@ -7583,20 +7450,21 @@ void CFiniteElementStd::AssembleParabolicEquation() else { fac1 = dt_inverse; - fac2 = relax0; //unterrelaxation WW theta* non_linear_function_iter; //*geo_fac; + fac2 = relax0; // unterrelaxation WW theta* non_linear_function_iter; //*geo_fac; } - //Mass matrix - if(pcs->PartialPS != 1) // PCH if not partial-pressure-based + // Mass matrix + if (pcs->PartialPS != 1) // PCH if not partial-pressure-based { if (PcsType == EPT_MULTIPHASE_FLOW || PcsType == EPT_PSGLOBAL || PcsType == EPT_MULTI_COMPONENTIAL_FLOW - || PcsType == EPT_THERMAL_NONEQUILIBRIUM || PcsType == EPT_TES) + || PcsType == EPT_THERMAL_NONEQUILIBRIUM + || PcsType == EPT_TES) { - *StiffMatrix = *Mass2; + *StiffMatrix = *Mass2; } else { - *StiffMatrix = *Mass; + *StiffMatrix = *Mass; } (*StiffMatrix) *= fac1; } @@ -7604,34 +7472,33 @@ void CFiniteElementStd::AssembleParabolicEquation() // Laplace matrix // PCH to reduce PDE to ODE in Saturation model // PCH: If equation 2 in Two-phase flow. - if(pcs->pcs_type_number == 1 && pcs->ML_Cap != 0) - { // then, Laplace equation is no need. Only solve for ODE + if (pcs->pcs_type_number == 1 && pcs->ML_Cap != 0) + { // then, Laplace equation is no need. Only solve for ODE } else { - *AuxMatrix = *Laplace; - if (PcsType == EPT_MULTI_COMPONENTIAL_FLOW - || PcsType == EPT_THERMAL_NONEQUILIBRIUM || PcsType == EPT_TES) + *AuxMatrix = *Laplace; + if (PcsType == EPT_MULTI_COMPONENTIAL_FLOW || PcsType == EPT_THERMAL_NONEQUILIBRIUM || PcsType == EPT_TES) { - *AuxMatrix += *Advection; + *AuxMatrix += *Advection; *AuxMatrix += *Content; } } - (*AuxMatrix) *= fac2; - *StiffMatrix += *AuxMatrix; + (*AuxMatrix) *= fac2; + *StiffMatrix += *AuxMatrix; //} //---------------------------------------------------------------------- // Add local matrix to global matrix - ///Initialize temporal vector + /// Initialize temporal vector for (int i = 0; i < nnodes; i++) NodalVal[i] = 0.0; - if(PcsType == EPT_MULTIPHASE_FLOW) // For DOF>1: 27.2.2007 WW + if (PcsType == EPT_MULTIPHASE_FLOW) // For DOF>1: 27.2.2007 WW for (int i = 0; i < nnodes; i++) NodalVal[i + nnodes] = 0.0; - if (PcsType==EPT_MULTI_COMPONENTIAL_FLOW || PcsType == EPT_THERMAL_NONEQUILIBRIUM || PcsType == EPT_TES) + if (PcsType == EPT_MULTI_COMPONENTIAL_FLOW || PcsType == EPT_THERMAL_NONEQUILIBRIUM || PcsType == EPT_TES) { for (int j = 0; j < pcs->dof * nnodes; j++) { @@ -7639,45 +7506,42 @@ void CFiniteElementStd::AssembleParabolicEquation() } } - if(pcs->m_num->nls_method > 0 && (!dynamic)) //Newton method + if (pcs->m_num->nls_method > 0 && (!dynamic)) // Newton method StiffMatrix->multi(NodalVal1, NodalVal, -1.0); - /// If JFNK. 10.08.2010 WW -#if defined(NEW_EQS) && defined(JFNK_H2M) - if(pcs->m_num->nls_method == 2) +/// If JFNK. 10.08.2010 WW +#if defined(NEW_EQS) && defined(JFNK_H2M) + if (pcs->m_num->nls_method == 2) { StiffMatrix->multi(NodalVal1, NodalVal, -1.0); /// Save diagnal entry for Jacobi preconditioner. 02.2011. WW - if(pcs->JFNK_precond) + if (pcs->JFNK_precond) { - if(PcsType == EPT_MULTIPHASE_FLOW) + if (PcsType == EPT_MULTIPHASE_FLOW) { int jj_sh; long j_sh = 0; - for(int ii = 0; ii < 2; ii++) + for (int ii = 0; ii < 2; ii++) { long i_sh = NodeShift[ii + dm_shift]; long ii_sh = ii * nnodes; - for(int jj = 0; jj < 2; jj++) + for (int jj = 0; jj < 2; jj++) { j_sh = NodeShift[jj + dm_shift]; jj_sh = jj * nnodes; - for(int i = 0; i < nnodes; i++) + for (int i = 0; i < nnodes; i++) { long kk = i_sh + eqs_number[i]; - for(int j = 0; j < nnodes; j++) + for (int j = 0; j < nnodes; j++) { -#ifdef _OPENMP //13.11.2008. WW +#ifdef _OPENMP // 13.11.2008. WW #pragma omp critical #endif /// JFNK and Jacobi preconditioner - if(kk != j_sh + eqs_number[j]) + if (kk != j_sh + eqs_number[j]) continue; - pcs->eqs_new->prec_M[kk] += - (*StiffMatrix)(i + ii_sh, - j + - jj_sh); + pcs->eqs_new->prec_M[kk] += (*StiffMatrix)(i + ii_sh, j + jj_sh); } } } @@ -7685,36 +7549,36 @@ void CFiniteElementStd::AssembleParabolicEquation() } else { - cshift += NodeShift[dm_shift]; //WW 05.01.07 - for(int i = 0; i < nnodes; i++) + cshift += NodeShift[dm_shift]; // WW 05.01.07 + for (int i = 0; i < nnodes; i++) { long kk = cshift + eqs_number[i]; - for(int j = 0; j < nnodes; j++) + for (int j = 0; j < nnodes; j++) { -#ifdef _OPENMP //13.11.2008. WW +#ifdef _OPENMP // 13.11.2008. WW #pragma omp critical #endif /// JFNK and Jacobi preconditioner - if(kk != cshift + eqs_number[j]) + if (kk != cshift + eqs_number[j]) continue; - pcs->eqs_new->prec_M[kk] += (*StiffMatrix)(i,j); + pcs->eqs_new->prec_M[kk] += (*StiffMatrix)(i, j); } } } } } - //else /// else if not JFNK -#endif // end of #ifdef NEW_EQS +// else /// else if not JFNK +#endif // end of #ifdef NEW_EQS //{ - //---------------------------------------------------------------------- - // Add local matrix to global matrix - //add2GlobalMatrixII(); //TN - added again 07/2013 + //---------------------------------------------------------------------- + // Add local matrix to global matrix + // add2GlobalMatrixII(); //TN - added again 07/2013 //} //====================================================================== // Assemble local RHS vector: // ( [C]/dt - (1.0-theta) [K] non_linear_function ) u0 for static problems // ( [C] + beta1*dt [K] ) dp for dynamic problems - if(dynamic) + if (dynamic) { fac1 = -1.0; fac2 = beta1 * pcs_time_step; @@ -7722,90 +7586,89 @@ void CFiniteElementStd::AssembleParabolicEquation() else { fac1 = dt_inverse; - fac2 = relax1; // Unerrelaxation. WW (1.0-theta) * non_linear_function_t0; //*geo_fac; + fac2 = relax1; // Unerrelaxation. WW (1.0-theta) * non_linear_function_t0; //*geo_fac; } // Mass - Storage - if(pcs->PartialPS != 1) // PCH if not partial-pressure-based + if (pcs->PartialPS != 1) // PCH if not partial-pressure-based { if (PcsType == EPT_MULTIPHASE_FLOW || PcsType == EPT_PSGLOBAL || PcsType == EPT_MULTI_COMPONENTIAL_FLOW - || PcsType == EPT_THERMAL_NONEQUILIBRIUM || PcsType == EPT_TES) //PCH + || PcsType == EPT_THERMAL_NONEQUILIBRIUM + || PcsType == EPT_TES) // PCH *AuxMatrix1 = *Mass2; else *AuxMatrix1 = *Mass; (*AuxMatrix1) *= fac1; } - //Laplace - Diffusion + // Laplace - Diffusion // Laplace matrix // PCH: If equation 2 in Two-phase flow. - if(pcs->pcs_type_number == 1 && pcs->ML_Cap != 0) - { // then, Laplace equation is no need. Only solve for ODE + if (pcs->pcs_type_number == 1 && pcs->ML_Cap != 0) + { // then, Laplace equation is no need. Only solve for ODE } else { - *AuxMatrix = *Laplace; - if(PcsType==EPT_MULTI_COMPONENTIAL_FLOW || PcsType==EPT_THERMAL_NONEQUILIBRIUM || PcsType == EPT_TES) + *AuxMatrix = *Laplace; + if (PcsType == EPT_MULTI_COMPONENTIAL_FLOW || PcsType == EPT_THERMAL_NONEQUILIBRIUM || PcsType == EPT_TES) { - *AuxMatrix += *Advection; - *AuxMatrix += *Content; + *AuxMatrix += *Advection; + *AuxMatrix += *Content; } } - (*AuxMatrix) *= fac2; - *AuxMatrix1 -= *AuxMatrix; + (*AuxMatrix) *= fac2; + *AuxMatrix1 -= *AuxMatrix; // 07.01.07 WW int idx = idx0; - if(pcs->continuum == 1) - idx = idxp20; + if (pcs->continuum == 1) + idx = idxp20; for (int i = 0; i < nnodes; i++) - NodalVal0[i] = pcs->GetNodeValue(nodes[i],idx); + NodalVal0[i] = pcs->GetNodeValue(nodes[i], idx); - if(PcsType == EPT_MULTI_COMPONENTIAL_FLOW)// For DOF>1: 27.2.2007 WW + if (PcsType == EPT_MULTI_COMPONENTIAL_FLOW) // For DOF>1: 27.2.2007 WW { for (int in = 0; in < pcs->dof; in++) { for (int i = 0; i < nnodes; i++) { - NodalVal0[i + in*nnodes] = pcs->GetNodeValue(nodes[i], idxMCF[in]); - NodalVal[i + in*nnodes] = 0.0; + NodalVal0[i + in * nnodes] = pcs->GetNodeValue(nodes[i], idxMCF[in]); + NodalVal[i + in * nnodes] = 0.0; } } } - else if(PcsType==EPT_THERMAL_NONEQUILIBRIUM) // For DOF>1: 27.2.2007 WW + else if (PcsType == EPT_THERMAL_NONEQUILIBRIUM) // For DOF>1: 27.2.2007 WW { for (int i = 0; i < nnodes; i++) { - NodalVal[i] = 0.0; - NodalVal0[i+nnodes] = pcs->GetNodeValue(nodes[i],idxt0); - NodalVal[i+nnodes] = 0.0; + NodalVal0[i + nnodes] = pcs->GetNodeValue(nodes[i], idxt0); + NodalVal[i + nnodes] = 0.0; - NodalVal0[i+2*nnodes] = pcs->GetNodeValue(nodes[i],idx_t2_0); - NodalVal[i+2*nnodes] = 0.0; + NodalVal0[i + 2 * nnodes] = pcs->GetNodeValue(nodes[i], idx_t2_0); + NodalVal[i + 2 * nnodes] = 0.0; - NodalVal0[i+3*nnodes] = pcs->GetNodeValue(nodes[i],idx_x0); - NodalVal[i+3*nnodes] = 0.0; + NodalVal0[i + 3 * nnodes] = pcs->GetNodeValue(nodes[i], idx_x0); + NodalVal[i + 3 * nnodes] = 0.0; } } - else if(PcsType==EPT_TES) // For DOF>1: 27.2.2007 WW + else if (PcsType == EPT_TES) // For DOF>1: 27.2.2007 WW { for (int i = 0; i < nnodes; i++) { - NodalVal[i] = 0.0; - NodalVal0[i+nnodes] = pcs->GetNodeValue(nodes[i], idxt0); - NodalVal[i+nnodes] = 0.0; + NodalVal0[i + nnodes] = pcs->GetNodeValue(nodes[i], idxt0); + NodalVal[i + nnodes] = 0.0; - NodalVal0[i+2*nnodes] = pcs->GetNodeValue(nodes[i], idx_x0); - NodalVal[i+2*nnodes] = 0.0; + NodalVal0[i + 2 * nnodes] = pcs->GetNodeValue(nodes[i], idx_x0); + NodalVal[i + 2 * nnodes] = 0.0; } } - else if(PcsType == EPT_PSGLOBAL) - {// For DOF>1: + else if (PcsType == EPT_PSGLOBAL) + { // For DOF>1: for (int i = 0; i < nnodes; i++) { NodalVal[i] = 0.0; - NodalVal0[i + nnodes] = pcs->GetNodeValue(nodes[i],idxSn0); + NodalVal0[i + nnodes] = pcs->GetNodeValue(nodes[i], idxSn0); NodalVal[i + nnodes] = 0.0; } } @@ -7813,28 +7676,30 @@ void CFiniteElementStd::AssembleParabolicEquation() // PCH: Type III (Cauchy boundary conditions) in need, it should be added here. // - if(dynamic) + if (dynamic) { // Velocity of pressure of the previous step p_n = dm_pcs->GetAuxArray(); for (int i = 0; i < nnodes; i++) NodalVal0[i] = p_n[nodes[i] + NodeShift[dm_shift]]; Mass->multi(NodalVal0, NodalVal, -1.0); - //p_n+vp*dt + // p_n+vp*dt for (int i = 0; i < nnodes; i++) { NodalVal0[i] *= pcs_time_step; - NodalVal0[i] += pcs->GetNodeValue(nodes[i],idx_pres); + NodalVal0[i] += pcs->GetNodeValue(nodes[i], idx_pres); } Laplace->multi(NodalVal0, NodalVal, -1.0); } if (PcsType == EPT_MULTIPHASE_FLOW || PcsType == EPT_PSGLOBAL || PcsType == EPT_MULTI_COMPONENTIAL_FLOW - || PcsType == EPT_THERMAL_NONEQUILIBRIUM || PcsType == EPT_TES) + || PcsType == EPT_THERMAL_NONEQUILIBRIUM + || PcsType == EPT_TES) { int nDF = 2; - if(PcsType == EPT_MULTI_COMPONENTIAL_FLOW || PcsType == EPT_THERMAL_NONEQUILIBRIUM || PcsType == EPT_TES) nDF=pcs->dof; - for(int ii = 0; ii < nDF; ii++) + if (PcsType == EPT_MULTI_COMPONENTIAL_FLOW || PcsType == EPT_THERMAL_NONEQUILIBRIUM || PcsType == EPT_TES) + nDF = pcs->dof; + for (int ii = 0; ii < nDF; ii++) { int ii_sh = ii * nnodes; for (int i = 0; i < nnodes; i++) @@ -7843,7 +7708,7 @@ void CFiniteElementStd::AssembleParabolicEquation() long i_sh = NodeShift[ii + dm_shift]; eqs_rhs[i_sh + eqs_number[i]] += NodalVal[i + ii_sh]; #endif - (*RHS)[i + LocalShift + ii_sh] += NodalVal[i + ii_sh]; + (*RHS)[i + LocalShift + ii_sh] += NodalVal[i + ii_sh]; } } } @@ -7855,11 +7720,11 @@ void CFiniteElementStd::AssembleParabolicEquation() #if !defined(USE_PETSC) // && !defined(other parallel libs)//03~04.3012. WW eqs_rhs[cshift + eqs_number[i]] += NodalVal[i]; #endif - (*RHS)[i + LocalShift] += NodalVal[i]; + (*RHS)[i + LocalShift] += NodalVal[i]; } } // - //RHS->Write(); + // RHS->Write(); } #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW /*! @@ -7870,137 +7735,130 @@ void CFiniteElementStd::AssembleParabolicEquation() //------------------------------------------------------ void CFiniteElementStd::add2GlobalMatrixII() { - int i; - int m_dim, n_dim; - int dof = pcs->pcs_number_of_primary_nvals; - if(pcs->GetContinnumType() == 1) - dof = 1; + int i; + int m_dim, n_dim; + int dof = pcs->pcs_number_of_primary_nvals; + if (pcs->GetContinnumType() == 1) + dof = 1; - double *local_matrix = NULL; - double *local_vec = NULL; - petsc_group::PETScLinearSolver *eqs = pcs->eqs_new; + double* local_matrix = NULL; + double* local_vec = NULL; + petsc_group::PETScLinearSolver* eqs = pcs->eqs_new; #define n_assmb_petsc_test #ifdef assmb_petsc_test - char rank_char[10]; - sprintf(rank_char, "%d", eqs->getMPI_Rank()); - string fname = FileName + rank_char + "_e_matrix.txt"; - ofstream os_t(fname.c_str(), ios::app); - os_t<<"\n=================================================="<<"\n"; + char rank_char[10]; + sprintf(rank_char, "%d", eqs->getMPI_Rank()); + string fname = FileName + rank_char + "_e_matrix.txt"; + ofstream os_t(fname.c_str(), ios::app); + os_t << "\n==================================================" + << "\n"; #endif - if(act_nodes != nnodes) - { - m_dim = act_nodes * dof; - n_dim = nnodes * dof; - - const int dim_full = nnodes * dof; - int i_dom, in; - // put the subdomain portion of local stiffness matrix to Mass - double *loc_m = StiffMatrix->getEntryArray(); - double *loc_v = RHS->getEntryArray(); - - for(i = 0; i < nnodes; i++) - { - const int i_buff = MeshElement->nodes[i]->GetEquationIndex() * dof; - for(int k=0; kgetEntryArray(); //Temporary use - for( i=0; inodes[local_idx[in]]->GetEquationIndex() * dof + i_dom; + const int dim_full = nnodes * dof; + int i_dom, in; + // put the subdomain portion of local stiffness matrix to Mass + double* loc_m = StiffMatrix->getEntryArray(); + double* loc_v = RHS->getEntryArray(); + for (i = 0; i < nnodes; i++) + { + const int i_buff = MeshElement->nodes[i]->GetEquationIndex() * dof; + for (int k = 0; k < dof; k++) + { + idxn[k * nnodes + i] = i_buff + k; + } + // local_vec[i] = 0.; + } - for(int j=0; jgetEntryArray(); // Temporary use + for (i = 0; i < m_dim; i++) + { + i_dom = i / act_nodes; + in = i % act_nodes; + int i_full = local_idx[in] + i_dom * nnodes; + local_vec[i] = loc_v[i_full]; + i_full *= dim_full; + idxm[i] = MeshElement->nodes[local_idx[in]]->GetEquationIndex() * dof + i_dom; - } + for (int j = 0; j < dim_full; j++) + { + local_matrix[i * dim_full + j] = loc_m[i_full + j]; - //TEST +// TEST #ifdef assmb_petsc_test - os_t<<"\n"; + os_t << "(" << local_idx[in] << ") " << local_matrix[i * dim_full + j] << " "; #endif //#ifdef assmb_petsc_test + } +// TEST +#ifdef assmb_petsc_test + os_t << "\n"; +#endif //#ifdef assmb_petsc_test + } } - - - } - else - { - m_dim = nnodes * dof; - n_dim = m_dim; - //---------------------------------------------------------------------- - // For overlapped partition DDC - local_matrix = StiffMatrix->getEntryArray(); - local_vec = RHS->getEntryArray(); - - for(i = 0; i < nnodes; i++) + else { - const int i_buff = MeshElement->nodes[i]->GetEquationIndex() * dof; - for(int k=0; kgetEntryArray(); + local_vec = RHS->getEntryArray(); + for (i = 0; i < nnodes; i++) + { + const int i_buff = MeshElement->nodes[i]->GetEquationIndex() * dof; + for (int k = 0; k < dof; k++) + { + const int ki = k * nnodes + i; + idxm[ki] = i_buff + k; + idxn[ki] = idxm[ki]; + } + // local_vec[i] = 0.; + } + } - //TEST +// TEST #ifdef assmb_petsc_test - { - os_t<<"\n------------------"<Write(os_t); - RHS->Write(os_t); - - os_t<<"Node ID: "; - for( i=0; inodes[i]->GetEquationIndex()<<" "; - } - os_t<<"\n"; - os_t<<"Act. Local ID: "; - for( i=0; iWrite(os_t); + RHS->Write(os_t); + + os_t << "Node ID: "; + for (i = 0; i < nnodes; i++) + { + os_t << MeshElement->nodes[i]->GetEquationIndex() << " "; + } + os_t << "\n"; + os_t << "Act. Local ID: "; + for (i = 0; i < act_nodes; i++) + { + os_t << local_idx[i] << " "; + } + os_t << "\n"; + os_t << "Act. Global ID:"; + for (i = 0; i < act_nodes * dof; i++) + { + os_t << idxm[i] << " "; + } + os_t << "\n"; + } os_t.close(); -#endif //ifdef assmb_petsc_test +#endif // ifdef assmb_petsc_test - eqs->addMatrixEntries(m_dim, idxm, n_dim, idxn, local_matrix); - eqs->setArrayValues(1, m_dim, idxm, local_vec); - //eqs->AssembleRHS_PETSc(); - //eqs->AssembleMatrixPETSc(MAT_FINAL_ASSEMBLY ); + eqs->addMatrixEntries(m_dim, idxm, n_dim, idxn, local_matrix); + eqs->setArrayValues(1, m_dim, idxm, local_vec); + // eqs->AssembleRHS_PETSc(); + // eqs->AssembleMatrixPETSc(MAT_FINAL_ASSEMBLY ); } #else //------------------------------------------------------ @@ -8010,57 +7868,54 @@ void CFiniteElementStd::add2GlobalMatrixII() 22.06.2011. WW */ //------------------------------------------------------ - void CFiniteElementStd::add2GlobalMatrixII(const int block_cols) +void CFiniteElementStd::add2GlobalMatrixII(const int block_cols) { long dm_shift = 0, cshift = 0; - if(pcs->dof > 1) + if (pcs->dof > 1) cshift = NodeShift[pcs->continuum]; - if(pcs->type / 10 == 4) + if (pcs->type / 10 == 4) dm_shift = problem_dimension_dm; - int i, j, ii, jj, ii_sh; long i_sh, kk; #if defined(NEW_EQS) - CSparseMatrix* A = NULL; //WW - if(m_dom) + CSparseMatrix* A = NULL; // WW + if (m_dom) A = m_dom->eqs->A; else A = pcs->eqs_new->A; #endif // For DOF>1: if (PcsType == EPT_MULTIPHASE_FLOW || PcsType == EPT_PSGLOBAL || PcsType == EPT_MULTI_COMPONENTIAL_FLOW - || PcsType == EPT_THERMAL_NONEQUILIBRIUM || PcsType == EPT_TES) + || PcsType == EPT_THERMAL_NONEQUILIBRIUM + || PcsType == EPT_TES) { int nDF = 2; - if (PcsType == EPT_MULTI_COMPONENTIAL_FLOW - || PcsType == EPT_THERMAL_NONEQUILIBRIUM || PcsType == EPT_TES) + if (PcsType == EPT_MULTI_COMPONENTIAL_FLOW || PcsType == EPT_THERMAL_NONEQUILIBRIUM || PcsType == EPT_TES) { - nDF=pcs->dof; + nDF = pcs->dof; } int jj_sh; long j_sh = 0; - for(ii = 0; ii < nDF; ii++) + for (ii = 0; ii < nDF; ii++) { i_sh = NodeShift[ii + dm_shift]; ii_sh = ii * nnodes; - for(jj = 0; jj < block_cols; jj++) + for (jj = 0; jj < block_cols; jj++) { j_sh = NodeShift[jj + dm_shift]; jj_sh = jj * nnodes; - for(i = 0; i < nnodes; i++) + for (i = 0; i < nnodes; i++) { kk = i_sh + eqs_number[i]; // 02.2011. WW - for(j = 0; j < nnodes; j++) + for (j = 0; j < nnodes; j++) { #ifdef NEW_EQS - (*A)(kk, j_sh + eqs_number[j]) += \ - (*StiffMatrix)(i + ii_sh,j + jj_sh); + (*A)(kk, j_sh + eqs_number[j]) += (*StiffMatrix)(i + ii_sh, j + jj_sh); #else - MXInc(kk, j_sh + eqs_number[j], \ - (*StiffMatrix)(i + ii_sh,j + jj_sh)); + MXInc(kk, j_sh + eqs_number[j], (*StiffMatrix)(i + ii_sh, j + jj_sh)); #endif } } @@ -8069,29 +7924,27 @@ void CFiniteElementStd::add2GlobalMatrixII() } else { - cshift += NodeShift[dm_shift]; //WW 05.01.07 - for(i = 0; i < nnodes; i++) + cshift += NodeShift[dm_shift]; // WW 05.01.07 + for (i = 0; i < nnodes; i++) { kk = cshift + eqs_number[i]; // 02.2011. WW - for(j = 0; j < nnodes; j++) + for (j = 0; j < nnodes; j++) { #ifdef NEW_EQS - (*A)(kk, cshift + eqs_number[j]) += \ - (*StiffMatrix)(i,j); + (*A)(kk, cshift + eqs_number[j]) += (*StiffMatrix)(i, j); #else - MXInc(kk, cshift + eqs_number[j], \ - (*StiffMatrix)(i,j)); + MXInc(kk, cshift + eqs_number[j], (*StiffMatrix)(i, j)); #endif } } } - /*if(pcs->matrix_file) - { - (*pcs->matrix_file) << "Stiffness: " <<'\n'; - StiffMatrix->Write(*pcs->matrix_file); - (*pcs->matrix_file) <<'\n'; - }*/ + /*if(pcs->matrix_file) + { + (*pcs->matrix_file) << "Stiffness: " <<'\n'; + StiffMatrix->Write(*pcs->matrix_file); + (*pcs->matrix_file) <<'\n'; + }*/ } #endif /************************************************************************** @@ -8105,8 +7958,8 @@ void CFiniteElementStd::CalcFEM_FCT() { const double dt_inverse = 1.0 / dt; #if defined(NEW_EQS) - CSparseMatrix* A = NULL; //WW - if(m_dom) + CSparseMatrix* A = NULL; // WW + if (m_dom) A = m_dom->eqs->A; else A = pcs->eqs_new->A; @@ -8119,13 +7972,13 @@ void CFiniteElementStd::CalcFEM_FCT() (*FCT_MassL) = 0.0; for (int i = 0; i < nnodes; i++) for (int j = 0; j < nnodes; j++) - (*FCT_MassL)(i) += (*Mass)(i,j); + (*FCT_MassL)(i) += (*Mass)(i, j); // add into a global diagonal vector - Math_Group::Vec *ML = this->pcs->Gl_ML; - for(int i = 0; i < nnodes; i++) + Math_Group::Vec* ML = this->pcs->Gl_ML; + for (int i = 0; i < nnodes; i++) { #ifdef USE_PETSC - long node_i_id = MeshElement->GetNode(i)->GetEquationIndex(); + long node_i_id = MeshElement->GetNode(i)->GetEquationIndex(); #else long node_i_id = this->MeshElement->nodes_index[i]; #endif @@ -8134,20 +7987,21 @@ void CFiniteElementStd::CalcFEM_FCT() //---------------------------------------------------------------------- // Initialize FCT flux with consistent mass matrix: f_ij = m_ij //---------------------------------------------------------------------- - Math_Group::SparseMatrixDOK *FCT_Flux = this->pcs->FCT_AFlux; + Math_Group::SparseMatrixDOK* FCT_Flux = this->pcs->FCT_AFlux; for (int i = 0; i < nnodes; i++) { long node_i_id = this->MeshElement->nodes_index[i]; // for (j=i; jMeshElement->nodes_index[j]; - double v = (*this->Mass)(i,j); + double v = (*this->Mass)(i, j); #ifdef USE_PETSC - if (v==.0) v = (*this->Mass)(j,i); //look for inner nodes + if (v == .0) + v = (*this->Mass)(j, i); // look for inner nodes #endif - (*FCT_Flux)(node_i_id,node_j_id) += v; - (*FCT_Flux)(node_j_id,node_i_id) += v; + (*FCT_Flux)(node_i_id, node_j_id) += v; + (*FCT_Flux)(node_j_id, node_i_id) += v; } } @@ -8155,78 +8009,79 @@ void CFiniteElementStd::CalcFEM_FCT() // calculate transport operator K //---------------------------------------------------------------------- // local K - *AuxMatrix = *Laplace; + *AuxMatrix = *Laplace; *AuxMatrix += *Advection; *AuxMatrix += *Storage; #ifdef USE_PETSC // store K (global) - for (int i = 0; i < nnodes; i++) { - long glob_i = MeshElement->GetNode(i)->GetEquationIndex(); - for (int j = 0; j < nnodes; j++) { - long glob_j = MeshElement->GetNode(j)->GetEquationIndex(); - (*this->pcs->FCT_K)(glob_i, glob_j) += (*AuxMatrix)(i,j); + for (int i = 0; i < nnodes; i++) + { + long glob_i = MeshElement->GetNode(i)->GetEquationIndex(); + for (int j = 0; j < nnodes; j++) + { + long glob_j = MeshElement->GetNode(j)->GetEquationIndex(); + (*this->pcs->FCT_K)(glob_i, glob_j) += (*AuxMatrix)(i, j); } } #else // Add K matrix to a global coefficient matrix - for(int i = 0; i < nnodes; i++) + for (int i = 0; i < nnodes; i++) { - for(int j = 0; j < nnodes; j++) + for (int j = 0; j < nnodes; j++) { #ifdef NEW_EQS - (*A)(NodeShift[problem_dimension_dm] + eqs_number[i], - NodeShift[problem_dimension_dm] + eqs_number[j]) += (*AuxMatrix)(i,j); + (*A)(NodeShift[problem_dimension_dm] + eqs_number[i], NodeShift[problem_dimension_dm] + eqs_number[j]) + += (*AuxMatrix)(i, j); #else - MXInc(NodeShift[problem_dimension_dm] + eqs_number[i], \ - NodeShift[problem_dimension_dm] + eqs_number[j], \ - (*AuxMatrix)(i,j)); + MXInc(NodeShift[problem_dimension_dm] + eqs_number[i], NodeShift[problem_dimension_dm] + eqs_number[j], + (*AuxMatrix)(i, j)); #endif } } #endif - //---------------------------------------------------------------------- - // Setup local coefficient matrix and RHS vector - //---------------------------------------------------------------------- +//---------------------------------------------------------------------- +// Setup local coefficient matrix and RHS vector +//---------------------------------------------------------------------- #ifdef USE_PETSC // A=1/dt*ML + theta*K const double theta = pcs->m_num->ls_theta; - *AuxMatrix *= theta; - *StiffMatrix = *FCT_MassL; + *AuxMatrix *= theta; + *StiffMatrix = *FCT_MassL; *StiffMatrix *= dt_inverse; *StiffMatrix += *AuxMatrix; // StiffMatrix is later added into a global matrix in add2GlobalMatrixII() // rhs=(1/dt*ML-(1-theta)*K)u^n *AuxMatrix1 = *FCT_MassL; *AuxMatrix1 *= dt_inverse; - *AuxMatrix = *Laplace; - *AuxMatrix += *Advection; - *AuxMatrix += *Storage; - *AuxMatrix *= -(1.0 - theta); - *AuxMatrix1 += *AuxMatrix; + *AuxMatrix = *Laplace; + *AuxMatrix += *Advection; + *AuxMatrix += *Storage; + *AuxMatrix *= -(1.0 - theta); + *AuxMatrix1 += *AuxMatrix; for (int i = 0; i < nnodes; i++) { - NodalVal1[i] = pcs->GetNodeValue(nodes[i],idx0); + NodalVal1[i] = pcs->GetNodeValue(nodes[i], idx0); NodalVal[i] = 0.0; } AuxMatrix1->multi(NodalVal1, NodalVal); for (int i = 0; i < nnodes; i++) - (*RHS)[i + LocalShift] += NodalVal[i]; // RHS is later added into a global RHS in add2GlobalMatrixII() + (*RHS)[i + LocalShift] += NodalVal[i]; // RHS is later added into a global RHS in add2GlobalMatrixII() #else // assemble part of RHS: b_i += 1/dt * ml_i * u_i^n - double fac_mass = dt_inverse; //*geo_fac; + double fac_mass = dt_inverse; //*geo_fac; for (int i = 0; i < nnodes; i++) - NodalVal[i] = fac_mass * (*FCT_MassL)(i) * pcs->GetNodeValue(nodes[i],idx0); + NodalVal[i] = fac_mass * (*FCT_MassL)(i)*pcs->GetNodeValue(nodes[i], idx0); for (int i = 0; i < nnodes; i++) { eqs_rhs[NodeShift[problem_dimension_dm] + eqs_number[i]] += NodalVal[i]; - (*RHS)[i + LocalShift] += NodalVal[i]; + (*RHS)[i + LocalShift] += NodalVal[i]; } #endif } -//SB4200 +// SB4200 /************************************************************************** FEMLib-Method: Task: Assemble local matrices of parabolic equation to the global system @@ -8239,12 +8094,12 @@ void CFiniteElementStd::CalcFEM_FCT() void CFiniteElementStd::AssembleMixedHyperbolicParabolicEquation() { double pcs_time_step, dt_inverse; - ElementMatrix* EleMat = NULL; //SB-3 + ElementMatrix* EleMat = NULL; // SB-3 // NUM - double theta = pcs->m_num->ls_theta; //OK + double theta = pcs->m_num->ls_theta; // OK #if defined(NEW_EQS) - CSparseMatrix* A = NULL; //WW - if(m_dom) + CSparseMatrix* A = NULL; // WW + if (m_dom) A = m_dom->eqs->A; else A = pcs->eqs_new->A; @@ -8252,7 +8107,7 @@ void CFiniteElementStd::AssembleMixedHyperbolicParabolicEquation() // JT2012: Get the time step of this process! Now dt can be independently controlled pcs_time_step = pcs->Tim->time_step_length; - dt_inverse = 1.0/pcs_time_step; // (also, no need to check minimum. It is handeled in Tim. + dt_inverse = 1.0 / pcs_time_step; // (also, no need to check minimum. It is handeled in Tim. // //---------------------------------------------------------------------- unit[0] = unit[1] = unit[2] = 0.0; @@ -8260,8 +8115,8 @@ void CFiniteElementStd::AssembleMixedHyperbolicParabolicEquation() // double non_linear_function_iter = 1.0; //OK MediaProp->NonlinearFlowFunction(Index,unit,theta); // double non_linear_function_t0 = 1.0; //OK MediaProp->NonlinearFlowFunction(Index,unit,0.0); double fac_mass, fac_laplace, fac_advection, fac_storage, fac_content; - //if(((aktueller_zeitschritt==1)||(pcs->tim_type_name.compare("TRANSIENT")==0))){ //SB-3 - //SB-3 + // if(((aktueller_zeitschritt==1)||(pcs->tim_type_name.compare("TRANSIENT")==0))){ //SB-3 + // SB-3 if (aktueller_zeitschritt == 1 || pcs->Memory_Type == 0) { // Initialize. @@ -8276,10 +8131,10 @@ void CFiniteElementStd::AssembleMixedHyperbolicParabolicEquation() //---------------------------------------------------------------------- // Calculate matrices // Mass matrix.......................................................... - //NW - if(this->pcs->tim_type != TimType::STEADY) + // NW + if (this->pcs->tim_type != TimType::STEADY) { - if(pcs->m_num->ele_mass_lumping) + if (pcs->m_num->ele_mass_lumping) CalcLumpedMass(); else CalcMass(); @@ -8294,7 +8149,7 @@ void CFiniteElementStd::AssembleMixedHyperbolicParabolicEquation() CalcContent(); // Store matrices to memory for steady state element matrices //SB-3 - if(pcs->Memory_Type > 0) + if (pcs->Memory_Type > 0) { EleMat = pcs->Ele_Matrices[Index]; EleMat->SetMass_notsym(Mass); @@ -8303,11 +8158,12 @@ void CFiniteElementStd::AssembleMixedHyperbolicParabolicEquation() EleMat->SetStorage(Storage); EleMat->SetContent(Content); } - } //SB-3 + } // SB-3 else { - if(Index < 1) - cout << " Skipping calculation of element matrices " << "\n"; + if (Index < 1) + cout << " Skipping calculation of element matrices " + << "\n"; // Get Element Matrices EleMat = pcs->Ele_Matrices[Index]; Mass = EleMat->GetMass_notsym(); @@ -8315,60 +8171,58 @@ void CFiniteElementStd::AssembleMixedHyperbolicParabolicEquation() Advection = EleMat->GetAdvection(); Storage = EleMat->GetStorage(); Content = EleMat->GetContent(); - } //pcs->tim_type //SB-3 + } // pcs->tim_type //SB-3 //====================================================================== // Assemble global matrix //---------------------------------------------------------------------- // Assemble local left matrix: // [C]/dt + theta [K] non_linear_function for static problems - fac_mass = dt_inverse; //*geo_fac; - fac_laplace = theta; //* non_linear_function_iter; //*geo_fac; + fac_mass = dt_inverse; //*geo_fac; + fac_laplace = theta; //* non_linear_function_iter; //*geo_fac; fac_advection = theta; fac_storage = theta; fac_content = theta * dt_inverse; - if (this->pcs->femFCTmode) //NW + if (this->pcs->femFCTmode) // NW this->CalcFEM_FCT(); else { - //Mass matrix - *StiffMatrix = *Mass; + // Mass matrix + *StiffMatrix = *Mass; (*StiffMatrix) *= fac_mass; // Laplace matrix - *AuxMatrix = *Laplace; - (*AuxMatrix) *= fac_laplace; - *StiffMatrix += *AuxMatrix; + *AuxMatrix = *Laplace; + (*AuxMatrix) *= fac_laplace; + *StiffMatrix += *AuxMatrix; // Advection matrix - *AuxMatrix = *Advection; - (*AuxMatrix) *= fac_advection; - *StiffMatrix += *AuxMatrix; + *AuxMatrix = *Advection; + (*AuxMatrix) *= fac_advection; + *StiffMatrix += *AuxMatrix; // Storage matrix - *AuxMatrix = *Storage; - (*AuxMatrix) *= fac_storage; - *StiffMatrix += *AuxMatrix; - // Content matrix - //*AuxMatrix = *Content; //SB, BG; Korrektur Stofftransport bei Mehrphasenströmung - //(*AuxMatrix) *= fac_content; - //*StiffMatrix += *AuxMatrix; // SB, BG + *AuxMatrix = *Storage; + (*AuxMatrix) *= fac_storage; + *StiffMatrix += *AuxMatrix; +// Content matrix +//*AuxMatrix = *Content; //SB, BG; Korrektur Stofftransport bei Mehrphasenströmung +//(*AuxMatrix) *= fac_content; +//*StiffMatrix += *AuxMatrix; // SB, BG #if !defined(USE_PETSC) // && !defined(other parallel libs)//03~04.3012. WW //---------------------------------------------------------------------- // Add local matrix to global matrix - for(int i = 0; i < nnodes; i++) + for (int i = 0; i < nnodes; i++) { - for(int j = 0; j < nnodes; j++) + for (int j = 0; j < nnodes; j++) { #ifdef NEW_EQS - //WW - (*A)(NodeShift[problem_dimension_dm] + eqs_number[i], - NodeShift[problem_dimension_dm] + - eqs_number[j]) += (*StiffMatrix)(i,j); + // WW + (*A)(NodeShift[problem_dimension_dm] + eqs_number[i], NodeShift[problem_dimension_dm] + eqs_number[j]) + += (*StiffMatrix)(i, j); #else - MXInc(NodeShift[problem_dimension_dm] + eqs_number[i], \ - NodeShift[problem_dimension_dm] + eqs_number[j], \ - (*StiffMatrix)(i,j)); + MXInc(NodeShift[problem_dimension_dm] + eqs_number[i], NodeShift[problem_dimension_dm] + eqs_number[j], + (*StiffMatrix)(i, j)); #endif } } @@ -8378,49 +8232,49 @@ void CFiniteElementStd::AssembleMixedHyperbolicParabolicEquation() // ( [C]/dt - (1.0-theta) [K] non_linear_function ) u0 for static problems // ( [C] + beta1*dt [K] ) dp for dynamic problems - fac_mass = dt_inverse; //*geo_fac; + fac_mass = dt_inverse; //*geo_fac; fac_laplace = -(1.0 - theta); // * non_linear_function_t0; //*geo_fac; fac_advection = -(1.0 - theta); fac_storage = -(1.0 - theta); //*lambda fac_content = -(1.0 - theta) * dt_inverse; // Mass - Storage - *AuxMatrix1 = *Mass; + *AuxMatrix1 = *Mass; (*AuxMatrix1) *= fac_mass; - //Laplace - Diffusion - *AuxMatrix = *Laplace; - (*AuxMatrix) *= fac_laplace; - *AuxMatrix1 += *AuxMatrix; + // Laplace - Diffusion + *AuxMatrix = *Laplace; + (*AuxMatrix) *= fac_laplace; + *AuxMatrix1 += *AuxMatrix; // Advection - *AuxMatrix = *Advection; - (*AuxMatrix) *= fac_advection; - *AuxMatrix1 += *AuxMatrix; + *AuxMatrix = *Advection; + (*AuxMatrix) *= fac_advection; + *AuxMatrix1 += *AuxMatrix; // Storage - *AuxMatrix = *Storage; - (*AuxMatrix) *= fac_storage; - *AuxMatrix1 += *AuxMatrix; + *AuxMatrix = *Storage; + (*AuxMatrix) *= fac_storage; + *AuxMatrix1 += *AuxMatrix; // Content - *AuxMatrix = *Content; - (*AuxMatrix) *= fac_content; - *AuxMatrix1 += *AuxMatrix; + *AuxMatrix = *Content; + (*AuxMatrix) *= fac_content; + *AuxMatrix1 += *AuxMatrix; for (int i = 0; i < nnodes; i++) { - NodalVal1[i] = pcs->GetNodeValue(nodes[i],idx0); + NodalVal1[i] = pcs->GetNodeValue(nodes[i], idx0); NodalVal[i] = 0.0; } - AuxMatrix1->multi(NodalVal1, NodalVal); //AuxMatrix1 times vector NodalVal1 = NodalVal + AuxMatrix1->multi(NodalVal1, NodalVal); // AuxMatrix1 times vector NodalVal1 = NodalVal //---------------------------------------------------------------------- for (int i = 0; i < nnodes; i++) { #if !defined(USE_PETSC) // && !defined(other parallel libs)//03~04.3012. WW eqs_rhs[NodeShift[problem_dimension_dm] + eqs_number[i]] += NodalVal[i]; #endif - (*RHS)[i + LocalShift] += NodalVal[i]; + (*RHS)[i + LocalShift] += NodalVal[i]; } - } //end: femFCTmode + } // end: femFCTmode //---------------------------------------------------------------------- - //Debug output + // Debug output /* if(Index < 10){ cout << " Element Number " << Index << "\n"; @@ -8469,12 +8323,12 @@ void CFiniteElementStd::AssembleParabolicEquationNewton() double** amat; int iups[16]; - jacobian = (double**) Malloc(nnodes * sizeof(double)); - amat = (double**) Malloc(nnodes * sizeof(double)); + jacobian = (double**)Malloc(nnodes * sizeof(double)); + amat = (double**)Malloc(nnodes * sizeof(double)); for (int i = 0; i < nnodes; i++) { - jacobian[i] = (double*) Malloc(nnodes * sizeof(double)); - amat[i] = (double*) Malloc(nnodes * sizeof(double)); + jacobian[i] = (double*)Malloc(nnodes * sizeof(double)); + amat[i] = (double*)Malloc(nnodes * sizeof(double)); } //////////////////////////// initialize with 0 @@ -8491,10 +8345,10 @@ void CFiniteElementStd::AssembleParabolicEquationNewton() /////////////////////////// fetch head (depth) nidx = pcs->GetNodeValueIndex("HEAD"); - for(int i = 0; i < nnodes; i++) + for (int i = 0; i < nnodes; i++) { - haa[i] = pcs->GetNodeValue(nodes[i],nidx + 1); - haaOld[i] = pcs->GetNodeValue(nodes[i],nidx); + haa[i] = pcs->GetNodeValue(nodes[i], nidx + 1); + haaOld[i] = pcs->GetNodeValue(nodes[i], nidx); } ///////////////////////////// assemble upwinded coefficients CalcOverlandCoefficients(haa, &axx, &ayy, &ast); @@ -8502,41 +8356,32 @@ void CFiniteElementStd::AssembleParabolicEquationNewton() CalcOverlandNLTERMS(haa, haaOld, swval, swold); // compute swval, swold, introduces surface structure in storage term CalcOverlandCKWR(haa, ckwr, iups); - //compute ckwr, iups, upstream weighting, hydraulic radius for channel + // compute ckwr, iups, upstream weighting, hydraulic radius for channel CalcOverlandUpwindedCoefficients(amat, ckwr, axx, ayy); - //Form elemental matrix + // Form elemental matrix /////////////////////////// form residual vector and jacobi matrix CalcOverlandResidual(haa, swval, swold, ast, residual, amat); - AssembleParabolicEquationNewtonJacobian(jacobian, - haa, - haaOld, - axx, - ayy, - amat, - ast, - swold, - residual, - iups); + AssembleParabolicEquationNewtonJacobian(jacobian, haa, haaOld, axx, ayy, amat, ast, swold, residual, iups); /////////////////////////// store - for(int i = 0; i < nnodes; i++) + for (int i = 0; i < nnodes; i++) { -#if defined(NEW_EQS) //WW +#if defined(NEW_EQS) // WW pcs->eqs_new->b[NodeShift[problem_dimension_dm] + eqs_number[i]] -= residual[i]; #else pcs->eqs->b[NodeShift[problem_dimension_dm] + eqs_number[i]] -= residual[i]; #endif - for(int j = 0; j < nnodes; j++) -#if defined(NEW_EQS) //WW + for (int j = 0; j < nnodes; j++) +#if defined(NEW_EQS) // WW (*pcs->eqs_new->A)(NodeShift[problem_dimension_dm] + eqs_number[i], NodeShift[problem_dimension_dm] + eqs_number[j]) - += jacobian[i][j]; //WW + += jacobian[i][j]; // WW #else - MXInc( NodeShift[problem_dimension_dm] + eqs_number[i], - NodeShift[problem_dimension_dm] + eqs_number[j], jacobian[i][j] ); + MXInc(NodeShift[problem_dimension_dm] + eqs_number[i], NodeShift[problem_dimension_dm] + eqs_number[j], + jacobian[i][j]); #endif } - for(int i = 0; i < nnodes; i++) + for (int i = 0; i < nnodes; i++) { free(jacobian[i]); free(amat[i]); @@ -8567,7 +8412,8 @@ void CFiniteElementStd::AssembleParabolicEquationNewtonJacobian(double** jacob, // double** jacob; double hEps[4], hKeep[4], swval_eps[4]; double sumjac, stor_eps, akrw, remember; - double epsilon = 1.e-7; // be carefull, like in primary variable dependent source terms (critical depth, normal depth) + double epsilon + = 1.e-7; // be carefull, like in primary variable dependent source terms (critical depth, normal depth) /* jacob = (double**) Malloc(nnodes * sizeof(double)); for (int i = 0; i < nnodes; i++) @@ -8576,7 +8422,7 @@ void CFiniteElementStd::AssembleParabolicEquationNewtonJacobian(double** jacob, for (int j = 0; j < nnodes; j++) jacob[i][j]= 0.0; */ - for(int i = 0; i < nnodes; i++) + for (int i = 0; i < nnodes; i++) { hEps[i] = haa[i] + epsilon; hKeep[i] = haa[i]; @@ -8585,37 +8431,29 @@ void CFiniteElementStd::AssembleParabolicEquationNewtonJacobian(double** jacob, CalcOverlandNLTERMS(hEps, hOld, swval_eps, swold); // compute swval_eps, swold, introduces surface structure in storage term - for(int i = 0; i < nnodes; i++) // Form jacobian ! + for (int i = 0; i < nnodes; i++) // Form jacobian ! { remember = haa[i]; haa[i] = hEps[i]; sumjac = 0.0; - for(int j = 0; j < nnodes; j++) - if(i != j) // nondiagonal + for (int j = 0; j < nnodes; j++) + if (i != j) // nondiagonal { CalcOverlandCKWRatNodes(i, j, haa, &akrw, iups); - //compute ckwr, iups, upstream weighting, hydraulic radius for channel - jacob[j][i] = CalcOverlandJacobiNodes(i, - j, - haa, - hKeep, - akrw, - axx, - ayy, - amat, - &sumjac) / epsilon; + // compute ckwr, iups, upstream weighting, hydraulic radius for channel + jacob[j][i] = CalcOverlandJacobiNodes(i, j, haa, hKeep, akrw, axx, ayy, amat, &sumjac) / epsilon; // if(MediaProp->channel ==1) // sumjac += swval_eps[i] * ast * (Haa[i] - Hold[i]); - } //end if (i!=j) - //end j + } // end if (i!=j) + // end j - //Compute diagonal for row i, Lump the storage term + // Compute diagonal for row i, Lump the storage term stor_eps = ast * (swval_eps[i] - swold[i]); sumjac = sumjac + stor_eps; jacob[i][i] = (sumjac - residual[i]) / epsilon; haa[i] = remember; - } // end i + } // end i // return jacob; } @@ -8636,28 +8474,28 @@ void CFiniteElementStd::AssembleParabolicEquationNewtonJacobian(double** jacob, void CFiniteElementStd::Assemble_strainCPL(const int phase) { int i, j; - double* u_n = NULL; // Dynamic + double* u_n = NULL; // Dynamic double fac; int Residual = -1; fac = 1.0 / dt; - if(dm_pcs->type != 41) - //if(D_Flag != 41) + if (dm_pcs->type != 41) + // if(D_Flag != 41) Residual = 0; - else // Mono - if(pcs_deformation > 100) // Pls + else // Mono + if (pcs_deformation > 100) // Pls Residual = 1; - if(dynamic) + if (dynamic) { Residual = 2; fac = pcs->m_num->GetDynamicDamping_beta1() * dt; u_n = dm_pcs->GetAuxArray(); } - if(MediaProp->storage_model == 7) //RW/WW + if (MediaProp->storage_model == 7) // RW/WW fac *= MediaProp->storage_model_values[0]; else - fac *= fabs(SolidProp->biot_const);//WX:11.2012. biot coeff is needed, in some case biot is defined negative + fac *= fabs(SolidProp->biot_const); // WX:11.2012. biot coeff is needed, in some case biot is defined negative // for (i = nnodes; i < nnodesHQ; i++) @@ -8665,54 +8503,47 @@ void CFiniteElementStd::Assemble_strainCPL(const int phase) (*StrainCoupling) = 0.0; CalcStrainCoupling(phase); // if(D_Flag != 41&&aktueller_zeitschritt>1) - if(Residual >= 0) - { // Incorparate this after the first time step - if(Residual == 0) // Partitioned + if (Residual >= 0) + { // Incorparate this after the first time step + if (Residual == 0) // Partitioned for (i = 0; i < nnodesHQ; i++) { - NodalVal2[i] = -fac * - (dm_pcs->GetNodeValue(nodes[i], - Idx_dm1[0]) - - dm_pcs->GetNodeValue(nodes[i],Idx_dm0[0])); - NodalVal3[i] = -fac * - (dm_pcs->GetNodeValue(nodes[i], - Idx_dm1[1]) - - dm_pcs->GetNodeValue(nodes[i],Idx_dm0[1])); - if(dim == 3) // 3D. - NodalVal4[i] = -fac * - (dm_pcs->GetNodeValue(nodes[i],Idx_dm1[2]) - - dm_pcs->GetNodeValue(nodes[i], - Idx_dm0[2])); - } - else if(Residual == 1) //Mono + NodalVal2[i] + = -fac * (dm_pcs->GetNodeValue(nodes[i], Idx_dm1[0]) - dm_pcs->GetNodeValue(nodes[i], Idx_dm0[0])); + NodalVal3[i] + = -fac * (dm_pcs->GetNodeValue(nodes[i], Idx_dm1[1]) - dm_pcs->GetNodeValue(nodes[i], Idx_dm0[1])); + if (dim == 3) // 3D. + NodalVal4[i] = -fac * (dm_pcs->GetNodeValue(nodes[i], Idx_dm1[2]) + - dm_pcs->GetNodeValue(nodes[i], Idx_dm0[2])); + } + else if (Residual == 1) // Mono // du is stored in u_0 for (i = 0; i < nnodesHQ; i++) { - NodalVal2[i] = -fac* pcs->GetNodeValue(nodes[i],Idx_dm0[0]); - NodalVal3[i] = -fac* pcs->GetNodeValue(nodes[i],Idx_dm0[1]); - if(dim == 3) // 3D. - NodalVal4[i] = -fac* pcs->GetNodeValue(nodes[i],Idx_dm0[2]); + NodalVal2[i] = -fac * pcs->GetNodeValue(nodes[i], Idx_dm0[0]); + NodalVal3[i] = -fac * pcs->GetNodeValue(nodes[i], Idx_dm0[1]); + if (dim == 3) // 3D. + NodalVal4[i] = -fac * pcs->GetNodeValue(nodes[i], Idx_dm0[2]); } - else if(Residual == 2) //Mono dynamic + else if (Residual == 2) // Mono dynamic // da is stored in a_0 // v_{n+1} = v_{n}+a_n*dt+beta1*dt*da // a_n is in dm_pcs->ARRAY for (i = 0; i < nnodesHQ; i++) { - NodalVal2[i] = -(pcs->GetNodeValue(nodes[i],idx_vel_disp[0]) - + fac * pcs->GetNodeValue(nodes[i],Idx_dm0[0]) - + u_n[nodes[i]] * dt); - NodalVal3[i] = -(pcs->GetNodeValue(nodes[i],idx_vel_disp[1]) - + fac * pcs->GetNodeValue(nodes[i],Idx_dm0[1]) - + u_n[nodes[i] + NodeShift[1]] * dt); - if(dim == 3) // 3D. - NodalVal4[i] = -(pcs->GetNodeValue(nodes[i],idx_vel_disp[2]) - + fac * - pcs->GetNodeValue(nodes[i],Idx_dm0[2]) - + u_n[nodes[i] + NodeShift[2]] * dt); + NodalVal2[i] + = -(pcs->GetNodeValue(nodes[i], idx_vel_disp[0]) + fac * pcs->GetNodeValue(nodes[i], Idx_dm0[0]) + + u_n[nodes[i]] * dt); + NodalVal3[i] + = -(pcs->GetNodeValue(nodes[i], idx_vel_disp[1]) + fac * pcs->GetNodeValue(nodes[i], Idx_dm0[1]) + + u_n[nodes[i] + NodeShift[1]] * dt); + if (dim == 3) // 3D. + NodalVal4[i] + = -(pcs->GetNodeValue(nodes[i], idx_vel_disp[2]) + fac * pcs->GetNodeValue(nodes[i], Idx_dm0[2]) + + u_n[nodes[i] + NodeShift[2]] * dt); } for (i = 0; i < nnodes; i++) @@ -8720,12 +8551,10 @@ void CFiniteElementStd::Assemble_strainCPL(const int phase) NodalVal[i] = 0.0; for (j = 0; j < nnodesHQ; j++) { - NodalVal[i] += (*StrainCoupling)(i,j) * NodalVal2[j]; - NodalVal[i] += (*StrainCoupling)(i,j + nnodesHQ) * NodalVal3[j]; - if(dim == 3) // 3D. - NodalVal[i] += - (*StrainCoupling)(i,j + 2 * - nnodesHQ) * NodalVal4[j]; + NodalVal[i] += (*StrainCoupling)(i, j) * NodalVal2[j]; + NodalVal[i] += (*StrainCoupling)(i, j + nnodesHQ) * NodalVal3[j]; + if (dim == 3) // 3D. + NodalVal[i] += (*StrainCoupling)(i, j + 2 * nnodesHQ) * NodalVal4[j]; } } // Add RHS @@ -8733,15 +8562,14 @@ void CFiniteElementStd::Assemble_strainCPL(const int phase) { #if !defined(USE_PETSC) // && !defined(other parallel libs)//03~04.3012. WW int shift_index = problem_dimension_dm + phase; - eqs_rhs[NodeShift[shift_index] + eqs_number[i]] - += NodalVal[i]; + eqs_rhs[NodeShift[shift_index] + eqs_number[i]] += NodalVal[i]; #endif - (*RHS)[i + LocalShift] += NodalVal[i]; + (*RHS)[i + LocalShift] += NodalVal[i]; } } // Monolithic scheme. // if(D_Flag == 41) - if(dm_pcs->type == 41) // 06.2011. WW + if (dm_pcs->type == 41) // 06.2011. WW Assemble_strainCPL_Matrix(fac, phase); } //************************************************************************** @@ -8752,45 +8580,43 @@ void CFiniteElementStd::Assemble_strainCPL(const int phase) */ //************************************************************************** #if defined(USE_PETSC) // && !defined(other parallel libs)//03~04.3012. WW -void CFiniteElementStd::Assemble_strainCPL_Matrix(const double, const int) {} +void CFiniteElementStd::Assemble_strainCPL_Matrix(const double, const int) +{ +} #else void CFiniteElementStd::Assemble_strainCPL_Matrix(const double fac, const int phase) { - //TODO + // TODO int i, j; int shift_index; #if defined(NEW_EQS) CSparseMatrix* A = NULL; - if(m_dom) + if (m_dom) A = m_dom->eqsH->A; else A = pcs->eqs_new->A; #endif // if Richard, StrainCoupling should be multiplied with -1. shift_index = problem_dimension_dm + phase; - for(i = 0; i < nnodes; i++) + for (i = 0; i < nnodes; i++) { - for(j = 0; j < nnodesHQ; j++) + for (j = 0; j < nnodesHQ; j++) { #ifdef NEW_EQS - (*A)(NodeShift[shift_index] + eqs_number[i], - eqs_number[j] + NodeShift[0]) += (*StrainCoupling)(i,j) * fac; - (*A)(NodeShift[shift_index] + eqs_number[i], - eqs_number[j] + - NodeShift[1]) += (*StrainCoupling)(i,j + nnodesHQ) * fac; - if(problem_dimension_dm == 3) - (*A)(NodeShift[shift_index] + eqs_number[i], - eqs_number[j] + - NodeShift[2]) += (*StrainCoupling)(i,j + 2 * nnodesHQ) * fac; + (*A)(NodeShift[shift_index] + eqs_number[i], eqs_number[j] + NodeShift[0]) += (*StrainCoupling)(i, j) * fac; + (*A)(NodeShift[shift_index] + eqs_number[i], eqs_number[j] + NodeShift[1]) + += (*StrainCoupling)(i, j + nnodesHQ) * fac; + if (problem_dimension_dm == 3) + (*A)(NodeShift[shift_index] + eqs_number[i], eqs_number[j] + NodeShift[2]) + += (*StrainCoupling)(i, j + 2 * nnodesHQ) * fac; #else - MXInc(NodeShift[shift_index] + eqs_number[i], - eqs_number[j] + NodeShift[0],(*StrainCoupling)(i,j) * fac); - MXInc(NodeShift[shift_index] + eqs_number[i], - eqs_number[j] + NodeShift[1], (*StrainCoupling)(i,j + nnodesHQ) * fac); - if(problem_dimension_dm == 3) + MXInc(NodeShift[shift_index] + eqs_number[i], eqs_number[j] + NodeShift[0], (*StrainCoupling)(i, j) * fac); + MXInc(NodeShift[shift_index] + eqs_number[i], eqs_number[j] + NodeShift[1], + (*StrainCoupling)(i, j + nnodesHQ) * fac); + if (problem_dimension_dm == 3) MXInc(NodeShift[shift_index] + eqs_number[i], eqs_number[j] + NodeShift[2], - (*StrainCoupling)(i,j + 2 * nnodesHQ) * fac); + (*StrainCoupling)(i, j + 2 * nnodesHQ) * fac); #endif } } @@ -8809,14 +8635,14 @@ void CFiniteElementStd::AssembleMassMatrix(int option) // Mass matrix.......................................................... // ---- Gauss integral int gp; - int gp_r = 0,gp_s = 0,gp_t = 0; - double fkt; //WW ,mat_fac; - // Material - //WW mat_fac = 1.0; + int gp_r = 0, gp_s = 0, gp_t = 0; + double fkt; // WW ,mat_fac; +// Material +// WW mat_fac = 1.0; #if defined(NEW_EQS) - CSparseMatrix* A = NULL; //PCH - if(m_dom) + CSparseMatrix* A = NULL; // PCH + if (m_dom) A = m_dom->eqs->A; else A = pcs->eqs_new->A; @@ -8833,47 +8659,45 @@ void CFiniteElementStd::AssembleMassMatrix(int option) fkt = GetGaussData(gp, gp_r, gp_s, gp_t); // Compute geometry - ComputeShapefct(1); // Linear interpolation function + ComputeShapefct(1); // Linear interpolation function - if(option == 0) // The consistent method + if (option == 0) // The consistent method // Calculate mass matrix for (int i = 0; i < nnodes; i++) for (int j = 0; j < nnodes; j++) // if(j>i) continue; - (*Mass)(i,j) += fkt * shapefct[i] * shapefct[j]; + (*Mass)(i, j) += fkt * shapefct[i] * shapefct[j]; - else if(option == 1) // The lumped method + else if (option == 1) // The lumped method // Calculate mass matrix for (int i = 0; i < nnodes; i++) for (int j = 0; j < nnodes; j++) - (*Mass)(i,i) += fkt * shapefct[i] * shapefct[j]; + (*Mass)(i, i) += fkt * shapefct[i] * shapefct[j]; } - //---------------------------------------------------------------------- - // Add local matrix to global matrix +//---------------------------------------------------------------------- +// Add local matrix to global matrix #if !defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - if(PcsType == EPT_MULTIPHASE_FLOW || PcsType == EPT_PSGLOBAL) // For DOF>1: 03.03.2009 PCH + if (PcsType == EPT_MULTIPHASE_FLOW || PcsType == EPT_PSGLOBAL) // For DOF>1: 03.03.2009 PCH { - for(int ii = 0; ii < pcs->dof; ii++) + for (int ii = 0; ii < pcs->dof; ii++) { long i_sh = NodeShift[ii]; long ii_sh = ii * nnodes; - for(int jj = 0; jj < pcs->dof; jj++) + for (int jj = 0; jj < pcs->dof; jj++) { long j_sh = NodeShift[jj]; long jj_sh = jj * nnodes; - for(int i = 0; i < nnodes; i++) + for (int i = 0; i < nnodes; i++) { - for(int j = 0; j < nnodes; j++) + for (int j = 0; j < nnodes; j++) { #if defined(NEW_EQS) - (*A)(i_sh + eqs_number[i], j_sh + eqs_number[j]) += \ - (*Mass)(i + ii_sh,j + jj_sh); + (*A)(i_sh + eqs_number[i], j_sh + eqs_number[j]) += (*Mass)(i + ii_sh, j + jj_sh); #else - MXInc(i_sh + eqs_number[i], j_sh + eqs_number[j], \ - (*Mass)(i + ii_sh,j + jj_sh)); + MXInc(i_sh + eqs_number[i], j_sh + eqs_number[j], (*Mass)(i + ii_sh, j + jj_sh)); #endif } } @@ -8883,18 +8707,16 @@ void CFiniteElementStd::AssembleMassMatrix(int option) else { int cshift = 0; - //WW 05.01.07 + // WW 05.01.07 cshift += NodeShift[problem_dimension_dm]; - for(int i = 0; i < nnodes; i++) + for (int i = 0; i < nnodes; i++) { - for(int j = 0; j < nnodes; j++) + for (int j = 0; j < nnodes; j++) { #if defined(NEW_EQS) - (*A)(cshift + eqs_number[i], cshift + eqs_number[j]) += \ - (*Mass)(i,j); + (*A)(cshift + eqs_number[i], cshift + eqs_number[j]) += (*Mass)(i, j); #else - MXInc(cshift + eqs_number[i], cshift + eqs_number[j], \ - (*Mass)(i,j)); + MXInc(cshift + eqs_number[i], cshift + eqs_number[j], (*Mass)(i, j)); #endif } } @@ -8911,18 +8733,18 @@ void CFiniteElementStd::AssembleMassMatrix(int option) void CFiniteElementStd::Config() { //---------------------------------------------------------------------- - //OK index = m_dom->elements[e]->global_number; + // OK index = m_dom->elements[e]->global_number; index = Index; //---------------------------------------------------------------------- int nn = nnodes; // ?2WW // ?2WW - if(pcs->type / 10 == 4 || pcs->type == 4) + if (pcs->type / 10 == 4 || pcs->type == 4) nn = nnodesHQ; - //---------------------------------------------------------------------- - // For DDC WW +//---------------------------------------------------------------------- +// For DDC WW #if !defined(USE_PETSC) // && defined(other parallel libs)//03~04.3012. WW - //TODO +// TODO #ifdef NEW_EQS eqs_rhs = pcs->eqs_new->b; #else @@ -8951,25 +8773,24 @@ void CFiniteElementStd::Config() } } - - //i_buff = nn*nn; - //for(i = 0; i < i_buff; i++) - // local_matrix[i] = 0.; - // If deformation related +// i_buff = nn*nn; +// for(i = 0; i < i_buff; i++) +// local_matrix[i] = 0.; +// If deformation related #else // EQS indices - if(m_dom) //WW + if (m_dom) // WW { eqs_rhs = m_dom->eqs->b; - for(int i = 0; i < nn; i++) - eqs_number[i] = element_nodes_dom[i]; //WW - if(pcs->dof > 1) //12.12.2007 WW - for(int i = 0; i < pcs->dof; i++) + for (int i = 0; i < nn; i++) + eqs_number[i] = element_nodes_dom[i]; // WW + if (pcs->dof > 1) // 12.12.2007 WW + for (int i = 0; i < pcs->dof; i++) NodeShift[i] = i * m_dom->nnodes_dom; } - else //OK4111 - for(int i = 0; i < nn; i++) + else // OK4111 + for (int i = 0; i < nn; i++) eqs_number[i] = MeshElement->nodes[i]->GetEquationIndex(); #endif //---------------------------------------------------------------------- @@ -8981,33 +8802,33 @@ void CFiniteElementStd::Config() //---------------------------------------------------------------------- //---------------------------------------------------------------------- // ?2WW - if((D_Flag == 41 && pcs_deformation > 100) || dynamic) + if ((D_Flag == 41 && pcs_deformation > 100) || dynamic) dm_pcs = (process::CRFProcessDeformation*)pcs; //---------------------------------------------------------------------- // Initialize RHS - if(pcs->Memory_Type > 0) - for(std::size_t i = LocalShift; i < RHS->Size(); i++) + if (pcs->Memory_Type > 0) + for (std::size_t i = LocalShift; i < RHS->Size(); i++) (*RHS)[i] = 0.0; else (*RHS) = 0.0; //---------------------------------------------------------------------- // Node value of the previous time step - int idx00 = idx0; //----------WW 05.01.07 + int idx00 = idx0; //----------WW 05.01.07 int idx11 = idx1; - if(pcs->GetContinnumType() == 1) + if (pcs->GetContinnumType() == 1) { idx00 = idxp20; idx11 = idxp21; } - for(int i = 0; i < nnodes; i++) + for (int i = 0; i < nnodes; i++) { - NodalVal0[i] = pcs->GetNodeValue(nodes[i],idx00); - NodalVal1[i] = pcs->GetNodeValue(nodes[i],idx11); - } //----------WW 05.01.07 + NodalVal0[i] = pcs->GetNodeValue(nodes[i], idx00); + NodalVal1[i] = pcs->GetNodeValue(nodes[i], idx11); + } //----------WW 05.01.07 - switch(PcsType) + switch (PcsType) { - case EPT_MULTIPHASE_FLOW: // 25.2.2007 + case EPT_MULTIPHASE_FLOW: // 25.2.2007 for (int i = 0; i < nnodes; i++) { NodalVal_p2[i] = pcs->GetNodeValue(nodes[i], idxp21); @@ -9039,7 +8860,8 @@ void CFiniteElementStd::Config() } break; case EPT_TES: - for (int i = 0; i < nnodes; i++) { + for (int i = 0; i < nnodes; i++) + { NodalVal_t1[i] = pcs->GetNodeValue(nodes[i], idxt1); NodalVal_X1[i] = pcs->GetNodeValue(nodes[i], idx_x1); @@ -9056,7 +8878,7 @@ void CFiniteElementStd::Config() } //----------WW 05.01.07 - if(cpl_pcs) // ?2WW: flags are necessary + if (cpl_pcs) // ?2WW: flags are necessary { for (int i = 0; i < nnodes; i++) { @@ -9091,237 +8913,243 @@ void CFiniteElementStd::Config() void CFiniteElementStd::Assembly() { int i; - Config(); //26.08.2008 + Config(); // 26.08.2008 // If output matrices and vectors. 07.2011. WW - if(pcs->Write_Matrix) + if (pcs->Write_Matrix) (*pcs->matrix_file) << "### Element: " << Index << "\n"; //====================================================================== - switch(PcsType) - { - //.................................................................... - case EPT_LIQUID_FLOW: // Liquid flow - AssembleParabolicEquation(); - Assemble_Gravity(); - Assemble_RHS_LIQUIDFLOW(); - if(dm_pcs) - Assemble_strainCPL(); - add2GlobalMatrixII(); - break; - //.................................................................... - //case U: // Unconfined flow // part of Groundwater flow mmp keyword ($UNCONFINED) - //.................................................................... - case EPT_GROUNDWATER_FLOW: // Groundwater flow - AssembleParabolicEquation(); - //RHS->Write(); - if(dm_pcs) - Assemble_strainCPL(); - add2GlobalMatrixII(); - break; - //.................................................................... - case EPT_TWOPHASE_FLOW: // Two-phase flow - if(pcs->pcs_type_number == 0) - { - // Start partial-pressure-based model - pcs->PartialPS = 0; - + switch (PcsType) + { + //.................................................................... + case EPT_LIQUID_FLOW: // Liquid flow + AssembleParabolicEquation(); + Assemble_Gravity(); + Assemble_RHS_LIQUIDFLOW(); + if (dm_pcs) + Assemble_strainCPL(); + add2GlobalMatrixII(); + break; + //.................................................................... + // case U: // Unconfined flow // part of Groundwater flow mmp keyword ($UNCONFINED) + //.................................................................... + case EPT_GROUNDWATER_FLOW: // Groundwater flow AssembleParabolicEquation(); + // RHS->Write(); + if (dm_pcs) + Assemble_strainCPL(); + add2GlobalMatrixII(); + break; + //.................................................................... + case EPT_TWOPHASE_FLOW: // Two-phase flow + if (pcs->pcs_type_number == 0) + { + // Start partial-pressure-based model + pcs->PartialPS = 0; - if(pcs->PartialPS == 1) // If it is partial-pressure-based - AssembleRHSVector(); - // PrintTheSetOfElementMatrices("Pressure1"); - AssembleCapillaryEffect(); - Assemble_Gravity_Multiphase(); - } - else if(pcs->pcs_type_number == 1) - { - // Turn off the partial-pressure-based model for Snw equation - pcs->PartialPS = 0; + AssembleParabolicEquation(); - pcs->ML_Cap = 0; - AssembleParabolicEquation(); - pcs->ML_Cap = 0; + if (pcs->PartialPS == 1) // If it is partial-pressure-based + AssembleRHSVector(); + // PrintTheSetOfElementMatrices("Pressure1"); + AssembleCapillaryEffect(); + Assemble_Gravity_Multiphase(); + } + else if (pcs->pcs_type_number == 1) + { + // Turn off the partial-pressure-based model for Snw equation + pcs->PartialPS = 0; - AssembleRHSVector(); - Assemble_Gravity_Multiphase(); - } - add2GlobalMatrixII(); - break; - //.................................................................... - case EPT_COMPONENTAL_FLOW: // Componental flow - for(i = 0; i < nnodes; i++) - NodalVal_Sat[i] = pcs->GetNodeValue(nodes[i], idxS); - break; - //.................................................................... - case EPT_HEAT_TRANSPORT: // Heat transport - heat_phase_change = false; // ?2WW - // if(SolidProp->GetCapacityModel()==2) // Boiling model - // CalNodalEnthalpy(); - //CMCD4213 - AssembleMixedHyperbolicParabolicEquation(); - if(FluidProp->density_model == 14 && MediaProp->heat_diffusion_model == 1 && - cpl_pcs ) - Assemble_RHS_HEAT_TRANSPORT(); // This include when need pressure terms n dp/dt + nv.Nabla p//AKS - if(MediaProp->evaporation == 647) - Assemble_RHS_HEAT_TRANSPORT2(); //AKS + pcs->ML_Cap = 0; + AssembleParabolicEquation(); + pcs->ML_Cap = 0; + + AssembleRHSVector(); + Assemble_Gravity_Multiphase(); + } + add2GlobalMatrixII(); + break; + //.................................................................... + case EPT_COMPONENTAL_FLOW: // Componental flow + for (i = 0; i < nnodes; i++) + NodalVal_Sat[i] = pcs->GetNodeValue(nodes[i], idxS); + break; + //.................................................................... + case EPT_HEAT_TRANSPORT: // Heat transport + heat_phase_change = false; // ?2WW + // if(SolidProp->GetCapacityModel()==2) // Boiling model + // CalNodalEnthalpy(); + // CMCD4213 + AssembleMixedHyperbolicParabolicEquation(); + if (FluidProp->density_model == 14 && MediaProp->heat_diffusion_model == 1 && cpl_pcs) + Assemble_RHS_HEAT_TRANSPORT(); // This include when need pressure terms n dp/dt + nv.Nabla p//AKS + if (MediaProp->evaporation == 647) + Assemble_RHS_HEAT_TRANSPORT2(); // AKS #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - add2GlobalMatrixII(); + add2GlobalMatrixII(); #endif - break; - //.................................................................... - case EPT_MASS_TRANSPORT: // Mass transport - //SB4200 - AssembleMixedHyperbolicParabolicEquation(); + break; + //.................................................................... + case EPT_MASS_TRANSPORT: // Mass transport + // SB4200 + AssembleMixedHyperbolicParabolicEquation(); #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - add2GlobalMatrixII(); + add2GlobalMatrixII(); #endif - break; - //.................................................................... - case EPT_OVERLAND_FLOW: // Overland flow - if(pcs->m_num->nls_method == 0) //PICARD - { - AssembleParabolicEquation(); //OK - add2GlobalMatrixII(); - } - else - AssembleParabolicEquationNewton(); //NEWTON - break; - //.................................................................... - case EPT_RICHARDS_FLOW: // Richards flow - if(MediaProp->heat_diffusion_model == 1) - CalcRHS_by_ThermalDiffusion(); - AssembleParabolicEquation(); //OK - Assemble_Gravity(); - Assemble_RHS_LIQUIDFLOW(); //JM (thermal expansion fluid) - if(dm_pcs) - Assemble_strainCPL(); - - if(pcs->m_num->nls_method == 1) // Newton-Raphson. 07.2011. WW - ComputeAdditionalJacobi_Richards(); - add2GlobalMatrixII(); - break; - //.................................................................... - case EPT_FLUID_MOMENTUM: // Fluid Momentum - Assembly handled in Assembly in Fluid_Momentum file - break; - //.................................................................... - case EPT_GAS_FLOW: // Air (gas) flow - //To account advection like term nv.Nabla p - AssembleMixedHyperbolicParabolicEquation(); - //AKS - if(MediaProp->heat_diffusion_model == 1 && cpl_pcs ) - Assemble_RHS_AIR_FLOW(); // n*drho/dt + Nabla.[rho*k/mu rho g]//AKS + break; + //.................................................................... + case EPT_OVERLAND_FLOW: // Overland flow + if (pcs->m_num->nls_method == 0) // PICARD + { + AssembleParabolicEquation(); // OK + add2GlobalMatrixII(); + } + else + AssembleParabolicEquationNewton(); // NEWTON + break; + //.................................................................... + case EPT_RICHARDS_FLOW: // Richards flow + if (MediaProp->heat_diffusion_model == 1) + CalcRHS_by_ThermalDiffusion(); + AssembleParabolicEquation(); // OK + Assemble_Gravity(); + Assemble_RHS_LIQUIDFLOW(); // JM (thermal expansion fluid) + if (dm_pcs) + Assemble_strainCPL(); + + if (pcs->m_num->nls_method == 1) // Newton-Raphson. 07.2011. WW + ComputeAdditionalJacobi_Richards(); + add2GlobalMatrixII(); + break; + //.................................................................... + case EPT_FLUID_MOMENTUM: // Fluid Momentum - Assembly handled in Assembly in Fluid_Momentum file + break; + //.................................................................... + case EPT_GAS_FLOW: // Air (gas) flow + // To account advection like term nv.Nabla p + AssembleMixedHyperbolicParabolicEquation(); + // AKS + if (MediaProp->heat_diffusion_model == 1 && cpl_pcs) + Assemble_RHS_AIR_FLOW(); // n*drho/dt + Nabla.[rho*k/mu rho g]//AKS #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - add2GlobalMatrixII(); + add2GlobalMatrixII(); #endif - break; - case EPT_MULTIPHASE_FLOW: - //TEST dm_pcs = NULL; - // Multi-phase flow 24.02.2007 WW - AssembleParabolicEquation(); - Assemble_Gravity(); - if(cpl_pcs && MediaProp->heat_diffusion_model == 1) - Assemble_RHS_T_MPhaseFlow(); - if(dm_pcs) - Assemble_RHS_M(); - if(pcs->m_num->nls_method == 1) // Newton-Raphson. 06.2011. WW - { - ComputeAdditionalJacobi_H2(); - - if(dm_pcs&& dm_pcs->type == 42) - { - (*StrainCoupling) = 0.0; - CalcStrainCoupling(0); - Assemble_strainCPL_Matrix(1.0, 0); //Phase 0 - - (*StrainCoupling) = 0.0; - CalcStrainCoupling(1); - Assemble_strainCPL_Matrix(1.0, 1); //Phase 1 - } - } - add2GlobalMatrixII(); - break; + break; + case EPT_MULTIPHASE_FLOW: + // TEST dm_pcs = NULL; + // Multi-phase flow 24.02.2007 WW + AssembleParabolicEquation(); + Assemble_Gravity(); + if (cpl_pcs && MediaProp->heat_diffusion_model == 1) + Assemble_RHS_T_MPhaseFlow(); + if (dm_pcs) + Assemble_RHS_M(); + if (pcs->m_num->nls_method == 1) // Newton-Raphson. 06.2011. WW + { + ComputeAdditionalJacobi_H2(); - case EPT_PSGLOBAL: // PS_GLOBAL for Multi-phase flow 03.03 2009 PCH - AssembleParabolicEquation(); - PrintTheSetOfElementMatrices("Laplace"); - if(pcs->num_type_name.find("DirectPc") != string::npos) - { - Assemble_RHS_Pc(); - PrintTheSetOfElementMatrices("RHS_Pc"); - } - Assemble_Gravity(); + if (dm_pcs && dm_pcs->type == 42) + { + (*StrainCoupling) = 0.0; + CalcStrainCoupling(0); + Assemble_strainCPL_Matrix(1.0, 0); // Phase 0 - if(dm_pcs) - Assemble_RHS_M(); - Assemble_RHS_T_PSGlobal(); - add2GlobalMatrixII(); - break; - case EPT_MULTI_COMPONENTIAL_FLOW: - AssembleParabolicEquation(); - Assemble_GravityMCF(); + (*StrainCoupling) = 0.0; + CalcStrainCoupling(1); + Assemble_strainCPL_Matrix(1.0, 1); // Phase 1 + } + } + add2GlobalMatrixII(); + break; + + case EPT_PSGLOBAL: // PS_GLOBAL for Multi-phase flow 03.03 2009 PCH + AssembleParabolicEquation(); + PrintTheSetOfElementMatrices("Laplace"); + if (pcs->num_type_name.find("DirectPc") != string::npos) + { + Assemble_RHS_Pc(); + PrintTheSetOfElementMatrices("RHS_Pc"); + } + Assemble_Gravity(); + + if (dm_pcs) + Assemble_RHS_M(); + Assemble_RHS_T_PSGlobal(); + add2GlobalMatrixII(); + break; + case EPT_MULTI_COMPONENTIAL_FLOW: + AssembleParabolicEquation(); + Assemble_GravityMCF(); #if defined(USE_PETSC) - add2GlobalMatrixII(); + add2GlobalMatrixII(); #else - add2GlobalMatrixII(pcs->dof); + add2GlobalMatrixII(pcs->dof); #endif - break; - case EPT_THERMAL_NONEQUILIBRIUM: - Cal_Velocity(); - AssembleParabolicEquation(); - //Assemble_Gravity(); - Assemble_RHS_TNEQ(); + break; + case EPT_THERMAL_NONEQUILIBRIUM: + Cal_Velocity(); + AssembleParabolicEquation(); + // Assemble_Gravity(); + Assemble_RHS_TNEQ(); #if defined(USE_PETSC) - add2GlobalMatrixII(); + add2GlobalMatrixII(); #else - // TODO [CL] give PETSC function the same signature (avoids ifdef) - add2GlobalMatrixII(pcs->dof); + // TODO [CL] give PETSC function the same signature (avoids ifdef) + add2GlobalMatrixII(pcs->dof); #endif - break; - case EPT_TES: - Cal_Velocity(); - AssembleParabolicEquation(); - //Assemble_Gravity(); - Assemble_RHS_TES(); + break; + case EPT_TES: + Cal_Velocity(); + AssembleParabolicEquation(); + // Assemble_Gravity(); + Assemble_RHS_TES(); #if defined(USE_PETSC) - add2GlobalMatrixII(); + add2GlobalMatrixII(); #else - add2GlobalMatrixII(pcs->dof); + add2GlobalMatrixII(pcs->dof); #endif - break; - //.................................................................... - default: - cout << "Fatal error: No valid PCS type" << '\n'; - break; + break; + //.................................................................... + default: + cout << "Fatal error: No valid PCS type" << '\n'; + break; } //---------------------------------------------------------------------- //---------------------------------------------------------------------- // Output matrices - if(pcs->Write_Matrix) + if (pcs->Write_Matrix) { - (*pcs->matrix_file) << "Stiffness: " << "\n"; + (*pcs->matrix_file) << "Stiffness: " + << "\n"; StiffMatrix->Write(*pcs->matrix_file); (*pcs->matrix_file) << "\n"; - (*pcs->matrix_file) << "---Mass matrix: " << "\n"; - if(Mass) + (*pcs->matrix_file) << "---Mass matrix: " + << "\n"; + if (Mass) Mass->Write(*pcs->matrix_file); - else if(Mass2) + else if (Mass2) Mass2->Write(*pcs->matrix_file); - (*pcs->matrix_file) << "---Laplacian matrix: " << "\n"; + (*pcs->matrix_file) << "---Laplacian matrix: " + << "\n"; Laplace->Write(*pcs->matrix_file); - if(Advection) + if (Advection) { - //CMCD - (*pcs->matrix_file) << "---Advective matrix: " << "\n"; + // CMCD + (*pcs->matrix_file) << "---Advective matrix: " + << "\n"; Advection->Write(*pcs->matrix_file); } - if(Content){ - (*pcs->matrix_file) << "---Content: " << "\n"; + if (Content) + { + (*pcs->matrix_file) << "---Content: " + << "\n"; Content->Write(*pcs->matrix_file); } - (*pcs->matrix_file) << "---RHS: " << "\n"; + (*pcs->matrix_file) << "---RHS: " + << "\n"; RHS->Write(*pcs->matrix_file); (*pcs->matrix_file) << "\n"; } @@ -9340,8 +9168,8 @@ void CFiniteElementStd::Assembly() **************************************************************************/ void CFiniteElementStd::Assembly(int option, int dimension) { - int i,nn; - //---------------------------------------------------------------------- + int i, nn; +//---------------------------------------------------------------------- #ifdef PARALLEL index = m_dom->elements[e]->global_number; #else @@ -9351,18 +9179,18 @@ void CFiniteElementStd::Assembly(int option, int dimension) nn = nnodes; // PCH should check the following line carefully. - if(pcs->type / 10 == 4 || pcs->type == 4) + if (pcs->type / 10 == 4 || pcs->type == 4) nn = nnodesHQ; #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - //TODO -#elif defined(NEW_EQS) //PCH +// TODO +#elif defined(NEW_EQS) // PCH eqs_rhs = pcs->eqs_new->b; #else eqs_rhs = pcs->eqs->b; #endif - for(i = 0; i < nn; i++) + for (i = 0; i < nn; i++) { #ifdef PARALLEL eqs_number[i] = MeshElement->domain_nodes[i]; @@ -9381,29 +9209,33 @@ void CFiniteElementStd::Assembly(int option, int dimension) // if (pcs->Memory_Type==2) skip the these initialization (*Mass) = 0.0; (*Laplace) = 0.0; - if(pcs->Memory_Type > 0) - for(i = LocalShift; (size_t)i < RHS->Size(); i++) + if (pcs->Memory_Type > 0) + for (i = LocalShift; (size_t)i < RHS->Size(); i++) (*RHS)[i] = 0.0; else (*RHS) = 0.0; // Fluid Momentum - AssembleMassMatrix(option); // This is exactly same with CalcMass(). + AssembleMassMatrix(option); // This is exactly same with CalcMass(). AssembleRHS(dimension); - //Output matrices - if(pcs->Write_Matrix) + // Output matrices + if (pcs->Write_Matrix) { for (i = 0; i < nnodes; i++) (*RHS)[i] = NodalVal[i]; (*pcs->matrix_file) << "### Element: " << Index << "\n"; - (*pcs->matrix_file) << "---Mass matrix: " << "\n"; + (*pcs->matrix_file) << "---Mass matrix: " + << "\n"; Mass->Write(*pcs->matrix_file); - (*pcs->matrix_file) << "---Laplacian matrix: " << "\n"; + (*pcs->matrix_file) << "---Laplacian matrix: " + << "\n"; Laplace->Write(*pcs->matrix_file); - (*pcs->matrix_file) << "---RHS: " << "\n"; + (*pcs->matrix_file) << "---RHS: " + << "\n"; RHS->Write(*pcs->matrix_file); (*pcs->matrix_file) << "\n"; - (*pcs->matrix_file) << "Stiffness: " << "\n"; + (*pcs->matrix_file) << "Stiffness: " + << "\n"; StiffMatrix->Write(*pcs->matrix_file); (*pcs->matrix_file) << "\n"; } @@ -9420,7 +9252,7 @@ void CFiniteElementStd::UpdateSolidDensity(size_t elem_idx) ElementValue* gp_ele = ele_gp_value[Index]; double rho_s_elem = 0.0; - double qR_elem = 0.0; + double qR_elem = 0.0; // loop over all Gauss points for (gp = 0; gp < nGaussPoints; gp++) @@ -9428,13 +9260,13 @@ void CFiniteElementStd::UpdateSolidDensity(size_t elem_idx) // copy current to previous. gp_ele->rho_s_prev[gp] = gp_ele->rho_s_curr[gp]; rho_s_elem += gp_ele->rho_s_curr[gp]; - qR_elem += gp_ele->q_R[gp]; + qR_elem += gp_ele->q_R[gp]; } rho_s_elem /= nGaussPoints; - qR_elem /= nGaussPoints; + qR_elem /= nGaussPoints; const int idx_rho = pcs->GetElementValueIndex("SOLID_DENSITY") + 1; - const int idx_qR = pcs->GetElementValueIndex("REACT_RATE") + 1; + const int idx_qR = pcs->GetElementValueIndex("REACT_RATE") + 1; pcs->SetElementValue(elem_idx, idx_rho, rho_s_elem); pcs->SetElementValue(elem_idx, idx_qR, qR_elem); @@ -9454,47 +9286,47 @@ void CFiniteElementStd::ExtropolateGauss(CRFProcess* m_pcs, const int idof) MshElemType::type ElementType = MeshElement->GetElementType(); // Multi-phase flow 03.2009 PCH - if(m_pcs->type == 1212 || m_pcs->type == 1313 || m_pcs->type == 42) + if (m_pcs->type == 1212 || m_pcs->type == 1313 || m_pcs->type == 42) { - switch(idof) + switch (idof) { - case 0: - idx_v2 = m_pcs->GetNodeValueIndex("VELOCITY_X2"); - break; - case 1: - idx_v2 = m_pcs->GetNodeValueIndex("VELOCITY_Y2"); - break; - case 2: - idx_v2 = m_pcs->GetNodeValueIndex("VELOCITY_Z2"); - break; + case 0: + idx_v2 = m_pcs->GetNodeValueIndex("VELOCITY_X2"); + break; + case 1: + idx_v2 = m_pcs->GetNodeValueIndex("VELOCITY_Y2"); + break; + case 2: + idx_v2 = m_pcs->GetNodeValueIndex("VELOCITY_Z2"); + break; } } // For strain and stress extrapolation all element types // Number of elements associated to nodes - for(i = 0; i < nnodes; i++) + for (i = 0; i < nnodes; i++) dbuff[i] = (double)MeshElement->nodes[i]->getConnectedElementIDs().size(); // gp_r = gp_s = gp_t = gp = 0; ElementValue* gp_ele = ele_gp_value[Index]; // - for(gp = 0; gp < nGaussPoints; gp++) + for (gp = 0; gp < nGaussPoints; gp++) { - if(ElementType == MshElemType::QUAD || ElementType == MshElemType::HEXAHEDRON) + if (ElementType == MshElemType::QUAD || ElementType == MshElemType::HEXAHEDRON) { SetGaussPoint(gp, gp_r, gp_s, gp_t); i = GetLocalIndex(gp_r, gp_s, gp_t); - if(i == -1) + if (i == -1) continue; } else i = gp; - NodalVal1[i] = gp_ele->Velocity(idof,gp) * time_unit_factor; + NodalVal1[i] = gp_ele->Velocity(idof, gp) * time_unit_factor; // // // PCH 05.2009 - if(m_pcs->type == 1212 || m_pcs->type == 1313 || m_pcs->type == 42) - NodalVal2[i] = gp_ele->Velocity_g(idof,gp) * time_unit_factor; + if (m_pcs->type == 1212 || m_pcs->type == 1313 || m_pcs->type == 42) + NodalVal2[i] = gp_ele->Velocity_g(idof, gp) * time_unit_factor; } if (ElementType == MshElemType::QUAD || ElementType == MshElemType::HEXAHEDRON) @@ -9504,7 +9336,7 @@ void CFiniteElementStd::ExtropolateGauss(CRFProcess* m_pcs, const int idof) i_s = 0; i_e = nnodes; ish = 0; - if(ElementType == MshElemType::TETRAHEDRON) // tet + if (ElementType == MshElemType::TETRAHEDRON) // tet { i_s = 1; i_e = nnodes + 1; @@ -9520,11 +9352,11 @@ void CFiniteElementStd::ExtropolateGauss(CRFProcess* m_pcs, const int idof) { // average avgEV = CalcAverageGaussPointValues(NodalVal1); - if(m_pcs->type == 1212 || m_pcs->type == 1313) + if (m_pcs->type == 1212 || m_pcs->type == 1313) avgEV1 = CalcAverageGaussPointValues(NodalVal2); } - for(i = 0; i < nnodes; i++) + for (i = 0; i < nnodes; i++) { EV = EV1 = varx = 0.0; @@ -9534,50 +9366,50 @@ void CFiniteElementStd::ExtropolateGauss(CRFProcess* m_pcs, const int idof) SetExtropoGaussPoints(i); // ComputeShapefct(1); // Linear interpolation function - for(j = i_s; j < i_e; j++) + for (j = i_s; j < i_e; j++) EV += NodalVal1[j] * shapefct[j - ish]; } else if (this->GetExtrapoMethod() == ExtrapolationMethod::EXTRAPO_AVERAGE) - //average + // average EV = avgEV; - //for(j=i_s; jGetNodeValue(nodes[i],idx_vel[idof]); - m_pcs->SetNodeValue (nodes[i], idx_vel[idof], EV); + EV += m_pcs->GetNodeValue(nodes[i], idx_vel[idof]); + m_pcs->SetNodeValue(nodes[i], idx_vel[idof], EV); // // Multi-phase flow PCH 05.2009 - if(m_pcs->type == 1212 || m_pcs->type == 1313 || m_pcs->type == 42) + if (m_pcs->type == 1212 || m_pcs->type == 1313 || m_pcs->type == 42) { // Calculate values at nodes if (this->GetExtrapoMethod() == ExtrapolationMethod::EXTRAPO_LINEAR) - for(j = i_s; j < i_e; j++) + for (j = i_s; j < i_e; j++) EV1 += NodalVal2[j] * shapefct[j - ish]; else if (this->GetExtrapoMethod() == ExtrapolationMethod::EXTRAPO_AVERAGE) - //average + // average EV1 = avgEV1; - //for(j=i_s; jGetNodeValue(nodes[i],idx_v2); - m_pcs->SetNodeValue (nodes[i], idx_v2, EV1); + EV1 += m_pcs->GetNodeValue(nodes[i], idx_v2); + m_pcs->SetNodeValue(nodes[i], idx_v2, EV1); } } - } +} /*********************************************************************** 19.02.2013 HS This function is needed to extrapolate the nodal reaction rate values, using the gauss point calculated reaction rates. ***********************************************************************/ -void CFiniteElementStd::ExtrapolateGauss_ReactRate_TNEQ_TES(CRFProcess *m_pcs) +void CFiniteElementStd::ExtrapolateGauss_ReactRate_TNEQ_TES(CRFProcess* m_pcs) { int i, j, gp, gp_r, gp_s, gp_t; int i_s, i_e, ish; - double EV, EV1=0.0, rhoEV, rhoEV1 = 0.0, varx=0.0; + double EV, EV1 = 0.0, rhoEV, rhoEV1 = 0.0, varx = 0.0; // get the index pointing to nodal reaction rate. const int idx_nodal_react_rate = m_pcs->GetNodeValueIndex("REACT_RATE_N"); @@ -9588,41 +9420,41 @@ void CFiniteElementStd::ExtrapolateGauss_ReactRate_TNEQ_TES(CRFProcess *m_pcs) MshElemType::type ElementType = MeshElement->GetElementType(); // Number of elements associated to nodes - for(i=0; inodes[i]->getConnectedElementIDs().size(); - gp_r=gp_s=gp_t=gp=0; + gp_r = gp_s = gp_t = gp = 0; ElementValue* gp_ele = ele_gp_value[Index]; // loop over all gauss points - for(gp=0; gpq_R[gp]*time_unit_factor; - NodalVal5[i] = gp_ele->rho_s_curr[gp]*time_unit_factor; + NodalVal4[i] = gp_ele->q_R[gp] * time_unit_factor; + NodalVal5[i] = gp_ele->rho_s_curr[gp] * time_unit_factor; } - if (ElementType==MshElemType::QUAD || ElementType==MshElemType::HEXAHEDRON) + if (ElementType == MshElemType::QUAD || ElementType == MshElemType::HEXAHEDRON) Xi_p = CalcXi_p(); - i_s=0; - i_e=nnodes; - ish=0; - if(ElementType==MshElemType::TETRAHEDRON) // tet + i_s = 0; + i_e = nnodes; + ish = 0; + if (ElementType == MshElemType::TETRAHEDRON) // tet { - i_s=1; - i_e=nnodes+1; - ish=1; + i_s = 1; + i_e = nnodes + 1; + ish = 1; } //--------------------------------------------------------- // Mapping Gauss point reaction rates to nodes and update nodal @@ -9630,44 +9462,43 @@ void CFiniteElementStd::ExtrapolateGauss_ReactRate_TNEQ_TES(CRFProcess *m_pcs) //--------------------------------------------------------- double avgEV = .0, avg_rhoEV = .0; // double avgEV1 = .0, avg_rhoEV1 = .0; - if (this->GetExtrapoMethod()==ExtrapolationMethod::EXTRAPO_AVERAGE) - { // average + if (this->GetExtrapoMethod() == ExtrapolationMethod::EXTRAPO_AVERAGE) + { // average avgEV = CalcAverageGaussPointValues(NodalVal4); } - for(i=0; iGetExtrapoMethod()==ExtrapolationMethod::EXTRAPO_LINEAR) + if (this->GetExtrapoMethod() == ExtrapolationMethod::EXTRAPO_LINEAR) { SetExtropoGaussPoints(i); // - ComputeShapefct(1); // Linear interpolation function - for(j=i_s; jGetExtrapoMethod()==ExtrapolationMethod::EXTRAPO_AVERAGE) - { //average + else if (this->GetExtrapoMethod() == ExtrapolationMethod::EXTRAPO_AVERAGE) + { // average EV = avgEV; rhoEV = avg_rhoEV; } EV /= dbuff[i]; - EV += m_pcs->GetNodeValue(nodes[i],idx_nodal_react_rate); - m_pcs->SetNodeValue (nodes[i], idx_nodal_react_rate, EV); + EV += m_pcs->GetNodeValue(nodes[i], idx_nodal_react_rate); + m_pcs->SetNodeValue(nodes[i], idx_nodal_react_rate, EV); rhoEV /= dbuff[i]; - rhoEV += m_pcs->GetNodeValue(nodes[i],idx_nodal_solid_density); - m_pcs->SetNodeValue (nodes[i], idx_nodal_solid_density, rhoEV); - } // end of for i over nnodes - + rhoEV += m_pcs->GetNodeValue(nodes[i], idx_nodal_solid_density); + m_pcs->SetNodeValue(nodes[i], idx_nodal_solid_density, rhoEV); + } // end of for i over nnodes } - /*********************************************************************** 27.03.2007 WW ***********************************************************************/ @@ -9677,10 +9508,10 @@ void CFiniteElementStd::CalcSatution() int i_s, i_e, ish; // int l1,l2,l3,l4; //, counter; double sign, eS = 0.0; - // CB_merge_0513 - double *tens = NULL; - int Index ; - Index = MeshElement->GetIndex(); + // CB_merge_0513 + double* tens = NULL; + int Index; + Index = MeshElement->GetIndex(); MshElemType::type ElementType = MeshElement->GetElementType(); //---------------------------------------------------------------------- @@ -9689,71 +9520,71 @@ void CFiniteElementStd::CalcSatution() long group = MeshElement->GetPatchIndex(); mmp_index = group; // - if(pcs->type == 22) + if (pcs->type == 22) { - if(pcs->GetContinnumType() == 0) // Matrix //WW + if (pcs->GetContinnumType() == 0) // Matrix //WW mmp_index = 2 * group; - else // fracture //WW + else // fracture //WW mmp_index = 2 * group + 1; } MediaProp = mmp_vector[mmp_index]; MediaProp->m_pcs = pcs; MediaProp->Fem_Ele_Std = this; - // CB_merge_0513 + // CB_merge_0513 tens = MediaProp->PermeabilityTensor(Index); // sign = -1.0; idx_cp = pcs->GetNodeValueIndex("PRESSURE1") + 1; - idx_S = pcs->GetNodeValueIndex("SATURATION1",true); + idx_S = pcs->GetNodeValueIndex("SATURATION1", true); // Dual Richards - if(pcs->type == 22 && pcs->GetContinnumType() == 1) + if (pcs->type == 22 && pcs->GetContinnumType() == 1) { idx_cp = pcs->GetNodeValueIndex("PRESSURE2") + 1; - idx_S = pcs->GetNodeValueIndex("SATURATION2") + 1; + idx_S = pcs->GetNodeValueIndex("SATURATION2") + 1; } - if(pcs->type == 1212 || pcs->type == 42) + if (pcs->type == 1212 || pcs->type == 42) sign = 1.0; // - for(i = 0; i < nnodes; i++) + for (i = 0; i < nnodes; i++) { // Number of elements associated to nodes dbuff[i] = (double)MeshElement->nodes[i]->getConnectedElementIDs().size(); // pressure - NodalVal0[i] = sign * pcs->GetNodeValue(nodes[i],idx_cp); + NodalVal0[i] = sign * pcs->GetNodeValue(nodes[i], idx_cp); } // gp_r = gp_s = gp_t = gp = 0; // - for(gp = 0; gp < nGaussPoints; gp++) + for (gp = 0; gp < nGaussPoints; gp++) { SetGaussPoint(gp, gp_r, gp_s, gp_t); - if(ElementType == MshElemType::QUAD || ElementType == MshElemType::HEXAHEDRON) + if (ElementType == MshElemType::QUAD || ElementType == MshElemType::HEXAHEDRON) { i = GetLocalIndex(gp_r, gp_s, gp_t); - if(i == -1) + if (i == -1) continue; } else i = gp; // - if(i > nnodes) + if (i > nnodes) continue; ComputeShapefct(1); // - // CB_merge_0513 in case of het K, store local K - MediaProp->local_permeability = tens[0]; + // CB_merge_0513 in case of het K, store local K + MediaProp->local_permeability = tens[0]; PG = interpolate(NodalVal0); NodalVal_Sat[i] = MediaProp->SaturationCapillaryPressureFunction(PG); } - if(ElementType == MshElemType::QUAD || ElementType == MshElemType::HEXAHEDRON) + if (ElementType == MshElemType::QUAD || ElementType == MshElemType::HEXAHEDRON) Xi_p = CalcXi_p(); // i_s = 0; i_e = nnodes; ish = 0; - if(ElementType == MshElemType::TETRAHEDRON) // tet + if (ElementType == MshElemType::TETRAHEDRON) // tet { i_s = 1; i_e = nnodes + 1; @@ -9767,7 +9598,7 @@ void CFiniteElementStd::CalcSatution() if (this->GetExtrapoMethod() == ExtrapolationMethod::EXTRAPO_AVERAGE) // average avgSat = CalcAverageGaussPointValues(NodalVal_Sat); - for(i = 0; i < nnodes; i++) + for (i = 0; i < nnodes; i++) { eS = 0.0; // Calculate values at nodes @@ -9776,21 +9607,23 @@ void CFiniteElementStd::CalcSatution() SetExtropoGaussPoints(i); // ComputeShapefct(1); // Linear interpolation function - for(j = i_s; j < i_e; j++) + for (j = i_s; j < i_e; j++) eS += NodalVal_Sat[j] * shapefct[j - ish]; } else if (this->GetExtrapoMethod() == ExtrapolationMethod::EXTRAPO_AVERAGE) eS = avgSat; // Average value of the contribution of ell neighbor elements eS /= dbuff[i]; - eS += pcs->GetNodeValue(nodes[i],idx_S); + eS += pcs->GetNodeValue(nodes[i], idx_S); // In case the node is on the material interface - if(eS > 1.0) + if (eS > 1.0) eS = 1.0; - if(MediaProp->permeability_saturation_model[0] == 10 && eS < MediaProp->capillary_pressure_values[1]) //MW: limit to non-negative saturation for stability in unconfined gw + if (MediaProp->permeability_saturation_model[0] == 10 + && eS < MediaProp->capillary_pressure_values[1]) // MW: limit to non-negative saturation for stability in + // unconfined gw eS = MediaProp->capillary_pressure_values[1]; // - pcs->SetNodeValue (nodes[i], idx_S, eS); + pcs->SetNodeValue(nodes[i], idx_S, eS); } } /************************************************************************** @@ -9817,83 +9650,82 @@ void CFiniteElementStd::CalcNodeMatParatemer() //---------------------------------------------------------------------- // Node value of the previous time step int idx11 = idx1; - if(pcs->GetContinnumType() == 1) + if (pcs->GetContinnumType() == 1) idx11 = idxp21; - for(i = 0; i < nnodes; i++) - NodalVal1[i] = pcs->GetNodeValue(nodes[i],idx11); - if(PcsType == EPT_MULTIPHASE_FLOW) - for(i = 0; i < nnodes; i++) - NodalVal_p2[i] = pcs->GetNodeValue(nodes[i],idxp21); - if(PcsType == EPT_PSGLOBAL) // 4.3.2009 PCH - - for(i = 0; i < nnodes; i++) - NodalVal_SatNW[i] = pcs->GetNodeValue(nodes[i],idxSn1); - if(cpl_pcs) - for(i = 0; i < nnodes; i++) - { - NodalValC[i] = cpl_pcs->GetNodeValue(nodes[i],idx_c0); - NodalValC1[i] = cpl_pcs->GetNodeValue(nodes[i],idx_c1); - if(cpl_pcs->type == 1212) - NodalVal_p2[i] = cpl_pcs->GetNodeValue(nodes[i],idx_c1 + 2); - //AKS - NodalVal_p20[i] = pcs->GetNodeValue(nodes[i],idx_c0 + 2); + for (i = 0; i < nnodes; i++) + NodalVal1[i] = pcs->GetNodeValue(nodes[i], idx11); + if (PcsType == EPT_MULTIPHASE_FLOW) + for (i = 0; i < nnodes; i++) + NodalVal_p2[i] = pcs->GetNodeValue(nodes[i], idxp21); + if (PcsType == EPT_PSGLOBAL) // 4.3.2009 PCH + + for (i = 0; i < nnodes; i++) + NodalVal_SatNW[i] = pcs->GetNodeValue(nodes[i], idxSn1); + if (cpl_pcs) + for (i = 0; i < nnodes; i++) + { + NodalValC[i] = cpl_pcs->GetNodeValue(nodes[i], idx_c0); + NodalValC1[i] = cpl_pcs->GetNodeValue(nodes[i], idx_c1); + if (cpl_pcs->type == 1212) + NodalVal_p2[i] = cpl_pcs->GetNodeValue(nodes[i], idx_c1 + 2); + // AKS + NodalVal_p20[i] = pcs->GetNodeValue(nodes[i], idx_c0 + 2); } // - if((pcs->additioanl2ndvar_print > 0) && (pcs->additioanl2ndvar_print < 3)) + if ((pcs->additioanl2ndvar_print > 0) && (pcs->additioanl2ndvar_print < 3)) { idx_perm[0] = pcs->GetNodeValueIndex("PERMEABILITY_X1"); idx_perm[1] = pcs->GetNodeValueIndex("PERMEABILITY_Y1"); - if(dim == 3) // 3D + if (dim == 3) // 3D idx_perm[2] = pcs->GetNodeValueIndex("PERMEABILITY_Z1"); } - if(pcs->additioanl2ndvar_print > 1) + if (pcs->additioanl2ndvar_print > 1) idxp = pcs->GetNodeValueIndex("POROSITY"); // Number of elements associated to nodes - for(i = 0; i < nnodes; i++) + for (i = 0; i < nnodes; i++) dbuff[i] = (double)MeshElement->nodes[i]->getConnectedElementIDs().size(); // gp_r = gp_s = gp_t = gp = 0; // - for(gp = 0; gp < nGaussPoints; gp++) + for (gp = 0; gp < nGaussPoints; gp++) { SetGaussPoint(gp, gp_r, gp_s, gp_t); if (ElementType == MshElemType::QUAD || ElementType == MshElemType::HEXAHEDRON) { i = GetLocalIndex(gp_r, gp_s, gp_t); - if(i == -1) + if (i == -1) continue; } else i = gp; // - if(i > nnodes) + if (i > nnodes) continue; ComputeShapefct(1); PG = interpolate(NodalVal1); // - if((pcs->additioanl2ndvar_print > 0) && (pcs->additioanl2ndvar_print < 3)) + if ((pcs->additioanl2ndvar_print > 0) && (pcs->additioanl2ndvar_print < 3)) { double* tensor = MediaProp->PermeabilityTensor(Index); // Modified LBNL model - if( MediaProp->permeability_stress_mode == 2 || - MediaProp->permeability_stress_mode == 3) + if (MediaProp->permeability_stress_mode == 2 || MediaProp->permeability_stress_mode == 3) { - if(cpl_pcs) + if (cpl_pcs) TG = interpolate(NodalValC1) + PhysicalConstant::CelsiusZeroInKelvin; else TG = 293.15; MediaProp->CalStressPermeabilityFactor(w, TG); - for(size_t j = 0; j < dim; j++) + for (size_t j = 0; j < dim; j++) tensor[j * dim + j] *= w[j]; } NodalVal2[i] = tensor[0]; // w[0]; NodalVal3[i] = tensor[dim + 1]; // w[1]; // - if(dim == 3) - NodalVal4[i] = tensor[2 * dim + 2]; // w[2]; // + if (dim == 3) + NodalVal4[i] = tensor[2 * dim + 2]; // w[2]; // } // Porosity - if(pcs->additioanl2ndvar_print > 1) - //MediaProp->Porosity(this); + if (pcs->additioanl2ndvar_print > 1) + // MediaProp->Porosity(this); NodalVal0[i] = MediaProp->Porosity(MeshElement->index, 1.0); } // @@ -9903,7 +9735,7 @@ void CFiniteElementStd::CalcNodeMatParatemer() i_s = 0; i_e = nnodes; ish = 0; - if(ElementType == MshElemType::TETRAHEDRON) // tet + if (ElementType == MshElemType::TETRAHEDRON) // tet { i_s = 1; i_e = nnodes + 1; @@ -9918,16 +9750,16 @@ void CFiniteElementStd::CalcNodeMatParatemer() if (this->GetExtrapoMethod() == ExtrapolationMethod::EXTRAPO_AVERAGE) { // average - if((pcs->additioanl2ndvar_print > 0) && (pcs->additioanl2ndvar_print < 3)) + if ((pcs->additioanl2ndvar_print > 0) && (pcs->additioanl2ndvar_print < 3)) { avgW[0] = CalcAverageGaussPointValues(NodalVal2); avgW[1] = CalcAverageGaussPointValues(NodalVal3); avgW[2] = CalcAverageGaussPointValues(NodalVal4); } - if(pcs->additioanl2ndvar_print > 1) + if (pcs->additioanl2ndvar_print > 1) avgVal = CalcAverageGaussPointValues(NodalVal0); } - for(i = 0; i < nnodes; i++) + for (i = 0; i < nnodes; i++) { // Calculate values at nodes if (this->GetExtrapoMethod() == ExtrapolationMethod::EXTRAPO_LINEAR) @@ -9936,46 +9768,46 @@ void CFiniteElementStd::CalcNodeMatParatemer() // ComputeShapefct(1); // Linear interpolation function } - if((pcs->additioanl2ndvar_print > 0) && (pcs->additioanl2ndvar_print < 3)) + if ((pcs->additioanl2ndvar_print > 0) && (pcs->additioanl2ndvar_print < 3)) { w[0] = w[1] = w[2] = 0.0; if (this->GetExtrapoMethod() == ExtrapolationMethod::EXTRAPO_LINEAR) - for(int j = i_s; j < i_e; j++) + for (int j = i_s; j < i_e; j++) { w[0] += NodalVal2[j] * shapefct[j - ish]; w[1] += NodalVal3[j] * shapefct[j - ish]; - if(dim == 3) + if (dim == 3) w[2] += NodalVal4[j] * shapefct[j - ish]; } else if (this->GetExtrapoMethod() == ExtrapolationMethod::EXTRAPO_AVERAGE) - for(size_t k = 0; k < dim; k++) + for (size_t k = 0; k < dim; k++) w[k] = avgW[k]; // Average value of the contribution of ell neighbor elements - for(size_t k = 0; k < dim; k++) + for (size_t k = 0; k < dim; k++) { w[k] /= dbuff[i]; - w[k] += pcs->GetNodeValue(nodes[i],idx_perm[k]); + w[k] += pcs->GetNodeValue(nodes[i], idx_perm[k]); // - pcs->SetNodeValue (nodes[i], idx_perm[k], w[k]); + pcs->SetNodeValue(nodes[i], idx_perm[k], w[k]); } } - if(pcs->additioanl2ndvar_print > 1) + if (pcs->additioanl2ndvar_print > 1) { nval = 0.0; if (this->GetExtrapoMethod() == ExtrapolationMethod::EXTRAPO_LINEAR) - for(int j = i_s; j < i_e; j++) + for (int j = i_s; j < i_e; j++) nval += NodalVal0[j] * shapefct[j - ish]; else if (this->GetExtrapoMethod() == ExtrapolationMethod::EXTRAPO_AVERAGE) nval = avgVal; - nval /= dbuff[i]; - nval += pcs->GetNodeValue(nodes[i],idxp); + nval /= dbuff[i]; + nval += pcs->GetNodeValue(nodes[i], idxp); // - pcs->SetNodeValue (nodes[i], idxp, nval); + pcs->SetNodeValue(nodes[i], idxp, nval); } } } -//WW 08/2007 +// WW 08/2007 ElementValue::ElementValue(CRFProcess* m_pcs, CElem* ele) : pcs(m_pcs) { MshElemType::type ele_type = ele->GetElementType(); @@ -9983,17 +9815,17 @@ ElementValue::ElementValue(CRFProcess* m_pcs, CElem* ele) : pcs(m_pcs) const int NGP = GetNumericsGaussPoints(ele_type); int NGPoints; - if(ele_type == MshElemType::LINE) - //OKWW + if (ele_type == MshElemType::LINE) + // OKWW NGPoints = m_pcs->m_num->ele_gauss_points; - else if(ele_type == MshElemType::TRIANGLE) + else if (ele_type == MshElemType::TRIANGLE) NGPoints = 3; - else if(ele_type == MshElemType::TETRAHEDRON) + else if (ele_type == MshElemType::TETRAHEDRON) NGPoints = 15; else NGPoints = MathLib::fastpow(NGP, ele_dim); - //WW Velocity.resize(m_pcs->m_msh->GetCoordinateFlag()/10, NGPoints); + // WW Velocity.resize(m_pcs->m_msh->GetCoordinateFlag()/10, NGPoints); Velocity.resize(3, NGPoints); Velocity = 0.0; #ifdef USE_TRANSPORT_FLUX @@ -10002,7 +9834,7 @@ ElementValue::ElementValue(CRFProcess* m_pcs, CElem* ele) : pcs(m_pcs) TransportFlux = 0.0; #endif // 15.3.2007 Multi-phase flow WW - if(pcs->type == 1212 || pcs->type == 1313 || m_pcs->type == 42) + if (pcs->type == 1212 || pcs->type == 1313 || m_pcs->type == 42) { Velocity_g.resize(3, NGPoints); Velocity_g = 0.0; @@ -10014,10 +9846,10 @@ ElementValue::ElementValue(CRFProcess* m_pcs, CElem* ele) : pcs(m_pcs) rho_s_curr = new double[NGPoints]; q_R = new double[NGPoints]; - for (int i=0; iGetPatchIndex(); - rho_s_prev[i] = msp_vector[group]->Density() ; + rho_s_prev[i] = msp_vector[group]->Density(); rho_s_curr[i] = rho_s_prev[i]; q_R[i] = 0.0; } @@ -10029,22 +9861,21 @@ ElementValue::ElementValue(CRFProcess* m_pcs, CElem* ele) : pcs(m_pcs) //_ctx_Gauss = 0.0; } - -//WW 08/2007 +// WW 08/2007 void ElementValue::getIPvalue_vec(const int IP, double* vec) { // SB, BG - for(int i = 0; i < int(Velocity.Rows()); i++) + for (int i = 0; i < int(Velocity.Rows()); i++) vec[i] = Velocity(i, IP); } -//SB, BG 09/2010 +// SB, BG 09/2010 void ElementValue::getIPvalue_vec_phase(const int IP, int phase, double* vec) { - if(phase == 0) - for(int i = 0; (size_t)i < Velocity.Rows(); i++) + if (phase == 0) + for (int i = 0; (size_t)i < Velocity.Rows(); i++) vec[i] = Velocity(i, IP); else if (phase == 10) - for(int i = 0; (size_t)i < Velocity_g.Rows(); i++) + for (int i = 0; (size_t)i < Velocity_g.Rows(); i++) vec[i] = Velocity_g(i, IP); } @@ -10057,29 +9888,29 @@ void ElementValue::getIPvalue_vec_phase(const int IP, int phase, double* vec) **************************************************************************/ void ElementValue::GetEleVelocity(double* vec) { - for(int i = 0; (size_t)i < Velocity.Rows(); i++) + for (int i = 0; (size_t)i < Velocity.Rows(); i++) { vec[i] = 0.0; - for(int j = 0; (size_t)j < Velocity.Cols(); j++) + for (int j = 0; (size_t)j < Velocity.Cols(); j++) vec[i] += Velocity(i, j); vec[i] /= Velocity.Cols(); } } - -//WW +// WW ElementValue::~ElementValue() { Velocity.resize(0, 0); #ifdef USE_TRANSPORT_FLUX TransportFlux.resize(0, 0); // JOD 2014-11-10 #endif - Velocity_g.resize(0,0); + Velocity_g.resize(0, 0); - if (pcs->getProcessType() == FiniteElement::TNEQ || pcs->getProcessType() == FiniteElement::TES) { - delete [] rho_s_prev; - delete [] rho_s_curr; - delete [] q_R; + if (pcs->getProcessType() == FiniteElement::TNEQ || pcs->getProcessType() == FiniteElement::TES) + { + delete[] rho_s_prev; + delete[] rho_s_curr; + delete[] q_R; } } @@ -10087,7 +9918,7 @@ ElementValue::~ElementValue() FEMLib-Method: 01/2006 OK Implementation **************************************************************************/ -//void CFiniteElementStd::AssembleLHSMatrix() +// void CFiniteElementStd::AssembleLHSMatrix() void CFiniteElementStd::AssembleParabolicEquationRHSVector() { int i; @@ -10103,7 +9934,7 @@ void CFiniteElementStd::AssembleParabolicEquationRHSVector() //---------------------------------------------------------------------- // Calculate matrices // Mass matrix.......................................................... - if(pcs->m_num->ele_mass_lumping) + if (pcs->m_num->ele_mass_lumping) CalcLumpedMass(); else CalcMass(); @@ -10112,35 +9943,35 @@ void CFiniteElementStd::AssembleParabolicEquationRHSVector() //---------------------------------------------------------------------- // Assemble local LHS matrix: // [C]/dt + theta [K] - //Mass matrix - *StiffMatrix = *Mass; + // Mass matrix + *StiffMatrix = *Mass; (*StiffMatrix) *= dt_inverse; // Laplace matrix - *AuxMatrix = *Laplace; - *StiffMatrix += *AuxMatrix; + *AuxMatrix = *Laplace; + *StiffMatrix += *AuxMatrix; //---------------------------------------------------------------------- for (i = 0; i < nnodes; i++) { - NodalVal1[i] = pcs->GetNodeValue(nodes[i],idx1); + NodalVal1[i] = pcs->GetNodeValue(nodes[i], idx1); NodalVal[i] = 0.0; } //---------------------------------------------------------------------- StiffMatrix->multi(NodalVal1, NodalVal); - //---------------------------------------------------------------------- +//---------------------------------------------------------------------- #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - //TODO +// TODO #else #ifdef NEW_EQS - eqs_rhs = pcs->eqs_new->b; //WW - if(m_dom) - eqs_rhs = m_dom->eqs->b; //WW + eqs_rhs = pcs->eqs_new->b; // WW + if (m_dom) + eqs_rhs = m_dom->eqs->b; // WW #else - eqs_rhs = pcs->eqs->b; //WW + eqs_rhs = pcs->eqs->b; // WW #endif for (i = 0; i < nnodes; i++) { eqs_number[i] = MeshElement->nodes[i]->GetEquationIndex(); - eqs_rhs[eqs_number[i]] += NodalVal[i]; + eqs_rhs[eqs_number[i]] += NodalVal[i]; } #endif //---------------------------------------------------------------------- @@ -10158,76 +9989,71 @@ void CFiniteElementStd::AssembleParabolicEquationRHSVector() double CFiniteElementStd::CalCoef_RHS_T_MPhase(int dof_index) { double val = 0.0, D_gw = 0.0, D_ga = 0.0; - double expfactor = 0.0,dens_arg[3]; + double expfactor = 0.0, dens_arg[3]; int Index = MeshElement->GetIndex(); ComputeShapefct(1); //====================================================================== const double Mw = MolarMass::Water; - switch(dof_index) + switch (dof_index) { - case 0: - PG = interpolate(NodalVal1); - Sw = MediaProp->SaturationCapillaryPressureFunction(PG); - TG = interpolate(NodalValC1) + PhysicalConstant::CelsiusZeroInKelvin; - TG0 = interpolate(NodalValC) + PhysicalConstant::CelsiusZeroInKelvin; - PG2 = interpolate(NodalVal_p2); - rhow = FluidProp->Density(); - poro = MediaProp->Porosity(Index,pcs->m_num->ls_theta); - expfactor = 1.0 / (rhow * SpecificGasConstant::WaterVapour * TG); - rho_gw = FluidProp->vaporDensity(TG) * exp(-PG * expfactor); - // - drho_gw_dT = (FluidProp->vaporDensity_derivative(TG) - + PG * expfactor * FluidProp->vaporDensity(TG) / TG) * exp( - -PG * expfactor); - val = (1. - Sw) * poro * drho_gw_dT / rhow; - // - if(SolidProp) - val -= - (1.0 - - poro) * - ((1 - Sw) * rho_gw / rhow + Sw) * SolidProp->Thermal_Expansion(); - // - // val += n*(1.0-rho_gw/rhow)*(dSw/dT) - val *= (TG - TG0); - break; - case 1: - // - val = -(1. - Sw) * poro * drho_gw_dT / rhow; - // - if(SolidProp) - val -= - (1.0 - - poro) * (1 - Sw) * rho_ga * SolidProp->Thermal_Expansion() / rhow; - // - // val -= n*rho_ga/rhow)*(dSw/dT) - //--------------------------------------------------------------- - val *= (TG - TG0); - break; - case 2: - //------------------------------------------------------------------------ - // From grad (p_gw/p_g) - tort = MediaProp->TortuosityFunction(Index,unit,pcs->m_num->ls_theta); - tort *= MediaProp->base_heat_diffusion_coefficient * (1 - Sw) * poro - * pow(TG / PhysicalConstant::CelsiusZeroInKelvin, 1.8); - p_gw = rho_gw * SpecificGasConstant::WaterVapour * TG; - dens_arg[0] = PG2 - p_gw; - dens_arg[1] = TG; - rho_ga = GasProp->Density(dens_arg); //AKS SEP 2010 //(PG2-p_gw)*GasProp->molar_mass/(FluidConstant::GasConstant()*TG); - rho_g = rho_ga + rho_gw; - // 1/Mg - M_g = (rho_gw / Mw + rho_ga / GasProp->molar_mass) / rho_g; - D_gw = tort * rho_g * Mw * GasProp->molar_mass * M_g * M_g / rhow; - val = D_gw * drho_gw_dT * SpecificGasConstant::WaterVapour * TG / PG2 * time_unit_factor; - break; - case 3: - //--------------------------------------------------------------- - // - D_ga = tort * rho_g * Mw * GasProp->molar_mass * M_g * M_g / rhow; - // From grad (p_gw/p_g) - val = -D_ga * drho_gw_dT * SpecificGasConstant::WaterVapour * TG / PG2 * time_unit_factor; + case 0: + PG = interpolate(NodalVal1); + Sw = MediaProp->SaturationCapillaryPressureFunction(PG); + TG = interpolate(NodalValC1) + PhysicalConstant::CelsiusZeroInKelvin; + TG0 = interpolate(NodalValC) + PhysicalConstant::CelsiusZeroInKelvin; + PG2 = interpolate(NodalVal_p2); + rhow = FluidProp->Density(); + poro = MediaProp->Porosity(Index, pcs->m_num->ls_theta); + expfactor = 1.0 / (rhow * SpecificGasConstant::WaterVapour * TG); + rho_gw = FluidProp->vaporDensity(TG) * exp(-PG * expfactor); + // + drho_gw_dT = (FluidProp->vaporDensity_derivative(TG) + PG * expfactor * FluidProp->vaporDensity(TG) / TG) + * exp(-PG * expfactor); + val = (1. - Sw) * poro * drho_gw_dT / rhow; + // + if (SolidProp) + val -= (1.0 - poro) * ((1 - Sw) * rho_gw / rhow + Sw) * SolidProp->Thermal_Expansion(); + // + // val += n*(1.0-rho_gw/rhow)*(dSw/dT) + val *= (TG - TG0); + break; + case 1: + // + val = -(1. - Sw) * poro * drho_gw_dT / rhow; + // + if (SolidProp) + val -= (1.0 - poro) * (1 - Sw) * rho_ga * SolidProp->Thermal_Expansion() / rhow; + // + // val -= n*rho_ga/rhow)*(dSw/dT) + //--------------------------------------------------------------- + val *= (TG - TG0); + break; + case 2: + //------------------------------------------------------------------------ + // From grad (p_gw/p_g) + tort = MediaProp->TortuosityFunction(Index, unit, pcs->m_num->ls_theta); + tort *= MediaProp->base_heat_diffusion_coefficient * (1 - Sw) * poro + * pow(TG / PhysicalConstant::CelsiusZeroInKelvin, 1.8); + p_gw = rho_gw * SpecificGasConstant::WaterVapour * TG; + dens_arg[0] = PG2 - p_gw; + dens_arg[1] = TG; + rho_ga = GasProp->Density( + dens_arg); // AKS SEP 2010 //(PG2-p_gw)*GasProp->molar_mass/(FluidConstant::GasConstant()*TG); + rho_g = rho_ga + rho_gw; + // 1/Mg + M_g = (rho_gw / Mw + rho_ga / GasProp->molar_mass) / rho_g; + D_gw = tort * rho_g * Mw * GasProp->molar_mass * M_g * M_g / rhow; + val = D_gw * drho_gw_dT * SpecificGasConstant::WaterVapour * TG / PG2 * time_unit_factor; + break; + case 3: + //--------------------------------------------------------------- + // + D_ga = tort * rho_g * Mw * GasProp->molar_mass * M_g * M_g / rhow; + // From grad (p_gw/p_g) + val = -D_ga * drho_gw_dT * SpecificGasConstant::WaterVapour * TG / PG2 * time_unit_factor; - break; - //------------------------------------------------------------------ + break; + //------------------------------------------------------------------ } return val; } @@ -10242,35 +10068,35 @@ double CFiniteElementStd::CalCoef_RHS_T_MPhase(int dof_index) **************************************************************************/ double CFiniteElementStd::CalCoef_RHS_T_PSGlobal(int dof_index) { - double val = 0.0, variables[3]; //OK411 D_gw=0.0, D_ga=0.0; - //OK411 double expfactor=0.0; - double P,T; + double val = 0.0, variables[3]; // OK411 D_gw=0.0, D_ga=0.0; + // OK411 double expfactor=0.0; + double P, T; int Index = MeshElement->GetIndex(); ComputeShapefct(1); //====================================================================== - switch(dof_index) + switch (dof_index) { - case 0: - val = 0.; - break; - case 1: - poro = MediaProp->Porosity(Index,pcs->m_num->ls_theta); - Sw = 1.0 - interpolate(NodalVal_SatNW); - // Pnw = Pw + Pc(Sw) - P = interpolate(NodalVal1) + MediaProp->CapillaryPressureFunction(Sw); - // P = interpolate(NodalVal1); // Pw - T = interpolate(NodalValC1); - variables[0]=P; - variables[1]=T; - val = -(1. - Sw) * poro * GasProp->drhodT(variables) / GasProp->Density(); - break; - case 2: - val = 0.; - break; - case 3: - val = 0.; - break; - //------------------------------------------------------------------ + case 0: + val = 0.; + break; + case 1: + poro = MediaProp->Porosity(Index, pcs->m_num->ls_theta); + Sw = 1.0 - interpolate(NodalVal_SatNW); + // Pnw = Pw + Pc(Sw) + P = interpolate(NodalVal1) + MediaProp->CapillaryPressureFunction(Sw); + // P = interpolate(NodalVal1); // Pw + T = interpolate(NodalValC1); + variables[0] = P; + variables[1] = T; + val = -(1. - Sw) * poro * GasProp->drhodT(variables) / GasProp->Density(); + break; + case 2: + val = 0.; + break; + case 3: + val = 0.; + break; + //------------------------------------------------------------------ } return val; } @@ -10285,33 +10111,33 @@ double CFiniteElementStd::CalCoef_RHS_T_PSGlobal(int dof_index) void CFiniteElementStd::CalCoef_RHS_Pc(int dof_index) { double* tensor = NULL; - double mat_fac = 1.0; //OK411 m_fac=0.; + double mat_fac = 1.0; // OK411 m_fac=0.; double k_rel = 0.0; int Index = MeshElement->GetIndex(); // - ComputeShapefct(1); // 12.3.2007 WW + ComputeShapefct(1); // 12.3.2007 WW //====================================================================== - for(size_t i = 0; i < dim * dim; i++) + for (size_t i = 0; i < dim * dim; i++) mat[i] = 0.0; - switch(dof_index) + switch (dof_index) { - case 0: - break; - case 1: - break; - case 2: - tensor = MediaProp->PermeabilityTensor(Index); - Sw = 1.0 - interpolate(NodalVal_SatNW); - k_rel = MediaProp->PermeabilitySaturationFunction(Sw,1); - mat_fac = k_rel / GasProp->Viscosity() * time_unit_factor; - - for(size_t i = 0; i < dim * dim; i++) - mat[i] = tensor[i] * mat_fac; - break; - case 3: - break; + case 0: + break; + case 1: + break; + case 2: + tensor = MediaProp->PermeabilityTensor(Index); + Sw = 1.0 - interpolate(NodalVal_SatNW); + k_rel = MediaProp->PermeabilitySaturationFunction(Sw, 1); + mat_fac = k_rel / GasProp->Viscosity() * time_unit_factor; + + for (size_t i = 0; i < dim * dim; i++) + mat[i] = tensor[i] * mat_fac; + break; + case 3: + break; } } @@ -10326,26 +10152,27 @@ void CFiniteElementStd::CalCoef_RHS_Pc(int dof_index) double CFiniteElementStd::CalCoef_RHS_PSGLOBAL(int dof_index) { ComputeShapefct(1); - for(size_t i = 0; i < dim * dim; i++) + for (size_t i = 0; i < dim * dim; i++) mat[i] = 0.0; - switch(dof_index) + switch (dof_index) { - case 0: - return 0.0; - break; - case 1: - return 0.0; - break; - case 2: { - Sw = 1.0 - interpolate(NodalVal_SatNW); - double k_rel (MediaProp->PermeabilitySaturationFunction(Sw,1)); - return (k_rel / GasProp->Viscosity() * time_unit_factor); - break; - } - case 3: - return 0.0; - break; + case 0: + return 0.0; + break; + case 1: + return 0.0; + break; + case 2: + { + Sw = 1.0 - interpolate(NodalVal_SatNW); + double k_rel(MediaProp->PermeabilitySaturationFunction(Sw, 1)); + return (k_rel / GasProp->Viscosity() * time_unit_factor); + break; + } + case 3: + return 0.0; + break; } return 0.0; } @@ -10365,16 +10192,16 @@ double CFiniteElementStd::CalCoef_RHS_AIR_FLOW(int dof_index) PG = interpolate(NodalVal1); TG = interpolate(NodalValC1) + PhysicalConstant::CelsiusZeroInKelvin; TG0 = interpolate(NodalValC) + PhysicalConstant::CelsiusZeroInKelvin; - switch(dof_index) + switch (dof_index) { - case 0: - val = -MediaProp->Porosity(Index,pcs->m_num->ls_theta) / TG; - val *= (TG - TG0); - break; + case 0: + val = -MediaProp->Porosity(Index, pcs->m_num->ls_theta) / TG; + val *= (TG - TG0); + break; - case 1: - val = -1.0 / TG; - break; + case 1: + val = -1.0 / TG; + break; } return val; } @@ -10399,18 +10226,17 @@ double CFiniteElementStd::CalCoef_RHS_HEAT_TRANSPORT(int dof_index) dens_arg[1] = 120 + PhysicalConstant::CelsiusZeroInKelvin; rho_0 = FluidProp->Density(dens_arg); - switch(dof_index) + switch (dof_index) { - case 0: - val = (interpolate(NodalValC1) - interpolate(NodalValC)) * MediaProp->Porosity( - Index, - pcs->m_num->ls_theta) * rho_g / rho_0; - break; + case 0: + val = (interpolate(NodalValC1) - interpolate(NodalValC)) * MediaProp->Porosity(Index, pcs->m_num->ls_theta) + * rho_g / rho_0; + break; - case 1: - val = rho_g / rho_0; - val -= 1.0; // term coresponding to the 'Viscour dissipation' - break; + case 1: + val = rho_g / rho_0; + val -= 1.0; // term coresponding to the 'Viscour dissipation' + break; } return val; } @@ -10424,7 +10250,7 @@ void CFiniteElementStd::Assemble_RHS_T_MPhaseFlow() { int i, j, ii; // ---- Gauss integral - int gp_r = 0,gp_s = 0,gp_t = 0; + int gp_r = 0, gp_s = 0, gp_t = 0; double fkt, fac; // Material int dof_n = 2; @@ -10441,17 +10267,17 @@ void CFiniteElementStd::Assemble_RHS_T_MPhaseFlow() //--------------------------------------------------------- fkt = GetGaussData(gp, gp_r, gp_s, gp_t); // Compute geometry - ComputeGradShapefct(1); // Linear interpolation function - ComputeShapefct(1); // Linear interpolation function - for(ii = 0; ii < dof_n; ii++) + ComputeGradShapefct(1); // Linear interpolation function + ComputeShapefct(1); // Linear interpolation function + for (ii = 0; ii < dof_n; ii++) { // Material fac = fkt * CalCoef_RHS_T_MPhase(ii) / dt; - // Calculate THS +// Calculate THS #if defined(USE_PETSC) //|| defined (other parallel solver) //WW 04.2014 for (int ia = 0; ia < act_nodes; ia++) - { - const int i = local_idx[ia]; + { + const int i = local_idx[ia]; #else for (i = 0; i < nnodes; i++) { @@ -10460,35 +10286,32 @@ void CFiniteElementStd::Assemble_RHS_T_MPhaseFlow() } } // grad T - for(ii = 0; ii < dof_n; ii++) + for (ii = 0; ii < dof_n; ii++) { // Material fac = fkt * CalCoef_RHS_T_MPhase(ii + dof_n); - // Calculate THS +// Calculate THS #if defined(USE_PETSC) //|| defined (other parallel solver) //WW 04.2014 for (int ia = 0; ia < act_nodes; ia++) - { - const int i = local_idx[ia]; + { + const int i = local_idx[ia]; #else for (i = 0; i < nnodes; i++) { #endif for (j = 0; j < nnodes; j++) for (size_t k = 0; k < dim; k++) - NodalVal[i + ii * nnodes] += - fac * - dshapefct[k * nnodes + - i] * dshapefct[k * nnodes + j] - * (NodalValC1[j] + PhysicalConstant::CelsiusZeroInKelvin); + NodalVal[i + ii * nnodes] += fac * dshapefct[k * nnodes + i] * dshapefct[k * nnodes + j] + * (NodalValC1[j] + PhysicalConstant::CelsiusZeroInKelvin); } } } #if !defined(USE_PETSC) // && !defined(other parallel libs)//03~04.3012. WW int dm_shift = 0; - if(pcs->type / 10 == 4) + if (pcs->type / 10 == 4) dm_shift = problem_dimension_dm; #endif - for(ii = 0; ii < 2; ii++) + for (ii = 0; ii < 2; ii++) { int ii_sh = ii * nnodes; for (i = 0; i < nnodes; i++) @@ -10497,7 +10320,7 @@ void CFiniteElementStd::Assemble_RHS_T_MPhaseFlow() int i_sh = NodeShift[ii + dm_shift]; eqs_rhs[i_sh + eqs_number[i]] -= NodalVal[i + ii_sh]; #endif - (*RHS)[i + LocalShift + ii_sh] -= NodalVal[i + ii_sh]; + (*RHS)[i + LocalShift + ii_sh] -= NodalVal[i + ii_sh]; } } // @@ -10509,9 +10332,9 @@ void CFiniteElementStd::Assemble_RHS_T_MPhaseFlow() **************************************************************************/ void CFiniteElementStd::Assemble_RHS_T_PSGlobal() { - int i, ii; //OK411 j, k, + int i, ii; // OK411 j, k, // ---- Gauss integral - int gp_r = 0,gp_s = 0,gp_t = 0; + int gp_r = 0, gp_s = 0, gp_t = 0; double fkt, fac; // Material int dof_n = 2; @@ -10529,28 +10352,28 @@ void CFiniteElementStd::Assemble_RHS_T_PSGlobal() //--------------------------------------------------------- fkt = GetGaussData(gp, gp_r, gp_s, gp_t); // Compute geometry - ComputeGradShapefct(1); // Linear interpolation function - ComputeShapefct(1); // Linear interpolation function + ComputeGradShapefct(1); // Linear interpolation function + ComputeShapefct(1); // Linear interpolation function - for(ii = 0; ii < dof_n; ii++) + for (ii = 0; ii < dof_n; ii++) { // Material fac = fkt * CalCoef_RHS_T_PSGlobal(ii) / dt; - // Calculate THS +// Calculate THS #if defined(USE_PETSC) //|| defined (other parallel solver) //WW 04.2014 for (int ia = 0; ia < act_nodes; ia++) - { - const int i = local_idx[ia]; + { + const int i = local_idx[ia]; #else for (i = 0; i < nnodes; i++) - { + { #endif NodalVal[i + ii * nnodes] += fac * shapefct[i]; - //remove temp[i + ii * nnodes] += fac * shapefct[i]; + // remove temp[i + ii * nnodes] += fac * shapefct[i]; } } } - for(ii = 0; ii < pcs->dof; ii++) + for (ii = 0; ii < pcs->dof; ii++) { int ii_sh = ii * nnodes; for (i = 0; i < nnodes; i++) @@ -10559,7 +10382,7 @@ void CFiniteElementStd::Assemble_RHS_T_PSGlobal() int i_sh = NodeShift[ii]; eqs_rhs[i_sh + eqs_number[i]] -= NodalVal[i + ii_sh]; #endif - (*RHS)[i + LocalShift + ii_sh] -= NodalVal[i + ii_sh]; + (*RHS)[i + LocalShift + ii_sh] -= NodalVal[i + ii_sh]; } } // @@ -10575,24 +10398,24 @@ void CFiniteElementStd::Assemble_RHS_Pc() { int i, j, ii; // ---- Gauss integral - int gp_r = 0,gp_s = 0,gp_t = 0; + int gp_r = 0, gp_s = 0, gp_t = 0; double fkt; // Material int dof_n = 2; int ndx_p_cap = pcs->GetNodeValueIndex("PRESSURE_CAP"); //---------------------------------------------------------------------- -// double temp[20]; + // double temp[20]; for (i = 0; i < dof_n * nnodes; i++) { -// temp[i] = NodalVal[i] = 0.0; + // temp[i] = NodalVal[i] = 0.0; NodalVal[i] = 0.0; NodalVal1[i] = 0.0; } for (i = 0; i < nnodes; i++) -// temp[i+dof_n] = NodalVal1[i+dof_n] = -pcs->GetNodeValue(nodes[i],ndx_p_cap); - NodalVal1[i + dof_n] = -pcs->GetNodeValue(nodes[i],ndx_p_cap); + // temp[i+dof_n] = NodalVal1[i+dof_n] = -pcs->GetNodeValue(nodes[i],ndx_p_cap); + NodalVal1[i + dof_n] = -pcs->GetNodeValue(nodes[i], ndx_p_cap); //====================================================================== // Loop over Gauss points @@ -10604,18 +10427,18 @@ void CFiniteElementStd::Assemble_RHS_Pc() //--------------------------------------------------------- fkt = GetGaussData(gp, gp_r, gp_s, gp_t); // Compute geometry - ComputeGradShapefct(1); // Linear interpolation function - ComputeShapefct(1); // Linear interpolation function + ComputeGradShapefct(1); // Linear interpolation function + ComputeShapefct(1); // Linear interpolation function // grad Pc - for(ii = 0; ii < dof_n; ii++) + for (ii = 0; ii < dof_n; ii++) { // Material CalCoef_RHS_Pc(ii + dof_n); - // Calculate Pc +// Calculate Pc #if defined(USE_PETSC) //|| defined (other parallel solver) //WW 04.2014 for (int ia = 0; ia < act_nodes; ia++) - { - const int i = local_idx[ia]; + { + const int i = local_idx[ia]; #else for (i = 0; i < nnodes; i++) { @@ -10623,23 +10446,16 @@ void CFiniteElementStd::Assemble_RHS_Pc() for (j = 0; j < nnodes; j++) for (size_t k = 0; k < dim; k++) for (size_t l = 0; l < dim; l++) - NodalVal[dof_n + - i] += fkt * - mat[dim * k + - l] * - dshapefct[k * nnodes + - i] * - dshapefct[l * nnodes + j] - * NodalVal1[j + - dof_n]; - } + NodalVal[dof_n + i] += fkt * mat[dim * k + l] * dshapefct[k * nnodes + i] + * dshapefct[l * nnodes + j] * NodalVal1[j + dof_n]; + } } } -// for(i=0; i<2*nnodes; ++i) -// temp[i]=NodalVal[i]; + // for(i=0; i<2*nnodes; ++i) + // temp[i]=NodalVal[i]; - for(ii = 0; ii < pcs->dof; ii++) + for (ii = 0; ii < pcs->dof; ii++) { int ii_sh = ii * nnodes; for (i = 0; i < nnodes; i++) @@ -10648,7 +10464,7 @@ void CFiniteElementStd::Assemble_RHS_Pc() int i_sh = NodeShift[ii]; eqs_rhs[i_sh + eqs_number[i]] += NodalVal[i + ii_sh]; #endif - (*RHS)[i + LocalShift + ii_sh] += NodalVal[i + ii_sh]; + (*RHS)[i + LocalShift + ii_sh] += NodalVal[i + ii_sh]; } } // @@ -10662,88 +10478,94 @@ void CFiniteElementStd::Assemble_RHS_Pc() **************************************************************************/ void CFiniteElementStd::Assemble_RHS_LIQUIDFLOW() { - if (!isTemperatureCoupling()) return; - if ((FluidProp->drho_dT == .0 && (FluidProp->density_model<8 || FluidProp->density_model>14))&& SolidProp->Thermal_Expansion()==.0) return; - - //---------------------------------------------------------------------- - for (int i = 0; i < nnodes; i++) - NodalVal[i] = 0.0; - //====================================================================== - // Loop over Gauss points - int gp_r = 0,gp_s = 0,gp_t = 0; - for (gp = 0; gp < nGaussPoints; gp++) - { - //--------------------------------------------------------- - // Get local coordinates and weights - // Compute Jacobian matrix and its determinate - //--------------------------------------------------------- - const double gp_fkt = GetGaussData(gp, gp_r, gp_s, gp_t); - //--------------------------------------------------------- - // Compute geometry - //--------------------------------------------------------- - ComputeShapefct(1); // Linear interpolation function - //--------------------------------------------------------- - // Evaluate variables - //--------------------------------------------------------- - const double T_n = interpolate(NodalValC); - const double T_n1 = interpolate(NodalValC1); - const double dT = T_n1 -T_n; - //--------------------------------------------------------- - // Evaluate material property - //--------------------------------------------------------- - const double poro = MediaProp->Porosity(Index, pcs->m_num->ls_theta); - double alpha_T_s = 3.*SolidProp->Thermal_Expansion(); // multiply 3 for volumetrix expression - Sw = 1.0; - double alpha_T_l; - if (FluidProp->density_model>7 && FluidProp->density_model<15){ - double arg[2]; - arg[0]=interpolate(NodalVal1); // p - arg[1]=interpolate(NodalValC1); // T - alpha_T_l = - FluidProp->drhodT(arg)/FluidProp->Density(); + if (!isTemperatureCoupling()) + return; + if ((FluidProp->drho_dT == .0 && (FluidProp->density_model < 8 || FluidProp->density_model > 14)) + && SolidProp->Thermal_Expansion() == .0) + return; + + //---------------------------------------------------------------------- + for (int i = 0; i < nnodes; i++) + NodalVal[i] = 0.0; + //====================================================================== + // Loop over Gauss points + int gp_r = 0, gp_s = 0, gp_t = 0; + for (gp = 0; gp < nGaussPoints; gp++) + { + //--------------------------------------------------------- + // Get local coordinates and weights + // Compute Jacobian matrix and its determinate + //--------------------------------------------------------- + const double gp_fkt = GetGaussData(gp, gp_r, gp_s, gp_t); + //--------------------------------------------------------- + // Compute geometry + //--------------------------------------------------------- + ComputeShapefct(1); // Linear interpolation function + //--------------------------------------------------------- + // Evaluate variables + //--------------------------------------------------------- + const double T_n = interpolate(NodalValC); + const double T_n1 = interpolate(NodalValC1); + const double dT = T_n1 - T_n; + //--------------------------------------------------------- + // Evaluate material property + //--------------------------------------------------------- + const double poro = MediaProp->Porosity(Index, pcs->m_num->ls_theta); + double alpha_T_s = 3. * SolidProp->Thermal_Expansion(); // multiply 3 for volumetrix expression + Sw = 1.0; + double alpha_T_l; + if (FluidProp->density_model > 7 && FluidProp->density_model < 15) + { + double arg[2]; + arg[0] = interpolate(NodalVal1); // p + arg[1] = interpolate(NodalValC1); // T + alpha_T_l = -FluidProp->drhodT(arg) / FluidProp->Density(); } else - alpha_T_l = - FluidProp->drho_dT; //negative sign is required due to OGS input - - if(PcsType==EPT_RICHARDS_FLOW){ - //for Richards: - PG = interpolate(NodalVal1); - if(PG<0.0){ - if(FluidProp->drho_dT_unsaturated) - Sw = MediaProp->SaturationCapillaryPressureFunction(-PG); - else - alpha_T_l = alpha_T_s = 0.0; - } - } - const double eff_thermal_expansion = (SolidProp->biot_const-poro)*alpha_T_s + poro*Sw*alpha_T_l; - //--------------------------------------------------------- - // Compute RHS+=int{N^T alpha_T dT/dt} - //--------------------------------------------------------- - const double fac = eff_thermal_expansion * dT / dt / time_unit_factor;//WX:bug fixed + alpha_T_l = -FluidProp->drho_dT; // negative sign is required due to OGS input + + if (PcsType == EPT_RICHARDS_FLOW) + { + // for Richards: + PG = interpolate(NodalVal1); + if (PG < 0.0) + { + if (FluidProp->drho_dT_unsaturated) + Sw = MediaProp->SaturationCapillaryPressureFunction(-PG); + else + alpha_T_l = alpha_T_s = 0.0; + } + } + const double eff_thermal_expansion = (SolidProp->biot_const - poro) * alpha_T_s + poro * Sw * alpha_T_l; + //--------------------------------------------------------- + // Compute RHS+=int{N^T alpha_T dT/dt} + //--------------------------------------------------------- + const double fac = eff_thermal_expansion * dT / dt / time_unit_factor; // WX:bug fixed #if defined(USE_PETSC) //|| defined (other parallel solver) //WW 04.2014 - for (int ia = 0; ia < act_nodes; ia++) - { - const int i = local_idx[ia]; + for (int ia = 0; ia < act_nodes; ia++) + { + const int i = local_idx[ia]; #else - for (int i = 0; i < nnodes; i++) - { + for (int i = 0; i < nnodes; i++) + { #endif - NodalVal[i] += gp_fkt * fac * shapefct[i]; - } - } + NodalVal[i] += gp_fkt * fac * shapefct[i]; + } + } #if !defined(USE_PETSC) // && !defined(other parallel libs)//03~04.3012. WW - int dm_shift = 0; - if(pcs->type / 10 == 4) - dm_shift = problem_dimension_dm; - int i_sh = NodeShift[dm_shift]; + int dm_shift = 0; + if (pcs->type / 10 == 4) + dm_shift = problem_dimension_dm; + int i_sh = NodeShift[dm_shift]; #endif - for (int i = 0; i < nnodes; i++) - { + for (int i = 0; i < nnodes; i++) + { #if !defined(USE_PETSC) // && !defined(other parallel libs)//03~04.3012. WW - eqs_rhs[i_sh + eqs_number[i]] += NodalVal[i]; + eqs_rhs[i_sh + eqs_number[i]] += NodalVal[i]; #endif - (*RHS)[i + LocalShift] += NodalVal[i]; - } + (*RHS)[i + LocalShift] += NodalVal[i]; + } } /*************************************************************************** @@ -10756,7 +10578,7 @@ void CFiniteElementStd::Assemble_RHS_M() { int i, ii; // ---- Gauss integral - int gp_r = 0,gp_s = 0,gp_t = 0; + int gp_r = 0, gp_s = 0, gp_t = 0; double fkt, fac, grad_du = 0.0; // Material int dof_n = 2; @@ -10766,25 +10588,22 @@ void CFiniteElementStd::Assemble_RHS_M() for (i = nnodes; i < nnodesHQ; i++) nodes[i] = MeshElement->nodes_index[i]; - if(dm_pcs->type == 42 ) // Monolitihc scheme. + if (dm_pcs->type == 42) // Monolitihc scheme. for (i = 0; i < nnodesHQ; i++) { - NodalVal2[i] = dm_pcs->GetNodeValue(nodes[i],Idx_dm1[0]); - NodalVal3[i] = dm_pcs->GetNodeValue(nodes[i],Idx_dm1[1]); - if(dim == 3) // 3D. - NodalVal4[i] = dm_pcs->GetNodeValue(nodes[i],Idx_dm1[2]); + NodalVal2[i] = dm_pcs->GetNodeValue(nodes[i], Idx_dm1[0]); + NodalVal3[i] = dm_pcs->GetNodeValue(nodes[i], Idx_dm1[1]); + if (dim == 3) // 3D. + NodalVal4[i] = dm_pcs->GetNodeValue(nodes[i], Idx_dm1[2]); } else for (i = 0; i < nnodesHQ; i++) { - NodalVal2[i] = dm_pcs->GetNodeValue(nodes[i],Idx_dm1[0]) - - dm_pcs->GetNodeValue(nodes[i],Idx_dm0[0]); - NodalVal3[i] = dm_pcs->GetNodeValue(nodes[i],Idx_dm1[1]) - - dm_pcs->GetNodeValue(nodes[i],Idx_dm0[1]); - if(dim == 3) // 3D. - NodalVal4[i] = dm_pcs->GetNodeValue(nodes[i],Idx_dm1[2]) - - dm_pcs->GetNodeValue(nodes[i],Idx_dm0[2]); + NodalVal2[i] = dm_pcs->GetNodeValue(nodes[i], Idx_dm1[0]) - dm_pcs->GetNodeValue(nodes[i], Idx_dm0[0]); + NodalVal3[i] = dm_pcs->GetNodeValue(nodes[i], Idx_dm1[1]) - dm_pcs->GetNodeValue(nodes[i], Idx_dm0[1]); + if (dim == 3) // 3D. + NodalVal4[i] = dm_pcs->GetNodeValue(nodes[i], Idx_dm1[2]) - dm_pcs->GetNodeValue(nodes[i], Idx_dm0[2]); } //====================================================================== SetHighOrderNodes(); @@ -10798,47 +10617,46 @@ void CFiniteElementStd::Assemble_RHS_M() //--------------------------------------------------------- fkt = GetGaussData(gp, gp_r, gp_s, gp_t); // Compute geometry - ComputeShapefct(1); // Linear interpolation function - //ComputeShapefct(2); + ComputeShapefct(1); // Linear interpolation function + // ComputeShapefct(2); ComputeGradShapefct(2); grad_du = 0.0; - //axi + // axi for (i = 0; i < nnodesHQ; i++) { - grad_du += dshapefctHQ[i] * NodalVal2[i] + - dshapefctHQ[i + nnodesHQ] * NodalVal3[i]; - if(dim == 3) // 3D. + grad_du += dshapefctHQ[i] * NodalVal2[i] + dshapefctHQ[i + nnodesHQ] * NodalVal3[i]; + if (dim == 3) // 3D. grad_du += dshapefctHQ[i + nnodesHQ * 2] * NodalVal4[i]; } grad_du /= dt; - for(ii = 0; ii < dof_n; ii++) + for (ii = 0; ii < dof_n; ii++) { // Material fac = fkt * grad_du * CalCoef_RHS_M_MPhase(ii); - //WX:11.2012:biot coef. + // WX:11.2012:biot coef. fac *= SolidProp->biot_const; - // Calculate MHS +// Calculate MHS #if defined(USE_PETSC) //|| defined (other parallel solver) //WW 04.2014 - for (int ia = 0; ia < act_nodes; ia++) - { - const int i = local_idx[ia]; + for (int ia = 0; ia < act_nodes; ia++) + { + const int i = local_idx[ia]; #else - for (i = 0; i < nnodes; i++) - { + for (i = 0; i < nnodes; i++) + { #endif NodalVal[i + ii * nnodes] += fac * shapefct[i]; - } + } } } - // +// #if !defined(USE_PETSC) // && !defined(other parallel libs)//03~04.3012. WW int dm_shift = 0; - if(pcs->type / 10 == 4) + if (pcs->type / 10 == 4) dm_shift = problem_dimension_dm; #endif - for(ii = 0; ii < dof_n; ii++) + for (ii = 0; ii < dof_n; ii++) { int ii_sh = ii * nnodes; for (i = 0; i < nnodes; i++) @@ -10847,7 +10665,7 @@ void CFiniteElementStd::Assemble_RHS_M() int i_sh = NodeShift[ii + dm_shift]; eqs_rhs[i_sh + eqs_number[i]] -= NodalVal[i + ii_sh]; #endif - (*RHS)[i + LocalShift + ii_sh] -= NodalVal[i + ii_sh]; + (*RHS)[i + LocalShift + ii_sh] -= NodalVal[i + ii_sh]; } } setOrder(1); @@ -10863,17 +10681,17 @@ void CFiniteElementStd::Assemble_RHS_M() void CFiniteElementStd::Assemble_RHS_AIR_FLOW() { - int j, ii; //KR,idxd; + int j, ii; // KR,idxd; // ---- Gauss integral - int gp_r = 0,gp_s = 0,gp_t = 0; //KR ,z_sum; - double vel[3]; //KR,rhoz[3]; - double fkt, fac,mat_fac,fluid_density; - double dens_arg[3]; //08.05.2008 WW + int gp_r = 0, gp_s = 0, gp_t = 0; // KR ,z_sum; + double vel[3]; // KR,rhoz[3]; + double fkt, fac, mat_fac, fluid_density; + double dens_arg[3]; // 08.05.2008 WW double* tensor = NULL; - //KR CFEMesh* m_msh; - int GravityOn = 1; // Initialized to be on + // KR CFEMesh* m_msh; + int GravityOn = 1; // Initialized to be on // If no gravity, then set GravityOn to be zero. - if((coordinate_system) % 10 != 2 && (!axisymmetry)) + if ((coordinate_system) % 10 != 2 && (!axisymmetry)) GravityOn = 0; // Material int dof_n = 1; @@ -10890,11 +10708,11 @@ void CFiniteElementStd::Assemble_RHS_AIR_FLOW() //--------------------------------------------------------- fkt = GetGaussData(gp, gp_r, gp_s, gp_t); // Compute geometry - ComputeGradShapefct(1); // Linear interpolation function - ComputeShapefct(1); // Linear interpolation function + ComputeGradShapefct(1); // Linear interpolation function + ComputeShapefct(1); // Linear interpolation function ElementValue* gp_ele = ele_gp_value[Index]; - for(ii = 0; ii < dof_n; ii++) + for (ii = 0; ii < dof_n; ii++) { // Material fac = CalCoef_RHS_AIR_FLOW(ii) / dt; @@ -10904,10 +10722,10 @@ void CFiniteElementStd::Assemble_RHS_AIR_FLOW() } // grad T - for(ii = 0; ii < dof_n; ii++) + for (ii = 0; ii < dof_n; ii++) { fac = CalCoef_RHS_AIR_FLOW(ii + 1); - //Velocity + // Velocity vel[0] = fac * gp_ele->Velocity(0, gp); vel[1] = fac * gp_ele->Velocity(1, gp); vel[2] = fac * gp_ele->Velocity(2, gp); @@ -10915,14 +10733,12 @@ void CFiniteElementStd::Assemble_RHS_AIR_FLOW() for (int i = 0; i < nnodes; i++) for (j = 0; j < nnodes; j++) for (size_t k = 0; k < dim; k++) - NodalVal[i + ii * - nnodes] += fkt * shapefct[i] * vel[k] * - dshapefct[k * nnodes + j] * - (NodalValC1[j] + PhysicalConstant::CelsiusZeroInKelvin); + NodalVal[i + ii * nnodes] += fkt * shapefct[i] * vel[k] * dshapefct[k * nnodes + j] + * (NodalValC1[j] + PhysicalConstant::CelsiusZeroInKelvin); } - //Body force term - if(GravityOn) + // Body force term + if (GravityOn) { dens_arg[0] = interpolate(NodalVal1); dens_arg[1] = interpolate(NodalValC1) + PhysicalConstant::CelsiusZeroInKelvin; @@ -10930,17 +10746,18 @@ void CFiniteElementStd::Assemble_RHS_AIR_FLOW() fluid_density = FluidProp->Density(dens_arg); mat_fac = FluidProp->Viscosity(dens_arg); tensor = MediaProp->PermeabilityTensor(Index); - for(size_t i = 0; i < dim * dim; i++) + for (size_t i = 0; i < dim * dim; i++) mat[i] = tensor[i] / mat_fac; - for (ii = 0; ii < dof_n; ii++) { + for (ii = 0; ii < dof_n; ii++) + { for (int i = 0; i < nnodes; i++) for (size_t k = 0; k < dim; k++) - NodalVal[i + ii * nnodes] -= fkt * fluid_density * gravity_constant - * mat[dim * k + dim - 1] * dshapefct[k * nnodes + i]; + NodalVal[i + ii * nnodes] -= fkt * fluid_density * gravity_constant * mat[dim * k + dim - 1] + * dshapefct[k * nnodes + i]; } } } - for(ii = 0; ii < pcs->dof; ii++) + for (ii = 0; ii < pcs->dof; ii++) { int ii_sh = ii * nnodes; for (int i = 0; i < nnodes; i++) @@ -10949,12 +10766,11 @@ void CFiniteElementStd::Assemble_RHS_AIR_FLOW() int i_sh = NodeShift[ii]; eqs_rhs[i_sh + eqs_number[i]] -= NodalVal[i + ii_sh]; #endif - (*RHS)[i + LocalShift + ii_sh] -= NodalVal[i + ii_sh]; + (*RHS)[i + LocalShift + ii_sh] -= NodalVal[i + ii_sh]; } } } - /*************************************************************************** GeoSys - Funktion: Assemble_RHS_HEAT_TRANSPORT: This include when need pressure terms n dp/dt + nv.Nabla p @@ -10966,7 +10782,7 @@ void CFiniteElementStd::Assemble_RHS_HEAT_TRANSPORT() { int i, j, ii; // ---- Gauss integral - int gp_r = 0,gp_s = 0,gp_t = 0; + int gp_r = 0, gp_s = 0, gp_t = 0; double vel[3]; double fkt = 0.0, fac = 0.0; // Material @@ -10984,11 +10800,11 @@ void CFiniteElementStd::Assemble_RHS_HEAT_TRANSPORT() //--------------------------------------------------------- fkt = GetGaussData(gp, gp_r, gp_s, gp_t); // Compute geometry - ComputeGradShapefct(1); // Linear interpolation function - ComputeShapefct(1); // Linear interpolation function + ComputeGradShapefct(1); // Linear interpolation function + ComputeShapefct(1); // Linear interpolation function ElementValue* gp_ele = ele_gp_value[Index]; - for(ii = 0; ii < dof_n; ii++) + for (ii = 0; ii < dof_n; ii++) { // Material fac = CalCoef_RHS_HEAT_TRANSPORT(ii) / dt; @@ -10999,10 +10815,10 @@ void CFiniteElementStd::Assemble_RHS_HEAT_TRANSPORT() // grad P - for(ii = 0; ii < dof_n; ii++) + for (ii = 0; ii < dof_n; ii++) { fac = CalCoef_RHS_HEAT_TRANSPORT(ii + 1); - //Velocity + // Velocity vel[0] = fac * gp_ele->Velocity(0, gp); vel[1] = fac * gp_ele->Velocity(1, gp); vel[2] = fac * gp_ele->Velocity(2, gp); @@ -11010,13 +10826,11 @@ void CFiniteElementStd::Assemble_RHS_HEAT_TRANSPORT() for (i = 0; i < nnodes; i++) for (j = 0; j < nnodes; j++) for (size_t k = 0; k < dim; k++) - NodalVal[i + ii * - nnodes] += fkt * vel[k] * shapefct[i] * - dshapefct[k * nnodes + - j] * NodalValC1[j]; + NodalVal[i + ii * nnodes] + += fkt * vel[k] * shapefct[i] * dshapefct[k * nnodes + j] * NodalValC1[j]; } } - for(ii = 0; ii < pcs->dof; ii++) + for (ii = 0; ii < pcs->dof; ii++) { int ii_sh = ii * nnodes; for (i = 0; i < nnodes; i++) @@ -11025,7 +10839,7 @@ void CFiniteElementStd::Assemble_RHS_HEAT_TRANSPORT() int i_sh = NodeShift[ii]; eqs_rhs[i_sh + eqs_number[i]] -= NodalVal[i + ii_sh]; #endif - (*RHS)[i + LocalShift + ii_sh] -= NodalVal[i + ii_sh]; + (*RHS)[i + LocalShift + ii_sh] -= NodalVal[i + ii_sh]; } } } @@ -11042,10 +10856,10 @@ double CFiniteElementStd::CalCoef_RHS_HEAT_TRANSPORT2(int dof_index) // TF unused variable - comment fix compile warning // ElementValue* gp_ele = ele_gp_value[Index]; double* tensor = NULL; - double val = 0.0,mat_fac; + double val = 0.0, mat_fac; // TF unused variable - comment fix compile warning // double Tc=647.096; - double H_vap = 0.0,dens_arg[3]; + double H_vap = 0.0, dens_arg[3]; ComputeShapefct(1); PG = interpolate(NodalValC1); PG2 = interpolate(NodalVal_p2); @@ -11056,44 +10870,41 @@ double CFiniteElementStd::CalCoef_RHS_HEAT_TRANSPORT2(int dof_index) dens_arg[0] = PG2 - PG; rhow = FluidProp->Density(dens_arg); Sw = MediaProp->SaturationCapillaryPressureFunction(PG); - dSdp = MediaProp->PressureSaturationDependency(Sw,true); // JT: now returns correct sign. - poro = MediaProp->Porosity(Index,pcs->m_num->ls_theta); - if(MediaProp->evaporation == 647) - H_vap = -2257000; //pow((Tc - TG),0.38)*2.5397E+5;//It is specific you can change thi value as you chaning fluid from water + dSdp = MediaProp->PressureSaturationDependency(Sw, true); // JT: now returns correct sign. + poro = MediaProp->Porosity(Index, pcs->m_num->ls_theta); + if (MediaProp->evaporation == 647) + H_vap = -2257000; // pow((Tc - TG),0.38)*2.5397E+5;//It is specific you can change thi value as you chaning + // fluid from water for (size_t i = 0; i < dim * dim; i++) mat[i] = 0.0; - switch(dof_index) + switch (dof_index) { - case 0: - val = H_vap * rhow * poro * dSdp; - val *= (PG - PG0); - return val; - break; + case 0: + val = H_vap * rhow * poro * dSdp; + val *= (PG - PG0); + return val; + break; - case 1: - val = 0.0; - return val; - break; + case 1: + val = 0.0; + return val; + break; - case 2: - tensor = MediaProp->PermeabilityTensor(Index); - mat_fac = H_vap * rhow * - MediaProp->PermeabilitySaturationFunction(Sw,0) / FluidProp->Viscosity(); - for(size_t i = 0; i < dim * dim; i++) - mat[i] = tensor[i] * mat_fac * time_unit_factor; - break; + case 2: + tensor = MediaProp->PermeabilityTensor(Index); + mat_fac = H_vap * rhow * MediaProp->PermeabilitySaturationFunction(Sw, 0) / FluidProp->Viscosity(); + for (size_t i = 0; i < dim * dim; i++) + mat[i] = tensor[i] * mat_fac * time_unit_factor; + break; - case 3: - tensor = MediaProp->PermeabilityTensor(Index); - mat_fac = - -H_vap* rhow* MediaProp->PermeabilitySaturationFunction(Sw, - 0) / - FluidProp->Viscosity(); - for(size_t i = 0; i < dim * dim; i++) - mat[i] = tensor[i] * mat_fac * time_unit_factor; - break; + case 3: + tensor = MediaProp->PermeabilityTensor(Index); + mat_fac = -H_vap * rhow * MediaProp->PermeabilitySaturationFunction(Sw, 0) / FluidProp->Viscosity(); + for (size_t i = 0; i < dim * dim; i++) + mat[i] = tensor[i] * mat_fac * time_unit_factor; + break; } - return 0.; //WW + return 0.; // WW } /*************************************************************************** GeoSys - Funktion: @@ -11106,7 +10917,7 @@ void CFiniteElementStd::Assemble_RHS_HEAT_TRANSPORT2() { int i, j, ii; // ---- Gauss integral - int gp_r = 0,gp_s = 0,gp_t = 0; + int gp_r = 0, gp_s = 0, gp_t = 0; // TF unused variable - comment fix compile warning // double *tensor = NULL, double dens_arg[3]; @@ -11114,7 +10925,7 @@ void CFiniteElementStd::Assemble_RHS_HEAT_TRANSPORT2() // double H_vap=0; // TF unused variable - comment fix compile warning // double Tc=647.096; - double fkt = 0.0, fac = 0.0; //WW,mat_fac; + double fkt = 0.0, fac = 0.0; // WW,mat_fac; // Material int dof_n = 1; //---------------------------------------------------------------------- @@ -11130,14 +10941,14 @@ void CFiniteElementStd::Assemble_RHS_HEAT_TRANSPORT2() //--------------------------------------------------------- fkt = GetGaussData(gp, gp_r, gp_s, gp_t); // Compute geometry - ComputeGradShapefct(1); // Linear interpolation function - ComputeShapefct(1); // Linear interpolation function + ComputeGradShapefct(1); // Linear interpolation function + ComputeShapefct(1); // Linear interpolation function // TF unused variable - comment fix compile warning // ElementValue* gp_ele = ele_gp_value[Index]; int dof_n = 2; - int GravityOn = 1; // Initialized to be on + int GravityOn = 1; // Initialized to be on // If no gravity, then set GravityOn to be zero. - if((coordinate_system) % 10 != 2 && (!axisymmetry)) + if ((coordinate_system) % 10 != 2 && (!axisymmetry)) GravityOn = 0; TG = interpolate(NodalVal1) + PhysicalConstant::CelsiusZeroInKelvin; PG = interpolate(NodalValC1); @@ -11145,7 +10956,7 @@ void CFiniteElementStd::Assemble_RHS_HEAT_TRANSPORT2() dens_arg[1] = TG; dens_arg[0] = PG2 - PG; - for(ii = 0; ii < dof_n; ii++) + for (ii = 0; ii < dof_n; ii++) { // Material fac = fkt * CalCoef_RHS_HEAT_TRANSPORT2(ii) / dt; @@ -11155,52 +10966,40 @@ void CFiniteElementStd::Assemble_RHS_HEAT_TRANSPORT2() } // grad pc - for(ii = 0; ii < dof_n - 1; ii++) + for (ii = 0; ii < dof_n - 1; ii++) { // Material CalCoef_RHS_HEAT_TRANSPORT2(ii + dof_n); for (i = 0; i < nnodes; i++) for (j = 0; j < nnodes; j++) for (size_t k = 0; k < dim; k++) - NodalVal[i] += fkt * - mat[dim * k + - k] * - dshapefct[k * nnodes + - i] * - dshapefct[k * nnodes + - j] * NodalValC1[j]; + NodalVal[i] += fkt * mat[dim * k + k] * dshapefct[k * nnodes + i] * dshapefct[k * nnodes + j] + * NodalValC1[j]; } // grad pc - for(ii = 0; ii < dof_n - 1; ii++) + for (ii = 0; ii < dof_n - 1; ii++) { // Material CalCoef_RHS_HEAT_TRANSPORT2(ii + dof_n + 1); for (i = 0; i < nnodes; i++) for (j = 0; j < nnodes; j++) for (size_t k = 0; k < dim; k++) - NodalVal[i] += fkt * - mat[dim * k + - k] * - dshapefct[k * nnodes + - i] * - dshapefct[k * nnodes + - j] * NodalVal_p2[j]; + NodalVal[i] += fkt * mat[dim * k + k] * dshapefct[k * nnodes + i] * dshapefct[k * nnodes + j] + * NodalVal_p2[j]; } - //gravity - if(GravityOn) + // gravity + if (GravityOn) { CalCoef_RHS_HEAT_TRANSPORT2(2); for (i = 0; i < nnodes; i++) for (size_t k = 0; k < dim; k++) - NodalVal[i] -= fkt * - mat[dim * k + dim - - 1] * FluidProp->Density(dens_arg) * - gravity_constant * dshapefct[k * nnodes + i]; + NodalVal[i] -= fkt * mat[dim * k + dim - 1] * FluidProp->Density(dens_arg) * gravity_constant + * dshapefct[k * nnodes + i]; } } - for(ii = 0; ii < pcs->dof; ii++) + for (ii = 0; ii < pcs->dof; ii++) { int ii_sh = ii * nnodes; for (i = 0; i < nnodes; i++) @@ -11209,12 +11008,11 @@ void CFiniteElementStd::Assemble_RHS_HEAT_TRANSPORT2() int i_sh = NodeShift[ii]; eqs_rhs[i_sh + eqs_number[i]] -= NodalVal[i + ii_sh]; #endif - (*RHS)[i + LocalShift + ii_sh] -= NodalVal[i + ii_sh]; + (*RHS)[i + LocalShift + ii_sh] -= NodalVal[i + ii_sh]; } } } - /************************************************************************** FEMLib-Method: Task: Calculate coefficient of displacement induced RHS of multi-phase @@ -11230,43 +11028,43 @@ double CFiniteElementStd::CalCoef_RHS_M_MPhase(int dof_index) double expfactor = 0.0; double dens_aug[3]; dens_aug[1] = 293.15; - bool diffusion = false; //08.05.2008 WW - if(MediaProp->heat_diffusion_model == 1 && cpl_pcs) + bool diffusion = false; // 08.05.2008 WW + if (MediaProp->heat_diffusion_model == 1 && cpl_pcs) diffusion = true; //====================================================================== - switch(dof_index) + switch (dof_index) { - case 0: - PG = interpolate(NodalVal1); - PG2 = interpolate(NodalVal_p2); // JT - Sw = MediaProp->SaturationCapillaryPressureFunction(PG); - if(diffusion) - { - TG = interpolate(NodalValC1) + PhysicalConstant::CelsiusZeroInKelvin; - dens_aug[1] = TG; - } - // - dens_aug[0] = PG2 - PG; //JT: this was wrong. density argument is water pressure. - rhow = FluidProp->Density(dens_aug); - val = Sw; - // - dens_aug[0] = PG2; - // - if(diffusion) - { - expfactor = 1.0 / (rhow * SpecificGasConstant::WaterVapour * TG); - rho_gw = FluidProp->vaporDensity(TG) * exp(-PG * expfactor); - p_gw = rho_gw * SpecificGasConstant::WaterVapour * TG; - dens_aug[0] -= p_gw; - } - rho_ga = GasProp->Density(dens_aug); - if(diffusion) - val += (1.0 - Sw) * rho_gw / rhow; - break; - case 1: - val = (1.0 - Sw) * rho_ga / rhow; - break; - //------------------------------------------------------------------ + case 0: + PG = interpolate(NodalVal1); + PG2 = interpolate(NodalVal_p2); // JT + Sw = MediaProp->SaturationCapillaryPressureFunction(PG); + if (diffusion) + { + TG = interpolate(NodalValC1) + PhysicalConstant::CelsiusZeroInKelvin; + dens_aug[1] = TG; + } + // + dens_aug[0] = PG2 - PG; // JT: this was wrong. density argument is water pressure. + rhow = FluidProp->Density(dens_aug); + val = Sw; + // + dens_aug[0] = PG2; + // + if (diffusion) + { + expfactor = 1.0 / (rhow * SpecificGasConstant::WaterVapour * TG); + rho_gw = FluidProp->vaporDensity(TG) * exp(-PG * expfactor); + p_gw = rho_gw * SpecificGasConstant::WaterVapour * TG; + dens_aug[0] -= p_gw; + } + rho_ga = GasProp->Density(dens_aug); + if (diffusion) + val += (1.0 - Sw) * rho_gw / rhow; + break; + case 1: + val = (1.0 - Sw) * rho_ga / rhow; + break; + //------------------------------------------------------------------ } return val; } @@ -11286,108 +11084,108 @@ void CFiniteElementStd::AssembleRHSVector() int i; int idx_fv = 0, idx_pw = 0, idx_pc = 0; double NodalVal_FV[20]; - //OK411 double FV; + // OK411 double FV; CRFProcess* pcs_p = NULL; CRFProcess* pcs_s = NULL; //---------------------------------------------------------------------- // Initializations - for(i = 0; i < nnodes; i++) + for (i = 0; i < nnodes; i++) NodalVal[i] = 0.0; // TF fixed warning -Wunused-but-set-variable -// double temp[8]; + // double temp[8]; - switch(PcsType) + switch (PcsType) { - //.................................................................... - case EPT_TWOPHASE_FLOW: // Two-phase flow - if(pcs->PartialPS == 0) // If not partial-pressure-based - (*Laplace) = 0.0; - else - (*Mass) = 0.0; - break; - default: - break; //.................................................................... + case EPT_TWOPHASE_FLOW: // Two-phase flow + if (pcs->PartialPS == 0) // If not partial-pressure-based + (*Laplace) = 0.0; + else + (*Mass) = 0.0; + break; + default: + break; + //.................................................................... } //---------------------------------------------------------------------- // Field variables - switch(PcsType) + switch (PcsType) { - //.................................................................... - case EPT_TWOPHASE_FLOW: // Two-phase flow - if(pcs->PartialPS == 0) - { - pcs_p = pcs_vector[0]; - pcs_s = pcs_vector[1]; - - idx_pw = pcs_p->GetNodeValueIndex("PRESSURE1"); - idx_pc = pcs_p->GetNodeValueIndex("PRESSURE_CAP"); - idx_fv = pcs_s->GetNodeValueIndex("SATURATION2"); - //WW CMediumProperties *m_mmp = NULL; - //WW m_mmp = mmp_vector[0]; - for(i = 0; i < nnodes; i++) + //.................................................................... + case EPT_TWOPHASE_FLOW: // Two-phase flow + if (pcs->PartialPS == 0) { - Sw = 1.0 - pcs_s->GetNodeValue(nodes[i],idx_fv + 1); - double Pw = pcs_p->GetNodeValue(nodes[i],idx_pw + 1); - double Pc = pcs_p->GetNodeValue(nodes[i],idx_pc + 1); - if(pcs->ML_Cap == 0) // If ODE method for Snw, - NodalVal_FV[i] = -(Pw + Pc); - else // If PDE method, - NodalVal_FV[i] = -Pw; + pcs_p = pcs_vector[0]; + pcs_s = pcs_vector[1]; + + idx_pw = pcs_p->GetNodeValueIndex("PRESSURE1"); + idx_pc = pcs_p->GetNodeValueIndex("PRESSURE_CAP"); + idx_fv = pcs_s->GetNodeValueIndex("SATURATION2"); + // WW CMediumProperties *m_mmp = NULL; + // WW m_mmp = mmp_vector[0]; + for (i = 0; i < nnodes; i++) + { + Sw = 1.0 - pcs_s->GetNodeValue(nodes[i], idx_fv + 1); + double Pw = pcs_p->GetNodeValue(nodes[i], idx_pw + 1); + double Pc = pcs_p->GetNodeValue(nodes[i], idx_pc + 1); + if (pcs->ML_Cap == 0) // If ODE method for Snw, + NodalVal_FV[i] = -(Pw + Pc); + else // If PDE method, + NodalVal_FV[i] = -Pw; + } } - } - else - { - } - break; - default: - break; - //.................................................................... + else + { + } + break; + default: + break; + //.................................................................... } //---------------------------------------------------------------------- // Element matrices - switch(PcsType) + switch (PcsType) { - //.................................................................... - case EPT_TWOPHASE_FLOW: // Two-phase flow - if(pcs->PartialPS == 0) - CalcLaplace(); - else - CalcMass(); - break; - default: - break; //.................................................................... + case EPT_TWOPHASE_FLOW: // Two-phase flow + if (pcs->PartialPS == 0) + CalcLaplace(); + else + CalcMass(); + break; + default: + break; + //.................................................................... } //---------------------------------------------------------------------- // Calc RHS contribution - switch(PcsType) + switch (PcsType) { - //.................................................................... - case EPT_TWOPHASE_FLOW: // Two-phase flow - if(pcs->PartialPS == 0) - Laplace->multi(NodalVal_FV,NodalVal); - else - Mass->multi(NodalVal_FV,NodalVal); - break; - default: - break; //.................................................................... + case EPT_TWOPHASE_FLOW: // Two-phase flow + if (pcs->PartialPS == 0) + Laplace->multi(NodalVal_FV, NodalVal); + else + Mass->multi(NodalVal_FV, NodalVal); + break; + default: + break; + //.................................................................... } // TF fixed warning -Wunused-but-set-variable -// for(i=0;ieqs_new->b[NodeShift[problem_dimension_dm] + eqs_number[i]] += NodalVal[i]; #else @@ -11396,7 +11194,7 @@ void CFiniteElementStd::AssembleRHSVector() (*RHS)[i + LocalShift] += NodalVal[i]; } //---------------------------------------------------------------------- - //RHS->Write(); + // RHS->Write(); } /************************************************************************** @@ -11406,35 +11204,35 @@ void CFiniteElementStd::AssembleRHSVector() void CFiniteElementStd::AssembleCapillaryEffect() { int i; - int idx_pc = 0; //OK411 idx_w=0, idx_pw=0, idx_fv=0, idx_nw=0, + int idx_pc = 0; // OK411 idx_w=0, idx_pw=0, idx_fv=0, idx_nw=0, double NodalVal_FV[20]; - //OK411 double FV; - //OK411 CRFProcess* m_pcs_cpl = NULL; + // OK411 double FV; + // OK411 CRFProcess* m_pcs_cpl = NULL; CRFProcess* pcs_p = NULL; - //OK411 CRFProcess* pcs_s = NULL; - //OK411 CMediumProperties *m_mmp = NULL; + // OK411 CRFProcess* pcs_s = NULL; + // OK411 CMediumProperties *m_mmp = NULL; //---------------------------------------------------------------------- // Initializations - for(i = 0; i < nnodes; i++) + for (i = 0; i < nnodes; i++) NodalVal[i] = 0.0; // Setting the laplace matrix initialized (*Laplace) = 0.0; - if(pcs->pcs_type_number == 0) + if (pcs->pcs_type_number == 0) { pcs_p = pcs_vector[0]; idx_pc = pcs_p->GetNodeValueIndex("PRESSURE_CAP"); - for(i = 0; i < nnodes; i++) + for (i = 0; i < nnodes; i++) { - double Pc = pcs_p->GetNodeValue(nodes[i],idx_pc + 1); + double Pc = pcs_p->GetNodeValue(nodes[i], idx_pc + 1); NodalVal_FV[i] = -Pc; } } - else if(pcs->pcs_type_number == 1) + else if (pcs->pcs_type_number == 1) { } else @@ -11442,30 +11240,30 @@ void CFiniteElementStd::AssembleCapillaryEffect() //---------------------------------------------------------------------- // Element matrices and RHS calculation - if(pcs->pcs_type_number == 0) + if (pcs->pcs_type_number == 0) { // Laplace should be calculated according to the nonwetting phase // Then I need one switch to tell CalcCoefLaplace to use the nonwetting parameter only pcs->ML_Cap = 1; CalcLaplace(); - Laplace->multi(NodalVal_FV,NodalVal); + Laplace->multi(NodalVal_FV, NodalVal); pcs->ML_Cap = 0; } - else if(pcs->pcs_type_number == 1) + else if (pcs->pcs_type_number == 1) { CalcLaplace(); - Laplace->multi(NodalVal_FV,NodalVal); + Laplace->multi(NodalVal_FV, NodalVal); } else printf("Something's wrong!!!\n"); //---------------------------------------------------------------------- // Store RHS contribution - for(i = 0; i < nnodes; i++) + for (i = 0; i < nnodes; i++) { - //CB 04008 +// CB 04008 #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - //TODO +// TODO #elif defined(NEW_EQS) pcs->eqs_new->b[NodeShift[problem_dimension_dm] + eqs_number[i]] += NodalVal[i]; #else @@ -11474,7 +11272,7 @@ void CFiniteElementStd::AssembleCapillaryEffect() (*RHS)[i + LocalShift] += NodalVal[i]; } //---------------------------------------------------------------------- - //RHS->Write(); + // RHS->Write(); } #ifdef E_NORM @@ -11485,8 +11283,7 @@ void CFiniteElementStd::AssembleCapillaryEffect() 25.08.2008 WW Implementation last modification: **************************************************************************/ -void CFiniteElementStd::CalcEnergyNorm(double &err_norm0, - double &err_normn) +void CFiniteElementStd::CalcEnergyNorm(double& err_norm0, double& err_normn) { int i, dof_n = 1; // NUM @@ -11495,15 +11292,15 @@ void CFiniteElementStd::CalcEnergyNorm(double &err_norm0, // Config(); // - ::Problem *p_pnt = pcs->getProblemObjectPointer(); - double *x_n = p_pnt->GetBufferArray(); - double *x_k = p_pnt->GetBufferArray(true); + ::Problem* p_pnt = pcs->getProblemObjectPointer(); + double* x_n = p_pnt->GetBufferArray(); + double* x_k = p_pnt->GetBufferArray(true); // rtol = pcs->Tim->GetRTol(); atol = pcs->Tim->GetATol(); //_new - for(i = 0; i < pcs->dof; i++) + for (i = 0; i < pcs->dof; i++) NodeShift[i] = i * pcs->m_msh->GetNodesNumber(false); //---------------------------------------------------------------------- @@ -11511,7 +11308,7 @@ void CFiniteElementStd::CalcEnergyNorm(double &err_norm0, //---------------------------------------------------------------------- // Initialize. // if (pcs->Memory_Type==2) skip the these initialization - if(PcsType == V || PcsType == P) // 03.2009 PCH + if (PcsType == V || PcsType == P) // 03.2009 PCH (*Mass2) = 0.0; else (*Mass) = 0.0; @@ -11522,60 +11319,56 @@ void CFiniteElementStd::CalcEnergyNorm(double &err_norm0, //---------------------------------------------------------------------- // Calculate matrices // Mass matrix.......................................................... - if(PcsType == V) + if (PcsType == V) { - if(pcs->m_num->ele_mass_lumping) + if (pcs->m_num->ele_mass_lumping) CalcLumpedMass2(); else CalcMass2(); } - else if(PcsType == P) // 03.2009 PCH + else if (PcsType == P) // 03.2009 PCH { - if(pcs->m_num->ele_mass_lumping) + if (pcs->m_num->ele_mass_lumping) CalcLumpedMassPSGLOBAL(); else CalcMassPSGLOBAL(); } else { - if(pcs->m_num->ele_mass_lumping) + if (pcs->m_num->ele_mass_lumping) CalcLumpedMass(); else CalcMass(); } // Laplace matrix....................................................... CalcLaplace(); - if(PcsType == V || PcsType == P) // 03.2009 PCH + if (PcsType == V || PcsType == P) // 03.2009 PCH *AuxMatrix1 = *Mass2; else *AuxMatrix1 = *Mass; (*AuxMatrix1) *= 1.0 / dt; - //Laplace - Diffusion - *AuxMatrix1 += *Laplace; + // Laplace - Diffusion + *AuxMatrix1 += *Laplace; // int idx = idx1; - if(pcs->continuum == 1) + if (pcs->continuum == 1) idx = idxp21; - if(PcsType == V) // + if (PcsType == V) // dof_n = 2; //-------------------------------------------------------------- - //1. Error epsilon + // 1. Error epsilon for (i = 0; i < nnodes; i++) { #if defined(USE_PETSC) // || defined(other parallel libs)//03.3012. WW - NodalVal0[i] = - fabs(pcs->GetNodeValue(nodes[i], - idx) - x_k[nodes[i] * dof_n]); + NodalVal0[i] = fabs(pcs->GetNodeValue(nodes[i], idx) - x_k[nodes[i] * dof_n]); #else - NodalVal0[i] = - fabs(pcs->GetNodeValue(nodes[i], - idx) - x_k[nodes[i] + NodeShift[pcs->continuum]]); + NodalVal0[i] = fabs(pcs->GetNodeValue(nodes[i], idx) - x_k[nodes[i] + NodeShift[pcs->continuum]]); #endif NodalVal[i] = 0.0; } - if(PcsType == V) // + if (PcsType == V) // { // // _new for(i=0; ipcs_number_of_primary_nvals; i++) @@ -11583,22 +11376,15 @@ void CFiniteElementStd::CalcEnergyNorm(double &err_norm0, // for (i = 0; i < nnodes; i++) { - #if defined(USE_PETSC) // || defined(other parallel libs)//07.3012. WW - NodalVal0[i + - nnodes] = - fabs(pcs->GetNodeValue(nodes[i], - idxp21) - x_k[nodes[i] * dof_n +1]); + NodalVal0[i + nnodes] = fabs(pcs->GetNodeValue(nodes[i], idxp21) - x_k[nodes[i] * dof_n + 1]); #else - NodalVal0[i + - nnodes] = - fabs(pcs->GetNodeValue(nodes[i], - idxp21) - x_k[nodes[i] + NodeShift[1]]); + NodalVal0[i + nnodes] = fabs(pcs->GetNodeValue(nodes[i], idxp21) - x_k[nodes[i] + NodeShift[1]]); #endif NodalVal[i + nnodes] = 0.0; } } - else if(PcsType == P) + else if (PcsType == P) { // // _new for(i=0; ipcs_number_of_primary_nvals; i++) @@ -11607,15 +11393,9 @@ void CFiniteElementStd::CalcEnergyNorm(double &err_norm0, for (i = 0; i < nnodes; i++) { #if defined(USE_PETSC) // || defined(other parallel libs)//07.3012. WW - NodalVal0[i + - nnodes] = - fabs(pcs->GetNodeValue(nodes[i], - idxSn1) - x_k[nodes[i] * dof_n+1]); + NodalVal0[i + nnodes] = fabs(pcs->GetNodeValue(nodes[i], idxSn1) - x_k[nodes[i] * dof_n + 1]); #else - NodalVal0[i + - nnodes] = - fabs(pcs->GetNodeValue(nodes[i], - idxSn1) - x_k[nodes[i] + NodeShift[1]]); + NodalVal0[i + nnodes] = fabs(pcs->GetNodeValue(nodes[i], idxSn1) - x_k[nodes[i] + NodeShift[1]]); #endif NodalVal[i + nnodes] = 0.0; } @@ -11628,45 +11408,41 @@ void CFiniteElementStd::CalcEnergyNorm(double &err_norm0, err_norm0 += NodalVal0[i] * NodalVal[i]; // //-------------------------------------------------------------- - //2. Error e_n + // 2. Error e_n for (i = 0; i < nnodes; i++) { #if defined(USE_PETSC) // || defined(other parallel libs)//07.3012. WW - NodalVal0[i] = atol + rtol* max(fabs(pcs->GetNodeValue(nodes[i],idx)),fabs( - x_n[nodes[i] * dof_n])); + NodalVal0[i] = atol + rtol * max(fabs(pcs->GetNodeValue(nodes[i], idx)), fabs(x_n[nodes[i] * dof_n])); #else - NodalVal0[i] = atol + rtol* max(fabs(pcs->GetNodeValue(nodes[i],idx)),fabs( - x_n[nodes[i] + NodeShift[pcs->continuum]])); + NodalVal0[i] + = atol + + rtol * max(fabs(pcs->GetNodeValue(nodes[i], idx)), fabs(x_n[nodes[i] + NodeShift[pcs->continuum]])); #endif NodalVal[i] = 0.0; } - if(PcsType == V) // + if (PcsType == V) // for (i = 0; i < nnodes; i++) { #if defined(USE_PETSC) // || defined(other parallel libs)//07.3012. WW - NodalVal0[i + nnodes] = atol + rtol* max(fabs(pcs->GetNodeValue(nodes[i], - idxp21)), - fabs(x_n[nodes[i] * dof_n +1])); + NodalVal0[i + nnodes] + = atol + rtol * max(fabs(pcs->GetNodeValue(nodes[i], idxp21)), fabs(x_n[nodes[i] * dof_n + 1])); #else - NodalVal0[i + nnodes] = atol + rtol* max(fabs(pcs->GetNodeValue(nodes[i], - idxp21)), - fabs(x_n[nodes[i] + NodeShift[1]])); + NodalVal0[i + nnodes] + = atol + rtol * max(fabs(pcs->GetNodeValue(nodes[i], idxp21)), fabs(x_n[nodes[i] + NodeShift[1]])); #endif NodalVal[i + nnodes] = 0.0; } - else if(PcsType == P) // 03.2009 PCH + else if (PcsType == P) // 03.2009 PCH for (i = 0; i < nnodes; i++) { #if defined(USE_PETSC) // || defined(other parallel libs)//07.3012. WW - NodalVal0[i + nnodes] = atol + rtol* max(fabs(pcs->GetNodeValue(nodes[i], - idxSn1)), - fabs(x_n[nodes[i] * dof_n + 1])); + NodalVal0[i + nnodes] + = atol + rtol * max(fabs(pcs->GetNodeValue(nodes[i], idxSn1)), fabs(x_n[nodes[i] * dof_n + 1])); #else - NodalVal0[i + nnodes] = atol + rtol* max(fabs(pcs->GetNodeValue(nodes[i], - idxSn1)), - fabs(x_n[nodes[i] + NodeShift[1]])); + NodalVal0[i + nnodes] + = atol + rtol * max(fabs(pcs->GetNodeValue(nodes[i], idxSn1)), fabs(x_n[nodes[i] + NodeShift[1]])); #endif NodalVal[i + nnodes] = 0.0; } @@ -11688,28 +11464,27 @@ void CFiniteElementStd::CalcEnergyNorm(double &err_norm0, 25.09.2008 WW Implementation last modification: **************************************************************************/ -void CFiniteElementStd::CalcEnergyNorm_Dual(double &err_norm0, - double &err_normn) +void CFiniteElementStd::CalcEnergyNorm_Dual(double& err_norm0, double& err_normn) { double rtol, atol; - ::Problem *p_pnt = pcs->getProblemObjectPointer(); - double *x_n = p_pnt->GetBufferArray(); - double *x_k = p_pnt->GetBufferArray(true); + ::Problem* p_pnt = pcs->getProblemObjectPointer(); + double* x_n = p_pnt->GetBufferArray(); + double* x_k = p_pnt->GetBufferArray(true); //---------------------------------------------------------------------- // // rtol = pcs->Tim->GetRTol(); atol = pcs->Tim->GetATol(); // - int i,j; + int i, j; int gp_r = 0, gp_s = 0, gp_t = 0; - double W, fkt,mat_fac = 0.; + double W, fkt, mat_fac = 0.; - //Inintialize + // Inintialize //-------------------------- WW W = pcs->continuum_vector[pcs->GetContinnumType()]; // - for(i = 0; i < nnodes; i++) + for (i = 0; i < nnodes; i++) { // Pressure 1 NodalVal3[i] = pcs->GetNodeValue(nodes[i], idx1); @@ -11728,26 +11503,25 @@ void CFiniteElementStd::CalcEnergyNorm_Dual(double &err_norm0, mat_fac = CalcCoefDualTransfer(); mat_fac *= fkt; // Material - ComputeShapefct(1); // Linear interpolation function + ComputeShapefct(1); // Linear interpolation function // Calculate mass matrix for (i = 0; i < nnodes; i++) for (j = 0; j < nnodes; j++) - (*Advection)(i,j) += mat_fac * shapefct[i] * shapefct[j]; + (*Advection)(i, j) += mat_fac * shapefct[i] * shapefct[j]; } // Add local matrix to global matrix long cshift = pcs->m_msh->GetNodesNumber(false); // double fm = 1.0 / W; double ff = 1.0 / (1.0 - W); - if(MediaProp->transfer_coefficient < 0.0) // for LBNL + if (MediaProp->transfer_coefficient < 0.0) // for LBNL ff = 1.0; // //-------------------------------------------------------------- - //1. Error epsilon + // 1. Error epsilon for (i = 0; i < nnodes; i++) { - NodalVal0[i] = fabs(NodalVal3[i] - x_k[nodes[i]]) - - fabs(NodalVal4[i] - x_k[nodes[i] + cshift]); + NodalVal0[i] = fabs(NodalVal3[i] - x_k[nodes[i]]) - fabs(NodalVal4[i] - x_k[nodes[i] + cshift]); NodalVal[i] = 0.0; } // @@ -11756,23 +11530,20 @@ void CFiniteElementStd::CalcEnergyNorm_Dual(double &err_norm0, // Error epsilon for (i = 0; i < nnodes; i++) - err_norm0 += (fm * (NodalVal3[i] - x_k[nodes[i]]) - - ff * (NodalVal4[i] - x_k[nodes[i] + cshift])) - * NodalVal[i]; + err_norm0 += (fm * (NodalVal3[i] - x_k[nodes[i]]) - ff * (NodalVal4[i] - x_k[nodes[i] + cshift])) * NodalVal[i]; // //-------------------------------------------------------------- - //2. Error e_n + // 2. Error e_n for (i = 0; i < nnodes; i++) { - NodalVal0[i] = max(NodalVal3[i],x_k[nodes[i]]) - - max(NodalVal4[i],x_k[nodes[i] + cshift]); + NodalVal0[i] = max(NodalVal3[i], x_k[nodes[i]]) - max(NodalVal4[i], x_k[nodes[i] + cshift]); NodalVal[i] = 0.0; } // AuxMatrix1->multi(NodalVal0, NodalVal); for (i = 0; i < nnodes; i++) - err_normn += (fm * (atol + rtol * max(NodalVal3[i],x_n[nodes[i]])) - - ff * (atol + rtol * max(NodalVal4[i],x_n[nodes[i] + cshift]))) + err_normn += (fm * (atol + rtol * max(NodalVal3[i], x_n[nodes[i]])) + - ff * (atol + rtol * max(NodalVal4[i], x_n[nodes[i] + cshift]))) * NodalVal[i]; // // @@ -11785,65 +11556,70 @@ void CFiniteElementStd::CalcEnergyNorm_Dual(double &err_norm0, void CFiniteElementStd::PrintTheSetOfElementMatrices(std::string mark) { // Output matrices - if(pcs->Write_Matrix) + if (pcs->Write_Matrix) { (*pcs->matrix_file) << "### Mark: " << mark << "\n"; (*pcs->matrix_file) << "### Element: " << Index << "\n"; - (*pcs->matrix_file) << "---Mass matrix: " << "\n"; - if(Mass) + (*pcs->matrix_file) << "---Mass matrix: " + << "\n"; + if (Mass) Mass->Write(*pcs->matrix_file); - else if(Mass2) + else if (Mass2) Mass2->Write(*pcs->matrix_file); - (*pcs->matrix_file) << "---Laplacian matrix: " << "\n"; + (*pcs->matrix_file) << "---Laplacian matrix: " + << "\n"; Laplace->Write(*pcs->matrix_file); - (*pcs->matrix_file) << "---AuxMatrix1 matrix: " << "\n"; + (*pcs->matrix_file) << "---AuxMatrix1 matrix: " + << "\n"; AuxMatrix1->Write(*pcs->matrix_file); // PCH for debug - if(Advection) + if (Advection) { - //CMCD - (*pcs->matrix_file) << "---Advective matrix: " << "\n"; + // CMCD + (*pcs->matrix_file) << "---Advective matrix: " + << "\n"; Advection->Write(*pcs->matrix_file); } - if(StrainCoupling) + if (StrainCoupling) { - (*pcs->matrix_file) << "---Strain couping matrix: " << "\n"; + (*pcs->matrix_file) << "---Strain couping matrix: " + << "\n"; StrainCoupling->Write(*pcs->matrix_file); } - (*pcs->matrix_file) << "---RHS: " << "\n"; + (*pcs->matrix_file) << "---RHS: " + << "\n"; RHS->Write(*pcs->matrix_file); (*pcs->matrix_file) << "\n"; - (*pcs->matrix_file) << "Stiffness: " << "\n"; + (*pcs->matrix_file) << "Stiffness: " + << "\n"; StiffMatrix->Write(*pcs->matrix_file); (*pcs->matrix_file) << "\n"; } } -//CB _ctx_ CB_merge_0513 +// CB _ctx_ CB_merge_0513 /*void CFiniteElementStd::Set_ctx_(long ele_index, double val, int gaussp, int i_dim){ - ElementValue* gp_ele = ele_gp_value[Index]; - //cout << " Index in SetElectricField: " << this->GetElementIndex() << "\n"; - if(this->GetElementIndex() != ele_index) cout << "\n" << " Warning! Element Index does not fit! " << "\n"; + ElementValue* gp_ele = ele_gp_value[Index]; + //cout << " Index in SetElectricField: " << this->GetElementIndex() << "\n"; + if(this->GetElementIndex() != ele_index) cout << "\n" << " Warning! Element Index does not fit! " << "\n"; - gp_ele->_ctx_Gauss(i_dim,gaussp) = val; + gp_ele->_ctx_Gauss(i_dim,gaussp) = val; } double CFiniteElementStd::Get_ctx_(long ele_index, int gaussp, int i_dim){ - double val=0.0; - ElementValue* gp_ele = ele_gp_value[Index]; - //cout << " Index in GetElectricField: " << this->GetElementIndex() << "\n"; - if(this->GetElementIndex() != ele_index) cout << "\n" << " Warning! Element Index does not fit! " << "\n"; - val = gp_ele->_ctx_Gauss(i_dim, gaussp); - return val; + double val=0.0; + ElementValue* gp_ele = ele_gp_value[Index]; + //cout << " Index in GetElectricField: " << this->GetElementIndex() << "\n"; + if(this->GetElementIndex() != ele_index) cout << "\n" << " Warning! Element Index does not fit! " << "\n"; + val = gp_ele->_ctx_Gauss(i_dim, gaussp); + return val; }*/ - - -} // end namespace +} // end namespace ////////////////////////////////////////////////////////////////////////// diff --git a/FEM/fem_ele_std.h b/FEM/fem_ele_std.h index 0e79b59d2..3bbf3ec10 100644 --- a/FEM/fem_ele_std.h +++ b/FEM/fem_ele_std.h @@ -25,36 +25,53 @@ // Problems #include "rf_mfp_new.h" //#include "rf_msp_new.h" -#include "rf_out_new.h" //OK +#include "rf_out_new.h" //OK #include "Eigen/Eigen" //----------------------------------------------------- // Process type -//L: Liquid flow -//U: Unconfined flow -//G: Groundwater flow -//T: Two-phase flow -//C: Componental flow -//H: heat transport -//M: Mass transport -//O: Overland flow -//R: Richards flow -//F: Fluid momentum -//A: Gas flow -//N: Thermal nonequilibrium -enum EnumProcessType { EPT_LIQUID_FLOW, EPT_UNCONFINED_FLOW, EPT_GROUNDWATER_FLOW, EPT_TWOPHASE_FLOW, EPT_COMPONENTAL_FLOW, - EPT_HEAT_TRANSPORT, EPT_MASS_TRANSPORT, EPT_OVERLAND_FLOW, EPT_RICHARDS_FLOW, EPT_FLUID_MOMENTUM, - EPT_GAS_FLOW, EPT_MULTIPHASE_FLOW, EPT_PSGLOBAL, EPT_MULTI_COMPONENTIAL_FLOW, - EPT_THERMAL_NONEQUILIBRIUM, EPT_TES }; +// L: Liquid flow +// U: Unconfined flow +// G: Groundwater flow +// T: Two-phase flow +// C: Componental flow +// H: heat transport +// M: Mass transport +// O: Overland flow +// R: Richards flow +// F: Fluid momentum +// A: Gas flow +// N: Thermal nonequilibrium +enum EnumProcessType +{ + EPT_LIQUID_FLOW, + EPT_UNCONFINED_FLOW, + EPT_GROUNDWATER_FLOW, + EPT_TWOPHASE_FLOW, + EPT_COMPONENTAL_FLOW, + EPT_HEAT_TRANSPORT, + EPT_MASS_TRANSPORT, + EPT_OVERLAND_FLOW, + EPT_RICHARDS_FLOW, + EPT_FLUID_MOMENTUM, + EPT_GAS_FLOW, + EPT_MULTIPHASE_FLOW, + EPT_PSGLOBAL, + EPT_MULTI_COMPONENTIAL_FLOW, + EPT_THERMAL_NONEQUILIBRIUM, + EPT_TES +}; //----------------------------------------------------- namespace process -{class CRFProcessDeformation; +{ +class CRFProcessDeformation; } // using SolidProp::CSolidProperties; // evil in header! namespace SolidProp -{ class CSolidProperties; +{ +class CSolidProperties; } // Predeclared classes 01/07, WW class CMediumProperties; @@ -90,19 +107,19 @@ class CFiniteElementStd : public CElement // 1. Mass matrix void CalcMass(); void CalcMass2(); - void CalcMassMCF(); //AKS/NB - void CalcMassTNEQ(); //AKS/NB - void CalcMassTES(); //AKS/NB - void CalcMassPSGLOBAL(); // PCH + void CalcMassMCF(); // AKS/NB + void CalcMassTNEQ(); // AKS/NB + void CalcMassTES(); // AKS/NB + void CalcMassPSGLOBAL(); // PCH // 2. Lumped mass matrix void CalcLumpedMass(); void CalcLumpedMass2(); void CalcLumpedMassTES(); - void CalcLumpedMassMCF(); //AKS - void CalcLumpedMassPSGLOBAL(); // PCH + void CalcLumpedMassMCF(); // AKS + void CalcLumpedMassPSGLOBAL(); // PCH // 3. Laplace matrix void CalcLaplace(); - void CalcLaplaceMCF();//AKS + void CalcLaplaceMCF(); // AKS // 4. Gravity term void CalcGravity(); // 5. Strain coupling matrix @@ -118,41 +135,41 @@ class CFiniteElementStd : public CElement void CalcStorage(); // 9. Content matrix void CalcContent(); - void CalcContentTNEQ(); //NW - void CalcContentTES(); //NW - // - void CalcSatution(); //WW + void CalcContentTNEQ(); // NW + void CalcContentTES(); // NW // + void CalcSatution(); // WW +// #ifdef E_NORM - //25.08.2008. WW - void CalcEnergyNorm(double &err_norm0, double &err_normn); - //25.09.2008. WW - void CalcEnergyNorm_Dual(double &err_norm0, double &err_normn); - // + // 25.08.2008. WW + void CalcEnergyNorm(double& err_norm0, double& err_normn); + // 25.09.2008. WW + void CalcEnergyNorm_Dual(double& err_norm0, double& err_normn); +// #endif - void CalcNodeMatParatemer(); //WW + void CalcNodeMatParatemer(); // WW // Assembly void Assembly(); void Assembly(int option, int dimension); // PCH for Fluid Momentum void Cal_Velocity(); - void CalcSolidDensityRate(); //HS thermal storage application, calculate rho_s - void Cal_VelocityMCF();//AKS - void Cal_Velocity_2(); //CB this is to provide velocity only at the element center of gravity - void Cal_GP_Velocity_FM(int* i_ind); //SB 4900 interpolate node velocities to Gauss point velocities - //BG + void CalcSolidDensityRate(); // HS thermal storage application, calculate rho_s + void Cal_VelocityMCF(); // AKS + void Cal_Velocity_2(); // CB this is to provide velocity only at the element center of gravity + void Cal_GP_Velocity_FM(int* i_ind); // SB 4900 interpolate node velocities to Gauss point velocities + // BG std::string Cal_GP_Velocity_ECLIPSE(std::string tempstring, bool output_average, int phase_index, std::string phase); - //BG coupling to DuMux + // BG coupling to DuMux std::string Cal_GP_Velocity_DuMux(int* i_ind, CRFProcess* m_pcs, int phase_index); // BG, 04/2012: Provides the average element velocity over all gauss points double Get_Element_Velocity(int Index, CRFProcess* m_pcs, int phase_index, int dimension); // necessary for using precalculated density and viscosity BG, 11/2010 double InterpolatePropertyToGausspoint(int GPIndex, CRFProcess* m_pcs, int Variableindex); // - //OK + // OK void AssembleParabolicEquationRHSVector(); // CVFEM functions for overland flow JOD @@ -161,20 +178,15 @@ class CFiniteElementStd : public CElement // to move void GetOverlandBasisFunctionMatrix_Quad(); void CalcOverlandCoefficients(double* head, double* axx, double* ayy, double* ast); - void CalcOverlandCoefficientsLine(double* head, double* axx, double* ast ); - void CalcOverlandCoefficientsQuad(double* head, double* axx, double* ayy, double* ast ); - void CalcOverlandCoefficientsTri(double* head, double* axx, double* ayy, double* ast ); + void CalcOverlandCoefficientsLine(double* head, double* axx, double* ast); + void CalcOverlandCoefficientsQuad(double* head, double* axx, double* ayy, double* ast); + void CalcOverlandCoefficientsTri(double* head, double* axx, double* ayy, double* ast); void CalcOverlandNLTERMS(double* H, double* HaaOld, double* swval, double* swold); void CalcOverlandNLTERMSRills(double* H, double* HaaOld, double* swval, double* swold); void CalcOverlandNLTERMSChannel(double* H, double* HaaOld, double* swval, double* swold); void CalcOverlandCKWR(double* head, double* ckwr, int* iups); void CalcOverlandCKWRatNodes(int i, int j, double* head, double* ckwr, int* iups); - void CalcOverlandResidual(double* head, - double* swval, - double* swold, - double ast, - double* residuall, - double** amat); + void CalcOverlandResidual(double* head, double* swval, double* swold, double ast, double* residuall, double** amat); double CalcOverlandJacobiNodes(int i, int j, double* depth, @@ -186,55 +198,50 @@ class CFiniteElementStd : public CElement double* sumjac); void CalcOverlandUpwindedCoefficients(double** amat, double* ckwr, double axx, double ayy); // - //CB added by CB: 090507 + // CB added by CB: 090507 void UpwindAlphaMass(double* alpha); - //CB added by CB: 090507 + // CB added by CB: 090507 void UpwindUnitCoord(int p, int point, int ind); int UpwindElement(int option, int phase); // PCH - //CB added by CB: 090507 - void UpwindSummandMass(const int gp, - int& gp_r, - int& gp_s, - int& gp_t, - double* alpha, - double* summand); - //NW - double CalcSUPGCoefficient(double* vel,int ip); - //NW - void CalcSUPGWeightingFunction(double* vel, int ip, double &tau, double* v_dN); - //NW + // CB added by CB: 090507 + void UpwindSummandMass(const int gp, int& gp_r, int& gp_s, int& gp_t, double* alpha, double* summand); + // NW + double CalcSUPGCoefficient(double* vel, int ip); + // NW + void CalcSUPGWeightingFunction(double* vel, int ip, double& tau, double* v_dN); + // NW double CalcSUPGEffectiveElemenetLength(double* vel); // Gauss value void ExtropolateGauss(CRFProcess* m_pcs, const int idof); // Extrapolate reaction rates on TNEQ flow - void ExtrapolateGauss_ReactRate_TNEQ_TES(CRFProcess *m_pcs); - void UpdateSolidDensity(size_t elem_idx); // HS + void ExtrapolateGauss_ReactRate_TNEQ_TES(CRFProcess* m_pcs); + void UpdateSolidDensity(size_t elem_idx); // HS // CB _ctx_ CB_merge_0513 - //void Set_ctx_(long ele_index, double val, int gaussp, int i_dim); - //double Get_ctx_(long ele_index, int gaussp, int i_dim); + // void Set_ctx_(long ele_index, double val, int gaussp, int i_dim); + // double Get_ctx_(long ele_index, int gaussp, int i_dim); private: - bool newton_raphson; //24.05.2007 WW + bool newton_raphson; // 24.05.2007 WW long index; - int dof_index; //24.02.2007 WW + int dof_index; // 24.02.2007 WW // Column index in the node value table int idx0, idx1, idxS, idxSn0, idxSn1, idx3, idxMCF[12]; - int idx_t2_0, idx_t2_1, idx_x0, idx_x1; - int idxp0,idxp1, idxp20, idxp21, idxt0, idxt1; + int idx_t2_0, idx_t2_1, idx_x0, idx_x1; + int idxp0, idxp1, idxp20, idxp21, idxt0, idxt1; int phase; - int comp; // Component - int LocalShift; // For RHS + int comp; // Component + int LocalShift; // For RHS // Danymic - int* idx_vel_disp, idx_pres; + int *idx_vel_disp, idx_pres; // Velocity - int* idx_vel; //WW + int* idx_vel; // WW // Material properties double* mat; double MassMatrixElements[36]; double AdvectionMatrixElements[36]; double ContentMatrixElements[36]; double LaplaceMatrixElements[36][9]; - double* eqs_rhs; //For DDC WW + double* eqs_rhs; // For DDC WW bool heat_phase_change; // /** @@ -248,46 +255,46 @@ class CFiniteElementStd : public CElement CFluidProperties* FluidProp; CFluidProperties* GasProp; CMediumProperties* MediaProp; - CMediumProperties* MediaProp1; // Matrix for the dual model. YD/WW - SolidProp::CSolidProperties* SolidProp1; // Matrix for the dual model. YD/WW + CMediumProperties* MediaProp1; // Matrix for the dual model. YD/WW + SolidProp::CSolidProperties* SolidProp1; // Matrix for the dual model. YD/WW CRFProcess* pcs; - ::CRFProcess* cpl_pcs; // Pointer to coupled process. WW + ::CRFProcess* cpl_pcs; // Pointer to coupled process. WW process::CRFProcessDeformation* dm_pcs; - bool flag_cpl_pcs; //OK + bool flag_cpl_pcs; // OK //------------------------------------------------------- // Auxillarary matrices Matrix* StiffMatrix; Matrix* AuxMatrix; Matrix* AuxMatrix1; // Gravity matrix; - //25.2.2007.WW SymMatrix *GravityMatrix; + // 25.2.2007.WW SymMatrix *GravityMatrix; // Gauss point value. Buffers. // Some changes. 27.2.2007 WW - double TG, TG0, PG, PG0, PG2,PG20, drho_gw_dT; + double TG, TG0, PG, PG0, PG2, PG20, drho_gw_dT; double Sw, rhow, poro, dSdp; double rho_gw, rho_ga, rho_g, p_gw, M_g, tort, Xw, eos_arg[5], heat_capacity, heat_conductivity, viscosity; - // - double* edlluse; // WW edlluse[16] - double* edttuse; // WW edlluse[16] + double* edlluse; // WW edlluse[16] + double* edttuse; // WW edlluse[16] // Local matrices - Matrix* Mass; //CB symMatrix *Mass; // unsymmetric in case of upwinding + Matrix* Mass; // CB symMatrix *Mass; // unsymmetric in case of upwinding Matrix* Mass2; Matrix* Laplace; - Matrix* Advection; //SB4200 - Matrix* Storage; //SB4200 - Matrix* Content; //SB4209 + Matrix* Advection; // SB4200 + Matrix* Storage; // SB4200 + Matrix* Content; // SB4209 Matrix* StrainCoupling; Vec* RHS; - DiagonalMatrix* FCT_MassL; //NW + DiagonalMatrix* FCT_MassL; // NW //------------------------------------------------------- - void SetHighOrderNodes(); // 25.2.2007 WW + void SetHighOrderNodes(); // 25.2.2007 WW // Primary as water head bool HEAD_Flag; // public: void Config(); + protected: // double CalCoefMass(); @@ -303,8 +310,8 @@ class CFiniteElementStd : public CElement void CalCoefLaplaceTNEQ(const int dof_index); void CalCoefLaplaceTES(const int dof_index); void CalCoefLaplacePSGLOBAL(bool Gravity, int dof_index); - double CalCoefAdvection(); //SB4200 OK/CMCD - //AKS/NB + double CalCoefAdvection(); // SB4200 OK/CMCD + // AKS/NB double CalCoefAdvectionTNEQ(const int dof_index); double CalCoefAdvectionTES(const int dof_index); @@ -316,13 +323,13 @@ class CFiniteElementStd : public CElement void CalcContentMCF(); void CalCoefContentMCF(); - double CalCoefStorage(); //SB4200 + double CalCoefStorage(); // SB4200 double CalCoefContent(); - double CalCoefContentTNEQ(const int dof_index); //NW + double CalCoefContentTNEQ(const int dof_index); // NW double CalCoefContentTES(const int dof_index); double CalCoefStrainCouping(const int phase = 0); - double CalcCoefDualTransfer(); + double CalcCoefDualTransfer(); // 27.2.2007 WW double CalCoef_RHS_T_MPhase(int dof_index); double CalCoef_RHS_TNEQ(const int dof_index); @@ -334,36 +341,36 @@ class CFiniteElementStd : public CElement double CalCoef_RHS_T_PSGlobal(int dof_index); // 03.2007 PCH void CalCoef_RHS_Pc(int dof_index); - //AKS + // AKS double CalCoef_RHS_AIR_FLOW(int dof_index); - //AKS + // AKS double CalCoef_RHS_HEAT_TRANSPORT(int dof_index); - //AKS + // AKS double CalCoef_RHS_HEAT_TRANSPORT2(int dof_index); void CalNodalEnthalpy(); - void ComputeAdditionalJacobi_H2(); //WW - void ComputeAdditionalJacobi_Richards(); //WW + void ComputeAdditionalJacobi_H2(); // WW + void ComputeAdditionalJacobi_Richards(); // WW //----------------------------------------------------- // Process type - //L: Liquid flow - //U: Unconfined flow - //G: Groundwater flow - //T: Two-phase flow - //C: Componental flow - //H: heat transport - //M: Mass transport - //O: Liquid flow - //R: Richards flow - //A: Gas flow - //F: Fluid Momentum - //N: Thermal nonequilibrium + // L: Liquid flow + // U: Unconfined flow + // G: Groundwater flow + // T: Two-phase flow + // C: Componental flow + // H: heat transport + // M: Mass transport + // O: Liquid flow + // R: Richards flow + // A: Gas flow + // F: Fluid Momentum + // N: Thermal nonequilibrium EnumProcessType PcsType; //----------------------------------------------------- // Local Assembly // Assembly of parabolic equation - void AssembleParabolicEquation(); //OK4104 + void AssembleParabolicEquation(); // OK4104 void AssembleMixedHyperbolicParabolicEquation(); void AssembleParabolicEquationNewton(); // JOD @@ -377,36 +384,36 @@ class CFiniteElementStd : public CElement double* swold, double* residuall, int* iups); - void Assemble_strainCPL(const int phase = 0); // Assembly of strain coupling + void Assemble_strainCPL(const int phase = 0); // Assembly of strain coupling void Assemble_strainCPL_Matrix(const double fac, const int phase = 0); - void AssembleMassMatrix(int option); // PCH + void AssembleMassMatrix(int option); // PCH // Assembly of RHS by Darcy's gravity term void Assemble_Gravity(); - void Assemble_GravityMCF();//AKS + void Assemble_GravityMCF(); // AKS void Assemble_Gravity_Multiphase(); // Assembly of RHS by temperature for m-phase flow 27.2.2007 WW void Assemble_RHS_T_MPhaseFlow(); // Assembly of RHS by deformation. 27.2.2007 WW void Assemble_RHS_M(); - void Assemble_RHS_Pc(); // 03.2009 PCH - void Assemble_RHS_AIR_FLOW(); //AKS - void Assemble_RHS_HEAT_TRANSPORT(); //AKS - void Assemble_RHS_TNEQ(); //AKS - void Assemble_RHS_TES(); //AKS - void Assemble_RHS_HEAT_TRANSPORT2(); //AKS - void Assemble_RHS_T_PSGlobal(); // Assembly of RHS by temperature for PSGlobal - void AssembleRHS(int dimension); // PCH - void Assemble_RHS_LIQUIDFLOW(); //NW + void Assemble_RHS_Pc(); // 03.2009 PCH + void Assemble_RHS_AIR_FLOW(); // AKS + void Assemble_RHS_HEAT_TRANSPORT(); // AKS + void Assemble_RHS_TNEQ(); // AKS + void Assemble_RHS_TES(); // AKS + void Assemble_RHS_HEAT_TRANSPORT2(); // AKS + void Assemble_RHS_T_PSGlobal(); // Assembly of RHS by temperature for PSGlobal + void AssembleRHS(int dimension); // PCH + void Assemble_RHS_LIQUIDFLOW(); // NW void Assemble_DualTransfer(); - bool check_matrices; //OK4104 - void AssembleRHSVector(); //OK - void AssembleCapillaryEffect(); // PCH - // PCH for debugging + bool check_matrices; // OK4104 + void AssembleRHSVector(); // OK + void AssembleCapillaryEffect(); // PCH +// PCH for debugging #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW void add2GlobalMatrixII(); #else - void add2GlobalMatrixII(const int block_cols = 2); //WW. 06.2011 + void add2GlobalMatrixII(const int block_cols = 2); // WW. 06.2011 #endif void PrintTheSetOfElementMatrices(std::string mark); // Friend classes, 01/07, WW @@ -414,35 +421,35 @@ class CFiniteElementStd : public CElement friend class SolidProp::CSolidProperties; friend class ::CFluidProperties; // Friend functions. WW - friend double ::MFPCalcFluidsHeatCapacity(CFiniteElementStd * assem); + friend double ::MFPCalcFluidsHeatCapacity(CFiniteElementStd* assem); // Auxillarary vectors for node values // Vector of local node values, e.g. pressure, temperature. // Assume maximium element nodes is 20 - //double OldMatrix[64]; // For grid adapting + // double OldMatrix[64]; // For grid adapting double NodalValue[12][40]; double* NodalVal; - double* NodalVal0; //?? NodalValueSaturation, NodalValueTemperature; ... + double* NodalVal0; //?? NodalValueSaturation, NodalValueTemperature; ... double* NodalVal1; double* NodalVal2; double* NodalVal3; double* NodalVal4; - double *NodalVal5; + double* NodalVal5; double* NodalValC; double* NodalValC1; double* NodalVal_Sat; double* NodalVal_SatNW; double* NodalVal_p2; - double* NodalVal_p20; //AKS - double *NodalVal_t0; // for TEMPERATURE1 - double *NodalVal_t1; //AKS - double *NodalVal_t2_0; // FOR TEMPERATURE2 previous time step - double *NodalVal_t2_1; // for TEMPERATURE2 current time step - double *NodalVal_X0; // for CONCENTRATION previous time step - double *NodalVal_X1; // for CONCENTRATION current time step + double* NodalVal_p20; // AKS + double* NodalVal_t0; // for TEMPERATURE1 + double* NodalVal_t1; // AKS + double* NodalVal_t2_0; // FOR TEMPERATURE2 previous time step + double* NodalVal_t2_1; // for TEMPERATURE2 current time step + double* NodalVal_X0; // for CONCENTRATION previous time step + double* NodalVal_X1; // for CONCENTRATION current time step // - double* weight_func; //NW - void CalcFEM_FCT(); //NW + double* weight_func; // NW + void CalcFEM_FCT(); // NW // friend class ::CRFProcess; }; @@ -454,7 +461,7 @@ class ElementValue ElementValue(CRFProcess* m_pcs, CElem* ele); ~ElementValue(); void getIPvalue_vec(const int IP, double* vec); - //SB 09/2010 + // SB 09/2010 void getIPvalue_vec_phase(const int IP, int phase, double* vec); void GetEleVelocity(double* vec); Matrix Velocity; @@ -462,25 +469,24 @@ class ElementValue // HS Thermal Storage parameters--------------- // Array of parameters on each Gauss point double *rho_s_prev, *rho_s_curr; - double *q_R; - // End of Thermal Storage parameters--------------- + double* q_R; +// End of Thermal Storage parameters--------------- #ifdef USE_TRANSPORT_FLUX - Matrix TransportFlux; // Fick or Fourier law with dispersion JOD 2014-11-10 + Matrix TransportFlux; // Fick or Fourier law with dispersion JOD 2014-11-10 #endif private: // Friend class friend class ::CRFProcess; friend class FiniteElement::CFiniteElementStd; - friend class ::COutput; //OK + friend class ::COutput; // OK // Process CRFProcess* pcs; // Data Matrix Velocity_g; // CB _ctx_ CB_merge_0513 - //Matrix _ctx_Gauss; + // Matrix _ctx_Gauss; }; - // controls if gas mass form is used in matrix elements of TNEQ process #define GAS_MASS_FORM #ifdef GAS_MASS_FORM @@ -490,7 +496,7 @@ const bool GasMassForm = false; #endif #undef GAS_MASS_FORM -} // end namespace +} // end namespace /*------------------------------------------------------------------ Finite element calculation for standard PDE. diff --git a/FEM/fem_ele_std1.cpp b/FEM/fem_ele_std1.cpp index f44c09ac7..e8ad86198 100644 --- a/FEM/fem_ele_std1.cpp +++ b/FEM/fem_ele_std1.cpp @@ -32,7 +32,7 @@ using Math_Group::CSparseMatrix; #endif -#include "pcs_dm.h" // displacement coupled +#include "pcs_dm.h" // displacement coupled using namespace std; namespace FiniteElement @@ -47,16 +47,16 @@ namespace FiniteElement */ void CFiniteElementStd::ComputeAdditionalJacobi_H2() { - int l; //, m; - //int dm_shift = problem_dimension_dm; + int l; //, m; + // int dm_shift = problem_dimension_dm; // ---- Gauss integral - int gp_r = 0,gp_s = 0,gp_t = 0; + int gp_r = 0, gp_s = 0, gp_t = 0; double fkt; double perturb = sqrt(DBL_EPSILON); - double* tensor, * p2, * p2_0; - double S1, vsc1, vsc2; + double *tensor, *p2, *p2_0; + double S1, vsc1, vsc2; double dkdp1, dkdp2; - //double phi_dP_dt, d_ds_dp, phi_dP_dt_g; + // double phi_dP_dt, d_ds_dp, phi_dP_dt_g; double relax = pcs->m_num->nls_relaxation; @@ -82,15 +82,15 @@ void CFiniteElementStd::ComputeAdditionalJacobi_H2() // Compute Jacobian matrix and its determinate //--------------------------------------------------------- fkt = relax * GetGaussData(gp, gp_r, gp_s, gp_t); - ComputeShapefct(1); // Linear interpolation function - ComputeGradShapefct(1); // Linear interpolation function + ComputeShapefct(1); // Linear interpolation function + ComputeGradShapefct(1); // Linear interpolation function - //poro = MediaProp->Porosity(Index,pcs->m_num->ls_theta); + // poro = MediaProp->Porosity(Index,pcs->m_num->ls_theta); tensor = MediaProp->PermeabilityTensor(Index); PG = interpolate(NodalVal1); PG2 = interpolate(p2); Sw = MediaProp->SaturationCapillaryPressureFunction(PG); - S1 = Sw + perturb; //MediaProp->SaturationCapillaryPressureFunction(PG+perturb); + S1 = Sw + perturb; // MediaProp->SaturationCapillaryPressureFunction(PG+perturb); dens_arg[0] = PG; rhow = FluidProp->Density(dens_arg); @@ -99,39 +99,40 @@ void CFiniteElementStd::ComputeAdditionalJacobi_H2() vsc1 = FluidProp->Viscosity(); vsc2 = GasProp->Viscosity(); - //dSdp = MediaProp->SaturationPressureDependency(Sw); - dSdp = - (MediaProp->SaturationCapillaryPressureFunction(PG + perturb) - Sw) / perturb; + // dSdp = MediaProp->SaturationPressureDependency(Sw); + dSdp = (MediaProp->SaturationCapillaryPressureFunction(PG + perturb) - Sw) / perturb; // Velocity for (size_t i = 0; i < dim; i++) { gradPw[i] = 0.0; gradPg[i] = 0.; - for(int j = 0; j < nnodes; j++) + for (int j = 0; j < nnodes; j++) { gradPw[i] += (p2[j] - NodalVal1[j]) * dshapefct[i * nnodes + j]; gradPg[i] += p2[j] * dshapefct[i * nnodes + j]; } } - if((coordinate_system) % 10 == 2) + if ((coordinate_system) % 10 == 2) { gradPw[dim - 1] += g_constant * rhow; gradPg[dim - 1] += g_constant * rho_ga; } - dkdp1 = dSdp * ( MediaProp->PermeabilitySaturationFunction(S1,0) - - MediaProp->PermeabilitySaturationFunction(Sw,0)) / perturb; - dkdp2 = dSdp * ( MediaProp->PermeabilitySaturationFunction(S1,1) - - MediaProp->PermeabilitySaturationFunction(Sw,1)) / perturb; + dkdp1 = dSdp + * (MediaProp->PermeabilitySaturationFunction(S1, 0) - MediaProp->PermeabilitySaturationFunction(Sw, 0)) + / perturb; + dkdp2 = dSdp + * (MediaProp->PermeabilitySaturationFunction(S1, 1) - MediaProp->PermeabilitySaturationFunction(Sw, 1)) + / perturb; for (size_t i = 0; i < dim && i < 3; i++) { vw[i] = 0.0; vg[i] = 0.; - const size_t ish = i * dim; - for(size_t j = 0; j < dim; j++) + const size_t ish = i * dim; + for (size_t j = 0; j < dim; j++) { vw[i] += tensor[ish + j] * gradPw[j]; vg[i] += tensor[ish + j] * gradPg[j]; @@ -145,12 +146,12 @@ void CFiniteElementStd::ComputeAdditionalJacobi_H2() { l = i + nnodes; for (int j = 0; j < nnodes; j++) - //m = j+nnodes; + // m = j+nnodes; for (size_t k = 0; k < dim; k++) { f_buff = fkt * dshapefct[k * nnodes + i] * shapefct[j]; - (*StiffMatrix)(i,j) += f_buff * vw[k]; - (*StiffMatrix)(l,j) += f_buff * vg[k]; + (*StiffMatrix)(i, j) += f_buff * vw[k]; + (*StiffMatrix)(l, j) += f_buff * vg[k]; } } @@ -182,7 +183,7 @@ void CFiniteElementStd::ComputeAdditionalJacobi_H2() ddens_g_dt = -poro * dSdp * (rho_ga - GasProp->Density(dens_arg)) / dt; ddens_g_dt /= rhow; - if(dm_pcs) + if (dm_pcs) { // setOrder(2); // GetGaussData(gp, gp_r, gp_s, gp_t); @@ -190,18 +191,17 @@ void CFiniteElementStd::ComputeAdditionalJacobi_H2() // setOrder(1); /// if deformation is coupled - vw[0] = 0.; // Here for dSdp*grad u/dt + vw[0] = 0.; // Here for dSdp*grad u/dt for (int i = 0; i < nnodes; i++) // for (i=0;iWrite(); } @@ -241,15 +241,15 @@ void CFiniteElementStd::ComputeAdditionalJacobi_H2() */ void CFiniteElementStd::ComputeAdditionalJacobi_Richards() { - //int dm_shift = problem_dimension_dm; + // int dm_shift = problem_dimension_dm; // ---- Gauss integral - int gp_r = 0,gp_s = 0,gp_t = 0; + int gp_r = 0, gp_s = 0, gp_t = 0; double fkt; //, mat_fac; double perturb = sqrt(DBL_EPSILON); double* tensor; - double S1, vsc1; + double S1, vsc1; double dkdp1; - //double phi_dP_dt, d_ds_dp, phi_dP_dt_g; + // double phi_dP_dt, d_ds_dp, phi_dP_dt_g; double relax = pcs->m_num->nls_relaxation; @@ -268,38 +268,38 @@ void CFiniteElementStd::ComputeAdditionalJacobi_Richards() // Compute Jacobian matrix and its determinate //--------------------------------------------------------- fkt = relax * GetGaussData(gp, gp_r, gp_s, gp_t); - ComputeShapefct(1); // Linear interpolation function - ComputeGradShapefct(1); // Linear interpolation function + ComputeShapefct(1); // Linear interpolation function + ComputeGradShapefct(1); // Linear interpolation function tensor = MediaProp->PermeabilityTensor(Index); PG = -interpolate(NodalVal1); Sw = MediaProp->SaturationCapillaryPressureFunction(PG); - S1 = Sw + perturb; //MediaProp->SaturationCapillaryPressureFunction(PG+perturb,0); + S1 = Sw + perturb; // MediaProp->SaturationCapillaryPressureFunction(PG+perturb,0); vsc1 = FluidProp->Viscosity(); - //dSdp = MediaProp->SaturationPressureDependency(Sw); - dSdp = - (MediaProp->SaturationCapillaryPressureFunction(PG + perturb) - Sw) / perturb; + // dSdp = MediaProp->SaturationPressureDependency(Sw); + dSdp = (MediaProp->SaturationCapillaryPressureFunction(PG + perturb) - Sw) / perturb; // Velocity for (size_t i = 0; i < dim; i++) { gradPw[i] = 0.0; - for(int j = 0; j < nnodes; j++) + for (int j = 0; j < nnodes; j++) gradPw[i] += NodalVal1[j] * dshapefct[i * nnodes + j]; } - if((coordinate_system) % 10 == 2) + if ((coordinate_system) % 10 == 2) gradPw[dim - 1] += g_constant * rhow; - dkdp1 = dSdp * ( MediaProp->PermeabilitySaturationFunction(S1,0) - - MediaProp->PermeabilitySaturationFunction(Sw,0)) / perturb; + dkdp1 = dSdp + * (MediaProp->PermeabilitySaturationFunction(S1, 0) - MediaProp->PermeabilitySaturationFunction(Sw, 0)) + / perturb; for (size_t i = 0; i < dim && i < 3; i++) { vw[i] = 0.0; - for(size_t j = 0; j < dim; j++) + for (size_t j = 0; j < dim; j++) vw[i] += tensor[i * dim + j] * gradPw[j]; vw[i] *= dkdp1 * time_unit_factor / vsc1; @@ -308,17 +308,14 @@ void CFiniteElementStd::ComputeAdditionalJacobi_Richards() /// For the Laplace for (int i = 0; i < nnodes; i++) for (int j = 0; j < nnodes; j++) - //m = j+nnodes; + // m = j+nnodes; for (size_t k = 0; k < dim; k++) - (*StiffMatrix)(i, - j) += fkt * - dshapefct[k * nnodes + - i] * shapefct[j] * vw[k]; + (*StiffMatrix)(i, j) += fkt * dshapefct[k * nnodes + i] * shapefct[j] * vw[k]; #define Take_Deformation_to_Jacobian #ifdef Take_Deformation_to_Jacobian - if(dm_pcs) + if (dm_pcs) { // setOrder(2); // GetGaussData(gp, gp_r, gp_s, gp_t); @@ -326,31 +323,30 @@ void CFiniteElementStd::ComputeAdditionalJacobi_Richards() // setOrder(1); /// if deformation is coupled - vw[0] = 0.; // Here for dSdp*grad u/dt + vw[0] = 0.; // Here for dSdp*grad u/dt for (int i = 0; i < nnodes; i++) // for (i=0;iWrite(); } -} // namespace +} // namespace diff --git a/FEM/fem_ele_std_tes.cpp b/FEM/fem_ele_std_tes.cpp index 691670d88..e82113651 100644 --- a/FEM/fem_ele_std_tes.cpp +++ b/FEM/fem_ele_std_tes.cpp @@ -14,11 +14,10 @@ #include "rfmat_cp.h" - #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW #include "PETSC/PETScLinearSolver.h" #else -#ifndef NEW_EQS //WW. 06.11.2008 +#ifndef NEW_EQS // WW. 06.11.2008 // Sytem matrix #include "matrix_routines.h" #endif @@ -33,27 +32,23 @@ using Math_Group::CSparseMatrix; namespace { - -static inline double ipol(double const * const a, double const * const b, - const double theta, FiniteElement::CElement const * const obj) +static inline double ipol(double const* const a, double const* const b, const double theta, + FiniteElement::CElement const* const obj) { - return (1.0-theta)*obj->interpolate(a) + theta*obj->interpolate(b); + return (1.0 - theta) * obj->interpolate(a) + theta * obj->interpolate(b); } - } - namespace FiniteElement { - /************************************************************************* - Programming: - 07/2013 TN + Programming: + 07/2013 TN **************************************************************************/ void CFiniteElementStd::CalcMassTES() { // ---- Gauss integral - int gp_r=0,gp_s=0,gp_t=0; + int gp_r = 0, gp_s = 0, gp_t = 0; // Loop over Gauss points for (gp = 0; gp < nGaussPoints; gp++) @@ -62,34 +57,34 @@ void CFiniteElementStd::CalcMassTES() // Compute Jacobian matrix and its determinate double fkt = GetGaussData(gp, gp_r, gp_s, gp_t); // Compute geometry - ComputeShapefct(1); // Linear interpolation function + ComputeShapefct(1); // Linear interpolation function - for (int in=0; indof; in++) + for (int in = 0; in < pcs->dof; in++) { - for (int jn=0; jndof; jn++) + for (int jn = 0; jn < pcs->dof; jn++) { // Material - const double coeff = CalCoefMassTES(in*pcs->dof+jn); + const double coeff = CalCoefMassTES(in * pcs->dof + jn); const double mat_fac = fkt * coeff; - // Calculate mass matrix +// Calculate mass matrix #if defined(USE_PETSC) // || defined(other parallel libs)//08.2014. WW - const int jn_offset = jn*nnodes; + const int jn_offset = jn * nnodes; for (int i = 0; i < act_nodes; i++) { const int ia = local_idx[i]; - const int ib = i + in*nnodes; + const int ib = i + in * nnodes; for (int j = 0; j < nnodes; j++) { - (*Mass2)(ib, j + jn_offset) += mat_fac *shapefct[ia]*shapefct[j]; + (*Mass2)(ib, j + jn_offset) += mat_fac * shapefct[ia] * shapefct[j]; } } #else for (int i = 0; i < nnodes; i++) { for (int j = 0; j < nnodes; j++) - (*Mass2)(i+in*nnodes,j+jn*nnodes) += mat_fac *shapefct[i]*shapefct[j]; + (*Mass2)(i + in * nnodes, j + jn * nnodes) += mat_fac * shapefct[i] * shapefct[j]; } #endif } @@ -100,10 +95,9 @@ void CFiniteElementStd::CalcMassTES() // << (*Mass2) << std::endl; } - /************************************************************************* - Programming: - 07/2013 TN + Programming: + 07/2013 TN **************************************************************************/ void CFiniteElementStd::CalcLumpedMassTES() { @@ -112,8 +106,8 @@ void CFiniteElementStd::CalcLumpedMassTES() double vol = 0.0; // Volume - if(axisymmetry) - { // This calculation should be done in CompleteMesh. + if (axisymmetry) + { // This calculation should be done in CompleteMesh. // However, in order not to destroy the concise of the code, // it is put here. Anyway it is computational cheap. WW vol = 0.0; @@ -123,17 +117,17 @@ void CFiniteElementStd::CalcLumpedMassTES() vol += GetGaussData(gp, gp_r, gp_s, gp_t); } else - vol = MeshElement->GetVolume();//* MeshElement->area; + vol = MeshElement->GetVolume(); //* MeshElement->area; // Initialize (*Mass2) = 0.0; // Center of the reference element SetCenterGP(); ComputeShapefct(1); - for(int in = 0; in < nDF; in++) + for (int in = 0; in < nDF; in++) { const int ish = in * nnodes; - for(int jn = 0; jn < nDF; jn++) + for (int jn = 0; jn < nDF; jn++) { const int jsh = jn * nnodes; double factor = CalCoefMassTES(in * nDF + jn); @@ -142,29 +136,28 @@ void CFiniteElementStd::CalcLumpedMassTES() factor *= vol; for (int i = 0; i < nnodes; i++) { - (*Mass2)(i + ish, i + jsh) = shapefct[i]*factor; + (*Mass2)(i + ish, i + jsh) = shapefct[i] * factor; } } } } - /************************************************************************** - FEMLib-Method: - Task: Calculate material coefficient for mass matrix - Implementaion: - 03/2011 AKS / NB - 07/2013 TN - 04/2015 CL + FEMLib-Method: + Task: Calculate material coefficient for mass matrix + Implementaion: + 03/2011 AKS / NB + 07/2013 TN + 04/2015 CL **************************************************************************/ double CFiniteElementStd::CalCoefMassTES(const int dof_index) { - double const * const p0 = NodalVal0; - double const * const p1 = NodalVal1; - double const * const T0 = NodalVal_t0; - double const * const T1 = NodalVal_t1; - double const * const X0 = NodalVal_X0; - double const * const X1 = NodalVal_X1; + double const* const p0 = NodalVal0; + double const* const p1 = NodalVal1; + double const* const T0 = NodalVal_t0; + double const* const T1 = NodalVal_t1; + double const* const X0 = NodalVal_X0; + double const* const X1 = NodalVal_X1; double& p = eos_arg[0]; double& T = eos_arg[1]; @@ -178,90 +171,89 @@ double CFiniteElementStd::CalCoefMassTES(const int dof_index) double val = 0.0; - switch(dof_index) - { - case 0: // M_pp - p = ipol(p0, p1, theta, this); - T = ipol(T0, T1, theta, this); - X = ipol(X0, X1, theta, this); - val = poro/p * FluidProp->Density(eos_arg); - break; - - case 1: // M_pT - p = ipol(p0, p1, theta, this); - T = ipol(T0, T1, theta, this); - X = ipol(X0, X1, theta, this); - val = -poro/T * FluidProp->Density(eos_arg); - break; - - case 2: // M_px + switch (dof_index) { - p = ipol(p0, p1, theta, this); - T = ipol(T0, T1, theta, this); - X = ipol(X0, X1, theta, this); + case 0: // M_pp + p = ipol(p0, p1, theta, this); + T = ipol(T0, T1, theta, this); + X = ipol(X0, X1, theta, this); + val = poro / p * FluidProp->Density(eos_arg); + break; + + case 1: // M_pT + p = ipol(p0, p1, theta, this); + T = ipol(T0, T1, theta, this); + X = ipol(X0, X1, theta, this); + val = -poro / T * FluidProp->Density(eos_arg); + break; + + case 2: // M_px + { + p = ipol(p0, p1, theta, this); + T = ipol(T0, T1, theta, this); + X = ipol(X0, X1, theta, this); - const double M0 = cp_vec[0]->molar_mass; // inert - const double M1 = cp_vec[1]->molar_mass; // reactive + const double M0 = cp_vec[0]->molar_mass; // inert + const double M1 = cp_vec[1]->molar_mass; // reactive - double dxn_dxm = M0 * M1; // 0 is inert, 1 is reactive - dxn_dxm /= (M0 * X + M1 * (1.0 - X)) * (M0 * X + M1 * (1.0 - X)); + double dxn_dxm = M0 * M1; // 0 is inert, 1 is reactive + dxn_dxm /= (M0 * X + M1 * (1.0 - X)) * (M0 * X + M1 * (1.0 - X)); - val = (M1-M0) * p / (PhysicalConstant::IdealGasConstant * T) * dxn_dxm * poro; - break; - } + val = (M1 - M0) * p / (PhysicalConstant::IdealGasConstant * T) * dxn_dxm * poro; + break; + } - case 3: // M_Tp - val = -poro; - break; + case 3: // M_Tp + val = -poro; + break; - case 4: // M_TT - { - p = ipol(p0, p1, theta, this); - T = ipol(T0, T1, theta, this); - X = ipol(X0, X1, theta, this); + case 4: // M_TT + { + p = ipol(p0, p1, theta, this); + T = ipol(T0, T1, theta, this); + X = ipol(X0, X1, theta, this); - const double rhoSR = gp_ele->rho_s_curr[gp]; - const double rhoGR = FluidProp->Density(eos_arg); - const double cpG = FluidProp->SpecificHeatCapacity(eos_arg); - const double cpS = SolidProp->Heat_Capacity(rhoSR); + const double rhoSR = gp_ele->rho_s_curr[gp]; + const double rhoGR = FluidProp->Density(eos_arg); + const double cpG = FluidProp->SpecificHeatCapacity(eos_arg); + const double cpS = SolidProp->Heat_Capacity(rhoSR); - val = poro * rhoGR * cpG + (1.0-poro) * rhoSR * cpS; - break; - } + val = poro * rhoGR * cpG + (1.0 - poro) * rhoSR * cpS; + break; + } // case 5: // case 6: // case 7: // break; - case 8: // M_xx - p = ipol(p0, p1, theta, this); - T = ipol(T0, T1, theta, this); - X = ipol(X0, X1, theta, this); - val= poro * FluidProp->Density(eos_arg); - break; + case 8: // M_xx + p = ipol(p0, p1, theta, this); + T = ipol(T0, T1, theta, this); + X = ipol(X0, X1, theta, this); + val = poro * FluidProp->Density(eos_arg); + break; } return val; } - /************************************************************************** - FEMLib-Method: - Task: Calculate material coefficient for Laplacian matrix - Implementaion: - 03/2011 AKS / NB - 07/2013 TN - 04/2015 CL + FEMLib-Method: + Task: Calculate material coefficient for Laplacian matrix + Implementaion: + 03/2011 AKS / NB + 07/2013 TN + 04/2015 CL **************************************************************************/ void CFiniteElementStd::CalCoefLaplaceTES(const int dof_index) { - double const * const p0 = NodalVal0; - double const * const p1 = NodalVal1; - double const * const T0 = NodalVal_t0; - double const * const T1 = NodalVal_t1; - double const * const X0 = NodalVal_X0; - double const * const X1 = NodalVal_X1; + double const* const p0 = NodalVal0; + double const* const p1 = NodalVal1; + double const* const T0 = NodalVal_t0; + double const* const T1 = NodalVal_t1; + double const* const X0 = NodalVal_X0; + double const* const X1 = NodalVal_X1; double& p = eos_arg[0]; double& T = eos_arg[1]; @@ -271,131 +263,125 @@ void CFiniteElementStd::CalCoefLaplaceTES(const int dof_index) const int Index = MeshElement->GetIndex(); - - - switch(dof_index) + switch (dof_index) { - case 0: - { - p = ipol(p0, p1, theta, this); - T = ipol(T0, T1, theta, this); - X = ipol(X0, X1, theta, this); - - double* tensor = MediaProp->PermeabilityTensor(Index); - double k_rel = 1.0; - if (MediaProp->flowlinearity_model > 0) + case 0: { - k_rel = MediaProp->NonlinearFlowFunction(Index, gp, theta, this); - } + p = ipol(p0, p1, theta, this); + T = ipol(T0, T1, theta, this); + X = ipol(X0, X1, theta, this); - double val = FluidProp->Density(eos_arg) - * k_rel / FluidProp->Viscosity(eos_arg); + double* tensor = MediaProp->PermeabilityTensor(Index); + double k_rel = 1.0; + if (MediaProp->flowlinearity_model > 0) + { + k_rel = MediaProp->NonlinearFlowFunction(Index, gp, theta, this); + } - for(size_t i=0; iDensity(eos_arg) * k_rel / FluidProp->Viscosity(eos_arg); + + for (size_t i = 0; i < dim * dim; i++) + { + mat[i] = tensor[i] * val; + } + break; } - break; - } - // case 1: - // case 2: - // case 3: - // break; + // case 1: + // case 2: + // case 3: + // break; - case 4: - { - p = ipol(p0, p1, theta, this); - T = ipol(T0, T1, theta, this); - X = ipol(X0, X1, theta, this); + case 4: + { + p = ipol(p0, p1, theta, this); + T = ipol(T0, T1, theta, this); + X = ipol(X0, X1, theta, this); - // TODO [CL]: only diagonal neeeded, and only one array needed - double fluid_heat_conductivity_tensor[9] = { 0. }; - double solid_heat_conductivity_tensor[9] = { 0. }; + // TODO [CL]: only diagonal neeeded, and only one array needed + double fluid_heat_conductivity_tensor[9] = {0.}; + double solid_heat_conductivity_tensor[9] = {0.}; - poro = MediaProp->Porosity(Index, theta); - const double lamf = FluidProp->HeatConductivity(eos_arg); - double lams = SolidProp->Heat_Conductivity(); + poro = MediaProp->Porosity(Index, theta); + const double lamf = FluidProp->HeatConductivity(eos_arg); + double lams = SolidProp->Heat_Conductivity(); - if (SolidProp->getSolidReactiveSystem() == FiniteElement::Z13XBF) - { - ElementValue* gp_ele = ele_gp_value[Index]; - double C = gp_ele->rho_s_curr[gp] - / SolidProp->lower_solid_density_limit - 1.; - const double lambda_ads = 0.7; //TODO [CL] Find relation for this - lams += C * SolidProp->lower_solid_density_limit - / pcs->m_conversion_rate->get_adsorbate_density(T) - * (lambda_ads - lamf); - } + if (SolidProp->getSolidReactiveSystem() == FiniteElement::Z13XBF) + { + ElementValue* gp_ele = ele_gp_value[Index]; + double C = gp_ele->rho_s_curr[gp] / SolidProp->lower_solid_density_limit - 1.; + const double lambda_ads = 0.7; // TODO [CL] Find relation for this + lams += C * SolidProp->lower_solid_density_limit / pcs->m_conversion_rate->get_adsorbate_density(T) + * (lambda_ads - lamf); + } - for (size_t i = 0; i < dim; i++) - { - fluid_heat_conductivity_tensor[i*dim+i] = poro * lamf; - solid_heat_conductivity_tensor[i*dim+i] = (1.0-poro) * lams; - } + for (size_t i = 0; i < dim; i++) + { + fluid_heat_conductivity_tensor[i * dim + i] = poro * lamf; + solid_heat_conductivity_tensor[i * dim + i] = (1.0 - poro) * lams; + } - for(size_t i=0; iPorosity(Index, theta); - tort = MediaProp->TortuosityFunction(Index, unit, theta); - const double diffusion_coefficient_component = cp_vec[1]->CalcDiffusionCoefficientCP(Index, theta, pcs);//coefficient of reactive (2nd) component - const double rhoGR = FluidProp->Density(eos_arg); + poro = MediaProp->Porosity(Index, theta); + tort = MediaProp->TortuosityFunction(Index, unit, theta); + const double diffusion_coefficient_component + = cp_vec[1]->CalcDiffusionCoefficientCP(Index, theta, pcs); // coefficient of reactive (2nd) component + const double rhoGR = FluidProp->Density(eos_arg); - for (size_t i = 0; i < dim; i++) - { - // TODO [CL] poro? - diffusion_tensor[i*dim+i] = tort * poro * rhoGR * diffusion_coefficient_component; - } + for (size_t i = 0; i < dim; i++) + { + // TODO [CL] poro? + diffusion_tensor[i * dim + i] = tort * poro * rhoGR * diffusion_coefficient_component; + } - for(size_t i=0;iVelocity(0, gp), - gp_ele->Velocity(1, gp), - gp_ele->Velocity(2, gp) - }; + double vel[] = {gp_ele->Velocity(0, gp), gp_ele->Velocity(1, gp), gp_ele->Velocity(2, gp)}; for (int in = 0; in < pcs->dof; in++) { for (int jn = 0; jn < pcs->dof; jn++) { - const double coeff = CalCoefAdvectionTES(in*pcs->dof + jn); + const double coeff = CalCoefAdvectionTES(in * pcs->dof + jn); const double mat_fac = fkt * coeff; #if defined(USE_PETSC) // || defined(other parallel libs)//08.2014. WW - const int jn_offset = jn*nnodes; + const int jn_offset = jn * nnodes; for (int i = 0; i < act_nodes; i++) { const int ia = local_idx[i]; - const int ib = i + in*nnodes; + const int ib = i + in * nnodes; for (int j = 0; j < nnodes; j++) { for (size_t k = 0; k < dim; k++) { - (*Advection)(ib, j + jn_offset) += mat_fac*shapefct[ia] - * vel[k]*dshapefct[k*nnodes+j]; + (*Advection)(ib, j + jn_offset) + += mat_fac * shapefct[ia] * vel[k] * dshapefct[k * nnodes + j]; } } } #else - for (int i = 0; i< nnodes; i++) + for (int i = 0; i < nnodes; i++) { - for (int j = 0; j< nnodes; j++) + for (int j = 0; j < nnodes; j++) { for (size_t k = 0; k < dim; k++) { - (*Advection)(i+in*nnodes, j+jn*nnodes) += mat_fac*shapefct[i]*vel[k]*dshapefct[k*nnodes+j]; + (*Advection)(i + in * nnodes, j + jn * nnodes) + += mat_fac * shapefct[i] * vel[k] * dshapefct[k * nnodes + j]; } } } #endif - } } } @@ -455,26 +437,25 @@ void CFiniteElementStd::CalcAdvectionTES() // << (*Advection) << std::endl; } - /************************************************************************** FEMLib-Method: - Task: Calculate material coefficient for advection matrix - Programing: - 01/2005 WW/OK Implementation - 03/2005 WW Heat transport - 07/2005 WW Change for geometry element object - 09/2005 SB - 07/2013 TN - 04/2015 CL + Task: Calculate material coefficient for advection matrix + Programing: + 01/2005 WW/OK Implementation + 03/2005 WW Heat transport + 07/2005 WW Change for geometry element object + 09/2005 SB + 07/2013 TN + 04/2015 CL **************************************************************************/ double CFiniteElementStd::CalCoefAdvectionTES(const int dof_index) { - double const * const p0 = NodalVal0; - double const * const p1 = NodalVal1; - double const * const T0 = NodalVal_t0; - double const * const T1 = NodalVal_t1; - double const * const X0 = NodalVal_X0; - double const * const X1 = NodalVal_X1; + double const* const p0 = NodalVal0; + double const* const p1 = NodalVal1; + double const* const T0 = NodalVal_t0; + double const* const T1 = NodalVal_t1; + double const* const X0 = NodalVal_X0; + double const* const X1 = NodalVal_X1; double& p = eos_arg[0]; double& T = eos_arg[1]; @@ -484,51 +465,50 @@ double CFiniteElementStd::CalCoefAdvectionTES(const int dof_index) double val = 0.0; - switch(dof_index) + switch (dof_index) { - // case 0: - // case 1: - // case 2: - // case 3: - // break; - - case 4: - p = ipol(p0, p1, theta, this); - T = ipol(T0, T1, theta, this); - X = ipol(X0, X1, theta, this); - - val = FluidProp->Density(eos_arg) * FluidProp->SpecificHeatCapacity(eos_arg); - break; + // case 0: + // case 1: + // case 2: + // case 3: + // break; + + case 4: + p = ipol(p0, p1, theta, this); + T = ipol(T0, T1, theta, this); + X = ipol(X0, X1, theta, this); + + val = FluidProp->Density(eos_arg) * FluidProp->SpecificHeatCapacity(eos_arg); + break; // case 5: // case 6: // case 7: // break; - case 8: - p = ipol(p0, p1, theta, this); - T = ipol(T0, T1, theta, this); - X = ipol(X0, X1, theta, this); + case 8: + p = ipol(p0, p1, theta, this); + T = ipol(T0, T1, theta, this); + X = ipol(X0, X1, theta, this); - val = FluidProp->Density(eos_arg); - break; + val = FluidProp->Density(eos_arg); + break; } return val; } - /*************************************************************************** - FEMLib-Method: - Task: Assembly of ContentMatrix for - TES - Implementaion: - 03/2011 AKS - 07/2013 TN + FEMLib-Method: + Task: Assembly of ContentMatrix for + TES + Implementaion: + 03/2011 AKS + 07/2013 TN **************************************************************************/ void CFiniteElementStd::CalcContentTES() { - int gp_r=0, gp_s=0, gp_t=0; + int gp_r = 0, gp_s = 0, gp_t = 0; for (gp = 0; gp < nGaussPoints; gp++) { @@ -539,26 +519,26 @@ void CFiniteElementStd::CalcContentTES() { for (int jn = 0; jn < pcs->dof; jn++) { - const double coeff = CalCoefContentTES(in*pcs->dof + jn); + const double coeff = CalCoefContentTES(in * pcs->dof + jn); double mat_fac = fkt * coeff; #if defined(USE_PETSC) // || defined(other parallel libs)//08.2014. WW - const int jn_offset = jn*nnodes; + const int jn_offset = jn * nnodes; for (int i = 0; i < act_nodes; i++) { const int ia = local_idx[i]; - const int ib = i + in*nnodes; + const int ib = i + in * nnodes; for (int j = 0; j < nnodes; j++) { (*Content)(ib, j + jn_offset) += mat_fac * shapefct[ia] * shapefct[j]; } } #else - for (int i = 0; i< nnodes; i++) + for (int i = 0; i < nnodes; i++) { - for (int j = 0; j< nnodes; j++) + for (int j = 0; j < nnodes; j++) { - (*Content)(i+in*nnodes, j+jn*nnodes) += mat_fac *shapefct[i]*shapefct[j]; + (*Content)(i + in * nnodes, j + jn * nnodes) += mat_fac * shapefct[i] * shapefct[j]; } } #endif @@ -570,13 +550,12 @@ void CFiniteElementStd::CalcContentTES() // << (*Content) << std::endl; } - /************************************************************************** - FEMLib-Method: - Task: - Programing: - 07/2013 TN - 04/2015 CL + FEMLib-Method: + Task: + Programing: + 07/2013 TN + 04/2015 CL **************************************************************************/ double CFiniteElementStd::CalCoefContentTES(const int dof_index) { @@ -587,38 +566,38 @@ double CFiniteElementStd::CalCoefContentTES(const int dof_index) double val = 0.0; - switch(dof_index) + switch (dof_index) { - // gas flow - // case 0: - // case 1: - // case 2: - // case 3: - // case 4: - // case 5: - // case 6: - // case 7: - // break; - case 8: // x x - val = (MediaProp->Porosity(Index, theta) - 1.0) * gp_ele->q_R[gp]; - break; + // gas flow + // case 0: + // case 1: + // case 2: + // case 3: + // case 4: + // case 5: + // case 6: + // case 7: + // break; + case 8: // x x + val = (MediaProp->Porosity(Index, theta) - 1.0) * gp_ele->q_R[gp]; + break; } return val; } - /*************************************************************************** - GeoSys - Funktion: - Assemble_RHS_TES: - 11/2011 AKS - 07/2013 TN + GeoSys - Funktion: + Assemble_RHS_TES: + 11/2011 AKS + 07/2013 TN **************************************************************************/ void CFiniteElementStd::Assemble_RHS_TES() { - int gp_r=0, gp_s=0, gp_t=0; + int gp_r = 0, gp_s = 0, gp_t = 0; - for (int i = 0; i < pcs->dof*nnodes; i++) NodalVal[i] = 0.0; + for (int i = 0; i < pcs->dof * nnodes; i++) + NodalVal[i] = 0.0; // Loop over Gauss points for (gp = 0; gp < nGaussPoints; gp++) @@ -628,49 +607,47 @@ void CFiniteElementStd::Assemble_RHS_TES() // Compute geometry ComputeShapefct(1); - for(int ii=0; iidof; ii++) + for (int ii = 0; ii < pcs->dof; ii++) { const double fac = CalCoef_RHS_TES(ii); for (int i = 0; i < nnodes; i++) - NodalVal[i+ii*nnodes] += fac*fkt*shapefct[i]; + NodalVal[i + ii * nnodes] += fac * fkt * shapefct[i]; } } - for(int ii=0; iidof; ii++) + for (int ii = 0; ii < pcs->dof; ii++) { - const int ii_sh = ii*nnodes; - //std::cout << ii << " " << i_sh << " " << ii_sh << "\n"; - for (int i=0; iGetIndex(); poro = MediaProp->Porosity(Index, theta); const ElementValue* gp_ele = ele_gp_value[Index]; - const double q_r= gp_ele->q_R[gp]; // reaction rate + const double q_r = gp_ele->q_R[gp]; // reaction rate double val = 0.0; // NodalVal0 and NodalVal1 is the pressure on previous and current time step. // - switch(dof_index) + switch (dof_index) { - case 0: - val = (poro - 1.0) * q_r; - break; + case 0: + val = (poro - 1.0) * q_r; + break; - case 1: - { - pg = ipol(p0, p1, theta, this); - Tg = ipol(T0, T1, theta, this); - Xw = ipol(X0, X1, theta, this); + case 1: + { + pg = ipol(p0, p1, theta, this); + Tg = ipol(T0, T1, theta, this); + Xw = ipol(X0, X1, theta, this); - val = FluidProp->Density(eos_arg) * poro * FluidProp->specific_heat_source; + val = FluidProp->Density(eos_arg) * poro * FluidProp->specific_heat_source; - double H_vap; - if (SolidProp->getSolidReactiveSystem() == FiniteElement::Z13XBF) - { - const double mole_frac = pcs->m_conversion_rate->get_mole_fraction(Xw); - H_vap = pcs->m_conversion_rate->get_enthalpy(Tg, pg * mole_frac); - } else { - // sign convention: - // defined negative for exothermic composition reaction but equ. written as: - // AB + \Delta H <--> A + B - H_vap = - SolidProp->reaction_enthalpy; - } + double H_vap; + if (SolidProp->getSolidReactiveSystem() == FiniteElement::Z13XBF) + { + const double mole_frac = pcs->m_conversion_rate->get_mole_fraction(Xw); + H_vap = pcs->m_conversion_rate->get_enthalpy(Tg, pg * mole_frac); + } + else + { + // sign convention: + // defined negative for exothermic composition reaction but equ. written as: + // AB + \Delta H <--> A + B + H_vap = -SolidProp->reaction_enthalpy; + } - val += (1.0-poro) * q_r * H_vap; - val += gp_ele->rho_s_curr[gp] * (1.0-poro) * SolidProp->specific_heat_source; - } + val += (1.0 - poro) * q_r * H_vap; + val += gp_ele->rho_s_curr[gp] * (1.0 - poro) * SolidProp->specific_heat_source; + } break; - case 2: - val = (poro - 1.0) * q_r; - if (Xw < 0.0) - val += 100.; - break; + case 2: + val = (poro - 1.0) * q_r; + if (Xw < 0.0) + val += 100.; + break; } return val; } - } diff --git a/FEM/fem_ele_std_tneq.cpp b/FEM/fem_ele_std_tneq.cpp index c077a3979..c2446d68c 100644 --- a/FEM/fem_ele_std_tneq.cpp +++ b/FEM/fem_ele_std_tneq.cpp @@ -14,11 +14,10 @@ #include "rfmat_cp.h" - #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW #include "PETSC/PETScLinearSolver.h" #else -#ifndef NEW_EQS //WW. 06.11.2008 +#ifndef NEW_EQS // WW. 06.11.2008 // Sytem matrix #include "matrix_routines.h" #endif @@ -29,24 +28,19 @@ using Math_Group::CSparseMatrix; #endif - #include "PhysicalConstant.h" namespace { - -static inline double ipol(double const * const a, double const * const b, - const double theta, FiniteElement::CElement const * const obj) +static inline double ipol(double const* const a, double const* const b, const double theta, + FiniteElement::CElement const* const obj) { - return (1.0-theta)*obj->interpolate(a) + theta*obj->interpolate(b); + return (1.0 - theta) * obj->interpolate(a) + theta * obj->interpolate(b); } - } - namespace FiniteElement { - /************************************************************************* Programming: 07/2013 TN @@ -54,7 +48,7 @@ namespace FiniteElement void CFiniteElementStd::CalcMassTNEQ() { // ---- Gauss integral - int gp_r=0,gp_s=0,gp_t=0; + int gp_r = 0, gp_s = 0, gp_t = 0; // Loop over Gauss points for (gp = 0; gp < nGaussPoints; gp++) @@ -63,27 +57,25 @@ void CFiniteElementStd::CalcMassTNEQ() // Compute Jacobian matrix and its determinate double fkt = GetGaussData(gp, gp_r, gp_s, gp_t); // Compute geometry - ComputeShapefct(1); // Linear interpolation function + ComputeShapefct(1); // Linear interpolation function - for (int in=0; indof; in++) + for (int in = 0; in < pcs->dof; in++) { - for (int jn=0; jndof; jn++) + for (int jn = 0; jn < pcs->dof; jn++) { // Material - double mat_fac = fkt*CalCoefMassTNEQ(in*pcs->dof+jn); + double mat_fac = fkt * CalCoefMassTNEQ(in * pcs->dof + jn); // Calculate mass matrix for (int i = 0; i < nnodes; i++) { for (int j = 0; j < nnodes; j++) - (*Mass2)(i+in*nnodes,j+jn*nnodes) += mat_fac *shapefct[i]*shapefct[j]; + (*Mass2)(i + in * nnodes, j + jn * nnodes) += mat_fac * shapefct[i] * shapefct[j]; } } } } } - - /************************************************************************** FEMLib-Method: Task: Calculate material coefficient for mass matrix @@ -94,12 +86,12 @@ void CFiniteElementStd::CalcMassTNEQ() **************************************************************************/ double CFiniteElementStd::CalCoefMassTNEQ(const int dof_index) { - double const * const p0 = NodalVal0; - double const * const p1 = NodalVal1; - double const * const T0 = NodalVal_t0; - double const * const T1 = NodalVal_t1; - double const * const X0 = NodalVal_X0; - double const * const X1 = NodalVal_X1; + double const* const p0 = NodalVal0; + double const* const p1 = NodalVal1; + double const* const T0 = NodalVal_t0; + double const* const T1 = NodalVal_t1; + double const* const X0 = NodalVal_X0; + double const* const X1 = NodalVal_X1; double& p = eos_arg[0]; double& T = eos_arg[1]; @@ -113,112 +105,120 @@ double CFiniteElementStd::CalCoefMassTNEQ(const int dof_index) double val = 0.0; - switch(dof_index) + switch (dof_index) { - case 0: // M_pp - if (GasMassForm) { - p = ipol(p0, p1, theta, this); - T = ipol(T0, T1, theta, this); - X = ipol(X0, X1, theta, this); - val = poro / p * FluidProp->Density(eos_arg); - } else { - p = ipol(p0, p1, theta, this); - val = poro / p; - } - break; + case 0: // M_pp + if (GasMassForm) + { + p = ipol(p0, p1, theta, this); + T = ipol(T0, T1, theta, this); + X = ipol(X0, X1, theta, this); + val = poro / p * FluidProp->Density(eos_arg); + } + else + { + p = ipol(p0, p1, theta, this); + val = poro / p; + } + break; + + case 1: // M_pT + if (GasMassForm) + { + p = ipol(p0, p1, theta, this); + T = ipol(T0, T1, theta, this); + X = ipol(X0, X1, theta, this); + val = -poro / T * FluidProp->Density(eos_arg); + } + else + { + T = ipol(T0, T1, theta, this); + val = -poro / T; + } + break; + + // case 2: + // val = 0.0; + // break; - case 1: // M_pT - if (GasMassForm) { + case 3: // M_px + { p = ipol(p0, p1, theta, this); T = ipol(T0, T1, theta, this); X = ipol(X0, X1, theta, this); - val = - poro / T * FluidProp->Density(eos_arg); - } else { - T = ipol(T0, T1, theta, this); - val = - poro/T; - } - break; - // case 2: - // val = 0.0; - // break; - - case 3: // M_px - { - p = ipol(p0, p1, theta, this); - T = ipol(T0, T1, theta, this); - X = ipol(X0, X1, theta, this); + const double M0 = cp_vec[0]->molar_mass; // inert + const double M1 = cp_vec[1]->molar_mass; // reactive - const double M0 = cp_vec[0]->molar_mass; // inert - const double M1 = cp_vec[1]->molar_mass; // reactive + double dxn_dxm = M0 * M1; // 0 is inert, 1 is reactive + dxn_dxm /= (M0 * X + M1 * (1.0 - X)) * (M0 * X + M1 * (1.0 - X)); - double dxn_dxm = M0 * M1; // 0 is inert, 1 is reactive - dxn_dxm /= (M0 * X + M1 * (1.0 - X)) * (M0 * X + M1 * (1.0 - X)); - - if (GasMassForm) { - val = (M1-M0) * p / (PhysicalConstant::IdealGasConstant * T) * dxn_dxm * poro; - } else { - val = (M1-M0) * p / (PhysicalConstant::IdealGasConstant * T) * dxn_dxm * poro - / FluidProp->Density(eos_arg); + if (GasMassForm) + { + val = (M1 - M0) * p / (PhysicalConstant::IdealGasConstant * T) * dxn_dxm * poro; + } + else + { + val = (M1 - M0) * p / (PhysicalConstant::IdealGasConstant * T) * dxn_dxm * poro + / FluidProp->Density(eos_arg); + } + break; } - break; - } - case 4: // M_Tp - if (FluidProp->beta_T == 0.0) - { - // TN: beta_T read as 0 from input file. This leads to neglection of this term. - val = -poro; - } - else - { + case 4: // M_Tp + if (FluidProp->beta_T == 0.0) + { + // TN: beta_T read as 0 from input file. This leads to neglection of this term. + val = -poro; + } + else + { + T = ipol(T0, T1, theta, this); + val = -poro * FluidProp->beta_T * T; + } + break; + + case 5: // M_TT + p = ipol(p0, p1, theta, this); T = ipol(T0, T1, theta, this); - val = -poro*FluidProp->beta_T*T; - } - break; + X = ipol(X0, X1, theta, this); - case 5: // M_TT - p = ipol(p0, p1, theta, this); - T = ipol(T0, T1, theta, this); - X = ipol(X0, X1, theta, this); + val = poro * FluidProp->Density(eos_arg) * FluidProp->SpecificHeatCapacity(eos_arg); - val = poro * FluidProp->Density(eos_arg) * FluidProp->SpecificHeatCapacity(eos_arg); + break; - break; + // case 6: + // case 7: + // case 8: + // case 9: + // val = 0.0; + // break; - // case 6: - // case 7: - // case 8: - // case 9: - // val = 0.0; - // break; + case 10: // M_TT^S + { + const double rho_s = gp_ele->rho_s_curr[gp]; + val = (1 - poro) * rho_s * SolidProp->Heat_Capacity(rho_s); // SolidProp->Density() + break; + } - case 10: // M_TT^S - { - const double rho_s = gp_ele->rho_s_curr[gp]; - val= (1-poro)*rho_s*SolidProp->Heat_Capacity(rho_s);//SolidProp->Density() - break; - } + // case 11: + // case 12: + // case 13: + // case 14: + // val = 0.0; + // break; - // case 11: - // case 12: - // case 13: - // case 14: - // val = 0.0; - // break; - - case 15: // M_xx - p = ipol(p0, p1, theta, this); - T = ipol(T0, T1, theta, this); - X = ipol(X0, X1, theta, this); - val = poro* FluidProp->Density(eos_arg); - break; + case 15: // M_xx + p = ipol(p0, p1, theta, this); + T = ipol(T0, T1, theta, this); + X = ipol(X0, X1, theta, this); + val = poro * FluidProp->Density(eos_arg); + break; } return val; } - /************************************************************************** FEMLib-Method: Task: Calculate material coefficient for Laplacian matrix @@ -230,12 +230,12 @@ double CFiniteElementStd::CalCoefMassTNEQ(const int dof_index) **************************************************************************/ void CFiniteElementStd::CalCoefLaplaceTNEQ(const int dof_index) { - double const * const p0 = NodalVal0; - double const * const p1 = NodalVal1; - double const * const T0 = NodalVal_t0; - double const * const T1 = NodalVal_t1; - double const * const X0 = NodalVal_X0; - double const * const X1 = NodalVal_X1; + double const* const p0 = NodalVal0; + double const* const p1 = NodalVal1; + double const* const T0 = NodalVal_t0; + double const* const T1 = NodalVal_t1; + double const* const X0 = NodalVal_X0; + double const* const X1 = NodalVal_X1; double& p = eos_arg[0]; double& T = eos_arg[1]; @@ -249,7 +249,7 @@ void CFiniteElementStd::CalCoefLaplaceTNEQ(const int dof_index) double solid_heat_conductivity_tensor[9]; double diffusion_tensor[9]; - for (size_t i = 0; i < dim*dim; i++) + for (size_t i = 0; i < dim * dim; i++) { fluid_heat_conductivity_tensor[i] = 0.0; solid_heat_conductivity_tensor[i] = 0.0; @@ -257,131 +257,133 @@ void CFiniteElementStd::CalCoefLaplaceTNEQ(const int dof_index) mat[i] = 0.0; } - switch(dof_index) + switch (dof_index) { - case 0: - { - p = ipol(p0, p1, theta, this); - T = ipol(T0, T1, theta, this); - X = ipol(X0, X1, theta, this); - - double* tensor = MediaProp->PermeabilityTensor(Index); - double k_rel = 1.0; - if (MediaProp->flowlinearity_model > 0) + case 0: { - k_rel = MediaProp->NonlinearFlowFunction(Index, gp, theta, this); - } + p = ipol(p0, p1, theta, this); + T = ipol(T0, T1, theta, this); + X = ipol(X0, X1, theta, this); - double val; - if (GasMassForm) { - val = FluidProp->Density(eos_arg) - * k_rel / FluidProp->Viscosity(eos_arg); - } else { - val = k_rel / FluidProp->Viscosity(eos_arg); - } + double* tensor = MediaProp->PermeabilityTensor(Index); + double k_rel = 1.0; + if (MediaProp->flowlinearity_model > 0) + { + k_rel = MediaProp->NonlinearFlowFunction(Index, gp, theta, this); + } - for(size_t i=0;iDensity(eos_arg) * k_rel / FluidProp->Viscosity(eos_arg); + } + else + { + val = k_rel / FluidProp->Viscosity(eos_arg); + } + + for (size_t i = 0; i < dim * dim; i++) + { + mat[i] = tensor[i] * val; + } + break; } - break; - } - // case 1: - // case 2: - // case 3: - // case 4: - // break; + // case 1: + // case 2: + // case 3: + // case 4: + // break; - case 5: - { - p = ipol(p0, p1, theta, this); - T = ipol(T0, T1, theta, this); - X = ipol(X0, X1, theta, this); + case 5: + { + p = ipol(p0, p1, theta, this); + T = ipol(T0, T1, theta, this); + X = ipol(X0, X1, theta, this); - poro = MediaProp->Porosity(Index, theta); - const double lamf = FluidProp->HeatConductivity(eos_arg); + poro = MediaProp->Porosity(Index, theta); + const double lamf = FluidProp->HeatConductivity(eos_arg); - for (size_t i = 0; i < dim; i++) - { - fluid_heat_conductivity_tensor[i*dim+i] = poro * lamf; - } - for(size_t i=0; iPorosity(Index, theta); - const double lams = SolidProp->Heat_Conductivity(); + // case 6: + // case 7: + // case 8: + // case 9: + // break; - for (size_t i = 0; i < dim; i++) + case 10: { - solid_heat_conductivity_tensor[i*dim+i] = (1-poro) * lams; - } - for(size_t i=0; iPorosity(Index, theta); + const double lams = SolidProp->Heat_Conductivity(); + + for (size_t i = 0; i < dim; i++) + { + solid_heat_conductivity_tensor[i * dim + i] = (1 - poro) * lams; + } + for (size_t i = 0; i < dim * dim; i++) + { + mat[i] = solid_heat_conductivity_tensor[i]; + } + break; } - break; - } - // case 11: - // case 12: - // case 13: - // case 14: - // break; + // case 11: + // case 12: + // case 13: + // case 14: + // break; - case 15: - p = ipol(p0, p1, theta, this); - T = ipol(T0, T1, theta, this); - X = ipol(X0, X1, theta, this); + case 15: + p = ipol(p0, p1, theta, this); + T = ipol(T0, T1, theta, this); + X = ipol(X0, X1, theta, this); - poro = MediaProp->Porosity(Index, theta); - tort = MediaProp->TortuosityFunction(Index, unit, theta); - const double diffusion_coefficient_component = cp_vec[1]->CalcDiffusionCoefficientCP(Index, theta, pcs); //coefficient of reactive (2nd) component - const double rhoGR = FluidProp->Density(eos_arg); + poro = MediaProp->Porosity(Index, theta); + tort = MediaProp->TortuosityFunction(Index, unit, theta); + const double diffusion_coefficient_component + = cp_vec[1]->CalcDiffusionCoefficientCP(Index, theta, pcs); // coefficient of reactive (2nd) component + const double rhoGR = FluidProp->Density(eos_arg); - for (size_t i = 0; i < dim; i++) - { - diffusion_tensor[i*dim+i] = tort * poro * rhoGR * diffusion_coefficient_component; - } + for (size_t i = 0; i < dim; i++) + { + diffusion_tensor[i * dim + i] = tort * poro * rhoGR * diffusion_coefficient_component; + } - for(size_t i=0;iVelocity(0, gp), - gp_ele->Velocity(1, gp), - gp_ele->Velocity(2, gp) - }; + // Velocity + double vel[] = {gp_ele->Velocity(0, gp), gp_ele->Velocity(1, gp), gp_ele->Velocity(2, gp)}; for (int in = 0; in < pcs->dof; in++) { for (int jn = 0; jn < pcs->dof; jn++) { - double mat_fac = fkt*CalCoefAdvectionTNEQ(in*pcs->dof + jn); - for (int i = 0; i< nnodes; i++) + double mat_fac = fkt * CalCoefAdvectionTNEQ(in * pcs->dof + jn); + for (int i = 0; i < nnodes; i++) { - for (int j = 0; j< nnodes; j++) + for (int j = 0; j < nnodes; j++) { for (size_t k = 0; k < dim; k++) { - (*Advection)(i+in*nnodes, j+jn*nnodes) += mat_fac*shapefct[i]*vel[k]*dshapefct[k*nnodes+j]; + (*Advection)(i + in * nnodes, j + jn * nnodes) + += mat_fac * shapefct[i] * vel[k] * dshapefct[k * nnodes + j]; } } } @@ -416,26 +415,25 @@ void CFiniteElementStd::CalcAdvectionTNEQ() } } - /************************************************************************** - FEMLib-Method: - Task: Calculate material coefficient for advection matrix - Programing: - 01/2005 WW/OK Implementation - 03/2005 WW Heat transport - 07/2005 WW Change for geometry element object - 09/2005 SB - 07/2013 TN - 04/2015 CL + FEMLib-Method: + Task: Calculate material coefficient for advection matrix + Programing: + 01/2005 WW/OK Implementation + 03/2005 WW Heat transport + 07/2005 WW Change for geometry element object + 09/2005 SB + 07/2013 TN + 04/2015 CL **************************************************************************/ double CFiniteElementStd::CalCoefAdvectionTNEQ(const int dof_index) { - double const * const p0 = NodalVal0; - double const * const p1 = NodalVal1; - double const * const T0 = NodalVal_t0; - double const * const T1 = NodalVal_t1; - double const * const X0 = NodalVal_X0; - double const * const X1 = NodalVal_X1; + double const* const p0 = NodalVal0; + double const* const p1 = NodalVal1; + double const* const T0 = NodalVal_t0; + double const* const T1 = NodalVal_t1; + double const* const X0 = NodalVal_X0; + double const* const X1 = NodalVal_X1; double& p = eos_arg[0]; double& T = eos_arg[1]; @@ -447,84 +445,88 @@ double CFiniteElementStd::CalCoefAdvectionTNEQ(const int dof_index) if (!GasMassForm) { - switch(dof_index) + switch (dof_index) { - case 0: - val = 1.0/p; - break; + case 0: + val = 1.0 / p; + break; - case 1: - T = ipol(T0, T1, theta, this); - // T = (1-pcs->m_num->ls_theta)*interpolate(NodalVal_t0) + pcs->m_num->ls_theta*interpolate(NodalVal_t1); //NW include theta - val = -1.0/T; + case 1: + T = ipol(T0, T1, theta, this); + // T = (1-pcs->m_num->ls_theta)*interpolate(NodalVal_t0) + + // pcs->m_num->ls_theta*interpolate(NodalVal_t1); //NW include theta + val = -1.0 / T; - break; + break; // case 2: - case 3: - poro = MediaProp->Porosity(Index,pcs->m_num->ls_theta); - val = 0.0; - break; + case 3: + poro = MediaProp->Porosity(Index, pcs->m_num->ls_theta); + val = 0.0; + break; } } - switch(dof_index) + switch (dof_index) { - case 4: - if (FluidProp->beta_T == 0.0) - { - // TODO [CL] check logic - if (MediaProp->getFrictionPhase() == FiniteElement::FLUID) { - val = 0.0; - } else { - val = -1.0; + case 4: + if (FluidProp->beta_T == 0.0) + { + // TODO [CL] check logic + if (MediaProp->getFrictionPhase() == FiniteElement::FLUID) + { + val = 0.0; + } + else + { + val = -1.0; + } } - } - else - { - T = ipol(T0, T1, theta, this); - val = -FluidProp->beta_T * T; + else + { + T = ipol(T0, T1, theta, this); + val = -FluidProp->beta_T * T; - if (MediaProp->getFrictionPhase() == FiniteElement::FLUID) { - val += 1.0; + if (MediaProp->getFrictionPhase() == FiniteElement::FLUID) + { + val += 1.0; + } } - } - break; - - case 5: - p = ipol(p0, p1, theta, this); - T = ipol(T0, T1, theta, this); - X = ipol(X0, X1, theta, this); - - val = FluidProp->Density(eos_arg) * FluidProp->SpecificHeatCapacity(eos_arg); - break; - - // case 6: - // case 7: - // case 8: - // case 9: - // case 10: - // case 11: - // case 12: - // case 13: - // case 14: - // val = 0.0; - // break; - - case 15: - p = ipol(p0, p1, theta, this); - T = ipol(T0, T1, theta, this); - X = ipol(X0, X1, theta, this); - - val = FluidProp->Density(eos_arg); - break; + break; + + case 5: + p = ipol(p0, p1, theta, this); + T = ipol(T0, T1, theta, this); + X = ipol(X0, X1, theta, this); + + val = FluidProp->Density(eos_arg) * FluidProp->SpecificHeatCapacity(eos_arg); + break; + + // case 6: + // case 7: + // case 8: + // case 9: + // case 10: + // case 11: + // case 12: + // case 13: + // case 14: + // val = 0.0; + // break; + + case 15: + p = ipol(p0, p1, theta, this); + T = ipol(T0, T1, theta, this); + X = ipol(X0, X1, theta, this); + + val = FluidProp->Density(eos_arg); + break; } return val; } - /*************************************************************************** FEMLib-Method: Task: Assembly of ContentMatrix for @@ -534,7 +536,7 @@ double CFiniteElementStd::CalCoefAdvectionTNEQ(const int dof_index) **************************************************************************/ void CFiniteElementStd::CalcContentTNEQ() { - int gp_r=0, gp_s=0, gp_t=0; + int gp_r = 0, gp_s = 0, gp_t = 0; for (gp = 0; gp < nGaussPoints; gp++) { double fkt = GetGaussData(gp, gp_r, gp_s, gp_t); @@ -544,12 +546,12 @@ void CFiniteElementStd::CalcContentTNEQ() { for (int jn = 0; jn < pcs->dof; jn++) { - double mat_fac = fkt*CalCoefContentTNEQ(in*pcs->dof + jn); - for (int i = 0; i< nnodes; i++) + double mat_fac = fkt * CalCoefContentTNEQ(in * pcs->dof + jn); + for (int i = 0; i < nnodes; i++) { - for (int j = 0; j< nnodes; j++) + for (int j = 0; j < nnodes; j++) { - (*Content)(i+in*nnodes, j+jn*nnodes) += mat_fac *shapefct[i]*shapefct[j]; + (*Content)(i + in * nnodes, j + jn * nnodes) += mat_fac * shapefct[i] * shapefct[j]; } } } @@ -557,7 +559,6 @@ void CFiniteElementStd::CalcContentTNEQ() } } - /************************************************************************** FEMLib-Method: Programing: @@ -566,10 +567,10 @@ void CFiniteElementStd::CalcContentTNEQ() **************************************************************************/ double CFiniteElementStd::CalCoefContentTNEQ(const int dof_index) { - double const * const p0 = NodalVal0; - double const * const p1 = NodalVal1; - double const * const T0 = NodalVal_t0; - double const * const T1 = NodalVal_t1; + double const* const p0 = NodalVal0; + double const* const p1 = NodalVal1; + double const* const T0 = NodalVal_t0; + double const* const T1 = NodalVal_t1; // double const * const X0 = NodalVal_X0; // double const * const X1 = NodalVal_X1; @@ -584,64 +585,65 @@ double CFiniteElementStd::CalCoefContentTNEQ(const int dof_index) double val = 0.0; - switch(dof_index) + switch (dof_index) { - // gas flow - // case 0: - // case 1: - // case 2: - // case 3: - // val = 0.0; - // break; - - // heat in gas - // case 4: - // val = 0.0;//-phi_g^-1 * grad phi_g - // break; - - case 5: // T T - val = MediaProp->HeatTransferCoefficient(Index, theta, this); - break; - case 6: // T T^S - val = - MediaProp->HeatTransferCoefficient(Index, theta, this); - break; - - // case 7: // T x - // case 8: // T^S p - // break; - - case 9: // T^ST - p = ipol(p0, p1, theta, this); - T = ipol(T0, T1, theta, this); - X = 1.0; //TN - only reactive component for specific heat capacity here! - val = - MediaProp->HeatTransferCoefficient(Index, theta, this); - val -= (1.0-MediaProp->Porosity(Index, theta))*gp_ele->q_R[gp]*FluidProp->SpecificHeatCapacity(eos_arg); //TN - break; - - case 10: // T^S T^S - val = MediaProp->HeatTransferCoefficient(Index, theta, this); - p = ipol(p0, p1, theta, this); - T = ipol(T0, T1, theta, this); - X = 1.0; //TN - only reactive component for specific heat capacity here! - val += (1.0-MediaProp->Porosity(Index, theta))*gp_ele->q_R[gp]*FluidProp->SpecificHeatCapacity(eos_arg); //TN - break; - - // case 11: - // case 12: - // case 13: - // case 14: - // val = 0.0; - // break; - - case 15: // x x - val = (MediaProp->Porosity(Index, theta) - 1.0) * gp_ele->q_R[gp]; - break; + // gas flow + // case 0: + // case 1: + // case 2: + // case 3: + // val = 0.0; + // break; + + // heat in gas + // case 4: + // val = 0.0;//-phi_g^-1 * grad phi_g + // break; + + case 5: // T T + val = MediaProp->HeatTransferCoefficient(Index, theta, this); + break; + case 6: // T T^S + val = -MediaProp->HeatTransferCoefficient(Index, theta, this); + break; + + // case 7: // T x + // case 8: // T^S p + // break; + + case 9: // T^ST + p = ipol(p0, p1, theta, this); + T = ipol(T0, T1, theta, this); + X = 1.0; // TN - only reactive component for specific heat capacity here! + val = -MediaProp->HeatTransferCoefficient(Index, theta, this); + val -= (1.0 - MediaProp->Porosity(Index, theta)) * gp_ele->q_R[gp] + * FluidProp->SpecificHeatCapacity(eos_arg); // TN + break; + + case 10: // T^S T^S + val = MediaProp->HeatTransferCoefficient(Index, theta, this); + p = ipol(p0, p1, theta, this); + T = ipol(T0, T1, theta, this); + X = 1.0; // TN - only reactive component for specific heat capacity here! + val += (1.0 - MediaProp->Porosity(Index, theta)) * gp_ele->q_R[gp] + * FluidProp->SpecificHeatCapacity(eos_arg); // TN + break; + + // case 11: + // case 12: + // case 13: + // case 14: + // val = 0.0; + // break; + + case 15: // x x + val = (MediaProp->Porosity(Index, theta) - 1.0) * gp_ele->q_R[gp]; + break; } return val; } - /*************************************************************************** GeoSys - Funktion: Assemble_RHS_TNEQ: @@ -649,8 +651,9 @@ double CFiniteElementStd::CalCoefContentTNEQ(const int dof_index) **************************************************************************/ void CFiniteElementStd::Assemble_RHS_TNEQ() { - int gp_r=0, gp_s=0, gp_t=0; - for (int i = 0; i < pcs->dof*nnodes; i++) NodalVal[i] = 0.0; + int gp_r = 0, gp_s = 0, gp_t = 0; + for (int i = 0; i < pcs->dof * nnodes; i++) + NodalVal[i] = 0.0; // Loop over Gauss points for (gp = 0; gp < nGaussPoints; gp++) @@ -661,47 +664,45 @@ void CFiniteElementStd::Assemble_RHS_TNEQ() ComputeShapefct(1); ComputeGradShapefct(1); // this is needed for CalCoef_RHS_TNEQ() !! - for (int ii=0; iidof; ii++) + for (int ii = 0; ii < pcs->dof; ii++) { const double fac = CalCoef_RHS_TNEQ(ii); for (int i = 0; i < nnodes; i++) - NodalVal[i+ii*nnodes] += fac*fkt*shapefct[i]; + NodalVal[i + ii * nnodes] += fac * fkt * shapefct[i]; } } - for (int ii=0; iidof; ii++) + for (int ii = 0; ii < pcs->dof; ii++) { const long i_sh = NodeShift[ii]; - const int ii_sh = ii*nnodes; - for (int i=0; iDensity(eos_arg) * poro * FluidProp->specific_heat_source; - break; + val = FluidProp->Density(eos_arg) * poro * FluidProp->specific_heat_source; + break; - case 2: - { - const double H_vap = - SolidProp->reaction_enthalpy; //sign convention: defined negative for exothermic composition reaction but equ. written as: AB + \Delta H <--> A + B + case 2: + { + const double H_vap = -SolidProp->reaction_enthalpy; // sign convention: defined negative for exothermic + // composition reaction but equ. written as: AB + \Delta + // H <--> A + B - val = (1.0-poro) * q_r * H_vap; - val += gp_ele->rho_s_curr[gp] * (1.0-poro) * SolidProp->specific_heat_source; + val = (1.0 - poro) * q_r * H_vap; + val += gp_ele->rho_s_curr[gp] * (1.0 - poro) * SolidProp->specific_heat_source; - if (MediaProp->getFrictionPhase() == FiniteElement::SOLID) - { - // HS, implementing the friction term here. + if (MediaProp->getFrictionPhase() == FiniteElement::SOLID) + { + // HS, implementing the friction term here. - const double* tensor = MediaProp->PermeabilityTensor(Index); // pointer to permeability tensor; - double k_rel = 1.0; // relative permeability; + const double* tensor = MediaProp->PermeabilityTensor(Index); // pointer to permeability tensor; + double k_rel = 1.0; // relative permeability; - // HS, added to get viscosity------------ - pg = ipol(p0, p1, theta, this); - Tg = ipol(T0, T1, theta, this); - Xw = ipol(X0, X1, theta, this); - // end of adding eos_arg----------------- + // HS, added to get viscosity------------ + pg = ipol(p0, p1, theta, this); + Tg = ipol(T0, T1, theta, this); + Xw = ipol(X0, X1, theta, this); + // end of adding eos_arg----------------- - if (MediaProp->flowlinearity_model > 0) - { - k_rel = MediaProp->NonlinearFlowFunction(Index, gp, theta, this); - } + if (MediaProp->flowlinearity_model > 0) + { + k_rel = MediaProp->NonlinearFlowFunction(Index, gp, theta, this); + } - double* grad_pg = new double[dim]; // gradient of gas pressure. + double* grad_pg = new double[dim]; // gradient of gas pressure. - for (size_t i=0; iViscosity(eos_arg); } - friction_term += vel_Darcy * grad_pg[i] * k_rel / FluidProp->Viscosity(eos_arg); - } - val += friction_term; + val += friction_term; - delete[] grad_pg; // clean tmp memory - // delete[] vel_Darcy; // clean the memory of velocity darcy + delete[] grad_pg; // clean tmp memory + // delete[] vel_Darcy; // clean the memory of velocity darcy + } + break; } - break; - } - case 3: - val = (poro - 1.0) * q_r; - break; + case 3: + val = (poro - 1.0) * q_r; + break; } return val; } - - } diff --git a/FEM/fem_ele_vec.cpp b/FEM/fem_ele_vec.cpp old mode 100755 new mode 100644 index fc1e34389..f068eeb6e --- a/FEM/fem_ele_vec.cpp +++ b/FEM/fem_ele_vec.cpp @@ -21,7 +21,7 @@ #include "pcs_dm.h" #include "rf_mfp_new.h" #include "rf_msp_new.h" -//Time step +// Time step //#include "rf_tim_new.h" // MSHLib //#include "msh_elem.h" @@ -29,15 +29,15 @@ //#include "fem_ele.h" #include "fem_ele_vec.h" //#include "rf_pcs.h" -#include "tools.h" //12.2009. WW +#include "tools.h" //12.2009. WW // Equation #if defined(NEW_EQS) #include "equation_class.h" using Math_Group::CSparseMatrix; #endif // -#define COMP_MOL_MASS_AIR 28.96 // kg/kmol WW 28.96 -#define GAS_CONSTANT 8314.41 // J/(kmol*K) WW +#define COMP_MOL_MASS_AIR 28.96 // kg/kmol WW 28.96 +#define GAS_CONSTANT 8314.41 // J/(kmol*K) WW #if defined(USE_PETSC) // || defined(other parallel libs)//07.3013. WW #include "PETSC/PETScLinearSolver.h" @@ -53,15 +53,11 @@ namespace FiniteElement // class Element_DM // Constructor of class Element_DM -CFiniteElementVec::CFiniteElementVec(process::CRFProcessDeformation* dm_pcs, - const int C_Sys_Flad, - const int order) - : CElement(C_Sys_Flad, - order), pcs(dm_pcs), PressureC(NULL), PressureC_S(NULL), PressureC_S_dp(NULL), - b_rhs(NULL) +CFiniteElementVec::CFiniteElementVec(process::CRFProcessDeformation* dm_pcs, const int C_Sys_Flad, const int order) + : CElement(C_Sys_Flad, order), pcs(dm_pcs), PressureC(NULL), PressureC_S(NULL), PressureC_S_dp(NULL), b_rhs(NULL) { int i; - excavation = false; // 12.2009. WW + excavation = false; // 12.2009. WW S_Water = 1.0; Tem = 273.15 + 23.0; @@ -72,11 +68,11 @@ CFiniteElementVec::CFiniteElementVec(process::CRFProcessDeformation* dm_pcs, #endif AuxNodal2 = NULL; - Idx_Vel = NULL; + Idx_Vel = NULL; X0 = n_jump = pr_stress = NULL; // ns = 4; - if(dim == 3) + if (dim == 3) ns = 6; // 10.11.2010. WW AuxNodal0 = new double[8]; @@ -90,12 +86,12 @@ CFiniteElementVec::CFiniteElementVec(process::CRFProcessDeformation* dm_pcs, strain_ne = new double[ns]; stress_ne = new double[ns]; stress0 = new double[ns]; - for(i = 0; i < 4; i++) + for (i = 0; i < 4; i++) NodeShift[i] = pcs->Shift[i]; - if(dm_pcs->pcs_type_name_vector[0].find("DYNAMIC") != std::string::npos) + if (dm_pcs->pcs_type_name_vector[0].find("DYNAMIC") != std::string::npos) { // Indecex in nodal value table - Idx_Vel = new int [3]; + Idx_Vel = new int[3]; Idx_dm0[0] = pcs->GetNodeValueIndex("ACCELERATION_X1"); Idx_dm0[1] = pcs->GetNodeValueIndex("ACCELERATION_Y1"); Idx_dm1[0] = Idx_dm0[0] + 1; @@ -103,7 +99,7 @@ CFiniteElementVec::CFiniteElementVec(process::CRFProcessDeformation* dm_pcs, Idx_Vel[0] = pcs->GetNodeValueIndex("VELOCITY_DM_X"); Idx_Vel[1] = pcs->GetNodeValueIndex("VELOCITY_DM_Y"); // if(problem_dimension_dm==3) - if(dim == 3) + if (dim == 3) { Idx_dm0[2] = pcs->GetNodeValueIndex("ACCELERATION_Z1"); Idx_dm1[2] = Idx_dm1[2] + 1; @@ -120,7 +116,7 @@ CFiniteElementVec::CFiniteElementVec(process::CRFProcessDeformation* dm_pcs, { dynamic = false; dAcceleration = NULL; - //Idx_Vel[0] = Idx_Vel[1] = Idx_Vel[2] = -1; + // Idx_Vel[0] = Idx_Vel[1] = Idx_Vel[2] = -1; beta2 = bbeta1 = 1.0; // Indecex in nodal value table Idx_dm0[0] = pcs->GetNodeValueIndex("DISPLACEMENT_X1"); @@ -129,7 +125,7 @@ CFiniteElementVec::CFiniteElementVec(process::CRFProcessDeformation* dm_pcs, Idx_dm1[1] = Idx_dm0[1] + 1; // if(problem_dimension_dm==3) - if(dim == 3) + if (dim == 3) { Idx_dm0[2] = pcs->GetNodeValueIndex("DISPLACEMENT_Z1"); Idx_dm1[2] = Idx_dm0[2] + 1; @@ -157,20 +153,20 @@ CFiniteElementVec::CFiniteElementVec(process::CRFProcessDeformation* dm_pcs, vec_B_matrix_T.resize(20); for (i = 0; i < (int)vec_B_matrix.size(); i++) { - switch(dim) + switch (dim) { - case 2: - vec_B_matrix[i] = new Matrix(4,2); - vec_B_matrix_T[i] = new Matrix(2,4); - break; - case 3: - vec_B_matrix[i] = new Matrix(6,3); - vec_B_matrix_T[i] = new Matrix(3,6); - break; + case 2: + vec_B_matrix[i] = new Matrix(4, 2); + vec_B_matrix_T[i] = new Matrix(2, 4); + break; + case 3: + vec_B_matrix[i] = new Matrix(6, 3); + vec_B_matrix_T[i] = new Matrix(3, 6); + break; } } // 10.11.2010. WW - if(enhanced_strain_dm) + if (enhanced_strain_dm) { X0 = new double[3]; n_jump = new double[3]; @@ -178,84 +174,84 @@ CFiniteElementVec::CFiniteElementVec(process::CRFProcessDeformation* dm_pcs, } // - switch(dim) - { - case 2: - ns = 4; - B_matrix = new Matrix(4,2); - B_matrix_T = new Matrix(2,4); - dstress = new double[4]; - dstrain = new double[4]; - De = new Matrix(4,4); - ConsistDep = new Matrix(4,4); - AuxMatrix = new Matrix(2,2); - AuxMatrix2 = new Matrix(2,4); //NW - Disp = new double[18]; - Temp = new double[9]; - T1 = new double[9]; - - Sxx = new double[9]; - Syy = new double[9]; - Szz = new double[9]; - Sxy = new double[9]; - pstr = new double[9]; - - Sxz = NULL; - Syz = NULL; - - if(enhanced_strain_dm) - { - NodesInJumpedA = new bool[9]; - Ge = new Matrix(4,2); - Pe = new Matrix(2,4); - PeDe = new Matrix(2,4); - - BDG = new Matrix(2,18); - PDB = new Matrix(18,2); - DtD = new Matrix(2,2); - } - break; - case 3: - ns = 6; - B_matrix = new Matrix(6,3); - B_matrix_T = new Matrix(3,6); - dstress = new double[6]; - dstrain = new double[6]; - De = new Matrix(6,6); - ConsistDep = new Matrix(6,6); - AuxMatrix = new Matrix(3,3); - AuxMatrix2 = new Matrix(3,6); //NW - Disp = new double[60]; - Temp = new double[20]; - T1 = new double[20]; - - Sxx = new double[20]; - Syy = new double[20]; - Szz = new double[20]; - Sxy = new double[20]; - Sxz = new double[20]; - Syz = new double[20]; - pstr = new double[20]; - - // Indecex in nodal value table - Idx_Strain[4] = pcs->GetNodeValueIndex("STRAIN_XZ"); - Idx_Strain[5] = pcs->GetNodeValueIndex("STRAIN_YZ"); - // - Idx_Stress[4] = pcs->GetNodeValueIndex("STRESS_XZ"); - Idx_Stress[5] = pcs->GetNodeValueIndex("STRESS_YZ"); - break; + switch (dim) + { + case 2: + ns = 4; + B_matrix = new Matrix(4, 2); + B_matrix_T = new Matrix(2, 4); + dstress = new double[4]; + dstrain = new double[4]; + De = new Matrix(4, 4); + ConsistDep = new Matrix(4, 4); + AuxMatrix = new Matrix(2, 2); + AuxMatrix2 = new Matrix(2, 4); // NW + Disp = new double[18]; + Temp = new double[9]; + T1 = new double[9]; + + Sxx = new double[9]; + Syy = new double[9]; + Szz = new double[9]; + Sxy = new double[9]; + pstr = new double[9]; + + Sxz = NULL; + Syz = NULL; + + if (enhanced_strain_dm) + { + NodesInJumpedA = new bool[9]; + Ge = new Matrix(4, 2); + Pe = new Matrix(2, 4); + PeDe = new Matrix(2, 4); + + BDG = new Matrix(2, 18); + PDB = new Matrix(18, 2); + DtD = new Matrix(2, 2); + } + break; + case 3: + ns = 6; + B_matrix = new Matrix(6, 3); + B_matrix_T = new Matrix(3, 6); + dstress = new double[6]; + dstrain = new double[6]; + De = new Matrix(6, 6); + ConsistDep = new Matrix(6, 6); + AuxMatrix = new Matrix(3, 3); + AuxMatrix2 = new Matrix(3, 6); // NW + Disp = new double[60]; + Temp = new double[20]; + T1 = new double[20]; + + Sxx = new double[20]; + Syy = new double[20]; + Szz = new double[20]; + Sxy = new double[20]; + Sxz = new double[20]; + Syz = new double[20]; + pstr = new double[20]; + + // Indecex in nodal value table + Idx_Strain[4] = pcs->GetNodeValueIndex("STRAIN_XZ"); + Idx_Strain[5] = pcs->GetNodeValueIndex("STRAIN_YZ"); + // + Idx_Stress[4] = pcs->GetNodeValueIndex("STRESS_XZ"); + Idx_Stress[5] = pcs->GetNodeValueIndex("STRESS_YZ"); + break; } *B_matrix = 0.0; *B_matrix_T = 0.0; - if(pcs->Memory_Type == 0) // Do not store local matrices + if (pcs->Memory_Type == 0) // Do not store local matrices { - Stiffness = new Matrix(60,60); + Stiffness = new Matrix(60, 60); RHS = new Vec(60); - if(H_Process) - PressureC = new Matrix(60,20); + if (H_Process) + PressureC = new Matrix(60, 20); } - else // Local matrices stored and allocated the pcs.cpp; + else // Local matrices stored and allocated the pcs.cpp; { Stiffness = NULL; RHS = NULL; @@ -266,7 +262,7 @@ CFiniteElementVec::CFiniteElementVec(process::CRFProcessDeformation* dm_pcs, // Fluid coupling m_mfp = NULL; // Medium property - m_mmp = NULL; // + m_mmp = NULL; // // Coupling Flow_Type = -1; @@ -278,7 +274,7 @@ CFiniteElementVec::CFiniteElementVec(process::CRFProcessDeformation* dm_pcs, if (isFlowProcess(pcs_vector[i]->getProcessType())) { h_pcs = pcs_vector[i]; - //25.04.2008, 04.09.2008 WW + // 25.04.2008, 04.09.2008 WW if (h_pcs->type == 1 || h_pcs->type == 41) { // if (h_pcs->pcs_type_name.find("GROUND") != string::npos) @@ -287,50 +283,50 @@ CFiniteElementVec::CFiniteElementVec(process::CRFProcessDeformation* dm_pcs, Flow_Type = 10; else Flow_Type = 0; - //25.08.2005. WW + // 25.08.2005. WW } else if (h_pcs->type == 14 || h_pcs->type == 22) Flow_Type = 1; else if (h_pcs->type == 1212 || h_pcs->type == 42) { - Flow_Type = 2; //25.04.2008. WW + Flow_Type = 2; // 25.04.2008. WW // 07.2011. WW - PressureC_S = new Matrix(60,20); - if(pcs->m_num->nls_method == 1 && h_pcs->type == 42) // Newton-raphson. WW - PressureC_S_dp = new Matrix(60,20); + PressureC_S = new Matrix(60, 20); + if (pcs->m_num->nls_method == 1 && h_pcs->type == 42) // Newton-raphson. WW + PressureC_S_dp = new Matrix(60, 20); } // WW idx_P0 = pcs->GetNodeValueIndex("POROPRESSURE0"); break; // } else if (pcs_vector[i]->pcs_type_name.find("PS_GLOBAL") != string::npos) { - } // TF + } // TF else if (pcs_vector[i]->getProcessType() == PS_GLOBAL) { h_pcs = pcs_vector[i]; if (h_pcs->type == 1313) - Flow_Type = 3; //05.05.2009. PCH + Flow_Type = 3; // 05.05.2009. PCH break; } } - if(Flow_Type == 0) + if (Flow_Type == 0) { idx_P1 = h_pcs->GetNodeValueIndex("PRESSURE1") + 1; - if(dynamic) + if (dynamic) { idx_P = h_pcs->GetNodeValueIndex("PRESSURE1"); idx_P1 = h_pcs->GetNodeValueIndex("PRESSURE_RATE1"); } } - if(Flow_Type == 10) + if (Flow_Type == 10) idx_P1 = h_pcs->GetNodeValueIndex("HEAD") + 1; - else if(Flow_Type == 1) + else if (Flow_Type == 1) { idx_P1 = h_pcs->GetNodeValueIndex("PRESSURE1") + 1; idx_P1_0 = h_pcs->GetNodeValueIndex("PRESSURE1"); idx_S0 = h_pcs->GetNodeValueIndex("SATURATION1"); idx_S = h_pcs->GetNodeValueIndex("SATURATION1") + 1; } - else if(Flow_Type == 2) + else if (Flow_Type == 2) { idx_P1 = h_pcs->GetNodeValueIndex("PRESSURE1") + 1; idx_P2 = h_pcs->GetNodeValueIndex("PRESSURE2") + 1; @@ -338,7 +334,7 @@ CFiniteElementVec::CFiniteElementVec(process::CRFProcessDeformation* dm_pcs, idx_S = h_pcs->GetNodeValueIndex("SATURATION1") + 1; AuxNodal2 = new double[8]; } - else if(Flow_Type == 3) + else if (Flow_Type == 3) { idx_P1 = h_pcs->GetNodeValueIndex("PRESSURE1") + 1; idx_P2 = h_pcs->GetNodeValueIndex("PRESSURE2"); @@ -356,21 +352,20 @@ CFiniteElementVec::CFiniteElementVec(process::CRFProcessDeformation* dm_pcs, t_pcs = pcs_vector[i]; break; } - if(T_Flag) + if (T_Flag) { - idx_T0 = t_pcs->GetNodeValueIndex("TEMPERATURE1"); - idx_T1 = idx_T0 + 1; + idx_T0 = t_pcs->GetNodeValueIndex("TEMPERATURE1"); + idx_T1 = idx_T0 + 1; } // // Time unit factor time_unit_factor = pcs->time_unit_factor; #if defined(USE_PETSC) // || defined(other parallel libs)//05~07.3013. WW - idxm = new int[60]; //> global indices of local matrix rows - idxn = new int[60]; //> global indices of local matrix columns + idxm = new int[60]; //> global indices of local matrix rows + idxn = new int[60]; //> global indices of local matrix columns local_idx = new int[60]; //> local index for local assemble #endif - } // Constructor of class Element_DM @@ -378,33 +373,33 @@ CFiniteElementVec::~CFiniteElementVec() { delete B_matrix; delete B_matrix_T; - delete [] dstress; - delete [] dstrain; + delete[] dstress; + delete[] dstrain; delete De; delete ConsistDep; delete AuxMatrix; - delete AuxMatrix2; //NW - delete [] Disp; - delete [] Temp; - delete [] T1; - delete [] Sxx; - delete [] Syy; - delete [] Szz; - delete [] Sxy; - delete [] pstr; - delete [] Idx_Strain; - delete [] Idx_Stress; - delete [] strain_ne; - delete [] stress_ne; - delete [] stress0; - if(Sxz) - delete [] Sxz; - if(Syz) - delete [] Syz; - if(AuxNodal2) - delete [] AuxNodal2; - - if(dynamic) + delete AuxMatrix2; // NW + delete[] Disp; + delete[] Temp; + delete[] T1; + delete[] Sxx; + delete[] Syy; + delete[] Szz; + delete[] Sxy; + delete[] pstr; + delete[] Idx_Strain; + delete[] Idx_Stress; + delete[] strain_ne; + delete[] stress_ne; + delete[] stress0; + if (Sxz) + delete[] Sxz; + if (Syz) + delete[] Syz; + if (AuxNodal2) + delete[] AuxNodal2; + + if (dynamic) { delete Mass; delete dAcceleration; @@ -412,7 +407,7 @@ CFiniteElementVec::~CFiniteElementVec() dAcceleration = NULL; } - if(pcs->Memory_Type == 0) // Do not store local matrices + if (pcs->Memory_Type == 0) // Do not store local matrices { delete Stiffness; delete RHS; @@ -420,7 +415,7 @@ CFiniteElementVec::~CFiniteElementVec() RHS = NULL; } - if(enhanced_strain_dm) + if (enhanced_strain_dm) { delete NodesInJumpedA; delete Ge; @@ -439,12 +434,12 @@ CFiniteElementVec::~CFiniteElementVec() DtD = NULL; } - //11.07.2011. WW - if(PressureC) + // 11.07.2011. WW + if (PressureC) delete PressureC; - if(PressureC_S) + if (PressureC_S) delete PressureC_S; - if(PressureC_S_dp) + if (PressureC_S_dp) delete PressureC_S_dp; B_matrix = NULL; @@ -454,7 +449,7 @@ CFiniteElementVec::~CFiniteElementVec() De = NULL; ConsistDep = NULL; AuxMatrix = NULL; - AuxMatrix2 = NULL; //NW + AuxMatrix2 = NULL; // NW Disp = NULL; Temp = NULL; T1 = NULL; @@ -466,20 +461,20 @@ CFiniteElementVec::~CFiniteElementVec() Syz = NULL; pstr = NULL; // 10.11.2010. WW - if(X0) - delete [] X0; - if(n_jump) - delete [] n_jump; - if(pr_stress) - delete [] pr_stress; - if(Idx_Vel) - delete [] Idx_Vel; + if (X0) + delete[] X0; + if (n_jump) + delete[] n_jump; + if (pr_stress) + delete[] pr_stress; + if (Idx_Vel) + delete[] Idx_Vel; X0 = n_jump = pr_stress = NULL; - delete [] AuxNodal; - delete [] AuxNodal_S0; - delete [] AuxNodal_S; - delete [] AuxNodal1; - AuxNodal = AuxNodal_S0 = AuxNodal_S = AuxNodal1 = NULL; + delete[] AuxNodal; + delete[] AuxNodal_S0; + delete[] AuxNodal_S; + delete[] AuxNodal1; + AuxNodal = AuxNodal_S0 = AuxNodal_S = AuxNodal1 = NULL; Idx_Vel = NULL; // Idx_Strain = NULL; @@ -489,7 +484,7 @@ CFiniteElementVec::~CFiniteElementVec() stress0 = NULL; // - //NW + // NW for (int i = 0; i < (int)vec_B_matrix.size(); i++) { delete vec_B_matrix[i]; @@ -519,20 +514,20 @@ void CFiniteElementVec::SetMaterial() //...................................................................... // MSP smat = msp_vector[MatGroup]; - //WX:01.2013. time dependent E nv aniso - if(smat->Time_Dependent_E_nv_mode==2) + // WX:01.2013. time dependent E nv aniso + if (smat->Time_Dependent_E_nv_mode == 2) smat->CalculateTransformMatrixFromNormalVector(ele_dim); smat->axisymmetry = pcs->m_msh->isAxisymmetry(); // Single yield surface model - if(smat->Plasticity_type == 2) + if (smat->Plasticity_type == 2) smat->ResizeMatricesSYS(ele_dim); //...................................................................... // MFP - if(F_Flag) + if (F_Flag) { m_mfp = MFPGet("LIQUID"); // YD - if(!m_mfp) - m_mfp = mfp_vector[0]; //OK + if (!m_mfp) + m_mfp = mfp_vector[0]; // OK } //...................................................................... // MMP @@ -556,16 +551,16 @@ void CFiniteElementVec::SetMemory() ElementMatrix* EleMat = NULL; // Prepare local matrices - if(pcs->Memory_Type == 0) + if (pcs->Memory_Type == 0) { // If local matrices are not stored, resize the matrix size = dim * nnodesHQ; Stiffness->LimitSize(size, size); - if(PressureC) + if (PressureC) PressureC->LimitSize(size, nnodes); - if(PressureC_S) + if (PressureC_S) PressureC_S->LimitSize(size, nnodes); - if(PressureC_S_dp) + if (PressureC_S_dp) PressureC_S_dp->LimitSize(size, nnodes); RHS->LimitSize(size); } @@ -574,11 +569,11 @@ void CFiniteElementVec::SetMemory() EleMat = pcs->Ele_Matrices[Index]; Stiffness = EleMat->GetStiffness(); RHS = EleMat->GetRHS(); - if(PressureC) + if (PressureC) PressureC = EleMat->GetCouplingMatrixA(); } - if(dynamic) + if (dynamic) { Mass->LimitSize(nnodesHQ, nnodesHQ); dAcceleration->LimitSize(nnodesHQ * dim); @@ -600,66 +595,66 @@ void CFiniteElementVec::SetMemory() **************************************************************************/ void CFiniteElementVec::setB_Matrix(const int LocalIndex) { - switch(dim) + switch (dim) { - case 2: - // B_11, dN/dx - (*B_matrix)(0,0) = dshapefctHQ[LocalIndex]; - // B_12, 0.0 - (*B_matrix)(0,1) = 0.0; + case 2: + // B_11, dN/dx + (*B_matrix)(0, 0) = dshapefctHQ[LocalIndex]; + // B_12, 0.0 + (*B_matrix)(0, 1) = 0.0; - if(axisymmetry) // Axisymmtry - { - // B_21, N/r - (*B_matrix)(1,0) = shapefctHQ[LocalIndex] / Radius; - // B_22, 0.0 - (*B_matrix)(1,1) = 0.0; - // B_31, 0.0 - (*B_matrix)(2,0) = 0.0; - // B_32, dN/dz - (*B_matrix)(2,1) = dshapefctHQ[nnodesHQ + LocalIndex]; - } - else - { - // B_21, 0.0 - (*B_matrix)(1,0) = 0.0; + if (axisymmetry) // Axisymmtry + { + // B_21, N/r + (*B_matrix)(1, 0) = shapefctHQ[LocalIndex] / Radius; + // B_22, 0.0 + (*B_matrix)(1, 1) = 0.0; + // B_31, 0.0 + (*B_matrix)(2, 0) = 0.0; + // B_32, dN/dz + (*B_matrix)(2, 1) = dshapefctHQ[nnodesHQ + LocalIndex]; + } + else + { + // B_21, 0.0 + (*B_matrix)(1, 0) = 0.0; + // B_22, dN/dy + (*B_matrix)(1, 1) = dshapefctHQ[nnodesHQ + LocalIndex]; + // B_31, 0.0 + (*B_matrix)(2, 0) = 0.0; + // B_32, 0.0 + (*B_matrix)(2, 1) = 0.0; + } + // B_41, dN/dy + (*B_matrix)(3, 0) = dshapefctHQ[nnodesHQ + LocalIndex]; + // B_42, dN/dx + (*B_matrix)(3, 1) = dshapefctHQ[LocalIndex]; + + break; + case 3: + // B_11, dN/dx + (*B_matrix)(0, 0) = dshapefctHQ[LocalIndex]; // B_22, dN/dy - (*B_matrix)(1,1) = dshapefctHQ[nnodesHQ + LocalIndex]; - // B_31, 0.0 - (*B_matrix)(2,0) = 0.0; - // B_32, 0.0 - (*B_matrix)(2,1) = 0.0; - } - // B_41, dN/dy - (*B_matrix)(3,0) = dshapefctHQ[nnodesHQ + LocalIndex]; - // B_42, dN/dx - (*B_matrix)(3,1) = dshapefctHQ[LocalIndex]; - - break; - case 3: - // B_11, dN/dx - (*B_matrix)(0,0) = dshapefctHQ[LocalIndex]; - // B_22, dN/dy - (*B_matrix)(1,1) = dshapefctHQ[nnodesHQ + LocalIndex]; - // B_33, dN/dz - (*B_matrix)(2,2) = dshapefctHQ[2 * nnodesHQ + LocalIndex]; - // - // B_41, dN/dy - (*B_matrix)(3,0) = dshapefctHQ[nnodesHQ + LocalIndex]; - // B_42, dN/dx - (*B_matrix)(3,1) = dshapefctHQ[LocalIndex]; - // - // B_51, dN/dz - (*B_matrix)(4,0) = dshapefctHQ[2 * nnodesHQ + LocalIndex]; - // B_53, dN/dx - (*B_matrix)(4,2) = dshapefctHQ[LocalIndex]; - // - // B_62, dN/dz - (*B_matrix)(5,1) = dshapefctHQ[2 * nnodesHQ + LocalIndex]; - // B_63, dN/dy - (*B_matrix)(5,2) = dshapefctHQ[nnodesHQ + LocalIndex]; + (*B_matrix)(1, 1) = dshapefctHQ[nnodesHQ + LocalIndex]; + // B_33, dN/dz + (*B_matrix)(2, 2) = dshapefctHQ[2 * nnodesHQ + LocalIndex]; + // + // B_41, dN/dy + (*B_matrix)(3, 0) = dshapefctHQ[nnodesHQ + LocalIndex]; + // B_42, dN/dx + (*B_matrix)(3, 1) = dshapefctHQ[LocalIndex]; + // + // B_51, dN/dz + (*B_matrix)(4, 0) = dshapefctHQ[2 * nnodesHQ + LocalIndex]; + // B_53, dN/dx + (*B_matrix)(4, 2) = dshapefctHQ[LocalIndex]; + // + // B_62, dN/dz + (*B_matrix)(5, 1) = dshapefctHQ[2 * nnodesHQ + LocalIndex]; + // B_63, dN/dy + (*B_matrix)(5, 2) = dshapefctHQ[nnodesHQ + LocalIndex]; - break; + break; } } @@ -695,58 +690,53 @@ void CFiniteElementVec::setTransB_Matrix(const int LocalIndex) void CFiniteElementVec::ComputeStrain() { int i, j = 0, k = 0; - if(excavation)//WX:03.2012 if element is excavated, strain = 0 + if (excavation) // WX:03.2012 if element is excavated, strain = 0 { - for(i=0; i 0) && (no_phases > phase)) + if ((no_phases > 0) && (no_phases > phase)) density_fluid = m_mfp->Density(); - //OK_MMP + // OK_MMP //-------------------------------------------------------------------- // MMP medium properties porosity = m_mmp->Porosity(this); // Assume solid density is constant. (*smat->data_Density)(0) - if(smat->Density() > 0.0) + if (smat->Density() > 0.0) { - Sw = 1.0; // JT, should be 1.0, unless multiphase (calculate below) (if unsaturated, fluid density would be negligible... so still works) - if(Flow_Type > 0 && Flow_Type != 10) + Sw = 1.0; // JT, should be 1.0, unless multiphase (calculate below) (if unsaturated, fluid density would be + // negligible... so still works) + if (Flow_Type > 0 && Flow_Type != 10) { - Sw = 0.; //WW - for(i = 0; i < nnodes; i++) + Sw = 0.; // WW + for (i = 0; i < nnodes; i++) Sw += shapefct[i] * AuxNodal_S[i]; } - rho = - (1. - - porosity) * fabs(smat->Density()) + porosity * Sw * density_fluid; + rho = (1. - porosity) * fabs(smat->Density()) + porosity * Sw * density_fluid; - if(Flow_Type == 2 || Flow_Type == 3) + if (Flow_Type == 2 || Flow_Type == 3) { /* p_g=0.0; @@ -813,8 +802,8 @@ double CFiniteElementVec::CalDensity() rho = 0.0; } else - // If negative value is given in the .msp file, gravity by solid is skipped - if(smat->Density() > 0.0) + // If negative value is given in the .msp file, gravity by solid is skipped + if (smat->Density() > 0.0) rho = smat->Density(); return rho; } @@ -829,8 +818,7 @@ double CFiniteElementVec::CalDensity() 08/2004 OK MFP implementation 01/2010 NW use chache of B,B^T matrices **************************************************************************/ -void CFiniteElementVec::ComputeMatrix_RHS(const double fkt, - const Matrix* p_D) +void CFiniteElementVec::ComputeMatrix_RHS(const double fkt, const Matrix* p_D) { int i, j, k, l; double rho, fac, fac1, fac2, dN_dx, f_buff; @@ -842,7 +830,7 @@ void CFiniteElementVec::ComputeMatrix_RHS(const double fkt, const int ele_dim = this->ele_dim; const int ns = this->ns; - //NW cache B, B^T + // NW cache B, B^T for (i = 0; i < nnodesHQ; i++) { setTransB_Matrix(i); @@ -872,46 +860,46 @@ void CFiniteElementVec::ComputeMatrix_RHS(const double fkt, #else const int ia = i; #endif - //NW setTransB_Matrix(i); + // NW setTransB_Matrix(i); tmp_B_matrix_T = this->vec_B_matrix_T[ia]; // Local assembly of A*u=int(B^t*sigma) for Newton-Raphson method for (j = 0; j < ele_dim; j++) for (k = 0; k < ns; k++) - (*RHS)[j * nnodesHQ + ia] += - (*tmp_B_matrix_T)(j,k) * (dstress[k] - stress0[k]) * fkt; - //TEST (*B_matrix_T)(j,k)*dstress[k]*fkt; - if(PreLoad == 11) + (*RHS)[j * nnodesHQ + ia] += (*tmp_B_matrix_T)(j, k) * (dstress[k] - stress0[k]) * fkt; + // TEST (*B_matrix_T)(j,k)*dstress[k]*fkt; + if (PreLoad == 11) continue; - if(excavation) continue;//WX:08.2011 - // Local assembly of stiffness matrix, B^T C B + if (excavation) + continue; // WX:08.2011 +// Local assembly of stiffness matrix, B^T C B #ifdef JFNK_H2M /// If JFNK. 18.10.2010. WW - if(pcs->m_num->nls_method == 2 && (!pcs->JFNK_precond)) + if (pcs->m_num->nls_method == 2 && (!pcs->JFNK_precond)) continue; #endif (*tmp_AuxMatrix2) = 0.0; - //NW + // NW tmp_B_matrix_T->multi(*p_D, *tmp_AuxMatrix2); for (j = 0; j < nnodesHQ; j++) { - //NW setB_Matrix(j); + // NW setB_Matrix(j); tmp_B_matrix = this->vec_B_matrix[j]; // Compute stiffness matrix (*tmp_AuxMatrix) = 0.0; tmp_AuxMatrix2->multi(*tmp_B_matrix, *tmp_AuxMatrix); - //NW B_matrix_T->multi(*p_D, *B_matrix, *AuxMatrix); + // NW B_matrix_T->multi(*p_D, *B_matrix, *AuxMatrix); // Local assembly of stiffness matrix for (k = 0; k < ele_dim; k++) { const int kia = ia + k * nnodesHQ; for (l = 0; l < ele_dim; l++) - (*tmp_Stiffness)(kia, j + l * nnodesHQ) += (*tmp_AuxMatrix)(k,l) * fkt; + (*tmp_Stiffness)(kia, j + l * nnodesHQ) += (*tmp_AuxMatrix)(k, l) * fkt; } - } // loop j - } // loop i + } // loop j + } // loop i - //should restore pointer NW + // should restore pointer NW B_matrix = old_B_matrix; B_matrix_T = old_B_matrix_T; @@ -921,23 +909,23 @@ void CFiniteElementVec::ComputeMatrix_RHS(const double fkt, // LoadFactor: factor of incremental loading, prescibed in rf_pcs.cpp // 07.2011 WW - if((PressureC || PressureC_S || PressureC_S_dp) && !PreLoad) + if ((PressureC || PressureC_S || PressureC_S_dp) && !PreLoad) { fac = LoadFactor * fkt; // 07.2011. WW - if(PressureC_S || PressureC_S_dp) + if (PressureC_S || PressureC_S_dp) { // Pressure 1 fac2 = interpolate(AuxNodal0); // Saturation of phase 1 fac1 = m_mmp->SaturationCapillaryPressureFunction(fac2); - if(PressureC_S_dp) - fac2 = fac1 - fac2* m_mmp->PressureSaturationDependency(fac1,true); - //JT: dSdP now returns actual sign (<0) + if (PressureC_S_dp) + fac2 = fac1 - fac2 * m_mmp->PressureSaturationDependency(fac1, true); + // JT: dSdP now returns actual sign (<0) } - if(axisymmetry) + if (axisymmetry) { for (k = 0; k < act_r; k++) { @@ -947,17 +935,17 @@ void CFiniteElementVec::ComputeMatrix_RHS(const double fkt, const int ka = k; #endif for (l = 0; l < nnodes; l++) - for(j = 0; j < ele_dim; j++) + for (j = 0; j < ele_dim; j++) { dN_dx = dshapefctHQ[nnodesHQ * j + ka]; - if(j == 0) + if (j == 0) dN_dx += shapefctHQ[ka] / Radius; f_buff = fac * dN_dx * shapefct[l]; (*PressureC)(nnodesHQ * j + ka, l) += f_buff; - if(PressureC_S) + if (PressureC_S) (*PressureC_S)(nnodesHQ * j + ka, l) += f_buff * fac1; - if(PressureC_S_dp) + if (PressureC_S_dp) (*PressureC_S_dp)(nnodesHQ * j + ka, l) += f_buff * fac2; } } @@ -966,20 +954,19 @@ void CFiniteElementVec::ComputeMatrix_RHS(const double fkt, { for (k = 0; k < act_r; k++) { - #if defined(USE_PETSC) // || defined(other parallel libs)//05.3013. WW const int ka = local_idx[k]; #else const int ka = k; #endif for (l = 0; l < nnodes; l++) - for(j = 0; j < ele_dim; j++) + for (j = 0; j < ele_dim; j++) { - f_buff = fac * dshapefctHQ[nnodesHQ * j + ka] * shapefct[l]; - (*PressureC)(nnodesHQ * j + ka,l) += f_buff; - if(PressureC_S) + f_buff = fac * dshapefctHQ[nnodesHQ * j + ka] * shapefct[l]; + (*PressureC)(nnodesHQ * j + ka, l) += f_buff; + if (PressureC_S) (*PressureC_S)(nnodesHQ * j + ka, l) += f_buff * fac1; - if(PressureC_S_dp) + if (PressureC_S_dp) (*PressureC_S_dp)(nnodesHQ * j + ka, l) += f_buff * fac2; } } @@ -988,7 +975,7 @@ void CFiniteElementVec::ComputeMatrix_RHS(const double fkt, //--------------------------------------------------------- // Assemble gravity force vector //--------------------------------------------------------- - if(rho > 0.0 && GravityForce) + if (rho > 0.0 && GravityForce) { // 2D, in y-direction // 3D, in z-direction @@ -996,15 +983,14 @@ void CFiniteElementVec::ComputeMatrix_RHS(const double fkt, const double coeff = LoadFactor * rho * smat->grav_const * fkt; for (k = 0; k < act_r; k++) { - #if defined(USE_PETSC) // || defined(other parallel libs)//05.3013. WW const int ka = local_idx[k]; #else const int ka = k; #endif (*RHS)[i + ka] += coeff * shapefctHQ[ka]; - // (*RHS)(i+ka) += LoadFactor * rho * smat->grav_const * shapefctHQ[ka] * fkt; - } + // (*RHS)(i+ka) += LoadFactor * rho * smat->grav_const * shapefctHQ[ka] * fkt; + } } } /*************************************************************************** @@ -1029,200 +1015,194 @@ void CFiniteElementVec::LocalAssembly(const int update) Index = MeshElement->GetIndex(); SetMemory(); SetMaterial(); - //12.2009. WW + // 12.2009. WW eleV_DM = ele_value_dm[MeshElement->GetIndex()]; #if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW - if(m_dom) - { //Moved here from GlobalAssemly. 08.2010. WW -#if defined (USE_PETSC) // || defined (other parallel solver lib). 04.2012 WW - //TODO + if (m_dom) + { // Moved here from GlobalAssemly. 08.2010. WW +#if defined(USE_PETSC) // || defined (other parallel solver lib). 04.2012 WW +// TODO #elif defined(NEW_EQS) b_rhs = m_dom->eqsH->b; #else b_rhs = m_dom->eqs->b; #endif - } + } else #endif //#if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW - { -#if defined (USE_PETSC) // || defined (other parallel solver lib). 04.2012 WW - // TODO + { +#if defined(USE_PETSC) // || defined (other parallel solver lib). 04.2012 WW +// TODO #elif defined(NEW_EQS) b_rhs = pcs->eqs_new->b; #else b_rhs = pcs->eqs->b; #endif - } + } (*RHS) = 0.0; (*Stiffness) = 0.0; // 07.2011. WW - if(PressureC) + if (PressureC) (*PressureC) = 0.0; - if(PressureC_S) + if (PressureC_S) (*PressureC_S) = 0.0; - if(PressureC_S_dp) + if (PressureC_S_dp) (*PressureC_S_dp) = 0.0; #if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW - if(m_dom) + if (m_dom) { - //06.2011. WW - for(size_t i = 0; i < pcs->GetPrimaryVNumber(); i++) + // 06.2011. WW + for (size_t i = 0; i < pcs->GetPrimaryVNumber(); i++) NodeShift[i] = m_dom->shift[i]; - for(int i = 0; i < nnodesHQ; i++) + for (int i = 0; i < nnodesHQ; i++) eqs_number[i] = element_nodes_dom[i]; } else #endif //#if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW #if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW - { - for(int i = 0; i < nnodesHQ; i++) - eqs_number[i] = MeshElement->nodes[i]->GetEquationIndex(); - } + { + for (int i = 0; i < nnodesHQ; i++) + eqs_number[i] = MeshElement->nodes[i]->GetEquationIndex(); + } #endif // For strain and stress extropolation all element types // Number of elements associated to nodes - for(int i = 0; i < nnodes; i++) + for (int i = 0; i < nnodes; i++) dbuff[i] = (double)MeshElement->nodes[i]->getConnectedElementIDs().size(); // Get displacement_n - if(dynamic) + if (dynamic) { a_n = pcs->GetAuxArray(); - for(size_t i = 0; i < dim; i++) - for(j = 0; j < nnodesHQ; j++) + for (size_t i = 0; i < dim; i++) + for (j = 0; j < nnodesHQ; j++) { // Increment of acceleration, da - (*dAcceleration)(i * nnodesHQ + j) = pcs->GetNodeValue(nodes[j], - Idx_dm0[i]); + (*dAcceleration)(i * nnodesHQ + j) = pcs->GetNodeValue(nodes[j], Idx_dm0[i]); // Increment of displacement // du = v_n*dt+0.5*a_n*dt*dt+0.5*beta2*da*dt*dt // a_n = a_{n+1}-da - Disp[j + i * - nnodesHQ] = pcs->GetNodeValue(nodes[j],Idx_Vel[i]) * dt \ - + 0.5 * dt * dt * - (a_n[nodes[j] + NodeShift[i]] - + beta2 * - (*dAcceleration)(i * nnodesHQ + j)); + Disp[j + i * nnodesHQ] + = pcs->GetNodeValue(nodes[j], Idx_Vel[i]) * dt + + 0.5 * dt * dt * (a_n[nodes[j] + NodeShift[i]] + beta2 * (*dAcceleration)(i * nnodesHQ + j)); } } else - for(size_t i = 0; i < dim; i++) - for(j = 0; j < nnodesHQ; j++) - //WX:03.2013 use total disp. if damage or E=f(t) is on, dstress in LocalAssembly_continumm() is also changed - if(smat->Time_Dependent_E_nv_mode > MKleinsteZahl && pcs->ExcavMaterialGroup<0) - Disp[j+i*nnodesHQ] = pcs->GetNodeValue(nodes[j],Idx_dm0[i]) + pcs->GetNodeValue(nodes[j],Idx_dm0[i]+1); + for (size_t i = 0; i < dim; i++) + for (j = 0; j < nnodesHQ; j++) + // WX:03.2013 use total disp. if damage or E=f(t) is on, dstress in LocalAssembly_continumm() is also + // changed + if (smat->Time_Dependent_E_nv_mode > MKleinsteZahl && pcs->ExcavMaterialGroup < 0) + Disp[j + i * nnodesHQ] + = pcs->GetNodeValue(nodes[j], Idx_dm0[i]) + pcs->GetNodeValue(nodes[j], Idx_dm0[i] + 1); else - Disp[j + i * nnodesHQ] = pcs->GetNodeValue(nodes[j],Idx_dm0[i]); + Disp[j + i * nnodesHQ] = pcs->GetNodeValue(nodes[j], Idx_dm0[i]); // Get saturation of element nodes - if(Flow_Type > 0 && Flow_Type != 10) + if (Flow_Type > 0 && Flow_Type != 10) { - for(int i = 0; i < nnodes; i++) + for (int i = 0; i < nnodes; i++) { AuxNodal_S[i] = h_pcs->GetNodeValue(nodes[i], idx_S); AuxNodal_S0[i] = h_pcs->GetNodeValue(nodes[i], idx_S0); } - if(Flow_Type == 2 || Flow_Type == 3) //09.10.2009 PCH + if (Flow_Type == 2 || Flow_Type == 3) // 09.10.2009 PCH - for(int i = 0; i < nnodes; i++) + for (int i = 0; i < nnodes; i++) { AuxNodal0[i] = h_pcs->GetNodeValue(nodes[i], idx_P1); AuxNodal2[i] = h_pcs->GetNodeValue(nodes[i], idx_P2); } - //12.03.2008 WW - if((Flow_Type == 1 || - Flow_Type == 2) && - (smat->SwellingPressureType == 3 || smat->SwellingPressureType == 4)) + // 12.03.2008 WW + if ((Flow_Type == 1 || Flow_Type == 2) && (smat->SwellingPressureType == 3 || smat->SwellingPressureType == 4)) { double fac = 1.0; - if(Flow_Type == 1) + if (Flow_Type == 1) fac = -1.0; - for(int i = 0; i < nnodes; i++) + for (int i = 0; i < nnodes; i++) { - //Pc + // Pc AuxNodal1[i] = fac * h_pcs->GetNodeValue(nodes[i], idx_P1 - 1); - //dPc - AuxNodal[i] = fac * - (h_pcs->GetNodeValue(nodes[i], - idx_P1) - - h_pcs->GetNodeValue(nodes[i], idx_P1 - 1)); + // dPc + AuxNodal[i] = fac * (h_pcs->GetNodeValue(nodes[i], idx_P1) - h_pcs->GetNodeValue(nodes[i], idx_P1 - 1)); } } } // // -------------------------------12.2009. WW - if(pcs->ite_steps == 1) + if (pcs->ite_steps == 1) { excavation = false; - if((smat->excavation > 0 || pcs->ExcavMaterialGroup > -1) && MeshElement->GetMark()) + if ((smat->excavation > 0 || pcs->ExcavMaterialGroup > -1) && MeshElement->GetMark()) { int valid; - if(smat->excavation > 0) + if (smat->excavation > 0) { - if(GetCurveValue(smat->excavation,0,aktuelle_zeit,&valid) < 1.0) + if (GetCurveValue(smat->excavation, 0, aktuelle_zeit, &valid) < 1.0) { excavation = true; smat->excavated = true; // To be ... 12.2009. WW *(eleV_DM->Stress) = 0.; } else - smat->excavated = false; // To be ... 12.2009. WW + smat->excavated = false; // To be ... 12.2009. WW } - //WX:07.2011 - if(static_cast(pcs->ExcavMaterialGroup) == MeshElement->GetPatchIndex()) + // WX:07.2011 + if (static_cast(pcs->ExcavMaterialGroup) == MeshElement->GetPatchIndex()) { - double const* ele_center (MeshElement->GetGravityCenter()); - if((GetCurveValue(pcs->ExcavCurve,0,aktuelle_zeit, - &valid) + pcs->ExcavBeginCoordinate) > - (ele_center[pcs->ExcavDirection]) && - (ele_center[pcs->ExcavDirection] - - pcs->ExcavBeginCoordinate) > -0.001) + double const* ele_center(MeshElement->GetGravityCenter()); + if ((GetCurveValue(pcs->ExcavCurve, 0, aktuelle_zeit, &valid) + pcs->ExcavBeginCoordinate) + > (ele_center[pcs->ExcavDirection]) + && (ele_center[pcs->ExcavDirection] - pcs->ExcavBeginCoordinate) > -0.001) { excavation = true; *(eleV_DM->Stress) = 0.; - //MeshElement->SetExcavState(1); //WX:03.2012 + // MeshElement->SetExcavState(1); //WX:03.2012 } } } } //---------------------------------------------------- - if(enhanced_strain_dm && ele_value_dm[MeshElement->GetIndex()]->Localized) + if (enhanced_strain_dm && ele_value_dm[MeshElement->GetIndex()]->Localized) LocalAssembly_EnhancedStrain(update); else LocalAssembly_continuum(update); - if(update == 0) + if (update == 0) { - if(dynamic) + if (dynamic) ComputeMass(); GlobalAssembly(); - //Output matrices - if(pcs->Write_Matrix) + // Output matrices + if (pcs->Write_Matrix) { (*pcs->matrix_file) << "### Element: " << Index << "\n"; - (*pcs->matrix_file) << "---Stiffness matrix: " << "\n"; + (*pcs->matrix_file) << "---Stiffness matrix: " + << "\n"; Stiffness->Write(*pcs->matrix_file); - (*pcs->matrix_file) << "---RHS: " << "\n"; + (*pcs->matrix_file) << "---RHS: " + << "\n"; RHS->Write(*pcs->matrix_file); - if(PressureC) + if (PressureC) { - (*pcs->matrix_file) << "Pressue coupling matrix: " << "\n"; + (*pcs->matrix_file) << "Pressue coupling matrix: " + << "\n"; PressureC->Write(*pcs->matrix_file); } // 07.2011. WW - if(PressureC_S) + if (PressureC_S) { - (*pcs->matrix_file) << - "Saturation depedent pressue coupling matrix: " << "\n"; + (*pcs->matrix_file) << "Saturation depedent pressue coupling matrix: " + << "\n"; PressureC_S->Write(*pcs->matrix_file); } - if(PressureC_S_dp) + if (PressureC_S_dp) { - (*pcs->matrix_file) << "Jacobi pressue coupling matrix: " << - "\n"; + (*pcs->matrix_file) << "Jacobi pressue coupling matrix: " + << "\n"; PressureC_S_dp->Write(*pcs->matrix_file); } } @@ -1245,62 +1225,62 @@ bool CFiniteElementVec::GlobalAssembly() int valid = 0; if (excavation) { - excavation = true; - bool onExBoundary = false; + excavation = true; + bool onExBoundary = false; - CNode* node; - CElem* elem; - CSolidProperties* smat_e; - - for (int i = 0; i < nnodesHQ; i++) - { - node = MeshElement->nodes[i]; - onExBoundary = false; - const size_t n_elements (node->getConnectedElementIDs().size()); - for (size_t j = 0; j < n_elements; j++) - { - elem = pcs->m_msh->ele_vector[node->getConnectedElementIDs()[j]]; - if (!elem->GetMark()) - continue; + CNode* node; + CElem* elem; + CSolidProperties* smat_e; - smat_e = msp_vector[elem->GetPatchIndex()]; - if (smat_e->excavation > 0) - { - if (fabs(GetCurveValue(smat_e->excavation, 0, - aktuelle_zeit, - &valid) - 1.0) < DBL_MIN) - { - onExBoundary = true; - break; - } - } - else if(pcs->ExcavMaterialGroup > -1) - { - double const* ele_center(elem->GetGravityCenter()); - if((GetCurveValue(pcs->ExcavCurve,0,aktuelle_zeit, - &valid) + pcs->ExcavBeginCoordinate) < - (ele_center[pcs->ExcavDirection])) - { - onExBoundary = true; - break; - } - else if (elem->GetPatchIndex() != static_cast(pcs->ExcavMaterialGroup)) - { - onExBoundary = true; - break; - } - } //WX:07.2011 - else - { - onExBoundary = true; - break; - } - } + for (int i = 0; i < nnodesHQ; i++) + { + node = MeshElement->nodes[i]; + onExBoundary = false; + const size_t n_elements (node->getConnectedElementIDs().size()); + for (size_t j = 0; j < n_elements; j++) + { + elem = pcs->m_msh->ele_vector[node->getConnectedElementIDs()[j]]; + if (!elem->GetMark()) + continue; + + smat_e = msp_vector[elem->GetPatchIndex()]; + if (smat_e->excavation > 0) + { + if (fabs(GetCurveValue(smat_e->excavation, 0, + aktuelle_zeit, + &valid) - 1.0) < DBL_MIN) + { + onExBoundary = true; + break; + } + } + else if(pcs->ExcavMaterialGroup > -1) + { + double const* ele_center(elem->GetGravityCenter()); + if((GetCurveValue(pcs->ExcavCurve,0,aktuelle_zeit, + &valid) + pcs->ExcavBeginCoordinate) < + (ele_center[pcs->ExcavDirection])) + { + onExBoundary = true; + break; + } + else if (elem->GetPatchIndex() != static_cast(pcs->ExcavMaterialGroup)) + { + onExBoundary = true; + break; + } + } //WX:07.2011 + else + { + onExBoundary = true; + break; + } + } - if (!onExBoundary) - for (size_t j = 0; j < dim; j++) - (*RHS)(j * nnodesHQ + i) = 0.0; - } + if (!onExBoundary) + for (size_t j = 0; j < dim; j++) + (*RHS)(j * nnodesHQ + i) = 0.0; + } }*/ GlobalAssembly_RHS(); @@ -1308,13 +1288,13 @@ bool CFiniteElementVec::GlobalAssembly() return true; // For excavation simulation. 12.2009. WW - if (excavation)//WX: modify + if (excavation) // WX: modify { - //MeshElement->MarkingAll(false); + // MeshElement->MarkingAll(false); //*(eleV_DM->Stress) = 0.; //*(eleV_DM->Stress0) = 0.; - //if (eleV_DM->Stress_j) - //(*eleV_DM->Stress_j) = 0.0; + // if (eleV_DM->Stress_j) + //(*eleV_DM->Stress_j) = 0.0; return false; } @@ -1341,15 +1321,15 @@ void CFiniteElementVec::GlobalAssembly_Stiffness() int non_ghost_flag = 1; if (act_nodes_h != nnodesHQ) - non_ghost_flag = -1; + non_ghost_flag = -1; for (int i = 0; i < nnodesHQ; i++) { - const int i_buff = MeshElement->nodes[i]->GetEquationIndex() * dof; - for(int k=0; knodes[i]->GetEquationIndex() * dof; + for (int k = 0; k < dof; k++) { - const int ki = k*nnodesHQ + i; - idxm[ki] = non_ghost_flag *( i_buff + k); + const int ki = k * nnodesHQ + i; + idxm[ki] = non_ghost_flag * (i_buff + k); idxn[ki] = non_ghost_flag * idxm[ki]; // always positive } } @@ -1358,25 +1338,25 @@ void CFiniteElementVec::GlobalAssembly_Stiffness() { for (int i = 0; i < act_nodes_h; i++) { - for(int k=0; kgetEntryArray(); double* local_vec = RHS->getEntryArray(); - for(std::size_t i=0; iSize(); i++) + for (std::size_t i = 0; i < RHS->Size(); i++) local_vec[i] *= -1.0; // if (dynamic) // not available. - petsc_group::PETScLinearSolver *eqs = pcs->eqs_new; + petsc_group::PETScLinearSolver* eqs = pcs->eqs_new; eqs->addMatrixEntries(m_dim, idxm, n_dim, idxn, local_matrix); eqs->setArrayValues(1, m_dim, idxm, local_vec); @@ -1393,16 +1373,16 @@ void CFiniteElementVec::GlobalAssembly_Stiffness() **************************************************************************/ void CFiniteElementVec::GlobalAssembly_Stiffness() { - int i,j; - double f1,f2; + int i, j; + double f1, f2; f1 = 1.0; f2 = -1.0; #if defined(NEW_EQS) && defined(JFNK_H2M) - ///If not JFNK. 02.2011. WW - if(pcs->m_num->nls_method == 2) + /// If not JFNK. 02.2011. WW + if (pcs->m_num->nls_method == 2) { - if(!pcs->JFNK_precond) + if (!pcs->JFNK_precond) return; long kk = 0; @@ -1415,15 +1395,13 @@ void CFiniteElementVec::GlobalAssembly_Stiffness() kk = eqs_number[i] + NodeShift[k]; for (j = 0; j < nnodesHQ; j++) { - if(kk != eqs_number[j] + NodeShift[l]) + if (kk != eqs_number[j] + NodeShift[l]) continue; - pcs->eqs_new->prec_M[kk] += - (*Stiffness)(i + k * nnodesHQ, j + l * - nnodesHQ); + pcs->eqs_new->prec_M[kk] += (*Stiffness)(i + k * nnodesHQ, j + l * nnodesHQ); } } // loop l - } // loop k + } // loop k return; } #endif @@ -1431,13 +1409,13 @@ void CFiniteElementVec::GlobalAssembly_Stiffness() biot = smat->biot_const; #if defined(NEW_EQS) CSparseMatrix* A = NULL; - if(m_dom) + if (m_dom) A = m_dom->eqsH->A; else A = pcs->eqs_new->A; #endif - if(dynamic) + if (dynamic) { f1 = 0.5 * beta2 * dt * dt; f2 = -0.5 * bbeta1 * dt; @@ -1450,17 +1428,13 @@ void CFiniteElementVec::GlobalAssembly_Stiffness() for (size_t k = 0; k < ele_dim; k++) { #ifdef NEW_EQS - (*A)(eqs_number[i] + NodeShift[k],eqs_number[j] + - NodeShift[k]) - += (*Mass)(i, j); + (*A)(eqs_number[i] + NodeShift[k], eqs_number[j] + NodeShift[k]) += (*Mass)(i, j); #else - MXInc(eqs_number[i] + NodeShift[k], - eqs_number[j] + NodeShift[k], - (*Mass)(i, j)); + MXInc(eqs_number[i] + NodeShift[k], eqs_number[j] + NodeShift[k], (*Mass)(i, j)); #endif } - } // loop j - } // loop i + } // loop j + } // loop i } // Assemble stiffness matrix @@ -1472,38 +1446,36 @@ void CFiniteElementVec::GlobalAssembly_Stiffness() for (size_t k = 0; k < ele_dim; k++) { for (size_t l = 0; l < ele_dim; l++) - { + { #ifdef NEW_EQS - (*A)(eqs_number[i] + NodeShift[k],eqs_number[j] + - NodeShift[l]) - += f1 * - (*Stiffness)(i + k * nnodesHQ, j + l * nnodesHQ); + (*A)(eqs_number[i] + NodeShift[k], eqs_number[j] + NodeShift[l]) + += f1 * (*Stiffness)(i + k * nnodesHQ, j + l * nnodesHQ); #else MXInc(eqs_number[i] + NodeShift[k], eqs_number[j] + NodeShift[l], f1 * (*Stiffness)(i + k * nnodesHQ, j + l * nnodesHQ)); #endif - } + } } - } // loop j - } // loop i + } // loop j + } // loop i - //TEST OUT - //Stiffness->Write(); - if(pcs->type / 40 != 1) // Not monolithic scheme + // TEST OUT + // Stiffness->Write(); + if (pcs->type / 40 != 1) // Not monolithic scheme return; - if(PressureC) + if (PressureC) { - i = 0; // phase - if(Flow_Type == 2) // Multi-phase-flow + i = 0; // phase + if (Flow_Type == 2) // Multi-phase-flow i = 1; GlobalAssembly_PressureCoupling(PressureC, f2 * biot, i); } // H2: p_g- S_w*p_c - if(PressureC_S) + if (PressureC_S) GlobalAssembly_PressureCoupling(PressureC_S, -f2 * biot, 0); - if(PressureC_S_dp) + if (PressureC_S_dp) GlobalAssembly_PressureCoupling(PressureC_S_dp, -f2 * biot, 0); /* @@ -1569,8 +1541,8 @@ void CFiniteElementVec::GlobalAssembly_Stiffness() } */ - //TEST OUT - //PressureC->Write(); + // TEST OUT + // PressureC->Write(); } #endif //#if defined(USE_PETSC) // || defined(other parallel libs)//07.2013. WW //-------------------------------------------------------------------------- @@ -1586,17 +1558,15 @@ void CFiniteElementVec::GlobalAssembly_Stiffness() 07.2011. WW */ #if defined(USE_PETSC) // || defined(other parallel libs)//10.3012. WW -void CFiniteElementVec::GlobalAssembly_PressureCoupling(Matrix*, - double, - const int) {} +void CFiniteElementVec::GlobalAssembly_PressureCoupling(Matrix*, double, const int) +{ +} #else -void CFiniteElementVec::GlobalAssembly_PressureCoupling(Matrix* pCMatrix, - double fct, - const int phase) +void CFiniteElementVec::GlobalAssembly_PressureCoupling(Matrix* pCMatrix, double fct, const int phase) { #if defined(NEW_EQS) CSparseMatrix* A = NULL; - if(m_dom) + if (m_dom) A = m_dom->eqsH->A; else A = pcs->eqs_new->A; @@ -1608,18 +1578,16 @@ void CFiniteElementVec::GlobalAssembly_PressureCoupling(Matrix* pCMatrix, { for (int j = 0; j < nnodes; j++) { - for(size_t k = 0; k < ele_dim; k++) - { + for (size_t k = 0; k < ele_dim; k++) + { #ifdef NEW_EQS - (*A)(NodeShift[k] + eqs_number[i], NodeShift[dim_shift] + - eqs_number[j]) - += fct * (*pCMatrix)(nnodesHQ * k + i,j); + (*A)(NodeShift[k] + eqs_number[i], NodeShift[dim_shift] + eqs_number[j]) + += fct * (*pCMatrix)(nnodesHQ * k + i, j); #else - MXInc(NodeShift[k] + eqs_number[i], - NodeShift[dim_shift] + eqs_number[j], \ - fct * (*pCMatrix)(nnodesHQ * k + i,j)); + MXInc(NodeShift[k] + eqs_number[i], NodeShift[dim_shift] + eqs_number[j], + fct * (*pCMatrix)(nnodesHQ * k + i, j)); #endif - } + } } } } @@ -1635,7 +1603,7 @@ void CFiniteElementVec::GlobalAssembly_PressureCoupling(Matrix* pCMatrix, **************************************************************************/ void CFiniteElementVec::ComputeMass() { - int i,j; + int i, j; // ---- Gauss integral int gp_r = 0, gp_s = 0, gp_t; gp = 0; @@ -1651,16 +1619,16 @@ void CFiniteElementVec::ComputeMass() // Compute Jacobian matrix and its determinate //--------------------------------------------------------- fkt = GetGaussData(gp, gp_r, gp_s, gp_t); - ComputeShapefct(1); //need for density calculation - ComputeShapefct(2); // Quadratic interpolation function + ComputeShapefct(1); // need for density calculation + ComputeShapefct(2); // Quadratic interpolation function fkt *= CalDensity(); - for(i = 0; i < nnodesHQ; i++) - for(j = 0; j < nnodesHQ; j++) + for (i = 0; i < nnodesHQ; i++) + for (j = 0; j < nnodesHQ; j++) { - if(i > j) + if (i > j) continue; - (*Mass)(i,j) += fkt * shapefctHQ[i] * shapefctHQ[j]; + (*Mass)(i, j) += fkt * shapefctHQ[i] * shapefctHQ[j]; } } } @@ -1681,26 +1649,26 @@ void CFiniteElementVec::GlobalAssembly_RHS() double fact, val_n = 0.0; double* a_n = NULL; double biot = 1.0; - //WW double dent_w = 1000.0; + // WW double dent_w = 1000.0; bool Residual; Residual = false; fact = 1.0; k = 0; - int idx_p1_ini = 0, idx_p2_ini = 0;//, idx_sw_ini;//WX:08.2011 neglect ini h affect + int idx_p1_ini = 0, idx_p2_ini = 0; //, idx_sw_ini;//WX:08.2011 neglect ini h affect biot = smat->biot_const; - if(Flow_Type >= 0) + if (Flow_Type >= 0) { - if(pcs->type / 10 == 4) // Monolithic scheme + if (pcs->type / 10 == 4) // Monolithic scheme { // If nonlinear deformation - if(pcs_deformation > 100) + if (pcs_deformation > 100) Residual = true; } - else // Partitioned scheme + else // Partitioned scheme Residual = true; } - if(dynamic) + if (dynamic) { fact = bbeta1 * dt; Residual = true; @@ -1709,49 +1677,49 @@ void CFiniteElementVec::GlobalAssembly_RHS() } // Assemble coupling matrix // If dynamic GetNodeValue(nodes[i],idx_P0) = 0; - if(Residual) + if (Residual) { - //WX:02.2013 coupling excavation + // WX:02.2013 coupling excavation int onExBoundaryState[20] = {0}; if (excavation) { int valid = 0; excavation = true; bool onExBoundary = false; - CNode * node; - CElem * elem; + CNode* node; + CElem* elem; CSolidProperties* smat_e; for (int i = 0; i < nnodes; i++) { node = MeshElement->nodes[i]; onExBoundary = false; - const size_t n_elements (node->getConnectedElementIDs().size()); + const size_t n_elements(node->getConnectedElementIDs().size()); for (size_t j = 0; j < n_elements; j++) { elem = pcs->m_msh->ele_vector[node->getConnectedElementIDs()[j]]; - if (!elem->GetMark()) continue; + if (!elem->GetMark()) + continue; smat_e = msp_vector[elem->GetPatchIndex()]; if (smat_e->excavation > 0) { - if (fabs(GetCurveValue(smat_e->excavation, 0, - aktuelle_zeit, &valid) - 1.0) < DBL_MIN) + if (fabs(GetCurveValue(smat_e->excavation, 0, aktuelle_zeit, &valid) - 1.0) < DBL_MIN) { onExBoundary = true; break; } } - else if(pcs->ExcavMaterialGroup>-1) + else if (pcs->ExcavMaterialGroup > -1) { double const* ele_center(elem->GetGravityCenter()); - if((GetCurveValue(pcs->ExcavCurve,0,aktuelle_zeit,&valid)+pcs->ExcavBeginCoordinate)< - (ele_center[pcs->ExcavDirection])) + if ((GetCurveValue(pcs->ExcavCurve, 0, aktuelle_zeit, &valid) + pcs->ExcavBeginCoordinate) + < (ele_center[pcs->ExcavDirection])) { onExBoundary = true; break; } - else if (elem->GetPatchIndex()!=static_cast(pcs->ExcavMaterialGroup)) + else if (elem->GetPatchIndex() != static_cast(pcs->ExcavMaterialGroup)) { onExBoundary = true; break; @@ -1763,2240 +1731,2196 @@ void CFiniteElementVec::GlobalAssembly_RHS() break; } } - if(onExBoundary) + if (onExBoundary) onExBoundaryState[i] = 1; } } - switch(Flow_Type) + switch (Flow_Type) { - case 0: // Liquid flow - // For monolithic scheme and liquid flow, the limit of positive pressure must be removed - if(pcs->Neglect_H_ini==2)//WX - idx_p1_ini = h_pcs->GetNodeValueIndex("PRESSURE1_Ini"); - for (i = 0; i < nnodes; i++) + case 0: // Liquid flow + // For monolithic scheme and liquid flow, the limit of positive pressure must be removed + if (pcs->Neglect_H_ini == 2) // WX + idx_p1_ini = h_pcs->GetNodeValueIndex("PRESSURE1_Ini"); + for (i = 0; i < nnodes; i++) + { + val_n = h_pcs->GetNodeValue(nodes[i], idx_P1); + // AuxNodal[i] = LoadFactor*( val_n -Max(pcs->GetNodeValue(nodes[i],idx_P0),0.0)); + // if(pcs->PCS_ExcavState == 1) + // WX:07.2011 for HM excavation + // val_n -= h_pcs->GetNodeValue(nodes[i],idx_P1 - 1); + if (onExBoundaryState[i] == 1) // WX:02.2013 + val_n = 0.; + if (pcs->Neglect_H_ini == 2) // WX:08.2011 -pw_ini + val_n -= h_pcs->GetNodeValue(nodes[i], idx_p1_ini); + AuxNodal[i] = LoadFactor * val_n; + } + break; + case 10: // Ground_flow. Will be merged to case 0 + // WW dent_w = m_mfp->Density(); + for (i = 0; i < nnodes; i++) + AuxNodal[i] = LoadFactor * h_pcs->GetNodeValue(nodes[i], idx_P1); + break; + case 1: // Richards flow { - val_n = h_pcs->GetNodeValue(nodes[i],idx_P1); - // AuxNodal[i] = LoadFactor*( val_n -Max(pcs->GetNodeValue(nodes[i],idx_P0),0.0)); - //if(pcs->PCS_ExcavState == 1) - //WX:07.2011 for HM excavation - //val_n -= h_pcs->GetNodeValue(nodes[i],idx_P1 - 1); - if(onExBoundaryState[i]==1)//WX:02.2013 - val_n=0.; - if(pcs->Neglect_H_ini==2)//WX:08.2011 -pw_ini - val_n -= h_pcs->GetNodeValue(nodes[i], idx_p1_ini); - AuxNodal[i] = LoadFactor * val_n; - } - break; - case 10: // Ground_flow. Will be merged to case 0 - //WW dent_w = m_mfp->Density(); - for (i = 0; i < nnodes; i++) - AuxNodal[i] = LoadFactor * h_pcs->GetNodeValue(nodes[i],idx_P1); - break; - case 1: // Richards flow - { - //WX:08.2011 - double bishop_coef_ini = 0.0; - double S_e, S_e_ini = 0.0, sw_ini; + // WX:08.2011 + double bishop_coef_ini = 0.0; + double S_e, S_e_ini = 0.0, sw_ini; - if(pcs->Neglect_H_ini==2) - { - idx_p1_ini = h_pcs->GetNodeValueIndex("PRESSURE1_Ini"); - } + if (pcs->Neglect_H_ini == 2) + { + idx_p1_ini = h_pcs->GetNodeValueIndex("PRESSURE1_Ini"); + } #ifdef DECOVALEX - int idv0; - // DECOVALEX - idv0 = S_Water * h_pcs->GetNodeValueIndex("PRESSURE_I"); + int idv0; + // DECOVALEX + idv0 = S_Water * h_pcs->GetNodeValueIndex("PRESSURE_I"); #endif - // - for (i = 0; i < nnodes; i++) - { - val_n = h_pcs->GetNodeValue(nodes[i],idx_P1); - S_e = (m_mmp->SaturationCapillaryPressureFunction(-val_n)-m_mmp->capillary_pressure_values[1]) - /(m_mmp->capillary_pressure_values[2]-m_mmp->capillary_pressure_values[1]); - if(onExBoundaryState[i]==1)//WX:02.2013 - val_n=0.; - if(biot < 0.0 && val_n < 0.0) - AuxNodal[i] = 0.0; - else + // + for (i = 0; i < nnodes; i++) { - // DECOVALEX + val_n = h_pcs->GetNodeValue(nodes[i], idx_P1); + S_e = (m_mmp->SaturationCapillaryPressureFunction(-val_n) - m_mmp->capillary_pressure_values[1]) + / (m_mmp->capillary_pressure_values[2] - m_mmp->capillary_pressure_values[1]); + if (onExBoundaryState[i] == 1) // WX:02.2013 + val_n = 0.; + if (biot < 0.0 && val_n < 0.0) + AuxNodal[i] = 0.0; + else + { +// DECOVALEX #ifdef DECOVALEX - AuxNodal[i] = LoadFactor * - (val_n - - Max(h_pcs->GetNodeValue(nodes[i],idv0),0.0)); + AuxNodal[i] = LoadFactor * (val_n - Max(h_pcs->GetNodeValue(nodes[i], idv0), 0.0)); #else - if(pcs->Neglect_H_ini==2) - { - sw_ini = m_mmp->SaturationCapillaryPressureFunction(-h_pcs->GetNodeValue(nodes[i],idx_p1_ini)); - S_e_ini = (sw_ini-m_mmp->capillary_pressure_values[1]) - /(m_mmp->capillary_pressure_values[2]-m_mmp->capillary_pressure_values[1]); - } + if (pcs->Neglect_H_ini == 2) + { + sw_ini = m_mmp->SaturationCapillaryPressureFunction( + -h_pcs->GetNodeValue(nodes[i], idx_p1_ini)); + S_e_ini = (sw_ini - m_mmp->capillary_pressure_values[1]) + / (m_mmp->capillary_pressure_values[2] - m_mmp->capillary_pressure_values[1]); + } - if(smat->bishop_model>0) - { - switch (smat->bishop_model) + if (smat->bishop_model > 0) { - case 1: - bishop_coef_ini=S_e_ini * smat->bishop_model_value; - AuxNodal[i] = LoadFactor*S_e*smat->bishop_model_value* val_n; - break; - case 2: - bishop_coef_ini = pow(S_e_ini,smat->bishop_model_value); - AuxNodal[i] = LoadFactor*pow(S_e,smat->bishop_model_value)* val_n; - break; - case 3: - h_pcs->GetNodeValue(nodes[i],idx_p1_ini)bishop_model_value ? bishop_coef_ini=0.0 : bishop_coef_ini=1.0; - if(val_nbishop_model_value) - AuxNodal[i] = 0.0; - else - AuxNodal[i] = LoadFactor * val_n; - break; - default : - break; + switch (smat->bishop_model) + { + case 1: + bishop_coef_ini = S_e_ini * smat->bishop_model_value; + AuxNodal[i] = LoadFactor * S_e * smat->bishop_model_value * val_n; + break; + case 2: + bishop_coef_ini = pow(S_e_ini, smat->bishop_model_value); + AuxNodal[i] = LoadFactor * pow(S_e, smat->bishop_model_value) * val_n; + break; + case 3: + h_pcs->GetNodeValue(nodes[i], idx_p1_ini) < smat->bishop_model_value + ? bishop_coef_ini = 0.0 + : bishop_coef_ini = 1.0; + if (val_n < smat->bishop_model_value) + AuxNodal[i] = 0.0; + else + AuxNodal[i] = LoadFactor * val_n; + break; + default: + break; + } } - } - else - AuxNodal[i] = LoadFactor * S_Water * val_n; - }//WX:12.2012 end if(biot<0.0&&val_n<0.0) else + else + AuxNodal[i] = LoadFactor * S_Water * val_n; + } // WX:12.2012 end if(biot<0.0&&val_n<0.0) else - if(pcs->Neglect_H_ini==2)//WX:08.2011 - { - if(smat->bishop_model==1||smat->bishop_model==2||smat->bishop_model==3) - AuxNodal[i] -= LoadFactor * bishop_coef_ini * h_pcs->GetNodeValue(nodes[i],idx_p1_ini); + if (pcs->Neglect_H_ini == 2) // WX:08.2011 + { + if (smat->bishop_model == 1 || smat->bishop_model == 2 || smat->bishop_model == 3) + AuxNodal[i] -= LoadFactor * bishop_coef_ini * h_pcs->GetNodeValue(nodes[i], idx_p1_ini); else { - - double p0 = h_pcs->GetNodeValue(nodes[i],idx_p1_ini); - double Sat0= LoadFactor*m_mmp->SaturationCapillaryPressureFunction(-p0); + double p0 = h_pcs->GetNodeValue(nodes[i], idx_p1_ini); + double Sat0 = LoadFactor * m_mmp->SaturationCapillaryPressureFunction(-p0); AuxNodal[i] -= LoadFactor * Sat0 * p0; } } #endif - } - break; - } - case 2: { // Multi-phase-flow: p_g-Sw*p_c - // 07.2011. WW - const int dim_times_nnodesHQ(dim * nnodesHQ); - for (i = 0; i < dim_times_nnodesHQ; i++) - AuxNodal1[i] = 0.0; - - if(h_pcs->Neglect_H_ini==2) - { - idx_p1_ini = h_pcs->GetNodeValueIndex("PRESSURE1_Ini"); - idx_p2_ini = h_pcs->GetNodeValueIndex("PRESSURE2_Ini"); - //idx_sw_ini = h_pcs->GetNodeValueIndex("SATURATION1_Ini"); - } - - if(smat->bishop_model > 0) - { - double bishop_coef = 0.0, bishop_coef_ini = 0.0; - double S_e, S_e_ini = 0.0, sw_ini; + } + break; + } + case 2: + { // Multi-phase-flow: p_g-Sw*p_c + // 07.2011. WW + const int dim_times_nnodesHQ(dim * nnodesHQ); + for (i = 0; i < dim_times_nnodesHQ; i++) + AuxNodal1[i] = 0.0; + + if (h_pcs->Neglect_H_ini == 2) + { + idx_p1_ini = h_pcs->GetNodeValueIndex("PRESSURE1_Ini"); + idx_p2_ini = h_pcs->GetNodeValueIndex("PRESSURE2_Ini"); + // idx_sw_ini = h_pcs->GetNodeValueIndex("SATURATION1_Ini"); + } - for (i = 0; i < nnodes; i++) - { - sw_ini = m_mmp->SaturationCapillaryPressureFunction(h_pcs->GetNodeValue(nodes[i],idx_p1_ini)); - switch(smat->bishop_model) + if (smat->bishop_model > 0) { - case 1: - bishop_coef = smat->bishop_model_value; - bishop_coef_ini = bishop_coef; - break; - case 2: - S_e = (AuxNodal_S[i]-m_mmp->capillary_pressure_values[1]) - /(m_mmp->capillary_pressure_values[2]-m_mmp->capillary_pressure_values[1]); - if(pcs->Neglect_H_ini==2) + double bishop_coef = 0.0, bishop_coef_ini = 0.0; + double S_e, S_e_ini = 0.0, sw_ini; + + for (i = 0; i < nnodes; i++) { - S_e_ini = (sw_ini-m_mmp->capillary_pressure_values[1]) - /(m_mmp->capillary_pressure_values[2]-m_mmp->capillary_pressure_values[1]); - bishop_coef_ini = pow(S_e_ini, smat->bishop_model_value); + sw_ini + = m_mmp->SaturationCapillaryPressureFunction(h_pcs->GetNodeValue(nodes[i], idx_p1_ini)); + switch (smat->bishop_model) + { + case 1: + bishop_coef = smat->bishop_model_value; + bishop_coef_ini = bishop_coef; + break; + case 2: + S_e = (AuxNodal_S[i] - m_mmp->capillary_pressure_values[1]) + / (m_mmp->capillary_pressure_values[2] - m_mmp->capillary_pressure_values[1]); + if (pcs->Neglect_H_ini == 2) + { + S_e_ini = (sw_ini - m_mmp->capillary_pressure_values[1]) + / (m_mmp->capillary_pressure_values[2] + - m_mmp->capillary_pressure_values[1]); + bishop_coef_ini = pow(S_e_ini, smat->bishop_model_value); + } + bishop_coef = pow(S_e, smat->bishop_model_value); + break; + case 3: + S_e = (AuxNodal_S[i] - m_mmp->capillary_pressure_values[1]) + / (m_mmp->capillary_pressure_values[2] - m_mmp->capillary_pressure_values[1]); + if (pcs->Neglect_H_ini == 2) + h_pcs->GetNodeValue(nodes[i], idx_p1_ini) < smat->bishop_model_value + ? bishop_coef_ini = 0.0 + : bishop_coef_ini = 1.0; + h_pcs->GetNodeValue(nodes[i], idx_P1) < smat->bishop_model_value + ? bishop_coef = 0.0 + : bishop_coef = 1.0; + break; + default: + break; + } + + if (smat->bishop_model == 1 || smat->bishop_model == 2 + || smat->bishop_model == 3) // pg-bishop*pc 05.2011 WX + { + val_n = h_pcs->GetNodeValue(nodes[i], idx_P2) + - bishop_coef * h_pcs->GetNodeValue(nodes[i], idx_P1); + if (onExBoundaryState[i] == 1) // WX:02.2013 + val_n = 0.; + if (pcs->Neglect_H_ini == 2) + val_n -= h_pcs->GetNodeValue(nodes[i], idx_p2_ini) + - bishop_coef_ini * h_pcs->GetNodeValue(nodes[i], idx_p1_ini); + } + else + { + val_n = h_pcs->GetNodeValue(nodes[i], idx_P2) // pg - Sw*pc + - AuxNodal_S[i] * h_pcs->GetNodeValue(nodes[i], idx_P1); + if (onExBoundaryState[i] == 1) // WX:02.2013 + val_n = 0.; + if (pcs->Neglect_H_ini == 2) + val_n -= h_pcs->GetNodeValue(nodes[i], idx_p2_ini) + - sw_ini * h_pcs->GetNodeValue(nodes[i], idx_p1_ini); + } + + if (biot < 0.0 && val_n < 0.0) + AuxNodal[i] = 0.0; + else + AuxNodal[i] = val_n * LoadFactor; } - bishop_coef = pow(S_e, smat->bishop_model_value); - break; - case 3: - S_e = (AuxNodal_S[i]-m_mmp->capillary_pressure_values[1]) - /(m_mmp->capillary_pressure_values[2]-m_mmp->capillary_pressure_values[1]); - if(pcs->Neglect_H_ini==2) - h_pcs->GetNodeValue(nodes[i],idx_p1_ini)bishop_model_value ? bishop_coef_ini=0.0 : bishop_coef_ini=1.0; - h_pcs->GetNodeValue(nodes[i],idx_P1)bishop_model_value ? bishop_coef=0.0 : bishop_coef=1.0; - break; - default: - break; - } - if(smat->bishop_model == 1 || smat->bishop_model == 2 || smat->bishop_model == 3) // pg-bishop*pc 05.2011 WX - { - val_n = h_pcs->GetNodeValue(nodes[i],idx_P2) - -bishop_coef*h_pcs->GetNodeValue(nodes[i],idx_P1); - if(onExBoundaryState[i]==1)//WX:02.2013 - val_n=0.; - if(pcs->Neglect_H_ini==2) - val_n -= h_pcs->GetNodeValue(nodes[i], idx_p2_ini) - -bishop_coef_ini*h_pcs->GetNodeValue(nodes[i], idx_p1_ini); + PressureC->multi(AuxNodal, AuxNodal1); } else { - val_n = h_pcs->GetNodeValue(nodes[i],idx_P2) // pg - Sw*pc - -AuxNodal_S[i]*h_pcs->GetNodeValue(nodes[i],idx_P1); - if(onExBoundaryState[i]==1)//WX:02.2013 - val_n=0.; - if(pcs->Neglect_H_ini==2) - val_n -= h_pcs->GetNodeValue(nodes[i],idx_p2_ini) - -sw_ini*h_pcs->GetNodeValue(nodes[i],idx_p1_ini); + if (pcs->Neglect_H_ini == 2) + { + for (i = 0; i < nnodes; i++) + { + AuxNodal0[i] -= h_pcs->GetNodeValue(nodes[i], idx_p1_ini); + AuxNodal2[i] -= h_pcs->GetNodeValue(nodes[i], idx_p2_ini); + } + } + + PressureC->multi(AuxNodal2, AuxNodal1, LoadFactor); + PressureC_S->multi(AuxNodal0, AuxNodal1, -1.0 * LoadFactor); } - if(biot < 0.0 && val_n < 0.0) - AuxNodal[i] = 0.0; - else - AuxNodal[i] = val_n * LoadFactor; + break; } - - PressureC->multi(AuxNodal, AuxNodal1); - } - else - { - - if(pcs->Neglect_H_ini==2) + case 3: // Multi-phase-flow: SwPw+SgPg // PCH 05.05.2009 { - for (i=0;iGetNodeValue(nodes[i],idx_p1_ini); - AuxNodal2[i] -= h_pcs->GetNodeValue(nodes[i],idx_p2_ini); + double Snw = h_pcs->GetNodeValue(nodes[i], idx_Snw); + double Sw = 1.0 - Snw; + double Pw = h_pcs->GetNodeValue(nodes[i], idx_P1); + double Pnw = h_pcs->GetNodeValue(nodes[i], idx_P2); + val_n = Sw * Pw + Snw * Pnw; + if (biot < 0.0 && val_n < 0.0) + AuxNodal[i] = 0.0; + else + AuxNodal[i] = val_n * LoadFactor; } + break; } + } // end switch - PressureC->multi(AuxNodal2, AuxNodal1, LoadFactor); - PressureC_S->multi(AuxNodal0, AuxNodal1, -1.0 * LoadFactor); - } + // If dymanic + if (dynamic) + for (i = 0; i < nnodes; i++) + { + AuxNodal[i] *= fact; + AuxNodal[i] += dt * a_n[nodes[i] + NodeShift[problem_dimension_dm]] + + pcs->GetNodeValue(nodes[i], idx_P); + } - break; - } - case 3: // Multi-phase-flow: SwPw+SgPg // PCH 05.05.2009 - { - for (i = 0; i < nnodes; i++) - { - double Snw = h_pcs->GetNodeValue(nodes[i],idx_Snw); - double Sw = 1.0 - Snw; - double Pw = h_pcs->GetNodeValue(nodes[i],idx_P1); - double Pnw = h_pcs->GetNodeValue(nodes[i],idx_P2); - val_n = Sw * Pw + Snw * Pnw; - if(biot < 0.0 && val_n < 0.0) - AuxNodal[i] = 0.0; - else - AuxNodal[i] = val_n * LoadFactor; - } - break; - } - } // end switch + const int dim_times_nnodesHQ(dim * nnodesHQ); + // Coupling effect to RHS + if (Flow_Type != 2) // 07.2011. WW + { + for (i = 0; i < dim_times_nnodesHQ; i++) + AuxNodal1[i] = 0.0; + PressureC->multi(AuxNodal, AuxNodal1); + } + for (i = 0; i < dim_times_nnodesHQ; i++) + (*RHS)[i] -= fabs(biot) * AuxNodal1[i]; + } // End if partioned // If dymanic - if(dynamic) - for (i = 0; i < nnodes; i++) - { - AuxNodal[i] *= fact; - AuxNodal[i] += dt * a_n[nodes[i] + NodeShift[problem_dimension_dm]] - + pcs->GetNodeValue(nodes[i],idx_P); - } - - const int dim_times_nnodesHQ(dim * nnodesHQ); - // Coupling effect to RHS - if(Flow_Type != 2) // 07.2011. WW - { - for (i = 0; i < dim_times_nnodesHQ; i++) - AuxNodal1[i] = 0.0; - PressureC->multi(AuxNodal, AuxNodal1); - } - for (i = 0; i < dim_times_nnodesHQ; i++) - (*RHS)[i] -= fabs(biot) * AuxNodal1[i]; - } // End if partioned - - // If dymanic - if(dynamic) + if (dynamic) + for (size_t i = 0; i < dim; i++) + for (j = 0; j < nnodesHQ; j++) + for (k = 0; k < nnodesHQ; k++) + (*RHS)[i * nnodesHQ + j] + += (*Mass)(j, k) * ((*dAcceleration)(i * nnodesHQ + k) + a_n[nodes[k] + NodeShift[i]]); + +// RHS->Write(); +#if !defined(USE_PETSC) // && !defined(other parallel libs)//06.2013. WW for (size_t i = 0; i < dim; i++) for (j = 0; j < nnodesHQ; j++) - for (k = 0; k < nnodesHQ; k++) - (*RHS)[i * nnodesHQ + j] += (*Mass)(j,k) * ( - (*dAcceleration)(i * nnodesHQ + k) - + a_n[nodes[k] + NodeShift[i]]); - - //RHS->Write(); -#if !defined(USE_PETSC) // && !defined(other parallel libs)//06.2013. WW - for (size_t i = 0; i < dim; i++) - for (j = 0; j < nnodesHQ; j++) - b_rhs[eqs_number[j] + NodeShift[i]] -= (*RHS)[i * nnodesHQ + j]; + b_rhs[eqs_number[j] + NodeShift[i]] -= (*RHS)[i * nnodesHQ + j]; #endif - //WX:07.2011 if not on excav boundary, RHS=0 - int valid = 0; - if (excavation) - { - excavation = true; - bool onExBoundary = false; + // WX:07.2011 if not on excav boundary, RHS=0 + int valid = 0; + if (excavation) + { + excavation = true; + bool onExBoundary = false; - CNode* node; - CElem* elem; - CSolidProperties* smat_e; + CNode* node; + CElem* elem; + CSolidProperties* smat_e; - for (int i = 0; i < nnodesHQ; i++) - { - node = MeshElement->nodes[i]; - onExBoundary = false; - const size_t n_elements (node->getConnectedElementIDs().size()); - for (size_t j = 0; j < n_elements; j++) + for (int i = 0; i < nnodesHQ; i++) { - elem = pcs->m_msh->ele_vector[node->getConnectedElementIDs()[j]]; - if (!elem->GetMark()) - continue; - - smat_e = msp_vector[elem->GetPatchIndex()]; - if (smat_e->excavation > 0) + node = MeshElement->nodes[i]; + onExBoundary = false; + const size_t n_elements(node->getConnectedElementIDs().size()); + for (size_t j = 0; j < n_elements; j++) { - if (fabs(GetCurveValue(smat_e->excavation, 0, - aktuelle_zeit, - &valid) - 1.0) < DBL_MIN) + elem = pcs->m_msh->ele_vector[node->getConnectedElementIDs()[j]]; + if (!elem->GetMark()) + continue; + + smat_e = msp_vector[elem->GetPatchIndex()]; + if (smat_e->excavation > 0) { - onExBoundary = true; - break; + if (fabs(GetCurveValue(smat_e->excavation, 0, aktuelle_zeit, &valid) - 1.0) < DBL_MIN) + { + onExBoundary = true; + break; + } } - } - else if(pcs->ExcavMaterialGroup > -1) - { - double const* ele_center(elem->GetGravityCenter()); - if((GetCurveValue(pcs->ExcavCurve,0,aktuelle_zeit, - &valid) + pcs->ExcavBeginCoordinate) < - (ele_center[pcs->ExcavDirection])) + else if (pcs->ExcavMaterialGroup > -1) { - onExBoundary = true; - break; + double const* ele_center(elem->GetGravityCenter()); + if ((GetCurveValue(pcs->ExcavCurve, 0, aktuelle_zeit, &valid) + pcs->ExcavBeginCoordinate) + < (ele_center[pcs->ExcavDirection])) + { + onExBoundary = true; + break; + } + else if (elem->GetPatchIndex() != static_cast(pcs->ExcavMaterialGroup)) + { + onExBoundary = true; + break; + } } - else if (elem->GetPatchIndex() != static_cast(pcs->ExcavMaterialGroup)) + else { onExBoundary = true; break; } } - else - { - onExBoundary = true; - break; - } - } - if (!onExBoundary) - { + if (!onExBoundary) + { #if !defined(USE_PETSC) // && !defined(other parallel libs)//06.2013. WW - for (size_t j = 0; j < dim; j++) - b_rhs[eqs_number[i] + NodeShift[j]] = 0.0; + for (size_t j = 0; j < dim; j++) + b_rhs[eqs_number[i] + NodeShift[j]] = 0.0; #endif + } } } } -} -/*************************************************************************** - GeoSys - Funktion: - CFiniteElementVec:: LocalAssembly_continuum() - Aufgabe: - Compute the local finite element matrices with the framework - of continuum assumption - Formalparameter: - E: - const int update : indicator to update stress and strain only - - Programming: - 02/2000 OK Elastische Elemente - 09/2002 WW Local assemby of stiffness matrix of elasto-plastic - tangential model - Local assemby of residual - 07/2003 WW Quadratic triangle element - 06/2004 WW Generalize for different element types as a member of class - 12/2005 WW Creep - **************************************************************************/ -void CFiniteElementVec::LocalAssembly_continuum(const int update) -{ - long i; - - Matrix* p_D = NULL; - eleV_DM = ele_value_dm[MeshElement->GetIndex()]; - - // ---- Gauss integral - int gp_r = 0, gp_s = 0, gp_t; - gp = 0; - gp_t = 0; - double fkt = 0.0; - - //WW double *DevStress ; - const int PModel = smat->Plasticity_type; - double dPhi = 0.0; // Sclar factor for the plastic strain - // double J2=0.0; - double dS = 0.0; - - double ThermalExpansion = 0.0; - double t1 = 0.0; - bool Strain_TCS = false; + /*************************************************************************** + GeoSys - Funktion: + CFiniteElementVec:: LocalAssembly_continuum() + Aufgabe: + Compute the local finite element matrices with the framework + of continuum assumption + Formalparameter: + E: + const int update : indicator to update stress and strain only + + Programming: + 02/2000 OK Elastische Elemente + 09/2002 WW Local assemby of stiffness matrix of elasto-plastic + tangential model + Local assemby of residual + 07/2003 WW Quadratic triangle element + 06/2004 WW Generalize for different element types as a member of class + 12/2005 WW Creep + **************************************************************************/ + void CFiniteElementVec::LocalAssembly_continuum(const int update) + { + long i; + + Matrix* p_D = NULL; + eleV_DM = ele_value_dm[MeshElement->GetIndex()]; + + // ---- Gauss integral + int gp_r = 0, gp_s = 0, gp_t; + gp = 0; + gp_t = 0; + double fkt = 0.0; + + // WW double *DevStress ; + const int PModel = smat->Plasticity_type; + double dPhi = 0.0; // Sclar factor for the plastic strain + // double J2=0.0; + double dS = 0.0; + + double ThermalExpansion = 0.0; + double t1 = 0.0; + bool Strain_TCS = false; #ifdef JFNK_H2M - bool JFNK = false; - if(pcs->m_num->nls_method == 2) // 10.09.2010. WW - JFNK = true; + bool JFNK = false; + if (pcs->m_num->nls_method == 2) // 10.09.2010. WW + JFNK = true; #endif - // - ThermalExpansion = 0.0; - // Thermal effect - if(smat->Thermal_Expansion() > 0.0) - ThermalExpansion = smat->Thermal_Expansion(); - - //Get porosity model - // ---- Material properties - //For swelling pressure; - double deporo = 0.0; - //OK_MMP - //-------------------------------------------------------------------- - // MMP medium properties - int PoroModel = m_mmp->porosity_model; - if(PoroModel == 4) - //OK deporo = PCSGetElementPorosityChangeRate(index)/(double)ele_dim; - //MX deporo = PCSGetELEValue(index,NULL,1.0,"n_sw_Rate")/(double)ele_dim; - deporo = - h_pcs->GetElementValue(Index, - h_pcs->GetElementValueIndex("n_sw_rate")) / - (double)ele_dim; - if(T_Flag) - for (i = 0; i < nnodes; i++) - { - T1[i] = t_pcs->GetNodeValue(nodes[i],idx_T1); - Temp[i] = t_pcs->GetNodeValue(nodes[i],idx_T1) - t_pcs->GetNodeValue( - nodes[i], - idx_T0); - } - // + // + ThermalExpansion = 0.0; + // Thermal effect + if (smat->Thermal_Expansion() > 0.0) + ThermalExpansion = smat->Thermal_Expansion(); - if(PModel == 1 || PModel == 10 || PModel == 11) //WX:modified for DP with tension cutoff - smat->CalulateCoefficent_DP(); - // - if(PModel != 3 && smat->Youngs_mode != 2) // modified due to transverse isotropic elasticity: UJG 24.11.2009 - { - if(smat->Youngs_mode < 10 || smat->Youngs_mode > 13) + // Get porosity model + // ---- Material properties + // For swelling pressure; + double deporo = 0.0; + // OK_MMP + //-------------------------------------------------------------------- + // MMP medium properties + int PoroModel = m_mmp->porosity_model; + if (PoroModel == 4) + // OK deporo = PCSGetElementPorosityChangeRate(index)/(double)ele_dim; + // MX deporo = PCSGetELEValue(index,NULL,1.0,"n_sw_Rate")/(double)ele_dim; + deporo = h_pcs->GetElementValue(Index, h_pcs->GetElementValueIndex("n_sw_rate")) / (double)ele_dim; + if (T_Flag) + for (i = 0; i < nnodes; i++) + { + T1[i] = t_pcs->GetNodeValue(nodes[i], idx_T1); + Temp[i] = t_pcs->GetNodeValue(nodes[i], idx_T1) - t_pcs->GetNodeValue(nodes[i], idx_T0); + } + // + + if (PModel == 1 || PModel == 10 || PModel == 11) // WX:modified for DP with tension cutoff + smat->CalulateCoefficent_DP(); + // + if (PModel != 3 && smat->Youngs_mode != 2) // modified due to transverse isotropic elasticity: UJG 24.11.2009 { + if (smat->Youngs_mode < 10 || smat->Youngs_mode > 13) + { #ifdef RFW_FRACTURE - smat->Calculate_Lame_Constant(GetMeshElement()); + smat->Calculate_Lame_Constant(GetMeshElement()); #else smat->Calculate_Lame_Constant(); #endif - // - smat->ElasticConsitutive(ele_dim, De); + // + smat->ElasticConsitutive(ele_dim, De); + } + else + *De = *(smat->getD_tran()); // UJG/WW } - else - *De = *(smat->getD_tran()); // UJG/WW - } - //WX: 06.2012 E depends on stress, strain ... - if(smat->E_Function_Model>0) - { - double tmp_value=1; - tmp_value=smat->E_Function(ele_dim, eleV_DM, nGaussPoints); - *De *= tmp_value; - } - - if(PModel == 5) - smat->CalculateCoefficent_HOEKBROWN(); //WX:02.2011 - /* - string fname=FileName+"_D.txt"; - ofstream out_f(fname.c_str()); - De->Write(out_f); - */ - - /* - //TEST - fstream oss; - if(update) - { - char tf_name[10]; - #ifdef USE_MPI - sprintf(tf_name,"%d",myrank); - string fname = FileName+tf_name+".stress"; - #else - string fname = FileName+".stress"; - #endif - oss.open(fname.c_str(), ios::app|ios::out); - // oss.open(fname.c_str(), ios::trunc|ios::out); - oss<<"\nElement "<Creep_mode > 0) - Strain_TCS = true; - // - if(smat->CreepModel() == 1000) //HL_ODS - smat->CleanTrBuffer_HL_ODS(); - // Loop over Gauss points - for (gp = 0; gp < nGaussPoints; gp++) - { - //--------------------------------------------------------- - // Get local coordinates and weights - // Compute Jacobian matrix and its determinate - //--------------------------------------------------------- - fkt = GetGaussData(gp, gp_r, gp_s, gp_t); - - //--------------------------------------------------------- - // Compute geometry - //--------------------------------------------------------- - ComputeGradShapefct(2); - ComputeShapefct(2); - if(smat->Youngs_mode == 2) //WW/UJG. 22.01.2009 + // WX: 06.2012 E depends on stress, strain ... + if (smat->E_Function_Model > 0) { - smat->CalcYoungs_SVV(CalcStrain_v()); - smat->ElasticConsitutive(ele_dim, De); + double tmp_value = 1; + tmp_value = smat->E_Function(ele_dim, eleV_DM, nGaussPoints); + *De *= tmp_value; } - ComputeStrain(); - if(update) - RecordGuassStrain(gp, gp_r, gp_s, gp_t); - if( F_Flag || T_Flag) - ComputeShapefct(1); // Linear order interpolation function - //--------------------------------------------------------- - // Material properties (Integration of the stress) - //--------------------------------------------------------- - // Initial the stress vector - if(PModel != 3) - { - for (i = 0; i < ns; i++) - dstress[i] = 0.0; - if(!excavation)//WX:07.2011 nonlinear excavation - { - //De->Write(); - De->multi(dstrain, dstress); - if(smat->Time_Dependent_E_nv_mode > MKleinsteZahl && pcs->ExcavMaterialGroup < 0) - for(i=0; iStress)(i, gp)-(*eleV_DM->Stress0)(i, gp); - } - } + if (PModel == 5) + smat->CalculateCoefficent_HOEKBROWN(); // WX:02.2011 + /* + string fname=FileName+"_D.txt"; + ofstream out_f(fname.c_str()); + De->Write(out_f); + */ - //--------------------------------------------------------- - // Integrate the stress by return mapping: - //--------------------------------------------------------- - if(excavation)//if elem is excavated, only do the comp. rhs WX:08.2011 - { - for (i=0;iStress)(i,gp); - S_Water=1.0;//WX:02.2013 - if(Flow_Type>0&&Flow_Type!=10) - S_Water = interpolate(AuxNodal_S,1); - } - else - { - switch(PModel) + /* + //TEST + fstream oss; + if(update) + { + char tf_name[10]; + #ifdef USE_MPI + sprintf(tf_name,"%d",myrank); + string fname = FileName+tf_name+".stress"; + #else + string fname = FileName+".stress"; + #endif + oss.open(fname.c_str(), ios::app|ios::out); + // oss.open(fname.c_str(), ios::trunc|ios::out); + oss<<"\nElement "<Creep_mode > 0) + Strain_TCS = true; + // + if (smat->CreepModel() == 1000) // HL_ODS + smat->CleanTrBuffer_HL_ODS(); + // Loop over Gauss points + for (gp = 0; gp < nGaussPoints; gp++) { - case -1: // Pure elasticity - // Non-linear elasticity: TE model. 10.03.2008. WW - for (i = 0; i < ns; i++) - dstress[i] += (*eleV_DM->Stress)(i, gp); - break; - case 1: // Drucker-Prager model -#ifdef JFNK_H2M - if(smat->StressIntegrationDP(gp, eleV_DM, dstress, dPhi, update) && !JFNK) -#else - if(smat->StressIntegrationDP(gp, eleV_DM, dstress, dPhi, update)) -#endif + //--------------------------------------------------------- + // Get local coordinates and weights + // Compute Jacobian matrix and its determinate + //--------------------------------------------------------- + fkt = GetGaussData(gp, gp_r, gp_s, gp_t); - //WW DevStress = smat->devS; - smat->ConsistentTangentialDP(ConsistDep, dPhi, ele_dim); - break; - case 10: // Drucker-Prager model, direct integration. 02/06 WW - if(smat->DirectStressIntegrationDP(gp, eleV_DM, dstress, update)) + //--------------------------------------------------------- + // Compute geometry + //--------------------------------------------------------- + ComputeGradShapefct(2); + ComputeShapefct(2); + if (smat->Youngs_mode == 2) // WW/UJG. 22.01.2009 { - *ConsistDep = *De; - smat->TangentialDP(ConsistDep); - dPhi = 1.0; + smat->CalcYoungs_SVV(CalcStrain_v()); + smat->ElasticConsitutive(ele_dim, De); } - break; - case 11: //WX: 08.2010 - { - double mm = 0.; //WX:09.2010. for DP with Tension. - switch(smat->DirectStressIntegrationDPwithTension(gp, De, eleV_DM, dstress, - update, mm)) - { - case 1: + + ComputeStrain(); + if (update) + RecordGuassStrain(gp, gp_r, gp_s, gp_t); + if (F_Flag || T_Flag) + ComputeShapefct(1); // Linear order interpolation function + //--------------------------------------------------------- + // Material properties (Integration of the stress) + //--------------------------------------------------------- + // Initial the stress vector + if (PModel != 3) { - *ConsistDep = *De; - smat->TangentialDP2(ConsistDep); - dPhi = 1.0; + for (i = 0; i < ns; i++) + dstress[i] = 0.0; + if (!excavation) // WX:07.2011 nonlinear excavation + { + // De->Write(); + De->multi(dstrain, dstress); + if (smat->Time_Dependent_E_nv_mode > MKleinsteZahl && pcs->ExcavMaterialGroup < 0) + for (i = 0; i < ns; i++) + dstress[i] -= (*eleV_DM->Stress)(i, gp) - (*eleV_DM->Stress0)(i, gp); + } } - break; - case 2: + + //--------------------------------------------------------- + // Integrate the stress by return mapping: + //--------------------------------------------------------- + if (excavation) // if elem is excavated, only do the comp. rhs WX:08.2011 { - *ConsistDep = *De; - smat->TangentialDPwithTension(ConsistDep, mm); - dPhi = 1.0; + for (i = 0; i < ns; i++) + dstress[i] += (*eleV_DM->Stress)(i, gp); + S_Water = 1.0; // WX:02.2013 + if (Flow_Type > 0 && Flow_Type != 10) + S_Water = interpolate(AuxNodal_S, 1); } - break; - case 3: + else { - *ConsistDep = *De; - smat->TangentialDPwithTensionCorner(ConsistDep, mm); - dPhi = 1.0; - } - break; - default: break; + switch (PModel) + { + case -1: // Pure elasticity + // Non-linear elasticity: TE model. 10.03.2008. WW + for (i = 0; i < ns; i++) + dstress[i] += (*eleV_DM->Stress)(i, gp); + break; + case 1: // Drucker-Prager model +#ifdef JFNK_H2M + if (smat->StressIntegrationDP(gp, eleV_DM, dstress, dPhi, update) && !JFNK) +#else + if (smat->StressIntegrationDP(gp, eleV_DM, dstress, dPhi, update)) +#endif + + // WW DevStress = smat->devS; + smat->ConsistentTangentialDP(ConsistDep, dPhi, ele_dim); + break; + case 10: // Drucker-Prager model, direct integration. 02/06 WW + if (smat->DirectStressIntegrationDP(gp, eleV_DM, dstress, update)) + { + *ConsistDep = *De; + smat->TangentialDP(ConsistDep); + dPhi = 1.0; + } + break; + case 11: // WX: 08.2010 + { + double mm = 0.; // WX:09.2010. for DP with Tension. + switch (smat->DirectStressIntegrationDPwithTension(gp, De, eleV_DM, dstress, update, mm)) + { + case 1: + { + *ConsistDep = *De; + smat->TangentialDP2(ConsistDep); + dPhi = 1.0; + } + break; + case 2: + { + *ConsistDep = *De; + smat->TangentialDPwithTension(ConsistDep, mm); + dPhi = 1.0; + } + break; + case 3: + { + *ConsistDep = *De; + smat->TangentialDPwithTensionCorner(ConsistDep, mm); + dPhi = 1.0; + } + break; + default: + break; + } + break; + } + case 2: // Rotational hardening model + // Compute stesses and plastic multi-plier + dPhi = 0.0; + if (smat->CalStress_and_TangentialMatrix_SYS(gp, eleV_DM, De, ConsistDep, dstress, update) > 0) + dPhi = 1.0; + break; + case 3: // Generalized Cam-Clay model + for (i = 0; i < ns; i++) + dstress[i] = dstrain[i]; + // + if (smat->SwellingPressureType == 3) + { + double suc = interpolate(AuxNodal1); + double dsuc = interpolate(AuxNodal); + (*smat->data_Youngs)(7) = suc; + (*smat->data_Youngs)(8) = dsuc; + smat->CalStress_and_TangentialMatrix_CC_SubStep(gp, eleV_DM, dstress, ConsistDep, update); + // + // double pn = -((*eleV_DM->Stress)(0, gp)+(*eleV_DM->Stress)(1, gp)+ + // (*eleV_DM->Stress)(2, gp))/3.0; + // de_vsw = -smat->TEPSwellingParameter(pn,suc)*dsuc/(suc+1.0e5); + } + /* + else if (smat->SwellingPressureType==4) //Power. 07.05.2008 WW + { + double suc = interpolate(AuxNodal1); + double dsuc = interpolate(AuxNodal); + smat->TEPSwellingParameter_kis(suc); + S_Water = m_mmp->SaturationCapillaryPressureFunction(suc); + dS = S_Water - m_mmp->SaturationCapillaryPressureFunction(suc-dsuc); + de_vsw = pow(S_Water, (*smat->data_Youngs)(2) )*dS; + } + */ + else + smat->CalStress_and_TangentialMatrix_CC(gp, eleV_DM, dstress, ConsistDep, update); + + dPhi = 1.0; + break; + case 4: // Mohr-Coloumb //WX:10.2010 + if (smat->DirectStressIntegrationMOHR(gp, eleV_DM, dstress, update, De, pcs->ite_steps)) + { + *ConsistDep = *De; + // also for tension + smat->TangentialMohrShear(ConsistDep); + // ConsistDep->Write(); + dPhi = 1.0; + } + break; + case 44: // WX:12.2011 Mohr-Coloumb bedding + if (smat->StressIntegrationMOHR_Aniso(gp, eleV_DM, dstress, update, De)) + { + *ConsistDep = *De; + smat->TangentialMohrShear(ConsistDep); // also for tension + // ConsistDep->Write(); + dPhi = 1.0; + } + break; + /*case 5: + if(smat->StressIntegrationHoekBrown(gp, eleV_DM, dstress, update, De)) + { + *ConsistDep = *De; + smat->TangentialHoekBrown(ConsistDep); //also for tension + //ConsistDep->Write(); + dPhi = 1.0; + } + break;*/ + } } - break; - } - case 2: // Rotational hardening model - // Compute stesses and plastic multi-plier - dPhi = 0.0; - if(smat->CalStress_and_TangentialMatrix_SYS(gp, eleV_DM, - De, ConsistDep, dstress, - update) > 0) - dPhi = 1.0; - break; - case 3: // Generalized Cam-Clay model - for (i = 0; i < ns; i++) - dstress[i] = dstrain[i]; + // -------------------------------------------------------------------- + // Stress increment by heat, swelling, or heat // - if(smat->SwellingPressureType == 3) + if (Strain_TCS) { - double suc = interpolate(AuxNodal1); - double dsuc = interpolate(AuxNodal); - (*smat->data_Youngs)(7) = suc; - (*smat->data_Youngs)(8) = dsuc; - smat->CalStress_and_TangentialMatrix_CC_SubStep(gp, - eleV_DM, - dstress, - ConsistDep, - update); - // - //double pn = -((*eleV_DM->Stress)(0, gp)+(*eleV_DM->Stress)(1, gp)+ - // (*eleV_DM->Stress)(2, gp))/3.0; - //de_vsw = -smat->TEPSwellingParameter(pn,suc)*dsuc/(suc+1.0e5); - } - /* - else if (smat->SwellingPressureType==4) //Power. 07.05.2008 WW - { - double suc = interpolate(AuxNodal1); - double dsuc = interpolate(AuxNodal); - smat->TEPSwellingParameter_kis(suc); - S_Water = m_mmp->SaturationCapillaryPressureFunction(suc); - dS = S_Water - m_mmp->SaturationCapillaryPressureFunction(suc-dsuc); - de_vsw = pow(S_Water, (*smat->data_Youngs)(2) )*dS; - } - */ - else - smat->CalStress_and_TangentialMatrix_CC(gp, - eleV_DM, - dstress, - ConsistDep, - update); + if (PModel == 3) + smat->ElasticConsitutive(ele_dim, De); + for (i = 0; i < ns; i++) + strain_ne[i] = 0.0; + if (PoroModel == 4) // For swelling pressure - dPhi = 1.0; - break; - case 4: // Mohr-Coloumb //WX:10.2010 - if(smat->DirectStressIntegrationMOHR(gp, eleV_DM, dstress, update, De, pcs->ite_steps)) - { - *ConsistDep = *De; - //also for tension - smat->TangentialMohrShear(ConsistDep); - //ConsistDep->Write(); - dPhi = 1.0; - } - break; - case 44: //WX:12.2011 Mohr-Coloumb bedding - if(smat->StressIntegrationMOHR_Aniso(gp, eleV_DM, dstress, update, De)) + for (i = 0; i < 3; i++) + strain_ne[i] -= deporo; + // + if (T_Flag) // Contribution by thermal expansion { - *ConsistDep = *De; - smat->TangentialMohrShear(ConsistDep); //also for tension - //ConsistDep->Write(); - dPhi = 1.0; + Tem = 0.0; + t1 = 0.0; + for (i = 0; i < nnodes; i++) + { + Tem += shapefct[i] * Temp[i]; + t1 += shapefct[i] * T1[i]; + } + for (i = 0; i < 3; i++) // JT: This was commented. SHOULDN'T BE! + strain_ne[i] -= ThermalExpansion * Tem; } - break; - /*case 5: - if(smat->StressIntegrationHoekBrown(gp, eleV_DM, dstress, update, De)) - { - *ConsistDep = *De; - smat->TangentialHoekBrown(ConsistDep); //also for tension - //ConsistDep->Write(); - dPhi = 1.0; - } - break;*/ - } - } - // -------------------------------------------------------------------- - // Stress increment by heat, swelling, or heat - // - if(Strain_TCS) - { - if(PModel == 3) - smat->ElasticConsitutive(ele_dim, De); - for (i = 0; i < ns; i++) - strain_ne[i] = 0.0; - if(PoroModel == 4) // For swelling pressure - - for (i = 0; i < 3; i++) - strain_ne[i] -= deporo; - // - if(T_Flag) // Contribution by thermal expansion - { - Tem = 0.0; - t1 = 0.0; - for(i = 0; i < nnodes; i++) + // Strain increment by creep + if (smat->Creep_mode == 1 || smat->Creep_mode == 2 || smat->Creep_mode == 3 || smat->Creep_mode == 4) + // TN:add BGRb BGRsf,WX { - Tem += shapefct[i] * Temp[i]; - t1 += shapefct[i] * T1[i]; + for (i = 0; i < ns; i++) + stress_ne[i] = (*eleV_DM->Stress)(i, gp); + smat->AddStain_by_Creep(ns, stress_ne, strain_ne, t1); } - for (i = 0; i < 3; i++) // JT: This was commented. SHOULDN'T BE! - strain_ne[i] -= ThermalExpansion * Tem; + if (smat->Creep_mode == 1000) // HL_ODS. Strain increment by creep + { + for (i = 0; i < ns; i++) + stress_ne[i] = (*eleV_DM->Stress)(i, gp); + smat->AddStain_by_HL_ODS(eleV_DM, stress_ne, strain_ne, t1); + } + // Stress deduced by thermal or swelling strain incremental: + De->multi(strain_ne, dstress); + for (i = 0; i < ns; i++) // JT: This was commented. It shouldn't be. + dstrain[i] += strain_ne[i]; } - // Strain increment by creep - if(smat->Creep_mode==1||smat->Creep_mode==2||smat->Creep_mode==3||smat->Creep_mode==4) - //TN:add BGRb BGRsf,WX + // Fluid coupling; + S_Water = 1.0; + if (Flow_Type > 0 && Flow_Type != 10) + S_Water = interpolate(AuxNodal_S, 1); + // Decovalex. Swelling pressure + if (smat->SwellingPressureType == 1) { - for (i = 0; i < ns; i++) - stress_ne[i] = (*eleV_DM->Stress)(i, gp); - smat->AddStain_by_Creep(ns,stress_ne, strain_ne, t1); + dS = -interpolate(AuxNodal_S0, 1); + dS += S_Water; + for (i = 0; i < 3; i++) + dstress[i] -= 2.0 * S_Water * dS * smat->Max_SwellingPressure; } - if(smat->Creep_mode == 1000) // HL_ODS. Strain increment by creep + else if (smat->SwellingPressureType == 2) // LBNL's model { + dS = -interpolate(AuxNodal_S0, 1); + dS += S_Water; + for (i = 0; i < 3; i++) + dstress[i] -= dS * smat->Max_SwellingPressure; + } + /* + else if(smat->SwellingPressureType==3||smat->SwellingPressureType==4) // TEP model + { + for (i = 0; i < 3; i++) + strain_ne[i] = -de_vsw; + for (i = 3; i < ns; i++) + strain_ne[i] = 0.; + smat->ElasticConsitutive(ele_dim, De); + De->multi(strain_ne, dstress); + } + */ + // Assemble matrices and RHS + if (update < 1) + { + //--------------------------------------------------------- + // Assemble matrices and RHS + //--------------------------------------------------------- + if (dPhi <= 0.0) + p_D = De; + else + p_D = ConsistDep; for (i = 0; i < ns; i++) - stress_ne[i] = (*eleV_DM->Stress)(i, gp); - smat->AddStain_by_HL_ODS(eleV_DM, stress_ne, strain_ne, t1); + stress0[i] = (*eleV_DM->Stress0)(i, gp); + ComputeMatrix_RHS(fkt, p_D); } - // Stress deduced by thermal or swelling strain incremental: - De->multi(strain_ne, dstress); - for(i = 0; i < ns; i++) // JT: This was commented. It shouldn't be. - dstrain[i] += strain_ne[i]; - } - // Fluid coupling; - S_Water = 1.0; - if(Flow_Type > 0 && Flow_Type != 10) - S_Water = interpolate(AuxNodal_S,1); - // Decovalex. Swelling pressure - if(smat->SwellingPressureType == 1) - { - dS = -interpolate(AuxNodal_S0,1); - dS += S_Water; - for (i = 0; i < 3; i++) - dstress[i] -= 2.0 * S_Water * dS * smat->Max_SwellingPressure; - } - else if(smat->SwellingPressureType == 2) // LBNL's model - { - dS = -interpolate(AuxNodal_S0,1); - dS += S_Water; - for (i = 0; i < 3; i++) - dstress[i] -= dS * smat->Max_SwellingPressure; + else // Update stress + + for (i = 0; i < ns; i++) + (*eleV_DM->Stress)(i, gp) = dstress[i]; } + // The mapping of Gauss point strain to element nodes + if (update) + ExtropolateGuassStrain(); + else if (smat->Creep_mode == 1000) // HL_ODS. Strain increment by creep + smat->AccumulateEtr_HL_ODS(eleV_DM, nGaussPoints); + /* - else if(smat->SwellingPressureType==3||smat->SwellingPressureType==4) // TEP model - { - for (i = 0; i < 3; i++) - strain_ne[i] = -de_vsw; - for (i = 3; i < ns; i++) - strain_ne[i] = 0.; - smat->ElasticConsitutive(ele_dim, De); - De->multi(strain_ne, dstress); - } + //TEST + + //TEST + if(update&&Index==0) + { + oss<<" Stress "<<"\n"; + eleV_DM->Stress->Write(oss); + oss.close(); + } */ - // Assemble matrices and RHS - if(update < 1) - { - //--------------------------------------------------------- - // Assemble matrices and RHS - //--------------------------------------------------------- - if(dPhi <= 0.0) - p_D = De; - else - p_D = ConsistDep; - for (i = 0; i < ns; i++) - stress0[i] = (*eleV_DM->Stress0)(i,gp); - ComputeMatrix_RHS(fkt, p_D); - } - else // Update stress - - for(i = 0; i < ns; i++) - (*eleV_DM->Stress)(i, gp) = dstress[i]; } - // The mapping of Gauss point strain to element nodes - if(update) - ExtropolateGuassStrain(); - else if(smat->Creep_mode == 1000) // HL_ODS. Strain increment by creep - smat->AccumulateEtr_HL_ODS(eleV_DM, nGaussPoints); - - /* - //TEST - - //TEST - if(update&&Index==0) - { - oss<<" Stress "<<"\n"; - eleV_DM->Stress->Write(oss); - oss.close(); - } - */ -} - -/*************************************************************************** - GeoSys - Funktion: - CFiniteElementVec::RecordGuassValues() - Aufgabe: - Accumulate stress at each nodes - Formalparameter: - E: - - Programming: - 06/2004 WW - **************************************************************************/ -bool CFiniteElementVec::RecordGuassStrain(const int gp, - const int gp_r, const int gp_s, int gp_t) -{ - int LoIndex = 0; - //--------------------------------------------------------- - // Accumulate strains - //--------------------------------------------------------- - switch(MeshElement->GetElementType()) - { - case MshElemType::QUAD: // Quadralateral - LoIndex = GetLocalIndex(gp_r, gp_s, gp_t); - Sxx[LoIndex] = dstrain[0]; - Syy[LoIndex] = dstrain[1]; - Sxy[LoIndex] = dstrain[3]; - Szz[LoIndex] = dstrain[2]; - break; - case MshElemType::TRIANGLE: // Triangle - Sxx[gp] = dstrain[0]; - Syy[gp] = dstrain[1]; - Szz[gp] = dstrain[2]; - Sxy[gp] = dstrain[3]; - break; - case MshElemType::HEXAHEDRON: // Hexahedra - LoIndex = GetLocalIndex(gp_r, gp_s, gp_t); - if(LoIndex < 0) - return false; - Sxx[LoIndex] = dstrain[0]; - Syy[LoIndex] = dstrain[1]; - Szz[LoIndex] = dstrain[2]; - Sxy[LoIndex] = dstrain[3]; - Sxz[LoIndex] = dstrain[4]; - Syz[LoIndex] = dstrain[5]; - break; - case MshElemType::TETRAHEDRON: // Tedrahedra - Sxx[gp] = dstrain[0]; - Syy[gp] = dstrain[1]; - Szz[gp] = dstrain[2]; - Sxy[gp] = dstrain[3]; - Sxz[gp] = dstrain[4]; - Syz[gp] = dstrain[5]; - break; - case MshElemType::PYRAMID: - Sxx[gp] = dstrain[0]; - Syy[gp] = dstrain[1]; - Szz[gp] = dstrain[2]; - Sxy[gp] = dstrain[3]; - Sxz[gp] = dstrain[4]; - Syz[gp] = dstrain[5]; - break; - default: break; - // 3D - } - return false; -} + /*************************************************************************** + GeoSys - Funktion: + CFiniteElementVec::RecordGuassValues() + Aufgabe: + Accumulate stress at each nodes + Formalparameter: + E: -/*************************************************************************** - GeoSys - Funktion: - CFiniteElementVec::ExtropolateGuassStrain() - Aufgabe: - Extropolate the Gauss point strains to nodes - Formalparameter: - E: + Programming: + 06/2004 WW + **************************************************************************/ + bool CFiniteElementVec::RecordGuassStrain(const int gp, const int gp_r, const int gp_s, int gp_t) + { + int LoIndex = 0; - Programming: - 06/2004 WW - 02/2007 Make it work for all 2nd variables - **************************************************************************/ -void CFiniteElementVec::ExtropolateGuassStrain() -{ - int i, j; - // int l1,l2,l3,l4; //, counter; - double ESxx, ESyy, ESzz, ESxy, ESxz, ESyz; - double avgESxx, avgESyy, avgESzz, avgESxy, avgESxz, avgESyz; - int i_s, i_e, ish, k = 0; - gp = 0; - //double Area1, Area2, Tol=10e-9; + //--------------------------------------------------------- + // Accumulate strains + //--------------------------------------------------------- + switch (MeshElement->GetElementType()) + { + case MshElemType::QUAD: // Quadralateral + LoIndex = GetLocalIndex(gp_r, gp_s, gp_t); + Sxx[LoIndex] = dstrain[0]; + Syy[LoIndex] = dstrain[1]; + Sxy[LoIndex] = dstrain[3]; + Szz[LoIndex] = dstrain[2]; + break; + case MshElemType::TRIANGLE: // Triangle + Sxx[gp] = dstrain[0]; + Syy[gp] = dstrain[1]; + Szz[gp] = dstrain[2]; + Sxy[gp] = dstrain[3]; + break; + case MshElemType::HEXAHEDRON: // Hexahedra + LoIndex = GetLocalIndex(gp_r, gp_s, gp_t); + if (LoIndex < 0) + return false; + Sxx[LoIndex] = dstrain[0]; + Syy[LoIndex] = dstrain[1]; + Szz[LoIndex] = dstrain[2]; + Sxy[LoIndex] = dstrain[3]; + Sxz[LoIndex] = dstrain[4]; + Syz[LoIndex] = dstrain[5]; + break; + case MshElemType::TETRAHEDRON: // Tedrahedra + Sxx[gp] = dstrain[0]; + Syy[gp] = dstrain[1]; + Szz[gp] = dstrain[2]; + Sxy[gp] = dstrain[3]; + Sxz[gp] = dstrain[4]; + Syz[gp] = dstrain[5]; + break; + case MshElemType::PYRAMID: + Sxx[gp] = dstrain[0]; + Syy[gp] = dstrain[1]; + Szz[gp] = dstrain[2]; + Sxy[gp] = dstrain[3]; + Sxz[gp] = dstrain[4]; + Syz[gp] = dstrain[5]; + break; + default: + break; + // 3D + } + return false; + } - //WX:03.2012. if excavation dbuff changed - if(pcs->ExcavMaterialGroup>-1) - { - int tmp_excavstate=-1; - for(i=0;inodes[i]->getConnectedElementIDs().size();jj++) + /*************************************************************************** + GeoSys - Funktion: + CFiniteElementVec::ExtropolateGuassStrain() + Aufgabe: + Extropolate the Gauss point strains to nodes + Formalparameter: + E: + + Programming: + 06/2004 WW + 02/2007 Make it work for all 2nd variables + **************************************************************************/ + void CFiniteElementVec::ExtropolateGuassStrain() + { + int i, j; + // int l1,l2,l3,l4; //, counter; + double ESxx, ESyy, ESzz, ESxy, ESxz, ESyz; + double avgESxx, avgESyy, avgESzz, avgESxy, avgESxz, avgESyz; + int i_s, i_e, ish, k = 0; + gp = 0; + // double Area1, Area2, Tol=10e-9; + + // WX:03.2012. if excavation dbuff changed + if (pcs->ExcavMaterialGroup > -1) + { + int tmp_excavstate = -1; + for (i = 0; i < nnodes; i++) { - tmp_excavstate=pcs->m_msh->ele_vector[MeshElement->nodes[i]->getConnectedElementIDs()[jj]]->GetExcavState(); - if(tmp_excavstate>-1) - dbuff[i] -=1; + for (size_t jj = 0; jj < MeshElement->nodes[i]->getConnectedElementIDs().size(); jj++) + { + tmp_excavstate + = pcs->m_msh->ele_vector[MeshElement->nodes[i]->getConnectedElementIDs()[jj]]->GetExcavState(); + if (tmp_excavstate > -1) + dbuff[i] -= 1; + } + if (dbuff[i] < MKleinsteZahl) // avoid error + dbuff[i] = 1; } - if(dbuff[i]GetElementType(); - if (ElementType == MshElemType::QUAD || ElementType == MshElemType::HEXAHEDRON) - Xi_p = CalcXi_p(); - - // - i_s = 0; - i_e = nnodes; - ish = 0; - if (ElementType == MshElemType::TETRAHEDRON) // tet - { - i_s = 1; - i_e = nnodes + 1; - ish = 1; - } - //--------------------------------------------------------- - // Mapping Gauss point strains to nodes and update nodes - // strains: - //--------------------------------------------------------- - avgESxx = avgESyy = avgESzz = avgESxy = avgESxz = avgESyz = 0.0; - if (this->GetExtrapoMethod() == ExtrapolationMethod::EXTRAPO_AVERAGE) - { - // average - avgESxx = CalcAverageGaussPointValues(Sxx); - avgESyy = CalcAverageGaussPointValues(Syy); - avgESzz = CalcAverageGaussPointValues(Szz); - avgESxy = CalcAverageGaussPointValues(Sxy); - avgESxz = CalcAverageGaussPointValues(Sxz); - avgESyz = CalcAverageGaussPointValues(Syz); - } + // l1=l2=l3=l4=0; + MshElemType::type ElementType = MeshElement->GetElementType(); + if (ElementType == MshElemType::QUAD || ElementType == MshElemType::HEXAHEDRON) + Xi_p = CalcXi_p(); - for(i = 0; i < nnodes; i++) - { - ESxx = ESyy = ESzz = ESxy = ESxz = ESyz = 0.0; + // + i_s = 0; + i_e = nnodes; + ish = 0; + if (ElementType == MshElemType::TETRAHEDRON) // tet + { + i_s = 1; + i_e = nnodes + 1; + ish = 1; + } + //--------------------------------------------------------- + // Mapping Gauss point strains to nodes and update nodes + // strains: + //--------------------------------------------------------- + avgESxx = avgESyy = avgESzz = avgESxy = avgESxz = avgESyz = 0.0; + if (this->GetExtrapoMethod() == ExtrapolationMethod::EXTRAPO_AVERAGE) + { + // average + avgESxx = CalcAverageGaussPointValues(Sxx); + avgESyy = CalcAverageGaussPointValues(Syy); + avgESzz = CalcAverageGaussPointValues(Szz); + avgESxy = CalcAverageGaussPointValues(Sxy); + avgESxz = CalcAverageGaussPointValues(Sxz); + avgESyz = CalcAverageGaussPointValues(Syz); + } - // Calculate values at nodes - if (this->GetExtrapoMethod() == ExtrapolationMethod::EXTRAPO_LINEAR) + for (i = 0; i < nnodes; i++) { - SetExtropoGaussPoints(i); - ComputeShapefct(1); // Linear interpolation function - // - for(j = i_s; j < i_e; j++) + ESxx = ESyy = ESzz = ESxy = ESxz = ESyz = 0.0; + + // Calculate values at nodes + if (this->GetExtrapoMethod() == ExtrapolationMethod::EXTRAPO_LINEAR) { - k = j - ish; - ESxx += Sxx[j] * shapefct[k]; - ESyy += Syy[j] * shapefct[k]; - ESxy += Sxy[j] * shapefct[k]; - ESzz += Szz[j] * shapefct[k]; - if(ele_dim == 3) + SetExtropoGaussPoints(i); + ComputeShapefct(1); // Linear interpolation function + // + for (j = i_s; j < i_e; j++) { - ESxz += Sxz[j] * shapefct[k]; - ESyz += Syz[j] * shapefct[k]; + k = j - ish; + ESxx += Sxx[j] * shapefct[k]; + ESyy += Syy[j] * shapefct[k]; + ESxy += Sxy[j] * shapefct[k]; + ESzz += Szz[j] * shapefct[k]; + if (ele_dim == 3) + { + ESxz += Sxz[j] * shapefct[k]; + ESyz += Syz[j] * shapefct[k]; + } } } - } - else if (this->GetExtrapoMethod() == ExtrapolationMethod::EXTRAPO_AVERAGE) - { - //average - ESxx = avgESxx; - ESyy = avgESyy; - ESxy = avgESxy; - ESzz = avgESzz; - if(ele_dim == 3) + else if (this->GetExtrapoMethod() == ExtrapolationMethod::EXTRAPO_AVERAGE) { - ESxz = avgESxz; - ESyz = avgESyz; + // average + ESxx = avgESxx; + ESyy = avgESyy; + ESxy = avgESxy; + ESzz = avgESzz; + if (ele_dim == 3) + { + ESxz = avgESxz; + ESyz = avgESyz; + } } - } - // Average value of the contribution of all neighbor elements - ESxx /= dbuff[i]; - ESyy /= dbuff[i]; - ESxy /= dbuff[i]; - ESzz /= dbuff[i]; + // Average value of the contribution of all neighbor elements + ESxx /= dbuff[i]; + ESyy /= dbuff[i]; + ESxy /= dbuff[i]; + ESzz /= dbuff[i]; - ESxx += pcs->GetNodeValue(nodes[i],Idx_Strain[0]); - ESyy += pcs->GetNodeValue(nodes[i],Idx_Strain[1]); - ESzz += pcs->GetNodeValue(nodes[i],Idx_Strain[2]); - ESxy += pcs->GetNodeValue(nodes[i],Idx_Strain[3]); + ESxx += pcs->GetNodeValue(nodes[i], Idx_Strain[0]); + ESyy += pcs->GetNodeValue(nodes[i], Idx_Strain[1]); + ESzz += pcs->GetNodeValue(nodes[i], Idx_Strain[2]); + ESxy += pcs->GetNodeValue(nodes[i], Idx_Strain[3]); - pcs->SetNodeValue (nodes[i], Idx_Strain[0], ESxx); - pcs->SetNodeValue (nodes[i], Idx_Strain[1], ESyy); - pcs->SetNodeValue (nodes[i], Idx_Strain[2], ESzz); - pcs->SetNodeValue (nodes[i], Idx_Strain[3], ESxy); + pcs->SetNodeValue(nodes[i], Idx_Strain[0], ESxx); + pcs->SetNodeValue(nodes[i], Idx_Strain[1], ESyy); + pcs->SetNodeValue(nodes[i], Idx_Strain[2], ESzz); + pcs->SetNodeValue(nodes[i], Idx_Strain[3], ESxy); - if(ele_dim == 3) - { - ESxz /= dbuff[i]; - ESyz /= dbuff[i]; - ESxz += pcs->GetNodeValue(nodes[i],Idx_Strain[4]); - ESyz += pcs->GetNodeValue(nodes[i],Idx_Strain[5]); - // - pcs->SetNodeValue (nodes[i], Idx_Strain[4], ESxz); - pcs->SetNodeValue (nodes[i], Idx_Strain[5], ESyz); + if (ele_dim == 3) + { + ESxz /= dbuff[i]; + ESyz /= dbuff[i]; + ESxz += pcs->GetNodeValue(nodes[i], Idx_Strain[4]); + ESyz += pcs->GetNodeValue(nodes[i], Idx_Strain[5]); + // + pcs->SetNodeValue(nodes[i], Idx_Strain[4], ESxz); + pcs->SetNodeValue(nodes[i], Idx_Strain[5], ESyz); + } } } -} - -/*************************************************************************** - GeoSys - Funktion: - CFiniteElementVec::ExtropolateGuassStress() - Aufgabe: - Extropolate the Gauss point strains to nodes - Formalparameter: - E: - Programming: - 06/2004 WW - 03/2007 WW Generize for all 2nd variables - **************************************************************************/ -void CFiniteElementVec::ExtropolateGuassStress() -{ - int i, j, gp_r, gp_s, gp_t; - // int l1,l2,l3,l4; //, counter; - double ESxx, ESyy, ESzz, ESxy, ESxz, ESyz, Pls; - double avgESxx, avgESyy, avgESzz, avgESxy, avgESxz, avgESyz, avgPls; - int i_s, i_e, ish, k = 0; - MshElemType::type ElementType = MeshElement->GetElementType(); - long node_i = 0; - // For strain and stress extropolation all element types - // Number of elements associated to nodes - for(i = 0; i < nnodes; i++) - dbuff[i] = (double)MeshElement->nodes[i]->getConnectedElementIDs().size(); - // - gp = gp_r = gp_s = gp_t = 0; - eleV_DM = ele_value_dm[MeshElement->GetIndex()]; - if(eleV_DM->pStrain) //08.02.2008 WW - idx_pls = pcs->GetNodeValueIndex("STRAIN_PLS"); - // - for(gp = 0; gp < nGaussPoints; gp++) - { - if (ElementType == MshElemType::QUAD || ElementType == MshElemType::HEXAHEDRON) - { - SetGaussPoint(gp, gp_r, gp_s, gp_t); - i = GetLocalIndex(gp_r, gp_s, gp_t); - if(i == -1) - continue; - } - else - i = gp; - - Sxx[i] = (*eleV_DM->Stress)(0,gp); - Syy[i] = (*eleV_DM->Stress)(1,gp); - Szz[i] = (*eleV_DM->Stress)(2,gp); - Sxy[i] = (*eleV_DM->Stress)(3,gp); - if(eleV_DM->pStrain) - pstr[i] = (*eleV_DM->pStrain)(gp); - else - pstr[i] = 0.0; //08.02.2008 WW - if(ele_dim == 3) + /*************************************************************************** + GeoSys - Funktion: + CFiniteElementVec::ExtropolateGuassStress() + Aufgabe: + Extropolate the Gauss point strains to nodes + Formalparameter: + E: + + Programming: + 06/2004 WW + 03/2007 WW Generize for all 2nd variables + **************************************************************************/ + void CFiniteElementVec::ExtropolateGuassStress() + { + int i, j, gp_r, gp_s, gp_t; + // int l1,l2,l3,l4; //, counter; + double ESxx, ESyy, ESzz, ESxy, ESxz, ESyz, Pls; + double avgESxx, avgESyy, avgESzz, avgESxy, avgESxz, avgESyz, avgPls; + int i_s, i_e, ish, k = 0; + MshElemType::type ElementType = MeshElement->GetElementType(); + long node_i = 0; + // For strain and stress extropolation all element types + // Number of elements associated to nodes + for (i = 0; i < nnodes; i++) + dbuff[i] = (double)MeshElement->nodes[i]->getConnectedElementIDs().size(); + // + gp = gp_r = gp_s = gp_t = 0; + eleV_DM = ele_value_dm[MeshElement->GetIndex()]; + if (eleV_DM->pStrain) // 08.02.2008 WW + idx_pls = pcs->GetNodeValueIndex("STRAIN_PLS"); + // + for (gp = 0; gp < nGaussPoints; gp++) { - Sxz[i] = (*eleV_DM->Stress)(4,gp); - Syz[i] = (*eleV_DM->Stress)(5,gp); + if (ElementType == MshElemType::QUAD || ElementType == MshElemType::HEXAHEDRON) + { + SetGaussPoint(gp, gp_r, gp_s, gp_t); + i = GetLocalIndex(gp_r, gp_s, gp_t); + if (i == -1) + continue; + } + else + i = gp; + + Sxx[i] = (*eleV_DM->Stress)(0, gp); + Syy[i] = (*eleV_DM->Stress)(1, gp); + Szz[i] = (*eleV_DM->Stress)(2, gp); + Sxy[i] = (*eleV_DM->Stress)(3, gp); + if (eleV_DM->pStrain) + pstr[i] = (*eleV_DM->pStrain)(gp); + else + pstr[i] = 0.0; // 08.02.2008 WW + if (ele_dim == 3) + { + Sxz[i] = (*eleV_DM->Stress)(4, gp); + Syz[i] = (*eleV_DM->Stress)(5, gp); + } } - } - // - if (ElementType == MshElemType::QUAD || ElementType == MshElemType::HEXAHEDRON) - Xi_p = CalcXi_p(); - - // - i_s = 0; - i_e = nnodes; - ish = 0; - if(ElementType == MshElemType::TETRAHEDRON) // tet - { - i_s = 1; - i_e = nnodes + 1; - ish = 1; - } - //--------------------------------------------------------- - // Mapping Gauss point strains to nodes and update nodes - // strains: - //--------------------------------------------------------- - avgESxx = avgESyy = avgESzz = avgESxy = avgESxz = avgESyz = avgPls = 0.0; - if (this->GetExtrapoMethod() == ExtrapolationMethod::EXTRAPO_AVERAGE) - { - // average - avgESxx = CalcAverageGaussPointValues(Sxx); - avgESyy = CalcAverageGaussPointValues(Syy); - avgESzz = CalcAverageGaussPointValues(Szz); - avgESxy = CalcAverageGaussPointValues(Sxy); - avgESxz = CalcAverageGaussPointValues(Sxz); - avgESyz = CalcAverageGaussPointValues(Syz); - avgPls = CalcAverageGaussPointValues(pstr); - } + // + if (ElementType == MshElemType::QUAD || ElementType == MshElemType::HEXAHEDRON) + Xi_p = CalcXi_p(); - for(i = 0; i < nnodes; i++) - { - ESxx = ESyy = ESzz = ESxy = ESxz = ESyz = Pls = 0.0; + // + i_s = 0; + i_e = nnodes; + ish = 0; + if (ElementType == MshElemType::TETRAHEDRON) // tet + { + i_s = 1; + i_e = nnodes + 1; + ish = 1; + } + //--------------------------------------------------------- + // Mapping Gauss point strains to nodes and update nodes + // strains: + //--------------------------------------------------------- + avgESxx = avgESyy = avgESzz = avgESxy = avgESxz = avgESyz = avgPls = 0.0; + if (this->GetExtrapoMethod() == ExtrapolationMethod::EXTRAPO_AVERAGE) + { + // average + avgESxx = CalcAverageGaussPointValues(Sxx); + avgESyy = CalcAverageGaussPointValues(Syy); + avgESzz = CalcAverageGaussPointValues(Szz); + avgESxy = CalcAverageGaussPointValues(Sxy); + avgESxz = CalcAverageGaussPointValues(Sxz); + avgESyz = CalcAverageGaussPointValues(Syz); + avgPls = CalcAverageGaussPointValues(pstr); + } - // Calculate values at nodes - if (this->GetExtrapoMethod() == ExtrapolationMethod::EXTRAPO_LINEAR) + for (i = 0; i < nnodes; i++) { - // - SetExtropoGaussPoints(i); - // - ComputeShapefct(1); // Linear interpolation function - // - for(j = i_s; j < i_e; j++) + ESxx = ESyy = ESzz = ESxy = ESxz = ESyz = Pls = 0.0; + + // Calculate values at nodes + if (this->GetExtrapoMethod() == ExtrapolationMethod::EXTRAPO_LINEAR) { - k = j - ish; - ESxx += Sxx[j] * shapefct[k]; - ESyy += Syy[j] * shapefct[k]; - ESxy += Sxy[j] * shapefct[k]; - ESzz += Szz[j] * shapefct[k]; - Pls += pstr[j] * shapefct[k]; - if(ele_dim == 3) + // + SetExtropoGaussPoints(i); + // + ComputeShapefct(1); // Linear interpolation function + // + for (j = i_s; j < i_e; j++) { - ESxz += Sxz[j] * shapefct[k]; - ESyz += Syz[j] * shapefct[k]; + k = j - ish; + ESxx += Sxx[j] * shapefct[k]; + ESyy += Syy[j] * shapefct[k]; + ESxy += Sxy[j] * shapefct[k]; + ESzz += Szz[j] * shapefct[k]; + Pls += pstr[j] * shapefct[k]; + if (ele_dim == 3) + { + ESxz += Sxz[j] * shapefct[k]; + ESyz += Syz[j] * shapefct[k]; + } } } - } - else if (this->GetExtrapoMethod() == ExtrapolationMethod::EXTRAPO_AVERAGE) - { - //average - ESxx = avgESxx; - ESyy = avgESyy; - ESxy = avgESxy; - ESzz = avgESzz; - Pls = avgPls; - if(ele_dim == 3) + else if (this->GetExtrapoMethod() == ExtrapolationMethod::EXTRAPO_AVERAGE) { - ESxz = avgESxz; - ESyz = avgESyz; + // average + ESxx = avgESxx; + ESyy = avgESyy; + ESxy = avgESxy; + ESzz = avgESzz; + Pls = avgPls; + if (ele_dim == 3) + { + ESxz = avgESxz; + ESyz = avgESyz; + } } - } - // Average value of the contribution of ell neighbor elements - ESxx /= dbuff[i]; - ESyy /= dbuff[i]; - ESxy /= dbuff[i]; - ESzz /= dbuff[i]; - Pls /= dbuff[i]; - // - node_i = nodes[i]; - ESxx += pcs->GetNodeValue(node_i,Idx_Stress[0]); - ESyy += pcs->GetNodeValue(node_i,Idx_Stress[1]); - ESzz += pcs->GetNodeValue(node_i,Idx_Stress[2]); - ESxy += pcs->GetNodeValue(node_i,Idx_Stress[3]); - if(eleV_DM->pStrain) //08.02.2008 WW - Pls += pcs->GetNodeValue(node_i,idx_pls); - - pcs->SetNodeValue (node_i, Idx_Stress[0], ESxx); - pcs->SetNodeValue (node_i, Idx_Stress[1], ESyy); - pcs->SetNodeValue (node_i, Idx_Stress[2], ESzz); - pcs->SetNodeValue (node_i, Idx_Stress[3], ESxy); - if(eleV_DM->pStrain) //08.02.2008 WW - pcs->SetNodeValue (node_i, idx_pls, fabs(Pls)); - - if(ele_dim == 3) - { - ESxz /= dbuff[i]; - ESyz /= dbuff[i]; + // Average value of the contribution of ell neighbor elements + ESxx /= dbuff[i]; + ESyy /= dbuff[i]; + ESxy /= dbuff[i]; + ESzz /= dbuff[i]; + Pls /= dbuff[i]; + // + node_i = nodes[i]; + ESxx += pcs->GetNodeValue(node_i, Idx_Stress[0]); + ESyy += pcs->GetNodeValue(node_i, Idx_Stress[1]); + ESzz += pcs->GetNodeValue(node_i, Idx_Stress[2]); + ESxy += pcs->GetNodeValue(node_i, Idx_Stress[3]); + if (eleV_DM->pStrain) // 08.02.2008 WW + Pls += pcs->GetNodeValue(node_i, idx_pls); + + pcs->SetNodeValue(node_i, Idx_Stress[0], ESxx); + pcs->SetNodeValue(node_i, Idx_Stress[1], ESyy); + pcs->SetNodeValue(node_i, Idx_Stress[2], ESzz); + pcs->SetNodeValue(node_i, Idx_Stress[3], ESxy); + if (eleV_DM->pStrain) // 08.02.2008 WW + pcs->SetNodeValue(node_i, idx_pls, fabs(Pls)); + + if (ele_dim == 3) + { + ESxz /= dbuff[i]; + ESyz /= dbuff[i]; - ESxz += pcs->GetNodeValue(node_i,Idx_Stress[4]); - ESyz += pcs->GetNodeValue(node_i,Idx_Stress[5]); + ESxz += pcs->GetNodeValue(node_i, Idx_Stress[4]); + ESyz += pcs->GetNodeValue(node_i, Idx_Stress[5]); - pcs->SetNodeValue (node_i, Idx_Stress[4], ESxz); - pcs->SetNodeValue (node_i, Idx_Stress[5], ESyz); + pcs->SetNodeValue(node_i, Idx_Stress[4], ESxz); + pcs->SetNodeValue(node_i, Idx_Stress[5], ESyz); + } } } -} - -//========================================================================== -// Enhanced strain element -/*************************************************************************** - GeoSys - Funktion: - CFiniteElementVec::CheckNodesInJumpedDomain(const double *tangJump) - - Aufgabe: - Compute the regular enhanced strain matrix (Only 2D) - Ge: (See the related references) - (Prorior: element nodes is fetched ) - - Formalparameter: - E: - const double *tangJump : Tangential to the jump surface - Programming: - 06/2004 WW Erste Version - **************************************************************************/ -void CFiniteElementVec::CheckNodesInJumpedDomain() -{ - int i; - double cdotpdt; - // static double dphi_e[3]; + //========================================================================== + // Enhanced strain element + /*************************************************************************** + GeoSys - Funktion: + CFiniteElementVec::CheckNodesInJumpedDomain(const double *tangJump) - // 2D - // Get the center of the discontinuity + Aufgabe: + Compute the regular enhanced strain matrix (Only 2D) + Ge: (See the related references) + (Prorior: element nodes is fetched ) - X0[0] = 0.5 * ((*eleV_DM->NodesOnPath)(0,0) + (*eleV_DM->NodesOnPath)(0,1)); - X0[1] = 0.5 * ((*eleV_DM->NodesOnPath)(1,0) + (*eleV_DM->NodesOnPath)(1,1)); - X0[2] = 0.5 * ((*eleV_DM->NodesOnPath)(2,0) + (*eleV_DM->NodesOnPath)(2,1)); + Formalparameter: + E: + const double *tangJump : Tangential to the jump surface - // Determine nodes in the jumping part - for(i = 0; i < nnodesHQ; i++) + Programming: + 06/2004 WW Erste Version + **************************************************************************/ + void CFiniteElementVec::CheckNodesInJumpedDomain() { - NodesInJumpedA[i] = false; - cdotpdt = 0.0; - cdotpdt += n_jump[0] * ( X[i] - X0[0]); - cdotpdt += n_jump[1] * ( Y[i] - X0[1]); - if(ele_dim == 3) - cdotpdt += n_jump[2] * ( Z[i] - X0[2]); - if(cdotpdt > 0.0) - NodesInJumpedA[i] = true; // Nodes in $\Omega_+$ - } -} - -/*************************************************************************** - GeoSys - Funktion: - CFiniteElementVec::ComputeRESM(double * normJump) - - Aufgabe: - Compute the regular enhanced strain matrix (Only 2D) - Ge: (See the related references) - (Prorior: element nodes is fetched ) - - Formalparameter: - E: - const double *tangJump : Tangential to the jump surface - - Programming: - 06/2004 WW Erste Version - **************************************************************************/ -void CFiniteElementVec::ComputeRESM(const double* tangJump) -{ - static double dphi_e[3]; - - for(size_t i = 0; i < ele_dim; i++) - { - dphi_e[i] = 0.0; - for(int j = 0; j < nnodesHQ; j++) - // for(int j=0; jNodesOnPath)(0, 0) + (*eleV_DM->NodesOnPath)(0, 1)); + X0[1] = 0.5 * ((*eleV_DM->NodesOnPath)(1, 0) + (*eleV_DM->NodesOnPath)(1, 1)); + X0[2] = 0.5 * ((*eleV_DM->NodesOnPath)(2, 0) + (*eleV_DM->NodesOnPath)(2, 1)); - Programming: - 06/2004 WW Erste Version - **************************************************************************/ -void CFiniteElementVec::ComputeSESM(const double* tangJump) -{ - // !!! Only for 2D up to now - tangJump = tangJump; - // Column 1 - (*Pe)(0,0) = n_jump[0] * n_jump[0]; - (*Pe)(0,1) = n_jump[1] * n_jump[1]; - (*Pe)(0,2) = 0.0; - (*Pe)(0,3) = 2.0 * n_jump[0] * n_jump[1]; - - // Column 2 - (*Pe)(1,0) = -n_jump[0] * n_jump[1]; - (*Pe)(1,1) = n_jump[1] * n_jump[0]; - (*Pe)(1,2) = 0.0; - (*Pe)(1,3) = n_jump[0] * n_jump[0] - n_jump[1] * n_jump[1]; -} + // Determine nodes in the jumping part + for (i = 0; i < nnodesHQ; i++) + { + NodesInJumpedA[i] = false; + cdotpdt = 0.0; + cdotpdt += n_jump[0] * (X[i] - X0[0]); + cdotpdt += n_jump[1] * (Y[i] - X0[1]); + if (ele_dim == 3) + cdotpdt += n_jump[2] * (Z[i] - X0[2]); + if (cdotpdt > 0.0) + NodesInJumpedA[i] = true; // Nodes in $\Omega_+$ + } + } -/*************************************************************************** - GeoSys - Funktion: - CFiniteElementVec::ComputePrincipleStresses(double *dEStress) - (2D only) - Aufgabe: + /*************************************************************************** + GeoSys - Funktion: + CFiniteElementVec::ComputeRESM(double * normJump) - Formalparameter: - E: - const double *Stresses: Stresses + Aufgabe: + Compute the regular enhanced strain matrix (Only 2D) + Ge: (See the related references) + (Prorior: element nodes is fetched ) - Return: Angle of maxium principle stress component to x direction - sig2= pr_stress[0]) - { - prin_ang += 0.5 * pai; - var = pr_stress[0]; - pr_stress[0] = pr_stress[1]; - pr_stress[1] = var; - } - //if(pr_stress[0]<0.0) prin_ang += pai; - return prin_ang; -} -/*************************************************************************** - GeoSys - Funktion: - CFiniteElementVec::ComputeJumpDirectionAngle(const double *Stresses, double *Mat) - (2D Drucker-Prager plasticity only. - cf. K. Runesson, D. Peric and S. Sture, - Discontinuous bifucations of elasto-plastic solutions at plane stress - and plane strain, Int. J. Plasticity 7(1991) 2087-2105) - Aufgabe: + Programming: + 06/2004 WW Erste Version + **************************************************************************/ + void CFiniteElementVec::ComputeRESM(const double* tangJump) + { + static double dphi_e[3]; - Formalparameter: - E: - const double *Stresses: Stresses - const double *Mat : Material parameters - 0, dilatancy - 1, frictional - 2, Poission ratio - Return: Angle of maxium principle stress component to x direction + for (size_t i = 0; i < ele_dim; i++) + { + dphi_e[i] = 0.0; + for (int j = 0; j < nnodesHQ; j++) + // for(int j=0; j= 0.0 || c2 <= 0.0) - NormS = -1.0; - else - NormS = atan(sqrt(-c2 / c1)); + if (NodesInJumpedA[j]) + dphi_e[i] += dshapefctHQ[i * nnodesHQ + j]; + // dphi_e[i] += dshapefct[i*nnodes+j]; + } + // !!! Only for 2D up to now + tangJump = tangJump; + // Column 1 + (*Ge)(0, 0) = n_jump[0] * dphi_e[0]; + (*Ge)(1, 0) = n_jump[1] * dphi_e[1]; + (*Ge)(2, 0) = 0.0; + (*Ge)(3, 0) = n_jump[0] * dphi_e[1] + n_jump[1] * dphi_e[0]; + + // Column 2 + (*Ge)(0, 1) = -n_jump[1] * dphi_e[0]; + (*Ge)(1, 1) = n_jump[0] * dphi_e[1]; + (*Ge)(2, 1) = 0.0; + (*Ge)(3, 1) = -n_jump[1] * dphi_e[1] + n_jump[0] * dphi_e[0]; + } + + /*************************************************************************** + GeoSys - Funktion: + CFiniteElementVec::ComputeSESM(double * normJump) + + Aufgabe: + Compute the singular enhanced strain matrix (Only 2D) + Ge: (See the related references) + (Prorior: element nodes is fetched ) + + Formalparameter: + E: + const double *tangJump : Tangential to the jump surface + + Programming: + 06/2004 WW Erste Version + **************************************************************************/ + void CFiniteElementVec::ComputeSESM(const double* tangJump) + { + // !!! Only for 2D up to now + tangJump = tangJump; + // Column 1 + (*Pe)(0, 0) = n_jump[0] * n_jump[0]; + (*Pe)(0, 1) = n_jump[1] * n_jump[1]; + (*Pe)(0, 2) = 0.0; + (*Pe)(0, 3) = 2.0 * n_jump[0] * n_jump[1]; + + // Column 2 + (*Pe)(1, 0) = -n_jump[0] * n_jump[1]; + (*Pe)(1, 1) = n_jump[1] * n_jump[0]; + (*Pe)(1, 2) = 0.0; + (*Pe)(1, 3) = n_jump[0] * n_jump[0] - n_jump[1] * n_jump[1]; + } + + /*************************************************************************** + GeoSys - Funktion: + CFiniteElementVec::ComputePrincipleStresses(double *dEStress) + (2D only) + Aufgabe: + + Formalparameter: + E: + const double *Stresses: Stresses + + Return: Angle of maxium principle stress component to x direction + sig2= pr_stress[0]) + { + prin_ang += 0.5 * pai; + var = pr_stress[0]; + pr_stress[0] = pr_stress[1]; + pr_stress[1] = var; + } + // if(pr_stress[0]<0.0) prin_ang += pai; + return prin_ang; + } + /*************************************************************************** + GeoSys - Funktion: + CFiniteElementVec::ComputeJumpDirectionAngle(const double *Stresses, double *Mat) + (2D Drucker-Prager plasticity only. + cf. K. Runesson, D. Peric and S. Sture, + Discontinuous bifucations of elasto-plastic solutions at plane stress + and plane strain, Int. J. Plasticity 7(1991) 2087-2105) + Aufgabe: + + Formalparameter: + E: + const double *Stresses: Stresses + const double *Mat : Material parameters + 0, dilatancy + 1, frictional + 2, Poission ratio + Return: Angle of maxium principle stress component to x direction + + Programming: + 06/2004 WW Erste Version + **************************************************************************/ + double CFiniteElementVec::ComputeJumpDirectionAngle(const double* Mat) + { + double NormS, c1, c2; + DeviatoricStress(pr_stress); + NormS = sqrt(TensorMutiplication2(pr_stress, pr_stress, ele_dim)); + c1 = pr_stress[1] + Mat[2] * pr_stress[2] + 0.5 * (1.0 + Mat[2]) * (Mat[0] + Mat[1]) * NormS; + c2 = pr_stress[0] + Mat[2] * pr_stress[2] + 0.5 * (1.0 + Mat[2]) * (Mat[0] + Mat[1]) * NormS; + + if (c1 >= 0.0 || c2 <= 0.0) + NormS = -1.0; + else + NormS = atan(sqrt(-c2 / c1)); - return NormS; // The angle return through NormS -} + return NormS; // The angle return through NormS + } -/************************************************************************** - GeoSys - Funktion: - void CFiniteElementVec::LocalAssembly_CheckLocalization + /************************************************************************** + GeoSys - Funktion: + void CFiniteElementVec::LocalAssembly_CheckLocalization - Aufgabe: - Trace discontinuity surface and determine the normal direction to it - element-wisely. (Material related) - (Drucker-Prager model and 2D only) + Aufgabe: + Trace discontinuity surface and determine the normal direction to it + element-wisely. (Material related) + (Drucker-Prager model and 2D only) - Formalparameter: (E: Eingabe; R: Rueckgabe; X: Beides) - E : + Formalparameter: (E: Eingabe; R: Rueckgabe; X: Beides) + E : - Programmaenderungen: - 06/2004 WW Erste Version -**************************************************************************/ -bool CFiniteElementVec::LocalAssembly_CheckLocalization(CElem* MElement) -{ - int i,j,k; - int MatGroup; + Programmaenderungen: + 06/2004 WW Erste Version + **************************************************************************/ + bool CFiniteElementVec::LocalAssembly_CheckLocalization(CElem * MElement) + { + int i, j, k; + int MatGroup; - double ep, p, normXi, n2; + double ep, p, normXi, n2; - // For enhanced strain element - double h_loc, detA, h_tol = 1.0e-5; - double pr_stress_ang, loc_ang; - static double OriJ[2], Nj[2], Aac[4], Mat[3]; - bool LOCed = false; - // - MeshElement = MElement; - eleV_DM = ele_value_dm[MeshElement->GetIndex()]; + // For enhanced strain element + double h_loc, detA, h_tol = 1.0e-5; + double pr_stress_ang, loc_ang; + static double OriJ[2], Nj[2], Aac[4], Mat[3]; + bool LOCed = false; + // + MeshElement = MElement; + eleV_DM = ele_value_dm[MeshElement->GetIndex()]; - p = 0.0; - // Get the total effective plastic strain - ep = 0.0; - for(i = 0; i < nGaussPoints; i++) - ep += (*eleV_DM->pStrain)(i); - ep /= (double)nGaussPoints; + p = 0.0; + // Get the total effective plastic strain + ep = 0.0; + for (i = 0; i < nGaussPoints; i++) + ep += (*eleV_DM->pStrain)(i); + ep /= (double)nGaussPoints; - if(ep > 0.0) // in yield status - { - if(!eleV_DM->Localized) + if (ep > 0.0) // in yield status { + if (!eleV_DM->Localized) + { #ifdef RFW_FRACTURE - smat->Calculate_Lame_Constant(MeshElement); + smat->Calculate_Lame_Constant(MeshElement); #endif #ifndef RFW_FRACTURE - smat->Calculate_Lame_Constant(); + smat->Calculate_Lame_Constant(); #endif - smat->CalulateCoefficent_DP(); + smat->CalulateCoefficent_DP(); - MatGroup = MeshElement->GetPatchIndex(); - smat = msp_vector[MatGroup]; + MatGroup = MeshElement->GetPatchIndex(); + smat = msp_vector[MatGroup]; - Mat[0] = smat->Al; - Mat[1] = smat->Xi; - Mat[2] = smat->Poisson_Ratio(); + Mat[0] = smat->Al; + Mat[1] = smat->Xi; + Mat[2] = smat->Poisson_Ratio(); - // Compute the average stress of this element - for(i = 0; i < ns; i++) - dstress[i] = 0.0; - for(i = 0; i < nGaussPoints; i++) - for(j = 0; j < ns; j++) - dstress[j] += (*eleV_DM->Stress)(j,i); - for(i = 0; i < ns; i++) - dstress[i] /= (double)nGaussPoints; + // Compute the average stress of this element + for (i = 0; i < ns; i++) + dstress[i] = 0.0; + for (i = 0; i < nGaussPoints; i++) + for (j = 0; j < ns; j++) + dstress[j] += (*eleV_DM->Stress)(j, i); + for (i = 0; i < ns; i++) + dstress[i] /= (double)nGaussPoints; - // Get the converged stresses of the previous step - //--- Compute the determinate of the acoustic tensor - pr_stress_ang = ComputePrincipleStresses(dstress); - loc_ang = ComputeJumpDirectionAngle(Mat); + // Get the converged stresses of the previous step + //--- Compute the determinate of the acoustic tensor + pr_stress_ang = ComputePrincipleStresses(dstress); + loc_ang = ComputeJumpDirectionAngle(Mat); - normXi = sqrt(TensorMutiplication2(pr_stress, pr_stress, ele_dim)); + normXi = sqrt(TensorMutiplication2(pr_stress, pr_stress, ele_dim)); - // Compute the localization condition - h_loc = pr_stress[2] / normXi + 0.5 * (smat->Al + smat->Xi) - - 0.5 * - sqrt(2.0 / (1.0 - smat->Poisson_Ratio())) * (smat->Al - smat->Xi); - detA = 1.0e8; + // Compute the localization condition + h_loc = pr_stress[2] / normXi + 0.5 * (smat->Al + smat->Xi) + - 0.5 * sqrt(2.0 / (1.0 - smat->Poisson_Ratio())) * (smat->Al - smat->Xi); + detA = 1.0e8; - // Two possible jump orientation, i.e. pr_stress_ang+/-loc_ang - OriJ[0] = pr_stress_ang - loc_ang + 0.5 * pai; - OriJ[1] = pr_stress_ang + loc_ang + 0.5 * pai; + // Two possible jump orientation, i.e. pr_stress_ang+/-loc_ang + OriJ[0] = pr_stress_ang - loc_ang + 0.5 * pai; + OriJ[1] = pr_stress_ang + loc_ang + 0.5 * pai; - // Compute the acoustic matrix - DeviatoricStress(dstress); - normXi = sqrt(TensorMutiplication2(dstress, dstress, ele_dim)); - if(loc_ang > 0.0) - { - for(i = 0; i < ns; i++) - dstress[i] /= normXi; - for(k = 0; k < 2; k++) + // Compute the acoustic matrix + DeviatoricStress(dstress); + normXi = sqrt(TensorMutiplication2(dstress, dstress, ele_dim)); + if (loc_ang > 0.0) { - n_jump[0] = cos(OriJ[k]); - n_jump[1] = sin(OriJ[k]); - // - Nj[0] = dstress[0] * n_jump[0] + dstress[3] * n_jump[1]; - Nj[1] = dstress[3] * n_jump[0] + dstress[1] * n_jump[1]; - - for(i = 0; i < 4; i++) - Aac[i] = 0.0; - for(i = 0; i < 2; i++) + for (i = 0; i < ns; i++) + dstress[i] /= normXi; + for (k = 0; k < 2; k++) { - Aac[i * 2 + i] = smat->G; - for(j = 0; j < 2; j++) - Aac[i * 2 + - j] += - (smat->K + smat->G / - 3.0) * n_jump[i] * n_jump[j] - - (4.5 * smat->Al * - smat->Xi * smat->K * smat->K * - n_jump[i] * - n_jump[j] + 3.0 * smat->G * - smat->K - * (smat->Al * Nj[i] * - n_jump[j] + smat->Xi * - Nj[j] * - n_jump[i]) - + 2.0 * smat->G * - smat->G * Nj[i] * Nj[j]) - / (4.5 * smat->Al * - smat->Xi * smat->K + smat->G); - } - detA = Aac[0] * Aac[3] - Aac[1] * Aac[2]; - if(detA <= 0.0) - { - LOCed = true; - break; + n_jump[0] = cos(OriJ[k]); + n_jump[1] = sin(OriJ[k]); + // + Nj[0] = dstress[0] * n_jump[0] + dstress[3] * n_jump[1]; + Nj[1] = dstress[3] * n_jump[0] + dstress[1] * n_jump[1]; + + for (i = 0; i < 4; i++) + Aac[i] = 0.0; + for (i = 0; i < 2; i++) + { + Aac[i * 2 + i] = smat->G; + for (j = 0; j < 2; j++) + Aac[i * 2 + j] + += (smat->K + smat->G / 3.0) * n_jump[i] * n_jump[j] + - (4.5 * smat->Al * smat->Xi * smat->K * smat->K * n_jump[i] * n_jump[j] + + 3.0 * smat->G * smat->K + * (smat->Al * Nj[i] * n_jump[j] + smat->Xi * Nj[j] * n_jump[i]) + + 2.0 * smat->G * smat->G * Nj[i] * Nj[j]) + / (4.5 * smat->Al * smat->Xi * smat->K + smat->G); + } + detA = Aac[0] * Aac[3] - Aac[1] * Aac[2]; + if (detA <= 0.0) + { + LOCed = true; + break; + } } + for (i = 0; i < ns; i++) + dstress[i] *= normXi; } - for(i = 0; i < ns; i++) - dstress[i] *= normXi; - } - // - if(fabs(h_loc) < h_tol) - LOCed = true; - - if(LOCed) - { - eleV_DM->orientation = new double[ele_dim]; - for(i = 0; i < 2; i++) - eleV_DM->orientation[i] = OriJ[i]; - eleV_DM->Localized = true; + // + if (fabs(h_loc) < h_tol) + LOCed = true; - // Choose one orientation. Empirical formular. 2D - if(!Localizing) + if (LOCed) { - for(i = 0; i < 3; i++) - dstress[i] += p / 3.0; - //WW n1 = (dstress[0]*cos(0.5*pai+OriJ[0])+dstress[1]*sin(0.5*pai+OriJ[0]))/normXi; - n2 = - (dstress[0] * - cos(0.5 * pai + - OriJ[1]) + dstress[1] * - sin(0.5 * pai + OriJ[1])) / normXi; - if(n2 > 0.0) + eleV_DM->orientation = new double[ele_dim]; + for (i = 0; i < 2; i++) + eleV_DM->orientation[i] = OriJ[i]; + eleV_DM->Localized = true; + + // Choose one orientation. Empirical formular. 2D + if (!Localizing) { - // Always use orientation[0] - eleV_DM->orientation[0] = OriJ[1]; - eleV_DM->orientation[1] = OriJ[0]; + for (i = 0; i < 3; i++) + dstress[i] += p / 3.0; + // WW n1 = (dstress[0]*cos(0.5*pai+OriJ[0])+dstress[1]*sin(0.5*pai+OriJ[0]))/normXi; + n2 = (dstress[0] * cos(0.5 * pai + OriJ[1]) + dstress[1] * sin(0.5 * pai + OriJ[1])) / normXi; + if (n2 > 0.0) + { + // Always use orientation[0] + eleV_DM->orientation[0] = OriJ[1]; + eleV_DM->orientation[1] = OriJ[0]; + } } } } } + return LOCed; } - return LOCed; -} - -/************************************************************************** - GeoSys - Funktion: - void CFiniteElementVec::IntersectionPoint(const int O_edge, const double k, - const double *NodeA, double nodeB ) - 2D only - Aufgabe: - Determine the second intersection point of a line and the element. - 2D only (Geometry) - Formalparameter: (E: Eingabe; R: Rueckgabe; X: Beides) - E : - const int O_edge : Edge will the departure point on - const double *NodeA : original node - double nodeB : Intersection point - - Programmaenderungen: - 06/2004 WW Erste Version -**************************************************************************/ -int CFiniteElementVec::IntersectionPoint(const int O_edge, const double* NodeA, double* NodeB ) -{ - int i,j, k, numf; //, nfnode; - - static double k1, k2, n1, n2, xA[3],xB[3]; - static int Face_node[8]; // Only 2D - - double Tol = 1.0e-12; - double area0, area1; - area0 = MeshElement->GetVolume(); - - k = -1; - eleV_DM = ele_value_dm[Index]; + /************************************************************************** + GeoSys - Funktion: + void CFiniteElementVec::IntersectionPoint(const int O_edge, const double k, + const double *NodeA, double nodeB ) + 2D only + Aufgabe: + Determine the second intersection point of a line and the element. + 2D only (Geometry) + Formalparameter: (E: Eingabe; R: Rueckgabe; X: Beides) + E : + const int O_edge : Edge will the departure point on + const double *NodeA : original node + double nodeB : Intersection point - numf = MeshElement->GetFacesNumber(); - for(i = 0; i < numf; i++) + Programmaenderungen: + 06/2004 WW Erste Version + **************************************************************************/ + int CFiniteElementVec::IntersectionPoint(const int O_edge, const double* NodeA, double* NodeB) { - k = -1; - if(i != O_edge) - { - //WW nfnode = - MeshElement->GetElementFaceNodes(i, Face_node); + int i, j, k, numf; //, nfnode; - xA[0] = X[Face_node[0]]; - xA[1] = Y[Face_node[0]]; - xA[2] = Z[Face_node[0]]; - xB[0] = X[Face_node[1]]; - xB[1] = Y[Face_node[1]]; - xB[2] = Z[Face_node[1]]; + static double k1, k2, n1, n2, xA[3], xB[3]; + static int Face_node[8]; // Only 2D - n1 = cos(eleV_DM->orientation[0]); - n2 = sin(eleV_DM->orientation[0]); + double Tol = 1.0e-12; + double area0, area1; + area0 = MeshElement->GetVolume(); - // parallel - if(fabs((xB[0] - xA[0]) * n1 + (xB[1] - xA[1]) * n2) < Tol) - continue; + k = -1; - if(fabs(n2) < Tol) - { - NodeB[0] = NodeA[0]; - NodeB[1] = (NodeA[0] - xA[0]) * (xB[1] - xA[1]) / (xB[0] - xA[0]) - + xA[1]; - } - else if(fabs(xB[0] - xA[0]) < Tol) - { - NodeB[0] = xA[0]; - NodeB[1] = -n1 * (xA[0] - NodeA[0]) / n2 + NodeA[1]; - } - else - { - k1 = (xB[1] - xA[1]) / (xB[0] - xA[0]); - k2 = -n1 / n2; - NodeB[0] = - (NodeA[1] - xA[1] + k1 * xA[0] - k2 * NodeA[0]) / (k1 - k2); - NodeB[1] = k1 * (NodeB[0] - xA[0]) + xA[1]; - } - k = i; - } + eleV_DM = ele_value_dm[Index]; - // Check if this point is on an edge of this element. - if(k >= 0) // Has intersection + numf = MeshElement->GetFacesNumber(); + for (i = 0; i < numf; i++) { - area1 = 0.0; - for(j = 0; j < numf; j++) + k = -1; + if (i != O_edge) { - if(j == k) - continue; - //WW nfnode = - MeshElement->GetElementFaceNodes(j, Face_node); + // WW nfnode = + MeshElement->GetElementFaceNodes(i, Face_node); + xA[0] = X[Face_node[0]]; xA[1] = Y[Face_node[0]]; xA[2] = Z[Face_node[0]]; xB[0] = X[Face_node[1]]; xB[1] = Y[Face_node[1]]; xB[2] = Z[Face_node[1]]; - area1 += ComputeDetTri(xA, xB, NodeB); + + n1 = cos(eleV_DM->orientation[0]); + n2 = sin(eleV_DM->orientation[0]); + + // parallel + if (fabs((xB[0] - xA[0]) * n1 + (xB[1] - xA[1]) * n2) < Tol) + continue; + + if (fabs(n2) < Tol) + { + NodeB[0] = NodeA[0]; + NodeB[1] = (NodeA[0] - xA[0]) * (xB[1] - xA[1]) / (xB[0] - xA[0]) + xA[1]; + } + else if (fabs(xB[0] - xA[0]) < Tol) + { + NodeB[0] = xA[0]; + NodeB[1] = -n1 * (xA[0] - NodeA[0]) / n2 + NodeA[1]; + } + else + { + k1 = (xB[1] - xA[1]) / (xB[0] - xA[0]); + k2 = -n1 / n2; + NodeB[0] = (NodeA[1] - xA[1] + k1 * xA[0] - k2 * NodeA[0]) / (k1 - k2); + NodeB[1] = k1 * (NodeB[0] - xA[0]) + xA[1]; + } + k = i; + } + + // Check if this point is on an edge of this element. + if (k >= 0) // Has intersection + { + area1 = 0.0; + for (j = 0; j < numf; j++) + { + if (j == k) + continue; + // WW nfnode = + MeshElement->GetElementFaceNodes(j, Face_node); + xA[0] = X[Face_node[0]]; + xA[1] = Y[Face_node[0]]; + xA[2] = Z[Face_node[0]]; + xB[0] = X[Face_node[1]]; + xB[1] = Y[Face_node[1]]; + xB[2] = Z[Face_node[1]]; + area1 += ComputeDetTri(xA, xB, NodeB); + } + if (fabs(area0 - area1) < Tol) + break; } - if(fabs(area0 - area1) < Tol) - break; } + return k; // Local index of other intersection point } - return k; // Local index of other intersection point -} -/************************************************************************** - GeoSys - Funktion: void CFiniteElementVec::LocalAssembly_EnhancedStrain + /************************************************************************** + GeoSys - Funktion: void CFiniteElementVec::LocalAssembly_EnhancedStrain - Aufgabe: - Local assembly within the strong discontinuity assumption - (Drucker-Prager model and 2D only) + Aufgabe: + Local assembly within the strong discontinuity assumption + (Drucker-Prager model and 2D only) - Formalparameter: (E: Eingabe; R: Rueckgabe; X: Beides) - E : - const int update: 1 update Gauss values - 0 do not update + Formalparameter: (E: Eingabe; R: Rueckgabe; X: Beides) + E : + const int update: 1 update Gauss values + 0 do not update - Ergebnis: - - double* - Deviatoric effetive stresses, s11,s22,s12,s33 + Ergebnis: + - double* - Deviatoric effetive stresses, s11,s22,s12,s33 - Programmaenderungen: - 06/2004 WW Erste Version -**************************************************************************/ -void CFiniteElementVec::LocalAssembly_EnhancedStrain(const int update) -{ - int gp_r(0), gp_s(0), gp_t(0); - double fkt = 0.0, area, Jac_e = 0.0, f_j; + Programmaenderungen: + 06/2004 WW Erste Version + **************************************************************************/ + void CFiniteElementVec::LocalAssembly_EnhancedStrain(const int update) + { + int gp_r(0), gp_s(0), gp_t(0); + double fkt = 0.0, area, Jac_e = 0.0, f_j; - // For enhanced strain element - double f_tol = 1.0e-4; //Triangle 1.0e-8; - double loc_dilatancy = 0.0, zeta_t0, zeta_t1; - double sign, sj0,sj = 0.0; - static double tt0[2], tt[2], zeta[2], D_prj[2]; + // For enhanced strain element + double f_tol = 1.0e-4; // Triangle 1.0e-8; + double loc_dilatancy = 0.0, zeta_t0, zeta_t1; + double sign, sj0, sj = 0.0; + static double tt0[2], tt[2], zeta[2], D_prj[2]; - bool isLoop = true; // Used only to avoid warnings with .net + bool isLoop = true; // Used only to avoid warnings with .net - double ThermalExpansion = 0.0, Tem = 0.0; - gp = 0; - BDG->LimitSize(2, 2 * nnodesHQ); - PDB->LimitSize(2 * nnodesHQ,2); + double ThermalExpansion = 0.0, Tem = 0.0; + gp = 0; + BDG->LimitSize(2, 2 * nnodesHQ); + PDB->LimitSize(2 * nnodesHQ, 2); - if(T_Flag) - { - // Thermal effect - if(smat->Thermal_Expansion() > 0.0) - ThermalExpansion = smat->Thermal_Expansion(); - for(int i = 0; i < nnodes; i++) - Temp[i] = t_pcs->GetNodeValue(nodes[i],idx_T1) - t_pcs->GetNodeValue( - nodes[i], - idx_T0); - } + if (T_Flag) + { + // Thermal effect + if (smat->Thermal_Expansion() > 0.0) + ThermalExpansion = smat->Thermal_Expansion(); + for (int i = 0; i < nnodes; i++) + Temp[i] = t_pcs->GetNodeValue(nodes[i], idx_T1) - t_pcs->GetNodeValue(nodes[i], idx_T0); + } - // Elastic modulus - smat->Calculate_Lame_Constant(); + // Elastic modulus + smat->Calculate_Lame_Constant(); - smat->ElasticConsitutive(ele_dim, De); + smat->ElasticConsitutive(ele_dim, De); - // Plasticity - smat->CalulateCoefficent_DP(); + // Plasticity + smat->CalulateCoefficent_DP(); - loc_dilatancy = smat->Al * sqrt(2.0 / (1.0 - 3.0 * smat->Al * smat->Al)); - double Hd = 0.5 * smat->Hard_Loc / (1.0 - 3.0 * smat->Al * smat->Al); + loc_dilatancy = smat->Al * sqrt(2.0 / (1.0 - 3.0 * smat->Al * smat->Al)); + double Hd = 0.5 * smat->Hard_Loc / (1.0 - 3.0 * smat->Al * smat->Al); - /* - // Reference - loc_dilatancy = 1.5*sqrt(2.0)*smat->Al*sqrt(1.0-6.0*smat->Al*smat->Al); - double Hd = smat->Hard_Loc/(3.0-18.0*smat->Al*smat->Al); - */ + /* + // Reference + loc_dilatancy = 1.5*sqrt(2.0)*smat->Al*sqrt(1.0-6.0*smat->Al*smat->Al); + double Hd = smat->Hard_Loc/(3.0-18.0*smat->Al*smat->Al); + */ - zeta_t0 = eleV_DM->disp_j; - zeta_t1 = zeta_t0; + zeta_t0 = eleV_DM->disp_j; + zeta_t1 = zeta_t0; - area = MeshElement->volume; + area = MeshElement->volume; - n_jump[0] = cos(eleV_DM->orientation[0]); - n_jump[1] = sin(eleV_DM->orientation[0]); + n_jump[0] = cos(eleV_DM->orientation[0]); + n_jump[1] = sin(eleV_DM->orientation[0]); - // Compute traction on the jump plane - // Compute Pe, singular part of enhanced strain-jump matrix - ComputeSESM(); - // PeDe=P^t *D_e - (*PeDe) = 0.0; - Pe->multi(*De, *PeDe); - // + // Compute traction on the jump plane + // Compute Pe, singular part of enhanced strain-jump matrix + ComputeSESM(); + // PeDe=P^t *D_e + (*PeDe) = 0.0; + Pe->multi(*De, *PeDe); + // - // If this is the beginning of localization - if(fabs(eleV_DM->tract_j) < MKleinsteZahl) - { - // average of stresses within an element - for(int j = 0; j < ns; j++) + // If this is the beginning of localization + if (fabs(eleV_DM->tract_j) < MKleinsteZahl) { - dstress[j] = 0.0; - for(int i = 0; i < nGaussPoints; i++) - dstress[j] += (*eleV_DM->Stress)(j,i); - } - for(int i = 0; i < ns; i++) - dstress[i] /= (double)nGaussPoints; + // average of stresses within an element + for (int j = 0; j < ns; j++) + { + dstress[j] = 0.0; + for (int i = 0; i < nGaussPoints; i++) + dstress[j] += (*eleV_DM->Stress)(j, i); + } + for (int i = 0; i < ns; i++) + dstress[i] /= (double)nGaussPoints; - for(size_t i = 0; i < ele_dim; i++) - { - tt0[i] = 0.0; - for(int j = 0; j < ns; j++) - tt0[i] += (*Pe)(i,j) * dstress[j]; - } - eleV_DM->tract_j = loc_dilatancy * tt0[0] + fabs(tt0[1]); - /* - // - for(gp=0; gpStress)(i,gp); - fkt = GetGaussData(gp, gp_r, gp_s, gp_t); - for(size_t i=0; itract_j = fkt*(loc_dilatancy*tt0[0]+fabs(tt0[1])); - } - eleV_DM->tract_j /= area; - */ - } - // - sj0 = eleV_DM->tract_j; - // - CheckNodesInJumpedDomain(); - // On discontinuity by enhanced strain - // AuxMatrix temporarily used to store PDG - (*AuxMatrix) = 0.0; - // Integration of P^t*Stress^{elastic try} - for(size_t i = 0; i < ele_dim; i++) - tt0[i] = 0.0; - //TEST - for(int i = 0; i < ns; i++) - dstress[i] = 0.0; //Test average appoach - for(gp = 0; gp < nGaussPoints; gp++) - { - //-------------------------------------------------------------- - //----------- Integrate of traction on the jump plane --------- - //-------------------------------------------------------------- - fkt = GetGaussData(gp, gp_r, gp_s, gp_t); - //--------------------------------------------------------- - // Compute geometry - //--------------------------------------------------------- - ComputeGradShapefct(2); - ComputeStrain(); - // Compute Ge, regular part of enhanced strain-jump matrix - ComputeRESM(); - if(T_Flag) // Contribution by thermal expansion - { - ComputeShapefct(1); // Linear interpolation function - Tem = 0.0; - for(int i = 0; i < nnodes; i++) - Tem += shapefct[i] * Temp[i]; - for (size_t i = 0; i < 3; i++) - dstrain[i] -= ThermalExpansion * Tem; + for (size_t i = 0; i < ele_dim; i++) + { + tt0[i] = 0.0; + for (int j = 0; j < ns; j++) + tt0[i] += (*Pe)(i, j) * dstress[j]; + } + eleV_DM->tract_j = loc_dilatancy * tt0[0] + fabs(tt0[1]); + /* + // + for(gp=0; gpStress)(i,gp); + fkt = GetGaussData(gp, gp_r, gp_s, gp_t); + for(size_t i=0; itract_j = fkt*(loc_dilatancy*tt0[0]+fabs(tt0[1])); + } + eleV_DM->tract_j /= area; + */ } - /* - for(int i=0; iStress)(i,gp); - De->multi(dstrain, dstress); - // Try stress - Pe->multi(dstress, tt0, fkt); - */ - // Pe*De*Ge - PeDe->multi(*Ge, *AuxMatrix, fkt); - - //TEST -----------Average approach ------------------------- - for(int i = 0; i < ns; i++) - dstress[i] += (*eleV_DM->Stress)(i,gp); - De->multi(dstrain, dstress); - //----------------------------------------------------------- - } + // + sj0 = eleV_DM->tract_j; + // + CheckNodesInJumpedDomain(); + // On discontinuity by enhanced strain + // AuxMatrix temporarily used to store PDG + (*AuxMatrix) = 0.0; + // Integration of P^t*Stress^{elastic try} + for (size_t i = 0; i < ele_dim; i++) + tt0[i] = 0.0; + // TEST + for (int i = 0; i < ns; i++) + dstress[i] = 0.0; // Test average appoach + for (gp = 0; gp < nGaussPoints; gp++) + { + //-------------------------------------------------------------- + //----------- Integrate of traction on the jump plane --------- + //-------------------------------------------------------------- + fkt = GetGaussData(gp, gp_r, gp_s, gp_t); + //--------------------------------------------------------- + // Compute geometry + //--------------------------------------------------------- + ComputeGradShapefct(2); + ComputeStrain(); + // Compute Ge, regular part of enhanced strain-jump matrix + ComputeRESM(); + if (T_Flag) // Contribution by thermal expansion + { + ComputeShapefct(1); // Linear interpolation function + Tem = 0.0; + for (int i = 0; i < nnodes; i++) + Tem += shapefct[i] * Temp[i]; + for (size_t i = 0; i < 3; i++) + dstrain[i] -= ThermalExpansion * Tem; + } + /* + for(int i=0; iStress)(i,gp); + De->multi(dstrain, dstress); + // Try stress + Pe->multi(dstress, tt0, fkt); + */ + // Pe*De*Ge + PeDe->multi(*Ge, *AuxMatrix, fkt); - //TEST average approach - for(int i = 0; i < ns; i++) - dstress[i] /= (double)nGaussPoints; - Pe->multi(dstress, tt0, 1.0); - for(size_t i = 0; i < ele_dim; i++) - tt0[i] *= area; - //------------------------------------------------------------- + // TEST -----------Average approach ------------------------- + for (int i = 0; i < ns; i++) + dstress[i] += (*eleV_DM->Stress)(i, gp); + De->multi(dstrain, dstress); + //----------------------------------------------------------- + } - // Local Newton iteration for discontinuity number - while(isLoop) - { - zeta[1] = zeta_t1 - zeta_t0; - zeta[0] = loc_dilatancy * fabs(zeta[1]); + // TEST average approach + for (int i = 0; i < ns; i++) + dstress[i] /= (double)nGaussPoints; + Pe->multi(dstress, tt0, 1.0); + for (size_t i = 0; i < ele_dim; i++) + tt0[i] *= area; + //------------------------------------------------------------- - // Sign(zeta_t) - if(fabs(zeta[1]) < MKleinsteZahl) - sign = 1.0; - else - sign = zeta[1] / fabs( zeta[1]); + // Local Newton iteration for discontinuity number + while (isLoop) + { + zeta[1] = zeta_t1 - zeta_t0; + zeta[0] = loc_dilatancy * fabs(zeta[1]); - // - D_prj[0] = sign * loc_dilatancy; - D_prj[1] = 1.0; + // Sign(zeta_t) + if (fabs(zeta[1]) < MKleinsteZahl) + sign = 1.0; + else + sign = zeta[1] / fabs(zeta[1]); - sj = sj0 + Hd * zeta[1]; + // + D_prj[0] = sign * loc_dilatancy; + D_prj[1] = 1.0; - //-------------------------------------------------------------- - //---------------- Local Jacobian -------------------------- - //-------------------------------------------------------------- - for(size_t i = 0; i < ele_dim; i++) - tt[i] = tt0[i]; - AuxMatrix->multi(zeta, tt, -1.0); + sj = sj0 + Hd * zeta[1]; - Jac_e = 0.0; - for (size_t i = 0; i < ele_dim; i++) - for(size_t j = 0; j < ele_dim; j++) - Jac_e += D_prj[i] * (*AuxMatrix)(i,j) * D_prj[j]; + //-------------------------------------------------------------- + //---------------- Local Jacobian -------------------------- + //-------------------------------------------------------------- + for (size_t i = 0; i < ele_dim; i++) + tt[i] = tt0[i]; + AuxMatrix->multi(zeta, tt, -1.0); - Jac_e /= area; - for(size_t i = 0; i < ele_dim; i++) - tt[i] /= area; + Jac_e = 0.0; + for (size_t i = 0; i < ele_dim; i++) + for (size_t j = 0; j < ele_dim; j++) + Jac_e += D_prj[i] * (*AuxMatrix)(i, j) * D_prj[j]; - f_j = D_prj[0] * tt[0] + tt[1] - sj; + Jac_e /= area; + for (size_t i = 0; i < ele_dim; i++) + tt[i] /= area; - Jac_e += Hd; - if(fabs(f_j) < f_tol) - break; + f_j = D_prj[0] * tt[0] + tt[1] - sj; - zeta_t1 += f_j / Jac_e; - } //Loop of the local Newton for enhanced parameter + Jac_e += Hd; + if (fabs(f_j) < f_tol) + break; - // Compute local RHS - (*BDG) = 0.0; - (*PDB) = 0.0; - for(gp = 0; gp < nGaussPoints; gp++) - { - //-------------------------------------------------------------- - //----------- Integrate of traction on the jump plane --------- - //-------------------------------------------------------------- - for(int i = 0; i < ns; i++) - dstress[i] = (*eleV_DM->Stress)(i,gp); - fkt = GetGaussData(gp, gp_r, gp_s, gp_t); - //--------------------------------------------------------- - // Compute geometry - //--------------------------------------------------------- - ComputeGradShapefct(2); - ComputeStrain(); - // Compute Ge - ComputeRESM(); + zeta_t1 += f_j / Jac_e; + } // Loop of the local Newton for enhanced parameter - if(T_Flag) // Contribution by thermal expansion + // Compute local RHS + (*BDG) = 0.0; + (*PDB) = 0.0; + for (gp = 0; gp < nGaussPoints; gp++) { - ComputeShapefct(1); // Linear interpolation function - Tem = 0.0; - for(int i = 0; i < nnodes; i++) - Tem += shapefct[i] * Temp[i]; - for (size_t i = 0; i < 3; i++) - dstrain[i] -= ThermalExpansion * Tem; - } + //-------------------------------------------------------------- + //----------- Integrate of traction on the jump plane --------- + //-------------------------------------------------------------- + for (int i = 0; i < ns; i++) + dstress[i] = (*eleV_DM->Stress)(i, gp); + fkt = GetGaussData(gp, gp_r, gp_s, gp_t); + //--------------------------------------------------------- + // Compute geometry + //--------------------------------------------------------- + ComputeGradShapefct(2); + ComputeStrain(); + // Compute Ge + ComputeRESM(); + + if (T_Flag) // Contribution by thermal expansion + { + ComputeShapefct(1); // Linear interpolation function + Tem = 0.0; + for (int i = 0; i < nnodes; i++) + Tem += shapefct[i] * Temp[i]; + for (size_t i = 0; i < 3; i++) + dstrain[i] -= ThermalExpansion * Tem; + } - // Ehhanced strain: - Ge->multi(zeta, dstrain, -1.0); + // Ehhanced strain: + Ge->multi(zeta, dstrain, -1.0); - // Compute try stress. 1. stress incremental: - De->multi(dstrain, dstress); + // Compute try stress. 1. stress incremental: + De->multi(dstrain, dstress); - // Update stresses if convergence is reached - if(update) - { - // Two Dimensional - RecordGuassStrain(gp, gp_r, gp_s, gp_t); - for(int i = 0; i < ns; i++) + // Update stresses if convergence is reached + if (update) { - (*eleV_DM->Stress)(i,gp) = dstress[i]; - dstrain[i] = 0.0; + // Two Dimensional + RecordGuassStrain(gp, gp_r, gp_s, gp_t); + for (int i = 0; i < ns; i++) + { + (*eleV_DM->Stress)(i, gp) = dstress[i]; + dstrain[i] = 0.0; + } + Ge->multi(zeta, dstrain, 1.0); + DeviatoricStress(dstrain); + (*eleV_DM->pStrain)(gp) += sqrt(2.0 * TensorMutiplication2(dstrain, dstrain, 2) / 3.0); } - Ge->multi(zeta, dstrain, 1.0); - DeviatoricStress(dstrain); - (*eleV_DM->pStrain)(gp) += - sqrt(2.0 * TensorMutiplication2(dstrain, dstrain, 2) / 3.0); - } - else - { - // Compute stiffness matrix - ComputeMatrix_RHS(fkt, De); - // Stiffness contributed by enhanced strain to the stiffness matrix - for (int i = 0; i < nnodesHQ; i++) + else { - setTransB_Matrix(i); - // B^T*D*G - (*AuxMatrix) = 0.0; - B_matrix_T->multi(*De, *Ge, *AuxMatrix); + // Compute stiffness matrix + ComputeMatrix_RHS(fkt, De); + // Stiffness contributed by enhanced strain to the stiffness matrix + for (int i = 0; i < nnodesHQ; i++) + { + setTransB_Matrix(i); + // B^T*D*G + (*AuxMatrix) = 0.0; + B_matrix_T->multi(*De, *Ge, *AuxMatrix); + + for (size_t k = 0; k < ele_dim; k++) + for (size_t l = 0; l < ele_dim; l++) + (*BDG)(k, ele_dim * i + l) += fkt * (*AuxMatrix)(k, l); + // + // P*D*B + setB_Matrix(i); + (*AuxMatrix) = 0.0; + PeDe->multi(*B_matrix, *AuxMatrix); + for (size_t k = 0; k < ele_dim; k++) + for (size_t l = 0; l < ele_dim; l++) + (*PDB)(ele_dim * i + k, l) += fkt * (*AuxMatrix)(k, l) / area; + } + } + } // End of RHS assembly + // Those contributed by enhanced strain to the stiffness matrix + // D*D^T + for (size_t i = 0; i < ele_dim; i++) + for (size_t j = 0; j < ele_dim; j++) + (*DtD)(i, j) = D_prj[i] * D_prj[j]; + + // + for (int i = 0; i < nnodesHQ; i++) + for (int j = 0; j < nnodesHQ; j++) + { + // Local assembly of stiffness matrix for (size_t k = 0; k < ele_dim; k++) for (size_t l = 0; l < ele_dim; l++) - (*BDG)(k, ele_dim * i + - l) += fkt * (*AuxMatrix)(k,l); - // - // P*D*B - setB_Matrix(i); - (*AuxMatrix) = 0.0; - PeDe->multi(*B_matrix, *AuxMatrix); - for (size_t k = 0; k < ele_dim; k++) - for (size_t l = 0; l < ele_dim; l++) - (*PDB)(ele_dim * i + k, - l) += fkt * (*AuxMatrix)(k,l) / area; + { + f_j = 0.0; + for (size_t ii = 0; ii < ele_dim; ii++) + for (size_t jj = 0; jj < ele_dim; jj++) + f_j += (*BDG)(k, ele_dim * i + ii) * (*DtD)(ii, jj) * (*PDB)(ele_dim * j + jj, l); + (*Stiffness)(i + k * nnodesHQ, l * nnodesHQ + j) -= f_j / Jac_e; + } } - } - } // End of RHS assembly - // Those contributed by enhanced strain to the stiffness matrix - // D*D^T - for(size_t i = 0; i < ele_dim; i++) - for(size_t j = 0; j < ele_dim; j++) - (*DtD)(i,j) = D_prj[i] * D_prj[j]; - - // - for (int i = 0; i < nnodesHQ; i++) - for (int j = 0; j < nnodesHQ; j++) + if (update) { - // Local assembly of stiffness matrix - for (size_t k = 0; k < ele_dim; k++) - for (size_t l = 0; l < ele_dim; l++) - { - f_j = 0.0; - for (size_t ii = 0; ii < ele_dim; ii++) - for (size_t jj = 0; jj < ele_dim; jj++) - f_j += - (*BDG)(k, ele_dim * i + - ii) * - (*DtD)(ii, - jj) * - (*PDB)(ele_dim * j + jj, l); - (*Stiffness)(i + k * nnodesHQ, l * nnodesHQ + - j) -= f_j / Jac_e; - } + // Update strains. + // The mapping of Gauss point strain to element nodes + ExtropolateGuassStrain(); + // Update enhanced parameter + eleV_DM->disp_j = zeta_t1; + eleV_DM->tract_j = sj; } - - if(update) - { - // Update strains. - // The mapping of Gauss point strain to element nodes - ExtropolateGuassStrain(); - // Update enhanced parameter - eleV_DM->disp_j = zeta_t1; - eleV_DM->tract_j = sj; } -} -/*---------------------------------------------------------------- - Class ElementValue_DM - - Allocate memory for element value - Matrix *Mat: - | Index | Paramete | - ---------------------- - | 0 | alpha | - | 1 | beta | - | 2 | delta | - | 3 | epsilon | - | 4 | kappa | - | 5 | gamma | - | 6 | m | - ---------------------- - -----------------------------------------------------------------*/ -ElementValue_DM::ElementValue_DM(CElem* ele, const int NGP, bool HM_Staggered) - : NodesOnPath(NULL), orientation(NULL) -{ - int Plastic = 1; - const int LengthMat = 7; // Number of material parameter of SYS model. - int LengthBS = 4; // Number of stress/strain components - int NGPoints = 0; - CSolidProperties* sdp = NULL; - int ele_dim; - // - Stress = NULL; - pStrain = NULL; - prep0 = NULL; - e_i = NULL; - xi = NULL; - MatP = NULL; - NodesOnPath = NULL; - orientation = NULL; - MshElemType::type ele_type = ele->GetElementType(); - ele_dim = ele->GetDimension(); - sdp = msp_vector[ele->GetPatchIndex()]; - Plastic = sdp->Plastictity(); - - if(ele_dim == 2) - LengthBS = 4; - else if(ele_dim == 3) - LengthBS = 6; - - if(ele_type == MshElemType::TRIANGLE) - NGPoints = 3; - else if(ele_type == MshElemType::TETRAHEDRON) - NGPoints = 5; //15 - else if(ele_type == MshElemType::PRISM) - NGPoints = 6; //9 - else - NGPoints = MathLib::fastpow(NGP, ele_dim); + /*---------------------------------------------------------------- + Class ElementValue_DM + + Allocate memory for element value + Matrix *Mat: + | Index | Paramete | + ---------------------- + | 0 | alpha | + | 1 | beta | + | 2 | delta | + | 3 | epsilon | + | 4 | kappa | + | 5 | gamma | + | 6 | m | + ---------------------- + -----------------------------------------------------------------*/ + ElementValue_DM::ElementValue_DM(CElem * ele, const int NGP, bool HM_Staggered) + : NodesOnPath(NULL), orientation(NULL) + { + int Plastic = 1; + const int LengthMat = 7; // Number of material parameter of SYS model. + int LengthBS = 4; // Number of stress/strain components + int NGPoints = 0; + CSolidProperties* sdp = NULL; + int ele_dim; + // + Stress = NULL; + pStrain = NULL; + prep0 = NULL; + e_i = NULL; + xi = NULL; + MatP = NULL; + NodesOnPath = NULL; + orientation = NULL; + MshElemType::type ele_type = ele->GetElementType(); + ele_dim = ele->GetDimension(); + sdp = msp_vector[ele->GetPatchIndex()]; + Plastic = sdp->Plastictity(); + + if (ele_dim == 2) + LengthBS = 4; + else if (ele_dim == 3) + LengthBS = 6; + + if (ele_type == MshElemType::TRIANGLE) + NGPoints = 3; + else if (ele_type == MshElemType::TETRAHEDRON) + NGPoints = 5; // 15 + else if (ele_type == MshElemType::PRISM) + NGPoints = 6; // 9 + else + NGPoints = MathLib::fastpow(NGP, ele_dim); - Stress0 = new Matrix(LengthBS, NGPoints); - Stress_i = new Matrix(LengthBS, NGPoints); - Stress = Stress_i; - if(HM_Staggered) - Stress_j = new Matrix(LengthBS, NGPoints); - else - Stress_j = NULL; // for HM coupling iteration - // - if(Plastic > 0) - { - pStrain = new Matrix(NGPoints); - y_surface = new Matrix(NGPoints); - *y_surface = 0.0; - *pStrain = 0.0; - } - else - y_surface = NULL; - *Stress = 0.0; + Stress0 = new Matrix(LengthBS, NGPoints); + Stress_i = new Matrix(LengthBS, NGPoints); + Stress = Stress_i; + if (HM_Staggered) + Stress_j = new Matrix(LengthBS, NGPoints); + else + Stress_j = NULL; // for HM coupling iteration + // + if (Plastic > 0) + { + pStrain = new Matrix(NGPoints); + y_surface = new Matrix(NGPoints); + *y_surface = 0.0; + *pStrain = 0.0; + } + else + y_surface = NULL; + *Stress = 0.0; - if(Plastic == 2) // Rotational hardening model - { - xi = new Matrix(LengthBS - 1, NGPoints); - MatP = new Matrix(LengthMat, NGPoints); - *xi = 0.0; - *MatP = 0.0; - } - if(Plastic == 3) // Cam-Clay - { - prep0 = new Matrix(NGPoints); - e_i = new Matrix(NGPoints); - *prep0 = 0.0; - *e_i = 0.0; - } - if(sdp->CreepModel() == 1000) - { - xi = new Matrix(LengthBS); - *xi = 0.0; + if (Plastic == 2) // Rotational hardening model + { + xi = new Matrix(LengthBS - 1, NGPoints); + MatP = new Matrix(LengthMat, NGPoints); + *xi = 0.0; + *MatP = 0.0; + } + if (Plastic == 3) // Cam-Clay + { + prep0 = new Matrix(NGPoints); + e_i = new Matrix(NGPoints); + *prep0 = 0.0; + *e_i = 0.0; + } + if (sdp->CreepModel() == 1000) + { + xi = new Matrix(LengthBS); + *xi = 0.0; + } + disp_j = 0.0; + tract_j = 0.0; + Localized = false; + scalar_aniso_comp = NULL; // WX: 11.2011 plasticity bedding + scalar_aniso_tens = NULL; + if (sdp->Plasticity_Bedding) + { + scalar_aniso_comp = new Matrix(NGPoints); + scalar_aniso_tens = new Matrix(NGPoints); + *scalar_aniso_comp = 0.; + *scalar_aniso_tens = 0.; + } } - disp_j = 0.0; - tract_j = 0.0; - Localized = false; - scalar_aniso_comp = NULL;//WX: 11.2011 plasticity bedding - scalar_aniso_tens = NULL; - if(sdp->Plasticity_Bedding) + // 01/2006 WW + void ElementValue_DM::Write_BIN(std::fstream & os, const bool last_step) { - scalar_aniso_comp = new Matrix(NGPoints); - scalar_aniso_tens = new Matrix(NGPoints); - *scalar_aniso_comp = 0.; - *scalar_aniso_tens = 0.; - } -} -// 01/2006 WW -void ElementValue_DM::Write_BIN(std::fstream& os, const bool last_step) -{ - if (last_step) + if (last_step) + Stress_i->Write_BIN(os); + else + Stress0->Write_BIN(os); Stress_i->Write_BIN(os); - else - Stress0->Write_BIN(os); - Stress_i->Write_BIN(os); - if(pStrain) - pStrain->Write_BIN(os); - if(y_surface) - y_surface->Write_BIN(os); - if(xi) - xi->Write_BIN(os); - if(MatP) - MatP->Write_BIN(os); - if(prep0) - prep0->Write_BIN(os); - if(e_i) - e_i->Write_BIN(os); - if(NodesOnPath) - NodesOnPath->Write_BIN(os); - if(orientation) - os.write((char*)(orientation), sizeof(*orientation)); - os.write((char*)(&disp_j), sizeof(disp_j)); - os.write((char*)(&tract_j), sizeof(tract_j)); - os.write((char*)(&Localized), sizeof(Localized)); -} -// 01/2006 WW -void ElementValue_DM::Read_BIN(std::fstream& is) -{ - Stress0->Read_BIN(is); - Stress_i->Read_BIN(is); - if(pStrain) - pStrain->Read_BIN(is); - if(y_surface) - y_surface->Read_BIN(is); - if(xi) - xi->Read_BIN(is); - if(MatP) - MatP->Read_BIN(is); - if(prep0) - prep0->Read_BIN(is); - if(e_i) - e_i->Read_BIN(is); - if(NodesOnPath) - NodesOnPath->Read_BIN(is); - if(orientation) - is.read((char*)(orientation), sizeof(*orientation)); - is.read((char*)(&disp_j), sizeof(disp_j)); - is.read((char*)(&tract_j), sizeof(tract_j)); - is.read((char*)(&Localized), sizeof(Localized)); -} - - -// 10/2011 WW -void ElementValue_DM::ReadElementStressASCI(std::fstream& is) -{ - size_t i,j; - size_t ns = Stress0->Rows(); - size_t nGS = Stress0->Cols(); + if (pStrain) + pStrain->Write_BIN(os); + if (y_surface) + y_surface->Write_BIN(os); + if (xi) + xi->Write_BIN(os); + if (MatP) + MatP->Write_BIN(os); + if (prep0) + prep0->Write_BIN(os); + if (e_i) + e_i->Write_BIN(os); + if (NodesOnPath) + NodesOnPath->Write_BIN(os); + if (orientation) + os.write((char*)(orientation), sizeof(*orientation)); + os.write((char*)(&disp_j), sizeof(disp_j)); + os.write((char*)(&tract_j), sizeof(tract_j)); + os.write((char*)(&Localized), sizeof(Localized)); + } + // 01/2006 WW + void ElementValue_DM::Read_BIN(std::fstream & is) + { + Stress0->Read_BIN(is); + Stress_i->Read_BIN(is); + if (pStrain) + pStrain->Read_BIN(is); + if (y_surface) + y_surface->Read_BIN(is); + if (xi) + xi->Read_BIN(is); + if (MatP) + MatP->Read_BIN(is); + if (prep0) + prep0->Read_BIN(is); + if (e_i) + e_i->Read_BIN(is); + if (NodesOnPath) + NodesOnPath->Read_BIN(is); + if (orientation) + is.read((char*)(orientation), sizeof(*orientation)); + is.read((char*)(&disp_j), sizeof(disp_j)); + is.read((char*)(&tract_j), sizeof(tract_j)); + is.read((char*)(&Localized), sizeof(Localized)); + } + + // 10/2011 WW + void ElementValue_DM::ReadElementStressASCI(std::fstream & is) + { + size_t i, j; + size_t ns = Stress0->Rows(); + size_t nGS = Stress0->Cols(); + + for (i = 0; i < ns; i++) + { + is >> (*Stress0)(i, 0); + for (j = 1; j < nGS; j++) + (*Stress0)(i, j) = (*Stress0)(i, 0); + } - for(i=0; i>(*Stress0)(i, 0); - for(j=1; jGetNodeValue(nodes[i], Idx_Strain[j]) * shapefctHQ[i]; + } + double val = 0; + for (int i = 0; i < 3; i++) + val += dstrain[i] * dstrain[i]; + for (int i = 3; i < ns; i++) + val += 0.5 * dstrain[i] * dstrain[i]; - Programming: - 01/2009 WW/UWG - **************************************************************************/ -double CFiniteElementVec:: CalcStrain_v() -{ - for (int j(0); jGetNodeValue(nodes[i],Idx_Strain[j]) * shapefctHQ[i]; - } - double val = 0; - for (int i = 0; i < 3; i++) - val += dstrain[i] * dstrain[i]; - for (int i = 3; i < ns; i++) - val += 0.5 * dstrain[i] * dstrain[i]; - - return sqrt(2.0 * val / 3.); -} -} // end namespace FiniteElement + return sqrt(2.0 * val / 3.); + } +} // end namespace FiniteElement diff --git a/FEM/fem_ele_vec.h b/FEM/fem_ele_vec.h old mode 100755 new mode 100644 index 61c99b480..9ebb7e232 --- a/FEM/fem_ele_vec.h +++ b/FEM/fem_ele_vec.h @@ -21,7 +21,8 @@ //#include "rf_mmp_new.h" namespace SolidProp -{class CSolidProperties; +{ +class CSolidProperties; } class CRFProcess; @@ -29,10 +30,12 @@ class CFluidProperties; class CMediumProperties; namespace process -{class CRFProcessDeformation; +{ +class CRFProcessDeformation; } namespace MeshLib -{class CElem; +{ +class CElem; } namespace FiniteElement { @@ -49,25 +52,21 @@ using MeshLib::CElem; class ElementValue_DM { public: - ElementValue_DM(CElem* ele, const int NGP, bool HM_Staggered); + ElementValue_DM(CElem* ele, const int NGP, bool HM_Staggered); ~ElementValue_DM(); void ResetStress(bool cpl_loop); /// \param last_step The last time step or the end of the program. void Write_BIN(std::fstream& os, const bool last_step = false); void Read_BIN(std::fstream& is); void ReadElementStressASCI(std::fstream& is); - double MeanStress(const int gp) - { - return (*Stress)(0, gp) - + (*Stress)(1, gp) + (*Stress)(2, gp); - } + double MeanStress(const int gp) { return (*Stress)(0, gp) + (*Stress)(1, gp) + (*Stress)(2, gp); } private: // Friend class friend class SolidProp::CSolidProperties; friend class process::CRFProcessDeformation; friend class ::CMediumProperties; friend class CFiniteElementVec; - Matrix* Stress0; // Initial stress + Matrix* Stress0; // Initial stress Matrix* Stress; Matrix* Stress_i; Matrix* Stress_j; @@ -75,10 +74,10 @@ class ElementValue_DM Matrix* y_surface; // Preconsolidation pressure Matrix* prep0; - Matrix* e_i; // Void ratio + Matrix* e_i; // Void ratio // Variables of single yield surface model - Matrix* xi; // Rotational hardening variables - Matrix* MatP; // Material parameters + Matrix* xi; // Rotational hardening variables + Matrix* MatP; // Material parameters // Discontinuity double disp_j; @@ -87,17 +86,16 @@ class ElementValue_DM Matrix* NodesOnPath; double* orientation; - Matrix *scalar_aniso_comp;//WX:11.2011 - Matrix *scalar_aniso_tens;//WX:11.2011 for aniso. plas. + Matrix* scalar_aniso_comp; // WX:11.2011 + Matrix* scalar_aniso_tens; // WX:11.2011 for aniso. plas. }; // Derived element for deformation caculation class CFiniteElementVec : public CElement { public: - CFiniteElementVec (process::CRFProcessDeformation* dm_pcs, - const int C_Sys_Flad, const int order = 2); - ~CFiniteElementVec (); + CFiniteElementVec(process::CRFProcessDeformation* dm_pcs, const int C_Sys_Flad, const int order = 2); + ~CFiniteElementVec(); // Set memory for local matrices void SetMemory(); @@ -114,30 +112,27 @@ class CFiniteElementVec : public CElement void SetMaterial(); // Get strain - double* GetStrain() const {return dstrain; } - + double* GetStrain() const { return dstrain; } //----------- Enhanced element ----------------------- // Geometry related bool LocalAssembly_CheckLocalization(CElem* MElement); - int IntersectionPoint(const int O_edge, - const double* NodeA, double* NodeB); + int IntersectionPoint(const int O_edge, const double* NodeA, double* NodeB); //----------- End of enhanced element ---------------- private: - process::CRFProcessDeformation* pcs; ::CRFProcess* h_pcs; ::CRFProcess* t_pcs; // excavation - bool excavation; //12.2009. WW + bool excavation; // 12.2009. WW // - int ns; // Number of stresses components + int ns; // Number of stresses components // Flow coupling int Flow_Type; // Primary value indeces // Column index in the node value table int idx_P, idx_P0, idx_P1, idx_P1_0, idx_P2; - int idx_T0,idx_T1; + int idx_T0, idx_T1; int idx_S0, idx_S, idx_Snw; int idx_pls; // Displacement column indeces in the node value table @@ -147,14 +142,14 @@ class CFiniteElementVec : public CElement // B matrix Matrix* B_matrix; Matrix* B_matrix_T; - std::vector vec_B_matrix; //NW - std::vector vec_B_matrix_T; //NW + std::vector vec_B_matrix; // NW + std::vector vec_B_matrix_T; // NW //------ Material ------- CSolidProperties* smat; - CFluidProperties* m_mfp; // Fluid coupling + CFluidProperties* m_mfp; // Fluid coupling // Medium property - CMediumProperties* m_mmp; // Fluid coupling + CMediumProperties* m_mmp; // Fluid coupling double CalDensity(); // Elastic constitutive matrix @@ -164,12 +159,12 @@ class CFiniteElementVec : public CElement // Local matricies and vectors Matrix* AuxMatrix; - Matrix* AuxMatrix2; //NW + Matrix* AuxMatrix2; // NW Matrix* Stiffness; Matrix* PressureC; - Matrix* PressureC_S; // Function of S - Matrix* PressureC_S_dp; // Function of S and ds_dp - Matrix* Mass; // For dynamic analysis + Matrix* PressureC_S; // Function of S + Matrix* PressureC_S_dp; // Function of S and ds_dp + Matrix* Mass; // For dynamic analysis Vec* RHS; // Global RHS. 08.2010. WW double* b_rhs; @@ -190,11 +185,11 @@ class CFiniteElementVec : public CElement double* Disp; // Temperatures of nodes - double* Temp, Tem; + double *Temp, Tem; double* T1; double S_Water; - //Element value + // Element value ElementValue_DM* eleV_DM; //------ Enhanced element ------ @@ -224,13 +219,12 @@ class CFiniteElementVec : public CElement void ComputeMatrix_RHS(const double fkt, const Matrix* p_D); // Temporarily used variables - double* Sxx, * Syy, * Szz, * Sxy, * Sxz, * Syz, * pstr; + double *Sxx, *Syy, *Szz, *Sxy, *Sxz, *Syz, *pstr; // 2. For enhanced strain approach - Matrix* BDG, * PDB, * DtD, * PeDe; // For enhanced strain element + Matrix *BDG, *PDB, *DtD, *PeDe; // For enhanced strain element /// Extropolation - bool RecordGuassStrain(const int gp, const int gp_r, - const int gp_s, int gp_t); + bool RecordGuassStrain(const int gp, const int gp_r, const int gp_s, int gp_t); // Effictive strain double CalcStrain_v(); void ExtropolateGuassStrain(); @@ -270,9 +264,8 @@ class CFiniteElementVec : public CElement // Auxillarary vector Vec* dAcceleration; void ComputeMass(); - }; -} // end namespace +} // end namespace extern std::vector ele_value_dm; #endif diff --git a/FEM/femlib.cpp b/FEM/femlib.cpp index e8c8d0979..93ea33fc2 100644 --- a/FEM/femlib.cpp +++ b/FEM/femlib.cpp @@ -50,68 +50,68 @@ **************************************************************************/ double MXPGaussPktTri(int anzgp, long xx, long coordr) { - double a[3] = {0.66666666666666,0.16666666666666,0.16666666666666}; - double b[3] = {0.16666666666666,0.66666666666666,0.16666666666666}; - double c[3] = {0.16666666666666,0.16666666666666,0.66666666666666}; + double a[3] = {0.66666666666666, 0.16666666666666, 0.16666666666666}; + double b[3] = {0.16666666666666, 0.66666666666666, 0.16666666666666}; + double c[3] = {0.16666666666666, 0.16666666666666, 0.66666666666666}; if (anzgp == 1) return 0.3333333333333333; else if (anzgp == 3) { switch (xx) { - case 0: - return a[coordr]; - case 1: - return b[coordr]; - case 2: - return c[coordr]; + case 0: + return a[coordr]; + case 1: + return b[coordr]; + case 2: + return c[coordr]; } } else if (anzgp == 4) { switch (xx) { - case 0: - switch (coordr) - { - case 0: - return 0.333333333333333; - case 1: - return 0.333333333333333; - } - break; - - case 1: - switch (coordr) - { - case 0: - return 0.600000000000000; - case 1: - return 0.200000000000000; - } - break; - - case 2: - switch (coordr) - { case 0: - return 0.200000000000000; - case 1: - return 0.600000000000000; - } - break; + switch (coordr) + { + case 0: + return 0.333333333333333; + case 1: + return 0.333333333333333; + } + break; - case 3: - switch (coordr) - { - case 0: - return 0.200000000000000; case 1: - return 0.200000000000000; - } - break; + switch (coordr) + { + case 0: + return 0.600000000000000; + case 1: + return 0.200000000000000; + } + break; + + case 2: + switch (coordr) + { + case 0: + return 0.200000000000000; + case 1: + return 0.600000000000000; + } + break; + + case 3: + switch (coordr) + { + case 0: + return 0.200000000000000; + case 1: + return 0.200000000000000; + } + break; } - } /*else if*/ /* switch grd */ + } /*else if*/ /* switch grd */ return 0.0; } @@ -136,7 +136,7 @@ double MXPGaussPktTri(int anzgp, long xx, long coordr) **************************************************************************/ double MXPGaussFktTri(int anzgp, long pkt) { - if(anzgp == 1) + if (anzgp == 1) return 0.5; else if (anzgp == 3) return 0.166666666666666; @@ -144,18 +144,18 @@ double MXPGaussFktTri(int anzgp, long pkt) { switch (pkt) { - case 0: - return -0.281250000000000; - break; - case 1: - return 0.260416666666667; - break; - case 2: - return 0.260416666666667; - break; - case 3: - return 0.260416666666667; - break; + case 0: + return -0.281250000000000; + break; + case 1: + return 0.260416666666667; + break; + case 2: + return 0.260416666666667; + break; + case 3: + return 0.260416666666667; + break; } } return 0.0; @@ -186,20 +186,20 @@ int Get_Nt_x_Nt(double* Ct) Ct1 = 2.0 / 3.0; Ct2 = 1.0 / 3.0; - Ct[0] = Ct[21] = Ct1; - Ct[1] = Ct[22] = Ct1; - Ct[2] = Ct[23] = Ct1; - Ct[6] = Ct[27] = Ct1; - Ct[7] = Ct[28] = Ct1; - Ct[8] = Ct[29] = Ct1; + Ct[0] = Ct[21] = Ct1; + Ct[1] = Ct[22] = Ct1; + Ct[2] = Ct[23] = Ct1; + Ct[6] = Ct[27] = Ct1; + Ct[7] = Ct[28] = Ct1; + Ct[8] = Ct[29] = Ct1; Ct[12] = Ct[33] = Ct1; Ct[13] = Ct[34] = Ct1; Ct[14] = Ct[35] = Ct1; - Ct[3] = Ct[18] = Ct2; - Ct[4] = Ct[19] = Ct2; - Ct[5] = Ct[20] = Ct2; - Ct[9] = Ct[24] = Ct2; + Ct[3] = Ct[18] = Ct2; + Ct[4] = Ct[19] = Ct2; + Ct[5] = Ct[20] = Ct2; + Ct[9] = Ct[24] = Ct2; Ct[10] = Ct[25] = Ct2; Ct[11] = Ct[26] = Ct2; Ct[15] = Ct[30] = Ct2; @@ -234,12 +234,12 @@ int Get_Nt_x_gradNt(double* Nt_x_gradNt) Ct1 = 1.0 / 2.0; Ct2 = -1.0 / 2.0; - Nt_x_gradNt[0] = Nt_x_gradNt[18] = Ct1; - Nt_x_gradNt[1] = Nt_x_gradNt[19] = Ct1; - Nt_x_gradNt[2] = Nt_x_gradNt[20] = Ct1; - Nt_x_gradNt[6] = Nt_x_gradNt[24] = Ct1; - Nt_x_gradNt[7] = Nt_x_gradNt[25] = Ct1; - Nt_x_gradNt[8] = Nt_x_gradNt[26] = Ct1; + Nt_x_gradNt[0] = Nt_x_gradNt[18] = Ct1; + Nt_x_gradNt[1] = Nt_x_gradNt[19] = Ct1; + Nt_x_gradNt[2] = Nt_x_gradNt[20] = Ct1; + Nt_x_gradNt[6] = Nt_x_gradNt[24] = Ct1; + Nt_x_gradNt[7] = Nt_x_gradNt[25] = Ct1; + Nt_x_gradNt[8] = Nt_x_gradNt[26] = Ct1; Nt_x_gradNt[12] = Nt_x_gradNt[30] = Ct1; Nt_x_gradNt[13] = Nt_x_gradNt[31] = Ct1; Nt_x_gradNt[14] = Nt_x_gradNt[32] = Ct1; @@ -282,25 +282,25 @@ int Get_gradNt_x_Nt(double* gradNt_x_Nt) Ct1 = 1.0 / 2.0; Ct2 = -1.0 / 2.0; - gradNt_x_Nt[0] = gradNt_x_Nt[3] = Ct1; - gradNt_x_Nt[1] = gradNt_x_Nt[4] = Ct1; - gradNt_x_Nt[2] = gradNt_x_Nt[5] = Ct1; - gradNt_x_Nt[6] = gradNt_x_Nt[9] = Ct1; - gradNt_x_Nt[7] = gradNt_x_Nt[10] = Ct1; - gradNt_x_Nt[8] = gradNt_x_Nt[11] = Ct1; + gradNt_x_Nt[0] = gradNt_x_Nt[3] = Ct1; + gradNt_x_Nt[1] = gradNt_x_Nt[4] = Ct1; + gradNt_x_Nt[2] = gradNt_x_Nt[5] = Ct1; + gradNt_x_Nt[6] = gradNt_x_Nt[9] = Ct1; + gradNt_x_Nt[7] = gradNt_x_Nt[10] = Ct1; + gradNt_x_Nt[8] = gradNt_x_Nt[11] = Ct1; gradNt_x_Nt[12] = gradNt_x_Nt[15] = Ct1; gradNt_x_Nt[13] = gradNt_x_Nt[16] = Ct1; gradNt_x_Nt[14] = gradNt_x_Nt[17] = Ct1; - gradNt_x_Nt[18] = gradNt_x_Nt[21] = Ct2; - gradNt_x_Nt[19] = gradNt_x_Nt[22] = Ct2; - gradNt_x_Nt[20] = gradNt_x_Nt[23] = Ct2; - gradNt_x_Nt[24] = gradNt_x_Nt[27] = Ct2; - gradNt_x_Nt[25] = gradNt_x_Nt[28] = Ct2; - gradNt_x_Nt[26] = gradNt_x_Nt[29] = Ct2; - gradNt_x_Nt[30] = gradNt_x_Nt[33] = Ct2; - gradNt_x_Nt[31] = gradNt_x_Nt[34] = Ct2; - gradNt_x_Nt[32] = gradNt_x_Nt[35] = Ct2; + gradNt_x_Nt[18] = gradNt_x_Nt[21] = Ct2; + gradNt_x_Nt[19] = gradNt_x_Nt[22] = Ct2; + gradNt_x_Nt[20] = gradNt_x_Nt[23] = Ct2; + gradNt_x_Nt[24] = gradNt_x_Nt[27] = Ct2; + gradNt_x_Nt[25] = gradNt_x_Nt[28] = Ct2; + gradNt_x_Nt[26] = gradNt_x_Nt[29] = Ct2; + gradNt_x_Nt[30] = gradNt_x_Nt[33] = Ct2; + gradNt_x_Nt[31] = gradNt_x_Nt[34] = Ct2; + gradNt_x_Nt[32] = gradNt_x_Nt[35] = Ct2; return 1; } @@ -327,23 +327,23 @@ int Get_gradNt_x_gradNt(double* GradNGradN) double Ct1; double Ct2; - Ct1 = 1.0 / 2.0; + Ct1 = 1.0 / 2.0; Ct2 = -1.0 / 2.0; - GradNGradN[0] = GradNGradN[21] = Ct1; - GradNGradN[1] = GradNGradN[22] = Ct1; - GradNGradN[2] = GradNGradN[23] = Ct1; - GradNGradN[6] = GradNGradN[27] = Ct1; - GradNGradN[7] = GradNGradN[28] = Ct1; - GradNGradN[8] = GradNGradN[29] = Ct1; + GradNGradN[0] = GradNGradN[21] = Ct1; + GradNGradN[1] = GradNGradN[22] = Ct1; + GradNGradN[2] = GradNGradN[23] = Ct1; + GradNGradN[6] = GradNGradN[27] = Ct1; + GradNGradN[7] = GradNGradN[28] = Ct1; + GradNGradN[8] = GradNGradN[29] = Ct1; GradNGradN[12] = GradNGradN[33] = Ct1; GradNGradN[13] = GradNGradN[34] = Ct1; GradNGradN[14] = GradNGradN[35] = Ct1; - GradNGradN[3] = GradNGradN[18] = Ct2; - GradNGradN[4] = GradNGradN[19] = Ct2; - GradNGradN[5] = GradNGradN[20] = Ct2; - GradNGradN[9] = GradNGradN[24] = Ct2; + GradNGradN[3] = GradNGradN[18] = Ct2; + GradNGradN[4] = GradNGradN[19] = Ct2; + GradNGradN[5] = GradNGradN[20] = Ct2; + GradNGradN[9] = GradNGradN[24] = Ct2; GradNGradN[10] = GradNGradN[25] = Ct2; GradNGradN[11] = GradNGradN[26] = Ct2; GradNGradN[15] = GradNGradN[30] = Ct2; @@ -425,23 +425,23 @@ int MGradOmegaPrism(double r, double s, double t, double* vf) } #endif /*grad r N */ - vf[0] = -(1.0 + t); - vf[1] = (1.0 + t); - vf[2] = 0.0; - vf[3] = -(1.0 - t); - vf[4] = (1.0 - t); - vf[5] = 0.0; + vf[0] = -(1.0 + t); + vf[1] = (1.0 + t); + vf[2] = 0.0; + vf[3] = -(1.0 - t); + vf[4] = (1.0 - t); + vf[5] = 0.0; /*grad s N */ - vf[6] = -(1.0 + t); - vf[7] = 0.0; - vf[8] = (1.0 + t); - vf[9] = -(1.0 - t); - vf[10] = 0.0; - vf[11] = (1.0 - t); + vf[6] = -(1.0 + t); + vf[7] = 0.0; + vf[8] = (1.0 + t); + vf[9] = -(1.0 - t); + vf[10] = 0.0; + vf[11] = (1.0 - t); /*grad t N */ - vf[12] = (1.0 - r - s); - vf[13] = r; - vf[14] = s; + vf[12] = (1.0 - r - s); + vf[13] = r; + vf[14] = s; vf[15] = -(1.0 - r - s); vf[16] = -r; vf[17] = -s; diff --git a/FEM/femlib.h b/FEM/femlib.h index a15956982..75e91c69c 100644 --- a/FEM/femlib.h +++ b/FEM/femlib.h @@ -21,41 +21,17 @@ extern void CalcElementsGeometry(void); extern void InitElementGeometry(long index); extern void CalcElementJacobiMatrix(long number, double* vec, double* dj); -extern void CalcXDElementJacobiMatrix(long index, - double r, - double s, - double t, - double* vec, - double* dj); +extern void CalcXDElementJacobiMatrix(long index, double r, double s, double t, double* vec, double* dj); extern void Calc1DElementJacobiMatrix(long number, double* vec, double* dj); extern void Calc2DElementJacobiMatrix(long number, double r, double s, double* erg, double* dj); extern void CalcTransformationsMatrix(long index, double* koma, double* trans); -extern void Calc2DElementCoordinatesTriangle(long index, double* x, double* y,double* dircos); -extern void Calc3DElementJacobiMatrix(long number, - double r, - double s, - double t, - double* erg, - double* dj); +extern void Calc2DElementCoordinatesTriangle(long index, double* x, double* y, double* dircos); +extern void Calc3DElementJacobiMatrix(long number, double r, double s, double t, double* erg, double* dj); extern void Calc2DElementJacobiMatrix_9N(long number, double r, double s, double* erg, double* dj); extern void CalcTransformationsMatrix_9N(long index, double* koma, double* trans); -extern void Calc2DElementJacobiMatrixXY_9N(long index, - double r, - double s, - double* invjac_t, - double* dj); -extern void Calc3DElementJacobiMatrix_20N(long number, - double r, - double s, - double t, - double* erg, - double* dj); -extern void CalcPrismElementJacobiMatrix(long number, - double r, - double s, - double t, - double* erg, - double* dj); +extern void Calc2DElementJacobiMatrixXY_9N(long index, double r, double s, double* invjac_t, double* dj); +extern void Calc3DElementJacobiMatrix_20N(long number, double r, double s, double t, double* erg, double* dj); +extern void CalcPrismElementJacobiMatrix(long number, double r, double s, double t, double* erg, double* dj); extern double MXPGaussPktTri(int anzgp, long grd, long pkt); extern int CalcGradXTri(long index, double* GradXTri); extern int CalcGradYTri(long index, double* GradYTri); @@ -65,11 +41,11 @@ extern int Get_gradNt_x_Nt(double* gradNt_x_Nt); extern int Get_gradNt_x_gradNt(double* GradNGradN); extern int Get_NTrinangle_x_NTrinangle(long index, double* Tri_x_Tri); extern int Get_IntNTri(long index, double* IntNTri); -extern double GetInvJac3Dz(long index); +extern double GetInvJac3Dz(long index); extern double* GetOmegaTri(long index, double x, double y); extern double MXPGaussFktTri(int anzgptri, long pkt); -extern int MGradOmegaPrism(double r, double s, double t,double* vf); -extern int MOmegaPrism(double* vf,double r, double s, double t); +extern int MGradOmegaPrism(double r, double s, double t, double* vf); +extern int MOmegaPrism(double* vf, double r, double s, double t); extern void CalcElementVolume(long number, double* volume); extern void Calc1DElementVolume(long number, double* volume); extern void Calc2DElementVolume(long number, double* volume); @@ -82,14 +58,11 @@ extern void Calc2DElement_ab2xyz_Coord(long index, double* erg, double a, double extern void Calc2DElement_ab2xyz_Vector(long index, double* vec_ab, double* vec_xyz); extern void Calc2DElement_xyz2ab_Vector(long index, double* vec_xyz, double* vec_ab); extern void Calc2DEdgeUnitNormalVec(long index, long side, double* n); -#ifndef NEW_EQS //WW. 06.11.2008 -extern void IncorporateMatrix(long element, - double* left_matrix, - double* right_vector, - double* rechts); +#ifndef NEW_EQS // WW. 06.11.2008 +extern void IncorporateMatrix(long element, double* left_matrix, double* right_vector, double* rechts); #endif extern void FEMCorrectFluxesOverIrregularNodes(int ndx); extern void FEMCorrectFluxesOverIrregularNodesOnVector(double* flux); -//CMCD 05.2004 +// CMCD 05.2004 extern void FEMCalcElementCharacterisiticLength(long index); #endif diff --git a/FEM/files0.cpp b/FEM/files0.cpp index de8ee6d8b..9cad05fa3 100644 --- a/FEM/files0.cpp +++ b/FEM/files0.cpp @@ -59,18 +59,18 @@ #include "rf_mfp_new.h" #include "rf_msp_new.h" //#include "rf_num_new.h" -#include "rf_fct.h" //OK -#include "rf_fluid_momentum.h" // PCH +#include "rf_fct.h" //OK +#include "rf_fluid_momentum.h" // PCH #include "rf_kinreact.h" -#include "rf_random_walk.h" // PCH +#include "rf_random_walk.h" // PCH #include "rf_react.h" #include "rf_react_int.h" -//CB2406 #ifdef OGS_FEM_CAP // CAP_REACT - // CB_merge_0513 - #include "rf_react_cap.h" +// CB2406 #ifdef OGS_FEM_CAP // CAP_REACT +// CB_merge_0513 +#include "rf_react_cap.h" #ifdef CHEMAPP -#include "eqlink.h" //MX +#include "eqlink.h" //MX #endif #include "fct_mpi.h" /* Tools */ @@ -83,16 +83,16 @@ //#include "msh_lib.h" //#include "gs_project.h" /* Dateinamen */ -char* crdat = NULL; /*MX*/ -char* file_name = NULL; /* dateiname */ +char* crdat = NULL; /*MX*/ +char* file_name = NULL; /* dateiname */ static char* msgdat = NULL; -#define RFD_FILE_EXTENSION ".rfd" //OK -#ifndef MFC //WW -void CURRead(std::string); //OK +#define RFD_FILE_EXTENSION ".rfd" // OK +#ifndef MFC // WW +void CURRead(std::string); // OK #endif -std::ios::pos_type CURReadCurve(std::ifstream*); //OK -void CURWrite(); //OK +std::ios::pos_type CURReadCurve(std::ifstream*); // OK +void CURWrite(); // OK #define KEYWORD '#' #define SUBKEYWORD '$' @@ -107,7 +107,7 @@ void CURWrite(); //OK using namespace std; -static bool isValidTextFileFormat(const std::string &basename, const std::string &fext) +static bool isValidTextFileFormat(const std::string& basename, const std::string& fext) { const std::string fname(basename + fext); if (!IsFileExisting(fname)) @@ -117,9 +117,12 @@ static bool isValidTextFileFormat(const std::string &basename, const std::string #else const bool is_win32 = false; #endif - if (is_win32 == HasCRInLineEnding(fname)) { + if (is_win32 == HasCRInLineEnding(fname)) + { return true; - } else { + } + else + { if (is_win32) std::cout << "*** ERROR: Detect UNIX file format " << fname.data() << std::endl; else @@ -128,7 +131,7 @@ static bool isValidTextFileFormat(const std::string &basename, const std::string } } -static bool checkFormatOfInputFiles(const std::string &basename) +static bool checkFormatOfInputFiles(const std::string& basename) { bool valid = true; valid &= isValidTextFileFormat(basename, ".gli"); @@ -171,41 +174,44 @@ static bool checkFormatOfInputFiles(const std::string &basename) last modified: OK 16.10.2002 */ /**************************************************************************/ -int ReadData ( char* dateiname, GEOLIB::GEOObjects& geo_obj, std::string& unique_name ) +int ReadData(char* dateiname, GEOLIB::GEOObjects& geo_obj, std::string& unique_name) { -#if defined(USE_MPI) //WW - if(myrank == 0) +#if defined(USE_MPI) // WW + if (myrank == 0) { #endif - std::cout << "\n"; - std::cout << "---------------------------------------------" << "\n"; - std::cout << "Data input:" << "\n"; -#if defined(USE_MPI) //WW -} + std::cout << "\n"; + std::cout << "---------------------------------------------" + << "\n"; + std::cout << "Data input:" + << "\n"; +#if defined(USE_MPI) // WW + } #endif /* Dateinamen generieren */ - //OK DATCreateFileNames(dateiname); + // OK DATCreateFileNames(dateiname); static int datlen; datlen = (int)strlen(dateiname) + 5; - crdat = (char*) Malloc(datlen); /*MX*/ - /*MX*/ - crdat = strcat(strcpy(crdat,dateiname),CHEM_REACTION_EXTENSION); - msgdat = (char*) Malloc(datlen); - msgdat = strcat(strcpy(msgdat,dateiname),RF_MESSAGE_EXTENSION); + crdat = (char*)Malloc(datlen); /*MX*/ + /*MX*/ + crdat = strcat(strcpy(crdat, dateiname), CHEM_REACTION_EXTENSION); + msgdat = (char*)Malloc(datlen); + msgdat = strcat(strcpy(msgdat, dateiname), RF_MESSAGE_EXTENSION); FILE* f = NULL; - if ((f = fopen(msgdat,"r")) == NULL) /* MSG-Datei existiert nicht */ + if ((f = fopen(msgdat, "r")) == NULL) /* MSG-Datei existiert nicht */ msgdat = (char*)Free(msgdat); else { - fclose (f); - if ((f = fopen(msgdat,"a")) == NULL) /* MSG-Schreibzugriff nicht moeglich */ + fclose(f); + if ((f = fopen(msgdat, "a")) == NULL) /* MSG-Schreibzugriff nicht moeglich */ msgdat = (char*)Free(msgdat); else - fclose (f); + fclose(f); } //---------------------------------------------------------------------- // Check line ending of input files - if (!checkFormatOfInputFiles(dateiname)) { + if (!checkFormatOfInputFiles(dateiname)) + { ScreenMessage("terminate this program"); exit(0); } @@ -213,17 +219,17 @@ int ReadData ( char* dateiname, GEOLIB::GEOObjects& geo_obj, std::string& unique // Read GEO data GEOLIB_Read_GeoLib(dateiname); - std::string geo_file_name (dateiname); + std::string geo_file_name(dateiname); geo_file_name += ".gli"; std::vector file_read_errors; - FileIO::readGLIFileV4 (geo_file_name, &geo_obj, unique_name, file_read_errors); + FileIO::readGLIFileV4(geo_file_name, &geo_obj, unique_name, file_read_errors); //---------------------------------------------------------------------- // Read object data PCSRead(dateiname); MFPRead(dateiname); // HS PCS immediately followed by the MCP read - CPRead(dateiname); //SB:GS4 + CPRead(dateiname); // SB:GS4 BCRead(dateiname, geo_obj, unique_name); STRead(dateiname, geo_obj, unique_name); ICRead(dateiname, geo_obj, unique_name); @@ -232,39 +238,39 @@ int ReadData ( char* dateiname, GEOLIB::GEOObjects& geo_obj, std::string& unique MSPRead(dateiname); MMPRead(dateiname); - REACINTRead(dateiname); // CB new reaction interface + REACINTRead(dateiname); // CB new reaction interface RCRead(dateiname); - REACT_CAP_Read(dateiname, geo_obj, unique_name); //DL/SB 11/2008 ChemASpp inteface new + REACT_CAP_Read(dateiname, geo_obj, unique_name); // DL/SB 11/2008 ChemASpp inteface new KRRead(dateiname, geo_obj, unique_name); KRWrite(dateiname); #ifdef CHEMAPP - CHMRead(dateiname); //MX for CHEMAPP + CHMRead(dateiname); // MX for CHEMAPP #endif NUMRead(dateiname); - FEMDeleteAll(); // KR moved from FEMRead() + FEMDeleteAll(); // KR moved from FEMRead() std::vector mesh_vec; FEMRead(dateiname, mesh_vec, &geo_obj, &unique_name); - if (!mesh_vec.empty()) //KR + if (!mesh_vec.empty()) // KR { fem_msh_vector.insert(fem_msh_vector.end(), mesh_vec.begin(), mesh_vec.end()); // re-inserted by KR - CompleteMesh(); //WW + CompleteMesh(); // WW } - //SBOK4209 MSHWrite(dateiname); + // SBOK4209 MSHWrite(dateiname); // PCTRead is bounded by msh - PCTRead(dateiname); // PCH - FMRead(dateiname); // PCH - FCTRead(dateiname); //OK - CURRead(dateiname); //OK - //CURWrite(); //OK + PCTRead(dateiname); // PCH + FMRead(dateiname); // PCH + FCTRead(dateiname); // OK + CURRead(dateiname); // OK +// CURWrite(); //OK #ifdef USE_PETSC FCT_MPI::FCTCommRead(dateiname); #endif //---------------------------------------------------------------------- // Read Excel/CVS data - //PNTPropertiesRead(dateiname); + // PNTPropertiesRead(dateiname); msgdat = (char*)Free(msgdat); @@ -303,31 +309,29 @@ bool RFDOpen(std::string file_name_base) 12/2001 MK Erste Version */ /**************************************************************************/ -FILE* OpenMsgFile () +FILE* OpenMsgFile() { FILE* f = NULL; if (msgdat) { - if ((f = fopen(msgdat,"a")) == NULL) + if ((f = fopen(msgdat, "a")) == NULL) { f = stdout; - fprintf( - f, + fprintf(f, "\n!!!!!!!! %s\n\n ", "Fehler: Schreibzugriff auf Message-Protokolldatei nicht moeglich!!"); } } else - f = stdout; /* Dateiname existiert nicht */ + f = stdout; /* Dateiname existiert nicht */ return f; } -void CloseMsgFile (FILE* f) +void CloseMsgFile(FILE* f) { if (f != stdout) if (fclose(f)) - DisplayErrorMsg( - "Fehler: Message-Protokolldatei konnte nicht geschlossen werden !!"); + DisplayErrorMsg("Fehler: Message-Protokolldatei konnte nicht geschlossen werden !!"); } /************************************************************************** @@ -344,18 +348,19 @@ void PRJRead(std::string base_file_name) // file handling string rfd_file_name; rfd_file_name = base_file_name + FCT_FILE_EXTENSION; - std::ifstream rfd_file (rfd_file_name.data(),std::ios::in); + std::ifstream rfd_file(rfd_file_name.data(), std::ios::in); if (!rfd_file.good()) return; - rfd_file.seekg(0L,std::ios::beg); + rfd_file.seekg(0L, std::ios::beg); //======================================================================== // keyword loop - std::cout << "RFDRead" << "\n"; + std::cout << "RFDRead" + << "\n"; while (!rfd_file.eof()) { - rfd_file.getline(line,MAX_ZEILE); + rfd_file.getline(line, MAX_ZEILE); project_title = line; - } // eof + } // eof } /************************************************************************** @@ -371,37 +376,38 @@ void CURRead(std::string base_file_name) //---------------------------------------------------------------------- StuetzStellen* stuetz = NULL; anz_kurven = 1; - stuetz = (StuetzStellen*) Malloc(sizeof(StuetzStellen)); + stuetz = (StuetzStellen*)Malloc(sizeof(StuetzStellen)); stuetz[0].punkt = 1.0; stuetz[0].wert = 1.0; - kurven = (Kurven*) Malloc(sizeof(Kurven)); + kurven = (Kurven*)Malloc(sizeof(Kurven)); kurven[anz_kurven - 1].anz_stuetzstellen = 1; kurven[anz_kurven - 1].stuetzstellen = stuetz; //---------------------------------------------------------------------- // file handling std::string cur_file_name; cur_file_name = base_file_name + RFD_FILE_EXTENSION; - std::ifstream cur_file (cur_file_name.data(),std::ios::in); + std::ifstream cur_file(cur_file_name.data(), std::ios::in); if (!cur_file.good()) return; - cur_file.seekg(0L,std::ios::beg); + cur_file.seekg(0L, std::ios::beg); //======================================================================== // keyword loop - std::cout << "CURRead" << "\n"; + std::cout << "CURRead" + << "\n"; while (!cur_file.eof()) { - cur_file.getline(line,MAX_ZEILE); + cur_file.getline(line, MAX_ZEILE); line_string = line; - if(line_string.find("#STOP") != std::string::npos) + if (line_string.find("#STOP") != std::string::npos) return; //---------------------------------------------------------------------- // keyword found - if(line_string.find("#CURVE") != std::string::npos) + if (line_string.find("#CURVE") != std::string::npos) { position = CURReadCurve(&cur_file); - cur_file.seekg(position,std::ios::beg); - } // keyword found - } // eof + cur_file.seekg(position, std::ios::beg); + } // keyword found + } // eof } /************************************************************************** @@ -416,45 +422,45 @@ std::ios::pos_type CURReadCurve(std::ifstream* cur_file) ios::pos_type position; std::stringstream line_stream; int anz = 0; - double d1,d2; + double d1, d2; StuetzStellen* stuetz = NULL; //---------------------------------------------------------------------- while (!new_keyword) { position = cur_file->tellg(); - //OK cur_file->getline(buffer,MAX_ZEILE); - //OK line_string = buffer; + // OK cur_file->getline(buffer,MAX_ZEILE); + // OK line_string = buffer; line_string = GetLineFromFile1(cur_file); - if(line_string.size() < 1) + if (line_string.size() < 1) continue; //.................................................................... // Test next keyword - if(line_string.find(hash) != string::npos) + if (line_string.find(hash) != string::npos) { new_keyword = true; continue; } //-------------------------------------------------------------------- - if(line_string.find(";") != string::npos) + if (line_string.find(";") != string::npos) continue; //-------------------------------------------------------------------- - //DATA - //OK cur_file->seekg(position,ios::beg); - //OK *cur_file >> d1 >> d2; + // DATA + // OK cur_file->seekg(position,ios::beg); + // OK *cur_file >> d1 >> d2; line_stream.str(line_string); line_stream >> d1 >> d2; anz++; - stuetz = (StuetzStellen*) Realloc(stuetz, (anz * sizeof(StuetzStellen))); + stuetz = (StuetzStellen*)Realloc(stuetz, (anz * sizeof(StuetzStellen))); stuetz[anz - 1].punkt = d1; stuetz[anz - 1].wert = d2; line_stream.clear(); //-------------------------------------------------------------------- } //---------------------------------------------------------------------- - if(anz >= 1l) + if (anz >= 1l) { anz_kurven++; - kurven = (Kurven*) Realloc(kurven, (anz_kurven * sizeof(Kurven))); + kurven = (Kurven*)Realloc(kurven, (anz_kurven * sizeof(Kurven))); kurven[anz_kurven - 1].anz_stuetzstellen = anz; kurven[anz_kurven - 1].stuetzstellen = stuetz; } @@ -470,23 +476,24 @@ void CURWrite() //======================================================================== // File handling std::string fct_file_name = "test.cur"; - std::fstream fct_file (fct_file_name.c_str(),ios::trunc | ios::out); - fct_file.setf(ios::scientific,ios::floatfield); + std::fstream fct_file(fct_file_name.c_str(), ios::trunc | ios::out); + fct_file.setf(ios::scientific, ios::floatfield); fct_file.precision(12); if (!fct_file.good()) return; - fct_file << "GeoSys-CUR: Functions ------------------------------------------------" << - "\n"; + fct_file << "GeoSys-CUR: Functions ------------------------------------------------" + << "\n"; //======================================================================== int j; StuetzStellen stuetz; - for(int i = 0; i < anz_kurven; i++) + for (int i = 0; i < anz_kurven; i++) { - fct_file << "#CURVES" << "\n"; - for(j = 0; j < kurven[i].anz_stuetzstellen; j++) + fct_file << "#CURVES" + << "\n"; + for (j = 0; j < kurven[i].anz_stuetzstellen; j++) { stuetz = kurven[i].stuetzstellen[j]; - fct_file << stuetz.punkt << " " << stuetz.wert << "\n"; + fct_file << stuetz.punkt << " " << stuetz.wert << "\n"; } } fct_file << "#STOP"; @@ -508,36 +515,41 @@ void CURWrite() **************************************************************************/ string GetLineFromFile1(ifstream* ein) { -// return readNonBlankLineFromInputStream(*ein); + // return readNonBlankLineFromInputStream(*ein); string line, zeile = ""; int fertig = 0, i = 0, j = 0; char zeile1[MAX_ZEILEN]; - line = ""; //WW + line = ""; // WW //---------------------------------------------------------------------- - while(fertig < 1) + while (fertig < 1) { - if(ein->getline(zeile1,MAX_ZEILEN)) //Zeile lesen + if (ein->getline(zeile1, MAX_ZEILEN)) // Zeile lesen { - line = zeile1; //character in string umwandeln - i = (int) line.find_first_not_of(" ",0); //Anf�ngliche Leerzeichen �berlesen, i=Position des ersten Nichtleerzeichens im string - j = (int) line.find(";",i); //Nach Kommentarzeichen ; suchen. j = Position des Kommentarzeichens, j=-1 wenn es keines gibt. - if(j != i) - fertig = 1; //Wenn das erste nicht-leerzeichen ein Kommentarzeichen ist, zeile �berlesen. Sonst ist das eine Datenzeile - if((i != -1)) - zeile = line.substr(i,j - i); //Ab erstem nicht-Leerzeichen bis Kommentarzeichen rauskopieren in neuen substring, falls Zeile nicht leer ist - i = (int) zeile.find_last_not_of(" "); // Suche nach dem letzten Zeichen, dass kein Leerzeichen ist - if(i >= 0) + line = zeile1; // character in string umwandeln + i = (int)line.find_first_not_of( + " ", 0); // Anf�ngliche Leerzeichen �berlesen, i=Position des ersten Nichtleerzeichens im string + j = (int)line.find( + ";", + i); // Nach Kommentarzeichen ; suchen. j = Position des Kommentarzeichens, j=-1 wenn es keines gibt. + if (j != i) + fertig = 1; // Wenn das erste nicht-leerzeichen ein Kommentarzeichen ist, zeile �berlesen. Sonst ist das + // eine Datenzeile + if ((i != -1)) + zeile = line.substr(i, j - i); // Ab erstem nicht-Leerzeichen bis Kommentarzeichen rauskopieren in neuen + // substring, falls Zeile nicht leer ist + i = (int)zeile.find_last_not_of(" "); // Suche nach dem letzten Zeichen, dass kein Leerzeichen ist + if (i >= 0) { // line.clear(); // = ""; - line = zeile.substr(0,i + 1); // Leerzeichen am Ende rausschneiden + line = zeile.substr(0, i + 1); // Leerzeichen am Ende rausschneiden // zeile.clear(); // = ""; zeile = line; } } - else //end of file found + else // end of file found fertig = 1; - } // end while(...) + } // end while(...) //---------------------------------------------------------------------- return zeile; } @@ -559,9 +571,9 @@ string GetLineFromFile1(ifstream* ein) 03/1994 MSR Erste Version */ /**************************************************************************/ -int FilePrintString ( FILE* f, const char* s ) +int FilePrintString(FILE* f, const char* s) { - if ((int)fprintf(f,"%s",s) != (int)strlen(s)) + if ((int)fprintf(f, "%s", s) != (int)strlen(s)) return 0; return 1; } @@ -583,9 +595,9 @@ int FilePrintString ( FILE* f, const char* s ) 05/1994 MSR Erste Version */ /**************************************************************************/ -int FilePrintInt ( FILE* f, int x ) +int FilePrintInt(FILE* f, int x) { - if (fprintf(f," %i ",x) < 0) + if (fprintf(f, " %i ", x) < 0) return 0; return 1; } @@ -607,9 +619,9 @@ int FilePrintInt ( FILE* f, int x ) 05/1994 MSR Erste Version */ /**************************************************************************/ -int FilePrintLong ( FILE* f, long x ) +int FilePrintLong(FILE* f, long x) { - if (fprintf(f," %ld ",x) < 0) + if (fprintf(f, " %ld ", x) < 0) return 0; return 1; } @@ -632,13 +644,13 @@ int FilePrintLong ( FILE* f, long x ) 12/1995 cb E-Format */ /**************************************************************************/ -int FilePrintDouble ( FILE* f, double x ) +int FilePrintDouble(FILE* f, double x) { #ifdef FORMAT_DOUBLE - if (fprintf(f," % #*.*g ",FPD_GESAMT,FPD_NACHKOMMA,x) < 0) + if (fprintf(f, " % #*.*g ", FPD_GESAMT, FPD_NACHKOMMA, x) < 0) return 0; #else - if (fprintf(f," % #g ",x) < 0) + if (fprintf(f, " % #g ", x) < 0) return 0; #endif return 1; @@ -665,22 +677,22 @@ int FilePrintDouble ( FILE* f, double x ) 03/1994 MSR Erste Version */ /**************************************************************************/ -int StrReadDouble ( double* x, char* s, FILE* f, int* pos ) +int StrReadDouble(double* x, char* s, FILE* f, int* pos) { *x = 0.0; - if (sscanf(s," %lf%n",x,pos) <= 0) + if (sscanf(s, " %lf%n", x, pos) <= 0) { - *pos = 0; /* nichts sinnvolles gelesen */ - fprintf(f,"\n %f *** Fehler: Kein Wert eingelesen (double) !!!\n",*x); + *pos = 0; /* nichts sinnvolles gelesen */ + fprintf(f, "\n %f *** Fehler: Kein Wert eingelesen (double) !!!\n", *x); return 0; } else { /* CT: Protokolformat geaendert */ if ((fabs(*x) < 100000.) && (fabs(*x) >= 0.1)) - fprintf(f," %f ",*x); + fprintf(f, " %f ", *x); else - fprintf(f," %e ",*x); + fprintf(f, " %e ", *x); return 1; } @@ -702,15 +714,15 @@ int StrReadDouble ( double* x, char* s, FILE* f, int* pos ) 03/1994 MSR Erste Version */ /**************************************************************************/ -char* ReadString ( void ) +char* ReadString(void) { - char* s = (char*) malloc(256); - //char *s = new char[256];//CC - scanf(" %s%*[^\n]%*c",s); + char* s = (char*)malloc(256); + // char *s = new char[256];//CC + scanf(" %s%*[^\n]%*c", s); // int a = (int)strlen(s); // delete[] s; - //s = new char[a+1];//CC - s = (char*) realloc(s,((int)strlen(s) + 1)); + // s = new char[a+1];//CC + s = (char*)realloc(s, ((int)strlen(s) + 1)); return s; } @@ -721,9 +733,9 @@ char* ReadString ( void ) 09/2004 OK Implementation last modification: **************************************************************************/ -bool SubKeyword(const std::string &line) +bool SubKeyword(const std::string& line) { - if(line.find(SUBKEYWORD) != std::string::npos) + if (line.find(SUBKEYWORD) != std::string::npos) return true; else return false; @@ -736,9 +748,9 @@ bool SubKeyword(const std::string &line) 09/2004 OK Implementation last modification: **************************************************************************/ -bool Keyword(const std::string &line) +bool Keyword(const std::string& line) { - if(line.find(KEYWORD) != std::string::npos) + if (line.find(KEYWORD) != std::string::npos) return true; else return false; @@ -760,7 +772,7 @@ bool Keyword(const std::string &line) 03/1994 MSR Erste Version */ /**************************************************************************/ -char* StrUp ( const char* s ) +char* StrUp(const char* s) { int i; int l = (int)strlen(s); @@ -792,19 +804,19 @@ char* StrUp ( const char* s ) 06/1999 OK aus StrReadString */ /**************************************************************************/ -int StringReadStr ( char** x, char* s, int* pos ) +int StringReadStr(char** x, char* s, int* pos) { *x = NULL; // *x = (char *) Malloc(256); - *x = new char[256]; //CC + *x = new char[256]; // CC *x[0] = '\0'; - if (sscanf(s," %s%n",*x,pos) <= 0) + if (sscanf(s, " %s%n", *x, pos) <= 0) { - int a = (int)strlen(*x); //CC - //delete[] *x;//CC - *x = new char[a + 1]; //CC + int a = (int)strlen(*x); // CC + // delete[] *x;//CC + *x = new char[a + 1]; // CC //*x = (char *) Realloc(*x,((int)strlen(*x)+1)); - *pos = 0; /* nichts sinnvolles gelesen */ + *pos = 0; /* nichts sinnvolles gelesen */ return 0; } else @@ -827,19 +839,19 @@ int StringReadStr ( char** x, char* s, int* pos ) 03/1994 MSR Erste Version */ /**************************************************************************/ -int LineFeed ( FILE* f ) +int LineFeed(FILE* f) { - if (fprintf(f,"\n") < 0) + if (fprintf(f, "\n") < 0) return 0; return 1; } -//int TFDouble ( double *x, FILE *f ) +// int TFDouble ( double *x, FILE *f ) //{ // return 1; //} -//int TFString ( char* x, FILE* f ) +// int TFString ( char* x, FILE* f ) //{ // return 1; //} @@ -859,7 +871,7 @@ void remove_white_space(std::string* buffer) pos = (int)buffer->find_first_of(" "); if (pos < 0) break; - buffer->erase(pos,1); + buffer->erase(pos, 1); } } @@ -885,22 +897,22 @@ void remove_white_space(std::string* buffer) 08/2000 CT Erste Version */ /**************************************************************************/ -int StrReadStr ( char* x, char* s, FILE* f, /*FctTestString func,*/ int* pos ) +int StrReadStr(char* x, char* s, FILE* f, /*FctTestString func,*/ int* pos) { -// int test; + // int test; x[0] = '\0'; - if (sscanf(s," %s%n",x,pos) <= 0) + if (sscanf(s, " %s%n", x, pos) <= 0) { - *pos = 0; /* nichts sinnvolles gelesen */ - fprintf(f,"\n %s *** Fehler: Kein Wert eingelesen (string) !!!\n",x); + *pos = 0; /* nichts sinnvolles gelesen */ + fprintf(f, "\n %s *** Fehler: Kein Wert eingelesen (string) !!!\n", x); return 0; } else { -// test = func(x,f); -// fprintf(f,"%s ",x); -// return test; - fprintf(f,"%s ",x); + // test = func(x,f); + // fprintf(f,"%s ",x); + // return test; + fprintf(f, "%s ", x); return 1; } } @@ -921,10 +933,10 @@ int StrReadStr ( char* x, char* s, FILE* f, /*FctTestString func,*/ int* pos ) 03/1994 MSR Erste Version */ /**************************************************************************/ -int StrTestDouble ( char* s ) +int StrTestDouble(char* s) { double i; - if (sscanf(s," %lf",&i) <= 0) + if (sscanf(s, " %lf", &i) <= 0) return 0; else return 1; @@ -947,15 +959,15 @@ int StrTestDouble ( char* s ) 03/1994 MSR Erste Version */ /**************************************************************************/ -int StrTestHash ( char* s, int* pos ) +int StrTestHash(char* s, int* pos) { int p; char h[256]; - if (sscanf(s," %s%n",h,&p) <= 0) + if (sscanf(s, " %s%n", h, &p) <= 0) return 0; else { - if (strcmp(h,"#") == 0) + if (strcmp(h, "#") == 0) { *pos = p; return 1; @@ -989,19 +1001,19 @@ int StrTestHash ( char* s, int* pos ) */ /**************************************************************************/ /*MX*/ -int StrOnlyReadStr ( char* x, char* s, FILE* /*f*/, /*FctTestString func,*/ int* pos ) +int StrOnlyReadStr(char* x, char* s, FILE* /*f*/, /*FctTestString func,*/ int* pos) { -// int test; + // int test; x[0] = '\0'; - if (sscanf(s," %s%n",x,pos) <= 0) + if (sscanf(s, " %s%n", x, pos) <= 0) { - *pos = 0; /* nichts sinnvolles gelesen */ + *pos = 0; /* nichts sinnvolles gelesen */ return 0; } else -// test = func(x,f); -// return test; + // test = func(x,f); + // return test; return 1; } @@ -1028,18 +1040,18 @@ int StrOnlyReadStr ( char* x, char* s, FILE* /*f*/, /*FctTestString func,*/ int* 08/2000 C.Thorenz Erste Version */ /**************************************************************************/ -int StrReadSubKeyword ( char* sub, char* s, int beginn, int* found, int* ende) +int StrReadSubKeyword(char* sub, char* s, int beginn, int* found, int* ende) { int i, xi = 0; *found = -1; *ende = (int)strlen(s); - for(i = beginn; i < (int)strlen(s); i++) + for (i = beginn; i < (int)strlen(s); i++) { - if(s[i] == '$') + if (s[i] == '$') { - if(*found < 1) + if (*found < 1) /* Anfang des Sub-Keywords merken */ *found = i; else @@ -1050,21 +1062,21 @@ int StrReadSubKeyword ( char* sub, char* s, int beginn, int* found, int* ende) } } - if(s[i] == '#') + if (s[i] == '#') { /* Ende des Sub-Keywords merken (neues Keyword folgt) */ *ende = i; break; } - if(*found >= 0) + if (*found >= 0) { sub[xi] = s[i]; xi++; } } - if(*found >= 0) + if (*found >= 0) sub[xi] = '\0'; return *found >= 0; @@ -1077,36 +1089,33 @@ int StrReadSubKeyword ( char* sub, char* s, int beginn, int* found, int* ende) 02/2004 OK Implementation last modification: **************************************************************************/ -std::string get_sub_string(const std::string &buffer, - const std::string &delimiter, - int pos1, - int* pos2) +std::string get_sub_string(const std::string& buffer, const std::string& delimiter, int pos1, int* pos2) { int pos = 0; std::string empty_string(""); - //string sub_string_this; - *pos2 = (int)buffer.find(delimiter,pos1); - if(*pos2 < 0) + // string sub_string_this; + *pos2 = (int)buffer.find(delimiter, pos1); + if (*pos2 < 0) return empty_string; - while(*pos2 <= pos1) + while (*pos2 <= pos1) { pos1++; - *pos2 = (int)buffer.find(delimiter,pos1); - if(*pos2 < 0) + *pos2 = (int)buffer.find(delimiter, pos1); + if (*pos2 < 0) { *pos2 = (int)buffer.size(); break; } - if(pos1 >= (int)buffer.size()) + if (pos1 >= (int)buffer.size()) break; } - string sub_string_this = buffer.substr(pos1,*pos2); + string sub_string_this = buffer.substr(pos1, *pos2); while (pos >= 0) { pos = (int)sub_string_this.find_first_of(" "); if (pos < 0) break; - sub_string_this.erase(pos,1); + sub_string_this.erase(pos, 1); } return sub_string_this; } @@ -1118,10 +1127,10 @@ std::string get_sub_string(const std::string &buffer, 02/2004 OK Implementation last modification: **************************************************************************/ -std::string get_sub_string2(const std::string &buffer,const std::string &delimiter,std::string* tmp) +std::string get_sub_string2(const std::string& buffer, const std::string& delimiter, std::string* tmp) { int pos2 = (int)buffer.find_first_of(delimiter); - std::string sub_string = buffer.substr(0,pos2); + std::string sub_string = buffer.substr(0, pos2); *tmp = buffer.substr(pos2 + delimiter.size()); return sub_string; } @@ -1141,14 +1150,17 @@ std::string GetUncommentedLine(std::string line) std::string zeile = ""; int i = 0, j = 0; //---------------------------------------------------------------------- - i = (int) line.find_first_not_of(" ",0); //Anf�ngliche Leerzeichen �berlesen, i=Position des ersten Nichtleerzeichens im string - j = (int) line.find(";",i); //Nach Kommentarzeichen ; suchen. j = Position des Kommentarzeichens, j=-1 wenn es keines gibt. - if((i != -1)) - zeile = line.substr(i,j - i); //Ab erstem nicht-Leerzeichen bis Kommentarzeichen rauskopieren in neuen substring, falls Zeile nicht leer ist - i = (int) zeile.find_last_not_of(" "); // Suche nach dem letzten Zeichen, dass kein Leerzeichen ist - if(i >= 0) + i = (int)line.find_first_not_of( + " ", 0); // Anf�ngliche Leerzeichen �berlesen, i=Position des ersten Nichtleerzeichens im string + j = (int)line.find( + ";", i); // Nach Kommentarzeichen ; suchen. j = Position des Kommentarzeichens, j=-1 wenn es keines gibt. + if ((i != -1)) + zeile = line.substr(i, j - i); // Ab erstem nicht-Leerzeichen bis Kommentarzeichen rauskopieren in neuen + // substring, falls Zeile nicht leer ist + i = (int)zeile.find_last_not_of(" "); // Suche nach dem letzten Zeichen, dass kein Leerzeichen ist + if (i >= 0) { - line = zeile.substr(0,i + 1); // Leerzeichen am Ende rausschneiden + line = zeile.substr(0, i + 1); // Leerzeichen am Ende rausschneiden zeile = line; } diff --git a/FEM/files0.h b/FEM/files0.h index 03fa339d1..89214a629 100644 --- a/FEM/files0.h +++ b/FEM/files0.h @@ -11,127 +11,123 @@ #define strings_INC #define FORMAT_DOUBLE -#define FPD_GESAMT 4 -#define FPD_NACHKOMMA 14 +#define FPD_GESAMT 4 +#define FPD_NACHKOMMA 14 /* Andere oeffentlich benutzte Module */ #include #include //#include -typedef int (*FctTestInt)( int*, FILE* ); -typedef int (*FctTestLong)( long*, FILE* ); -typedef int (*FctTestFloat)( float*, FILE* ); -typedef int (*FctTestDouble)( double*, FILE* ); -typedef int (*FctTestString)( char*, FILE* ); +typedef int (*FctTestInt)(int*, FILE*); +typedef int (*FctTestLong)(long*, FILE*); +typedef int (*FctTestFloat)(float*, FILE*); +typedef int (*FctTestDouble)(double*, FILE*); +typedef int (*FctTestString)(char*, FILE*); /* Funktionsprototypen zum Testen von eingelesenen Werten auf zulaessige Wertebereiche, mit Protokolldatei; Ergebnis: 0 bei Fehler, der zum Abbruch fuehren soll, sonst 1. Wenn korrigiert wurde: Protokoll schreiben und Ergebnis 1 */ -extern int LineFeed ( FILE* f ); +extern int LineFeed(FILE* f); /* Schreibt Zeilenvorschub in Textdatei */ -extern int FilePrintString ( FILE* f, const char* s ); +extern int FilePrintString(FILE* f, const char* s); /* Schreibt Zeichenkette in Textdatei */ -extern int FilePrintInt ( FILE* f, int x ); +extern int FilePrintInt(FILE* f, int x); /* Schreibt Integer-Wert in Textdatei */ -extern int FilePrintLong ( FILE* f, long x ); +extern int FilePrintLong(FILE* f, long x); /* Schreibt Long-Wert in Textdatei */ -extern int FilePrintDouble ( FILE* f, double x ); +extern int FilePrintDouble(FILE* f, double x); /* Schreibt Double-Wert in Textdatei */ -extern int FilePrintIntWB ( FILE* f, int x ); +extern int FilePrintIntWB(FILE* f, int x); /* Schreibt Integer-Wert ohne fuehrende Leerzeichen in Textdatei */ -extern int FilePrintLongWB ( FILE* f, long x ); +extern int FilePrintLongWB(FILE* f, long x); /* Schreibt Long-Wert ohne fuehrende Leerzeichen in Textdatei */ -extern int FilePrintDoubleWB ( FILE* f, double x ); +extern int FilePrintDoubleWB(FILE* f, double x); /* Schreibt Double-Wert ohne fuehrende Leerzeichen in Textdatei */ -extern int FileCommentDoubleMatrix ( FILE* f, double* d, int adjust, - long m, long n ); +extern int FileCommentDoubleMatrix(FILE* f, double* d, int adjust, long m, long n); /* Schreibt Double-m x n-Matrix als Kommentar mit Einrueckung adjust in Textdatei */ -extern int StrReadSubSubKeyword ( char* x, char* s, int beginn, int* found, int* ende ); +extern int StrReadSubSubKeyword(char* x, char* s, int beginn, int* found, int* ende); /* Liest Sub-Sub-Keyword aus String */ -extern int StrReadSubKeyword ( char* x, char* s, int beginn, int* found, int* ende ); +extern int StrReadSubKeyword(char* x, char* s, int beginn, int* found, int* ende); /* Liest Sub-Keyword aus String */ -extern int StrReadInt ( int* x, char* s, FILE* f, - FctTestInt func, int* pos ); +extern int StrReadInt(int* x, char* s, FILE* f, FctTestInt func, int* pos); /* Liest Integer-Wert aus String und schreibt Protokoll in Datei */ -extern int StrReadLong ( long* x, char* s, FILE* f, - FctTestLong func, int* pos ); +extern int StrReadLong(long* x, char* s, FILE* f, FctTestLong func, int* pos); /* Liest Long-Wert aus String und schreibt Protokoll in Datei */ -extern int StrReadFloat ( float* x, char* s, FILE* f, - FctTestFloat func, int* pos ); +extern int StrReadFloat(float* x, char* s, FILE* f, FctTestFloat func, int* pos); /* Liest Float-Wert aus String und schreibt Protokoll in Datei */ -extern int StrReadDouble ( double* x, char* s, FILE* f, int* pos ); +extern int StrReadDouble(double* x, char* s, FILE* f, int* pos); /* Liest Double-Wert aus String und schreibt Protokoll in Datei */ -extern int StrReadString ( char** x, char* s, FILE* f, /*FctTestString func,*/ int* pos ); +extern int StrReadString(char** x, char* s, FILE* f, /*FctTestString func,*/ int* pos); /* Liest Zeichenkette aus String und schreibt Protokoll in Datei */ -extern int StrReadStr ( char* x, char* s, FILE* f, /*FctTestString func,*/ int* pos ); +extern int StrReadStr(char* x, char* s, FILE* f, /*FctTestString func,*/ int* pos); /* Liest Zeichenkette aus String und schreibt Protokoll in Datei */ -extern int StrTestInt ( char* s ); +extern int StrTestInt(char* s); /* Testet, ob in s noch ein Integer kommt; 0:=nein */ -extern int StrTestLong ( char* s ); +extern int StrTestLong(char* s); /* Testet, ob in s noch ein LongInt kommt; 0:=nein */ -extern int StrTestFloat ( char* s ); +extern int StrTestFloat(char* s); /* Testet, ob in s noch ein Float kommt; 0:=nein */ -extern int StrTestDouble ( char* s ); +extern int StrTestDouble(char* s); /* Testet, ob in s noch ein Double kommt; 0:=nein */ -extern int StrTestString ( char* s ); +extern int StrTestString(char* s); /* Testet, ob in s noch ein String kommt; 0:=nein */ -extern int StrTestHash ( char* s, int* pos); +extern int StrTestHash(char* s, int* pos); /* Testet, ob in s ein # folgt; 0:=nein; 1:=ja, pos liefert Position nach dem # */ -extern int StrTestDollar ( char* s, int* pos); +extern int StrTestDollar(char* s, int* pos); /* Testet, ob in s ein $ folgt; 0:=nein; 1:=ja, pos liefert Position nach dem $ */ -extern int StrTestInv ( char* s, int* pos); +extern int StrTestInv(char* s, int* pos); /* Testet, ob in s ein ? folgt; 0:=nein; 1:=ja, pos liefert Position nach dem ? */ -extern int StrReadLongNoComment (long* x,char* s,FILE* f,FctTestLong func,int* pos ); -extern int StrReadStrNoComment ( char* x, char* s, FILE* f, FctTestString func, int* pos ); +extern int StrReadLongNoComment(long* x, char* s, FILE* f, FctTestLong func, int* pos); +extern int StrReadStrNoComment(char* x, char* s, FILE* f, FctTestString func, int* pos); /* zusaetzliche Lesefunktionen fuer RF-SHELL */ -extern int StringReadFloat ( float* x, char* s, int* pos ); -extern int StringReadDouble ( double* x, char* s, int* pos ); -extern int StringReadInt ( int* x, char* s, int* pos ); -extern int StringReadLong ( long* x, char* s, int* pos ); -extern int StringReadStr ( char** x, char* s, int* pos ); +extern int StringReadFloat(float* x, char* s, int* pos); +extern int StringReadDouble(double* x, char* s, int* pos); +extern int StringReadInt(int* x, char* s, int* pos); +extern int StringReadLong(long* x, char* s, int* pos); +extern int StringReadStr(char** x, char* s, int* pos); /* allgemeine Dummy-Testfunktionen */ -//extern int TFInt ( int *x, FILE *f ); -//extern int TFLong ( long *x, FILE *f ); -//extern int TFFloat ( float *x, FILE *f ); -//extern int TFDouble ( double *x, FILE *f ); -//extern int TFDoubleNew (char *s, FILE *f ); -extern int TFString ( char* x, FILE* f ); +// extern int TFInt ( int *x, FILE *f ); +// extern int TFLong ( long *x, FILE *f ); +// extern int TFFloat ( float *x, FILE *f ); +// extern int TFDouble ( double *x, FILE *f ); +// extern int TFDoubleNew (char *s, FILE *f ); +extern int TFString(char* x, FILE* f); -extern char* ReadString ( void ); +extern char* ReadString(void); /* Liest Zeichenkette von Standardeingabe */ -extern char* StrUp ( const char* s ); +extern char* StrUp(const char* s); /* wandelt s in Grossbuchstaben um */ -extern char* StrDown ( char* s ); +extern char* StrDown(char* s); /* wandelt s in Kleinbuchstaben um */ -extern void GetRFINodesData (); +extern void GetRFINodesData(); /* Weitere externe Objekte */ #define MAX_NAME 80 /*MX*/ -extern int StrOnlyReadStr ( char* x, char* s, FILE* f, /*FctTestString func,*/ int* pos ); +extern int StrOnlyReadStr(char* x, char* s, FILE* f, /*FctTestString func,*/ int* pos); -extern std::string get_sub_string(const std::string&,const std::string&,int,int*); +extern std::string get_sub_string(const std::string&, const std::string&, int, int*); extern void remove_white_space(std::string*); -//extern std::string get_sub_string2(std::string buffer,std::string delimiter,std::string cut_string); -extern std::string get_sub_string2(const std::string&,const std::string&,std::string*); +// extern std::string get_sub_string2(std::string buffer,std::string delimiter,std::string cut_string); +extern std::string get_sub_string2(const std::string&, const std::string&, std::string*); extern bool SubKeyword(const std::string&); extern bool Keyword(const std::string&); -//CC move here +// CC move here extern std::string GetLineFromFile1(std::ifstream*); -//SB +// SB extern std::string GetUncommentedLine(std::string); -//extern std::string NumberToString(long); -extern void is_line_empty(std::string*); //OK +// extern std::string NumberToString(long); +extern void is_line_empty(std::string*); // OK #endif diff --git a/FEM/mathlib.cpp b/FEM/mathlib.cpp index f239ba463..ec444a452 100644 --- a/FEM/mathlib.cpp +++ b/FEM/mathlib.cpp @@ -162,14 +162,14 @@ #include //#include -#include "femlib.h" //CMCD 03 2004 +#include "femlib.h" //CMCD 03 2004 #include "makros.h" #include "memory.h" #include "display.h" #include "mathlib.h" -//WW---------------------- +// WW---------------------- #include "par_ddc.h" -//WW---------------------- +// WW---------------------- double pai = 4.0 * atan(1.0); VoidFuncDXCDX ShapeFunction; VoidFuncDXCDX ShapeFunctionHQ; @@ -203,7 +203,7 @@ double MBtrgVec(double* vec, long n) return sqrt(zwo); } -#ifdef obsolete //05.03.2010 WW +#ifdef obsolete // 05.03.2010 WW /*************************************************************************** ROCKFLOW - Funktion: MGleichDouble Aufgabe: @@ -229,10 +229,10 @@ int MGleichDouble(double zahl1, double zahl2, double tol) retval = 0; return retval; } -#endif //#ifdef obsolete //05.03.2010 WW +#endif //#ifdef obsolete //05.03.2010 WW //////////////////////////////////////////////////////////// -#ifdef obsolete //05.03.2010 WW +#ifdef obsolete // 05.03.2010 WW /*************************************************************************** ROCKFLOW - Funktion: MOmega1D Aufgabe: @@ -380,8 +380,8 @@ int MOmega3D(double* vf, double r, double s, double t) //#ifdef obsolete //WW. 06.11.2008 int MOmega2DTriangle(double* vf, double xx, double yy, long number) { - int i,nn = 3,ok = 0; - double x[3],y[3]; + int i, nn = 3, ok = 0; + double x[3], y[3]; double area; long* element_nodes; @@ -423,17 +423,17 @@ int MOmega2DTriangle(double* vf, double xx, double yy, long number) Programing: 08/2003 OK Implementation **************************************************************************/ -int MOmega3DTetrahedron(double* vf,double r,double s,double t,long number) +int MOmega3DTetrahedron(double* vf, double r, double s, double t, long number) { int ok = 0; long* element_nodes; int i; - double a1,a2,a3,a4; - double b1,b2,b3,b4; - double c1,c2,c3,c4; - double d1,d2,d3,d4; - double x[4],y[4],z[4]; - double N1,N2,N3,N4; + double a1, a2, a3, a4; + double b1, b2, b3, b4; + double c1, c2, c3, c4; + double d1, d2, d3, d4; + double x[4], y[4], z[4]; + double N1, N2, N3, N4; double volume; double mat3x3[9]; @@ -610,7 +610,7 @@ int MOmega3DTetrahedron(double* vf,double r,double s,double t,long number) mat3x3[8] = 1.0; d4 = 1.0 * M3Determinante(mat3x3); - //Element Shape Functions + // Element Shape Functions N1 = ((a1 * 1) + (b1 * r) + (c1 * s) + (d1 * t)) / (6 * volume); N2 = ((a2 * 1) + (b2 * r) + (c2 * s) + (d2 * t)) / (6 * volume); N3 = ((a3 * 1) + (b3 * r) + (c3 * s) + (d3 * t)) / (6 * volume); @@ -728,46 +728,22 @@ int MPhi3D_SUPG(double* vf, double r, double s, double t, double* alpha) return ok; } #endif - vf[0] = (1.0 + r) * (1.0 + s) * (1.0 + t) \ - + alpha[0] * - (1.0 + - s) * - (1.0 + t) + alpha[1] * (1.0 + r) * (1.0 + t) + alpha[2] * (1.0 + r) * (1.0 + s); - vf[1] = (1.0 - r) * (1.0 + s) * (1.0 + t) \ - - alpha[0] * - (1.0 + - s) * - (1.0 + t) + alpha[1] * (1.0 - r) * (1.0 + t) + alpha[2] * (1.0 - r) * (1.0 + s); - vf[2] = (1.0 - r) * (1.0 - s) * (1.0 + t) \ - - alpha[0] * - (1.0 - - s) * - (1.0 + t) - alpha[1] * (1.0 - r) * (1.0 + t) + alpha[2] * (1.0 - r) * (1.0 - s); - vf[3] = (1.0 + r) * (1.0 - s) * (1.0 + t) \ - + alpha[0] * - (1.0 - - s) * - (1.0 + t) - alpha[1] * (1.0 + r) * (1.0 + t) + alpha[2] * (1.0 + r) * (1.0 - s); - vf[4] = (1.0 + r) * (1.0 + s) * (1.0 - t) \ - + alpha[0] * - (1.0 + - s) * - (1.0 - t) + alpha[1] * (1.0 + r) * (1.0 - t) - alpha[2] * (1.0 + r) * (1.0 + s); - vf[5] = (1.0 - r) * (1.0 + s) * (1.0 - t) \ - - alpha[0] * - (1.0 + - s) * - (1.0 - t) + alpha[1] * (1.0 - r) * (1.0 - t) - alpha[2] * (1.0 - r) * (1.0 + s); - vf[6] = (1.0 - r) * (1.0 - s) * (1.0 - t) \ - - alpha[0] * - (1.0 - - s) * - (1.0 - t) - alpha[1] * (1.0 - r) * (1.0 - t) - alpha[2] * (1.0 - r) * (1.0 - s); - vf[7] = (1.0 + r) * (1.0 - s) * (1.0 - t) \ - + alpha[0] * - (1.0 - - s) * - (1.0 - t) - alpha[1] * (1.0 + r) * (1.0 - t) - alpha[2] * (1.0 + r) * (1.0 - s); + vf[0] = (1.0 + r) * (1.0 + s) * (1.0 + t) + alpha[0] * (1.0 + s) * (1.0 + t) + alpha[1] * (1.0 + r) * (1.0 + t) + + alpha[2] * (1.0 + r) * (1.0 + s); + vf[1] = (1.0 - r) * (1.0 + s) * (1.0 + t) - alpha[0] * (1.0 + s) * (1.0 + t) + alpha[1] * (1.0 - r) * (1.0 + t) + + alpha[2] * (1.0 - r) * (1.0 + s); + vf[2] = (1.0 - r) * (1.0 - s) * (1.0 + t) - alpha[0] * (1.0 - s) * (1.0 + t) - alpha[1] * (1.0 - r) * (1.0 + t) + + alpha[2] * (1.0 - r) * (1.0 - s); + vf[3] = (1.0 + r) * (1.0 - s) * (1.0 + t) + alpha[0] * (1.0 - s) * (1.0 + t) - alpha[1] * (1.0 + r) * (1.0 + t) + + alpha[2] * (1.0 + r) * (1.0 - s); + vf[4] = (1.0 + r) * (1.0 + s) * (1.0 - t) + alpha[0] * (1.0 + s) * (1.0 - t) + alpha[1] * (1.0 + r) * (1.0 - t) + - alpha[2] * (1.0 + r) * (1.0 + s); + vf[5] = (1.0 - r) * (1.0 + s) * (1.0 - t) - alpha[0] * (1.0 + s) * (1.0 - t) + alpha[1] * (1.0 - r) * (1.0 - t) + - alpha[2] * (1.0 - r) * (1.0 + s); + vf[6] = (1.0 - r) * (1.0 - s) * (1.0 - t) - alpha[0] * (1.0 - s) * (1.0 - t) - alpha[1] * (1.0 - r) * (1.0 - t) + - alpha[2] * (1.0 - r) * (1.0 - s); + vf[7] = (1.0 + r) * (1.0 - s) * (1.0 - t) + alpha[0] * (1.0 - s) * (1.0 - t) - alpha[1] * (1.0 + r) * (1.0 - t) + - alpha[2] * (1.0 + r) * (1.0 - s); for (i = 0; i < 8; i++) vf[i] *= 0.125; return ok = 1; @@ -946,21 +922,21 @@ void MGetCoor(int typ, long j, double* r, double* s, double* t) { switch (typ) { - case 0: - *r = (double) (1l - j - j); - *s = *t = 0.0; - break; - case 1: - *r = 1.0 - 2.0 * (double) (((j + 1l) % 4) / 2l); - *s = 1.0 - 2.0 * (double) (j / 2l); - *t = 0.0; - break; - case 2: - *r = 1.0 - 2.0 * (double) (((j + 1l) % 4) / 2l); - *s = 1.0 - 2.0 * (double) ((j % 4) / 2l); - *t = 1.0 - 2.0 * (double) (j / 4l); - break; - } /* switch typ */ + case 0: + *r = (double)(1l - j - j); + *s = *t = 0.0; + break; + case 1: + *r = 1.0 - 2.0 * (double)(((j + 1l) % 4) / 2l); + *s = 1.0 - 2.0 * (double)(j / 2l); + *t = 0.0; + break; + case 2: + *r = 1.0 - 2.0 * (double)(((j + 1l) % 4) / 2l); + *s = 1.0 - 2.0 * (double)((j % 4) / 2l); + *t = 1.0 - 2.0 * (double)(j / 4l); + break; + } /* switch typ */ } /************************************************************************** @@ -983,7 +959,7 @@ double MAngleVectors(double* v1, double* v2) double angle; Pproduct = v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2]; - angle = (acos ( Pproduct / (MBtrgVec(v1, 3) * MBtrgVec(v2, 3)))) * 180 / PI; + angle = (acos(Pproduct / (MBtrgVec(v1, 3) * MBtrgVec(v2, 3)))) * 180 / PI; return angle; } @@ -1027,7 +1003,7 @@ void MNormiere(double* vec, long n) double M2Determinante(double* matrix) { return matrix[0] * matrix[3] - matrix[1] * matrix[2]; -} /* extern double M2Determinante */ +} /* extern double M2Determinante */ /*************************************************************************** ROCKFLOW - Funktion: Mxg2Determinante @@ -1058,12 +1034,12 @@ double Mxg2Determinante(double* matrix, long m, long n) { DisplayErrorMsg("Determinate einer nicht-quadratischen Matrix ?"); return 0.0; - } /* if */ + } /* if */ if (m < 3) { DisplayErrorMsg("Determinate zu klein m>2 !!"); return 0.0; - } /* if */ + } /* if */ #endif dussel = 1.0; @@ -1079,9 +1055,9 @@ double Mxg2Determinante(double* matrix, long m, long n) dussel *= matrix[i]; if (sprung == i) i -= m; - } /* for */ + } /* for */ depp += dussel; - } /* for */ + } /* for */ dussel = 1.0; for (i = n - 1; i < m * n - m + 1; i += m - 1) dussel *= matrix[i]; @@ -1095,11 +1071,11 @@ double Mxg2Determinante(double* matrix, long m, long n) dussel *= matrix[i]; if (sprung == i) i += m; - } /* for */ + } /* for */ depp -= dussel; - } /* for */ + } /* for */ return depp; -} /* extern double Mxg2Determinante */ +} /* extern double Mxg2Determinante */ /************************************************************************** ROCKFLOW - Funktion: MTranspoVec @@ -1125,7 +1101,7 @@ void MTranspoVec(double* vec, long g) vec[i] = vec[g - 1 - i]; vec[g - 1 - i] = zwiebel; } -} /* MTranspoVec */ +} /* MTranspoVec */ /************************************************************************** ROCKFLOW - Funktion: MTranspoMat @@ -1150,7 +1126,7 @@ void MTranspoMat(double* mat1, long m, long n, double* mat2) for (i = 0; i < n; i++) for (k = 0; k < m; k++) mat2[i * m + k] = mat1[k * n + i]; -} /* MTranspoMat */ +} /* MTranspoMat */ /************************************************************************** ROCKFLOW - Funktion: M2InvertiereUndTransponiere @@ -1175,17 +1151,17 @@ void M2InvertiereUndTransponiere(double* m) register double eddet, zecke; register int i; eddet = m[0] * m[3] - m[1] * m[2]; - if (fabs(eddet) > MKleinsteZahl) + if (fabs(eddet) > MKleinsteZahl) eddet = 1.0 / eddet; zecke = m[0]; m[0] = m[3]; m[3] = zecke; zecke = -m[1]; - m[1] = -m[2]; /* hier wird auch transponiert */ + m[1] = -m[2]; /* hier wird auch transponiert */ m[2] = zecke; for (i = 0; i < 4; i++) m[i] *= eddet; -} /* M2InvertiereUndTransponiere */ +} /* M2InvertiereUndTransponiere */ /************************************************************************** ROCKFLOW - Funktion: M2Invertiere @@ -1213,7 +1189,7 @@ void M2Invertiere(double* m) register double eddet, zecke; register int i; eddet = m[0] * m[3] - m[1] * m[2]; - if (fabs(eddet) > MKleinsteZahl) + if (fabs(eddet) > MKleinsteZahl) eddet = 1.0 / eddet; zecke = m[0]; m[0] = m[3]; @@ -1222,7 +1198,7 @@ void M2Invertiere(double* m) m[2] = -m[2]; for (i = 0; i < 4; i++) m[i] *= eddet; -} /* M2Invertiere */ +} /* M2Invertiere */ /************************************************************************** ROCKFLOW - Funktion: M3Invertiere @@ -1243,10 +1219,8 @@ void M3Invertiere(double* m) double z[9]; register double d; register int i; - d = m[0] * (m[4] * m[8] - m[7] * m[5]) \ - + m[3] * (m[7] * m[2] - m[1] * m[8]) \ - + m[6] * (m[1] * m[5] - m[4] * m[2]); - if (fabs(d) > MKleinsteZahl) + d = m[0] * (m[4] * m[8] - m[7] * m[5]) + m[3] * (m[7] * m[2] - m[1] * m[8]) + m[6] * (m[1] * m[5] - m[4] * m[2]); + if (fabs(d) > MKleinsteZahl) d = 1.0 / d; z[0] = m[4] * m[8] - m[7] * m[5]; z[3] = m[6] * m[5] - m[3] * m[8]; @@ -1259,7 +1233,7 @@ void M3Invertiere(double* m) z[8] = m[0] * m[4] - m[3] * m[1]; for (i = 0; i < 9; i++) m[i] = d * z[i]; -} /* M3Invertiere */ +} /* M3Invertiere */ /************************************************************************** ROCKFLOW - Funktion: MInvertiere @@ -1294,7 +1268,7 @@ void MInvertiere(double* mat, long m, long n) abort(); } #endif - m = n; /* ah */ + m = n; /* ah */ for (k = 0; k < n; k++) { for (j = 0; j < n; j++) @@ -1310,7 +1284,7 @@ void MInvertiere(double* mat, long m, long n) if (i != k) mat[n * i + k] *= mat[n * k + k]; } -} /* MInvertiere */ +} /* MInvertiere */ /************************************************************************** ROCKFLOW - Funktion: MAddVektoren @@ -1340,7 +1314,7 @@ int MAddVektoren(double* v1, double* v2, double* vout, long g) for (i = 0; i < g; i++) vout[i] = v1[i] + v2[i]; return 1; -} /* MAddVektoren */ +} /* MAddVektoren */ /************************************************************************** ROCKFLOW - Funktion: MAddMatrizen @@ -1397,7 +1371,7 @@ int MMultVecSkalar(double* vec, double skal, long g) for (i = 0; i < g; i++) vec[i] *= skal; return 1; -} /* extern int MMultVecSkalar */ +} /* extern int MMultVecSkalar */ /************************************************************************** ROCKFLOW - Funktion: MMultMatSkalar @@ -1635,7 +1609,7 @@ int MKTF3Dr2D(double* vec1, double* vec2, double winkel, double* vec) **************************************************************************/ void MKTFMat3Dr2D(double* vec1, double* vec2, double winkel, double* mat) -{ /* if(winkel!=0.0) */ /* diese Verzweigung spart viel Zeit */ +{ /* if(winkel!=0.0) */ /* diese Verzweigung spart viel Zeit */ { static double f; static double zwick[6]; @@ -1657,13 +1631,13 @@ void MKTFMat3Dr2D(double* vec1, double* vec2, double winkel, double* mat) MMultMatMat(zwick, 3, 2, zwock, 2, 2, zwack, 3, 2); for (i = 0; i < 6; i++) mat[i] = zwack[i]; - } /* if */ + } /* if */ -/* else - {MNulleMat(mat,3,2); - mat[0]=1.0;mat[3]=1.0; - } */ -/* else */ + /* else + {MNulleMat(mat,3,2); + mat[0]=1.0;mat[3]=1.0; + } */ + /* else */ } /*########################################################################## @@ -1694,8 +1668,7 @@ int MBistDuDiagMat(double* matrix, long m, long n) for (i = 0; i < m; i++) for (j = 0; j < n; j++) /*printf(" %ld %ld \n",i,j); */ - if ((fabs(matrix[i + j * n]) > MKleinsteZahl) && - ((i - j < -1) || (i - j > 1))) + if ((fabs(matrix[i + j * n]) > MKleinsteZahl) && ((i - j < -1) || (i - j > 1))) return 0; diag = 3; @@ -1707,7 +1680,7 @@ int MBistDuDiagMat(double* matrix, long m, long n) if (!knall) diag = 1; return diag; -} /* of MBistDuDiagMat */ +} /* of MBistDuDiagMat */ /*########################################################################## Bearbeitungfunktionen fuer Vektoren @@ -1731,8 +1704,8 @@ void MLoeschVec(double* vec) if (vec == NULL) DisplayErrorMsg("Fehler in MLoeschVec"); #endif - vec = (double*) Free(vec); -} /* MLoeschVec */ + vec = (double*)Free(vec); +} /* MLoeschVec */ /*########################################################################## Bearbeitungfunktionen fuer Matrizen @@ -1755,13 +1728,13 @@ void MLoeschVec(double* vec) double* MMachMat(long m, long n) { double* zwerg; - zwerg = (double*) Malloc(sizeof(double) * m * n); + zwerg = (double*)Malloc(sizeof(double) * m * n); #ifdef ERROR_CONTROL if (zwerg == NULL) DisplayErrorMsg("zuwenig Speicher in MMachMat"); #endif return zwerg; -} /* MMachMat */ +} /* MMachMat */ /************************************************************************** ROCKFLOW - Funktion: MNullMat @@ -1783,7 +1756,7 @@ void MNullMat(double* zwerg, long m, long n) #endif for (i = 0; i < m * n; i++) zwerg[i] = 0.0; -} /* MNullMat */ +} /* MNullMat */ /************************************************************************** ROCKFLOW - Funktion: MLoeschMat @@ -1803,8 +1776,8 @@ void MLoeschMat(double* mat) if (mat == NULL) DisplayErrorMsg("Fehler in MLoeschMat"); #endif - mat = (double*) Free(mat); -} /* MLoeschMat */ + mat = (double*)Free(mat); +} /* MLoeschMat */ /************************************************************************** ROCKFLOW - Funktion: MKopierMat @@ -1826,7 +1799,7 @@ void MKopierMat(double* matq, double* matz, long m, long n) register long i; for (i = 0; i < m * n; i++) matz[i] = matq[i]; -} /* MKopierMat */ +} /* MKopierMat */ /*########################################################################## Ausgabefunktionen @@ -1895,7 +1868,7 @@ void MZeigMat(double* mat, long m, long n, char* text) printf(" %e ", mat[i + k * n]); puts(" |"); } -} /* MZeigMat */ +} /* MZeigMat */ /************************************************************************** ROCKFLOW - Funktion: MVekNormMax @@ -1970,15 +1943,15 @@ double MCalcProjectionOfPointOnLine(double* pt, double* l1, double* l2, double* double vec1[3], vec2[3], l, projektionslaenge, abstand; /* Vektor Linienpunkt zu Punkt */ - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) vec1[i] = pt[i] - l1[i]; /* Vektor Linienpunkt zu Linienpunkt */ - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) vec2[i] = l2[i] - l1[i]; /* Normieren */ - l = MBtrgVec(vec2,3); + l = MBtrgVec(vec2, 3); #ifdef ERROR_CONTROL if (l < MKleinsteZahl) { @@ -1986,13 +1959,13 @@ double MCalcProjectionOfPointOnLine(double* pt, double* l1, double* l2, double* exit(1); } #endif - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) vec2[i] /= (l + MKleinsteZahl); projektionslaenge = MSkalarprodukt(vec1, vec2, 3); /* Punkt bestimmen */ - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) proj[i] = l1[i] + projektionslaenge * vec2[i]; abstand = MCalcDistancePointToPoint(proj, pt); @@ -2052,12 +2025,12 @@ double MCalcProjectionOfPointOnLine(double* pt, double* l1, double* l2, double* 05/2000 RK Erste Version **************************************************************************/ -double CalcTriangleArea (long n1, long n2, long n3) +double CalcTriangleArea(long n1, long n2, long n3) { double area = 0.0; n1 = n1; n2 = n2; - n3 = n3; //OK411 + n3 = n3; // OK411 /*OK411 double vec1[3], vec2[3], vec3[3]; @@ -2123,7 +2096,7 @@ int MOmega2D_9N(double* vf, double r, double s) return ok; } #endif - vf[8] = (1.0 - r * r) * ( 1.0 - s * s); + vf[8] = (1.0 - r * r) * (1.0 - s * s); vf[7] = 0.5 * (1.0 - s * s) * (1.0 + r) - 0.5 * vf[8]; vf[6] = 0.5 * (1.0 - r * r) * (1.0 - s) - 0.5 * vf[8]; vf[5] = 0.5 * (1.0 - s * s) * (1.0 - r) - 0.5 * vf[8]; @@ -2154,7 +2127,7 @@ int MPhi2D_9N(double* vf, double r, double s) { int ok = 0; - vf[8] = (1.0 - r * r) * ( 1.0 - s * s); + vf[8] = (1.0 - r * r) * (1.0 - s * s); vf[7] = 0.5 * (1.0 - s * s) * (1.0 + r) - 0.5 * vf[8]; vf[6] = 0.5 * (1.0 - r * r) * (1.0 - s) - 0.5 * vf[8]; vf[5] = 0.5 * (1.0 - s * s) * (1.0 - r) - 0.5 * vf[8]; @@ -2268,26 +2241,26 @@ int MPhi3D_20N(double* vf, double r, double s, double t) } #endif - g[0] = 0.125 * (1.0 + r) * (1.0 + s) * (1.0 + t); - g[1] = 0.125 * (1.0 - r) * (1.0 + s) * (1.0 + t); - g[2] = 0.125 * (1.0 - r) * (1.0 - s) * (1.0 + t); - g[3] = 0.125 * (1.0 + r) * (1.0 - s) * (1.0 + t); - g[4] = 0.125 * (1.0 + r) * (1.0 + s) * (1.0 - t); - g[5] = 0.125 * (1.0 - r) * (1.0 + s) * (1.0 - t); - g[6] = 0.125 * (1.0 - r) * (1.0 - s) * (1.0 - t); - g[7] = 0.125 * (1.0 + r) * (1.0 - s) * (1.0 - t); - g[8] = 0.25 * (1.0 - r * r) * (1.0 + s) * (1.0 + t); - g[9] = 0.25 * (1.0 - r) * (1.0 - s * s) * (1.0 + t); - g[10] = 0.25 * (1.0 - r * r) * (1.0 - s) * (1.0 + t); - g[11] = 0.25 * (1.0 + r) * (1.0 - s * s) * (1.0 + t); - g[12] = 0.25 * (1.0 - r * r) * (1.0 + s) * (1.0 - t); - g[13] = 0.25 * (1.0 - r) * (1.0 - s * s) * (1.0 - t); - g[14] = 0.25 * (1.0 - r * r) * (1.0 - s) * (1.0 - t); - g[15] = 0.25 * (1.0 + r) * (1.0 - s * s) * (1.0 - t); - g[16] = 0.25 * (1.0 + r) * (1.0 + s) * (1.0 - t * t); - g[17] = 0.25 * (1.0 - r) * (1.0 + s) * (1.0 - t * t); - g[18] = 0.25 * (1.0 - r) * (1.0 - s) * (1.0 - t * t); - g[19] = 0.25 * (1.0 + r) * (1.0 - s) * (1.0 - t * t); + g[0] = 0.125 * (1.0 + r) * (1.0 + s) * (1.0 + t); + g[1] = 0.125 * (1.0 - r) * (1.0 + s) * (1.0 + t); + g[2] = 0.125 * (1.0 - r) * (1.0 - s) * (1.0 + t); + g[3] = 0.125 * (1.0 + r) * (1.0 - s) * (1.0 + t); + g[4] = 0.125 * (1.0 + r) * (1.0 + s) * (1.0 - t); + g[5] = 0.125 * (1.0 - r) * (1.0 + s) * (1.0 - t); + g[6] = 0.125 * (1.0 - r) * (1.0 - s) * (1.0 - t); + g[7] = 0.125 * (1.0 + r) * (1.0 - s) * (1.0 - t); + g[8] = 0.25 * (1.0 - r * r) * (1.0 + s) * (1.0 + t); + g[9] = 0.25 * (1.0 - r) * (1.0 - s * s) * (1.0 + t); + g[10] = 0.25 * (1.0 - r * r) * (1.0 - s) * (1.0 + t); + g[11] = 0.25 * (1.0 + r) * (1.0 - s * s) * (1.0 + t); + g[12] = 0.25 * (1.0 - r * r) * (1.0 + s) * (1.0 - t); + g[13] = 0.25 * (1.0 - r) * (1.0 - s * s) * (1.0 - t); + g[14] = 0.25 * (1.0 - r * r) * (1.0 - s) * (1.0 - t); + g[15] = 0.25 * (1.0 + r) * (1.0 - s * s) * (1.0 - t); + g[16] = 0.25 * (1.0 + r) * (1.0 + s) * (1.0 - t * t); + g[17] = 0.25 * (1.0 - r) * (1.0 + s) * (1.0 - t * t); + g[18] = 0.25 * (1.0 - r) * (1.0 - s) * (1.0 - t * t); + g[19] = 0.25 * (1.0 + r) * (1.0 - s) * (1.0 - t * t); vf[0] = g[0] - (g[8] + g[11] + g[16]) * 0.5; vf[1] = g[1] - (g[8] + g[9] + g[17]) * 0.5; @@ -2298,8 +2271,8 @@ int MPhi3D_20N(double* vf, double r, double s, double t) vf[6] = g[6] - (g[13] + g[14] + g[18]) * 0.5; vf[7] = g[7] - (g[14] + g[15] + g[19]) * 0.5; - vf[8] = g[8]; - vf[9] = g[9]; + vf[8] = g[8]; + vf[9] = g[9]; vf[10] = g[10]; vf[11] = g[11]; vf[12] = g[12]; @@ -2331,9 +2304,9 @@ int MPhi3D_20N(double* vf, double r, double s, double t) int MGradOmega3D_20N(double* vf, double r, double s, double t) { int ok = 0; - double g_r[20]; /* r-Ableitung */ - double g_s[20]; /* s-Ableitung */ - double g_t[20]; /* t-Ableitung */ + double g_r[20]; /* r-Ableitung */ + double g_s[20]; /* s-Ableitung */ + double g_t[20]; /* t-Ableitung */ #ifdef ERROR_CONTROL if (vf == NULL) @@ -2343,68 +2316,68 @@ int MGradOmega3D_20N(double* vf, double r, double s, double t) } #endif - g_r[0] = +0.125 * (1.0 + s) * (1.0 + t); - g_r[1] = -0.125 * (1.0 + s) * (1.0 + t); - g_r[2] = -0.125 * (1.0 - s) * (1.0 + t); - g_r[3] = +0.125 * (1.0 - s) * (1.0 + t); - g_r[4] = +0.125 * (1.0 + s) * (1.0 - t); - g_r[5] = -0.125 * (1.0 + s) * (1.0 - t); - g_r[6] = -0.125 * (1.0 - s) * (1.0 - t); - g_r[7] = +0.125 * (1.0 - s) * (1.0 - t); - g_r[8] = -0.5 * r * (1.0 + s) * (1.0 + t); - g_r[9] = -0.25 * (1.0 - s * s) * (1.0 + t); - g_r[10] = -0.5 * r * (1.0 - s) * (1.0 + t); - g_r[11] = +0.25 * (1.0 - s * s) * (1.0 + t); - g_r[12] = -0.5 * r * (1.0 + s) * (1.0 - t); - g_r[13] = -0.25 * (1.0 - s * s) * (1.0 - t); - g_r[14] = -0.5 * r * (1.0 - s) * (1.0 - t); - g_r[15] = +0.25 * (1.0 - s * s) * (1.0 - t); - g_r[16] = +0.25 * (1.0 + s) * (1.0 - t * t); - g_r[17] = -0.25 * (1.0 + s) * (1.0 - t * t); - g_r[18] = -0.25 * (1.0 - s) * (1.0 - t * t); - g_r[19] = +0.25 * (1.0 - s) * (1.0 - t * t); - - g_s[0] = +0.125 * (1.0 + r) * (1.0 + t); - g_s[1] = +0.125 * (1.0 - r) * (1.0 + t); - g_s[2] = -0.125 * (1.0 - r) * (1.0 + t); - g_s[3] = -0.125 * (1.0 + r) * (1.0 + t); - g_s[4] = +0.125 * (1.0 + r) * (1.0 - t); - g_s[5] = +0.125 * (1.0 - r) * (1.0 - t); - g_s[6] = -0.125 * (1.0 - r) * (1.0 - t); - g_s[7] = -0.125 * (1.0 + r) * (1.0 - t); - g_s[8] = +0.25 * (1.0 - r * r) * (1.0 + t); - g_s[9] = -0.5 * (1.0 - r) * s * (1.0 + t); - g_s[10] = -0.25 * (1.0 - r * r) * (1.0 + t); - g_s[11] = -0.5 * (1.0 + r) * s * (1.0 + t); - g_s[12] = +0.25 * (1.0 - r * r) * (1.0 - t); - g_s[13] = -0.5 * (1.0 - r) * s * (1.0 - t); - g_s[14] = -0.25 * (1.0 - r * r) * (1.0 - t); - g_s[15] = -0.5 * (1.0 + r) * s * (1.0 - t); - g_s[16] = +0.25 * (1.0 + r) * (1.0 - t * t); - g_s[17] = +0.25 * (1.0 - r) * (1.0 - t * t); - g_s[18] = -0.25 * (1.0 - r) * (1.0 - t * t); - g_s[19] = -0.25 * (1.0 + r) * (1.0 - t * t); - - g_t[0] = +0.125 * (1.0 + r) * (1.0 + s); - g_t[1] = +0.125 * (1.0 - r) * (1.0 + s); - g_t[2] = +0.125 * (1.0 - r) * (1.0 - s); - g_t[3] = +0.125 * (1.0 + r) * (1.0 - s); - g_t[4] = -0.125 * (1.0 + r) * (1.0 + s); - g_t[5] = -0.125 * (1.0 - r) * (1.0 + s); - g_t[6] = -0.125 * (1.0 - r) * (1.0 - s); - g_t[7] = -0.125 * (1.0 + r) * (1.0 - s); - g_t[8] = +0.25 * (1.0 - r * r) * (1.0 + s); - g_t[9] = +0.25 * (1.0 - r) * (1.0 - s * s); - g_t[10] = +0.25 * (1.0 - r * r) * (1.0 - s); - g_t[11] = +0.25 * (1.0 + r) * (1.0 - s * s); - g_t[12] = -0.25 * (1.0 - r * r) * (1.0 + s); - g_t[13] = -0.25 * (1.0 - r) * (1.0 - s * s); - g_t[14] = -0.25 * (1.0 - r * r) * (1.0 - s); - g_t[15] = -0.25 * (1.0 + r) * (1.0 - s * s); - g_t[16] = -0.5 * (1.0 + r) * (1.0 + s) * t; - g_t[17] = -0.5 * (1.0 - r) * (1.0 + s) * t; - g_t[18] = -0.5 * (1.0 - r) * (1.0 - s) * t; - g_t[19] = -0.5 * (1.0 + r) * (1.0 - s) * t; + g_r[0] = +0.125 * (1.0 + s) * (1.0 + t); + g_r[1] = -0.125 * (1.0 + s) * (1.0 + t); + g_r[2] = -0.125 * (1.0 - s) * (1.0 + t); + g_r[3] = +0.125 * (1.0 - s) * (1.0 + t); + g_r[4] = +0.125 * (1.0 + s) * (1.0 - t); + g_r[5] = -0.125 * (1.0 + s) * (1.0 - t); + g_r[6] = -0.125 * (1.0 - s) * (1.0 - t); + g_r[7] = +0.125 * (1.0 - s) * (1.0 - t); + g_r[8] = -0.5 * r * (1.0 + s) * (1.0 + t); + g_r[9] = -0.25 * (1.0 - s * s) * (1.0 + t); + g_r[10] = -0.5 * r * (1.0 - s) * (1.0 + t); + g_r[11] = +0.25 * (1.0 - s * s) * (1.0 + t); + g_r[12] = -0.5 * r * (1.0 + s) * (1.0 - t); + g_r[13] = -0.25 * (1.0 - s * s) * (1.0 - t); + g_r[14] = -0.5 * r * (1.0 - s) * (1.0 - t); + g_r[15] = +0.25 * (1.0 - s * s) * (1.0 - t); + g_r[16] = +0.25 * (1.0 + s) * (1.0 - t * t); + g_r[17] = -0.25 * (1.0 + s) * (1.0 - t * t); + g_r[18] = -0.25 * (1.0 - s) * (1.0 - t * t); + g_r[19] = +0.25 * (1.0 - s) * (1.0 - t * t); + + g_s[0] = +0.125 * (1.0 + r) * (1.0 + t); + g_s[1] = +0.125 * (1.0 - r) * (1.0 + t); + g_s[2] = -0.125 * (1.0 - r) * (1.0 + t); + g_s[3] = -0.125 * (1.0 + r) * (1.0 + t); + g_s[4] = +0.125 * (1.0 + r) * (1.0 - t); + g_s[5] = +0.125 * (1.0 - r) * (1.0 - t); + g_s[6] = -0.125 * (1.0 - r) * (1.0 - t); + g_s[7] = -0.125 * (1.0 + r) * (1.0 - t); + g_s[8] = +0.25 * (1.0 - r * r) * (1.0 + t); + g_s[9] = -0.5 * (1.0 - r) * s * (1.0 + t); + g_s[10] = -0.25 * (1.0 - r * r) * (1.0 + t); + g_s[11] = -0.5 * (1.0 + r) * s * (1.0 + t); + g_s[12] = +0.25 * (1.0 - r * r) * (1.0 - t); + g_s[13] = -0.5 * (1.0 - r) * s * (1.0 - t); + g_s[14] = -0.25 * (1.0 - r * r) * (1.0 - t); + g_s[15] = -0.5 * (1.0 + r) * s * (1.0 - t); + g_s[16] = +0.25 * (1.0 + r) * (1.0 - t * t); + g_s[17] = +0.25 * (1.0 - r) * (1.0 - t * t); + g_s[18] = -0.25 * (1.0 - r) * (1.0 - t * t); + g_s[19] = -0.25 * (1.0 + r) * (1.0 - t * t); + + g_t[0] = +0.125 * (1.0 + r) * (1.0 + s); + g_t[1] = +0.125 * (1.0 - r) * (1.0 + s); + g_t[2] = +0.125 * (1.0 - r) * (1.0 - s); + g_t[3] = +0.125 * (1.0 + r) * (1.0 - s); + g_t[4] = -0.125 * (1.0 + r) * (1.0 + s); + g_t[5] = -0.125 * (1.0 - r) * (1.0 + s); + g_t[6] = -0.125 * (1.0 - r) * (1.0 - s); + g_t[7] = -0.125 * (1.0 + r) * (1.0 - s); + g_t[8] = +0.25 * (1.0 - r * r) * (1.0 + s); + g_t[9] = +0.25 * (1.0 - r) * (1.0 - s * s); + g_t[10] = +0.25 * (1.0 - r * r) * (1.0 - s); + g_t[11] = +0.25 * (1.0 + r) * (1.0 - s * s); + g_t[12] = -0.25 * (1.0 - r * r) * (1.0 + s); + g_t[13] = -0.25 * (1.0 - r) * (1.0 - s * s); + g_t[14] = -0.25 * (1.0 - r * r) * (1.0 - s); + g_t[15] = -0.25 * (1.0 + r) * (1.0 - s * s); + g_t[16] = -0.5 * (1.0 + r) * (1.0 + s) * t; + g_t[17] = -0.5 * (1.0 - r) * (1.0 + s) * t; + g_t[18] = -0.5 * (1.0 - r) * (1.0 - s) * t; + g_t[19] = -0.5 * (1.0 + r) * (1.0 - s) * t; vf[0] = g_r[0] - (g_r[8] + g_r[11] + g_r[16]) * 0.5; vf[1] = g_r[1] - (g_r[8] + g_r[9] + g_r[17]) * 0.5; @@ -2415,8 +2388,8 @@ int MGradOmega3D_20N(double* vf, double r, double s, double t) vf[6] = g_r[6] - (g_r[13] + g_r[14] + g_r[18]) * 0.5; vf[7] = g_r[7] - (g_r[14] + g_r[15] + g_r[19]) * 0.5; - vf[8] = g_r[8]; - vf[9] = g_r[9]; + vf[8] = g_r[8]; + vf[9] = g_r[9]; vf[10] = g_r[10]; vf[11] = g_r[11]; vf[12] = g_r[12]; @@ -2437,8 +2410,8 @@ int MGradOmega3D_20N(double* vf, double r, double s, double t) vf[26] = g_s[6] - (g_s[13] + g_s[14] + g_s[18]) * 0.5; vf[27] = g_s[7] - (g_s[14] + g_s[15] + g_s[19]) * 0.5; - vf[28] = g_s[8]; - vf[29] = g_s[9]; + vf[28] = g_s[8]; + vf[29] = g_s[9]; vf[30] = g_s[10]; vf[31] = g_s[11]; vf[32] = g_s[12]; @@ -2459,8 +2432,8 @@ int MGradOmega3D_20N(double* vf, double r, double s, double t) vf[46] = g_t[6] - (g_t[13] + g_t[14] + g_t[18]) * 0.5; vf[47] = g_t[7] - (g_t[14] + g_t[15] + g_t[19]) * 0.5; - vf[48] = g_t[8]; - vf[49] = g_t[9]; + vf[48] = g_t[8]; + vf[49] = g_t[9]; vf[50] = g_t[10]; vf[51] = g_t[11]; vf[52] = g_t[12]; @@ -2510,14 +2483,14 @@ int MGradPhi3D_20N(double* vf, double r, double s, double t) 06/2001 MK Erste Version **************************************************************************/ -int MCompare_for_MQSort_LongDouble( const void* Arg1, const void* Arg2 ) +int MCompare_for_MQSort_LongDouble(const void* Arg1, const void* Arg2) { typedef struct { long index; double value; } MType_LongDouble; - MType_LongDouble* arg1, * arg2; + MType_LongDouble *arg1, *arg2; arg1 = (MType_LongDouble*)Arg1; arg2 = (MType_LongDouble*)Arg2; if ((arg1->value) > (arg2->value)) @@ -2545,7 +2518,7 @@ int MCompare_for_MQSort_LongDouble( const void* Arg1, const void* Arg2 ) **************************************************************************/ void MQSort_LongDouble(void* DataSets, const int NumberOfDataSets, const int SizeOfDataSet) { - qsort( DataSets, NumberOfDataSets, SizeOfDataSet, MCompare_for_MQSort_LongDouble ); + qsort(DataSets, NumberOfDataSets, SizeOfDataSet, MCompare_for_MQSort_LongDouble); } /*########################################################################## @@ -2569,24 +2542,23 @@ void MQSort_LongDouble(void* DataSets, const int NumberOfDataSets, const int Siz **************************************************************************/ -double* JWDMMultMatSkalar(double* matrix, - double skal, long m, long n) -{ /* flip ist Zwischenspeicher fuer die Matrix */ - double* flip, * flippy; +double* JWDMMultMatSkalar(double* matrix, double skal, long m, long n) +{ /* flip ist Zwischenspeicher fuer die Matrix */ + double *flip, *flippy; long i; - flip = (double*) Malloc(sizeof(double) * n * m); + flip = (double*)Malloc(sizeof(double) * n * m); flippy = flip; if (flip == NULL) { DisplayErrorMsg(" kein Speicher mehr !!! "); return 0; - } /* if */ + } /* if */ for (i = 0; i < m * n; i++) flip[i] = matrix[i] * skal; /* for */ return flippy; /* flippy = Free(flippy); */ -} /* extern double *JWDMMultMatSkalar */ +} /* extern double *JWDMMultMatSkalar */ /************************************************************************** ROCKFLOW - Function: GetPriMatFromTriMat @@ -2722,12 +2694,12 @@ double* TensorDrehDich(double* d, double* velo) MMultMatMat(d, 3, 3, zwa, 3, 3, zwi, 3, 3); MTranspoMat(zwa, 3, 3, zwo); MMultMatMat(zwo, 3, 3, zwi, 3, 3, d, 3, 3); - } /* end if (vg > MKleinsteZahl) */ + } /* end if (vg > MKleinsteZahl) */ /* end if (d[0] > MKleinsteZahl || d[4] > MKleinsteZahl || d[8] > MKleinsteZahl) */ return d; } -#endif //#ifdef obsolete //05.03.2010 WW +#endif //#ifdef obsolete //05.03.2010 WW /////////////////////////////////////////////////////////////////// // @@ -2753,21 +2725,21 @@ double* TensorDrehDich(double* d, double* velo) 02/2000 C. Thorenz Erste Version **************************************************************************/ -double MCalcDistancePointToLine(double* pt,double* l1,double* l2) +double MCalcDistancePointToLine(double* pt, double* l1, double* l2) { int i; double vec1[3], vec2[3], erg_vec[3], l; /* Vektor Linienpunkt zu Punkt */ - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) vec1[i] = pt[i] - l1[i]; /* Vektor Linienpunkt zu Linienpunkt */ - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) vec2[i] = l2[i] - l1[i]; /* Normieren */ - l = MBtrgVec(vec2,3); + l = MBtrgVec(vec2, 3); #ifdef ERROR_CONTROL if (l < MKleinsteZahl) { @@ -2776,12 +2748,12 @@ double MCalcDistancePointToLine(double* pt,double* l1,double* l2) } #endif - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) vec2[i] /= (l + MKleinsteZahl); M3KreuzProdukt(vec1, vec2, erg_vec); - return MBtrgVec(erg_vec,3); + return MBtrgVec(erg_vec, 3); } /*************************************************************************** @@ -2808,15 +2780,15 @@ double MCalcProjectionOfPointOnLine(double* pt, double* l1, double* l2, double* double vec1[3], vec2[3], l, projektionslaenge, abstand; /* Vektor Linienpunkt zu Punkt */ - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) vec1[i] = pt[i] - l1[i]; /* Vektor Linienpunkt zu Linienpunkt */ - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) vec2[i] = l2[i] - l1[i]; /* Normieren */ - l = MBtrgVec(vec2,3); + l = MBtrgVec(vec2, 3); #ifdef ERROR_CONTROL if (l < MKleinsteZahl) { @@ -2824,13 +2796,13 @@ double MCalcProjectionOfPointOnLine(double* pt, double* l1, double* l2, double* exit(1); } #endif - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) vec2[i] /= (l + MKleinsteZahl); projektionslaenge = MSkalarprodukt(vec1, vec2, 3); /* Punkt bestimmen */ - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) proj[i] = l1[i] + projektionslaenge * vec2[i]; abstand = MCalcDistancePointToPoint(proj, pt); @@ -2857,21 +2829,21 @@ double MCalcProjectionOfPointOnLine(double* pt, double* l1, double* l2, double* 02/2000 C. Thorenz Erste Version **************************************************************************/ -double MCalcDistancePointToPlane(double const* const pt,double* e1,double* e2,double* e3) +double MCalcDistancePointToPlane(double const* const pt, double* e1, double* e2, double* e3) { int i; double vec1[3], vec2[3], vec3[3], normal[3], volume, area; /* 1. Ebenen-Vektor */ - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) vec1[i] = e2[i] - e1[i]; /* 2. Ebenen-Vektor */ - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) vec2[i] = e3[i] - e1[i]; /* Ebene-Punkt-Vektor */ - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) vec3[i] = pt[i] - e1[i]; /* Normalenvektor */ @@ -3011,7 +2983,7 @@ void MNulleMat(double* mat, long m, long n) mat[i] = 0.0; } -#ifndef NEW_EQS //WW. 05.03.2010 +#ifndef NEW_EQS // WW. 05.03.2010 /*########################################################################## Funktionen fuer Gleichungsloeser (CG) ######################################################################## */ @@ -3100,7 +3072,7 @@ double MVekNorm2(double* x, long n) #ifdef SX void MVekSum(double* restrict x, double alpha, double* restrict y, long n) #else -void MVekSum(double* x,double alpha,double* y,long n) +void MVekSum(double* x, double alpha, double* y, long n) #endif { register long i; @@ -3137,8 +3109,7 @@ void MVekSum(double* x,double alpha,double* y,long n) 11/1995 MSR Erste Version **************************************************************************/ -void MVekGle(double alpha, double* x, double beta, double* y, - double* z, long n) +void MVekGle(double alpha, double* x, double beta, double* y, double* z, long n) { register long i; for (i = 0l; i < n; i++) @@ -3168,10 +3139,10 @@ double MVekDist(double* x, double* y, long n) double dist; double* d; - d = (double*) Malloc(n * sizeof(double)); + d = (double*)Malloc(n * sizeof(double)); MVekGle(1., x, -1., y, d, n); dist = VEKNORM_BICG(d, n); - d = (double*) Free(d); + d = (double*)Free(d); return dist; } @@ -3193,13 +3164,13 @@ double MVekDist(double* x, double* y, long n) double* MMachVec(long g) { double* zwerg; - zwerg = (double*) Malloc(sizeof(double) * g); + zwerg = (double*)Malloc(sizeof(double) * g); #ifdef ERROR_CONTROL if (zwerg == NULL) DisplayErrorMsg("zuwenig Speicher in MMachVec"); #endif return zwerg; -} /* MMachVec */ +} /* MMachVec */ /************************************************************************** ROCKFLOW - Funktion: MNullVec @@ -3219,7 +3190,7 @@ void MNullVec(double* zwerg, long g) #endif { register long i; - zwerg = (double*) Malloc(sizeof(double) * g); + zwerg = (double*)Malloc(sizeof(double) * g); #ifdef ERROR_CONTROL if (zwerg == NULL) DisplayErrorMsg("Fehler in MNullVec"); @@ -3229,7 +3200,7 @@ void MNullVec(double* zwerg, long g) #endif for (i = 0; i < g; i++) zwerg[i] = 0.0; -} /* MNullVec */ +} /* MNullVec */ /************************************************************************** ROCKFLOW - Funktion: MKopierVec @@ -3263,7 +3234,7 @@ void MKopierVec(double* vecquelle, double* vecziel, long g) #endif for (i = 0; i < g; i++) vecziel[i] = vecquelle[i]; -} /* MKopierVec */ +} /* MKopierVec */ /* Function MVectorlength Aufgabe: @@ -3278,7 +3249,7 @@ void MKopierVec(double* vecquelle, double* vecziel, long g) 05/2004 CMCD Erste Version 01/2011 TF changed from pow(*,0.5) to sqrt(*) */ -//double MVectorlength(double dx, double dy, double dz) +// double MVectorlength(double dx, double dy, double dz) //{ //// double length; //// length=pow(((dz*dz)+(dy*dy)+(dx*dx)),0.5); @@ -3301,31 +3272,26 @@ void MKopierVec(double* vecquelle, double* vecziel, long g) 8/2001 C.Thorenz: Erste Version **************************************************************************/ #ifdef SX -int MAddSkalVektoren(double* restrict v1, - double m1, - double* restrict v2, - double m2, - double* restrict vout, - long g) +int MAddSkalVektoren(double* restrict v1, double m1, double* restrict v2, double m2, double* restrict vout, long g) #else int MAddSkalVektoren(double* v1, double m1, double* v2, double m2, double* vout, long g) #endif { register long i; - //WW if ((m1==1.)&&(m2==1.)) + // WW if ((m1==1.)&&(m2==1.)) if ((fabs(m1 - 1.) < MKleinsteZahl) && (fabs(m2 - 1.) < MKleinsteZahl)) #ifdef SX #pragma cdir nodep #endif for (i = 0; i < g; i++) vout[i] = v1[i] + v2[i]; - else if(fabs(m1 - 1.) < MKleinsteZahl) + else if (fabs(m1 - 1.) < MKleinsteZahl) #ifdef SX #pragma cdir nodep #endif for (i = 0; i < g; i++) vout[i] = v1[i] + m2 * v2[i]; - else if(fabs(m2 - 1.) < MKleinsteZahl) + else if (fabs(m2 - 1.) < MKleinsteZahl) #ifdef SX #pragma cdir nodep #endif @@ -3340,7 +3306,7 @@ int MAddSkalVektoren(double* v1, double m1, double* v2, double m2, double* vout, return 1; } -#endif // 05.03.2010. WW +#endif // 05.03.2010. WW //// /************************************************************************** @@ -3365,9 +3331,7 @@ int MAddSkalVektoren(double* v1, double m1, double* v2, double m2, double* vout, 11/1999 C.Thorenz Register-Variablen **************************************************************************/ -int MMultVecVec(double* vec1, long gv1, - double* vec2, long gv2, - double* mato, long mo, long no) +int MMultVecVec(double* vec1, long gv1, double* vec2, long gv2, double* mato, long mo, long no) { register long i, j; @@ -3376,7 +3340,8 @@ int MMultVecVec(double* vec1, long gv1, #else const bool check_err = false; #endif - if (check_err) { + if (check_err) + { if (gv1 != mo) DisplayErrorMsg("MMultVecVec: Groesse von Matrix und Vektor 1 passen nicht"); if (gv2 != no) @@ -3389,7 +3354,7 @@ int MMultVecVec(double* vec1, long gv1, for (j = 0; j < gv2; j++) mato[i * gv2 + j] = vec1[i] * vec2[j]; return 1; -} /* MMultVecVec */ +} /* MMultVecVec */ /************************************************************************** ROCKFLOW - Funktion: MMultVecMat @@ -3419,13 +3384,9 @@ int MMultVecVec(double* vec1, long gv1, 11/1999 C.Thorenz Register-Variablen **************************************************************************/ #ifdef SX -int MMultVecMat(double* restrict vec, long gv, - double* restrict mat, long m, long n, - double* restrict veco, long go) +int MMultVecMat(double* restrict vec, long gv, double* restrict mat, long m, long n, double* restrict veco, long go) #else -int MMultVecMat(double* vec, long gv, - double* mat, long m, long n, - double* veco, long go) +int MMultVecMat(double* vec, long gv, double* mat, long m, long n, double* veco, long go) #endif { register long i, j; @@ -3434,14 +3395,15 @@ int MMultVecMat(double* vec, long gv, #else const bool check_err = false; #endif - if (check_err) { + if (check_err) + { if (gv != m) DisplayErrorMsg("MMultVecMat: Groesse von Matrix und Vektor passen nicht"); if (go != n) DisplayErrorMsg("MMultVecMat: Groesse von Ergebnis-Vektor stimmt nicht"); } - MNulleVec(veco, n); /* cb: Nullen nicht vergessen ! */ + MNulleVec(veco, n); /* cb: Nullen nicht vergessen ! */ for (i = 0; i < m; i++) #ifdef SX #pragma cdir nodep @@ -3449,7 +3411,7 @@ int MMultVecMat(double* vec, long gv, for (j = 0; j < n; j++) veco[j] += vec[i] * mat[j + i * n]; return 1; -} /* MMultVecMat */ +} /* MMultVecMat */ /************************************************************************** ROCKFLOW - Funktion: MMultMatVec @@ -3479,12 +3441,12 @@ int MMultVecMat(double* vec, long gv, 11/1999 C.Thorenz Warnung in #IFDEF, Register-Variablen **************************************************************************/ -int MMultMatVec( /* Matrix */ - double* mat, long m, long n, -/* Veltor fuer das Produkt */ - double* vec, long g, -/* Vektor fuer das Ergebnis */ - double* veco, long r) +int MMultMatVec(/* Matrix */ + double* mat, long m, long n, + /* Veltor fuer das Produkt */ + double* vec, long g, + /* Vektor fuer das Ergebnis */ + double* veco, long r) { register long i, k; @@ -3493,7 +3455,8 @@ int MMultMatVec( /* Matrix */ #else const bool check_err = false; #endif - if (check_err) { + if (check_err) + { if (g != n) DisplayErrorMsg("MMultMatVec: Groesse von Matrix und Vektor passen nicht"); if (r != m) @@ -3503,12 +3466,12 @@ int MMultMatVec( /* Matrix */ r = m; for (k = 0; k < m; k++) { - veco[k] = 0.0; /* cb: Nullen nicht vergessen ! */ + veco[k] = 0.0; /* cb: Nullen nicht vergessen ! */ for (i = 0; i < g; i++) veco[k] += vec[i] * mat[i + k * n]; } return 1; -} /* MMultMatVec */ +} /* MMultMatVec */ /************************************************************************** ROCKFLOW - Funktion: MMultMatMat @@ -3551,13 +3514,10 @@ int MMultMatVec( /* Matrix */ **************************************************************************/ #ifdef SX -int MMultMatMat(double* restrict mat1, long m1, long n1, - double* restrict mat2, long m2, long n2, - double* restrict mato, long mo, long no) +int MMultMatMat(double* restrict mat1, long m1, long n1, double* restrict mat2, long m2, long n2, double* restrict mato, + long mo, long no) #else -int MMultMatMat(double* mat1, long m1, long n1, - double* mat2, long m2, long n2, - double* mato, long mo, long no) +int MMultMatMat(double* mat1, long m1, long n1, double* mat2, long m2, long n2, double* mato, long mo, long no) #endif { #ifdef CBLAS_MMultMatMat @@ -3581,7 +3541,7 @@ int MMultMatMat(double* mat1, long m1, long n1, #pragma cdir nodep #endif for (i = 0; i < mo * no; i++) - mato[i] = 0.0; /*Ergebnismatrix vorsichtshalber nullen */ + mato[i] = 0.0; /*Ergebnismatrix vorsichtshalber nullen */ for (i = 0; i < n1 * m1; i++) { @@ -3598,7 +3558,7 @@ int MMultMatMat(double* mat1, long m1, long n1, #endif return 1; -} /* MMultMatMat */ +} /* MMultMatMat */ /*************************************************************************** ROCKFLOW - Funktion: MXPGaussPkt @@ -3623,42 +3583,42 @@ double MXPGaussPkt(long grd, long pkt) { switch (grd) { - case 1: - return 0.0; - case 2: - switch (pkt) - { - case 0: - return 0.577350269189626; - case 1: - return -0.577350269189626; - } - break; - case 3: - switch (pkt) - { - case 0: - return 0.774596669241483; case 1: return 0.0; case 2: - return -0.774596669241483; - } - break; - case 4: - switch (pkt) - { - case 0: - return 0.861136311594053; - case 1: - return 0.339981043584856; - case 2: - return -0.339981043584856; + switch (pkt) + { + case 0: + return 0.577350269189626; + case 1: + return -0.577350269189626; + } + break; case 3: - return -0.861136311594053; - } - break; - } /* switch grd */ + switch (pkt) + { + case 0: + return 0.774596669241483; + case 1: + return 0.0; + case 2: + return -0.774596669241483; + } + break; + case 4: + switch (pkt) + { + case 0: + return 0.861136311594053; + case 1: + return 0.339981043584856; + case 2: + return -0.339981043584856; + case 3: + return -0.861136311594053; + } + break; + } /* switch grd */ return 0.0; } @@ -3685,42 +3645,42 @@ double MXPGaussFkt(long grd, long pkt) { switch (grd) { - case 1: - return 2.0; - case 2: - switch (pkt) - { - case 0: - return 1.0; - case 1: - return 1.0; - } - break; - case 3: - switch (pkt) - { - case 0: - return 0.555555555555556; case 1: - return 0.888888888888889; + return 2.0; case 2: - return 0.555555555555556; - } - break; - case 4: - switch (pkt) - { - case 0: - return 0.347854845137454; - case 1: - return 0.652145154862546; - case 2: - return 0.652145154862546; + switch (pkt) + { + case 0: + return 1.0; + case 1: + return 1.0; + } + break; case 3: - return 0.347854845137454; - } - break; - } /* switch grd */ + switch (pkt) + { + case 0: + return 0.555555555555556; + case 1: + return 0.888888888888889; + case 2: + return 0.555555555555556; + } + break; + case 4: + switch (pkt) + { + case 0: + return 0.347854845137454; + case 1: + return 0.652145154862546; + case 2: + return 0.652145154862546; + case 3: + return 0.347854845137454; + } + break; + } /* switch grd */ return 0.0; } @@ -3730,7 +3690,7 @@ double MXPGaussFkt(long grd, long pkt) //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- -//NEW. WW +// NEW. WW /*************************************************************************** ROCKFLOW - Funktion: SamplePointTriHQ(const int nsample) @@ -3756,24 +3716,25 @@ double MXPGaussFkt(long grd, long pkt) **************************************************************************/ void SamplePointTriHQ(const int nsample, double* SPoint) { - switch(nsample) + switch (nsample) { - case 0: - SPoint[0] = 0.166666666666667; - SPoint[1] = 0.166666666666667; - SPoint[2] = 0.1666666666667; // Weight - break; - case 1: - SPoint[0] = 0.666666666666667; - SPoint[1] = 0.166666666666667; - SPoint[2] = 0.1666666666667; // Weight - break; - case 2: - SPoint[0] = 0.166666666666667; - SPoint[1] = 0.666666666666667; - SPoint[2] = 0.1666666666667; // Weight - break; - default: break; + case 0: + SPoint[0] = 0.166666666666667; + SPoint[1] = 0.166666666666667; + SPoint[2] = 0.1666666666667; // Weight + break; + case 1: + SPoint[0] = 0.666666666666667; + SPoint[1] = 0.166666666666667; + SPoint[2] = 0.1666666666667; // Weight + break; + case 2: + SPoint[0] = 0.166666666666667; + SPoint[1] = 0.666666666666667; + SPoint[2] = 0.1666666666667; // Weight + break; + default: + break; } } @@ -3793,39 +3754,40 @@ void SamplePointTriHQ(const int nsample, double* SPoint) **************************************************************************/ void SamplePointTet5(const int nsample, double* SPoint) { - switch(nsample) + switch (nsample) { - case 0: - SPoint[0] = 0.25; - SPoint[1] = 0.25; - SPoint[2] = 0.25; - SPoint[3] = -0.133333333333333; // Weight - break; - case 1: - SPoint[0] = 0.166666666666667; - SPoint[1] = 0.166666666666667; - SPoint[2] = 0.166666666666667; - SPoint[3] = 0.07500000000000; // Weight - break; - case 2: - SPoint[0] = 0.5; - SPoint[1] = 0.166666666666667; - SPoint[2] = 0.166666666666667; - SPoint[3] = 0.07500000000000; // Weight - break; - case 3: - SPoint[0] = 0.166666666666667; - SPoint[1] = 0.5; - SPoint[2] = 0.166666666666667; - SPoint[3] = 0.07500000000000; // Weight - break; - case 4: - SPoint[0] = 0.166666666666667; - SPoint[1] = 0.166666666666667; - SPoint[2] = 0.5; - SPoint[3] = 0.07500000000000; // Weight - break; - default: break; + case 0: + SPoint[0] = 0.25; + SPoint[1] = 0.25; + SPoint[2] = 0.25; + SPoint[3] = -0.133333333333333; // Weight + break; + case 1: + SPoint[0] = 0.166666666666667; + SPoint[1] = 0.166666666666667; + SPoint[2] = 0.166666666666667; + SPoint[3] = 0.07500000000000; // Weight + break; + case 2: + SPoint[0] = 0.5; + SPoint[1] = 0.166666666666667; + SPoint[2] = 0.166666666666667; + SPoint[3] = 0.07500000000000; // Weight + break; + case 3: + SPoint[0] = 0.166666666666667; + SPoint[1] = 0.5; + SPoint[2] = 0.166666666666667; + SPoint[3] = 0.07500000000000; // Weight + break; + case 4: + SPoint[0] = 0.166666666666667; + SPoint[1] = 0.166666666666667; + SPoint[2] = 0.5; + SPoint[3] = 0.07500000000000; // Weight + break; + default: + break; } } @@ -3845,99 +3807,100 @@ void SamplePointTet5(const int nsample, double* SPoint) **************************************************************************/ void SamplePointTet15(const int nsample, double* SPoint) { - switch(nsample) + switch (nsample) { - case 0: - SPoint[0] = 0.25; - SPoint[1] = 0.25; - SPoint[2] = 0.25; - SPoint[3] = 0.019753086419753086; // Weight - break; - case 1: - SPoint[0] = 0.09197107805272303; - SPoint[1] = 0.09197107805272303; - SPoint[2] = 0.09197107805272303; - SPoint[3] = 0.011989513963169772; // Weight - break; - case 2: - SPoint[0] = 0.72408676584183096; - SPoint[1] = 0.09197107805272303; - SPoint[2] = 0.09197107805272303; - SPoint[3] = 0.011989513963169772; // Weight - break; - case 3: - SPoint[0] = 0.09197107805272303; - SPoint[1] = 0.72408676584183096; - SPoint[2] = 0.09197107805272303; - SPoint[3] = 0.011989513963169772; // Weight - break; - case 4: - SPoint[0] = 0.09197107805272303; - SPoint[1] = 0.09197107805272303; - SPoint[2] = 0.72408676584183096; - SPoint[3] = 0.011989513963169772; // Weight - break; - case 5: - SPoint[0] = 0.44364916731037080; - SPoint[1] = 0.05635083268962915; - SPoint[2] = 0.05635083268962915; - SPoint[3] = 0.008818342151675485; // Weight - break; - case 6: - SPoint[0] = 0.05635083268962915; - SPoint[1] = 0.44364916731037080; - SPoint[2] = 0.05635083268962915; - SPoint[3] = 0.008818342151675485; // Weight - break; - case 7: - SPoint[0] = 0.05635083268962915; - SPoint[1] = 0.05635083268962915; - SPoint[2] = 0.44364916731037080; - SPoint[3] = 0.008818342151675485; // Weight - break; - case 8: - SPoint[0] = 0.05635083268962915; - SPoint[1] = 0.44364916731037080; - SPoint[2] = 0.44364916731037080; - SPoint[3] = 0.008818342151675485; // Weight - break; - case 9: - SPoint[0] = 0.44364916731037080; - SPoint[1] = 0.05635083268962915; - SPoint[2] = 0.44364916731037080; - SPoint[3] = 0.008818342151675485; // Weight - break; - case 10: - SPoint[0] = 0.44364916731037080; - SPoint[1] = 0.44364916731037080; - SPoint[2] = 0.05635083268962915; - SPoint[3] = 0.008818342151675485; // Weight - break; - case 11: - SPoint[0] = 0.31979362782962989; - SPoint[1] = 0.31979362782962989; - SPoint[2] = 0.31979362782962989; - SPoint[3] = 0.011511367871045397; // Weight - break; - case 12: - SPoint[0] = 0.04061911651111023; - SPoint[1] = 0.31979362782962989; - SPoint[2] = 0.31979362782962989; - SPoint[3] = 0.011511367871045397; // Weight - break; - case 13: - SPoint[0] = 0.31979362782962989; - SPoint[1] = 0.04061911651111023; - SPoint[2] = 0.31979362782962989; - SPoint[3] = 0.011511367871045397; // Weight - break; - case 14: - SPoint[0] = 0.31979362782962989; - SPoint[1] = 0.31979362782962989; - SPoint[2] = 0.04061911651111023; - SPoint[3] = 0.011511367871045397; // Weight - break; - default: break; + case 0: + SPoint[0] = 0.25; + SPoint[1] = 0.25; + SPoint[2] = 0.25; + SPoint[3] = 0.019753086419753086; // Weight + break; + case 1: + SPoint[0] = 0.09197107805272303; + SPoint[1] = 0.09197107805272303; + SPoint[2] = 0.09197107805272303; + SPoint[3] = 0.011989513963169772; // Weight + break; + case 2: + SPoint[0] = 0.72408676584183096; + SPoint[1] = 0.09197107805272303; + SPoint[2] = 0.09197107805272303; + SPoint[3] = 0.011989513963169772; // Weight + break; + case 3: + SPoint[0] = 0.09197107805272303; + SPoint[1] = 0.72408676584183096; + SPoint[2] = 0.09197107805272303; + SPoint[3] = 0.011989513963169772; // Weight + break; + case 4: + SPoint[0] = 0.09197107805272303; + SPoint[1] = 0.09197107805272303; + SPoint[2] = 0.72408676584183096; + SPoint[3] = 0.011989513963169772; // Weight + break; + case 5: + SPoint[0] = 0.44364916731037080; + SPoint[1] = 0.05635083268962915; + SPoint[2] = 0.05635083268962915; + SPoint[3] = 0.008818342151675485; // Weight + break; + case 6: + SPoint[0] = 0.05635083268962915; + SPoint[1] = 0.44364916731037080; + SPoint[2] = 0.05635083268962915; + SPoint[3] = 0.008818342151675485; // Weight + break; + case 7: + SPoint[0] = 0.05635083268962915; + SPoint[1] = 0.05635083268962915; + SPoint[2] = 0.44364916731037080; + SPoint[3] = 0.008818342151675485; // Weight + break; + case 8: + SPoint[0] = 0.05635083268962915; + SPoint[1] = 0.44364916731037080; + SPoint[2] = 0.44364916731037080; + SPoint[3] = 0.008818342151675485; // Weight + break; + case 9: + SPoint[0] = 0.44364916731037080; + SPoint[1] = 0.05635083268962915; + SPoint[2] = 0.44364916731037080; + SPoint[3] = 0.008818342151675485; // Weight + break; + case 10: + SPoint[0] = 0.44364916731037080; + SPoint[1] = 0.44364916731037080; + SPoint[2] = 0.05635083268962915; + SPoint[3] = 0.008818342151675485; // Weight + break; + case 11: + SPoint[0] = 0.31979362782962989; + SPoint[1] = 0.31979362782962989; + SPoint[2] = 0.31979362782962989; + SPoint[3] = 0.011511367871045397; // Weight + break; + case 12: + SPoint[0] = 0.04061911651111023; + SPoint[1] = 0.31979362782962989; + SPoint[2] = 0.31979362782962989; + SPoint[3] = 0.011511367871045397; // Weight + break; + case 13: + SPoint[0] = 0.31979362782962989; + SPoint[1] = 0.04061911651111023; + SPoint[2] = 0.31979362782962989; + SPoint[3] = 0.011511367871045397; // Weight + break; + case 14: + SPoint[0] = 0.31979362782962989; + SPoint[1] = 0.31979362782962989; + SPoint[2] = 0.04061911651111023; + SPoint[3] = 0.011511367871045397; // Weight + break; + default: + break; } } @@ -3956,40 +3919,40 @@ void SamplePointPyramid5(const int nsample, double* SPoint) static const double w1 = 81.0 / 100.0; static const double w2 = 125.0 / 27.0; - switch(nsample) + switch (nsample) { - case 0: - SPoint[0] = -g1; - SPoint[1] = -g1; - SPoint[2] = g2; - SPoint[3] = w1; // Weight - break; - case 1: - SPoint[0] = g1; - SPoint[1] = -g1; - SPoint[2] = g2; - SPoint[3] = w1; // Weight - break; - case 2: - SPoint[0] = g1; - SPoint[1] = g1; - SPoint[2] = g2; - SPoint[3] = w1; // Weight - break; - case 3: - SPoint[0] = -g1; - SPoint[1] = g1; - SPoint[2] = g2; - SPoint[3] = w1; // Weight - break; - case 4: - SPoint[0] = .0; - SPoint[1] = .0; - SPoint[2] = g3; - SPoint[3] = w2; // Weight - break; - default: - break; + case 0: + SPoint[0] = -g1; + SPoint[1] = -g1; + SPoint[2] = g2; + SPoint[3] = w1; // Weight + break; + case 1: + SPoint[0] = g1; + SPoint[1] = -g1; + SPoint[2] = g2; + SPoint[3] = w1; // Weight + break; + case 2: + SPoint[0] = g1; + SPoint[1] = g1; + SPoint[2] = g2; + SPoint[3] = w1; // Weight + break; + case 3: + SPoint[0] = -g1; + SPoint[1] = g1; + SPoint[2] = g2; + SPoint[3] = w1; // Weight + break; + case 4: + SPoint[0] = .0; + SPoint[1] = .0; + SPoint[2] = g3; + SPoint[3] = w2; // Weight + break; + default: + break; } } @@ -4014,88 +3977,88 @@ void SamplePointPyramid13(const int nsample, double* SPoint) static const double w3 = 2.474004977113405936; static const double w4 = 0.419515737191525950; - switch(nsample) + switch (nsample) { - case 0: - SPoint[0] = -g1; - SPoint[1] = -g1; - SPoint[2] = g4; - SPoint[3] = w1; // Weight - break; - case 1: - SPoint[0] = g1; - SPoint[1] = -g1; - SPoint[2] = g4; - SPoint[3] = w1; // Weight - break; - case 2: - SPoint[0] = g1; - SPoint[1] = g1; - SPoint[2] = g4; - SPoint[3] = w1; // Weight - break; - case 3: - SPoint[0] = -g1; - SPoint[1] = g1; - SPoint[2] = g4; - SPoint[3] = w1; // Weight - break; - case 4: - SPoint[0] = -g2; - SPoint[1] = .0; - SPoint[2] = g5; - SPoint[3] = w2; // Weight - break; - case 5: - SPoint[0] = g2; - SPoint[1] = .0; - SPoint[2] = g5; - SPoint[3] = w2; // Weight - break; - case 6: - SPoint[0] = .0; - SPoint[1] = -g2; - SPoint[2] = g5; - SPoint[3] = w2; // Weight - break; - case 7: - SPoint[0] = .0; - SPoint[1] = g2; - SPoint[2] = g5; - SPoint[3] = w2; // Weight - break; - case 8: - SPoint[0] = .0; - SPoint[1] = .0; - SPoint[2] = g6; - SPoint[3] = w3; // Weight - break; - case 9: - SPoint[0] = -g3; - SPoint[1] = -g3; - SPoint[2] = g7; - SPoint[3] = w4; // Weight - break; - case 10: - SPoint[0] = g3; - SPoint[1] = -g3; - SPoint[2] = g7; - SPoint[3] = w4; // Weight - break; - case 11: - SPoint[0] = g3; - SPoint[1] = g3; - SPoint[2] = g7; - SPoint[3] = w4; // Weight - break; - case 12: - SPoint[0] = -g3; - SPoint[1] = g3; - SPoint[2] = g7; - SPoint[3] = w4; // Weight - break; - default: - break; + case 0: + SPoint[0] = -g1; + SPoint[1] = -g1; + SPoint[2] = g4; + SPoint[3] = w1; // Weight + break; + case 1: + SPoint[0] = g1; + SPoint[1] = -g1; + SPoint[2] = g4; + SPoint[3] = w1; // Weight + break; + case 2: + SPoint[0] = g1; + SPoint[1] = g1; + SPoint[2] = g4; + SPoint[3] = w1; // Weight + break; + case 3: + SPoint[0] = -g1; + SPoint[1] = g1; + SPoint[2] = g4; + SPoint[3] = w1; // Weight + break; + case 4: + SPoint[0] = -g2; + SPoint[1] = .0; + SPoint[2] = g5; + SPoint[3] = w2; // Weight + break; + case 5: + SPoint[0] = g2; + SPoint[1] = .0; + SPoint[2] = g5; + SPoint[3] = w2; // Weight + break; + case 6: + SPoint[0] = .0; + SPoint[1] = -g2; + SPoint[2] = g5; + SPoint[3] = w2; // Weight + break; + case 7: + SPoint[0] = .0; + SPoint[1] = g2; + SPoint[2] = g5; + SPoint[3] = w2; // Weight + break; + case 8: + SPoint[0] = .0; + SPoint[1] = .0; + SPoint[2] = g6; + SPoint[3] = w3; // Weight + break; + case 9: + SPoint[0] = -g3; + SPoint[1] = -g3; + SPoint[2] = g7; + SPoint[3] = w4; // Weight + break; + case 10: + SPoint[0] = g3; + SPoint[1] = -g3; + SPoint[2] = g7; + SPoint[3] = w4; // Weight + break; + case 11: + SPoint[0] = g3; + SPoint[1] = g3; + SPoint[2] = g7; + SPoint[3] = w4; // Weight + break; + case 12: + SPoint[0] = -g3; + SPoint[1] = g3; + SPoint[2] = g7; + SPoint[3] = w4; // Weight + break; + default: + break; } } void SamplePointPyramid8(const int i, double* SPoint) @@ -4106,56 +4069,56 @@ void SamplePointPyramid8(const int i, double* SPoint) static const double w1 = 5.0 * (68.0 + 5.0 * sqrt(10.0)) / 432.0; static const double w2 = 85.0 / 54.0 - w1; - switch(i) + switch (i) { - case 0: - SPoint[0] = -g1; - SPoint[1] = -g1; - SPoint[2] = g2; - SPoint[3] = w1; // Weight - break; - case 1: - SPoint[0] = g1; - SPoint[1] = -g1; - SPoint[2] = g2; - SPoint[3] = w1; // Weight - break; - case 2: - SPoint[0] = g1; - SPoint[1] = g1; - SPoint[2] = g2; - SPoint[3] = w1; // Weight - break; - case 3: - SPoint[0] = -g1; - SPoint[1] = g1; - SPoint[2] = g2; - SPoint[3] = w1; // Weight - break; - case 4: - SPoint[0] = -g1; - SPoint[1] = -g1; - SPoint[2] = g3; - SPoint[3] = w2; // Weight - break; - case 5: - SPoint[0] = g1; - SPoint[1] = -g1; - SPoint[2] = g3; - SPoint[3] = w2; // Weight - break; - case 6: - SPoint[0] = g1; - SPoint[1] = g1; - SPoint[2] = g3; - SPoint[3] = w2; // Weight - break; - case 7: - SPoint[0] = -g1; - SPoint[1] = g1; - SPoint[2] = g3; - SPoint[3] = w2; // Weight - break; + case 0: + SPoint[0] = -g1; + SPoint[1] = -g1; + SPoint[2] = g2; + SPoint[3] = w1; // Weight + break; + case 1: + SPoint[0] = g1; + SPoint[1] = -g1; + SPoint[2] = g2; + SPoint[3] = w1; // Weight + break; + case 2: + SPoint[0] = g1; + SPoint[1] = g1; + SPoint[2] = g2; + SPoint[3] = w1; // Weight + break; + case 3: + SPoint[0] = -g1; + SPoint[1] = g1; + SPoint[2] = g2; + SPoint[3] = w1; // Weight + break; + case 4: + SPoint[0] = -g1; + SPoint[1] = -g1; + SPoint[2] = g3; + SPoint[3] = w2; // Weight + break; + case 5: + SPoint[0] = g1; + SPoint[1] = -g1; + SPoint[2] = g3; + SPoint[3] = w2; // Weight + break; + case 6: + SPoint[0] = g1; + SPoint[1] = g1; + SPoint[2] = g3; + SPoint[3] = w2; // Weight + break; + case 7: + SPoint[0] = -g1; + SPoint[1] = g1; + SPoint[2] = g3; + SPoint[3] = w2; // Weight + break; } } /************************************************************************** @@ -4267,8 +4230,8 @@ void GradShapeFunctionTri(double* dN3, const double* u) u = u; // d()/dL_1 dN3[0] = -1.0; - dN3[1] = 1.0; - dN3[2] = 0.0; + dN3[1] = 1.0; + dN3[2] = 0.0; // d()/dL_2 dN3[3] = -1.0; dN3[4] = 0.0; @@ -4323,22 +4286,22 @@ void ShapeFunctionTriHQ(double* N6, const double* u) **************************************************************************/ void GradShapeFunctionTriHQ(double* dN6, const double* u) { - dN6[0] = 4. * (u[0] + u[1]) - 3.; // dN1/dL1 - dN6[6] = 4. * (u[0] + u[1]) - 3.; // dN1/dL2 + dN6[0] = 4. * (u[0] + u[1]) - 3.; // dN1/dL1 + dN6[6] = 4. * (u[0] + u[1]) - 3.; // dN1/dL2 - dN6[1] = 4. * u[0] - 1.; // dN2/dL1 - dN6[7] = 0.; // dN2/dL2 + dN6[1] = 4. * u[0] - 1.; // dN2/dL1 + dN6[7] = 0.; // dN2/dL2 - dN6[2] = 0.; // dN3/dL1 - dN6[8] = 4. * u[1] - 1.; // dN3/dL2 + dN6[2] = 0.; // dN3/dL1 + dN6[8] = 4. * u[1] - 1.; // dN3/dL2 - dN6[3] = 4. * (1 - 2. * u[0] - u[1]); // dN4/dL1 - dN6[9] = -4. * u[0]; // dN4/dL2 + dN6[3] = 4. * (1 - 2. * u[0] - u[1]); // dN4/dL1 + dN6[9] = -4. * u[0]; // dN4/dL2 - dN6[4] = 4. * u[1]; // dN5/dL1 - dN6[10] = 4. * u[0]; // dN5/dL2 + dN6[4] = 4. * u[1]; // dN5/dL1 + dN6[10] = 4. * u[0]; // dN5/dL2 - dN6[5] = -4. * u[1]; // dN6/dL1 + dN6[5] = -4. * u[1]; // dN6/dL1 dN6[11] = 4. * (1 - u[0] - 2. * u[1]); // dN6/dL2 } @@ -4361,10 +4324,10 @@ void GradShapeFunctionTriHQ(double* dN6, const double* u) 06/2003 WW Erste Version **************************************************************************/ -void realCoordTriHQ(double* x, const double* XY, const double* u ) +void realCoordTriHQ(double* x, const double* XY, const double* u) { - x[1] = (1.0 - u[0] - u[1]) * XY[0] + u[0] * XY[1] + u[1] * XY[2]; - x[1] = (1.0 - u[0] - u[1]) * XY[6] + u[0] * XY[7] + u[1] * XY[8]; + x[1] = (1.0 - u[0] - u[1]) * XY[0] + u[0] * XY[1] + u[1] * XY[2]; + x[1] = (1.0 - u[0] - u[1]) * XY[6] + u[0] * XY[7] + u[1] * XY[8]; } /*************************************************************************** @@ -4444,10 +4407,10 @@ void GradShapeFunctionQuad(double* dN4, const double* u) void ShapeFunctionQuadHQ8(double* N8, const double* u) { // - N8[0] = -0.25 * (1.0 - u[0]) * (1.0 - u[1]) * (( 1.0 + u[0] + u[1])); - N8[1] = 0.25 * (1.0 + u[0]) * (1.0 - u[1]) * ((-1.0 + u[0] - u[1])); - N8[2] = 0.25 * (1.0 + u[0]) * (1.0 + u[1]) * ((-1.0 + u[0] + u[1])); - N8[3] = -0.25 * (1.0 - u[0]) * (1.0 + u[1]) * (( 1.0 + u[0] - u[1])); + N8[0] = -0.25 * (1.0 - u[0]) * (1.0 - u[1]) * ((1.0 + u[0] + u[1])); + N8[1] = 0.25 * (1.0 + u[0]) * (1.0 - u[1]) * ((-1.0 + u[0] - u[1])); + N8[2] = 0.25 * (1.0 + u[0]) * (1.0 + u[1]) * ((-1.0 + u[0] + u[1])); + N8[3] = -0.25 * (1.0 - u[0]) * (1.0 + u[1]) * ((1.0 + u[0] - u[1])); // N8[4] = 0.5 * (1.0 - u[0] * u[0]) * (1.0 - u[1]); N8[5] = 0.5 * (1.0 - u[1] * u[1]) * (1.0 + u[0]); @@ -4473,7 +4436,7 @@ void ShapeFunctionQuadHQ8(double* N8, const double* u) **************************************************************************/ void ShapeFunctionQuadHQ(double* N9, const double* u) { - N9[8] = (1.0 - u[0] * u[0]) * ( 1.0 - u[1] * u[1]); + N9[8] = (1.0 - u[0] * u[0]) * (1.0 - u[1] * u[1]); N9[7] = 0.5 * (1.0 - u[1] * u[1]) * (1.0 + u[0]) - 0.5 * N9[8]; N9[6] = 0.5 * (1.0 - u[0] * u[0]) * (1.0 - u[1]) - 0.5 * N9[8]; N9[5] = 0.5 * (1.0 - u[1] * u[1]) * (1.0 - u[0]) - 0.5 * N9[8]; @@ -4541,7 +4504,7 @@ void GradShapeFunctionQuadHQ8(double* dN8, const double* u) double r = u[0]; double s = u[1]; - //dN/dr + // dN/dr dN8[0] = (1 - s) * (2 * r + s) * 0.25; dN8[1] = (1 - s) * (2 * r - s) * 0.25; dN8[2] = (1 + s) * (2 * r + s) * 0.25; @@ -4551,7 +4514,7 @@ void GradShapeFunctionQuadHQ8(double* dN8, const double* u) dN8[6] = -r * (1 + s); dN8[7] = -(1 - s * s) * 0.5; - //dN/ds + // dN/ds dN8[8] = (1 - r) * (r + 2 * s) * 0.25; dN8[9] = -(1 + r) * (r - 2 * s) * 0.25; dN8[10] = (1 + r) * (r + 2 * s) * 0.25; @@ -4676,7 +4639,7 @@ void GradShapeFunctionTetHQ(double* dN10, const double* x) dN10[8] = 0.0; dN10[9] = -4.0 * x[2]; - dN10[10] = 4. * (x[0] + x[1] + x[2]) - 3.; + dN10[10] = 4. * (x[0] + x[1] + x[2]) - 3.; dN10[11] = 0.0; dN10[12] = 4. * x[1] - 1.; dN10[13] = 0.; @@ -4763,9 +4726,9 @@ void ShapeFunctionHex(double* N8, const double* x) void GradShapeFunctionHex(double* dN8, const double* x) { int i; - double r = x[0]; - double s = x[1]; - double t = x[2]; + double r = x[0]; + double s = x[1]; + double t = x[2]; dN8[0] = +(1.0 + s) * (1.0 + t); dN8[1] = -(1.0 + s) * (1.0 + t); dN8[2] = -(1.0 - s) * (1.0 + t); @@ -4822,7 +4785,7 @@ void GradShapeFunctionHex(double* dN8, const double* x) **************************************************************************/ double ShapeFunctionHexHQ_Corner(const double r, const double s, const double t) { - return 0.125 * (1 + r) * (1 + s) * (1 + t) * ( r + s + t - 2.0); + return 0.125 * (1 + r) * (1 + s) * (1 + t) * (r + s + t - 2.0); } double ShapeFunctionHexHQ_Middle(const double r, const double s, const double t) @@ -4832,34 +4795,34 @@ double ShapeFunctionHexHQ_Middle(const double r, const double s, const double t) double dShapeFunctionHexHQ_Corner(const double r, const double s, const double t, const int ty) { - switch(ty) + switch (ty) { - case 0: - return 0.125 * (1 + s) * (1 + t) * (2.0 * r + s + t - 1.0); - break; - case 1: - return 0.125 * (1 + t) * (1 + r) * (2.0 * s + r + t - 1.0); - break; - case 2: - return 0.125 * (1 + r) * (1 + s) * (2.0 * t + s + r - 1.0); - break; + case 0: + return 0.125 * (1 + s) * (1 + t) * (2.0 * r + s + t - 1.0); + break; + case 1: + return 0.125 * (1 + t) * (1 + r) * (2.0 * s + r + t - 1.0); + break; + case 2: + return 0.125 * (1 + r) * (1 + s) * (2.0 * t + s + r - 1.0); + break; } return 0.0; } double dShapeFunctionHexHQ_Middle(const double r, const double s, const double t, const int ty) { - switch(ty) + switch (ty) { - case 0: - return -0.5 * r * (1 + s) * (1 + t); - break; - case 1: - return 0.25 * (1 - r * r) * (1 + t); - break; - case 2: - return 0.25 * (1 - r * r) * (1 + s); - break; + case 0: + return -0.5 * r * (1 + s) * (1 + t); + break; + case 1: + return 0.25 * (1 - r * r) * (1 + t); + break; + case 2: + return 0.25 * (1 - r * r) * (1 + s); + break; } return 0.0; } @@ -4870,29 +4833,29 @@ void ShapeFunctionHexHQ(double* N20, const double* x) double s = x[1]; double t = x[2]; - N20[0] = ShapeFunctionHexHQ_Corner(r,s,t); - N20[1] = ShapeFunctionHexHQ_Corner(-r,s,t); - N20[2] = ShapeFunctionHexHQ_Corner(-r,-s,t); - N20[3] = ShapeFunctionHexHQ_Corner(r,-s,t); - N20[4] = ShapeFunctionHexHQ_Corner(r,s,-t); - N20[5] = ShapeFunctionHexHQ_Corner(-r,s,-t); - N20[6] = ShapeFunctionHexHQ_Corner(-r,-s,-t); - N20[7] = ShapeFunctionHexHQ_Corner(r,-s,-t); - - N20[8] = ShapeFunctionHexHQ_Middle(r,s,t); - N20[10] = ShapeFunctionHexHQ_Middle(r,-s,t); - N20[14] = ShapeFunctionHexHQ_Middle(r,-s,-t); - N20[12] = ShapeFunctionHexHQ_Middle(r,s,-t); - - N20[11] = ShapeFunctionHexHQ_Middle(s,t,r); - N20[15] = ShapeFunctionHexHQ_Middle(s,-t,r); - N20[13] = ShapeFunctionHexHQ_Middle(s,-t,-r); - N20[9] = ShapeFunctionHexHQ_Middle(s,t,-r); - - N20[16] = ShapeFunctionHexHQ_Middle(t,r,s); - N20[17] = ShapeFunctionHexHQ_Middle(t,-r,s); - N20[18] = ShapeFunctionHexHQ_Middle(t,-r,-s); - N20[19] = ShapeFunctionHexHQ_Middle(t,r,-s); + N20[0] = ShapeFunctionHexHQ_Corner(r, s, t); + N20[1] = ShapeFunctionHexHQ_Corner(-r, s, t); + N20[2] = ShapeFunctionHexHQ_Corner(-r, -s, t); + N20[3] = ShapeFunctionHexHQ_Corner(r, -s, t); + N20[4] = ShapeFunctionHexHQ_Corner(r, s, -t); + N20[5] = ShapeFunctionHexHQ_Corner(-r, s, -t); + N20[6] = ShapeFunctionHexHQ_Corner(-r, -s, -t); + N20[7] = ShapeFunctionHexHQ_Corner(r, -s, -t); + + N20[8] = ShapeFunctionHexHQ_Middle(r, s, t); + N20[10] = ShapeFunctionHexHQ_Middle(r, -s, t); + N20[14] = ShapeFunctionHexHQ_Middle(r, -s, -t); + N20[12] = ShapeFunctionHexHQ_Middle(r, s, -t); + + N20[11] = ShapeFunctionHexHQ_Middle(s, t, r); + N20[15] = ShapeFunctionHexHQ_Middle(s, -t, r); + N20[13] = ShapeFunctionHexHQ_Middle(s, -t, -r); + N20[9] = ShapeFunctionHexHQ_Middle(s, t, -r); + + N20[16] = ShapeFunctionHexHQ_Middle(t, r, s); + N20[17] = ShapeFunctionHexHQ_Middle(t, -r, s); + N20[18] = ShapeFunctionHexHQ_Middle(t, -r, -s); + N20[19] = ShapeFunctionHexHQ_Middle(t, r, -s); } /*************************************************************************** @@ -4919,39 +4882,36 @@ void GradShapeFunctionHexHQ(double* dN20, const double* x) double r = x[0]; double s = x[1]; double t = x[2]; - static double sign1[] = {-1.0, 1.0,1.0}; - static double sign2[] = { 1.0,-1.0,1.0}; - static double sign3[] = { 1.0, 1.0,-1.0}; - for(int i = 0; i < 3; i++) + static double sign1[] = {-1.0, 1.0, 1.0}; + static double sign2[] = {1.0, -1.0, 1.0}; + static double sign3[] = {1.0, 1.0, -1.0}; + for (int i = 0; i < 3; i++) { - dN20[20 * i + 0] = dShapeFunctionHexHQ_Corner(r,s,t,i); - dN20[20 * i + 1] = sign1[i] * dShapeFunctionHexHQ_Corner(-r,s,t,i); - dN20[20 * i + 2] = sign1[i] * sign2[i] * dShapeFunctionHexHQ_Corner(-r,-s,t,i); - dN20[20 * i + 3] = sign2[i] * dShapeFunctionHexHQ_Corner(r,-s,t,i); - dN20[20 * i + 4] = sign3[i] * dShapeFunctionHexHQ_Corner(r,s,-t,i); - dN20[20 * i + 5] = sign1[i] * sign3[i] * dShapeFunctionHexHQ_Corner(-r,s,-t,i); - dN20[20 * i + 6] = sign1[i] * sign2[i] * sign3[i] * dShapeFunctionHexHQ_Corner(-r, - -s, - -t, - i); - dN20[20 * i + 7] = sign2[i] * sign3[i] * dShapeFunctionHexHQ_Corner(r,-s,-t,i); - - dN20[20 * i + 8] = dShapeFunctionHexHQ_Middle(r,s,t,i); - dN20[20 * i + 10] = sign2[i] * dShapeFunctionHexHQ_Middle(r,-s,t,i); - dN20[20 * i + 14] = sign2[i] * sign3[i] * dShapeFunctionHexHQ_Middle(r,-s,-t,i); - dN20[20 * i + 12] = sign3[i] * dShapeFunctionHexHQ_Middle(r,s,-t,i); + dN20[20 * i + 0] = dShapeFunctionHexHQ_Corner(r, s, t, i); + dN20[20 * i + 1] = sign1[i] * dShapeFunctionHexHQ_Corner(-r, s, t, i); + dN20[20 * i + 2] = sign1[i] * sign2[i] * dShapeFunctionHexHQ_Corner(-r, -s, t, i); + dN20[20 * i + 3] = sign2[i] * dShapeFunctionHexHQ_Corner(r, -s, t, i); + dN20[20 * i + 4] = sign3[i] * dShapeFunctionHexHQ_Corner(r, s, -t, i); + dN20[20 * i + 5] = sign1[i] * sign3[i] * dShapeFunctionHexHQ_Corner(-r, s, -t, i); + dN20[20 * i + 6] = sign1[i] * sign2[i] * sign3[i] * dShapeFunctionHexHQ_Corner(-r, -s, -t, i); + dN20[20 * i + 7] = sign2[i] * sign3[i] * dShapeFunctionHexHQ_Corner(r, -s, -t, i); + + dN20[20 * i + 8] = dShapeFunctionHexHQ_Middle(r, s, t, i); + dN20[20 * i + 10] = sign2[i] * dShapeFunctionHexHQ_Middle(r, -s, t, i); + dN20[20 * i + 14] = sign2[i] * sign3[i] * dShapeFunctionHexHQ_Middle(r, -s, -t, i); + dN20[20 * i + 12] = sign3[i] * dShapeFunctionHexHQ_Middle(r, s, -t, i); co = (i + 2) % 3; - dN20[20 * i + 11] = dShapeFunctionHexHQ_Middle(s,t,r,co); - dN20[20 * i + 15] = sign3[i] * dShapeFunctionHexHQ_Middle(s,-t,r,co); - dN20[20 * i + 13] = sign1[i] * sign3[i] * dShapeFunctionHexHQ_Middle(s,-t,-r,co); - dN20[20 * i + 9] = sign1[i] * dShapeFunctionHexHQ_Middle(s,t,-r,co); + dN20[20 * i + 11] = dShapeFunctionHexHQ_Middle(s, t, r, co); + dN20[20 * i + 15] = sign3[i] * dShapeFunctionHexHQ_Middle(s, -t, r, co); + dN20[20 * i + 13] = sign1[i] * sign3[i] * dShapeFunctionHexHQ_Middle(s, -t, -r, co); + dN20[20 * i + 9] = sign1[i] * dShapeFunctionHexHQ_Middle(s, t, -r, co); co = (i + 1) % 3; - dN20[20 * i + 16] = dShapeFunctionHexHQ_Middle(t,r,s,co); - dN20[20 * i + 17] = sign1[i] * dShapeFunctionHexHQ_Middle(t,-r,s,co); - dN20[20 * i + 18] = sign1[i] * sign2[i] * dShapeFunctionHexHQ_Middle(t,-r,-s,co); - dN20[20 * i + 19] = sign2[i] * dShapeFunctionHexHQ_Middle(t,r,-s,co); + dN20[20 * i + 16] = dShapeFunctionHexHQ_Middle(t, r, s, co); + dN20[20 * i + 17] = sign1[i] * dShapeFunctionHexHQ_Middle(t, -r, s, co); + dN20[20 * i + 18] = sign1[i] * sign2[i] * dShapeFunctionHexHQ_Middle(t, -r, -s, co); + dN20[20 * i + 19] = sign2[i] * dShapeFunctionHexHQ_Middle(t, r, -s, co); } } @@ -5113,18 +5073,18 @@ void GradShapeFunctionPriHQ(double* dN, const double* x) double v2 = (4.0 * L1 - 1); // Vertex, bottom dN[0] = -0.5 * (v1 * (1.0 - t) - tt1); - dN[1] = 0.5 * (v2 * (1.0 - t) - tt1); - dN[2] = 0.0; + dN[1] = 0.5 * (v2 * (1.0 - t) - tt1); + dN[2] = 0.0; // Vertex, top dN[3] = -0.5 * (v1 * (1.0 + t) - tt1); - dN[4] = 0.5 * (v2 * (1.0 + t) - tt1); - dN[5] = 0.0; + dN[4] = 0.5 * (v2 * (1.0 + t) - tt1); + dN[5] = 0.0; // Middle point, bottom - dN[6] = 2.0 * (L0 -L1) * (1.0 - t); - dN[7] = 2.0 * L2 * (1.0 - t); - dN[8] = - dN[7]; + dN[6] = 2.0 * (L0 - L1) * (1.0 - t); + dN[7] = 2.0 * L2 * (1.0 - t); + dN[8] = -dN[7]; // Middle point, top - dN[9] = 2.0 * (L0 - L1) * (1.0 + t); + dN[9] = 2.0 * (L0 - L1) * (1.0 + t); dN[10] = 2.0 * L2 * (1.0 + t); dN[11] = -dN[10]; // Middle point, center @@ -5136,20 +5096,20 @@ void GradShapeFunctionPriHQ(double* dN, const double* x) v1 = (4.0 * L2 - 1); // Vertex, bottom dN[15] = dN[0]; - dN[16] = 0.0; - dN[17] = 0.5 * (v1 * (1.0 - t) - tt1); + dN[16] = 0.0; + dN[17] = 0.5 * (v1 * (1.0 - t) - tt1); // Vertex, top dN[18] = dN[3]; - dN[19] = 0.0; - dN[20] = 0.5 * (v1 * (1.0 + t) - tt1); + dN[19] = 0.0; + dN[20] = 0.5 * (v1 * (1.0 + t) - tt1); // Middle point, bottom dN[21] = -2.0 * L1 * (1.0 - t); dN[22] = -dN[21]; - v1 = 2.0 * (L0 - L2); - dN[23] = v1 * (1.0 - t); + v1 = 2.0 * (L0 - L2); + dN[23] = v1 * (1.0 - t); // Middle point, top dN[24] = -2.0 * L1 * (1.0 + t); - dN[25] = -dN[24]; + dN[25] = -dN[24]; dN[26] = v1 * (1.0 + t); // Middle point, center dN[27] = -tt1; @@ -5231,47 +5191,23 @@ void ShapeFunctionPyraHQ13(double* N, const double* x) const double s = x[1]; const double t = x[2]; - N[0] = -0.0625 * - (1.0 - - r) * - (1.0 - - s) * - (1.0 - - t) * - (4.0 + 3.0 * r + 3.0 * s + 2.0 * r * s + 2.0 * t + r * t + s * t + 2.0 * r * s * t); - N[1] = -0.0625 * - (1.0 + - r) * - (1.0 - - s) * - (1.0 - - t) * - (4.0 - 3.0 * r + 3.0 * s - 2.0 * r * s + 2.0 * t - r * t + s * t - 2.0 * r * s * t); - N[2] = -0.0625 * - (1.0 + - r) * - (1.0 + - s) * - (1.0 - - t) * - (4.0 - 3.0 * r - 3.0 * s + 2.0 * r * s + 2.0 * t - r * t - s * t + 2.0 * r * s * t); - N[3] = -0.0625 * - (1.0 - - r) * - (1.0 + - s) * - (1.0 - - t) * - (4.0 + 3.0 * r - 3.0 * s - 2.0 * r * s + 2.0 * t + r * t - s * t - 2.0 * r * s * t); - N[4] = 0.5 * t * (1.0 + t); - N[5] = 0.125 * (1.0 - r * r) * (1.0 - s) * (1.0 - t) * (2.0 + s + s * t); - N[6] = 0.125 * (1.0 + r) * (1.0 - s * s) * (1.0 - t) * (2.0 - r - r * t); - N[7] = 0.125 * (1.0 - r * r) * (1.0 + s) * (1.0 - t) * (2.0 - s - s * t); - N[8] = 0.125 * (1.0 - r) * (1.0 - s * s) * (1.0 - t) * (2.0 + r + r * t); - N[9] = 0.25 * (1.0 - r) * (1.0 - s) * (1.0 - t * t); - N[10] = 0.25 * (1.0 + r) * (1.0 - s) * (1.0 - t * t); - N[11] = 0.25 * (1.0 + r) * (1.0 + s) * (1.0 - t * t); - N[12] = 0.25 * (1.0 - r) * (1.0 + s) * (1.0 - t * t); + N[0] = -0.0625 * (1.0 - r) * (1.0 - s) * (1.0 - t) + * (4.0 + 3.0 * r + 3.0 * s + 2.0 * r * s + 2.0 * t + r * t + s * t + 2.0 * r * s * t); + N[1] = -0.0625 * (1.0 + r) * (1.0 - s) * (1.0 - t) + * (4.0 - 3.0 * r + 3.0 * s - 2.0 * r * s + 2.0 * t - r * t + s * t - 2.0 * r * s * t); + N[2] = -0.0625 * (1.0 + r) * (1.0 + s) * (1.0 - t) + * (4.0 - 3.0 * r - 3.0 * s + 2.0 * r * s + 2.0 * t - r * t - s * t + 2.0 * r * s * t); + N[3] = -0.0625 * (1.0 - r) * (1.0 + s) * (1.0 - t) + * (4.0 + 3.0 * r - 3.0 * s - 2.0 * r * s + 2.0 * t + r * t - s * t - 2.0 * r * s * t); + N[4] = 0.5 * t * (1.0 + t); + N[5] = 0.125 * (1.0 - r * r) * (1.0 - s) * (1.0 - t) * (2.0 + s + s * t); + N[6] = 0.125 * (1.0 + r) * (1.0 - s * s) * (1.0 - t) * (2.0 - r - r * t); + N[7] = 0.125 * (1.0 - r * r) * (1.0 + s) * (1.0 - t) * (2.0 - s - s * t); + N[8] = 0.125 * (1.0 - r) * (1.0 - s * s) * (1.0 - t) * (2.0 + r + r * t); + N[9] = 0.25 * (1.0 - r) * (1.0 - s) * (1.0 - t * t); + N[10] = 0.25 * (1.0 + r) * (1.0 - s) * (1.0 - t * t); + N[11] = 0.25 * (1.0 + r) * (1.0 + s) * (1.0 - t * t); + N[12] = 0.25 * (1.0 - r) * (1.0 + s) * (1.0 - t * t); } /*************************************************************************** @@ -5299,16 +5235,16 @@ void GradShapeFunctionPyra(double* dN, const double* x) const double t = x[2]; // dN/dL1 dN[0] = -0.125 * (1.0 - s) * (1.0 - t); - dN[1] = 0.125 * (1.0 - s) * (1.0 - t); - dN[2] = 0.125 * (1.0 + s) * (1.0 - t); + dN[1] = 0.125 * (1.0 - s) * (1.0 - t); + dN[2] = 0.125 * (1.0 + s) * (1.0 - t); dN[3] = -0.125 * (1.0 + s) * (1.0 - t); - dN[4] = 0.0; + dN[4] = 0.0; // dN/dL2 dN[5] = -0.125 * (1.0 - r) * (1.0 - t); dN[6] = -0.125 * (1.0 + r) * (1.0 - t); - dN[7] = 0.125 * (1.0 + r) * (1.0 - t); - dN[8] = 0.125 * (1.0 - r) * (1.0 - t); - dN[9] = 0.0; + dN[7] = 0.125 * (1.0 + r) * (1.0 - t); + dN[8] = 0.125 * (1.0 - r) * (1.0 - t); + dN[9] = 0.0; // dN/dt dN[10] = -0.125 * (1.0 - r) * (1.0 - s); dN[11] = -0.125 * (1.0 + r) * (1.0 - s); @@ -5340,77 +5276,49 @@ void GradShapeFunctionPyraHQ13(double* dN, const double* x) const double s = x[1]; const double t = x[2]; //---dN/dr - dN[0] = 0.0625 * - (1.0 - - s) * - (1.0 - - t) * (1.0 + 6.0 * r + s + 4.0 * r * s + t + 2.0 * r * t - s * t + 4.0 * r * s * t); - dN[1] = -0.0625 * - (1.0 - - s) * - (1.0 - - t) * (1.0 - 6.0 * r + s - 4.0 * r * s + t - 2.0 * r * t - s * t - 4.0 * r * s * t); - dN[2] = -0.0625 * - (1.0 + - s) * - (1.0 - - t) * (1.0 - 6.0 * r - s + 4.0 * r * s + t - 2.0 * r * t + s * t + 4.0 * r * s * t); - dN[3] = 0.0625 * - (1.0 + - s) * - (1.0 - - t) * (1.0 + 6.0 * r - s - 4.0 * r * s + t + 2.0 * r * t + s * t - 4.0 * r * s * t); - dN[4] = 0.0; - dN[5] = -0.25 * r * (1.0 - s) * (1.0 - t) * (2.0 + s + s * t); - dN[6] = 0.125 * (1.0 - s * s) * (1.0 - t) * (1.0 - 2.0 * r - t - 2 * r * t); - dN[7] = -0.25 * r * (1.0 + s) * (1.0 - t) * (2.0 - s - s * t); - dN[8] = -0.125 * (1.0 - s * s) * (1.0 - t) * (1.0 + 2.0 * r - t + 2 * r * t); - dN[9] = -0.25 * (1.0 - s) * (1.0 - t * t); - dN[10] = 0.25 * (1.0 - s) * (1.0 - t * t); - dN[11] = 0.25 * (1.0 + s) * (1.0 - t * t); + dN[0] = 0.0625 * (1.0 - s) * (1.0 - t) + * (1.0 + 6.0 * r + s + 4.0 * r * s + t + 2.0 * r * t - s * t + 4.0 * r * s * t); + dN[1] = -0.0625 * (1.0 - s) * (1.0 - t) + * (1.0 - 6.0 * r + s - 4.0 * r * s + t - 2.0 * r * t - s * t - 4.0 * r * s * t); + dN[2] = -0.0625 * (1.0 + s) * (1.0 - t) + * (1.0 - 6.0 * r - s + 4.0 * r * s + t - 2.0 * r * t + s * t + 4.0 * r * s * t); + dN[3] = 0.0625 * (1.0 + s) * (1.0 - t) + * (1.0 + 6.0 * r - s - 4.0 * r * s + t + 2.0 * r * t + s * t - 4.0 * r * s * t); + dN[4] = 0.0; + dN[5] = -0.25 * r * (1.0 - s) * (1.0 - t) * (2.0 + s + s * t); + dN[6] = 0.125 * (1.0 - s * s) * (1.0 - t) * (1.0 - 2.0 * r - t - 2 * r * t); + dN[7] = -0.25 * r * (1.0 + s) * (1.0 - t) * (2.0 - s - s * t); + dN[8] = -0.125 * (1.0 - s * s) * (1.0 - t) * (1.0 + 2.0 * r - t + 2 * r * t); + dN[9] = -0.25 * (1.0 - s) * (1.0 - t * t); + dN[10] = 0.25 * (1.0 - s) * (1.0 - t * t); + dN[11] = 0.25 * (1.0 + s) * (1.0 - t * t); dN[12] = -0.25 * (1.0 + s) * (1.0 - t * t); //---dN/ds - dN[13] = 0.0625 * - (1.0 - - r) * - (1.0 - - t) * (1.0 + r + 6.0 * s + 4.0 * r * s + t - r * t + 2.0 * s * t + 4.0 * r * s * t); - dN[14] = 0.0625 * - (1.0 + - r) * - (1.0 - - t) * (1.0 - r + 6.0 * s - 4.0 * r * s + t + r * t + 2.0 * s * t - 4.0 * r * s * t); - dN[15] = -0.0625 * - (1.0 + - r) * - (1.0 - - t) * (1.0 - r - 6.0 * s + 4.0 * r * s + t + r * t - 2.0 * s * t + 4.0 * r * s * t); - dN[16] = -0.0625 * - (1.0 - - r) * - (1.0 - - t) * (1.0 + r - 6.0 * s - 4.0 * r * s + t - r * t - 2.0 * s * t - 4.0 * r * s * t); - dN[17] = 0.0; + dN[13] = 0.0625 * (1.0 - r) * (1.0 - t) + * (1.0 + r + 6.0 * s + 4.0 * r * s + t - r * t + 2.0 * s * t + 4.0 * r * s * t); + dN[14] = 0.0625 * (1.0 + r) * (1.0 - t) + * (1.0 - r + 6.0 * s - 4.0 * r * s + t + r * t + 2.0 * s * t - 4.0 * r * s * t); + dN[15] = -0.0625 * (1.0 + r) * (1.0 - t) + * (1.0 - r - 6.0 * s + 4.0 * r * s + t + r * t - 2.0 * s * t + 4.0 * r * s * t); + dN[16] = -0.0625 * (1.0 - r) * (1.0 - t) + * (1.0 + r - 6.0 * s - 4.0 * r * s + t - r * t - 2.0 * s * t - 4.0 * r * s * t); + dN[17] = 0.0; dN[18] = -0.125 * (1.0 - r * r) * (1.0 - t) * (1.0 + 2.0 * s - t + 2.0 * s * t); dN[19] = -0.25 * (1.0 + r) * s * (1.0 - t) * (2.0 - r - r * t); - dN[20] = 0.125 * (1.0 - r * r) * (1.0 - t) * (1.0 - 2.0 * s - t - 2.0 * s * t); + dN[20] = 0.125 * (1.0 - r * r) * (1.0 - t) * (1.0 - 2.0 * s - t - 2.0 * s * t); dN[21] = -0.25 * (1.0 - r) * s * (1.0 - t) * (2.0 + r + r * t); dN[22] = -0.25 * (1.0 - r) * (1.0 - t * t); dN[23] = -0.25 * (1.0 + r) * (1.0 - t * t); - dN[24] = 0.25 * (1.0 + r) * (1.0 - t * t); - dN[25] = 0.25 * (1.0 - r) * (1.0 - t * t); + dN[24] = 0.25 * (1.0 + r) * (1.0 - t * t); + dN[25] = 0.25 * (1.0 - r) * (1.0 - t * t); //---dN/dt - dN[26] = 0.125 * - (1.0 - r) * (1.0 - s) * (1.0 + r + s + 2.0 * t + r * t + s * t + 2.0 * r * s * t); - dN[27] = 0.125 * - (1.0 + r) * (1.0 - s) * (1.0 - r + s + 2.0 * t - r * t + s * t - 2.0 * r * s * t); - dN[28] = 0.125 * - (1.0 + r) * (1.0 + s) * (1.0 - r - s + 2.0 * t - r * t - s * t + 2.0 * r * s * t); - dN[29] = 0.125 * - (1.0 - r) * (1.0 + s) * (1.0 + r - s + 2.0 * t + r * t - s * t - 2.0 * r * s * t); - dN[30] = 0.5 + t; + dN[26] = 0.125 * (1.0 - r) * (1.0 - s) * (1.0 + r + s + 2.0 * t + r * t + s * t + 2.0 * r * s * t); + dN[27] = 0.125 * (1.0 + r) * (1.0 - s) * (1.0 - r + s + 2.0 * t - r * t + s * t - 2.0 * r * s * t); + dN[28] = 0.125 * (1.0 + r) * (1.0 + s) * (1.0 - r - s + 2.0 * t - r * t - s * t + 2.0 * r * s * t); + dN[29] = 0.125 * (1.0 - r) * (1.0 + s) * (1.0 + r - s + 2.0 * t + r * t - s * t - 2.0 * r * s * t); + dN[30] = 0.5 + t; dN[31] = -0.25 * (1.0 - r * r) * (1.0 - s) * (1.0 + s * t); dN[32] = -0.25 * (1.0 + r) * (1.0 - s * s) * (1.0 - r * t); dN[33] = -0.25 * (1.0 - r * r) * (1.0 + s) * (1.0 - s * t); @@ -5434,8 +5342,7 @@ void GradShapeFunctionPyraHQ13(double* dN, const double* x) Programming: 09/2004 WW Erste Version **************************************************************************/ -double ComputeDetTri(const double* x1, const double* x2, - const double* x3) +double ComputeDetTri(const double* x1, const double* x2, const double* x3) { static double u[3], v[3], z[3]; @@ -5451,7 +5358,7 @@ double ComputeDetTri(const double* x1, const double* x2, z[1] = u[2] * v[0] - u[0] * v[2]; z[2] = u[0] * v[1] - u[1] * v[0]; - return 0.5 * sqrt(z[0] * z[0] + z[1] * z[1] + z[2] * z[2] ); + return 0.5 * sqrt(z[0] * z[0] + z[1] * z[1] + z[2] * z[2]); } /*************************************************************************** @@ -5469,13 +5376,12 @@ double ComputeDetTri(const double* x1, const double* x2, Programming: 09/2004 WW Erste Version **************************************************************************/ -double ComputeDetTex(const double* x1, const double* x2, - const double* x3, const double* x4) +double ComputeDetTex(const double* x1, const double* x2, const double* x3, const double* x4) { - return - fabs((x1[0] - x4[0]) * ((x2[1] - x4[1]) * (x3[2] - x4[2]) - (x2[2] - x4[2]) * (x3[1] - x4[1])) - - (x1[1] - x4[1]) * ((x2[0] - x4[0]) * (x3[2] - x4[2]) - (x2[2] - x4[2]) * (x3[0] - x4[0])) - + (x1[2] - x4[2]) * ((x2[0] - x4[0]) * (x3[1] - x4[1]) - (x2[1] - x4[1]) * (x3[0] - x4[0]))) / 6.0; + return fabs((x1[0] - x4[0]) * ((x2[1] - x4[1]) * (x3[2] - x4[2]) - (x2[2] - x4[2]) * (x3[1] - x4[1])) + - (x1[1] - x4[1]) * ((x2[0] - x4[0]) * (x3[2] - x4[2]) - (x2[2] - x4[2]) * (x3[0] - x4[0])) + + (x1[2] - x4[2]) * ((x2[0] - x4[0]) * (x3[1] - x4[1]) - (x2[1] - x4[1]) * (x3[0] - x4[0]))) + / 6.0; } /************************************************************************** @@ -5488,10 +5394,10 @@ double ComputeDetTex(const double* x1, const double* x2, double NormalizeVector(double* x, size_t n) { double nrm(x[0] * x[0]); - for(size_t i = 1; i < n; i++) + for (size_t i = 1; i < n; i++) nrm += x[i] * x[i]; - double sqrt_nrm (sqrt(nrm)); - for(size_t i = 0; i < n; i++) + double sqrt_nrm(sqrt(nrm)); + for (size_t i = 0; i < n; i++) x[i] /= sqrt_nrm; return sqrt_nrm; } @@ -5519,7 +5425,7 @@ double PointProduction(double* x, double* y) { int i; double nrm = 0.0; - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) nrm += x[i] * y[i]; return nrm; } @@ -5553,7 +5459,7 @@ double MLangevin(double v) void VCopy(double* x, const double* y, const int n) { int i; - for(i = 0; i < n; i++) + for (i = 0; i < n; i++) x[i] = y[i]; } @@ -5583,10 +5489,10 @@ double SuperBee(double v1, double v2) { if (v1 * v2 < 0.0) return 0.0; - //max{min{2|a|, |b|},min{|a|, 2|b|}}. + // max{min{2|a|, |b|},min{|a|, 2|b|}}. double a1 = std::min(2.0 * fabs(v1), fabs(v2)); double a2 = std::min(fabs(v1), 2.0 * fabs(v2)); - double ret = std::max(a1,a2); + double ret = std::max(a1, a2); if (v1 > 0.0) return ret; else diff --git a/FEM/mathlib.h b/FEM/mathlib.h index d32f5ff88..379e722bd 100644 --- a/FEM/mathlib.h +++ b/FEM/mathlib.h @@ -34,7 +34,7 @@ sozusagen durchgeschleift: */ /* #include "matrix_routines.h" */ /* Speichertechnik fuer Matrix des Gesamtgleichungssystems */ -#ifndef NEW_EQS //WW. 11.2008 +#ifndef NEW_EQS // WW. 11.2008 #include "solver.h" #endif /* Iterative GLS-Loeser auf Basis der Speichertechnik aus 'matrix.h' (herkoemmliche Verfahren) */ @@ -46,81 +46,81 @@ Mathematische Funktionen ########################################################################*/ -#ifdef obsolete //01.2011 WW -extern int MGleichDouble (double zahl1, double zahl2,double tol); +#ifdef obsolete // 01.2011 WW +extern int MGleichDouble(double zahl1, double zahl2, double tol); /* MGleichDouble - Vergleicht zwei double-Zahlen unter Beruecksichtigung einer Fehlertoleranz */ -extern int MOmega1D(double* vf,double r); +extern int MOmega1D(double* vf, double r); /* Berechnet 1D Ansatzfunktionen */ -extern int MOmega2D(double* vf,double r, double s); +extern int MOmega2D(double* vf, double r, double s); /* Berechnet 2D Ansatzfunktionen */ -extern int MOmega3D(double* vf,double r, double s, double t); +extern int MOmega3D(double* vf, double r, double s, double t); /* Berechnet 3D Ansatzfunktionen */ //#ifdef obsolete //WW. 11.2008 -extern int MOmega3DTetrahedron(double* vf,double xx,double yy,double zz,long number); -extern int MOmega2DTriangle(double* vf,double r, double s, long number); +extern int MOmega3DTetrahedron(double* vf, double xx, double yy, double zz, long number); +extern int MOmega2DTriangle(double* vf, double r, double s, long number); //#endif /* Berechnet 2D Ansatzfunktionen fuer Dreiecke */ -//extern int MPhi2D(double *vf,double r, double s); +// extern int MPhi2D(double *vf,double r, double s); /* Berechnet 2D Testfunktionen */ -extern int MPhi2D_SUPG(double* vf,double r, double s, double* alpha); +extern int MPhi2D_SUPG(double* vf, double r, double s, double* alpha); /* Berechnet 2D Testfunktionen (SUPG) */ -extern int MPhi3D(double* vf,double r, double s, double t); +extern int MPhi3D(double* vf, double r, double s, double t); /* Berechnet 3D Testfunktionen */ -extern int MPhi3D_SUPG(double* vf,double r, double s, double t, double* alpha); +extern int MPhi3D_SUPG(double* vf, double r, double s, double t, double* alpha); /* Berechnet 3D Testfunktionen (SUPG)*/ -extern int MGradOmega2D(double* vf,double r, double s); +extern int MGradOmega2D(double* vf, double r, double s); /* Berechnet Gradient der 2D Ansatzfunktionen */ -extern int MGradOmega3D(double* vf,double r, double s, double t); +extern int MGradOmega3D(double* vf, double r, double s, double t); /* Berechnet Gradient der 3D Ansatzfunktionen */ -extern int MGradPhi2D(double* vf,double r, double s); +extern int MGradPhi2D(double* vf, double r, double s); /* Berechnet Gradient der 2D Testfunktionen */ -extern int MGradPhi3D(double* vf,double r, double s, double t); +extern int MGradPhi3D(double* vf, double r, double s, double t); /* Faktoren fuer die X Punkt Gauss-Integration */ extern void MGetCoor(int typ, long j, double* r, double* s, double* t); /* lokale Koordinaten der Eckpunkte */ /* MBtrgVec - Betrag von Vektor */ -/* MAngleVectors - Winkel zwischen Vektoren */ /* MB */ +/* MAngleVectors - Winkel zwischen Vektoren */ /* MB */ double MAngleVectors(double* v1, double* v2); /* MNormiere - Normiert Vektoren */ void MNormiere(double* vec, long n); /* M2Determinante - Determinante einer 2x2Matrix */ -extern double M2Determinante ( double* matrix ); +extern double M2Determinante(double* matrix); /* M3Determinante - Determinante einer 3x3Matrix */ -//extern double M3Determinante ( double *m ); +// extern double M3Determinante ( double *m ); /* Mxg2Determinante - Determinante einer beliebigen Matrix mit goesseren Ausmassen als 2x2 */ /* M4Determinante - Determinante einer 4x4Matrix */ -//extern double M4Determinante ( double *m ); -extern double Mxg2Determinante (double* matrix, long m, long n ); +// extern double M4Determinante ( double *m ); +extern double Mxg2Determinante(double* matrix, long m, long n); /* MTranspoVec - Transponieren beliebiger Vektoren */ -extern void MTranspoVec (double* vec, long g); +extern void MTranspoVec(double* vec, long g); /* MTranspoMat - Transponieren beliebiger Matrizen */ -extern void MTranspoMat (double* mat1, long m, long n, double* mat2); +extern void MTranspoMat(double* mat1, long m, long n, double* mat2); /* M2Invertiere - Invertiert 2x2 Matrizen */ -extern void M2Invertiere (double* m); +extern void M2Invertiere(double* m); /* M2InvertiereUndTransponiere - Invertiert und transponiert 2x2 Matrizen */ -extern void M2InvertiereUndTransponiere (double* m); +extern void M2InvertiereUndTransponiere(double* m); /* M3Invertiere - Invertiert 3x3 Matrizen */ -extern void M3Invertiere (double* m); +extern void M3Invertiere(double* m); /* MInvertiere - Invertieren beliebier regulaerer Matrizen */ -extern void MInvertiere (double* matrix, long m, long n); +extern void MInvertiere(double* matrix, long m, long n); /* MAddVektoren - Addition zweier beliebier Vektoren */ -extern int MAddVektoren (double* v1, double* v2, double* vout, long g); +extern int MAddVektoren(double* v1, double* v2, double* vout, long g); /* MAddSkalVektoren - Vektoren mit Skalar multiplizieren und dann addieren */ -//WW extern int MAddSkalVektoren(double *v1, double m1, double *v2, double m2, double *vout, long g); +// WW extern int MAddSkalVektoren(double *v1, double m1, double *v2, double m2, double *vout, long g); /* MAddMatrizen - Addition zweier beliebier Matrizen */ -extern int MAddMatrizen (double* m1, double* m2, double* mout,long m,long n); +extern int MAddMatrizen(double* m1, double* m2, double* mout, long m, long n); /* MMultVecSkalar - Multiplikation Vektor mit Skalarwert */ -extern int MMultVecSkalar (double* vec, double skal, long g); +extern int MMultVecSkalar(double* vec, double skal, long g); /* MMultMatSkalar - Multiplikation Matrix mit Skalarwert */ -extern int MMultMatSkalar (double* matrix, double skal, long m, long n); +extern int MMultMatSkalar(double* matrix, double skal, long m, long n); /* MSkalarprodukt - Skalarprodukt zweier beliebiger Vektoren */ -//extern double MSkalarprodukt ( double *vec1, double *vec2, long g ); +// extern double MSkalarprodukt ( double *vec1, double *vec2, long g ); /* M3KreuzProdukt - Kreuzprodukt von 3D-Vektoren */ -//extern int M3KreuzProdukt( double *vec1, double *vec2 , double *vec); +// extern int M3KreuzProdukt( double *vec1, double *vec2 , double *vec); /*########################################################################## Auf Matrizen und Vektoren aufbauende Funktionen ########################################################################*/ @@ -136,13 +136,13 @@ void MKTFMat3Dr2D(double* vec1, double* vec2, double winkel, double* mat); Prueffunktion fuer Matrix ########################################################################*/ /* MBistDuDiagMat - Prueft auf Diagonalitaet einer Matrix */ -extern int MBistDuDiagMat ( double* matrix, long m, long n ); +extern int MBistDuDiagMat(double* matrix, long m, long n); /*########################################################################## Sortierfunktionen ########################################################################*/ extern void MQSort_LongDouble(void* DataSets, const int NumberOfDataSets, const int SiezeOfDataSet); -extern int MCompare_for_MQSort_LongDouble( const void* arg1, const void* arg2 ); +extern int MCompare_for_MQSort_LongDouble(const void* arg1, const void* arg2); extern double* TensorDrehDich(double* d, double* velo); extern int GetPriMatFromTriMat(double* mat1, double* mat2); @@ -152,13 +152,12 @@ extern int MMultMatMat2(double* mat1, long m1, long n1, double* mat2, double* er eventuell noch nuetzliche Funktionen, die im Moment nicht gebraucht werden ########################################################################*/ -extern double* JWDMMultMatSkalar (double* matrix, - double skal, long m, long n); +extern double* JWDMMultMatSkalar(double* matrix, double skal, long m, long n); -//extern long IsNodeInsideTriangle (long n1, long n2, long n3, long node); -//CC -extern double CalcTriangleArea (long n1, long n2, long n3); -//extern long IsNodeInsidePlain (long n1, long n2, long n3, long node); +// extern long IsNodeInsideTriangle (long n1, long n2, long n3, long node); +// CC +extern double CalcTriangleArea(long n1, long n2, long n3); +// extern long IsNodeInsidePlain (long n1, long n2, long n3, long node); extern int MOmega2D_9N(double* vf, double r, double s); extern int MPhi2D_9N(double* vf, double r, double s); @@ -169,7 +168,7 @@ extern int MOmega3D_20N(double* vf, double r, double s, double t); extern int MPhi3D_20N(double* vf, double r, double s, double t); extern int MGradOmega3D_20N(double* vf, double r, double s, double t); extern int MGradPhi3D_20N(double* vf, double r, double s, double t); -#endif // 05.03.2010. WW //#ifdef obsolete +#endif // 05.03.2010. WW //#ifdef obsolete /* Ermittelt min */ extern double MMin(double, double); @@ -179,89 +178,80 @@ extern double MMax(double, double); extern double MRange(double a, double b, double c); double MBtrgVec(double* vec, long n); -#ifndef NEW_EQS //WW. 05.03.2010 +#ifndef NEW_EQS // WW. 05.03.2010 /*########################################################################## Funktionen fuer Gleichungsloeser (CG) ########################################################################*/ -extern double MVekNorm1 ( double* x, long n ); +extern double MVekNorm1(double* x, long n); /* Spaltensummennorm */ -extern double MVekNorm2 ( double* x, long n ); +extern double MVekNorm2(double* x, long n); /* Euklidische Norm */ -//WW extern double MVekNormMax ( double *x, long n ); +// WW extern double MVekNormMax ( double *x, long n ); /* Maximumnorm */ -extern void MVekSum ( double* x, double alpha, double* y, long n ); +extern void MVekSum(double* x, double alpha, double* y, long n); /* Fuehrt die Operation x = x + alpha * y durch; n: Vektordimension */ -extern void MVekGle ( double alpha, double* x, double beta, double* y, - double* z, long n ); +extern void MVekGle(double alpha, double* x, double beta, double* y, double* z, long n); /* Fuehrt die Operation z = alpha * x + beta * y durch; n: Vektordimension */ -extern double MVekDist ( double* x, double* y, long n ); +extern double MVekDist(double* x, double* y, long n); /* Abstand zwischen zwei Vektoren */ /*########################################################################## Bearbeitungsfunktionen ########################################################################*/ /* MMachVec - Erzeugt einen Vektor */ -extern double* MMachVec (long g); +extern double* MMachVec(long g); /* MNullVec - Fuellt einen Vektor mit Nullen */ -extern void MNullVec (double*, long); +extern void MNullVec(double*, long); /* MLoeschVec - Loescht einen Vektor */ -//WW extern void MLoeschVec (double *vec); +// WW extern void MLoeschVec (double *vec); /* MKopierVec - Kopiert einen Vektor auf einen Anderen */ -extern void MKopierVec (double* vecquelle, double* vecziel, long g); +extern void MKopierVec(double* vecquelle, double* vecziel, long g); /* MMachMat - Erzeugt einer Matrix */ -//WW extern double *MMachMat (long m, long n); +// WW extern double *MMachMat (long m, long n); /* MNullMat - Fuellt eine Matrix mit Nullen*/ -//WW extern void MNullMat (double *,long , long); +// WW extern void MNullMat (double *,long , long); /* MLoeschMat - Loescht einer Matrix */ -//WW extern void MLoeschMat (double *mat); +// WW extern void MLoeschMat (double *mat); /* MKopierMat - Kopiert eine Matrix auf eine Andere */ -extern void MKopierMat (double* matq, double* matz, long m, long n); +extern void MKopierMat(double* matq, double* matz, long m, long n); /* nur fuer mich!!! hh */ -//extern void MZeigVec (double *vec, long grad, char *text); -//extern void MZeigMat (double *mat, long m, long n, char *text); -//extern void M2FileVec (double *vec, long grad, char *text); +// extern void MZeigVec (double *vec, long grad, char *text); +// extern void MZeigMat (double *mat, long m, long n, char *text); +// extern void M2FileVec (double *vec, long grad, char *text); /* PS: Finger Weg, Michael!!! --> baeeh */ /* MAddSkalVektoren - Vektoren mit Skalar multiplizieren und dann addieren */ extern int MAddSkalVektoren(double* v1, double m1, double* v2, double m2, double* vout, long g); -#endif /////////////////////////// +#endif /////////////////////////// -//WW: Only unsed in a member function of CFiniteElementStd implementated by MB +// WW: Only unsed in a member function of CFiniteElementStd implementated by MB /* MMultVecVec - Multiplikation Vektor mit Vektor */ -extern int MMultVecVec ( double* vec1, long gv1, - double* vec2, long gv2, - double* mato, long mo, long no); +extern int MMultVecVec(double* vec1, long gv1, double* vec2, long gv2, double* mato, long mo, long no); /* MMultVecMat - Multiplikation Vektor mit Matrix */ -extern int MMultVecMat (double* vec, long gv, - double* mat, long m, long n, - double* veco, long go); +extern int MMultVecMat(double* vec, long gv, double* mat, long m, long n, double* veco, long go); /* MMultMatVec - Multiplikation Matrix mit Vektor */ -extern int MMultMatVec ( double* mat, long m, long n, - double* vec, long g, - double* veco, long r); +extern int MMultMatVec(double* mat, long m, long n, double* vec, long g, double* veco, long r); /* MMultMatMat - Multiplikation Matrix mit Matrix */ -extern int MMultMatMat (double* mat1, long m1, long n1, - double* mat2, long m2, long n2, - double* mato, long mo, long no); +extern int MMultMatMat(double* mat1, long m1, long n1, double* mat2, long m2, long n2, double* mato, long mo, long no); /*########################################################################## Geometrie-Funktionen ########################################################################*/ -//extern double MCalcDistancePointToPoint(double *pt1,double *pt2); -extern double MCalcDistancePointToLine(double* pt,double* l1,double* l2); -extern double MCalcProjectionOfPointOnLine(double* pt1,double* pt2,double* pt3,double* pt4); -extern double MCalcDistancePointToPlane(double const* const pt,double* e1,double* e2,double* e3); -//extern double MCalcProjectionOfPointOnPlane(double *pt, double *e1, double *e2, double *e3, double *proj); +// extern double MCalcDistancePointToPoint(double *pt1,double *pt2); +extern double MCalcDistancePointToLine(double* pt, double* l1, double* l2); +extern double MCalcProjectionOfPointOnLine(double* pt1, double* pt2, double* pt3, double* pt4); +extern double MCalcDistancePointToPlane(double const* const pt, double* e1, double* e2, double* e3); +// extern double MCalcProjectionOfPointOnPlane(double *pt, double *e1, double *e2, double *e3, double *proj); /* MNulleVec - Setze angegebenen Vektor = 0.0 */ -extern void MNulleVec (double* vec, long g); +extern void MNulleVec(double* vec, long g); /* MNulleMat - Setze angegebene Matrix = 0.0 */ -extern void MNulleMat (double* vec, long m, long n); +extern void MNulleMat(double* vec, long m, long n); /* Berechnet Gradient der 3D Testfunktionen */ extern double MXPGaussPkt(long grd, long pkt); /* Punkte fuer die X Punkt Gauss-Integration */ extern double MXPGaussFkt(long grd, long pkt); -extern void realCoordTriHQ(double* x, const double* XY, const double* u ); +extern void realCoordTriHQ(double* x, const double* XY, const double* u); // Family of element interpolation. WW extern void ShapeFunctionLine(double* N1, const double* u); @@ -305,26 +295,24 @@ extern void GradShapeFunctionPyraHQ13(double* dN, const double* u); extern double pai; extern long binarySearch(long* arr, long target, long start, long end); -//WW Cubic spline -//WW -double ComputeDetTri(const double* x1, const double* x2, - const double* x3); -double ComputeDetTex(const double* x1, const double* x2, - const double* x3, const double* x4); +// WW Cubic spline +// WW +double ComputeDetTri(const double* x1, const double* x2, const double* x3); +double ComputeDetTex(const double* x1, const double* x2, const double* x3, const double* x4); void CrossProduction(const double* x, const double* y, double* z); double NormalizeVector(double* x, size_t n); -//extern double MVectorlength(double dx, double dy, double dz); +// extern double MVectorlength(double dx, double dy, double dz); extern double PointProduction(double* x, double* y); extern void VCopy(double* x, const double* y, const int n); -//NW +// NW extern double MLangevin(double v); extern double MinMod(double v1, double v2); extern double SuperBee(double v1, double v2); extern double GetFCTADiff(double v1, double v2); -#endif /* gehoert zum Schutz gegen mehrfaches Einfuegen */ +#endif /* gehoert zum Schutz gegen mehrfaches Einfuegen */ /*########################################################################## Ende von: ROCKFLOW - Modul mathlib.h diff --git a/FEM/matrix_class.cpp b/FEM/matrix_class.cpp index 8c715351e..3150ebcab 100644 --- a/FEM/matrix_class.cpp +++ b/FEM/matrix_class.cpp @@ -34,33 +34,31 @@ namespace Math_Group { - -MatrixBase::MatrixBase(size_t rows, size_t cols, size_t size) : - nrows (rows), nrows0 (rows), ncols (cols), ncols0 (cols), - size(size), data(size>0?new double[size]:NULL) +MatrixBase::MatrixBase(size_t rows, size_t cols, size_t size) + : nrows(rows), nrows0(rows), ncols(cols), ncols0(cols), size(size), data(size > 0 ? new double[size] : NULL) { - for(size_t i = 0; i < size; i++) + for (size_t i = 0; i < size; i++) data[i] = 0.0; } -MatrixBase::MatrixBase(const MatrixBase &m) : - nrows (m.nrows), nrows0 (m.nrows0), ncols (m.ncols), ncols0 (m.ncols0), - size(m.size), data(size>0?new double[size]:NULL) +MatrixBase::MatrixBase(const MatrixBase& m) + : nrows(m.nrows), nrows0(m.nrows0), ncols(m.ncols), ncols0(m.ncols0), size(m.size), + data(size > 0 ? new double[size] : NULL) { - for(size_t i = 0; i < size; i++) + for (size_t i = 0; i < size; i++) data[i] = m.data[i]; } MatrixBase::~MatrixBase() { - delete [] data; + delete[] data; data = NULL; } // 06.2010. WW void MatrixBase::ReleaseMemory() { - delete [] data; + delete[] data; data = NULL; } @@ -68,19 +66,20 @@ void MatrixBase::ReleaseMemory() void MatrixBase::multi(const MatrixBase& m, MatrixBase& m_result, double fac) { #ifdef gDEBUG - if(ncols != m.Rows() && nrows != m_result.Rows() && m.Cols() != m_result.Cols()) + if (ncols != m.Rows() && nrows != m_result.Rows() && m.Cols() != m_result.Cols()) { - std::cout << "\n The sizes of the two matrices are not matched" << "\n"; + std::cout << "\n The sizes of the two matrices are not matched" + << "\n"; abort(); } #endif - for(size_t i = 0; i < m_result.Rows(); i++) - for(size_t j = 0; j < m_result.Cols(); j++) + for (size_t i = 0; i < m_result.Rows(); i++) + for (size_t j = 0; j < m_result.Cols(); j++) { // m_result(i,j) = 0.0; - for(size_t k = 0; k < ncols; k++) + for (size_t k = 0; k < ncols; k++) // m_result(i,j) += fac*data[i*ncols+k]*m(k,j); - m_result(i,j) += fac * (*this)(i,k) * m(k,j); + m_result(i, j) += fac * (*this)(i, k) * m(k, j); } } @@ -89,29 +88,29 @@ void MatrixBase::multi(const MatrixBase& m, MatrixBase& m_result, double fac) void MatrixBase::multi(const MatrixBase& m1, const MatrixBase& m2, MatrixBase& m_result) { #ifdef gDEBUG - if(ncols != m1.Rows() && m1.Cols() != m2.Rows() - && m2.Cols() != m_result.Cols() && nrows != m_result.Rows()) + if (ncols != m1.Rows() && m1.Cols() != m2.Rows() && m2.Cols() != m_result.Cols() && nrows != m_result.Rows()) { - std::cout << "\n The sizes of the two matrices are not matched" << "\n"; + std::cout << "\n The sizes of the two matrices are not matched" + << "\n"; abort(); } #endif - for(size_t i = 0; i < m_result.Rows(); i++) - for(size_t j = 0; j < m_result.Cols(); j++) + for (size_t i = 0; i < m_result.Rows(); i++) + for (size_t j = 0; j < m_result.Cols(); j++) { - //m_result(i,j) = 0.0; - for(size_t k = 0; k < ncols; k++) - for(size_t l = 0; l < m2.Rows(); l++) + // m_result(i,j) = 0.0; + for (size_t k = 0; k < ncols; k++) + for (size_t l = 0; l < m2.Rows(); l++) // m_result(i,j) += data[i*ncols+k]*m1(k,l)*m2(l,j); - m_result(i,j) += (*this)(i,k) * m1(k,l) * m2(l,j); + m_result(i, j) += (*this)(i, k) * m1(k, l) * m2(l, j); } } // vec_result = This*vec. vec_result must be initialized void MatrixBase::multi(const double* vec, double* vec_result, double fac) { - for(int i = 0; (size_t)i < nrows; i++) - for(int j = 0; (size_t)j < ncols; j++) - vec_result[i] += fac * (*this)(i,j) * vec[j]; + for (int i = 0; (size_t)i < nrows; i++) + for (int j = 0; (size_t)j < ncols; j++) + vec_result[i] += fac * (*this)(i, j) * vec[j]; } /************************************************************************** @@ -131,7 +130,8 @@ void MatrixBase::Write(std::ostream& os) os << "| "; for (size_t j = 0; j < ncols; j++) os << (*this)(i, j) << " "; - os << "| " << "\n"; + os << "| " + << "\n"; } os << "\n"; } @@ -159,16 +159,15 @@ void MatrixBase::Read_BIN(std::fstream& is) } // Constructors -Matrix::Matrix(size_t rows, size_t cols) : - MatrixBase (rows, cols, rows * cols) -{} +Matrix::Matrix(size_t rows, size_t cols) : MatrixBase(rows, cols, rows * cols) +{ +} -Matrix::Matrix() : - MatrixBase (0, 0, 0) -{} +Matrix::Matrix() : MatrixBase(0, 0, 0) +{ +} -Matrix::Matrix(const Matrix& m) : - MatrixBase (m) +Matrix::Matrix(const Matrix& m) : MatrixBase(m) { } @@ -186,7 +185,7 @@ void Matrix::resize(size_t rows, size_t cols) ncols0 = ncols; size = nrows * ncols; data = new double[size]; - for(size_t i = 0; i < size; i++) + for (size_t i = 0; i < size; i++) data[i] = 0.0; } @@ -198,57 +197,59 @@ Matrix::~Matrix() void Matrix::GetTranspose(Matrix& m) { #ifdef gDEBUG - if(ncols != m.Rows() && nrows != m.Cols()) + if (ncols != m.Rows() && nrows != m.Cols()) { - std::cout << "\n The sizes of the two matrices are not matched" << "\n"; + std::cout << "\n The sizes of the two matrices are not matched" + << "\n"; abort(); } #endif - double *m_data = m.getEntryArray(); - const size_t mrows = m.Rows(); - const size_t mcols = m.Cols(); - for(size_t i = 0; i < mrows; i++) - { - double *row_m_data = &m_data[i * mcols] ; - for(size_t j = 0; j < mcols; j++) - { - row_m_data[j] = data[j*ncols+i]; - } - } + double* m_data = m.getEntryArray(); + const size_t mrows = m.Rows(); + const size_t mcols = m.Cols(); + for (size_t i = 0; i < mrows; i++) + { + double* row_m_data = &m_data[i * mcols]; + for (size_t j = 0; j < mcols; j++) + { + row_m_data[j] = data[j * ncols + i]; + } + } } // m_results = this*m. m_results must be initialized void Matrix::multi(const Matrix& m, Matrix& m_result, double fac) { #ifdef gDEBUG - if(ncols != m.Rows() && nrows != m_result.Rows() && m.Cols() != m_result.Cols()) + if (ncols != m.Rows() && nrows != m_result.Rows() && m.Cols() != m_result.Cols()) { - std::cout << "\n The sizes of the two matrices are not matched" << "\n"; + std::cout << "\n The sizes of the two matrices are not matched" + << "\n"; abort(); } #endif - const double *m_data = m.getEntryArray(); - const size_t mcols = m.Cols(); - double *r_data = m_result.getEntryArray(); - const size_t r_rows = m_result.Rows(); - const size_t r_cols = m_result.Cols(); - - for(size_t i = 0; i < r_rows; i++) - { - const double *row_data = &data[i * ncols] ; - double *r_row_data = &r_data[i * r_cols] ; - for(size_t j = 0; j < r_cols; j++) - { - // r_row_data[j] = 0.0; - double val = 0.; - for(size_t k = 0; k < ncols; k++) - { - val += row_data[k] * m_data[k*mcols + j]; - } - r_row_data[j] += val * fac; - } - } + const double* m_data = m.getEntryArray(); + const size_t mcols = m.Cols(); + double* r_data = m_result.getEntryArray(); + const size_t r_rows = m_result.Rows(); + const size_t r_cols = m_result.Cols(); + + for (size_t i = 0; i < r_rows; i++) + { + const double* row_data = &data[i * ncols]; + double* r_row_data = &r_data[i * r_cols]; + for (size_t j = 0; j < r_cols; j++) + { + // r_row_data[j] = 0.0; + double val = 0.; + for (size_t k = 0; k < ncols; k++) + { + val += row_data[k] * m_data[k * mcols + j]; + } + r_row_data[j] += val * fac; + } + } } // @@ -256,44 +257,45 @@ void Matrix::multi(const Matrix& m, Matrix& m_result, double fac) void Matrix::multi(const Matrix& m1, const Matrix& m2, Matrix& m_result) { #ifdef gDEBUG - if(ncols != m1.Rows() && m1.Cols() != m2.Rows() - && m2.Cols() != m_result.Cols() && nrows != m_result.Rows()) + if (ncols != m1.Rows() && m1.Cols() != m2.Rows() && m2.Cols() != m_result.Cols() && nrows != m_result.Rows()) { - std::cout << "\n The sizes of the two matrices are not matched" << "\n"; + std::cout << "\n The sizes of the two matrices are not matched" + << "\n"; abort(); } #endif - for(size_t i = 0; i < m_result.Rows(); i++) - for(size_t j = 0; j < m_result.Cols(); j++) + for (size_t i = 0; i < m_result.Rows(); i++) + for (size_t j = 0; j < m_result.Cols(); j++) { - //m_result(i,j) = 0.0; - for(size_t k = 0; k < ncols; k++) - for(size_t l = 0; l < m2.Rows(); l++) + // m_result(i,j) = 0.0; + for (size_t k = 0; k < ncols; k++) + for (size_t l = 0; l < m2.Rows(); l++) // m_result(i,j) += data[i*ncols+k]*m1(k,l)*m2(l,j); - m_result(i,j) += (*this)(i,k) * m1(k,l) * m2(l,j); + m_result(i, j) += (*this)(i, k) * m1(k, l) * m2(l, j); } } // vec_result = This*vec. vec_result must be initialized void Matrix::multi(const double* vec, double* vec_result, double fac) { - for(size_t i = 0; i < nrows; i++) - { - double val = 0.; - const double *row_data = &data[i * ncols] ; - for(size_t j = 0; j < ncols; j++) - { - val += row_data[j] * vec[j]; - } - vec_result[i] += fac * val; - } + for (size_t i = 0; i < nrows; i++) + { + double val = 0.; + const double* row_data = &data[i * ncols]; + for (size_t j = 0; j < ncols; j++) + { + val += row_data[j] * vec[j]; + } + vec_result[i] += fac * val; + } } -double& Matrix::operator() (size_t i, size_t j) const +double& Matrix::operator()(size_t i, size_t j) const { #ifdef gDEBUG - if(i >= nrows || j >= ncols) + if (i >= nrows || j >= ncols) { - std::cout << "\n Index exceeds the size of the matrix" << "\n"; + std::cout << "\n Index exceeds the size of the matrix" + << "\n"; abort(); } #endif @@ -302,9 +304,10 @@ double& Matrix::operator() (size_t i, size_t j) const void Matrix::LimitSize(size_t nRows, size_t nCols) { #ifdef gDEBUG - if(nRows > nrows0 || nCols > ncols0) + if (nRows > nrows0 || nCols > ncols0) { - std::cout << "\n Given size exceeds the original size of the matrix" << "\n"; + std::cout << "\n Given size exceeds the original size of the matrix" + << "\n"; abort(); } #endif @@ -315,12 +318,11 @@ void Matrix::LimitSize(size_t nRows, size_t nCols) //----------------------------------------------------- // Symmetrical matrix -SymMatrix::SymMatrix(size_t dim) : - MatrixBase(dim, dim, (size_t)dim * (dim + 1) / 2) +SymMatrix::SymMatrix(size_t dim) : MatrixBase(dim, dim, (size_t)dim * (dim + 1) / 2) { } -SymMatrix::SymMatrix() : MatrixBase(0,0,0) +SymMatrix::SymMatrix() : MatrixBase(0, 0, 0) { } SymMatrix::SymMatrix(const SymMatrix& m) : MatrixBase(m) @@ -336,7 +338,7 @@ void SymMatrix::resize(size_t dim) } nrows = ncols = dim; - size = (int) nrows * (nrows + 1) / 2; + size = (int)nrows * (nrows + 1) / 2; data = new double[size]; nrows0 = ncols0 = dim; for (size_t i = 0; i < size; i++) @@ -347,9 +349,10 @@ void SymMatrix::resize(size_t dim) void SymMatrix::LimitSize(size_t dim) { #ifdef gDEBUG - if(dim > nrows0) + if (dim > nrows0) { - std::cout << "\n Given size exceeds the original size of the matrix" << "\n"; + std::cout << "\n Given size exceeds the original size of the matrix" + << "\n"; abort(); } #endif @@ -361,36 +364,37 @@ void SymMatrix::LimitSize(size_t dim) void SymMatrix::multi(const SymMatrix& m, Matrix& m_result, double fac) { #ifdef gDEBUG - if(ncols != m.Rows() && nrows != m_result.Rows() && m.Cols() != m_result.Cols()) + if (ncols != m.Rows() && nrows != m_result.Rows() && m.Cols() != m_result.Cols()) { - std::cout << "\n The sizes of the two matrices are not matched" << "\n"; + std::cout << "\n The sizes of the two matrices are not matched" + << "\n"; abort(); } #endif - double *r_data = m_result.getEntryArray(); - const size_t r_rows = m_result.Rows(); - const size_t r_cols = m_result.Cols(); - - for(size_t i = 0; i < r_rows; i++) - { - const double *row_data = &data[(i * (i + 1) / 2)] ; - double *row_data_r = &r_data[i * r_cols] ; - - for(size_t j = 0; j(i * (i + 1) / 2)] ; - for(size_t j = 0; j <= i; j++) - { - val += row_data[j] * vec[j]; - } + const double* row_data = &data[static_cast(i * (i + 1) / 2)]; + for (size_t j = 0; j <= i; j++) + { + val += row_data[j] * vec[j]; + } - for(size_t j = i+1; j < ncols; j++) - { - val += data[static_cast(j * (j + 1) / 2) + i] * vec[j]; - } + for (size_t j = i + 1; j < ncols; j++) + { + val += data[static_cast(j * (j + 1) / 2) + i] * vec[j]; + } - vec_result[i] += fac * val; - } + vec_result[i] += fac * val; + } } //----------------------------------------------------- // Diagonal matrix -DiagonalMatrix::DiagonalMatrix(size_t dim) : MatrixBase(dim,dim,dim) +DiagonalMatrix::DiagonalMatrix(size_t dim) : MatrixBase(dim, dim, dim) { dummy_zero = 0.0; } -DiagonalMatrix::DiagonalMatrix() : MatrixBase(0,0,0) +DiagonalMatrix::DiagonalMatrix() : MatrixBase(0, 0, 0) { dummy_zero = 0.0; } @@ -466,9 +470,9 @@ DiagonalMatrix::DiagonalMatrix(const DiagonalMatrix& m) : MatrixBase(m) void DiagonalMatrix::resize(size_t dim) { - if(size > 0) + if (size > 0) { - delete [] data; + delete[] data; data = NULL; } @@ -476,16 +480,17 @@ void DiagonalMatrix::resize(size_t dim) size = dim; data = new double[size]; nrows0 = ncols0 = dim; - for(size_t i = 0; i < size; i++) + for (size_t i = 0; i < size; i++) data[i] = 0.0; } void DiagonalMatrix::LimitSize(size_t dim) { #ifdef gDEBUG - if(dim > nrows0) + if (dim > nrows0) { - cout << "\n Given size exceeds the original size of the matrix" << "\n"; + cout << "\n Given size exceeds the original size of the matrix" + << "\n"; abort(); } #endif @@ -500,9 +505,9 @@ void DiagonalMatrix::LimitSize(size_t dim) programming: 05/2005 WW ==========================================================================*/ -//1. -template vec::vec(int argSize) : - _size(argSize), _entry (new T[argSize]) +// 1. +template +vec::vec(int argSize) : _size(argSize), _entry(new T[argSize]) { #ifdef gDEBUG if (!_entry) @@ -513,8 +518,8 @@ template vec::vec(int argSize) : #endif } -template vec::vec(const vec& v) : - _size(v.Size()), _entry (new T[v.Size()]) +template +vec::vec(const vec& v) : _size(v.Size()), _entry(new T[v.Size()]) { #ifdef gDEBUG if (!_entry) @@ -527,15 +532,17 @@ template vec::vec(const vec& v) : _entry[i] = v._entry[i]; } -template vec::~vec() +template +vec::~vec() { delete[] _entry; _entry = 0; } -template void vec:: resize(const int argSize) +template +void vec::resize(const int argSize) { - if(_size > 0) + if (_size > 0) { delete[] _entry; _entry = NULL; @@ -551,7 +558,8 @@ template void vec:: resize(const int argSize) #endif } -template void vec:: operator = (const vec& v) +template +void vec::operator=(const vec& v) { #ifdef gDEBUG if (_size != v.Size()) @@ -564,15 +572,16 @@ template void vec:: operator = (const vec& v) _entry[i] = v[i]; } -template void vec:: Write(std::ostream& os) const +template +void vec::Write(std::ostream& os) const { for (size_t i = 0; i < _size; i++) os << _entry[i] << " "; os << "\n"; } -//2. -vec:: vec (const int argSize) : _size(argSize) +// 2. +vec::vec(const int argSize) : _size(argSize) { _entry = new void*[argSize]; #ifdef gDEBUG @@ -584,7 +593,7 @@ vec:: vec (const int argSize) : _size(argSize) #endif } -vec:: vec (const vec& v) +vec::vec(const vec& v) { _size = v.Size(); resize(_size); @@ -605,9 +614,9 @@ vec::~vec() delete[] _entry; _entry = 0; } -void vec:: resize(const int argSize) +void vec::resize(const int argSize) { - if(_size > 0) + if (_size > 0) { delete[] _entry; _entry = NULL; @@ -630,7 +639,7 @@ void vec::Write(std::ostream& os) const os << "\n"; } -void vec:: operator = (const vec& v) +void vec::operator=(const vec& v) { #ifdef gDEBUG if (_size != v.Size()) @@ -643,8 +652,9 @@ void vec:: operator = (const vec& v) _entry[i] = v._entry[i]; } -//3. -template void vec:: operator = (const vec& v) +// 3. +template +void vec::operator=(const vec& v) { #ifdef gDEBUG if (_size != v.Size()) @@ -657,8 +667,7 @@ template void vec:: operator = (const vec& v) _entry[i] = v._entry[i]; } - - //////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////// #ifdef NEW_EQS /*\! ******************************************************************** @@ -671,7 +680,7 @@ template void vec:: operator = (const vec& v) ******************************************************************** */ SparseTable::SparseTable(CFEMesh* a_mesh, bool quadratic, bool symm, StorageType stype) - : symmetry(symm), storage_type(stype) + : symmetry(symm), storage_type(stype) { long i = 0, j = 0, ii = 0, jj = 0; long lbuff0 = 0, lbuff1 = 0; @@ -683,7 +692,7 @@ SparseTable::SparseTable(CFEMesh* a_mesh, bool quadratic, bool symm, StorageType size_entry_column = 0; diag_entry = new long[rows]; - if(storage_type == JDS) + if (storage_type == JDS) { row_index_mapping_n2o = new long[rows]; row_index_mapping_o2n = new long[rows]; @@ -694,12 +703,12 @@ SparseTable::SparseTable(CFEMesh* a_mesh, bool quadratic, bool symm, StorageType row_index_mapping_o2n = NULL; } - if(symmetry) + if (symmetry) { larraybuffer = new long*[rows]; - for(i = 0; i < rows; i++) + for (i = 0; i < rows; i++) { - if(storage_type == JDS) + if (storage_type == JDS) row_index_mapping_n2o[i] = i; // 'diag_entry' used as a temporary array // to store the number of nodes connected to this node @@ -707,21 +716,20 @@ SparseTable::SparseTable(CFEMesh* a_mesh, bool quadratic, bool symm, StorageType larraybuffer[i] = new long[lbuff1 + 1]; // larraybuffer[i][0] = lbuff1; - for(j = 0; j < lbuff1; j++) - larraybuffer[i][j + - 1] = a_mesh->nod_vector[i]->getConnectedNodes()[j]; + for (j = 0; j < lbuff1; j++) + larraybuffer[i][j + 1] = a_mesh->nod_vector[i]->getConnectedNodes()[j]; a_mesh->nod_vector[i]->getConnectedNodes().clear(); - for(j = 0; j < lbuff1; j++) + for (j = 0; j < lbuff1; j++) { jj = larraybuffer[i][j + 1]; - if(i <= jj) + if (i <= jj) a_mesh->nod_vector[i]->getConnectedNodes().push_back(jj); } } } /// CRS storage - if(storage_type == CRS) + if (storage_type == CRS) { /// num_column_entries saves vector ptr of CRS num_column_entries = new long[rows + 1]; @@ -729,19 +737,19 @@ SparseTable::SparseTable(CFEMesh* a_mesh, bool quadratic, bool symm, StorageType std::vector A_index; long col_index; - for(i = 0; i < rows; i++) + for (i = 0; i < rows; i++) { num_column_entries[i] = (long)A_index.size(); - for(j = 0; j < (long)a_mesh->nod_vector[i]->getConnectedNodes().size(); j++) + for (j = 0; j < (long)a_mesh->nod_vector[i]->getConnectedNodes().size(); j++) { col_index = a_mesh->nod_vector[i]->getConnectedNodes()[j]; /// If linear element is used - if((!quadratic) && (col_index >= rows)) + if ((!quadratic) && (col_index >= rows)) continue; - if(i == col_index) + if (i == col_index) diag_entry[i] = (long)A_index.size(); A_index.push_back(col_index); } @@ -751,26 +759,25 @@ SparseTable::SparseTable(CFEMesh* a_mesh, bool quadratic, bool symm, StorageType num_column_entries[rows] = size_entry_column; entry_column = new long[size_entry_column]; - for(i = 0; i < size_entry_column; i++) + for (i = 0; i < size_entry_column; i++) entry_column[i] = A_index[i]; } - else if(storage_type == JDS) + else if (storage_type == JDS) { // //--- Sort, from that has maximum connect nodes to that has minimum connect nodes // - for(i = 0; i < rows; i++) + for (i = 0; i < rows; i++) { row_index_mapping_n2o[i] = i; // 'diag_entry' used as a temporary array // to store the number of nodes connected to this node diag_entry[i] = (long)a_mesh->nod_vector[i]->getConnectedNodes().size(); - if(!quadratic) + if (!quadratic) { lbuff0 = 0; - for(j = 0; j < diag_entry[i]; j++) - if(a_mesh->nod_vector[i]->getConnectedNodes()[j] < - static_cast(rows)) + for (j = 0; j < diag_entry[i]; j++) + if (a_mesh->nod_vector[i]->getConnectedNodes()[j] < static_cast(rows)) lbuff0++; diag_entry[i] = lbuff0; } @@ -778,14 +785,14 @@ SparseTable::SparseTable(CFEMesh* a_mesh, bool quadratic, bool symm, StorageType } // - for(i = 0; i < rows; i++) + for (i = 0; i < rows; i++) { // 'diag_entry' used as a temporary array // to store the number of nodes connected to this node lbuff0 = diag_entry[i]; // Nodes to this row lbuff1 = row_index_mapping_n2o[i]; j = i; - while((j > 0) && (diag_entry[j - 1] < lbuff0)) + while ((j > 0) && (diag_entry[j - 1] < lbuff0)) { diag_entry[j] = diag_entry[j - 1]; row_index_mapping_n2o[j] = row_index_mapping_n2o[j - 1]; @@ -795,7 +802,7 @@ SparseTable::SparseTable(CFEMesh* a_mesh, bool quadratic, bool symm, StorageType row_index_mapping_n2o[j] = lbuff1; } // Old index to new one - for(i = 0; i < rows; i++) + for (i = 0; i < rows; i++) row_index_mapping_o2n[row_index_mapping_n2o[i]] = i; // Maximum number of columns in the sparse table max_columns = diag_entry[0]; @@ -829,7 +836,7 @@ SparseTable::SparseTable(CFEMesh* a_mesh, bool quadratic, bool symm, StorageType // Till to this stage, 'diag_entry' is really used to store indices of the diagonal entries. // Hereby, 'index' refers to the index in entry_column array. - if(ii == jj) + if (ii == jj) diag_entry[ii] = lbuff0; // lbuff0++; @@ -837,23 +844,22 @@ SparseTable::SparseTable(CFEMesh* a_mesh, bool quadratic, bool symm, StorageType } // For the case of symmetry matrix - if(symmetry) + if (symmetry) { - for(i = 0; i < rows; i++) + for (i = 0; i < rows; i++) { lbuff0 = larraybuffer[i][0]; a_mesh->nod_vector[i]->getConnectedNodes().resize(lbuff0); // - for(j = 0; j < lbuff0; j++) - a_mesh->nod_vector[i]->getConnectedNodes()[j] = - larraybuffer[i][j + 1]; + for (j = 0; j < lbuff0; j++) + a_mesh->nod_vector[i]->getConnectedNodes()[j] = larraybuffer[i][j + 1]; } - for(i = 0; i < rows; i++) + for (i = 0; i < rows; i++) { - delete [] larraybuffer[i]; + delete[] larraybuffer[i]; larraybuffer[i] = 0; } - delete [] larraybuffer; + delete[] larraybuffer; larraybuffer = 0; } } @@ -863,8 +869,7 @@ SparseTable::SparseTable(CFEMesh* a_mesh, bool quadratic, bool symm, StorageType 12/2007 WW ******************************************************************** */ -SparseTable::SparseTable(CPARDomain &m_dom, bool quadratic, bool symm) : - symmetry(symm) +SparseTable::SparseTable(CPARDomain& m_dom, bool quadratic, bool symm) : symmetry(symm) { long i = 0, j = 0, ii = 0, jj = 0; long lbuff0 = 0, lbuff1 = 0; @@ -877,59 +882,59 @@ SparseTable::SparseTable(CPARDomain &m_dom, bool quadratic, bool symm) : row_index_mapping_o2n = new long[rows]; diag_entry = new long[rows]; - if(symmetry) + if (symmetry) { std::vector conc; - for(i = 0; i < rows; i++) + for (i = 0; i < rows; i++) { row_index_mapping_n2o[i] = i; // 'diag_entry' used as a temporary array // to store the number of nodes connected to this node lbuff1 = m_dom.num_nodes2_node[i]; // - for(j = 0; j < lbuff1; j++) + for (j = 0; j < lbuff1; j++) { jj = m_dom.node_conneted_nodes[i][j]; - if(i <= jj) + if (i <= jj) conc.push_back(jj); m_dom.node_conneted_nodes[i][j] = 0; } // Number of nodes connected to this node. m_dom.num_nodes2_node[i] = (long)conc.size(); // New - for(j = 0; j < m_dom.num_nodes2_node[i]; j++) - m_dom.node_conneted_nodes[i][j] = conc[j]; + for (j = 0; j < m_dom.num_nodes2_node[i]; j++) + m_dom.node_conneted_nodes[i][j] = conc[j]; } } // //--- Sort, from that has maximum connect nodes to that has minimum connect nodes // - for(i = 0; i < rows; i++) + for (i = 0; i < rows; i++) { row_index_mapping_n2o[i] = i; // 'diag_entry' used as a temporary array // to store the number of nodes connected to this node - diag_entry[i] = m_dom.num_nodes2_node[i]; - if(!quadratic) + diag_entry[i] = m_dom.num_nodes2_node[i]; + if (!quadratic) { lbuff0 = 0; - for(j = 0; j < diag_entry[i]; j++) - if(m_dom.node_conneted_nodes[i][j] < rows) + for (j = 0; j < diag_entry[i]; j++) + if (m_dom.node_conneted_nodes[i][j] < rows) lbuff0++; diag_entry[i] = lbuff0; } size_entry_column += diag_entry[i]; } // - for(i = 0; i < rows; i++) + for (i = 0; i < rows; i++) { // 'diag_entry' used as a temporary array // to store the number of nodes connected to this node - lbuff0 = diag_entry[i]; // Nodes to this row + lbuff0 = diag_entry[i]; // Nodes to this row lbuff1 = row_index_mapping_n2o[i]; j = i; - while((j > 0) && (diag_entry[j - 1] < lbuff0)) + while ((j > 0) && (diag_entry[j - 1] < lbuff0)) { diag_entry[j] = diag_entry[j - 1]; row_index_mapping_n2o[j] = row_index_mapping_n2o[j - 1]; @@ -939,7 +944,7 @@ SparseTable::SparseTable(CPARDomain &m_dom, bool quadratic, bool symm) : row_index_mapping_n2o[j] = lbuff1; } // Old index to new one - for(i = 0; i < rows; i++) + for (i = 0; i < rows; i++) row_index_mapping_o2n[row_index_mapping_n2o[i]] = i; // Maximum number of columns in the sparse table max_columns = diag_entry[0]; @@ -970,7 +975,7 @@ SparseTable::SparseTable(CPARDomain &m_dom, bool quadratic, bool symm) : entry_column[lbuff0] = jj; // Till to this stage, 'diag_entry' is really used to store indices of the diagonal entries. // Hereby, 'index' refers to the index in entry_column array. - if(ii == jj) + if (ii == jj) diag_entry[ii] = lbuff0; // lbuff0++; @@ -983,17 +988,19 @@ SparseTable::SparseTable(CPARDomain &m_dom, bool quadratic, bool symm) : 10/2007 WW 5/2011 WW CRS storage ********************************************************************/ -void SparseTable::Write(std::ostream &os) +void SparseTable::Write(std::ostream& os) { long i, k, counter = 0; os.width(10); os << "Symmetry: " << symmetry << "\n"; - os << "\n*** Row index " << "\n"; + os << "\n*** Row index " + << "\n"; - if(storage_type == CRS) + if (storage_type == CRS) { - os << "\n*** Sparse entry " << "\n"; + os << "\n*** Sparse entry " + << "\n"; for (i = 0; i < rows; i++) { for (k = num_column_entries[i]; k < num_column_entries[i + 1]; k++) @@ -1001,12 +1008,13 @@ void SparseTable::Write(std::ostream &os) os << "\n"; } } - else if(storage_type == JDS) + else if (storage_type == JDS) { for (i = 0; i < rows; i++) os << row_index_mapping_n2o[i] + 1 << "\n"; // - os << "\n*** Sparse entry " << "\n"; + os << "\n*** Sparse entry " + << "\n"; for (k = 0; k < max_columns; k++) { os << "--Column: " << k + 1 << "\n"; @@ -1029,16 +1037,16 @@ void SparseTable::Write(std::ostream &os) ********************************************************************/ SparseTable::~SparseTable() { - if(entry_column) - delete [] entry_column; - if(num_column_entries) - delete [] num_column_entries; - if(row_index_mapping_n2o) - delete [] row_index_mapping_n2o; - if(row_index_mapping_o2n) - delete [] row_index_mapping_o2n; - if(diag_entry) - delete [] diag_entry; + if (entry_column) + delete[] entry_column; + if (num_column_entries) + delete[] num_column_entries; + if (row_index_mapping_n2o) + delete[] row_index_mapping_n2o; + if (row_index_mapping_o2n) + delete[] row_index_mapping_o2n; + if (diag_entry) + delete[] diag_entry; entry_column = NULL; num_column_entries = NULL; row_index_mapping_n2o = NULL; @@ -1055,14 +1063,13 @@ SparseTable::~SparseTable() 10/2007 WW 02/2008 PCH Compressed Row Storage ********************************************************************/ -CSparseMatrix::CSparseMatrix(const SparseTable &sparse_table, const int dof) - : DOF(dof) +CSparseMatrix::CSparseMatrix(const SparseTable& sparse_table, const int dof) : DOF(dof) { symmetry = sparse_table.symmetry; size_entry_column = sparse_table.size_entry_column; max_columns = sparse_table.max_columns; rows = sparse_table.rows; - storage_type = sparse_table.storage_type; //WW + storage_type = sparse_table.storage_type; // WW // Topology mapping from data array to matrix // Only refer address entry_column = sparse_table.entry_column; @@ -1074,31 +1081,31 @@ CSparseMatrix::CSparseMatrix(const SparseTable &sparse_table, const int dof) entry = new double[dof * dof * size_entry_column + 1]; entry[dof * dof * size_entry_column] = 0.; zero_e = 0.; - // -#if defined(LIS) || defined(MKL) // PCH +// +#if defined(LIS) || defined(MKL) // PCH int counter, counter_ptr = 0, counter_col_idx = 0; - int i,k,ii,jj,J,K; + int i, k, ii, jj, J, K; int row_in_sparse_table; - ptr = new int [rows * dof + 1]; - col_idx = new int [dof * dof * size_entry_column]; - entry_index = new int [dof * dof * size_entry_column]; + ptr = new int[rows * dof + 1]; + col_idx = new int[dof * dof * size_entry_column]; + entry_index = new int[dof * dof * size_entry_column]; - for(ii = 0; ii < DOF; ii++) - for(i = 0; i < rows; i++) + for (ii = 0; ii < DOF; ii++) + for (i = 0; i < rows; i++) { // Store ptr arrary for CRS ptr[i + rows * ii] = counter_ptr; row_in_sparse_table = row_index_mapping_o2n[i]; - for(jj = 0; jj < DOF; jj++) + for (jj = 0; jj < DOF; jj++) { counter = row_in_sparse_table; for (k = 0; k < max_columns; k++) { - if(row_in_sparse_table < num_column_entries[k]) + if (row_in_sparse_table < num_column_entries[k]) { - //I = ii * rows + i; // row in global matrix - // column in global matrix + // I = ii * rows + i; // row in global matrix + // column in global matrix J = jj * rows + entry_column[counter]; K = (ii * DOF + jj) * size_entry_column + counter; @@ -1126,15 +1133,15 @@ CSparseMatrix::CSparseMatrix(const SparseTable &sparse_table, const int dof) ********************************************************************/ CSparseMatrix::~CSparseMatrix() { - delete [] entry; + delete[] entry; entry = NULL; -#if defined(LIS) || defined(MKL) // PCH - delete [] ptr; +#if defined(LIS) || defined(MKL) // PCH + delete[] ptr; ptr = NULL; - delete [] col_idx; + delete[] col_idx; col_idx = NULL; - delete [] entry_index; + delete[] entry_index; entry_index = NULL; #endif } @@ -1145,20 +1152,21 @@ CSparseMatrix::~CSparseMatrix() 10/2007 WW 5/2011 WW CRS storage ********************************************************************/ -double& CSparseMatrix::operator() (const long i, const long j) const +double& CSparseMatrix::operator()(const long i, const long j) const { #ifdef gDEBUG - if(i >= rows * DOF || j >= rows * DOF) + if (i >= rows * DOF || j >= rows * DOF) { - std::cout << "\n Index exceeds the dimension of the matrix" << "\n"; + std::cout << "\n Index exceeds the dimension of the matrix" + << "\n"; abort(); } #endif long ii, jj, ir, jr, k; ii = i; jj = j; - if(symmetry) - if(i > j) + if (symmetry) + if (i > j) { ii = j; jj = i; @@ -1170,35 +1178,31 @@ double& CSparseMatrix::operator() (const long i, const long j) const // k = -1; - if(storage_type == JDS) + if (storage_type == JDS) { long row_in_parse_table, counter; row_in_parse_table = row_index_mapping_o2n[ir]; counter = row_in_parse_table; for (k = 0; k < max_columns; k++) { - if(row_in_parse_table >= num_column_entries[k]) + if (row_in_parse_table >= num_column_entries[k]) return zero_e; - if(entry_column[counter] == jr) - break; // Found the entry + if (entry_column[counter] == jr) + break; // Found the entry counter += num_column_entries[k]; } - if(counter >= size_entry_column) + if (counter >= size_entry_column) return zero_e; // Zero entry; k = (ii * DOF + jj) * size_entry_column + counter; } - else if(storage_type == CRS) + else if (storage_type == CRS) { /// Left boundary of this row: num_column_entries[ir] /// Right boundary of this row: num_column_entries[ir+1] /// Search target is jr - k = - binarySearch(entry_column, - jr, - num_column_entries[ir], - num_column_entries[ir + 1]); - if(k == -1) + k = binarySearch(entry_column, jr, num_column_entries[ir], num_column_entries[ir + 1]); + if (k == -1) return zero_e; k = (ii * DOF + jj) * size_entry_column + k; @@ -1212,10 +1216,10 @@ double& CSparseMatrix::operator() (const long i, const long j) const 08/2007 WW 10/2007 WW ********************************************************************/ -void CSparseMatrix::operator = (const double a) +void CSparseMatrix::operator=(const double a) { long size = DOF * DOF * size_entry_column; - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) entry[i] = a; } /*\! @@ -1224,10 +1228,10 @@ void CSparseMatrix::operator = (const double a) 08/2007 WW 10/2007 WW ********************************************************************/ -void CSparseMatrix::operator *= (const double a) +void CSparseMatrix::operator*=(const double a) { long size = DOF * DOF * size_entry_column; - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) entry[i] *= a; } /*\! @@ -1236,10 +1240,10 @@ void CSparseMatrix::operator *= (const double a) 08/2007 WW 10/2007 WW ********************************************************************/ -void CSparseMatrix::operator += (const double a) +void CSparseMatrix::operator+=(const double a) { long size = DOF * DOF * size_entry_column; - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) entry[i] += a; } /*\! @@ -1248,17 +1252,18 @@ void CSparseMatrix::operator += (const double a) 08/2007 WW 10/2007 WW ********************************************************************/ -void CSparseMatrix::operator = (const CSparseMatrix& m) +void CSparseMatrix::operator=(const CSparseMatrix& m) { long size = DOF * DOF * size_entry_column; #ifdef gDEBUG - if(size != m.DOF * m.DOF * m.size_entry_column) + if (size != m.DOF * m.DOF * m.size_entry_column) { - std::cout << "\n Dimensions of two matrices do not match" << "\n"; + std::cout << "\n Dimensions of two matrices do not match" + << "\n"; abort(); } #endif - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) entry[i] = m.entry[i]; } /*\! @@ -1267,17 +1272,18 @@ void CSparseMatrix::operator = (const CSparseMatrix& m) 08/2007 WW 10/2007 WW ********************************************************************/ -void CSparseMatrix::operator += (const CSparseMatrix& m) +void CSparseMatrix::operator+=(const CSparseMatrix& m) { long size = DOF * DOF * size_entry_column; #ifdef gDEBUG - if(size != m.DOF * m.DOF * m.size_entry_column) + if (size != m.DOF * m.DOF * m.size_entry_column) { - std::cout << "\n Dimensions of two matrices do not match" << "\n"; + std::cout << "\n Dimensions of two matrices do not match" + << "\n"; abort(); } #endif - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) entry[i] += m.entry[i]; } /*\! @@ -1286,17 +1292,18 @@ void CSparseMatrix::operator += (const CSparseMatrix& m) 08/2007 WW 10/2007 WW ********************************************************************/ -void CSparseMatrix::operator -= (const CSparseMatrix& m) +void CSparseMatrix::operator-=(const CSparseMatrix& m) { long size = DOF * DOF * size_entry_column; #ifdef gDEBUG - if(size != m.DOF * m.DOF * m.size_entry_column) + if (size != m.DOF * m.DOF * m.size_entry_column) { - std::cout << "\n Dimensions of two matrices do not match" << "\n"; + std::cout << "\n Dimensions of two matrices do not match" + << "\n"; abort(); } #endif - for(long i = 0; i < size; i++) + for (long i = 0; i < size; i++) entry[i] -= m.entry[i]; } /*\! @@ -1306,49 +1313,43 @@ void CSparseMatrix::operator -= (const CSparseMatrix& m) 10/2007 WW 03/2011 WW CRS ********************************************************************/ -void CSparseMatrix::Write(std::ostream &os) +void CSparseMatrix::Write(std::ostream& os) { // long i, k, ii, jj, row_in_parse_table, counter; - os << "*** Non-zero entries of matrix: " << "\n"; + os << "*** Non-zero entries of matrix: " + << "\n"; os.width(14); os.precision(8); // - if(storage_type == CRS ) - for(ii = 0; ii < DOF; ii++) - for(i = 0; i < rows; i++) - for(jj = 0; jj < DOF; jj++) - for (k = num_column_entries[i]; - k < num_column_entries[i + 1]; k++) -//TEST + if (storage_type == CRS) + for (ii = 0; ii < DOF; ii++) + for (i = 0; i < rows; i++) + for (jj = 0; jj < DOF; jj++) + for (k = num_column_entries[i]; k < num_column_entries[i + 1]; k++) + // TEST // if(fabs(entry[(ii*DOF+jj)*size_entry_column+counter])>DBL_MIN) //DBL_EPSILON) - os << std::setw(10) << ii * rows + i << " " - << std::setw(10) << jj * rows + entry_column[k] << " " - << std::setw(15) << - entry[(ii * DOF + jj) * size_entry_column + k] << "\n"; + os << std::setw(10) << ii * rows + i << " " << std::setw(10) << jj * rows + entry_column[k] + << " " << std::setw(15) << entry[(ii * DOF + jj) * size_entry_column + k] << "\n"; - else if(storage_type == JDS ) + else if (storage_type == JDS) { - for(ii = 0; ii < DOF; ii++) - for(i = 0; i < rows; i++) + for (ii = 0; ii < DOF; ii++) + for (i = 0; i < rows; i++) { row_in_parse_table = row_index_mapping_o2n[i]; - for(jj = 0; jj < DOF; jj++) + for (jj = 0; jj < DOF; jj++) { counter = row_in_parse_table; for (k = 0; k < max_columns; k++) { - if(row_in_parse_table < num_column_entries[k]) + if (row_in_parse_table < num_column_entries[k]) { -//TEST + // TEST // if(fabs(entry[(ii*DOF+jj)*size_entry_column+counter])>DBL_MIN) //DBL_EPSILON) - os << std::setw(10) << ii * rows + i << " " - << std::setw(10) << jj * rows + - entry_column[counter] << " " - << std::setw(15) << - entry[(ii * DOF + - jj) * size_entry_column + - counter] << "\n"; + os << std::setw(10) << ii * rows + i << " " << std::setw(10) + << jj * rows + entry_column[counter] << " " << std::setw(15) + << entry[(ii * DOF + jj) * size_entry_column + counter] << "\n"; counter += num_column_entries[k]; } else @@ -1364,17 +1365,17 @@ void CSparseMatrix::Write(std::ostream &os) 03.2011. WW */ -void CSparseMatrix::Write_BIN(std::ostream &os) +void CSparseMatrix::Write_BIN(std::ostream& os) { - if(storage_type == JDS ) + if (storage_type == JDS) return; // - if(DOF == 1) + if (DOF == 1) { - os.write((char*) &rows, sizeof(long)); - os.write((char*) num_column_entries, (rows + 1) * sizeof(long)); - os.write((char*) entry_column, num_column_entries[rows] * sizeof(long)); - os.write((char*) entry, num_column_entries[rows] * sizeof(double)); + os.write((char*)&rows, sizeof(long)); + os.write((char*)num_column_entries, (rows + 1) * sizeof(long)); + os.write((char*)entry_column, num_column_entries[rows] * sizeof(long)); + os.write((char*)entry, num_column_entries[rows] * sizeof(double)); } else { @@ -1390,32 +1391,29 @@ void CSparseMatrix::Write_BIN(std::ostream &os) long counter = 0; - for(ii = 0; ii < DOF; ii++) - for(i = 0; i < rows; i++) + for (ii = 0; ii < DOF; ii++) + for (i = 0; i < rows; i++) { ptr[ii * rows + i] = counter; - for(jj = 0; jj < DOF; jj++) - for (k = num_column_entries[i]; - k < num_column_entries[i + 1]; k++) + for (jj = 0; jj < DOF; jj++) + for (k = num_column_entries[i]; k < num_column_entries[i + 1]; k++) { A_index[counter] = jj * rows + entry_column[k]; - A_value[counter] = - entry[(ii * DOF + - jj) * size_entry_column + k]; + A_value[counter] = entry[(ii * DOF + jj) * size_entry_column + k]; counter++; } } ptr[DOF * rows] = counter; ii = DOF * rows; - os.write((char*) &ii, sizeof(long)); - os.write((char*) ptr, (ii + 1) * sizeof(long)); - os.write((char*) A_index, size * sizeof(long)); - os.write((char*) A_value, size * sizeof(double)); - - delete [] ptr; - delete [] A_index; - delete [] A_value; + os.write((char*)&ii, sizeof(long)); + os.write((char*)ptr, (ii + 1) * sizeof(long)); + os.write((char*)A_index, size * sizeof(long)); + os.write((char*)A_value, size * sizeof(double)); + + delete[] ptr; + delete[] A_index; + delete[] A_value; } } @@ -1430,59 +1428,53 @@ void CSparseMatrix::Write_BIN(std::ostream &os) ********************************************************************/ void CSparseMatrix::multiVec(double* vec_s, double* vec_r) { - long i, j, k, ii, jj, kk,ll,idof, jdof, counter; - for(i = 0; i < rows * DOF; i++) + long i, j, k, ii, jj, kk, ll, idof, jdof, counter; + for (i = 0; i < rows * DOF; i++) vec_r[i] = 0.0; // counter = 0; - if(DOF > 1) + if (DOF > 1) { // Although this piece of code can deal with the case // of DOF = 1, we also prepare a special piece of code for // the case of DOF = 1 just for efficiency - if(storage_type == CRS) + if (storage_type == CRS) { /// ptr is num_column_entries for (ii = 0; ii < rows; ii++) - for (j = num_column_entries[ii]; j < num_column_entries[ii + 1]; - j++) + for (j = num_column_entries[ii]; j < num_column_entries[ii + 1]; j++) { jj = entry_column[j]; - for(idof = 0; idof < DOF; idof++) + for (idof = 0; idof < DOF; idof++) { kk = idof * rows + ii; - for(jdof = 0; jdof < DOF; jdof++) + for (jdof = 0; jdof < DOF; jdof++) { ll = jdof * rows + jj; - k = - (idof * DOF + - jdof) * size_entry_column + j; + k = (idof * DOF + jdof) * size_entry_column + j; vec_r[kk] += entry[k] * vec_s[ll]; - if(symmetry & (kk != ll)) + if (symmetry & (kk != ll)) vec_r[ll] += entry[k] * vec_s[kk]; } } } } - else if(storage_type == JDS) + else if (storage_type == JDS) { for (k = 0; k < max_columns; k++) for (i = 0; i < num_column_entries[k]; i++) { ii = row_index_mapping_n2o[i]; jj = entry_column[counter]; - for(idof = 0; idof < DOF; idof++) + for (idof = 0; idof < DOF; idof++) { kk = idof * rows + ii; - for(jdof = 0; jdof < DOF; jdof++) + for (jdof = 0; jdof < DOF; jdof++) { ll = jdof * rows + jj; - j = - (idof * DOF + - jdof) * size_entry_column + - counter; + j = (idof * DOF + jdof) * size_entry_column + counter; vec_r[kk] += entry[j] * vec_s[ll]; - if(symmetry & (kk != ll)) + if (symmetry & (kk != ll)) vec_r[ll] += entry[j] * vec_s[kk]; } } @@ -1492,20 +1484,19 @@ void CSparseMatrix::multiVec(double* vec_s, double* vec_r) } else // DOF = 1 { - if(storage_type == CRS) + if (storage_type == CRS) { /// ptr is num_column_entries for (ii = 0; ii < rows; ii++) - for (j = num_column_entries[ii]; j < num_column_entries[ii + 1]; - j++) + for (j = num_column_entries[ii]; j < num_column_entries[ii + 1]; j++) { jj = entry_column[j]; vec_r[ii] += entry[j] * vec_s[jj]; - if(symmetry & (ii != jj)) + if (symmetry & (ii != jj)) vec_r[jj] += entry[j] * vec_s[ii]; } } - else if(storage_type == JDS) + else if (storage_type == JDS) { for (k = 0; k < max_columns; k++) for (i = 0; i < num_column_entries[k]; i++) @@ -1513,7 +1504,7 @@ void CSparseMatrix::multiVec(double* vec_s, double* vec_r) ii = row_index_mapping_n2o[i]; jj = entry_column[counter]; vec_r[ii] += entry[counter] * vec_s[jj]; - if(symmetry & (ii != jj)) + if (symmetry & (ii != jj)) vec_r[jj] += entry[counter] * vec_s[ii]; counter++; } @@ -1531,59 +1522,53 @@ void CSparseMatrix::multiVec(double* vec_s, double* vec_r) ********************************************************************/ void CSparseMatrix::Trans_MultiVec(double* vec_s, double* vec_r) { - long i, j, k, ii, jj, kk,ll,idof, jdof, counter; - for(i = 0; i < rows * DOF; i++) + long i, j, k, ii, jj, kk, ll, idof, jdof, counter; + for (i = 0; i < rows * DOF; i++) vec_r[i] = 0.0; // counter = 0; - if(DOF > 1) + if (DOF > 1) { // Although this piece of code can deal with the case // of DOF = 1, we also prepare a special piece of code for // the case of DOF = 1 just for efficiency - if(storage_type == CRS) + if (storage_type == CRS) { /// ptr is num_column_entries for (ii = 0; ii < rows; ii++) - for (j = num_column_entries[ii]; j < num_column_entries[ii + 1]; - j++) + for (j = num_column_entries[ii]; j < num_column_entries[ii + 1]; j++) { jj = entry_column[j]; - for(idof = 0; idof < DOF; idof++) + for (idof = 0; idof < DOF; idof++) { kk = idof * rows + ii; - for(jdof = 0; jdof < DOF; jdof++) + for (jdof = 0; jdof < DOF; jdof++) { ll = jdof * rows + jj; - k = - (idof * DOF + - jdof) * size_entry_column + j; + k = (idof * DOF + jdof) * size_entry_column + j; vec_r[ll] += entry[k] * vec_s[kk]; - if(symmetry & (kk != ll)) + if (symmetry & (kk != ll)) vec_r[kk] += entry[k] * vec_s[ll]; } } } } - else if(storage_type == JDS) + else if (storage_type == JDS) { for (k = 0; k < max_columns; k++) for (i = 0; i < num_column_entries[k]; i++) { ii = row_index_mapping_n2o[i]; jj = entry_column[counter]; - for(idof = 0; idof < DOF; idof++) + for (idof = 0; idof < DOF; idof++) { kk = idof * rows + ii; - for(jdof = 0; jdof < DOF; jdof++) + for (jdof = 0; jdof < DOF; jdof++) { ll = jdof * rows + jj; - j = - (idof * DOF + - jdof) * size_entry_column + - counter; + j = (idof * DOF + jdof) * size_entry_column + counter; vec_r[ll] += entry[j] * vec_s[kk]; - if(symmetry & (kk != ll)) + if (symmetry & (kk != ll)) vec_r[kk] += entry[j] * vec_s[ll]; } } @@ -1593,20 +1578,19 @@ void CSparseMatrix::Trans_MultiVec(double* vec_s, double* vec_r) } else // DOF = 1 { - if(storage_type == CRS) + if (storage_type == CRS) { /// ptr is num_column_entries for (ii = 0; ii < rows; ii++) - for (j = num_column_entries[ii]; j < num_column_entries[ii + 1]; - j++) + for (j = num_column_entries[ii]; j < num_column_entries[ii + 1]; j++) { jj = entry_column[j]; vec_r[jj] += entry[j] * vec_s[ii]; - if(symmetry & (ii != jj)) + if (symmetry & (ii != jj)) vec_r[ii] += entry[j] * vec_s[jj]; } } - else if(storage_type == JDS) + else if (storage_type == JDS) { for (k = 0; k < max_columns; k++) for (i = 0; i < num_column_entries[k]; i++) @@ -1614,7 +1598,7 @@ void CSparseMatrix::Trans_MultiVec(double* vec_s, double* vec_r) ii = row_index_mapping_n2o[i]; jj = entry_column[counter]; vec_r[jj] += entry[counter] * vec_s[ii]; - if(symmetry & (ii != jj)) + if (symmetry & (ii != jj)) vec_r[ii] += entry[counter] * vec_s[jj]; counter++; } @@ -1639,23 +1623,22 @@ void CSparseMatrix::Diagonize(const long idiag, const double b_given, double* b) long j, k, ii, jj, j0; long id = idiag % rows; - ii = idiag / rows; - if(storage_type == CRS) + if (storage_type == CRS) { - const long row_end = num_column_entries[id + 1]; + const long row_end = num_column_entries[id + 1]; /// Diagonal entry and the row where the diagonal entry exists j = diag_entry[id]; vdiag = entry[(ii * DOF + ii) * size_entry_column + j]; /// Row where the diagonal entry exists - for(jj = 0; jj < DOF; jj++) + for (jj = 0; jj < DOF; jj++) { const long ij = (ii * DOF + jj) * size_entry_column; - for(k = num_column_entries[id]; k < row_end; k++) + for (k = num_column_entries[id]; k < row_end; k++) { j0 = entry_column[k]; - if(id == j0 && jj == ii) // Diagonal entry + if (id == j0 && jj == ii) // Diagonal entry continue; entry[ij + k] = 0.; } @@ -1664,17 +1647,14 @@ void CSparseMatrix::Diagonize(const long idiag, const double b_given, double* b) /// Clean column id for (i = 0; i < rows; i++) { - j = binarySearch(entry_column, - id, - num_column_entries[i], - num_column_entries[i + 1]); - if(j == -1) + j = binarySearch(entry_column, id, num_column_entries[i], num_column_entries[i + 1]); + if (j == -1) continue; j0 = entry_column[j]; - for(jj = 0; jj < DOF; jj++) + for (jj = 0; jj < DOF; jj++) { - if(i == j0 && ii == jj) + if (i == j0 && ii == jj) continue; k = (jj * DOF + ii) * size_entry_column + j; b[jj * rows + i] -= entry[k] * b_given; @@ -1684,9 +1664,9 @@ void CSparseMatrix::Diagonize(const long idiag, const double b_given, double* b) } #endif } - else if(storage_type == JDS) + else if (storage_type == JDS) { - const long kk = ii * DOF; + const long kk = ii * DOF; long row_in_parse_table, counter; // Row is zero @@ -1694,12 +1674,12 @@ void CSparseMatrix::Diagonize(const long idiag, const double b_given, double* b) counter = row_in_parse_table; for (k = 0; k < max_columns; k++) { - if(row_in_parse_table < num_column_entries[k]) + if (row_in_parse_table < num_column_entries[k]) { j0 = entry_column[counter]; - for(jj = 0; jj < DOF; jj++) + for (jj = 0; jj < DOF; jj++) { - if(id == j0 && jj == ii) + if (id == j0 && jj == ii) { vdiag = entry[(kk + jj) * size_entry_column + counter]; } @@ -1728,10 +1708,10 @@ void CSparseMatrix::Diagonize(const long idiag, const double b_given, double* b) } */ j0 = entry_column[counter]; - if(j0 == id) - for(jj = 0; jj < DOF; jj++) + if (j0 == id) + for (jj = 0; jj < DOF; jj++) { - if(i0 == j0 && ii == jj) + if (i0 == j0 && ii == jj) continue; j = (jj * DOF + ii) * size_entry_column + counter; b[jj * rows + i0] -= entry[j] * b_given; @@ -1761,18 +1741,16 @@ void CSparseMatrix::Precond_Jacobi(double* vec_s, double* vec_r) long i, idof; double diag = 0.; // - if(DOF > 1) + if (DOF > 1) { // Although this piece of code can deal with the case // of DOF = 1, we also prepare a special piece of code for // the case of DOF = 1 just for efficiency - for(i = 0; i < rows; i++) - for(idof = 0; idof < DOF; idof++) + for (i = 0; i < rows; i++) + for (idof = 0; idof < DOF; idof++) { - diag = - entry[(idof * DOF + - idof) * size_entry_column + diag_entry[i]]; - if(fabs(diag) < DBL_MIN) + diag = entry[(idof * DOF + idof) * size_entry_column + diag_entry[i]]; + if (fabs(diag) < DBL_MIN) // if(fabs(diag) 1) + if (DOF > 1) // Although this piece of code can deal with the case // of DOF = 1, we also prepare a special piece of code for // the case of DOF = 1 just for efficiency - for(i = 0; i < rows; i++) - for(idof = 0; idof < DOF; idof++) - diag_e[idof * rows + - i] = - entry[(idof * DOF + - idof) * size_entry_column + diag_entry[i]]; + for (i = 0; i < rows; i++) + for (idof = 0; idof < DOF; idof++) + diag_e[idof * rows + i] = entry[(idof * DOF + idof) * size_entry_column + diag_entry[i]]; // - else // DOF = 1 + else // DOF = 1 - for(i = 0; i < rows; i++) - diag_e[i] = entry[diag_entry[i]]; + for (i = 0; i < rows; i++) + diag_e[i] = entry[diag_entry[i]]; } -#endif // USE_MPI +#endif // USE_MPI #if defined(LIS) || defined(MKL) /******************************************************************** @@ -1836,15 +1811,15 @@ int CSparseMatrix::GetCRSValue(double* value) #ifdef _OPENMP #pragma omp parallel for #endif - for(i = 0; i < size_entry_column * DOF * DOF; ++i) + for (i = 0; i < size_entry_column * DOF * DOF; ++i) value[i] = entry[entry_index[i]]; return success; } -#endif // LIS -#endif //NEW_EQS +#endif // LIS +#endif // NEW_EQS /////////////////////////////////////////////////////////// -} // Namespace +} // Namespace using Math_Group::vec; using Math_Group::SymMatrix; diff --git a/FEM/matrix_class.h b/FEM/matrix_class.h old mode 100755 new mode 100644 index 725ac113f..d320860d5 --- a/FEM/matrix_class.h +++ b/FEM/matrix_class.h @@ -26,16 +26,16 @@ #include #ifdef NEW_EQS namespace MeshLib -{class CFEMesh; +{ +class CFEMesh; } -//08.2007 WW +// 08.2007 WW class CPARDomain; #endif //#define OverLoadNEW_DELETE namespace Math_Group { - /// Base class for matrix objects class MatrixBase { @@ -48,92 +48,93 @@ class MatrixBase */ MatrixBase(size_t rows, size_t cols, size_t size); - MatrixBase(const MatrixBase &m); + MatrixBase(const MatrixBase& m); virtual ~MatrixBase(); void ReleaseMemory(); - size_t Rows() const {return nrows; } - size_t Cols() const {return ncols; } - size_t Size() const {return size; } - + size_t Rows() const { return nrows; } + size_t Cols() const { return ncols; } + size_t Size() const { return size; } // Access to members - virtual double& operator() (const size_t i, const size_t j = 0) const = 0; - double *getEntryArray() { return data; } - const double *getEntryArray() const { return data; } - double& operator[] (const size_t i) const { return data[i]; } - + virtual double& operator()(const size_t i, const size_t j = 0) const = 0; + double* getEntryArray() { return data; } + const double* getEntryArray() const { return data; } + double& operator[](const size_t i) const { return data[i]; } // Operators - inline void operator= (double a) + inline void operator=(double a) { - for(size_t i = 0; i < size; i++) + for (size_t i = 0; i < size; i++) data[i] = a; } - inline void operator*= (double a) + inline void operator*=(double a) { - for(size_t i = 0; i < size; i++) + for (size_t i = 0; i < size; i++) data[i] *= a; } - inline void operator/= (double a) + inline void operator/=(double a) { - for(size_t i = 0; i < size; i++) + for (size_t i = 0; i < size; i++) data[i] /= a; } - inline void operator+= (double a) + inline void operator+=(double a) { - for(size_t i = 0; i < size; i++) + for (size_t i = 0; i < size; i++) data[i] += a; } - inline void operator-= (double a) + inline void operator-=(double a) { - for(size_t i = 0; i < size; i++) + for (size_t i = 0; i < size; i++) data[i] -= a; } - inline void operator= (const MatrixBase& m) + inline void operator=(const MatrixBase& m) { #ifdef gDEBUG - if(nrows != m.Rows() || ncols != m.Cols()) + if (nrows != m.Rows() || ncols != m.Cols()) { - std::cout << "\n The sizes of the two matrices are not matched" << "\n"; + std::cout << "\n The sizes of the two matrices are not matched" + << "\n"; abort(); } #endif - for(size_t i = 0; i < nrows; i++) - for(size_t j = 0; j < ncols; j++) - data[i * ncols + j] = m(i,j); + for (size_t i = 0; i < nrows; i++) + for (size_t j = 0; j < ncols; j++) + data[i * ncols + j] = m(i, j); } - inline void operator+= (const MatrixBase& m) + inline void operator+=(const MatrixBase& m) { #ifdef gDEBUG - if(nrows != m.Rows() || ncols != m.Cols()) + if (nrows != m.Rows() || ncols != m.Cols()) { - std::cout << "\n The sizes of the two matrices are not matched" << "\n"; + std::cout << "\n The sizes of the two matrices are not matched" + << "\n"; abort(); } #endif - for(size_t i = 0; i < nrows; i++) - for(size_t j = 0; j < ncols; j++) - data[i * ncols + j] += m(i,j); + for (size_t i = 0; i < nrows; i++) + for (size_t j = 0; j < ncols; j++) + data[i * ncols + j] += m(i, j); } - inline void operator-= (const MatrixBase& m) + inline void operator-=(const MatrixBase& m) { #ifdef gDEBUG - if(nrows != m.Rows() || ncols != m.Cols()) //Assertion, will be removed + if (nrows != m.Rows() || ncols != m.Cols()) // Assertion, will be removed { - std::cout << "\n The sizes of the two matrices are not matched" << "\n"; + std::cout << "\n The sizes of the two matrices are not matched" + << "\n"; abort(); } #endif - for(size_t i = 0; i < nrows; i++) - for(size_t j = 0; j < ncols; j++) - data[i * ncols + j] -= m(i,j); + for (size_t i = 0; i < nrows; i++) + for (size_t j = 0; j < ncols; j++) + data[i * ncols + j] -= m(i, j); } // vec_result = This*vec. vec_result must be initialized. @@ -156,7 +157,7 @@ class MatrixBase }; #ifdef _MSC_VER -#pragma warning( disable: 4522 ) +#pragma warning(disable : 4522) #endif /// Dense matrix @@ -178,44 +179,47 @@ class Matrix : public MatrixBase virtual ~Matrix(); // Operators - inline void operator= (const Matrix& m) + inline void operator=(const Matrix& m) { #ifdef gDEBUG - if(nrows != m.Rows() || ncols != m.Cols()) - { - std::cout << "\n The sizes of the two matrices are not matched" << "\n"; - abort(); - } + if (nrows != m.Rows() || ncols != m.Cols()) + { + std::cout << "\n The sizes of the two matrices are not matched" + << "\n"; + abort(); + } #endif - const double *m_data = m.getEntryArray() ; - for(size_t i = 0; i < size; i++) + const double* m_data = m.getEntryArray(); + for (size_t i = 0; i < size; i++) data[i] = m_data[i]; } - inline void operator+= (const Matrix& m) + inline void operator+=(const Matrix& m) { #ifdef gDEBUG - if(nrows != m.Rows() || ncols != m.Cols()) - { - std::cout << "\n The sizes of the two matrices are not matched" << "\n"; - abort(); - } + if (nrows != m.Rows() || ncols != m.Cols()) + { + std::cout << "\n The sizes of the two matrices are not matched" + << "\n"; + abort(); + } #endif - const double *m_data = m.getEntryArray(); + const double* m_data = m.getEntryArray(); for (size_t i = 0; i < size; i++) data[i] += m_data[i]; } - inline void operator-= (const Matrix& m) + inline void operator-=(const Matrix& m) { #ifdef gDEBUG - if(nrows != m.Rows() || ncols != m.Cols()) //Assertion, will be removed - { - std::cout << "\n The sizes of the two matrices are not matched" << "\n"; - abort(); - } + if (nrows != m.Rows() || ncols != m.Cols()) // Assertion, will be removed + { + std::cout << "\n The sizes of the two matrices are not matched" + << "\n"; + abort(); + } #endif - const double *m_data = m.getEntryArray(); + const double* m_data = m.getEntryArray(); for (size_t i = 0; i < size; i++) data[i] -= m_data[i]; } @@ -230,7 +234,7 @@ class Matrix : public MatrixBase virtual void multi(const Matrix& m1, const Matrix& m2, Matrix& m_result); // Access to members - virtual double& operator() (const size_t i, const size_t j = 0) const; + virtual double& operator()(const size_t i, const size_t j = 0) const; void LimitSize(size_t nRows, size_t nCols = 1); }; @@ -250,14 +254,14 @@ class SymMatrix : public MatrixBase void resize(size_t dim); virtual ~SymMatrix() {} - // Operators - inline void operator= (const SymMatrix& m) + inline void operator=(const SymMatrix& m) { #ifdef gDEBUG - if(nrows != m.Rows()) + if (nrows != m.Rows()) { - std::cout << "\n The sizes of the two matrices are not matched" << "\n"; + std::cout << "\n The sizes of the two matrices are not matched" + << "\n"; abort(); } #endif @@ -265,12 +269,13 @@ class SymMatrix : public MatrixBase data[i] = m.data[i]; } - inline void operator+= (const SymMatrix& m) + inline void operator+=(const SymMatrix& m) { #ifdef gDEBUG - if(nrows != m.Rows()) + if (nrows != m.Rows()) { - std::cout << "\n The sizes of the two matrices are not matched" << "\n"; + std::cout << "\n The sizes of the two matrices are not matched" + << "\n"; abort(); } #endif @@ -278,12 +283,13 @@ class SymMatrix : public MatrixBase data[i] += m.data[i]; } - inline void operator-= (const SymMatrix& m) + inline void operator-=(const SymMatrix& m) { #ifdef gDEBUG - if(nrows != m.Rows()) //Assertion, will be removed + if (nrows != m.Rows()) // Assertion, will be removed { - std::cout << "\n The sizes of the two matrices are not matched" << "\n"; + std::cout << "\n The sizes of the two matrices are not matched" + << "\n"; abort(); } #endif @@ -292,11 +298,7 @@ class SymMatrix : public MatrixBase } // Access the element - virtual inline double& operator() (const size_t i, const size_t j = 1) const - { - return data[getArrayIndex(i, j)]; - } - + virtual inline double& operator()(const size_t i, const size_t j = 1) const { return data[getArrayIndex(i, j)]; } // Access to members void LimitSize(size_t dim); @@ -307,9 +309,9 @@ class SymMatrix : public MatrixBase // m_result = this*m1*m2. m_result must be initialized. m_result must be a full stored matrix virtual void multi(const SymMatrix& m1, const Matrix& m2, Matrix& m_result); - inline size_t getArrayIndex(const size_t i, const size_t j) const + inline size_t getArrayIndex(const size_t i, const size_t j) const { - if(i >= j) + if (i >= j) return static_cast(i * (i + 1) / 2) + j; else return static_cast(j * (j + 1) / 2) + i; @@ -320,6 +322,7 @@ class DiagonalMatrix : public MatrixBase { private: mutable double dummy_zero; + public: using MatrixBase::operator=; using MatrixBase::operator+=; @@ -334,71 +337,75 @@ class DiagonalMatrix : public MatrixBase void resize(size_t dim); virtual ~DiagonalMatrix() {} - // Forwarded operators - inline void operator = (const DiagonalMatrix& m) + inline void operator=(const DiagonalMatrix& m) { #ifdef gDEBUG - if(nrows != m.Rows() || ncols != m.Cols()) + if (nrows != m.Rows() || ncols != m.Cols()) { - cout << "\n The sizes of the two matrices are not matched" << "\n"; + cout << "\n The sizes of the two matrices are not matched" + << "\n"; abort(); } #endif - for(size_t i = 0; i < size; i++) + for (size_t i = 0; i < size; i++) data[i] = m.data[i]; } - inline void operator += (const DiagonalMatrix& m) + inline void operator+=(const DiagonalMatrix& m) { #ifdef gDEBUG - if(nrows != m.Rows()) + if (nrows != m.Rows()) { - cout << "\n The sizes of the two matrices are not matched" << "\n"; + cout << "\n The sizes of the two matrices are not matched" + << "\n"; abort(); } #endif - for(size_t i = 0; i < size; i++) + for (size_t i = 0; i < size; i++) data[i] += m.data[i]; } - inline void operator -= (const DiagonalMatrix& m) + inline void operator-=(const DiagonalMatrix& m) { #ifdef gDEBUG - if(nrows != m.Rows()) //Assertion, will be removed + if (nrows != m.Rows()) // Assertion, will be removed { - cout << "\n The sizes of the two matrices are not matched" << "\n"; + cout << "\n The sizes of the two matrices are not matched" + << "\n"; abort(); } #endif - for(size_t i = 0; i < size; i++) + for (size_t i = 0; i < size; i++) data[i] -= m.data[i]; } void LimitSize(size_t dim); // Access to members - inline double& operator() (const size_t i, const size_t j) const + inline double& operator()(const size_t i, const size_t j) const { #ifdef gDEBUG - if(i >= nrows || j >= nrows) + if (i >= nrows || j >= nrows) { - cout << "\n Index exceeds the size of the matrix" << "\n"; + cout << "\n Index exceeds the size of the matrix" + << "\n"; abort(); } #endif - if(i == j) - return data[i]; // temporary + if (i == j) + return data[i]; // temporary else return dummy_zero; } - inline double& operator() (const size_t i) const + inline double& operator()(const size_t i) const { #ifdef gDEBUG - if(i >= size) + if (i >= size) { - cout << "\n Index exceeds the size of the matrix" << "\n"; + cout << "\n Index exceeds the size of the matrix" + << "\n"; abort(); } #endif @@ -408,7 +415,7 @@ class DiagonalMatrix : public MatrixBase }; #ifdef _MSC_VER -#pragma warning( default: 4522 ) +#pragma warning(default : 4522) #endif typedef Matrix Vec; @@ -420,7 +427,8 @@ typedef Matrix Vec; programming: 05/2005 WW ==========================================================================*/ -template class vec +template +class vec { public: vec(int argSize); @@ -429,16 +437,18 @@ template class vec virtual ~vec(); // Operator - virtual void operator = (T v) { for (size_t i = 0; i < _size; i++) _entry[i] = v; } - virtual void operator = (const vec&); + virtual void operator=(T v) + { + for (size_t i = 0; i < _size; i++) + _entry[i] = v; + } + virtual void operator=(const vec&); virtual void resize(int newh); - virtual T& operator[] (size_t i) { return (T &)_entry[i]; } - virtual const T& operator[] (size_t i) const {return (const T &)_entry[i]; } + virtual T& operator[](size_t i) { return (T&)_entry[i]; } + virtual const T& operator[](size_t i) const { return (const T&)_entry[i]; } virtual size_t Size() const { return _size; } - - T* Entry() { return _entry; } - T* Entry() const { return _entry; } - + T* Entry() { return _entry; } + T* Entry() const { return _entry; } virtual void Write(std::ostream& os = std::cout) const; protected: @@ -446,25 +456,27 @@ template class vec T* _entry; }; -template<> class vec +template <> +class vec { public: vec(int argSize); - vec() : _entry(NULL), _size (0) {} + vec() : _entry(NULL), _size(0) {} explicit vec(const vec& v); virtual ~vec(); // Operator - void operator = (void* v) - { for (size_t i = 0; i < _size; i++) _entry[i] = v; } - void operator = (const vec& v); - void*& operator[] (size_t i) { return _entry[i]; } - const void*& operator[] (size_t i) const { return (const void* &)_entry[i]; } - + void operator=(void* v) + { + for (size_t i = 0; i < _size; i++) + _entry[i] = v; + } + void operator=(const vec& v); + void*& operator[](size_t i) { return _entry[i]; } + const void*& operator[](size_t i) const { return (const void*&)_entry[i]; } // Access to memebers - void** Entry() { return _entry; } - const void** Entry() const { return (const void**)_entry; } - + void** Entry() { return _entry; } + const void** Entry() const { return (const void**)_entry; } virtual void resize(int newh); virtual size_t Size() const { return _size; } virtual void Write(std::ostream& os = std::cout) const; @@ -474,90 +486,93 @@ template<> class vec size_t _size; }; -template class vec : public vec +template +class vec : public vec { public: - vec( int Size) : vec(Size) { } - vec() : vec() { } - explicit vec(const vec& v) : vec(v) { } - - ~vec() { } - + vec(int Size) : vec(Size) {} + vec() : vec() {} + explicit vec(const vec& v) : vec(v) {} + ~vec() {} // Operator - void operator = (T* v) { for (size_t i = 0; i < _size; i++) _entry[i] = v; } - void operator = (const vec& v); - T*& operator[] (size_t i) { return (T * &)_entry[i]; } - const T*& operator[] (size_t i) const {return (const T * &)_entry[i]; } - - T** Entry() { return _entry; } - T** Entry() const { return (const T**)_entry; } + void operator=(T* v) + { + for (size_t i = 0; i < _size; i++) + _entry[i] = v; + } + void operator=(const vec& v); + T*& operator[](size_t i) { return (T*&)_entry[i]; } + const T*& operator[](size_t i) const { return (const T*&)_entry[i]; } + T** Entry() { return _entry; } + T** Entry() const { return (const T**)_entry; } }; - #ifdef NEW_EQS // /// Sparse matrix storage type //04.2011. WW -enum StorageType { CRS, JDS}; +enum StorageType +{ + CRS, + JDS +}; class SparseTable { public: - SparseTable(MeshLib::CFEMesh* a_mesh, - bool quadratic, - bool symm = false, - StorageType stype = JDS); - SparseTable(CPARDomain &m_dom, bool quadratic, bool symm = false); + SparseTable(MeshLib::CFEMesh* a_mesh, bool quadratic, bool symm = false, StorageType stype = JDS); + SparseTable(CPARDomain& m_dom, bool quadratic, bool symm = false); ~SparseTable(); - void Write(std::ostream &os = std::cout); + void Write(std::ostream& os = std::cout); + private: bool symmetry; // Topology mapping from data array to matrix long* entry_column; - long* num_column_entries; // number of entries of each columns in sparse table - long* row_index_mapping_n2o; // Row index of sparse table to row index of matrix - long* row_index_mapping_o2n; // Inverse of last - long* diag_entry; // Global index to the index of entry_column + long* num_column_entries; // number of entries of each columns in sparse table + long* row_index_mapping_n2o; // Row index of sparse table to row index of matrix + long* row_index_mapping_o2n; // Inverse of last + long* diag_entry; // Global index to the index of entry_column long size_entry_column; long max_columns; long rows; - StorageType storage_type; //04.2011. WW + StorageType storage_type; // 04.2011. WW friend class CSparseMatrix; }; -//08.2007 WW +// 08.2007 WW // Jagged Diagonal Storage class CSparseMatrix { public: - CSparseMatrix(const SparseTable &sparse_table, const int dof); + CSparseMatrix(const SparseTable& sparse_table, const int dof); ~CSparseMatrix(); // Preconditioner void Precond_Jacobi(double* vec_s, double* vec_r); - //TEMP + // TEMP void Precond_ILU(double* /*vec_s*/, double* /*vec_r*/) {} // Operator - void operator = (const double a); - void operator *= (const double a); - void operator += (const double a); - void operator = (const CSparseMatrix& m); - void operator += (const CSparseMatrix& m); - void operator -= (const CSparseMatrix& m); + void operator=(const double a); + void operator*=(const double a); + void operator+=(const double a); + void operator=(const CSparseMatrix& m); + void operator+=(const CSparseMatrix& m); + void operator-=(const CSparseMatrix& m); // Vector pass through augment and bring results back. void multiVec(double* vec_s, double* vec_r); void Trans_MultiVec(double* vec_s, double* vec_r); void Diagonize(const long idiag, const double b_given, double* b); // // Access to members - double& operator() (const long i, const long j = 0) const; + double& operator()(const long i, const long j = 0) const; // - StorageType GetStorageType() const {return storage_type; } //05.2011. WW - long Dim() const {return DOF * rows; } - int Dof() const {return DOF; } - void SetDOF(const int dof_n) //_new. 02/2010. WW + StorageType GetStorageType() const { return storage_type; } // 05.2011. WW + long Dim() const { return DOF * rows; } + int Dof() const { return DOF; } + void SetDOF(const int dof_n) //_new. 02/2010. WW { DOF = dof_n; } - long Size() const {return rows; } -#if defined(LIS) || defined(MKL) // These two pointers are in need for Compressed Row Storage - int nnz() const // PCH + long Size() const { return rows; } +#if defined(LIS) || defined(MKL) // These two pointers are in need for Compressed Row Storage + int nnz() const // PCH { return DOF * DOF * size_entry_column; } @@ -567,9 +582,9 @@ class CSparseMatrix int GetCRSValue(double* value); #endif // Print - void Write(std::ostream &os = std::cout); - void Write_BIN(std::ostream &os); - // Domain decomposition + void Write(std::ostream& os = std::cout); + void Write_BIN(std::ostream& os); +// Domain decomposition #if defined(USE_MPI) void DiagonalEntries(double* diag_e); #endif @@ -584,9 +599,9 @@ class CSparseMatrix // Topology mapping from data array to matrix. All are only pointers to the // correpinding members in SparseTable, and no memory are allocated for them long* entry_column; - long* num_column_entries; // number of entries of each columns in sparse table - long* row_index_mapping_n2o; // Row index of sparse table to row index of matrix - long* row_index_mapping_o2n; // Inverse of last + long* num_column_entries; // number of entries of each columns in sparse table + long* row_index_mapping_n2o; // Row index of sparse table to row index of matrix + long* row_index_mapping_o2n; // Inverse of last long* diag_entry; long size_entry_column; long max_columns; @@ -599,7 +614,7 @@ class CSparseMatrix // // Cross production x^y. WW 12.01.2005 -//const Vec& operator ^ (Vec& x, Vec& y); +// const Vec& operator ^ (Vec& x, Vec& y); // End of class Matrix } diff --git a/FEM/matrix_routines.cpp b/FEM/matrix_routines.cpp index 3d05221c8..0281c0bfd 100644 --- a/FEM/matrix_routines.cpp +++ b/FEM/matrix_routines.cpp @@ -107,11 +107,11 @@ using MeshLib::CNode; #include #endif /* Interne (statische) Deklarationen */ -static void* wurzel = NULL; /* interner Matrix-Wurzelzeiger */ +static void* wurzel = NULL; /* interner Matrix-Wurzelzeiger */ /* Allgemeine Funktionen ohne Modellspezifisches */ -int MXSetFunctionPointers(int matrix_type); /* Setzt Funktionszeiger */ -int MXGetMatrixType(void); /* Liefert Matrixtyp */ +int MXSetFunctionPointers(int matrix_type); /* Setzt Funktionszeiger */ +int MXGetMatrixType(void); /* Liefert Matrixtyp */ int MX_Dec(long i, long j, double aij_dec); int MX_Div(long i, long j, double aij_div); void MX_Trans(long i, long j, long ii, long jj); @@ -119,9 +119,9 @@ void MX_Trans(long i, long j, long ii, long jj); /* Struktur und Funktionen zu Speichermodell 1 (vollbesetzte Matrix) */ typedef struct { - long info[2]; /* Muss immer zuerst kommen, enthaelt Dimension und Matrixtyp */ + long info[2]; /* Muss immer zuerst kommen, enthaelt Dimension und Matrixtyp */ long max_size; - long NumDif; /* max. Differenz |Spalten-Zeilennummer| */ + long NumDif; /* max. Differenz |Spalten-Zeilennummer| */ double* matrix; } @@ -138,39 +138,31 @@ double M1Get(long i, long j); void M1MatVek(double* vektor, double* ergebnis); void M1MatTVek(double* vektor, double* ergebnis); void M1Vorkond(int aufgabe, double* x, double* b); -int M1CopyToAMG1R5Structure( double* A, - int* IA, - int* JA, - int NDA, - int NDIA, - int NDJA, - double*, - double*, - double*, - double*); +int M1CopyToAMG1R5Structure(double* A, int* IA, int* JA, int NDA, int NDIA, int NDJA, double*, double*, double*, + double*); /* Strukturen und Funktionen zu Speichermodell 2 (i, j, Wert) */ typedef struct { - int max_anz; /* Anzahl der allokierten Spalten (ohne Diagonale) */ - int anz; /* Anzahl der belegten Spalten (ohne Diagonale) */ - int min_col; /* Kleinste Spaltennummer */ - int max_col; /* Groesste Spaltennummer */ - long* index; /* Index fuer Spalteneintraege */ - double* wert; /* Spalteneintraege */ + int max_anz; /* Anzahl der allokierten Spalten (ohne Diagonale) */ + int anz; /* Anzahl der belegten Spalten (ohne Diagonale) */ + int min_col; /* Kleinste Spaltennummer */ + int max_col; /* Groesste Spaltennummer */ + long* index; /* Index fuer Spalteneintraege */ + double* wert; /* Spalteneintraege */ } M2_Zeile; typedef struct { - long info[2]; /* Muss immer zuerst kommen, enthaelt Dimension und Matrixtyp */ + long info[2]; /* Muss immer zuerst kommen, enthaelt Dimension und Matrixtyp */ long max_size; - long NumDif; /* max. Differenz |Spalten-Zeilennummer| */ - M2_Zeile* zeile; /* Eintraege in den Zeilen; Diagonale in zeile[0] */ + long NumDif; /* max. Differenz |Spalten-Zeilennummer| */ + M2_Zeile* zeile; /* Eintraege in den Zeilen; Diagonale in zeile[0] */ } Modell2; typedef struct { - long NumDif; //dummy + long NumDif; // dummy } Modell5; @@ -190,24 +182,24 @@ void M2MatVek(double* vektor, double* ergebnis); int M5Inc(long i, long j, double aij_inc); double M5Get(long i, long j); int M5Set(long i, long j, double e_val); -void M5MatVek( double* b, double* erg); +void M5MatVek(double* b, double* erg); void M5InitMatrix(void); void* M5DestroyMatrix(void); void M5Vorkond(int aufgabe, double* x, double* b); -//void M5CreateMatrix(void); +// void M5CreateMatrix(void); void* M5CreateMatrix(long param1, long param2, long param3); -void insertionSort1_des(int numbers[],int numbers1[], int array_size); +void insertionSort1_des(int numbers[], int numbers1[], int array_size); void transM2toM5(void); -int* jd_ptr1, * jd_ptr2, * jd_ptr, * jd_ptrf, * col_ind; +int *jd_ptr1, *jd_ptr2, *jd_ptr, *jd_ptrf, *col_ind; long* diag5_i; -double* temp_ergebnis,* jdiag; +double *temp_ergebnis, *jdiag; int m_count, jd_ptr_max, Dim_L; /*----------------------------------------------------------------------- * ITPACKV format Modell 6 * */ -void M6MatVek( double* b, double* erg); +void M6MatVek(double* b, double* erg); void transM2toM6(void); double* itpackv; int* it_col; @@ -215,72 +207,68 @@ int itpack_max; /*----------------------------------------------------------------------*/ void M2MatTVek(double* vektor, double* ergebnis); void M2Vorkond(int aufgabe, double* x, double* b); -int M2CopyToAMG1R5Structure( double* A, - int* IA, - int* JA, - int NDA, - int NDIA, - int NDJA, - double*, - double*, - double*, - double*); +int M2CopyToAMG1R5Structure(double* A, int* IA, int* JA, int NDA, int NDIA, int NDJA, double*, double*, double*, + double*); /* Strukturen und Funktionen zu Speichermodell 3/4 (i, j, Wert) */ typedef struct -{ /* einzelner Eintrag in der Spalte k mit Index i */ +{ /* einzelner Eintrag in der Spalte k mit Index i */ long Index; double Aik[4]; } M34_aik; typedef struct -{ /* Spalte k der Obermatrix (Zeile k der Untermatrix) */ - int max_anz; /* Anzahl der allokierten Elemente i (ohne Diagonale) */ - int anz; /* Anzahl eingespeicherter Aik (ohne Diagonale) */ - long rechts; /* rechts[k]: letzte Spalte j, die ein Akj enthaelt */ - M34_aik* Ak; /* Spalten/Zeilenelemente */ +{ /* Spalte k der Obermatrix (Zeile k der Untermatrix) */ + int max_anz; /* Anzahl der allokierten Elemente i (ohne Diagonale) */ + int anz; /* Anzahl eingespeicherter Aik (ohne Diagonale) */ + long rechts; /* rechts[k]: letzte Spalte j, die ein Akj enthaelt */ + M34_aik* Ak; /* Spalten/Zeilenelemente */ } M34_Spalte; typedef struct { - long info[2]; /* Muss immer zuerst kommen, enthaelt Dimension und Matrixtyp */ + long info[2]; /* Muss immer zuerst kommen, enthaelt Dimension und Matrixtyp */ long max_size; - int usym; /* 0: symmetrisch, Modell 3 */ + int usym; /* 0: symmetrisch, Modell 3 */ /* 1: unsymmetrisch, Modell 4 */ - int stat; /* -1: nicht initialisiert */ + int stat; /* -1: nicht initialisiert */ /* 0: initialisiert */ /* 1: aik eingespeichert oder veraendert, */ /* 2: ILU-Zerlegung gelaufen */ - int l34_Aik; /* L�nge von Aik */ + int l34_Aik; /* L�nge von Aik */ /* 2: symmetrisch, 4: unsymmetrisch */ - int i34_Bik; /* Start Bik (Preconditioner) innerhalb aik */ + int i34_Bik; /* Start Bik (Preconditioner) innerhalb aik */ /* 1: symmetrisch, 2: unsymmetrisch */ - double* Diag; /* Akk als Vektor */ - double* PreD; /* Bkk (ILU-Preconditioner) */ - M34_Spalte* Spalte; /* Obermatrixspalten (Untermatrixzeilen) */ + double* Diag; /* Akk als Vektor */ + double* PreD; /* Bkk (ILU-Preconditioner) */ + M34_Spalte* Spalte; /* Obermatrixspalten (Untermatrixzeilen) */ } Modell34; /* Die nachfolgenden Makros dienen der besseren Lesbarkeit (Kuerze!) des Codes. Sie werden am Ende dieser Quelle saemtlich undefiniert! Allgemeines: */ -#define dim ((long*)wurzel)[0] /* Dimension der aktuellen Matrix */ -#define matrix_type ((long*)wurzel)[1] /* Speichermodell der aktuellen Matrix */ -#define Maxim(x,v) if(x < (v)) x = v /* x =max(x,v) */ -#define Minim(x,v) if(x > (v)) x = v +#define dim ((long*)wurzel)[0] /* Dimension der aktuellen Matrix */ +#define matrix_type ((long*)wurzel)[1] /* Speichermodell der aktuellen Matrix */ +#define Maxim(x, v) \ + if (x < (v)) \ + x = v /* x =max(x,v) */ +#define Minim(x, v) \ + if (x > (v)) \ + x = v /* x =min(x,v) Modell 1: */ #define Matrix1 w->matrix -#define Aik1(i,k) Matrix1[i* dim + k] +#define Aik1(i, k) Matrix1[i * dim + k] /* Modell 2: */ #define Zeil2(i) w->zeile[i] -#define Aik2(i,j) Zeil2(i).wert[j] -#define Ind2(i,j) Zeil2(i).index[j] +#define Aik2(i, j) Zeil2(i).wert[j] +#define Ind2(i, j) Zeil2(i).index[j] #define Diag2(i) Zeil2(i).wert[0] /* Modelle 3,4: */ #define Sp34(k) w->Spalte[k] -#define Aik34(k,j,teil) Sp34(k).Ak[j].Aik[teil] -#define Bik34(k,j,teil) Sp34(k).Ak[j].Aik[(w->i34_Bik) + teil] -#define Ind34(k,j) Sp34(k).Ak[j].Index +#define Aik34(k, j, teil) Sp34(k).Ak[j].Aik[teil] +#define Bik34(k, j, teil) Sp34(k).Ak[j].Aik[(w->i34_Bik) + teil] +#define Ind34(k, j) Sp34(k).Ak[j].Index void* M34CreateMatrix(long param1, long param2, long param3); void* M34DestroyMatrix(void); @@ -293,44 +281,36 @@ double M34Get(long i, long j); void M34MatVek(double* vektor, double* ergebnis); void M34MatTVek(double* vektor, double* ergebnis); void M34Vorkond(int aufgabe, double* x, double* b); -int M34CopyToAMG1R5Structure( double* A, - int* IA, - int* JA, - int NDA, - int NDIA, - int NDJA, - double*, - double*, - double*, - double*); +int M34CopyToAMG1R5Structure(double* A, int* IA, int* JA, int NDA, int NDIA, int NDJA, double*, double*, double*, + double*); void MX_Exit(const char* caller, int errcode) { char text[1024]; - strcpy(text,caller); + strcpy(text, caller); strcat(text, ": "); switch (errcode) { - case 0: - strcat(text, "Negative Dimension"); - break; - case 1: - strcat(text, "Keine Wurzel eingetragen"); - break; - case 2: - strcat(text, "Feldgrenzenueberschreitung"); - break; - case 3: - strcat(text, "Nullzeiger"); - break; - case 4: - strcat(text, "Unbekanntes Speichermodell"); - break; - case 5: - strcat(text, "Argumente falsch"); - break; + case 0: + strcat(text, "Negative Dimension"); + break; + case 1: + strcat(text, "Keine Wurzel eingetragen"); + break; + case 2: + strcat(text, "Feldgrenzenueberschreitung"); + break; + case 3: + strcat(text, "Nullzeiger"); + break; + case 4: + strcat(text, "Unbekanntes Speichermodell"); + break; + case 5: + strcat(text, "Argumente falsch"); + break; } DisplayErrorMsg(strcat(text, " -> Abbruch!")); exit(1); @@ -376,7 +356,7 @@ MXPCopyToAMG1R5Structure MXCopyToAMG1R5Structure; *************************************************************************/ void* MXSetupMatrix(long param1, long param2, long param3) { - MXSetFunctionPointers((int) param2); + MXSetFunctionPointers((int)param2); wurzel = MXCreateMatrix(param1, param2, param3); MXSetMatrixPointer(wurzel); MXInitMatrix(); @@ -404,95 +384,95 @@ int MXSetFunctionPointers(int type) { switch (type) { - case 1: - MXCreateMatrix = M1CreateMatrix; - MXDestroyMatrix = M1DestroyMatrix; - MXResizeMatrix = M1ResizeMatrix; - MXInitMatrix = M1InitMatrix; - MXSet = M1Set; - MXInc = M1Inc; - MXMul = M1Mul; - MXGet = M1Get; - MXMatVek = M1MatVek; - MXMatTVek = M1MatTVek; - MXVorkond = M1Vorkond; - MXCopyToAMG1R5Structure = M1CopyToAMG1R5Structure; - break; - case 2: - MXCreateMatrix = M2CreateMatrix; - MXDestroyMatrix = M2DestroyMatrix; - MXResizeMatrix = M2ResizeMatrix; - MXInitMatrix = M2InitMatrix; - MXSet = M2Set; - MXInc = M2Inc; - MXMul = M2Mul; - MXGet = M2Get; - MXMatVek = M2MatVek; - MXMatTVek = M2MatTVek; - MXVorkond = M2Vorkond; - MXCopyToAMG1R5Structure = M2CopyToAMG1R5Structure; - break; - case 3: - MXCreateMatrix = M34CreateMatrix; - MXDestroyMatrix = M34DestroyMatrix; - MXResizeMatrix = M34ResizeMatrix; - MXInitMatrix = M34InitMatrix; - MXSet = M34Set; - MXInc = M34Inc; - MXMul = M34Mul; - MXGet = M34Get; - MXMatVek = M34MatVek; - MXMatTVek = M34MatTVek; - MXVorkond = M34Vorkond; - MXCopyToAMG1R5Structure = M34CopyToAMG1R5Structure; - break; - case 4: - MXCreateMatrix = M34CreateMatrix; - MXDestroyMatrix = M34DestroyMatrix; - MXResizeMatrix = M34ResizeMatrix; - MXInitMatrix = M34InitMatrix; - MXSet = M34Set; - MXInc = M34Inc; - MXMul = M34Mul; - MXGet = M34Get; - MXMatVek = M34MatVek; - MXMatTVek = M34MatTVek; - MXVorkond = M34Vorkond; - MXCopyToAMG1R5Structure = M34CopyToAMG1R5Structure; - break; - case 5: - MXCreateMatrix = M5CreateMatrix; - MXDestroyMatrix = M5DestroyMatrix; - MXResizeMatrix = M2ResizeMatrix; - MXInitMatrix = M5InitMatrix; - MXSet = M5Set; - MXInc = M5Inc; //M2Inc; - MXMul = M2Mul; - MXGet = M5Get; - MXMatVek = M5MatVek; - MXMatTVek = M2MatTVek; - MXVorkond = M5Vorkond; - MXCopyToAMG1R5Structure = M2CopyToAMG1R5Structure; - break; - case 6: - MXCreateMatrix = M2CreateMatrix; - MXDestroyMatrix = M2DestroyMatrix; - MXResizeMatrix = M2ResizeMatrix; - MXInitMatrix = M2InitMatrix; - MXSet = M2Set; - MXInc = M2Inc; - MXMul = M2Mul; - MXGet = M2Get; - MXMatVek = M6MatVek; - MXMatTVek = M2MatTVek; - MXVorkond = M2Vorkond; - MXCopyToAMG1R5Structure = M2CopyToAMG1R5Structure; - break; - default: - return 0; + case 1: + MXCreateMatrix = M1CreateMatrix; + MXDestroyMatrix = M1DestroyMatrix; + MXResizeMatrix = M1ResizeMatrix; + MXInitMatrix = M1InitMatrix; + MXSet = M1Set; + MXInc = M1Inc; + MXMul = M1Mul; + MXGet = M1Get; + MXMatVek = M1MatVek; + MXMatTVek = M1MatTVek; + MXVorkond = M1Vorkond; + MXCopyToAMG1R5Structure = M1CopyToAMG1R5Structure; + break; + case 2: + MXCreateMatrix = M2CreateMatrix; + MXDestroyMatrix = M2DestroyMatrix; + MXResizeMatrix = M2ResizeMatrix; + MXInitMatrix = M2InitMatrix; + MXSet = M2Set; + MXInc = M2Inc; + MXMul = M2Mul; + MXGet = M2Get; + MXMatVek = M2MatVek; + MXMatTVek = M2MatTVek; + MXVorkond = M2Vorkond; + MXCopyToAMG1R5Structure = M2CopyToAMG1R5Structure; + break; + case 3: + MXCreateMatrix = M34CreateMatrix; + MXDestroyMatrix = M34DestroyMatrix; + MXResizeMatrix = M34ResizeMatrix; + MXInitMatrix = M34InitMatrix; + MXSet = M34Set; + MXInc = M34Inc; + MXMul = M34Mul; + MXGet = M34Get; + MXMatVek = M34MatVek; + MXMatTVek = M34MatTVek; + MXVorkond = M34Vorkond; + MXCopyToAMG1R5Structure = M34CopyToAMG1R5Structure; + break; + case 4: + MXCreateMatrix = M34CreateMatrix; + MXDestroyMatrix = M34DestroyMatrix; + MXResizeMatrix = M34ResizeMatrix; + MXInitMatrix = M34InitMatrix; + MXSet = M34Set; + MXInc = M34Inc; + MXMul = M34Mul; + MXGet = M34Get; + MXMatVek = M34MatVek; + MXMatTVek = M34MatTVek; + MXVorkond = M34Vorkond; + MXCopyToAMG1R5Structure = M34CopyToAMG1R5Structure; + break; + case 5: + MXCreateMatrix = M5CreateMatrix; + MXDestroyMatrix = M5DestroyMatrix; + MXResizeMatrix = M2ResizeMatrix; + MXInitMatrix = M5InitMatrix; + MXSet = M5Set; + MXInc = M5Inc; // M2Inc; + MXMul = M2Mul; + MXGet = M5Get; + MXMatVek = M5MatVek; + MXMatTVek = M2MatTVek; + MXVorkond = M5Vorkond; + MXCopyToAMG1R5Structure = M2CopyToAMG1R5Structure; + break; + case 6: + MXCreateMatrix = M2CreateMatrix; + MXDestroyMatrix = M2DestroyMatrix; + MXResizeMatrix = M2ResizeMatrix; + MXInitMatrix = M2InitMatrix; + MXSet = M2Set; + MXInc = M2Inc; + MXMul = M2Mul; + MXGet = M2Get; + MXMatVek = M6MatVek; + MXMatTVek = M2MatTVek; + MXVorkond = M2Vorkond; + MXCopyToAMG1R5Structure = M2CopyToAMG1R5Structure; + break; + default: + return 0; } - MXDec = MX_Dec; /* nicht modellspezifisch */ + MXDec = MX_Dec; /* nicht modellspezifisch */ MXDiv = MX_Div; MXTrans = MX_Trans; return 1; @@ -622,13 +602,13 @@ void* M1CreateMatrix(long param1, long param2, long /*param3*/) MX_Exit("M1CreateMatrix", 0); #endif - w = (Modell1*) Malloc(sizeof(Modell1)); - MXSetMatrixPointer((void*) w); - Matrix1 = (double*) Malloc(param1 * param1 * sizeof(double)); + w = (Modell1*)Malloc(sizeof(Modell1)); + MXSetMatrixPointer((void*)w); + Matrix1 = (double*)Malloc(param1 * param1 * sizeof(double)); dim = w->max_size = param1; matrix_type = param2; w->NumDif = 0; - return (void*) w; + return (void*)w; } /**** Modell 2 ************************************************************/ @@ -642,13 +622,13 @@ void* M2CreateMatrix(long param1, long param2, long /*param3*/) MX_Exit("M2CreateMatrix", 0); #endif - w = (Modell2*) Malloc(sizeof(Modell2)); - MXSetMatrixPointer((void*) w); - w->zeile = (M2_Zeile*) Malloc(param1 * sizeof(M2_Zeile)); + w = (Modell2*)Malloc(sizeof(Modell2)); + MXSetMatrixPointer((void*)w); + w->zeile = (M2_Zeile*)Malloc(param1 * sizeof(M2_Zeile)); for (i = 0; i < param1; i++) { - Zeil2(i).index = (long*) Malloc(sp2_start * sizeof(long)); - Zeil2(i).wert = (double*) Malloc(sp2_start * sizeof(double)); + Zeil2(i).index = (long*)Malloc(sp2_start * sizeof(long)); + Zeil2(i).wert = (double*)Malloc(sp2_start * sizeof(double)); Zeil2(i).max_anz = sp2_start; Zeil2(i).anz = 0; Zeil2(i).min_col = i; @@ -657,7 +637,7 @@ void* M2CreateMatrix(long param1, long param2, long /*param3*/) dim = w->max_size = param1; matrix_type = param2; w->NumDif = 0; - return (void*) w; + return (void*)w; } /**** Modell 3 und 4 ******************************************************/ @@ -671,26 +651,26 @@ void* M34CreateMatrix(long param1, long param2, long /*param3*/) MX_Exit("M34CreateMatrix", 0); #endif - w = (Modell34*) Malloc(sizeof(Modell34)); - MXSetMatrixPointer((void*) w); + w = (Modell34*)Malloc(sizeof(Modell34)); + MXSetMatrixPointer((void*)w); dim = w->max_size = param1; matrix_type = param2; w->usym = matrix_type - 3; w->stat = -1; w->l34_Aik = (w->usym + 1) * 2; w->i34_Bik = w->usym + 1; - w->Diag = (double*) Malloc(param1 * sizeof(double)); + w->Diag = (double*)Malloc(param1 * sizeof(double)); /* Diag. Precond. */ - w->PreD = (double*) Malloc(param1 * sizeof(double)); - w->Spalte = (M34_Spalte*) Malloc(param1 * sizeof(M34_Spalte)); + w->PreD = (double*)Malloc(param1 * sizeof(double)); + w->Spalte = (M34_Spalte*)Malloc(param1 * sizeof(M34_Spalte)); for (i = 0; i < param1; i++) - { /* Start- und Inkrementlaengen wie Modell 2 */ + { /* Start- und Inkrementlaengen wie Modell 2 */ Sp34(i).max_anz = sp2_start; Sp34(i).anz = 0; Sp34(i).rechts = 0; - Sp34(i).Ak = (M34_aik*) Malloc(sp2_start * sizeof(M34_aik)); + Sp34(i).Ak = (M34_aik*)Malloc(sp2_start * sizeof(M34_aik)); } - return (void*) w; /* Die ILU-Pointer sind auch schon initialisiert */ + return (void*)w; /* Die ILU-Pointer sind auch schon initialisiert */ } /************************************************************************* @@ -711,10 +691,10 @@ void* M34CreateMatrix(long param1, long param2, long /*param3*/) *** Modell 1 ************************************************************/ void* M1DestroyMatrix(void) { - Modell1* w = (Modell1*) wurzel; + Modell1* w = (Modell1*)wurzel; if (wurzel == NULL) return NULL; - Matrix1 = (double*) Free(Matrix1); + Matrix1 = (double*)Free(Matrix1); wurzel = Free(w); return NULL; } @@ -722,7 +702,7 @@ void* M1DestroyMatrix(void) /**** Modell 2 ************************************************************/ void* M2DestroyMatrix(void) { - Modell2* w = (Modell2*) wurzel; + Modell2* w = (Modell2*)wurzel; static long i; if (wurzel == NULL) return NULL; @@ -745,10 +725,10 @@ void* M2DestroyMatrix(void) DisplayLong(w->max_size); DisplayMsgLn(""); DisplayMsg(" - Ausgangsgroesse der Zeileneintraege sp2_start: "); - DisplayLong((long) sp2_start); + DisplayLong((long)sp2_start); DisplayMsgLn(""); DisplayMsg(" - Erhoehung der Zeileneintraege sp2_inc: "); - DisplayLong((long) sp2_inc); + DisplayLong((long)sp2_inc); DisplayMsgLn(""); DisplayMsg(" - Anzahl der erhoehten Zeileneintraege: "); DisplayLong(anz_inc); @@ -764,10 +744,10 @@ void* M2DestroyMatrix(void) for (i = 0; i < w->max_size; i++) { - Zeil2(i).index = (long*) Free(Zeil2(i).index); - Zeil2(i).wert = (double*) Free(Zeil2(i).wert); + Zeil2(i).index = (long*)Free(Zeil2(i).index); + Zeil2(i).wert = (double*)Free(Zeil2(i).wert); } - w->zeile = (M2_Zeile*) Free(w->zeile); + w->zeile = (M2_Zeile*)Free(w->zeile); wurzel = Free(w); return NULL; } @@ -776,12 +756,12 @@ void* M2DestroyMatrix(void) void* M34DestroyMatrix(void) { register long i; - Modell34* w = (Modell34*) wurzel; + Modell34* w = (Modell34*)wurzel; if (w == NULL) return NULL; #ifdef TESTMATRIX_PERF - { /* statistische Auswertung der Speicherstruktur */ + { /* statistische Auswertung der Speicherstruktur */ long anz_inc = 0, max_inc = 0, zaehler = 0; for (j = 0; j < w->max_size; j++) { @@ -797,10 +777,10 @@ void* M34DestroyMatrix(void) DisplayLong(w->max_size); DisplayMsgLn(""); DisplayMsg(" - Ausgangsgroesse der Zeileneintraege sp2_start: "); - DisplayLong((long) sp2_start); + DisplayLong((long)sp2_start); DisplayMsgLn(""); DisplayMsg(" - Erhoehung der Zeileneintraege sp2_inc: "); - DisplayLong((long) sp2_inc); + DisplayLong((long)sp2_inc); DisplayMsgLn(""); DisplayMsg(" - Anzahl der erhoehten Zeileneintraege: "); DisplayLong(anz_inc); @@ -815,17 +795,17 @@ void* M34DestroyMatrix(void) #endif for (i = 0; i < w->max_size; i++) - Sp34(i).Ak = (M34_aik*) Free(Sp34(i).Ak); + Sp34(i).Ak = (M34_aik*)Free(Sp34(i).Ak); - w->Spalte = (M34_Spalte*) Free(w->Spalte); - w->Diag = (double*) Free(w->Diag); - w->PreD = (double*) Free(w->PreD); + w->Spalte = (M34_Spalte*)Free(w->Spalte); + w->Diag = (double*)Free(w->Diag); + w->PreD = (double*)Free(w->PreD); wurzel = Free(w); return NULL; } /**** Modell 5 ************************************************************/ -//WW/PA 08/02/2006 +// WW/PA 08/02/2006 void* M5DestroyMatrix(void) { free(jd_ptr1); @@ -836,7 +816,7 @@ void* M5DestroyMatrix(void) free(col_ind); free(jdiag); free(diag5_i); - return (void*) 1; + return (void*)1; } /************************************************************************* @@ -861,7 +841,7 @@ void* M5DestroyMatrix(void) *** Modell 1 ************************************************************/ void M1ResizeMatrix(long dimension) { - Modell1* w = (Modell1*) wurzel; + Modell1* w = (Modell1*)wurzel; #ifdef ERROR_CONTROL if (w == NULL) @@ -873,8 +853,8 @@ void M1ResizeMatrix(long dimension) dim = dimension; if (w->max_size < dimension) { - Matrix1 = (double*) Free(w->matrix); - Matrix1 = (double*) Malloc(dim * dim * sizeof(double)); + Matrix1 = (double*)Free(w->matrix); + Matrix1 = (double*)Malloc(dim * dim * sizeof(double)); w->max_size = dim; } } @@ -882,7 +862,7 @@ void M1ResizeMatrix(long dimension) /**** Modell 2 ************************************************************/ void M2ResizeMatrix(long dimension) { - Modell2* w = (Modell2*) wurzel; + Modell2* w = (Modell2*)wurzel; static long i; #ifdef ERROR_CONTROL @@ -895,11 +875,11 @@ void M2ResizeMatrix(long dimension) dim = dimension; if (w->max_size < dim) { - w->zeile = (M2_Zeile*) Realloc(w->zeile, dim * sizeof(M2_Zeile)); + w->zeile = (M2_Zeile*)Realloc(w->zeile, dim * sizeof(M2_Zeile)); for (i = w->max_size; i < dim; i++) { - Zeil2(i).index = (long*) Malloc(sp2_start * sizeof(long)); - Zeil2(i).wert = (double*) Malloc(sp2_start * sizeof(double)); + Zeil2(i).index = (long*)Malloc(sp2_start * sizeof(long)); + Zeil2(i).wert = (double*)Malloc(sp2_start * sizeof(double)); Zeil2(i).max_anz = sp2_start; Zeil2(i).anz = 0; Zeil2(i).min_col = i; @@ -913,7 +893,7 @@ void M2ResizeMatrix(long dimension) void M34ResizeMatrix(long dimension) { register long i; - Modell34* w = (Modell34*) wurzel; + Modell34* w = (Modell34*)wurzel; #ifdef ERROR_CONTROL if (w == NULL) @@ -926,15 +906,15 @@ void M34ResizeMatrix(long dimension) w->stat = -1; if (w->max_size < dim) { - w->Spalte = (M34_Spalte*) Realloc(w->Spalte, dim * sizeof(M34_Spalte)); - w->Diag = (double*) Realloc(w->Diag, dim * sizeof(double)); - w->PreD = (double*) Realloc(w->PreD, dim * sizeof(double)); + w->Spalte = (M34_Spalte*)Realloc(w->Spalte, dim * sizeof(M34_Spalte)); + w->Diag = (double*)Realloc(w->Diag, dim * sizeof(double)); + w->PreD = (double*)Realloc(w->PreD, dim * sizeof(double)); for (i = w->max_size; i < dim; i++) - { /* Laengen wie Modell 2 */ + { /* Laengen wie Modell 2 */ Sp34(i).max_anz = sp2_start; Sp34(i).anz = 0; Sp34(i).rechts = 0; - Sp34(i).Ak = (M34_aik*) Malloc(sp2_start * sizeof(M34_aik)); + Sp34(i).Ak = (M34_aik*)Malloc(sp2_start * sizeof(M34_aik)); } w->max_size = dim; } @@ -959,7 +939,7 @@ void M34ResizeMatrix(long dimension) *** Modell 1 ************************************************************/ void M1InitMatrix(void) { - Modell1* w = (Modell1*) wurzel; + Modell1* w = (Modell1*)wurzel; register long i, j = dim * dim; for (i = 0; i < j; i++) Matrix1[i] = 0.0; @@ -971,13 +951,13 @@ void M2InitMatrix(void) { register long i; register int j; - Modell2* w = (Modell2*) wurzel; + Modell2* w = (Modell2*)wurzel; for (i = 0; i < dim; i++) { Zeil2(i).anz = 1; for (j = 0; j < Zeil2(i).max_anz; j++) Aik2(i, j) = 0.0; - Ind2(i, 0) = i; /* Diagonale immer in Zeilenelement 0! */ + Ind2(i, 0) = i; /* Diagonale immer in Zeilenelement 0! */ Zeil2(i).min_col = i; Zeil2(i).max_col = i; } @@ -988,18 +968,18 @@ void M2InitMatrix(void) void M34InitMatrix(void) { register long i; - Modell34* w = (Modell34*) wurzel; + Modell34* w = (Modell34*)wurzel; for (i = 0; i < dim; i++) { - w->Diag[i] = 0.0; /* Diagonale */ - Sp34(i).anz = 0; /* geloescht, keine Nebenelemente */ - Sp34(i).rechts = i; /* fuer RDB */ + w->Diag[i] = 0.0; /* Diagonale */ + Sp34(i).anz = 0; /* geloescht, keine Nebenelemente */ + Sp34(i).rechts = i; /* fuer RDB */ } w->stat = 0; } /**** Modell 5 ************************************************************/ -//WW/PA 08/02/2006 +// WW/PA 08/02/2006 void M5InitMatrix(void) { long k; @@ -1029,7 +1009,7 @@ void M5InitMatrix(void) *** Modell 1 *********************************************************** */ int M1Set(long i, long j, double aij) { - Modell1* w = (Modell1*) wurzel; + Modell1* w = (Modell1*)wurzel; #ifdef ERROR_CONTROL if ((i >= dim) || (j >= dim) || (i < 0) || (j < 0)) @@ -1044,7 +1024,7 @@ int M1Set(long i, long j, double aij) /**** Modell 2 ************************************************************/ int M2Set(long i, long j, double aij) { - Modell2* w = (Modell2*) wurzel; + Modell2* w = (Modell2*)wurzel; register int k = 0; #ifdef ERROR_CONTROL @@ -1052,9 +1032,9 @@ int M2Set(long i, long j, double aij) MX_Exit("M2Set", 2); #endif - if(j < Zeil2(i).min_col) + if (j < Zeil2(i).min_col) Zeil2(i).min_col = j; - if(j > Zeil2(i).max_col) + if (j > Zeil2(i).max_col) Zeil2(i).max_col = j; /* Alle Spalteneintraege durchsuchen */ @@ -1064,19 +1044,19 @@ int M2Set(long i, long j, double aij) { Aik2(i, k) = aij; return 0; - } /* gefunden! */ + } /* gefunden! */ k++; } - if (fabs(aij) < MKleinsteZahl ) - return 0; /* Abbruch bei Nullwert */ + if (fabs(aij) < MKleinsteZahl) + return 0; /* Abbruch bei Nullwert */ (Zeil2(i).anz)++; /* Neuen Speicher holen */ if (Zeil2(i).anz > Zeil2(i).max_anz) { Zeil2(i).max_anz += sp2_inc; /* Tabelle vergroessern */ - Zeil2(i).index = (long*) Realloc(Zeil2(i).index, Zeil2(i).max_anz * sizeof(long)); - Zeil2(i).wert = (double*) Realloc(Zeil2(i).wert, Zeil2(i).max_anz * sizeof(double)); + Zeil2(i).index = (long*)Realloc(Zeil2(i).index, Zeil2(i).max_anz * sizeof(long)); + Zeil2(i).wert = (double*)Realloc(Zeil2(i).wert, Zeil2(i).max_anz * sizeof(double)); } Ind2(i, k) = j; Aik2(i, k) = aij; @@ -1090,7 +1070,7 @@ int M34Set(long i1, long k1, double aik) register int j = 0; register long i = i1, k = k1; int u = 0, j1; - Modell34* w = (Modell34*) wurzel; + Modell34* w = (Modell34*)wurzel; #ifdef ERROR_CONTROL if ((i >= dim) || (k >= dim) || (i < 0) || (k < 0)) @@ -1102,11 +1082,11 @@ int M34Set(long i1, long k1, double aik) { w->Diag[i] = aik; return 0; - } /* Diagonalelement */ + } /* Diagonalelement */ if (i > k) - { /* Untermatrixelement */ + { /* Untermatrixelement */ if (!(w->usym)) - return 0; /* symmetrische Matrix, ignorieren */ + return 0; /* symmetrische Matrix, ignorieren */ u = 1; i = k; k = i1; @@ -1118,23 +1098,23 @@ int M34Set(long i1, long k1, double aik) { Aik34(k, j, u) = aik; return 0; - } /* vorhanden */ + } /* vorhanden */ j++; } /* Das Element ist noch nicht vorhanden */ - //WW if (fabs(aik)< MKleinsteZahl) + // WW if (fabs(aik)< MKleinsteZahl) if (fabs(aik) < DBL_MIN) return 0; if (Sp34(k).anz == Sp34(k).max_anz) - { /* Spalte verlaengern */ + { /* Spalte verlaengern */ j1 = Sp34(k).max_anz; Sp34(k).max_anz += sp2_inc; - Sp34(k).Ak = (M34_aik*) Realloc(Sp34(k).Ak, Sp34(k).max_anz * sizeof(M34_aik)); + Sp34(k).Ak = (M34_aik*)Realloc(Sp34(k).Ak, Sp34(k).max_anz * sizeof(M34_aik)); } /* Spalteneintraege sind nach aufsteigender Zeilennummer sortiert! */ - for (j1 = Sp34(k).anz; j1 > j; j1--) /* Rest verschieben */ + for (j1 = Sp34(k).anz; j1 > j; j1--) /* Rest verschieben */ Sp34(k).Ak[j1] = Sp34(k).Ak[j1 - 1]; Sp34(k).anz++; @@ -1142,7 +1122,7 @@ int M34Set(long i1, long k1, double aik) if (w->usym) Aik34(k, j, 1 - u) = 0.0; Aik34(k, j, u) = aik; - Maxim(Sp34(i).rechts, k); /* fuer RDB */ + Maxim(Sp34(i).rechts, k); /* fuer RDB */ return 0; } @@ -1167,7 +1147,7 @@ int M34Set(long i1, long k1, double aik) *** Modell 1 ************************************************************/ int M1Inc(long i, long j, double aij_inc) { - Modell1* w = (Modell1*) wurzel; + Modell1* w = (Modell1*)wurzel; #ifdef ERROR_CONTROL if ((i >= dim) || (j >= dim) || (i < 0) || (j < 0)) @@ -1182,7 +1162,7 @@ int M1Inc(long i, long j, double aij_inc) /**** Modell 2 ************************************************************/ int M2Inc(long i, long j, double aij_inc) { - Modell2* w = (Modell2*) wurzel; + Modell2* w = (Modell2*)wurzel; register int k = 0; #ifdef ERROR_CONTROL @@ -1191,18 +1171,18 @@ int M2Inc(long i, long j, double aij_inc) #endif if (fabs(aij_inc) < MKleinsteZahl) - return 0; /* Abbruch bei Nullwert */ + return 0; /* Abbruch bei Nullwert */ while (k < Zeil2(i).anz) - { /* alle Eintraege durchsuchen */ + { /* alle Eintraege durchsuchen */ if (j == Ind2(i, k)) { Aik2(i, k) += aij_inc; return 0; - } /* gefunden! */ + } /* gefunden! */ k++; } Maxim(w->NumDif, labs(i - j)); - return M2Set(i, j, aij_inc); /* neuer Eintrag */ + return M2Set(i, j, aij_inc); /* neuer Eintrag */ } /**** Modell 3, 4 *********************************************************/ @@ -1211,7 +1191,7 @@ int M34Inc(long i1, long k1, double aik) register int j = 0; register long i = i1, k = k1; int u = 0; - Modell34* w = (Modell34*) wurzel; + Modell34* w = (Modell34*)wurzel; #ifdef ERROR_CONTROL if ((i >= dim) || (k >= dim) || (i < 0) || (k < 0)) @@ -1223,11 +1203,11 @@ int M34Inc(long i1, long k1, double aik) { w->Diag[i] += aik; return 0; - } /* Diagonalelement */ + } /* Diagonalelement */ if (i > k) - { /* Untermatrixelement */ + { /* Untermatrixelement */ if (!(w->usym)) - return 0; /* symmetrische Matrix, ignorieren */ + return 0; /* symmetrische Matrix, ignorieren */ u = 1; i = k; k = i1; @@ -1242,7 +1222,7 @@ int M34Inc(long i1, long k1, double aik) } j++; } - return M34Set(i1, k1, aik); /* war noch nicht vorhanden */ + return M34Set(i1, k1, aik); /* war noch nicht vorhanden */ } /************************************************************************* @@ -1288,7 +1268,7 @@ int MX_Dec(long i, long j, double aij_dec) *** Modell 1 ************************************************************/ int M1Mul(long i, long j, double aij_mul) { - Modell1* w = (Modell1*) wurzel; + Modell1* w = (Modell1*)wurzel; #ifdef ERROR_CONTROL if ((i >= dim) || (j >= dim) || (i < 0) || (j < 0)) @@ -1302,7 +1282,7 @@ int M1Mul(long i, long j, double aij_mul) /**** Modell 2 ************************************************************/ int M2Mul(long i, long j, double aij_mul) { - Modell2* w = (Modell2*) wurzel; + Modell2* w = (Modell2*)wurzel; register int k = 0; #ifdef ERROR_CONTROL @@ -1311,12 +1291,12 @@ int M2Mul(long i, long j, double aij_mul) #endif while (k < Zeil2(i).anz) - { /* Alle Eintraege durchsuchen */ + { /* Alle Eintraege durchsuchen */ if (j == Ind2(i, k)) { Aik2(i, k) *= aij_mul; return 0; - } /* gefunden! */ + } /* gefunden! */ k++; } return 0; @@ -1325,7 +1305,7 @@ int M2Mul(long i, long j, double aij_mul) /**** Modell 3, 4 *********************************************************/ int M34Mul(long i1, long k1, double aik) { - Modell34* w = (Modell34*) wurzel; + Modell34* w = (Modell34*)wurzel; register int j = 0; register long i = i1, k = k1; int u = 0; @@ -1340,11 +1320,11 @@ int M34Mul(long i1, long k1, double aik) { w->Diag[i] *= aik; return 0; - } /* Diagonalelement */ + } /* Diagonalelement */ if (i > k) - { /* Untermatrixelement */ + { /* Untermatrixelement */ if (!(w->usym)) - return 0; /* symmetrische Matrix, ignorieren */ + return 0; /* symmetrische Matrix, ignorieren */ u = 1; i = k; k = i1; @@ -1359,7 +1339,7 @@ int M34Mul(long i1, long k1, double aik) } j++; } - return 0; /* Element nicht vorhanden */ + return 0; /* Element nicht vorhanden */ } /************************************************************************* @@ -1382,7 +1362,7 @@ int M34Mul(long i1, long k1, double aik) *** nicht modellspezifisch! *********************************************/ int MX_Div(long i, long j, double aij_div) { - return MXMul(i, j, (double) 1.0 / aij_div); + return MXMul(i, j, (double)1.0 / aij_div); } /************************************************************************* @@ -1404,7 +1384,7 @@ int MX_Div(long i, long j, double aij_div) *** Modell 1 ************************************************************/ double M1Get(long i, long j) { - Modell1* w = (Modell1*) wurzel; + Modell1* w = (Modell1*)wurzel; #ifdef ERROR_CONTROL if ((i >= dim) || (j >= dim) || (i < 0) || (j < 0)) @@ -1417,7 +1397,7 @@ double M1Get(long i, long j) /**** Modell 2 ************************************************************/ double M2Get(long i, long j) { - Modell2* w = (Modell2*) wurzel; + Modell2* w = (Modell2*)wurzel; register int k = 0; #ifdef ERROR_CONTROL @@ -1429,18 +1409,18 @@ double M2Get(long i, long j) return 0.; while (k < Zeil2(i).anz) - { /* Alle Eintraege durchsuchen */ + { /* Alle Eintraege durchsuchen */ if (j == Ind2(i, k)) - return Aik2(i, k); /* gefunden! */ + return Aik2(i, k); /* gefunden! */ k++; } - return 0.0; /* Kein Eintrag gefunden */ + return 0.0; /* Kein Eintrag gefunden */ } /**** Modell 3,4 **********************************************************/ double M34Get(long i1, long k1) { - Modell34* w = (Modell34*) wurzel; + Modell34* w = (Modell34*)wurzel; register int j = 0; register long i = i1, k = k1; int u = 0; @@ -1451,13 +1431,13 @@ double M34Get(long i1, long k1) #endif if (i == k) - return w->Diag[i]; /* Diagonalelement */ + return w->Diag[i]; /* Diagonalelement */ if (i > k) { u = w->usym; i = k; k = i1; - } /* Untermatrixelement */ + } /* Untermatrixelement */ /* Alle Spalteneintraege durchsuchen */ while (j < Sp34(k).anz && i >= Ind34(k, j)) { @@ -1465,13 +1445,13 @@ double M34Get(long i1, long k1) return Aik34(k, j, u); j++; } - return 0.0; /* Element ist nicht vorhanden */ + return 0.0; /* Element ist nicht vorhanden */ } -//WW/PA 08/02/2006 +// WW/PA 08/02/2006 double M5Get(long i, long j) { - MeshLib::CFEMesh const* const mesh (FEMGet("GROUNDWATER_FLOW")); + MeshLib::CFEMesh const* const mesh(FEMGet("GROUNDWATER_FLOW")); const long dim1 = mesh->NodesInUsage(); #ifdef ERROR_CONTROL @@ -1479,24 +1459,24 @@ double M5Get(long i, long j) MX_Exit("M5Get", 2); #endif - const size_t jj (mesh->Eqs2Global_NodeIndex[j]); - CNode const* const nod_i (mesh->nod_vector[mesh->Eqs2Global_NodeIndex[i]]); - std::vector const& connected_nodes (nod_i->getConnectedNodes()); - const size_t n_connected_nodes (connected_nodes.size()); + const size_t jj(mesh->Eqs2Global_NodeIndex[j]); + CNode const* const nod_i(mesh->nod_vector[mesh->Eqs2Global_NodeIndex[i]]); + std::vector const& connected_nodes(nod_i->getConnectedNodes()); + const size_t n_connected_nodes(connected_nodes.size()); - for(size_t k = 0; k < n_connected_nodes; k++) - if(connected_nodes[k] == jj) - //TEST WW return jdiag[m_nod_i->m5_index[k]]; + for (size_t k = 0; k < n_connected_nodes; k++) + if (connected_nodes[k] == jj) + // TEST WW return jdiag[m_nod_i->m5_index[k]]; break; - return 0.0; /* Kein Eintrag gefunden */ + return 0.0; /* Kein Eintrag gefunden */ } -//WW/PA 08/02/2006 +// WW/PA 08/02/2006 int M5Set(long i, long j, double e_val) { long dim1; - e_val = e_val; //OK411 + e_val = e_val; // OK411 MeshLib::CFEMesh const* const mesh(FEMGet("GROUNDWATER_FLOW")); // CNode *m_nod_j = NULL; dim1 = mesh->NodesInUsage(); @@ -1506,17 +1486,17 @@ int M5Set(long i, long j, double e_val) MX_Exit("M5Get", 2); #endif - const size_t jj (mesh->Eqs2Global_NodeIndex[j]); - CNode const* const nod_i (mesh->nod_vector[mesh->Eqs2Global_NodeIndex[i]]); - std::vector const& connected_nodes (nod_i->getConnectedNodes()); - const size_t n_connected_nodes (connected_nodes.size()); + const size_t jj(mesh->Eqs2Global_NodeIndex[j]); + CNode const* const nod_i(mesh->nod_vector[mesh->Eqs2Global_NodeIndex[i]]); + std::vector const& connected_nodes(nod_i->getConnectedNodes()); + const size_t n_connected_nodes(connected_nodes.size()); - for(size_t k = 0; k < n_connected_nodes; k++) - if(connected_nodes[k] == jj) - //TEST WW jdiag[m_nod_i->m5_index[k]] = e_val; + for (size_t k = 0; k < n_connected_nodes; k++) + if (connected_nodes[k] == jj) + // TEST WW jdiag[m_nod_i->m5_index[k]] = e_val; break; - return 0; /* Kein Eintrag gefunden */ + return 0; /* Kein Eintrag gefunden */ } /************************************************************************* @@ -1540,16 +1520,8 @@ int M5Set(long i, long j, double e_val) 1/2004 TK Compiler Warning: Unreferenced formal parameters deleted *****************************************************************************/ -int M1CopyToAMG1R5Structure(double* A, - int* IA, - int* JA, - int /*NDA*/, - int /*NDIA*/, - int /*NDJA*/, - double* x, - double* U, - double* b, - double* F) +int M1CopyToAMG1R5Structure(double* A, int* IA, int* JA, int /*NDA*/, int /*NDIA*/, int /*NDJA*/, double* x, double* U, + double* b, double* F) { long i, j, NNA = 0, NIA = 0; double a; @@ -1562,7 +1534,7 @@ int M1CopyToAMG1R5Structure(double* A, /* Diagonale eintragen */ j = i; - a = MXGet(i,j); + a = MXGet(i, j); A[NNA] = a; JA[NNA] = j + 1; @@ -1573,8 +1545,8 @@ int M1CopyToAMG1R5Structure(double* A, for (j = 0; j < dim; j++) { /* Restmatrix eintragen */ - a = MXGet(i,j); - if((fabs(a) > MKleinsteZahl) && (i != j)) + a = MXGet(i, j); + if ((fabs(a) > MKleinsteZahl) && (i != j)) { A[NNA] = a; JA[NNA] = j + 1; @@ -1587,21 +1559,13 @@ int M1CopyToAMG1R5Structure(double* A, return 0; } -int M2CopyToAMG1R5Structure(double* A, - int* IA, - int* JA, - int /*NDA*/, - int /*NDIA*/, - int /*NDJA*/, - double* x, - double* U, - double* b, - double* F) +int M2CopyToAMG1R5Structure(double* A, int* IA, int* JA, int /*NDA*/, int /*NDIA*/, int /*NDJA*/, double* x, double* U, + double* b, double* F) { long i, j; long NNA = 0, NIA = 0; double a; - Modell2* w = (Modell2*) wurzel; + Modell2* w = (Modell2*)wurzel; register int k; for (i = 0; i < dim; i++) @@ -1619,9 +1583,9 @@ int M2CopyToAMG1R5Structure(double* A, IA[NIA] = NNA; NIA++; - k = 1; /* Diagonale ist schon beruecksichtigt */ + k = 1; /* Diagonale ist schon beruecksichtigt */ while (k < Zeil2(i).anz) - { /* Alle Eintraege durchsuchen */ + { /* Alle Eintraege durchsuchen */ j = Ind2(i, k); a = Aik2(i, k); A[NNA] = a; @@ -1635,16 +1599,8 @@ int M2CopyToAMG1R5Structure(double* A, return 0; } -int M34CopyToAMG1R5Structure(double* A, - int* IA, - int* JA, - int /*NDA*/, - int /*NDIA*/, - int /*NDJA*/, - double* x, - double* U, - double* b, - double* F) +int M34CopyToAMG1R5Structure(double* A, int* IA, int* JA, int /*NDA*/, int /*NDIA*/, int /*NDJA*/, double* x, double* U, + double* b, double* F) { long i, j, NNA = 0, NIA = 0; double a; @@ -1657,7 +1613,7 @@ int M34CopyToAMG1R5Structure(double* A, U[i] = x[i]; F[i] = b[i]; - a = MXGet(i,j); + a = MXGet(i, j); A[NNA] = a; JA[NNA] = j + 1; NNA++; @@ -1666,8 +1622,8 @@ int M34CopyToAMG1R5Structure(double* A, for (j = 0; j < dim; j++) { - a = MXGet(i,j); - if((fabs(a) > MKleinsteZahl) && (i != j)) + a = MXGet(i, j); + if ((fabs(a) > MKleinsteZahl) && (i != j)) { A[NNA] = a; JA[NNA] = j + 1; @@ -1724,7 +1680,7 @@ void MX_Trans(long i, long j, long ii, long jj) *** Modell 1 ************************************************************/ void M1MatVek(double* vektor, double* ergebnis) { - Modell1* w = (Modell1*) wurzel; + Modell1* w = (Modell1*)wurzel; register long i, k; #ifdef ERROR_CONTROL @@ -1744,7 +1700,7 @@ void M1MatVek(double* vektor, double* ergebnis) /****** Permutation when transforming from Modell2 to Modell 5 JAD ********/ /**** Modell 2 ************************************************************/ -//WW/PA 08/02/2006 +// WW/PA 08/02/2006 int M5Inc(long i, long j, double aij_inc) { MeshLib::CFEMesh const* const mesh(FEMGet("GROUNDWATER_FLOW")); @@ -1755,7 +1711,7 @@ int M5Inc(long i, long j, double aij_inc) MX_Exit("M5Inc", 2); #endif if (fabs(aij_inc) < MKleinsteZahl) - return 0; /* Abbruch bei Nullwert */ + return 0; /* Abbruch bei Nullwert */ const size_t jj(mesh->Eqs2Global_NodeIndex[j]); CNode const* const nod_i(mesh->nod_vector[mesh->Eqs2Global_NodeIndex[i]]); @@ -1763,13 +1719,13 @@ int M5Inc(long i, long j, double aij_inc) const size_t n_connected_nodes(connected_nodes.size()); for (size_t k = 0; k < n_connected_nodes; k++) if (connected_nodes[k] == jj) - //TEST WW jdiag[m_nod_i->m5_index[k]] += aij_inc; + // TEST WW jdiag[m_nod_i->m5_index[k]] += aij_inc; break; return 1; } -//WW/PA 08/02/2006 +// WW/PA 08/02/2006 /* void Write_Matrix_M5(double *b, ostream& os) { @@ -1794,22 +1750,22 @@ int M5Inc(long i, long j, double aij_inc) } */ -//void transM2toM5(void) -//void M5CreateMatrix(void) -//PA/WW 08/02/2006 +// void transM2toM5(void) +// void M5CreateMatrix(void) +// PA/WW 08/02/2006 void* M5CreateMatrix(long param1, long param2, long param3) { param1 = param1; param3 = param3; // - Modell5* w = (Modell5*) wurzel; - w = (Modell5*) Malloc(sizeof(Modell5)); - MXSetMatrixPointer((void*) w); + Modell5* w = (Modell5*)wurzel; + w = (Modell5*)Malloc(sizeof(Modell5)); + MXSetMatrixPointer((void*)w); matrix_type = param2; - int i, ii,jj,count1; - long k, index, Size, dim1; //OK + int i, ii, jj, count1; + long k, index, Size, dim1; // OK /*------------------------------------------------------------*/ jd_ptr_max = 0; MeshLib::CFEMesh* m_msh = NULL; @@ -1822,9 +1778,9 @@ void* M5CreateMatrix(long param1, long param2, long param3) for (k = 0; k < dim1; k++) { index = m_msh->Eqs2Global_NodeIndex[k]; // - //WW + // WW Size = (int)m_msh->nod_vector[index]->getConnectedNodes().size(); - if ( Size > jd_ptr_max ) + if (Size > jd_ptr_max) jd_ptr_max = Size; #ifdef SX #pragma cdir nodep @@ -1850,7 +1806,7 @@ void* M5CreateMatrix(long param1, long param2, long param3) for (k = 0; k < dim1; k++) { index = m_msh->Eqs2Global_NodeIndex[k]; // - //WW + // WW Size = (int)m_msh->nod_vector[index]->getConnectedNodes().size(); for (i = 0; i < Size; i++) jd_ptr[i]++; @@ -1860,7 +1816,7 @@ void* M5CreateMatrix(long param1, long param2, long param3) { // printf("Zeil2(%d).anz=%d\n",k,Zeil2(k).anz); index = m_msh->Eqs2Global_NodeIndex[k]; // - // Zeil2(k).anz; + // Zeil2(k).anz; jd_ptr1[k] = (int)m_msh->nod_vector[index]->getConnectedNodes().size(); jd_ptr2[k] = k; } @@ -1871,7 +1827,7 @@ void* M5CreateMatrix(long param1, long param2, long param3) for(k=0;kEqs2Global_NodeIndex[ii]; + index = m_msh->Eqs2Global_NodeIndex[ii]; // col_ind[count1] = m_msh->go[m_msh->nod_vector[index]->connected_nodes[k]]; col_i = m_msh->nod_vector[index]->getConnectedNodes()[k]; col_ind[count1] = m_msh->nod_vector[col_i]->GetEquationIndex(); jj = col_ind[count1]; - //TEST WW m_msh->nod_vector[index]->m5_index[k]=count1; - if(ii == jj) + // TEST WW m_msh->nod_vector[index]->m5_index[k]=count1; + if (ii == jj) diag5_i[ii] = count1; - //TEST WW OUT + // TEST WW OUT // cout<<" Row: "<< ii<<" "<< col_ind[count1]<<" "; // cout< itpack_max ) + if (Zeil2(k).anz > itpack_max) itpack_max = Zeil2(k).anz; itpackv = (double*)malloc(itpack_max * dim1 * sizeof(double)); @@ -2009,19 +1965,19 @@ void transM2toM6(void) // temp_ergebnis = (double *)malloc(dim*sizeof(double)); count1 = 0; - for(i = 0; i < itpack_max; i++) - for(k = 0; k < dim1; k++) + for (i = 0; i < itpack_max; i++) + for (k = 0; k < dim1; k++) { - if (i < Zeil2(k).anz ) + if (i < Zeil2(k).anz) { - itpackv[count1] = Aik2(k,i); - it_col[count1] = Ind2(k,i); + itpackv[count1] = Aik2(k, i); + it_col[count1] = Ind2(k, i); count1++; } else { itpackv[count1] = 0.0; - it_col[count1] = Ind2(0,0); + it_col[count1] = Ind2(0, 0); count1++; } } @@ -2041,13 +1997,13 @@ void transM2toM6(void) /**** Modell 2 ************************************************************/ void M2MatVek(double* vektor, double* ergebnis) { - Modell2* w = (Modell2*) wurzel; + Modell2* w = (Modell2*)wurzel; register long k; register int i; #ifdef CBLAS_M2MatVek double* help; - help = (double*) Malloc(dim * sizeof(double)); + help = (double*)Malloc(dim * sizeof(double)); #endif #ifdef ERROR_CONTROL @@ -2074,7 +2030,7 @@ void M2MatVek(double* vektor, double* ergebnis) } #ifdef CBLAS_M2MatVek - help = (double*) Free(help); + help = (double*)Free(help); #endif } @@ -2089,10 +2045,10 @@ void M5MatVek(double* b, double* erg) #endif { // Modell2 *w = (Modell2 *) wurzel; - int i, dim1; //k, + int i, dim1; // k, int j, num; long col_len; - MeshLib::CFEMesh* m_msh = NULL; //WW + MeshLib::CFEMesh* m_msh = NULL; // WW m_msh = FEMGet("GROUNDWATER_FLOW"); dim1 = m_msh->NodesInUsage(); @@ -2109,11 +2065,11 @@ void M5MatVek(double* b, double* erg) { col_len = jd_ptrf[i + 1] - jd_ptrf[i]; num = jd_ptrf[i]; - // printf("num=%d\n",num); - // printf("col_len=%d\n",col_len); +// printf("num=%d\n",num); +// printf("col_len=%d\n",col_len); #ifdef _OPENMP -#pragma omp parallel for private(j) shared(temp_ergebnis,jdiag,b,num,col_ind) +#pragma omp parallel for private(j) shared(temp_ergebnis, jdiag, b, num, col_ind) #endif #ifdef SX #pragma cdir nodep @@ -2125,7 +2081,7 @@ void M5MatVek(double* b, double* erg) #ifdef SX #pragma cdir nodep #endif - for(i = 0; i < dim1; i++) + for (i = 0; i < dim1; i++) erg[jd_ptr2[i]] = temp_ergebnis[i]; } @@ -2139,7 +2095,7 @@ void M6MatVek(double* b, double* erg) #endif { // Modell2 *w = (Modell2 *) wurzel; - int i,j,num, dim1; + int i, j, num, dim1; dim1 = ((long*)wurzel)[0]; @@ -2153,7 +2109,7 @@ void M6MatVek(double* b, double* erg) // printf("In M6MatVek itpack_max=%d\n",itpack_max); for (i = 0; i < itpack_max; i++) { - //#pragma omp parallel for private(j) shared(erg,itpackv,b,num,it_col) +//#pragma omp parallel for private(j) shared(erg,itpackv,b,num,it_col) #ifdef SX #pragma cdir nodep #endif @@ -2172,10 +2128,10 @@ void H_MX34_mul(double* x, double* r, int o) Die Vektoren x und r muessen allokiert sein! */ { - Modell34* w = (Modell34*) wurzel; + Modell34* w = (Modell34*)wurzel; register long k, i; register int j; - int u = 1 - o; /* o=0: normal, o=1: mit Transponierter */ + int u = 1 - o; /* o=0: normal, o=1: mit Transponierter */ #ifdef ERROR_CONTROL if ((x == NULL) || (r == NULL)) @@ -2186,7 +2142,7 @@ void H_MX34_mul(double* x, double* r, int o) { o = 0; u = 0; - } /* symmetrische Matrix: Oik=Uki */ + } /* symmetrische Matrix: Oik=Uki */ for (k = 0; k < dim; k++) { r[k] = w->Diag[k] * x[k]; @@ -2204,7 +2160,7 @@ void H_MX34_mul(double* x, double* r, int o) void M34MatVek(double* vektor, double* ergebnis) { - H_MX34_mul(vektor, ergebnis, (int) 0); + H_MX34_mul(vektor, ergebnis, (int)0); } /************************************************************************* @@ -2229,7 +2185,7 @@ void M34MatVek(double* vektor, double* ergebnis) *** Modell 1 ***********************************************************/ void M1MatTVek(double* vektor, double* ergebnis) { - Modell1* w = (Modell1*) wurzel; + Modell1* w = (Modell1*)wurzel; register long i, k; #ifdef ERROR_CONTROL @@ -2248,7 +2204,7 @@ void M1MatTVek(double* vektor, double* ergebnis) /**** Modell 2 ***********************************************************/ void M2MatTVek(double* vektor, double* ergebnis) { - Modell2* w = (Modell2*) wurzel; + Modell2* w = (Modell2*)wurzel; register long k; register int i; @@ -2267,7 +2223,7 @@ void M2MatTVek(double* vektor, double* ergebnis) /**************************************************************************/ void M34MatTVek(double* vektor, double* ergebnis) { - H_MX34_mul(vektor, ergebnis, (int) 1); /* siehe M34MatVek */ + H_MX34_mul(vektor, ergebnis, (int)1); /* siehe M34MatVek */ } /************************************************************************* @@ -2306,14 +2262,14 @@ void MXResiduum(double* x, double* b, double* ergebnis) MXMatVek(x, ergebnis); - //WW + // WW long Dimension = 0; - if(matrix_type == 5) + if (matrix_type == 5) Dimension = Dim_L; else Dimension = dim; // - //WW + // WW MAddSkalVektoren(ergebnis, -1., b, 1., ergebnis, Dimension); } @@ -2341,7 +2297,7 @@ void MXResiduum(double* x, double* b, double* ergebnis) *** Unterscheidung nach Modell innerhalb der Prozedur! ******************/ void MXRandbed(long ir, double Ri, double* ReSei) { - register long i=0, ip, im; + register long i = 0, ip, im; long p, q; int k; double diag; @@ -2357,11 +2313,11 @@ void MXRandbed(long ir, double Ri, double* ReSei) { ip = ir + i; im = ir - i; - if(ip < dim) - if(fabs(diag = MXGet(ip, ip)) > DBL_MIN) + if (ip < dim) + if (fabs(diag = MXGet(ip, ip)) > DBL_MIN) break; - if(im >= 0) - if(fabs(diag = MXGet(im, im)) > DBL_MIN) + if (im >= 0) + if (fabs(diag = MXGet(im, im)) > DBL_MIN) break; } @@ -2369,7 +2325,7 @@ void MXRandbed(long ir, double Ri, double* ReSei) if (fabs(diag) < DBL_MIN) diag = MKleinsteZahl; - //TEST WW + // TEST WW /* #ifdef ERROR_CONTROL if ((ir >= dim) || (ir < 0)) @@ -2380,147 +2336,147 @@ void MXRandbed(long ir, double Ri, double* ReSei) */ switch (matrix_type) { - case 1: - { - Modell1* w = (Modell1*) wurzel; - p = ir - w->NumDif; - if (p < 0) - p = 0; - q = ir + w->NumDif + 1; - if (q > dim) - q = dim; - for (i = p; i < q; i++) + case 1: { - ReSei[i] -= Aik1(i, ir) * Ri; /* Spalte ausmultiplizieren */ - Aik1(i, ir) = Aik1(ir, i) = 0.0; /* Spalte und Zeile Null setzen */ - } - ReSei[ir] = Ri * diag; /* Randwert einsetzen */ - MXSet(ir, ir, diag); - } - break; - - case 2: - { - Modell2* w = (Modell2*) wurzel; - p = ir - w->NumDif; - if (p < 0) - p = 0; - q = ir + w->NumDif + 1; - if (q > dim) - q = dim; - for (i = p; i < q; i++) - if (i != ir) - { /* alle anderen Zeilen mit Spalte iR */ - k = 0; - while (++k < Zeil2(i).anz) /* Alle Eintraege (ausser Diag.) */ - if (ir == Ind2(i, k)) - { - ReSei[i] -= Aik2(i, k) * Ri; - Aik2(i, k) = 0.0; - goto End_Zeil; - } /*[i,iR] */ -End_Zeil:; + Modell1* w = (Modell1*)wurzel; + p = ir - w->NumDif; + if (p < 0) + p = 0; + q = ir + w->NumDif + 1; + if (q > dim) + q = dim; + for (i = p; i < q; i++) + { + ReSei[i] -= Aik1(i, ir) * Ri; /* Spalte ausmultiplizieren */ + Aik1(i, ir) = Aik1(ir, i) = 0.0; /* Spalte und Zeile Null setzen */ } + ReSei[ir] = Ri * diag; /* Randwert einsetzen */ + MXSet(ir, ir, diag); + } + break; - for (k = 0; k < Zeil2(ir).anz; k++) - Aik2(ir, k) = 0.0; /* Rest der Zeile Null */ - ReSei[ir] = Ri * diag; /* Randwert einsetzen */ - MXSet(ir, ir, diag); - } - break; + case 2: + { + Modell2* w = (Modell2*)wurzel; + p = ir - w->NumDif; + if (p < 0) + p = 0; + q = ir + w->NumDif + 1; + if (q > dim) + q = dim; + for (i = p; i < q; i++) + if (i != ir) + { /* alle anderen Zeilen mit Spalte iR */ + k = 0; + while (++k < Zeil2(i).anz) /* Alle Eintraege (ausser Diag.) */ + if (ir == Ind2(i, k)) + { + ReSei[i] -= Aik2(i, k) * Ri; + Aik2(i, k) = 0.0; + goto End_Zeil; + } /*[i,iR] */ + End_Zeil:; + } - case 3: - case 4: - { - Modell34* w = (Modell34*) wurzel; - int u = w->usym; - for (k = 0; k < Sp34(ir).anz; k++) - { /* ueber (links von) Diag. */ - /* Obermatrix ausmultipl. */ - ReSei[Ind34(ir, k)] -= Aik34(ir, k, 0) * Ri; - /* Zeile / Spalte Null */ - Aik34(ir, k, 0) = Aik34(ir, k, u) = 0.0; + for (k = 0; k < Zeil2(ir).anz; k++) + Aik2(ir, k) = 0.0; /* Rest der Zeile Null */ + ReSei[ir] = Ri * diag; /* Randwert einsetzen */ + MXSet(ir, ir, diag); } + break; - MXSet(ir, ir, diag); /* Randwert einsetzen */ - ReSei[ir] = Ri * diag; + case 3: + case 4: + { + Modell34* w = (Modell34*)wurzel; + int u = w->usym; + for (k = 0; k < Sp34(ir).anz; k++) + { /* ueber (links von) Diag. */ + /* Obermatrix ausmultipl. */ + ReSei[Ind34(ir, k)] -= Aik34(ir, k, 0) * Ri; + /* Zeile / Spalte Null */ + Aik34(ir, k, 0) = Aik34(ir, k, u) = 0.0; + } - for (i = ir + 1; i <= Sp34(ir).rechts; i++) - for (k = 0; k < Sp34(i).anz; k++) - { - if (Ind34(i, k) > ir) - break; - if (Ind34(i, k) == ir) + MXSet(ir, ir, diag); /* Randwert einsetzen */ + ReSei[ir] = Ri * diag; + + for (i = ir + 1; i <= Sp34(ir).rechts; i++) + for (k = 0; k < Sp34(i).anz; k++) { - ReSei[i] -= Aik34(i, k, u) * Ri; /* Untermatrix ausmult. */ - /* Zeile / Spalte Null */ - Aik34(i, k, 0) = Aik34(i, k, u) = 0.0; + if (Ind34(i, k) > ir) + break; + if (Ind34(i, k) == ir) + { + ReSei[i] -= Aik34(i, k, u) * Ri; /* Untermatrix ausmult. */ + /* Zeile / Spalte Null */ + Aik34(i, k, 0) = Aik34(i, k, u) = 0.0; + } } - } - w->stat = 1; /* Matrix veraendert! */ - } - break; - case 5: //WW/PA 08/02/2006 - { - //WW long dim1; - long jr; - MeshLib::CFEMesh const* const mesh(FEMGet("GROUNDWATER_FLOW")); - CNode* m_nod_j = NULL; - //WW dim1 = m_msh->NodesInUsage(); - ReSei[ir] = Ri * MXGet(ir,ir); - - CNode const* const nod_i(mesh->nod_vector[mesh->Eqs2Global_NodeIndex[i]]); // TODO check this. i could be 0. - std::vector const& connected_nodes(nod_i->getConnectedNodes()); - const size_t n_connected_nodes(connected_nodes.size()); - - for(size_t k = 0; k < n_connected_nodes; k++) - { - m_nod_j = mesh->nod_vector[connected_nodes[k]]; - jr = m_nod_j->GetEquationIndex(); - if(ir == jr) - continue; - MXSet(ir,jr,0.0); - ReSei[jr] -= MXGet(jr,ir) * Ri; - MXSet(jr,ir,0.0); + w->stat = 1; /* Matrix veraendert! */ } - } - break; - case 6: - { - Modell2* w = (Modell2*) wurzel; - p = ir - w->NumDif; - if (p < 0) - p = 0; - q = ir + w->NumDif + 1; - if (q > dim) - q = dim; - for (i = p; i < q; i++) - if (i != ir) - { /* alle anderen Zeilen mit Spalte iR */ - k = 0; - while (++k < Zeil2(i).anz) /* Alle Eintraege (ausser Diag.) */ - if (ir == Ind2(i, k)) - { - ReSei[i] -= Aik2(i, k) * Ri; - Aik2(i, k) = 0.0; - goto End_Zeil6; - } /*[i,iR] */ -End_Zeil6:; + break; + case 5: // WW/PA 08/02/2006 + { + // WW long dim1; + long jr; + MeshLib::CFEMesh const* const mesh(FEMGet("GROUNDWATER_FLOW")); + CNode* m_nod_j = NULL; + // WW dim1 = m_msh->NodesInUsage(); + ReSei[ir] = Ri * MXGet(ir, ir); + + CNode const* const nod_i(mesh->nod_vector[mesh->Eqs2Global_NodeIndex[i]]); // TODO check this. i could be 0. + std::vector const& connected_nodes(nod_i->getConnectedNodes()); + const size_t n_connected_nodes(connected_nodes.size()); + + for (size_t k = 0; k < n_connected_nodes; k++) + { + m_nod_j = mesh->nod_vector[connected_nodes[k]]; + jr = m_nod_j->GetEquationIndex(); + if (ir == jr) + continue; + MXSet(ir, jr, 0.0); + ReSei[jr] -= MXGet(jr, ir) * Ri; + MXSet(jr, ir, 0.0); } + } + break; + case 6: + { + Modell2* w = (Modell2*)wurzel; + p = ir - w->NumDif; + if (p < 0) + p = 0; + q = ir + w->NumDif + 1; + if (q > dim) + q = dim; + for (i = p; i < q; i++) + if (i != ir) + { /* alle anderen Zeilen mit Spalte iR */ + k = 0; + while (++k < Zeil2(i).anz) /* Alle Eintraege (ausser Diag.) */ + if (ir == Ind2(i, k)) + { + ReSei[i] -= Aik2(i, k) * Ri; + Aik2(i, k) = 0.0; + goto End_Zeil6; + } /*[i,iR] */ + End_Zeil6:; + } - for (k = 0; k < Zeil2(ir).anz; k++) - Aik2(ir, k) = 0.0; /* Rest der Zeile Null */ - ReSei[ir] = Ri * diag; /* Randwert einsetzen */ - MXSet(ir, ir, diag); - } - break; + for (k = 0; k < Zeil2(ir).anz; k++) + Aik2(ir, k) = 0.0; /* Rest der Zeile Null */ + ReSei[ir] = Ri * diag; /* Randwert einsetzen */ + MXSet(ir, ir, diag); + } + break; #ifdef ERROR_CONTROL - default: - MX_Exit("MXRandbed", 4); + default: + MX_Exit("MXRandbed", 4); #endif } -} /* MXRandbed */ +} /* MXRandbed */ /************************************************************************* ROCKFLOW - Funktion: MXEliminateIrrNode @@ -2547,7 +2503,7 @@ End_Zeil6:; void MXEliminateIrrNode(long index, int anz_nachbarn, long* nachbarn_index, double* rechts) { long zeile, spalte, j, k, l; - double inc, gewicht = 1. / (double) anz_nachbarn, diag = MXGet(index, index); + double inc, gewicht = 1. / (double)anz_nachbarn, diag = MXGet(index, index); #ifdef ERROR_CONTROL if ((index >= dim) || (index < 0)) @@ -2558,406 +2514,406 @@ void MXEliminateIrrNode(long index, int anz_nachbarn, long* nachbarn_index, doub switch (matrix_type) { - default: - { - /* Spalte des irr. Knotens eliminieren : */ - /* Ueber alle Zeilen gehen, um nach Eintragen fuer den Knoten zu suchen */ - for (j = 0l; j < dim; j++) + default: { - /* Der Knoteneintrag wird ausmultipliziert und den Nachbarn zugeschlagen */ - /* index ist der irregulaere Knoten, j ist die Zeile, nachbarn_index die Spalte */ - inc = gewicht * MXGet(j, index); - if (fabs(inc) > 0.) - for (k = 0; k < anz_nachbarn; k++) - MXInc(j, nachbarn_index[k], inc); - - /* Spalte des Knotens zu Null setzen, da der Wert oben verteilt wurde */ - if (fabs(MXGet(j, index)) > 0.) - MXSet(j, index, 0.); - } /* endfor j */ + /* Spalte des irr. Knotens eliminieren : */ + /* Ueber alle Zeilen gehen, um nach Eintragen fuer den Knoten zu suchen */ + for (j = 0l; j < dim; j++) + { + /* Der Knoteneintrag wird ausmultipliziert und den Nachbarn zugeschlagen */ + /* index ist der irregulaere Knoten, j ist die Zeile, nachbarn_index die Spalte */ + inc = gewicht * MXGet(j, index); + if (fabs(inc) > 0.) + for (k = 0; k < anz_nachbarn; k++) + MXInc(j, nachbarn_index[k], inc); + + /* Spalte des Knotens zu Null setzen, da der Wert oben verteilt wurde */ + if (fabs(MXGet(j, index)) > 0.) + MXSet(j, index, 0.); + } /* endfor j */ #ifdef DUMP - MXDumpGLS("a_spalte", 1, rechts, rechts); + MXDumpGLS("a_spalte", 1, rechts, rechts); #endif - /* Zeile des irr. Knotens eliminieren : */ - /* Ueber Zeilen der regulaeren Nachbarn gehen */ - /* Der Knoteneintrag wird ausmultipliziert und den Nachbarn zugeschlagen */ - for (k = 0; k < dim; k++) - { - inc = gewicht * MXGet(index, k); - if (fabs(inc) > 0.) + /* Zeile des irr. Knotens eliminieren : */ + /* Ueber Zeilen der regulaeren Nachbarn gehen */ + /* Der Knoteneintrag wird ausmultipliziert und den Nachbarn zugeschlagen */ + for (k = 0; k < dim; k++) { - for (j = 0l; j < anz_nachbarn; j++) - MXInc(nachbarn_index[j], k, inc); - /* Zeile des Knotens zu Null setzen, da hier die Interpolation eingesetzt wird */ - MXSet(index, k, 0.); - } /* endif */ - } + inc = gewicht * MXGet(index, k); + if (fabs(inc) > 0.) + { + for (j = 0l; j < anz_nachbarn; j++) + MXInc(nachbarn_index[j], k, inc); + /* Zeile des Knotens zu Null setzen, da hier die Interpolation eingesetzt wird */ + MXSet(index, k, 0.); + } /* endif */ + } - /* Der rechte Seite-Eintrag wird den Nachbarn zugeschlagen */ - for (j = 0l; j < anz_nachbarn; j++) - rechts[nachbarn_index[j]] += gewicht * rechts[index]; + /* Der rechte Seite-Eintrag wird den Nachbarn zugeschlagen */ + for (j = 0l; j < anz_nachbarn; j++) + rechts[nachbarn_index[j]] += gewicht * rechts[index]; #ifdef DUMP - MXDumpGLS("a_zeile", 1, rechts, rechts); + MXDumpGLS("a_zeile", 1, rechts, rechts); #endif - /* Neuer Zeileneintrag fuer den irr. Knoten, dies ist - die Zwangsbedingung aus der Interpolation */ + /* Neuer Zeileneintrag fuer den irr. Knoten, dies ist + die Zwangsbedingung aus der Interpolation */ - MXSet(index, index, diag); - rechts[index] = 0.; - for (k = 0; k < anz_nachbarn; k++) - /* i ist die Zeile des irregulaere Knoten, nachbarn_index die Spalte */ - MXSet(index, nachbarn_index[k], -gewicht * diag); + MXSet(index, index, diag); + rechts[index] = 0.; + for (k = 0; k < anz_nachbarn; k++) + /* i ist die Zeile des irregulaere Knoten, nachbarn_index die Spalte */ + MXSet(index, nachbarn_index[k], -gewicht * diag); #ifdef DUMP - MXDumpGLS("a_zwang", 1, rechts, rechts); + MXDumpGLS("a_zwang", 1, rechts, rechts); #endif - } - break; - - case 2: - { - Modell2* w = (Modell2*) wurzel; + } + break; - /* Spalte des irr. Knotens eliminieren : */ - /* Ueber alle Zeilen gehen, um nach Eintragen fuer den Knoten zu suchen */ - for (zeile = 0l; zeile < dim; zeile++) + case 2: { - /* Der Knoteneintrag wird ausmultipliziert und den Nachbarn zugeschlagen */ - /* index ist der irregulaere Knoten, nachbarn_index[] die Spalte */ - - spalte = index; - k = 0; - - while (k < Zeil2(zeile).anz) - { /* Alle Eintraege durchsuchen */ - if (spalte == Ind2(zeile, k)) - { /* gefunden! */ - inc = gewicht * Aik2(zeile, k); /* Mit dem Gewicht multiplizieren */ - Aik2(zeile, k) = 0.; /* Eigenen Eintrag loeschen */ - for (l = 0; l < anz_nachbarn; l++) - /* Den reg. Nachbarn zuschlagen */ - MXInc(zeile, nachbarn_index[l], inc); - break; - } - else - k++; - } - } /* endfor j */ + Modell2* w = (Modell2*)wurzel; - /* Zeile des irr. Knotens eliminieren : */ - /* Ueber Zeilen der regulaeren Nachbarn gehen */ - for (spalte = 0; spalte < dim; spalte++) - { - zeile = index; - k = 0; - - while (k < Zeil2(zeile).anz) - { /* Alle Eintraege durchsuchen */ - if (spalte == Ind2(zeile, k)) - { /* gefunden! */ - inc = gewicht * Aik2(zeile, k); /* Mit dem Gewicht multiplizieren */ - Aik2(zeile, k) = 0.; /* Eigenen Eintrag loeschen */ - for (l = 0; l < anz_nachbarn; l++) - /* Den reg. Nachbarn zuschlagen */ - MXInc(nachbarn_index[l], spalte, inc); - break; + /* Spalte des irr. Knotens eliminieren : */ + /* Ueber alle Zeilen gehen, um nach Eintragen fuer den Knoten zu suchen */ + for (zeile = 0l; zeile < dim; zeile++) + { + /* Der Knoteneintrag wird ausmultipliziert und den Nachbarn zugeschlagen */ + /* index ist der irregulaere Knoten, nachbarn_index[] die Spalte */ + + spalte = index; + k = 0; + + while (k < Zeil2(zeile).anz) + { /* Alle Eintraege durchsuchen */ + if (spalte == Ind2(zeile, k)) + { /* gefunden! */ + inc = gewicht * Aik2(zeile, k); /* Mit dem Gewicht multiplizieren */ + Aik2(zeile, k) = 0.; /* Eigenen Eintrag loeschen */ + for (l = 0; l < anz_nachbarn; l++) + /* Den reg. Nachbarn zuschlagen */ + MXInc(zeile, nachbarn_index[l], inc); + break; + } + else + k++; } - else - k++; - } /* endwhile */ - } /* endfor */ + } /* endfor j */ - for (j = 0l; j < anz_nachbarn; j++) - /* Der rechte Seite-Eintrag wird den Nachbarn zugeschlagen */ - rechts[nachbarn_index[j]] += gewicht * rechts[index]; - /* endfor j */ + /* Zeile des irr. Knotens eliminieren : */ + /* Ueber Zeilen der regulaeren Nachbarn gehen */ + for (spalte = 0; spalte < dim; spalte++) + { + zeile = index; + k = 0; + + while (k < Zeil2(zeile).anz) + { /* Alle Eintraege durchsuchen */ + if (spalte == Ind2(zeile, k)) + { /* gefunden! */ + inc = gewicht * Aik2(zeile, k); /* Mit dem Gewicht multiplizieren */ + Aik2(zeile, k) = 0.; /* Eigenen Eintrag loeschen */ + for (l = 0; l < anz_nachbarn; l++) + /* Den reg. Nachbarn zuschlagen */ + MXInc(nachbarn_index[l], spalte, inc); + break; + } + else + k++; + } /* endwhile */ + } /* endfor */ - /* Neuer Zeileneintrag fuer den irr. Knoten, dies ist - die Zwangsbedingung aus der Interpolation */ - MXSet(index, index, diag); + for (j = 0l; j < anz_nachbarn; j++) + /* Der rechte Seite-Eintrag wird den Nachbarn zugeschlagen */ + rechts[nachbarn_index[j]] += gewicht * rechts[index]; + /* endfor j */ - for (k = 0; k < anz_nachbarn; k++) - /* i ist die Zeile des irregulaere Knoten, nachbarn_index die Spalte */ - MXSet(index, nachbarn_index[k], -gewicht * diag); + /* Neuer Zeileneintrag fuer den irr. Knoten, dies ist + die Zwangsbedingung aus der Interpolation */ + MXSet(index, index, diag); - rechts[index] = 0.; - } - break; + for (k = 0; k < anz_nachbarn; k++) + /* i ist die Zeile des irregulaere Knoten, nachbarn_index die Spalte */ + MXSet(index, nachbarn_index[k], -gewicht * diag); - case 3: - case 4: - { - Modell34* w = (Modell34*) wurzel; - long i34, j34, k34; - int u; + rechts[index] = 0.; + } + break; - /* Spalte des irr. Knotens eliminieren : */ - /* Ueber alle Zeilen gehen, um nach Eintragen fuer den Knoten zu suchen */ - for (j = 0l; j < dim; j++) + case 3: + case 4: { - /* Der Knoteneintrag wird ausmultipliziert und den Nachbarn zugeschlagen */ - inc = 0.; + Modell34* w = (Modell34*)wurzel; + long i34, j34, k34; + int u; - if (j == index) - { - inc = gewicht * (w->Diag[j]); /* Diagonalelement */ - w->Diag[j] = 0.; - } - else + /* Spalte des irr. Knotens eliminieren : */ + /* Ueber alle Zeilen gehen, um nach Eintragen fuer den Knoten zu suchen */ + for (j = 0l; j < dim; j++) { - /* Variablen setzen */ - j34 = 0; + /* Der Knoteneintrag wird ausmultipliziert und den Nachbarn zugeschlagen */ + inc = 0.; - /* Untermatrixelement? */ - if (j > index) + if (j == index) { - u = w->usym; - i34 = index; - k34 = j; + inc = gewicht * (w->Diag[j]); /* Diagonalelement */ + w->Diag[j] = 0.; } else { - u = 0; - i34 = j; - k34 = index; - } - /* Alle Spalteneintraege durchsuchen */ - while (j34 < Sp34(k34).anz && i34 >= Ind34(k34, j34)) - { - if (i34 == Ind34(k34, j34)) + /* Variablen setzen */ + j34 = 0; + + /* Untermatrixelement? */ + if (j > index) { - inc = gewicht * Aik34(k34, j34, u); - /* Spalte des Knotens zu Null setzen, da der Wert mit "inc" verteilt wird */ - Aik34(k34, j34, u) = 0.; - break; + u = w->usym; + i34 = index; + k34 = j; } - j34++; - } - } /* endif */ + else + { + u = 0; + i34 = j; + k34 = index; + } + /* Alle Spalteneintraege durchsuchen */ + while (j34 < Sp34(k34).anz && i34 >= Ind34(k34, j34)) + { + if (i34 == Ind34(k34, j34)) + { + inc = gewicht * Aik34(k34, j34, u); + /* Spalte des Knotens zu Null setzen, da der Wert mit "inc" verteilt wird */ + Aik34(k34, j34, u) = 0.; + break; + } + j34++; + } + } /* endif */ - if (fabs(inc) > 0.) - for (k = 0; k < anz_nachbarn; k++) - MXInc(j, nachbarn_index[k], inc); - } /* endfor j */ + if (fabs(inc) > 0.) + for (k = 0; k < anz_nachbarn; k++) + MXInc(j, nachbarn_index[k], inc); + } /* endfor j */ #ifdef DUMP - MXDumpGLS("b_spalte", 1, rechts, rechts); + MXDumpGLS("b_spalte", 1, rechts, rechts); #endif - /* Zeile des irr. Knotens eliminieren : */ - /* Ueber Zeilen der regulaeren Nachbarn gehen */ - /* Der Knoteneintrag wird ausmultipliziert und den Nachbarn zugeschlagen */ - for (k = 0; k < dim; k++) - { - inc = 0.; - - if (index == k) - { - inc = gewicht * (w->Diag[k]); /* Diagonalelement */ - w->Diag[k] = 0.; - } - else + /* Zeile des irr. Knotens eliminieren : */ + /* Ueber Zeilen der regulaeren Nachbarn gehen */ + /* Der Knoteneintrag wird ausmultipliziert und den Nachbarn zugeschlagen */ + for (k = 0; k < dim; k++) { - /* Variablen setzen */ - j34 = 0; + inc = 0.; - /* Untermatrixelement */ - if (index > k) + if (index == k) { - u = w->usym; - i34 = k; - k34 = index; + inc = gewicht * (w->Diag[k]); /* Diagonalelement */ + w->Diag[k] = 0.; } else { - u = 0; - i34 = index; - k34 = k; - } + /* Variablen setzen */ + j34 = 0; - /* Alle Spalteneintraege durchsuchen */ - while (j34 < Sp34(k34).anz && i34 >= Ind34(k34, j34)) - { - if (i34 == Ind34(k34, j34)) + /* Untermatrixelement */ + if (index > k) { - inc = gewicht * Aik34(k34, j34, u); - /* Spalte des Knotens zu Null setzen, da der Wert mit "inc" verteilt wird */ - Aik34(k34, j34, u) = 0.; - for (j = 0l; j < anz_nachbarn; j++) - MXInc(nachbarn_index[j], k, inc); - break; + u = w->usym; + i34 = k; + k34 = index; } - j34++; - } /* endwhile */ - } /* endif */ - } /* endfor */ + else + { + u = 0; + i34 = index; + k34 = k; + } + + /* Alle Spalteneintraege durchsuchen */ + while (j34 < Sp34(k34).anz && i34 >= Ind34(k34, j34)) + { + if (i34 == Ind34(k34, j34)) + { + inc = gewicht * Aik34(k34, j34, u); + /* Spalte des Knotens zu Null setzen, da der Wert mit "inc" verteilt wird */ + Aik34(k34, j34, u) = 0.; + for (j = 0l; j < anz_nachbarn; j++) + MXInc(nachbarn_index[j], k, inc); + break; + } + j34++; + } /* endwhile */ + } /* endif */ + } /* endfor */ - /* Der rechte Seite-Eintrag wird den Nachbarn zugeschlagen */ - for (j = 0l; j < anz_nachbarn; j++) - rechts[nachbarn_index[j]] += gewicht * rechts[index]; - /* endfor j */ + /* Der rechte Seite-Eintrag wird den Nachbarn zugeschlagen */ + for (j = 0l; j < anz_nachbarn; j++) + rechts[nachbarn_index[j]] += gewicht * rechts[index]; +/* endfor j */ #ifdef DUMP - MXDumpGLS("b_zeile", 1, rechts, rechts); + MXDumpGLS("b_zeile", 1, rechts, rechts); #endif - /* Neuer Zeileneintrag fuer den irr. Knoten, dies ist - die Zwangsbedingung aus der Interpolation */ + /* Neuer Zeileneintrag fuer den irr. Knoten, dies ist + die Zwangsbedingung aus der Interpolation */ - MXSet(index, index, diag); - rechts[index] = 0.; - for (k = 0; k < anz_nachbarn; k++) - /* i ist die Zeile des irregulaere Knoten, nachbarn_index die Spalte */ - MXSet(index, nachbarn_index[k], -gewicht * diag); + MXSet(index, index, diag); + rechts[index] = 0.; + for (k = 0; k < anz_nachbarn; k++) + /* i ist die Zeile des irregulaere Knoten, nachbarn_index die Spalte */ + MXSet(index, nachbarn_index[k], -gewicht * diag); #ifdef DUMP - MXDumpGLS("b_zwang", 1, rechts, rechts); + MXDumpGLS("b_zwang", 1, rechts, rechts); #endif - break; - } - case 5: - { - Modell2* w = (Modell2*) wurzel; - - /* Spalte des irr. Knotens eliminieren : */ - /* Ueber alle Zeilen gehen, um nach Eintragen fuer den Knoten zu suchen */ - for (zeile = 0l; zeile < dim; zeile++) + break; + } + case 5: { - /* Der Knoteneintrag wird ausmultipliziert und den Nachbarn zugeschlagen */ - /* index ist der irregulaere Knoten, nachbarn_index[] die Spalte */ - - spalte = index; - k = 0; - - while (k < Zeil2(zeile).anz) - { /* Alle Eintraege durchsuchen */ - if (spalte == Ind2(zeile, k)) - { /* gefunden! */ - inc = gewicht * Aik2(zeile, k); /* Mit dem Gewicht multiplizieren */ - Aik2(zeile, k) = 0.; /* Eigenen Eintrag loeschen */ - for (l = 0; l < anz_nachbarn; l++) - /* Den reg. Nachbarn zuschlagen */ - MXInc(zeile, nachbarn_index[l], inc); - break; - } - else - k++; - } - } /* endfor j */ + Modell2* w = (Modell2*)wurzel; - /* Zeile des irr. Knotens eliminieren : */ - /* Ueber Zeilen der regulaeren Nachbarn gehen */ - for (spalte = 0; spalte < dim; spalte++) - { - zeile = index; - k = 0; - - while (k < Zeil2(zeile).anz) - { /* Alle Eintraege durchsuchen */ - if (spalte == Ind2(zeile, k)) - { /* gefunden! */ - inc = gewicht * Aik2(zeile, k); /* Mit dem Gewicht multiplizieren */ - Aik2(zeile, k) = 0.; /* Eigenen Eintrag loeschen */ - for (l = 0; l < anz_nachbarn; l++) - /* Den reg. Nachbarn zuschlagen */ - MXInc(nachbarn_index[l], spalte, inc); - break; + /* Spalte des irr. Knotens eliminieren : */ + /* Ueber alle Zeilen gehen, um nach Eintragen fuer den Knoten zu suchen */ + for (zeile = 0l; zeile < dim; zeile++) + { + /* Der Knoteneintrag wird ausmultipliziert und den Nachbarn zugeschlagen */ + /* index ist der irregulaere Knoten, nachbarn_index[] die Spalte */ + + spalte = index; + k = 0; + + while (k < Zeil2(zeile).anz) + { /* Alle Eintraege durchsuchen */ + if (spalte == Ind2(zeile, k)) + { /* gefunden! */ + inc = gewicht * Aik2(zeile, k); /* Mit dem Gewicht multiplizieren */ + Aik2(zeile, k) = 0.; /* Eigenen Eintrag loeschen */ + for (l = 0; l < anz_nachbarn; l++) + /* Den reg. Nachbarn zuschlagen */ + MXInc(zeile, nachbarn_index[l], inc); + break; + } + else + k++; } - else - k++; - } /* endwhile */ - } /* endfor */ + } /* endfor j */ - for (j = 0l; j < anz_nachbarn; j++) - /* Der rechte Seite-Eintrag wird den Nachbarn zugeschlagen */ - rechts[nachbarn_index[j]] += gewicht * rechts[index]; - /* endfor j */ + /* Zeile des irr. Knotens eliminieren : */ + /* Ueber Zeilen der regulaeren Nachbarn gehen */ + for (spalte = 0; spalte < dim; spalte++) + { + zeile = index; + k = 0; - /* Neuer Zeileneintrag fuer den irr. Knoten, dies ist - die Zwangsbedingung aus der Interpolation */ - MXSet(index, index, diag); + while (k < Zeil2(zeile).anz) + { /* Alle Eintraege durchsuchen */ + if (spalte == Ind2(zeile, k)) + { /* gefunden! */ + inc = gewicht * Aik2(zeile, k); /* Mit dem Gewicht multiplizieren */ + Aik2(zeile, k) = 0.; /* Eigenen Eintrag loeschen */ + for (l = 0; l < anz_nachbarn; l++) + /* Den reg. Nachbarn zuschlagen */ + MXInc(nachbarn_index[l], spalte, inc); + break; + } + else + k++; + } /* endwhile */ + } /* endfor */ - for (k = 0; k < anz_nachbarn; k++) - /* i ist die Zeile des irregulaere Knoten, nachbarn_index die Spalte */ - MXSet(index, nachbarn_index[k], -gewicht * diag); + for (j = 0l; j < anz_nachbarn; j++) + /* Der rechte Seite-Eintrag wird den Nachbarn zugeschlagen */ + rechts[nachbarn_index[j]] += gewicht * rechts[index]; + /* endfor j */ - rechts[index] = 0.; - } - break; - case 6: - { - Modell2* w = (Modell2*) wurzel; + /* Neuer Zeileneintrag fuer den irr. Knoten, dies ist + die Zwangsbedingung aus der Interpolation */ + MXSet(index, index, diag); - /* Spalte des irr. Knotens eliminieren : */ - /* Ueber alle Zeilen gehen, um nach Eintragen fuer den Knoten zu suchen */ - for (zeile = 0l; zeile < dim; zeile++) - { - /* Der Knoteneintrag wird ausmultipliziert und den Nachbarn zugeschlagen */ - /* index ist der irregulaere Knoten, nachbarn_index[] die Spalte */ - - spalte = index; - k = 0; - - while (k < Zeil2(zeile).anz) - { /* Alle Eintraege durchsuchen */ - if (spalte == Ind2(zeile, k)) - { /* gefunden! */ - inc = gewicht * Aik2(zeile, k); /* Mit dem Gewicht multiplizieren */ - Aik2(zeile, k) = 0.; /* Eigenen Eintrag loeschen */ - for (l = 0; l < anz_nachbarn; l++) - /* Den reg. Nachbarn zuschlagen */ - MXInc(zeile, nachbarn_index[l], inc); - break; - } - else - k++; - } - } /* endfor j */ + for (k = 0; k < anz_nachbarn; k++) + /* i ist die Zeile des irregulaere Knoten, nachbarn_index die Spalte */ + MXSet(index, nachbarn_index[k], -gewicht * diag); - /* Zeile des irr. Knotens eliminieren : */ - /* Ueber Zeilen der regulaeren Nachbarn gehen */ - for (spalte = 0; spalte < dim; spalte++) + rechts[index] = 0.; + } + break; + case 6: { - zeile = index; - k = 0; - - while (k < Zeil2(zeile).anz) - { /* Alle Eintraege durchsuchen */ - if (spalte == Ind2(zeile, k)) - { /* gefunden! */ - inc = gewicht * Aik2(zeile, k); /* Mit dem Gewicht multiplizieren */ - Aik2(zeile, k) = 0.; /* Eigenen Eintrag loeschen */ - for (l = 0; l < anz_nachbarn; l++) - /* Den reg. Nachbarn zuschlagen */ - MXInc(nachbarn_index[l], spalte, inc); - break; + Modell2* w = (Modell2*)wurzel; + + /* Spalte des irr. Knotens eliminieren : */ + /* Ueber alle Zeilen gehen, um nach Eintragen fuer den Knoten zu suchen */ + for (zeile = 0l; zeile < dim; zeile++) + { + /* Der Knoteneintrag wird ausmultipliziert und den Nachbarn zugeschlagen */ + /* index ist der irregulaere Knoten, nachbarn_index[] die Spalte */ + + spalte = index; + k = 0; + + while (k < Zeil2(zeile).anz) + { /* Alle Eintraege durchsuchen */ + if (spalte == Ind2(zeile, k)) + { /* gefunden! */ + inc = gewicht * Aik2(zeile, k); /* Mit dem Gewicht multiplizieren */ + Aik2(zeile, k) = 0.; /* Eigenen Eintrag loeschen */ + for (l = 0; l < anz_nachbarn; l++) + /* Den reg. Nachbarn zuschlagen */ + MXInc(zeile, nachbarn_index[l], inc); + break; + } + else + k++; } - else - k++; - } /* endwhile */ - } /* endfor */ + } /* endfor j */ - for (j = 0l; j < anz_nachbarn; j++) - /* Der rechte Seite-Eintrag wird den Nachbarn zugeschlagen */ - rechts[nachbarn_index[j]] += gewicht * rechts[index]; - /* endfor j */ + /* Zeile des irr. Knotens eliminieren : */ + /* Ueber Zeilen der regulaeren Nachbarn gehen */ + for (spalte = 0; spalte < dim; spalte++) + { + zeile = index; + k = 0; + + while (k < Zeil2(zeile).anz) + { /* Alle Eintraege durchsuchen */ + if (spalte == Ind2(zeile, k)) + { /* gefunden! */ + inc = gewicht * Aik2(zeile, k); /* Mit dem Gewicht multiplizieren */ + Aik2(zeile, k) = 0.; /* Eigenen Eintrag loeschen */ + for (l = 0; l < anz_nachbarn; l++) + /* Den reg. Nachbarn zuschlagen */ + MXInc(nachbarn_index[l], spalte, inc); + break; + } + else + k++; + } /* endwhile */ + } /* endfor */ - /* Neuer Zeileneintrag fuer den irr. Knoten, dies ist - die Zwangsbedingung aus der Interpolation */ - MXSet(index, index, diag); + for (j = 0l; j < anz_nachbarn; j++) + /* Der rechte Seite-Eintrag wird den Nachbarn zugeschlagen */ + rechts[nachbarn_index[j]] += gewicht * rechts[index]; + /* endfor j */ - for (k = 0; k < anz_nachbarn; k++) - /* i ist die Zeile des irregulaere Knoten, nachbarn_index die Spalte */ - MXSet(index, nachbarn_index[k], -gewicht * diag); + /* Neuer Zeileneintrag fuer den irr. Knoten, dies ist + die Zwangsbedingung aus der Interpolation */ + MXSet(index, index, diag); - rechts[index] = 0.; - } - break; + for (k = 0; k < anz_nachbarn; k++) + /* i ist die Zeile des irregulaere Knoten, nachbarn_index die Spalte */ + MXSet(index, nachbarn_index[k], -gewicht * diag); + + rechts[index] = 0.; + } + break; } } @@ -3000,9 +2956,9 @@ void MXEliminateIrrNode(long index, int anz_nachbarn, long* nachbarn_index, doub 6/2000 C.Thorenz Diagonalenskalierung eingebaut (Nur Mod.4) *** Definitionen fuer Preconditioner ************************************/ #define fastNull MKleinsteZahl -#define VK_Skalierung 1 +#define VK_Skalierung 1 #define VK_Extraktion 10 -#define VK_iLDU 100 +#define VK_iLDU 100 #define VK_Modus(vk) ((int)(vorkond % (vk * 10) / vk)) /* werden am Ende von matrix.c undefiniert Hilfsfunktion Skalarprodukt a*b, (Elementabstand da in a, 1 in db) */ @@ -3021,10 +2977,10 @@ double H_M1skprod(double* a, long da, double* b, long n) /**** Modell 1 ************************************************************/ void M1Vorkond(int aufgabe, double* x, double* b) { - Modell1* w = (Modell1*) wurzel; + Modell1* w = (Modell1*)wurzel; register long i, k; register double h; - static double* x0, * r0, * Gik = NULL; + static double *x0, *r0, *Gik = NULL; #ifdef ERROR_CONTROL if (b == NULL || x == NULL) @@ -3033,143 +2989,142 @@ void M1Vorkond(int aufgabe, double* x, double* b) switch (aufgabe) { - case 0: /* Start des Vorkonditionierers */ - if VK_Modus - (VK_Extraktion) - { /* immer zuerst! */ - x0 = (double*) Malloc(sizeof(double) * dim); - r0 = (double*) Malloc(sizeof(double) * dim); - MXResiduum(x, b, r0); /* Rechte Seite ex A*(Startloesung x) */ - for (i = 0; i < dim; i++) - { - b[i] = r0[i]; - x0[i] = x[i]; - x[i] = 0.0; - } - r0 = (double*) Free(r0); - } - if VK_Modus - (VK_Skalierung) - { /* Diagonal-Skalierung */ - for (i = 0; i < dim; i++) - { - if(fabs(Aik1(i, i)) > DBL_MIN) - { - h = 1. / Aik1(i, i); - b[i] *= h; - for (k = 0; k < dim; k++) - Aik1(i, k) *= h; + case 0: /* Start des Vorkonditionierers */ + if + VK_Modus(VK_Extraktion) + { /* immer zuerst! */ + x0 = (double*)Malloc(sizeof(double) * dim); + r0 = (double*)Malloc(sizeof(double) * dim); + MXResiduum(x, b, r0); /* Rechte Seite ex A*(Startloesung x) */ + for (i = 0; i < dim; i++) + { + b[i] = r0[i]; + x0[i] = x[i]; + x[i] = 0.0; + } + r0 = (double*)Free(r0); } - else - { - DisplayMsg("!!! Equation system: Line: "); - DisplayLong(i); - DisplayMsg(" Value: "); - DisplayDouble(Aik1(i, i), 0, 0); - DisplayMsgLn( - "!!! Diagonal near zero! Disable diagonal preconditioner!"); - exit(1); + if + VK_Modus(VK_Skalierung) + { /* Diagonal-Skalierung */ + for (i = 0; i < dim; i++) + { + if (fabs(Aik1(i, i)) > DBL_MIN) + { + h = 1. / Aik1(i, i); + b[i] *= h; + for (k = 0; k < dim; k++) + Aik1(i, k) *= h; + } + else + { + DisplayMsg("!!! Equation system: Line: "); + DisplayLong(i); + DisplayMsg(" Value: "); + DisplayDouble(Aik1(i, i), 0, 0); + DisplayMsgLn("!!! Diagonal near zero! Disable diagonal preconditioner!"); + exit(1); + } + } } - } - } - break; - - case 1: /* Ende des Vorkonditionierers */ - if VK_Modus - (VK_iLDU) Gik = (double*) Free(Gik); + break; - if VK_Modus - (VK_Extraktion) - { /* immer zuletzt: Startloesung addieren */ - for (i = 0; i < dim; i++) - x[i] += x0[i]; - x0 = (double*) Free(x0); - } - break; + case 1: /* Ende des Vorkonditionierers */ + if + VK_Modus(VK_iLDU) Gik = (double*)Free(Gik); - case 2: /* Linkstransformation des Gesamtsystems x <= L*b */ - if VK_Modus - (VK_iLDU) - { /* Gauss anstelle L(D)U-Zerlegung */ - long ia, diag, ka = 0; - if (Gik == NULL) - { /* Matrix kopieren (transponiert!) und zerlegen */ - long ig = 0; - Gik = (double*) Malloc(dim * dim * sizeof(double)); - for (k = 0; k < dim; k++) - { - ia = k; + if + VK_Modus(VK_Extraktion) + { /* immer zuletzt: Startloesung addieren */ for (i = 0; i < dim; i++) - { - Gik[ig++] = w->matrix[ia]; - ia += dim; - } + x[i] += x0[i]; + x0 = (double*)Free(x0); } + break; - for (k = 0; k < dim; k++) - { /* alle Spalten/Zeilen */ + case 2: /* Linkstransformation des Gesamtsystems x <= L*b */ + if + VK_Modus(VK_iLDU) + { /* Gauss anstelle L(D)U-Zerlegung */ + long ia, diag, ka = 0; + if (Gik == NULL) + { /* Matrix kopieren (transponiert!) und zerlegen */ + long ig = 0; + Gik = (double*)Malloc(dim * dim * sizeof(double)); + for (k = 0; k < dim; k++) + { + ia = k; + for (i = 0; i < dim; i++) + { + Gik[ig++] = w->matrix[ia]; + ia += dim; + } + } + + for (k = 0; k < dim; k++) + { /* alle Spalten/Zeilen */ + diag = 0; + for (i = 0; i < k; i++) + { /* Spalte ohne Okk */ + Gik[ka + i] -= H_M1skprod(&Gik[i], dim, &Gik[ka], i); + Gik[ka + i] *= Gik[diag]; + diag += dim + 1; /* /Uii (Kehrwert) */ + } /* i */ + + ia = 0; /* Spaltenanfang Spalte i */ + for (i = 0; i <= k; i++) + { /* Zeile incl. Ukk */ + Gik[ia + k] -= H_M1skprod(&Gik[k], dim, &Gik[ia], i); + ia += dim; /* Uik */ + } /* i */ + Gik[diag] = 1.0 / Gik[diag]; /* 1.0/Ukk */ + ka += dim; /* naechste Spalte k */ + } + } /* k - Matrix zerlegt */ + /* Gleichungssystem aufloesen */ diag = 0; - for (i = 0; i < k; i++) - { /* Spalte ohne Okk */ - Gik[ka + i] -= H_M1skprod(&Gik[i], dim, &Gik[ka], i); - Gik[ka + i] *= Gik[diag]; - diag += dim + 1; /* /Uii (Kehrwert) */ + for (i = 0; i < dim; i++) + { /* vorwaerts einsetzen mit Uik */ + x[i] = (b[i] - H_M1skprod(&Gik[i], dim, x, i)) * Gik[diag]; + diag += dim + 1; /* naechstes Diagonalelement */ + } + diag--; /* rechts neben letztem Diagonalelement */ + for (i = dim; i > 0; i--) + { /* rueckwaerts einsetzen mit Oik */ + x[i - 1] -= H_M1skprod(&Gik[diag], dim, &x[i], dim - i); + diag -= dim + 1; } /* i */ + } /* Modus iLDU, (zerlegen und) aufloesen */ + case 3: /* Linkstransformation des Gesamtsystems x <= L(t)*b */ + if + VK_Modus(VK_iLDU) + { /* Gauss anstelle L(D)U-Zerlegung */ + long ia = 0, diag = dim * dim - 1; + /* Nur aufloesen, Matrix ist immer schon zerlegt! */ + for (i = 0; i < dim; i++) + { /* vorwaerts einsetzen mit Oik */ + x[i] = b[i] - H_M1skprod(&Gik[ia], 1l, x, i); + ia += dim; + } - ia = 0; /* Spaltenanfang Spalte i */ - for (i = 0; i <= k; i++) - { /* Zeile incl. Ukk */ - Gik[ia + k] -= H_M1skprod(&Gik[k], dim, &Gik[ia], i); - ia += dim; /* Uik */ + ia--; /* rechts neben letztem Diagonalelement */ + for (i = dim; i > 0; i--) + { /* rueckwaerts einsetzen mit Uik */ + x[i - 1] -= H_M1skprod(&Gik[ia], 1l, &x[i], dim - i); + x[i - 1] *= Gik[diag]; + diag -= dim + 1; } /* i */ - Gik[diag] = 1.0 / Gik[diag]; /* 1.0/Ukk */ - ka += dim; /* naechste Spalte k */ - } - } /* k - Matrix zerlegt */ - /* Gleichungssystem aufloesen */ - diag = 0; - for (i = 0; i < dim; i++) - { /* vorwaerts einsetzen mit Uik */ - x[i] = (b[i] - H_M1skprod(&Gik[i], dim, x, i)) * Gik[diag]; - diag += dim + 1; /* naechstes Diagonalelement */ - } - diag--; /* rechts neben letztem Diagonalelement */ - for (i = dim; i > 0; i--) - { /* rueckwaerts einsetzen mit Oik */ - x[i - 1] -= H_M1skprod(&Gik[diag], dim, &x[i], dim - i); - diag -= dim + 1; - } /* i */ - } /* Modus iLDU, (zerlegen und) aufloesen */ - case 3: /* Linkstransformation des Gesamtsystems x <= L(t)*b */ - if VK_Modus - (VK_iLDU) - { /* Gauss anstelle L(D)U-Zerlegung */ - long ia = 0, diag = dim * dim - 1; - /* Nur aufloesen, Matrix ist immer schon zerlegt! */ - for (i = 0; i < dim; i++) - { /* vorwaerts einsetzen mit Oik */ - x[i] = b[i] - H_M1skprod(&Gik[ia], 1l, x, i); - ia += dim; - } - - ia--; /* rechts neben letztem Diagonalelement */ - for (i = dim; i > 0; i--) - { /* rueckwaerts einsetzen mit Uik */ - x[i - 1] -= H_M1skprod(&Gik[ia], 1l, &x[i], dim - i); - x[i - 1] *= Gik[diag]; - diag -= dim + 1; - } /* i */ - } /* Modus iLDU, aufloesen mit L(t) */ - } /* aufgabe */ -} /* M1Vorkond */ + } /* Modus iLDU, aufloesen mit L(t) */ + } /* aufgabe */ +} /* M1Vorkond */ /**** Modell 2 ************************************************************/ void M2Vorkond(int aufgabe, double* x, double* b) { - Modell2* w = (Modell2*) wurzel; + Modell2* w = (Modell2*)wurzel; register long k; register int i; - static double* x0, * r0, h; + static double *x0, *r0, h; #ifdef ERROR_CONTROL if (b == NULL || x == NULL) @@ -3178,66 +3133,65 @@ void M2Vorkond(int aufgabe, double* x, double* b) //====================================================================== switch (aufgabe) { - //-------------------------------------------------------------------- - case 0: /* Start des Vorkonditionierers */ - if VK_Modus - (VK_Extraktion) - { /* immer zuerst! */ - x0 = (double*) Malloc(sizeof(double) * dim); - r0 = (double*) Malloc(sizeof(double) * dim); - MXResiduum(x, b, r0); /* Rechte Seite ex A*(Startloesung x) */ - for (i = 0; i < dim; i++) - { - b[i] = r0[i]; - x0[i] = x[i]; - x[i] = 0.0; - } - r0 = (double*) Free(r0); - } - if VK_Modus - (VK_Skalierung) - { /* Diagonal-Skalierung */ - for (k = 0; k < dim; k++) - { - if(fabs(Diag2(k)) > DBL_MIN) - { - h = 1. / Diag2(k); - b[k] *= h; - for (i = 0; i < Zeil2(k).anz; i++) - Aik2(k, i) *= h; + //-------------------------------------------------------------------- + case 0: /* Start des Vorkonditionierers */ + if + VK_Modus(VK_Extraktion) + { /* immer zuerst! */ + x0 = (double*)Malloc(sizeof(double) * dim); + r0 = (double*)Malloc(sizeof(double) * dim); + MXResiduum(x, b, r0); /* Rechte Seite ex A*(Startloesung x) */ + for (i = 0; i < dim; i++) + { + b[i] = r0[i]; + x0[i] = x[i]; + x[i] = 0.0; + } + r0 = (double*)Free(r0); } - else - { - DisplayMsg("!!! Equation system: Line: "); - DisplayLong(k); - DisplayMsg(" Value: "); - DisplayDouble(Diag2(k), 0, 0); - DisplayMsgLn(""); - DisplayMsgLn( - "!!! Diagonal near zero! Disable diagonal preconditioner!"); - exit(1); + if + VK_Modus(VK_Skalierung) + { /* Diagonal-Skalierung */ + for (k = 0; k < dim; k++) + { + if (fabs(Diag2(k)) > DBL_MIN) + { + h = 1. / Diag2(k); + b[k] *= h; + for (i = 0; i < Zeil2(k).anz; i++) + Aik2(k, i) *= h; + } + else + { + DisplayMsg("!!! Equation system: Line: "); + DisplayLong(k); + DisplayMsg(" Value: "); + DisplayDouble(Diag2(k), 0, 0); + DisplayMsgLn(""); + DisplayMsgLn("!!! Diagonal near zero! Disable diagonal preconditioner!"); + exit(1); + } + } } - } - } - break; - //-------------------------------------------------------------------- - case 1: /* Ende des Vorkonditionierers */ - if VK_Modus - (VK_Extraktion) - { /* immer zuletzt: Startloesung addieren */ - for (i = 0; i < dim; i++) - x[i] += x0[i]; - x0 = (double*) Free(x0); - } - break; - //-------------------------------------------------------------------- - case 2: - //-------------------------------------------------------------------- - case 3: /* Linkstransformationen */ - if VK_Modus - (VK_iLDU) /* incomplete L(D)U-Zerlegung geht nicht! */ - DisplayMsgLn("Modell 2: kein ILU-Vorkonditionierer!"); + break; //-------------------------------------------------------------------- + case 1: /* Ende des Vorkonditionierers */ + if + VK_Modus(VK_Extraktion) + { /* immer zuletzt: Startloesung addieren */ + for (i = 0; i < dim; i++) + x[i] += x0[i]; + x0 = (double*)Free(x0); + } + break; + //-------------------------------------------------------------------- + case 2: + //-------------------------------------------------------------------- + case 3: /* Linkstransformationen */ + if + VK_Modus(VK_iLDU) /* incomplete L(D)U-Zerlegung geht nicht! */ + DisplayMsgLn("Modell 2: kein ILU-Vorkonditionierer!"); + //-------------------------------------------------------------------- } //====================================================================== } @@ -3245,13 +3199,13 @@ void M2Vorkond(int aufgabe, double* x, double* b) /**** Modell 3,4 **********************************************************/ void M34Vorkond(int aufgabe, double* x, double* b) { - Modell34* w = (Modell34*) wurzel; + Modell34* w = (Modell34*)wurzel; long i, k, l; register long zk; register int ji, jk; int j, u = w->usym, o = 0; double Oik, Uki = 0.0, Dkk, r; - static double* x0, * r0, h; + static double *x0, *r0, h; #ifdef ERROR_CONTROL if (b == NULL || x == NULL) @@ -3260,155 +3214,149 @@ void M34Vorkond(int aufgabe, double* x, double* b) switch (aufgabe) { - case 0: /* Start des Vorkonditionierers - ILU! */ - if (VK_Modus(VK_Extraktion)) /* immer zuerst! */ - { - x0 = (double*) Malloc(sizeof(double) * dim); - r0 = (double*) Malloc(sizeof(double) * dim); - MXResiduum(x, b, r0); /* Rechte Seite ex A*(Startloesung x) */ - for (i = 0; i < dim; i++) + case 0: /* Start des Vorkonditionierers - ILU! */ + if (VK_Modus(VK_Extraktion)) /* immer zuerst! */ { - b[i] = r0[i]; - x0[i] = x[i]; - x[i] = 0.0; - } - r0 = (double*) Free(r0); - } - if (VK_Modus (VK_Skalierung)) - { - for (k = 0; k < dim; k++) - if(fabs(w->Diag[k]) > DBL_MIN) + x0 = (double*)Malloc(sizeof(double) * dim); + r0 = (double*)Malloc(sizeof(double) * dim); + MXResiduum(x, b, r0); /* Rechte Seite ex A*(Startloesung x) */ + for (i = 0; i < dim; i++) { - h = 1. / w->Diag[k]; - b[k] *= h; - for (l = 0; l < dim; l++) - M34Mul(k, l, h); + b[i] = r0[i]; + x0[i] = x[i]; + x[i] = 0.0; } - /* - else { - DisplayMsg("!!! Equation system: Line: "); - DisplayLong(k); - DisplayMsg(" Value: "); - DisplayDouble(w -> Diag[k], 0, 0); - DisplayMsgLn(""); - DisplayMsgLn("!!! Diagonal near zero! Disable diagonal preconditioner!"); - exit(1); - }*/ + r0 = (double*)Free(r0); + } + if (VK_Modus(VK_Skalierung)) + { + for (k = 0; k < dim; k++) + if (fabs(w->Diag[k]) > DBL_MIN) + { + h = 1. / w->Diag[k]; + b[k] *= h; + for (l = 0; l < dim; l++) + M34Mul(k, l, h); + } +/* + else { + DisplayMsg("!!! Equation system: Line: "); + DisplayLong(k); + DisplayMsg(" Value: "); + DisplayDouble(w -> Diag[k], 0, 0); + DisplayMsgLn(""); + DisplayMsgLn("!!! Diagonal near zero! Disable diagonal preconditioner!"); + exit(1); + }*/ #ifdef geht_nicht - for (k = 0; k < dim; k++) - for (j = 0; j < Sp34(k).anz; j++) - { - i = Ind34(k, j); - Aik34(k, j, u) /= w->Diag[k]; /* Untermatrix */ - Aik34(k, j, 0) /= w->Diag[i]; /* Obermatrix o=0! */ - } - for (k = 0; k < dim; k++) - w->Diag[k] = 1.; + for (k = 0; k < dim; k++) + for (j = 0; j < Sp34(k).anz; j++) + { + i = Ind34(k, j); + Aik34(k, j, u) /= w->Diag[k]; /* Untermatrix */ + Aik34(k, j, 0) /= w->Diag[i]; /* Obermatrix o=0! */ + } + for (k = 0; k < dim; k++) + w->Diag[k] = 1.; #endif - } - break; + } + break; - case 1: /* Ende des Vorkonditionierers */ - if (VK_Modus (VK_Extraktion)) /* immer zuletzt: Startloesung addieren */ - { - for (i = 0; i < dim; i++) - x[i] += x0[i]; - x0 = (double*) Free(x0); - } - break; /* Matrix fuer ILU-Zerlegung wird nicht freigegeben! */ + case 1: /* Ende des Vorkonditionierers */ + if (VK_Modus(VK_Extraktion)) /* immer zuletzt: Startloesung addieren */ + { + for (i = 0; i < dim; i++) + x[i] += x0[i]; + x0 = (double*)Free(x0); + } + break; /* Matrix fuer ILU-Zerlegung wird nicht freigegeben! */ - case 3: /* Linkstransformation des Gesamtsystems x <= L(t)*b */ - u = 0; - o = w->usym; - /* kein break! "Fall through" nach Aufgabe 2 */ + case 3: /* Linkstransformation des Gesamtsystems x <= L(t)*b */ + u = 0; + o = w->usym; + /* kein break! "Fall through" nach Aufgabe 2 */ - case 2: /* Linkstransformation x <= L*b */ - if (VK_Modus (VK_iLDU)) /* incomplete L(D)U-Zerlegung */ - { - if (w->stat < 2) /* Matrix ist noch nicht zerlegt */ + case 2: /* Linkstransformation x <= L*b */ + if (VK_Modus(VK_iLDU)) /* incomplete L(D)U-Zerlegung */ { - for (k = 0; k < dim; k++) /* Spalten reduzieren */ + if (w->stat < 2) /* Matrix ist noch nicht zerlegt */ { - for (j = 0; j < Sp34(k).anz; j++) + for (k = 0; k < dim; k++) /* Spalten reduzieren */ { - Oik = Aik34(k, j, o); - if (u) - Uki = Aik34(k, j, u); - i = Ind34(k, j); - - /* Skalarprodukte abziehen */ - jk = 0; - zk = Ind34(k, jk); /* oberstes Element Spalte k */ - for (ji = 0; ji < Sp34(i).anz; ji++) + for (j = 0; j < Sp34(k).anz; j++) { - while (Ind34(i, ji) > zk) - zk = Ind34(k, ++jk); /* zk existiert! */ - if (zk == Ind34(i, ji)) + Oik = Aik34(k, j, o); + if (u) + Uki = Aik34(k, j, u); + i = Ind34(k, j); + + /* Skalarprodukte abziehen */ + jk = 0; + zk = Ind34(k, jk); /* oberstes Element Spalte k */ + for (ji = 0; ji < Sp34(i).anz; ji++) { - Oik -= Bik34(i, ji, u) * Bik34(k, - jk, - o); - if (u) - Uki -= - Bik34(i, ji, - o) * Bik34(k, - jk, - u); - } - } /* Ende ji Skalarprodukt */ - Bik34(k, j, o) = Oik; - if (u) - Bik34(k, j, u) = Uki; - } /* j, Spaltenelemente staffeln */ - - /* Diagonale extrahieren mit Sk.prod. fuer Diagonalelement */ - Dkk = w->Diag[k]; - for (jk = 0; jk < Sp34(k).anz; jk++) - { - Oik = Bik34(k, jk, o); - zk = Ind34(k, jk); - Bik34(k, jk, o) *= w->PreD[zk]; - if (u) - Bik34(k, jk, u) *= w->PreD[zk]; - Dkk -= Bik34(k, jk, u) * Oik; + while (Ind34(i, ji) > zk) + zk = Ind34(k, ++jk); /* zk existiert! */ + if (zk == Ind34(i, ji)) + { + Oik -= Bik34(i, ji, u) * Bik34(k, jk, o); + if (u) + Uki -= Bik34(i, ji, o) * Bik34(k, jk, u); + } + } /* Ende ji Skalarprodukt */ + Bik34(k, j, o) = Oik; + if (u) + Bik34(k, j, u) = Uki; + } /* j, Spaltenelemente staffeln */ + + /* Diagonale extrahieren mit Sk.prod. fuer Diagonalelement */ + Dkk = w->Diag[k]; + for (jk = 0; jk < Sp34(k).anz; jk++) + { + Oik = Bik34(k, jk, o); + zk = Ind34(k, jk); + Bik34(k, jk, o) *= w->PreD[zk]; + if (u) + Bik34(k, jk, u) *= w->PreD[zk]; + Dkk -= Bik34(k, jk, u) * Oik; + } + if (fabs(Dkk) < fastNull) + /*sign */ + Dkk = (Dkk < 0.0) ? -fastNull : fastNull; + w->PreD[k] = 1.0 / Dkk; /* Kehrwert speichern */ } - if (fabs(Dkk) < fastNull) - /*sign */ - Dkk = (Dkk < 0.0) ? -fastNull : fastNull; - w->PreD[k] = 1.0 / Dkk; /* Kehrwert speichern */ + w->stat = 2; /* merken! */ + } /* Ende der Zerlegung */ + /* genaeherte Loesung von A*x = b. Ergebnis: x */ + for (k = 0; k < dim; k++) /* vorwaerts einsetzen mit Untermatrix */ + { + r = b[k]; + for (j = 0; j < Sp34(k).anz; j++) + r -= Bik34(k, j, u) * x[Ind34(k, j)]; + x[k] = r; } - w->stat = 2; /* merken! */ - } /* Ende der Zerlegung */ - /* genaeherte Loesung von A*x = b. Ergebnis: x */ - for (k = 0; k < dim; k++) /* vorwaerts einsetzen mit Untermatrix */ - { - r = b[k]; - for (j = 0; j < Sp34(k).anz; j++) - r -= Bik34(k, j, u) * x[Ind34(k, j)]; - x[k] = r; - } - for (k = 0; k < dim; k++) - x[k] *= w->PreD[k]; /* Diagonal-Normierung */ - for (k = dim - 1; k > 0; k--) /* rueckwaerts einsetzen mit Obermatrix */ - { - r = x[k]; - for (j = 0; j < Sp34(k).anz; j++) - x[Ind34(k, j)] -= Bik34(k, j, o) * r; - } - } /* Ende ILU-Vorkonditionierer */ - } /* switch aufgabe */ -} /*M34Precond */ + for (k = 0; k < dim; k++) + x[k] *= w->PreD[k]; /* Diagonal-Normierung */ + for (k = dim - 1; k > 0; k--) /* rueckwaerts einsetzen mit Obermatrix */ + { + r = x[k]; + for (j = 0; j < Sp34(k).anz; j++) + x[Ind34(k, j)] -= Bik34(k, j, o) * r; + } + } /* Ende ILU-Vorkonditionierer */ + } /* switch aufgabe */ +} /*M34Precond */ /**** Modell 5 ************************************************************/ // WW/PA 16/02/2006 void M5Vorkond(int aufgabe, double* x, double* b) { - Modell2* w = (Modell2*) wurzel; + Modell2* w = (Modell2*)wurzel; register long k; register int i; - static double* x0, * r0, h; - long ii; //, count1; + static double *x0, *r0, h; + long ii; //, count1; double v_diag = 0.0; #ifdef ERROR_CONTROL @@ -3418,117 +3366,116 @@ void M5Vorkond(int aufgabe, double* x, double* b) //====================================================================== switch (aufgabe) { - //-------------------------------------------------------------------- - case 0: /* Start des Vorkonditionierers */ - if VK_Modus - (VK_Extraktion) - { /* immer zuerst! */ - x0 = (double*) Malloc(sizeof(double) * dim); - r0 = (double*) Malloc(sizeof(double) * dim); - MXResiduum(x, b, r0); /* Rechte Seite ex A*(Startloesung x) */ - for (i = 0; i < dim; i++) - { - b[i] = r0[i]; - x0[i] = x[i]; - x[i] = 0.0; - } - r0 = (double*) Free(r0); - } - if VK_Modus - (VK_Skalierung) - { - for (k = 0; k < Dim_L; k++) - { - v_diag = jdiag[diag5_i[k]]; - if(fabs(v_diag) > DBL_MIN) - { - h = 1. / v_diag; - b[k] *= h; + //-------------------------------------------------------------------- + case 0: /* Start des Vorkonditionierers */ + if + VK_Modus(VK_Extraktion) + { /* immer zuerst! */ + x0 = (double*)Malloc(sizeof(double) * dim); + r0 = (double*)Malloc(sizeof(double) * dim); + MXResiduum(x, b, r0); /* Rechte Seite ex A*(Startloesung x) */ + for (i = 0; i < dim; i++) + { + b[i] = r0[i]; + x0[i] = x[i]; + x[i] = 0.0; + } + r0 = (double*)Free(r0); } - else + if + VK_Modus(VK_Skalierung) { - DisplayMsg("!!! Equation system: Line: "); - DisplayLong(k); - DisplayMsg(" Value: "); - DisplayDouble(Diag2(k), 0, 0); - DisplayMsgLn(""); - DisplayMsgLn( - "!!! Diagonal near zero! Disable diagonal preconditioner!"); - exit(1); - } - } - - // For test, must be improved + for (k = 0; k < Dim_L; k++) + { + v_diag = jdiag[diag5_i[k]]; + if (fabs(v_diag) > DBL_MIN) + { + h = 1. / v_diag; + b[k] *= h; + } + else + { + DisplayMsg("!!! Equation system: Line: "); + DisplayLong(k); + DisplayMsg(" Value: "); + DisplayDouble(Diag2(k), 0, 0); + DisplayMsgLn(""); + DisplayMsgLn("!!! Diagonal near zero! Disable diagonal preconditioner!"); + exit(1); + } + } - double val; - for (k = 0; k < Dim_L; k++) - { - v_diag = MXGet(k,k); - for (ii = 0; ii < Dim_L; ii++) - { - val = MXGet(k,ii); - val /= v_diag; - MXSet(k,ii,val); - } - } + // For test, must be improved - /* - long count1 = 0; - for (k = 0; k < jd_ptr_max; k++) - { - for (i = 0; i < jd_ptr[k]; i++) - { - // Row of equation system - ii = jd_ptr2[i]; - v_diag = jdiag[diag5_i[ii]]; - if(fabs(v_diag) > DBL_MIN) - jdiag[count1] /= v_diag; // - count1++; - } - } - */ - ///////////////////////////////////////////////// + double val; + for (k = 0; k < Dim_L; k++) + { + v_diag = MXGet(k, k); + for (ii = 0; ii < Dim_L; ii++) + { + val = MXGet(k, ii); + val /= v_diag; + MXSet(k, ii, val); + } + } - /* - // Diagonal-Skalierung - for (k = 0; k < dim; k++) - { - if(fabs(Diag2(k)) > DBL_MIN) { - h = 1. / Diag2(k); - b[k] *= h; - for (i = 0; i < Zeil2(k).anz; i++) - Aik2(k, i) *= h; - } else { - DisplayMsg("!!! Equation system: Line: "); - DisplayLong(k); - DisplayMsg(" Value: "); - DisplayDouble(Diag2(k), 0, 0); - DisplayMsgLn(""); - DisplayMsgLn("!!! Diagonal near zero! Disable diagonal preconditioner!"); - exit(1); - } - } - */ - } - break; - //-------------------------------------------------------------------- - case 1: /* Ende des Vorkonditionierers */ - if VK_Modus - (VK_Extraktion) - { /* immer zuletzt: Startloesung addieren */ - for (i = 0; i < dim; i++) - x[i] += x0[i]; - x0 = (double*) Free(x0); - } - break; - //-------------------------------------------------------------------- - case 2: - //-------------------------------------------------------------------- - case 3: /* Linkstransformationen */ - if VK_Modus - (VK_iLDU) /* incomplete L(D)U-Zerlegung geht nicht! */ - DisplayMsgLn("Modell 2: kein ILU-Vorkonditionierer!"); + /* + long count1 = 0; + for (k = 0; k < jd_ptr_max; k++) + { + for (i = 0; i < jd_ptr[k]; i++) + { + // Row of equation system + ii = jd_ptr2[i]; + v_diag = jdiag[diag5_i[ii]]; + if(fabs(v_diag) > DBL_MIN) + jdiag[count1] /= v_diag; // + count1++; + } + } + */ + ///////////////////////////////////////////////// + + /* + // Diagonal-Skalierung + for (k = 0; k < dim; k++) + { + if(fabs(Diag2(k)) > DBL_MIN) { + h = 1. / Diag2(k); + b[k] *= h; + for (i = 0; i < Zeil2(k).anz; i++) + Aik2(k, i) *= h; + } else { + DisplayMsg("!!! Equation system: Line: "); + DisplayLong(k); + DisplayMsg(" Value: "); + DisplayDouble(Diag2(k), 0, 0); + DisplayMsgLn(""); + DisplayMsgLn("!!! Diagonal near zero! Disable diagonal preconditioner!"); + exit(1); + } + } + */ + } + break; + //-------------------------------------------------------------------- + case 1: /* Ende des Vorkonditionierers */ + if + VK_Modus(VK_Extraktion) + { /* immer zuletzt: Startloesung addieren */ + for (i = 0; i < dim; i++) + x[i] += x0[i]; + x0 = (double*)Free(x0); + } + break; + //-------------------------------------------------------------------- + case 2: //-------------------------------------------------------------------- + case 3: /* Linkstransformationen */ + if + VK_Modus(VK_iLDU) /* incomplete L(D)U-Zerlegung geht nicht! */ + DisplayMsgLn("Modell 2: kein ILU-Vorkonditionierer!"); + //-------------------------------------------------------------------- } //====================================================================== } @@ -3572,7 +3519,7 @@ void MXDumpGLS(const char* name, int modus, double* rechts, double* ergebnis) return; for (i = 0; i < dim; i++) - { /* Nicht-Null-Elemente zaehlen */ + { /* Nicht-Null-Elemente zaehlen */ for (j = 0; j < dim; j++) /* !quadratisches Problem! (Ra) */ if (fabs(MXGet(i, j)) > MKleinsteZahl) NonZeroMatrix++; @@ -3581,7 +3528,7 @@ void MXDumpGLS(const char* name, int modus, double* rechts, double* ergebnis) } if (modus == 0) - { /* Map des gesamten GLS */ + { /* Map des gesamten GLS */ FilePrintString(dumpfile, "Variables=i,j,X\nZone, i="); FilePrintLong(dumpfile, dim * (dim + 2)); FilePrintString(dumpfile, ", f=point\n"); @@ -3596,15 +3543,15 @@ void MXDumpGLS(const char* name, int modus, double* rechts, double* ergebnis) } } if (modus == 1) - { /* Map der ungleich-null Werte des GLS */ + { /* Map der ungleich-null Werte des GLS */ FilePrintString(dumpfile, "Variables=i,j,X\n"); for (i = 0; i < dim; i++) { for (j = 0; j < dim; j++) if (fabs(MXGet(i, j)) > 0.0) { - FilePrintDouble(dumpfile, (double) i); - FilePrintDouble(dumpfile, (double) j); + FilePrintDouble(dumpfile, (double)i); + FilePrintDouble(dumpfile, (double)j); FilePrintDouble(dumpfile, MXGet(i, j)); FilePrintString(dumpfile, "\n"); } @@ -3620,18 +3567,18 @@ void MXDumpGLS(const char* name, int modus, double* rechts, double* ergebnis) if (ergebnis) if (fabs(ergebnis[i]) > MKleinsteZahl) { - FilePrintDouble(dumpfile, (double) i); - FilePrintDouble(dumpfile, (double) (dim + 2)); + FilePrintDouble(dumpfile, (double)i); + FilePrintDouble(dumpfile, (double)(dim + 2)); FilePrintDouble(dumpfile, ergebnis[i]); FilePrintString(dumpfile, "\n"); } } - //TEST WW + // TEST WW FilePrintString(dumpfile, "RHS\n"); for (i = 0; i < dim; i++) { - FilePrintDouble(dumpfile, (double) i); + FilePrintDouble(dumpfile, (double)i); FilePrintDouble(dumpfile, rechts[i]); FilePrintString(dumpfile, "\n"); } @@ -3656,8 +3603,8 @@ void MXDumpGLS(const char* name, int modus, double* rechts, double* ergebnis) for (j = 0; j < dim; j++) if (fabs(MXGet(i, j)) > MKleinsteZahl) { - FilePrintDouble(dumpfile, (double) i); - FilePrintDouble(dumpfile, (double) j); + FilePrintDouble(dumpfile, (double)i); + FilePrintDouble(dumpfile, (double)j); FilePrintDouble(dumpfile, MXGet(i, j)); FilePrintString(dumpfile, "\n"); } @@ -3695,17 +3642,17 @@ void MXEstimateStartVector(double* ReSei, double* x0) register long i; if (VK_Modus(VK_iLDU) && matrix_type != 2) - MXVorkond(2, x0, ReSei); /* Startvektor aus ILU-Zerlegung */ + MXVorkond(2, x0, ReSei); /* Startvektor aus ILU-Zerlegung */ else - { /* Startvektor aus Zeilen-Lumping */ - double* sum = (double*) Malloc(dim * sizeof(double)); + { /* Startvektor aus Zeilen-Lumping */ + double* sum = (double*)Malloc(dim * sizeof(double)); for (i = 0; i < dim; i++) x0[i] = 1.0; - MXMatVek(x0, sum); /* sum: Zeilensummen von A */ + MXMatVek(x0, sum); /* sum: Zeilensummen von A */ for (i = 0; i < dim; i++) x0[i] = ReSei[i] / sum[i]; - sum = (double*) Free(sum); + sum = (double*)Free(sum); } } diff --git a/FEM/matrix_routines.h b/FEM/matrix_routines.h index 0febfe049..2e5982f99 100644 --- a/FEM/matrix_routines.h +++ b/FEM/matrix_routines.h @@ -62,10 +62,10 @@ /* Deklarationen */ /* allgemeine Funktionen */ -extern void* MXSetupMatrix (long, long, long); +extern void* MXSetupMatrix(long, long, long); /* Erstellt eine Matrix und initialisiert alle noetigen Pointer */ -extern void MXSetMatrixPointer ( void* matrix_pointer ); +extern void MXSetMatrixPointer(void* matrix_pointer); /* Setzt den internen Matrix-Wurzelzeiger auf die angegebene Matrix-Wurzel. Alle folgenden Aufrufe der MX-Funktionen beziehen sich dann auf die gewaehlte Matrix. Dadurch entfaellt die Parameteruebergabe des @@ -74,14 +74,14 @@ extern void MXSetMatrixPointer ( void* matrix_pointer ); Setzt auch die MX-Funktionszeiger auf die entsprechenden Funktionen des angegebenen Speichermodells! */ -extern void* MXGetMatrixPointer ( void ); +extern void* MXGetMatrixPointer(void); /* Liefert einen Zeiger auf die gerade aktive Matrix */ -extern long MXGetDim ( void ); +extern long MXGetDim(void); /* liefert Dimension der zuvor mit MXSetMatrixPointer angegebenen Matrix-Struktur. */ -extern void MXDumpGLS ( const char*, int, double*, double*); +extern void MXDumpGLS(const char*, int, double*, double*); /* Schreibt das durch die zuvor mit MXSetMatrixPointer angegebene Matrix und den Vektor gegebene GLeichungssystem eine Datei "GLS" */ @@ -89,7 +89,7 @@ extern void MXEstimateStartVector(double*, double*); /* Versucht mit Hilfe eines Zeilen-Masslumpings eine gute Startloseung fuer den Gleichungsloeser zu finden */ -extern void MXRandbed (long, double, double*); +extern void MXRandbed(long, double, double*); /* Einarbeiten einer Randbedingung in Matrix und Rechte Seite */ extern void MXEliminateIrrNode(long index, int anz_nachbarn, long* nachbarn_index, double* rechts); /* Elimieren irr. Knoten aus dem Gesamtsystem */ @@ -99,56 +99,56 @@ extern void MXResiduum(double* x, double* b, double* ergebnis); komplett ueberschrieben; der Speicher muss bereits allokiert sein. */ /* MX-Funktionszeiger (Typen) */ -typedef void*(*MXPCreateMatrix)( long param1, long param2, long param3 ); +typedef void* (*MXPCreateMatrix)(long param1, long param2, long param3); /* Erzeugen einer neuen Matrix-Struktur im zuvor mit MXSetFunctionPointers implizit angegebenen Speichermodell. Das Ergebnis ist der Matrix-Wurzelzeiger. Die Parameter werden abhaengig vom Speichermodell unterschiedlich benutzt (z.B. fuer Bandbreite etc.). */ -typedef void* (*MXPDestroyMatrix)( void ); +typedef void* (*MXPDestroyMatrix)(void); /* Freigeben der zuvor mit MXSetMatrixPointer angegebenen Matrix-Struktur; Ergebnis ist immer NULL. */ -typedef void (*MXPResizeMatrix)( long dimension ); +typedef void (*MXPResizeMatrix)(long dimension); /* Veraendern der Groesse der zuvor mit MXSetMatrixPointer angegebenen Matrix-Struktur. Der Wurzelzeiger bleibt erhalten, die bisher eingetragenen Werte nicht. Die Matrix wird nur vergroessert, nie verkleinert. */ -typedef void (*MXPInitMatrix)( void ); +typedef void (*MXPInitMatrix)(void); /* Initialisieren (A[i,j] = 0.0) aller Elemente der zuvor mit MXSetMatrixPointer angegebenen Matrix-Struktur. */ -typedef int (*MXPSet)( long i, long j, double aij ); +typedef int (*MXPSet)(long i, long j, double aij); /* Setzen des Wertes aij als Matrixwert A[i,j] der zuvor mit MXSetMatrixPointer angegebenen Matrix-Struktur. */ -typedef int (*MXPInc)( long i, long j, double aij_inc ); +typedef int (*MXPInc)(long i, long j, double aij_inc); /* Inkrementieren des Matrixwertes A[i,j] der zuvor mit MXSetMatrixPointer angegebenen Matrix-Struktur um den Wert aij_inc. */ -typedef int (*MXPDec)( long i, long j, double aij_dec ); +typedef int (*MXPDec)(long i, long j, double aij_dec); /* Dekrementieren des Matrixwertes A[i,j] der zuvor mit MXSetMatrixPointer angegebenen Matrix-Struktur um den Wert aij_dec. */ -typedef int (*MXPMul)( long i, long j, double aij_mul ); +typedef int (*MXPMul)(long i, long j, double aij_mul); /* Multiplizieren des Matrixwertes A[i,j] der zuvor mit MXSetMatrixPointer angegebenen Matrix-Struktur mit dem Wert aij_mul. */ -typedef int (*MXPDiv)( long i, long j, double aij_div ); +typedef int (*MXPDiv)(long i, long j, double aij_div); /* Dividieren des Matrixwertes A[i,j] der zuvor mit MXSetMatrixPointer angegebenen Matrix-Struktur durch den Wert aij_div. */ -typedef double (*MXPGet)( long i, long j ); +typedef double (*MXPGet)(long i, long j); /* Ergebnis ist der Matrixwert A[i,j] der zuvor mit MXSetMatrixPointer angegebenen Matrix-Struktur. */ -typedef void (*MXPTrans)( long i, long j, long ii, long jj ); +typedef void (*MXPTrans)(long i, long j, long ii, long jj); /* Fuehrt in der zuvor mit MXSetMatrixPointer angegebenen Matrix-Struktur folgende Operation durch: A[i,j] = A[ii,jj] */ -typedef void (*MXPMatVek)( double* vektor, double* ergebnis ); +typedef void (*MXPMatVek)(double* vektor, double* ergebnis); /* Ausf hren des Matrix-Vektor-Produktes "A * vektor = ergebnis" mit der zuvor mit MXSetMatrixPointer angegebenen Matrix-Struktur. "ergebnis" wird komplett ueberschrieben; der Speicher muss bereits allokiert sein. */ -typedef void (*MXPMatTVek)( double* vektor, double* ergebnis ); +typedef void (*MXPMatTVek)(double* vektor, double* ergebnis); /* Ausfuehren des Matrix-Vektor-Produktes "A^T * vektor = ergebnis" mit der zuvor mit MXSetMatrixPointer angegebenen Matrix-Struktur. "ergebnis" wird komplett ueberschrieben; der Speicher muss bereits allokiert sein. */ -typedef void (*MXPVorkond)( int aufgabe, double* x, double* b); +typedef void (*MXPVorkond)(int aufgabe, double* x, double* b); /* Vorkonditionierer nach dem mit vorkond gewaehlten Verfahren */ -typedef int (*MXPCopyToAMG1R5Structure)( double* A, int* IA, int* JA, int NDA, int NDIA, int NDJA, - double*, double*, double*, double*); +typedef int (*MXPCopyToAMG1R5Structure)(double* A, int* IA, int* JA, int NDA, int NDIA, int NDJA, double*, double*, + double*, double*); /* Umkopieren einer Matrix auf AMG1R5-Speicherstruktur */ /* zugehoerige MX-Funktionszeiger */ diff --git a/FEM/par_ddc.cpp b/FEM/par_ddc.cpp index 9dd431824..e06b9f00d 100644 --- a/FEM/par_ddc.cpp +++ b/FEM/par_ddc.cpp @@ -26,8 +26,8 @@ // #error to indicate a fatal error. Users can either #undef // the names before including mpi.h or include mpi.h *before* stdio.h // or iostream. -#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || \ - defined(USE_MPI_GEMS) || defined(USE_MPI_KRC) +#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_GEMS) \ + || defined(USE_MPI_KRC) //#undef SEEK_SET //WW //#undef SEEK_END //WW //#undef SEEK_CUR //WW @@ -45,7 +45,7 @@ using namespace std; #include "par_ddc.h" // FEM-Makros #include "makros.h" -#ifndef NEW_EQS //WW. 11.2008 +#ifndef NEW_EQS // WW. 11.2008 #include "matrix_routines.h" #endif #include "files0.h" @@ -55,8 +55,8 @@ using namespace std; #include "equation_class.h" #include "matrix_class.h" #endif -vectordom_vector; -vector node_connected_doms; //This will be removed after sparse class is finished WW +vector dom_vector; +vector node_connected_doms; // This will be removed after sparse class is finished WW /************************************************************************** STRLib-Method: @@ -67,7 +67,7 @@ vector node_connected_doms; //This will be removed after s bool KeywordFound(string line) { string hash("#"); - if(line.find(hash) != string::npos) + if (line.find(hash) != string::npos) return true; else return false; @@ -82,7 +82,7 @@ bool KeywordFound(string line) bool SubKeywordFound(string line) { string dollar("$"); - if(line.find(dollar) != string::npos) + if (line.find(dollar) != string::npos) return true; else return false; @@ -111,31 +111,33 @@ void DOMRead(string file_base_name) //---------------------------------------------------------------------- // File handling ddc_file_name = file_base_name + DDC_FILE_EXTENSION; - ifstream ddc_file (ddc_file_name.data(),ios::in); - if(!ddc_file.good()) + ifstream ddc_file(ddc_file_name.data(), ios::in); + if (!ddc_file.good()) { - cout << "no DDC file" << "\n"; + cout << "no DDC file" + << "\n"; return; } - ddc_file.seekg(0L,ios::beg); + ddc_file.seekg(0L, ios::beg); //---------------------------------------------------------------------- // Keyword loop while (!ddc_file.eof()) { - ddc_file.getline(line,MAX_ZEILE); + ddc_file.getline(line, MAX_ZEILE); line_string = line; //---------------------------------------------------------------------- // keyword found - if(line_string.find("#DOMAIN") != string::npos) + if (line_string.find("#DOMAIN") != string::npos) { m_dom = new CPARDomain(); position = m_dom->Read(&ddc_file); dom_vector.push_back(m_dom); - ddc_file.seekg(position,ios::beg); - } // keyword found - } // eof + ddc_file.seekg(position, ios::beg); + } // keyword found + } // eof //---------------------------------------------------------------------- - cout << dom_vector.size() << " domains" << "\n"; + cout << dom_vector.size() << " domains" + << "\n"; //---------------------------------------------------------------------- } @@ -147,36 +149,36 @@ void DOMRead(string file_base_name) **************************************************************************/ void CountDoms2Nodes(CRFProcess* m_pcs) { - size_t i,j,k; + size_t i, j, k; long n_index = 0; CPARDomain* m_dom = NULL; MeshLib::CNode* anode = NULL; MeshLib::CElem* elem = NULL; CFEMesh* a_msh = m_pcs->m_msh; - //Average of nodal Neumann BCs contributed by nodes from different domains + // Average of nodal Neumann BCs contributed by nodes from different domains bool quad = false; - if(m_pcs->type == 4 || m_pcs->type == 41) + if (m_pcs->type == 4 || m_pcs->type == 41) quad = true; size_t nsize = m_pcs->m_msh->GetNodesNumber(quad); node_connected_doms.resize(nsize); - for(j = 0; j < nsize; j++) + for (j = 0; j < nsize; j++) node_connected_doms[j] = 0; - for(i = 0; i < dom_vector.size(); i++) + for (i = 0; i < dom_vector.size(); i++) { m_dom = dom_vector[i]; - for(j = 0; j < nsize; j++) + for (j = 0; j < nsize; j++) a_msh->nod_vector[j]->SetMark(false); - for(j = 0; j < m_dom->elements.size(); j++) + for (j = 0; j < m_dom->elements.size(); j++) { elem = a_msh->ele_vector[m_dom->elements[j]]; - if(elem->GetMark()) - for(k = 0; k < elem->GetNodesNumber(quad); k++) + if (elem->GetMark()) + for (k = 0; k < elem->GetNodesNumber(quad); k++) { n_index = elem->GetNodeIndex(k); anode = elem->GetNode(k); - if(!anode->GetMark()) + if (!anode->GetMark()) { node_connected_doms[n_index] += 1; anode->SetMark(true); @@ -185,11 +187,11 @@ void CountDoms2Nodes(CRFProcess* m_pcs) } } // - for(j = 0; j < a_msh->ele_vector.size(); j++) + for (j = 0; j < a_msh->ele_vector.size(); j++) { elem = a_msh->ele_vector[j]; - if(elem->GetMark()) - for(k = 0; k < elem->GetNodesNumber(quad); k++) + if (elem->GetMark()) + for (k = 0; k < elem->GetNodesNumber(quad); k++) { anode = elem->GetNode(k); anode->SetMark(true); @@ -210,30 +212,31 @@ void CountDoms2Nodes(CRFProcess* m_pcs) void DOMCreate() { size_t no_domains = dom_vector.size(); - if(no_domains == 0) + if (no_domains == 0) return; CPARDomain* m_dom = NULL; CRFProcess* m_pcs = NULL; - bool quadr = false; //WW + bool quadr = false; // WW size_t i; - //WW ----- D + // WW ----- D //---------------------------------------------------------------------- - for(i = 0; i < pcs_vector.size(); i++) + for (i = 0; i < pcs_vector.size(); i++) { m_pcs = pcs_vector[i]; // if(m_pcs->pcs_type_name.find("DEFORMATION")!=string::npos) { // TF 10/2010 - if(isDeformationProcess (m_pcs->getProcessType ())) + if (isDeformationProcess(m_pcs->getProcessType())) { quadr = true; break; } } - if(!quadr) + if (!quadr) m_pcs = pcs_vector[0]; //---------------------------------------------------------------------- // Create domain nodes - cout << "->Create DOM" << "\n"; + cout << "->Create DOM" + << "\n"; /* // Comment by WW for(i=0;im_msh = m_pcs->m_msh; @@ -253,8 +257,9 @@ void DOMCreate() } //---------------------------------------------------------------------- // Create domain elements - cout << " Create domain elements" << "\n"; - for(i = 0; i < no_domains; i++) + cout << " Create domain elements" + << "\n"; + for (i = 0; i < no_domains; i++) { m_dom = dom_vector[i]; cout << " Domain:" << m_dom->ID << "\n"; @@ -263,54 +268,57 @@ void DOMCreate() // For find nodes connected to node WW long j; long nsize = m_pcs->m_msh->GetNodesNumber(true); - //node_connected_doms.resize(nsize); - for(j = 0; j < nsize; j++) + // node_connected_doms.resize(nsize); + for (j = 0; j < nsize; j++) node_connected_doms[j] = 0; - for(i = 0; i < dom_vector.size(); i++) + for (i = 0; i < dom_vector.size(); i++) { m_dom = dom_vector[i]; - for(j = 0; j < (long)m_dom->nodes.size(); j++) + for (j = 0; j < (long)m_dom->nodes.size(); j++) node_connected_doms[m_dom->nodes[j]] += 1; } // // Find nodes of all neighbors of each node. // WW // Local topology. WW - cout << " Find nodes on borders" << "\n"; + cout << " Find nodes on borders" + << "\n"; FindNodesOnInterface(m_pcs->m_msh, quadr); - cout << " Find the connected nodes for each node" << "\n"; -#ifndef USE_MPI //WW - for(i = 0; i < no_domains; i++) + cout << " Find the connected nodes for each node" + << "\n"; +#ifndef USE_MPI // WW + for (i = 0; i < no_domains; i++) { #else - i = myrank; //WW + i = myrank; // WW #endif m_dom = dom_vector[i]; m_dom->NodeConnectedNodes(); -#ifndef USE_MPI //WW +#ifndef USE_MPI // WW } #endif - //---------------------------------------------------------------------- - // Create domain EQS - cout << " Create domain EQS" << "\n"; + //---------------------------------------------------------------------- + // Create domain EQS + cout << " Create domain EQS" + << "\n"; #ifdef USE_MPI - i = myrank; + i = myrank; #else - for(i = 0; i < no_domains; i++) - { + for (i = 0; i < no_domains; i++) + { #endif - m_dom = dom_vector[i]; - cout << " Domain:" << m_dom->ID << "\n"; + m_dom = dom_vector[i]; + cout << " Domain:" << m_dom->ID << "\n"; #ifdef NEW_EQS - m_dom->CreateEQS(); + m_dom->CreateEQS(); #else m_dom->CreateEQS(m_pcs); #endif - // +// #ifndef USE_MPI - } +} #endif - //---------------------------------------------------------------------- - } +//---------------------------------------------------------------------- +} ////////////////////////////////////////////////////////////////////////// // CPARDomain @@ -321,86 +329,86 @@ void DOMCreate() Programing: 07/2004 OK Implementation **************************************************************************/ - CPARDomain::CPARDomain(void) - { - ID = (int)dom_vector.size(); - for(int i = 0; i < 5; i++) //WW - shift[i] = 0; - quadratic = false; //WW +CPARDomain::CPARDomain(void) +{ + ID = (int)dom_vector.size(); + for (int i = 0; i < 5; i++) // WW + shift[i] = 0; + quadratic = false; // WW #ifdef NEW_EQS - sparse_graph = NULL; - sparse_graph_H = NULL; - eqs = NULL; - eqsH = NULL; + sparse_graph = NULL; + sparse_graph_H = NULL; + eqs = NULL; + eqsH = NULL; #endif -#if defined(USE_MPI) // 13.12.2007 WW - t_border_nodes = NULL; - t_border_nodes_size = t_border_nodes_sizeH = 0; - // +#if defined(USE_MPI) // 13.12.2007 WW + t_border_nodes = NULL; + t_border_nodes_size = t_border_nodes_sizeH = 0; +// #if defined(NEW_BREDUCE) - receive_cnt_b = new int[mysize]; - receive_disp_b = new int[mysize]; + receive_cnt_b = new int[mysize]; + receive_disp_b = new int[mysize]; #endif - receive_cnt_i = new int[mysize]; - receive_disp_i = new int[mysize]; - receive_cnt = new int[mysize]; - receive_disp = new int[mysize]; + receive_cnt_i = new int[mysize]; + receive_disp_i = new int[mysize]; + receive_cnt = new int[mysize]; + receive_disp = new int[mysize]; #endif - } +} - CPARDomain::~CPARDomain(void) +CPARDomain::~CPARDomain(void) +{ + elements.clear(); + nodes.clear(); + nodes_inner.clear(); + nodes_halo.clear(); + long i; + + // WW + for (i = 0; i < (long)element_nodes_dom.size(); i++) { - elements.clear(); - nodes.clear(); - nodes_inner.clear(); - nodes_halo.clear(); - long i; - - // WW - for(i = 0; i < (long)element_nodes_dom.size(); i++) - { - delete [] element_nodes_dom[i]; - element_nodes_dom[i] = NULL; - } - for(long i = 0; i < (long)node_conneted_nodes.size(); i++) - { - delete [] node_conneted_nodes[i]; - node_conneted_nodes[i] = NULL; - } + delete[] element_nodes_dom[i]; + element_nodes_dom[i] = NULL; + } + for (long i = 0; i < (long)node_conneted_nodes.size(); i++) + { + delete[] node_conneted_nodes[i]; + node_conneted_nodes[i] = NULL; + } - // +// #ifdef NEW_EQS - if(eqs) - delete eqs; - if(eqsH) - delete eqsH; - if(sparse_graph) - delete sparse_graph; - if(sparse_graph_H) - delete sparse_graph_H; + if (eqs) + delete eqs; + if (eqsH) + delete eqsH; + if (sparse_graph) + delete sparse_graph; + if (sparse_graph_H) + delete sparse_graph_H; #endif -#if defined(USE_MPI) // 13.12.2007 WW - // - if(t_border_nodes) - delete [] t_border_nodes; - t_border_nodes = NULL; +#if defined(USE_MPI) // 13.12.2007 WW + // + if (t_border_nodes) + delete[] t_border_nodes; + t_border_nodes = NULL; #if defined(NEW_BREDUCE) - delete [] receive_cnt_b; - delete [] receive_disp_b; - receive_cnt_b = NULL; - receive_disp_b = NULL; + delete[] receive_cnt_b; + delete[] receive_disp_b; + receive_cnt_b = NULL; + receive_disp_b = NULL; #endif - delete [] receive_cnt_i; - delete [] receive_disp_i; - delete [] receive_cnt; - delete [] receive_disp; - receive_cnt_i = NULL; - receive_disp_i = NULL; - receive_cnt = NULL; - receive_disp = NULL; + delete[] receive_cnt_i; + delete[] receive_disp_i; + delete[] receive_cnt; + delete[] receive_disp; + receive_cnt_i = NULL; + receive_disp_i = NULL; + receive_cnt = NULL; + receive_disp = NULL; #endif - } +} /************************************************************************** FEMLib-Method: @@ -409,45 +417,45 @@ void DOMCreate() 012/2007 WW Implementation **************************************************************************/ #if defined(USE_MPI) - void CPARDomain::ReleaseMemory() +void CPARDomain::ReleaseMemory() +{ + // WW + for (long i = 0; i < (long)element_nodes_dom.size(); i++) { - // WW - for(long i = 0; i < (long)element_nodes_dom.size(); i++) - { - delete [] element_nodes_dom[i]; - element_nodes_dom[i] = NULL; - } - for(long i = 0; i < (long)node_conneted_nodes.size(); i++) - { - delete [] node_conneted_nodes[i]; - node_conneted_nodes[i] = NULL; - } - if(eqs) - delete eqs; - if(eqsH) - delete eqsH; - if(sparse_graph) - delete sparse_graph; - if(sparse_graph_H) - delete sparse_graph_H; - if(t_border_nodes) - delete [] t_border_nodes; - t_border_nodes = NULL; + delete[] element_nodes_dom[i]; + element_nodes_dom[i] = NULL; + } + for (long i = 0; i < (long)node_conneted_nodes.size(); i++) + { + delete[] node_conneted_nodes[i]; + node_conneted_nodes[i] = NULL; + } + if (eqs) + delete eqs; + if (eqsH) + delete eqsH; + if (sparse_graph) + delete sparse_graph; + if (sparse_graph_H) + delete sparse_graph_H; + if (t_border_nodes) + delete[] t_border_nodes; + t_border_nodes = NULL; #if defined(NEW_BREDUCE) - delete [] receive_cnt_b; - delete [] receive_disp_b; - receive_cnt_b = NULL; - receive_disp_b = NULL; + delete[] receive_cnt_b; + delete[] receive_disp_b; + receive_cnt_b = NULL; + receive_disp_b = NULL; #endif - delete [] receive_cnt_i; - delete [] receive_disp_i; - delete [] receive_cnt; - delete [] receive_disp; - receive_cnt_i = NULL; - receive_disp_i = NULL; - receive_cnt = NULL; - receive_disp = NULL; - } + delete[] receive_cnt_i; + delete[] receive_disp_i; + delete[] receive_cnt; + delete[] receive_disp; + receive_cnt_i = NULL; + receive_disp_i = NULL; + receive_cnt = NULL; + receive_disp = NULL; +} #endif /************************************************************************** FEMLib-Method: @@ -457,101 +465,101 @@ void DOMCreate() 07/2004 OK Version 1 untill 3.9.17OK6 07/2004 OK Version 2 from 3.9.17OK7 **************************************************************************/ - ios::pos_type CPARDomain::Read(ifstream* ddc_file) +ios::pos_type CPARDomain::Read(ifstream* ddc_file) +{ + char line[MAX_ZEILE]; + string sub_line; + string sub_string; + string cut_string; + string line_string; + string delimiter(" "); + string delimiter_type(";"); + bool new_subkeyword = false; + string dollar("$"); + bool new_keyword = false; + string hash("#"); + ios::pos_type position; + long i; + // CElem* m_ele = NULL; + //====================================================================== + while (!new_keyword) { - char line[MAX_ZEILE]; - string sub_line; - string sub_string; - string cut_string; - string line_string; - string delimiter(" "); - string delimiter_type(";"); - bool new_subkeyword = false; - string dollar("$"); - bool new_keyword = false; - string hash("#"); - ios::pos_type position; - long i; - // CElem* m_ele = NULL; - //====================================================================== - while (!new_keyword) + position = ddc_file->tellg(); + ddc_file->getline(line, MAX_ZEILE); + line_string = line; + if (line_string.find(hash) != string::npos) { - position = ddc_file->tellg(); - ddc_file->getline(line,MAX_ZEILE); - line_string = line; - if(line_string.find(hash) != string::npos) + new_keyword = true; + break; + } + //.................................................................... + // subkeyword found + if (line_string.find("$ELEMENTS") != string::npos) + while ((!new_keyword) && (!new_subkeyword)) { - new_keyword = true; - break; + position = ddc_file->tellg(); + ddc_file->getline(line, MAX_ZEILE); + line_string = line; + if (line_string.find(hash) != string::npos) + { + new_keyword = true; + break; + } + if (line_string.find(dollar) != string::npos) + { + new_subkeyword = true; + break; + } + i = strtol(line, NULL, 0); + elements.push_back(i); } - //.................................................................... - // subkeyword found - if(line_string.find("$ELEMENTS") != string::npos) - while ((!new_keyword) && (!new_subkeyword)) + //.................................................................... + // subkeyword found + if (line_string.find("$NODES_INNER") != string::npos) + while (!new_keyword) + { + position = ddc_file->tellg(); + ddc_file->getline(line, MAX_ZEILE); + line_string = line; + if (line_string.find(hash) != string::npos) { - position = ddc_file->tellg(); - ddc_file->getline(line,MAX_ZEILE); - line_string = line; - if(line_string.find(hash) != string::npos) - { - new_keyword = true; - break; - } - if(line_string.find(dollar) != string::npos) - { - new_subkeyword = true; - break; - } - i = strtol(line,NULL,0); - elements.push_back(i); + new_keyword = true; + break; } - //.................................................................... - // subkeyword found - if(line_string.find("$NODES_INNER") != string::npos) - while (!new_keyword) + if (line_string.find(dollar) != string::npos) { - position = ddc_file->tellg(); - ddc_file->getline(line,MAX_ZEILE); - line_string = line; - if(line_string.find(hash) != string::npos) - { - new_keyword = true; - break; - } - if(line_string.find(dollar) != string::npos) - { - new_subkeyword = true; - break; - } - i = strtol(line,NULL,0); - nodes_inner.push_back(i); + new_subkeyword = true; + break; } - //.................................................................... - // subkeyword found - if(line_string.find("$NODES_BORDER") != string::npos) - while (!new_keyword) + i = strtol(line, NULL, 0); + nodes_inner.push_back(i); + } + //.................................................................... + // subkeyword found + if (line_string.find("$NODES_BORDER") != string::npos) + while (!new_keyword) + { + position = ddc_file->tellg(); + ddc_file->getline(line, MAX_ZEILE); + line_string = line; + if (line_string.find(hash) != string::npos) { - position = ddc_file->tellg(); - ddc_file->getline(line,MAX_ZEILE); - line_string = line; - if(line_string.find(hash) != string::npos) - { - new_keyword = true; - break; - } - if(line_string.find(dollar) != string::npos) - { - new_subkeyword = true; - break; - } - i = strtol(line,NULL,0); - nodes_halo.push_back(i); + new_keyword = true; + break; } - //.................................................................... - } - //====================================================================== - return position; + if (line_string.find(dollar) != string::npos) + { + new_subkeyword = true; + break; + } + i = strtol(line, NULL, 0); + nodes_halo.push_back(i); + } + //.................................................................... } + //====================================================================== + return position; +} /************************************************************************** PARLib-Method: @@ -559,31 +567,31 @@ void DOMCreate() Programing: 07/2004 OK Implementation **************************************************************************/ - void CPARDomain::CreateNodes() +void CPARDomain::CreateNodes() +{ + long j, k; + long no_nodes_halo, no_nodes_inner; + //---------------------------------------------------------------------- + no_nodes_inner = (long)nodes_inner.size(); + for (j = 0; j < no_nodes_inner; j++) { - long j,k; - long no_nodes_halo, no_nodes_inner; - //---------------------------------------------------------------------- - no_nodes_inner = (long)nodes_inner.size(); - for(j = 0; j < no_nodes_inner; j++) - { - k = nodes_inner[j]; - nodes.push_back(k); - //cout << nodes[j] << "\n"; - } - //cout << "---" << "\n"; - no_nodes_halo = (long)nodes_halo.size(); - for(j = 0; j < no_nodes_halo; j++) - { - k = nodes_halo[j]; - nodes.push_back(k); - //cout << nodes[no_nodes_inner+j] << "\n"; - } - nnodes_dom = no_nodes_halo + no_nodes_inner; //WW - nnodesHQ_dom = nnodes_dom; - - //---------------------------------------------------------------------- + k = nodes_inner[j]; + nodes.push_back(k); + // cout << nodes[j] << "\n"; } + // cout << "---" << "\n"; + no_nodes_halo = (long)nodes_halo.size(); + for (j = 0; j < no_nodes_halo; j++) + { + k = nodes_halo[j]; + nodes.push_back(k); + // cout << nodes[no_nodes_inner+j] << "\n"; + } + nnodes_dom = no_nodes_halo + no_nodes_inner; // WW + nnodesHQ_dom = nnodes_dom; + + //---------------------------------------------------------------------- +} /************************************************************************** PARLib-Method: @@ -593,73 +601,73 @@ void DOMCreate() 05/2006 WW Fix bugs and add the case of DOF>1 09/2007 WW Improve the extremly slow performance of the old code **************************************************************************/ - void CPARDomain::CreateElements(const bool quadr) +void CPARDomain::CreateElements(const bool quadr) +{ + //---------------------------------------------------------------------- + if (!m_msh) + return; + //---------------------------------------------------------------------- + long i, k; + int j, nNodes, nNodesHQ; + long* elem_nodes = NULL; + MeshLib::CElem* m_ele = NULL; + MeshLib::CNode* m_nod = NULL; + //*** Buffer for acceleration. 14.09.2007 WW: + // As long buffer + node_connected_doms.resize((long)m_msh->nod_vector.size()); + for (k = 0; k < (long)m_msh->nod_vector.size(); k++) + node_connected_doms[k] = -1; + for (k = 0; k < (long)nodes.size(); k++) { - //---------------------------------------------------------------------- - if(!m_msh) - return; - //---------------------------------------------------------------------- - long i,k; - int j, nNodes, nNodesHQ; - long* elem_nodes = NULL; - MeshLib::CElem* m_ele = NULL; - MeshLib::CNode* m_nod = NULL; - //*** Buffer for acceleration. 14.09.2007 WW: - // As long buffer - node_connected_doms.resize((long)m_msh->nod_vector.size()); - for(k = 0; k < (long)m_msh->nod_vector.size(); k++) - node_connected_doms[k] = -1; - for(k = 0; k < (long)nodes.size(); k++) + i = nodes[k]; + m_nod = m_msh->nod_vector[i]; + node_connected_doms[m_nod->GetIndex()] = k; + } + //*** + //---------------------------------------------------------------------- + for (i = 0; i < (long)elements.size(); i++) + { + if (elements[i] > (long)m_msh->ele_vector.size()) { - i = nodes[k]; - m_nod = m_msh->nod_vector[i]; - node_connected_doms[m_nod->GetIndex()] = k; + cout << "Warning: no ELE data" << '\n'; + continue; } - //*** - //---------------------------------------------------------------------- - for(i = 0; i < (long)elements.size(); i++) + m_ele = m_msh->ele_vector[elements[i]]; + nNodes = m_ele->GetNodesNumber(false); // WW + nNodesHQ = m_ele->GetNodesNumber(quadr); + // cout << i << " " << elements[i] << ": "; + elem_nodes = new long[nNodesHQ]; // WW + element_nodes_dom.push_back(elem_nodes); // WW + for (j = 0; j < nNodes; j++) { - if(elements[i] > (long)m_msh->ele_vector.size()) - { - cout << "Warning: no ELE data" << '\n'; - continue; - } - m_ele = m_msh->ele_vector[elements[i]]; - nNodes = m_ele->GetNodesNumber(false); //WW - nNodesHQ = m_ele->GetNodesNumber(quadr); - // cout << i << " " << elements[i] << ": "; - elem_nodes = new long[nNodesHQ]; //WW - element_nodes_dom.push_back(elem_nodes); //WW - for(j = 0; j < nNodes; j++) - { - m_nod = m_ele->GetNode(j); - //14.09.2007 WW - elem_nodes[j] = node_connected_doms[m_nod->GetIndex()]; - } - //------------------WW - if(!quadr) - continue; - for(j = nNodes; j < nNodesHQ; j++) + m_nod = m_ele->GetNode(j); + // 14.09.2007 WW + elem_nodes[j] = node_connected_doms[m_nod->GetIndex()]; + } + //------------------WW + if (!quadr) + continue; + for (j = nNodes; j < nNodesHQ; j++) + { + m_nod = m_ele->GetNode(j); + // 14.09.2007 WW + k = m_nod->GetIndex(); + if (node_connected_doms[k] > -1) + elem_nodes[j] = node_connected_doms[k]; + else { - m_nod = m_ele->GetNode(j); - //14.09.2007 WW - k = m_nod->GetIndex(); - if(node_connected_doms[k] > -1) - elem_nodes[j] = node_connected_doms[k]; - else - { - elem_nodes[j] = (long)nodes.size(); - node_connected_doms[k] = elem_nodes[j]; - nodes.push_back(m_nod->GetIndex()); - } + elem_nodes[j] = (long)nodes.size(); + node_connected_doms[k] = elem_nodes[j]; + nodes.push_back(m_nod->GetIndex()); } - nnodesHQ_dom = (long) nodes.size(); - //------------------WW - // cout << "\n"; } - // - //---------------------------------------------------------------------- + nnodesHQ_dom = (long)nodes.size(); + //------------------WW + // cout << "\n"; } + // + //---------------------------------------------------------------------- +} /************************************************************************** MSHLib-Method: @@ -668,39 +676,38 @@ void DOMCreate() 06/2006 WW Implementation 09/2007 WW Improve computational efficiency **************************************************************************/ - void CPARDomain::NodeConnectedNodes() +void CPARDomain::NodeConnectedNodes() +{ + vector nodes2node; + // node_connected_doms as buffer to accelerate the computation + // 14.09.2007 WW + const size_t n_mesh_nodes(m_msh->nod_vector.size()); + for (size_t i = 0; i < n_mesh_nodes; i++) + node_connected_doms[i] = -1; + + for (size_t j = 0; j < nodes.size(); j++) + node_connected_doms[m_msh->nod_vector[nodes[j]]->GetIndex()] = j; + + const size_t n_nodes(nodes.size()); + for (size_t i = 0; i < n_nodes; i++) { - vector nodes2node; - // node_connected_doms as buffer to accelerate the computation - // 14.09.2007 WW - const size_t n_mesh_nodes (m_msh->nod_vector.size()); - for (size_t i = 0; i < n_mesh_nodes; i++) - node_connected_doms[i] = -1; - - for (size_t j = 0; j < nodes.size(); j++) - node_connected_doms[m_msh->nod_vector[nodes[j]]->GetIndex()] = j; - - const size_t n_nodes(nodes.size()); - for (size_t i = 0; i < n_nodes; i++) + nodes2node.clear(); + std::vector const& connected_nodes(m_msh->nod_vector[nodes[i]]->getConnectedNodes()); + const size_t n_connected_nodes(connected_nodes.size()); + for (size_t k = 0; k < n_connected_nodes; k++) { - nodes2node.clear(); - std::vector const& connected_nodes( - m_msh->nod_vector[nodes[i]]->getConnectedNodes()); - const size_t n_connected_nodes(connected_nodes.size()); - for (size_t k = 0; k < n_connected_nodes; k++) - { - int j = node_connected_doms[connected_nodes[k]]; - if (j > -1) - nodes2node.push_back(j); - } - const size_t i_buff (nodes2node.size()); - long* nodes_to_node = new long[i_buff]; - for (size_t k = 0; k < i_buff; k++) - nodes_to_node[k] = nodes2node[k]; - node_conneted_nodes.push_back(nodes_to_node); - num_nodes2_node.push_back(i_buff); + int j = node_connected_doms[connected_nodes[k]]; + if (j > -1) + nodes2node.push_back(j); } + const size_t i_buff(nodes2node.size()); + long* nodes_to_node = new long[i_buff]; + for (size_t k = 0; k < i_buff; k++) + nodes_to_node[k] = nodes2node[k]; + node_conneted_nodes.push_back(nodes_to_node); + num_nodes2_node.push_back(i_buff); } +} /************************************************************************** FEMLib-Method: @@ -708,15 +715,15 @@ void DOMCreate() Programing: 07/2004 OK Implementation **************************************************************************/ - long CPARDomain::GetDOMNode(long global_node) - { - long i; - long no_nodes = (long)nodes.size(); - for(i = 0; i < no_nodes; i++) - if(nodes[i] == global_node) - return i; - return -1; - } +long CPARDomain::GetDOMNode(long global_node) +{ + long i; + long no_nodes = (long)nodes.size(); + for (i = 0; i < no_nodes; i++) + if (nodes[i] == global_node) + return i; + return -1; +} #ifdef NEW_EQS /************************************************************************** @@ -725,40 +732,40 @@ void DOMCreate() Programing: 12/2007 WW Implementation **************************************************************************/ - void CPARDomain::CreateSparseTable() +void CPARDomain::CreateSparseTable() +{ + // Symmetry case is skipped. + // 1. Sparse_graph_H for high order interpolation. Up to now, deformation + if (nnodesHQ_dom != nnodes_dom) + sparse_graph_H = new SparseTable(*this, true); + // 2. M coupled with other processes with linear element + if (sparse_graph_H) { - // Symmetry case is skipped. - // 1. Sparse_graph_H for high order interpolation. Up to now, deformation - if(nnodesHQ_dom != nnodes_dom) - sparse_graph_H = new SparseTable(*this, true); - // 2. M coupled with other processes with linear element - if(sparse_graph_H) - { - if((int)pcs_vector.size() > 1) - sparse_graph = new SparseTable(*this, false); - } - // 3. For process with linear elements - else + if ((int)pcs_vector.size() > 1) sparse_graph = new SparseTable(*this, false); + } + // 3. For process with linear elements + else + sparse_graph = new SparseTable(*this, false); - //sparse_graph->Write(); - //sparse_graph_H->Write(); - // - //ofstream Dum("sparse.txt", ios::out); - //sparse_graph_H->Write(Dum);} + // sparse_graph->Write(); + // sparse_graph_H->Write(); + // + // ofstream Dum("sparse.txt", ios::out); + // sparse_graph_H->Write(Dum);} - /* + /* - //TEST - string test = "rank"; - char stro[1028]; - sprintf(stro, "%d",myrank); - string test1 = test+(string)stro+"sparse.txt"; - ofstream Dum(test1.c_str(), ios::out); // WW - sparse_graph->Write(Dum); Dum.close(); + //TEST + string test = "rank"; + char stro[1028]; + sprintf(stro, "%d",myrank); + string test1 = test+(string)stro+"sparse.txt"; + ofstream Dum(test1.c_str(), ios::out); // WW + sparse_graph->Write(Dum); Dum.close(); - */ - } + */ +} /************************************************************************** PARLib-Method: @@ -766,30 +773,30 @@ void DOMCreate() Programing: 12/2007 WW Implementation **************************************************************************/ - void CPARDomain::CreateEQS() - { - size_t dof_nonDM = 1, dof_DM = 1; +void CPARDomain::CreateEQS() +{ + size_t dof_nonDM = 1, dof_DM = 1; - const size_t pcs_vector_size (pcs_vector.size()); - for(size_t i = 0; i < pcs_vector_size; i++) - { - CRFProcess* pcs (pcs_vector[i]); - if(pcs->type == 22) // Monolithic TH2 - dof_nonDM = pcs->GetPrimaryVNumber(); - if(pcs->type == 4 || pcs->type == 41) // Deformation - dof_DM = pcs->GetPrimaryVNumber(); - else // Monolithic scheme for the process with linear elements - if(dof_nonDM < pcs->GetPrimaryVNumber()) - dof_nonDM = pcs->GetPrimaryVNumber(); - } + const size_t pcs_vector_size(pcs_vector.size()); + for (size_t i = 0; i < pcs_vector_size; i++) + { + CRFProcess* pcs(pcs_vector[i]); + if (pcs->type == 22) // Monolithic TH2 + dof_nonDM = pcs->GetPrimaryVNumber(); + if (pcs->type == 4 || pcs->type == 41) // Deformation + dof_DM = pcs->GetPrimaryVNumber(); + else // Monolithic scheme for the process with linear elements + if (dof_nonDM < pcs->GetPrimaryVNumber()) + dof_nonDM = pcs->GetPrimaryVNumber(); + } - CreateSparseTable(); + CreateSparseTable(); - if(sparse_graph) - eqs = new Linear_EQS(*sparse_graph, dof_nonDM); - if(sparse_graph_H) - eqsH = new Linear_EQS(*sparse_graph_H, dof_DM); - } + if (sparse_graph) + eqs = new Linear_EQS(*sparse_graph, dof_nonDM); + if (sparse_graph_H) + eqsH = new Linear_EQS(*sparse_graph_H, dof_DM); +} /************************************************************************** PARLib-Method: @@ -797,56 +804,52 @@ void DOMCreate() Programing: 12/2007 WW Implementation **************************************************************************/ - void CPARDomain::InitialEQS(CRFProcess* m_pcs) +void CPARDomain::InitialEQS(CRFProcess* m_pcs) +{ + long size = nnodes_dom; + Linear_EQS* this_eqs = NULL; + if (m_pcs->type == 4 || m_pcs->type == 41) { - long size = nnodes_dom; - Linear_EQS* this_eqs = NULL; - if(m_pcs->type == 4 || m_pcs->type == 41) - { - size = nnodesHQ_dom; - this_eqs = eqsH; - } - else - this_eqs = eqs; - for(size_t i = 0; i < m_pcs->GetPrimaryVNumber(); i++) - shift[i] = i * size; - // - this_eqs->Initialize(); + size = nnodesHQ_dom; + this_eqs = eqsH; } + else + this_eqs = eqs; + for (size_t i = 0; i < m_pcs->GetPrimaryVNumber(); i++) + shift[i] = i * size; + // + this_eqs->Initialize(); +} // #else // ifdef NEW_EQS -/************************************************************************** - PARLib-Method: - Task: - Programing: - 07/2004 OK Implementation - 05/2006 WW Fix bugs and add the case of DOF>1 -**************************************************************************/ - void CPARDomain::CreateEQS(CRFProcess* m_pcs) + /************************************************************************** + PARLib-Method: + Task: + Programing: + 07/2004 OK Implementation + 05/2006 WW Fix bugs and add the case of DOF>1 + **************************************************************************/ + void CPARDomain::CreateEQS(CRFProcess * m_pcs) { long no_nodes = (long)nodes.size(); int dof = m_pcs->GetPrimaryVNumber(); - if(m_pcs->type == 4 || m_pcs->type == 41) - for(size_t i = 0; i < m_pcs->GetPrimaryVNumber(); i++) + if (m_pcs->type == 4 || m_pcs->type == 41) + for (size_t i = 0; i < m_pcs->GetPrimaryVNumber(); i++) shift[i] = i * nnodesHQ_dom; - if(m_pcs->type == 4) - eqs = CreateLinearSolverDim(m_pcs->m_num->ls_storage_method, - dof, - dof * nnodesHQ_dom); + if (m_pcs->type == 4) + eqs = CreateLinearSolverDim(m_pcs->m_num->ls_storage_method, dof, dof * nnodesHQ_dom); // InitializeLinearSolver(eqs,m_num); - else if(m_pcs->type == 41) - eqs = CreateLinearSolverDim(m_pcs->m_num->ls_storage_method, - dof, - dof * nnodesHQ_dom + nnodes_dom); + else if (m_pcs->type == 41) + eqs = CreateLinearSolverDim(m_pcs->m_num->ls_storage_method, dof, dof * nnodesHQ_dom + nnodes_dom); else - //WW. + // WW. eqs = CreateLinearSolver(m_pcs->m_num->ls_storage_method, no_nodes); // eqs = CreateLinearSolver(0,no_nodes); - //InitializeLinearSolver(m_dom->eqs,NULL,NULL,NULL,m_dom->lsp_name); + // InitializeLinearSolver(m_dom->eqs,NULL,NULL,NULL,m_dom->lsp_name); InitLinearSolver(eqs); } #endif @@ -856,10 +859,10 @@ void DOMCreate() Programing: 07/2004 OK Implementation **************************************************************************/ - void CPARDomain::CalcElementMatrices(CRFProcess* m_pcs) - { - m_pcs = m_pcs; - } +void CPARDomain::CalcElementMatrices(CRFProcess* m_pcs) +{ + m_pcs = m_pcs; +} /************************************************************************** FEMLib-Method: @@ -890,15 +893,15 @@ void DOMCreate() Programing: 07/2004 OK Implementation **************************************************************************/ - bool NodeExists(long node,vectornode_vector) - { - long i; - long no_nodes = (long)node_vector.size(); - for(i = 0; i < no_nodes; i++) - if(node == node_vector[i]) - return true; - return false; - } +bool NodeExists(long node, vector node_vector) +{ + long i; + long no_nodes = (long)node_vector.size(); + for (i = 0; i < no_nodes; i++) + if (node == node_vector[i]) + return true; + return false; +} /************************************************************************** FEMLib-Method: @@ -907,66 +910,66 @@ void DOMCreate() 07/2006 WW Implementation last modification: **************************************************************************/ - void FindNodesOnInterface(CFEMesh* m_msh, bool quadr) - { - // int k; - long i, nnodes_gl, g_index, nnodes_l; - size_t j; - long l_buff = 0, l_buff1 = 0; +void FindNodesOnInterface(CFEMesh* m_msh, bool quadr) +{ + // int k; + long i, nnodes_gl, g_index, nnodes_l; + size_t j; + long l_buff = 0, l_buff1 = 0; - long* elem_nodes = NULL; - // - MeshLib::CElem* m_ele = NULL; - // - CPARDomain* m_dom = NULL; - vector boundary_nodes; - vector boundary_nodes_HQ; - vector inner_nodes_HQ; - vector inner_nodes; - vector long_buffer; - vector bc_buffer; - vector dom_bc_buffer; - vector dom_bc_bufferHQ; - // - nnodes_gl = m_msh->GetNodesNumber(true); - nnodes_l = m_msh->GetNodesNumber(false); - // - bc_buffer.resize(nnodes_gl); - // -#if defined(USE_MPI) //13.12.2007 - long overlapped_entry_size = 0; + long* elem_nodes = NULL; + // + MeshLib::CElem* m_ele = NULL; + // + CPARDomain* m_dom = NULL; + vector boundary_nodes; + vector boundary_nodes_HQ; + vector inner_nodes_HQ; + vector inner_nodes; + vector long_buffer; + vector bc_buffer; + vector dom_bc_buffer; + vector dom_bc_bufferHQ; + // + nnodes_gl = m_msh->GetNodesNumber(true); + nnodes_l = m_msh->GetNodesNumber(false); + // + bc_buffer.resize(nnodes_gl); +// +#if defined(USE_MPI) // 13.12.2007 + long overlapped_entry_size = 0; #endif - for(i = 0; i < nnodes_gl; i++) + for (i = 0; i < nnodes_gl; i++) + { + if (node_connected_doms[i] > 1.0) { - if(node_connected_doms[i] > 1.0) - { - // Mapp BC entry-->global node array - bc_buffer[i] = (long)long_buffer.size(); - long_buffer.push_back(m_msh->nod_vector[i]->GetIndex()); + // Mapp BC entry-->global node array + bc_buffer[i] = (long)long_buffer.size(); + long_buffer.push_back(m_msh->nod_vector[i]->GetIndex()); #ifdef USE_MPI - if(m_msh->nod_vector[i]->GetIndex() < m_msh->GetNodesNumber(false)) - overlapped_entry_size = (long)long_buffer.size(); + if (m_msh->nod_vector[i]->GetIndex() < m_msh->GetNodesNumber(false)) + overlapped_entry_size = (long)long_buffer.size(); #endif - } - else - bc_buffer[i] = -1; } - // -#if defined(USE_MPI) // 13.12.2007 - // Total border nodes - m_dom = dom_vector[myrank]; - m_dom->t_border_nodes_size = overlapped_entry_size; - m_dom->t_border_nodes_sizeH = (long)long_buffer.size(); - m_dom->t_border_nodes = new long[m_dom->t_border_nodes_sizeH]; - for(i = 0; i < m_dom->t_border_nodes_sizeH; i++) - m_dom->t_border_nodes [i] = long_buffer[i]; + else + bc_buffer[i] = -1; + } +// +#if defined(USE_MPI) // 13.12.2007 + // Total border nodes + m_dom = dom_vector[myrank]; + m_dom->t_border_nodes_size = overlapped_entry_size; + m_dom->t_border_nodes_sizeH = (long)long_buffer.size(); + m_dom->t_border_nodes = new long[m_dom->t_border_nodes_sizeH]; + for (i = 0; i < m_dom->t_border_nodes_sizeH; i++) + m_dom->t_border_nodes[i] = long_buffer[i]; #endif - // Sort +// Sort #ifndef USE_MPI - for(int k = 0; k < (int)dom_vector.size(); k++) - { - int myrank = k; + for (int k = 0; k < (int)dom_vector.size(); k++) + { + int myrank = k; #endif m_dom = dom_vector[myrank]; // @@ -979,17 +982,16 @@ void DOMCreate() dom_bc_buffer.clear(); dom_bc_bufferHQ.clear(); - for(i = 0; i < (long)m_dom->nodes.size(); i++) + for (i = 0; i < (long)m_dom->nodes.size(); i++) { g_index = m_dom->nodes[i]; - if(node_connected_doms[ g_index] > 1.0) + if (node_connected_doms[g_index] > 1.0) { - if(g_index >= nnodes_l) + if (g_index >= nnodes_l) { boundary_nodes_HQ.push_back(i); dom_bc_bufferHQ.push_back(bc_buffer[g_index]); - long_buffer[i] = -(long)boundary_nodes_HQ.size() - - nnodes_gl; + long_buffer[i] = -(long)boundary_nodes_HQ.size() - nnodes_gl; } else { @@ -1000,7 +1002,7 @@ void DOMCreate() } else { - if(g_index >= nnodes_l) + if (g_index >= nnodes_l) { long_buffer[i] = (long)inner_nodes_HQ.size() + nnodes_gl; inner_nodes_HQ.push_back(i); @@ -1021,59 +1023,58 @@ void DOMCreate() m_dom->nodes_inner.clear(); m_dom->nodes_halo.clear(); - for(i = 0; i < m_dom->num_inner_nodes; i++) + for (i = 0; i < m_dom->num_inner_nodes; i++) m_dom->nodes_inner.push_back(m_dom->nodes[inner_nodes[i]]); - for(i = 0; i < (long)inner_nodes_HQ.size(); i++) + for (i = 0; i < (long)inner_nodes_HQ.size(); i++) m_dom->nodes_inner.push_back(m_dom->nodes[inner_nodes_HQ[i]]); // - for(i = 0; i < m_dom->num_boundary_nodes; i++) + for (i = 0; i < m_dom->num_boundary_nodes; i++) m_dom->nodes_halo.push_back(m_dom->nodes[boundary_nodes[i]]); - for(i = 0; i < (long)boundary_nodes_HQ.size(); i++) + for (i = 0; i < (long)boundary_nodes_HQ.size(); i++) m_dom->nodes_halo.push_back(m_dom->nodes[boundary_nodes_HQ[i]]); // m_dom->nodes.clear(); m_dom->nodes.resize(m_dom->nnodesHQ_dom); // First interior nodes, then interface nodes j = 0; - for(i = 0; i < m_dom->num_inner_nodes; i++) + for (i = 0; i < m_dom->num_inner_nodes; i++) m_dom->nodes[i] = m_dom->nodes_inner[i]; // m_dom->nodes_inner[i] = i; j += m_dom->num_inner_nodes; - for(i = 0; i < m_dom->num_boundary_nodes; i++) + for (i = 0; i < m_dom->num_boundary_nodes; i++) m_dom->nodes[i + j] = m_dom->nodes_halo[i]; // m_dom->nodes_halo[i] = i+j; j += m_dom->num_boundary_nodes; - for(i = 0; i < (long)inner_nodes_HQ.size(); i++) + for (i = 0; i < (long)inner_nodes_HQ.size(); i++) m_dom->nodes[i + j] = m_dom->nodes_inner[i + m_dom->num_inner_nodes]; // m_dom->nodes_inner[i+m_dom->num_inner_nodes] = i+j; j += (long)inner_nodes_HQ.size(); - for(i = 0; i < (long)boundary_nodes_HQ.size(); i++) + for (i = 0; i < (long)boundary_nodes_HQ.size(); i++) m_dom->nodes[i + j] = m_dom->nodes_halo[i + m_dom->num_boundary_nodes]; // m_dom->nodes_halo[i+m_dom->num_boundary_nodes] = i+j; - for(i = 0; i < (long)m_dom->nodes.size(); i++) + for (i = 0; i < (long)m_dom->nodes.size(); i++) { l_buff = long_buffer[i]; - if(l_buff < 0) //interface nodes + if (l_buff < 0) // interface nodes { - if(-l_buff - nnodes_gl > 0) //HQ nodes - l_buff1 = m_dom->nnodes_dom + (long)inner_nodes_HQ.size() - - l_buff - nnodes_gl - 1; + if (-l_buff - nnodes_gl > 0) // HQ nodes + l_buff1 = m_dom->nnodes_dom + (long)inner_nodes_HQ.size() - l_buff - nnodes_gl - 1; else l_buff1 = (long)inner_nodes.size() - l_buff - 1; // l_buff1 = m_dom->num_inner_nodesHQ-l_buff-1; } else { - if(l_buff - nnodes_gl >= 0) //HQ nodes + if (l_buff - nnodes_gl >= 0) // HQ nodes l_buff1 = m_dom->nnodes_dom + l_buff - nnodes_gl; else l_buff1 = l_buff; } long_buffer[i] = l_buff1; } - // -#ifdef USE_MPI //WW +// +#ifdef USE_MPI // WW m_dom->FillBorderNodeConnectDom(node_connected_doms); #endif // @@ -1081,16 +1082,16 @@ void DOMCreate() m_dom->nodes_halo.clear(); // Mapping the local index to global BC array, overlapped_entry. // - for(i = 0; i < m_dom->num_boundary_nodes; i++) + for (i = 0; i < m_dom->num_boundary_nodes; i++) m_dom->nodes_halo.push_back(dom_bc_buffer[i]); - for(i = 0; i < (long)boundary_nodes_HQ.size(); i++) + for (i = 0; i < (long)boundary_nodes_HQ.size(); i++) m_dom->nodes_halo.push_back(dom_bc_bufferHQ[i]); //---------------------------------------------------------------------- - for(i = 0; i < (long)m_dom->elements.size(); i++) + for (i = 0; i < (long)m_dom->elements.size(); i++) { m_ele = m_msh->ele_vector[m_dom->elements[i]]; elem_nodes = m_dom->element_nodes_dom[i]; - for(j = 0; j < m_ele->GetNodesNumber(quadr); j++) + for (j = 0; j < m_ele->GetNodesNumber(quadr); j++) { l_buff = elem_nodes[j]; elem_nodes[j] = long_buffer[l_buff]; @@ -1102,7 +1103,7 @@ void DOMCreate() #endif } -#if defined(USE_MPI) //WW +#if defined(USE_MPI) // WW //------------------------For parallel solvers------------------------------ /************************************************************************* GeoSys-Function: @@ -1110,46 +1111,46 @@ void DOMCreate() Programming: 02/2008 WW Implementation **************************************************************************/ - void CPARDomain::FillBorderNodeConnectDom(vector allnodes_doms) +void CPARDomain::FillBorderNodeConnectDom(vector allnodes_doms) +{ + long i, ig; + int k; + b_start[0] = num_inner_nodes; + b_end[0] = num_inner_nodes + num_boundary_nodes; + nq = 1; + // + if (nnodesHQ_dom > nnodes_dom) { - long i, ig; - int k; - b_start[0] = num_inner_nodes; - b_end[0] = num_inner_nodes + num_boundary_nodes; - nq = 1; // - if(nnodesHQ_dom > nnodes_dom) + nq = 2; + b_start[1] = b_end[0] + num_inner_nodesHQ; + b_end[1] = nnodesHQ_dom; + } + // + // + for (k = 0; k < nq; k++) + for (i = b_start[k]; i < b_end[k]; i++) { - // - nq = 2; - b_start[1] = b_end[0] + num_inner_nodesHQ; - b_end[1] = nnodesHQ_dom; + ig = nodes[i]; + bnode_connected_dom.push_back(allnodes_doms[ig]); } - // - // - for(k = 0; k < nq; k++) - for(i = b_start[k]; i < b_end[k]; i++) - { - ig = nodes[i]; - bnode_connected_dom.push_back(allnodes_doms[ig]); - } - /* - string test = "rank"; - static char stro[102]; - - sprintf(stro, "%d",myrank); - string test1 = test+(string)stro+"dom.txt"; - ofstream Dum(test1.c_str(), ios::out); // WW - Dum<DOF(); - eqsH->SetDomain(this); - eqsH->ConfigNumerics(m_num, n); - inner_size += num_inner_nodesHQ; - border_size += num_boundary_nodesHQ; - } - else - { - n_loc = nnodes_dom; - nq = 1; - n_bc = t_border_nodes_size; - dof = eqs->DOF(); - eqs->SetDomain(this); - eqs->ConfigNumerics(m_num, n); - } - // Concatenate index - inner_size *= dof; - border_size *= dof; - for(int i = 0; i < mysize; i++) - { - receive_cnt[i] = 1; - receive_disp[i] = i; - } - // - // receive_cnt_i[]: number of subdomain inner nodes in the concatenated array - MPI_Allgatherv ( &inner_size, 1, MPI_INT, receive_cnt_i, receive_cnt, receive_disp, - MPI_INT, comm_DDC ); - inner_size = 0; - for(int i = 0; i < mysize; i++) - { - receive_disp_i[i] = inner_size; - inner_size += receive_cnt_i[i]; - } -#if defined(NEW_BREDUCE) - // receive_cnt_b[]: number of subdomain border nodes in the concatenated array - MPI_Allgatherv ( &border_size, 1, MPI_INT, receive_cnt_b, receive_cnt, receive_disp, - MPI_INT, comm_DDC ); - border_size = 0; - for(i = 0; i < mysize; i++) - { - receive_disp_b[i] = border_size; - border_size += receive_cnt_b[i]; - } + if (quadratic) + { + n_loc = nnodesHQ_dom; + nq = 2; + n_bc = t_border_nodes_sizeH; + i_start[1] = i_end[0] + num_boundary_nodes; + i_end[1] = i_start[1] + num_inner_nodesHQ; // Number of interior nodes // - cpu_time_local += MPI_Wtime(); - if(quadratic) - { - eqsH->f_buffer[(int)eqsH->f_buffer.size() - 3] = new double[border_size]; - eqsH->cpu_time += cpu_time_local; - } - else - { - eqs->f_buffer[(int)eqs->f_buffer.size() - 3] = new double[border_size]; - eqs->cpu_time += cpu_time_local; - } -#endif + b_start[1] = b_end[0]; + b_end[1] = b_start[1] + num_boundary_nodesHQ; + n_shift[1] = n_shift[0] + num_inner_nodesHQ; // - // long dim = n_loc*dof; - // MPI_Allreduce(&dim, &max_dimen, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD); + dof = eqsH->DOF(); + eqsH->SetDomain(this); + eqsH->ConfigNumerics(m_num, n); + inner_size += num_inner_nodesHQ; + border_size += num_boundary_nodesHQ; } + else + { + n_loc = nnodes_dom; + nq = 1; + n_bc = t_border_nodes_size; + dof = eqs->DOF(); + eqs->SetDomain(this); + eqs->ConfigNumerics(m_num, n); + } + // Concatenate index + inner_size *= dof; + border_size *= dof; + for (int i = 0; i < mysize; i++) + { + receive_cnt[i] = 1; + receive_disp[i] = i; + } + // + // receive_cnt_i[]: number of subdomain inner nodes in the concatenated array + MPI_Allgatherv(&inner_size, 1, MPI_INT, receive_cnt_i, receive_cnt, receive_disp, MPI_INT, comm_DDC); + inner_size = 0; + for (int i = 0; i < mysize; i++) + { + receive_disp_i[i] = inner_size; + inner_size += receive_cnt_i[i]; + } +#if defined(NEW_BREDUCE) + // receive_cnt_b[]: number of subdomain border nodes in the concatenated array + MPI_Allgatherv(&border_size, 1, MPI_INT, receive_cnt_b, receive_cnt, receive_disp, MPI_INT, comm_DDC); + border_size = 0; + for (i = 0; i < mysize; i++) + { + receive_disp_b[i] = border_size; + border_size += receive_cnt_b[i]; + } + // + cpu_time_local += MPI_Wtime(); + if (quadratic) + { + eqsH->f_buffer[(int)eqsH->f_buffer.size() - 3] = new double[border_size]; + eqsH->cpu_time += cpu_time_local; + } + else + { + eqs->f_buffer[(int)eqs->f_buffer.size() - 3] = new double[border_size]; + eqs->cpu_time += cpu_time_local; + } +#endif + // + // long dim = n_loc*dof; + // MPI_Allreduce(&dim, &max_dimen, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD); +} /************************************************************************* GeoSys-Function: @@ -1268,22 +1267,22 @@ void DOMCreate() Programming: 02/2008 WW Implementation **************************************************************************/ - double CPARDomain::Dot_Border_Vec(const double* vec_x, const double* vec_y) - { - // - double val = 0.; - for(int k = 0; k < nq; k++) - for(long i = b_start[k]; i < b_end[k]; i++) +double CPARDomain::Dot_Border_Vec(const double* vec_x, const double* vec_y) +{ + // + double val = 0.; + for (int k = 0; k < nq; k++) + for (long i = b_start[k]; i < b_end[k]; i++) + { + const double fac = 1.0 / (double)bnode_connected_dom[i]; + for (int ii = 0; ii < dof; ii++) { - const double fac = 1.0 / (double)bnode_connected_dom[i]; - for(int ii = 0; ii < dof; ii++) - { - const long l_buff = i + n_loc * ii + n_shift[k]; - val += fac * vec_x[l_buff] * vec_y[l_buff]; - } + const long l_buff = i + n_loc * ii + n_shift[k]; + val += fac * vec_x[l_buff] * vec_y[l_buff]; } - return val; - } + } + return val; +} /************************************************************************* GeoSys-Function: @@ -1294,78 +1293,74 @@ void DOMCreate() 07/2006 WW Implementation 12/2007 WW Revise **************************************************************************/ - double CPARDomain::Dot_Interior(const double* localr0, const double* localr1) - { - long i; - int ii, k; - double val; - // +double CPARDomain::Dot_Interior(const double* localr0, const double* localr1) +{ + long i; + int ii, k; + double val; + // + + /* + if(dof>1) + { + //TEST - /* - if(dof>1) - { - //TEST + string test = "rank"; + char stro[64]; + sprintf(stro, "%d",myrank); + string test1 = test+(string)stro+"dom.txt"; - string test = "rank"; - char stro[64]; - sprintf(stro, "%d",myrank); - string test1 = test+(string)stro+"dom.txt"; + ofstream Dum(test1.c_str(), ios::out); + Dum<<" nnodesHQ_dom "<< nnodesHQ_dom<<"\n"; - ofstream Dum(test1.c_str(), ios::out); - Dum<<" nnodesHQ_dom "<< nnodesHQ_dom<<"\n"; + Dum<<" nq "<1) + exit(1); + */ - else - for(k = 0; k < nq; k++) - for(i = i_start[k]; i < i_end[k]; i++) - for(ii = 0; ii < dof; ii++) - val += - localr0[i + n_loc * - ii] * localr1[i + n_loc * ii]; - - /* - //TEST - Dum.close(); - if(nq>1) - exit(1); - */ - - return val; - } + return val; +} /************************************************************************* GeoSys-Function: @@ -1376,22 +1371,22 @@ void DOMCreate() 06/2006 WW Implementation 12/2007 WW Revise **************************************************************************/ - void CPARDomain::Global2Local(const double* global_x, double* local_x, const long n ) +void CPARDomain::Global2Local(const double* global_x, double* local_x, const long n) +{ + long i, ig; + int ii; + // + // + long n_global = (long)n / dof; + for (i = 0; i < n_loc * dof; i++) + local_x[i] = 0.; + for (i = 0; i < n_loc; i++) { - long i, ig; - int ii; - // - // - long n_global = (long)n / dof; - for(i = 0; i < n_loc * dof; i++) - local_x[i] = 0.; - for(i = 0; i < n_loc; i++) - { - ig = nodes[i]; - for(ii = 0; ii < dof; ii++) - local_x[i + n_loc * ii] = global_x[ig + n_global * ii]; - } + ig = nodes[i]; + for (ii = 0; ii < dof; ii++) + local_x[i + n_loc * ii] = global_x[ig + n_global * ii]; } +} /************************************************************************* GeoSys-Function: @@ -1403,39 +1398,38 @@ void DOMCreate() 12/2007 WW Revise 02/2008 WW Revise **************************************************************************/ - void CPARDomain:: Local2Global(const double* local_x, double* global_x, const long n ) - { - long i, ig, b_index; - int ii, k; - double fac = 0.; - // - // - long n_global = (long)n / dof; - // - for(i = 0; i < n; i++) - global_x[i] = 0.; - // - for(k = 0; k < nq; k++) - for(i = i_start[k]; i < i_end[k]; i++) - { - ig = nodes[i]; - for(ii = 0; ii < dof; ii++) - global_x[ig + n_global * ii] = local_x[i + n_loc * ii]; - } - // - for(k = 0; k < nq; k++) - for(i = b_start[k]; i < b_end[k]; i++) - { - b_index = i + n_shift[k]; - fac = 1.0 / (double)bnode_connected_dom[i]; - // - ig = nodes[b_index]; - for(ii = 0; ii < dof; ii++) - global_x[ig + n_global * - ii] += fac * local_x[b_index + n_loc * ii]; - } - // - } +void CPARDomain::Local2Global(const double* local_x, double* global_x, const long n) +{ + long i, ig, b_index; + int ii, k; + double fac = 0.; + // + // + long n_global = (long)n / dof; + // + for (i = 0; i < n; i++) + global_x[i] = 0.; + // + for (k = 0; k < nq; k++) + for (i = i_start[k]; i < i_end[k]; i++) + { + ig = nodes[i]; + for (ii = 0; ii < dof; ii++) + global_x[ig + n_global * ii] = local_x[i + n_loc * ii]; + } + // + for (k = 0; k < nq; k++) + for (i = b_start[k]; i < b_end[k]; i++) + { + b_index = i + n_shift[k]; + fac = 1.0 / (double)bnode_connected_dom[i]; + // + ig = nodes[b_index]; + for (ii = 0; ii < dof; ii++) + global_x[ig + n_global * ii] += fac * local_x[b_index + n_loc * ii]; + } + // +} /************************************************************************* GeoSys-Function: @@ -1445,21 +1439,21 @@ void DOMCreate() Programming: 12/2007 WW **************************************************************************/ - void CPARDomain::Global2Border(const double* x, double* local_x, const long n ) +void CPARDomain::Global2Border(const double* x, double* local_x, const long n) +{ + // + long nnodes_g = (long)n / dof; + // BC + for (long i = 0; i < dof * n_bc; i++) + local_x[i] = 0.0; + // + for (long i = 0; i < n_bc; i++) { - // - long nnodes_g = (long)n / dof; - // BC - for(long i = 0; i < dof * n_bc; i++) - local_x[i] = 0.0; - // - for(long i = 0; i < n_bc; i++) - { - int k = t_border_nodes[i]; - for(int ii = 0; ii < dof; ii++) - local_x[i + n_bc * ii] = x[k + nnodes_g * ii]; - } + int k = t_border_nodes[i]; + for (int ii = 0; ii < dof; ii++) + local_x[i + n_bc * ii] = x[k + nnodes_g * ii]; } +} /************************************************************************* GeoSys-Function: @@ -1469,18 +1463,18 @@ void DOMCreate() Programming: 12/2007 WW **************************************************************************/ - void CPARDomain::Border2Global(const double* local_x, double* x, const long n) +void CPARDomain::Border2Global(const double* local_x, double* x, const long n) +{ + // + long nnodes_g = (long)n / dof; + // + for (long i = 0; i < n_bc; i++) { - // - long nnodes_g = (long)n / dof; - // - for(long i = 0; i < n_bc; i++) - { - const int k = t_border_nodes[i]; - for(int ii = 0; ii < dof; ii++) - x[k + nnodes_g * ii] = local_x[i + n_bc * ii]; - } + const int k = t_border_nodes[i]; + for (int ii = 0; ii < dof; ii++) + x[k + nnodes_g * ii] = local_x[i + n_bc * ii]; } +} /************************************************************************* GeoSys-Function: @@ -1491,24 +1485,23 @@ void DOMCreate() 07/2006 WW Implementation 12/2007 WW Revise **************************************************************************/ - void CPARDomain::Local2Border(const double* local_x, double* border_x) - { - long i, ig; - int ii, k; - // - // BC - for(i = 0; i < dof * n_bc; i++) - border_x[i] = 0.0; - // - for(k = 0; k < nq; k++) - for(i = b_start[k]; i < b_end[k]; i++) - { - ig = nodes_halo[i]; - for(ii = 0; ii < dof; ii++) - border_x[ig + n_bc * - ii] = local_x[i + n_shift[k] + n_loc * ii]; - } - } +void CPARDomain::Local2Border(const double* local_x, double* border_x) +{ + long i, ig; + int ii, k; + // + // BC + for (i = 0; i < dof * n_bc; i++) + border_x[i] = 0.0; + // + for (k = 0; k < nq; k++) + for (i = b_start[k]; i < b_end[k]; i++) + { + ig = nodes_halo[i]; + for (ii = 0; ii < dof; ii++) + border_x[ig + n_bc * ii] = local_x[i + n_shift[k] + n_loc * ii]; + } +} /************************************************************************* GeoSys-Function: @@ -1519,21 +1512,20 @@ void DOMCreate() 07/2006 WW Implementation 12/2007 WW Revise **************************************************************************/ - void CPARDomain::Border2Local(const double* border_x, double* local_x) - { - long i, ig; - int ii, k; - // - // - for(k = 0; k < nq; k++) - for(i = b_start[k]; i < b_end[k]; i++) - { - ig = nodes_halo[i]; - for(ii = 0; ii < dof; ii++) - local_x[i + n_shift[k] + n_loc * - ii] = border_x[ig + n_bc * ii]; - } - } +void CPARDomain::Border2Local(const double* border_x, double* local_x) +{ + long i, ig; + int ii, k; + // + // + for (k = 0; k < nq; k++) + for (i = b_start[k]; i < b_end[k]; i++) + { + ig = nodes_halo[i]; + for (ii = 0; ii < dof; ii++) + local_x[i + n_shift[k] + n_loc * ii] = border_x[ig + n_bc * ii]; + } +} /*\! ******************************************************************** @@ -1542,78 +1534,77 @@ void DOMCreate() 12/2007 WW ********************************************************************/ //#define NEW_BREDUCE2 - void CPARDomain::CatInnerX(double* global_x, const double* local_x, const long n) +void CPARDomain::CatInnerX(double* global_x, const double* local_x, const long n) +{ + Linear_EQS* eq = NULL; + if (quadratic) + eq = eqsH; + else + eq = eqs; + // + double* x_g = eq->f_buffer[(long)eq->f_buffer.size() - 1]; +// +// +#if defined(NEW_BREDUCE2) + // Not finished + // Due to the parallel computing of dom topology, not all num_inner_node of + // dom_vector[j] is caculated. + // for(i=0; iA->Dim();i++) + // x_i[i] = 0.; + // + double* x_i = eq->f_buffer[0]; + const long n_global = (long)n / dof; + long counter = 0; + for (int k = 0; k < nq; k++) { - Linear_EQS* eq = NULL; - if(quadratic) - eq = eqsH; + for (long i = i_start[k]; i < i_end[k]; i++) + for (int ii = 0; ii < dof; ii++) + { + x_i[counter] = local_x[i + n_loc * ii]; + counter++; // + } + } + // Concatentate + MPI_Allgatherv(x_i, counter, MPI_DOUBLE, x_g, receive_cnt_i, receive_disp_i, MPI_DOUBLE, comm_DDC); + // + // Mapping to the golbal x + CPARDomain* a_dom; + for (long j = 0; j < mysize; j++) + { + counter = receive_disp_i[j]; + // Problem from here + if (j == myrank) + a_dom = this; else - eq = eqs; - // - double* x_g = eq->f_buffer[(long)eq->f_buffer.size() - 1]; - // - // -#if defined(NEW_BREDUCE2) - // Not finished - // Due to the parallel computing of dom topology, not all num_inner_node of - // dom_vector[j] is caculated. - // for(i=0; iA->Dim();i++) - // x_i[i] = 0.; - // - double* x_i = eq->f_buffer[0]; - const long n_global = (long)n / dof; - long counter = 0; - for(int k = 0; k < nq; k++) + a_dom = dom_vector[j]; + a_dom->nq = 1; + a_dom->i_start[0] = 0; + a_dom->i_end[0] = a_dom->num_inner_nodes; // Number of interior nodes + if (quadratic) { - for(long i = i_start[k]; i < i_end[k]; i++) - for(int ii = 0; ii < dof; ii++) - { - x_i[counter] = local_x[i + n_loc * ii]; - counter++; // - } + a_dom->nq = 2; + a_dom->i_start[1] = a_dom->i_end[0] + a_dom->num_boundary_nodes; + a_dom->i_end[1] = a_dom->i_start[1] + a_dom->num_inner_nodesHQ; } - // Concatentate - MPI_Allgatherv (x_i, counter, MPI_DOUBLE, x_g, receive_cnt_i, receive_disp_i, - MPI_DOUBLE, comm_DDC ); - // - // Mapping to the golbal x - CPARDomain* a_dom; - for(long j = 0; j < mysize; j++) - { - counter = receive_disp_i[j]; - // Problem from here - if(j == myrank) - a_dom = this; - else - a_dom = dom_vector[j]; - a_dom->nq = 1; - a_dom->i_start[0] = 0; - a_dom->i_end[0] = a_dom->num_inner_nodes; //Number of interior nodes - if(quadratic) - { - a_dom->nq = 2; - a_dom->i_start[1] = a_dom->i_end[0] + a_dom->num_boundary_nodes; - a_dom->i_end[1] = a_dom->i_start[1] + a_dom->num_inner_nodesHQ; - } - for(int k = 0; k < a_dom->nq; k++) // This should come from different processors + for (int k = 0; k < a_dom->nq; k++) // This should come from different processors - for(long i = a_dom->i_start[k]; i < a_dom->i_end[k]; i++) + for (long i = a_dom->i_start[k]; i < a_dom->i_end[k]; i++) + { + const long ig = a_dom->nodes[i]; + for (int ii = 0; ii < dof; ii++) { - const long ig = a_dom->nodes[i]; - for(int ii = 0; ii < dof; ii++) - { - global_x[ig + n_global * ii] = x_g[counter]; - counter++; - } + global_x[ig + n_global * ii] = x_g[counter]; + counter++; } - } + } + } #else // if defined(NEW_BREDUCE2) - Local2Global(local_x, x_g, n); - MPI_Allreduce( x_g, global_x, n, MPI_DOUBLE,MPI_SUM,comm_DDC); + Local2Global(local_x, x_g, n); + MPI_Allreduce(x_g, global_x, n, MPI_DOUBLE, MPI_SUM, comm_DDC); #endif - } +} #if defined(NEW_BREDUCE) /*\! @@ -1622,68 +1613,65 @@ void DOMCreate() Programm: 12/2007 WW ********************************************************************/ - void CPARDomain::ReduceBorderV(double* local_x) +void CPARDomain::ReduceBorderV(double* local_x) +{ + long i, j, ig; + int ii, k; + long counter = 0; + double *x_b, *x_cat, *x_g; + Linear_EQS* eq = NULL; + if (quadratic) + eq = eqsH; + else + eq = eqs; + // + x_g = eq->f_buffer[(long)eq->f_buffer.size() - 1]; + x_cat = eq->f_buffer[(int)eq->f_buffer.size() - 2]; + x_b = &local_x[eq->Dim()]; + // + for (k = 0; k < nq; k++) { - long i, j, ig; - int ii, k; - long counter = 0; - double* x_b, * x_cat, * x_g; - Linear_EQS* eq = NULL; - if(quadratic) - eq = eqsH; - else - eq = eqs; - // - x_g = eq->f_buffer[(long)eq->f_buffer.size() - 1]; - x_cat = eq->f_buffer[(int)eq->f_buffer.size() - 2]; - x_b = &local_x[eq->Dim()]; - // - for(k = 0; k < nq; k++) - { - for(i = b_start[k]; i < b_end[k]; i++) - for(ii = 0; ii < dof; ii++) + for (i = b_start[k]; i < b_end[k]; i++) + for (ii = 0; ii < dof; ii++) + { + //; + x_g[counter] = local_x[i + n_shift[k] + n_loc * ii]; + counter++; + } + } + // Concatentate + MPI_Allgatherv(x_g, counter, MPI_DOUBLE, x_cat, receive_cnt_b, receive_disp_b, MPI_DOUBLE, comm_DDC); + for (i = 0; i < dof * n_bc; i++) + x_b[i] = 0.0; + // + CPARDomain* a_dom; + for (j = 0; j < mysize; j++) + { + a_dom = dom_vector[j]; + counter = receive_disp_b[j]; + for (k = 0; k < a_dom->nq; k++) + for (i = a_dom->b_start[k]; i < a_dom->b_end[k]; i++) + { + ig = a_dom->nodes_halo[i]; + for (ii = 0; ii < dof; ii++) { - //; - x_g[counter] = local_x[i + n_shift[k] + n_loc * ii]; + x_b[ig + n_bc * ii] += x_cat[counter]; counter++; } - } - // Concatentate - MPI_Allgatherv (x_g, counter, MPI_DOUBLE, x_cat, receive_cnt_b, receive_disp_b, - MPI_DOUBLE, comm_DDC ); - for(i = 0; i < dof * n_bc; i++) - x_b[i] = 0.0; - // - CPARDomain* a_dom; - for(j = 0; j < mysize; j++) - { - a_dom = dom_vector[j]; - counter = receive_disp_b[j]; - for(k = 0; k < a_dom->nq; k++) - for(i = a_dom->b_start[k]; i < a_dom->b_end[k]; i++) - { - ig = a_dom->nodes_halo[i]; - for(ii = 0; ii < dof; ii++) - { - x_b[ig + n_bc * ii] += x_cat[counter]; - counter++; - } - } - } + } } -#endif //if defined(NEW_BREDUCE) +} +#endif // if defined(NEW_BREDUCE) /******************************************************************** As the title Programm: 12/2007 WW ********************************************************************/ - void CPARDomain::PrintEQS_CPUtime(ostream &os) - { - if(eqs) - os << "CPU time elapsed in linear solver for linear elements: " - << eqs->GetCPUtime() << "\n"; - if(eqsH) - os << "CPU time elapsed in linear solver for quadratic elements: " - << eqsH->GetCPUtime() << "\n"; - } -#endif //// if defined(USE_MPI) +void CPARDomain::PrintEQS_CPUtime(ostream& os) +{ + if (eqs) + os << "CPU time elapsed in linear solver for linear elements: " << eqs->GetCPUtime() << "\n"; + if (eqsH) + os << "CPU time elapsed in linear solver for quadratic elements: " << eqsH->GetCPUtime() << "\n"; +} +#endif //// if defined(USE_MPI) diff --git a/FEM/par_ddc.h b/FEM/par_ddc.h index 5ec0aaac2..eebda21cb 100644 --- a/FEM/par_ddc.h +++ b/FEM/par_ddc.h @@ -28,15 +28,18 @@ //--------- Declaration ---------------------WW namespace FiniteElement -{ class CFiniteElementStd; - class CFiniteElementVec; +{ +class CFiniteElementStd; +class CFiniteElementVec; } namespace process -{ class CRFProcessDeformation; +{ +class CRFProcessDeformation; } namespace Math_Group -{class SparseTable; - class Linear_EQS; +{ +class SparseTable; +class Linear_EQS; } using process::CRFProcessDeformation; using FiniteElement::CFiniteElementVec; @@ -45,13 +48,14 @@ using Math_Group::SparseTable; //--------- Declaration ---------------------WW #if defined(USE_MPI) -//WW +// WW namespace MeshLib -{class CFEMesh; +{ +class CFEMesh; } -using MeshLib::CFEMesh; +using MeshLib::CFEMesh; #endif -void FindNodesOnInterface( CFEMesh* m_msh, bool quadr); +void FindNodesOnInterface(CFEMesh* m_msh, bool quadr); //----------------------------------------------- class CPARDomain @@ -66,8 +70,8 @@ class CPARDomain long num_boundary_nodes; long num_boundary_nodesHQ; friend void FindNodesOnInterface(CFEMesh* m_msh, bool quadr); - //#endif -#if defined(USE_MPI) // 13.12.2007 WW +//#endif +#if defined(USE_MPI) // 13.12.2007 WW // Store global indices of all border nodes to border_nodes of the whole mesh // 0-->border_nodes_size, nodes for linear interpolation // border_nodes_size-->border_nodes_sizeH, nodes for quadratic interpolation @@ -78,7 +82,7 @@ class CPARDomain // For local EQS // For index mapping from local to global int dof, nq; - long n_loc, n_bc; //, max_dimen; + long n_loc, n_bc; //, max_dimen; long i_start[2], i_end[2]; long b_start[2], b_end[2], n_shift[2]; // Data for concatenate internal entries of domain vectors @@ -92,32 +96,32 @@ class CPARDomain // int* receive_cnt; int* receive_disp; - //friend class Math_Group::Linear_EQS; - // +// friend class Math_Group::Linear_EQS; +// #endif // - long shift[5]; //WW - // Equation -#ifdef NEW_EQS //WW + long shift[5]; // WW +// Equation +#ifdef NEW_EQS // WW SparseTable* sparse_graph; SparseTable* sparse_graph_H; - Linear_EQS* eqs; //WW - Linear_EQS* eqsH; //WW + Linear_EQS* eqs; // WW + Linear_EQS* eqsH; // WW #endif - friend class CRFProcess; //WW - //WW //:: for SXC compiler + friend class CRFProcess; // WW + // WW //:: for SXC compiler friend class FiniteElement::CFiniteElementStd; - //WW //:: for SXC compiler + // WW //:: for SXC compiler friend class FiniteElement::CFiniteElementVec; - friend class process::CRFProcessDeformation; //WW //:: for SXC compiler + friend class process::CRFProcessDeformation; // WW //:: for SXC compiler public: int ID; std::vector elements; std::vector nodes_inner; std::vector nodes_halo; std::vector nodes; - //?vectormatrix; - // EQS +//?vectormatrix; +// EQS #ifndef NEW_EQS LINEAR_SOLVER* eqs; LINEAR_SOLVER_PROPERTIES* lsp; @@ -132,92 +136,96 @@ class CPARDomain void CreateNodes(); // const long *longbuff, const bool quadr. WW void CreateElements(const bool quadr); - void NodeConnectedNodes(); //WW - // -#ifdef NEW_EQS //WW - void CreateSparseTable(); //WW - void CreateEQS(); //WW - void InitialEQS(CRFProcess* m_pcs); //WW + void NodeConnectedNodes(); // WW +// +#ifdef NEW_EQS // WW + void CreateSparseTable(); // WW + void CreateEQS(); // WW + void InitialEQS(CRFProcess* m_pcs); // WW #else void CreateEQS(CRFProcess* m_pcs); #endif void CalcElementMatrices(CRFProcess*); - //WW void AssembleMatrix(CRFProcess*); + // WW void AssembleMatrix(CRFProcess*); long GetDOMNode(long); - int m_color[3]; //OK - void WriteTecplot(std::string); //OK + int m_color[3]; // OK + void WriteTecplot(std::string); // OK - bool selected; //OK - bool quadratic; //WW - std::vector node_conneted_nodes; //WW - std::vector num_nodes2_node; //WW + bool selected; // OK + bool quadratic; // WW + std::vector node_conneted_nodes; // WW + std::vector num_nodes2_node; // WW // - long GetDomainNodes() const //WW + long GetDomainNodes() const // WW { - if(quadratic) return nnodesHQ_dom; - else return nnodes_dom; + if (quadratic) + return nnodesHQ_dom; + else + return nnodes_dom; } - long GetDomainNodes(bool quad) const //WW + long GetDomainNodes(bool quad) const // WW { - if(quad) return nnodesHQ_dom; - else return nnodes_dom; + if (quad) + return nnodesHQ_dom; + else + return nnodes_dom; } -#if defined(USE_MPI) //WW +#if defined(USE_MPI) // WW // long MaxDim() const {return max_dimen;} //WW void ReleaseMemory(); - //WW + // WW void FillBorderNodeConnectDom(std::vector allnodes_doms); - long BSize() const //WW + long BSize() const // WW { return n_bc; } - //WW + // WW void ConfigEQS(CNumerics* m_num, const long n, bool quad = false); - //WW - double Dot_Interior(const double* localr0, const double* localr1 = NULL); - //WW - void Global2Local(const double* global_x, double* local_x, const long n ); - //WW - void Local2Global(const double* local_x, double* global_x, const long n ); - //WW + // WW + double Dot_Interior(const double* localr0, const double* localr1 = NULL); + // WW + void Global2Local(const double* global_x, double* local_x, const long n); + // WW + void Local2Global(const double* local_x, double* global_x, const long n); + // WW void Global2Border(const double* x, double* local_x, const long n); - //WW + // WW void Border2Global(const double* local_x, double* x, const long n); - //WW + // WW void Local2Border(const double* local_x, double* border_x); - //WW + // WW void Border2Local(const double* border_x, double* local_x); // double Dot_Border_Vec(const double* vec_x, const double* vec_y); // - //WW + // WW void CatInnerX(double* global_x, const double* local_x, const long n); - //WW - void PrintEQS_CPUtime(std::ostream &os = std::cout); + // WW + void PrintEQS_CPUtime(std::ostream& os = std::cout); #if defined(NEW_BREDUCE) void ReduceBorderV(double* local_x); #endif - // - // +// +// #endif }; extern std::vector dom_vector; -extern std::vector node_connected_doms; // WW -extern void CountDoms2Nodes(CRFProcess* m_pcs); //WW +extern std::vector node_connected_doms; // WW +extern void CountDoms2Nodes(CRFProcess* m_pcs); // WW extern void DOMRead(std::string); extern void DOMCreate(); //---- MPI Parallel -------------- -//MH//HS -#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || \ - defined(USE_MPI_GEMS) || defined(USE_MPI_BRNS) || defined(USE_MPI_KRC) +// MH//HS +#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_GEMS) \ + || defined(USE_MPI_BRNS) || defined(USE_MPI_KRC) extern char t_fname[3]; extern double time_ele_paral; //#include -//extern MPI_Comm comm_DDC; +// extern MPI_Comm comm_DDC; #endif //---- MPI Parallel -------------- diff --git a/FEM/pcs_dm.cpp b/FEM/pcs_dm.cpp old mode 100755 new mode 100644 index 0e217a56f..bacb05820 --- a/FEM/pcs_dm.cpp +++ b/FEM/pcs_dm.cpp @@ -26,7 +26,7 @@ #include "fem_ele_vec.h" // BC_Dynamic #include "rf_bc_new.h" -#include "rf_pcs.h" //OK_MOD" +#include "rf_pcs.h" //OK_MOD" #include "tools.h" // #if !defined(USE_PETSC) && !defined(NEW_EQS) // && defined(other parallel libs)//03~04.3012. WW @@ -69,10 +69,10 @@ int problem_dimension_dm = 0; int PreLoad = 0; bool GravityForce = true; -bool Localizing = false; // for tracing localization +bool Localizing = false; // for tracing localization // Last discontinuity element correponding to SeedElement vector LastElement(0); -vector ElementOnPath(0); // Element on the discontinuity path +vector ElementOnPath(0); // Element on the discontinuity path using namespace std; using FiniteElement::CFiniteElementVec; @@ -83,29 +83,26 @@ using Math_Group::Matrix; namespace process { -CRFProcessDeformation:: -CRFProcessDeformation() - : CRFProcess(), fem_dm(NULL), ARRAY(NULL), - counter(0), InitialNorm(0.0), idata_type(none), - _has_initial_stress_data(false), error_k0(1.0e10) +CRFProcessDeformation::CRFProcessDeformation() + : CRFProcess(), fem_dm(NULL), ARRAY(NULL), counter(0), InitialNorm(0.0), idata_type(none), + _has_initial_stress_data(false), error_k0(1.0e10) { - } CRFProcessDeformation::~CRFProcessDeformation() { const bool last_step = true; WriteGaussPointStress(last_step); - if(type == 41 && (idata_type == write_all_binary || idata_type == read_write) ) + if (type == 41 && (idata_type == write_all_binary || idata_type == read_write)) { // mono-deformation-liquid WriteSolution(); } - if(ARRAY) - delete [] ARRAY; - if(fem_dm) + if (ARRAY) + delete[] ARRAY; + if (fem_dm) delete fem_dm; fem_dm = NULL; @@ -115,24 +112,24 @@ CRFProcessDeformation::~CRFProcessDeformation() for (std::size_t i = 0; i < m_msh->ele_vector.size(); i++) { elem = m_msh->ele_vector[i]; - if (elem->GetMark()) // Marked for use + if (elem->GetMark()) // Marked for use { delete ele_value_dm[i]; ele_value_dm[i] = NULL; } } - if(enhanced_strain_dm > 0) + if (enhanced_strain_dm > 0) { - while(ele_value_dm.size() > 0) + while (ele_value_dm.size() > 0) ele_value_dm.pop_back(); - for(std::size_t i = 0; i < LastElement.size(); i++) + for (std::size_t i = 0; i < LastElement.size(); i++) { DisElement* disEle = LastElement[i]; delete disEle->InterFace; delete disEle; disEle = NULL; } - while(LastElement.size() > 0) + while (LastElement.size() > 0) LastElement.pop_back(); } } @@ -150,50 +147,51 @@ void CRFProcessDeformation::Initialization() //-- NW 25.10.2011 // this section has to be executed at latest before calling InitGauss() // Control for reading and writing solution - if(reload == 1) + if (reload == 1) idata_type = write_all_binary; - if(reload == 2) + if (reload == 2) idata_type = read_all_binary; - if(reload == 3) + if (reload == 3) idata_type = read_write; // Local assembliers // An instaniate of CFiniteElementVec - int i, Axisymm = 1; // ani-axisymmetry + int i, Axisymm = 1; // ani-axisymmetry // - if(m_msh->isAxisymmetry()) - Axisymm = -1; // Axisymmetry is true + if (m_msh->isAxisymmetry()) + Axisymm = -1; // Axisymmetry is true fem_dm = new CFiniteElementVec(this, Axisymm * m_msh->GetCoordinateFlag()); // // Monolithic scheme - if(type / 10 == 4) - fem = new CFiniteElementStd(this, Axisymm * m_msh->GetCoordinateFlag()); + if (type / 10 == 4) + fem = new CFiniteElementStd(this, Axisymm * m_msh->GetCoordinateFlag()); // pcs_number_deformation = pcs_number; // if (m_num) { - Tolerance_Local_Newton = m_num->nls_plasticity_local_tolerance; + Tolerance_Local_Newton = m_num->nls_plasticity_local_tolerance; Tolerance_global_Newton = m_num->nls_error_tolerance[0]; } - //Initialize material transform tensor for tansverse isotropic elasticity - //UJG/WW. 25.11.2009 - for(i = 0; i < (int)msp_vector.size(); i++) + // Initialize material transform tensor for tansverse isotropic elasticity + // UJG/WW. 25.11.2009 + for (i = 0; i < (int)msp_vector.size(); i++) msp_vector[i]->CalculateTransformMatrixFromNormalVector(problem_dimension_dm); - if(!msp_vector.size()) + if (!msp_vector.size()) { - std::cout << "***ERROR: MSP data not found!" << "\n"; + std::cout << "***ERROR: MSP data not found!" + << "\n"; return; } InitialMBuffer(); InitGauss(); //////////////////////////////////// - //WX:08.2011 initialise node value of h_pcs - if(Neglect_H_ini == 2) + // WX:08.2011 initialise node value of h_pcs + if (Neglect_H_ini == 2) InitialNodeValueHpcs(); - if(Neglect_H_ini == 1) + if (Neglect_H_ini == 1) CalIniTotalStress(); #ifdef DECOVALEX @@ -202,19 +200,19 @@ void CRFProcessDeformation::Initialization() int idv0 = 0, idv1 = 0; CRFProcess* h_pcs = NULL; h_pcs = fem_dm->h_pcs; - if(h_pcs->type == 14) // Richards + if (h_pcs->type == 14) // Richards { idv0 = h_pcs->GetNodeValueIndex("PRESSURE_I"); idv1 = h_pcs->GetNodeValueIndex("PRESSURE1"); for (i = 0; i < m_msh->GetNodesNumber(false); i++) - h_pcs->SetNodeValue(i,idv0, h_pcs->GetNodeValue(i,idv1)); + h_pcs->SetNodeValue(i, idv0, h_pcs->GetNodeValue(i, idv1)); } #endif /////////////////////////// - if(fem_dm->dynamic) + if (fem_dm->dynamic) CalcBC_or_SecondaryVariable_Dynamics(); - //TEST + // TEST // De_ActivateElement(false); } @@ -223,46 +221,46 @@ WX:08.2011 initialise node value of h pcs *************************************************************************/ void CRFProcessDeformation::InitialNodeValueHpcs() { - CRFProcess *tmp_h_pcs=NULL; - if(fem_dm->h_pcs==NULL) + CRFProcess* tmp_h_pcs = NULL; + if (fem_dm->h_pcs == NULL) return; tmp_h_pcs = fem_dm->h_pcs; int h_pcs_type = tmp_h_pcs->type; - int idv_p_ini, idv_p1_ini, idv_p2_ini, idv_p_1, idv_p1_1, idv_p2_1;// idv_sw_ini, idv_sw_1; + int idv_p_ini, idv_p1_ini, idv_p2_ini, idv_p_1, idv_p1_1, idv_p2_1; // idv_sw_ini, idv_sw_1; size_t i; - if (h_pcs_type == 1 || h_pcs_type == 41)//Liquide Flow + if (h_pcs_type == 1 || h_pcs_type == 41) // Liquide Flow { idv_p_ini = tmp_h_pcs->GetNodeValueIndex("PRESSURE1_Ini"); idv_p_1 = tmp_h_pcs->GetNodeValueIndex("PRESSURE1"); for (i = 0; i < m_msh->GetNodesNumber(false); i++) - tmp_h_pcs->SetNodeValue(i,idv_p_ini,tmp_h_pcs->GetNodeValue(i,idv_p_1)); + tmp_h_pcs->SetNodeValue(i, idv_p_ini, tmp_h_pcs->GetNodeValue(i, idv_p_1)); } - else if (h_pcs_type == 14)//Richards Flow + else if (h_pcs_type == 14) // Richards Flow { idv_p_ini = tmp_h_pcs->GetNodeValueIndex("PRESSURE1_Ini"); - //idv_sw_ini = tmp_h_pcs->GetNodeValueIndex("SATURATION1_Ini"); + // idv_sw_ini = tmp_h_pcs->GetNodeValueIndex("SATURATION1_Ini"); idv_p_1 = tmp_h_pcs->GetNodeValueIndex("PRESSURE1"); - //idv_sw_1 = tmp_h_pcs->GetNodeValueIndex("SATURATION1"); + // idv_sw_1 = tmp_h_pcs->GetNodeValueIndex("SATURATION1"); for (i = 0; i < m_msh->GetNodesNumber(false); i++) { - tmp_h_pcs->SetNodeValue(i,idv_p_ini,tmp_h_pcs->GetNodeValue(i,idv_p_1)); - //tmp_h_pcs->SetNodeValue(i,idv_sw_ini,tmp_h_pcs->GetNodeValue(i,idv_sw_1)); + tmp_h_pcs->SetNodeValue(i, idv_p_ini, tmp_h_pcs->GetNodeValue(i, idv_p_1)); + // tmp_h_pcs->SetNodeValue(i,idv_sw_ini,tmp_h_pcs->GetNodeValue(i,idv_sw_1)); } } - else if (h_pcs_type == 1212||h_pcs_type==42)//Multi Phase Flwo + else if (h_pcs_type == 1212 || h_pcs_type == 42) // Multi Phase Flwo { idv_p1_ini = tmp_h_pcs->GetNodeValueIndex("PRESSURE1_Ini"); idv_p2_ini = tmp_h_pcs->GetNodeValueIndex("PRESSURE2_Ini"); - //idv_sw_ini = tmp_h_pcs->GetNodeValueIndex("SATURSTION1_Ini"); + // idv_sw_ini = tmp_h_pcs->GetNodeValueIndex("SATURSTION1_Ini"); idv_p1_1 = tmp_h_pcs->GetNodeValueIndex("PRESSURE1"); idv_p2_1 = tmp_h_pcs->GetNodeValueIndex("PRESSURE2"); - //idv_sw_1 = tmp_h_pcs->GetNodeValueIndex("SATURATION1"); + // idv_sw_1 = tmp_h_pcs->GetNodeValueIndex("SATURATION1"); for (i = 0; i < m_msh->GetNodesNumber(false); i++) { - tmp_h_pcs->SetNodeValue(i,idv_p1_ini,tmp_h_pcs->GetNodeValue(i,idv_p1_1)); - tmp_h_pcs->SetNodeValue(i,idv_p2_ini,tmp_h_pcs->GetNodeValue(i,idv_p2_1)); - //tmp_h_pcs->SetNodeValue(i,idv_sw_ini,tmp_h_pcs->GetNodeValue(i,idv_sw_1)); + tmp_h_pcs->SetNodeValue(i, idv_p1_ini, tmp_h_pcs->GetNodeValue(i, idv_p1_1)); + tmp_h_pcs->SetNodeValue(i, idv_p2_ini, tmp_h_pcs->GetNodeValue(i, idv_p2_1)); + // tmp_h_pcs->SetNodeValue(i,idv_sw_ini,tmp_h_pcs->GetNodeValue(i,idv_sw_1)); } } return; @@ -272,19 +270,19 @@ WX:04.2013 calculate initial total stress for neglect h initial effect *************************************************************************/ void CRFProcessDeformation::CalIniTotalStress() { - if(fem_dm->h_pcs==NULL) + if (fem_dm->h_pcs == NULL) return; - CRFProcess *tmp_h_pcs=NULL; + CRFProcess* tmp_h_pcs = NULL; tmp_h_pcs = fem_dm->h_pcs; - ElementValue_DM *eleV_DM = NULL; - CSolidProperties *SMat = NULL; + ElementValue_DM* eleV_DM = NULL; + CSolidProperties* SMat = NULL; MeshLib::CElem* elem = NULL; int h_pcs_type = tmp_h_pcs->type; int idx_p1, idx_p2, idx_s; double pw = 0.; - idx_p1 = tmp_h_pcs->GetNodeValueIndex("PRESSURE1")+1; - idx_p2 = tmp_h_pcs->GetNodeValueIndex("PRESSURE2")+1; - idx_s = tmp_h_pcs->GetNodeValueIndex("SATURATION1")+1; + idx_p1 = tmp_h_pcs->GetNodeValueIndex("PRESSURE1") + 1; + idx_p2 = tmp_h_pcs->GetNodeValueIndex("PRESSURE2") + 1; + idx_s = tmp_h_pcs->GetNodeValueIndex("SATURATION1") + 1; for (std::size_t i = 0; i < m_msh->ele_vector.size(); i++) { pw = 0.; @@ -292,62 +290,70 @@ void CRFProcessDeformation::CalIniTotalStress() const int nnodes = elem->GetNodesNumber(false); const int MatGroup = elem->GetPatchIndex(); SMat = msp_vector[MatGroup]; - for (int j=0; jGetNodeValue(j,idx_p1); + pw += tmp_h_pcs->GetNodeValue(j, idx_p1); } - if(h_pcs_type == 14)//richards flow + if (h_pcs_type == 14) // richards flow { - if(SMat->bishop_model==1) - pw += tmp_h_pcs->GetNodeValue(j,idx_p1)*SMat->bishop_model_value; - else if (SMat->bishop_model==2) - pw += tmp_h_pcs->GetNodeValue(j,idx_p1)*pow(tmp_h_pcs->GetNodeValue(j,idx_s),SMat->bishop_model_value); - else if (SMat->bishop_model==3) + if (SMat->bishop_model == 1) + pw += tmp_h_pcs->GetNodeValue(j, idx_p1) * SMat->bishop_model_value; + else if (SMat->bishop_model == 2) + pw += tmp_h_pcs->GetNodeValue(j, idx_p1) + * pow(tmp_h_pcs->GetNodeValue(j, idx_s), SMat->bishop_model_value); + else if (SMat->bishop_model == 3) { - tmp_h_pcs->GetNodeValue(j,idx_s) >= SMat->bishop_model_value ? pw += tmp_h_pcs->GetNodeValue(j,idx_p1) : pw +=0.0; + tmp_h_pcs->GetNodeValue(j, idx_s) >= SMat->bishop_model_value + ? pw += tmp_h_pcs->GetNodeValue(j, idx_p1) + : pw += 0.0; } else - pw += tmp_h_pcs->GetNodeValue(j,idx_p1)*tmp_h_pcs->GetNodeValue(j,idx_s); + pw += tmp_h_pcs->GetNodeValue(j, idx_p1) * tmp_h_pcs->GetNodeValue(j, idx_s); } - if(h_pcs_type == 1212 || h_pcs_type == 42)//multi phase flow pg-sw*pc + if (h_pcs_type == 1212 || h_pcs_type == 42) // multi phase flow pg-sw*pc { - if(SMat->bishop_model==1) - pw += tmp_h_pcs->GetNodeValue(j,idx_p2) - SMat->bishop_model_value * tmp_h_pcs->GetNodeValue(j,idx_p1); - else if(SMat->bishop_model==2) - pw += tmp_h_pcs->GetNodeValue(j,idx_p2) - pow(tmp_h_pcs->GetNodeValue(j,idx_s),SMat->bishop_model_value) - *tmp_h_pcs->GetNodeValue(j,idx_p1); - else if(SMat->bishop_model==3) + if (SMat->bishop_model == 1) + pw += tmp_h_pcs->GetNodeValue(j, idx_p2) + - SMat->bishop_model_value * tmp_h_pcs->GetNodeValue(j, idx_p1); + else if (SMat->bishop_model == 2) + pw += tmp_h_pcs->GetNodeValue(j, idx_p2) + - pow(tmp_h_pcs->GetNodeValue(j, idx_s), SMat->bishop_model_value) + * tmp_h_pcs->GetNodeValue(j, idx_p1); + else if (SMat->bishop_model == 3) { - tmp_h_pcs->GetNodeValue(j,idx_p1) >= SMat->bishop_model_value ? pw += tmp_h_pcs->GetNodeValue(j,idx_p2) - tmp_h_pcs->GetNodeValue(j,idx_p1) : pw += tmp_h_pcs->GetNodeValue(j,idx_p2); - } - else - pw += tmp_h_pcs->GetNodeValue(j,idx_p2) - tmp_h_pcs->GetNodeValue(j,idx_s)*tmp_h_pcs->GetNodeValue(j,idx_p1); + tmp_h_pcs->GetNodeValue(j, idx_p1) >= SMat->bishop_model_value + ? pw += tmp_h_pcs->GetNodeValue(j, idx_p2) - tmp_h_pcs->GetNodeValue(j, idx_p1) + : pw += tmp_h_pcs->GetNodeValue(j, idx_p2); + } + else + pw += tmp_h_pcs->GetNodeValue(j, idx_p2) + - tmp_h_pcs->GetNodeValue(j, idx_s) * tmp_h_pcs->GetNodeValue(j, idx_p1); } } - pw /= nnodes;//average node value, could be also interp. value + pw /= nnodes; // average node value, could be also interp. value - if (elem->GetMark()) // Marked for use, it is necessary here + if (elem->GetMark()) // Marked for use, it is necessary here { - //elem->SetOrder(true); - //fem_dm->ConfigElement(elem); + // elem->SetOrder(true); + // fem_dm->ConfigElement(elem); eleV_DM = ele_value_dm[i]; const int NGS = fem_dm->GetNumGaussPoints(); for (int gp = 0; gp < NGS; gp++) { - for(int j=0; j<3; j++) + for (int j = 0; j < 3; j++) { - if(SMat->biot_const<0 && pw < 0)//if biot is negative value, negative pw is not considered - (*eleV_DM->Stress0)(j, gp) = (*eleV_DM->Stress0)(j, gp); + if (SMat->biot_const < 0 && pw < 0) // if biot is negative value, negative pw is not considered + (*eleV_DM->Stress0)(j, gp) = (*eleV_DM->Stress0)(j, gp); else - (*eleV_DM->Stress0)(j, gp) = (*eleV_DM->Stress0)(j, gp) - SMat->biot_const*pw; + (*eleV_DM->Stress0)(j, gp) = (*eleV_DM->Stress0)(j, gp) - SMat->biot_const * pw; } - //for postExcavation Stress0 is already updated with Stress, as well as UpdateIniStateValue() + // for postExcavation Stress0 is already updated with Stress, as well as UpdateIniStateValue() } } - }// end loop elements + } // end loop elements } /************************************************************************* @@ -358,30 +364,29 @@ void CRFProcessDeformation::CalIniTotalStress() **************************************************************************/ void CRFProcessDeformation::InitialMBuffer() { - if(!msp_vector.size()) + if (!msp_vector.size()) { - cout << "No .msp file. " << "\n"; + cout << "No .msp file. " + << "\n"; abort(); } - size_t bufferSize (0); + size_t bufferSize(0); bool HM_Stagered = false; - if(GetObjType() == 4) + if (GetObjType() == 4) { bufferSize = GetPrimaryVNumber() * m_msh->GetNodesNumber(true); - if(H_Process) + if (H_Process) HM_Stagered = true; } - else if(GetObjType() == 41) - bufferSize = (GetPrimaryVNumber() - 1) * m_msh->GetNodesNumber(true) + - m_msh->GetNodesNumber(false); + else if (GetObjType() == 41) + bufferSize = (GetPrimaryVNumber() - 1) * m_msh->GetNodesNumber(true) + m_msh->GetNodesNumber(false); else if (GetObjType() == 42) - bufferSize = (GetPrimaryVNumber() - 2) * m_msh->GetNodesNumber(true) + - 2 * m_msh->GetNodesNumber(false); + bufferSize = (GetPrimaryVNumber() - 2) * m_msh->GetNodesNumber(true) + 2 * m_msh->GetNodesNumber(false); - //Allocate memory for temporal array - if(m_num->nls_method != 2) - ARRAY = new double[bufferSize]; + // Allocate memory for temporal array + if (m_num->nls_method != 2) + ARRAY = new double[bufferSize]; // Allocate memory for element variables MeshLib::CElem* elem = NULL; @@ -390,8 +395,7 @@ void CRFProcessDeformation::InitialMBuffer() elem = m_msh->ele_vector[i]; // if (elem->GetMark()) // Marked for use // { - ElementValue_DM* ele_val = - new ElementValue_DM(elem, m_num->ele_gauss_points, HM_Stagered); + ElementValue_DM* ele_val = new ElementValue_DM(elem, m_num->ele_gauss_points, HM_Stagered); ele_value_dm.push_back(ele_val); // } } @@ -408,14 +412,17 @@ void CRFProcessDeformation::InitialMBuffer() double CRFProcessDeformation::Execute(int loop_process_number) { #if defined(USE_MPI) || defined(USE_PETSC) - if(myrank == 1) + if (myrank == 1) { #endif - std::cout<<"\n ================================================" << "\n"; - std::cout << " ->Process " << loop_process_number << ": " << convertProcessTypeToString (getProcessType()) << "\n"; - std::cout << " ================================================" << "\n"; + std::cout << "\n ================================================" + << "\n"; + std::cout << " ->Process " << loop_process_number << ": " << convertProcessTypeToString(getProcessType()) + << "\n"; + std::cout << " ================================================" + << "\n"; #if defined(USE_MPI) || defined(USE_PETSC) -} + } #endif clock_t dm_time; @@ -431,10 +438,10 @@ double CRFProcessDeformation::Execute(int loop_process_number) double NormU, Norm = 0.0, Error1, Error = 0.0; double ErrorU1, ErrorU = 0.0; - //const int defaultSteps=100; + // const int defaultSteps=100; int MaxIteration = m_num->nls_max_iterations; int elasticity = 0; - //int monolithic=0; + // int monolithic=0; // string delim = " | "; //---------------------------------------------------------- @@ -442,43 +449,43 @@ double CRFProcessDeformation::Execute(int loop_process_number) // m_msh->SwitchOnQuadraticNodes(true); // - //TEST if(num_type_name.find("EXCAVATION")!=0) - if(hasAnyProcessDeactivatedSubdomains || NumDeactivated_SubDomains > 0 || - num_type_name.find("EXCAVATION") != string::npos) - //if(NumDeactivated_SubDomains>0||num_type_name.find("EXCAVATION")!=string::npos) + // TEST if(num_type_name.find("EXCAVATION")!=0) + if (hasAnyProcessDeactivatedSubdomains || NumDeactivated_SubDomains > 0 + || num_type_name.find("EXCAVATION") != string::npos) + // if(NumDeactivated_SubDomains>0||num_type_name.find("EXCAVATION")!=string::npos) CheckMarkedElement(); // MarkNodesForGlobalAssembly(); - if(ExcavMaterialGroup>-1) - CheckExcavedElement();//WX:07.2011 + if (ExcavMaterialGroup > -1) + CheckExcavedElement(); // WX:07.2011 - counter++; // Times of this method to be called + counter++; // Times of this method to be called LoadFactor = 1.0; // For pure elesticity - if(pcs_deformation <= 100 && !fem_dm->dynamic) + if (pcs_deformation <= 100 && !fem_dm->dynamic) { elasticity = 1; MaxIteration = 1; } // For monolithic scheme - if(type / 10 == 4) // Modified at 05.07.2010 WW + if (type / 10 == 4) // Modified at 05.07.2010 WW // monolithic=1; number_of_load_steps = 1; - // system matrix -#if defined (USE_PETSC) // || defined (other parallel solver lib). 04.2012 WW +// system matrix +#if defined(USE_PETSC) // || defined (other parallel solver lib). 04.2012 WW eqs_new->Initialize(); -#elif defined(NEW_EQS) //WW - // +#elif defined(NEW_EQS) // WW +// #if defined(USE_MPI) CPARDomain* dom = dom_vector[myrank]; long global_eqs_dim = pcs_number_of_primary_nvals * m_msh->GetNodesNumber(true); dom->ConfigEQS(m_num, global_eqs_dim, true); #else - eqs_new->ConfigNumerics(m_num); //27.11.2007 WW + eqs_new->ConfigNumerics(m_num); // 27.11.2007 WW #endif - // +// #else SetZeroLinearSolver(eqs); #endif @@ -500,11 +507,11 @@ double CRFProcessDeformation::Execute(int loop_process_number) */ - //JT//if(CouplingIterations == 0 && m_num->nls_method != 2) - if(this->first_coupling_iteration && m_num->nls_method != 2) - StoreLastSolution(); //u_n-->temp + // JT//if(CouplingIterations == 0 && m_num->nls_method != 2) + if (this->first_coupling_iteration && m_num->nls_method != 2) + StoreLastSolution(); // u_n-->temp // Reset stress for each coupling step when partitioned scheme is applied to HM - if(H_Process && (type / 10 != 4)) + if (H_Process && (type / 10 != 4)) ResetCouplingStep(); // // Compute the maxium ratio of load increment and @@ -572,7 +579,7 @@ double CRFProcessDeformation::Execute(int loop_process_number) if(fluid) number_of_load_steps = 10; } */ - for(int l = 1; l <= number_of_load_steps; l++) + for (int l = 1; l <= number_of_load_steps; l++) { // This is may needed by pure mechacial process // Auto increment loading 2 @@ -614,39 +621,41 @@ double CRFProcessDeformation::Execute(int loop_process_number) InitializeNewtonSteps(); // // Begin Newton-Raphson steps - if(elasticity != 1) + if (elasticity != 1) { - //ite_steps = 0; + // ite_steps = 0; Error = 1.0e+8; ErrorU = 1.0e+8; Norm = 1.0e+8; NormU = 1.0e+8; #if defined(USE_MPI) || defined(USE_PETSC) - if(myrank == 0) + if (myrank == 0) { #endif - //Screan printing: - std::cout <<" Starting loading step "<< l << "/" << number_of_load_steps <<". Load factor: " << LoadFactor << "\n"; - std::cout <<" ------------------------------------------------"<<"\n"; + // Screan printing: + std::cout << " Starting loading step " << l << "/" << number_of_load_steps + << ". Load factor: " << LoadFactor << "\n"; + std::cout << " ------------------------------------------------" + << "\n"; #if defined(USE_MPI) || defined(USE_PETSC) - } + } #endif } ite_steps = 0; - while(ite_steps < MaxIteration) + while (ite_steps < MaxIteration) { ite_steps++; - // Refresh solver +// Refresh solver #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - // InitializeRHS_with_u0(); -#elif defined(NEW_EQS) //WW +// InitializeRHS_with_u0(); +#elif defined(NEW_EQS) // WW #ifndef USE_MPI - eqs_new->Initialize(); //27.11.2007 WW + eqs_new->Initialize(); // 27.11.2007 WW #endif #ifdef JFNK_H2M /// If JFNK method (1.09.2010. WW): - if(m_num->nls_method == 2) + if (m_num->nls_method == 2) { Jacobian_Multi_Vector_JFNK(); eqs_new->setPCS(this); @@ -656,171 +665,186 @@ double CRFProcessDeformation::Execute(int loop_process_number) SetZeroLinearSolver(eqs); #endif - // Assemble and solve system equation - /* - #ifdef MFC - CString m_str; - m_str.Format("Time step: t=%e sec, %s, Load step: %i, NR-Iteration: %i, Calculate element matrices",\ - aktuelle_zeit,pcs_type_name.c_str(),l,ite_steps); - pWin->SendMessage(WM_SETMESSAGESTRING,0,(LPARAM)(LPCSTR)m_str); - #endif - */ -#if defined( USE_MPI) || defined( USE_PETSC) //WW - if(myrank == 0) +// Assemble and solve system equation +/* + #ifdef MFC + CString m_str; + m_str.Format("Time step: t=%e sec, %s, Load step: %i, NR-Iteration: %i, Calculate element matrices",\ + aktuelle_zeit,pcs_type_name.c_str(),l,ite_steps); + pWin->SendMessage(WM_SETMESSAGESTRING,0,(LPARAM)(LPCSTR)m_str); + #endif + */ +#if defined(USE_MPI) || defined(USE_PETSC) // WW + if (myrank == 0) #endif - std::cout << " Assembling equation system..." << "\n"; + std::cout << " Assembling equation system..." + << "\n"; -#if defined( USE_MPI) || defined( USE_PETSC) //WW - clock_t cpu_time = 0; //WW +#if defined(USE_MPI) || defined(USE_PETSC) // WW + clock_t cpu_time = 0; // WW cpu_time = -clock(); #endif - if(m_num->nls_method != 2) // Not JFNK method. 05.08.2010. WW + if (m_num->nls_method != 2) // Not JFNK method. 05.08.2010. WW GlobalAssembly(); -#if defined(USE_MPI) || defined( USE_PETSC) //WW +#if defined(USE_MPI) || defined(USE_PETSC) // WW cpu_time += clock(); cpu_time_assembly += cpu_time; #endif // - if(type != 41) -#if defined( USE_PETSC) //WW - InitializeRHS_with_u0(); + if (type != 41) +#if defined(USE_PETSC) // WW + InitializeRHS_with_u0(); #else SetInitialGuess_EQS_VEC(); #endif -#ifdef USE_MPI //WW - // No initial guess for deformation. - // for(long ll=0; lldim; ll++) - // eqs->x[ll] = 0.0; - // +#ifdef USE_MPI // WW +// No initial guess for deformation. +// for(long ll=0; lldim; ll++) +// eqs->x[ll] = 0.0; +// #endif -#if defined( USE_MPI) || defined( USE_PETSC) //WW - if(myrank == 0) +#if defined(USE_MPI) || defined(USE_PETSC) // WW + if (myrank == 0) #endif - std::cout << " Calling linear solver..." << "\n"; - /// Linear solver + std::cout << " Calling linear solver..." + << "\n"; +/// Linear solver #if defined(USE_PETSC) //|| defined(other parallel libs)//03~04.3012. WW - eqs_new->Solver(); - eqs_new->MappingSolution(); - if(!elasticity) - Norm = eqs_new->GetVecNormRHS(); + eqs_new->Solver(); + eqs_new->MappingSolution(); + if (!elasticity) + Norm = eqs_new->GetVecNormRHS(); -#elif defined(NEW_EQS) //WW - // +#elif defined(NEW_EQS) // WW +// #if defined(USE_MPI) - //21.12.2007 + // 21.12.2007 dom->eqsH->Solver(eqs_new->x, global_eqs_dim); #else #if defined(LIS) || defined(MKL) - eqs_new->Solver(this->m_num); //NW + eqs_new->Solver(this->m_num); // NW #else - eqs_new->Solver(); //27.11.2007 + eqs_new->Solver(); // 27.11.2007 #endif #endif #else // ifdef NEW_EQS ExecuteLinearSolver(); #endif - // - // Norm of b (RHS in eqs) +// +// Norm of b (RHS in eqs) #ifdef USE_MPI - if(!elasticity) + if (!elasticity) Norm = dom->eqsH->NormRHS(); #else #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - //TODO +// TODO #elif defined(NEW_EQS) - if(!elasticity) + if (!elasticity) Norm = eqs_new->NormRHS(); #else - if(!elasticity) + if (!elasticity) Norm = NormOfUnkonwn_orRHS(false); #endif #endif - if(!elasticity) + if (!elasticity) { // Check the convergence Error1 = Error; ErrorU1 = ErrorU; #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - NormU = eqs_new->GetVecNormX(); + NormU = eqs_new->GetVecNormX(); #elif defined(NEW_EQS) NormU = eqs_new->NormX(); #else NormU = NormOfUnkonwn_orRHS(); #endif - //JT//if(ite_steps == 1 && CouplingIterations == 0) - if(ite_steps == 1 && this->first_coupling_iteration) + // JT//if(ite_steps == 1 && CouplingIterations == 0) + if (ite_steps == 1 && this->first_coupling_iteration) { InitialNorm = Norm; InitialNormU0 = NormU; - if(counter == 1) + if (counter == 1) InitialNormU = NormU; } Error = Norm / InitialNorm; ErrorU = NormU / InitialNormU0; - if(Norm < Tolerance_global_Newton && Error > Norm) + if (Norm < Tolerance_global_Newton && Error > Norm) Error = Norm; // if(Norm1.0e-1) damping=0.5; - if(Error / Error1 > 1.0e-1 || ErrorU / ErrorU1 > 1.0e-1) + if (Error / Error1 > 1.0e-1 || ErrorU / ErrorU1 > 1.0e-1) damping = 0.5; - if(ErrorU < Error) + if (ErrorU < Error) Error = ErrorU; #if defined(NEW_EQS) && defined(JFNK_H2M) /// If JFNK, get w from the buffer - if(m_num->nls_method == 2) - //damping = LineSearch(); + if (m_num->nls_method == 2) + // damping = LineSearch(); Recovery_du_JFNK(); #endif // JT: Store the process and coupling errors pcs_num_dof_errors = 1; - if(ite_steps == 1){ + if (ite_steps == 1) + { pcs_absolute_error[0] = NormU; pcs_relative_error[0] = pcs_absolute_error[0] / Tolerance_global_Newton; cpl_max_relative_error = pcs_relative_error[0]; cpl_num_dof_errors = 1; } - else{ + else + { pcs_absolute_error[0] = Error; pcs_relative_error[0] = Error / Tolerance_global_Newton; } - // +// #if defined(USE_MPI) || defined(USE_PETSC) - if(myrank == 0) + if (myrank == 0) { #endif - //Screan printing: - std::cout<<" -->End of Newton-Raphson iteration: "<End of Newton-Raphson iteration: " << ite_steps << "/" << MaxIteration + << "\n"; + cout.width(8); + cout.precision(2); + cout.setf(ios::scientific); + cout << " NR-Error" + << " " + << "RHS Norm 0" + << " " + << "RHS Norm " + << " " + << "Unknowns Norm" + << " " + << "Damping" + << "\n"; + cout << " " << Error << " " << InitialNorm << " " << Norm << " " << NormU << " " + << " " << damping << "\n"; + std::cout << " ------------------------------------------------" + << "\n"; #if defined(USE_MPI) || defined(USE_PETSC) - } + } #endif - if(Error > 100.0 && ite_steps > 1) + if (Error > 100.0 && ite_steps > 1) { - printf ( - "\n Attention: Newton-Raphson step is diverged. Programme halt!\n"); + printf("\n Attention: Newton-Raphson step is diverged. Programme halt!\n"); exit(1); } - if(InitialNorm < 10 * Tolerance_global_Newton) + if (InitialNorm < 10 * Tolerance_global_Newton) break; - if(Norm < 0.001 * InitialNorm) + if (Norm < 0.001 * InitialNorm) break; - if(Error <= Tolerance_global_Newton) + if (Error <= Tolerance_global_Newton) { - if(ite_steps==1)//WX:05.2012 + if (ite_steps == 1) // WX:05.2012 { UpdateIterativeStep(damping, 0); break; @@ -831,29 +855,30 @@ double CRFProcessDeformation::Execute(int loop_process_number) } // w = w+dw for Newton-Raphson UpdateIterativeStep(damping, 0); // w = w+dw - } // Newton-Raphson iteration + } // Newton-Raphson iteration // Update stresses UpdateStress(); - if(fem_dm->dynamic) + if (fem_dm->dynamic) CalcBC_or_SecondaryVariable_Dynamics(); // Update displacements, u=u+w for the Newton-Raphson // u1 = u0 for pure elasticity - UpdateIterativeStep(1.0,1); + UpdateIterativeStep(1.0, 1); } // Load step // // For coupling control - std::cout <<" Deformation process converged." << "\n"; + std::cout << " Deformation process converged." + << "\n"; Error = 0.0; - if(type / 10 != 4) // Partitioned scheme + if (type / 10 != 4) // Partitioned scheme { #ifdef USE_PETSC - NormU = eqs_new->GetVecNormX(); + NormU = eqs_new->GetVecNormX(); #else - for(size_t n = 0; n < m_msh->GetNodesNumber(true); n++) - for(int l = 0; l < pcs_number_of_primary_nvals; l++) + for (size_t n = 0; n < m_msh->GetNodesNumber(true); n++) + for (int l = 0; l < pcs_number_of_primary_nvals; l++) { NormU = GetNodeValue(n, fem_dm->Idx_dm1[l]); Error += NormU * NormU; @@ -865,24 +890,26 @@ double CRFProcessDeformation::Execute(int loop_process_number) // Determine the discontinuity surface if enhanced strain methods is on. - if(enhanced_strain_dm > 0) + if (enhanced_strain_dm > 0) Trace_Discontinuity(); // dm_time += clock(); -#if defined( USE_MPI) || defined( USE_PETSC) //WW - if(myrank == 0) +#if defined(USE_MPI) || defined(USE_PETSC) // WW + if (myrank == 0) { #endif - std::cout <<" CPU time elapsed in deformation: " << (double)dm_time / CLOCKS_PER_SEC<<"s"<<"\n"; - std::cout <<" ------------------------------------------------"<<"\n"; -#if defined( USE_MPI) || defined( USE_PETSC) //WW -} + std::cout << " CPU time elapsed in deformation: " << (double)dm_time / CLOCKS_PER_SEC << "s" + << "\n"; + std::cout << " ------------------------------------------------" + << "\n"; +#if defined(USE_MPI) || defined(USE_PETSC) // WW + } #endif // Recovery the old solution. Temp --> u_n for flow proccess - if(m_num->nls_method != 2) + if (m_num->nls_method != 2) RecoverSolution(); - // -#ifdef NEW_EQS //WW +// +#ifdef NEW_EQS // WW #if defined(USE_MPI) dom->eqsH->Clean(); #else @@ -891,8 +918,8 @@ double CRFProcessDeformation::Execute(int loop_process_number) #endif #endif // - //JT//if(CouplingIterations > 0) - if(this->first_coupling_iteration) + // JT//if(CouplingIterations > 0) + if (this->first_coupling_iteration) Error = fabs(Error - error_k0) / error_k0; error_k0 = Error; // @@ -903,82 +930,82 @@ double CRFProcessDeformation::Execute(int loop_process_number) //---------------------------------------------------------------------- std::vector deact_dom; for(l = 0; l < (long)msp_vector.size(); l++) - if(msp_vector[l]->excavated) - deact_dom.push_back(l); + if(msp_vector[l]->excavated) + deact_dom.push_back(l); if(ExcavMaterialGroup >= 0 && PCS_ExcavState < 0) //WX:01.2010.update pcs excav state { - for(l = 0; l < (long)m_msh->ele_vector.size(); l++) - if((m_msh->ele_vector[l]->GetExcavState() > 0) && - !(m_msh->ele_vector[l]->GetMark())) - { - PCS_ExcavState = 1; - break; - } + for(l = 0; l < (long)m_msh->ele_vector.size(); l++) + if((m_msh->ele_vector[l]->GetExcavState() > 0) && + !(m_msh->ele_vector[l]->GetMark())) + { + PCS_ExcavState = 1; + break; + } } //WX:01.2011 modified for coupled excavation if(deact_dom.size() > 0 || PCS_ExcavState > 0) { - // MXDumpGLS("rf_pcs.txt",1,eqs->b,eqs->x); //abort();} - - // - // 07.04.2010 WW - size_t i; - bool done; - MeshLib::CElem* elem = NULL; - MeshLib::CNode* node = NULL; - ElementValue_DM* eleV_DM = NULL; - for (l = 0; l < (long)m_msh->ele_vector.size(); l++) - { - eleV_DM = ele_value_dm[l]; - (*eleV_DM->Stress0) = (*eleV_DM->Stress); - - elem = m_msh->ele_vector[l]; - done = false; - for(i = 0; i < deact_dom.size(); i++) - if(elem->GetPatchIndex() == static_cast(deact_dom[i])) - { - elem->MarkingAll(false); - done = true; - break; - } - if(ExcavMaterialGroup >= 0) //WX - if(elem->GetExcavState() >= 0) - { - elem->MarkingAll(false); - done = true; - } - if(done) - continue; - else - elem->MarkingAll(true); - } - - size_t mesh_node_vector_size (m_msh->nod_vector.size()); - for (size_t l = 0; l < mesh_node_vector_size; l++) - while(m_msh->nod_vector[l]->getConnectedElementIDs().size()) - m_msh->nod_vector[l]->getConnectedElementIDs().pop_back(); - - size_t mesh_ele_vector_size (m_msh->ele_vector.size()); - //WX:07.2011 error fixed - for (size_t l = 0; l < mesh_ele_vector_size; l++) - { - elem = m_msh->ele_vector[l]; - if(!elem->GetMark()) - continue; - for(i = 0; i < elem->GetNodesNumber(m_msh->getOrder()); i++) - { - done = false; - node = elem->GetNode(i); - for(size_t j = 0; j < node->getConnectedElementIDs().size(); j++) - if(l == node->getConnectedElementIDs()[j]) - { - done = true; - break; - } - if(!done) - node->getConnectedElementIDs().push_back(l); - } - } // + // MXDumpGLS("rf_pcs.txt",1,eqs->b,eqs->x); //abort();} + + // + // 07.04.2010 WW + size_t i; + bool done; + MeshLib::CElem* elem = NULL; + MeshLib::CNode* node = NULL; + ElementValue_DM* eleV_DM = NULL; + for (l = 0; l < (long)m_msh->ele_vector.size(); l++) + { + eleV_DM = ele_value_dm[l]; + (*eleV_DM->Stress0) = (*eleV_DM->Stress); + + elem = m_msh->ele_vector[l]; + done = false; + for(i = 0; i < deact_dom.size(); i++) + if(elem->GetPatchIndex() == static_cast(deact_dom[i])) + { + elem->MarkingAll(false); + done = true; + break; + } + if(ExcavMaterialGroup >= 0) //WX + if(elem->GetExcavState() >= 0) + { + elem->MarkingAll(false); + done = true; + } + if(done) + continue; + else + elem->MarkingAll(true); + } + + size_t mesh_node_vector_size (m_msh->nod_vector.size()); + for (size_t l = 0; l < mesh_node_vector_size; l++) + while(m_msh->nod_vector[l]->getConnectedElementIDs().size()) + m_msh->nod_vector[l]->getConnectedElementIDs().pop_back(); + + size_t mesh_ele_vector_size (m_msh->ele_vector.size()); + //WX:07.2011 error fixed + for (size_t l = 0; l < mesh_ele_vector_size; l++) + { + elem = m_msh->ele_vector[l]; + if(!elem->GetMark()) + continue; + for(i = 0; i < elem->GetNodesNumber(m_msh->getOrder()); i++) + { + done = false; + node = elem->GetNode(i); + for(size_t j = 0; j < node->getConnectedElementIDs().size(); j++) + if(l == node->getConnectedElementIDs()[j]) + { + done = true; + break; + } + if(!done) + node->getConnectedElementIDs().push_back(l); + } + } // } */ @@ -1006,7 +1033,7 @@ void CRFProcessDeformation::InitGauss(void) { const int LenMat = 7; size_t i; - int j, k, gp, NGS, MatGroup, n_dom; + int j, k, gp, NGS, MatGroup, n_dom; int PModel = 1; int gp_r = 0, gp_s = 0, gp_t = 0; // double z=0.0; @@ -1017,7 +1044,7 @@ void CRFProcessDeformation::InitGauss(void) CInitialCondition* m_ic = NULL; std::vector stress_ic(6); - //double M_cam = 0.0; + // double M_cam = 0.0; double pc0 = 0.0; double OCR = 1.0; n_dom = k = 0; @@ -1030,7 +1057,7 @@ void CRFProcessDeformation::InitGauss(void) Idx_Strain[2] = GetNodeValueIndex("STRAIN_ZZ"); Idx_Strain[3] = GetNodeValueIndex("STRAIN_XY"); - if(problem_dimension_dm == 3) + if (problem_dimension_dm == 3) { NS = 6; Idx_Strain[4] = GetNodeValueIndex("STRAIN_XZ"); @@ -1038,9 +1065,9 @@ void CRFProcessDeformation::InitGauss(void) } Idx_Strain[NS] = GetNodeValueIndex("STRAIN_PLS"); - for(j = 0; j < NS; j++) + for (j = 0; j < NS; j++) stress_ic[j] = NULL; - for(j = 0; j < (long)ic_vector.size(); j++) + for (j = 0; j < (long)ic_vector.size(); j++) { m_ic = ic_vector[j]; if (m_ic->getProcessPrimaryVariable() == FiniteElement::STRESS_XX) @@ -1057,24 +1084,24 @@ void CRFProcessDeformation::InitGauss(void) stress_ic[5] = m_ic; } int ccounter = 0; - for(j = 0; j < NS; j++) - if(stress_ic[j]) + for (j = 0; j < NS; j++) + if (stress_ic[j]) ccounter++; // Initial stresses are given in .ic file, reload file is therefore disabled, - if(ccounter > 0) + if (ccounter > 0) { _has_initial_stress_data = true; } for (i = 0; i < m_msh->GetNodesNumber(false); i++) - for(j = 0; j < NS + 1; j++) + for (j = 0; j < NS + 1; j++) SetNodeValue(i, Idx_Strain[j], 0.0); MeshLib::CElem* elem = NULL; for (i = 0; i < m_msh->ele_vector.size(); i++) { elem = m_msh->ele_vector[i]; - if (elem->GetMark()) // Marked for use + if (elem->GetMark()) // Marked for use { MatGroup = elem->GetPatchIndex(); SMat = msp_vector[MatGroup]; @@ -1088,14 +1115,14 @@ void CRFProcessDeformation::InitGauss(void) for (j = 3; j < fem_dm->ns; j++) Strs[j] = 0.0; - if(PModel == 2) + if (PModel == 2) *(eleV_DM->xi) = 0.0; - if(PModel == 3) + if (PModel == 3) { - //WW M_cam = (*SMat->data_Plasticity)(0); + // WW M_cam = (*SMat->data_Plasticity)(0); pc0 = (*SMat->data_Plasticity)(3); // The initial preconsolidation pressure - // Void ratio + // Void ratio *(eleV_DM->e_i) = (*SMat->data_Plasticity)(4); OCR = (*SMat->data_Plasticity)(5); // Over consolidation ratio for (j = 0; j < 3; j++) @@ -1118,14 +1145,14 @@ void CRFProcessDeformation::InitGauss(void) } // - //if 2D //ToDo: Set option for 3D + // if 2D //ToDo: Set option for 3D // Loop over Gauss points NGS = fem_dm->GetNumGaussPoints(); - //WW NGSS = fem_dm->GetNumGaussSamples(); + // WW NGSS = fem_dm->GetNumGaussSamples(); for (gp = 0; gp < NGS; gp++) { - if(ccounter > 0) + if (ccounter > 0) { fem_dm->GetGaussData(gp, gp_r, gp_s, gp_t); fem_dm->ComputeShapefct(2); @@ -1133,63 +1160,53 @@ void CRFProcessDeformation::InitGauss(void) for (j = 0; j < NS; j++) { m_ic = stress_ic[j]; - if(!m_ic) + if (!m_ic) continue; n_dom = m_ic->GetNumDom(); for (k = 0; k < n_dom; k++) { - if(MatGroup != m_ic->GetDomain(k)) + if (MatGroup != m_ic->GetDomain(k)) continue; - (*eleV_DM->Stress)(j, gp) = - m_ic->getLinearFunction()->getValue( - k, - xyz[0], - xyz[1], - xyz[2]); - (*eleV_DM->Stress0)(j, - gp) = - (*eleV_DM->Stress)(j, gp); + (*eleV_DM->Stress)(j, gp) = m_ic->getLinearFunction()->getValue(k, xyz[0], xyz[1], xyz[2]); + (*eleV_DM->Stress0)(j, gp) = (*eleV_DM->Stress)(j, gp); } } } else { - switch(PModel) + switch (PModel) { - case 2: // Weimar's model - // Initial stress_xx, yy,zz - for (j = 0; j < 3; j++) - (*eleV_DM->Stress)(j, - gp) = - (*SMat->data_Plasticity)(20 + j); - break; - case 3: // Cam-Clay - for (j = 0; j < 3; j++) - (*eleV_DM->Stress0)(j, gp) = Strs[j]; - (*eleV_DM->Stress) = (*eleV_DM->Stress0); - break; + case 2: // Weimar's model + // Initial stress_xx, yy,zz + for (j = 0; j < 3; j++) + (*eleV_DM->Stress)(j, gp) = (*SMat->data_Plasticity)(20 + j); + break; + case 3: // Cam-Clay + for (j = 0; j < 3; j++) + (*eleV_DM->Stress0)(j, gp) = Strs[j]; + (*eleV_DM->Stress) = (*eleV_DM->Stress0); + break; } } - if(eleV_DM->Stress_j) + if (eleV_DM->Stress_j) (*eleV_DM->Stress_j) = (*eleV_DM->Stress); // - switch(PModel) + switch (PModel) { - case 2: // Weimar's model - for (j = 0; j < LenMat; j++) - (*eleV_DM->MatP)(j, - gp) = (*SMat->data_Plasticity)(j); - break; - case 3: // Cam-Clay - pc0 *= OCR; ///TEST - (*eleV_DM->prep0)(gp) = pc0; - break; + case 2: // Weimar's model + for (j = 0; j < LenMat; j++) + (*eleV_DM->MatP)(j, gp) = (*SMat->data_Plasticity)(j); + break; + case 3: // Cam-Clay + pc0 *= OCR; /// TEST + (*eleV_DM->prep0)(gp) = pc0; + break; } // } - // Initial condition by LBNL - //////////////////////////////////////////////////////// - //#define EXCAVATION +// Initial condition by LBNL +//////////////////////////////////////////////////////// +//#define EXCAVATION #ifdef EXCAVATION int gp_r, gp_s, gp_t; double z = 0.0; @@ -1207,13 +1224,13 @@ void CRFProcessDeformation::InitGauss(void) (*eleV_DM->Stress)(0, gp) = 0.6*(*eleV_DM->Stress)(1, gp); */ - //THM1 + // THM1 z = 500 - xyz[2]; // 3D xyz[1]; //2D (*eleV_DM->Stress)(2, gp) = -(0.02 * z + 0.6) * 1.0e6; (*eleV_DM->Stress)(1, gp) = -2700 * 9.81 * z; (*eleV_DM->Stress)(0, gp) = -(0.055 * z + 4.6) * 1.0e6; - if(eleV_DM->Stress_j) + if (eleV_DM->Stress_j) (*eleV_DM->Stress_j) = (*eleV_DM->Stress); } #endif @@ -1222,10 +1239,10 @@ void CRFProcessDeformation::InitGauss(void) } } // Reload the stress results of the previous simulation - if(idata_type == read_all_binary || idata_type == read_write ) + if (idata_type == read_all_binary || idata_type == read_write) { ReadGaussPointStress(); - if(type == 41) // mono-deformation-liquid + if (type == 41) // mono-deformation-liquid ReadSolution(); } // For excavation simulation. Moved here on 05.09.2007 WW @@ -1252,7 +1269,7 @@ void CRFProcessDeformation::CreateInitialState4Excavation() Idx_Strain[2] = GetNodeValueIndex("STRAIN_ZZ"); Idx_Strain[3] = GetNodeValueIndex("STRAIN_XY"); - if(problem_dimension_dm == 3) + if (problem_dimension_dm == 3) { NS = 6; Idx_Strain[4] = GetNodeValueIndex("STRAIN_XZ"); @@ -1260,33 +1277,34 @@ void CRFProcessDeformation::CreateInitialState4Excavation() } Idx_Strain[NS] = GetNodeValueIndex("STRAIN_PLS"); // For excavation simulation. Moved here on 05.09.2007 WW - if ( !_has_initial_stress_data ) + if (!_has_initial_stress_data) { GravityForce = true; - cout << "\n ***Excavation simulation: 1. Establish initial stress profile..." << - "\n"; + cout << "\n ***Excavation simulation: 1. Establish initial stress profile..." + << "\n"; counter = 0; Execute(0); } else - UpdateInitialStress(true); // s0 = 0 + UpdateInitialStress(true); // s0 = 0 // Extropolation_GaussValue(); // - cout << "\n ***Excavation simulation: 2. Excavating..." << "\n"; + cout << "\n ***Excavation simulation: 2. Excavating..." + << "\n"; counter = 0; InitializeNewtonSteps(true); GravityForce = false; // ReleaseLoadingByExcavation(); - //GravityForce = true; - UpdateInitialStress(false); // s-->s0 + // GravityForce = true; + UpdateInitialStress(false); // s-->s0 m_msh->ConnectedElements2Node(); for (i = 0; i < m_msh->GetNodesNumber(false); i++) - for(j = 0; j < NS + 1; j++) + for (j = 0; j < NS + 1; j++) SetNodeValue(i, Idx_Strain[j], 0.0); #if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW - if(dom_vector.size() > 0) + if (dom_vector.size() > 0) { bc_node_value_in_dom.clear(); bc_local_index_in_dom.clear(); @@ -1313,7 +1331,7 @@ void CRFProcessDeformation::ResetCouplingStep() long shift = 0; ElementValue_DM* eleV_DM = NULL; for (e = 0; e < (long)m_msh->ele_vector.size(); e++) - if(m_msh->ele_vector[e]->GetMark()) + if (m_msh->ele_vector[e]->GetMark()) { eleV_DM = ele_value_dm[e]; eleV_DM->ResetStress(true); @@ -1322,7 +1340,7 @@ void CRFProcessDeformation::ResetCouplingStep() for (i = 0; i < pcs_number_of_primary_nvals; i++) { number_of_nodes = num_nodes_p_var[i]; - for(j = 0; j < number_of_nodes; j++) + for (j = 0; j < number_of_nodes; j++) SetNodeValue(j, p_var_index[i], ARRAY[shift + j]); shift += number_of_nodes; } @@ -1337,7 +1355,7 @@ void CRFProcessDeformation::ResetTimeStep() long e; ElementValue_DM* eleV_DM = NULL; for (e = 0; e < (long)m_msh->ele_vector.size(); e++) - if(m_msh->ele_vector[e]->GetMark()) + if (m_msh->ele_vector[e]->GetMark()) { eleV_DM = ele_value_dm[e]; eleV_DM->ResetStress(false); @@ -1362,8 +1380,8 @@ void CRFProcessDeformation::SetInitialGuess_EQS_VEC() long number_of_nodes; long shift = 0; double* eqs_x = NULL; -#if defined (USE_PETSC) // || defined (other parallel solver lib). 04.2012 WW - //TODO +#if defined(USE_PETSC) // || defined (other parallel solver lib). 04.2012 WW +// TODO #elif defined(NEW_EQS) eqs_x = eqs_new->x; #else @@ -1373,14 +1391,14 @@ void CRFProcessDeformation::SetInitialGuess_EQS_VEC() { number_of_nodes = num_nodes_p_var[i]; v_idx = p_var_index[i]; - if(i < problem_dimension_dm) + if (i < problem_dimension_dm) { v_idx--; - for(j = 0; j < number_of_nodes; j++) + for (j = 0; j < number_of_nodes; j++) eqs_x[shift + j] = GetNodeValue(j, v_idx); } else - for(j = 0; j < number_of_nodes; j++) + for (j = 0; j < number_of_nodes; j++) eqs_x[shift + j] = 0.; shift += number_of_nodes; } @@ -1413,7 +1431,7 @@ void CRFProcessDeformation::UpdateIterativeStep(const double damp, const int u_t int ColIndex = 0; double* eqs_x = NULL; -#if defined (USE_PETSC) // || defined (other parallel solver lib). 04.2012 WW +#if defined(USE_PETSC) // || defined (other parallel solver lib). 04.2012 WW eqs_x = eqs_new->GetGlobalSolution(); #elif defined(NEW_EQS) eqs_x = eqs_new->x; @@ -1421,52 +1439,50 @@ void CRFProcessDeformation::UpdateIterativeStep(const double damp, const int u_t eqs_x = eqs->x; #endif - if(type == 41 && fem_dm->dynamic) + if (type == 41 && fem_dm->dynamic) { - -#if defined (USE_PETSC) // || defined (other parallel solver lib). 06.2013 WW - //const long size_q = num_nodes_p_var[0]; - const long size_l = num_nodes_p_var[pcs_number_of_primary_nvals-1]; +#if defined(USE_PETSC) // || defined (other parallel solver lib). 06.2013 WW + // const long size_q = num_nodes_p_var[0]; + const long size_l = num_nodes_p_var[pcs_number_of_primary_nvals - 1]; #endif for (i = 0; i < pcs_number_of_primary_nvals; i++) { number_of_nodes = num_nodes_p_var[i]; // - if(u_type == 0) + if (u_type == 0) { ColIndex = p_var_index[i] - 1; - for(j = 0; j < number_of_nodes; j++) + for (j = 0; j < number_of_nodes; j++) { -#if defined (USE_PETSC) // || defined (other parallel solver lib). 06.2013 WW +#if defined(USE_PETSC) // || defined (other parallel solver lib). 06.2013 WW long eqs_r = 0; const long ja = m_msh->Eqs2Global_NodeIndex[j]; - if(j < size_l) + if (j < size_l) eqs_r = pcs_number_of_primary_nvals * ja + i; else { - if( i > problem_dimension_dm) + if (i > problem_dimension_dm) continue; - eqs_r = pcs_number_of_primary_nvals * size_l + problem_dimension_dm * (ja -size_l) + i; + eqs_r = pcs_number_of_primary_nvals * size_l + problem_dimension_dm * (ja - size_l) + i; } const long eqs_row = eqs_r; #else const long eqs_row = j + shift; #endif - SetNodeValue(j,ColIndex, GetNodeValue(j, ColIndex) + eqs_x[eqs_row] * damp); + SetNodeValue(j, ColIndex, GetNodeValue(j, ColIndex) + eqs_x[eqs_row] * damp); } shift += number_of_nodes; } else { ColIndex = p_var_index[i]; - for(j = 0; j < number_of_nodes; j++) - { - SetNodeValue(j,ColIndex, GetNodeValue(j,ColIndex) + - GetNodeValue(j, ColIndex - 1)); - } + for (j = 0; j < number_of_nodes; j++) + { + SetNodeValue(j, ColIndex, GetNodeValue(j, ColIndex) + GetNodeValue(j, ColIndex - 1)); + } } } return; @@ -1479,35 +1495,35 @@ void CRFProcessDeformation::UpdateIterativeStep(const double damp, const int u_t // ColIndex = p_var_index[i] - 1; /// Update Newton step: w = w+dw - if(u_type == 0) + if (u_type == 0) { - for(j = 0; j < number_of_nodes; j++) + for (j = 0; j < number_of_nodes; j++) { -#if defined (USE_PETSC) // || defined (other parallel solver lib). 06.2013 WW - const long eqs_row = problem_dimension_dm * m_msh->Eqs2Global_NodeIndex[j] + i; +#if defined(USE_PETSC) // || defined (other parallel solver lib). 06.2013 WW + const long eqs_row = problem_dimension_dm * m_msh->Eqs2Global_NodeIndex[j] + i; #else const long eqs_row = j + shift; #endif - SetNodeValue(j,ColIndex, GetNodeValue(j, ColIndex) + eqs_x[eqs_row] * damp); + SetNodeValue(j, ColIndex, GetNodeValue(j, ColIndex) + eqs_x[eqs_row] * damp); } shift += number_of_nodes; } else { - for(j = 0; j < number_of_nodes; j++) - SetNodeValue(j,ColIndex + 1, GetNodeValue(j, ColIndex + 1) + GetNodeValue(j,ColIndex)); + for (j = 0; j < number_of_nodes; j++) + SetNodeValue(j, ColIndex + 1, GetNodeValue(j, ColIndex + 1) + GetNodeValue(j, ColIndex)); } } -#if defined (USE_PETSC) // || defined (other parallel solver lib). 06.2013 WW +#if defined(USE_PETSC) // || defined (other parallel solver lib). 06.2013 WW // The node wise storage has already included the following stuff. return; #else - //if(type == 42&&m_num->nls_method>0) //H2M, Newton-Raphson. 06.09.2010. WW - if(type / 10 == 4) //H2M, HM. 28.09.2011. WW + // if(type == 42&&m_num->nls_method>0) //H2M, Newton-Raphson. 06.09.2010. WW + if (type / 10 == 4) // H2M, HM. 28.09.2011. WW { /// $p_{n+1}=p_{n+1}+\Delta p$ is already performed when type = 0 - if(u_type == 1) + if (u_type == 1) return; for (i = problem_dimension_dm; i < pcs_number_of_primary_nvals; i++) @@ -1516,13 +1532,10 @@ void CRFProcessDeformation::UpdateIterativeStep(const double damp, const int u_t // ColIndex = p_var_index[i]; - for(j = 0; j < number_of_nodes; j++) - { - - SetNodeValue(j,ColIndex, GetNodeValue(j, - ColIndex) + - eqs_x[j + shift] * damp); - } + for (j = 0; j < number_of_nodes; j++) + { + SetNodeValue(j, ColIndex, GetNodeValue(j, ColIndex) + eqs_x[j + shift] * damp); + } shift += number_of_nodes; } } @@ -1549,8 +1562,7 @@ void CRFProcessDeformation::UpdateIterativeStep(const double damp, const int u_t 11/2007 WW Change to fit the new equation class 06/2007 WW Rewrite **************************************************************************/ -void CRFProcessDeformation:: -InitializeNewtonSteps(const bool ini_excav) +void CRFProcessDeformation::InitializeNewtonSteps(const bool ini_excav) { long i, j; long number_of_nodes; @@ -1562,11 +1574,11 @@ InitializeNewtonSteps(const bool ini_excav) // /// u_0 = 0 - if(type == 42) // H2M + if (type == 42) // H2M end = problem_dimension_dm; /// Dynamic: plus p_0 = 0 - if(type == 41 && !fem_dm->dynamic) + if (type == 41 && !fem_dm->dynamic) { // p_1 = 0 for (i = 0; i < pcs_number_of_primary_nvals; i++) @@ -1574,14 +1586,14 @@ InitializeNewtonSteps(const bool ini_excav) Col = p_var_index[i]; col0 = Col - 1; number_of_nodes = num_nodes_p_var[i]; - if(i < problem_dimension_dm) + if (i < problem_dimension_dm) for (j = 0; j < number_of_nodes; j++) - //SetNodeValue(j, Col, 0.0); + // SetNodeValue(j, Col, 0.0); SetNodeValue(j, col0, 0.0); else { - if(m_num->nls_method > 0) // If newton. 29.09.2011. WW + if (m_num->nls_method > 0) // If newton. 29.09.2011. WW continue; for (j = 0; j < number_of_nodes; j++) @@ -1598,12 +1610,12 @@ InitializeNewtonSteps(const bool ini_excav) for (j = 0; j < number_of_nodes; j++) SetNodeValue(j, Col, 0.0); - if(fem_dm->dynamic) + if (fem_dm->dynamic) continue; } - } + } /// Excavation: plus u_1 = 0; - if(ini_excav) + if (ini_excav) // p_1 = 0 for (i = 0; i < problem_dimension_dm; i++) { @@ -1641,9 +1653,9 @@ double CRFProcessDeformation::NormOfUpdatedNewton() for (i = 0; i < pcs_number_of_primary_nvals; i++) { number_of_nodes = num_nodes_p_var[i]; - for(j = 0; j < number_of_nodes; j++) + for (j = 0; j < number_of_nodes; j++) { - val = GetNodeValue(j, p_var_index[i] - Colshift); + val = GetNodeValue(j, p_var_index[i] - Colshift); NormW += val * val; } } @@ -1678,9 +1690,8 @@ void CRFProcessDeformation::StoreLastSolution(const int ty) for (i = 0; i < pcs_number_of_primary_nvals; i++) { number_of_nodes = num_nodes_p_var[i]; - for(j = 0; j < number_of_nodes; j++) - ARRAY[shift + j] = - GetNodeValue(j, p_var_index[i] - ty); + for (j = 0; j < number_of_nodes; j++) + ARRAY[shift + j] = GetNodeValue(j, p_var_index[i] - ty); shift += number_of_nodes; } } @@ -1713,33 +1724,33 @@ void CRFProcessDeformation::RecoverSolution(const int ty) end = pcs_number_of_primary_nvals; // If monolithic scheme for p-u coupling, p_i-->p_0 only - if(pcs_deformation % 11 == 0 && ty > 0) + if (pcs_deformation % 11 == 0 && ty > 0) { start = problem_dimension_dm; for (i = 0; i < start; i++) shift += num_nodes_p_var[i]; - //TODO: end = problem_dimension_dm; + // TODO: end = problem_dimension_dm; } for (i = start; i < end; i++) { number_of_nodes = num_nodes_p_var[i]; - idx = p_var_index[i] - Colshift; - for(j = 0; j < number_of_nodes; j++) + idx = p_var_index[i] - Colshift; + for (j = 0; j < number_of_nodes; j++) { - if(ty < 2) + if (ty < 2) { - if(ty == 1) - tem = GetNodeValue(j, idx); + if (ty == 1) + tem = GetNodeValue(j, idx); SetNodeValue(j, idx, ARRAY[shift + j]); - if(ty == 1) + if (ty == 1) ARRAY[shift + j] = tem; } - else if(ty == 2) + else if (ty == 2) { tem = ARRAY[shift + j]; ARRAY[shift + j] = GetNodeValue(j, idx); - SetNodeValue(j, idx, tem); + SetNodeValue(j, idx, tem); } } shift += number_of_nodes; @@ -1770,9 +1781,8 @@ double CRFProcessDeformation::NormOfDisp() for (i = 0; i < pcs_number_of_primary_nvals; i++) { number_of_nodes = num_nodes_p_var[i]; - for(j = 0; j < number_of_nodes; j++) - Norm1 += GetNodeValue(j, p_var_index[i]) - * GetNodeValue(j, p_var_index[i]); + for (j = 0; j < number_of_nodes; j++) + Norm1 += GetNodeValue(j, p_var_index[i]) * GetNodeValue(j, p_var_index[i]); } return Norm1; } @@ -1812,21 +1822,21 @@ double CRFProcessDeformation::NormOfUnkonwn_orRHS(bool isUnknowns) #endif double* vec = NULL; - if(isUnknowns) + if (isUnknowns) vec = eqs->x; else vec = eqs->b; int end = pcs_number_of_primary_nvals; - if(fem_dm->dynamic) + if (fem_dm->dynamic) end = problem_dimension_dm; for (i = 0; i < end; i++) { number_of_nodes = num_nodes_p_var[i]; - for(j = 0; j < number_of_nodes; j++) + for (j = 0; j < number_of_nodes; j++) { - val = vec[v_shift + j]; + val = vec[v_shift + j]; NormW += val * val; } @@ -1860,7 +1870,7 @@ double CRFProcessDeformation::NormOfUnkonwn_orRHS(bool isUnknowns) //#define Modified_B_matrix double CRFProcessDeformation::CaclMaxiumLoadRatio(void) { - int j,gp, gp_r, gp_s; //, gp_t; + int j, gp, gp_r, gp_s; //, gp_t; int PModel = 1; long i = 0; double* dstrain; @@ -1883,12 +1893,12 @@ double CRFProcessDeformation::CaclMaxiumLoadRatio(void) int NGS, NGPS; - //gp_t = 0; + // gp_t = 0; for (i = 0; i < (long)m_msh->ele_vector.size(); i++) { elem = m_msh->ele_vector[i]; - if (elem->GetMark()) // Marked for use + if (elem->GetMark()) // Marked for use { fem_dm->ConfigElement(elem, m_num->ele_gauss_points); fem_dm->SetMaterial(); @@ -1897,54 +1907,53 @@ double CRFProcessDeformation::CaclMaxiumLoadRatio(void) SMat->axisymmetry = m_msh->isAxisymmetry(); PModel = SMat->Plasticity_type; // - switch(PModel) + switch (PModel) { - case 1: + case 1: #ifdef RFW_FRACTURE - SMat->Calculate_Lame_Constant(elem); + SMat->Calculate_Lame_Constant(elem); #endif #ifndef RFW_FRACTURE - SMat->Calculate_Lame_Constant(); + SMat->Calculate_Lame_Constant(); #endif - SMat->ElasticConsitutive(fem_dm->Dim(), fem_dm->De); - SMat->CalulateCoefficent_DP(); - S0 = MSqrt2Over3 * SMat->BetaN * SMat->Y0; - break; - case 2: + SMat->ElasticConsitutive(fem_dm->Dim(), fem_dm->De); + SMat->CalulateCoefficent_DP(); + S0 = MSqrt2Over3 * SMat->BetaN * SMat->Y0; + break; + case 2: #ifdef RFW_FRACTURE - SMat->Calculate_Lame_Constant(elem); + SMat->Calculate_Lame_Constant(elem); #endif #ifndef RFW_FRACTURE - SMat->Calculate_Lame_Constant(); + SMat->Calculate_Lame_Constant(); #endif - SMat->ElasticConsitutive(fem_dm->Dim(), fem_dm->De); - Mat = eleV_DM->MatP; - break; - case 3: - Mat = SMat->data_Plasticity; - S0 = (*Mat)(3); - break; + SMat->ElasticConsitutive(fem_dm->Dim(), fem_dm->De); + Mat = eleV_DM->MatP; + break; + case 3: + Mat = SMat->data_Plasticity; + S0 = (*Mat)(3); + break; } NGS = fem_dm->GetNumGaussPoints(); NGPS = fem_dm->GetNumGaussSamples(); // for (gp = 0; gp < NGS; gp++) { - switch(elem->GetElementType()) + switch (elem->GetElementType()) { - case MshElemType::TRIANGLE: // Triangle - SamplePointTriHQ(gp, fem_dm->unit); - break; - case MshElemType::QUAD: // Quadralateral - gp_r = (int)(gp / NGPS); - gp_s = gp % NGPS; - fem_dm->unit[0] = MXPGaussPkt(NGPS, gp_r); - fem_dm->unit[1] = MXPGaussPkt(NGPS, gp_s); - break; - default: - std::cerr << - "CRFProcessDeformation::CaclMaxiumLoadRatio MshElemType not handled" - << "\n"; + case MshElemType::TRIANGLE: // Triangle + SamplePointTriHQ(gp, fem_dm->unit); + break; + case MshElemType::QUAD: // Quadralateral + gp_r = (int)(gp / NGPS); + gp_s = gp % NGPS; + fem_dm->unit[0] = MXPGaussPkt(NGPS, gp_r); + fem_dm->unit[1] = MXPGaussPkt(NGPS, gp_s); + break; + default: + std::cerr << "CRFProcessDeformation::CaclMaxiumLoadRatio MshElemType not handled" + << "\n"; } fem_dm->computeJacobian(2); fem_dm->ComputeGradShapefct(2); @@ -1952,98 +1961,80 @@ double CRFProcessDeformation::CaclMaxiumLoadRatio(void) dstrain = fem_dm->GetStrain(); - if(PModel == 3) //Cam-Clay + if (PModel == 3) // Cam-Clay { - p0 = ( (*eleV_DM->Stress)(0,gp) - + (*eleV_DM->Stress)(1,gp) - + (*eleV_DM->Stress)(2,gp)) / 3.0; + p0 = ((*eleV_DM->Stress)(0, gp) + (*eleV_DM->Stress)(1, gp) + (*eleV_DM->Stress)(2, gp)) / 3.0; // Swelling index: (*SMat->data_Plasticity)(2) - if(fabs(p0) < MKleinsteZahl) + if (fabs(p0) < MKleinsteZahl) // The initial preconsolidation pressure p0 = (*SMat->data_Plasticity)(3); - SMat->K = - (1.0 + - (*eleV_DM->e_i)(gp)) * fabs(p0) / - (*SMat->data_Plasticity)(2); - SMat->G = 1.5 * SMat->K * - (1 - 2.0 * - SMat->PoissonRatio) / (1 + SMat->PoissonRatio); + SMat->K = (1.0 + (*eleV_DM->e_i)(gp)) * fabs(p0) / (*SMat->data_Plasticity)(2); + SMat->G = 1.5 * SMat->K * (1 - 2.0 * SMat->PoissonRatio) / (1 + SMat->PoissonRatio); SMat->Lambda = SMat->K - 2.0 * SMat->G / 3.0; SMat->ElasticConsitutive(fem_dm->Dim(), fem_dm->De); } // Stress of the previous time step - for(j = 0; j < fem_dm->ns; j++) - fem_dm->dstress[j] = (*eleV_DM->Stress)(j,gp); + for (j = 0; j < fem_dm->ns; j++) + fem_dm->dstress[j] = (*eleV_DM->Stress)(j, gp); // Compute try stress, stress incremental: fem_dm->De->multi(dstrain, fem_dm->dstress); p0 = DeviatoricStress(fem_dm->dstress) / 3.0; - switch(PModel) + switch (PModel) { - case 1: // Drucker-Prager model - EffS = sqrt(TensorMutiplication2(fem_dm->dstress, - fem_dm->dstress, - fem_dm->Dim())) + 3.0 * - SMat->Al * p0; + case 1: // Drucker-Prager model + EffS = sqrt(TensorMutiplication2(fem_dm->dstress, fem_dm->dstress, fem_dm->Dim())) + + 3.0 * SMat->Al * p0; - if(EffS > S0 && EffS > MaxS && fabs(S0) > MKleinsteZahl) - { - MaxS = EffS; - PRatio = MaxS / S0; - } - break; + if (EffS > S0 && EffS > MaxS && fabs(S0) > MKleinsteZahl) + { + MaxS = EffS; + PRatio = MaxS / S0; + } + break; - case 2: // Single yield surface - // Compute try stress, stress incremental: - II = TensorMutiplication2(fem_dm->dstress, - fem_dm->dstress, fem_dm->Dim()); - III = TensorMutiplication3(fem_dm->dstress, - fem_dm->dstress, - fem_dm->dstress, - fem_dm->Dim()); - p0 *= 3.0; - EffS = - sqrt(II * - pow(1.0 + (*Mat)(5) * III / pow(II, - 1.5), - (*Mat)(6)) + 0.5 * (*Mat)(0) * p0 * p0 - + (*Mat)(2) * (*Mat)(2) * p0 * p0 * p0 * - p0) + (*Mat)(1) * p0 + (*Mat)(3) * p0 * p0; - - if(EffS > (*Mat)(4)) - { - if((*Mat)(4) > 0.0) + case 2: // Single yield surface + // Compute try stress, stress incremental: + II = TensorMutiplication2(fem_dm->dstress, fem_dm->dstress, fem_dm->Dim()); + III = TensorMutiplication3(fem_dm->dstress, fem_dm->dstress, fem_dm->dstress, fem_dm->Dim()); + p0 *= 3.0; + EffS + = sqrt(II * pow(1.0 + (*Mat)(5) * III / pow(II, 1.5), (*Mat)(6)) + 0.5 * (*Mat)(0) * p0 * p0 + + (*Mat)(2) * (*Mat)(2) * p0 * p0 * p0 * p0) + + (*Mat)(1) * p0 + (*Mat)(3) * p0 * p0; + + if (EffS > (*Mat)(4)) { - if(EffS > MaxS) - MaxS = EffS; - PRatio = MaxS / (*Mat)(4); - if(PRatio > MaxR) - PRatio = MaxR; + if ((*Mat)(4) > 0.0) + { + if (EffS > MaxS) + MaxS = EffS; + PRatio = MaxS / (*Mat)(4); + if (PRatio > MaxR) + PRatio = MaxR; + } + else + PRatio = EffS; } - else - PRatio = EffS; - } - break; + break; - case 3: // Cam-Clay - II = 1.5 * TensorMutiplication2(fem_dm->dstress, - fem_dm->dstress, - fem_dm->Dim()); - if(S0 > 0.0) - { - EffS = II / (p0 * (*Mat)(0) * (*Mat)(0)) + p0; - if(EffS > S0) - PRatio = EffS / S0; + case 3: // Cam-Clay + II = 1.5 * TensorMutiplication2(fem_dm->dstress, fem_dm->dstress, fem_dm->Dim()); + if (S0 > 0.0) + { + EffS = II / (p0 * (*Mat)(0) * (*Mat)(0)) + p0; + if (EffS > S0) + PRatio = EffS / S0; + else + PRatio = 1.0; + } else PRatio = 1.0; - } - else - PRatio = 1.0; - break; + break; } } } @@ -2081,10 +2072,10 @@ void CRFProcessDeformation::Extropolation_GaussValue() // Clean nodal stresses NS = 4; Idx_Stress[0] = GetNodeValueIndex("STRESS_XX"); - if(m_msh->isAxisymmetry()) // indices are swapped if axisymmetry! + if (m_msh->isAxisymmetry()) // indices are swapped if axisymmetry! { - Idx_Stress[2] = GetNodeValueIndex("STRESS_YY"); - Idx_Stress[1] = GetNodeValueIndex("STRESS_ZZ"); + Idx_Stress[2] = GetNodeValueIndex("STRESS_YY"); + Idx_Stress[1] = GetNodeValueIndex("STRESS_ZZ"); } else { @@ -2092,7 +2083,7 @@ void CRFProcessDeformation::Extropolation_GaussValue() Idx_Stress[2] = GetNodeValueIndex("STRESS_ZZ"); } Idx_Stress[3] = GetNodeValueIndex("STRESS_XY"); - if(problem_dimension_dm == 3) + if (problem_dimension_dm == 3) { NS = 6; Idx_Stress[4] = GetNodeValueIndex("STRESS_XZ"); @@ -2101,7 +2092,7 @@ void CRFProcessDeformation::Extropolation_GaussValue() Idx_Stress[NS] = GetNodeValueIndex("STRAIN_PLS"); NS++; - //NB, TN + // NB, TN int stressPrincipleIndices[3]; stressPrincipleIndices[0] = GetNodeValueIndex("STRESS_1"); @@ -2120,44 +2111,43 @@ void CRFProcessDeformation::Extropolation_GaussValue() PrinStressDirectionIndices[7] = GetNodeValueIndex("NORM_STRESS_3_Y"); PrinStressDirectionIndices[8] = GetNodeValueIndex("NORM_STRESS_3_Z"); - for (i = 0; i < LowOrderNodes; i++) { - for(k = 0; k < NS; k++) - SetNodeValue (i, Idx_Stress[k], 0.0); - for(k = 0; k < 3; k++) - SetNodeValue (i, stressPrincipleIndices[k], 0.0); + for (k = 0; k < NS; k++) + SetNodeValue(i, Idx_Stress[k], 0.0); + for (k = 0; k < 3; k++) + SetNodeValue(i, stressPrincipleIndices[k], 0.0); } for (i = 0; i < (long)m_msh->ele_vector.size(); i++) { elem = m_msh->ele_vector[i]; - if (elem->GetMark()) // Marked for use + if (elem->GetMark()) // Marked for use { fem_dm->ConfigElement(elem, m_num->ele_gauss_points); fem_dm->SetMaterial(); // eval_DM = ele_value_dm[i]; - //TEST (*eval_DM->Stress) += (*eval_DM->Stress0); + // TEST (*eval_DM->Stress) += (*eval_DM->Stress0); fem_dm->ExtropolateGuassStress(); - //TEST if(!update) + // TEST if(!update) // (*eval_DM->Stress) -= (*eval_DM->Stress0); -// calculation of principal stresses for postprocessing on nodes + // calculation of principal stresses for postprocessing on nodes - for (int i=0; innodes; i++) + for (int i = 0; i < fem_dm->nnodes; i++) { // MeshLib::CNode *node; int node_index = fem_dm->nodes[i]; // node = m_msh->nod_vector[node_index]; double stress[6]; - stress[0] = fem_dm->pcs->GetNodeValue(node_index,Idx_Stress[0]); // sigma_xx - stress[1] = fem_dm->pcs->GetNodeValue(node_index,Idx_Stress[1]); // sigma_yy - stress[2] = fem_dm->pcs->GetNodeValue(node_index,Idx_Stress[2]); // sigma_zz - stress[3] = fem_dm->pcs->GetNodeValue(node_index,Idx_Stress[3]); // sigma_xy - if(problem_dimension_dm == 3) - { - stress[4] = fem_dm->pcs->GetNodeValue(node_index,Idx_Stress[4]); // sigma_xz - stress[5] = fem_dm->pcs->GetNodeValue(node_index,Idx_Stress[5]); // sigma_yz - } + stress[0] = fem_dm->pcs->GetNodeValue(node_index, Idx_Stress[0]); // sigma_xx + stress[1] = fem_dm->pcs->GetNodeValue(node_index, Idx_Stress[1]); // sigma_yy + stress[2] = fem_dm->pcs->GetNodeValue(node_index, Idx_Stress[2]); // sigma_zz + stress[3] = fem_dm->pcs->GetNodeValue(node_index, Idx_Stress[3]); // sigma_xy + if (problem_dimension_dm == 3) + { + stress[4] = fem_dm->pcs->GetNodeValue(node_index, Idx_Stress[4]); // sigma_xz + stress[5] = fem_dm->pcs->GetNodeValue(node_index, Idx_Stress[5]); // sigma_yz + } else { stress[4] = 0; // sigma_xz @@ -2166,18 +2156,18 @@ void CRFProcessDeformation::Extropolation_GaussValue() double prin_str[3]; double prin_dir[9]; fem_dm->smat->CalPrinStrDir(stress, prin_str, prin_dir, 3); -// transpose rotation tensor for principal directions - for (size_t i=0; i<3; i++) - fem_dm->pcs->SetNodeValue(node_index,stressPrincipleIndices[i], prin_str[i]); - fem_dm->pcs->SetNodeValue(node_index,PrinStressDirectionIndices[0], prin_dir[0]); - fem_dm->pcs->SetNodeValue(node_index,PrinStressDirectionIndices[1], prin_dir[3]); - fem_dm->pcs->SetNodeValue(node_index,PrinStressDirectionIndices[2], prin_dir[6]); - fem_dm->pcs->SetNodeValue(node_index,PrinStressDirectionIndices[3], prin_dir[1]); - fem_dm->pcs->SetNodeValue(node_index,PrinStressDirectionIndices[4], prin_dir[4]); - fem_dm->pcs->SetNodeValue(node_index,PrinStressDirectionIndices[5], prin_dir[7]); - fem_dm->pcs->SetNodeValue(node_index,PrinStressDirectionIndices[6], prin_dir[2]); - fem_dm->pcs->SetNodeValue(node_index,PrinStressDirectionIndices[7], prin_dir[5]); - fem_dm->pcs->SetNodeValue(node_index,PrinStressDirectionIndices[8], prin_dir[8]); + // transpose rotation tensor for principal directions + for (size_t i = 0; i < 3; i++) + fem_dm->pcs->SetNodeValue(node_index, stressPrincipleIndices[i], prin_str[i]); + fem_dm->pcs->SetNodeValue(node_index, PrinStressDirectionIndices[0], prin_dir[0]); + fem_dm->pcs->SetNodeValue(node_index, PrinStressDirectionIndices[1], prin_dir[3]); + fem_dm->pcs->SetNodeValue(node_index, PrinStressDirectionIndices[2], prin_dir[6]); + fem_dm->pcs->SetNodeValue(node_index, PrinStressDirectionIndices[3], prin_dir[1]); + fem_dm->pcs->SetNodeValue(node_index, PrinStressDirectionIndices[4], prin_dir[4]); + fem_dm->pcs->SetNodeValue(node_index, PrinStressDirectionIndices[5], prin_dir[7]); + fem_dm->pcs->SetNodeValue(node_index, PrinStressDirectionIndices[6], prin_dir[2]); + fem_dm->pcs->SetNodeValue(node_index, PrinStressDirectionIndices[7], prin_dir[5]); + fem_dm->pcs->SetNodeValue(node_index, PrinStressDirectionIndices[8], prin_dir[8]); } } } @@ -2188,24 +2178,24 @@ void CRFProcessDeformation::Extropolation_GaussValue() --------------------------------------------------------------------------*/ void CRFProcessDeformation::Trace_Discontinuity() { - long k,l; + long k, l; int i, nn, Size, bFaces, bFacesCounter, intP; int b_node_counter; int locEleFound, numf, nPathNodes; - bool thisLoop; //, neighborSeed; + bool thisLoop; //, neighborSeed; - //Element value + // Element value ElementValue_DM* eleV_DM; static double xn[20], yn[20], zn[20]; - static double xa[3], xb[3], n[3],ts[3]; - double v1,v2; + static double xa[3], xb[3], n[3], ts[3]; + double v1, v2; int FNodes0[8]; std::vector SeedElement; locEleFound = 0; - nPathNodes = 2; //2D element + nPathNodes = 2; // 2D element bFaces = 0; intP = 0; @@ -2215,25 +2205,25 @@ void CRFProcessDeformation::Trace_Discontinuity() for (l = 0; l < (long)m_msh->ele_vector.size(); l++) { elem = m_msh->ele_vector[l]; - if (elem->GetMark()) // Marked for use + if (elem->GetMark()) // Marked for use - if(fem_dm->LocalAssembly_CheckLocalization(elem)) + if (fem_dm->LocalAssembly_CheckLocalization(elem)) { locEleFound++; // If this is first bifurcated element, call them as seeds - if(!Localizing) + if (!Localizing) SeedElement.push_back(l); } } - if(locEleFound > 0 && !Localizing) // Bifurcation inception + if (locEleFound > 0 && !Localizing) // Bifurcation inception { - //TEST - //mesh1 de =23; - //mesh2_iregular de = 76 - //mesh coarst de = 5; - //mesh quad de=23 - //crack tri de=0 + // TEST + // mesh1 de =23; + // mesh2_iregular de = 76 + // mesh coarst de = 5; + // mesh quad de=23 + // crack tri de=0 /* SeedElement.clear(); @@ -2241,11 +2231,11 @@ void CRFProcessDeformation::Trace_Discontinuity() SeedElement.push_back(de); */ - //TEST + // TEST // Determine the seed element Size = (long)SeedElement.size(); - for(l = 0; l < Size; l++) + for (l = 0; l < Size; l++) { k = SeedElement[l]; elem = m_msh->ele_vector[k]; @@ -2253,7 +2243,7 @@ void CRFProcessDeformation::Trace_Discontinuity() numf = elem->GetFacesNumber(); eleV_DM = ele_value_dm[k]; - //If seed element are neighbor. Choose one + // If seed element are neighbor. Choose one /*//TEST neighborSeed = false; for(m=0; mGetNodesNumber(true); - for(i = 0; i < nn; i++) + for (i = 0; i < nn; i++) { // Coordinates of all element nodes -// xn[i] = elem->nodes[i]->X(); -// yn[i] = elem->nodes[i]->Y(); -// zn[i] = elem->nodes[i]->Z(); - double const* const coords (elem->nodes[i]->getData()); + // xn[i] = elem->nodes[i]->X(); + // yn[i] = elem->nodes[i]->Y(); + // zn[i] = elem->nodes[i]->Z(); + double const* const coords(elem->nodes[i]->getData()); xn[i] = coords[0]; yn[i] = coords[1]; zn[i] = coords[2]; @@ -2291,24 +2281,24 @@ void CRFProcessDeformation::Trace_Discontinuity() // Elements which have one only boundary face are chosen as seed element bFaces = -1; bFacesCounter = 0; - for(i = 0; i < numf; i++) - if(elem->neighbors[i]->GetDimension() != elem->GetDimension()) + for (i = 0; i < numf; i++) + if (elem->neighbors[i]->GetDimension() != elem->GetDimension()) { bFaces = i; bFacesCounter++; } // Elements which have only one boundary face or one boundary node are chosen as seed element - if(bFacesCounter != 1) + if (bFacesCounter != 1) { // b_node_counter = 0; - for(i = 0; i < elem->GetVertexNumber(); i++) + for (i = 0; i < elem->GetVertexNumber(); i++) { bFaces = i; b_node_counter++; } - if(b_node_counter != 1) + if (b_node_counter != 1) { eleV_DM->Localized = false; delete eleV_DM->orientation; @@ -2318,43 +2308,39 @@ void CRFProcessDeformation::Trace_Discontinuity() } fem_dm->ConfigElement(elem, m_num->ele_gauss_points); - //2D + // 2D elem->GetElementFaceNodes(bFaces, FNodes0); - if (elem->GetElementType() == MshElemType::QUAD || - elem->GetElementType() == MshElemType::TRIANGLE) + if (elem->GetElementType() == MshElemType::QUAD || elem->GetElementType() == MshElemType::TRIANGLE) nPathNodes = 2; // Locate memory for points on the path of this element eleV_DM->NodesOnPath = new Matrix(3, nPathNodes); *eleV_DM->NodesOnPath = 0.0; - if(nPathNodes == 2) // 2D + if (nPathNodes == 2) // 2D { // Departure point - (*eleV_DM->NodesOnPath)(0, - 0) = 0.5 * (xn[FNodes0[0]] + xn[FNodes0[1]]); - (*eleV_DM->NodesOnPath)(1, - 0) = 0.5 * (yn[FNodes0[0]] + yn[FNodes0[1]]); - (*eleV_DM->NodesOnPath)(2, - 0) = 0.5 * (zn[FNodes0[0]] + zn[FNodes0[1]]); + (*eleV_DM->NodesOnPath)(0, 0) = 0.5 * (xn[FNodes0[0]] + xn[FNodes0[1]]); + (*eleV_DM->NodesOnPath)(1, 0) = 0.5 * (yn[FNodes0[0]] + yn[FNodes0[1]]); + (*eleV_DM->NodesOnPath)(2, 0) = 0.5 * (zn[FNodes0[0]] + zn[FNodes0[1]]); - xa[0] = (*eleV_DM->NodesOnPath)(0,0); - xa[1] = (*eleV_DM->NodesOnPath)(1,0); - xa[2] = (*eleV_DM->NodesOnPath)(2,0); + xa[0] = (*eleV_DM->NodesOnPath)(0, 0); + xa[1] = (*eleV_DM->NodesOnPath)(1, 0); + xa[2] = (*eleV_DM->NodesOnPath)(2, 0); // Check oreintation again. ts[0] = xn[FNodes0[1]] - xn[FNodes0[0]]; ts[1] = yn[FNodes0[1]] - yn[FNodes0[0]]; - //ts[2] = zn[FNodes0[1]]-zn[FNodes0[0]]; + // ts[2] = zn[FNodes0[1]]-zn[FNodes0[0]]; v1 = sqrt(ts[0] * ts[0] + ts[1] * ts[1]); ts[0] /= v1; ts[1] /= v1; n[0] = cos(eleV_DM->orientation[0]); n[1] = sin(eleV_DM->orientation[0]); - v1 = n[0] * ts[0] + n[1] * ts[1]; + v1 = n[0] * ts[0] + n[1] * ts[1]; n[0] = cos(eleV_DM->orientation[1]); n[1] = sin(eleV_DM->orientation[1]); - v2 = n[0] * ts[0] + n[1] * ts[1]; - if(fabs(v2) > fabs(v1)) + v2 = n[0] * ts[0] + n[1] * ts[1]; + if (fabs(v2) > fabs(v1)) { v1 = eleV_DM->orientation[0]; eleV_DM->orientation[0] = eleV_DM->orientation[1]; @@ -2363,9 +2349,9 @@ void CRFProcessDeformation::Trace_Discontinuity() intP = fem_dm->IntersectionPoint(bFaces, xa, xb); - (*eleV_DM->NodesOnPath)(0,1) = xb[0]; - (*eleV_DM->NodesOnPath)(1,1) = xb[1]; - (*eleV_DM->NodesOnPath)(2,1) = xb[2]; + (*eleV_DM->NodesOnPath)(0, 1) = xb[0]; + (*eleV_DM->NodesOnPath)(1, 1) = xb[1]; + (*eleV_DM->NodesOnPath)(2, 1) = xb[2]; } // Last element to this seed @@ -2382,38 +2368,38 @@ void CRFProcessDeformation::Trace_Discontinuity() } // Seek path from the last bifurcated element of corrsponding seeds. - if(Localizing) + if (Localizing) { Size = (long)LastElement.size(); - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) { thisLoop = true; - while(thisLoop) + while (thisLoop) { nn = MarkBifurcatedNeighbor(i); - if(nn < 0) + if (nn < 0) break; ElementOnPath.push_back(nn); } } Size = (long)ElementOnPath.size(); - for(l = 0; l < (long)m_msh->ele_vector.size(); l++) + for (l = 0; l < (long)m_msh->ele_vector.size(); l++) { elem = m_msh->ele_vector[l]; if (elem->GetMark()) // Marked for use { eleV_DM = ele_value_dm[l]; - if(eleV_DM->Localized) + if (eleV_DM->Localized) { thisLoop = false; - for(k = 0; k < Size; k++) - if(l == ElementOnPath[k]) + for (k = 0; k < Size; k++) + if (l == ElementOnPath[k]) { thisLoop = true; break; } - if(!thisLoop) + if (!thisLoop) { eleV_DM->Localized = false; delete eleV_DM->orientation; @@ -2425,17 +2411,17 @@ void CRFProcessDeformation::Trace_Discontinuity() } } -//WW +// WW long CRFProcessDeformation::MarkBifurcatedNeighbor(const int PathIndex) { int j; - int f1, f2, nb, numf1; + int f1, f2, nb, numf1; long index, Extended; bool adjacent, onPath; - ElementValue_DM* eleV_DM, * eleV_DM1; + ElementValue_DM *eleV_DM, *eleV_DM1; DisElement* disEle; - static double n1[2],n2[2], xA[3],xB[3]; - //WW static int Face_node[8]; // Only 2D + static double n1[2], n2[2], xA[3], xB[3]; + // WW static int Face_node[8]; // Only 2D MeshLib::CElem* elem; MeshLib::CElem* elem1; @@ -2455,45 +2441,45 @@ long CRFProcessDeformation::MarkBifurcatedNeighbor(const int PathIndex) n1[0] = cos(eleV_DM->orientation[0]); n1[1] = sin(eleV_DM->orientation[0]); - xA[0] = (*eleV_DM->NodesOnPath)(0,1); - xA[1] = (*eleV_DM->NodesOnPath)(1,1); - xA[2] = (*eleV_DM->NodesOnPath)(2,1); + xA[0] = (*eleV_DM->NodesOnPath)(0, 1); + xA[1] = (*eleV_DM->NodesOnPath)(1, 1); + xA[2] = (*eleV_DM->NodesOnPath)(2, 1); - //nfnode = elem->GetElementFaceNodes(f1, Face_node); + // nfnode = elem->GetElementFaceNodes(f1, Face_node); // Check discintinuity path goes to which neighbor elem1 = elem->neighbors[f1]; // Boundary reached - if(elem1->GetDimension() != elem->GetDimension()) + if (elem1->GetDimension() != elem->GetDimension()) return -1; nb = elem1->GetIndex(); // Check if the element is already in discontinuity line/surface onPath = false; - for(j = 0; j < (int)ElementOnPath.size(); j++) - if(nb == ElementOnPath[j]) + for (j = 0; j < (int)ElementOnPath.size(); j++) + if (nb == ElementOnPath[j]) { onPath = true; break; } // If has neighbor and it is not on the discontinuity surface. - if(!onPath) // Has neighbor - if(ele_value_dm[nb]->Localized) + if (!onPath) // Has neighbor + if (ele_value_dm[nb]->Localized) { - //TEST OUT - //cout <<" element on track " <GetFacesNumber(); eleV_DM1 = ele_value_dm[nb]; fem_dm->ConfigElement(elem1, m_num->ele_gauss_points); // Search faces of neighbor's neighbors - for(j = 0; j < numf1; j++) + for (j = 0; j < numf1; j++) { // Neighbor is a face on surface - if(elem1->neighbors[j]->GetDimension() != elem1->GetDimension()) + if (elem1->neighbors[j]->GetDimension() != elem1->GetDimension()) continue; - if((size_t)index != elem1->neighbors[j]->GetIndex()) + if ((size_t)index != elem1->neighbors[j]->GetIndex()) continue; { adjacent = true; @@ -2505,7 +2491,7 @@ long CRFProcessDeformation::MarkBifurcatedNeighbor(const int PathIndex) n2[0] = cos(eleV_DM1->orientation[1]); n2[1] = sin(eleV_DM1->orientation[1]); pd2 = n1[0] * n2[0] + n1[1] * n2[1]; - if(pd2 > pd1) // Always use the first entry of orientation + if (pd2 > pd1) // Always use the first entry of orientation { // Swap the values pd1 = eleV_DM1->orientation[1]; @@ -2516,12 +2502,12 @@ long CRFProcessDeformation::MarkBifurcatedNeighbor(const int PathIndex) *eleV_DM1->NodesOnPath = 0.0; // Get another intersection point f2 = fem_dm->IntersectionPoint(j, xA, xB); - (*eleV_DM1->NodesOnPath)(0,0) = xA[0]; - (*eleV_DM1->NodesOnPath)(1,0) = xA[1]; - (*eleV_DM1->NodesOnPath)(2,0) = xA[2]; - (*eleV_DM1->NodesOnPath)(0,1) = xB[0]; - (*eleV_DM1->NodesOnPath)(1,1) = xB[1]; - (*eleV_DM1->NodesOnPath)(2,1) = xB[2]; + (*eleV_DM1->NodesOnPath)(0, 0) = xA[0]; + (*eleV_DM1->NodesOnPath)(1, 0) = xA[1]; + (*eleV_DM1->NodesOnPath)(2, 0) = xA[2]; + (*eleV_DM1->NodesOnPath)(0, 1) = xB[0]; + (*eleV_DM1->NodesOnPath)(1, 1) = xB[1]; + (*eleV_DM1->NodesOnPath)(2, 1) = xB[2]; // Last element disEle->ElementIndex = nb; @@ -2533,7 +2519,7 @@ long CRFProcessDeformation::MarkBifurcatedNeighbor(const int PathIndex) // If not on the discontinuity surface // Release memory - if(!adjacent) + if (!adjacent) { delete eleV_DM1->orientation; eleV_DM1->orientation = NULL; @@ -2552,7 +2538,7 @@ long CRFProcessDeformation::MarkBifurcatedNeighbor(const int PathIndex) 04/2006 WW **************************************************************************/ #if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW -void CRFProcessDeformation:: DomainAssembly(CPARDomain* m_dom) +void CRFProcessDeformation::DomainAssembly(CPARDomain* m_dom) { long i; MeshLib::CElem* elem = NULL; @@ -2565,20 +2551,20 @@ void CRFProcessDeformation:: DomainAssembly(CPARDomain* m_dom) for (i = 0; i < (long)m_dom->elements.size(); i++) { elem = m_msh->ele_vector[m_dom->elements[i]]; - if (elem->GetMark()) // Marked for use + if (elem->GetMark()) // Marked for use { elem->SetOrder(true); - //WW + // WW fem_dm->SetElementNodesDomain(m_dom->element_nodes_dom[i]); fem_dm->ConfigElement(elem, m_num->ele_gauss_points); fem_dm->m_dom = m_dom; fem_dm->LocalAssembly(0); } } - if(type == 41) // p-u monolithic scheme + if (type == 41) // p-u monolithic scheme { - if(!fem_dm->dynamic) - RecoverSolution(1); // p_i-->p_0 + if (!fem_dm->dynamic) + RecoverSolution(1); // p_i-->p_0 // 2. // Assemble pressure eqs for (i = 0; i < (long)m_msh->ele_vector.size(); i++) @@ -2587,15 +2573,15 @@ void CRFProcessDeformation:: DomainAssembly(CPARDomain* m_dom) if (elem->GetMark()) // Marked for use { elem->SetOrder(false); - //WW + // WW fem->SetElementNodesDomain(m_dom->element_nodes_dom[i]); fem->ConfigElement(elem, m_num->ele_gauss_points); fem->m_dom = m_dom; fem->Assembly(); } } - if(!fem_dm->dynamic) - RecoverSolution(2); // p_i-->p_0 + if (!fem_dm->dynamic) + RecoverSolution(2); // p_i-->p_0 } /* @@ -2624,9 +2610,9 @@ void CRFProcessDeformation::GlobalAssembly() { #if !defined(USE_PETSC) // && !defined(other parallel libs)//10.3012. WW #ifdef USE_MPI - if(dom_vector.size() > 0) + if (dom_vector.size() > 0) { - std::cout << " Domain Decomposition " << myrank << '\n'; + std::cout << " Domain Decomposition " << myrank << '\n'; CPARDomain* m_dom = NULL; m_dom = dom_vector[myrank]; @@ -2653,16 +2639,16 @@ void CRFProcessDeformation::GlobalAssembly() // Assemble global system // DDCAssembleGlobalMatrix(); - //MXDumpGLS("rf_pcs.txt",1,eqs->b,eqs->x); + // MXDumpGLS("rf_pcs.txt",1,eqs->b,eqs->x); } #else // ifdef USE_MPI //---------------------------------------------------------------------- // DDC - if(dom_vector.size() > 0) + if (dom_vector.size() > 0) { cout << " Domain Decomposition" << '\n'; CPARDomain* m_dom = NULL; - for(int j = 0; j < (int)dom_vector.size(); j++) + for (int j = 0; j < (int)dom_vector.size(); j++) { m_dom = dom_vector[j]; DomainAssembly(m_dom); @@ -2679,7 +2665,7 @@ void CRFProcessDeformation::GlobalAssembly() // eqs_new->Write(Dum); // Dum.close(); - //MXDumpGLS("rf_pcs1.txt",1,eqs->b,eqs->x); abort(); + // MXDumpGLS("rf_pcs1.txt",1,eqs->b,eqs->x); abort(); } #endif //---------------------------------------------------------------------- @@ -2689,7 +2675,7 @@ void CRFProcessDeformation::GlobalAssembly() { GlobalAssembly_DM(); - if(type / 10 == 4) // p-u monolithic scheme + if (type / 10 == 4) // p-u monolithic scheme // if(!fem_dm->dynamic) /// // RecoverSolution(1); // p_i-->p_0 @@ -2714,41 +2700,41 @@ void CRFProcessDeformation::GlobalAssembly() // Apply Neumann BC IncorporateSourceTerms(); -#if defined(USE_PETSC) // || defined(other parallel libs)//05.3013. +#if defined(USE_PETSC) // || defined(other parallel libs)//05.3013. eqs_new->AssembleRHS_PETSc(); - eqs_new->AssembleMatrixPETSc(MAT_FINAL_ASSEMBLY ); + eqs_new->AssembleMatrixPETSc(MAT_FINAL_ASSEMBLY); #endif - //DumpEqs("rf_pcs2.txt"); + // DumpEqs("rf_pcs2.txt"); // { MXDumpGLS("rf_pcs1.txt",1,eqs->b,eqs->x); // abort();} /// If not JFNK or if JFNK but the Newton step is greater than one. 11.11.2010. WW - if(!(m_num->nls_method == 2 && ite_steps == 1)) + if (!(m_num->nls_method == 2 && ite_steps == 1)) { // Apply Dirchlete bounday condition - if(!fem_dm->dynamic) + if (!fem_dm->dynamic) IncorporateBoundaryConditions(); else CalcBC_or_SecondaryVariable_Dynamics(true); } - // { MXDumpGLS("rf_pcs1.txt",1,eqs->b,eqs->x); //abort();} - // +// { MXDumpGLS("rf_pcs1.txt",1,eqs->b,eqs->x); //abort();} +// #define atest_dump #ifdef test_dump string fname = FileName + "rf_pcs_omp.txt"; ofstream Dum1(fname.c_str(), ios::out); // WW eqs_new->Write(Dum1); - Dum1.close(); // abort(); + Dum1.close(); // abort(); #endif -#define atest_bin_dump -#ifdef test_bin_dump //WW +#define atest_bin_dump +#ifdef test_bin_dump // WW string fname = FileName + ".eqiation_binary.bin"; ofstream Dum1(fname.data(), ios::out | ios::binary | ios::trunc); - if(Dum1.good()) + if (Dum1.good()) eqs_new->Write_BIN(Dum1); Dum1.close(); #endif @@ -2772,7 +2758,7 @@ void CRFProcessDeformation::GlobalAssembly_DM() for (i = 0; i < (long)m_msh->ele_vector.size(); i++) { elem = m_msh->ele_vector[i]; - if (!elem->GetMark()) // Marked for use + if (!elem->GetMark()) // Marked for use continue; elem->SetOrder(true); @@ -2790,65 +2776,65 @@ Task: post process for excavation void CRFProcessDeformation::PostExcavation() { std::vector deact_dom; - //PCS_ExcavState = -1; + // PCS_ExcavState = -1; bool now_Excav = false; - MeshLib::CElem *elem = NULL; - MeshLib::CNode *node = NULL; - for(size_t l=0; lexcavated) + if (msp_vector[l]->excavated) deact_dom.push_back(l); } - //if(ExcavMaterialGroup>=0&&PCS_ExcavState<0) //WX:01.2010.update pcs excav state - if(ExcavMaterialGroup>=0) + // if(ExcavMaterialGroup>=0&&PCS_ExcavState<0) //WX:01.2010.update pcs excav state + if (ExcavMaterialGroup >= 0) { - for(size_t l=0; lele_vector.size();l++) + for (size_t l = 0; l < m_msh->ele_vector.size(); l++) { - //if((m_msh->ele_vector[l]->GetExcavState()>0)&&!(m_msh->ele_vector[l]->GetMark()))//WX:07.2011 HM excav - if(ExcavMaterialGroup == static_cast(m_msh->ele_vector[l]->GetPatchIndex())) + // if((m_msh->ele_vector[l]->GetExcavState()>0)&&!(m_msh->ele_vector[l]->GetMark()))//WX:07.2011 HM excav + if (ExcavMaterialGroup == static_cast(m_msh->ele_vector[l]->GetPatchIndex())) { - if((m_msh->ele_vector[l]->GetExcavState()>-1)&&m_msh->ele_vector[l]->GetMark()) + if ((m_msh->ele_vector[l]->GetExcavState() > -1) && m_msh->ele_vector[l]->GetMark()) { - if(m_msh->ele_vector[l]->GetExcavState()==1) - m_msh->ele_vector[l]->SetExcavState(0);//1=now, 0=past - PCS_ExcavState = 1;//not necessary - now_Excav = true;//new elems are excavated at this time step - //break; + if (m_msh->ele_vector[l]->GetExcavState() == 1) + m_msh->ele_vector[l]->SetExcavState(0); // 1=now, 0=past + PCS_ExcavState = 1; // not necessary + now_Excav = true; // new elems are excavated at this time step + // break; } } } } - if(deact_dom.size() > 0 || now_Excav) //WX:01.2011 modified for coupled excavation + if (deact_dom.size() > 0 || now_Excav) // WX:01.2011 modified for coupled excavation { // MXDumpGLS("rf_pcs.txt",1,eqs->b,eqs->x); //abort();} // 07.04.2010 WW bool done; - ElementValue_DM *eleV_DM = NULL; - if((fem_dm->Flow_Type==0||fem_dm->Flow_Type==2||fem_dm->Flow_Type==1)&&Neglect_H_ini==2) + ElementValue_DM* eleV_DM = NULL; + if ((fem_dm->Flow_Type == 0 || fem_dm->Flow_Type == 2 || fem_dm->Flow_Type == 1) && Neglect_H_ini == 2) { - int tmp_type, idx_p1_ini, idx_p2_ini, idx_p1_1, idx_p2_1;//, idx_sw_1;//idx_sw_ini, - CRFProcess *h_pcs=NULL; + int tmp_type, idx_p1_ini, idx_p2_ini, idx_p1_1, idx_p2_1; //, idx_sw_1;//idx_sw_ini, + CRFProcess* h_pcs = NULL; h_pcs = fem_dm->h_pcs; tmp_type = h_pcs->type; idx_p1_ini = h_pcs->GetNodeValueIndex("PRESSURE1_Ini"); - idx_p1_1 = h_pcs->GetNodeValueIndex("PRESSURE1")+1; - if(tmp_type==1212) + idx_p1_1 = h_pcs->GetNodeValueIndex("PRESSURE1") + 1; + if (tmp_type == 1212) { idx_p2_ini = h_pcs->GetNodeValueIndex("PRESSURE2_Ini"); - //idx_sw_ini = h_pcs->GetNodeValueIndex("SATURATION1_Ini"); - idx_p2_1 = h_pcs->GetNodeValueIndex("PRESSURE2")+1; - //idx_sw_1 = h_pcs->GetNodeValueIndex("SATURATION1")+1; + // idx_sw_ini = h_pcs->GetNodeValueIndex("SATURATION1_Ini"); + idx_p2_1 = h_pcs->GetNodeValueIndex("PRESSURE2") + 1; + // idx_sw_1 = h_pcs->GetNodeValueIndex("SATURATION1")+1; } - for(size_t i=0; iGetNodesNumber(false); i++) + for (size_t i = 0; i < m_msh->GetNodesNumber(false); i++) { - //if(tmp_type==1)//LiquideFlow, RichardsFlow, MultiPhaseFlow + // if(tmp_type==1)//LiquideFlow, RichardsFlow, MultiPhaseFlow h_pcs->SetNodeValue(i, idx_p1_ini, h_pcs->GetNodeValue(i, idx_p1_1)); - if (tmp_type==1212) + if (tmp_type == 1212) { - //h_pcs->SetNodeValue(i, idx_p1_ini, h_pcs->GetNodeValue(i, idx_p1_1)); + // h_pcs->SetNodeValue(i, idx_p1_ini, h_pcs->GetNodeValue(i, idx_p1_1)); h_pcs->SetNodeValue(i, idx_p2_ini, h_pcs->GetNodeValue(i, idx_p2_1)); - //h_pcs->SetNodeValue(i, idx_sw_ini, h_pcs->GetNodeValue(i, idx_sw_1)); + // h_pcs->SetNodeValue(i, idx_sw_ini, h_pcs->GetNodeValue(i, idx_sw_1)); } } } @@ -2856,42 +2842,46 @@ void CRFProcessDeformation::PostExcavation() { eleV_DM = ele_value_dm[l]; // - (*eleV_DM->Stress0) = (*eleV_DM->Stress);//if not assembly the excavated eles in next time step + (*eleV_DM->Stress0) = (*eleV_DM->Stress); // if not assembly the excavated eles in next time step // elem = m_msh->ele_vector[l]; done = false; - for(size_t i=0; iGetPatchIndex() == static_cast(deact_dom[i])) + if (elem->GetPatchIndex() == static_cast(deact_dom[i])) { elem->MarkingAll(false); *(eleV_DM->Stress) = 0.; *(eleV_DM->Stress0) = 0.; - if (eleV_DM->Stress_j) (*eleV_DM->Stress_j) = 0.0; - if (eleV_DM->Stress_i) (*eleV_DM->Stress_i) = 0.0; + if (eleV_DM->Stress_j) + (*eleV_DM->Stress_j) = 0.0; + if (eleV_DM->Stress_i) + (*eleV_DM->Stress_i) = 0.0; done = true; break; } } - if(ExcavMaterialGroup>=0)//WX + if (ExcavMaterialGroup >= 0) // WX { - if(elem->GetExcavState()>=0) + if (elem->GetExcavState() >= 0) { elem->MarkingAll(false); - //if update stress0 + // if update stress0 (*eleV_DM->Stress) = 0.; (*eleV_DM->Stress0) = 0.; - if (eleV_DM->Stress_j) (*eleV_DM->Stress_j) = 0.0; - if (eleV_DM->Stress_i) (*eleV_DM->Stress_i) = 0.0; + if (eleV_DM->Stress_j) + (*eleV_DM->Stress_j) = 0.0; + if (eleV_DM->Stress_i) + (*eleV_DM->Stress_i) = 0.0; // done = true; } } - if(hasAnyProcessDeactivatedSubdomains)//WX:11.2012 if there is deactivated subdomain when excavated + if (hasAnyProcessDeactivatedSubdomains) // WX:11.2012 if there is deactivated subdomain when excavated { - for(int i=0; iGetPatchIndex() == static_cast(Deactivated_SubDomain[i])) + if (elem->GetPatchIndex() == static_cast(Deactivated_SubDomain[i])) { elem->MarkingAll(false); done = true; @@ -2899,62 +2889,63 @@ void CRFProcessDeformation::PostExcavation() } } } - if(done) + if (done) continue; else elem->MarkingAll(true); } - size_t mesh_node_vector_size (m_msh->nod_vector.size()); + size_t mesh_node_vector_size(m_msh->nod_vector.size()); for (size_t l = 0; l < mesh_node_vector_size; l++) { - while(m_msh->nod_vector[l]->getConnectedElementIDs().size()) + while (m_msh->nod_vector[l]->getConnectedElementIDs().size()) m_msh->nod_vector[l]->getConnectedElementIDs().pop_back(); } - //for (size_t l = 0; l < mesh_node_vector_size; l++) - size_t mesh_ele_vector_size (m_msh->ele_vector.size()); - for (size_t l = 0; l < mesh_ele_vector_size; l++)//WX: 07.2011 + // for (size_t l = 0; l < mesh_node_vector_size; l++) + size_t mesh_ele_vector_size(m_msh->ele_vector.size()); + for (size_t l = 0; l < mesh_ele_vector_size; l++) // WX: 07.2011 { elem = m_msh->ele_vector[l]; - if(!elem->GetMark()) continue; - //for(size_t i=0; iGetNodesNumber(m_msh->getOrder()); i++) - for(size_t i=0; iGetNodesNumber(1); i++)//WX:10.2011 change for one way coup. M->H + if (!elem->GetMark()) + continue; + // for(size_t i=0; iGetNodesNumber(m_msh->getOrder()); i++) + for (size_t i = 0; i < elem->GetNodesNumber(1); i++) // WX:10.2011 change for one way coup. M->H { done = false; node = elem->GetNode(i); - for(size_t j=0; jgetConnectedElementIDs().size(); j++) + for (size_t j = 0; j < node->getConnectedElementIDs().size(); j++) { - if(l==node->getConnectedElementIDs()[j]) + if (l == node->getConnectedElementIDs()[j]) { done = true; break; } } - if(!done) + if (!done) node->getConnectedElementIDs().push_back(l); } } - if(Neglect_H_ini == 1)//WX:04.2013 + if (Neglect_H_ini == 1) // WX:04.2013 CalIniTotalStress(); } - //WX:10.2011 strain update for excavated node, the excavated node Strain = 0 + // WX:10.2011 strain update for excavated node, the excavated node Strain = 0 int Idx_Strain[6]; Idx_Strain[0] = GetNodeValueIndex("STRAIN_XX"); Idx_Strain[1] = GetNodeValueIndex("STRAIN_YY"); Idx_Strain[2] = GetNodeValueIndex("STRAIN_ZZ"); Idx_Strain[3] = GetNodeValueIndex("STRAIN_XY"); - if(problem_dimension_dm==3) + if (problem_dimension_dm == 3) { Idx_Strain[4] = GetNodeValueIndex("STRAIN_XZ"); Idx_Strain[5] = GetNodeValueIndex("STRAIN_YZ"); } - for(size_t i=0; iGetNodesNumber(false); i++) + for (size_t i = 0; i < m_msh->GetNodesNumber(false); i++) { node = m_msh->nod_vector[i]; - if(node->getConnectedElementIDs().size()==0) - for(int ii=0; ii<(2*problem_dimension_dm); ii++) - fem_dm->pcs->SetNodeValue(i,Idx_Strain[ii],0); + if (node->getConnectedElementIDs().size() == 0) + for (int ii = 0; ii < (2 * problem_dimension_dm); ii++) + fem_dm->pcs->SetNodeValue(i, Idx_Strain[ii], 0); } return; } @@ -2968,39 +2959,39 @@ void CRFProcessDeformation::UpdateIniStateValue() { for (size_t l = 0; l < m_msh->ele_vector.size(); l++) { - ElementValue_DM *eleV_DM = NULL; + ElementValue_DM* eleV_DM = NULL; eleV_DM = ele_value_dm[l]; // - (*eleV_DM->Stress0) = (*eleV_DM->Stress); + (*eleV_DM->Stress0) = (*eleV_DM->Stress); } - if(Neglect_H_ini == 1) + if (Neglect_H_ini == 1) CalIniTotalStress(); - if((fem_dm->Flow_Type==0||fem_dm->Flow_Type==1||fem_dm->Flow_Type==2 )&&Neglect_H_ini==2) + if ((fem_dm->Flow_Type == 0 || fem_dm->Flow_Type == 1 || fem_dm->Flow_Type == 2) && Neglect_H_ini == 2) { int tmp_type; - CRFProcess *h_pcs=NULL; + CRFProcess* h_pcs = NULL; h_pcs = fem_dm->h_pcs; tmp_type = fem_dm->Flow_Type; int idx_p1_ini = h_pcs->GetNodeValueIndex("PRESSURE1_Ini"); - int idx_p1_1 = h_pcs->GetNodeValueIndex("PRESSURE1")+1; - if(tmp_type==0||tmp_type==1)//LiquideFlow,RichardsFlow + int idx_p1_1 = h_pcs->GetNodeValueIndex("PRESSURE1") + 1; + if (tmp_type == 0 || tmp_type == 1) // LiquideFlow,RichardsFlow { - for(size_t i=0; iGetNodesNumber(false); i++) + for (size_t i = 0; i < m_msh->GetNodesNumber(false); i++) { h_pcs->SetNodeValue(i, idx_p1_ini, h_pcs->GetNodeValue(i, idx_p1_1)); } } - else if (tmp_type==2) + else if (tmp_type == 2) { int idx_p2_ini = h_pcs->GetNodeValueIndex("PRESSURE2_Ini"); - //int idx_sw_ini = h_pcs->GetNodeValueIndex("SATURATION1_Ini"); - int idx_p2_1 = h_pcs->GetNodeValueIndex("PRESSURE2")+1; - //int idx_sw_1 = h_pcs->GetNodeValueIndex("SATURATION1")+1; - for(size_t i=0; iGetNodesNumber(false); i++) + // int idx_sw_ini = h_pcs->GetNodeValueIndex("SATURATION1_Ini"); + int idx_p2_1 = h_pcs->GetNodeValueIndex("PRESSURE2") + 1; + // int idx_sw_1 = h_pcs->GetNodeValueIndex("SATURATION1")+1; + for (size_t i = 0; i < m_msh->GetNodesNumber(false); i++) { h_pcs->SetNodeValue(i, idx_p1_ini, h_pcs->GetNodeValue(i, idx_p1_1)); h_pcs->SetNodeValue(i, idx_p2_ini, h_pcs->GetNodeValue(i, idx_p2_1)); - //h_pcs->SetNodeValue(i, idx_sw_ini, h_pcs->GetNodeValue(i, idx_sw_1)); + // h_pcs->SetNodeValue(i, idx_sw_ini, h_pcs->GetNodeValue(i, idx_sw_1)); } } } @@ -3055,7 +3046,7 @@ void CRFProcessDeformation::UpdateStress() for (i = 0; i < (long)m_msh->ele_vector.size(); i++) { elem = m_msh->ele_vector[i]; - if (elem->GetMark()) // Marked for use + if (elem->GetMark()) // Marked for use { elem->SetOrder(true); #if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW @@ -3081,44 +3072,44 @@ void CRFProcessDeformation::UpdateStress() **************************************************************************/ void CRFProcessDeformation::WriteGaussPointStress(const bool last_step) { - if ( !(idata_type == write_all_binary || idata_type == read_write) ) + if (!(idata_type == write_all_binary || idata_type == read_write)) return; - if ( ( aktueller_zeitschritt % nwrite_restart ) > 0 && (!last_step)) + if ((aktueller_zeitschritt % nwrite_restart) > 0 && (!last_step)) return; - + #if defined(USE_PETSC) || defined(USE_MPI) //|| defined(other parallel libs)//03.3012. WW const std::string StressFileName = FileName + "_" + number2str(myrank) + ".sts"; #else const std::string StressFileName = FileName + ".sts"; #endif - fstream file_stress(StressFileName.data(),ios::binary | ios::out | ios::trunc); + fstream file_stress(StressFileName.data(), ios::binary | ios::out | ios::trunc); ElementValue_DM* eleV_DM = NULL; std::size_t ActiveElements = 0; MeshLib::CElem* elem = NULL; - for(std::size_t i=0; iele_vector.size(); i++) + for (std::size_t i = 0; i < m_msh->ele_vector.size(); i++) { elem = m_msh->ele_vector[i]; - if (ExcavMaterialGroup > -1)//WX:if excavation write all eles + if (ExcavMaterialGroup > -1) // WX:if excavation write all eles ActiveElements++; else { - if (elem->GetMark()) // Marked for use - ActiveElements++; - } + if (elem->GetMark()) // Marked for use + ActiveElements++; + } } file_stress.write((char*)(&ActiveElements), sizeof(ActiveElements)); - for(std::size_t i=0; iele_vector.size(); i++) + for (std::size_t i = 0; i < m_msh->ele_vector.size(); i++) { elem = m_msh->ele_vector[i]; - if (elem->GetMark()||ExcavMaterialGroup > -1) // Marked for use//WX:if excavation write all eles + if (elem->GetMark() || ExcavMaterialGroup > -1) // Marked for use//WX:if excavation write all eles { eleV_DM = ele_value_dm[i]; file_stress.write((char*)(&i), sizeof(i)); // *eleV_DM->Stress_i += *eleV_DM->Stress0; - //TEST *eleV_DM->Stress0 = 0.0; + // TEST *eleV_DM->Stress0 = 0.0; eleV_DM->Write_BIN(file_stress, last_step); } } @@ -3144,7 +3135,7 @@ void CRFProcessDeformation::ReadGaussPointStress() const std::string StressFileName = FileName + ".sts"; #endif - fstream file_stress (StressFileName.data(),ios::binary | ios::in); + fstream file_stress(StressFileName.data(), ios::binary | ios::in); ElementValue_DM* eleV_DM = NULL; // std::size_t ActiveElements; @@ -3156,14 +3147,13 @@ void CRFProcessDeformation::ReadGaussPointStress() eleV_DM = ele_value_dm[index]; eleV_DM->Read_BIN(file_stress); (*eleV_DM->Stress0) = (*eleV_DM->Stress); - if(eleV_DM->Stress_j) + if (eleV_DM->Stress_j) (*eleV_DM->Stress_j) = (*eleV_DM->Stress); } // file_stress.close(); } - /************************************************************************** ROCKFLOW - Funktion: ReadGaussPointStress() @@ -3179,24 +3169,23 @@ void CRFProcessDeformation::ReadElementStress() { long i, index, ActiveElements; string StressFileName = FileName + ".ele_stress.asc"; - fstream file_stress (StressFileName.data()); + fstream file_stress(StressFileName.data()); ElementValue_DM* eleV_DM = NULL; // - file_stress>>ActiveElements; + file_stress >> ActiveElements; for (i = 0; i < ActiveElements; i++) { - file_stress>>index; + file_stress >> index; eleV_DM = ele_value_dm[index]; eleV_DM->ReadElementStressASCI(file_stress); (*eleV_DM->Stress) = (*eleV_DM->Stress0); - if(eleV_DM->Stress_j) + if (eleV_DM->Stress_j) (*eleV_DM->Stress_j) = (*eleV_DM->Stress); } // file_stress.close(); } - /************************************************************************** ROCKFLOW - Funktion: ReleaseLoadingByExcavation() @@ -3219,12 +3208,12 @@ void CRFProcessDeformation::ReleaseLoadingByExcavation() std::vector NodesOnCaveSurface; CSourceTerm* m_st = NULL; - SizeSt = (int) st_vector.size(); + SizeSt = (int)st_vector.size(); bool exist = false; double* eqs_b = NULL; -#if defined (USE_PETSC) // || defined (other parallel solver lib). 04.2012 WW - //TODO +#if defined(USE_PETSC) // || defined (other parallel solver lib). 04.2012 WW +// TODO #elif defined(NEW_EQS) eqs_b = eqs_new->b; #else @@ -3234,7 +3223,7 @@ void CRFProcessDeformation::ReleaseLoadingByExcavation() for (k = 0; k < SizeSt; k++) { m_st = st_vector[k]; - if (m_st->getProcessPrimaryVariable () == FiniteElement::EXCAVATION) + if (m_st->getProcessPrimaryVariable() == FiniteElement::EXCAVATION) { // ---- 16.01.2009 WW exist = false; @@ -3249,14 +3238,14 @@ void CRFProcessDeformation::ReleaseLoadingByExcavation() ExcavDomainIndex.push_back(m_st->getSubDomainIndex()); } } - SizeSubD = (int) ExcavDomainIndex.size(); + SizeSubD = (int)ExcavDomainIndex.size(); if (SizeSubD == 0) - return; //05.09.2007 WW - exist = false; // 16.02 + return; // 05.09.2007 WW + exist = false; // 16.02 // 1. De-active host domain to be exvacated actElements = 0; MeshLib::CElem* elem = NULL; - for (i = 0; i < (long) m_msh->ele_vector.size(); i++) + for (i = 0; i < (long)m_msh->ele_vector.size(); i++) { elem = m_msh->ele_vector[i]; elem->SetMark(false); @@ -3268,26 +3257,25 @@ void CRFProcessDeformation::ReleaseLoadingByExcavation() } if (actElements == 0) { - cout - << "No element specified for excavation. Please check data in .st file " - << "\n"; + cout << "No element specified for excavation. Please check data in .st file " + << "\n"; abort(); } - // 2. Compute the released node loading +// 2. Compute the released node loading -#if !defined( NEW_EQS) && !defined(USE_PETSC) //WW. 06.11.2008, 04.2012 +#if !defined(NEW_EQS) && !defined(USE_PETSC) // WW. 06.11.2008, 04.2012 SetLinearSolver(eqs); SetZeroLinearSolver(eqs); #endif - for (i = 0; i < 4; i++) // In case the domain decomposition is employed + for (i = 0; i < 4; i++) // In case the domain decomposition is employed fem_dm->NodeShift[i] = Shift[i]; // PreLoad = 11; LoadFactor = 1.0; - for (i = 0; i < (long) m_msh->ele_vector.size(); i++) + for (i = 0; i < (long)m_msh->ele_vector.size(); i++) { elem = m_msh->ele_vector[i]; - if (elem->GetMark()) // Marked for use + if (elem->GetMark()) // Marked for use { fem_dm->ConfigElement(elem, m_num->ele_gauss_points); fem_dm->LocalAssembly(0); @@ -3307,9 +3295,9 @@ void CRFProcessDeformation::ReleaseLoadingByExcavation() std::vector nodes_vector(0); number_of_nodes = 0; - RecordNodeVSize((long) st_node_value.size()); + RecordNodeVSize((long)st_node_value.size()); - //TEST + // TEST st_node_value.clear(); // @@ -3317,29 +3305,27 @@ void CRFProcessDeformation::ReleaseLoadingByExcavation() { // Get nodes on cave surface m_st = st_vector[k]; - if (m_st->getProcessPrimaryVariable () != FiniteElement::EXCAVATION) + if (m_st->getProcessPrimaryVariable() != FiniteElement::EXCAVATION) continue; - if (m_st->getGeoType () == GEOLIB::POLYLINE) + if (m_st->getGeoType() == GEOLIB::POLYLINE) { - CGLPolyline* m_polyline (GEOGetPLYByName(m_st->getGeoName())); + CGLPolyline* m_polyline(GEOGetPLYByName(m_st->getGeoName())); // reset the min edge length of mesh - double mesh_min_edge_length (m_msh->getMinEdgeLength()); + double mesh_min_edge_length(m_msh->getMinEdgeLength()); m_msh->setMinEdgeLength(m_polyline->epsilon); if (m_st->getGeoObj()) { - m_msh->GetNODOnPLY(static_cast(m_st-> - getGeoObj()), - nodes_vector); + m_msh->GetNODOnPLY(static_cast(m_st->getGeoObj()), nodes_vector); // reset min edge length of mesh - m_msh->setMinEdgeLength (mesh_min_edge_length); + m_msh->setMinEdgeLength(mesh_min_edge_length); } - m_msh->setMinEdgeLength (mesh_min_edge_length); + m_msh->setMinEdgeLength(mesh_min_edge_length); } - if (m_st->getGeoType () == GEOLIB::SURFACE) + if (m_st->getGeoType() == GEOLIB::SURFACE) { - //CC 10/05 + // CC 10/05 Surface* m_surface = GEOGetSFCByName(m_st->getGeoName()); // 07/2010 TF ToDo: to do away with the global vector surface_vector // fetch the geometry from CFEMesh @@ -3353,21 +3339,19 @@ void CRFProcessDeformation::ReleaseLoadingByExcavation() } } // Set released node forces from eqs->b; - number_of_nodes = (int) nodes_vector.size(); + number_of_nodes = (int)nodes_vector.size(); for (j = 0; j < problem_dimension_dm; j++) for (i = 0; i < number_of_nodes; i++) { m_node_value = new CNodeValue(); m_node_value->msh_node_number = nodes_vector[i] + Shift[j]; m_node_value->geo_node_number = nodes_vector[i]; - m_node_value->node_value = -eqs_b[m_node_value->geo_node_number - + Shift[j]]; + m_node_value->node_value = -eqs_b[m_node_value->geo_node_number + Shift[j]]; m_node_value->CurveIndex = m_st->CurveIndex; // Each node only take once exist = false; - for (l = 0; l < (int) st_node_value.size(); l++) - if (st_node_value[l]->msh_node_number - == m_node_value->msh_node_number) + for (l = 0; l < (int)st_node_value.size(); l++) + if (st_node_value[l]->msh_node_number == m_node_value->msh_node_number) { exist = true; break; @@ -3386,14 +3370,14 @@ void CRFProcessDeformation::ReleaseLoadingByExcavation() Deactivated_SubDomain[j] = ExcavDomainIndex[j]; // Activate the host domain for excavtion analysis - for (i = 0; i < (long) m_msh->ele_vector.size(); i++) + for (i = 0; i < (long)m_msh->ele_vector.size(); i++) { elem = m_msh->ele_vector[i]; if (!elem->GetMark()) elem->SetMark(true); } PreLoad = 1; - //TEST OUTPUT + // TEST OUTPUT // {MXDumpGLS("rf_pcs.txt",1,eqs->b,eqs->x); abort();} } @@ -3414,10 +3398,10 @@ void CRFProcessDeformation::UpdateInitialStress(bool ZeroInitialS) for (i = 0; i < (long)m_msh->ele_vector.size(); i++) { elem = m_msh->ele_vector[i]; - if (elem->GetMark()) // Marked for use + if (elem->GetMark()) // Marked for use { eval_DM = ele_value_dm[i]; - if(ZeroInitialS) + if (ZeroInitialS) (*eval_DM->Stress0) = 0.0; else (*eval_DM->Stress0) = (*eval_DM->Stress); @@ -3454,7 +3438,7 @@ bool CRFProcessDeformation::CalcBC_or_SecondaryVariable_Dynamics(bool BC) v = 0.0; // 0: not given // 1, 2, 3: x,y, or z is given - for(size_t i = 0; i < Size; i++) + for (size_t i = 0; i < Size; i++) bc_type[i] = 0; idx_dpre0 = GetNodeValueIndex("PRESSURE_RATE1"); @@ -3462,7 +3446,7 @@ bool CRFProcessDeformation::CalcBC_or_SecondaryVariable_Dynamics(bool BC) idx_pre = GetNodeValueIndex("PRESSURE1"); nv = 2 * problem_dimension_dm + 1; - if(m_msh->GetCoordinateFlag() / 10 == 2) // 2D + if (m_msh->GetCoordinateFlag() / 10 == 2) // 2D { function_name[0] = "DISPLACEMENT_X1"; function_name[1] = "DISPLACEMENT_Y1"; @@ -3475,10 +3459,10 @@ bool CRFProcessDeformation::CalcBC_or_SecondaryVariable_Dynamics(bool BC) idx_vel[1] = GetNodeValueIndex("VELOCITY_DM_Y"); idx_acc0[0] = GetNodeValueIndex("ACCELERATION_X1"); idx_acc0[1] = GetNodeValueIndex("ACCELERATION_Y1"); - idx_acc[0] = idx_acc0[0] + 1; - idx_acc[1] = idx_acc0[1] + 1; + idx_acc[0] = idx_acc0[0] + 1; + idx_acc[1] = idx_acc0[1] + 1; } - else if(m_msh->GetCoordinateFlag() / 10 == 3) //3D + else if (m_msh->GetCoordinateFlag() / 10 == 3) // 3D { function_name[0] = "DISPLACEMENT_X1"; function_name[1] = "DISPLACEMENT_Y1"; @@ -3496,36 +3480,34 @@ bool CRFProcessDeformation::CalcBC_or_SecondaryVariable_Dynamics(bool BC) idx_acc0[0] = GetNodeValueIndex("ACCELERATION_X1"); idx_acc0[1] = GetNodeValueIndex("ACCELERATION_Y1"); idx_acc0[2] = GetNodeValueIndex("ACCELERATION_Z1"); - for(k = 0; k < 3; k++) + for (k = 0; k < 3; k++) idx_acc[k] = idx_acc0[k] + 1; } // - for(size_t i = 0; i < bc_node_value.size(); i++) + for (size_t i = 0; i < bc_node_value.size(); i++) { CBoundaryConditionNode* m_bc_node = bc_node_value[i]; m_bc = bc_node[i]; - for(j = 0; j < nv; j++) - if (convertPrimaryVariableToString(m_bc->getProcessPrimaryVariable()). - compare(function_name[j]) == 0) + for (j = 0; j < nv; j++) + if (convertPrimaryVariableToString(m_bc->getProcessPrimaryVariable()).compare(function_name[j]) == 0) break; - if(j == nv) + if (j == nv) { - cout << - "No such primary variable found in CalcBC_or_SecondaryVariable_Dynamics." + cout << "No such primary variable found in CalcBC_or_SecondaryVariable_Dynamics." << "\n"; abort(); } bc_msh_node = m_bc_node->geo_node_number; - if(!m_msh->nod_vector[bc_msh_node]->GetMark()) + if (!m_msh->nod_vector[bc_msh_node]->GetMark()) continue; - if(bc_msh_node >= 0) + if (bc_msh_node >= 0) { - curve = m_bc_node->CurveIndex; - if(curve > 0) + curve = m_bc_node->CurveIndex; + if (curve > 0) { - time_fac = GetCurveValue(curve,interp_method,aktuelle_zeit,&valid); - if(!valid) + time_fac = GetCurveValue(curve, interp_method, aktuelle_zeit, &valid); + if (!valid) continue; } else @@ -3533,30 +3515,30 @@ bool CRFProcessDeformation::CalcBC_or_SecondaryVariable_Dynamics(bool BC) bc_value = time_fac * m_bc_node->node_value; bc_eqs_index = m_msh->nod_vector[bc_msh_node]->GetEquationIndex(); - if(BC) + if (BC) { - if(j < problem_dimension_dm) // da + if (j < problem_dimension_dm) // da { bc_eqs_index += Shift[j]; - // da = v = 0.0; -#if defined (USE_PETSC) // || defined (other parallel solver lib). 04.2012 WW - //TODO -#elif defined(NEW_EQS) //WW +// da = v = 0.0; +#if defined(USE_PETSC) // || defined (other parallel solver lib). 04.2012 WW +// TODO +#elif defined(NEW_EQS) // WW eqs_new->SetKnownX_i(bc_eqs_index, 0.); #else - MXRandbed(bc_eqs_index,0.0,eqs->b); + MXRandbed(bc_eqs_index, 0.0, eqs->b); #endif } - else if(j == nv - 1) // P + else if (j == nv - 1) // P { bc_eqs_index += Shift[problem_dimension_dm]; - // da = v = 0.0; -#if defined (USE_PETSC) // || defined (other parallel solver lib). 04.2012 WW - //TODO -#elif defined(NEW_EQS) //WW +// da = v = 0.0; +#if defined(USE_PETSC) // || defined (other parallel solver lib). 04.2012 WW +// TODO +#elif defined(NEW_EQS) // WW eqs_new->SetKnownX_i(bc_eqs_index, 0.); #else - MXRandbed(bc_eqs_index,0.0,eqs->b); + MXRandbed(bc_eqs_index, 0.0, eqs->b); #endif } } @@ -3565,70 +3547,65 @@ bool CRFProcessDeformation::CalcBC_or_SecondaryVariable_Dynamics(bool BC) // Bit operator if (!(bc_type[bc_eqs_index] & (int)MathLib::fastpow(2, j))) bc_type[bc_eqs_index] += (int)MathLib::fastpow(2, j); - if(j < problem_dimension_dm) // Disp + if (j < problem_dimension_dm) // Disp { SetNodeValue(bc_eqs_index, idx_disp[j], bc_value); SetNodeValue(bc_eqs_index, idx_vel[j], 0.0); SetNodeValue(bc_eqs_index, idx_acc[j], 0.0); } // Vel - else if(j >= problem_dimension_dm && j < nv - 1) + else if (j >= problem_dimension_dm && j < nv - 1) { v = GetNodeValue(bc_eqs_index, idx_disp[j]); v += bc_value * dt - + 0.5 * dt * dt * (ARRAY[bc_eqs_index + Shift[j]] - + m_num->GetDynamicDamping_beta2() - * GetNodeValue(bc_eqs_index, - idx_acc0[j])); + + 0.5 * dt * dt + * (ARRAY[bc_eqs_index + Shift[j]] + + m_num->GetDynamicDamping_beta2() * GetNodeValue(bc_eqs_index, idx_acc0[j])); SetNodeValue(bc_eqs_index, idx_disp[j], v); SetNodeValue(bc_eqs_index, idx_vel[j], bc_value); } - else if(j == nv - 1) // Vel - { //p + else if (j == nv - 1) // Vel + { // p SetNodeValue(bc_eqs_index, idx_pre, bc_value); SetNodeValue(bc_eqs_index, idx_dpre, 0.0); } } } } - if(BC) + if (BC) return BC; // BC - for(i = 0; i < m_msh->GetNodesNumber(true); i++) - for(k = 0; k < problem_dimension_dm; k++) + for (i = 0; i < m_msh->GetNodesNumber(true); i++) + for (k = 0; k < problem_dimension_dm; k++) { // If boundary - if (bc_type[i] & (int) MathLib::fastpow(2, k)) - continue; //u + if (bc_type[i] & (int)MathLib::fastpow(2, k)) + continue; // u // v = GetNodeValue(i, idx_disp[k]); v += GetNodeValue(i, idx_vel[k]) * dt - + 0.5 * dt * dt * (ARRAY[i + Shift[k]] - + m_num->GetDynamicDamping_beta2() - * GetNodeValue(i, idx_acc0[k])); + + 0.5 * dt * dt + * (ARRAY[i + Shift[k]] + m_num->GetDynamicDamping_beta2() * GetNodeValue(i, idx_acc0[k])); SetNodeValue(i, idx_disp[k], v); - if(bc_type[i] & (int)MathLib::fastpow(2, k + problem_dimension_dm)) + if (bc_type[i] & (int)MathLib::fastpow(2, k + problem_dimension_dm)) continue; // v v = GetNodeValue(i, idx_vel[k]); - v += dt * ARRAY[i + Shift[k]] - + m_num->GetDynamicDamping_beta1() * dt - * GetNodeValue(i, idx_acc0[k]); + v += dt * ARRAY[i + Shift[k]] + m_num->GetDynamicDamping_beta1() * dt * GetNodeValue(i, idx_acc0[k]); SetNodeValue(i, idx_vel[k], v); } - for(i = 0; i < m_msh->GetNodesNumber(false); i++) + for (i = 0; i < m_msh->GetNodesNumber(false); i++) { - if(bc_type[i] & (int)MathLib::fastpow(2, (nv - 1))) + if (bc_type[i] & (int)MathLib::fastpow(2, (nv - 1))) continue; v = GetNodeValue(i, idx_pre); - v += ARRAY[i + Shift[problem_dimension_dm]] * dt - + m_num->GetDynamicDamping_beta1() * dt * - GetNodeValue(i, idx_dpre0); + v += ARRAY[i + Shift[problem_dimension_dm]] * dt + + m_num->GetDynamicDamping_beta1() * dt * GetNodeValue(i, idx_dpre0); SetNodeValue(i, idx_pre, v); } return BC; } -} // end namespace +} // end namespace diff --git a/FEM/pcs_dm.h b/FEM/pcs_dm.h index 538a20967..5d43370ec 100644 --- a/FEM/pcs_dm.h +++ b/FEM/pcs_dm.h @@ -21,19 +21,20 @@ #include "rf_pcs.h" // Strong discontinuity -extern bool Localizing; // for tracing localization +extern bool Localizing; // for tracing localization typedef struct { int ElementIndex; - int NumInterFace; // Number of intersection faces + int NumInterFace; // Number of intersection faces // Local indeces of intersection faces (3D) int* InterFace; } DisElement; -extern std::vector LastElement; // Last discontinuity element correponding to SeedElement -extern std::vector ElementOnPath; // Element on the discontinuity path +extern std::vector LastElement; // Last discontinuity element correponding to SeedElement +extern std::vector ElementOnPath; // Element on the discontinuity path namespace FiniteElement -{class CFiniteElementVec; +{ +class CFiniteElementVec; } using FiniteElement::CFiniteElementVec; #if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW @@ -42,12 +43,21 @@ class CPARDomain; namespace process { - -enum InitDataReadWriteType {none, read_write, read_all_binary, write_all_binary, - read_all_asci, write_all_asci, - read_stress_binary, write_stress_binary, - read_displacement, write_displacement, - read_pressure, write_pressure}; +enum InitDataReadWriteType +{ + none, + read_write, + read_all_binary, + write_all_binary, + read_all_asci, + write_all_asci, + read_stress_binary, + write_stress_binary, + read_displacement, + write_displacement, + read_pressure, + write_pressure +}; // Elasto-plastic Deformation class CRFProcessDeformation : public CRFProcess @@ -57,8 +67,8 @@ class CRFProcessDeformation : public CRFProcess virtual ~CRFProcessDeformation(); void Initialization(); - void InitialNodeValueHpcs();//WX:08.2011 - void CalIniTotalStress();//WX:04.2013 + void InitialNodeValueHpcs(); // WX:08.2011 + void CalIniTotalStress(); // WX:04.2013 // Assemble system equation void GlobalAssembly(); @@ -68,8 +78,7 @@ class CRFProcessDeformation : public CRFProcess double Execute(int loop_process_number); // Aux. Memory - double* GetAuxArray() const {return ARRAY; } - + double* GetAuxArray() const { return ARRAY; } void ScalingNodeForce(const double SFactor); void InitGauss(); // @@ -81,7 +90,7 @@ class CRFProcessDeformation : public CRFProcess void RecoverSolution(const int ty = 0); double NormOfDisp(); #if !defined(USE_PETSC) && !defined(NEW_EQS) // && defined(other parallel libs)//03~04.3012. WW - //#ifndef NEW_EQS + //#ifndef NEW_EQS double NormOfUnkonwn_orRHS(bool isUnknowns = true); #endif // Stress @@ -108,14 +117,12 @@ class CRFProcessDeformation : public CRFProcess void ReadElementStress(); // Access members - CFiniteElementVec* GetFEM_Assembler() const {return fem_dm; } - - //WX:07.2011 + CFiniteElementVec* GetFEM_Assembler() const { return fem_dm; } + // WX:07.2011 void PostExcavation(); - //WX:10.2011 + // WX:10.2011 void UpdateIniStateValue(); - private: CFiniteElementVec* fem_dm; void InitialMBuffer(); @@ -141,9 +148,9 @@ class CRFProcessDeformation : public CRFProcess void Trace_Discontinuity(); long MarkBifurcatedNeighbor(const int PathIndex); }; -} // end namespace +} // end namespace -extern void CalStressInvariants(const long Node_Inex,double* StressInv); +extern void CalStressInvariants(const long Node_Inex, double* StressInv); // For visualization extern void CalMaxiumStressInvariants(double* StressInv); extern double LoadFactor; diff --git a/FEM/problem.cpp b/FEM/problem.cpp index 5d1989296..c0179bfc8 100644 --- a/FEM/problem.cpp +++ b/FEM/problem.cpp @@ -19,18 +19,17 @@ ========================================================================*/ #include "problem.h" -#if defined (USE_MPI) +#if defined(USE_MPI) #include #include "SplitMPI_Communicator.h" #endif - #include #include #include -//kg44: max size for size_t (system_dependent) is set normally here +// kg44: max size for size_t (system_dependent) is set normally here #include -//WW +// WW // /*------------------------------------------------------------------------*/ /* Pre-processor definitions */ @@ -44,12 +43,12 @@ /*------------------------------------------------------------------------*/ // Data file -//OK411 +// OK411 extern int ReadData(char*, GEOLIB::GEOObjects& geo_obj, std::string& unique_name); /* PCS */ #include "pcs_dm.h" #include "rf_pcs.h" -//16.12.2008.WW #include "rf_apl.h" +// 16.12.2008.WW #include "rf_apl.h" #if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW #include "par_ddc.h" @@ -57,8 +56,7 @@ extern int ReadData(char*, GEOLIB::GEOObjects& geo_obj, std::string& unique_name #include "rf_react.h" #include "rf_react_int.h" -#include "rf_react_cap.h" //CB merge CAP 0311 - +#include "rf_react_cap.h" //CB merge CAP 0311 #include "rf_st_new.h" #include "rf_tim_new.h" @@ -67,17 +65,17 @@ extern int ReadData(char*, GEOLIB::GEOObjects& geo_obj, std::string& unique_name #include "rf_fluid_momentum.h" #include "rf_random_walk.h" // Finite element -#include "DUMUX.h" // BG 02/2011 -#include "Eclipse.h" //BG 09/2009 +#include "DUMUX.h" // BG 02/2011 +#include "Eclipse.h" //BG 09/2009 #include "Output.h" #include "fem_ele_std.h" -#include "files0.h" // GetLineFromFile1 +#include "files0.h" // GetLineFromFile1 #include "rf_bc_new.h" #include "rf_node.h" #include "rf_out_new.h" #include "tools.h" #include "timer.h" -#include "rf_msp_new.h"//WX:01.2013 +#include "rf_msp_new.h" //WX:01.2013 // #ifdef CHEMAPP #include "eqlink.h" @@ -98,7 +96,8 @@ extern int ReadData(char*, GEOLIB::GEOObjects& geo_obj, std::string& unique_name #include "PETSC/PETScLinearSolver.h" #endif namespace process -{class CRFProcessDeformation; +{ +class CRFProcessDeformation; } using process::CRFProcessDeformation; @@ -110,62 +109,63 @@ using process::CRFProcessDeformation; PreTimeloop Modification: ***************************************************************************/ -Problem::Problem (char* filename) : - dt0(0.), print_result(true), _geo_obj (new GEOLIB::GEOObjects), _geo_name (filename), - mrank(0), msize(0) +Problem::Problem(char* filename) + : dt0(0.), print_result(true), _geo_obj(new GEOLIB::GEOObjects), _geo_name(filename), mrank(0), msize(0) { if (filename != NULL) { // read data ReadData(filename, *_geo_obj, _geo_name); -#if !defined(USE_PETSC) // && !defined(other parallel libs)//03~04.3012. WW +#if !defined(USE_PETSC) // && !defined(other parallel libs)//03~04.3012. WW DOMRead(filename); #endif } #if !defined(USE_PETSC) && !defined(NEW_EQS) // && defined(other parallel libs)//03~04.3012. WW //#ifndef NEW_EQS - ConfigSolverProperties(); //_new. 19.10.2008. WW + ConfigSolverProperties(); //_new. 19.10.2008. WW #endif // set the link to Problem instance in CRFProcess objects for (size_t i = 0; i < pcs_vector.size(); i++) - pcs_vector[i]->setProblemObjectPointer (this); + pcs_vector[i]->setProblemObjectPointer(this); for (size_t i = 0; i < pcs_vector.size(); i++) { - hasAnyProcessDeactivatedSubdomains - = (pcs_vector[i]->NumDeactivated_SubDomains > 0); + hasAnyProcessDeactivatedSubdomains = (pcs_vector[i]->NumDeactivated_SubDomains > 0); if (hasAnyProcessDeactivatedSubdomains) break; } //---------------------------------------------------------------------- // Create ST - //OK STCreateFromPNT(); + // OK STCreateFromPNT(); //---------------------------------------------------------------------- - GetHeterogeneousFields(); //OK/MB + GetHeterogeneousFields(); // OK/MB //---------------------------------------------------------------------- // Test MSH-MMP //OK bool validMatID = true; - if (fem_msh_vector.size()==1) { + if (fem_msh_vector.size() == 1) + { size_t max_matId = MSHGetMaxPatchIndex(fem_msh_vector[0]); - validMatID = (max_matId+1<=mmp_vector.size()); - } else { + validMatID = (max_matId + 1 <= mmp_vector.size()); + } + else + { int g_max_mmp_groups = MSHSetMaxMMPGroups(); validMatID = !(g_max_mmp_groups > (int)mmp_vector.size()); } - if(!validMatID) + if (!validMatID) { std::cout << "Error: not enough MMP data. please check MMP and material IDs in a mesh." << std::endl; - print_result = false; //OK + print_result = false; // OK return; } //---------------------------------------------------------------------- // Create PCS processes PCSCreate(); - if (!PCSCheck()) //OK4910 reactivated + if (!PCSCheck()) // OK4910 reactivated { - print_result = false; //OK + print_result = false; // OK return; } @@ -178,16 +178,17 @@ Problem::Problem (char* filename) : pcs_fluid_momentum->_idxVy = pcs_fluid_momentum->GetNodeValueIndex("VELOCITY1_Y", true); pcs_fluid_momentum->_idxVz = pcs_fluid_momentum->GetNodeValueIndex("VELOCITY1_Z", true); } - //delete pcs_fluid_momentum; + // delete pcs_fluid_momentum; // - //JT: Set to true to force node copy at end of loop + // JT: Set to true to force node copy at end of loop force_post_node_copy = true; // - //JT: Certain restrictions might be made if an external simulator is being used + // JT: Certain restrictions might be made if an external simulator is being used external_coupling_exists = false; - for(size_t i = 0; i < pcs_vector.size(); i++){ - if(pcs_vector[i]->simulator.compare("GEOSYS") != 0) + for (size_t i = 0; i < pcs_vector.size(); i++) + { + if (pcs_vector[i]->simulator.compare("GEOSYS") != 0) external_coupling_exists = true; } #ifdef GEM_REACT @@ -210,83 +211,92 @@ Problem::Problem (char* filename) : // PCSCalcSecondaryVariables(); //OK //#endif //...................................................................... - //09.07.2008 WW + // 09.07.2008 WW SetActiveProcesses(); - //OK if (!Check()) return; //OK + // OK if (!Check()) return; //OK //---------------------------------------------------------------------- // REACTIONS - //CB before the first time step - if(REACTINT_vec.size()==0){ - for(size_t i=0; iporosity_model==13){ - std::cout << " Error in Model setup: Porosity model 13 is used, " << "\n"; - std::cout << " but no reaction interface is defined! Exiting now..." << "\n"; - exit(0); - } - } - } - //if(MASS_TRANSPORT_Process) // if(MASS_TRANSPORT_Process&&NAPL_Dissolution) //CB Todo - CreateClockTime(); // CB time - if(transport_processes.size() > 0) //12.12.2008. WW + // CB before the first time step + if (REACTINT_vec.size() == 0) { - // set the id variable flow_pcs_type for Saturation and velocity calculation - // in mass transport element matrices - SetFlowProcessType(); - //---------------------------------------------------------------------- - KRConfig(*_geo_obj, _geo_name); - - // initialyse the reaction interface if not done yet - if(REACTINT_vec.size()>0){ - if(REACTINT_vec[0]->unitconversion){ - CRFProcess* flow_pcs = NULL; - flow_pcs = PCSGetFlow(); - if( flow_pcs->type==1212) // in case of mutlltiphase flow, sat water must be calculated here, required by pgc interface - flow_pcs->CalcSecondaryVariables(true); - } - REACTINT_vec[0]->InitREACTINT(); - } - //---------------------------------------------------------------------- - if(KinReactData_vector.size() > 0){ - // Configure Data for Blobs (=>NAPL dissolution) - KBlobConfig(*_geo_obj, _geo_name); - KBlobCheck(); - // in case of Twophaseflow before the first time step - if(total_processes[3] || total_processes[4]) - if(KNaplDissCheck()) // 3: TWO_PHASE_FLOW. 12.12.2008. WW - KNaplCalcDensity(); //PCSCalcSecondaryVariables(); - // CB _drmc_ data for microbes - if(MicrobeData_vector.size()>0) - MicrobeConfig(); - } - } - //---------------------------------------------------------------------- - // REACTIONS - // Initialization of REACT structure for rate exchange between MTM2 and Reactions + for (size_t i = 0; i < mmp_vector.size(); i++) + { + if (mmp_vector[i]->porosity_model == 13) + { + std::cout << " Error in Model setup: Porosity model 13 is used, " + << "\n"; + std::cout << " but no reaction interface is defined! Exiting now..." + << "\n"; + exit(0); + } + } + } + // if(MASS_TRANSPORT_Process) // if(MASS_TRANSPORT_Process&&NAPL_Dissolution) //CB Todo + CreateClockTime(); // CB time + if (transport_processes.size() > 0) // 12.12.2008. WW + { + // set the id variable flow_pcs_type for Saturation and velocity calculation + // in mass transport element matrices + SetFlowProcessType(); + //---------------------------------------------------------------------- + KRConfig(*_geo_obj, _geo_name); + + // initialyse the reaction interface if not done yet + if (REACTINT_vec.size() > 0) + { + if (REACTINT_vec[0]->unitconversion) + { + CRFProcess* flow_pcs = NULL; + flow_pcs = PCSGetFlow(); + if (flow_pcs->type == 1212) // in case of mutlltiphase flow, sat water must be calculated here, required + // by pgc interface + flow_pcs->CalcSecondaryVariables(true); + } + REACTINT_vec[0]->InitREACTINT(); + } + //---------------------------------------------------------------------- + if (KinReactData_vector.size() > 0) + { + // Configure Data for Blobs (=>NAPL dissolution) + KBlobConfig(*_geo_obj, _geo_name); + KBlobCheck(); + // in case of Twophaseflow before the first time step + if (total_processes[3] || total_processes[4]) + if (KNaplDissCheck()) // 3: TWO_PHASE_FLOW. 12.12.2008. WW + KNaplCalcDensity(); // PCSCalcSecondaryVariables(); + // CB _drmc_ data for microbes + if (MicrobeData_vector.size() > 0) + MicrobeConfig(); + } + } +//---------------------------------------------------------------------- +// REACTIONS +// Initialization of REACT structure for rate exchange between MTM2 and Reactions - //-------------------------------------------------- - // HB, for the GEM chemical reaction engine 05.2007 - //-------------------------------------------------- +//-------------------------------------------------- +// HB, for the GEM chemical reaction engine 05.2007 +//-------------------------------------------------- #ifdef GEM_REACT m_vec_GEM = new REACT_GEM(); - GEMRead( FileName, m_vec_GEM ); + GEMRead(FileName, m_vec_GEM); - string path = ""; // to get the path of the file; - path = FileName; // first get full path and project name; + string path = ""; // to get the path of the file; + path = FileName; // first get full path and project name; int pos, npos; pos = 0; npos = (int)path.size(); - // Get path +// Get path #ifdef _WIN32 - pos = (int)path.rfind("\\"); // HS keep this on windows + pos = (int)path.rfind("\\"); // HS keep this on windows #else - pos = (int)path.rfind("/"); // HS keep this on linux -#endif // _WIN32 - if( pos < npos ) + pos = (int)path.rfind("/"); // HS keep this on linux +#endif // _WIN32 + if (pos < npos) path = path.substr(0, pos + 1); // now start initialization of GEMS - if ( m_vec_GEM -> Init_Nodes(path) == 0) + if (m_vec_GEM->Init_Nodes(path) == 0) { if (m_vec_GEM->Init_RUN(path) == 0) { @@ -294,68 +304,71 @@ Problem::Problem (char* filename) : } else // something is wrong and we stop execution { - cout << " GEMS: Error in Init_Nodes..check input " << "\n"; + cout << " GEMS: Error in Init_Nodes..check input " + << "\n"; #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - MPI_Finalize(); //make sure MPI exits + MPI_Finalize(); // make sure MPI exits #endif - exit ( 1 ); + exit(1); } } else // something is wrong and we stop execution { - cout << " GEMS: Error in Init_RUN..check input " << "\n"; + cout << " GEMS: Error in Init_RUN..check input " + << "\n"; #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - MPI_Finalize(); //make sure MPI exits + MPI_Finalize(); // make sure MPI exits #endif - exit ( 1 ); + exit(1); } -#else // GEM_REACT +#else // GEM_REACT //--------------------------------------------------- - REACT* rc = NULL; //SB + REACT* rc = NULL; // SB // rc->TestPHREEQC(); // Test if *.pqc file is present rc = rc->GetREACT(); - if(rc) //OK + if (rc) // OK { - if(rc->flag_pqc) + if (rc->flag_pqc) { - if(cp_vec.size() > 0) - { //OK + if (cp_vec.size() > 0) + { // OK #ifdef REACTION_ELEMENT - rc->CreateREACT(); //SB + rc->CreateREACT(); // SB rc->InitREACT0(); rc->ExecuteReactionsPHREEQC0(); REACT_vec.clear(); REACT_vec.push_back(rc); #else - rc->CreateREACT(); //SB + rc->CreateREACT(); // SB rc->InitREACT(); - //SB4501 rc->ExecuteReactions(); +// SB4501 rc->ExecuteReactions(); #ifdef OGS_FEM_IPQC rc->ExecutePQCString(); -#elif LIBPHREEQC // MDL: new functions with built-in phreeqc +#elif LIBPHREEQC // MDL: new functions with built-in phreeqc rc->ExecuteReactionsPHREEQCNewLib(); #else rc->ExecuteReactionsPHREEQCNew(); -#endif //LIBPHREEQC +#endif // LIBPHREEQC REACT_vec.clear(); REACT_vec.push_back(rc); -#endif // REACTION_ELEMENT +#endif // REACTION_ELEMENT } } // delete rc; } -//CB merge CAP 0311 - // Initialize using ChemApp - if(REACT_CAP_vec.size() > 0) { - // SB 10/2009 do a first equilibrium calculation - REACT_CAP_vec[0]->ExecuteReactionsChemApp(0, -1); // DL/SB 11/2008 //DL 2011.11.24 comment for AGU - // Copy new timelevel to old time level - REACT_CAP_vec[0]->ConvertIC2BC(*_geo_obj, _geo_name); - } -#endif // GEM_REACT + // CB merge CAP 0311 + // Initialize using ChemApp + if (REACT_CAP_vec.size() > 0) + { + // SB 10/2009 do a first equilibrium calculation + REACT_CAP_vec[0]->ExecuteReactionsChemApp(0, -1); // DL/SB 11/2008 //DL 2011.11.24 comment for AGU + // Copy new timelevel to old time level + REACT_CAP_vec[0]->ConvertIC2BC(*_geo_obj, _geo_name); + } +#endif // GEM_REACT #ifdef BRNS // Here to test BRNS; HB 02.11.2007 @@ -368,7 +381,7 @@ Problem::Problem (char* filename) : #ifdef CHEMAPP CEqlink* eq = NULL; eq = eq->GetREACTION(); - if(cp_vec.size() > 0 && eq) //MX + if (cp_vec.size() > 0 && eq) // MX { eq->TestCHEMAPPParameterFile(pcs_vector[0]->file_name_base); if (eq->flag_chemapp) @@ -377,8 +390,8 @@ Problem::Problem (char* filename) : #endif // delete rc; - if(REACTINT_vec.size()>0) - REACTINT_vec[0]->ReactionPostProcessing(true); + if (REACTINT_vec.size() > 0) + REACTINT_vec[0]->ReactionPostProcessing(true); //---------------------------------------------------------------------- // DDC size_t no_processes = pcs_vector.size(); @@ -386,28 +399,28 @@ Problem::Problem (char* filename) : #if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW //---------------------------------------------------------------------- // DDC - if(dom_vector.size() > 0) + if (dom_vector.size() > 0) { DOMCreate(); // - for(size_t i = 0; i < no_processes; i++) + for (size_t i = 0; i < no_processes; i++) { m_pcs = pcs_vector[i]; m_pcs->CheckMarkedElement(); CountDoms2Nodes(m_pcs); // Config boundary conditions for domain decomposition - m_pcs->SetBoundaryConditionSubDomain(); //WW + m_pcs->SetBoundaryConditionSubDomain(); // WW } // node_connected_doms.clear(); - // Release some memory. WW -#if defined(USE_MPI) //TEST_MPI WW +// Release some memory. WW +#if defined(USE_MPI) // TEST_MPI WW // Release memory of other domains. WW - for(size_t i = 0; i < dom_vector.size(); i++) + for (size_t i = 0; i < dom_vector.size(); i++) { - if(i != (size_t)myrank) + if (i != (size_t)myrank) { - // If shared memory, skip the following line +// If shared memory, skip the following line #if defined(NEW_BREDUCE2) dom_vector[i]->ReleaseMemory(); #else @@ -421,8 +434,8 @@ Problem::Problem (char* filename) : } #endif //#if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW //---------------------------------------------------------------------- - PCSRestart(); //SB - OUTCheck(); // new SB + PCSRestart(); // SB + OUTCheck(); // new SB //======================================================================== // Controls for coupling. WW cpl_overall_max_iterations = 1; @@ -435,21 +448,22 @@ Problem::Problem (char* filename) : std::stringstream in_num; // File handling std::string num_file_name = FileName + NUM_FILE_EXTENSION; - std::ifstream num_file (num_file_name.data(),std::ios::in); + std::ifstream num_file(num_file_name.data(), std::ios::in); if (num_file.good()) { - num_file.seekg(0L,std::ios::beg); + num_file.seekg(0L, std::ios::beg); while (!num_file.eof()) { - num_file.getline(line,MAX_ZEILE); + num_file.getline(line, MAX_ZEILE); line_string = line; - if(line_string.find("#STOP") != std::string::npos) + if (line_string.find("#STOP") != std::string::npos) break; - if(line_string.find("$OVERALL_COUPLING") != std::string::npos) + if (line_string.find("$OVERALL_COUPLING") != std::string::npos) { in_num.str(GetLineFromFile1(&num_file)); - //JT// in_num >> max_coupling_iterations >> coupling_tolerance; - //JT: coupling_tolerance is process dependent, cannot be here. See m_num->cpl_tolerance (with $COUPLING_CONTROL) + // JT// in_num >> max_coupling_iterations >> coupling_tolerance; + // JT: coupling_tolerance is process dependent, cannot be here. See m_num->cpl_tolerance (with + // $COUPLING_CONTROL) in_num >> cpl_overall_min_iterations >> cpl_overall_max_iterations; break; } @@ -459,7 +473,8 @@ Problem::Problem (char* filename) : //======================================================================== // For time stepping. WW CTimeDiscretization* m_tim = NULL; - start_time = 1.0e+25; // 1.e+8; kg44 I need a really big time, as I have starting times bigger than 3.e+13 (1 Million years!!!) + start_time = 1.0e+25; // 1.e+8; kg44 I need a really big time, as I have starting times bigger than 3.e+13 (1 + // Million years!!!) end_time = 0.; max_time_steps = 0; bool time_ctr = false; @@ -472,39 +487,42 @@ Problem::Problem (char* filename) : start_time = m_tim->time_start; if (m_tim->time_end > end_time) end_time = m_tim->time_end; - if (max_time_steps < m_tim->time_step_vector.size()) + if (max_time_steps < m_tim->time_step_vector.size()) max_time_steps = m_tim->time_step_vector.size(); if (m_tim->GetPITimeStepCrtlType() > 0) time_ctr = true; - m_tim->last_active_time = start_time; //NW + m_tim->last_active_time = start_time; // NW - //check maximum number of coupling iterations against maximum time step increase + // check maximum number of coupling iterations against maximum time step increase if (m_tim->time_control_type == TimeControlType::SELF_ADAPTIVE - && (m_tim->adapt_itr_type == IterationType::COUPLED || m_tim->adapt_itr_type==IterationType::COUPLED_STABLE_ERROR) - && cpl_overall_max_iterations < m_tim->time_adapt_tim_vector.back()) - std::cout << "Warning: Maximum number of coupling iterations is smaller than maximum time step increase!!!" << std::endl; + && (m_tim->adapt_itr_type == IterationType::COUPLED + || m_tim->adapt_itr_type == IterationType::COUPLED_STABLE_ERROR) + && cpl_overall_max_iterations < m_tim->time_adapt_tim_vector.back()) + std::cout << "Warning: Maximum number of coupling iterations is smaller than maximum time step increase!!!" + << std::endl; } - if(max_time_steps == 0) - max_time_steps = std::numeric_limits::max()-1; // ULONG_MAX-1; //kg44 increased the number to maximum number (size_t) - current_time = start_time; + if (max_time_steps == 0) + max_time_steps = std::numeric_limits::max() + - 1; // ULONG_MAX-1; //kg44 increased the number to maximum number (size_t) + current_time = start_time; if (time_ctr) { // Modified on 14.02.2011. WW long maxi_eqs_dim = 0; - for(size_t i = 0; i < no_processes; i++) + for (size_t i = 0; i < no_processes; i++) { m_pcs = pcs_vector[i]; - if(m_pcs->size_unknowns > maxi_eqs_dim) + if (m_pcs->size_unknowns > maxi_eqs_dim) maxi_eqs_dim = m_pcs->size_unknowns; } buffer_array = new double[maxi_eqs_dim]; buffer_array1 = new double[maxi_eqs_dim]; } else - { + { buffer_array = NULL; buffer_array1 = NULL; - } + } //======================================================================== CRFProcessDeformation* dm_pcs = NULL; @@ -512,14 +530,14 @@ Problem::Problem (char* filename) : for (size_t i = 0; i < no_processes; i++) { m_pcs = pcs_vector[i]; - m_pcs->CalcSecondaryVariables(true); //WW - m_pcs->Extropolation_MatValue(); //WW + m_pcs->CalcSecondaryVariables(true); // WW + m_pcs->Extropolation_MatValue(); // WW } // Calculation of the initial stress and released load for excavation simulation // 07.09.2007 WW // Excavation for defromation dm_pcs = (CRFProcessDeformation*)total_processes[12]; - if(dm_pcs) + if (dm_pcs) dm_pcs->CreateInitialState4Excavation(); #ifdef OGS_DELETE_EDGES_AFTER_INIT @@ -528,15 +546,15 @@ Problem::Problem (char* filename) : for (size_t i = 0; i < no_processes; i++) { m_pcs = pcs_vector[i]; - if(m_pcs->getProcessType() == FiniteElement::FLUID_MOMENTUM) //09.2012 WW + if (m_pcs->getProcessType() == FiniteElement::FLUID_MOMENTUM) // 09.2012 WW { fluid_mom_pcs = true; break; } } - if(!fluid_mom_pcs) + if (!fluid_mom_pcs) { - for(size_t k = 0; k < fem_msh_vector.size(); k++) + for (size_t k = 0; k < fem_msh_vector.size(); k++) { fem_msh_vector[k]->FreeEdgeMemory(); } @@ -571,12 +589,12 @@ Problem::~Problem() // PCSDestroyAllProcesses(); // - if(GetRFProcessProcessingAndActivation("MT") && GetRFProcessNumComponents() > 0) + if (GetRFProcessProcessingAndActivation("MT") && GetRFProcessNumComponents() > 0) { - DestroyREACT(); //SB - cp_vec.clear(); // Destroy component properties vector + DestroyREACT(); // SB + cp_vec.clear(); // Destroy component properties vector } - // +// #ifdef CHEMAPP if (Eqlink_vec.size() > 0) { @@ -584,7 +602,7 @@ Problem::~Problem() Eqlink_vec.clear(); } #endif - //WW ClockTimeVec[0]->PrintTimes(); +// WW ClockTimeVec[0]->PrintTimes(); #ifdef GEM_REACT // HS: delete m_vec_GEM; @@ -596,10 +614,12 @@ Problem::~Problem() delete m_vec_BRNS; #endif -#if defined(USE_PETSC) ||defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_GEMS) - if(mrank == 0) +#if defined(USE_PETSC) || defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) \ + || defined(USE_MPI_GEMS) + if (mrank == 0) #endif - std::cout << "\n^O^: Your simulation is terminated normally ^O^ " << "\n"; + std::cout << "\n^O^: Your simulation is terminated normally ^O^ " + << "\n"; } /*------------------------------------------------------------------------- @@ -714,7 +734,7 @@ inline int Problem::AssignProcessIndex(CRFProcess* m_pcs, bool activefunc) return 10; total_processes[10] = m_pcs; active_processes[10] = &Problem::RandomWalker; - DATWriteParticleFile(0); //YS + DATWriteParticleFile(0); // YS return 10; // } else if (m_pcs->pcs_type_name.compare("MASS_TRANSPORT") == 0) { } @@ -727,7 +747,7 @@ inline int Problem::AssignProcessIndex(CRFProcess* m_pcs, bool activefunc) return 11; // } else if (m_pcs->pcs_type_name.find("DEFORMATION") != string::npos) { } - else if (isDeformationProcess (m_pcs->getProcessType())) + else if (isDeformationProcess(m_pcs->getProcessType())) { if (!activefunc) return 12; @@ -773,7 +793,6 @@ inline int Problem::AssignProcessIndex(CRFProcess* m_pcs, bool activefunc) return -1; } - /*------------------------------------------------------------------------- GeoSys - Function: SetActiveProcesses Task: @@ -797,26 +816,28 @@ void Problem::SetActiveProcesses() coupled_process_index.resize(max_processes); exe_flag = new bool[max_processes]; // - for(size_t i = 0; i < max_processes; i++) + for (size_t i = 0; i < max_processes; i++) { total_processes[i] = NULL; active_processes[i] = NULL; coupled_process_index[i] = -1; } // - for(size_t i = 0; i < pcs_vector.size(); i++) + for (size_t i = 0; i < pcs_vector.size(); i++) { m_pcs = pcs_vector[i]; AssignProcessIndex(m_pcs); } // - for(size_t i = 0; i < max_processes; i++) - if(total_processes[i]) + for (size_t i = 0; i < max_processes; i++) + if (total_processes[i]) { - // JT: Check for a coupled variable or process (variable is probably necessary for multiple component transport situations. + // JT: Check for a coupled variable or process (variable is probably necessary for multiple component + // transport situations. // First try for a variable, because this is more general for mass transport - m_pcs = PCSGet(total_processes[i]->m_num->cpl_variable,true); - if(m_pcs){ + m_pcs = PCSGet(total_processes[i]->m_num->cpl_variable, true); + if (m_pcs) + { m_pcs->pcs_is_cpl_underling = true; total_processes[i]->pcs_is_cpl_overlord = true; // @@ -824,9 +845,11 @@ void Problem::SetActiveProcesses() m_pcs->cpl_overlord = total_processes[i]; total_processes[i]->cpl_underling = m_pcs; } - else{ // Try for a process, because it may have been assigned this way + else + { // Try for a process, because it may have been assigned this way m_pcs = PCSGet(total_processes[i]->m_num->cpl_process); - if(m_pcs){ + if (m_pcs) + { m_pcs->pcs_is_cpl_underling = true; total_processes[i]->pcs_is_cpl_overlord = true; // @@ -847,15 +870,16 @@ void Problem::SetActiveProcesses() transport_processes.push_back(m_pcs); // if (m_pcs->pcs_type_name.compare("TWO_PHASE_FLOW") == 0) //09.01.2008. WW // TF - if ((m_pcs->getProcessType() == FiniteElement::TWO_PHASE_FLOW) || (m_pcs->getProcessType() == FiniteElement::MULTI_PHASE_FLOW)) //BG 04/2011 + if ((m_pcs->getProcessType() == FiniteElement::TWO_PHASE_FLOW) + || (m_pcs->getProcessType() == FiniteElement::MULTI_PHASE_FLOW)) // BG 04/2011 multiphase_processes.push_back(m_pcs); - if ((m_pcs->getProcessType() == FiniteElement::GROUNDWATER_FLOW) || (m_pcs->getProcessType() == FiniteElement::LIQUID_FLOW)) //BG 04/2011 + if ((m_pcs->getProcessType() == FiniteElement::GROUNDWATER_FLOW) + || (m_pcs->getProcessType() == FiniteElement::LIQUID_FLOW)) // BG 04/2011 singlephaseflow_process.push_back(m_pcs); } } - /************************************************************************** < ROCKFLOW - Function: PCSCreate Task: @@ -878,22 +902,26 @@ void Problem::SetActiveProcesses() ***************************************************************************/ void Problem::PCSCreate() { -#if defined(USE_PETSC) ||defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_GEMS) - if(mrank == 0) +#if defined(USE_PETSC) || defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) \ + || defined(USE_MPI_GEMS) + if (mrank == 0) { #endif - std::cout << "---------------------------------------------" << "\n"; - std::cout << "Create PCS processes" << "\n"; -#if defined(USE_PETSC) ||defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_GEMS) + std::cout << "---------------------------------------------" + << "\n"; + std::cout << "Create PCS processes" + << "\n"; +#if defined(USE_PETSC) || defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) \ + || defined(USE_MPI_GEMS) } #endif size_t no_processes = pcs_vector.size(); - //OK_MOD if(pcs_deformation>0) Init_Linear_Elements(); + // OK_MOD if(pcs_deformation>0) Init_Linear_Elements(); for (size_t i = 0; i < no_processes; i++) { pcs_vector[i]->pcs_type_number = i; - pcs_vector[i]->Config(); //OK + pcs_vector[i]->Config(); // OK } #if defined(NEW_EQS) @@ -902,32 +930,33 @@ void Problem::PCSCreate() for (size_t i = 0; i < no_processes; i++) { -#if defined(USE_PETSC) ||defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_GEMS) - if(mrank == 0) - { -#endif - std::cout << "............................................." << "\n"; - FiniteElement::ProcessType pcs_type (pcs_vector[i]->getProcessType()); - std::cout << "Create: " << FiniteElement::convertProcessTypeToString (pcs_type) << "\n"; - // if (!pcs_vector[i]->pcs_type_name.compare("MASS_TRANSPORT")) { - //YS // TF - //if (pcs_type != FiniteElement::MASS_TRANSPORT && pcs_type != FiniteElement::FLUID_MOMENTUM - // && pcs_type != FiniteElement::RANDOM_WALK) - if (pcs_type == FiniteElement::MASS_TRANSPORT ) //SB +#if defined(USE_PETSC) || defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) \ + || defined(USE_MPI_GEMS) + if (mrank == 0) { - std::cout << " for " << pcs_vector[i]->pcs_primary_function_name[0] << " "; - std::cout << " pcs_component_number " << - pcs_vector[i]->pcs_component_number; +#endif + std::cout << "............................................." + << "\n"; + FiniteElement::ProcessType pcs_type(pcs_vector[i]->getProcessType()); + std::cout << "Create: " << FiniteElement::convertProcessTypeToString(pcs_type) << "\n"; + // if (!pcs_vector[i]->pcs_type_name.compare("MASS_TRANSPORT")) { + // YS // TF + // if (pcs_type != FiniteElement::MASS_TRANSPORT && pcs_type != FiniteElement::FLUID_MOMENTUM + // && pcs_type != FiniteElement::RANDOM_WALK) + if (pcs_type == FiniteElement::MASS_TRANSPORT) // SB + { + std::cout << " for " << pcs_vector[i]->pcs_primary_function_name[0] << " "; + std::cout << " pcs_component_number " << pcs_vector[i]->pcs_component_number; + } + std::cout << "\n"; +#if defined(USE_PETSC) || defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) \ + || defined(USE_MPI_GEMS) } - std::cout << "\n"; -#if defined(USE_PETSC) ||defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_GEMS) - } #endif pcs_vector[i]->Create(); } - #if defined(USE_PETSC) // || defined(other solver libs)//03.3012. WW CreateEQS_LinearSolver(); #endif @@ -935,7 +964,7 @@ void Problem::PCSCreate() for (size_t i = 0; i < no_processes; i++) MMP2PCSRelation(pcs_vector[i]); - for (size_t i = 0; i < no_processes; i++) //WW + for (size_t i = 0; i < no_processes; i++) // WW pcs_vector[i]->ConfigureCouplingForLocalAssemblier(); @@ -954,29 +983,30 @@ void Problem::PCSCreate() -------------------------------------------------------------------------*/ void Problem::PCSRestart() { - const size_t no_processes (pcs_vector.size()); + const size_t no_processes(pcs_vector.size()); if (no_processes == 0) - return; //OK41 + return; // OK41 - int ok = 0; // = ReadRFRRestartData(file_name_base); + int ok = 0; // = ReadRFRRestartData(file_name_base); if (ok == 0) { - std::cout << "RFR: no restart data" << "\n"; + std::cout << "RFR: no restart data" + << "\n"; return; } - //WW int nidx0; //, nidx1; + // WW int nidx0; //, nidx1; for (size_t i = 0; i < no_processes; i++) { CRFProcess* m_pcs = pcs_vector[i]; for (size_t j = 0; j < m_pcs->GetPrimaryVNumber(); j++) { // timelevel=0; - //WW nidx0 = m_pcs->GetNodeValueIndex(m_pcs->GetPrimaryVName(j)); + // WW nidx0 = m_pcs->GetNodeValueIndex(m_pcs->GetPrimaryVName(j)); // timelevel= 1; - //WW nidx1 = nidx0 + 1; - //OK411 CopyNodeVals(nidx1,nidx0); + // WW nidx1 = nidx0 + 1; + // OK411 CopyNodeVals(nidx1,nidx0); } } } @@ -999,15 +1029,17 @@ void Problem::SetTimeActiveProcesses() next_time = current_time + dt; // lowest_next_active = DBL_MAX; - for(ii=0; iiTim; m_tim->time_active = true; // activate - if(m_tim->time_independence && m_tim->next_active_time > next_time){ // Process is then not active this time step + if (m_tim->time_independence && m_tim->next_active_time > next_time) + { // Process is then not active this time step m_tim->time_active = false; // deactivate // // store the lowest next active time of inactive processes - if(m_tim->next_active_time < lowest_next_active){ + if (m_tim->next_active_time < lowest_next_active) + { lowest_next_active = m_tim->next_active_time; inactive_tim = m_tim; } @@ -1015,24 +1047,28 @@ void Problem::SetTimeActiveProcesses() } // // Check if we should shift time step slightly to hit a non-active process - if(inactive_tim){ - tval = next_time + dt/1.0e3; // a small dt increase is better than a miniscule dt on the next step - if(tval > lowest_next_active){ // allow this slight increase + if (inactive_tim) + { + tval = next_time + dt / 1.0e3; // a small dt increase is better than a miniscule dt on the next step + if (tval > lowest_next_active) + { // allow this slight increase inactive_tim->time_active = true; dt = lowest_next_active - current_time; next_time = current_time + dt; } - else if(tval+dt > lowest_next_active){ // Try to smooth to the target time from 2 time steps away - dt = (lowest_next_active - current_time)/2.0; + else if (tval + dt > lowest_next_active) + { // Try to smooth to the target time from 2 time steps away + dt = (lowest_next_active - current_time) / 2.0; next_time = current_time + dt; } } // // Set times for all active processes - for(ii=0; iiTim; - if(m_tim->time_active){ + if (m_tim->time_active) + { m_tim->time_step_length = next_time - m_tim->last_active_time; m_tim->last_active_time = next_time; } @@ -1057,22 +1093,22 @@ void Problem::Euler_TimeDiscretize() CTimeDiscretization* m_tim = NULL; aktueller_zeitschritt = 0; ScreenMessage("\n\n***Start time steps\n"); - // - // Output zero time initial values -#if defined(USE_MPI) || defined(USE_MPI_KRC) - if(mrank == 0) +// +// Output zero time initial values +#if defined(USE_MPI) || defined(USE_MPI_KRC) + if (mrank == 0) { #endif - OUTData(current_time,aktueller_zeitschritt,true); + OUTData(current_time, aktueller_zeitschritt, true); #if defined(USE_MPI) || defined(USE_MPI_KRC) } #endif // check if this is a steady state simulation bool isSteadySimulation = true; - for(i=0; i<(int)active_process_index.size(); i++) + for (i = 0; i < (int)active_process_index.size(); i++) { - if (total_processes[active_process_index[i]]->tim_type!=TimType::STEADY) + if (total_processes[active_process_index[i]]->tim_type != TimType::STEADY) { isSteadySimulation = false; break; @@ -1084,19 +1120,21 @@ void Problem::Euler_TimeDiscretize() // PERFORM TRANSIENT SIMULATION // ------------------------------------------ double previous_rejected_dt = .0; - while(end_time > current_time) + while (end_time > current_time) { // Get time step dt = dt_rec = DBL_MAX; - for(i=0; i<(int)active_process_index.size(); i++) + for (i = 0; i < (int)active_process_index.size(); i++) { m_tim = total_processes[active_process_index[i]]->Tim; - if(!m_tim->time_active) continue; // JT - dt = MMin(dt,m_tim->CalcTimeStep(current_time)); - dt_rec = MMin(dt_rec,m_tim->recommended_time_step); // to know if we have a critical time alteration + if (!m_tim->time_active) + continue; // JT + dt = MMin(dt, m_tim->CalcTimeStep(current_time)); + dt_rec = MMin(dt_rec, m_tim->recommended_time_step); // to know if we have a critical time alteration } - if (!last_dt_accepted && dt==previous_rejected_dt) { + if (!last_dt_accepted && dt == previous_rejected_dt) + { ScreenMessage("Stop this simulation. New time step size is same as the rejected one.\n"); break; } @@ -1104,65 +1142,73 @@ void Problem::Euler_TimeDiscretize() SetTimeActiveProcesses(); // JT2012: Activate or deactivate processes with independent time stepping // #if defined(USE_MPI) - MPI_Bcast(&dt, 1, MPI_DOUBLE, 0, comm_DDC); // all processes use the same time stepping (JT->WW. Must they always?) + MPI_Bcast( + &dt, 1, MPI_DOUBLE, 0, comm_DDC); // all processes use the same time stepping (JT->WW. Must they always?) #endif -// + // // Update time settings aktueller_zeitschritt++; current_time += dt; aktuelle_zeit = current_time; - // - // Print messsage -#if defined(USE_PETSC) ||defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_GEMS) - if(mrank == 0) +// +// Print messsage +#if defined(USE_PETSC) || defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) \ + || defined(USE_MPI_GEMS) + if (mrank == 0) { #endif - std::cout << "\n\n#############################################################\n"; - std::cout << "Time step: " << aktueller_zeitschritt << "| Time: " << - current_time << "| Time step size: " << dt << "\n"; - if(dt_rec > dt){ - std::cout << "This time step size was modified to match a critical time!" << "\n"; - } -#if defined(USE_PETSC) ||defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_GEMS) + std::cout << "\n\n#############################################################\n"; + std::cout << "Time step: " << aktueller_zeitschritt << "| Time: " << current_time + << "| Time step size: " << dt << "\n"; + if (dt_rec > dt) + { + std::cout << "This time step size was modified to match a critical time!" + << "\n"; + } +#if defined(USE_PETSC) || defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) \ + || defined(USE_MPI_GEMS) } #endif - if(CouplingLoop()) + if (CouplingLoop()) { // --------------------------------- // TIME STEP ACCEPTED // --------------------------------- last_dt_accepted = true; -#if defined(USE_PETSC) ||defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_GEMS) - if(mrank == 0) +#if defined(USE_PETSC) || defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) \ + || defined(USE_MPI_GEMS) + if (mrank == 0) #endif - ScreenMessage("This step is accepted.\n"); + ScreenMessage("This step is accepted.\n"); PostCouplingLoop(); - if(print_result) + if (print_result) { - if(current_time < end_time) + if (current_time < end_time) force_output = false; else // JT: Make sure we printout on last time step force_output = true; #if defined(USE_MPI) || defined(USE_MPI_KRC) - if(myrank == 0) + if (myrank == 0) { #endif // - OUTData(current_time, aktueller_zeitschritt,force_output); + OUTData(current_time, aktueller_zeitschritt, force_output); #if defined(USE_MPI) } #endif } accepted_times++; - for(i=0; i<(int)active_process_index.size(); i++) + for (i = 0; i < (int)active_process_index.size(); i++) { m_tim = total_processes[active_process_index[i]]->Tim; - if(m_tim->time_active) m_tim->accepted_step_count++; + if (m_tim->time_active) + m_tim->accepted_step_count++; } } else if (isSteadySimulation) { - ScreenMessage("This time step is rejected. We stop the simulation because this is steady state simulation.\n"); + ScreenMessage( + "This time step is rejected. We stop the simulation because this is steady state simulation.\n"); break; } else @@ -1179,26 +1225,28 @@ void Problem::Euler_TimeDiscretize() previous_rejected_dt = dt; // // decrement active dt, and increment count - for(i=0; i<(int)active_process_index.size(); i++) + for (i = 0; i < (int)active_process_index.size(); i++) { m_tim = total_processes[active_process_index[i]]->Tim; - if(!m_tim->time_active) + if (!m_tim->time_active) continue; m_tim->rejected_step_count++; m_tim->last_active_time -= dt; m_tim->step_current--; m_tim->repeat = true; - m_tim->last_rejected_timestep = aktueller_zeitschritt+1; + m_tim->last_rejected_timestep = aktueller_zeitschritt + 1; // // Copy nodal values in reverse - if(isDeformationProcess(total_processes[active_process_index[i]]->getProcessType())) + if (isDeformationProcess(total_processes[active_process_index[i]]->getProcessType())) continue; total_processes[active_process_index[i]]->CopyTimestepNODValues(false); - // JT: This wasn't done before. Is it needed? // total_processes[active_process_index[i]]->CopyTimestepELEValues(false); + // JT: This wasn't done before. Is it needed? // + // total_processes[active_process_index[i]]->CopyTimestepELEValues(false); } - for(i = 0; i < (int)total_processes.size(); i++) + for (i = 0; i < (int)total_processes.size(); i++) { - if(!active_processes[i] && total_processes[i] && total_processes[i]->tim_type==TimType::STEADY) { + if (!active_processes[i] && total_processes[i] && total_processes[i]->tim_type == TimType::STEADY) + { m_tim = total_processes[i]->Tim; m_tim->step_current--; m_tim->repeat = true; @@ -1206,43 +1254,51 @@ void Problem::Euler_TimeDiscretize() } } ScreenMessage("\n#############################################################\n"); - if(aktueller_zeitschritt >= max_time_steps) + if (aktueller_zeitschritt >= max_time_steps) break; -// // executing only one time step for profiling -// current_time = end_time; + // // executing only one time step for profiling + // current_time = end_time; } -#if defined(USE_PETSC) ||defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_GEMS) || defined(USE_MPI_KRC) - if(mrank == 0) +#if defined(USE_PETSC) || defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) \ + || defined(USE_MPI_GEMS) || defined(USE_MPI_KRC) + if (mrank == 0) { #endif - std::cout << "\n----------------------------------------------------\n"; - for(i=0; i<(int)active_process_index.size(); i++) // JT2012 - { - m_tim = total_processes[active_process_index[i]]->Tim; - std::cout << "\nFor process: " << convertProcessTypeToString(total_processes[active_process_index[i]]->getProcessType()) << "\n"; - if(m_tim->time_control_type == TimeControlType::FIXED_STEPS){ - std::cout << "No time control for this process." << "\n"; - } - else{ - std::cout << "Accepted time steps: " << m_tim->accepted_step_count << "\n"; - std::cout << "Rejected time steps: " << m_tim->rejected_step_count << "\n"; - } - if(total_processes[active_process_index[i]]->m_num->nls_max_iterations > 1){ - std::cout << "Number of non-converged iterations: " << total_processes[active_process_index[i]]->num_notsatisfied << "\n"; - std::cout << "Number of stagnated iterations: " << total_processes[active_process_index[i]]->num_diverged << "\n"; + std::cout << "\n----------------------------------------------------\n"; + for (i = 0; i < (int)active_process_index.size(); i++) // JT2012 + { + m_tim = total_processes[active_process_index[i]]->Tim; + std::cout << "\nFor process: " + << convertProcessTypeToString(total_processes[active_process_index[i]]->getProcessType()) << "\n"; + if (m_tim->time_control_type == TimeControlType::FIXED_STEPS) + { + std::cout << "No time control for this process." + << "\n"; + } + else + { + std::cout << "Accepted time steps: " << m_tim->accepted_step_count << "\n"; + std::cout << "Rejected time steps: " << m_tim->rejected_step_count << "\n"; + } + if (total_processes[active_process_index[i]]->m_num->nls_max_iterations > 1) + { + std::cout << "Number of non-converged iterations: " + << total_processes[active_process_index[i]]->num_notsatisfied << "\n"; + std::cout << "Number of stagnated iterations: " + << total_processes[active_process_index[i]]->num_diverged << "\n"; + } } - } - std::cout<<"\n----------------------------------------------------\n"; -#if defined(USE_PETSC) ||defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_GEMS) || defined(USE_MPI_KRC) + std::cout << "\n----------------------------------------------------\n"; +#if defined(USE_PETSC) || defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) \ + || defined(USE_MPI_GEMS) || defined(USE_MPI_KRC) -#if defined(USE_PETSC) //05.2014. WW - for (size_t i = 0; i < out_vector.size(); i++) - { - out_vector[i]->NODDomainWriteBinary_Header(); - } +#if defined(USE_PETSC) // 05.2014. WW + for (size_t i = 0; i < out_vector.size(); i++) + { + out_vector[i]->NODDomainWriteBinary_Header(); + } #endif - } #endif } @@ -1261,7 +1317,7 @@ bool Problem::CouplingLoop() { int i, index, cpl_index; double max_outer_error, max_inner_error; //, error; - bool transient_bc = false; + bool transient_bc = false; bool run_flag[max_processes]; int outer_index, inner_index, inner_max; //, inner_min; // @@ -1272,17 +1328,18 @@ bool Problem::CouplingLoop() print_result = false; int acounter = 0; // - for(i=0; i<(int)pcs_vector.size(); i++){ - pcs_vector[i]-> UpdateTransientBC(); - if(pcs_vector[i]->bc_transient_index.size() != 0) - transient_bc = true; - } - if(transient_bc) - pcs_vector[0]->WriteBC(); - - for(i = 0; i < (int)total_processes.size(); i++) + for (i = 0; i < (int)pcs_vector.size(); i++) + { + pcs_vector[i]->UpdateTransientBC(); + if (pcs_vector[i]->bc_transient_index.size() != 0) + transient_bc = true; + } + if (transient_bc) + pcs_vector[0]->WriteBC(); + + for (i = 0; i < (int)total_processes.size(); i++) { - if(active_processes[i] && total_processes[i]->selected) + if (active_processes[i] && total_processes[i]->selected) { exe_flag[i] = true; m_tim = total_processes[i]->Tim; @@ -1294,112 +1351,130 @@ bool Problem::CouplingLoop() total_processes[i]->iter_lin_max = 0; } else - { //21.05.2010. WW - if(total_processes[i] && total_processes[i]->tim_type == TimType::STEADY) { + { // 21.05.2010. WW + if (total_processes[i] && total_processes[i]->tim_type == TimType::STEADY) + { acounter++; m_tim = total_processes[i]->Tim; - m_tim->step_current++; //NW increment needed to get correct time step length in CTimeDiscretization::CalcTimeStep() + m_tim->step_current++; // NW increment needed to get correct time step length in + // CTimeDiscretization::CalcTimeStep() } exe_flag[i] = false; } } int num_processes = (int)active_process_index.size(); // - // JT: All active processes must run on the overall loop. Strange this wasn't the case before. - for(i=0; i<(int)total_processes.size(); i++){ - run_flag[i] = exe_flag[i]; - } - for(i=0; ifirst_coupling_iteration = true; } // // To do - //SB->WW I do not understand this condition, why switch off output? - //WW Reason: + // SB->WW I do not understand this condition, why switch off output? + // WW Reason: /// Make output when all defined processes are activated. - //JT->WW->SB: I agree with SB. Just b/c one process is deactivated doesn't mean we don't want output for the others. - //if(acounter == num_processes) + // JT->WW->SB: I agree with SB. Just b/c one process is deactivated doesn't mean we don't want output for the + // others. + // if(acounter == num_processes) print_result = true; // bool accept = true; max_outer_error = 0.0; - for(outer_index = 0; outer_index < cpl_overall_max_iterations; outer_index++) + for (outer_index = 0; outer_index < cpl_overall_max_iterations; outer_index++) { - // JT: All active processes must run on the overall loop. Strange this wasn't the case before. - for(i=0; iTim; - if(!m_tim->time_active) run_flag[index] = false; - } - - max_outer_error = 0.0; //NW reset error for each iteration - for(i = 0; i < num_processes; i++) + run_flag[index] = exe_flag[index]; + } + for (i = 0; i < num_processes; i++) + { + index = active_process_index[i]; + m_tim = total_processes[index]->Tim; + if (!m_tim->time_active) + run_flag[index] = false; + } + + max_outer_error = 0.0; // NW reset error for each iteration + for (i = 0; i < num_processes; i++) { index = active_process_index[i]; - if(!run_flag[index]) continue; //JT: may have been turned off after an inner loop! + if (!run_flag[index]) + continue; // JT: may have been turned off after an inner loop! cpl_index = coupled_process_index[index]; // // PERFORM AN INNER COUPLING // --------------------------------------- - if(cpl_index >= 0 && run_flag[cpl_index]) + if (cpl_index >= 0 && run_flag[cpl_index]) { a_pcs = total_processes[index]; b_pcs = total_processes[cpl_index]; // inner_max = a_pcs->m_num->cpl_max_iterations; -// inner_min = a_pcs->m_num->cpl_min_iterations; // variable set but never used + // inner_min = a_pcs->m_num->cpl_min_iterations; // variable set but never used // a_pcs->iter_outer_cpl = outer_index; b_pcs->iter_outer_cpl = outer_index; // max_inner_error = 0.0; - for(inner_index=0; inner_index < a_pcs->m_num->cpl_max_iterations; inner_index++) + for (inner_index = 0; inner_index < a_pcs->m_num->cpl_max_iterations; inner_index++) { - a_pcs->iter_inner_cpl = inner_index; - b_pcs->iter_inner_cpl = inner_index; - // - // FIRST PROCESS - loop_process_number = i; - if(a_pcs->first_coupling_iteration) PreCouplingLoop(a_pcs); -// error = Call_Member_FN(this, active_processes[index])(); - Call_Member_FN(this, active_processes[index])(); - if(!a_pcs->TimeStepAccept()){ - accept = false; - break; - } - // - // COUPLED PROCESS - loop_process_number = i+1; - if(b_pcs->first_coupling_iteration) PreCouplingLoop(b_pcs); -// error = Call_Member_FN(this, active_processes[cpl_index])(); - Call_Member_FN(this, active_processes[cpl_index])(); - if(!b_pcs->TimeStepAccept()){ - accept = false; - break; - } - // - // Check for break criteria - max_inner_error = MMax(a_pcs->cpl_max_relative_error,b_pcs->cpl_max_relative_error); - a_pcs->first_coupling_iteration = false; // No longer true (JT: these are important, and are also used elswhere). - b_pcs->first_coupling_iteration = false; // No longer true. - // - // Store the outer loop error - if(inner_index==0) - max_outer_error = MMax(max_outer_error,max_inner_error); - // - std::cout << "\n======================================================\n"; - std::cout << "Inner coupling loop " << inner_index+1 << "/" << inner_max << " complete."<<"\n"; - std::cout << "Max coupling error (relative to tolerance): " << max_inner_error << "\n"; - std::cout << "======================================================\n"; - // - // Coupling convergence criteria (use loop minimum from a_pcs because this is where the coupled process was called) - if(max_inner_error <= 1.0 && inner_index+2 > a_pcs->m_num->cpl_min_iterations) // JT: error is relative to the tolerance. - break; + a_pcs->iter_inner_cpl = inner_index; + b_pcs->iter_inner_cpl = inner_index; + // + // FIRST PROCESS + loop_process_number = i; + if (a_pcs->first_coupling_iteration) + PreCouplingLoop(a_pcs); + // error = Call_Member_FN(this, active_processes[index])(); + Call_Member_FN(this, active_processes[index])(); + if (!a_pcs->TimeStepAccept()) + { + accept = false; + break; + } + // + // COUPLED PROCESS + loop_process_number = i + 1; + if (b_pcs->first_coupling_iteration) + PreCouplingLoop(b_pcs); + // error = Call_Member_FN(this, active_processes[cpl_index])(); + Call_Member_FN(this, active_processes[cpl_index])(); + if (!b_pcs->TimeStepAccept()) + { + accept = false; + break; + } + // + // Check for break criteria + max_inner_error = MMax(a_pcs->cpl_max_relative_error, b_pcs->cpl_max_relative_error); + a_pcs->first_coupling_iteration + = false; // No longer true (JT: these are important, and are also used elswhere). + b_pcs->first_coupling_iteration = false; // No longer true. + // + // Store the outer loop error + if (inner_index == 0) + max_outer_error = MMax(max_outer_error, max_inner_error); + // + std::cout << "\n======================================================\n"; + std::cout << "Inner coupling loop " << inner_index + 1 << "/" << inner_max << " complete." + << "\n"; + std::cout << "Max coupling error (relative to tolerance): " << max_inner_error << "\n"; + std::cout << "======================================================\n"; + // + // Coupling convergence criteria (use loop minimum from a_pcs because this is where the coupled + // process was called) + if (max_inner_error <= 1.0 + && inner_index + 2 + > a_pcs->m_num->cpl_min_iterations) // JT: error is relative to the tolerance. + break; } run_flag[cpl_index] = false; // JT: CRUCIAL!! } @@ -1412,19 +1487,22 @@ bool Problem::CouplingLoop() a_pcs->iter_inner_cpl = 0; // loop_process_number = i; - if(a_pcs->first_coupling_iteration) PreCouplingLoop(a_pcs); -// error = Call_Member_FN(this, active_processes[index])(); // TF: error set, but never used + if (a_pcs->first_coupling_iteration) + PreCouplingLoop(a_pcs); + // error = Call_Member_FN(this, active_processes[index])(); // TF: error set, but never + // used Call_Member_FN(this, active_processes[index])(); - if(!a_pcs->TimeStepAccept()){ - accept = false; - break; + if (!a_pcs->TimeStepAccept()) + { + accept = false; + break; } a_pcs->first_coupling_iteration = false; // No longer true. // Check for break criteria - max_outer_error = MMax(max_outer_error,a_pcs->cpl_max_relative_error); + max_outer_error = MMax(max_outer_error, a_pcs->cpl_max_relative_error); - // Reapply BCs if constrained BC -#if defined(USE_MPI) || defined (USE_PETSC) +// Reapply BCs if constrained BC +#if defined(USE_MPI) || defined(USE_PETSC) int has_constrained_bc_i = a_pcs->hasConstrainedBC() ? 1 : 0; int n_has_constrained_bc = 0; #ifdef USE_PETSC @@ -1433,15 +1511,15 @@ bool Problem::CouplingLoop() MPI_Comm comm = comm_DDC; #endif MPI_Allreduce(&has_constrained_bc_i, &n_has_constrained_bc, 1, MPI_INT, MPI_SUM, comm); - if(n_has_constrained_bc > 0) - /* Commented out the following codes because MPI_C_BOOL is supported from the MPI 2.2 - bool has_constrained_bc_i = a_pcs->hasConstrainedBC(); - bool has_constrained_bc = false; - MPI_Allreduce(&has_constrained_bc_i, &has_constrained_bc, 1, MPI_C_BOOL, MPI_LOR, MPI_COMM_WORLD); - if(has_constrained_bc > 0) - */ + if (n_has_constrained_bc > 0) +/* Commented out the following codes because MPI_C_BOOL is supported from the MPI 2.2 +bool has_constrained_bc_i = a_pcs->hasConstrainedBC(); +bool has_constrained_bc = false; +MPI_Allreduce(&has_constrained_bc_i, &has_constrained_bc, 1, MPI_C_BOOL, MPI_LOR, MPI_COMM_WORLD); +if(has_constrained_bc > 0) +*/ #else - if(a_pcs->hasConstrainedBC()) + if (a_pcs->hasConstrainedBC()) #endif { #if defined(USE_MPI) || defined(USE_PETSC) @@ -1449,45 +1527,54 @@ bool Problem::CouplingLoop() #else const int rank = -1; #endif - if (rank<1) std::cout << "this process has constrained BCs. reapply BCs." << std::endl; + if (rank < 1) + std::cout << "this process has constrained BCs. reapply BCs." << std::endl; a_pcs->IncorporateBoundaryConditions(rank); } } - if(!accept) break; + if (!accept) + break; } - if(!accept){ + if (!accept) + { std::cout << "\n"; break; } // - if(cpl_overall_max_iterations > 1){ + if (cpl_overall_max_iterations > 1) + { std::cout << "\n======================================================\n"; - std::cout << "Outer coupling loop " << outer_index+1 << "/" << cpl_overall_max_iterations << " complete."<<"\n"; + std::cout << "Outer coupling loop " << outer_index + 1 << "/" << cpl_overall_max_iterations << " complete." + << "\n"; std::cout << "Max coupling error (relative to tolerance): " << max_outer_error << "\n"; std::cout << "======================================================\n"; - //update max cpl error variable in all processes - for (std::size_t i(0); icpl_max_relative_error_overall = max_outer_error; } - } - else{ + } + else + { std::cout << "\n"; - } + } // Coupling convergence criteria - //if(max_outer_error <= 1.0 && outer_index+2 > cpl_overall_min_iterations) // JT: error is relative to the tolerance. //MW outer_index + 2 is hard to follow - is it faster to write it like this? - if(max_outer_error <= 1.0 && outer_index+1 >= cpl_overall_min_iterations) // JT: error is relative to the tolerance. + // if(max_outer_error <= 1.0 && outer_index+2 > cpl_overall_min_iterations) // JT: error is relative to the + // tolerance. //MW outer_index + 2 is hard to follow - is it faster to write it like this? + if (max_outer_error <= 1.0 + && outer_index + 1 >= cpl_overall_min_iterations) // JT: error is relative to the tolerance. break; - //MW - if(max_outer_error > 1 && outer_index+1 == cpl_overall_max_iterations && cpl_overall_max_iterations>1) //m_tim->step_current>1 && - { - accept = false; - break; - } + // MW + if (max_outer_error > 1 && outer_index + 1 == cpl_overall_max_iterations + && cpl_overall_max_iterations > 1) // m_tim->step_current>1 && + { + accept = false; + break; + } } // return accept; @@ -1500,31 +1587,33 @@ bool Problem::CouplingLoop() 03/2012 JT Modification: -------------------------------------------------------------------------*/ -void Problem::PreCouplingLoop(CRFProcess *m_pcs) +void Problem::PreCouplingLoop(CRFProcess* m_pcs) { - if(!last_dt_accepted || force_post_node_copy) // if last time step not accepted or values were already copied. + if (!last_dt_accepted || force_post_node_copy) // if last time step not accepted or values were already copied. return; // /*For mass transport this routine is only called once (for the overall transport process) and so we need to copy for all transport components*/ - if(m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) + if (m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) { - CRFProcess *c_pcs = NULL; - for(size_t i=0; igetProcessType() == FiniteElement::MASS_TRANSPORT){ + if (c_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) + { c_pcs->CopyTimestepNODValues(); c_pcs->CopyTimestepELEValues(); } } } - else{ // Otherwise, just copy this process + else + { // Otherwise, just copy this process m_pcs->CopyTimestepNODValues(); m_pcs->CopyTimestepELEValues(); } } - /*----------------------------------------------------------------------- GeoSys - Function: post Coupling loop Task: @@ -1536,20 +1625,20 @@ void Problem::PreCouplingLoop(CRFProcess *m_pcs) void Problem::PostCouplingLoop() { CRFProcess* m_pcs = NULL; - bool prqvec = false; - bool capvec = false; + bool prqvec = false; + bool capvec = false; if (total_processes[12]) { CRFProcessDeformation* dm_pcs = (CRFProcessDeformation*)(total_processes[12]); - bool doPostExcav = false;//WX - for(size_t l=0; lGetBoolExcavated()) doPostExcav = true; } - if(dm_pcs->ExcavMaterialGroup>=0||doPostExcav) - dm_pcs->PostExcavation();//WX:07.2011 - if(dm_pcs->UpdateIniState==1)//WX:10.2011 + if (dm_pcs->ExcavMaterialGroup >= 0 || doPostExcav) + dm_pcs->PostExcavation(); // WX:07.2011 + if (dm_pcs->UpdateIniState == 1) // WX:10.2011 dm_pcs->UpdateIniStateValue(); if (H_Process && dm_pcs->type / 10 != 4) // HM partitioned scheme @@ -1558,68 +1647,76 @@ void Problem::PostCouplingLoop() dm_pcs->WriteGaussPointStress(); } -// Reaction postprocessing - if (REACT_CAP_vec.size() > 0) capvec = true; - - - if( (KinReactData_vector.size() > 0) || (REACT_vec.size()>0) || capvec || prqvec ){ - // map concentrations in radial model - if( KinReactData_vector.size() > 0) - if(KinReactData_vector[0]->copy_concentrations ) - KinReactData_vector[0]->CopyConcentrations(); - if(transport_processes.size()>0){ - if(total_processes[3] || total_processes[4]) - if(KNaplDissCheck()){ // Check if NAPLdissolution is modeled - // return P_new, and Phase_volumina - CalcNewPhasePressure(); - } - } - // update porosities and permeabilities from reactions - if(REACTINT_vec.size()>0) - REACTINT_vec[0]->ReactionPostProcessing(false); - if( KinReactData_vector.size() > 0){ - if(KinReactData_vector[0]->NumberMineralkinetics>0) - KinReactData_vector[0]->PostprocessMinKin(); // Set Mineral surface areas for next time step based on deltaC - } - m_pcs = PCSGetFlow(); - m_pcs->Extropolation_GaussValue(); - } + // Reaction postprocessing + if (REACT_CAP_vec.size() > 0) + capvec = true; + if ((KinReactData_vector.size() > 0) || (REACT_vec.size() > 0) || capvec || prqvec) + { + // map concentrations in radial model + if (KinReactData_vector.size() > 0) + if (KinReactData_vector[0]->copy_concentrations) + KinReactData_vector[0]->CopyConcentrations(); + if (transport_processes.size() > 0) + { + if (total_processes[3] || total_processes[4]) + if (KNaplDissCheck()) + { // Check if NAPLdissolution is modeled + // return P_new, and Phase_volumina + CalcNewPhasePressure(); + } + } + // update porosities and permeabilities from reactions + if (REACTINT_vec.size() > 0) + REACTINT_vec[0]->ReactionPostProcessing(false); + if (KinReactData_vector.size() > 0) + { + if (KinReactData_vector[0]->NumberMineralkinetics > 0) + KinReactData_vector[0] + ->PostprocessMinKin(); // Set Mineral surface areas for next time step based on deltaC + } + m_pcs = PCSGetFlow(); + m_pcs->Extropolation_GaussValue(); + } // Update the results for (int i = 0; i < (int)pcs_vector.size(); i++) { m_pcs = pcs_vector[i]; - if (hasAnyProcessDeactivatedSubdomains&&m_pcs->ExcavMaterialGroup<0) //NW - //WX:11.2012 when excavated, not do CheckMarkedElement + if (hasAnyProcessDeactivatedSubdomains && m_pcs->ExcavMaterialGroup < 0) // NW + // WX:11.2012 when excavated, not do CheckMarkedElement m_pcs->CheckMarkedElement(); -#if defined(USE_MPI) // 18.10.2007 WW +#if defined(USE_MPI) // 18.10.2007 WW if (myrank == 0) { #endif - m_pcs->WriteSolution(); //WW + m_pcs->WriteSolution(); // WW #ifdef GEM_REACT - if (i == 0) // for GEM_REACT we also need information on porosity (node porosity internally stored in Gems process)!....do it only once and it does not matter for which process ! ....we assume that the first pcs process is the flow process...if reload not defined for every process, restarting with gems will not work in any case + if (i == 0) // for GEM_REACT we also need information on porosity (node porosity internally stored in Gems + // process)!....do it only once and it does not matter for which process ! ....we assume that + // the first pcs process is the flow process...if reload not defined for every process, + // restarting with gems will not work in any case - if (( m_pcs->reload == 1 || - m_pcs->reload == 3 ) && - !(( aktueller_zeitschritt % m_pcs->nwrite_restart ) > 0) ) - m_vec_GEM->WriteReloadGem(); + if ((m_pcs->reload == 1 || m_pcs->reload == 3) + && !((aktueller_zeitschritt % m_pcs->nwrite_restart) > 0)) + m_vec_GEM->WriteReloadGem(); #endif -#if defined(USE_MPI) // 18.10.2007 WW - } +#if defined(USE_MPI) // 18.10.2007 WW + } #endif - m_pcs->Extropolation_MatValue(); //WW - if (m_pcs->cal_integration_point_value) //WW + m_pcs->Extropolation_MatValue(); // WW + if (m_pcs->cal_integration_point_value) // WW m_pcs->Extropolation_GaussValue(); - //BG - if ((m_pcs->simulator == "ECLIPSE") || (m_pcs->simulator == "DUMUX")){ + // BG + if ((m_pcs->simulator == "ECLIPSE") || (m_pcs->simulator == "DUMUX")) + { m_pcs->Extropolation_GaussValue(); } // JT: Now done in PreCouplingLoop() // m_pcs->CopyTimestepNODValues(); //MB - if(force_post_node_copy){ // JT: safety valve. Set this value to true (in Problem()) and values will be copied here. + if (force_post_node_copy) + { // JT: safety valve. Set this value to true (in Problem()) and values will be copied here. m_pcs->CopyTimestepNODValues(); m_pcs->CopyTimestepELEValues(); } @@ -1633,12 +1730,12 @@ void Problem::PostCouplingLoop() LOPCalcELEResultants(); } -const GEOLIB::GEOObjects* Problem::getGeoObj () const +const GEOLIB::GEOObjects* Problem::getGeoObj() const { return _geo_obj; } -const std::string& Problem::getGeoObjName () const +const std::string& Problem::getGeoObjName() const { return _geo_name; } @@ -1656,41 +1753,44 @@ inline double Problem::LiquidFlow() int success; double error = 0.; CRFProcess* m_pcs = total_processes[6]; - if(!m_pcs->selected) + if (!m_pcs->selected) return error; // error = m_pcs->Execute(); // Cases: decide, weather to use GEOSYS, ECLIPSE or DuMux; BG 10/2010 - if((m_pcs->simulator.compare("GEOSYS") == 0)) // ||(m_pcs->simulator.compare("ECLIPSE")==0)){ // standard: use GeoSys + if ((m_pcs->simulator.compare("GEOSYS") + == 0)) // ||(m_pcs->simulator.compare("ECLIPSE")==0)){ // standard: use GeoSys { error = m_pcs->ExecuteNonLinear(loop_process_number); #ifdef RESET_4410 PCSCalcSecondaryVariables(); // PCS member function #endif - m_pcs->CalIntegrationPointValue(); //WW - if(m_pcs->tim_type == TimType::STEADY) + m_pcs->CalIntegrationPointValue(); // WW + if (m_pcs->tim_type == TimType::STEADY) m_pcs->selected = false; } - if(m_pcs->simulator.compare("ECLIPSE") == 0) // use ECLIPSE to calculate one phase liquid flow, BG + if (m_pcs->simulator.compare("ECLIPSE") == 0) // use ECLIPSE to calculate one phase liquid flow, BG { - if(m_pcs->EclipseData == NULL) //SBG if this is the first call, make a new instance + if (m_pcs->EclipseData == NULL) // SBG if this is the first call, make a new instance m_pcs->EclipseData = new CECLIPSEData(); // call ECLIPSE interface success = m_pcs->EclipseData->RunEclipse(m_pcs->Tim->step_current, m_pcs); if (success == 0) - std::cout << "Error running Eclipse!" << "\n"; - if(m_pcs->tim_type == TimType::STEADY) + std::cout << "Error running Eclipse!" + << "\n"; + if (m_pcs->tim_type == TimType::STEADY) m_pcs->selected = false; } else if (m_pcs->simulator.compare("DUMUX") == 0) { - if(m_pcs->DuMuxData == NULL) //SBG if this is the first call, make a new instance + if (m_pcs->DuMuxData == NULL) // SBG if this is the first call, make a new instance m_pcs->DuMuxData = new CDUMUXData(); // call DUMUX interface success = m_pcs->DuMuxData->RunDuMux(m_pcs->Tim->step_current, m_pcs); if (success == 0) - std::cout << "Error running DuMux!" << "\n"; + std::cout << "Error running DuMux!" + << "\n"; } return error; @@ -1709,52 +1809,52 @@ inline double Problem::RichardsFlow() //------- WW double error = 0.; CRFProcess* m_pcs = total_processes[2]; - if(!m_pcs->selected) + if (!m_pcs->selected) return error; bool twoflowcpl = false; - //if(GROUNDWATER_FLOW|| OVERLAND_FLOW) WW - if(total_processes[1] || total_processes[6]) + // if(GROUNDWATER_FLOW|| OVERLAND_FLOW) WW + if (total_processes[1] || total_processes[6]) twoflowcpl = true; - if(twoflowcpl) - { //------- WW + if (twoflowcpl) + { //------- WW // JOD coupling lop_coupling_iterations = m_pcs->m_num->cpl_max_iterations; - if(pcs_vector.size() > 1 && lop_coupling_iterations > 1) + if (pcs_vector.size() > 1 && lop_coupling_iterations > 1) m_pcs->CopyCouplingNODValues(); - //WW if(m_pcs->adaption) PCSStorage(); + // WW if(m_pcs->adaption) PCSStorage(); CFEMesh* m_msh = FEMGet("RICHARDS_FLOW"); - if(m_msh->geo_name.compare("REGIONAL") == 0) - LOPExecuteRegionalRichardsFlow(m_pcs,loop_process_number); + if (m_msh->geo_name.compare("REGIONAL") == 0) + LOPExecuteRegionalRichardsFlow(m_pcs, loop_process_number); else error = m_pcs->ExecuteNonLinear(loop_process_number); - if(m_pcs->saturation_switch == true) - m_pcs->CalcSaturationRichards(1, false); // JOD + if (m_pcs->saturation_switch == true) + m_pcs->CalcSaturationRichards(1, false); // JOD else - //WW + // WW m_pcs->CalcSecondaryVariablesUnsaturatedFlow(); - //WW#ifndef NEW_EQS //WW. 07.11.2008 - //WW if(lop_coupling_iterations > 1) // JOD coupling - //WW pcs_coupling_error = m_pcs->CalcCouplingNODError(); - //WW#endif - conducted = true; //WW + // WW#ifndef NEW_EQS //WW. 07.11.2008 + // WW if(lop_coupling_iterations > 1) // JOD coupling + // WW pcs_coupling_error = m_pcs->CalcCouplingNODError(); + // WW#endif + conducted = true; // WW } - else //WW + else // WW { - CFEMesh* m_msh = FEMGet("RICHARDS_FLOW"); //WW - if(m_msh->geo_name.compare("REGIONAL") == 0) - LOPExecuteRegionalRichardsFlow(m_pcs,loop_process_number); + CFEMesh* m_msh = FEMGet("RICHARDS_FLOW"); // WW + if (m_msh->geo_name.compare("REGIONAL") == 0) + LOPExecuteRegionalRichardsFlow(m_pcs, loop_process_number); else error = m_pcs->ExecuteNonLinear(loop_process_number); - if(m_pcs->TimeStepAccept()) + if (m_pcs->TimeStepAccept()) { - //WW + // WW m_pcs->CalcSecondaryVariablesUnsaturatedFlow(); CalcVelocities = true; - conducted = true; //WW + conducted = true; // WW } } - if(m_pcs->TimeStepAccept()) - m_pcs->CalIntegrationPointValue(); //WW + if (m_pcs->TimeStepAccept()) + m_pcs->CalIntegrationPointValue(); // WW return error; } @@ -1772,20 +1872,20 @@ inline double Problem::TwoPhaseFlow() { double error = 1.0e+8; CRFProcess* m_pcs = total_processes[3]; - if(!m_pcs->selected) - return error; //12.12.2008 WW + if (!m_pcs->selected) + return error; // 12.12.2008 WW // - //08.01.2009. WW - for(int i = 0; i < (int)multiphase_processes.size(); i++) + // 08.01.2009. WW + for (int i = 0; i < (int)multiphase_processes.size(); i++) { m_pcs = multiphase_processes[i]; error = m_pcs->ExecuteNonLinear(loop_process_number); - if(m_pcs->TimeStepAccept()) + if (m_pcs->TimeStepAccept()) { PCSCalcSecondaryVariables(); m_pcs->CalIntegrationPointValue(); - //CB 12/09 (first time added on 010808) Velocity at CenterOfGravity, required for NAPL dissolution - if (i == 0) // is 0 in all cases the correct index? + // CB 12/09 (first time added on 010808) Velocity at CenterOfGravity, required for NAPL dissolution + if (i == 0) // is 0 in all cases the correct index? m_pcs->CalcELEVelocities(); } } @@ -1804,66 +1904,73 @@ inline double Problem::TwoPhaseFlow() inline double Problem::MultiPhaseFlow() { double error = 1.0e+8; - int success = 0; // BG + int success = 0; // BG CRFProcess* m_pcs = total_processes[4]; - if(!m_pcs->selected) - return error; //12.12.2008 WW - //initialize density and viscosity if the CO2 phase transition is used + if (!m_pcs->selected) + return error; // 12.12.2008 WW + // initialize density and viscosity if the CO2 phase transition is used if (m_pcs->Phase_Transition_Model == 1) { if (m_pcs->Tim->step_current == 1) { - std::cout << " The Viscosity is not calculated yet!!!" << "\n"; + std::cout << " The Viscosity is not calculated yet!!!" + << "\n"; m_pcs->CalculateFluidDensitiesAndViscositiesAtNodes(m_pcs); } else m_pcs->Phase_Transition_CO2(m_pcs, 1); } - //m_pcs->CalculateFluidDensitiesAndViscositiesAtNodes(m_pcs); + // m_pcs->CalculateFluidDensitiesAndViscositiesAtNodes(m_pcs); // Cases: decide, weather to use GEOSYS, ECLIPSE or DuMux; BG 10/2010 - if((m_pcs->simulator.compare("GEOSYS") == 0)) // ||(m_pcs->simulator.compare("ECLIPSE")==0)){ // standard: use GeoSys + if ((m_pcs->simulator.compare("GEOSYS") + == 0)) // ||(m_pcs->simulator.compare("ECLIPSE")==0)){ // standard: use GeoSys { - //if((m_pcs->simulator.compare("GEOSYS")==0) ||(m_pcs->simulator.compare("ECLIPSE")==0)){ // standard: use GeoSys + // if((m_pcs->simulator.compare("GEOSYS")==0) ||(m_pcs->simulator.compare("ECLIPSE")==0)){ // standard: use + // GeoSys error = m_pcs->ExecuteNonLinear(loop_process_number); - if(m_pcs->TimeStepAccept()) - m_pcs->CalIntegrationPointValue(); //WW + if (m_pcs->TimeStepAccept()) + m_pcs->CalIntegrationPointValue(); // WW } - if(m_pcs->simulator.compare("ECLIPSE") == 0) // use ECLIPSE to calculate multi-phase flow, BG + if (m_pcs->simulator.compare("ECLIPSE") == 0) // use ECLIPSE to calculate multi-phase flow, BG { - if(m_pcs->EclipseData == NULL) //SBG if this is the first call, make a new instance + if (m_pcs->EclipseData == NULL) // SBG if this is the first call, make a new instance m_pcs->EclipseData = new CECLIPSEData(); // redo WTP - m_pcs->EclipseData->dissolved_co2_pcs_name_ECL = m_pcs->dissolved_co2_pcs_name; // hand over process name for storing dissolved CO2 + m_pcs->EclipseData->dissolved_co2_pcs_name_ECL + = m_pcs->dissolved_co2_pcs_name; // hand over process name for storing dissolved CO2 m_pcs->EclipseData->dissolved_co2_ingas_pcs_name_ECL = m_pcs->dissolved_co2_ingas_pcs_name; // call ECLIPSE interface success = m_pcs->EclipseData->RunEclipse(m_pcs->Tim->step_current, m_pcs); if (success == 0) { - std::cout << "Error running Eclipse!" << "\n"; + std::cout << "Error running Eclipse!" + << "\n"; system("Pause"); exit(0); } } else if (m_pcs->simulator.compare("DUMUX") == 0) { - if(m_pcs->DuMuxData == NULL) //SBG if this is the first call, make a new instance + if (m_pcs->DuMuxData == NULL) // SBG if this is the first call, make a new instance { m_pcs->DuMuxData = new CDUMUXData(); - m_pcs->DuMuxData->dissolved_co2_pcs_name_DUMUX = m_pcs->dissolved_co2_pcs_name; // hand over process name for storing dissolved CO2 + m_pcs->DuMuxData->dissolved_co2_pcs_name_DUMUX + = m_pcs->dissolved_co2_pcs_name; // hand over process name for storing dissolved CO2 } // call DUMUX interface success = m_pcs->DuMuxData->RunDuMux(m_pcs->Tim->step_current, m_pcs); if (success == 0) - std::cout << "Error running DuMux!" << "\n"; + std::cout << "Error running DuMux!" + << "\n"; } - //CO2-Phase_Transition BG, NB + // CO2-Phase_Transition BG, NB if ((m_pcs->Phase_Transition_Model == 1) && ((m_pcs->simulator.compare("GEOSYS") == 0))) { - //check if mfp-model for density and viscosity is 18 + // check if mfp-model for density and viscosity is 18 if (m_pcs->Tim->step_current == 1) { CFluidProperties* FluidProp; @@ -1871,20 +1978,22 @@ inline double Problem::MultiPhaseFlow() FluidProp = MFPGet("LIQUID"); if ((FluidProp->density_model != 18) || (FluidProp->viscosity_model != 18)) { - std::cout << - "If the Phase_Transition_Model is used the density model and the viscosity model should be 18!" - << "\n"; - std::cout << "The run is terminated now ..." << "\n"; + std::cout + << "If the Phase_Transition_Model is used the density model and the viscosity model should be 18!" + << "\n"; + std::cout << "The run is terminated now ..." + << "\n"; system("Pause"); exit(0); } FluidProp = MFPGet("GAS"); if ((FluidProp->density_model != 18) || (FluidProp->viscosity_model != 18)) { - std::cout << - "If the Phase_Transition_Model is used the density model and the viscosity model should be 18!" - << "\n"; - std::cout << "The run is terminated now ..." << "\n"; + std::cout + << "If the Phase_Transition_Model is used the density model and the viscosity model should be 18!" + << "\n"; + std::cout << "The run is terminated now ..." + << "\n"; system("Pause"); exit(0); } @@ -1896,13 +2005,13 @@ inline double Problem::MultiPhaseFlow() } } - if(m_pcs->tim_type == TimType::STEADY) + if (m_pcs->tim_type == TimType::STEADY) m_pcs->selected = false; - //TestOutputEclipse(m_pcs); - //TestOutputDuMux(m_pcs); + // TestOutputEclipse(m_pcs); + // TestOutputDuMux(m_pcs); - if (m_pcs->OutputMassOfGasInModel == true) // 05/2012 BG + if (m_pcs->OutputMassOfGasInModel == true) // 05/2012 BG OutputMassOfGasInModel(m_pcs); return error; @@ -1917,8 +2026,8 @@ inline double Problem::MultiPhaseFlow() -------------------------------------------------------------------------*/ void Problem::TestOutputDuMux(CRFProcess* m_pcs) { - //Testoutput amount of co2 in model domain - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt + // Testoutput amount of co2 in model domain + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt MeshLib::CElem* m_ele = NULL; MeshLib::CNode* m_node = NULL; CMediumProperties* m_mat_mp = NULL; @@ -1930,34 +2039,34 @@ void Problem::TestOutputDuMux(CRFProcess* m_pcs) double node_volume; double time; std::string tempstring; - std::vector vec_string; - //int position; + std::vector vec_string; + // int position; std::string path; double density_CO2; double porosity = 0.0; int variable_index; double concentration_CO2_water; int indexConcentration_CO2; - //CRFProcess *n_pcs = NULL; + // CRFProcess *n_pcs = NULL; int group; path = m_pcs->file_name_base; int position = int(path.find_last_of("\\")); std::string path_new; - path_new = path.substr(0,position); - //position = int(path_new.find_last_of("\\")); - //path_new = path_new.substr(0,position); + path_new = path.substr(0, position); + // position = int(path_new.find_last_of("\\")); + // path_new = path_new.substr(0,position); if (m_pcs->DuMuxData->Windows_System == true) tempstring = path_new + "\\Sum_CO2_nodes.csv"; else tempstring = path_new + "Sum_CO2_nodes.csv"; if (m_pcs->Tim->step_current == 1) - //Header of the file + // Header of the file vec_string.push_back("Time, massCO2_gas, massCO2_water, massCO2, porosity"); else { - //read file and store data + // read file and store data CReadTextfiles_DuMux* TextFile; TextFile = new CReadTextfiles_DuMux; TextFile->Read_Text(tempstring); @@ -1968,11 +2077,9 @@ void Problem::TestOutputDuMux(CRFProcess* m_pcs) mass_CO2 = mass_CO2_gas = mass_CO2_water = 0; // +1: new timelevel - indexConcentration_CO2 = - pcs_vector[m_pcs->DuMuxData->ProcessIndex_CO2inLiquid]->GetNodeValueIndex( - pcs_vector[m_pcs-> - DuMuxData - ->ProcessIndex_CO2inLiquid]->pcs_primary_function_name[0]) + 1; + indexConcentration_CO2 = pcs_vector[m_pcs->DuMuxData->ProcessIndex_CO2inLiquid]->GetNodeValueIndex( + pcs_vector[m_pcs->DuMuxData->ProcessIndex_CO2inLiquid]->pcs_primary_function_name[0]) + + 1; for (long i = 0; i < (long)m_msh->nod_vector.size(); i++) { @@ -1991,7 +2098,7 @@ void Problem::TestOutputDuMux(CRFProcess* m_pcs) { m_ele = m_msh->ele_vector[m_node->getConnectedElementIDs()[j]]; - //get the phase volume of current element elem + // get the phase volume of current element elem group = m_ele->GetPatchIndex(); m_mat_mp = mmp_vector[group]; // CB Now provides also heterogeneous porosity, model 11 @@ -2001,21 +2108,21 @@ void Problem::TestOutputDuMux(CRFProcess* m_pcs) //+1... new time level index = m_pcs->GetNodeValueIndex("SATURATION1") + 1; - saturation_water = m_pcs->GetNodeValue(i,index); - //if (saturation_water < 1) + saturation_water = m_pcs->GetNodeValue(i, index); + // if (saturation_water < 1) saturation_CO2 = 1 - saturation_water; - concentration_CO2_water = - pcs_vector[m_pcs->DuMuxData->ProcessIndex_CO2inLiquid]->GetNodeValue( - i, - indexConcentration_CO2); + concentration_CO2_water + = pcs_vector[m_pcs->DuMuxData->ProcessIndex_CO2inLiquid]->GetNodeValue(i, indexConcentration_CO2); mass_CO2_gas = mass_CO2_gas + node_volume * saturation_CO2 * density_CO2; - mass_CO2_water = mass_CO2_water + node_volume * saturation_water * - concentration_CO2_water * m_pcs->DuMuxData->Molweight_CO2 * 0.001; - //cout << " Node: " << i << " saturation: " << saturation_water << " Density_CO2: " << density_CO2 << " node_volume: " << node_volume << "\n"; + mass_CO2_water + = mass_CO2_water + + node_volume * saturation_water * concentration_CO2_water * m_pcs->DuMuxData->Molweight_CO2 * 0.001; + // cout << " Node: " << i << " saturation: " << saturation_water << " Density_CO2: " << density_CO2 << " + // node_volume: " << node_volume << "\n"; } mass_CO2 = mass_CO2_gas + mass_CO2_water; - //calculating time + // calculating time time = 0; for (int k = 0; k < m_pcs->Tim->step_current; k++) time += m_pcs->Tim->time_step_vector[k]; @@ -2050,7 +2157,7 @@ void Problem::TestOutputDuMux(CRFProcess* m_pcs) vec_string.push_back(tempstring); - //within the first timestep create file and write header + // within the first timestep create file and write header CWriteTextfiles_DuMux* TextFile; TextFile = new CWriteTextfiles_DuMux; if (m_pcs->DuMuxData->Windows_System == true) @@ -2059,15 +2166,15 @@ void Problem::TestOutputDuMux(CRFProcess* m_pcs) tempstring = path_new + "Sum_CO2_nodes.csv"; TextFile->Write_Text(tempstring, vec_string); - //Testoutput amount of co2 in model domain calculated at nodes-DuMux - //double element_volume; + // Testoutput amount of co2 in model domain calculated at nodes-DuMux + // double element_volume; Math_Group::vec ele_nodes(8); path = m_pcs->file_name_base; position = int(path.find_last_of("\\")); - path_new = path.substr(0,position); - //position = int(path_new.find_last_of("\\")); - //path_new = path_new.substr(0,position); + path_new = path.substr(0, position); + // position = int(path_new.find_last_of("\\")); + // path_new = path_new.substr(0,position); if (m_pcs->DuMuxData->Windows_System == true) tempstring = path_new + "\\Sum_CO2_nodes_DuMux.csv"; else @@ -2075,11 +2182,11 @@ void Problem::TestOutputDuMux(CRFProcess* m_pcs) vec_string.clear(); if (m_pcs->Tim->step_current == 1) - //Header of the file + // Header of the file vec_string.push_back("Time, massCO2_gas, massCO2_water, massCO2, porosity"); else { - //read file and store data + // read file and store data CReadTextfiles_DuMux* TextFile; TextFile = new CReadTextfiles_DuMux; TextFile->Read_Text(tempstring); @@ -2090,11 +2197,9 @@ void Problem::TestOutputDuMux(CRFProcess* m_pcs) mass_CO2 = mass_CO2_gas = mass_CO2_water = 0; // +1: new timelevel - indexConcentration_CO2 = - pcs_vector[m_pcs->DuMuxData->ProcessIndex_CO2inLiquid]->GetNodeValueIndex( - pcs_vector[m_pcs-> - DuMuxData - ->ProcessIndex_CO2inLiquid]->pcs_primary_function_name[0]) + 1; + indexConcentration_CO2 = pcs_vector[m_pcs->DuMuxData->ProcessIndex_CO2inLiquid]->GetNodeValueIndex( + pcs_vector[m_pcs->DuMuxData->ProcessIndex_CO2inLiquid]->pcs_primary_function_name[0]) + + 1; for (long i = 0; i < (long)m_pcs->DuMuxData->NodeData.size(); i++) { @@ -2108,7 +2213,7 @@ void Problem::TestOutputDuMux(CRFProcess* m_pcs) { m_ele = m_msh->ele_vector[m_node->getConnectedElementIDs()[j]]; - //get the phase volume of current element elem + // get the phase volume of current element elem group = m_ele->GetPatchIndex(); m_mat_mp = mmp_vector[group]; // CB Now provides also heterogeneous porosity, model 11 @@ -2119,17 +2224,19 @@ void Problem::TestOutputDuMux(CRFProcess* m_pcs) saturation_water = m_pcs->DuMuxData->NodeData[i]->getPhaseSaturation()[0]; saturation_CO2 = 1 - saturation_water; - //concentration_CO2_water = pcs_vector[m_pcs->DuMuxData->ProcessIndex_CO2inLiquid]->GetNodeValue(i, indexConcentration_CO2); - concentration_CO2_water = m_pcs->DuMuxData->NodeData[i]->getCO2InLiquid() * - m_pcs->DuMuxData->NodeData[i]->getPhaseDensity()[0] / - (m_pcs->DuMuxData->Molweight_CO2 * 1e-3); + // concentration_CO2_water = pcs_vector[m_pcs->DuMuxData->ProcessIndex_CO2inLiquid]->GetNodeValue(i, + // indexConcentration_CO2); + concentration_CO2_water = m_pcs->DuMuxData->NodeData[i]->getCO2InLiquid() + * m_pcs->DuMuxData->NodeData[i]->getPhaseDensity()[0] + / (m_pcs->DuMuxData->Molweight_CO2 * 1e-3); mass_CO2_gas = mass_CO2_gas + node_volume * saturation_CO2 * density_CO2; - mass_CO2_water = mass_CO2_water + node_volume * saturation_water * - concentration_CO2_water * m_pcs->DuMuxData->Molweight_CO2 * 0.001; + mass_CO2_water + = mass_CO2_water + + node_volume * saturation_water * concentration_CO2_water * m_pcs->DuMuxData->Molweight_CO2 * 0.001; } mass_CO2 = mass_CO2_gas + mass_CO2_water; - //calculating time + // calculating time time = 0; for (int k = 0; k < m_pcs->Tim->step_current; k++) time += m_pcs->Tim->time_step_vector[k]; @@ -2164,7 +2271,7 @@ void Problem::TestOutputDuMux(CRFProcess* m_pcs) vec_string.push_back(tempstring); - //within the first timestep create file and write header + // within the first timestep create file and write header TextFile = new CWriteTextfiles_DuMux; if (m_pcs->DuMuxData->Windows_System == true) tempstring = path_new + "\\Sum_CO2_nodes_DuMux.csv"; @@ -2182,8 +2289,8 @@ void Problem::TestOutputDuMux(CRFProcess* m_pcs) -------------------------------------------------------------------------*/ void Problem::TestOutputEclipse(CRFProcess* m_pcs) { - //Testoutput amount of co2 in model domain calculated at nodes - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt + // Testoutput amount of co2 in model domain calculated at nodes + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt MeshLib::CElem* m_ele = NULL; MeshLib::CNode* m_node = NULL; CMediumProperties* m_mat_mp = NULL; @@ -2195,31 +2302,31 @@ void Problem::TestOutputEclipse(CRFProcess* m_pcs) double node_volume; double time; std::string tempstring; - std::vector vec_string; - //int position; + std::vector vec_string; + // int position; std::string path; double density_CO2; double porosity = 0.0; int variable_index; double concentration_CO2_water; int indexConcentration_CO2; - //CRFProcess *n_pcs = NULL; + // CRFProcess *n_pcs = NULL; int group; path = m_pcs->file_name_base; int position = int(path.find_last_of("\\")); std::string path_new; - path_new = path.substr(0,position); - //position = int(path_new.find_last_of("\\")); - //path_new = path_new.substr(0,position); + path_new = path.substr(0, position); + // position = int(path_new.find_last_of("\\")); + // path_new = path_new.substr(0,position); tempstring = path_new + "\\Sum_CO2_nodes.csv"; if (m_pcs->Tim->step_current == 1) - //Header of the file + // Header of the file vec_string.push_back("Time, massCO2_gas, massCO2_water, massCO2, porosity"); else { - //read file and store data + // read file and store data CReadTextfiles_ECL* TextFile; TextFile = new CReadTextfiles_ECL; TextFile->Read_Text(tempstring); @@ -2230,12 +2337,9 @@ void Problem::TestOutputEclipse(CRFProcess* m_pcs) mass_CO2 = mass_CO2_gas = mass_CO2_water = 0; // +1: new timelevel - indexConcentration_CO2 = - pcs_vector[m_pcs->EclipseData->ProcessIndex_CO2inLiquid]->GetNodeValueIndex( - pcs_vector[m_pcs - -> - EclipseData->ProcessIndex_CO2inLiquid]-> - pcs_primary_function_name[0]) + 1; + indexConcentration_CO2 = pcs_vector[m_pcs->EclipseData->ProcessIndex_CO2inLiquid]->GetNodeValueIndex( + pcs_vector[m_pcs->EclipseData->ProcessIndex_CO2inLiquid]->pcs_primary_function_name[0]) + + 1; for (long i = 0; i < (long)m_msh->nod_vector.size(); i++) { @@ -2254,7 +2358,7 @@ void Problem::TestOutputEclipse(CRFProcess* m_pcs) { m_ele = m_msh->ele_vector[m_node->getConnectedElementIDs()[j]]; - //get the phase volume of current element elem + // get the phase volume of current element elem group = m_ele->GetPatchIndex(); m_mat_mp = mmp_vector[group]; // CB Now provides also heterogeneous porosity, model 11 @@ -2264,22 +2368,21 @@ void Problem::TestOutputEclipse(CRFProcess* m_pcs) //+1... new time level index = m_pcs->GetNodeValueIndex("SATURATION1") + 1; - saturation_water = m_pcs->GetNodeValue(i,index); - //if (saturation_water < 1) + saturation_water = m_pcs->GetNodeValue(i, index); + // if (saturation_water < 1) saturation_CO2 = 1 - saturation_water; - concentration_CO2_water = - pcs_vector[m_pcs->EclipseData->ProcessIndex_CO2inLiquid]->GetNodeValue( - i, - indexConcentration_CO2); + concentration_CO2_water + = pcs_vector[m_pcs->EclipseData->ProcessIndex_CO2inLiquid]->GetNodeValue(i, indexConcentration_CO2); mass_CO2_gas = mass_CO2_gas + node_volume * saturation_CO2 * density_CO2; - mass_CO2_water = mass_CO2_water + node_volume * saturation_water * - concentration_CO2_water * m_pcs->EclipseData->Molweight_CO2 * - 0.001; - //cout << " Node: " << i << " saturation: " << saturation_water << " Density_CO2: " << density_CO2 << " node_volume: " << node_volume << "\n"; + mass_CO2_water + = mass_CO2_water + + node_volume * saturation_water * concentration_CO2_water * m_pcs->EclipseData->Molweight_CO2 * 0.001; + // cout << " Node: " << i << " saturation: " << saturation_water << " Density_CO2: " << density_CO2 << " + // node_volume: " << node_volume << "\n"; } mass_CO2 = mass_CO2_gas + mass_CO2_water; - //calculating time + // calculating time time = 0; for (int k = 0; k < m_pcs->Tim->step_current; k++) time += m_pcs->Tim->time_step_vector[k]; @@ -2314,30 +2417,30 @@ void Problem::TestOutputEclipse(CRFProcess* m_pcs) vec_string.push_back(tempstring); - //within the first timestep create file and write header + // within the first timestep create file and write header CWriteTextfiles_ECL* TextFile; TextFile = new CWriteTextfiles_ECL; tempstring = path_new + "\\Sum_CO2_nodes.csv"; TextFile->Write_Text(tempstring, vec_string); - //Testoutput amount of co2 in model domain calculated at elements + // Testoutput amount of co2 in model domain calculated at elements double element_volume; Math_Group::vec ele_nodes(8); path = m_pcs->file_name_base; position = int(path.find_last_of("\\")); - path_new = path.substr(0,position); - //position = int(path_new.find_last_of("\\")); - //path_new = path_new.substr(0,position); + path_new = path.substr(0, position); + // position = int(path_new.find_last_of("\\")); + // path_new = path_new.substr(0,position); tempstring = path_new + "\\Sum_CO2_elements.csv"; vec_string.clear(); if (m_pcs->Tim->step_current == 1) - //Header of the file + // Header of the file vec_string.push_back("Time, massCO2_gas, massCO2_water, massCO2, porosity"); else { - //read file and store data + // read file and store data CReadTextfiles_ECL* TextFile; TextFile = new CReadTextfiles_ECL; TextFile->Read_Text(tempstring); @@ -2348,12 +2451,9 @@ void Problem::TestOutputEclipse(CRFProcess* m_pcs) mass_CO2 = mass_CO2_gas = mass_CO2_water = 0; // +1: new timelevel - indexConcentration_CO2 = - pcs_vector[m_pcs->EclipseData->ProcessIndex_CO2inLiquid]->GetNodeValueIndex( - pcs_vector[m_pcs - -> - EclipseData->ProcessIndex_CO2inLiquid]-> - pcs_primary_function_name[0]) + 1; + indexConcentration_CO2 = pcs_vector[m_pcs->EclipseData->ProcessIndex_CO2inLiquid]->GetNodeValueIndex( + pcs_vector[m_pcs->EclipseData->ProcessIndex_CO2inLiquid]->pcs_primary_function_name[0]) + + 1; for (long i = 0; i < long(m_pcs->EclipseData->eclgrid.size()); i++) { @@ -2363,13 +2463,9 @@ void Problem::TestOutputEclipse(CRFProcess* m_pcs) element_volume = 0; if (m_pcs->EclipseData->E100 == true) - density_CO2 = - m_pcs->EclipseData->Data[i][m_pcs->EclipseData->GetVariableIndex( - "GAS_DEN")]; + density_CO2 = m_pcs->EclipseData->Data[i][m_pcs->EclipseData->GetVariableIndex("GAS_DEN")]; else - density_CO2 = - m_pcs->EclipseData->Data[i][m_pcs->EclipseData->GetVariableIndex( - "DENG")]; + density_CO2 = m_pcs->EclipseData->Data[i][m_pcs->EclipseData->GetVariableIndex("DENG")]; group = m_ele->GetPatchIndex(); m_mat_mp = mmp_vector[group]; @@ -2377,33 +2473,26 @@ void Problem::TestOutputEclipse(CRFProcess* m_pcs) porosity = m_mat_mp->Porosity(m_ele->GetIndex(), 1); element_volume = m_ele->GetVolume() * porosity; if (m_pcs->EclipseData->E100 == true) - saturation_water = 1 - - m_pcs->EclipseData->Data[i][m_pcs->EclipseData-> - GetVariableIndex("SGAS")]; + saturation_water = 1 - m_pcs->EclipseData->Data[i][m_pcs->EclipseData->GetVariableIndex("SGAS")]; else - saturation_water = - m_pcs->EclipseData->Data[i][m_pcs->EclipseData->GetVariableIndex( - "SWAT")]; - saturation_CO2 = - m_pcs->EclipseData->Data[i][m_pcs->EclipseData->GetVariableIndex("SGAS")]; + saturation_water = m_pcs->EclipseData->Data[i][m_pcs->EclipseData->GetVariableIndex("SWAT")]; + saturation_CO2 = m_pcs->EclipseData->Data[i][m_pcs->EclipseData->GetVariableIndex("SGAS")]; m_ele->GetNodes(ele_nodes); concentration_CO2_water = 0; for (int j = 0; j < int(ele_nodes.Size()); j++) - concentration_CO2_water = concentration_CO2_water + - pcs_vector[m_pcs->EclipseData-> - ProcessIndex_CO2inLiquid]-> - GetNodeValue( - ele_nodes[j]->GetIndex(), - indexConcentration_CO2) / ele_nodes.Size(); + concentration_CO2_water = concentration_CO2_water + + pcs_vector[m_pcs->EclipseData->ProcessIndex_CO2inLiquid]->GetNodeValue( + ele_nodes[j]->GetIndex(), indexConcentration_CO2) + / ele_nodes.Size(); mass_CO2_gas = mass_CO2_gas + element_volume * saturation_CO2 * density_CO2; - mass_CO2_water = mass_CO2_water + element_volume * saturation_water * - concentration_CO2_water * m_pcs->EclipseData->Molweight_CO2 * - 0.001; + mass_CO2_water + = mass_CO2_water + + element_volume * saturation_water * concentration_CO2_water * m_pcs->EclipseData->Molweight_CO2 * 0.001; } mass_CO2 = mass_CO2_gas + mass_CO2_water; - //calculating time + // calculating time time = 0; for (int k = 0; k < m_pcs->Tim->step_current; k++) time += m_pcs->Tim->time_step_vector[k]; @@ -2438,7 +2527,7 @@ void Problem::TestOutputEclipse(CRFProcess* m_pcs) vec_string.push_back(tempstring); - //within the first timestep create file and write header + // within the first timestep create file and write header TextFile = new CWriteTextfiles_ECL; tempstring = path_new + "\\Sum_CO2_elements.csv"; TextFile->Write_Text(tempstring, vec_string); @@ -2453,8 +2542,8 @@ void Problem::TestOutputEclipse(CRFProcess* m_pcs) -------------------------------------------------------------------------*/ void Problem::OutputMassOfGasInModel(CRFProcess* m_pcs) { - //Testoutput amount of co2 in model domain calculated at nodes - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt + // Testoutput amount of co2 in model domain calculated at nodes + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt MeshLib::CElem* m_ele = NULL; MeshLib::CNode* m_node = NULL; CMediumProperties* m_mat_mp = NULL; @@ -2466,21 +2555,21 @@ void Problem::OutputMassOfGasInModel(CRFProcess* m_pcs) double node_volume; double time; std::string tempstring; - std::vector vec_string; - //int position; + std::vector vec_string; + // int position; std::string path; double density_Gas; double porosity = 0.0; int variable_index; double concentration_Gas_water; - int indexConcentration_Gas=0; + int indexConcentration_Gas = 0; int ProcessIndex_GasInLiquid; - CRFProcess *n_pcs = NULL; + CRFProcess* n_pcs = NULL; int group; std::string transport_process_name, Processname; double Molweight_Gas; double V_model; - //bool Windows_System; + // bool Windows_System; int position; std::string filename; @@ -2494,7 +2583,7 @@ void Problem::OutputMassOfGasInModel(CRFProcess* m_pcs) else { std::string path_new; - path_new = path.substr(0,position); + path_new = path.substr(0, position); filename = path_new + "\\Sum_Gas_nodes.csv"; } } @@ -2506,7 +2595,7 @@ void Problem::OutputMassOfGasInModel(CRFProcess* m_pcs) else { std::string path_new; - path_new = path.substr(0,position); + path_new = path.substr(0, position); filename = path_new + "/Sum_Gas_nodes.csv"; } } @@ -2518,17 +2607,16 @@ void Problem::OutputMassOfGasInModel(CRFProcess* m_pcs) ProcessIndex_GasInLiquid = -1; if (ProcessIndex_GasInLiquid == -1) - for(int i = 0; i < int(pcs_vector.size()); i++) + for (int i = 0; i < int(pcs_vector.size()); i++) { n_pcs = pcs_vector[i]; // identify your process and store idx of pcs-vector if (n_pcs->nod_val_name_vector[0] == transport_process_name) - ProcessIndex_GasInLiquid = i; + ProcessIndex_GasInLiquid = i; } - if (m_pcs->Tim->step_current == 1) - //Header of the file + // Header of the file vec_string.push_back("Time, massGas_gas, massGas_water, massGas, porosity, Modelvolume, Pressure2, Density2"); else { @@ -2542,10 +2630,9 @@ void Problem::OutputMassOfGasInModel(CRFProcess* m_pcs) V_model = mass_Gas = mass_Gas_gas = mass_Gas_water = 0; // +1: new timelevel if (ProcessIndex_GasInLiquid > -1) - indexConcentration_Gas = - pcs_vector[ProcessIndex_GasInLiquid]->GetNodeValueIndex( - pcs_vector[ProcessIndex_GasInLiquid]-> - pcs_primary_function_name[0]) + 1; + indexConcentration_Gas = pcs_vector[ProcessIndex_GasInLiquid]->GetNodeValueIndex( + pcs_vector[ProcessIndex_GasInLiquid]->pcs_primary_function_name[0]) + + 1; for (long i = 0; i < (long)m_msh->nod_vector.size(); i++) { @@ -2564,24 +2651,23 @@ void Problem::OutputMassOfGasInModel(CRFProcess* m_pcs) double dens_arg[3]; dens_arg[0] = p2; density_Gas = mfp_vector[1]->Density(dens_arg); - //cout << "Knoten: " << i << " Dichte: " << density_Gas << " P2: " << p2 << "\n"; + // cout << "Knoten: " << i << " Dichte: " << density_Gas << " P2: " << p2 << "\n"; } for (int j = 0; j < int(m_node->getConnectedElementIDs().size()); j++) { m_ele = m_msh->ele_vector[m_node->getConnectedElementIDs()[j]]; - //get the phase volume of current element elem + // get the phase volume of current element elem group = m_ele->GetPatchIndex(); m_mat_mp = mmp_vector[group]; // CB Now provides also heterogeneous porosity, model 11 porosity = m_mat_mp->Porosity(m_ele->GetIndex(), 1); - //node_volume = node_volume + m_ele->GetVolume() / 8 * porosity; + // node_volume = node_volume + m_ele->GetVolume() / 8 * porosity; if (m_ele->GetElementType() == 2) node_volume = node_volume + m_ele->GetVolume() / m_ele->GetNodesNumber(true) * porosity; else node_volume = node_volume + m_ele->GetVolume() / m_ele->GetNodesNumber(false) * porosity; - } V_model = V_model + node_volume; @@ -2591,25 +2677,24 @@ void Problem::OutputMassOfGasInModel(CRFProcess* m_pcs) index = m_pcs->GetNodeValueIndex("SATURATION1"); else index = m_pcs->GetNodeValueIndex("SATURATION1") + 1; - saturation_water = m_pcs->GetNodeValue(i,index); - //if (saturation_water < 1) + saturation_water = m_pcs->GetNodeValue(i, index); + // if (saturation_water < 1) saturation_Gas = 1 - saturation_water; if (ProcessIndex_GasInLiquid > -1) { - concentration_Gas_water = - pcs_vector[ProcessIndex_GasInLiquid]->GetNodeValue( - i, indexConcentration_Gas); - mass_Gas_water = mass_Gas_water + node_volume * saturation_water * - concentration_Gas_water * Molweight_Gas * 0.001; + concentration_Gas_water = pcs_vector[ProcessIndex_GasInLiquid]->GetNodeValue(i, indexConcentration_Gas); + mass_Gas_water + = mass_Gas_water + node_volume * saturation_water * concentration_Gas_water * Molweight_Gas * 0.001; } else mass_Gas_water = 0; mass_Gas_gas = mass_Gas_gas + node_volume * saturation_Gas * density_Gas; - //cout << " Node: " << i << " saturation: " << saturation_water << " Density_CO2: " << density_CO2 << " node_volume: " << node_volume << "\n"; + // cout << " Node: " << i << " saturation: " << saturation_water << " Density_CO2: " << density_CO2 << " + // node_volume: " << node_volume << "\n"; } mass_Gas = mass_Gas_gas + mass_Gas_water; - //calculating time + // calculating time time = 0; for (int k = 0; k < m_pcs->Tim->step_current; k++) time += m_pcs->Tim->time_step_vector[k]; @@ -2670,7 +2755,7 @@ void Problem::OutputMassOfGasInModel(CRFProcess* m_pcs) vec_string.push_back(tempstring); - //within the first timestep create file and write header + // within the first timestep create file and write header CWriteTextfiles_ECL TextFile; TextFile.Write_Text(filename, vec_string); } @@ -2682,13 +2767,13 @@ Return: nothing Programming: 05/2011 BG -------------------------------------------------------------------------*/ -void Problem::OutputMassOfComponentInModel(std::vector flow_pcs, CRFProcess *transport_pcs) +void Problem::OutputMassOfComponentInModel(std::vector flow_pcs, CRFProcess* transport_pcs) { - //Testoutput mass of component in model domain calculated at nodes - MeshLib::CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt + // Testoutput mass of component in model domain calculated at nodes + MeshLib::CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt MeshLib::CElem* m_ele = NULL; MeshLib::CNode* m_node = NULL; - CMediumProperties *m_mat_mp = NULL; + CMediumProperties* m_mat_mp = NULL; std::ostringstream temp; double ComponentMass; // //int index; @@ -2696,27 +2781,27 @@ void Problem::OutputMassOfComponentInModel(std::vector flow_pcs, CR double node_volume; double time; std::string tempstring; - std::vector vec_string; - //int position; + std::vector vec_string; + // int position; std::string path; -// double density_water; // 2012-08 TF, variable ‘density_water’ set but not used [-Wunused-but-set-variable] + // double density_water; // 2012-08 TF, variable ‘density_water’ set but not used [-Wunused-but-set-variable] double porosity; -// int variable_index; // 2012-08 TF, variable set but not used + // int variable_index; // 2012-08 TF, variable set but not used double ComponentConcentration, TotalVolume, SourceTerm; int indexComponentConcentration; - //CRFProcess *n_pcs = NULL; + // CRFProcess *n_pcs = NULL; int group; std::string filename; - //bool Windows_System; + // bool Windows_System; int position; path = flow_pcs[0]->file_name_base; - //position = int(path.find_last_of("\\")); - //if (position >= 0) - // Windows_System = true; - //else - // Windows_System = false; - //if (Windows_System == true) +// position = int(path.find_last_of("\\")); +// if (position >= 0) +// Windows_System = true; +// else +// Windows_System = false; +// if (Windows_System == true) #ifdef _WIN32 { position = int(path.find_last_of("\\")); @@ -2725,7 +2810,7 @@ void Problem::OutputMassOfComponentInModel(std::vector flow_pcs, CR else { std::string path_new; - path_new = path.substr(0,position); + path_new = path.substr(0, position); filename = path_new + "\\Mass_" + transport_pcs->nod_val_name_vector[0] + "_nodes.csv"; } } @@ -2737,19 +2822,19 @@ void Problem::OutputMassOfComponentInModel(std::vector flow_pcs, CR else { std::string path_new; - path_new = path.substr(0,position); + path_new = path.substr(0, position); filename = path_new + "/Mass_" + transport_pcs->nod_val_name_vector[0] + "_nodes.csv"; } } #endif if (flow_pcs[0]->Tim->step_current == 1) { - //Header of the file + // Header of the file vec_string.push_back("Time, ComponentMass, TotalVolume"); } else { - //read file and store data + // read file and store data CReadTextfiles_ECL TextFile; TextFile.Read_Text(filename); @@ -2763,65 +2848,85 @@ void Problem::OutputMassOfComponentInModel(std::vector flow_pcs, CR for (long i = 0; i < (long)m_msh->nod_vector.size(); i++) { - m_node = m_msh->nod_vector[i]; // get element + m_node = m_msh->nod_vector[i]; // get element node_volume = 0; if (mfp_vector[0]->density_model == 18) { -// variable_index = flow_pcs[0]->GetNodeValueIndex("DENSITY1"); // // 2012-08 TF, variable set but not used -// density_water = flow_pcs[0]->GetNodeValue(i, variable_index); // 2012-08 TF, variable ‘density_water’ set but not used [-Wunused-but-set-variable] + // variable_index = flow_pcs[0]->GetNodeValueIndex("DENSITY1"); // // 2012-08 TF, variable set but + // not + // used + // density_water = flow_pcs[0]->GetNodeValue(i, variable_index); // 2012-08 TF, variable + //‘density_water’ set but not used [-Wunused-but-set-variable] } -// else -// density_water = mfp_vector[0]->Density(); // 2012-08 TF, variable ‘density_water’ set but not used [-Wunused-but-set-variable] + // else + // density_water = mfp_vector[0]->Density(); // 2012-08 TF, variable ‘density_water’ set but not used + //[-Wunused-but-set-variable] for (int j = 0; j < int(m_node->getConnectedElementIDs().size()); j++) { m_ele = m_msh->ele_vector[m_node->getConnectedElementIDs()[j]]; - //get the phase volume of current element elem + // get the phase volume of current element elem group = m_ele->GetPatchIndex(); m_mat_mp = mmp_vector[group]; - porosity = m_mat_mp->Porosity(m_ele->GetIndex(), 1); // CB Now provides also heterogeneous porosity, model 11 - node_volume = node_volume + porosity * m_ele->GetVolume() * m_ele->GetFluxArea() / m_ele->GetNodesNumber(false); - //cout << m_ele->GetNodesNumber(false) << " " << "\n"; + porosity + = m_mat_mp->Porosity(m_ele->GetIndex(), 1); // CB Now provides also heterogeneous porosity, model 11 + node_volume + = node_volume + porosity * m_ele->GetVolume() * m_ele->GetFluxArea() / m_ele->GetNodesNumber(false); + // cout << m_ele->GetNodesNumber(false) << " " << "\n"; } TotalVolume += node_volume; if (flow_pcs[0]->getProcessType() == FiniteElement::GROUNDWATER_FLOW) - saturation_water = 1; // saturation does not exist for example in groundwater flow + saturation_water = 1; // saturation does not exist for example in groundwater flow else { int index = flow_pcs[0]->GetNodeValueIndex("SATURATION1") + 1; //+1... new time level saturation_water = flow_pcs[0]->GetNodeValue(i, index); } - indexComponentConcentration = transport_pcs->GetNodeValueIndex(transport_pcs->pcs_primary_function_name[0]) + 1; // +1: new timelevel + indexComponentConcentration + = transport_pcs->GetNodeValueIndex(transport_pcs->pcs_primary_function_name[0]) + 1; // +1: new timelevel ComponentConcentration = transport_pcs->GetNodeValue(i, indexComponentConcentration); ComponentMass = ComponentMass + node_volume * saturation_water * ComponentConcentration; - //cout << " Node: " << i << " saturation: " << saturation_water << " Density_water: " << density_water << " node_volume: " << node_volume << " Concentration: " << ComponentConcentration << "\n"; + // cout << " Node: " << i << " saturation: " << saturation_water << " Density_water: " << density_water << " + // node_volume: " << node_volume << " Concentration: " << ComponentConcentration << "\n"; } - //calculating source term + // calculating source term for (long i = 0; i < (long)transport_pcs->st_node_value.size(); i++) { SourceTerm = transport_pcs->st_node_value[i]->node_value; } SourceTerm *= transport_pcs->Tim->this_stepsize; - //calculating time + // calculating time time = 0; for (int k = 0; k < transport_pcs->Tim->step_current; k++) { time += transport_pcs->Tim->time_step_vector[k]; } - temp.str(""); temp.clear(); temp.precision(14); temp << time; tempstring = temp.str(); + temp.str(""); + temp.clear(); + temp.precision(14); + temp << time; + tempstring = temp.str(); tempstring += ", "; - temp.str(""); temp.clear(); temp.precision(14); temp << ComponentMass; tempstring += temp.str(); + temp.str(""); + temp.clear(); + temp.precision(14); + temp << ComponentMass; + tempstring += temp.str(); tempstring += ", "; - temp.str(""); temp.clear(); temp.precision(14); temp << TotalVolume; tempstring += temp.str(); + temp.str(""); + temp.clear(); + temp.precision(14); + temp << TotalVolume; + tempstring += temp.str(); vec_string.push_back(tempstring); - //within the first timestep create file and write header + // within the first timestep create file and write header CWriteTextfiles_ECL TextFile; TextFile.Write_Text(filename, vec_string); } @@ -2838,13 +2943,13 @@ inline double Problem::PS_Global() { double error = 1.0e+8; CRFProcess* m_pcs = total_processes[3]; - if(!m_pcs->selected) + if (!m_pcs->selected) return error; error = m_pcs->ExecuteNonLinear(loop_process_number); - if(m_pcs->TimeStepAccept()) + if (m_pcs->TimeStepAccept()) m_pcs->CalIntegrationPointValue(); - if (m_pcs->OutputMassOfGasInModel == true) // 05/2012 BG + if (m_pcs->OutputMassOfGasInModel == true) // 05/2012 BG OutputMassOfGasInModel(m_pcs); return error; @@ -2861,10 +2966,10 @@ inline double Problem::MULTI_COMPONENTIAL_FLOW() { double error = 1.0e+8; CRFProcess* m_pcs = total_processes[5]; - if(!m_pcs->selected) + if (!m_pcs->selected) return error; error = m_pcs->ExecuteNonLinear(loop_process_number); - if(m_pcs->TimeStepAccept()) + if (m_pcs->TimeStepAccept()) m_pcs->CalIntegrationPointValue(); return error; } @@ -2880,15 +2985,14 @@ inline double Problem::TNEQ() { double error = 1.0e+8; CRFProcess* m_pcs = total_processes[14]; - if(!m_pcs->selected) + if (!m_pcs->selected) return error; error = m_pcs->ExecuteNonLinear(loop_process_number); - if(m_pcs->TimeStepAccept()) + if (m_pcs->TimeStepAccept()) m_pcs->CalIntegrationPointValue(); return error; } - /*------------------------------------------------------------------------- GeoSys - Function: TES() Task: Simulate Reactive thermal nonequilibrium flow @@ -2901,15 +3005,14 @@ inline double Problem::TES() { double error = 1.0e+8; CRFProcess* m_pcs = total_processes[15]; - if(!m_pcs->selected) + if (!m_pcs->selected) return error; error = m_pcs->ExecuteNonLinear(loop_process_number); - if(m_pcs->TimeStepAccept()) + if (m_pcs->TimeStepAccept()) m_pcs->CalIntegrationPointValue(); return error; } - /*------------------------------------------------------------------------- GeoSys - Function: GroundWaterFlow() Task: @@ -2924,9 +3027,9 @@ inline double Problem::GroundWaterFlow() { double error = 1.0e+8; CRFProcess* m_pcs = total_processes[1]; - if(!m_pcs->selected) - return error; //12.12.2008 WW - ClockTimeVec[0]->StartTime(); // CB time + if (!m_pcs->selected) + return error; // 12.12.2008 WW + ClockTimeVec[0]->StartTime(); // CB time //----- For the coupling with the soil column approach. 05.2009. WW MeshLib::GridsTopo* neighb_grid = NULL; @@ -2934,40 +3037,38 @@ inline double Problem::GroundWaterFlow() CRFProcess* neighb_pcs = total_processes[2]; std::vector border_flux; int idx_flux = 0, idx_flux_this; - //WW int no_local_nodes; + // WW int no_local_nodes; long i; - if(neighb_pcs) + if (neighb_pcs) { - for(i = 0; i < (long)neighb_pcs->m_msh->grid_neighbors.size(); i++) + for (i = 0; i < (long)neighb_pcs->m_msh->grid_neighbors.size(); i++) { neighb_grid = neighb_pcs->m_msh->grid_neighbors[i]; - if(neighb_grid->getNeighbor_Name().find("SECTOR_GROUND") != - std::string::npos) + if (neighb_grid->getNeighbor_Name().find("SECTOR_GROUND") != std::string::npos) break; neighb_grid = NULL; } - for(i = 0; i < (long)m_pcs->m_msh->grid_neighbors.size(); i++) + for (i = 0; i < (long)m_pcs->m_msh->grid_neighbors.size(); i++) { neighb_grid_this = m_pcs->m_msh->grid_neighbors[i]; - if(neighb_grid_this->getNeighbor_Name().find("SECTOR_SOIL") != - std::string::npos) + if (neighb_grid_this->getNeighbor_Name().find("SECTOR_SOIL") != std::string::npos) break; neighb_grid_this = NULL; } } //------------ - if(neighb_grid) + if (neighb_grid) { CSourceTerm* m_st = NULL; CNodeValue* m_nod_val = NULL; long l = 0, m = 0; - //WW no_local_nodes = neighb_pcs->m_msh->getNumberOfMeshLayers()+1; + // WW no_local_nodes = neighb_pcs->m_msh->getNumberOfMeshLayers()+1; - if(aktueller_zeitschritt == 1) + if (aktueller_zeitschritt == 1) { m_st = new CSourceTerm(); - for(i = 0; i < neighb_grid->getBorderNodeNumber(); i++) + for (i = 0; i < neighb_grid->getBorderNodeNumber(); i++) { m_nod_val = new CNodeValue(); m_pcs->st_node_value.push_back(m_nod_val); @@ -2980,15 +3081,14 @@ inline double Problem::GroundWaterFlow() border_flux.resize(neighb_grid->getBorderNodeNumber()); idx_flux = neighb_pcs->GetNodeValueIndex("VELOCITY_Z1"); - for(i = 0; i < neighb_grid->getBorderNodeNumber(); i++) - border_flux[local_indxs_this[i]] = neighb_pcs->GetNodeValue(local_indxs[i], - idx_flux) - / neighb_pcs->time_unit_factor; + for (i = 0; i < neighb_grid->getBorderNodeNumber(); i++) + border_flux[local_indxs_this[i]] + = neighb_pcs->GetNodeValue(local_indxs[i], idx_flux) / neighb_pcs->time_unit_factor; m_pcs->Integration(border_flux); m = l - neighb_grid->getBorderNodeNumber(); - for(i = m; i < l; i++) + for (i = m; i < l; i++) { m_nod_val = m_pcs->st_node_value[i]; m_nod_val->msh_node_number = local_indxs_this[i - m]; @@ -2998,50 +3098,50 @@ inline double Problem::GroundWaterFlow() } //------------------------------- - error = m_pcs->ExecuteNonLinear(loop_process_number); + error = m_pcs->ExecuteNonLinear(loop_process_number); //................................................................ // Calculate secondary variables // NOD values - conducted = true; //WW - //std::cout << " Calculation of secondary NOD values" << "\n"; - if(m_pcs->TimeStepAccept()) + conducted = true; // WW + // std::cout << " Calculation of secondary NOD values" << "\n"; + if (m_pcs->TimeStepAccept()) { #ifdef RESET_4410 PCSCalcSecondaryVariables(); // PCS member function #endif - //std::cout << " Calculation of secondary GP values" << "\n"; - m_pcs->CalIntegrationPointValue(); //WW - m_pcs->cal_integration_point_value = true; //WW Do not extropolate Gauss velocity + // std::cout << " Calculation of secondary GP values" << "\n"; + m_pcs->CalIntegrationPointValue(); // WW + m_pcs->cal_integration_point_value = true; // WW Do not extropolate Gauss velocity - if(neighb_grid) + if (neighb_grid) { m_pcs->Extropolation_GaussValue(); m_pcs->cal_integration_point_value = false; idx_flux_this = m_pcs->GetNodeValueIndex("VELOCITY_Z1"); - for(i = 0; i < neighb_grid->getBorderNodeNumber(); i++) - border_flux[i] = m_pcs->GetNodeValue(i,idx_flux_this); + for (i = 0; i < neighb_grid->getBorderNodeNumber(); i++) + border_flux[i] = m_pcs->GetNodeValue(i, idx_flux_this); m_pcs->Integration(border_flux); - for(i = 0; i < neighb_grid->getBorderNodeNumber(); i++) + for (i = 0; i < neighb_grid->getBorderNodeNumber(); i++) neighb_pcs->SetNodeValue(i, idx_flux, border_flux[i]); // neighb_pcs->SetNodeValue(i+no_local_nodes, idx_flux, border_flux[i]); } } - // ELE values +// ELE values #if !defined(USE_PETSC) && !defined(NEW_EQS) // && defined(other parallel libs)//03~04.3012. WW //#ifndef NEW_EQS //WW. 07.11.2008 - if(m_pcs->tim_type == TimType::STEADY) //CMCD 05/2006 + if (m_pcs->tim_type == TimType::STEADY) // CMCD 05/2006 { - //std::cout << " Calculation of secondary ELE values" << "\n"; - m_pcs->AssembleParabolicEquationRHSVector(); //WW LOPCalcNODResultants(); + // std::cout << " Calculation of secondary ELE values" << "\n"; + m_pcs->AssembleParabolicEquationRHSVector(); // WW LOPCalcNODResultants(); m_pcs->CalcELEVelocities(); m_pcs->selected = false; } #endif - ClockTimeVec[0]->StopTime("Flow"); // CB time - ClockTimeVec[0]->StartTime(); // CB time + ClockTimeVec[0]->StopTime("Flow"); // CB time + ClockTimeVec[0]->StartTime(); // CB time - return error; + return error; } /*------------------------------------------------------------------------- @@ -3056,11 +3156,11 @@ inline double Problem::ComponentalFlow() { double error = 1.e8; CRFProcess* m_pcs = total_processes[5]; - if(!m_pcs->selected) - return error; //12.12.2008 WW + if (!m_pcs->selected) + return error; // 12.12.2008 WW // error = m_pcs->ExecuteNonLinear(loop_process_number); - m_pcs->CalIntegrationPointValue(); //WW + m_pcs->CalIntegrationPointValue(); // WW return error; } @@ -3076,11 +3176,11 @@ inline double Problem::OverlandFlow() { double error = 1.e8; CRFProcess* m_pcs = total_processes[0]; - if(!m_pcs->selected) - return error; //12.12.2008 WW + if (!m_pcs->selected) + return error; // 12.12.2008 WW error = m_pcs->ExecuteNonLinear(loop_process_number); - if(m_pcs->TimeStepAccept()) + if (m_pcs->TimeStepAccept()) PCSCalcSecondaryVariables(); return error; } @@ -3097,13 +3197,13 @@ inline double Problem::AirFlow() { double error = 1.e8; CRFProcess* m_pcs = total_processes[7]; - if(!m_pcs->selected) - return error; //12.12.2008 WW + if (!m_pcs->selected) + return error; // 12.12.2008 WW error = m_pcs->ExecuteNonLinear(loop_process_number); - m_pcs->CalIntegrationPointValue(); //WW - m_pcs->cal_integration_point_value = false; //AKS - m_pcs->CalcELEVelocities(); //OK + m_pcs->CalIntegrationPointValue(); // WW + m_pcs->cal_integration_point_value = false; // AKS + m_pcs->CalcELEVelocities(); // OK // return error; } @@ -3120,23 +3220,23 @@ inline double Problem::HeatTransport() { double error = 1.0e+8; CRFProcess* m_pcs = total_processes[8]; - if(!m_pcs->selected) - return error; //12.12.2008 WW - //CB This is a cheat to map a 2D horizontal heat pump distribution on a vertical model - if(REACTINT_vec.size()>0) - if(REACTINT_vec[0]->heatpump_2DhTO2Dv) - REACTINT_vec[0]->Heatpump_2DhTO2Dv_Mapping(false); // Restore the old solution + if (!m_pcs->selected) + return error; // 12.12.2008 WW + // CB This is a cheat to map a 2D horizontal heat pump distribution on a vertical model + if (REACTINT_vec.size() > 0) + if (REACTINT_vec[0]->heatpump_2DhTO2Dv) + REACTINT_vec[0]->Heatpump_2DhTO2Dv_Mapping(false); // Restore the old solution error = m_pcs->ExecuteNonLinear(loop_process_number); - //if(m_pcs->non_linear) + // if(m_pcs->non_linear) // error = m_pcs->ExecuteNonLinear(); - //else + // else // error = m_pcs->Execute(); - //CB This is a cheat to map a 2D horizontal heat pump distribution on a vertical model - if(REACTINT_vec.size()>0) - if(REACTINT_vec[0]->heatpump_2DhTO2Dv) - REACTINT_vec[0]->Heatpump_2DhTO2Dv_Mapping(true); // Map Heat plume CL to 2D vertical + // CB This is a cheat to map a 2D horizontal heat pump distribution on a vertical model + if (REACTINT_vec.size() > 0) + if (REACTINT_vec[0]->heatpump_2DhTO2Dv) + REACTINT_vec[0]->Heatpump_2DhTO2Dv_Mapping(true); // Map Heat plume CL to 2D vertical return error; } @@ -3153,44 +3253,47 @@ inline double Problem::HeatTransport() inline double Problem::MassTrasport() { double error = 1.0e+8; - bool capvec = false; - // bool prqvec = false; + bool capvec = false; + // bool prqvec = false; CRFProcess* m_pcs = total_processes[11]; // - if(!m_pcs->selected) - return error; //12.12.2008 WW - //ClockTimeVec[0]->StartTime(); // CB time, remove if flow time is stopped + if (!m_pcs->selected) + return error; // 12.12.2008 WW + // ClockTimeVec[0]->StartTime(); // CB time, remove if flow time is stopped - for(int i = 0; i < (int)transport_processes.size(); i++) + for (int i = 0; i < (int)transport_processes.size(); i++) { - m_pcs = transport_processes[i]; //18.08.2008 WW - //Component Mobile ? + m_pcs = transport_processes[i]; // 18.08.2008 WW + // Component Mobile ? - //MW reduce CONCENTRATION1 to non-negative values above water table for stability for Sugio approach with RICHARDS + // MW reduce CONCENTRATION1 to non-negative values above water table for stability for Sugio approach with + // RICHARDS if (mmp_vector[0]->permeability_saturation_model[0] == 10) { - int nidx0 = m_pcs->GetNodeValueIndex("CONCENTRATION1",0); - CRFProcess *local_richards_flow = PCSGet("PRESSURE1",true); + int nidx0 = m_pcs->GetNodeValueIndex("CONCENTRATION1", 0); + CRFProcess* local_richards_flow = PCSGet("PRESSURE1", true); if (local_richards_flow != NULL) { - int nidx1 = local_richards_flow->GetNodeValueIndex("PRESSURE1",0); - for (size_t j=0; jm_msh->GetNodesNumber(false);j++) + int nidx1 = local_richards_flow->GetNodeValueIndex("PRESSURE1", 0); + for (size_t j = 0; j < m_pcs->m_msh->GetNodesNumber(false); j++) { - double local_conc = m_pcs->GetNodeValue(j,nidx0+1); - double local_pressure = local_richards_flow->GetNodeValue(j,nidx1+1); + double local_conc = m_pcs->GetNodeValue(j, nidx0 + 1); + double local_pressure = local_richards_flow->GetNodeValue(j, nidx1 + 1); if (local_pressure < 0 && local_conc < 0) - m_pcs->SetNodeValue(j,nidx0+1,0); + m_pcs->SetNodeValue(j, nidx0 + 1, 0); } } } - if(CPGetMobil(m_pcs->GetProcessComponentNumber()) > 0) - error = m_pcs->ExecuteNonLinear(loop_process_number); //NW. ExecuteNonLinear() is called to use the adaptive time step scheme + if (CPGetMobil(m_pcs->GetProcessComponentNumber()) > 0) + error = m_pcs->ExecuteNonLinear( + loop_process_number); // NW. ExecuteNonLinear() is called to use the adaptive time step scheme int component = m_pcs->pcs_component_number; CompProperties* m_cp = cp_vec[component]; - if (m_cp->OutputMassOfComponentInModel == 1) { // 05/2012 BG + if (m_cp->OutputMassOfComponentInModel == 1) + { // 05/2012 BG // TODO: Check if (singlephaseflow_process.size() > 0) OutputMassOfComponentInModel(singlephaseflow_process, m_pcs); @@ -3201,44 +3304,45 @@ inline double Problem::MassTrasport() // Calculate Chemical reactions, after convergence of flow and transport // Move inside iteration loop if couplingwith transport is implemented SB:todo - //SB:todo move into Execute Reactions if((aktueller_zeitschritt % 1) == 0) - //REACT *rc = NULL; //OK - //rc = REACT_vec[0]; //OK + // SB:todo move into Execute Reactions if((aktueller_zeitschritt % 1) == 0) + // REACT *rc = NULL; //OK + // rc = REACT_vec[0]; //OK // if(rc->flag_pqc) rc->ExecuteReactions(); // delete rc; -//CB2406 #ifdef OGS_FEM_CAP // CAP_REACT //CB merge CAP 0311 - if (REACT_CAP_vec.size() > 0) capvec = true; - - - //if( (KinReactData_vector.size() > 0) || (REACT_vec.size()>0) || capvec || (REACT_PRQ_vec.size()>0) ) //CB merge CAP 0311 - if(REACTINT_vec.size()>0) - REACTINT_vec[0]->ReactionPreProcessing(); - - if(KinReactData_vector.size() > 0) - { // WW moved the following lines into this curly braces. 12.12.2008 - ClockTimeVec[0]->StopTime("Transport"); // CB time - ClockTimeVec[0]->StartTime(); // CB time - // Calculate Chemical reactions, after convergence of flow and transport - // Move inside iteration loop if couplingwith transport is implemented SB:todo - // First calculate kinetic reactions - - //DL --> for liquid phase only, - // this will provide activities and speciation for kinetics - if(capvec && KinReactData_vector[0]->NumberMineralkinetics>0) - REACT_CAP_vec[0]->ExecuteReactionsChemApp(-1, -1); - - KinReactData_vector[0]->ExecuteKinReact(); - ClockTimeVec[0]->StopTime("KinReactions"); // CB time - ClockTimeVec[0]->StartTime(); // CB time - } - if(REACT_vec.size() > 0) //OK + // CB2406 #ifdef OGS_FEM_CAP // CAP_REACT //CB merge CAP 0311 + if (REACT_CAP_vec.size() > 0) + capvec = true; + + // if( (KinReactData_vector.size() > 0) || (REACT_vec.size()>0) || capvec || (REACT_PRQ_vec.size()>0) ) //CB merge + // CAP 0311 + if (REACTINT_vec.size() > 0) + REACTINT_vec[0]->ReactionPreProcessing(); + + if (KinReactData_vector.size() > 0) + { // WW moved the following lines into this curly braces. 12.12.2008 + ClockTimeVec[0]->StopTime("Transport"); // CB time + ClockTimeVec[0]->StartTime(); // CB time + // Calculate Chemical reactions, after convergence of flow and transport + // Move inside iteration loop if couplingwith transport is implemented SB:todo + // First calculate kinetic reactions + + // DL --> for liquid phase only, + // this will provide activities and speciation for kinetics + if (capvec && KinReactData_vector[0]->NumberMineralkinetics > 0) + REACT_CAP_vec[0]->ExecuteReactionsChemApp(-1, -1); + + KinReactData_vector[0]->ExecuteKinReact(); + ClockTimeVec[0]->StopTime("KinReactions"); // CB time + ClockTimeVec[0]->StartTime(); // CB time + } + if (REACT_vec.size() > 0) // OK { - if(REACT_vec[0]->flag_pqc) + if (REACT_vec[0]->flag_pqc) { #ifdef REACTION_ELEMENT REACT_vec[0]->ExecuteReactionsPHREEQC0(); #else - // REACT_vec[0]->ExecuteReactions(); +// REACT_vec[0]->ExecuteReactions(); #ifdef OGS_FEM_IPQC REACT_vec[0]->ExecutePQCString(); @@ -3247,26 +3351,26 @@ inline double Problem::MassTrasport() REACT_vec[0]->ExecuteReactionsPHREEQCNewLib(); #else REACT_vec[0]->ExecuteReactionsPHREEQCNew(); -#endif // LIBPHREEQC -#endif // REACTION_ELEMENT +#endif // LIBPHREEQC +#endif // REACTION_ELEMENT } } - if(REACT_CAP_vec.size() > 0){ // use ChemApp - REACT_CAP_vec[0]->ExecuteReactionsChemApp(1, -1); //DL - //REACT_CAP_vec[0]->ConvertIC2BC(); - } - + if (REACT_CAP_vec.size() > 0) + { // use ChemApp + REACT_CAP_vec[0]->ExecuteReactionsChemApp(1, -1); // DL + // REACT_CAP_vec[0]->ConvertIC2BC(); + } #ifdef GEM_REACT - else // WW moved these pare of curly braces inside ifdef GEM_REACT - if (m_vec_GEM->initialized_flag == 1) //when it was initialized. + else // WW moved these pare of curly braces inside ifdef GEM_REACT + if (m_vec_GEM->initialized_flag == 1) // when it was initialized. { - int m_time = 1; // 0-previous time step results; 1-current time step results + int m_time = 1; // 0-previous time step results; 1-current time step results // Check if the Sequential Iterative Scheme needs to be intergrated if (m_pcs->m_num->cpl_max_iterations > 1) - m_vec_GEM->flag_iterative_scheme = 1; // set to standard iterative scheme; + m_vec_GEM->flag_iterative_scheme = 1; // set to standard iterative scheme; // Move current xDC to previous xDC m_vec_GEM->CopyCurXDCPre(); // Get info from MT @@ -3282,21 +3386,21 @@ inline double Problem::MassTrasport() m_vec_GEM->UpdateXDCChemDelta(); // Set info in MT m_vec_GEM->SetReactInfoBackMassTransport(m_time); - //m_vec_GEM->ConvPorosityNodeValue2Elem(); // update element porosity and push back values + // m_vec_GEM->ConvPorosityNodeValue2Elem(); // update element porosity and push back values } -#endif // GEM_REACT +#endif // GEM_REACT #ifdef CHEMAPP - if(Eqlink_vec.size() > 0) + if (Eqlink_vec.size() > 0) Eqlink_vec[0]->ExecuteEQLINK(); #endif #ifdef BRNS - if(m_vec_BRNS->init_flag == true) - m_vec_BRNS->RUN( dt /*time value in seconds*/); + if (m_vec_BRNS->init_flag == true) + m_vec_BRNS->RUN(dt /*time value in seconds*/); #endif // if(KinReactData_vector.size() > 0) //12.12.2008 WW - ClockTimeVec[0]->StopTime("EquiReact"); // CB time + ClockTimeVec[0]->StopTime("EquiReact"); // CB time return error; } @@ -3314,36 +3418,37 @@ inline double Problem::FluidMomentum() double error = 1.0e+8; CRFProcess* m_pcs = total_processes[9]; // - if(!m_pcs->selected) - return error; //12.12.2008 WW + if (!m_pcs->selected) + return error; // 12.12.2008 WW - CFluidMomentum* fm_pcs = NULL; // by PCH + CFluidMomentum* fm_pcs = NULL; // by PCH // - CFEMesh* m_msh = fem_msh_vector[0]; // Something must be done later on here. + CFEMesh* m_msh = fem_msh_vector[0]; // Something must be done later on here. fm_pcs = m_msh->fm_pcs; fm_pcs->Execute(loop_process_number); // Switch off rechard flow if - if(m_pcs->num_type_name.compare("STEADY") == 0 && aktueller_zeitschritt > 1) + if (m_pcs->num_type_name.compare("STEADY") == 0 && aktueller_zeitschritt > 1) { // Turn off FLUID_MOMENTUM m_pcs->selected = false; // Turn off RICHARDS_FLOW m_pcs = PCSGet("RICHARDS_FLOW"); - if(m_pcs) + if (m_pcs) m_pcs->selected = false; // Turn off LIQUID_FLOW m_pcs = PCSGet("LIQUID_FLOW"); - if(m_pcs) + if (m_pcs) m_pcs->selected = false; // Turn off GROUNDWATER_FLOW m_pcs = PCSGet("GROUNDWATER_FLOW"); - if(m_pcs) + if (m_pcs) m_pcs->selected = false; } // - //error = 0.0 // JT... in unsteady flow, setting error=0.0 corresponds to error_cpl=0.0, and the coupling loop ceases before RWPT is performed + // error = 0.0 // JT... in unsteady flow, setting error=0.0 corresponds to error_cpl=0.0, and the coupling loop + // ceases before RWPT is performed // // What is the correct way to handle this, rather than setting error=1.e8??? return error; } @@ -3363,124 +3468,135 @@ inline double Problem::RandomWalker() // CRFProcess* m_pcs = total_processes[10]; // - if(!m_pcs->selected) - return error; //12.12.2008 WW + if (!m_pcs->selected) + return error; // 12.12.2008 WW // // CFEMesh* m_msh = NULL; - if(m_pcs && m_pcs->selected) + if (m_pcs && m_pcs->selected) { lop_coupling_iterations = 1; // Mount the proper mesh CFEMesh* m_msh = NULL; - for(int i = 0; i < (int)pcs_vector.size(); ++i) + for (int i = 0; i < (int)pcs_vector.size(); ++i) { m_pcs = pcs_vector[i]; // Select the mesh whose process name has the mesh for Fluid_Momentum // if( m_pcs->pcs_type_name.find("RICHARDS_FLOW")!=string::npos) // TF - if( m_pcs->getProcessType () == FiniteElement::RICHARDS_FLOW) + if (m_pcs->getProcessType() == FiniteElement::RICHARDS_FLOW) m_msh = FEMGet("RICHARDS_FLOW"); // else if( m_pcs->pcs_type_name.find("LIQUID_FLOW")!=string::npos) // TF - else if( m_pcs->getProcessType () == FiniteElement::LIQUID_FLOW) + else if (m_pcs->getProcessType() == FiniteElement::LIQUID_FLOW) m_msh = FEMGet("LIQUID_FLOW"); // else if( m_pcs->pcs_type_name.find("GROUNDWATER_FLOW")!=string::npos) // TF - else if( m_pcs->getProcessType () == FiniteElement::GROUNDWATER_FLOW) + else if (m_pcs->getProcessType() == FiniteElement::GROUNDWATER_FLOW) m_msh = FEMGet("GROUNDWATER_FLOW"); } - if(!m_msh) - m_msh = FEMGet("FLUID_MOMENTUM"); + if (!m_msh) + m_msh = FEMGet("FLUID_MOMENTUM"); RandomWalk* rw_pcs = NULL; // By PCH rw_pcs = m_msh->PT; - if(rw_pcs->getFlowPCS()) - { - if (rw_pcs->getFlowPCS()->cal_integration_point_value) //WW - rw_pcs->getFlowPCS()->Extropolation_GaussValue(); - } + if (rw_pcs->getFlowPCS()) + { + if (rw_pcs->getFlowPCS()->cal_integration_point_value) // WW + rw_pcs->getFlowPCS()->Extropolation_GaussValue(); + } // Do I need velocity fileds solved by the FEM? - if(m_pcs->tim_type == TimType::PURERWPT) + if (m_pcs->tim_type == TimType::PURERWPT) { rw_pcs->PURERWPT = 1; char* dateiname = NULL; int sizeOfWord = 100; - dateiname = (char*)malloc(sizeOfWord * sizeof(char )); + dateiname = (char*)malloc(sizeOfWord * sizeof(char)); std::string filename = FileName; - for(int i = 0; i <= (int)filename.size(); ++i) + for (int i = 0; i <= (int)filename.size(); ++i) dateiname[i] = filename[i]; rw_pcs->ReadInVelocityFieldOnNodes(dateiname); - delete [] dateiname; + delete[] dateiname; } // Set the mode of the RWPT method - if(m_pcs->num_type_name.compare("HETERO") == 0) + if (m_pcs->num_type_name.compare("HETERO") == 0) { rw_pcs->RWPTMode = 1; // Set it for heterogeneous media - std::cout << "RWPT is on " << m_pcs->num_type_name << " mode." << "\n"; + std::cout << "RWPT is on " << m_pcs->num_type_name << " mode." + << "\n"; } - else if(m_pcs->num_type_name.compare("HOMO_ADVECTION") == 0) + else if (m_pcs->num_type_name.compare("HOMO_ADVECTION") == 0) { rw_pcs->RWPTMode = 2; - std::cout << "RWPT is on " << m_pcs->num_type_name << " mode." << "\n"; + std::cout << "RWPT is on " << m_pcs->num_type_name << " mode." + << "\n"; } - else if(m_pcs->num_type_name.compare("HETERO_ADVECTION") == 0) + else if (m_pcs->num_type_name.compare("HETERO_ADVECTION") == 0) { rw_pcs->RWPTMode = 3; - std::cout << "RWPT is on " << m_pcs->num_type_name << " mode." << "\n"; + std::cout << "RWPT is on " << m_pcs->num_type_name << " mode." + << "\n"; } - else if(m_pcs->num_type_name.compare("HOMO_DISPERSION") == 0) + else if (m_pcs->num_type_name.compare("HOMO_DISPERSION") == 0) { rw_pcs->RWPTMode = 4; - std::cout << "RWPT is on " << m_pcs->num_type_name << " mode." << "\n"; + std::cout << "RWPT is on " << m_pcs->num_type_name << " mode." + << "\n"; } - else if(m_pcs->num_type_name.compare("HETERO_DISPERSION") == 0) + else if (m_pcs->num_type_name.compare("HETERO_DISPERSION") == 0) { rw_pcs->RWPTMode = 5; - std::cout << "RWPT is on " << m_pcs->num_type_name << " mode." << "\n"; + std::cout << "RWPT is on " << m_pcs->num_type_name << " mode." + << "\n"; } - else if(m_pcs->num_type_name.compare("HETERO_FDM") == 0) + else if (m_pcs->num_type_name.compare("HETERO_FDM") == 0) { rw_pcs->RWPTMode = 1; // Set it for heterogeneous media - std::cout << "RWPT is on " << m_pcs->num_type_name << " mode." << "\n"; + std::cout << "RWPT is on " << m_pcs->num_type_name << " mode." + << "\n"; } - else if(m_pcs->num_type_name.compare("HOMO_ADVECTION_FDM") == 0) + else if (m_pcs->num_type_name.compare("HOMO_ADVECTION_FDM") == 0) { rw_pcs->RWPTMode = 2; - std::cout << "RWPT is on " << m_pcs->num_type_name << " mode." << "\n"; + std::cout << "RWPT is on " << m_pcs->num_type_name << " mode." + << "\n"; } - else if(m_pcs->num_type_name.compare("HETERO_ADVECTION_FDM") == 0) + else if (m_pcs->num_type_name.compare("HETERO_ADVECTION_FDM") == 0) { rw_pcs->RWPTMode = 3; - std::cout << "RWPT is on " << m_pcs->num_type_name << " mode." << "\n"; + std::cout << "RWPT is on " << m_pcs->num_type_name << " mode." + << "\n"; } - else if(m_pcs->num_type_name.compare("HOMO_DISPERSION_FDM") == 0) + else if (m_pcs->num_type_name.compare("HOMO_DISPERSION_FDM") == 0) { rw_pcs->RWPTMode = 4; - std::cout << "RWPT is on " << m_pcs->num_type_name << " mode." << "\n"; + std::cout << "RWPT is on " << m_pcs->num_type_name << " mode." + << "\n"; } - else if(m_pcs->num_type_name.compare("HETERO_DISPERSION_FDM") == 0) + else if (m_pcs->num_type_name.compare("HETERO_DISPERSION_FDM") == 0) { rw_pcs->RWPTMode = 5; - std::cout << "RWPT is on " << m_pcs->num_type_name << " mode." << "\n"; + std::cout << "RWPT is on " << m_pcs->num_type_name << " mode." + << "\n"; } - else // HOMO Advection + Dispersion + else // HOMO Advection + Dispersion { rw_pcs->RWPTMode = 0; - std::cout << "RWPT is on HOMO_ADVECTION_DISPERSION mode." << "\n"; + std::cout << "RWPT is on HOMO_ADVECTION_DISPERSION mode." + << "\n"; } - if(m_pcs->num_type_name.find("FDM") != std::string::npos) + if (m_pcs->num_type_name.find("FDM") != std::string::npos) { rw_pcs->PURERWPT = 2; - if(rw_pcs->FDMIndexSwitch == 0) + if (rw_pcs->FDMIndexSwitch == 0) { rw_pcs->buildFDMIndex(); // Switch off @@ -3488,13 +3604,13 @@ inline double Problem::RandomWalker() } } - if(rwpt_numsplits < 0) - rwpt_numsplits = 10; // JT 2010 set default value, unless specified in .tim input file + if (rwpt_numsplits < 0) + rwpt_numsplits = 10; // JT 2010 set default value, unless specified in .tim input file - rw_pcs->AdvanceBySplitTime(dt,rwpt_numsplits); + rw_pcs->AdvanceBySplitTime(dt, rwpt_numsplits); // rw_pcs->TraceStreamline(); // JT, no longer needed print_result = true; - rw_pcs->RandomWalkOutput(aktuelle_zeit,aktueller_zeitschritt); + rw_pcs->RandomWalkOutput(aktuelle_zeit, aktueller_zeitschritt); } return 0.0; @@ -3517,18 +3633,17 @@ inline double Problem::Deformation() dm_pcs = (CRFProcessDeformation*)(m_pcs); error = dm_pcs->Execute(loop_process_number); - if( dm_pcs->pcs_type_name_vector.size()>0 - &&dm_pcs->pcs_type_name_vector[0].find("DYNAMIC") != std::string::npos) + if (dm_pcs->pcs_type_name_vector.size() > 0 && dm_pcs->pcs_type_name_vector[0].find("DYNAMIC") != std::string::npos) { - return error; + return error; } - //Error + // Error if (dm_pcs->type / 10 == 4) { m_pcs->cal_integration_point_value = true; dm_pcs->CalIntegrationPointValue(); - if(dm_pcs->type == 42) // H2M. 07.2011. WW + if (dm_pcs->type == 42) // H2M. 07.2011. WW dm_pcs->CalcSecondaryVariablesUnsaturatedFlow(); } return error; @@ -3545,16 +3660,16 @@ inline double Problem::Deformation() **************************************************************************/ inline void Problem::LOPExecuteRegionalRichardsFlow(CRFProcess* m_pcs_global, int loop_process_number) { - int j,k; + int j, k; long i; MeshLib::CElem* m_ele = NULL; -// TF not used MeshLib::CNode* m_nod = NULL; + // TF not used MeshLib::CNode* m_nod = NULL; int no_local_elements = m_pcs_global->m_msh->getNumberOfMeshLayers(); int no_local_nodes = no_local_elements + 1; - long g_element_number,g_node_number; + long g_element_number, g_node_number; CFEMesh* m_msh_local = NULL; CRFProcess* m_pcs_local = NULL; - Math_Group::vecele_nodes(20); + Math_Group::vec ele_nodes(20); double value; #if defined(USE_MPI_REGSOIL) double* values; @@ -3563,61 +3678,58 @@ inline void Problem::LOPExecuteRegionalRichardsFlow(CRFProcess* m_pcs_global, in int l; #endif int timelevel = 1; - int idxp = m_pcs_global->GetNodeValueIndex("PRESSURE1") + timelevel; - //WW int idxcp = m_pcs_global->GetNodeValueIndex("PRESSURE_CAP") + timelevel; - int idxS = m_pcs_global->GetNodeValueIndex("SATURATION1") + timelevel; + int idxp = m_pcs_global->GetNodeValueIndex("PRESSURE1") + timelevel; + // WW int idxcp = m_pcs_global->GetNodeValueIndex("PRESSURE_CAP") + timelevel; + int idxS = m_pcs_global->GetNodeValueIndex("SATURATION1") + timelevel; MeshLib::CElem* m_ele_local = NULL; MeshLib::CNode* m_nod_local = NULL; #if defined(USE_MPI_REGSOIL) - values = new double[no_local_nodes]; // Should be more sophisticated + values = new double[no_local_nodes]; // Should be more sophisticated #endif //====================================================================== - if(aktueller_zeitschritt == 1) + if (aktueller_zeitschritt == 1) { //-------------------------------------------------------------------- // Create local RICHARDS process - std::cout << " Create local RICHARDS process" << "\n"; + std::cout << " Create local RICHARDS process" + << "\n"; m_pcs_local = new CRFProcess(); - m_pcs_local->isRSM = true; //WW + m_pcs_local->isRSM = true; // WW // m_pcs_local->pcs_type_name = m_pcs_global->pcs_type_name; // TF - m_pcs_local->setProcessType (m_pcs_global->getProcessType()); + m_pcs_local->setProcessType(m_pcs_global->getProcessType()); m_pcs_local->num_type_name = m_pcs_global->num_type_name; m_pcs_local->cpl_type_name = m_pcs_global->cpl_type_name; m_pcs_local->Write_Matrix = m_pcs_global->Write_Matrix; m_pcs_local->pcs_type_number = (int)pcs_vector.size(); m_pcs_local->Config(); - m_pcs_local->setProblemObjectPointer(m_pcs_global->getProblemObjectPointer()); //WW 18.08.2011. WW + m_pcs_local->setProblemObjectPointer(m_pcs_global->getProblemObjectPointer()); // WW 18.08.2011. WW //-------------------------------------------------------------------- // Create local MSH - m_msh_local = new CFEMesh( - m_pcs_global->m_msh->getGEOObjects(), m_pcs_global->m_msh->getProjectName()); + m_msh_local = new CFEMesh(m_pcs_global->m_msh->getGEOObjects(), m_pcs_global->m_msh->getProjectName()); m_msh_local->geo_name = "RICHARDS_FLOW_LOCAL"; - m_msh_local->setElementType (MshElemType::LINE); - m_msh_local->setNumberOfMeshLayers (m_pcs_global->m_msh->getNumberOfMeshLayers()); + m_msh_local->setElementType(MshElemType::LINE); + m_msh_local->setNumberOfMeshLayers(m_pcs_global->m_msh->getNumberOfMeshLayers()); //.................................................................... m_msh_local->ele_vector.resize(no_local_elements); - for(j = 0; j < no_local_elements; j++) + for (j = 0; j < no_local_elements; j++) { m_ele = m_pcs_global->m_msh->ele_vector[j]; - m_ele_local = new MeshLib::CElem(j,m_ele); - for(k = 0; k < 2; k++) // ele_type + m_ele_local = new MeshLib::CElem(j, m_ele); + for (k = 0; k < 2; k++) // ele_type m_ele_local->getNodeIndices()[k] = j + k; m_msh_local->ele_vector[j] = m_ele_local; } m_msh_local->nod_vector.resize(no_local_nodes); m_msh_local->Eqs2Global_NodeIndex.resize(no_local_nodes); - for(j = 0; j < no_local_nodes; j++) + for (j = 0; j < no_local_nodes; j++) { -// TF m_nod = m_pcs_global->m_msh->nod_vector[j]; - m_nod_local = new MeshLib::CNode( - j, - m_pcs_global->m_msh->nod_vector[j]-> - getData()); - //m_nod_local = m_nod; + // TF m_nod = m_pcs_global->m_msh->nod_vector[j]; + m_nod_local = new MeshLib::CNode(j, m_pcs_global->m_msh->nod_vector[j]->getData()); + // m_nod_local = m_nod; m_msh_local->nod_vector[j] = m_nod_local; m_msh_local->nod_vector[j]->SetEquationIndex(j); m_msh_local->Eqs2Global_NodeIndex[j] = m_msh_local->nod_vector[j]->GetIndex(); @@ -3647,29 +3759,31 @@ inline void Problem::LOPExecuteRegionalRichardsFlow(CRFProcess* m_pcs_global, in */ m_pcs_local->st_node_value.clear(); m_pcs_local->st_node.clear(); - for(j = 0; j < (int)m_pcs_global->st_node_value.size(); j++) + for (j = 0; j < (int)m_pcs_global->st_node_value.size(); j++) m_pcs_local->st_node_value.push_back(m_pcs_global->st_node_value[j]); - for(j = 0; j < (int)m_pcs_global->st_node.size(); j++) + for (j = 0; j < (int)m_pcs_global->st_node.size(); j++) m_pcs_local->st_node.push_back(m_pcs_global->st_node[j]); //.................................................................... pcs_vector.push_back(m_pcs_local); } //====================================================================== else - for(i = 0; i < (long)m_pcs_global->m_msh->nod_vector.size(); i++) + for (i = 0; i < (long)m_pcs_global->m_msh->nod_vector.size(); i++) { - value = m_pcs_global->GetNodeValue(i,idxp); - m_pcs_global->SetNodeValue(i,idxp - 1,value); - //WW value = m_pcs_global->GetNodeValue(i,idxcp); - //WW m_pcs_global->SetNodeValue(i,idxcp-1,value); - value = m_pcs_global->GetNodeValue(i,idxS); - m_pcs_global->SetNodeValue(i,idxS - 1,value); + value = m_pcs_global->GetNodeValue(i, idxp); + m_pcs_global->SetNodeValue(i, idxp - 1, value); + // WW value = m_pcs_global->GetNodeValue(i,idxcp); + // WW m_pcs_global->SetNodeValue(i,idxcp-1,value); + value = m_pcs_global->GetNodeValue(i, idxS); + m_pcs_global->SetNodeValue(i, idxS - 1, value); } //====================================================================== - std::cout << "\n ================================================" << "\n"; + std::cout << "\n ================================================" + << "\n"; std::cout << " ->Process " << loop_process_number << ": " - << "REGIONAL_" << convertProcessTypeToString (m_pcs_global->getProcessType()) << "\n"; - std::cout << " ================================================" << "\n"; + << "REGIONAL_" << convertProcessTypeToString(m_pcs_global->getProcessType()) << "\n"; + std::cout << " ================================================" + << "\n"; int no_richards_problems = (int)(m_pcs_global->m_msh->ele_vector.size() / no_local_elements); //--- For couping with ground flow process. WW @@ -3677,39 +3791,42 @@ inline void Problem::LOPExecuteRegionalRichardsFlow(CRFProcess* m_pcs_global, in MeshLib::GridsTopo* neighb_grid = NULL; CRFProcess* neighb_pcs = total_processes[1]; - if(neighb_pcs) - for(i = 0; i < (int)neighb_pcs->m_msh->grid_neighbors.size(); i++) + if (neighb_pcs) + for (i = 0; i < (int)neighb_pcs->m_msh->grid_neighbors.size(); i++) { neighb_grid = neighb_pcs->m_msh->grid_neighbors[i]; - if(neighb_grid->getNeighbor_Name().find("SECTOR_SOIL") != std::string::npos) + if (neighb_grid->getNeighbor_Name().find("SECTOR_SOIL") != std::string::npos) break; neighb_grid = NULL; } - //------------ +//------------ #ifndef USE_MPI_REGSOIL - for(i = 0; i < no_richards_problems; i++) - //for(i=0;i<2;i++) + for (i = 0; i < no_richards_problems; i++) + // for(i=0;i<2;i++) { - if(i>0) std::cout << " ================================================" << "\n"; + if (i > 0) + std::cout << " ================================================" + << "\n"; std::cout << " ->Column number: " << i << "\n"; - std::cout << " ================================================" << "\n"; + std::cout << " ================================================" + << "\n"; m_pcs_local = pcs_vector[(int)pcs_vector.size() - 1]; m_pcs_local->pcs_number = i; m_msh_local = fem_msh_vector[(int)fem_msh_vector.size() - 1]; //.................................................................... // Set local NODs - for(j = 0; j < no_local_nodes; j++) + for (j = 0; j < no_local_nodes; j++) { g_node_number = j + (i * no_local_nodes); -// TF not used m_nod = m_pcs_global->m_msh->nod_vector[g_node_number]; + // TF not used m_nod = m_pcs_global->m_msh->nod_vector[g_node_number]; m_nod_local = m_msh_local->nod_vector[j]; - //m_nod_local = m_nod; + // m_nod_local = m_nod; m_nod_local->getConnectedElementIDs().push_back(i); - //m_nod_local->ok_dummy = i; + // m_nod_local->ok_dummy = i; } //.................................................................... // Set local ELEs - for(j = 0; j < no_local_elements; j++) + for (j = 0; j < no_local_elements; j++) { g_element_number = j + (i * no_local_elements); m_ele = m_pcs_global->m_msh->ele_vector[g_element_number]; @@ -3718,48 +3835,48 @@ inline void Problem::LOPExecuteRegionalRichardsFlow(CRFProcess* m_pcs_global, in } //.................................................................... // Set ICs - if(aktueller_zeitschritt == 1) //YD + if (aktueller_zeitschritt == 1) // YD - for(j = 0; j < no_local_nodes; j++) + for (j = 0; j < no_local_nodes; j++) { g_node_number = j + (i * no_local_nodes); - value = m_pcs_global->GetNodeValue(g_node_number,idxp); - m_pcs_local->SetNodeValue(j,idxp - 1,value); - m_pcs_local->SetNodeValue(j,idxp,value); - //WW value = m_pcs_global->GetNodeValue(g_node_number,idxcp); - //WW m_pcs_local->SetNodeValue(j,idxcp-1,value); - //WW m_pcs_local->SetNodeValue(j,idxcp,value); - value = m_pcs_global->GetNodeValue(g_node_number,idxS); - m_pcs_local->SetNodeValue(j,idxS - 1,value); - m_pcs_local->SetNodeValue(j,idxS,value); + value = m_pcs_global->GetNodeValue(g_node_number, idxp); + m_pcs_local->SetNodeValue(j, idxp - 1, value); + m_pcs_local->SetNodeValue(j, idxp, value); + // WW value = m_pcs_global->GetNodeValue(g_node_number,idxcp); + // WW m_pcs_local->SetNodeValue(j,idxcp-1,value); + // WW m_pcs_local->SetNodeValue(j,idxcp,value); + value = m_pcs_global->GetNodeValue(g_node_number, idxS); + m_pcs_local->SetNodeValue(j, idxS - 1, value); + m_pcs_local->SetNodeValue(j, idxS, value); } else - for(j = 0; j < no_local_nodes; j++) + for (j = 0; j < no_local_nodes; j++) { g_node_number = j + (i * no_local_nodes); - value = m_pcs_global->GetNodeValue(g_node_number,idxp); - m_pcs_local->SetNodeValue(j,idxp - 1,value); - //value = m_pcs_global->GetNodeValue(g_node_number,idxcp); - //m_pcs_local->SetNodeValue(j,idxcp-1,value); - value = m_pcs_global->GetNodeValue(g_node_number,idxS); - m_pcs_local->SetNodeValue(j,idxS - 1,value); + value = m_pcs_global->GetNodeValue(g_node_number, idxp); + m_pcs_local->SetNodeValue(j, idxp - 1, value); + // value = m_pcs_global->GetNodeValue(g_node_number,idxcp); + // m_pcs_local->SetNodeValue(j,idxcp-1,value); + value = m_pcs_global->GetNodeValue(g_node_number, idxS); + m_pcs_local->SetNodeValue(j, idxS - 1, value); } //.................................................................... // Set local BCs - //WW m_pcs_local->CreateBCGroup(); + // WW m_pcs_local->CreateBCGroup(); //.................................................................... // Set local STs - //WW m_pcs_local->CreateSTGroup(); + // WW m_pcs_local->CreateSTGroup(); // look for corresponding OF-triangle // m_ele_of = m_msh_of->GetElement(m_pnt_sf); //.................................................................... //---- Source term from neighbor process. 25.05.2009. WW idx_v = m_pcs_local->GetNodeValueIndex("VELOCITY_Z1"); - if(neighb_grid) + if (neighb_grid) { CSourceTerm* m_st = NULL; CNodeValue* m_nod_val = NULL; - if(aktueller_zeitschritt == 1) + if (aktueller_zeitschritt == 1) { m_st = new CSourceTerm(); m_nod_val = new CNodeValue(); @@ -3769,51 +3886,46 @@ inline void Problem::LOPExecuteRegionalRichardsFlow(CRFProcess* m_pcs_global, in else { m_st = m_pcs_local->st_node[(int)m_pcs_local->st_node.size() - 1]; - m_nod_val = - m_pcs_local->st_node_value[(int)m_pcs_local->st_node_value. - size() - - 1]; + m_nod_val = m_pcs_local->st_node_value[(int)m_pcs_local->st_node_value.size() - 1]; } - //WW long *local_indxs = NULL; - //WW local_indxs = neighb_grid->getBorderNodeIndicies(); + // WW long *local_indxs = NULL; + // WW local_indxs = neighb_grid->getBorderNodeIndicies(); m_nod_val->msh_node_number = no_local_nodes - 1; m_nod_val->geo_node_number = no_local_nodes - 1; - // m_nod_val->node_value = -neighb_pcs->GetNodeValue(local_indxs[i], neighb_pcs->GetNodeValueIndex("VELOCITY_Z1")) + // m_nod_val->node_value = -neighb_pcs->GetNodeValue(local_indxs[i], + // neighb_pcs->GetNodeValueIndex("VELOCITY_Z1")) // /neighb_pcs->time_unit_factor; - m_nod_val->node_value = -m_pcs_global->GetNodeValue( - i, - m_pcs_global-> - GetNodeValueIndex("VELOCITY_Z1")) + m_nod_val->node_value = -m_pcs_global->GetNodeValue(i, m_pcs_global->GetNodeValueIndex("VELOCITY_Z1")) / neighb_pcs->time_unit_factor; - m_pcs_global->SetNodeValue(i, m_pcs_global->GetNodeValueIndex( - "VELOCITY_Z1"),0.); + m_pcs_global->SetNodeValue(i, m_pcs_global->GetNodeValueIndex("VELOCITY_Z1"), 0.); } //----------------------------------------------------- - m_pcs_local->ExecuteNonLinear(loop_process_number,false); + m_pcs_local->ExecuteNonLinear(loop_process_number, false); // Velocity. 22.05.2009. WW m_pcs_local->CalIntegrationPointValue(); m_pcs_local->Extropolation_GaussValue(); m_pcs_local->cal_integration_point_value = false; //.................................................................... // Store results in global PCS tables - for(j = 0; j < no_local_nodes; j++) + for (j = 0; j < no_local_nodes; j++) { g_node_number = j + (i * no_local_nodes); - value = m_pcs_local->GetNodeValue(j,idxp); - m_pcs_global->SetNodeValue(g_node_number,idxp,value); + value = m_pcs_local->GetNodeValue(j, idxp); + m_pcs_global->SetNodeValue(g_node_number, idxp, value); // value = m_pcs_local->GetNodeValue(j,idxcp); - //m_pcs_global->SetNodeValue(g_node_number,idxcp,value); - value = m_pcs_local->GetNodeValue(j,idxS); - m_pcs_global->SetNodeValue(g_node_number,idxS,value); - //WW. 22.05.2009 - value = m_pcs_local->GetNodeValue(j,idx_v); - m_pcs_global->SetNodeValue(g_node_number,idx_v,value); + // m_pcs_global->SetNodeValue(g_node_number,idxcp,value); + value = m_pcs_local->GetNodeValue(j, idxS); + m_pcs_global->SetNodeValue(g_node_number, idxS, value); + // WW. 22.05.2009 + value = m_pcs_local->GetNodeValue(j, idx_v); + m_pcs_global->SetNodeValue(g_node_number, idx_v, value); } - //m_pcs->m_msh = FEMGet("RICHARDS_FLOW"); + // m_pcs->m_msh = FEMGet("RICHARDS_FLOW"); // pcs->m_msh->RenumberNodesForGlobalAssembly(); related to Comment 1 // MB/WW - if (!m_pcs_local->TimeStepAccept()) { + if (!m_pcs_local->TimeStepAccept()) + { m_pcs_global->accepted = false; break; } @@ -3825,10 +3937,10 @@ inline void Problem::LOPExecuteRegionalRichardsFlow(CRFProcess* m_pcs_global, in std::cout << "Num parallel blocks: " << num_parallel_blocks << "\n"; #endif - for(i = 0; i < num_parallel_blocks + 1; i++) - //for(i=0;i<2;i++) + for (i = 0; i < num_parallel_blocks + 1; i++) + // for(i=0;i<2;i++) { - if(i * size + myrank < no_richards_problems) // Do a parallel block + if (i * size + myrank < no_richards_problems) // Do a parallel block { rp = i * size + myrank; m_pcs_local = pcs_vector[(int)pcs_vector.size() - 1]; @@ -3836,18 +3948,18 @@ inline void Problem::LOPExecuteRegionalRichardsFlow(CRFProcess* m_pcs_global, in m_msh_local = fem_msh_vector[(int)fem_msh_vector.size() - 1]; //.................................................................... // Set local NODs - for(j = 0; j < no_local_nodes; j++) + for (j = 0; j < no_local_nodes; j++) { g_node_number = j + (rp * no_local_nodes); m_nod = m_pcs_global->m_msh->nod_vector[g_node_number]; m_nod_local = m_msh_local->nod_vector[j]; - //m_nod_local = m_nod; + // m_nod_local = m_nod; // ???? m_nod_local->connected_elements.push_back(rp); } //.................................................................... // Set local ELEs - for(j = 0; j < no_local_elements; j++) + for (j = 0; j < no_local_elements; j++) { g_element_number = j + (rp * no_local_elements); m_ele = m_pcs_global->m_msh->ele_vector[g_element_number]; @@ -3856,130 +3968,95 @@ inline void Problem::LOPExecuteRegionalRichardsFlow(CRFProcess* m_pcs_global, in } //.................................................................... // Set ICs - if(aktueller_zeitschritt == 1) //YD + if (aktueller_zeitschritt == 1) // YD - for(j = 0; j < no_local_nodes; j++) + for (j = 0; j < no_local_nodes; j++) { g_node_number = j + (rp * no_local_nodes); - value = m_pcs_global->GetNodeValue(g_node_number,idxp); - m_pcs_local->SetNodeValue(j,idxp - 1,value); - m_pcs_local->SetNodeValue(j,idxp,value); - value = m_pcs_global->GetNodeValue(g_node_number,idxcp); - m_pcs_local->SetNodeValue(j,idxcp - 1,value); - m_pcs_local->SetNodeValue(j,idxcp,value); - value = m_pcs_global->GetNodeValue(g_node_number,idxS); - m_pcs_local->SetNodeValue(j,idxS - 1,value); - m_pcs_local->SetNodeValue(j,idxS,value); + value = m_pcs_global->GetNodeValue(g_node_number, idxp); + m_pcs_local->SetNodeValue(j, idxp - 1, value); + m_pcs_local->SetNodeValue(j, idxp, value); + value = m_pcs_global->GetNodeValue(g_node_number, idxcp); + m_pcs_local->SetNodeValue(j, idxcp - 1, value); + m_pcs_local->SetNodeValue(j, idxcp, value); + value = m_pcs_global->GetNodeValue(g_node_number, idxS); + m_pcs_local->SetNodeValue(j, idxS - 1, value); + m_pcs_local->SetNodeValue(j, idxS, value); } else - for(j = 0; j < no_local_nodes; j++) + for (j = 0; j < no_local_nodes; j++) { g_node_number = j + (rp * no_local_nodes); - value = m_pcs_global->GetNodeValue(g_node_number,idxp); - m_pcs_local->SetNodeValue(j,idxp - 1,value); - value = m_pcs_global->GetNodeValue(g_node_number,idxcp); - m_pcs_local->SetNodeValue(j,idxcp - 1,value); - value = m_pcs_global->GetNodeValue(g_node_number,idxS); - m_pcs_local->SetNodeValue(j,idxS - 1,value); + value = m_pcs_global->GetNodeValue(g_node_number, idxp); + m_pcs_local->SetNodeValue(j, idxp - 1, value); + value = m_pcs_global->GetNodeValue(g_node_number, idxcp); + m_pcs_local->SetNodeValue(j, idxcp - 1, value); + value = m_pcs_global->GetNodeValue(g_node_number, idxS); + m_pcs_local->SetNodeValue(j, idxS - 1, value); } //.................................................................... // Set local BCs m_pcs_local->CreateBCGroup(); - //.................................................................... - // Set local STs - // m_pcs_local->CreateSTGroup(); - // look for corresponding OF-triangle - // m_ele_of = m_msh_of->GetElement(m_pnt_sf); - //.................................................................... +//.................................................................... +// Set local STs +// m_pcs_local->CreateSTGroup(); +// look for corresponding OF-triangle +// m_ele_of = m_msh_of->GetElement(m_pnt_sf); +//.................................................................... #ifdef TRACE - std::cout << "Executing local process." << "\n"; + std::cout << "Executing local process." + << "\n"; #endif m_pcs_local->ExecuteNonLinear(loop_process_number); - } // End of parallel block + } // End of parallel block //.................................................................... // Store results in global PCS tables - for(int k = 0; k < size; k++) + for (int k = 0; k < size; k++) { rp = i * size + k; - if(rp < no_richards_problems) + if (rp < no_richards_problems) { - if(myrank == k) + if (myrank == k) { // idxp - for(l = 0; l < no_local_nodes; l++) + for (l = 0; l < no_local_nodes; l++) values[l] = m_pcs_local->GetNodeValue(l, idxp); - MPI_Bcast((void*)values, - no_local_nodes, - MPI_DOUBLE, - k, - comm_DDC); - for(l = 0; l < no_local_nodes; l++) - m_pcs_global->SetNodeValue(l + rp * no_local_nodes, - idxp, - values[l]); + MPI_Bcast((void*)values, no_local_nodes, MPI_DOUBLE, k, comm_DDC); + for (l = 0; l < no_local_nodes; l++) + m_pcs_global->SetNodeValue(l + rp * no_local_nodes, idxp, values[l]); // idxcp - for(l = 0; l < no_local_nodes; l++) + for (l = 0; l < no_local_nodes; l++) values[l] = m_pcs_local->GetNodeValue(l, idxcp); - MPI_Bcast((void*)values, - no_local_nodes, - MPI_DOUBLE, - k, - comm_DDC); - for(l = 0; l < no_local_nodes; l++) - m_pcs_global->SetNodeValue(l + rp * no_local_nodes, - idxcp, - values[l]); + MPI_Bcast((void*)values, no_local_nodes, MPI_DOUBLE, k, comm_DDC); + for (l = 0; l < no_local_nodes; l++) + m_pcs_global->SetNodeValue(l + rp * no_local_nodes, idxcp, values[l]); // idxS - for(l = 0; l < no_local_nodes; l++) + for (l = 0; l < no_local_nodes; l++) values[l] = m_pcs_local->GetNodeValue(l, idxS); - MPI_Bcast((void*)values, - no_local_nodes, - MPI_DOUBLE, - k, - comm_DDC); - for(l = 0; l < no_local_nodes; l++) - m_pcs_global->SetNodeValue(l + rp * no_local_nodes, - idxS, - values[l]); + MPI_Bcast((void*)values, no_local_nodes, MPI_DOUBLE, k, comm_DDC); + for (l = 0; l < no_local_nodes; l++) + m_pcs_global->SetNodeValue(l + rp * no_local_nodes, idxS, values[l]); } else { // idxp - MPI_Bcast((void*)values, - no_local_nodes, - MPI_DOUBLE, - k, - comm_DDC); - for(l = 0; l < no_local_nodes; l++) - m_pcs_global->SetNodeValue(l + rp * no_local_nodes, - idxp, - values[l]); + MPI_Bcast((void*)values, no_local_nodes, MPI_DOUBLE, k, comm_DDC); + for (l = 0; l < no_local_nodes; l++) + m_pcs_global->SetNodeValue(l + rp * no_local_nodes, idxp, values[l]); // idxcp - MPI_Bcast((void*)values, - no_local_nodes, - MPI_DOUBLE, - k, - comm_DDC); - for(l = 0; l < no_local_nodes; l++) - m_pcs_global->SetNodeValue(l + rp * no_local_nodes, - idxcp, - values[l]); + MPI_Bcast((void*)values, no_local_nodes, MPI_DOUBLE, k, comm_DDC); + for (l = 0; l < no_local_nodes; l++) + m_pcs_global->SetNodeValue(l + rp * no_local_nodes, idxcp, values[l]); // idxS - MPI_Bcast((void*)values, - no_local_nodes, - MPI_DOUBLE, - k, - comm_DDC); - for(l = 0; l < no_local_nodes; l++) - m_pcs_global->SetNodeValue(l + rp * no_local_nodes, - idxS, - values[l]); + MPI_Bcast((void*)values, no_local_nodes, MPI_DOUBLE, k, comm_DDC); + for (l = 0; l < no_local_nodes; l++) + m_pcs_global->SetNodeValue(l + rp * no_local_nodes, idxS, values[l]); } } } } #endif - //---------------------------------------------------------------------- +//---------------------------------------------------------------------- #if defined(USE_MPI_REGSOIL) delete[] values; @@ -4004,44 +4081,44 @@ void Problem::LOPCalcELEResultants() for (size_t p = 0; p < no_processes; p++) { m_pcs = pcs_vector[p]; - if (!m_pcs->selected) //OK4108 + if (!m_pcs->selected) // OK4108 continue; - //cout << "LOPCalcELEResultants: " << m_pcs->pcs_type_name << "\n"; + // cout << "LOPCalcELEResultants: " << m_pcs->pcs_type_name << "\n"; // TF - std::string pcs_type_name (convertProcessTypeToString(m_pcs->getProcessType())); + std::string pcs_type_name(convertProcessTypeToString(m_pcs->getProcessType())); // switch (m_pcs->pcs_type_name[0]) { switch (pcs_type_name[0]) { - default: - break; - case 'L': // Liquid flow - m_pcs->CalcELEVelocities(); - break; - case 'G': // Groundwater flow - m_pcs->CalcELEVelocities(); - break; - case 'A': // Gas flow - m_pcs->CalcELEVelocities(); - //m_pcs->CalcELEMassFluxes(); // BG - break; - case 'T': // Two-phase flow - break; - case 'C': // Componental flow - break; - case 'H': // Heat transport - break; - case 'M': // Mass transport - break; - case 'D': // Deformation - break; - case 'O': // Overland flow - m_pcs->CalcELEVelocities(); - break; - case 'R': // Richards flow - m_pcs->CalcELEVelocities(); - break; - case 'F': // Fluid Momentum - break; + default: + break; + case 'L': // Liquid flow + m_pcs->CalcELEVelocities(); + break; + case 'G': // Groundwater flow + m_pcs->CalcELEVelocities(); + break; + case 'A': // Gas flow + m_pcs->CalcELEVelocities(); + // m_pcs->CalcELEMassFluxes(); // BG + break; + case 'T': // Two-phase flow + break; + case 'C': // Componental flow + break; + case 'H': // Heat transport + break; + case 'M': // Mass transport + break; + case 'D': // Deformation + break; + case 'O': // Overland flow + m_pcs->CalcELEVelocities(); + break; + case 'R': // Richards flow + m_pcs->CalcELEVelocities(); + break; + case 'F': // Fluid Momentum + break; } } } @@ -4064,21 +4141,21 @@ void Problem::LOPCalcELEResultants() inline void Problem::ASMCalcNodeWDepth(CRFProcess* m_pcs) { int nidx, nidy, nidz; - //OK411 int timelevel = 1; + // OK411 int timelevel = 1; double WDepth; nidx = m_pcs->GetNodeValueIndex("HEAD") + 1; nidy = m_pcs->GetNodeValueIndex("WDEPTH"); nidz = m_pcs->GetNodeValueIndex("COUPLING"); - const size_t n_nodes (m_pcs->m_msh->nod_vector.size()); - for(size_t nn = 0; nn < n_nodes; nn++) + const size_t n_nodes(m_pcs->m_msh->nod_vector.size()); + for (size_t nn = 0; nn < n_nodes; nn++) { WDepth = m_pcs->GetNodeValue(nn, nidx) - m_pcs->m_msh->nod_vector[nn]->getData()[2]; // JOD only needed for GREEN_AMPT source term - m_pcs->SetNodeValue(nn,nidz, m_pcs->GetNodeValue(nn,nidz + 1) ); + m_pcs->SetNodeValue(nn, nidz, m_pcs->GetNodeValue(nn, nidz + 1)); if (WDepth < 0.0) - WDepth = 0.0; + WDepth = 0.0; m_pcs->SetNodeValue(nn, nidy, WDepth); } } @@ -4098,64 +4175,64 @@ inline void Problem::ASMCalcNodeWDepth(CRFProcess* m_pcs) /**************************************************************************/ void Problem::PCSCalcSecondaryVariables() { - //WW long j; + // WW long j; int i, ptype; CRFProcess* m_pcs = NULL; - //OK411 CRFProcess* m_pcs_phase_1 = NULL; - //OK411 CRFProcess* m_pcs_phase_2 = NULL; - //WW int ndx_p_gas_old,ndx_p_gas_new,ndx_p_liquid_old,ndx_p_liquid_new,ndx_p_cap_old; + // OK411 CRFProcess* m_pcs_phase_1 = NULL; + // OK411 CRFProcess* m_pcs_phase_2 = NULL; + // WW int ndx_p_gas_old,ndx_p_gas_new,ndx_p_liquid_old,ndx_p_liquid_new,ndx_p_cap_old; //---------------------------------------------------------------------- - //OK411 bool pcs_cpl = true; + // OK411 bool pcs_cpl = true; //---------------------------------------------------------------------- // Check if NAPLdissolution is modeled, required by MMPCalcSecondaryVariablesNew bool NAPLdiss = false; NAPLdiss = KNaplDissCheck(); /* go through all processes */ int no_processes = (int)pcs_vector.size(); - for(i = 0; i < no_processes; i++) + for (i = 0; i < no_processes; i++) { /* get process */ - //pcs = pcs->GetProcessByNumber(i+1); - m_pcs = pcs_vector[i]; //JOD - if(m_pcs != NULL) + // pcs = pcs->GetProcessByNumber(i+1); + m_pcs = pcs_vector[i]; // JOD + if (m_pcs != NULL) { ptype = m_pcs->GetObjType(); switch (ptype) { - case 1: /* Flow process */ - // do nothing - break; - case 66: - //Temp mit pcs, only for test MB - ASMCalcNodeWDepth(m_pcs); - break; - case 11: /* Non-isothermal flow process */ - break; - case 13: /* Non-isothermal flow process */ - break; - case 2: /* Mass transport process */ - break; - case 3: /* Heat transport */ - // do nothing - break; - case 4: /* Deformation */ - // do nothing - break; - case 41: /* Deformation-flow coupled system in monolithic scheme */ - // do nothing - break; - case 12: /* Multi-phase flow process */ - MMPCalcSecondaryVariablesNew(m_pcs, NAPLdiss); - //MMPCalcSecondaryVariablesNew(m_pcs); - break; - default: - //std::cout << "PCSCalcSecondaryVariables - nothing to do" << - //"\n"; - break; + case 1: /* Flow process */ + // do nothing + break; + case 66: + // Temp mit pcs, only for test MB + ASMCalcNodeWDepth(m_pcs); + break; + case 11: /* Non-isothermal flow process */ + break; + case 13: /* Non-isothermal flow process */ + break; + case 2: /* Mass transport process */ + break; + case 3: /* Heat transport */ + // do nothing + break; + case 4: /* Deformation */ + // do nothing + break; + case 41: /* Deformation-flow coupled system in monolithic scheme */ + // do nothing + break; + case 12: /* Multi-phase flow process */ + MMPCalcSecondaryVariablesNew(m_pcs, NAPLdiss); + // MMPCalcSecondaryVariablesNew(m_pcs); + break; + default: + // std::cout << "PCSCalcSecondaryVariables - nothing to do" << + //"\n"; + break; } - } //If - } // while + } // If + } // while } /************************************************************************** @@ -4165,10 +4242,10 @@ void Problem::PCSCalcSecondaryVariables() bool Problem::Check() { CRFProcess* m_pcs = NULL; - for(int i = 0; i < (int)total_processes.size(); i++) + for (int i = 0; i < (int)total_processes.size(); i++) { m_pcs = total_processes[i]; - if(!m_pcs->Check()) + if (!m_pcs->Check()) return false; } return true; @@ -4180,8 +4257,8 @@ bool Problem::Check() **************************************************************************/ bool MODCreate() { - PCSConfig(); //OK - if(!PCSCheck()) //OK + PCSConfig(); // OK + if (!PCSCheck()) // OK { std::cout << "Not enough data for MOD creation.\n"; return false; @@ -4204,5 +4281,4 @@ double Problem::getEndTime() { return end_time; } -#endif //BRNS - +#endif // BRNS diff --git a/FEM/problem.h b/FEM/problem.h old mode 100755 new mode 100644 index fa2c748e6..c7147b00b --- a/FEM/problem.h +++ b/FEM/problem.h @@ -14,7 +14,6 @@ #ifndef problem_INC #define problem_INC - #include class CRFProcess; @@ -22,74 +21,74 @@ class CRFProcess; #include "GEOObjects.h" //--------------------------------------------------------------------- -//Pointers to member functions +// Pointers to member functions class Problem; -typedef double (Problem::*ProblemMemFn)(void); -#define Call_Member_FN(object,ptrToMember) ((object)->*(ptrToMember)) +typedef double (Problem::*ProblemMemFn)(void); +#define Call_Member_FN(object, ptrToMember) ((object)->*(ptrToMember)) //--------------------------------------------------------------------- class Problem { - public: - Problem(char* filename = NULL); - ~Problem(); - void Euler_TimeDiscretize(); - void RosenBrock_TimeDiscretize() {}; - // +public: + Problem(char* filename = NULL); + ~Problem(); + void Euler_TimeDiscretize(); + void RosenBrock_TimeDiscretize(){}; + // void SetActiveProcesses(); void SetTimeActiveProcesses(); // JT2012 void PCSRestart(); // bool CouplingLoop(); void PostCouplingLoop(); - void PreCouplingLoop(CRFProcess *m_pcs = NULL); + void PreCouplingLoop(CRFProcess* m_pcs = NULL); // Copy u_n for auto time stepping - double* GetBufferArray(const bool is_x_k = false) - { - if(is_x_k) - return buffer_array1; - else - return buffer_array; - } + double* GetBufferArray(const bool is_x_k = false) + { + if (is_x_k) + return buffer_array1; + else + return buffer_array; + } int GetCPLMaxIterations() { return cpl_overall_max_iterations; } - /** - * get the geometric objects stored in GEOLIB::GEOObjects - * @return a pointer to an instance of class GEOLIB::GEOObjects - */ - const GEOLIB::GEOObjects* getGeoObj () const; - /** - * Get the name of the project. The name is used by GEOLIB::GEOObjects - * to access the geometric data. - * @return the name to acces geometric data - */ - const std::string& getGeoObjName () const; + * get the geometric objects stored in GEOLIB::GEOObjects + * @return a pointer to an instance of class GEOLIB::GEOObjects + */ + const GEOLIB::GEOObjects* getGeoObj() const; + /** + * Get the name of the project. The name is used by GEOLIB::GEOObjects + * to access the geometric data. + * @return the name to acces geometric data + */ + const std::string& getGeoObjName() const; #ifdef BRNS - // BRNS-Coupling: For writing spatially resolved reaction rates at the final iteration, - // we need to get the timing information. + // BRNS-Coupling: For writing spatially resolved reaction rates at the final iteration, + // we need to get the timing information. - double getCurrentTime(); - double getEndTime(); -#endif //BRNS + double getCurrentTime(); + double getEndTime(); +#endif // BRNS /// Set rank and size for MPI - void setRankandSize(const int rank, const int size) + void setRankandSize(const int rank, const int size) { - mrank = rank; - msize = size; + mrank = rank; + msize = size; } - private: - // Time: - double start_time; - double end_time; + +private: + // Time: + double start_time; + double end_time; double current_time; double* buffer_array; double* buffer_array1; int step_control_type; - bool last_dt_accepted; //JT - bool force_post_node_copy; //JT + bool last_dt_accepted; // JT + bool force_post_node_copy; // JT // Mixed time step WW - double dt0; // Save the original time step size + double dt0; // Save the original time step size // Controls bool external_coupling_exists; @@ -98,16 +97,16 @@ class Problem int loop_process_number; size_t max_time_steps; // - int lop_coupling_iterations; - bool CalcVelocities; - bool conducted; + int lop_coupling_iterations; + bool CalcVelocities; + bool conducted; - // Print flag - bool print_result; - // Processes + // Print flag + bool print_result; + // Processes - std::vector total_processes; - std::vector transport_processes; + std::vector total_processes; + std::vector transport_processes; std::vector multiphase_processes; std::vector singlephaseflow_process; ProblemMemFn* active_processes; @@ -117,54 +116,54 @@ class Problem bool* exe_flag; inline int AssignProcessIndex(CRFProcess* m_pcs, bool activefunc = true); // - void PCSCreate(); - // Perform processes: - inline double LiquidFlow(); - inline double RichardsFlow(); - inline double TwoPhaseFlow(); - inline double MultiPhaseFlow(); - inline double PS_Global(); // 03 2009 PCH - inline double MULTI_COMPONENTIAL_FLOW(); // 02 2011 AKS/NB - inline double TNEQ(); //07/2013 HS/TN - inline double TES(); //07/2013 HS/TN - inline double GroundWaterFlow(); - inline double ComponentalFlow(); - inline double OverlandFlow(); - inline double AirFlow(); - inline double HeatTransport(); - inline double FluidMomentum(); - inline double RandomWalker(); - inline double MassTrasport(); - inline double Deformation(); - // Accessory + void PCSCreate(); + // Perform processes: + inline double LiquidFlow(); + inline double RichardsFlow(); + inline double TwoPhaseFlow(); + inline double MultiPhaseFlow(); + inline double PS_Global(); // 03 2009 PCH + inline double MULTI_COMPONENTIAL_FLOW(); // 02 2011 AKS/NB + inline double TNEQ(); // 07/2013 HS/TN + inline double TES(); // 07/2013 HS/TN + inline double GroundWaterFlow(); + inline double ComponentalFlow(); + inline double OverlandFlow(); + inline double AirFlow(); + inline double HeatTransport(); + inline double FluidMomentum(); + inline double RandomWalker(); + inline double MassTrasport(); + inline double Deformation(); + // Accessory void LOPExecuteRegionalRichardsFlow(CRFProcess* m_pcs_global, int loop_process_number); void LOPCalcELEResultants(); inline void ASMCalcNodeWDepth(CRFProcess* m_pcs); void PCSCalcSecondaryVariables(); - bool Check(); //OK - void TestOutputEclipse(CRFProcess* m_pcs); //BG - void TestOutputDuMux(CRFProcess* m_pcs); //BG - void OutputMassOfComponentInModel(std::vector flow_pcs, CRFProcess *transport_pcs); //BG - void OutputMassOfGasInModel(CRFProcess* m_pcs); //BG + bool Check(); // OK + void TestOutputEclipse(CRFProcess* m_pcs); // BG + void TestOutputDuMux(CRFProcess* m_pcs); // BG + void OutputMassOfComponentInModel(std::vector flow_pcs, CRFProcess* transport_pcs); // BG + void OutputMassOfGasInModel(CRFProcess* m_pcs); // BG /** * pointer to an instance of class GEOObjects, * that manages geometric entities */ - GEOLIB::GEOObjects* _geo_obj; // TF + GEOLIB::GEOObjects* _geo_obj; // TF /** * project/file name for geometry file, * used to access data in data manager GEOObjects */ - std::string _geo_name; // TF + std::string _geo_name; // TF /// rank for MPI int mrank; - /// processor number for MPI + /// processor number for MPI int msize; static const size_t max_processes = 16; }; -extern bool MODCreate(); //OK +extern bool MODCreate(); // OK #endif diff --git a/FEM/prototyp.h b/FEM/prototyp.h index f06273e69..f0c429e36 100644 --- a/FEM/prototyp.h +++ b/FEM/prototyp.h @@ -25,8 +25,8 @@ /* Deklarationen der Funktionszeigerprototypen */ typedef void (*VoidFuncVoid)(void); -typedef void*(*VoidXFuncVoid)(void); -typedef void*(*VoidXFuncVoidX)(void*); +typedef void* (*VoidXFuncVoid)(void); +typedef void* (*VoidXFuncVoidX)(void*); typedef void (*VoidFuncCharX)(char*); typedef void (*VoidFuncInt)(int); typedef void (*VoidFuncIntFileX)(int, FILE*); @@ -51,8 +51,8 @@ typedef void (*VoidFuncLLX)(long, long*); typedef void (*VoidFuncLX)(long*); typedef void (*VoidFuncDouble)(double); typedef void (*VoidFuncLXDXDXD)(long, double*, double*, double*); -typedef void (*VoidFuncLIID)(long,int,int,double); -typedef void (*VoidFuncLIIDX)(long,int,int,double*); +typedef void (*VoidFuncLIID)(long, int, int, double); +typedef void (*VoidFuncLIIDX)(long, int, int, double*); typedef int (*IntFuncLIDX)(long, int, double*); typedef int (*IntFuncVoid)(void); typedef int (*IntFuncLong)(long); @@ -60,8 +60,8 @@ typedef int (*IntFuncFileX)(FILE*); typedef int (*IntFuncDXDXL)(double*, double*, long); typedef int (*IntFuncDXDXLVXL)(double*, double*, long, void (*)(double*, double*, double), long); typedef int (*IntFuncII)(int, int); -typedef int (*IntFuncIII)(int,int,int); -typedef long*(*LongXFuncLIX)(long, int*); +typedef int (*IntFuncIII)(int, int, int); +typedef long* (*LongXFuncLIX)(long, int*); typedef long (*LongFuncVoid)(void); typedef double (*DoubleFuncVoid)(void); typedef double (*DoubleFuncLong)(long); @@ -79,12 +79,12 @@ typedef double (*DoubleFuncILDDDD)(int, long, double, double, double, double); typedef double (*DoubleFuncILDDID)(int, long, double, double, double, double); typedef double (*DoubleFuncILLD)(int, long, long, double); typedef double (*DoubleFuncILLI)(int, long, long, int); -typedef double (*DoubleFuncIV)(int,...); -typedef double*(*DoubleXFuncLong)(long); -typedef double*(*DoubleXFuncLI)(long, int); -typedef double*(*DoubleXFuncLDX)(long, double*); -typedef double*(*DoubleXFuncLII)(long,int,int); +typedef double (*DoubleFuncIV)(int, ...); +typedef double* (*DoubleXFuncLong)(long); +typedef double* (*DoubleXFuncLI)(long, int); +typedef double* (*DoubleXFuncLDX)(long, double*); +typedef double* (*DoubleXFuncLII)(long, int, int); typedef void (*VoidFuncDXCDX)(double*, const double*); -typedef void*(*VoidXFuncIVoidX)(int,void*); -typedef double (*DoubleFuncIL)(int,long); +typedef void* (*VoidXFuncIVoidX)(int, void*); +typedef double (*DoubleFuncIL)(int, long); #endif diff --git a/FEM/rf_REACT_BRNS.cpp b/FEM/rf_REACT_BRNS.cpp index 1a25394a4..88ce73715 100644 --- a/FEM/rf_REACT_BRNS.cpp +++ b/FEM/rf_REACT_BRNS.cpp @@ -23,7 +23,7 @@ //#undef SEEK_SET //#undef SEEK_CUR //#undef SEEK_END -#include "mpi.h" //Parallel Computing Support +#include "mpi.h" //Parallel Computing Support #include "par_ddc.h" // HS 07.01.2008: Comment the following 2 lines on LiClus. // int size; @@ -51,11 +51,11 @@ REACT_BRNS::REACT_BRNS(void) cout << "Debugging #1." << endl; #ifdef GCC hDll = dlopen("./brns.so", RTLD_NOW); - if (hDll==NULL) + if (hDll == NULL) std::cout << "***error: failed to load a library ./brns.so" << std::endl; cout << "Debugging #2." << endl; invokebrns = (LPFNDLLFUNC)dlsym(hDll, "invokebrns_"); - if (invokebrns==NULL) + if (invokebrns == NULL) std::cout << "***error: failed to find a symbol \"invokebrns_\"" << std::endl; #endif cout << "Debugging #3." << endl; @@ -82,8 +82,7 @@ REACT_BRNS::~REACT_BRNS(void) #endif #ifdef TESTTIME - cout << "Total time spent in BRNS Coupling, including Solver: " << - timeSpentInBrnsCoupling << "s" << endl; + cout << "Total time spent in BRNS Coupling, including Solver: " << timeSpentInBrnsCoupling << "s" << endl; #endif } @@ -114,7 +113,7 @@ void REACT_BRNS::TestRUN(void) cout << "Calling invokebrns() ..." << endl; - //invokebrns(myArray, sizeOfArray, &returnValue); + // invokebrns(myArray, sizeOfArray, &returnValue); cout << "Returning from invokebrns(), return code " << returnValue << endl; cout << "New Concentrationvector:" << endl; @@ -122,7 +121,7 @@ void REACT_BRNS::TestRUN(void) for (int i = 0; i < sizeOfArray; i++) cout << i << ": " << myArray[i] << endl; - delete [] myArray; + delete[] myArray; myArray = NULL; } @@ -137,7 +136,7 @@ long REACT_BRNS::GetNodesNumber(void) // if (m_pcs->pcs_type_name.compare("MASS_TRANSPORT")==0) { if (m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) { - number = (long) m_pcs->m_msh->GetNodesNumber(false); + number = (long)m_pcs->m_msh->GetNodesNumber(false); return number; } } @@ -149,13 +148,13 @@ long REACT_BRNS::GetElemNumber(void) { long number; //------------read number of elems-------------- - for ( size_t i = 0; i < pcs_vector.size(); i++ ) + for (size_t i = 0; i < pcs_vector.size(); i++) { m_pcs = pcs_vector[i]; // if ( m_pcs->pcs_type_name.compare ( "MASS_TRANSPORT" ) ==0 ) { - if ( m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) + if (m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) { - number = ( long ) m_pcs->m_msh->ele_vector.size(); + number = (long)m_pcs->m_msh->ele_vector.size(); return number; } } @@ -198,19 +197,19 @@ void REACT_BRNS::InitBRNS(Problem* myProblem) #endif // Giving initial values - for ( int i = 0; i < num_Comp * nNodes; i++ ) + for (int i = 0; i < num_Comp * nNodes; i++) { cur_ts_Conc[i] = 0.0; pre_ts_Conc[i] = 0.0; m_dC_Chem_delta[i] = 0.0; } - for ( long k = 0; k < nNodes; k++) + for (long k = 0; k < nNodes; k++) { rt_BRNS[k] = 0; m_porosity_Node[k] = 0.0; } - if ( num_Comp > 0 && nNodes > 0 ) + if (num_Comp > 0 && nNodes > 0) init_flag = true; else { @@ -225,71 +224,60 @@ void REACT_BRNS::InitBRNS(Problem* myProblem) double BCValue = 0.0; int p, k; - for (long i = 0; i < nNodes; i++ ) - for ( k = 0; k < num_Comp; k++ ) + for (long i = 0; i < nNodes; i++) + for (k = 0; k < num_Comp; k++) { this_pcs = NULL; m_cp = cp_vec[k]; // Get the pointer to the proper PCS. - this_pcs = PCSGet( "MASS_TRANSPORT", m_cp->compname ); + this_pcs = PCSGet("MASS_TRANSPORT", m_cp->compname); if (this_pcs) - for(p = 0; p < this_pcs->pcs_number_of_primary_nvals; ++p) + for (p = 0; p < this_pcs->pcs_number_of_primary_nvals; ++p) { // Let's print BC and ST values CBoundaryConditionsGroup* m_bc_group = NULL; - const std::string tmp_pcs_type (convertProcessTypeToString( - this_pcs-> - getProcessType())); - m_bc_group = BCGetGroup( - tmp_pcs_type, - this_pcs->pcs_primary_function_name - [p]); + const std::string tmp_pcs_type(convertProcessTypeToString(this_pcs->getProcessType())); + m_bc_group = BCGetGroup(tmp_pcs_type, this_pcs->pcs_primary_function_name[p]); // BC printing - if( IsThisPointBCIfYesStoreValue(i, this_pcs, BCValue) ) + if (IsThisPointBCIfYesStoreValue(i, this_pcs, BCValue)) { // If this node is on the fixed boudnary for this component boundary_flag[i * num_Comp + k] = 1; - cout << "Node " << i << ", Comp " << k << - ",Value " << BCValue << endl; + cout << "Node " << i << ", Comp " << k << ",Value " << BCValue << endl; } else // If this node is NOT on the fixed boudnary for this component boundary_flag[i * num_Comp + k] = 0; } // end of for // end of if (this_pcs) - else // not getting the pointer to the proper PCS. + else // not getting the pointer to the proper PCS. { DisplayErrorMsg("!!! In InitBRNS, can not find corresponding PCS!"); abort(); } - } // end of for components + } // end of for components // fill in the porosity values. - for ( size_t i = 0; i < m_flow_pcs->m_msh->ele_vector.size(); i++ ) + for (size_t i = 0; i < m_flow_pcs->m_msh->ele_vector.size(); i++) { int idx_patch = m_flow_pcs->m_msh->ele_vector[i]->GetPatchIndex(); MediaProp = mmp_vector[idx_patch]; - m_porosity_Elem[i] = MediaProp->Porosity( i, 0.0 ); + m_porosity_Elem[i] = MediaProp->Porosity(i, 0.0); } // averaging to Nodes int idx_elem; double elem_volume; double total_volume; - for ( long i = 0; i < nNodes; i++ ) + for (long i = 0; i < nNodes; i++) { - if ( m_flow_pcs->m_msh->nod_vector[i]->getConnectedElementIDs().size() > 0 ) + if (m_flow_pcs->m_msh->nod_vector[i]->getConnectedElementIDs().size() > 0) { total_volume = 0.0; - for ( int j = 0; - j < - (int)m_flow_pcs->m_msh->nod_vector[i]->getConnectedElementIDs().size(); - j++ ) + for (int j = 0; j < (int)m_flow_pcs->m_msh->nod_vector[i]->getConnectedElementIDs().size(); j++) { - idx_elem = - m_flow_pcs->m_msh->nod_vector[i]->getConnectedElementIDs()[ - j]; + idx_elem = m_flow_pcs->m_msh->nod_vector[i]->getConnectedElementIDs()[j]; elem_volume = m_flow_pcs->m_msh->ele_vector[idx_elem]->GetVolume(); m_porosity_Node[i] += m_porosity_Elem[idx_elem] * elem_volume; total_volume += elem_volume; @@ -305,33 +293,27 @@ void REACT_BRNS::GSRF2Buffer(long i) { long i_times_num_Comp_plus_k = i * num_Comp; // for this node, loop over all the chemical components and update the values - for ( int k = 0; k < num_Comp; k++, i_times_num_Comp_plus_k++ ) + for (int k = 0; k < num_Comp; k++, i_times_num_Comp_plus_k++) { this_pcs = NULL; m_cp = cp_vec[k]; // Get the pointer to the proper PCS. - this_pcs = PCSGet( "MASS_TRANSPORT", m_cp->compname ); + this_pcs = PCSGet("MASS_TRANSPORT", m_cp->compname); if (this_pcs) { // Set the Concentration of this component - cur_ts_Conc[i_times_num_Comp_plus_k] = this_pcs->GetNodeValue( - i, - this_pcs-> - GetNodeValueIndex( this_pcs->pcs_primary_function_name[0] ) + 1 ); - pre_ts_Conc[i_times_num_Comp_plus_k] = this_pcs->GetNodeValue( - i, - this_pcs-> - GetNodeValueIndex( this_pcs->pcs_primary_function_name[0] ) + 0 ); + cur_ts_Conc[i_times_num_Comp_plus_k] + = this_pcs->GetNodeValue(i, this_pcs->GetNodeValueIndex(this_pcs->pcs_primary_function_name[0]) + 1); + pre_ts_Conc[i_times_num_Comp_plus_k] + = this_pcs->GetNodeValue(i, this_pcs->GetNodeValueIndex(this_pcs->pcs_primary_function_name[0]) + 0); } - else // not getting the pointer to the proper PCS. + else // not getting the pointer to the proper PCS. { #ifdef MFC - AfxMessageBox( - "!!! In Data transfer for BRNS, can not find corresponding PCS!"); + AfxMessageBox("!!! In Data transfer for BRNS, can not find corresponding PCS!"); #endif - DisplayErrorMsg( - "!!! In Data transfer for BRNS, can not find corresponding PCS!"); + DisplayErrorMsg("!!! In Data transfer for BRNS, can not find corresponding PCS!"); abort(); } } @@ -341,27 +323,25 @@ void REACT_BRNS::Buffer2GSRF(long i) { long i_times_num_Comp_plus_k = i * num_Comp; // for this node, loop over all the chemical components and update the values - for ( int k = 0; k < num_Comp; k++, i_times_num_Comp_plus_k++ ) + for (int k = 0; k < num_Comp; k++, i_times_num_Comp_plus_k++) { this_pcs = NULL; m_cp = cp_vec[k]; // Get the pointer to the proper PCS. - this_pcs = PCSGet( "MASS_TRANSPORT", m_cp->compname ); + this_pcs = PCSGet("MASS_TRANSPORT", m_cp->compname); if (this_pcs) // Set the Concentration of this component at current time step; - this_pcs->SetNodeValue( i, - this_pcs->GetNodeValueIndex( - this_pcs->pcs_primary_function_name[0]) + 1 /*1-current time step*/, - pre_ts_Conc[i_times_num_Comp_plus_k]); - else // not getting the pointer to the proper PCS. + this_pcs->SetNodeValue( + i, + this_pcs->GetNodeValueIndex(this_pcs->pcs_primary_function_name[0]) + 1 /*1-current time step*/, + pre_ts_Conc[i_times_num_Comp_plus_k]); + else // not getting the pointer to the proper PCS. { #ifdef MFC - AfxMessageBox( - "!!! In Data transfer for BRNS, can not find corresponding PCS!"); + AfxMessageBox("!!! In Data transfer for BRNS, can not find corresponding PCS!"); #endif - DisplayErrorMsg( - "!!! In Data transfer for BRNS, can not find corresponding PCS!"); + DisplayErrorMsg("!!! In Data transfer for BRNS, can not find corresponding PCS!"); abort(); } } @@ -371,21 +351,21 @@ void REACT_BRNS::RUN(double time_step) { long i; // this is the last call to the chemical solver and - if (myProblem->getEndTime() < myProblem->getCurrentTime() + time_step ) + if (myProblem->getEndTime() < myProblem->getCurrentTime() + time_step) { - rt_BRNS[0] = -1; // reaction rates should be printed by BRNS.dll for the whole domain + rt_BRNS[0] = -1; // reaction rates should be printed by BRNS.dll for the whole domain for (i = 1; i < nNodes; i++) // -1: delete a potentially existing rate file rt_BRNS[i] = -2; } #ifdef USE_MPI_BRNS if (myrank == 1) - startTime = clock(); // in MPI: make statistics only when running on one processor + startTime = clock(); // in MPI: make statistics only when running on one processor #else startTime = clock(); #endif // Loop over all nodes to transfer data - for ( i = 0; i < nNodes; i++ ) + for (i = 0; i < nNodes; i++) // Get Conc Data from GSRF; GSRF2Buffer(i); @@ -396,9 +376,9 @@ void REACT_BRNS::RUN(double time_step) // double porosity; double waterSaturation; - //------------end of reading number of nodes---- +//------------end of reading number of nodes---- - // Run BRNS +// Run BRNS #ifdef BRNS_OMP // ADD CONSIDERATION OF porosity and waterSaturation!!! // do it with OpenMP @@ -415,9 +395,10 @@ void REACT_BRNS::RUN(double time_step) omp_set_num_threads((int)NUM_THREADS); cout << "Max. thread num is:" << omp_get_max_threads() << endl; -#pragma \ - omp parallel for shared(nNodes_temp, num_Comp_temp, time_step, cur_ts_Conc_temp, pre_ts_Conc_temp, boundary_flag_temp) private(i,pos_x,pos_y,pos_z) - for ( i = 0; i < nNodes_temp; i++ ) +#pragma omp parallel for shared( \ + nNodes_temp, num_Comp_temp, time_step, cur_ts_Conc_temp, pre_ts_Conc_temp, boundary_flag_temp) private( \ + i, pos_x, pos_y, pos_z) + for (i = 0; i < nNodes_temp; i++) { pos_x = m_pcs->m_msh->nod_vector[i]->X(); pos_y = m_pcs->m_msh->nod_vector[i]->Y(); @@ -425,37 +406,36 @@ void REACT_BRNS::RUN(double time_step) //------------------------ // Prepare porosity and waterSaturation values (weighted sums?), or move to Buffer<->GSFR methods - //porosity = 0.0; + // porosity = 0.0; waterSaturation = 0.0; //------------------------ // Run BRNS; - invokebrns( &(cur_ts_Conc_temp[i * num_Comp_temp]), - &(pre_ts_Conc_temp[i * num_Comp_temp]), - &(pre_ts_Conc_temp[i * num_Comp_temp]), - &num_Comp_temp, - &time_step, - &(boundary_flag_temp[i * num_Comp_temp]), - &(rt_BRNS[i]), - &pos_x, - &pos_y, - &pos_z, - REACT_BRNS::m_porosity_Node + i, - &waterSaturation, - NULL ); - int num = omp_get_thread_num (); - cout << "#" << num << "thread reporting. My i is: " << - i /*cur_ts_Conc_temp[i*num_Comp_temp]*/ << endl; + invokebrns(&(cur_ts_Conc_temp[i * num_Comp_temp]), + &(pre_ts_Conc_temp[i * num_Comp_temp]), + &(pre_ts_Conc_temp[i * num_Comp_temp]), + &num_Comp_temp, + &time_step, + &(boundary_flag_temp[i * num_Comp_temp]), + &(rt_BRNS[i]), + &pos_x, + &pos_y, + &pos_z, + REACT_BRNS::m_porosity_Node + i, + &waterSaturation, + NULL); + int num = omp_get_thread_num(); + cout << "#" << num << "thread reporting. My i is: " << i /*cur_ts_Conc_temp[i*num_Comp_temp]*/ << endl; // cout << endl << "Number of threads " << omp_get_num_threads (); } #else // ifdef BRNS_OMP #ifdef USE_MPI_BRNS - MPI_Bcast(&nNodes, 1, MPI_LONG, 0, MPI_COMM_WORLD ); - MPI_Bcast(&num_Comp, 1, MPI_INT, 0, MPI_COMM_WORLD ); - for ( i = myrank; i < nNodes; i += mysize ) + MPI_Bcast(&nNodes, 1, MPI_LONG, 0, MPI_COMM_WORLD); + MPI_Bcast(&num_Comp, 1, MPI_INT, 0, MPI_COMM_WORLD); + for (i = myrank; i < nNodes; i += mysize) #else - for ( i = 0; i < nNodes; i++ ) + for (i = 0; i < nNodes; i++) #endif { // Check out if this node is on the boundary - A fixed boundary condition @@ -469,40 +449,41 @@ void REACT_BRNS::RUN(double time_step) // porosity = 0.0; waterSaturation = 0.0; - //------------------------ +//------------------------ - // Run BRNS; - // solverTime=0.0; - // if (pos_x== 0 && pos_y==0) { porosity=8; pos_z=99.9; waterSaturation=3.3; solverTime=7.0; cout << "solverTime passed to BRNS: " << solverTime << endl; } +// Run BRNS; +// solverTime=0.0; +// if (pos_x== 0 && pos_y==0) { porosity=8; pos_z=99.9; waterSaturation=3.3; solverTime=7.0; cout << "solverTime +// passed to BRNS: " << solverTime << endl; } #ifdef USE_MPI_BRNS - invokebrns( &(cur_ts_Conc[i * num_Comp]), - &(pre_ts_Conc[i * num_Comp]), - &(pre_ts_Conc_buf[i * num_Comp]), - &num_Comp, - &time_step, - &(boundary_flag[i * num_Comp]), - &(rt_BRNS[i]), - &pos_x, - &pos_y, - &pos_z, - REACT_BRNS::m_porosity_Node + i, - &waterSaturation, - NULL ); + invokebrns(&(cur_ts_Conc[i * num_Comp]), + &(pre_ts_Conc[i * num_Comp]), + &(pre_ts_Conc_buf[i * num_Comp]), + &num_Comp, + &time_step, + &(boundary_flag[i * num_Comp]), + &(rt_BRNS[i]), + &pos_x, + &pos_y, + &pos_z, + REACT_BRNS::m_porosity_Node + i, + &waterSaturation, + NULL); #else // ifdef USE_MPI_BRNS - invokebrns( &(cur_ts_Conc[i * num_Comp]), - &(pre_ts_Conc[i * num_Comp]), - &(pre_ts_Conc[i * num_Comp]), - &num_Comp, - &time_step, - &(boundary_flag[i * num_Comp]), - &(rt_BRNS[i]), - &pos_x, - &pos_y, - &pos_z, - REACT_BRNS::m_porosity_Node + i, - &waterSaturation, - NULL ); + invokebrns(&(cur_ts_Conc[i * num_Comp]), + &(pre_ts_Conc[i * num_Comp]), + &(pre_ts_Conc[i * num_Comp]), + &num_Comp, + &time_step, + &(boundary_flag[i * num_Comp]), + &(rt_BRNS[i]), + &pos_x, + &pos_y, + &pos_z, + REACT_BRNS::m_porosity_Node + i, + &waterSaturation, + NULL); #endif } #endif @@ -512,43 +493,40 @@ void REACT_BRNS::RUN(double time_step) #endif // calculate dC - for ( i = 0; i < nNodes * num_Comp; i++) + for (i = 0; i < nNodes * num_Comp; i++) m_dC_Chem_delta[i] = cur_ts_Conc[i] - pre_ts_Conc[i]; // Loop over all nodes to retrieve data - for ( i = 0; i < nNodes; i++ ) + for (i = 0; i < nNodes; i++) { // Set data back to GSRF Buffer2GSRF(i); if (rt_BRNS[i] == 2 || rt_BRNS[i] == 3) { - cout << "In Node " << i << - ": BRNS exceeded max newton iterations, aborting." << endl; + cout << "In Node " << i << ": BRNS exceeded max newton iterations, aborting." << endl; exit(10); } -#ifndef BRNS_NO_LOG // should be eventually changed to #ifdef BRNS_LOG +#ifndef BRNS_NO_LOG // should be eventually changed to #ifdef BRNS_LOG switch (rt_BRNS[i]) { - case 1: - cout << "In Node " << i << ": BRNS calculated negative concentration!" << - endl; - break; - case 2: - cout << "In Node " << i << ": BRNS exceeded max newton iterations!" << endl; - break; - case 3: - cout << "In Node " << i << ": BRNS calculated negative concentration, " << - "and exceeded max newton iterations!" << endl; - break; - // default: + case 1: + cout << "In Node " << i << ": BRNS calculated negative concentration!" << endl; + break; + case 2: + cout << "In Node " << i << ": BRNS exceeded max newton iterations!" << endl; + break; + case 3: + cout << "In Node " << i << ": BRNS calculated negative concentration, " + << "and exceeded max newton iterations!" << endl; + break; + // default: } - if (rt_BRNS[i] == 1 || rt_BRNS[i] == 3 ) + if (rt_BRNS[i] == 1 || rt_BRNS[i] == 3) { cout << "Still negative concentrations after chemical simulation for:"; for (int j = 0; j < num_Comp; j++) if (pre_ts_Conc[i * num_Comp + j] < 0.0) - cout << " Species " << j + 1 << ": " << - pre_ts_Conc[i * num_Comp + j]; + cout << " Species " << j + 1 << ": " << pre_ts_Conc[i * num_Comp + j]; cout << endl; } #endif @@ -560,41 +538,41 @@ void REACT_BRNS::RUN(double time_step) #ifdef USE_MPI_BRNS if (myrank == 1) - timeSpentInBrnsCoupling += (double) (clock() - startTime) / CLOCKS_PER_SEC; + timeSpentInBrnsCoupling += (double)(clock() - startTime) / CLOCKS_PER_SEC; #else - timeSpentInBrnsCoupling += (double) (clock() - startTime) / CLOCKS_PER_SEC; + timeSpentInBrnsCoupling += (double)(clock() - startTime) / CLOCKS_PER_SEC; - // cout << "solverTime=" << solverTime << "total "<< timeSpentInBrnsSolver << endl; +// cout << "solverTime=" << solverTime << "total "<< timeSpentInBrnsSolver << endl; #endif #ifdef BRNS_LOG #ifdef USE_MPI_BRNS if (myrank == 1) - cout << "Total time spent in BRNS Coupling and Solver: " << - timeSpentInBrnsCoupling << "s, " << timeSpentInBrnsSolver << "s " << endl; + cout << "Total time spent in BRNS Coupling and Solver: " << timeSpentInBrnsCoupling << "s, " + << timeSpentInBrnsSolver << "s " << endl; #else - cout << "Total time spent in BRNS Coupling and Solver: " << timeSpentInBrnsCoupling << - "s, " << timeSpentInBrnsSolver << "s " << endl; + cout << "Total time spent in BRNS Coupling and Solver: " << timeSpentInBrnsCoupling << "s, " + << timeSpentInBrnsSolver << "s " << endl; #endif #endif } int REACT_BRNS::IsThisPointBCIfYesStoreValue(int index, CRFProcess* m_pcs, double& value) { - for(int p = 0; p < (int)m_pcs->bc_node_value.size(); ++p) - if(index == m_pcs->bc_node_value[p]->msh_node_number) + for (int p = 0; p < (int)m_pcs->bc_node_value.size(); ++p) + if (index == m_pcs->bc_node_value[p]->msh_node_number) { value = m_pcs->bc_node_value[p]->node_value; - return 1; // Yes, found it. + return 1; // Yes, found it. } return 0; } // i_timestep 0: old timestep 1: new timestep -int REACT_BRNS::SetPorosityValue_MT ( long ele_Index, double m_porosity_Elem, int i_timestep ) +int REACT_BRNS::SetPorosityValue_MT(long ele_Index, double m_porosity_Elem, int i_timestep) { int idx; double old_porosity; @@ -604,88 +582,87 @@ int REACT_BRNS::SetPorosityValue_MT ( long ele_Index, double m_porosity_Elem, i CRFProcess* m_pcs = NULL; - if ( flowflag > 0 ) + if (flowflag > 0) { GetFluidProperty_MT(); - switch ( flowflag ) + switch (flowflag) { - case 1: - m_pcs = PCSGet ( "GROUNDWATER_FLOW" ); - idx = m_pcs->GetElementValueIndex ( "POROSITY" ); - - // set new porosity; - m_pcs->SetElementValue ( ele_Index, idx + i_timestep, m_porosity_Elem ); - break; - case 2: - m_pcs = PCSGet ( "LIQUID_FLOW" ); - idx = m_pcs->GetElementValueIndex ( "POROSITY" ); - // always write into the new step - m_pcs->SetElementValue ( ele_Index,idx + 1,m_porosity_Elem ); - break; - case 3: - - m_pcs = PCSGet ( "RICHARDS_FLOW" ); - idx = m_pcs->GetElementValueIndex ( "POROSITY" ); - // always write into the new step - if (m_pcs->GetElementValue(ele_Index,idx + 1) == 0) - m_pcs->SetElementValue ( ele_Index,idx + 1,m_porosity_Elem ); - else - if (m_porosity_Elem != m_pcs->GetElementValue(ele_Index,idx + 1) ) - { - cout << "Richards flow not supported - quitting program" << endl; - exit(1); - } - break; - m_pcs->SetElementValue ( ele_Index,idx + 1,m_porosity_Elem ); - break; - case 4: // kg44: do we have to update POROSITY_IL and POROSITY_SW? - m_pcs = PCSGet ( "TWO_PHASE_FLOW" ); - idx = m_pcs->GetElementValueIndex ( "POROSITY" ); - // always write into the new step - m_pcs->SetElementValue ( ele_Index,idx + 1,m_porosity_Elem ); - break; - default: + case 1: + m_pcs = PCSGet("GROUNDWATER_FLOW"); + idx = m_pcs->GetElementValueIndex("POROSITY"); + + // set new porosity; + m_pcs->SetElementValue(ele_Index, idx + i_timestep, m_porosity_Elem); + break; + case 2: + m_pcs = PCSGet("LIQUID_FLOW"); + idx = m_pcs->GetElementValueIndex("POROSITY"); + // always write into the new step + m_pcs->SetElementValue(ele_Index, idx + 1, m_porosity_Elem); + break; + case 3: + + m_pcs = PCSGet("RICHARDS_FLOW"); + idx = m_pcs->GetElementValueIndex("POROSITY"); + // always write into the new step + if (m_pcs->GetElementValue(ele_Index, idx + 1) == 0) + m_pcs->SetElementValue(ele_Index, idx + 1, m_porosity_Elem); + else if (m_porosity_Elem != m_pcs->GetElementValue(ele_Index, idx + 1)) + { + cout << "Richards flow not supported - quitting program" << endl; + exit(1); + } + break; + m_pcs->SetElementValue(ele_Index, idx + 1, m_porosity_Elem); + break; + case 4: // kg44: do we have to update POROSITY_IL and POROSITY_SW? + m_pcs = PCSGet("TWO_PHASE_FLOW"); + idx = m_pcs->GetElementValueIndex("POROSITY"); + // always write into the new step + m_pcs->SetElementValue(ele_Index, idx + 1, m_porosity_Elem); + break; + default: #ifdef USE_MPI_BRNS - if ( myrank == 0 /*should be set to root*/ ) + if (myrank == 0 /*should be set to root*/) #endif - DisplayErrorMsg ( "Error: Not implemented for the flow in BRNS case!!!" ); - break; + DisplayErrorMsg("Error: Not implemented for the flow in BRNS case!!!"); + break; } } return 1; } -void REACT_BRNS::GetFluidProperty_MT ( void ) +void REACT_BRNS::GetFluidProperty_MT(void) { - m_FluidProp = MFPGet ( "LIQUID" ); + m_FluidProp = MFPGet("LIQUID"); } -int REACT_BRNS::GetFlowType_MT ( void ) +int REACT_BRNS::GetFlowType_MT(void) { - //flow type - for ( size_t i = 0; i < pcs_vector.size(); i++ ) + // flow type + for (size_t i = 0; i < pcs_vector.size(); i++) { m_pcs = pcs_vector[i]; // if ( m_pcs->pcs_type_name.compare ( "GROUNDWATER_FLOW" ) ==0 ) { - if ( m_pcs->getProcessType() == FiniteElement::GROUNDWATER_FLOW) + if (m_pcs->getProcessType() == FiniteElement::GROUNDWATER_FLOW) { m_flow_pcs = m_pcs; return 1; } // else if ( m_pcs->pcs_type_name.compare ( "LIQUID_FLOW" ) ==0 ) { - else if ( m_pcs->getProcessType() == FiniteElement::LIQUID_FLOW ) + else if (m_pcs->getProcessType() == FiniteElement::LIQUID_FLOW) { m_flow_pcs = m_pcs; return 2; } // else if ( m_pcs->pcs_type_name.compare ( "RICHARDS_FLOW" ) ==0 ) { - else if ( m_pcs->getProcessType() == FiniteElement::RICHARDS_FLOW ) + else if (m_pcs->getProcessType() == FiniteElement::RICHARDS_FLOW) { m_flow_pcs = m_pcs; return 3; } // else if ( m_pcs->pcs_type_name.compare ( "TWO_PHASE_FLOW" ) ==0 ) { - else if ( m_pcs->getProcessType() == FiniteElement::TWO_PHASE_FLOW ) + else if (m_pcs->getProcessType() == FiniteElement::TWO_PHASE_FLOW) { m_flow_pcs = m_pcs; return 4; @@ -695,43 +672,44 @@ int REACT_BRNS::GetFlowType_MT ( void ) } // i_timestep: 0: old timestep 1: new timestep -void REACT_BRNS::ConvPorosityNodeValue2Elem ( int i_timestep ) +void REACT_BRNS::ConvPorosityNodeValue2Elem(int i_timestep) { - long i,idx_Node; + long i, idx_Node; size_t j, number_of_nodes; - double pormin = 2.0,pormax = 0.0; + double pormin = 2.0, pormax = 0.0; MeshLib::CNode* m_Node; MeshLib::CElem* m_Elem; - for ( i = 0; i < nElems; i++ ) + for (i = 0; i < nElems; i++) { - m_Elem = m_pcs->m_msh->ele_vector[i]; + m_Elem = m_pcs->m_msh->ele_vector[i]; // first set the parameters to zero; m_porosity_Elem[i] = 0.0; // then get the values from nodes - for ( j = 0; j < m_Elem->GetNodesNumber ( false ); j++ ) + for (j = 0; j < m_Elem->GetNodesNumber(false); j++) { - idx_Node = m_Elem->GetNodeIndex ( j ); // get the connected nodes; + idx_Node = m_Elem->GetNodeIndex(j); // get the connected nodes; m_Node = m_pcs->m_msh->nod_vector[idx_Node]; - number_of_nodes = m_Elem->GetNodesNumber ( false ); + number_of_nodes = m_Elem->GetNodesNumber(false); // m_porosity_Elem[i] += m_porosity[idx_Node] / number_of_nodes; // this is arithmetric mean - // here we use harmonic mean, as porosity is used for permeability/diffusivity changes....flux in the element is strongly influenced by the minimum values + // here we use harmonic mean, as porosity is used for permeability/diffusivity changes....flux in the + // element is strongly influenced by the minimum values // this is for harmonic mean m_porosity_Elem[i] += 1.0 / m_porosity_Node[idx_Node] / number_of_nodes; } // cout << "error in ConvPorosity" << endl; - if ( m_porosity_Elem[i] > 1.e6 ) + if (m_porosity_Elem[i] > 1.e6) m_porosity_Elem[i] = 1.e6; m_porosity_Elem[i] = 1.0 / m_porosity_Elem[i]; - pormin = min ( pormin,m_porosity_Elem[i] ); - pormax = max ( pormax,m_porosity_Elem[i] ); + pormin = min(pormin, m_porosity_Elem[i]); + pormax = max(pormax, m_porosity_Elem[i]); // push back porosities - SetPorosityValue_MT ( i, m_porosity_Elem[i], i_timestep ); + SetPorosityValue_MT(i, m_porosity_Elem[i], i_timestep); } cout << "min, max porosity: " << pormin << " " << pormax << endl; } @@ -740,22 +718,17 @@ void REACT_BRNS::ConvPorosityNodeValue2Elem ( int i_timestep ) void REACT_BRNS::GetBRNSResult_MPI(void) { // Retrieve the values from MPI buffer to the main memory - MPI_Allreduce( rt_BRNS_buf, rt_BRNS, nNodes, MPI_INT, MPI_SUM, MPI_COMM_WORLD); - MPI_Allreduce( pre_ts_Conc_buf, - pre_ts_Conc, - num_Comp * nNodes, - MPI_DOUBLE, - MPI_SUM, - MPI_COMM_WORLD); + MPI_Allreduce(rt_BRNS_buf, rt_BRNS, nNodes, MPI_INT, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(pre_ts_Conc_buf, pre_ts_Conc, num_Comp * nNodes, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); } void REACT_BRNS::CleanMPIBuffer(void) { long in; - for ( in = 0; in < nNodes; in++) + for (in = 0; in < nNodes; in++) rt_BRNS_buf[in] = 0; - for ( in = 0; in < num_Comp * nNodes; in++) + for (in = 0; in < num_Comp * nNodes; in++) pre_ts_Conc_buf[in] = 0.0; } #endif -#endif // end of BRNS +#endif // end of BRNS diff --git a/FEM/rf_REACT_BRNS.h b/FEM/rf_REACT_BRNS.h index f26323099..d3d00d4a0 100644 --- a/FEM/rf_REACT_BRNS.h +++ b/FEM/rf_REACT_BRNS.h @@ -20,20 +20,20 @@ #ifdef BRNS #ifdef WIN32 #pragma once -extern "C" __declspec( dllimport ) void brnsIsAlive(); -extern "C" __declspec( dllimport ) void invokebrns(double* theCurArray, - double* thePreArray, - double* outputArray, - int* sizeOfArray, - double* time_step, - int* boundary_flag, - int* returnValue, - double* pos_x, - double* pos_y, - double* pos_z, - double* porosity, - double* waterSaturation, - double* parameterVector); +extern "C" __declspec(dllimport) void brnsIsAlive(); +extern "C" __declspec(dllimport) void invokebrns(double* theCurArray, + double* thePreArray, + double* outputArray, + int* sizeOfArray, + double* time_step, + int* boundary_flag, + int* returnValue, + double* pos_x, + double* pos_y, + double* pos_z, + double* porosity, + double* waterSaturation, + double* parameterVector); #endif #endif @@ -64,9 +64,9 @@ class REACT_BRNS #ifdef GCC void* hDll; -// void* hDll, * hDll_1, * hDll_2; - typedef void (*LPFNDLLFUNC)(double*, double*, double*, int*, double*, int*, int*, double*, - double*, double*, double*, double*, double*); + // void* hDll, * hDll_1, * hDll_2; + typedef void (*LPFNDLLFUNC)(double*, double*, double*, int*, double*, int*, int*, double*, double*, double*, + double*, double*, double*); LPFNDLLFUNC invokebrns; #endif @@ -77,7 +77,7 @@ class REACT_BRNS #endif // pointer to the PCS Class; - CRFProcess* m_pcs, * this_pcs, * m_flow_pcs; + CRFProcess *m_pcs, *this_pcs, *m_flow_pcs; Problem* myProblem; // pointer to MFP class @@ -116,16 +116,16 @@ class REACT_BRNS void InitBRNS(Problem* myProblem); // Data transfer btw GeoSys and BRNS; - void GSRF2Buffer( long i ); - void Buffer2GSRF( long i ); + void GSRF2Buffer(long i); + void Buffer2GSRF(long i); // BC node checking int IsThisPointBCIfYesStoreValue(int index, CRFProcess* m_pcs, double& value); // porosity setting function - int SetPorosityValue_MT ( long ele_Index, double m_porosity_Elem, int i_timestep ); - void GetFluidProperty_MT ( void ); - void ConvPorosityNodeValue2Elem( int i_timestep ); + int SetPorosityValue_MT(long ele_Index, double m_porosity_Elem, int i_timestep); + void GetFluidProperty_MT(void); + void ConvPorosityNodeValue2Elem(int i_timestep); private: // For measuring the time spent in BRNS calls diff --git a/FEM/rf_REACT_GEM.cpp b/FEM/rf_REACT_GEM.cpp index dbb8b52da..0401d2ef1 100644 --- a/FEM/rf_REACT_GEM.cpp +++ b/FEM/rf_REACT_GEM.cpp @@ -7,30 +7,32 @@ * */ - /** - * rf_REACT_GEM.cpp - * Haibing Shao 25.03.08 - * haibing.shao@ufz.de - * GEM Reaction Package - * based on the PSI node-GEM source code - * using the node-GEM code from Paul Sherrer Institute (PSI) - * current maintainer: Georg Kosakowski - * georg.kosakowski@psi.ch - * last major changes: 01 April 2010 start of doxygen documentation - * 03 April 2010 start of cleaning code and reducing memory consumption/communication for ! - * 05.10.2010 extend doxygen documentation, kintetics with solid solutions and richards flow coupling - * 22. Feb. 2012 extended for multi-threading, needs boost library and fixed GEMS3K kernel - * June 2012 adjusted Richards flow coupling and added density dependence - * Code description - * - * The files rf_REACT_GEM.cpp and rf_REACT_GEM.h contain the main core modules of the OpenGeosys - GEMIPM2K coupling. - * GEMIPM2K is the calculation kernel of GEMS-PSI (http://gems.web.psi.ch). GEMS-PSI executables for various platforms are freely - * availabe for download. - * The the kernel GEMIPM2K source code is available on request. - * GEMIPM2K is currently coupled in a non-iterave sequential way to groundwater flow and transport. The coupling to the Richards flow - * module is under development. - * - */ +/** +* rf_REACT_GEM.cpp +* Haibing Shao 25.03.08 +* haibing.shao@ufz.de +* GEM Reaction Package +* based on the PSI node-GEM source code +* using the node-GEM code from Paul Sherrer Institute (PSI) +* current maintainer: Georg Kosakowski +* georg.kosakowski@psi.ch +* last major changes: 01 April 2010 start of doxygen documentation +* 03 April 2010 start of cleaning code and reducing memory consumption/communication for ! +* 05.10.2010 extend doxygen documentation, kintetics with solid solutions and richards flow coupling +* 22. Feb. 2012 extended for multi-threading, needs boost library and fixed GEMS3K kernel +* June 2012 adjusted Richards flow coupling and added density dependence +* Code description +* +* The files rf_REACT_GEM.cpp and rf_REACT_GEM.h contain the main core modules of the OpenGeosys - GEMIPM2K coupling. +* GEMIPM2K is the calculation kernel of GEMS-PSI (http://gems.web.psi.ch). GEMS-PSI executables for various platforms +*are freely +* availabe for download. +* The the kernel GEMIPM2K source code is available on request. +* GEMIPM2K is currently coupled in a non-iterave sequential way to groundwater flow and transport. The coupling to the +*Richards flow +* module is under development. +* +*/ // There is a name conflict between stdio.h and the MPI C++ binding // with respect to the names SEEK_SET, SEEK_CUR, and SEEK_END. MPI @@ -59,7 +61,7 @@ #include "fem_ele_vec.h" // ----------------------- #include "files0.h" -//Headers for shuffling +// Headers for shuffling #include #include #include @@ -82,7 +84,7 @@ using namespace std; /** REACT_GEM() is the main constructor. It initializes several variables with default values. */ -REACT_GEM::REACT_GEM ( void ) +REACT_GEM::REACT_GEM(void) { REACT_GEM::dch_input_file_path = "calcite-dch.dat"; REACT_GEM::ipm_input_file_path = "calcite-ipm.dat"; @@ -104,23 +106,23 @@ REACT_GEM::REACT_GEM ( void ) initialized_flag = 0; heatflag = 0; flowflag = 0; - flag_porosity_change = 1; //0-not coupled;1=coupled; - min_possible_porosity = 1.e-4; // minimum porostiy in case of changing porosity: avoid zero porosity - max_possible_porosity = 0.9999; // max porosity - flag_coupling_hydrology = 1; //0-not coupled;1=coupled; - m_gem_temperature = 298.15; //default gem temperature is 25°C, in Kelvin! - m_gem_pressure = 1.0e+5; // default pressure 1 bar - flag_iterative_scheme = 0; //0-not iteration;1=iteration; - flag_disable_gems = 0; // always calculate gems + flag_porosity_change = 1; // 0-not coupled;1=coupled; + min_possible_porosity = 1.e-4; // minimum porostiy in case of changing porosity: avoid zero porosity + max_possible_porosity = 0.9999; // max porosity + flag_coupling_hydrology = 1; // 0-not coupled;1=coupled; + m_gem_temperature = 298.15; // default gem temperature is 25°C, in Kelvin! + m_gem_pressure = 1.0e+5; // default pressure 1 bar + flag_iterative_scheme = 0; // 0-not iteration;1=iteration; + flag_disable_gems = 0; // always calculate gems // flag for different iterative scheme // 0 - sequential non-iterative scheme // 1 - standard iterative scheme // 2 - symetric iterative scheme // 3 - strang splitting scheme - flag_transport_b = 1; // default is transport full speciation; 1: transport only dissolved components of b vector - gem_mass_scale = 1.0e-0; // GEMS default mass scaling parameter - flag_calculate_boundary_nodes = 0; // set to zero if boundary nodes should not change the porosity - m_max_failed_nodes = 5; //default number of max allowed nodes to fail + flag_transport_b = 1; // default is transport full speciation; 1: transport only dissolved components of b vector + gem_mass_scale = 1.0e-0; // GEMS default mass scaling parameter + flag_calculate_boundary_nodes = 0; // set to zero if boundary nodes should not change the porosity + m_max_failed_nodes = 5; // default number of max allowed nodes to fail m_diff_gems = 0.0; Fem_Ele_Std = NULL; @@ -129,110 +131,110 @@ REACT_GEM::REACT_GEM ( void ) string tinit_path = " "; boost::barrier* gem_barrier_start; - boost::barrier* gem_barrier_finish; + boost::barrier* gem_barrier_finish; boost::thread* gemThread; boost::mutex rwmutex, getnode_mutex; -// the next two definitions are set to default values such that they can be used in serial version + // the next two definitions are set to default values such that they can be used in serial version myrank = 0; mysize = 1; } -REACT_GEM::~REACT_GEM ( void ) +REACT_GEM::~REACT_GEM(void) { - if ( initialized_flag > 0 ) + if (initialized_flag > 0) { - delete [] m_xDC; - delete [] m_gam; - delete [] m_xPH; - delete []m_aPH; - delete [] m_bSP; - delete []m_vPS; - delete []m_mPS; - delete []m_bPS; - delete []m_xPA; - delete []m_dul; - delete []m_dll; - delete []m_uIC; - delete []m_bIC; - delete []m_bIC_dummy; - delete []m_rMB; - delete []m_xDC_pts; - delete []m_soluteB_pts; - delete []m_bIC_pts; - delete []m_xDC_MT_delta; - delete []m_xDC_Chem_delta; - delete []m_NodeHandle; - - delete [] m_NodeStatusCH; - delete [] m_IterDone; - delete [] m_IterDoneIndex; - delete [] m_IterDoneCumulative; - delete [] m_T; - delete [] m_P; - delete [] m_Vs; - delete [] m_Ms; - delete [] m_Gs; - delete [] m_Hs; - delete [] m_IC; - delete [] m_pH; - delete [] m_pe; - delete [] m_Eh; - delete [] m_porosity; - delete [] m_porosity_initial; - delete [] m_excess_water; - delete [] m_excess_gas; - delete [] m_Node_Volume; - delete [] m_gas_volume; - delete [] m_fluid_volume; - delete [] m_fluid_density; - delete [] m_soluteB; - delete [] m_soluteB_buff; + delete[] m_xDC; + delete[] m_gam; + delete[] m_xPH; + delete[] m_aPH; + delete[] m_bSP; + delete[] m_vPS; + delete[] m_mPS; + delete[] m_bPS; + delete[] m_xPA; + delete[] m_dul; + delete[] m_dll; + delete[] m_uIC; + delete[] m_bIC; + delete[] m_bIC_dummy; + delete[] m_rMB; + delete[] m_xDC_pts; + delete[] m_soluteB_pts; + delete[] m_bIC_pts; + delete[] m_xDC_MT_delta; + delete[] m_xDC_Chem_delta; + delete[] m_NodeHandle; + + delete[] m_NodeStatusCH; + delete[] m_IterDone; + delete[] m_IterDoneIndex; + delete[] m_IterDoneCumulative; + delete[] m_T; + delete[] m_P; + delete[] m_Vs; + delete[] m_Ms; + delete[] m_Gs; + delete[] m_Hs; + delete[] m_IC; + delete[] m_pH; + delete[] m_pe; + delete[] m_Eh; + delete[] m_porosity; + delete[] m_porosity_initial; + delete[] m_excess_water; + delete[] m_excess_gas; + delete[] m_Node_Volume; + delete[] m_gas_volume; + delete[] m_fluid_volume; + delete[] m_fluid_density; + delete[] m_soluteB; + delete[] m_soluteB_buff; // delete MPI buffer-------- - delete [] m_NodeHandle_buff; - delete [] m_NodeStatusCH_buff; - delete [] m_IterDone_buff; - - delete [] m_Vs_buff; - delete [] m_Ms_buff; - delete [] m_Gs_buff; - delete [] m_Hs_buff; - delete [] m_IC_buff; - delete [] m_pH_buff; - delete [] m_pe_buff; - delete [] m_Eh_buff; - - delete [] m_xDC_buff; - delete [] m_xPH_buff; - delete [] m_xPA_buff; - delete [] m_excess_water_buff; - delete [] m_excess_gas_buff; - delete [] m_porosity_buff; - delete [] m_boundary; - delete [] m_gas_volume_buff; - delete [] m_fluid_volume_buff; - delete [] m_fluid_density_buff; - delete [] m_dul_buff; - delete [] m_dll_buff; - delete [] m_xDC_pts_buff; - delete [] m_xDC_MT_delta_buff; - delete [] m_xDC_Chem_delta_buff; - delete [] m_aPH_buff; - delete [] m_bIC_buff; - delete [] m_bIC_dummy_buff; - delete [] m_porosity_Elem_buff; - delete [] m_porosity_Elem; + delete[] m_NodeHandle_buff; + delete[] m_NodeStatusCH_buff; + delete[] m_IterDone_buff; + + delete[] m_Vs_buff; + delete[] m_Ms_buff; + delete[] m_Gs_buff; + delete[] m_Hs_buff; + delete[] m_IC_buff; + delete[] m_pH_buff; + delete[] m_pe_buff; + delete[] m_Eh_buff; + + delete[] m_xDC_buff; + delete[] m_xPH_buff; + delete[] m_xPA_buff; + delete[] m_excess_water_buff; + delete[] m_excess_gas_buff; + delete[] m_porosity_buff; + delete[] m_boundary; + delete[] m_gas_volume_buff; + delete[] m_fluid_volume_buff; + delete[] m_fluid_density_buff; + delete[] m_dul_buff; + delete[] m_dll_buff; + delete[] m_xDC_pts_buff; + delete[] m_xDC_MT_delta_buff; + delete[] m_xDC_Chem_delta_buff; + delete[] m_aPH_buff; + delete[] m_bIC_buff; + delete[] m_bIC_dummy_buff; + delete[] m_porosity_Elem_buff; + delete[] m_porosity_Elem; // ------------------------- - delete [] mol_phase; - delete [] omega_phase; - delete [] omega_components; + delete[] mol_phase; + delete[] omega_phase; + delete[] omega_components; - delete [] dmdt; - delete [] omega_phase_buff; // this we need for kinetics - delete [] mol_phase_buff; // this we need for kinetics - delete [] omega_components_buff; // this we need for kinetics + delete[] dmdt; + delete[] omega_phase_buff; // this we need for kinetics + delete[] mol_phase_buff; // this we need for kinetics + delete[] omega_components_buff; // this we need for kinetics - delete [] dmdt_buff; + delete[] dmdt_buff; m_flow_pcs = NULL; m_kin.clear(); @@ -248,7 +250,7 @@ REACT_GEM::~REACT_GEM ( void ) The easiest way to prepare them is to use GEMS-PSI code (GEM2MT module) */ -short REACT_GEM::Init_Nodes ( string Project_path) +short REACT_GEM::Init_Nodes(string Project_path) { long ii = 0, i = 0, in = 0; // make sure we have the correct values @@ -259,15 +261,16 @@ short REACT_GEM::Init_Nodes ( string Project_path) glob_NodesNumber_Linear = GetGlobalNodeNumber_MT(); loc_NodesNumber_Linear = GetLocalNodeNumber_MT(); NodesNumber_Linear = GetNodeNumber_MT(); - gem_glob_buff = new PetscScalar[glob_NodesNumber_Linear]; //m_size is defined in the petsc part...this re-usable buffer has size of vector in global equation system + gem_glob_buff = new PetscScalar[glob_NodesNumber_Linear]; // m_size is defined in the petsc part...this re-usable + // buffer has size of vector in global equation system gem_glob_x0 = new PetscScalar[glob_NodesNumber_Linear]; gem_glob_x1 = new PetscScalar[glob_NodesNumber_Linear]; #endif TNode* m_Node; // DATABR structure for exchange with GEMIPM - DATACH* dCH; //pointer to DATACH - DATABR* dBR; //pointer to DATABR + DATACH* dCH; // pointer to DATACH + DATABR* dBR; // pointer to DATABR // Creating TNode structure accessible trough node pointer // Here we read the files needed as input for initializing GEMIPM2K @@ -278,52 +281,52 @@ short REACT_GEM::Init_Nodes ( string Project_path) dCH = m_Node->pCSD(); dBR = m_Node->pCNode(); - if ( Load_Init_File ( Project_path, m_Node ) ) + if (Load_Init_File(Project_path, m_Node)) { // The init file is successfully loaded // Getting direct access to DataCH structure in GEMIPM2K memory dBR->NodeStatusCH = NEED_GEM_AIA; - m_Node->GEM_run ( false ); -//iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii + m_Node->GEM_run(false); + // iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii // The init file is successfully loaded // Getting direct access to DataCH structure in GEMIPM2K memory -//iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii + // iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii // Extracting data bridge array sizes - nIC = dCH->nICb; //Num of Independent components - nDC = dCH->nDCb; //Num of Chemical species in the reactive part - nPH = dCH->nPHb; //Num of Phases - nPS = dCH->nPSb; //Num of multicomponent phases; ASSERT(nPS < nPH) + nIC = dCH->nICb; // Num of Independent components + nDC = dCH->nDCb; // Num of Chemical species in the reactive part + nPH = dCH->nPHb; // Num of Phases + nPS = dCH->nPSb; // Num of multicomponent phases; ASSERT(nPS < nPH) // get the index of water idx_water = FindWater_xDC(m_Node); // imediately check - if ( idx_water == -1 ) + if (idx_water == -1) return 1; // get index for H and OH idx_oxygen = Findoxygen_bIC(m_Node); // imediately check - if ( idx_oxygen == -1 ) + if (idx_oxygen == -1) return 1; idx_hydrogen = Findhydrogen_bIC(m_Node); // imediately check - if ( idx_hydrogen == -1 ) + if (idx_hydrogen == -1) return 1; - heatflag = GetHeatFlag_MT(); // Get heatflag - flowflag = GetFlowType_MT(); // Get flow flag + heatflag = GetHeatFlag_MT(); // Get heatflag + flowflag = GetFlowType_MT(); // Get flow flag // get m_flow_pcs already, then check the flag: - if ( flag_coupling_hydrology == 1 ) + if (flag_coupling_hydrology == 1) // need to couple to flow process; // mark the flag m_flow_pcs->flag_couple_GEMS = 1; else - m_flow_pcs->flag_couple_GEMS = 0; //default is set to not-coupled! + m_flow_pcs->flag_couple_GEMS = 0; // default is set to not-coupled! - gem_pressure_flag = 0; // use not a user defined pressure + gem_pressure_flag = 0; // use not a user defined pressure // Get number of Nodes nNodes = GetNodeNumber_MT(); // Get number of Elems @@ -331,135 +334,136 @@ short REACT_GEM::Init_Nodes ( string Project_path) // kg44 03 april 2010 first we take all variables that we need for all nodes! // Allocating work memory for FMT part (here only chemical variables) - m_NodeHandle = new long [nNodes]; - m_NodeHandle_buff = new long [nNodes]; + m_NodeHandle = new long[nNodes]; + m_NodeHandle_buff = new long[nNodes]; - m_NodeStatusCH = new long [nNodes]; - m_NodeStatusCH_buff = new long [nNodes]; + m_NodeStatusCH = new long[nNodes]; + m_NodeStatusCH_buff = new long[nNodes]; - m_IterDone = new long [nNodes]; + m_IterDone = new long[nNodes]; m_IterDone_buff = new long[nNodes]; - m_IterDoneCumulative = new long [nNodes]; + m_IterDoneCumulative = new long[nNodes]; m_IterDoneIndex = new long[nNodes]; // MPI Buffer Variable--------------- - m_boundary = new int [nNodes]; // this marks boundary nodes with fixed concentrations!? - m_T = new double [nNodes]; - m_P = new double [nNodes]; + m_boundary = new int[nNodes]; // this marks boundary nodes with fixed concentrations!? + m_T = new double[nNodes]; + m_P = new double[nNodes]; - m_Vs = new double [nNodes]; + m_Vs = new double[nNodes]; m_Vs_buff = new double[nNodes]; - m_Ms = new double [nNodes]; + m_Ms = new double[nNodes]; m_Ms_buff = new double[nNodes]; - m_Gs = new double [nNodes]; + m_Gs = new double[nNodes]; m_Gs_buff = new double[nNodes]; - m_Hs = new double [nNodes]; + m_Hs = new double[nNodes]; m_Hs_buff = new double[nNodes]; - m_IC = new double [nNodes]; + m_IC = new double[nNodes]; m_IC_buff = new double[nNodes]; - m_pH = new double [nNodes]; + m_pH = new double[nNodes]; m_pH_buff = new double[nNodes]; - m_pe = new double [nNodes]; + m_pe = new double[nNodes]; m_pe_buff = new double[nNodes]; - m_Eh = new double [nNodes]; + m_Eh = new double[nNodes]; m_Eh_buff = new double[nNodes]; - m_porosity = new double [nNodes]; + m_porosity = new double[nNodes]; m_porosity_buff = new double[nNodes]; - m_porosity_initial = new double [nNodes]; - m_volumes_initial = new double [nNodes * nPH]; + m_porosity_initial = new double[nNodes]; + m_volumes_initial = new double[nNodes * nPH]; - m_excess_water = new double [nNodes]; - m_excess_water_buff = new double [nNodes]; + m_excess_water = new double[nNodes]; + m_excess_water_buff = new double[nNodes]; - m_excess_gas = new double [nNodes]; - m_excess_gas_buff = new double [nNodes]; + m_excess_gas = new double[nNodes]; + m_excess_gas_buff = new double[nNodes]; - m_Node_Volume = new double [nNodes]; + m_Node_Volume = new double[nNodes]; - m_fluid_volume = new double [nNodes]; - m_fluid_volume_buff = new double [nNodes]; + m_fluid_volume = new double[nNodes]; + m_fluid_volume_buff = new double[nNodes]; - m_fluid_density = new double [nNodes]; - m_fluid_density_buff = new double [nNodes]; + m_fluid_density = new double[nNodes]; + m_fluid_density_buff = new double[nNodes]; - m_gas_volume = new double [nNodes]; - m_gas_volume_buff = new double [nNodes]; + m_gas_volume = new double[nNodes]; + m_gas_volume_buff = new double[nNodes]; - m_porosity_Elem = new double [nElems]; - m_porosity_Elem_buff = new double [nElems]; + m_porosity_Elem = new double[nElems]; + m_porosity_Elem_buff = new double[nElems]; - m_soluteB = new double [nNodes * nIC]; - m_soluteB_buff = new double [nNodes * nIC]; + m_soluteB = new double[nNodes * nIC]; + m_soluteB_buff = new double[nNodes * nIC]; - m_bIC = new double [nNodes * nIC]; - m_bIC_buff = new double [nNodes * nIC]; + m_bIC = new double[nNodes * nIC]; + m_bIC_buff = new double[nNodes * nIC]; - m_bIC_dummy = new double [nNodes * nIC]; - m_bIC_dummy_buff = new double [nNodes * nIC]; + m_bIC_dummy = new double[nNodes * nIC]; + m_bIC_dummy_buff = new double[nNodes * nIC]; - m_dul = new double [nNodes * nDC]; - m_dll = new double [nNodes * nDC]; - m_dul_buff = new double [nNodes * nDC]; - m_dll_buff = new double [nNodes * nDC]; + m_dul = new double[nNodes * nDC]; + m_dll = new double[nNodes * nDC]; + m_dul_buff = new double[nNodes * nDC]; + m_dll_buff = new double[nNodes * nDC]; - m_xDC = new double [nNodes * nDC]; - m_xDC_buff = new double [nNodes * nDC]; + m_xDC = new double[nNodes * nDC]; + m_xDC_buff = new double[nNodes * nDC]; - m_aPH = new double [nNodes * nPH]; // surface area for surface species ..input to GEMS! - m_aPH_buff = new double [nNodes * nPH]; - m_xPH = new double [nNodes * nPH]; // amount of carrier...used for smart initial aproximation - m_xPH_buff = new double [nNodes * nPH]; - m_xPA = new double [nNodes * nPS]; - m_xPA_buff = new double [nNodes * nPS]; + m_aPH = new double[nNodes * nPH]; // surface area for surface species ..input to GEMS! + m_aPH_buff = new double[nNodes * nPH]; + m_xPH = new double[nNodes * nPH]; // amount of carrier...used for smart initial aproximation + m_xPH_buff = new double[nNodes * nPH]; + m_xPA = new double[nNodes * nPS]; + m_xPA_buff = new double[nNodes * nPS]; - m_bSP = new double [nNodes * nIC]; //Bulk composition of all solids, moles [nIC] ...not yet buffered via MPI, because we do not use the data yet + m_bSP = new double[nNodes * nIC]; // Bulk composition of all solids, moles [nIC] ...not yet buffered via MPI, + // because we do not use the data yet // ---------------------------------- // this is for kinetics - Kinetic_GEMS m_kin; // new kinetic vector - - omega_phase = new double [nNodes * nPH]; - omega_phase_buff = new double [nNodes * nPH]; - mol_phase = new double [nNodes * nPH]; - mol_phase_buff = new double [nNodes * nPH]; - dmdt = new double [nNodes * nPH]; - dmdt_buff = new double [nNodes * nPH]; - omega_components = new double [nNodes * nDC]; - omega_components_buff = new double [nNodes * nDC]; - - m_xDC_pts = new double [nNodes * nDC]; - m_soluteB_pts = new double [nNodes * nIC]; - m_bIC_pts = new double [nNodes * nIC]; - m_xDC_MT_delta = new double [nNodes * nDC]; - m_xDC_Chem_delta = new double [nNodes * nDC]; - - m_xDC_pts_buff = new double [nNodes * nDC]; - m_xDC_MT_delta_buff = new double [nNodes * nDC]; - m_xDC_Chem_delta_buff = new double [nNodes * nDC]; + Kinetic_GEMS m_kin; // new kinetic vector + + omega_phase = new double[nNodes * nPH]; + omega_phase_buff = new double[nNodes * nPH]; + mol_phase = new double[nNodes * nPH]; + mol_phase_buff = new double[nNodes * nPH]; + dmdt = new double[nNodes * nPH]; + dmdt_buff = new double[nNodes * nPH]; + omega_components = new double[nNodes * nDC]; + omega_components_buff = new double[nNodes * nDC]; + + m_xDC_pts = new double[nNodes * nDC]; + m_soluteB_pts = new double[nNodes * nIC]; + m_bIC_pts = new double[nNodes * nIC]; + m_xDC_MT_delta = new double[nNodes * nDC]; + m_xDC_Chem_delta = new double[nNodes * nDC]; + + m_xDC_pts_buff = new double[nNodes * nDC]; + m_xDC_MT_delta_buff = new double[nNodes * nDC]; + m_xDC_Chem_delta_buff = new double[nNodes * nDC]; // kg44 03 april 2010 ...from here on, most data is only necessary once (check if this is needed for all nodes!) - m_rMB = new double [nNodes * nIC]; // buffer removed...we do not need the mass balance residuals globally - m_uIC = new double [nNodes * nIC]; // chemical potentials...in current code not needed, but maybe later? + m_rMB = new double[nNodes * nIC]; // buffer removed...we do not need the mass balance residuals globally + m_uIC = new double[nNodes * nIC]; // chemical potentials...in current code not needed, but maybe later? - m_gam = new double [nNodes * nDC]; + m_gam = new double[nNodes * nDC]; - m_vPS = new double [nNodes * nPS]; - m_mPS = new double [nNodes * nPS]; - m_bPS = new double [nNodes * nIC * nPS]; - m_bPS_buff = new double [nNodes * nIC * nPS]; + m_vPS = new double[nNodes * nPS]; + m_mPS = new double[nNodes * nPS]; + m_bPS = new double[nNodes * nIC * nPS]; + m_bPS_buff = new double[nNodes * nIC * nPS]; - m_ICNL = new char [nIC][MaxICN]; // List of IC names in the system, [nIC] of MaxICN length - m_DCNL = new char [nDC][MaxDCN]; // List of DC names in the system, [nDC] of MaxDCN length - m_PHNL = new char [nDC][MaxPHN]; // List of Phase names [nPH] of MaxPHN length + m_ICNL = new char[nIC][MaxICN]; // List of IC names in the system, [nIC] of MaxICN length + m_DCNL = new char[nDC][MaxDCN]; // List of DC names in the system, [nDC] of MaxDCN length + m_PHNL = new char[nDC][MaxPHN]; // List of Phase names [nPH] of MaxPHN length // now fill the arrays for vtk output @@ -470,19 +474,19 @@ short REACT_GEM::Init_Nodes ( string Project_path) m_PHNL = dCH->PHNL; // ------------------------ - for ( in = 0; in < nNodes; in++ ) + for (in = 0; in < nNodes; in++) { - m_boundary[in] = 0; // cout << "boundary init ok"<<"\n"; + m_boundary[in] = 0; // cout << "boundary init ok"<<"\n"; m_NodeHandle[in] = 0; m_NodeStatusCH[in] = 0; m_IterDone[in] = 0; m_IterDoneCumulative[in] = 0; - m_IterDoneIndex[in] = in; //initial values order of Nodes + m_IterDoneIndex[in] = in; // initial values order of Nodes m_NodeHandle_buff[in] = 0; m_NodeStatusCH_buff[in] = 0; m_IterDone_buff[in] = 0; - m_T[in] = 298.15; //equivalent to 25°C + m_T[in] = 298.15; // equivalent to 25°C m_P[in] = 1.0e+5; m_Vs[in] = 0.0; m_Ms[in] = 0.0; @@ -514,133 +518,129 @@ short REACT_GEM::Init_Nodes ( string Project_path) m_excess_water[in] = 0.0; m_excess_gas[in] = 0.0; - m_Node_Volume[in] = REACT_GEM::GetNodeAdjacentVolume ( in); + m_Node_Volume[in] = REACT_GEM::GetNodeAdjacentVolume(in); m_excess_water_buff[in] = 0.0; m_excess_gas_buff[in] = 0.0; - for ( ii = 0; ii < nIC; ii++ ) + for (ii = 0; ii < nIC; ii++) { - m_bIC[in * nIC + ii ] = 0.0; - m_bIC_dummy [ in * nIC + ii ] = 0.0; - - m_soluteB[in * nIC + ii ] = 0.0; - m_soluteB_buff[ in * nIC + ii ] = 0.0; - m_soluteB_pts[in * nIC + ii ] = 0.0; - m_bIC_pts[in * nIC + ii ] = 0.0; - m_rMB[in * nIC + ii ] = 0.0; - m_uIC[in * nIC + ii ] = 0.0; - - m_bIC_buff[in * nIC + ii ] = 0.0; - m_bIC_dummy_buff [ in * nIC + ii ] = 0.0; + m_bIC[in * nIC + ii] = 0.0; + m_bIC_dummy[in * nIC + ii] = 0.0; + + m_soluteB[in * nIC + ii] = 0.0; + m_soluteB_buff[in * nIC + ii] = 0.0; + m_soluteB_pts[in * nIC + ii] = 0.0; + m_bIC_pts[in * nIC + ii] = 0.0; + m_rMB[in * nIC + ii] = 0.0; + m_uIC[in * nIC + ii] = 0.0; + + m_bIC_buff[in * nIC + ii] = 0.0; + m_bIC_dummy_buff[in * nIC + ii] = 0.0; } - for ( ii = 0; ii < nDC; ii++ ) + for (ii = 0; ii < nDC; ii++) { - m_xDC[in * nDC + ii ] = 0.0; - m_gam[in * nDC + ii ] = 0.0; - m_dul[in * nDC + ii ] = 1.0e+10; // this should be a large number, because after scaling to 1kg in Gems it should be 1.e+6 - m_dll[in * nDC + ii ] = 0.0; // zero is ok - m_xDC_pts[in * nDC + ii ] = 0.0; - m_xDC_MT_delta[in * nDC + ii ] = 0.0; - m_xDC_Chem_delta[in * nDC + ii ] = 0.0; - - m_xDC_buff[in * nDC + ii ] = 0.0; - m_dul_buff[in * nDC + ii ] = 0.0; - m_dll_buff[in * nDC + ii ] = 0.0; - m_xDC_pts_buff[in * nDC + ii ] = 0.0; - m_xDC_MT_delta_buff[in * nDC + ii ] = 0.0; - m_xDC_Chem_delta_buff[in * nDC + ii ] = 0.0; - omega_components[in * nDC + ii ] = 0.0; - omega_components_buff[in * nDC + ii ] = 0.0; + m_xDC[in * nDC + ii] = 0.0; + m_gam[in * nDC + ii] = 0.0; + m_dul[in * nDC + ii] + = 1.0e+10; // this should be a large number, because after scaling to 1kg in Gems it should be 1.e+6 + m_dll[in * nDC + ii] = 0.0; // zero is ok + m_xDC_pts[in * nDC + ii] = 0.0; + m_xDC_MT_delta[in * nDC + ii] = 0.0; + m_xDC_Chem_delta[in * nDC + ii] = 0.0; + + m_xDC_buff[in * nDC + ii] = 0.0; + m_dul_buff[in * nDC + ii] = 0.0; + m_dll_buff[in * nDC + ii] = 0.0; + m_xDC_pts_buff[in * nDC + ii] = 0.0; + m_xDC_MT_delta_buff[in * nDC + ii] = 0.0; + m_xDC_Chem_delta_buff[in * nDC + ii] = 0.0; + omega_components[in * nDC + ii] = 0.0; + omega_components_buff[in * nDC + ii] = 0.0; } - for ( ii = 0; ii < nPH; ii++ ) + for (ii = 0; ii < nPH; ii++) { - m_aPH[in * nPH + ii ] = 0.0; - m_xPH[in * nPH + ii ] = 0.0; + m_aPH[in * nPH + ii] = 0.0; + m_xPH[in * nPH + ii] = 0.0; - m_xPH_buff[in * nPH + ii ] = 0.0; - m_aPH_buff[in * nPH + ii ] = 0.0; + m_xPH_buff[in * nPH + ii] = 0.0; + m_aPH_buff[in * nPH + ii] = 0.0; - omega_phase[in * nPH + ii ] = 0.0; - omega_phase_buff[in * nPH + ii ] = 0.0; - mol_phase[in * nPH + ii ] = 0.0; - mol_phase_buff[in * nPH + ii ] = 0.0; + omega_phase[in * nPH + ii] = 0.0; + omega_phase_buff[in * nPH + ii] = 0.0; + mol_phase[in * nPH + ii] = 0.0; + mol_phase_buff[in * nPH + ii] = 0.0; - dmdt[in * nPH + ii ] = 0.0; - dmdt_buff[in * nPH + ii ] = 0.0; - m_volumes_initial[in * nPH + ii ] = 0.0; + dmdt[in * nPH + ii] = 0.0; + dmdt_buff[in * nPH + ii] = 0.0; + m_volumes_initial[in * nPH + ii] = 0.0; } - for ( ii = 0; ii < nPS; ii++ ) + for (ii = 0; ii < nPS; ii++) { - m_vPS[in * nPS + ii ] = 0.0; - m_mPS[in * nPS + ii ] = 0.0; - m_xPA[in * nPS + ii ] = 0.0; - m_xPA_buff[in * nPS + ii ] = 0.0; + m_vPS[in * nPS + ii] = 0.0; + m_mPS[in * nPS + ii] = 0.0; + m_xPA[in * nPS + ii] = 0.0; + m_xPA_buff[in * nPS + ii] = 0.0; } - for ( ii = 0; ii < nIC; ii++ ) - for ( int jj = 0; jj < nPS; jj++ ) + for (ii = 0; ii < nIC; ii++) + for (int jj = 0; jj < nPS; jj++) { - m_bPS[in * ii * nPS + jj ] = 0.0; - m_bPS_buff[in * ii * nPS + jj ] = 0.0; + m_bPS[in * ii * nPS + jj] = 0.0; + m_bPS_buff[in * ii * nPS + jj] = 0.0; } } - for ( in = 0; in < nElems; in++ ) + for (in = 0; in < nElems; in++) { m_porosity_Elem[in] = 0.0; m_porosity_Elem_buff[in] = 0.0; } nNodes = GetNodeNumber_MT(); nElems = GetElemNumber_MT(); - if ( nPH < 2 && flowflag == 3 ) + if (nPH < 2 && flowflag == 3) { #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - if ( myrank == 0 /*should be set to root*/ ) + if (myrank == 0 /*should be set to root*/) #endif - cout << - "Richards flow used and only the water pahse is defined in GEMS...please add a gas phase.\n"; - exit ( 1 ); + cout << "Richards flow used and only the water pahse is defined in GEMS...please add a gas phase.\n"; + exit(1); } string tinit_path = Project_path; -// if ( myrank == 0 /*should be set to root*/ ) + // if ( myrank == 0 /*should be set to root*/ ) { -// here the boost barriers are defined.... + // here the boost barriers are defined.... gem_barrier_finish = (new boost::barrier((gem_nThread + 1))); gem_barrier_start = (new boost::barrier((gem_nThread + 1))); - gemThread = (new boost::thread[gem_nThread]); //each mpi task creates gem_nThread workers + gemThread = (new boost::thread[gem_nThread]); // each mpi task creates gem_nThread workers for (i = 0; i < gem_nThread; ++i) // here we create the threads! { #if defined(USE_MPI_GEMS) || defined(USE_PETSC) rwmutex.lock(); - cout << "Creating GEMS-worker thread " << i << " for MPI task " << - myrank << "\n"; + cout << "Creating GEMS-worker thread " << i << " for MPI task " << myrank << "\n"; rwmutex.unlock(); #else rwmutex.lock(); cout << "Creating GEMS-worker thread " << i << "\n"; rwmutex.unlock(); #endif - gemThread[i] = - boost::thread(boost::bind(&REACT_GEM::gems_worker, this, - (int) i, - Project_path)); + gemThread[i] = boost::thread(boost::bind(&REACT_GEM::gems_worker, this, (int)i, Project_path)); } } - return 0; //successed + return 0; // successed } - return 1; //something went wrong + return 1; // something went wrong } short REACT_GEM::Init_RUN(string Project_path) { nNodes = GetNodeNumber_MT(); nElems = GetElemNumber_MT(); - long ii = 0,in = 0,i = 0,j; + long ii = 0, in = 0, i = 0, j; // CompProperties *m_cp = NULL; CRFProcess* this_pcs; double BCValue = 0.0; @@ -650,22 +650,22 @@ short REACT_GEM::Init_RUN(string Project_path) TNode* m_Node; // DATABR structure for exchange with GEMIPM - DATACH* dCH; //pointer to DATACH - DATABR* dBR; //pointer to DATABR + DATACH* dCH; // pointer to DATACH + DATABR* dBR; // pointer to DATABR // Creating TNode structure accessible trough node pointer m_Node = new TNode(); // Here we read the files needed as input for initializing GEMIPM2K // The easiest way to prepare them is to use GEMS-PSI code (GEM2MT module) - if ( Load_Init_File ( Project_path, m_Node ) ) + if (Load_Init_File(Project_path, m_Node)) { // The init file is successfully loaded // Getting direct access to DataCH structure in GEMIPM2K memory dCH = m_Node->pCSD(); - if ( !dCH ) + if (!dCH) { #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - MPI_Finalize(); //make sure MPI exits + MPI_Finalize(); // make sure MPI exits #endif exit(1); } @@ -673,77 +673,81 @@ short REACT_GEM::Init_RUN(string Project_path) // Getting direct access to work node DATABR structure which // exchanges data between GEMIPM and FMT parts dBR = m_Node->pCNode(); - if ( !dBR ) + if (!dBR) { #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - MPI_Finalize(); //make sure MPI exits + MPI_Finalize(); // make sure MPI exits #endif exit(1); } // run GEMS once dBR->NodeStatusCH = NEED_GEM_AIA; - m_Node->GEM_run ( false ); + m_Node->GEM_run(false); } else { #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - MPI_Finalize(); //make sure MPI exits + MPI_Finalize(); // make sure MPI exits #endif exit(1); return 5; } - for ( i = 0; i < nNodes; i++ ) //after running GEMS once we initialize the OGS-GEMS data arrays + for (i = 0; i < nNodes; i++) // after running GEMS once we initialize the OGS-GEMS data arrays // initialize the arrays - REACT_GEM::GetReactInfoFromGEM ( i, m_Node); // get the data even if GEMS failed...this is necessary for initializing the arrays for example m_aPH - // unfortunately aPH is passed to GEMS and needs correct input for working with sorption + REACT_GEM::GetReactInfoFromGEM(i, m_Node); // get the data even if GEMS failed...this is necessary for + // initializing the arrays for example m_aPH + // unfortunately aPH is passed to GEMS and needs correct input for working with sorption - for ( ii = 0; ii < ( int ) m_kin.size(); ii++ ) // this loop is for identifying kinetically controlled phases + for (ii = 0; ii < (int)m_kin.size(); ii++) // this loop is for identifying kinetically controlled phases { m_kin[ii].phase_number = -1; - m_kin[ii].dc_counter = 0; //this is the starting dc + m_kin[ii].dc_counter = 0; // this is the starting dc // phase numbers are not yet set...do it! - for ( j = 0; j < nPH; j++ ) + for (j = 0; j < nPH; j++) { - cstr.assign ( dCH->PHNL[j] ); - // cout << m_kin[ii].phase_name << " gems phase: " << cstr << " "<< " component start number " << m_kin[ii].dc_counter << "\n"; - if ( m_kin[ii].phase_name == cstr ) + cstr.assign(dCH->PHNL[j]); + // cout << m_kin[ii].phase_name << " gems phase: " << cstr << " "<< " component start number " << + // m_kin[ii].dc_counter << "\n"; + if (m_kin[ii].phase_name == cstr) { m_kin[ii].phase_number = j; break; } - //add the number of components to the counter..after test for phasename...as this counter gives the starting position of the dependent components + // add the number of components to the counter..after test for phasename...as this counter gives the + // starting position of the dependent components m_kin[ii].dc_counter += dCH->nDCinPH[j]; } - if ( m_kin[ii].phase_number < 0 || m_kin[ii].phase_number >= nPH ) + if (m_kin[ii].phase_number < 0 || m_kin[ii].phase_number >= nPH) { - cout << " GEMS: Error in Phase kinetics..check input for " << - m_kin[ii].phase_name << "\n"; + cout << " GEMS: Error in Phase kinetics..check input for " << m_kin[ii].phase_name << "\n"; #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - MPI_Finalize(); //make sure MPI exits + MPI_Finalize(); // make sure MPI exits #endif - exit ( 1 ); + exit(1); } else - cout << "GEM Kinetics phase number: " << m_kin[ii].phase_name << - " in phase number " << m_kin[ii].phase_number << "\n"; + cout << "GEM Kinetics phase number: " << m_kin[ii].phase_name << " in phase number " + << m_kin[ii].phase_number << "\n"; } // Marking species with fixed concentrations (in boundary nodes) // first we check the boundary nodes with fixed concentrations - // this is adopted from rf_REACT_BRNS...we only look for the first species, as with GEMS we should define boundary conditions for ALL species + // this is adopted from rf_REACT_BRNS...we only look for the first species, as with GEMS we should define boundary + // conditions for ALL species this_pcs = NULL; // Get the pointer to the proper PCS. - this_pcs = PCSGet ( "MASS_TRANSPORT" ); - for ( i = 0; i < nNodes; i++ ) + this_pcs = PCSGet("MASS_TRANSPORT"); + for (i = 0; i < nNodes; i++) { - if ( this_pcs ) + if (this_pcs) { // BC printing - if ( IsThisPointBCIfYesStoreValue ( i, this_pcs, BCValue ) ) + if (IsThisPointBCIfYesStoreValue(i, this_pcs, BCValue)) // If this node is on the fixed boudnary for this component -// cout << "Node " << i <<", Comp " << this_pcs->pcs_primary_function_name[0] << " ,Value " << BCValue << " is boundary node" <<"\n"; + // cout << "Node " << i <<", Comp " << this_pcs->pcs_primary_function_name[0] << " ,Value + // " << BCValue << " is boundary node" <<"\n"; m_boundary[i] = 1; else // If this node is NOT on the fixed boudnary for this component @@ -751,51 +755,55 @@ short REACT_GEM::Init_RUN(string Project_path) } else // not getting the pointer to the proper PCS. { - cout << this_pcs->pcs_primary_function_name[0] << - "!!! In InitGEMS, can not find corresponding PCS for checking boundary conditions! " + cout << this_pcs->pcs_primary_function_name[0] + << "!!! In InitGEMS, can not find corresponding PCS for checking boundary conditions! " << "\n"; #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - MPI_Finalize(); //make sure MPI exits + MPI_Finalize(); // make sure MPI exits #endif - exit ( 1 ); + exit(1); } - } //end loop over all nodes -// here we have to make sure that the flow process has all initial data to do the saturation! -// synchronize pressures should be enough! + } // end loop over all nodes + // here we have to make sure that the flow process has all initial data to do the saturation! + // synchronize pressures should be enough! - flowflag = GetFlowType_MT(); // Get flow flag + flowflag = GetFlowType_MT(); // Get flow flag // we have to make sure saturation is properly defined..otherwise we can not calculate concentrations properly // kg44 16.05.2013 something wrong here? saturation seems not properly defined for Richards flow and restart - if ( flowflag == 3 ) //this is only for Richards flow + if (flowflag == 3) // this is only for Richards flow { -// TODO for petsc probably need to synchronize the pressure field here (as shadow nodes are not initializee via surfaces/volumes/plylines etc) + // TODO for petsc probably need to synchronize the pressure field here (as shadow nodes are not initializee via + // surfaces/volumes/plylines etc) cout << "GEM-INIT: "; - if ( m_flow_pcs->saturation_switch == true ) + if (m_flow_pcs->saturation_switch == true) { - cout << "CalcSaturationRichards " << "\n"; - //is true here correct? - m_flow_pcs->CalcSaturationRichards ( 1, true ); - } // JOD + cout << "CalcSaturationRichards " + << "\n"; + // is true here correct? + m_flow_pcs->CalcSaturationRichards(1, true); + } // JOD else { - //WW - m_flow_pcs->CalcSecondaryVariablesUnsaturatedFlow ( true ); - cout << " CalcSecondaryVariablesUnsaturatedFlow" << "\n"; + // WW + m_flow_pcs->CalcSecondaryVariablesUnsaturatedFlow(true); + cout << " CalcSecondaryVariablesUnsaturatedFlow" + << "\n"; } - //TODO for petsc we may need to synchronize saturations ...have to check! + // TODO for petsc we may need to synchronize saturations ...have to check! } - if ( ( m_flow_pcs->GetRestartFlag() >= 2 ) ) //get the restart data specific for gems + if ((m_flow_pcs->GetRestartFlag() >= 2)) // get the restart data specific for gems { - if ( !ReadReloadGem() ) + if (!ReadReloadGem()) { #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - MPI_Finalize(); //make sure MPI exits + MPI_Finalize(); // make sure MPI exits #endif - exit(1); // we save m_bic and m_soluteb as is, therefore these are concentrations -> call concentration_to:mass + exit(1); // we save m_bic and m_soluteb as is, therefore these are concentrations -> call + // concentration_to:mass } /* for ( i=0 ; i < nNodes ; i++ ) Better not here..... { @@ -803,27 +811,28 @@ short REACT_GEM::Init_RUN(string Project_path) } */ } -// else test: we do this always! ...should be safe ;-) + // else test: we do this always! ...should be safe ;-) { - GetInitialReactInfoFromMassTransport ( 1 ); //get the initial values from MD ...IC are total B vectors - last time step! this is not necessary for restart - cout << - "Attentione GEMS users: Initial kinetics calculated without restart! This probably kills kinetics, as phases in m_xDC are not yet properly initialized!" + GetInitialReactInfoFromMassTransport(1); // get the initial values from MD ...IC are total B vectors - last time + // step! this is not necessary for restart + cout << "Attentione GEMS users: Initial kinetics calculated without restart! This probably kills kinetics, as " + "phases in m_xDC are not yet properly initialized!" << "\n"; - cout << - "No upper or lower constrains set during equilibration!...If your setup requires constrains, please contact georg.kosakowski@psi.ch" + cout << "No upper or lower constrains set during equilibration!...If your setup requires constrains, please " + "contact georg.kosakowski@psi.ch" << "\n"; } - delete m_Node; //get rid of this GEMS instance + delete m_Node; // get rid of this GEMS instance rwmutex.unlock(); // now it is save to release the lock // from here the gems threads are responsible for GEMS - // distribute the data +// distribute the data #ifdef USE_MPI_GEMS // MPI initialization. - MPI_Bcast ( &nNodes, 1, MPI_LONG, 0, MPI_COMM_WORLD ); + MPI_Bcast(&nNodes, 1, MPI_LONG, 0, MPI_COMM_WORLD); #endif -// if ( myrank == 0 /*should be set to root*/ ) + // if ( myrank == 0 /*should be set to root*/ ) { // cout << "main waits for start barrier " << "\n"; @@ -838,159 +847,161 @@ short REACT_GEM::Init_RUN(string Project_path) REACT_GEM::CleanMPIBuffer(); #endif - for ( in = 0; in < nNodes; in++ ) // set the correct boundary conditions + for (in = 0; in < nNodes; in++) // set the correct boundary conditions { - REACT_GEM::SetBValue_MT ( in, 0, &( m_soluteB[in * nIC] ) ); // old timestep - REACT_GEM::SetBValue_MT ( in, 1, &( m_soluteB[in * nIC] ) ); // new timestep + REACT_GEM::SetBValue_MT(in, 0, &(m_soluteB[in * nIC])); // old timestep + REACT_GEM::SetBValue_MT(in, 1, &(m_soluteB[in * nIC])); // new timestep } // always calculate porosity at the beginning - ConvPorosityNodeValue2Elem ( 1 ); // new timestep: update element porosity and push back values - ConvPorosityNodeValue2Elem ( 0 ); // old timestep: fill with current values! + ConvPorosityNodeValue2Elem(1); // new timestep: update element porosity and push back values + ConvPorosityNodeValue2Elem(0); // old timestep: fill with current values! CopyCurBPre(); rwmutex.lock(); - cout << "Initial Running GEM to get the correct porosities successful. " << "\n"; + cout << "Initial Running GEM to get the correct porosities successful. " + << "\n"; rwmutex.unlock(); return 0; } -string REACT_GEM::Get_Init_File_Path ( void ) +string REACT_GEM::Get_Init_File_Path(void) { return init_input_file_path; } -string REACT_GEM::Get_IPM_File_Path ( void ) +string REACT_GEM::Get_IPM_File_Path(void) { return ipm_input_file_path; } -string REACT_GEM::Get_DBR_File_Path ( void ) +string REACT_GEM::Get_DBR_File_Path(void) { return dbr_input_file_path; } -string REACT_GEM::Get_DCH_File_Path ( void ) +string REACT_GEM::Get_DCH_File_Path(void) { return dch_input_file_path; } -int REACT_GEM::Set_IPM_FILE_PATH ( string m_path ) +int REACT_GEM::Set_IPM_FILE_PATH(string m_path) { REACT_GEM::ipm_input_file_path = m_path; return 0; } -int REACT_GEM::Set_DBR_FILE_PATH ( string m_path ) +int REACT_GEM::Set_DBR_FILE_PATH(string m_path) { REACT_GEM::dbr_input_file_path = m_path; return 0; } -int REACT_GEM::Set_DCH_FILE_PATH ( string m_path ) +int REACT_GEM::Set_DCH_FILE_PATH(string m_path) { REACT_GEM::dch_input_file_path = m_path; return 0; } -int REACT_GEM::Set_Init_File_Path ( string m_path ) +int REACT_GEM::Set_Init_File_Path(string m_path) { REACT_GEM::init_input_file_path = m_path; return 0; } -bool REACT_GEM::Load_Init_File ( string m_Project_path, TNode* m_Node ) +bool REACT_GEM::Load_Init_File(string m_Project_path, TNode* m_Node) { string init_path; char* buffer = NULL; - init_path = m_Project_path.append ( REACT_GEM::init_input_file_path ); + init_path = m_Project_path.append(REACT_GEM::init_input_file_path); #ifdef _WIN32 // keep this on windows - if ( init_path.rfind ( "\\" ) == string::npos ) + if (init_path.rfind("\\") == string::npos) #else // keep this on linux - if ( init_path.rfind ( "/" ) == string::npos ) + if (init_path.rfind("/") == string::npos) #endif { #ifdef _WIN32 - if ( ( buffer = _getcwd ( NULL, 0 ) ) == NULL ) + if ((buffer = _getcwd(NULL, 0)) == NULL) #else - if ( ( buffer = getcwd ( NULL, 0 ) ) == NULL ) + if ((buffer = getcwd(NULL, 0)) == NULL) #endif - perror ( "_getcwd error" ); + perror("_getcwd error"); else { #ifdef _WIN32 - init_path.insert ( 0, "\\" ); // keep this on window + init_path.insert(0, "\\"); // keep this on window #else - init_path.insert ( 0, "/" ); // keep this on linux + init_path.insert(0, "/"); // keep this on linux #endif - init_path.insert ( 0, buffer ); + init_path.insert(0, buffer); } } - if ( buffer ) - free ( buffer ); + if (buffer) + free(buffer); - if ( m_Node->GEM_init ( init_path.c_str() ) ) - return 0; // error occured during reading the files + if (m_Node->GEM_init(init_path.c_str())) + return 0; // error occured during reading the files else - return 1; // read init file successed + return 1; // read init file successed } -short REACT_GEM::GetInitialReactInfoFromMassTransport ( int timelevel ) +short REACT_GEM::GetInitialReactInfoFromMassTransport(int timelevel) { heatflag = GetHeatFlag_MT(); flowflag = GetFlowType_MT(); REACT_GEM::nNodes = GetNodeNumber_MT(); - for ( long node_i = 0; node_i < nNodes; node_i++ ) + for (long node_i = 0; node_i < nNodes; node_i++) { - //get temperature from MT - m_T[node_i] = REACT_GEM::GetTempValue_MT ( node_i, timelevel ); - - //get pressure from MT - m_P[node_i] = REACT_GEM::GetPressureValue_MT ( node_i, timelevel ); - //get Independent and dependent Component value from MT - if ( ( flag_transport_b == 1 ) && ( m_flow_pcs->GetRestartFlag() < 2 ) ) - REACT_GEM::GetBValue_MT ( node_i, timelevel, m_bIC + node_i * nIC ); //do this not for restart...overwrites values!!! + // get temperature from MT + m_T[node_i] = REACT_GEM::GetTempValue_MT(node_i, timelevel); + + // get pressure from MT + m_P[node_i] = REACT_GEM::GetPressureValue_MT(node_i, timelevel); + // get Independent and dependent Component value from MT + if ((flag_transport_b == 1) && (m_flow_pcs->GetRestartFlag() < 2)) + REACT_GEM::GetBValue_MT(node_i, timelevel, + m_bIC + node_i * nIC); // do this not for restart...overwrites values!!! } #if defined(USE_PETSC) -// arrays are filled, now we should synchronize the values - SynchronizeData(m_P); //this also overwrites default values for shadow nodes! - SynchronizeData(m_T); //this also overwrites default values for shadow nodes! + // arrays are filled, now we should synchronize the values + SynchronizeData(m_P); // this also overwrites default values for shadow nodes! + SynchronizeData(m_T); // this also overwrites default values for shadow nodes! // for b vector we need to copy data into working vector first...with use the b_buffer for this_pcs // in is node...i is vector component! for (long i = 0; i < nIC; i++) { for (long in = 0; in < loc_NodesNumber_Linear; in++) - m_bIC_buff[in] = m_bIC[in * nIC + i]; // copy only local nodes + m_bIC_buff[in] = m_bIC[in * nIC + i]; // copy only local nodes SynchronizeData(m_bIC_buff); for (long in = 0; in < nNodes; in++) - m_bIC[in * nIC + i] = m_bIC_buff[in]; // copy also shadow nodes + m_bIC[in * nIC + i] = m_bIC_buff[in]; // copy also shadow nodes } #endif return 0; } -short REACT_GEM::GetReactInfoFromMassTransport ( int timelevel ) +short REACT_GEM::GetReactInfoFromMassTransport(int timelevel) { heatflag = GetHeatFlag_MT(); flowflag = GetFlowType_MT(); REACT_GEM::nNodes = GetNodeNumber_MT(); - for ( long node_i = 0; node_i < nNodes; node_i++ ) + for (long node_i = 0; node_i < nNodes; node_i++) { - //get temperature from MT - m_T[node_i] = REACT_GEM::GetTempValue_MT ( node_i, timelevel ); - - //get pressure from MT - m_P[node_i] = REACT_GEM::GetPressureValue_MT ( node_i, timelevel ); - //get Independent and dependent Component value from MT - if ( flag_transport_b == 1 ) - REACT_GEM::GetBValue_MT ( node_i, timelevel, m_soluteB + node_i * nIC ); + // get temperature from MT + m_T[node_i] = REACT_GEM::GetTempValue_MT(node_i, timelevel); + + // get pressure from MT + m_P[node_i] = REACT_GEM::GetPressureValue_MT(node_i, timelevel); + // get Independent and dependent Component value from MT + if (flag_transport_b == 1) + REACT_GEM::GetBValue_MT(node_i, timelevel, m_soluteB + node_i * nIC); // Convert to mole values // if(conv_concentration == 1) REACT_GEM::ConcentrationToMass( node_i ); @@ -1001,13 +1012,13 @@ short REACT_GEM::GetReactInfoFromMassTransport ( int timelevel ) return 0; } -short REACT_GEM::SetReactInfoBackMassTransport ( int timelevel ) +short REACT_GEM::SetReactInfoBackMassTransport(int timelevel) { heatflag = GetHeatFlag_MT(); flowflag = GetFlowType_MT(); REACT_GEM::nNodes = GetNodeNumber_MT(); - for ( long in = 0; in < nNodes; in++ ) + for (long in = 0; in < nNodes; in++) { // Setting Temperature // disabled by HS. temperature is NOT the output from chemistry. // REACT_GEM::SetTempValue_MT(in,timelevel,m_T[in]); @@ -1017,89 +1028,88 @@ short REACT_GEM::SetReactInfoBackMassTransport ( int timelevel ) // if (m_pcs->m_msh->nod_vector[in]->onBoundary() == false) { // Setting Independent Component - if ( m_NodeStatusCH[in] == OK_GEM_AIA || m_NodeStatusCH[in] == OK_GEM_SIA || - m_NodeStatusCH[in] == BAD_GEM_AIA || m_NodeStatusCH[in] == BAD_GEM_SIA ) - if ( flag_transport_b == 1 ) - REACT_GEM::SetBValue_MT ( in, timelevel, &( m_soluteB[in * nIC] ) ); - + if (m_NodeStatusCH[in] == OK_GEM_AIA || m_NodeStatusCH[in] == OK_GEM_SIA || m_NodeStatusCH[in] == BAD_GEM_AIA + || m_NodeStatusCH[in] == BAD_GEM_SIA) + if (flag_transport_b == 1) + REACT_GEM::SetBValue_MT(in, timelevel, &(m_soluteB[in * nIC])); // Set the extra water as source/sink term; not for boundary nodes - if ( flag_coupling_hydrology > 0 && !m_boundary[in] ) - REACT_GEM::SetSourceSink_MT ( in, dt /*in sec*/ ); + if (flag_coupling_hydrology > 0 && !m_boundary[in]) + REACT_GEM::SetSourceSink_MT(in, dt /*in sec*/); } #if defined(USE_MPI_GEMS) - if ( flag_coupling_hydrology > 0 ) - m_flow_pcs->SetSTWaterGemSubDomain ( myrank ); // necessary for domain decomposition + if (flag_coupling_hydrology > 0) + m_flow_pcs->SetSTWaterGemSubDomain(myrank); // necessary for domain decomposition #endif - if ( flag_porosity_change > 0 ) - ConvPorosityNodeValue2Elem ( 0 ); // old timestep :copy current values to old timestep before updating porosity - if ( flag_porosity_change > 0 ) - ConvPorosityNodeValue2Elem ( timelevel ); // new timestep :update element porosity and push back values + if (flag_porosity_change > 0) + ConvPorosityNodeValue2Elem(0); // old timestep :copy current values to old timestep before updating porosity + if (flag_porosity_change > 0) + ConvPorosityNodeValue2Elem(timelevel); // new timestep :update element porosity and push back values return 0; } -void REACT_GEM::GetReactInfoFromGEM ( long in, TNode* m_Node ) +void REACT_GEM::GetReactInfoFromGEM(long in, TNode* m_Node) { - m_Node->GEM_to_MT ( m_NodeHandle[in], - m_NodeStatusCH[in], - m_IterDone[in], - m_Vs[in], - m_Ms[in], - m_Gs[in], - m_Hs[in], - m_IC[in], - m_pH[in], - m_pe[in], - m_Eh[in], - m_rMB + in * nIC, - m_uIC + in * nIC, - m_xDC + in * nDC, - m_gam + in * nDC, - m_xPH + in * nPH, - m_vPS + in * nPS, - m_mPS + in * nPS, - m_bPS + in * nPS * nIC, - m_xPA + in * nPS, - m_aPH + in * nPH, - m_bSP + in * nIC); + m_Node->GEM_to_MT(m_NodeHandle[in], + m_NodeStatusCH[in], + m_IterDone[in], + m_Vs[in], + m_Ms[in], + m_Gs[in], + m_Hs[in], + m_IC[in], + m_pH[in], + m_pe[in], + m_Eh[in], + m_rMB + in * nIC, + m_uIC + in * nIC, + m_xDC + in * nDC, + m_gam + in * nDC, + m_xPH + in * nPH, + m_vPS + in * nPS, + m_mPS + in * nPS, + m_bPS + in * nPS * nIC, + m_xPA + in * nPS, + m_aPH + in * nPH, + m_bSP + in * nIC); // old kernel version m_bPS+in*nPS*nIC, m_xPA+in*nPS, m_aPH+in*nPH ); } -void REACT_GEM::SetReactInfoBackGEM ( long in, TNode* m_Node ) +void REACT_GEM::SetReactInfoBackGEM(long in, TNode* m_Node) { // Setting input data for GEMIPM // for (i=0;iGEM_from_MT ( m_NodeHandle[in], - m_NodeStatusCH[in], - m_T[in], - m_P[in], - m_Vs[in], - m_Ms[in], - m_bIC + in * nIC, - m_dul + in * nDC, - m_dll + in * nDC, - m_aPH + in * nPH ); + if (flag_transport_b == 1) // here we insert the actual B vector + + m_Node->GEM_from_MT(m_NodeHandle[in], + m_NodeStatusCH[in], + m_T[in], + m_P[in], + m_Vs[in], + m_Ms[in], + m_bIC + in * nIC, + m_dul + in * nDC, + m_dll + in * nDC, + m_aPH + in * nPH); // cout << m_xDC+in*nDC << "\n"; // set charge to zero m_Node->pCNode()->bIC[nIC - 1] = 0.0; } -short REACT_GEM::Run_MainLoop ( ) +short REACT_GEM::Run_MainLoop() { if (flag_disable_gems) - return 0; // do nothing if GEMS calculations are disabled - max_kinetic_timestep = 1.0e+99; // restrict time step for kinetics + return 0; // do nothing if GEMS calculations are disabled + max_kinetic_timestep = 1.0e+99; // restrict time step for kinetics #ifdef USE_MPI_GEMS // MPI initialization. // So here is going to distribute the task. - MPI_Bcast ( &nNodes, 1, MPI_LONG, 0, MPI_COMM_WORLD ); + MPI_Bcast(&nNodes, 1, MPI_LONG, 0, MPI_COMM_WORLD); #endif // if ( myrank == 0 /*should be set to root*/ ) { @@ -1120,55 +1130,55 @@ short REACT_GEM::Run_MainLoop ( ) REACT_GEM::CleanMPIBuffer(); #endif rwmutex.lock(); // avoid mutual exclusion in the MPI version -// cout << "DEBUG failed: max kinetic time step " << max_kinetic_timestep << "\n"; -// cout << " GEM run successful. " << "\n"; + // cout << "DEBUG failed: max kinetic time step " << max_kinetic_timestep << "\n"; + // cout << " GEM run successful. " << "\n"; rwmutex.unlock(); return 0; } -int REACT_GEM::GetHeatFlag_MT ( void ) +int REACT_GEM::GetHeatFlag_MT(void) { CRFProcess* m_pcs = NULL; - //heat transport - for ( size_t i = 0; i < pcs_vector.size(); i++ ) + // heat transport + for (size_t i = 0; i < pcs_vector.size(); i++) { m_pcs = pcs_vector[i]; // if ( m_pcs->pcs_type_name.compare ( "HEAT_TRANSPORT" ) == 0 ) { // TF - if ( m_pcs->getProcessType() == FiniteElement::HEAT_TRANSPORT ) + if (m_pcs->getProcessType() == FiniteElement::HEAT_TRANSPORT) return 1; } return 0; } -int REACT_GEM::GetFlowType_MT ( void ) +int REACT_GEM::GetFlowType_MT(void) { CRFProcess* m_pcs = NULL; - //flow type - for ( size_t i = 0; i < pcs_vector.size(); i++ ) + // flow type + for (size_t i = 0; i < pcs_vector.size(); i++) { m_pcs = pcs_vector[i]; // if ( m_pcs->pcs_type_name.compare ( "GROUNDWATER_FLOW" ) ==0 ) { - if ( m_pcs->getProcessType() == FiniteElement::GROUNDWATER_FLOW ) + if (m_pcs->getProcessType() == FiniteElement::GROUNDWATER_FLOW) { m_flow_pcs = m_pcs; return 1; // } else if ( m_pcs->pcs_type_name.compare ( "LIQUID_FLOW" ) ==0 ) { } - else if ( m_pcs->getProcessType() == FiniteElement::LIQUID_FLOW ) + else if (m_pcs->getProcessType() == FiniteElement::LIQUID_FLOW) { m_flow_pcs = m_pcs; return 2; // } else if ( m_pcs->pcs_type_name.compare ( "RICHARDS_FLOW" ) ==0 ) { } - else if ( m_pcs->getProcessType() == FiniteElement::RICHARDS_FLOW ) + else if (m_pcs->getProcessType() == FiniteElement::RICHARDS_FLOW) { m_flow_pcs = m_pcs; return 3; // } else if ( m_pcs->pcs_type_name.compare ( "MULTI_PHASE_FLOW" ) ==0 ) { } - else if ( m_pcs->getProcessType() == FiniteElement::MULTI_PHASE_FLOW ) + else if (m_pcs->getProcessType() == FiniteElement::MULTI_PHASE_FLOW) { } m_flow_pcs = m_pcs; @@ -1177,18 +1187,18 @@ int REACT_GEM::GetFlowType_MT ( void ) return 0; } -long REACT_GEM::GetNodeNumber_MT ( void ) +long REACT_GEM::GetNodeNumber_MT(void) { long number; CRFProcess* m_pcs = NULL; //------------read number of nodes-------------- - for ( size_t i = 0; i < pcs_vector.size(); i++ ) + for (size_t i = 0; i < pcs_vector.size(); i++) { m_pcs = pcs_vector[i]; // if ( m_pcs->pcs_type_name.compare ( "MASS_TRANSPORT" ) ==0 ) { - if ( m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT ) + if (m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) { - number = ( long ) m_pcs->m_msh->GetNodesNumber ( false ); + number = (long)m_pcs->m_msh->GetNodesNumber(false); return number; } } @@ -1197,36 +1207,36 @@ long REACT_GEM::GetNodeNumber_MT ( void ) } #if defined(USE_PETSC) -long REACT_GEM::GetGlobalNodeNumber_MT ( void ) +long REACT_GEM::GetGlobalNodeNumber_MT(void) { long number; CRFProcess* m_pcs = NULL; //------------read number of nodes-------------- - for ( size_t i = 0; i < pcs_vector.size(); i++ ) + for (size_t i = 0; i < pcs_vector.size(); i++) { m_pcs = pcs_vector[i]; // if ( m_pcs->pcs_type_name.compare ( "MASS_TRANSPORT" ) ==0 ) { - if ( m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT ) + if (m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) { - number = ( long ) m_pcs->m_msh->getNumNodesGlobal(); + number = (long)m_pcs->m_msh->getNumNodesGlobal(); return number; } } //------------end of reading number of nodes---- return 0; } -long REACT_GEM::GetLocalNodeNumber_MT ( void ) +long REACT_GEM::GetLocalNodeNumber_MT(void) { long number; CRFProcess* m_pcs = NULL; //------------read number of nodes-------------- - for ( size_t i = 0; i < pcs_vector.size(); i++ ) + for (size_t i = 0; i < pcs_vector.size(); i++) { m_pcs = pcs_vector[i]; // if ( m_pcs->pcs_type_name.compare ( "MASS_TRANSPORT" ) ==0 ) { - if ( m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT ) + if (m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) { - number = ( long ) m_pcs->m_msh->getNumNodesLocal(); + number = (long)m_pcs->m_msh->getNumNodesLocal(); return number; } } @@ -1235,276 +1245,275 @@ long REACT_GEM::GetLocalNodeNumber_MT ( void ) } #endif -long REACT_GEM::GetElemNumber_MT ( void ) +long REACT_GEM::GetElemNumber_MT(void) { long number; CRFProcess* m_pcs = NULL; //------------read number of elems-------------- - for ( size_t i = 0; i < pcs_vector.size(); i++ ) + for (size_t i = 0; i < pcs_vector.size(); i++) { m_pcs = pcs_vector[i]; // if ( m_pcs->pcs_type_name.compare ( "MASS_TRANSPORT" ) ==0 ) { - if ( m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT ) + if (m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) { - number = ( long ) m_pcs->m_msh->ele_vector.size(); + number = (long)m_pcs->m_msh->ele_vector.size(); return number; } } return 0; } -double REACT_GEM::GetTempValue_MT ( long node_Index, int timelevel ) +double REACT_GEM::GetTempValue_MT(long node_Index, int timelevel) { int indx; double temp; CRFProcess* m_pcs = NULL; - if ( heatflag == 1 ) + if (heatflag == 1) { - m_pcs = PCSGet ( "HEAT_TRANSPORT" ); + m_pcs = PCSGet("HEAT_TRANSPORT"); - indx = m_pcs->GetNodeValueIndex ( "TEMPERATURE1" ) + timelevel; - temp = m_pcs->GetNodeValue ( node_Index, indx ); + indx = m_pcs->GetNodeValueIndex("TEMPERATURE1") + timelevel; + temp = m_pcs->GetNodeValue(node_Index, indx); } else temp = m_gem_temperature; return temp; } -short REACT_GEM::SetTempValue_MT ( long node_Index, int timelevel, double temp ) +short REACT_GEM::SetTempValue_MT(long node_Index, int timelevel, double temp) { int indx; CRFProcess* m_pcs = NULL; - if ( heatflag == 1 ) + if (heatflag == 1) { - m_pcs = PCSGet ( "HEAT_TRANSPORT" ); + m_pcs = PCSGet("HEAT_TRANSPORT"); - indx = m_pcs->GetNodeValueIndex ( "TEMPERATURE1" ) + timelevel; - m_pcs->SetNodeValue ( node_Index, indx, temp ); + indx = m_pcs->GetNodeValueIndex("TEMPERATURE1") + timelevel; + m_pcs->SetNodeValue(node_Index, indx, temp); - //sysT[i] = m_pcs->GetNodeValue(i, indx1); - //if (sysT0[i] <273.15) sysT0[i] += 273.15; //ToDo �C->K - //if (sysT[i] <273.15) sysT[i] += 273.15; //ToDo �C->K + // sysT[i] = m_pcs->GetNodeValue(i, indx1); + // if (sysT0[i] <273.15) sysT0[i] += 273.15; //ToDo �C->K + // if (sysT[i] <273.15) sysT[i] += 273.15; //ToDo �C->K return 1; } else return 0; } -double REACT_GEM::GetPressureValue_MT ( long node_Index, int timelevel ) +double REACT_GEM::GetPressureValue_MT(long node_Index, int timelevel) { - //Get pressure value + // Get pressure value double pressure; int indx; pressure = 0.0; CFluidProperties* m_FluidProp; - m_FluidProp = MFPGet ( "LIQUID" ); + m_FluidProp = MFPGet("LIQUID"); - if ( flowflag > 0 ) + if (flowflag > 0) { - switch ( flowflag ) + switch (flowflag) { - case 1: // for "GROUNDWATER_FLOW"; + case 1: // for "GROUNDWATER_FLOW"; - if ( gem_pressure_flag < 1 ) - { - // just set to 1.0 bar. - pressure = m_gem_pressure; + if (gem_pressure_flag < 1) + { + // just set to 1.0 bar. + pressure = m_gem_pressure; + break; + } + else + { + indx = m_flow_pcs->GetNodeValueIndex("HEAD"); + // The unit of HEAD is in meters + pressure = m_flow_pcs->GetNodeValue(node_Index, indx + timelevel); + // cout << pressure << " " << " timelevel "<Density()); + // y cout << pressure << " density" << m_FluidProp->Density()<<"\n"; + // add atmospheric pressure + } + + if (pressure <= 0.0 /*valcumm suction in groundwater is not so realistic*/ + || pressure > 1.0e+15 /*some very high pressure*/ + ) + { + // then set it to 1.0 bar = 1.0e5 Pa; + cout << " high pressure " << pressure << "\n"; + pressure = 1.0e+05; + } break; - } - else - { - indx = m_flow_pcs->GetNodeValueIndex ( "HEAD" ); + + case 2: // for "LIQUID_FLOW", not tested!!! + + indx = m_flow_pcs->GetNodeValueIndex("PRESSURE1") + timelevel; // The unit of HEAD is in meters - pressure = - m_flow_pcs->GetNodeValue ( node_Index, indx + timelevel ); - // cout << pressure << " " << " timelevel "<Density() ); - //y cout << pressure << " density" << m_FluidProp->Density()<<"\n"; - // add atmospheric pressure - } + pressure = m_flow_pcs->GetNodeValue(node_Index, indx); - if ( pressure <= 0.0 /*valcumm suction in groundwater is not so realistic*/ - || pressure > 1.0e+15 /*some very high pressure*/ - ) - { - // then set it to 1.0 bar = 1.0e5 Pa; - cout << " high pressure " << pressure << "\n"; - pressure = 1.0e+05; - } - break; + // change the pressure unit from meters of water to bar. + // pressure = Pressure_M_2_Bar ( pressure , m_FluidProp->Density() ); + // add atmospheric pressure + if (pressure < 0.0 /*valcumm suction in groundwater is not so realistic*/ + || pressure > 1.0e+15 /*some very high pressure*/ + ) + pressure = 1.0e+5; // then set it to 1.0 bar; + break; + case 3: // for "RICHARDS_FLOW", not tested!!! + pressure = m_gem_pressure; + // indx = m_flow_pcs->GetNodeValueIndex ( "PRESSURE1" ) +timelevel; + // pressure = m_flow_pcs->GetNodeValue ( node_Index, indx ); // The unit of HEAD is in meters - case 2: // for "LIQUID_FLOW", not tested!!! + // change the pressure unit from meters of water to bar. + // pressure = Pressure_M_2_Bar ( pressure , m_FluidProp->Density() ); + // add atmospheric pressure + // pressure +=1.0; + if (pressure < 0.0 /*valcumm suction in groundwater is not so realistic*/ + || pressure > 1.0e+15 /*some very high pressure*/ + ) + pressure = 1.0e+5; // then set it to 1.0 bar; + break; + case 4: // MULTIPHASE ....not tested + indx = m_flow_pcs->GetNodeValueIndex("PRESSURE1"); + // The unit of HEAD is in meters + pressure = m_flow_pcs->GetNodeValue(node_Index, indx + timelevel); - indx = m_flow_pcs->GetNodeValueIndex ( "PRESSURE1" ) + timelevel; - // The unit of HEAD is in meters - pressure = m_flow_pcs->GetNodeValue ( node_Index, indx ); + // change the pressure unit from meters of water to bar. + // pressure = Pressure_M_2_Bar ( pressure , m_FluidProp->Density() ); + // add atmospheric pressure - // change the pressure unit from meters of water to bar. - // pressure = Pressure_M_2_Bar ( pressure , m_FluidProp->Density() ); - // add atmospheric pressure - if ( pressure < 0.0 /*valcumm suction in groundwater is not so realistic*/ - || pressure > 1.0e+15 /*some very high pressure*/ - ) - pressure = 1.0e+5; // then set it to 1.0 bar; - break; - case 3: // for "RICHARDS_FLOW", not tested!!! - pressure = m_gem_pressure; - // indx = m_flow_pcs->GetNodeValueIndex ( "PRESSURE1" ) +timelevel; - // pressure = m_flow_pcs->GetNodeValue ( node_Index, indx ); // The unit of HEAD is in meters - - // change the pressure unit from meters of water to bar. - // pressure = Pressure_M_2_Bar ( pressure , m_FluidProp->Density() ); - // add atmospheric pressure - // pressure +=1.0; - if ( pressure < 0.0 /*valcumm suction in groundwater is not so realistic*/ - || pressure > 1.0e+15 /*some very high pressure*/ - ) - pressure = 1.0e+5; // then set it to 1.0 bar; - break; - case 4: // MULTIPHASE ....not tested - indx = m_flow_pcs->GetNodeValueIndex ( "PRESSURE1" ); - // The unit of HEAD is in meters - pressure = m_flow_pcs->GetNodeValue ( node_Index, indx + timelevel ); - - // change the pressure unit from meters of water to bar. - // pressure = Pressure_M_2_Bar ( pressure , m_FluidProp->Density() ); - // add atmospheric pressure - - if ( pressure < 0.0 /*valcumm suction in groundwater is not so realistic*/ - || pressure > 1.0e+15 /*some very high pressure*/ - ) - pressure = 1.0e+5; // then set it to 1.0 bar; - break; - default: + if (pressure < 0.0 /*valcumm suction in groundwater is not so realistic*/ + || pressure > 1.0e+15 /*some very high pressure*/ + ) + pressure = 1.0e+5; // then set it to 1.0 bar; + break; + default: #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - if ( myrank == 0 /*should be set to root*/ ) + if (myrank == 0 /*should be set to root*/) #endif - cout << "Error: Not implemented for the flow in GEM case!!!" << "\n"; - pressure = 1.0e+05; - break; - } // end of switch case; - } // end of if (flow_flag); + cout << "Error: Not implemented for the flow in GEM case!!!" + << "\n"; + pressure = 1.0e+05; + break; + } // end of switch case; + } // end of if (flow_flag); else // if no valid flow pcs existing; - cout << "Warning: No valid flow process!!" << "\n"; + cout << "Warning: No valid flow process!!" + << "\n"; return pressure; } -short REACT_GEM::SetPressureValue_MT ( long node_Index, int timelevel, double pressure ) +short REACT_GEM::SetPressureValue_MT(long node_Index, int timelevel, double pressure) { CRFProcess* m_pcs = NULL; CFluidProperties* m_FluidProp; - m_FluidProp = MFPGet ( "LIQUID" ); + m_FluidProp = MFPGet("LIQUID"); - //Set pressure value + // Set pressure value int indx; indx = 0; - if ( flowflag > 0 ) + if (flowflag > 0) { - switch ( flowflag ) + switch (flowflag) { - case 1: - m_pcs = PCSGet ( "GROUNDWATER_FLOW" ); - pressure = Pressure_Pa_2_M ( pressure, m_FluidProp->Density() ); - indx = m_pcs->GetNodeValueIndex ( "HEAD" ) + timelevel; - m_pcs->SetNodeValue ( node_Index, indx, pressure ); - break; - case 2: - m_pcs = PCSGet ( "LIQUID_FLOW" ); - indx = m_pcs->GetNodeValueIndex ( "PRESSURE1" ) + timelevel; + case 1: + m_pcs = PCSGet("GROUNDWATER_FLOW"); + pressure = Pressure_Pa_2_M(pressure, m_FluidProp->Density()); + indx = m_pcs->GetNodeValueIndex("HEAD") + timelevel; + m_pcs->SetNodeValue(node_Index, indx, pressure); + break; + case 2: + m_pcs = PCSGet("LIQUID_FLOW"); + indx = m_pcs->GetNodeValueIndex("PRESSURE1") + timelevel; - m_pcs->SetNodeValue ( node_Index, indx, pressure ); - break; - case 3: - // do nothing for Richards flow - break; - // m_pcs = PCSGet ( "RICHARDS_FLOW" ); - // indx = m_pcs->GetNodeValueIndex ( "PRESSURE1" ) +timelevel; - // pressure = Pressure_Bar_2_Pa ( pressure ); - // m_pcs->SetNodeValue ( node_Index, indx, pressure ); - // break; - case 4: - m_pcs = PCSGet ( "MULTI_PHASE_FLOW" ); - indx = m_pcs->GetNodeValueIndex ( "PRESSURE1" ) + timelevel; - - m_pcs->SetNodeValue ( node_Index, indx, pressure ); - default: + m_pcs->SetNodeValue(node_Index, indx, pressure); + break; + case 3: + // do nothing for Richards flow + break; + // m_pcs = PCSGet ( "RICHARDS_FLOW" ); + // indx = m_pcs->GetNodeValueIndex ( "PRESSURE1" ) +timelevel; + // pressure = Pressure_Bar_2_Pa ( pressure ); + // m_pcs->SetNodeValue ( node_Index, indx, pressure ); + // break; + case 4: + m_pcs = PCSGet("MULTI_PHASE_FLOW"); + indx = m_pcs->GetNodeValueIndex("PRESSURE1") + timelevel; + + m_pcs->SetNodeValue(node_Index, indx, pressure); + default: #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - if ( myrank == 0 /*should be set to root*/ ) + if (myrank == 0 /*should be set to root*/) #endif - cout << "Error: Not implemented for the flow in GEM case!!!" << "\n"; - break; + cout << "Error: Not implemented for the flow in GEM case!!!" + << "\n"; + break; } } else { #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - if ( myrank == 0 /*should be set to root*/ ) + if (myrank == 0 /*should be set to root*/) #endif - cout << "Warning: No valid flow process!!" << "\n"; + cout << "Warning: No valid flow process!!" + << "\n"; return 0; } return 1; } -short REACT_GEM::GetDCValue_MT ( long node_Index, - int timelevel, - double* m_DC, - double* m_DC_pts, - double* m_DC_MT_delta ) +short REACT_GEM::GetDCValue_MT(long node_Index, int timelevel, double* m_DC, double* m_DC_pts, double* m_DC_MT_delta) { string str; double /*DC_MT_pre,*/ DC_MT_cur; CRFProcess* m_pcs = NULL; int i = -1; - for ( size_t j = 0; j < pcs_vector.size(); j++ ) + for (size_t j = 0; j < pcs_vector.size(); j++) { - m_pcs = pcs_vector[j]; // dangerous!! - if ( m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT ) + m_pcs = pcs_vector[j]; // dangerous!! + if (m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) { - //if ( m_pcs->m_msh->nod_vector[node_Index]->onBoundary() == false ) // do not update values for boundary node? + // if ( m_pcs->m_msh->nod_vector[node_Index]->onBoundary() == false ) // do not update values for boundary + // node? i += +1; str = m_pcs->pcs_primary_function_name[0]; // Get previous iteration mass transport concentration value // DC_MT_pre = m_pcs->GetNodeValue ( node_Index,m_pcs->GetNodeValueIndex ( str ) +0 ); // Get current iteration mass transport concentration value - DC_MT_cur = m_pcs->GetNodeValue ( node_Index,m_pcs->GetNodeValueIndex ( - str ) + timelevel ); - *( m_DC + i ) = DC_MT_cur; + DC_MT_cur = m_pcs->GetNodeValue(node_Index, m_pcs->GetNodeValueIndex(str) + timelevel); + *(m_DC + i) = DC_MT_cur; } } return 1; } -short REACT_GEM::GetBValue_MT ( long node_Index, int timelevel, double* m_soluteB ) +short REACT_GEM::GetBValue_MT(long node_Index, int timelevel, double* m_soluteB) { string str; double /*DC_MT_pre,*/ DC_B_cur; CRFProcess* m_pcs = NULL; long i = -1; // set it to minus 1 as we add 1 before we use it - for ( size_t j = 0; j < pcs_vector.size(); j++ ) + for (size_t j = 0; j < pcs_vector.size(); j++) { - m_pcs = pcs_vector[j]; // dangerous!! + m_pcs = pcs_vector[j]; // dangerous!! // if ( m_pcs->pcs_type_name.compare ( "MASS_TRANSPORT" ) == 0 ) { - if ( m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT ) + if (m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) { - //if ( m_pcs->m_msh->nod_vector[node_Index]->onBoundary() == false ) // do not update values for boundary node? + // if ( m_pcs->m_msh->nod_vector[node_Index]->onBoundary() == false ) // do not update values for boundary + // node? str = m_pcs->pcs_primary_function_name[0]; // here we could add some type of test in order to make sure we get the correct process! - i += 1; //add one to counter + i += 1; // add one to counter // Get previous iteration mass transport concentration value // DC_MT_pre = m_pcs->GetNodeValue ( node_Index,m_pcs->GetNodeValueIndex ( str ) +0 ); // Get current iteration mass transport concentration value - DC_B_cur = m_pcs->GetNodeValue ( node_Index,m_pcs->GetNodeValueIndex ( - str ) + timelevel ); + DC_B_cur = m_pcs->GetNodeValue(node_Index, m_pcs->GetNodeValueIndex(str) + timelevel); - *( m_soluteB + i ) = DC_B_cur; + *(m_soluteB + i) = DC_B_cur; } } @@ -1512,51 +1521,50 @@ short REACT_GEM::GetBValue_MT ( long node_Index, int timelevel, double* m_solute } // same functionality as GetComponentValue_MT -double REACT_GEM::GetDCValueSpecies_MT ( long node_Index, int timelevel, int iDc ) +double REACT_GEM::GetDCValueSpecies_MT(long node_Index, int timelevel, int iDc) { string str; double /*DC_MT_pre,*/ DC_MT_cur = 0.0; - size_t i = 0; //counter for processes + size_t i = 0; // counter for processes CRFProcess* m_pcs = NULL; // first find out the number for the first Mass_transport process - while ( i < pcs_vector.size() ) + while (i < pcs_vector.size()) { - m_pcs = pcs_vector[i]; // dangerous!! + m_pcs = pcs_vector[i]; // dangerous!! // if ( m_pcs->pcs_type_name.compare ( "MASS_TRANSPORT" ) == 0 ) { - if ( m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT ) + if (m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) { m_pcs = pcs_vector[iDc + i]; // dangerous!! ... this is now the process we are looking for // if ( m_pcs->pcs_type_name.compare ( "MASS_TRANSPORT" ) == 0 ) { - if ( m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT ) + if (m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) { str = m_pcs->pcs_primary_function_name[0]; - if ( str.compare ( "pH" ) != 0 && str.compare ( "pe" ) != 0 && - str.compare ( "Eh" ) != 0 && str.compare ( "NodePorosity" ) != - 0 ) + if (str.compare("pH") != 0 && str.compare("pe") != 0 && str.compare("Eh") != 0 + && str.compare("NodePorosity") != 0) { // Get previous iteration mass transport concentration value // DC_MT_pre = m_pcs->GetNodeValue ( node_Index,m_pcs->GetNodeValueIndex ( str ) +0 ); // Get current iteration mass transport concentration value getnode_mutex.lock(); - DC_MT_cur = m_pcs->GetNodeValue ( node_Index, - m_pcs->GetNodeValueIndex ( - str ) + - timelevel ); //KG44 I am not quite sure, but it looks as this is not thread safe...lets look it with a special mutex + DC_MT_cur = m_pcs->GetNodeValue(node_Index, + m_pcs->GetNodeValueIndex(str) + timelevel); // KG44 I am not quite + // sure, but it looks as + // this is not thread + // safe...lets look it + // with a special mutex getnode_mutex.unlock(); } else { - cout << - "Error in GetDCValueSpecies_MT ... return zero value" - << - "\n"; + cout << "Error in GetDCValueSpecies_MT ... return zero value" + << "\n"; DC_MT_cur = 0.0; } } else { - cout << "Error in GetDCValueSpecies_MT ... return zero value" << - "\n"; + cout << "Error in GetDCValueSpecies_MT ... return zero value" + << "\n"; DC_MT_cur = 0.0; } @@ -1565,51 +1573,47 @@ double REACT_GEM::GetDCValueSpecies_MT ( long node_Index, int timelevel, int iDc } i += 1; } -// something went wrong...we exit the program - cout << "error in GetDCValueSpecies_MT " << "\n"; + // something went wrong...we exit the program + cout << "error in GetDCValueSpecies_MT " + << "\n"; #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - MPI_Finalize(); //make sure MPI exits + MPI_Finalize(); // make sure MPI exits #endif - exit ( 1 ); + exit(1); } -short REACT_GEM::GetSoComponentValue_MT ( long node_Index, - int timelevel, - double* m_Phase, - TNode* m_Node ) +short REACT_GEM::GetSoComponentValue_MT(long node_Index, int timelevel, double* m_Phase, TNode* m_Node) { string str; int x_Component = 0; CRFProcess* m_pcs = NULL; - for ( size_t i = 0; i < pcs_vector.size(); i++ ) + for (size_t i = 0; i < pcs_vector.size(); i++) { m_pcs = pcs_vector[i]; // if ( m_pcs->pcs_type_name.compare ( "MASS_TRANSPORT" ) == 0 ) { - if ( m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT ) + if (m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) { x_Component = -1; - //get the name of compound from MT; + // get the name of compound from MT; str = m_pcs->pcs_primary_function_name[0]; - //get the index of certain compound, -1: no match - x_Component = m_Node->Ph_name_to_xDB ( str.c_str() ); - if ( x_Component > -1 ) - *( m_Phase + x_Component ) = m_pcs->GetNodeValue ( node_Index, - m_pcs->GetNodeValueIndex ( - str ) + - timelevel ); + // get the index of certain compound, -1: no match + x_Component = m_Node->Ph_name_to_xDB(str.c_str()); + if (x_Component > -1) + *(m_Phase + x_Component) = m_pcs->GetNodeValue(node_Index, m_pcs->GetNodeValueIndex(str) + timelevel); else { - //DisplayErrorMsg("Error: Corresponding Component NOT FOUND in GEM part!!"); - //return 0; + // DisplayErrorMsg("Error: Corresponding Component NOT FOUND in GEM part!!"); + // return 0; } } } - //DisplayErrorMsg("Error: MASS TRANSPORT NOT FOUND!!"); + // DisplayErrorMsg("Error: MASS TRANSPORT NOT FOUND!!"); return 1; } /* - short REACT_GEM::SetDCValue_MT ( long node_Index, int timelevel, double* m_DC ) // This routine does not work properly!!!!!!!!!!!!! + short REACT_GEM::SetDCValue_MT ( long node_Index, int timelevel, double* m_DC ) // This routine does not work + properly!!!!!!!!!!!!! { CRFProcess* m_pcs = NULL; string str; @@ -1622,7 +1626,8 @@ short REACT_GEM::GetSoComponentValue_MT ( long node_Index, if ( m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT ) { str = m_pcs->pcs_primary_function_name[0]; - if ( str.compare ( "pH" ) != 0 && str.compare ( "pe" ) != 0 && str.compare ( "Eh" ) != 0 && str.compare ( "NodePorosity" ) != 0 ) + if ( str.compare ( "pH" ) != 0 && str.compare ( "pe" ) != 0 && str.compare ( "Eh" ) != 0 && str.compare ( + "NodePorosity" ) != 0 ) { if ( flag_iterative_scheme > 0 ) { @@ -1653,44 +1658,34 @@ short REACT_GEM::GetSoComponentValue_MT ( long node_Index, return 1; } */ -short REACT_GEM::SetBValue_MT ( long node_Index, int timelevel, double* m_soluteB ) +short REACT_GEM::SetBValue_MT(long node_Index, int timelevel, double* m_soluteB) { CRFProcess* m_pcs = NULL; string str; long i = -1; - for ( size_t j = 0; j < pcs_vector.size(); j++ ) + for (size_t j = 0; j < pcs_vector.size(); j++) { m_pcs = pcs_vector[j]; // not good! // if ( m_pcs->pcs_type_name.compare ( "MASS_TRANSPORT" ) == 0 ) { - if ( m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT ) + if (m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) { str = m_pcs->pcs_primary_function_name[0]; i += 1; - if ( flag_iterative_scheme > 0 ) + if (flag_iterative_scheme > 0) { - if ( CPGetMobil ( m_pcs->GetProcessComponentNumber() ) > 0 ) + if (CPGetMobil(m_pcs->GetProcessComponentNumber()) > 0) // m_pcs->eqs->b[node_Index] += m_xDC_Chem_delta[node_Index*nDC+i] / dt ; - m_pcs->SetNodeValue ( node_Index, - m_pcs->GetNodeValueIndex ( - str ) + timelevel, - *( m_soluteB + i ) ); + m_pcs->SetNodeValue(node_Index, m_pcs->GetNodeValueIndex(str) + timelevel, *(m_soluteB + i)); else - m_pcs->SetNodeValue ( node_Index, - m_pcs->GetNodeValueIndex ( - str ) + timelevel, - *( m_soluteB + i ) ); - + m_pcs->SetNodeValue(node_Index, m_pcs->GetNodeValueIndex(str) + timelevel, *(m_soluteB + i)); } else - m_pcs->SetNodeValue ( node_Index, m_pcs->GetNodeValueIndex ( - str ) + timelevel, - *( m_soluteB + i ) ); - + m_pcs->SetNodeValue(node_Index, m_pcs->GetNodeValueIndex(str) + timelevel, *(m_soluteB + i)); } } @@ -1698,129 +1693,131 @@ short REACT_GEM::SetBValue_MT ( long node_Index, int timelevel, double* m_solute } // i_timestep 0: old timestep 1: new timestep -int REACT_GEM::SetPorosityValue_MT ( long ele_Index, double m_porosity_Elem, int i_timestep ) +int REACT_GEM::SetPorosityValue_MT(long ele_Index, double m_porosity_Elem, int i_timestep) { int idx; idx = -1; CRFProcess* m_pcs = NULL; - if ( flowflag > 0 ) + if (flowflag > 0) { - switch ( flowflag ) + switch (flowflag) { - case 1: - m_pcs = PCSGet ( "GROUNDWATER_FLOW" ); - idx = m_pcs->GetElementValueIndex ( "POROSITY" ); - // set new porosity; - m_pcs->SetElementValue ( ele_Index, idx + i_timestep, m_porosity_Elem ); - break; - case 2: - m_pcs = PCSGet ( "LIQUID_FLOW" ); - idx = m_pcs->GetElementValueIndex ( "POROSITY" ); - // always write into the new step - m_pcs->SetElementValue ( ele_Index,idx + i_timestep,m_porosity_Elem ); - break; - case 3: - m_pcs = PCSGet ( "RICHARDS_FLOW" ); - idx = m_pcs->GetElementValueIndex ( "POROSITY" ); - // always write into the new step - m_pcs->SetElementValue ( ele_Index,idx + i_timestep,m_porosity_Elem ); - break; - case 4: // kg44: do we have to update POROSITY_IL and POROSITY_SW? - m_pcs = PCSGet ( "MULTI_PHASE_FLOW" ); - idx = m_pcs->GetElementValueIndex ( "POROSITY1" ); - // always write into the new step - m_pcs->SetElementValue ( ele_Index,idx + i_timestep,m_porosity_Elem ); - break; - default: + case 1: + m_pcs = PCSGet("GROUNDWATER_FLOW"); + idx = m_pcs->GetElementValueIndex("POROSITY"); + // set new porosity; + m_pcs->SetElementValue(ele_Index, idx + i_timestep, m_porosity_Elem); + break; + case 2: + m_pcs = PCSGet("LIQUID_FLOW"); + idx = m_pcs->GetElementValueIndex("POROSITY"); + // always write into the new step + m_pcs->SetElementValue(ele_Index, idx + i_timestep, m_porosity_Elem); + break; + case 3: + m_pcs = PCSGet("RICHARDS_FLOW"); + idx = m_pcs->GetElementValueIndex("POROSITY"); + // always write into the new step + m_pcs->SetElementValue(ele_Index, idx + i_timestep, m_porosity_Elem); + break; + case 4: // kg44: do we have to update POROSITY_IL and POROSITY_SW? + m_pcs = PCSGet("MULTI_PHASE_FLOW"); + idx = m_pcs->GetElementValueIndex("POROSITY1"); + // always write into the new step + m_pcs->SetElementValue(ele_Index, idx + i_timestep, m_porosity_Elem); + break; + default: #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - if ( myrank == 0 /*should be set to root*/ ) + if (myrank == 0 /*should be set to root*/) #endif - cout << "Error: Not implemented for the flow in GEM case!!!" << "\n"; - break; + cout << "Error: Not implemented for the flow in GEM case!!!" + << "\n"; + break; } } return 1; } -int REACT_GEM::SetSourceSink_MT ( long in, double time_step_size /*in sec*/ ) +int REACT_GEM::SetSourceSink_MT(long in, double time_step_size /*in sec*/) { Water_ST_GEMS m_st; - switch ( flowflag ) + switch (flowflag) { - case 1: // groundwater flow - m_st.index_node = in; - m_st.water_st_value = m_excess_water[in] / time_step_size; - // normalize with node volume - m_st.water_st_value *= m_Node_Volume[in]; - m_flow_pcs->Water_ST_vec.push_back ( m_st ); - return 1; - break; - case 2: // liquid flow - m_st.index_node = in; - m_st.water_st_value = m_excess_water[in] / time_step_size; - // normalize with node volume - m_st.water_st_value *= m_Node_Volume[in]; - m_flow_pcs->Water_ST_vec.push_back ( m_st ); - return 1; - break; - case 3: // Richards flow - m_st.index_node = in; - m_st.water_st_value = m_excess_water[in] / time_step_size; - // normalize with node volume - m_st.water_st_value *= m_Node_Volume[in]; - m_flow_pcs->Water_ST_vec.push_back ( m_st ); - return 1; - break; - case 4: // multiphase flow...works with case 1 ...pressure saturation scheme - m_st.index_node = in; - m_st.water_st_value = m_excess_water[in] / time_step_size; - // normalize with node volume - m_st.water_st_value *= m_Node_Volume[in]; - m_flow_pcs->Water_ST_vec.push_back ( m_st ); - return 1; - break; - default: + case 1: // groundwater flow + m_st.index_node = in; + m_st.water_st_value = m_excess_water[in] / time_step_size; + // normalize with node volume + m_st.water_st_value *= m_Node_Volume[in]; + m_flow_pcs->Water_ST_vec.push_back(m_st); + return 1; + break; + case 2: // liquid flow + m_st.index_node = in; + m_st.water_st_value = m_excess_water[in] / time_step_size; + // normalize with node volume + m_st.water_st_value *= m_Node_Volume[in]; + m_flow_pcs->Water_ST_vec.push_back(m_st); + return 1; + break; + case 3: // Richards flow + m_st.index_node = in; + m_st.water_st_value = m_excess_water[in] / time_step_size; + // normalize with node volume + m_st.water_st_value *= m_Node_Volume[in]; + m_flow_pcs->Water_ST_vec.push_back(m_st); + return 1; + break; + case 4: // multiphase flow...works with case 1 ...pressure saturation scheme + m_st.index_node = in; + m_st.water_st_value = m_excess_water[in] / time_step_size; + // normalize with node volume + m_st.water_st_value *= m_Node_Volume[in]; + m_flow_pcs->Water_ST_vec.push_back(m_st); + return 1; + break; + default: #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - if ( myrank == 0 /*should be set to root*/ ) + if (myrank == 0 /*should be set to root*/) #endif - cout << "Error: Not implemented for the flow in GEM case!!!" << "\n"; - break; + cout << "Error: Not implemented for the flow in GEM case!!!" + << "\n"; + break; } return 0; } -int REACT_GEM::FindWater_xDC ( TNode* m_Node ) +int REACT_GEM::FindWater_xDC(TNode* m_Node) { // initialization int rt = -1; int i; - DATACH* dCH; //pointer to DATACH + DATACH* dCH; // pointer to DATACH DATABR* dBR; // Getting direct access to DataCH structure in GEMIPM2K memory dCH = m_Node->pCSD(); - if ( !dCH ) + if (!dCH) { #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - MPI_Finalize(); //make sure MPI exits + MPI_Finalize(); // make sure MPI exits #endif - exit ( 1 ); + exit(1); } // Getting direct access to work node DATABR structure which // exchanges data between GEMIPM and FMT parts dBR = m_Node->pCNode(); - if ( !dBR ) + if (!dBR) { #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - MPI_Finalize(); //make sure MPI exits + MPI_Finalize(); // make sure MPI exits #endif - exit ( 1 ); + exit(1); } // loop over all the xDC names, and find the one that is water - for ( i = 0; i < nDC; i++ ) - if ( dCH->ccDC[i] == 'W' ) + for (i = 0; i < nDC; i++) + if (dCH->ccDC[i] == 'W') { rt = i; return rt; @@ -1828,35 +1825,35 @@ int REACT_GEM::FindWater_xDC ( TNode* m_Node ) return rt; } -int REACT_GEM::Findhydrogen_bIC ( TNode* m_Node) +int REACT_GEM::Findhydrogen_bIC(TNode* m_Node) { // initialization int rt = -1; int i; - DATACH* dCH; //pointer to DATACH + DATACH* dCH; // pointer to DATACH DATABR* dBR; // Getting direct access to DataCH structure in GEMIPM2K memory dCH = m_Node->pCSD(); - if ( !dCH ) + if (!dCH) { #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - MPI_Finalize(); //make sure MPI exits + MPI_Finalize(); // make sure MPI exits #endif - exit ( 1 ); + exit(1); } // Getting direct access to work node DATABR structure which // exchanges data between GEMIPM and FMT parts dBR = m_Node->pCNode(); - if ( !dBR ) + if (!dBR) { #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - MPI_Finalize(); //make sure MPI exits + MPI_Finalize(); // make sure MPI exits #endif - exit ( 1 ); + exit(1); } // loop over all the bIC names, and find the one that is hydrogen - for ( i = 0; i < nIC; i++ ) - if ( dCH->ccIC[i] == 'h' ) + for (i = 0; i < nIC; i++) + if (dCH->ccIC[i] == 'h') { rt = i; return rt; @@ -1864,35 +1861,35 @@ int REACT_GEM::Findhydrogen_bIC ( TNode* m_Node) return rt; } -int REACT_GEM::Findoxygen_bIC (TNode* m_Node) +int REACT_GEM::Findoxygen_bIC(TNode* m_Node) { // initialization int rt = -1; int i; - DATACH* dCH; //pointer to DATACH + DATACH* dCH; // pointer to DATACH DATABR* dBR; // Getting direct access to DataCH structure in GEMIPM2K memory dCH = m_Node->pCSD(); - if ( !dCH ) + if (!dCH) { #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - MPI_Finalize(); //make sure MPI exits + MPI_Finalize(); // make sure MPI exits #endif - exit ( 1 ); + exit(1); } // Getting direct access to work node DATABR structure which // exchanges data between GEMIPM and FMT parts dBR = m_Node->pCNode(); - if ( !dBR ) + if (!dBR) { #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - MPI_Finalize(); //make sure MPI exits + MPI_Finalize(); // make sure MPI exits #endif - exit ( 1 ); + exit(1); } // loop over all the bIC names, and find the one that is oxygen - for ( i = 0; i < nIC; i++ ) - if ( dCH->ccIC[i] == 'o' ) + for (i = 0; i < nIC; i++) + if (dCH->ccIC[i] == 'o') { rt = i; return rt; @@ -1900,37 +1897,37 @@ int REACT_GEM::Findoxygen_bIC (TNode* m_Node) return rt; } -double REACT_GEM::Pressure_Pa_2_Bar ( double Pre_in_Pa ) +double REACT_GEM::Pressure_Pa_2_Bar(double Pre_in_Pa) { return Pre_in_Pa / 1.0e+5; } -double REACT_GEM::Pressure_Bar_2_Pa ( double Pre_in_Bar ) +double REACT_GEM::Pressure_Bar_2_Pa(double Pre_in_Bar) { return Pre_in_Bar * 1.0e+5; } -double REACT_GEM::Pressure_M_2_Bar ( double Pre_in_M, double flu_density ) +double REACT_GEM::Pressure_M_2_Bar(double Pre_in_M, double flu_density) { return Pre_in_M * 9.81 * flu_density / 1.0e+5; } -double REACT_GEM::Pressure_Bar_2_M ( double Pre_in_Bar, double flu_density ) +double REACT_GEM::Pressure_Bar_2_M(double Pre_in_Bar, double flu_density) { return Pre_in_Bar * 1.0e5 / 9.81 / flu_density; } -double REACT_GEM::Pressure_M_2_Pa ( double Pre_in_M, double flu_density ) +double REACT_GEM::Pressure_M_2_Pa(double Pre_in_M, double flu_density) { return Pre_in_M * 9.81 * flu_density; } -double REACT_GEM::Pressure_Pa_2_M ( double Pre_in_Pa, double flu_density ) +double REACT_GEM::Pressure_Pa_2_M(double Pre_in_Pa, double flu_density) { return Pre_in_Pa / 9.81 / flu_density; } -double REACT_GEM::GetNodeAdjacentVolume ( long Idx_Node) +double REACT_GEM::GetNodeAdjacentVolume(long Idx_Node) { double volume; long Idx_Ele; @@ -1942,20 +1939,20 @@ double REACT_GEM::GetNodeAdjacentVolume ( long Idx_Node) MeshLib::CElem* m_Elem; // get the pointer to current node; - m_ogsNode = m_flow_pcs->m_msh->nod_vector[Idx_Node]; + m_ogsNode = m_flow_pcs->m_msh->nod_vector[Idx_Node]; // loop over all the elements that adjacent to this node; - for ( int i = 0; i < ( long ) m_ogsNode->getConnectedElementIDs().size(); i++ ) + for (int i = 0; i < (long)m_ogsNode->getConnectedElementIDs().size(); i++) { // get the index of current element; - Idx_Ele = m_ogsNode->getConnectedElementIDs() [i]; + Idx_Ele = m_ogsNode->getConnectedElementIDs()[i]; // get the pointer of this element; m_Elem = m_flow_pcs->m_msh->ele_vector[Idx_Ele]; // get the number of nodes in this element; // given argument "false" means giving node number instead of Gauss points; - number_of_nodes = m_Elem->GetNodesNumber ( false ); + number_of_nodes = m_Elem->GetNodesNumber(false); // taking part of volume from this element; volume += m_Elem->GetVolume() / number_of_nodes; @@ -1965,154 +1962,154 @@ double REACT_GEM::GetNodeAdjacentVolume ( long Idx_Node) } // i_timestep: 0: old timestep 1: new timestep -void REACT_GEM::ConvPorosityNodeValue2Elem ( int i_timestep ) +void REACT_GEM::ConvPorosityNodeValue2Elem(int i_timestep) { - long i,idx_Node, group; + long i, idx_Node, group; int j, number_of_nodes; - double pormin = 2.0,pormax = 0.0; + double pormin = 2.0, pormax = 0.0; double distance, weight, sum_weights; MeshLib::CElem* m_Elem; MeshLib::CNode* m_ogsNode; CMediumProperties* m_mmp = NULL; - for ( i = 0; i < nElems; i++ ) + for (i = 0; i < nElems; i++) { - distance = weight = sum_weights = 0.0; - m_Elem = m_flow_pcs->m_msh->ele_vector[i]; + distance = weight = sum_weights = 0.0; + m_Elem = m_flow_pcs->m_msh->ele_vector[i]; group = m_Elem->GetPatchIndex(); m_mmp = mmp_vector[group]; - if ( i_timestep == 0 ) // only do something if we have model 15...gems changes porosity + if (i_timestep == 0) // only do something if we have model 15...gems changes porosity { // push back porosities if (!(m_mmp->porosity_model == 15)) - m_porosity_Elem[i] = m_mmp->Porosity(i,1); // get element porosity - SetPorosityValue_MT ( i, m_porosity_Elem[i], i_timestep ); + m_porosity_Elem[i] = m_mmp->Porosity(i, 1); // get element porosity + SetPorosityValue_MT(i, m_porosity_Elem[i], i_timestep); } else if (m_mmp->porosity_model == 15) // only do something if porosity model 15 { // first set the parameters to zero; m_porosity_Elem[i] = 0.0; - number_of_nodes = ( int ) m_Elem->GetNodesNumber ( false ); + number_of_nodes = (int)m_Elem->GetNodesNumber(false); // then get the values from nodes - for ( j = 0; j < number_of_nodes; j++ ) + for (j = 0; j < number_of_nodes; j++) { // get the connected nodes; - idx_Node = m_Elem->GetNodeIndex ( j ); + idx_Node = m_Elem->GetNodeIndex(j); m_ogsNode = m_flow_pcs->m_msh->nod_vector[idx_Node]; - //calculate distance between the node and the barycentre + // calculate distance between the node and the barycentre double const* gravity_centre(m_Elem->GetGravityCenter()); - double const* const pnt (m_ogsNode->getData()); - distance = - (gravity_centre[0] - pnt[0]) * (gravity_centre[0] - pnt[0]); - distance += - (gravity_centre[1] - pnt[1]) * (gravity_centre[1] - pnt[1]); - distance += - (gravity_centre[2] - pnt[2]) * (gravity_centre[2] - pnt[2]); - distance = sqrt(distance); - - //Weight of each face depending on distance + double const* const pnt(m_ogsNode->getData()); + distance = (gravity_centre[0] - pnt[0]) * (gravity_centre[0] - pnt[0]); + distance += (gravity_centre[1] - pnt[1]) * (gravity_centre[1] - pnt[1]); + distance += (gravity_centre[2] - pnt[2]) * (gravity_centre[2] - pnt[2]); + distance = sqrt(distance); + + // Weight of each face depending on distance weight = (1.0 / distance); // Sum of weights sum_weights += weight; // this is arithmetric mean m_porosity_Elem[i] += m_porosity[idx_Node] / number_of_nodes; - // here we use harmonic mean, as porosity is used for permeability/diffusivity changes....flux in the element is strongly influenced by the minimum values + // here we use harmonic mean, as porosity is used for permeability/diffusivity changes....flux in the + // element is strongly influenced by the minimum values // cout << " porosity " << idx_Node <<" "<= max_possible_porosity ) + if (m_porosity_Elem[i] >= max_possible_porosity) m_porosity_Elem[i] = max_possible_porosity; - //lower limit of porosity.. - if ( m_porosity_Elem[i] <= min_possible_porosity ) + // lower limit of porosity.. + if (m_porosity_Elem[i] <= min_possible_porosity) m_porosity_Elem[i] = min_possible_porosity; - pormin = min ( pormin,m_porosity_Elem[i] ); - pormax = max ( pormax,m_porosity_Elem[i] ); + pormin = min(pormin, m_porosity_Elem[i]); + pormax = max(pormax, m_porosity_Elem[i]); // push back porosities - SetPorosityValue_MT ( i, m_porosity_Elem[i], i_timestep ); + SetPorosityValue_MT(i, m_porosity_Elem[i], i_timestep); } else - m_porosity_Elem[i] = m_mmp->Porosity(i,1); // get element porosity - // debug - // cout << " GEMS3K DEBUG elment material group porosity " << i << " " << m_mmp->porosity_model << " " << m_porosity_Elem[i] << "\n"; + m_porosity_Elem[i] = m_mmp->Porosity(i, 1); // get element porosity + // debug + // cout << " GEMS3K DEBUG elment material group porosity " << i << " " << m_mmp->porosity_model << " " << + // m_porosity_Elem[i] << "\n"; } - if ( i_timestep == 1 ) - cout << "min, max porosity: " << pormin << " " << pormax << "\n"; //only output for current time step....old time step will give wrong values + if (i_timestep == 1) + cout << "min, max porosity: " << pormin << " " << pormax + << "\n"; // only output for current time step....old time step will give wrong values } double REACT_GEM::FluidDensity(long elem, int gaussnode) { long idx_Node; - int number_of_nodes, j,i; + int number_of_nodes, j, i; MeshLib::CElem* m_Elem; MeshLib::CNode* m_ogsNode; double density; double distance, weight, sum_weights; - int size_m = 20; //assigned to the value in CFiniteElementStd(CRFProcess *Pcs, const int C_Sys_Flad, const int order=1); + int size_m + = 20; // assigned to the value in CFiniteElementStd(CRFProcess *Pcs, const int C_Sys_Flad, const int order=1); double* NodalVal_BG; - density = 1000.0; //default backup value + density = 1000.0; // default backup value - distance = weight = sum_weights = 0.0; + distance = weight = sum_weights = 0.0; // cout << "GEMS DEBUG: FluidDensity " << density << "elem " << elem << " gaussnode " << gaussnode<< "\n"; - m_Elem = m_flow_pcs->m_msh->ele_vector[elem]; - number_of_nodes = ( int ) m_Elem->GetNodesNumber ( false ); + m_Elem = m_flow_pcs->m_msh->ele_vector[elem]; + number_of_nodes = (int)m_Elem->GetNodesNumber(false); if (gaussnode > -1) // gauss point like in InterpolatPorpertytoGausPoints { if (!Fem_Ele_Std) { - cout << - "DEBUG REACTGEM: fluiddensity from gauss node failed: could not get Fem_Ele_Std" + cout << "DEBUG REACTGEM: fluiddensity from gauss node failed: could not get Fem_Ele_Std" << "\n"; - return density; //make sure call to interpolate does not fail + return density; // make sure call to interpolate does not fail } - NodalVal_BG = new double [size_m]; //BG + NodalVal_BG = new double[size_m]; // BG // Get gauss point data // GetGaussData(gp, gp_r, gp_s, gp_t); - //fkt = GetGaussData(GPIndex, gp_r, gp_s, gp_t); + // fkt = GetGaussData(GPIndex, gp_r, gp_s, gp_t); // Compute the shape function for interpolation within element - //ComputeShapefct(1); - //read density from nodes - for(i = 0; i < number_of_nodes; i++) + // ComputeShapefct(1); + // read density from nodes + for (i = 0; i < number_of_nodes; i++) { - idx_Node = m_Elem->GetNodeIndex ( i ); + idx_Node = m_Elem->GetNodeIndex(i); NodalVal_BG[i] = m_fluid_density[idx_Node]; } // Interpolate density from nodes to gauss point density = Fem_Ele_Std->interpolate(NodalVal_BG); } - else //arithmetric average on element + else // arithmetric average on element { // get the values from nodes - for ( j = 0; j < number_of_nodes; j++ ) + for (j = 0; j < number_of_nodes; j++) { // get the connected nodes; - idx_Node = m_Elem->GetNodeIndex ( j ); + idx_Node = m_Elem->GetNodeIndex(j); m_ogsNode = m_flow_pcs->m_msh->nod_vector[idx_Node]; - //calculate distance between the node and the barycentre + // calculate distance between the node and the barycentre double const* gravity_centre(m_Elem->GetGravityCenter()); - double const* const pnt (m_ogsNode->getData()); - distance = (gravity_centre[0] - pnt[0]) * (gravity_centre[0] - pnt[0]); + double const* const pnt(m_ogsNode->getData()); + distance = (gravity_centre[0] - pnt[0]) * (gravity_centre[0] - pnt[0]); distance += (gravity_centre[1] - pnt[1]) * (gravity_centre[1] - pnt[1]); distance += (gravity_centre[2] - pnt[2]) * (gravity_centre[2] - pnt[2]); - distance = sqrt(distance); + distance = sqrt(distance); - //Weight of each face depending on distance + // Weight of each face depending on distance weight = (1.0 / distance); // Sum of weights sum_weights += weight; - //Density + // Density // this is arithmetric mean density += m_fluid_density[idx_Node] * weight; } @@ -2123,81 +2120,86 @@ double REACT_GEM::FluidDensity(long elem, int gaussnode) return density; } -int REACT_GEM::CalcPorosity ( long in, TNode* m_Node ) +int REACT_GEM::CalcPorosity(long in, TNode* m_Node) { - int k; //must be int for Ph_Volume ! - DATACH* dCH; //pointer to DATACH + int k; // must be int for Ph_Volume ! + DATACH* dCH; // pointer to DATACH DATABR* dBR; // Getting direct access to DataCH structure in GEMIPM2K memory dCH = m_Node->pCSD(); - if ( !dCH ) + if (!dCH) { #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - MPI_Finalize(); //make sure MPI exits + MPI_Finalize(); // make sure MPI exits #endif - exit ( 1 ); + exit(1); } // Getting direct access to work node DATABR structure which // exchanges data between GEMIPM and FMT parts dBR = m_Node->pCNode(); - if ( !dBR ) + if (!dBR) { #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - MPI_Finalize(); //make sure MPI exits + MPI_Finalize(); // make sure MPI exits #endif - exit ( 1 ); + exit(1); } m_porosity[in] = 0.0; - for ( k = 0; k < dCH->nPHb; k++ ) - if ( ( dCH->ccPH[k] == 's' ) || ( dCH->ccPH[k] == 'x' ) || ( dCH->ccPH[k] == 'd' ) ) - m_porosity[in] += m_Node->Ph_Volume ( k ); + for (k = 0; k < dCH->nPHb; k++) + if ((dCH->ccPH[k] == 's') || (dCH->ccPH[k] == 'x') || (dCH->ccPH[k] == 'd')) + m_porosity[in] += m_Node->Ph_Volume(k); // normalized by m_Vs // m_porosity[in] = 1.0 - m_porosity[in] / ( m_Vs[in] * 1.0e-6 /*convert to cm3 here*/) ; - //kg44 this is the correct way to do it - m_porosity[in] = 1.0 - ( m_porosity[in] ); + // kg44 this is the correct way to do it + m_porosity[in] = 1.0 - (m_porosity[in]); // cout <<" porosity:" << m_porosity[in] << " node: "<< in <<"\n"; // checking whether out of bounary. only needed if calc porosity is done - if ( m_porosity[in] >= max_possible_porosity ) + if (m_porosity[in] >= max_possible_porosity) m_porosity[in] = max_possible_porosity; // upper limit of porosity - if ( m_porosity[in] <= min_possible_porosity ) - m_porosity[in] = min_possible_porosity; //lower limit of porosity.. cout << " skal factor " << skal_faktor << " excess water volume " << m_excess_water[in] ; + if (m_porosity[in] <= min_possible_porosity) + m_porosity[in] + = min_possible_porosity; // lower limit of porosity.. cout << " skal factor " << skal_faktor << " + // excess water volume " << m_excess_water[in] ; // cout <<" porosity:" << m_porosity[in] << " node: "<< in <<" Vs "<pCSD(); - if ( !dCH ) + if (!dCH) { #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - MPI_Finalize(); //make sure MPI exits + MPI_Finalize(); // make sure MPI exits #endif - exit ( 1 ); + exit(1); } // Getting direct access to work node DATABR structure which // exchanges data between GEMIPM and FMT parts dBR = m_Node->pCNode(); - if ( !dBR ) + if (!dBR) { #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - MPI_Finalize(); //make sure MPI exits + MPI_Finalize(); // make sure MPI exits #endif - exit ( 1 ); + exit(1); } // get the fluid volume - if ( i_failed ) + if (i_failed) { fluid_volume = m_fluid_volume[in]; gas_volume = m_gas_volume[in]; @@ -2206,41 +2208,40 @@ int REACT_GEM::MassToConcentration ( long in,int i_failed, TNode* m_Node ) // { fluid_volume = 0.0; gas_volume = 0.0; - for ( k = 0; k < dCH->nPHb; k++ ) + for (k = 0; k < dCH->nPHb; k++) { - if ( dCH->ccPH[k] == 'a' ) - fluid_volume += m_Node->Ph_Volume ( k ); - if ( dCH->ccPH[k] == 'g' ) - gas_volume += m_Node->Ph_Volume ( k ); + if (dCH->ccPH[k] == 'a') + fluid_volume += m_Node->Ph_Volume(k); + if (dCH->ccPH[k] == 'g') + gas_volume += m_Node->Ph_Volume(k); // * 1.0e-6; // transform cm3 -> m3 !! } - // cout << " node " << in << " fluid_volume " << fluid_volume << " gas volume " << gas_volume << " total-gas: " << m_Vs[in]-gas_volume << "\n"; + // cout << " node " << in << " fluid_volume " << fluid_volume << " gas volume " << gas_volume << " + // total-gas: " << m_Vs[in]-gas_volume << "\n"; } - if ( ( fluid_volume <= 0.0 ) ) + if ((fluid_volume <= 0.0)) { - cout << "OGSGEM MassToConcentration: fluid volume negative or zero " << - fluid_volume << " node " << in << " " << m_fluid_volume[in] << "\n"; - m_Node->GEM_write_dbr ( "dbr_for_crash_node_fluid_volume.txt" ); - cout << " skal factor " << skal_faktor << " excess water volume " << - m_excess_water[in]; - m_Node->GEM_print_ipm ( "ipm_for_crash_node_fluid_volume.txt" ); + cout << "OGSGEM MassToConcentration: fluid volume negative or zero " << fluid_volume << " node " << in << " " + << m_fluid_volume[in] << "\n"; + m_Node->GEM_write_dbr("dbr_for_crash_node_fluid_volume.txt"); + cout << " skal factor " << skal_faktor << " excess water volume " << m_excess_water[in]; + m_Node->GEM_print_ipm("ipm_for_crash_node_fluid_volume.txt"); #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - MPI_Finalize(); //make sure MPI exits + MPI_Finalize(); // make sure MPI exits #endif - exit ( 1 ); + exit(1); } - if ( ( gas_volume < 0.0 ) ) + if ((gas_volume < 0.0)) { - cout << "OGSGEM MassToConcentration: gas volume negative" << gas_volume << - " node " << in << "\n"; + cout << "OGSGEM MassToConcentration: gas volume negative" << gas_volume << " node " << in << "\n"; #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - MPI_Finalize(); //make sure MPI exits + MPI_Finalize(); // make sure MPI exits #endif - exit ( 1 ); + exit(1); } // store volumes for reuse during concentration_to_mass @@ -2250,95 +2251,97 @@ int REACT_GEM::MassToConcentration ( long in,int i_failed, TNode* m_Node ) // // calculate excess water: volume of fluid phase bigger/smaller than porosity; // requires updated porosity (calc porosity before calculation of execc water) CRFProcess* m_pcs = NULL; - switch ( flowflag ) + switch (flowflag) { - case 1: // groundwater flow cout << " skal factor " << skal_faktor << " excess water volume " << m_excess_water[in] ; - m_excess_water[in] = m_fluid_volume[in] - m_porosity[in]; - skal_faktor = ( m_porosity[in] ) / m_fluid_volume[in]; //scale water to available volume - m_fluid_volume[in] = m_porosity[in]; - break; - case 2: // liquid flow - m_excess_water[in] = m_fluid_volume[in] - m_porosity[in]; - skal_faktor = ( m_porosity[in] ) / m_fluid_volume[in]; //scale water to available volume - m_fluid_volume[in] = m_porosity[in]; - break; - case 3: // Richards flow: Saturation is directly calculated from the pressure, therefore add a source-sink term to induce pressure/saturation changes - m_pcs = PCSGet ( "RICHARDS_FLOW" ); - idx = m_pcs->GetNodeValueIndex ( "SATURATION1" ); - - if ( m_fluid_volume[in] > m_porosity[in] ) // fluid volume exceeds available pore space - { - m_excess_water[in] = m_fluid_volume[in] - m_porosity[in]; - skal_faktor = m_porosity[in] / m_fluid_volume[in]; //mol amount of water in first phase + case 1: // groundwater flow cout << " skal factor " << skal_faktor << " excess water volume " << + // m_excess_water[in] ; + m_excess_water[in] = m_fluid_volume[in] - m_porosity[in]; + skal_faktor = (m_porosity[in]) / m_fluid_volume[in]; // scale water to available volume m_fluid_volume[in] = m_porosity[in]; - m_pcs->SetNodeValue ( in, idx, 1.0); // instead change saturation accordingly; - // cout << " skal factor " << skal_faktor << " excess water volume " << m_excess_water[in] ; - } - else - { - m_excess_water[in] = m_fluid_volume[in] - m_porosity[in] * - m_pcs->GetNodeValue ( in,idx + 1); - skal_faktor = m_porosity[in] * - m_pcs->GetNodeValue ( in,idx + 1) / m_fluid_volume[in]; //KG44 18.10.2012 is this really correct?? - m_fluid_volume[in] = m_porosity[in] * m_pcs->GetNodeValue ( in,idx + 1); + break; + case 2: // liquid flow + m_excess_water[in] = m_fluid_volume[in] - m_porosity[in]; + skal_faktor = (m_porosity[in]) / m_fluid_volume[in]; // scale water to available volume + m_fluid_volume[in] = m_porosity[in]; + break; + case 3: // Richards flow: Saturation is directly calculated from the pressure, therefore add a source-sink term + // to induce pressure/saturation changes + m_pcs = PCSGet("RICHARDS_FLOW"); + idx = m_pcs->GetNodeValueIndex("SATURATION1"); -// m_pcs->SetNodeValue ( in, idx, m_fluid_volume[in] / m_porosity[in]); // instead change saturation accordingly; this is done always. - } - // m_excess_gas[in] = m_gas_volume[in]- m_porosity[in]* ( 1.0 - m_pcs->GetNodeValue ( in,idx+1 ) ); // in contrast to fluid this is not really strongly coupled ...we calculate the stuff but do not couple it to gas flow (yet) - // skal_faktor_gas= ( m_porosity[in]* ( 1.0-m_pcs->GetNodeValue ( in,idx+1 ) ) ) /m_gas_volume[in]; - // m_gas_volume[in] = m_porosity[in]* ( 1-m_pcs->GetNodeValue ( in,idx+1 ) ); - - break; - case 4: // multiphase flow...works with case 1 ...pressure saturation scheme - m_pcs = PCSGet ( "MULTI_PHASE_FLOW" ); - idx = m_pcs->GetNodeValueIndex ( "SATURATION0" ); - m_excess_water[in] = m_fluid_volume[in] - m_porosity[in] * m_pcs->GetNodeValue ( in, - idx + - 1 ); - m_excess_gas[in] = m_gas_volume[in] - m_porosity[in] * - ( 1.0 - m_pcs->GetNodeValue ( in,idx + 1 ) ); - if ( m_fluid_volume[in] > 0.0 ) - m_xDC[in * nDC + - idx_water] *= - m_pcs->GetNodeValue ( in,idx + - 1 ) * m_porosity[in] / m_fluid_volume[in]; - else - m_xDC[in * nDC + idx_water] = 0.0; + if (m_fluid_volume[in] > m_porosity[in]) // fluid volume exceeds available pore space + { + m_excess_water[in] = m_fluid_volume[in] - m_porosity[in]; + skal_faktor = m_porosity[in] / m_fluid_volume[in]; // mol amount of water in first phase + m_fluid_volume[in] = m_porosity[in]; + m_pcs->SetNodeValue(in, idx, 1.0); // instead change saturation accordingly; + // cout << " skal factor " << skal_faktor << " excess water volume " << m_excess_water[in] ; + } + else + { + m_excess_water[in] = m_fluid_volume[in] - m_porosity[in] * m_pcs->GetNodeValue(in, idx + 1); + skal_faktor = m_porosity[in] * m_pcs->GetNodeValue(in, idx + 1) + / m_fluid_volume[in]; // KG44 18.10.2012 is this really correct?? + m_fluid_volume[in] = m_porosity[in] * m_pcs->GetNodeValue(in, idx + 1); + + // m_pcs->SetNodeValue ( in, idx, m_fluid_volume[in] / m_porosity[in]); // instead change + // saturation accordingly; this is done always. + } + // m_excess_gas[in] = m_gas_volume[in]- m_porosity[in]* ( 1.0 - m_pcs->GetNodeValue ( in,idx+1 ) ); // in + // contrast to fluid this is not really strongly coupled ...we calculate the stuff but do not couple it to + // gas flow (yet) + // skal_faktor_gas= ( m_porosity[in]* ( 1.0-m_pcs->GetNodeValue ( in,idx+1 ) ) ) /m_gas_volume[in]; + // m_gas_volume[in] = m_porosity[in]* ( 1-m_pcs->GetNodeValue ( in,idx+1 ) ); + + break; + case 4: // multiphase flow...works with case 1 ...pressure saturation scheme + m_pcs = PCSGet("MULTI_PHASE_FLOW"); + idx = m_pcs->GetNodeValueIndex("SATURATION0"); + m_excess_water[in] = m_fluid_volume[in] - m_porosity[in] * m_pcs->GetNodeValue(in, idx + 1); + m_excess_gas[in] = m_gas_volume[in] - m_porosity[in] * (1.0 - m_pcs->GetNodeValue(in, idx + 1)); + if (m_fluid_volume[in] > 0.0) + m_xDC[in * nDC + idx_water] *= m_pcs->GetNodeValue(in, idx + 1) * m_porosity[in] / m_fluid_volume[in]; + else + m_xDC[in * nDC + idx_water] = 0.0; - break; - default: + break; + default: #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - if ( myrank == 0 /*should be set to root*/ ) + if (myrank == 0 /*should be set to root*/) #endif - cout << "Error: Not implemented for the flow in GEM case!!!" << "\n"; - break; + cout << "Error: Not implemented for the flow in GEM case!!!" + << "\n"; + break; } #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - // if ( fabs ( m_excess_water_buff[in] ) >= 0.01 ) cout << "node "<< in <<" m_excess_water" << m_excess_water_buff[in] <<"\n"; - // if ( fabs ( m_excess_gas_buff[in] ) >= 0.01 ) cout << "node "<< in <<" m_excess_gas" << m_excess_water_buff[in] <<"\n"; +// if ( fabs ( m_excess_water_buff[in] ) >= 0.01 ) cout << "node "<< in <<" m_excess_water" << m_excess_water_buff[in] +//<<"\n"; +// if ( fabs ( m_excess_gas_buff[in] ) >= 0.01 ) cout << "node "<< in <<" m_excess_gas" << m_excess_water_buff[in] +//<<"\n"; #else - // if ( fabs ( m_excess_water[in] ) >= 0.01 ) cout << "node "<< in <<" m_excess_water " << m_excess_water[in] <<"\n"; - // if ( fabs ( m_excess_gas[in] ) >= 0.01 ) cout << "node "<< in <<" m_excess_gas " << m_excess_water[in] <<"\n"; +// if ( fabs ( m_excess_water[in] ) >= 0.01 ) cout << "node "<< in <<" m_excess_water " << m_excess_water[in] <<"\n"; +// if ( fabs ( m_excess_gas[in] ) >= 0.01 ) cout << "node "<< in <<" m_excess_gas " << m_excess_water[in] <<"\n"; #endif // if positive, then source, otherwise sink. // change amount of fluid .... at the moment only water!!!!!! - // if ( fabs ( m_excess_water[in] ) >= 1.e-10 ) cout << "node "<< in <<"m_excess_water" << m_excess_water[in] <<"\n"; + // if ( fabs ( m_excess_water[in] ) >= 1.e-10 ) cout << "node "<< in <<"m_excess_water" << m_excess_water[in] + // <<"\n"; // do we need to scale this accoring to the node volume?..I think so: it is done while transering this to GEMS - if ( flowflag < 3 ) + if (flowflag < 3) { - for ( j = 0; j < nIC; j++ ) + for (j = 0; j < nIC; j++) { i = in * nIC + j; ii = in * nPS * nIC + 0 * nIC + j; // corresponding index of first phase (fluid) for m_bPS - m_bIC[i] -= m_bPS[ii]; // B vector without solute - if ( flag_coupling_hydrology ) + m_bIC[i] -= m_bPS[ii]; // B vector without solute + if (flag_coupling_hydrology) m_bPS[ii] *= skal_faktor; // completely newly scaled first phase ...only for coupling with hydraulics else { // this is necessary for not coupling with hydrology, but porosity change or water is used by gems.... - if ( idx_hydrogen == j ) + if (idx_hydrogen == j) m_bPS[ii] *= skal_faktor; - if ( idx_oxygen == j ) + if (idx_oxygen == j) m_bPS[ii] *= skal_faktor; } } @@ -2346,23 +2349,22 @@ int REACT_GEM::MassToConcentration ( long in,int i_failed, TNode* m_Node ) // j = idx_water; { i = in * nDC + j; - m_xDC[i] *= skal_faktor; //newly scaled xDC including water /excluding rest + m_xDC[i] *= skal_faktor; // newly scaled xDC including water /excluding rest } // here we do not need to account for different flow processes .... //**************************************************************************************** - if ( flag_transport_b == 1 ) - for ( j = 0; j < nIC; j++ ) + if (flag_transport_b == 1) + for (j = 0; j < nIC; j++) { i = in * nIC + j; ii = in * nPS * nIC + 0 * nIC + j; // corresponding index of first phase (fluid) for m_bPS // correct for water and transform bPS into concentrations - //carrier for zero(first phase) is normally water! - if ( idx_hydrogen == j ) - m_soluteB[i] = m_bPS[ii] - - ( 2.0 * m_xDC[in * nDC + idx_water] ); - else if ( idx_oxygen == j ) + // carrier for zero(first phase) is normally water! + if (idx_hydrogen == j) + m_soluteB[i] = m_bPS[ii] - (2.0 * m_xDC[in * nDC + idx_water]); + else if (idx_oxygen == j) m_soluteB[i] = m_bPS[ii] - m_xDC[in * nDC + idx_water]; else m_soluteB[i] = m_bPS[ii]; @@ -2371,21 +2373,21 @@ int REACT_GEM::MassToConcentration ( long in,int i_failed, TNode* m_Node ) // } } // flowflag < 3 is finished - else if ( flowflag == 3 ) // richards flow ....no corrections in gas phase for Richards flow! + else if (flowflag == 3) // richards flow ....no corrections in gas phase for Richards flow! { - for ( j = 0; j < nIC; j++ ) + for (j = 0; j < nIC; j++) { i = in * nIC + j; ii = in * nPS * nIC + 0 * nIC + j; // corresponding index of first phase (fluid) for m_bPS - m_bIC[i] -= ( m_bPS[ii]); // B vector without solute - if ( flag_coupling_hydrology ) // in any case this accounts only for fully saturated conditions + m_bIC[i] -= (m_bPS[ii]); // B vector without solute + if (flag_coupling_hydrology) // in any case this accounts only for fully saturated conditions m_bPS[ii] *= skal_faktor; // completely newly scaled first phase ...only for coupling with hydraulics else { // this is necessary for not coupling with hydrology, but porosity change or water is used by gems.... - if ( idx_hydrogen == j ) + if (idx_hydrogen == j) m_bPS[ii] *= skal_faktor; - if ( idx_oxygen == j ) + if (idx_oxygen == j) m_bPS[ii] *= skal_faktor; } } @@ -2393,207 +2395,213 @@ int REACT_GEM::MassToConcentration ( long in,int i_failed, TNode* m_Node ) // j = idx_water; { i = in * nDC + j; - m_xDC[i] *= skal_faktor; //newly scaled xDC for water + m_xDC[i] *= skal_faktor; // newly scaled xDC for water } - // here we do not need to account for different flow processes .... as long as we work only with one wetting phase (water!!!) ...for liqid CO2 we have to change something .... + // here we do not need to account for different flow processes .... as long as we work only with one wetting + // phase (water!!!) ...for liqid CO2 we have to change something .... //**************************************************************************************** - if ( flag_transport_b == 1 ) - for ( j = 0; j < nIC; j++ ) + if (flag_transport_b == 1) + for (j = 0; j < nIC; j++) { i = in * nIC + j; ii = in * nPS * nIC + 0 * nIC + j; // corresponding index of first phase (fluid) for m_bPS // correct for water and transform bPS into concentrations - //carrier for zero(first phase) is normally water! - if ( idx_hydrogen == j ) - m_soluteB[i] = m_bPS[ii] - - ( 2.0 * m_xDC[in * nDC + idx_water] ); - else if ( idx_oxygen == j ) + // carrier for zero(first phase) is normally water! + if (idx_hydrogen == j) + m_soluteB[i] = m_bPS[ii] - (2.0 * m_xDC[in * nDC + idx_water]); + else if (idx_oxygen == j) m_soluteB[i] = m_bPS[ii] - m_xDC[in * nDC + idx_water]; else m_soluteB[i] = m_bPS[ii]; m_soluteB[i] /= m_fluid_volume[in]; // now these are the concentrations } - } return 1; } -int REACT_GEM::ConcentrationToMass ( long l /*idx of node*/, int i_timestep ) +int REACT_GEM::ConcentrationToMass(long l /*idx of node*/, int i_timestep) { // converting the value from mol/m^3 water to moles. - long i,j,ii; + long i, j, ii; double water_volume = 0.0, scale_factor = 1.0; int idx; string ErrorOut; // cout <<"water volume " << water_volume << "\n"; - // I think here it has to be different than in MassToConcentration module, as after hydraulics, the volume is limited to porosity + // I think here it has to be different than in MassToConcentration module, as after hydraulics, the volume is + // limited to porosity // As we work with an unit volume of "one", it should be save to directly take porosity as volume.... // of course we have to differenciate between the different flow models CRFProcess* m_pcs = NULL; - switch ( flowflag ) + switch (flowflag) { - case 1: // groundwater flow - water_volume = m_fluid_volume[l]; // kg44: reuse stored fluid volume from last timestep! - break; - case 2: // liquid flow - water_volume = m_fluid_volume[l]; - break; - case 3: // Richards flow - m_pcs = PCSGet ( "RICHARDS_FLOW" ); - idx = m_pcs->GetNodeValueIndex ( "SATURATION1" ); - scale_factor = m_porosity[l] * m_pcs->GetNodeValue ( l,idx + i_timestep ); //current volume of water phase after hydraulic step - water_volume = m_fluid_volume[l]; // old volume of water phase after last GEMS step - scale_factor /= water_volume; // 1: same volume <1 decrease in water volume >1 incresing volume - m_fluid_volume[l] = water_volume; // update fluid volume - // cout << "conctomass " << m_fluid_volume[l] << " " << scale_factor <<" " ; - break; - case 4: // multiphase flow...works with case 1 ...pressure saturation scheme - m_pcs = PCSGet ( "MULTI_PHASE_FLOW" ); - idx = m_pcs->GetNodeValueIndex ( "SATURATION0" ); - water_volume = m_porosity[l] * m_pcs->GetNodeValue ( l,idx + i_timestep ); - break; - default: + case 1: // groundwater flow + water_volume = m_fluid_volume[l]; // kg44: reuse stored fluid volume from last timestep! + break; + case 2: // liquid flow + water_volume = m_fluid_volume[l]; + break; + case 3: // Richards flow + m_pcs = PCSGet("RICHARDS_FLOW"); + idx = m_pcs->GetNodeValueIndex("SATURATION1"); + scale_factor + = m_porosity[l] + * m_pcs->GetNodeValue(l, idx + i_timestep); // current volume of water phase after hydraulic step + water_volume = m_fluid_volume[l]; // old volume of water phase after last GEMS step + scale_factor /= water_volume; // 1: same volume <1 decrease in water volume >1 incresing volume + m_fluid_volume[l] = water_volume; // update fluid volume + // cout << "conctomass " << m_fluid_volume[l] << " " << scale_factor <<" " ; + break; + case 4: // multiphase flow...works with case 1 ...pressure saturation scheme + m_pcs = PCSGet("MULTI_PHASE_FLOW"); + idx = m_pcs->GetNodeValueIndex("SATURATION0"); + water_volume = m_porosity[l] * m_pcs->GetNodeValue(l, idx + i_timestep); + break; + default: #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - if ( myrank == 0 /*should be set to root*/ ) + if (myrank == 0 /*should be set to root*/) #endif - cout << "Error: Not implemented for the flow in GEM case!!!" << "\n"; - break; + cout << "Error: Not implemented for the flow in GEM case!!!" + << "\n"; + break; } - if ( ( water_volume < min_possible_porosity ) || ( water_volume > 1.0 ) ) + if ((water_volume < min_possible_porosity) || (water_volume > 1.0)) { cout << "conctomass water volume " << water_volume << " at node: " << l << "\n"; #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - MPI_Finalize(); //make sure MPI exits + MPI_Finalize(); // make sure MPI exits #endif - exit ( 1 ); + exit(1); } - if ( flowflag < 3 ) // groundwater flow or fluid flow + if (flowflag < 3) // groundwater flow or fluid flow - for ( j = 0; j < nIC; j++ ) + for (j = 0; j < nIC; j++) { i = l * nIC + j; // also check if xDC values is negative - if ( m_soluteB[i] < 0.0 ) + if (m_soluteB[i] < 0.0) // make sure it is greater/eq zero and take value from last timestep ---> second argument is zero! - m_soluteB[i] = fabs ( GetDCValueSpecies_MT ( l, 0, ( int ) j ) ); + m_soluteB[i] = fabs(GetDCValueSpecies_MT(l, 0, (int)j)); m_soluteB[i] *= water_volume; - //carrier for zero(first phase) is normally water! - if ( idx_hydrogen == j ) - m_soluteB[i] += ( 2.0 * m_xDC[l * nDC + idx_water] ); - else if ( idx_oxygen == j ) - m_soluteB[i] += m_xDC[l * nDC + idx_water]; - - m_bIC[i] += m_soluteB[i]; //updated B vector for GEMS - // here we check again if the vector if negative or smaller than a minimum amount...if yes we add some stuff.... - // adding 10-6 Mol/m^3 should be save, as this corresponds aprox to 10-9 Mol/kg ..which is well above the accuracy for most calculations - if ( m_bIC[i] <= 1.0e-8 ) + // carrier for zero(first phase) is normally water! + if (idx_hydrogen == j) + m_soluteB[i] += (2.0 * m_xDC[l * nDC + idx_water]); + else if (idx_oxygen == j) + m_soluteB[i] += m_xDC[l * nDC + idx_water]; + + m_bIC[i] += m_soluteB[i]; // updated B vector for GEMS + // here we check again if the vector if negative or smaller than a minimum amount...if yes we add some + // stuff.... + // adding 10-6 Mol/m^3 should be save, as this corresponds aprox to 10-9 Mol/kg ..which is well above the + // accuracy for most calculations + if (m_bIC[i] <= 1.0e-8) m_bIC[i] = 1e-6; // cout << " i " << i << " " << m_bIC[i] << "\n"; } - else if ( flowflag == 3 ) // Richards flow + else if (flowflag == 3) // Richards flow { - for ( j = 0; j < nIC; j++ ) + for (j = 0; j < nIC; j++) { i = l * nIC + j; ii = l * nPS * nIC + 0 * nIC + j; // corresponding index of first phase (fluid) for m_bPS - // cout << " i " << i << " " << m_soluteB[i] << " " < 1.0 ) ) + if (!(m_soluteB[i] <= 1.0) && !(m_soluteB[i] > 1.0)) { - cout << " m_soluteB[i] " << m_soluteB[i] << " is NaN " << " i " << - i << " stop calculations " << "\n"; + cout << " m_soluteB[i] " << m_soluteB[i] << " is NaN " + << " i " << i << " stop calculations " + << "\n"; #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - MPI_Finalize(); //make sure MPI exits + MPI_Finalize(); // make sure MPI exits #endif - exit ( 1 ); + exit(1); } // also check if xDC values is negative - if ( m_soluteB[i] < 0.0 ) + if (m_soluteB[i] < 0.0) // make sure it is greater/eq zero and take value from last timestep ---> second argument is zero! - m_soluteB[i] = fabs ( GetDCValueSpecies_MT ( l, 0, ( int ) j ) ); - m_soluteB[i] *= water_volume * scale_factor; //match solutes with old fluid volume and account for hydraulic changes - //carrier for zero(first phase) is normally water! - if ( idx_hydrogen == j ) - m_soluteB[i] += ( 2.0 * m_xDC[l * nDC + idx_water] ) * scale_factor; - //match to volume after hydraulic step - else if ( idx_oxygen == j ) - m_soluteB[i] += m_xDC[l * nDC + idx_water] * scale_factor; - -// m_bIC[i]+= ( m_soluteB[i]+m_bPS[ii] ); //updated B vector for GEMS ....no correction in gas phase for Richards flow! - m_bIC[i] += ( m_soluteB[i]); //updated B vector for GEMS ....no correction in gas phase for Richards flow! - - // here we check again if the vector if negative or smaller than a minimum amount...if yes we add some stuff.... - // adding 10-6 Mol/m^3 should be save, as this corresponds aprox to 10-9 Mol/kg ..which is well above the accuracy for most calculations - if ( m_bIC[i] <= 1.0e-8 ) + m_soluteB[i] = fabs(GetDCValueSpecies_MT(l, 0, (int)j)); + m_soluteB[i] + *= water_volume * scale_factor; // match solutes with old fluid volume and account for hydraulic changes + // carrier for zero(first phase) is normally water! + if (idx_hydrogen == j) + m_soluteB[i] += (2.0 * m_xDC[l * nDC + idx_water]) * scale_factor; + // match to volume after hydraulic step + else if (idx_oxygen == j) + m_soluteB[i] += m_xDC[l * nDC + idx_water] * scale_factor; + + // m_bIC[i]+= ( m_soluteB[i]+m_bPS[ii] ); //updated B vector for GEMS ....no + // correction in gas phase for Richards flow! + m_bIC[i] += (m_soluteB[i]); // updated B vector for GEMS ....no correction in gas phase for Richards flow! + + // here we check again if the vector if negative or smaller than a minimum amount...if yes we add some + // stuff.... + // adding 10-6 Mol/m^3 should be save, as this corresponds aprox to 10-9 Mol/kg ..which is well above the + // accuracy for most calculations + if (m_bIC[i] <= 1.0e-8) m_bIC[i] = 1e-6; } } return 1; } -void REACT_GEM::CopyCurXDCPre ( void ) +void REACT_GEM::CopyCurXDCPre(void) { long i; - for ( i = 0; i < nNodes * nDC; i++ ) + for (i = 0; i < nNodes * nDC; i++) m_xDC_pts[i] = m_xDC[i]; - } -void REACT_GEM::UpdateXDCChemDelta ( void ) +void REACT_GEM::UpdateXDCChemDelta(void) { long i; - for ( i = 0; i < nNodes * nDC; i++ ) + for (i = 0; i < nNodes * nDC; i++) m_xDC_Chem_delta[i] = m_xDC[i] - m_xDC_pts[i]; - } -void REACT_GEM::CopyCurBPre ( void ) +void REACT_GEM::CopyCurBPre(void) { long i; - for ( i = 0; i < nNodes * nIC; i++ ) + for (i = 0; i < nNodes * nIC; i++) { m_soluteB_pts[i] = m_soluteB[i]; m_bIC_pts[i] = m_bIC[i]; } } -double REACT_GEM::CalcSoluteBDelta ( long in ) +double REACT_GEM::CalcSoluteBDelta(long in) { long i; double dummy = 0; - for ( i = 0; i < nIC - 1; i++ ) - dummy = max ( dummy,abs ( - m_soluteB[in * nIC + - i] - - m_soluteB_pts[in * nIC + i] ) / m_soluteB[in * nIC + i] ); + for (i = 0; i < nIC - 1; i++) + dummy = max(dummy, abs(m_soluteB[in * nIC + i] - m_soluteB_pts[in * nIC + i]) / m_soluteB[in * nIC + i]); return dummy; } -void REACT_GEM::RestoreOldSolution ( long in ) +void REACT_GEM::RestoreOldSolution(long in) { long i; - for ( i = 0; i < nIC - 1; i++ ) + for (i = 0; i < nIC - 1; i++) { m_soluteB[in * nIC + i] = m_soluteB_pts[in * nIC + i]; m_bIC[in * nIC + i] = m_bIC_pts[in * nIC + i]; } - for ( i = 0; i < nDC; i++ ) + for (i = 0; i < nDC; i++) m_xDC[in * nDC + i] = m_xDC_pts[in * nDC + i]; - } -bool GEMRead ( string base_file_name, REACT_GEM* m_GEM_p ) +bool GEMRead(string base_file_name, REACT_GEM* m_GEM_p) { - cout << "GEMRead" << "\n"; + cout << "GEMRead" + << "\n"; char line[MAX_ZEILE]; string sub_line; string line_string; @@ -2602,29 +2610,30 @@ bool GEMRead ( string base_file_name, REACT_GEM* m_GEM_p ) // file handling string gem_file_name; gem_file_name = base_file_name + GEM_FILE_EXTENSION; - ifstream gem_file ( gem_file_name.data(),ios::in ); - if ( !gem_file.good() ) + ifstream gem_file(gem_file_name.data(), ios::in); + if (!gem_file.good()) { - cout << "! Error in GEMRead: No GEM data !" << "\n"; + cout << "! Error in GEMRead: No GEM data !" + << "\n"; return false; } - gem_file.seekg ( 0L,ios::beg ); + gem_file.seekg(0L, ios::beg); //======================================================================== // keyword loop - while ( !gem_file.eof() ) + while (!gem_file.eof()) { - gem_file.getline ( line,MAX_ZEILE ); + gem_file.getline(line, MAX_ZEILE); line_string = line; - if ( line_string.find ( "#STOP" ) != string::npos ) + if (line_string.find("#STOP") != string::npos) return true; //---------------------------------------------------------------------- // keyword found - if ( line_string.find ( "#GEM_PROPERTIES" ) != string::npos ) + if (line_string.find("#GEM_PROPERTIES") != string::npos) { - position = m_GEM_p->Read ( &gem_file ); - gem_file.seekg ( position,ios::beg ); - } // keyword found - } // eof + position = m_GEM_p->Read(&gem_file); + gem_file.seekg(position, ios::beg); + } // keyword found + } // eof return true; } @@ -2632,153 +2641,167 @@ bool GEMRead ( string base_file_name, REACT_GEM* m_GEM_p ) * * */ -ios::pos_type REACT_GEM::Read ( std::ifstream* gem_file ) +ios::pos_type REACT_GEM::Read(std::ifstream* gem_file) { - Kinetic_GEMS d_kin; // dummy kinetic vector + Kinetic_GEMS d_kin; // dummy kinetic vector int j; // Initialization---------------- string sub_line; string line_string; - string delimiter ( " " ); + string delimiter(" "); bool new_keyword = false; - string hash ( "#" ); + string hash("#"); ios::pos_type position; string sub_string; - string dollar ( "$" ); - string delimiter_type ( ":" ); + string dollar("$"); + string delimiter_type(":"); std::stringstream in; // ------------------------------ // Loop over all the key words---------------------- - while ( !new_keyword ) + while (!new_keyword) { position = gem_file->tellg(); - line_string = GetLineFromFile1 ( gem_file ); - if ( line_string.size() < 1 ) + line_string = GetLineFromFile1(gem_file); + if (line_string.size() < 1) break; - if ( line_string.find ( hash ) != string::npos ) + if (line_string.find(hash) != string::npos) { new_keyword = true; break; } - /// Key word "$GEM_INIT_FILE" : next line contains the name of the GEMS file with ending ".lst" that defines the setup, thermodynamic data and the numerical settings for the simulation........................ - if ( line_string.find ( "$GEM_INIT_FILE" ) != string::npos ) + /// Key word "$GEM_INIT_FILE" : next line contains the name of the GEMS file with ending ".lst" that defines the + /// setup, thermodynamic data and the numerical settings for the simulation........................ + if (line_string.find("$GEM_INIT_FILE") != string::npos) { // subkeyword found - in.str ( GetLineFromFile1 ( gem_file ) ); + in.str(GetLineFromFile1(gem_file)); in >> init_input_file_path; in.clear(); continue; } - /// Key word "$GEM_THREADS" : next line contains the number of GEMS3K worker threads to be started (for each MPI process). The minimum number of threads is 1!....................... - if ( line_string.find ( "$GEM_THREADS" ) != string::npos ) + /// Key word "$GEM_THREADS" : next line contains the number of GEMS3K worker threads to be started (for each MPI + /// process). The minimum number of threads is 1!....................... + if (line_string.find("$GEM_THREADS") != string::npos) { // subkeyword found - in.str ( GetLineFromFile1 ( gem_file ) ); + in.str(GetLineFromFile1(gem_file)); in >> gem_nThread; cout << "OGS-GEM gem read: number of threads: " << gem_nThread << "\n"; in.clear(); continue; } - /// Key word "$TRANSPORT_B": next line should be "1" to indicate the transport of total concentrations of independet species in fluid phase. The transport of all dependent species in the fluid phase is currently not supported anymore. ....................... - if ( line_string.find ( "$TRANSPORT_B" ) != string::npos ) + /// Key word "$TRANSPORT_B": next line should be "1" to indicate the transport of total concentrations of + /// independet species in fluid phase. The transport of all dependent species in the fluid phase is currently + /// not supported anymore. ....................... + if (line_string.find("$TRANSPORT_B") != string::npos) { // subkeyword found - in.str ( GetLineFromFile1 ( gem_file ) ); + in.str(GetLineFromFile1(gem_file)); in >> flag_transport_b; - if ( !flag_transport_b ) + if (!flag_transport_b) { - cout << - "Transport of all species is currently not supported! stop program" + cout << "Transport of all species is currently not supported! stop program" << "\n"; #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - MPI_Finalize(); //make sure MPI exits + MPI_Finalize(); // make sure MPI exits #endif - exit ( 1 ); + exit(1); } in.clear(); continue; } // ...................................................... - /// Key word "$FLAG_POROSITY_CHANGE": next line could be either "0" or "1" (recommended). "1": changes in the volume of solid phases cause the porosity to change ....................... - if ( line_string.find ( "$FLAG_POROSITY_CHANGE" ) != string::npos ) + /// Key word "$FLAG_POROSITY_CHANGE": next line could be either "0" or "1" (recommended). "1": changes in the + /// volume of solid phases cause the porosity to change ....................... + if (line_string.find("$FLAG_POROSITY_CHANGE") != string::npos) { // subkeyword found - in.str ( GetLineFromFile1 ( gem_file ) ); + in.str(GetLineFromFile1(gem_file)); in >> flag_porosity_change; in.clear(); continue; } // ...................................................... - /// Key word "$MIN_POROSITY": next line should contain the minim porosity which has to be bigger than "0" e.g. "1e-6" ............................. - if ( line_string.find ( "$MIN_POROSITY" ) != string::npos ) + /// Key word "$MIN_POROSITY": next line should contain the minim porosity which has to be bigger than "0" e.g. + /// "1e-6" ............................. + if (line_string.find("$MIN_POROSITY") != string::npos) { // subkeyword found - in.str ( GetLineFromFile1 ( gem_file ) ); + in.str(GetLineFromFile1(gem_file)); in >> min_possible_porosity; in.clear(); continue; } // ...................................................... - /// Key word "$MAX_POROSITY": next line should contain the maximum porosity, recommended value: 1.0 ............................. - if ( line_string.find ( "$MAX_POROSITY" ) != string::npos ) + /// Key word "$MAX_POROSITY": next line should contain the maximum porosity, recommended value: 1.0 + /// ............................. + if (line_string.find("$MAX_POROSITY") != string::npos) { // subkeyword found - in.str ( GetLineFromFile1 ( gem_file ) ); + in.str(GetLineFromFile1(gem_file)); in >> max_possible_porosity; in.clear(); continue; } // ...................................................... - /// Key word "$FLAG_COUPLING_HYDROLOGY": If the system volume exceeds the reference volume (1 m^3) due to volume changes of solids and/or fluid phases the excess fluid is substracted from the volume. It is reinjected into the system during the next time step via source/sink time in the flow equation. .................. - if ( line_string.find ( "$FLAG_COUPLING_HYDROLOGY" ) != string::npos ) + /// Key word "$FLAG_COUPLING_HYDROLOGY": If the system volume exceeds the reference volume (1 m^3) due to volume + /// changes of solids and/or fluid phases the excess fluid is substracted from the volume. It is reinjected into + /// the system during the next time step via source/sink time in the flow equation. .................. + if (line_string.find("$FLAG_COUPLING_HYDROLOGY") != string::npos) { // subkeyword found - in.str ( GetLineFromFile1 ( gem_file ) ); + in.str(GetLineFromFile1(gem_file)); in >> flag_coupling_hydrology; in.clear(); continue; } // ...................................................... - /// Key word "$ITERATIVE_SCHEME": not yet implemented, set to zero or remove keyword from input file ......................... - if ( line_string.find ( "$ITERATIVE_SCHEME" ) != string::npos ) + /// Key word "$ITERATIVE_SCHEME": not yet implemented, set to zero or remove keyword from input file + /// ......................... + if (line_string.find("$ITERATIVE_SCHEME") != string::npos) { // subkeyword found - in.str ( GetLineFromFile1 ( gem_file ) ); + in.str(GetLineFromFile1(gem_file)); in >> flag_iterative_scheme; in.clear(); continue; } // ...................................................... - /// Key word "$GEM_CALCULATE_BOUNDARY_NODES": By setting this to "1" it is possible to switch on GEMS calculations at boundary nodes (e.g. kinetically controlled porosity change at boundary nodes). This normally requires the definition of time dependent concentration values via time curves (see documentation of .bc files how to do this). .................. - if ( line_string.find ( "$CALCULATE_BOUNDARY_NODES" ) != string::npos ) + /// Key word "$GEM_CALCULATE_BOUNDARY_NODES": By setting this to "1" it is possible to switch on GEMS + /// calculations at boundary nodes (e.g. kinetically controlled porosity change at boundary nodes). This + /// normally requires the definition of time dependent concentration values via time curves (see documentation + /// of .bc files how to do this). .................. + if (line_string.find("$CALCULATE_BOUNDARY_NODES") != string::npos) { // subkeyword found - in.str ( GetLineFromFile1 ( gem_file ) ); + in.str(GetLineFromFile1(gem_file)); in >> flag_calculate_boundary_nodes; in.clear(); continue; } // ...................................................... // ...................................................... - /// Key word "$TEMPERATURE_GEM": with this keyword it is possible to change the overall temperature of the system (default 298.15 K)......................... - if ( line_string.find ( "$TEMPERATURE_GEM" ) != string::npos ) + /// Key word "$TEMPERATURE_GEM": with this keyword it is possible to change the overall temperature of the + /// system (default 298.15 K)......................... + if (line_string.find("$TEMPERATURE_GEM") != string::npos) { // subkeyword found - in.str ( GetLineFromFile1 ( gem_file ) ); + in.str(GetLineFromFile1(gem_file)); in >> m_gem_temperature; in.clear(); continue; } - /// Key word "$PRESSURE_GEM": with this keyword it is possible to disable the coupling between fluid pressures and GEMS calculations: set the desired value for GEMS calculations ......................... - if ( line_string.find ( "$PRESSURE_GEM" ) != string::npos ) + /// Key word "$PRESSURE_GEM": with this keyword it is possible to disable the coupling between fluid pressures + /// and GEMS calculations: set the desired value for GEMS calculations ......................... + if (line_string.find("$PRESSURE_GEM") != string::npos) { // subkeyword found - in.str ( GetLineFromFile1 ( gem_file ) ); + in.str(GetLineFromFile1(gem_file)); in >> m_gem_pressure; in.clear(); gem_pressure_flag = 1; @@ -2786,33 +2809,36 @@ ios::pos_type REACT_GEM::Read ( std::ifstream* gem_file ) } // ...................................................... - /// Key word "$MAX_FAILED_NODES" limits the number of failed nodes of GEMS calcuations for each MPI process. Run is exited if the number is exceeded.......................... - if ( line_string.find ( "$MAX_FAILED_NODES" ) != string::npos ) + /// Key word "$MAX_FAILED_NODES" limits the number of failed nodes of GEMS calcuations for each MPI process. Run + /// is exited if the number is exceeded.......................... + if (line_string.find("$MAX_FAILED_NODES") != string::npos) { // subkeyword found - in.str ( GetLineFromFile1 ( gem_file ) ); + in.str(GetLineFromFile1(gem_file)); in >> m_max_failed_nodes; in.clear(); continue; } - /// Key word "$MY_SMART_GEMS": if the summarized change in b-vector is smaller than this value, GEMS calculations are not done and previous values are taken. ......................... - if ( line_string.find ( "$MY_SMART_GEMS" ) != string::npos ) + /// Key word "$MY_SMART_GEMS": if the summarized change in b-vector is smaller than this value, GEMS + /// calculations are not done and previous values are taken. ......................... + if (line_string.find("$MY_SMART_GEMS") != string::npos) { // subkeyword found - in.str ( GetLineFromFile1 ( gem_file ) ); + in.str(GetLineFromFile1(gem_file)); in >> m_diff_gems; in.clear(); continue; - } // ...................................................... - /// Key word "$DISABLE_GEMS": gems calculations are not done / and no update of porosity etc...usefull for creating initial files if boundary conditions cause oszillations......................... - if ( line_string.find ( "$FLAG_DISABLE_GEM" ) != string::npos ) + } // ...................................................... + /// Key word "$DISABLE_GEMS": gems calculations are not done / and no update of porosity etc...usefull for + /// creating initial files if boundary conditions cause oszillations......................... + if (line_string.find("$FLAG_DISABLE_GEM") != string::npos) { // subkeyword found - in.str ( GetLineFromFile1 ( gem_file ) ); + in.str(GetLineFromFile1(gem_file)); in >> flag_disable_gems; in.clear(); continue; - } // ...................................................... + } // ...................................................... // kg44 26.11.2008 read in parameters for kinetics and GEM /** $KINETIC_GEM @@ -2832,103 +2858,94 @@ ios::pos_type REACT_GEM::Read ( std::ifstream* gem_file ) * model parameters for reactive surface area: e.g. specific reactive surface area * example: * $KINETIC_GEM ; Quartz phase no 45 (starts at 0) wie Fernandez et al 2009 - * Quartz 1 1 0.0 0.0 0.0 0.0 -13.99 -16.29 0.0 1.0 0.0 1.0 1.0 1.0 H+ 0.0 0.0 -0.5 ; this are the kinetic parameters + * Quartz 1 1 0.0 0.0 0.0 0.0 -13.99 -16.29 0.0 1.0 0.0 1.0 1.0 1.0 H+ 0.0 0.0 -0.5 ; this + * are the kinetic parameters * 1 1.0e4 ; this are the parameters for reactive surface area */ - if ( line_string.find ( "$KINETIC_GEM" ) != string::npos ) + if (line_string.find("$KINETIC_GEM") != string::npos) { - in.str ( GetLineFromFile1 ( gem_file ) ); + in.str(GetLineFromFile1(gem_file)); in >> d_kin.phase_name >> d_kin.kinetic_model; - if ( d_kin.kinetic_model >= 1 && d_kin.kinetic_model <= 5 ) + if (d_kin.kinetic_model >= 1 && d_kin.kinetic_model <= 5) { - cout << " found kinetics " << d_kin.kinetic_model << " " << - d_kin.phase_name << "\n"; + cout << " found kinetics " << d_kin.kinetic_model << " " << d_kin.phase_name << "\n"; in >> d_kin.n_activities; - if ( d_kin.n_activities > 10 ) + if (d_kin.n_activities > 10) { - cout << - "To many dependent species for GEM kinetic model " - << - d_kin.n_activities << "\n"; + cout << "To many dependent species for GEM kinetic model " << d_kin.n_activities << "\n"; #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - MPI_Finalize(); //make sure MPI exits + MPI_Finalize(); // make sure MPI exits #endif - exit ( 1 ); + exit(1); } // cout <<" activities " << n_activities << "\n"; // first general kinetic parameters // 0,1,2 double E_acid,E_neutral,E_base; // activation energies - in >> d_kin.kinetic_parameters[0] >> d_kin.kinetic_parameters[1] >> - d_kin.kinetic_parameters[2]; + in >> d_kin.kinetic_parameters[0] >> d_kin.kinetic_parameters[1] >> d_kin.kinetic_parameters[2]; // cout << kinetic_parameters[0] << kinetic_parameters[1] << kinetic_parameters[1]<<"\n"; // 3-5 double k_acid, k_neutral,k_base; // dissolution/precipitation rate constants - in >> d_kin.kinetic_parameters[3] >> d_kin.kinetic_parameters[4] >> - d_kin.kinetic_parameters[5]; + in >> d_kin.kinetic_parameters[3] >> d_kin.kinetic_parameters[4] >> d_kin.kinetic_parameters[5]; // cout << kinetic_parameters[3] << kinetic_parameters[4] << kinetic_parameters[5]<<"\n"; // 6-11 double q1,p1,q2,q3,p2,p3; // exponents for omega - in >> d_kin.kinetic_parameters[6] >> d_kin.kinetic_parameters[7] >> - d_kin.kinetic_parameters[8] >> d_kin.kinetic_parameters[9] >> - d_kin.kinetic_parameters[10] >> d_kin.kinetic_parameters[11]; - for ( j = 0; j < d_kin.n_activities; j++ ) + in >> d_kin.kinetic_parameters[6] >> d_kin.kinetic_parameters[7] >> d_kin.kinetic_parameters[8] + >> d_kin.kinetic_parameters[9] >> d_kin.kinetic_parameters[10] >> d_kin.kinetic_parameters[11]; + for (j = 0; j < d_kin.n_activities; j++) { in >> d_kin.active_species[j]; // cout << active_species[j] ; - // 12,13,14 double n_1, n_2,n_3; // exponents for acidic, neutral and base cases for species one - - in >> - d_kin.kinetic_parameters[j + - 12] >> - d_kin.kinetic_parameters[j + - 13] >> - d_kin.kinetic_parameters[j + 14]; + // 12,13,14 double n_1, n_2,n_3; // exponents for acidic, neutral and base cases for species + // one + + in >> d_kin.kinetic_parameters[j + 12] >> d_kin.kinetic_parameters[j + 13] + >> d_kin.kinetic_parameters[j + 14]; } } in.clear(); // next line is surface area - in.str ( GetLineFromFile1 ( gem_file ) ); + in.str(GetLineFromFile1(gem_file)); in >> d_kin.surface_model; cout << d_kin.surface_model << "\n"; - if ( d_kin.surface_model >= 1 || d_kin.surface_model < 4 ) // surface model 1, 2 and 3....only one parameter... + if (d_kin.surface_model >= 1 + || d_kin.surface_model < 4) // surface model 1, 2 and 3....only one parameter... { in >> d_kin.surface_area[0]; // surface: m*m / mol cout << "surface area " << d_kin.surface_area[0] << "\n"; } - else if ( d_kin.kinetic_model == 4 ) // model 4 is kinetic a la crunch + else if (d_kin.kinetic_model == 4) // model 4 is kinetic a la crunch { in >> d_kin.surface_area[0]; // surface: m*m / mol - cout << "mimic crunch: surface area " << d_kin.surface_area[0] << - "\n"; + cout << "mimic crunch: surface area " << d_kin.surface_area[0] << "\n"; } - else if ( d_kin.kinetic_model == 5 ) // model 5 is for solid solutions, needed parameters are the number of endmembers and the surface area for each endmember + else if (d_kin.kinetic_model == 5) // model 5 is for solid solutions, needed parameters are the number of + // endmembers and the surface area for each endmember { // next line are SS parameters - in.str ( GetLineFromFile1 ( gem_file ) ); + in.str(GetLineFromFile1(gem_file)); in >> d_kin.ss_endmembers; try { d_kin.ss_scaling = new double[d_kin.ss_endmembers]; } - catch ( bad_alloc ) + catch (bad_alloc) { - cout << - "Reading Gems input: problem while allocating memory for Solid Solution scaling parameters" + cout << "Reading Gems input: problem while allocating memory for Solid Solution scaling parameters" << "\n"; #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - MPI_Finalize(); //make sure MPI exits + MPI_Finalize(); // make sure MPI exits #endif - exit ( 1 ); + exit(1); } - for ( j = 0; j < d_kin.ss_endmembers; j++ ) + for (j = 0; j < d_kin.ss_endmembers; j++) in >> d_kin.ss_scaling[j]; } in.clear(); // push back vector - m_kin.push_back ( d_kin ); - } // subkeyword found + m_kin.push_back(d_kin); + } // subkeyword found } // End of looping over all the key words----------- return position; @@ -2938,26 +2955,26 @@ ios::pos_type REACT_GEM::Read ( std::ifstream* gem_file ) * kg44 30.07.2009 * in: node temp: temperature */ -int REACT_GEM::CalcReactionRate ( long in, double temp, TNode* m_Node ) +int REACT_GEM::CalcReactionRate(long in, double temp, TNode* m_Node) { - int idx = 0,i,ii; - long j,k; - double rrn = 0.0, rrb = 0.0,rra = 0.0, sa = 0.0; - double R = 8.31451070; // molar gas konstant [J K-1 mol-1] - double aa = 1.0,ab = 1.0,ac = 1.0; // activity products ...species are input from material file - double sactivity; // dummy variable for extracting activities + int idx = 0, i, ii; + long j, k; + double rrn = 0.0, rrb = 0.0, rra = 0.0, sa = 0.0; + double R = 8.31451070; // molar gas konstant [J K-1 mol-1] + double aa = 1.0, ab = 1.0, ac = 1.0; // activity products ...species are input from material file + double sactivity; // dummy variable for extracting activities const char* species; - DATACH* dCH; //pointer to DATACH + DATACH* dCH; // pointer to DATACH DATABR* dBR; // Getting direct access to DataCH structure in GEMIPM2K memory dCH = m_Node->pCSD(); - if ( !dCH ) + if (!dCH) return 0; // Getting direct access to work node DATABR structure which // exchanges data between GEMIPM and FMT parts dBR = m_Node->pCNode(); - if ( !dBR ) + if (!dBR) return 0; /** int kinetic_model; // only 1 = GEMS implemented right now @@ -2972,16 +2989,18 @@ int REACT_GEM::CalcReactionRate ( long in, double temp, TNode* m_Node ) */ - // initialize in the first time step some variables...currently only necessary for kinetic mocel 4 (implementation a la crunch) + // initialize in the first time step some variables...currently only necessary for kinetic mocel 4 (implementation a + // la crunch) if (aktueller_zeitschritt < 1) { - if ( m_porosity_initial[in] < min_possible_porosity ) - m_porosity_initial[in] = m_porosity[in]; //make sure m_porosity_initial is not zero! ...does not work properly with RESTART!!!!! - if ( m_porosity_initial[in] < min_possible_porosity ) - m_porosity_initial[in] = m_porosity[in]; // secondary mineral ...see Cochepin et al 2008 + if (m_porosity_initial[in] < min_possible_porosity) + m_porosity_initial[in] = m_porosity[in]; // make sure m_porosity_initial is not zero! ...does not work + // properly with RESTART!!!!! + if (m_porosity_initial[in] < min_possible_porosity) + m_porosity_initial[in] = m_porosity[in]; // secondary mineral ...see Cochepin et al 2008 for (j = 0; j < nPH; j++) { - m_volumes_initial[in * nPH + j] = m_Node->Ph_Volume ( j ); + m_volumes_initial[in * nPH + j] = m_Node->Ph_Volume(j); // secondary mineral ...see Cochepin et al 2008 if (m_volumes_initial[in * nPH + j] <= 0.0) m_volumes_initial[in * nPH + j] = 0.01; @@ -2991,11 +3010,11 @@ int REACT_GEM::CalcReactionRate ( long in, double temp, TNode* m_Node ) // loop over all kinetic vectors and do for the defined phases and get rate for each phase ... // this algorithm assumes that we have correct ordering of phases and components that belong into the phase - for ( ii = 0; ii < ( int ) m_kin.size(); ii++ ) + for (ii = 0; ii < (int)m_kin.size(); ii++) { k = m_kin[ii].phase_number; - if ( m_kin[ii].kinetic_model > 0 ) // do it only if kinetic model is defined take model + if (m_kin[ii].kinetic_model > 0) // do it only if kinetic model is defined take model // kinetic_model==1 dissolution+precipitation kinetics // kinetic_model==2 only dissolution (no precipitation)aktueller // kinetic_mocel==3 only precipitation (no dissolution) @@ -3004,107 +3023,98 @@ int REACT_GEM::CalcReactionRate ( long in, double temp, TNode* m_Node ) omega_phase[in * nPH + k] = 0.0; dmdt[in * nPH + k] = 0.0; - if ( m_kin[ii].kinetic_model == 5 ) // special treatment of solid solution phases with e.g. vanselow convention + if (m_kin[ii].kinetic_model + == 5) // special treatment of solid solution phases with e.g. vanselow convention { - for ( j = m_kin[ii].dc_counter; - j < m_kin[ii].dc_counter + dCH->nDCinPH[k]; j++ ) + for (j = m_kin[ii].dc_counter; j < m_kin[ii].dc_counter + dCH->nDCinPH[k]; j++) // do not include surface complexation species! - if ( !( dCH->ccDC[j] == '0' ) && - !( dCH->ccDC[j] == 'X' ) && - !( dCH->ccDC[j] == 'Y' ) && - !( dCH->ccDC[j] == 'Z' ) ) + if (!(dCH->ccDC[j] == '0') && !(dCH->ccDC[j] == 'X') && !(dCH->ccDC[j] == 'Y') + && !(dCH->ccDC[j] == 'Z')) { // we need this later for solid solutions.... - omega_components[in * nDC + j] = m_Node->DC_a ( j ); + omega_components[in * nDC + j] = m_Node->DC_a(j); // loop over all components of the phase - omega_phase[in * nPH + k] += m_Node->DC_a ( j ); - - mol_phase[in * nPH + - k] += - ( m_xDC[in * nDC + - j] * - m_kin[ii].ss_scaling[j - - m_kin[ii].dc_counter] ); - // cout << "Debug kin omega phase "<< omega_phase[in*nPH+k] << " fraction component " << omega_components[in*nDC+j] << " mol phase " << mol_phase[in*nPH+k] << "\n"; // debug + omega_phase[in * nPH + k] += m_Node->DC_a(j); + + mol_phase[in * nPH + k] + += (m_xDC[in * nDC + j] * m_kin[ii].ss_scaling[j - m_kin[ii].dc_counter]); + // cout << "Debug kin omega phase "<< omega_phase[in*nPH+k] << " fraction component " << + // omega_components[in*nDC+j] << " mol phase " << mol_phase[in*nPH+k] << "\n"; // debug } } - else // normal behabviour for single component phases and SS which do have all the same endmember characteristics + else // normal behabviour for single component phases and SS which do have all the same endmember + // characteristics { - for ( j = m_kin[ii].dc_counter; - j < m_kin[ii].dc_counter + dCH->nDCinPH[k]; j++ ) + for (j = m_kin[ii].dc_counter; j < m_kin[ii].dc_counter + dCH->nDCinPH[k]; j++) // do not include surface complexation species! - if ( !( dCH->ccDC[j] == '0' ) && - !( dCH->ccDC[j] == 'X' ) && - !( dCH->ccDC[j] == 'Y' ) && - !( dCH->ccDC[j] == 'Z' ) ) + if (!(dCH->ccDC[j] == '0') && !(dCH->ccDC[j] == 'X') && !(dCH->ccDC[j] == 'Y') + && !(dCH->ccDC[j] == 'Z')) { - // omega_phase[k] += CalcSaturationIndex ( j, in,tempC,press ); // loop over all components of the phase + // omega_phase[k] += CalcSaturationIndex ( j, in,tempC,press ); // loop over all + // components of the phase // we need this later for solid solutions.... - omega_components[in * nDC + j] = m_Node->DC_a ( j ); + omega_components[in * nDC + j] = m_Node->DC_a(j); // loop over all components of the phase - omega_phase[in * nPH + k] += m_Node->DC_a ( j ); + omega_phase[in * nPH + k] += m_Node->DC_a(j); mol_phase[in * nPH + k] += m_xDC[in * nDC + j]; - // if (omega_phase[in*nPH+k] >1e6) cout << "Debug kin omega phase "<< omega_phase[in*nPH+k] << " fraction component " << omega_components[in*nDC+j] << " mol phase " << mol_phase[in*nPH+k] << "\n"; // debug + // if (omega_phase[in*nPH+k] >1e6) cout << "Debug kin omega phase "<< omega_phase[in*nPH+k] << " + // fraction component " << omega_components[in*nDC+j] << " mol phase " << mol_phase[in*nPH+k] + // << "\n"; // debug } } // cout << omega_phase[k] << " " << mol_phase[k] << "\n"; // debug - sa = REACT_GEM::SurfaceAreaPh ( ii,in,m_Node); // value for surface area in m^2...(specific surface area multiplied with volume of the phase) - if ( m_kin[ii].kinetic_model == 4 ) // in the next part we try to mimic Crunchflow (at least partially)..could be also done in CalcLimits if this makes the code easier to read + sa = REACT_GEM::SurfaceAreaPh( + ii, in, + m_Node); // value for surface area in m^2...(specific surface area multiplied with volume of the phase) + if (m_kin[ii].kinetic_model == 4) // in the next part we try to mimic Crunchflow (at least partially)..could + // be also done in CalcLimits if this makes the code easier to read { - if ( omega_phase[in * nPH + k] < 1.0 ) // this is the dissolution case + if (omega_phase[in * nPH + k] < 1.0) // this is the dissolution case - sa *= pow ( m_porosity[in] / m_porosity_initial[in] * m_Node->Ph_Volume( - k) / m_volumes_initial[in * nPH + k], - 0.66666666667 ); + sa *= pow(m_porosity[in] / m_porosity_initial[in] * m_Node->Ph_Volume(k) + / m_volumes_initial[in * nPH + k], + 0.66666666667); - else if ( omega_phase[in * nPH + k] > 1.0 ) // this is the precipitation case - - - sa *= pow ( m_porosity[in] / m_porosity_initial[in], - 0.66666666667 ); + else if (omega_phase[in * nPH + k] > 1.0) // this is the precipitation case + sa *= pow(m_porosity[in] / m_porosity_initial[in], 0.66666666667); } aa = 1.0; ab = 1.0; - ac = 1.0; // reset values for each phase! - for ( i = 0; i < m_kin[ii].n_activities; i++ ) + ac = 1.0; // reset values for each phase! + for (i = 0; i < m_kin[ii].n_activities; i++) { species = m_kin[ii].active_species[i].c_str(); // loop over all the names in the list - idx = m_Node->DC_name_to_xCH ( species ); - if ( idx < 0 ) + idx = m_Node->DC_name_to_xCH(species); + if (idx < 0) { - if ( m_porosity_initial[in] < min_possible_porosity ) - m_porosity_initial[in] = m_porosity[in]; //make sure m_porosity_initial is not zero! ...does not work properly with RESTART!!!!! - if ( m_porosity_initial[in] < min_possible_porosity ) + if (m_porosity_initial[in] < min_possible_porosity) + m_porosity_initial[in] = m_porosity[in]; // make sure m_porosity_initial is not zero! ...does + // not work properly with RESTART!!!!! + if (m_porosity_initial[in] < min_possible_porosity) m_porosity_initial[in] = min_possible_porosity; - cout << "failed CalcReactionRate: no DC-name " << - m_kin[ii].active_species[i] << " found" << "\n"; + cout << "failed CalcReactionRate: no DC-name " << m_kin[ii].active_species[i] << " found" + << "\n"; #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - MPI_Finalize(); //make sure MPI exits + MPI_Finalize(); // make sure MPI exits #endif - exit ( 1 ); + exit(1); } else { // cout << "activities " <DC_a ( idx ); // extract activities (not activity coefficients!) + sactivity = m_Node->DC_a(idx); // extract activities (not activity coefficients!) // cout << "Activity " << sactivity << pow(10.0,sactivity)<< "\n"; - aa *= - pow ( sactivity, - m_kin[ii].kinetic_parameters[12 + i] ); - ab *= - pow ( sactivity, - m_kin[ii].kinetic_parameters[13 + i] ); - ac *= - pow ( sactivity, - m_kin[ii].kinetic_parameters[14 + i] ); + aa *= pow(sactivity, m_kin[ii].kinetic_parameters[12 + i]); + ab *= pow(sactivity, m_kin[ii].kinetic_parameters[13 + i]); + ac *= pow(sactivity, m_kin[ii].kinetic_parameters[14 + i]); // *Y_m, // Molalities of aqueous species and sorbates [0:Ls-1] // *Y_la, // log activity of DC in multi-component phases (mju-mji0) [0:Ls-1] // *Y_w, // Mass concentrations of DC in multi-component phases,%(ppm)[Ls] @@ -3113,67 +3123,41 @@ int REACT_GEM::CalcReactionRate ( long in, double temp, TNode* m_Node ) } // cout << "activities " < 1.0 ) ) + dmdt[in * nPH + k] = -1.0 * sa * (pow(10.0, m_kin[ii].kinetic_parameters[3]) * rra + + pow(10.0, m_kin[ii].kinetic_parameters[4]) * rrn + + pow(10.0, m_kin[ii].kinetic_parameters[5]) * rrb); + + // test for NaN!! ---seems necessary as sometimes rra, rrn, rrb get Inf! ---seems enough to test the upper + // limit---this test does not resolve the real problem ;-)...probably pow(0.0,0.0) for rra,rrn,rrb ? + if (!(dmdt[in * nPH + k] <= 1.0) && !(dmdt[in * nPH + k] > 1.0)) { - cout << "failed " << m_kin[ii].phase_name << "at node " << in << - " dmdt " << dmdt << " is NaN " << " sa " << sa << " rra " << - rra << - " rrn " << rrn << " rrb " << rrb << "\n"; - cout << "mol_phase " << - mol_phase[in * nPH + - k] << " m_gam " << m_gam[idx] << " dmdt " << - dmdt[in * nPH + - k] << " omegaPhase " << - omega_phase[in * nPH + k] << "\n"; + cout << "failed " << m_kin[ii].phase_name << "at node " << in << " dmdt " << dmdt << " is NaN " + << " sa " << sa << " rra " << rra << " rrn " << rrn << " rrb " << rrb << "\n"; + cout << "mol_phase " << mol_phase[in * nPH + k] << " m_gam " << m_gam[idx] << " dmdt " + << dmdt[in * nPH + k] << " omegaPhase " << omega_phase[in * nPH + k] << "\n"; dmdt[in * nPH + k] = 0.0; // no change! } // calculate max kinetic time step - if ( fabs(dmdt[in * nPH + k]) > 0.0 && fabs(m_xDC[in * nDC + j]) > 0.0) + if (fabs(dmdt[in * nPH + k]) > 0.0 && fabs(m_xDC[in * nDC + j]) > 0.0) { rwmutex.lock(); // - max_kinetic_timestep = - min(max_kinetic_timestep, - fabs(m_xDC[in * nDC + j] / dmdt[in * nPH + k])); + max_kinetic_timestep = min(max_kinetic_timestep, fabs(m_xDC[in * nDC + j] / dmdt[in * nPH + k])); rwmutex.unlock(); // avoid mutual exclusion in the MPI version } - } //end if for kinetic model >1 + } // end if for kinetic model >1 } return 1; @@ -3183,51 +3167,54 @@ int REACT_GEM::CalcReactionRate ( long in, double temp, TNode* m_Node ) * REACT_GEM::CalcLimitsInitial ( long in ) * This is part of the OGS-GEMS kinetic implementation. It should be called during initialization phase, when * no information from the previous timestep is available. All kinetically controlled phases are set to their - * initial values by assigning dll (lower limit) and dul (upper limit) to the xDC values from a restart file or from IC files (in + * initial values by assigning dll (lower limit) and dul (upper limit) to the xDC values from a restart file or from IC + files (in * case transport is done with full speciation). - * In case the simulation starts and no xDC restart values are available, one should create such a restart file e.g. by conducting a - * a equilibrium simulation with one time-step and - if necessary - adjucst the values for the kinetically controlled phases e.g. + * In case the simulation starts and no xDC restart values are available, one should create such a restart file e.g. by + conducting a + * a equilibrium simulation with one time-step and - if necessary - adjucst the values for the kinetically controlled + phases e.g. * with an editor or by scripts. */ -int REACT_GEM::CalcLimitsInitial ( long in, TNode* m_Node) +int REACT_GEM::CalcLimitsInitial(long in, TNode* m_Node) { - long ii,k,j; - DATACH* dCH; //pointer to DATACH + long ii, k, j; + DATACH* dCH; // pointer to DATACH DATABR* dBR; // Getting direct access to DataCH structure in GEMIPM2K memory dCH = m_Node->pCSD(); - if ( !dCH ) + if (!dCH) return 0; // Getting direct access to work node DATABR structure which // exchanges data between GEMIPM and FMT parts dBR = m_Node->pCNode(); - if ( !dBR ) + if (!dBR) return 0; - for ( j = 0; j < nDC; j++ ) + for (j = 0; j < nDC; j++) { - m_dll[in * nDC + j] = 0.0; // set to zero - m_dul[in * nDC + j] = 1.0e+10; // very high number + m_dll[in * nDC + j] = 0.0; // set to zero + m_dul[in * nDC + j] = 1.0e+10; // very high number } - if ( ( m_flow_pcs->GetRestartFlag() >= 2 ) ) // we test if restart flag is set....if not this will not work, as x_dc might be not correct + if ((m_flow_pcs->GetRestartFlag() + >= 2)) // we test if restart flag is set....if not this will not work, as x_dc might be not correct { - for ( ii = 0; ii < ( int ) m_kin.size(); ii++ ) + for (ii = 0; ii < (int)m_kin.size(); ii++) { k = m_kin[ii].phase_number; - if ( m_kin[ii].kinetic_model > 0 ) // do it only if kinetic model is defined take model + if (m_kin[ii].kinetic_model > 0) // do it only if kinetic model is defined take model // kinetic_model==1 dissolution+precipitation kinetics // kinetic_model==2 only dissolution (no precipitation) // kinetic_mocel==3 only precipitation (no dissolution) - for ( j = m_kin[ii].dc_counter; - j < m_kin[ii].dc_counter + dCH->nDCinPH[k]; j++ ) + for (j = m_kin[ii].dc_counter; j < m_kin[ii].dc_counter + dCH->nDCinPH[k]; j++) { - if ( ( dCH->ccDC[j] == '0' ) || ( dCH->ccDC[j] == 'X' ) || - ( dCH->ccDC[j] == 'Y' ) || ( dCH->ccDC[j] == 'Z' ) ) + if ((dCH->ccDC[j] == '0') || (dCH->ccDC[j] == 'X') || (dCH->ccDC[j] == 'Y') + || (dCH->ccDC[j] == 'Z')) { m_dll[in * nDC + j] = 0.0; // set to zero m_dul[in * nDC + j] = 1.0e+10; // very high number @@ -3236,16 +3223,16 @@ int REACT_GEM::CalcLimitsInitial ( long in, TNode* m_Node) { m_dul[in * nDC + j] = m_xDC[in * nDC + j]; m_dll[in * nDC + j] = m_xDC[in * nDC + j]; - if ( m_dll[in * nDC + j] < 0.0 ) + if (m_dll[in * nDC + j] < 0.0) m_dll[in * nDC + j] = 0.0; // no negative masses allowed - if ( m_dul[in * nDC + j] < 0.0 ) + if (m_dul[in * nDC + j] < 0.0) m_dul[in * nDC + j] = 0.0; - if ( m_dll[in * nDC + j] > m_dul[in * nDC + j] ) + if (m_dll[in * nDC + j] > m_dul[in * nDC + j]) m_dll[in * nDC + j] = m_dul[in * nDC + j]; } } - //end kinetic model - } // end loop over phases + // end kinetic model + } // end loop over phases return 1; // end restart } return 1; @@ -3254,75 +3241,71 @@ int REACT_GEM::CalcLimitsInitial ( long in, TNode* m_Node) /** In this function we calculate the actual upper and lower metastability constraints for the GEMS solution * from the phase reaction rates (calculated at the previous time step) */ -int REACT_GEM::CalcLimits ( long in, TNode* m_Node) +int REACT_GEM::CalcLimits(long in, TNode* m_Node) { double dummy; - long ii,k,j; - DATACH* dCH; //pointer to DATACH + long ii, k, j; + DATACH* dCH; // pointer to DATACH DATABR* dBR; // Getting direct access to DataCH structure in GEMIPM2K memory dCH = m_Node->pCSD(); - if ( !dCH ) + if (!dCH) return 0; // Getting direct access to work node DATABR structure which // exchanges data between GEMIPM and FMT parts dBR = m_Node->pCNode(); - if ( !dBR ) + if (!dBR) return 0; - for ( j = 0; j < nDC; j++ ) + for (j = 0; j < nDC; j++) { - m_dll[in * nDC + j] = 0.0; // set to zero - m_dul[in * nDC + j] = 1.0e+10; // very high number + m_dll[in * nDC + j] = 0.0; // set to zero + m_dul[in * nDC + j] = 1.0e+10; // very high number } - for ( ii = 0; ii < ( int ) m_kin.size(); ii++ ) + for (ii = 0; ii < (int)m_kin.size(); ii++) { k = m_kin[ii].phase_number; // cout << " kinetics phase " << ii << " " << m_kin[ii].kinetic_model << "\n"; - if ( m_kin[ii].kinetic_model > 0 && m_kin[ii].kinetic_model < 6 ) // do it only if kinetic model is defined take model + if (m_kin[ii].kinetic_model > 0 + && m_kin[ii].kinetic_model < 6) // do it only if kinetic model is defined take model // kinetic_model==1 dissolution+precipitation kinetics // kinetic_model==2 only dissolution (no precipitation) // kinetic_mocel==3 only precipitation (no dissolution) - for ( j = m_kin[ii].dc_counter; j < m_kin[ii].dc_counter + dCH->nDCinPH[k]; - j++ ) + for (j = m_kin[ii].dc_counter; j < m_kin[ii].dc_counter + dCH->nDCinPH[k]; j++) { - // cout << "Kin debug " << in << " mol amount species " << m_xDC[in*nDC+j] << " saturation phase " << omega_phase[in*nPH+k] << " saturation species" << omega_components[in*nDC+j] << " mol fraction now" << (m_xDC[in*nDC+j]/mol_phase[in*nPH+k] )<< "\n"; - // surface complexation species are not kinetically controlled -- 0 is old way...X is new way in DCH files - if ( ( dCH->ccDC[j] == '0' ) || ( dCH->ccDC[j] == 'X' ) || - ( dCH->ccDC[j] == 'Y' ) || ( dCH->ccDC[j] == 'Z' ) ) + // cout << "Kin debug " << in << " mol amount species " << m_xDC[in*nDC+j] << " saturation phase " + // << omega_phase[in*nPH+k] << " saturation species" << omega_components[in*nDC+j] << " mol fraction + // now" << (m_xDC[in*nDC+j]/mol_phase[in*nPH+k] )<< "\n"; + // surface complexation species are not kinetically controlled -- 0 is old way...X is new way in DCH + // files + if ((dCH->ccDC[j] == '0') || (dCH->ccDC[j] == 'X') || (dCH->ccDC[j] == 'Y') || (dCH->ccDC[j] == 'Z')) { m_dll[in * nDC + j] = 0.0; // set to zero m_dul[in * nDC + j] = 1.0e+10; // very high number } else { - // cout << "Kin debug SS mol phase " << mol_phase[in*nPH+k] << " dmdt " << dmdt[in*nPH+k]*dt << " omega comp " < 1.0e10) dummy = 1.0e10; - if ( !( dummy <= 1.0 ) && !( dummy > 1.0 ) ) + if (!(dummy <= 1.0) && !(dummy > 1.0)) { // no change! m_dul[in * nDC + j] = m_xDC[in * nDC + j]; m_dll[in * nDC + j] = m_xDC[in * nDC + j]; } - else if ( m_xDC[in * nDC + j] > dummy ) // This is the dissolution case + else if (m_xDC[in * nDC + j] > dummy) // This is the dissolution case { m_dul[in * nDC + j] = m_xDC[in * nDC + j]; m_dll[in * nDC + j] = dummy; @@ -3335,169 +3318,125 @@ int REACT_GEM::CalcLimits ( long in, TNode* m_Node) // do some corrections // kinetic_model==2 only dissolution is kontrolled (free precipitation) // kinetic_mocel==3 only precipitation is copntroleld (free dissolution) - if ( ( m_kin[ii].kinetic_model == 2 ) && - ( m_dul[in * nDC + j] > m_xDC[in * nDC + j] ) ) + if ((m_kin[ii].kinetic_model == 2) && (m_dul[in * nDC + j] > m_xDC[in * nDC + j])) m_dul[in * nDC + j] = 1.0e+10; // m_dul[in*nDC+j]= m_xDC[in*nDC+j]; - if ( ( m_kin[ii].kinetic_model == 3 ) && - ( m_dll[in * nDC + j] < m_xDC[in * nDC + j] ) ) + if ((m_kin[ii].kinetic_model == 3) && (m_dll[in * nDC + j] < m_xDC[in * nDC + j])) m_dll[in * nDC + j] = 0.0; // m_dll[in*nDC+j]= m_xDC[in*nDC+j]; - if ( ( m_xDC[in * nDC + j] < 1.0e-6 ) && - ( omega_phase[in * nPH + k] >= 1.0001 ) && - ( m_dul[in * nDC + j] < 1.0e-6 ) ) + if ((m_xDC[in * nDC + j] < 1.0e-6) && (omega_phase[in * nPH + k] >= 1.0001) + && (m_dul[in * nDC + j] < 1.0e-6)) { - m_dul[in * nDC + j] = 1.0e-6; // allow some kind of precipitation...based on saturation index for component value...here we set 10-6 mol per m^3 ..which is maybe 10-10 per litre ...? + m_dul[in * nDC + j] = 1.0e-6; // allow some kind of precipitation...based on saturation index + // for component value...here we set 10-6 mol per m^3 ..which is + // maybe 10-10 per litre ...? m_dll[in * nDC + j] = 0.0; } - if ( m_dll[in * nDC + j] > m_dul[in * nDC + j] ) - m_dll[in * nDC + j] = m_dul[in * nDC + j]; // dll should be always lower than dul + if (m_dll[in * nDC + j] > m_dul[in * nDC + j]) + m_dll[in * nDC + j] = m_dul[in * nDC + j]; // dll should be always lower than dul // no negative masses allowed - if ( m_dll[in * nDC + j] < 0.0 ) + if (m_dll[in * nDC + j] < 0.0) m_dll[in * nDC + j] = 0.0; // no negative masses allowed..give some freedom - if ( m_dul[in * nDC + j] <= 0.0 ) + if (m_dul[in * nDC + j] <= 0.0) { m_dul[in * nDC + j] = 1.0e-6; m_dll[in * nDC + j] = 0.0; } } - // cout << "Kin debug for component no. " << j << " at node " << in << " m_xDC " << m_xDC[in*nDC+j] << " m_dll, mdul " << m_dll[in*nDC+j] << " " << m_dul[in*nDC+j] << " diff " << m_dul[in*nDC+j]- m_dll[in*nDC+j] << "\n"; - // if ((fabs((m_dul[in*nDC+j]- m_dll[in*nDC+j]))>0.0)) cout << "Kinetics for component no. " << j << " at node " << in << " m_xDC " << m_xDC[in*nDC+j] << " m_dll, mdul " << m_dll[in*nDC+j] << " " << m_dul[in*nDC+j] << " diff " << m_dul[in*nDC+j]- m_dll[in*nDC+j] << "\n"; // give some debug output for kinetics + // cout << "Kin debug for component no. " << j << " at node " << in << " m_xDC " << m_xDC[in*nDC+j] << + // " m_dll, mdul " << m_dll[in*nDC+j] << " " << m_dul[in*nDC+j] << " diff " << m_dul[in*nDC+j]- + // m_dll[in*nDC+j] << "\n"; + // if ((fabs((m_dul[in*nDC+j]- m_dll[in*nDC+j]))>0.0)) cout << "Kinetics for component no. " + // << j << " at node " << in << " m_xDC " << m_xDC[in*nDC+j] << " m_dll, mdul " << + // m_dll[in*nDC+j] << " " << m_dul[in*nDC+j] << " diff " << m_dul[in*nDC+j]- m_dll[in*nDC+j] + // << "\n"; // give some debug output for kinetics } - } // end loop over phases + } // end loop over phases return 1; } // simplest case....scaling with a specific surface area per volume mineral -// phasenr: index for phase compnr: index of component which belongs to the phase and for which a specific surface area is defined -double REACT_GEM::SurfaceAreaPh ( long kin_phasenr,long in, TNode* m_Node ) +// phasenr: index for phase compnr: index of component which belongs to the phase and for which a specific surface area +// is defined +double REACT_GEM::SurfaceAreaPh(long kin_phasenr, long in, TNode* m_Node) { double surf_area = 0.0; // now it is volume of the phase ..with respect to the unit volume in m^3 - surf_area = m_Node->Ph_Volume ( m_kin[kin_phasenr].phase_number ); + surf_area = m_Node->Ph_Volume(m_kin[kin_phasenr].phase_number); - if ( m_kin[kin_phasenr].surface_model == 1 ) + if (m_kin[kin_phasenr].surface_model == 1) // multiplication with specific surface area gives area surf_area *= m_kin[kin_phasenr].surface_area[0]; - else if ( m_kin[kin_phasenr].surface_model == 2 ) + else if (m_kin[kin_phasenr].surface_model == 2) // constant surface area surf_area = m_kin[kin_phasenr].surface_area[0]; - else if ( m_kin[kin_phasenr].surface_model == 3 ) - surf_area *= m_kin[kin_phasenr].surface_area[0] / m_porosity[in]; // multiplication with specific surface area and division by porosity - else if ( m_kin[kin_phasenr].surface_model == 4 ) - surf_area = m_kin[kin_phasenr].surface_area[0] * m_porosity[in]; // multiplication of specific surface area and porosity + else if (m_kin[kin_phasenr].surface_model == 3) + surf_area *= m_kin[kin_phasenr].surface_area[0] + / m_porosity[in]; // multiplication with specific surface area and division by porosity + else if (m_kin[kin_phasenr].surface_model == 4) + surf_area = m_kin[kin_phasenr].surface_area[0] + * m_porosity[in]; // multiplication of specific surface area and porosity else - surf_area = 0.0; // no kinetics...safe solution + surf_area = 0.0; // no kinetics...safe solution - // cout << "phase " << kin_phasenr << " area default " << m_kin[kin_phasenr].surface_area[0] << " model " << m_kin[kin_phasenr].surface_model << " surface area: " << surf_area << "\n"; + // cout << "phase " << kin_phasenr << " area default " << m_kin[kin_phasenr].surface_area[0] << " model " << + // m_kin[kin_phasenr].surface_model << " surface area: " << surf_area << "\n"; return surf_area; } #if defined(USE_MPI_GEMS) -void REACT_GEM::GetGEMResult_MPI ( void ) +void REACT_GEM::GetGEMResult_MPI(void) { // Now gather the calculated values------------------------------------------------------------------------------ - MPI_Allreduce ( m_NodeHandle_buff, m_NodeHandle, nNodes, MPI_LONG, MPI_SUM, - MPI_COMM_WORLD ); - MPI_Allreduce ( m_NodeStatusCH_buff, - m_NodeStatusCH, - nNodes, - MPI_LONG, - MPI_SUM, - MPI_COMM_WORLD ); - MPI_Allreduce ( m_IterDone_buff, m_IterDone, nNodes, MPI_LONG, MPI_SUM, MPI_COMM_WORLD ); - - MPI_Allreduce ( m_Vs_buff, m_Vs, nNodes, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD ); - MPI_Allreduce ( m_Ms_buff, m_Ms, nNodes, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD ); - MPI_Allreduce ( m_Gs_buff, m_Gs, nNodes, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD ); - MPI_Allreduce ( m_Hs_buff, m_Hs, nNodes, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD ); - MPI_Allreduce ( m_IC_buff, m_IC, nNodes, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD ); - MPI_Allreduce ( m_pH_buff, m_pH, nNodes, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD ); - MPI_Allreduce ( m_pe_buff, m_pe, nNodes, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD ); - MPI_Allreduce ( m_Eh_buff, m_Eh, nNodes, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD ); - MPI_Allreduce ( m_porosity_buff, m_porosity, nNodes, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD ); - MPI_Allreduce ( m_fluid_volume_buff, - m_fluid_volume, - nNodes, - MPI_DOUBLE, - MPI_SUM, - MPI_COMM_WORLD ); - MPI_Allreduce ( m_fluid_density_buff, - m_fluid_density, - nNodes, - MPI_DOUBLE, - MPI_SUM, - MPI_COMM_WORLD ); - MPI_Allreduce ( m_gas_volume_buff, m_gas_volume, nNodes, MPI_DOUBLE, MPI_SUM, - MPI_COMM_WORLD ); - MPI_Allreduce ( m_excess_water_buff, - m_excess_water, - nNodes, - MPI_DOUBLE, - MPI_SUM, - MPI_COMM_WORLD ); - MPI_Allreduce ( m_excess_gas_buff, m_excess_gas, nNodes, MPI_DOUBLE, MPI_SUM, - MPI_COMM_WORLD ); - MPI_Allreduce ( m_bPS_buff, m_bPS, nNodes * nIC * nPS, MPI_DOUBLE, MPI_SUM, - MPI_COMM_WORLD ); - - MPI_Allreduce ( m_bIC_buff, m_bIC, nNodes * nIC, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD ); - MPI_Allreduce ( m_bIC_dummy_buff, - m_bIC_dummy, - nNodes * nIC, - MPI_DOUBLE, - MPI_SUM, - MPI_COMM_WORLD ); - MPI_Allreduce ( m_soluteB_buff, m_soluteB, nNodes * nIC, MPI_DOUBLE, MPI_SUM, - MPI_COMM_WORLD ); - - MPI_Allreduce ( m_xDC_buff, m_xDC, nNodes * nDC, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD ); - - MPI_Allreduce ( m_dll_buff, m_dll, nNodes * nDC, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD ); - MPI_Allreduce ( m_dul_buff, m_dul, nNodes * nDC, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD ); - MPI_Allreduce ( m_aPH_buff, m_aPH, nNodes * nPH, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD ); - MPI_Allreduce ( m_xPH_buff, m_xPH, nNodes * nPH, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD ); - MPI_Allreduce ( m_xPA_buff, m_xPA, nNodes * nPS, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD ); - - MPI_Allreduce ( m_xDC_pts_buff, m_xDC_pts, nNodes * nDC, MPI_DOUBLE, MPI_SUM, - MPI_COMM_WORLD ); - MPI_Allreduce ( m_xDC_MT_delta_buff, - m_xDC_MT_delta, - nNodes * nDC, - MPI_DOUBLE, - MPI_SUM, - MPI_COMM_WORLD ); - MPI_Allreduce ( m_xDC_Chem_delta_buff, - m_xDC_Chem_delta, - nNodes * nDC, - MPI_DOUBLE, - MPI_SUM, - MPI_COMM_WORLD ); - MPI_Allreduce ( omega_phase_buff, - omega_phase, - nNodes * nPH, - MPI_DOUBLE, - MPI_SUM, - MPI_COMM_WORLD ); - MPI_Allreduce ( mol_phase_buff, mol_phase, nNodes * nPH, MPI_DOUBLE, MPI_SUM, - MPI_COMM_WORLD ); - - MPI_Allreduce ( dmdt_buff, dmdt, nNodes * nPH, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD ); - MPI_Allreduce ( omega_components_buff, - omega_components, - nNodes * nDC, - MPI_DOUBLE, - MPI_SUM, - MPI_COMM_WORLD ); + MPI_Allreduce(m_NodeHandle_buff, m_NodeHandle, nNodes, MPI_LONG, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(m_NodeStatusCH_buff, m_NodeStatusCH, nNodes, MPI_LONG, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(m_IterDone_buff, m_IterDone, nNodes, MPI_LONG, MPI_SUM, MPI_COMM_WORLD); + + MPI_Allreduce(m_Vs_buff, m_Vs, nNodes, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(m_Ms_buff, m_Ms, nNodes, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(m_Gs_buff, m_Gs, nNodes, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(m_Hs_buff, m_Hs, nNodes, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(m_IC_buff, m_IC, nNodes, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(m_pH_buff, m_pH, nNodes, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(m_pe_buff, m_pe, nNodes, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(m_Eh_buff, m_Eh, nNodes, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(m_porosity_buff, m_porosity, nNodes, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(m_fluid_volume_buff, m_fluid_volume, nNodes, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(m_fluid_density_buff, m_fluid_density, nNodes, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(m_gas_volume_buff, m_gas_volume, nNodes, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(m_excess_water_buff, m_excess_water, nNodes, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(m_excess_gas_buff, m_excess_gas, nNodes, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(m_bPS_buff, m_bPS, nNodes * nIC * nPS, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + + MPI_Allreduce(m_bIC_buff, m_bIC, nNodes * nIC, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(m_bIC_dummy_buff, m_bIC_dummy, nNodes * nIC, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(m_soluteB_buff, m_soluteB, nNodes * nIC, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + + MPI_Allreduce(m_xDC_buff, m_xDC, nNodes * nDC, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + + MPI_Allreduce(m_dll_buff, m_dll, nNodes * nDC, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(m_dul_buff, m_dul, nNodes * nDC, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(m_aPH_buff, m_aPH, nNodes * nPH, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(m_xPH_buff, m_xPH, nNodes * nPH, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(m_xPA_buff, m_xPA, nNodes * nPS, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + + MPI_Allreduce(m_xDC_pts_buff, m_xDC_pts, nNodes * nDC, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(m_xDC_MT_delta_buff, m_xDC_MT_delta, nNodes * nDC, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(m_xDC_Chem_delta_buff, m_xDC_Chem_delta, nNodes * nDC, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(omega_phase_buff, omega_phase, nNodes * nPH, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(mol_phase_buff, mol_phase, nNodes * nPH, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + + MPI_Allreduce(dmdt_buff, dmdt, nNodes * nPH, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(omega_components_buff, omega_components, nNodes * nDC, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); // -------------------------------------------------------------------------------------------------------------- } -void REACT_GEM::CleanMPIBuffer ( void ) +void REACT_GEM::CleanMPIBuffer(void) { - long in, ii,jj; - for ( in = 0; in < nNodes; in++ ) + long in, ii, jj; + for (in = 0; in < nNodes; in++) { m_IterDoneCumulative[in] += m_IterDone[in]; m_NodeHandle_buff[in] = 0; @@ -3520,48 +3459,46 @@ void REACT_GEM::CleanMPIBuffer ( void ) m_excess_water_buff[in] = 0.0; m_excess_gas_buff[in] = 0.0; - for ( ii = 0; ii < nIC; ii++ ) + for (ii = 0; ii < nIC; ii++) { - m_soluteB_buff[in * nIC + ii ] = 0.0; - m_bIC_buff[in * nIC + ii ] = 0.0; - m_bIC_dummy_buff [ in * nIC + ii ] = 0.0; + m_soluteB_buff[in * nIC + ii] = 0.0; + m_bIC_buff[in * nIC + ii] = 0.0; + m_bIC_dummy_buff[in * nIC + ii] = 0.0; } - for ( ii = 0; ii < nDC; ii++ ) + for (ii = 0; ii < nDC; ii++) { - m_xDC_buff[in * nDC + ii ] = 0.0; - m_dul_buff[in * nDC + ii ] = 0.0; - m_dll_buff[in * nDC + ii ] = 0.0; - m_xDC_pts_buff[in * nDC + ii ] = 0.0; - m_xDC_MT_delta_buff[in * nDC + ii ] = 0.0; - m_xDC_Chem_delta_buff[in * nDC + ii ] = 0.0; - omega_components_buff[in * nDC + ii ] = 0.0; + m_xDC_buff[in * nDC + ii] = 0.0; + m_dul_buff[in * nDC + ii] = 0.0; + m_dll_buff[in * nDC + ii] = 0.0; + m_xDC_pts_buff[in * nDC + ii] = 0.0; + m_xDC_MT_delta_buff[in * nDC + ii] = 0.0; + m_xDC_Chem_delta_buff[in * nDC + ii] = 0.0; + omega_components_buff[in * nDC + ii] = 0.0; } - for ( ii = 0; ii < nPH; ii++ ) + for (ii = 0; ii < nPH; ii++) { - m_xPH_buff[in * nPH + ii ] = 0.0; - m_aPH_buff[in * nPH + ii ] = 0.0; - omega_phase_buff[in * nPH + ii ] = 0.0; - mol_phase_buff[in * nPH + ii ] = 0.0; - dmdt_buff[in * nPH + ii ] = 0.0; + m_xPH_buff[in * nPH + ii] = 0.0; + m_aPH_buff[in * nPH + ii] = 0.0; + omega_phase_buff[in * nPH + ii] = 0.0; + mol_phase_buff[in * nPH + ii] = 0.0; + dmdt_buff[in * nPH + ii] = 0.0; } - for ( ii = 0; ii < nPS; ii++ ) - m_xPA_buff[in * nPS + ii ] = 0.0; - - for ( ii = 0; ii < nIC; ii++ ) - for ( int jj = 0; jj < nPS; jj++ ) - m_bPS_buff[in * ii * nPS + jj ] = 0.0; + for (ii = 0; ii < nPS; ii++) + m_xPA_buff[in * nPS + ii] = 0.0; + for (ii = 0; ii < nIC; ii++) + for (int jj = 0; jj < nPS; jj++) + m_bPS_buff[in * ii * nPS + jj] = 0.0; } - for ( in = 0; in < nElems; in++ ) + for (in = 0; in < nElems; in++) m_porosity_Elem_buff[in] = m_porosity_Elem[in]; - } -void REACT_GEM::CopyToMPIBuffer ( long in ) +void REACT_GEM::CopyToMPIBuffer(long in) { long ii; m_NodeHandle_buff[in] = m_NodeHandle[in]; @@ -3585,63 +3522,63 @@ void REACT_GEM::CopyToMPIBuffer ( long in ) m_excess_water_buff[in] = m_excess_water[in]; m_excess_gas_buff[in] = m_excess_gas[in]; - for ( ii = 0; ii < nIC; ii++ ) + for (ii = 0; ii < nIC; ii++) { - m_bIC_buff[in * nIC + ii ] = m_bIC[in * nIC + ii ]; - m_soluteB_buff[in * nIC + ii ] = m_soluteB[in * nIC + ii ]; + m_bIC_buff[in * nIC + ii] = m_bIC[in * nIC + ii]; + m_soluteB_buff[in * nIC + ii] = m_soluteB[in * nIC + ii]; - m_bIC_dummy_buff [ in * nIC + ii ] = m_bIC_dummy[ in * nIC + ii ]; + m_bIC_dummy_buff[in * nIC + ii] = m_bIC_dummy[in * nIC + ii]; } - for ( ii = 0; ii < nDC; ii++ ) + for (ii = 0; ii < nDC; ii++) { - m_xDC_buff[in * nDC + ii ] = m_xDC[in * nDC + ii ]; - m_dul_buff[in * nDC + ii ] = m_dul[in * nDC + ii ]; - m_dll_buff[in * nDC + ii ] = m_dll[in * nDC + ii ]; - m_xDC_pts_buff[in * nDC + ii ] = m_xDC_pts[in * nDC + ii ]; - m_xDC_MT_delta_buff[in * nDC + ii ] = m_xDC_MT_delta[in * nDC + ii ]; - m_xDC_Chem_delta_buff[in * nDC + ii ] = m_xDC_Chem_delta[in * nDC + ii ]; - omega_components_buff[in * nDC + ii ] = omega_components[in * nDC + ii ]; + m_xDC_buff[in * nDC + ii] = m_xDC[in * nDC + ii]; + m_dul_buff[in * nDC + ii] = m_dul[in * nDC + ii]; + m_dll_buff[in * nDC + ii] = m_dll[in * nDC + ii]; + m_xDC_pts_buff[in * nDC + ii] = m_xDC_pts[in * nDC + ii]; + m_xDC_MT_delta_buff[in * nDC + ii] = m_xDC_MT_delta[in * nDC + ii]; + m_xDC_Chem_delta_buff[in * nDC + ii] = m_xDC_Chem_delta[in * nDC + ii]; + omega_components_buff[in * nDC + ii] = omega_components[in * nDC + ii]; } - for ( ii = 0; ii < nPH; ii++ ) + for (ii = 0; ii < nPH; ii++) { - m_xPH_buff[in * nPH + ii ] = m_xPH[in * nPH + ii ]; - m_aPH_buff[in * nPH + ii ] = m_aPH[in * nPH + ii ]; - omega_phase_buff[in * nPH + ii ] = omega_phase[in * nPH + ii ]; - mol_phase_buff[in * nPH + ii ] = mol_phase[in * nPH + ii ]; - dmdt_buff[in * nPH + ii ] = dmdt[in * nPH + ii ]; + m_xPH_buff[in * nPH + ii] = m_xPH[in * nPH + ii]; + m_aPH_buff[in * nPH + ii] = m_aPH[in * nPH + ii]; + omega_phase_buff[in * nPH + ii] = omega_phase[in * nPH + ii]; + mol_phase_buff[in * nPH + ii] = mol_phase[in * nPH + ii]; + dmdt_buff[in * nPH + ii] = dmdt[in * nPH + ii]; } - for ( ii = 0; ii < nPS; ii++ ) - m_xPA_buff[in * nPS + ii ] = m_xPA[in * nPS + ii ]; - + for (ii = 0; ii < nPS; ii++) + m_xPA_buff[in * nPS + ii] = m_xPA[in * nPS + ii]; } -#endif // end MPI +#endif // end MPI /** GetNodePorosityValue(long node_Index): function coming from GEMS coupling...extract node based porosities..does only * work with GEMS coupling * georg.kosakowski@psi.ch 02.11.2009 * georg.kosakowski@psi.ch 22.02.2013 */ -double REACT_GEM::GetNodePorosityValue ( long node_Index ) +double REACT_GEM::GetNodePorosityValue(long node_Index) { - double node_poros = -1.0; //default value is negative...that should not happen + double node_poros = -1.0; // default value is negative...that should not happen node_poros = m_porosity[node_Index]; return node_poros; } -/** GetNodePorosityValueInitial(long node_Index): function coming from GEMS coupling...extract initial node based porosities..does only +/** GetNodePorosityValueInitial(long node_Index): function coming from GEMS coupling...extract initial node based + * porosities..does only * work with GEMS coupling * georg.kosakowski@psi.ch 02.11.2009 * georg.kosakowski@psi.ch 22.02.2013 */ -double REACT_GEM::GetNodePorosityValueInitial ( long node_Index ) +double REACT_GEM::GetNodePorosityValueInitial(long node_Index) { - double node_poros = -1.0; //default value is negative...that should not happen + double node_poros = -1.0; // default value is negative...that should not happen node_poros = m_porosity_initial[node_Index]; @@ -3652,23 +3589,23 @@ double REACT_GEM::GetNodePorosityValueInitial ( long node_Index ) // work with GEMS coupling a // georg.kosakowski@psi.ch 15.06.2012 -double REACT_GEM::GetNodeFluidDensityValue ( long node_Index ) +double REACT_GEM::GetNodeFluidDensityValue(long node_Index) { - double fluid_density = -1.0; //default value is negative...that should not happen + double fluid_density = -1.0; // default value is negative...that should not happen fluid_density = m_fluid_density[node_Index]; return fluid_density; } -//taken from rf_REACT_BRNS -int REACT_GEM::IsThisPointBCIfYesStoreValue ( long index, CRFProcess* m_pcs, double& value ) +// taken from rf_REACT_BRNS +int REACT_GEM::IsThisPointBCIfYesStoreValue(long index, CRFProcess* m_pcs, double& value) { - for ( long p = 0; p < ( int ) m_pcs->bc_node_value.size(); ++p ) - if ( index == m_pcs->bc_node_value[p]->msh_node_number ) + for (long p = 0; p < (int)m_pcs->bc_node_value.size(); ++p) + if (index == m_pcs->bc_node_value[p]->msh_node_number) { value = m_pcs->bc_node_value[p]->node_value; - return 1; // Yes, found it. + return 1; // Yes, found it. } return 0; @@ -3676,15 +3613,15 @@ int REACT_GEM::IsThisPointBCIfYesStoreValue ( long index, CRFProcess* m_pcs, dou int REACT_GEM::WriteReloadGem() { - long i,j; + long i, j; string rank_str; rank_str = "0"; -#if defined(USE_PETSC) //|| defined(other parallel libs)//03.3012. WW +#if defined(USE_PETSC) //|| defined(other parallel libs)//03.3012. WW int rank, msize; MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &msize); - stringstream ss (stringstream::in | stringstream::out); + stringstream ss(stringstream::in | stringstream::out); ss.clear(); ss.str(""); ss << rank; @@ -3696,59 +3633,59 @@ int REACT_GEM::WriteReloadGem() string m_file_namet = FileName + "_" + "time" + "_gem.asc"; #endif - ofstream ost ( m_file_namet.c_str(), ios::trunc | ios::out ); - if ( !ost.good() ) + ofstream ost(m_file_namet.c_str(), ios::trunc | ios::out); + if (!ost.good()) { cout << "Failure to open file: " << m_file_namet << "\n"; abort(); } - ost.precision ( 15 ); // 15 digits accuracy seems enough? more fields are filled up with random numbers! - ost.setf ( ios_base::scientific,ios_base::floatfield ); + ost.precision(15); // 15 digits accuracy seems enough? more fields are filled up with random numbers! + ost.setf(ios_base::scientific, ios_base::floatfield); ost << "time: " << aktuelle_zeit << "\n"; ost.close(); // node porosity ...necessary for restart // first test if m_poorosity exists (possible if no gem process exists) - if ( !m_porosity ) + if (!m_porosity) return 2; -#if defined(USE_PETSC) //|| defined(other parallel libs)//03.3012. WW +#if defined(USE_PETSC) //|| defined(other parallel libs)//03.3012. WW string m_file_name = FileName + "_" + "m_porosity" + "_gem_" + rank_str + ".asc"; #else string m_file_name = FileName + "_" + "m_porosity" + "_gem.asc"; #endif - ofstream os ( m_file_name.c_str(), ios::trunc | ios::out ); - if ( !os.good() ) + ofstream os(m_file_name.c_str(), ios::trunc | ios::out); + if (!os.good()) { cout << "Failure to open file: " << m_file_name << "\n"; abort(); } - os.precision ( 15 ); // 15 digits accuracy seems enough? more fields are filled up with random numbers! - os.setf ( ios_base::scientific,ios_base::floatfield ); + os.precision(15); // 15 digits accuracy seems enough? more fields are filled up with random numbers! + os.setf(ios_base::scientific, ios_base::floatfield); - for ( i = 0; i < nNodes; i++ ) + for (i = 0; i < nNodes; i++) { os << m_porosity[i] << " "; os << "\n"; } os.close(); // now write the fluid_volumes - if ( !m_fluid_volume ) + if (!m_fluid_volume) return 2; #if defined(USE_PETSC) string m_file_name2 = FileName + "_" + "m_fluid_volume" + "_gem_" + rank_str + ".asc"; #else string m_file_name2 = FileName + "_" + "m_fluid_volume" + "_gem.asc"; #endif - ofstream os2 ( m_file_name2.c_str(), ios::trunc | ios::out ); - if ( !os2.good() ) + ofstream os2(m_file_name2.c_str(), ios::trunc | ios::out); + if (!os2.good()) { cout << "Failure to open file: " << m_file_name2 << "\n"; abort(); } - os2.precision ( 15 ); // 15 digits accuracy seems enough? more fields are filled up with random numbers! - os2.setf ( ios_base::scientific,ios_base::floatfield ); + os2.precision(15); // 15 digits accuracy seems enough? more fields are filled up with random numbers! + os2.setf(ios_base::scientific, ios_base::floatfield); - for ( i = 0; i < nNodes; i++ ) + for (i = 0; i < nNodes; i++) { os2 << m_fluid_volume[i] << " "; os2 << "\n"; @@ -3756,54 +3693,51 @@ int REACT_GEM::WriteReloadGem() os2.close(); // write b vector - if ( !m_bIC ) + if (!m_bIC) return 2; #if defined(USE_PETSC) string m_file_name3 = FileName + "_" + "m_bIC" + "_gem_" + rank_str + ".asc"; #else string m_file_name3 = FileName + "_" + "m_bIC" + "_gem.asc"; #endif - ofstream os3 ( m_file_name3.c_str(), ios::trunc | ios::out ); - if ( !os3.good() ) + ofstream os3(m_file_name3.c_str(), ios::trunc | ios::out); + if (!os3.good()) { cout << "Failure to open file: " << m_file_name3 << "\n"; abort(); } - os3.precision ( 15 ); // 15 digits accuracy seems enough? more fields are filled up with random numbers! - os3.setf ( ios_base::scientific,ios_base::floatfield ); + os3.precision(15); // 15 digits accuracy seems enough? more fields are filled up with random numbers! + os3.setf(ios_base::scientific, ios_base::floatfield); - for ( i = 0; i < nNodes; i++ ) - for ( j = 0; j < nIC; j++ ) + for (i = 0; i < nNodes; i++) + for (j = 0; j < nIC; j++) { - os3 << m_bIC[i * nIC + j ] << " "; - os3 << m_soluteB[i * nIC + j ] << " "; + os3 << m_bIC[i * nIC + j] << " "; + os3 << m_soluteB[i * nIC + j] << " "; os3 << "\n"; } os3.close(); // write xDC vector - if ( !m_xDC ) + if (!m_xDC) return 2; #if defined(USE_PETSC) string m_file_name4 = FileName + "_" + "m_xDC" + "_gem_" + rank_str + ".asc"; #else string m_file_name4 = FileName + "_" + "m_xDC" + "_gem.asc"; #endif - ofstream os4 ( m_file_name4.c_str(), ios::trunc | ios::out ); - if ( !os4.good() ) + ofstream os4(m_file_name4.c_str(), ios::trunc | ios::out); + if (!os4.good()) { cout << "Failure to open file: " << m_file_name4 << "\n"; abort(); } - os4.precision ( 15 ); // 15 digits accuracy seems enough? more fields are filled up with random numbers! - os4.setf ( ios_base::scientific,ios_base::floatfield ); + os4.precision(15); // 15 digits accuracy seems enough? more fields are filled up with random numbers! + os4.setf(ios_base::scientific, ios_base::floatfield); - for ( i = 0; i < nNodes; i++ ) - for ( j = 0; j < nDC; j++ ) + for (i = 0; i < nNodes; i++) + for (j = 0; j < nDC; j++) { - os4 << - m_xDC[i * nDC + - j ] << " " << - m_dll[i * nDC + j] << " " << m_dul[i * nDC + j]; + os4 << m_xDC[i * nDC + j] << " " << m_dll[i * nDC + j] << " " << m_dul[i * nDC + j]; os4 << "\n"; } os4.close(); @@ -3813,15 +3747,15 @@ int REACT_GEM::WriteReloadGem() int REACT_GEM::ReadReloadGem() { - long i,j; + long i, j; string rank_str; rank_str = "0"; -#if defined(USE_PETSC) //|| defined(other parallel libs)//03.3012. WW +#if defined(USE_PETSC) //|| defined(other parallel libs)//03.3012. WW int rank, msize; MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &msize); - stringstream ss (stringstream::in | stringstream::out); + stringstream ss(stringstream::in | stringstream::out); ss.clear(); ss.str(""); ss << rank; @@ -3831,8 +3765,8 @@ int REACT_GEM::ReadReloadGem() #else // if defined(USE_PETSC) string m_file_name = FileName + "_" + "m_porosity" + "_gem.asc"; #endif - ifstream is ( m_file_name.c_str(), ios::in ); - if ( !is.good() ) + ifstream is(m_file_name.c_str(), ios::in); + if (!is.good()) { cout << "Failure to open file: " << m_file_name << "\n"; abort(); @@ -3840,7 +3774,7 @@ int REACT_GEM::ReadReloadGem() // // node porosity ...necessary for restart - for ( i = 0; i < nNodes; i++ ) + for (i = 0; i < nNodes; i++) { is >> m_porosity[i]; is >> ws; @@ -3851,14 +3785,14 @@ int REACT_GEM::ReadReloadGem() #else string m_file_name2 = FileName + "_" + "m_fluid_volume" + "_gem.asc"; #endif - ifstream is2 ( m_file_name2.c_str(), ios::in ); - if ( !is2.good() ) + ifstream is2(m_file_name2.c_str(), ios::in); + if (!is2.good()) { cout << "Failure to open file: " << m_file_name2 << "\n"; abort(); } - for ( i = 0; i < nNodes; i++ ) + for (i = 0; i < nNodes; i++) { is2 >> m_fluid_volume[i]; is2 >> ws; @@ -3869,18 +3803,18 @@ int REACT_GEM::ReadReloadGem() #else string m_file_name3 = FileName + "_" + "m_bIC" + "_gem.asc"; #endif - ifstream is3 ( m_file_name3.c_str(), ios::in ); - if ( !is3.good() ) + ifstream is3(m_file_name3.c_str(), ios::in); + if (!is3.good()) { cout << "Failure to open file: " << m_file_name3 << "\n"; abort(); } - for ( i = 0; i < nNodes; i++ ) - for ( j = 0; j < nIC; j++ ) + for (i = 0; i < nNodes; i++) + for (j = 0; j < nIC; j++) { - is3 >> m_bIC[i * nIC + j ]; - is3 >> m_soluteB[i * nIC + j ]; + is3 >> m_bIC[i * nIC + j]; + is3 >> m_soluteB[i * nIC + j]; is3 >> ws; } is3.close(); @@ -3889,19 +3823,19 @@ int REACT_GEM::ReadReloadGem() #else string m_file_name4 = FileName + "_" + "m_xDC" + "_gem.asc"; #endif - ifstream is4 ( m_file_name4.c_str(), ios::in ); - if ( !is4.good() ) + ifstream is4(m_file_name4.c_str(), ios::in); + if (!is4.good()) { cout << "Failure to open file: " << m_file_name4 << "\n"; abort(); } - for ( i = 0; i < nNodes; i++ ) - for ( j = 0; j < nDC; j++ ) + for (i = 0; i < nNodes; i++) + for (j = 0; j < nDC; j++) { - is4 >> m_xDC[i * nDC + j ]; - is4 >> m_dll[i * nDC + j ]; - is4 >> m_dul[i * nDC + j ]; + is4 >> m_xDC[i * nDC + j]; + is4 >> m_dll[i * nDC + j]; + is4 >> m_dul[i * nDC + j]; is4 >> ws; } is4.close(); @@ -3910,14 +3844,15 @@ int REACT_GEM::ReadReloadGem() } #if defined(USE_PETSC) -/** WriteVTKGEMValues (fstream &vtk_file) ...for serial or normal mpi version it appends GEMS node based data to vtk output +/** WriteVTKGEMValues (fstream &vtk_file) ...for serial or normal mpi version it appends GEMS node based data to vtk + *output * for PETSC version it writes its own vtk file * */ -void REACT_GEM::WriteVTKGEMValuesPETSC (PetscViewer viewer) +void REACT_GEM::WriteVTKGEMValuesPETSC(PetscViewer viewer) { - PetscScalar* xp; //used for pointer - PetscInt low,high; + PetscScalar* xp; // used for pointer + PetscInt low, high; PetscInt count; double bdummy; // MeshLib::CFEMesh *mesh = fem_msh_vector[0]; @@ -3926,188 +3861,223 @@ void REACT_GEM::WriteVTKGEMValuesPETSC (PetscViewer viewer) // test vtk output PETSc_Vec x; // VecCreate(PETSC_COMM_WORLD, &x); - VecSetSizes(x, nNodes,PETSC_DECIDE); + VecSetSizes(x, nNodes, PETSC_DECIDE); VecSetFromOptions(x); // // get range of local variables VecGetOwnershipRange(x, &low, &high); VecGetLocalSize(x, &count); // get local part of vectors VecGetArray(x, &xp); -// write node based data - PetscViewerSetFormat(viewer, PETSC_VIEWER_ASCII_VTK); //will cause a failure if cell data is written before this + // write node based data + PetscViewerSetFormat(viewer, PETSC_VIEWER_ASCII_VTK); // will cause a failure if cell data is written before this -//******************************** B Vector ******************** - for ( int j = 0; j < nIC; j++ ) + //******************************** B Vector ******************** + for (int j = 0; j < nIC; j++) { - const char* fieldname = m_ICNL[j]; - PetscObjectSetName((PetscObject)x,fieldname); + const char* fieldname = m_ICNL[j]; + PetscObjectSetName((PetscObject)x, fieldname); //.................................................................... - for (int k = 0; k < count; k++ ) + for (int k = 0; k < count; k++) { - bdummy = m_soluteB[k * nIC + j] * m_fluid_volume[k]; //soluteB contains volume based concentrations + bdummy = m_soluteB[k * nIC + j] * m_fluid_volume[k]; // soluteB contains volume based concentrations // now we have to add water - if ( idx_hydrogen == j ) - bdummy += ( 2.0 * m_xDC[k * nDC + idx_water] ); //carrier for zero(first phase) is normally water! - else if ( idx_oxygen == j ) - bdummy += m_xDC[k * nDC + idx_water]; + if (idx_hydrogen == j) + bdummy += (2.0 * m_xDC[k * nDC + idx_water]); // carrier for zero(first phase) is normally water! + else if (idx_oxygen == j) + bdummy += m_xDC[k * nDC + idx_water]; - bdummy += m_bIC[k * nIC + j]; //add the solids + bdummy += m_bIC[k * nIC + j]; // add the solids xp[k] = bdummy; } VecView(x, viewer); } -//*********************** speciation vector ********************************* - for (int i = 0; i < nDC; i++ ) + //*********************** speciation vector ********************************* + for (int i = 0; i < nDC; i++) { const char* fieldname = m_DCNL[i]; - PetscObjectSetName((PetscObject)x,fieldname); + PetscObjectSetName((PetscObject)x, fieldname); //.................................................................... - for (int j = 0; j < nNodes; j++ ) - xp[j] = m_xDC[j * nDC + i ]; + for (int j = 0; j < nNodes; j++) + xp[j] = m_xDC[j * nDC + i]; VecView(x, viewer); } -// ******************* eh, pe, pH, Nodeporosity **************************** - PetscObjectSetName((PetscObject)x,"Ph"); + // ******************* eh, pe, pH, Nodeporosity **************************** + PetscObjectSetName((PetscObject)x, "Ph"); //.................................................................... - for (int j = 0; j < nNodes; j++ ) + for (int j = 0; j < nNodes; j++) xp[j] = m_pH[j]; VecView(x, viewer); - PetscObjectSetName((PetscObject)x,"pe"); + PetscObjectSetName((PetscObject)x, "pe"); //.................................................................... - for (int j = 0; j < nNodes; j++ ) + for (int j = 0; j < nNodes; j++) xp[j] = m_pe[j]; VecView(x, viewer); - PetscObjectSetName((PetscObject)x,"Eh"); + PetscObjectSetName((PetscObject)x, "Eh"); //.................................................................... - for (int j = 0; j < nNodes; j++ ) + for (int j = 0; j < nNodes; j++) xp[j] = m_Eh[j]; VecView(x, viewer); -// ***************************Nodeporosity, fluidvolume, excess volume, node volume + // ***************************Nodeporosity, fluidvolume, excess volume, node volume - PetscObjectSetName((PetscObject)x,"NodePorosity"); + PetscObjectSetName((PetscObject)x, "NodePorosity"); //.................................................................... - for (int j = 0; j < nNodes; j++ ) + for (int j = 0; j < nNodes; j++) xp[j] = m_porosity[j]; VecView(x, viewer); - PetscObjectSetName((PetscObject)x,"FluidVolume"); + PetscObjectSetName((PetscObject)x, "FluidVolume"); //.................................................................... - for (int j = 0; j < nNodes; j++ ) + for (int j = 0; j < nNodes; j++) xp[j] = m_fluid_volume[j]; VecView(x, viewer); - PetscObjectSetName((PetscObject)x,"ExcessVolume"); + PetscObjectSetName((PetscObject)x, "ExcessVolume"); //.................................................................... - for (int j = 0; j < nNodes; j++ ) + for (int j = 0; j < nNodes; j++) xp[j] = m_excess_water[j]; VecView(x, viewer); - PetscObjectSetName((PetscObject)x,"NodeVolume"); + PetscObjectSetName((PetscObject)x, "NodeVolume"); //.................................................................... - for (int j = 0; j < nNodes; j++ ) - xp[j] = m_Vs[j]; + for (int j = 0; j < nNodes; j++) + xp[j] = m_Vs[j]; VecView(x, viewer); -// *********************Fluiddensity **************************** + // *********************Fluiddensity **************************** - PetscObjectSetName((PetscObject)x,"FluidDensity"); + PetscObjectSetName((PetscObject)x, "FluidDensity"); //.................................................................... - for (int j = 0; j < nNodes; j++ ) + for (int j = 0; j < nNodes; j++) xp[j] = m_fluid_density[j]; - } #endif -void REACT_GEM::WriteVTKGEMValues ( fstream &vtk_file ) +void REACT_GEM::WriteVTKGEMValues(fstream& vtk_file) { - long i,j,k; + long i, j, k; double bdummy = 0.0; // this is point data - for ( j = 0; j < nIC; j++ ) + for (j = 0; j < nIC; j++) { - vtk_file << "SCALARS " << m_ICNL[j] << " double 1" << "\n"; - vtk_file << "LOOKUP_TABLE default" << "\n"; + vtk_file << "SCALARS " << m_ICNL[j] << " double 1" + << "\n"; + vtk_file << "LOOKUP_TABLE default" + << "\n"; //.................................................................... - for ( k = 0; k < nNodes; k++ ) + for (k = 0; k < nNodes; k++) { - bdummy = m_soluteB[k * nIC + j] * m_fluid_volume[k]; //soluteB contains volume based concentrations + bdummy = m_soluteB[k * nIC + j] * m_fluid_volume[k]; // soluteB contains volume based concentrations // now we have to add water - if ( idx_hydrogen == j ) - bdummy += ( 2.0 * m_xDC[k * nDC + idx_water] ); //carrier for zero(first phase) is normally water! - else if ( idx_oxygen == j ) - bdummy += m_xDC[k * nDC + idx_water]; + if (idx_hydrogen == j) + bdummy += (2.0 * m_xDC[k * nDC + idx_water]); // carrier for zero(first phase) is normally water! + else if (idx_oxygen == j) + bdummy += m_xDC[k * nDC + idx_water]; - bdummy += m_bIC[k * nIC + j]; //add the solids - vtk_file << " " << bdummy << "\n"; // and output + bdummy += m_bIC[k * nIC + j]; // add the solids + vtk_file << " " << bdummy << "\n"; // and output } } // loop over speciation vector! - for ( i = 0; i < nDC; i++ ) + for (i = 0; i < nDC; i++) { - vtk_file << "SCALARS " << m_DCNL[i] << " double 1" << "\n"; - vtk_file << "LOOKUP_TABLE default" << "\n"; + vtk_file << "SCALARS " << m_DCNL[i] << " double 1" + << "\n"; + vtk_file << "LOOKUP_TABLE default" + << "\n"; //.................................................................... - for ( j = 0; j < nNodes; j++ ) - vtk_file << " " << ( float ) m_xDC[j * nDC + i ] << "\n"; + for (j = 0; j < nNodes; j++) + vtk_file << " " << (float)m_xDC[j * nDC + i] << "\n"; } // eh, pe, pH, Nodeporosity - vtk_file << "SCALARS " << " pH " << " double 1" << "\n"; - vtk_file << "LOOKUP_TABLE default" << "\n"; + vtk_file << "SCALARS " + << " pH " + << " double 1" + << "\n"; + vtk_file << "LOOKUP_TABLE default" + << "\n"; //.................................................................... - for ( j = 0; j < nNodes; j++ ) - vtk_file << " " << m_pH[j] << "\n"; - vtk_file << "SCALARS " << " pe " << " double 1" << "\n"; - vtk_file << "LOOKUP_TABLE default" << "\n"; + for (j = 0; j < nNodes; j++) + vtk_file << " " << m_pH[j] << "\n"; + vtk_file << "SCALARS " + << " pe " + << " double 1" + << "\n"; + vtk_file << "LOOKUP_TABLE default" + << "\n"; //.................................................................... - for ( j = 0; j < nNodes; j++ ) - vtk_file << " " << m_pe[j] << "\n"; - vtk_file << "SCALARS " << " Eh " << " double 1" << "\n"; - vtk_file << "LOOKUP_TABLE default" << "\n"; + for (j = 0; j < nNodes; j++) + vtk_file << " " << m_pe[j] << "\n"; + vtk_file << "SCALARS " + << " Eh " + << " double 1" + << "\n"; + vtk_file << "LOOKUP_TABLE default" + << "\n"; //.................................................................... - for ( j = 0; j < nNodes; j++ ) - vtk_file << " " << m_Eh[j] << "\n"; - vtk_file << "SCALARS " << " NodePorosity " << " double 1" << "\n"; - vtk_file << "LOOKUP_TABLE default" << "\n"; + for (j = 0; j < nNodes; j++) + vtk_file << " " << m_Eh[j] << "\n"; + vtk_file << "SCALARS " + << " NodePorosity " + << " double 1" + << "\n"; + vtk_file << "LOOKUP_TABLE default" + << "\n"; //.................................................................... - for ( j = 0; j < nNodes; j++ ) - vtk_file << " " << m_porosity[j] << "\n"; - vtk_file << "SCALARS " << " Fluidvolume " << " double 1" << "\n"; - vtk_file << "LOOKUP_TABLE default" << "\n"; + for (j = 0; j < nNodes; j++) + vtk_file << " " << m_porosity[j] << "\n"; + vtk_file << "SCALARS " + << " Fluidvolume " + << " double 1" + << "\n"; + vtk_file << "LOOKUP_TABLE default" + << "\n"; //.................................................................... - for ( j = 0; j < nNodes; j++ ) - vtk_file << " " << m_fluid_volume[j] << "\n"; - vtk_file << "SCALARS " << " ExcessVolume " << " double 1" << "\n"; - vtk_file << "LOOKUP_TABLE default" << "\n"; + for (j = 0; j < nNodes; j++) + vtk_file << " " << m_fluid_volume[j] << "\n"; + vtk_file << "SCALARS " + << " ExcessVolume " + << " double 1" + << "\n"; + vtk_file << "LOOKUP_TABLE default" + << "\n"; //.................................................................... - for ( j = 0; j < nNodes; j++ ) - vtk_file << " " << m_excess_water[j] << "\n"; - vtk_file << "SCALARS " << " NodeVolume " << " double 1" << "\n"; - vtk_file << "LOOKUP_TABLE default" << "\n"; + for (j = 0; j < nNodes; j++) + vtk_file << " " << m_excess_water[j] << "\n"; + vtk_file << "SCALARS " + << " NodeVolume " + << " double 1" + << "\n"; + vtk_file << "LOOKUP_TABLE default" + << "\n"; //.................................................................... - for ( j = 0; j < nNodes; j++ ) - vtk_file << " " << m_Vs[j] << "\n"; - vtk_file << "SCALARS " << " FluidDensity " << " double 1" << "\n"; - vtk_file << "LOOKUP_TABLE default" << "\n"; + for (j = 0; j < nNodes; j++) + vtk_file << " " << m_Vs[j] << "\n"; + vtk_file << "SCALARS " + << " FluidDensity " + << " double 1" + << "\n"; + vtk_file << "LOOKUP_TABLE default" + << "\n"; //.................................................................... - for ( j = 0; j < nNodes; j++ ) - vtk_file << " " << m_fluid_density[j] << "\n"; - + for (j = 0; j < nNodes; j++) + vtk_file << " " << m_fluid_density[j] << "\n"; } /** gems_worker: - * This function creates and initializes one GEMS3K kernel. It may be spawned several times. Calculations are coordinated with boost barrier commands. + * This function creates and initializes one GEMS3K kernel. It may be spawned several times. Calculations are + * coordinated with boost barrier commands. */ void REACT_GEM::gems_worker(int tid, string m_Project_path) { nNodes = GetNodeNumber_MT(); nElems = GetElemNumber_MT(); - long j,in,node_fail = 0, repeated_fail = 0; + long j, in, node_fail = 0, repeated_fail = 0; double oldvolume; // collection of time data for rough performance analysis @@ -4122,64 +4092,63 @@ void REACT_GEM::gems_worker(int tid, string m_Project_path) TNode* t_Node; // DATABR structure for exchange with GEMIPM this should be local data for each thread - DATACH* tdCH; //pointer to DATACH - DATABR* tdBR; //pointer to DATABR + DATACH* tdCH; // pointer to DATACH + DATABR* tdBR; // pointer to DATABR string tinit_path; char* buffer = NULL; - tinit_path = m_Project_path.append ( REACT_GEM::init_input_file_path ); - // int tid=1; + tinit_path = m_Project_path.append(REACT_GEM::init_input_file_path); +// int tid=1; // string tinit_path = "./BC-dat.lst"; #ifdef _WIN32 // keep this on windows - if ( tinit_path.rfind ( "\\" ) == string::npos ) + if (tinit_path.rfind("\\") == string::npos) #else // keep this on linux - if ( tinit_path.rfind ( "/" ) == string::npos ) + if (tinit_path.rfind("/") == string::npos) #endif { #ifdef _WIN32 - if ( ( buffer = _getcwd ( NULL, 0 ) ) == NULL ) + if ((buffer = _getcwd(NULL, 0)) == NULL) #else - if ( ( buffer = getcwd ( NULL, 0 ) ) == NULL ) + if ((buffer = getcwd(NULL, 0)) == NULL) #endif - perror ( "_getcwd error" ); + perror("_getcwd error"); else { #ifdef _WIN32 - tinit_path.insert ( 0, "\\" ); // keep this on window + tinit_path.insert(0, "\\"); // keep this on window #else - tinit_path.insert ( 0, "/" ); // keep this on linux + tinit_path.insert(0, "/"); // keep this on linux #endif - tinit_path.insert ( 0, buffer ); + tinit_path.insert(0, buffer); } } - if ( buffer ) - free ( buffer ); + if (buffer) + free(buffer); rwmutex.lock(); // first lock for reading gem init files t_Node = new TNode(); - if ( t_Node->GEM_init ( tinit_path.c_str() ) ) + if (t_Node->GEM_init(tinit_path.c_str())) { // error occured during reading the files - cout << "Hello World! I failed!!!! It's me, thread " << tid << " " << - tinit_path.c_str() << "\n"; + cout << "Hello World! I failed!!!! It's me, thread " << tid << " " << tinit_path.c_str() << "\n"; #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - MPI_Finalize(); //make sure MPI exits + MPI_Finalize(); // make sure MPI exits #endif exit(1); } tdCH = t_Node->pCSD(); - if ( !tdCH ) + if (!tdCH) { #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - MPI_Finalize(); //make sure MPI exits + MPI_Finalize(); // make sure MPI exits #endif exit(1); @@ -4187,35 +4156,36 @@ void REACT_GEM::gems_worker(int tid, string m_Project_path) // Getting direct access to work node DATABR structure which // exchanges data between GEMIPM and FMT parts tdBR = t_Node->pCNode(); - if ( !tdBR ) + if (!tdBR) { #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - MPI_Finalize(); //make sure MPI exits + MPI_Finalize(); // make sure MPI exits #endif exit(1); } // run GEMS once tdBR->NodeStatusCH = NEED_GEM_AIA; - t_Node->GEM_run ( false ); + t_Node->GEM_run(false); -// t_Node->GEM_write_dbr ( "dbr_for_crash_node_init_thread1.txt" ); -// t_Node->GEM_print_ipm ( "ipm_for_crash_node_init_thread1.txt" ); + // t_Node->GEM_write_dbr ( "dbr_for_crash_node_init_thread1.txt" ); + // t_Node->GEM_print_ipm ( "ipm_for_crash_node_init_thread1.txt" ); rwmutex.unlock(); -// now we set the loop variables - int mycount,mystart; + // now we set the loop variables + int mycount, mystart; #if defined(USE_MPI_GEMS) mystart = tid + (myrank * gem_nThread); mycount = gem_nThread * mysize; // rwmutex.lock(); //avoid mutual exclusion in the MPI version -// cout << "GEMS3K MPI Processe / Thread: " << myrank << " " << tid << " mystart,mycont: " << mystart << " " << mycount << "\n"; +// cout << "GEMS3K MPI Processe / Thread: " << myrank << " " << tid << " mystart,mycont: " << mystart << " " << +// mycount << "\n"; // rwmutex.unlock(); - // here "myrank" is the index of the CPU Processes, and "mysize" is the number of CPU Processes +// here "myrank" is the index of the CPU Processes, and "mysize" is the number of CPU Processes #else - mycount = gem_nThread; //make sure the loop over the nodes counts only the threads! + mycount = gem_nThread; // make sure the loop over the nodes counts only the threads! mystart = tid; int myrank = 0; int mysize = 1; @@ -4226,22 +4196,23 @@ void REACT_GEM::gems_worker(int tid, string m_Project_path) // cout << "thread " << tid << " passed start barrier " << "\n"; tdummy = GetTimeOfDayDouble(); - for ( in = mystart; in < nNodes; in += mycount ) // myrank ist defined vi USE_MPI_GEMS + for (in = mystart; in < nNodes; in += mycount) // myrank ist defined vi USE_MPI_GEMS { -// rwmutex.lock(); -// cout << "GEMS3K MPI Processe / Thread: " << myrank << " " << tid << " in " << in << "\n"; -// rwmutex.unlock(); + // rwmutex.lock(); + // cout << "GEMS3K MPI Processe / Thread: " << myrank << " " << tid << " in " << in << "\n"; + // rwmutex.unlock(); - if ( ( m_flow_pcs->GetRestartFlag() >= 2 ) ) // everything is stored in concentrations for restart ...moved it to here from init_gems + if ((m_flow_pcs->GetRestartFlag() + >= 2)) // everything is stored in concentrations for restart ...moved it to here from init_gems // Convert from concentration - REACT_GEM::ConcentrationToMass ( in,1); // I believe this is save for MPI - // this we have already - + REACT_GEM::ConcentrationToMass(in, 1); // I believe this is save for MPI + // this we have already // now we calculate kinetic constraints for GEMS! - if ( !( m_flow_pcs->GetRestartFlag() >= 2 ) ) - REACT_GEM::CalcLimitsInitial ( in, t_Node); //kg44 16.05.2013 new version, restart files contain upper and lower limits + if (!(m_flow_pcs->GetRestartFlag() >= 2)) + REACT_GEM::CalcLimitsInitial( + in, t_Node); // kg44 16.05.2013 new version, restart files contain upper and lower limits // Manipulate some kinetic contstraints for special initial conditions // get all nodes of mesh // const std::vector& msh_nodes (m_flow_pcs->m_msh->getNodeVector()); @@ -4250,65 +4221,62 @@ void REACT_GEM::gems_worker(int tid, string m_Project_path) // if ((coords[0] >0.0) && (coords[0]<10.0)) m_dll[in*nDC+nDC-6]= 2.869412109375e+04; // here set gravel // if (coords[0] >=10.0) m_dll[in*nDC+nDC-3]=2.532753515625e+04; // here set monocorn again - //Get data - REACT_GEM::SetReactInfoBackGEM ( in,t_Node ); // thcc1p.pcs.initialis is necessary, otherwise the correct data is not available + // Get data + REACT_GEM::SetReactInfoBackGEM( + in, t_Node); // thcc1p.pcs.initialis is necessary, otherwise the correct data is not available // Order GEM to run tdBR->NodeStatusCH = NEED_GEM_AIA; - m_NodeStatusCH[in] = t_Node->GEM_run ( false ); + m_NodeStatusCH[in] = t_Node->GEM_run(false); // t_Node->GEM_write_dbr ( "dbr_for_crash_node_init_thread_1.txt" ); - REACT_GEM::GetReactInfoFromGEM ( in, t_Node); // test case..get the data even if GEMS failed + REACT_GEM::GetReactInfoFromGEM(in, t_Node); // test case..get the data even if GEMS failed - if ( !( m_NodeStatusCH[in] == OK_GEM_AIA || m_NodeStatusCH[in] == OK_GEM_SIA ) ) + if (!(m_NodeStatusCH[in] == OK_GEM_AIA || m_NodeStatusCH[in] == OK_GEM_SIA)) { rwmutex.lock(); // cout << "Initial GEMs run first pass failed at node " << in ; // cout << " repeat calculations and change kinetic constraintsby 0.1%" << "\n"; rwmutex.unlock(); // change a bit the kinetic constraints -> make the system less stiff - for ( j = 0; j < nDC; j++ ) + for (j = 0; j < nDC; j++) { m_dll[in * nDC + j] = 0.999 * m_dll[in * nDC + j] - 1.0e-6; // make smaller - if ( m_dll[in * nDC + j] < 0.0 ) + if (m_dll[in * nDC + j] < 0.0) m_dll[in * nDC + j] = 0.0; m_dul[in * nDC + j] = 1.001 * m_dul[in * nDC + j] + 1.0e-6; // make bigger } - REACT_GEM::SetReactInfoBackGEM ( in, t_Node); // needs to be done to + REACT_GEM::SetReactInfoBackGEM(in, t_Node); // needs to be done to -// run GEMS again + // run GEMS again tdBR->NodeStatusCH = NEED_GEM_AIA; - m_NodeStatusCH[in] = t_Node->GEM_run ( false ); + m_NodeStatusCH[in] = t_Node->GEM_run(false); - if ( ( m_NodeStatusCH[in] == ERR_GEM_AIA || m_NodeStatusCH[in] == - ERR_GEM_SIA ) ) + if ((m_NodeStatusCH[in] == ERR_GEM_AIA || m_NodeStatusCH[in] == ERR_GEM_SIA)) { -/* - rwmutex.lock(); - cout << " Error: Init Loop failed when running GEM on Node #" << in << "." << "\n"; - cout << "Returned Error Code: " << m_NodeStatusCH[in] << "\n"; - t_Node->GEM_write_dbr ( "dbr_for_crash_node_init_thread.txt" ); - t_Node->GEM_print_ipm ( "ipm_for_crash_node_init_thread.txt" ); - rwmutex.unlock(); - #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - MPI_Finalize(); //make sure MPI exits - #endif - - exit ( 1 ); - */ + /* + rwmutex.lock(); + cout << " Error: Init Loop failed when running GEM on Node #" << in << "." << "\n"; + cout << "Returned Error Code: " << m_NodeStatusCH[in] << "\n"; + t_Node->GEM_write_dbr ( "dbr_for_crash_node_init_thread.txt" ); + t_Node->GEM_print_ipm ( "ipm_for_crash_node_init_thread.txt" ); + rwmutex.unlock(); + #if defined(USE_MPI_GEMS) || defined(USE_PETSC) + MPI_Finalize(); //make sure MPI exits + #endif + + exit ( 1 ); + */ rwmutex.lock(); - cout << - "error: Initial GEMs run after Read GEMS gives bad result..proceed in any case. node: " - << in << "\n"; + cout << "error: Initial GEMs run after Read GEMS gives bad result..proceed in any case. node: " << in + << "\n"; rwmutex.unlock(); } - else if (( m_NodeStatusCH[in] == BAD_GEM_AIA || m_NodeStatusCH[in] == - BAD_GEM_SIA )) + else if ((m_NodeStatusCH[in] == BAD_GEM_AIA || m_NodeStatusCH[in] == BAD_GEM_SIA)) { rwmutex.lock(); - cout << - "error: Initial GEMs run after Read GEMS gives bad result..proceed in any case. node: " - << in << "\n"; + cout << "error: Initial GEMs run after Read GEMS gives bad result..proceed in any case. node: " << in + << "\n"; rwmutex.unlock(); } else @@ -4319,19 +4287,20 @@ void REACT_GEM::gems_worker(int tid, string m_Project_path) } } // end loop if initial gems run fails - //Get data also for volumes! - REACT_GEM::GetReactInfoFromGEM ( in, t_Node); // this we need also for restart + // Get data also for volumes! + REACT_GEM::GetReactInfoFromGEM(in, t_Node); // this we need also for restart // calculate density of fluid phase, which is normally the first phase - m_fluid_density[in] = m_mPS[in * nPS + 0] / m_vPS[in * nPS + 0 ]; + m_fluid_density[in] = m_mPS[in * nPS + 0] / m_vPS[in * nPS + 0]; - if ( ( m_flow_pcs->GetRestartFlag() < 2 ) ) // we do not need the second pass for complete restart + if ((m_flow_pcs->GetRestartFlag() < 2)) // we do not need the second pass for complete restart // scale data so that second pass gives the normalized volume of 1m^3 if (m_Vs[in] >= 0.0) - { // this should be not done for restart, decoupled porosity runs do not change volumes and the other runs should be ok - for ( j = 0; j < nIC; j++ ) - m_bIC[in * nIC + j] /= m_Vs[in]; //This is then for b vector - for ( j = 0; j < nDC; j++ ) + { // this should be not done for restart, decoupled porosity runs do not change volumes and the other runs + // should be ok + for (j = 0; j < nIC; j++) + m_bIC[in * nIC + j] /= m_Vs[in]; // This is then for b vector + for (j = 0; j < nDC; j++) { m_dll[in * nDC + j] /= m_Vs[in]; m_dul[in * nDC + j] /= m_Vs[in]; @@ -4339,238 +4308,225 @@ void REACT_GEM::gems_worker(int tid, string m_Project_path) } // end if for restart - REACT_GEM::SetReactInfoBackGEM ( in,t_Node ); // this is necessary, otherwise the correct data is not available + REACT_GEM::SetReactInfoBackGEM(in, t_Node); // this is necessary, otherwise the correct data is not available // Order GEM to run tdBR->NodeStatusCH = NEED_GEM_AIA; - m_NodeStatusCH[in] = t_Node->GEM_run ( false ); + m_NodeStatusCH[in] = t_Node->GEM_run(false); - if ( ( m_NodeStatusCH[in] == ERR_GEM_AIA || m_NodeStatusCH[in] == ERR_GEM_SIA ) ) + if ((m_NodeStatusCH[in] == ERR_GEM_AIA || m_NodeStatusCH[in] == ERR_GEM_SIA)) { rwmutex.lock(); cout << "Initial GEMs run second pass failed at node " << in; - cout << " repeat calculations and change kinetic constraintsby 0.1%" << - "\n"; + cout << " repeat calculations and change kinetic constraintsby 0.1%" + << "\n"; rwmutex.unlock(); // change a bit the kinetic constraints -> make the system less stiff - for ( j = 0; j < nDC; j++ ) + for (j = 0; j < nDC; j++) { m_dll[in * nDC + j] = 0.999 * m_dll[in * nDC + j] - 1.0e-6; // make smaller - if ( m_dll[in * nDC + j] < 0.0 ) + if (m_dll[in * nDC + j] < 0.0) m_dll[in * nDC + j] = 0.0; m_dul[in * nDC + j] = 1.001 * m_dul[in * nDC + j] + 1.0e-6; // make bigger } - REACT_GEM::SetReactInfoBackGEM ( in, t_Node); // needs to be done to + REACT_GEM::SetReactInfoBackGEM(in, t_Node); // needs to be done to // m_Node->GEM_write_dbr ( "dbr_for_crash_node_fail1.txt" ); // run GEMS again tdBR->NodeStatusCH = NEED_GEM_AIA; - m_NodeStatusCH[in] = t_Node->GEM_run ( false ); + m_NodeStatusCH[in] = t_Node->GEM_run(false); // m_Node->GEM_write_dbr ( "dbr_for_crash_node_fail2.txt" ); - if ( ( m_NodeStatusCH[in] == ERR_GEM_AIA || m_NodeStatusCH[in] == - ERR_GEM_SIA ) ) + if ((m_NodeStatusCH[in] == ERR_GEM_AIA || m_NodeStatusCH[in] == ERR_GEM_SIA)) { rwmutex.lock(); - cout << - " Error: Init Loop second pass failed when running GEM on Node #" - << - in << "." << "\n"; + cout << " Error: Init Loop second pass failed when running GEM on Node #" << in << "." + << "\n"; cout << "Returned Error Code: " << m_NodeStatusCH[in] << "\n"; - t_Node->GEM_write_dbr ( "dbr_for_crash_node_init2.txt" ); + t_Node->GEM_write_dbr("dbr_for_crash_node_init2.txt"); rwmutex.unlock(); #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - MPI_Finalize(); //make sure MPI exits + MPI_Finalize(); // make sure MPI exits #endif - exit ( 1 ); + exit(1); } - else if ( m_NodeStatusCH[in] == BAD_GEM_AIA || m_NodeStatusCH[in] == - BAD_GEM_SIA ) + else if (m_NodeStatusCH[in] == BAD_GEM_AIA || m_NodeStatusCH[in] == BAD_GEM_SIA) { rwmutex.lock(); - cout << - "error: Initial GEMs run after Read GEMS gives bad result..proceed in any case. node" - << in << "\n"; + cout << "error: Initial GEMs run after Read GEMS gives bad result..proceed in any case. node" << in + << "\n"; rwmutex.unlock(); } else { rwmutex.lock(); - cout << " sucess with second try.... " << "\n"; + cout << " sucess with second try.... " + << "\n"; rwmutex.unlock(); } - } // end loop if initial gems run fails + } // end loop if initial gems run fails - REACT_GEM::GetReactInfoFromGEM ( in, t_Node ); + REACT_GEM::GetReactInfoFromGEM(in, t_Node); -// } // end if for restart + // } // end if for restart // calculate the chemical porosity - if ( m_flow_pcs->GetRestartFlag() < 2 ) - REACT_GEM::CalcPorosity ( in, t_Node); //during init it should be always done, except for restart !!! + if (m_flow_pcs->GetRestartFlag() < 2) + REACT_GEM::CalcPorosity(in, t_Node); // during init it should be always done, except for restart !!! - REACT_GEM::CalcReactionRate ( in, m_T[in], t_Node); //moved it after porosity calculation because of chrunchflow kinetics (model 4)! + REACT_GEM::CalcReactionRate( + in, m_T[in], t_Node); // moved it after porosity calculation because of chrunchflow kinetics (model 4)! // Convert to concentration: should be done always... - REACT_GEM::MassToConcentration ( in,0, t_Node); // concentrations are now based on the fluid-gas volumes... + REACT_GEM::MassToConcentration(in, 0, t_Node); // concentrations are now based on the fluid-gas volumes... #if defined(USE_MPI_GEMS) - REACT_GEM::CopyToMPIBuffer ( in ); //copy data to MPI buffer in any case + REACT_GEM::CopyToMPIBuffer(in); // copy data to MPI buffer in any case #endif - } // end for loop for all nodes + } // end for loop for all nodes gem_barrier_finish->wait(); // init run finished ...now the init routine takes over time_gem_total += (GetTimeOfDayDouble() - tdummy); time_fraction = time_gem_total / GetTimeOfDayDouble(); // main loop which is synchronized via run_main - for (;; ) + for (;;) { gem_barrier_start->wait(); // central barrier for synchonizing the main runs tdummy = GetTimeOfDayDouble(); repeated_fail = 0; // set this to zero for each new run_main - for ( in = mystart; in < nNodes; in += mycount ) // myrank ist defined vi USE_MPI_GEMS + for (in = mystart; in < nNodes; in += mycount) // myrank ist defined vi USE_MPI_GEMS { - if ( ( !flag_calculate_boundary_nodes && - m_boundary[in] ) || ( CalcSoluteBDelta ( in ) < m_diff_gems ) ) // do this only without calculation if on a boundary or differences very small!!! + if ((!flag_calculate_boundary_nodes && m_boundary[in]) + || (CalcSoluteBDelta(in) + < m_diff_gems)) // do this only without calculation if on a boundary or differences very small!!! { #if defined(USE_MPI_GEMS) - REACT_GEM::CopyToMPIBuffer ( in ); // copy old values to buffer..otherwise we loose them + REACT_GEM::CopyToMPIBuffer(in); // copy old values to buffer..otherwise we loose them #endif } else // calculate if not on a boundary or transport causes differences in solutes { // Convert from concentration - REACT_GEM::ConcentrationToMass ( in,1); // I believe this is save for MPI + REACT_GEM::ConcentrationToMass(in, 1); // I believe this is save for MPI // now we calculate kinetic constraints for GEMS! - REACT_GEM::CalcLimits ( in,t_Node); - //Get data + REACT_GEM::CalcLimits(in, t_Node); + // Get data - REACT_GEM::SetReactInfoBackGEM ( in,t_Node); // this should be also save for MPI + REACT_GEM::SetReactInfoBackGEM(in, t_Node); // this should be also save for MPI // take values from old B volume for comparison oldvolume = m_Vs[in]; // Order GEM to run tdBR->NodeStatusCH = NEED_GEM_AIA; // first try without simplex using old solution - m_NodeStatusCH[in] = t_Node->GEM_run ( false ); + m_NodeStatusCH[in] = t_Node->GEM_run(false); - if ( !( m_NodeStatusCH[in] == OK_GEM_AIA || m_NodeStatusCH[in] == - OK_GEM_SIA || m_NodeStatusCH[in] == BAD_GEM_AIA || - m_NodeStatusCH[in] == BAD_GEM_SIA ) || - ( ( ( abs ( oldvolume - tdBR->Vs ) / oldvolume ) > 0.1 ) && - ( flowflag != 3 ) )) // not for Richards flow // ups...failed..try again with changed kinetics + if (!(m_NodeStatusCH[in] == OK_GEM_AIA || m_NodeStatusCH[in] == OK_GEM_SIA + || m_NodeStatusCH[in] == BAD_GEM_AIA + || m_NodeStatusCH[in] == BAD_GEM_SIA) + || (((abs(oldvolume - tdBR->Vs) / oldvolume) > 0.1) + && (flowflag != 3))) // not for Richards flow // ups...failed..try again with changed kinetics { -//#if !defined(USE_MPI_GEMS) && !defined(USE_PETSC) - rwmutex.lock(); //KG44 try to avoid mutual exclusion at least in the parallel version, as this might slow down execution - cout << - "Error: Main Loop failed when running GEM on Node #" - << - in << "." << " Returned Error Code: " << - m_NodeStatusCH[in]; - cout << " or GEM weird result at node " << in << - " volume " << tdBR->Vs << " old volume " << - oldvolume; - cout << - " repeat calculations and change kinetic constraintsby 0.1%" + //#if !defined(USE_MPI_GEMS) && !defined(USE_PETSC) + rwmutex.lock(); // KG44 try to avoid mutual exclusion at least in the parallel version, as this + // might slow down execution + cout << "Error: Main Loop failed when running GEM on Node #" << in << "." + << " Returned Error Code: " << m_NodeStatusCH[in]; + cout << " or GEM weird result at node " << in << " volume " << tdBR->Vs << " old volume " + << oldvolume; + cout << " repeat calculations and change kinetic constraintsby 0.1%" << "\n"; rwmutex.unlock(); -//#endif + //#endif // change a bit the kinetic constraints -> make the system less stiff - for ( j = 0; j < nDC; j++ ) + for (j = 0; j < nDC; j++) { - m_dll[in * nDC + - j] = 0.999 * m_dll[in * nDC + j] - 1.0e-6; // make smaller - if ( m_dll[in * nDC + j] < 0.0 ) + m_dll[in * nDC + j] = 0.999 * m_dll[in * nDC + j] - 1.0e-6; // make smaller + if (m_dll[in * nDC + j] < 0.0) m_dll[in * nDC + j] = 0.0; - m_dul[in * nDC + - j] = 1.001 * m_dul[in * nDC + j] + 1.0e-6; // make bigger + m_dul[in * nDC + j] = 1.001 * m_dul[in * nDC + j] + 1.0e-6; // make bigger } - REACT_GEM::SetReactInfoBackGEM ( in, t_Node); // needs to be done to for update dll dul + REACT_GEM::SetReactInfoBackGEM(in, t_Node); // needs to be done to for update dll dul // run GEMS again tdBR->NodeStatusCH = NEED_GEM_AIA; - m_NodeStatusCH[in] = t_Node->GEM_run ( false ); + m_NodeStatusCH[in] = t_Node->GEM_run(false); } // test for bad GEMS and for volume changes bigger than 10% ...maximum 5 failed nodes per process..... - if ( - !( m_NodeStatusCH[in] == OK_GEM_AIA || m_NodeStatusCH[in] == - OK_GEM_SIA || m_NodeStatusCH[in] == BAD_GEM_AIA || - m_NodeStatusCH[in] == BAD_GEM_SIA ) || - ( ( ( abs ( oldvolume - tdBR->Vs ) / oldvolume ) > 0.1 ) && - ( flowflag != 3 ) ) // not for Richards flow - ) + if (!(m_NodeStatusCH[in] == OK_GEM_AIA || m_NodeStatusCH[in] == OK_GEM_SIA + || m_NodeStatusCH[in] == BAD_GEM_AIA + || m_NodeStatusCH[in] == BAD_GEM_SIA) + || (((abs(oldvolume - tdBR->Vs) / oldvolume) > 0.1) && (flowflag != 3)) // not for Richards flow + ) { -//#if !defined(USE_MPI_GEMS) && !defined(USE_PETSC) + //#if !defined(USE_MPI_GEMS) && !defined(USE_PETSC) rwmutex.lock(); - cout << - "Error: Main Loop failed when running GEM on Node #" - << - in << "." << " Returned Error Code: " << - m_NodeStatusCH[in]; - cout << " or GEM weird result at node " << in << - " volume " << tdBR->Vs << " old volume " << - oldvolume; - cout << " continue with last good solution for this node" << - "\n"; -// t_Node->GEM_write_dbr ( "dbr_for_crash_node_fail.txt" ); -// t_Node->GEM_print_ipm ( "ipm_for_crash_node_fail.txt" ); + cout << "Error: Main Loop failed when running GEM on Node #" << in << "." + << " Returned Error Code: " << m_NodeStatusCH[in]; + cout << " or GEM weird result at node " << in << " volume " << tdBR->Vs << " old volume " + << oldvolume; + cout << " continue with last good solution for this node" + << "\n"; + // t_Node->GEM_write_dbr ( "dbr_for_crash_node_fail.txt" ); + // t_Node->GEM_print_ipm ( "ipm_for_crash_node_fail.txt" ); rwmutex.unlock(); -//#endif + //#endif // exit ( 1 ); node_fail = 1; repeated_fail += 1; - if ( repeated_fail > m_max_failed_nodes ) + if (repeated_fail > m_max_failed_nodes) { rwmutex.lock(); - cout << "GEFMS: " << repeated_fail << - "nodes failed this timestep, check chemical system!" + cout << "GEFMS: " << repeated_fail << "nodes failed this timestep, check chemical system!" << "\n"; rwmutex.unlock(); #if defined(USE_MPI_GEMS) || defined(USE_PETSC) - MPI_Finalize(); //make sure MPI exits + MPI_Finalize(); // make sure MPI exits #endif - exit ( 1 ); - } // we do not tolerate more than three failed nodes -> something wrong with chemistry/time step? - } // end loop if initial gems run fails + exit(1); + } // we do not tolerate more than three failed nodes -> something wrong with chemistry/time step? + } // end loop if initial gems run fails else // this is if gem run is ok - REACT_GEM::GetReactInfoFromGEM ( in, t_Node); //from here on we have buffer values if GEMS_MPI is defined + REACT_GEM::GetReactInfoFromGEM(in, + t_Node); // from here on we have buffer values if GEMS_MPI is defined - if ( node_fail < 1 ) // this needs to be done with buffer variables for MPI + if (node_fail < 1) // this needs to be done with buffer variables for MPI { // CALC kintetic constrains - REACT_GEM::CalcReactionRate ( in, m_T[in],t_Node); // check for kinetics is done in the subroutine for each species separately + REACT_GEM::CalcReactionRate( + in, m_T[in], + t_Node); // check for kinetics is done in the subroutine for each species separately // calculate the chemical porosity - if ( flag_porosity_change == 1 ) - REACT_GEM::CalcPorosity ( in,t_Node); + if (flag_porosity_change == 1) + REACT_GEM::CalcPorosity(in, t_Node); // Convert to concentration .. - REACT_GEM::MassToConcentration ( in, 0,t_Node); + REACT_GEM::MassToConcentration(in, 0, t_Node); // calculate density of fluid phase, which is normally the first phase - m_fluid_density[in] = - m_mPS[in * nPS + 0] / m_vPS[in * nPS + 0 ]; + m_fluid_density[in] = m_mPS[in * nPS + 0] / m_vPS[in * nPS + 0]; } else { - RestoreOldSolution ( in ); + RestoreOldSolution(in); node_fail = 0; } #if defined(USE_MPI_GEMS) - REACT_GEM::CopyToMPIBuffer ( in ); //copy data to MPI buffer in any case + REACT_GEM::CopyToMPIBuffer(in); // copy data to MPI buffer in any case #endif - } //end if check for boundary node12 + } // end if check for boundary node12 } // end for loop for all nodes - twait = GetTimeOfDayDouble(); //this if for performance check...init waiting time + twait = GetTimeOfDayDouble(); // this if for performance check...init waiting time gem_barrier_finish->wait(); // barrier for synchonizing threads @@ -4586,17 +4542,14 @@ void REACT_GEM::gems_worker(int tid, string m_Project_path) // rwmutex.lock(); // cout << "GEMS3K MPI Processe / Thread: " << myrank << " " << tid << " waiting time: " << twait << "\n"; // rwmutex.unlock(); - // write some time values for performance ...only for first thread..do only for all threads if +// write some time values for performance ...only for first thread..do only for all threads if #if !defined(USE_MPI_GEMS) && !defined(USE_PETSC) - if (tid == 0 && myrank == 0) //try to avoid mutual exclusion in MPI version + if (tid == 0 && myrank == 0) // try to avoid mutual exclusion in MPI version { rwmutex.lock(); - cout << "GEMS3K MPI Processes / Threads: " << mysize << " " << - gem_nThread << " mid/tid " << myrank << " " << tid << - " total time: " << - time_gem_total << " s, this dt for GEMS: " << tdummy2 << - " total fraction in GEMS: " << time_fraction << " idle time: " << - twaittotal << "\n"; + cout << "GEMS3K MPI Processes / Threads: " << mysize << " " << gem_nThread << " mid/tid " << myrank << " " + << tid << " total time: " << time_gem_total << " s, this dt for GEMS: " << tdummy2 + << " total fraction in GEMS: " << time_fraction << " idle time: " << twaittotal << "\n"; rwmutex.unlock(); } #endif @@ -4611,7 +4564,7 @@ double REACT_GEM::GetTimeOfDayDouble() dtime = 1.0; // plugin dummy value as long as sys/time.h for windoof is not available #else timeval current; - gettimeofday(¤t,0); + gettimeofday(¤t, 0); dtime = 1.0 * current.tv_sec + 1.0e-6 * current.tv_usec; #endif @@ -4620,53 +4573,50 @@ double REACT_GEM::GetTimeOfDayDouble() #if defined(USE_PETSC) // The following routine is NOT thread safe, therefore do not call within threads!!!!!!!!!!!!!!!!!!!!!!!!!!! -void REACT_GEM::SynchronizeData(double* data) //pass pointer to the vector we would like to synchronize... +void REACT_GEM::SynchronizeData(double* data) // pass pointer to the vector we would like to synchronize... { long i; CRFProcess* this_pcs; - this_pcs = PCSGet ( "MASS_TRANSPORT" ); //first mass transport process...for gems coupling we should always have this -// gem_glob_buff[m_size] is re-used to distribute values.... -// first fill data into global buffer...then get back data... -// size of global buffer is m_size + this_pcs = PCSGet("MASS_TRANSPORT"); // first mass transport process...for gems coupling we should always have this + // gem_glob_buff[m_size] is re-used to distribute values.... + // first fill data into global buffer...then get back data... + // size of global buffer is m_size int receivecount; - PetscInt low,high,otherlow; + PetscInt low, high, otherlow; MPI_Status status; PetscInt count; int tag = 9999; // clean buffer, otherwise allreduce will not work - for(i = 0; i < glob_NodesNumber_Linear; i++) + for (i = 0; i < glob_NodesNumber_Linear; i++) { - gem_glob_buff[i] = 0.0; //put data into array - gem_glob_x0[i] = 0.0; //put data into array + gem_glob_buff[i] = 0.0; // put data into array + gem_glob_x0[i] = 0.0; // put data into array } // arrays are filled, now we should synchronize the values -// for ( long node_i=0; node_i < nNodes ; node_i++ ) -// { -// cout << "before i, value, global_indes " << node_i << " " << data[node_i] << " " << this_pcs->m_msh->Eqs2Global_NodeIndex[node_i] << "\n" ; -// } -// cout << "loc, nodes and glob nodes number " << loc_NodesNumber_Linear << " " << nNodes << " " << glob_NodesNumber_Linear << "\n"; -// put data into buffer array ...only local data without shadow nodes - for(i = 0; i < loc_NodesNumber_Linear; i++) - gem_glob_buff[this_pcs->m_msh->Eqs2Global_NodeIndex[i]] = data[i]; //put data into array - -// now fill gem_glob_x0 - MPI_Allreduce ( gem_glob_buff, - gem_glob_x0, - glob_NodesNumber_Linear, - MPI_DOUBLE, - MPI_SUM, - PETSC_COMM_WORLD ); - -// put data back into data array, but now with shadow nodes - for(i = 0; i < NodesNumber_Linear; i++) + // for ( long node_i=0; node_i < nNodes ; node_i++ ) + // { + // cout << "before i, value, global_indes " << node_i << " " << data[node_i] << " " << + // this_pcs->m_msh->Eqs2Global_NodeIndex[node_i] << "\n" ; + // } + // cout << "loc, nodes and glob nodes number " << loc_NodesNumber_Linear << " " << nNodes << " " << + // glob_NodesNumber_Linear << "\n"; + // put data into buffer array ...only local data without shadow nodes + for (i = 0; i < loc_NodesNumber_Linear; i++) + gem_glob_buff[this_pcs->m_msh->Eqs2Global_NodeIndex[i]] = data[i]; // put data into array + + // now fill gem_glob_x0 + MPI_Allreduce(gem_glob_buff, gem_glob_x0, glob_NodesNumber_Linear, MPI_DOUBLE, MPI_SUM, PETSC_COMM_WORLD); + + // put data back into data array, but now with shadow nodes + for (i = 0; i < NodesNumber_Linear; i++) data[i] = gem_glob_x0[this_pcs->m_msh->Eqs2Global_NodeIndex[i]]; -// for ( long node_i=0; node_i < nNodes ; node_i++ ) -// { -// cout << "after i, value " << node_i << " " << data[node_i] << "\n"; -// } + // for ( long node_i=0; node_i < nNodes ; node_i++ ) + // { + // cout << "after i, value " << node_i << " " << data[node_i] << "\n"; + // } } #endif diff --git a/FEM/rf_REACT_GEM.h b/FEM/rf_REACT_GEM.h index a83f9de2f..0ab716f72 100644 --- a/FEM/rf_REACT_GEM.h +++ b/FEM/rf_REACT_GEM.h @@ -7,7 +7,7 @@ * */ - //------------------------------------- +//------------------------------------- // rf_REACT_GEM.h // Haibing Shao 23.05.07 // haibing.shao@ufz.de @@ -43,304 +43,303 @@ typedef Vec PETSc_Vec; class REACT_GEM { private: - string ipm_input_file_path; - string dbr_input_file_path; - string dbr_bc_input_file_path; - string dch_input_file_path; - string init_input_file_path; - string init_input_file_sig; + string ipm_input_file_path; + string dbr_input_file_path; + string dbr_bc_input_file_path; + string dch_input_file_path; + string init_input_file_path; + string init_input_file_sig; public: - REACT_GEM(void); - ~REACT_GEM(void); + REACT_GEM(void); + ~REACT_GEM(void); - //FEM + // FEM CFiniteElementStd* Fem_Ele_Std; - /// Instance of TNode class - /// HS: 06.2007 Only set one TNode here, repeatedly use its resources for GEM calculation -// TNode* m_Node; - - // DATABR structure for exchange with GEMIPM -// DATACH* dCH; //pointer to DATACH -// DATABR* dBR; //pointer to DATABR - - // Read function for gem input file - ios::pos_type Read(ifstream *gem_file); - - // Number of ICs, DCs, Phases and Phases-solutions kept in the node or elem; - long nIC, nDC, nPH, nPS; - - // Data structure for each node to carry the chemical information (real FMT problems consider many nodes) - // Names are consistent with the DataBridge structure (also see "\GEM\databr.h") - long *m_NodeHandle, *m_NodeStatusCH, *m_IterDone, *m_IterDoneCumulative, *m_IterDoneIndex; - // this is for porosity calculated on volume of solids - double *m_porosity; - /// this is used for kinetic law number 4 - double *m_porosity_initial, *m_volumes_initial; - - /// this we need for porosity coupling to groundwater flow & multiphase flow - double *m_fluid_volume, *m_gas_volume; - - /// take the fluid density from GEMS for density driven flow - double *m_fluid_density; - - /// indexes, which one in the xDC vector is water, oxygen or hydrogen - int idx_water, idx_hydrogen, idx_oxygen; - - double *m_T, *m_P, *m_Vs, *m_Ms, - *m_Gs, *m_Hs, *m_IC, *m_pH, *m_pe, - *m_Eh; - - double *m_xDC, *m_gam, *m_xPH, *m_aPH, *m_vPS, *m_mPS, *m_bPS, - *m_xPA, *m_dul, *m_dll, *m_bIC, *m_bIC_dummy, *m_rMB, *m_uIC, *m_bSP; - - double *m_porosity_Elem, *m_porosity_Elem_buff; - - /// data for transport of IC - double *m_soluteB, *m_soluteB_buff, *m_soluteB_pts, *m_bIC_pts; - - // previous time step DC values - double *m_xDC_pts; // previous time step Concentration; - double *m_xDC_MT_delta; // delta C from Mass Transport; - double *m_xDC_Chem_delta; // delta C from Chemistry; - - double *m_excess_water; // excess water in m3/s for each node; - double *m_excess_gas; // excess gas in m3/s for each node; - double *m_saturation; - double *m_Node_Volume; // Volume around the node; - - // this we need for kinetics - double *mol_phase, *omega_phase,*omega_components; - - double *dmdt; // kinetically controlled rates - int CalcLimits ( long in, TNode* m_Node); - int CalcLimitsInitial ( long in, TNode* m_Node); - int *m_boundary; //holds marker for boundary nodes - double max_kinetic_timestep; // variable used for limiting time step - - // CRFProcess *m_pcs; // pointer to the PCS Class. - CRFProcess *m_flow_pcs; // pointer to the flow PCS. - - - /** Initialization of the GEM TNode Class - * return: 0-ok; - * 1-loading init file failure; - * 3-dch problem; - * 4-dbr problem; - */ - short Init_Nodes(string Project_path); // Initialization of the GEM TNode Class - // return: 0-ok; - // 1-loading init file failure; - // 3-dch problem; - // 4-dbr problem; - - short Init_RUN(string Project_path); // Run the node-GEM - // return: 0-ok;5-GEM does not converge - short Run_MainLoop(); - - // return: 0-ok;5-GEM does not converge - - string Get_Init_File_Path(void); - string Get_DCH_File_Path(void); - string Get_IPM_File_Path(void); - string Get_DBR_File_Path(void); - - int Set_Init_File_Path(string m_path); - int Set_DCH_FILE_PATH(string m_path); - int Set_IPM_FILE_PATH(string m_path); - int Set_DBR_FILE_PATH(string m_path); - - bool Load_Init_File(string m_Project_path, TNode* m_Node ); - long* mp_nodeTypes; - - //---flags------ - int initialized_flag; //0 - not initialized 1 - initialized - int flag_iterative_scheme; // 0 - sequential non-iterative scheme; - // 1 - standard iterative scheme; - // 2 - symetric iterative scheme; - // 3 - strang splitting scheme; - int heatflag; //0-initialized and not heat transport;1-heat_transport; - int flowflag; //0-initialized;1-GROUNDWATER_FLOW;2-LIQUID_FLOW;3-RICHARDS_FLOW;4-FLOW; - int flag_porosity_change; //0-porosity change not coupled into transport; 1=coupled; - int flag_coupling_hydrology; //0-without coupling; 1=with coupling; - int flag_calculate_boundary_nodes; // set to zero to avoid precipitation/dissolution (porosity change) at boundary nodes - int gem_pressure_flag; //shall we give a constant user defined pressure to gems? - int flag_transport_b; //1: transport only dissolved components of b vector; 0: transport full speciation - long m_max_failed_nodes; ///maximum number of failed nodes - int flag_disable_gems; //disable gems calculations in main loop ..not for initialization! - //-------------- - - long nNodes; // number of all nodes; - long nElems; // number of all elements; - int GetHeatFlag_MT(void); - int GetFlowType_MT(void); - long GetNodeNumber_MT(void); - long GetElemNumber_MT(void); - void GetFluidProperty_MT(void); - - short GetInitialReactInfoFromMassTransport(int timelevel); - short GetReactInfoFromMassTransport(int timelevel); - short SetReactInfoBackMassTransport(int timelevel); - void GetReactInfoFromGEM(long in, TNode* m_Node ); - void SetReactInfoBackGEM(long in, TNode* m_Node ); - // necessary for reload with gems - int WriteReloadGem(); - int ReadReloadGem(); - - double GetTempValue_MT(long node_Index, int timelevel); - double GetPressureValue_MT(long node_Index, int timelevel); - short GetDCValue_MT(long node_Index, int timelevel, double* m_DC, double* m_DC_pts, double* m_DC_MT_delta); - short GetBValue_MT ( long node_i, int timelevel, double *m_soluteB); - short GetSoComponentValue_MT(long node_Index, int timelevel, double* m_Phase, TNode* m_Node ); - double GetDCValueSpecies_MT ( long node_Index, int timelevel, int iDc ); - short SetTempValue_MT(long node_Index, int timelevel, double temp); - short SetPressureValue_MT(long node_Index, int timelevel, double pressure); -// short SetDCValue_MT(long node_Index, int timelevel, double* m_DC); - short SetBValue_MT(long node_Index, int timelevel, double* m_soluteB); - - int IsThisPointBCIfYesStoreValue ( long index, CRFProcess* m_pcs, double& value );/// taken from rf_REACT_BRNS - - /// Copy current values into previous time step values - void CopyCurXDCPre ( void ); - void UpdateXDCChemDelta ( void ); - void CopyCurBPre ( void ); - double CalcSoluteBDelta ( long in ); - double m_diff_gems; - void RestoreOldSolution ( long in ); - /// this is only for porosity interpolation to elemens - void ConvPorosityNodeValue2Elem(int i_timestep); - int CalcPorosity(long in, TNode* m_Node ); - - double min_possible_porosity, max_possible_porosity; - void ScaleVolume_Water(long in); - - // Set porosity in Mass Transport - int SetPorosityValue_MT(long ele_Index, double m_porosity_Elem, int i_timestep); - int SetSourceSink_MT(long in, double time_step_size /*in sec*/); - - // pass fluid density back - double FluidDensity(long elem, int gaussnode); - - // find which one in xDC vector is water - int FindWater_xDC(TNode* m_Node); - int Findhydrogen_bIC ( TNode* m_Node); - int Findoxygen_bIC ( TNode* m_Node); - //kg44 11/2008 for kinetics - int CalcReactionRate ( long node, double temp , TNode* m_Node ); - double SurfaceAreaPh ( long kin_phasenr,long in , TNode* m_Node ); - - // concentration related - int ConcentrationToMass (long l /*idx of node*/,int i_timestep ); - int MassToConcentration (long l /*idx of node*/,int i_timestep, TNode* m_Node ); - - // Unit conversion for pressures - double Pressure_Pa_2_Bar(double Pre_in_Pa); - double Pressure_Bar_2_Pa(double Pre_in_Bar); - double Pressure_M_2_Bar(double Pre_in_M, double flu_density ); - double Pressure_Bar_2_M(double Pre_in_Bar, double flu_density ); - double Pressure_M_2_Pa ( double Pre_in_M, double flu_density ); - double Pressure_Pa_2_M ( double Pre_in_Pa, double flu_density ); - // Calculate the volume of the nodes; - // given argument is the index of one particular node; - double GetNodeAdjacentVolume(long Idx_Node); - - // GEMS mass scaling parameter - double gem_mass_scale; - // GEM temperature (without coupling to temperature) - double m_gem_temperature; - // GEM pressure (needed for Richards flow) - double m_gem_pressure; - - /// Definition of buffer variables for MPI - long *m_NodeHandle_buff, *m_NodeStatusCH_buff, *m_IterDone_buff; - // porosity buffer - double *m_porosity_buff, *m_fluid_volume_buff, *m_gas_volume_buff, *m_fluid_density_buff; - double *m_Vs_buff, *m_Ms_buff, *m_Gs_buff, *m_Hs_buff, *m_IC_buff, *m_pH_buff, *m_pe_buff, *m_Eh_buff; - double *m_xDC_buff, *m_xPH_buff,*m_aPH_buff,*m_xPA_buff,*m_excess_water_buff,*m_excess_gas_buff,*m_dul_buff, *m_dll_buff, *m_Node_Volume_buff, *m_saturation_buff,*m_bIC_buff,*m_bIC_dummy_buff, *m_xDC_pts_buff, *m_xDC_MT_delta_buff, *m_xDC_Chem_delta_buff; - double *m_bPS_buff; // for Richards flow and gas transport... - // this we need for kinetics - double *omega_phase_buff, *mol_phase_buff, *dmdt_buff, *omega_components_buff; - -// the next two are always defined, such that it also works in serial version - int myrank; - int mysize; - - // MPI implementation + /// Instance of TNode class + /// HS: 06.2007 Only set one TNode here, repeatedly use its resources for GEM calculation + // TNode* m_Node; + + // DATABR structure for exchange with GEMIPM + // DATACH* dCH; //pointer to DATACH + // DATABR* dBR; //pointer to DATABR + + // Read function for gem input file + ios::pos_type Read(ifstream* gem_file); + + // Number of ICs, DCs, Phases and Phases-solutions kept in the node or elem; + long nIC, nDC, nPH, nPS; + + // Data structure for each node to carry the chemical information (real FMT problems consider many nodes) + // Names are consistent with the DataBridge structure (also see "\GEM\databr.h") + long *m_NodeHandle, *m_NodeStatusCH, *m_IterDone, *m_IterDoneCumulative, *m_IterDoneIndex; + // this is for porosity calculated on volume of solids + double* m_porosity; + /// this is used for kinetic law number 4 + double *m_porosity_initial, *m_volumes_initial; + + /// this we need for porosity coupling to groundwater flow & multiphase flow + double *m_fluid_volume, *m_gas_volume; + + /// take the fluid density from GEMS for density driven flow + double* m_fluid_density; + + /// indexes, which one in the xDC vector is water, oxygen or hydrogen + int idx_water, idx_hydrogen, idx_oxygen; + + double *m_T, *m_P, *m_Vs, *m_Ms, *m_Gs, *m_Hs, *m_IC, *m_pH, *m_pe, *m_Eh; + + double *m_xDC, *m_gam, *m_xPH, *m_aPH, *m_vPS, *m_mPS, *m_bPS, *m_xPA, *m_dul, *m_dll, *m_bIC, *m_bIC_dummy, *m_rMB, + *m_uIC, *m_bSP; + + double *m_porosity_Elem, *m_porosity_Elem_buff; + + /// data for transport of IC + double *m_soluteB, *m_soluteB_buff, *m_soluteB_pts, *m_bIC_pts; + + // previous time step DC values + double* m_xDC_pts; // previous time step Concentration; + double* m_xDC_MT_delta; // delta C from Mass Transport; + double* m_xDC_Chem_delta; // delta C from Chemistry; + + double* m_excess_water; // excess water in m3/s for each node; + double* m_excess_gas; // excess gas in m3/s for each node; + double* m_saturation; + double* m_Node_Volume; // Volume around the node; + + // this we need for kinetics + double *mol_phase, *omega_phase, *omega_components; + + double* dmdt; // kinetically controlled rates + int CalcLimits(long in, TNode* m_Node); + int CalcLimitsInitial(long in, TNode* m_Node); + int* m_boundary; // holds marker for boundary nodes + double max_kinetic_timestep; // variable used for limiting time step + + // CRFProcess *m_pcs; // pointer to the PCS Class. + CRFProcess* m_flow_pcs; // pointer to the flow PCS. + + /** Initialization of the GEM TNode Class + * return: 0-ok; + * 1-loading init file failure; + * 3-dch problem; + * 4-dbr problem; + */ + short Init_Nodes(string Project_path); // Initialization of the GEM TNode Class + // return: 0-ok; + // 1-loading init file failure; + // 3-dch problem; + // 4-dbr problem; + + short Init_RUN(string Project_path); // Run the node-GEM + // return: 0-ok;5-GEM does not converge + short Run_MainLoop(); + + // return: 0-ok;5-GEM does not converge + + string Get_Init_File_Path(void); + string Get_DCH_File_Path(void); + string Get_IPM_File_Path(void); + string Get_DBR_File_Path(void); + + int Set_Init_File_Path(string m_path); + int Set_DCH_FILE_PATH(string m_path); + int Set_IPM_FILE_PATH(string m_path); + int Set_DBR_FILE_PATH(string m_path); + + bool Load_Init_File(string m_Project_path, TNode* m_Node); + long* mp_nodeTypes; + + //---flags------ + int initialized_flag; // 0 - not initialized 1 - initialized + int flag_iterative_scheme; // 0 - sequential non-iterative scheme; + // 1 - standard iterative scheme; + // 2 - symetric iterative scheme; + // 3 - strang splitting scheme; + int heatflag; // 0-initialized and not heat transport;1-heat_transport; + int flowflag; // 0-initialized;1-GROUNDWATER_FLOW;2-LIQUID_FLOW;3-RICHARDS_FLOW;4-FLOW; + int flag_porosity_change; // 0-porosity change not coupled into transport; 1=coupled; + int flag_coupling_hydrology; // 0-without coupling; 1=with coupling; + int flag_calculate_boundary_nodes; // set to zero to avoid precipitation/dissolution (porosity change) at boundary + // nodes + int gem_pressure_flag; // shall we give a constant user defined pressure to gems? + int flag_transport_b; // 1: transport only dissolved components of b vector; 0: transport full speciation + long m_max_failed_nodes; /// maximum number of failed nodes + int flag_disable_gems; // disable gems calculations in main loop ..not for initialization! + //-------------- + + long nNodes; // number of all nodes; + long nElems; // number of all elements; + int GetHeatFlag_MT(void); + int GetFlowType_MT(void); + long GetNodeNumber_MT(void); + long GetElemNumber_MT(void); + void GetFluidProperty_MT(void); + + short GetInitialReactInfoFromMassTransport(int timelevel); + short GetReactInfoFromMassTransport(int timelevel); + short SetReactInfoBackMassTransport(int timelevel); + void GetReactInfoFromGEM(long in, TNode* m_Node); + void SetReactInfoBackGEM(long in, TNode* m_Node); + // necessary for reload with gems + int WriteReloadGem(); + int ReadReloadGem(); + + double GetTempValue_MT(long node_Index, int timelevel); + double GetPressureValue_MT(long node_Index, int timelevel); + short GetDCValue_MT(long node_Index, int timelevel, double* m_DC, double* m_DC_pts, double* m_DC_MT_delta); + short GetBValue_MT(long node_i, int timelevel, double* m_soluteB); + short GetSoComponentValue_MT(long node_Index, int timelevel, double* m_Phase, TNode* m_Node); + double GetDCValueSpecies_MT(long node_Index, int timelevel, int iDc); + short SetTempValue_MT(long node_Index, int timelevel, double temp); + short SetPressureValue_MT(long node_Index, int timelevel, double pressure); + // short SetDCValue_MT(long node_Index, int timelevel, double* m_DC); + short SetBValue_MT(long node_Index, int timelevel, double* m_soluteB); + + int IsThisPointBCIfYesStoreValue(long index, CRFProcess* m_pcs, double& value); /// taken from rf_REACT_BRNS + + /// Copy current values into previous time step values + void CopyCurXDCPre(void); + void UpdateXDCChemDelta(void); + void CopyCurBPre(void); + double CalcSoluteBDelta(long in); + double m_diff_gems; + void RestoreOldSolution(long in); + /// this is only for porosity interpolation to elemens + void ConvPorosityNodeValue2Elem(int i_timestep); + int CalcPorosity(long in, TNode* m_Node); + + double min_possible_porosity, max_possible_porosity; + void ScaleVolume_Water(long in); + + // Set porosity in Mass Transport + int SetPorosityValue_MT(long ele_Index, double m_porosity_Elem, int i_timestep); + int SetSourceSink_MT(long in, double time_step_size /*in sec*/); + + // pass fluid density back + double FluidDensity(long elem, int gaussnode); + + // find which one in xDC vector is water + int FindWater_xDC(TNode* m_Node); + int Findhydrogen_bIC(TNode* m_Node); + int Findoxygen_bIC(TNode* m_Node); + // kg44 11/2008 for kinetics + int CalcReactionRate(long node, double temp, TNode* m_Node); + double SurfaceAreaPh(long kin_phasenr, long in, TNode* m_Node); + + // concentration related + int ConcentrationToMass(long l /*idx of node*/, int i_timestep); + int MassToConcentration(long l /*idx of node*/, int i_timestep, TNode* m_Node); + + // Unit conversion for pressures + double Pressure_Pa_2_Bar(double Pre_in_Pa); + double Pressure_Bar_2_Pa(double Pre_in_Bar); + double Pressure_M_2_Bar(double Pre_in_M, double flu_density); + double Pressure_Bar_2_M(double Pre_in_Bar, double flu_density); + double Pressure_M_2_Pa(double Pre_in_M, double flu_density); + double Pressure_Pa_2_M(double Pre_in_Pa, double flu_density); + // Calculate the volume of the nodes; + // given argument is the index of one particular node; + double GetNodeAdjacentVolume(long Idx_Node); + + // GEMS mass scaling parameter + double gem_mass_scale; + // GEM temperature (without coupling to temperature) + double m_gem_temperature; + // GEM pressure (needed for Richards flow) + double m_gem_pressure; + + /// Definition of buffer variables for MPI + long *m_NodeHandle_buff, *m_NodeStatusCH_buff, *m_IterDone_buff; + // porosity buffer + double *m_porosity_buff, *m_fluid_volume_buff, *m_gas_volume_buff, *m_fluid_density_buff; + double *m_Vs_buff, *m_Ms_buff, *m_Gs_buff, *m_Hs_buff, *m_IC_buff, *m_pH_buff, *m_pe_buff, *m_Eh_buff; + double *m_xDC_buff, *m_xPH_buff, *m_aPH_buff, *m_xPA_buff, *m_excess_water_buff, *m_excess_gas_buff, *m_dul_buff, + *m_dll_buff, *m_Node_Volume_buff, *m_saturation_buff, *m_bIC_buff, *m_bIC_dummy_buff, *m_xDC_pts_buff, + *m_xDC_MT_delta_buff, *m_xDC_Chem_delta_buff; + double* m_bPS_buff; // for Richards flow and gas transport... + // this we need for kinetics + double *omega_phase_buff, *mol_phase_buff, *dmdt_buff, *omega_components_buff; + + // the next two are always defined, such that it also works in serial version + int myrank; + int mysize; + +// MPI implementation #if defined(USE_MPI_GEMS) - void CleanMPIBuffer(void); - void CopyToMPIBuffer(long in); - void GetGEMResult_MPI(void); + void CleanMPIBuffer(void); + void CopyToMPIBuffer(long in); + void GetGEMResult_MPI(void); #endif - - double GetNodePorosityValue( long node_Index); - double GetNodePorosityValueInitial( long node_Index); - double GetNodeFluidDensityValue( long node_Index); - - // Name lists from DCH file! - // const long int - // MaxICN = 6, // IC name length - // MaxDCN = 16, // DC name length - // MaxPHN = 16; // PH name length - char (*m_ICNL)[MaxICN]; // List of IC names in the system, [nIC] of MaxICN length - char (*m_DCNL)[MaxDCN]; // List of DC names in the system, [nDC] of MaxDCN length - char (*m_PHNL)[MaxPHN]; // List of Phase names [nPH] of MaxPHN length + double GetNodePorosityValue(long node_Index); + double GetNodePorosityValueInitial(long node_Index); + double GetNodeFluidDensityValue(long node_Index); + + // Name lists from DCH file! + // const long int + // MaxICN = 6, // IC name length + // MaxDCN = 16, // DC name length + // MaxPHN = 16; // PH name length + char (*m_ICNL)[MaxICN]; // List of IC names in the system, [nIC] of MaxICN length + char (*m_DCNL)[MaxDCN]; // List of DC names in the system, [nDC] of MaxDCN length + char (*m_PHNL)[MaxPHN]; // List of Phase names [nPH] of MaxPHN length #if defined(USE_PETSC) - PetscScalar *gem_glob_buff, *gem_glob_x1 , *gem_glob_x0; - void WriteVTKGEMValuesPETSC(PetscViewer viewer); - // for synchronizing data - void SynchronizeData(PetscScalar *data); - long GetGlobalNodeNumber_MT ( void); - long GetLocalNodeNumber_MT(void); - long loc_NodesNumber_Linear, NodesNumber_Linear,glob_NodesNumber_Linear; + PetscScalar *gem_glob_buff, *gem_glob_x1, *gem_glob_x0; + void WriteVTKGEMValuesPETSC(PetscViewer viewer); + // for synchronizing data + void SynchronizeData(PetscScalar* data); + long GetGlobalNodeNumber_MT(void); + long GetLocalNodeNumber_MT(void); + long loc_NodesNumber_Linear, NodesNumber_Linear, glob_NodesNumber_Linear; #endif - void WriteVTKGEMValues(fstream &vtk_file); - // timer - double GetTimeOfDayDouble(); - - typedef struct - { - //kg44 25.11.2008 kinetics...for coupling with GEMS - // - string phase_name; - int phase_number; - int dc_counter; - int kinetic_model; // only 1 = GEMS implemented right now - int n_activities; // number of species for activities - string active_species[10]; // name for species ...maximum 10 names - - /** this vector holds the kinetic material parameters - * 0,1,2 double E_acid,E_neutral,E_base; // activation energies - * 3-5 double k_acid, k_neutral,k_base; // dissolution/precipitation rate constants - * 6-11 double p1,q1,p2,q2,p2,q2; // exponents for omega - * 12,13, 14 double n_1, n_2, n_3; // exponents for acidic neutral and base cases for species one - * append for each species another set of n_1, n_2, n_3 (up to 10 sets -> up to ten species) - */ - double kinetic_parameters[41]; - int surface_model; // currently only 1 implemented - double surface_area[10]; - int ss_endmembers; // special model for solid solutions...only read for kinetic model == 5 - double *ss_scaling; // special model for solid solutions...only read for kinetic model == 5 - } Kinetic_GEMS; - - vector m_kin; - - // here we define the variables we need for the threads - unsigned int gem_nThread, gem_nbar; // number of threads, number of threads + 1 (number of threads + master that have to cross a barrier) - boost::barrier* gem_barrier_start; // start barrier for calculations - boost::barrier* gem_barrier_finish; //stop barrier when calculations are finished - boost::thread* gemThread; // the gems worker threads - boost::mutex rwmutex; // used to lock during write or read operations..example gem init or write dbrs or cout! - boost::mutex getnode_mutex; // used to lock during getnodeindex - void gems_worker(int tid, string tinit_path); + void WriteVTKGEMValues(fstream& vtk_file); + // timer + double GetTimeOfDayDouble(); + + typedef struct + { + // kg44 25.11.2008 kinetics...for coupling with GEMS + // + string phase_name; + int phase_number; + int dc_counter; + int kinetic_model; // only 1 = GEMS implemented right now + int n_activities; // number of species for activities + string active_species[10]; // name for species ...maximum 10 names + + /** this vector holds the kinetic material parameters + * 0,1,2 double E_acid,E_neutral,E_base; // activation energies + * 3-5 double k_acid, k_neutral,k_base; // dissolution/precipitation rate constants + * 6-11 double p1,q1,p2,q2,p2,q2; // exponents for omega + * 12,13, 14 double n_1, n_2, n_3; // exponents for acidic neutral and base cases for species one + * append for each species another set of n_1, n_2, n_3 (up to 10 sets -> up to ten species) + */ + double kinetic_parameters[41]; + int surface_model; // currently only 1 implemented + double surface_area[10]; + int ss_endmembers; // special model for solid solutions...only read for kinetic model == 5 + double* ss_scaling; // special model for solid solutions...only read for kinetic model == 5 + } Kinetic_GEMS; + + vector m_kin; + + // here we define the variables we need for the threads + unsigned int gem_nThread, + gem_nbar; // number of threads, number of threads + 1 (number of threads + master that have to cross a barrier) + boost::barrier* gem_barrier_start; // start barrier for calculations + boost::barrier* gem_barrier_finish; // stop barrier when calculations are finished + boost::thread* gemThread; // the gems worker threads + boost::mutex rwmutex; // used to lock during write or read operations..example gem init or write dbrs or cout! + boost::mutex getnode_mutex; // used to lock during getnodeindex + void gems_worker(int tid, string tinit_path); }; - #define GEM_FILE_EXTENSION ".gem" /** This is the function for reading the OGS-GEM specific parameters. * Todo: if .gems not exist, decouple gems */ -extern bool GEMRead(string base_file_name, REACT_GEM *m_GEM_p); +extern bool GEMRead(string base_file_name, REACT_GEM* m_GEM_p); #endif #endif diff --git a/FEM/rf_bc_new.cpp b/FEM/rf_bc_new.cpp index a72def611..a462dffca 100644 --- a/FEM/rf_bc_new.cpp +++ b/FEM/rf_bc_new.cpp @@ -89,7 +89,7 @@ CBoundaryConditionNode::CBoundaryConditionNode() _normal_vector[i] = 0; } -void CBoundaryConditionNode::SetNormalVector(double const*const normal_vector) +void CBoundaryConditionNode::SetNormalVector(double const* const normal_vector) { _normal_vector[0] = normal_vector[0]; _normal_vector[1] = normal_vector[1]; @@ -143,21 +143,20 @@ std::vector bc_db_vector; Programing: 01/2004 OK Implementation **************************************************************************/ -CBoundaryCondition::CBoundaryCondition() : - GeoInfo (), geo_name (""), _curve_index (-1), dis_linear_f(NULL) +CBoundaryCondition::CBoundaryCondition() : GeoInfo(), geo_name(""), _curve_index(-1), dis_linear_f(NULL) { this->setProcessDistributionType(FiniteElement::INVALID_DIS_TYPE); // FCT conditional = false; time_dep_interpol = false; - epsilon = 1e-9; //NW - time_contr_curve = -1; //WX - bcExcav = -1; //WX - MatGr = -1; //WX - NoDispIncre = -1; //WX:12.2012 - gradient_ref_depth = 0; //CB - gradient_ref_depth_value = 0; //CB - gradient_ref_depth_gradient = 0; //CB + epsilon = 1e-9; // NW + time_contr_curve = -1; // WX + bcExcav = -1; // WX + MatGr = -1; // WX + NoDispIncre = -1; // WX:12.2012 + gradient_ref_depth = 0; // CB + gradient_ref_depth_value = 0; // CB + gradient_ref_depth_gradient = 0; // CB _pressure_as_head_model = -1; _pressure_as_head_density = 0; _isConstrainedBC = false; @@ -167,11 +166,10 @@ CBoundaryCondition::CBoundaryCondition() : // KR: Conversion from GUI-BC-object to CBoundaryCondition CBoundaryCondition::CBoundaryCondition(const BoundaryCondition* bc) - : ProcessInfo(bc->getProcessType(),bc->getProcessPrimaryVariable(),NULL), - GeoInfo(bc->getGeoType(),bc->getGeoObj()), - DistributionInfo(bc->getProcessDistributionType()) + : ProcessInfo(bc->getProcessType(), bc->getProcessPrimaryVariable(), NULL), + GeoInfo(bc->getGeoType(), bc->getGeoObj()), DistributionInfo(bc->getProcessDistributionType()) { - setProcess( PCSGet( this->getProcessType() ) ); + setProcess(PCSGet(this->getProcessType())); this->geo_name = bc->getGeoName(); const std::vector dis_nodes = bc->getDisNodes(); const std::vector dis_values = bc->getDisValues(); @@ -182,7 +180,7 @@ CBoundaryCondition::CBoundaryCondition(const BoundaryCondition* bc) } else if (this->getProcessDistributionType() == FiniteElement::LINEAR) { - for (size_t i=0; i_PointsHaveDistribedBC.push_back(static_cast(dis_nodes[i])); this->_DistribedBC.push_back(dis_values[i]); @@ -191,7 +189,8 @@ CBoundaryCondition::CBoundaryCondition(const BoundaryCondition* bc) else std::cout << "Error in CBoundaryCondition() - DistributionType \"" << FiniteElement::convertDisTypeToString(this->getProcessDistributionType()) - << "\" currently not supported." << "\n"; + << "\" currently not supported." + << "\n"; } /************************************************************************** @@ -207,13 +206,13 @@ CBoundaryCondition::~CBoundaryCondition() geo_node_number = -1; geo_node_value = 0.0; - //WW - if(dis_linear_f) + // WW + if (dis_linear_f) delete dis_linear_f; dis_linear_f = NULL; } -const std::string& CBoundaryCondition::getGeoName () const +const std::string& CBoundaryCondition::getGeoName() const { return geo_name; } @@ -229,22 +228,22 @@ const std::string& CBoundaryCondition::getGeoName () const std::ios::pos_type CBoundaryCondition::Read(std::ifstream* bc_file, const GEOLIB::GEOObjects& geo_obj, const std::string& unique_fname, - bool & valid) + bool& valid) { std::string line_string; bool new_keyword = false; std::ios::pos_type position; std::string sub_string, strbuff; - int ibuff; //pos, - double dbuff; //WW + int ibuff; // pos, + double dbuff; // WW std::stringstream in; // Schleife ueber alle Phasen bzw. Komponenten while (!new_keyword) { position = bc_file->tellg(); - line_string = readNonBlankLineFromInputStream (*bc_file); + line_string = readNonBlankLineFromInputStream(*bc_file); if (line_string.size() < 1) break; if (line_string.find("#") != std::string::npos) @@ -254,34 +253,34 @@ std::ios::pos_type CBoundaryCondition::Read(std::ifstream* bc_file, } if (line_string.find("$PCS_TYPE") != std::string::npos) - if (!FileIO::ProcessIO::readProcessInfo (*bc_file, _pcs_type)) + if (!FileIO::ProcessIO::readProcessInfo(*bc_file, _pcs_type)) valid = false; if (line_string.find("$PRIMARY_VARIABLE") != std::string::npos) { in.str(readNonBlankLineFromInputStream(*bc_file)); std::string tmp; - in >> tmp; // _pcs_pv_name; - if ( this->_pcs_type == FiniteElement::MASS_TRANSPORT ) + in >> tmp; // _pcs_pv_name; + if (this->_pcs_type == FiniteElement::MASS_TRANSPORT) { // HS set the pointer to MCP based on component name. // a check whether this name is existing and unique. - if ( cp_name_2_idx.count( tmp ) == 1 ) + if (cp_name_2_idx.count(tmp) == 1) { - setProcess(cp_vec[cp_name_2_idx[tmp]]->getProcess() ); - setProcessPrimaryVariable( FiniteElement::CONCENTRATION ); + setProcess(cp_vec[cp_name_2_idx[tmp]]->getProcess()); + setProcessPrimaryVariable(FiniteElement::CONCENTRATION); } else { DisplayErrorMsg( - "Error: In reading BC file, the input component names are not found in MCP file!!!"); + "Error: In reading BC file, the input component names are not found in MCP file!!!"); exit(1); } } else { - setProcess( PCSGet( this->getProcessType() ) ); - setProcessPrimaryVariable (FiniteElement::convertPrimaryVariable (tmp)); + setProcess(PCSGet(this->getProcessType())); + setProcessPrimaryVariable(FiniteElement::convertPrimaryVariable(tmp)); } in.clear(); } @@ -291,20 +290,20 @@ std::ios::pos_type CBoundaryCondition::Read(std::ifstream* bc_file, { in.str(readNonBlankLineFromInputStream(*bc_file)); std::string tmp; - in >> tmp; // _pcs_pv_name; - if ( this->_pcs_type == FiniteElement::MASS_TRANSPORT ) + in >> tmp; // _pcs_pv_name; + if (this->_pcs_type == FiniteElement::MASS_TRANSPORT) { // HS set the pointer to MCP based on component name. // check whether this name is existing and unique. - if ( cp_name_2_idx.count( tmp ) == 1 ) + if (cp_name_2_idx.count(tmp) == 1) { - setProcess(cp_vec[cp_name_2_idx[tmp]]->getProcess() ); - setProcessPrimaryVariable( FiniteElement::CONCENTRATION ); + setProcess(cp_vec[cp_name_2_idx[tmp]]->getProcess()); + setProcessPrimaryVariable(FiniteElement::CONCENTRATION); } else { DisplayErrorMsg( - "Error: In reading BC file, the input component names are not found in MCP file!!!"); + "Error: In reading BC file, the input component names are not found in MCP file!!!"); exit(1); } } @@ -312,15 +311,14 @@ std::ios::pos_type CBoundaryCondition::Read(std::ifstream* bc_file, } if (line_string.find("$GEO_TYPE") != std::string::npos) - if (!FileIO::GeoIO::readGeoInfo (this, *bc_file, geo_name, geo_obj, - unique_fname)) + if (!FileIO::GeoIO::readGeoInfo(this, *bc_file, geo_name, geo_obj, unique_fname)) valid = false; - //PCH + // PCH if (line_string.find("$DIS_TYPE") != std::string::npos) { in.str(readNonBlankLineFromInputStream(*bc_file)); - in >> line_string; //sub_line + in >> line_string; // sub_line _periodic = false; // JOD // Source terms are assign to element nodes directly. 23.02.2009. WW @@ -335,7 +333,7 @@ std::ios::pos_type CBoundaryCondition::Read(std::ifstream* bc_file, if (line_string.find("CONSTANT") != std::string::npos) { this->setProcessDistributionType(FiniteElement::CONSTANT); - in >> geo_node_value; //sub_line + in >> geo_node_value; // sub_line in.clear(); } @@ -347,7 +345,7 @@ std::ios::pos_type CBoundaryCondition::Read(std::ifstream* bc_file, // read process in >> tempst; _switchBC.switchProcessType = FiniteElement::convertProcessType(tempst); - if(_switchBC.switchProcessType == FiniteElement::INVALID_PROCESS) + if (_switchBC.switchProcessType == FiniteElement::INVALID_PROCESS) { std::cerr << "Invalid Process type in SWITCH BC! Exiting now." << std::endl; std::exit(0); @@ -388,7 +386,7 @@ std::ios::pos_type CBoundaryCondition::Read(std::ifstream* bc_file, this->setProcessDistributionType(FiniteElement::LINEAR); // Distribuded. WW size_t nLBC; - in >> nLBC; //sub_line + in >> nLBC; // sub_line in.clear(); for (size_t i = 0; i < nLBC; i++) @@ -413,9 +411,9 @@ std::ios::pos_type CBoundaryCondition::Read(std::ifstream* bc_file, if (line_string.find("GRADIENT") != std::string::npos) // 6/2012 JOD { this->setProcessDistributionType(FiniteElement::GRADIENT); - in >> gradient_ref_depth; - in >> gradient_ref_depth_value; - in >> gradient_ref_depth_gradient; + in >> gradient_ref_depth; + in >> gradient_ref_depth_value; + in >> gradient_ref_depth_gradient; in.clear(); } @@ -429,7 +427,7 @@ std::ios::pos_type CBoundaryCondition::Read(std::ifstream* bc_file, if (line_string.find("CURVE") != std::string::npos) { // tim_type_name = "CURVE"; - //WW this->setProcessDistributionType(FiniteElement::CONSTANT); + // WW this->setProcessDistributionType(FiniteElement::CONSTANT); in >> _curve_index; in.clear(); @@ -443,14 +441,14 @@ std::ios::pos_type CBoundaryCondition::Read(std::ifstream* bc_file, if (line_string.find("$FCT_TYPE") != std::string::npos) { in.str(readNonBlankLineFromInputStream(*bc_file)); - in >> fct_name; //sub_line + in >> fct_name; // sub_line in.clear(); } if (line_string.find("$MSH_TYPE") != std::string::npos) { in.str(readNonBlankLineFromInputStream(*bc_file)); - in >> sub_string; //sub_line + in >> sub_string; // sub_line _msh_type_name = "NODE"; if (sub_string.find("NODE") != std::string::npos) { @@ -471,8 +469,7 @@ std::ios::pos_type CBoundaryCondition::Read(std::ifstream* bc_file, } in.str(readNonBlankLineFromInputStream(*bc_file)); // 0.0 IF HEAD > 0.04 std::string pcs_pv_name_cond; // 07/2010 TF temp string - in >> node_value_cond >> line_string >> pcs_pv_name_cond - >> line_string >> condition; + in >> node_value_cond >> line_string >> pcs_pv_name_cond >> line_string >> condition; in.clear(); in.str(readNonBlankLineFromInputStream(*bc_file)); // PCS OVERLAND_FLOW std::string pcs_type_name_cond; @@ -488,7 +485,7 @@ std::ios::pos_type CBoundaryCondition::Read(std::ifstream* bc_file, in.clear(); } //.................................................................... - //aktive state of the bc is time controlled WX + // aktive state of the bc is time controlled WX if (line_string.find("$TIME_CONTROLLED_ACTIVE") != std::string::npos) { in.str(readNonBlankLineFromInputStream(*bc_file)); @@ -496,7 +493,7 @@ std::ios::pos_type CBoundaryCondition::Read(std::ifstream* bc_file, in.clear(); } //.................................................................... - //bc for excated boundaries WX + // bc for excated boundaries WX if (line_string.find("$EXCAVATION") != std::string::npos) { in.str(readNonBlankLineFromInputStream(*bc_file)); @@ -504,20 +501,20 @@ std::ios::pos_type CBoundaryCondition::Read(std::ifstream* bc_file, in.clear(); } //.................................................................... - //NO DISPLACEMENT INCREMENT WX:12.2012 + // NO DISPLACEMENT INCREMENT WX:12.2012 if (line_string.find("$NO_DISP_INCREMENT") != std::string::npos) { in.str(readNonBlankLineFromInputStream(*bc_file)); in >> NoDispIncre; in.clear(); } - //.................................................................... - //bc for copying of primary variables; give geometry type and name SB 09.2012 + //.................................................................... + // bc for copying of primary variables; give geometry type and name SB 09.2012 if (line_string.find("$COPY_VALUE") != std::string::npos) { // CB_merge_0513 ?? in.str(readNonBlankLineFromInputStream(*bc_file)); - //in.str(GetLineFromFile1(bc_file)); + // in.str(GetLineFromFile1(bc_file)); in >> copy_geom >> copy_geom_name; in.clear(); } @@ -544,7 +541,8 @@ std::ios::pos_type CBoundaryCondition::Read(std::ifstream* bc_file, in.str(readNonBlankLineFromInputStream(*bc_file)); std::string tempst, tempst2; - in >> tempst >> tempst2; //VELOCITY and DIRECTION (positive/negative scalar product between velocity vector and surface normal); or PROCESS_TYPE and associated PRIMARY_VARIABLE + in >> tempst >> tempst2; // VELOCITY and DIRECTION (positive/negative scalar product between velocity vector + // and surface normal); or PROCESS_TYPE and associated PRIMARY_VARIABLE if (tempst == "VELOCITY") { temp.constrainedVariable = convertConstrainedVariable(tempst); @@ -552,10 +550,12 @@ std::ios::pos_type CBoundaryCondition::Read(std::ifstream* bc_file, temp.constrainedValue = std::numeric_limits::max(); temp.constrainedPrimVar = FiniteElement::INVALID_PV; temp.constrainedProcessType = FiniteElement::INVALID_PROCESS; - if ( !(temp.constrainedDirection == ConstrainedType::POSITIVE || temp.constrainedDirection == ConstrainedType::NEGATIVE)) + if (!(temp.constrainedDirection == ConstrainedType::POSITIVE + || temp.constrainedDirection == ConstrainedType::NEGATIVE)) { - std::cout << "No valid constrainedDirection for " << convertConstrainedVariableToString(temp.constrainedVariable) - << "(" << tempst2 << ")" << std::endl; + std::cout << "No valid constrainedDirection for " + << convertConstrainedVariableToString(temp.constrainedVariable) << "(" << tempst2 << ")" + << std::endl; _isConstrainedBC = false; } @@ -569,33 +569,40 @@ std::ios::pos_type CBoundaryCondition::Read(std::ifstream* bc_file, else { temp.constrainedProcessType = FiniteElement::convertProcessType(tempst); - if ( !(temp.constrainedProcessType == FiniteElement::MASS_TRANSPORT || - temp.constrainedProcessType == FiniteElement::HEAT_TRANSPORT || - temp.constrainedProcessType == FiniteElement::LIQUID_FLOW || - temp.constrainedProcessType == FiniteElement::RICHARDS_FLOW) ) { + if (!(temp.constrainedProcessType == FiniteElement::MASS_TRANSPORT + || temp.constrainedProcessType == FiniteElement::HEAT_TRANSPORT + || temp.constrainedProcessType == FiniteElement::LIQUID_FLOW + || temp.constrainedProcessType == FiniteElement::RICHARDS_FLOW)) + { _isConstrainedBC = false; break; } temp.constrainedPrimVar = FiniteElement::convertPrimaryVariable(tempst2); - in >> temp.constrainedValue >> tempst; //Constrained Value; and constrain direction (greater/smaller than value) + in >> temp.constrainedValue + >> tempst; // Constrained Value; and constrain direction (greater/smaller than value) temp.constrainedDirection = convertConstrainedType(tempst); temp.constrainedVariable = ConstrainedVariable::INVALID_CONSTRAINED_VARIABLE; - if ( !(temp.constrainedDirection == ConstrainedType::SMALLER || temp.constrainedDirection == ConstrainedType::GREATER)) + if (!(temp.constrainedDirection == ConstrainedType::SMALLER + || temp.constrainedDirection == ConstrainedType::GREATER)) { - std::cout << "No valid constrainedDirection for " << FiniteElement::convertProcessTypeToString(temp.constrainedProcessType) - << " (" << tempst << ")" << std::endl; + std::cout << "No valid constrainedDirection for " + << FiniteElement::convertProcessTypeToString(temp.constrainedProcessType) << " (" + << tempst << ")" << std::endl; _isConstrainedBC = false; } - in >> tempst; //Seepage face option (set BC to constrained value, if calculated value > constrained value) + in >> tempst; // Seepage face option (set BC to constrained value, if calculated value > constrained + // value) if (tempst == "SEEPAGE") { if (temp.constrainedDirection == ConstrainedType::SMALLER) temp._isSeepageBC = true; else - std::cout << "Seepage not used as constrained direction is not set to SMALLER.\n Please check .bc file." << std::endl; + std::cout << "Seepage not used as constrained direction is not set to SMALLER.\n Please check " + ".bc file." + << std::endl; } } if (_isConstrainedBC) @@ -603,7 +610,6 @@ std::ios::pos_type CBoundaryCondition::Read(std::ifstream* bc_file, in.clear(); } //.................................................................... - } return position; } @@ -615,7 +621,7 @@ std::ios::pos_type CBoundaryCondition::Read(std::ifstream* bc_file, // 10/2008 OK NOD // 06/2009 OK MSH_TYPE off // **************************************************************************/ -//void CBoundaryCondition::Write(std::fstream* rfd_file) const +// void CBoundaryCondition::Write(std::fstream* rfd_file) const //{ // //KEYWORD // *rfd_file << "#BOUNDARY_CONDITION" << "\n"; @@ -692,87 +698,80 @@ void CBoundaryCondition::WriteTecplot(std::fstream* tec_file) const long no_points = 0; std::vector triangle_vector; - *tec_file << "VARIABLES = X,Y,Z,V1" << "\n"; + *tec_file << "VARIABLES = X,Y,Z,V1" + << "\n"; - if (getGeoType () == GEOLIB::SURFACE) + if (getGeoType() == GEOLIB::SURFACE) { - m_surface = GEOGetSFCByName(geo_name); //CC + m_surface = GEOGetSFCByName(geo_name); // CC if (m_surface) switch (m_surface->type) { - case 2: - p = m_surface->polyline_of_surface_vector.begin(); - while (p != m_surface->polyline_of_surface_vector.end()) - { - m_polyline1 = *p; - ++p; - m_polyline2 = *p; + case 2: + p = m_surface->polyline_of_surface_vector.begin(); + while (p != m_surface->polyline_of_surface_vector.end()) + { + m_polyline1 = *p; + ++p; + m_polyline2 = *p; + break; + } + no_points = (long)m_polyline1->point_vector.size(); + /* + for(i=0;ix[0] = m_polyline1->point_vector[i]->x; + m_triangle->y[0] = m_polyline1->point_vector[i]->y; + m_triangle->z[0] = m_polyline1->point_vector[i]->z; + m_triangle->x[1] = m_polyline1->point_vector[i+1]->x; + m_triangle->y[1] = m_polyline1->point_vector[i+1]->y; + m_triangle->z[1] = m_polyline1->point_vector[i+1]->z; + m_triangle->x[2] = m_polyline2->point_vector[i+1]->x; + m_triangle->y[2] = m_polyline2->point_vector[i+1]->y; + m_triangle->z[2] = m_polyline2->point_vector[i+1]->z; + triangle_vector.push_back(m_triangle); + m_triangle = new CTriangle; + m_triangle->x[0] = m_polyline2->point_vector[i]->x; + m_triangle->y[0] = m_polyline2->point_vector[i]->y; + m_triangle->z[0] = m_polyline2->point_vector[i]->z; + m_triangle->x[1] = m_polyline2->point_vector[i+1]->x; + m_triangle->y[1] = m_polyline2->point_vector[i+1]->y; + m_triangle->z[1] = m_polyline2->point_vector[i+1]->z; + m_triangle->x[2] = m_polyline1->point_vector[i+1]->x; + m_triangle->y[2] = m_polyline1->point_vector[i+1]->y; + m_triangle->z[2] = m_polyline1->point_vector[i+1]->z; + triangle_vector.push_back(m_triangle); + } + */ break; - } - no_points = (long) m_polyline1->point_vector.size(); - /* - for(i=0;ix[0] = m_polyline1->point_vector[i]->x; - m_triangle->y[0] = m_polyline1->point_vector[i]->y; - m_triangle->z[0] = m_polyline1->point_vector[i]->z; - m_triangle->x[1] = m_polyline1->point_vector[i+1]->x; - m_triangle->y[1] = m_polyline1->point_vector[i+1]->y; - m_triangle->z[1] = m_polyline1->point_vector[i+1]->z; - m_triangle->x[2] = m_polyline2->point_vector[i+1]->x; - m_triangle->y[2] = m_polyline2->point_vector[i+1]->y; - m_triangle->z[2] = m_polyline2->point_vector[i+1]->z; - triangle_vector.push_back(m_triangle); - m_triangle = new CTriangle; - m_triangle->x[0] = m_polyline2->point_vector[i]->x; - m_triangle->y[0] = m_polyline2->point_vector[i]->y; - m_triangle->z[0] = m_polyline2->point_vector[i]->z; - m_triangle->x[1] = m_polyline2->point_vector[i+1]->x; - m_triangle->y[1] = m_polyline2->point_vector[i+1]->y; - m_triangle->z[1] = m_polyline2->point_vector[i+1]->z; - m_triangle->x[2] = m_polyline1->point_vector[i+1]->x; - m_triangle->y[2] = m_polyline1->point_vector[i+1]->y; - m_triangle->z[2] = m_polyline1->point_vector[i+1]->z; - triangle_vector.push_back(m_triangle); - } - */ - break; } } long no_nodes = 2 * no_points; - //long no_elements = triangle_vector.size(); + // long no_elements = triangle_vector.size(); long no_elements = 2 * (no_points - 1); // Write *tec_file << "ZONE T = " << geo_name << ", " << "N = " << no_nodes << ", " << "E = " << no_elements << ", " - << "F = FEPOINT" << ", " << "ET = TRIANGLE" << "\n"; - if(m_polyline1) - for(i = 0; i < no_points; i++) - *tec_file - << m_polyline1->point_vector[i]->x << " " << - m_polyline1->point_vector[i]->y << " " << - m_polyline1->point_vector[i]->z << - " " \ - << geo_node_value << "\n"; - - if(m_polyline2) - for(i = 0; i < no_points; i++) - *tec_file \ - << m_polyline2->point_vector[i]->x << " " << - m_polyline2->point_vector[i]->y << " " << - m_polyline2->point_vector[i]->z << - " " \ - << geo_node_value << "\n"; - - for(i = 0; i < no_points - 1; i++) - *tec_file \ - << i + 1 << " " << i + 1 + 1 << " " << no_points + i + 1 << "\n"; - for(i = 0; i < no_points - 1; i++) - *tec_file \ - << no_points + i + 1 << " " << no_points + i + 1 + 1 << " " << i + 1 + 1 << - "\n"; + << "F = FEPOINT" + << ", " + << "ET = TRIANGLE" + << "\n"; + if (m_polyline1) + for (i = 0; i < no_points; i++) + *tec_file << m_polyline1->point_vector[i]->x << " " << m_polyline1->point_vector[i]->y << " " + << m_polyline1->point_vector[i]->z << " " << geo_node_value << "\n"; + + if (m_polyline2) + for (i = 0; i < no_points; i++) + *tec_file << m_polyline2->point_vector[i]->x << " " << m_polyline2->point_vector[i]->y << " " + << m_polyline2->point_vector[i]->z << " " << geo_node_value << "\n"; + + for (i = 0; i < no_points - 1; i++) + *tec_file << i + 1 << " " << i + 1 + 1 << " " << no_points + i + 1 << "\n"; + for (i = 0; i < no_points - 1; i++) + *tec_file << no_points + i + 1 << " " << no_points + i + 1 + 1 << " " << i + 1 + 1 << "\n"; } /************************************************************************** @@ -784,8 +783,7 @@ void CBoundaryCondition::WriteTecplot(std::fstream* tec_file) const 01/2005 OK Destruct before read 05/2010 TF changes due to new GEOLIB integration, some improvements **************************************************************************/ -bool BCRead(std::string const& file_base_name, const GEOLIB::GEOObjects& geo_obj, - const std::string& unique_name) +bool BCRead(std::string const& file_base_name, const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) { char line[MAX_ZEILE]; std::string line_string, bc_file_name; @@ -796,7 +794,8 @@ bool BCRead(std::string const& file_base_name, const GEOLIB::GEOObjects& geo_obj std::ifstream bc_file(bc_file_name.data(), std::ios::in); if (!bc_file.good()) { - std::cout << "! Error in BCRead: No boundary conditions !" << "\n"; + std::cout << "! Error in BCRead: No boundary conditions !" + << "\n"; return false; } @@ -808,16 +807,15 @@ bool BCRead(std::string const& file_base_name, const GEOLIB::GEOObjects& geo_obj line_string = line; if (line_string.find("#STOP") != std::string::npos) { - std::cout << "done, read " << bc_list.size() - << " boundary conditions" << "\n"; + std::cout << "done, read " << bc_list.size() << " boundary conditions" + << "\n"; return true; } if (line_string.find("#BOUNDARY_CONDITION") != std::string::npos) { CBoundaryCondition* bc(new CBoundaryCondition()); - bool valid (true); - std::ios::pos_type position = bc->Read(&bc_file, geo_obj, - unique_name, valid); + bool valid(true); + std::ios::pos_type position = bc->Read(&bc_file, geo_obj, unique_name, valid); if (valid) bc_list.push_back(bc); else @@ -842,19 +840,18 @@ void BCWrite(std::string const& base_file_name) std::string line_string; // File handling - std::string bc_file_name (base_file_name + BC_FILE_EXTENSION); + std::string bc_file_name(base_file_name + BC_FILE_EXTENSION); std::fstream bc_file(bc_file_name.data(), std::ios::trunc | std::ios::out); bc_file.setf(std::ios::scientific, std::ios::floatfield); bc_file.precision(12); - //OK string tec_file_name = base_file_name + ".tec"; - //OK fstream tec_file (tec_file_name.data(),ios::trunc|ios::out); - //OK tec_file.setf(ios::scientific,ios::floatfield); - //OK tec_file.precision(12); + // OK string tec_file_name = base_file_name + ".tec"; + // OK fstream tec_file (tec_file_name.data(),ios::trunc|ios::out); + // OK tec_file.setf(ios::scientific,ios::floatfield); + // OK tec_file.precision(12); if (!bc_file.good()) return; bc_file.seekg(0L, std::ios::beg); // rewind? - bc_file << - "GeoSys-BC: Boundary Conditions ------------------------------------------------\n"; + bc_file << "GeoSys-BC: Boundary Conditions ------------------------------------------------\n"; //======================================================================== // BC list std::list::const_iterator p_bc = bc_list.begin(); @@ -865,7 +862,7 @@ void BCWrite(std::string const& base_file_name) } bc_file << "#STOP"; bc_file.close(); - //OK tec_file.close(); + // OK tec_file.close(); } /************************************************************************** @@ -873,7 +870,7 @@ void BCWrite(std::string const& base_file_name) 01/2004 OK Implementation 07/2007 OK V2, global function **************************************************************************/ -//CBoundaryCondition* BCGet(const std::string &pcs_name, const std::string &geo_type_name, +// CBoundaryCondition* BCGet(const std::string &pcs_name, const std::string &geo_type_name, // const std::string &geo_name) //{ // std::list::const_iterator p_bc = bc_list.begin(); @@ -905,12 +902,11 @@ inline void CBoundaryCondition::DirectAssign(long ShiftInNodeVector) //======================================================================== // File handling std::ifstream d_file(fname.c_str(), std::ios::in); - //if (!st_file.good()) return; + // if (!st_file.good()) return; if (!d_file.good()) { - std::cout << "! Error in direct node source terms: Could not find file:!\n" - << fname << "\n"; + std::cout << "! Error in direct node source terms: Could not find file:!\n" << fname << "\n"; abort(); } // Rewind the file @@ -935,7 +931,7 @@ inline void CBoundaryCondition::DirectAssign(long ShiftInNodeVector) m_node_value->CurveIndex = _curve_index; m_pcs->bc_node.push_back(this); m_pcs->bc_node_value.push_back(m_node_value); - } // eof + } // eof } /************************************************************************** @@ -950,8 +946,7 @@ inline void CBoundaryCondition::PatchAssign(long ShiftInNodeVector) std::vector sfc_nodes; CBoundaryConditionNode* m_node_value = NULL; - CRFProcess* pcs( - PCSGet(convertProcessTypeToString(this->getProcessType()))); + CRFProcess* pcs(PCSGet(convertProcessTypeToString(this->getProcessType()))); Surface* surface(GEOGetSFCByName(geo_name)); // File handling @@ -959,9 +954,7 @@ inline void CBoundaryCondition::PatchAssign(long ShiftInNodeVector) if (!d_file.good()) { - std::cout - << "! Error in direct node source terms: Could not find file:!\n" - << fname << "\n"; + std::cout << "! Error in direct node source terms: Could not find file:!\n" << fname << "\n"; abort(); } // Rewind the file @@ -999,7 +992,7 @@ inline void CBoundaryCondition::PatchAssign(long ShiftInNodeVector) CBoundaryConditionsGroup::CBoundaryConditionsGroup(void) { - msh_node_number_subst = -1; // + msh_node_number_subst = -1; // time_dep_bc = -1; } @@ -1030,20 +1023,19 @@ CBoundaryConditionsGroup::~CBoundaryConditionsGroup(void) 10/2008 WW/CB SetTransientBCtoNodes last modification: **************************************************************************/ -void CBoundaryConditionsGroup::Set(CRFProcess* pcs, int ShiftInNodeVector, - const std::string& this_pv_name) +void CBoundaryConditionsGroup::Set(CRFProcess* pcs, int ShiftInNodeVector, const std::string& this_pv_name) { // long number_of_nodes = 0; - long i, j; //WX + long i, j; // WX long* nodes = NULL; std::vector nodes_vector; std::vector node_value; CGLPolyline* m_polyline = NULL; -// CBoundaryCondition *m_bc = NULL; + // CBoundaryCondition *m_bc = NULL; CBoundaryConditionNode* m_node_value = NULL; group_name = _pcs_type_name; bool quadratic = false; - bool cont = false; //WW + bool cont = false; // WW if (!this_pv_name.empty()) _pcs_pv_name = this_pv_name; @@ -1053,13 +1045,13 @@ void CBoundaryConditionsGroup::Set(CRFProcess* pcs, int ShiftInNodeVector, if (!m_msh) std::cout << "Warning in CBoundaryConditionsGroup::Set - no MSH data" << "\n"; - //return; - if (m_msh) //WW + // return; + if (m_msh) // WW { /// In case of P_U coupling monolithic scheme - if (pcs->type == 41) //WW Mono + if (pcs->type == 41) // WW Mono { - //Deform + // Deform if (_pcs_pv_name.find("DISPLACEMENT") != std::string::npos || _pcs_pv_name.find("VELOCITY_DM") != std::string::npos) quadratic = true; @@ -1076,32 +1068,31 @@ void CBoundaryConditionsGroup::Set(CRFProcess* pcs, int ShiftInNodeVector, FiniteElement::PrimaryVariable primary_variable(FiniteElement::convertPrimaryVariable(_pcs_pv_name)); std::list::const_iterator p_bc = bc_list.begin(); - clock_t start_time (clock()); + clock_t start_time(clock()); while (p_bc != bc_list.end()) { - CBoundaryCondition* bc (*p_bc); - if (bc->time_dep_interpol) //WW/CB + CBoundaryCondition* bc(*p_bc); + if (bc->time_dep_interpol) // WW/CB { ++p_bc; continue; } - if ((bc->getProcess() == pcs) && - (bc->getProcessPrimaryVariable() == primary_variable)) + if ((bc->getProcess() == pcs) && (bc->getProcessPrimaryVariable() == primary_variable)) { cont = false; //------------------------------------------------------------------ - if (bc->getExcav()>0||bc->getGeoType()==GEOLIB::GEODOMAIN) - //WX: 01.2011. boundary conditions for excavation. 03.2011. Material domain BC + if (bc->getExcav() > 0 || bc->getGeoType() == GEOLIB::GEODOMAIN) + // WX: 01.2011. boundary conditions for excavation. 03.2011. Material domain BC { - //GEOGetNodesInMaterialDomain(m_msh, m_bc->getExcavMatGr(),nodes_vector, quadratic); + // GEOGetNodesInMaterialDomain(m_msh, m_bc->getExcavMatGr(),nodes_vector, quadratic); size_t ii; long Size; int nn = 0, Domain_MG = -1; bool exist; - if(bc->getGeoType()==GEOLIB::GEODOMAIN) + if (bc->getGeoType() == GEOLIB::GEODOMAIN) Domain_MG = atoi(bc->geo_name.c_str()); MeshLib::CElem* elem = NULL; nodes_vector.resize(0); @@ -1109,42 +1100,40 @@ void CBoundaryConditionsGroup::Set(CRFProcess* pcs, int ShiftInNodeVector, { elem = m_msh->ele_vector[ii]; nn = elem->GetNodesNumber(quadratic); - if(elem->GetPatchIndex()==static_cast(bc->getExcavMatGr()) - || static_cast(elem->GetPatchIndex())==Domain_MG) + if (elem->GetPatchIndex() == static_cast(bc->getExcavMatGr()) + || static_cast(elem->GetPatchIndex()) == Domain_MG) { Size = (int)nodes_vector.size(); - for(i = 0; i < nn; i++) + for (i = 0; i < nn; i++) { exist = false; - for(j = 0; j < Size; j++) - if(elem->GetNodeIndex(i) == - nodes_vector[j]) + for (j = 0; j < Size; j++) + if (elem->GetNodeIndex(i) == nodes_vector[j]) { exist = true; break; } - if(!exist) - nodes_vector.push_back( - elem->GetNodeIndex(i)); + if (!exist) + nodes_vector.push_back(elem->GetNodeIndex(i)); } } } - for (i = 0; i < (long) nodes_vector.size(); i++) //possible nodes - //for(int j=0; jnod_vector[nodes_vector[i]]->connected_elements.size(); j++){ - //if(m_msh->ele_vector[m_msh->nod_vector[nodes_vector[i]]->connected_elements[j]]->GetPatchIndex()==m_bc->getExcavMatGr()) + for (i = 0; i < (long)nodes_vector.size(); i++) // possible nodes + // for(int j=0; jnod_vector[nodes_vector[i]]->connected_elements.size(); j++){ + // if(m_msh->ele_vector[m_msh->nod_vector[nodes_vector[i]]->connected_elements[j]]->GetPatchIndex()==m_bc->getExcavMatGr()) { m_node_value = new CBoundaryConditionNode(); m_node_value->msh_node_number = -1; - m_node_value->msh_node_number = nodes_vector[i] + - ShiftInNodeVector; //nodes[i]; - m_node_value->geo_node_number = nodes_vector[i]; //nodes[i]; + m_node_value->msh_node_number = nodes_vector[i] + ShiftInNodeVector; // nodes[i]; + m_node_value->geo_node_number = nodes_vector[i]; // nodes[i]; m_node_value->node_value = bc->geo_node_value; - m_node_value->pcs_pv_name = _pcs_pv_name; //YD/WW + m_node_value->pcs_pv_name = _pcs_pv_name; // YD/WW m_node_value->CurveIndex = bc->getCurveIndex(); - pcs->bc_node.push_back(bc); //WW - pcs->bc_node_value.push_back(m_node_value); //WW - //j=m_msh->nod_vector[nodes_vector[i]]->connected_elements.size(); //only on material group boundary is selected + pcs->bc_node.push_back(bc); // WW + pcs->bc_node_value.push_back(m_node_value); // WW + // j=m_msh->nod_vector[nodes_vector[i]]->connected_elements.size(); //only on material group + // boundary is selected } ++p_bc; continue; @@ -1160,20 +1149,19 @@ void CBoundaryConditionsGroup::Set(CRFProcess* pcs, int ShiftInNodeVector, //................................................................ if (bc->getGeoType() == GEOLIB::POINT) { - //05.2012. WW - long node_idx = m_msh->GetNODOnPNT(static_cast - (bc->getGeoObj())); - if(node_idx<0) - { - ++p_bc; - continue; - } - //------- + // 05.2012. WW + long node_idx = m_msh->GetNODOnPNT(static_cast(bc->getGeoObj())); + if (node_idx < 0) + { + ++p_bc; + continue; + } + //------- m_node_value = new CBoundaryConditionNode; // Get MSH node number - if (bc->getProcessDistributionType() == FiniteElement::CONSTANT - || bc->getProcessDistributionType() == FiniteElement::SWITCH) - m_node_value->geo_node_number = node_idx; + if (bc->getProcessDistributionType() == FiniteElement::CONSTANT + || bc->getProcessDistributionType() == FiniteElement::SWITCH) + m_node_value->geo_node_number = node_idx; m_node_value->conditional = cont; m_node_value->CurveIndex = bc->getCurveIndex(); @@ -1181,43 +1169,38 @@ void CBoundaryConditionsGroup::Set(CRFProcess* pcs, int ShiftInNodeVector, // Get value from a linear function. 25.08.2011. WW if (bc->getProcessDistributionType() == FiniteElement::FUNCTION) { -// a_node = m_msh->nod_vector[m_node_value->geo_node_number]; -// m_node_value->node_value = bc->dis_linear_f->getValue(a_node->X(),a_node->Y(),a_node->Z()); - double const* const coords( - m_msh->nod_vector[m_node_value->geo_node_number]-> - getData()); - m_node_value->node_value = bc->dis_linear_f->getValue( - coords[0], coords[1], coords[2]); + // a_node = m_msh->nod_vector[m_node_value->geo_node_number]; + // m_node_value->node_value = + // bc->dis_linear_f->getValue(a_node->X(),a_node->Y(),a_node->Z()); + double const* const coords(m_msh->nod_vector[m_node_value->geo_node_number]->getData()); + m_node_value->node_value = bc->dis_linear_f->getValue(coords[0], coords[1], coords[2]); } else m_node_value->node_value = bc->geo_node_value; - m_node_value->msh_node_number = m_node_value->geo_node_number - + ShiftInNodeVector; //WW - //YD/WW + m_node_value->msh_node_number = m_node_value->geo_node_number + ShiftInNodeVector; // WW + // YD/WW m_node_value->pcs_pv_name = _pcs_pv_name; m_node_value->msh_node_number_subst = msh_node_number_subst; - pcs->bc_node.push_back(bc); //WW - //WW + pcs->bc_node.push_back(bc); // WW + // WW pcs->bc_node_value.push_back(m_node_value); } - //-------------------------------------------------------------------- + //-------------------------------------------------------------------- if (bc->getGeoType() == GEOLIB::POLYLINE) { - //CC + // CC m_polyline = GEOGetPLYByName(bc->geo_name); // 08/2010 TF get the polyline data structure - GEOLIB::Polyline const* ply( - static_cast (bc->getGeoObj())); + GEOLIB::Polyline const* ply(static_cast(bc->getGeoObj())); if (m_polyline) { if (bc->getProcessDistributionType() == FiniteElement::CONSTANT - || bc->getProcessDistributionType() == FiniteElement::SWITCH) + || bc->getProcessDistributionType() == FiniteElement::SWITCH) { // 08/2010 TF - double msh_min_edge_length = - m_msh->getMinEdgeLength(); + double msh_min_edge_length = m_msh->getMinEdgeLength(); m_msh->setMinEdgeLength(m_polyline->epsilon); std::vector my_nodes_vector; m_msh->GetNODOnPLY(ply, my_nodes_vector); @@ -1227,35 +1210,32 @@ void CBoundaryConditionsGroup::Set(CRFProcess* pcs, int ShiftInNodeVector, nodes_vector.push_back(my_nodes_vector[k]); // for some benchmarks we need the vector entries sorted by index - std::sort (nodes_vector.begin(), nodes_vector.end()); + std::sort(nodes_vector.begin(), nodes_vector.end()); - const size_t nodes_vector_size (nodes_vector.size()); + const size_t nodes_vector_size(nodes_vector.size()); for (size_t i(0); i < nodes_vector_size; i++) { m_node_value = new CBoundaryConditionNode(); - m_node_value->msh_node_number = - nodes_vector[i] + ShiftInNodeVector; - m_node_value->geo_node_number = - nodes_vector[i]; - //dis_prop[0]; + m_node_value->msh_node_number = nodes_vector[i] + ShiftInNodeVector; + m_node_value->geo_node_number = nodes_vector[i]; + // dis_prop[0]; if (bc->getProcessDistributionType() == FiniteElement::SWITCH) m_node_value->node_value = bc->getSwitchBC().switchOnValue; else m_node_value->node_value = bc->geo_node_value; - m_node_value->CurveIndex = - bc->getCurveIndex(); - //YD/WW + m_node_value->CurveIndex = bc->getCurveIndex(); + // YD/WW m_node_value->pcs_pv_name = _pcs_pv_name; // SB copy values 09.2012 m_node_value->bc_node_copy_geom = bc->copy_geom; m_node_value->bc_node_copy_geom_name = bc->copy_geom_name; - //WW + // WW pcs->bc_node.push_back(bc); - //WW + // WW pcs->bc_node_value.push_back(m_node_value); - //WW group_vector.push_back(m_node_value); - //WW bc_group_vector.push_back(m_bc); //OK + // WW group_vector.push_back(m_node_value); + // WW bc_group_vector.push_back(m_bc); //OK } } @@ -1263,8 +1243,7 @@ void CBoundaryConditionsGroup::Set(CRFProcess* pcs, int ShiftInNodeVector, if (bc->getProcessDistributionType() == FiniteElement::FUNCTION) { // 08/2010 TF - double msh_min_edge_length = - m_msh->getMinEdgeLength(); + double msh_min_edge_length = m_msh->getMinEdgeLength(); m_msh->setMinEdgeLength(m_polyline->epsilon); std::vector my_nodes_vector; m_msh->GetNODOnPLY(ply, my_nodes_vector); @@ -1275,26 +1254,21 @@ void CBoundaryConditionsGroup::Set(CRFProcess* pcs, int ShiftInNodeVector, nodes_vector.push_back(my_nodes_vector[k]); // for some benchmarks we need the vector entries sorted by index - std::sort (nodes_vector.begin(), nodes_vector.end()); + std::sort(nodes_vector.begin(), nodes_vector.end()); - const size_t nodes_vector_size (nodes_vector.size()); + const size_t nodes_vector_size(nodes_vector.size()); for (size_t i(0); i < nodes_vector_size; i++) { m_node_value = new CBoundaryConditionNode(); m_node_value->msh_node_number = nodes_vector[i] + ShiftInNodeVector; m_node_value->geo_node_number = nodes_vector[i]; -// a_node = m_msh->nod_vector[m_node_value->geo_node_number]; -// m_node_value->node_value = bc->dis_linear_f->getValue(a_node->X(),a_node->Y(),a_node->Z()); - double const* const coords ( - m_msh->nod_vector[m_node_value-> - geo_node_number] - ->getData()); - m_node_value->node_value = - bc->dis_linear_f->getValue(coords[0], - coords[1], coords[2]); - - m_node_value->CurveIndex = - bc->getCurveIndex(); + // a_node = m_msh->nod_vector[m_node_value->geo_node_number]; + // m_node_value->node_value = + // bc->dis_linear_f->getValue(a_node->X(),a_node->Y(),a_node->Z()); + double const* const coords(m_msh->nod_vector[m_node_value->geo_node_number]->getData()); + m_node_value->node_value = bc->dis_linear_f->getValue(coords[0], coords[1], coords[2]); + + m_node_value->CurveIndex = bc->getCurveIndex(); m_node_value->pcs_pv_name = _pcs_pv_name; pcs->bc_node.push_back(bc); pcs->bc_node_value.push_back(m_node_value); @@ -1305,16 +1279,16 @@ void CBoundaryConditionsGroup::Set(CRFProcess* pcs, int ShiftInNodeVector, { m_msh->GetNODOnPLY(ply, nodes_vector); - for (size_t k(0); k < nodes_vector.size(); k++) { + for (size_t k(0); k < nodes_vector.size(); k++) + { m_node_value = new CBoundaryConditionNode(); m_node_value->msh_node_number = -1; m_node_value->msh_node_number = nodes_vector[k] + ShiftInNodeVector; m_node_value->geo_node_number = nodes_vector[k]; m_node_value->node_value - = bc->gradient_ref_depth_gradient - * (bc->gradient_ref_depth - - m_msh->nod_vector[nodes_vector[k]]->getData()[2]) - + bc->gradient_ref_depth_value; + = bc->gradient_ref_depth_gradient + * (bc->gradient_ref_depth - m_msh->nod_vector[nodes_vector[k]]->getData()[2]) + + bc->gradient_ref_depth_value; m_node_value->CurveIndex = bc->getCurveIndex(); m_node_value->pcs_pv_name = _pcs_pv_name; m_node_value->msh_node_number_subst = msh_node_number_subst; @@ -1323,18 +1297,15 @@ void CBoundaryConditionsGroup::Set(CRFProcess* pcs, int ShiftInNodeVector, } } - //WW / TF + // WW / TF if (bc->getProcessDistributionType() == FiniteElement::LINEAR) { - double msh_min_edge_length = - m_msh->getMinEdgeLength(); + double msh_min_edge_length = m_msh->getMinEdgeLength(); m_msh->setMinEdgeLength(m_polyline->epsilon); std::vector my_nodes_vector; m_msh->GetNODOnPLY(ply, my_nodes_vector); std::vector nodes_as_interpol_points; - m_msh->getPointsForInterpolationAlongPolyline ( - ply, - nodes_as_interpol_points); + m_msh->getPointsForInterpolationAlongPolyline(ply, nodes_as_interpol_points); m_msh->setMinEdgeLength(msh_min_edge_length); nodes_vector.clear(); @@ -1343,56 +1314,37 @@ void CBoundaryConditionsGroup::Set(CRFProcess* pcs, int ShiftInNodeVector, std::vector interpolation_points; std::vector interpolation_values; - for (size_t i(0); i < bc->getDistribedBC().size(); - i++) + for (size_t i(0); i < bc->getDistribedBC().size(); i++) { - for (size_t j = 0; - j < ply->getNumberOfPoints(); j++) - if (bc->getPointsWithDistribedBC()[ - i] == - (int)ply->getPointID(j)) + for (size_t j = 0; j < ply->getNumberOfPoints(); j++) + if (bc->getPointsWithDistribedBC()[i] == (int)ply->getPointID(j)) { - if (fabs(bc->getDistribedBC() - [i]) < - MKleinsteZahl) - bc->getDistribedBC() - [i] = 1.0e-20; - interpolation_points. - push_back (ply->getLength(j)); - interpolation_values. - push_back ( - bc->getDistribedBC() - [i]); + if (fabs(bc->getDistribedBC()[i]) < MKleinsteZahl) + bc->getDistribedBC()[i] = 1.0e-20; + interpolation_points.push_back(ply->getLength(j)); + interpolation_values.push_back(bc->getDistribedBC()[i]); break; } } - MathLib::PiecewiseLinearInterpolation ( - interpolation_points, - interpolation_values, - nodes_as_interpol_points, - node_value); + MathLib::PiecewiseLinearInterpolation( + interpolation_points, interpolation_values, nodes_as_interpol_points, node_value); for (size_t i = 0; i < nodes_vector.size(); i++) { m_node_value = new CBoundaryConditionNode(); m_node_value->msh_node_number = -1; - m_node_value->msh_node_number = - nodes_vector[i] - + - ShiftInNodeVector; - m_node_value->geo_node_number = - nodes_vector[i]; + m_node_value->msh_node_number = nodes_vector[i] + ShiftInNodeVector; + m_node_value->geo_node_number = nodes_vector[i]; m_node_value->node_value = node_value[i]; - //YD/WW + // YD/WW m_node_value->pcs_pv_name = _pcs_pv_name; - m_node_value->CurveIndex = - bc->getCurveIndex(); - //WW + m_node_value->CurveIndex = bc->getCurveIndex(); + // WW pcs->bc_node.push_back(bc); - //WW + // WW pcs->bc_node_value.push_back(m_node_value); - //WW group_vector.push_back(m_node_value); - //WW bc_group_vector.push_back(bc); //OK + // WW group_vector.push_back(m_node_value); + // WW bc_group_vector.push_back(bc); //OK } node_value.clear(); } @@ -1402,125 +1354,142 @@ void CBoundaryConditionsGroup::Set(CRFProcess* pcs, int ShiftInNodeVector, //------------------------------------------------------------------ if (bc->getGeoType() == GEOLIB::SURFACE) { - //CC10/05 + // CC10/05 // 04/2011 TF get the GEOLIB::Surface data structure - GEOLIB::Surface const* sfc( - static_cast (bc->getGeoObj())); + GEOLIB::Surface const* sfc(static_cast(bc->getGeoObj())); Surface* m_surface = GEOGetSFCByName(bc->geo_name); if (m_surface) { nodes_vector.clear(); -// m_msh->GetNODOnSFC(m_surface, nodes_vector); -//#ifndef NDEBUG -// GEOLIB::GEOObjects const& geo_obj(* m_msh->getGEOObjects()); -// std::string const& geo_project_name (* m_msh->getProjectName()); -// std::string sfc_name; -// geo_obj.getSurfaceVecObj(geo_project_name)->getNameOfElement(sfc, sfc_name); -// std::string debug_fname("MeshNodesOld-BC-" + sfc_name + ".gli"); -// std::ofstream debug_out (debug_fname.c_str()); -// debug_out << "#POINTS" << "\n"; -// for (size_t k(0); kgetNodeVector())[nodes_vector[k]]->getData()) << -// " $NAME " << nodes_vector[k] << "\n"; -// } -// debug_out << "#STOP" << "\n"; -// debug_out.close(); -//#endif + // m_msh->GetNODOnSFC(m_surface, nodes_vector); + //#ifndef NDEBUG + // GEOLIB::GEOObjects const& geo_obj(* m_msh->getGEOObjects()); + // std::string const& geo_project_name (* m_msh->getProjectName()); + // std::string sfc_name; + // geo_obj.getSurfaceVecObj(geo_project_name)->getNameOfElement(sfc, sfc_name); + // std::string debug_fname("MeshNodesOld-BC-" + sfc_name + ".gli"); + // std::ofstream debug_out (debug_fname.c_str()); + // debug_out << "#POINTS" << "\n"; + // for (size_t k(0); kgetNodeVector())[nodes_vector[k]]->getData()) << + // " $NAME " << nodes_vector[k] << "\n"; + // } + // debug_out << "#STOP" << "\n"; + // debug_out.close(); + //#endif std::vector msh_nod_vec; m_msh->GetNODOnSFC(sfc, msh_nod_vec); #ifndef NDEBUG #ifdef DEBUGMESHNODESEARCH { - std::string const debug_fname(bc->geo_name+"-FoundNodes.gli"); + std::string const debug_fname(bc->geo_name + "-FoundNodes.gli"); std::ofstream debug_out(debug_fname.c_str()); debug_out << "#POINTS\n"; - for (size_t k(0); kgetNodeVector())[msh_nod_vec[k]]->getData()) << - " $NAME " << msh_nod_vec[k] << "\n"; + for (size_t k(0); k < msh_nod_vec.size(); k++) + { + debug_out << k << " " << GEOLIB::Point((m_msh->getNodeVector())[msh_nod_vec[k]]->getData()) + << " $NAME " << msh_nod_vec[k] << "\n"; } - debug_out << "#STOP" << "\n"; + debug_out << "#STOP" + << "\n"; debug_out.close(); } #endif #endif -// nodes_vector.clear(); - for (size_t k(0); k < msh_nod_vec.size(); k++) { -// std::cout << "\t" << k << "\t" << nodes_vector_old[k] << "\t" << msh_nod_vec[k] << "\n"; - nodes_vector.push_back (msh_nod_vec[k]); + // nodes_vector.clear(); + for (size_t k(0); k < msh_nod_vec.size(); k++) + { + // std::cout << "\t" << k << "\t" << nodes_vector_old[k] << "\t" << + // msh_nod_vec[k] + //<< + //"\n"; + nodes_vector.push_back(msh_nod_vec[k]); } - size_t nodes_vector_length (nodes_vector.size()); + size_t nodes_vector_length(nodes_vector.size()); if (bc->isConstrainedBC() && nodes_vector_length > 0) { - for (std::size_t i=0; i < bc->getNumberOfConstrainedBCs(); i++) + for (std::size_t i = 0; i < bc->getNumberOfConstrainedBCs(); i++) { - const Constrained &temp(bc->getConstrainedBC(i)); + const Constrained& temp(bc->getConstrainedBC(i)); if (temp.constrainedVariable == ConstrainedVariable::VELOCITY) { - //calculate normals of triangles + // calculate normals of triangles sfc->calculateTriangleNormals(); } } } - if (bc->getProcessDistributionType() == FiniteElement::LINEAR) { - std::vector::iterator p = - m_surface->polyline_of_surface_vector.begin(); + if (bc->getProcessDistributionType() == FiniteElement::LINEAR) + { + std::vector::iterator p = m_surface->polyline_of_surface_vector.begin(); node_value.resize(nodes_vector_length); p = m_surface->polyline_of_surface_vector.begin(); - while (p != m_surface->polyline_of_surface_vector.end()) { + while (p != m_surface->polyline_of_surface_vector.end()) + { m_polyline = *p; - for (size_t i(0); i < bc->getDistribedBC().size(); i++) { + for (size_t i(0); i < bc->getDistribedBC().size(); i++) + { for (size_t j = 0; j < m_polyline->point_vector.size(); j++) - if (bc-> getPointsWithDistribedBC()[i] - == m_polyline-> point_vector[j] ->id) { - if (fabs(bc-> getDistribedBC()[i]) < MKleinsteZahl) bc-> getDistribedBC()[i] - = 1.0e-20; - m_polyline-> point_vector[j]-> setPropert( - bc-> getDistribedBC()[i]); + if (bc->getPointsWithDistribedBC()[i] == m_polyline->point_vector[j]->id) + { + if (fabs(bc->getDistribedBC()[i]) < MKleinsteZahl) + bc->getDistribedBC()[i] = 1.0e-20; + m_polyline->point_vector[j]->setPropert(bc->getDistribedBC()[i]); break; } } p++; } - //WW + // WW node_value.resize(nodes_vector_length); - bc->SurfaceInterpolation(pcs, nodes_vector, node_value); //WW + bc->SurfaceInterpolation(pcs, nodes_vector, node_value); // WW } for (size_t i = 0; i < nodes_vector_length; i++) { m_node_value = new CBoundaryConditionNode(); m_node_value->msh_node_number = -1; - m_node_value->msh_node_number = nodes_vector[i] - + ShiftInNodeVector; //nodes[i]; + m_node_value->msh_node_number = nodes_vector[i] + ShiftInNodeVector; // nodes[i]; - //nodes[i]; + // nodes[i]; m_node_value->geo_node_number = nodes_vector[i]; - //YD/WW + // YD/WW m_node_value->pcs_pv_name = _pcs_pv_name; - if (bc->getProcessDistributionType() == FiniteElement::LINEAR) { + if (bc->getProcessDistributionType() == FiniteElement::LINEAR) + { m_node_value->node_value = node_value[i]; - } else { - if (bc->getProcessDistributionType() == FiniteElement::GRADIENT) {// 6/2012 JOD - m_node_value->node_value = bc->gradient_ref_depth_gradient - * (bc->gradient_ref_depth - - m_msh->nod_vector[m_node_value->geo_node_number]->getData()[2]) - + bc->gradient_ref_depth_value; - } else { - // 25.08.2011. WW - if (bc->getProcessDistributionType() == FiniteElement::FUNCTION) { - // a_node = m_msh->nod_vector[m_node_value->geo_node_number]; - // m_node_value->node_value = bc->dis_linear_f->getValue(a_node->X(),a_node->Y(),a_node->Z()); - double const* const coords(m_msh->nod_vector[m_node_value-> geo_node_number]->getData()); - m_node_value->node_value = bc->dis_linear_f->getValue(coords[0], - coords[1], coords[2]); - } else { + } + else + { + if (bc->getProcessDistributionType() == FiniteElement::GRADIENT) + { // 6/2012 JOD + m_node_value->node_value + = bc->gradient_ref_depth_gradient + * (bc->gradient_ref_depth + - m_msh->nod_vector[m_node_value->geo_node_number]->getData()[2]) + + bc->gradient_ref_depth_value; + } + else + { + // 25.08.2011. WW + if (bc->getProcessDistributionType() == FiniteElement::FUNCTION) + { + // a_node = + // m_msh->nod_vector[m_node_value->geo_node_number]; + // m_node_value->node_value = + // bc->dis_linear_f->getValue(a_node->X(),a_node->Y(),a_node->Z()); + double const* const coords( + m_msh->nod_vector[m_node_value->geo_node_number]->getData()); + m_node_value->node_value + = bc->dis_linear_f->getValue(coords[0], coords[1], coords[2]); + } + else + { if (bc->getProcessDistributionType() == FiniteElement::SWITCH) { m_node_value->node_value = bc->getSwitchBC().switchOnValue; @@ -1531,22 +1500,24 @@ void CBoundaryConditionsGroup::Set(CRFProcess* pcs, int ShiftInNodeVector, } } m_node_value->CurveIndex = bc->getCurveIndex(); - //OK + // OK bc->node_number_vector = nodes_vector; - pcs->bc_node.push_back(bc); //WW - //WW + pcs->bc_node.push_back(bc); // WW + // WW pcs->bc_node_value.push_back(m_node_value); - //WW group_vector.push_back(m_node_value); - //WW bc_group_vector.push_back(bc); //OK + // WW group_vector.push_back(m_node_value); + // WW bc_group_vector.push_back(bc); //OK if (bc->isConstrainedBC() == true && nodes_vector_length > 0) { - for (std::size_t k=0; k < bc->getNumberOfConstrainedBCs(); k++) + for (std::size_t k = 0; k < bc->getNumberOfConstrainedBCs(); k++) { - const Constrained &temp(bc->getConstrainedBC(k)); //delete object, else previous elements will reside here. + const Constrained& temp( + bc->getConstrainedBC(k)); // delete object, else previous elements will reside here. if (temp.constrainedVariable == ConstrainedVariable::VELOCITY) { - double const * const coords(m_msh->nod_vector[m_node_value->geo_node_number]->getData()); + double const* const coords( + m_msh->nod_vector[m_node_value->geo_node_number]->getData()); // works only for planar surfaces since // the normal is constant for all triangles int triangle_id(sfc->getTriangleIDOfPoint(coords)); @@ -1554,7 +1525,7 @@ void CBoundaryConditionsGroup::Set(CRFProcess* pcs, int ShiftInNodeVector, m_node_value->SetNormalVector(sfc->getTriangleNormal(triangle_id)); else std::cout << "Could not find current BC node " << m_node_value->geo_node_number - << " on given SURFACE " << m_surface->name << std::endl; + << " on given SURFACE " << m_surface->name << std::endl; } } } @@ -1591,32 +1562,31 @@ void CBoundaryConditionsGroup::Set(CRFProcess* pcs, int ShiftInNodeVector, m_node_value->geo_node_number = bc->getMeshNodeNumber(); m_node_value->node_value = bc->geo_node_value; m_node_value->CurveIndex = bc->getCurveIndex(); - //YD/WW + // YD/WW m_node_value->pcs_pv_name = _pcs_pv_name; - pcs->bc_node.push_back(bc); //WW - //WW + pcs->bc_node.push_back(bc); // WW + // WW pcs->bc_node_value.push_back(m_node_value); - //WW group_vector.push_back(m_node_value); - //WW bc_group_vector.push_back(bc); //OK + // WW group_vector.push_back(m_node_value); + // WW bc_group_vector.push_back(bc); //OK } //------------------------------------------------------------------ // FCT types //OK if (bc->fct_name.size() > 0) - //WW + // WW for (size_t i = 0; i < pcs->bc_node_value.size(); i++) { pcs->bc_node_value[i]->fct_name = bc->fct_name; - pcs->bc_node_value[i]->msh_node_number_subst - = msh_node_number_subst; + pcs->bc_node_value[i]->msh_node_number_subst = msh_node_number_subst; } - //WW fct_name = bc->fct_name; + // WW fct_name = bc->fct_name; //------------------------------------------------------------------ } // PCS ++p_bc; } // list - clock_t end_time (clock()); - std::cout << "\t[BC] set BC took " << (end_time-start_time)/(double)(CLOCKS_PER_SEC) << "\n"; + clock_t end_time(clock()); + std::cout << "\t[BC] set BC took " << (end_time - start_time) / (double)(CLOCKS_PER_SEC) << "\n"; start_time = clock(); // SetTransientBCtoNodes 10/2008 WW/CB Implementation @@ -1624,7 +1594,7 @@ void CBoundaryConditionsGroup::Set(CRFProcess* pcs, int ShiftInNodeVector, while (p_bc != bc_list.end()) { CBoundaryCondition* bc(*p_bc); - if (!bc->time_dep_interpol) //WW/CB + if (!bc->time_dep_interpol) // WW/CB { ++p_bc; continue; @@ -1633,23 +1603,19 @@ void CBoundaryConditionsGroup::Set(CRFProcess* pcs, int ShiftInNodeVector, //................................................................ if (bc->getGeoType() == GEOLIB::POLYLINE) { - //CC + // CC m_polyline = GEOGetPLYByName(bc->geo_name); if (m_polyline) { - //WW - if (bc->getProcessDistributionType() == - FiniteElement::LINEAR) + // WW + if (bc->getProcessDistributionType() == FiniteElement::LINEAR) { // TF - double msh_min_edge_length = - m_msh->getMinEdgeLength(); + double msh_min_edge_length = m_msh->getMinEdgeLength(); m_msh->setMinEdgeLength(m_polyline->epsilon); std::vector my_nodes_vector; - GEOLIB::Polyline const* ply ( - static_cast (bc-> - getGeoObj())); + GEOLIB::Polyline const* ply(static_cast(bc->getGeoObj())); m_msh->GetNODOnPLY(ply, my_nodes_vector); m_msh->setMinEdgeLength(msh_min_edge_length); @@ -1657,32 +1623,26 @@ void CBoundaryConditionsGroup::Set(CRFProcess* pcs, int ShiftInNodeVector, for (size_t k(0); k < my_nodes_vector.size(); k++) nodes_vector.push_back(my_nodes_vector[k]); - pcs->bc_transient_index.push_back( - (long) pcs->bc_node.size()); + pcs->bc_transient_index.push_back((long)pcs->bc_node.size()); for (size_t i = 0; i < nodes_vector.size(); i++) { m_node_value = new CBoundaryConditionNode(); m_node_value->msh_node_number = -1; - m_node_value->msh_node_number = - nodes_vector[i] - + - ShiftInNodeVector; - m_node_value->geo_node_number = - nodes_vector[i]; + m_node_value->msh_node_number = nodes_vector[i] + ShiftInNodeVector; + m_node_value->geo_node_number = nodes_vector[i]; m_node_value->node_value = 0.0; - //YD/WW + // YD/WW m_node_value->pcs_pv_name = _pcs_pv_name; - m_node_value->CurveIndex = - bc->getCurveIndex(); - //WW + m_node_value->CurveIndex = bc->getCurveIndex(); + // WW pcs->bc_node.push_back(bc); - //WW + // WW pcs->bc_node_value.push_back(m_node_value); } node_value.clear(); } //................................................................ - //delete(values); + // delete(values); Free(nodes); } // if(m_ply) } @@ -1690,14 +1650,14 @@ void CBoundaryConditionsGroup::Set(CRFProcess* pcs, int ShiftInNodeVector, // PCS ++p_bc; } // list - /* // Make the following as comment by WW - // Test - long no_bc = (long)pcs->bc_node_value.size(); - if(no_bc<1) - cout << "Warning: no boundary conditions specified for " << pcs_type_name << "\n"; - */ + /* // Make the following as comment by WW + // Test + long no_bc = (long)pcs->bc_node_value.size(); + if(no_bc<1) + cout << "Warning: no boundary conditions specified for " << pcs_type_name << "\n"; + */ end_time = clock(); - std::cout << "\t[BC] set transient BC took " << (end_time-start_time)/(double)(CLOCKS_PER_SEC) << "\n"; + std::cout << "\t[BC] set transient BC took " << (end_time - start_time) / (double)(CLOCKS_PER_SEC) << "\n"; } /************************************************************************** @@ -1710,8 +1670,7 @@ void CBoundaryConditionsGroup::Set(CRFProcess* pcs, int ShiftInNodeVector, CBoundaryConditionsGroup* CBoundaryConditionsGroup::Get(const std::string& pcs_name) { CBoundaryConditionsGroup* m_bc_group = NULL; - std::list::const_iterator p_bc_group = - bc_group_list.begin(); + std::list::const_iterator p_bc_group = bc_group_list.begin(); while (p_bc_group != bc_group_list.end()) { m_bc_group = *p_bc_group; @@ -1729,8 +1688,7 @@ CBoundaryConditionsGroup* CBoundaryConditionsGroup::Get(const std::string& pcs_n 04/2005 OK Implementation last modification: **************************************************************************/ -CBoundaryConditionsGroup* BCGetGroup(const std::string& pcs_type_name, - const std::string& pcs_pv_name) +CBoundaryConditionsGroup* BCGetGroup(const std::string& pcs_type_name, const std::string& pcs_pv_name) { std::list::const_iterator it = bc_group_list.begin(); while (it != bc_group_list.end()) @@ -1756,7 +1714,7 @@ void BCDelete() std::list::const_iterator p = bc_list.begin(); while (p != bc_list.end()) { - //bc_list.remove(*p); + // bc_list.remove(*p); m_bc = *p; delete m_bc; ++p; @@ -1779,7 +1737,7 @@ void BCGroupDelete() { m_bc_group = *p; delete m_bc_group; - //bc_group_list.remove(*p); + // bc_group_list.remove(*p); ++p; } bc_group_list.clear(); @@ -1833,8 +1791,8 @@ CBoundaryCondition* BCGet(const std::string& pcs_type_name) 11/2007 WW Implementation **************************************************************************/ void CBoundaryCondition::SurfaceInterpolation(CRFProcess* m_pcs, - std::vector&nodes_on_sfc, - std::vector&node_value_vector) + std::vector& nodes_on_sfc, + std::vector& node_value_vector) { long i, j, k, l; @@ -1842,25 +1800,24 @@ void CBoundaryCondition::SurfaceInterpolation(CRFProcess* m_pcs, // Interpolation of polygon values to nodes_on_sfc int nPointsPly = 0; double Area1, Area2; - //NW. Default tolerance is 1e-9 but it can be changed in a BC file. + // NW. Default tolerance is 1e-9 but it can be changed in a BC file. double Tol = this->epsilon; bool Passed; double gC[3], p1[3], p2[3], vn[3], unit[3], NTri[3]; // CGLPolyline* m_polyline = NULL; Surface* m_surface = NULL; - m_surface = GEOGetSFCByName(geo_name); //CC + m_surface = GEOGetSFCByName(geo_name); // CC // list::const_iterator p = m_surface->polyline_of_surface_list.begin(); - std::vector::iterator p = - m_surface->polyline_of_surface_vector.begin(); + std::vector::iterator p = m_surface->polyline_of_surface_vector.begin(); for (j = 0; j < (long)nodes_on_sfc.size(); j++) { -// pn[0] = m_pcs->m_msh->nod_vector[nodes_on_sfc[j]]->X(); -// pn[1] = m_pcs->m_msh->nod_vector[nodes_on_sfc[j]]->Y(); -// pn[2] = m_pcs->m_msh->nod_vector[nodes_on_sfc[j]]->Z(); - double const* const pn (m_pcs->m_msh->nod_vector[nodes_on_sfc[j]]->getData()); + // pn[0] = m_pcs->m_msh->nod_vector[nodes_on_sfc[j]]->X(); + // pn[1] = m_pcs->m_msh->nod_vector[nodes_on_sfc[j]]->Y(); + // pn[2] = m_pcs->m_msh->nod_vector[nodes_on_sfc[j]]->Z(); + double const* const pn(m_pcs->m_msh->nod_vector[nodes_on_sfc[j]]->getData()); node_value_vector[j] = 0.0; Passed = false; // nodes close to first polyline @@ -1872,7 +1829,7 @@ void CBoundaryCondition::SurfaceInterpolation(CRFProcess* m_pcs, for (i = 0; i < 3; i++) gC[i] = 0.0; vn[2] = 0.0; - nPointsPly = (int) m_polyline->point_vector.size(); + nPointsPly = (int)m_polyline->point_vector.size(); if (m_polyline->point_vector.front() == m_polyline->point_vector.back()) nPointsPly -= 1; for (i = 0; i < nPointsPly; i++) @@ -1883,9 +1840,9 @@ void CBoundaryCondition::SurfaceInterpolation(CRFProcess* m_pcs, vn[2] += m_polyline->point_vector[i]->getPropert(); } for (i = 0; i < 3; i++) - gC[i] /= (double) nPointsPly; + gC[i] /= (double)nPointsPly; // BC value at center is an average of all point values of polygon - vn[2] /= (double) nPointsPly; + vn[2] /= (double)nPointsPly; // Area of this polygon by the gravity center for (i = 0; i < nPointsPly; i++) { @@ -1926,6 +1883,6 @@ void CBoundaryCondition::SurfaceInterpolation(CRFProcess* m_pcs, p++; if (Passed) break; - } // while - } //j + } // while + } // j } diff --git a/FEM/rf_bc_new.h b/FEM/rf_bc_new.h index 8fc023209..328f6f8a4 100644 --- a/FEM/rf_bc_new.h +++ b/FEM/rf_bc_new.h @@ -30,9 +30,9 @@ class BoundaryConditionIO; // new GEOLIB #include "DistributionInfo.h" // TF #include "GEOObjects.h" -#include "GeoInfo.h" // TF +#include "GeoInfo.h" // TF #include "LinearFunctionData.h" // TF -#include "ProcessInfo.h" // KR +#include "ProcessInfo.h" // KR #include "Constrained.h" #include "SwitchBC.h" @@ -49,16 +49,13 @@ class CFEMesh; class BoundaryCondition; -class CBoundaryCondition : - public ProcessInfo, - public GeoInfo, - public DistributionInfo +class CBoundaryCondition : public ProcessInfo, public GeoInfo, public DistributionInfo { public: -// CBoundaryCondition(ProcessInfo const& process_info, -// GeoInfo const& geo_info, -// DistributionInfo const& distribution_info, -// ); + // CBoundaryCondition(ProcessInfo const& process_info, + // GeoInfo const& geo_info, + // DistributionInfo const& distribution_info, + // ); friend class CBoundaryConditionsGroup; friend class FileIO::BoundaryConditionIO; CBoundaryCondition(); @@ -78,9 +75,8 @@ class CBoundaryCondition : * @return the position in the stream after the boundary condition */ // TF - std::ios::pos_type Read(std::ifstream* in, - const GEOLIB::GEOObjects& geo_obj, const std::string& unique_fname, - bool &valid); + std::ios::pos_type Read(std::ifstream* in, const GEOLIB::GEOObjects& geo_obj, const std::string& unique_fname, + bool& valid); /** * ToDo remove after transition to new GEOLIB - REMOVE CANDIDATE @@ -109,56 +105,30 @@ class CBoundaryCondition : return _periode_phase_shift; } - const std::vector& getPointsWithDistribedBC() const - { - return _PointsHaveDistribedBC; - } - const std::vector& getDistribedBC() const - { - return _DistribedBC; - } - std::vector& getDistribedBC() - { - return _DistribedBC; - } - double getGeoNodeValue() const - { - return geo_node_value; - } - //KR - - const std::vector& getPointsFCTNames() const - { - return _PointsFCTNames; - } - - size_t getMeshNodeNumber() const - { - return _msh_node_number; - } - const std::string& getMeshTypeName() const - { - return _msh_type_name; - } - - int getExcav() {return bcExcav; } //WX:12.2010 get bc excav model - int getExcavMatGr() {return MatGr; } //WX:12.2010 get excav material group - int getTimeContrCurve() {return time_contr_curve; } //WX:12.2010 get bc ativity controlled curve - int getNoDispIncre() {return NoDispIncre;}; //WX:12.2012 - + const std::vector& getPointsWithDistribedBC() const { return _PointsHaveDistribedBC; } + const std::vector& getDistribedBC() const { return _DistribedBC; } + std::vector& getDistribedBC() { return _DistribedBC; } + double getGeoNodeValue() const { return geo_node_value; } + // KR + + const std::vector& getPointsFCTNames() const { return _PointsFCTNames; } + size_t getMeshNodeNumber() const { return _msh_node_number; } + const std::string& getMeshTypeName() const { return _msh_type_name; } + int getExcav() { return bcExcav; } // WX:12.2010 get bc excav model + int getExcavMatGr() { return MatGr; } // WX:12.2010 get excav material group + int getTimeContrCurve() { return time_contr_curve; } // WX:12.2010 get bc ativity controlled curve + int getNoDispIncre() { return NoDispIncre; }; // WX:12.2012 // give head bc for PRESSURE1 primary variable //MW - int getPressureAsHeadModel() const {return _pressure_as_head_model;} + int getPressureAsHeadModel() const { return _pressure_as_head_model; } // return given density double getPressureAsHeadDensity() const { return _pressure_as_head_density; }; // constrain a BC by other process - bool isConstrainedBC() const {return _isConstrainedBC;} - Constrained const & getConstrainedBC(std::size_t i) const { return _constrainedBC[i]; } + bool isConstrainedBC() const { return _isConstrainedBC; } + Constrained const& getConstrainedBC(std::size_t i) const { return _constrainedBC[i]; } std::size_t getNumberOfConstrainedBCs() const { return _constrainedBC.size(); } bool isSeepageBC() const { return _isSeepageBC; } - bool isSwitchBC() const {return _isSwitchBC;} - SwitchBC const & getSwitchBC() const { return _switchBC; } - - + bool isSwitchBC() const { return _isSwitchBC; } + SwitchBC const& getSwitchBC() const { return _switchBC; } private: std::vector _PointsFCTNames; std::vector _PointsHaveDistribedBC; @@ -171,7 +141,7 @@ class CBoundaryCondition : std::string geo_name; // TF 05/2010 std::string geo_type_name; - std::string fname; //27.02.2009. WW + std::string fname; // 27.02.2009. WW int _curve_index; // Time function index // DIS @@ -188,28 +158,28 @@ class CBoundaryCondition : double gradient_ref_depth_value; double gradient_ref_depth_gradient; - double node_value_cond; //OK - double condition; //OK - double epsilon; //NW. temporally set here for surface interpolation + double node_value_cond; // OK + double condition; // OK + double epsilon; // NW. temporally set here for surface interpolation bool time_dep_interpol; // FCT std::string fct_name; bool conditional; - LinearFunctionData* dis_linear_f; //24.8.2011. WW + LinearFunctionData* dis_linear_f; // 24.8.2011. WW - //WW + // WW void SurfaceInterpolation(CRFProcess* m_pcs, std::vector& nodes_on_sfc, std::vector& node_value_vector); inline void DirectAssign(long ShiftInNodeVector); - //19.03.2009. WW + // 19.03.2009. WW inline void PatchAssign(long ShiftInNodeVector); // MSH long _msh_node_number; - std::string _msh_type_name; //OK4105 + std::string _msh_type_name; // OK4105 // copy values SB 09.2012 std::string copy_geom; @@ -233,29 +203,28 @@ class CBoundaryCondition : bool _isSwitchBC; SwitchBC _switchBC; - }; -class CBoundaryConditionNode //OK raus +class CBoundaryConditionNode // OK raus { public: long geo_node_number; long msh_node_number; - long msh_node_number_subst; //WW + long msh_node_number_subst; // WW double node_value; double node_value_pre_calc; - int CurveIndex; // Time dependent function index - std::string pcs_pv_name; //YD/WW + int CurveIndex; // Time dependent function index + std::string pcs_pv_name; // YD/WW // - std::string fct_name; //WW - //FCT - int conditional; //OK + std::string fct_name; // WW + // FCT + int conditional; // OK std::string bc_node_copy_geom; std::string bc_node_copy_geom_name; CBoundaryConditionNode(); - void SetNormalVector(double const*const normal_vector); + void SetNormalVector(double const* const normal_vector); double const* GetNormalVector() const; // 25.08.2011. WW @@ -275,35 +244,34 @@ class CBoundaryConditionsGroup void Set(CRFProcess* pcs, int ShiftInNodeVector, const std::string& this_pv_name = ""); CBoundaryConditionsGroup* Get(const std::string&); - const std::string& getProcessTypeName () const { return _pcs_type_name; } - void setProcessTypeName (const std::string& pcs_type_name) { _pcs_type_name = pcs_type_name; } - const std::string& getProcessPrimaryVariableName () const { return _pcs_pv_name; } - void setProcessPrimaryVariableName (const std::string& pcs_pv_name) + const std::string& getProcessTypeName() const { return _pcs_type_name; } + void setProcessTypeName(const std::string& pcs_type_name) { _pcs_type_name = pcs_type_name; } + const std::string& getProcessPrimaryVariableName() const { return _pcs_pv_name; } + void setProcessPrimaryVariableName(const std::string& pcs_pv_name) { if (_pcs_type_name.find("MASS_TRANSPORT") == std::string::npos) _pcs_pv_name = pcs_pv_name; else _pcs_pv_name = "CONCENTRATION1"; } - long msh_node_number_subst; //WW - std::string fct_name; //OK + long msh_node_number_subst; // WW + std::string fct_name; // OK - MeshLib::CFEMesh* m_msh; //OK - //WW std::vectorbc_group_vector; //OK - //WW double GetConditionalNODValue(int,CBoundaryCondition*); //OK + MeshLib::CFEMesh* m_msh; // OK + // WW std::vectorbc_group_vector; //OK + // WW double GetConditionalNODValue(int,CBoundaryCondition*); //OK int time_dep_bc; private: std::string group_name; - std::string _pcs_type_name; //OK - std::string _pcs_pv_name; //OK + std::string _pcs_type_name; // OK + std::string _pcs_pv_name; // OK }; //======================================================================== #define BC_FILE_EXTENSION ".bc" extern std::list bc_group_list; -extern CBoundaryConditionsGroup* BCGetGroup(const std::string& pcs_type_name, - const std::string& pcs_pv_name); +extern CBoundaryConditionsGroup* BCGetGroup(const std::string& pcs_type_name, const std::string& pcs_pv_name); extern std::list bc_list; /** @@ -313,18 +281,16 @@ extern std::list bc_list; * @param unique_name the (unique) name of the project * @return false, if the file can not opened, else true */ -bool BCRead (std::string const& file_base_name, - const GEOLIB::GEOObjects& geo_obj, - const std::string& unique_name); +bool BCRead(std::string const& file_base_name, const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name); extern void BCWrite(std::string const&); extern void BCDelete(); extern void BCGroupDelete(const std::string& pcs_type_name, const std::string& pcs_pv_name); extern void BCGroupDelete(void); -//OK -extern CBoundaryCondition* BCGet(const std::string&,const std::string&,const std::string&); -extern CBoundaryCondition* BCGet(std::string); //OK +// OK +extern CBoundaryCondition* BCGet(const std::string&, const std::string&, const std::string&); +extern CBoundaryCondition* BCGet(std::string); // OK -//ToDo +// ToDo extern void ScalingDirichletBoundaryConditions(const double factor); #endif diff --git a/FEM/rf_fct.cpp b/FEM/rf_fct.cpp index 4510fd582..4a1e341ab 100644 --- a/FEM/rf_fct.cpp +++ b/FEM/rf_fct.cpp @@ -62,10 +62,10 @@ CFunction* FCTGet(std::string fct_name) int i; int fct_vector_size = (int)fct_vector.size(); CFunction* m_fct = NULL; - for(i = 0; i < fct_vector_size; i++) + for (i = 0; i < fct_vector_size; i++) { m_fct = fct_vector[i]; - if(fct_name.compare(m_fct->type_name) == 0) //OK + if (fct_name.compare(m_fct->type_name) == 0) // OK return m_fct; } return NULL; @@ -83,9 +83,9 @@ std::ios::pos_type CFunction::Read(std::ifstream* fct_file) { bool ok_true = true; bool new_keyword = false; - //WW bool dim = false; + // WW bool dim = false; int unsigned no_variable_names; - //OK411 int unsigned i; + // OK411 int unsigned i; int i; double* variable_data = NULL; double* j = 0; @@ -98,25 +98,25 @@ std::ios::pos_type CFunction::Read(std::ifstream* fct_file) string dollar("$"); ios::pos_type position; std::stringstream line_stream; - std::vectordim_x; //OK memory release check - std::vectordim_y; - std::vectordim_z; + std::vector dim_x; // OK memory release check + std::vector dim_y; + std::vector dim_z; //---------------------------------------------------------------------- while (!new_keyword) { position = fct_file->tellg(); - fct_file->getline(buffer,MAX_ZEILE); + fct_file->getline(buffer, MAX_ZEILE); line_string = buffer; //.................................................................... // Test next keyword - if(line_string.find(hash) != string::npos) + if (line_string.find(hash) != string::npos) { new_keyword = true; break; } //.................................................................... // TYPE - if(line_string.find("$TYPE") != string::npos) //subkeyword found + if (line_string.find("$TYPE") != string::npos) // subkeyword found { line_stream.str(GetLineFromFile1(fct_file)); line_stream >> type_name; @@ -124,12 +124,12 @@ std::ios::pos_type CFunction::Read(std::ifstream* fct_file) } //.................................................................... // GEO_TYPE - //subkeyword found - if(line_string.find("$GEO_TYPE") != string::npos) + // subkeyword found + if (line_string.find("$GEO_TYPE") != string::npos) { line_stream.str(GetLineFromFile1(fct_file)); line_stream >> geo_type_name; - if(geo_type_name.find("POINT") != string::npos) + if (geo_type_name.find("POINT") != string::npos) { line_stream >> geo_name; line_stream.clear(); @@ -137,23 +137,23 @@ std::ios::pos_type CFunction::Read(std::ifstream* fct_file) } //.................................................................... // DIS_TYPE //CMCD - //subkeyword found - if(line_string.find("$DIS_TYPE") != string::npos) + // subkeyword found + if (line_string.find("$DIS_TYPE") != string::npos) { line_stream.str(GetLineFromFile1(fct_file)); - line_stream >> dis_type_name; //TRANSIENT + line_stream >> dis_type_name; // TRANSIENT line_stream.clear(); } //.................................................................... - //VARIABLES - //subkeyword found - if(line_string.find("$VARIABLES") != string::npos) + // VARIABLES + // subkeyword found + if (line_string.find("$VARIABLES") != string::npos) { line_stream.str(GetLineFromFile1(fct_file)); - while(ok_true) + while (ok_true) { line_stream >> line_string; - if(line_string.compare(test_string) == 0) + if (line_string.compare(test_string) == 0) { line_stream.clear(); break; @@ -164,10 +164,10 @@ std::ios::pos_type CFunction::Read(std::ifstream* fct_file) } //.................................................................... - //MATRIX_DIMENSION NB + // MATRIX_DIMENSION NB //... reads the number of colums and rows of the given matrix ........ - //subkeyword found - if(line_string.find("$DIMENSION") != string::npos) + // subkeyword found + if (line_string.find("$DIMENSION") != string::npos) { line_stream.str(GetLineFromFile1(fct_file)); @@ -180,18 +180,18 @@ std::ios::pos_type CFunction::Read(std::ifstream* fct_file) line_string = ""; } //.................................................................... - //MATRIX NB + // MATRIX NB //...reads both arguments and depending function values in the given.. //...matrix and saves them consecutively in variable_data_vector...... - //subkeyword found - if(line_string.find("$MATRIX") != string::npos) + // subkeyword found + if (line_string.find("$MATRIX") != string::npos) { for (i = 0; i < matrix_dimension[0] * matrix_dimension[1]; i++) { line_stream.str(GetLineFromFile1(fct_file)); line_string = line_stream.str(); - j = new double; //OK + j = new double; // OK k = new double; l = new double; @@ -206,7 +206,7 @@ std::ios::pos_type CFunction::Read(std::ifstream* fct_file) line_stream.clear(); } - //OK411 + // OK411 for (i = 0; i < (int)dim_x.size(); i++) variable_data_vector.push_back(dim_x[i]); for (i = 0; i < (int)dim_y.size(); i++) @@ -214,12 +214,11 @@ std::ios::pos_type CFunction::Read(std::ifstream* fct_file) for (i = 0; i < (int)dim_z.size(); i++) variable_data_vector.push_back(dim_z[i]); - //OK411 - if ((int)variable_data_vector.size() != matrix_dimension[0] * - matrix_dimension[1] + matrix_dimension[0] + matrix_dimension[1]) + // OK411 + if ((int)variable_data_vector.size() + != matrix_dimension[0] * matrix_dimension[1] + matrix_dimension[0] + matrix_dimension[1]) { - std::cout << - "FCT function: Error! The number of data does not correspond to the specified matrix size" + std::cout << "FCT function: Error! The number of data does not correspond to the specified matrix size" << "\n"; break; } @@ -228,26 +227,26 @@ std::ios::pos_type CFunction::Read(std::ifstream* fct_file) } //-------------------------------------------------------------------- - //DATA - if(line_string.find("$DATA") != string::npos) //subkeyword found + // DATA + if (line_string.find("$DATA") != string::npos) // subkeyword found { no_variable_names = (int)variable_names_vector.size(); - while(ok_true) + while (ok_true) { line_string = GetLineFromFile1(fct_file); line_stream.str(line_string); - if(line_string.find("$") != string::npos) + if (line_string.find("$") != string::npos) { line_stream.clear(); break; } - if(line_string.find("#") != string::npos) + if (line_string.find("#") != string::npos) { line_stream.clear(); return position; } variable_data = new double[no_variable_names]; - for(i = 0; i < (int)no_variable_names; i++) //OK411 + for (i = 0; i < (int)no_variable_names; i++) // OK411 { line_stream >> variable_data[i]; variable_data_vector.push_back(variable_data); @@ -269,38 +268,43 @@ std::ios::pos_type CFunction::Read(std::ifstream* fct_file) **************************************************************************/ void CFunction::Write(std::fstream* fct_file) { - int i,j; + int i, j; int variable_names_vector_size = (int)variable_names_vector.size(); int variable_data_vector_size = (int)variable_data_vector.size(); //-------------------------------------------------------------------- // CHECK //-------------------------------------------------------------------- - //KEYWORD - *fct_file << "#FUNCTION" << "\n"; + // KEYWORD + *fct_file << "#FUNCTION" + << "\n"; //-------------------------------------------------------------------- // TYPE - *fct_file << " $TYPE" << "\n"; + *fct_file << " $TYPE" + << "\n"; *fct_file << " "; *fct_file << type_name << "\n"; //-------------------------------------------------------------------- // GEO_TYPE - *fct_file << " $GEO_TYPE" << "\n"; + *fct_file << " $GEO_TYPE" + << "\n"; *fct_file << " "; *fct_file << geo_type_name << " " << geo_name << "\n"; //-------------------------------------------------------------------- // DATA - *fct_file << " $VARIABLES" << "\n"; + *fct_file << " $VARIABLES" + << "\n"; *fct_file << " "; - for(i = 0; i < variable_names_vector_size; i++) + for (i = 0; i < variable_names_vector_size; i++) *fct_file << " " << variable_names_vector[i]; *fct_file << "\n"; //-------------------------------------------------------------------- // DATA - *fct_file << " $DATA" << "\n"; - for(i = 0; i < variable_data_vector_size; i++) + *fct_file << " $DATA" + << "\n"; + for (i = 0; i < variable_data_vector_size; i++) { *fct_file << " "; - for(j = 0; j < variable_names_vector_size; j++) + for (j = 0; j < variable_names_vector_size; j++) *fct_file << " " << variable_data_vector[i][j]; *fct_file << "\n"; } @@ -325,33 +329,34 @@ void FCTRead(std::string base_file_name) // file handling std::string fct_file_name; fct_file_name = base_file_name + FCT_FILE_EXTENSION; - std::ifstream fct_file (fct_file_name.data(),std::ios::in); + std::ifstream fct_file(fct_file_name.data(), std::ios::in); if (!fct_file.good()) return; - fct_file.seekg(0L,std::ios::beg); + fct_file.seekg(0L, std::ios::beg); //======================================================================== // keyword loop - std::cout << "FCTRead" << "\n"; + std::cout << "FCTRead" + << "\n"; while (!fct_file.eof()) { - fct_file.getline(line,MAX_ZEILE); + fct_file.getline(line, MAX_ZEILE); line_string = line; - if (line_string.find("#STOP") != std::string::npos) - { - return ; - } + if (line_string.find("#STOP") != std::string::npos) + { + return; + } //---------------------------------------------------------------------- // keyword found - if(line_string.find("#FUNCTION") != std::string::npos) + if (line_string.find("#FUNCTION") != std::string::npos) { m_fct = new CFunction(); position = m_fct->Read(&fct_file); fct_vector.push_back(m_fct); - fct_file.seekg(position,std::ios::beg); - } // keyword found - } // eof + fct_file.seekg(position, std::ios::beg); + } // keyword found + } // eof } /************************************************************************** @@ -362,7 +367,7 @@ void FCTRead(std::string base_file_name) last modification: **************************************************************************/ void FCTWrite(std::string file_base_name) -//void MATWriteMediumProperties(fstream *mp_file) +// void MATWriteMediumProperties(fstream *mp_file) { CFunction* m_fct = NULL; std::string sub_line; @@ -370,24 +375,24 @@ void FCTWrite(std::string file_base_name) //======================================================================== // File handling std::string fct_file_name = file_base_name + FCT_FILE_EXTENSION; - std::fstream fct_file (fct_file_name.c_str(),ios::trunc | ios::out); - fct_file.setf(std::ios::scientific,std::ios::floatfield); + std::fstream fct_file(fct_file_name.c_str(), ios::trunc | ios::out); + fct_file.setf(std::ios::scientific, std::ios::floatfield); fct_file.precision(12); if (!fct_file.good()) return; - fct_file << "GeoSys-FCT: Functions ------------------------------------------------" << - "\n"; + fct_file << "GeoSys-FCT: Functions ------------------------------------------------" + << "\n"; //======================================================================== // FCT vect list int no_fct = (int)fct_vector.size(); int i; - for(i = 0; i < no_fct; i++) + for (i = 0; i < no_fct; i++) { m_fct = fct_vector[i]; m_fct->Write(&fct_file); } fct_file << "#STOP"; - //mp_file.close(); + // mp_file.close(); } /************************************************************************** @@ -400,7 +405,7 @@ void FCTWrite(std::string file_base_name) void FCTReadTIMData(std::string file_name_base) { int counter; - int pos1,pos2; + int pos1, pos2; double scale_factor = 1.; double* variable_data = NULL; char line[MAX_ZEILE]; @@ -423,61 +428,61 @@ void FCTReadTIMData(std::string file_name_base) std::cout << "Read FCT properties from " << file_name_base << "\n"; //---------------------------------------------------------------------- // File handling - //OK4105 + // OK4105 std::string csv_file_name = file_name_base + CSV_FILE_EXTENSION; - std::ifstream csv_file (csv_file_name.data(),std::ios::in); + std::ifstream csv_file(csv_file_name.data(), std::ios::in); if (!csv_file.good()) return; - csv_file.seekg(0L,std::ios::beg); + csv_file.seekg(0L, std::ios::beg); //---------------------------------------------------------------------- // Evaluate header - csv_file.getline(line,MAX_ZEILE); + csv_file.getline(line, MAX_ZEILE); line_string = line; //...................................................................... // MODE check pos1 = 0; - sub_string = get_sub_string(line_string,delimiter_type,pos1,&pos2); - sub_string = line_string.substr(pos1,pos2 - pos1); + sub_string = get_sub_string(line_string, delimiter_type, pos1, &pos2); + sub_string = line_string.substr(pos1, pos2 - pos1); header_rows = sub_string; pos1 = pos2 + 1; - sub_string = get_sub_string(line_string,delimiter_type,pos1,&pos2); - sub_string = line_string.substr(pos1,pos2 - pos1); + sub_string = get_sub_string(line_string, delimiter_type, pos1, &pos2); + sub_string = line_string.substr(pos1, pos2 - pos1); header_cols = sub_string; - if(header_cols.find("TIME") != std::string::npos) + if (header_cols.find("TIME") != std::string::npos) mode = 0; - if(header_rows.find("TIME") != std::string::npos) + if (header_rows.find("TIME") != std::string::npos) mode = 1; //====================================================================== // MODE 0 - ROW: PNT, COL: TIM - if(mode == 0) + if (mode == 0) { pos1 = 0; - sub_string = get_sub_string(line_string,delimiter_type,pos1,&pos2); - sub_string = line_string.substr(pos1,pos2 - pos1); + sub_string = get_sub_string(line_string, delimiter_type, pos1, &pos2); + sub_string = line_string.substr(pos1, pos2 - pos1); fct_type_name = sub_string; pos1 = pos2 + 1; - sub_string = get_sub_string(line_string,"=",pos1,&pos2); - sub_string = line_string.substr(pos1,pos2 - pos1); + sub_string = get_sub_string(line_string, "=", pos1, &pos2); + sub_string = line_string.substr(pos1, pos2 - pos1); fct_x_name = sub_string; pos1 = pos2 + 1; - sub_string = line_string.substr(pos1,pos2 + fct_x_name.size() + 2 - pos1); + sub_string = line_string.substr(pos1, pos2 + fct_x_name.size() + 2 - pos1); fct_x_unit = sub_string; - if(fct_x_unit.find("MONTH") != string::npos) + if (fct_x_unit.find("MONTH") != string::npos) scale_factor = 86400. * 30.; pos1 = pos2 + (int)fct_x_name.size() + 2 + 1; - sub_string = get_sub_string(line_string,delimiter_type,pos1,&pos2); - sub_string = line_string.substr(pos1,pos2 - pos1); + sub_string = get_sub_string(line_string, delimiter_type, pos1, &pos2); + sub_string = line_string.substr(pos1, pos2 - pos1); fct_y_name = sub_string; //---------------------------------------------------------------------- // Read header - csv_file.getline(line,MAX_ZEILE); + csv_file.getline(line, MAX_ZEILE); //---------------------------------------------------------------------- // Read POINT, TIME ... while (!csv_file.eof()) { - csv_file.getline(line,MAX_ZEILE); + csv_file.getline(line, MAX_ZEILE); line_string = line; - if(line_string.empty()) + if (line_string.empty()) return; //.................................................................... m_fct = new CFunction(); @@ -487,8 +492,8 @@ void FCTReadTIMData(std::string file_name_base) //.................................................................... // POINT pos1 = 0; - sub_string = get_sub_string(line_string,delimiter_type,pos1,&pos2); - sub_string = line_string.substr(pos1,pos2 - pos1); + sub_string = get_sub_string(line_string, delimiter_type, pos1, &pos2); + sub_string = line_string.substr(pos1, pos2 - pos1); m_fct->geo_type_name = "POINT"; m_fct->geo_name = sub_string; fct_vector.push_back(m_fct); @@ -501,55 +506,55 @@ void FCTReadTIMData(std::string file_name_base) //.................................................................... // TIME, VALUE counter = 0; - while((pos1 > -1) && (pos2 > -1)) + while ((pos1 > -1) && (pos2 > -1)) { counter++; pos1 = pos2 + 1; - sub_string = get_sub_string(line_string,delimiter_type,pos1,&pos2); - if(pos2 < 0) + sub_string = get_sub_string(line_string, delimiter_type, pos1, &pos2); + if (pos2 < 0) break; variable_data = new double[2]; // TIME variable_data[0] = counter * scale_factor; // VALUE - sub_string = line_string.substr(pos1,pos2 - pos1); - variable_data[1] = strtod(sub_string.data(),NULL); + sub_string = line_string.substr(pos1, pos2 - pos1); + variable_data[1] = strtod(sub_string.data(), NULL); m_fct->variable_data_vector.push_back(variable_data); } //.................................................................... - } // eof + } // eof //---------------------------------------------------------------------- - } // MODE==0 + } // MODE==0 //====================================================================== // MODE 1 - ROW: TIM, COL: PNT - if(mode == 1) + if (mode == 1) { - csv_file.seekg(0L,std::ios::beg); - csv_file.getline(line,MAX_ZEILE); + csv_file.seekg(0L, std::ios::beg); + csv_file.getline(line, MAX_ZEILE); pos1 = 0; - sub_string = get_sub_string(header_rows,"=",pos1,&pos2); - sub_string = line_string.substr(pos1,pos2 - pos1); + sub_string = get_sub_string(header_rows, "=", pos1, &pos2); + sub_string = line_string.substr(pos1, pos2 - pos1); fct_x_name = sub_string; pos1 = pos2 + 1; - sub_string = line_string.substr(pos1,pos2 + fct_x_name.size() + 1 - pos1); + sub_string = line_string.substr(pos1, pos2 + fct_x_name.size() + 1 - pos1); fct_x_unit = sub_string; - if(fct_x_unit.find("MONTH") != string::npos) + if (fct_x_unit.find("MONTH") != string::npos) scale_factor = 86400. * 30.; - if(fct_x_unit.find("YEAR") != string::npos) + if (fct_x_unit.find("YEAR") != string::npos) scale_factor = 86400. * 364.25; pos1 = pos2 + (int)fct_x_name.size() + 1 + 1; - sub_string = get_sub_string(line_string,delimiter_type,pos1,&pos2); - sub_string = line_string.substr(pos1,pos2 - pos1); + sub_string = get_sub_string(line_string, delimiter_type, pos1, &pos2); + sub_string = line_string.substr(pos1, pos2 - pos1); fct_y_name = sub_string; //-------------------------------------------------------------------- // Read header - csv_file.getline(line,MAX_ZEILE); + csv_file.getline(line, MAX_ZEILE); line_string = line; pos1 = 0; - sub_string = get_sub_string(line_string,delimiter_type,pos1,&pos2); - //sub_string = line_string.substr(pos1,pos2-pos1); + sub_string = get_sub_string(line_string, delimiter_type, pos1, &pos2); + // sub_string = line_string.substr(pos1,pos2-pos1); int no_fct = 0; - while(pos2 > 0) + while (pos2 > 0) { m_fct = new CFunction(); m_fct->geo_type_name = "POINT"; @@ -557,8 +562,8 @@ void FCTReadTIMData(std::string file_name_base) m_fct->variable_names_vector.push_back(fct_x_name); m_fct->variable_names_vector.push_back(fct_y_name); pos1 = pos2 + 1; - sub_string = get_sub_string(line_string,delimiter_type,pos1,&pos2); - sub_string = line_string.substr(pos1,pos2 - pos1); + sub_string = get_sub_string(line_string, delimiter_type, pos1, &pos2); + sub_string = line_string.substr(pos1, pos2 - pos1); m_fct->geo_name = sub_string; fct_vector.push_back(m_fct); no_fct++; @@ -567,30 +572,30 @@ void FCTReadTIMData(std::string file_name_base) // Read data: TIME, POINT ... while (!csv_file.eof()) { - csv_file.getline(line,MAX_ZEILE); + csv_file.getline(line, MAX_ZEILE); line_string = line; - if(line_string.empty()) + if (line_string.empty()) return; //.................................................................. // TIM pos1 = 0; - sub_string = get_sub_string(line_string,delimiter_type,pos1,&pos2); - sub_string = line_string.substr(pos1,pos2 - pos1); - time = strtod(sub_string.data(),NULL); - for(i = 0; i < no_fct; i++) + sub_string = get_sub_string(line_string, delimiter_type, pos1, &pos2); + sub_string = line_string.substr(pos1, pos2 - pos1); + time = strtod(sub_string.data(), NULL); + for (i = 0; i < no_fct; i++) { m_fct = fct_vector[i]; variable_data = new double[2]; pos1 = pos2 + 1; - sub_string = get_sub_string(line_string,delimiter_type,pos1,&pos2); - sub_string = line_string.substr(pos1,pos2 - pos1); + sub_string = get_sub_string(line_string, delimiter_type, pos1, &pos2); + sub_string = line_string.substr(pos1, pos2 - pos1); variable_data[0] = time * scale_factor; - value = strtod(sub_string.data(),NULL); + value = strtod(sub_string.data(), NULL); variable_data[1] = value; m_fct->variable_data_vector.push_back(variable_data); } //.................................................................. - } // eof + } // eof //-------------------------------------------------------------------- } //====================================================================== @@ -609,7 +614,7 @@ double CFunction::GetValue(double point, bool* valid, int method) { long anz; anz = (long)variable_data_vector.size(); - if(anz == 0) + if (anz == 0) return 1.0; *valid = true; register long i; @@ -618,38 +623,36 @@ double CFunction::GetValue(double point, bool* valid, int method) //---------------------------------------------------------------------- // value = variable_data_vector[0][1]; - if(point < variable_data_vector[0][0]) + if (point < variable_data_vector[0][0]) { *valid = false; return value; } - if(point > variable_data_vector[anz - 1][0]) + if (point > variable_data_vector[anz - 1][0]) { *valid = false; return variable_data_vector[anz - 1][1]; } - //Check what type of function, continuous or transient + // Check what type of function, continuous or transient if (dis_type_name != "TRANSIENT") { //---------------------------------------------------------------------- // Suchen der Stuetzstelle. Vorraussetzung: Zeitpunkte aufsteigend geordnet i = 1l; - while(point > variable_data_vector[i][0]) + while (point > variable_data_vector[i][0]) { i++; switch (method) { - case 0: // Lineare Interpolation - value = variable_data_vector[i - 1][1] \ - + (variable_data_vector[i][1] - - variable_data_vector[i - 1][1]) \ - / (variable_data_vector[i][0] - - variable_data_vector[i - 1][0]) \ - * (point - variable_data_vector[i - 1][0]); - break; - case 1: // Piece wise constant. FS//WW - value = variable_data_vector[i - 1][1]; - break; + case 0: // Lineare Interpolation + value = variable_data_vector[i - 1][1] + + (variable_data_vector[i][1] - variable_data_vector[i - 1][1]) + / (variable_data_vector[i][0] - variable_data_vector[i - 1][0]) + * (point - variable_data_vector[i - 1][0]); + break; + case 1: // Piece wise constant. FS//WW + value = variable_data_vector[i - 1][1]; + break; } } } @@ -661,18 +664,18 @@ double CFunction::GetValue(double point, bool* valid, int method) for (j = 0; j < anz; j += 2) { double temp1 = variable_data_vector[j][0]; - //OK double temp2 = variable_data_vector[j][1]; - if(point > temp1) + // OK double temp2 = variable_data_vector[j][1]; + if (point > temp1) index++; } if (index % 2 == 1) { pp = (index - 1) * 2; np = index * 2; - value = variable_data_vector[pp][1] \ - + (variable_data_vector[np][1] - variable_data_vector[pp][1]) \ - / (variable_data_vector[np][0] - variable_data_vector[pp][0]) \ - * (point - variable_data_vector[pp][0]); + value = variable_data_vector[pp][1] + + (variable_data_vector[np][1] - variable_data_vector[pp][1]) + / (variable_data_vector[np][0] - variable_data_vector[pp][0]) + * (point - variable_data_vector[pp][0]); *valid = true; } if (index % 2 == 0) diff --git a/FEM/rf_fct.h b/FEM/rf_fct.h index 81afc8899..0ed028ab5 100644 --- a/FEM/rf_fct.h +++ b/FEM/rf_fct.h @@ -29,30 +29,31 @@ class CFunction public: CFunction(void); ~CFunction(void); - void Set(std::string,std::string,double); + void Set(std::string, std::string, double); std::ios::pos_type Read(std::ifstream*); void Write(std::fstream*); // add int method. WW double GetValue(double point, bool* valid, int method = 0); + public: std::string type_name; std::string geo_name; std::string geo_type_name; - std::string dis_type_name; //CMCD - std::vectorvariable_names_vector; - std::vectorvariable_data_vector; + std::string dis_type_name; // CMCD + std::vector variable_names_vector; + std::vector variable_data_vector; // int matrix_dimension_x; //NB4703 // int matrix_dimension_y; //NB4703 - std::vectormatrix_dimension; //NB 4.8.01 + std::vector matrix_dimension; // NB 4.8.01 bool selected; }; -extern std::vectorfct_vector; +extern std::vector fct_vector; extern void FCTWrite(std::string); extern void FCTRead(std::string); extern void FCTReadTIMData(std::string); extern CFunction* FCTGet(std::string); -extern CFunction* FCTGet(long); //YD +extern CFunction* FCTGet(long); // YD #define FCT_FILE_EXTENSION ".fct" #endif diff --git a/FEM/rf_fluid_momentum.cpp b/FEM/rf_fluid_momentum.cpp index 0f158bdd4..71395aa82 100644 --- a/FEM/rf_fluid_momentum.cpp +++ b/FEM/rf_fluid_momentum.cpp @@ -35,7 +35,7 @@ PlaneSet::PlaneSet(void) { eleIndex = 0; ratio = 0.0; - for(int i = 0; i < 3; ++i) + for (int i = 0; i < 3; ++i) V[i] = norm[i] = 0.0; } @@ -55,8 +55,8 @@ CrossRoad::CrossRoad(void) CrossRoad::~CrossRoad(void) { - if(plane) - delete [] plane; + if (plane) + delete[] plane; } /************************************************************************** @@ -68,7 +68,7 @@ CrossRoad::~CrossRoad(void) **************************************************************************/ void CrossRoad::CreatePlaneSet(const int index) { - plane = new PlaneSet[index] (); + plane = new PlaneSet[index](); } /************************************************************************** @@ -81,7 +81,7 @@ void CrossRoad::CreatePlaneSet(const int index) CFluidMomentum::CFluidMomentum(void) { m_pcs = NULL; - RWPTSwitch = 0; // Set to be no + RWPTSwitch = 0; // Set to be no } /************************************************************************** @@ -111,80 +111,83 @@ double CFluidMomentum::Execute(int loop_process_number) Create(); - //JT: Printout message. Give zero error to coupling scheme. - std::cout << "\n ================================================" << "\n"; - std::cout << " ->Process " << loop_process_number << ": " << "FLUID_MOMENTUM" << "\n"; - std::cout << " ================================================" << "\n"; - cout << " Solving for nodal velocity..." << "\n"; + // JT: Printout message. Give zero error to coupling scheme. + std::cout << "\n ================================================" + << "\n"; + std::cout << " ->Process " << loop_process_number << ": " + << "FLUID_MOMENTUM" + << "\n"; + std::cout << " ================================================" + << "\n"; + cout << " Solving for nodal velocity..." + << "\n"; cpl_max_relative_error = pcs_error; - bool isFlow = false; - CRFProcess *a_pcs = NULL; - // CRFProcess *f_pcs = NULL; - for(int k=0; kgetProcessType () == FiniteElement::RICHARDS_FLOW - || a_pcs->getProcessType () == FiniteElement::LIQUID_FLOW - || a_pcs->getProcessType () == FiniteElement::GROUNDWATER_FLOW - || a_pcs->getProcessType () == FiniteElement::TWO_PHASE_FLOW - || a_pcs->getProcessType () == FiniteElement::MULTI_PHASE_FLOW - ) - { - isFlow = true; - break; - } - } - for(int i = 0; i < no_processes; ++i) + bool isFlow = false; + CRFProcess* a_pcs = NULL; + // CRFProcess *f_pcs = NULL; + for (int k = 0; k < no_processes; k++) + { + a_pcs = pcs_vector[k]; + if (!a_pcs) + continue; + if (a_pcs->getProcessType() == FiniteElement::RICHARDS_FLOW + || a_pcs->getProcessType() == FiniteElement::LIQUID_FLOW + || a_pcs->getProcessType() == FiniteElement::GROUNDWATER_FLOW + || a_pcs->getProcessType() == FiniteElement::TWO_PHASE_FLOW + || a_pcs->getProcessType() == FiniteElement::MULTI_PHASE_FLOW) + { + isFlow = true; + break; + } + } + for (int i = 0; i < no_processes; ++i) { m_pcs = pcs_vector[i]; // Select the mesh whose process name has the mesh for Fluid_Momentum // if( m_pcs->pcs_type_name.find("RICHARDS_FLOW")!=string::npos) TF - if( m_pcs->getProcessType () == FiniteElement::RICHARDS_FLOW) + if (m_pcs->getProcessType() == FiniteElement::RICHARDS_FLOW) m_msh = FEMGet("RICHARDS_FLOW"); // else if( m_pcs->pcs_type_name.find("LIQUID_FLOW")!=string::npos) TF - else if( m_pcs->getProcessType () == FiniteElement::LIQUID_FLOW) + else if (m_pcs->getProcessType() == FiniteElement::LIQUID_FLOW) m_msh = FEMGet("LIQUID_FLOW"); // else if( m_pcs->pcs_type_name.find("GROUNDWATER_FLOW")!=string::npos) TF - else if( m_pcs->getProcessType () == FiniteElement::GROUNDWATER_FLOW) + else if (m_pcs->getProcessType() == FiniteElement::GROUNDWATER_FLOW) m_msh = FEMGet("GROUNDWATER_FLOW"); // if(m_pcs->pcs_type_name.find("FLUID_MOMENTUM")!=string::npos) TF - if(m_pcs->getProcessType () == FiniteElement::FLUID_MOMENTUM) - { - if( isFlow ) - SolveDarcyVelocityOnNode(); - else - { - m_msh = FEMGet("FLUID_MOMENTUM"); - string vel_file = FileName+".vel"; - ifstream ins(vel_file.c_str()); - double vx, vy, vz; - - int nidx = m_pcs->GetNodeValueIndex("VELOCITY1_X")+1; - int nidy = m_pcs->GetNodeValueIndex("VELOCITY1_Y")+1; - int nidz = m_pcs->GetNodeValueIndex("VELOCITY1_Z")+1; - - for (size_t i = 0; i < m_pcs->m_msh->nod_vector.size(); i++) - { - ins>>vx>>vy>>vz>>ws; - m_pcs->SetNodeValue(i,nidx,vx); - m_pcs->SetNodeValue(i,nidy,vy); - m_pcs->SetNodeValue(i,nidz,vz); - } - } + if (m_pcs->getProcessType() == FiniteElement::FLUID_MOMENTUM) + { + if (isFlow) + SolveDarcyVelocityOnNode(); + else + { + m_msh = FEMGet("FLUID_MOMENTUM"); + string vel_file = FileName + ".vel"; + ifstream ins(vel_file.c_str()); + double vx, vy, vz; - } - } + int nidx = m_pcs->GetNodeValueIndex("VELOCITY1_X") + 1; + int nidy = m_pcs->GetNodeValueIndex("VELOCITY1_Y") + 1; + int nidz = m_pcs->GetNodeValueIndex("VELOCITY1_Z") + 1; + + for (size_t i = 0; i < m_pcs->m_msh->nod_vector.size(); i++) + { + ins >> vx >> vy >> vz >> ws; + m_pcs->SetNodeValue(i, nidx, vx); + m_pcs->SetNodeValue(i, nidy, vy); + m_pcs->SetNodeValue(i, nidz, vz); + } + } + } + } // Just one time execution. Needs improvement later on. m_pcs = PCSGet("RANDOM_WALK"); - if(m_pcs && RWPTSwitch == 0) + if (m_pcs && RWPTSwitch == 0) { - if(m_msh->GetCoordinateFlag() != 32) + if (m_msh->GetCoordinateFlag() != 32) ConstructFractureNetworkTopology(); RWPTSwitch = 1; } @@ -206,55 +209,55 @@ void CFluidMomentum::SolveDarcyVelocityOnNode() long i; MeshLib::CElem* elem = NULL; - CheckMarkedElement(); + CheckMarkedElement(); fem = new CFiniteElementStd(m_pcs, m_msh->GetCoordinateFlag()); // Checking the coordinateflag for proper solution. int coordinateflag = m_msh->GetCoordinateFlag(); int dimension = 0; int axis = 0; - if(coordinateflag == 10) + if (coordinateflag == 10) { dimension = 1; - axis = 0; // x only + axis = 0; // x only } - else if(coordinateflag == 11) + else if (coordinateflag == 11) { dimension = 1; - axis = 1; // y only + axis = 1; // y only } - else if(coordinateflag == 12) + else if (coordinateflag == 12) { dimension = 1; - axis = 2; // z only + axis = 2; // z only } - else if(coordinateflag == 21) + else if (coordinateflag == 21) { dimension = 2; - axis = 1; // x, y only + axis = 1; // x, y only } - else if(coordinateflag == 22) + else if (coordinateflag == 22) { dimension = 2; - axis = 2; // x, z only + axis = 2; // x, z only } - else if(coordinateflag == 32) + else if (coordinateflag == 32) { dimension = 3; - axis = 3; // x, y, z only + axis = 3; // x, y, z only } // Loop over three dimension to solve three velocity components for (int phase = 0; phase < GetRFProcessNumPhases(); phase++) { - for(int d = 0; d < dimension; ++d) + for (int d = 0; d < dimension; ++d) { - /* Initializations */ - /* System matrix */ -#if defined(NEW_EQS) //WW +/* Initializations */ +/* System matrix */ +#if defined(NEW_EQS) // WW m_pcs->EQSInitialize(); #else - SetLinearSolverType(m_pcs->getEQSPointer(), m_num); //NW + SetLinearSolverType(m_pcs->getEQSPointer(), m_num); // NW SetZeroLinearSolver(m_pcs->getEQSPointer()); #endif @@ -269,57 +272,48 @@ void CFluidMomentum::SolveDarcyVelocityOnNode() } // MXDumpGLS("rf_pcs.txt",1,m_pcs->eqs->b,m_pcs->eqs->x); //abort(); - m_pcs->IncorporateBoundaryConditions(-1,d); - // Solve for velocity + m_pcs->IncorporateBoundaryConditions(-1, d); +// Solve for velocity #if defined(NEW_EQS) double* x; - int size = (int)m_msh->nod_vector.size(); //OK411??? long + int size = (int)m_msh->nod_vector.size(); // OK411??? long x = new double[size]; #if defined(LIS) m_pcs->EQSSolver(x); // an option added to tell FLUID_MOMENTUM for sparse matrix system. - cout << "Solver passed in FLUID_MOMENTUM." << "\n"; + cout << "Solver passed in FLUID_MOMENTUM." + << "\n"; #endif #else ExecuteLinearSolver(m_pcs->getEQSPointer()); #endif /* Store solution vector in model node values table */ - if(dimension == 1) - nidx1 = - m_pcs->GetNodeValueIndex(m_pcs->pcs_primary_function_name[ - axis]) + 1; - else if(dimension == 2) + if (dimension == 1) + nidx1 = m_pcs->GetNodeValueIndex(m_pcs->pcs_primary_function_name[axis]) + 1; + else if (dimension == 2) { - if(axis == 1) // x,y only - nidx1 = m_pcs->GetNodeValueIndex( - m_pcs->pcs_primary_function_name[(axis - d + - 1) % - dimension]) + 1; - else if(axis == 2) // x,z only - nidx1 = m_pcs->GetNodeValueIndex( - m_pcs->pcs_primary_function_name[(axis - d + - 1) % 3]) + 1; + if (axis == 1) // x,y only + nidx1 = m_pcs->GetNodeValueIndex(m_pcs->pcs_primary_function_name[(axis - d + 1) % dimension]) + 1; + else if (axis == 2) // x,z only + nidx1 = m_pcs->GetNodeValueIndex(m_pcs->pcs_primary_function_name[(axis - d + 1) % 3]) + 1; else - abort(); // Just stop something's wrong. + abort(); // Just stop something's wrong. } - else if(dimension == 3) - nidx1 = m_pcs->GetNodeValueIndex( - m_pcs->pcs_primary_function_name[d]) + 1; + else if (dimension == 3) + nidx1 = m_pcs->GetNodeValueIndex(m_pcs->pcs_primary_function_name[d]) + 1; else - abort(); // Just stop something's wrong. + abort(); // Just stop something's wrong. #if defined(NEW_EQS) - for(int j = 0; j < size; j++) - m_pcs->SetNodeValue(m_msh->Eqs2Global_NodeIndex[j],nidx1,x[j]); + for (int j = 0; j < size; j++) + m_pcs->SetNodeValue(m_msh->Eqs2Global_NodeIndex[j], nidx1, x[j]); - delete [] x; + delete[] x; #else - LINEAR_SOLVER *eqs = m_pcs->getEQSPointer(); - for(int j = 0; j < eqs->dim; j++) - m_pcs->SetNodeValue(m_msh->Eqs2Global_NodeIndex[j], - nidx1, - eqs->x[j]); + LINEAR_SOLVER* eqs = m_pcs->getEQSPointer(); + for (int j = 0; j < eqs->dim; j++) + m_pcs->SetNodeValue(m_msh->Eqs2Global_NodeIndex[j], nidx1, eqs->x[j]); #endif } @@ -376,20 +370,11 @@ void CFluidMomentum::SolveDarcyVelocityOnNode() double vx = 0.0, vy = 0.0, vz = 0.0; int numOfNodeInElement = elem->GetVertexNumber(); - for(int j = 0; j < numOfNodeInElement; ++j) + for (int j = 0; j < numOfNodeInElement; ++j) { - vx += m_pcs->GetNodeValue(elem->GetNodeIndex( - j), - m_pcs->GetNodeValueIndex( - "VELOCITY1_X") + 1); - vy += m_pcs->GetNodeValue(elem->GetNodeIndex( - j), - m_pcs->GetNodeValueIndex( - "VELOCITY1_Y") + 1); - vz += m_pcs->GetNodeValue(elem->GetNodeIndex( - j), - m_pcs->GetNodeValueIndex( - "VELOCITY1_Z") + 1); + vx += m_pcs->GetNodeValue(elem->GetNodeIndex(j), m_pcs->GetNodeValueIndex("VELOCITY1_X") + 1); + vy += m_pcs->GetNodeValue(elem->GetNodeIndex(j), m_pcs->GetNodeValueIndex("VELOCITY1_Y") + 1); + vz += m_pcs->GetNodeValue(elem->GetNodeIndex(j), m_pcs->GetNodeValueIndex("VELOCITY1_Z") + 1); } vx /= (double)numOfNodeInElement; vy /= (double)numOfNodeInElement; @@ -401,12 +386,9 @@ void CFluidMomentum::SolveDarcyVelocityOnNode() case 0: */ - m_pcs->SetElementValue(i, m_pcs->GetElementValueIndex( - "VELOCITY1_X") + 1, vx); - m_pcs->SetElementValue(i, m_pcs->GetElementValueIndex( - "VELOCITY1_Y") + 1, vy); - m_pcs->SetElementValue(i, m_pcs->GetElementValueIndex( - "VELOCITY1_Z") + 1, vz); + m_pcs->SetElementValue(i, m_pcs->GetElementValueIndex("VELOCITY1_X") + 1, vx); + m_pcs->SetElementValue(i, m_pcs->GetElementValueIndex("VELOCITY1_Y") + 1, vy); + m_pcs->SetElementValue(i, m_pcs->GetElementValueIndex("VELOCITY1_Z") + 1, vz); /* break; @@ -441,15 +423,16 @@ void CFluidMomentum::Create() CNumerics* m_num_tmp = NULL; - for(int i = 0; i < no_numerics; i++) + for (int i = 0; i < no_numerics; i++) { m_num_tmp = num_vector[i]; - if(m_num_tmp->pcs_type_name.compare("FLUID_MOMENTUM") == 0 ) + if (m_num_tmp->pcs_type_name.compare("FLUID_MOMENTUM") == 0) m_num = m_num_tmp; } - if(!m_num) - cout << "Warning in CRFProcess::Create() - no numerical properties" << "\n"; + if (!m_num) + cout << "Warning in CRFProcess::Create() - no numerical properties" + << "\n"; } /************************************************************************** @@ -464,30 +447,30 @@ void CFluidMomentum::ConstructFractureNetworkTopology() { // Mount the process and the mesh CFEMesh* m_msh = NULL; - for(int i = 0; i < (int)pcs_vector.size(); ++i) + for (int i = 0; i < (int)pcs_vector.size(); ++i) { m_pcs = pcs_vector[i]; // Select the mesh whose process name has the mesh for Fluid_Momentum // if( m_pcs->pcs_type_name.find("RICHARDS_FLOW")!=string::npos) TF - if( m_pcs->getProcessType () == FiniteElement::RICHARDS_FLOW) + if (m_pcs->getProcessType() == FiniteElement::RICHARDS_FLOW) m_msh = FEMGet("RICHARDS_FLOW"); // else if( m_pcs->pcs_type_name.find("LIQUID_FLOW")!=string::npos) TF - else if( m_pcs->getProcessType () == FiniteElement::LIQUID_FLOW) + else if (m_pcs->getProcessType() == FiniteElement::LIQUID_FLOW) m_msh = FEMGet("LIQUID_FLOW"); // else if( m_pcs->pcs_type_name.find("GROUNDWATER_FLOW")!=string::npos) TF - else if( m_pcs->getProcessType () == FiniteElement::GROUNDWATER_FLOW) + else if (m_pcs->getProcessType() == FiniteElement::GROUNDWATER_FLOW) m_msh = FEMGet("GROUNDWATER_FLOW"); } m_pcs = PCSGet("FLUID_MOMENTUM"); - if(!m_msh) - m_msh = m_pcs->m_msh; + if (!m_msh) + m_msh = m_pcs->m_msh; // Something must be done later on here. double tolerance = 1e-12; // Checking the node is a crossroad starts here // Loop over all the nodes - for(int i = 0; i < (int) m_msh->nod_vector.size(); ++i) + for (int i = 0; i < (int)m_msh->nod_vector.size(); ++i) { MeshLib::CNode* thisNode = m_msh->nod_vector[i]; int NumOfNeighborElements = (int)thisNode->getConnectedElementIDs().size(); @@ -498,39 +481,36 @@ void CFluidMomentum::ConstructFractureNetworkTopology() // Let's store the index of the reference element // to the connected_planes of thisNode thisNode->connected_planes.push_back(index); - if(m_msh->GetCoordinateFlag() != 32 && m_msh->GetCoordinateFlag() != 22) + if (m_msh->GetCoordinateFlag() != 32 && m_msh->GetCoordinateFlag() != 22) { norm[0] = 0.0; norm[1] = 0.0; norm[2] = 1.0; } else - for(int j = 0; j < 3; ++j) + for (int j = 0; j < 3; ++j) norm[j] = m_msh->ele_vector[index]->getTransformTensor(j + 6); // Let's compare this norm with other norms of the connected elements - for(int j = 1; j < NumOfNeighborElements; ++j) + for (int j = 1; j < NumOfNeighborElements; ++j) { double normOther[3]; // Let's get the element one by one. int indexOther = thisNode->getConnectedElementIDs()[j]; - if(m_msh->GetCoordinateFlag() != 32 && m_msh->GetCoordinateFlag() != 22) + if (m_msh->GetCoordinateFlag() != 32 && m_msh->GetCoordinateFlag() != 22) { normOther[0] = 0.0; normOther[1] = 0.0; normOther[2] = 1.0; } else - for(int k = 0; k < 3; ++k) - normOther[k] = - m_msh->ele_vector[indexOther]->getTransformTensor( - k + 6); + for (int k = 0; k < 3; ++k) + normOther[k] = m_msh->ele_vector[indexOther]->getTransformTensor(k + 6); // Check two norms are same. - if( fabs(norm[0] - normOther[0]) < tolerance && - fabs(norm[1] - normOther[1]) < tolerance - && fabs(norm[2] - normOther[2]) < tolerance ) - ; // Two elements stay on the same plane + if (fabs(norm[0] - normOther[0]) < tolerance && fabs(norm[1] - normOther[1]) < tolerance + && fabs(norm[2] - normOther[2]) < tolerance) + ; // Two elements stay on the same plane else { thisNode->crossroad = true; @@ -545,65 +525,54 @@ void CFluidMomentum::ConstructFractureNetworkTopology() // Get rid of duplicates of the elements that have the same norm for the potential crossroads // This works great with h_frac example in RWPT - if(thisNode->crossroad) + if (thisNode->crossroad) { // Let's get rid of duplicates of the elements on the same plane int numOfPlanesAtCrossroad = (int)thisNode->connected_planes.size(); - for(int j = 0; j < numOfPlanesAtCrossroad; ++j) + for (int j = 0; j < numOfPlanesAtCrossroad; ++j) { double normOther[3]; // Let's get the element one by one. int indexOther = thisNode->connected_planes[j]; - if(m_msh->GetCoordinateFlag() != 32 && - m_msh->GetCoordinateFlag() != 22) + if (m_msh->GetCoordinateFlag() != 32 && m_msh->GetCoordinateFlag() != 22) { normOther[0] = 0.0; normOther[1] = 0.0; normOther[2] = 1.0; } else - for(int k = 0; k < 3; ++k) - normOther[k] = - m_msh->ele_vector[indexOther]-> - getTransformTensor( - k + 6); + for (int k = 0; k < 3; ++k) + normOther[k] = m_msh->ele_vector[indexOther]->getTransformTensor(k + 6); - for(int l = j + 1; l < numOfPlanesAtCrossroad; ++l) + for (int l = j + 1; l < numOfPlanesAtCrossroad; ++l) { double normAnother[3]; // Let's get the element one by one. int indexAnother = thisNode->connected_planes[l]; - if(m_msh->GetCoordinateFlag() != 32 && - m_msh->GetCoordinateFlag() != 22) + if (m_msh->GetCoordinateFlag() != 32 && m_msh->GetCoordinateFlag() != 22) { normAnother[0] = 0.0; normAnother[1] = 0.0; normAnother[2] = 1.0; } else - for(int k = 0; k < 3; ++k) - normAnother[k] = - m_msh->ele_vector[indexAnother]-> - getTransformTensor(k + 6); + for (int k = 0; k < 3; ++k) + normAnother[k] = m_msh->ele_vector[indexAnother]->getTransformTensor(k + 6); // Check two norms are same. // If two norms of the elemenets are same, - if( fabs(normOther[0] - normAnother[0]) < tolerance && - fabs(normOther[1] - normAnother[1]) < tolerance - && fabs(normOther[2] - normAnother[2]) < tolerance ) + if (fabs(normOther[0] - normAnother[0]) < tolerance + && fabs(normOther[1] - normAnother[1]) < tolerance + && fabs(normOther[2] - normAnother[2]) < tolerance) { // Two elements stay on the same plane - for(int m = l; m < (numOfPlanesAtCrossroad - 1); - ++m) - thisNode->connected_planes[m] = - thisNode->connected_planes[m + 1]; + for (int m = l; m < (numOfPlanesAtCrossroad - 1); ++m) + thisNode->connected_planes[m] = thisNode->connected_planes[m + 1]; // Erase the element of the vector and adjust the number of the planes at crossroad - thisNode->connected_planes.erase( - thisNode->connected_planes.begin() + - numOfPlanesAtCrossroad - 1); - numOfPlanesAtCrossroad = - (int)thisNode->connected_planes.size(); + thisNode->connected_planes.erase(thisNode->connected_planes.begin() + numOfPlanesAtCrossroad + - 1); + numOfPlanesAtCrossroad = (int)thisNode->connected_planes.size(); --l; // Very important. Huh. } } @@ -618,18 +587,18 @@ void CFluidMomentum::ConstructFractureNetworkTopology() V[0] = m_pcs->GetNodeValue(i, m_pcs->GetNodeValueIndex("VELOCITY1_X") + 1); V[1] = m_pcs->GetNodeValue(i, m_pcs->GetNodeValueIndex("VELOCITY1_Y") + 1); V[2] = m_pcs->GetNodeValue(i, m_pcs->GetNodeValueIndex("VELOCITY1_Z") + 1); - if(thisNode->crossroad == false) + if (thisNode->crossroad == false) { // Let's solve the projected velocity on the element plane // by Vp = norm X (V X norm) assuming norm is a unit vector double VxNorm[3], Vp[3]; - CrossProduction(V,norm,VxNorm); - CrossProduction(norm,VxNorm, Vp); + CrossProduction(V, norm, VxNorm); + CrossProduction(norm, VxNorm, Vp); // Store the projected velocity back to the node velocity - m_pcs->SetNodeValue(i,m_pcs->GetNodeValueIndex("VELOCITY1_X") + 1,Vp[0]); - m_pcs->SetNodeValue(i,m_pcs->GetNodeValueIndex("VELOCITY1_Y") + 1,Vp[1]); - m_pcs->SetNodeValue(i,m_pcs->GetNodeValueIndex("VELOCITY1_Z") + 1,Vp[2]); + m_pcs->SetNodeValue(i, m_pcs->GetNodeValueIndex("VELOCITY1_X") + 1, Vp[0]); + m_pcs->SetNodeValue(i, m_pcs->GetNodeValueIndex("VELOCITY1_Y") + 1, Vp[1]); + m_pcs->SetNodeValue(i, m_pcs->GetNodeValueIndex("VELOCITY1_Z") + 1, Vp[2]); } else { @@ -638,55 +607,46 @@ void CFluidMomentum::ConstructFractureNetworkTopology() // Mount cross CrossRoad* thisCross; thisCross = new CrossRoad(); - thisCross->numOfThePlanes = (int) thisNode->connected_planes.size(); + thisCross->numOfThePlanes = (int)thisNode->connected_planes.size(); thisCross->CreatePlaneSet(thisCross->numOfThePlanes); // Loop over the number of connected planes - for(int j = 0; j < thisCross->numOfThePlanes; ++j) + for (int j = 0; j < thisCross->numOfThePlanes; ++j) { // Some local variables within this else double norm[3], VxNorm[3], Vp[3]; // Solve for the norm of this plane. int index = thisNode->connected_planes[j]; - if(m_msh->GetCoordinateFlag() != 32 && - m_msh->GetCoordinateFlag() != 22) + if (m_msh->GetCoordinateFlag() != 32 && m_msh->GetCoordinateFlag() != 22) { thisCross->plane[j].norm[0] = norm[0] = 0.0; thisCross->plane[j].norm[1] = norm[1] = 0.0; thisCross->plane[j].norm[2] = norm[2] = 1.0; } else - for(int k = 0; k < 3; ++k) - thisCross->plane[j].norm[k] = norm[k] = - m_msh-> - ele_vector[ - index - ]-> - getTransformTensor( - k + 6); + for (int k = 0; k < 3; ++k) + thisCross->plane[j].norm[k] = norm[k] = m_msh->ele_vector[index]->getTransformTensor(k + 6); // Store the position vector defined below - double const* CenterOfEle( - m_msh->ele_vector[index]->GetGravityCenter()); - double const* const coords (thisNode->getData()); + double const* CenterOfEle(m_msh->ele_vector[index]->GetGravityCenter()); + double const* const coords(thisNode->getData()); thisCross->plane[j].Eele[0] = CenterOfEle[0] - coords[0]; // thisNode->X(); thisCross->plane[j].Eele[1] = CenterOfEle[1] - coords[1]; // thisNode->Y(); thisCross->plane[j].Eele[2] = CenterOfEle[2] - coords[2]; // thisNode->Z(); // Solve the velocity contribution for this plane. - CrossProduction(V,norm,VxNorm); - CrossProduction(norm,VxNorm, Vp); - for(int k = 0; k < 3; ++k) + CrossProduction(V, norm, VxNorm); + CrossProduction(norm, VxNorm, Vp); + for (int k = 0; k < 3; ++k) thisCross->plane[j].V[k] = Vp[k]; // For ratio and Vmag - thisCross->plane[j].ratio = sqrt( - Vp[0] * Vp[0] + Vp[1] * Vp[1] + Vp[2] * Vp[2]); + thisCross->plane[j].ratio = sqrt(Vp[0] * Vp[0] + Vp[1] * Vp[1] + Vp[2] * Vp[2]); Vmag += thisCross->plane[j].ratio; // Update the eleIndex for this plane thisCross->plane[j].eleIndex = thisNode->connected_planes[j]; } // Let's sort the contribution of each plane and the index of this node - for(int j = 0; j < thisCross->numOfThePlanes; ++j) + for (int j = 0; j < thisCross->numOfThePlanes; ++j) thisCross->plane[j].ratio = thisCross->plane[j].ratio / Vmag; thisCross->Index = i; // velocity for each connected planes ends here. @@ -695,31 +655,31 @@ void CFluidMomentum::ConstructFractureNetworkTopology() // First, we will solve vectors from each potential crossroad to one of the center // of the connected elements. // Now some dot product. - for(int j = 0; j < thisCross->numOfThePlanes; ++j) + for (int j = 0; j < thisCross->numOfThePlanes; ++j) { double angle = 0.0; double a[3], b[3]; - for(int p = 0; p < 3; ++p) + for (int p = 0; p < 3; ++p) { a[p] = thisCross->plane[j].Eele[p]; b[p] = thisCross->plane[j].V[p]; } // Let's normalize these two vectors first. - NormalizeVector(a,3); - NormalizeVector(b,3); + NormalizeVector(a, 3); + NormalizeVector(b, 3); double dotProduct = a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; angle = acos(dotProduct); // If this angle is bigger than Pi/2 (90 degree), // then this crossroad is not a realone. - if(angle > PI / 2.0) + if (angle > PI / 2.0) thisNode->crossroad = false; } // Extraction ends here. // Now add this crossroad to the vector of all crossroads in the domain - if(thisNode->crossroad) + if (thisNode->crossroad) crossroads.push_back(thisCross); } } @@ -727,57 +687,40 @@ void CFluidMomentum::ConstructFractureNetworkTopology() // Checking the edge is a joint starts here // Loop over all the edges - for(int i = 0; i < (int) m_msh->edge_vector.size(); ++i) + for (int i = 0; i < (int)m_msh->edge_vector.size(); ++i) { // Mount the nodes of the edge - vectheNodesOfThisEdge(3); + vec theNodesOfThisEdge(3); m_msh->edge_vector[i]->GetNodes(theNodesOfThisEdge); // Do some proper projection of velocity computed from Fluid Momentum. // Get the fluid velocity for this edge double V[3], V0[3], V1[3]; - V0[0] = m_pcs->GetNodeValue( - theNodesOfThisEdge[0]->GetIndex(), m_pcs->GetNodeValueIndex( - "VELOCITY1_X") + 1); - V0[1] = m_pcs->GetNodeValue( - theNodesOfThisEdge[0]->GetIndex(), m_pcs->GetNodeValueIndex( - "VELOCITY1_Y") + 1); - V0[2] = m_pcs->GetNodeValue( - theNodesOfThisEdge[0]->GetIndex(), m_pcs->GetNodeValueIndex( - "VELOCITY1_Z") + 1); - V1[0] = m_pcs->GetNodeValue( - theNodesOfThisEdge[1]->GetIndex(), m_pcs->GetNodeValueIndex( - "VELOCITY1_X") + 1); - V1[1] = m_pcs->GetNodeValue( - theNodesOfThisEdge[1]->GetIndex(), m_pcs->GetNodeValueIndex( - "VELOCITY1_Y") + 1); - V1[2] = m_pcs->GetNodeValue( - theNodesOfThisEdge[1]->GetIndex(), m_pcs->GetNodeValueIndex( - "VELOCITY1_Z") + 1); + V0[0] = m_pcs->GetNodeValue(theNodesOfThisEdge[0]->GetIndex(), m_pcs->GetNodeValueIndex("VELOCITY1_X") + 1); + V0[1] = m_pcs->GetNodeValue(theNodesOfThisEdge[0]->GetIndex(), m_pcs->GetNodeValueIndex("VELOCITY1_Y") + 1); + V0[2] = m_pcs->GetNodeValue(theNodesOfThisEdge[0]->GetIndex(), m_pcs->GetNodeValueIndex("VELOCITY1_Z") + 1); + V1[0] = m_pcs->GetNodeValue(theNodesOfThisEdge[1]->GetIndex(), m_pcs->GetNodeValueIndex("VELOCITY1_X") + 1); + V1[1] = m_pcs->GetNodeValue(theNodesOfThisEdge[1]->GetIndex(), m_pcs->GetNodeValueIndex("VELOCITY1_Y") + 1); + V1[2] = m_pcs->GetNodeValue(theNodesOfThisEdge[1]->GetIndex(), m_pcs->GetNodeValueIndex("VELOCITY1_Z") + 1); V[0] = (V0[0] + V1[0]) / 2.0; V[1] = (V0[1] + V1[1]) / 2.0; V[2] = (V0[2] + V1[2]) / 2.0; - if( theNodesOfThisEdge[0]->crossroad && theNodesOfThisEdge[1]->crossroad ) + if (theNodesOfThisEdge[0]->crossroad && theNodesOfThisEdge[1]->crossroad) { m_msh->edge_vector[i]->SetJoint(1); // Constructing the connected elements of an edge starts here - int numOfCEfromNode0 = - (int)theNodesOfThisEdge[0]->getConnectedElementIDs().size(); - int numOfCEfromNode1 = - (int)theNodesOfThisEdge[1]->getConnectedElementIDs().size(); + int numOfCEfromNode0 = (int)theNodesOfThisEdge[0]->getConnectedElementIDs().size(); + int numOfCEfromNode1 = (int)theNodesOfThisEdge[1]->getConnectedElementIDs().size(); - for(int j = 0; j < numOfCEfromNode0; ++j) - for(int k = 0; k < numOfCEfromNode1; ++k) + for (int j = 0; j < numOfCEfromNode0; ++j) + for (int k = 0; k < numOfCEfromNode1; ++k) { - int indexOfCEfromNode0 = - theNodesOfThisEdge[0]->getConnectedElementIDs()[j]; - int indexOfCEfromNode1 = - theNodesOfThisEdge[1]->getConnectedElementIDs()[k]; - if( indexOfCEfromNode0 == indexOfCEfromNode1 ) - m_msh->edge_vector[i]->connected_elements.push_back( - indexOfCEfromNode0); + int indexOfCEfromNode0 = theNodesOfThisEdge[0]->getConnectedElementIDs()[j]; + int indexOfCEfromNode1 = theNodesOfThisEdge[1]->getConnectedElementIDs()[k]; + if (indexOfCEfromNode0 == indexOfCEfromNode1) + m_msh->edge_vector[i]->connected_elements.push_back(indexOfCEfromNode0); } // Constructing the connected elements of an edge ends here @@ -786,66 +729,55 @@ void CFluidMomentum::ConstructFractureNetworkTopology() double Vmag = 0.0; CrossRoad* thisJoint; thisJoint = new CrossRoad(); - thisJoint->numOfThePlanes = - (int)m_msh->edge_vector[i]->connected_elements.size(); + thisJoint->numOfThePlanes = (int)m_msh->edge_vector[i]->connected_elements.size(); thisJoint->CreatePlaneSet(thisJoint->numOfThePlanes); // Loop over the number of connected planes - for(int j = 0; j < thisJoint->numOfThePlanes; ++j) + for (int j = 0; j < thisJoint->numOfThePlanes; ++j) { // Some local variables within this else double norm[3], VxNorm[3], Vp[3]; // Solve for the norm of this plane. int index = m_msh->edge_vector[i]->connected_elements[j]; - if(m_msh->GetCoordinateFlag() != 32 && - m_msh->GetCoordinateFlag() != 22) + if (m_msh->GetCoordinateFlag() != 32 && m_msh->GetCoordinateFlag() != 22) { norm[0] = 0.0; norm[1] = 0.0; norm[2] = 1.0; } else - for(int k = 0; k < 3; ++k) - thisJoint->plane[j].norm[k] = norm[k] = - m_msh-> - ele_vector[ - index - ]-> - getTransformTensor( - k + 6); + for (int k = 0; k < 3; ++k) + thisJoint->plane[j].norm[k] = norm[k] = m_msh->ele_vector[index]->getTransformTensor(k + 6); // Store the position vector defined below - double const* CenterOfEle( - m_msh->ele_vector[index]->GetGravityCenter()); + double const* CenterOfEle(m_msh->ele_vector[index]->GetGravityCenter()); // I am using the center position of the joint -// thisJoint->plane[j].Eele[0] = CenterOfEle[0] - (theNodesOfThisEdge[0]->X()+theNodesOfThisEdge[1]->X())/2.0; -// thisJoint->plane[j].Eele[1] = CenterOfEle[1] - (theNodesOfThisEdge[0]->Y()+theNodesOfThisEdge[1]->Y())/2.0; -// thisJoint->plane[j].Eele[2] = CenterOfEle[2] - (theNodesOfThisEdge[0]->Z()+theNodesOfThisEdge[1]->Z())/2.0; + // thisJoint->plane[j].Eele[0] = CenterOfEle[0] - + // (theNodesOfThisEdge[0]->X()+theNodesOfThisEdge[1]->X())/2.0; + // thisJoint->plane[j].Eele[1] = CenterOfEle[1] - + // (theNodesOfThisEdge[0]->Y()+theNodesOfThisEdge[1]->Y())/2.0; + // thisJoint->plane[j].Eele[2] = CenterOfEle[2] - + // (theNodesOfThisEdge[0]->Z()+theNodesOfThisEdge[1]->Z())/2.0; double const* const pnt0(theNodesOfThisEdge[0]->getData()); double const* const pnt1(theNodesOfThisEdge[1]->getData()); - thisJoint->plane[j].Eele[0] = CenterOfEle[0] - - (pnt0[0] + pnt1[0]) / 2.0; - thisJoint->plane[j].Eele[1] = CenterOfEle[1] - - (pnt0[1] + pnt1[1]) / 2.0; - thisJoint->plane[j].Eele[2] = CenterOfEle[2] - - (pnt0[2] + pnt1[2]) / 2.0; + thisJoint->plane[j].Eele[0] = CenterOfEle[0] - (pnt0[0] + pnt1[0]) / 2.0; + thisJoint->plane[j].Eele[1] = CenterOfEle[1] - (pnt0[1] + pnt1[1]) / 2.0; + thisJoint->plane[j].Eele[2] = CenterOfEle[2] - (pnt0[2] + pnt1[2]) / 2.0; // Solve the velocity contribution for this plane. - CrossProduction(V,norm,VxNorm); - CrossProduction(norm,VxNorm, Vp); - for(int k = 0; k < 3; ++k) + CrossProduction(V, norm, VxNorm); + CrossProduction(norm, VxNorm, Vp); + for (int k = 0; k < 3; ++k) thisJoint->plane[j].V[k] = Vp[k]; // For ratio and Vmag - thisJoint->plane[j].ratio = sqrt( - Vp[0] * Vp[0] + Vp[1] * Vp[1] + Vp[2] * Vp[2]); + thisJoint->plane[j].ratio = sqrt(Vp[0] * Vp[0] + Vp[1] * Vp[1] + Vp[2] * Vp[2]); Vmag += thisJoint->plane[j].ratio; // Update the eleIndex for this plane - thisJoint->plane[j].eleIndex = - m_msh->edge_vector[i]->connected_elements[j]; + thisJoint->plane[j].eleIndex = m_msh->edge_vector[i]->connected_elements[j]; } // Let's sort the contribution of each plane and the index of this node - for(int j = 0; j < thisJoint->numOfThePlanes; ++j) + for (int j = 0; j < thisJoint->numOfThePlanes; ++j) thisJoint->plane[j].ratio = thisJoint->plane[j].ratio / Vmag; thisJoint->Index = i; // velocity for each connected planes ends here. @@ -854,31 +786,31 @@ void CFluidMomentum::ConstructFractureNetworkTopology() // First, we will solve vectors from each potential joint to one of the center // of the connected elements. // Now some dot product. - for(int j = 0; j < thisJoint->numOfThePlanes; ++j) + for (int j = 0; j < thisJoint->numOfThePlanes; ++j) { double angle = 0.0; double a[3], b[3]; - for(int p = 0; p < 3; ++p) + for (int p = 0; p < 3; ++p) { a[p] = thisJoint->plane[j].Eele[p]; b[p] = thisJoint->plane[j].V[p]; } // Let's normalize these two vectors first. - NormalizeVector(a,3); - NormalizeVector(b,3); + NormalizeVector(a, 3); + NormalizeVector(b, 3); double dotProduct = a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; angle = acos(dotProduct); // If this angle is bigger than Pi/2 (90 degree), // then this crossroad is not a realone. - if(angle > PI / 2.0) + if (angle > PI / 2.0) m_msh->edge_vector[i]->SetJoint(0); } // Extraction ends here. // Now add this crossroad to the vector of all crossroads in the domain - if(m_msh->edge_vector[i]->GetJoint() == 1) + if (m_msh->edge_vector[i]->GetJoint() == 1) joints.push_back(thisJoint); } } @@ -886,7 +818,7 @@ void CFluidMomentum::ConstructFractureNetworkTopology() // Compute the angles of the element for rotation. // This process can be embedded into CElem class when in need. - for(int i = 0; i < (int)m_msh->ele_vector.size(); ++i) + for (int i = 0; i < (int)m_msh->ele_vector.size(); ++i) m_msh->PT->SolveAnglesOfTheElment(m_msh->ele_vector[i]); } @@ -899,54 +831,40 @@ void CFluidMomentum::SolveForEdgeVelocity(void) { // Mount the process and the mesh m_pcs = PCSGet("FLUID_MOMENTUM"); - CFEMesh* m_msh = fem_msh_vector[0]; // Something must be done later on here. + CFEMesh* m_msh = fem_msh_vector[0]; // Something must be done later on here. double tolerance = 1e-12; // Checking the edge is a joint starts here // Loop over all the edges // Mount the nodes of the edge - vectheNodesOfThisEdge(3); - for(int i = 0; i < (int) m_msh->edge_vector.size(); ++i) + vec theNodesOfThisEdge(3); + for (int i = 0; i < (int)m_msh->edge_vector.size(); ++i) { m_msh->edge_vector[i]->GetNodes(theNodesOfThisEdge); - double const* const coords1 (theNodesOfThisEdge[1]->getData()); - double const* const coords0 (theNodesOfThisEdge[0]->getData()); + double const* const coords1(theNodesOfThisEdge[1]->getData()); + double const* const coords0(theNodesOfThisEdge[0]->getData()); // Norma vector of the edge double VectorOfEdge[3] = {coords1[0] - coords0[0], coords1[1] - coords0[1], 0.0}; // Note MagOfVector is never zero - double MagOfVector = sqrt( - VectorOfEdge[0] * VectorOfEdge[0] + VectorOfEdge[1] * VectorOfEdge[1]); + double MagOfVector = sqrt(VectorOfEdge[0] * VectorOfEdge[0] + VectorOfEdge[1] * VectorOfEdge[1]); // Now VectorOfEdge is unit vector VectorOfEdge[0] = VectorOfEdge[0] / MagOfVector; VectorOfEdge[1] = VectorOfEdge[1] / MagOfVector; VectorOfEdge[2] = 0.0; // TF Why not simply set to one at this points, i.e. MagOfVector = 1.0? - MagOfVector = sqrt( - VectorOfEdge[0] * VectorOfEdge[0] + VectorOfEdge[1] * VectorOfEdge[1]); + MagOfVector = sqrt(VectorOfEdge[0] * VectorOfEdge[0] + VectorOfEdge[1] * VectorOfEdge[1]); // Geting velocity on two ending nodes of the edge double V[3], V0[3], V1[3], Ve0[3], Ve1[3]; - V0[0] = m_pcs->GetNodeValue( - theNodesOfThisEdge[0]->GetIndex(), m_pcs->GetNodeValueIndex( - "VELOCITY1_X") + 1); - V0[1] = m_pcs->GetNodeValue( - theNodesOfThisEdge[0]->GetIndex(), m_pcs->GetNodeValueIndex( - "VELOCITY1_Y") + 1); - V0[2] = m_pcs->GetNodeValue( - theNodesOfThisEdge[0]->GetIndex(), m_pcs->GetNodeValueIndex( - "VELOCITY1_Z") + 1); - V1[0] = m_pcs->GetNodeValue( - theNodesOfThisEdge[1]->GetIndex(), m_pcs->GetNodeValueIndex( - "VELOCITY1_X") + 1); - V1[1] = m_pcs->GetNodeValue( - theNodesOfThisEdge[1]->GetIndex(), m_pcs->GetNodeValueIndex( - "VELOCITY1_Y") + 1); - V1[2] = m_pcs->GetNodeValue( - theNodesOfThisEdge[1]->GetIndex(), m_pcs->GetNodeValueIndex( - "VELOCITY1_Z") + 1); + V0[0] = m_pcs->GetNodeValue(theNodesOfThisEdge[0]->GetIndex(), m_pcs->GetNodeValueIndex("VELOCITY1_X") + 1); + V0[1] = m_pcs->GetNodeValue(theNodesOfThisEdge[0]->GetIndex(), m_pcs->GetNodeValueIndex("VELOCITY1_Y") + 1); + V0[2] = m_pcs->GetNodeValue(theNodesOfThisEdge[0]->GetIndex(), m_pcs->GetNodeValueIndex("VELOCITY1_Z") + 1); + V1[0] = m_pcs->GetNodeValue(theNodesOfThisEdge[1]->GetIndex(), m_pcs->GetNodeValueIndex("VELOCITY1_X") + 1); + V1[1] = m_pcs->GetNodeValue(theNodesOfThisEdge[1]->GetIndex(), m_pcs->GetNodeValueIndex("VELOCITY1_Y") + 1); + V1[2] = m_pcs->GetNodeValue(theNodesOfThisEdge[1]->GetIndex(), m_pcs->GetNodeValueIndex("VELOCITY1_Z") + 1); double cos, sin, MagOfV0, MagOfV1; MagOfV0 = sqrt(V0[0] * V0[0] + V0[1] * V0[1]); @@ -956,11 +874,11 @@ void CFluidMomentum::SolveForEdgeVelocity(void) // such as (-y,x) or (y,-x) for (x,y) edge vector double UNVOfE[2]; // I will only use (-y,x) for rightys - UNVOfE[0] = -VectorOfEdge[1]; - UNVOfE[1] = VectorOfEdge[0]; + UNVOfE[0] = -VectorOfEdge[1]; + UNVOfE[1] = VectorOfEdge[0]; // Check if denominator is zero - if(MagOfV0 < tolerance) + if (MagOfV0 < tolerance) { Ve0[0] = 0.0; Ve0[1] = 0.0; @@ -969,9 +887,7 @@ void CFluidMomentum::SolveForEdgeVelocity(void) else { // For Ve0 first - cos = - (VectorOfEdge[0] * V0[0] + VectorOfEdge[1] * - V0[1]) / (MagOfVector * MagOfV0); + cos = (VectorOfEdge[0] * V0[0] + VectorOfEdge[1] * V0[1]) / (MagOfVector * MagOfV0); sin = sqrt(1.0 - cos * cos); double magOfNormalV = sin * MagOfV0; @@ -982,7 +898,7 @@ void CFluidMomentum::SolveForEdgeVelocity(void) Ve0[2] = 0.0; } // Now for the other node of the edge - if(MagOfV1 < tolerance) + if (MagOfV1 < tolerance) { Ve1[0] = 0.0; Ve1[1] = 0.0; @@ -991,9 +907,7 @@ void CFluidMomentum::SolveForEdgeVelocity(void) else { // For Ve1 second - cos = - (VectorOfEdge[0] * V1[0] + VectorOfEdge[1] * - V1[1]) / (MagOfVector * MagOfV1); + cos = (VectorOfEdge[0] * V1[0] + VectorOfEdge[1] * V1[1]) / (MagOfVector * MagOfV1); sin = sqrt(1.0 - cos * cos); double magOfNormalV = sin * MagOfV1; @@ -1014,12 +928,9 @@ void CFluidMomentum::SolveForEdgeVelocity(void) Vc[2] = 0.0; // Checking the angle between node averaged velocity and flux averaged velocity along the edge - double angle = - acos((V[0] * Vc[0] + V[1] * - Vc[1]) / - (sqrt(V[0] * V[0] + V[1] * V[1] + V[2] * - V[2]) * sqrt(Vc[0] * Vc[0] + Vc[1] * Vc[1] + Vc[2] * Vc[2]))); - if(angle > 3.141592 / 2.0) + double angle = acos((V[0] * Vc[0] + V[1] * Vc[1]) / (sqrt(V[0] * V[0] + V[1] * V[1] + V[2] * V[2]) + * sqrt(Vc[0] * Vc[0] + Vc[1] * Vc[1] + Vc[2] * Vc[2]))); + if (angle > 3.141592 / 2.0) { V[0] = -V[0]; V[1] = -V[1]; @@ -1036,11 +947,11 @@ void FMRead(string file_base_name) (void)file_base_name; // Fluid_Momentum memory allocation is moved here. by PCH CRFProcess* m_pcs = PCSGet("FLUID_MOMENTUM"); - //WW if(!m_pcs) - if(m_pcs) //WW + // WW if(!m_pcs) + if (m_pcs) // WW { CFEMesh* m_msh = fem_msh_vector[0]; // Something must be done later on here. - m_msh->fm_pcs = new CFluidMomentum (); + m_msh->fm_pcs = new CFluidMomentum(); } } @@ -1053,25 +964,25 @@ void FMRead(string file_base_name) /* //WW void DATWriteHETFile(const char* file_name) { - FILE* tet_file = NULL; - char tet_file_name[MAX_ZEILE]; - CFEMesh* m_msh = NULL; - m_msh = fem_msh_vector[0]; // Something must be done later on here. - MeshLib::CElem* elem = NULL; - - sprintf(tet_file_name,"%s.%s",file_name,"tet"); - tet_file = fopen(tet_file_name,"w+t"); - // Obtain element-based velocity - for (int i = 0; i < (long)m_msh->ele_vector.size(); i++) - { - elem = m_msh->ele_vector[i]; - double const* center(elem->GetGravityCenter()); + FILE* tet_file = NULL; + char tet_file_name[MAX_ZEILE]; + CFEMesh* m_msh = NULL; + m_msh = fem_msh_vector[0]; // Something must be done later on here. + MeshLib::CElem* elem = NULL; + + sprintf(tet_file_name,"%s.%s",file_name,"tet"); + tet_file = fopen(tet_file_name,"w+t"); + // Obtain element-based velocity + for (int i = 0; i < (long)m_msh->ele_vector.size(); i++) + { + elem = m_msh->ele_vector[i]; + double const* center(elem->GetGravityCenter()); - fprintf(tet_file, "%17.12e %17.12e %17.12e %17.12e\n", - center[0], center[1], center[2], elem->mat_vector(0) * 1e7); - } + fprintf(tet_file, "%17.12e %17.12e %17.12e %17.12e\n", + center[0], center[1], center[2], elem->mat_vector(0) * 1e7); + } - // Let's close it, now - fclose(tet_file); + // Let's close it, now + fclose(tet_file); } */ diff --git a/FEM/rf_fluid_momentum.h b/FEM/rf_fluid_momentum.h index 1b0dbd68c..861725673 100644 --- a/FEM/rf_fluid_momentum.h +++ b/FEM/rf_fluid_momentum.h @@ -22,7 +22,7 @@ //#include "rf_vel_new.h" #include "fem_ele.h" #include "fem_ele_std.h" -#ifndef NEW_EQS //WW. 06.11.2008 +#ifndef NEW_EQS // WW. 06.11.2008 #include "matrix_routines.h" #endif #include "mathlib.h" @@ -31,21 +31,21 @@ class PlaneSet { public: int eleIndex; - double ratio; // ratio: contribution of velocity to this plane. + double ratio; // ratio: contribution of velocity to this plane. double V[3]; double norm[3]; - double Eele[3]; // The vector from the crossroad to the center of the connected element + double Eele[3]; // The vector from the crossroad to the center of the connected element // that lies in one of the connected planes. // Constructor PlaneSet(void); - PlaneSet&operator=(const PlaneSet& B) + PlaneSet& operator=(const PlaneSet& B) { eleIndex = B.eleIndex; ratio = B.ratio; - for(int i = 0; i < 3; ++i) + for (int i = 0; i < 3; ++i) { V[i] = B.V[i]; norm[i] = B.norm[i]; @@ -58,9 +58,8 @@ class PlaneSet class CrossRoad { public: - int numOfThePlanes; - int Index; // This can be node or edge index + int Index; // This can be node or edge index // depending on crossroad or edge PlaneSet* plane; @@ -107,4 +106,4 @@ class CFluidMomentum : public CRFProcess }; extern void FMRead(std::string pcs_name = ""); -//WWextern void DATWriteHETFile(const char* file_name); +// WWextern void DATWriteHETFile(const char* file_name); diff --git a/FEM/rf_ic_new.cpp b/FEM/rf_ic_new.cpp index 58ddd3309..d68f360cd 100644 --- a/FEM/rf_ic_new.cpp +++ b/FEM/rf_ic_new.cpp @@ -42,8 +42,8 @@ using namespace std; #include "InitialCondition.h" //========================================================================== -vectoric_group_vector; -vectoric_vector; +vector ic_group_vector; +vector ic_vector; /************************************************************************** FEMLib-Method: @@ -60,18 +60,17 @@ CInitialCondition::CInitialCondition() : dis_linear_f(NULL) // m_node->node_value = 0.0; SubNumber = 0; storeValues = false; // JOD 2014-11-10 - this->setProcess(NULL); //OK + this->setProcess(NULL); // OK - m_msh = NULL; //OK + m_msh = NULL; // OK } // KR: Conversion from GUI-IC-object to CInitialCondition CInitialCondition::CInitialCondition(const InitialCondition* ic) - : ProcessInfo(ic->getProcessType(),ic->getProcessPrimaryVariable(),NULL), - GeoInfo(ic->getGeoType(),ic->getGeoObj()), - DistributionInfo(ic->getProcessDistributionType()) + : ProcessInfo(ic->getProcessType(), ic->getProcessPrimaryVariable(), NULL), + GeoInfo(ic->getGeoType(), ic->getGeoObj()), DistributionInfo(ic->getProcessDistributionType()) { - setProcess( PCSGet( this->getProcessType() ) ); + setProcess(PCSGet(this->getProcessType())); this->geo_name = ic->getGeoName(); const std::vector dis_nodes = ic->getDisNodes(); const std::vector dis_values = ic->getDisValues(); @@ -89,7 +88,8 @@ CInitialCondition::CInitialCondition(const InitialCondition* ic) else std::cout << "Error in CBoundaryCondition() - DistributionType \"" << FiniteElement::convertDisTypeToString(this->getProcessDistributionType()) - << "\" currently not supported." << "\n"; + << "\" currently not supported." + << "\n"; } /************************************************************************** @@ -100,16 +100,16 @@ CInitialCondition::CInitialCondition(const InitialCondition* ic) **************************************************************************/ CInitialCondition::~CInitialCondition(void) { -/* KR - if ( !node_value_vector.empty() ) - { - for (size_t i=0; i < node_value_vector.size(); i++) - delete node_value_vector[i]; - } - node_value_vector.clear(); - */ - //WW - if(dis_linear_f) + /* KR + if ( !node_value_vector.empty() ) + { + for (size_t i=0; i < node_value_vector.size(); i++) + delete node_value_vector[i]; + } + node_value_vector.clear(); + */ + // WW + if (dis_linear_f) delete dis_linear_f; dis_linear_f = NULL; } @@ -123,15 +123,15 @@ CInitialCondition::~CInitialCondition(void) 01/2005 OK Destruct before read 05/2010 TF reformated, restructured, signature changed, use new GEOLIB data structures **************************************************************************/ -bool ICRead(const std::string& file_base_name, - const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) +bool ICRead(const std::string& file_base_name, const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) { // File handling std::string ic_file_name = file_base_name + IC_FILE_EXTENSION; std::ifstream ic_file(ic_file_name.data(), std::ios::in); if (!ic_file.good()) { - std::cout << "WARNING: ICRead: No initial conditions !" << "\n"; + std::cout << "WARNING: ICRead: No initial conditions !" + << "\n"; return false; } @@ -140,7 +140,8 @@ bool ICRead(const std::string& file_base_name, std::ios::pos_type position; // Keyword loop - std::cout << "ICRead" << "\n"; + std::cout << "ICRead" + << "\n"; while (!ic_file.eof()) { ic_file.getline(line, MAX_ZEILE); @@ -152,20 +153,20 @@ bool ICRead(const std::string& file_base_name, if (line_string.find("#INITIAL_CONDITION") != std::string::npos) { CInitialCondition* ic = new CInitialCondition(); - std::ios::pos_type pos (ic_file.tellg()); + std::ios::pos_type pos(ic_file.tellg()); position = ic->Read(&ic_file, geo_obj, unique_name); if (pos != position) ic_vector.push_back(ic); else { - std::cerr << - "WARNING: in ICRead: could not read initial condition" << "\n"; + std::cerr << "WARNING: in ICRead: could not read initial condition" + << "\n"; delete ic; } ic = NULL; ic_file.seekg(position, ios::beg); - } // keyword found - } // eof + } // keyword found + } // eof return true; } @@ -185,19 +186,18 @@ void ICWrite(string base_file_name) //======================================================================== // File handling string ic_file_name = base_file_name + IC_FILE_EXTENSION; - fstream ic_file (ic_file_name.data(),ios::trunc | ios::out); - ic_file.setf(ios::scientific,ios::floatfield); + fstream ic_file(ic_file_name.data(), ios::trunc | ios::out); + ic_file.setf(ios::scientific, ios::floatfield); ic_file.precision(12); if (!ic_file.good()) return; - ic_file.seekg(0L,ios::beg); + ic_file.seekg(0L, ios::beg); //======================================================================== - ic_file << - "GeoSys-IC: Initial Conditions ------------------------------------------------\n"; + ic_file << "GeoSys-IC: Initial Conditions ------------------------------------------------\n"; //======================================================================== // IC list long no_ic = (long)ic_vector.size(); - for(i = 0; i < no_ic; i++) + for (i = 0; i < no_ic; i++) { m_ic = ic_vector[i]; m_ic->Write(&ic_file); @@ -228,8 +228,8 @@ ios::pos_type CInitialCondition::Read(std::ifstream* ic_file, ios::pos_type position; bool new_keyword = false; - int ibuf (0); - double d_buf (0.0); + int ibuf(0); + double d_buf(0.0); // read loop while (!new_keyword) @@ -249,7 +249,7 @@ ios::pos_type CInitialCondition::Read(std::ifstream* ic_file, { in.str(GetLineFromFile1(ic_file)); std::string tmp; - in >> tmp; // pcs_type_name; + in >> tmp; // pcs_type_name; this->setProcessType(FiniteElement::convertProcessType(tmp)); in.clear(); continue; @@ -260,27 +260,27 @@ ios::pos_type CInitialCondition::Read(std::ifstream* ic_file, { in.str(GetLineFromFile1(ic_file)); std::string tmp; - in >> tmp; // pcs_pv_name; - if ( this->getProcessType() == FiniteElement::MASS_TRANSPORT ) + in >> tmp; // pcs_pv_name; + if (this->getProcessType() == FiniteElement::MASS_TRANSPORT) { // HS set the pointer to MCP based on component name. // first do a check whether this name is existing and unique. - if ( cp_name_2_idx.count( tmp ) == 1 ) + if (cp_name_2_idx.count(tmp) == 1) { - setProcess(cp_vec[cp_name_2_idx[tmp]]->getProcess() ); - setProcessPrimaryVariable( FiniteElement::CONCENTRATION ); + setProcess(cp_vec[cp_name_2_idx[tmp]]->getProcess()); + setProcessPrimaryVariable(FiniteElement::CONCENTRATION); } else { DisplayErrorMsg( - "Error: In reading IC file, the input component names are not found in MCP file!!!"); + "Error: In reading IC file, the input component names are not found in MCP file!!!"); exit(1); } } else { - setProcess( PCSGet( this->getProcessType() ) ); - setProcessPrimaryVariable (FiniteElement::convertPrimaryVariable (tmp)); + setProcess(PCSGet(this->getProcessType())); + setProcessPrimaryVariable(FiniteElement::convertPrimaryVariable(tmp)); } in.clear(); continue; @@ -294,15 +294,14 @@ ios::pos_type CInitialCondition::Read(std::ifstream* ic_file, in >> tmp; // HS set the pointer to MCP based on component name. // first do a check whether this name is existing and unique. - if ( cp_name_2_idx.count( tmp ) == 1 ) + if (cp_name_2_idx.count(tmp) == 1) { - setProcess(cp_vec[cp_name_2_idx[tmp]]->getProcess() ); - setProcessPrimaryVariable( FiniteElement::CONCENTRATION ); + setProcess(cp_vec[cp_name_2_idx[tmp]]->getProcess()); + setProcessPrimaryVariable(FiniteElement::CONCENTRATION); } else { - DisplayErrorMsg( - "Error: In reading BC file, the input component names are not found in MCP file!!!"); + DisplayErrorMsg("Error: In reading BC file, the input component names are not found in MCP file!!!"); exit(1); } in.clear(); @@ -317,23 +316,23 @@ ios::pos_type CInitialCondition::Read(std::ifstream* ic_file, continue; } //.................................................................... - //subkeyword found + // subkeyword found if (line_string.find("$DIS_TYPE") != string::npos) { in.str(GetLineFromFile1(ic_file)); std::string tmp; - in >> tmp; // dis_type_name; + in >> tmp; // dis_type_name; this->setProcessDistributionType(FiniteElement::convertDisType(tmp)); if (this->getProcessDistributionType() == FiniteElement::CONSTANT) - //KR CNodeValue* m_node = new CNodeValue(); - //KR node_value_vector.push_back(m_node); + // KR CNodeValue* m_node = new CNodeValue(); + // KR node_value_vector.push_back(m_node); in >> geo_node_value; else if (this->getProcessDistributionType() == FiniteElement::GRADIENT) { - in >> gradient_ref_depth; //CMCD - in >> gradient_ref_depth_value; //CMCD - in >> gradient_ref_depth_gradient; //CMCD + in >> gradient_ref_depth; // CMCD + in >> gradient_ref_depth_value; // CMCD + in >> gradient_ref_depth_gradient; // CMCD } else if (this->getProcessDistributionType() == FiniteElement::RESTART) in >> rfr_file_name; @@ -346,7 +345,7 @@ ios::pos_type CInitialCondition::Read(std::ifstream* ic_file, continue; } //.................................................................... - //subkeyword found + // subkeyword found if (line_string.find("$GEO_TYPE") != string::npos) { in.str(GetLineFromFile1(ic_file)); @@ -355,18 +354,15 @@ ios::pos_type CInitialCondition::Read(std::ifstream* ic_file, if (geo_type_name.find("POINT") != string::npos) { in >> geo_name; - const GEOLIB::Point* pnt ((geo_obj.getPointVecObj( - unique_geo_name))-> - getElementByName (geo_name)); + const GEOLIB::Point* pnt((geo_obj.getPointVecObj(unique_geo_name))->getElementByName(geo_name)); if (pnt == NULL) { - std::cerr << - "error in CInitialCondition::Read: point name \"" << - geo_name << "\" not found!" << "\n"; - exit (1); + std::cerr << "error in CInitialCondition::Read: point name \"" << geo_name << "\" not found!" + << "\n"; + exit(1); } - setGeoType (GEOLIB::POINT); - setGeoObj (pnt); + setGeoType(GEOLIB::POINT); + setGeoObj(pnt); in.clear(); geo_name = ""; // REMOVE CANDIDATE @@ -374,53 +370,43 @@ ios::pos_type CInitialCondition::Read(std::ifstream* ic_file, if (geo_type_name.find("POLYLINE") != string::npos) { in >> geo_name; - const GEOLIB::Polyline* ply ((geo_obj.getPolylineVecObj( - unique_geo_name))-> - getElementByName (geo_name)); + const GEOLIB::Polyline* ply((geo_obj.getPolylineVecObj(unique_geo_name))->getElementByName(geo_name)); if (ply == NULL) { - std::cerr << - "error in CInitialCondition::Read: polyline name \"" << - geo_name << "\" not found!" << "\n"; - exit (1); + std::cerr << "error in CInitialCondition::Read: polyline name \"" << geo_name << "\" not found!" + << "\n"; + exit(1); } - setGeoType (GEOLIB::POLYLINE); - setGeoObj (ply); + setGeoType(GEOLIB::POLYLINE); + setGeoObj(ply); } if (geo_type_name.find("SURFACE") != string::npos) { - setGeoType (GEOLIB::SURFACE); + setGeoType(GEOLIB::SURFACE); in >> geo_name; - GEOLIB::Surface const* sfc( - geo_obj.getSurfaceVecObj(unique_geo_name)->getElementByName(geo_name) - ); + GEOLIB::Surface const* sfc(geo_obj.getSurfaceVecObj(unique_geo_name)->getElementByName(geo_name)); setGeoObj(sfc); - if (sfc == NULL) { - std::cerr - << "ERROR: CInitialCondition::Read: surface \"" << - geo_name << "\" not found!" - << "\n"; + if (sfc == NULL) + { + std::cerr << "ERROR: CInitialCondition::Read: surface \"" << geo_name << "\" not found!" + << "\n"; exit(1); } } if (geo_type_name.find("VOLUME") != string::npos) - setGeoType (GEOLIB::VOLUME); + setGeoType(GEOLIB::VOLUME); if (geo_type_name.find("DOMAIN") != string::npos) { - setGeoType (GEOLIB::GEODOMAIN); + setGeoType(GEOLIB::GEODOMAIN); // Give initial condition by patches of domain. WW if (geo_type_name.find("SUB") != string::npos) { *ic_file >> SubNumber; - if (convertPrimaryVariableToString(this-> - getProcessPrimaryVariable()) - .find("STRESS") != string::npos - || getProcessDistributionType() == - FiniteElement::FUNCTION) //01.07.2008 WW + if (convertPrimaryVariableToString(this->getProcessPrimaryVariable()).find("STRESS") != string::npos + || getProcessDistributionType() == FiniteElement::FUNCTION) // 01.07.2008 WW { // 24.08.2011. WW - dis_linear_f = new LinearFunctionData(*ic_file, - SubNumber); + dis_linear_f = new LinearFunctionData(*ic_file, SubNumber); size_t* sd_idx = dis_linear_f->getSubDomIndex(); for (size_t i = 0; i < SubNumber; i++) subdom_index.push_back(sd_idx[i]); @@ -437,7 +423,7 @@ ios::pos_type CInitialCondition::Read(std::ifstream* ic_file, in.clear(); continue; } - } // Schleife ueber alle Phasen bzw. Komponenten + } // Schleife ueber alle Phasen bzw. Komponenten return position; } @@ -453,24 +439,29 @@ ios::pos_type CInitialCondition::Read(std::ifstream* ic_file, **************************************************************************/ void CInitialCondition::Write(fstream* ic_file) const { - //KEYWORD - *ic_file << "#INITIAL_CONDITION" << "\n"; + // KEYWORD + *ic_file << "#INITIAL_CONDITION" + << "\n"; //-------------------------------------------------------------------- - //NAME+NUMBER - *ic_file << " $PCS_TYPE" << "\n"; + // NAME+NUMBER + *ic_file << " $PCS_TYPE" + << "\n"; *ic_file << " "; *ic_file << convertProcessTypeToString(this->getProcessType()) << "\n"; - *ic_file << " $PRIMARY_VARIABLE" << "\n"; + *ic_file << " $PRIMARY_VARIABLE" + << "\n"; *ic_file << " "; *ic_file << convertPrimaryVariableToString(this->getProcessPrimaryVariable()) << "\n"; //-------------------------------------------------------------------- - //GEO_TYPE - *ic_file << " $GEO_TYPE" << "\n"; + // GEO_TYPE + *ic_file << " $GEO_TYPE" + << "\n"; *ic_file << " " << getGeoTypeAsString() << this->geo_name << "\n"; //-------------------------------------------------------------------- - //DIS_TYPE - *ic_file << " $DIS_TYPE" << "\n"; + // DIS_TYPE + *ic_file << " $DIS_TYPE" + << "\n"; *ic_file << " "; *ic_file << convertDisTypeToString(this->getProcessDistributionType()) << " "; *ic_file << " "; @@ -503,34 +494,37 @@ void CInitialCondition::Write(fstream* ic_file) const **************************************************************************/ void CInitialCondition::Set(int nidx) { - if (getProcessDistributionType() == FiniteElement::DIRECT) //NW recover + if (getProcessDistributionType() == FiniteElement::DIRECT) // NW recover SetByNodeIndex(nidx); else { - switch(getGeoType()) + switch (getGeoType()) { - case GEOLIB::POINT: - SetPoint(nidx); - std::cout << "WARNING: CInitialCondition::Set - ToDo" << "\n"; - break; - case GEOLIB::POLYLINE: - SetPolyline(nidx); - break; - case GEOLIB::SURFACE: - SetSurface(nidx); - break; - case GEOLIB::VOLUME: - std::cout << "WARNING: CInitialCondition::Set - ToDo" << "\n"; - break; - case GEOLIB::GEODOMAIN: - SetDomain(nidx); - if (storeValues) - StoreInitialValues();// JOD 2014-11-10 - break; - case GEOLIB::INVALID: - std::cout << "WARNING: CInitialCondition::Set - invalid geo type" << "\n"; - break; + case GEOLIB::POINT: + SetPoint(nidx); + std::cout << "WARNING: CInitialCondition::Set - ToDo" + << "\n"; + break; + case GEOLIB::POLYLINE: + SetPolyline(nidx); + break; + case GEOLIB::SURFACE: + SetSurface(nidx); + break; + case GEOLIB::VOLUME: + std::cout << "WARNING: CInitialCondition::Set - ToDo" + << "\n"; + break; + case GEOLIB::GEODOMAIN: + SetDomain(nidx); + if (storeValues) + StoreInitialValues(); // JOD 2014-11-10 + break; + case GEOLIB::INVALID: + std::cout << "WARNING: CInitialCondition::Set - invalid geo type" + << "\n"; + break; } } } @@ -550,25 +544,24 @@ void CInitialCondition::SetByNodeIndex(int nidx) double node_val; // File handling - ifstream d_file (fname.c_str(),ios::in); + ifstream d_file(fname.c_str(), ios::in); if (!d_file.is_open()) { - cout << "! Error in direct node source terms: Could not find file " << fname << - "\n"; + cout << "! Error in direct node source terms: Could not find file " << fname << "\n"; abort(); } while (!d_file.eof()) { line_string = GetLineFromFile1(&d_file); - if(line_string.find("#STOP") != string::npos) + if (line_string.find("#STOP") != string::npos) break; in.str(line_string); in >> node_index >> node_val; in.clear(); - this->getProcess()->SetNodeValue(node_index,nidx,node_val); + this->getProcess()->SetNodeValue(node_index, nidx, node_val); } } @@ -582,18 +575,14 @@ void CInitialCondition::SetByNodeIndex(int nidx) void CInitialCondition::SetPoint(int nidx) { if (m_msh && this->getProcessDistributionType() == FiniteElement::CONSTANT) - this->getProcess()->SetNodeValue(this->getProcess()->m_msh->GetNODOnPNT(static_cast - ( - getGeoObj( - ))), - nidx, - geo_node_value); + this->getProcess()->SetNodeValue( + this->getProcess()->m_msh->GetNODOnPNT(static_cast(getGeoObj())), + nidx, + geo_node_value); else std::cerr << "Error in CInitialCondition::SetPoint - point: " - << *(static_cast(getGeoObj())) - << " not found" << "\n"; + << *(static_cast(getGeoObj())) << " not found" + << "\n"; } /************************************************************************** @@ -606,25 +595,30 @@ void CInitialCondition::SetEle(int nidx) { switch (getGeoType()) { - case GEOLIB::POINT: - std::cout << "Warning CInitialCondition::Set - ToDo" << "\n"; - break; - case GEOLIB::POLYLINE: - // SetPolyline(nidx); - std::cout << "Warning CInitialCondition::Set - ToDo" << "\n"; - break; - case GEOLIB::SURFACE: - std::cout << "Warning CInitialCondition::Set - ToDo" << "\n"; - break; - case GEOLIB::VOLUME: - std::cout << "Warning CInitialCondition::Set - ToDo" << "\n"; - break; - case GEOLIB::GEODOMAIN: - SetDomainEle(nidx); - break; - case GEOLIB::INVALID: - std::cout << "WARNING: CInitialCondition::SetEle - invalid geo type" << "\n"; - break; + case GEOLIB::POINT: + std::cout << "Warning CInitialCondition::Set - ToDo" + << "\n"; + break; + case GEOLIB::POLYLINE: + // SetPolyline(nidx); + std::cout << "Warning CInitialCondition::Set - ToDo" + << "\n"; + break; + case GEOLIB::SURFACE: + std::cout << "Warning CInitialCondition::Set - ToDo" + << "\n"; + break; + case GEOLIB::VOLUME: + std::cout << "Warning CInitialCondition::Set - ToDo" + << "\n"; + break; + case GEOLIB::GEODOMAIN: + SetDomainEle(nidx); + break; + case GEOLIB::INVALID: + std::cout << "WARNING: CInitialCondition::SetEle - invalid geo type" + << "\n"; + break; } } @@ -637,43 +631,42 @@ void CInitialCondition::SetEle(int nidx) **************************************************************************/ void CInitialCondition::SetPolyline(int nidx) { - if (this->getProcessDistributionType() == FiniteElement::CONSTANT) + if (this->getProcessDistributionType() == FiniteElement::CONSTANT) { CGLPolyline* m_polyline = GEOGetPLYByName(geo_name); - if (!m_polyline) { - std::cout << "Error in CInitialCondition::SetPolyline - CGLPolyline: " - << geo_name << " not found" << "\n"; + if (!m_polyline) + { + std::cout << "Error in CInitialCondition::SetPolyline - CGLPolyline: " << geo_name << " not found" + << "\n"; } - if (!getGeoObj()) { - std::cout << "Error in CInitialCondition::SetPolyline - Polyline: " - << geo_name << " not found" << "\n"; + if (!getGeoObj()) + { + std::cout << "Error in CInitialCondition::SetPolyline - Polyline: " << geo_name << " not found" + << "\n"; return; } - bool automatic(! m_polyline->isSetEps()); + bool automatic(!m_polyline->isSetEps()); std::vector nodes_vector; - m_msh->GetNODOnPLY( - static_cast(getGeoObj()), - nodes_vector, automatic, m_polyline->epsilon - ); + m_msh->GetNODOnPLY(static_cast(getGeoObj()), nodes_vector, automatic, + m_polyline->epsilon); for (size_t i = 0; i < nodes_vector.size(); i++) - this->getProcess()->SetNodeValue(nodes_vector[i], - nidx, - geo_node_value); + this->getProcess()->SetNodeValue(nodes_vector[i], nidx, geo_node_value); #ifndef NDEBUG #ifdef DEBUGMESHNODESEARCH - { - std::string const debug_fname(geo_name+"-FoundNodes.gli"); - std::ofstream debug_out(debug_fname.c_str()); - debug_out << "#POINTS\n"; - for (size_t k(0); kgetNodeVector())[nodes_vector[k]]->getData()) << - " $NAME " << nodes_vector[k] << "\n"; + { + std::string const debug_fname(geo_name + "-FoundNodes.gli"); + std::ofstream debug_out(debug_fname.c_str()); + debug_out << "#POINTS\n"; + for (size_t k(0); k < nodes_vector.size(); k++) + { + debug_out << k << " " << GEOLIB::Point((m_msh->getNodeVector())[nodes_vector[k]]->getData()) + << " $NAME " << nodes_vector[k] << "\n"; + } + debug_out << "#STOP" + << "\n"; + debug_out.close(); } - debug_out << "#STOP" << "\n"; - debug_out.close(); - } #endif #endif } @@ -691,51 +684,51 @@ void CInitialCondition::SetPolyline(int nidx) void CInitialCondition::SetSurface(int nidx) { double value, node_depth; - vectorsfc_nod_vector; + vector sfc_nod_vector; Surface* m_sfc = GEOGetSFCByName(geo_name); - if(m_sfc && m_msh) + if (m_sfc && m_msh) { - // m_msh->GetNODOnSFC(m_sfc, sfc_nod_vector); // TF: use the following - // lines to get mesh nodes on surfaces - GEOLIB::Surface const* sfc( - static_cast (getGeoObj())); - if (sfc == NULL) { + // m_msh->GetNODOnSFC(m_sfc, sfc_nod_vector); // TF: use the following + // lines to get mesh nodes on surfaces + GEOLIB::Surface const* sfc(static_cast(getGeoObj())); + if (sfc == NULL) + { std::cerr << "CInitialCondition::SetSurface(): Did not find surface.\n"; return; } std::vector msh_nod_vec; m_msh->GetNODOnSFC(sfc, msh_nod_vec); // copy node ids - for (size_t k(0); k < msh_nod_vec.size(); k++) { - sfc_nod_vector.push_back (msh_nod_vec[k]); + for (size_t k(0); k < msh_nod_vec.size(); k++) + { + sfc_nod_vector.push_back(msh_nod_vec[k]); } #ifndef NDEBUG #ifdef DEBUGMESHNODESEARCH { - std::string const debug_fname("IC-Surface-"+geo_name+"-FoundNodes.gli"); + std::string const debug_fname("IC-Surface-" + geo_name + "-FoundNodes.gli"); std::ofstream debug_out(debug_fname.c_str()); debug_out << "#POINTS\n"; - for (size_t k(0); kgetNodeVector())[msh_nod_vec[k]]->getData()) << - " $NAME " << msh_nod_vec[k] << "\n"; + for (size_t k(0); k < msh_nod_vec.size(); k++) + { + debug_out << k << " " << GEOLIB::Point((m_msh->getNodeVector())[msh_nod_vec[k]]->getData()) << " $NAME " + << msh_nod_vec[k] << "\n"; } - debug_out << "#STOP" << "\n"; + debug_out << "#STOP" + << "\n"; debug_out.close(); } #endif #endif - if(this->getProcessDistributionType() == FiniteElement::CONSTANT) - for(size_t i = 0; i < sfc_nod_vector.size(); i++) - this->getProcess()->SetNodeValue(sfc_nod_vector[i], - nidx, - geo_node_value); + if (this->getProcessDistributionType() == FiniteElement::CONSTANT) + for (size_t i = 0; i < sfc_nod_vector.size(); i++) + this->getProcess()->SetNodeValue(sfc_nod_vector[i], nidx, geo_node_value); // end surface nodes // end constant - else if(this->getProcessDistributionType() == FiniteElement::GRADIENT) + else if (this->getProcessDistributionType() == FiniteElement::GRADIENT) { int onZ = m_msh->GetCoordinateFlag() % 10; long msh_node; @@ -743,33 +736,29 @@ void CInitialCondition::SetSurface(int nidx) for (size_t i = 0; i < sfc_nod_vector.size(); i++) { msh_node = sfc_nod_vector[i]; - if(onZ == 1) //2D + if (onZ == 1) // 2D node_depth = m_msh->nod_vector[msh_node]->getData()[1]; - else if(onZ == 2) //3D + else if (onZ == 2) // 3D node_depth = m_msh->nod_vector[msh_node]->getData()[2]; else { - cout << - "Error in CInitialCondition::SetSurface - dis_type: " << - convertDisTypeToString(this->getProcessDistributionType()) - << "don't know If 2D or 3D" << "\n"; + cout << "Error in CInitialCondition::SetSurface - dis_type: " + << convertDisTypeToString(this->getProcessDistributionType()) << "don't know If 2D or 3D" + << "\n"; node_depth = 0; } - value = - ((gradient_ref_depth_gradient) * - (gradient_ref_depth - - node_depth)) + gradient_ref_depth_value; - this->getProcess()->SetNodeValue(msh_node,nidx, value); - } // end surface nodes - } // end gradient + value = ((gradient_ref_depth_gradient) * (gradient_ref_depth - node_depth)) + gradient_ref_depth_value; + this->getProcess()->SetNodeValue(msh_node, nidx, value); + } // end surface nodes + } // end gradient else - cout << "Error in CInitialCondition::SetSurface - dis_type: " << - convertDisTypeToString(this->getProcessDistributionType()) << - " not found" << "\n"; - } // end m_sfc + cout << "Error in CInitialCondition::SetSurface - dis_type: " + << convertDisTypeToString(this->getProcessDistributionType()) << " not found" + << "\n"; + } // end m_sfc else - cout << "Error in CInitialCondition::SetSurface - surface: " << geo_name << - " not found" << "\n"; + cout << "Error in CInitialCondition::SetSurface - surface: " << geo_name << " not found" + << "\n"; } /************************************************************************** @@ -783,7 +772,7 @@ CInitialConditionGroup* GetInitialConditionGroup(string this_pcs_name) { CInitialConditionGroup* m_ic_group = NULL; size_t no_ic_groups = ic_group_vector.size(); - for(size_t i = 0; i < no_ic_groups; i++) + for (size_t i = 0; i < no_ic_groups; i++) { m_ic_group = ic_group_vector[i]; if (m_ic_group->pcs_type_name.find(this_pcs_name) != string::npos) @@ -812,7 +801,7 @@ void CInitialCondition::SetDomain(int nidx) vector nodes_vector; CFEMesh* m_msh = this->getProcess()->m_msh; onZ = 0; - if (m_msh) //OK + if (m_msh) // OK onZ = m_msh->GetCoordinateFlag() % 10; node_depth = 0.0; k = 0; @@ -822,20 +811,17 @@ void CInitialCondition::SetDomain(int nidx) { // if (this->getProcess()->pcs_type_name.compare("OVERLAND_FLOW") == 0) if (this->getProcess()->getProcessType() == FiniteElement::OVERLAND_FLOW) - //OK MSH - for (i = 0; i < this->getProcess()->m_msh->GetNodesNumber(false); - i++) + // OK MSH + for (i = 0; i < this->getProcess()->m_msh->GetNodesNumber(false); i++) { - node_val = geo_node_value + - this->getProcess()->m_msh->nod_vector[i]-> - getData()[2]; + node_val = geo_node_value + this->getProcess()->m_msh->nod_vector[i]->getData()[2]; this->getProcess()->SetNodeValue(i, nidx, node_val); } else { //................................................................ node_val = geo_node_value; - //OK MSH + // OK MSH for (i = 0; i < m_msh->GetNodesNumber(true); i++) this->getProcess()->SetNodeValue(i, nidx, node_val); //................................................................ @@ -844,20 +830,17 @@ void CInitialCondition::SetDomain(int nidx) //-------------------------------------------------------------------- // Remove unused stuff by WW if (this->getProcessDistributionType() == FiniteElement::GRADIENT) - //WW + // WW for (i = 0; i < m_msh->GetNodesNumber(true); i++) { - if (onZ == 1) //2D + if (onZ == 1) // 2D node_depth = m_msh->nod_vector[i]->getData()[1]; - if (onZ == 2) //3D + if (onZ == 2) // 3D node_depth = m_msh->nod_vector[i]->getData()[2]; - node_val = gradient_ref_depth_gradient * (gradient_ref_depth - - node_depth) + - gradient_ref_depth_value; - this->getProcess()->SetNodeValue( - m_msh->nod_vector[i]->GetIndex(), nidx, node_val); + node_val = gradient_ref_depth_gradient * (gradient_ref_depth - node_depth) + gradient_ref_depth_value; + this->getProcess()->SetNodeValue(m_msh->nod_vector[i]->GetIndex(), nidx, node_val); } - //if(dis_type_name.find("GRADIENT")!=string::npos) + // if(dis_type_name.find("GRADIENT")!=string::npos) //---------------------------------------------------------------------- if (this->getProcessDistributionType() == FiniteElement::RESTART) { @@ -909,8 +892,8 @@ void CInitialCondition::SetDomain(int nidx) } rfr_file.seekg(0L, ios::beg); // rewind? rfr_file.getline(line, MAX_ZEILEN); //#0#0#0#1#100000#0#4.2.13 ########################################### - rfr_file.getline(line, MAX_ZEILEN); //1 1 4 - rfr_file >> no_var; //2 1 1 + rfr_file.getline(line, MAX_ZEILEN); // 1 1 4 + rfr_file >> no_var; // 2 1 1 var_n = new int[no_var]; for (i = 0; i < (size_t)no_var; i++) rfr_file >> var_n[i]; @@ -922,11 +905,11 @@ void CInitialCondition::SetDomain(int nidx) var_name_string.erase(pos, 1); var_name.push_back(var_name_string); } - while (!rfr_file.eof()) //TODO Implementation/Manual Correction of Keyword #STOP: TK + while (!rfr_file.eof()) // TODO Implementation/Manual Correction of Keyword #STOP: TK { rfr_file >> dddummy; - ldummy = (long) dddummy; - //WW cout << ldummy << "\n"; + ldummy = (long)dddummy; + // WW cout << ldummy << "\n"; for (i = 0; i < (size_t)no_var; i++) // HEAD, m ... { rfr_file >> ddummy; @@ -940,15 +923,14 @@ void CInitialCondition::SetDomain(int nidx) //---------------------------------------------------------------------- } //======================================================================== - else //WW + else // WW { bool quadratic = false; /// In case of P_U coupling monolithic scheme - if (this->getProcess()->type == 41) //WW Mono + if (this->getProcess()->type == 41) // WW Mono { - if (convertPrimaryVariableToString( - this->getProcessPrimaryVariable()).find("DISPLACEMENT") - != string::npos) //Deform + if (convertPrimaryVariableToString(this->getProcessPrimaryVariable()).find("DISPLACEMENT") + != string::npos) // Deform quadratic = true; else quadratic = false; @@ -957,58 +939,42 @@ void CInitialCondition::SetDomain(int nidx) quadratic = true; else quadratic = false; - //WW if (m_msh){ - for (k = 0; (size_t) k < SubNumber; k++) + // WW if (m_msh){ + for (k = 0; (size_t)k < SubNumber; k++) { - GEOGetNodesInMaterialDomain(m_msh, subdom_index[k], nodes_vector, - quadratic); + GEOGetNodesInMaterialDomain(m_msh, subdom_index[k], nodes_vector, quadratic); if (this->getProcessDistributionType() == FiniteElement::GRADIENT) { - if (k == 0) //TEST for DECOVALEX + if (k == 0) // TEST for DECOVALEX for (i = 0; i < nodes_vector.size(); i++) - this->getProcess()->SetNodeValue(nodes_vector[i], - nidx, - subdom_ic[k]); + this->getProcess()->SetNodeValue(nodes_vector[i], nidx, subdom_ic[k]); else for (i = 0; i < nodes_vector.size(); i++) { - if (onZ == 1) //2D - node_depth = - m_msh->nod_vector[nodes_vector[i]] - ->getData() - [1]; - if (onZ == 2) //2D - node_depth = - m_msh->nod_vector[nodes_vector[i]] - ->getData() - [2]; - node_val = ((gradient_ref_depth_gradient) - * (gradient_ref_depth - node_depth)) + if (onZ == 1) // 2D + node_depth = m_msh->nod_vector[nodes_vector[i]]->getData()[1]; + if (onZ == 2) // 2D + node_depth = m_msh->nod_vector[nodes_vector[i]]->getData()[2]; + node_val = ((gradient_ref_depth_gradient) * (gradient_ref_depth - node_depth)) + gradient_ref_depth_value; - this->getProcess()->SetNodeValue(nodes_vector[i], - nidx, - node_val); + this->getProcess()->SetNodeValue(nodes_vector[i], nidx, node_val); } } - else if(getProcessDistributionType() == FiniteElement::FUNCTION) //01.07.2008 WW + else if (getProcessDistributionType() == FiniteElement::FUNCTION) // 01.07.2008 WW - for(i = 0; i < nodes_vector.size(); i++) + for (i = 0; i < nodes_vector.size(); i++) { -// MeshLib::CNode *thisNode = m_msh->nod_vector[nodes_vector[i]]; -// getProcess()->SetNodeValue(nodes_vector[i],nidx,dis_linear_f->getValue(k, thisNode->X(),thisNode->Y(), thisNode->Z())); - double const* const pnt( - m_msh->nod_vector[nodes_vector[i]]->getData()); - getProcess()->SetNodeValue(nodes_vector[i], - nidx, - dis_linear_f->getValue(k, pnt[0], - pnt[1], - pnt[2])); + // MeshLib::CNode *thisNode = m_msh->nod_vector[nodes_vector[i]]; + // getProcess()->SetNodeValue(nodes_vector[i],nidx,dis_linear_f->getValue(k, + // thisNode->X(),thisNode->Y(), thisNode->Z())); + double const* const pnt(m_msh->nod_vector[nodes_vector[i]]->getData()); + getProcess()->SetNodeValue(nodes_vector[i], nidx, + dis_linear_f->getValue(k, pnt[0], pnt[1], pnt[2])); } else for (i = 0; i < nodes_vector.size(); i++) - this->getProcess()->SetNodeValue(nodes_vector[i], nidx, - subdom_ic[k]); + this->getProcess()->SetNodeValue(nodes_vector[i], nidx, subdom_ic[k]); } // } /* // Comment by WW @@ -1058,12 +1024,12 @@ void CInitialCondition::SetDomain(int nidx) void ICDelete() { size_t no_ic = ic_vector.size(); - for(size_t i = 0; i < no_ic; i++) + for (size_t i = 0; i < no_ic; i++) delete ic_vector[i]; ic_vector.clear(); no_ic = ic_group_vector.size(); - for(size_t i = 0; i < no_ic; i++) + for (size_t i = 0; i < no_ic; i++) delete ic_group_vector[i]; ic_group_vector.clear(); } @@ -1093,36 +1059,36 @@ void CInitialCondition::SetDomainEle(int nidx) { int k; long i; - //WW double ele_val=0.0; - std::vectorele_vector; + // WW double ele_val=0.0; + std::vector ele_vector; CFEMesh* m_msh = this->getProcess()->m_msh; k = 0; MeshLib::CElem* m_ele = NULL; - if(SubNumber == 0) //only for constant values + if (SubNumber == 0) // only for constant values - //KR ele_val = node_value_vector[0]->node_value; - for(i = 0; i < (long)m_msh->ele_vector.size(); i++) + // KR ele_val = node_value_vector[0]->node_value; + for (i = 0; i < (long)m_msh->ele_vector.size(); i++) { m_ele = m_msh->ele_vector[i]; - if(m_ele->GetMark()) // Marked for use + if (m_ele->GetMark()) // Marked for use - this->getProcess()->SetElementValue(i,nidx, geo_node_value); + this->getProcess()->SetElementValue(i, nidx, geo_node_value); } //======================================================================== - else //MX - if (m_msh) + else // MX + if (m_msh) { - for(k = 0; (size_t)k < SubNumber; k++) - for(i = 0; i < (long)m_msh->ele_vector.size(); i++) + for (k = 0; (size_t)k < SubNumber; k++) + for (i = 0; i < (long)m_msh->ele_vector.size(); i++) { m_ele = m_msh->ele_vector[i]; // Marked for use - if(m_ele->GetMark() && m_ele->GetPatchIndex() == static_cast(subdom_index[k])) + if (m_ele->GetMark() && m_ele->GetPatchIndex() == static_cast(subdom_index[k])) this->getProcess()->SetElementValue(i, nidx, subdom_ic[k]); - //WW ele_val = this->getProcess()->GetElementValue(i, nidx); + // WW ele_val = this->getProcess()->GetElementValue(i, nidx); } - } //if + } // if } /************************************************************************** @@ -1132,10 +1098,10 @@ void CInitialCondition::SetDomainEle(int nidx) CInitialCondition* ICGet(string ic_name) { CInitialCondition* m_ic = NULL; - for(int i = 0; i < (int)ic_vector.size(); i++) + for (int i = 0; i < (int)ic_vector.size(); i++) { m_ic = ic_vector[i]; - if(m_ic->getProcessType() == FiniteElement::convertProcessType(ic_name)) + if (m_ic->getProcessType() == FiniteElement::convertProcessType(ic_name)) return m_ic; } return NULL; @@ -1149,17 +1115,13 @@ Used for LIQUID_FLOW with varying fluid density 11/2014 JOD Implementation **************************************************************************/ -void CInitialCondition::StoreInitialValues() { - - string variable_name = "DELTA_" + convertPrimaryVariableToString(this-> - getProcessPrimaryVariable()); +void CInitialCondition::StoreInitialValues() +{ + string variable_name = "DELTA_" + convertPrimaryVariableToString(this->getProcessPrimaryVariable()); for (int i = 0; i < (long)m_msh->nod_vector.size(); i++) { - this->getProcess()->SetNodeValue(i, this->getProcess()->GetNodeValueIndex(variable_name), - this->getProcess()->GetNodeValue(i, 0)); - + this->getProcess()->GetNodeValue(i, 0)); } - } diff --git a/FEM/rf_ic_new.h b/FEM/rf_ic_new.h index 3d1cccebc..825ef904b 100644 --- a/FEM/rf_ic_new.h +++ b/FEM/rf_ic_new.h @@ -25,10 +25,10 @@ #include // FEM -#include "DistributionInfo.h" // TF -#include "GeoInfo.h" // TF +#include "DistributionInfo.h" // TF +#include "GeoInfo.h" // TF #include "LinearFunctionData.h" // TF -#include "ProcessInfo.h" // KR +#include "ProcessInfo.h" // KR //#include "rf_pcs.h" @@ -50,37 +50,36 @@ class InitialCondition; class CInitialCondition : public ProcessInfo, public GeoInfo, public DistributionInfo { private: - size_t SubNumber; //WW - std::vector subdom_index; //WW - std::vector subdom_ic; //WW - std::string fname; //17.11.2009. PCH + size_t SubNumber; // WW + std::vector subdom_index; // WW + std::vector subdom_ic; // WW + std::string fname; // 17.11.2009. PCH - LinearFunctionData* dis_linear_f; //24.8.2011. WW + LinearFunctionData* dis_linear_f; // 24.8.2011. WW // REMOVE CANDIDATE - std::string geo_name; // TF 05/2010 - double geo_node_value; //KR + std::string geo_name; // TF 05/2010 + double geo_node_value; // KR public: - const std::string& getGeoName () const { return geo_name; } //KR - double getGeoNodeValue() const { return geo_node_value; } //KR - - int GetNumDom() const { return (int) subdom_index.size(); } //WW - int GetDomain(const int dom_index) const { return subdom_index[dom_index]; } //WW - //int mat_type; //MX + const std::string& getGeoName() const { return geo_name; } // KR + double getGeoNodeValue() const { return geo_node_value; } // KR + int GetNumDom() const { return (int)subdom_index.size(); } // WW + int GetDomain(const int dom_index) const { return subdom_index[dom_index]; } // WW + // int mat_type; //MX // DIS - //KR std::vector node_value_vector; + // KR std::vector node_value_vector; void SetDomain(int); - void SetByNodeIndex(int); // 19.11.2009 PCH + void SetByNodeIndex(int); // 19.11.2009 PCH void SetPolyline(int); void SetSurface(int); void SetPoint(int); - void StoreInitialValues();// JOD 2014-11-10 + void StoreInitialValues(); // JOD 2014-11-10 bool storeValues; - //void SetMaterialDomain(int); //MX + // void SetMaterialDomain(int); //MX double gradient_ref_depth; double gradient_ref_depth_value; double gradient_ref_depth_gradient; - std::string rfr_file_name; //OK + std::string rfr_file_name; // OK CInitialCondition(); CInitialCondition(const InitialCondition* ic); ~CInitialCondition(); @@ -91,28 +90,25 @@ class CInitialCondition : public ProcessInfo, public GeoInfo, public Distributio * @param unique_name the name of the project to access the right geometric entities * @return the new position in the stream after reading */ - std::ios::pos_type Read(std::ifstream* in, - const GEOLIB::GEOObjects& geo_obj, - const std::string& unique_name); + std::ios::pos_type Read(std::ifstream* in, const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name); void Write(std::fstream*) const; void Set(int); - void SetEle(int); //MX - void SetDomainEle(int); //MX + void SetEle(int); // MX + void SetDomainEle(int); // MX LinearFunctionData* getLinearFunction() const { return dis_linear_f; } - MeshLib::CFEMesh* m_msh; }; class CInitialConditionGroup { public: - std::string pcs_type_name; //OK - std::string pcs_pv_name; //OK - std::vectorgroup_vector; + std::string pcs_type_name; // OK + std::string pcs_pv_name; // OK + std::vector group_vector; }; -extern std::vectoric_group_vector; -extern std::vectoric_vector; +extern std::vector ic_group_vector; +extern std::vector ic_vector; /** * read file that stores initial conditions * @param file_base_name base file name (without extension) containing the initial conditions @@ -120,10 +116,8 @@ extern std::vectoric_vector; * @param unique_name unique name to access the geometric entities in geo_obj * @return true if initial conditions found in file, else false */ -bool ICRead(const std::string& file_base_name, - const GEOLIB::GEOObjects& geo_obj, - const std::string& unique_name); +bool ICRead(const std::string& file_base_name, const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name); extern void ICWrite(std::string); extern void ICDelete(); -extern CInitialCondition* ICGet(std::string); //OK +extern CInitialCondition* ICGet(std::string); // OK #endif diff --git a/FEM/rf_kinreact.cpp b/FEM/rf_kinreact.cpp index 44bfaab62..ae3e6dc79 100644 --- a/FEM/rf_kinreact.cpp +++ b/FEM/rf_kinreact.cpp @@ -44,34 +44,31 @@ #include "rf_react_int.h" #ifdef OGS_FEM_CAP // CAP_REACT //CB merge CAP 0311 - #include "rf_react_cap.h" +#include "rf_react_cap.h" #endif #if defined(USE_MPI) || defined(USE_MPI_KRC) //#undef SEEK_SET //#undef SEEK_CUR //#undef SEEK_END -#include "mpi.h"//Parallel Computing Support +#include "mpi.h" //Parallel Computing Support #include "par_ddc.h" #include "SplitMPI_Communicator.h" #endif - //#include "msh_mesh.h" using namespace std; using SolidProp::CSolidProperties; using namespace Math_Group; -vector KinReact_vector; // declare instance CKinReact_vector -vector KinReactData_vector; // declare instance CKinReact_vector -vector KinBlob_vector; // declare extern instance of class Blob +vector KinReact_vector; // declare instance CKinReact_vector +vector KinReactData_vector; // declare instance CKinReact_vector +vector KinBlob_vector; // declare extern instance of class Blob // CB _drmc_ -vector MicrobeData_vector; // declare extern instance of class Blob +vector MicrobeData_vector; // declare extern instance of class Blob static double dmaxarg1, dmaxarg2; -#define DMAX(a,b) (dmaxarg1 = (a),dmaxarg2 = (b),(dmaxarg1) > (dmaxarg2) ? \ - (dmaxarg1) : (dmaxarg2)) -#define DMIN(a,b) (dmaxarg1 = (a),dmaxarg2 = (b),(dmaxarg1) < (dmaxarg2) ? \ - (dmaxarg1) : (dmaxarg2)) +#define DMAX(a, b) (dmaxarg1 = (a), dmaxarg2 = (b), (dmaxarg1) > (dmaxarg2) ? (dmaxarg1) : (dmaxarg2)) +#define DMIN(a, b) (dmaxarg1 = (a), dmaxarg2 = (b), (dmaxarg1) < (dmaxarg2) ? (dmaxarg1) : (dmaxarg2)) /* Constructor for MonodSubstruct */ MonodSubstruct::MonodSubstruct(void) @@ -80,7 +77,7 @@ MonodSubstruct::MonodSubstruct(void) speciesnumber = -1; concentration = -1.0e9; order = -99.0; - isotopecouplenumber = -1; // CB isotope fractionation + isotopecouplenumber = -1; // CB isotope fractionation threshhold = false; threshConc = -1.0e9; threshOrder = -99; @@ -92,107 +89,108 @@ MonodSubstruct::~MonodSubstruct(void) } // CB _drmc_ -MicrobeData::MicrobeData(void){ - MicrobeName = "Blupp"; - MonodReactionName = "Bluxx"; - steepness = -1.0; - k_incr = 0.0; - k_decr = 0.0; - G0 = 0; - dt = 0; - decayrate = 0.0 ; - _drmc_ = false; - MonodReactionIdx = -1; - - Gibbs.clear(); - _drmc_level.clear(); - - +MicrobeData::MicrobeData(void) +{ + MicrobeName = "Blupp"; + MonodReactionName = "Bluxx"; + steepness = -1.0; + k_incr = 0.0; + k_decr = 0.0; + G0 = 0; + dt = 0; + decayrate = 0.0; + _drmc_ = false; + MonodReactionIdx = -1; + + Gibbs.clear(); + _drmc_level.clear(); } -MicrobeData::~MicrobeData(void){ +MicrobeData::~MicrobeData(void) +{ } -double MicrobeData::GetGibbsEnergy(long node){ - -double R = 8.314472; // Gas constant -double T = 298.25; // K -double G = 0, dG = 0; // dummy -int MonodSpecies = 0; -double MonodConcentration = 1.0; -int MonodOrder = 0; -double Ctot, C = 0; -//int Isotopespecies = 0; -double Monodterm = 1.0; -//double Inhibition = 1.0; -//double Rateconstant = 1.0; -//int NumberMonod = 0; -double scoeff = 0; -double unitfactor_l = 0.001; - - -CKinReact *m_kr = NULL; -m_kr = KinReact_vector[MonodReactionIdx]; -CKinReactData *m_krd = NULL; -m_krd = KinReactData_vector[0]; - -if(REACTINT_vec.size()>0) // Get the Temperature - T = REACTINT_vec[0]->GetTemperature(node); - -// G = dG * -µmax*Prod[Ai/(Ai+KAi)] -// = [dG0 + R*T*ln(Q)] * -µmax*Prod[Ai/(Ai+KAi)] - -// calculate dG = dG0 + R*T*ln(Q) -for(int i=0;inumber_reactionpartner;i++){ - MonodSpecies = m_kr->ProdStochhelp[i]->speciesnumber; - scoeff = m_kr->ProductionStoch[MonodSpecies]; - C = cp_vec[MonodSpecies]->getProcess()->GetNodeValue(node, m_krd->sp_varind[MonodSpecies]) ; - if(C <=0) - C = 1e-10; - dG += scoeff * log( 1 * C * unitfactor_l); -} -dG *= R*T; -dG += m_kr->dG0; - -// dS/dt/B term = -µmax*Prod[Ai/(Ai+KAi)] -for (int i=0; i < m_kr->number_monod; i++) { - MonodSpecies = m_kr->monod[i]->speciesnumber; - MonodConcentration = m_kr->monod[i]->concentration; - MonodOrder = (int)m_kr->monod[i]->order; // CB higher order Monod terms - C = cp_vec[MonodSpecies]->getProcess()->GetNodeValue(node, m_krd->sp_varind[MonodSpecies]); - Ctot = C; // standard case, no iso fractionation - // CB Isotope fractionation: here Ctot=C_light+C_heavy must be passed to fct Monod() - if((m_kr->typeflag_iso_fract==1) && (m_kr->monod[i]->isotopecouplenumber>=0)){ - MonodSpecies = m_kr->monod[i]->isotopecouplenumber; - Ctot = C + cp_vec[MonodSpecies]->getProcess()->GetNodeValue(node, m_krd->sp_varind[MonodSpecies]); - } - Monodterm *= m_kr->Monod(MonodConcentration, C, Ctot, MonodOrder); // new formulation - // now multiply by additional Threshhold Term, if present, - // technically this is the same as an additional Monod term for the same MonodSpecies - // usually of higher order and lower Monod-Conc = threshConc - if(m_kr->monod[i]->threshhold==true){ - MonodConcentration = m_kr->monod[i]->threshConc; // CB Threshhold concentration - MonodOrder = (int)m_kr->monod[i]->threshOrder; // CB higher order Monod terms - Monodterm *= m_kr->Monod(MonodConcentration, Ctot, Ctot, MonodOrder); // C should in any case be total C - } -} -for (int i = 0; i < m_kr->number_inhibit; i++) { - MonodSpecies = m_kr->inhibit[i]->speciesnumber; - MonodConcentration = m_kr->inhibit[i]->concentration; - C = cp_vec[MonodSpecies]->getProcess()->GetNodeValue(node, m_krd->sp_varind[MonodSpecies]); - Monodterm *= m_kr->Inhibition(MonodConcentration, C); -} +double MicrobeData::GetGibbsEnergy(long node) +{ + double R = 8.314472; // Gas constant + double T = 298.25; // K + double G = 0, dG = 0; // dummy + int MonodSpecies = 0; + double MonodConcentration = 1.0; + int MonodOrder = 0; + double Ctot, C = 0; + // int Isotopespecies = 0; + double Monodterm = 1.0; + // double Inhibition = 1.0; + // double Rateconstant = 1.0; + // int NumberMonod = 0; + double scoeff = 0; + double unitfactor_l = 0.001; + + CKinReact* m_kr = NULL; + m_kr = KinReact_vector[MonodReactionIdx]; + CKinReactData* m_krd = NULL; + m_krd = KinReactData_vector[0]; -// put together G = dG * ds/dt/X ; -// division by X not necessary here, as we calculated the rate explicitly -G = -m_kr->rateconstant*Monodterm*dG; -//dG = 200000; // dummy + if (REACTINT_vec.size() > 0) // Get the Temperature + T = REACTINT_vec[0]->GetTemperature(node); -return G; + // G = dG * -µmax*Prod[Ai/(Ai+KAi)] + // = [dG0 + R*T*ln(Q)] * -µmax*Prod[Ai/(Ai+KAi)] -} + // calculate dG = dG0 + R*T*ln(Q) + for (int i = 0; i < m_kr->number_reactionpartner; i++) + { + MonodSpecies = m_kr->ProdStochhelp[i]->speciesnumber; + scoeff = m_kr->ProductionStoch[MonodSpecies]; + C = cp_vec[MonodSpecies]->getProcess()->GetNodeValue(node, m_krd->sp_varind[MonodSpecies]); + if (C <= 0) + C = 1e-10; + dG += scoeff * log(1 * C * unitfactor_l); + } + dG *= R * T; + dG += m_kr->dG0; + // dS/dt/B term = -µmax*Prod[Ai/(Ai+KAi)] + for (int i = 0; i < m_kr->number_monod; i++) + { + MonodSpecies = m_kr->monod[i]->speciesnumber; + MonodConcentration = m_kr->monod[i]->concentration; + MonodOrder = (int)m_kr->monod[i]->order; // CB higher order Monod terms + C = cp_vec[MonodSpecies]->getProcess()->GetNodeValue(node, m_krd->sp_varind[MonodSpecies]); + Ctot = C; // standard case, no iso fractionation + // CB Isotope fractionation: here Ctot=C_light+C_heavy must be passed to fct Monod() + if ((m_kr->typeflag_iso_fract == 1) && (m_kr->monod[i]->isotopecouplenumber >= 0)) + { + MonodSpecies = m_kr->monod[i]->isotopecouplenumber; + Ctot = C + cp_vec[MonodSpecies]->getProcess()->GetNodeValue(node, m_krd->sp_varind[MonodSpecies]); + } + Monodterm *= m_kr->Monod(MonodConcentration, C, Ctot, MonodOrder); // new formulation + // now multiply by additional Threshhold Term, if present, + // technically this is the same as an additional Monod term for the same MonodSpecies + // usually of higher order and lower Monod-Conc = threshConc + if (m_kr->monod[i]->threshhold == true) + { + MonodConcentration = m_kr->monod[i]->threshConc; // CB Threshhold concentration + MonodOrder = (int)m_kr->monod[i]->threshOrder; // CB higher order Monod terms + Monodterm *= m_kr->Monod(MonodConcentration, Ctot, Ctot, MonodOrder); // C should in any case be total C + } + } + for (int i = 0; i < m_kr->number_inhibit; i++) + { + MonodSpecies = m_kr->inhibit[i]->speciesnumber; + MonodConcentration = m_kr->inhibit[i]->concentration; + C = cp_vec[MonodSpecies]->getProcess()->GetNodeValue(node, m_krd->sp_varind[MonodSpecies]); + Monodterm *= m_kr->Inhibition(MonodConcentration, C); + } + // put together G = dG * ds/dt/X ; + // division by X not necessary here, as we calculated the rate explicitly + G = -m_kr->rateconstant * Monodterm * dG; + // dG = 200000; // dummy + + return G; +} /************************************************************************** FEMLib-Method: @@ -202,97 +200,95 @@ return G; **************************************************************************/ void MicrobeConfig(void) { + // create vector for _drmc_ level and switsh function and initialization with value + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt + if (m_msh == NULL) + { + cout << "No mesh in KRConfig" + << "\n"; + exit(1); + } - // create vector for _drmc_ level and switsh function and initialization with value - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt - if (m_msh == NULL) - { - cout << "No mesh in KRConfig" << "\n"; - exit(1); - } - - for (size_t i = 0; i < MicrobeData_vector.size(); i++) - { - MicrobeData *m_md(MicrobeData_vector[i]); - for (size_t l = 0; l < m_msh->nod_vector.size(); l++){ - m_md->Gibbs.push_back(1.0); //Vorbelegung mit theta=-1 - m_md->_drmc_level.push_back(1.0); //Vorbelegung mit S=-1 - } - } + for (size_t i = 0; i < MicrobeData_vector.size(); i++) + { + MicrobeData* m_md(MicrobeData_vector[i]); + for (size_t l = 0; l < m_msh->nod_vector.size(); l++) + { + m_md->Gibbs.push_back(1.0); // Vorbelegung mit theta=-1 + m_md->_drmc_level.push_back(1.0); // Vorbelegung mit S=-1 + } + } } - /************************************************************************** FEMLib-Method: Task: OBJ read function for CKinBlob-Structure Programing: 02/2007 DS Implementation **************************************************************************/ -bool MicrobeData::Read(ifstream *rfd_file) +bool MicrobeData::Read(ifstream* rfd_file) { - char line[MAX_ZEILE]; - string line_string, line_str1, s_geo_type, s_geo_name; - string hash("#"), dollar("$"); - string species; - - - bool new_keyword = false;//, OK = true, new_subkeyword = false; - long index; - std::stringstream in; - - //======================================================================== - while (!new_keyword) - { - index = rfd_file->tellg(); - // if(!rfd_file->getline(line,MAX_ZEILE)) break; - if (!GetLineFromFile(line, rfd_file)) - break; - line_string = line; - if (line_string.find(hash) != string::npos) - { - new_keyword = true; - rfd_file->seekg(index); //Dateipointer zur�cksetzen, sonst ist das n�chste keyword weg - break; - } - /* Keywords nacheinander durchsuchen */ - //.................................................................... - // subkeyword found - if (line_string.find("$MICROBENAME") != string::npos) - { - in.str(GetLineFromFile1(rfd_file)); - in >> MicrobeName; - in.clear(); - } - //.................................................................... - // subkeyword found - if (line_string.find("$_drmc__PARAMETERS") != string::npos) - { - in.str(GetLineFromFile1(rfd_file)); - in >> steepness >> k_incr >> k_decr >> G0 >> decayrate; - //check for read in - if ((steepness != -1.0) && (k_incr != 0.0) && (k_decr != 0.0) ) - _drmc_= true; - else - { - DisplayMsgLn(" ERROR reading Microbe _drmc_ Terms - skipping"); - return false; - } - in.clear(); - } - //.................................................................... - // subkeyword found - if (line_string.find("$MONOD_REACTION_NAME") != string::npos) - { - in.str(GetLineFromFile1(rfd_file)); - in >> MonodReactionName; - in.clear(); - } - - } //end while keyword - - return true; -} + char line[MAX_ZEILE]; + string line_string, line_str1, s_geo_type, s_geo_name; + string hash("#"), dollar("$"); + string species; + + bool new_keyword = false; //, OK = true, new_subkeyword = false; + long index; + std::stringstream in; + + //======================================================================== + while (!new_keyword) + { + index = rfd_file->tellg(); + // if(!rfd_file->getline(line,MAX_ZEILE)) break; + if (!GetLineFromFile(line, rfd_file)) + break; + line_string = line; + if (line_string.find(hash) != string::npos) + { + new_keyword = true; + rfd_file->seekg(index); // Dateipointer zur�cksetzen, sonst ist das n�chste keyword weg + break; + } + /* Keywords nacheinander durchsuchen */ + //.................................................................... + // subkeyword found + if (line_string.find("$MICROBENAME") != string::npos) + { + in.str(GetLineFromFile1(rfd_file)); + in >> MicrobeName; + in.clear(); + } + //.................................................................... + // subkeyword found + if (line_string.find("$_drmc__PARAMETERS") != string::npos) + { + in.str(GetLineFromFile1(rfd_file)); + in >> steepness >> k_incr >> k_decr >> G0 >> decayrate; + // check for read in + if ((steepness != -1.0) && (k_incr != 0.0) && (k_decr != 0.0)) + _drmc_ = true; + else + { + DisplayMsgLn(" ERROR reading Microbe _drmc_ Terms - skipping"); + return false; + } + in.clear(); + } + //.................................................................... + // subkeyword found + if (line_string.find("$MONOD_REACTION_NAME") != string::npos) + { + in.str(GetLineFromFile1(rfd_file)); + in >> MonodReactionName; + in.clear(); + } + } // end while keyword + + return true; +} /*************************************************************************** FEMLib-Method: @@ -309,11 +305,11 @@ CKinReact::CKinReact(void) reactionpartner.clear(); stochmet.clear(); rateconstant = 0.0; - rateorder = 1.0; //CB default changed from 0 to 1, 06/2012 + rateorder = 1.0; // CB default changed from 0 to 1, 06/2012 number_monod = 0; number_inhibit = 0; number_production = 0; - number_isotope_couples = 0; // CB isotope fractionation + number_isotope_couples = 0; // CB isotope fractionation monod.clear(); inhibit.clear(); production.clear(); @@ -321,22 +317,22 @@ CKinReact::CKinReact(void) bacteria_number = -1; ProductionStoch.clear(); grow = -1; - specif_cap = -1.0; - isoenfac = 0; // CB Isotope fractionation - degType = "NULL"; // CB Isotope fractionation - T_dependence = false; - T_model = 0; - T_params.clear(); - -// CB _drmc_ - _drmc_ = false; - MicrobeData_idx = -1; - DormType = "NULL"; - DormTypeIdx = -1; - dG0 = 0; - Yieldcoefficient = 1; // microbial yield coeff, is 1 as standard case - - //CB Not this particular reaction on specified GEO-Objects + specif_cap = -1.0; + isoenfac = 0; // CB Isotope fractionation + degType = "NULL"; // CB Isotope fractionation + T_dependence = false; + T_model = 0; + T_params.clear(); + + // CB _drmc_ + _drmc_ = false; + MicrobeData_idx = -1; + DormType = "NULL"; + DormTypeIdx = -1; + dG0 = 0; + Yieldcoefficient = 1; // microbial yield coeff, is 1 as standard case + + // CB Not this particular reaction on specified GEO-Objects switched_off_node.clear(); ProdStochhelp.clear(); @@ -345,13 +341,13 @@ CKinReact::CKinReact(void) ex_species_names.clear(); exSurfaceID = -1; exType = "NULL"; - //NAPL-dissolution + // NAPL-dissolution blob_name = "NULL"; blob_ID = -1; Csat_pure = 0.; current_Csat = 0.; Density_NAPL = 0.; - Current_Csat.clear(); + Current_Csat.clear(); // typeflag_monod = 0; typeflag_exchange = 0; @@ -359,33 +355,32 @@ CKinReact::CKinReact(void) typeflag_exchange_langmuir = 0; typeflag_exchange_freundlich = 0; typeflag_napldissolution = 0; - typeflag_iso_fract = 0; // CB isotope fractionation - typeflag_mineralkinetics = 0; //CB - typeflag_gasdissolution = 0; - // Minkin - mechvec.clear(); - number_Mech=0; - minSpeciesIdx.clear(); - Am.clear(); // initial specific reactive mineral surface area - Km.clear(); // Equilibrium constant (at node) vector (if Km_uniform == false) - Cminini.clear(); - Km_uniform=true; - Km_CHEMAPP = false; - Km_HKF = false; - Am_constant = true; - Am_model = 0; - Am_ini = 0; - Eta=1.0; - Theta=1.0; - precip_baseterm_only = false; - precipfactor = 1.0; - precipexponent = 1.0; - scale_rate = false; - lagneau = false; - OmegaThreshhold = 1e-10; // if |1-Omega| < OmegaThreshhold, set rate to zero - MinKinRateCoeff = 0; - ExplicitMinKinRateCoeff = false; - + typeflag_iso_fract = 0; // CB isotope fractionation + typeflag_mineralkinetics = 0; // CB + typeflag_gasdissolution = 0; + // Minkin + mechvec.clear(); + number_Mech = 0; + minSpeciesIdx.clear(); + Am.clear(); // initial specific reactive mineral surface area + Km.clear(); // Equilibrium constant (at node) vector (if Km_uniform == false) + Cminini.clear(); + Km_uniform = true; + Km_CHEMAPP = false; + Km_HKF = false; + Am_constant = true; + Am_model = 0; + Am_ini = 0; + Eta = 1.0; + Theta = 1.0; + precip_baseterm_only = false; + precipfactor = 1.0; + precipexponent = 1.0; + scale_rate = false; + lagneau = false; + OmegaThreshhold = 1e-10; // if |1-Omega| < OmegaThreshhold, set rate to zero + MinKinRateCoeff = 0; + ExplicitMinKinRateCoeff = false; } /*************************************************************************** @@ -395,7 +390,8 @@ CKinReact::CKinReact(void) 02/2006 SB Implementation ***************************************************************************/ CKinReact::~CKinReact(void) -{} +{ +} /************************************************************************** FEMLib-Method: @@ -403,19 +399,18 @@ CKinReact::~CKinReact(void) Programing: 02/2004 SB Implementation **************************************************************************/ -bool KRRead(const std::string &file_base_name, - const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) +bool KRRead(const std::string& file_base_name, const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) { // File handling - std::string krc_file_name (file_base_name + KRC_FILE_EXTENSION); + std::string krc_file_name(file_base_name + KRC_FILE_EXTENSION); std::ifstream krc_file(krc_file_name.data(), ios::in); if (!krc_file.good()) return false; - CKinReact* m_kr = NULL, * m_kr1 = NULL; + CKinReact *m_kr = NULL, *m_kr1 = NULL; CKinReactData* m_krd = NULL; CKinBlob* m_bp = NULL; - MicrobeData *m_md = NULL; + MicrobeData* m_md = NULL; char line[MAX_ZEILE]; string sub_line; string line_string; @@ -428,7 +423,8 @@ bool KRRead(const std::string &file_base_name, KRCDelete(); //======================================================================== // Keyword loop - cout << "KinReact Read" << "\n"; + cout << "KinReact Read" + << "\n"; while (!krc_file.eof()) { krc_file.getline(line, MAX_ZEILE); @@ -441,32 +437,32 @@ bool KRRead(const std::string &file_base_name, { m_kr = new CKinReact(); m_kr->Read(&krc_file, geo_obj, unique_name); - m_kr->number = (int) KinReact_vector.size(); + m_kr->number = (int)KinReact_vector.size(); KinReact_vector.push_back(m_kr); - } // keyword found - // keyword found // Read KinReactData + } // keyword found + // keyword found // Read KinReactData if (line_string.find("#KINREACTIONDATA") != string::npos) { m_krd = new CKinReactData(); m_krd->Read(&krc_file, geo_obj, unique_name); KinReactData_vector.push_back(m_krd); - } // keyword found - // keyword found // Read BlobProperties + } // keyword found + // keyword found // Read BlobProperties if (line_string.find("#BLOB_PROPERTIES") != string::npos) { m_bp = new CKinBlob(); m_bp->Read(&krc_file, geo_obj, unique_name); KinBlob_vector.push_back(m_bp); - } // keyword found -// CB _drmc_ - if (line_string.find("#MICROBE_PROPERTIES") != string::npos) - { - m_md = new MicrobeData(); - if(m_md->Read(&krc_file)) - MicrobeData_vector.push_back(m_md); - } // keyword found - - } // eof + } // keyword found + // CB _drmc_ + if (line_string.find("#MICROBE_PROPERTIES") != string::npos) + { + m_md = new MicrobeData(); + if (m_md->Read(&krc_file)) + MicrobeData_vector.push_back(m_md); + } // keyword found + + } // eof // Close input file krc_file.close(); @@ -508,19 +504,13 @@ bool KRRead(const std::string &file_base_name, if (line_string.find("#REACTION") != string::npos) { m_kr1 = new CKinReact(); - position = m_kr1->Read(&dbf_file, - geo_obj, - unique_name); - //check if this is the right one + position = m_kr1->Read(&dbf_file, geo_obj, unique_name); + // check if this is the right one if (m_kr->name == m_kr1->name) { // Insert in Reaction vector and remove old reaction (replacement) - KinReact_vector.insert( - KinReact_vector.begin() + i - + 1, - m_kr1); - KinReact_vector.erase(KinReact_vector.begin( - ) + i); + KinReact_vector.insert(KinReact_vector.begin() + i + 1, m_kr1); + KinReact_vector.erase(KinReact_vector.begin() + i); found = 1; } else @@ -532,36 +522,36 @@ bool KRRead(const std::string &file_base_name, if (found == 0) { // reaction not complete in input file and also not specified in dbf_file - cout << " ERROR! Reaction " << m_kr->name - << " not found in database file" << "\n"; - cout << " Reaction removed from set of reaction " << "\n"; + cout << " ERROR! Reaction " << m_kr->name << " not found in database file" + << "\n"; + cout << " Reaction removed from set of reaction " + << "\n"; // remove reaction from reaction vector KinReact_vector.erase(KinReact_vector.begin() + i); } - } // end of if(m_kr=NULL - } //end for + } // end of if(m_kr=NULL + } // end for // close database file dbf_file.close(); - } // end if kinreaction_vec.size() > + } // end if kinreaction_vec.size() > /* end data base file read for reactions */ - //======================================================================== + //======================================================================== /* check reaction data consistency */ - std::cout << " Checking reaction data consistency for " - << KinReact_vector.size() << " specified reactions " << "\n"; + std::cout << " Checking reaction data consistency for " << KinReact_vector.size() << " specified reactions " + << "\n"; length = KinReact_vector.size(); for (size_t i = 0; i < length; i++) { m_kr = KinReact_vector[i]; if (!m_kr->CheckReactionDataConsistency()) { - cout << " ERROR! Reaction " << m_kr->name - << " removed from set of reactions due to data inconsistency" + cout << " ERROR! Reaction " << m_kr->name << " removed from set of reactions due to data inconsistency" << "\n"; KinReact_vector.erase(KinReact_vector.begin() + i); } - } //end for(i=0;.. consistency check + } // end for(i=0;.. consistency check return true; } @@ -578,47 +568,53 @@ void KRConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) { CKinReact* m_kr = NULL; //, *m_kr1=NULL; CKinReactData* m_krd = NULL; - MinkinMech * m_mech = NULL; - MicrobeData * m_md = NULL; - int k;//i, length, j, ; - // int idummy; //idx, - long ll, lm; - string m_name, sp_name; + MinkinMech* m_mech = NULL; + MicrobeData* m_md = NULL; + int k; // i, length, j, ; + // int idummy; //idx, + long ll, lm; + string m_name, sp_name; CompProperties* m_cp = NULL; CRFProcess* m_pcs = NULL; vector nodes_vector; CMediumProperties* m_mat_mp = NULL; - //long group; - double ww;//foc, , w; + // long group; + double ww; // foc, , w; - string dummy; - bool ok = true; - std::vector helpvec; + string dummy; + bool ok = true; + std::vector helpvec; - // CB reaction deactivation - //int annode_idx, lll, llll, lllll, nnodpneigh, duplicate,nn, nnodsneigh - //int dnele_idx; // , pneighnod_idx, snele_idx, - // int dnnode, snnode, duplicate2; + // CB reaction deactivation + // int annode_idx, lll, llll, lllll, nnodpneigh, duplicate,nn, nnodsneigh + // int dnele_idx; // , pneighnod_idx, snele_idx, + // int dnnode, snnode, duplicate2; MeshLib::CElem* m_dnele = NULL; MeshLib::CElem* m_snele = NULL; MeshLib::CNode* m_dnnod = NULL; - std::vector ReactNeighborNodes; + std::vector ReactNeighborNodes; vec secnnodesindices(8); vec primnnodesindices(8); - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt - if(m_msh == NULL) {cout << "No mesh in KRConfig" << "\n"; exit(0);} - //======================================================================== + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt + if (m_msh == NULL) + { + cout << "No mesh in KRConfig" + << "\n"; + exit(0); + } + //======================================================================== if (!KinReactData_vector.empty()) { m_krd = KinReactData_vector[0]; if (m_krd == NULL) - cout << " Error - no m_krd data " << "\n"; + cout << " Error - no m_krd data " + << "\n"; // Set up additional data structures for calculations // Set number of reactions - m_krd->NumberReactions = (int) KinReact_vector.size(); - size_t length (cp_vec.size()); + m_krd->NumberReactions = (int)KinReact_vector.size(); + size_t length(cp_vec.size()); // Check if all reaction partners are specified as processes for (int j = 0; j < m_krd->NumberReactions; j++) @@ -631,8 +627,7 @@ void KRConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) if (m_pcs == NULL) { cout << " Warning: Component " << m_kr->bacteria_name - << - " specified in KinReact as biomass but not given as transport process " + << " specified in KinReact as biomass but not given as transport process " << "\n"; ok = false; } @@ -644,8 +639,7 @@ void KRConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) if (m_pcs == NULL) { cout << " Warning: Component " << m_kr->monod[i]->species - << - " specified in KinReact as monod species but not given as transport process " + << " specified in KinReact as monod species but not given as transport process " << "\n"; ok = false; } @@ -657,8 +651,7 @@ void KRConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) if (m_pcs == NULL) { cout << " Warning: Component " << m_kr->inhibit[i]->species - << - " specified in KinReact as inhibition species but not given as transport process " + << " specified in KinReact as inhibition species but not given as transport process " << "\n"; ok = false; } @@ -666,14 +659,11 @@ void KRConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) // Check productionstoch for (size_t i = 0; i < m_kr->ProdStochhelp.size(); i++) { - m_pcs = PCSGet("MASS_TRANSPORT", - m_kr->ProdStochhelp[i]->species); + m_pcs = PCSGet("MASS_TRANSPORT", m_kr->ProdStochhelp[i]->species); if (m_pcs == NULL) { - cout << " Warning: Component " - << m_kr->ProdStochhelp[i]->species - << - " specified in KinReact as produced species but not given as transport process " + cout << " Warning: Component " << m_kr->ProdStochhelp[i]->species + << " specified in KinReact as produced species but not given as transport process " << "\n"; ok = false; } @@ -684,10 +674,8 @@ void KRConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) m_pcs = PCSGet("MASS_TRANSPORT", m_kr->reactionpartner[i]); if (m_pcs == NULL) { - cout << " Warning: Component " - << m_kr->reactionpartner[i] - << - " specified in KinReact as reaction partner but not given as transport process " + cout << " Warning: Component " << m_kr->reactionpartner[i] + << " specified in KinReact as reaction partner but not given as transport process " << "\n"; ok = false; } @@ -700,29 +688,34 @@ void KRConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) if (m_pcs == NULL) { cout << " Warning: Component " << m_kr->Isotope_light - << - " specified in KinReact in isotope couple but not given as transport process " + << " specified in KinReact in isotope couple but not given as transport process " << "\n"; ok = false; } } - // check mechanism terms - for(int i=0;i<(int)m_kr->number_Mech;i++){ // todo CB isotope fract - m_mech = m_kr->mechvec[i]; - for(k=0;kno_mechSpec;k++){ // todo CB isotope fract - m_pcs = PCSGet("MASS_TRANSPORT", m_mech->mechSpeciesNames[k]); - if(m_pcs == NULL) { - cout << " Warning: Component " << m_mech->mechSpeciesNames[k] << " specified in KinReact in Mechanism term but not given as transport process " << "\n"; - ok=false; - } - } - } - - } // loop over m_krd->NumberReactions + // check mechanism terms + for (int i = 0; i < (int)m_kr->number_Mech; i++) + { // todo CB isotope fract + m_mech = m_kr->mechvec[i]; + for (k = 0; k < m_mech->no_mechSpec; k++) + { // todo CB isotope fract + m_pcs = PCSGet("MASS_TRANSPORT", m_mech->mechSpeciesNames[k]); + if (m_pcs == NULL) + { + cout << " Warning: Component " << m_mech->mechSpeciesNames[k] + << " specified in KinReact in Mechanism term but not given as transport process " + << "\n"; + ok = false; + } + } + } + + } // loop over m_krd->NumberReactions // if (ok == false) { - cout << " Components missing, Stopping" << "\n"; + cout << " Components missing, Stopping" + << "\n"; cout.flush(); exit(1); } @@ -730,7 +723,7 @@ void KRConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) // Set vector is_a_bacterium // cout << " Length of cp_vec: " << length << "\n"; for (size_t j = 0; j < length; j++) - m_krd->is_a_bacterium.push_back(0); //initialize + m_krd->is_a_bacterium.push_back(0); // initialize for (int j = 0; j < m_krd->NumberReactions; j++) { m_kr = KinReact_vector[j]; @@ -746,22 +739,24 @@ void KRConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) for (int j = 0; j < m_krd->NumberReactions; j++) { m_kr = KinReact_vector[j]; - if((m_kr->type.compare("monod")==0) || (m_kr->type.compare("Mineralkinetics")==0) ){ + if ((m_kr->type.compare("monod") == 0) || (m_kr->type.compare("Mineralkinetics") == 0)) + { for (size_t i = 0; i < length; i++) - //initialize + // initialize m_kr->ProductionStoch.push_back(0.0); // Get Stochiometry for (size_t k = 0; k < m_kr->ProdStochhelp.size(); k++) { - std::string const& m_name (m_kr->ProdStochhelp[k]->species); + std::string const& m_name(m_kr->ProdStochhelp[k]->species); for (size_t i = 0; i < length; i++) - if (m_name.compare(cp_vec[i]->compname) == 0){ + if (m_name.compare(cp_vec[i]->compname) == 0) + { m_kr->ProductionStoch[i] = m_kr->ProdStochhelp[k]->concentration; - m_kr->ProdStochhelp[k]->speciesnumber = i; + m_kr->ProdStochhelp[k]->speciesnumber = i; } } - } //if type == monod or type == Mineralkinetics + } // if type == monod or type == Mineralkinetics } // vector ProductionStoch // Set numbers for monod species for each reaction @@ -771,7 +766,7 @@ void KRConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) if (m_kr->type.compare("monod") == 0) for (size_t i = 0; i < m_kr->monod.size(); i++) { - std::string const& m_name (m_kr->monod[i]->species); + std::string const& m_name(m_kr->monod[i]->species); for (size_t k = 0; k < length; k++) if (m_name.compare(cp_vec[k]->compname) == 0) m_kr->monod[i]->speciesnumber = k; @@ -786,16 +781,14 @@ void KRConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) if (m_kr->degType.compare("isotope_fractionation") == 0) for (size_t i = 0; i < m_kr->monod.size(); i++) { - std::string m_name (m_kr->monod[i]->species); + std::string m_name(m_kr->monod[i]->species); if (m_name.compare(m_kr->Isotope_light) == 0) { m_name = m_kr->Isotope_heavy; for (size_t k = 0; k < length; k++) - if (m_name.compare(cp_vec[k]->compname) == - 0) + if (m_name.compare(cp_vec[k]->compname) == 0) { - m_kr->monod[i]->isotopecouplenumber - = k; + m_kr->monod[i]->isotopecouplenumber = k; break; } } @@ -803,11 +796,9 @@ void KRConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) { m_name = m_kr->Isotope_light; for (size_t k = 0; k < length; k++) - if (m_name.compare(cp_vec[k]->compname) == - 0) + if (m_name.compare(cp_vec[k]->compname) == 0) { - m_kr->monod[i]->isotopecouplenumber - = k; + m_kr->monod[i]->isotopecouplenumber = k; break; } } @@ -821,7 +812,7 @@ void KRConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) if (m_kr->type.compare("monod") == 0) for (size_t i = 0; i < m_kr->inhibit.size(); i++) { - std::string const& m_name (m_kr->inhibit[i]->species); + std::string const& m_name(m_kr->inhibit[i]->species); for (size_t k = 0; k < length; k++) if (m_name.compare(cp_vec[k]->compname) == 0) m_kr->inhibit[i]->speciesnumber = k; @@ -834,59 +825,61 @@ void KRConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) m_kr = KinReact_vector[j]; if (m_kr->type.compare("monod") == 0) { - std::string const& m_name (m_kr->bacteria_name); + std::string const& m_name(m_kr->bacteria_name); for (size_t k = 0; k < length; k++) { m_cp = cp_vec[k]; if (m_name.compare(m_cp->compname) == 0) - m_kr->bacteria_number - = k; + m_kr->bacteria_number = k; } } - } //bacteria numbers - - // Set MicrobeData for each reaction - for (int j = 0; j < m_krd->NumberReactions; j++) - { - m_kr = KinReact_vector[j]; - if (m_kr->_drmc_) - { - // Set MicrobeData group index - m_name = m_kr->Microbename; - for (size_t k = 0; k < MicrobeData_vector.size(); k++) - { - if (m_name.compare(MicrobeData_vector[k]->MicrobeName) == 0) - m_kr->MicrobeData_idx = k; - } - if(m_kr->MicrobeData_idx==-1){ - cout << " Microbe name " << m_name << " does not match MicrobeData! Stopping" << "\n"; - cout.flush(); - exit(1); - } - // set _drmc_ type index - if(m_kr->DormType.compare("GROWTH")==0) - m_kr->DormTypeIdx=0; - else if(m_kr->DormType.compare("DEACTIVATION")==0) - m_kr->DormTypeIdx=1; - else if(m_kr->DormType.compare("REACTIVATION")==0) - m_kr->DormTypeIdx=2; - else if(m_kr->DormType.compare("DECAY")==0) - m_kr->DormTypeIdx=3; - else{ - cout << " Unknown _drmc_ Reaction Type " << m_kr->DormType << "! Stopping" << "\n"; - cout.flush(); - exit(1); - } - // - } - } //MicrobeData + } // bacteria numbers + // Set MicrobeData for each reaction + for (int j = 0; j < m_krd->NumberReactions; j++) + { + m_kr = KinReact_vector[j]; + if (m_kr->_drmc_) + { + // Set MicrobeData group index + m_name = m_kr->Microbename; + for (size_t k = 0; k < MicrobeData_vector.size(); k++) + { + if (m_name.compare(MicrobeData_vector[k]->MicrobeName) == 0) + m_kr->MicrobeData_idx = k; + } + if (m_kr->MicrobeData_idx == -1) + { + cout << " Microbe name " << m_name << " does not match MicrobeData! Stopping" + << "\n"; + cout.flush(); + exit(1); + } + // set _drmc_ type index + if (m_kr->DormType.compare("GROWTH") == 0) + m_kr->DormTypeIdx = 0; + else if (m_kr->DormType.compare("DEACTIVATION") == 0) + m_kr->DormTypeIdx = 1; + else if (m_kr->DormType.compare("REACTIVATION") == 0) + m_kr->DormTypeIdx = 2; + else if (m_kr->DormType.compare("DECAY") == 0) + m_kr->DormTypeIdx = 3; + else + { + cout << " Unknown _drmc_ Reaction Type " << m_kr->DormType << "! Stopping" + << "\n"; + cout.flush(); + exit(1); + } + // + } + } // MicrobeData // Set flags type_monod and type_exchange for (int j = 0; j < m_krd->NumberReactions; j++) { m_kr = KinReact_vector[j]; -// dummy = m_kr->type; + // dummy = m_kr->type; if (m_kr->type.compare("monod") == 0) // CB Isotope fractionation { m_kr->typeflag_monod = 1; @@ -905,27 +898,31 @@ void KRConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) } if (m_kr->type.compare("NAPLdissolution") == 0) m_kr->typeflag_napldissolution = 1; - if(m_kr->type.compare("Mineralkinetics")==0) - m_kr->typeflag_mineralkinetics=1; - } //typeflags - - //set index number for MicrobeData - for (int j = 0; j < (int) MicrobeData_vector.size(); j++) - { - m_md = MicrobeData_vector[j]; - for (int k = 0; k < m_krd->NumberReactions; k++){ - m_kr = KinReact_vector[k]; - if (m_md->MonodReactionName.compare(m_kr->name) == 0){ - m_md->MonodReactionIdx = k; - break; - } - } - if(m_md->MonodReactionIdx == -1){ // failure - cout << " Unknown Monod Reaction for _drmc_ model: " << m_md->MonodReactionName << " ! Stopping" << "\n"; - cout.flush(); - exit(1); - } - } + if (m_kr->type.compare("Mineralkinetics") == 0) + m_kr->typeflag_mineralkinetics = 1; + } // typeflags + + // set index number for MicrobeData + for (int j = 0; j < (int)MicrobeData_vector.size(); j++) + { + m_md = MicrobeData_vector[j]; + for (int k = 0; k < m_krd->NumberReactions; k++) + { + m_kr = KinReact_vector[k]; + if (m_md->MonodReactionName.compare(m_kr->name) == 0) + { + m_md->MonodReactionIdx = k; + break; + } + } + if (m_md->MonodReactionIdx == -1) + { // failure + cout << " Unknown Monod Reaction for _drmc_ model: " << m_md->MonodReactionName << " ! Stopping" + << "\n"; + cout.flush(); + exit(1); + } + } // exchange reactions for (int j = 0; j < m_krd->NumberReactions; j++) @@ -935,161 +932,192 @@ void KRConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) // move names from equation to vector with names for (size_t i = 0; i < m_kr->reactionpartner.size(); i++) { - std::string const& m_name (m_kr->reactionpartner[i]); + std::string const& m_name(m_kr->reactionpartner[i]); m_kr->ex_species_names.push_back(m_name); // find species numbers for soecies names for (size_t k = 0; k < length; k++) if (m_name.compare(cp_vec[k]->compname) == 0) m_kr->ex_species.push_back(k); } - } //exchange species numbers + } // exchange species numbers //#ds NAPLdissolution reaction for (int j = 0; j < m_krd->NumberReactions; j++) { m_kr = KinReact_vector[j]; if (m_kr->type.compare("NAPLdissolution") == 0) - { + { // move names from equation to vector with names for (size_t i = 0; i < m_kr->reactionpartner.size(); i++) { - std::string const& m_name (m_kr->reactionpartner[i]); + std::string const& m_name(m_kr->reactionpartner[i]); m_kr->ex_species_names.push_back(m_name); // find species numbers for species names for (size_t k = 0; k < length; k++) if (m_name.compare(cp_vec[k]->compname) == 0) m_kr->ex_species.push_back(k); } - // Prepare vector Current_Csat for each node - for(size_t l=0; l< m_msh->nod_vector.size();l++) - m_kr->Current_Csat.push_back(0); - } + // Prepare vector Current_Csat for each node + for (size_t l = 0; l < m_msh->nod_vector.size(); l++) + m_kr->Current_Csat.push_back(0); + } - //set index numbers for blob_id + // set index numbers for blob_id CKinBlob* m_kb = NULL; for (size_t i = 0; i < KinBlob_vector.size(); i++) - { - m_kb = KinBlob_vector[i]; - if (m_kr->blob_name.compare(m_kb->name) == 0) - { - m_kr->blob_ID = i; - if(m_kb->gas_dissolution_flag) - m_kr->typeflag_gasdissolution = 1; - } - } //blob vector size - } //NAPLdissolution species numbers - - //CB Mineralkinetics reaction - for(int j=0;jNumberReactions;j++){ - m_kr = KinReact_vector[j]; - if(m_kr->type.compare("Mineralkinetics")==0){ - if(m_krd->activity_model>0){ - //initialize help vector for activties, do only once - if(helpvec.size()==0) - for(size_t i=0;iActivityCoefficients.size()==0) - for(size_t i=0;inod_vector.size(); i++) - m_krd->ActivityCoefficients.push_back(helpvec); - // Ionic Strengths, do only once - if(m_krd->IonicStrengths.size()==0) - for(size_t i=0;inod_vector.size(); i++) - m_krd->IonicStrengths.push_back(0); - } - // Prepare Km vector, for each node 1 value, per reaction - if(m_kr->Km_uniform==false){ - ww = m_kr->Km[0]; - for(size_t l=1; l< m_msh->nod_vector.size();l++) // start at idx 1, as first value has been set already in CKinReact::READ - m_kr->Km.push_back(ww); - } - // Prepare Am vector, for each node 1 value, per reaction - if(m_kr->Am_constant==false){ - ww = m_kr->Am[0]; - for(size_t l=1; l< m_msh->nod_vector.size();l++) // start at idx 1, as first value has been set already in CKinReact::READ - m_kr->Am.push_back(ww); - } - // Set Omega treshholds from MinReactData - m_kr->OmegaThreshhold = m_krd->OmegaThresh; - } - } //Mineralkinetics - - // Set numbers for Mineral species for each reaction - for(int j=0;jNumberReactions;j++){ - m_kr = KinReact_vector[j]; - if(m_kr->type.compare("Mineralkinetics")==0){ - // Mineral index - m_name = m_kr->mineral_name; - for(size_t k=0;kcompname) == 0){ - m_kr->mineral_number = k; - if(cp_vec[k]->transport_phase!=1) - cout << "Warning: Mineral is not defined as solid phase species, phase # " << cp_vec[k]->transport_phase << "\n"; - break; - } - } - // water index (this needs to be defined for reactions involving H2O as a species - for(size_t k=0;kcompname.compare("H2O") == 0) || (cp_vec[k]->compname.compare("H2O_liquid") == 0) || (cp_vec[k]->compname.compare("water_liquid")==0) ){ - m_kr->water_number = k; - break; - } - } - // Mineral species - for(int i=0;i<(int)m_kr->number_reactionpartner;i++){ - m_name = m_kr->reactionpartner[i]; - for(size_t k=0;kcompname) == 0) - m_kr->minSpeciesIdx.push_back(k); - } - // Mechanism term species - for(size_t i=0;imechvec.size();i++){ - m_mech = m_kr->mechvec[i]; - for(int l=0;lmechvec[i]->no_mechSpec;l++){ - m_name = m_kr->mechvec[i]->mechSpeciesNames[l]; - for(size_t k=0;kcompname) == 0) - m_kr->mechvec[i]->mechSpeciesIdx.push_back(k); - } - } - } - } // Mineral Kinetics & substructure numbers - - // check for necessary data in Mineral kinetics - for(int j=0;jNumberReactions;j++){ - m_kr = KinReact_vector[j]; - if(m_kr->type.compare("Mineralkinetics")==0){ - // surface area data - if(m_kr->Am_constant==false){ - if(m_kr->Am_model>1){ - if(cp_vec[m_kr->mineral_number]->molar_weight==0){ - cout << " Warning for surface area model of Mineral " << m_kr->mineral_name << ":" << "\n"; - cout << " No molar_weight defined in component properties." << "\n" ; - ok=false; - } - if(cp_vec[m_kr->mineral_number]->mineral_density==0){ - cout << " Warning for surface area model of Mineral " << m_kr->mineral_name << ":" << "\n"; - cout << " No mineral_density defined in component properties." << "\n" ; - ok=false; - } - } - } - // node porosities - // water concentrations - // etc - } - } - // set special case of Lagneau-Benchmark - if(m_krd->lagneau){ - for(int j=0;jNumberReactions;j++){ - KinReact_vector[j]->lagneau=true; - } - } - //.................................................................... - if(m_krd->scale_dcdt ){ // scale dcdt vector in derivs for stabilization of ODE solver - for(int j=0;jNumberReactions;j++) - KinReact_vector[j]->scale_rate=true; - } + { + m_kb = KinBlob_vector[i]; + if (m_kr->blob_name.compare(m_kb->name) == 0) + { + m_kr->blob_ID = i; + if (m_kb->gas_dissolution_flag) + m_kr->typeflag_gasdissolution = 1; + } + } // blob vector size + } // NAPLdissolution species numbers + + // CB Mineralkinetics reaction + for (int j = 0; j < m_krd->NumberReactions; j++) + { + m_kr = KinReact_vector[j]; + if (m_kr->type.compare("Mineralkinetics") == 0) + { + if (m_krd->activity_model > 0) + { + // initialize help vector for activties, do only once + if (helpvec.size() == 0) + for (size_t i = 0; i < length; i++) // length = no of species + helpvec.push_back(0.0); + // Activity coefficients, do only once + if (m_krd->ActivityCoefficients.size() == 0) + for (size_t i = 0; i < m_msh->nod_vector.size(); i++) + m_krd->ActivityCoefficients.push_back(helpvec); + // Ionic Strengths, do only once + if (m_krd->IonicStrengths.size() == 0) + for (size_t i = 0; i < m_msh->nod_vector.size(); i++) + m_krd->IonicStrengths.push_back(0); + } + // Prepare Km vector, for each node 1 value, per reaction + if (m_kr->Km_uniform == false) + { + ww = m_kr->Km[0]; + for (size_t l = 1; l < m_msh->nod_vector.size(); + l++) // start at idx 1, as first value has been set already in CKinReact::READ + m_kr->Km.push_back(ww); + } + // Prepare Am vector, for each node 1 value, per reaction + if (m_kr->Am_constant == false) + { + ww = m_kr->Am[0]; + for (size_t l = 1; l < m_msh->nod_vector.size(); + l++) // start at idx 1, as first value has been set already in CKinReact::READ + m_kr->Am.push_back(ww); + } + // Set Omega treshholds from MinReactData + m_kr->OmegaThreshhold = m_krd->OmegaThresh; + } + } // Mineralkinetics + + // Set numbers for Mineral species for each reaction + for (int j = 0; j < m_krd->NumberReactions; j++) + { + m_kr = KinReact_vector[j]; + if (m_kr->type.compare("Mineralkinetics") == 0) + { + // Mineral index + m_name = m_kr->mineral_name; + for (size_t k = 0; k < length; k++) + { + if (m_name.compare(cp_vec[k]->compname) == 0) + { + m_kr->mineral_number = k; + if (cp_vec[k]->transport_phase != 1) + cout << "Warning: Mineral is not defined as solid phase species, phase # " + << cp_vec[k]->transport_phase << "\n"; + break; + } + } + // water index (this needs to be defined for reactions involving H2O as a species + for (size_t k = 0; k < length; k++) + { + if ((cp_vec[k]->compname.compare("H2O") == 0) || (cp_vec[k]->compname.compare("H2O_liquid") == 0) + || (cp_vec[k]->compname.compare("water_liquid") == 0)) + { + m_kr->water_number = k; + break; + } + } + // Mineral species + for (int i = 0; i < (int)m_kr->number_reactionpartner; i++) + { + m_name = m_kr->reactionpartner[i]; + for (size_t k = 0; k < length; k++) + if (m_name.compare(cp_vec[k]->compname) == 0) + m_kr->minSpeciesIdx.push_back(k); + } + // Mechanism term species + for (size_t i = 0; i < m_kr->mechvec.size(); i++) + { + m_mech = m_kr->mechvec[i]; + for (int l = 0; l < m_kr->mechvec[i]->no_mechSpec; l++) + { + m_name = m_kr->mechvec[i]->mechSpeciesNames[l]; + for (size_t k = 0; k < length; k++) + if (m_name.compare(cp_vec[k]->compname) == 0) + m_kr->mechvec[i]->mechSpeciesIdx.push_back(k); + } + } + } + } // Mineral Kinetics & substructure numbers + + // check for necessary data in Mineral kinetics + for (int j = 0; j < m_krd->NumberReactions; j++) + { + m_kr = KinReact_vector[j]; + if (m_kr->type.compare("Mineralkinetics") == 0) + { + // surface area data + if (m_kr->Am_constant == false) + { + if (m_kr->Am_model > 1) + { + if (cp_vec[m_kr->mineral_number]->molar_weight == 0) + { + cout << " Warning for surface area model of Mineral " << m_kr->mineral_name << ":" + << "\n"; + cout << " No molar_weight defined in component properties." + << "\n"; + ok = false; + } + if (cp_vec[m_kr->mineral_number]->mineral_density == 0) + { + cout << " Warning for surface area model of Mineral " << m_kr->mineral_name << ":" + << "\n"; + cout << " No mineral_density defined in component properties." + << "\n"; + ok = false; + } + } + } + // node porosities + // water concentrations + // etc + } + } + // set special case of Lagneau-Benchmark + if (m_krd->lagneau) + { + for (int j = 0; j < m_krd->NumberReactions; j++) + { + KinReact_vector[j]->lagneau = true; + } + } + //.................................................................... + if (m_krd->scale_dcdt) + { // scale dcdt vector in derivs for stabilization of ODE solver + for (int j = 0; j < m_krd->NumberReactions; j++) + KinReact_vector[j]->scale_rate = true; + } // exchange reactions numbers for m_krd for (int j = 0; j < m_krd->NumberReactions; j++) { @@ -1104,15 +1132,15 @@ void KRConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) m_krd->NumberMonod++; if (m_kr->type.compare("NAPLdissolution") == 0) m_krd->NumberNAPLdissolution++; - if(m_kr->type.compare("Mineralkinetics")==0) - m_krd->NumberMineralkinetics++; + if (m_kr->type.compare("Mineralkinetics") == 0) + m_krd->NumberMineralkinetics++; } - m_krd->NumberMicrobeData = (int)MicrobeData_vector.size(); + m_krd->NumberMicrobeData = (int)MicrobeData_vector.size(); // set up vectors sp_pcs and sp_varind for (size_t j = 0; j < length; j++) { - std::string const& sp_name (cp_vec[j]->compname); + std::string const& sp_name(cp_vec[j]->compname); // HS, PCSGet not needed any more. // m_pcs = PCSGet("MASS_TRANSPORT", sp_name); // new style: @@ -1123,10 +1151,10 @@ void KRConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) // m_krd->sp_pcsind.push_back(idummy); // new timelevel m_krd->sp_varind.push_back(m_pcs->GetNodeValueIndex(sp_name) + 1); - // cout << " PCS: " << j << ", " << sp_name << ", " << idummy << ", " << m_pcs->GetNodeValueIndex(sp_name) + 1 << "\n"; + // cout << " PCS: " << j << ", " << sp_name << ", " << idummy << ", " << m_pcs->GetNodeValueIndex(sp_name) + //+ 1 << "\n"; } - // CB isotope fractionation // modify rateconstant for Monod-type reactions and isotope fractionation for (int j = 0; j < m_krd->NumberReactions; j++) @@ -1141,29 +1169,27 @@ void KRConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) if (m_krd->NumberMonod > 0) for (size_t j = 0; j < mmp_vector.size(); j++) if (mmp_vector[j]->vol_bio < MKleinsteZahl) - std::cout << - "Warning: Porosity of bio-phase is 0.0 ! Change Settings in *.mmp file " + std::cout << "Warning: Porosity of bio-phase is 0.0 ! Change Settings in *.mmp file " << "\n"; //#ds k= m_krd->NumberLinear + m_krd->NumberFreundlich + m_krd->NumberLangmuir; - int k = m_krd->NumberLinear + m_krd->NumberFreundlich - + m_krd->NumberLangmuir + m_krd->NumberNAPLdissolution; + int k = m_krd->NumberLinear + m_krd->NumberFreundlich + m_krd->NumberLangmuir + m_krd->NumberNAPLdissolution; if (k > 0) for (size_t j = 0; j < mmp_vector.size(); j++) if (mmp_vector[j]->vol_mat < MKleinsteZahl) - std::cout << - "Warning: Porosity of solid phase is 0.0 ! Change Settings in *.mmp file " + std::cout << "Warning: Porosity of solid phase is 0.0 ! Change Settings in *.mmp file " << "\n"; /********************************************************/ - //Set up vector is_a_CCBC - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt + // Set up vector is_a_CCBC + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt if (m_msh == NULL) { - cout << "No mesh in KRConfig" << "\n"; + cout << "No mesh in KRConfig" + << "\n"; exit(1); } - const size_t mesh_node_vector_size (m_msh->nod_vector.size()); + const size_t mesh_node_vector_size(m_msh->nod_vector.size()); // Initialize vector is_a_CCBC for (size_t l = 0; l < mesh_node_vector_size; l++) m_krd->is_a_CCBC.push_back(false); @@ -1171,77 +1197,74 @@ void KRConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) std::string s_geo_name, s_geo_type; size_t s_geo_id; - // 1) AllowReactions: This allows reactions only on specific geometries - - // First, set all nodes in vector is_a_CCBC inactive, if $ALLOW_REACTIONS was set - if(m_krd->AllowReactGeoName.size()>0) - for (size_t l = 0; l < m_msh->nod_vector.size(); l++) - m_krd->is_a_CCBC[l]=true; - - // then, activate the nodes on geometries allowed for reactions - for (size_t j = 0; j < m_krd->AllowReactGeoName.size(); j++) - { - s_geo_name = m_krd->AllowReactGeoName[j]; - s_geo_type = m_krd->AllowReactGeoType[j]; - s_geo_id = m_krd->AllowReactGeoID[j]; - //------------------------------------------------------------------ - if (s_geo_type.compare("POINT") == 0) - { - const std::vector* pnt_vec (geo_obj.getPointVec(unique_name)); - lm = m_msh->GetNODOnPNT ((*pnt_vec)[m_krd->AllowReactGeoID[j]]); - m_krd->is_a_CCBC[lm] = false; - } - //------------------------------------------------------------------ - if (s_geo_type.compare("POLYLINE") == 0) - { - - //CGLPolyline *ply (polyline_vector[s_geo_id]); - std::vector const* const ply_vec( - geo_obj.getPolylineVec(unique_name)); - GEOLIB::Polyline const* const ply( - (*ply_vec)[s_geo_id]); - if (ply) - { - //if (ply->getType() == 100) //WW - // m_msh->GetNodesOnArc(ply, nodes_vector); - //else - m_msh->GetNODOnPLY(ply, nodes_vector); - for (size_t i = 0; i < nodes_vector.size(); i++) - { - ll = nodes_vector[i]; - lm = ll; //+ShiftInNodeVector; - m_krd->is_a_CCBC[lm] = false; - } - } - } // if(POLYLINE) - //------------------------------------------------------------------ - if (s_geo_type.compare("SURFACE") == 0) - { - Surface *m_surface = NULL; - m_surface = GEOGetSFCByName(s_geo_name); - if (m_surface) - { - m_msh->GetNODOnSFC(m_surface, nodes_vector); //kg44 if used together with PETSC one maybe needs to set the for_ic flag...see rf_id_new.cpp - for (size_t i = 0; i < nodes_vector.size(); i++) - { - ll = nodes_vector[i]; - lm = ll; //+ShiftInNodeVector; - m_krd->is_a_CCBC[lm] = false; - } - } - } - } // end of for(j=0;jNoReactGeoName.size()... - //test output - /* cout << " Vector KinReactData::is_a_CCBC: " << "\n"; - for(l=0; l< (long)m_msh->nod_vector.size();l++) - if(m_krd->is_a_CCBC[l] == true) cout << l <<", "; - cout << "\n"; - */ - nodes_vector.clear(); - - - // 2) NoReactions, this suppresses reactions on specific geometries - // can be used in combination with 1) + // 1) AllowReactions: This allows reactions only on specific geometries + + // First, set all nodes in vector is_a_CCBC inactive, if $ALLOW_REACTIONS was set + if (m_krd->AllowReactGeoName.size() > 0) + for (size_t l = 0; l < m_msh->nod_vector.size(); l++) + m_krd->is_a_CCBC[l] = true; + + // then, activate the nodes on geometries allowed for reactions + for (size_t j = 0; j < m_krd->AllowReactGeoName.size(); j++) + { + s_geo_name = m_krd->AllowReactGeoName[j]; + s_geo_type = m_krd->AllowReactGeoType[j]; + s_geo_id = m_krd->AllowReactGeoID[j]; + //------------------------------------------------------------------ + if (s_geo_type.compare("POINT") == 0) + { + const std::vector* pnt_vec(geo_obj.getPointVec(unique_name)); + lm = m_msh->GetNODOnPNT((*pnt_vec)[m_krd->AllowReactGeoID[j]]); + m_krd->is_a_CCBC[lm] = false; + } + //------------------------------------------------------------------ + if (s_geo_type.compare("POLYLINE") == 0) + { + // CGLPolyline *ply (polyline_vector[s_geo_id]); + std::vector const* const ply_vec(geo_obj.getPolylineVec(unique_name)); + GEOLIB::Polyline const* const ply((*ply_vec)[s_geo_id]); + if (ply) + { + // if (ply->getType() == 100) //WW + // m_msh->GetNodesOnArc(ply, nodes_vector); + // else + m_msh->GetNODOnPLY(ply, nodes_vector); + for (size_t i = 0; i < nodes_vector.size(); i++) + { + ll = nodes_vector[i]; + lm = ll; //+ShiftInNodeVector; + m_krd->is_a_CCBC[lm] = false; + } + } + } // if(POLYLINE) + //------------------------------------------------------------------ + if (s_geo_type.compare("SURFACE") == 0) + { + Surface* m_surface = NULL; + m_surface = GEOGetSFCByName(s_geo_name); + if (m_surface) + { + m_msh->GetNODOnSFC(m_surface, nodes_vector); // kg44 if used together with PETSC one maybe needs to + // set the for_ic flag...see rf_id_new.cpp + for (size_t i = 0; i < nodes_vector.size(); i++) + { + ll = nodes_vector[i]; + lm = ll; //+ShiftInNodeVector; + m_krd->is_a_CCBC[lm] = false; + } + } + } + } // end of for(j=0;jNoReactGeoName.size()... + // test output + /* cout << " Vector KinReactData::is_a_CCBC: " << "\n"; + for(l=0; l< (long)m_msh->nod_vector.size();l++) + if(m_krd->is_a_CCBC[l] == true) cout << l <<", "; + cout << "\n"; + */ + nodes_vector.clear(); + + // 2) NoReactions, this suppresses reactions on specific geometries + // can be used in combination with 1) for (size_t j = 0; j < m_krd->NoReactGeoName.size(); j++) { s_geo_name = m_krd->NoReactGeoName[j]; @@ -1250,39 +1273,35 @@ void KRConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) //------------------------------------------------------------------ if (s_geo_type.compare("POINT") == 0) { - const std::vector* pnt_vec(geo_obj.getPointVec( - unique_name)); + const std::vector* pnt_vec(geo_obj.getPointVec(unique_name)); if (pnt_vec) - m_krd->is_a_CCBC[m_msh->GetNODOnPNT((*pnt_vec)[m_krd-> - NoReactGeoID - [j]])] = - true; + m_krd->is_a_CCBC[m_msh->GetNODOnPNT((*pnt_vec)[m_krd->NoReactGeoID[j]])] = true; } //------------------------------------------------------------------ if (s_geo_type.compare("POLYLINE") == 0) { CGLPolyline* ply(polyline_vector[s_geo_id]); - std::vector const* const ply_vec( - geo_obj.getPolylineVec(unique_name)); + std::vector const* const ply_vec(geo_obj.getPolylineVec(unique_name)); GEOLIB::Polyline const* const polyline((*ply_vec)[s_geo_id]); double msh_min_edge_length(m_msh->getMinEdgeLength()); m_msh->setMinEdgeLength(ply->epsilon); m_msh->GetNODOnPLY(polyline, nodes_vector); m_msh->setMinEdgeLength(msh_min_edge_length); for (size_t i = 0; i < nodes_vector.size(); i++) -// m_krd->is_a_CCBC[nodes_vector[i]+ShiftInNodeVector] = true; + // m_krd->is_a_CCBC[nodes_vector[i]+ShiftInNodeVector] = true; m_krd->is_a_CCBC[nodes_vector[i]] = true; - nodes_vector.clear(); + nodes_vector.clear(); } // if(POLYLINE) - //------------------------------------------------------------------ + //------------------------------------------------------------------ if (s_geo_type.compare("SURFACE") == 0) { Surface* m_surface = NULL; m_surface = GEOGetSFCByName(s_geo_name); if (m_surface) { - m_msh->GetNODOnSFC(m_surface, nodes_vector); //kg44 if used together with PETSC one maybe needs to set the for_ic flag...see rf_id_new.cpp + m_msh->GetNODOnSFC(m_surface, nodes_vector); // kg44 if used together with PETSC one maybe needs to + // set the for_ic flag...see rf_id_new.cpp for (size_t i = 0; i < nodes_vector.size(); i++) { long ll = nodes_vector[i]; //+ShiftInNodeVector; @@ -1291,20 +1310,21 @@ void KRConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) } } } // end of for(j=0;jNoReactGeoName.size()... - //test output - /* cout << " Vector KinReactData::is_a_CCBC: " << "\n"; - for(l=0; l< (long)m_msh->nod_vector.size();l++) - if(m_krd->is_a_CCBC[l] == true) cout << l <<", "; - cout << "\n"; - */ + // test output + /* cout << " Vector KinReactData::is_a_CCBC: " << "\n"; + for(l=0; l< (long)m_msh->nod_vector.size();l++) + if(m_krd->is_a_CCBC[l] == true) cout << l <<", "; + cout << "\n"; + */ nodes_vector.clear(); /********************************************************/ - //Set up vectors switched_off_node for individual reactions - m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt + // Set up vectors switched_off_node for individual reactions + m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt if (m_msh == NULL) { - std::cout << "No mesh in KRConfig" << "\n"; + std::cout << "No mesh in KRConfig" + << "\n"; exit(1); } // for all reactions @@ -1325,22 +1345,14 @@ void KRConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) //------------------------------------------------------------------ if (s_geo_type.compare("POINT") == 0) { - const std::vector* pnt_vec( - geo_obj.getPointVec(unique_name)); - m_kr->switched_off_node[m_msh->GetNODOnPNT((* - pnt_vec) - [m_kr-> - NotThisReactGeoID - [j]])] - = true; + const std::vector* pnt_vec(geo_obj.getPointVec(unique_name)); + m_kr->switched_off_node[m_msh->GetNODOnPNT((*pnt_vec)[m_kr->NotThisReactGeoID[j]])] = true; } //------------------------------------------------------------------ if (s_geo_type.compare("POLYLINE") == 0) { - std::vector const* const ply_vec( - geo_obj.getPolylineVec(unique_name)); - GEOLIB::Polyline const* const polyline( - (*ply_vec)[s_geo_id]); + std::vector const* const ply_vec(geo_obj.getPolylineVec(unique_name)); + GEOLIB::Polyline const* const polyline((*ply_vec)[s_geo_id]); m_msh->GetNODOnPLY(polyline, nodes_vector); for (size_t i = 0; i < nodes_vector.size(); i++) { @@ -1355,9 +1367,10 @@ void KRConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) m_surface = GEOGetSFCByName(s_geo_name); if (m_surface) { - m_msh->GetNODOnSFC(m_surface, nodes_vector); //kg44 if used together with PETSC one maybe needs to set the for_ic flag...see rf_id_new.cpp - for (size_t i = 0; i < nodes_vector.size(); - i++) + m_msh->GetNODOnSFC(m_surface, nodes_vector); // kg44 if used together with PETSC one maybe + // needs to set the for_ic flag...see + // rf_id_new.cpp + for (size_t i = 0; i < nodes_vector.size(); i++) { long ll = nodes_vector[i]; //+ShiftInNodeVector; m_kr->switched_off_node[ll] = true; @@ -1365,13 +1378,13 @@ void KRConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) } } //------------------------------------------------------------------ - } //loop over j NotThisReactGeoName elements + } // loop over j NotThisReactGeoName elements nodes_vector.clear(); } // if NotThisReactGeoName.size > 0 } // loop over k nreactions /********************************************************/ - //Get foc average of connected elements + // Get foc average of connected elements MeshLib::CNode* m_nod = NULL; MeshLib::CElem* m_ele = NULL; for (size_t l = 0; l < mesh_node_vector_size; l++) @@ -1379,8 +1392,8 @@ void KRConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) for (size_t l = 0; l < mesh_node_vector_size; l++) { m_nod = m_msh->nod_vector[l]; - double ww (0.0); - double w (0.0); + double ww(0.0); + double w(0.0); for (size_t i = 0; i < m_nod->getConnectedElementIDs().size(); i++) { m_ele = m_msh->ele_vector[m_nod->getConnectedElementIDs()[i]]; @@ -1388,11 +1401,11 @@ void KRConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) ww += m_mat_mp->foc * m_ele->GetVolume(); w += m_ele->GetVolume(); } - double foc (ww / w); + double foc(ww / w); //// CB Brand project - //if(foc>0.1) + // if(foc>0.1) // foc = 1; - //else + // else // foc = 1e-100; m_krd->node_foc[l] = foc; } @@ -1413,11 +1426,9 @@ void KRConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) m_krd->React_dCdT.push_back(0); m_nod = m_msh->nod_vector[l]; // get current node object - // loop over PRIMARY NEIGHBOR elements // this routine takes longer, but gets all the nodes - for (size_t ll = 0; ll < m_nod->getConnectedElementIDs().size(); - ll++) + for (size_t ll = 0; ll < m_nod->getConnectedElementIDs().size(); ll++) { // get index of direct neighbour element size_t dnele_idx = m_nod->getConnectedElementIDs()[ll]; @@ -1435,45 +1446,34 @@ void KRConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) // get the node object m_dnnod = m_msh->nod_vector[pneighnod_idx]; // loop over the connected elements, this now includes the SECONDARY NEIGHBORS - for (size_t llll = 0; - llll < m_dnnod->getConnectedElementIDs().size(); - llll++) + for (size_t llll = 0; llll < m_dnnod->getConnectedElementIDs().size(); llll++) { // get the current connected element indices - size_t snele_idx = - m_dnnod->getConnectedElementIDs()[ - llll]; + size_t snele_idx = m_dnnod->getConnectedElementIDs()[llll]; // get secondary neighbour element object m_snele = m_msh->ele_vector[snele_idx]; // get the neighbor element node indices m_snele->GetNodeIndeces(secnnodesindices); // get the neighbor element number of nodes - int nnodsneigh = m_snele->GetNodesNumber( - false); + int nnodsneigh = m_snele->GetNodesNumber(false); // loop over secondary neighbour element number of nodes - for (int lllll = 0; lllll < nnodsneigh; - lllll++) + for (int lllll = 0; lllll < nnodsneigh; lllll++) { - bool duplicate (false); // flag, initialize - int annode_idx = - secnnodesindices[lllll]; + bool duplicate(false); // flag, initialize + int annode_idx = secnnodesindices[lllll]; // check vs. all previously identified nodes to prevent duplicate entries - for (size_t nn = 0; - nn < ReactNeighborNodes.size(); - nn++) + for (size_t nn = 0; nn < ReactNeighborNodes.size(); nn++) // node has already been found - if (annode_idx == - ReactNeighborNodes[nn]) + if (annode_idx == ReactNeighborNodes[nn]) { duplicate = true; // set flag to "not fresh" break; // skip rest of comparisons } if (!duplicate) // fresh node // push back node index - ReactNeighborNodes. - push_back(annode_idx); + ReactNeighborNodes.push_back(annode_idx); else - duplicate = false; // was no fresh node, reinitialize flag + duplicate = false; // was no fresh node, reinitialize flag } } } @@ -1484,40 +1484,38 @@ void KRConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) ReactNeighborNodes.clear(); } // debug - //for (nn=0;nnReactNeighborhood.size();nn++){ + // for (nn=0;nnReactNeighborhood.size();nn++){ // cout << nn << " " << m_krd->ReactNeighborhood[nn].size() << " " ; // for (ll=0;llReactNeighborhood[nn].size();ll++) // cout << m_krd->ReactNeighborhood[nn][ll] << " " ; // cout << "\n"; //} - m_krd->concentrationmatrix = (double**) malloc( - ((long) mesh_node_vector_size) * sizeof(double*)); + m_krd->concentrationmatrix = (double**)malloc(((long)mesh_node_vector_size) * sizeof(double*)); for (size_t ix = 0; ix < mesh_node_vector_size; ix++) - m_krd->concentrationmatrix[ix] = - (double*) malloc((length) * sizeof(double)); + m_krd->concentrationmatrix[ix] = (double*)malloc((length) * sizeof(double)); for (size_t ix = 0; ix < mesh_node_vector_size; ix++) for (size_t ixx = 0; ixx < length; ixx++) m_krd->concentrationmatrix[ix][ixx] = 0; - } // if (m_krd->ReactDeactFlag) - - /********************************************************/ - if (m_krd->debugoutflag) - { - m_krd->debugoutfilename = FileName + "_KR_Debug_out.txt"; - m_krd->c_dumpfilename = FileName +"_KR_C_dump.txt"; - } - /********************************************************/ - if (m_krd->sortnodes) - { - m_krd->substeps = new long[(long) m_msh->nod_vector.size()]; - m_krd->noderanks = new long[(long) m_msh->nod_vector.size()]; - for (long ix = 0; ix < ((long) m_msh->nod_vector.size()); ix++){ - m_krd->noderanks[ix]= ix; - m_krd->substeps[ix] = 0; - } - - } - /********************************************************/ + } // if (m_krd->ReactDeactFlag) + + /********************************************************/ + if (m_krd->debugoutflag) + { + m_krd->debugoutfilename = FileName + "_KR_Debug_out.txt"; + m_krd->c_dumpfilename = FileName + "_KR_C_dump.txt"; + } + /********************************************************/ + if (m_krd->sortnodes) + { + m_krd->substeps = new long[(long)m_msh->nod_vector.size()]; + m_krd->noderanks = new long[(long)m_msh->nod_vector.size()]; + for (long ix = 0; ix < ((long)m_msh->nod_vector.size()); ix++) + { + m_krd->noderanks[ix] = ix; + m_krd->substeps[ix] = 0; + } + } + /********************************************************/ } // if KinReactData_vector.size() > 0 } @@ -1531,7 +1529,7 @@ void KRConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) void KRCDelete(void) { long i; - int no_krc = (int) KinReact_vector.size(); + int no_krc = (int)KinReact_vector.size(); for (i = 0; i < no_krc; i++) delete KinReact_vector[i]; KinReact_vector.clear(); @@ -1545,16 +1543,14 @@ void KRCDelete(void) 02/2006 SB New Class structure, IO, C++, FEM 06/2010 TF formated, removed unused variables, changed signature for new GEOLIB data structures **************************************************************************/ -bool CKinReact::Read(std::ifstream* rfd_file, - const GEOLIB::GEOObjects& geo_obj, - const std::string& unique_name) +bool CKinReact::Read(std::ifstream* rfd_file, const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) { char line[MAX_ZEILE]; std::string line_string, line_str1; bool new_keyword = false, new_subkeyword = false; std::stringstream in; - MonodSubstruct* m_monod = NULL, * m_inhibit = NULL, * m_production = NULL; - //MicrobeData* m_microbe = NULL; + MonodSubstruct *m_monod = NULL, *m_inhibit = NULL, *m_production = NULL; + // MicrobeData* m_microbe = NULL; size_t index, index1; double dval; // CB 10/09 @@ -1563,20 +1559,20 @@ bool CKinReact::Read(std::ifstream* rfd_file, double thresh_conc, thresh_ord; bool found = false; int i; - double dummy = 0; - //clear vectors + double dummy = 0; + // clear vectors monod.clear(); inhibit.clear(); production.clear(); reactionpartner.clear(); stochmet.clear(); - T_params.clear(); - mechvec.clear(); //CB minkin - minSpeciesIdx.clear(); //CB minkin - MinkinMech* m_mech=NULL; - double expo = -99; - string speciesname = "Nix"; - string dummystring; + T_params.clear(); + mechvec.clear(); // CB minkin + minSpeciesIdx.clear(); // CB minkin + MinkinMech* m_mech = NULL; + double expo = -99; + string speciesname = "Nix"; + string dummystring; while (!new_keyword) { @@ -1587,7 +1583,7 @@ bool CKinReact::Read(std::ifstream* rfd_file, if (line_string.find("#") != string::npos) { new_keyword = true; - rfd_file->seekg(index); //Dateipointer zur�cksetzen, sonst ist das n�chste keyword weg + rfd_file->seekg(index); // Dateipointer zur�cksetzen, sonst ist das n�chste keyword weg break; } /* Keywords nacheinander durchsuchen */ @@ -1646,22 +1642,18 @@ bool CKinReact::Read(std::ifstream* rfd_file, index1 = rfd_file->tellg(); line_str1 = GetLineFromFile1(rfd_file); // Check for end of data block - if ((line_str1.find("#") != string::npos) || (line_str1.find( - "$") != - string::npos)) + if ((line_str1.find("#") != string::npos) || (line_str1.find("$") != string::npos)) { if (line_str1.find("#") != string::npos) new_keyword = true; - rfd_file->seekg(index1); //Dateipointer zur�cksetzen, sonst ist das n�chste subkeyword weg + rfd_file->seekg(index1); // Dateipointer zur�cksetzen, sonst ist das n�chste subkeyword weg break; } m_monod = new MonodSubstruct(); number_monod++; in.str(line_str1); - in >> m_monod->species >> m_monod->concentration - >> m_monod->order; - if ((m_monod->order != -99.0) && (m_monod->concentration - != -1.0e9)) //check for read in + in >> m_monod->species >> m_monod->concentration >> m_monod->order; + if ((m_monod->order != -99.0) && (m_monod->concentration != -1.0e9)) // check for read in monod.push_back(m_monod); else { @@ -1679,18 +1671,16 @@ bool CKinReact::Read(std::ifstream* rfd_file, index1 = rfd_file->tellg(); line_str1 = GetLineFromFile1(rfd_file); // Check for end of data block - if ((line_str1.find("#") != string::npos) || (line_str1.find( - "$") != - string::npos)) + if ((line_str1.find("#") != string::npos) || (line_str1.find("$") != string::npos)) { if (line_str1.find("#") != string::npos) new_keyword = true; - rfd_file->seekg(index1); //Dateipointer zur�cksetzen, sonst ist das n�chste subkeyword weg + rfd_file->seekg(index1); // Dateipointer zur�cksetzen, sonst ist das n�chste subkeyword weg break; } in.str(line_str1); in >> thresh_species >> thresh_conc >> thresh_ord; - //check for read in + // check for read in if ((thresh_ord != -99.0) && (thresh_conc != -1.0e9)) { found = false; @@ -1706,11 +1696,8 @@ bool CKinReact::Read(std::ifstream* rfd_file, } if (found == false) { - cout - << - " WARNING: no matching MONOD SPECIES found in reaction "; - cout << name << " for THRESHHOLD TERM SPECIES " - << thresh_species << "\n"; + cout << " WARNING: no matching MONOD SPECIES found in reaction "; + cout << name << " for THRESHHOLD TERM SPECIES " << thresh_species << "\n"; } } else @@ -1725,13 +1712,11 @@ bool CKinReact::Read(std::ifstream* rfd_file, index1 = rfd_file->tellg(); line_str1 = GetLineFromFile1(rfd_file); // Check for end of data block - if ((line_str1.find("#") != string::npos) || (line_str1.find( - "$") != - string::npos)) + if ((line_str1.find("#") != string::npos) || (line_str1.find("$") != string::npos)) { if (line_str1.find("#") != string::npos) new_keyword = true; - rfd_file->seekg(index1); //Dateipointer zur�cksetzen, sonst ist das n�chste subkeyword weg + rfd_file->seekg(index1); // Dateipointer zur�cksetzen, sonst ist das n�chste subkeyword weg break; } in.str(line_str1); @@ -1740,12 +1725,11 @@ bool CKinReact::Read(std::ifstream* rfd_file, in >> m_inhibit->species; in >> m_inhibit->concentration; in >> m_inhibit->order; - if ((m_inhibit->order != -99.0) && - (m_inhibit->concentration != -1.0e9)) //check for read in + if ((m_inhibit->order != -99.0) && (m_inhibit->concentration != -1.0e9)) // check for read in inhibit.push_back(m_inhibit); else { - delete m_inhibit; // CB_merge_0513 ?? + delete m_inhibit; // CB_merge_0513 ?? DisplayMsgLn(" ERROR reading Inhibition Terms - skipping"); number_inhibit--; } @@ -1760,22 +1744,19 @@ bool CKinReact::Read(std::ifstream* rfd_file, index1 = rfd_file->tellg(); line_str1 = GetLineFromFile1(rfd_file); // Check for end of data block - if ((line_str1.find("#") != string::npos) || (line_str1.find( - "$") != - string::npos)) + if ((line_str1.find("#") != string::npos) || (line_str1.find("$") != string::npos)) { if (line_str1.find("#") != string::npos) new_keyword = true; - rfd_file->seekg(index1); //Dateipointer zur�cksetzen, sonst ist das n�chste subkeyword weg + rfd_file->seekg(index1); // Dateipointer zur�cksetzen, sonst ist das n�chste subkeyword weg break; } in.str(line_str1); m_production = new MonodSubstruct(); number_production++; - in >> m_production->species >> m_production->concentration - >> m_production->order; + in >> m_production->species >> m_production->concentration >> m_production->order; if ((m_production->order != -99.0) - //check for read in + // check for read in && (m_production->concentration != -1.0e9)) production.push_back(m_production); else @@ -1794,13 +1775,11 @@ bool CKinReact::Read(std::ifstream* rfd_file, index1 = rfd_file->tellg(); line_str1 = GetLineFromFile1(rfd_file); // Check for end of data block - if ((line_str1.find("#") != string::npos) || (line_str1.find( - "$") != - string::npos)) + if ((line_str1.find("#") != string::npos) || (line_str1.find("$") != string::npos)) { if (line_str1.find("#") != string::npos) new_subkeyword = true; - rfd_file->seekg(index1); //Dateipointer zur�cksetzen, sonst ist das n�chste subkeyword weg + rfd_file->seekg(index1); // Dateipointer zur�cksetzen, sonst ist das n�chste subkeyword weg break; } in.str(line_str1); @@ -1810,12 +1789,13 @@ bool CKinReact::Read(std::ifstream* rfd_file, in.clear(); } //.................................................................... - if(line_string.find("$BACTERIAL_YIELD")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> Yieldcoefficient ; - in.clear(); - } - //.................................................................... + if (line_string.find("$BACTERIAL_YIELD") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> Yieldcoefficient; + in.clear(); + } + //.................................................................... // CB Iso routine for reading in the isotope couples // subkeyword found if (line_string.find("$ISOTOPE_FRACTIONATION") != string::npos) @@ -1827,106 +1807,130 @@ bool CKinReact::Read(std::ifstream* rfd_file, degType = "isotope_fractionation"; // CB besser in KRConfig?? } //.................................................................... - if(line_string.find("$BACTERIA_SPECIFIC_CAPACITY")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> specif_cap ; - in.clear(); - } - //.................................................................... - if(line_string.find("$TEMPERATURE_DEPENDENCE")!=string::npos) { // subkeyword found - T_dependence = true; - in.str(GetLineFromFile1(rfd_file)); - in >> T_model ; - // - if(T_model == 0){ - T_dependence = false; - cout << " Warning - Model 0: Reaction assumed independent of Temperature. " << "\n"; - } - else if((T_model == 1) || (T_model == 2)){ - if(type.compare("monod")==0) { - if(T_model == 1) { // Biomass growth, Ratkowsky2 : Zwietering et al. - in >> dummy ; // Ratkowsky Tmin - T_params.push_back(dummy); - in >> dummy ; // Ratkowsky Tmax - T_params.push_back(dummy); - in >> dummy ; // Ratkowsky b - T_params.push_back(dummy); - in >> dummy ; // Ratkowsky c - T_params.push_back(dummy); - } - else if(T_model == 2){ - cout << " Unknown model for Temperature Dependence of Reaction " << name << " in CKinReact::Read(). " << "\n" ; - cout << " Aborting now!" << "\n"; - exit(0); - } - } - else if(type.compare("NAPLdissolution")==0) { // NAPL dissolution, Chen et al (1) or Knauss et al (2) model - in >> dummy ; // Knauss A - T_params.push_back(dummy); - in >> dummy ; // Knauss B - T_params.push_back(dummy); - in >> dummy ; // Knauss C - T_params.push_back(dummy); - } - else if(type.compare("Mineralkinetics")==0) { - cout << " Warning in CKinReact::Read() - Arrhenius-Equation is used for Temperature correction of Mineral Reaction " << name << "\n" ; - cout << " Input values for $TEMPERATURE_DEPENDENCE keyword will be ignored. " << "\n"; - } - else { - cout << " Warning in CKinReact::Read() - Temperature correction of " << type << " Reaction " << name << " is not implemented. " << "\n" ; - cout << " Input values for $TEMPERATURE_DEPENDENCE keyword will be ignored. " << "\n"; - } - } - else{ - cout << " Unknown model for Temperature Dependence of Reaction " << name << " in CKinReact::Read(). " << "\n" ; - cout << " Aborting now!" << "\n"; - exit(0); - } - - in.clear(); - } - //.................................................................... - // subkeyword found - if (line_string.find("$_drmc_") != string::npos) - { - _drmc_= true; - in.str(GetLineFromFile1(rfd_file)); - in >> Microbename >> DormType; - in.clear(); - } - //.................................................................... - // subkeyword found - if(line_string.find("$STANDARD_GIBBS_ENERGY")!=string::npos) { - in.str(GetLineFromFile1(rfd_file)); - in >> dG0 ; - in.clear(); - } - - //.................................................................... - // subkeyword found - if (line_string.find("$EXCHANGE_PARAMETERS") != string::npos) - { + if (line_string.find("$BACTERIA_SPECIFIC_CAPACITY") != string::npos) + { // subkeyword found in.str(GetLineFromFile1(rfd_file)); - in >> dval; // velocity - ex_param.push_back(dval); - in >> dval; //kd - ex_param.push_back(dval); - if (exType.compare("langmuir") == 0) - in >> exSurfaceID; - if (exType.compare("freundlich") == 0) - { - in >> dval; - ex_param.push_back(dval); - dval = 1; - in >> dval; - ex_param.push_back(dval); - } - if (exType.compare("linear") == 0) - { - dval = 1; - in >> dval; - ex_param.push_back(dval); - } + in >> specif_cap; + in.clear(); + } + //.................................................................... + if (line_string.find("$TEMPERATURE_DEPENDENCE") != string::npos) + { // subkeyword found + T_dependence = true; + in.str(GetLineFromFile1(rfd_file)); + in >> T_model; + // + if (T_model == 0) + { + T_dependence = false; + cout << " Warning - Model 0: Reaction assumed independent of Temperature. " + << "\n"; + } + else if ((T_model == 1) || (T_model == 2)) + { + if (type.compare("monod") == 0) + { + if (T_model == 1) + { // Biomass growth, Ratkowsky2 : Zwietering et al. + in >> dummy; // Ratkowsky Tmin + T_params.push_back(dummy); + in >> dummy; // Ratkowsky Tmax + T_params.push_back(dummy); + in >> dummy; // Ratkowsky b + T_params.push_back(dummy); + in >> dummy; // Ratkowsky c + T_params.push_back(dummy); + } + else if (T_model == 2) + { + cout << " Unknown model for Temperature Dependence of Reaction " << name + << " in CKinReact::Read(). " + << "\n"; + cout << " Aborting now!" + << "\n"; + exit(0); + } + } + else if (type.compare("NAPLdissolution") == 0) + { // NAPL dissolution, Chen et al (1) or Knauss et al (2) model + in >> dummy; // Knauss A + T_params.push_back(dummy); + in >> dummy; // Knauss B + T_params.push_back(dummy); + in >> dummy; // Knauss C + T_params.push_back(dummy); + } + else if (type.compare("Mineralkinetics") == 0) + { + cout << " Warning in CKinReact::Read() - Arrhenius-Equation is used for Temperature correction of " + "Mineral Reaction " + << name << "\n"; + cout << " Input values for $TEMPERATURE_DEPENDENCE keyword will be ignored. " + << "\n"; + } + else + { + cout << " Warning in CKinReact::Read() - Temperature correction of " << type << " Reaction " << name + << " is not implemented. " + << "\n"; + cout << " Input values for $TEMPERATURE_DEPENDENCE keyword will be ignored. " + << "\n"; + } + } + else + { + cout << " Unknown model for Temperature Dependence of Reaction " << name << " in CKinReact::Read(). " + << "\n"; + cout << " Aborting now!" + << "\n"; + exit(0); + } + + in.clear(); + } + //.................................................................... + // subkeyword found + if (line_string.find("$_drmc_") != string::npos) + { + _drmc_ = true; + in.str(GetLineFromFile1(rfd_file)); + in >> Microbename >> DormType; + in.clear(); + } + //.................................................................... + // subkeyword found + if (line_string.find("$STANDARD_GIBBS_ENERGY") != string::npos) + { + in.str(GetLineFromFile1(rfd_file)); + in >> dG0; + in.clear(); + } + + //.................................................................... + // subkeyword found + if (line_string.find("$EXCHANGE_PARAMETERS") != string::npos) + { + in.str(GetLineFromFile1(rfd_file)); + in >> dval; // velocity + ex_param.push_back(dval); + in >> dval; // kd + ex_param.push_back(dval); + if (exType.compare("langmuir") == 0) + in >> exSurfaceID; + if (exType.compare("freundlich") == 0) + { + in >> dval; + ex_param.push_back(dval); + dval = 1; + in >> dval; + ex_param.push_back(dval); + } + if (exType.compare("linear") == 0) + { + dval = 1; + in >> dval; + ex_param.push_back(dval); + } in.clear(); } @@ -1939,167 +1943,186 @@ bool CKinReact::Read(std::ifstream* rfd_file, in.clear(); } - //.................................................................... - // subkeyword found - if (line_string.find("$NAPL_PROPERTIES") != string::npos) - { - in.str(GetLineFromFile1(rfd_file)); - in >> blob_name ; // >> Csat_pure >> Density_NAPL; - in.clear(); - } - //.................................................................... - // subkeyword found - if (line_string.find("$REACTION_ORDER") != string::npos) - { - in.str(GetLineFromFile1(rfd_file)); - in >> rateorder ; // CB rateorder added 06/2012 - in.clear(); - } - //.................................................................... - if(line_string.find("$MINERALNAME")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> mineral_name; - in.clear(); - } - if(line_string.find("$CHEMAPPNAME")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> chemapp_name; - in.clear(); - } - if(line_string.find("$EQUILIBRIUM_CONSTANT")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> dummystring >> Km_default; - if(dummystring.compare("UNIFORM")==0){ - Km_uniform = true; - Km_CHEMAPP = false; - Km_HKF = false; - } - else if(dummystring.compare("CHEMAPP")==0){ - Km_uniform = false; - Km_CHEMAPP = true; - Km_HKF = false; - } - else if(dummystring.compare("HKF")==0){ - Km_uniform = false; - Km_CHEMAPP = false; - Km_HKF = true; - } - else - cout << " Warning in CKinReact::Read - No valid model for Mineralkinetics equilibrium constant Km." << "\n"; - // anyway, pushback the input value - Km.push_back(pow(10, Km_default)); - in.clear(); - } - //.................................................................... - if(line_string.find("$RATE_EXPONENTS")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> Theta >> Eta ; - in.clear(); - } - //.................................................................... - if(line_string.find("$REACTIVE_SURFACE_AREA")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> Am_model >> Am_ini; - if(Am_model==0){ - Am_constant = true; - } - else if (Am_model <= 5){ - Am_constant = false; - } - else - cout << " Warning in CKinReact::Read - No valid model for Mineralkinetics reactive surface area Am." << "\n"; - // anyway, pushback the input value - Am.push_back(Am_ini); - in.clear(); - } - //.................................................................... - if(line_string.find("$PRECIPITATION_BY_BASETERM_ONLY")!=string::npos) { // subkeyword found - precip_baseterm_only = true; - } - //.................................................................... - if(line_string.find("$PRECIPITATION_FACTOR")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> this->precipfactor; - in.clear(); - } - //.................................................................... - if(line_string.find("$PRECIPITATION_EXPONENT")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> this->precipexponent; - in.clear(); - } - //.................................................................... - if(line_string.find("$BASETERM")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - m_mech = new MinkinMech(); - number_Mech++; - in >> m_mech->k25 >> m_mech->Eact; - in.clear(); - //convert log(k25) --> k25 - m_mech->k25 = pow(10, m_mech->k25); - mechvec.push_back(m_mech); - } - //.................................................................... - if(line_string.find("$MECHANISMTERM")!=string::npos) { // subkeyword found - // before reading in k mechanistic species, store ratteconstant and Eact - m_mech = new MinkinMech(); - number_Mech++; - in.str(GetLineFromFile1(rfd_file)); - in >> m_mech->k25 >> m_mech->Eact; - in.clear(); - //convert log(k25) --> k25 - m_mech->k25 = pow(10, m_mech->k25); - if((m_mech->k25!=0)/*&&(m_mech->Eact != 0)*/){ //check for read in - // now read mechanistic species - while(!new_subkeyword){ - index1 = rfd_file->tellg(); - line_str1 = GetLineFromFile1(rfd_file); - // Check for end of data block - if((line_str1.find("#")!=string::npos) || (line_str1.find("$")!=string::npos)) { - if(line_str1.find("#")!=string::npos) - new_keyword = true; - rfd_file->seekg(index1); //Dateipointer zurücksetzen, sonst ist das nächste subkeyword weg - break; - } - // Here, read individual species data - in.str(line_str1); - in >> speciesname >> expo; - if((speciesname.compare("NIX")!=0)&&(expo != -99)){ //check for read in - m_mech->no_mechSpec++; - m_mech->mechSpeciesNames.push_back(speciesname); - m_mech->mechSpeciesExpo.push_back(expo); - expo = -99; - speciesname = "NIX"; - } - else - DisplayMsgLn(" ERROR reading Mechanism Species - skipping"); - in.clear(); - } - in.clear(); - mechvec.push_back(m_mech); - }// successfull read - else{ - DisplayMsgLn(" ERROR reading Mechanism Terms - skipping"); - number_Mech--; - delete m_mech; - } - - } - //.................................................................... - // subkeyword found + //.................................................................... + // subkeyword found + if (line_string.find("$NAPL_PROPERTIES") != string::npos) + { + in.str(GetLineFromFile1(rfd_file)); + in >> blob_name; // >> Csat_pure >> Density_NAPL; + in.clear(); + } + //.................................................................... + // subkeyword found + if (line_string.find("$REACTION_ORDER") != string::npos) + { + in.str(GetLineFromFile1(rfd_file)); + in >> rateorder; // CB rateorder added 06/2012 + in.clear(); + } + //.................................................................... + if (line_string.find("$MINERALNAME") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> mineral_name; + in.clear(); + } + if (line_string.find("$CHEMAPPNAME") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> chemapp_name; + in.clear(); + } + if (line_string.find("$EQUILIBRIUM_CONSTANT") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> dummystring >> Km_default; + if (dummystring.compare("UNIFORM") == 0) + { + Km_uniform = true; + Km_CHEMAPP = false; + Km_HKF = false; + } + else if (dummystring.compare("CHEMAPP") == 0) + { + Km_uniform = false; + Km_CHEMAPP = true; + Km_HKF = false; + } + else if (dummystring.compare("HKF") == 0) + { + Km_uniform = false; + Km_CHEMAPP = false; + Km_HKF = true; + } + else + cout << " Warning in CKinReact::Read - No valid model for Mineralkinetics equilibrium constant Km." + << "\n"; + // anyway, pushback the input value + Km.push_back(pow(10, Km_default)); + in.clear(); + } + //.................................................................... + if (line_string.find("$RATE_EXPONENTS") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> Theta >> Eta; + in.clear(); + } + //.................................................................... + if (line_string.find("$REACTIVE_SURFACE_AREA") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> Am_model >> Am_ini; + if (Am_model == 0) + { + Am_constant = true; + } + else if (Am_model <= 5) + { + Am_constant = false; + } + else + cout << " Warning in CKinReact::Read - No valid model for Mineralkinetics reactive surface area Am." + << "\n"; + // anyway, pushback the input value + Am.push_back(Am_ini); + in.clear(); + } + //.................................................................... + if (line_string.find("$PRECIPITATION_BY_BASETERM_ONLY") != string::npos) + { // subkeyword found + precip_baseterm_only = true; + } + //.................................................................... + if (line_string.find("$PRECIPITATION_FACTOR") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> this->precipfactor; + in.clear(); + } + //.................................................................... + if (line_string.find("$PRECIPITATION_EXPONENT") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> this->precipexponent; + in.clear(); + } + //.................................................................... + if (line_string.find("$BASETERM") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + m_mech = new MinkinMech(); + number_Mech++; + in >> m_mech->k25 >> m_mech->Eact; + in.clear(); + // convert log(k25) --> k25 + m_mech->k25 = pow(10, m_mech->k25); + mechvec.push_back(m_mech); + } + //.................................................................... + if (line_string.find("$MECHANISMTERM") != string::npos) + { // subkeyword found + // before reading in k mechanistic species, store ratteconstant and Eact + m_mech = new MinkinMech(); + number_Mech++; + in.str(GetLineFromFile1(rfd_file)); + in >> m_mech->k25 >> m_mech->Eact; + in.clear(); + // convert log(k25) --> k25 + m_mech->k25 = pow(10, m_mech->k25); + if ((m_mech->k25 != 0) /*&&(m_mech->Eact != 0)*/) + { // check for read in + // now read mechanistic species + while (!new_subkeyword) + { + index1 = rfd_file->tellg(); + line_str1 = GetLineFromFile1(rfd_file); + // Check for end of data block + if ((line_str1.find("#") != string::npos) || (line_str1.find("$") != string::npos)) + { + if (line_str1.find("#") != string::npos) + new_keyword = true; + rfd_file->seekg(index1); // Dateipointer zurücksetzen, sonst ist das nächste subkeyword weg + break; + } + // Here, read individual species data + in.str(line_str1); + in >> speciesname >> expo; + if ((speciesname.compare("NIX") != 0) && (expo != -99)) + { // check for read in + m_mech->no_mechSpec++; + m_mech->mechSpeciesNames.push_back(speciesname); + m_mech->mechSpeciesExpo.push_back(expo); + expo = -99; + speciesname = "NIX"; + } + else + DisplayMsgLn(" ERROR reading Mechanism Species - skipping"); + in.clear(); + } + in.clear(); + mechvec.push_back(m_mech); + } // successfull read + else + { + DisplayMsgLn(" ERROR reading Mechanism Terms - skipping"); + number_Mech--; + delete m_mech; + } + } + //.................................................................... + // subkeyword found if (line_string.find("$SWITCH_OFF_GEOMETRY") != string::npos) while (!new_subkeyword) { index1 = rfd_file->tellg(); line_str1 = GetLineFromFile1(rfd_file); // Check for end of data block - if ((line_str1.find("#") != string::npos) || (line_str1.find( - "$") != - string::npos)) + if ((line_str1.find("#") != string::npos) || (line_str1.find("$") != string::npos)) { if (line_str1.find("#") != string::npos) new_keyword = true; - rfd_file->seekg(index1); //Dateipointer zurueksetzen, sonst ist das naehste subkeyword weg + rfd_file->seekg(index1); // Dateipointer zurueksetzen, sonst ist das naehste subkeyword weg break; } in.str(line_str1); @@ -2110,26 +2133,18 @@ bool CKinReact::Read(std::ifstream* rfd_file, if (s_geo_type.find("POINT") != std::string::npos) // TF 06/2010 - get the point vector and set the geo_obj_idx - if (!((geo_obj.getPointVecObj(unique_name))-> - getElementIDByName( - s_geo_name, geo_obj_idx))) + if (!((geo_obj.getPointVecObj(unique_name))->getElementIDByName(s_geo_name, geo_obj_idx))) { - std::cerr - << - "error in CKinReact::Read: point name not found!" - << "\n"; + std::cerr << "error in CKinReact::Read: point name not found!" + << "\n"; exit(1); } if (s_geo_type.find("POLYLINE") != std::string::npos) // TF 07/2010 - get the polyline vector and set the geo_obj_idx - if (!((geo_obj.getPolylineVecObj(unique_name))-> - getElementIDByName( - s_geo_name, geo_obj_idx))) + if (!((geo_obj.getPolylineVecObj(unique_name))->getElementIDByName(s_geo_name, geo_obj_idx))) { - std::cerr - << - "error in CKinReact::Read: polyline name not found!" - << "\n"; + std::cerr << "error in CKinReact::Read: polyline name not found!" + << "\n"; exit(1); } NotThisReactGeoID.push_back(geo_obj_idx); @@ -2159,27 +2174,29 @@ int CKinReact::CheckReactionDataConsistency() // Check number of reaction partners if (number_reactionpartner < 2) { - //SB todo ok=0; - //SB todo cout << " Less than two reaction partners in equation found" << "\n"; + // SB todo ok=0; + // SB todo cout << " Less than two reaction partners in equation found" << "\n"; } // Ratekonstant zero? if ((fabs(rateconstant) < MKleinsteZahl) && (type.compare("monod") == 0)) { //#ds erstetzt statt: if((fabs(rateconstant) < MKleinsteZahl) && (type.compare("exchange")!=0) ){ ok = 0; - cout << " Rateconstant is zero" << "\n"; + cout << " Rateconstant is zero" + << "\n"; } // Number of partners higher than in arrays? - length = (int) reactionpartner.size(); //Muss so gemacht werden, weil sonst signed/unsigned warning kommt + length = (int)reactionpartner.size(); // Muss so gemacht werden, weil sonst signed/unsigned warning kommt if (number_reactionpartner != length) { ok = 0; - cout << " Not enough reaction partners" << "\n"; + cout << " Not enough reaction partners" + << "\n"; for (i = 0; i < length; i++) cout << reactionpartner[i] << " "; cout << "\n"; } - length = (int) stochmet.size(); + length = (int)stochmet.size(); if (stochmet.size() != reactionpartner.size()) { ok = 0; @@ -2194,52 +2211,53 @@ int CKinReact::CheckReactionDataConsistency() { if (type.compare("exchange") != 0) if (type.compare("NAPLdissolution") != 0) - if(type.compare("Mineralkinetics") != 0) { - ok = 0; - cout << "Unknown reaction type" << "\n"; - } + if (type.compare("Mineralkinetics") != 0) + { + ok = 0; + cout << "Unknown reaction type" + << "\n"; + } } /* Check Monod-, Inhibition and Production terms */ - length = (int) monod.size(); + length = (int)monod.size(); if (length < number_monod) - number_monod = (int) monod.size(); - length = (int) inhibit.size(); + number_monod = (int)monod.size(); + length = (int)inhibit.size(); if (length < number_inhibit) - number_inhibit = (int) inhibit.size(); - length = (int) production.size(); + number_inhibit = (int)inhibit.size(); + length = (int)production.size(); if (length < number_production) - number_production = (int) production.size(); + number_production = (int)production.size(); - if ((number_monod + number_inhibit + number_production == 0) && (type - == "monod")) + if ((number_monod + number_inhibit + number_production == 0) && (type == "monod")) { // cout << "Warning: no monod terms specified for monod equation "<< "\n"; } // Test concentrations and constants for > 0.0 - length = (int) monod.size(); + length = (int)monod.size(); for (i = 0; i < length; i++) if (monod[i]->concentration < MKleinsteZahl) { - cout << " Monod Concentration of reaction " << name - << " smaller than 0.0 " << "\n"; + cout << " Monod Concentration of reaction " << name << " smaller than 0.0 " + << "\n"; ok = 0; } - length = (int) inhibit.size(); + length = (int)inhibit.size(); for (i = 0; i < length; i++) if (inhibit[i]->concentration < MKleinsteZahl) { - cout << " Inhibition Concentration of reaction " << name - << " smaller than 0.0 " << "\n"; + cout << " Inhibition Concentration of reaction " << name << " smaller than 0.0 " + << "\n"; ok = 0; } //#ds check NAPL dissolution reactions if (type.compare("NAPLdissolution") == 0) { - //does blob-name exist? + // does blob-name exist? CKinBlob* m_kb = NULL; - for (i = 0; i < (int) KinBlob_vector.size(); i++) + for (i = 0; i < (int)KinBlob_vector.size(); i++) { m_kb = KinBlob_vector[i]; if (blob_name.compare(m_kb->name) == 0) @@ -2248,32 +2266,34 @@ int CKinReact::CheckReactionDataConsistency() if (found == false) { ok = 0; - cout << " Blob_Name " << blob_name << " defined in Reaction " - << name << " does not exist " << "\n"; + cout << " Blob_Name " << blob_name << " defined in Reaction " << name << " does not exist " + << "\n"; } // Csat_pure >= 0 - //if (Csat_pure < -MKleinsteZahl) - if (cp_vec[cp_name_2_idx[reactionpartner[0]]]->max_solubility < -MKleinsteZahl) + // if (Csat_pure < -MKleinsteZahl) + if (cp_vec[cp_name_2_idx[reactionpartner[0]]]->max_solubility < -MKleinsteZahl) { ok = 0; - cout << " Invalid maximum solubility Csat_pure: " << cp_vec[cp_name_2_idx[reactionpartner[0]]]->max_solubility /*Csat_pure*/ - << " in Reaction " << name << "\n"; + cout << " Invalid maximum solubility Csat_pure: " + << cp_vec[cp_name_2_idx[reactionpartner[0]]]->max_solubility /*Csat_pure*/ + << " in Reaction " << name << "\n"; } // Density_NAPL >0 - //if (Density_NAPL < MKleinsteZahl) - if (cp_vec[cp_name_2_idx[reactionpartner[0]]]->molar_density < MKleinsteZahl) + // if (Density_NAPL < MKleinsteZahl) + if (cp_vec[cp_name_2_idx[reactionpartner[0]]]->molar_density < MKleinsteZahl) { ok = 0; - cout << " Invalid NAPL density Density_NAPL: " << cp_vec[cp_name_2_idx[reactionpartner[0]]]->molar_density /*Density_NAPL*/ - << " in Reaction " << name << "\n"; + cout << " Invalid NAPL density Density_NAPL: " + << cp_vec[cp_name_2_idx[reactionpartner[0]]]->molar_density /*Density_NAPL*/ + << " in Reaction " << name << "\n"; } - } //end type=NAPLdissolution + } // end type=NAPLdissolution - if(type.compare("Mineralkinetics") == 0) { - //is mineral defined as solid phase species? - // TODO CB_merge_0513 ?? - - } + if (type.compare("Mineralkinetics") == 0) + { + // is mineral defined as solid phase species? + // TODO CB_merge_0513 ?? + } return ok; } @@ -2289,36 +2309,42 @@ void CKinReact::Write(ofstream* rfe_file) int i, flag = 0, length; // Write Keyword - *rfe_file << "#REACTION" << "\n"; + *rfe_file << "#REACTION" + << "\n"; // Name of reaction - *rfe_file << "$NAME" << "\n" << name << "\n"; + *rfe_file << "$NAME" + << "\n" + << name << "\n"; // Type of reaction - *rfe_file << "$TYPE" << "\n" << type << "\n"; + *rfe_file << "$TYPE" + << "\n" + << type << "\n"; // bacteria name if (type == "monod") - *rfe_file << "$BACTERIANAME" << "\n" << bacteria_name << "\n"; + *rfe_file << "$BACTERIANAME" + << "\n" + << bacteria_name << "\n"; if (type == "exchange") - *rfe_file << "$SORPTION_TYPE" << "\n" << exType << "\n"; - //ReactionEquation - *rfe_file << "$EQUATION" << "\n"; + *rfe_file << "$SORPTION_TYPE" + << "\n" + << exType << "\n"; + // ReactionEquation + *rfe_file << "$EQUATION" + << "\n"; for (i = 0; i < number_reactionpartner; i++) { - if (stochmet[i] < 0.0) //left side of equation + if (stochmet[i] < 0.0) // left side of equation { if (i == 0) - *rfe_file << " " << fabs(stochmet[i]) << " " - << reactionpartner[i]; + *rfe_file << " " << fabs(stochmet[i]) << " " << reactionpartner[i]; else - *rfe_file << " + " << fabs(stochmet[i]) << " " - << reactionpartner[i]; + *rfe_file << " + " << fabs(stochmet[i]) << " " << reactionpartner[i]; } if (stochmet[i] > 0 && (flag > 0)) // remaining right hand side - *rfe_file << " + " << fabs(stochmet[i]) << " " - << reactionpartner[i]; + *rfe_file << " + " << fabs(stochmet[i]) << " " << reactionpartner[i]; if (stochmet[i] > 0 && (flag == 0)) // " = " Sign and first term on right hand side { - *rfe_file << " = " << fabs(stochmet[i]) << " " - << reactionpartner[i]; + *rfe_file << " = " << fabs(stochmet[i]) << " " << reactionpartner[i]; flag = 1; } } @@ -2326,44 +2352,50 @@ void CKinReact::Write(ofstream* rfe_file) // Rateconstant and order if (type == "monod") { - *rfe_file << "$RATECONSTANT" << "\n" << rateconstant << " " - << rateorder << "\n"; - *rfe_file << "$GROWTH" << "\n" << grow << "\n"; - //Monod terms - *rfe_file << "$MONODTERMS" << "\n"; //<< number_monod << "\n"; + *rfe_file << "$RATECONSTANT" + << "\n" + << rateconstant << " " << rateorder << "\n"; + *rfe_file << "$GROWTH" + << "\n" + << grow << "\n"; + // Monod terms + *rfe_file << "$MONODTERMS" + << "\n"; //<< number_monod << "\n"; for (i = 0; i < number_monod; i++) - *rfe_file << monod[i]->species << " " << monod[i]->concentration - << " " << monod[i]->order << "\n"; - //Inhibition terms - *rfe_file << "$INHIBITIONTERMS" << "\n"; // << number_inhibit << "\n"; + *rfe_file << monod[i]->species << " " << monod[i]->concentration << " " << monod[i]->order << "\n"; + // Inhibition terms + *rfe_file << "$INHIBITIONTERMS" + << "\n"; // << number_inhibit << "\n"; for (i = 0; i < number_inhibit; i++) - *rfe_file << inhibit[i]->species << " " - << inhibit[i]->concentration << " " << inhibit[i]->order - << "\n"; + *rfe_file << inhibit[i]->species << " " << inhibit[i]->concentration << " " << inhibit[i]->order << "\n"; // Production Terms //*rfe_file << "$PRODUCTIONTERMS" << "\n" << number_production << "\n"; - //for(i=0;ispecies << " " << production[i]->concentration << " " << production[i]->order << "\n"; + // for(i=0;ispecies << " " << production[i]->concentration << " " << production[i]->order + //<< "\n"; // Production Terms - length = (int) ProdStochhelp.size(); - *rfe_file << "$PRODUCTIONSTOCH" << "\n"; // << length << "\n"; + length = (int)ProdStochhelp.size(); + *rfe_file << "$PRODUCTIONSTOCH" + << "\n"; // << length << "\n"; for (i = 0; i < length; i++) - *rfe_file << ProdStochhelp[i]->species << " " - << ProdStochhelp[i]->concentration << " " << "\n"; + *rfe_file << ProdStochhelp[i]->species << " " << ProdStochhelp[i]->concentration << " " + << "\n"; if (degType == "isotope_fractionation") { - *rfe_file << "$ISOTOPE_FRACTIONATION" << "\n"; - *rfe_file << Isotope_light << " " << Isotope_heavy << " " - << isoenfac << "\n"; + *rfe_file << "$ISOTOPE_FRACTIONATION" + << "\n"; + *rfe_file << Isotope_light << " " << Isotope_heavy << " " << isoenfac << "\n"; } //#ds output f�r NAPL-dissolution // *rfe_file << "$NAPL_PROPERTIES" << "\n"; - // *rfe_file << "blob_name " << blob_name << " Csat_pure " << Csat_pure << " Density_NAPL " << Density_NAPL << "\n"; + // *rfe_file << "blob_name " << blob_name << " Csat_pure " << Csat_pure << " Density_NAPL " << Density_NAPL << + //"\n"; } if (type == "exchange") { - *rfe_file << "EXCHANGE_PARAMETERS" << "\n"; - length = (int) ex_param.size(); + *rfe_file << "EXCHANGE_PARAMETERS" + << "\n"; + length = (int)ex_param.size(); for (i = 0; i < length; i++) *rfe_file << ex_param[i] << " "; *rfe_file << "\n"; @@ -2382,28 +2414,27 @@ void CKinReact::ReadReactionEquation(string line_string_all) { string line_string, name, helpstring, c, calt; string substring, subsubstring; - int indexlow, indexhigh, help1, strl, linelength, ih1, ih2, ih3, - indexgleich, i, partners, p; + int indexlow, indexhigh, help1, strl, linelength, ih1, ih2, ih3, indexgleich, i, partners, p; double zahl, vz = -1.0; stochmet.clear(); reactionpartner.clear(); - //Anf�ngliche Leerzeichen, Kommentar am Ende raus - ih1 = (int) line_string_all.find_first_not_of(" ", 0); - ih2 = (int) line_string_all.find_first_of(";", ih1); - ih3 = (int) line_string_all.length(); + // Anf�ngliche Leerzeichen, Kommentar am Ende raus + ih1 = (int)line_string_all.find_first_not_of(" ", 0); + ih2 = (int)line_string_all.find_first_of(";", ih1); + ih3 = (int)line_string_all.length(); line_string = line_string_all.substr(ih1, ih2 - ih1); - //Auf mehrfache Leerzeichen und Tabs �berpr�fen - ersetzt durch je ein Leerzeichen - ih3 = (int) line_string.length(); + // Auf mehrfache Leerzeichen und Tabs �berpr�fen - ersetzt durch je ein Leerzeichen + ih3 = (int)line_string.length(); for (i = 0; i < ih3; i++) { c = line_string[i]; if (c == " ") - c = " "; //replace tab by space + c = " "; // replace tab by space if ((c == " ") && (calt == " ")) - ih1++; //nothing + ih1++; // nothing else { helpstring.append(c); @@ -2412,32 +2443,32 @@ void CKinReact::ReadReactionEquation(string line_string_all) } // Leerzeichen am Ende raus - ih1 = (int) helpstring.find_first_not_of(" ", 0); - ih2 = (int) helpstring.find_last_of(" "); - ih3 = (int) helpstring.length(); - if (ih2 == ih3 - 1) // Leerzeichen am Ende + ih1 = (int)helpstring.find_first_not_of(" ", 0); + ih2 = (int)helpstring.find_last_of(" "); + ih3 = (int)helpstring.length(); + if (ih2 == ih3 - 1) // Leerzeichen am Ende line_string = helpstring.substr(ih1, ih2 - ih1); else line_string = helpstring.substr(ih1, ih3 - ih1); - //Count reaction partners by looking for " + " - linelength = (int) line_string.length(); + // Count reaction partners by looking for " + " + linelength = (int)line_string.length(); indexhigh = 0; partners = 0; - ih1 = (int) line_string.find(" = "); + ih1 = (int)line_string.find(" = "); if (ih1 < 0) DisplayMsgLn(" Error in keyword REACTION"); // Exception handling while (indexhigh < linelength) { - ih1 = (int) line_string.find(" + ", indexhigh); + ih1 = (int)line_string.find(" + ", indexhigh); if (ih1 > 0) { partners++; indexhigh = ih1 + 3; } else - //no " + " found + // no " + " found indexhigh = linelength; } // Number of partners is 2 for " = " and one additional for each " + " @@ -2446,33 +2477,33 @@ void CKinReact::ReadReactionEquation(string line_string_all) /* Zerlegen der Gleichung in Bl�che mit "Zahl Namen"*/ indexhigh = 0; - p = 0; //Zaehlt partner hoch + p = 0; // Zaehlt partner hoch indexlow = indexhigh; - linelength = (int) line_string.length(); + linelength = (int)line_string.length(); - indexgleich = (int) line_string.find(" = "); + indexgleich = (int)line_string.find(" = "); while (indexhigh < linelength) { /* einen Block holen - find next occurence of +, -, = */ - ih1 = (int) line_string.find(" + ", indexlow); + ih1 = (int)line_string.find(" + ", indexlow); if (ih1 < 0) ih1 = linelength; - ih2 = (int) line_string.find(" - ", indexlow); + ih2 = (int)line_string.find(" - ", indexlow); if (ih2 < 0) ih2 = linelength; - ih3 = (int) line_string.find(" = ", indexlow); + ih3 = (int)line_string.find(" = ", indexlow); if (ih3 < 0) ih3 = linelength; indexhigh = min(ih1, min(ih2, ih3)); if (indexhigh > indexgleich) - vz = 1.0; //rechte Seite der Gleichung: Vorzeichenwechsel + vz = 1.0; // rechte Seite der Gleichung: Vorzeichenwechsel substring = line_string.substr(indexlow, indexhigh - indexlow); /* Leerzeichen drin ? */ - help1 = (int) substring.find(" ", 0); - strl = (int) substring.length(); - if (help1 > 0) //Leerzeichen gefunden + help1 = (int)substring.find(" ", 0); + strl = (int)substring.length(); + if (help1 > 0) // Leerzeichen gefunden { subsubstring = substring.substr(0, help1); // if(subsubstring.find(".",0)>0) //double value given @@ -2482,7 +2513,7 @@ void CKinReact::ReadReactionEquation(string line_string_all) // reactionpartner[p] = subsubstring.data(); // sprintf(reactionpartner[p],"%s", subsubstring.data()); reactionpartner.push_back(subsubstring); - } //kein Leerzeichen gefunden, substring enth�lt nur den Namen => Zahl wird 1 gesetzt + } // kein Leerzeichen gefunden, substring enth�lt nur den Namen => Zahl wird 1 gesetzt else { zahl = 1.0 * vz; @@ -2491,16 +2522,15 @@ void CKinReact::ReadReactionEquation(string line_string_all) // sprintf(reactionpartner[p],"%s", subsubstring.data()); reactionpartner.push_back(substring); } - p++; //Reactionpartner hochzaehlen + p++; // Reactionpartner hochzaehlen // cout << zahl <<" "<< name << " "; indexlow = indexhigh + 3; // add length of " + " - } //end while + } // end while if (p != number_reactionpartner) - cout - << "Error: Parser for kinetic equations found varying number of reaction partners" - << "\n"; + cout << "Error: Parser for kinetic equations found varying number of reaction partners" + << "\n"; } /*************************************************************************** @@ -2525,49 +2555,49 @@ CKinBlob::CKinBlob(void) BlobGeoName.clear(); Area_Value.clear(); Interfacial_area.clear(); - Masstransfer_K.clear(); - gas_dissolution_flag = false; - //New-Sherwood-Number - shidx = 0; // SP: Index for different Sherwood calculations - NContent_expo = 0; - WContent_expo = 0; - Pe_expo = 0; - D50_expo = 0; - Poro_expo = 0; - Delta_expo = 0; - UI_expo = 0; - NContent_ini_expo = 0; - NContent_res_expo = 0; - GSR_expo = 0; - Length_expo = 0; - Tort_expo = 0; - Pfannkuch_constant = 0; - beta_4 = 0 ; - one_three = 0; - two_three = 0; - four_nine = 0; - fife_nine = 0; - elev_nine = 0; - fife_three = 0; - grain_expo = 0 ; - modSherwood = false; - Sherwood_model = false; - - dM = -1; - dS = -1; - UI = -1; - grain_var = -1; - NCont_ini = -1; - NCont_res = -1; - NCont_Sh1 = -1; - NCont_Sh2 = -1 ; - //mod_Reynolds = -1 ; - GSR = -1; - Length = -1; - Tort = -1; - // CB 12/09 new data structures for parallel computation - //Exchangeterms.clear(); - //Volume_old.clear(); + Masstransfer_K.clear(); + gas_dissolution_flag = false; + // New-Sherwood-Number + shidx = 0; // SP: Index for different Sherwood calculations + NContent_expo = 0; + WContent_expo = 0; + Pe_expo = 0; + D50_expo = 0; + Poro_expo = 0; + Delta_expo = 0; + UI_expo = 0; + NContent_ini_expo = 0; + NContent_res_expo = 0; + GSR_expo = 0; + Length_expo = 0; + Tort_expo = 0; + Pfannkuch_constant = 0; + beta_4 = 0; + one_three = 0; + two_three = 0; + four_nine = 0; + fife_nine = 0; + elev_nine = 0; + fife_three = 0; + grain_expo = 0; + modSherwood = false; + Sherwood_model = false; + + dM = -1; + dS = -1; + UI = -1; + grain_var = -1; + NCont_ini = -1; + NCont_res = -1; + NCont_Sh1 = -1; + NCont_Sh2 = -1; + // mod_Reynolds = -1 ; + GSR = -1; + Length = -1; + Tort = -1; + // CB 12/09 new data structures for parallel computation + // Exchangeterms.clear(); + // Volume_old.clear(); } /*************************************************************************** @@ -2586,9 +2616,7 @@ CKinBlob::~CKinBlob(void) Programing: 02/2007 DS Implementation **************************************************************************/ -bool CKinBlob::Read(ifstream* rfd_file, - const GEOLIB::GEOObjects& geo_obj, - const std::string& unique_name) +bool CKinBlob::Read(ifstream* rfd_file, const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) { char line[MAX_ZEILE]; string line_string, line_str1, s_geo_type, s_geo_name; @@ -2598,7 +2626,7 @@ bool CKinBlob::Read(ifstream* rfd_file, double d_inivalue; std::stringstream in; - //STP New-Sherwood-Number + // STP New-Sherwood-Number //======================================================================== while (!new_keyword) { @@ -2610,7 +2638,7 @@ bool CKinBlob::Read(ifstream* rfd_file, if (line_string.find(hash) != string::npos) { new_keyword = true; - rfd_file->seekg(index); //Dateipointer zur�cksetzen, sonst ist das n�chste keyword weg + rfd_file->seekg(index); // Dateipointer zur�cksetzen, sonst ist das n�chste keyword weg break; } /* Keywords nacheinander durchsuchen */ @@ -2632,7 +2660,7 @@ bool CKinBlob::Read(ifstream* rfd_file, } //.................................................................... // subkeyword found - //if (line_string.find("$CALC_SHERWOOD") != string::npos) + // if (line_string.find("$CALC_SHERWOOD") != string::npos) //{ // in.str(GetLineFromFile1(rfd_file)); // in >> Sh_factor >> Re_expo >> Sc_expo; @@ -2640,124 +2668,139 @@ bool CKinBlob::Read(ifstream* rfd_file, //} //.................................................................... // subkeyword found - if(line_string.find("$DM")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> dM; - in.clear(); - } - //.................................................................... - if(line_string.find("$DS")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> dS; - in.clear(); - } - //.................................................................... - if(line_string.find("$UI")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> UI; - in.clear(); - } - //.................................................................... - if(line_string.find("$NAPL_CONTENT_INI")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> NCont_ini; - in.clear(); - } - //.................................................................... - if(line_string.find("$NAPL_CONTENT_RES")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> NCont_res; - in.clear(); - } - //.................................................................... - if(line_string.find("$GRAIN_SPHERE_RATIO")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> GSR; - in.clear(); - } - //.................................................................... - if(line_string.find("$TORTUOSITY")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> Tort; - in.clear(); - } - //.................................................................... - if(line_string.find("$LENGTH")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> Length; //Länge der NAPL-Quelle - in.clear(); - } - //.................................................................... - if( line_string.find("$CALC_SHERWOOD")!=string::npos && line_string.find("$CALC_SHERWOOD_MODIFIED")==string::npos ) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> Sh_factor >> Re_expo >> Sc_expo ; - in.clear(); - } - //.................................................................... - if(line_string.find("$CALC_SHERWOOD_MODIFIED")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> Pe_expo >> NContent_expo >> WContent_expo >> D50_expo >> Poro_expo >> Delta_expo >> UI_expo >> NContent_ini_expo >> NContent_res_expo >> GSR_expo >> Tort_expo >> Length_expo >> Pfannkuch_constant; - in.clear(); - modSherwood = true; - } - //.................................................................... - if(line_string.find("$SHERWOOD_MODEL")!=string::npos) // subkeyword found, SP: keyword for calculation of diffenrent Sherwood-models - { - in.str(GetLineFromFile1(rfd_file)); - in >> shidx; //Sh_factor >> Re_expo >> Sc_expo >> Pe_expo >> NContent_expo >> WContent_expo >> D50_expo >> Poro_expo >> Delta_expo >> UI_expo >> NContent_ini_expo >> NContent_res_expo >> GSR_expo >> Tort_expo >> Length_expo >> Pfannkuch_constant; - if(shidx==0) // SP: Standard Sherwood calculation after Bradford and Abriola, 2001 - { - in >> Sh_factor >> Re_expo >> Sc_expo ; - } - if(shidx==1) // SP: Sherwood calculation after Powers et al., 1994 - { - in >> Sh_factor >> Re_expo >> Delta_expo >> UI_expo ; - Sherwood_model = true; - } - if(shidx==2) // SP: Sherwood calculation after Powers et al., 1992 - { - in >> Sh_factor >> Re_expo >> D50_expo >> UI_expo ; - Sherwood_model = true; - } - if(shidx==3) // SP: Sherwood calculation after Wilson and Geankoplis, 1966 - { - in >> Sh_factor ; - } - if(shidx==4) // SP: Sherwood calculation after Pfannkuch, 1984 - { - in >> Sh_factor >> Pfannkuch_constant; - } - if(shidx==5) // SP: Sherwood calculation after Miller, 1990 - { - in >> Sh_factor >> Re_expo >> WContent_expo >> Sc_expo; - Sherwood_model = true; - } - if(shidx==6) // SP: Sherwood calculation after Saba&Illangasekare, 2000 - { - in >> Sh_factor >> Re_expo >> Sc_expo ; - Sherwood_model = true; - } - if(shidx==7) // SP: Sherwood calculation after Geller&Hunt, 1993 - { - in >> Sh_factor >> Re_expo >> NContent_expo >> NContent_ini_expo >> Poro_expo >> grain_expo; - Sherwood_model = true; - } - in.clear(); - continue; - } - //.................................................................... - // subkeyword found + if (line_string.find("$DM") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> dM; + in.clear(); + } + //.................................................................... + if (line_string.find("$DS") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> dS; + in.clear(); + } + //.................................................................... + if (line_string.find("$UI") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> UI; + in.clear(); + } + //.................................................................... + if (line_string.find("$NAPL_CONTENT_INI") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> NCont_ini; + in.clear(); + } + //.................................................................... + if (line_string.find("$NAPL_CONTENT_RES") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> NCont_res; + in.clear(); + } + //.................................................................... + if (line_string.find("$GRAIN_SPHERE_RATIO") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> GSR; + in.clear(); + } + //.................................................................... + if (line_string.find("$TORTUOSITY") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> Tort; + in.clear(); + } + //.................................................................... + if (line_string.find("$LENGTH") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> Length; // Länge der NAPL-Quelle + in.clear(); + } + //.................................................................... + if (line_string.find("$CALC_SHERWOOD") != string::npos + && line_string.find("$CALC_SHERWOOD_MODIFIED") == string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> Sh_factor >> Re_expo >> Sc_expo; + in.clear(); + } + //.................................................................... + if (line_string.find("$CALC_SHERWOOD_MODIFIED") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> Pe_expo >> NContent_expo >> WContent_expo >> D50_expo >> Poro_expo >> Delta_expo >> UI_expo + >> NContent_ini_expo >> NContent_res_expo >> GSR_expo >> Tort_expo >> Length_expo >> Pfannkuch_constant; + in.clear(); + modSherwood = true; + } + //.................................................................... + if (line_string.find("$SHERWOOD_MODEL") + != string::npos) // subkeyword found, SP: keyword for calculation of diffenrent Sherwood-models + { + in.str(GetLineFromFile1(rfd_file)); + in >> shidx; // Sh_factor >> Re_expo >> Sc_expo >> Pe_expo >> NContent_expo >> WContent_expo >> D50_expo >> + // Poro_expo >> Delta_expo >> UI_expo >> NContent_ini_expo >> NContent_res_expo >> GSR_expo >> + // Tort_expo >> Length_expo >> Pfannkuch_constant; + if (shidx == 0) // SP: Standard Sherwood calculation after Bradford and Abriola, 2001 + { + in >> Sh_factor >> Re_expo >> Sc_expo; + } + if (shidx == 1) // SP: Sherwood calculation after Powers et al., 1994 + { + in >> Sh_factor >> Re_expo >> Delta_expo >> UI_expo; + Sherwood_model = true; + } + if (shidx == 2) // SP: Sherwood calculation after Powers et al., 1992 + { + in >> Sh_factor >> Re_expo >> D50_expo >> UI_expo; + Sherwood_model = true; + } + if (shidx == 3) // SP: Sherwood calculation after Wilson and Geankoplis, 1966 + { + in >> Sh_factor; + } + if (shidx == 4) // SP: Sherwood calculation after Pfannkuch, 1984 + { + in >> Sh_factor >> Pfannkuch_constant; + } + if (shidx == 5) // SP: Sherwood calculation after Miller, 1990 + { + in >> Sh_factor >> Re_expo >> WContent_expo >> Sc_expo; + Sherwood_model = true; + } + if (shidx == 6) // SP: Sherwood calculation after Saba&Illangasekare, 2000 + { + in >> Sh_factor >> Re_expo >> Sc_expo; + Sherwood_model = true; + } + if (shidx == 7) // SP: Sherwood calculation after Geller&Hunt, 1993 + { + in >> Sh_factor >> Re_expo >> NContent_expo >> NContent_ini_expo >> Poro_expo >> grain_expo; + Sherwood_model = true; + } + in.clear(); + continue; + } + //.................................................................... + // subkeyword found if (line_string.find("$GEOMETRY") != string::npos) { in.str(GetLineFromFile1(rfd_file)); in >> Geometry_expo; in.clear(); } - //.................................................................... - // subkeyword found - if (line_string.find("$GAS_DISSOLUTION") != string::npos) - gas_dissolution_flag = true; - // subkeyword found + //.................................................................... + // subkeyword found + if (line_string.find("$GAS_DISSOLUTION") != string::npos) + gas_dissolution_flag = true; + // subkeyword found if (line_string.find("$INTERFACIAL_AREA") != string::npos) while (OK) { @@ -2765,12 +2808,10 @@ bool CKinBlob::Read(ifstream* rfd_file, if (!GetLineFromFile(line, rfd_file)) break; line_str1 = line; - if ((line_str1.find(hash) != string::npos) || (line_str1.find( - dollar) != - string::npos)) + if ((line_str1.find(hash) != string::npos) || (line_str1.find(dollar) != string::npos)) { OK = false; - rfd_file->seekg(index1); //Dateipointer zur�cksetzen, sonst ist das n�chste keyword weg + rfd_file->seekg(index1); // Dateipointer zur�cksetzen, sonst ist das n�chste keyword weg break; } in.str(line_str1); @@ -2793,25 +2834,18 @@ bool CKinBlob::Read(ifstream* rfd_file, if (s_geo_type.find("POINT") != std::string::npos) // TF 06/2010 - get the point vector and set the geo_obj_idx - if (!((geo_obj.getPointVecObj(unique_name))-> - getElementIDByName( - s_geo_name, geo_obj_idx))) + if (!((geo_obj.getPointVecObj(unique_name))->getElementIDByName(s_geo_name, geo_obj_idx))) { - std::cerr - << - "error in CKinBlob::Read: point name not found!" - << "\n"; + std::cerr << "error in CKinBlob::Read: point name not found!" + << "\n"; exit(1); } if (s_geo_type.find("POLYLINE") != std::string::npos) // TF 06/2010 - get the polyline vector and set the geo_obj_idx - if (!((geo_obj.getPolylineVecObj(unique_name))-> - getElementIDByName( - s_geo_name, geo_obj_idx))) + if (!((geo_obj.getPolylineVecObj(unique_name))->getElementIDByName(s_geo_name, geo_obj_idx))) { - std::cerr << - "error in CKinBlob::Read: polyline name not found!" + std::cerr << "error in CKinBlob::Read: polyline name not found!" << "\n"; exit(1); } @@ -2821,7 +2855,7 @@ bool CKinBlob::Read(ifstream* rfd_file, BlobGeoID.push_back(geo_obj_idx); in.clear(); } - } //end while keyword + } // end while keyword return true; } @@ -2837,45 +2871,56 @@ bool CKinBlob::Read(ifstream* rfd_file, void CKinBlob::Write(std::ostream& rfe_file) const { rfe_file << "\n"; - rfe_file << "#BLOB_PROPERTIES" << "\n"; - rfe_file << "$NAME" << "\n" << name << "\n"; - rfe_file << "$D50" << "\n" << d50 << "\n"; - rfe_file << "$CALC_SHERWOOD" << "\n"; + rfe_file << "#BLOB_PROPERTIES" + << "\n"; + rfe_file << "$NAME" + << "\n" + << name << "\n"; + rfe_file << "$D50" + << "\n" + << d50 << "\n"; + rfe_file << "$CALC_SHERWOOD" + << "\n"; rfe_file << " Sh_factor : " << Sh_factor << "\n"; rfe_file << " Re_expo : " << Re_expo << "\n"; rfe_file << " Sc_expo : " << Sc_expo << "\n"; - rfe_file << "$GEOMETRY" << "\n" << Geometry_expo << "\n"; - rfe_file << "$INTERFACIAL_AREA" << "\n"; + rfe_file << "$GEOMETRY" + << "\n" + << Geometry_expo << "\n"; + rfe_file << "$INTERFACIAL_AREA" + << "\n"; for (size_t j = 0; j < BlobGeoName.size(); j++) { rfe_file << " Geotype : " << BlobGeoType[j]; rfe_file << " Geoname : " << BlobGeoName[j]; rfe_file << " Value : " << Area_Value[j] << "\n"; } - if(modSherwood==true){ - rfe_file << "$CALC_SHERWOOD_MODIFIED " << "\n"; - rfe_file << " UI : " << this->UI << "\n"; - rfe_file << " dM : " << this->dM << "\n"; - rfe_file << " NAPL_CONTENT_INI : " << this->NCont_ini << "\n"; - rfe_file << " NAPL_CONTENT_RESIDUAL: " << this->NCont_res << "\n"; - rfe_file << " GRAIN_SPHERE_RATIO : " << this->GSR << "\n"; - rfe_file << " TORTUOSITY : " << this->Tort << "\n"; - rfe_file << " LENGTH : " << this->Length << "\n"; - - rfe_file << " Pe_expo : " << this->Pe_expo << "\n"; - rfe_file << " NContent_expo : " << this->NContent_expo << "\n"; - rfe_file << " WContent_expo : " << this->WContent_expo << "\n"; - rfe_file << " d50_expo : " << this->D50_expo << "\n"; - rfe_file << " n_expo : " << this->Poro_expo << "\n"; - rfe_file << " delta_expo : " << this->Delta_expo << "\n"; - rfe_file << " UI_expo : " << this->UI_expo << "\n"; - rfe_file << " NCont_ini_expo : " << this->NContent_ini_expo << "\n"; - rfe_file << " NCont_res_expo : " << this->NContent_res_expo << "\n"; - rfe_file << " GSR_expo : " << this->GSR_expo << "\n"; - rfe_file << " Tort_expo : " << this->Tort_expo << "\n"; - rfe_file << " Length_expo : " << this->Length_expo << "\n"; - rfe_file << " Pfannkuch_constant: " << this->Pfannkuch_constant << "\n"; - } + if (modSherwood == true) + { + rfe_file << "$CALC_SHERWOOD_MODIFIED " + << "\n"; + rfe_file << " UI : " << this->UI << "\n"; + rfe_file << " dM : " << this->dM << "\n"; + rfe_file << " NAPL_CONTENT_INI : " << this->NCont_ini << "\n"; + rfe_file << " NAPL_CONTENT_RESIDUAL: " << this->NCont_res << "\n"; + rfe_file << " GRAIN_SPHERE_RATIO : " << this->GSR << "\n"; + rfe_file << " TORTUOSITY : " << this->Tort << "\n"; + rfe_file << " LENGTH : " << this->Length << "\n"; + + rfe_file << " Pe_expo : " << this->Pe_expo << "\n"; + rfe_file << " NContent_expo : " << this->NContent_expo << "\n"; + rfe_file << " WContent_expo : " << this->WContent_expo << "\n"; + rfe_file << " d50_expo : " << this->D50_expo << "\n"; + rfe_file << " n_expo : " << this->Poro_expo << "\n"; + rfe_file << " delta_expo : " << this->Delta_expo << "\n"; + rfe_file << " UI_expo : " << this->UI_expo << "\n"; + rfe_file << " NCont_ini_expo : " << this->NContent_ini_expo << "\n"; + rfe_file << " NCont_res_expo : " << this->NContent_res_expo << "\n"; + rfe_file << " GSR_expo : " << this->GSR_expo << "\n"; + rfe_file << " Tort_expo : " << this->Tort_expo << "\n"; + rfe_file << " Length_expo : " << this->Length_expo << "\n"; + rfe_file << " Pfannkuch_constant: " << this->Pfannkuch_constant << "\n"; + } rfe_file << "\n"; } @@ -2893,20 +2938,22 @@ void KBlobConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_na std::vector nodes_vector; // create vector for Interfacial_area and initialization with input value (Interfacial_area[0]=input value) - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt if (m_msh == NULL) { - cout << "No mesh in KRConfig" << "\n"; + cout << "No mesh in KRConfig" + << "\n"; exit(1); } for (size_t i = 0; i < KinBlob_vector.size(); i++) { CKinBlob* m_kb(KinBlob_vector[i]); - for (size_t l = 0; l < m_msh->nod_vector.size(); l++){ - m_kb->Interfacial_area.push_back(-1.); //Vorbelegung mit Area=-1 - m_kb->Masstransfer_K.push_back( -1. ); //Vorbelegung mit K=-1 - } + for (size_t l = 0; l < m_msh->nod_vector.size(); l++) + { + m_kb->Interfacial_area.push_back(-1.); // Vorbelegung mit Area=-1 + m_kb->Masstransfer_K.push_back(-1.); // Vorbelegung mit K=-1 + } for (size_t j = 0; j < m_kb->BlobGeoName.size(); j++) { s_geo_name = m_kb->BlobGeoName[j]; @@ -2918,26 +2965,25 @@ void KBlobConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_na // CGLPoint* m_geo_point = NULL; // make new GEO point // m_geo_point = GEOGetPointByName(s_geo_name);//Get GEO point by name // if (m_geo_point) - // l = m_msh->GetNODOnPNT(m_geo_point); // + ShiftInNodeVector; // find MSH point number stored in l + // l = m_msh->GetNODOnPNT(m_geo_point); // + ShiftInNodeVector; // find MSH point + // number + // stored + // in l - const std::vector* pnt_vec(geo_obj.getPointVec( - unique_name)); - size_t msh_node_id = - m_msh->GetNODOnPNT((*pnt_vec)[(m_kb->getBlobGeoID())[j]]); + const std::vector* pnt_vec(geo_obj.getPointVec(unique_name)); + size_t msh_node_id = m_msh->GetNODOnPNT((*pnt_vec)[(m_kb->getBlobGeoID())[j]]); m_kb->Interfacial_area[msh_node_id] = m_kb->Area_Value[j]; - } // end if POINT + } // end if POINT if (s_geo_type.compare("POLYLINE") == 0) - { - std::vector const* const ply_vec( - geo_obj.getPolylineVec(unique_name)); + { + std::vector const* const ply_vec(geo_obj.getPolylineVec(unique_name)); GEOLIB::Polyline const* const polyline((*ply_vec)[s_geo_id]); m_msh->GetNODOnPLY(polyline, nodes_vector); for (size_t k = 0; k < nodes_vector.size(); k++) - m_kb->Interfacial_area[nodes_vector[k]] = - m_kb->Area_Value[j]; - } // end if POLYLINE + m_kb->Interfacial_area[nodes_vector[k]] = m_kb->Area_Value[j]; + } // end if POLYLINE if (s_geo_type.compare("SURFACE") == 0) { @@ -2945,23 +2991,23 @@ void KBlobConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_na m_surface = GEOGetSFCByName(s_geo_name); if (m_surface) { - m_msh->GetNODOnSFC(m_surface, nodes_vector); //kg44 if used together with PETSC one maybe needs to set the for_ic flag...see rf_id_new.cpp + m_msh->GetNODOnSFC(m_surface, nodes_vector); // kg44 if used together with PETSC one maybe needs to + // set the for_ic flag...see rf_id_new.cpp for (size_t k = 0; k < nodes_vector.size(); k++) { //+ShiftInNodeVector; size_t msh_node_id = nodes_vector[k]; - m_kb->Interfacial_area[msh_node_id] = - m_kb->Area_Value[j]; + m_kb->Interfacial_area[msh_node_id] = m_kb->Area_Value[j]; } } - } // end if SURFACE + } // end if SURFACE if (s_geo_type.compare("DOMAIN") == 0) for (size_t k = 0; k < m_msh->nod_vector.size(); k++) m_kb->Interfacial_area[k] = m_kb->Area_Value[j]; // end if SURFACE } - } //end loop over i = Number of blobs + } // end loop over i = Number of blobs nodes_vector.clear(); } @@ -2978,17 +3024,20 @@ void KBlobCheck(void) long k, l; CKinBlob* m_kb = NULL; - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt - cout << "\n" << "Checking defined blob classes" << "\n"; - for (i = 0; i < (int) KinBlob_vector.size(); i++) + cout << "\n" + << "Checking defined blob classes" + << "\n"; + for (i = 0; i < (int)KinBlob_vector.size(); i++) { m_kb = KinBlob_vector[i]; cout << m_kb->name << "\n"; if (m_kb->d50 <= 0.) { - cout << " Warning: D50 <= 0., D50 is set to 1.E-4" << "\n"; + cout << " Warning: D50 <= 0., D50 is set to 1.E-4" + << "\n"; m_kb->d50 = 1.E-4; } if (m_kb->Sh_factor < 0.) @@ -2999,37 +3048,38 @@ void KBlobCheck(void) } if (m_kb->Re_expo < 0.) { - cout << " Warning: Re_expo < 0., Re_expo is set to 0.654" << "\n"; + cout << " Warning: Re_expo < 0., Re_expo is set to 0.654" + << "\n"; m_kb->Re_expo = 0.654; } if (m_kb->Sc_expo < 0.) { - cout << " Warning: Sc_expo < 0., Sc_expo is set to 0.486" << "\n"; + cout << " Warning: Sc_expo < 0., Sc_expo is set to 0.486" + << "\n"; m_kb->Sc_expo = 0.486; } if (m_kb->Geometry_expo < 0.) { - cout - << " Warning: Geometry_expo < 0., Geometry_expo is set to 0.66" - << "\n"; + cout << " Warning: Geometry_expo < 0., Geometry_expo is set to 0.66" + << "\n"; m_kb->Geometry_expo = 0.66; } k = 0; - for (l = 0; l < (long) m_msh->nod_vector.size(); l++) + for (l = 0; l < (long)m_msh->nod_vector.size(); l++) { if (m_kb->Interfacial_area[l] < 0.) { - cout << " Warning: no value for node " << l - << " , Interfacial area is set to zero." << "\n"; + cout << " Warning: no value for node " << l << " , Interfacial area is set to zero." + << "\n"; m_kb->Interfacial_area[l] = 0.; } else k += 1; } - cout << " Values for interfacial Surfaces have been defined for " << k - << " nodes by user." << "\n"; - } //end loop i over blob classes + cout << " Values for interfacial Surfaces have been defined for " << k << " nodes by user." + << "\n"; + } // end loop i over blob classes } /************************************************************************** @@ -3050,63 +3100,62 @@ CKinReactData::CKinReactData(void) NumberLinear = 0; NumberMonod = 0; NumberNAPLdissolution = 0; -NumberMineralkinetics=0; -NumberMicrobeData = 0; - usedt = -1.0; - maxBacteriaCapacity = -1.0; - minBactConcentration = 1e-30; - minConcentrationMode = 0; - minConcentrationThreshhold = 1e-30; - minConcentrationSet = 1e-30; + NumberMineralkinetics = 0; + NumberMicrobeData = 0; + usedt = -1.0; + maxBacteriaCapacity = -1.0; + minBactConcentration = 1e-30; + minConcentrationMode = 0; + minConcentrationThreshhold = 1e-30; + minConcentrationSet = 1e-30; is_a_bacterium.clear(); - testoutput = false; //true; - maxSurfaces = 3; // Why is max = 3 ?? CB + testoutput = false; // true; + maxSurfaces = 3; // Why is max = 3 ?? CB exSurface.clear(); - //sp_index.clear(); - //kr_active_species = -1; + // sp_index.clear(); + // kr_active_species = -1; sp_varind.clear(); // sp_pcsind.clear(); //HS - //das Surface-Array k�nnte auch dynamisch allokiert werden + // das Surface-Array k�nnte auch dynamisch allokiert werden for (int i = 0; i < maxSurfaces; i++) exSurface.push_back(-1.0); NoReactGeoName.clear(); NoReactGeoType.clear(); - NoReactGeoID.clear(); - is_a_CCBC.clear(); - AllowReactGeoName.clear(); - AllowReactGeoType.clear(); - AllowReactGeoID.clear(); - node_foc.clear(); -cpu_time_krc = 0; // to measure cpu time - -IonicStrengths.clear(); -ActivityCoefficients.clear(); -activity_model=0; - - ReactDeactMode = -1; - ReactDeactEpsilon = -1.0; //CB ReactDeact - ReactDeactCThresh = -1.0; - ReactDeactRelative = false; + NoReactGeoID.clear(); + is_a_CCBC.clear(); + AllowReactGeoName.clear(); + AllowReactGeoType.clear(); + AllowReactGeoID.clear(); + node_foc.clear(); + cpu_time_krc = 0; // to measure cpu time + + IonicStrengths.clear(); + ActivityCoefficients.clear(); + activity_model = 0; + + ReactDeactMode = -1; + ReactDeactEpsilon = -1.0; // CB ReactDeact + ReactDeactCThresh = -1.0; + ReactDeactRelative = false; ReactDeactFlag = false; ReactDeactPlotFlag = 0; - ReactDeact.clear(); // flags for individual nodes - React_dCdT.clear(); // Sum of reaction rates for individual nodes - ReactNeighborhood.clear(); // node indices of local neighborhood around individual nodes - copy_concentrations = false; //SB 01.2011 - copy_nodes.clear(); //SB 01.2011 - radial = false; // default case - batch = false; - TwoDinThreeD = false; - - debugoutflag = false; - scale_dcdt = false; - lagneau = false; - sortnodes = false; - OmegaThresh = 1e-10; - - noototnodes = 0; - noocalcnodes = 0; - + ReactDeact.clear(); // flags for individual nodes + React_dCdT.clear(); // Sum of reaction rates for individual nodes + ReactNeighborhood.clear(); // node indices of local neighborhood around individual nodes + copy_concentrations = false; // SB 01.2011 + copy_nodes.clear(); // SB 01.2011 + radial = false; // default case + batch = false; + TwoDinThreeD = false; + + debugoutflag = false; + scale_dcdt = false; + lagneau = false; + sortnodes = false; + OmegaThresh = 1e-10; + + noototnodes = 0; + noocalcnodes = 0; } /************************************************************************** @@ -3117,10 +3166,11 @@ activity_model=0; **************************************************************************/ CKinReactData::~CKinReactData(void) { - if(sortnodes){ - delete [] substeps; - delete [] noderanks; - } + if (sortnodes) + { + delete[] substeps; + delete[] noderanks; + } } /************************************************************************** @@ -3129,9 +3179,7 @@ CKinReactData::~CKinReactData(void) Programing: 02/2006 SB New Class structure, IO, C++, FEM **************************************************************************/ -bool CKinReactData::Read(ifstream* rfd_file, - const GEOLIB::GEOObjects& geo_obj, - const std::string& unique_name) +bool CKinReactData::Read(ifstream* rfd_file, const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) { char line[MAX_ZEILE]; string sub_line; @@ -3143,9 +3191,9 @@ bool CKinReactData::Read(ifstream* rfd_file, size_t index, index1; int /* count_surf, */ surf_id; string s_geo_type, s_geo_name; - string dummy; - bool allow = false; - bool allow_not = false; + string dummy; + bool allow = false; + bool allow_not = false; //======================================================================== while (!new_keyword) @@ -3157,7 +3205,7 @@ bool CKinReactData::Read(ifstream* rfd_file, if (line_string.find(hash) != string::npos) { new_keyword = true; - rfd_file->seekg(index); //Dateipointer zur�cksetzen, sonst ist das n�chste keyword weg + rfd_file->seekg(index); // Dateipointer zur�cksetzen, sonst ist das n�chste keyword weg break; } /* Keywords nacheinander durchsuchen */ @@ -3202,21 +3250,21 @@ bool CKinReactData::Read(ifstream* rfd_file, in.clear(); } //.................................................................... - if (line_string.find("$MIN_BACTERIACONC") != string::npos) - { - in.str(GetLineFromFile1(rfd_file)); - in >> minBactConcentration; - in.clear(); - } - //.................................................................... - if (line_string.find("$MIN_CONCENTRATION_REPLACE") != string::npos) - { - in.str(GetLineFromFile1(rfd_file)); - in >> minConcentrationMode >> minConcentrationThreshhold >> minConcentrationSet; - in.clear(); - } - //.................................................................... - // subkeyword found + if (line_string.find("$MIN_BACTERIACONC") != string::npos) + { + in.str(GetLineFromFile1(rfd_file)); + in >> minBactConcentration; + in.clear(); + } + //.................................................................... + if (line_string.find("$MIN_CONCENTRATION_REPLACE") != string::npos) + { + in.str(GetLineFromFile1(rfd_file)); + in >> minConcentrationMode >> minConcentrationThreshhold >> minConcentrationSet; + in.clear(); + } + //.................................................................... + // subkeyword found if (line_string.find("$SURFACES") != string::npos) while (OK) { @@ -3224,172 +3272,180 @@ bool CKinReactData::Read(ifstream* rfd_file, if (!GetLineFromFile(line, rfd_file)) break; line_str1 = line; - if ((line_str1.find(hash) != string::npos) || (line_str1.find( - dollar) != - string::npos)) + if ((line_str1.find(hash) != string::npos) || (line_str1.find(dollar) != string::npos)) { OK = false; - rfd_file->seekg(index1); //Dateipointer zur�cksetzen, sonst ist das n�chste keyword weg + rfd_file->seekg(index1); // Dateipointer zur�cksetzen, sonst ist das n�chste keyword weg break; } in.str(line_str1); in >> surf_id; - if(surf_id > maxSurfaces-1){ - cout << " Warning in CKinReactData::Read: Specified surf_id " << surf_id << " is equal" << "\n"; - cout << " or larger than max no. of surfaces maxSurfaces = " << maxSurfaces << "." << "\n"; - cout << " First surf_id specified in KRC input file should be 0." << "\n"; - } + if (surf_id > maxSurfaces - 1) + { + cout << " Warning in CKinReactData::Read: Specified surf_id " << surf_id << " is equal" + << "\n"; + cout << " or larger than max no. of surfaces maxSurfaces = " << maxSurfaces << "." + << "\n"; + cout << " First surf_id specified in KRC input file should be 0." + << "\n"; + } in >> exSurface[surf_id]; in.clear(); } //.................................................................... // subkeyword found - allow = allow_not = false; - if (line_string.find("$ALLOW_REACTIONS") != string::npos) - allow = true; - if (line_string.find("$NO_REACTIONS") != string::npos) - allow_not = true; - if ((allow==true)|| (allow_not==true)) - { - while (OK) - { - index1 = rfd_file->tellg(); - if (!GetLineFromFile(line, rfd_file)) - break; - line_str1 = line; - if ((line_str1.find(hash) != string::npos) || (line_str1.find( - dollar) != - string::npos)) - { - OK = false; - rfd_file->seekg(index1); //Dateipointer zur�cksetzen, sonst ist das n�chste keyword weg - break; - } - in.str(line_str1); - in >> s_geo_type >> s_geo_name; - if (allow_not==true){ - NoReactGeoType.push_back(s_geo_type); - NoReactGeoName.push_back(s_geo_name); - } - else if(allow==true){ - AllowReactGeoType.push_back(s_geo_type); - AllowReactGeoName.push_back(s_geo_name); - } - - // TF 06/2010 - for the change string-ID to size_t-ID - size_t geo_obj_idx(std::numeric_limits::max()); - - if (s_geo_type.find("POINT") != std::string::npos) - { - // get the point vector and set the geo_obj_idx - if (!((geo_obj.getPointVecObj(unique_name))-> - getElementIDByName( - s_geo_name, geo_obj_idx))) - { - std::cerr - << "error in CKinReactData::Read: (type=" << - s_geo_type << "): " << s_geo_name << - " point name not found!" - << "\n"; - exit(1); - } - } - if (s_geo_type.find("POLYLINE") != std::string::npos) - { - // get the point vector and set the geo_obj_idx - if (!((geo_obj.getPolylineVecObj(unique_name))-> - getElementIDByName( - s_geo_name, geo_obj_idx))) - { - std::cerr - << "error in CKinReactData::Read: polyline name " - << s_geo_name << " not found!" - << "\n"; - exit(1); - } - } - - // - if (allow_not==true) - NoReactGeoID.push_back(geo_obj_idx); - else if(allow==true) - AllowReactGeoID.push_back(geo_obj_idx); - - in.clear(); - } - } - - //.................................................................... - if (line_string.find("$COPY_CONCENTRATIONS") != string::npos) { //SB 01.2011 - std::cout << "COPY_CONCENTRATIONS allows copying concentrations after reactions to neighbouring" - << " nodes for symmetric models:" << "\n"; - std::cout << " - BATCH: 2 node quasi 0D models." << "\n"; - std::cout << " - RADIAL symmetric quasi 2D hex models with y = 0 as symmetry axis." << "\n"; - std::cout << " - 2DIN3D: vertical x-z cross sections in full 3D hex models with arbitrary y as symmetry axis." << "\n"; - - this->copy_concentrations = true; - in.str(GetLineFromFile1(rfd_file)); - in >> dummy ; - in.clear(); - if (dummy.compare("RADIAL")==0) - radial = true; // default case - else if (dummy.compare("BATCH")==0) - batch = true; - else if (dummy.compare("2DIN3D")==0) - TwoDinThreeD = true; - else { - cout << "Error in CKinReactData::Read: $COPY_CONCENTRATIONS: No copy mode defined." - << "\n" << " Define either RADIAL or BATCH or 2DIN3D. Terminating now!" << "\n"; - exit(1); - } - } - //.................................................................... - if (line_string.find("$LAGNEAU_BENCHMARK") != string::npos) { //CB 04.2011 - this->lagneau = true; - } - //.................................................................... - if (line_string.find("$SCALE_DCDT") != string::npos) { //CB 04.2011 - this->scale_dcdt = true; // scale dcdt vector in derivs for stabilization of ODE solver - } - //.................................................................... - if (line_string.find("$SORT_NODES") != string::npos) { //CB 04.2011 - this->sortnodes = true; // scale dcdt vector in derivs for stabilization of ODE solver - } - //..................................................................... - if (line_string.find("$OMEGA_THRESHOLD") != string::npos) { //CB 11.2011 - in.str(GetLineFromFile1(rfd_file)); - in >> OmegaThresh; // set Minrate to 0 if |1-omega|< OmegaThresh - in.clear(); - } - //.................................................................... - // subkeyword found - if (line_string.find("$REACTION_DEACTIVATION") != string::npos) + allow = allow_not = false; + if (line_string.find("$ALLOW_REACTIONS") != string::npos) + allow = true; + if (line_string.find("$NO_REACTIONS") != string::npos) + allow_not = true; + if ((allow == true) || (allow_not == true)) { - in.str(GetLineFromFile1(rfd_file)); - in >> ReactDeactMode >> ReactDeactEpsilon >> ReactDeactPlotFlag >> dummy >> ReactDeactCThresh ; - in.clear(); - if (dummy.compare("RELATIVE")==0) - ReactDeactRelative = true; - else - ReactDeactRelative = false; - } - // subkeyword found - if (line_string.find("$DEBUG_OUTPUT") != string::npos) - debugoutflag = true; - //.................................................................... - if(line_string.find("$ACTIVITY_MODEL")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> activity_model; - in.clear(); - } - //.................................................................... - } - usedt = DMAX(initialTimestep, minTimestep); - return true; -} - -/************************************************************************** - Reaction-Method: + while (OK) + { + index1 = rfd_file->tellg(); + if (!GetLineFromFile(line, rfd_file)) + break; + line_str1 = line; + if ((line_str1.find(hash) != string::npos) || (line_str1.find(dollar) != string::npos)) + { + OK = false; + rfd_file->seekg(index1); // Dateipointer zur�cksetzen, sonst ist das n�chste keyword weg + break; + } + in.str(line_str1); + in >> s_geo_type >> s_geo_name; + if (allow_not == true) + { + NoReactGeoType.push_back(s_geo_type); + NoReactGeoName.push_back(s_geo_name); + } + else if (allow == true) + { + AllowReactGeoType.push_back(s_geo_type); + AllowReactGeoName.push_back(s_geo_name); + } + + // TF 06/2010 - for the change string-ID to size_t-ID + size_t geo_obj_idx(std::numeric_limits::max()); + + if (s_geo_type.find("POINT") != std::string::npos) + { + // get the point vector and set the geo_obj_idx + if (!((geo_obj.getPointVecObj(unique_name))->getElementIDByName(s_geo_name, geo_obj_idx))) + { + std::cerr << "error in CKinReactData::Read: (type=" << s_geo_type << "): " << s_geo_name + << " point name not found!" + << "\n"; + exit(1); + } + } + if (s_geo_type.find("POLYLINE") != std::string::npos) + { + // get the point vector and set the geo_obj_idx + if (!((geo_obj.getPolylineVecObj(unique_name))->getElementIDByName(s_geo_name, geo_obj_idx))) + { + std::cerr << "error in CKinReactData::Read: polyline name " << s_geo_name << " not found!" + << "\n"; + exit(1); + } + } + + // + if (allow_not == true) + NoReactGeoID.push_back(geo_obj_idx); + else if (allow == true) + AllowReactGeoID.push_back(geo_obj_idx); + + in.clear(); + } + } + + //.................................................................... + if (line_string.find("$COPY_CONCENTRATIONS") != string::npos) + { // SB 01.2011 + std::cout << "COPY_CONCENTRATIONS allows copying concentrations after reactions to neighbouring" + << " nodes for symmetric models:" + << "\n"; + std::cout << " - BATCH: 2 node quasi 0D models." + << "\n"; + std::cout << " - RADIAL symmetric quasi 2D hex models with y = 0 as symmetry axis." + << "\n"; + std::cout + << " - 2DIN3D: vertical x-z cross sections in full 3D hex models with arbitrary y as symmetry axis." + << "\n"; + + this->copy_concentrations = true; + in.str(GetLineFromFile1(rfd_file)); + in >> dummy; + in.clear(); + if (dummy.compare("RADIAL") == 0) + radial = true; // default case + else if (dummy.compare("BATCH") == 0) + batch = true; + else if (dummy.compare("2DIN3D") == 0) + TwoDinThreeD = true; + else + { + cout << "Error in CKinReactData::Read: $COPY_CONCENTRATIONS: No copy mode defined." + << "\n" + << " Define either RADIAL or BATCH or 2DIN3D. Terminating now!" + << "\n"; + exit(1); + } + } + //.................................................................... + if (line_string.find("$LAGNEAU_BENCHMARK") != string::npos) + { // CB 04.2011 + this->lagneau = true; + } + //.................................................................... + if (line_string.find("$SCALE_DCDT") != string::npos) + { // CB 04.2011 + this->scale_dcdt = true; // scale dcdt vector in derivs for stabilization of ODE solver + } + //.................................................................... + if (line_string.find("$SORT_NODES") != string::npos) + { // CB 04.2011 + this->sortnodes = true; // scale dcdt vector in derivs for stabilization of ODE solver + } + //..................................................................... + if (line_string.find("$OMEGA_THRESHOLD") != string::npos) + { // CB 11.2011 + in.str(GetLineFromFile1(rfd_file)); + in >> OmegaThresh; // set Minrate to 0 if |1-omega|< OmegaThresh + in.clear(); + } + //.................................................................... + // subkeyword found + if (line_string.find("$REACTION_DEACTIVATION") != string::npos) + { + in.str(GetLineFromFile1(rfd_file)); + in >> ReactDeactMode >> ReactDeactEpsilon >> ReactDeactPlotFlag >> dummy >> ReactDeactCThresh; + in.clear(); + if (dummy.compare("RELATIVE") == 0) + ReactDeactRelative = true; + else + ReactDeactRelative = false; + } + // subkeyword found + if (line_string.find("$DEBUG_OUTPUT") != string::npos) + debugoutflag = true; + //.................................................................... + if (line_string.find("$ACTIVITY_MODEL") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> activity_model; + in.clear(); + } + //.................................................................... + } + usedt = DMAX(initialTimestep, minTimestep); + return true; +} + +/************************************************************************** + Reaction-Method: Task: Reaction data class write function Programing: 02/2006 SB Adapted to new FEM structure @@ -3399,28 +3455,44 @@ void CKinReactData::Write(ofstream* rfe_file) int i; // Write Keyword *rfe_file << "\n"; - *rfe_file << "#KINREACTIONDATA" << "\n"; - *rfe_file << "$SOLVER_TYPE" << "\n" << SolverType << "\n"; - *rfe_file << "$RELATIVE_ERROR" << "\n" << relErrorTolerance << "\n"; - *rfe_file << "$MIN_TIMESTEP" << "\n" << minTimestep << "\n"; - *rfe_file << "$INITIAL_TIMESTEP" << "\n" << initialTimestep << "\n"; - *rfe_file << "$BACTERIACAPACITY" << "\n" << maxBacteriaCapacity << "\n"; + *rfe_file << "#KINREACTIONDATA" + << "\n"; + *rfe_file << "$SOLVER_TYPE" + << "\n" + << SolverType << "\n"; + *rfe_file << "$RELATIVE_ERROR" + << "\n" + << relErrorTolerance << "\n"; + *rfe_file << "$MIN_TIMESTEP" + << "\n" + << minTimestep << "\n"; + *rfe_file << "$INITIAL_TIMESTEP" + << "\n" + << initialTimestep << "\n"; + *rfe_file << "$BACTERIACAPACITY" + << "\n" + << maxBacteriaCapacity << "\n"; //*rfe_file << " max Surfaces : " << maxSurfaces << "\n"; - *rfe_file << "$SURFACES" << "\n"; //<< (int)exSurface.size() << "\n"; - for (i = 0; i < (int) exSurface.size(); i++) + *rfe_file << "$SURFACES" + << "\n"; //<< (int)exSurface.size() << "\n"; + for (i = 0; i < (int)exSurface.size(); i++) *rfe_file << i + 1 << " " << exSurface[i] << "\n"; - *rfe_file << "NO_REACTIONS" << "\n"; // << (int)NoReactGeoName.size() << "\n"; - for (i = 0; i < (int) NoReactGeoName.size(); i++) + *rfe_file << "NO_REACTIONS" + << "\n"; // << (int)NoReactGeoName.size() << "\n"; + for (i = 0; i < (int)NoReactGeoName.size(); i++) *rfe_file << NoReactGeoType[i] << " " << NoReactGeoName[i] << "\n"; - *rfe_file << "$REACTION_DEACTIVATION "<< "\n" << ReactDeactMode << " " - << ReactDeactEpsilon << " " << ReactDeactPlotFlag << "\n"; - *rfe_file << "$DEBUG_OUTPUT "<< "\n" << debugoutflag << "\n"; + *rfe_file << "$REACTION_DEACTIVATION " + << "\n" + << ReactDeactMode << " " << ReactDeactEpsilon << " " << ReactDeactPlotFlag << "\n"; + *rfe_file << "$DEBUG_OUTPUT " + << "\n" + << debugoutflag << "\n"; //*rfe_file << " Number of reactions: " << NumberReactions << "\n"; //*rfe_file << " Number of linear exchange reactions: " << NumberLinear << "\n"; //*rfe_file << " Number of freundlich exchange reactions: " << NumberFreundlich << "\n"; //*rfe_file << " Number of langmuir exchange reactions: " << NumberLangmuir << "\n"; //*rfe_file << " is_a_bacterium: " << "\n"; - //for(i=0;inod_vector.size()); // SB: ToDo hart gesetzt - const size_t nnodes(fem_msh_vector[0]->nod_vector.size()); // SB: ToDo hart gesetzt - - // CB Reaction deactivation for this time step - if (ReactDeactFlag){ - if (aktueller_zeitschritt > 2) - ReactionDeactivation(nnodes); // Check if nodes should be deactivated or activated for this time step - ClockTimeVec[0]->StopTime("ReactDeact"); // CB time - ClockTimeVec[0]->StartTime(); // CB time - } - if(debugoutflag){ - debugoutstr.setf(ios::scientific,ios::floatfield); - debugoutstr.precision(12); - debugoutstr.open(debugoutfilename.c_str()); - } + // CB Reaction deactivation for this time step + if (ReactDeactFlag) + { + if (aktueller_zeitschritt > 2) + ReactionDeactivation(nnodes); // Check if nodes should be deactivated or activated for this time step + ClockTimeVec[0]->StopTime("ReactDeact"); // CB time + ClockTimeVec[0]->StartTime(); // CB time + } + if (debugoutflag) + { + debugoutstr.setf(ios::scientific, ios::floatfield); + debugoutstr.precision(12); + debugoutstr.open(debugoutfilename.c_str()); + } if (time_vector.size() > 0) dt = time_vector[0]->CalcTimeStep(); - // This function prepares - // - flow velocities of PS_GLOBAL - // at all nodes - if(this->NumberNAPLdissolution > 0) - NAPLDissolutionPreprocessing(); - // This function prepares - // - Ionic streghts - // - activity coefficients - // at all nodes and for all species - if(this->NumberMineralkinetics > 0) - PreprocessMinKin(); - if(this->NumberMicrobeData >0) - this->PreprocessMicrobe_drmc_(dt); + // This function prepares + // - flow velocities of PS_GLOBAL + // at all nodes + if (this->NumberNAPLdissolution > 0) + NAPLDissolutionPreprocessing(); + // This function prepares + // - Ionic streghts + // - activity coefficients + // at all nodes and for all species + if (this->NumberMineralkinetics > 0) + PreprocessMinKin(); + if (this->NumberMicrobeData > 0) + this->PreprocessMicrobe_drmc_(dt); if ((dt > 1.E-20) && (aktueller_zeitschritt > 0)) - { - size_t save_node (0); + { + size_t save_node(0); int save_nok = 0, save_nbad = 0; double usedttmp = 1.E+30; /* Einstellungen Gleichungsl�ser f�r alle Knoten gleich */ @@ -3589,212 +3676,239 @@ void CKinReactData::ExecuteKinReact(void) /* min zulaessiger Zeitschritt*/ double hmin = minTimestep; - double usedtneu = 0.0 ; - long node; - size_t it, node_idx=0; - int nok = 0, nbad = 0, totsteps = 0; - double *Concentration; // HS: concentration of all result - int nComponents; - bool dry = false; - //CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt - //CTimeDiscretization *m_tim = NULL; - int tt=0, tsteps=1; - //cout << " ExecuteKineticReactions" << "\n"; - - nComponents = (int)cp_vec.size(); - nComponents++; - - Concentration = new double[nComponents*nnodes]; - for ( it=0 ; it < (nComponents)*nnodes ; it++ ) Concentration[it]=0.0; - if(this->sortnodes) { - for ( it=0 ; it < nnodes ; it++ ) substeps[it]=0; - } - #if defined(USE_MPI) || defined(USE_MPI_KRC) - if (this->NumberReactions>0) cout << " ExecuteKineticReactions MPI" << "\n"; - double *Concentration_buff; - Concentration_buff = new double[nComponents*nnodes]; - for ( it=0 ; it < (long)(nComponents)*nnodes ; it++ ) Concentration_buff[it]=0.0; - #else - if (this->NumberReactions>0) cout << " ExecuteKineticReactions" << "\n"; - #endif - - // Get the reaction interface data for checking for dried out nodes from eclipse coupling --> rateflag = 0 - REACTINT *m_rei = NULL; - if(REACTINT_vec.size()>0) - m_rei = REACTINT_vec[0]; - - if (NumberReactions > 0) - { - unsigned count = 0; - #if defined(USE_MPI) || defined(USE_MPI_KRC) - // MPI initialization. - // So here is going to distribute the task. - long nNodes = (long)nnodes; - MPI_Bcast ( &nNodes, 1, MPI_LONG, 0, comm_DDC ); - // here "myrank" is the index of the CPU Processes, and "mysize" is the number of CPU Processes - for ( it = myrank; it < nnodes ; it += mysize ) { - #else - for(it = 0; it < nnodes; it++){ - #endif -// substepping - for(tt=0;tts_water_limit) - if(m_rei->dried_out_nodes[node]) - dry = true; - } - // no reactions at Concentration BCs - if (is_a_CCBC[node] == true) - { - } - // CB no reactions at deactivated nodes - else if ((ReactDeactFlag) && (ReactDeact[node] == true)) - { - noototnodes ++; - } - // dryout node - else if (dry) - { - } - else{ - #if defined(USE_MPI) || defined(USE_MPI_KRC) - Biodegradation(Concentration_buff + node*nComponents, node, eps, hmin, &usedtneu, &nok, &nbad, tt, tsteps); - #else - #ifdef OGS_FEM_CAP - if (tt>0){ // update equilibrium system by call to chemapp - m_rei->ReactionPreProcessing(); - REACT_CAP_vec[0]->ExecuteReactionsChemApp(-1, it); // liquid - } - #endif - Biodegradation(Concentration + node*nComponents, node, eps, hmin, &usedtneu, &nok, &nbad, tt, tsteps); - - #ifdef OGS_FEM_CAP - if (tt < tsteps-1){ // update equilibrium system by call to chemapp - REACT_CAP_vec[0]->ExecuteReactionsChemApp(1, it); // solid+liquid - } - #endif - - #endif - if(usedtneu 1) usedt = usedtneu; // use last successfull timestep to continue integration over substeps - } - } // tt -// - - } // end for(node... - - // cout << " Total no. of RK-Steps: " << totsteps << "\n"; - - - // Get MPI results - #if defined(USE_MPI) || defined(USE_MPI_KRC) - MPI_Allreduce ( Concentration_buff, Concentration, nnodes*nComponents, MPI_DOUBLE, MPI_SUM, comm_DDC ); - #endif - // post-processing - //PostprocessNAPLDissolution(node); -/**/ - // update results - for(node_idx = 0; node_idx < nnodes; node_idx++){ - // only update those nodes, where Biodegradation() was executed - - dry = false; // by default, all nodes are wet - if(m_rei) { - if(m_rei->s_water_limit) - if(m_rei->dried_out_nodes[node_idx]) - dry = true; - } - - if(is_a_CCBC[node_idx] == true){ - } - else if((ReactDeactFlag)&&(ReactDeact[node_idx]== true)){ - } - else if(dry){ - } - else{ - for(int sp=0 ; sp < (nComponents-1) ; sp++){ - //Notlösung gegen das vollständige Absterben der Bakterien - if ((is_a_bacterium[sp]) && (Concentration[node_idx*nComponents+sp+1]SetNodeValue(node_idx,sp_varind[sp],Concentration[node_idx*nComponents+sp+1]); // CB HS update - cp_vec[sp]->getProcess()->SetNodeValue(node_idx,sp_varind[sp],Concentration[node_idx*nComponents+sp+1]); - // save exchange term SB todo - } - } - } // end of concentration update - cout << " Kinetic reactions executed at " << count << " of " << nnodes << " nodes." << "\n"; - cout << " Total no of nodes with reactions so far: " << noototnodes << "\n"; - cout << " Total no of nodes with reactions calculated so far: " << noocalcnodes << "\n"; - - - // sort noderanks according to computation time - if(sortnodes) - SortIterations ( substeps,noderanks,nnodes ); - //for(node_idx = 0; node_idx < nnodes; node_idx++) - // cout << substeps[node_idx] << " " << noderanks[node_idx] << "\n"; - - // CB Reaction deactivation for next time step - if(ReactDeactFlag) - { - //cout << " Kinetic reactions executed at " << count << " of " << nnodes << " nodes." << "\n"; - if(ReactDeactMode==2) // For mode 2 the C_new must be updated by C_old (C after eraction of last time step) - ReactDeactSetOldReactionTerms(nnodes); - //Aromaticum(nnodes); - } - } // end if(NumberRactions>0) + double usedtneu = 0.0; + long node; + size_t it, node_idx = 0; + int nok = 0, nbad = 0, totsteps = 0; + double* Concentration; // HS: concentration of all result + int nComponents; + bool dry = false; + // CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt + // CTimeDiscretization *m_tim = NULL; + int tt = 0, tsteps = 1; + // cout << " ExecuteKineticReactions" << "\n"; + + nComponents = (int)cp_vec.size(); + nComponents++; + + Concentration = new double[nComponents * nnodes]; + for (it = 0; it < (nComponents)*nnodes; it++) + Concentration[it] = 0.0; + if (this->sortnodes) + { + for (it = 0; it < nnodes; it++) + substeps[it] = 0; + } +#if defined(USE_MPI) || defined(USE_MPI_KRC) + if (this->NumberReactions > 0) + cout << " ExecuteKineticReactions MPI" + << "\n"; + double* Concentration_buff; + Concentration_buff = new double[nComponents * nnodes]; + for (it = 0; it < (long)(nComponents)*nnodes; it++) + Concentration_buff[it] = 0.0; +#else + if (this->NumberReactions > 0) + cout << " ExecuteKineticReactions" + << "\n"; +#endif + + // Get the reaction interface data for checking for dried out nodes from eclipse coupling --> rateflag = 0 + REACTINT* m_rei = NULL; + if (REACTINT_vec.size() > 0) + m_rei = REACTINT_vec[0]; + + if (NumberReactions > 0) + { + unsigned count = 0; +#if defined(USE_MPI) || defined(USE_MPI_KRC) + // MPI initialization. + // So here is going to distribute the task. + long nNodes = (long)nnodes; + MPI_Bcast(&nNodes, 1, MPI_LONG, 0, comm_DDC); + // here "myrank" is the index of the CPU Processes, and "mysize" is the number of CPU Processes + for (it = myrank; it < nnodes; it += mysize) + { +#else + for (it = 0; it < nnodes; it++) + { +#endif + // substepping + for (tt = 0; tt < tsteps; tt++) + { + if (sortnodes) // execute reactions at nodes in sequence according to no of substeps in last time + // step + node = noderanks[it]; + else + node = it; + // cout << node << "\n"; + + // check for dryout + dry = false; // by default, all nodes are wet + if (m_rei) + { + if (m_rei->s_water_limit) + if (m_rei->dried_out_nodes[node]) + dry = true; + } + // no reactions at Concentration BCs + if (is_a_CCBC[node] == true) + { + } + // CB no reactions at deactivated nodes + else if ((ReactDeactFlag) && (ReactDeact[node] == true)) + { + noototnodes++; + } + // dryout node + else if (dry) + { + } + else + { +#if defined(USE_MPI) || defined(USE_MPI_KRC) + Biodegradation(Concentration_buff + node * nComponents, node, eps, hmin, &usedtneu, &nok, &nbad, + tt, tsteps); +#else +#ifdef OGS_FEM_CAP + if (tt > 0) + { // update equilibrium system by call to chemapp + m_rei->ReactionPreProcessing(); + REACT_CAP_vec[0]->ExecuteReactionsChemApp(-1, it); // liquid + } +#endif + Biodegradation(Concentration + node * nComponents, node, eps, hmin, &usedtneu, &nok, &nbad, tt, + tsteps); + +#ifdef OGS_FEM_CAP + if (tt < tsteps - 1) + { // update equilibrium system by call to chemapp + REACT_CAP_vec[0]->ExecuteReactionsChemApp(1, it); // solid+liquid + } +#endif + +#endif + if (usedtneu < usedttmp) + { + usedttmp = usedtneu; + save_nok = nok; + save_nbad = nbad; + save_node = node; + } + count++; + totsteps = totsteps + nbad + nok; + noocalcnodes++; + noototnodes++; + + if (sortnodes) + substeps[node] = nbad + nok; // no of substeps as indicator for computation time + + if (tsteps > 1) + usedt = usedtneu; // use last successfull timestep to continue integration over substeps + } + } // tt + // + + } // end for(node... + +// cout << " Total no. of RK-Steps: " << totsteps << "\n"; + +// Get MPI results +#if defined(USE_MPI) || defined(USE_MPI_KRC) + MPI_Allreduce(Concentration_buff, Concentration, nnodes * nComponents, MPI_DOUBLE, MPI_SUM, comm_DDC); +#endif + // post-processing + // PostprocessNAPLDissolution(node); + /**/ + // update results + for (node_idx = 0; node_idx < nnodes; node_idx++) + { + // only update those nodes, where Biodegradation() was executed + + dry = false; // by default, all nodes are wet + if (m_rei) + { + if (m_rei->s_water_limit) + if (m_rei->dried_out_nodes[node_idx]) + dry = true; + } + + if (is_a_CCBC[node_idx] == true) + { + } + else if ((ReactDeactFlag) && (ReactDeact[node_idx] == true)) + { + } + else if (dry) + { + } + else + { + for (int sp = 0; sp < (nComponents - 1); sp++) + { + // Notlösung gegen das vollständige Absterben der Bakterien + if ((is_a_bacterium[sp]) + && (Concentration[node_idx * nComponents + sp + 1] < minBactConcentration)) + Concentration[node_idx * nComponents + sp + 1] = minBactConcentration; + // Konzentrationen aller Substanzen in Datenstruktur zurückschreiben + // pcs_vector[sp_pcsind[sp]]->SetNodeValue(node_idx,sp_varind[sp],Concentration[node_idx*nComponents+sp+1]); + // // CB HS update + cp_vec[sp]->getProcess()->SetNodeValue(node_idx, sp_varind[sp], + Concentration[node_idx * nComponents + sp + 1]); + // save exchange term SB todo + } + } + } // end of concentration update + cout << " Kinetic reactions executed at " << count << " of " << nnodes << " nodes." + << "\n"; + cout << " Total no of nodes with reactions so far: " << noototnodes << "\n"; + cout << " Total no of nodes with reactions calculated so far: " << noocalcnodes << "\n"; + + // sort noderanks according to computation time + if (sortnodes) + SortIterations(substeps, noderanks, nnodes); + // for(node_idx = 0; node_idx < nnodes; node_idx++) + // cout << substeps[node_idx] << " " << noderanks[node_idx] << "\n"; + + // CB Reaction deactivation for next time step + if (ReactDeactFlag) + { + // cout << " Kinetic reactions executed at " << count << " of " << nnodes << " nodes." << "\n"; + if (ReactDeactMode + == 2) // For mode 2 the C_new must be updated by C_old (C after eraction of last time step) + ReactDeactSetOldReactionTerms(nnodes); + // Aromaticum(nnodes); + } + } // end if(NumberRactions>0) if (usedttmp < usedt) { - cout << "\n" << "Kinetics in node " << save_node - << " limit integration step - nok: "; + cout << "\n" + << "Kinetics in node " << save_node << " limit integration step - nok: "; cout << save_nok << " nbad: " << save_nbad << "\n"; } // update des zul�ssigen Integrationsschritts, verwendet beim Aufruf von odeint // kleinster Wert, der in einem der Knoten zu einer zuverl�ssigen Integration gef�hrt hat // konservative, aber stabile Annahme - usedttmp = DMAX(usedttmp,hmin); + usedttmp = DMAX(usedttmp, hmin); usedt = DMIN(usedttmp, dt); - // cout << "\n" << " Next suggested integration step " << usedt << "\n"; - - #if defined(USE_MPI) || defined(USE_MPI_KRC) - // free_dvector(Concentration_buff,(long)1,(long)nComponents*nnodes); - delete [] Concentration_buff; - #endif - //free_dvector(Concentration,(long)1,(long)nComponents*nnodes); - delete [] Concentration; - +// cout << "\n" << " Next suggested integration step " << usedt << "\n"; +#if defined(USE_MPI) || defined(USE_MPI_KRC) + // free_dvector(Concentration_buff,(long)1,(long)nComponents*nnodes); + delete[] Concentration_buff; +#endif + // free_dvector(Concentration,(long)1,(long)nComponents*nnodes); + delete[] Concentration; } // end if((dt>1.E-20)&&(aktueller_zeitschritt>0)){ - if (debugoutflag) - debugoutstr.close(); - if (ReactDeactFlag) - if (ReactDeactPlotFlag == 1) - ReactDeactPlotFlagsToTec(); - + if (debugoutflag) + debugoutstr.close(); + if (ReactDeactFlag) + if (ReactDeactPlotFlag == 1) + ReactDeactPlotFlagsToTec(); } /**************************************************************************/ @@ -3820,470 +3934,518 @@ void CKinReactData::ExecuteKinReact(void) /* */ /**************************************************************************/ -void CKinReactData::Biodegradation( double *m_Conc, long node, double eps, double hmin, - double *usedtneu, int *nok, int *nbad, int tt, int tsteps) +void CKinReactData::Biodegradation(double* m_Conc, long node, double eps, double hmin, double* usedtneu, int* nok, + int* nbad, int tt, int tsteps) { - // double *Concentration; - double* newVolume = NULL; - double *oldVolume = NULL; - double *oldMass = NULL; - double nexth = 0.; - long sp;//, timelevel; - // int nok=0, nbad=0, Number_of_Components; - int Number_of_Components, nreactions, r, Sp1, blob, Number_of_blobs; - double Csat_max=0, DensityNAPL=0, DensityAQ=0, DiffusionAQ=0, ViscosityAQ=0, - PoreVelocity = 0.0, d50=0, Reynolds=0, Schmidt=0, Sherwood=0, NCont_Sh2=0; // NCont_Sh1=0, - double DarcyVelocity = 0.0; - double mod_Reynolds; - double beta_4, grain_var; //, grain_expo; - double one_three, two_three; - double Peclet, Delta; - double NAPLcontent = 1; - double WATERcontent = 1; - double Sat, Poro; - double tstart, tend, dt = 0.0; - double baditerations; - CRFProcess* m_pcs = NULL; - int idxS = 0; - int shidx; - CTimeDiscretization* m_tim = NULL; - float garage = 0; - bool success = false; - //double *m_Conc_save; // CB: for failure of ODE integration - // this is a temp array used to feed C as float to odeint in case integration failed - //m_Conc_save = new double[Number_of_Components]; - vector tempstore; - double variables[3]; - variables[0]=variables[1]=variables[2]=0; - bool Tflag = false; - //double A = 0; //Daq(T) PCE - //double B = 0; //Daq(T) PCE - bool gassdiss = false; - double Cmin = 0; - + // double *Concentration; + double* newVolume = NULL; + double* oldVolume = NULL; + double* oldMass = NULL; + double nexth = 0.; + long sp; //, timelevel; + // int nok=0, nbad=0, Number_of_Components; + int Number_of_Components, nreactions, r, Sp1, blob, Number_of_blobs; + double Csat_max = 0, DensityNAPL = 0, DensityAQ = 0, DiffusionAQ = 0, ViscosityAQ = 0, PoreVelocity = 0.0, d50 = 0, + Reynolds = 0, Schmidt = 0, Sherwood = 0, NCont_Sh2 = 0; // NCont_Sh1=0, + double DarcyVelocity = 0.0; + double mod_Reynolds; + double beta_4, grain_var; //, grain_expo; + double one_three, two_three; + double Peclet, Delta; + double NAPLcontent = 1; + double WATERcontent = 1; + double Sat, Poro; + double tstart, tend, dt = 0.0; + double baditerations; + CRFProcess* m_pcs = NULL; + int idxS = 0; + int shidx; + CTimeDiscretization* m_tim = NULL; + float garage = 0; + bool success = false; + // double *m_Conc_save; // CB: for failure of ODE integration + // this is a temp array used to feed C as float to odeint in case integration failed + // m_Conc_save = new double[Number_of_Components]; + vector tempstore; + double variables[3]; + variables[0] = variables[1] = variables[2] = 0; + bool Tflag = false; + // double A = 0; //Daq(T) PCE + // double B = 0; //Daq(T) PCE + bool gassdiss = false; + double Cmin = 0; CKinReact* m_kr = NULL; CKinBlob* m_kb = NULL; CKinReactData* m_krd = NULL; m_krd = KinReactData_vector[0]; - nreactions = m_krd->NumberReactions; - //timelevel = 1; // concentrations are in new timelevel + nreactions = m_krd->NumberReactions; + // timelevel = 1; // concentrations are in new timelevel if (time_vector.size() > 0) { m_tim = time_vector[0]; dt = m_tim->CalcTimeStep(); } - //Number_of_Components = kr_active_species; // - Number_of_Components = (int) cp_vec.size(); - // Get storage for vector of concentrations - // Concentration = dvector(1,Number_of_Components); + // Number_of_Components = kr_active_species; // + Number_of_Components = (int)cp_vec.size(); + // Get storage for vector of concentrations + // Concentration = dvector(1,Number_of_Components); /* Konzentrationen aller Substanzen aus Datenstruktur auslesen und in neuem Array speichern */ for (sp = 0; sp < Number_of_Components; sp++) { - m_Conc[sp+1] = cp_vec[sp]->getProcess()->GetNodeValue(node, sp_varind[sp]); - // CB reset concentrations below a threshhold to a minimum value - // 1e-19 and 0.0 by default - if(minConcentrationMode>0){ - if (minConcentrationMode==1) - Cmin = fabs(m_Conc[sp+1]); - else if (minConcentrationMode==2) - Cmin = m_Conc[sp+1] ; - if(Cmin < minConcentrationThreshhold) - m_Conc[sp+1] = minConcentrationSet; - } - //SB todo - ist abewr gerade eh noch ein dummy - //ExchangeTerm[sp]=TBCGetExchange(node,sp)/(dt); + m_Conc[sp + 1] = cp_vec[sp]->getProcess()->GetNodeValue(node, sp_varind[sp]); + // CB reset concentrations below a threshhold to a minimum value + // 1e-19 and 0.0 by default + if (minConcentrationMode > 0) + { + if (minConcentrationMode == 1) + Cmin = fabs(m_Conc[sp + 1]); + else if (minConcentrationMode == 2) + Cmin = m_Conc[sp + 1]; + if (Cmin < minConcentrationThreshhold) + m_Conc[sp + 1] = minConcentrationSet; + } + // SB todo - ist abewr gerade eh noch ein dummy + // ExchangeTerm[sp]=TBCGetExchange(node,sp)/(dt); } - // CB CLEAN speed up fix - //if(m_Conc[12] < 5 ) return; // CO2 concentration - if(debugoutflag) - { - if(node==1){ - debugoutstr << "node timestep " << flush; - //debugoutstr << " Concentrations before odeint: " << "\n" << " " << flush; - for(sp=0;spgetProcess()->nod_val_name_vector[0] - << " " << flush; - debugoutstr << " SATURATION1 " << flush; - - //debugoutstr << pcs_vector[sp_pcsind[sp]]->nod_val_name_vector[0] << " " << flush; // CB HS update - debugoutstr << "usedt nok nbad" << "\n"; - } - debugoutstr << node << " " << aktueller_zeitschritt << " " - << flush; - for(sp=0;spGetSaturation(node, 1, 1) << " " << flush; - debugoutstr << usedt <<" - -" << "\n" << flush; - } + // CB CLEAN speed up fix + // if(m_Conc[12] < 5 ) return; // CO2 concentration + if (debugoutflag) + { + if (node == 1) + { + debugoutstr << "node timestep " << flush; + // debugoutstr << " Concentrations before odeint: " << "\n" << " " << flush; + for (sp = 0; sp < Number_of_Components; sp++) + debugoutstr << cp_vec[sp]->getProcess()->nod_val_name_vector[0] << " " << flush; + debugoutstr << " SATURATION1 " << flush; + + // debugoutstr << pcs_vector[sp_pcsind[sp]]->nod_val_name_vector[0] << " " << flush; // CB HS update + debugoutstr << "usedt nok nbad" + << "\n"; + } + debugoutstr << node << " " << aktueller_zeitschritt << " " << flush; + for (sp = 0; sp < Number_of_Components; sp++) + debugoutstr << m_Conc[sp + 1] << " " << flush; + debugoutstr << KinReact_vector[0]->GetSaturation(node, 1, 1) << " " << flush; + debugoutstr << usedt << " - -" + << "\n" + << flush; + } //#ds /* PREPARE PARAMETERS FOR NAPL-DISSOLUION*/ /* calculate Mass and Volume of blobs for this node */ - // first get T - for(r=0;r<(int)KinReact_vector.size();r++){ - if(KinReact_vector[r]->T_dependence==true && KinReact_vector[r]->typeflag_napldissolution==1){ - Tflag = true; - if(REACTINT_vec.size()>0) // Get the Temperature - variables[1] = REACTINT_vec[0]->GetTemperature(node); - break; - } - } - - if(Tflag==false) //CB, SP, 19.04.2013, get Temp. for DensityAQ calculations - if((mfp_vector[0]->getCompressibilityTModel()!=0) || (mfp_vector[0]->diffusion_model==2)) - if(REACTINT_vec.size()>0) // Get the Temperature - variables[1] = REACTINT_vec[0]->GetTemperature(node); - - //set all mass(blob)=0, volume(blob)=0 - Number_of_blobs = (int) KinBlob_vector.size(); - if(Number_of_blobs>0){ - - for (r=0; rgas_dissolution_flag){ - gassdiss = true; - break; - } - } - - - if(gassdiss==false) - DensityAQ = mfp_vector[0]->Density(variables); // should be returned as temperature dependent value, if required - if(Tflag){ - if(REACTINT_vec.size()>0) // Get the Temperature - if(REACTINT_vec[0]->constanttemperature){ - variables[1] = REACTINT_vec[0]->GetTemperature(node); - DensityAQ = REACTINT_vec[0]->LiquidDensity_Busch(variables[1]); - } - } - - // get storage for local data structures - oldVolume = dvector(0,Number_of_blobs); - oldMass = dvector(0,Number_of_blobs); - newVolume = dvector(0,Number_of_blobs); - // initialize - for (r = 0; r < Number_of_blobs; r++) - oldVolume[r] = oldMass[r] = newVolume[r] = 0.; - // 1) Here, calculate current Mass and old Volume of NAPL for each blob - // - Mass is required for computing current Csat in 2) - // - old Volume is required for updating Interfacial Area in postprocessing - if(KinBlob_vector[0]->gas_dissolution_flag == false){ - for (r = 0; r < nreactions; r++) + // first get T + for (r = 0; r < (int)KinReact_vector.size(); r++) { - m_kr = KinReact_vector[r]; - // CB new reaction switch for individual reactions - if (m_kr->switched_off_node.size() > 0) - if (m_kr->switched_off_node[node] == true) - continue; - if (m_kr->typeflag_napldissolution) //dissolution reaction identified + if (KinReact_vector[r]->T_dependence == true && KinReact_vector[r]->typeflag_napldissolution == 1) { - Sp1 = m_kr->ex_species[0] + 1; //Sp1 = NAPL-species - blob = m_kr->blob_ID; - DensityNAPL = cp_vec[Sp1 - 1]->molar_density; - //DensityNAPL = m_kr->Density_NAPL; // CB: this should be obtained from comp properties - m_kb = KinBlob_vector[blob]; // pointer to blob-properties set in the reaction r - if(m_Conc[Sp1] > 0.) - { - //new local data structures - oldMass[blob] += DMAX(m_Conc[Sp1],0.); - oldVolume[blob] += DMAX(m_Conc[Sp1],0.) / DensityNAPL; - //Sb todo Achtung - das wird ja gar nicht zurückgespeichert... - } - } - } // end for nreactions - } - - // 2) Now, calculate current Csat for each species (i.e. reaction) depending on Raoults law for this node. - // This requires previously calculated Mass. - for (r=0; rswitched_off_node.size()>0) - if(m_kr->switched_off_node[node]== true) - continue; - if(m_kr->typeflag_napldissolution) //dissolution reaction identifie - { - if(m_kr->typeflag_gasdissolution == 1){ - Csat_max = m_kr->GetMaxSolubility(node, 0); - m_kr->Current_Csat[node] = Csat_max; // keine NAPL-Masse vorhanden, NAPL-Bildung möglich wenn c(singleSubstance) > Csat - } - else { - Sp1 = m_kr->ex_species[0]+1; //Sp1 = NAPL-species - Csat_max = m_kr->GetMaxSolubility(node, DensityAQ); - //Csat_max = cp_vec[Sp1-1]->max_solubility; - blob = m_kr->blob_ID; - if (oldMass[blob] > 0.) - m_kr->Current_Csat[node] = Csat_max * DMAX(m_Conc[Sp1],0.) - / oldMass[blob]; - else - //m_kr->current_Csat = Csat_max; // keine NAPL-Masse vorhanden, NAPL-Bildung möglich wenn c(singleSubstance) > Csat - m_kr->Current_Csat[node] = Csat_max; // keine NAPL-Masse vorhanden, NAPL-Bildung möglich wenn c(singleSubstance) > Csat - } - } - } // end for nreactions - - // 3) Next, calculate current Masstransfer-coefficient k for this node - // First, get the pore velocity for mass transfer coefficient - for (r=0; rswitched_off_node.size()>0) - if(m_kr->switched_off_node[node]== true) - continue; - if(m_kr->typeflag_napldissolution){ - PoreVelocity = m_kr->GetNodePoreVelocity(node); - DarcyVelocity = m_kr->GetNodeDarcyVelocity(node); //SP: added for Sherwood calculation after Powers et al. 1992 - break; // do this only once - } - } - // calculate current Masstransfer-coefficient - if(Tflag == false) - DiffusionAQ = mfp_vector[0]->PhaseDiffusion(variables); //SP: Implemented to be temperature dependent - if(gassdiss==false) - ViscosityAQ = mfp_vector[0]->Viscosity(variables); // in case of heat transport this T dependent - //mfp_vector[0]->mode = tmod; - if(Tflag){ - if(REACTINT_vec.size()>0) // Get the Temperature - //if(REACTINT_vec[0]->constanttemperature){ - variables[1] = REACTINT_vec[0]->GetTemperature(node); - ViscosityAQ = REACTINT_vec[0]->LiquidViscosity_Yaws_1976(variables[1]); - //} - } - - // calculate current Masstransfer-coefficient - m_pcs = PCSGetFlow(); - Poro = KinReact_vector[0]->GetPhaseVolumeAtNode(node, 1, 0); - idxS = m_pcs->GetNodeValueIndex("SATURATION2")+1; // new timelevel - NAPLcontent = MRange(0, m_pcs->GetNodeValue(node, idxS)*Poro, Poro); - WATERcontent = Poro-NAPLcontent; - - for (r=0; rd50; - shidx = m_kb->shidx; - if(m_kb->gas_dissolution_flag == false){ - DiffusionAQ = mfp_vector[0]->PhaseDiffusion(variables); // CB Todo: this should be a component property => Sherwood is component dependent - DensityAQ = mfp_vector[0]->Density(variables); - //ViscosityAQ = mfp_vector[0]->Viscosity(); - mod_Reynolds = DensityAQ * PoreVelocity * d50 / ViscosityAQ ; // modified Re' includes transport velo - Reynolds = DensityAQ * DarcyVelocity * d50 / ViscosityAQ ; // Re includes darcy velo - Schmidt = ViscosityAQ / DiffusionAQ / DensityAQ ; - Peclet = PoreVelocity * WATERcontent * d50 / DiffusionAQ; - Delta = d50 / m_kb->dM; - grain_var = d50/m_kb->dS; - //NCont_Sh1 = m_kb->NCont_ini / m_kb->NCont_ini ; - NCont_Sh2 = NAPLcontent / m_kb->NCont_ini ; - beta_4 = 0.518+0.114*Delta+0.1+m_kb->UI ; - one_three = 1.00/3.00; - two_three = 2.00/3.00; - - switch(shidx) - { - case 0: // Standard Sherwood calculation after Bradford and Abriola (2001) - Sherwood = m_kb->Sh_factor * pow(mod_Reynolds, m_kb->Re_expo) * pow(Schmidt, m_kb->Sc_expo) ; - break; - case 1: // Sherwood calculation after Powers et al. (1994) - //Sherwood = m_kb->Sh_factor * pow(Reynolds, m_kb->Re_expo) * pow(Delta, m_kb->Delta_expo) * pow(m_kb->UI, m_kb->UI_expo) * pow(m_kb->NCont_ini, m_kb->Geometry_expo) ; - Sherwood = m_kb->Sh_factor * pow(mod_Reynolds, m_kb->Re_expo) * pow(Delta, m_kb->Delta_expo) * pow(m_kb->UI, m_kb->UI_expo) * pow(NCont_Sh2, beta_4) ; - break; - case 2: // Sherwood calculation after Powers et al. (1992) - Sherwood = m_kb->Sh_factor * pow(Reynolds, m_kb->Re_expo) * pow(d50, m_kb->D50_expo) * pow(m_kb->UI, m_kb->UI_expo) ; - break; - case 3: // Sherwood calculation after Wilson and Geankoplis (1966) - Sherwood = m_kb->Sh_factor * pow(Poro, -1) * pow(Peclet, one_three); - break; - case 4: // Sherwood calculation after Pfannkuch (1984) - Sherwood = m_kb->Sh_factor + m_kb->Pfannkuch_constant * pow(Peclet, two_three) ; - break; - case 5: // Sherwood calculation after Miller et al. (1990) - Sherwood = m_kb->Sh_factor * pow(mod_Reynolds, m_kb->Re_expo) * pow(WATERcontent, m_kb->WContent_expo) * pow(Schmidt, m_kb->Sc_expo) ; - break; - case 6: // Sherwood calculation after Saba&Illangasekare (2000) - Sherwood = m_kb->Sh_factor * pow(mod_Reynolds, m_kb->Re_expo) * pow(Schmidt, m_kb->Sc_expo) * ((d50*NAPLcontent)/(m_kb->Tort*m_kb->Length)) ; - break; - case 7: // Sherwood calculation after Geller&Hunt (1993) - Sherwood = m_kb->Sh_factor * pow(mod_Reynolds, m_kb->Re_expo) * pow(NAPLcontent, m_kb->NContent_expo) * pow(m_kb->NCont_ini, m_kb->NContent_ini_expo) * pow(Poro, m_kb->Poro_expo) * pow(grain_var, m_kb->grain_expo) ; - break; - default: - break; - - } - } - else if(m_kb->gas_dissolution_flag == true) - Sherwood = d50 * (4/d50 + pow((2*PoreVelocity/PI/d50/DiffusionAQ), 0.5)); - - if(m_kb->Sherwood_model==false) - m_kb->Masstransfer_K[node] = Sherwood * DiffusionAQ / d50 ; //k in m/s - else if(m_kb->Sherwood_model==true) // modified Sh'= k * (d50)^2 / Daq --> k = Sh*Daq/(d50)^2 - m_kb->Masstransfer_K[node] = Sherwood * DiffusionAQ / (d50*d50) ; //k in m/s - } - - // This step is necessary only for gas dissolution, as saturation changes over time - // 4) Finally, save current Interfacial areas for this node. - for (r=0; rgas_dissolution_flag){ - Poro = KinReact_vector[0]->GetPhaseVolumeAtNode(node, 1, 0); - Sat = KinReact_vector[0]->GetSaturation(node, 1, 1); - m_kb->Interfacial_area[node] = 12 * Sat * Poro / d50 * m_kb->Area_Value[0]; - } - } - } // if No of blobs > 0 - - - /**********************************************/ - /* ODE Integration */ - /**********************************************/ - tstart = DMAX(aktuelle_zeit - dt,0.); - tend = aktuelle_zeit; - // calculate substep length - tstart += dt * double(tt)/double(tsteps); - tend -= dt * double(tsteps-(tt+1))/double(tsteps); - /* Aufruf Gleichungsl�ser */ - /* eigentliche Rechenroutinen sind "derivs" und "jacobn" (namen fest vorgegeben), - die vom Gleichungsl�ser aufgerufen werden */ - if(SolverType==0){ - Calc_linearized_rates(m_Conc, Number_of_Components,tend-tstart, node); - success = true; // works always - *nok = 1; - *nbad = 0; - } - else{ - success = odeint(m_Conc, Number_of_Components,tstart,tend,eps,usedt,hmin,&nexth,nok,nbad,derivs,stifbs,rkqs,node, SolverType); - - if(success==0){ // if odeint failed for some reason - cout << "Warning in CKinReactData::Biodegradation: Odeint did not converge at node " << node << "." << "\n"; - cout << " -Trying increased relative error " << eps*10 << "\n"; - success = odeint(m_Conc, Number_of_Components,tstart,tend,eps*10,usedt,hmin,&nexth,nok,nbad,derivs,stifbs,rkqs,node, SolverType); - if(success==0){ - cout << " -Trying perturbation of initial time step usedt" << "\n"; - success = odeint(m_Conc, Number_of_Components,tstart,tend,eps,usedt*0.99,hmin,&nexth,nok,nbad,derivs,stifbs,rkqs,node, SolverType); - if(success==0){ - cout << " -Trying conversion of C vector from double to float." << "\n"; - for(sp=0;sp usedt) - *usedtneu = DMAX(nexth,usedt * 2.); - else - *usedtneu = usedt * 1.5; - } - else - { - // Integrationsfehler, zeitschritt beibehalten oder verkleinern - if (*nbad == 1) - *usedtneu = DMAX(nexth,usedt * 1.10); - else if (*nok > *nbad * 2) - *usedtneu = DMAX(nexth,usedt * 1.01); - else - *usedtneu = DMAX(nexth,usedt / 5.); + Tflag = true; + if (REACTINT_vec.size() > 0) // Get the Temperature + variables[1] = REACTINT_vec[0]->GetTemperature(node); + break; + } } -// update results, now outside in ExecuteKinReact + if (Tflag == false) // CB, SP, 19.04.2013, get Temp. for DensityAQ calculations + if ((mfp_vector[0]->getCompressibilityTModel() != 0) || (mfp_vector[0]->diffusion_model == 2)) + if (REACTINT_vec.size() > 0) // Get the Temperature + variables[1] = REACTINT_vec[0]->GetTemperature(node); - if (debugoutflag) + // set all mass(blob)=0, volume(blob)=0 + Number_of_blobs = (int)KinBlob_vector.size(); + if (Number_of_blobs > 0) { - //debugoutstr << " Concentrations after odeint: " << "\n" << " " << flush; - debugoutstr << node << " " << aktueller_zeitschritt << " " - << flush; - for (sp = 0; sp < Number_of_Components; sp++) - debugoutstr << m_Conc[sp+1] << " " << flush; - debugoutstr << KinReact_vector[0]->GetSaturation(node, 1, 1) << " " << flush; - debugoutstr << nexth << " " << int(*nok) << " " << int(*nbad) << "\n" << flush; - } - - /**********************************************/ - /* Postprocessing NAPL Dissolution */ - /* calculate Interfacial areas for this node after dissolution for next time step */ - /**********************************************/ - if(Number_of_blobs > 0) { - if(KinBlob_vector[0]->gas_dissolution_flag == false){ - for (r = 0; r < nreactions; r++) - { - m_kr = KinReact_vector[r]; - // CB new reaction switch for individual reactions - if (m_kr->switched_off_node.size() > 0) - if (m_kr->switched_off_node[node] == true) - continue; - if (m_kr->typeflag_napldissolution) //dissolution reaction identified - { - Sp1 = m_kr->ex_species[0] + 1; //Sp1 = NAPL-species - blob = m_kr->blob_ID; - DensityNAPL = cp_vec[Sp1 - 1]->molar_density; - newVolume[blob] += DMAX(m_Conc[Sp1],0.) / DensityNAPL; - } - } // end for nreactions - for (r = 0; r < Number_of_blobs; r++) - { - m_kb = KinBlob_vector[r]; - if ((newVolume[r] > 0.) && (oldVolume[r] > 0.)) - m_kb->Interfacial_area[node] *= pow( (newVolume[r] / oldVolume[r]), m_kb->Geometry_expo) ; - else - m_kb->Interfacial_area[node] = 1.E-20; //residual interfacial area to allow re-building of phase - } - } - // Free storage - free_dvector(newVolume,0,Number_of_blobs); - free_dvector(oldVolume,0,Number_of_blobs); - free_dvector(oldMass,0,Number_of_blobs); - }// if No of blobs > 0 - // free_dvector(Concentration,1,Number_of_Components); - //free(m_Conc_save); - tempstore.clear(); + for (r = 0; r < Number_of_blobs; r++) + { + if (KinBlob_vector[r]->gas_dissolution_flag) + { + gassdiss = true; + break; + } + } -} + if (gassdiss == false) + DensityAQ + = mfp_vector[0]->Density(variables); // should be returned as temperature dependent value, if required + if (Tflag) + { + if (REACTINT_vec.size() > 0) // Get the Temperature + if (REACTINT_vec[0]->constanttemperature) + { + variables[1] = REACTINT_vec[0]->GetTemperature(node); + DensityAQ = REACTINT_vec[0]->LiquidDensity_Busch(variables[1]); + } + } -void CKinReactData::Calc_linearized_rates( double *m_Conc, long Number_of_Components, double deltaT, long node) -{ - double *dydx; + // get storage for local data structures + oldVolume = dvector(0, Number_of_blobs); + oldMass = dvector(0, Number_of_blobs); + newVolume = dvector(0, Number_of_blobs); + // initialize + for (r = 0; r < Number_of_blobs; r++) + oldVolume[r] = oldMass[r] = newVolume[r] = 0.; + // 1) Here, calculate current Mass and old Volume of NAPL for each blob + // - Mass is required for computing current Csat in 2) + // - old Volume is required for updating Interfacial Area in postprocessing + if (KinBlob_vector[0]->gas_dissolution_flag == false) + { + for (r = 0; r < nreactions; r++) + { + m_kr = KinReact_vector[r]; + // CB new reaction switch for individual reactions + if (m_kr->switched_off_node.size() > 0) + if (m_kr->switched_off_node[node] == true) + continue; + if (m_kr->typeflag_napldissolution) // dissolution reaction identified + { + Sp1 = m_kr->ex_species[0] + 1; // Sp1 = NAPL-species + blob = m_kr->blob_ID; + DensityNAPL = cp_vec[Sp1 - 1]->molar_density; + // DensityNAPL = m_kr->Density_NAPL; // CB: this should be obtained from comp properties + m_kb = KinBlob_vector[blob]; // pointer to blob-properties set in the reaction r + if (m_Conc[Sp1] > 0.) + { + // new local data structures + oldMass[blob] += DMAX(m_Conc[Sp1], 0.); + oldVolume[blob] += DMAX(m_Conc[Sp1], 0.) / DensityNAPL; + // Sb todo Achtung - das wird ja gar nicht zurückgespeichert... + } + } + } // end for nreactions + } - dydx=dvector(1,Number_of_Components); - derivs(deltaT, m_Conc,dydx,Number_of_Components,node, deltaT); - for(long i = 0;iswitched_off_node.size() > 0) + if (m_kr->switched_off_node[node] == true) + continue; + if (m_kr->typeflag_napldissolution) // dissolution reaction identifie + { + if (m_kr->typeflag_gasdissolution == 1) + { + Csat_max = m_kr->GetMaxSolubility(node, 0); + m_kr->Current_Csat[node] + = Csat_max; // keine NAPL-Masse vorhanden, NAPL-Bildung möglich wenn c(singleSubstance) > Csat + } + else + { + Sp1 = m_kr->ex_species[0] + 1; // Sp1 = NAPL-species + Csat_max = m_kr->GetMaxSolubility(node, DensityAQ); + // Csat_max = cp_vec[Sp1-1]->max_solubility; + blob = m_kr->blob_ID; + if (oldMass[blob] > 0.) + m_kr->Current_Csat[node] = Csat_max * DMAX(m_Conc[Sp1], 0.) / oldMass[blob]; + else + // m_kr->current_Csat = Csat_max; // keine NAPL-Masse vorhanden, NAPL-Bildung + // möglich wenn c(singleSubstance) > Csat + m_kr->Current_Csat[node] = Csat_max; // keine NAPL-Masse vorhanden, NAPL-Bildung möglich wenn + // c(singleSubstance) > Csat + } + } + } // end for nreactions -} + // 3) Next, calculate current Masstransfer-coefficient k for this node + // First, get the pore velocity for mass transfer coefficient + for (r = 0; r < nreactions; r++) + { + m_kr = KinReact_vector[r]; + // CB new reaction switch for individual reactions + if (m_kr->switched_off_node.size() > 0) + if (m_kr->switched_off_node[node] == true) + continue; + if (m_kr->typeflag_napldissolution) + { + PoreVelocity = m_kr->GetNodePoreVelocity(node); + DarcyVelocity + = m_kr->GetNodeDarcyVelocity(node); // SP: added for Sherwood calculation after Powers et al. 1992 + break; // do this only once + } + } + // calculate current Masstransfer-coefficient + if (Tflag == false) + DiffusionAQ = mfp_vector[0]->PhaseDiffusion(variables); // SP: Implemented to be temperature dependent + if (gassdiss == false) + ViscosityAQ = mfp_vector[0]->Viscosity(variables); // in case of heat transport this T dependent + // mfp_vector[0]->mode = tmod; + if (Tflag) + { + if (REACTINT_vec.size() > 0) // Get the Temperature + // if(REACTINT_vec[0]->constanttemperature){ + variables[1] = REACTINT_vec[0]->GetTemperature(node); + ViscosityAQ = REACTINT_vec[0]->LiquidViscosity_Yaws_1976(variables[1]); + //} + } + // calculate current Masstransfer-coefficient + m_pcs = PCSGetFlow(); + Poro = KinReact_vector[0]->GetPhaseVolumeAtNode(node, 1, 0); + idxS = m_pcs->GetNodeValueIndex("SATURATION2") + 1; // new timelevel + NAPLcontent = MRange(0, m_pcs->GetNodeValue(node, idxS) * Poro, Poro); + WATERcontent = Poro - NAPLcontent; -/*************************************************************************************/ -/* Routine f�r Bulirsch-Stoer Gleichungsl�ser (steife ODEs) */ -/* DS-TBC */ -/* */ -/* Berechnung der ersten Ableitungen �ber die Zeit dC/dt=... */ -/* */ -/* Input: */ -/* t = aktuelle Zeit */ + for (r = 0; r < Number_of_blobs; r++) + { + m_kb = KinBlob_vector[r]; + d50 = m_kb->d50; + shidx = m_kb->shidx; + if (m_kb->gas_dissolution_flag == false) + { + DiffusionAQ = mfp_vector[0]->PhaseDiffusion( + variables); // CB Todo: this should be a component property => Sherwood is component dependent + DensityAQ = mfp_vector[0]->Density(variables); + // ViscosityAQ = mfp_vector[0]->Viscosity(); + mod_Reynolds = DensityAQ * PoreVelocity * d50 / ViscosityAQ; // modified Re' includes transport velo + Reynolds = DensityAQ * DarcyVelocity * d50 / ViscosityAQ; // Re includes darcy velo + Schmidt = ViscosityAQ / DiffusionAQ / DensityAQ; + Peclet = PoreVelocity * WATERcontent * d50 / DiffusionAQ; + Delta = d50 / m_kb->dM; + grain_var = d50 / m_kb->dS; + // NCont_Sh1 = m_kb->NCont_ini / m_kb->NCont_ini ; + NCont_Sh2 = NAPLcontent / m_kb->NCont_ini; + beta_4 = 0.518 + 0.114 * Delta + 0.1 + m_kb->UI; + one_three = 1.00 / 3.00; + two_three = 2.00 / 3.00; + + switch (shidx) + { + case 0: // Standard Sherwood calculation after Bradford and Abriola (2001) + Sherwood = m_kb->Sh_factor * pow(mod_Reynolds, m_kb->Re_expo) * pow(Schmidt, m_kb->Sc_expo); + break; + case 1: // Sherwood calculation after Powers et al. (1994) + // Sherwood = m_kb->Sh_factor * pow(Reynolds, m_kb->Re_expo) * pow(Delta, m_kb->Delta_expo) * + // pow(m_kb->UI, m_kb->UI_expo) * pow(m_kb->NCont_ini, m_kb->Geometry_expo) ; + Sherwood = m_kb->Sh_factor * pow(mod_Reynolds, m_kb->Re_expo) * pow(Delta, m_kb->Delta_expo) + * pow(m_kb->UI, m_kb->UI_expo) * pow(NCont_Sh2, beta_4); + break; + case 2: // Sherwood calculation after Powers et al. (1992) + Sherwood = m_kb->Sh_factor * pow(Reynolds, m_kb->Re_expo) * pow(d50, m_kb->D50_expo) + * pow(m_kb->UI, m_kb->UI_expo); + break; + case 3: // Sherwood calculation after Wilson and Geankoplis (1966) + Sherwood = m_kb->Sh_factor * pow(Poro, -1) * pow(Peclet, one_three); + break; + case 4: // Sherwood calculation after Pfannkuch (1984) + Sherwood = m_kb->Sh_factor + m_kb->Pfannkuch_constant * pow(Peclet, two_three); + break; + case 5: // Sherwood calculation after Miller et al. (1990) + Sherwood = m_kb->Sh_factor * pow(mod_Reynolds, m_kb->Re_expo) + * pow(WATERcontent, m_kb->WContent_expo) * pow(Schmidt, m_kb->Sc_expo); + break; + case 6: // Sherwood calculation after Saba&Illangasekare (2000) + Sherwood = m_kb->Sh_factor * pow(mod_Reynolds, m_kb->Re_expo) * pow(Schmidt, m_kb->Sc_expo) + * ((d50 * NAPLcontent) / (m_kb->Tort * m_kb->Length)); + break; + case 7: // Sherwood calculation after Geller&Hunt (1993) + Sherwood = m_kb->Sh_factor * pow(mod_Reynolds, m_kb->Re_expo) + * pow(NAPLcontent, m_kb->NContent_expo) + * pow(m_kb->NCont_ini, m_kb->NContent_ini_expo) * pow(Poro, m_kb->Poro_expo) + * pow(grain_var, m_kb->grain_expo); + break; + default: + break; + } + } + else if (m_kb->gas_dissolution_flag == true) + Sherwood = d50 * (4 / d50 + pow((2 * PoreVelocity / PI / d50 / DiffusionAQ), 0.5)); + + if (m_kb->Sherwood_model == false) + m_kb->Masstransfer_K[node] = Sherwood * DiffusionAQ / d50; // k in m/s + else if (m_kb->Sherwood_model == true) // modified Sh'= k * (d50)^2 / Daq --> k = Sh*Daq/(d50)^2 + m_kb->Masstransfer_K[node] = Sherwood * DiffusionAQ / (d50 * d50); // k in m/s + } + + // This step is necessary only for gas dissolution, as saturation changes over time + // 4) Finally, save current Interfacial areas for this node. + for (r = 0; r < Number_of_blobs; r++) + { + m_kb = KinBlob_vector[r]; + if (m_kb->gas_dissolution_flag) + { + Poro = KinReact_vector[0]->GetPhaseVolumeAtNode(node, 1, 0); + Sat = KinReact_vector[0]->GetSaturation(node, 1, 1); + m_kb->Interfacial_area[node] = 12 * Sat * Poro / d50 * m_kb->Area_Value[0]; + } + } + } // if No of blobs > 0 + + /**********************************************/ + /* ODE Integration */ + /**********************************************/ + tstart = DMAX(aktuelle_zeit - dt, 0.); + tend = aktuelle_zeit; + // calculate substep length + tstart += dt * double(tt) / double(tsteps); + tend -= dt * double(tsteps - (tt + 1)) / double(tsteps); + /* Aufruf Gleichungsl�ser */ + /* eigentliche Rechenroutinen sind "derivs" und "jacobn" (namen fest vorgegeben), + die vom Gleichungsl�ser aufgerufen werden */ + if (SolverType == 0) + { + Calc_linearized_rates(m_Conc, Number_of_Components, tend - tstart, node); + success = true; // works always + *nok = 1; + *nbad = 0; + } + else + { + success = odeint(m_Conc, Number_of_Components, tstart, tend, eps, usedt, hmin, &nexth, nok, nbad, derivs, + stifbs, rkqs, node, SolverType); + + if (success == 0) + { // if odeint failed for some reason + cout << "Warning in CKinReactData::Biodegradation: Odeint did not converge at node " << node << "." + << "\n"; + cout << " -Trying increased relative error " << eps * 10 << "\n"; + success = odeint(m_Conc, Number_of_Components, tstart, tend, eps * 10, usedt, hmin, &nexth, nok, nbad, + derivs, stifbs, rkqs, node, SolverType); + if (success == 0) + { + cout << " -Trying perturbation of initial time step usedt" + << "\n"; + success = odeint(m_Conc, Number_of_Components, tstart, tend, eps, usedt * 0.99, hmin, &nexth, nok, nbad, + derivs, stifbs, rkqs, node, SolverType); + if (success == 0) + { + cout << " -Trying conversion of C vector from double to float." + << "\n"; + for (sp = 0; sp < Number_of_Components; sp++) + { + tempstore.push_back(m_Conc[sp + 1]); + garage = float(m_Conc[sp + 1]); + m_Conc[sp + 1] = double(garage); + } + success = odeint(m_Conc /*_save*/, Number_of_Components, tstart, tend, eps, usedt, hmin, &nexth, + nok, nbad, derivs, stifbs, rkqs, node, SolverType); + // if(success) for(sp=0;sp usedt) + *usedtneu = DMAX(nexth, usedt * 2.); + else + *usedtneu = usedt * 1.5; + } + else + { + // Integrationsfehler, zeitschritt beibehalten oder verkleinern + if (*nbad == 1) + *usedtneu = DMAX(nexth, usedt * 1.10); + else if (*nok > *nbad * 2) + *usedtneu = DMAX(nexth, usedt * 1.01); + else + *usedtneu = DMAX(nexth, usedt / 5.); + } + + // update results, now outside in ExecuteKinReact + + if (debugoutflag) + { + // debugoutstr << " Concentrations after odeint: " << "\n" << " " << flush; + debugoutstr << node << " " << aktueller_zeitschritt << " " << flush; + for (sp = 0; sp < Number_of_Components; sp++) + debugoutstr << m_Conc[sp + 1] << " " << flush; + debugoutstr << KinReact_vector[0]->GetSaturation(node, 1, 1) << " " << flush; + debugoutstr << nexth << " " << int(*nok) << " " << int(*nbad) << "\n" << flush; + } + + /**********************************************/ + /* Postprocessing NAPL Dissolution */ + /* calculate Interfacial areas for this node after dissolution for next time step */ + /**********************************************/ + if (Number_of_blobs > 0) + { + if (KinBlob_vector[0]->gas_dissolution_flag == false) + { + for (r = 0; r < nreactions; r++) + { + m_kr = KinReact_vector[r]; + // CB new reaction switch for individual reactions + if (m_kr->switched_off_node.size() > 0) + if (m_kr->switched_off_node[node] == true) + continue; + if (m_kr->typeflag_napldissolution) // dissolution reaction identified + { + Sp1 = m_kr->ex_species[0] + 1; // Sp1 = NAPL-species + blob = m_kr->blob_ID; + DensityNAPL = cp_vec[Sp1 - 1]->molar_density; + newVolume[blob] += DMAX(m_Conc[Sp1], 0.) / DensityNAPL; + } + } // end for nreactions + for (r = 0; r < Number_of_blobs; r++) + { + m_kb = KinBlob_vector[r]; + if ((newVolume[r] > 0.) && (oldVolume[r] > 0.)) + m_kb->Interfacial_area[node] *= pow((newVolume[r] / oldVolume[r]), m_kb->Geometry_expo); + else + m_kb->Interfacial_area[node] = 1.E-20; // residual interfacial area to allow re-building of phase + } + } + // Free storage + free_dvector(newVolume, 0, Number_of_blobs); + free_dvector(oldVolume, 0, Number_of_blobs); + free_dvector(oldMass, 0, Number_of_blobs); + } // if No of blobs > 0 + // free_dvector(Concentration,1,Number_of_Components); + // free(m_Conc_save); + tempstore.clear(); +} + +void CKinReactData::Calc_linearized_rates(double* m_Conc, long Number_of_Components, double deltaT, long node) +{ + double* dydx; + + dydx = dvector(1, Number_of_Components); + derivs(deltaT, m_Conc, dydx, Number_of_Components, node, deltaT); + for (long i = 0; i < Number_of_Components; i++) + m_Conc[i + 1] += dydx[i + 1] * deltaT; +} + +/*************************************************************************************/ +/* Routine f�r Bulirsch-Stoer Gleichungsl�ser (steife ODEs) */ +/* DS-TBC */ +/* */ +/* Berechnung der ersten Ableitungen �ber die Zeit dC/dt=... */ +/* */ +/* Input: */ +/* t = aktuelle Zeit */ /* c[1..Number_of_Components] = aktuelle Konzentration der Substanzen in Zelle */ /* n =! Number_of_Components */ /* */ @@ -4300,14 +4462,14 @@ void CKinReactData::Calc_linearized_rates( double *m_Conc, long Number_of_Compon void derivs(double t, double c[], double dcdt[], int n, long node, double /*steplength*/) { - t = t; //OK411 - int i, j, r, nreactions, BacteriaNumber; - int Sp1, Sp2, surfaceID = -1, blob; //phase, + t = t; // OK411 + int i, j, r, nreactions, BacteriaNumber; + int Sp1, Sp2, surfaceID = -1, blob; // phase, double BacteriaMass, BacGrowth, Yield, sumX = 0., maxkap; - double porosity1, porosity2, exchange = 0.0, exch, kd, density1, - saturation2, kadsorb, kdesorb, totalSurface, exponent, parameter, - chochexp; //OK411 - double ratefact=1; + double porosity1, porosity2, exchange = 0.0, exch, kd, density1, saturation2, kadsorb, kdesorb, totalSurface, + exponent, parameter, + chochexp; // OK411 + double ratefact = 1; double dt; double foc; //#ds @@ -4315,45 +4477,46 @@ void derivs(double t, double c[], double dcdt[], int n, long node, double /*step double Csat; // double occupiedSurface[m_krd->maxSurfaces+1]; vector occupiedSurface; - //MinKin - double MinGrowth, omega; - int MineralNumber; - double scale = 1; - double scalemin = 1; - //scale rates correctly - std::vector ratevector; - std::vector > ratematrix; - - // phase = 0; + // MinKin + double MinGrowth, omega; + int MineralNumber; + double scale = 1; + double scalemin = 1; + // scale rates correctly + std::vector ratevector; + std::vector > ratematrix; + + // phase = 0; CKinReact* m_kr = NULL; - //OK411 CKinReact *m_kr1 = NULL; + // OK411 CKinReact *m_kr1 = NULL; CKinBlob* m_kb = NULL; CKinReactData* m_krd = NULL; m_krd = KinReactData_vector[0]; - /* Anzahl der mikrobiellen Reaktionen aus Datenstruktur auslesen */ - nreactions = m_krd->NumberReactions; //BioDegradation.NumberReactions; - //if(m_krd->debugoutflag) + /* Anzahl der mikrobiellen Reaktionen aus Datenstruktur auslesen */ + nreactions = m_krd->NumberReactions; // BioDegradation.NumberReactions; + // if(m_krd->debugoutflag) // m_krd->debugoutstr << " derivs" << "\n" << flush; CTimeDiscretization* m_tim = NULL; m_tim = time_vector[0]; dt = m_tim->CalcTimeStep(); - if(m_krd->scale_dcdt){ - for(i=0;iscale_dcdt) + { + for (i = 0; i < nreactions; i++) + ratevector.push_back(0); + for (i = 0; i < n; i++) + ratematrix.push_back(ratevector); + ratevector.clear(); + } /* reset array with derivatives */ /* ACHTUNG, unterschiedliche Indizierung der Arrays, c[1..n] BioDegradation[0..n-1] */ for (i = 0; i < n; i++) - //SBtodo dcdt[i+1]=ExchangeTerm[i]; + // SBtodo dcdt[i+1]=ExchangeTerm[i]; dcdt[i + 1] = 0.0; /* calculate present bacteria capacity */ - sumX = 0.0; //SB added + sumX = 0.0; // SB added maxkap = m_krd->maxBacteriaCapacity; if (maxkap > 1.E-30) for (i = 0; i < n; i++) @@ -4362,7 +4525,7 @@ void derivs(double t, double c[], double dcdt[], int n, long node, double /*step /**********************************************************************************************/ /* Anzahl der mikrobiellen Reaktionen aus Datenstruktur auslesen */ - nreactions = m_krd->NumberReactions; //BioDegradation.NumberReactions; + nreactions = m_krd->NumberReactions; // BioDegradation.NumberReactions; /* loop over reactions dX/dt= nymax * X * monodterms * inhibitionterms */ for (r = 0; r < nreactions; r++) { @@ -4378,107 +4541,121 @@ void derivs(double t, double c[], double dcdt[], int n, long node, double /*step porosity1 = m_kr->GetReferenceVolume(BacteriaNumber - 1, node); if (BacteriaMass > 1.E-40) { - m_kr->currentnode = node; // CB 19/10/09 This is eclusively for Brand model to allow porosity in Inhibition constant calculation + m_kr->currentnode = node; // CB 19/10/09 This is eclusively for Brand model to allow porosity in + // Inhibition constant calculation // This is where growth rate is computed - BacGrowth = m_kr->BacteriaGrowth(r, c, sumX, -1, node); + BacGrowth = m_kr->BacteriaGrowth(r, c, sumX, -1, node); if (m_kr->grow) - dcdt[BacteriaNumber] += BacGrowth * m_kr->EffectiveYield(node); // CB 08/12 added a microbial yield coefficient + dcdt[BacteriaNumber] + += BacGrowth * m_kr->EffectiveYield(node); // CB 08/12 added a microbial yield coefficient /* microbial consumption of substances */ for (i = 0; i < n; i++) { - Yield = m_kr->ProductionStoch[i]; // CB 08/12 this is the stoichiometry coefficient of the reaction + Yield = m_kr->ProductionStoch[i]; // CB 08/12 this is the stoichiometry coefficient of the reaction if (fabs(Yield) > 1.E-30) { porosity2 = m_kr->GetReferenceVolume(i, node); - dcdt[i + 1] += BacGrowth * Yield * porosity1 - / porosity2; + dcdt[i + 1] += BacGrowth * Yield * porosity1 / porosity2; + } + } + } + } // type == monod + } // nreactions + + /**********************************************************************************************/ + /* Berechnung der Mineralkinetiken */ + if (m_krd->NumberMineralkinetics > 0) + { + for (r = 0; r < nreactions; r++) + { + m_kr = KinReact_vector[r]; + // CB new reaction switch for individual reactions + if (m_kr->switched_off_node.size() > 0) + if (m_kr->switched_off_node[node] == true) + continue; + if (m_kr->typeflag_mineralkinetics) + { + // Equilibrium: when rate is zero, division by 0 (1-omega^theta) in fct jacbn is a problem, + // therefore, do nothing here when in in equilibrium + omega = m_kr->Omega(c, node); + if (fabs(1 - pow(omega, m_kr->Theta)) > 0) + { + MineralNumber = m_kr->mineral_number + 1; + // This is where growth rate is computed + MinGrowth = m_kr->MinRate(c, node, dt, omega); + // cout << MinGrowth << " "; + // unit: --> mol/s/m³_solid + if (MinGrowth != 0) + { + dcdt[MineralNumber] += MinGrowth; + if (m_krd->scale_dcdt) + ratematrix[MineralNumber - 1][r] = MinGrowth; + // mineral species precipitation or dissolution (not for the actual mineral, + // ProductionStoch[MineralNumber-1]=0) + porosity1 = m_kr->GetReferenceVolume(MineralNumber - 1, node); + for (i = 0; i < n; i++) + { + Yield = m_kr->ProductionStoch[i]; + porosity2 = m_kr->GetReferenceVolume(i, node); + if (fabs(Yield) > 1.E-30) + { + // unit conversion: --> mol/s/m³_solid * m³sol/m³Aq * (m³w/m³Aq)^-1 = mol/s/m³w + dcdt[i + 1] += MinGrowth * Yield * porosity1 / porosity2; + if (m_krd->scale_dcdt) + ratematrix[i][r] += MinGrowth * Yield * porosity1 / porosity2; + } + } } } + } // type == mineralkinetics + } // nreactions + } + + if (m_krd->scale_dcdt) + { + // cout << "derivs: dt=" << dt << "s, node=" << node << ": " << "\n"; + // for (i=0; iSolverType == 0) // for linearized rate calculation + ratematrix[j][r] *= scale; + else + ratematrix[j][r] *= scale * 0.9; + } + // then recompute dcdt + for (j = 0; j < n; j++) + { // species by species + dcdt[j + 1] = 0; + for (r = 0; r < nreactions; r++) + dcdt[j + 1] += ratematrix[j][r]; // sum up contributions of all reactions + } } - } // type == monod - } //nreactions - -/**********************************************************************************************/ -/* Berechnung der Mineralkinetiken */ - if(m_krd->NumberMineralkinetics > 0){ - for (r=0; rswitched_off_node.size()>0) - if(m_kr->switched_off_node[node]== true) - continue; - if(m_kr->typeflag_mineralkinetics){ - - // Equilibrium: when rate is zero, division by 0 (1-omega^theta) in fct jacbn is a problem, - // therefore, do nothing here when in in equilibrium - omega = m_kr->Omega(c, node); - if (fabs(1-pow(omega, m_kr->Theta))>0){ - MineralNumber = m_kr->mineral_number+1; - // This is where growth rate is computed - MinGrowth = m_kr->MinRate(c, node, dt, omega); - //cout << MinGrowth << " "; - // unit: --> mol/s/m³_solid - if(MinGrowth!=0){ - dcdt[MineralNumber] += MinGrowth; - if(m_krd->scale_dcdt) - ratematrix[MineralNumber-1][r] = MinGrowth; - // mineral species precipitation or dissolution (not for the actual mineral, ProductionStoch[MineralNumber-1]=0) - porosity1 = m_kr->GetReferenceVolume(MineralNumber-1,node); - for (i=0; iProductionStoch[i]; - porosity2 = m_kr->GetReferenceVolume(i,node); - if (fabs(Yield) > 1.E-30){ - // unit conversion: --> mol/s/m³_solid * m³sol/m³Aq * (m³w/m³Aq)^-1 = mol/s/m³w - dcdt[i+1] += MinGrowth * Yield * porosity1 / porosity2; - if(m_krd->scale_dcdt) - ratematrix[i][r] += MinGrowth * Yield * porosity1 / porosity2; - } - } - } - } - }// type == mineralkinetics - } //nreactions - } - - if(m_krd->scale_dcdt){ - //cout << "derivs: dt=" << dt << "s, node=" << node << ": " << "\n"; - //for (i=0; iSolverType==0) // for linearized rate calculation - ratematrix[j][r]*=scale; - else - ratematrix[j][r]*=scale*0.9; - } - // then recompute dcdt - for(j=0; j 0 + } // if NumberLangmuir > 0 for (r = 0; r < nreactions; r++) { @@ -4516,24 +4693,25 @@ void derivs(double t, double c[], double dcdt[], int n, long node, double /*step /* linearer Austausch ggf. mit kd */ if (m_kr->typeflag_exchange_linear) { - //Matrix + // Matrix Sp1 = m_kr->ex_species[0] + 1; porosity1 = m_kr->GetReferenceVolume(Sp1 - 1, node); density1 = m_kr->GetDensity(Sp1 - 1, node); - //geloest + // geloest Sp2 = m_kr->ex_species[1] + 1; porosity2 = m_kr->GetReferenceVolume(Sp2 - 1, node); - ratefact = m_kr->ex_param[2]; + ratefact = m_kr->ex_param[2]; exch = m_kr->ex_param[0]; kd = m_kr->ex_param[1]; if (fabs(kd) < MKleinsteZahl) { - //no kd, exchange between two species in solution + // no kd, exchange between two species in solution - // slow down desorption rate by constant factor - if((c[Sp2] - c[Sp1])<0) exch *= ratefact; + // slow down desorption rate by constant factor + if ((c[Sp2] - c[Sp1]) < 0) + exch *= ratefact; exchange = exch * (c[Sp2] - c[Sp1]); dcdt[Sp1] += exchange / porosity1; @@ -4546,61 +4724,64 @@ void derivs(double t, double c[], double dcdt[], int n, long node, double /*step if (foc > MKleinsteZahl) kd = kd * foc; - //else + // else // kd = 0; - // slow down desorption rate by constant factor - if((kd * c[Sp2] - c[Sp1]) < 0) exch *= ratefact; + // slow down desorption rate by constant factor + if ((kd * c[Sp2] - c[Sp1]) < 0) + exch *= ratefact; exchange = exch * (c[Sp2] * kd - c[Sp1]); - /* Die Abfrage verringert die Desorptionsgeschwindigkeit, wenn absehbar ist, dass Csorbiert im Negativen landet */ + /* Die Abfrage verringert die Desorptionsgeschwindigkeit, wenn absehbar ist, dass Csorbiert im + * Negativen landet */ if (-exchange * dt > c[Sp1]) exchange = -c[Sp1] / dt; dcdt[Sp1] += exchange; dcdt[Sp2] += -exchange * porosity1 / porosity2 * density1; } - } // ende if exType == linear + } // ende if exType == linear /* Freundlich Kinetik */ if (m_kr->typeflag_exchange_freundlich) { - //Matrix + // Matrix Sp1 = m_kr->ex_species[0] + 1; porosity1 = m_kr->GetReferenceVolume(Sp1 - 1, node); density1 = m_kr->GetDensity(Sp1 - 1, node); - //geloest + // geloest Sp2 = m_kr->ex_species[1] + 1; porosity2 = m_kr->GetReferenceVolume(Sp2 - 1, node); - // if both species are in the same phase, density multiplication below is not required - if(cp_vec[Sp1-1]->transport_phase == cp_vec[Sp2-1]->transport_phase) - density1 = 1; + // if both species are in the same phase, density multiplication below is not required + if (cp_vec[Sp1 - 1]->transport_phase == cp_vec[Sp2 - 1]->transport_phase) + density1 = 1; exponent = m_kr->ex_param[2]; parameter = m_kr->ex_param[1]; exch = m_kr->ex_param[0]; - ratefact = m_kr->ex_param[3]; + ratefact = m_kr->ex_param[3]; if (c[Sp2] > residual) // no linearisation required chochexp = pow(c[Sp2], exponent); else // linearisation required due to instability of c^x if c c[Sp1]) exchange = -c[Sp1] / dt; dcdt[Sp1] += exchange; dcdt[Sp2] += -exchange * porosity1 / porosity2 * density1; - } // if freundlich + } // if freundlich /* Langmuir Kinetik */ if (m_kr->typeflag_exchange_langmuir) @@ -4615,24 +4796,23 @@ void derivs(double t, double c[], double dcdt[], int n, long node, double /*step kadsorb = m_kr->ex_param[0]; kdesorb = m_kr->ex_param[1]; - //SB_langmuir surfaceID = m_kr->exSurfaceID; //Exchange.Langmuir[i].SurfaceID; + // SB_langmuir surfaceID = m_kr->exSurfaceID; //Exchange.Langmuir[i].SurfaceID; totalSurface = m_krd->exSurface[m_kr->exSurfaceID]; //#ds ACHTUNG hier muss sicher gestellt sein, dass Sp1 die adsorbierte und Sp2 die gel�ste Species ist ! - exchange = kadsorb - * (totalSurface - occupiedSurface[surfaceID]) * c[Sp2] - - kdesorb * c[Sp1]; + exchange = kadsorb * (totalSurface - occupiedSurface[surfaceID]) * c[Sp2] - kdesorb * c[Sp1]; - /* Die Abfrage verringert die Desorptionsgeschwindigkeit, wenn absehbar ist, dass Csorbiert im Negativen landet */ + /* Die Abfrage verringert die Desorptionsgeschwindigkeit, wenn absehbar ist, dass Csorbiert im Negativen + * landet */ if (-exchange * dt > c[Sp1]) exchange = -c[Sp1] / dt; dcdt[Sp1] += exchange; dcdt[Sp2] += -exchange * porosity1 / porosity2 * density1; // } - } // ende if exType == langmuir - } //if type == exchange - } // for r + } // ende if exType == langmuir + } // if type == exchange + } // for r //#ds /**********************************************************************************************/ @@ -4649,52 +4829,53 @@ void derivs(double t, double c[], double dcdt[], int n, long node, double /*step if (m_kr->typeflag_napldissolution) { - Sp1 = m_kr->ex_species[0] + 1; //Exchange.Linear[i].Species1; Sp1 muss NAPL sein + Sp1 = m_kr->ex_species[0] + 1; // Exchange.Linear[i].Species1; Sp1 muss NAPL sein // porosity1 = m_kr->GetPorosity(Sp1-1,node); // density1 = m_kr->GetDensity(Sp1-1,node); //GetDensity(phase); blob = m_kr->blob_ID; m_kb = KinBlob_vector[blob]; // pointer to blob-properties set in the reaction r - Sp2 = m_kr->ex_species[1] + 1; //Exchange.Linear[i].Species2; Sp2 = mobile Phase - //CB this includes the saturation + Sp2 = m_kr->ex_species[1] + 1; // Exchange.Linear[i].Species2; Sp2 = mobile Phase + // CB this includes the saturation porosity2 = m_kr->GetReferenceVolume(Sp2 - 1, node); //#ds TODO saturation2 = ?? saturation2 = 1.; - //CB now access data for each node directly from node vectors - Csat = m_kr->Current_Csat[node]; // Csat externally calculated in Function Biodegradation - exch = m_kb->Masstransfer_K[node] * m_kb->Interfacial_area[node]; // k * A externally calculated in Function Biodegradation - exponent = m_kr->rateorder; + // CB now access data for each node directly from node vectors + Csat = m_kr->Current_Csat[node]; // Csat externally calculated in Function Biodegradation + exch = m_kb->Masstransfer_K[node] + * m_kb->Interfacial_area[node]; // k * A externally calculated in Function Biodegradation + exponent = m_kr->rateorder; - exchange = 0; + exchange = 0; if (exch > 0) - exchange = exch * pow((Csat - c[Sp2]), exponent); // CB introduced rateorder 06/2012 + exchange = exch * pow((Csat - c[Sp2]), exponent); // CB introduced rateorder 06/2012 /* Die Abfrage verringert die L�sungsgeschwindigkeit, wenn absehbar ist, dass CNAPL im Negativen landet Verhindert negative CNAPL-Konzentrationen */ - if (exchange * dt > c[Sp1]) - { - //k1 = c[Sp1] / dt; - //k2 = (Csat - c[Sp2]) * porosity2 * saturation2 / dt; - exchange = c[Sp1] / dt; - //exchange = DMIN(k1, k2); - //cout << "Warning in derivs: exchange * dt > c[Sp1]" << "\n"; - } -// if ((exchange > 0) && (exchange * dt + c[Sp2] > Csat)) -// exchange = (Csat - c[Sp2]) / dt /5; - if(c[Sp1] > MKleinsteZahl) // no dissolution or NAPL mass present - if ((exchange < 0.) || (c[Sp1] > MKleinsteZahl)) - { - dcdt[Sp1] += -exchange; //NAPL - //concentration in solution, refers to mass / volume of water - dcdt[Sp2] += exchange / porosity2 / saturation2; + if (exchange * dt > c[Sp1]) + { + // k1 = c[Sp1] / dt; + // k2 = (Csat - c[Sp2]) * porosity2 * saturation2 / dt; + exchange = c[Sp1] / dt; + // exchange = DMIN(k1, k2); + // cout << "Warning in derivs: exchange * dt > c[Sp1]" << "\n"; } - } // ifNAPL dissolution - } // loop ofer reactions r + // if ((exchange > 0) && (exchange * dt + c[Sp2] > Csat)) + // exchange = (Csat - c[Sp2]) / dt /5; + if (c[Sp1] > MKleinsteZahl) // no dissolution or NAPL mass present + if ((exchange < 0.) || (c[Sp1] > MKleinsteZahl)) + { + dcdt[Sp1] += -exchange; // NAPL + // concentration in solution, refers to mass / volume of water + dcdt[Sp2] += exchange / porosity2 / saturation2; + } + } // ifNAPL dissolution + } // loop ofer reactions r //#ds occupiedSurface.clear(); - ratematrix.clear(); + ratematrix.clear(); } /**************************************************************************/ @@ -4711,7 +4892,8 @@ int CKinReact::GetPhase(int species) if (cp_m != NULL) phase = cp_m->transport_phase; else - cout << " Error: component does not exist !" << "\n"; + cout << " Error: component does not exist !" + << "\n"; return phase; } @@ -4725,21 +4907,22 @@ int CKinReact::GetPhase(int species) double CKinReact::GetReferenceVolume(int comp, long index) { // Get process - CRFProcess const* const pcs (cp_vec[comp]->getProcess()); - double theta (pcs->m_num->ls_theta), refvol=0; + CRFProcess const* const pcs(cp_vec[comp]->getProcess()); + double theta(pcs->m_num->ls_theta), refvol = 0; long phase = cp_vec[comp]->transport_phase; if (phase == 0) { int idx; - refvol = GetPhaseVolumeAtNode(index, theta, phase); + refvol = GetPhaseVolumeAtNode(index, theta, phase); // water phase, reference volume might be less than pore space in case of multiphase or richards flow // --> Get node saturation of mobile (water) phase, required for all exchange processes double saturation = 1.0; // default CRFProcess* pcs_flow = PCSGetFlow(); - if(pcs_flow->getProcessType() == FiniteElement::PS_GLOBAL){ - idx = pcs_flow->GetNodeValueIndex("SATURATION1"); // Sat of water phase - saturation = pcs_flow->GetNodeValue(index, idx); + if (pcs_flow->getProcessType() == FiniteElement::PS_GLOBAL) + { + idx = pcs_flow->GetNodeValueIndex("SATURATION1"); // Sat of water phase + saturation = pcs_flow->GetNodeValue(index, idx); } else if (pcs_flow->getProcessType() == FiniteElement::TWO_PHASE_FLOW) { @@ -4756,24 +4939,25 @@ double CKinReact::GetReferenceVolume(int comp, long index) idx = pcs_flow->GetNodeValueIndex("SATURATION1"); saturation = pcs_flow->GetNodeValue(index, idx); } - else if (pcs_flow->getProcessType() == FiniteElement::MULTI_PHASE_FLOW) - { - // Sat of water phase - idx = pcs_flow->GetNodeValueIndex("SATURATION1"); - saturation = pcs_flow->GetNodeValue(index, idx); - } + else if (pcs_flow->getProcessType() == FiniteElement::MULTI_PHASE_FLOW) + { + // Sat of water phase + idx = pcs_flow->GetNodeValueIndex("SATURATION1"); + saturation = pcs_flow->GetNodeValue(index, idx); + } refvol *= saturation; } - else if (phase == 1) // solid - { - refvol = GetPhaseVolumeAtNode(index, theta, phase); - } - else if (phase == 2) // bio phase - refvol = GetPhaseVolumeAtNode(index, theta, phase); - else if (phase == 3) // NAPL phase (refers to REV) - refvol = 1.0; - else - cout << " Warning: Unknown phase index " << phase << " in CKinReact::GetReferenceVolume()." << "\n"; + else if (phase == 1) // solid + { + refvol = GetPhaseVolumeAtNode(index, theta, phase); + } + else if (phase == 2) // bio phase + refvol = GetPhaseVolumeAtNode(index, theta, phase); + else if (phase == 3) // NAPL phase (refers to REV) + refvol = 1.0; + else + cout << " Warning: Unknown phase index " << phase << " in CKinReact::GetReferenceVolume()." + << "\n"; return refvol; } @@ -4787,51 +4971,54 @@ double CKinReact::GetReferenceVolume(int comp, long index) /*****************************************************************************************/ double CKinReact::GetSaturation(long node, int theta, int phase) { - double saturation = 1; // refvol = 0.0, - CRFProcess *pcs_flow = PCSGetFlow(); - int idx; - - // - if (phase == 0){ // water - if(pcs_flow->getProcessType() == FiniteElement::PS_GLOBAL){ - idx = pcs_flow->GetNodeValueIndex("SATURATION2"); // Sat of NAPL phase - saturation = 1.0 - pcs_flow->GetNodeValue(node, idx+theta); - } - else if (pcs_flow->getProcessType() == FiniteElement::RICHARDS_FLOW) - { - // Sat of water phase - idx = pcs_flow->GetNodeValueIndex("SATURATION1"); - saturation = pcs_flow->GetNodeValue(node, idx+theta); - } - else if (pcs_flow->getProcessType() == FiniteElement::MULTI_PHASE_FLOW) - { - // Sat of water phase - idx = pcs_flow->GetNodeValueIndex("SATURATION1"); - saturation = pcs_flow->GetNodeValue(node, idx+theta); - } - } - // - else if (phase == 1) // NAPL, gas - { - if(pcs_flow->getProcessType() == FiniteElement::PS_GLOBAL){ - idx = pcs_flow->GetNodeValueIndex("SATURATION2"); // Sat of NAPL phase - saturation = pcs_flow->GetNodeValue(node, idx+theta); - } - else if (pcs_flow->getProcessType() == FiniteElement::RICHARDS_FLOW) - { - // Sat of water phase - idx = pcs_flow->GetNodeValueIndex("SATURATION1"); - saturation = 1.0 - pcs_flow->GetNodeValue(node, idx+theta); - } - else if (pcs_flow->getProcessType() == FiniteElement::MULTI_PHASE_FLOW) - { - // Sat of water phase - idx = pcs_flow->GetNodeValueIndex("SATURATION1"); - saturation =1.0 - pcs_flow->GetNodeValue(node, idx+theta); - } - } - - return saturation; + double saturation = 1; // refvol = 0.0, + CRFProcess* pcs_flow = PCSGetFlow(); + int idx; + + // + if (phase == 0) + { // water + if (pcs_flow->getProcessType() == FiniteElement::PS_GLOBAL) + { + idx = pcs_flow->GetNodeValueIndex("SATURATION2"); // Sat of NAPL phase + saturation = 1.0 - pcs_flow->GetNodeValue(node, idx + theta); + } + else if (pcs_flow->getProcessType() == FiniteElement::RICHARDS_FLOW) + { + // Sat of water phase + idx = pcs_flow->GetNodeValueIndex("SATURATION1"); + saturation = pcs_flow->GetNodeValue(node, idx + theta); + } + else if (pcs_flow->getProcessType() == FiniteElement::MULTI_PHASE_FLOW) + { + // Sat of water phase + idx = pcs_flow->GetNodeValueIndex("SATURATION1"); + saturation = pcs_flow->GetNodeValue(node, idx + theta); + } + } + // + else if (phase == 1) // NAPL, gas + { + if (pcs_flow->getProcessType() == FiniteElement::PS_GLOBAL) + { + idx = pcs_flow->GetNodeValueIndex("SATURATION2"); // Sat of NAPL phase + saturation = pcs_flow->GetNodeValue(node, idx + theta); + } + else if (pcs_flow->getProcessType() == FiniteElement::RICHARDS_FLOW) + { + // Sat of water phase + idx = pcs_flow->GetNodeValueIndex("SATURATION1"); + saturation = 1.0 - pcs_flow->GetNodeValue(node, idx + theta); + } + else if (pcs_flow->getProcessType() == FiniteElement::MULTI_PHASE_FLOW) + { + // Sat of water phase + idx = pcs_flow->GetNodeValueIndex("SATURATION1"); + saturation = 1.0 - pcs_flow->GetNodeValue(node, idx + theta); + } + } + + return saturation; } /**************************************************************************/ @@ -4849,50 +5036,52 @@ double CKinReact::GetSaturation(long node, int theta, int phase) /**************************************************************************/ double CKinReact::GetPhaseVolumeAtNode(long node_number, double theta, int phase) { - CFEMesh const* const mesh (fem_msh_vector[0]); //SB: ToDo hart gesetzt + CFEMesh const* const mesh(fem_msh_vector[0]); // SB: ToDo hart gesetzt size_t idx = 0; - long elem; //OK411 + long elem; // OK411 double distance, weight, sum_w = 0; double vol = 0, poro = 0; - // if node poro vector is used - if(phase==0 || phase==1){ - REACTINT *m_rei = NULL; - if(REACTINT_vec.size()>0){ - m_rei = REACTINT_vec[0]; - vol = m_rei->node_porosity[node_number]; - if(phase==1) // solid phase - vol = 1.0 - vol; - return vol; - } - } + // if node poro vector is used + if (phase == 0 || phase == 1) + { + REACTINT* m_rei = NULL; + if (REACTINT_vec.size() > 0) + { + m_rei = REACTINT_vec[0]; + vol = m_rei->node_porosity[node_number]; + if (phase == 1) // solid phase + vol = 1.0 - vol; + return vol; + } + } // get Indices for phase 1 or 2, only if heterogeneous porosity model = 11, i.e. vol_mat_model = vol_bio_model = 2 - long group = 0; //SB todo group = m_ele->GetPatchIndex(); Todo CB + long group = 0; // SB todo group = m_ele->GetPatchIndex(); Todo CB CMediumProperties* m_mat_mp(mmp_vector[group]); if (m_mat_mp->vol_bio_model == 2 && m_mat_mp->vol_mat_model == 2) { switch (phase) { - case 1: //solid phase - // Get VOL_MAT index - for (idx = 0; idx < mesh->mat_names_vector.size(); idx++) - if (mesh->mat_names_vector[idx].compare("VOL_MAT") == 0) - break; - break; - case 2: //bio phase - // Get VOL_BIO index - for (idx = 0; idx < mesh->mat_names_vector.size(); idx++) - if (mesh->mat_names_vector[idx].compare("VOL_BIO") == 0) - break; - break; - default: - break; + case 1: // solid phase + // Get VOL_MAT index + for (idx = 0; idx < mesh->mat_names_vector.size(); idx++) + if (mesh->mat_names_vector[idx].compare("VOL_MAT") == 0) + break; + break; + case 2: // bio phase + // Get VOL_BIO index + for (idx = 0; idx < mesh->mat_names_vector.size(); idx++) + if (mesh->mat_names_vector[idx].compare("VOL_BIO") == 0) + break; + break; + default: + break; } } // Get node coordinates - MeshLib::CNode const* const node (mesh->nod_vector[node_number]); + MeshLib::CNode const* const node(mesh->nod_vector[node_number]); double const* const coord = node->getData(); // Coordinates(coord); for (size_t el = 0; el < node->getConnectedElementIDs().size(); el++) @@ -4901,50 +5090,46 @@ double CKinReact::GetPhaseVolumeAtNode(long node_number, double theta, int phase distance = weight = poro = 0; // Get the connected element elem = node->getConnectedElementIDs()[el]; // element index - MeshLib::CElem const* const m_ele (mesh->ele_vector[elem]); - //get the phase volume of current element elem + MeshLib::CElem const* const m_ele(mesh->ele_vector[elem]); + // get the phase volume of current element elem group = 0; // group = m_ele->GetPatchIndex(); Todo CB m_mat_mp = mmp_vector[group]; switch (phase) { - case 0: //pore space - // CB Now provides also heterogeneous porosity, model 11 - poro = m_mat_mp->Porosity(elem, theta); - break; - case 1: //solid phase - if (m_mat_mp->vol_mat_model == 1) // homogeneous - poro = m_mat_mp->vol_mat; - else if (m_mat_mp->vol_mat_model == 2) // CB heterogeneous - poro = m_ele->mat_vector(idx); - else - cout - << - "Warning! No valid VOL_MAT model in CKinReact::GetPhaseVolumeAtNode, vol_mat_model =" - << m_mat_mp->vol_mat_model << "\n"; - break; - case 2: //bio phase - if (m_mat_mp->vol_bio_model == 1) // homogeneous - poro = m_mat_mp->vol_bio; - else if (m_mat_mp->vol_bio_model == 2) // CB heterogeneous - poro = m_ele->mat_vector(idx); - else - cout - << - "Warning! No valid VOL_BIO model in CKinReact::GetPhaseVolumeAtNode, vol_bio_model =" - << m_mat_mp->vol_bio_model << "\n"; - break; - case 3: // NAPL phase (refers to REV) - poro = 1.0; - break; - default: - cout << "Error in CKinReact::GetPhaseVolumeAtNode: no valid phase" - << "\n"; - break; + case 0: // pore space + // CB Now provides also heterogeneous porosity, model 11 + poro = m_mat_mp->Porosity(elem, theta); + break; + case 1: // solid phase + if (m_mat_mp->vol_mat_model == 1) // homogeneous + poro = m_mat_mp->vol_mat; + else if (m_mat_mp->vol_mat_model == 2) // CB heterogeneous + poro = m_ele->mat_vector(idx); + else + cout << "Warning! No valid VOL_MAT model in CKinReact::GetPhaseVolumeAtNode, vol_mat_model =" + << m_mat_mp->vol_mat_model << "\n"; + break; + case 2: // bio phase + if (m_mat_mp->vol_bio_model == 1) // homogeneous + poro = m_mat_mp->vol_bio; + else if (m_mat_mp->vol_bio_model == 2) // CB heterogeneous + poro = m_ele->mat_vector(idx); + else + cout << "Warning! No valid VOL_BIO model in CKinReact::GetPhaseVolumeAtNode, vol_bio_model =" + << m_mat_mp->vol_bio_model << "\n"; + break; + case 3: // NAPL phase (refers to REV) + poro = 1.0; + break; + default: + cout << "Error in CKinReact::GetPhaseVolumeAtNode: no valid phase" + << "\n"; + break; } // calculate distance node <-> element center of gravity - double const* grav_c (m_ele->GetGravityCenter()); + double const* grav_c(m_ele->GetGravityCenter()); for (size_t i = 0; i < 3; i++) - distance += (coord[i] - grav_c[i]) * (coord[i] - grav_c[i]); //pow((coord[i] - grav_c[i]), 2); + distance += (coord[i] - grav_c[i]) * (coord[i] - grav_c[i]); // pow((coord[i] - grav_c[i]), 2); // linear inverse distance weight = 1/(distance) distance = sqrt(distance); // for quadratic interpolation uncomment this line weight = (1 / distance); @@ -4963,48 +5148,59 @@ double CKinReact::GetPhaseVolumeAtNode(long node_number, double theta, int phase /* Max Solubility of a NAPL component */ /* 05/2012 CB */ /**************************************************************************/ -double CKinReact::GetMaxSolubility(long node, double density){ - - double Csatmax=0; - int Sp1 = ex_species[0]+1; //Sp1 = NAPL-species - double Temperature = 0; - double logK = 0; - double R = 8.314472; // gas constant = R 8.314472(15) J/K/mol - - if(typeflag_gasdissolution==1){ - if(REACTINT_vec.size()>0) - Csatmax = REACTINT_vec[0]->GetCO2SolubilityDuan(node); - else{ - cout << " Warning in CKinReact::GetMaxSolubility(): " << "\n"; - cout << " No Reaction Interface REI defined, but required for CO2 solubility calculation." << "\n"; - cout << " Using constant value from cp_data." << "\n"; - Csatmax = cp_vec[Sp1-1]->max_solubility; // temporary substitute - } - return Csatmax; - } - - if(T_dependence == false) - Csatmax = cp_vec[Sp1-1]->max_solubility; - else if (T_dependence == true){ - if(REACTINT_vec.size()>0) // Get the Temperature - Temperature = REACTINT_vec[0]->GetTemperature(node); - if(T_model==1){ // Chen Model : R*ln(K) = A + B/T + C*ln(T); based on molar fraction mol/molw - logK = (T_params[0] + T_params[1]/Temperature + T_params[2]*log(Temperature) ) / R; // nat log - Csatmax = exp(logK) ; // mol/mol wasser - Csatmax *= (1/0.01801528) * density; // mol/molw * molw/kgw * kgw/m³ - } - else if(T_model==2){ // Knauss Model : R*ln(K) = A + B/T + C*ln(T); based on molality mol/kgw - logK = (T_params[0] + T_params[1]/Temperature + T_params[2]*log(Temperature) ) / R; // nat log - Csatmax = exp(logK) ; // mol/kgw wasser - Csatmax *= density; // mol/kgw * kgw/m³ - } - else{ - cout << " Unknown model for Temperature Dependence in CKinReact::GetMaxSolubility(). " << "\n" ; - cout << " Aborting now!" << "\n"; - exit(0); - } - } - return Csatmax; +double CKinReact::GetMaxSolubility(long node, double density) +{ + double Csatmax = 0; + int Sp1 = ex_species[0] + 1; // Sp1 = NAPL-species + double Temperature = 0; + double logK = 0; + double R = 8.314472; // gas constant = R 8.314472(15) J/K/mol + + if (typeflag_gasdissolution == 1) + { + if (REACTINT_vec.size() > 0) + Csatmax = REACTINT_vec[0]->GetCO2SolubilityDuan(node); + else + { + cout << " Warning in CKinReact::GetMaxSolubility(): " + << "\n"; + cout << " No Reaction Interface REI defined, but required for CO2 solubility calculation." + << "\n"; + cout << " Using constant value from cp_data." + << "\n"; + Csatmax = cp_vec[Sp1 - 1]->max_solubility; // temporary substitute + } + return Csatmax; + } + + if (T_dependence == false) + Csatmax = cp_vec[Sp1 - 1]->max_solubility; + else if (T_dependence == true) + { + if (REACTINT_vec.size() > 0) // Get the Temperature + Temperature = REACTINT_vec[0]->GetTemperature(node); + if (T_model == 1) + { // Chen Model : R*ln(K) = A + B/T + C*ln(T); based on molar fraction mol/molw + logK = (T_params[0] + T_params[1] / Temperature + T_params[2] * log(Temperature)) / R; // nat log + Csatmax = exp(logK); // mol/mol wasser + Csatmax *= (1 / 0.01801528) * density; // mol/molw * molw/kgw * kgw/m³ + } + else if (T_model == 2) + { // Knauss Model : R*ln(K) = A + B/T + C*ln(T); based on molality mol/kgw + logK = (T_params[0] + T_params[1] / Temperature + T_params[2] * log(Temperature)) / R; // nat log + Csatmax = exp(logK); // mol/kgw wasser + Csatmax *= density; // mol/kgw * kgw/m³ + } + else + { + cout << " Unknown model for Temperature Dependence in CKinReact::GetMaxSolubility(). " + << "\n"; + cout << " Aborting now!" + << "\n"; + exit(0); + } + } + return Csatmax; } /**************************************************************************/ @@ -5013,16 +5209,17 @@ double CKinReact::GetMaxSolubility(long node, double density){ /**************************************************************************/ double CKinReact::EffectiveYield(long node) { - double Yieldeff=Yieldcoefficient; + double Yieldeff = Yieldcoefficient; - if(DormTypeIdx==0){ - MicrobeData *m_md = NULL; - m_md = MicrobeData_vector[MicrobeData_idx]; - Yieldeff *= (1 - m_md->G0/m_md->Gibbs[node]); - return MRange(0.0, Yieldeff, Yieldcoefficient); - } + if (DormTypeIdx == 0) + { + MicrobeData* m_md = NULL; + m_md = MicrobeData_vector[MicrobeData_idx]; + Yieldeff *= (1 - m_md->G0 / m_md->Gibbs[node]); + return MRange(0.0, Yieldeff, Yieldcoefficient); + } - return Yieldeff; + return Yieldeff; } /**************************************************************************/ @@ -5035,10 +5232,9 @@ double CKinReact::GetDensity(int comp, long index) { double dens = 0.; long group, phase; - //WW CRFProcess *m_pcs = NULL; - - group = index; // avoid warning + // WW CRFProcess *m_pcs = NULL; + group = index; // avoid warning cout << comp << " " << cp_vec.size() << " "; cout << cp_vec[comp]->transport_phase << endl; @@ -5046,16 +5242,16 @@ double CKinReact::GetDensity(int comp, long index) phase = cp_vec[comp]->transport_phase; // Get material properties of element - group = 0; //m_pcs->m_msh->ele_vector[index]->GetPatchIndex(); //SB todo + group = 0; // m_pcs->m_msh->ele_vector[index]->GetPatchIndex(); //SB todo - if (phase == 0) // component in water phase, return liquid density + if (phase == 0) // component in water phase, return liquid density dens = mfp_vector[0]->Density(); // component in solid phase, return solid phase density else if (phase == 1) dens = msp_vector[group]->Density(); - else if (phase == 2) // component in bio phase, return 1 as density - dens = 1; + else if (phase == 2) // component in bio phase, return 1 as density + dens = 1; return dens; } @@ -5080,142 +5276,151 @@ double CKinReact::GetDensity(int comp, long index) /* */ /**************************************************************************/ -double CKinReact::BacteriaGrowth(int r, double *c, double sumX, int exclude, long node) +double CKinReact::BacteriaGrowth(int r, double* c, double sumX, int exclude, long node) { - r = r; //OK411 - int i, BacteriaNumber, MonodSpecies, InhibitionSpecies, Isotopespecies, - NumberMonod, NumberInhibition; + r = r; // OK411 + int i, BacteriaNumber, MonodSpecies, InhibitionSpecies, Isotopespecies, NumberMonod, NumberInhibition; double Growth, BacteriaMass, maxVelocity, maxkap; double MonodConcentration, InhibitionConcentration, C; - double Ctot = 0; //CB Isotope fractionation + double Ctot = 0; // CB Isotope fractionation double MonodOrder; - double Temperature = 0; - double theta = 0; + double Temperature = 0; + double theta = 0; CKinReactData* m_krd = NULL; - MicrobeData *m_md = NULL; + MicrobeData* m_md = NULL; m_krd = KinReactData_vector[0]; BacteriaNumber = bacteria_number + 1; maxVelocity = rateconstant; BacteriaMass = c[BacteriaNumber]; - if(T_dependence){ - if(this->T_model==0){ - // do nothing - } - else { - if(REACTINT_vec.size()>0) // Get the Temperature - Temperature = REACTINT_vec[0]->GetTemperature(node); - if(T_model==1){ // Ratkowski2 - if(Temperature < T_params[0] || Temperature > T_params[1] ) - maxVelocity = 0; - else{ - maxVelocity = 1.0/3600 * pow((T_params[2]*(Temperature - T_params[0])), 2.0); // [b*(T-Tmin)]^2 - maxVelocity *= (1.0 - exp(T_params[3]*(Temperature - T_params[1]))); // *(1-exp(C(T-Tmax))) - } - } - else{ - cout << " Unknown model for growth dependent on Temperature in CKinReact::BacteriaGrowth(). " << "\n" ; - cout << " Aborting now!" << "\n"; - exit(0); - } - } - } - - if(_drmc_){ - m_md = MicrobeData_vector[MicrobeData_idx]; - theta = 1/(exp((m_md->G0-m_md->Gibbs[node])/(m_md->steepness*m_md->G0))+1); - if(theta>1.0) - theta=1.0; - switch(DormTypeIdx){ - case 0: //GROWTH - maxVelocity *= theta; - break; - case 1: //DEACTIVATION - maxVelocity *= (1-theta); - break; - case 2: //REACTIVATION - maxVelocity *= theta * m_md->_drmc_level[node] ; - break; - case 3: //DECAY - maxVelocity += m_md->_drmc_level[node] * m_md->decayrate; - break; - default: - cout << " Warning in CKinReact::BacteriaGrowth(): Unknown _drmc_ reaction type!" << "\n"; - break; - } - } + if (T_dependence) + { + if (this->T_model == 0) + { + // do nothing + } + else + { + if (REACTINT_vec.size() > 0) // Get the Temperature + Temperature = REACTINT_vec[0]->GetTemperature(node); + if (T_model == 1) + { // Ratkowski2 + if (Temperature < T_params[0] || Temperature > T_params[1]) + maxVelocity = 0; + else + { + maxVelocity = 1.0 / 3600 * pow((T_params[2] * (Temperature - T_params[0])), 2.0); // [b*(T-Tmin)]^2 + maxVelocity *= (1.0 - exp(T_params[3] * (Temperature - T_params[1]))); // *(1-exp(C(T-Tmax))) + } + } + else + { + cout << " Unknown model for growth dependent on Temperature in CKinReact::BacteriaGrowth(). " + << "\n"; + cout << " Aborting now!" + << "\n"; + exit(0); + } + } + } + + if (_drmc_) + { + m_md = MicrobeData_vector[MicrobeData_idx]; + theta = 1 / (exp((m_md->G0 - m_md->Gibbs[node]) / (m_md->steepness * m_md->G0)) + 1); + if (theta > 1.0) + theta = 1.0; + switch (DormTypeIdx) + { + case 0: // GROWTH + maxVelocity *= theta; + break; + case 1: // DEACTIVATION + maxVelocity *= (1 - theta); + break; + case 2: // REACTIVATION + maxVelocity *= theta * m_md->_drmc_level[node]; + break; + case 3: // DECAY + maxVelocity += m_md->_drmc_level[node] * m_md->decayrate; + break; + default: + cout << " Warning in CKinReact::BacteriaGrowth(): Unknown _drmc_ reaction type!" + << "\n"; + break; + } + } Growth = maxVelocity * BacteriaMass; /* Hemmung durch Bakteriendichte sumX nur bei Wachstum */ - if ((sumX>1.E-30)&&(maxVelocity>0.)&&(specif_cap<1e-30)) - { // specif_cap is used to limit growth only to the specific bacteria + if ((sumX > 1.E-30) && (maxVelocity > 0.) && (specif_cap < 1e-30)) + { // specif_cap is used to limit growth only to the specific bacteria /* Max. Bakterienkapazit�t aus Datenstruktur auslesen */ maxkap = m_krd->maxBacteriaCapacity; - Growth *= maxkap / (sumX + maxkap); + Growth *= maxkap / (sumX + maxkap); + } + // Limit growth by specific bacteria density and not by total density + else if (specif_cap > 1e-30) + { + Growth *= specif_cap / (BacteriaMass + specif_cap); } - // Limit growth by specific bacteria density and not by total density - else if(specif_cap>1e-30){ - Growth *= specif_cap/(BacteriaMass+specif_cap); - } /* FOR-Schleife �ber vorhandene Monodterme */ NumberMonod = number_monod; - for (i=0; ispeciesnumber; - MonodConcentration = monod[i]->concentration; - MonodOrder = monod[i]->order; // CB higher order Monod terms - C = c[MonodSpecies+1]; - Ctot = C; // standard case, no iso fractionation - // CB Isotope fractionation: here Ctot=C_light+C_heavy must be passed to fct Monod() - if((typeflag_iso_fract==1) && (monod[i]->isotopecouplenumber - >=0)) - { - Isotopespecies = monod[i]->isotopecouplenumber; - Ctot = C + c[Isotopespecies+1]; - } - //Growth = Growth * Monod(MonodConcentration,C); // old formulation without isotope fractionation - Growth *= Monod(MonodConcentration, C, Ctot, MonodOrder); // new formulation - // now multiply by additional Threshhold Term, if present, - // technically this is the same as an additional Monod term for the same MonodSpecies - // usually of higher order and lower Monod-Conc = threshConc - if(monod[i]->threshhold==true) - { - MonodConcentration = monod[i]->threshConc; // CB Threshhold concentration - MonodOrder = monod[i]->threshOrder; // CB higher order Monod terms - Growth *= Monod(MonodConcentration, Ctot, Ctot, - MonodOrder); // C should in any case be total C - } - } - } // for NumberMonod + for (i = 0; i < NumberMonod; i++) + { + /* Möglichkeit zum Weglassen Monodterm für partielle Ableitungen erforderlich */ + if (i != exclude) + { + MonodSpecies = monod[i]->speciesnumber; + MonodConcentration = monod[i]->concentration; + MonodOrder = monod[i]->order; // CB higher order Monod terms + C = c[MonodSpecies + 1]; + Ctot = C; // standard case, no iso fractionation + // CB Isotope fractionation: here Ctot=C_light+C_heavy must be passed to fct Monod() + if ((typeflag_iso_fract == 1) && (monod[i]->isotopecouplenumber >= 0)) + { + Isotopespecies = monod[i]->isotopecouplenumber; + Ctot = C + c[Isotopespecies + 1]; + } + // Growth = Growth * Monod(MonodConcentration,C); // old formulation without isotope fractionation + Growth *= Monod(MonodConcentration, C, Ctot, MonodOrder); // new formulation + // now multiply by additional Threshhold Term, if present, + // technically this is the same as an additional Monod term for the same MonodSpecies + // usually of higher order and lower Monod-Conc = threshConc + if (monod[i]->threshhold == true) + { + MonodConcentration = monod[i]->threshConc; // CB Threshhold concentration + MonodOrder = monod[i]->threshOrder; // CB higher order Monod terms + Growth *= Monod(MonodConcentration, Ctot, Ctot, MonodOrder); // C should in any case be total C + } + } + } // for NumberMonod /* FOR-Schleife �ber vorhandene Inhibitionsterme */ NumberInhibition = number_inhibit; - for (i = 0; i < NumberInhibition; i++) - { - InhibitionSpecies = inhibit[i]->speciesnumber; - InhibitionConcentration = inhibit[i]->concentration; - // ATTENTION!!! - // CB 16/10/09 fix of Fe3 inhibition concentration for Brand model, - // this parameter depends on porosity as in Min3P Fe3 is in solid phase - // and Inhibition concentrations are expressed in terms of Volume fraction - // Vol_Fe3/Vol_BulkAquifer [m?m�] - // while in Geosys, Fe3 is considered an immobile aqueous species - // and concentrations were converted to [mol/L_water] by - // C_gs = C_min3p * rho_Fe3 / molweight / porosity - // for inhibition concentrations, division by porosity is still required -// if(inhibit[i]->species.compare("Fe3")==0) { -// InhibitionConcentration *= 1/GetPhaseVolumeAtNode(currentnode, 1, 0); -// } // CB further changes in derivs (1), jacbn (2), class CKinReact{} - C = c[InhibitionSpecies + 1]; - Growth *= Inhibition(InhibitionConcentration, C); - } + for (i = 0; i < NumberInhibition; i++) + { + InhibitionSpecies = inhibit[i]->speciesnumber; + InhibitionConcentration = inhibit[i]->concentration; + // ATTENTION!!! + // CB 16/10/09 fix of Fe3 inhibition concentration for Brand model, + // this parameter depends on porosity as in Min3P Fe3 is in solid phase + // and Inhibition concentrations are expressed in terms of Volume fraction + // Vol_Fe3/Vol_BulkAquifer [m?m�] + // while in Geosys, Fe3 is considered an immobile aqueous species + // and concentrations were converted to [mol/L_water] by + // C_gs = C_min3p * rho_Fe3 / molweight / porosity + // for inhibition concentrations, division by porosity is still required + // if(inhibit[i]->species.compare("Fe3")==0) { + // InhibitionConcentration *= 1/GetPhaseVolumeAtNode(currentnode, 1, 0); + // } // CB further changes in derivs (1), jacbn (2), class CKinReact{} + C = c[InhibitionSpecies + 1]; + Growth *= Inhibition(InhibitionConcentration, C); + } return Growth; } @@ -5240,16 +5445,16 @@ double CKinReact::BacteriaGrowth(int r, double *c, double sumX, int exclude, lon /* */ /**************************************************************************/ double CKinReact::Monod(double MC, double C, double Ctot, double order) -//double CKinReact::Monod ( double MC, double C ) +// double CKinReact::Monod ( double MC, double C ) { double Monod; - //CKinReactData *m_krd = KinReactData_vector[0]; + // CKinReactData *m_krd = KinReactData_vector[0]; if (C > 0.) - //Monod=C/(MC+C); // normaler Monodterm - Monod = pow((C / (MC + Ctot)), order); // CB higher order Monod terms --> factor order for partial derivatives + // Monod=C/(MC+C); // normaler Monodterm + Monod = pow((C / (MC + Ctot)), order); // CB higher order Monod terms --> factor order for partial derivatives else /* linearisierter Term fuer c<=0, with very small slope due to high concentrations */ - Monod = pow(((C / 1000.) / MC), order); // CB higher order Monod terms + Monod = pow(((C / 1000.) / MC), order); // CB higher order Monod terms return Monod; } @@ -5283,7 +5488,7 @@ double CKinReact::Inhibition(double IC, double C) Inhibition = IC / (IC + C); else /* linearisierter Term fuer C<=0 */ - Inhibition = 1.0; //Inhibition=1.-C/IC; CB changed due to stimulance of growth for neg conc. + Inhibition = 1.0; // Inhibition=1.-C/IC; CB changed due to stimulance of growth for neg conc. return Inhibition; } @@ -5313,49 +5518,47 @@ double CKinReact::Inhibition(double IC, double C) /* */ /*************************************************************************************/ -void jacobn(double t, double c[], double dfdt[], double** dfdc, int n, - long node) +void jacobn(double t, double c[], double dfdt[], double** dfdc, int n, long node) { - t = t; //OK411 - int i, j, r, nreactions, BacteriaNumber, NumberMonod, MonodSpecies, - NumberInhibition, InhibitionSpecies; + t = t; // OK411 + int i, j, r, nreactions, BacteriaNumber, NumberMonod, MonodSpecies, NumberInhibition, InhibitionSpecies; int Sp1, Sp2, SpX, surfaceID = -1, surfaceID2, blob; - double maxkap, speccap, BacteriaMass, sumX=0., BacGrowth, maxVelocity, *d2X_dtdS; - double CMonodSpecies, MonodConcentration, CInhibitionSpecies, - InhibitionConcentration, Yield; + double maxkap, speccap, BacteriaMass, sumX = 0., BacGrowth, maxVelocity, *d2X_dtdS; + double CMonodSpecies, MonodConcentration, CInhibitionSpecies, InhibitionConcentration, Yield; double porosity1, porosity2, exch, kd, density1, saturation2, kadsorb; double kdesorb, totalSurface, adsorb, exponent, parameter; - //SBtodo double occupiedSurface[maxSurfaces+1]; + // SBtodo double occupiedSurface[maxSurfaces+1]; vector occupiedSurface; int IsotopeSpecies; double Ciso; double MonodOrder; double ThreshOrder; double ThreshConc; - double Yieldcff=0; + double Yieldcff = 0; - double ratefact=1; + double ratefact = 1; - int MineralNumber, MineralSpecies, MechSpecies, no_mech, no_mechspec; - double MineralGrowth, CMineralSpecies, StoechMinSpecies, CMechSpecies, ExpoMechSpecies, omega, dXdt_Mech; - double theta, eta, eta2, area, Betrag, BetragArg; - CKinReact* m_kr = NULL, * m_kr1 = NULL; //OK411 *m_kr2=NULL; + int MineralNumber, MineralSpecies, MechSpecies, no_mech, no_mechspec; + double MineralGrowth, CMineralSpecies, StoechMinSpecies, CMechSpecies, ExpoMechSpecies, omega, dXdt_Mech; + double theta, eta, eta2, area, Betrag, BetragArg; + CKinReact *m_kr = NULL, *m_kr1 = NULL; // OK411 *m_kr2=NULL; CKinBlob* m_kb = NULL; CKinReactData* m_krd = NULL; - MinkinMech *m_mech = NULL; + MinkinMech* m_mech = NULL; // CMediumProperties *m_mat_mp = NULL; double foc; - double dt=0; + double dt = 0; m_krd = KinReactData_vector[0]; -// what's the current time step size? -if(m_krd->NumberMineralkinetics>0){ - CTimeDiscretization *m_tim = NULL; - m_tim = time_vector[0]; - dt = m_tim->CalcTimeStep(); -} + // what's the current time step size? + if (m_krd->NumberMineralkinetics > 0) + { + CTimeDiscretization* m_tim = NULL; + m_tim = time_vector[0]; + dt = m_tim->CalcTimeStep(); + } - //if(m_krd->debugoutflag) + // if(m_krd->debugoutflag) // m_krd->debugoutstr << " jacobn" << "\n" << flush; /* Hilfsvektor f�r partielle Ableitung des Bakterienwachstums nach Species S */ @@ -5375,7 +5578,7 @@ if(m_krd->NumberMineralkinetics>0){ maxkap = m_krd->maxBacteriaCapacity; // F�r Berechnung der Ableitungen f�r den Fall dass eine maximale Kapazit�t ber�cksichtigt werden muss // Muss sein, weil Ableitungen h�here Ordnung haben (Bakterienmasse steckt auch in Kapazit�tsgleichung) - sumX = 0.; // added CB + sumX = 0.; // added CB if (maxkap > 1.E-30) { for (i = 0; i < n; i++) @@ -5402,435 +5605,425 @@ if(m_krd->NumberMineralkinetics>0){ { BacteriaNumber = m_kr->bacteria_number + 1; BacteriaMass = c[BacteriaNumber]; - speccap = m_kr->specif_cap; + speccap = m_kr->specif_cap; if (BacteriaMass > 1.E-40) { /* Ableitungen werden aus dX/dt = BacGrowth berechnet */ // sumX is different for case with (>0) or without (==0) maxkap - m_kr->currentnode = node; // CB This is eclusively for Brand model to allow porosity in Inhibition constant calculation - Yieldcff = m_kr->EffectiveYield(node); - BacGrowth = m_kr->BacteriaGrowth(r, c, sumX, -1, node); + m_kr->currentnode = node; // CB This is eclusively for Brand model to allow porosity in Inhibition + // constant calculation + Yieldcff = m_kr->EffectiveYield(node); + BacGrowth = m_kr->BacteriaGrowth(r, c, sumX, -1, node); for (i = 0; i < n; i++) d2X_dtdS[i + 1] = 0.; - // Berechnung der Bakterien Ableitungen für den Fall dass eine maximale Kapazität berücksichtigt werden muss - // Muss sein, weil Ableitungen höhere Ordnung haben (Bakterienmasse steckt auch in Kapazitätsgleichung) - // This is for the case that growth of any bacteria is limited by total bacteria density sumX & maxkap - if ((maxkap>1.E-30) && (speccap<1e-30)) // no bacteria specific capacity term defined - { - maxVelocity = m_kr->rateconstant; - /* Wachstumsterm, ber�cksichtige Kapazit�tsterm */ - if (maxVelocity > 1.E-30) - { - // Erst Berechnen der Ableitungen des Bakterienwachstums nach allen anderen Substanzen - // Ableitung nach der Bakterienmasse (mit Ber�cksichtigung Kapazit�tsterm) - // d2Xi / dt*dXi = BacGrowth *(sumx+maxkap-Xi) / (Xi*(sumx+maxkap)) - d2X_dtdS[BacteriaNumber] = BacGrowth * - (sumX + maxkap - - - BacteriaMass) / - (BacteriaMass * (sumX - + - maxkap)) * Yieldcff; // CB 08/12 added yield coeff - for (i = 0; i < n; i++) - { - if (m_krd->is_a_bacterium[i] && (i + 1 - != - BacteriaNumber)) - // Ableitung nach den anderen Bakterienmassen im Kapazit�tsterm - // d2Xi / dt*dXj = BacGrowth / -(sumx+maxkap) - d2X_dtdS[i + - 1] = BacGrowth / - -(sumX + maxkap) * Yieldcff; // CB 08/12 added yield coeff - } - } /* Sterbeterm, grunds�tzlich keine Ber�cksichtigung des Kapazit�tsterms */ - else { /* Sterbeterm, grundsätzlich keine Berücksichtigung des Kapazitätsterms */ - /* d2Xi / dt*dXi = BacGrowth / Xi */ - d2X_dtdS[BacteriaNumber] = BacGrowth / BacteriaMass; - /* d2Xi / dt*dXj = 0 for decay */ - } - } - // This is for the case that growth of a specific bacteria is limited by the SPECIFIC bacteria density BacteriaMass & specif_cap - else if (speccap>1e-30) { // bacteria specific capacity term defined - maxVelocity=m_kr->rateconstant; - /* Wachstumsterm, berücksichtige Kapazitätsterm */ - if (maxVelocity > 1.E-30) { - // Erst Berechnen der Ableitungen des Bakterienwachstums nach allen anderen Substanzen - // Ableitung nach der Bakterienmasse (mit Berücksichtigung d. spezif. Kapazitätsterms) - // d2Xi / dt*dXi = BacGrowth *(specif_cap) / (Xi*(Xi+specif_cap)) - d2X_dtdS[BacteriaNumber] = BacGrowth * (speccap) / (BacteriaMass*(BacteriaMass+speccap)) *Yieldcff; // CB 08/12 added yield coeff - // Ableitung nach den anderen Bakterienmassen im Kapazitätsterm non existant - } - else { /* Sterbeterm, grundsätzlich keine Berücksichtigung des Kapazitätsterms */ - /* d2Xi / dt*dXi = BacGrowth / Xi */ - d2X_dtdS[BacteriaNumber] = BacGrowth / BacteriaMass; - /* d2Xi / dt*dXj = 0 for decay */ - } - } - // Berechnung der Bakterien Ableitungen für den Fall dass KEINE maximale Kapazität berücksichtigt werden muss - // without capacity term, this is identical for growth and decay term; but not if yield coeff is considered (CB) - else { // maxkap = 0 - /* d2Xi / dt*dXi = BacGrowth / Xi */ - d2X_dtdS[BacteriaNumber] = BacGrowth / BacteriaMass * Yieldcff; // CB 08/12 added yield coeff = 1 for decay; - } - - /* Schleife f�r Ableitungen nach Substanzen in Monodtermen; unabh�ngig von maxkap */ - NumberMonod = m_kr->number_monod; - for (i = 0; i < NumberMonod; i++) - { - // d2X / dt*dS_j = S_j = monod-species - // S_j may be ZERO or below ! - MonodSpecies = m_kr->monod[i]->speciesnumber + 1; - MonodConcentration = m_kr->monod[i]->concentration; - MonodOrder = m_kr->monod[i]->order; - CMonodSpecies = c[MonodSpecies]; - if (CMonodSpecies > 1.E-20) - { - // S_j > 0, normal Monod Term used - // divide BacGrowth through Monod-Term of spec. j - // and multiplicate with partial derivate of Monod-Term - - //In case of isotope fractionation of substrate Si,Sj (i,j=l,h ; light,heavy) - // - the partial derivative d2X/dtdSi is different: - // d2X_dtdS[Si] = BacGrowth * (MonodConcentration+CisotopePartner) - // / CMonodSpecies / (MonodConcentration+CMonodSpecies+CisotopePartner) - // - an additional partial derivative d2X/dtdSj with respect to the isotope partner Sj appears - // and must be accounted for and added in the vector d2X_dtdS[...] for the current reaction: - // d2X_dtdS[Sj] = BacGrowth * (-1) / (MonodConcentration+CMonodSpecies+CisotopePartner)... - - if ((m_kr->monod[i]->species == m_kr->Isotope_heavy) || (m_kr->monod[i]->species == m_kr->Isotope_light)) { - IsotopeSpecies = m_kr->monod[i]->isotopecouplenumber+1; - Ciso = c[IsotopeSpecies]; - //this is the term for the Monod-Species - d2X_dtdS[MonodSpecies] = BacGrowth* - MonodOrder - * ( - MonodConcentration + Ciso) - / CMonodSpecies / - ( - MonodConcentration - + - CMonodSpecies+Ciso); // no isofrac - // now get the partial derivative d2x/dtdSj with respect to isotope partner - d2X_dtdS[IsotopeSpecies] = BacGrowth * - MonodOrder - * (-1)/ - ( - MonodConcentration - + - CMonodSpecies+Ciso); - //If a threshhold term exists for the Monod species, the partial derivative is modified for this species - // - the ODE with Monod and threshold term for Monod species C and Isotope fractionation is: - // dX/dt = my*R * [Cl/(Cl+Ch+K)]^n * [(Cl+Ch)/(Cl+Ch+T)]^m - // - with n and K the Order and Monod-concentration of the Monod term - // - with m and T the Order and Threshhold-concentration of the threshhold term - // - The partial derivative with respect to Cl (taking into account Division by the Monod and Threshhold term) is - // d2X/dtdCl = my*R * [n*(Ch+K)/Cl/(Cl+Ch+K) + p*T/(Cl+Ch)/(Cl+Ch+T)] - // - The partial derivative with respect to Ch (taking into account Division by the Monod and Threshhold term) is - // d2X/dtdCh = my*R * [-n/(Cl+Ch+K) + p*T/(Cl+Ch)/(Cl+Ch+T)] - // - The latter term is identical for both derivs hence must be added to the previously calculated first terms - if(m_kr->monod[i]->threshhold==true){ - ThreshConc = m_kr->monod[i]->threshConc; - ThreshOrder = m_kr->monod[i]->threshOrder; - d2X_dtdS[MonodSpecies] += BacGrowth * ThreshOrder * ThreshConc / (CMonodSpecies+Ciso) / (ThreshConc+CMonodSpecies+Ciso); // isofrac - d2X_dtdS[IsotopeSpecies] += BacGrowth * ThreshOrder * ThreshConc / (CMonodSpecies+Ciso) / (ThreshConc+CMonodSpecies+Ciso); // isofrac - } - } - else // no isofrac standard case: d2X_dtdS[MonodSpecies] = BacGrowth * MonodConcentration / CMonodSpecies / (MonodConcentration+CMonodSpecies); // no isofrac - { - d2X_dtdS[MonodSpecies] = BacGrowth * - MonodOrder - * - MonodConcentration - / CMonodSpecies - / ( - MonodConcentration+CMonodSpecies); // no isofrac - //If a threshhold term exists for the Monod species, the partial derivative is modified for this species - // - the ODE with Monod and threshold term for Monod species C is: - // dX/dt = my*R * [C/(C+K)]^n * [C/(C+T)]^m - // - with n and K the Order and Monod-concentration of the Monod term - // - with m and T the Order and Threshhold-concentration of the threshhold term - // - The partial derivative with respect to C (taking into account Division by the Monod and Threshhold term) is - // d2X/dtdC = my*R * [n*K/C/(C+K) + p*T/C/(C+T)] - // - The latter term hence must be added to the previously calculated first term - if(m_kr->monod[i]->threshhold==true) - { - ThreshConc = - m_kr->monod[i]->threshConc; - ThreshOrder = - m_kr->monod[i]->threshOrder; - d2X_dtdS[MonodSpecies] += BacGrowth - * - ThreshOrder - * - ThreshConc - / - CMonodSpecies - / ( - ThreshConc - + - CMonodSpecies); // no isofrac - } - } - } - else if (CMonodSpecies < -1.E-20) - { - /* S_j << 0, linear Monod Term used */ - //d2X_dtdS[MonodSpecies] = BacGrowth / CMonodSpecies ; - d2X_dtdS[MonodSpecies] = BacGrowth * MonodOrder - / CMonodSpecies / 1000; // Changed monod term with smaller slope CB - if (m_kr->monod[i]->threshhold == true) - { - ThreshConc = m_kr->monod[i]->threshConc; - ThreshOrder = m_kr->monod[i]->threshOrder; - d2X_dtdS[MonodSpecies] += BacGrowth * - ThreshOrder - * ThreshConc / - CMonodSpecies / - (ThreshConc - + - CMonodSpecies); // no isofrac - } - } // Todo CB isofrac special case necessary? Threshhold terms?? - else - { - // S_j near 0 numerically instable - // recompute BacGrowth without S_j - // (hope, that will only sometimes occur) - - m_kr->currentnode = node; // CB 19/10/09 This is eclusively for Brand model to allow porosity in Inhibition constant calculation - - d2X_dtdS[MonodSpecies] = m_kr->BacteriaGrowth( - r, - c, - sumX, - MonodSpecies, node) - / MonodConcentration; - } - } // for NumberMonod - - /* Schleife f�r Ableitungen nach Substanzen in Inhibitionstermen, unabh�ngig von maxkap */ - NumberInhibition = m_kr->number_inhibit; - for (i = 0; i < NumberInhibition; i++) - { - // d2X / dt*dS_j = S_j = inhibition-species - // S_j may be Zero without any problem - InhibitionSpecies = m_kr->inhibit[i]->speciesnumber + 1; - InhibitionConcentration = m_kr->inhibit[i]->concentration; - - // ATTENTION!!! - // CB 16/10/09 fix of Fe3 inhibition concentration for Brand model, - // this parameter depends on porosity as in Min3P Fe3 is in solid phase - // and Inhibition concentrations are expressed in terms of Volume fraction - // Vol_Fe3/Vol_BulkAquifer [m?m�] - // while in Geosys, Fe3 is considered an immobile aqueous species - // and concentrations were converted to [mol/L_water] by - // C_gs = C_min3p * rho_Fe3 / molweight / porosity - // for inhibition concentrations, division by porosity is still required -// if(m_kr->inhibit[i]->species.compare("Fe3")==0) { -// InhibitionConcentration *= 1/m_kr->GetPhaseVolumeAtNode(node, 1, 0); -// } // CB further changes in derivs (1), jacbn (2), class CKinReact{} - - CInhibitionSpecies = c[InhibitionSpecies]; - if (CInhibitionSpecies > 0.) - { - // S_j > 0, normal Inhibition Term used - // divide BacGrowth through Inhibition-Term of spec. j - // and multiplicate with partial derivate of Inhi-Term - d2X_dtdS[InhibitionSpecies] - = -BacGrowth / (InhibitionConcentration - + CInhibitionSpecies); - } - else - { - /* S_j <= 0, linear Inhibition Term used */ - //d2X_dtdS[InhibitionSpecies] = - BacGrowth / (InhibitionConcentration-CInhibitionSpecies);// CB changed as in next line - d2X_dtdS[InhibitionSpecies] = -BacGrowth - / ( - InhibitionConcentration); // CB changed due to stimulance of growth for neg conc. - } - } - - /* transfer partial derivatives to dfdc-Array of equation solver */ - if (m_kr->grow) - { - for (i = 0; i < n; i++) - /* transfer der berechneten Ableitungen f�r die Bakteriengruppe */ - dfdc[BacteriaNumber][i + 1] += d2X_dtdS[i + 1]; - } - - /* Berechnung der Ableitungen f�r die vom Bakteriellen Wachstum abh�ngigen Substanzen, unabh�ngig von maxkap */ - /* d2S_j / dt*dS_k = yield(j) * d2X/dt*dS_k */ - porosity1 = m_kr->GetReferenceVolume(BacteriaNumber - 1, node); - for (i = 0; i < n; i++) - { - Yield = m_kr->ProductionStoch[i]; - if (fabs(Yield) > 1.E-30) - { - porosity2 = m_kr->GetReferenceVolume(i, node); - for (j = 0; j < n; j++) - { - if (fabs(d2X_dtdS[j + 1]) > 1.E-30) - dfdc[i + 1][j + - 1] += - d2X_dtdS[j + 1] * Yield - * porosity1 / - porosity2; - } - } - } - - } // Ende if BacteriaMass > 1e-40*/ - } // Ende if type monod - } // Ende Schleife �ber nreactions*/ - - -// Berechnung der Ableitungen der Mineralkinetiken -for (r=0; rswitched_off_node.size()>0) - if(m_kr->switched_off_node[node]== true) - continue; - - // Mineral kinetics - if(m_kr->typeflag_mineralkinetics){ - //first, compute quantities that are used several times below - omega = m_kr->Omega(c, node); - theta = m_kr->Theta; - BetragArg = 1-pow(omega, theta); - Betrag = fabs(BetragArg ); - // Equilibrium: when rate is zero, division by 0 (1-omega^theta) is a problem, - // therefore, do only when not in equilibrium - if (Betrag>0){ - // get quantities - eta = m_kr->Eta; - eta2 = m_kr->precipexponent; - MineralNumber = m_kr->mineral_number+1; - // This is the mineral growth rate, i.e. the basic derivative dM/dt - MineralGrowth = m_kr->MinRate ( c, node, dt, omega); - //initialize vector before calculating partial derivs - for (i=0; iminSpeciesIdx.size()); i++) { - MineralSpecies = m_kr->minSpeciesIdx[i]+1; - CMineralSpecies = c[MineralSpecies]; - StoechMinSpecies = m_kr->ProductionStoch[MineralSpecies-1]; - d2X_dtdS[MineralSpecies] = -fabs(MineralGrowth); // get dM/dt and make it negative - d2X_dtdS[MineralSpecies] /= Betrag ; // reduce power ^eta -> ^(eta-1) - d2X_dtdS[MineralSpecies] *= eta * theta * (-StoechMinSpecies); // factor1 from derivative - if(BetragArg <= -1) // strong supersaturation - d2X_dtdS[MineralSpecies] *= 1/eta2; // --> slow down precipitation rate by root fct. (default = 1) - if( CMineralSpecies>1e-25 || CMineralSpecies<-1e-25 ) // factor2 from derivative - d2X_dtdS[MineralSpecies] *= 1 / CMineralSpecies; - else // for almost zero concentration - d2X_dtdS[MineralSpecies] *= 1 / 1e-25; - d2X_dtdS[MineralSpecies] *= pow(omega, theta); // factor3 from derivative - } - - //(2) - // - // d2M_dtdCmech derivative wrt mechanism species in rate constant of rate law - // d2M_dtdCmech = 0 + 0 + ... + K_mech*A* |1-Om^theta|^eta * MechExpo_i/Cmech_i - // - // calculate these partial derivatives here without using previously calculated dM/dt - // as only the a term containing Cmech remains from sum after taking derivative. - // This partial derviatives adds up to a mineral species p.d. from (1), - // when it is a mech species at the same time; however, no special treatment is required - // first, get some quantities - - // todo: check root function derivative - - no_mech = int(m_kr->mechvec.size()); - - // get Surface Area - if (m_kr->Am_constant) - area = m_kr->Am[0]; - else - area = m_kr->Am[node]; - porosity1 = m_kr->GetReferenceVolume(MineralNumber-1,node); - for (i=0; imechvec[i]; - no_mechspec = m_mech->no_mechSpec; - // the next is identical for all MechSpecies partial derivs - dXdt_Mech = pow(Betrag, eta); // = |1-Om^theta|^eta - if(BetragArg <= -1) // strong supersaturation - dXdt_Mech = pow(dXdt_Mech, 1/eta2); // --> slow down precipitation rate by root function (default = 1) - dXdt_Mech *= m_mech->Mech(c, node) * area / porosity1; // *K_mech*A0/(1-n) ; unit: --> mol/s/m³_solid - if(BetragArg <= 0) // supersaturation - dXdt_Mech *= m_kr->precipfactor; // --> slow down precipitation rate by factor (default = 1) - for(j=0;jmechSpeciesIdx[j]+1; - CMechSpecies = c[MechSpecies]; - //pH!!! - //if(m_mech->mechSpeciesNames[j].compare("pH")==0) // pH is -log(gamma*H+) - // CMechSpecies = pow(10,-CMechSpecies); - ExpoMechSpecies = m_mech->mechSpeciesExpo[j]; - // the next is specific to MechSpecies_j p. deriv - // but severeal mechanisms_i may contain the same mech species, - // and it may ALSO be a mineral species from (1) at the same time - // therefore += results - if( CMechSpecies>1e-25 || CMechSpecies<-1e-25 ) - d2X_dtdS[MechSpecies] += dXdt_Mech*ExpoMechSpecies/CMechSpecies; // * MechExpo_i/Cmech_i - else - d2X_dtdS[MechSpecies] += dXdt_Mech*ExpoMechSpecies/1e-25; // * MechExpo_i/Cmech_i - } - } - - //(3) - // - // d2M_dtdM derivative wrt mineral mass is zero always, - // d2M_dtdM = 0 - // - // ... as activity of mineral in IAP of rate law is 1 always per definition - d2X_dtdS[MineralNumber]=0.0; - - // now transfer partial derivatives to dfdc-Array of equation solver - // rows i of J contain a single species' derivatives wrt all other species d2Ci/dtdCj - for (j=0; j mol/s/m³_solid - - //(4) - // - // derivatives of produced or consumed species, the Mineral species - // d2S_j / dt*dS_k = yield(j) * d2X/dt*dS_k - // - // These are simply coupled to p.d. of Mineral wtr. to all other species d2X_dtdS - // via the stoechiometric coefficients; Attention: - // this MUST be zero for the mineral itself, as otherwise, the p.d. is added here again - porosity1 = m_kr->GetReferenceVolume(MineralNumber-1,node); - for (i=0; iProductionStoch[i]; // = 0 for Mineral (must), <0 for min species consumed, >0 for species produced by precipitation - if (fabs(Yield)>1.E-30) { - porosity2 = m_kr->GetReferenceVolume(i,node); - for (j=0; j1.E-30) - // unit conversion: --> mol/s/m³_solid * m³sol/m³Aq * (m³w/m³Aq)^-1 = mol/s/m³w - dfdc[i+1][j+1] += d2X_dtdS[j+1] * Yield * porosity1 / porosity2; - } - } - } - - } // if (fabs(1-pow(omega, theta)) > 0) --> no equiliubrium - } //if(m_kr->typeflag_mineralkinetics) + // Berechnung der Bakterien Ableitungen für den Fall dass eine maximale Kapazität berücksichtigt werden + // muss + // Muss sein, weil Ableitungen höhere Ordnung haben (Bakterienmasse steckt auch in Kapazitätsgleichung) + // This is for the case that growth of any bacteria is limited by total bacteria density sumX & maxkap + if ((maxkap > 1.E-30) && (speccap < 1e-30)) // no bacteria specific capacity term defined + { + maxVelocity = m_kr->rateconstant; + /* Wachstumsterm, ber�cksichtige Kapazit�tsterm */ + if (maxVelocity > 1.E-30) + { + // Erst Berechnen der Ableitungen des Bakterienwachstums nach allen anderen Substanzen + // Ableitung nach der Bakterienmasse (mit Ber�cksichtigung Kapazit�tsterm) + // d2Xi / dt*dXi = BacGrowth *(sumx+maxkap-Xi) / (Xi*(sumx+maxkap)) + d2X_dtdS[BacteriaNumber] = BacGrowth * (sumX + maxkap - BacteriaMass) + / (BacteriaMass * (sumX + maxkap)) + * Yieldcff; // CB 08/12 added yield coeff + for (i = 0; i < n; i++) + { + if (m_krd->is_a_bacterium[i] && (i + 1 != BacteriaNumber)) + // Ableitung nach den anderen Bakterienmassen im Kapazit�tsterm + // d2Xi / dt*dXj = BacGrowth / -(sumx+maxkap) + d2X_dtdS[i + 1] = BacGrowth / -(sumX + maxkap) * Yieldcff; // CB 08/12 added yield coeff + } + } /* Sterbeterm, grunds�tzlich keine Ber�cksichtigung des Kapazit�tsterms */ + else + { /* Sterbeterm, grundsätzlich keine Berücksichtigung des Kapazitätsterms */ + /* d2Xi / dt*dXi = BacGrowth / Xi */ + d2X_dtdS[BacteriaNumber] = BacGrowth / BacteriaMass; + /* d2Xi / dt*dXj = 0 for decay */ + } + } + // This is for the case that growth of a specific bacteria is limited by the SPECIFIC bacteria density + // BacteriaMass & specif_cap + else if (speccap > 1e-30) + { // bacteria specific capacity term defined + maxVelocity = m_kr->rateconstant; + /* Wachstumsterm, berücksichtige Kapazitätsterm */ + if (maxVelocity > 1.E-30) + { + // Erst Berechnen der Ableitungen des Bakterienwachstums nach allen anderen Substanzen + // Ableitung nach der Bakterienmasse (mit Berücksichtigung d. spezif. Kapazitätsterms) + // d2Xi / dt*dXi = BacGrowth *(specif_cap) / (Xi*(Xi+specif_cap)) + d2X_dtdS[BacteriaNumber] = BacGrowth * (speccap) / (BacteriaMass * (BacteriaMass + speccap)) + * Yieldcff; // CB 08/12 added yield coeff + // Ableitung nach den anderen Bakterienmassen im Kapazitätsterm non existant + } + else + { /* Sterbeterm, grundsätzlich keine Berücksichtigung des Kapazitätsterms */ + /* d2Xi / dt*dXi = BacGrowth / Xi */ + d2X_dtdS[BacteriaNumber] = BacGrowth / BacteriaMass; + /* d2Xi / dt*dXj = 0 for decay */ + } + } + // Berechnung der Bakterien Ableitungen für den Fall dass KEINE maximale Kapazität berücksichtigt werden + // muss + // without capacity term, this is identical for growth and decay term; but not if yield coeff is + // considered (CB) + else + { // maxkap = 0 + /* d2Xi / dt*dXi = BacGrowth / Xi */ + d2X_dtdS[BacteriaNumber] + = BacGrowth / BacteriaMass * Yieldcff; // CB 08/12 added yield coeff = 1 for decay; + } -} + /* Schleife f�r Ableitungen nach Substanzen in Monodtermen; unabh�ngig von maxkap */ + NumberMonod = m_kr->number_monod; + for (i = 0; i < NumberMonod; i++) + { + // d2X / dt*dS_j = S_j = monod-species + // S_j may be ZERO or below ! + MonodSpecies = m_kr->monod[i]->speciesnumber + 1; + MonodConcentration = m_kr->monod[i]->concentration; + MonodOrder = m_kr->monod[i]->order; + CMonodSpecies = c[MonodSpecies]; + if (CMonodSpecies > 1.E-20) + { + // S_j > 0, normal Monod Term used + // divide BacGrowth through Monod-Term of spec. j + // and multiplicate with partial derivate of Monod-Term + + // In case of isotope fractionation of substrate Si,Sj (i,j=l,h ; light,heavy) + // - the partial derivative d2X/dtdSi is different: + // d2X_dtdS[Si] = BacGrowth * (MonodConcentration+CisotopePartner) + // / CMonodSpecies / (MonodConcentration+CMonodSpecies+CisotopePartner) + // - an additional partial derivative d2X/dtdSj with respect to the isotope partner Sj appears + // and must be accounted for and added in the vector d2X_dtdS[...] for the current reaction: + // d2X_dtdS[Sj] = BacGrowth * (-1) / (MonodConcentration+CMonodSpecies+CisotopePartner)... + + if ((m_kr->monod[i]->species == m_kr->Isotope_heavy) + || (m_kr->monod[i]->species == m_kr->Isotope_light)) + { + IsotopeSpecies = m_kr->monod[i]->isotopecouplenumber + 1; + Ciso = c[IsotopeSpecies]; + // this is the term for the Monod-Species + d2X_dtdS[MonodSpecies] = BacGrowth * MonodOrder * (MonodConcentration + Ciso) + / CMonodSpecies + / (MonodConcentration + CMonodSpecies + Ciso); // no isofrac + // now get the partial derivative d2x/dtdSj with respect to isotope partner + d2X_dtdS[IsotopeSpecies] + = BacGrowth * MonodOrder * (-1) / (MonodConcentration + CMonodSpecies + Ciso); + // If a threshhold term exists for the Monod species, the partial derivative is modified for + // this species + // - the ODE with Monod and threshold term for Monod species C and Isotope fractionation + // is: + // dX/dt = my*R * [Cl/(Cl+Ch+K)]^n * [(Cl+Ch)/(Cl+Ch+T)]^m + // - with n and K the Order and Monod-concentration of the Monod term + // - with m and T the Order and Threshhold-concentration of the threshhold term + // - The partial derivative with respect to Cl (taking into account Division by the Monod + // and Threshhold term) is + // d2X/dtdCl = my*R * [n*(Ch+K)/Cl/(Cl+Ch+K) + p*T/(Cl+Ch)/(Cl+Ch+T)] + // - The partial derivative with respect to Ch (taking into account Division by the Monod + // and Threshhold term) is + // d2X/dtdCh = my*R * [-n/(Cl+Ch+K) + p*T/(Cl+Ch)/(Cl+Ch+T)] + // - The latter term is identical for both derivs hence must be added to the previously + // calculated first terms + if (m_kr->monod[i]->threshhold == true) + { + ThreshConc = m_kr->monod[i]->threshConc; + ThreshOrder = m_kr->monod[i]->threshOrder; + d2X_dtdS[MonodSpecies] += BacGrowth * ThreshOrder * ThreshConc / (CMonodSpecies + Ciso) + / (ThreshConc + CMonodSpecies + Ciso); // isofrac + d2X_dtdS[IsotopeSpecies] += BacGrowth * ThreshOrder * ThreshConc + / (CMonodSpecies + Ciso) + / (ThreshConc + CMonodSpecies + Ciso); // isofrac + } + } + else // no isofrac standard case: d2X_dtdS[MonodSpecies] = BacGrowth * MonodConcentration / + // CMonodSpecies / (MonodConcentration+CMonodSpecies); // no isofrac + { + d2X_dtdS[MonodSpecies] = BacGrowth * MonodOrder * MonodConcentration / CMonodSpecies + / (MonodConcentration + CMonodSpecies); // no isofrac + // If a threshhold term exists for the Monod species, the partial derivative is modified for + // this species + // - the ODE with Monod and threshold term for Monod species C is: + // dX/dt = my*R * [C/(C+K)]^n * [C/(C+T)]^m + // - with n and K the Order and Monod-concentration of the Monod term + // - with m and T the Order and Threshhold-concentration of the threshhold term + // - The partial derivative with respect to C (taking into account Division by the Monod + // and Threshhold term) is + // d2X/dtdC = my*R * [n*K/C/(C+K) + p*T/C/(C+T)] + // - The latter term hence must be added to the previously calculated first term + if (m_kr->monod[i]->threshhold == true) + { + ThreshConc = m_kr->monod[i]->threshConc; + ThreshOrder = m_kr->monod[i]->threshOrder; + d2X_dtdS[MonodSpecies] += BacGrowth * ThreshOrder * ThreshConc / CMonodSpecies + / (ThreshConc + CMonodSpecies); // no isofrac + } + } + } + else if (CMonodSpecies < -1.E-20) + { + /* S_j << 0, linear Monod Term used */ + // d2X_dtdS[MonodSpecies] = BacGrowth / CMonodSpecies ; + d2X_dtdS[MonodSpecies] + = BacGrowth * MonodOrder / CMonodSpecies / 1000; // Changed monod term with smaller slope CB + if (m_kr->monod[i]->threshhold == true) + { + ThreshConc = m_kr->monod[i]->threshConc; + ThreshOrder = m_kr->monod[i]->threshOrder; + d2X_dtdS[MonodSpecies] += BacGrowth * ThreshOrder * ThreshConc / CMonodSpecies + / (ThreshConc + CMonodSpecies); // no isofrac + } + } // Todo CB isofrac special case necessary? Threshhold terms?? + else + { + // S_j near 0 numerically instable + // recompute BacGrowth without S_j + // (hope, that will only sometimes occur) + + m_kr->currentnode = node; // CB 19/10/09 This is eclusively for Brand model to allow porosity in + // Inhibition constant calculation + + d2X_dtdS[MonodSpecies] + = m_kr->BacteriaGrowth(r, c, sumX, MonodSpecies, node) / MonodConcentration; + } + } // for NumberMonod + + /* Schleife f�r Ableitungen nach Substanzen in Inhibitionstermen, unabh�ngig von maxkap */ + NumberInhibition = m_kr->number_inhibit; + for (i = 0; i < NumberInhibition; i++) + { + // d2X / dt*dS_j = S_j = inhibition-species + // S_j may be Zero without any problem + InhibitionSpecies = m_kr->inhibit[i]->speciesnumber + 1; + InhibitionConcentration = m_kr->inhibit[i]->concentration; + + // ATTENTION!!! + // CB 16/10/09 fix of Fe3 inhibition concentration for Brand model, + // this parameter depends on porosity as in Min3P Fe3 is in solid phase + // and Inhibition concentrations are expressed in terms of Volume fraction + // Vol_Fe3/Vol_BulkAquifer [m?m�] + // while in Geosys, Fe3 is considered an immobile aqueous species + // and concentrations were converted to [mol/L_water] by + // C_gs = C_min3p * rho_Fe3 / molweight / porosity + // for inhibition concentrations, division by porosity is still required + // if(m_kr->inhibit[i]->species.compare("Fe3")==0) { + // InhibitionConcentration *= 1/m_kr->GetPhaseVolumeAtNode(node, 1, 0); + // } // CB further changes in derivs (1), jacbn (2), class CKinReact{} + + CInhibitionSpecies = c[InhibitionSpecies]; + if (CInhibitionSpecies > 0.) + { + // S_j > 0, normal Inhibition Term used + // divide BacGrowth through Inhibition-Term of spec. j + // and multiplicate with partial derivate of Inhi-Term + d2X_dtdS[InhibitionSpecies] = -BacGrowth / (InhibitionConcentration + CInhibitionSpecies); + } + else + { + /* S_j <= 0, linear Inhibition Term used */ + // d2X_dtdS[InhibitionSpecies] = - BacGrowth / (InhibitionConcentration-CInhibitionSpecies);// + // CB changed as in next line + d2X_dtdS[InhibitionSpecies] + = -BacGrowth + / (InhibitionConcentration); // CB changed due to stimulance of growth for neg conc. + } + } + + /* transfer partial derivatives to dfdc-Array of equation solver */ + if (m_kr->grow) + { + for (i = 0; i < n; i++) + /* transfer der berechneten Ableitungen f�r die Bakteriengruppe */ + dfdc[BacteriaNumber][i + 1] += d2X_dtdS[i + 1]; + } + + /* Berechnung der Ableitungen f�r die vom Bakteriellen Wachstum abh�ngigen Substanzen, unabh�ngig von + * maxkap */ + /* d2S_j / dt*dS_k = yield(j) * d2X/dt*dS_k */ + porosity1 = m_kr->GetReferenceVolume(BacteriaNumber - 1, node); + for (i = 0; i < n; i++) + { + Yield = m_kr->ProductionStoch[i]; + if (fabs(Yield) > 1.E-30) + { + porosity2 = m_kr->GetReferenceVolume(i, node); + for (j = 0; j < n; j++) + { + if (fabs(d2X_dtdS[j + 1]) > 1.E-30) + dfdc[i + 1][j + 1] += d2X_dtdS[j + 1] * Yield * porosity1 / porosity2; + } + } + } + + } // Ende if BacteriaMass > 1e-40*/ + } // Ende if type monod + } // Ende Schleife �ber nreactions*/ + + // Berechnung der Ableitungen der Mineralkinetiken + for (r = 0; r < nreactions; r++) + { + m_kr = KinReact_vector[r]; + // CB new reaction switch for individual reactions + if (m_kr->switched_off_node.size() > 0) + if (m_kr->switched_off_node[node] == true) + continue; + + // Mineral kinetics + if (m_kr->typeflag_mineralkinetics) + { + // first, compute quantities that are used several times below + omega = m_kr->Omega(c, node); + theta = m_kr->Theta; + BetragArg = 1 - pow(omega, theta); + Betrag = fabs(BetragArg); + // Equilibrium: when rate is zero, division by 0 (1-omega^theta) is a problem, + // therefore, do only when not in equilibrium + if (Betrag > 0) + { + // get quantities + eta = m_kr->Eta; + eta2 = m_kr->precipexponent; + MineralNumber = m_kr->mineral_number + 1; + // This is the mineral growth rate, i.e. the basic derivative dM/dt + MineralGrowth = m_kr->MinRate(c, node, dt, omega); + // initialize vector before calculating partial derivs + for (i = 0; i < n; i++) + d2X_dtdS[i + 1] = 0.0; + //(1) + // + // d2M_dtdCmin derivative wrt mineral species in IAP of rate law + // d2M_dtdCmin = - K * Am * eta * theta * Stoech_i / C_i * |1-Om^theta|^(eta-1) * Om^theta + // + // This is complete, if the mineral species is NOT a mech species at the same time; + // otherwise, additional terms will apear in 2nd deriv, + // these are automaticaly computed below in loop over mechterms and mechspecies (2) + // Anyway, we calculate these partial derivatives based on dM/dt = MineralGrowth. + // StoechCoeff sign in factor2 must be changed because it is defined negative + // for species which in the IAP are forming the mineral (there, they are positive, See fct. Omega) + + // todo: check root function derivative + + for (i = 0; i < int(m_kr->minSpeciesIdx.size()); i++) + { + MineralSpecies = m_kr->minSpeciesIdx[i] + 1; + CMineralSpecies = c[MineralSpecies]; + StoechMinSpecies = m_kr->ProductionStoch[MineralSpecies - 1]; + d2X_dtdS[MineralSpecies] = -fabs(MineralGrowth); // get dM/dt and make it negative + d2X_dtdS[MineralSpecies] /= Betrag; // reduce power ^eta -> ^(eta-1) + d2X_dtdS[MineralSpecies] *= eta * theta * (-StoechMinSpecies); // factor1 from derivative + if (BetragArg <= -1) // strong supersaturation + d2X_dtdS[MineralSpecies] + *= 1 / eta2; // --> slow down precipitation rate by root fct. (default = 1) + if (CMineralSpecies > 1e-25 || CMineralSpecies < -1e-25) // factor2 from derivative + d2X_dtdS[MineralSpecies] *= 1 / CMineralSpecies; + else // for almost zero concentration + d2X_dtdS[MineralSpecies] *= 1 / 1e-25; + d2X_dtdS[MineralSpecies] *= pow(omega, theta); // factor3 from derivative + } + + //(2) + // + // d2M_dtdCmech derivative wrt mechanism species in rate constant of rate law + // d2M_dtdCmech = 0 + 0 + ... + K_mech*A* |1-Om^theta|^eta * MechExpo_i/Cmech_i + // + // calculate these partial derivatives here without using previously calculated dM/dt + // as only the a term containing Cmech remains from sum after taking derivative. + // This partial derviatives adds up to a mineral species p.d. from (1), + // when it is a mech species at the same time; however, no special treatment is required + // first, get some quantities + + // todo: check root function derivative + + no_mech = int(m_kr->mechvec.size()); + + // get Surface Area + if (m_kr->Am_constant) + area = m_kr->Am[0]; + else + area = m_kr->Am[node]; + porosity1 = m_kr->GetReferenceVolume(MineralNumber - 1, node); + for (i = 0; i < no_mech; i++) + { + m_mech = m_kr->mechvec[i]; + no_mechspec = m_mech->no_mechSpec; + // the next is identical for all MechSpecies partial derivs + dXdt_Mech = pow(Betrag, eta); // = |1-Om^theta|^eta + if (BetragArg <= -1) // strong supersaturation + dXdt_Mech = pow(dXdt_Mech, + 1 / eta2); // --> slow down precipitation rate by root function (default = 1) + dXdt_Mech + *= m_mech->Mech(c, node) * area / porosity1; // *K_mech*A0/(1-n) ; unit: --> mol/s/m³_solid + if (BetragArg <= 0) // supersaturation + dXdt_Mech *= m_kr->precipfactor; // --> slow down precipitation rate by factor (default = 1) + for (j = 0; j < no_mechspec; j++) + { + MechSpecies = m_mech->mechSpeciesIdx[j] + 1; + CMechSpecies = c[MechSpecies]; + // pH!!! + // if(m_mech->mechSpeciesNames[j].compare("pH")==0) // pH is -log(gamma*H+) + // CMechSpecies = pow(10,-CMechSpecies); + ExpoMechSpecies = m_mech->mechSpeciesExpo[j]; + // the next is specific to MechSpecies_j p. deriv + // but severeal mechanisms_i may contain the same mech species, + // and it may ALSO be a mineral species from (1) at the same time + // therefore += results + if (CMechSpecies > 1e-25 || CMechSpecies < -1e-25) + d2X_dtdS[MechSpecies] += dXdt_Mech * ExpoMechSpecies / CMechSpecies; // * MechExpo_i/Cmech_i + else + d2X_dtdS[MechSpecies] += dXdt_Mech * ExpoMechSpecies / 1e-25; // * MechExpo_i/Cmech_i + } + } + + //(3) + // + // d2M_dtdM derivative wrt mineral mass is zero always, + // d2M_dtdM = 0 + // + // ... as activity of mineral in IAP of rate law is 1 always per definition + d2X_dtdS[MineralNumber] = 0.0; + + // now transfer partial derivatives to dfdc-Array of equation solver + // rows i of J contain a single species' derivatives wrt all other species d2Ci/dtdCj + for (j = 0; j < n; j++) // for the Mineral, first row of J + dfdc[MineralNumber][j + 1] += d2X_dtdS[j + 1]; // unit: --> mol/s/m³_solid + + //(4) + // + // derivatives of produced or consumed species, the Mineral species + // d2S_j / dt*dS_k = yield(j) * d2X/dt*dS_k + // + // These are simply coupled to p.d. of Mineral wtr. to all other species d2X_dtdS + // via the stoechiometric coefficients; Attention: + // this MUST be zero for the mineral itself, as otherwise, the p.d. is added here again + porosity1 = m_kr->GetReferenceVolume(MineralNumber - 1, node); + for (i = 0; i < n; i++) + { // these are the rows i + Yield = m_kr->ProductionStoch[i]; // = 0 for Mineral (must), <0 for min species consumed, >0 for + // species produced by precipitation + if (fabs(Yield) > 1.E-30) + { + porosity2 = m_kr->GetReferenceVolume(i, node); + for (j = 0; j < n; j++) + { // these are the j column entries of a row i, Yi is the same in 1 row + if (fabs(d2X_dtdS[j + 1]) > 1.E-30) + // unit conversion: --> mol/s/m³_solid * m³sol/m³Aq * (m³w/m³Aq)^-1 = mol/s/m³w + dfdc[i + 1][j + 1] += d2X_dtdS[j + 1] * Yield * porosity1 / porosity2; + } + } + } + + } // if (fabs(1-pow(omega, theta)) > 0) --> no equiliubrium + } // if(m_kr->typeflag_mineralkinetics) + } /**********************************************************************************************/ /* Berechnung der Ableitungen der Austauschprozesse */ // calculate already occupied surfaces first @@ -5847,15 +6040,14 @@ for (r=0; rswitched_off_node.size() > 0) if (m_kr->switched_off_node[node] == true) continue; - if ((m_kr->getType().compare("exchange") == 0) - && (m_kr->typeflag_exchange_langmuir)) + if ((m_kr->getType().compare("exchange") == 0) && (m_kr->typeflag_exchange_langmuir)) { Sp1 = m_kr->ex_species[0] + 1; surfaceID = m_kr->exSurfaceID; occupiedSurface[surfaceID] += c[Sp1]; } } - } // if NumberLangmuir > 0 + } // if NumberLangmuir > 0 /* Berechnung der Ableitungen der Austauschprozesse */ for (r = 0; r < nreactions; r++) @@ -5871,25 +6063,25 @@ for (r=0; rtypeflag_exchange_linear) { - //Matrix + // Matrix Sp1 = m_kr->ex_species[0] + 1; porosity1 = m_kr->GetReferenceVolume(Sp1 - 1, node); density1 = m_kr->GetDensity(Sp1 - 1, node); - //geloest + // geloest Sp2 = m_kr->ex_species[1] + 1; porosity2 = m_kr->GetReferenceVolume(Sp2 - 1, node); - ratefact = m_kr->ex_param[2]; + ratefact = m_kr->ex_param[2]; exch = m_kr->ex_param[0]; kd = m_kr->ex_param[1]; if (fabs(kd) < MKleinsteZahl) { - // slow down desorption rate by constant factor - if((c[Sp2] - c[Sp1])<0) - exch *= ratefact; + // slow down desorption rate by constant factor + if ((c[Sp2] - c[Sp1]) < 0) + exch *= ratefact; - //no kd, exchange between two species in solution + // no kd, exchange between two species in solution dfdc[Sp1][Sp1] += -exch / porosity1; dfdc[Sp1][Sp2] += exch / porosity1; dfdc[Sp2][Sp1] += exch / porosity2; @@ -5901,18 +6093,17 @@ for (r=0; rnode_foc[node]; if (foc > MKleinsteZahl) kd = kd * foc; - //else + // else // kd = 0; - // slow down desorption rate by constant factor - if((kd * c[Sp2] - c[Sp1]) < 0) - exch *= ratefact; + // slow down desorption rate by constant factor + if ((kd * c[Sp2] - c[Sp1]) < 0) + exch *= ratefact; dfdc[Sp1][Sp1] += -exch; dfdc[Sp1][Sp2] += exch * kd; dfdc[Sp2][Sp1] += exch * porosity1 / porosity2 * density1; - dfdc[Sp2][Sp2] += -exch * kd * porosity1 / porosity2 - * density1; + dfdc[Sp2][Sp2] += -exch * kd * porosity1 / porosity2 * density1; } - } // linear + } // linear /* Langmuir Kinetik */ if (m_kr->typeflag_exchange_langmuir) { @@ -5924,7 +6115,7 @@ for (r=0; rGetReferenceVolume(Sp2 - 1, node); kadsorb = m_kr->ex_param[0]; kdesorb = m_kr->ex_param[1]; - //SB_langmuir surfaceID = m_kr->exSurfaceID; //Exchange.Langmuir[i].SurfaceID; + // SB_langmuir surfaceID = m_kr->exSurfaceID; //Exchange.Langmuir[i].SurfaceID; totalSurface = m_krd->exSurface[m_kr->exSurfaceID]; // occupiedSurface is calculated just above adsorb = kadsorb * (totalSurface - occupiedSurface[surfaceID]); @@ -5944,15 +6135,11 @@ for (r=0; rtypeflag_exchange_freundlich) @@ -5965,32 +6152,30 @@ for (r=0; rex_param[2]; parameter = m_kr->ex_param[1]; exch = m_kr->ex_param[0]; - ratefact = m_kr->ex_param[3]; + ratefact = m_kr->ex_param[3]; - // if both species are in the same phase, density multiplication below is not required - if(cp_vec[Sp1-1]->transport_phase == cp_vec[Sp2-1]->transport_phase) - density1 = 1; + // if both species are in the same phase, density multiplication below is not required + if (cp_vec[Sp1 - 1]->transport_phase == cp_vec[Sp2 - 1]->transport_phase) + density1 = 1; - // slow down DEsorption rate by constant factor - if((parameter * pow(c[Sp2], exponent)-c[Sp1])<0) - exch *= ratefact; + // slow down DEsorption rate by constant factor + if ((parameter * pow(c[Sp2], exponent) - c[Sp1]) < 0) + exch *= ratefact; if (c[Sp2] > residual) // no linearisation required - adsorb = exch * parameter * exponent * pow(c[Sp2], - (exponent - 1.0)); + adsorb = exch * parameter * exponent * pow(c[Sp2], (exponent - 1.0)); else // linearisation required due to instability of c^x if cswitched_off_node[node] == true) continue; - if (m_kr->typeflag_napldissolution) - { - /* NAPL-L�sung */ - Sp1 = m_kr->ex_species[0] + 1; //Exchange.Linear[i].Species1; should be NAPL - // porosity1 = m_kr->GetReferenceVolume(Sp1-1,node); - blob = m_kr->blob_ID; - m_kb = KinBlob_vector[blob]; // pointer to blob-properties set in the reaction r - Sp2 = m_kr->ex_species[1] + 1; //Exchange.Linear[i].Species2; should be dissolved - //CB this includes the saturation - porosity2 = m_kr->GetReferenceVolume(Sp2 - 1, node); - //#ds TODO saturation2 = ?? - saturation2 = 1.; - exponent = m_kr->rateorder; - exch = m_kb->Masstransfer_K[node] * m_kb->Interfacial_area[node]; - exch *= exponent * pow((c[Sp2] ), (exponent - 1.0)); // CB introduced rateorder 06/2012 - - // Remark: In function derivs the dissolution velocity can be reduced, if NAPL concentration falls below zero. - // The partial derivatives should change, too, but this is not considered here. - // However, it works fine - - // Case 1 : reduced rate in derivs - if ((m_kb->Masstransfer_K[node] * m_kb->Interfacial_area[node] * pow((m_kr->Current_Csat[node] - c[Sp2]), exponent)* dt) > c[Sp1]){ - // dfdc[Sp1][Sp2] = 0 derivatives for water-concentration is zero in case of reduced rate in derivs - // dfdc[Sp2][Sp2] = 0 - - if ( (m_kr->Current_Csat[node] < c[Sp2]) || (c[Sp1] > MKleinsteZahl) ) { // no dissolution or NAPL mass present - // dCNAPL/dt = CNAPL/dt - // d2CNAPL / dt dCNAPL = 1/dt - // d2Cmob / dt dCmob = -k*A/n/Sw - dfdc[Sp1][Sp2] += -1/dt; - dfdc[Sp2][Sp2] += 1/dt / porosity2 / saturation2; - } - } - // Case 2 : original rate in derivs - else{ - // dfdc[Sp1][Sp1] = 0 derivatives for NAPL-concentration always zero - // dfdc[Sp2][Sp1] = 0 - - //if ( (m_kr->current_Csat < c[Sp2]) || (c[Sp1] > MKleinsteZahl) ) { // no dissolution or NAPL mass present - if ( (m_kr->Current_Csat[node] < c[Sp2]) || (c[Sp1] > MKleinsteZahl) ) // no dissolution or NAPL mass present - { - // d2CNAPL / dt dCmob = k*A - // d2Cmob / dt dCmob = -k*A/n/Sw - dfdc[Sp1][Sp2] += exch; - dfdc[Sp2][Sp2] += -exch / porosity2 / saturation2; - } - } - } // NAPL-dissolution - } // loop over reactions r + if (m_kr->typeflag_napldissolution) + { + /* NAPL-L�sung */ + Sp1 = m_kr->ex_species[0] + 1; // Exchange.Linear[i].Species1; should be NAPL + // porosity1 = m_kr->GetReferenceVolume(Sp1-1,node); + blob = m_kr->blob_ID; + m_kb = KinBlob_vector[blob]; // pointer to blob-properties set in the reaction r + Sp2 = m_kr->ex_species[1] + 1; // Exchange.Linear[i].Species2; should be dissolved + // CB this includes the saturation + porosity2 = m_kr->GetReferenceVolume(Sp2 - 1, node); + //#ds TODO saturation2 = ?? + saturation2 = 1.; + exponent = m_kr->rateorder; + exch = m_kb->Masstransfer_K[node] * m_kb->Interfacial_area[node]; + exch *= exponent * pow((c[Sp2]), (exponent - 1.0)); // CB introduced rateorder 06/2012 + + // Remark: In function derivs the dissolution velocity can be reduced, if NAPL concentration falls below + // zero. + // The partial derivatives should change, too, but this is not considered here. + // However, it works fine + + // Case 1 : reduced rate in derivs + if ((m_kb->Masstransfer_K[node] * m_kb->Interfacial_area[node] + * pow((m_kr->Current_Csat[node] - c[Sp2]), exponent) + * dt) + > c[Sp1]) + { + // dfdc[Sp1][Sp2] = 0 derivatives for water-concentration is zero in case of reduced rate in + // derivs + // dfdc[Sp2][Sp2] = 0 + + if ((m_kr->Current_Csat[node] < c[Sp2]) || (c[Sp1] > MKleinsteZahl)) + { // no dissolution or NAPL mass present + // dCNAPL/dt = CNAPL/dt + // d2CNAPL / dt dCNAPL = 1/dt + // d2Cmob / dt dCmob = -k*A/n/Sw + dfdc[Sp1][Sp2] += -1 / dt; + dfdc[Sp2][Sp2] += 1 / dt / porosity2 / saturation2; + } + } + // Case 2 : original rate in derivs + else + { + // dfdc[Sp1][Sp1] = 0 derivatives for NAPL-concentration always zero + // dfdc[Sp2][Sp1] = 0 + + // if ( (m_kr->current_Csat < c[Sp2]) || (c[Sp1] > MKleinsteZahl) ) { // no dissolution or NAPL + // mass present + if ((m_kr->Current_Csat[node] < c[Sp2]) + || (c[Sp1] > MKleinsteZahl)) // no dissolution or NAPL mass present + { + // d2CNAPL / dt dCmob = k*A + // d2Cmob / dt dCmob = -k*A/n/Sw + dfdc[Sp1][Sp2] += exch; + dfdc[Sp2][Sp2] += -exch / porosity2 / saturation2; + } + } + } // NAPL-dissolution + } // loop over reactions r //#ds free_dvector(d2X_dtdS, 1, n); @@ -6070,27 +6265,32 @@ void CKinReact::TestWrite(void) int i, length, flag = 0; // Write Keyword - cout - << - "8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888" - << "\n"; - cout << " Test Output " << "\n"; - cout - << - "8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888" - << "\n"; - cout << "#REACTION" << "\n"; + cout << "8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888" + << "\n"; + cout << " Test Output " + << "\n"; + cout << "8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888" + << "\n"; + cout << "#REACTION" + << "\n"; // Name of reaction - cout << "$NAME" << "\n" << name << "\n"; + cout << "$NAME" + << "\n" + << name << "\n"; // Type of reaction - cout << "$TYPE" << "\n" << type << "\n"; + cout << "$TYPE" + << "\n" + << type << "\n"; // bacteria name - cout << "$BACTERIANAME" << "\n" << bacteria_name << "\n"; - //ReactionEquation - cout << "$EQUATION" << "\n"; + cout << "$BACTERIANAME" + << "\n" + << bacteria_name << "\n"; + // ReactionEquation + cout << "$EQUATION" + << "\n"; for (i = 0; i < number_reactionpartner; i++) { - if (stochmet[i] < 0.0) //left side of equation + if (stochmet[i] < 0.0) // left side of equation { if (i == 0) cout << " " << fabs(stochmet[i]) << " " << reactionpartner[i]; @@ -6107,47 +6307,56 @@ void CKinReact::TestWrite(void) } cout << "\n"; // Rateconstant and order - cout << "$RATEKONSTANT" << "\n" << rateconstant << " " << rateorder - << "\n"; - cout << "$GROWTH" << "\n" << grow << "\n"; - //Monod terms - cout << "$MONODTERMS" << "\n" << number_monod << "\n"; + cout << "$RATEKONSTANT" + << "\n" + << rateconstant << " " << rateorder << "\n"; + cout << "$GROWTH" + << "\n" + << grow << "\n"; + // Monod terms + cout << "$MONODTERMS" + << "\n" + << number_monod << "\n"; for (i = 0; i < number_monod; i++) - cout << monod[i]->species << " " << monod[i]->concentration << " " - << monod[i]->order << "\n"; - //Inhibition terms - cout << "$INHIBITIONTERMS" << "\n" << number_inhibit << "\n"; + cout << monod[i]->species << " " << monod[i]->concentration << " " << monod[i]->order << "\n"; + // Inhibition terms + cout << "$INHIBITIONTERMS" + << "\n" + << number_inhibit << "\n"; for (i = 0; i < number_inhibit; i++) - cout << inhibit[i]->species << " " << inhibit[i]->concentration - << " " << inhibit[i]->order << "\n"; + cout << inhibit[i]->species << " " << inhibit[i]->concentration << " " << inhibit[i]->order << "\n"; // Production Terms - cout << "$PRODUCTIONTERMS" << "\n" << number_production << "\n"; + cout << "$PRODUCTIONTERMS" + << "\n" + << number_production << "\n"; for (i = 0; i < number_production; i++) - cout << production[i]->species << " " << production[i]->concentration - << " " << production[i]->order << "\n"; + cout << production[i]->species << " " << production[i]->concentration << " " << production[i]->order << "\n"; // ProductionStochhelp Terms - cout << "$PRODUCTIONSTOCH" << "\n" << (int) ProdStochhelp.size() << "\n"; - for (i = 0; i < (int) ProdStochhelp.size(); i++) - cout << ProdStochhelp[i]->species << " " - << ProdStochhelp[i]->concentration << "\n"; + cout << "$PRODUCTIONSTOCH" + << "\n" + << (int)ProdStochhelp.size() << "\n"; + for (i = 0; i < (int)ProdStochhelp.size(); i++) + cout << ProdStochhelp[i]->species << " " << ProdStochhelp[i]->concentration << "\n"; // exchange - cout << "$EXCHANGE_PARAMETERS" << "\n" << (int) ex_param.size() << "\n"; - for (i = 0; i < (int) ex_param.size(); i++) + cout << "$EXCHANGE_PARAMETERS" + << "\n" + << (int)ex_param.size() << "\n"; + for (i = 0; i < (int)ex_param.size(); i++) cout << ex_param[i] << " "; cout << "\n"; cout << "\n"; - cout << "number_reactionpartner " << (int) number_reactionpartner << "\n"; - cout << "bacteria_number " << (int) bacteria_number << "\n"; + cout << "number_reactionpartner " << (int)number_reactionpartner << "\n"; + cout << "bacteria_number " << (int)bacteria_number << "\n"; cout << "grow " << grow << "\n"; - length = (int) ProductionStoch.size(); + length = (int)ProductionStoch.size(); cout << "length ProductionStoch: " << length << "\n"; for (i = 0; i < length; i++) - cout << (int) ProductionStoch[i] << " "; + cout << (int)ProductionStoch[i] << " "; cout << "\n"; - length = (int) ex_species.size(); + length = (int)ex_species.size(); cout << "length exSpecies: " << length << "\n"; for (i = 0; i < length; i++) cout << ex_species_names[i] << " " << ex_species[i] << "\n"; @@ -6165,19 +6374,20 @@ Task: returns true if NAPL dissolution is modeled **************************************************************************/ bool KNaplDissCheck(void) { - bool NAPLdiss = false; + bool NAPLdiss = false; - CKinReactData *m_krd = NULL; - if(KinReactData_vector.size()==0) - return NAPLdiss; + CKinReactData* m_krd = NULL; + if (KinReactData_vector.size() == 0) + return NAPLdiss; - else{ - m_krd = KinReactData_vector[0]; - if(m_krd->NumberNAPLdissolution>0) - NAPLdiss=true; + else + { + m_krd = KinReactData_vector[0]; + if (m_krd->NumberNAPLdissolution > 0) + NAPLdiss = true; - return NAPLdiss; - } + return NAPLdiss; + } } /************************************************************************** Reaction-Method: @@ -6188,60 +6398,57 @@ Task: returns true if mineral kinetics is modeled **************************************************************************/ bool KMinKinCheck(void) { + bool MinKin = false; - bool MinKin = false; - - CKinReactData *m_krd = NULL; + CKinReactData* m_krd = NULL; - if(KinReactData_vector.size()==0) - return MinKin; + if (KinReactData_vector.size() == 0) + return MinKin; - else{ - m_krd = KinReactData_vector[0]; - if(m_krd->NumberMineralkinetics>0) - MinKin=true; - return MinKin; - } + else + { + m_krd = KinReactData_vector[0]; + if (m_krd->NumberMineralkinetics > 0) + MinKin = true; + return MinKin; + } } /**************************************************************************/ -//Task: Calculates and sets the NAPL density for all nodes +// Task: Calculates and sets the NAPL density for all nodes // in case of NAPL dissolution -//Programing: +// Programing: // 01/2008 CB Implementation /**************************************************************************/ -void KNaplCalcDensity(void){ - - CRFProcess *m_pcs=NULL; - CFluidProperties* m_mfp = NULL; - //CFEMesh* m_msh = NULL; - - double density = 0; - //double viscosity = 0; - long i; - int ndx_density_phase = -1; - long nnodes = 0; - - m_pcs = PCSGetFlow(); - ndx_density_phase = m_pcs->GetNodeValueIndex("DENSITY2"); +void KNaplCalcDensity(void) +{ + CRFProcess* m_pcs = NULL; + CFluidProperties* m_mfp = NULL; + // CFEMesh* m_msh = NULL; - nnodes = int(m_pcs->m_msh->nod_vector.size()); - m_mfp = mfp_vector[m_pcs->pcs_type_number+1]; - m_mfp->mode = 1; + double density = 0; + // double viscosity = 0; + long i; + int ndx_density_phase = -1; + long nnodes = 0; - for(i=0;iGetNodeValueIndex("DENSITY2"); - // CB: Density2 reintroduced as secondary variable of PS_GLOBAL, - m_pcs->SetNodeValue(i,ndx_density_phase,density); + nnodes = int(m_pcs->m_msh->nod_vector.size()); + m_mfp = mfp_vector[m_pcs->pcs_type_number + 1]; + m_mfp->mode = 1; - } - m_mfp->mode = 0; + for (i = 0; i < nnodes; i++) + { + density = CalcNAPLDens(i); + // CB: Density2 reintroduced as secondary variable of PS_GLOBAL, + m_pcs->SetNodeValue(i, ndx_density_phase, density); + } + m_mfp->mode = 0; } - /************************************************************************** Task: Postprocessing function calculates the NAPL saturation after Flow, Transport and kinetic NAPL dissolution @@ -6251,161 +6458,169 @@ Task: Postprocessing function calculates the NAPL saturation after /**************************************************************************/ void CalcNewNAPLSat() { + long i, j, k, l; + int idx0 = 0; + int idx1, idx2, idxC; + long nnodes, nNAPLcomps; + double conc, conc2, rho_N_new, rho_N_old, rho_N_fluid; + double mass, volume; + double satu_N_new, satu_N_old; + + vector pcs_napl_comps_vector; + vector molar_weights_vector; + vector molar_densities_vector; + + string var_name; + int no_processes = (int)pcs_vector.size(); + CRFProcess* m_pcs = NULL; + CRFProcess* n_pcs = NULL; + CFluidProperties* m_mfp = NULL; - long i, j, k, l; - int idx0=0; - int idx1, idx2, idxC; - long nnodes, nNAPLcomps; - double conc, conc2, rho_N_new, rho_N_old, rho_N_fluid; - double mass, volume; - double satu_N_new, satu_N_old ; - - vectorpcs_napl_comps_vector; - vectormolar_weights_vector; - vectormolar_densities_vector; - - string var_name; - int no_processes=(int)pcs_vector.size(); - CRFProcess *m_pcs = NULL; - CRFProcess *n_pcs = NULL; - CFluidProperties* m_mfp = NULL; - - m_pcs = PCSGetFlow(); - - bool psg = false; - if (m_pcs->getProcessType() == FiniteElement::PS_GLOBAL) - psg = true; - - nnodes = (long) fem_msh_vector[0]->nod_vector.size(); - - - // CB PS_GLOBAL this needs update - m_mfp = mfp_vector[m_pcs->pcs_type_number]; - //m_mfp->mode = 1; // CB ?? - - // Get indices of node value variables for phase 2 - if(psg) - idx0 = m_pcs->GetNodeValueIndex("SATURATION2"); // old timelevel - idx1 = m_pcs->GetNodeValueIndex("DENSITY2"); // CB PS_GLOBAL this needs update - idx2 = m_pcs->GetNodeValueIndex("SATURATION1"); // old timelevel - - i = j = k = l = 0; - no_processes =(int)pcs_vector.size(); - - // get the parameters - for(i=0;ipcs_type_name.compare("MASS_TRANSPORT")==0) - if(n_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) - { - j = n_pcs->GetProcessComponentNumber(); - if(cp_vec[j]->transport_phase==3){ // is in napl - pcs_napl_comps_vector.push_back(i); // store processes that are NAPL dissolution components - if(KinBlob_vector[0]->gas_dissolution_flag==false){ - molar_weights_vector.push_back(cp_vec[j]->molar_weight); // get the corresponding molar weight - molar_densities_vector.push_back(cp_vec[j]->molar_density); // get the corresponding densities - } - l++; - } - } - } - nNAPLcomps = l; - - // do the update - for(i = 0; i < nnodes; i++) { - conc = rho_N_new = rho_N_old = rho_N_fluid = satu_N_new = satu_N_old = mass = volume = conc2 = 0; - - if(KinBlob_vector[0]->gas_dissolution_flag==false){ - // determine the old NAPL DENSITY after flow / transport step - for(j = 0; j < nNAPLcomps; j++) { - l=pcs_napl_comps_vector[j]; - idxC = pcs_vector[l]->GetNodeValueIndex(pcs_vector[l]->pcs_primary_function_name[0]); - conc = pcs_vector[l]->GetNodeValue(i, idxC);// old timelevel - mass += conc * molar_weights_vector[j]; - } - if(mass > 0) - rho_N_old = mass; // [kg/m³REV] - else - rho_N_old = 0; - // determine the new NAPL density rho_N_neu at current node - mass = 0; - for(j = 0; j < nNAPLcomps; j++) { - l=pcs_napl_comps_vector[j]; - idxC = pcs_vector[l]->GetNodeValueIndex(pcs_vector[l]->pcs_primary_function_name[0]); - conc = pcs_vector[l]->GetNodeValue(i, idxC+1);// +1 new timelevel - if(fabs(conc)<1e-19) - conc = 0.0; - mass += conc * molar_weights_vector[j]; - volume += conc / molar_densities_vector[j]; // this is required calculating the napl fluid density - } - if(mass > 0) - rho_N_new = mass ; // [kg/m³REV] - else - rho_N_new = 0; - - // get the old SATURATION2 of NAPL after flow / transport step - if(psg) //PS_GLOBAL - satu_N_old = m_pcs->GetNodeValue(i, idx0+1); - else // MULTI_PHASE_FLOW - satu_N_old = 1.0 - m_pcs->GetNodeValue(i, idx2+1); - // calculate new NAPL Saturation: dSatu = Satu(t+dt)-Satu(t) = Satu(t)*(1-rho(t)/rho(t+dt)) - if(satu_N_old * rho_N_new * rho_N_old > 0) - satu_N_new = satu_N_old + satu_N_old * (1 - rho_N_old / rho_N_new); //fast - //satu_N_new = satu_N_old + satu_N_old * (rho_N_new / rho_N_old - 1); //slow - else - satu_N_new = satu_N_old ; - if (satu_N_new <0){ - cout << " Warning in fct CalcNewNAPLSat: NAPL-Sat: " << satu_N_new << "\n"; - satu_N_new = MRange(0.0, satu_N_new, 1.0); - } - - // set new SATURATION2 - //if(satu_N_new > 0.00001) satu_N_new = 1-0.95; // 0.985 CB 14.01.09 Hansen+Kueper BM - - //m_pcs->SetNodeValue(i, idx0, satu_N_new); // idx0 for timelevel 0 ?? - if(psg) - m_pcs->SetNodeValue(i, idx0+1, satu_N_new); // idx0+1 for timelevel 1 ?? - // set new SATURATION1 - //m_pcs->SetNodeValue(i, idx2, 1-satu_N_new); // idx2 for timelevel 0 ?? - m_pcs->SetNodeValue(i, idx2+1, 1-satu_N_new); // idx2+1 for timelevel 1 ?? - // finally determine the new napl fluid density - if(mass * volume > 0) - rho_N_fluid = mass / volume; // [kg/m³N] = [kg/m³REV] / [m³N/m³REV] - else - rho_N_fluid = m_mfp->Density(); // use NAPL phase fluid density as defined in .mfp - // set new DENSITY2 - m_pcs->SetNodeValue(i, idx1, rho_N_fluid); - // CB PS_GLOBAL this needs update - } - else{ // gas_dissolution - // get the old SATURATION2 of NAPL after flow / transport step - if(psg) //PS_GLOBAL - satu_N_old = m_pcs->GetNodeValue(i, idx0); - else // MULTI_PHASE_FLOW only has water satu - satu_N_old = 1.0 - m_pcs->GetNodeValue(i, idx2+1); // idx2+1 as in case of Eclipse coupling, Sats are transient. - // hence the sat before KRC is available only at "new" TL - // get the old and new CO2 conc in gas phase after flow / transport step - for(j = 0; j < nNAPLcomps; j++) { - l=pcs_napl_comps_vector[j]; - idxC = pcs_vector[l]->GetNodeValueIndex(pcs_vector[l]->pcs_primary_function_name[0]); - conc += pcs_vector[l]->GetNodeValue(i, idxC); // old timelevel - conc2 += pcs_vector[l]->GetNodeValue(i, idxC+1); // new timelevel - } - satu_N_new = satu_N_old * (conc2 / conc); // simple scaling - if(psg) // Set new NAPL SATURATION2 - m_pcs->SetNodeValue(i, idx0+1, satu_N_new); - // Set new water SATURATION1 in any case - m_pcs->SetNodeValue(i, idx2+1, 1-satu_N_new); - } - } - pcs_napl_comps_vector.clear(); - molar_weights_vector.clear(); - molar_densities_vector.clear(); - - //m_pcs->WriteAllVariables(); -} + m_pcs = PCSGetFlow(); + + bool psg = false; + if (m_pcs->getProcessType() == FiniteElement::PS_GLOBAL) + psg = true; + + nnodes = (long)fem_msh_vector[0]->nod_vector.size(); + + // CB PS_GLOBAL this needs update + m_mfp = mfp_vector[m_pcs->pcs_type_number]; + // m_mfp->mode = 1; // CB ?? + + // Get indices of node value variables for phase 2 + if (psg) + idx0 = m_pcs->GetNodeValueIndex("SATURATION2"); // old timelevel + idx1 = m_pcs->GetNodeValueIndex("DENSITY2"); // CB PS_GLOBAL this needs update + idx2 = m_pcs->GetNodeValueIndex("SATURATION1"); // old timelevel + + i = j = k = l = 0; + no_processes = (int)pcs_vector.size(); + + // get the parameters + for (i = 0; i < no_processes; i++) + { + n_pcs = pcs_vector[i]; + // if(n_pcs->pcs_type_name.compare("MASS_TRANSPORT")==0) + if (n_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) + { + j = n_pcs->GetProcessComponentNumber(); + if (cp_vec[j]->transport_phase == 3) + { // is in napl + pcs_napl_comps_vector.push_back(i); // store processes that are NAPL dissolution components + if (KinBlob_vector[0]->gas_dissolution_flag == false) + { + molar_weights_vector.push_back(cp_vec[j]->molar_weight); // get the corresponding molar weight + molar_densities_vector.push_back(cp_vec[j]->molar_density); // get the corresponding densities + } + l++; + } + } + } + nNAPLcomps = l; + // do the update + for (i = 0; i < nnodes; i++) + { + conc = rho_N_new = rho_N_old = rho_N_fluid = satu_N_new = satu_N_old = mass = volume = conc2 = 0; + + if (KinBlob_vector[0]->gas_dissolution_flag == false) + { + // determine the old NAPL DENSITY after flow / transport step + for (j = 0; j < nNAPLcomps; j++) + { + l = pcs_napl_comps_vector[j]; + idxC = pcs_vector[l]->GetNodeValueIndex(pcs_vector[l]->pcs_primary_function_name[0]); + conc = pcs_vector[l]->GetNodeValue(i, idxC); // old timelevel + mass += conc * molar_weights_vector[j]; + } + if (mass > 0) + rho_N_old = mass; // [kg/m³REV] + else + rho_N_old = 0; + // determine the new NAPL density rho_N_neu at current node + mass = 0; + for (j = 0; j < nNAPLcomps; j++) + { + l = pcs_napl_comps_vector[j]; + idxC = pcs_vector[l]->GetNodeValueIndex(pcs_vector[l]->pcs_primary_function_name[0]); + conc = pcs_vector[l]->GetNodeValue(i, idxC + 1); // +1 new timelevel + if (fabs(conc) < 1e-19) + conc = 0.0; + mass += conc * molar_weights_vector[j]; + volume += conc / molar_densities_vector[j]; // this is required calculating the napl fluid density + } + if (mass > 0) + rho_N_new = mass; // [kg/m³REV] + else + rho_N_new = 0; + + // get the old SATURATION2 of NAPL after flow / transport step + if (psg) // PS_GLOBAL + satu_N_old = m_pcs->GetNodeValue(i, idx0 + 1); + else // MULTI_PHASE_FLOW + satu_N_old = 1.0 - m_pcs->GetNodeValue(i, idx2 + 1); + // calculate new NAPL Saturation: dSatu = Satu(t+dt)-Satu(t) = Satu(t)*(1-rho(t)/rho(t+dt)) + if (satu_N_old * rho_N_new * rho_N_old > 0) + satu_N_new = satu_N_old + satu_N_old * (1 - rho_N_old / rho_N_new); // fast + // satu_N_new = satu_N_old + satu_N_old * (rho_N_new / rho_N_old - 1); //slow + else + satu_N_new = satu_N_old; + if (satu_N_new < 0) + { + cout << " Warning in fct CalcNewNAPLSat: NAPL-Sat: " << satu_N_new << "\n"; + satu_N_new = MRange(0.0, satu_N_new, 1.0); + } + + // set new SATURATION2 + // if(satu_N_new > 0.00001) satu_N_new = 1-0.95; // 0.985 CB 14.01.09 Hansen+Kueper BM + + // m_pcs->SetNodeValue(i, idx0, satu_N_new); // idx0 for timelevel 0 ?? + if (psg) + m_pcs->SetNodeValue(i, idx0 + 1, satu_N_new); // idx0+1 for timelevel 1 ?? + // set new SATURATION1 + // m_pcs->SetNodeValue(i, idx2, 1-satu_N_new); // idx2 for timelevel 0 ?? + m_pcs->SetNodeValue(i, idx2 + 1, 1 - satu_N_new); // idx2+1 for timelevel 1 ?? + // finally determine the new napl fluid density + if (mass * volume > 0) + rho_N_fluid = mass / volume; // [kg/m³N] = [kg/m³REV] / [m³N/m³REV] + else + rho_N_fluid = m_mfp->Density(); // use NAPL phase fluid density as defined in .mfp + // set new DENSITY2 + m_pcs->SetNodeValue(i, idx1, rho_N_fluid); + // CB PS_GLOBAL this needs update + } + else + { // gas_dissolution + // get the old SATURATION2 of NAPL after flow / transport step + if (psg) // PS_GLOBAL + satu_N_old = m_pcs->GetNodeValue(i, idx0); + else // MULTI_PHASE_FLOW only has water satu + satu_N_old + = 1.0 + - m_pcs->GetNodeValue(i, idx2 + 1); // idx2+1 as in case of Eclipse coupling, Sats are transient. + // hence the sat before KRC is available only at "new" TL + // get the old and new CO2 conc in gas phase after flow / transport step + for (j = 0; j < nNAPLcomps; j++) + { + l = pcs_napl_comps_vector[j]; + idxC = pcs_vector[l]->GetNodeValueIndex(pcs_vector[l]->pcs_primary_function_name[0]); + conc += pcs_vector[l]->GetNodeValue(i, idxC); // old timelevel + conc2 += pcs_vector[l]->GetNodeValue(i, idxC + 1); // new timelevel + } + satu_N_new = satu_N_old * (conc2 / conc); // simple scaling + if (psg) // Set new NAPL SATURATION2 + m_pcs->SetNodeValue(i, idx0 + 1, satu_N_new); + // Set new water SATURATION1 in any case + m_pcs->SetNodeValue(i, idx2 + 1, 1 - satu_N_new); + } + } + pcs_napl_comps_vector.clear(); + molar_weights_vector.clear(); + molar_densities_vector.clear(); + + // m_pcs->WriteAllVariables(); +} /************************************************************************** Task: Postprocessing function calculates the NAPL saturation after @@ -6416,476 +6631,492 @@ Task: Postprocessing function calculates the NAPL saturation after /**************************************************************************/ void CalcNewPhasePressure() { + long i; //, j=0; + double Cgo, Cgn, Clo, Cln, TT, Po, Pn, H2O, rho; + double Cgn2, Cln2; + double Vg = 0, Vl = 1; //, delta = 0; + double NumberReactions; //, scale=0; - long i;//, j=0; - double Cgo, Cgn, Clo, Cln, TT, Po, Pn, H2O, rho; - double Cgn2, Cln2; - double Vg= 0, Vl = 1;//, delta = 0; - double NumberReactions; //, scale=0; - - //int idx0=0; - int idxCg, idxCl, idxP, idxS, sp; - long nnodes; - - double poro = 0, Satu = 1; - - CRFProcess *m_pcs = NULL; - m_pcs = PCSGetFlow(); - if(m_pcs->getProcessType() != FiniteElement::MULTI_PHASE_FLOW){ - if(m_pcs->getProcessType() == FiniteElement::PS_GLOBAL) - // this is for NAPL only, for CO2 use the routine below - CalcNewNAPLSat(); - return; - } - - - // this is only for CO2 dissolution - - CRFProcess *g_pcs = NULL; - CRFProcess *l_pcs = NULL; - - idxP = m_pcs->GetNodeValueIndex("PRESSURE2") + 1; // Pnw new TL - idxS = m_pcs->GetNodeValueIndex("SATURATION1") + 1; // Sw new TL - - NumberReactions = KinReact_vector.size(); - - // Get dissolution Reaction - CKinReact *m_kr = NULL; - for (i=0; itypeflag_napldissolution) - break; - } - if(m_kr->typeflag_napldissolution!=1) - return; - - //CKinReactData *m_krd = NULL; - //m_krd = KinReactData_vector[0]; - - nnodes = (long) fem_msh_vector[0]->nod_vector.size(); - - // do the Pressure update - for(i = 0; i < nnodes; i++) { - Cgo = Cgn = Clo = Cln = TT = Po = Pn = H2O = rho = Cgn2 = Cln2 = 0; - //Get Sw - Satu = m_pcs->GetNodeValue(i, idxS); - - // Get P, T, H2O - if(REACTINT_vec.size()>0) { - Po = REACTINT_vec[0]->GetPressure(i); - TT = REACTINT_vec[0]->GetTemperature(i); - poro = REACTINT_vec[0]->node_porosity[i]; - H2O = REACTINT_vec[0]->water_conc[i] * Satu * poro; - } - - // Get concentrations - // C in NAPL / gas phase - sp = m_kr->ex_species[0]; - g_pcs = cp_vec[sp]->getProcess(); // true: new->old - idxCg = g_pcs->GetNodeValueIndex(m_kr->ex_species_names[0]) ; - Cgo = g_pcs->GetNodeValue(i, idxCg); - Cgn = g_pcs->GetNodeValue(i, idxCg+1); - - sp = m_kr->ex_species[1]; - l_pcs = cp_vec[sp]->getProcess(); - idxCl = l_pcs->GetNodeValueIndex(m_kr->ex_species_names[1]); - Clo = l_pcs->GetNodeValue(i, idxCl); - Cln = l_pcs->GetNodeValue(i, idxCl+1); - Clo *= poro * Satu; - Cln *= poro * Satu; - - //delta = fabs(fabs(Clo - Cln) - fabs(Cgo - Cgn)); - //if( delta > 1e-6) - // cout << "!!! " << Cgo << " " << Cgn << " " << Clo << " " << Cln << " " << ((Cgo - Cgn)+(Clo - Cln)) << " " << poro << " " << Satu << "\n"; - // //cout << "Warning: Wrong Mass balance at node " << i << " in CalcNewPhasePressure. dC = " << delta << "\n"; - - // P & S update - Pn = Po ; - - VLE_CalcNewPressure(TT, Pn, Vg, Vl, Cgo, Cgn, Clo, Cln, H2O, H2O, rho); - Pn *= 1.0e+5; // bar --> Pa - m_pcs->SetNodeValue(i, idxP, Pn); - - Vl *= 1e-6/poro; - Vg *= 1e-6/poro; - Satu = 1-Vg /(Vg+Vl); - m_pcs->SetNodeValue(i, idxS, Satu); - - // as pressure and vol have changed, density and thus gas conc. is different now - Cgn2 = rho*1000*poro*(1-Satu)/(44.009/1000); - g_pcs->SetNodeValue(i, idxCg+1, Cgn2); - // put the residual to water phase - Cln2 = (Cln /*+ (Cgn-Cgn2)*/) / (poro*Satu); - l_pcs->SetNodeValue(i, idxCl+1, Cln2); - } + // int idx0=0; + int idxCg, idxCl, idxP, idxS, sp; + long nnodes; -} + double poro = 0, Satu = 1; + + CRFProcess* m_pcs = NULL; + m_pcs = PCSGetFlow(); + if (m_pcs->getProcessType() != FiniteElement::MULTI_PHASE_FLOW) + { + if (m_pcs->getProcessType() == FiniteElement::PS_GLOBAL) + // this is for NAPL only, for CO2 use the routine below + CalcNewNAPLSat(); + return; + } + + // this is only for CO2 dissolution + + CRFProcess* g_pcs = NULL; + CRFProcess* l_pcs = NULL; + + idxP = m_pcs->GetNodeValueIndex("PRESSURE2") + 1; // Pnw new TL + idxS = m_pcs->GetNodeValueIndex("SATURATION1") + 1; // Sw new TL + + NumberReactions = KinReact_vector.size(); + // Get dissolution Reaction + CKinReact* m_kr = NULL; + for (i = 0; i < NumberReactions; i++) + { + m_kr = KinReact_vector[i]; + if (m_kr->typeflag_napldissolution) + break; + } + if (m_kr->typeflag_napldissolution != 1) + return; + + // CKinReactData *m_krd = NULL; + // m_krd = KinReactData_vector[0]; + + nnodes = (long)fem_msh_vector[0]->nod_vector.size(); + // do the Pressure update + for (i = 0; i < nnodes; i++) + { + Cgo = Cgn = Clo = Cln = TT = Po = Pn = H2O = rho = Cgn2 = Cln2 = 0; + // Get Sw + Satu = m_pcs->GetNodeValue(i, idxS); + + // Get P, T, H2O + if (REACTINT_vec.size() > 0) + { + Po = REACTINT_vec[0]->GetPressure(i); + TT = REACTINT_vec[0]->GetTemperature(i); + poro = REACTINT_vec[0]->node_porosity[i]; + H2O = REACTINT_vec[0]->water_conc[i] * Satu * poro; + } + // Get concentrations + // C in NAPL / gas phase + sp = m_kr->ex_species[0]; + g_pcs = cp_vec[sp]->getProcess(); // true: new->old + idxCg = g_pcs->GetNodeValueIndex(m_kr->ex_species_names[0]); + Cgo = g_pcs->GetNodeValue(i, idxCg); + Cgn = g_pcs->GetNodeValue(i, idxCg + 1); + + sp = m_kr->ex_species[1]; + l_pcs = cp_vec[sp]->getProcess(); + idxCl = l_pcs->GetNodeValueIndex(m_kr->ex_species_names[1]); + Clo = l_pcs->GetNodeValue(i, idxCl); + Cln = l_pcs->GetNodeValue(i, idxCl + 1); + Clo *= poro * Satu; + Cln *= poro * Satu; + + // delta = fabs(fabs(Clo - Cln) - fabs(Cgo - Cgn)); + // if( delta > 1e-6) + // cout << "!!! " << Cgo << " " << Cgn << " " << Clo << " " << Cln << " " << ((Cgo - Cgn)+(Clo - Cln)) << " " + // << poro << " " << Satu << "\n"; + // //cout << "Warning: Wrong Mass balance at node " << i << " in CalcNewPhasePressure. dC = " << delta << "\n"; + + // P & S update + Pn = Po; + + VLE_CalcNewPressure(TT, Pn, Vg, Vl, Cgo, Cgn, Clo, Cln, H2O, H2O, rho); + Pn *= 1.0e+5; // bar --> Pa + m_pcs->SetNodeValue(i, idxP, Pn); + + Vl *= 1e-6 / poro; + Vg *= 1e-6 / poro; + Satu = 1 - Vg / (Vg + Vl); + m_pcs->SetNodeValue(i, idxS, Satu); + + // as pressure and vol have changed, density and thus gas conc. is different now + Cgn2 = rho * 1000 * poro * (1 - Satu) / (44.009 / 1000); + g_pcs->SetNodeValue(i, idxCg + 1, Cgn2); + // put the residual to water phase + Cln2 = (Cln /*+ (Cgn-Cgn2)*/) / (poro * Satu); + l_pcs->SetNodeValue(i, idxCl + 1, Cln2); + } +} /**************************************************************************/ -//Task: Calculates the NAPL mass flux across Model boundary +// Task: Calculates the NAPL mass flux across Model boundary // in case of NAPL infiltration -//Programing: +// Programing: // 01/2008 CB Implementation /**************************************************************************/ void CalcNAPLCompMasses() { - long i, j, k, l; - int idxC, idx, idxS; - long nnodes, nelenodes, nNAPLcomps, nDisscomps; - double conc=0; - double sat=0; - double maxconc = 0; - double mass, volume; - ofstream _dump; - double time ; - int no_processes; - const double * coord; - - double xmax = 0; - double ymax = 0; - double ymin = 1e9; - double area; - - long idxVx;//, idxVy, idxVz; - //double vel_nod[3]; - double vel_nod; - - vectorpcs_napl_comps_vector; - vectorconc_napl_comps_vector; - vectorpcs_comps_vector; - vectorconc_comps_vector; - vectormf_vector; - - MeshLib::CNode* m_nod = NULL; - MeshLib::CElem* m_ele = NULL; - CFEMesh* m_msh = NULL; - m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt - - string var_name; - CRFProcess *m_pcs = NULL; - CRFProcess *n_pcs = NULL; - CTimeDiscretization *m_tim = NULL; - m_tim = time_vector[0]; - time = m_tim->time_current; - - i = j = k=l = 0; - no_processes =(int)pcs_vector.size(); - nnodes = (long) fem_msh_vector[0]->nod_vector.size(); - volume = fem_msh_vector[0]->ele_vector[0]->GetVolume(); - - m_pcs = PCSGetFlow(); - // get the indices of velocity of flow process - idxVx = m_pcs->GetNodeValueIndex("VELOCITY_X1"); - //idxVy = m_pcs->GetNodeValueIndex("VELOCITY_Y1"); - //idxVz = m_pcs->GetNodeValueIndex("VELOCITY_Z1"); - idxS = m_pcs->GetNodeValueIndex("SATURATION1")+1; // new timelevel - - bool mpf = false; - if (m_pcs->getProcessType() == FiniteElement::MULTI_PHASE_FLOW) - mpf = true; - - - // prepare indices and data size structures - for(i=0;ipcs_type_name.compare("MASS_TRANSPORT")==0) - if(n_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) - { - j = n_pcs->GetProcessComponentNumber(); - if(cp_vec[j]->transport_phase==3){ // is in napl - pcs_napl_comps_vector.push_back(i); // store processes that are NAPL dissolution components - conc_napl_comps_vector.push_back(0); // get the corresponding molar weight - l++; - } - else if(cp_vec[j]->transport_phase==0){ - pcs_comps_vector.push_back(i); - conc_comps_vector.push_back(0); - mf_vector.push_back(0); - k++; - } - } - } - nNAPLcomps = l; - nDisscomps = k; - - // integrate NAPL masses - for(j = 0; j < nNAPLcomps; j++) { - conc = mass = 0; - l=pcs_napl_comps_vector[j]; - idxC = pcs_vector[l]->GetNodeValueIndex(pcs_vector[l]->pcs_primary_function_name[0]) + 1; // new timelevel - for(i = 0; i < nnodes; i++) { - conc = pcs_vector[l]->GetNodeValue(i, idxC); - sat = m_pcs->GetNodeValue(i, idxS); // should be napl sat - if(mpf) // in case of MULTI_PHASE_FLOW, it is water sat - sat = 1-sat; - if(sat>1e-3) - mass += conc *volume; - } - conc_napl_comps_vector[j]=mass; - } - - // get downgrad model boundary x coordinate - for(i = 0; i < nnodes; i++) { - m_nod = m_msh->nod_vector[i]; - coord = m_nod->getData(); - if(coord[0]>xmax) - xmax = coord[0]; - } - - // get ele flux area - m_ele = m_msh->ele_vector[0]; - area = m_ele->GetFluxArea(); - nelenodes = m_ele->GetNodesNumber(false); - for(j = 0; j < nelenodes; j++){ - idx = m_ele->GetNodeIndex(j); - m_nod = m_msh->nod_vector[idx]; - coord = m_nod->getData(); - if(coord[2]>ymax) - ymax = coord[2]; - if(coord[3]GetNodeValueIndex(pcs_vector[l]->pcs_primary_function_name[0]); - for(i = 0; i < nnodes; i++) { - conc = pcs_vector[l]->GetNodeValue(i, idxC);// new timelevel - if(conc>maxconc) - maxconc = conc ; - } - conc_comps_vector[j]=maxconc; - } - - //Mass flux across model boundary - for(j = 0; j < nDisscomps; j++) { - mass = conc = 0; - for(i = 0; i < nnodes; i++) { - m_nod = m_msh->nod_vector[i]; - coord=m_nod->getData(); - if(coord[0]==xmax){ - // Get the velocity components - vel_nod = m_pcs->GetNodeValue(i, idxVx); - //vel_nod[1] = m_pcs->GetNodeValue(i, idxVy); - //vel_nod[2] = m_pcs->GetNodeValue(i, idxVz); - // Get the concentration - l=pcs_comps_vector[j]; - idxC = 1+pcs_vector[l]->GetNodeValueIndex(pcs_vector[l]->pcs_primary_function_name[0]); - conc = pcs_vector[l]->GetNodeValue(i, idxC);// new timelevel - // mass flux - mass += conc * vel_nod; - } - } - mf_vector[j]=mass*area; - } - - // output to Tecfile - ifstream in; - string file; - file = FileName + "_Masses_.tec"; - _dump.setf(ios::scientific,ios::floatfield); - _dump.precision(12); - if (m_tim->step_current==1){ - _dump.open(file.c_str(),ios::out); - //header - _dump << "TITLE = \"Masses and concentrations over time\" " << "\n"; - _dump << "VARIABLES = \"TIME [a]\",\"TIME [s]\"" ; - for(j = 0; j < nNAPLcomps; j++) { - l=pcs_napl_comps_vector[j]; - _dump << "\"" << pcs_vector[l]->pcs_primary_function_name[0] << "\"," ; - } - for(j = 0; j < nDisscomps; j++) { - l=pcs_comps_vector[j]; - _dump << "\"" << pcs_vector[l]->pcs_primary_function_name[0] << "\"," ; - } - for(j = 0; j < nDisscomps; j++) { - l=pcs_comps_vector[j]; - _dump << "\"" << pcs_vector[l]->pcs_primary_function_name[0] << "_mf\"," ; - } - _dump << "\n"<< flush; - _dump << "ZONE T=\"Source Zone\"" << "\n"; - } - else - _dump.open(file.c_str(),ios::app); - //data - _dump << time/86400/365 << " " << time << " "; - for(j = 0; j < nNAPLcomps; j++) - _dump << conc_napl_comps_vector[j] << " " ; - for(j = 0; j < nDisscomps; j++) - _dump << conc_comps_vector[j] << " " ; - for(j = 0; j < nDisscomps; j++) - _dump << mf_vector[j] << " " ; - _dump << "\n"; - _dump.close(); - - // clear vectors - pcs_napl_comps_vector.clear(); - conc_napl_comps_vector.clear(); - pcs_comps_vector.clear(); - conc_comps_vector.clear(); - mf_vector.clear(); -} + long i, j, k, l; + int idxC, idx, idxS; + long nnodes, nelenodes, nNAPLcomps, nDisscomps; + double conc = 0; + double sat = 0; + double maxconc = 0; + double mass, volume; + ofstream _dump; + double time; + int no_processes; + const double* coord; + + double xmax = 0; + double ymax = 0; + double ymin = 1e9; + double area; + + long idxVx; //, idxVy, idxVz; + // double vel_nod[3]; + double vel_nod; + + vector pcs_napl_comps_vector; + vector conc_napl_comps_vector; + vector pcs_comps_vector; + vector conc_comps_vector; + vector mf_vector; + + MeshLib::CNode* m_nod = NULL; + MeshLib::CElem* m_ele = NULL; + CFEMesh* m_msh = NULL; + m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt + + string var_name; + CRFProcess* m_pcs = NULL; + CRFProcess* n_pcs = NULL; + CTimeDiscretization* m_tim = NULL; + m_tim = time_vector[0]; + time = m_tim->time_current; + i = j = k = l = 0; + no_processes = (int)pcs_vector.size(); + nnodes = (long)fem_msh_vector[0]->nod_vector.size(); + volume = fem_msh_vector[0]->ele_vector[0]->GetVolume(); -/**************************************************************************/ -//Task: Calculates the NAPL density for a node -// in case of NAPL dissolution -//Programing: -// 01/2008 CB Implementation -/**************************************************************************/ -double CalcNAPLDens(int node) -{ - long i, j, k, l; - int idxC; // idx1 - int nNAPLcomps; - double conc, rho_N_new, mass, volume; - string var_name; - - vectorpcs_napl_comps_vector; - vectormolar_weights_vector; - vectormolar_densities_vector; - - int no_processes=(int)pcs_vector.size(); - CRFProcess *m_pcs = NULL; - CRFProcess *n_pcs = NULL; - CFluidProperties* m_mfp = NULL; - - - m_pcs = PCSGetFlow(); - - m_mfp = mfp_vector[m_pcs->pcs_type_number+1]; // CB ToDo: check, if this also applies for MULTI_PHASE_FLOW - //m_mfp = mfp_vector[m_pcs->pcs_type_number]; - //m_mfp->mode = 1; // CB ?? - - i = j = k = l = 0; - - //collect parameters and concentrations for NAPL-components - for(i=0;ipcs_type_name.compare("MASS_TRANSPORT")==0) - if(n_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) - { - j = n_pcs->GetProcessComponentNumber(); - if(cp_vec[j]->transport_phase==3){ // is in NAPL component - pcs_napl_comps_vector.push_back(i); // store processes that are NAPL dissolution components - molar_weights_vector.push_back(cp_vec[j]->molar_weight); // get the corresponding molar weight - molar_densities_vector.push_back(cp_vec[j]->molar_density); // get the corresponding densities - l++; - } - } - } - nNAPLcomps = l; - - // determine the NAPL density rho_N_neu at current node - conc = rho_N_new = mass = volume = 0; - for(j = 0; j < nNAPLcomps; j++) { - l=pcs_napl_comps_vector[j]; - idxC = pcs_vector[l]->GetNodeValueIndex(pcs_vector[l]->pcs_primary_function_name[0]); - conc = pcs_vector[l]->GetNodeValue(node, idxC); - if(fabs(conc)<1e-19) - conc = 0.0; - mass += conc * molar_weights_vector[j]; // [kg/m³REV] = [molN/m³REV] * [kg/molN] - volume += conc / molar_densities_vector[j]; // [m³N/m³REV] = [molN/m³REV] / [molN/m³REV] - } - if(mass * volume > 0) - rho_N_new = mass / volume; // [kg/m³N] = [kg/m³REV] / [m³N/m³REV] - else - rho_N_new = m_mfp->Density(); // use NAPL phase fluid density as defined in .mfp - // This may be not possible if new spatially distributed density model will be implemented.. - // What to do in case of no NAPL? Set a default density? - - pcs_napl_comps_vector.clear(); - molar_weights_vector.clear(); - molar_densities_vector.clear(); - - return rho_N_new; -} + m_pcs = PCSGetFlow(); + // get the indices of velocity of flow process + idxVx = m_pcs->GetNodeValueIndex("VELOCITY_X1"); + // idxVy = m_pcs->GetNodeValueIndex("VELOCITY_Y1"); + // idxVz = m_pcs->GetNodeValueIndex("VELOCITY_Z1"); + idxS = m_pcs->GetNodeValueIndex("SATURATION1") + 1; // new timelevel -/************************************************************************** - Reaction-Method: - Task: returns the Porevelocity of the mobile (water) phase in case of a NAPL - dissolution model and TwoPhaseFlow; v at the node as a inverse distance - weighted mean of the connecting elements velocities - Programing: - 08/2008 CB Implementation - 10/2010 TF changed access to process type - 09/2011 TF changed access to coordinates of mesh node, - - substituted access to mesh_element from pointer to direct access into the vector - - made the mesh node a const pointer - - made the pointer to the mesh const, made the mesh itself const - - substituted pow(x,2) by x*x - - reduced scope of some loop variables -**************************************************************************/ -double CKinReact::GetNodePoreVelocity(long node_number) -{ - CRFProcess* pcs(PCSGetFlow()); - //CFEMesh const* const msh(fem_msh_vector[0]); //SB: ToDo hart gesetzt - - //long group; - //long el, elem; - long idxVx, idxVy, idxVz, idxs1; - double vel_nod[3]; //, coord[3], vel_ele[3]; - //double distance, sum_w, weight; - //double* grav_c; - double PoreVel(0), poro(0), satu = 1.0; // default - double theta = pcs->m_num->ls_theta; + bool mpf = false; + if (m_pcs->getProcessType() == FiniteElement::MULTI_PHASE_FLOW) + mpf = true; - // Get node saturation of mobile (water) phase - if (pcs->getProcessType () == FiniteElement::PS_GLOBAL) - { - idxs1 = pcs->GetNodeValueIndex("SATURATION1"); // Sat of water phase - satu = pcs->GetNodeValue(node_number, idxs1); - } - else if (pcs->getProcessType () == FiniteElement::MULTI_PHASE_FLOW) - { - idxs1 = pcs->GetNodeValueIndex("SATURATION1"); // Sat of water phase - satu = pcs->GetNodeValue(node_number, idxs1); - } - else if (pcs->getProcessType() == FiniteElement::TWO_PHASE_FLOW) + // prepare indices and data size structures + for (i = 0; i < no_processes; i++) { - if (pcs->pcs_type_number == 0) - // this is the saturation equation - pcs = pcs_vector[pcs->pcs_number + 1]; - // Sat of water phase - idxs1 = pcs->GetNodeValueIndex("SATURATION1"); - satu = pcs->GetNodeValue(node_number, idxs1); + n_pcs = pcs_vector[i]; + // if(n_pcs->pcs_type_name.compare("MASS_TRANSPORT")==0) + if (n_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) + { + j = n_pcs->GetProcessComponentNumber(); + if (cp_vec[j]->transport_phase == 3) + { // is in napl + pcs_napl_comps_vector.push_back(i); // store processes that are NAPL dissolution components + conc_napl_comps_vector.push_back(0); // get the corresponding molar weight + l++; + } + else if (cp_vec[j]->transport_phase == 0) + { + pcs_comps_vector.push_back(i); + conc_comps_vector.push_back(0); + mf_vector.push_back(0); + k++; + } + } } - else if (pcs->getProcessType() == FiniteElement::RICHARDS_FLOW) + nNAPLcomps = l; + nDisscomps = k; + + // integrate NAPL masses + for (j = 0; j < nNAPLcomps; j++) { - // Sat of water phase + conc = mass = 0; + l = pcs_napl_comps_vector[j]; + idxC = pcs_vector[l]->GetNodeValueIndex(pcs_vector[l]->pcs_primary_function_name[0]) + 1; // new timelevel + for (i = 0; i < nnodes; i++) + { + conc = pcs_vector[l]->GetNodeValue(i, idxC); + sat = m_pcs->GetNodeValue(i, idxS); // should be napl sat + if (mpf) // in case of MULTI_PHASE_FLOW, it is water sat + sat = 1 - sat; + if (sat > 1e-3) + mass += conc * volume; + } + conc_napl_comps_vector[j] = mass; + } + + // get downgrad model boundary x coordinate + for (i = 0; i < nnodes; i++) + { + m_nod = m_msh->nod_vector[i]; + coord = m_nod->getData(); + if (coord[0] > xmax) + xmax = coord[0]; + } + + // get ele flux area + m_ele = m_msh->ele_vector[0]; + area = m_ele->GetFluxArea(); + nelenodes = m_ele->GetNodesNumber(false); + for (j = 0; j < nelenodes; j++) + { + idx = m_ele->GetNodeIndex(j); + m_nod = m_msh->nod_vector[idx]; + coord = m_nod->getData(); + if (coord[2] > ymax) + ymax = coord[2]; + if (coord[3] < ymin) + ymin = coord[2]; + } + area *= (ymax - ymin); + + // maximum C + for (j = 0; j < nDisscomps; j++) + { + conc = maxconc = 0; + l = pcs_comps_vector[j]; + idxC = 1 + pcs_vector[l]->GetNodeValueIndex(pcs_vector[l]->pcs_primary_function_name[0]); + for (i = 0; i < nnodes; i++) + { + conc = pcs_vector[l]->GetNodeValue(i, idxC); // new timelevel + if (conc > maxconc) + maxconc = conc; + } + conc_comps_vector[j] = maxconc; + } + + // Mass flux across model boundary + for (j = 0; j < nDisscomps; j++) + { + mass = conc = 0; + for (i = 0; i < nnodes; i++) + { + m_nod = m_msh->nod_vector[i]; + coord = m_nod->getData(); + if (coord[0] == xmax) + { + // Get the velocity components + vel_nod = m_pcs->GetNodeValue(i, idxVx); + // vel_nod[1] = m_pcs->GetNodeValue(i, idxVy); + // vel_nod[2] = m_pcs->GetNodeValue(i, idxVz); + // Get the concentration + l = pcs_comps_vector[j]; + idxC = 1 + pcs_vector[l]->GetNodeValueIndex(pcs_vector[l]->pcs_primary_function_name[0]); + conc = pcs_vector[l]->GetNodeValue(i, idxC); // new timelevel + // mass flux + mass += conc * vel_nod; + } + } + mf_vector[j] = mass * area; + } + + // output to Tecfile + ifstream in; + string file; + file = FileName + "_Masses_.tec"; + _dump.setf(ios::scientific, ios::floatfield); + _dump.precision(12); + if (m_tim->step_current == 1) + { + _dump.open(file.c_str(), ios::out); + // header + _dump << "TITLE = \"Masses and concentrations over time\" " + << "\n"; + _dump << "VARIABLES = \"TIME [a]\",\"TIME [s]\""; + for (j = 0; j < nNAPLcomps; j++) + { + l = pcs_napl_comps_vector[j]; + _dump << "\"" << pcs_vector[l]->pcs_primary_function_name[0] << "\","; + } + for (j = 0; j < nDisscomps; j++) + { + l = pcs_comps_vector[j]; + _dump << "\"" << pcs_vector[l]->pcs_primary_function_name[0] << "\","; + } + for (j = 0; j < nDisscomps; j++) + { + l = pcs_comps_vector[j]; + _dump << "\"" << pcs_vector[l]->pcs_primary_function_name[0] << "_mf\","; + } + _dump << "\n" << flush; + _dump << "ZONE T=\"Source Zone\"" + << "\n"; + } + else + _dump.open(file.c_str(), ios::app); + // data + _dump << time / 86400 / 365 << " " << time << " "; + for (j = 0; j < nNAPLcomps; j++) + _dump << conc_napl_comps_vector[j] << " "; + for (j = 0; j < nDisscomps; j++) + _dump << conc_comps_vector[j] << " "; + for (j = 0; j < nDisscomps; j++) + _dump << mf_vector[j] << " "; + _dump << "\n"; + _dump.close(); + + // clear vectors + pcs_napl_comps_vector.clear(); + conc_napl_comps_vector.clear(); + pcs_comps_vector.clear(); + conc_comps_vector.clear(); + mf_vector.clear(); +} + +/**************************************************************************/ +// Task: Calculates the NAPL density for a node +// in case of NAPL dissolution +// Programing: +// 01/2008 CB Implementation +/**************************************************************************/ +double CalcNAPLDens(int node) +{ + long i, j, k, l; + int idxC; // idx1 + int nNAPLcomps; + double conc, rho_N_new, mass, volume; + string var_name; + + vector pcs_napl_comps_vector; + vector molar_weights_vector; + vector molar_densities_vector; + + int no_processes = (int)pcs_vector.size(); + CRFProcess* m_pcs = NULL; + CRFProcess* n_pcs = NULL; + CFluidProperties* m_mfp = NULL; + + m_pcs = PCSGetFlow(); + + m_mfp = mfp_vector[m_pcs->pcs_type_number + 1]; // CB ToDo: check, if this also applies for MULTI_PHASE_FLOW + // m_mfp = mfp_vector[m_pcs->pcs_type_number]; + // m_mfp->mode = 1; // CB ?? + + i = j = k = l = 0; + + // collect parameters and concentrations for NAPL-components + for (i = 0; i < no_processes; i++) + { + n_pcs = pcs_vector[i]; + // if(n_pcs->pcs_type_name.compare("MASS_TRANSPORT")==0) + if (n_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) + { + j = n_pcs->GetProcessComponentNumber(); + if (cp_vec[j]->transport_phase == 3) + { // is in NAPL component + pcs_napl_comps_vector.push_back(i); // store processes that are NAPL dissolution components + molar_weights_vector.push_back(cp_vec[j]->molar_weight); // get the corresponding molar weight + molar_densities_vector.push_back(cp_vec[j]->molar_density); // get the corresponding densities + l++; + } + } + } + nNAPLcomps = l; + + // determine the NAPL density rho_N_neu at current node + conc = rho_N_new = mass = volume = 0; + for (j = 0; j < nNAPLcomps; j++) + { + l = pcs_napl_comps_vector[j]; + idxC = pcs_vector[l]->GetNodeValueIndex(pcs_vector[l]->pcs_primary_function_name[0]); + conc = pcs_vector[l]->GetNodeValue(node, idxC); + if (fabs(conc) < 1e-19) + conc = 0.0; + mass += conc * molar_weights_vector[j]; // [kg/m³REV] = [molN/m³REV] * [kg/molN] + volume += conc / molar_densities_vector[j]; // [m³N/m³REV] = [molN/m³REV] / [molN/m³REV] + } + if (mass * volume > 0) + rho_N_new = mass / volume; // [kg/m³N] = [kg/m³REV] / [m³N/m³REV] + else + rho_N_new = m_mfp->Density(); // use NAPL phase fluid density as defined in .mfp + // This may be not possible if new spatially distributed density model will be implemented.. + // What to do in case of no NAPL? Set a default density? + + pcs_napl_comps_vector.clear(); + molar_weights_vector.clear(); + molar_densities_vector.clear(); + + return rho_N_new; +} + +/************************************************************************** + Reaction-Method: + Task: returns the Porevelocity of the mobile (water) phase in case of a NAPL + dissolution model and TwoPhaseFlow; v at the node as a inverse distance + weighted mean of the connecting elements velocities + Programing: + 08/2008 CB Implementation + 10/2010 TF changed access to process type + 09/2011 TF changed access to coordinates of mesh node, + - substituted access to mesh_element from pointer to direct access into the vector + - made the mesh node a const pointer + - made the pointer to the mesh const, made the mesh itself const + - substituted pow(x,2) by x*x + - reduced scope of some loop variables +**************************************************************************/ +double CKinReact::GetNodePoreVelocity(long node_number) +{ + CRFProcess* pcs(PCSGetFlow()); + // CFEMesh const* const msh(fem_msh_vector[0]); //SB: ToDo hart gesetzt + + // long group; + // long el, elem; + long idxVx, idxVy, idxVz, idxs1; + double vel_nod[3]; //, coord[3], vel_ele[3]; + // double distance, sum_w, weight; + // double* grav_c; + double PoreVel(0), poro(0), satu = 1.0; // default + double theta = pcs->m_num->ls_theta; + + // Get node saturation of mobile (water) phase + if (pcs->getProcessType() == FiniteElement::PS_GLOBAL) + { + idxs1 = pcs->GetNodeValueIndex("SATURATION1"); // Sat of water phase + satu = pcs->GetNodeValue(node_number, idxs1); + } + else if (pcs->getProcessType() == FiniteElement::MULTI_PHASE_FLOW) + { + idxs1 = pcs->GetNodeValueIndex("SATURATION1"); // Sat of water phase + satu = pcs->GetNodeValue(node_number, idxs1); + } + else if (pcs->getProcessType() == FiniteElement::TWO_PHASE_FLOW) + { + if (pcs->pcs_type_number == 0) + // this is the saturation equation + pcs = pcs_vector[pcs->pcs_number + 1]; + // Sat of water phase + idxs1 = pcs->GetNodeValueIndex("SATURATION1"); + satu = pcs->GetNodeValue(node_number, idxs1); + } + else if (pcs->getProcessType() == FiniteElement::RICHARDS_FLOW) + { + // Sat of water phase idxs1 = pcs->GetNodeValueIndex("SATURATION1"); satu = pcs->GetNodeValue(node_number, idxs1); } - // Get the porosity as average from neighbouring elements from - poro = GetPhaseVolumeAtNode(node_number, theta, 0); - - // initialize data structures - for(int i=0;i<3;i++) - vel_nod[i]=0; - PoreVel = 0; - - // get the indices of velocity of flow process - idxVx = pcs->GetNodeValueIndex("VELOCITY_X1"); - idxVy = pcs->GetNodeValueIndex("VELOCITY_Y1"); - idxVz = pcs->GetNodeValueIndex("VELOCITY_Z1"); - // Get the velocity components - vel_nod[0] = pcs->GetNodeValue(node_number, idxVx); - vel_nod[1] = pcs->GetNodeValue(node_number, idxVy); - vel_nod[2] = pcs->GetNodeValue(node_number, idxVz); - // absolute value of velocity vector - for(int i=0;i<3;i++) - PoreVel += pow(vel_nod[i],2); - PoreVel = sqrt(PoreVel); - //divide by porosity and saturation to obtain transport velocity - PoreVel /= (poro * satu); + // Get the porosity as average from neighbouring elements from + poro = GetPhaseVolumeAtNode(node_number, theta, 0); + + // initialize data structures + for (int i = 0; i < 3; i++) + vel_nod[i] = 0; + PoreVel = 0; + + // get the indices of velocity of flow process + idxVx = pcs->GetNodeValueIndex("VELOCITY_X1"); + idxVy = pcs->GetNodeValueIndex("VELOCITY_Y1"); + idxVz = pcs->GetNodeValueIndex("VELOCITY_Z1"); + // Get the velocity components + vel_nod[0] = pcs->GetNodeValue(node_number, idxVx); + vel_nod[1] = pcs->GetNodeValue(node_number, idxVy); + vel_nod[2] = pcs->GetNodeValue(node_number, idxVz); + // absolute value of velocity vector + for (int i = 0; i < 3; i++) + PoreVel += pow(vel_nod[i], 2); + PoreVel = sqrt(PoreVel); + // divide by porosity and saturation to obtain transport velocity + PoreVel /= (poro * satu); return PoreVel; } @@ -6902,7 +7133,7 @@ double CKinReact::GetNodePoreVelocity(long node_number) **************************************************************************/ double CKinReact::GetNodeDarcyVelocity(long node) { - CRFProcess *m_pcs = NULL; + CRFProcess* m_pcs = NULL; long i; long idxVx, idxVy, idxVz; @@ -6912,8 +7143,8 @@ double CKinReact::GetNodeDarcyVelocity(long node) m_pcs = PCSGetFlow(); // initialize data structures - for(i=0;i<3;i++) - vel_nod[i]=0; + for (i = 0; i < 3; i++) + vel_nod[i] = 0; DarcyVel = 0; // get the indices of velocity of flow process @@ -6925,8 +7156,8 @@ double CKinReact::GetNodeDarcyVelocity(long node) vel_nod[1] = m_pcs->GetNodeValue(node, idxVy); vel_nod[2] = m_pcs->GetNodeValue(node, idxVz); // absolute value of velocity vector - for(i=0;i<3;i++) - DarcyVel += pow(vel_nod[i],2); + for (i = 0; i < 3; i++) + DarcyVel += pow(vel_nod[i], 2); DarcyVel = sqrt(DarcyVel); return DarcyVel; @@ -6949,29 +7180,29 @@ double CKinReact::GetNodeDarcyVelocity(long node) void CKinReactData::ReactionDeactivation(long nonodes) { long node; - int react_t = 10; // reactions are calculated at all nodes every react_t timesteps + int react_t = 10; // reactions are calculated at all nodes every react_t timesteps size_t sp; - const size_t Number_of_Components (cp_vec.size()); - if(ReactDeactRelative) - cout << " Reaction deactivation mode " << ReactDeactMode << " with relative concentration change! " << "\n"; - else - cout << " Reaction deactivation mode " << ReactDeactMode << " with absolute concentration change! " << "\n"; + const size_t Number_of_Components(cp_vec.size()); + if (ReactDeactRelative) + cout << " Reaction deactivation mode " << ReactDeactMode << " with relative concentration change! " + << "\n"; + else + cout << " Reaction deactivation mode " << ReactDeactMode << " with absolute concentration change! " + << "\n"; // reactivate all nodes every n time steps - if (((aktueller_zeitschritt) % react_t) == 0) // when evaluated before loop over nodes, i.e. prepare for this time step + if (((aktueller_zeitschritt) % react_t) + == 0) // when evaluated before loop over nodes, i.e. prepare for this time step - //if(((aktueller_zeitschritt+1) % react_t ) == 0) { // when evaluated after loop over nodes, i.e. prepare for next time step + // if(((aktueller_zeitschritt+1) % react_t ) == 0) { // when evaluated after loop over nodes, i.e. prepare for + // next time step for (node = 0; node < nonodes; node++) { ReactDeact[node] = false; - if (ReactDeactMode != 3) // for all timesteps, anyway prepare the concentrationmatrix for the next time step, i.e. save the current concentrations after Transport + if (ReactDeactMode != 3) // for all timesteps, anyway prepare the concentrationmatrix for the next time + // step, i.e. save the current concentrations after Transport for (sp = 0; sp < Number_of_Components; sp++) - concentrationmatrix[node][sp] - = cp_vec[sp]->getProcess()->GetNodeValue( - node, - sp_varind[ - sp - ]); + concentrationmatrix[node][sp] = cp_vec[sp]->getProcess()->GetNodeValue(node, sp_varind[sp]); } // CB Now check if node can be deactivated for the next time step else @@ -6985,30 +7216,26 @@ void CKinReactData::ReactionDeactivation(long nonodes) React_dCdT[node] = 0; for (sp = 0; sp < Number_of_Components; sp++) { - //This is C of last time step after reactions, i.e. the old time level for this time step - double Concentration = cp_vec[sp]->getProcess()->GetNodeValue(node, (sp_varind[sp] - 1)); - //This is C of previous time step after transport only, which was stored in matrix - double Concentration_old = concentrationmatrix[node][sp]; - // relative concentration change + // This is C of last time step after reactions, i.e. the old time level for this time step + double Concentration = cp_vec[sp]->getProcess()->GetNodeValue(node, (sp_varind[sp] - 1)); + // This is C of previous time step after transport only, which was stored in matrix + double Concentration_old = concentrationmatrix[node][sp]; + // relative concentration change double maxi = 1; - if(ReactDeactRelative) - maxi = DMAX(Concentration_old, Concentration); - if (maxi < ReactDeactCThresh) - React_dCdT[node] += 0.0; - else + if (ReactDeactRelative) + maxi = DMAX(Concentration_old, Concentration); + if (maxi < ReactDeactCThresh) + React_dCdT[node] += 0.0; + else { - React_dCdT[node] += fabs((Concentration_old - - Concentration) / - maxi) / dt; // normalized by current local concentration - // and now prepare concentrationmatrix for next time step, i.e. save current concentrations after Transport - concentrationmatrix[node][sp] - = cp_vec[sp]->getProcess()->GetNodeValue( - node, - sp_varind - [sp]); + React_dCdT[node] += fabs((Concentration_old - Concentration) / maxi) + / dt; // normalized by current local concentration + // and now prepare concentrationmatrix for next time step, i.e. save current concentrations + // after Transport + concentrationmatrix[node][sp] = cp_vec[sp]->getProcess()->GetNodeValue(node, sp_varind[sp]); } } - //cout << nod << " " << React_dCdT[nod] << "\n"; + // cout << nod << " " << React_dCdT[nod] << "\n"; } // this is the check, if a node may be deactivated for this time step @@ -7018,74 +7245,64 @@ void CKinReactData::ReactionDeactivation(long nonodes) switch (ReactDeactMode) { - case 1: // loop over no of connected nodes and their respective neighbours - for (size_t nn = 0; nn < ReactNeighborhood[node].size(); nn++) - { - int node_idx = ReactNeighborhood[node][nn]; - sumReact_dCdT += React_dCdT[node_idx]; - } - if(ReactDeactRelative) - sumReact_dCdT /= double (ReactNeighborhood[node].size()); - break; - case 2: // compare with C after transport of last timestep, loop over all components - for (sp = 0; sp < Number_of_Components; sp++) - { - //This is C of current time step after transport - double Concentration = - cp_vec[sp]->getProcess()->GetNodeValue( - node, - sp_varind[sp - ]); - //This is C of previous time step after transport only - double Concentration_old = concentrationmatrix[node][sp]; - double maxi = 1; - if(ReactDeactRelative) - maxi = DMAX(Concentration_old, Concentration); - if(maxi > ReactDeactCThresh) - sumReact_dCdT += fabs( (Concentration - Concentration_old)/maxi); - // and now prepare the concentrationmatrix for the next time step, i.e. save the current concentrations after Transport - concentrationmatrix[node][sp] = Concentration; - } - break; - case 3: // compare with C after reaction of last timestep, loop over all components - for (sp = 0; sp < Number_of_Components; sp++) - { - //This is C of current time step after transport - double Concentration = - cp_vec[sp]->getProcess()->GetNodeValue( - node, sp_varind[sp]); - //This is C of previous time step after transport & reaction - double Concentration_old = - cp_vec[sp]->getProcess()->GetNodeValue(node, - (sp_varind[ - sp] - - 1)); - double maxi = 1; - if(ReactDeactRelative) - maxi = DMAX(Concentration_old, Concentration); - if(maxi > ReactDeactCThresh) - sumReact_dCdT += fabs((Concentration - Concentration_old)/maxi); - } - break; - default: - break; + case 1: // loop over no of connected nodes and their respective neighbours + for (size_t nn = 0; nn < ReactNeighborhood[node].size(); nn++) + { + int node_idx = ReactNeighborhood[node][nn]; + sumReact_dCdT += React_dCdT[node_idx]; + } + if (ReactDeactRelative) + sumReact_dCdT /= double(ReactNeighborhood[node].size()); + break; + case 2: // compare with C after transport of last timestep, loop over all components + for (sp = 0; sp < Number_of_Components; sp++) + { + // This is C of current time step after transport + double Concentration = cp_vec[sp]->getProcess()->GetNodeValue(node, sp_varind[sp]); + // This is C of previous time step after transport only + double Concentration_old = concentrationmatrix[node][sp]; + double maxi = 1; + if (ReactDeactRelative) + maxi = DMAX(Concentration_old, Concentration); + if (maxi > ReactDeactCThresh) + sumReact_dCdT += fabs((Concentration - Concentration_old) / maxi); + // and now prepare the concentrationmatrix for the next time step, i.e. save the current + // concentrations after Transport + concentrationmatrix[node][sp] = Concentration; + } + break; + case 3: // compare with C after reaction of last timestep, loop over all components + for (sp = 0; sp < Number_of_Components; sp++) + { + // This is C of current time step after transport + double Concentration = cp_vec[sp]->getProcess()->GetNodeValue(node, sp_varind[sp]); + // This is C of previous time step after transport & reaction + double Concentration_old = cp_vec[sp]->getProcess()->GetNodeValue(node, (sp_varind[sp] - 1)); + double maxi = 1; + if (ReactDeactRelative) + maxi = DMAX(Concentration_old, Concentration); + if (maxi > ReactDeactCThresh) + sumReact_dCdT += fabs((Concentration - Concentration_old) / maxi); + } + break; + default: + break; } // check if deactivation criterion is met - if(ReactDeactRelative) - sumReact_dCdT /= double(Number_of_Components); + if (ReactDeactRelative) + sumReact_dCdT /= double(Number_of_Components); if (sumReact_dCdT < ReactDeactEpsilon) - ReactDeact[node] = true; // negligible change, deactivate the node for the next time step + ReactDeact[node] = true; // negligible change, deactivate the node for the next time step else - ReactDeact[node] = false; // sufficient change, reactivate the node for the next time step + ReactDeact[node] = false; // sufficient change, reactivate the node for the next time step } - } //else - - // Resets the reaction rates vector, only in case of model 1 - if (ReactDeactMode == 1) - for (node = 0; node < nonodes; node++) - React_dCdT[node] = 0; + } // else + // Resets the reaction rates vector, only in case of model 1 + if (ReactDeactMode == 1) + for (node = 0; node < nonodes; node++) + React_dCdT[node] = 0; } /**************************************************************************/ @@ -7104,7 +7321,7 @@ void CKinReactData::ReactDeactSetOldReactionTerms(long nonodes) { long node; int sp; - int Number_of_Components = (int) cp_vec.size(); + int Number_of_Components = (int)cp_vec.size(); double Concentration; for (node = 0; node < nonodes; node++) @@ -7113,13 +7330,9 @@ void CKinReactData::ReactDeactSetOldReactionTerms(long nonodes) for (sp = 0; sp < Number_of_Components; sp++) { // Get the C after reactions of last time step (old time level, index = 0) - Concentration = cp_vec[sp]->getProcess()->GetNodeValue( - node, - sp_varind[sp - ] - 1); + Concentration = cp_vec[sp]->getProcess()->GetNodeValue(node, sp_varind[sp] - 1); // Set this C as the new concentration after reaction - cp_vec[sp]->getProcess()->SetNodeValue(node, sp_varind[sp], - Concentration); + cp_vec[sp]->getProcess()->SetNodeValue(node, sp_varind[sp], Concentration); } } } @@ -7138,7 +7351,7 @@ void CKinReactData::ReactDeactSetOldReactionTerms(long nonodes) /**************************************************************************/ void CKinReactData::ReactDeactPlotFlagsToTec() { - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt std::string eleType; if (m_msh->getNumberOfLines() > 0) @@ -7166,12 +7379,17 @@ void CKinReactData::ReactDeactPlotFlagsToTec() const size_t nnodes(m_msh->nod_vector.size()); const size_t nele(m_msh->ele_vector.size()); - aus << "VARIABLES = " << "\"x\"" << " " << "\"y\"" << " " << "\"z\"" - << "\"active\"" << "\n"; - aus << "ZONE T=" << "\"aktueller_zeitschritt=" << aktueller_zeitschritt - << "\""; - aus << ", N=" << nnodes << ", E=" << nele << " F=FEPOINT, ET=" - << eleType << "\n"; + aus << "VARIABLES = " + << "\"x\"" + << " " + << "\"y\"" + << " " + << "\"z\"" + << "\"active\"" + << "\n"; + aus << "ZONE T=" + << "\"aktueller_zeitschritt=" << aktueller_zeitschritt << "\""; + aus << ", N=" << nnodes << ", E=" << nele << " F=FEPOINT, ET=" << eleType << "\n"; for (size_t i = 0; i < nnodes; i++) { @@ -7202,15 +7420,14 @@ void CKinReactData::ReactDeactPlotFlagsToTec() void CKinReactData::Aromaticum(long nonodes) { long node; - double conc, lambda = 0.0; //OK411 + double conc, lambda = 0.0; // OK411 // int pcsindex = 0; CRFProcess* m_pcs = NULL; int varindex = 0; - int nospec = (int) sp_varind.size(); + int nospec = (int)sp_varind.size(); for (int sp = 0; sp < nospec; sp++) - if (cp_vec[sp]->getProcess()->nod_val_name_vector[0].compare( - "Aromaticum") == 0) + if (cp_vec[sp]->getProcess()->nod_val_name_vector[0].compare("Aromaticum") == 0) { // pcsindex = sp_pcsind[sp]; m_pcs = cp_vec[sp]->getProcess(); @@ -7241,71 +7458,76 @@ void CKinReactData::Aromaticum(long nonodes) Programing: //CB 01.2011 CB First implementation **************************************************************************/ -void CKinReactData::NAPLDissolutionPreprocessing(){ - - CKinReact *m_kr = NULL; - CRFProcess *m_pcs = NULL; - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt - - int i, j, sp; // idx0, - bool mpf = false; - bool psg = false; - - // To access nodal pore velocities , these may be calculated for all nodes beforehands - for (i=0; itypeflag_napldissolution){ - m_pcs = PCSGetFlow(); - if(m_pcs->getProcessType() == FiniteElement::PS_GLOBAL) - psg = true; - else if (m_pcs->getProcessType() == FiniteElement::MULTI_PHASE_FLOW ) - mpf = true; - //if(m_pcs->pcs_type_name.compare("PS_GLOBAL")!=0) - if(!psg && !mpf) - cout << "WARNING in CKinReact::NAPLDissolutionPreprocessing: Flow process cannot be used" << "\n"; - // CB copied from Problem::PostCouplingLoop() - else if(m_pcs->cal_integration_point_value) //WW - m_pcs->Extropolation_GaussValue(); - break; // do only once - } - } - - // In case of Eclipse coupling and MULTI_PHASE_FLOW set data to old time level - for (i=0; itypeflag_napldissolution){ - // C in NAPL / gas phase - sp = m_kr->ex_species[0]; - cp_vec[sp]->getProcess()->CopyTimestepNODValues(true); // true: new->old - // saturation - m_pcs->CopyTimestepNODValues(true); - } - } - - // Switch off nodes with too low NAPL saturation - //now set up vectors switched_off_node for individual reactions - //if (psg) - // idx0 = m_pcs->GetNodeValueIndex("SATURATION2"); // old timelevel - // check all reactions - for(i=0;itypeflag_napldissolution){ - // Initialize vector if not yet done in KRConfig() - if(m_kr->NotThisReactGeoType.size()==0) - for(j=0; j< (long)m_msh->nod_vector.size();j++) - m_kr->switched_off_node.push_back(false); - // Go through all nodes - //for(j=0;j<(long)m_msh->nod_vector.size();j++){ - // if(m_pcs->GetNodeValue(j, idx0) < 1e-13) - // m_kr->switched_off_node[j] = true; - //} - } // reaction is NAPL diss - - } // loop over k nreactions +void CKinReactData::NAPLDissolutionPreprocessing() +{ + CKinReact* m_kr = NULL; + CRFProcess* m_pcs = NULL; + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt -} + int i, j, sp; // idx0, + bool mpf = false; + bool psg = false; + + // To access nodal pore velocities , these may be calculated for all nodes beforehands + for (i = 0; i < NumberReactions; i++) + { + m_kr = KinReact_vector[i]; + if (m_kr->typeflag_napldissolution) + { + m_pcs = PCSGetFlow(); + if (m_pcs->getProcessType() == FiniteElement::PS_GLOBAL) + psg = true; + else if (m_pcs->getProcessType() == FiniteElement::MULTI_PHASE_FLOW) + mpf = true; + // if(m_pcs->pcs_type_name.compare("PS_GLOBAL")!=0) + if (!psg && !mpf) + cout << "WARNING in CKinReact::NAPLDissolutionPreprocessing: Flow process cannot be used" + << "\n"; + // CB copied from Problem::PostCouplingLoop() + else if (m_pcs->cal_integration_point_value) // WW + m_pcs->Extropolation_GaussValue(); + break; // do only once + } + } + + // In case of Eclipse coupling and MULTI_PHASE_FLOW set data to old time level + for (i = 0; i < NumberReactions; i++) + { + m_kr = KinReact_vector[i]; + if (m_kr->typeflag_napldissolution) + { + // C in NAPL / gas phase + sp = m_kr->ex_species[0]; + cp_vec[sp]->getProcess()->CopyTimestepNODValues(true); // true: new->old + // saturation + m_pcs->CopyTimestepNODValues(true); + } + } + + // Switch off nodes with too low NAPL saturation + // now set up vectors switched_off_node for individual reactions + // if (psg) + // idx0 = m_pcs->GetNodeValueIndex("SATURATION2"); // old timelevel + // check all reactions + for (i = 0; i < NumberReactions; i++) + { + m_kr = KinReact_vector[i]; + + if (m_kr->typeflag_napldissolution) + { + // Initialize vector if not yet done in KRConfig() + if (m_kr->NotThisReactGeoType.size() == 0) + for (j = 0; j < (long)m_msh->nod_vector.size(); j++) + m_kr->switched_off_node.push_back(false); + // Go through all nodes + // for(j=0;j<(long)m_msh->nod_vector.size();j++){ + // if(m_pcs->GetNodeValue(j, idx0) < 1e-13) + // m_kr->switched_off_node[j] = true; + //} + } // reaction is NAPL diss + } // loop over k nreactions +} /************************************************************************** Reaction-Method: @@ -7316,37 +7538,38 @@ void CKinReactData::NAPLDissolutionPreprocessing(){ Programing: //CB 01.2011 CB First implementation **************************************************************************/ -void CKinReactData::PreprocessMicrobe_drmc_(double steplength){ - - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt - MicrobeData* m_md = NULL; - - double theta, G, S; - int i, j; - - for(i=0;inod_vector.size();j++) { - // here, get the gibbs energy for the reaction at beginning of time step - G = m_md->GetGibbsEnergy(j); - m_md->Gibbs[j] = G; - theta = 1/(exp((m_md->G0-G)/(m_md->steepness*m_md->G0))+1); - if(theta>1.0) - theta=1.0; - // variable dt is updated only after the first time step and is initialized with zero before - // the first time step, update of S in the first time step hence is Snew = Sold * exp(0) - // this is an analytical approximtion of dS/dt = [kincr*theta*(1-theta_s)-kdecr*(1-theta)] * S - S = m_md->_drmc_level[j] * exp((m_md->k_incr*theta*(1-theta) - m_md->k_decr*(1-theta))*m_md->dt); - if(S>1.0) S=1.0; - m_md->_drmc_level[j] = S; - } - // store time step length for next time step update - m_md->dt = steplength; - - } +void CKinReactData::PreprocessMicrobe_drmc_(double steplength) +{ + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt + MicrobeData* m_md = NULL; -} + double theta, G, S; + int i, j; + for (i = 0; i < NumberMicrobeData; i++) + { + m_md = MicrobeData_vector[i]; + for (j = 0; j < (long)m_msh->nod_vector.size(); j++) + { + // here, get the gibbs energy for the reaction at beginning of time step + G = m_md->GetGibbsEnergy(j); + m_md->Gibbs[j] = G; + theta = 1 / (exp((m_md->G0 - G) / (m_md->steepness * m_md->G0)) + 1); + if (theta > 1.0) + theta = 1.0; + // variable dt is updated only after the first time step and is initialized with zero before + // the first time step, update of S in the first time step hence is Snew = Sold * exp(0) + // this is an analytical approximtion of dS/dt = [kincr*theta*(1-theta_s)-kdecr*(1-theta)] * S + S = m_md->_drmc_level[j] + * exp((m_md->k_incr * theta * (1 - theta) - m_md->k_decr * (1 - theta)) * m_md->dt); + if (S > 1.0) + S = 1.0; + m_md->_drmc_level[j] = S; + } + // store time step length for next time step update + m_md->dt = steplength; + } +} /************************************************************************** Reaction-Method: @@ -7358,820 +7581,938 @@ void CKinReactData::PreprocessMicrobe_drmc_(double steplength){ Programing: //CB 01.2011 CB First implementation **************************************************************************/ -void CKinReactData::PreprocessMinKin(){ - - - int i, j, k=0, nnode=0, ncomp, widx=0;//node, - double val, conc, A0, poro; - //double fact; - double A=0, B=0, a0, I, Imin, Imax, dens; - double T = 298.15; - double TC; - double phi, MV, epsi; - bool warning = false; - double unitfactor_l = 1; - - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt - CKinReact *m_kr = NULL; - nnode = (long) m_msh->nod_vector.size(); - ncomp = (int)cp_vec.size(); - //CB merge CAP 0311 - #ifdef OGS_FEM_CAP // CAP_REACT - REACT_CAP *m_cap; - #endif - - - REACTINT *m_rei = NULL; - if(REACTINT_vec.size()>0) - m_rei = REACTINT_vec[0]; - -//CB merge CAP 0311 - // get ChemApp data structure - if(activity_model==3){ +void CKinReactData::PreprocessMinKin() +{ + int i, j, k = 0, nnode = 0, ncomp, widx = 0; // node, + double val, conc, A0, poro; + // double fact; + double A = 0, B = 0, a0, I, Imin, Imax, dens; + double T = 298.15; + double TC; + double phi, MV, epsi; + bool warning = false; + double unitfactor_l = 1; + + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt + CKinReact* m_kr = NULL; + nnode = (long)m_msh->nod_vector.size(); + ncomp = (int)cp_vec.size(); +// CB merge CAP 0311 #ifdef OGS_FEM_CAP // CAP_REACT - if(REACT_CAP_vec.size()>0) m_cap = REACT_CAP_vec[0]; -#else - cout << " Warning: in PreprocessMinKin: Activity model = 3, but CAP is not defined. " << "\n"; + REACT_CAP* m_cap; #endif - } - else{ - for (i=0; itypeflag_mineralkinetics && m_kr->Km_uniform == false){ + + REACTINT* m_rei = NULL; + if (REACTINT_vec.size() > 0) + m_rei = REACTINT_vec[0]; + + // CB merge CAP 0311 + // get ChemApp data structure + if (activity_model == 3) + { #ifdef OGS_FEM_CAP // CAP_REACT - m_cap = REACT_CAP_vec[0]; - break; + if (REACT_CAP_vec.size() > 0) + m_cap = REACT_CAP_vec[0]; #else - cout << " Warning: in PreprocessMinKin: Km is not uniform, but CAP is not defined. " << "\n"; + cout << " Warning: in PreprocessMinKin: Activity model = 3, but CAP is not defined. " + << "\n"; #endif - } - } - } - - // get water index - for (i=0; itypeflag_mineralkinetics ){ - widx = m_kr->water_number; - break; - } - } - - - if(activity_model==1 || activity_model==2){ - // first calculate ionic strength at each node - // I = 0.5SUM(z_i^2 * Moles_i / MassWater) = 0.5SUM(z_i^2 * C_i) - Imin=1000; - Imax = 0; - for (j=0;j molality - if(m_rei) { - if(m_rei->unitconversion) - unitfactor_l = MOLH2OPERKG / m_rei->water_conc[j] ; - } - - for (i=0;ivalence;// Valenz; - // Attention: next conc should be molality [mol/kg_h2o], so miltiply with conversion factor - conc = cp_vec[i]->getProcess()->GetNodeValue(j,sp_varind[i]) * unitfactor_l; - //conc = pcs_vector[sp_pcsind[i]]->GetNodeValue(j,sp_varind[i]) * unitfactor_l; // CB HS update - if(cp_vec[i]->compname.compare("pH")==0) - conc = pow(10, -conc * unitfactor_l); // this is inacurate as it should be molality of H+, not the activity. - IonicStrengths[j] += 0.5*val*val*conc; - } - // store min and max I in model domain - if(Imin>IonicStrengths[j]) - Imin = IonicStrengths[j]; - if(Imax0.1) - DisplayMsgLn("Warning in CKinReactData::PreprocessMinkin(): I > 0.1 --> use of DH activity model is not recomended!"); - break; - case 2: /* Davies*/ - if(Imin<0.1) - DisplayMsgLn("Warning in CKinReactData::PreprocessMinkin(): I < 0.1 --> use of Davies activity model is not recomended!"); - break; - case 3: /* CHEMAPP*/ - break; - default: - DisplayMsgLn("Unknown activity model in CKinReactData::PreprocessMinkin()!"); - break; - } - - // then calculate T dependent parameters A & B, from Groundwater Geochemistry, Broder Merkel - // Todo: get T - TC = T-273.15; - dens = 1-(TC-3.9863)*(TC-3.9863)*(TC+288.9414)/508929.2/(TC+68.12963) + 0.011445*exp(-374.3/TC); - epsi = 2727.586 + 0.6224107*T - 466.9151*log(T) - 52000.87/T; - A = 1.82483e6 * pow(dens,0.5) * pow(epsi*T, -1.5); - B = 50.2916* pow(dens,0.5)*pow(epsi*T, -0.5); - } - - // now calculate activity coefficients for all species at all nodes - switch (activity_model) { - - case 0: /* constant activity = 1*/ - // do nothing - break; - case 1: /* DH*/ - for (j=0;jtransport_phase==0){ - val = double(cp_vec[j]->valence);// Valenz; - a0 = cp_vec[j]->a_zero; // a0; - for (i=0;i0){ - if(fabs(val)>0) // charged species - ActivityCoefficients[i][j] = pow(10, -A*val*val*sqrt(I)/(1+B*a0*sqrt(I))); - else{ // uncharged species - if(j==widx) - ActivityCoefficients[i][j] = 1; // set water activity to 1 - else - ActivityCoefficients[i][j] = pow(10, 0.1*I); // as in PHREEQC, manual, p 157 - } - } - else{ - ActivityCoefficients[i][j]=1; - if(i==0 && j==0) cout << "Warning in KinReactData: zero Ionic strength in PreprocessMinKin; using gamma = 1.0" << "\n"; - } - } - } - } - break; - case 2: /* DAVIS*/ - for (j=0;jtransport_phase==0){ - val = double(cp_vec[j]->valence);// Valenz; - for (i=0;i0){ - if(fabs(val)>0) // charged species - ActivityCoefficients[i][j] = pow(10, -A*val*val* ( sqrt(I)/(1+sqrt(I)) -0.3*I) ); - else{ // uncharged species - if(j==widx) - ActivityCoefficients[i][j] = 1; // set water activity to 1 - else - ActivityCoefficients[i][j] = pow(10, 0.1*I); // as in PHREEQC, manual, p 157 - } - } - else{ - ActivityCoefficients[i][j]=1; - if(i==0 && j==0) cout << "Warning in KinReactData: zero Ionic strength in PreprocessMinKin; using gamma = 1.0" << "\n"; - } - } - } - } - break; - case 3: /* CHEMAPP*/ + } + else + { + for (i = 0; i < NumberReactions; i++) + { + m_kr = KinReact_vector[i]; + if (m_kr->typeflag_mineralkinetics && m_kr->Km_uniform == false) + { #ifdef OGS_FEM_CAP // CAP_REACT - for (j=0;j0){ - for(k=0;kmass_num;k++){ // Attention, m_cap->mass_num can be less than ncomp - if(cp_vec[j]->compname.compare(m_cap->species_name[k])==0) - break; - } //CB merge CAP 0311 - } //CB merge CAP 0311 - for (i=0;iGetNodeValue(i,sp_varind[j]); - conc=cp_vec[j]->getProcess()->GetNodeValue(i,sp_varind[j]); - if(cp_vec[j]->compname.compare("pH")==0) - conc = pow(10, -conc); // this is inacurate as it should be molality of H+, not the activity. - // finally, get activity from vector node_ac and divide by conc to get gamma - if(REACT_CAP_vec.size()>0) - if(m_cap->node_ac[i].size()>0){ //CB merge CAP 0311 - if ( /*conc>0 && */ k < m_cap->mass_num) - ActivityCoefficients[i][j] = m_cap->node_ac[i][k] /*/ conc*/ ; - else - ActivityCoefficients[i][j] = 1.0; - } - else{ //CB merge CAP 0311 - ActivityCoefficients[i][j] = 1.0; - if(j==0 && is_a_CCBC[i]==false){ - cout << " Warning in CKinReactData::PreprocessMinKin():" << "\n"; - cout << " No Chemapp-activity coefficient data available for node " << i << "\n"; - } - } //CB merge CAP 0311 - } - } -#else - cout << " Warning: in PreprocessMinKin: Km is not uniform, but CAP is not defined. " << "\n"; -#endif - break; - default: - DisplayMsgLn("Unknown activity model in CKinReactData::PreprocessMinkin()!"); - break; - } /* switch */ - - - // Set K_m as function of P and T in vector m_kr->Km[node]; get data from ChemApp - for (i=0; itypeflag_mineralkinetics && m_kr->Km_uniform == false){ -#ifdef OGS_FEM_CAP // CAP_REACT //CB merge CAP 0311 - if(m_kr->Km_CHEMAPP==true){ // find the matching CAP Kinetic reaction - for(j=0;jKin_Reactions.size());j++){ - if(m_kr->chemapp_name.compare(m_cap->Kin_Reactions[j].type)==0){ // found - for (k=0;knode_logK[k].size()>0) - m_kr->Km[k] = pow(10, -m_cap->node_logK[k][j]); - else if(is_a_CCBC[k]==false){ // what, if no data has been calculated by chemapp?? - cout << " Warning in CKinReactData::PreprocessMinkin:" << "\n"; - cout << " No Chemapp-log(K) data available for reaction " << m_kr->chemapp_name ; - cout << " at node "<< k << "\n"; - if(k>0) m_kr->Km[k] = m_kr->Km[k-1]; // use neighbour node value - else m_kr->Km[k] = m_kr->Km_default; // use default input value - } - } - break; - } - } - } - else if(m_kr->Km_HKF==true){ // find the matching HKF Kinetic reaction - for(j=0;jKin_HKF_Reactions.size());j++){ - if(m_kr->chemapp_name.compare(m_cap->Kin_HKF_Reactions[j].type)==0){ // found - for (k=0;knode_HKF_logK[k].size()>0) - m_kr->Km[k] = pow(10, m_cap->node_HKF_logK[k][j]); - else if(is_a_CCBC[k]==false){ // what, if no data has been calculated by chemapp?? - cout << " Warning in CKinReactData::PreprocessMinkin:" << "\n"; - cout << " No HKF-log(K) data available for reaction " << m_kr->chemapp_name ; - cout << " at node "<< k << "\n"; - if(k>0) m_kr->Km[k] = m_kr->Km[k-1]; // use neighbour node value - else m_kr->Km[k] = m_kr->Km_default; // use default input value - } - } - break; - } - } - } + m_cap = REACT_CAP_vec[0]; + break; #else - cout << " Warning: in PreprocessMinKin: Km is not uniform, but CAP is not defined. " << "\n"; + cout << " Warning: in PreprocessMinKin: Km is not uniform, but CAP is not defined. " + << "\n"; #endif - } - } //CB merge CAP 0311 - - // set mineral reactive surface areas - // they are updated each time step by the remaing mass fraction C(t)/C0 - // before first zime step, prepare Am/C0, this is done just once at the beginning of simulation - if(aktueller_zeitschritt == 1){ - for (i=0; itypeflag_mineralkinetics && m_kr->Am_constant == false){ - for (k=0;kmineral_number]]->GetNodeValue(k,sp_varind[m_kr->mineral_number]); // CB HS update - conc = cp_vec[m_kr->mineral_number]->getProcess()->GetNodeValue(k,sp_varind[m_kr->mineral_number]); - switch (m_kr->Am_model) { - case 1: - // A0/C0 to multiply with C(t) before each time step - A0 = m_kr->Am[0]; // save area - if(conc>0) - m_kr->Am[k] = A0 / conc; - break; - case 2: - // store thi initial mineral concentration for surface updating in postprocessing - m_kr->Cminini.push_back(conc); - break; - case 3: - // do nothing - break; - case 4: - // do nothing - break; - case 5: - // do nothing - break; - default: - // do nothing - break; - } - - } - } - } - } - - // here, update each time step by the remaing mass fraction C(t)/C0 - for (i=0; itypeflag_mineralkinetics && m_kr->Am_constant == false){ - MV = cp_vec[m_kr->mineral_number]->molar_weight / cp_vec[m_kr->mineral_number]->mineral_density; - - for (k=0;kmineral_number]]->GetNodeValue(k,sp_varind[m_kr->mineral_number]); // CB HS update - conc = cp_vec[m_kr->mineral_number]->getProcess()->GetNodeValue(k,sp_varind[m_kr->mineral_number]); - - phi = 0; - - switch (m_kr->Am_model) { - case 1: - if(conc>0) - m_kr->Am[k] *= conc; - if(m_kr->Am[k] < 1e-6){ - m_kr->Am[k] = 1e-6; //minimum allowed surface area to allow regrowth of a mineral - warning = true; - //node = k; - } - break; - case 2: - // do nothing here, update is done in preprocessing function - break; - case 3: - // do nothing here, update is done in preprocessing function - break; - case 4: - // do nothing here, update is done in preprocessing function - break; - case 5: - // SA is proportional to mineral volume fraction - if(conc>0){ - if(REACTINT_vec.size()>0) - poro = REACTINT_vec[0]->node_porosity[k]; - else - poro = m_kr->GetPhaseVolumeAtNode(k, 1, 0); // no poro update when RACINT does not exist - phi = conc * MV * (1-poro); - } - phi = DMAX(1e-7, phi); // guarantee a minimum surface area - //else phi = 1e-6; - m_kr->Am[k] = phi * m_kr->Am_ini * cp_vec[m_kr->mineral_number]->molar_weight / MV; - break; - default: - // do nothing here, update is done in preprocessing function - break; - } - - } - } - } - if(warning) cout << " Warning: A mineral concentration is 0.0 at node " << k << "\n" << " --> setting surface area to minimum of 1e-8." << "\n"; - - - CTimeDiscretization *m_tim = NULL; - m_tim = time_vector[0]; - int steps = int(m_tim->time_step_vector.size()); - bool plot = false; - if(aktueller_zeitschritt == 1 || aktueller_zeitschritt % 10 == 0 || steps == int(aktueller_zeitschritt)) - plot = true; - - - // debug output - if(debugoutflag && activity_model>0 && plot == true){ - c_dumpfilename = FileName + "_Activities.dump"; - c_dump.setf(ios::scientific,ios::floatfield); - c_dump.precision(12); - c_dump.open(c_dumpfilename.c_str()); - //header - c_dump << "Node IonicStrength " ; - for (i=0;icompname << " " ; - c_dump << "\n"; - //data - for(int j = 0; j < nnode; j++){ - c_dump << j << " " << IonicStrengths[j] << " " ; - for (i=0;iNumberReactions;i++) { - m_kr = KinReact_vector[i]; - if(m_kr->typeflag_mineralkinetics!=0) - c_dump << m_kr->getName() << " " ; - } - c_dump << "\n"; - //data - for(int j = 0; j < nnode; j++){ - c_dump << j << " "; - for (i=0;iNumberReactions;i++) { - m_kr = KinReact_vector[i]; - if(m_kr->typeflag_mineralkinetics!=0){ - if (m_kr->Km_uniform==false) - c_dump << m_kr->Km[j] << " " ; - else - c_dump << m_kr->Km[0] << " " ; - } - } - c_dump << "\n" << flush; - } - c_dump.close(); - } - - return; -} - -/************************************************************************** - Reaction-Method: - Task: This function updates mineral reactive surface areas after reactions - Programing: - //CB 01.2011 CB First implementation - **************************************************************************/ -void CKinReactData::PostprocessMinKin(){ - - int i, k, nnode; - double conc0 = 0; - double phi0, phi1, n0, n1, conc1, mv; - bool outflag = false; - - phi0 = phi1 = n0 = n1 = conc0 = mv = 0; - - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt - nnode = (long) m_msh->nod_vector.size(); - CKinReact *m_kr = NULL; - - // update or reset mineral reactive surface areas for next time step - for (i=0; itypeflag_mineralkinetics && m_kr->Am_constant == false){ - outflag = true; - for (k=0;kmineral_number]]->GetNodeValue(k,sp_varind[m_kr->mineral_number]-1); - //conc1 = pcs_vector[sp_pcsind[m_kr->mineral_number]]->GetNodeValue(k,sp_varind[m_kr->mineral_number]); - conc0 = cp_vec[m_kr->mineral_number]->getProcess()->GetNodeValue(k,sp_varind[m_kr->mineral_number]-1); - conc1 = cp_vec[m_kr->mineral_number]->getProcess()->GetNodeValue(k,sp_varind[m_kr->mineral_number]); - // CB HS update - - switch (m_kr->Am_model) { - case 1: // restore A0/C0 from A0*C(t)/C0 by division with C(t) after transport - if(conc0>0) - m_kr->Am[k] /= conc0; - else - m_kr->Am[k] = 1e-6; // minimum allowed surface area to allow regrowth of a mineral - break; - case 2: // for primary minerals, volume fraction weighted - if(REACTINT_vec.size()>0){ - n0 = REACTINT_vec[0]->node_ini_porosity[k]; // here plug in n_ini at node - n1 = REACTINT_vec[0]->node_porosity[k]; - } - else - n0 = n1 = m_kr->GetPhaseVolumeAtNode(k, 1, 0); // no poro update when RACINT does not exist - if(conc0>conc1){ // dissolution - mv = cp_vec[m_kr->mineral_number]->molar_weight / cp_vec[m_kr->mineral_number]->mineral_density ; - phi0 = m_kr->Cminini[k] * (1-n0) * mv; - phi1 = conc1 * (1-n1) * mv; - } - else // precipitation - phi0 = phi1 = 1; - m_kr->Am[k] = m_kr->Am_ini * pow( (phi1/phi0*n1/n0) , 0.66667); - break; - case 3: // for secondary minerals, only poro fraction weighted - if(REACTINT_vec.size()>0){ - n0 = REACTINT_vec[0]->node_porosity[k]; // here plug in n_ini at node - n1 = REACTINT_vec[0]->node_porosity[k]; - } - else - n0 = n1 = m_kr->GetPhaseVolumeAtNode(k, 1, 0); // no poro update when RACINT does not exist - if(conc0>conc1){ // dissolution - mv = cp_vec[m_kr->mineral_number]->molar_weight / cp_vec[m_kr->mineral_number]->mineral_density ; - phi1 = conc1 * (1-n1) * mv; - } - else // precipitation - phi1 = 1; - m_kr->Am[k] = m_kr->Am_ini * pow(phi1*n1/n0 , 0.66667); - break; - case 4: // for secondary minerals, specific Area dissolution model - if(REACTINT_vec.size()>0){ - n0 = REACTINT_vec[0]->node_ini_porosity[k]; // here plug in n_ini at node - n1 = REACTINT_vec[0]->node_porosity[k]; - } - else - n0 = n1 = m_kr->GetPhaseVolumeAtNode(k, 1, 0); // no poro update when RACINT does not exist - if(conc0>conc1){ // dissolution - mv = cp_vec[m_kr->mineral_number]->molar_weight / cp_vec[m_kr->mineral_number]->mineral_density ; - phi1 = conc1 * (1-n1) * mv; - m_kr->Am[k] = m_kr->Am_ini * phi1 * cp_vec[m_kr->mineral_number]->molar_weight / mv; - } - else { // precipitation as model 3 - phi1 = 1; - m_kr->Am[k] = m_kr->Am_ini * pow(phi1*n1/n0 , 0.66667); - } - break; - case 5: - // do nothing - break; - default: - // do nothing - break; - } - - } - } - } - - - CTimeDiscretization *m_tim = NULL; - m_tim = time_vector[0]; - int steps = int(m_tim->time_step_vector.size()); - bool plot = false; - if(aktueller_zeitschritt == 1 || aktueller_zeitschritt % 10 == 0 || steps == int(aktueller_zeitschritt)) - plot = true; - - - // debug output - if(debugoutflag && outflag && plot){ - ofstream aus; - string file= FileName + "_reactivesurfaceareas.dump"; - aus.setf(ios::scientific,ios::floatfield); - aus.precision(12); - aus.open(file.c_str()); - - for(i=0;itypeflag_mineralkinetics && m_kr->Am_constant == false) - aus << m_kr->mineral_name << " " ; - } - aus << "\n"; - } - aus << i << " " ; - // data - for (int j=0; jtypeflag_mineralkinetics && m_kr->Am_constant == false) - aus << m_kr->Am[i] << " "; - } - aus << "\n"; - } - aus.close(); - } - - return; -} - - -/************************************************************************** - Reaction-Method: - Task: This function calculates the IAP/Kequi term of the Lasaga rate law - Programing: - //CB 01.2011 CB First implementation - **************************************************************************/ -double CKinReact::Omega(double *c, int node){ - - //if(node == 68) - // cout << node ; - int i, idx; - double omega=1; - double K_pt = 0; - double conc = 0; - double unitfactor_l = 1; - - CKinReactData *m_krd = NULL; - m_krd = KinReactData_vector[0]; - - if(REACTINT_vec.size()>0){ - REACTINT *m_rei = NULL; - m_rei = REACTINT_vec[0]; - if(m_rei->unitconversion) - unitfactor_l = MOLH2OPERKG / m_rei->water_conc[node] ; - } - // get K equi at given P and T - if (Km_uniform==true) - K_pt = Km[0]; // KR variable - else if (Km_uniform==false) - K_pt = Km[node]; // KR variable - - // ion activity product - // -ProductionStoch[idx] is exponent in IAP; sign must be changed here - // negative, because the kinetic reaction is formulated for precipitation - // --> removal of dissolved species from solution --> negative StoechCoeff, - // but they are positive in IAP for educts of a mineral - for(i=0;iactivity_model>0) // in case of water, this contains the activity directly - omega *= pow( m_krd->ActivityCoefficients[node][idx], -ProductionStoch[idx]); - else - omega /= 1 ; - } - else{ - //if(reactionpartner[i].compare("pH")!=0){ - if(m_krd->activity_model>0) - omega *= pow( m_krd->ActivityCoefficients[node][idx] * conc * unitfactor_l, -ProductionStoch[idx]); - else - omega *= pow( 1 * conc * unitfactor_l, -ProductionStoch[idx]); - //} - //else // pH is -log(gamma*H+) - // omega *= pow( exp(-conc), -ProductionStoch[idx]); - } - } - // divide by equilibrium constant - if (number_reactionpartner==0) - omega = 0; - else - omega/=K_pt; - return omega; -} - - -/************************************************************************** - Reaction-Method: - Task: This function calculates the mineral dissolution / precipitation - rate as a function of the rate constant Ktot, the surface area - and the IAP - Programing: - //CB 01.2011 CB First implementation - **************************************************************************/ -double CKinReact::MinRate(double *c, int node, double dt, double Om){ - - double rate = 0, maxrate = 0; - double ktot = 0, conc = 0, poro1=1, poro2=1; - double /*Om,*/ H1, H2, Betrag, vol, A=0; - int i=0; - - // get Surface Area - if (Am_constant) - A = Am[0]; - else - A = Am[node]; - - // IAP - //Om = Omega(c, node); - H1 = pow(Om,Theta); - //DMIN(H1, 11.0); - // total rate - if(H1<1 && c[mineral_number+1]<=1.1e-7) // undersaturated, but no mineral present, no dissolution - rate = 0; - else{ // supersat.-->precip, or undersat. & mineral present - H2 = fabs(1-H1); - if(H2MinKinRateCoeff; - else - ktot = -MinRateConstant(c, node, (1-H1)); // default negative rate: dissolution of mineral - // sign function:, positive rate for supersat, and slow it down by precipfactor (defaulfactor = 1) - if((1-H1)<=0) - rate = -1.0*precipfactor*ktot*A/vol; // precipfactor used to slow down precipitation by constant factor - else - rate = ktot*A/vol; - //some modification for Lagneau Benchmark probably required here - - //Lagneau Benchmark - //bool lagneau = false; - if(lagneau) rate = -1.0*A*vol*ktot/vol; - //if(node==1) cout << " Attention: Lagneau-Benchmark with modified mineral rate"; - - // in case of strong supersaturation, reduce precipitation rate by root function - if((1-H1)<=-1.0) - rate *= pow(Betrag, 1/precipexponent); - else - rate *= Betrag; - } - } - - // limit rates to the present amount of mineral and dissolved species to avoid overshoot - if(scale_rate && rate != 0){ - maxrate = rate; - poro1 = GetReferenceVolume(mineral_number,node); // mineral (solid phase volume) - if(rate<0){ // dissolution - //only limited by left hand side reaction equation species, i.e. Stcoef>0 or mineral itself - for(i=0;i0 || i==mineral_number){ - conc = DMAX(0,c[i+1]); // do not evaluate negative conc - if(mineral_number==i) // this is the mineral - maxrate = -conc / dt; // max amount that can be dissolved - else if(ProductionStoch[i]>0){ // this is other species consumed by dissolution, Stcoef > 0 - poro2 = GetReferenceVolume(i,node); // dissolved phase volume - maxrate = -conc / dt * poro2 / poro1 / ProductionStoch[i]; - } - // update maxrate,the larger, the more negative, so find maximum here - rate = DMAX(rate,maxrate); - } - } - } - else if (rate>0){ // precipitation, not limited by mineral concentration - for(i=0;i0 or mineral itself - // for(i=0;i0){ // this is other species consumed by dissolution, Stcoef > 0 - // poro2 = GetReferenceVolume(minSpeciesIdx[i],node); // dissolved phase volume - // maxrate = -conc / dt * poro2 / poro1 / ProductionStoch[minSpeciesIdx[i]]; - // } - // // update maxrate,the larger, the more negative, so find maximum here - // rate = DMAX(rate,maxrate); - // } - // } - // else if (rate>0){ // precipitation, not limited by mineral concentration - // for(i=0;i0 && rate<1e-30) rate=0; - if(rate<0 && rate>-1e-30) rate=0; - return rate; - //return rate/double(KinReactData_vector[0]->NumberMineralkinetics); -} - -/************************************************************************** - Reaction-Method: - Task: This function resturns the mineral disoolution / precipitation - rate constant as a sum over all reaction mechanisms - Ktot = Sum(Mech) - Programing: - //CB 01.2011 CB First implementation - **************************************************************************/ -double CKinReact::MinRateConstant(double *c, int node, double disso){ - - int i; - double ktot = 0; - - // calc the rate constant - for(i=0;ino_mechSpec==0) - ktot += mechvec[i]->Mech(c, node); - } - else{ // consider all mechanisms - ktot += mechvec[i]->Mech(c, node); - } - } - - return ktot; -} - + } + } + } + // get water index + for (i = 0; i < NumberReactions; i++) + { + m_kr = KinReact_vector[i]; + if (m_kr->typeflag_mineralkinetics) + { + widx = m_kr->water_number; + break; + } + } + if (activity_model == 1 || activity_model == 2) + { + // first calculate ionic strength at each node + // I = 0.5SUM(z_i^2 * Moles_i / MassWater) = 0.5SUM(z_i^2 * C_i) + Imin = 1000; + Imax = 0; + for (j = 0; j < nnode; j++) + { + IonicStrengths[j] = 0; + // get the unit conversion factor: mol/m³l --> molality + if (m_rei) + { + if (m_rei->unitconversion) + unitfactor_l = MOLH2OPERKG / m_rei->water_conc[j]; + } + for (i = 0; i < ncomp; i++) + { + val = cp_vec[i]->valence; // Valenz; + // Attention: next conc should be molality [mol/kg_h2o], so miltiply with conversion factor + conc = cp_vec[i]->getProcess()->GetNodeValue(j, sp_varind[i]) * unitfactor_l; + // conc = pcs_vector[sp_pcsind[i]]->GetNodeValue(j,sp_varind[i]) * unitfactor_l; // CB HS update + if (cp_vec[i]->compname.compare("pH") == 0) + conc = pow( + 10, + -conc * unitfactor_l); // this is inacurate as it should be molality of H+, not the activity. + IonicStrengths[j] += 0.5 * val * val * conc; + } + // store min and max I in model domain + if (Imin > IonicStrengths[j]) + Imin = IonicStrengths[j]; + if (Imax < IonicStrengths[j]) + Imax = IonicStrengths[j]; + } // nnodes + // check activity model vs. min / max ionic strength + switch (activity_model) + { + case 0: /* constant activity = 1*/ + break; + case 1: /* DH*/ + if (Imax > 0.1) + DisplayMsgLn( + "Warning in CKinReactData::PreprocessMinkin(): I > 0.1 --> use of DH activity model is not " + "recomended!"); + break; + case 2: /* Davies*/ + if (Imin < 0.1) + DisplayMsgLn( + "Warning in CKinReactData::PreprocessMinkin(): I < 0.1 --> use of Davies activity model is not " + "recomended!"); + break; + case 3: /* CHEMAPP*/ + break; + default: + DisplayMsgLn("Unknown activity model in CKinReactData::PreprocessMinkin()!"); + break; + } + // then calculate T dependent parameters A & B, from Groundwater Geochemistry, Broder Merkel + // Todo: get T + TC = T - 273.15; + dens = 1 - (TC - 3.9863) * (TC - 3.9863) * (TC + 288.9414) / 508929.2 / (TC + 68.12963) + + 0.011445 * exp(-374.3 / TC); + epsi = 2727.586 + 0.6224107 * T - 466.9151 * log(T) - 52000.87 / T; + A = 1.82483e6 * pow(dens, 0.5) * pow(epsi * T, -1.5); + B = 50.2916 * pow(dens, 0.5) * pow(epsi * T, -0.5); + } -/**************************************************************************/ -// Functions for class MinKinMech -/**************************************************************************/ + // now calculate activity coefficients for all species at all nodes + switch (activity_model) + { + case 0: /* constant activity = 1*/ + // do nothing + break; + case 1: /* DH*/ + for (j = 0; j < ncomp; j++) + { + if (cp_vec[j]->transport_phase == 0) + { + val = double(cp_vec[j]->valence); // Valenz; + a0 = cp_vec[j]->a_zero; // a0; + for (i = 0; i < nnode; i++) + { + I = IonicStrengths[i]; + if (I > 0) + { + if (fabs(val) > 0) // charged species + ActivityCoefficients[i][j] = pow(10, -A * val * val * sqrt(I) / (1 + B * a0 * sqrt(I))); + else + { // uncharged species + if (j == widx) + ActivityCoefficients[i][j] = 1; // set water activity to 1 + else + ActivityCoefficients[i][j] = pow(10, 0.1 * I); // as in PHREEQC, manual, p 157 + } + } + else + { + ActivityCoefficients[i][j] = 1; + if (i == 0 && j == 0) + cout << "Warning in KinReactData: zero Ionic strength in PreprocessMinKin; using gamma " + "= 1.0" + << "\n"; + } + } + } + } + break; + case 2: /* DAVIS*/ + for (j = 0; j < ncomp; j++) + { + if (cp_vec[j]->transport_phase == 0) + { + val = double(cp_vec[j]->valence); // Valenz; + for (i = 0; i < nnode; i++) + { + I = IonicStrengths[i]; + if (I > 0) + { + if (fabs(val) > 0) // charged species + ActivityCoefficients[i][j] + = pow(10, -A * val * val * (sqrt(I) / (1 + sqrt(I)) - 0.3 * I)); + else + { // uncharged species + if (j == widx) + ActivityCoefficients[i][j] = 1; // set water activity to 1 + else + ActivityCoefficients[i][j] = pow(10, 0.1 * I); // as in PHREEQC, manual, p 157 + } + } + else + { + ActivityCoefficients[i][j] = 1; + if (i == 0 && j == 0) + cout << "Warning in KinReactData: zero Ionic strength in PreprocessMinKin; using gamma " + "= 1.0" + << "\n"; + } + } + } + } + break; + case 3: /* CHEMAPP*/ +#ifdef OGS_FEM_CAP // CAP_REACT + for (j = 0; j < ncomp; j++) + { // CB merge CAP 0311 + // first, find the matching CAP species idx k + if (REACT_CAP_vec.size() > 0) + { + for (k = 0; k < m_cap->mass_num; k++) + { // Attention, m_cap->mass_num can be less than ncomp + if (cp_vec[j]->compname.compare(m_cap->species_name[k]) == 0) + break; + } // CB merge CAP 0311 + } // CB merge CAP 0311 + for (i = 0; i < nnode; i++) + { + // Chemapp now returns activity coefficients gamma instead of activities. + + // then, get the concentration of species j at node i + // Attention: next conc should be molality [mol/kg_h2o] + // conc=pcs_vector[sp_pcsind[j]]->GetNodeValue(i,sp_varind[j]); + conc = cp_vec[j]->getProcess()->GetNodeValue(i, sp_varind[j]); + if (cp_vec[j]->compname.compare("pH") == 0) + conc = pow(10, -conc); // this is inacurate as it should be molality of H+, not the activity. + // finally, get activity from vector node_ac and divide by conc to get gamma + if (REACT_CAP_vec.size() > 0) + if (m_cap->node_ac[i].size() > 0) + { // CB merge CAP 0311 + if (/*conc>0 && */ k < m_cap->mass_num) + ActivityCoefficients[i][j] = m_cap->node_ac[i][k] /*/ conc*/; + else + ActivityCoefficients[i][j] = 1.0; + } + else + { // CB merge CAP 0311 + ActivityCoefficients[i][j] = 1.0; + if (j == 0 && is_a_CCBC[i] == false) + { + cout << " Warning in CKinReactData::PreprocessMinKin():" + << "\n"; + cout << " No Chemapp-activity coefficient data available for node " << i << "\n"; + } + } // CB merge CAP 0311 + } + } +#else + cout << " Warning: in PreprocessMinKin: Km is not uniform, but CAP is not defined. " + << "\n"; +#endif + break; + default: + DisplayMsgLn("Unknown activity model in CKinReactData::PreprocessMinkin()!"); + break; + } /* switch */ + + // Set K_m as function of P and T in vector m_kr->Km[node]; get data from ChemApp + for (i = 0; i < NumberReactions; i++) + { + m_kr = KinReact_vector[i]; + if (m_kr->typeflag_mineralkinetics && m_kr->Km_uniform == false) + { +#ifdef OGS_FEM_CAP // CAP_REACT //CB merge CAP 0311 + if (m_kr->Km_CHEMAPP == true) + { // find the matching CAP Kinetic reaction + for (j = 0; j < int(m_cap->Kin_Reactions.size()); j++) + { + if (m_kr->chemapp_name.compare(m_cap->Kin_Reactions[j].type) == 0) + { // found + for (k = 0; k < nnode; k++) + { + if (m_cap->node_logK[k].size() > 0) + m_kr->Km[k] = pow(10, -m_cap->node_logK[k][j]); + else if (is_a_CCBC[k] == false) + { // what, if no data has been calculated by chemapp?? + cout << " Warning in CKinReactData::PreprocessMinkin:" + << "\n"; + cout << " No Chemapp-log(K) data available for reaction " << m_kr->chemapp_name; + cout << " at node " << k << "\n"; + if (k > 0) + m_kr->Km[k] = m_kr->Km[k - 1]; // use neighbour node value + else + m_kr->Km[k] = m_kr->Km_default; // use default input value + } + } + break; + } + } + } + else if (m_kr->Km_HKF == true) + { // find the matching HKF Kinetic reaction + for (j = 0; j < int(m_cap->Kin_HKF_Reactions.size()); j++) + { + if (m_kr->chemapp_name.compare(m_cap->Kin_HKF_Reactions[j].type) == 0) + { // found + for (k = 0; k < nnode; k++) + { + if (m_cap->node_HKF_logK[k].size() > 0) + m_kr->Km[k] = pow(10, m_cap->node_HKF_logK[k][j]); + else if (is_a_CCBC[k] == false) + { // what, if no data has been calculated by chemapp?? + cout << " Warning in CKinReactData::PreprocessMinkin:" + << "\n"; + cout << " No HKF-log(K) data available for reaction " << m_kr->chemapp_name; + cout << " at node " << k << "\n"; + if (k > 0) + m_kr->Km[k] = m_kr->Km[k - 1]; // use neighbour node value + else + m_kr->Km[k] = m_kr->Km_default; // use default input value + } + } + break; + } + } + } +#else + cout << " Warning: in PreprocessMinKin: Km is not uniform, but CAP is not defined. " + << "\n"; +#endif + } + } // CB merge CAP 0311 + + // set mineral reactive surface areas + // they are updated each time step by the remaing mass fraction C(t)/C0 + // before first zime step, prepare Am/C0, this is done just once at the beginning of simulation + if (aktueller_zeitschritt == 1) + { + for (i = 0; i < NumberReactions; i++) + { + m_kr = KinReact_vector[i]; + + if (m_kr->typeflag_mineralkinetics && m_kr->Am_constant == false) + { + for (k = 0; k < nnode; k++) + { + // conc = + // pcs_vector[sp_pcsind[m_kr->mineral_number]]->GetNodeValue(k,sp_varind[m_kr->mineral_number]); // + // CB HS update + conc = cp_vec[m_kr->mineral_number]->getProcess()->GetNodeValue(k, sp_varind[m_kr->mineral_number]); + switch (m_kr->Am_model) + { + case 1: + // A0/C0 to multiply with C(t) before each time step + A0 = m_kr->Am[0]; // save area + if (conc > 0) + m_kr->Am[k] = A0 / conc; + break; + case 2: + // store thi initial mineral concentration for surface updating in postprocessing + m_kr->Cminini.push_back(conc); + break; + case 3: + // do nothing + break; + case 4: + // do nothing + break; + case 5: + // do nothing + break; + default: + // do nothing + break; + } + } + } + } + } + + // here, update each time step by the remaing mass fraction C(t)/C0 + for (i = 0; i < NumberReactions; i++) + { + m_kr = KinReact_vector[i]; + if (m_kr->typeflag_mineralkinetics && m_kr->Am_constant == false) + { + MV = cp_vec[m_kr->mineral_number]->molar_weight / cp_vec[m_kr->mineral_number]->mineral_density; + + for (k = 0; k < nnode; k++) + { + // A0/C0 here is multiplied with C(t) before current time step + // conc = pcs_vector[sp_pcsind[m_kr->mineral_number]]->GetNodeValue(k,sp_varind[m_kr->mineral_number]); + // // CB HS update + conc = cp_vec[m_kr->mineral_number]->getProcess()->GetNodeValue(k, sp_varind[m_kr->mineral_number]); + + phi = 0; + + switch (m_kr->Am_model) + { + case 1: + if (conc > 0) + m_kr->Am[k] *= conc; + if (m_kr->Am[k] < 1e-6) + { + m_kr->Am[k] = 1e-6; // minimum allowed surface area to allow regrowth of a mineral + warning = true; + // node = k; + } + break; + case 2: + // do nothing here, update is done in preprocessing function + break; + case 3: + // do nothing here, update is done in preprocessing function + break; + case 4: + // do nothing here, update is done in preprocessing function + break; + case 5: + // SA is proportional to mineral volume fraction + if (conc > 0) + { + if (REACTINT_vec.size() > 0) + poro = REACTINT_vec[0]->node_porosity[k]; + else + poro = m_kr->GetPhaseVolumeAtNode(k, 1, 0); // no poro update when RACINT does not exist + phi = conc * MV * (1 - poro); + } + phi = DMAX(1e-7, phi); // guarantee a minimum surface area + // else phi = 1e-6; + m_kr->Am[k] = phi * m_kr->Am_ini * cp_vec[m_kr->mineral_number]->molar_weight / MV; + break; + default: + // do nothing here, update is done in preprocessing function + break; + } + } + } + } + if (warning) + cout << " Warning: A mineral concentration is 0.0 at node " << k << "\n" + << " --> setting surface area to minimum of 1e-8." + << "\n"; + + CTimeDiscretization* m_tim = NULL; + m_tim = time_vector[0]; + int steps = int(m_tim->time_step_vector.size()); + bool plot = false; + if (aktueller_zeitschritt == 1 || aktueller_zeitschritt % 10 == 0 || steps == int(aktueller_zeitschritt)) + plot = true; + + // debug output + if (debugoutflag && activity_model > 0 && plot == true) + { + c_dumpfilename = FileName + "_Activities.dump"; + c_dump.setf(ios::scientific, ios::floatfield); + c_dump.precision(12); + c_dump.open(c_dumpfilename.c_str()); + // header + c_dump << "Node IonicStrength "; + for (i = 0; i < ncomp; i++) + c_dump << cp_vec[i]->compname << " "; + c_dump << "\n"; + // data + for (int j = 0; j < nnode; j++) + { + c_dump << j << " " << IonicStrengths[j] << " "; + for (i = 0; i < ncomp; i++) + c_dump << ActivityCoefficients[j][i] << " "; + c_dump << "\n" << flush; + } + c_dump.close(); + } + if (debugoutflag && plot == true) + { + c_dumpfilename = FileName + "_EquilibriumConstants.dump"; + c_dump.setf(ios::scientific, ios::floatfield); + c_dump.precision(12); + c_dump.open(c_dumpfilename.c_str()); + // header + c_dump << "Node "; + for (i = 0; i < this->NumberReactions; i++) + { + m_kr = KinReact_vector[i]; + if (m_kr->typeflag_mineralkinetics != 0) + c_dump << m_kr->getName() << " "; + } + c_dump << "\n"; + // data + for (int j = 0; j < nnode; j++) + { + c_dump << j << " "; + for (i = 0; i < this->NumberReactions; i++) + { + m_kr = KinReact_vector[i]; + if (m_kr->typeflag_mineralkinetics != 0) + { + if (m_kr->Km_uniform == false) + c_dump << m_kr->Km[j] << " "; + else + c_dump << m_kr->Km[0] << " "; + } + } + c_dump << "\n" << flush; + } + c_dump.close(); + } + + return; +} /************************************************************************** Reaction-Method: - Task: Constructor of MinkinMech class + Task: This function updates mineral reactive surface areas after reactions Programing: //CB 01.2011 CB First implementation **************************************************************************/ -MinkinMech::MinkinMech (void){ +void CKinReactData::PostprocessMinKin() +{ + int i, k, nnode; + double conc0 = 0; + double phi0, phi1, n0, n1, conc1, mv; + bool outflag = false; + + phi0 = phi1 = n0 = n1 = conc0 = mv = 0; + + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt + nnode = (long)m_msh->nod_vector.size(); + CKinReact* m_kr = NULL; - no_mechSpec=0; - mechSpeciesIdx.clear(); - mechSpeciesNames.clear(); - mechSpeciesExpo.clear(); - Eact=-1; - k25=-1; + // update or reset mineral reactive surface areas for next time step + for (i = 0; i < NumberReactions; i++) + { + m_kr = KinReact_vector[i]; + if (m_kr->typeflag_mineralkinetics && m_kr->Am_constant == false) + { + outflag = true; + for (k = 0; k < nnode; k++) + { + // this function is executed before new time level Cs were copied to old time level + // so access the old time level concentrazion here by index-1 + // conc0 = + // pcs_vector[sp_pcsind[m_kr->mineral_number]]->GetNodeValue(k,sp_varind[m_kr->mineral_number]-1); + // conc1 = pcs_vector[sp_pcsind[m_kr->mineral_number]]->GetNodeValue(k,sp_varind[m_kr->mineral_number]); + conc0 + = cp_vec[m_kr->mineral_number]->getProcess()->GetNodeValue(k, sp_varind[m_kr->mineral_number] - 1); + conc1 = cp_vec[m_kr->mineral_number]->getProcess()->GetNodeValue(k, sp_varind[m_kr->mineral_number]); + // CB HS update + + switch (m_kr->Am_model) + { + case 1: // restore A0/C0 from A0*C(t)/C0 by division with C(t) after transport + if (conc0 > 0) + m_kr->Am[k] /= conc0; + else + m_kr->Am[k] = 1e-6; // minimum allowed surface area to allow regrowth of a mineral + break; + case 2: // for primary minerals, volume fraction weighted + if (REACTINT_vec.size() > 0) + { + n0 = REACTINT_vec[0]->node_ini_porosity[k]; // here plug in n_ini at node + n1 = REACTINT_vec[0]->node_porosity[k]; + } + else + n0 = n1 = m_kr->GetPhaseVolumeAtNode(k, 1, 0); // no poro update when RACINT does not exist + if (conc0 > conc1) + { // dissolution + mv = cp_vec[m_kr->mineral_number]->molar_weight + / cp_vec[m_kr->mineral_number]->mineral_density; + phi0 = m_kr->Cminini[k] * (1 - n0) * mv; + phi1 = conc1 * (1 - n1) * mv; + } + else // precipitation + phi0 = phi1 = 1; + m_kr->Am[k] = m_kr->Am_ini * pow((phi1 / phi0 * n1 / n0), 0.66667); + break; + case 3: // for secondary minerals, only poro fraction weighted + if (REACTINT_vec.size() > 0) + { + n0 = REACTINT_vec[0]->node_porosity[k]; // here plug in n_ini at node + n1 = REACTINT_vec[0]->node_porosity[k]; + } + else + n0 = n1 = m_kr->GetPhaseVolumeAtNode(k, 1, 0); // no poro update when RACINT does not exist + if (conc0 > conc1) + { // dissolution + mv = cp_vec[m_kr->mineral_number]->molar_weight + / cp_vec[m_kr->mineral_number]->mineral_density; + phi1 = conc1 * (1 - n1) * mv; + } + else // precipitation + phi1 = 1; + m_kr->Am[k] = m_kr->Am_ini * pow(phi1 * n1 / n0, 0.66667); + break; + case 4: // for secondary minerals, specific Area dissolution model + if (REACTINT_vec.size() > 0) + { + n0 = REACTINT_vec[0]->node_ini_porosity[k]; // here plug in n_ini at node + n1 = REACTINT_vec[0]->node_porosity[k]; + } + else + n0 = n1 = m_kr->GetPhaseVolumeAtNode(k, 1, 0); // no poro update when RACINT does not exist + if (conc0 > conc1) + { // dissolution + mv = cp_vec[m_kr->mineral_number]->molar_weight + / cp_vec[m_kr->mineral_number]->mineral_density; + phi1 = conc1 * (1 - n1) * mv; + m_kr->Am[k] = m_kr->Am_ini * phi1 * cp_vec[m_kr->mineral_number]->molar_weight / mv; + } + else + { // precipitation as model 3 + phi1 = 1; + m_kr->Am[k] = m_kr->Am_ini * pow(phi1 * n1 / n0, 0.66667); + } + break; + case 5: + // do nothing + break; + default: + // do nothing + break; + } + } + } + } + + CTimeDiscretization* m_tim = NULL; + m_tim = time_vector[0]; + int steps = int(m_tim->time_step_vector.size()); + bool plot = false; + if (aktueller_zeitschritt == 1 || aktueller_zeitschritt % 10 == 0 || steps == int(aktueller_zeitschritt)) + plot = true; + + // debug output + if (debugoutflag && outflag && plot) + { + ofstream aus; + string file = FileName + "_reactivesurfaceareas.dump"; + aus.setf(ios::scientific, ios::floatfield); + aus.precision(12); + aus.open(file.c_str()); + + for (i = 0; i < nnode; i++) + { + if (i == 0) + { + aus << "node "; + for (int j = 0; j < NumberReactions; j++) + { + m_kr = KinReact_vector[j]; + if (m_kr->typeflag_mineralkinetics && m_kr->Am_constant == false) + aus << m_kr->mineral_name << " "; + } + aus << "\n"; + } + aus << i << " "; + // data + for (int j = 0; j < NumberReactions; j++) + { + m_kr = KinReact_vector[j]; + if (m_kr->typeflag_mineralkinetics && m_kr->Am_constant == false) + aus << m_kr->Am[i] << " "; + } + aus << "\n"; + } + aus.close(); + } + return; } -MinkinMech::~MinkinMech (void){ + +/************************************************************************** + Reaction-Method: + Task: This function calculates the IAP/Kequi term of the Lasaga rate law + Programing: + //CB 01.2011 CB First implementation + **************************************************************************/ +double CKinReact::Omega(double* c, int node) +{ + // if(node == 68) + // cout << node ; + int i, idx; + double omega = 1; + double K_pt = 0; + double conc = 0; + double unitfactor_l = 1; + + CKinReactData* m_krd = NULL; + m_krd = KinReactData_vector[0]; + + if (REACTINT_vec.size() > 0) + { + REACTINT* m_rei = NULL; + m_rei = REACTINT_vec[0]; + if (m_rei->unitconversion) + unitfactor_l = MOLH2OPERKG / m_rei->water_conc[node]; + } + // get K equi at given P and T + if (Km_uniform == true) + K_pt = Km[0]; // KR variable + else if (Km_uniform == false) + K_pt = Km[node]; // KR variable + + // ion activity product + // -ProductionStoch[idx] is exponent in IAP; sign must be changed here + // negative, because the kinetic reaction is formulated for precipitation + // --> removal of dissolved species from solution --> negative StoechCoeff, + // but they are positive in IAP for educts of a mineral + for (i = 0; i < number_reactionpartner; i++) + { + idx = minSpeciesIdx[i]; + conc = c[idx + 1]; + if (c[idx + 1] < 0) + conc = 1e-20; + if (idx == mineral_number) + omega /= 1; // Mineral activity = 1 by definition + else if (idx == water_number) + { + if (m_krd->activity_model > 0) // in case of water, this contains the activity directly + omega *= pow(m_krd->ActivityCoefficients[node][idx], -ProductionStoch[idx]); + else + omega /= 1; + } + else + { + // if(reactionpartner[i].compare("pH")!=0){ + if (m_krd->activity_model > 0) + omega *= pow(m_krd->ActivityCoefficients[node][idx] * conc * unitfactor_l, -ProductionStoch[idx]); + else + omega *= pow(1 * conc * unitfactor_l, -ProductionStoch[idx]); + //} + // else // pH is -log(gamma*H+) + // omega *= pow( exp(-conc), -ProductionStoch[idx]); + } + } + // divide by equilibrium constant + if (number_reactionpartner == 0) + omega = 0; + else + omega /= K_pt; + return omega; } +/************************************************************************** + Reaction-Method: + Task: This function calculates the mineral dissolution / precipitation + rate as a function of the rate constant Ktot, the surface area + and the IAP + Programing: + //CB 01.2011 CB First implementation + **************************************************************************/ +double CKinReact::MinRate(double* c, int node, double dt, double Om) +{ + double rate = 0, maxrate = 0; + double ktot = 0, conc = 0, poro1 = 1, poro2 = 1; + double /*Om,*/ H1, H2, Betrag, vol, A = 0; + int i = 0; + + // get Surface Area + if (Am_constant) + A = Am[0]; + else + A = Am[node]; + + // IAP + // Om = Omega(c, node); + H1 = pow(Om, Theta); + // DMIN(H1, 11.0); + // total rate + if (H1 < 1 && c[mineral_number + 1] <= 1.1e-7) // undersaturated, but no mineral present, no dissolution + rate = 0; + else + { // supersat.-->precip, or undersat. & mineral present + H2 = fabs(1 - H1); + if (H2 < OmegaThreshhold) // very close to equilibrium, do nothing + rate = 0; + else + { + Betrag = pow(H2, Eta); + vol = GetReferenceVolume(mineral_number, node); + if (ExplicitMinKinRateCoeff) + ktot = this->MinKinRateCoeff; + else + ktot = -MinRateConstant(c, node, (1 - H1)); // default negative rate: dissolution of mineral + // sign function:, positive rate for supersat, and slow it down by precipfactor (defaulfactor = 1) + if ((1 - H1) <= 0) + rate = -1.0 * precipfactor * ktot * A + / vol; // precipfactor used to slow down precipitation by constant factor + else + rate = ktot * A / vol; + // some modification for Lagneau Benchmark probably required here + + // Lagneau Benchmark + // bool lagneau = false; + if (lagneau) + rate = -1.0 * A * vol * ktot / vol; + // if(node==1) cout << " Attention: Lagneau-Benchmark with modified mineral rate"; + + // in case of strong supersaturation, reduce precipitation rate by root function + if ((1 - H1) <= -1.0) + rate *= pow(Betrag, 1 / precipexponent); + else + rate *= Betrag; + } + } + // limit rates to the present amount of mineral and dissolved species to avoid overshoot + if (scale_rate && rate != 0) + { + maxrate = rate; + poro1 = GetReferenceVolume(mineral_number, node); // mineral (solid phase volume) + if (rate < 0) + { // dissolution + // only limited by left hand side reaction equation species, i.e. Stcoef>0 or mineral itself + for (i = 0; i < int(ProductionStoch.size()); i++) + { + if (ProductionStoch[i] > 0 || i == mineral_number) + { + conc = DMAX(0, c[i + 1]); // do not evaluate negative conc + if (mineral_number == i) // this is the mineral + maxrate = -conc / dt; // max amount that can be dissolved + else if (ProductionStoch[i] > 0) + { // this is other species consumed by dissolution, Stcoef > 0 + poro2 = GetReferenceVolume(i, node); // dissolved phase volume + maxrate = -conc / dt * poro2 / poro1 / ProductionStoch[i]; + } + // update maxrate,the larger, the more negative, so find maximum here + rate = DMAX(rate, maxrate); + } + } + } + else if (rate > 0) + { // precipitation, not limited by mineral concentration + for (i = 0; i < int(ProductionStoch.size()); i++) + { + if (ProductionStoch[i] < 0) + { // this is species consumed by precipitation, Stcoef < 0 + conc = DMAX(0, c[i + 1]); // do not evaluate negative conc + poro2 = GetReferenceVolume(i, node); // dissolved phase volume + maxrate = -conc / dt * poro2 / poro1 / ProductionStoch[i]; // - before conc is necessary here + } + // update maxrate, the larger, the more positive, so find minimum here + rate = DMIN(rate, maxrate); + } + } + } + + // if(scale_rate){ + // maxrate = rate; + // poro1 = GetReferenceVolume(mineral_number,node); // mineral (solid phase volume) + // if(rate<0){ // dissolution + // //only limited by left hand side reaction equation species, i.e. Stcoef>0 or mineral itself + // for(i=0;i0){ // this is other species consumed by dissolution, Stcoef > 0 + // poro2 = GetReferenceVolume(minSpeciesIdx[i],node); // dissolved phase volume + // maxrate = -conc / dt * poro2 / poro1 / ProductionStoch[minSpeciesIdx[i]]; + // } + // // update maxrate,the larger, the more negative, so find maximum here + // rate = DMAX(rate,maxrate); + // } + // } + // else if (rate>0){ // precipitation, not limited by mineral concentration + // for(i=0;i 0 && rate < 1e-30) + rate = 0; + if (rate < 0 && rate > -1e-30) + rate = 0; + return rate; + // return rate/double(KinReactData_vector[0]->NumberMineralkinetics); +} + +/************************************************************************** + Reaction-Method: + Task: This function resturns the mineral disoolution / precipitation + rate constant as a sum over all reaction mechanisms + Ktot = Sum(Mech) + Programing: + //CB 01.2011 CB First implementation + **************************************************************************/ +double CKinReact::MinRateConstant(double* c, int node, double disso) +{ + int i; + double ktot = 0; + + // calc the rate constant + for (i = 0; i < number_Mech; i++) + { + if (disso < 0 && precip_baseterm_only == true) + { // for precipitation, consider only base mechanism, if set in inputfile + if (mechvec[i]->no_mechSpec == 0) + ktot += mechvec[i]->Mech(c, node); + } + else + { // consider all mechanisms + ktot += mechvec[i]->Mech(c, node); + } + } + + return ktot; +} + +/**************************************************************************/ +// Functions for class MinKinMech +/**************************************************************************/ + +/************************************************************************** + Reaction-Method: + Task: Constructor of MinkinMech class + Programing: + //CB 01.2011 CB First implementation + **************************************************************************/ +MinkinMech::MinkinMech(void) +{ + no_mechSpec = 0; + mechSpeciesIdx.clear(); + mechSpeciesNames.clear(); + mechSpeciesExpo.clear(); + Eact = -1; + k25 = -1; +} +MinkinMech::~MinkinMech(void) +{ +} /************************************************************************** Reaction-Method: @@ -8181,334 +8522,394 @@ MinkinMech::~MinkinMech (void){ Programing: //CB 01.2011 CB First implementation **************************************************************************/ -double MinkinMech::Mech (double *c, int node){ - - // the base term is treated as a mechanism as well - // Todo: add some function to get T - - int i, idx, actmodel; - double kmech=0, conc = 0; - double R = 8.314472; // gas constant = R 8.314472(15) J/K/mol - CKinReactData *m_krd = NULL; - m_krd = KinReactData_vector[0]; - double unitfactor_l = 1; - double T = 298.15; - - if(REACTINT_vec.size()>0){ - REACTINT *m_rei = NULL; - m_rei = REACTINT_vec[0]; - if(m_rei->unitconversion) - unitfactor_l = MOLH2OPERKG / m_rei->water_conc[node] ; - T = m_rei->GetTemperature(node); - } - actmodel = m_krd->activity_model; - - // Todo: add some function to get T from heat transport pcs - - // Arrhenius - kmech = k25*exp(-Eact/R*(1/T-1/298.15)); - // multiply by mechanism activities term - for(i=0;i0) - kmech *= pow((m_krd->ActivityCoefficients[node][idx]*conc*unitfactor_l), mechSpeciesExpo[i]); - else - kmech *= pow((1*conc*unitfactor_l), mechSpeciesExpo[i]); // all activity coefficients are 1.0 - } - else{ // pH is -log(gamma*H+) - if(actmodel>0) - kmech *= pow(pow(10,m_krd->ActivityCoefficients[node][idx]*(-conc*unitfactor_l)), mechSpeciesExpo[i]); - else - kmech *= pow(pow(10,1*(-conc*unitfactor_l)), mechSpeciesExpo[i]); - } - } - - return kmech; -} +double MinkinMech::Mech(double* c, int node) +{ + // the base term is treated as a mechanism as well + // Todo: add some function to get T + + int i, idx, actmodel; + double kmech = 0, conc = 0; + double R = 8.314472; // gas constant = R 8.314472(15) J/K/mol + CKinReactData* m_krd = NULL; + m_krd = KinReactData_vector[0]; + double unitfactor_l = 1; + double T = 298.15; + + if (REACTINT_vec.size() > 0) + { + REACTINT* m_rei = NULL; + m_rei = REACTINT_vec[0]; + if (m_rei->unitconversion) + unitfactor_l = MOLH2OPERKG / m_rei->water_conc[node]; + T = m_rei->GetTemperature(node); + } + actmodel = m_krd->activity_model; + + // Todo: add some function to get T from heat transport pcs + + // Arrhenius + kmech = k25 * exp(-Eact / R * (1 / T - 1 / 298.15)); + // multiply by mechanism activities term + for (i = 0; i < no_mechSpec; i++) + { + idx = mechSpeciesIdx[i]; + conc = c[idx + 1]; + if (conc < 0) + conc = 1.0e-20; + if (mechSpeciesNames[i].compare("pH") != 0) + { + if (actmodel > 0) + kmech *= pow((m_krd->ActivityCoefficients[node][idx] * conc * unitfactor_l), mechSpeciesExpo[i]); + else + kmech *= pow((1 * conc * unitfactor_l), mechSpeciesExpo[i]); // all activity coefficients are 1.0 + } + else + { // pH is -log(gamma*H+) + if (actmodel > 0) + kmech *= pow(pow(10, m_krd->ActivityCoefficients[node][idx] * (-conc * unitfactor_l)), + mechSpeciesExpo[i]); + else + kmech *= pow(pow(10, 1 * (-conc * unitfactor_l)), mechSpeciesExpo[i]); + } + } + return kmech; +} /************************************************************************** Reaction-Method: Task: Copy concentrations after reaction step to symmetric nodes - Implemented only for radial models with one hex element in theta direction - Then it is sufficient to simulate flow and conservative transport at all nodes, - but reactions only at one side of the element. Then copy to other side of element. + Implemented only for radial models with one hex element in theta direction + Then it is sufficient to simulate flow and conservative transport at all nodes, + but reactions only at one side of the element. Then copy to other side of element. Programing: //SB 01.2011 SB First implementation **************************************************************************/ -void CKinReactData::CopyConcentrations(void){ - - long i, l, k, nnodes, nele; - size_t j; - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt - CRFProcess *m_pcs = NULL; - //CNode* m_nod0 = NULL, *m_nod1 = NULL, *m_nod2 = NULL, *m_nod3 = NULL; - MeshLib::CElem* m_ele = NULL; - vec ele_nodes(8); - Math_Group::vec vec_nod_index(8); - const double * coord0, * coord1, * coord2, * coord3; - bool err_flag = true; // if true, all is OK, if false, do not use this option - int copy_direction = -1; - long i_copy_from, i_copy_to; - int nidx0; - long nidx = 0; - - if(copy_concentrations == false) - return; - - cout << " CopyConcentrations " << "\n"; - // get number of nodes - nnodes = (long) m_msh->nod_vector.size(); - nele = (long) m_msh->ele_vector.size(); - - // first time called, Check if mesh is appropriate - if(copy_nodes.size() < 1){ - // BATCH - if(batch){ - if(nnodes==2 && nele == 1 && m_msh->ele_vector[0]->GetElementType() == 1){ - // for a single line element - if(is_a_CCBC[0] == true && is_a_CCBC[1] == false ) - batch = true; - else if(is_a_CCBC[0] == false && is_a_CCBC[1] == true ) - batch = true; - else{ - cout << "\n" << " Copy Concentrations only for a single (batch) line element with one deactivated node!" - << " - Option switched off " << "\n"; - batch = copy_concentrations = false; - } - } - } - // RADIAL - else if ((radial) || (TwoDinThreeD)){ - // Only for hex-elements - for(i=0;iele_vector[i]->GetElementType() != 3){ - cout << "\n" << " Copy Cons only for hex elements ! - Option switched off " << "\n"; - radial = TwoDinThreeD = copy_concentrations = false; - break; - } - } - - // Now test for radial flow model along x-Axis - // Test is if model is symmetric to x-Axis; not tested is, if it is one column - m_ele = m_msh->ele_vector[0]; // get first element - m_ele->GetNodes(ele_nodes); // get element nodes - coord0 = ele_nodes[0]->getData(); // Get coordinates of first four element nodes ("upper" part of element) - coord1 = ele_nodes[1]->getData(); // CB 03/11 - coord2 = ele_nodes[2]->getData(); - coord3 = ele_nodes[3]->getData(); - -/* *3-----*2 - |\ |\ - | *0---+-*1 - *-|----* | - \| \| - *------* */ - - // check orientation of element: all should have same z-value - if((coord0[2] != coord1[2]) || (coord0[2] != coord2[2]) || (coord0[2] != coord3[2])){ - cout << " Error: Not identical z coordinates of element nodes of element 0 " << "\n"; - err_flag = false; - } - // node0 and node3 should have same x value, as well as node1 and node2 - if((coord0[0] != coord3[0]) || (coord1[0] != coord2[0])){ - cout << " Error: Not identical x coordinates of element nodes (0/3) or (1/2) of element 0 " << "\n"; - err_flag = false; - } - // this is different for radial and TwoDinThreeD - if(radial){ - // node0 and node3 should have same y=-y value, as well as node1 and node2 - if((coord0[1] != -1.0*coord3[1]) || (coord1[1] != -1.0*coord2[1])){ // this is just for radial flow models - cout << " Error: Not y_i = -y_j for element nodes (0/3) or (1/2) of element 0 " << "\n"; - err_flag = false; - } - } - else if (TwoDinThreeD){ - // node0 and node1 should have same y value, as well as node2 and node3 - if((coord0[1] != coord1[1]) || (coord2[1] != coord3[1])){ // this is for regular hex grid flow models - cout << " Error: Not y_i = -y_j for element nodes (0/3) or (1/2) of element 0 " << "\n"; - err_flag = false; - } - } - // everything fine so far? - if(err_flag == false) { - cout << "\n" << " Copy Cons - Grid not appliccable ! - Option switched off " << "\n"; - radial = TwoDinThreeD = copy_concentrations = false; - } - - // Now check, if the correct nodes are switched off and determine copy direction, only for radial - err_flag = true; // reset for reuse - if(radial){ - if(is_a_CCBC[ele_nodes[0]->GetIndex()] == true) { // element node 0 is not calculated - if(is_a_CCBC[ele_nodes[1]->GetIndex()] != true) err_flag = false; - if(is_a_CCBC[ele_nodes[2]->GetIndex()] != false) err_flag = false; - if(is_a_CCBC[ele_nodes[3]->GetIndex()] != false) err_flag = false; - copy_direction = 1; - } - if(is_a_CCBC[ele_nodes[3]->GetIndex()] == true) { // element node 0 is not calculated - if(is_a_CCBC[ele_nodes[2]->GetIndex()] != true) err_flag = false; - if(is_a_CCBC[ele_nodes[1]->GetIndex()] != false) err_flag = false; - if(is_a_CCBC[ele_nodes[0]->GetIndex()] != false) err_flag = false; - copy_direction = 0; - } - // everything fine so far? - if(err_flag == false) { - cout << "\n" << " Copy Cons - Please switch off one model side for reaction calculation ! - Option switched off " << "\n"; - radial = TwoDinThreeD = copy_concentrations = false; - } - } - }// ((radial) || (TwoDinThreeD)){ - - }// end of mesh and geometry checks - - // now quit, if somethings wrong - if(copy_concentrations == false) - return; - - - - // first time called, build data structures and set up index vector - if(copy_nodes.size() < 1){ - - // Make vector for all nodes for mapping - for(i=0;i0 ) copy_nodes[i]=i-1; - else if(is_a_CCBC[i] == true) copy_nodes[i]=i+1; - }// batch - else if(radial){ - // Go through all elements and set copy values respectively - for(i=0;iele_vector[i]; // get element - m_ele->GetNodeIndeces(vec_nod_index); - if(copy_direction == 1){ // element nodes 0, 1, 4, 5 not calculated - // copy concentrations 3 -> 0 - i_copy_from = vec_nod_index[3]; - i_copy_to = vec_nod_index[0]; - copy_nodes[i_copy_to] = i_copy_from; - // copy concentrations 2 -> 1 - i_copy_from = vec_nod_index[2]; - i_copy_to = vec_nod_index[1]; - copy_nodes[i_copy_to] = i_copy_from; - // copy concentrations 7 -> 4 - i_copy_from = vec_nod_index[7]; - i_copy_to = vec_nod_index[4]; - copy_nodes[i_copy_to] = i_copy_from; - // copy concentrations 6 -> 5 - i_copy_from = vec_nod_index[6]; - i_copy_to = vec_nod_index[5]; - copy_nodes[i_copy_to] = i_copy_from; - } - if(copy_direction == 0){ // element nodes 2, 3, 6, 7 not calculated - // copy concentrations 0 -> 3 - i_copy_from = vec_nod_index[0]; - i_copy_to = vec_nod_index[3]; - copy_nodes[i_copy_to] = i_copy_from; - // copy concentrations 1 -> 2 - i_copy_from = vec_nod_index[1]; - i_copy_to = vec_nod_index[2]; - copy_nodes[i_copy_to] = i_copy_from; - // copy concentrations 4 -> 7 - i_copy_from = vec_nod_index[4]; - i_copy_to = vec_nod_index[7]; - copy_nodes[i_copy_to] = i_copy_from; - // copy concentrations 5 -> 6 - i_copy_from = vec_nod_index[5]; - i_copy_to = vec_nod_index[6]; - copy_nodes[i_copy_to] = i_copy_from; - } - if(i==0) { - cout << "\n" << "copy_nodes[i] = " << "\n"; - for(int ii=0;ii<8;ii++) cout << " " << ii << " = " << copy_nodes[ii] << "\n"; - } - } - } // radial - else if(TwoDinThreeD ){ - for(i=0;inod_vector[i]->getData(); - // check all neighbour nodes - for(j=0;jnod_vector[i]->getNumConnectedNodes();j++){ - nidx = m_msh->nod_vector[i]->getConnectedNodes()[j]; - coord1 = m_msh->nod_vector[nidx]->getData(); - // check orientation of nodes: should have same x + z and y of neighbour should be larger - if((coord0[0] == coord1[0]) && (coord0[2] == coord1[2]) && (coord0[1] < coord1[1])){ - // Found! - // Check if reaction is really switched off at this neighbour - if(is_a_CCBC[nidx] == true) //set the neighbour index - //copy_nodes[i]=nidx; - copy_nodes[nidx]=i; - break; - } - } // done - // now check for success: - if(copy_nodes[nidx]==nidx) - cout << "Warning in CKinReactData::CopyConcentrations:!" - << " No Neighbour found for copy nodes " << i << "\n"; - }// is_a_CCBC[i] == false -> node with reactions - }// node loop - }// TwoDinThreeD - - }// if first time - - - // Now, Copy concentrations in all cases - // Go through all transport processes and copy values for all nodes - // Where to put this? -> ToDo CB in new concept - // this is the same for batch or radial or 2Din3D - for(i=0;i<(int)pcs_vector.size();i++){ - m_pcs = pcs_vector[i]; - if(m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) { // if it is a MASS_TRANSPORT process - l=0; - // get index of concentration - for(j=0;j<(size_t)m_pcs->pcs_number_of_primary_nvals;j++){ - nidx0 = m_pcs->GetNodeValueIndex(m_pcs->pcs_primary_function_name[j])+1; // new time level - for(k=0;kSetNodeValue(i_copy_to,nidx0,m_pcs->GetNodeValue(i_copy_from,nidx0)); - l++; - } - } - } - } - } - cout << " at " << l << " of " << nnodes << " nodes." << "\n"; - // end function -} +void CKinReactData::CopyConcentrations(void) +{ + long i, l, k, nnodes, nele; + size_t j; + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt + CRFProcess* m_pcs = NULL; + // CNode* m_nod0 = NULL, *m_nod1 = NULL, *m_nod2 = NULL, *m_nod3 = NULL; + MeshLib::CElem* m_ele = NULL; + vec ele_nodes(8); + Math_Group::vec vec_nod_index(8); + const double *coord0, *coord1, *coord2, *coord3; + bool err_flag = true; // if true, all is OK, if false, do not use this option + int copy_direction = -1; + long i_copy_from, i_copy_to; + int nidx0; + long nidx = 0; + + if (copy_concentrations == false) + return; + + cout << " CopyConcentrations " + << "\n"; + // get number of nodes + nnodes = (long)m_msh->nod_vector.size(); + nele = (long)m_msh->ele_vector.size(); + // first time called, Check if mesh is appropriate + if (copy_nodes.size() < 1) + { + // BATCH + if (batch) + { + if (nnodes == 2 && nele == 1 && m_msh->ele_vector[0]->GetElementType() == 1) + { + // for a single line element + if (is_a_CCBC[0] == true && is_a_CCBC[1] == false) + batch = true; + else if (is_a_CCBC[0] == false && is_a_CCBC[1] == true) + batch = true; + else + { + cout << "\n" + << " Copy Concentrations only for a single (batch) line element with one deactivated node!" + << " - Option switched off " + << "\n"; + batch = copy_concentrations = false; + } + } + } + // RADIAL + else if ((radial) || (TwoDinThreeD)) + { + // Only for hex-elements + for (i = 0; i < nele; i++) + { + if (m_msh->ele_vector[i]->GetElementType() != 3) + { + cout << "\n" + << " Copy Cons only for hex elements ! - Option switched off " + << "\n"; + radial = TwoDinThreeD = copy_concentrations = false; + break; + } + } + + // Now test for radial flow model along x-Axis + // Test is if model is symmetric to x-Axis; not tested is, if it is one column + m_ele = m_msh->ele_vector[0]; // get first element + m_ele->GetNodes(ele_nodes); // get element nodes + coord0 = ele_nodes[0]->getData(); // Get coordinates of first four element nodes ("upper" part of element) + coord1 = ele_nodes[1]->getData(); // CB 03/11 + coord2 = ele_nodes[2]->getData(); + coord3 = ele_nodes[3]->getData(); + + /* *3-----*2 + |\ |\ + | *0---+-*1 + *-|----* | + \| \| + *------* */ + + // check orientation of element: all should have same z-value + if ((coord0[2] != coord1[2]) || (coord0[2] != coord2[2]) || (coord0[2] != coord3[2])) + { + cout << " Error: Not identical z coordinates of element nodes of element 0 " + << "\n"; + err_flag = false; + } + // node0 and node3 should have same x value, as well as node1 and node2 + if ((coord0[0] != coord3[0]) || (coord1[0] != coord2[0])) + { + cout << " Error: Not identical x coordinates of element nodes (0/3) or (1/2) of element 0 " + << "\n"; + err_flag = false; + } + // this is different for radial and TwoDinThreeD + if (radial) + { + // node0 and node3 should have same y=-y value, as well as node1 and node2 + if ((coord0[1] != -1.0 * coord3[1]) || (coord1[1] != -1.0 * coord2[1])) + { // this is just for radial flow models + cout << " Error: Not y_i = -y_j for element nodes (0/3) or (1/2) of element 0 " + << "\n"; + err_flag = false; + } + } + else if (TwoDinThreeD) + { + // node0 and node1 should have same y value, as well as node2 and node3 + if ((coord0[1] != coord1[1]) || (coord2[1] != coord3[1])) + { // this is for regular hex grid flow models + cout << " Error: Not y_i = -y_j for element nodes (0/3) or (1/2) of element 0 " + << "\n"; + err_flag = false; + } + } + // everything fine so far? + if (err_flag == false) + { + cout << "\n" + << " Copy Cons - Grid not appliccable ! - Option switched off " + << "\n"; + radial = TwoDinThreeD = copy_concentrations = false; + } + + // Now check, if the correct nodes are switched off and determine copy direction, only for radial + err_flag = true; // reset for reuse + if (radial) + { + if (is_a_CCBC[ele_nodes[0]->GetIndex()] == true) + { // element node 0 is not calculated + if (is_a_CCBC[ele_nodes[1]->GetIndex()] != true) + err_flag = false; + if (is_a_CCBC[ele_nodes[2]->GetIndex()] != false) + err_flag = false; + if (is_a_CCBC[ele_nodes[3]->GetIndex()] != false) + err_flag = false; + copy_direction = 1; + } + if (is_a_CCBC[ele_nodes[3]->GetIndex()] == true) + { // element node 0 is not calculated + if (is_a_CCBC[ele_nodes[2]->GetIndex()] != true) + err_flag = false; + if (is_a_CCBC[ele_nodes[1]->GetIndex()] != false) + err_flag = false; + if (is_a_CCBC[ele_nodes[0]->GetIndex()] != false) + err_flag = false; + copy_direction = 0; + } + // everything fine so far? + if (err_flag == false) + { + cout << "\n" + << " Copy Cons - Please switch off one model side for reaction calculation ! - Option " + "switched off " + << "\n"; + radial = TwoDinThreeD = copy_concentrations = false; + } + } + } // ((radial) || (TwoDinThreeD)){ + + } // end of mesh and geometry checks + + // now quit, if somethings wrong + if (copy_concentrations == false) + return; + + // first time called, build data structures and set up index vector + if (copy_nodes.size() < 1) + { + // Make vector for all nodes for mapping + for (i = 0; i < nnodes; i++) + copy_nodes.push_back(i); // map each node to itself by default + + // Now, prepare copy node relations + if (batch) + { + for (i = 0; i < nnodes; i++) + if (is_a_CCBC[i] == true && i > 0) + copy_nodes[i] = i - 1; + else if (is_a_CCBC[i] == true) + copy_nodes[i] = i + 1; + } // batch + else if (radial) + { + // Go through all elements and set copy values respectively + for (i = 0; i < nele; i++) + { + m_ele = m_msh->ele_vector[i]; // get element + m_ele->GetNodeIndeces(vec_nod_index); + if (copy_direction == 1) + { // element nodes 0, 1, 4, 5 not calculated + // copy concentrations 3 -> 0 + i_copy_from = vec_nod_index[3]; + i_copy_to = vec_nod_index[0]; + copy_nodes[i_copy_to] = i_copy_from; + // copy concentrations 2 -> 1 + i_copy_from = vec_nod_index[2]; + i_copy_to = vec_nod_index[1]; + copy_nodes[i_copy_to] = i_copy_from; + // copy concentrations 7 -> 4 + i_copy_from = vec_nod_index[7]; + i_copy_to = vec_nod_index[4]; + copy_nodes[i_copy_to] = i_copy_from; + // copy concentrations 6 -> 5 + i_copy_from = vec_nod_index[6]; + i_copy_to = vec_nod_index[5]; + copy_nodes[i_copy_to] = i_copy_from; + } + if (copy_direction == 0) + { // element nodes 2, 3, 6, 7 not calculated + // copy concentrations 0 -> 3 + i_copy_from = vec_nod_index[0]; + i_copy_to = vec_nod_index[3]; + copy_nodes[i_copy_to] = i_copy_from; + // copy concentrations 1 -> 2 + i_copy_from = vec_nod_index[1]; + i_copy_to = vec_nod_index[2]; + copy_nodes[i_copy_to] = i_copy_from; + // copy concentrations 4 -> 7 + i_copy_from = vec_nod_index[4]; + i_copy_to = vec_nod_index[7]; + copy_nodes[i_copy_to] = i_copy_from; + // copy concentrations 5 -> 6 + i_copy_from = vec_nod_index[5]; + i_copy_to = vec_nod_index[6]; + copy_nodes[i_copy_to] = i_copy_from; + } + if (i == 0) + { + cout << "\n" + << "copy_nodes[i] = " + << "\n"; + for (int ii = 0; ii < 8; ii++) + cout << " " << ii << " = " << copy_nodes[ii] << "\n"; + } + } + } // radial + else if (TwoDinThreeD) + { + for (i = 0; i < nnodes; i++) + { + if (is_a_CCBC[i] == false) + { // reactions are quantified at this node + // get node coordinates + coord0 = m_msh->nod_vector[i]->getData(); + // check all neighbour nodes + for (j = 0; j < m_msh->nod_vector[i]->getNumConnectedNodes(); j++) + { + nidx = m_msh->nod_vector[i]->getConnectedNodes()[j]; + coord1 = m_msh->nod_vector[nidx]->getData(); + // check orientation of nodes: should have same x + z and y of neighbour should be larger + if ((coord0[0] == coord1[0]) && (coord0[2] == coord1[2]) && (coord0[1] < coord1[1])) + { + // Found! + // Check if reaction is really switched off at this neighbour + if (is_a_CCBC[nidx] == true) // set the neighbour index + // copy_nodes[i]=nidx; + copy_nodes[nidx] = i; + break; + } + } // done + // now check for success: + if (copy_nodes[nidx] == nidx) + cout << "Warning in CKinReactData::CopyConcentrations:!" + << " No Neighbour found for copy nodes " << i << "\n"; + } // is_a_CCBC[i] == false -> node with reactions + } // node loop + } // TwoDinThreeD + + } // if first time + + // Now, Copy concentrations in all cases + // Go through all transport processes and copy values for all nodes + // Where to put this? -> ToDo CB in new concept + // this is the same for batch or radial or 2Din3D + for (i = 0; i < (int)pcs_vector.size(); i++) + { + m_pcs = pcs_vector[i]; + if (m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) + { // if it is a MASS_TRANSPORT process + l = 0; + // get index of concentration + for (j = 0; j < (size_t)m_pcs->pcs_number_of_primary_nvals; j++) + { + nidx0 = m_pcs->GetNodeValueIndex(m_pcs->pcs_primary_function_name[j]) + 1; // new time level + for (k = 0; k < nnodes; k++) + { + i_copy_to = k; + i_copy_from = copy_nodes[i_copy_to]; + if (i_copy_to != i_copy_from) + { // only do for differing node indicess + m_pcs->SetNodeValue(i_copy_to, nidx0, m_pcs->GetNodeValue(i_copy_from, nidx0)); + l++; + } + } + } + } + } + cout << " at " << l << " of " << nnodes << " nodes." + << "\n"; + // end function +} // this is a "slow" bubblesort, but it gives back the indexes of our sort -void CKinReactData::SortIterations ( long *iterations, long *indexes, long len ) +void CKinReactData::SortIterations(long* iterations, long* indexes, long len) { - long i,j,iTmp; - // Set the index to match the current sort - // order of the names - for ( i = 0; i < len; i++ ) - indexes[i] = i; - - // Bubblesort. Sort the indexes - for ( i = 0; i < len; i++ ) - { - for ( j = 0; j < len; j++ ) - { - if ( iterations[indexes[i]] < iterations[indexes[j]] ) - { - // swap the indexes - iTmp = indexes[i]; - indexes[i] = indexes[j]; - indexes[j] = iTmp; - } - } - } + long i, j, iTmp; + // Set the index to match the current sort + // order of the names + for (i = 0; i < len; i++) + indexes[i] = i; + + // Bubblesort. Sort the indexes + for (i = 0; i < len; i++) + { + for (j = 0; j < len; j++) + { + if (iterations[indexes[i]] < iterations[indexes[j]]) + { + // swap the indexes + iTmp = indexes[i]; + indexes[i] = indexes[j]; + indexes[j] = iTmp; + } + } + } } diff --git a/FEM/rf_kinreact.h b/FEM/rf_kinreact.h index e411d5ad4..4a9b00be8 100644 --- a/FEM/rf_kinreact.h +++ b/FEM/rf_kinreact.h @@ -44,11 +44,11 @@ class MonodSubstruct { private: public: - std::string species; // Name of species - int speciesnumber; // number of species; - double concentration; //Monod concentration - double order; // Order of monod term - int isotopecouplenumber; // CB isotope fractionation : specis number of isotope partner + std::string species; // Name of species + int speciesnumber; // number of species; + double concentration; // Monod concentration + double order; // Order of monod term + int isotopecouplenumber; // CB isotope fractionation : specis number of isotope partner // CB for Threshhold terms bool threshhold; double threshConc; @@ -63,45 +63,43 @@ class MonodSubstruct // C++ Class Monodsubstruct class MicrobeData { - private: - public: - std::string MicrobeName; - std::string MonodReactionName; - std::vector Gibbs; - std::vector _drmc_level; - double steepness ; - double k_incr; - double k_decr; - double G0; - double dt; - double decayrate; - bool _drmc_; - int MonodReactionIdx; - - - double GetGibbsEnergy(long node); - bool Read(std::ifstream* in); - - - MicrobeData(void); - ~MicrobeData(void); +private: +public: + std::string MicrobeName; + std::string MonodReactionName; + std::vector Gibbs; + std::vector _drmc_level; + double steepness; + double k_incr; + double k_decr; + double G0; + double dt; + double decayrate; + bool _drmc_; + int MonodReactionIdx; + + double GetGibbsEnergy(long node); + bool Read(std::ifstream* in); + + MicrobeData(void); + ~MicrobeData(void); }; // C++ Class MinKinMech -class MinkinMech { +class MinkinMech +{ private: public: - int no_mechSpec; - std::vector mechSpeciesIdx; - std::vector mechSpeciesNames; - std::vector mechSpeciesExpo; - double Eact; - double k25; - - MinkinMech (void); - ~MinkinMech (void); - double Mech (double *c, int node); - + int no_mechSpec; + std::vector mechSpeciesIdx; + std::vector mechSpeciesNames; + std::vector mechSpeciesExpo; + double Eact; + double k25; + + MinkinMech(void); + ~MinkinMech(void); + double Mech(double* c, int node); }; // C++ Class CKinReact @@ -117,121 +115,121 @@ class CKinReact */ std::string type; - friend bool KRRead(std::string const & file_base_name, - GEOLIB::GEOObjects const & geo_obj, std::string const & unique_name); + friend bool KRRead(std::string const& file_base_name, GEOLIB::GEOObjects const& geo_obj, + std::string const& unique_name); friend void KRConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name); public: - CKinReact(void); // Constructor - ~CKinReact(void); // Destructor - - std::string const & getType () const { return type; } - std::string const & getName () const { return name; } - - int number; /* counter */ - int number_reactionpartner; /* Number of chemical species involved in reaction */ - std::vector reactionpartner; /* all names of reaction partners stored here */ - std::vector stochmet; /* stochiometric coefficients for each reactionpartner stored here */ - double rateconstant; /* rateconstant */ - double rateorder; /* order of reaction */ - int number_monod; /* Number of Monod terms */ - int number_inhibit; /* Number of inhibition terms */ - int number_production; /* number of production terms */ - int number_isotope_couples; /* number of production terms */ - std::vector monod; /* saves monod concentrations and names of species */ - std::vector inhibit; /* saves inhibit concentrations and names of species */ - std::vector production; /* saves production concentrations, orders and names of species */ - int grow; /* growth or no growth */ + CKinReact(void); // Constructor + ~CKinReact(void); // Destructor + + std::string const& getType() const { return type; } + std::string const& getName() const { return name; } + int number; /* counter */ + int number_reactionpartner; /* Number of chemical species involved in reaction */ + std::vector reactionpartner; /* all names of reaction partners stored here */ + std::vector stochmet; /* stochiometric coefficients for each reactionpartner stored here */ + double rateconstant; /* rateconstant */ + double rateorder; /* order of reaction */ + int number_monod; /* Number of Monod terms */ + int number_inhibit; /* Number of inhibition terms */ + int number_production; /* number of production terms */ + int number_isotope_couples; /* number of production terms */ + std::vector monod; /* saves monod concentrations and names of species */ + std::vector inhibit; /* saves inhibit concentrations and names of species */ + std::vector production; /* saves production concentrations, orders and names of species */ + int grow; /* growth or no growth */ std::string bacteria_name; int bacteria_number; - std::vector ProductionStoch; // stochiometry of reaction + std::vector ProductionStoch; // stochiometry of reaction // vector ProductionStoch2; // stochiometry of reaction - short version - std::vector ProdStochhelp; // store input values - double specif_cap; - //CB Isotope fractionation + std::vector ProdStochhelp; // store input values + double specif_cap; + // CB Isotope fractionation std::string Isotope_light; std::string Isotope_heavy; std::string degType; double isoenfac; - bool T_dependence; - int T_model; - std::vector T_params; - - // CB _drmc_ - bool _drmc_; - std::string Microbename; - std::string DormType; - int DormTypeIdx; - int MicrobeData_idx; - double dG0; // standard Gibbs energy of reaction - double Yieldcoefficient; - - //CB Not this particular reaction on specified GEO-Objects; Data structures - std::vector NotThisReactGeoName; - std::vector NotThisReactGeoID; // 06/2010 TF - std::vector NotThisReactGeoType; - std::vector switched_off_node; - long currentnode; // CB 19/10/09 This is eclusively for Brand model to allow porosity in Inhibition constant calculation + bool T_dependence; + int T_model; + std::vector T_params; + + // CB _drmc_ + bool _drmc_; + std::string Microbename; + std::string DormType; + int DormTypeIdx; + int MicrobeData_idx; + double dG0; // standard Gibbs energy of reaction + double Yieldcoefficient; + + // CB Not this particular reaction on specified GEO-Objects; Data structures + std::vector NotThisReactGeoName; + std::vector NotThisReactGeoID; // 06/2010 TF + std::vector NotThisReactGeoType; + std::vector switched_off_node; + long currentnode; // CB 19/10/09 This is eclusively for Brand model to allow porosity in Inhibition constant + // calculation // exchange data - std::vector ex_species_names; - std::vector ex_species; - std::vector ex_param; + std::vector ex_species_names; + std::vector ex_species; + std::vector ex_param; int exSurfaceID; - std::string exType; /* sorption type: linear, langmuir, exchange */ + std::string exType; /* sorption type: linear, langmuir, exchange */ //#ds NAPLdissolution data - std::string blob_name; /* name of blob-class */ - int blob_ID; /* id number of blobs where the NAPL phase resides */ - double Csat_pure; /* maximum solubility of the pure NAPL phase */ - double current_Csat; /* current solubility after considering Roult's law, interally calculated */ - double Density_NAPL; /* density of the pure NAPL phase */ + std::string blob_name; /* name of blob-class */ + int blob_ID; /* id number of blobs where the NAPL phase resides */ + double Csat_pure; /* maximum solubility of the pure NAPL phase */ + double current_Csat; /* current solubility after considering Roult's law, interally calculated */ + double Density_NAPL; /* density of the pure NAPL phase */ // double ConversionFactor; /* factor to convert concentrations to mol/kg */ - //SB speed-up flags - int typeflag_monod; /* set to 1 if reaction is monod type */ - int typeflag_exchange; /* set to 1 if reaction is exchange type */ - int typeflag_exchange_linear; /* set to 1 if reaction is linear exchange type */ - int typeflag_exchange_langmuir; /* set to 1 if reaction is langmuir exchange type */ - int typeflag_exchange_freundlich; /* set to 1 if reaction is freundlich exchange type */ - int typeflag_napldissolution; /* set to 1 if reaction is NAPL dissolution */ - int typeflag_iso_fract; /* set to 1 if reaction is isotope fractionation */ - int typeflag_mineralkinetics; /* set to 1 if reaction is mineral kinetics */ - int typeflag_gasdissolution; - - //CB new parallel computation data structure, replaces double current_Csat; - std::vector Current_Csat; /* initial interfacial area, interfacial area of last iteration */ - // Mineral kinetics data - std::vector mechvec; // stores individual mechanisms of this reaction - std::vector minSpeciesIdx; // stores cp vector index of mineral species - std::vector Am; // initial specific reactive mineral surface area m²/m³ aquifer = Am * rho_b = m²/kg * kg/m³aquifer - std::vector Km; // Equilibrium constant - std::vector Cminini; // initial mineral concentration - int number_Mech; // Number of Mechanism terms */ - bool Km_uniform; - bool Km_CHEMAPP; - bool Km_HKF; - bool scale_rate; - bool lagneau ; - - - double Km_default; - bool Am_constant; - int Am_model; - double Am_ini; // initial mineral Surface area - double Theta; - double Eta; - bool precip_baseterm_only; - double precipfactor; - double precipexponent; - std::string mineral_name; - std::string chemapp_name; - int mineral_number; // cp_vec idx of mineral - int water_number; // cp_vec idx of mineral - double Temperature; - double Pressure; - double OmegaThreshhold; - double MinKinRateCoeff; - bool ExplicitMinKinRateCoeff; + // SB speed-up flags + int typeflag_monod; /* set to 1 if reaction is monod type */ + int typeflag_exchange; /* set to 1 if reaction is exchange type */ + int typeflag_exchange_linear; /* set to 1 if reaction is linear exchange type */ + int typeflag_exchange_langmuir; /* set to 1 if reaction is langmuir exchange type */ + int typeflag_exchange_freundlich; /* set to 1 if reaction is freundlich exchange type */ + int typeflag_napldissolution; /* set to 1 if reaction is NAPL dissolution */ + int typeflag_iso_fract; /* set to 1 if reaction is isotope fractionation */ + int typeflag_mineralkinetics; /* set to 1 if reaction is mineral kinetics */ + int typeflag_gasdissolution; + + // CB new parallel computation data structure, replaces double current_Csat; + std::vector Current_Csat; /* initial interfacial area, interfacial area of last iteration */ + // Mineral kinetics data + std::vector mechvec; // stores individual mechanisms of this reaction + std::vector minSpeciesIdx; // stores cp vector index of mineral species + std::vector + Am; // initial specific reactive mineral surface area m²/m³ aquifer = Am * rho_b = m²/kg * kg/m³aquifer + std::vector Km; // Equilibrium constant + std::vector Cminini; // initial mineral concentration + int number_Mech; // Number of Mechanism terms */ + bool Km_uniform; + bool Km_CHEMAPP; + bool Km_HKF; + bool scale_rate; + bool lagneau; + + double Km_default; + bool Am_constant; + int Am_model; + double Am_ini; // initial mineral Surface area + double Theta; + double Eta; + bool precip_baseterm_only; + double precipfactor; + double precipexponent; + std::string mineral_name; + std::string chemapp_name; + int mineral_number; // cp_vec idx of mineral + int water_number; // cp_vec idx of mineral + double Temperature; + double Pressure; + double OmegaThreshhold; + double MinKinRateCoeff; + bool ExplicitMinKinRateCoeff; /* Methods */ /** @@ -241,37 +239,35 @@ class CKinReact * @param unique_name the name of the project to access the right geometric entities * @return true (in every case) ToDo */ - bool Read(std::ifstream* in, - const GEOLIB::GEOObjects& geo_obj, - const std::string& unique_name); + bool Read(std::ifstream* in, const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name); - void Write(std::ofstream*); /* Class Write Function */ + void Write(std::ofstream*); /* Class Write Function */ void ReadReactionEquation(std::string); /* Read function for chemical equations */ int CheckReactionDataConsistency(void); /* check data set */ - void TestWrite(void); // test output function + void TestWrite(void); // test output function // CB isotope fractionation + higher order terms double Monod(double, double, double, double); double Inhibition(double, double); - double BacteriaGrowth ( int r, double *c, double sumX, int exclude, long node ); - int GetPhase(int ); + double BacteriaGrowth(int r, double* c, double sumX, int exclude, long node); + int GetPhase(int); // double GetPorosity( int comp, long index ); // CB replaced by - double GetReferenceVolume( int comp, long index ); - double GetDensity( int comp, long index ); - double GetNodePoreVelocity( long node); - double GetNodeDarcyVelocity( long node); + double GetReferenceVolume(int comp, long index); + double GetDensity(int comp, long index); + double GetNodePoreVelocity(long node); + double GetNodeDarcyVelocity(long node); double GetPhaseVolumeAtNode(long node, double theta, int phase); - double GetSaturation(long node, int theta, int phase); - double GetMaxSolubility(long node, double density); - double EffectiveYield(long node); - // MinKin - double Omega(double *c, int node); - //void IonicStrength(int nnode, int ncomp); - //void ActvityCoefficients(int nnode, int ncomp); - //double Arrhenius(double, double, double); - double MinRate(double *c, int node, double dt, double Om); - double MinRateConstant(double *c, int node, double disso); + double GetSaturation(long node, int theta, int phase); + double GetMaxSolubility(long node, double density); + double EffectiveYield(long node); + // MinKin + double Omega(double* c, int node); + // void IonicStrength(int nnode, int ncomp); + // void ActvityCoefficients(int nnode, int ncomp); + // double Arrhenius(double, double, double); + double MinRate(double* c, int node, double dt, double Om); + double MinRateConstant(double* c, int node, double disso); }; //#ds Class for blob properties @@ -287,15 +283,9 @@ class CKinBlob * @param unique_name the name of the project to access the right geometric entities * @return true (always) TODO */ - bool Read(std::ifstream* in, - const GEOLIB::GEOObjects& geo_obj, - const std::string& unique_name); - void Write(std::ostream & out) const; - const std::vector& getBlobGeoID() - { - return BlobGeoID; - } - + bool Read(std::ifstream* in, const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name); + void Write(std::ostream& out) const; + const std::vector& getBlobGeoID() { return BlobGeoID; } std::string name; double d50; double Sh_factor; @@ -306,45 +296,46 @@ class CKinBlob double Volume; double Masstransfer_k; double current_Interfacial_area; - std::vector Masstransfer_K; /* CB: current Mass transfer coefficient, now saved in node vector*/ + std::vector Masstransfer_K; /* CB: current Mass transfer coefficient, now saved in node vector*/ std::vector Area_Value; std::vector Interfacial_area; std::vector BlobGeoType; std::vector BlobGeoName; - //New-Sherwood-Number - int shidx; - double NContent_expo; - double WContent_expo; - double Pe_expo; - double D50_expo; - double Poro_expo ; - double Delta_expo; - double UI_expo ; - double NContent_ini_expo ; - double NContent_res_expo ; - double GSR_expo ; - double Length_expo ; - double Tort_expo ; - double Pfannkuch_constant ; - double beta_4; - double one_three, two_three, four_nine, fife_nine, elev_nine, fife_three; - double grain_var; - double grain_expo; - double dM; - double dS; - double UI; - double Ui_expo; - double NCont_ini; - double NCont_res; - double NCont_Sh1; - double NCont_Sh2; - double GSR; - double Tort; - double Length; - bool modSherwood ; - bool Sherwood_model ; - - bool gas_dissolution_flag; + // New-Sherwood-Number + int shidx; + double NContent_expo; + double WContent_expo; + double Pe_expo; + double D50_expo; + double Poro_expo; + double Delta_expo; + double UI_expo; + double NContent_ini_expo; + double NContent_res_expo; + double GSR_expo; + double Length_expo; + double Tort_expo; + double Pfannkuch_constant; + double beta_4; + double one_three, two_three, four_nine, fife_nine, elev_nine, fife_three; + double grain_var; + double grain_expo; + double dM; + double dS; + double UI; + double Ui_expo; + double NCont_ini; + double NCont_res; + double NCont_Sh1; + double NCont_Sh2; + double GSR; + double Tort; + double Length; + bool modSherwood; + bool Sherwood_model; + + bool gas_dissolution_flag; + private: std::vector BlobGeoID; }; @@ -364,27 +355,27 @@ class CKinReactData int NumberFreundlich; int NumberMonod; int NumberNAPLdissolution; - int NumberMineralkinetics; + int NumberMineralkinetics; - // CB _drmc_ - int NumberMicrobeData; + // CB _drmc_ + int NumberMicrobeData; - clock_t cpu_time_krc; + clock_t cpu_time_krc; - // biodeg data - double maxBacteriaCapacity; - std::vector is_a_bacterium; - double minBactConcentration; - int minConcentrationMode; - double minConcentrationThreshhold; - double minConcentrationSet; + // biodeg data + double maxBacteriaCapacity; + std::vector is_a_bacterium; + double minBactConcentration; + int minConcentrationMode; + double minConcentrationThreshhold; + double minConcentrationSet; // vector is_a_bacterium2; // short version // exchange data int maxSurfaces; std::vector exSurface; // output flag bool testoutput; - //index vector for shortening vectors c in kinetic calculations (omitting nonreacting species) + // index vector for shortening vectors c in kinetic calculations (omitting nonreacting species) // vector sp_index; // int kr_active_species; // std::vector sp_pcsind; // HS @@ -395,47 +386,48 @@ class CKinReactData std::vector NoReactGeoID; std::vector NoReactGeoType; std::vector is_a_CCBC; - std::vector AllowReactGeoName; - std::vector AllowReactGeoID; - std::vector AllowReactGeoType; + std::vector AllowReactGeoName; + std::vector AllowReactGeoID; + std::vector AllowReactGeoType; // CB ReactDeact no reaction switch - bool ReactDeactFlag; // method flag - int ReactDeactPlotFlag; // flag for tecplot plots of flags each timestep - double ReactDeactEpsilon; // treshhold - double ReactDeactCThresh; - std::vector ReactDeact; // flags for individual nodes - std::vector React_dCdT; // Sum of reaction rates for individual nodes - // node indices of local neighborhood around individual nodes + bool ReactDeactFlag; // method flag + int ReactDeactPlotFlag; // flag for tecplot plots of flags each timestep + double ReactDeactEpsilon; // treshhold + double ReactDeactCThresh; + std::vector ReactDeact; // flags for individual nodes + std::vector React_dCdT; // Sum of reaction rates for individual nodes + // node indices of local neighborhood around individual nodes std::vector > ReactNeighborhood; int ReactDeactMode; - bool ReactDeactRelative; - - bool copy_concentrations; //SB 01.2011 Flag for copying concentrations in radial models to save reaction simulation time - std::vector copy_nodes; //SB 01.2011 - bool radial ; // default case - bool batch ; - bool TwoDinThreeD ; - - bool scale_dcdt; // stabilization for ODE solver in derivs, sclae dcdt vector - bool lagneau ; // special configuration of minrate and porosity update for Lagneaubenchmark - bool sortnodes; - long *substeps; - long *noderanks; - double OmegaThresh; - long noototnodes; - long noocalcnodes; + bool ReactDeactRelative; + + bool copy_concentrations; // SB 01.2011 Flag for copying concentrations in radial models to save reaction simulation + // time + std::vector copy_nodes; // SB 01.2011 + bool radial; // default case + bool batch; + bool TwoDinThreeD; + + bool scale_dcdt; // stabilization for ODE solver in derivs, sclae dcdt vector + bool lagneau; // special configuration of minrate and porosity update for Lagneaubenchmark + bool sortnodes; + long* substeps; + long* noderanks; + double OmegaThresh; + long noototnodes; + long noocalcnodes; bool debugoutflag; std::string debugoutfilename; - std::string c_dumpfilename; + std::string c_dumpfilename; std::ofstream debugoutstr; - std::ofstream c_dump; + std::ofstream c_dump; std::vector node_foc; - std::vector IonicStrengths; - std::vector > ActivityCoefficients; // For Mineral Dissolution, store gammas in 1 data object - int activity_model; + std::vector IonicStrengths; + std::vector > ActivityCoefficients; // For Mineral Dissolution, store gammas in 1 data object + int activity_model; /* Methods */ CKinReactData(void); @@ -449,42 +441,40 @@ class CKinReactData * @param unique_name the name of the project to access the right geometric entities * @return */ - bool Read(std::ifstream* in, - const GEOLIB::GEOObjects& geo_obj, - const std::string& unique_name); - void Write(std::ofstream*); /* Class Write Function */ + bool Read(std::ifstream* in, const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name); + void Write(std::ofstream*); /* Class Write Function */ void TestWrite(void); void ExecuteKinReact(void); - void Biodegradation( double *m_Conc, long node, double eps, double hmin, double *usedtneu, int *nok, int *nbad, int tt, int tsteps); + void Biodegradation(double* m_Conc, long node, double eps, double hmin, double* usedtneu, int* nok, int* nbad, + int tt, int tsteps); // CB ReactDeact - void ReactionDeactivation(long); // Sets nodes active / inactive + void ReactionDeactivation(long); // Sets nodes active / inactive void ReactDeactPlotFlagsToTec(); void ReactDeactSetOldReactionTerms(long nonodes); - void SortIterations ( long *iterations, long *indexes, long len); + void SortIterations(long* iterations, long* indexes, long len); - void CopyConcentrations(void); //SB 01.2011 + void CopyConcentrations(void); // SB 01.2011 double** concentrationmatrix; void Aromaticum(long nonodes); - // CB 12/09 new data structures for parallel computation - void NAPLDissolutionPreprocessing(); - void PreprocessMinKin(); - void PostprocessMinKin(); - void Calc_linearized_rates(double *m_Conc, long Number_of_Components,double deltaT, long node); - -// CB _drmc_ - void PreprocessMicrobe_drmc_(double steplength); + // CB 12/09 new data structures for parallel computation + void NAPLDissolutionPreprocessing(); + void PreprocessMinKin(); + void PostprocessMinKin(); + void Calc_linearized_rates(double* m_Conc, long Number_of_Components, double deltaT, long node); + // CB _drmc_ + void PreprocessMicrobe_drmc_(double steplength); }; -extern std::vector KinReact_vector; // declare extern instance of class CKinReact - // declare extern instance of class CKinReact -extern std::vector KinReactData_vector; -extern std::vector KinBlob_vector; // declare extern instance of class Blob +extern std::vector KinReact_vector; // declare extern instance of class CKinReact +// declare extern instance of class CKinReact +extern std::vector KinReactData_vector; +extern std::vector KinBlob_vector; // declare extern instance of class Blob // CB _drmc_ -extern std::vector MicrobeData_vector; // declare extern instance of class Blob +extern std::vector MicrobeData_vector; // declare extern instance of class Blob /** * read file for kinetic reaction @@ -493,9 +483,7 @@ extern std::vector MicrobeData_vector; // declare extern insta * @param unique_name unique name to access the geometric entities in geo_obj * @return false if file can not be opened, else true */ -bool KRRead(const std::string& file_base_name, - const GEOLIB::GEOObjects& geo_obj, - const std::string& unique_name); +bool KRRead(const std::string& file_base_name, const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name); extern bool KRWrite(std::string const&); extern void KRCDelete(void); @@ -514,11 +502,11 @@ void KRConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) */ void KBlobConfig(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name); -extern void KBlobCheck(void); /* check Blob-Object for input errors */ -extern bool KNaplDissCheck(void); /* CB check if NAPL dissolution is modeled */ -extern void KNaplCalcDensity(void); /* CB check if NAPL dissolution is modeled */ -extern double CalcNAPLDens(int node); //CB 01/08 -extern void CalcNewNAPLSat(); //CB 01/08 +extern void KBlobCheck(void); /* check Blob-Object for input errors */ +extern bool KNaplDissCheck(void); /* CB check if NAPL dissolution is modeled */ +extern void KNaplCalcDensity(void); /* CB check if NAPL dissolution is modeled */ +extern double CalcNAPLDens(int node); // CB 01/08 +extern void CalcNewNAPLSat(); // CB 01/08 extern void CalcNAPLCompMasses(); extern void CalcNewPhasePressure(); extern bool KMinKinCheck(void); @@ -528,30 +516,26 @@ void MicrobeConfig(void); /* Externe Subroutine-Deklarationen fuer Bulirsch-Stoer Gleichungsl�ser */ -extern bool odeint(double ystart[], int nvar, double x1, double x2, double eps, double h1, - double hmin, double *nexth, int *nok, int *nbad, - void (*derivs)(double, double [], double [], int, long, double), - bool (*stifbs)(double [], double [], int, double *, double, double, double [], - double *, double *, void (*)(double, double [], double [], int, long, double), long), - bool (*rkqs)(double [], double [], int, double *, double , double , double [], - double *, double *, void (*)(double , double [], double [], int, long, double), long), - long, int); - -extern bool stifbs(double y[], double dydx[], int nv, double *xx, double htry, double eps, - double yscal[], double *hdid, double *hnext, - void (*derivs)(double, double [], double [], int, long, double), long); +extern bool odeint(double ystart[], int nvar, double x1, double x2, double eps, double h1, double hmin, double* nexth, + int* nok, int* nbad, void (*derivs)(double, double[], double[], int, long, double), + bool (*stifbs)(double[], double[], int, double*, double, double, double[], double*, double*, + void (*)(double, double[], double[], int, long, double), long), + bool (*rkqs)(double[], double[], int, double*, double, double, double[], double*, double*, + void (*)(double, double[], double[], int, long, double), long), + long, int); +extern bool stifbs(double y[], double dydx[], int nv, double* xx, double htry, double eps, double yscal[], double* hdid, + double* hnext, void (*derivs)(double, double[], double[], int, long, double), long); -extern bool rkqs(double y[], double dydx[], int n, double *x, double htry, double eps, - double yscal[], double *hdid, double *hnext, - void (*derivs)(double , double [], double [], int, long, double), long); +extern bool rkqs(double y[], double dydx[], int n, double* x, double htry, double eps, double yscal[], double* hdid, + double* hnext, void (*derivs)(double, double[], double[], int, long, double), long); extern double* dvector(long nl, long nh); extern void free_dvector(double* v, long nl, long nh); /* interne Deklarationen */ -extern void ExecuteKineticReactions(); -extern double TBCGetExchange(long node, int sp); -extern void derivs(double x, double y[], double dydx[], int n, long node, double); -extern void jacobn(double x, double y[], double dfdx[], double **dfdy, int n, long node); +extern void ExecuteKineticReactions(); +extern double TBCGetExchange(long node, int sp); +extern void derivs(double x, double y[], double dydx[], int n, long node, double); +extern void jacobn(double x, double y[], double dfdx[], double** dfdy, int n, long node); #endif diff --git a/FEM/rf_mfp_new.cpp b/FEM/rf_mfp_new.cpp index 9fc0bdc52..72ae8eb55 100644 --- a/FEM/rf_mfp_new.cpp +++ b/FEM/rf_mfp_new.cpp @@ -23,7 +23,7 @@ // FEM-Makros //#include "mathlib.h" -#include "eos.h" //NB +#include "eos.h" //NB // GeoSys-GeoLib #include "files0.h" // GeoSys-FEMLib @@ -31,11 +31,11 @@ // #include "rf_mfp_new.h" //#include "rf_mmp_new.h" -extern double InterpolValue(long number,int ndx,double r,double s,double t); +extern double InterpolValue(long number, int ndx, double r, double s, double t); //#include "rf_pcs.h" #include "rfmat_cp.h" -extern double GetCurveValue(int,int,double,int*); -#include "tools.h" //GetLineFromFile +extern double GetCurveValue(int, int, double, int*); +#include "tools.h" //GetLineFromFile // KG44 used for GEMS part #ifdef GEM_REACT #include "rf_REACT_GEM.h" @@ -44,17 +44,17 @@ extern double GetCurveValue(int,int,double,int*); #include "PhysicalConstant.h" /* Umrechnungen SI - Amerikanisches System */ -//WW #include "steam67.h" +// WW #include "steam67.h" #define PSI2PA 6895. #define PA2PSI 1.4503263234227701232777374909355e-4 -double gravity_constant = 9.81; //TEST for FEBEX OK 9.81; +double gravity_constant = 9.81; // TEST for FEBEX OK 9.81; using namespace PhysicalConstant; using namespace std; //========================================================================== -std::vectormfp_vector; +std::vector mfp_vector; /************************************************************************** FEMLib-Method: @@ -62,8 +62,7 @@ std::vectormfp_vector; Programing: 08/2004 OK Implementation **************************************************************************/ -CFluidProperties::CFluidProperties() : - name ("WATER") +CFluidProperties::CFluidProperties() : name("WATER") { phase = 0; // Density @@ -74,14 +73,14 @@ CFluidProperties::CFluidProperties() : drho_dC = 0.; // Viscosity viscosity_model = 1; - viscosity_T_shift =0.0; + viscosity_T_shift = 0.0; my_0 = 1e-3; dmy_dp = 0.; dmy_dT = 0.; dmy_dC = 0.; // Thermal properties heat_capacity_model = 1; - specific_heat_capacity = 4680.; //CMCD we should give this as SHC not HC GeoSys 4 9/2004 + specific_heat_capacity = 4680.; // CMCD we should give this as SHC not HC GeoSys 4 9/2004 heat_conductivity_model = 1; heat_conductivity = 0.6; // Electrical properties @@ -94,9 +93,9 @@ CFluidProperties::CFluidProperties() : C_0 = 0.; Z = 1.; cal_gravity = true; - drho_dT_unsaturated = false; //considering fluid expansion due to temperature in the unsaturated case? (Richards) + drho_dT_unsaturated = false; // considering fluid expansion due to temperature in the unsaturated case? (Richards) // Data - mode = 0; // Gauss point values + mode = 0; // Gauss point values Fem_Ele_Std = NULL; // WW molar_mass = MolarMass::Air; @@ -106,7 +105,7 @@ CFluidProperties::CFluidProperties() : beta_T = 0.0; cmpN = 0; -#ifdef MFP_TEST //WW +#ifdef MFP_TEST // WW scatter_data = NULL; #endif } @@ -119,12 +118,12 @@ CFluidProperties::CFluidProperties() : **************************************************************************/ CFluidProperties::~CFluidProperties(void) { - for (int i = 0; i < (int)component_vector.size(); i++ ) + for (int i = 0; i < (int)component_vector.size(); i++) component_vector[i] = NULL; component_vector.clear(); #ifdef MFP_TEST - if(scatter_data) //WW + if (scatter_data) // WW delete scatter_data; #endif } @@ -145,7 +144,7 @@ std::ios::pos_type CFluidProperties::Read(std::ifstream* mfp_file) std::string hash("#"); std::ios::pos_type position; std::string sub_string; - //WW bool new_subkeyword = false; + // WW bool new_subkeyword = false; std::string dollar("$"); std::string delimiter_type(":"); std::stringstream in; @@ -153,84 +152,84 @@ std::ios::pos_type CFluidProperties::Read(std::ifstream* mfp_file) // Schleife ueber alle Phasen bzw. Komponenten while (!new_keyword) { - //WW new_subkeyword = false; + // WW new_subkeyword = false; position = mfp_file->tellg(); - //SB mfp_file->getline(buffer,MAX_ZEILE); - //SB line_string = buffer; + // SB mfp_file->getline(buffer,MAX_ZEILE); + // SB line_string = buffer; line_string = GetLineFromFile1(mfp_file); - if(line_string.size() < 1) + if (line_string.size() < 1) break; - if(line_string.find(hash) != string::npos) + if (line_string.find(hash) != string::npos) { new_keyword = true; break; } //.................................................................... // subkeyword found - if(line_string.find("$FLUID_TYPE") != string::npos) + if (line_string.find("$FLUID_TYPE") != string::npos) { in.str(GetLineFromFile1(mfp_file)); - in >> name; //sub_line + in >> name; // sub_line in.clear(); continue; } //.................................................................... // AKS - if(line_string.find("$COMPONENTS") != string::npos) + if (line_string.find("$COMPONENTS") != string::npos) { in.str(GetLineFromFile1(mfp_file)); - in >> cmpN >> cmpNm1 >> cmpNm2 >> cmpNm3 >> cmpNm4; //get up to four component + in >> cmpN >> cmpNm1 >> cmpNm2 >> cmpNm3 >> cmpNm4; // get up to four component in.clear(); continue; } //.................................................................... // NB 4.8.01 - if(line_string.find("$FLUID_NAME") != string::npos) + if (line_string.find("$FLUID_NAME") != string::npos) { in.str(GetLineFromFile1(mfp_file)); - in >> fluid_name; //sub_line - therm_prop (fluid_name); //NB 4.9.05 (getting thermophysical constants of specified substance) - //TODO: add choosing of property functions in input file (NB) + in >> fluid_name; // sub_line + therm_prop(fluid_name); // NB 4.9.05 (getting thermophysical constants of specified substance) + // TODO: add choosing of property functions in input file (NB) in.clear(); continue; } //.................................................................... - if(line_string.find("$EOS_TYPE") != string::npos) + if (line_string.find("$EOS_TYPE") != string::npos) { in.str(GetLineFromFile1(mfp_file)); - in >> eos_name; //sub_line + in >> eos_name; // sub_line in.clear(); continue; } //.................................................................... // NB Oct-2009 - if(line_string.find("$COMPRESSIBILITY") != string::npos) + if (line_string.find("$COMPRESSIBILITY") != string::npos) { in.str(GetLineFromFile1(mfp_file)); - in >> compressibility_model_pressure; //sub_line 1 for first phase - if(compressibility_model_pressure == 15)// components constant density + in >> compressibility_model_pressure; // sub_line 1 for first phase + if (compressibility_model_pressure == 15) // components constant density { - if(eos_name == "CONSTANT") - in >> beta_p[0] >> beta_p[1] >> beta_p[2] >> beta_p[3]; + if (eos_name == "CONSTANT") + in >> beta_p[0] >> beta_p[1] >> beta_p[2] >> beta_p[3]; } else - in >> compressibility_pressure; //sub_line 1 + in >> compressibility_pressure; // sub_line 1 in.clear(); in.str(GetLineFromFile1(mfp_file)); - in >> compressibility_model_temperature; //sub_line 2 for second phase - if(compressibility_model_temperature == 15)// components constant density + in >> compressibility_model_temperature; // sub_line 2 for second phase + if (compressibility_model_temperature == 15) // components constant density { - if(eos_name == "CONSTANT") - in >> alpha_T[0] >> alpha_T[1] >> alpha_T[2] >> alpha_T[3]; + if (eos_name == "CONSTANT") + in >> alpha_T[0] >> alpha_T[1] >> alpha_T[2] >> alpha_T[3]; } else - in >> compressibility_temperature; //sub_line 2 + in >> compressibility_temperature; // sub_line 2 in.clear(); in.str(GetLineFromFile1(mfp_file)); - in >> solutal_expansivity_model; //sub_line 2 for second phase - in >> solutal_expansivity; //sub_line 2 + in >> solutal_expansivity_model; // sub_line 2 for second phase + in >> solutal_expansivity; // sub_line 2 in.clear(); // available models see CFluidProperties::drhodP and CFluidProperties::drhodT @@ -244,73 +243,75 @@ std::ios::pos_type CFluidProperties::Read(std::ifstream* mfp_file) continue; } //.................................................................... - if(line_string.find("$JTC") != string::npos) + if (line_string.find("$JTC") != string::npos) { in.str(GetLineFromFile1(mfp_file)); - in >> mu_JT; //sub_line + in >> mu_JT; // sub_line in.clear(); continue; } //.................................................................... // subkeyword found - if(line_string.find("$DAT_TYPE") != string::npos) + if (line_string.find("$DAT_TYPE") != string::npos) { in.str(GetLineFromFile1(mfp_file)); - in >> name; //sub_line + in >> name; // sub_line in.clear(); continue; } - //YD/WW subkeyword found - if(line_string.find("$NON_GRAVITY") != string::npos) + // YD/WW subkeyword found + if (line_string.find("$NON_GRAVITY") != string::npos) { cal_gravity = false; continue; } - if(line_string.find("$DRHO_DT_UNSATURATED") != string::npos) //JM considering drho/dT for the unsaturated case (richards)? + if (line_string.find("$DRHO_DT_UNSATURATED") + != string::npos) // JM considering drho/dT for the unsaturated case (richards)? { - drho_dT_unsaturated = true; //if keyword found, drho/dT will be considered for unsaturated case (richards) + drho_dT_unsaturated = true; // if keyword found, drho/dT will be considered for unsaturated case (richards) continue; } //.................................................................... // subkeyword found - if(line_string.find("$DENSITY") != string::npos) + if (line_string.find("$DENSITY") != string::npos) { - //WW new_subkeyword = false; + // WW new_subkeyword = false; in.str(GetLineFromFile1(mfp_file)); in >> density_model; // TF - _rho_fct_name is only used for writing it back to the file - if(density_model == 0) // rho = f(x) - { // JOD 2014-11-10 + if (density_model == 0) // rho = f(x) + { // JOD 2014-11-10 in >> density_curve_number; density_pcs_name_vector.push_back("TEMPERATURE1"); } - if(density_model == 1) // rho = const + if (density_model == 1) // rho = const in >> rho_0; - if(density_model == 2) // rho(p) = rho_0*(1+beta_p*(p-p_0)) + if (density_model == 2) // rho(p) = rho_0*(1+beta_p*(p-p_0)) { in >> rho_0; in >> p_0; in >> drho_dp; density_pcs_name_vector.push_back("PRESSURE1"); } - if(density_model == 3) // rho(C) = rho_0*(1+beta_C*(C-C_0)) + if (density_model == 3) // rho(C) = rho_0*(1+beta_C*(C-C_0)) { in >> rho_0; in >> C_0; in >> drho_dC; - density_pcs_name_vector.push_back("CONCENTRATION1"); // JOD 2014-11-10, consistent with output DELTA_CONCENTRATION1 - //density_pcs_name_vector.push_back("Isochlor"); // PCH + density_pcs_name_vector.push_back( + "CONCENTRATION1"); // JOD 2014-11-10, consistent with output DELTA_CONCENTRATION1 + // density_pcs_name_vector.push_back("Isochlor"); // PCH } - if(density_model == 4) // rho(T) = rho_0*(1+beta_T*(T-T_0)) + if (density_model == 4) // rho(T) = rho_0*(1+beta_T*(T-T_0)) { in >> rho_0; in >> T_0; in >> drho_dT; density_pcs_name_vector.push_back("TEMPERATURE1"); } - if(density_model == 5) // rho(C,T) = rho_0*(1+beta_C*(C-C_0)+beta_T*(T-T_0)) + if (density_model == 5) // rho(C,T) = rho_0*(1+beta_C*(C-C_0)+beta_T*(T-T_0)) { in >> rho_0; in >> C_0; @@ -320,7 +321,7 @@ std::ios::pos_type CFluidProperties::Read(std::ifstream* mfp_file) density_pcs_name_vector.push_back("CONCENTRATION1"); density_pcs_name_vector.push_back("TEMPERATURE1"); } - if(density_model == 6 || density_model == 14) // rho(p,T) = rho_0*(1+beta_p*(p-p_0)+beta_T*(T-T_0)) + if (density_model == 6 || density_model == 14) // rho(p,T) = rho_0*(1+beta_p*(p-p_0)+beta_T*(T-T_0)) { in >> rho_0; in >> p_0; @@ -330,37 +331,38 @@ std::ios::pos_type CFluidProperties::Read(std::ifstream* mfp_file) density_pcs_name_vector.push_back("PRESSURE1"); density_pcs_name_vector.push_back("TEMPERATURE1"); } - if(density_model == 7) // rho(p,p_v,T) + if (density_model == 7) // rho(p,p_v,T) { // no input data required } - if(density_model == 8) // rho(p,T,C) + if (density_model == 8) // rho(p,T,C) { in >> C_0; density_pcs_name_vector.push_back("PRESSURE1"); density_pcs_name_vector.push_back("TEMPERATURE1"); } - if(density_model == 9) //WW + if (density_model == 9) // WW // Molar mass in >> molar_mass; - if((density_model == 10) //NB 4.8.01 read density from a rho-P-T table - || (density_model == 11) //NB 4.9.05 Peng-Robinson Equation of State - || (density_model == 12) //NB 4.9.05 Redlich-Kwong Equation of State - || (density_model == 13)) //NB JUN 09 Fundamental equation + if ((density_model == 10) // NB 4.8.01 read density from a rho-P-T table + || (density_model == 11) // NB 4.9.05 Peng-Robinson Equation of State + || (density_model == 12) // NB 4.9.05 Redlich-Kwong Equation of State + || (density_model == 13)) // NB JUN 09 Fundamental equation { - std::string arg1,arg2,arg3; - in >> arg1 >> arg2 >> arg3; //get up to three arguments for density model + std::string arg1, arg2, arg3; + in >> arg1 >> arg2 >> arg3; // get up to three arguments for density model if (arg1.length() > 0) { - if (isdigit(arg1[0]) != 0) // first argument is reference temperature - { - T_0 = atof(arg1.c_str()); - arg1 = arg2; - arg2 = arg3; + if (isdigit(arg1[0]) != 0) // first argument is reference temperature + { + T_0 = atof(arg1.c_str()); + arg1 = arg2; + arg2 = arg3; + } } - } - else T_0=0.0; + else + T_0 = 0.0; if (arg1.length() == 0) // if no arguments are given use standard { @@ -374,24 +376,25 @@ std::ios::pos_type CFluidProperties::Read(std::ifstream* mfp_file) if (T_Process) density_pcs_name_vector.push_back(arg2); } - //AKS - if(density_model == 15)// components constant density + // AKS + if (density_model == 15) // components constant density { - if(eos_name == "CONSTANT") - in >> rho[0] >> rho[1] >> rho[2] >> rho[3]; + if (eos_name == "CONSTANT") + in >> rho[0] >> rho[1] >> rho[2] >> rho[3]; } - if(density_model == 18) // BG, NB calculated node densities from the phase transition model + if (density_model == 18) // BG, NB calculated node densities from the phase transition model { } /// Density model no. 19: Extracts fluid densities from GEM3K calculations /// The densites depend on the thermodynamic data base (including pressure and temperature corrections) /// in addition various gas/fluid models (&EOS) are defined in GEMS3K - if(density_model == 19) // KG44 get node densities from GEMS calculations + if (density_model == 19) // KG44 get node densities from GEMS calculations { } - if (density_model == 20) // rho(C) = rho (p, T)*(1+beta_C*(C-C_0)) for water, range p < 100 MPa, 0 <= T <= 350 °C Magri GFZ thesis - { // JOD 2014-11-10 + if (density_model == 20) // rho(C) = rho (p, T)*(1+beta_C*(C-C_0)) for water, range p < 100 MPa, 0 <= T <= + // 350 °C Magri GFZ thesis + { // JOD 2014-11-10 in >> C_0; in >> drho_dC; density_pcs_name_vector.push_back("PRESSURE1"); @@ -400,7 +403,8 @@ std::ios::pos_type CFluidProperties::Read(std::ifstream* mfp_file) } if (density_model == 26) // && pcs_vector[0]->getProcessType() != FiniteElement::TNEQ) { - std::cout << "Warning: This density model requires two components and their molar masses defined in the mcp file!\n"; + std::cout << "Warning: This density model requires two components and their molar masses defined in " + "the mcp file!\n"; density_pcs_name_vector.push_back("PRESSURE1"); density_pcs_name_vector.push_back("TEMPERATURE1"); density_pcs_name_vector.push_back("CONCENTRATION1"); @@ -409,7 +413,7 @@ std::ios::pos_type CFluidProperties::Read(std::ifstream* mfp_file) in.clear(); continue; } - if(line_string.find("$TEMPERATURE") != string::npos) // subkeyword found 11/2010, BG, NB, DL, SB + if (line_string.find("$TEMPERATURE") != string::npos) // subkeyword found 11/2010, BG, NB, DL, SB { in.str(GetLineFromFile1(mfp_file)); in >> T_0 >> T_0; @@ -418,56 +422,57 @@ std::ios::pos_type CFluidProperties::Read(std::ifstream* mfp_file) } //.................................................................... // subkeyword found - if(line_string.find("$VISCOSITY") != string::npos) + if (line_string.find("$VISCOSITY") != string::npos) { in.str(GetLineFromFile1(mfp_file)); in >> viscosity_model; // TF 11/2011 - used only in read- and write-method if (viscosity_model == 0) // my = fct(x) in >> viscosity_curve_number; // JOD 2014-11-10 -// in >> _my_fct_name; - if(viscosity_model == 1) // my = const + // in >> _my_fct_name; + if (viscosity_model == 1) // my = const in >> my_0; - if(viscosity_model == 2) // my(p) = my_0*(1+gamma_p*(p-p_0)) + if (viscosity_model == 2) // my(p) = my_0*(1+gamma_p*(p-p_0)) { in >> my_0; in >> p_0; in >> dmy_dp; viscosity_pcs_name_vector.push_back("PRESSURE1"); } - if(viscosity_model == 3) // my(T), Yaws et al. (1976) - { // optional: read reference temperature for viscosity model - std::string arg1; - in >> arg1; //get one optional argument - if (arg1.length() > 0) - if (isdigit(arg1[0]) != 0) // first argument is temperature shift for viscosity, in order to allow the use of deg Celsius - viscosity_T_shift = atof(arg1.c_str()); - viscosity_pcs_name_vector.push_back("PRESSURE1"); //JM dummy wird benoetigt! - //OK4704 + if (viscosity_model == 3) // my(T), Yaws et al. (1976) + { // optional: read reference temperature for viscosity model + std::string arg1; + in >> arg1; // get one optional argument + if (arg1.length() > 0) + if (isdigit(arg1[0]) != 0) // first argument is temperature shift for viscosity, in order to allow + // the use of deg Celsius + viscosity_T_shift = atof(arg1.c_str()); + viscosity_pcs_name_vector.push_back("PRESSURE1"); // JM dummy wird benoetigt! + // OK4704 viscosity_pcs_name_vector.push_back("TEMPERATURE1"); - } - if(viscosity_model == 4) // my(T), ??? + } + if (viscosity_model == 4) // my(T), ??? { - viscosity_pcs_name_vector.push_back("PRESSURE1"); //JM dummy wird benoetigt! - viscosity_pcs_name_vector.push_back("TEMPERATURE1"); // added by CB + viscosity_pcs_name_vector.push_back("PRESSURE1"); // JM dummy wird benoetigt! + viscosity_pcs_name_vector.push_back("TEMPERATURE1"); // added by CB } - if(viscosity_model == 5) // my(p,T), Reichenberg (1971) + if (viscosity_model == 5) // my(p,T), Reichenberg (1971) { } - if(viscosity_model == 6) // my(C,T), + if (viscosity_model == 6) // my(C,T), { } - if(viscosity_model == 7) // my(p,T,C) + if (viscosity_model == 7) // my(p,T,C) { in >> C_0; viscosity_pcs_name_vector.push_back("PRESSURE1"); viscosity_pcs_name_vector.push_back("TEMPERATURE1"); } - if(viscosity_model == 9) // my(rho,T) + if (viscosity_model == 9) // my(rho,T) { - std::string arg1,arg2; - in >> arg1 >> arg2; //get up to three arguments for density model + std::string arg1, arg2; + in >> arg1 >> arg2; // get up to three arguments for density model if (arg1.length() == 0) // if no arguments are given use standard { @@ -482,23 +487,24 @@ std::ios::pos_type CFluidProperties::Read(std::ifstream* mfp_file) if (T_Process) viscosity_pcs_name_vector.push_back(arg2); } - //AKS - if(density_model == 15)// components constant viscosity + // AKS + if (density_model == 15) // components constant viscosity { - if(eos_name == "CONSTANT") - in >> mu[0] >> mu[1] >> mu[2] >> mu[3]; + if (eos_name == "CONSTANT") + in >> mu[0] >> mu[1] >> mu[2] >> mu[3]; } - if(viscosity_model == 18) // BG, NB calculated node viscosities from the phase transition model + if (viscosity_model == 18) // BG, NB calculated node viscosities from the phase transition model { } /// Viscosity model no. 19: Extracts viscosities from GEM3K calculations (not yet implemented) - if(viscosity_model == 19) // KG44 extract viscosity from GEMS + if (viscosity_model == 19) // KG44 extract viscosity from GEMS { } if (viscosity_model == 26) // && pcs_vector[0]->getProcessType() != FiniteElement::TNEQ) { - std::cout << "Warning: This viscosity model requires two components and their molar masses defined in the mcp file!\n"; + std::cout << "Warning: This viscosity model requires two components and their molar masses defined in " + "the mcp file!\n"; viscosity_pcs_name_vector.push_back("PRESSURE1"); viscosity_pcs_name_vector.push_back("TEMPERATURE1"); viscosity_pcs_name_vector.push_back("CONCENTRATION1"); @@ -516,26 +522,26 @@ std::ios::pos_type CFluidProperties::Read(std::ifstream* mfp_file) } //.................................................................... // subkeyword found - if(line_string.find("$SPECIFIC_HEAT_CAPACITY") != string::npos) + if (line_string.find("$SPECIFIC_HEAT_CAPACITY") != string::npos) { in.str(GetLineFromFile1(mfp_file)); in >> heat_capacity_model; // TF 11/2011 - used only in read- and write-method -// if(heat_capacity_model == 0) // c = fct(x) -// in >> heat_capacity_fct_name; - if(heat_capacity_model == 1) // c = const + // if(heat_capacity_model == 0) // c = fct(x) + // in >> heat_capacity_fct_name; + if (heat_capacity_model == 1) // c = const { in >> specific_heat_capacity; specific_heat_capacity_pcs_name_vector.push_back("PRESSURE1"); specific_heat_capacity_pcs_name_vector.push_back("TEMPERATURE1"); } - if(heat_capacity_model == 2) // my(p,T,C) + if (heat_capacity_model == 2) // my(p,T,C) { in >> C_0; specific_heat_capacity_pcs_name_vector.push_back("PRESSURE1"); specific_heat_capacity_pcs_name_vector.push_back("TEMPERATURE1"); } - if(heat_capacity_model == 3) // YD: improved phase change + if (heat_capacity_model == 3) // YD: improved phase change { in >> T_Latent1; // Tmin for phase change in >> T_Latent2; // Tmax for phase change @@ -545,7 +551,7 @@ std::ios::pos_type CFluidProperties::Read(std::ifstream* mfp_file) specific_heat_capacity_pcs_name_vector.push_back("SATURATION1"); enthalpy_pcs_name_vector.push_back("TEMPERATURE1"); } - if(heat_capacity_model == 4) // YD: improved phase change, function + if (heat_capacity_model == 4) // YD: improved phase change, function { in >> T_Latent1; // Tmin for phase change in >> T_Latent2; // Tmax for phase change @@ -557,16 +563,18 @@ std::ios::pos_type CFluidProperties::Read(std::ifstream* mfp_file) enthalpy_pcs_name_vector.push_back("TEMPERATURE1"); } - //AKS - if(density_model == 15)// components constant density + // AKS + if (density_model == 15) // components constant density { - if(eos_name == "CONSTANT") - in >> cp[0] >> cp[1] >> cp[2] >> cp[3]; + if (eos_name == "CONSTANT") + in >> cp[0] >> cp[1] >> cp[2] >> cp[3]; } - if ((heat_capacity_model == 11 || heat_capacity_model == 12)) // && pcs_vector[0]->getProcessType() != FiniteElement::TNEQ) + if ((heat_capacity_model == 11 + || heat_capacity_model == 12)) // && pcs_vector[0]->getProcessType() != FiniteElement::TNEQ) { - std::cout << "Warning: This heat capacity model requires two components and their molar masses defined in the mcp file!\n"; + std::cout << "Warning: This heat capacity model requires two components and their molar masses defined " + "in the mcp file!\n"; specific_heat_capacity_pcs_name_vector.push_back("PRESSURE1"); specific_heat_capacity_pcs_name_vector.push_back("TEMPERATURE1"); specific_heat_capacity_pcs_name_vector.push_back("CONCENTRATION1"); @@ -577,26 +585,26 @@ std::ios::pos_type CFluidProperties::Read(std::ifstream* mfp_file) } //.................................................................... // subkeyword found - if(line_string.find("$HEAT_CONDUCTIVITY") != string::npos) + if (line_string.find("$HEAT_CONDUCTIVITY") != string::npos) { in.str(GetLineFromFile1(mfp_file)); in >> heat_conductivity_model; // TF 11/2011 - used only in read- and write-method -// if(heat_conductivity_model == 0) // my = fct(x) -// in >> heat_conductivity_fct_name; - if(heat_conductivity_model == 1) // my = const + // if(heat_conductivity_model == 0) // my = fct(x) + // in >> heat_conductivity_fct_name; + if (heat_conductivity_model == 1) // my = const in >> heat_conductivity; - if(heat_conductivity_model == 2) // my = f(p,T,C) + if (heat_conductivity_model == 2) // my = f(p,T,C) { in >> C_0; heat_conductivity_pcs_name_vector.push_back("PRESSURE1"); heat_conductivity_pcs_name_vector.push_back("TEMPERATURE1"); } - if(heat_conductivity_model == 3) // my = f(p,T) NB + if (heat_conductivity_model == 3) // my = f(p,T) NB { - std::string arg1,arg2; - in >> arg1 >> arg2; //get up to three arguments for density model + std::string arg1, arg2; + in >> arg1 >> arg2; // get up to three arguments for density model if (arg1.length() == 0) // if no arguments are given use standard { @@ -610,62 +618,63 @@ std::ios::pos_type CFluidProperties::Read(std::ifstream* mfp_file) heat_conductivity_pcs_name_vector.push_back(arg1); heat_conductivity_pcs_name_vector.push_back(arg2); } - //AKS - if(density_model == 15)// components constant density + // AKS + if (density_model == 15) // components constant density { - if(eos_name == "CONSTANT") - in >> kappa[0] >> kappa[1] >> kappa[2] >> kappa[3]; + if (eos_name == "CONSTANT") + in >> kappa[0] >> kappa[1] >> kappa[2] >> kappa[3]; } if (heat_conductivity_model == 11) // && pcs_vector[0]->getProcessType() != FiniteElement::TNEQ) { - std::cout << "Warning: This heat conductivity model requires two components and their molar masses defined in the mcp file!\n"; + std::cout << "Warning: This heat conductivity model requires two components and their molar masses " + "defined in the mcp file!\n"; heat_conductivity_pcs_name_vector.push_back("PRESSURE1"); heat_conductivity_pcs_name_vector.push_back("TEMPERATURE1"); heat_conductivity_pcs_name_vector.push_back("CONCENTRATION1"); } - in.clear(); //OK + in.clear(); // OK continue; } // subkeyword found - if(line_string.find("$PHASE_DIFFUSION") != string::npos) + if (line_string.find("$PHASE_DIFFUSION") != string::npos) { in.str(GetLineFromFile1(mfp_file)); in >> diffusion_model; // TF 11/2011 - only read - not used -// if(diffusion_model == 0) // D = fct(x) -// in >> dif_fct_name; - if(diffusion_model == 1) // D = const //MX + // if(diffusion_model == 0) // D = fct(x) + // in >> dif_fct_name; + if (diffusion_model == 1) // D = const //MX in >> diffusion; - if(diffusion_model==2) // D = const //MX - { - in >> A_Daq >> B_Daq; // SP: Daq calculated after Yaws; fct(T) - phase_diffusion_pcs_name_vector.push_back("TEMPERATURE1"); - } + if (diffusion_model == 2) // D = const //MX + { + in >> A_Daq >> B_Daq; // SP: Daq calculated after Yaws; fct(T) + phase_diffusion_pcs_name_vector.push_back("TEMPERATURE1"); + } in.clear(); continue; } //.................................................................... - if(line_string.find("$DIFFUSION") != string::npos) + if (line_string.find("$DIFFUSION") != string::npos) { in.str(GetLineFromFile1(mfp_file)); - in >> diffusion_model; //sub_line 1 for first phase - if(diffusion_model == 15 && eos_name == "CONSTANT") - in >> D0[0] >> D0[1] >> D0[2] >> D0[3]; + in >> diffusion_model; // sub_line 1 for first phase + if (diffusion_model == 15 && eos_name == "CONSTANT") + in >> D0[0] >> D0[1] >> D0[2] >> D0[3]; else - in >> diffusion_coef; //sub_line 1 + in >> diffusion_coef; // sub_line 1 in.clear(); } //.................................................................... - if(line_string.find("$DECAY") != string::npos) + if (line_string.find("$DECAY") != string::npos) { in.str(GetLineFromFile1(mfp_file)); in >> decay_model >> lambda[0] >> lambda[1] >> lambda[2] >> lambda[3]; in.clear(); } //.................................................................... - if(line_string.find("$ISOTHERM") != string::npos) + if (line_string.find("$ISOTHERM") != string::npos) { in.str(GetLineFromFile1(mfp_file)); in >> isotherm_model >> Kd[0] >> Kd[1] >> Kd[2] >> Kd[3]; @@ -673,19 +682,20 @@ std::ios::pos_type CFluidProperties::Read(std::ifstream* mfp_file) } //.................................................................... // CMCD outer space version - if(line_string.find("$GRAVITY") != string::npos) + if (line_string.find("$GRAVITY") != string::npos) { in.str(GetLineFromFile1(mfp_file)); in >> gravity_constant; in.clear(); continue; } - if(line_string.find("$SPECIFIC_HEAT_SOURCE")!=string::npos){ - in.str(GetLineFromFile1(mfp_file)); - in >> specific_heat_source; - in.clear(); - continue; - } + if (line_string.find("$SPECIFIC_HEAT_SOURCE") != string::npos) + { + in.str(GetLineFromFile1(mfp_file)); + in >> specific_heat_source; + in.clear(); + continue; + } } return position; } @@ -701,7 +711,7 @@ std::ios::pos_type CFluidProperties::Read(std::ifstream* mfp_file) bool MFPRead(std::string file_base_name) { //---------------------------------------------------------------------- - //OK MFPDelete(); + // OK MFPDelete(); //---------------------------------------------------------------------- CFluidProperties* m_mfp = NULL; char line[MAX_ZEILE]; @@ -711,53 +721,55 @@ bool MFPRead(std::string file_base_name) //======================================================================== // File handling std::string mfp_file_name = file_base_name + MFP_FILE_EXTENSION; - std::ifstream mfp_file (mfp_file_name.data(),std::ios::in); + std::ifstream mfp_file(mfp_file_name.data(), std::ios::in); if (!mfp_file.good()) return false; - mfp_file.seekg(0L,std::ios::beg); + mfp_file.seekg(0L, std::ios::beg); //======================================================================== // Keyword loop - std::cout << "MFPRead" << "\n"; + std::cout << "MFPRead" + << "\n"; while (!mfp_file.eof()) { - mfp_file.getline(line,MAX_ZEILE); + mfp_file.getline(line, MAX_ZEILE); line_string = line; - if(line_string.find("#STOP") != std::string::npos) + if (line_string.find("#STOP") != std::string::npos) return true; //---------------------------------------------------------------------- // keyword found - if(line_string.find("#FLUID_PROPERTIES") != std::string::npos) + if (line_string.find("#FLUID_PROPERTIES") != std::string::npos) { m_mfp = new CFluidProperties(); position = m_mfp->Read(&mfp_file); - m_mfp->phase = (int)mfp_vector.size(); //OK4108 + m_mfp->phase = (int)mfp_vector.size(); // OK4108 mfp_vector.push_back(m_mfp); - mfp_file.seekg(position,std::ios::beg); - } // keyword found - } // eof + mfp_file.seekg(position, std::ios::beg); + } // keyword found + } // eof //======================================================================== // Configuration int i; int no_fluids = (int)mfp_vector.size(); - if(no_fluids == 1) + if (no_fluids == 1) { m_mfp = mfp_vector[0]; m_mfp->phase = 0; } - else if(no_fluids == 2) - for(i = 0; i < no_fluids; i++) + else if (no_fluids == 2) + for (i = 0; i < no_fluids; i++) { m_mfp = mfp_vector[i]; - if(m_mfp->name.find("GAS") != string::npos) + if (m_mfp->name.find("GAS") != string::npos) m_mfp->phase = 0; else m_mfp->phase = 1; } //---------------------------------------------------------------------- // Test - if(mfp_vector.size() == 0) + if (mfp_vector.size() == 0) { - std::cout << "Error in MFPRead: no MFP data" << "\n"; + std::cout << "Error in MFPRead: no MFP data" + << "\n"; abort(); } //---------------------------------------------------------------------- @@ -773,46 +785,55 @@ bool MFPRead(std::string file_base_name) **************************************************************************/ void CFluidProperties::Write(std::ofstream* mfp_file) const { - //KEYWORD - *mfp_file << "#FLUID_PROPERTIES" << "\n"; - *mfp_file << " $FLUID_TYPE" << "\n"; + // KEYWORD + *mfp_file << "#FLUID_PROPERTIES" + << "\n"; + *mfp_file << " $FLUID_TYPE" + << "\n"; *mfp_file << " " << name << "\n"; - *mfp_file << " $DAT_TYPE" << "\n"; + *mfp_file << " $DAT_TYPE" + << "\n"; *mfp_file << " " << name << "\n"; - *mfp_file << " $DENSITY" << "\n"; + *mfp_file << " $DENSITY" + << "\n"; // TF 11/2011 - _rho_fct_name is used only here and in the read-method -// if(density_model == 0) -// *mfp_file << " " << density_model << " " << _rho_fct_name << "\n"; - if(density_model == 1) + // if(density_model == 0) + // *mfp_file << " " << density_model << " " << _rho_fct_name << "\n"; + if (density_model == 1) *mfp_file << " " << density_model << " " << rho_0 << "\n"; - //todo - *mfp_file << " $VISCOSITY" << "\n"; + // todo + *mfp_file << " $VISCOSITY" + << "\n"; // TF 11/2011 - used only in read- and write-method -// if(viscosity_model == 0) -// *mfp_file << " " << viscosity_model << " " << _my_fct_name << "\n"; - if(viscosity_model == 1) + // if(viscosity_model == 0) + // *mfp_file << " " << viscosity_model << " " << _my_fct_name << "\n"; + if (viscosity_model == 1) *mfp_file << " " << viscosity_model << " " << my_0 << "\n"; - *mfp_file << " $PHASE_DIFFUSION" << "\n"; - //if(diffusion_model == 0) *mfp_file << " " << diffusion_model << " " << dif_fct_name << "\n"; - if(diffusion_model == 1) *mfp_file << " " << diffusion_model << " " << diffusion << "\n"; - if(diffusion_model == 2) *mfp_file << " " << diffusion_model << " " << "\n"; - //todo - *mfp_file << " $SPECIFIC_HEAT_CAPACITY" << "\n"; + *mfp_file << " $PHASE_DIFFUSION" + << "\n"; + // if(diffusion_model == 0) *mfp_file << " " << diffusion_model << " " << dif_fct_name << "\n"; + if (diffusion_model == 1) + *mfp_file << " " << diffusion_model << " " << diffusion << "\n"; + if (diffusion_model == 2) + *mfp_file << " " << diffusion_model << " " + << "\n"; + // todo + *mfp_file << " $SPECIFIC_HEAT_CAPACITY" + << "\n"; // TF 11/2011 - used only in read- and write-method -// if(heat_capacity_model == 0) -// *mfp_file << " " << heat_capacity_model << " " << heat_capacity_fct_name << -// "\n"; - if(heat_capacity_model == 1) - *mfp_file << " " << heat_capacity_model << " " << specific_heat_capacity << - "\n"; - *mfp_file << " $SPECIFIC_HEAT_CONDUCTIVITY" << "\n"; + // if(heat_capacity_model == 0) + // *mfp_file << " " << heat_capacity_model << " " << heat_capacity_fct_name << + // "\n"; + if (heat_capacity_model == 1) + *mfp_file << " " << heat_capacity_model << " " << specific_heat_capacity << "\n"; + *mfp_file << " $SPECIFIC_HEAT_CONDUCTIVITY" + << "\n"; // TF 11/2011 - used only in read- and write-method -// if(heat_conductivity_model == 0) -// *mfp_file << " " << heat_conductivity_model << " " << -// heat_conductivity_fct_name << "\n"; - if(heat_conductivity_model == 1) - *mfp_file << " " << heat_conductivity_model << " " << heat_conductivity << - "\n"; + // if(heat_conductivity_model == 0) + // *mfp_file << " " << heat_conductivity_model << " " << + // heat_conductivity_fct_name << "\n"; + if (heat_conductivity_model == 1) + *mfp_file << " " << heat_conductivity_model << " " << heat_conductivity << "\n"; //-------------------------------------------------------------------- } @@ -832,19 +853,20 @@ void MFPWrite(std::string base_file_name) //======================================================================== // File handling std::string mfp_file_name = base_file_name + MFP_FILE_EXTENSION; - mfp_file.open(mfp_file_name.data(),std::ios::trunc | std::ios::out); - mfp_file.setf(std::ios::scientific,std::ios::floatfield); + mfp_file.open(mfp_file_name.data(), std::ios::trunc | std::ios::out); + mfp_file.setf(std::ios::scientific, std::ios::floatfield); mfp_file.precision(12); if (!mfp_file.good()) return; // mfp_file.seekg(0L,ios::beg); //======================================================================== - mfp_file << "GeoSys-MFP: Material Fluid Properties -------------" << "\n"; + mfp_file << "GeoSys-MFP: Material Fluid Properties -------------" + << "\n"; //======================================================================== // OUT vector int mfp_vector_size = (int)mfp_vector.size(); int i; - for(i = 0; i < mfp_vector_size; i++) + for (i = 0; i < mfp_vector_size; i++) { m_mfp = mfp_vector[i]; m_mfp->Write(&mfp_file); @@ -871,50 +893,40 @@ void CFluidProperties::CalPrimaryVariable(std::vector& pcs_name_vec { CRFProcess* m_pcs = NULL; - int nidx0,nidx1; - if(!Fem_Ele_Std) //OK + int nidx0, nidx1; + if (!Fem_Ele_Std) // OK return; primary_variable[0] = 0; primary_variable[1] = 0; primary_variable[2] = 0; - for(int i = 0; i < (int)pcs_name_vector.size(); i++) + for (int i = 0; i < (int)pcs_name_vector.size(); i++) { - //MX m_pcs = PCSGet("HEAT_TRANSPORT"); - m_pcs = PCSGet(pcs_name_vector[i],true); + // MX m_pcs = PCSGet("HEAT_TRANSPORT"); + m_pcs = PCSGet(pcs_name_vector[i], true); if (!m_pcs) - return; //MX + return; // MX nidx0 = m_pcs->GetNodeValueIndex(pcs_name_vector[i]); nidx1 = nidx0 + 1; - if(mode == 0) // Gauss point values + if (mode == 0) // Gauss point values { - primary_variable_t0[i] = Fem_Ele_Std->interpolate(nidx0,m_pcs); - primary_variable_t1[i] = Fem_Ele_Std->interpolate(nidx1,m_pcs); - primary_variable[i] = - (1. - Fem_Ele_Std->pcs->m_num->ls_theta) * Fem_Ele_Std->interpolate( - nidx0, - m_pcs) - + - Fem_Ele_Std->pcs->m_num->ls_theta* Fem_Ele_Std-> - interpolate(nidx1,m_pcs); + primary_variable_t0[i] = Fem_Ele_Std->interpolate(nidx0, m_pcs); + primary_variable_t1[i] = Fem_Ele_Std->interpolate(nidx1, m_pcs); + primary_variable[i] = (1. - Fem_Ele_Std->pcs->m_num->ls_theta) * Fem_Ele_Std->interpolate(nidx0, m_pcs) + + Fem_Ele_Std->pcs->m_num->ls_theta * Fem_Ele_Std->interpolate(nidx1, m_pcs); } - else if(mode == 2) // Element average value + else if (mode == 2) // Element average value { - primary_variable[i] = - (1. - - Fem_Ele_Std->pcs->m_num->ls_theta) * Fem_Ele_Std->elemnt_average( - nidx0, - m_pcs) - + Fem_Ele_Std->pcs->m_num->ls_theta* Fem_Ele_Std-> - elemnt_average(nidx1,m_pcs); - primary_variable_t0[i] = Fem_Ele_Std->elemnt_average(nidx0,m_pcs); - primary_variable_t1[i] = Fem_Ele_Std->elemnt_average(nidx1,m_pcs); + primary_variable[i] = (1. - Fem_Ele_Std->pcs->m_num->ls_theta) * Fem_Ele_Std->elemnt_average(nidx0, m_pcs) + + Fem_Ele_Std->pcs->m_num->ls_theta * Fem_Ele_Std->elemnt_average(nidx1, m_pcs); + primary_variable_t0[i] = Fem_Ele_Std->elemnt_average(nidx0, m_pcs); + primary_variable_t1[i] = Fem_Ele_Std->elemnt_average(nidx1, m_pcs); } - if (mode == 3) //NB, just testing + if (mode == 3) // NB, just testing - primary_variable[i] = Fem_Ele_Std->interpolate(nidx0,m_pcs); + primary_variable[i] = Fem_Ele_Std->interpolate(nidx0, m_pcs); } } @@ -941,268 +953,303 @@ double CFluidProperties::Density(double* variables) int gueltig; //---------------------------------------------------------------------- - if(variables) // This condition is added by WW + if (variables) // This condition is added by WW { //---------------------------------------------------------------------- // Duplicate the following lines just to enhance computation. WW - switch(density_model) + switch (density_model) { - case 0: // rho = f(x) - density = GetCurveValue(density_curve_number, 0, variables[1], &gueltig); - break; - case 1: // rho = const - density = rho_0; - break; - case 2: // rho(p) = rho_0*(1+beta_p*(p-p_0)) - density = rho_0 * (1. + drho_dp * (max(variables[0],0.0) - p_0)); - break; - case 3: // rho(C) = rho_0*(1+beta_C*(C-C_0)) - density = rho_0 * (1. + drho_dC * (max(variables[2],0.0) - C_0)); - break; - case 4: // rho(T) = rho_0*(1+beta_T*(T-T_0)) - density = rho_0 * (1. + drho_dT * (max(variables[1],0.0) - T_0)); - break; - case 5: // rho(C,T) = rho_0*(1+beta_C*(C-C_0)+beta_T*(T-T_0)) - density = rho_0 * - (1. + drho_dC * - (max(variables[2], - 0.0) - C_0) + drho_dT * (max(variables[1],0.0) - T_0)); - break; - case 6: // rho(p,T) = rho_0*(1+beta_p*(p-p_0)+beta_T*(T-T_0)) - density = rho_0 * - (1. + drho_dp * - (max(variables[0], - 0.0) - p_0) + drho_dT * (max(variables[1],0.0) - T_0)); - break; - case 7: // Pefect gas. WW - density = variables[0] * molar_mass / (PhysicalConstant::IdealGasConstant * variables[1]); - break; - case 8: // M14 von JdJ // 25.1.12 Added by CB for density output AB-model - density = MATCalcFluidDensityMethod8(variables[0],variables[1],variables[2]); - break; - case 10: // Get density from temperature-pressure values from fct-file NB 4.8.01 - if(!T_Process) - variables[1] = T_0; - else variables[1]+=T_0; //JM if T_0==273 (user defined), Celsius can be used within this model - density = GetMatrixValue(variables[1],variables[0],fluid_name,&gueltig); - break; - case 11: // Redlich-Kwong EOS for different fluids NB 4.9.05 - if(!T_Process) - variables[1] = T_0; - else variables[1]+=T_0; //JM if T_0==273 (user defined), Celsius can be used within this model - density = rkeos(variables[1],variables[0],fluid_id); - break; - case 12: //Peng-Robinson EOS for different fluids NB 4.9.05 - if(!T_Process) - variables[1] = T_0; - else variables[1]+=T_0; //JM if T_0==273 (user defined), Celsius can be used within this model - //NB - density = preos(this, variables[1],variables[0]); - break; - case 13: // Helmholtz free Energy NB JUN 09 - variables[1]+=T_0; //JM if T_0==273 (user defined), Celsius can be used within this model - //NB - density = zero(variables[1],variables[0],fluid_id,1e-8); - break; - case 14: // #Exponential law# - density = rho_0 *exp(drho_dp * (max(variables[0],0.0) - p_0) + drho_dT * (max(variables[2], 0.0)) + drho_dC *max(variables[2], 0.0)); - break; - - case 15: // mixture 1/rho= sum_i x_i/rho_i #p, T, x:->Amagat's law# - for (int CIndex = 2; CIndex < cmpN + 2; CIndex++) Rho += variables[CIndex]/ComponentDensity(CIndex, variables); - density = 1/Rho; - break; - - case 18: //using calculated densities at nodes from the phase transition model, BG, NB 11/2010 - variables[2] = phase; - density = GetElementValueFromNodes(int(variables[0]), - int(variables[1]), - int(variables[2]), - 0); // hand over element index, Gauss point index and phase index - break; - case 19: // KG44 get the density from GEMS calculations - // seems complicated, as we probably have to call GEMS.....or take values from last GEMS calculation ---> update during iterations is not possible - // long elem = Fem_Ele_Std->GetMeshElement()->GetIndex(); - density=1000.0; + case 0: // rho = f(x) + density = GetCurveValue(density_curve_number, 0, variables[1], &gueltig); + break; + case 1: // rho = const + density = rho_0; + break; + case 2: // rho(p) = rho_0*(1+beta_p*(p-p_0)) + density = rho_0 * (1. + drho_dp * (max(variables[0], 0.0) - p_0)); + break; + case 3: // rho(C) = rho_0*(1+beta_C*(C-C_0)) + density = rho_0 * (1. + drho_dC * (max(variables[2], 0.0) - C_0)); + break; + case 4: // rho(T) = rho_0*(1+beta_T*(T-T_0)) + density = rho_0 * (1. + drho_dT * (max(variables[1], 0.0) - T_0)); + break; + case 5: // rho(C,T) = rho_0*(1+beta_C*(C-C_0)+beta_T*(T-T_0)) + density = rho_0 + * (1. + drho_dC * (max(variables[2], 0.0) - C_0) + drho_dT * (max(variables[1], 0.0) - T_0)); + break; + case 6: // rho(p,T) = rho_0*(1+beta_p*(p-p_0)+beta_T*(T-T_0)) + density = rho_0 + * (1. + drho_dp * (max(variables[0], 0.0) - p_0) + drho_dT * (max(variables[1], 0.0) - T_0)); + break; + case 7: // Pefect gas. WW + density = variables[0] * molar_mass / (PhysicalConstant::IdealGasConstant * variables[1]); + break; + case 8: // M14 von JdJ // 25.1.12 Added by CB for density output AB-model + density = MATCalcFluidDensityMethod8(variables[0], variables[1], variables[2]); + break; + case 10: // Get density from temperature-pressure values from fct-file NB 4.8.01 + if (!T_Process) + variables[1] = T_0; + else + variables[1] += T_0; // JM if T_0==273 (user defined), Celsius can be used within this model + density = GetMatrixValue(variables[1], variables[0], fluid_name, &gueltig); + break; + case 11: // Redlich-Kwong EOS for different fluids NB 4.9.05 + if (!T_Process) + variables[1] = T_0; + else + variables[1] += T_0; // JM if T_0==273 (user defined), Celsius can be used within this model + density = rkeos(variables[1], variables[0], fluid_id); + break; + case 12: // Peng-Robinson EOS for different fluids NB 4.9.05 + if (!T_Process) + variables[1] = T_0; + else + variables[1] += T_0; // JM if T_0==273 (user defined), Celsius can be used within this model + // NB + density = preos(this, variables[1], variables[0]); + break; + case 13: // Helmholtz free Energy NB JUN 09 + variables[1] += T_0; // JM if T_0==273 (user defined), Celsius can be used within this model + // NB + density = zero(variables[1], variables[0], fluid_id, 1e-8); + break; + case 14: // #Exponential law# + density = rho_0 * exp(drho_dp * (max(variables[0], 0.0) - p_0) + drho_dT * (max(variables[2], 0.0)) + + drho_dC * max(variables[2], 0.0)); + break; + + case 15: // mixture 1/rho= sum_i x_i/rho_i #p, T, x:->Amagat's law# + for (int CIndex = 2; CIndex < cmpN + 2; CIndex++) + Rho += variables[CIndex] / ComponentDensity(CIndex, variables); + density = 1 / Rho; + break; + + case 18: // using calculated densities at nodes from the phase transition model, BG, NB 11/2010 + variables[2] = phase; + density = GetElementValueFromNodes(int(variables[0]), + int(variables[1]), + int(variables[2]), + 0); // hand over element index, Gauss point index and phase index + break; + case 19: // KG44 get the density from GEMS calculations + // seems complicated, as we probably have to call GEMS.....or take values from last GEMS calculation + // ---> update during iterations is not possible + // long elem = Fem_Ele_Std->GetMeshElement()->GetIndex(); + density = 1000.0; #ifdef GEM_REACT - if (!Fem_Ele_Std) //for Richards flow (when saturation is needed initially in GEMS setup) we have to make - { - density=1000.0; - } - else - { - // elem = Fem_Ele_Std->GetMeshElement()->GetIndex(); //kg44 need element index or node index for GEMS ...currently we stick to arithmetric average of node data (even for gauss points!) - density=m_vec_GEM->REACT_GEM::FluidDensity( long(variables[0]), int(variables[1])); //hand over element index and gauss point index - // here we can interpolate values from nodes to elemnt or to gauss points - } + if (!Fem_Ele_Std) // for Richards flow (when saturation is needed initially in GEMS setup) we have to + // make + { + density = 1000.0; + } + else + { + // elem = Fem_Ele_Std->GetMeshElement()->GetIndex(); //kg44 need element index or node index for + // GEMS ...currently we stick to arithmetric average of node data (even for gauss points!) + density = m_vec_GEM->REACT_GEM::FluidDensity( + long(variables[0]), int(variables[1])); // hand over element index and gauss point index + // here we can interpolate values from nodes to elemnt or to gauss points + } #endif - //insert call for GEMS densities.. - break; - case 20: // rho(p,T, C) for water, range p < 100 MPa, 0 <= T <= 350 °C Magri GFZ thesis - - pressure = variables[0] / 1e5; - density = - 9.99792877961606e+02 + 5.07605113140940e-04 * max(pressure, 0.0) - 5.28425478164183e-10 * pow(max(pressure, 0.0), 2.) - + (5.13864847162196e-02 - 3.61991396354483e-06 * max(pressure, 0.0) + 7.97204102509724e-12 * pow(max(pressure, 0.0), 2.)) * max(variables[1], 0.0) - + (-7.53557031774437e-03 + 6.32712093275576e-08 * max(pressure, 0.0) - 1.66203631393248e-13 * pow(max(pressure, 0.0), 2.)) * pow(max(variables[1], 0.0), 2.) - + (4.60380647957350e-05 - 5.61299059722121e-10 * max(pressure, 0.0) + 1.80924436489400e-15 * pow(max(pressure, 0.0), 2.)) * pow(max(variables[1], 0.0), 3.) - + (-2.26651454175013e-07 + 3.36874416675978e-12 * max(pressure, 0.0) - 1.30352149261326e-17 * pow(max(pressure, 0.0), 2.)) * pow(max(variables[1], 0.0), 4.) - + (6.14889851856743e-10 - 1.06165223196756e-14 * max(pressure, 0.0) + 4.75014903737416e-20 * pow(max(pressure, 0.0), 2.)) * pow(max(variables[1], 0.0), 5.) - + (-7.39221950969522e-13 + 1.42790422913922e-17 * max(pressure, 0.0) - 7.13130230531541e-23 * pow(max(pressure, 0.0), 2.)) * pow(max(variables[1], 0.0), 6.); - - if (fabs(drho_dC) > 1.e-20) - density *= 1. + drho_dC * (max(variables[2], 0.0) - C_0); - - break; - case 26: //Dalton's law + ideal gas for use with TNEQ/TES - { - const double M0 = cp_vec[0]->molar_mass; // molar mass of component 0 - const double M1 = cp_vec[1]->molar_mass; - const double p = variables[0]; - const double T = variables[1]; - const double x = variables[2]; // gas mass fraction of component 1 - // assert(0.0 <= x && x <= 1.0); + // insert call for GEMS densities.. + break; + case 20: // rho(p,T, C) for water, range p < 100 MPa, 0 <= T <= 350 °C Magri GFZ thesis + + pressure = variables[0] / 1e5; + density = 9.99792877961606e+02 + 5.07605113140940e-04 * max(pressure, 0.0) + - 5.28425478164183e-10 * pow(max(pressure, 0.0), 2.) + + (5.13864847162196e-02 - 3.61991396354483e-06 * max(pressure, 0.0) + + 7.97204102509724e-12 * pow(max(pressure, 0.0), 2.)) + * max(variables[1], 0.0) + + (-7.53557031774437e-03 + 6.32712093275576e-08 * max(pressure, 0.0) + - 1.66203631393248e-13 * pow(max(pressure, 0.0), 2.)) + * pow(max(variables[1], 0.0), 2.) + + (4.60380647957350e-05 - 5.61299059722121e-10 * max(pressure, 0.0) + + 1.80924436489400e-15 * pow(max(pressure, 0.0), 2.)) + * pow(max(variables[1], 0.0), 3.) + + (-2.26651454175013e-07 + 3.36874416675978e-12 * max(pressure, 0.0) + - 1.30352149261326e-17 * pow(max(pressure, 0.0), 2.)) + * pow(max(variables[1], 0.0), 4.) + + (6.14889851856743e-10 - 1.06165223196756e-14 * max(pressure, 0.0) + + 4.75014903737416e-20 * pow(max(pressure, 0.0), 2.)) + * pow(max(variables[1], 0.0), 5.) + + (-7.39221950969522e-13 + 1.42790422913922e-17 * max(pressure, 0.0) + - 7.13130230531541e-23 * pow(max(pressure, 0.0), 2.)) + * pow(max(variables[1], 0.0), 6.); + + if (fabs(drho_dC) > 1.e-20) + density *= 1. + drho_dC * (max(variables[2], 0.0) - C_0); + + break; + case 26: // Dalton's law + ideal gas for use with TNEQ/TES + { + const double M0 = cp_vec[0]->molar_mass; // molar mass of component 0 + const double M1 = cp_vec[1]->molar_mass; + const double p = variables[0]; + const double T = variables[1]; + const double x = variables[2]; // gas mass fraction of component 1 + // assert(0.0 <= x && x <= 1.0); - // gas molar fraction of component 1 - const double xn = M0*x/(M0*x + M1*(1.0-x)); + // gas molar fraction of component 1 + const double xn = M0 * x / (M0 * x + M1 * (1.0 - x)); - density = p / (PhysicalConstant::IdealGasConstant * T) * (M1*xn + M0*(1.0-xn)); //R_uni in mNs - } + density = p / (PhysicalConstant::IdealGasConstant * T) * (M1 * xn + M0 * (1.0 - xn)); // R_uni in mNs + } break; - default: - std::cout << "Error in CFluidProperties::Density: no valid model" << - "\n"; - break; + default: + std::cout << "Error in CFluidProperties::Density: no valid model" + << "\n"; + break; } } else { CalPrimaryVariable(density_pcs_name_vector); //---------------------------------------------------------------------- - switch(density_model) + switch (density_model) { - case 0: // rho = f(x) - density = GetCurveValue(density_curve_number,0,primary_variable[0],&gueltig); - break; - case 1: // rho = const - density = rho_0; - break; - case 2: // rho(p) = rho_0*(1+beta_p*(p-p_0)) - density = rho_0 * (1. + drho_dp * (max(primary_variable[0],0.0) - p_0)); - break; - case 3: // rho(C) = rho_0*(1+beta_C*(C-C_0)) - density = rho_0 * (1. + drho_dC * (max(primary_variable[0],0.0) - C_0)); - break; - case 4: // rho(T) = rho_0*(1+beta_T*(T-T_0)) - density = rho_0 * (1. + drho_dT * (max(primary_variable[0],0.0) - T_0)); - break; - case 5: // rho(C,T) = rho_0*(1+beta_C*(C-C_0)+beta_T*(T-T_0)) - density = rho_0 * - (1. + drho_dC * - (max(primary_variable[0], - 0.0) - C_0) + drho_dT * (max(primary_variable[1],0.0) - T_0)); - break; - case 6: // rho(p,T) = rho_0*(1+beta_p*(p-p_0)+beta_T*(T-T_0)) - density = rho_0 * - (1. + drho_dp * - (max(primary_variable[0], - 0.0) - p_0) + drho_dT * (max(primary_variable[1],0.0) - T_0)); - break; - case 7: // rho_w^l(p,T) for gas phase - /* //WW - { - const double vapour_pressure = MFPCalcVapourPressure(primary_variable[0]); - air_gas_density = (MolarMass::Air * (primary_variable[1]-vapour_pressure)) / (PhysicalConstant::IdealGasConstant*(primary_variable[0]+0.0)); - vapour_density = (MolarMass::Water * vapour_pressure) / (PhysicalConstant::IdealGasConstant*(primary_variable[0]+0.0)); - density = vapour_density + air_gas_density; - } - */ - break; - case 8: // M14 von JdJ - density = MATCalcFluidDensityMethod8(primary_variable[0], - primary_variable[1], - primary_variable[2]); - break; - case 10: // Get density from temperature-pressure values from fct-file NB - if(!T_Process) - primary_variable[1] = T_0; - else primary_variable[1]+=T_0; //JM if T_0==273 (user defined), Celsius can be used within this model - density = GetMatrixValue(primary_variable[1], - primary_variable[0], - fluid_name, - &gueltig); - break; - case 11: //Peng-Robinson equation of state NB - if(!T_Process) - primary_variable[1] = T_0; - else primary_variable[1]+=T_0; //JM if T_0==273 (user defined), Celsius can be used within this model - density = rkeos(primary_variable[1],primary_variable[0],fluid_id); - break; - case 12: //Redlich-Kwong equation of state NB - if(!T_Process) - primary_variable[1] = T_0; - else primary_variable[1]+=T_0; //JM if T_0==273 (user defined), Celsius can be used within this model - density = preos(this, primary_variable[1],primary_variable[0]); - break; - case 13: // Helmholtz free Energy NB JUN 09 - if(!T_Process) - primary_variable[1] = T_0; - else primary_variable[1]+=T_0; //JM if T_0==273 (user defined), Celsius can be used within this model - //NB - density = zero(primary_variable[1],primary_variable[0],fluid_id,1e-8); - break; - - case 14: // #Exponential law# - density = rho_0 *exp(drho_dp * (max(variables[0],0.0) - p_0) + drho_dT * (max(variables[2], 0.0)) + drho_dC *max(variables[2], 0.0)); - break; - case 15: // mixture 1/rho= sum_i x_i/rho_i #p, T, x:-> Amagat's law# - for (int CIndex = 2; CIndex < cmpN + 2; CIndex++) Rho += variables[CIndex]/ComponentDensity(CIndex, variables); - density = 1/Rho; - break; - case 18: //using calculated densities at nodes from the phase transition model, BG, NB 11/2010 - // Just dummy function, so density is not 0 ; - std::cout << " Error - Density Model 18 not implemented, usind dummy density of 1000." << "\n"; - density = 1000; // Achtung - dummy - - - case 19: // KG44 get the density from GEMS calculations - // seems complicated, as we probably have to call GEMS.....or take values from last GEMS calculation ---> update during iterations is not possible - // long elem = Fem_Ele_Std->GetMeshElement()->GetIndex(); - density=1000.0; + case 0: // rho = f(x) + density = GetCurveValue(density_curve_number, 0, primary_variable[0], &gueltig); + break; + case 1: // rho = const + density = rho_0; + break; + case 2: // rho(p) = rho_0*(1+beta_p*(p-p_0)) + density = rho_0 * (1. + drho_dp * (max(primary_variable[0], 0.0) - p_0)); + break; + case 3: // rho(C) = rho_0*(1+beta_C*(C-C_0)) + density = rho_0 * (1. + drho_dC * (max(primary_variable[0], 0.0) - C_0)); + break; + case 4: // rho(T) = rho_0*(1+beta_T*(T-T_0)) + density = rho_0 * (1. + drho_dT * (max(primary_variable[0], 0.0) - T_0)); + break; + case 5: // rho(C,T) = rho_0*(1+beta_C*(C-C_0)+beta_T*(T-T_0)) + density = rho_0 * (1. + drho_dC * (max(primary_variable[0], 0.0) - C_0) + + drho_dT * (max(primary_variable[1], 0.0) - T_0)); + break; + case 6: // rho(p,T) = rho_0*(1+beta_p*(p-p_0)+beta_T*(T-T_0)) + density = rho_0 * (1. + drho_dp * (max(primary_variable[0], 0.0) - p_0) + + drho_dT * (max(primary_variable[1], 0.0) - T_0)); + break; + case 7: // rho_w^l(p,T) for gas phase + /* //WW + { + const double vapour_pressure = MFPCalcVapourPressure(primary_variable[0]); + air_gas_density = (MolarMass::Air * (primary_variable[1]-vapour_pressure)) / + (PhysicalConstant::IdealGasConstant*(primary_variable[0]+0.0)); + vapour_density = (MolarMass::Water * vapour_pressure) / + (PhysicalConstant::IdealGasConstant*(primary_variable[0]+0.0)); + density = vapour_density + air_gas_density; + } + */ + break; + case 8: // M14 von JdJ + density = MATCalcFluidDensityMethod8(primary_variable[0], primary_variable[1], primary_variable[2]); + break; + case 10: // Get density from temperature-pressure values from fct-file NB + if (!T_Process) + primary_variable[1] = T_0; + else + primary_variable[1] += T_0; // JM if T_0==273 (user defined), Celsius can be used within this model + density = GetMatrixValue(primary_variable[1], primary_variable[0], fluid_name, &gueltig); + break; + case 11: // Peng-Robinson equation of state NB + if (!T_Process) + primary_variable[1] = T_0; + else + primary_variable[1] += T_0; // JM if T_0==273 (user defined), Celsius can be used within this model + density = rkeos(primary_variable[1], primary_variable[0], fluid_id); + break; + case 12: // Redlich-Kwong equation of state NB + if (!T_Process) + primary_variable[1] = T_0; + else + primary_variable[1] += T_0; // JM if T_0==273 (user defined), Celsius can be used within this model + density = preos(this, primary_variable[1], primary_variable[0]); + break; + case 13: // Helmholtz free Energy NB JUN 09 + if (!T_Process) + primary_variable[1] = T_0; + else + primary_variable[1] += T_0; // JM if T_0==273 (user defined), Celsius can be used within this model + // NB + density = zero(primary_variable[1], primary_variable[0], fluid_id, 1e-8); + break; + + case 14: // #Exponential law# + density = rho_0 * exp(drho_dp * (max(variables[0], 0.0) - p_0) + drho_dT * (max(variables[2], 0.0)) + + drho_dC * max(variables[2], 0.0)); + break; + case 15: // mixture 1/rho= sum_i x_i/rho_i #p, T, x:-> Amagat's law# + for (int CIndex = 2; CIndex < cmpN + 2; CIndex++) + Rho += variables[CIndex] / ComponentDensity(CIndex, variables); + density = 1 / Rho; + break; + case 18: // using calculated densities at nodes from the phase transition model, BG, NB 11/2010 + // Just dummy function, so density is not 0 ; + std::cout << " Error - Density Model 18 not implemented, usind dummy density of 1000." + << "\n"; + density = 1000; // Achtung - dummy + + case 19: // KG44 get the density from GEMS calculations + // seems complicated, as we probably have to call GEMS.....or take values from last GEMS calculation + // ---> update during iterations is not possible + // long elem = Fem_Ele_Std->GetMeshElement()->GetIndex(); + density = 1000.0; #ifdef GEM_REACT - if (!Fem_Ele_Std) //for Richards flow (when saturation is needed initially in GEMS setup) we have to make - { - density=1000.0; - } - else - { - long elem = Fem_Ele_Std->GetMeshElement()->GetIndex(); //kg44 need element index or node index for GEMS ...currently we stick to arithmetric average of node data (even for gauss points!) - density=m_vec_GEM->REACT_GEM::FluidDensity( elem, -1); //hand over element index and set gauss point to -1... - // Remark: Interpolation from Gauss points to element is not possible here: Fluid densities are only calculated at nodes, therefore interpolation from gauss points onto element will not work - } + if (!Fem_Ele_Std) // for Richards flow (when saturation is needed initially in GEMS setup) we have to + // make + { + density = 1000.0; + } + else + { + long elem = Fem_Ele_Std->GetMeshElement()->GetIndex(); // kg44 need element index or node index for + // GEMS ...currently we stick to arithmetric + // average of node data (even for gauss + // points!) + density = m_vec_GEM->REACT_GEM::FluidDensity( + elem, -1); // hand over element index and set gauss point to -1... + // Remark: Interpolation from Gauss points to element is not possible here: Fluid densities are only + // calculated at nodes, therefore interpolation from gauss points onto element will not work + } #endif - //insert call for GEMS densities.. - break; - case 20: // rho(p,T, C) for water, range p < 100 MPa, 0 <= T <= 350 °C Magri GFZ thesis - pressure = primary_variable[0] / 1e5; - - density = - 9.99792877961606e+02 + 5.07605113140940e-04 * max(pressure, 0.0) - 5.28425478164183e-10 * pow(max(pressure, 0.0), 2.) - + (5.13864847162196e-02 - 3.61991396354483e-06 * max(pressure, 0.0) + 7.97204102509724e-12 * pow(max(pressure, 0.0), 2.)) * max(primary_variable[1], 0.0) - + (-7.53557031774437e-03 + 6.32712093275576e-08 * max(pressure, 0.0) - 1.66203631393248e-13 * pow(max(pressure, 0.0), 2.)) * pow(max(primary_variable[1], 0.0), 2.) - + (4.60380647957350e-05 - 5.61299059722121e-10 * max(pressure, 0.0) + 1.80924436489400e-15 * pow(max(pressure, 0.0), 2.)) * pow(max(primary_variable[1], 0.0), 3.) - + (-2.26651454175013e-07 + 3.36874416675978e-12 * max(pressure, 0.0) - 1.30352149261326e-17 * pow(max(pressure, 0.0), 2.)) * pow(max(primary_variable[1], 0.0), 4.) - + (6.14889851856743e-10 - 1.06165223196756e-14 * max(pressure, 0.0) + 4.75014903737416e-20 * pow(max(pressure, 0.0), 2.)) * pow(max(primary_variable[1], 0.0), 5.) - + (-7.39221950969522e-13 + 1.42790422913922e-17 * max(pressure, 0.0) - 7.13130230531541e-23 * pow(max(pressure, 0.0), 2.)) * pow(max(primary_variable[1], 0.0), 6.); - - if (fabs(drho_dC) > 1.e-20) - density *= 1. + drho_dC * (max(primary_variable[2], 0.0) - C_0); - break; - default: - std::cout << "Error in CFluidProperties::Density: no valid model" << - "\n"; - break; + // insert call for GEMS densities.. + break; + case 20: // rho(p,T, C) for water, range p < 100 MPa, 0 <= T <= 350 °C Magri GFZ thesis + pressure = primary_variable[0] / 1e5; + + density = 9.99792877961606e+02 + 5.07605113140940e-04 * max(pressure, 0.0) + - 5.28425478164183e-10 * pow(max(pressure, 0.0), 2.) + + (5.13864847162196e-02 - 3.61991396354483e-06 * max(pressure, 0.0) + + 7.97204102509724e-12 * pow(max(pressure, 0.0), 2.)) + * max(primary_variable[1], 0.0) + + (-7.53557031774437e-03 + 6.32712093275576e-08 * max(pressure, 0.0) + - 1.66203631393248e-13 * pow(max(pressure, 0.0), 2.)) + * pow(max(primary_variable[1], 0.0), 2.) + + (4.60380647957350e-05 - 5.61299059722121e-10 * max(pressure, 0.0) + + 1.80924436489400e-15 * pow(max(pressure, 0.0), 2.)) + * pow(max(primary_variable[1], 0.0), 3.) + + (-2.26651454175013e-07 + 3.36874416675978e-12 * max(pressure, 0.0) + - 1.30352149261326e-17 * pow(max(pressure, 0.0), 2.)) + * pow(max(primary_variable[1], 0.0), 4.) + + (6.14889851856743e-10 - 1.06165223196756e-14 * max(pressure, 0.0) + + 4.75014903737416e-20 * pow(max(pressure, 0.0), 2.)) + * pow(max(primary_variable[1], 0.0), 5.) + + (-7.39221950969522e-13 + 1.42790422913922e-17 * max(pressure, 0.0) + - 7.13130230531541e-23 * pow(max(pressure, 0.0), 2.)) + * pow(max(primary_variable[1], 0.0), 6.); + + if (fabs(drho_dC) > 1.e-20) + density *= 1. + drho_dC * (max(primary_variable[2], 0.0) - C_0); + break; + default: + std::cout << "Error in CFluidProperties::Density: no valid model" + << "\n"; + break; } } return density; @@ -1215,75 +1262,70 @@ double CFluidProperties::Density(double* variables) Programming: 11/2010 BG Modification: -------------------------------------------------------------------------*/ -double CFluidProperties::GetElementValueFromNodes(long ElementIndex, - int GPIndex, - int PhaseIndex, - int VariableIndex) +double CFluidProperties::GetElementValueFromNodes(long ElementIndex, int GPIndex, int PhaseIndex, int VariableIndex) { - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt MeshLib::CElem* m_ele = NULL; MeshLib::CNode* m_node = NULL; CRFProcess* m_pcs; double var, variable; int variable_index = 0, nNodes; double distance, weight, sum_weights; - Math_Group::vec vec_nod_index(8); + Math_Group::vec vec_nod_index(8); variable = 0; m_pcs = PCSGet("MULTI_PHASE_FLOW"); - //check if PHASE_TRANSITION is used for the process + // check if PHASE_TRANSITION is used for the process if ((density_model == 18) || (viscosity_model == 18)) if (m_pcs->Phase_Transition_Model != 1) { - cout << - "The Phase_Transition_Model should be used together with the density and viscosity model 18 !" + cout << "The Phase_Transition_Model should be used together with the density and viscosity model 18 !" + << "\n"; + cout << "The run is terminated now ..." << "\n"; - cout << "The run is terminated now ..." << "\n"; system("Pause"); exit(0); } m_ele = m_msh->ele_vector[ElementIndex]; // get element - //if GPIndex > 0 -> interpolation to GP if not then interpolation to the Element centre + // if GPIndex > 0 -> interpolation to GP if not then interpolation to the Element centre if (PhaseIndex == 0) { - switch(VariableIndex) + switch (VariableIndex) { - case 0: // Density - variable_index = m_pcs->GetNodeValueIndex("DENSITY1"); - break; - case 1: // Viscosity - variable_index = m_pcs->GetNodeValueIndex("VISCOSITY1"); - break; + case 0: // Density + variable_index = m_pcs->GetNodeValueIndex("DENSITY1"); + break; + case 1: // Viscosity + variable_index = m_pcs->GetNodeValueIndex("VISCOSITY1"); + break; } } else { - switch(VariableIndex) + switch (VariableIndex) { - case 0: // Density - variable_index = m_pcs->GetNodeValueIndex("DENSITY2"); - break; - case 1: // Viscosity - variable_index = m_pcs->GetNodeValueIndex("VISCOSITY2"); - break; + case 0: // Density + variable_index = m_pcs->GetNodeValueIndex("DENSITY2"); + break; + case 1: // Viscosity + variable_index = m_pcs->GetNodeValueIndex("VISCOSITY2"); + break; } } if (GPIndex > -1) { - //interpolate density to gauss point + // interpolate density to gauss point if (m_ele->GetMark()) // Marked for use // Configure Element for interpolation of node velocities to GP velocities - //Fem_Ele_Std->ConfigElement(m_ele); - variable = Fem_Ele_Std->InterpolatePropertyToGausspoint(GPIndex, - m_pcs, - variable_index); + // Fem_Ele_Std->ConfigElement(m_ele); + variable = Fem_Ele_Std->InterpolatePropertyToGausspoint(GPIndex, m_pcs, variable_index); } else { - distance = weight = sum_weights = 0.0; + distance = weight = sum_weights = 0.0; if (m_ele->GetElementType() == 0) nNodes = m_ele->GetNodesNumber(true); else @@ -1291,27 +1333,27 @@ double CFluidProperties::GetElementValueFromNodes(long ElementIndex, m_ele->GetNodeIndeces(vec_nod_index); for (long i = 0; i < int(nNodes); i++) // go through list of connected nodes - { //Get the connected node + { // Get the connected node m_node = m_msh->nod_vector[vec_nod_index[i]]; - //calculate distance between the node and the barycentre + // calculate distance between the node and the barycentre double const* gravity_centre(m_ele->GetGravityCenter()); - double const* const pnt (m_node->getData()); - distance = (gravity_centre[0] - pnt[0]) * (gravity_centre[0] - pnt[0]); + double const* const pnt(m_node->getData()); + distance = (gravity_centre[0] - pnt[0]) * (gravity_centre[0] - pnt[0]); distance += (gravity_centre[1] - pnt[1]) * (gravity_centre[1] - pnt[1]); distance += (gravity_centre[2] - pnt[2]) * (gravity_centre[2] - pnt[2]); - distance = sqrt(distance); + distance = sqrt(distance); - //Weight of each face depending on distance + // Weight of each face depending on distance weight = (1.0 / distance); // Sum of weights sum_weights += weight; - //Density + // Density var = m_pcs->GetNodeValue(int(m_node->GetIndex()), variable_index); variable += var * weight; } variable = variable / sum_weights; } - //cout << "Variable: " << variable << "\n"; + // cout << "Variable: " << variable << "\n"; return variable; } @@ -1335,8 +1377,8 @@ double CFluidProperties::MATCalcFluidDensityMethod8(double Press, double TempK, /*int c_idx;*/ double rho_0; double GammaPi, Pressurevar, Tau, pressure_average, temperature_average; - double Tstar, Pstar,GazConst; - double L[35],J[35],n[35]; + double Tstar, Pstar, GazConst; + double L[35], J[35], n[35]; int i; double salinity; @@ -1344,8 +1386,8 @@ double CFluidProperties::MATCalcFluidDensityMethod8(double Press, double TempK, temperature_average = TempK; salinity = C_0; Tstar = 1386; - Pstar = 16.53e6; // MPa - GazConst = 0.461526e3; // + Pstar = 16.53e6; // MPa + GazConst = 0.461526e3; // n[0] = 0.0; n[1] = 0.14632971213167; @@ -1463,8 +1505,7 @@ double CFluidProperties::MATCalcFluidDensityMethod8(double Press, double TempK, for (i = 1; i < 35; i++) - GammaPi = GammaPi - (n[i]) * (L[i]) * - (pow((7.1 - Pressurevar),(L[i] - 1))) * (pow((Tau - 1.222),J[i])); + GammaPi = GammaPi - (n[i]) * (L[i]) * (pow((7.1 - Pressurevar), (L[i] - 1))) * (pow((Tau - 1.222), J[i])); /*END: Calculation of GammaPi*/ @@ -1488,153 +1529,154 @@ double CFluidProperties::MATCalcFluidDensityMethod8(double Press, double TempK, 10/2008 OK Faster data access 03/2009 NB Viscosity depending on Density() **************************************************************************/ -//OK4709 +// OK4709 double CFluidProperties::Viscosity(double* variables) { double viscosity = 0.0; //---------------------------------------------------------------------- - if(variables) //OK4709: faster data access + if (variables) // OK4709: faster data access { - primary_variable[0] = variables[0]; //p (single phase) - primary_variable[1] = variables[1]; //T (temperature) - primary_variable[2] = variables[2]; //C (salinity)//index in case of AIR_FLOW + primary_variable[0] = variables[0]; // p (single phase) + primary_variable[1] = variables[1]; // T (temperature) + primary_variable[2] = variables[2]; // C (salinity)//index in case of AIR_FLOW } else CalPrimaryVariable(viscosity_pcs_name_vector); //---------------------------------------------------------------------- - switch(viscosity_model) - { - case 0: // rho = f(x) + switch (viscosity_model) { - int gueltig; - viscosity = GetCurveValue(viscosity_curve_number,0,primary_variable[1],&gueltig); - break; - } - case 1: // my = const - viscosity = my_0; - break; - case 2: // my(p) = my_0*(1+gamma_p*(p-p_0)) - viscosity = my_0 * (1. + dmy_dp * (max(primary_variable[0],0.0) - p_0)); - break; - case 3: // my^l(T), Yaws et al. (1976) - { - CRFProcess* m_pcs = PCSGet("MULTI_COMPONENTIAL_FLOW"); - - if(mode == 1) //OK4704 for nodal output + case 0: // rho = f(x) { - m_pcs = PCSGet("HEAT_TRANSPORT"); - //if(!m_pcs) return 0.0; - primary_variable[1] = - m_pcs->GetNodeValue(node,m_pcs->GetNodeValueIndex( - "TEMPERATURE1") + 1); + int gueltig; + viscosity = GetCurveValue(viscosity_curve_number, 0, primary_variable[1], &gueltig); + break; } - //ToDo pcs_name - if(!T_Process) - primary_variable[1] = T_0+viscosity_T_shift; - else primary_variable[1]+=viscosity_T_shift; //JM if viscosity_T_shift==273 (user defined), Celsius can be used within this model - viscosity = LiquidViscosity_Yaws_1976(primary_variable[1]); - break; - } - case 4: // my^g(T), Marsily (1986) - viscosity = LiquidViscosity_Marsily_1986(primary_variable[1]); - //viscosity = LiquidViscosity_Marsily_1986(primary_variable[0]); - break; - case 5: // my^g(p,T), Reichenberg (1971) - viscosity = GasViscosity_Reichenberg_1971(primary_variable[0],primary_variable[1]); - break; - case 6: // my(C,T), - viscosity = LiquidViscosity_NN(primary_variable[0],primary_variable[1]); - break; - case 8: // my(p,C,T), - viscosity = LiquidViscosity_CMCD(primary_variable[0], - primary_variable[1], - primary_variable[2]); - break; - case 9: // viscosity as function of density and temperature, NB - { - double mfp_arguments[2]; - - if(!T_Process) - primary_variable[1] = T_0; - // TODO: switch case different models... - // Problem.cpp 3 PS_GLOBAL, 1212,1313 pcs_type - //TODO: default fluid_ID, if not specified - mfp_arguments[0] = primary_variable[0]; // rescue primary_variable before its destroyed by Density(); - mfp_arguments[1] = primary_variable[1]; - - const double density = Density(mfp_arguments); //TODO: (NB) store density (and viscosity) as secondary variable - //NB - viscosity = Fluid_Viscosity(density,mfp_arguments[1],mfp_arguments[0],fluid_id); - break; - } - case 15: //mixture 1/�= sum_i y_i/�_i:: VTPR-EoS - { - CRFProcess* m_pcs = PCSGet("MULTI_COMPONENTIAL_FLOW"); - double my = 0.0; - - for (int CIndex = 2; CIndex < cmpN + 2; CIndex++) + case 1: // my = const + viscosity = my_0; + break; + case 2: // my(p) = my_0*(1+gamma_p*(p-p_0)) + viscosity = my_0 * (1. + dmy_dp * (max(primary_variable[0], 0.0) - p_0)); + break; + case 3: // my^l(T), Yaws et al. (1976) { - if(eos_name == "CONSTANT") + CRFProcess* m_pcs = PCSGet("MULTI_COMPONENTIAL_FLOW"); + + if (mode == 1) // OK4704 for nodal output { - my += variables[CIndex]/mu[CIndex-2]; + m_pcs = PCSGet("HEAT_TRANSPORT"); + // if(!m_pcs) return 0.0; + primary_variable[1] = m_pcs->GetNodeValue(node, m_pcs->GetNodeValueIndex("TEMPERATURE1") + 1); } + // ToDo pcs_name + if (!T_Process) + primary_variable[1] = T_0 + viscosity_T_shift; else + primary_variable[1] += viscosity_T_shift; // JM if viscosity_T_shift==273 (user defined), Celsius can be + // used within this model + viscosity = LiquidViscosity_Yaws_1976(primary_variable[1]); + break; + } + case 4: // my^g(T), Marsily (1986) + viscosity = LiquidViscosity_Marsily_1986(primary_variable[1]); + // viscosity = LiquidViscosity_Marsily_1986(primary_variable[0]); + break; + case 5: // my^g(p,T), Reichenberg (1971) + viscosity = GasViscosity_Reichenberg_1971(primary_variable[0], primary_variable[1]); + break; + case 6: // my(C,T), + viscosity = LiquidViscosity_NN(primary_variable[0], primary_variable[1]); + break; + case 8: // my(p,C,T), + viscosity = LiquidViscosity_CMCD(primary_variable[0], primary_variable[1], primary_variable[2]); + break; + case 9: // viscosity as function of density and temperature, NB + { + double mfp_arguments[2]; + + if (!T_Process) + primary_variable[1] = T_0; + // TODO: switch case different models... + // Problem.cpp 3 PS_GLOBAL, 1212,1313 pcs_type + // TODO: default fluid_ID, if not specified + mfp_arguments[0] = primary_variable[0]; // rescue primary_variable before its destroyed by Density(); + mfp_arguments[1] = primary_variable[1]; + + const double density + = Density(mfp_arguments); // TODO: (NB) store density (and viscosity) as secondary variable + // NB + viscosity = Fluid_Viscosity(density, mfp_arguments[1], mfp_arguments[0], fluid_id); + break; + } + case 15: // mixture 1/�= sum_i y_i/�_i:: VTPR-EoS + { + CRFProcess* m_pcs = PCSGet("MULTI_COMPONENTIAL_FLOW"); + double my = 0.0; + + for (int CIndex = 2; CIndex < cmpN + 2; CIndex++) { - therm_prop(m_pcs->pcs_primary_function_name[CIndex]); - my += variables[CIndex]/Fluid_Viscosity(ComponentDensity(CIndex, variables), variables[1], variables[0], fluid_id); + if (eos_name == "CONSTANT") + { + my += variables[CIndex] / mu[CIndex - 2]; + } + else + { + therm_prop(m_pcs->pcs_primary_function_name[CIndex]); + my += variables[CIndex] + / Fluid_Viscosity(ComponentDensity(CIndex, variables), variables[1], variables[0], fluid_id); + } } + viscosity = 1.0 / my; + break; } - viscosity = 1.0/my; - break; - } + case 18: // BG, NB using calculated viscosities at nodes from the phase transition model + variables[2] = phase; + viscosity = GetElementValueFromNodes( + int(variables[0]), int(variables[1]), int(variables[2]), + 1); // hand over element index, Gauss point index, phase index and variable index + break; + case 19: // reserved for GEMS coupling + break; + case 26: // Wilke (see Poling, B. E.; Prausnitz, J. M.; John Paul, O. & Reid, R. C. The properties of gases and + // liquids McGraw-Hill New York, 2001, 5: page 9.21) + { + double x[2], Vs[2]; - case 18: //BG, NB using calculated viscosities at nodes from the phase transition model - variables[2] = phase; - viscosity = - GetElementValueFromNodes(int(variables[0]), int(variables[1]), - int(variables[2]), 1); // hand over element index, Gauss point index, phase index and variable index - break; - case 19: // reserved for GEMS coupling - break; - case 26: //Wilke (see Poling, B. E.; Prausnitz, J. M.; John Paul, O. & Reid, R. C. The properties of gases and liquids McGraw-Hill New York, 2001, 5: page 9.21) - { - double x[2], Vs[2]; - - const double M1 = cp_vec[0]->molar_mass; - const double M2 = cp_vec[1]->molar_mass; + const double M1 = cp_vec[0]->molar_mass; + const double M2 = cp_vec[1]->molar_mass; - const double p = variables[0]; - const double T = variables[1]; - const double X = variables[2]; + const double p = variables[0]; + const double T = variables[1]; + const double X = variables[2]; - //reactive component - x[0] = M1*X/(M1*X + M2*(1.0-X)); //mass in mole fraction - Vs[0] = Fluid_Viscosity(M2*p/(PhysicalConstant::IdealGasConstant * T), T, p, cp_vec[1]->fluid_id); - //inert component - x[1] = 1.0 - x[0]; - Vs[1] = Fluid_Viscosity(M1*p/(PhysicalConstant::IdealGasConstant * T), T, p, cp_vec[0]->fluid_id);//R_uni in mNs + // reactive component + x[0] = M1 * X / (M1 * X + M2 * (1.0 - X)); // mass in mole fraction + Vs[0] = Fluid_Viscosity(M2 * p / (PhysicalConstant::IdealGasConstant * T), T, p, cp_vec[1]->fluid_id); + // inert component + x[1] = 1.0 - x[0]; + Vs[1] = Fluid_Viscosity(M1 * p / (PhysicalConstant::IdealGasConstant * T), T, p, + cp_vec[0]->fluid_id); // R_uni in mNs - const double M1_over_M2 (M2/M1); //reactive over inert - const double V1_over_V2 (Vs[0]/Vs[1]); + const double M1_over_M2(M2 / M1); // reactive over inert + const double V1_over_V2(Vs[0] / Vs[1]); - const double phi_12 = (1.0 + pow(V1_over_V2,0.5) * pow(1.0/M1_over_M2,0.25)) - * (1.0 + pow(V1_over_V2,0.5) * pow(1.0/M1_over_M2,0.25)) - / pow(8.0*(1.0+M1_over_M2),0.5); - const double phi_21 = phi_12 * M1_over_M2 / V1_over_V2; + const double phi_12 = (1.0 + pow(V1_over_V2, 0.5) * pow(1.0 / M1_over_M2, 0.25)) + * (1.0 + pow(V1_over_V2, 0.5) * pow(1.0 / M1_over_M2, 0.25)) + / pow(8.0 * (1.0 + M1_over_M2), 0.5); + const double phi_21 = phi_12 * M1_over_M2 / V1_over_V2; - viscosity = Vs[0]*x[0] / (x[0] + x[1] * phi_12) - + Vs[1]*x[1] / (x[1] + x[0] * phi_21); + viscosity = Vs[0] * x[0] / (x[0] + x[1] * phi_12) + Vs[1] * x[1] / (x[1] + x[0] * phi_21); - break; - } - case 30: // exp(T) e.g Reynolds - viscosity = LiquidViscosity_expo(primary_variable[1]); - break; - default: - cout << "Error in CFluidProperties::Viscosity: no valid model" << "\n"; - break; + break; + } + case 30: // exp(T) e.g Reynolds + viscosity = LiquidViscosity_expo(primary_variable[1]); + break; + default: + cout << "Error in CFluidProperties::Viscosity: no valid model" + << "\n"; + break; } //---------------------------------------------------------------------- @@ -1651,19 +1693,19 @@ double CFluidProperties::Viscosity(double* variables) 08/2004 OK MFP implementation based on CalcFluidViscosityMethod7 by OK last modification: **************************************************************************/ -double CFluidProperties::GasViscosity_Reichenberg_1971(double p,double T) +double CFluidProperties::GasViscosity_Reichenberg_1971(double p, double T) { - double my,my0; - double A,B,C,D; - double Q,Pr,Tr; + double my, my0; + double A, B, C, D; + double Q, Pr, Tr; double alpha1, alpha2, beta1, beta2, gamma1, gamma2, delta1, delta2; - double a,c,d; - double pc,Tc; + double a, c, d; + double pc, Tc; alpha1 = 1.9824e-3; alpha2 = 5.2683; - beta1 = 1.6552; - beta2 = 1.2760; + beta1 = 1.6552; + beta2 = 1.2760; gamma1 = 0.1319; gamma2 = 3.7035; delta1 = 2.9496; @@ -1674,17 +1716,17 @@ double CFluidProperties::GasViscosity_Reichenberg_1971(double p,double T) Q = 1.0; Tc = 126.2; Tr = T / Tc; - pc = 33.9 * 10000.; /* bar->Pascal*/ + pc = 33.9 * 10000.; /* bar->Pascal*/ Pr = p / pc; - A = alpha1 / Tr* exp(alpha2 * pow(Tr,a)); + A = alpha1 / Tr * exp(alpha2 * pow(Tr, a)); B = A * (beta1 * Tr - beta2); - C = gamma1 / Tr* exp(gamma2 * pow(Tr,c)); - D = delta1 / Tr* exp(delta2 * pow(Tr,d)); + C = gamma1 / Tr * exp(gamma2 * pow(Tr, c)); + D = delta1 / Tr * exp(delta2 * pow(Tr, d)); /* Poise->Pa*s */ my0 = 26.69 * sqrt(28.96) * sqrt(T) / (3.7 * 3.7) * 1.e-6 * 0.1; - my = my0 * ( 1.0 + Q * (A * pow(Pr,1.5)) / (B * Pr + (1 / (1 + C * pow(Pr,D)))) ); + my = my0 * (1.0 + Q * (A * pow(Pr, 1.5)) / (B * Pr + (1 / (1 + C * pow(Pr, D))))); return my; } @@ -1702,25 +1744,25 @@ double CFluidProperties::GasViscosity_Reichenberg_1971(double p,double T) **************************************************************************/ double CFluidProperties::LiquidViscosity_Yaws_1976(double T) { - double ln_my,my; - double A,B,C,D; + double ln_my, my; + double A, B, C, D; A = -2.471e+01; - B = 4.209e+03; - C = 4.527e-02; + B = 4.209e+03; + C = 4.527e-02; D = -3.376e-5; - //A = -11.6225; // CB values for water viscosity after YAWS et al. (1976) - //B = 1.9490e+03; - //C = 2.1641e-02; - //D = -1.5990e-05; + // A = -11.6225; // CB values for water viscosity after YAWS et al. (1976) + // B = 1.9490e+03; + // C = 2.1641e-02; + // D = -1.5990e-05; - if (T>0) + if (T > 0) { ln_my = A + B / T + C * T + D * T * T; - my = exp(ln_my); /* in cP */ - //my = pow(10, ln_my); - my = my * 1.e-3; /* in Pa s */ + my = exp(ln_my); /* in cP */ + // my = pow(10, ln_my); + my = my * 1.e-3; /* in Pa s */ } else my = 1e-3; @@ -1741,13 +1783,13 @@ double CFluidProperties::LiquidViscosity_Marsily_1986(double T) { const double A = 2.29E-03, B = -1.01E-03; - //MW: coefficients are wrong! + // MW: coefficients are wrong! // log(T) gives natural logarithm, here decadal log is needed. // There is no benchmark for this, so nobody noticed... - //my = 2.285e-5 + 1.01e-3 * log(T); + // my = 2.285e-5 + 1.01e-3 * log(T); - if (T>0) - return A + B * log10(T); // T in Celsius needed + if (T > 0) + return A + B * log10(T); // T in Celsius needed else return 0.001758784; } @@ -1762,12 +1804,12 @@ double CFluidProperties::LiquidViscosity_Marsily_1986(double T) 08/2004 OK MFP implementation last modification: **************************************************************************/ -double CFluidProperties::LiquidViscosity_NN(double c,double T) +double CFluidProperties::LiquidViscosity_NN(double c, double T) { double f1, f2, mu0 = 0.001, mu; double omega0, omega, sigma0, sigma; - if (rho_0 < MKleinsteZahl || T_0 < MKleinsteZahl) + if (rho_0 < MKleinsteZahl || T_0 < MKleinsteZahl) return 0.; omega = c / rho_0; @@ -1775,10 +1817,10 @@ double CFluidProperties::LiquidViscosity_NN(double c,double T) sigma = (T - T_0) / T_0; sigma0 = 0.; - f1 = (1. + 1.85 * omega0 - 4.1 * omega0 * omega0 + 44.5 * omega0 * omega0 * omega0) / - (1. + 1.85 * omega - 4.1 * omega * omega + 44.5 * omega * omega * omega); - f2 = (1 + 0.7063 * sigma - 0.04832 * sigma * sigma * sigma) / - (1 + 0.7063 * sigma0 - 0.04832 * sigma0 * sigma * sigma0); + f1 = (1. + 1.85 * omega0 - 4.1 * omega0 * omega0 + 44.5 * omega0 * omega0 * omega0) + / (1. + 1.85 * omega - 4.1 * omega * omega + 44.5 * omega * omega * omega); + f2 = (1 + 0.7063 * sigma - 0.04832 * sigma * sigma * sigma) + / (1 + 0.7063 * sigma0 - 0.04832 * sigma0 * sigma * sigma0); mu = mu0 / (f1 + f2); return mu; } @@ -1793,55 +1835,53 @@ Task: Master calc function **************************************************************************/ double CFluidProperties::PhaseDiffusion(double* variables) { - static double diff; - //int fct_number = 0; - //int gueltig; - //double mfp_arguments[2]; - //double density; - - // double TTT=0, PPP=0; - // long Element_Index; - // int nod_index; - - // string val_name; - //CRFProcess* m_pcs = NULL; + static double diff; + // int fct_number = 0; + // int gueltig; + // double mfp_arguments[2]; + // double density; - //---------------------------------------------------------------------- - //bool New = false; // To be - //if(fem_msh_vector.size()>0) New = true; + // double TTT=0, PPP=0; + // long Element_Index; + // int nod_index; - //---------------------------------------------------------------------- - if(variables) //OK4709: faster data access - { - primary_variable[0] = variables[0]; //p (single phase)// SP: has to be T - primary_variable[1] = variables[1]; //T (temperature) // SP: has to be p - primary_variable[2] = variables[2]; //C (salinity)//index in case of AIR_FLOW + // string val_name; + // CRFProcess* m_pcs = NULL; - } - else - { - CalPrimaryVariable(phase_diffusion_pcs_name_vector); - } - //---------------------------------------------------------------------- - switch(diffusion_model) - { - //case 0: // rho = f(x) - // diff = GetCurveValue(fct_number,0,primary_variable[0],&gueltig); - // break; - case 1: // my = const - diff = diffusion; - break; - case 2: // my(p) = my_0*(1+gamma_p*(p-p_0)) - diff = PhaseDiffusion_Yaws_1976(primary_variable[1]); - break; - default: - cout << "Error in CFluidProperties::PhaseDiffusion: no valid model" << endl; - break; - } - //---------------------------------------------------------------------- + //---------------------------------------------------------------------- + // bool New = false; // To be + // if(fem_msh_vector.size()>0) New = true; - return diff; + //---------------------------------------------------------------------- + if (variables) // OK4709: faster data access + { + primary_variable[0] = variables[0]; // p (single phase)// SP: has to be T + primary_variable[1] = variables[1]; // T (temperature) // SP: has to be p + primary_variable[2] = variables[2]; // C (salinity)//index in case of AIR_FLOW + } + else + { + CalPrimaryVariable(phase_diffusion_pcs_name_vector); + } + //---------------------------------------------------------------------- + switch (diffusion_model) + { + // case 0: // rho = f(x) + // diff = GetCurveValue(fct_number,0,primary_variable[0],&gueltig); + // break; + case 1: // my = const + diff = diffusion; + break; + case 2: // my(p) = my_0*(1+gamma_p*(p-p_0)) + diff = PhaseDiffusion_Yaws_1976(primary_variable[1]); + break; + default: + cout << "Error in CFluidProperties::PhaseDiffusion: no valid model" << endl; + break; + } + //---------------------------------------------------------------------- + return diff; } /************************************************************************** @@ -1856,13 +1896,13 @@ FEMLib-Method: **************************************************************************/ double CFluidProperties::PhaseDiffusion_Yaws_1976(double T) { - double A,B; + double A, B; - A = A_Daq; - B = B_Daq; + A = A_Daq; + B = B_Daq; - diff = pow(10, (A+(B/T))) / 10000; //cm�/s -> m�/s - return diff; + diff = pow(10, (A + (B / T))) / 10000; // cm�/s -> m�/s + return diff; } //////////////////////////////////////////////////////////////////////////// @@ -1877,99 +1917,101 @@ double CFluidProperties::PhaseDiffusion_Yaws_1976(double T) 11/2005 CMCD edited cases and expanded case 3 & 4 last modification: NB Jan 09 4.9.05 **************************************************************************/ -//NB +// NB double CFluidProperties::SpecificHeatCapacity(double* variables) { - CRFProcess* m_pcs; - m_pcs = PCSGet("MULTI_COMPONENTIAL_FLOW"); + CRFProcess* m_pcs; + m_pcs = PCSGet("MULTI_COMPONENTIAL_FLOW"); double Cp = 0.0; double x[2], Cp_c[2]; int gueltig = -1; double pressure, saturation, temperature; - if(variables) //NB Jan 09 + if (variables) // NB Jan 09 { - primary_variable[0] = variables[0]; //p (single phase) - primary_variable[1] = variables[1]; //T (temperature) - primary_variable[2] = variables[2]; //ELE index + primary_variable[0] = variables[0]; // p (single phase) + primary_variable[1] = variables[1]; // T (temperature) + primary_variable[2] = variables[2]; // ELE index } else CalPrimaryVariable(specific_heat_capacity_pcs_name_vector); pressure = primary_variable[0]; - temperature = primary_variable[1]; + temperature = primary_variable[1]; saturation = primary_variable[2]; //...................................................................... // - switch(heat_capacity_model) + switch (heat_capacity_model) { - case 0: // c = f(x) - specific_heat_capacity = GetCurveValue(0,0,temperature,&gueltig); - break; - case 1: // c = const, value already read in to specific_heat_capacity - break; - case 2: // c = f(p,T,Conc) - specific_heat_capacity = MATCalcFluidHeatCapacityMethod2(pressure,temperature,saturation); - break; - case 5: - specific_heat_capacity = GetCurveValue(heat_phase_change_curve,0, temperature_buffer, &gueltig); - break; - case 9: - specific_heat_capacity = isobaric_heat_capacity(Density(primary_variable), primary_variable[1], fluid_id); - break; - case 11: //mole fraction weighted average of molar isochoric specific heat capacities converted into isobaric mixture specific heat capacity (ideal conversion) - { - //reactive component - const double M1 = cp_vec[0]->molar_mass; - const double M2 = cp_vec[1]->molar_mass; - const double p = variables[0]; - const double T = variables[1]; - const double X = variables[2]; - - x[0] = M1 * X / (M1 * X + M2 * (1.0-X) ); //mass in mole fraction - therm_prop("W"); - const double R = PhysicalConstant::IdealGasConstant; - Cp_c[0] = isochoric_heat_capacity(M2*p/(R*T), T,cp_vec[1]->fluid_id); - //inert component - x[1] = 1.0 - x[0]; - therm_prop("N"); - Cp_c[1] = isochoric_heat_capacity(M1*p/(R*T), T,cp_vec[0]->fluid_id); - specific_heat_capacity = Cp_c[0]*M2*x[0] + Cp_c[1]*M1*x[1]; //mixture isochoric molar heat capacities - specific_heat_capacity += R; //isochoric in isobaric - specific_heat_capacity /= (M1*x[1] + M2*x[0]); //molar in specific of mixture value - break; - } - case 12: //mass fraction weighted average of isobaric specific heat capacities using a linearised model - //reactive component - x[0] = variables[2]; //mass fraction - Cp_c[0] = linear_heat_capacity(variables[1],cp_vec[1]->fluid_id); - //inert component + case 0: // c = f(x) + specific_heat_capacity = GetCurveValue(0, 0, temperature, &gueltig); + break; + case 1: // c = const, value already read in to specific_heat_capacity + break; + case 2: // c = f(p,T,Conc) + specific_heat_capacity = MATCalcFluidHeatCapacityMethod2(pressure, temperature, saturation); + break; + case 5: + specific_heat_capacity = GetCurveValue(heat_phase_change_curve, 0, temperature_buffer, &gueltig); + break; + case 9: + specific_heat_capacity = isobaric_heat_capacity(Density(primary_variable), primary_variable[1], fluid_id); + break; + case 11: // mole fraction weighted average of molar isochoric specific heat capacities converted into isobaric + // mixture specific heat capacity (ideal conversion) + { + // reactive component + const double M1 = cp_vec[0]->molar_mass; + const double M2 = cp_vec[1]->molar_mass; + const double p = variables[0]; + const double T = variables[1]; + const double X = variables[2]; + + x[0] = M1 * X / (M1 * X + M2 * (1.0 - X)); // mass in mole fraction + therm_prop("W"); + const double R = PhysicalConstant::IdealGasConstant; + Cp_c[0] = isochoric_heat_capacity(M2 * p / (R * T), T, cp_vec[1]->fluid_id); + // inert component + x[1] = 1.0 - x[0]; + therm_prop("N"); + Cp_c[1] = isochoric_heat_capacity(M1 * p / (R * T), T, cp_vec[0]->fluid_id); + specific_heat_capacity + = Cp_c[0] * M2 * x[0] + Cp_c[1] * M1 * x[1]; // mixture isochoric molar heat capacities + specific_heat_capacity += R; // isochoric in isobaric + specific_heat_capacity /= (M1 * x[1] + M2 * x[0]); // molar in specific of mixture value + break; + } + case 12: // mass fraction weighted average of isobaric specific heat capacities using a linearised model + // reactive component + x[0] = variables[2]; // mass fraction + Cp_c[0] = linear_heat_capacity(variables[1], cp_vec[1]->fluid_id); + // inert component x[1] = 1.0 - x[0]; - Cp_c[1] = linear_heat_capacity(variables[1],cp_vec[0]->fluid_id); - specific_heat_capacity = Cp_c[0]*x[0] + Cp_c[1]*x[1]; //mixture isobaric specific heat capacities - break; - case 15: // mixture cp= sum_i y_i*cp:: P, T, x dependent - for (int CIndex = 2; CIndex < cmpN + 2; CIndex++) - { - if(eos_name == "CONSTANT") - { - Cp += variables[CIndex]*cp[CIndex-2]; - } - else - { - therm_prop(m_pcs->pcs_primary_function_name[CIndex]); - Cp += variables[CIndex]*isobaric_heat_capacity(ComponentDensity(CIndex, variables), variables[1], fluid_id); - } - } - specific_heat_capacity = Cp; + Cp_c[1] = linear_heat_capacity(variables[1], cp_vec[0]->fluid_id); + specific_heat_capacity = Cp_c[0] * x[0] + Cp_c[1] * x[1]; // mixture isobaric specific heat capacities + break; + case 15: // mixture cp= sum_i y_i*cp:: P, T, x dependent + for (int CIndex = 2; CIndex < cmpN + 2; CIndex++) + { + if (eos_name == "CONSTANT") + { + Cp += variables[CIndex] * cp[CIndex - 2]; + } + else + { + therm_prop(m_pcs->pcs_primary_function_name[CIndex]); + Cp += variables[CIndex] + * isobaric_heat_capacity(ComponentDensity(CIndex, variables), variables[1], fluid_id); + } + } + specific_heat_capacity = Cp; - break; + break; } return specific_heat_capacity; } - /************************************************************************** FEMLib-Method: Task: calculate heat capacity for phase change @@ -1981,49 +2023,46 @@ double CFluidProperties::PhaseChange() { int gueltig = -1; double heat_capacity_phase_change = 0; - double pressure; //WW , saturation, temperature; + double pressure; // WW , saturation, temperature; double density_vapor, humi, drdT; - double H1,H0,T0,T_1; //T1 defined at 662 in steam67??? + double H1, H0, T0, T_1; // T1 defined at 662 in steam67??? //...................................................................... CalPrimaryVariable(specific_heat_capacity_pcs_name_vector); pressure = primary_variable[0]; - //WW temperature = primary_variable[1]; - //WW saturation = primary_variable[2]; + // WW temperature = primary_variable[1]; + // WW saturation = primary_variable[2]; - if(heat_capacity_model == 3) + if (heat_capacity_model == 3) { T_1 = primary_variable_t1[1]; - if(T_1 <= T_Latent1 || T_1 >= T_Latent2) - heat_capacity_phase_change = GetCurveValue(heat_phase_change_curve, - 0, - temperature_buffer, - &gueltig); + if (T_1 <= T_Latent1 || T_1 >= T_Latent2) + heat_capacity_phase_change = GetCurveValue(heat_phase_change_curve, 0, temperature_buffer, &gueltig); else { heat_capacity_model = 5; // ??? JOD H1 = CalcEnthalpy(T_1); T0 = primary_variable_t0[1]; - if(fabs(T_1 - T0) < 1.0e-8) + if (fabs(T_1 - T0) < 1.0e-8) T_1 += 1.0e-8; H0 = CalcEnthalpy(T0); heat_capacity_phase_change = (H1 - H0) / (T_1 - T_0); heat_capacity_model = 3; } } - else if(heat_capacity_model == 4) + else if (heat_capacity_model == 4) { T_1 = primary_variable_t1[1]; - if(T_1 <= T_Latent1 || T_1 >= T_Latent2) + if (T_1 <= T_Latent1 || T_1 >= T_Latent2) { - humi = exp( pressure / ( PhysicalConstant::SpecificGasConstant::WaterVapour * temperature_buffer * Density() ) ); + humi + = exp(pressure / (PhysicalConstant::SpecificGasConstant::WaterVapour * temperature_buffer * Density())); density_vapor = humi * Density(); - drdT = ( vaporDensity_derivative( temperature_buffer ) * humi \ - - density_vapor * pressure / - ( PhysicalConstant::SpecificGasConstant::WaterVapour * Density() * - (temperature_buffer * temperature_buffer) ) ) / Density(); - H1 = latent_heat + specific_heat_capacity * - ( temperature_buffer - T_Latent1); + drdT = (vaporDensity_derivative(temperature_buffer) * humi + - density_vapor * pressure / (PhysicalConstant::SpecificGasConstant::WaterVapour * Density() + * (temperature_buffer * temperature_buffer))) + / Density(); + H1 = latent_heat + specific_heat_capacity * (temperature_buffer - T_Latent1); heat_capacity_phase_change = H1 * drdT; } else @@ -2031,7 +2070,7 @@ double CFluidProperties::PhaseChange() heat_capacity_model = 5; H1 = CalcEnthalpy(T_1); T0 = primary_variable_t0[1]; - if(fabs(T_1 - T0) < 1.0e-8) + if (fabs(T_1 - T0) < 1.0e-8) T_1 += 1.0e-8; H0 = CalcEnthalpy(T0); heat_capacity_phase_change = (H1 - H0) / (T_1 - T0); @@ -2051,62 +2090,57 @@ double CFluidProperties::PhaseChange() double MFPCalcFluidsHeatCapacity(CFiniteElementStd* assem) { double heat_capacity_fluids = 0.0; - double PG = 0.0, Sw = 0.0,TG,rhow,rho_gw,p_gw,dens_aug[3],rho_g; + double PG = 0.0, Sw = 0.0, TG, rhow, rho_gw, p_gw, dens_aug[3], rho_g; CFluidProperties* m_mfp = NULL; CRFProcess* m_pcs = assem->cpl_pcs; - //if (m_pcs->pcs_type_name.find("MULTI_PHASE_FLOW")!=string::npos) - if (m_pcs && m_pcs->type == 1212) // non-isothermal multi-phase flow - { - // Capillary pressure - PG = assem->interpolate(assem->NodalValC1); - Sw = assem->MediaProp->SaturationCapillaryPressureFunction(PG); - double PG2 = assem->interpolate(assem->NodalVal_p2); - TG = assem->interpolate(assem->NodalVal1) + PhysicalConstant::CelsiusZeroInKelvin; - rhow = assem->FluidProp->Density(); - rho_gw = assem->FluidProp->vaporDensity(TG) * exp( - -PG / (rhow * SpecificGasConstant::WaterVapour * TG)); - p_gw = rho_gw * SpecificGasConstant::WaterVapour * TG; - dens_aug[0] = PG2 - p_gw; - dens_aug[1] = TG; - m_mfp = mfp_vector[1]; - // 2 Dec 2010 AKS - rho_g = rho_gw + m_mfp->Density(dens_aug); - //double rho_g = PG2*FluidConstant::ComponentMolarMassAir() /(FluidConstant::GasConstant()*(assem->TG+273.15));\\WW - // - m_mfp = mfp_vector[0]; - heat_capacity_fluids = Sw * m_mfp->Density() * m_mfp->SpecificHeatCapacity(); - m_mfp = mfp_vector[1]; - heat_capacity_fluids += (1.0 - Sw) * rho_g * m_mfp->SpecificHeatCapacity(); - } + // if (m_pcs->pcs_type_name.find("MULTI_PHASE_FLOW")!=string::npos) + if (m_pcs && m_pcs->type == 1212) // non-isothermal multi-phase flow + { + // Capillary pressure + PG = assem->interpolate(assem->NodalValC1); + Sw = assem->MediaProp->SaturationCapillaryPressureFunction(PG); + double PG2 = assem->interpolate(assem->NodalVal_p2); + TG = assem->interpolate(assem->NodalVal1) + PhysicalConstant::CelsiusZeroInKelvin; + rhow = assem->FluidProp->Density(); + rho_gw = assem->FluidProp->vaporDensity(TG) * exp(-PG / (rhow * SpecificGasConstant::WaterVapour * TG)); + p_gw = rho_gw * SpecificGasConstant::WaterVapour * TG; + dens_aug[0] = PG2 - p_gw; + dens_aug[1] = TG; + m_mfp = mfp_vector[1]; + // 2 Dec 2010 AKS + rho_g = rho_gw + m_mfp->Density(dens_aug); + // double rho_g = PG2*FluidConstant::ComponentMolarMassAir() + // /(FluidConstant::GasConstant()*(assem->TG+273.15));\\WW + // + m_mfp = mfp_vector[0]; + heat_capacity_fluids = Sw * m_mfp->Density() * m_mfp->SpecificHeatCapacity(); + m_mfp = mfp_vector[1]; + heat_capacity_fluids += (1.0 - Sw) * rho_g * m_mfp->SpecificHeatCapacity(); + } - else + else + { + heat_capacity_fluids = assem->FluidProp->Density() * assem->FluidProp->SpecificHeatCapacity(); + + if (m_pcs && m_pcs->type != 1) // neither liquid nor ground water flow { - heat_capacity_fluids = assem->FluidProp->Density() * - assem->FluidProp->SpecificHeatCapacity(); + // pressure + PG = assem->interpolate(assem->NodalValC1); - if(m_pcs && m_pcs->type != 1) // neither liquid nor ground water flow + if (PG < 0.0) { - // pressure - PG = assem->interpolate(assem->NodalValC1); - - if(PG < 0.0) - { - Sw = assem->MediaProp->SaturationCapillaryPressureFunction(-PG); - heat_capacity_fluids *= Sw; - if( assem->GasProp != 0) - heat_capacity_fluids += - (1. - - Sw) * assem->GasProp->Density() * - assem->GasProp->SpecificHeatCapacity(); - heat_capacity_fluids += - (1. - Sw) * assem->FluidProp->PhaseChange(); - } + Sw = assem->MediaProp->SaturationCapillaryPressureFunction(-PG); + heat_capacity_fluids *= Sw; + if (assem->GasProp != 0) + heat_capacity_fluids + += (1. - Sw) * assem->GasProp->Density() * assem->GasProp->SpecificHeatCapacity(); + heat_capacity_fluids += (1. - Sw) * assem->FluidProp->PhaseChange(); } } + } return heat_capacity_fluids; } - /************************************************************************** FEMLib-Method: Task: Master calc function @@ -2185,96 +2219,96 @@ double MFPCalcFluidsHeatCapacity(CFiniteElementStd* assem) last modification: NB 4.9.05 **************************************************************************/ -//NB Dec 08 4.9.05 +// NB Dec 08 4.9.05 double CFluidProperties::HeatConductivity(double* variables) { - if(variables) //NB Dec 08 + if (variables) // NB Dec 08 { - primary_variable[0] = variables[0]; //p (single phase) - primary_variable[1] = variables[1]; //T (temperature) - primary_variable[2] = variables[2]; //ELE index + primary_variable[0] = variables[0]; // p (single phase) + primary_variable[1] = variables[1]; // T (temperature) + primary_variable[2] = variables[2]; // ELE index } else CalPrimaryVariable(heat_conductivity_pcs_name_vector); - switch(heat_conductivity_model) - { - case 0: // rho = f(x) + switch (heat_conductivity_model) { - int fct_number = 0; - int gueltig; - heat_conductivity = GetCurveValue(fct_number,0,primary_variable[0],&gueltig); - } - break; - case 1: // c = const - heat_conductivity = heat_conductivity; - break; - case 2: - heat_conductivity = MATCalcHeatConductivityMethod2(primary_variable[0], - primary_variable[1], - primary_variable[2]); - break; - case 3: // NB - heat_conductivity = Fluid_Heat_Conductivity (Density(),primary_variable[1],fluid_id); - // if (heat_conductivity<0.03) // not sure about this - break; - case 9: - heat_conductivity = Fluid_Heat_Conductivity(Density(primary_variable), primary_variable[1], fluid_id); - break; - - case 11: //Wassilijewa, Maso&Saxena (see Poling, B. E.; Prausnitz, J. M.; John Paul, O. & Reid, R. C. The properties of gases and liquids McGraw-Hill New York, 2001, 5: page 10.30f.) + case 0: // rho = f(x) { - double x[2], k[2]; - const double M0 = cp_vec[0]->molar_mass; - const double M1 = cp_vec[1]->molar_mass; - const double p = variables[0]; - const double T = variables[1]; - const double X = variables[2]; - - // TODO [CL] max() is redundant if the fraction is guaranteed to be between 0 and 1. - //reactive component - const double R = PhysicalConstant::IdealGasConstant; - x[0] = max(M0*X/(M0*X + M1*(1.0-X)), 0.); // convert mass to mole fraction - k[0] = Fluid_Heat_Conductivity(M1*p/(R * T), T, cp_vec[1]->fluid_id); - //inert component - x[1] = 1.0 - x[0]; - k[1] = Fluid_Heat_Conductivity(M0*p/(R * T), T, cp_vec[0]->fluid_id); - - const double M1_over_M2 = M1/M0; //reactive over inert - const double V1_over_V2 = Fluid_Viscosity(M1*p/(R * T), T, p, cp_vec[1]->fluid_id) - / Fluid_Viscosity(M0*p/(R * T), T, p, cp_vec[0]->fluid_id); - const double L1_over_L2 = V1_over_V2 / M1_over_M2; - - const double phi_12 = (1.0 + pow(L1_over_L2, 0.5) * pow(M1_over_M2, -0.25)) - * (1.0 + pow(V1_over_V2, 0.5) * pow(M1_over_M2, -0.25)) - / pow(8.0 * (1.0 + M1_over_M2), 0.5); - const double phi_21 = phi_12 * M1_over_M2 / V1_over_V2; - - heat_conductivity = k[0]*x[0]/(x[0]+x[1]*phi_12); - heat_conductivity += k[1]*x[1]/(x[1]+x[0]*phi_21); - break; + int fct_number = 0; + int gueltig; + heat_conductivity = GetCurveValue(fct_number, 0, primary_variable[0], &gueltig); } - case 15: // mixture k_m= sum_i y_i*k_i:: p, T, x - { - CRFProcess* m_pcs = PCSGet("MULTI_COMPONENTIAL_FLOW"); - double Kappa = 0.0; + break; + case 1: // c = const + heat_conductivity = heat_conductivity; + break; + case 2: + heat_conductivity + = MATCalcHeatConductivityMethod2(primary_variable[0], primary_variable[1], primary_variable[2]); + break; + case 3: // NB + heat_conductivity = Fluid_Heat_Conductivity(Density(), primary_variable[1], fluid_id); + // if (heat_conductivity<0.03) // not sure about this + break; + case 9: + heat_conductivity = Fluid_Heat_Conductivity(Density(primary_variable), primary_variable[1], fluid_id); + break; - for (int CIndex = 2; CIndex < cmpN + 2; CIndex++) - { - if(eos_name == "CONSTANT") + case 11: // Wassilijewa, Maso&Saxena (see Poling, B. E.; Prausnitz, J. M.; John Paul, O. & Reid, R. C. The + // properties of gases and liquids McGraw-Hill New York, 2001, 5: page 10.30f.) { - Kappa += variables[CIndex]*kappa[CIndex-2]; + double x[2], k[2]; + const double M0 = cp_vec[0]->molar_mass; + const double M1 = cp_vec[1]->molar_mass; + const double p = variables[0]; + const double T = variables[1]; + const double X = variables[2]; + + // TODO [CL] max() is redundant if the fraction is guaranteed to be between 0 and 1. + // reactive component + const double R = PhysicalConstant::IdealGasConstant; + x[0] = max(M0 * X / (M0 * X + M1 * (1.0 - X)), 0.); // convert mass to mole fraction + k[0] = Fluid_Heat_Conductivity(M1 * p / (R * T), T, cp_vec[1]->fluid_id); + // inert component + x[1] = 1.0 - x[0]; + k[1] = Fluid_Heat_Conductivity(M0 * p / (R * T), T, cp_vec[0]->fluid_id); + + const double M1_over_M2 = M1 / M0; // reactive over inert + const double V1_over_V2 = Fluid_Viscosity(M1 * p / (R * T), T, p, cp_vec[1]->fluid_id) + / Fluid_Viscosity(M0 * p / (R * T), T, p, cp_vec[0]->fluid_id); + const double L1_over_L2 = V1_over_V2 / M1_over_M2; + + const double phi_12 = (1.0 + pow(L1_over_L2, 0.5) * pow(M1_over_M2, -0.25)) + * (1.0 + pow(V1_over_V2, 0.5) * pow(M1_over_M2, -0.25)) + / pow(8.0 * (1.0 + M1_over_M2), 0.5); + const double phi_21 = phi_12 * M1_over_M2 / V1_over_V2; + + heat_conductivity = k[0] * x[0] / (x[0] + x[1] * phi_12); + heat_conductivity += k[1] * x[1] / (x[1] + x[0] * phi_21); + break; } - else + case 15: // mixture k_m= sum_i y_i*k_i:: p, T, x + { + CRFProcess* m_pcs = PCSGet("MULTI_COMPONENTIAL_FLOW"); + double Kappa = 0.0; + + for (int CIndex = 2; CIndex < cmpN + 2; CIndex++) { - therm_prop(m_pcs->pcs_primary_function_name[CIndex]); - Kappa += variables[CIndex]*Fluid_Heat_Conductivity(ComponentDensity(CIndex, variables), variables[1], fluid_id); + if (eos_name == "CONSTANT") + { + Kappa += variables[CIndex] * kappa[CIndex - 2]; + } + else + { + therm_prop(m_pcs->pcs_primary_function_name[CIndex]); + Kappa += variables[CIndex] + * Fluid_Heat_Conductivity(ComponentDensity(CIndex, variables), variables[1], fluid_id); + } } + heat_conductivity = Kappa; } - heat_conductivity = Kappa; - } break; - } return heat_conductivity; @@ -2288,61 +2322,60 @@ double CFluidProperties::HeatConductivity(double* variables) last modification: 10/2010 TF changed access to process type **************************************************************************/ -double MFPCalcFluidsHeatConductivity(long index,double* gp,double theta, CFiniteElementStd* assem) +double MFPCalcFluidsHeatConductivity(long index, double* gp, double theta, CFiniteElementStd* assem) { - gp = gp; //OK411 + gp = gp; // OK411 index = index; - double saturation_phase = 0.0; //OK411 + double saturation_phase = 0.0; // OK411 double heat_conductivity_fluids = 0.0; - int nidx0,nidx1; - bool New = false; // To be removed. WW - if(fem_msh_vector.size() > 0) + int nidx0, nidx1; + bool New = false; // To be removed. WW + if (fem_msh_vector.size() > 0) New = true; //-------------------------------------------------------------------- //---------------------------------------------------------------------- CFluidProperties* m_mfp = NULL; int no_fluids = (int)mfp_vector.size(); - //YD----------- + // YD----------- CRFProcess* m_pcs = NULL; - for(int i = 0; i < (int)pcs_vector.size(); i++) + for (int i = 0; i < (int)pcs_vector.size(); i++) { m_pcs = pcs_vector[i]; // if(m_pcs->pcs_type_name.find("RICHARDS_FLOW")) - if(m_pcs->getProcessType () == FiniteElement::RICHARDS_FLOW) + if (m_pcs->getProcessType() == FiniteElement::RICHARDS_FLOW) no_fluids = 1; } - //YD----------- - switch(no_fluids) + // YD----------- + switch (no_fluids) { - case 1: - m_mfp = mfp_vector[0]; - heat_conductivity_fluids = m_mfp->HeatConductivity(); - break; - case 2: - m_mfp = mfp_vector[0]; - if(New) //WW - { - nidx0 = m_pcs->GetNodeValueIndex("SATURATION1"); - nidx1 = nidx0 + 1; - saturation_phase = (1. - theta) * assem->interpolate(nidx0,m_pcs) - + theta* assem->interpolate(nidx1,m_pcs); - } - heat_conductivity_fluids = saturation_phase - * m_mfp->HeatConductivity(); - m_mfp = mfp_vector[1]; - heat_conductivity_fluids += (1.0 - saturation_phase ) - * m_mfp->HeatConductivity(); - break; - default: - cout << "Error in MFPCalcFluidsHeatConductivity: no fluid phase data" << "\n"; + case 1: + m_mfp = mfp_vector[0]; + heat_conductivity_fluids = m_mfp->HeatConductivity(); + break; + case 2: + m_mfp = mfp_vector[0]; + if (New) // WW + { + nidx0 = m_pcs->GetNodeValueIndex("SATURATION1"); + nidx1 = nidx0 + 1; + saturation_phase + = (1. - theta) * assem->interpolate(nidx0, m_pcs) + theta * assem->interpolate(nidx1, m_pcs); + } + heat_conductivity_fluids = saturation_phase * m_mfp->HeatConductivity(); + m_mfp = mfp_vector[1]; + heat_conductivity_fluids += (1.0 - saturation_phase) * m_mfp->HeatConductivity(); + break; + default: + cout << "Error in MFPCalcFluidsHeatConductivity: no fluid phase data" + << "\n"; } return heat_conductivity_fluids; } //////////////////////////////////////////////////////////////////////////// // Fluid phase change properties -#ifdef obsolete //WW +#ifdef obsolete // WW /************************************************************************** FEMLib-Method: Task: Vapour pressure from table @@ -2375,23 +2408,23 @@ double MFPCalcVapourPressure(double temperature) ((vapour_enthalpy*FluidConstant::ComponentMolarMassWater())/FluidConstant::GasConstant()); vapour_pressure = pressure_ref * exp(potenz); */ - pressure = 1.e-3; /*Vorgabe eines vernueftigen Wertes*/ - pressure *= PA2PSI; /* Umrechnung Pa in psia */ - temperature -= 273.15; /* Kelvin -> Celsius */ + pressure = 1.e-3; /*Vorgabe eines vernueftigen Wertes*/ + pressure *= PA2PSI; /* Umrechnung Pa in psia */ + temperature -= 273.15; /* Kelvin -> Celsius */ temperature_F = temperature * 1.8 + 32.; /* Umrechnung Celsius in Fahrenheit */ - steam67 (&temperature_F, - &pressure, - &quality, - &weight, - &enthalpy, - &entropy, - &saturation_temperature, - &saturation_pressure, - °rees_superheat, - °rees_subcooling, - &viscosity, - &critical_velocity, - action); + steam67(&temperature_F, + &pressure, + &quality, + &weight, + &enthalpy, + &entropy, + &saturation_temperature, + &saturation_pressure, + °rees_superheat, + °rees_subcooling, + &viscosity, + &critical_velocity, + action); pressure_vapour = saturation_pressure * PSI2PA; /* Umrechnung psia in Pa */ /* density_vapour = 0.062427962/weight; Dichte in kg/m^3 @@ -2408,7 +2441,7 @@ double MFPCalcVapourPressure(double temperature) 08/2004 OK MFP implementation last modification: **************************************************************************/ -double CFluidProperties::Enthalpy(int comp,double temperature) +double CFluidProperties::Enthalpy(int comp, double temperature) { double temperature_F; double pressure; @@ -2424,34 +2457,34 @@ double CFluidProperties::Enthalpy(int comp,double temperature) double critical_velocity; int action = 0; - if((phase == 0) && (comp == 0)) - enthalpy = 733.0 * temperature + - (FluidConstant::GasConstant() * (temperature + 0.0)) / FluidConstant::ComponentMolarMassAir() ; - else if((phase == 0) && (comp == 1)) /* h_w^g: water species in gaseous phase */ + if ((phase == 0) && (comp == 0)) + enthalpy = 733.0 * temperature + + (FluidConstant::GasConstant() * (temperature + 0.0)) / FluidConstant::ComponentMolarMassAir(); + else if ((phase == 0) && (comp == 1)) /* h_w^g: water species in gaseous phase */ { - pressure = 1.e-3; /*Vorgabe eines vernuenftigen Wertes */ - pressure *= PA2PSI; /* Umrechnung Pa in psia */ - temperature -= 273.15; /* Kelvin -> Celsius */ + pressure = 1.e-3; /*Vorgabe eines vernuenftigen Wertes */ + pressure *= PA2PSI; /* Umrechnung Pa in psia */ + temperature -= 273.15; /* Kelvin -> Celsius */ temperature_F = temperature * 1.8 + 32.; /* Umrechnung Celsius in Fahrenheit*/ - steam67 (&temperature_F, - &pressure, - &quality, - &weight, - &enthalpy, - &entropy, - &saturation_temperature, - &saturation_pressure, - °rees_superheat, - °rees_subcooling, - &viscosity, - &critical_velocity, - action); + steam67(&temperature_F, + &pressure, + &quality, + &weight, + &enthalpy, + &entropy, + &saturation_temperature, + &saturation_pressure, + °rees_superheat, + °rees_subcooling, + &viscosity, + &critical_velocity, + action); enthalpy = enthalpy * 1055. / 0.454; /* Umrechnung von btu/lbm in J/kg */ } - else if((phase == 1) && (comp == 0)) /* h_a^l: air species in liquid phase */ + else if ((phase == 1) && (comp == 0)) /* h_a^l: air species in liquid phase */ { } - else if((phase == 1) && (comp == 1)) /* h_w^l: water species in liquid phase */ + else if ((phase == 1) && (comp == 1)) /* h_w^l: water species in liquid phase */ { } return enthalpy; @@ -2465,38 +2498,37 @@ double CFluidProperties::Enthalpy(int comp,double temperature) 08/2004 OK MFP implementation last modification: **************************************************************************/ -double CFluidProperties::EnthalpyPhase(long number,int comp,double* gp,double theta) +double CFluidProperties::EnthalpyPhase(long number, int comp, double* gp, double theta) { double temperature; double enthalpy = 0.0; - double mass_fraction_air,enthalpy_air,mass_fraction_water,enthalpy_water; - int nidx0,nidx1; + double mass_fraction_air, enthalpy_air, mass_fraction_water, enthalpy_water; + int nidx0, nidx1; - nidx0 = PCSGetNODValueIndex("TEMPERATURE1",0); - nidx1 = PCSGetNODValueIndex("TEMPERATURE1",1); - temperature = (1. - theta) * InterpolValue(number,nidx0,gp[0],gp[1],gp[2]) \ - + theta* InterpolValue(number,nidx1,gp[0],gp[1],gp[2]); + nidx0 = PCSGetNODValueIndex("TEMPERATURE1", 0); + nidx1 = PCSGetNODValueIndex("TEMPERATURE1", 1); + temperature = (1. - theta) * InterpolValue(number, nidx0, gp[0], gp[1], gp[2]) + + theta * InterpolValue(number, nidx1, gp[0], gp[1], gp[2]); - if(phase == 0) + if (phase == 0) { - if(comp < 0) + if (comp < 0) { comp = 0; - mass_fraction_air = MassFraction(number,comp,gp,theta); + mass_fraction_air = MassFraction(number, comp, gp, theta); comp = 1; - mass_fraction_water = MassFraction(number,comp,gp,theta); + mass_fraction_water = MassFraction(number, comp, gp, theta); comp = 0; - enthalpy_air = Enthalpy(comp,temperature); + enthalpy_air = Enthalpy(comp, temperature); comp = 1; - enthalpy_water = Enthalpy(comp,temperature); + enthalpy_water = Enthalpy(comp, temperature); - enthalpy = mass_fraction_air * enthalpy_air + \ - mass_fraction_water * enthalpy_water; + enthalpy = mass_fraction_air * enthalpy_air + mass_fraction_water * enthalpy_water; } else if (comp >= 0) - enthalpy = Enthalpy(comp,temperature); + enthalpy = Enthalpy(comp, temperature); } - else if(phase == 1) + else if (phase == 1) // enthalpy = SpecificHeatCapacity() * temperature; @@ -2515,7 +2547,7 @@ double CFluidProperties::EnthalpyPhase(long number,int comp,double* gp,double th double MFPCalcHenryConstant(double temperature) { double HenryConstant; - HenryConstant = (0.8942 + 1.47 * exp(-0.04394 * (temperature - 273.14))) * 0.0000000001; + HenryConstant = (0.8942 + 1.47 * exp(-0.04394 * (temperature - 273.14))) * 0.0000000001; return HenryConstant; } @@ -2534,71 +2566,63 @@ double MFPCalcHenryConstant(double temperature) 08/2004 OK MFP implementation last modification: **************************************************************************/ -double CFluidProperties::MassFraction(long number, - int comp, - double* gp, - double theta, - CFiniteElementStd* assem) +double CFluidProperties::MassFraction(long number, int comp, double* gp, double theta, CFiniteElementStd* assem) { double mass_fraction = 0.0; - double mass_fraction_air_in_gas,mass_fraction_air_in_liquid; + double mass_fraction_air_in_gas, mass_fraction_air_in_liquid; double gas_density = 0.0; double vapour_pressure; double temperature; double henry_constant; - int nidx0,nidx1; + int nidx0, nidx1; double gas_pressure; /*--------------------------------------------------------------------------*/ /* Get and calc independent variables */ - nidx0 = PCSGetNODValueIndex("PRESSURE1",0); - nidx1 = PCSGetNODValueIndex("PRESSURE1",1); - if(mode == 0) // Gauss point values - - gas_pressure = (1. - theta) * InterpolValue(number,nidx0,gp[0],gp[1],gp[2]) \ - + theta* InterpolValue(number,nidx1,gp[0],gp[1],gp[2]); - else // Node values - - gas_pressure = (1. - theta) * GetNodeVal(number,nidx0) \ - + theta* GetNodeVal(number,nidx1); - nidx0 = PCSGetNODValueIndex("TEMPERATURE1",0); - nidx1 = PCSGetNODValueIndex("TEMPERATURE1",1); - if(mode == 0) // Gauss point values - - temperature = (1. - theta) * InterpolValue(number,nidx0,gp[0],gp[1],gp[2]) \ - + theta* InterpolValue(number,nidx1,gp[0],gp[1],gp[2]); - else // Node values - - temperature = (1. - theta) * GetNodeVal(number,nidx0) \ - + theta* GetNodeVal(number,nidx1); + nidx0 = PCSGetNODValueIndex("PRESSURE1", 0); + nidx1 = PCSGetNODValueIndex("PRESSURE1", 1); + if (mode == 0) // Gauss point values + + gas_pressure = (1. - theta) * InterpolValue(number, nidx0, gp[0], gp[1], gp[2]) + + theta * InterpolValue(number, nidx1, gp[0], gp[1], gp[2]); + else // Node values + + gas_pressure = (1. - theta) * GetNodeVal(number, nidx0) + theta * GetNodeVal(number, nidx1); + nidx0 = PCSGetNODValueIndex("TEMPERATURE1", 0); + nidx1 = PCSGetNODValueIndex("TEMPERATURE1", 1); + if (mode == 0) // Gauss point values + + temperature = (1. - theta) * InterpolValue(number, nidx0, gp[0], gp[1], gp[2]) + + theta * InterpolValue(number, nidx1, gp[0], gp[1], gp[2]); + else // Node values + + temperature = (1. - theta) * GetNodeVal(number, nidx0) + theta * GetNodeVal(number, nidx1); gas_density = Density(); vapour_pressure = MFPCalcVapourPressure(temperature); /*--------------------------------------------------------------------------*/ /* Calc mass fractions */ switch (phase) { - case 0: /* gas phase */ - mass_fraction_air_in_gas = \ - ((gas_pressure - vapour_pressure) * FluidConstant::ComponentMolarMassAir() ) \ - / (FluidConstant::GasConstant() * (temperature + 0.0) * gas_density); - mass_fraction_air_in_gas = MRange(0.0,mass_fraction_air_in_gas,1.0); - if(comp == 0) /* air specie */ - mass_fraction = mass_fraction_air_in_gas; - if(comp == 1) /* water specie */ - mass_fraction = 1.0 - mass_fraction_air_in_gas; - break; - case 1: /* liquid phase */ - henry_constant = MFPCalcHenryConstant(temperature); - mass_fraction_air_in_liquid = \ - FluidConstant::ComponentMolarMassAir() / (FluidConstant::ComponentMolarMassAir() \ - - FluidConstant::ComponentMolarMassWater() * - (1.0 - 1.0 / - (henry_constant * (gas_pressure - vapour_pressure)))); - mass_fraction_air_in_liquid = MRange(0.0,mass_fraction_air_in_liquid,1.0); - if(comp == 0) /* air specie */ - mass_fraction = mass_fraction_air_in_liquid; - if(comp == 1) /* water specie X_w^l = 1-X_a^l */ - mass_fraction = 1.0 - mass_fraction_air_in_liquid; - break; + case 0: /* gas phase */ + mass_fraction_air_in_gas = ((gas_pressure - vapour_pressure) * FluidConstant::ComponentMolarMassAir()) + / (FluidConstant::GasConstant() * (temperature + 0.0) * gas_density); + mass_fraction_air_in_gas = MRange(0.0, mass_fraction_air_in_gas, 1.0); + if (comp == 0) /* air specie */ + mass_fraction = mass_fraction_air_in_gas; + if (comp == 1) /* water specie */ + mass_fraction = 1.0 - mass_fraction_air_in_gas; + break; + case 1: /* liquid phase */ + henry_constant = MFPCalcHenryConstant(temperature); + mass_fraction_air_in_liquid = FluidConstant::ComponentMolarMassAir() + / (FluidConstant::ComponentMolarMassAir() + - FluidConstant::ComponentMolarMassWater() + * (1.0 - 1.0 / (henry_constant * (gas_pressure - vapour_pressure)))); + mass_fraction_air_in_liquid = MRange(0.0, mass_fraction_air_in_liquid, 1.0); + if (comp == 0) /* air specie */ + mass_fraction = mass_fraction_air_in_liquid; + if (comp == 1) /* water specie X_w^l = 1-X_a^l */ + mass_fraction = 1.0 - mass_fraction_air_in_liquid; + break; } /*--------------------------------------------------------------------------*/ return mass_fraction; @@ -2613,27 +2637,27 @@ double CFluidProperties::MassFraction(long number, 08/2004 OK MFP implementation last modification: **************************************************************************/ -double CFluidProperties::InternalEnergy(long number,double* gp,double theta) +double CFluidProperties::InternalEnergy(long number, double* gp, double theta) { double energy = 0.0; - int nidx0,nidx1; - double temperature,pressure; - - nidx0 = PCSGetNODValueIndex("TEMPERATURE1",0); - nidx1 = PCSGetNODValueIndex("TEMPERATURE1",1); - temperature = (1. - theta) * InterpolValue(number,nidx0,gp[0],gp[1],gp[2]) \ - + theta* InterpolValue(number,nidx1,gp[0],gp[1],gp[2]); - energy = SpecificHeatCapacity() * temperature; //YD - //energy = HeatCapacity(temperature,m_ele_fem_std) * temperature; - - //if(name.find("GAS")!=string::npos){ - if(phase == 0) + int nidx0, nidx1; + double temperature, pressure; + + nidx0 = PCSGetNODValueIndex("TEMPERATURE1", 0); + nidx1 = PCSGetNODValueIndex("TEMPERATURE1", 1); + temperature = (1. - theta) * InterpolValue(number, nidx0, gp[0], gp[1], gp[2]) + + theta * InterpolValue(number, nidx1, gp[0], gp[1], gp[2]); + energy = SpecificHeatCapacity() * temperature; // YD + // energy = HeatCapacity(temperature,m_ele_fem_std) * temperature; + + // if(name.find("GAS")!=string::npos){ + if (phase == 0) { - nidx0 = PCSGetNODValueIndex("PRESSURE1",0); - nidx1 = PCSGetNODValueIndex("PRESSURE1",1); - pressure = (1. - theta) * InterpolValue(number,nidx0,gp[0],gp[1],gp[2]) \ - + theta* InterpolValue(number,nidx1,gp[0],gp[1],gp[2]); - energy += pressure / Density(); //YD + nidx0 = PCSGetNODValueIndex("PRESSURE1", 0); + nidx1 = PCSGetNODValueIndex("PRESSURE1", 1); + pressure = (1. - theta) * InterpolValue(number, nidx0, gp[0], gp[1], gp[2]) + + theta * InterpolValue(number, nidx1, gp[0], gp[1], gp[2]); + energy += pressure / Density(); // YD } return energy; } @@ -2648,44 +2672,42 @@ double CFluidProperties::InternalEnergy(long number,double* gp,double theta) 08/2004 OK MFP implementation last modification: **************************************************************************/ -double CFluidProperties::DensityTemperatureDependence(long number,int comp,double* gp,double theta) +double CFluidProperties::DensityTemperatureDependence(long number, int comp, double* gp, double theta) { double vapour_pressure; double dvapour_pressure_dT; double drho_dT; double temperature; - int nidx0,nidx1; + int nidx0, nidx1; //---------------------------------------------------------------------- // State functions - nidx0 = PCSGetNODValueIndex("TEMPERATURE1",0); - nidx1 = PCSGetNODValueIndex("TEMPERATURE1",1); - if(mode == 0) // Gauss point values + nidx0 = PCSGetNODValueIndex("TEMPERATURE1", 0); + nidx1 = PCSGetNODValueIndex("TEMPERATURE1", 1); + if (mode == 0) // Gauss point values - temperature = (1. - theta) * InterpolValue(number,nidx0,gp[0],gp[1],gp[2]) \ - + theta* InterpolValue(number,nidx1,gp[0],gp[1],gp[2]); - else // Node values + temperature = (1. - theta) * InterpolValue(number, nidx0, gp[0], gp[1], gp[2]) + + theta * InterpolValue(number, nidx1, gp[0], gp[1], gp[2]); + else // Node values - temperature = (1. - theta) * GetNodeVal(number,nidx0) \ - + theta* GetNodeVal(number,nidx1); + temperature = (1. - theta) * GetNodeVal(number, nidx0) + theta * GetNodeVal(number, nidx1); //---------------------------------------------------------------------- // Vapour vapour_pressure = MFPCalcVapourPressure(temperature); - dvapour_pressure_dT = FluidConstant::ComponentMolarMassWater() * Enthalpy(comp,temperature) \ - / (FluidConstant::GasConstant() * temperature * temperature) \ - * vapour_pressure; + dvapour_pressure_dT = FluidConstant::ComponentMolarMassWater() * Enthalpy(comp, temperature) + / (FluidConstant::GasConstant() * temperature * temperature) * vapour_pressure; - drho_dT = -1.0 * FluidConstant::ComponentMolarMassWater() / (FluidConstant::GasConstant() * temperature) \ + drho_dT = -1.0 * FluidConstant::ComponentMolarMassWater() / (FluidConstant::GasConstant() * temperature) * (dvapour_pressure_dT - vapour_pressure / temperature); //---------------------------------------------------------------------- // Test - if((phase > 0) || (comp == 0)) + if ((phase > 0) || (comp == 0)) { DisplayMsgLn("MATCalcFluidDensityTemperatureDependence: Incorrect use of function"); abort(); } return drho_dT; } -#endif // if define obsolete. WW +#endif // if define obsolete. WW double CFluidProperties::LiquidViscosity_expo(double T) { @@ -2700,15 +2722,16 @@ double CFluidProperties::LiquidViscosity_expo(double T) last modification: **************************************************************************/ -double CFluidProperties::LiquidViscosity_CMCD(double Press,double TempK,double C) +double CFluidProperties::LiquidViscosity_CMCD(double Press, double TempK, double C) { C = C; /*CMcD variables for 20 ALR*/ - double A1,A2,A3,A4,A5,A6,A7,A8; /*constants*/ - double TempC,TempF, Pbar,Salinity; /* Temperature [K], Temperature [F], Pressure [bar]*/ - double my_Zero,PsatBar, PsatKPa; /*my pure water, my saline water, Saturation pressure [bar], Saturation pressure [KPa]*/ - /*intermediate values*/ - double sum1,sum2,sum3,sum4,sum5,sum6,sum7,sum8, exponent; + double A1, A2, A3, A4, A5, A6, A7, A8; /*constants*/ + double TempC, TempF, Pbar, Salinity; /* Temperature [K], Temperature [F], Pressure [bar]*/ + double my_Zero, PsatBar, + PsatKPa; /*my pure water, my saline water, Saturation pressure [bar], Saturation pressure [KPa]*/ + /*intermediate values*/ + double sum1, sum2, sum3, sum4, sum5, sum6, sum7, sum8, exponent; /*CMcD end variables for 20 ALR*/ /* //Prepared for introduction of solute transport in PCS version //Average Concentration @@ -2720,7 +2743,7 @@ double CFluidProperties::LiquidViscosity_CMCD(double Press,double TempK,double C concentration_average /= count_nodes; fp->salinity=fp->rho_0+concentration_average*fp->drho_dC; */ - //Link to function from ALR + // Link to function from ALR Salinity = C_0 / 1000.; /***constant values*******/ A1 = -7.419242; @@ -2739,36 +2762,31 @@ double CFluidProperties::LiquidViscosity_CMCD(double Press,double TempK,double C /*end of units conversion*/ /*Calculation of the saturation pressure*/ -// sum1=pow((0.65-0.01*TempK),0)*A1; + // sum1=pow((0.65-0.01*TempK),0)*A1; sum1 = 1.0 * A1; -// sum2=pow((0.65-0.01*TempK),1)*A2; + // sum2=pow((0.65-0.01*TempK),1)*A2; sum2 = (0.65 - 0.01 * TempK) * A2; sum3 = (0.65 - 0.01 * TempK) * (0.65 - 0.01 * TempK) * A3; - sum4 = MathLib::fastpow((0.65 - 0.01 * TempK),3) * A4; - sum5 = MathLib::fastpow((0.65 - 0.01 * TempK),4) * A5; - sum6 = MathLib::fastpow((0.65 - 0.01 * TempK),5) * A6; - sum7 = MathLib::fastpow((0.65 - 0.01 * TempK),6) * A7; - sum8 = MathLib::fastpow((0.65 - 0.01 * TempK),7) * A8; + sum4 = MathLib::fastpow((0.65 - 0.01 * TempK), 3) * A4; + sum5 = MathLib::fastpow((0.65 - 0.01 * TempK), 4) * A5; + sum6 = MathLib::fastpow((0.65 - 0.01 * TempK), 5) * A6; + sum7 = MathLib::fastpow((0.65 - 0.01 * TempK), 6) * A7; + sum8 = MathLib::fastpow((0.65 - 0.01 * TempK), 7) * A8; /*intermediate value*/ exponent = sum1 + sum2 + sum3 + sum4 + sum5 + sum6 + sum7 + sum8; exponent = exponent * (374.136 - TempC) / TempK; /*intermediate value*/ - PsatKPa = exp(exponent) * 22088; /*saturation pressure in kPa*/ - PsatBar = PsatKPa / (1000 * 100000); /*Saturation pressure in bar*/ + PsatKPa = exp(exponent) * 22088; /*saturation pressure in kPa*/ + PsatBar = PsatKPa / (1000 * 100000); /*Saturation pressure in bar*/ /*Viscosity of pure water in Pa-S*/ - my_Zero = 243.18e-7 * - (pow(10., - (247.8 / (TempK - 140)))) * (1 + (Pbar - PsatBar) * 1.0467e-6 * (TempK - 305)); + my_Zero = 243.18e-7 * (pow(10., (247.8 / (TempK - 140)))) * (1 + (Pbar - PsatBar) * 1.0467e-6 * (TempK - 305)); /*Viscosity of saline water in Pa-S*/ - viscosity = my_Zero * - (1 - 0.00187 * (sqrt(Salinity)) + 0.000218 * - (MathLib::fastpow(sqrt(Salinity), - 5)) + - (sqrt(TempF) - 0.0135 * - TempF) * (0.00276 * Salinity - 0.000344 * (MathLib::fastpow(sqrt(Salinity),3)))); + viscosity = my_Zero * (1 - 0.00187 * (sqrt(Salinity)) + 0.000218 * (MathLib::fastpow(sqrt(Salinity), 5)) + + (sqrt(TempF) - 0.0135 * TempF) + * (0.00276 * Salinity - 0.000344 * (MathLib::fastpow(sqrt(Salinity), 3)))); return viscosity; } @@ -2795,19 +2813,20 @@ double CFluidProperties::MATCalcHeatConductivityMethod2(double Press, double Tem int i, j; double TauTC, Nabla, Delta, Nabla0, Nabla1, Nabla2; double heat_conductivity, Rho, temperature_average, pressure_average, viscosity; - double Rhostar, TstarTC, Lambdastar; //WW, Pstar1; + double Rhostar, TstarTC, Lambdastar; // WW, Pstar1; double nZero[4]; double n[5][6]; - double A1,A2,A3,A4,A5,A6,A7,A8; /*constants*/ - double TempC, TempF, Pbar, Salinity; /* Temperature [K], Temperature [F], Pressure [bar]*/ - double my_Zero,PsatBar, PsatKPa; /*my pure water, my saline water, Saturation pressure [bar], Saturation pressure [KPa]*/ - /*intermediate values*/ - double sum1,sum2,sum3,sum4,sum5,sum6,sum7,sum8, exponent; + double A1, A2, A3, A4, A5, A6, A7, A8; /*constants*/ + double TempC, TempF, Pbar, Salinity; /* Temperature [K], Temperature [F], Pressure [bar]*/ + double my_Zero, PsatBar, + PsatKPa; /*my pure water, my saline water, Saturation pressure [bar], Saturation pressure [KPa]*/ + /*intermediate values*/ + double sum1, sum2, sum3, sum4, sum5, sum6, sum7, sum8, exponent; /*************************************************************************************************/ /*************************************************************************************************/ /*************************Partial derivatives calculation*****************************************/ - double GammaPi, GammaPiTau, GammaPiPi, Pii, Tau, GazConst; + double GammaPi, GammaPiTau, GammaPiPi, Pii, Tau, GazConst; double LGamma[35]; double JGamma[35]; double nGamma[35]; @@ -2819,20 +2838,20 @@ double CFluidProperties::MATCalcHeatConductivityMethod2(double Press, double Tem temperature_average = TempK; Salinity = C_0; Tstar = 1386; - Pstar = 16.53e6; // MPa - GazConst = 0.461526e3; //!!!!Given by equation (2.1) + Pstar = 16.53e6; // MPa + GazConst = 0.461526e3; //!!!!Given by equation (2.1) TstarTilda = 647.226; PstarTilda = 22.115e6; RhostarTilda = 317.763; Lambdastar = 0.4945; Rhostar = 317.763; TstarTC = 647.226; - //WW Pstar1 = 22.115e-6; + // WW Pstar1 = 22.115e-6; /*BEGIN: reduced dimensions*/ TauTC = TstarTC / temperature_average; - //Delta = Rho / Rhostar; - //WW PiiTC = pressure_average / Pstar1; + // Delta = Rho / Rhostar; + // WW PiiTC = pressure_average / Pstar1; /*END: reduced dimensions*/ nGamma[1] = 0.14632971213167; @@ -2947,38 +2966,31 @@ double CFluidProperties::MATCalcHeatConductivityMethod2(double Press, double Tem GammaPi = 0; for (i = 1; i < 35; i++) - GammaPi = GammaPi - (nGamma[i]) * (LGamma[i]) * - (pow((7.1 - Pii),(LGamma[i] - 1))) * (pow((Tau - 1.222),JGamma[i])); + GammaPi = GammaPi + - (nGamma[i]) * (LGamma[i]) * (pow((7.1 - Pii), (LGamma[i] - 1))) * (pow((Tau - 1.222), JGamma[i])); /*END: Calculation of GammaPi*/ /*BEGIN:Calculation of GammaPiTau*/ GammaPiTau = 0; for (i = 1; i < 35; i++) - GammaPiTau = GammaPiTau - (nGamma[i]) * (LGamma[i]) * - (pow((7.1 - Pii), - (LGamma[i] - - 1))) * (JGamma[i]) * (pow((Tau - 1.222),(JGamma[i] - 1))); + GammaPiTau = GammaPiTau + - (nGamma[i]) * (LGamma[i]) * (pow((7.1 - Pii), (LGamma[i] - 1))) * (JGamma[i]) + * (pow((Tau - 1.222), (JGamma[i] - 1))); /*END: Calculation of GammaPiTau*/ /*BEGIN:Calculation of GammaPiPi*/ GammaPiPi = 0; for (i = 1; i <= 34; i++) - GammaPiPi = GammaPiPi + (nGamma[i]) * (LGamma[i]) * - (LGamma[i] - - 1) * - (pow((7.1 - Pii),(LGamma[i] - 2))) * (pow((Tau - 1.222),(JGamma[i]))); + GammaPiPi = GammaPiPi + + (nGamma[i]) * (LGamma[i]) * (LGamma[i] - 1) * (pow((7.1 - Pii), (LGamma[i] - 2))) + * (pow((Tau - 1.222), (JGamma[i]))); /*END: Calculation of GammaPiPi*/ /*BEGIN:Calculation of derivative*/ - First_derivative = - ((TstarTilda) * (Pstar) * - ((GammaPiTau) * (Tstar) - (GammaPi) * - (temperature_average))) / - (PstarTilda * temperature_average * temperature_average * GammaPiPi), - Second_derivative = - ((-1) * (PstarTilda) * - (GammaPiPi) ) / - ( (RhostarTilda) * (temperature_average) * (GazConst) * ((GammaPi * GammaPi))); + First_derivative = ((TstarTilda) * (Pstar) * ((GammaPiTau) * (Tstar) - (GammaPi) * (temperature_average))) + / (PstarTilda * temperature_average * temperature_average * GammaPiPi), + Second_derivative = ((-1) * (PstarTilda) * (GammaPiPi)) + / ((RhostarTilda) * (temperature_average) * (GazConst) * ((GammaPi * GammaPi))); /*End:Calculation of derivative*/ /*BEGIN: Calculation of density*/ @@ -2994,7 +3006,7 @@ double CFluidProperties::MATCalcHeatConductivityMethod2(double Press, double Tem Lambdastar = 0.4945; Rhostar = 317.763; TstarTC = 647.226; - //WW Pstar1 = 22.115e6; + // WW Pstar1 = 22.115e6; nZero[0] = 0.1e1; nZero[1] = 0.6978267e1; @@ -3040,13 +3052,13 @@ double CFluidProperties::MATCalcHeatConductivityMethod2(double Press, double Tem /*BEGIN: reduced dimensions*/ TauTC = TstarTC / temperature_average; Delta = Rho / Rhostar; - //WW PiiTC = pressure_average / Pstar1; + // WW PiiTC = pressure_average / Pstar1; /*END: reduced dimensions*/ /*BEGIN: Nabla0*/ Nabla0 = 0; for (i = 0; i <= 3; i++) - Nabla0 = Nabla0 + (nZero[i]) * (MathLib::fastpow(TauTC,i)); + Nabla0 = Nabla0 + (nZero[i]) * (MathLib::fastpow(TauTC, i)); Nabla0 = Nabla0 * (sqrt(TauTC)); Nabla0 = 1 / Nabla0; @@ -3091,52 +3103,38 @@ double CFluidProperties::MATCalcHeatConductivityMethod2(double Press, double Tem /*end of units conversion*/ /*Calculation of the saturation pressure*/ -// TF sum1=pow((0.65-0.01*TempK),0)*A1; + // TF sum1=pow((0.65-0.01*TempK),0)*A1; sum1 = A1; -// TF sum2=pow((0.65-0.01*TempK),1)*A2; + // TF sum2=pow((0.65-0.01*TempK),1)*A2; sum2 = (0.65 - 0.01 * TempK) * A2; sum3 = (0.65 - 0.01 * TempK) * (0.65 - 0.01 * TempK) * A3; - sum4 = MathLib::fastpow((0.65 - 0.01 * TempK),3) * A4; - sum5 = MathLib::fastpow((0.65 - 0.01 * TempK),4) * A5; - sum6 = MathLib::fastpow((0.65 - 0.01 * TempK),5) * A6; - sum7 = MathLib::fastpow((0.65 - 0.01 * TempK),6) * A7; - sum8 = MathLib::fastpow((0.65 - 0.01 * TempK),7) * A8; + sum4 = MathLib::fastpow((0.65 - 0.01 * TempK), 3) * A4; + sum5 = MathLib::fastpow((0.65 - 0.01 * TempK), 4) * A5; + sum6 = MathLib::fastpow((0.65 - 0.01 * TempK), 5) * A6; + sum7 = MathLib::fastpow((0.65 - 0.01 * TempK), 6) * A7; + sum8 = MathLib::fastpow((0.65 - 0.01 * TempK), 7) * A8; /*intermediate value*/ exponent = sum1 + sum2 + sum3 + sum4 + sum5 + sum6 + sum7 + sum8; exponent = exponent * (374.136 - TempC) / TempK; /*intermediate value*/ - PsatKPa = exp(exponent) * 22088; /*saturation pressure in kPa*/ - PsatBar = PsatKPa / (1000 * 100000); /*Saturation pressure in bar*/ + PsatKPa = exp(exponent) * 22088; /*saturation pressure in kPa*/ + PsatBar = PsatKPa / (1000 * 100000); /*Saturation pressure in bar*/ /*Viscosity of pure water in Pa-S*/ - my_Zero = 243.18e-7 * - (pow(10., - (247.8 / (TempK - 140)))) * (1 + (Pbar - PsatBar) * 1.0467e-6 * (TempK - 305)); + my_Zero = 243.18e-7 * (pow(10., (247.8 / (TempK - 140)))) * (1 + (Pbar - PsatBar) * 1.0467e-6 * (TempK - 305)); /*Viscosity of saline water in Pa-S*/ - viscosity = my_Zero * - (1 - 0.00187 * (sqrt(Salinity)) + 0.000218 * - (MathLib::fastpow(sqrt(Salinity), - 5)) + - (sqrt(TempF) - 0.0135 * - TempF) * (0.00276 * Salinity - 0.000344 * (MathLib::fastpow(sqrt(Salinity),3)))); + viscosity = my_Zero * (1 - 0.00187 * (sqrt(Salinity)) + 0.000218 * (MathLib::fastpow(sqrt(Salinity), 5)) + + (sqrt(TempF) - 0.0135 * TempF) + * (0.00276 * Salinity - 0.000344 * (MathLib::fastpow(sqrt(Salinity), 3)))); /* End of viscosity function*/ /*BEGIN: Nabla2*/ - Nabla2 = 0.0013848 / - ((viscosity) / - 55.071e-6) * - (1.0 / - (TauTC * - Delta) * - (TauTC * - Delta)) * - (First_derivative * - First_derivative) * - (pow((Delta * (Second_derivative)),0.4678)) * (sqrt(Delta)) * exp( - -18.66 * ((1 / TauTC - 1) * (1 / TauTC - 1)) - (MathLib::fastpow(Delta - 1,4))); + Nabla2 = 0.0013848 / ((viscosity) / 55.071e-6) * (1.0 / (TauTC * Delta) * (TauTC * Delta)) + * (First_derivative * First_derivative) * (pow((Delta * (Second_derivative)), 0.4678)) * (sqrt(Delta)) + * exp(-18.66 * ((1 / TauTC - 1) * (1 / TauTC - 1)) - (MathLib::fastpow(Delta - 1, 4))); /*END: Nabla2*/ /*BEGIN: Nabla => heat_conductivity*/ @@ -3184,22 +3182,22 @@ double CFluidProperties::vaporDensity_derivative(const double T_abs) double CFluidProperties::MATCalcFluidHeatCapacityMethod2(double Press, double TempK, double Conc) { Conc = Conc; - double Pressurevar, Tau, pressure_average, temperature_average, Tstar, Pstar,GazConst; + double Pressurevar, Tau, pressure_average, temperature_average, Tstar, Pstar, GazConst; double GammaPi, GammaPiTau, GammaPiPi, GammaTauTau; - double L[35],J[35],n[35]; + double L[35], J[35], n[35]; int i; - //WW double salinity; - double Cp; //WW , Cv; + // WW double salinity; + double Cp; // WW , Cv; pressure_average = Press; temperature_average = TempK; - //WW salinity=C_0; + // WW salinity=C_0; Tstar = 1386; - Pstar = 16.53e6; // MPa - GazConst = 0.461526e3; // + Pstar = 16.53e6; // MPa + GazConst = 0.461526e3; // n[0] = 0.0; n[1] = 0.14632971213167; @@ -3316,32 +3314,31 @@ double CFluidProperties::MATCalcFluidHeatCapacityMethod2(double Press, double Te GammaPi = 0; for (i = 1; i < 35; i++) - GammaPi = GammaPi - (n[i]) * (L[i]) * - (pow((7.1 - Pressurevar),(L[i] - 1.))) * (pow((Tau - 1.222),J[i])); + GammaPi = GammaPi - (n[i]) * (L[i]) * (pow((7.1 - Pressurevar), (L[i] - 1.))) * (pow((Tau - 1.222), J[i])); /*END: Calculation of GammaPi*/ /*BEGIN:Calculation of GammaPiTau*/ GammaPiTau = 0; for (i = 1; i < 35; i++) - GammaPiTau = GammaPiTau - (n[i]) * (L[i]) * - (pow((7.1 - Pressurevar), - (L[i] - 1.))) * (J[i]) * (pow((Tau - 1.222),(J[i] - 1.))); + GammaPiTau + = GammaPiTau + - (n[i]) * (L[i]) * (pow((7.1 - Pressurevar), (L[i] - 1.))) * (J[i]) * (pow((Tau - 1.222), (J[i] - 1.))); /*END: Calculation of GammaPiTau*/ /*BEGIN:Calculation of GammaTauTau*/ GammaTauTau = 0; for (i = 1; i < 35; i++) - GammaTauTau = GammaTauTau + (n[i]) * - (pow((7.1 - Pressurevar), - (L[i]))) * (J[i]) * (J[i] - 1.) * (pow((Tau - 1.222),(J[i] - 2))); + GammaTauTau + = GammaTauTau + + (n[i]) * (pow((7.1 - Pressurevar), (L[i]))) * (J[i]) * (J[i] - 1.) * (pow((Tau - 1.222), (J[i] - 2))); /*END: Calculation of GammaTauTau*/ /*BEGIN:Calculation of GammaPiPi*/ GammaPiPi = 0; for (i = 1; i < 35; i++) - GammaPiPi = GammaPiPi + (n[i]) * (L[i]) * - (L[i] - - 1) * (pow((7.1 - Pressurevar),(L[i] - 2.))) * (pow((Tau - 1.222),(J[i]))); + GammaPiPi + = GammaPiPi + + (n[i]) * (L[i]) * (L[i] - 1) * (pow((7.1 - Pressurevar), (L[i] - 2.))) * (pow((Tau - 1.222), (J[i]))); /*END: Calculation of GammaPiPi*/ /*************************Partial derivatives calculation*****************************************/ @@ -3354,7 +3351,7 @@ double CFluidProperties::MATCalcFluidHeatCapacityMethod2(double Press, double Te /*BEGIN: Fluid isochoric heat capacity*/ /* Cv is not used currently 9.2003*/ - //WW Cv = (- (pow(Tau,2))* (GammaTauTau) + pow(GammaPi - Tau * (GammaPiTau),2) / GammaPiPi) * GazConst; + // WW Cv = (- (pow(Tau,2))* (GammaTauTau) + pow(GammaPi - Tau * (GammaPiTau),2) / GammaPiPi) * GazConst; /*BEGIN: Fluid isochoric heat capacity*/ return Cp; @@ -3371,7 +3368,7 @@ void MFPDelete() { long i; int no_mfp = (int)mfp_vector.size(); - for(i = 0; i < no_mfp; i++) + for (i = 0; i < no_mfp; i++) delete mfp_vector[i]; mfp_vector.clear(); } @@ -3382,25 +3379,25 @@ void MFPDelete() Programing: 10/2005 OK/YD Implementation **************************************************************************/ -CFluidProperties* MFPGet(const string &name) +CFluidProperties* MFPGet(const string& name) { CFluidProperties* m_mfp = NULL; - for(int i = 0; i < (int)mfp_vector.size(); i++) + for (int i = 0; i < (int)mfp_vector.size(); i++) { m_mfp = mfp_vector[i]; - if(m_mfp->name.compare(name) == 0) + if (m_mfp->name.compare(name) == 0) return m_mfp; } return NULL; } -CFluidProperties* MFPGet(int fluid) //NB +CFluidProperties* MFPGet(int fluid) // NB { CFluidProperties* m_mfp = NULL; - for(int i = 0; i < (int)mfp_vector.size(); i++) + for (int i = 0; i < (int)mfp_vector.size(); i++) { m_mfp = mfp_vector[i]; - if(m_mfp->fluid_id == fluid) + if (m_mfp->fluid_id == fluid) return m_mfp; } return NULL; @@ -3417,45 +3414,45 @@ double CFluidProperties::CalcEnthalpy(double temperature) //---------------------------------------------------------------------- CalPrimaryVariable(enthalpy_pcs_name_vector); //---------------------------------------------------------------------- - //double temperature = primary_variable[0]; + // double temperature = primary_variable[0]; double val = 0.0; double T0_integrate = 0.0; double T1_integrate = 0.0; double heat_capacity_all; - switch(GetHeatCapacityModel()) + switch (GetHeatCapacityModel()) { - case 5: - MFPGet("LIQUID"); - //------------PART 1-------------------------------- - T0_integrate = 273.15; - T1_integrate = T_Latent1 + 273.15; - int npoint = 100; //Gauss point - double DT = (T1_integrate - T0_integrate) / npoint; - for(int i = 0; i < npoint; i++) - { - temperature_buffer = T0_integrate + i * DT - 273.15; - heat_capacity_all = Fem_Ele_Std->FluidProp->SpecificHeatCapacity(); - temperature_buffer = T0_integrate + (i + 1) * DT - 273.15; - heat_capacity_all += Fem_Ele_Std->FluidProp->SpecificHeatCapacity(); - val += 0.5 * DT * heat_capacity_all; - } + case 5: + MFPGet("LIQUID"); + //------------PART 1-------------------------------- + T0_integrate = 273.15; + T1_integrate = T_Latent1 + 273.15; + int npoint = 100; // Gauss point + double DT = (T1_integrate - T0_integrate) / npoint; + for (int i = 0; i < npoint; i++) + { + temperature_buffer = T0_integrate + i * DT - 273.15; + heat_capacity_all = Fem_Ele_Std->FluidProp->SpecificHeatCapacity(); + temperature_buffer = T0_integrate + (i + 1) * DT - 273.15; + heat_capacity_all += Fem_Ele_Std->FluidProp->SpecificHeatCapacity(); + val += 0.5 * DT * heat_capacity_all; + } - //------------PART 2-------------------------------- - npoint = 500; - T0_integrate = T_Latent1 + 273.15; - T1_integrate = temperature + 273.15; - DT = (T1_integrate - T0_integrate) / npoint; - for(int i = 0; i < npoint; i++) - { - temperature_buffer = T0_integrate + i * DT - 273.15; - heat_capacity_all = Fem_Ele_Std->FluidProp->SpecificHeatCapacity(); - temperature_buffer = T0_integrate + (i + 1) * DT - 273.15; - heat_capacity_all += Fem_Ele_Std->FluidProp->SpecificHeatCapacity(); - val += 0.5 * DT * heat_capacity_all; - } - break; - // case 5: + //------------PART 2-------------------------------- + npoint = 500; + T0_integrate = T_Latent1 + 273.15; + T1_integrate = temperature + 273.15; + DT = (T1_integrate - T0_integrate) / npoint; + for (int i = 0; i < npoint; i++) + { + temperature_buffer = T0_integrate + i * DT - 273.15; + heat_capacity_all = Fem_Ele_Std->FluidProp->SpecificHeatCapacity(); + temperature_buffer = T0_integrate + (i + 1) * DT - 273.15; + heat_capacity_all += Fem_Ele_Std->FluidProp->SpecificHeatCapacity(); + val += 0.5 * DT * heat_capacity_all; + } + break; + // case 5: } return val; } @@ -3465,9 +3462,9 @@ double CFluidProperties::CalcEnthalpy(double temperature) 08/2008 OK last change: 11/2008 NB **************************************************************************/ -double MFPGetNodeValue(long node,const string &mfp_name, int phase_number) +double MFPGetNodeValue(long node, const string& mfp_name, int phase_number) { - CFluidProperties* m_mfp = mfp_vector[max(phase_number,0)]; + CFluidProperties* m_mfp = mfp_vector[max(phase_number, 0)]; const int restore_mode = m_mfp->mode; m_mfp->mode = 0; m_mfp->node = node; @@ -3476,44 +3473,55 @@ double MFPGetNodeValue(long node,const string &mfp_name, int phase_number) std::vector* vec_var_names; switch (mfp_name[0]) { - case 'V': mfp_id = 0; //VISCOSITY - vec_var_names = &m_mfp->viscosity_pcs_name_vector; - break; - case 'D': mfp_id = 1; //DENSITY - vec_var_names = &m_mfp->density_pcs_name_vector; - break; - case 'H': mfp_id = 2; //HEAT_CONDUCTIVITY - vec_var_names = &m_mfp->heat_conductivity_pcs_name_vector; - break; - case 'S': mfp_id = 3; //SPECIFIC HEAT CAPACITY - vec_var_names = &m_mfp->specific_heat_capacity_pcs_name_vector; - break; - default: mfp_id = -1; - static std::vector default_var_names; - if (default_var_names.empty()) { - default_var_names.push_back("PRESSURE1"); - default_var_names.push_back("TEMPERATURE1"); - default_var_names.push_back("CONCENTRATION1"); - } - vec_var_names = &default_var_names; - break; + case 'V': + mfp_id = 0; // VISCOSITY + vec_var_names = &m_mfp->viscosity_pcs_name_vector; + break; + case 'D': + mfp_id = 1; // DENSITY + vec_var_names = &m_mfp->density_pcs_name_vector; + break; + case 'H': + mfp_id = 2; // HEAT_CONDUCTIVITY + vec_var_names = &m_mfp->heat_conductivity_pcs_name_vector; + break; + case 'S': + mfp_id = 3; // SPECIFIC HEAT CAPACITY + vec_var_names = &m_mfp->specific_heat_capacity_pcs_name_vector; + break; + default: + mfp_id = -1; + static std::vector default_var_names; + if (default_var_names.empty()) + { + default_var_names.push_back("PRESSURE1"); + default_var_names.push_back("TEMPERATURE1"); + default_var_names.push_back("CONCENTRATION1"); + } + vec_var_names = &default_var_names; + break; } - //std::vector arguments(vec_var_names->size()); + // std::vector arguments(vec_var_names->size()); std::vector arguments(std::max(size_t(3ul), vec_var_names->size())); - for (unsigned i=0; isize(); i++) { - CRFProcess* pcs = PCSGet((*vec_var_names)[i],true); - if (pcs) { - int var_idx = pcs->GetNodeValueIndex((*vec_var_names)[i],true); - if( (*vec_var_names)[i] == "PRESSURE1") - arguments[0] = pcs->GetNodeValue(node,var_idx); - else if( (*vec_var_names)[i] == "TEMPERATURE1") - arguments[1] = pcs->GetNodeValue(node,var_idx); - else if( (*vec_var_names)[i] == "CONCENTRATION1") - arguments[2] = pcs->GetNodeValue(node,var_idx); + for (unsigned i = 0; i < vec_var_names->size(); i++) + { + CRFProcess* pcs = PCSGet((*vec_var_names)[i], true); + if (pcs) + { + int var_idx = pcs->GetNodeValueIndex((*vec_var_names)[i], true); + if ((*vec_var_names)[i] == "PRESSURE1") + arguments[0] = pcs->GetNodeValue(node, var_idx); + else if ((*vec_var_names)[i] == "TEMPERATURE1") + arguments[1] = pcs->GetNodeValue(node, var_idx); + else if ((*vec_var_names)[i] == "CONCENTRATION1") + arguments[2] = pcs->GetNodeValue(node, var_idx); else - std::cout << "The variable " << (*vec_var_names)[i] << " is not supported in MFPGetNodeValue." << std::endl; - } else { + std::cout << "The variable " << (*vec_var_names)[i] << " is not supported in MFPGetNodeValue." + << std::endl; + } + else + { arguments[i] = 0.0; } } @@ -3522,30 +3530,36 @@ double MFPGetNodeValue(long node,const string &mfp_name, int phase_number) { CRFProcess* m_pcs = PCSGet("MULTI_COMPONENTIAL_FLOW"); arguments.resize(m_mfp->cmpN + 2); - for(int PVIndex=0; PVIndex < m_mfp->cmpN + 2; PVIndex++) - arguments[PVIndex] = m_pcs->GetNodeValue(node, m_pcs->GetNodeValueIndex(m_pcs->pcs_primary_function_name[PVIndex])); + for (int PVIndex = 0; PVIndex < m_mfp->cmpN + 2; PVIndex++) + arguments[PVIndex] + = m_pcs->GetNodeValue(node, m_pcs->GetNodeValueIndex(m_pcs->pcs_primary_function_name[PVIndex])); } //...................................................................... double mfp_value = .0; - switch(mfp_id) + switch (mfp_id) { - - case 0: mfp_value = m_mfp->Viscosity(arguments.data()); - break; - //NB 4.8.01 - case 1: mfp_value = m_mfp->Density(arguments.data()); - break; - case 2: mfp_value = m_mfp->HeatConductivity(arguments.data()); - break; - //NB AUG 2009 - case 3: mfp_value = m_mfp->SpecificHeatCapacity(arguments.data()); - break; - default: cout << "MFPGetNodeValue: no MFP data" << "\n"; - break; + case 0: + mfp_value = m_mfp->Viscosity(arguments.data()); + break; + // NB 4.8.01 + case 1: + mfp_value = m_mfp->Density(arguments.data()); + break; + case 2: + mfp_value = m_mfp->HeatConductivity(arguments.data()); + break; + // NB AUG 2009 + case 3: + mfp_value = m_mfp->SpecificHeatCapacity(arguments.data()); + break; + default: + cout << "MFPGetNodeValue: no MFP data" + << "\n"; + break; } //...................................................................... - m_mfp->mode = restore_mode; //NB changeback + m_mfp->mode = restore_mode; // NB changeback return mfp_value; } @@ -3564,92 +3578,102 @@ double CFluidProperties::drhodP(double* variables) if (p < 0) return 0; - switch(compressibility_model_pressure) + switch (compressibility_model_pressure) { - case 0: // incompressible - drhodP = 0; - break; + case 0: // incompressible + drhodP = 0; + break; - case 1: // constant slope compressibility - drhodP = compressibility_pressure; - break; + case 1: // constant slope compressibility + drhodP = compressibility_pressure; + break; - case 2: // use of fct file - drhodP = 0; // to be done - break; - case 3: // use of difference quotient - arguments[1] = T; - // in case 3, compressibility_pressure acts as delta P - arguments[0] = p + (compressibility_pressure / 2.); - rho1 = Density(arguments); - - arguments[0] = p - (compressibility_pressure / 2.); - rho2 = Density(arguments); - - //drhodP = (rho(p+dP/2)-rho(P-dP/2))/dP - // in case 3, compressibility_pressure acts as delta P - drhodP = (rho1 - rho2) / compressibility_pressure; - - break; // use of difference quotient - case 7: // use of fct file - drhodP = 1.0/p; // to be done - break; + case 2: // use of fct file + drhodP = 0; // to be done + break; + case 3: // use of difference quotient + arguments[1] = T; + // in case 3, compressibility_pressure acts as delta P + arguments[0] = p + (compressibility_pressure / 2.); + rho1 = Density(arguments); + + arguments[0] = p - (compressibility_pressure / 2.); + rho2 = Density(arguments); + + // drhodP = (rho(p+dP/2)-rho(P-dP/2))/dP + // in case 3, compressibility_pressure acts as delta P + drhodP = (rho1 - rho2) / compressibility_pressure; + + break; // use of difference quotient + case 7: // use of fct file + drhodP = 1.0 / p; // to be done + break; + case 15: // volume translated Peng-Robinson + if (eos_name == "VTPR" || eos_name == "PR" || eos_name == "IDEAL") + { + CRFProcess* m_pcs = PCSGet("MULTI_COMPONENTIAL_FLOW"); + std::vector roots; - case 15: //volume translated Peng-Robinson - if(eos_name == "VTPR" || eos_name == "PR" ||eos_name == "IDEAL") - { - CRFProcess* m_pcs = PCSGet("MULTI_COMPONENTIAL_FLOW"); - std::vector roots; + double beta_m = 0.0; + double v_m = 0.0; + const double R = 1000.0 * PhysicalConstant::IdealGasConstant; - double beta_m = 0.0; - double v_m = 0.0; - const double R = 1000.0 * PhysicalConstant::IdealGasConstant; + for (int CIndex = 2; CIndex < cmpN + 2; CIndex++) + { + double A, B, c, C, dvdp, fctA, fctB, fctC, beta, Tr, z, z1, z2, z3, v, Trr, fct; + therm_prop(m_pcs->pcs_primary_function_name[CIndex]); + Tr = T / Tc; + // double a0 = 1.0 + m0*(1.0 - Tr) + n0*(1.0 - Tr)*(0.7 - Tr); + Trr = 1.0 - pow(Tr, 0.6667); + fct = -0.25 + pc / p; + if (fluid_id == 1) + fct = (1.0780 + p / 6.8e8); + c = fct * (k1 + k2 * Trr + k3 * Trr * Trr) * R * Tc / pc; + if (eos_name == "PR") + c = 0.0; + A = a * p * pow(R * T, -2.0); + B = b * p * pow(R * T, -1.0); + C = c * p * pow(R * T, -1.0); + z1 = B - 1.0 + 3.0 * C; + z2 = (A - 3.0 * B * B + 3.0 * C * C + 2.0 * B * C - 2.0 * B - 2.0 * C); + z3 = (B * B * B + C * C * C + B * B - C * C + B * C * C - 3.0 * B * B * C - 2.0 * B * C + C * A + - A * B); + NsPol3(z1, z2, z3, &roots); + z = FindMax(roots); + if (fluid_id == 1) + z = FindMin(roots); + if (eos_name == "IDEAL") + { + z = 1.0; + c = 0.0; + b = 0.0; + a = 0.0; + } + v = (z * R * T / p); + fctB = (v + c) * (v + c + b) + b * (v + c - b); + fctA = v + c - b; + fctC = v + c + b; + dvdp = fctA * fctB / (p * fctB + 2.0 * p * fctA * fctC - 2.0 * R * T * fctC + a); + beta = dvdp; + beta_m += beta; + v_m += v; + } - for (int CIndex = 2; CIndex < cmpN + 2; CIndex++) - { - double A, B, c, C, dvdp, fctA, fctB, fctC, beta, Tr, z, z1, z2, z3, v, Trr, fct; - therm_prop(m_pcs->pcs_primary_function_name[CIndex]); - Tr = T/Tc; - // double a0 = 1.0 + m0*(1.0 - Tr) + n0*(1.0 - Tr)*(0.7 - Tr); - Trr = 1.0 - pow(Tr, 0.6667); - fct = -0.25 + pc/p; - if(fluid_id == 1) fct = (1.0780 + p/6.8e8); - c = fct*(k1 + k2*Trr + k3*Trr*Trr)*R*Tc/pc; - if(eos_name == "PR") c=0.0; - A = a*p*pow(R*T, -2.0); - B = b*p*pow(R*T, -1.0); - C = c*p*pow(R*T, -1.0); - z1 = B - 1.0 + 3.0*C; - z2 = (A - 3.0*B*B + 3.0*C*C + 2.0*B*C - 2.0*B - 2.0*C ); - z3 = (B*B*B + C*C*C + B*B - C*C + B*C*C - 3.0*B*B*C - 2.0*B*C + C*A - A*B); - NsPol3(z1,z2,z3,&roots); - z = FindMax(roots); - if(fluid_id == 1) z = FindMin(roots); - if(eos_name == "IDEAL") {z=1.0; c=0.0; b=0.0; a=0.0;} - v = (z*R*T/p); - fctB = (v + c)*(v + c + b) + b*(v + c - b); - fctA = v + c - b; - fctC = v + c + b; - dvdp = fctA*fctB/(p*fctB + 2.0*p*fctA*fctC - 2.0*R*T*fctC + a); - beta = dvdp; - beta_m += beta; - v_m += v; + drhodP = beta_m / v_m; // beta_t=beta_g*(vg/vt)+beta_l*(vl/vt) } - - drhodP = beta_m/v_m;//beta_t=beta_g*(vg/vt)+beta_l*(vl/vt) - } - else if(eos_name == "CONSTANT") { - for (int CIndex = 2; CIndex < cmpN + 2; CIndex++) + else if (eos_name == "CONSTANT") { - drhodP = variables[CIndex-2]*beta_p[CIndex-2]; + for (int CIndex = 2; CIndex < cmpN + 2; CIndex++) + { + drhodP = variables[CIndex - 2] * beta_p[CIndex - 2]; + } } - } - break; + break; - default: - drhodP = drho_dp; + default: + drhodP = drho_dp; } return drhodP; @@ -3661,102 +3685,112 @@ double CFluidProperties::drhodP(double* variables) **************************************************************************/ double CFluidProperties::drhodT(double* variables) { -double a0, A, B, c, C, da0, da, alpha, alpha_m, dvdT, fctA, fctB, fctC, p, R, T, Tr, z, z1, z2, z3, v, v_m, Trr, fct; + double a0, A, B, c, C, da0, da, alpha, alpha_m, dvdT, fctA, fctB, fctC, p, R, T, Tr, z, z1, z2, z3, v, v_m, Trr, + fct; std::vector roots; CRFProcess* m_pcs; m_pcs = PCSGet("MULTI_COMPONENTIAL_FLOW"); p = variables[0]; T = variables[1]; R = 1000.0 * PhysicalConstant::IdealGasConstant; - alpha_m=0.0; - v_m=0.0; + alpha_m = 0.0; + v_m = 0.0; double arguments[2]; double rho1, rho2, drhodT = 0.0; - if(!drho_dT_unsaturated) //fluid expansion (drho/dT) for unsaturated case activated? + if (!drho_dT_unsaturated) // fluid expansion (drho/dT) for unsaturated case activated? { - if (p < 0) - return 0; + if (p < 0) + return 0; } - switch(compressibility_model_temperature) + switch (compressibility_model_temperature) { - case 0: // fluid is incompressible - drhodT = 0; - break; - case 1: // constant slope compressibility, (for test cases) - drhodT = compressibility_temperature; - break; + case 0: // fluid is incompressible + drhodT = 0; + break; + case 1: // constant slope compressibility, (for test cases) + drhodT = compressibility_temperature; + break; - case 2: // use of fct file - drhodT = 0; // to be done - break; + case 2: // use of fct file + drhodT = 0; // to be done + break; - case 3: // use of difference quotient - // in case 3, compressibility_temperature acts as delta T - arguments[0] = p; + case 3: // use of difference quotient + // in case 3, compressibility_temperature acts as delta T + arguments[0] = p; - arguments[1] = T + (compressibility_temperature / 2.); - rho1 = Density(arguments); + arguments[1] = T + (compressibility_temperature / 2.); + rho1 = Density(arguments); - arguments[1] = T - (compressibility_temperature / 2.); - rho2 = Density(arguments); + arguments[1] = T - (compressibility_temperature / 2.); + rho2 = Density(arguments); - drhodT = (rho1 - rho2) / compressibility_temperature; - break; - case 7: // use of fct file - drhodT = 1.0/T; - break; + drhodT = (rho1 - rho2) / compressibility_temperature; + break; + case 7: // use of fct file + drhodT = 1.0 / T; + break; - case 15: //volume translated Peng-Robinson - if(eos_name == "VTPR" || eos_name == "PR" ||eos_name == "IDEAL") - { - for (int CIndex = 2; CIndex < cmpN + 2; CIndex++) + case 15: // volume translated Peng-Robinson + if (eos_name == "VTPR" || eos_name == "PR" || eos_name == "IDEAL") { - therm_prop(m_pcs->pcs_primary_function_name[CIndex]); - Tr = T/Tc; - a0 = 1.0 + m0*(1.0 - Tr) + n0*(1.0 - Tr)*(0.7 - Tr); - da0 = -(m0 + n0*(1.0 - Tr) + n0*(0.7 - Tr))/Tc; - da = 0.457235*2.0*a0*da0*pow(R*Tc, 2.0)/pc; - Trr = 1.0 - pow(Tr, 0.6667); - fct = -0.25 + pc/p; - if(fluid_id == 1) fct = (1.0780 + p/6.8e8); - c = fct*(k1 + k2*Trr + k3*Trr*Trr)*R*Tc/pc; - if(eos_name == "PR") c=0.0; - A = a*p*pow(R*T, -2.0); - B = b*p*pow(R*T, -1.0); - C = c*p*pow(R*T, -1.0); - z1 = B - 1.0 + 3.0*C; - z2 = (A - 3.0*B*B + 3.0*C*C + 2.0*B*C - 2.0*B - 2.0*C ); - z3 = (B*B*B + C*C*C + B*B - C*C + B*C*C - 3.0*B*B*C - 2.0*B*C + C*A - A*B); - NsPol3(z1,z2,z3,&roots); - z = FindMax(roots); - if(fluid_id == 1) z = FindMin(roots); - if(eos_name == "IDEAL") {z=1.0; c=0.0; b=0.0; a=0.0, da=0.0;} - v = (z*R*T/p); - fctB = (v + c)*(v + c + b) + b*(v + c - b); - fctA = v + c - b; - fctC = v + c + b; - dvdT = (R*fctB - da*fctA)/(p*fctB + 2.0*p*fctA*fctC - 2.0*R*T*fctC + a); - alpha = dvdT; - alpha_m += alpha; - v_m += v; + for (int CIndex = 2; CIndex < cmpN + 2; CIndex++) + { + therm_prop(m_pcs->pcs_primary_function_name[CIndex]); + Tr = T / Tc; + a0 = 1.0 + m0 * (1.0 - Tr) + n0 * (1.0 - Tr) * (0.7 - Tr); + da0 = -(m0 + n0 * (1.0 - Tr) + n0 * (0.7 - Tr)) / Tc; + da = 0.457235 * 2.0 * a0 * da0 * pow(R * Tc, 2.0) / pc; + Trr = 1.0 - pow(Tr, 0.6667); + fct = -0.25 + pc / p; + if (fluid_id == 1) + fct = (1.0780 + p / 6.8e8); + c = fct * (k1 + k2 * Trr + k3 * Trr * Trr) * R * Tc / pc; + if (eos_name == "PR") + c = 0.0; + A = a * p * pow(R * T, -2.0); + B = b * p * pow(R * T, -1.0); + C = c * p * pow(R * T, -1.0); + z1 = B - 1.0 + 3.0 * C; + z2 = (A - 3.0 * B * B + 3.0 * C * C + 2.0 * B * C - 2.0 * B - 2.0 * C); + z3 = (B * B * B + C * C * C + B * B - C * C + B * C * C - 3.0 * B * B * C - 2.0 * B * C + C * A + - A * B); + NsPol3(z1, z2, z3, &roots); + z = FindMax(roots); + if (fluid_id == 1) + z = FindMin(roots); + if (eos_name == "IDEAL") + { + z = 1.0; + c = 0.0; + b = 0.0; + a = 0.0, da = 0.0; + } + v = (z * R * T / p); + fctB = (v + c) * (v + c + b) + b * (v + c - b); + fctA = v + c - b; + fctC = v + c + b; + dvdT = (R * fctB - da * fctA) / (p * fctB + 2.0 * p * fctA * fctC - 2.0 * R * T * fctC + a); + alpha = dvdT; + alpha_m += alpha; + v_m += v; + } + drhodT = -alpha_m / v_m; // alpha_t=alpha_g*(vg/vt)+alpha_l*(vl/vt) } - drhodT = -alpha_m/v_m;//alpha_t=alpha_g*(vg/vt)+alpha_l*(vl/vt) - } - if(eos_name == "CONSTANT") - for (int CIndex = 2; CIndex < cmpN + 2; CIndex++) - { - drhodT = variables[CIndex-2]*alpha_T[CIndex-2]; - } - - break; + if (eos_name == "CONSTANT") + for (int CIndex = 2; CIndex < cmpN + 2; CIndex++) + { + drhodT = variables[CIndex - 2] * alpha_T[CIndex - 2]; + } + break; - default: - drhodT = 0; - break; + default: + drhodT = 0; + break; } return drhodT; } @@ -3768,21 +3802,22 @@ double a0, A, B, c, C, da0, da, alpha, alpha_m, dvdT, fctA, fctB, fctC, p, R, T, double CFluidProperties::drhodX(int CIndex, double* variables) { static double drhodX; - switch(solutal_expansivity_model) + switch (solutal_expansivity_model) { - case 1: - drhodX = solutal_expansivity; - break; - - case 15: - if(eos_name == "CONSTANT") drhodX = -Density(variables)/rho[CIndex-2]; - else drhodX = -Density(variables)/ComponentDensity(CIndex, variables); - break; + case 1: + drhodX = solutal_expansivity; + break; - default: - drhodX = 0.0; - break; + case 15: + if (eos_name == "CONSTANT") + drhodX = -Density(variables) / rho[CIndex - 2]; + else + drhodX = -Density(variables) / ComponentDensity(CIndex, variables); + break; + default: + drhodX = 0.0; + break; } return drhodX; } @@ -3801,33 +3836,38 @@ double CFluidProperties::ComponentDensity(int CIndex, double* variables) T = variables[1]; R = 1000.0 * PhysicalConstant::IdealGasConstant; - if(eos_name == "VTPR" || eos_name == "PR" ||eos_name == "IDEAL") + if (eos_name == "VTPR" || eos_name == "PR" || eos_name == "IDEAL") { therm_prop(m_pcs->pcs_primary_function_name[CIndex]); - Tr = T/Tc; + Tr = T / Tc; // double a0 = 1.0 + m0*(1.0 - Tr) + n0*(1.0 - Tr)*(0.7 - Tr); Trr = 1.0 - pow(Tr, 0.6667); - fct = -0.25 + pc/p; - if(fluid_id == 1) - fct = (1.0780 + p/6.8e8); - c = fct*(k1 + k2*Trr + k3*Trr*Trr)*R*Tc/pc; - if(eos_name == "PR" ) c=0.0; - A = a*p*pow(R*T, -2.0); - B = b*p*pow(R*T, -1.0); - C = c*p*pow(R*T, -1.0); - z1 = B - 1.0 + 3.0*C; - z2 = (A - 3.0*B*B + 3.0*C*C + 2.0*B*C - 2.0*B - 2.0*C ); - z3 = (B*B*B + C*C*C + B*B - C*C + B*C*C - 3.0*B*B*C - 2.0*B*C + C*A - A*B); - NsPol3(z1,z2,z3,&roots); + fct = -0.25 + pc / p; + if (fluid_id == 1) + fct = (1.0780 + p / 6.8e8); + c = fct * (k1 + k2 * Trr + k3 * Trr * Trr) * R * Tc / pc; + if (eos_name == "PR") + c = 0.0; + A = a * p * pow(R * T, -2.0); + B = b * p * pow(R * T, -1.0); + C = c * p * pow(R * T, -1.0); + z1 = B - 1.0 + 3.0 * C; + z2 = (A - 3.0 * B * B + 3.0 * C * C + 2.0 * B * C - 2.0 * B - 2.0 * C); + z3 = (B * B * B + C * C * C + B * B - C * C + B * C * C - 3.0 * B * B * C - 2.0 * B * C + C * A - A * B); + NsPol3(z1, z2, z3, &roots); z = FindMax(roots); - if(fluid_id == 1) z = FindMin(roots); - if(eos_name == "IDEAL" ) z=1.0; - density = p*molar_mass/(z*R*T); + if (fluid_id == 1) + z = FindMin(roots); + if (eos_name == "IDEAL") + z = 1.0; + density = p * molar_mass / (z * R * T); } - else if(eos_name == "CONSTANT") { - density = rho[CIndex-2]; + else if (eos_name == "CONSTANT") + { + density = rho[CIndex - 2]; } - else { + else + { density = 0.0; } @@ -3837,41 +3877,40 @@ double CFluidProperties::ComponentDensity(int CIndex, double* variables) Task: Calculation of component's effective diffusion coefficient in a mixture Programing: 05/2010 AKS **************************************************************************/ -double CFluidProperties::EffectiveDiffusionCoef(int CIndex, double* variables) - { +double CFluidProperties::EffectiveDiffusionCoef(int CIndex, double* variables) +{ CRFProcess* m_pcs; - m_pcs = PCSGet("MULTI_COMPONENTIAL_FLOW"); - double MI=0.0, VdI =0.0, effective_diffusion_coef=0.0, T, p; + m_pcs = PCSGet("MULTI_COMPONENTIAL_FLOW"); + double MI = 0.0, VdI = 0.0, effective_diffusion_coef = 0.0, T, p; T = variables[1]; p = variables[0]; - switch(diffusion_model) + switch (diffusion_model) { - case 1: - effective_diffusion_coef = diffusion_coef; - break; + case 1: + effective_diffusion_coef = diffusion_coef; + break; - case 15: - if(eos_name == "VTPR" || eos_name == "PR" ||eos_name == "IDEAL") - { - for (int i = 0; i < cmpN; i++) - { - therm_prop(m_pcs->pcs_primary_function_name[i+2]); - MI += 1.0/molar_mass; - VdI += pow(Vd, 1.0/3.0); - } - therm_prop(m_pcs->pcs_primary_function_name[CIndex]); - MI = MI - 1.0/molar_mass; - VdI = VdI - pow(Vd, 1.0/3.0); - effective_diffusion_coef = 0.0143*pow(T, 1.75)/(p*pow(2.0*pow(MI, -1), 0.5)*pow(VdI, 2)); + case 15: + if (eos_name == "VTPR" || eos_name == "PR" || eos_name == "IDEAL") + { + for (int i = 0; i < cmpN; i++) + { + therm_prop(m_pcs->pcs_primary_function_name[i + 2]); + MI += 1.0 / molar_mass; + VdI += pow(Vd, 1.0 / 3.0); + } + therm_prop(m_pcs->pcs_primary_function_name[CIndex]); + MI = MI - 1.0 / molar_mass; + VdI = VdI - pow(Vd, 1.0 / 3.0); + effective_diffusion_coef = 0.0143 * pow(T, 1.75) / (p * pow(2.0 * pow(MI, -1), 0.5) * pow(VdI, 2)); + } + if (eos_name == "CONSTANT") + effective_diffusion_coef = D0[CIndex - 2]; + break; } - if(eos_name == "CONSTANT") effective_diffusion_coef = D0[CIndex - 2]; - break; - - } return effective_diffusion_coef; - - } +} #ifdef MFP_TEST //----------------------------------------------------- // @@ -3889,16 +3928,16 @@ Hash_Table::Hash_Table(string f_name) int i_buff = 0.; int i, length; - f_name = FilePath + f_name; + f_name = FilePath + f_name; ifstream ins(f_name.c_str()); - if(!ins.good()) + if (!ins.good()) { cout << "File " << f_name << " cannot openned. Program exit "; exit(1); } getline(ins, aline); - if(aline.find("Varaiable_Number") != string::npos) + if (aline.find("Varaiable_Number") != string::npos) { ss.str(aline); ss >> aline >> num_var; @@ -3917,23 +3956,23 @@ Hash_Table::Hash_Table(string f_name) names.resize(length); getline(ins, aline); ss.str(aline); - for(i = 0; i < length; i++) + for (i = 0; i < length; i++) ss >> names[i]; ss.clear(); int counter = 0; double par = 0.; table_section_ends.push_back(0); - while(!ins.eof()) + while (!ins.eof()) { getline(ins, aline); - if(aline.find("...") != string::npos) + if (aline.find("...") != string::npos) { table_section_ends.push_back(counter + 1); hash_row_par.push_back(par); continue; } - if(aline.find("---") != string::npos) + if (aline.find("---") != string::npos) break; double* data_vp = new double[length - 1]; @@ -3941,7 +3980,7 @@ Hash_Table::Hash_Table(string f_name) ss.str(aline); ss >> par; - for(i = 0; i < length - 1; i++) + for (i = 0; i < length - 1; i++) ss >> data_vp[i]; ss.clear(); @@ -3956,9 +3995,9 @@ Hash_Table::Hash_Table(string f_name) */ Hash_Table::~Hash_Table() { - while(hash_table_data.size() > 0) + while (hash_table_data.size() > 0) { - delete [] hash_table_data[hash_table_data.size() - 1]; + delete[] hash_table_data[hash_table_data.size() - 1]; hash_table_data.pop_back(); } } @@ -3972,22 +4011,21 @@ Hash_Table::~Hash_Table() double Hash_Table::CalcValue(double* var, const int var_id) const { size_t i, j, k; - double* data_0, * data_1; + double *data_0, *data_1; double val_e[4]; - if(var[0] < hash_row_par[0]) + if (var[0] < hash_row_par[0]) var[0] = hash_row_par[0]; - if(var[0] > hash_row_par[hash_row_par.size() - 1]) + if (var[0] > hash_row_par[hash_row_par.size() - 1]) var[0] = hash_row_par[hash_row_par.size() - 1]; - for(i = 0; i < hash_row_par.size() - 1; i++) - if((var[0] >= hash_row_par[i]) && (var[0] < hash_row_par[i + 1])) + for (i = 0; i < hash_row_par.size() - 1; i++) + if ((var[0] >= hash_row_par[i]) && (var[0] < hash_row_par[i + 1])) { - for(j = 0; j < 2; j++) + for (j = 0; j < 2; j++) { data_0 = hash_table_data[i + j]; - for(k = table_section_ends[i + j]; - k < table_section_ends[i + j + 1]; k++) + for (k = table_section_ends[i + j]; k < table_section_ends[i + j + 1]; k++) { } } diff --git a/FEM/rf_mfp_new.h b/FEM/rf_mfp_new.h index 495831c27..b3b3308a9 100644 --- a/FEM/rf_mfp_new.h +++ b/FEM/rf_mfp_new.h @@ -39,7 +39,7 @@ class Hash_Table double CalcValue(double* var, const int var_id) const; private: - ///Hash. Test. 08.2011. WW + /// Hash. Test. 08.2011. WW int num_par; int num_var; @@ -50,10 +50,11 @@ class Hash_Table }; #endif /*---------------------------------------------------------------*/ -//namespace FiniteElement {class CElement;} -//using FiniteElement::CElement; -namespace FiniteElement { - class CFiniteElementStd; +// namespace FiniteElement {class CElement;} +// using FiniteElement::CElement; +namespace FiniteElement +{ +class CFiniteElementStd; } class CFluidProperties @@ -75,64 +76,58 @@ class CFluidProperties double getAzentricFactor() const { return omega; } double getDiffusion() const { return diffusion; } double getSpecificHeatCapacity() const { return specific_heat_capacity; } - /** * get the reference temperature * @return */ double getReferenceTemperature() const { return T_0; } - std::ios::pos_type Read(std::ifstream*); void Write(std::ofstream*) const; void CalPrimaryVariable(std::vector& pcs_name_vector); // Add an argument: double* variables = NULL. 28.05.2008 WW double Density(double* variables = NULL); - double GetElementValueFromNodes(long ElementIndex, - int GPIndex, - int PhaseIndex, - int Variable); + double GetElementValueFromNodes(long ElementIndex, int GPIndex, int PhaseIndex, int Variable); double drhodP(double* variables = NULL); double drhodT(double* variables = NULL); double drhodX(int CIndex, double* variables = NULL); - double ComponentDensity(int CIndex, double* variables = NULL);//AKS - double Viscosity(double* variables = NULL); //OK4709 - //NB Jan09 - double PhaseDiffusion(double *variables = NULL); + double ComponentDensity(int CIndex, double* variables = NULL); // AKS + double Viscosity(double* variables = NULL); // OK4709 + // NB Jan09 + double PhaseDiffusion(double* variables = NULL); double SpecificHeatCapacity(double* variables = NULL); - void therm_prop(std::string caption); //NB 4.9.05 - double PhaseChange(); // JOD + void therm_prop(std::string caption); // NB 4.9.05 + double PhaseChange(); // JOD double HeatConductivity(double* variables = NULL); double CalcEnthalpy(double temperature); - double vaporDensity(const double T); //WW - //WW + double vaporDensity(const double T); // WW + // WW double vaporDensity_derivative(const double T); - bool CheckGravityCalculation() const {return cal_gravity; } - int GetHeatCapacityModel() const //YD + bool CheckGravityCalculation() const { return cal_gravity; } + int GetHeatCapacityModel() const // YD { return heat_capacity_model; } - double GetDiffusion() {return diffusion; } - int getCompressibilityTModel() const {return compressibility_model_temperature;} //CB + double GetDiffusion() { return diffusion; } + int getCompressibilityTModel() const { return compressibility_model_temperature; } // CB // Derivations of free Helmholtz energy, NB JUN 09 - double phi_r_d (double rho, double T) const; - double phi_r_tt (double rho, double T) const; - double phi_0_t (double T) const; - double phi_r_t (double rho, double T) const; - double phi_r_dt (double rho, double T) const; - double phi_r_dd (double rho, double T) const; - double phi_0_tt (double T) const; - double EffectiveDiffusionCoef(int CIndex, double* variables = NULL); //AKS - void SetFemEleStd(FiniteElement::CFiniteElementStd* fem) { Fem_Ele_Std = fem;} - + double phi_r_d(double rho, double T) const; + double phi_r_tt(double rho, double T) const; + double phi_0_t(double T) const; + double phi_r_t(double rho, double T) const; + double phi_r_dt(double rho, double T) const; + double phi_r_dd(double rho, double T) const; + double phi_0_tt(double T) const; + double EffectiveDiffusionCoef(int CIndex, double* variables = NULL); // AKS + void SetFemEleStd(FiniteElement::CFiniteElementStd* fem) { Fem_Ele_Std = fem; } private: - int fluid_id; // specification of substance (NB JUN 09) + int fluid_id; // specification of substance (NB JUN 09) std::string name; std::string cmpNm1, cmpNm2, cmpNm3, cmpNm4; // component name - int cmpN; //components number + int cmpN; // components number // FEM FiniteElement::CFiniteElementStd* Fem_Ele_Std; - long node; //OK4704 + long node; // OK4704 // Density int density_model; @@ -149,8 +144,8 @@ class CFluidProperties int heat_conductivity_model; // TF 11/2011 - used only in read- and write-method // std::string heat_conductivity_fct_name; - int heat_diffusion_model; //AKS - int heat_capacity_model; //YD, shifted to public JOD + int heat_diffusion_model; // AKS + int heat_capacity_model; // YD, shifted to public JOD // Electrical properties int electric_conductivity_model; int electric_conductivity_num_val; @@ -159,7 +154,7 @@ class CFluidProperties // Chemical properties // TF 11/2011 - only in read-method used // std::string dif_fct_name; - int diffusion_model; /* SB:p2 */ + int diffusion_model; /* SB:p2 */ // Phase diffusion (Daq, Yaws et al.) double diff; double A_Daq; @@ -175,23 +170,23 @@ class CFluidProperties std::vector specific_heat_capacity_pcs_name_vector; std::vector heat_conductivity_pcs_name_vector; std::vector enthalpy_pcs_name_vector; - //AKS + // AKS std::vector component_vector; bool drho_dT_unsaturated; double specific_heat_source; - double rhoc; //critical_density; //NB - double Tc; //critical_temperature; - double pc; //critical_pressure; - double Tt; //triple_point_temperature; - double pt; //triple_point_pressure; - double Rs; //specific_gas_constant; - double Ru; //universal_gas_constant; - double omega; // azentric factor for Peng-Robinson EOS + double rhoc; // critical_density; //NB + double Tc; // critical_temperature; + double pc; // critical_pressure; + double Tt; // triple_point_temperature; + double pt; // triple_point_pressure; + double Rs; // specific_gas_constant; + double Ru; // universal_gas_constant; + double omega; // azentric factor for Peng-Robinson EOS double molar_mass; - double Vd, Zc, n0, m0, a, b, k1, k2, k3;//constants are used in VTPR + double Vd, Zc, n0, m0, a, b, k1, k2, k3; // constants are used in VTPR /** * density */ @@ -210,25 +205,26 @@ class CFluidProperties double drho_dC; double diffusion; /*SB:2p */ - double diffusion_coef; //AKS + double diffusion_coef; // AKS // Viscosity double viscosity; double viscosity0; double viscosity_T_star; - double viscosity_T_shift; //JM in order to use some viscosity functions, based on total temperature, within Richards + double viscosity_T_shift; // JM in order to use some viscosity functions, based on total temperature, within + // Richards double my_0; double dmy_dp; double dmy_dT; double dmy_dC; - //Multi_componential flow - int decay_model, isotherm_model; + // Multi_componential flow + int decay_model, isotherm_model; double rho[4], mu[4], cp[4], kappa[4], lambda[4], Kd[4], D0[4], alpha_T[4], beta_p[4]; std::string eos_name, mu_JT; // Thermal properties double specific_heat_capacity; double beta_T; double heat_conductivity; - double temperature_buffer; //YD, shifted to public JOD + double temperature_buffer; // YD, shifted to public JOD // State variables double p_0; @@ -242,35 +238,35 @@ class CFluidProperties // Chemical properties double T_Latent1, T_Latent2, latent_heat; - std::string fluid_name; //NB4801 + std::string fluid_name; // NB4801 // compressibility - int compressibility_model_pressure; //NB - int compressibility_model_temperature; //NB - int solutal_expansivity_model; //NB - double compressibility_pressure; //NB - double compressibility_temperature; //NB - double solutal_expansivity; //AKS + int compressibility_model_pressure; // NB + int compressibility_model_temperature; // NB + int solutal_expansivity_model; // NB + double compressibility_pressure; // NB + double compressibility_temperature; // NB + double solutal_expansivity; // AKS int phase; // Limits and coefficients for free Helmholtz Energy, NB JUN 09 int limit[5]; - double k [2][8]; - double K [14][56], KP[4]; + double k[2][8]; + double K[14][56], KP[4]; // State variables - double primary_variable[10]; //WW - double primary_variable_t0[10]; //CMCD - double primary_variable_t1[10]; //CMCD - bool cal_gravity; //YD/WW + double primary_variable[10]; // WW + double primary_variable_t0[10]; // CMCD + double primary_variable_t1[10]; // CMCD + bool cal_gravity; // YD/WW - double GasViscosity_Reichenberg_1971(double,double); - //AKS + double GasViscosity_Reichenberg_1971(double, double); + // AKS double MATCalcFluidDensityMethod8(double p, double T, double C); double LiquidViscosity_Yaws_1976(double); double LiquidViscosity_Marsily_1986(double); - double LiquidViscosity_NN(double,double); - double LiquidViscosity_CMCD(double p,double T,double C); + double LiquidViscosity_NN(double, double); + double LiquidViscosity_CMCD(double p, double T, double C); double LiquidViscosity_expo(double T); double PhaseDiffusion_Yaws_1976(double); double MATCalcHeatConductivityMethod2(double p, double T, double C); @@ -288,11 +284,11 @@ class CFluidProperties friend CFluidProperties* MFPGet(const std::string&); friend CFluidProperties* MFPGet(int); friend void KNaplCalcDensity(); - friend double MFPGetNodeValue(long,const std::string&,int); + friend double MFPGetNodeValue(long, const std::string&, int); friend void MMPCalcSecondaryVariablesNew(CRFProcess*, bool); }; -extern std::vectormfp_vector; +extern std::vector mfp_vector; extern bool MFPRead(std::string); extern void MFPWrite(std::string); #define MFP_FILE_EXTENSION ".mfp" @@ -303,9 +299,9 @@ extern double MFPCalcFluidsHeatConductivity(long index, double theta, FiniteElement::CFiniteElementStd* assem = NULL); extern void MFPDelete(); -//OK/YD +// OK/YD extern CFluidProperties* MFPGet(const std::string&); -extern CFluidProperties* MFPGet(int); //NB JUN 09 - //NB AUG 09 -double MFPGetNodeValue(long,const std::string&,int); +extern CFluidProperties* MFPGet(int); // NB JUN 09 +// NB AUG 09 +double MFPGetNodeValue(long, const std::string&, int); #endif diff --git a/FEM/rf_mmp_new.cpp b/FEM/rf_mmp_new.cpp index bfb4a45a7..4ee68eaac 100644 --- a/FEM/rf_mmp_new.cpp +++ b/FEM/rf_mmp_new.cpp @@ -24,7 +24,7 @@ #include "tools.h" //#include "rf_pcs.h" //#include "femlib.h" -extern double* GEOGetELEJacobianMatrix(long number,double* detjac); +extern double* GEOGetELEJacobianMatrix(long number, double* detjac); #include "mathlib.h" //#include "rf_mfp_new.h" #include "rf_msp_new.h" @@ -32,7 +32,7 @@ extern double* GEOGetELEJacobianMatrix(long number,double* detjac); #include "rf_tim_new.h" #include "rfmat_cp.h" extern double gravity_constant; -//using SolidProp::CSolidProperties; +// using SolidProp::CSolidProperties; // LIB #include "files0.h" // this @@ -43,18 +43,18 @@ extern double gravity_constant; #include "fem_ele_vec.h" // MSHLib //#include "msh_lib.h" -#include "pcs_dm.h" //WX +#include "pcs_dm.h" //WX #include "PhysicalConstant.h" // MAT-MP data base lists -listkeywd_list; -listmat_name_list; -listmat_name_list_char; -listdb_mat_mp_list; +list keywd_list; +list mat_name_list; +list mat_name_list_char; +list db_mat_mp_list; // MAT-MP list -vectormmp_vector; -listmmp_group_list; +vector mmp_vector; +list mmp_group_list; using namespace std; using namespace PhysicalConstant; @@ -70,15 +70,14 @@ using FiniteElement::ElementValue_DM; 02/2004 OK Implementation last modification: **************************************************************************/ -CMediumProperties::CMediumProperties() : - geo_dimension(0), _mesh (NULL), _geo_type (GEOLIB::GEODOMAIN) +CMediumProperties::CMediumProperties() : geo_dimension(0), _mesh(NULL), _geo_type(GEOLIB::GEODOMAIN) { name = "DEFAULT"; mode = 0; selected = false; - m_pcs = NULL; //OK + m_pcs = NULL; // OK // GEO - geo_area = 1.0; //OK + geo_area = 1.0; // OK porosity_model = -1; porosity_model_values[0] = 0.1; tortuosity_model = -1; @@ -91,59 +90,59 @@ CMediumProperties::CMediumProperties() : tortuosity_tensor_type = 0; permeability_tensor[0] = 1.e-13; local_permeability = 1e-13; - residual_saturation[0] = 0.0; // sgr: residual saturation, this phase - maximum_saturation[0] = 1.0; // sgm: maximum saturation, this phase - saturation_exponent[0] = 1.0; // (set exponent = 1 results in a linear k_rel function) + residual_saturation[0] = 0.0; // sgr: residual saturation, this phase + maximum_saturation[0] = 1.0; // sgm: maximum saturation, this phase + saturation_exponent[0] = 1.0; // (set exponent = 1 results in a linear k_rel function) conductivity_model = -1; flowlinearity_model = 0; capillary_pressure_model = -1; - capillary_pressure_values[4] = 1.0/DBL_EPSILON; // JT: max Pc + capillary_pressure_values[4] = 1.0 / DBL_EPSILON; // JT: max Pc entry_pressure_conversion = false; permeability_saturation_model[0] = -1; - minimum_relative_permeability = 1.0e-9; // JT: the default value + minimum_relative_permeability = 1.0e-9; // JT: the default value unconfined_flow_group = -1; - permeability_stress_mode = -1; //WW - c_coefficient = NULL; //WW + permeability_stress_mode = -1; // WW + c_coefficient = NULL; // WW // surface flow friction_coefficient = -1; // friction_model = -1; // mass transport // heat transport - heat_dispersion_model = -1; //WW + heat_dispersion_model = -1; // WW heat_dispersion_longitudinal = 0.; heat_dispersion_transverse = 0.; lgpn = 0.0; mass_dispersion_transverse = 0.0; mass_dispersion_longitudinal = 0.0; - heat_diffusion_model = -1; //WW - base_heat_diffusion_coefficient = 2.16e-5; //JM + heat_diffusion_model = -1; // WW + base_heat_diffusion_coefficient = 2.16e-5; // JM geo_area = 1.0; -// geo_type_name = "DOMAIN"; //OK + // geo_type_name = "DOMAIN"; //OK vol_mat = 0.0; vol_bio = 0.0; vol_mat_model = 0; vol_bio_model = 0; foc = 0.0; - alpha_t_model = -1; - graindiameter = 0; //CB Chiogna et al alpha-t model - hydraulicrad = 0; - betaexpo = 0; - ElementVolumeMultiplyer = 1.0; //SB / JOD 2014-11-10 - - permeability_pressure_model = -1; //01.09.2011. WW - permeability_strain_model = -1; //01.09.2011. WW - forchheimer_cf = 0.0; //NW - forchheimer_De = .0; - forchheimer_a1 = .0; - forchheimer_a2 = .0; - heat_transfer_model = 0; - effective_heat_transfer_model = 0; - heat_transfer_model_value = .0; - particle_diameter_model = 0; - particle_diameter_model_value = .0; - - PhaseHeatedByFriction = "SOLID"; - _fric_phase = FiniteElement::SOLID; + alpha_t_model = -1; + graindiameter = 0; // CB Chiogna et al alpha-t model + hydraulicrad = 0; + betaexpo = 0; + ElementVolumeMultiplyer = 1.0; // SB / JOD 2014-11-10 + + permeability_pressure_model = -1; // 01.09.2011. WW + permeability_strain_model = -1; // 01.09.2011. WW + forchheimer_cf = 0.0; // NW + forchheimer_De = .0; + forchheimer_a1 = .0; + forchheimer_a2 = .0; + heat_transfer_model = 0; + effective_heat_transfer_model = 0; + heat_transfer_model_value = .0; + particle_diameter_model = 0; + particle_diameter_model_value = .0; + + PhaseHeatedByFriction = "SOLID"; + _fric_phase = FiniteElement::SOLID; storage_effstress_model = 0; permeability_effstress_model = 0; evaporation = -1; @@ -158,8 +157,8 @@ CMediumProperties::CMediumProperties() : **************************************************************************/ CMediumProperties::~CMediumProperties(void) { - if(c_coefficient) - delete[] c_coefficient; //WW + if (c_coefficient) + delete[] c_coefficient; // WW geo_name_vector.clear(); } @@ -177,7 +176,7 @@ CMediumProperties::~CMediumProperties(void) bool MMPRead(std::string base_file_name) { //---------------------------------------------------------------------- - //OK MMPDelete(); + // OK MMPDelete(); //---------------------------------------------------------------------- std::cout << "MMPRead ... " << std::flush; CMediumProperties* m_mat_mp = NULL; @@ -189,37 +188,38 @@ bool MMPRead(std::string base_file_name) // file handling std::string mp_file_name; mp_file_name = base_file_name + MMP_FILE_EXTENSION; - std::ifstream mp_file (mp_file_name.data(),std::ios::in); + std::ifstream mp_file(mp_file_name.data(), std::ios::in); if (!mp_file.good()) { - std::cout << "! Error in MMPRead: No material data !" << "\n"; + std::cout << "! Error in MMPRead: No material data !" + << "\n"; return false; } - mp_file.seekg(0L,std::ios::beg); + mp_file.seekg(0L, std::ios::beg); //======================================================================== // keyword loop while (!mp_file.eof()) { - mp_file.getline(line,MAX_ZEILE); + mp_file.getline(line, MAX_ZEILE); line_string = line; - if(line_string.find("#STOP") != string::npos) + if (line_string.find("#STOP") != string::npos) { - std::cout << "done, read " << mmp_vector.size() << " medium properties" << - "\n"; + std::cout << "done, read " << mmp_vector.size() << " medium properties" + << "\n"; return true; } //---------------------------------------------------------------------- // keyword found - if(line_string.find("#MEDIUM_PROPERTIES") != string::npos) + if (line_string.find("#MEDIUM_PROPERTIES") != string::npos) { m_mat_mp = new CMediumProperties(); position = m_mat_mp->Read(&mp_file); - //OK41 + // OK41 m_mat_mp->number = (int)mmp_vector.size(); mmp_vector.push_back(m_mat_mp); - mp_file.seekg(position,std::ios::beg); - } // keyword found - } // eof + mp_file.seekg(position, std::ios::beg); + } // keyword found + } // eof return true; // Tests } @@ -286,7 +286,7 @@ std::ios::pos_type CMediumProperties::Read(std::ifstream* mmp_file) std::ios::pos_type position; std::string dollar("$"); std::string hash("#"); - //WW bool new_subkeyword = false; + // WW bool new_subkeyword = false; bool new_keyword = false; std::string m_string; // WW @@ -296,24 +296,24 @@ std::ios::pos_type CMediumProperties::Read(std::ifstream* mmp_file) char seps[] = "+\n"; char seps1[] = "*"; double f_buff; - size_t indexChWin, indexChLinux; //JT, DEC 2009 - std::string funfname; //JT, DEC 2009 + size_t indexChWin, indexChLinux; // JT, DEC 2009 + std::string funfname; // JT, DEC 2009 while (!new_keyword) { - //WW new_subkeyword = false; + // WW new_subkeyword = false; position = mmp_file->tellg(); line_string = GetLineFromFile1(mmp_file); - if(line_string.size() < 1) + if (line_string.size() < 1) break; - if(line_string.find(hash) != std::string::npos) + if (line_string.find(hash) != std::string::npos) { new_keyword = true; break; } //-------------------------------------------------------------------- - //PCS //YD - if(line_string.find("$PCS_TYPE") != std::string::npos) + // PCS //YD + if (line_string.find("$PCS_TYPE") != std::string::npos) { in.str(GetLineFromFile1(mmp_file)); in >> pcs_type_name; @@ -321,45 +321,43 @@ std::ios::pos_type CMediumProperties::Read(std::ifstream* mmp_file) continue; } - //NAME - //subkeyword found - if(line_string.find("$NAME") != std::string::npos) + // NAME + // subkeyword found + if (line_string.find("$NAME") != std::string::npos) { in.str(GetLineFromFile1(mmp_file)); - in >> name; //sub_line + in >> name; // sub_line in.clear(); continue; } //-------------------------------------------------------------------- - //GEO_TYPE + // GEO_TYPE - //subkeyword found - if(line_string.find("$GEO_TYPE") != std::string::npos) + // subkeyword found + if (line_string.find("$GEO_TYPE") != std::string::npos) { - while(!(m_string.find("$") != std::string::npos) && - (!(m_string.find("#") != std::string::npos))) + while (!(m_string.find("$") != std::string::npos) && (!(m_string.find("#") != std::string::npos))) { position = mmp_file->tellg(); in.str(GetLineFromFile1(mmp_file)); in >> m_string >> geo_name; in.clear(); - if(!(m_string.find("$") != std::string::npos) && - (!(m_string.find("#") != std::string::npos))) + if (!(m_string.find("$") != std::string::npos) && (!(m_string.find("#") != std::string::npos))) { -// geo_type_name = m_string; - _geo_type = GEOLIB::convertGeoType (m_string); + // geo_type_name = m_string; + _geo_type = GEOLIB::convertGeoType(m_string); geo_name_vector.push_back(geo_name); } } - mmp_file->seekg(position,std::ios::beg); + mmp_file->seekg(position, std::ios::beg); continue; } //.................................................................... // ToDo to GeoLib - //2i..GEOMETRY_DIMENSION + // 2i..GEOMETRY_DIMENSION //------------------------------------------------------------------------ - //subkeyword found - if(line_string.find("$GEOMETRY_DIMENSION") != std::string::npos) + // subkeyword found + if (line_string.find("$GEOMETRY_DIMENSION") != std::string::npos) { in.str(GetLineFromFile1(mmp_file)); in >> geo_dimension; @@ -367,8 +365,8 @@ std::ios::pos_type CMediumProperties::Read(std::ifstream* mmp_file) continue; } //------------------------------------------------------------------------ - //subkeyword found - if(line_string.find("$GEOMETRY_INCLINATION") != std::string::npos) + // subkeyword found + if (line_string.find("$GEOMETRY_INCLINATION") != std::string::npos) { in.str(GetLineFromFile1(mmp_file)); in >> geo_inclination; @@ -377,355 +375,350 @@ std::ios::pos_type CMediumProperties::Read(std::ifstream* mmp_file) } //------------------------------------------------------------------------ // ToDo to GeoLib - //2ii..GEOMETRY_AREA + // 2ii..GEOMETRY_AREA //------------------------------------------------------------------------ - indexChWin = indexChLinux = 0; //JT, DEC 2009 - //subkeyword found - if(line_string.find("$GEOMETRY_AREA") != std::string::npos) + indexChWin = indexChLinux = 0; // JT, DEC 2009 + // subkeyword found + if (line_string.find("$GEOMETRY_AREA") != std::string::npos) { in.str(GetLineFromFile1(mmp_file)); in >> line_string; - if(line_string.find("FILE") != string::npos) + if (line_string.find("FILE") != string::npos) { in >> geo_area_file; // JT, Dec. 16, 2009, added lines below to correct and globalize the read of geometry area file std::string file_name = geo_area_file; indexChWin = FileName.find_last_of('\\'); indexChLinux = FileName.find_last_of('/'); - if(indexChWin == string::npos && indexChLinux == std::string::npos) + if (indexChWin == string::npos && indexChLinux == std::string::npos) funfname = file_name; - else if(indexChWin != string::npos) + else if (indexChWin != string::npos) { - funfname = FileName.substr(0,indexChWin); + funfname = FileName.substr(0, indexChWin); funfname = funfname + "\\" + file_name; } - else if(indexChLinux != string::npos) + else if (indexChLinux != string::npos) { - funfname = FileName.substr(0,indexChLinux); + funfname = FileName.substr(0, indexChLinux); funfname = funfname + "/" + file_name; } geo_area_file = funfname; // End of new lines } else - geo_area = strtod(line_string.data(),NULL); + geo_area = strtod(line_string.data(), NULL); in.clear(); continue; } //------------------------------------------------------------------------ - //3..POROSITY + // 3..POROSITY //------------------------------------------------------------------------ - //CB - //subkeyword found - if((line_string.find("$POROSITY") != string::npos) && - (!(line_string.find("_DISTRIBUTION") != std::string::npos))) + // CB + // subkeyword found + if ((line_string.find("$POROSITY") != string::npos) + && (!(line_string.find("_DISTRIBUTION") != std::string::npos))) { in.str(GetLineFromFile1(mmp_file)); in >> porosity_model; - switch(porosity_model) + switch (porosity_model) { - case 0: // n=f(x) - in >> porosity_curve; - break; - case 1: // n=const - in >> porosity_model_values[0]; - break; - case 2: // f(normal effective stress for fracture systems) - in >> porosity_model_values[0]; - in >> porosity_model_values[1]; - in >> porosity_model_values[2]; - in >> porosity_model_values[3]; - porosity_pcs_name_vector.push_back("PRESSURE1"); - break; - case 3: // Chemical swelling model - in >> porosity_model_values[0]; // Initial porosity - in >> porosity_model_values[1]; // Specific surface[m^2/g] - in >> porosity_model_values[2]; // Expansive min. fragtion - in >> porosity_model_values[3]; // m - in >> porosity_model_values[4]; // I - in >> porosity_model_values[5]; // S^l_0 - in >> porosity_model_values[6]; // beta - porosity_pcs_name_vector.push_back("SATURATION2"); - porosity_pcs_name_vector.push_back("TEMPERATURE1"); - break; - case 4: // Chemical swelling model (constrained swelling, constant I) - in >> porosity_model_values[0]; // Initial porosity - in >> porosity_model_values[1]; // Specific surface[m^2/g] - in >> porosity_model_values[2]; // Expansive min. fragtion - in >> porosity_model_values[3]; // m - in >> porosity_model_values[4]; // I - in >> porosity_model_values[5]; // S^l_0 - in >> porosity_model_values[6]; // beta - in >> porosity_model_values[7]; // n_min - //for richard flow only - porosity_pcs_name_vector.push_back("SATURATION1"); - porosity_pcs_name_vector.push_back("TEMPERATURE1"); - break; - case 5: // Chemical swelling model (free swelling, constant I) - in >> porosity_model_values[0]; // Initial porosity - in >> porosity_model_values[1]; // Specific surface[m^2/g] - in >> porosity_model_values[2]; // Expansive min. fragtion - in >> porosity_model_values[3]; // m - in >> porosity_model_values[4]; // I - in >> porosity_model_values[5]; // S^l_0 - in >> porosity_model_values[6]; // beta - porosity_pcs_name_vector.push_back("SATURATION2"); - porosity_pcs_name_vector.push_back("TEMPERATURE1"); - break; - case 6: // Chemical swelling model (constrained swelling) - in >> porosity_model_values[0]; // Initial porosity - in >> porosity_model_values[1]; // Specific surface[m^2/g] - in >> porosity_model_values[2]; // Expansive min. fragtion - in >> porosity_model_values[3]; // m - in >> porosity_model_values[4]; // I - in >> porosity_model_values[5]; // S^l_0 - in >> porosity_model_values[6]; // beta - in >> porosity_model_values[7]; // n_min - porosity_pcs_name_vector.push_back("SATURATION2"); - porosity_pcs_name_vector.push_back("TEMPERATURE1"); - break; - case 7: // n=f(stress_mean) WW - in >> porosity_curve; - break; - case 10: // Chemical swelling model (constrained swelling, constant I) - { - int m; - in >> porosity_model_values[0]; // Initial porosity - in >> m; // m - if (m > 15) - std::cout - << - "Maximal number of solid phases is now limited to be 15!!!" - << "\n"; - for (int i = 0; i < m + 1; i++) - // molar volume [l/mol] - in >> porosity_model_values[i + 1]; - break; - } - case 11: //MB: read from file ToDo - // in >> porosity_file; // CB - in >> porosity_model_values[0]; // CB some dummy default value is read - // CB $POROSITY_DISTRIBUTION should be given as keyword in *.mmp file, - // porosities then are to be read in from file by fct. - // CMediumProperties::SetDistributedELEProperties - break; - case 12: - in >> porosity_model_values[0]; //WX 03.2011, dependent on strain - break; - case 13: // mineral precipitation / dissolution by ABM - in >> porosity_model_values[0]; // Initial porosity - break; + case 0: // n=f(x) + in >> porosity_curve; + break; + case 1: // n=const + in >> porosity_model_values[0]; + break; + case 2: // f(normal effective stress for fracture systems) + in >> porosity_model_values[0]; + in >> porosity_model_values[1]; + in >> porosity_model_values[2]; + in >> porosity_model_values[3]; + porosity_pcs_name_vector.push_back("PRESSURE1"); + break; + case 3: // Chemical swelling model + in >> porosity_model_values[0]; // Initial porosity + in >> porosity_model_values[1]; // Specific surface[m^2/g] + in >> porosity_model_values[2]; // Expansive min. fragtion + in >> porosity_model_values[3]; // m + in >> porosity_model_values[4]; // I + in >> porosity_model_values[5]; // S^l_0 + in >> porosity_model_values[6]; // beta + porosity_pcs_name_vector.push_back("SATURATION2"); + porosity_pcs_name_vector.push_back("TEMPERATURE1"); + break; + case 4: // Chemical swelling model (constrained swelling, constant I) + in >> porosity_model_values[0]; // Initial porosity + in >> porosity_model_values[1]; // Specific surface[m^2/g] + in >> porosity_model_values[2]; // Expansive min. fragtion + in >> porosity_model_values[3]; // m + in >> porosity_model_values[4]; // I + in >> porosity_model_values[5]; // S^l_0 + in >> porosity_model_values[6]; // beta + in >> porosity_model_values[7]; // n_min + // for richard flow only + porosity_pcs_name_vector.push_back("SATURATION1"); + porosity_pcs_name_vector.push_back("TEMPERATURE1"); + break; + case 5: // Chemical swelling model (free swelling, constant I) + in >> porosity_model_values[0]; // Initial porosity + in >> porosity_model_values[1]; // Specific surface[m^2/g] + in >> porosity_model_values[2]; // Expansive min. fragtion + in >> porosity_model_values[3]; // m + in >> porosity_model_values[4]; // I + in >> porosity_model_values[5]; // S^l_0 + in >> porosity_model_values[6]; // beta + porosity_pcs_name_vector.push_back("SATURATION2"); + porosity_pcs_name_vector.push_back("TEMPERATURE1"); + break; + case 6: // Chemical swelling model (constrained swelling) + in >> porosity_model_values[0]; // Initial porosity + in >> porosity_model_values[1]; // Specific surface[m^2/g] + in >> porosity_model_values[2]; // Expansive min. fragtion + in >> porosity_model_values[3]; // m + in >> porosity_model_values[4]; // I + in >> porosity_model_values[5]; // S^l_0 + in >> porosity_model_values[6]; // beta + in >> porosity_model_values[7]; // n_min + porosity_pcs_name_vector.push_back("SATURATION2"); + porosity_pcs_name_vector.push_back("TEMPERATURE1"); + break; + case 7: // n=f(stress_mean) WW + in >> porosity_curve; + break; + case 10: // Chemical swelling model (constrained swelling, constant I) + { + int m; + in >> porosity_model_values[0]; // Initial porosity + in >> m; // m + if (m > 15) + std::cout << "Maximal number of solid phases is now limited to be 15!!!" + << "\n"; + for (int i = 0; i < m + 1; i++) + // molar volume [l/mol] + in >> porosity_model_values[i + 1]; + break; + } + case 11: // MB: read from file ToDo + // in >> porosity_file; // CB + in >> porosity_model_values[0]; // CB some dummy default value is read + // CB $POROSITY_DISTRIBUTION should be given as keyword in *.mmp file, + // porosities then are to be read in from file by fct. + // CMediumProperties::SetDistributedELEProperties + break; + case 12: + in >> porosity_model_values[0]; // WX 03.2011, dependent on strain + break; + case 13: // mineral precipitation / dissolution by ABM + in >> porosity_model_values[0]; // Initial porosity + break; #ifdef GEM_REACT - case 15: - in >> porosity_model_values[0]; // set a default value for GEMS calculation - // save this seperately; - break; + case 15: + in >> porosity_model_values[0]; // set a default value for GEMS calculation + // save this seperately; + break; #endif #ifdef BRNS - case 16: - in >> porosity_model_values[0]; // set a default value for BRNS calculation - break; + case 16: + in >> porosity_model_values[0]; // set a default value for BRNS calculation + break; #endif - default: - std::cerr << "Error in MMPRead: no valid porosity model" << - "\n"; - break; + default: + std::cerr << "Error in MMPRead: no valid porosity model" + << "\n"; + break; } in.clear(); continue; } - //subkeyword found - if(line_string.find("$VOL_MAT") != string::npos) + // subkeyword found + if (line_string.find("$VOL_MAT") != string::npos) { in.str(GetLineFromFile1(mmp_file)); // in >> idummy >> this->vol_mat; CB in >> vol_mat_model >> this->vol_mat; - switch(vol_mat_model) + switch (vol_mat_model) { - case 1: // do nothing - break; - case 2: // do nothing - break; - default: - std::cout << "Error in MMPRead: no valid vol_mat_model" << - "\n"; - break; + case 1: // do nothing + break; + case 2: // do nothing + break; + default: + std::cout << "Error in MMPRead: no valid vol_mat_model" + << "\n"; + break; } in.clear(); continue; } - //subkeyword found - if(line_string.find("$VOL_BIO") != string::npos) + // subkeyword found + if (line_string.find("$VOL_BIO") != string::npos) { in.str(GetLineFromFile1(mmp_file)); // in >> idummy >> this->vol_bio; CB in >> vol_bio_model >> this->vol_bio; - switch(vol_bio_model) + switch (vol_bio_model) { - case 1: // do nothing - break; - case 2: // do nothing - break; - default: - std::cout << "Error in MMPRead: no valid vol_bio_model" << - "\n"; - break; + case 1: // do nothing + break; + case 2: // do nothing + break; + default: + std::cout << "Error in MMPRead: no valid vol_bio_model" + << "\n"; + break; } in.clear(); continue; } //------------------------------------------------------------------------ - //4..TORTUOSITY + // 4..TORTUOSITY //------------------------------------------------------------------------ - //subkeyword found - if(line_string.find("$TORTUOSITY") != std::string::npos) + // subkeyword found + if (line_string.find("$TORTUOSITY") != std::string::npos) { in.str(GetLineFromFile1(mmp_file)); in >> tortuosity_tensor_type_name; - switch(tortuosity_tensor_type_name[0]) + switch (tortuosity_tensor_type_name[0]) { - case '0': // n=f(x) <- Case zero - break; - case '1': // n=const - tortuosity_model = 1; - in >> tortuosity_model_values[0]; - break; - case '2': // t=n*factor - tortuosity_model = 2; - in >> tortuosity_model_values[0]; - break; - case 'I': // isotropic - tortuosity_tensor_type = 0; - tortuosity_model = 1; - in >> tortuosity_model_values[0]; - //CMCD to pick up 2D and 3D Isotropic case. - tortuosity_model_values[1] = tortuosity_model_values[2] = - tortuosity_model_values[0]; - break; - case 'O': // orthotropic <- Case Alphabet O - tortuosity_model = 1; - tortuosity_tensor_type = 1; - if(geo_dimension == 0) - std::cout << - "Error in CMediumProperties::Read: no geometric dimension" - << "\n"; - if(geo_dimension == 2) - { - in >> tortuosity_model_values[0]; - in >> tortuosity_model_values[1]; - } - if(geo_dimension == 3) - { + case '0': // n=f(x) <- Case zero + break; + case '1': // n=const + tortuosity_model = 1; in >> tortuosity_model_values[0]; - in >> tortuosity_model_values[1]; - in >> tortuosity_model_values[2]; - } - break; - case 'A': // anisotropic - tortuosity_model = 1; - tortuosity_tensor_type = 2; - if(geo_dimension == 0) - std::cout << - "Error in CMediumProperties::Read: no geometric dimension" - << "\n"; - if(geo_dimension == 2) - { + break; + case '2': // t=n*factor + tortuosity_model = 2; in >> tortuosity_model_values[0]; - in >> tortuosity_model_values[1]; - in >> tortuosity_model_values[2]; - in >> tortuosity_model_values[3]; - } - if(geo_dimension == 3) - { + break; + case 'I': // isotropic + tortuosity_tensor_type = 0; + tortuosity_model = 1; in >> tortuosity_model_values[0]; - in >> tortuosity_model_values[1]; - in >> tortuosity_model_values[2]; - in >> tortuosity_model_values[3]; - in >> tortuosity_model_values[4]; - in >> tortuosity_model_values[5]; - in >> tortuosity_model_values[6]; - in >> tortuosity_model_values[7]; - in >> tortuosity_model_values[8]; - } - break; - case 'F': //SB: read from file - tortuosity_model = 2; //OK - in >> permeability_file; - break; - default: - std::cout << "Error in MMPRead: no valid tortuosity tensor type" << - "\n"; - break; + // CMCD to pick up 2D and 3D Isotropic case. + tortuosity_model_values[1] = tortuosity_model_values[2] = tortuosity_model_values[0]; + break; + case 'O': // orthotropic <- Case Alphabet O + tortuosity_model = 1; + tortuosity_tensor_type = 1; + if (geo_dimension == 0) + std::cout << "Error in CMediumProperties::Read: no geometric dimension" + << "\n"; + if (geo_dimension == 2) + { + in >> tortuosity_model_values[0]; + in >> tortuosity_model_values[1]; + } + if (geo_dimension == 3) + { + in >> tortuosity_model_values[0]; + in >> tortuosity_model_values[1]; + in >> tortuosity_model_values[2]; + } + break; + case 'A': // anisotropic + tortuosity_model = 1; + tortuosity_tensor_type = 2; + if (geo_dimension == 0) + std::cout << "Error in CMediumProperties::Read: no geometric dimension" + << "\n"; + if (geo_dimension == 2) + { + in >> tortuosity_model_values[0]; + in >> tortuosity_model_values[1]; + in >> tortuosity_model_values[2]; + in >> tortuosity_model_values[3]; + } + if (geo_dimension == 3) + { + in >> tortuosity_model_values[0]; + in >> tortuosity_model_values[1]; + in >> tortuosity_model_values[2]; + in >> tortuosity_model_values[3]; + in >> tortuosity_model_values[4]; + in >> tortuosity_model_values[5]; + in >> tortuosity_model_values[6]; + in >> tortuosity_model_values[7]; + in >> tortuosity_model_values[8]; + } + break; + case 'F': // SB: read from file + tortuosity_model = 2; // OK + in >> permeability_file; + break; + default: + std::cout << "Error in MMPRead: no valid tortuosity tensor type" + << "\n"; + break; } in.clear(); continue; } //------------------------------------------------------------------------ - //5..MOBILE_IMOBILE_MODEL + // 5..MOBILE_IMOBILE_MODEL //------------------------------------------------------------------------ - //To do as necessary + // To do as necessary //------------------------------------------------------------------------ - //6..LITHOLOGY_GRAIN_CLASS + // 6..LITHOLOGY_GRAIN_CLASS //------------------------------------------------------------------------ - //To do as necessary + // To do as necessary //------------------------------------------------------------------------ - //7..FLOWLINEARITY + // 7..FLOWLINEARITY //------------------------------------------------------------------------ - //subkeyword found - if(line_string.find("$FLOWLINEARITY") != std::string::npos) + // subkeyword found + if (line_string.find("$FLOWLINEARITY") != std::string::npos) { in.str(GetLineFromFile1(mmp_file)); in >> flowlinearity_model; - switch(flowlinearity_model) + switch (flowlinearity_model) { - case 0: // k=f(x) - break; - case 1: // Read in alpha - //Alpha - in >> flowlinearity_model_values[0]; - break; - case 2: // For equivalent flow in trianglular elements - //Alpha - in >> flowlinearity_model_values[0]; - //Number of Fractures in Equivalent Medium - in >> flowlinearity_model_values[1]; - //Reynolds Number above which non linear flow occurs. - in >> flowlinearity_model_values[2]; - pcs_name_vector.push_back("PRESSURE1"); - break; - case 3: // EE formulation for Forchheimer - in >> forchheimer_cf; - std::cout << "->Forchheimer nonlinear flow for EE" << std::endl; - break; - case 4: // GW formulation for Forchheimer - in >> forchheimer_a1 >> forchheimer_a2; - std::cout << "->Forchheimer nonlinear flow with given a1, a2" << std::endl; - break; - case 5: // GW formulation for Forchheimer if a1=1/k0 - in >> forchheimer_a2; - forchheimer_a1 = .0; - std::cout << "->Forchheimer nonlinear flow assuming a1=1/K0" << std::endl; - break; - case 6: // EE formulation 2 for Forchheimer - in >> forchheimer_De; - std::cout << "->Forchheimer nonlinear flow for EE" << '\n'; - break; - default: - std::cout << "Error in MMPRead: no valid flow linearity model" << - "\n"; - break; + case 0: // k=f(x) + break; + case 1: // Read in alpha + // Alpha + in >> flowlinearity_model_values[0]; + break; + case 2: // For equivalent flow in trianglular elements + // Alpha + in >> flowlinearity_model_values[0]; + // Number of Fractures in Equivalent Medium + in >> flowlinearity_model_values[1]; + // Reynolds Number above which non linear flow occurs. + in >> flowlinearity_model_values[2]; + pcs_name_vector.push_back("PRESSURE1"); + break; + case 3: // EE formulation for Forchheimer + in >> forchheimer_cf; + std::cout << "->Forchheimer nonlinear flow for EE" << std::endl; + break; + case 4: // GW formulation for Forchheimer + in >> forchheimer_a1 >> forchheimer_a2; + std::cout << "->Forchheimer nonlinear flow with given a1, a2" << std::endl; + break; + case 5: // GW formulation for Forchheimer if a1=1/k0 + in >> forchheimer_a2; + forchheimer_a1 = .0; + std::cout << "->Forchheimer nonlinear flow assuming a1=1/K0" << std::endl; + break; + case 6: // EE formulation 2 for Forchheimer + in >> forchheimer_De; + std::cout << "->Forchheimer nonlinear flow for EE" << '\n'; + break; + default: + std::cout << "Error in MMPRead: no valid flow linearity model" + << "\n"; + break; } in.clear(); continue; } //------------------------------------------------------------------------ - //8..SORPTION_MODEL + // 8..SORPTION_MODEL //------------------------------------------------------------------------ - //subkeyword found - if(line_string.find("$ORGANIC_CARBON") != std::string::npos) + // subkeyword found + if (line_string.find("$ORGANIC_CARBON") != std::string::npos) { in.str(GetLineFromFile1(mmp_file)); in >> foc; @@ -734,198 +727,195 @@ std::ios::pos_type CMediumProperties::Read(std::ifstream* mmp_file) } //------------------------------------------------------------------------ - //9..STORAGE + // 9..STORAGE //------------------------------------------------------------------------ - //subkeyword found - if(line_string.find("$STORAGE") != std::string::npos) + // subkeyword found + if (line_string.find("$STORAGE") != std::string::npos) { in.str(GetLineFromFile1(mmp_file)); in >> storage_model; - switch(storage_model) + switch (storage_model) { - case 0: // S=f(x) - in >> storage_model_values[0]; //Function of pressure defined by curve - pcs_name_vector.push_back("PRESSURE1"); - break; - case 1: // S=const - in >> storage_model_values[0]; //Constant value in Pa - break; - case 2: - in >> storage_model_values[0]; //S0 - in >> storage_model_values[1]; //increase - in >> storage_model_values[2]; //sigma(z0) - in >> storage_model_values[3]; //d_sigma/d_z - break; - case 3: - in >> storage_model_values[0]; //curve number (as real number) - in >> storage_model_values[1]; //sigma(z0) - in >> storage_model_values[2]; //_sigma/d_z - break; - case 4: - in >> storage_model_values[0]; //curve number (as real number) - in >> storage_model_values[1]; //time collation - in >> storage_model_values[2]; //solid density - in >> storage_model_values[3]; //curve fitting factor, default 1 - pcs_name_vector.push_back("PRESSURE1"); - break; - case 5: //Storativity is a function of normal effective stress defined by curve, set up for KTB. - in >> storage_model_values[0]; //curve number - in >> storage_model_values[1]; //time collation - in >> storage_model_values[2]; //Default storage value for material groups > 0 - in >> storage_model_values[3]; //Angular difference between Y direction and Sigma 1 - pcs_name_vector.push_back("PRESSURE1"); - break; - case 6: //Storativity is a function of normal effective stress defined by curve and distance from borehole, set up for KTB. - in >> storage_model_values[0]; //curve number - in >> storage_model_values[1]; //time collation - in >> storage_model_values[2]; //Default storage value for material groups > 0 - in >> storage_model_values[3]; //Angular difference between Y direction and Sigma 1 - in >> storage_model_values[4]; //Borehole (x) coordinate - in >> storage_model_values[5]; //Borehole (y) coordinate - in >> storage_model_values[6]; //Borehole (z) coordinate - in >> storage_model_values[7]; //Maximum thickness of shear zone - in >> storage_model_values[8]; //Fracture density - pcs_name_vector.push_back("PRESSURE1"); - break; - case 10: // S=const for permeability_saturation_model = 10 - storage_model_values[0] = 1; - break; - case 11: - storage_model_values[0] = 1; - break; - default: - cout << "Error in MMPRead: no valid storativity model" << "\n"; - break; - case 7: //RW/WW - in >> storage_model_values[0]; //Biot's alpha - in >> storage_model_values[1]; //Skempton's B coefficient - in >> storage_model_values[2]; //macroscopic drained bulk modulus - double val_l = storage_model_values[0] * - (1. - storage_model_values[0] * - storage_model_values[1]) - / storage_model_values[1] / storage_model_values[2]; - storage_model_values[1] = val_l; - break; + case 0: // S=f(x) + in >> storage_model_values[0]; // Function of pressure defined by curve + pcs_name_vector.push_back("PRESSURE1"); + break; + case 1: // S=const + in >> storage_model_values[0]; // Constant value in Pa + break; + case 2: + in >> storage_model_values[0]; // S0 + in >> storage_model_values[1]; // increase + in >> storage_model_values[2]; // sigma(z0) + in >> storage_model_values[3]; // d_sigma/d_z + break; + case 3: + in >> storage_model_values[0]; // curve number (as real number) + in >> storage_model_values[1]; // sigma(z0) + in >> storage_model_values[2]; //_sigma/d_z + break; + case 4: + in >> storage_model_values[0]; // curve number (as real number) + in >> storage_model_values[1]; // time collation + in >> storage_model_values[2]; // solid density + in >> storage_model_values[3]; // curve fitting factor, default 1 + pcs_name_vector.push_back("PRESSURE1"); + break; + case 5: // Storativity is a function of normal effective stress defined by curve, set up for KTB. + in >> storage_model_values[0]; // curve number + in >> storage_model_values[1]; // time collation + in >> storage_model_values[2]; // Default storage value for material groups > 0 + in >> storage_model_values[3]; // Angular difference between Y direction and Sigma 1 + pcs_name_vector.push_back("PRESSURE1"); + break; + case 6: // Storativity is a function of normal effective stress defined by curve and distance from + // borehole, set up for KTB. + in >> storage_model_values[0]; // curve number + in >> storage_model_values[1]; // time collation + in >> storage_model_values[2]; // Default storage value for material groups > 0 + in >> storage_model_values[3]; // Angular difference between Y direction and Sigma 1 + in >> storage_model_values[4]; // Borehole (x) coordinate + in >> storage_model_values[5]; // Borehole (y) coordinate + in >> storage_model_values[6]; // Borehole (z) coordinate + in >> storage_model_values[7]; // Maximum thickness of shear zone + in >> storage_model_values[8]; // Fracture density + pcs_name_vector.push_back("PRESSURE1"); + break; + case 10: // S=const for permeability_saturation_model = 10 + storage_model_values[0] = 1; + break; + case 11: + storage_model_values[0] = 1; + break; + default: + cout << "Error in MMPRead: no valid storativity model" + << "\n"; + break; + case 7: // RW/WW + in >> storage_model_values[0]; // Biot's alpha + in >> storage_model_values[1]; // Skempton's B coefficient + in >> storage_model_values[2]; // macroscopic drained bulk modulus + double val_l = storage_model_values[0] * (1. - storage_model_values[0] * storage_model_values[1]) + / storage_model_values[1] / storage_model_values[2]; + storage_model_values[1] = val_l; + break; } in.clear(); continue; } //------------------------------------------------------------------------ - //10..CONDUCTIVITY_MODEL + // 10..CONDUCTIVITY_MODEL //------------------------------------------------------------------------ - //subkeyword found - if(line_string.find("$CONDUCTIVITY_MODEL") != std::string::npos) + // subkeyword found + if (line_string.find("$CONDUCTIVITY_MODEL") != std::string::npos) { in.str(GetLineFromFile1(mmp_file)); in >> conductivity_model; - switch(conductivity_model) + switch (conductivity_model) { - case 0: // K=f(x) - break; - case 1: // K=const - in >> conductivity; - break; - case 2: // Manning - break; - case 3: // Chezy - break; - default: - std::cout << "Error in MMPRead: no valid conductivity model" << - "\n"; - break; + case 0: // K=f(x) + break; + case 1: // K=const + in >> conductivity; + break; + case 2: // Manning + break; + case 3: // Chezy + break; + default: + std::cout << "Error in MMPRead: no valid conductivity model" + << "\n"; + break; } in.clear(); continue; } - //subkeyword found - if(line_string.find("$UNCONFINED") != string::npos) + // subkeyword found + if (line_string.find("$UNCONFINED") != string::npos) { - //unconfined_flow_group = 1; + // unconfined_flow_group = 1; in.str(GetLineFromFile1(mmp_file)); - in >> unconfined_flow_group; // 5.3.07 JOD + in >> unconfined_flow_group; // 5.3.07 JOD in.clear(); continue; } //------------------------------------------------------------------------ - //11..PERMEABILITY_TENSOR + // 11..PERMEABILITY_TENSOR //------------------------------------------------------------------------ - //subkeyword found - if(line_string.find("$PERMEABILITY_TENSOR") != std::string::npos) + // subkeyword found + if (line_string.find("$PERMEABILITY_TENSOR") != std::string::npos) { in.str(GetLineFromFile1(mmp_file)); in >> permeability_tensor_type_name; - switch(permeability_tensor_type_name[0]) + switch (permeability_tensor_type_name[0]) { - case 'I': // isotropic - permeability_tensor_type = 0; - permeability_model = 1; - in >> permeability_tensor[0]; - //CMCD to pick up 2D and 3D Isotropic case. - permeability_tensor[1] = permeability_tensor[2] = - permeability_tensor[0]; - break; - case 'O': // orthotropic - permeability_tensor_type = 1; - if(geo_dimension == 0) - std::cout << - "Error in CMediumProperties::Read: no geometric dimension" - << "\n"; - if(geo_dimension == 2) - { - in >> permeability_tensor[0]; - in >> permeability_tensor[1]; - } - if(geo_dimension == 3) - { + case 'I': // isotropic + permeability_tensor_type = 0; + permeability_model = 1; in >> permeability_tensor[0]; - in >> permeability_tensor[1]; - in >> permeability_tensor[2]; - } - break; - case 'A': // anisotropic - permeability_tensor_type = 2; - if(geo_dimension == 0) - std::cout << - "Error in CMediumProperties::Read: no geometric dimension" + // CMCD to pick up 2D and 3D Isotropic case. + permeability_tensor[1] = permeability_tensor[2] = permeability_tensor[0]; + break; + case 'O': // orthotropic + permeability_tensor_type = 1; + if (geo_dimension == 0) + std::cout << "Error in CMediumProperties::Read: no geometric dimension" + << "\n"; + if (geo_dimension == 2) + { + in >> permeability_tensor[0]; + in >> permeability_tensor[1]; + } + if (geo_dimension == 3) + { + in >> permeability_tensor[0]; + in >> permeability_tensor[1]; + in >> permeability_tensor[2]; + } + break; + case 'A': // anisotropic + permeability_tensor_type = 2; + if (geo_dimension == 0) + std::cout << "Error in CMediumProperties::Read: no geometric dimension" + << "\n"; + if (geo_dimension == 2) + { + in >> permeability_tensor[0]; + in >> permeability_tensor[1]; + in >> permeability_tensor[2]; + in >> permeability_tensor[3]; + } + if (geo_dimension == 3) + { + in >> permeability_tensor[0]; + in >> permeability_tensor[1]; + in >> permeability_tensor[2]; + in >> permeability_tensor[3]; + in >> permeability_tensor[4]; + in >> permeability_tensor[5]; + in >> permeability_tensor[6]; + in >> permeability_tensor[7]; + in >> permeability_tensor[8]; + } + break; + case 'F': // SB: read from file + permeability_model = 2; // OK + in >> permeability_file; + break; + default: + std::cout << "Error in MMPRead: no valid permeability tensor type" << "\n"; - if(geo_dimension == 2) - { - in >> permeability_tensor[0]; - in >> permeability_tensor[1]; - in >> permeability_tensor[2]; - in >> permeability_tensor[3]; - } - if(geo_dimension == 3) - { - in >> permeability_tensor[0]; - in >> permeability_tensor[1]; - in >> permeability_tensor[2]; - in >> permeability_tensor[3]; - in >> permeability_tensor[4]; - in >> permeability_tensor[5]; - in >> permeability_tensor[6]; - in >> permeability_tensor[7]; - in >> permeability_tensor[8]; - } - break; - case 'F': //SB: read from file - permeability_model = 2; //OK - in >> permeability_file; - break; - default: - std::cout << - "Error in MMPRead: no valid permeability tensor type" << "\n"; - break; + break; } in.clear(); continue; } //------------------------------------------------------------------------ - //12. $PERMEABILITY_FUNCTION + // 12. $PERMEABILITY_FUNCTION // (i) _DEFORMATION // (ii) _PRESSURE // (iii) _SATURATION @@ -934,564 +924,580 @@ std::ios::pos_type CMediumProperties::Read(std::ifstream* mmp_file) // (vi) _POROSITY //------------------------------------------------------------------------ //------------------------------------------------------------------------ - //12.1 PERMEABILITY_FUNCTION_DEFORMATION + // 12.1 PERMEABILITY_FUNCTION_DEFORMATION //------------------------------------------------------------------------ - //subkeyword found - if(line_string.find("$PERMEABILITY_FUNCTION_DEFORMATION") != std::string::npos) + // subkeyword found + if (line_string.find("$PERMEABILITY_FUNCTION_DEFORMATION") != std::string::npos) { in.str(GetLineFromFile1(mmp_file)); in >> permeability_model; - switch(permeability_model) + switch (permeability_model) { - case 0: // k=f(x) - break; - case 1: // k=const - in >> permeability; - break; - default: - std::cout << "Error in MMPRead: no valid permeability model" << - "\n"; - break; + case 0: // k=f(x) + break; + case 1: // k=const + in >> permeability; + break; + default: + std::cout << "Error in MMPRead: no valid permeability model" + << "\n"; + break; } in.clear(); continue; } - //WX: 05.2010 - if(line_string.find("$PERMEABILITY_FUNCTION_STRAIN") != string::npos) + // WX: 05.2010 + if (line_string.find("$PERMEABILITY_FUNCTION_STRAIN") != string::npos) { in.str(GetLineFromFile1(mmp_file)); in >> permeability_strain_model; - switch(permeability_strain_model) + switch (permeability_strain_model) { - case 0: //strain_volume - break; - case 1: //strain_volumeeff plas strain - in >> permeability_strain_model_value[0]; - break; - case 2: //eff plas strainif eff plas strain>0, f(strainp). else stain volume - in >> permeability_strain_model_value[0]; - break; - case 3: //if eff plas strain>0, f(strainp). else stain volume - in >> permeability_strain_model_value[0]; //for strain volume - in >> permeability_strain_model_value[1]; //for eff plas strain - break; - case 4: //strain volume + eff plas strain - in >> permeability_strain_model_value[0]; - in >> permeability_strain_model_value[1]; - break; - case 5: //strain volume (threshold value, can be changed with plas strain) - in >> permeability_strain_model_value[0]; //threshold vol. strain - in >> permeability_strain_model_value[1]; //d_fac/d_volStrain when vol. strain <= threshold - in >> permeability_strain_model_value[2];// d_fac/d_volStrain when vol. strain > threshold - in >> permeability_strain_model_value[3];//curve numer for dependenc between threshold and plas strain - //if -1, threshold is constant - in >> permeability_strain_model_value[4];//lower limit - in >> permeability_strain_model_value[5];//uper limit - default: - cout << "Error in MMPRead: no valid permeability strain model" << - "\n"; - break; + case 0: // strain_volume + break; + case 1: // strain_volumeeff plas strain + in >> permeability_strain_model_value[0]; + break; + case 2: // eff plas strainif eff plas strain>0, f(strainp). else stain volume + in >> permeability_strain_model_value[0]; + break; + case 3: // if eff plas strain>0, f(strainp). else stain volume + in >> permeability_strain_model_value[0]; // for strain volume + in >> permeability_strain_model_value[1]; // for eff plas strain + break; + case 4: // strain volume + eff plas strain + in >> permeability_strain_model_value[0]; + in >> permeability_strain_model_value[1]; + break; + case 5: // strain volume (threshold value, can be changed with plas strain) + in >> permeability_strain_model_value[0]; // threshold vol. strain + in >> permeability_strain_model_value[1]; // d_fac/d_volStrain when vol. strain <= threshold + in >> permeability_strain_model_value[2]; // d_fac/d_volStrain when vol. strain > threshold + in >> permeability_strain_model_value[3]; // curve numer for dependenc between threshold and plas + // strain + // if -1, threshold is constant + in >> permeability_strain_model_value[4]; // lower limit + in >> permeability_strain_model_value[5]; // uper limit + default: + cout << "Error in MMPRead: no valid permeability strain model" + << "\n"; + break; } in.clear(); continue; } //------------------------------------------------------------------------ - //12.2 PERMEABILITY_FUNCTION_PRESSURE + // 12.2 PERMEABILITY_FUNCTION_PRESSURE //------------------------------------------------------------------------ - //subkeyword found - if(line_string.find("$PERMEABILITY_FUNCTION_PRESSURE") != std::string::npos) + // subkeyword found + if (line_string.find("$PERMEABILITY_FUNCTION_PRESSURE") != std::string::npos) { in.str(GetLineFromFile1(mmp_file)); in >> permeability_pressure_model; - switch(permeability_pressure_model) + switch (permeability_pressure_model) { - case 0: // k=f(x) - break; - case 1: // k=const - in >> permeability_pressure_model_values[0]; - pcs_name_vector.push_back("PRESSURE1"); - break; - case 2: // Permebility is a function of effective stress - in >> permeability_pressure_model_values[0]; - in >> permeability_pressure_model_values[1]; - in >> permeability_pressure_model_values[2]; - in >> permeability_pressure_model_values[3]; - pcs_name_vector.push_back("PRESSURE1"); - break; - case 3: // Permeability is a function of non linear flow - in >> permeability_pressure_model_values[0]; - in >> permeability_pressure_model_values[1]; - in >> permeability_pressure_model_values[2]; - in >> permeability_pressure_model_values[3]; - pcs_name_vector.push_back("PRESSURE1"); - break; - case 4: // Function of effective stress from a curve - in >> permeability_pressure_model_values[0]; - in >> permeability_pressure_model_values[1]; - in >> permeability_pressure_model_values[2]; - pcs_name_vector.push_back("PRESSURE1"); - break; - case 5: // Function of overburden converted to effective stress and related to a curve. - in >> permeability_pressure_model_values[0]; - in >> permeability_pressure_model_values[1]; - in >> permeability_pressure_model_values[2]; - pcs_name_vector.push_back("PRESSURE1"); - break; - case 6: // Normal effective stress calculated according to fracture orientation, related over a curve : KTB site - in >> permeability_pressure_model_values[0]; - in >> permeability_pressure_model_values[1]; - in >> permeability_pressure_model_values[2]; - in >> permeability_pressure_model_values[3]; - pcs_name_vector.push_back("PRESSURE1"); - break; - case 7: // Normal effective stress calculated according to fracture orientation, related over a curve : KTB site, and distance to the borehole. - in >> permeability_pressure_model_values[0]; - in >> permeability_pressure_model_values[1]; - in >> permeability_pressure_model_values[2]; - in >> permeability_pressure_model_values[3]; - in >> permeability_pressure_model_values[4]; - in >> permeability_pressure_model_values[5]; - in >> permeability_pressure_model_values[6]; - in >> permeability_pressure_model_values[7]; - in >> permeability_pressure_model_values[8]; - pcs_name_vector.push_back("PRESSURE1"); - break; - case 8: // Effective stress related to depth and curve, Urach - in >> permeability_pressure_model_values[0]; - in >> permeability_pressure_model_values[1]; - pcs_name_vector.push_back("PRESSURE1"); - break; - case 9: // Effective stress related to depth and curve, and to temperature, Urach - in >> permeability_pressure_model_values[0]; - in >> permeability_pressure_model_values[1]; - in >> permeability_pressure_model_values[2]; - in >> permeability_pressure_model_values[3]; - in >> permeability_pressure_model_values[4]; - pcs_name_vector.push_back("PRESSURE1"); - pcs_name_vector.push_back("TEMPERATURE1"); - break; - case 10: //WX:05.2010 directly from curve - in >> permeability_pressure_model_values[0]; //WX: curve number 05.2010 - break; - default: - std::cout << "Error in MMPRead: no valid permeability model" << - "\n"; - break; + case 0: // k=f(x) + break; + case 1: // k=const + in >> permeability_pressure_model_values[0]; + pcs_name_vector.push_back("PRESSURE1"); + break; + case 2: // Permebility is a function of effective stress + in >> permeability_pressure_model_values[0]; + in >> permeability_pressure_model_values[1]; + in >> permeability_pressure_model_values[2]; + in >> permeability_pressure_model_values[3]; + pcs_name_vector.push_back("PRESSURE1"); + break; + case 3: // Permeability is a function of non linear flow + in >> permeability_pressure_model_values[0]; + in >> permeability_pressure_model_values[1]; + in >> permeability_pressure_model_values[2]; + in >> permeability_pressure_model_values[3]; + pcs_name_vector.push_back("PRESSURE1"); + break; + case 4: // Function of effective stress from a curve + in >> permeability_pressure_model_values[0]; + in >> permeability_pressure_model_values[1]; + in >> permeability_pressure_model_values[2]; + pcs_name_vector.push_back("PRESSURE1"); + break; + case 5: // Function of overburden converted to effective stress and related to a curve. + in >> permeability_pressure_model_values[0]; + in >> permeability_pressure_model_values[1]; + in >> permeability_pressure_model_values[2]; + pcs_name_vector.push_back("PRESSURE1"); + break; + case 6: // Normal effective stress calculated according to fracture orientation, related over a curve : + // KTB site + in >> permeability_pressure_model_values[0]; + in >> permeability_pressure_model_values[1]; + in >> permeability_pressure_model_values[2]; + in >> permeability_pressure_model_values[3]; + pcs_name_vector.push_back("PRESSURE1"); + break; + case 7: // Normal effective stress calculated according to fracture orientation, related over a curve : + // KTB site, and distance to the borehole. + in >> permeability_pressure_model_values[0]; + in >> permeability_pressure_model_values[1]; + in >> permeability_pressure_model_values[2]; + in >> permeability_pressure_model_values[3]; + in >> permeability_pressure_model_values[4]; + in >> permeability_pressure_model_values[5]; + in >> permeability_pressure_model_values[6]; + in >> permeability_pressure_model_values[7]; + in >> permeability_pressure_model_values[8]; + pcs_name_vector.push_back("PRESSURE1"); + break; + case 8: // Effective stress related to depth and curve, Urach + in >> permeability_pressure_model_values[0]; + in >> permeability_pressure_model_values[1]; + pcs_name_vector.push_back("PRESSURE1"); + break; + case 9: // Effective stress related to depth and curve, and to temperature, Urach + in >> permeability_pressure_model_values[0]; + in >> permeability_pressure_model_values[1]; + in >> permeability_pressure_model_values[2]; + in >> permeability_pressure_model_values[3]; + in >> permeability_pressure_model_values[4]; + pcs_name_vector.push_back("PRESSURE1"); + pcs_name_vector.push_back("TEMPERATURE1"); + break; + case 10: // WX:05.2010 directly from curve + in >> permeability_pressure_model_values[0]; // WX: curve number 05.2010 + break; + default: + std::cout << "Error in MMPRead: no valid permeability model" + << "\n"; + break; } in.clear(); continue; } //------------------------------------------------------------------------ - //12.3 PERMEABILITY_FUNCTION_SATURATION + // 12.3 PERMEABILITY_FUNCTION_SATURATION //------------------------------------------------------------------------ - if(line_string.find("$PERMEABILITY_SATURATION") != std::string::npos) + if (line_string.find("$PERMEABILITY_SATURATION") != std::string::npos) { int num_phases = 0; - if(H3_Process) - num_phases = 3; // the existence of additional fluids in the .mfp file is not an indicator of a 4-phase system. - else if(H2_Process) - num_phases = 2; // the existence of additional fluids in the .mfp file is not an indicator of a 3-phase system. - else if(H_Process) + if (H3_Process) + num_phases + = 3; // the existence of additional fluids in the .mfp file is not an indicator of a 4-phase system. + else if (H2_Process) + num_phases + = 2; // the existence of additional fluids in the .mfp file is not an indicator of a 3-phase system. + else if (H_Process) num_phases = 1; // - for(k = 0; k < num_phases; k++) + for (k = 0; k < num_phases; k++) { in.str(GetLineFromFile1(mmp_file)); in >> permeability_saturation_model[k]; // - switch(permeability_saturation_model[k]) + switch (permeability_saturation_model[k]) { - case 0: // Curve of [Sw,k_rel] - in >> perm_saturation_value[k]; // curve number - break; - // - case 1: // Constant - in >> perm_saturation_value[k]; // constant value of k_rel - break; - // - case 2: // krg = 1.0 - krl (only for gas phase) - if(k==0){ - ScreenMessage("ERROR in MMPRead: Relative permeability model 2 is only valid for the gas phase.\n"); - exit(0); - } - in >> minimum_relative_permeability; - break; - // - case 3: // JT: Function (power or linear) WETTING - // krw = (m*Se)^exp - // Se = (sl - slr) / (slm - slr) - in >> residual_saturation[k]; // slr: residual saturation, this phase - in >> maximum_saturation[k]; // slm: maximum saturation, this phase - in >> saturation_exponent[k]; // (set exponent = 1 results in a linear k_rel function) - in >> perm_saturation_value[k]; // multiplier "m" - in >> minimum_relative_permeability; // minimum relative permeability this phase - break; - // - case 33: // JT: Function (power or linear) NON-WETTING - // krg = (m*(1-Se))^exp - // Se = (sl - slr) / (slm - slr) --> slr = 1 - sgm --> slm = 1 - sgr - in >> residual_saturation[k]; // sgr: residual saturation, this phase - in >> maximum_saturation[k]; // sgm: maximum saturation, this phase - in >> saturation_exponent[k]; // (set exponent = 1 results in a linear k_rel function) - in >> perm_saturation_value[k]; // multiplier "m" - in >> minimum_relative_permeability; // minimum relative permeability this phase - break; - // - case 4: // 2-phase Van Genuchten/Mualem Model WETTING - // krw = pow(se,0.5) * pow(1.0-pow(1.0-pow(se,1.0/m),m),2) - // Se = (sl - slr) / (slm - slr) - in >> residual_saturation[k]; // slr: residual saturation, this phase - in >> maximum_saturation[k]; // slm: maximum saturation, this phase - in >> saturation_exponent[k]; // exponent (always <= 1.0) --> (typical is 0.5) i.e. n = 1 / (1 - exponent) == 2.0 - in >> minimum_relative_permeability; // minimum relative permeability this phase - break; - // - case 44: // 2-phase Van Genuchten/Mualem Model NON-WETTING - // krg = pow(1.0-se,1.0/3.0) * pow(1.0-pow(se,1.0/m),2.0*m) - // Se = (sl - slr) / (slm - slr) --> slr = 1 - sgm --> slm = 1 - sgr - in >> residual_saturation[k]; // sgr: residual saturation, this phase - in >> maximum_saturation[k]; // sgm: maximum saturation, this phase - in >> saturation_exponent[k]; // exponent (always <= 1.0) --> (typical is 0.5) i.e. n = 1 / (1 - exponent) == 2.0 - in >> minimum_relative_permeability; // minimum relative permeability this phase - break; - // - case 6: // Brooks/Corey WETTING - // krw = pow(se,3.0+2.0/m) - // Se = (sl - slr) / (slm - slr) - in >> residual_saturation[k]; // slr: residual saturation, this phase - in >> maximum_saturation[k]; // slm: maximum saturation, this phase - in >> saturation_exponent[k]; // exponent (always >= 1.0) (typical might be 2.0) - in >> minimum_relative_permeability; // minimum relative permeability this phase - break; - // - case 10: // unconfined GW 6/2012 JOD - break; - case 61: //Brooks-Corey CB modified Seff - in >> residual_saturation[k]; // sgr: residual saturation, this phase - in >> maximum_saturation[k]; // sgm: maximum saturation, this phase - in >> saturation_exponent[k]; // exponent (always >= 1.0) (typical might be 2.0) - break; - case 66: // Brooks/Corey NON-WETTING - // krg = pow(1.0-se,2)*(1.0-pow(se,1.0+2.0/m)) - // Se = (sl - slr) / (slm - slr) --> slr = 1 - sgm --> slm = 1 - sgr - in >> residual_saturation[k]; // sgr: residual saturation, this phase - in >> maximum_saturation[k]; // sgm: maximum saturation, this phase - in >> saturation_exponent[k]; // exponent (always >= 1.0) (typical might be 2.0) - in >> minimum_relative_permeability; // minimum relative permeability this phase - break; - // - case 7: // Corey's curves WETTING - // krw = pow(se,4) - // Se = (sl - slr) / (slm - slr) - in >> residual_saturation[k]; // slr: residual saturation, this phase - in >> maximum_saturation[k]; // slm: maximum saturation, this phase - in >> saturation_exponent[k]; // exponent (always >= 1.0) - in >> minimum_relative_permeability; // minimum relative permeability this phase - break; - // - case 77: // Corey's curves NON-WETTING - // krg = pow((1.0-se),2)*(1.0-pow(se,2)) - // Se = (sl - slr) / (slm - slr) --> slr = 1 - sgmax --> slm = 1 - sgr - in >> residual_saturation[k]; // sgr: residual saturation, this phase - in >> maximum_saturation[k]; // sgm: maximum saturation, this phase - in >> saturation_exponent[k]; // exponent (always >= 1.0) - in >> minimum_relative_permeability; // minimum relative permeability this phase - break; - // - default: - ScreenMessage("Error in MMPRead: no valid permeability saturation model.\n"); - break; + case 0: // Curve of [Sw,k_rel] + in >> perm_saturation_value[k]; // curve number + break; + // + case 1: // Constant + in >> perm_saturation_value[k]; // constant value of k_rel + break; + // + case 2: // krg = 1.0 - krl (only for gas phase) + if (k == 0) + { + ScreenMessage( + "ERROR in MMPRead: Relative permeability model 2 is only valid for the gas phase.\n"); + exit(0); + } + in >> minimum_relative_permeability; + break; + // + case 3: // JT: Function (power or linear) WETTING + // krw = (m*Se)^exp + // Se = (sl - slr) / (slm - slr) + in >> residual_saturation[k]; // slr: residual saturation, this phase + in >> maximum_saturation[k]; // slm: maximum saturation, this phase + in >> saturation_exponent[k]; // (set exponent = 1 results in a linear k_rel function) + in >> perm_saturation_value[k]; // multiplier "m" + in >> minimum_relative_permeability; // minimum relative permeability this phase + break; + // + case 33: // JT: Function (power or linear) NON-WETTING + // krg = (m*(1-Se))^exp + // Se = (sl - slr) / (slm - slr) --> slr = 1 - sgm --> slm = 1 - sgr + in >> residual_saturation[k]; // sgr: residual saturation, this phase + in >> maximum_saturation[k]; // sgm: maximum saturation, this phase + in >> saturation_exponent[k]; // (set exponent = 1 results in a linear k_rel function) + in >> perm_saturation_value[k]; // multiplier "m" + in >> minimum_relative_permeability; // minimum relative permeability this phase + break; + // + case 4: // 2-phase Van Genuchten/Mualem Model WETTING + // krw = pow(se,0.5) * pow(1.0-pow(1.0-pow(se,1.0/m),m),2) + // Se = (sl - slr) / (slm - slr) + in >> residual_saturation[k]; // slr: residual saturation, this phase + in >> maximum_saturation[k]; // slm: maximum saturation, this phase + in >> saturation_exponent[k]; // exponent (always <= 1.0) --> (typical is 0.5) i.e. n = 1 / (1 - + // exponent) == 2.0 + in >> minimum_relative_permeability; // minimum relative permeability this phase + break; + // + case 44: // 2-phase Van Genuchten/Mualem Model NON-WETTING + // krg = pow(1.0-se,1.0/3.0) * pow(1.0-pow(se,1.0/m),2.0*m) + // Se = (sl - slr) / (slm - slr) --> slr = 1 - sgm --> slm = 1 - sgr + in >> residual_saturation[k]; // sgr: residual saturation, this phase + in >> maximum_saturation[k]; // sgm: maximum saturation, this phase + in >> saturation_exponent[k]; // exponent (always <= 1.0) --> (typical is 0.5) i.e. n = 1 / (1 - + // exponent) == 2.0 + in >> minimum_relative_permeability; // minimum relative permeability this phase + break; + // + case 6: // Brooks/Corey WETTING + // krw = pow(se,3.0+2.0/m) + // Se = (sl - slr) / (slm - slr) + in >> residual_saturation[k]; // slr: residual saturation, this phase + in >> maximum_saturation[k]; // slm: maximum saturation, this phase + in >> saturation_exponent[k]; // exponent (always >= 1.0) (typical might be 2.0) + in >> minimum_relative_permeability; // minimum relative permeability this phase + break; + // + case 10: // unconfined GW 6/2012 JOD + break; + case 61: // Brooks-Corey CB modified Seff + in >> residual_saturation[k]; // sgr: residual saturation, this phase + in >> maximum_saturation[k]; // sgm: maximum saturation, this phase + in >> saturation_exponent[k]; // exponent (always >= 1.0) (typical might be 2.0) + break; + case 66: // Brooks/Corey NON-WETTING + // krg = pow(1.0-se,2)*(1.0-pow(se,1.0+2.0/m)) + // Se = (sl - slr) / (slm - slr) --> slr = 1 - sgm --> slm = 1 - sgr + in >> residual_saturation[k]; // sgr: residual saturation, this phase + in >> maximum_saturation[k]; // sgm: maximum saturation, this phase + in >> saturation_exponent[k]; // exponent (always >= 1.0) (typical might be 2.0) + in >> minimum_relative_permeability; // minimum relative permeability this phase + break; + // + case 7: // Corey's curves WETTING + // krw = pow(se,4) + // Se = (sl - slr) / (slm - slr) + in >> residual_saturation[k]; // slr: residual saturation, this phase + in >> maximum_saturation[k]; // slm: maximum saturation, this phase + in >> saturation_exponent[k]; // exponent (always >= 1.0) + in >> minimum_relative_permeability; // minimum relative permeability this phase + break; + // + case 77: // Corey's curves NON-WETTING + // krg = pow((1.0-se),2)*(1.0-pow(se,2)) + // Se = (sl - slr) / (slm - slr) --> slr = 1 - sgmax --> slm = 1 - sgr + in >> residual_saturation[k]; // sgr: residual saturation, this phase + in >> maximum_saturation[k]; // sgm: maximum saturation, this phase + in >> saturation_exponent[k]; // exponent (always >= 1.0) + in >> minimum_relative_permeability; // minimum relative permeability this phase + break; + // + default: + ScreenMessage("Error in MMPRead: no valid permeability saturation model.\n"); + break; } in.clear(); } continue; } //------------------------------------------------------------------------ - //12.4 PERMEABILITY_FUNCTION_STRESS + // 12.4 PERMEABILITY_FUNCTION_STRESS //------------------------------------------------------------------------ - //subkeyword found - if(line_string.find("$PERMEABILITY_FUNCTION_STRESS") != std::string::npos) + // subkeyword found + if (line_string.find("$PERMEABILITY_FUNCTION_STRESS") != std::string::npos) { in.str(GetLineFromFile1(mmp_file)); in >> permeability_stress_mode; - switch(permeability_stress_mode) + switch (permeability_stress_mode) { - case 0: // k=f(x) - break; - case 1: // k=const - in >> permeability; - break; - case 2: // Modified LBNL model. WW - c_coefficient = new double [18]; - in >> c_coefficient[0] // b_0 - >> c_coefficient[1] // alpha - >> c_coefficient[2] // br_1 - >> c_coefficient[3] // br_2 - >> c_coefficient[4] // br_3 - >> c_coefficient[5] >> ws; // fracture frequency - for(i = 6; i < 18; i++) - c_coefficient[i] = 0.0; - for(i = 0; i < 3; i++) - { - in.clear(); - in.str(GetLineFromFile1(mmp_file)); - in >> m_string; - if(m_string.find("_XX") != string::npos) - k = 0; - else if(m_string.find("_YY") != string::npos) - k = 1; - else if(m_string.find("_ZZ") != string::npos) - k = 2; - m_string.clear(); - in >> m_string; - pch = strtok (const_cast (m_string.c_str()),seps); - buff << pch; - buff >> c_coefficient[6 + k * 4]; - buff.clear(); - while (pch != NULL) - { - pch = strtok (NULL, seps); - if(pch == NULL) - break; - string token = pch; - tokens.push_back(token); - } - for(j = 0; j < (int)tokens.size(); j++) + case 0: // k=f(x) + break; + case 1: // k=const + in >> permeability; + break; + case 2: // Modified LBNL model. WW + c_coefficient = new double[18]; + in >> c_coefficient[0] // b_0 + >> c_coefficient[1] // alpha + >> c_coefficient[2] // br_1 + >> c_coefficient[3] // br_2 + >> c_coefficient[4] // br_3 + >> c_coefficient[5] >> ws; // fracture frequency + for (i = 6; i < 18; i++) + c_coefficient[i] = 0.0; + for (i = 0; i < 3; i++) { - pch = strtok ( - const_cast (tokens[j].c_str()),seps1); + in.clear(); + in.str(GetLineFromFile1(mmp_file)); + in >> m_string; + if (m_string.find("_XX") != string::npos) + k = 0; + else if (m_string.find("_YY") != string::npos) + k = 1; + else if (m_string.find("_ZZ") != string::npos) + k = 2; + m_string.clear(); + in >> m_string; + pch = strtok(const_cast(m_string.c_str()), seps); buff << pch; - buff >> f_buff; + buff >> c_coefficient[6 + k * 4]; buff.clear(); - pch = strtok (NULL,seps1); - switch(pch[0]) + while (pch != NULL) { - case 'x': c_coefficient[k * 4 + 7] = f_buff; - break; - case 'y': c_coefficient[k * 4 + 8] = f_buff; - break; - case 'z': c_coefficient[k * 4 + 9] = f_buff; - break; + pch = strtok(NULL, seps); + if (pch == NULL) + break; + string token = pch; + tokens.push_back(token); } + for (j = 0; j < (int)tokens.size(); j++) + { + pch = strtok(const_cast(tokens[j].c_str()), seps1); + buff << pch; + buff >> f_buff; + buff.clear(); + pch = strtok(NULL, seps1); + switch (pch[0]) + { + case 'x': + c_coefficient[k * 4 + 7] = f_buff; + break; + case 'y': + c_coefficient[k * 4 + 8] = f_buff; + break; + case 'z': + c_coefficient[k * 4 + 9] = f_buff; + break; + } + } + tokens.clear(); } - tokens.clear(); - } - break; - case 3: // Barton-Bandis WW - c_coefficient = new double [24]; - in >> c_coefficient[0] // JRC - >> c_coefficient[1] // JCS //an0 - >> c_coefficient[2] // UCS //Kn - >> c_coefficient[7] // sig_h - >> c_coefficient[8] >> ws; // sig_H - for(i = 3; i < 7; i++) - c_coefficient[i] = 0.0; - for(i = 9; i < 24; i++) - c_coefficient[i] = 0.0; - for(i = 0; i < 3; i++) - { - in.clear(); - in.str(GetLineFromFile1(mmp_file)); - in >> m_string; - if(m_string.find("_XX") != string::npos) - k = 0; - else if(m_string.find("_YY") != string::npos) - k = 1; - else if(m_string.find("_ZZ") != string::npos) - k = 2; - m_string.clear(); - in >> m_string; - pch = strtok (const_cast (m_string.c_str()),seps); - buff << pch; - buff >> c_coefficient[9 + k * 4]; - buff.clear(); - while (pch != NULL) - { - pch = strtok (NULL, seps); - if(pch == NULL) - break; - string token = pch; - tokens.push_back(token); - } - for(j = 0; j < (int)tokens.size(); j++) + break; + case 3: // Barton-Bandis WW + c_coefficient = new double[24]; + in >> c_coefficient[0] // JRC + >> c_coefficient[1] // JCS //an0 + >> c_coefficient[2] // UCS //Kn + >> c_coefficient[7] // sig_h + >> c_coefficient[8] >> ws; // sig_H + for (i = 3; i < 7; i++) + c_coefficient[i] = 0.0; + for (i = 9; i < 24; i++) + c_coefficient[i] = 0.0; + for (i = 0; i < 3; i++) { - pch = strtok ( - const_cast (tokens[j].c_str()),seps1); + in.clear(); + in.str(GetLineFromFile1(mmp_file)); + in >> m_string; + if (m_string.find("_XX") != string::npos) + k = 0; + else if (m_string.find("_YY") != string::npos) + k = 1; + else if (m_string.find("_ZZ") != string::npos) + k = 2; + m_string.clear(); + in >> m_string; + pch = strtok(const_cast(m_string.c_str()), seps); buff << pch; - buff >> f_buff; + buff >> c_coefficient[9 + k * 4]; buff.clear(); - pch = strtok (NULL,seps1); - switch(pch[0]) + while (pch != NULL) { - case 'x': c_coefficient[k * 4 + 10] = f_buff; - break; - case 'y': c_coefficient[k * 4 + 11] = f_buff; - break; - case 'z': c_coefficient[k * 4 + 12] = f_buff; - break; + pch = strtok(NULL, seps); + if (pch == NULL) + break; + string token = pch; + tokens.push_back(token); } + for (j = 0; j < (int)tokens.size(); j++) + { + pch = strtok(const_cast(tokens[j].c_str()), seps1); + buff << pch; + buff >> f_buff; + buff.clear(); + pch = strtok(NULL, seps1); + switch (pch[0]) + { + case 'x': + c_coefficient[k * 4 + 10] = f_buff; + break; + case 'y': + c_coefficient[k * 4 + 11] = f_buff; + break; + case 'z': + c_coefficient[k * 4 + 12] = f_buff; + break; + } + } + tokens.clear(); } - tokens.clear(); - } - // - CalStressPermeabilityFactor3_Coef(); - // - break; + // + CalStressPermeabilityFactor3_Coef(); + // + break; - default: - std::cout << "Error in MMPRead: no valid permeability model" << - "\n"; - break; + default: + std::cout << "Error in MMPRead: no valid permeability model" + << "\n"; + break; } in.clear(); continue; } - //AS,WX:08.2012 - if(line_string.find("$PERMEABILITY_FUNCTION_EFFSTRESS")!=std::string::npos) + // AS,WX:08.2012 + if (line_string.find("$PERMEABILITY_FUNCTION_EFFSTRESS") != std::string::npos) { in.str(GetLineFromFile1(mmp_file)); in >> permeability_effstress_model; - switch(permeability_effstress_model) + switch (permeability_effstress_model) { - case 1: - in >> permeability_effstress_model_value[0]; - break; - default: - cout<< "Error in MMPRead: no valid permeability stress model" << "\n"; - break; + case 1: + in >> permeability_effstress_model_value[0]; + break; + default: + cout << "Error in MMPRead: no valid permeability stress model" + << "\n"; + break; } in.clear(); continue; } //------------------------------------------------------------------------ - //12.5 PERMEABILITY_FUNCTION_VELOCITY + // 12.5 PERMEABILITY_FUNCTION_VELOCITY //------------------------------------------------------------------------ - //WW - if(line_string.find("$PERMEABILITY_FUNCTION_VELOCITY") != std::string::npos) + // WW + if (line_string.find("$PERMEABILITY_FUNCTION_VELOCITY") != std::string::npos) { - //WW if(line_string.find("$PERMEABILITY_FUNCTION_STRESS")!=string::npos) { //subkeyword found + // WW if(line_string.find("$PERMEABILITY_FUNCTION_STRESS")!=string::npos) { //subkeyword found in.str(GetLineFromFile1(mmp_file)); in >> permeability_model; - switch(permeability_model) + switch (permeability_model) { - case 0: // k=f(x) - break; - case 1: // k=const - in >> permeability; - break; - default: - std::cout << "Error in MMPRead: no valid permeability model" << - "\n"; - break; + case 0: // k=f(x) + break; + case 1: // k=const + in >> permeability; + break; + default: + std::cout << "Error in MMPRead: no valid permeability model" + << "\n"; + break; } in.clear(); continue; } //------------------------------------------------------------------------ - //12.6 PERMEABILITY_FUNCTION_POROSITY + // 12.6 PERMEABILITY_FUNCTION_POROSITY //------------------------------------------------------------------------ - //subkeyword found - if(line_string.find("$PERMEABILITY_FUNCTION_POROSITY") != std::string::npos) + // subkeyword found + if (line_string.find("$PERMEABILITY_FUNCTION_POROSITY") != std::string::npos) { in.str(GetLineFromFile1(mmp_file)); in >> permeability_porosity_model; - switch(permeability_porosity_model) + switch (permeability_porosity_model) { - case 0: // k=f(x) - break; - case 1: // k=const - in >> permeability_porosity_model_values[0]; - mmp_file->ignore(MAX_ZEILE,'\n'); - break; - case 2: // Model from Ming Lian - in >> permeability_porosity_model_values[0]; - in >> permeability_porosity_model_values[1]; - break; - case 3: // HS: 11.2008, Kozeny-Carman relationship - // we set the tensor type first to isotropic and constant as initial value - permeability_tensor_type = 0; - permeability_model = 3; // this means permeability depends on K-C relationship - // initial values - in >> permeability_porosity_model_values[0]; // initial porosity - in >> permeability_porosity_model_values[1]; // initial permeability - KC_permeability_initial = permeability_porosity_model_values[1]; - KC_porosity_initial =permeability_porosity_model_values[0]; - + case 0: // k=f(x) + break; + case 1: // k=const + in >> permeability_porosity_model_values[0]; + mmp_file->ignore(MAX_ZEILE, '\n'); + break; + case 2: // Model from Ming Lian + in >> permeability_porosity_model_values[0]; + in >> permeability_porosity_model_values[1]; + break; + case 3: // HS: 11.2008, Kozeny-Carman relationship + // we set the tensor type first to isotropic and constant as initial value + permeability_tensor_type = 0; + permeability_model = 3; // this means permeability depends on K-C relationship + // initial values + in >> permeability_porosity_model_values[0]; // initial porosity + in >> permeability_porosity_model_values[1]; // initial permeability + KC_permeability_initial = permeability_porosity_model_values[1]; + KC_porosity_initial = permeability_porosity_model_values[0]; - break; - case 4: // HS: 11.2008, Kozeny-Carman_normalized relationship - // we set the tensor type first to isotropic and constant as initial value - permeability_tensor_type = 0; - permeability_model = 4; // this means permeability depends on K-C_normalized relationship - // initial values - in >> permeability_porosity_model_values[0]; // initial porosity - in >> permeability_porosity_model_values[1]; //initial permeab ility - KC_permeability_initial = permeability_porosity_model_values[1]; - KC_porosity_initial =permeability_porosity_model_values[0]; - break; - case 5: // HS: 01.2010, Clement 1996 model - // M. Thullner et al. 2004, J Contaminant Hydrology 70: 37-62, pp42 - permeability_tensor_type = 0; - permeability_model = 5; // Clement original model - // this is initial porosity - in >> permeability_porosity_model_values[0]; - // this is initial permeability - in >> permeability_porosity_model_values[1]; - break; - case 6: // HS: 01.2010, ,modified Clement, biomass colonies clogging - // M. Thullner et al. 2004, J Contaminant Hydrology 70: 37-62, pp42 - permeability_tensor_type = 0; - permeability_model = 6; // modified Clement, biomass growing in colonies - // this is initial porosity - in >> permeability_porosity_model_values[0]; - // this is initial permeability - in >> permeability_porosity_model_values[1]; - // this is parameter a - in >> permeability_porosity_model_values[2]; - break; - case 7: // HS: 01.2010, ,modified Clement, biofilm clogging - // M. Thullner et al. 2004, J Contaminant Hydrology 70: 37-62, pp42 - permeability_tensor_type = 0; - permeability_model = 7; // modified Clement, biomass growing in biofilm - // this is initial porosity - in >> permeability_porosity_model_values[0]; - // this is initial permeability - in >> permeability_porosity_model_values[1]; - // this is parameter b - in >> permeability_porosity_model_values[2]; - // this is prarameter k_fmin - in >> permeability_porosity_model_values[3]; - break; - case 8:// AB: 2010, Updating permeability due to change in porosity - // Inital permeability provided in $PERMEABILITY_TENSOR will be read for initial condition - permeability_model = 8; - in >> permeability_porosity_updating_type_name; - switch(permeability_porosity_updating_type_name[0]) { - case 'K': // Kozeny-Carman formulation - permeability_porosity_updating_type = 0; - break; - case 'V': // Verma-Pruess formulation - permeability_porosity_updating_type = 1; - in >> permeability_porosity_updating_values[0]; // critical porosity - in >> permeability_porosity_updating_values[1]; // n: a power law exponent - break; - } - if(this->permeability_tensor_type==2) - std::cout << "Warning in MMPRead: permeability_model 8 is not implemented for permeability_tensor_type 2" << "\n"; - break; - default: - std::cout << "Error in MMPRead: no valid permeability model" << - "\n"; - break; + break; + case 4: // HS: 11.2008, Kozeny-Carman_normalized relationship + // we set the tensor type first to isotropic and constant as initial value + permeability_tensor_type = 0; + permeability_model = 4; // this means permeability depends on K-C_normalized relationship + // initial values + in >> permeability_porosity_model_values[0]; // initial porosity + in >> permeability_porosity_model_values[1]; // initial permeab ility + KC_permeability_initial = permeability_porosity_model_values[1]; + KC_porosity_initial = permeability_porosity_model_values[0]; + break; + case 5: // HS: 01.2010, Clement 1996 model + // M. Thullner et al. 2004, J Contaminant Hydrology 70: 37-62, pp42 + permeability_tensor_type = 0; + permeability_model = 5; // Clement original model + // this is initial porosity + in >> permeability_porosity_model_values[0]; + // this is initial permeability + in >> permeability_porosity_model_values[1]; + break; + case 6: // HS: 01.2010, ,modified Clement, biomass colonies clogging + // M. Thullner et al. 2004, J Contaminant Hydrology 70: 37-62, pp42 + permeability_tensor_type = 0; + permeability_model = 6; // modified Clement, biomass growing in colonies + // this is initial porosity + in >> permeability_porosity_model_values[0]; + // this is initial permeability + in >> permeability_porosity_model_values[1]; + // this is parameter a + in >> permeability_porosity_model_values[2]; + break; + case 7: // HS: 01.2010, ,modified Clement, biofilm clogging + // M. Thullner et al. 2004, J Contaminant Hydrology 70: 37-62, pp42 + permeability_tensor_type = 0; + permeability_model = 7; // modified Clement, biomass growing in biofilm + // this is initial porosity + in >> permeability_porosity_model_values[0]; + // this is initial permeability + in >> permeability_porosity_model_values[1]; + // this is parameter b + in >> permeability_porosity_model_values[2]; + // this is prarameter k_fmin + in >> permeability_porosity_model_values[3]; + break; + case 8: // AB: 2010, Updating permeability due to change in porosity + // Inital permeability provided in $PERMEABILITY_TENSOR will be read for initial condition + permeability_model = 8; + in >> permeability_porosity_updating_type_name; + switch (permeability_porosity_updating_type_name[0]) + { + case 'K': // Kozeny-Carman formulation + permeability_porosity_updating_type = 0; + break; + case 'V': // Verma-Pruess formulation + permeability_porosity_updating_type = 1; + in >> permeability_porosity_updating_values[0]; // critical porosity + in >> permeability_porosity_updating_values[1]; // n: a power law exponent + break; + } + if (this->permeability_tensor_type == 2) + std::cout << "Warning in MMPRead: permeability_model 8 is not implemented for " + "permeability_tensor_type 2" + << "\n"; + break; + default: + std::cout << "Error in MMPRead: no valid permeability model" + << "\n"; + break; } in.clear(); continue; } //.................................................................... - //subkeyword found - if(line_string.find("$CAPILLARY_PRESSURE") != std::string::npos) + // subkeyword found + if (line_string.find("$CAPILLARY_PRESSURE") != std::string::npos) { in.str(GetLineFromFile1(mmp_file)); in >> capillary_pressure_model; @@ -1500,87 +1506,105 @@ std::ios::pos_type CMediumProperties::Read(std::ifstream* mmp_file) capillary_pressure_values[2] = -1.0; bool old_format = false; // - switch(capillary_pressure_model) + switch (capillary_pressure_model) { - case 0: // k=f(Se) - in >> capillary_pressure_values[0]; // curve - in >> capillary_pressure_values[1]; // Slr - in >> capillary_pressure_values[2]; // Slmax - // - // JT: Check for old version format. - if(capillary_pressure_values[2] < 0.0){ - capillary_pressure_values[1] = residual_saturation[0]; // old version uses relative permeabilty values for this - capillary_pressure_values[2] = maximum_saturation[0]; // old version uses relative permeabilty values for this - old_format = true; - } - break; - case 1: // const - in >> capillary_pressure_values[0]; // the constant Pc value - // - // This next value is NOT REQUIRED. It is here because in the old version this entry was used to represent - // a constant value of saturation in PP models. SHOULD DELETE THIS CHECK EVENTUALLY! - in >> capillary_pressure_values[2]; - if(capillary_pressure_values[2] >= 0.0){ // Then a constant saturation value has been entered. This is model #2. - ScreenMessage("WARNING in MMPRead. Capillary pressure model 1 used for a constant saturation. THIS IS NOW MODEL #2. PLEASE SWITCH TO MODEL #2.\n"); - capillary_pressure_model = 2; - capillary_pressure_values[0] = capillary_pressure_values[2]; - } - // - // Assign bounds - capillary_pressure_values[1] = 0.0; // Slr - capillary_pressure_values[2] = 1.0; // Slmax - break; - case 2: // Constant saturation for pp models (for WX, from JT) - in >> capillary_pressure_values[0]; // The fixed saturation - // Assign bounds - capillary_pressure_values[1] = 0.0; // Slr - capillary_pressure_values[2] = 1.0; // Slmax - break; - case 4: // van Genuchten - in >> capillary_pressure_values[0]; // Pb (or "alpha" if [alpha_switch>0]) - in >> capillary_pressure_values[1]; // Slr - in >> capillary_pressure_values[2]; // Slmax - in >> capillary_pressure_values[3]; // exponent (always <= 1.0) --> (typical is 0.5) i.e. n = 1 / (1 - exponent) == 2.0 - in >> capillary_pressure_values[4]; // maximum Pc - in >> i; // alpha_switch (default = 0) - if(i>0) entry_pressure_conversion = true; - // - // JT: Check for old version format. - if(capillary_pressure_values[2] < 0.0){ - entry_pressure_conversion = true; // entry is alpha in old version - capillary_pressure_values[1] = residual_saturation[0]; // old version uses relative permeabilty values for this - capillary_pressure_values[2] = maximum_saturation[0]; // old version uses relative permeabilty values for this - capillary_pressure_values[3] = saturation_exponent[0]; // old version uses relative permeabilty values for this - capillary_pressure_values[4] = 1.0e10; - old_format = true; - } - break; - case 6: // Brook & Corey. 2.05.2008. WW - in >> capillary_pressure_values[0]; // Pb - in >> capillary_pressure_values[1]; // Slr - in >> capillary_pressure_values[2]; // Slmax - in >> capillary_pressure_values[3]; // exponent (always >= 1.0) (typical might be 2.0) - in >> capillary_pressure_values[4]; // maximum Pc - // - // JT: Check for old version format. - if(capillary_pressure_values[2] < 0.0){ - capillary_pressure_values[1] = residual_saturation[0]; // old version uses relative permeabilty values for this - capillary_pressure_values[2] = maximum_saturation[0]; // old version uses relative permeabilty values for this - capillary_pressure_values[3] = saturation_exponent[0]; // old version uses relative permeabilty values for this - capillary_pressure_values[4] = 1.0e10; - old_format = true; - } - break; - case 10: // unconfined 3D GW. 5.3.07 JOD - in >> capillary_pressure_values[1]; // Slr - in >> capillary_pressure_values[0]; // Pb - break; - default: - ScreenMessage("Error in MMPRead: no valid capillary pressure model.\n"); - exit(1); - break; + case 0: // k=f(Se) + in >> capillary_pressure_values[0]; // curve + in >> capillary_pressure_values[1]; // Slr + in >> capillary_pressure_values[2]; // Slmax + // + // JT: Check for old version format. + if (capillary_pressure_values[2] < 0.0) + { + capillary_pressure_values[1] + = residual_saturation[0]; // old version uses relative permeabilty values for this + capillary_pressure_values[2] + = maximum_saturation[0]; // old version uses relative permeabilty values for this + old_format = true; + } + break; + case 1: // const + in >> capillary_pressure_values[0]; // the constant Pc value + // + // This next value is NOT REQUIRED. It is here because in the old version this entry was used to + // represent + // a constant value of saturation in PP models. SHOULD DELETE THIS CHECK EVENTUALLY! + in >> capillary_pressure_values[2]; + if (capillary_pressure_values[2] >= 0.0) + { // Then a constant saturation value has been entered. This is model #2. + ScreenMessage( + "WARNING in MMPRead. Capillary pressure model 1 used for a constant saturation. THIS IS " + "NOW MODEL #2. PLEASE SWITCH TO MODEL #2.\n"); + capillary_pressure_model = 2; + capillary_pressure_values[0] = capillary_pressure_values[2]; + } + // + // Assign bounds + capillary_pressure_values[1] = 0.0; // Slr + capillary_pressure_values[2] = 1.0; // Slmax + break; + case 2: // Constant saturation for pp models (for WX, from JT) + in >> capillary_pressure_values[0]; // The fixed saturation + // Assign bounds + capillary_pressure_values[1] = 0.0; // Slr + capillary_pressure_values[2] = 1.0; // Slmax + break; + case 4: // van Genuchten + in >> capillary_pressure_values[0]; // Pb (or "alpha" if [alpha_switch>0]) + in >> capillary_pressure_values[1]; // Slr + in >> capillary_pressure_values[2]; // Slmax + in >> capillary_pressure_values[3]; // exponent (always <= 1.0) --> (typical is 0.5) i.e. n = 1 / (1 + // - exponent) == 2.0 + in >> capillary_pressure_values[4]; // maximum Pc + in >> i; // alpha_switch (default = 0) + if (i > 0) + entry_pressure_conversion = true; + // + // JT: Check for old version format. + if (capillary_pressure_values[2] < 0.0) + { + entry_pressure_conversion = true; // entry is alpha in old version + capillary_pressure_values[1] + = residual_saturation[0]; // old version uses relative permeabilty values for this + capillary_pressure_values[2] + = maximum_saturation[0]; // old version uses relative permeabilty values for this + capillary_pressure_values[3] + = saturation_exponent[0]; // old version uses relative permeabilty values for this + capillary_pressure_values[4] = 1.0e10; + old_format = true; + } + break; + case 6: // Brook & Corey. 2.05.2008. WW + in >> capillary_pressure_values[0]; // Pb + in >> capillary_pressure_values[1]; // Slr + in >> capillary_pressure_values[2]; // Slmax + in >> capillary_pressure_values[3]; // exponent (always >= 1.0) (typical might be 2.0) + in >> capillary_pressure_values[4]; // maximum Pc + // + // JT: Check for old version format. + if (capillary_pressure_values[2] < 0.0) + { + capillary_pressure_values[1] + = residual_saturation[0]; // old version uses relative permeabilty values for this + capillary_pressure_values[2] + = maximum_saturation[0]; // old version uses relative permeabilty values for this + capillary_pressure_values[3] + = saturation_exponent[0]; // old version uses relative permeabilty values for this + capillary_pressure_values[4] = 1.0e10; + old_format = true; + } + break; + case 10: // unconfined 3D GW. 5.3.07 JOD + in >> capillary_pressure_values[1]; // Slr + in >> capillary_pressure_values[0]; // Pb + break; + default: + ScreenMessage("Error in MMPRead: no valid capillary pressure model.\n"); + exit(1); + break; } - if(old_format){ + if (old_format) + { ScreenMessage("\n--\n Adopting capillary pressure saturation parameters from the\n"); ScreenMessage(" relative permeability function for phase 0. Alternatively, you\n"); ScreenMessage(" may enter capillary pressure specific parameters directly.\n--/n"); @@ -1589,8 +1613,8 @@ std::ios::pos_type CMediumProperties::Read(std::ifstream* mmp_file) continue; } //.................................................................... - //Dual Richards - if(line_string.find("$TRANSFER_COEFFICIENT") != std::string::npos) + // Dual Richards + if (line_string.find("$TRANSFER_COEFFICIENT") != std::string::npos) { in.str(GetLineFromFile1(mmp_file)); in >> transfer_coefficient; //(-) @@ -1599,111 +1623,109 @@ std::ios::pos_type CMediumProperties::Read(std::ifstream* mmp_file) continue; } //.................................................................... - //Dual Richards - if(line_string.find("$SPECIFIC_STORAGE") != std::string::npos) + // Dual Richards + if (line_string.find("$SPECIFIC_STORAGE") != std::string::npos) { in.str(GetLineFromFile1(mmp_file)); in >> specific_storage; //(Pa-1) in.clear(); continue; } - //AS:08.2012 storage function eff stress - if(line_string.find("$STORAGE_FUNCTION_EFFSTRESS")!=std::string::npos) + // AS:08.2012 storage function eff stress + if (line_string.find("$STORAGE_FUNCTION_EFFSTRESS") != std::string::npos) { in.str(GetLineFromFile1(mmp_file)); in >> storage_effstress_model; - switch(storage_effstress_model) + switch (storage_effstress_model) { - case 1: - in >> storage_effstress_model_value[0]; - break; - default: - cout<< "Error in MMPRead: no valid storage stress model" << "\n"; - break; + case 1: + in >> storage_effstress_model_value[0]; + break; + default: + cout << "Error in MMPRead: no valid storage stress model" + << "\n"; + break; } in.clear(); continue; } //------------------------------------------------------------------------ - //14 MASSDISPERSION_ + // 14 MASSDISPERSION_ // (1) LONGITUDINAL // (2) TRANSVERSE //------------------------------------------------------------------------ - //subkeyword found - if(line_string.find("$MASS_DISPERSION") != std::string::npos) + // subkeyword found + if (line_string.find("$MASS_DISPERSION") != std::string::npos) { in.str(GetLineFromFile1(mmp_file)); in >> mass_dispersion_model; - switch(mass_dispersion_model) + switch (mass_dispersion_model) { - case 0: // f(x) - break; - case 1: // Constant value - in >> mass_dispersion_longitudinal; - in >> mass_dispersion_transverse; - in >> lgpn; - if(lgpn > 0 ) - cout << " Limiting Grid Peclet Numbers to " << lgpn << - "\n"; - break; - default: - std::cout << - "Error in CMediumProperties::Read: no valid mass dispersion model" - << "\n"; - break; + case 0: // f(x) + break; + case 1: // Constant value + in >> mass_dispersion_longitudinal; + in >> mass_dispersion_transverse; + in >> lgpn; + if (lgpn > 0) + cout << " Limiting Grid Peclet Numbers to " << lgpn << "\n"; + break; + default: + std::cout << "Error in CMediumProperties::Read: no valid mass dispersion model" + << "\n"; + break; } in.clear(); continue; } - // Chiogna et al ES&T model: Daq-dependent alpha_t - if(line_string.find("$COMPOUND_DEPENDENT_DT")!=std::string::npos) - { //subkeyword found - in.str(GetLineFromFile1(mmp_file)); - in >> alpha_t_model >> graindiameter >> hydraulicrad >> betaexpo ; - in.clear(); - continue; - } + // Chiogna et al ES&T model: Daq-dependent alpha_t + if (line_string.find("$COMPOUND_DEPENDENT_DT") != std::string::npos) + { // subkeyword found + in.str(GetLineFromFile1(mmp_file)); + in >> alpha_t_model >> graindiameter >> hydraulicrad >> betaexpo; + in.clear(); + continue; + } //------------------------------------------------------------------------ - //15 HEATDISPERSION + // 15 HEATDISPERSION // (1) LONGTIDUINAL // (2) TRANSVERSE //------------------------------------------------------------------------ - //subkeyword found - if(line_string.find("$HEAT_DISPERSION") != std::string::npos) + // subkeyword found + if (line_string.find("$HEAT_DISPERSION") != std::string::npos) { in.str(GetLineFromFile1(mmp_file)); in >> heat_dispersion_model; - switch(heat_dispersion_model) + switch (heat_dispersion_model) { - case 0: // f(x) - break; - case 1: // Constant value - in >> heat_dispersion_longitudinal; - in >> heat_dispersion_transverse; - break; - default: - std::cout << - "Error in CMediumProperties::Read: no valid heat dispersion model" - << "\n"; - break; + case 0: // f(x) + break; + case 1: // Constant value + in >> heat_dispersion_longitudinal; + in >> heat_dispersion_transverse; + break; + default: + std::cout << "Error in CMediumProperties::Read: no valid heat dispersion model" + << "\n"; + break; } in.clear(); continue; } - //subkeyword found - if(line_string.find("$DIFFUSION") != std::string::npos) + // subkeyword found + if (line_string.find("$DIFFUSION") != std::string::npos) { in.str(GetLineFromFile1(mmp_file)); in >> heat_diffusion_model; - if (heat_diffusion_model==1) - in >> base_heat_diffusion_coefficient; - else if (heat_diffusion_model==273) //JM allow old model number - heat_diffusion_model=1; + if (heat_diffusion_model == 1) + in >> base_heat_diffusion_coefficient; + else if (heat_diffusion_model == 273) // JM allow old model number + heat_diffusion_model = 1; in.clear(); continue; } - //subkeyword found - if(line_string.find("$EVAPORATION") != string::npos) + // subkeyword found + if (line_string.find("$EVAPORATION") != string::npos) { in.str(GetLineFromFile1(mmp_file)); in >> evaporation; @@ -1713,10 +1735,10 @@ std::ios::pos_type CMediumProperties::Read(std::ifstream* mmp_file) continue; } //------------------------------------------------------------------------ - //16. Surface water + // 16. Surface water //------------------------------------------------------------------------ - //subkeyword found - if(line_string.find("$SURFACE_FRICTION") != std::string::npos) + // subkeyword found + if (line_string.find("$SURFACE_FRICTION") != std::string::npos) { in.str(GetLineFromFile1(mmp_file)); in >> friction_coefficient >> friction_exp_slope >> friction_exp_depth; @@ -1724,8 +1746,8 @@ std::ios::pos_type CMediumProperties::Read(std::ifstream* mmp_file) continue; } - //subkeyword found - if(line_string.find("$WIDTH") != std::string::npos) + // subkeyword found + if (line_string.find("$WIDTH") != std::string::npos) { in.str(GetLineFromFile1(mmp_file)); in >> overland_width; @@ -1733,8 +1755,8 @@ std::ios::pos_type CMediumProperties::Read(std::ifstream* mmp_file) continue; } - //subkeyword found - if(line_string.find("$RILL") != std::string::npos) + // subkeyword found + if (line_string.find("$RILL") != std::string::npos) { in.str(GetLineFromFile1(mmp_file)); in >> rill_height >> rill_epsilon; @@ -1742,31 +1764,31 @@ std::ios::pos_type CMediumProperties::Read(std::ifstream* mmp_file) continue; } - //subkeyword found - if(line_string.find("$CHANNEL") != std::string::npos) + // subkeyword found + if (line_string.find("$CHANNEL") != std::string::npos) { channel = 1; continue; } //------------------------------------------------------------------------ - //19 ELECTRIC_CONDUCTIVITY + // 19 ELECTRIC_CONDUCTIVITY //------------------------------------------------------------------------ //------------------------------------------------------------------------ - //20 UNCONFINED_FLOW_GROUP + // 20 UNCONFINED_FLOW_GROUP //------------------------------------------------------------------------ //------------------------------------------------------------------------ - //21 FLUID_EXCHANGE_WITH_OTHER_CONTINUA + // 21 FLUID_EXCHANGE_WITH_OTHER_CONTINUA //------------------------------------------------------------------------ //------------------------------------------------------------------------ - //11..PERMEABILITY_DISTRIBUTION + // 11..PERMEABILITY_DISTRIBUTION //------------------------------------------------------------------------ - size_t indexChWin, indexChLinux; //WW + size_t indexChWin, indexChLinux; // WW indexChWin = indexChLinux = 0; std::string funfname; - //subkeyword found - if(line_string.find("$PERMEABILITY_DISTRIBUTION") != std::string::npos) + // subkeyword found + if (line_string.find("$PERMEABILITY_DISTRIBUTION") != std::string::npos) { in.str(GetLineFromFile1(mmp_file)); in >> permeability_file; @@ -1774,26 +1796,25 @@ std::ios::pos_type CMediumProperties::Read(std::ifstream* mmp_file) //-------WW indexChWin = FileName.find_last_of('\\'); indexChLinux = FileName.find_last_of('/'); - if(indexChWin == string::npos && indexChLinux == std::string::npos) + if (indexChWin == string::npos && indexChLinux == std::string::npos) funfname = file_name; - else if(indexChWin != string::npos) + else if (indexChWin != string::npos) { - funfname = FileName.substr(0,indexChWin); + funfname = FileName.substr(0, indexChWin); funfname = funfname + "\\" + file_name; } - else if(indexChLinux != string::npos) + else if (indexChLinux != string::npos) { - funfname = FileName.substr(0,indexChLinux); + funfname = FileName.substr(0, indexChLinux); funfname = funfname + "/" + file_name; } permeability_file = funfname; //-------------------------------------- - //WW - std::ifstream mmp_file(funfname.data(),std::ios::in); + // WW + std::ifstream mmp_file(funfname.data(), std::ios::in); if (!mmp_file.good()) - std::cout << - "Fatal error in MMPRead: no PERMEABILITY_DISTRIBUTION file" << - "\n"; + std::cout << "Fatal error in MMPRead: no PERMEABILITY_DISTRIBUTION file" + << "\n"; mmp_file.close(); permeability_model = 2; in.clear(); @@ -1801,128 +1822,132 @@ std::ios::pos_type CMediumProperties::Read(std::ifstream* mmp_file) } //------------------------------------------------------------------------ - //11..POROSITY_DISTRIBUTION + // 11..POROSITY_DISTRIBUTION //------------------------------------------------------------------------ - //subkeyword found - if(line_string.find("$POROSITY_DISTRIBUTION") != std::string::npos) + // subkeyword found + if (line_string.find("$POROSITY_DISTRIBUTION") != std::string::npos) { in.str(GetLineFromFile1(mmp_file)); in >> porosity_file; string file_name = porosity_file; - //else{ //CB this is to get the correct path in case the exe is not run from within the project folder + // else{ //CB this is to get the correct path in case the exe is not run from within the project folder // pos = (int)FileName.find_last_of('\\', -1) + 1; // file_name = FileName.substr(0,pos) + porosity_file; //} //-------CB as above by WW indexChWin = FileName.find_last_of('\\'); indexChLinux = FileName.find_last_of('/'); - if(indexChWin == string::npos && indexChLinux == std::string::npos) + if (indexChWin == string::npos && indexChLinux == std::string::npos) funfname = file_name; - else if(indexChWin != string::npos) + else if (indexChWin != string::npos) { - funfname = FileName.substr(0,indexChWin); + funfname = FileName.substr(0, indexChWin); funfname = funfname + "\\" + file_name; } - else if(indexChLinux != string::npos) + else if (indexChLinux != string::npos) { - funfname = FileName.substr(0,indexChLinux); + funfname = FileName.substr(0, indexChLinux); funfname = funfname + "/" + file_name; } porosity_file = funfname; - //WW - ifstream mmp_file(funfname.data(),ios::in); + // WW + ifstream mmp_file(funfname.data(), ios::in); if (!mmp_file.good()) - std::cout << - "Fatal error in MMPRead: no POROSITY_DISTRIBUTION file" << - "\n"; + std::cout << "Fatal error in MMPRead: no POROSITY_DISTRIBUTION file" + << "\n"; mmp_file.close(); porosity_model = 11; in.clear(); continue; } - //------------------------------------------------------------------------ - // HEAT_TRANSFER - //------------------------------------------------------------------------ - if(line_string.find("$HEAT_TRANSFER")!=std::string::npos) //NW - { - in.str(GetLineFromFile1(mmp_file)); - in >> heat_transfer_model; - switch(heat_transfer_model) - { - case 0: // f(x) - break; - case 1: // Constant value - in >> heat_transfer_model_value; - break; - case 2: // Effective heat transfer coefficient between fluid and particles - in >> effective_heat_transfer_model; - if (effective_heat_transfer_model==1) { - std::cout << "-> Heat transfer model: Schaube11 with given h" << '\n'; - in >> heat_transfer_model_value; - } else if (effective_heat_transfer_model==2) { - std::cout << "-> Heat transfer model: Schaube11 with h by Gnielinskl" << '\n'; - } else { - std::cout << "Error in CMediumProperties::Read: no valid effective heat transfer model" << '\n'; - } - break; - default: - std::cout << "Error in CMediumProperties::Read: no valid heat transfer model" << '\n'; - break; - } - in.clear(); - continue; - } - - //------------------------------------------------------------------------ - // Particle diameter - //------------------------------------------------------------------------ - if(line_string.find("$PARTICLE_DIAMETER")!=std::string::npos) //NW - { - in.str(GetLineFromFile1(mmp_file)); - in >> particle_diameter_model; - switch(particle_diameter_model) - { - case 0: // f(x) - break; - case 1: // Constant value - std::cout << "-> Particle dimaeter is set" << '\n'; - in >> particle_diameter_model_value; - break; - default: - std::cout << "Error in CMediumProperties::Read: no valid heat transfer model" << '\n'; - break; - } - in.clear(); - continue; - } - - if(line_string.find("$INTERPHASE_FRICTION")!=std::string::npos) - { - in.str(GetLineFromFile1(mmp_file)); - in >> PhaseHeatedByFriction; - this->setFrictionPhase(FiniteElement::convertFrictionPhase(PhaseHeatedByFriction)); - if (PhaseHeatedByFriction.compare("SOLID") != 0 && PhaseHeatedByFriction.compare("FLUID") != 0 && PhaseHeatedByFriction.compare("NONE") != 0) - std::cout << "Error in CMediumProperties::Read: $INTERPHASE_FRICTION must be either SOLID or FLUID or NONE"; - in.clear(); - continue; - } - //------------------------------------------------------------------------ - // Element volme multiplyer - //------------------------------------------------------------------------ - if (line_string.find("$ELEMENT_VOLUME_MULTIPLYER") != std::string::npos) - { - in.str(GetLineFromFile1(mmp_file)); - in >> ElementVolumeMultiplyer; - std::cout << " Setting ElementVolumeMultiplyer to " << ElementVolumeMultiplyer << "- times the grid value \n"; - } + //------------------------------------------------------------------------ + // HEAT_TRANSFER + //------------------------------------------------------------------------ + if (line_string.find("$HEAT_TRANSFER") != std::string::npos) // NW + { + in.str(GetLineFromFile1(mmp_file)); + in >> heat_transfer_model; + switch (heat_transfer_model) + { + case 0: // f(x) + break; + case 1: // Constant value + in >> heat_transfer_model_value; + break; + case 2: // Effective heat transfer coefficient between fluid and particles + in >> effective_heat_transfer_model; + if (effective_heat_transfer_model == 1) + { + std::cout << "-> Heat transfer model: Schaube11 with given h" << '\n'; + in >> heat_transfer_model_value; + } + else if (effective_heat_transfer_model == 2) + { + std::cout << "-> Heat transfer model: Schaube11 with h by Gnielinskl" << '\n'; + } + else + { + std::cout << "Error in CMediumProperties::Read: no valid effective heat transfer model" << '\n'; + } + break; + default: + std::cout << "Error in CMediumProperties::Read: no valid heat transfer model" << '\n'; + break; + } + in.clear(); + continue; + } + //------------------------------------------------------------------------ + // Particle diameter + //------------------------------------------------------------------------ + if (line_string.find("$PARTICLE_DIAMETER") != std::string::npos) // NW + { + in.str(GetLineFromFile1(mmp_file)); + in >> particle_diameter_model; + switch (particle_diameter_model) + { + case 0: // f(x) + break; + case 1: // Constant value + std::cout << "-> Particle dimaeter is set" << '\n'; + in >> particle_diameter_model_value; + break; + default: + std::cout << "Error in CMediumProperties::Read: no valid heat transfer model" << '\n'; + break; + } + in.clear(); + continue; + } - } + if (line_string.find("$INTERPHASE_FRICTION") != std::string::npos) + { + in.str(GetLineFromFile1(mmp_file)); + in >> PhaseHeatedByFriction; + this->setFrictionPhase(FiniteElement::convertFrictionPhase(PhaseHeatedByFriction)); + if (PhaseHeatedByFriction.compare("SOLID") != 0 && PhaseHeatedByFriction.compare("FLUID") != 0 + && PhaseHeatedByFriction.compare("NONE") != 0) + std::cout + << "Error in CMediumProperties::Read: $INTERPHASE_FRICTION must be either SOLID or FLUID or NONE"; + in.clear(); + continue; + } + //------------------------------------------------------------------------ + // Element volme multiplyer + //------------------------------------------------------------------------ + if (line_string.find("$ELEMENT_VOLUME_MULTIPLYER") != std::string::npos) + { + in.str(GetLineFromFile1(mmp_file)); + in >> ElementVolumeMultiplyer; + std::cout << " Setting ElementVolumeMultiplyer to " << ElementVolumeMultiplyer + << "- times the grid value \n"; + } + } return position; } - /************************************************************************** FEMLib-Method: MMPWrite Task: master write functionn @@ -1931,7 +1956,7 @@ std::ios::pos_type CMediumProperties::Read(std::ifstream* mmp_file) last modification: **************************************************************************/ void MMPWrite(std::string file_base_name) -//void MATWriteMediumProperties(fstream *mp_file) +// void MATWriteMediumProperties(fstream *mp_file) { CMediumProperties* m_mat_mp = NULL; std::string sub_line; @@ -1939,18 +1964,17 @@ void MMPWrite(std::string file_base_name) //======================================================================== // File handling std::string mp_file_name = file_base_name + MMP_FILE_EXTENSION; - std::fstream mp_file (mp_file_name.c_str(),std::ios::trunc | ios::out); - mp_file.setf(std::ios::scientific,std::ios::floatfield); + std::fstream mp_file(mp_file_name.c_str(), std::ios::trunc | ios::out); + mp_file.setf(std::ios::scientific, std::ios::floatfield); mp_file.precision(12); if (!mp_file.good()) return; - mp_file << - "GeoSys-MMP: Material Medium Properties ------------------------------------------------\n"; + mp_file << "GeoSys-MMP: Material Medium Properties ------------------------------------------------\n"; //======================================================================== // MAT-MP list int no_mat = (int)mmp_vector.size(); int i; - for(i = 0; i < no_mat; i++) + for (i = 0; i < no_mat; i++) { m_mat_mp = mmp_vector[i]; m_mat_mp->Write(&mp_file); @@ -1974,207 +1998,225 @@ void MMPWrite(std::string file_base_name) **************************************************************************/ void CMediumProperties::Write(std::fstream* mmp_file) { - //KEYWORD + // KEYWORD *mmp_file << "#MEDIUM_PROPERTIES\n"; //-------------------------------------------------------------------- - //NAME - if(name.length() > 0) + // NAME + if (name.length() > 0) { - *mmp_file << " $NAME" << "\n"; + *mmp_file << " $NAME" + << "\n"; *mmp_file << " "; *mmp_file << name << "\n"; } //-------------------------------------------------------------------- - //GEO_TYPE -// if(geo_type_name.compare("DOMAIN") == 0) //OK - if(_geo_type == GEOLIB::GEODOMAIN) // OK / TF + // GEO_TYPE + // if(geo_type_name.compare("DOMAIN") == 0) //OK + if (_geo_type == GEOLIB::GEODOMAIN) // OK / TF { - *mmp_file << " $GEO_TYPE" << "\n"; - *mmp_file << " DOMAIN" << "\n"; + *mmp_file << " $GEO_TYPE" + << "\n"; + *mmp_file << " DOMAIN" + << "\n"; } - else if((int)geo_name_vector.size() > 0) //OK + else if ((int)geo_name_vector.size() > 0) // OK { - *mmp_file << " $GEO_TYPE" << "\n"; - for(int i = 0; i < (int)geo_name_vector.size(); i++) + *mmp_file << " $GEO_TYPE" + << "\n"; + for (int i = 0; i < (int)geo_name_vector.size(); i++) { *mmp_file << " "; -// *mmp_file << geo_type_name; + // *mmp_file << geo_type_name; *mmp_file << GEOLIB::convertGeoTypeToString(_geo_type); *mmp_file << " "; *mmp_file << geo_name_vector[i] << "\n"; } } //-------------------------------------------------------------------- - //DIMENSION - *mmp_file << " $GEOMETRY_DIMENSION" << "\n"; + // DIMENSION + *mmp_file << " $GEOMETRY_DIMENSION" + << "\n"; *mmp_file << " "; *mmp_file << geo_dimension << "\n"; - *mmp_file << " $GEOMETRY_AREA" << "\n"; + *mmp_file << " $GEOMETRY_AREA" + << "\n"; *mmp_file << " "; *mmp_file << geo_area << "\n"; //-------------------------------------------------------------------- - //PROPERTIES + // PROPERTIES //.................................................................... - //POROSITY - if(porosity_model > -1) + // POROSITY + if (porosity_model > -1) { - *mmp_file << " $POROSITY" << "\n"; + *mmp_file << " $POROSITY" + << "\n"; *mmp_file << " "; *mmp_file << porosity_model << " "; switch (porosity_model) { - case 1: - *mmp_file << porosity_model_values[0] << "\n"; - break; - case 11: //MB ToDo - *mmp_file << porosity_file << "\n"; //MB - break; + case 1: + *mmp_file << porosity_model_values[0] << "\n"; + break; + case 11: // MB ToDo + *mmp_file << porosity_file << "\n"; // MB + break; } } //.................................................................... - //TORTUOSITY //OK4104 - if(tortuosity_model > -1) + // TORTUOSITY //OK4104 + if (tortuosity_model > -1) { - *mmp_file << " $TORTUOSITY" << "\n"; + *mmp_file << " $TORTUOSITY" + << "\n"; *mmp_file << " "; *mmp_file << tortuosity_model << " "; switch (tortuosity_model) { - case 1: - *mmp_file << tortuosity_model_values[0] << "\n"; - break; - case 2: - *mmp_file << tortuosity_model_values[0] << "\n"; - break; + case 1: + *mmp_file << tortuosity_model_values[0] << "\n"; + break; + case 2: + *mmp_file << tortuosity_model_values[0] << "\n"; + break; } } //.................................................................... - //CONDUCTIVITY //MB ToDo - if(conductivity_model > -1) + // CONDUCTIVITY //MB ToDo + if (conductivity_model > -1) { - *mmp_file << " $CONDUCTIVITY_MODEL" << "\n"; + *mmp_file << " $CONDUCTIVITY_MODEL" + << "\n"; *mmp_file << " "; *mmp_file << conductivity_model << " "; switch (conductivity_model) { - case 1: - *mmp_file << conductivity; - break; + case 1: + *mmp_file << conductivity; + break; } *mmp_file << "\n"; } //.................................................................... - //STORAGE - if(storage_model > -1) + // STORAGE + if (storage_model > -1) { - *mmp_file << " $STORAGE" << "\n"; + *mmp_file << " $STORAGE" + << "\n"; switch (storage_model) { - case 1: - *mmp_file << " " << storage_model << " " << storage_model_values[0] << - "\n"; - break; + case 1: + *mmp_file << " " << storage_model << " " << storage_model_values[0] << "\n"; + break; } } //.................................................................... - //PERMEABILITY_TENSOR - if(permeability_tensor_type > -1) + // PERMEABILITY_TENSOR + if (permeability_tensor_type > -1) { - *mmp_file << " $PERMEABILITY_TENSOR" << "\n"; + *mmp_file << " $PERMEABILITY_TENSOR" + << "\n"; switch (permeability_tensor_type) { - case 0: - *mmp_file << " " << "ISOTROPIC" << " " << permeability_tensor[0] << "\n"; - break; - case 3: //MB for heterogeneous fields //OK - *mmp_file << " " << "FILE" << " " << permeability_file << "\n"; - break; + case 0: + *mmp_file << " " + << "ISOTROPIC" + << " " << permeability_tensor[0] << "\n"; + break; + case 3: // MB for heterogeneous fields //OK + *mmp_file << " " + << "FILE" + << " " << permeability_file << "\n"; + break; } } //.................................................................... - //PERMEABILITY_DISTRIBUTION - if(permeability_model == 2) + // PERMEABILITY_DISTRIBUTION + if (permeability_model == 2) { - *mmp_file << " $PERMEABILITY_DISTRIBUTION" << "\n"; + *mmp_file << " $PERMEABILITY_DISTRIBUTION" + << "\n"; *mmp_file << " " << permeability_file << "\n"; } //.................................................................... - //PERMEABILITY - if(permeability_saturation_model[0] > -1) + // PERMEABILITY + if (permeability_saturation_model[0] > -1) { - *mmp_file << " $PERMEABILITY_SATURATION" << "\n"; - for(int i = 0; i < (int)mfp_vector.size(); i++) + *mmp_file << " $PERMEABILITY_SATURATION" + << "\n"; + for (int i = 0; i < (int)mfp_vector.size(); i++) { *mmp_file << " "; *mmp_file << permeability_saturation_model[0] << " "; switch (permeability_saturation_model[0]) { - case 0: - *mmp_file << (int)perm_saturation_value[0] << "\n"; - break; - case 4: //VG - *mmp_file << perm_saturation_value[0] << " "; - *mmp_file << 1.0-perm_saturation_value[0] << " "; - *mmp_file << perm_saturation_value[0] << "\n"; - break; + case 0: + *mmp_file << (int)perm_saturation_value[0] << "\n"; + break; + case 4: // VG + *mmp_file << perm_saturation_value[0] << " "; + *mmp_file << 1.0 - perm_saturation_value[0] << " "; + *mmp_file << perm_saturation_value[0] << "\n"; + break; } } } //.................................................................... - //CAPILLARY PRESSURE - if(capillary_pressure_model > -1) + // CAPILLARY PRESSURE + if (capillary_pressure_model > -1) { - *mmp_file << " $CAPILLARY_PRESSURE" << "\n"; + *mmp_file << " $CAPILLARY_PRESSURE" + << "\n"; *mmp_file << " "; *mmp_file << capillary_pressure_model << " "; switch (capillary_pressure_model) { - case 0: - *mmp_file << (int)capillary_pressure_values[0] << "\n"; - break; - case 4: //VG - *mmp_file << capillary_pressure_values[0] << "\n"; - break; - case 9: // HydroSphere - *mmp_file << capillary_pressure_values[0] << " "; - *mmp_file << capillary_pressure_values[1] << "\n"; - *mmp_file << capillary_pressure_values[2] << "\n"; - break; + case 0: + *mmp_file << (int)capillary_pressure_values[0] << "\n"; + break; + case 4: // VG + *mmp_file << capillary_pressure_values[0] << "\n"; + break; + case 9: // HydroSphere + *mmp_file << capillary_pressure_values[0] << " "; + *mmp_file << capillary_pressure_values[1] << "\n"; + *mmp_file << capillary_pressure_values[2] << "\n"; + break; } } //.................................................................... - //HEAT DISPERSION - if(heat_dispersion_model > -1) + // HEAT DISPERSION + if (heat_dispersion_model > -1) { - *mmp_file << " $HEAT_DISPERSION" << "\n"; + *mmp_file << " $HEAT_DISPERSION" + << "\n"; switch (heat_dispersion_model) { - case 1: - //CMCD permeability - *mmp_file << " " << heat_dispersion_model << " " << - heat_dispersion_longitudinal << " " << heat_dispersion_transverse << "\n"; - break; + case 1: + // CMCD permeability + *mmp_file << " " << heat_dispersion_model << " " << heat_dispersion_longitudinal << " " + << heat_dispersion_transverse << "\n"; + break; } } //.................................................................... - //MASS DISPERSION - if(mass_dispersion_model > -1) + // MASS DISPERSION + if (mass_dispersion_model > -1) { - *mmp_file << " $MASS_DISPERSION" << "\n"; - switch(mass_dispersion_model) + *mmp_file << " $MASS_DISPERSION" + << "\n"; + switch (mass_dispersion_model) { - case 1: - //CMCD permeability - *mmp_file << " " << mass_dispersion_model << " " << - mass_dispersion_longitudinal << " " << mass_dispersion_transverse << "\n"; - break; + case 1: + // CMCD permeability + *mmp_file << " " << mass_dispersion_model << " " << mass_dispersion_longitudinal << " " + << mass_dispersion_transverse << "\n"; + break; } } //---------------------------------------------------------------------- } - //////////////////////////////////////////////////////////////////////////// // Access functions //////////////////////////////////////////////////////////////////////////// @@ -2186,21 +2228,20 @@ void CMediumProperties::Write(std::fstream* mmp_file) 02/2004 OK Implementation last modification: **************************************************************************/ -CMediumProperties* MMPGet(const std::string &mat_name) +CMediumProperties* MMPGet(const std::string& mat_name) { CMediumProperties* m_mat = NULL; int no_mat = (int)mmp_vector.size(); int i; - for(i = 0; i < no_mat; i++) + for (i = 0; i < no_mat; i++) { m_mat = mmp_vector[i]; - if(mat_name.compare(m_mat->name) == 0) + if (mat_name.compare(m_mat->name) == 0) return m_mat; } return NULL; } - /************************************************************************** FEMLib-Method: CMediumProperties Task: get instance by name @@ -2213,16 +2254,15 @@ CMediumProperties* CMediumProperties::GetByGroupNumber(int group_number) CMediumProperties* m_mat = NULL; int no_mat = (int)mmp_vector.size(); int i; - for(i = 0; i < no_mat; i++) + for (i = 0; i < no_mat; i++) { m_mat = mmp_vector[i]; - if(m_mat->number == group_number) + if (m_mat->number == group_number) return m_mat; } return NULL; } - //////////////////////////////////////////////////////////////////////////// // Properties functions //////////////////////////////////////////////////////////////////////////// @@ -2238,19 +2278,20 @@ double CMediumProperties::GetEffectiveSaturationForPerm(const double wetting_sat double sl, se, slr, slm; sl = wetting_saturation; // - switch(phase){ + switch (phase) + { case 0: slr = residual_saturation[phase]; slm = maximum_saturation[phase]; - sl = MRange(slr,sl,slm); - se = (sl - slr) / (slm - slr); + sl = MRange(slr, sl, slm); + se = (sl - slr) / (slm - slr); break; // case 1: - slr = 1.0 - maximum_saturation[phase]; // slr = 1.0 - sgm + slr = 1.0 - maximum_saturation[phase]; // slr = 1.0 - sgm slm = 1.0 - residual_saturation[phase]; // slm = 1.0 - sgr - sl = MRange(slr,sl,slm); - se = (sl - slr) / (slm - slr); + sl = MRange(slr, sl, slm); + se = (sl - slr) / (slm - slr); break; // default: @@ -2284,13 +2325,14 @@ double CMediumProperties::PermeabilitySaturationFunction(const double wetting_sa sl = wetting_saturation; // model = permeability_saturation_model[phase]; - if(model == 2){ // krg = 1.0 - krl : get paramters for liquid phase calculation + if (model == 2) + { // krg = 1.0 - krl : get paramters for liquid phase calculation phase_shift = true; - phase = 0; - model = permeability_saturation_model[phase]; + phase = 0; + model = permeability_saturation_model[phase]; } // - switch(model) + switch (model) { default: ScreenMessage("ERROR in PermeabilitySaturationFunction(): Unrecognized relative permeability method.\n"); @@ -2298,8 +2340,8 @@ double CMediumProperties::PermeabilitySaturationFunction(const double wetting_sa break; // case 0: // CURVE - kr = GetCurveValue((int)perm_saturation_value[phase],0,sl,&gueltig); - if(kr < minimum_relative_permeability) + kr = GetCurveValue((int)perm_saturation_value[phase], 0, sl, &gueltig); + if (kr < minimum_relative_permeability) kr = minimum_relative_permeability; break; // @@ -2315,18 +2357,18 @@ double CMediumProperties::PermeabilitySaturationFunction(const double wetting_sa case 3: // FUNCTION: LINEAR OR POWER --> WETTING: krw = (b*Se)^m slr = residual_saturation[phase]; slm = maximum_saturation[phase]; - m = saturation_exponent[phase]; - b = perm_saturation_value[phase]; - sl = MRange(slr, sl, slm); - se = (sl - slr)/(slm - slr); + m = saturation_exponent[phase]; + b = perm_saturation_value[phase]; + sl = MRange(slr, sl, slm); + se = (sl - slr) / (slm - slr); // - kr = pow((b*se),m); - if(kr < minimum_relative_permeability) + kr = pow((b * se), m); + if (kr < minimum_relative_permeability) kr = minimum_relative_permeability; break; // case 10: // for unconfined 3D GW 5.3.07 JOD - //MW correct function. did only get constants before + // MW correct function. did only get constants before /* b = capillary_pressure_values[0]; slr = capillary_pressure_values[1]; @@ -2341,135 +2383,136 @@ double CMediumProperties::PermeabilitySaturationFunction(const double wetting_sa kr = sl; break; case 33: // FUNCTION: LINEAR OR POWER --> NON-WETTING krg = (b*(1-Se))^m - slr = 1.0 - maximum_saturation[phase]; // slr = 1.0 - sgm + slr = 1.0 - maximum_saturation[phase]; // slr = 1.0 - sgm slm = 1.0 - residual_saturation[phase]; // slm = 1.0 - sgr - m = saturation_exponent[phase]; - b = perm_saturation_value[phase]; - sl = MRange(slr, sl, slm); - se = (sl - slr)/(slm - slr); + m = saturation_exponent[phase]; + b = perm_saturation_value[phase]; + sl = MRange(slr, sl, slm); + se = (sl - slr) / (slm - slr); // - kr = pow((b*(1.0-se)),m); - if(kr < minimum_relative_permeability) + kr = pow((b * (1.0 - se)), m); + if (kr < minimum_relative_permeability) kr = minimum_relative_permeability; break; // case 4: // 2-phase VAN GENUCHTEN/MUALEM --> WETTING slr = residual_saturation[phase]; slm = maximum_saturation[phase]; - m = saturation_exponent[phase]; // always <= 1.0. Input is exponent = 1 / (1-lambda) - sl = MRange(slr, sl, slm); - se = (sl - slr)/(slm - slr); + m = saturation_exponent[phase]; // always <= 1.0. Input is exponent = 1 / (1-lambda) + sl = MRange(slr, sl, slm); + se = (sl - slr) / (slm - slr); // - kr = sqrt(se) * pow(1.0-pow(1.0-pow(se,1.0/m),m),2); - if(kr < minimum_relative_permeability) + kr = sqrt(se) * pow(1.0 - pow(1.0 - pow(se, 1.0 / m), m), 2); + if (kr < minimum_relative_permeability) kr = minimum_relative_permeability; break; // case 44: // 2-phase VAN GENUCHTEN/MUALEM --> NON-WETTING - slr = 1.0 - maximum_saturation[phase]; // slr = 1.0 - sgm - slm = 1.0 - residual_saturation[phase]; // slm = 1.0 - sgr - m = saturation_exponent[phase]; // always <= 1.0. Input is exponent = 1 / (1-lambda) - sl = MRange(slr, sl, slm); - se = (sl - slr)/(slm - slr); - // - kr = pow(1.0-se,1.0/3.0) * pow(1.0-pow(se,1.0/m),2.0*m); - if(kr < minimum_relative_permeability) - kr = minimum_relative_permeability; - // TF: the following commented code is a new implementation of JOD - // with this code we have different results in benchmark H2/LabGasInjec/H2_Permeability_GasPressure -// if (sl > (maximum_saturation[phase] - MKleinsteZahl)) sl = maximum_saturation[phase] -// - MKleinsteZahl; -// if (sl < (residual_saturation[phase] + MKleinsteZahl)) sl = residual_saturation[phase] -// + MKleinsteZahl; -// -// slr = residual_saturation[0]; -// slr1 = residual_saturation[1]; -// -// m = saturation_exponent[phase]; -// -// se = (sl - slr1) / (1 - slr); -// // -// kr = pow(1.0 - se, 1.0 / 3.0) * pow(1.0 - pow(se, 1.0 / m), 2.0 * m); -// if (kr < minimum_relative_permeability) -// kr = minimum_relative_permeability; + slr = 1.0 - maximum_saturation[phase]; // slr = 1.0 - sgm + slm = 1.0 - residual_saturation[phase]; // slm = 1.0 - sgr + m = saturation_exponent[phase]; // always <= 1.0. Input is exponent = 1 / (1-lambda) + sl = MRange(slr, sl, slm); + se = (sl - slr) / (slm - slr); + // + kr = pow(1.0 - se, 1.0 / 3.0) * pow(1.0 - pow(se, 1.0 / m), 2.0 * m); + if (kr < minimum_relative_permeability) + kr = minimum_relative_permeability; + // TF: the following commented code is a new implementation of JOD + // with this code we have different results in benchmark H2/LabGasInjec/H2_Permeability_GasPressure + // if (sl > (maximum_saturation[phase] - MKleinsteZahl)) sl = maximum_saturation[phase] + // - MKleinsteZahl; + // if (sl < (residual_saturation[phase] + MKleinsteZahl)) sl = residual_saturation[phase] + // + MKleinsteZahl; + // + // slr = residual_saturation[0]; + // slr1 = residual_saturation[1]; + // + // m = saturation_exponent[phase]; + // + // se = (sl - slr1) / (1 - slr); + // // + // kr = pow(1.0 - se, 1.0 / 3.0) * pow(1.0 - pow(se, 1.0 / m), 2.0 * m); + // if (kr < minimum_relative_permeability) + // kr = minimum_relative_permeability; break; // case 6: // 2-phase BROOKS/COREY --> WETTING slr = residual_saturation[phase]; slm = maximum_saturation[phase]; - m = saturation_exponent[phase]; - sl = MRange(slr, sl, slm); - se = (sl - slr)/(slm - slr); + m = saturation_exponent[phase]; + sl = MRange(slr, sl, slm); + se = (sl - slr) / (slm - slr); // - kr = pow(se,3.0+2.0/m); - if(kr < minimum_relative_permeability) + kr = pow(se, 3.0 + 2.0 / m); + if (kr < minimum_relative_permeability) kr = minimum_relative_permeability; break; // - case 61: // Brooks Corey: CB with modified effective saturation + case 61: // Brooks Corey: CB with modified effective saturation slr = residual_saturation[phase]; slm = maximum_saturation[phase]; - sl = MRange(slr, sl, slm); - se = (sl - slr)/(1 - slr); - m = saturation_exponent[phase]; - kr = pow(se,(2.0+3.0*m)/m); - kr = MRange(DBL_EPSILON,kr,1.); - break; + sl = MRange(slr, sl, slm); + se = (sl - slr) / (1 - slr); + m = saturation_exponent[phase]; + kr = pow(se, (2.0 + 3.0 * m) / m); + kr = MRange(DBL_EPSILON, kr, 1.); + break; case 66: // 2-phase BROOKS/COREY --> NON-WETTING - slr = 1.0 - maximum_saturation[phase]; // slr = 1.0 - sgm - slm = 1.0 - residual_saturation[phase]; // slm = 1.0 - sgr - m = saturation_exponent[phase]; - sl = MRange(slr, sl, slm); - se = (sl - slr)/(slm - slr); + slr = 1.0 - maximum_saturation[phase]; // slr = 1.0 - sgm + slm = 1.0 - residual_saturation[phase]; // slm = 1.0 - sgr + m = saturation_exponent[phase]; + sl = MRange(slr, sl, slm); + se = (sl - slr) / (slm - slr); // - kr = pow(1.0-se,2)*(1.0-pow(se,1.0+2.0/m)); - if(kr < minimum_relative_permeability) - kr = minimum_relative_permeability; + kr = pow(1.0 - se, 2) * (1.0 - pow(se, 1.0 + 2.0 / m)); + if (kr < minimum_relative_permeability) + kr = minimum_relative_permeability; // TF: the following commented code is a new implementation of JOD // with this code we have different results in benchmark of // Liakopoulos type and Buckley Leverett -// if (sl > (maximum_saturation[phase] - MKleinsteZahl)) -// sl = maximum_saturation[phase]- MKleinsteZahl; -// if (sl < (residual_saturation[phase] + MKleinsteZahl)) -// sl = residual_saturation[phase]+ MKleinsteZahl; -// // -// se = (sl - residual_saturation[1]) / (1. - residual_saturation[0] - residual_saturation[1]); -// kr = pow(1.0 - se, 2) * (1.0 - pow(se, (2.0 + saturation_exponent[phase]) -// / saturation_exponent[phase])); -// kr = MRange(minimum_relative_permeability,kr,1.); + // if (sl > (maximum_saturation[phase] - MKleinsteZahl)) + // sl = maximum_saturation[phase]- MKleinsteZahl; + // if (sl < (residual_saturation[phase] + MKleinsteZahl)) + // sl = residual_saturation[phase]+ MKleinsteZahl; + // // + // se = (sl - residual_saturation[1]) / (1. - residual_saturation[0] - residual_saturation[1]); + // kr = pow(1.0 - se, 2) * (1.0 - pow(se, (2.0 + saturation_exponent[phase]) + // / saturation_exponent[phase])); + // kr = MRange(minimum_relative_permeability,kr,1.); break; // case 7: // 2-phase COREY'S CURVES (JT) --> WETTING slr = residual_saturation[phase]; slm = maximum_saturation[phase]; - m = saturation_exponent[phase]; - sl = MRange(slr, sl, slm); - se = (sl - slr)/(slm - slr); + m = saturation_exponent[phase]; + sl = MRange(slr, sl, slm); + se = (sl - slr) / (slm - slr); // - kr = pow(se,4); - if(kr < minimum_relative_permeability) + kr = pow(se, 4); + if (kr < minimum_relative_permeability) kr = minimum_relative_permeability; break; // case 77: // 2-phase COREY'S CURVES (JT) --> NON-WETTING - slr = 1.0 - maximum_saturation[phase]; // slr = 1.0 - sgm - slm = 1.0 - residual_saturation[phase]; // slm = 1.0 - sgr - m = saturation_exponent[phase]; - sl = MRange(slr, sl, slm); - se = (sl - slr)/(slm - slr); + slr = 1.0 - maximum_saturation[phase]; // slr = 1.0 - sgm + slm = 1.0 - residual_saturation[phase]; // slm = 1.0 - sgr + m = saturation_exponent[phase]; + sl = MRange(slr, sl, slm); + se = (sl - slr) / (slm - slr); // - kr = pow((1.0-se),2)*(1.0-pow(se,2)); - if(kr < minimum_relative_permeability) + kr = pow((1.0 - se), 2) * (1.0 - pow(se, 2)); + if (kr < minimum_relative_permeability) kr = minimum_relative_permeability; break; } // - if(phase_shift){ // krg = 1.0 - krl : revert to gaseous phase + if (phase_shift) + { // krg = 1.0 - krl : revert to gaseous phase kr = 1.0 - kr; - if(kr < minimum_relative_permeability) + if (kr < minimum_relative_permeability) kr = minimum_relative_permeability; } // @@ -2487,8 +2530,7 @@ double CMediumProperties::PermeabilitySaturationFunction(const double wetting_sa 10/2005 YD/OK: general concept for heat capacity 10/2010 TF changed access to process type **************************************************************************/ -double CMediumProperties::HeatCapacity(long number, double theta, - CFiniteElementStd* assem) +double CMediumProperties::HeatCapacity(long number, double theta, CFiniteElementStd* assem) { SolidProp::CSolidProperties* m_msp = NULL; double heat_capacity_fluids, specific_heat_capacity_solid; @@ -2498,89 +2540,87 @@ double CMediumProperties::HeatCapacity(long number, double theta, double T0, T1 = 0.0; // double H0,H1; // ??? - bool FLOW = false; //WW + bool FLOW = false; // WW for (size_t ii = 0; ii < pcs_vector.size(); ii++) // if(pcs_vector[ii]->pcs_type_name.find("FLOW")!=string::npos) { - if (isFlowProcess (pcs_vector[ii]->getProcessType ())) + if (isFlowProcess(pcs_vector[ii]->getProcessType())) { FLOW = true; break; } - //WW if(pcs_vector[ii]->pcs_type_name.find("RICHARDS")!=string::npos) - //WW nphase = 3; + // WW if(pcs_vector[ii]->pcs_type_name.find("RICHARDS")!=string::npos) + // WW nphase = 3; //---------------------------------------------------------------------- switch (assem->SolidProp->GetCapacityModel()) { - //.................................................................... - case 0: // f(x) user-defined function - break; - //.................................................................... - case 1: // const - //OK411 - group = m_pcs->m_msh->ele_vector[number]->GetPatchIndex(); - m_msp = msp_vector[group]; - specific_heat_capacity_solid = m_msp->Heat_Capacity(); - density_solid = fabs(m_msp->Density()); - if (FLOW) - { - porosity = assem->MediaProp->Porosity(number, theta); - heat_capacity_fluids = MFPCalcFluidsHeatCapacity(assem); - } - else - { - heat_capacity_fluids = 0.0; - porosity = 0.0; - } - heat_capacity = porosity * heat_capacity_fluids + (1.0 - porosity) *specific_heat_capacity_solid* density_solid; - break; - case 2: //boiling model for YD - //YD/OK: n c rho = n S^g c^g rho^g + n S^l c^l rho^l + (1-n) c^s rho^s - //assem->GetNodalVal(1); WW - T0 = assem->interpolate(assem->NodalVal0); - //This following lines moved from fem_ele_std but wrong.. WW - /* - if(assem->FluidProp->heat_phase_change_curve>0){ // - if(assem->FluidProp->heat_phase_change_curve>0||assem->heat_phase_change) - { // - if(fabs(assem->TG-T0)<1.0e-8) T1 +=1.0e-8; - H0 = assem->interpolate(assem->NodalVal2); - H1 = assem->interpolate(assem->NodalVal3); - heat_capacity = (H1-H0)/(assem->TG-T0); - } - else //WW - { - */ - if (FLOW) - { - PG = assem->interpolate(assem->NodalValC1); - if (assem->cpl_pcs->type == 1212) // Multi-phase WW - PG *= -1.0; - Sat = SaturationCapillaryPressureFunction(-PG); - } - else - Sat = 1.0; - T1 = assem->TG; - if ((T1 - T0) < DBL_MIN) - T1 *= -1; - heat_capacity = assem->SolidProp->Heat_Capacity(T1, Porosity( - assem), Sat); - // } - break; - case 3: // D_THM1 - Richards model //WW - T1 = assem->TG; - heat_capacity = assem->SolidProp->Heat_Capacity(T1) * fabs( - assem->SolidProp->Density()) + Porosity(assem) - * MFPCalcFluidsHeatCapacity(assem); - break; - //.................................................................... - default: - std::cout - << "Error in CMediumProperties::HeatCapacity: no valid material model" - << "\n"; - break; //.................................................................... + case 0: // f(x) user-defined function + break; + //.................................................................... + case 1: // const + // OK411 + group = m_pcs->m_msh->ele_vector[number]->GetPatchIndex(); + m_msp = msp_vector[group]; + specific_heat_capacity_solid = m_msp->Heat_Capacity(); + density_solid = fabs(m_msp->Density()); + if (FLOW) + { + porosity = assem->MediaProp->Porosity(number, theta); + heat_capacity_fluids = MFPCalcFluidsHeatCapacity(assem); + } + else + { + heat_capacity_fluids = 0.0; + porosity = 0.0; + } + heat_capacity + = porosity * heat_capacity_fluids + (1.0 - porosity) * specific_heat_capacity_solid * density_solid; + break; + case 2: // boiling model for YD + // YD/OK: n c rho = n S^g c^g rho^g + n S^l c^l rho^l + (1-n) c^s rho^s + // assem->GetNodalVal(1); WW + T0 = assem->interpolate(assem->NodalVal0); + // This following lines moved from fem_ele_std but wrong.. WW + /* + if(assem->FluidProp->heat_phase_change_curve>0){ // + if(assem->FluidProp->heat_phase_change_curve>0||assem->heat_phase_change) + { // + if(fabs(assem->TG-T0)<1.0e-8) T1 +=1.0e-8; + H0 = assem->interpolate(assem->NodalVal2); + H1 = assem->interpolate(assem->NodalVal3); + heat_capacity = (H1-H0)/(assem->TG-T0); + } + else //WW + { + */ + if (FLOW) + { + PG = assem->interpolate(assem->NodalValC1); + if (assem->cpl_pcs->type == 1212) // Multi-phase WW + PG *= -1.0; + Sat = SaturationCapillaryPressureFunction(-PG); + } + else + Sat = 1.0; + T1 = assem->TG; + if ((T1 - T0) < DBL_MIN) + T1 *= -1; + heat_capacity = assem->SolidProp->Heat_Capacity(T1, Porosity(assem), Sat); + // } + break; + case 3: // D_THM1 - Richards model //WW + T1 = assem->TG; + heat_capacity = assem->SolidProp->Heat_Capacity(T1) * fabs(assem->SolidProp->Density()) + + Porosity(assem) * MFPCalcFluidsHeatCapacity(assem); + break; + //.................................................................... + default: + std::cout << "Error in CMediumProperties::HeatCapacity: no valid material model" + << "\n"; + break; + //.................................................................... } return heat_capacity; } @@ -2603,132 +2643,115 @@ double* CMediumProperties::HeatConductivityTensor(int number) { int i, dimen; SolidProp::CSolidProperties* m_msp = NULL; - double heat_conductivity_fluids,Kx[3]; + double heat_conductivity_fluids, Kx[3]; // TF unused variable - comment fix compile warning -// double *tensor = NULL; - //double a, b, Pc, T, Mw, rhow, rho_gw,rho_ga,rho_g, p_gw, mat_fac_w, mat_fac_g, A, B,H_vap, dp_gw, dPc, dA, dB, dT, q,Tc=647.3,expfactor; - double a, b, rhow, rho_gw,rho_ga,rho_g, p_gw, mat_fac_w, mat_fac_g, A, B,H_vap, dp_gw, dPc, - dA, dB, dT, q; + // double *tensor = NULL; + // double a, b, Pc, T, Mw, rhow, rho_gw,rho_ga,rho_g, p_gw, mat_fac_w, mat_fac_g, A, B,H_vap, dp_gw, dPc, dA, dB, + // dT, q,Tc=647.3,expfactor; + double a, b, rhow, rho_gw, rho_ga, rho_g, p_gw, mat_fac_w, mat_fac_g, A, B, H_vap, dp_gw, dPc, dA, dB, dT, q; // TF unused variable - comment fix compile warning -// double Tc=647.3; + // double Tc=647.3; double expfactor; - double dens_arg[3]; //AKS + double dens_arg[3]; // AKS // TF unused variable - comment fix compile warning -// ElementValue* gp_ele = ele_gp_value[Fem_Ele_Std->Index]; + // ElementValue* gp_ele = ele_gp_value[Fem_Ele_Std->Index]; // double porosity = this->porosity; //MX double Sw, porosity = this->porosity_model_values[0]; - bool FLOW = false; //WW + bool FLOW = false; // WW // int heat_capacity_model = 0; - CFluidProperties* m_mfp; //WW + CFluidProperties* m_mfp; // WW // long group = Fem_Ele_Std->GetMeshElement()->GetPatchIndex(); - m_mfp = Fem_Ele_Std->FluidProp; //WW + m_mfp = Fem_Ele_Std->FluidProp; // WW - //if (Fem_Ele_Std->PcsType==S) // Multi-phase WW + // if (Fem_Ele_Std->PcsType==S) // Multi-phase WW //{ ///*m_mfp = mfp_vector[0]; - //eos_arg[0] = Fem_Ele_Std->interpolate(Fem_Ele_Std->NodalVal0); - //eos_arg[1] = Fem_Ele_Std->interpolate(Fem_Ele_Std->NodalVal_t0); - //eos_arg[2] = Fem_Ele_Std->interpolate(Fem_Ele_Std->NodalVal_X0); - //heat_conductivity_fluids = m_mfp->HeatConductivity(eos_arg);*/ + // eos_arg[0] = Fem_Ele_Std->interpolate(Fem_Ele_Std->NodalVal0); + // eos_arg[1] = Fem_Ele_Std->interpolate(Fem_Ele_Std->NodalVal_t0); + // eos_arg[2] = Fem_Ele_Std->interpolate(Fem_Ele_Std->NodalVal_X0); + // heat_conductivity_fluids = m_mfp->HeatConductivity(eos_arg);*/ //} - //else -// { - for (size_t ii = 0; ii < pcs_vector.size(); ii++) - // if (pcs_vector[ii]->pcs_type_name.find("FLOW") != string::npos) TF - if (isFlowProcess (pcs_vector[ii]->getProcessType ())) - FLOW = true; - if (FLOW) //WW + // else + // { + for (size_t ii = 0; ii < pcs_vector.size(); ii++) + // if (pcs_vector[ii]->pcs_type_name.find("FLOW") != string::npos) TF + if (isFlowProcess(pcs_vector[ii]->getProcessType())) + FLOW = true; + if (FLOW) // WW + { + CRFProcess const* cpl_pcs = Fem_Ele_Std->cpl_pcs; + if (cpl_pcs && cpl_pcs->type == 1212) // Multi-phase WW + { + double PG = Fem_Ele_Std->interpolate(Fem_Ele_Std->NodalValC1); // Capillary pressure + double Sw = Fem_Ele_Std->MediaProp->SaturationCapillaryPressureFunction(PG); + // + m_mfp = mfp_vector[0]; + heat_conductivity_fluids = Sw * m_mfp->HeatConductivity(); + m_mfp = mfp_vector[1]; + heat_conductivity_fluids += (1.0 - Sw) * m_mfp->HeatConductivity(); + } + else { - CRFProcess const* cpl_pcs = Fem_Ele_Std->cpl_pcs; - if (cpl_pcs && cpl_pcs->type == 1212) // Multi-phase WW + if (Fem_Ele_Std->FluidProp->density_model == 14 && Fem_Ele_Std->MediaProp->heat_diffusion_model == 1 + && Fem_Ele_Std->cpl_pcs) { - double PG = Fem_Ele_Std->interpolate( - Fem_Ele_Std->NodalValC1); // Capillary pressure - double - Sw = - Fem_Ele_Std->MediaProp->SaturationCapillaryPressureFunction(PG); - // - m_mfp = mfp_vector[0]; - heat_conductivity_fluids = Sw * m_mfp->HeatConductivity(); - m_mfp = mfp_vector[1]; - heat_conductivity_fluids += (1.0 - Sw) - * m_mfp->HeatConductivity(); + dens_arg[0] = Fem_Ele_Std->interpolate(Fem_Ele_Std->NodalValC1); // Pressure + dens_arg[1] = Fem_Ele_Std->interpolate(Fem_Ele_Std->NodalVal1) + 273.15; // Temperature + dens_arg[2] = Fem_Ele_Std->Index; // ELE index + heat_conductivity_fluids = Fem_Ele_Std->FluidProp->HeatConductivity(dens_arg); } else + heat_conductivity_fluids = Fem_Ele_Std->FluidProp->HeatConductivity(); + Sw = 1; + + if (cpl_pcs && cpl_pcs->type != 1) { - if (Fem_Ele_Std->FluidProp->density_model == 14 - && Fem_Ele_Std->MediaProp->heat_diffusion_model - == 1 && Fem_Ele_Std->cpl_pcs) - { - dens_arg[0] = Fem_Ele_Std->interpolate( - Fem_Ele_Std->NodalValC1); //Pressure - dens_arg[1] = Fem_Ele_Std->interpolate( - Fem_Ele_Std->NodalVal1) + 273.15; //Temperature - dens_arg[2] = Fem_Ele_Std->Index; //ELE index - heat_conductivity_fluids - = Fem_Ele_Std->FluidProp->HeatConductivity( - dens_arg); - } - else - heat_conductivity_fluids - = Fem_Ele_Std->FluidProp->HeatConductivity(); - Sw = 1; + double PG = Fem_Ele_Std->interpolate(Fem_Ele_Std->NodalValC1); // Capillary pressure - if (cpl_pcs && cpl_pcs->type != 1) + if (PG < 0.0) { - double PG = Fem_Ele_Std->interpolate( - Fem_Ele_Std->NodalValC1); // Capillary pressure - - if (PG < 0.0) - { - Sw - = Fem_Ele_Std->MediaProp-> - SaturationCapillaryPressureFunction(-PG); - heat_conductivity_fluids *= Sw; - if (Fem_Ele_Std->GasProp != 0) - heat_conductivity_fluids - += (1. - Sw) - * Fem_Ele_Std->GasProp-> - HeatConductivity(); - } + Sw = Fem_Ele_Std->MediaProp->SaturationCapillaryPressureFunction(-PG); + heat_conductivity_fluids *= Sw; + if (Fem_Ele_Std->GasProp != 0) + heat_conductivity_fluids += (1. - Sw) * Fem_Ele_Std->GasProp->HeatConductivity(); } } } - else - { - heat_conductivity_fluids = 0.0; - porosity = 0.0; - } -//} + } + else + { + heat_conductivity_fluids = 0.0; + porosity = 0.0; + } + //} dimen = m_pcs->m_msh->GetCoordinateFlag() / 10; int group = m_pcs->m_msh->ele_vector[number]->GetPatchIndex(); - for (i = 0; i < dimen * dimen; i++) //MX + for (i = 0; i < dimen * dimen; i++) // MX heat_conductivity_tensor[i] = 0.0; m_msp = msp_vector[group]; - m_msp->HeatConductivityTensor(dimen, heat_conductivity_tensor, - group); //MX + m_msp->HeatConductivityTensor(dimen, heat_conductivity_tensor, group); // MX for (i = 0; i < dimen * dimen; i++) heat_conductivity_tensor[i] *= (1.0 - porosity); for (i = 0; i < dimen; i++) heat_conductivity_tensor[i * dimen + i] += porosity * heat_conductivity_fluids; - if(evaporation == 647) + if (evaporation == 647) { int GravityOn = 1; - if((Fem_Ele_Std->coordinate_system) % 10 != 2 && (!Fem_Ele_Std->axisymmetry)) + if ((Fem_Ele_Std->coordinate_system) % 10 != 2 && (!Fem_Ele_Std->axisymmetry)) GravityOn = 0; double PG2 = Fem_Ele_Std->interpolate(Fem_Ele_Std->NodalVal_p2); // Capillary pressure double PG = Fem_Ele_Std->interpolate(Fem_Ele_Std->NodalValC1); - //Temperature + // Temperature double TG = Fem_Ele_Std->interpolate(Fem_Ele_Std->NodalVal1) + 273.15; double Sw = Fem_Ele_Std->MediaProp->SaturationCapillaryPressureFunction(PG); heat_conductivity_fluids = 0.0; - H_vap = 2257000; //pow((Tc - TG),0.38)*2.65E+5; + H_vap = 2257000; // pow((Tc - TG),0.38)*2.65E+5; a = 19.81; b = 4975.9; m_mfp = mfp_vector[0]; @@ -2743,14 +2766,14 @@ double* CMediumProperties::HeatConductivityTensor(int number) rho_ga = m_mfp->Density(dens_arg); rho_g = rho_ga + rho_gw; m_mfp = mfp_vector[0]; - mat_fac_w = PermeabilitySaturationFunction(Sw,0) / m_mfp->Viscosity(); + mat_fac_w = PermeabilitySaturationFunction(Sw, 0) / m_mfp->Viscosity(); m_mfp = mfp_vector[1]; - mat_fac_g = PermeabilitySaturationFunction(Sw,1) / m_mfp->Viscosity(); + mat_fac_g = PermeabilitySaturationFunction(Sw, 1) / m_mfp->Viscosity(); A = b + PG / (rhow * Rv); B = a - log(p_gw / 30024.895431831395); q = heatflux; - for(i = 0; i < dimen; i++) + for (i = 0; i < dimen; i++) Kx[i] = 0.0; dPc = (q / (H_vap * 1.0e-13)) * ((1 / (rhow * mat_fac_w)) + (1 / (rho_g * mat_fac_g))); dA = dPc / (rhow * Rv); @@ -2759,7 +2782,7 @@ double* CMediumProperties::HeatConductivityTensor(int number) dT = (B * dA - A * dB) / ((B * B) + (0 / TG)); heat_conductivity_fluids = 2 * q / dT; Kx[0] = heat_conductivity_fluids; - if(GravityOn) + if (GravityOn) { dPc -= (rhow - rho_g) * gravity_constant; dA = dPc / (rhow * Rv); @@ -2769,9 +2792,9 @@ double* CMediumProperties::HeatConductivityTensor(int number) heat_conductivity_fluids = 2 * q / dT; Kx[dimen - 1] = heat_conductivity_fluids; } - for(i = 0; i < dimen * dimen; i++) + for (i = 0; i < dimen * dimen; i++) heat_conductivity_tensor[i] = 0.0; - for(i = 0; i < dimen; i++) + for (i = 0; i < dimen; i++) heat_conductivity_tensor[i * dimen + i] = Kx[i]; } return heat_conductivity_tensor; @@ -2802,72 +2825,59 @@ double* CMediumProperties::HeatDispersionTensorNew(int ip) ElementValue* gp_ele = ele_gp_value[index]; // Materials - //MX, add index + // MX, add index heat_conductivity_porous_medium = HeatConductivityTensor(index); m_mfp = Fem_Ele_Std->FluidProp; - fluid_density = m_mfp->Density(); + fluid_density = m_mfp->Density(); heat_capacity_fluids = m_mfp->getSpecificHeatCapacity(); - //Global Velocity - double velocity[3] = {0.,0.,0.}; - gp_ele->getIPvalue_vec(ip, velocity); //gp velocities - vg = MBtrgVec(velocity,3); + // Global Velocity + double velocity[3] = {0., 0., 0.}; + gp_ele->getIPvalue_vec(ip, velocity); // gp velocities + vg = MBtrgVec(velocity, 3); - //Dl in local coordinates + // Dl in local coordinates alpha_l = heat_dispersion_longitudinal; alpha_t = heat_dispersion_transverse; - if (abs(vg) > MKleinsteZahl //For the case of diffusive transport only - //WW - && (alpha_l > MKleinsteZahl || alpha_t > MKleinsteZahl) ) + if (abs(vg) > MKleinsteZahl // For the case of diffusive transport only + // WW + && (alpha_l > MKleinsteZahl || alpha_t > MKleinsteZahl)) { switch (Dim) { - case 1: // line elements - heat_dispersion_tensor[0] = heat_conductivity_porous_medium[0] + - alpha_l * heat_capacity_fluids * - fluid_density * vg; - break; - case 2: - D[0] = - (alpha_t * - vg) + (alpha_l - alpha_t) * (velocity[0] * velocity[0]) / vg; - D[1] = ((alpha_l - alpha_t) * (velocity[0] * velocity[1])) / vg; - D[2] = ((alpha_l - alpha_t) * (velocity[1] * velocity[0])) / vg; - D[3] = - (alpha_t * - vg) + (alpha_l - alpha_t) * (velocity[1] * velocity[1]) / vg; - for (i = 0; i < 4; i++) - heat_dispersion_tensor[i] = heat_conductivity_porous_medium[i] + - (D[i] * heat_capacity_fluids * - fluid_density); - break; - case 3: - D[0] = - (alpha_t * - vg) + (alpha_l - alpha_t) * (velocity[0] * velocity[0]) / vg; - D[1] = ((alpha_l - alpha_t) * (velocity[0] * velocity[1])) / vg; - D[2] = ((alpha_l - alpha_t) * (velocity[0] * velocity[2])) / vg; - D[3] = ((alpha_l - alpha_t) * (velocity[1] * velocity[0])) / vg; - D[4] = - (alpha_t * - vg) + (alpha_l - alpha_t) * (velocity[1] * velocity[1]) / vg; - D[5] = ((alpha_l - alpha_t) * (velocity[1] * velocity[2])) / vg; - D[6] = ((alpha_l - alpha_t) * (velocity[2] * velocity[0])) / vg; - D[7] = ((alpha_l - alpha_t) * (velocity[2] * velocity[1])) / vg; - D[8] = - (alpha_t * - vg) + (alpha_l - alpha_t) * (velocity[2] * velocity[2]) / vg; - for (i = 0; i < 9; i++) - heat_dispersion_tensor[i] = heat_conductivity_porous_medium[i] + - (D[i] * heat_capacity_fluids * - fluid_density); - break; + case 1: // line elements + heat_dispersion_tensor[0] + = heat_conductivity_porous_medium[0] + alpha_l * heat_capacity_fluids * fluid_density * vg; + break; + case 2: + D[0] = (alpha_t * vg) + (alpha_l - alpha_t) * (velocity[0] * velocity[0]) / vg; + D[1] = ((alpha_l - alpha_t) * (velocity[0] * velocity[1])) / vg; + D[2] = ((alpha_l - alpha_t) * (velocity[1] * velocity[0])) / vg; + D[3] = (alpha_t * vg) + (alpha_l - alpha_t) * (velocity[1] * velocity[1]) / vg; + for (i = 0; i < 4; i++) + heat_dispersion_tensor[i] + = heat_conductivity_porous_medium[i] + (D[i] * heat_capacity_fluids * fluid_density); + break; + case 3: + D[0] = (alpha_t * vg) + (alpha_l - alpha_t) * (velocity[0] * velocity[0]) / vg; + D[1] = ((alpha_l - alpha_t) * (velocity[0] * velocity[1])) / vg; + D[2] = ((alpha_l - alpha_t) * (velocity[0] * velocity[2])) / vg; + D[3] = ((alpha_l - alpha_t) * (velocity[1] * velocity[0])) / vg; + D[4] = (alpha_t * vg) + (alpha_l - alpha_t) * (velocity[1] * velocity[1]) / vg; + D[5] = ((alpha_l - alpha_t) * (velocity[1] * velocity[2])) / vg; + D[6] = ((alpha_l - alpha_t) * (velocity[2] * velocity[0])) / vg; + D[7] = ((alpha_l - alpha_t) * (velocity[2] * velocity[1])) / vg; + D[8] = (alpha_t * vg) + (alpha_l - alpha_t) * (velocity[2] * velocity[2]) / vg; + for (i = 0; i < 9; i++) + heat_dispersion_tensor[i] + = heat_conductivity_porous_medium[i] + (D[i] * heat_capacity_fluids * fluid_density); + break; } } else for (i = 0; i < Dim * Dim; i++) - heat_dispersion_tensor[i] = heat_conductivity_porous_medium[i]; + heat_dispersion_tensor[i] = heat_conductivity_porous_medium[i]; return heat_dispersion_tensor; } @@ -2885,39 +2895,37 @@ double* CMediumProperties::HeatDispersionTensorNew(int ip) **************************************************************************/ double* CMediumProperties::MassDispersionTensorNew(int ip, int tr_phase) // SB + BG { - static double advection_dispersion_tensor[9]; //Name change due to static conflict + static double advection_dispersion_tensor[9]; // Name change due to static conflict int component = Fem_Ele_Std->pcs->pcs_component_number; int i; long index = Fem_Ele_Std->GetMeshElement()->GetIndex(); double molecular_diffusion[9], molecular_diffusion_value; double vg; double D[9]; - double alpha_l,alpha_t; + double alpha_l, alpha_t; double theta = Fem_Ele_Std->pcs->m_num->ls_theta; - double g[3] = {0.,0.,0.}; - double l_char = 0.0; //OK411 volume=0.0; + double g[3] = {0., 0., 0.}; + double l_char = 0.0; // OK411 volume=0.0; double saturation = 1.0; int set = 0; double arg, Daq, Pec; ElementValue* gp_ele = ele_gp_value[index]; CompProperties* m_cp = cp_vec[component]; - //CFluidProperties* m_mfp; - //m_mfp = Fem_Ele_Std->FluidProp; + // CFluidProperties* m_mfp; + // m_mfp = Fem_Ele_Std->FluidProp; MshElemType::type eleType = m_pcs->m_msh->ele_vector[number]->GetElementType(); int Dim = m_pcs->m_msh->GetCoordinateFlag() / 10; //---------------------------------------------------------------------- // Materials - Daq = m_cp->CalcDiffusionCoefficientCP(index,theta, m_pcs) ; - molecular_diffusion_value = Daq * TortuosityFunction(index,g, theta); + Daq = m_cp->CalcDiffusionCoefficientCP(index, theta, m_pcs); + molecular_diffusion_value = Daq * TortuosityFunction(index, g, theta); - molecular_diffusion_value = m_cp->CalcDiffusionCoefficientCP(index,theta, m_pcs) * TortuosityFunction(index,g, theta); + molecular_diffusion_value + = m_cp->CalcDiffusionCoefficientCP(index, theta, m_pcs) * TortuosityFunction(index, g, theta); - molecular_diffusion_value *= Porosity(index,theta); - //CB, SB - saturation = PCSGetEleMeanNodeSecondary_2(index, - Fem_Ele_Std->pcs->flow_pcs_type, - "SATURATION1", - 1); + molecular_diffusion_value *= Porosity(index, theta); + // CB, SB + saturation = PCSGetEleMeanNodeSecondary_2(index, Fem_Ele_Std->pcs->flow_pcs_type, "SATURATION1", 1); if (tr_phase == 10) // multi phase transport saturation = 1.0 - saturation; molecular_diffusion_value *= saturation; @@ -2927,179 +2935,155 @@ double* CMediumProperties::MassDispersionTensorNew(int ip, int tr_phase) // SB + molecular_diffusion[i * Dim + i] = molecular_diffusion_value; //---------------------------------------------------------------------- - //Anisotropic diffusion coefficient - if(tortuosity_tensor_type_name[0] == 'A') + // Anisotropic diffusion coefficient + if (tortuosity_tensor_type_name[0] == 'A') { switch (Dim) { - //-------------------------------------------------------------------- - case 1: // line elements - ; // Do nothing - break; - //-------------------------------------------------------------------- - case 2: - molecular_diffusion[0] = molecular_diffusion_value * - tortuosity_model_values[0]; - molecular_diffusion[1] = molecular_diffusion_value * - tortuosity_model_values[1]; - molecular_diffusion[2] = molecular_diffusion_value * - tortuosity_model_values[2]; - molecular_diffusion[3] = molecular_diffusion_value * - tortuosity_model_values[3]; - break; - //-------------------------------------------------------------------- - case 3: - molecular_diffusion[0] = molecular_diffusion_value * - tortuosity_model_values[0]; - molecular_diffusion[1] = molecular_diffusion_value * - tortuosity_model_values[1]; - molecular_diffusion[2] = molecular_diffusion_value * - tortuosity_model_values[2]; - molecular_diffusion[3] = molecular_diffusion_value * - tortuosity_model_values[3]; - molecular_diffusion[4] = molecular_diffusion_value * - tortuosity_model_values[4]; - molecular_diffusion[5] = molecular_diffusion_value * - tortuosity_model_values[5]; - molecular_diffusion[6] = molecular_diffusion_value * - tortuosity_model_values[6]; - molecular_diffusion[7] = molecular_diffusion_value * - tortuosity_model_values[7]; - molecular_diffusion[8] = molecular_diffusion_value * - tortuosity_model_values[8]; + //-------------------------------------------------------------------- + case 1: // line elements + ; // Do nothing + break; + //-------------------------------------------------------------------- + case 2: + molecular_diffusion[0] = molecular_diffusion_value * tortuosity_model_values[0]; + molecular_diffusion[1] = molecular_diffusion_value * tortuosity_model_values[1]; + molecular_diffusion[2] = molecular_diffusion_value * tortuosity_model_values[2]; + molecular_diffusion[3] = molecular_diffusion_value * tortuosity_model_values[3]; + break; + //-------------------------------------------------------------------- + case 3: + molecular_diffusion[0] = molecular_diffusion_value * tortuosity_model_values[0]; + molecular_diffusion[1] = molecular_diffusion_value * tortuosity_model_values[1]; + molecular_diffusion[2] = molecular_diffusion_value * tortuosity_model_values[2]; + molecular_diffusion[3] = molecular_diffusion_value * tortuosity_model_values[3]; + molecular_diffusion[4] = molecular_diffusion_value * tortuosity_model_values[4]; + molecular_diffusion[5] = molecular_diffusion_value * tortuosity_model_values[5]; + molecular_diffusion[6] = molecular_diffusion_value * tortuosity_model_values[6]; + molecular_diffusion[7] = molecular_diffusion_value * tortuosity_model_values[7]; + molecular_diffusion[8] = molecular_diffusion_value * tortuosity_model_values[8]; } } - //Global Velocity - double velocity[3] = {0.,0.,0.}; - gp_ele->getIPvalue_vec_phase(ip, tr_phase, velocity); //gp velocities // SB - vg = MBtrgVec(velocity,3); - // if(index < 10) cout <<" Velocity in MassDispersionTensorNew(): "<getIPvalue_vec_phase(ip, tr_phase, velocity); // gp velocities // SB + vg = MBtrgVec(velocity, 3); + // if(index < 10) cout <<" Velocity in MassDispersionTensorNew(): "<bubble_velocity_model == 1) + if (m_cp->bubble_velocity_model == 1) { - if(index < 0) - cout << " Velocity in MassDispersionTensorNew(): " << velocity[0] << - ", " << velocity[1] << ", " << velocity[2] << ", " << vg << "\n"; + if (index < 0) + cout << " Velocity in MassDispersionTensorNew(): " << velocity[0] << ", " << velocity[1] << ", " + << velocity[2] << ", " << vg << "\n"; velocity[0] = m_cp->bubble_velocity[0]; velocity[1] = m_cp->bubble_velocity[1]; velocity[2] = m_cp->bubble_velocity[2]; - vg = MBtrgVec(velocity,3); - if(index == 100) - std::cout << " Bubble velocity in MassDispersionTensorNew(): " << - velocity[0] << ", " << velocity[1] << ", " << velocity[2] << ", " << vg << - "\n"; + vg = MBtrgVec(velocity, 3); + if (index == 100) + std::cout << " Bubble velocity in MassDispersionTensorNew(): " << velocity[0] << ", " << velocity[1] << ", " + << velocity[2] << ", " << vg << "\n"; } // end bubble velocity - //Dl in local coordinates + // Dl in local coordinates alpha_l = mass_dispersion_longitudinal; alpha_t = mass_dispersion_transverse; - // transverse Dispersion model by Chiogna et al. ES&T 2010 - // here, the dispersive part of Dmech = Dp + Ddisp is divided by vg to obtain a Daq-dependent alpha_t - // which is used in the dispersion tensor in the usual way - if(alpha_t_model == 1) { - Pec = vg*graindiameter/Daq; - arg = pow(Pec, 2) / (Pec + 2 + 4 * pow(graindiameter/hydraulicrad, 2)); - alpha_t = Daq * pow(arg, betaexpo); // D_disp_t (without the diffusion term) - alpha_t /= vg; // aT = D_disp_t/vg - } + // transverse Dispersion model by Chiogna et al. ES&T 2010 + // here, the dispersive part of Dmech = Dp + Ddisp is divided by vg to obtain a Daq-dependent alpha_t + // which is used in the dispersion tensor in the usual way + if (alpha_t_model == 1) + { + Pec = vg * graindiameter / Daq; + arg = pow(Pec, 2) / (Pec + 2 + 4 * pow(graindiameter / hydraulicrad, 2)); + alpha_t = Daq * pow(arg, betaexpo); // D_disp_t (without the diffusion term) + alpha_t /= vg; // aT = D_disp_t/vg + } // hard stabilization - if(this->lgpn > 0.0) + if (this->lgpn > 0.0) { MeshLib::CElem* m_ele = NULL; m_ele = m_pcs->m_msh->ele_vector[index]; - if(eleType == 2) + if (eleType == 2) l_char = sqrt(m_ele->GetVolume()); - if(eleType == 4) + if (eleType == 4) l_char = sqrt(m_ele->GetVolume()); // cout << " Element number: " << index << ", Volume: " << m_ele->GetVolume() << ", l_char: " << l_char << "\n"; set = 0; - if(alpha_l < l_char / lgpn) + if (alpha_l < l_char / lgpn) { - set = 1; //flag for output + set = 1; // flag for output alpha_l = l_char / lgpn; } - if(alpha_t < l_char / lgpn) + if (alpha_t < l_char / lgpn) { set = 1; alpha_t = l_char / lgpn; } - //cout << " alpha_L = " << alpha_l << " < l_char/Pe; setting alpha_L = " << l_char/lgpn << " for element " << index << "\n"; - if((set > 0) & (aktueller_zeitschritt == 1) & (component < 1) & (ip < 1)) - std::cout << "element " << index << " " << l_char << " " << alpha_l << - " " << alpha_t << "\n"; + // cout << " alpha_L = " << alpha_l << " < l_char/Pe; setting alpha_L = " << l_char/lgpn << " for element " << + // index << "\n"; + if ((set > 0) & (aktueller_zeitschritt == 1) & (component < 1) & (ip < 1)) + std::cout << "element " << index << " " << l_char << " " << alpha_l << " " << alpha_t << "\n"; } //---------------------------------------------------------------------- - if (abs(vg) > MKleinsteZahl) //For the case of diffusive transport only. + if (abs(vg) > MKleinsteZahl) // For the case of diffusive transport only. { switch (Dim) { - //-------------------------------------------------------------------- - case 1: // line elements - advection_dispersion_tensor[0] = molecular_diffusion[0] + alpha_l * vg; - break; - //-------------------------------------------------------------------- - case 2: - D[0] = - (alpha_t * - vg) + (alpha_l - alpha_t) * (velocity[0] * velocity[0]) / vg; - D[1] = ((alpha_l - alpha_t) * (velocity[0] * velocity[1])) / vg; - D[2] = ((alpha_l - alpha_t) * (velocity[1] * velocity[0])) / vg; - D[3] = - (alpha_t * - vg) + (alpha_l - alpha_t) * (velocity[1] * velocity[1]) / vg; - - if(tortuosity_tensor_type_name[0] == 'A') - for (i = 0; i < Dim * Dim; i++) - advection_dispersion_tensor[i] = molecular_diffusion[i] + - D[i]; - else - { - advection_dispersion_tensor[0] = molecular_diffusion[0] + D[0]; - //SB added - CHP, all parts of tensor required - advection_dispersion_tensor[1] = D[1]; - //SB added - CHP, all parts of tensor required - advection_dispersion_tensor[2] = D[2]; - advection_dispersion_tensor[3] = molecular_diffusion[3] + D[3]; - } - break; - //-------------------------------------------------------------------- - case 3: - D[0] = - (alpha_t * - vg) + (alpha_l - alpha_t) * (velocity[0] * velocity[0]) / vg; - D[1] = ((alpha_l - alpha_t) * (velocity[0] * velocity[1])) / vg; - D[2] = ((alpha_l - alpha_t) * (velocity[0] * velocity[2])) / vg; - D[3] = ((alpha_l - alpha_t) * (velocity[1] * velocity[0])) / vg; - D[4] = - (alpha_t * - vg) + (alpha_l - alpha_t) * (velocity[1] * velocity[1]) / vg; - D[5] = ((alpha_l - alpha_t) * (velocity[1] * velocity[2])) / vg; - D[6] = ((alpha_l - alpha_t) * (velocity[2] * velocity[0])) / vg; - D[7] = ((alpha_l - alpha_t) * (velocity[2] * velocity[1])) / vg; - D[8] = - (alpha_t * - vg) + (alpha_l - alpha_t) * (velocity[2] * velocity[2]) / vg; - if(tortuosity_tensor_type_name[0] == 'A') - for (i = 0; i < Dim * Dim; i++) - advection_dispersion_tensor[i] = molecular_diffusion[i] + - D[i]; - else - { - /* SB changed - CHP, check - aktually the main coordinate method should work - advection_dispersion_tensor[0] = molecular_diffusion[0] + D[0]; - advection_dispersion_tensor[4] = molecular_diffusion[4] + D[4]; - advection_dispersion_tensor[8] = molecular_diffusion[8] + D[8]; - */ - for (i = 0; i < Dim * Dim; i++) - advection_dispersion_tensor[i] = D[i]; - advection_dispersion_tensor[0] += molecular_diffusion[0]; - advection_dispersion_tensor[4] += molecular_diffusion[4]; - advection_dispersion_tensor[8] += molecular_diffusion[8]; - } + //-------------------------------------------------------------------- + case 1: // line elements + advection_dispersion_tensor[0] = molecular_diffusion[0] + alpha_l * vg; + break; + //-------------------------------------------------------------------- + case 2: + D[0] = (alpha_t * vg) + (alpha_l - alpha_t) * (velocity[0] * velocity[0]) / vg; + D[1] = ((alpha_l - alpha_t) * (velocity[0] * velocity[1])) / vg; + D[2] = ((alpha_l - alpha_t) * (velocity[1] * velocity[0])) / vg; + D[3] = (alpha_t * vg) + (alpha_l - alpha_t) * (velocity[1] * velocity[1]) / vg; + + if (tortuosity_tensor_type_name[0] == 'A') + for (i = 0; i < Dim * Dim; i++) + advection_dispersion_tensor[i] = molecular_diffusion[i] + D[i]; + else + { + advection_dispersion_tensor[0] = molecular_diffusion[0] + D[0]; + // SB added - CHP, all parts of tensor required + advection_dispersion_tensor[1] = D[1]; + // SB added - CHP, all parts of tensor required + advection_dispersion_tensor[2] = D[2]; + advection_dispersion_tensor[3] = molecular_diffusion[3] + D[3]; + } + break; + //-------------------------------------------------------------------- + case 3: + D[0] = (alpha_t * vg) + (alpha_l - alpha_t) * (velocity[0] * velocity[0]) / vg; + D[1] = ((alpha_l - alpha_t) * (velocity[0] * velocity[1])) / vg; + D[2] = ((alpha_l - alpha_t) * (velocity[0] * velocity[2])) / vg; + D[3] = ((alpha_l - alpha_t) * (velocity[1] * velocity[0])) / vg; + D[4] = (alpha_t * vg) + (alpha_l - alpha_t) * (velocity[1] * velocity[1]) / vg; + D[5] = ((alpha_l - alpha_t) * (velocity[1] * velocity[2])) / vg; + D[6] = ((alpha_l - alpha_t) * (velocity[2] * velocity[0])) / vg; + D[7] = ((alpha_l - alpha_t) * (velocity[2] * velocity[1])) / vg; + D[8] = (alpha_t * vg) + (alpha_l - alpha_t) * (velocity[2] * velocity[2]) / vg; + if (tortuosity_tensor_type_name[0] == 'A') + for (i = 0; i < Dim * Dim; i++) + advection_dispersion_tensor[i] = molecular_diffusion[i] + D[i]; + else + { + /* SB changed - CHP, check - aktually the main coordinate method should work + advection_dispersion_tensor[0] = molecular_diffusion[0] + D[0]; + advection_dispersion_tensor[4] = molecular_diffusion[4] + D[4]; + advection_dispersion_tensor[8] = molecular_diffusion[8] + D[8]; + */ + for (i = 0; i < Dim * Dim; i++) + advection_dispersion_tensor[i] = D[i]; + advection_dispersion_tensor[0] += molecular_diffusion[0]; + advection_dispersion_tensor[4] += molecular_diffusion[4]; + advection_dispersion_tensor[8] += molecular_diffusion[8]; + } } } else @@ -3118,8 +3102,9 @@ double* CMediumProperties::MassDispersionTensorNew(int ip, int tr_phase) // SB + double* CMediumProperties::DispersionTensorMCF(int ip, int PCSIndex, int CIndex, double* variables) { int k; - double Material[9], D[9], multiplier=1.0; - double set, vg, fac = 0.0, alpha_l,alpha_t, g[3] = {0.,0.,0.}, l_char = 0.0, theta = Fem_Ele_Std->pcs->m_num->ls_theta; + double Material[9], D[9], multiplier = 1.0; + double set, vg, fac = 0.0, alpha_l, alpha_t, g[3] = {0., 0., 0.}, l_char = 0.0, + theta = Fem_Ele_Std->pcs->m_num->ls_theta; static double tensor[9]; CFluidProperties* m_mfp; SolidProp::CSolidProperties* m_msp = NULL; @@ -3139,103 +3124,106 @@ double* CMediumProperties::DispersionTensorMCF(int ip, int PCSIndex, int CIndex, } switch (PCSIndex) { - case 0://FLOW - fac = permeability_tensor[0]/m_mfp->Viscosity(variables); - multiplier = 0.0; - break; + case 0: // FLOW + fac = permeability_tensor[0] / m_mfp->Viscosity(variables); + multiplier = 0.0; + break; - case 1: //HEAT - fac = porosity*m_mfp->HeatConductivity(variables) + (1.0 - porosity)*m_msp->Heat_Conductivity(0); - multiplier = m_mfp->Density(variables)* m_mfp->SpecificHeatCapacity(variables); - break; + case 1: // HEAT + fac = porosity * m_mfp->HeatConductivity(variables) + (1.0 - porosity) * m_msp->Heat_Conductivity(0); + multiplier = m_mfp->Density(variables) * m_mfp->SpecificHeatCapacity(variables); + break; - case 2://MASS - fac = porosity*TortuosityFunction(index, g, theta)*m_mfp->EffectiveDiffusionCoef(CIndex, variables); - multiplier = 1.0; - break; + case 2: // MASS + fac = porosity * TortuosityFunction(index, g, theta) * m_mfp->EffectiveDiffusionCoef(CIndex, variables); + multiplier = 1.0; + break; } - for (k = 0; k < Dim; k++) Material[k*Dim + k] = fac; + for (k = 0; k < Dim; k++) + Material[k * Dim + k] = fac; - //Global Velocity - double velocity[3] = {0.,0.,0.}; - gp_ele->getIPvalue_vec_phase(ip, 0, velocity); //gp velocities // SB + // Global Velocity + double velocity[3] = {0., 0., 0.}; + gp_ele->getIPvalue_vec_phase(ip, 0, velocity); // gp velocities // SB vg = MBtrgVec(velocity, 3); alpha_l = mass_dispersion_longitudinal; alpha_t = mass_dispersion_transverse; // hard stabilization - if(this->lgpn > 0.0) + if (this->lgpn > 0.0) { MeshLib::CElem* m_ele = NULL; m_ele = m_pcs->m_msh->ele_vector[index]; - if(eleType == 2) + if (eleType == 2) l_char = sqrt(m_ele->GetVolume()); - if(eleType == 4) + if (eleType == 4) l_char = sqrt(m_ele->GetVolume()); // cout << " Element number: " << index << ", Volume: " << m_ele->GetVolume() << ", l_char: " << l_char << endl; set = 0; - if(alpha_l < l_char / lgpn) + if (alpha_l < l_char / lgpn) { - set = 1; //flag for output + set = 1; // flag for output alpha_l = l_char / lgpn; } - if(alpha_t < l_char / lgpn) + if (alpha_t < l_char / lgpn) { set = 1; alpha_t = l_char / lgpn; } - //cout << " alpha_L = " << alpha_l << " < l_char/Pe; setting alpha_L = " << l_char/lgpn << " for element " << index << endl; - if((set > 0) & (aktueller_zeitschritt == 1) & (CIndex < 2) & (ip < 1)) - std::cout << "element " << index << " " << l_char << " " << alpha_l << - " " << alpha_t << std::endl; + // cout << " alpha_L = " << alpha_l << " < l_char/Pe; setting alpha_L = " << l_char/lgpn << " for element " << + // index << endl; + if ((set > 0) & (aktueller_zeitschritt == 1) & (CIndex < 2) & (ip < 1)) + std::cout << "element " << index << " " << l_char << " " << alpha_l << " " << alpha_t << std::endl; } //---------------------------------------------------------------------- - if (abs(vg) > MKleinsteZahl && PCSIndex > 0) //For the case of diffusive transport only. + if (abs(vg) > MKleinsteZahl && PCSIndex > 0) // For the case of diffusive transport only. { switch (Dim) { - //-------------------------------------------------------------------- - case 1: - tensor[0] = Material[0] + alpha_l*vg*multiplier; - break; //-------------------------------------------------------------------- - case 2: - D[0] = (alpha_t*vg) + (alpha_l - alpha_t)*(velocity[0]*velocity[0])/vg; - D[1] = ((alpha_l - alpha_t)*(velocity[0]*velocity[1]))/vg; - D[2] = ((alpha_l - alpha_t)*(velocity[1]*velocity[0]))/vg; - D[3] = (alpha_t*vg) + (alpha_l - alpha_t)*(velocity[1]*velocity[1])/vg; - for (k = 0; k::const_iterator p_mat = db_mat_mp_list.begin(); - while(p_mat != db_mat_mp_list.end()) + while (p_mat != db_mat_mp_list.end()) { m_mat = *p_mat; - if(mat_name.compare(m_mat->name) == 0) + if (mat_name.compare(m_mat->name) == 0) return m_mat; ++p_mat; } @@ -3270,21 +3258,21 @@ CMediumProperties* CMediumProperties::GetDB(std::string mat_name) 02/2004 OK Implementation last modification: **************************************************************************/ -void CMediumProperties::SetDB(std::string mat_name,std::string prop_name,double value) +void CMediumProperties::SetDB(std::string mat_name, std::string prop_name, double value) { CMediumProperties* m_mat = NULL; m_mat = GetDB(mat_name); switch (GetPropertyType(prop_name)) { - case 0: - m_mat->conductivity = value; - break; - case 1: - m_mat->permeability = value; - break; - case 2: - m_mat->porosity = value; - break; + case 0: + m_mat->conductivity = value; + break; + case 1: + m_mat->permeability = value; + break; + case 2: + m_mat->porosity = value; + break; } } @@ -3300,13 +3288,12 @@ int CMediumProperties::GetPropertyType(std::string prop_name) int counter = 0; string keyword_name; list::const_iterator p_keywords = keywd_list.begin(); - while(p_keywords != keywd_list.end()) + while (p_keywords != keywd_list.end()) { keyword_name = *p_keywords; - if(prop_name.compare(keyword_name) == 0) + if (prop_name.compare(keyword_name) == 0) return counter; - ++p_keywords, - counter++; + ++p_keywords, counter++; } return -1; } @@ -3319,12 +3306,12 @@ std::string read_MAT_name(std::string in, std::string* z_rest_out) std::string mat_name; std::string z_rest; std::string delimiter(";"); - //wenn eine mg gefunden wird nach dem Schlüsselwort - if(in.find_first_not_of(delimiter) != std::string::npos) + // wenn eine mg gefunden wird nach dem Schlüsselwort + if (in.find_first_not_of(delimiter) != std::string::npos) { z_rest = in.substr(in.find_first_not_of(delimiter)); - //string für die erste (1) material group - mat_name = z_rest.substr(0,z_rest.find_first_of(delimiter)); + // string für die erste (1) material group + mat_name = z_rest.substr(0, z_rest.find_first_of(delimiter)); *z_rest_out = z_rest.substr(mat_name.length()); return mat_name; } @@ -3352,10 +3339,10 @@ void MATLoadDB(std::string csv_file_name) read_keywd_list(); //======================================================================== // File handling - ifstream csv_file(csv_file_name.data(),ios::in); + ifstream csv_file(csv_file_name.data(), ios::in); if (!csv_file.good()) return; - csv_file.seekg(0L,ios::beg); // rewind + csv_file.seekg(0L, ios::beg); // rewind //======================================================================== // Read MATERIALS group names comp_keywd_list(csv_file_name); @@ -3385,11 +3372,11 @@ void MATLoadDB(std::string csv_file_name) **************************************************************************/ void read_keywd_list(void) { - //File handling============================= - std::ifstream eingabe("mat_mp_keywords.dat",ios::in); + // File handling============================= + std::ifstream eingabe("mat_mp_keywords.dat", ios::in); if (eingabe.good()) { - eingabe.seekg(0L,ios::beg); + eingabe.seekg(0L, ios::beg); //========================================== std::string keyword("MATERIALS"); std::string in; @@ -3400,21 +3387,21 @@ void read_keywd_list(void) std::string keywd_tmp("KEYWD"); char line_char[MAX_ZEILE]; // Read MATERIALS group names - //1 get string with keywords + // 1 get string with keywords while (!eingabe.eof()) { eingabe.getline(line_char, MAX_ZEILE); line = line_char; - if(line.find_first_not_of(delimiter) != string::npos) + if (line.find_first_not_of(delimiter) != string::npos) { - //schneidet delimiter ab + // schneidet delimiter ab in = line.substr(line.find_first_not_of(delimiter)); - keywd_tmp = in.substr(0,in.find_first_of(delimiter)); + keywd_tmp = in.substr(0, in.find_first_of(delimiter)); keywd_list.push_back(keywd_tmp); } - //keywd_list.remove(keyword); - } // eof - } // if eingabe.good + // keywd_list.remove(keyword); + } // eof + } // if eingabe.good else printf("No keyword file: mat_mp_keywords.dat"); } @@ -3435,30 +3422,30 @@ void comp_keywd_list(std::string csv_file_name) std::string mat_name; std::string mat_name_tmp("MAT_NAME"); char line_char[MAX_ZEILE]; - std::string in1; //zwischenstring zum abschneiden der einheit + std::string in1; // zwischenstring zum abschneiden der einheit std::string delimiter(";"); std::string keyword("MATERIALS"); double kwvalue; - //File handling------------------------------------ + // File handling------------------------------------ std::string sp; - std::ifstream eingabe(csv_file_name.data(),ios::in); + std::ifstream eingabe(csv_file_name.data(), ios::in); if (eingabe.good()) { - eingabe.seekg(0L,ios::beg); //rewind um materialgruppen auszulesen + eingabe.seekg(0L, ios::beg); // rewind um materialgruppen auszulesen eingabe.getline(line_char, MAX_ZEILE); line = line_char; //----------------------------------------------- // 1 - read MAT names // ReadMATNames(csv_file_name); - if(line.find(mat_names) != string::npos) + if (line.find(mat_names) != string::npos) { in = line.substr(mat_names.length() + 1); // 2 Read material group names - while(!mat_name_tmp.empty()) + while (!mat_name_tmp.empty()) { - mat_name_tmp = read_MAT_name(in,&z_rest); - if(mat_name_tmp.empty()) + mat_name_tmp = read_MAT_name(in, &z_rest); + if (mat_name_tmp.empty()) break; else { @@ -3466,13 +3453,13 @@ void comp_keywd_list(std::string csv_file_name) mat_name_list.push_back(mat_name); in = z_rest; } - } // while mat_name - } // keyword found + } // while mat_name + } // keyword found //----------------------------------------------- // 2 - create MAT-SP instances CMediumProperties* m_mat_mp = NULL; list::const_iterator p_mat_names = mat_name_list.begin(); - while(p_mat_names != mat_name_list.end()) + while (p_mat_names != mat_name_list.end()) { mat_name = *p_mat_names; m_mat_mp = new CMediumProperties; @@ -3483,7 +3470,7 @@ void comp_keywd_list(std::string csv_file_name) //----------------------------------------------- // 3 - read MAT properties - //1 get string where keyword hits + // 1 get string where keyword hits CMediumProperties* m_mat_mp1 = NULL; while (!eingabe.eof()) { @@ -3491,34 +3478,32 @@ void comp_keywd_list(std::string csv_file_name) line = line_char; string sp; list::const_iterator pm = keywd_list.begin(); - while(pm != keywd_list.end()) + while (pm != keywd_list.end()) { sp = *pm; - if(line.find(sp) != string::npos) + if (line.find(sp) != string::npos) { - //schneidet keyword ab - in1 = line.substr(line.find_first_not_of( - delimiter) + sp.length() + 1); - //schneidet keyword ab + // schneidet keyword ab + in1 = line.substr(line.find_first_not_of(delimiter) + sp.length() + 1); + // schneidet keyword ab in = in1.substr(in1.find_first_of(delimiter)); - //Schleife über alle MAT-Gruppen - list::const_iterator p_mat_names = - mat_name_list.begin(); - while(p_mat_names != mat_name_list.end()) + // Schleife über alle MAT-Gruppen + list::const_iterator p_mat_names = mat_name_list.begin(); + while (p_mat_names != mat_name_list.end()) { mat_name = *p_mat_names; m_mat_mp1 = m_mat_mp1->GetDB(mat_name); - mat_name_tmp = read_MAT_name(in,&z_rest); + mat_name_tmp = read_MAT_name(in, &z_rest); kwvalue = atof(mat_name_tmp.data()); - //Val = strtod(pDispInfo->item.strText, NULL); - m_mat_mp1->SetDB(mat_name,sp,kwvalue); + // Val = strtod(pDispInfo->item.strText, NULL); + m_mat_mp1->SetDB(mat_name, sp, kwvalue); ++p_mat_names; } } // ++pm; - } // kwlist - } // eof - } // if eingabe.good + } // kwlist + } // eof + } // if eingabe.good } ///************************************************************************************************* @@ -3549,7 +3534,7 @@ void CMediumProperties::SetMediumPropertiesDefaultsClay(void) geo_area = 1.0; porosity = 0.4; tortuosity = 1.0; - storage = 1.5e-10; //m/pa + storage = 1.5e-10; // m/pa for (i = 0; i < 9; i++) permeability_tensor[i] = 1.e-17; heat_dispersion_longitudinal = 0.01; @@ -3583,8 +3568,8 @@ void CMediumProperties::SetMediumPropertiesDefaultsSilt(void) geo_area = 1.0; porosity = 0.4; tortuosity = 1.0; - storage = 5.e-7; //m/pa - //m² + storage = 5.e-7; // m/pa + // m² for (i = 0; i < 9; i++) permeability_tensor[i] = 1.e-14; heat_dispersion_longitudinal = 0.01; @@ -3617,8 +3602,8 @@ void CMediumProperties::SetMediumPropertiesDefaultsSand(void) geo_area = 1.0; porosity = 0.3; tortuosity = 1.0; - storage = 5.e-8; //m/pa - //m² + storage = 5.e-8; // m/pa + // m² for (i = 0; i < 9; i++) permeability_tensor[i] = 1.e-11; heat_dispersion_longitudinal = 0.01; @@ -3652,8 +3637,8 @@ void CMediumProperties::SetMediumPropertiesDefaultsGravel(void) geo_area = 1.0; porosity = 0.32; tortuosity = 1.0; - storage = 5.e-9; //m/pa - //m² + storage = 5.e-9; // m/pa + // m² for (i = 0; i < 9; i++) permeability_tensor[i] = 1.e-9; heat_dispersion_longitudinal = 0.01; @@ -3686,8 +3671,8 @@ void CMediumProperties::SetMediumPropertiesDefaultsCrystalline(void) geo_area = 1.0; porosity = 0.05; tortuosity = 1.0; - storage = 5.e-11; //m/pa - //m² + storage = 5.e-11; // m/pa + // m² for (i = 0; i < 9; i++) permeability_tensor[i] = 1.e-14; heat_dispersion_longitudinal = 0.01; @@ -3720,8 +3705,8 @@ void CMediumProperties::SetMediumPropertiesDefaultsBordenAquifer(void) geo_area = 1.0; porosity = 0.10; tortuosity = 1.0; - storage = 5.e-11; //m/pa - //m² + storage = 5.e-11; // m/pa + // m² for (i = 0; i < 9; i++) permeability_tensor[i] = 1.e-12; heat_dispersion_longitudinal = 0.01; @@ -3753,7 +3738,7 @@ void CMediumProperties::SetMediumPropertiesDefaultsBordenAquifer(void) 04/2007 WW Porosity by gauss stress value last modification: *************************************************************************/ -double CMediumProperties::Porosity(long number,double theta) +double CMediumProperties::Porosity(long number, double theta) { int nidx0, nidx1; double primary_variable[PCS_NUMBER_MAX]; @@ -3768,13 +3753,11 @@ double CMediumProperties::Porosity(long number,double theta) ElementValue_DM* gval = NULL; // CB Get idx of porosity in elements mat vector for het porosity - size_t por_index (0); + size_t por_index(0); if (porosity_model == 11) - for (por_index = 0; por_index - < m_pcs->m_msh->mat_names_vector.size(); por_index++) - if (m_pcs->m_msh->mat_names_vector[por_index].compare("POROSITY") - == 0) + for (por_index = 0; por_index < m_pcs->m_msh->mat_names_vector.size(); por_index++) + if (m_pcs->m_msh->mat_names_vector[por_index].compare("POROSITY") == 0) break; // Functional dependencies @@ -3784,33 +3767,30 @@ double CMediumProperties::Porosity(long number,double theta) for (size_t i = 0; i < no_pcs_names; i++) { str = porosity_pcs_name_vector[i]; - pcs_temp = PCSGet(str, true); //MX + pcs_temp = PCSGet(str, true); // MX nidx0 = pcs_temp->GetNodeValueIndex(porosity_pcs_name_vector[i]); nidx1 = nidx0 + 1; - if (mode == 0) // Gauss point values + if (mode == 0) // Gauss point values { assem->ComputeShapefct(1); - primary_variable[i] = (1. - theta) * assem->interpolate(nidx0, - pcs_temp) + - theta* assem->interpolate(nidx1, pcs_temp); - } // Node values + primary_variable[i] + = (1. - theta) * assem->interpolate(nidx0, pcs_temp) + theta * assem->interpolate(nidx1, pcs_temp); + } // Node values else if (mode == 1) - primary_variable[i] = (1. - theta) * pcs_temp->GetNodeValue(number, - nidx0) + - theta* pcs_temp->GetNodeValue(number, nidx1); + primary_variable[i] + = (1. - theta) * pcs_temp->GetNodeValue(number, nidx0) + theta * pcs_temp->GetNodeValue(number, nidx1); // Element average value else if (mode == 2) - primary_variable[i] = (1. - theta) * assem->elemnt_average(nidx0, - pcs_temp) + - theta* assem->elemnt_average(nidx1, pcs_temp); - else if(mode == 1) // Node values + primary_variable[i] = (1. - theta) * assem->elemnt_average(nidx0, pcs_temp) + + theta * assem->elemnt_average(nidx1, pcs_temp); + else if (mode == 1) // Node values - primary_variable[i] = (1. - theta) * pcs_temp->GetNodeValue(number,nidx0) \ - + theta* pcs_temp->GetNodeValue(number,nidx1); - else if(mode == 2) // Element average value + primary_variable[i] + = (1. - theta) * pcs_temp->GetNodeValue(number, nidx0) + theta * pcs_temp->GetNodeValue(number, nidx1); + else if (mode == 2) // Element average value - primary_variable[i] = (1. - theta) * assem->elemnt_average(nidx0,pcs_temp) - + theta* assem->elemnt_average(nidx1,pcs_temp); + primary_variable[i] = (1. - theta) * assem->elemnt_average(nidx0, pcs_temp) + + theta * assem->elemnt_average(nidx1, pcs_temp); } //---------------------------------------------------------------------- @@ -3841,109 +3821,103 @@ double CMediumProperties::Porosity(long number,double theta) */ switch (porosity_model) { - case 0: // n = f(x) - porosity = GetCurveValue(fct_number, 0, primary_variable[0], &gueltig); - break; - case 1: // n = const - porosity = porosity_model_values[0]; - break; - case 2: // n = f(sigma_eff), Stress dependance - porosity = PorosityEffectiveStress(number, primary_variable[0]); - break; - case 3: // n = f(S), Free chemical swelling - porosity = PorosityVolumetricFreeSwellingConstantIonicstrength(number, - primary_variable[0], - primary_variable[1]); - break; - case 4: // n = f(S), Constrained chemical swelling - porosity = PorosityEffectiveConstrainedSwellingConstantIonicStrength( - number, primary_variable[0], primary_variable[1], &porosity_sw); - break; - case 5: // n = f(S), Free chemical swelling, I const - porosity = PorosityVolumetricFreeSwelling(number, primary_variable[0], - primary_variable[1]); - break; - case 6: // n = f(S), Constrained chemical swelling, I const - porosity = PorosityEffectiveConstrainedSwelling(number, - primary_variable[0], - primary_variable[1], - &porosity_sw); - break; - case 7: // n = f(mean stress) WW - gval = ele_value_dm[number]; - primary_variable[0] = -gval->MeanStress(assem->gp) / 3.0; - porosity = GetCurveValue(porosity_curve, 0, primary_variable[0], - &gueltig); - break; - case 10: - /* porosity change through dissolution/precipitation */ - porosity = PorosityVolumetricChemicalReaction(number); - break; - case 11: // n = temp const, but spatially distributed CB - //porosity = porosity_model_values[0]; - porosity = _mesh->ele_vector[number]->mat_vector(por_index); - break; - case 12: // n = n0 + vol_strain, WX: 03.2011 - porosity = PorosityVolStrain(number, porosity_model_values[0], assem); - break; - case 13: - { - CRFProcess *m_pcs_flow = PCSGetFlow(); - const int idx_n = m_pcs_flow->GetElementValueIndex("POROSITY"); + case 0: // n = f(x) + porosity = GetCurveValue(fct_number, 0, primary_variable[0], &gueltig); + break; + case 1: // n = const + porosity = porosity_model_values[0]; + break; + case 2: // n = f(sigma_eff), Stress dependance + porosity = PorosityEffectiveStress(number, primary_variable[0]); + break; + case 3: // n = f(S), Free chemical swelling + porosity + = PorosityVolumetricFreeSwellingConstantIonicstrength(number, primary_variable[0], primary_variable[1]); + break; + case 4: // n = f(S), Constrained chemical swelling + porosity = PorosityEffectiveConstrainedSwellingConstantIonicStrength(number, primary_variable[0], + primary_variable[1], &porosity_sw); + break; + case 5: // n = f(S), Free chemical swelling, I const + porosity = PorosityVolumetricFreeSwelling(number, primary_variable[0], primary_variable[1]); + break; + case 6: // n = f(S), Constrained chemical swelling, I const + porosity + = PorosityEffectiveConstrainedSwelling(number, primary_variable[0], primary_variable[1], &porosity_sw); + break; + case 7: // n = f(mean stress) WW + gval = ele_value_dm[number]; + primary_variable[0] = -gval->MeanStress(assem->gp) / 3.0; + porosity = GetCurveValue(porosity_curve, 0, primary_variable[0], &gueltig); + break; + case 10: + /* porosity change through dissolution/precipitation */ + porosity = PorosityVolumetricChemicalReaction(number); + break; + case 11: // n = temp const, but spatially distributed CB + // porosity = porosity_model_values[0]; + porosity = _mesh->ele_vector[number]->mat_vector(por_index); + break; + case 12: // n = n0 + vol_strain, WX: 03.2011 + porosity = PorosityVolStrain(number, porosity_model_values[0], assem); + break; + case 13: + { + CRFProcess* m_pcs_flow = PCSGetFlow(); + const int idx_n = m_pcs_flow->GetElementValueIndex("POROSITY"); - // porosity change through dissolution/precipitation - // Here, you should access porosity from the element value vector of the flow process - // so you have to get the index of porosity above, if porosity model = 13 - porosity = m_pcs_flow->GetElementValue(number, idx_n+1); - break; - } + // porosity change through dissolution/precipitation + // Here, you should access porosity from the element value vector of the flow process + // so you have to get the index of porosity above, if porosity model = 13 + porosity = m_pcs_flow->GetElementValue(number, idx_n + 1); + break; + } #ifdef GEM_REACT - case 15: - porosity = porosity_model_values[0]; // default value as backup + case 15: + porosity = porosity_model_values[0]; // default value as backup - for (size_t i = 0; i < pcs_vector.size(); i++) - // if ((pcs_vector[i]->pcs_type_name.find("FLOW") != string::npos)) { - if (isFlowProcess(pcs_vector[i]->getProcessType())) - { - idx = pcs_vector[i]->GetElementValueIndex ( "POROSITY" ); - porosity = pcs_vector[i]->GetElementValue(number, idx + 1); // always return new/actual value - if (porosity < 0.0 || porosity > 1.0) + for (size_t i = 0; i < pcs_vector.size(); i++) + // if ((pcs_vector[i]->pcs_type_name.find("FLOW") != string::npos)) { + if (isFlowProcess(pcs_vector[i]->getProcessType())) { - cout << - "Porosity: error getting porosity for model 15. porosity: " - << porosity << " at node " << number << "\n"; - porosity = porosity_model_values[0]; + idx = pcs_vector[i]->GetElementValueIndex("POROSITY"); + porosity = pcs_vector[i]->GetElementValue(number, idx + 1); // always return new/actual value + if (porosity < 0.0 || porosity > 1.0) + { + cout << "Porosity: error getting porosity for model 15. porosity: " << porosity << " at node " + << number << "\n"; + porosity = porosity_model_values[0]; + } } - } - break; + break; #endif #ifdef BRNS - case 16: - porosity = porosity_model_values[0]; // default value as backup - if ( aktueller_zeitschritt > 1 ) - for (size_t i = 0; i < pcs_vector.size(); i++) - { - pcs_temp = pcs_vector[i]; - // if ( pcs_temp->pcs_type_name.compare("GROUNDWATER_FLOW") == 0 || - // pcs_temp->pcs_type_name.compare("LIQUID_FLOW") == 0 ) { - if ( pcs_temp->getProcessType() == FiniteElement::GROUNDWATER_FLOW - || pcs_temp->getProcessType() == FiniteElement::LIQUID_FLOW) + case 16: + porosity = porosity_model_values[0]; // default value as backup + if (aktueller_zeitschritt > 1) + for (size_t i = 0; i < pcs_vector.size(); i++) { - int idx; - idx = pcs_temp->GetElementValueIndex ( "POROSITY" ); + pcs_temp = pcs_vector[i]; + // if ( pcs_temp->pcs_type_name.compare("GROUNDWATER_FLOW") == 0 || + // pcs_temp->pcs_type_name.compare("LIQUID_FLOW") == 0 ) { + if (pcs_temp->getProcessType() == FiniteElement::GROUNDWATER_FLOW + || pcs_temp->getProcessType() == FiniteElement::LIQUID_FLOW) + { + int idx; + idx = pcs_temp->GetElementValueIndex("POROSITY"); - porosity = pcs_temp->GetElementValue(number, idx); - if (porosity < 1.e-6) - cout << "error for porosity1 " << porosity << - " node " << number << "\n"; + porosity = pcs_temp->GetElementValue(number, idx); + if (porosity < 1.e-6) + cout << "error for porosity1 " << porosity << " node " << number << "\n"; + } } - } - break; + break; #endif - default: - cout << "Unknown porosity model!" << "\n"; - break; + default: + cout << "Unknown porosity model!" + << "\n"; + break; } return porosity; } @@ -3969,137 +3943,128 @@ double CMediumProperties::Porosity(long number,double theta) 04/2007 WW Porosity by gauss stress value last modification: *************************************************************************/ -//WW +// WW double CMediumProperties::Porosity(CElement* assem) { - static int nidx0,nidx1, idx_n; + static int nidx0, nidx1, idx_n; double primary_variable[PCS_NUMBER_MAX]; int gueltig; double porosity_sw, theta; std::string str; /// ElementValue_DM* gval = NULL; - CFiniteElementStd* assem_tmp = m_pcs->GetAssember(); //WX: for poro vol strain. 03.2011 + CFiniteElementStd* assem_tmp = m_pcs->GetAssember(); // WX: for poro vol strain. 03.2011 //---------------------------------------------------------------------- // Functional dependencies number = assem->GetElementIndex(); CRFProcess* pcs_temp; - CRFProcess *m_pcs_flow; + CRFProcess* m_pcs_flow; - const size_t no_pcs_names (porosity_pcs_name_vector.size()); - for(size_t i = 0; i < no_pcs_names; i++) + const size_t no_pcs_names(porosity_pcs_name_vector.size()); + for (size_t i = 0; i < no_pcs_names; i++) { str = porosity_pcs_name_vector[i]; - pcs_temp = PCSGet(str, true); //MX - theta = pcs_temp->m_num->ls_theta; //WW + pcs_temp = PCSGet(str, true); // MX + theta = pcs_temp->m_num->ls_theta; // WW nidx0 = pcs_temp->GetNodeValueIndex(porosity_pcs_name_vector[i]); nidx1 = nidx0 + 1; - if(mode == 0) // Gauss point values + if (mode == 0) // Gauss point values { assem->ComputeShapefct(1); - primary_variable[i] = (1. - theta) * assem->interpolate(nidx0,pcs_temp) - + theta* assem->interpolate(nidx1,pcs_temp); + primary_variable[i] + = (1. - theta) * assem->interpolate(nidx0, pcs_temp) + theta * assem->interpolate(nidx1, pcs_temp); } - else if(mode == 1) // Node values + else if (mode == 1) // Node values - primary_variable[i] = (1. - theta) * pcs_temp->GetNodeValue(number,nidx0) \ - + theta* pcs_temp->GetNodeValue(number,nidx1); - else if(mode == 2) // Element average value + primary_variable[i] + = (1. - theta) * pcs_temp->GetNodeValue(number, nidx0) + theta * pcs_temp->GetNodeValue(number, nidx1); + else if (mode == 2) // Element average value - primary_variable[i] = (1. - theta) * assem->elemnt_average(nidx0,pcs_temp) - + theta* assem->elemnt_average(nidx1,pcs_temp); + primary_variable[i] = (1. - theta) * assem->elemnt_average(nidx0, pcs_temp) + + theta * assem->elemnt_average(nidx1, pcs_temp); } //---------------------------------------------------------------------- // Material models switch (porosity_model) { - case 0: // n = f(x) - porosity = GetCurveValue(fct_number,0,primary_variable[0],&gueltig); - break; - case 1: // n = const - porosity = porosity_model_values[0]; - break; - case 2: // n = f(sigma_eff), Stress dependance - porosity = PorosityEffectiveStress(number,primary_variable[0]); - break; - case 3: // n = f(S), Free chemical swelling - porosity = PorosityVolumetricFreeSwellingConstantIonicstrength(number, - primary_variable[0], - primary_variable[1]); - break; - case 4: // n = f(S), Constrained chemical swelling - porosity = PorosityEffectiveConstrainedSwellingConstantIonicStrength( - number, - primary_variable - [0], - primary_variable - [1], - &porosity_sw); - break; - case 5: // n = f(S), Free chemical swelling, I const - porosity = PorosityVolumetricFreeSwelling(number, - primary_variable[0], - primary_variable[1]); - break; - case 6: // n = f(S), Constrained chemical swelling, I const - porosity = PorosityEffectiveConstrainedSwelling(number, - primary_variable[0], - primary_variable[1], - &porosity_sw); - break; - case 7: // n = f(mean stress) WW - gval = ele_value_dm[number]; - primary_variable[0] = -gval->MeanStress(assem->GetGPindex()) / 3.0; - porosity = GetCurveValue(porosity_curve,0,primary_variable[0],&gueltig); - break; - case 10: - /* porosity change through dissolution/precipitation */ - porosity = PorosityVolumetricChemicalReaction(number); - break; - case 11: // n = const, but spatially distributed CB - porosity = porosity_model_values[0]; - break; - case 12: // n = n0 + vol_strain - porosity = PorosityVolStrain(number, porosity_model_values[0], assem_tmp); //WX:03.2011 - break; - case 13: - m_pcs_flow = PCSGetFlow(); - idx_n = m_pcs_flow->GetElementValueIndex("POROSITY"); - porosity = m_pcs_flow->GetElementValue(number, idx_n+1); - break; + case 0: // n = f(x) + porosity = GetCurveValue(fct_number, 0, primary_variable[0], &gueltig); + break; + case 1: // n = const + porosity = porosity_model_values[0]; + break; + case 2: // n = f(sigma_eff), Stress dependance + porosity = PorosityEffectiveStress(number, primary_variable[0]); + break; + case 3: // n = f(S), Free chemical swelling + porosity + = PorosityVolumetricFreeSwellingConstantIonicstrength(number, primary_variable[0], primary_variable[1]); + break; + case 4: // n = f(S), Constrained chemical swelling + porosity = PorosityEffectiveConstrainedSwellingConstantIonicStrength(number, primary_variable[0], + primary_variable[1], &porosity_sw); + break; + case 5: // n = f(S), Free chemical swelling, I const + porosity = PorosityVolumetricFreeSwelling(number, primary_variable[0], primary_variable[1]); + break; + case 6: // n = f(S), Constrained chemical swelling, I const + porosity + = PorosityEffectiveConstrainedSwelling(number, primary_variable[0], primary_variable[1], &porosity_sw); + break; + case 7: // n = f(mean stress) WW + gval = ele_value_dm[number]; + primary_variable[0] = -gval->MeanStress(assem->GetGPindex()) / 3.0; + porosity = GetCurveValue(porosity_curve, 0, primary_variable[0], &gueltig); + break; + case 10: + /* porosity change through dissolution/precipitation */ + porosity = PorosityVolumetricChemicalReaction(number); + break; + case 11: // n = const, but spatially distributed CB + porosity = porosity_model_values[0]; + break; + case 12: // n = n0 + vol_strain + porosity = PorosityVolStrain(number, porosity_model_values[0], assem_tmp); // WX:03.2011 + break; + case 13: + m_pcs_flow = PCSGetFlow(); + idx_n = m_pcs_flow->GetElementValueIndex("POROSITY"); + porosity = m_pcs_flow->GetElementValue(number, idx_n + 1); + break; #ifdef GEM_REACT - case 15: + case 15: - porosity = porosity_model_values[0]; // default value as backup + porosity = porosity_model_values[0]; // default value as backup - // CRFProcess* mf_pcs = NULL; - for (size_t i = 0; i < pcs_vector.size(); i++) - { - pcs_temp = pcs_vector[i]; - // if ((pcs_temp->pcs_type_name.compare("GROUNDWATER_FLOW") == 0) || (pcs_temp->pcs_type_name.compare("RICHARDS_FLOW") == 0)||(pcs_temp->pcs_type_name.compare("MULTI_PHASE_FLOW") == 0)) - if ( (pcs_temp->getProcessType() == FiniteElement::GROUNDWATER_FLOW) - || (pcs_temp->getProcessType() == FiniteElement::RICHARDS_FLOW) - // TF - || (pcs_temp->getProcessType() == FiniteElement::MULTI_PHASE_FLOW) ) + // CRFProcess* mf_pcs = NULL; + for (size_t i = 0; i < pcs_vector.size(); i++) { - int idx = pcs_temp->GetElementValueIndex ( "POROSITY" ); - porosity = pcs_temp->GetElementValue(number, idx); - if (porosity < 1.e-6 || porosity > 1.0) + pcs_temp = pcs_vector[i]; + // if ((pcs_temp->pcs_type_name.compare("GROUNDWATER_FLOW") == 0) || + //(pcs_temp->pcs_type_name.compare("RICHARDS_FLOW") == + // 0)||(pcs_temp->pcs_type_name.compare("MULTI_PHASE_FLOW") == 0)) + if ((pcs_temp->getProcessType() == FiniteElement::GROUNDWATER_FLOW) + || (pcs_temp->getProcessType() == FiniteElement::RICHARDS_FLOW) + // TF + || (pcs_temp->getProcessType() == FiniteElement::MULTI_PHASE_FLOW)) { - std:: cout << " error getting porosity model 15 " << - porosity << " node " << number << "\n"; - porosity = porosity_model_values[0]; + int idx = pcs_temp->GetElementValueIndex("POROSITY"); + porosity = pcs_temp->GetElementValue(number, idx); + if (porosity < 1.e-6 || porosity > 1.0) + { + std::cout << " error getting porosity model 15 " << porosity << " node " << number << "\n"; + porosity = porosity_model_values[0]; + } } } - } - // KG44: TODO!!!!!!!!!!!!! check the above *************** - break; + // KG44: TODO!!!!!!!!!!!!! check the above *************** + break; #endif - default: - DisplayMsgLn("Unknown porosity model!"); - break; + default: + DisplayMsgLn("Unknown porosity model!"); + break; } //---------------------------------------------------------------------- return porosity; @@ -4112,21 +4077,18 @@ double CMediumProperties::Porosity(CElement* assem) 05/2005 MX Implementation last modification: **************************************************************************/ -double CMediumProperties::PorosityEffectiveConstrainedSwellingConstantIonicStrength( - long index, - double - saturation, - double temperature, - double* porosity_sw) +double CMediumProperties::PorosityEffectiveConstrainedSwellingConstantIonicStrength(long index, + double saturation, + double temperature, + double* porosity_sw) { - porosity_sw = porosity_sw; // WW Remove this argument + porosity_sw = porosity_sw; // WW Remove this argument /* Soil Properties */ double mat_mp_m, beta; double porosity = 0.0; - //WW static double theta; - double porosity_n, porosity_IL, d_porosity, \ - density_rock, fmon, porosity_max; + // WW static double theta; + double porosity_n, porosity_IL, d_porosity, density_rock, fmon, porosity_max; double n_sw, det_n_sw; double old_value, new_value; static double porosity_IP0; @@ -4139,52 +4101,51 @@ double CMediumProperties::PorosityEffectiveConstrainedSwellingConstantIonicStren static double F_const = 96484.6, epsilon_0 = 8.854e-12; static double R = 8.314510, psi = 1.0; /* Fluid properies */ - //WW int phase=1; + // WW int phase=1; //-------------------------------------------------------------------- // MMP medium properties - S_0 = porosity_model_values[1]; // Specific surface area [m^2/g] - fmon = porosity_model_values[2]; // Anteil quelfaehige mineral [-] - mat_mp_m = porosity_model_values[3]; // Schichtenanzahl eines quellfähigen Partikels [-] - beta = porosity_model_values[6]; // modifications coefficient (z.B. free swelling Weimar beta=3.0) + S_0 = porosity_model_values[1]; // Specific surface area [m^2/g] + fmon = porosity_model_values[2]; // Anteil quelfaehige mineral [-] + mat_mp_m = porosity_model_values[3]; // Schichtenanzahl eines quellfähigen Partikels [-] + beta = porosity_model_values[6]; // modifications coefficient (z.B. free swelling Weimar beta=3.0) //-------------------------------------------------------------------- // MSP solid properties SolidProp::CSolidProperties* m_msp = NULL; // long group = ElGetElementGroupNumber(index); long group = m_pcs->m_msh->ele_vector[index]->GetPatchIndex(); m_msp = msp_vector[group]; - density_rock = fabs(m_msp->Density(1)); + density_rock = fabs(m_msp->Density(1)); //-------------------------------------------------------------------- /* Component Properties */ ion_strength = porosity_model_values[4]; /*Ionic strength [M]*/ - satu_0 = porosity_model_values[5]; /*Initial saturation, if the sample is homogenous [-]*/ + satu_0 = porosity_model_values[5]; /*Initial saturation, if the sample is homogenous [-]*/ porosity_min = porosity_model_values[7]; /*minimal porosity after swelling compaction*/ /* Field v0ariables */ - //WW theta = m_pcs->m_num->ls_theta; - //WW phase=1; - satu = saturation; /*only for fluid, phase=1*/ + // WW theta = m_pcs->m_num->ls_theta; + // WW phase=1; + satu = saturation; /*only for fluid, phase=1*/ /*-----------------------------------------------------------------------*/ /* Interlayer Porositaet berechnen */ if (temperature < 0.0 || temperature > 600.0) - temperature = 298.0; //ToDo, MX + temperature = 298.0; // ToDo, MX epsilon = 87.0 + exp(-0.00456 * (temperature - 273.0)); porosity_n = porosity_model_values[0]; /* Maximal inter layer porosity */ - porosity_max = fmon * psi * mat_mp_m * S_0 * (density_rock * 1.0e3) \ - * sqrt(epsilon * epsilon_0 * R * temperature / - (2000.0 * F_const * F_const * ion_strength )); + porosity_max = fmon * psi * mat_mp_m * S_0 * (density_rock * 1.0e3) + * sqrt(epsilon * epsilon_0 * R * temperature / (2000.0 * F_const * F_const * ion_strength)); d_porosity = porosity_max * (pow(satu, beta) - pow(satu_0, beta)); /*-----------Interlayer porosity calculation------------------*/ /* porosity_IL = porosity_IL*satu; */ - porosity_IL = porosity_max * pow(satu,beta); + porosity_IL = porosity_max * pow(satu, beta); // ElSetElementVal(index,PCSGetELEValueIndex("POROSITY_IL"),porosity_IL); - m_pcs->SetElementValue(index, m_pcs->GetElementValueIndex("POROSITY_IL") + 1,porosity_IL); + m_pcs->SetElementValue(index, m_pcs->GetElementValueIndex("POROSITY_IL") + 1, porosity_IL); /*-----------Effective porosity calculation------------------*/ @@ -4194,46 +4155,46 @@ double CMediumProperties::PorosityEffectiveConstrainedSwellingConstantIonicStren porosity = porosity_min; // ElSetElementVal(index,PCSGetELEValueIndex("POROSITY"),porosity); - m_pcs->SetElementValue(index, m_pcs->GetElementValueIndex("POROSITY") + 1,porosity); + m_pcs->SetElementValue(index, m_pcs->GetElementValueIndex("POROSITY") + 1, porosity); /*-----------Swelling strain rate, xie, wang and Kolditz, (23)------------------*/ - porosity_IP0 = porosity_n - porosity_max* pow(satu_0,beta); + porosity_IP0 = porosity_n - porosity_max * pow(satu_0, beta); n_sw = d_porosity - (porosity_IP0 - porosity_min); if (n_sw <= 0.0) n_sw = 0.0; - int indx_sw0 = m_pcs->GetElementValueIndex("n_sw"); + int indx_sw0 = m_pcs->GetElementValueIndex("n_sw"); int indx_sw1 = indx_sw0 + 1; - if ( aktuelle_zeit == dt) + if (aktuelle_zeit == dt) { - m_pcs->SetElementValue(index,indx_sw0,n_sw); - m_pcs->SetElementValue(index,indx_sw1,n_sw); + m_pcs->SetElementValue(index, indx_sw0, n_sw); + m_pcs->SetElementValue(index, indx_sw1, n_sw); } - if ( aktuelle_zeit >= 2 * dt) - m_pcs->SetElementValue(index,indx_sw1,n_sw); + if (aktuelle_zeit >= 2 * dt) + m_pcs->SetElementValue(index, indx_sw1, n_sw); - old_value = m_pcs->GetElementValue(index,indx_sw0); - new_value = m_pcs->GetElementValue(index,indx_sw1); + old_value = m_pcs->GetElementValue(index, indx_sw0); + new_value = m_pcs->GetElementValue(index, indx_sw1); - if ( index == 399 && aktuelle_zeit == 10 * dt) + if (index == 399 && aktuelle_zeit == 10 * dt) - index = index; //only for debug + index = index; // only for debug // change rate of swelling strain det_n_sw = new_value - old_value; if (det_n_sw < -1.0e-8) det_n_sw = det_n_sw; - if ( aktuelle_zeit == dt) - m_pcs->SetElementValue(index, m_pcs->GetElementValueIndex("n_sw_rate"),det_n_sw); - m_pcs->SetElementValue(index, m_pcs->GetElementValueIndex("n_sw_rate") + 1,det_n_sw); + if (aktuelle_zeit == dt) + m_pcs->SetElementValue(index, m_pcs->GetElementValueIndex("n_sw_rate"), det_n_sw); + m_pcs->SetElementValue(index, m_pcs->GetElementValueIndex("n_sw_rate") + 1, det_n_sw); return porosity; } //------------------------------------------------------------------------ -//4..TORTUOSITY +// 4..TORTUOSITY //------------------------------------------------------------------------ /* 4B.4.3 non-linear flow */ @@ -4261,8 +4222,8 @@ double* CMediumProperties::PermeabilityTensor(long index) int idx_k, idx_n; double /*k_old, n_old,*/ k_new, n_new, k_rel, n_rel; CRFProcess* m_pcs_tmp(NULL); - if ((permeability_model==8) && (porosity_model==13)) - m_pcs_tmp = PCSGetFlow(); + if ((permeability_model == 8) && (porosity_model == 13)) + m_pcs_tmp = PCSGetFlow(); // HS: move the following loop into the "if ( permeability_tensor_type == 0 )" scope.---- // this is not necessary for in-isotropic case; @@ -4277,35 +4238,33 @@ double* CMediumProperties::PermeabilityTensor(long index) // value in permability_model. for 3 and 4, it gets the values from K-C relationship. // this will only influence then case when permeability_tensor_type = 0 // ------------------------------------------------------------------------------------------------------- - if ( permeability_tensor_type == 0 ) - { // only when permeability is isotropic + if (permeability_tensor_type == 0) + { // only when permeability is isotropic tensor[0] = permeability_tensor[0]; - if( permeability_model == 2 ) - { // here get the initial permeability values from material perperty class; + if (permeability_model == 2) + { // here get the initial permeability values from material perperty class; // get the index:------------------------------------------------------------------- - for(perm_index = 0; perm_index < (int)m_pcs->m_msh->mat_names_vector.size(); - perm_index++) - if(m_pcs->m_msh->mat_names_vector[perm_index].compare( - "PERMEABILITY") == 0) + for (perm_index = 0; perm_index < (int)m_pcs->m_msh->mat_names_vector.size(); perm_index++) + if (m_pcs->m_msh->mat_names_vector[perm_index].compare("PERMEABILITY") == 0) break; // end of getting the index--------------------------------------------------------- tensor[0] = _mesh->ele_vector[index]->mat_vector(perm_index); - //CMCD - //01.09.2011 WW. int edx = m_pcs->GetElementValueIndex("PERMEABILITY"); - //CMCD - //01.09.2011 WW. m_pcs->SetElementValue(index,edx,tensor[0]); + // CMCD + // 01.09.2011 WW. int edx = m_pcs->GetElementValueIndex("PERMEABILITY"); + // CMCD + // 01.09.2011 WW. m_pcs->SetElementValue(index,edx,tensor[0]); } - else if ( permeability_model == 3 ) - { // HS: 11.2008, for K-C relationship + else if (permeability_model == 3) + { // HS: 11.2008, for K-C relationship k_new = tensor[0]; CRFProcess* pcs_tmp(NULL); for (size_t i = 0; i < pcs_vector.size(); i++) { pcs_tmp = pcs_vector[i]; - if ( pcs_tmp->getProcessType () == FiniteElement::GROUNDWATER_FLOW || - pcs_tmp->getProcessType () == FiniteElement::LIQUID_FLOW || - pcs_tmp->getProcessType () == FiniteElement::RICHARDS_FLOW) + if (pcs_tmp->getProcessType() == FiniteElement::GROUNDWATER_FLOW + || pcs_tmp->getProcessType() == FiniteElement::LIQUID_FLOW + || pcs_tmp->getProcessType() == FiniteElement::RICHARDS_FLOW) break; } // get indexes @@ -4313,40 +4272,38 @@ double* CMediumProperties::PermeabilityTensor(long index) idx_n = pcs_tmp->GetElementValueIndex("POROSITY"); // get values of k0, n0, and n. - k_new = pcs_tmp->GetElementValue( index, idx_k + 1 ); - n_new = pcs_tmp->GetElementValue( index, idx_n + 1 ); + k_new = pcs_tmp->GetElementValue(index, idx_k + 1); + n_new = pcs_tmp->GetElementValue(index, idx_n + 1); // if first time step, get the k_new from material class - if ( aktueller_zeitschritt == 1) // for the first time step..... + if (aktueller_zeitschritt == 1) // for the first time step..... { // get the permeability. -// KC_permeability_initial = k_new = tensor[0]; -// KC_porosity_initial = n_new; + // KC_permeability_initial = k_new = tensor[0]; + // KC_porosity_initial = n_new; } // save old permeability - pcs_tmp->SetElementValue( index, idx_k, k_new ); + pcs_tmp->SetElementValue(index, idx_k, k_new); // calculate new permeability - k_new = CMediumProperties::KozenyCarman( KC_permeability_initial, - KC_porosity_initial, - n_new ); + k_new = CMediumProperties::KozenyCarman(KC_permeability_initial, KC_porosity_initial, n_new); // save new permeability - pcs_tmp->SetElementValue( index, idx_k + 1, k_new ); + pcs_tmp->SetElementValue(index, idx_k + 1, k_new); // now gives the newly calculated value to tensor[] tensor[0] = k_new; } - else if ( permeability_model == 4 ) - { // HS: 11.2008, for K-C_normalized relationship - k_new=tensor[0]; + else if (permeability_model == 4) + { // HS: 11.2008, for K-C_normalized relationship + k_new = tensor[0]; CRFProcess* pcs_tmp(NULL); for (size_t i = 0; i < pcs_vector.size(); i++) { pcs_tmp = pcs_vector[i]; - if ( pcs_tmp->getProcessType () == FiniteElement::GROUNDWATER_FLOW || - pcs_tmp->getProcessType () == FiniteElement::LIQUID_FLOW || - pcs_tmp->getProcessType () == FiniteElement::RICHARDS_FLOW) + if (pcs_tmp->getProcessType() == FiniteElement::GROUNDWATER_FLOW + || pcs_tmp->getProcessType() == FiniteElement::LIQUID_FLOW + || pcs_tmp->getProcessType() == FiniteElement::RICHARDS_FLOW) break; } // get indexes @@ -4354,41 +4311,39 @@ double* CMediumProperties::PermeabilityTensor(long index) idx_n = pcs_tmp->GetElementValueIndex("POROSITY"); // get values of k0, n0, and n. - k_new = pcs_tmp->GetElementValue( index, idx_k + 1 ); - n_new = pcs_tmp->GetElementValue( index, idx_n + 1 ); + k_new = pcs_tmp->GetElementValue(index, idx_k + 1); + n_new = pcs_tmp->GetElementValue(index, idx_n + 1); // if first time step, get the k_new from material class - if ( aktueller_zeitschritt == 1) // for the first time step..... + if (aktueller_zeitschritt == 1) // for the first time step..... { // get the permeability. -// KC_permeability_initial = k_new = tensor[0]; -// KC_porosity_initial = n_new; + // KC_permeability_initial = k_new = tensor[0]; + // KC_porosity_initial = n_new; } // save old permeability - pcs_tmp->SetElementValue( index, idx_k, k_new ); + pcs_tmp->SetElementValue(index, idx_k, k_new); // calculate new permeability - k_new = CMediumProperties::KozenyCarman_normalized( KC_permeability_initial, - KC_porosity_initial, - n_new ); + k_new = CMediumProperties::KozenyCarman_normalized(KC_permeability_initial, KC_porosity_initial, n_new); // save new permeability - pcs_tmp->SetElementValue( index, idx_k + 1, k_new ); + pcs_tmp->SetElementValue(index, idx_k + 1, k_new); // now gives the newly calculated value to tensor[] tensor[0] = k_new; } - else if ( permeability_model == 5 ) - { // HS: 11.2008, for Clement clogging model + else if (permeability_model == 5) + { // HS: 11.2008, for Clement clogging model // if first time step, do nothing. otherwise, - if ( aktueller_zeitschritt > 1 ) + if (aktueller_zeitschritt > 1) { CRFProcess* pcs_tmp(NULL); for (size_t i = 0; i < pcs_vector.size(); i++) { pcs_tmp = pcs_vector[i]; - if ( pcs_tmp->getProcessType () == FiniteElement::GROUNDWATER_FLOW || - pcs_tmp->getProcessType () == FiniteElement::LIQUID_FLOW) + if (pcs_tmp->getProcessType() == FiniteElement::GROUNDWATER_FLOW + || pcs_tmp->getProcessType() == FiniteElement::LIQUID_FLOW) break; } // get index @@ -4396,7 +4351,7 @@ double* CMediumProperties::PermeabilityTensor(long index) idx_n = pcs_tmp->GetElementValueIndex("POROSITY"); // get values of n. - n_new = pcs_tmp->GetElementValue( index, idx_n + 1 ); + n_new = pcs_tmp->GetElementValue(index, idx_n + 1); // calculate new permeability // k_rel(n) = n_rel^{19/6} @@ -4407,16 +4362,16 @@ double* CMediumProperties::PermeabilityTensor(long index) // finially permeability k_new = k_rel * permeability_porosity_model_values[1]; // save new permeability - m_pcs->SetElementValue( index, idx_k + 1, k_new ); + m_pcs->SetElementValue(index, idx_k + 1, k_new); // now gives the newly calculated value to tensor[] tensor[0] = k_new; } } - else if ( permeability_model == 6 ) - { // HS: 11.2008, for Clement biomass colony clogging + else if (permeability_model == 6) + { // HS: 11.2008, for Clement biomass colony clogging // if first time step, do nothing. otherwise, - if ( aktueller_zeitschritt > 1 ) + if (aktueller_zeitschritt > 1) { CRFProcess* pcs_tmp(NULL); for (size_t i = 0; i < pcs_vector.size(); i++) @@ -4424,8 +4379,8 @@ double* CMediumProperties::PermeabilityTensor(long index) pcs_tmp = pcs_vector[i]; // if ( m_pcs_tmp->pcs_type_name.compare("GROUNDWATER_FLOW") == 0 || // m_pcs_tmp->pcs_type_name.compare("LIQUID_FLOW") == 0) TF - if ( pcs_tmp->getProcessType () == FiniteElement::GROUNDWATER_FLOW || - pcs_tmp->getProcessType () == FiniteElement::LIQUID_FLOW) + if (pcs_tmp->getProcessType() == FiniteElement::GROUNDWATER_FLOW + || pcs_tmp->getProcessType() == FiniteElement::LIQUID_FLOW) break; } // get index @@ -4433,7 +4388,7 @@ double* CMediumProperties::PermeabilityTensor(long index) idx_n = pcs_tmp->GetElementValueIndex("POROSITY"); // get values of n. - n_new = pcs_tmp->GetElementValue( index, idx_n + 1 ); + n_new = pcs_tmp->GetElementValue(index, idx_n + 1); // calculate new permeability // k_rel(n) = n_rel^{19/6} @@ -4441,22 +4396,26 @@ double* CMediumProperties::PermeabilityTensor(long index) n_rel = n_new / permeability_porosity_model_values[0]; // then relative permeability change - const double temp (( n_rel - permeability_porosity_model_values[0] ) / (1 - permeability_porosity_model_values[0])); - k_rel = permeability_porosity_model_values[2] * - MathLib::fastpow((n_rel - permeability_porosity_model_values[0] ) / (1 - permeability_porosity_model_values[0]),3) - + ( 1 - permeability_porosity_model_values[2] ) * temp * temp; + const double temp((n_rel - permeability_porosity_model_values[0]) + / (1 - permeability_porosity_model_values[0])); + k_rel = permeability_porosity_model_values[2] + * MathLib::fastpow((n_rel - permeability_porosity_model_values[0]) + / (1 - permeability_porosity_model_values[0]), + 3) + + (1 - permeability_porosity_model_values[2]) * temp * temp; // finially permeability k_new = k_rel * permeability_porosity_model_values[1]; // save new permeability - m_pcs->SetElementValue( index, idx_k + 1, k_new ); + m_pcs->SetElementValue(index, idx_k + 1, k_new); // now gives the newly calculated value to tensor[] tensor[0] = k_new; } } - else if ( permeability_model == 7 ) {// HS: 11.2008, for Clement biofilm clogging + else if (permeability_model == 7) + { // HS: 11.2008, for Clement biofilm clogging // if first time step, do nothing. otherwise, - if ( aktueller_zeitschritt > 1 ) + if (aktueller_zeitschritt > 1) { CRFProcess* pcs_tmp(NULL); for (size_t i = 0; i < pcs_vector.size(); i++) @@ -4464,8 +4423,8 @@ double* CMediumProperties::PermeabilityTensor(long index) pcs_tmp = pcs_vector[i]; // if ( m_pcs_tmp->pcs_type_name.compare("GROUNDWATER_FLOW") == 0 || // m_pcs_tmp->pcs_type_name.compare("LIQUID_FLOW") == 0) TF - if ( pcs_tmp->getProcessType() == FiniteElement::GROUNDWATER_FLOW || - pcs_tmp->getProcessType () == FiniteElement::LIQUID_FLOW) + if (pcs_tmp->getProcessType() == FiniteElement::GROUNDWATER_FLOW + || pcs_tmp->getProcessType() == FiniteElement::LIQUID_FLOW) break; } // get index @@ -4473,7 +4432,7 @@ double* CMediumProperties::PermeabilityTensor(long index) idx_n = pcs_tmp->GetElementValueIndex("POROSITY"); // get values of n. - n_new = pcs_tmp->GetElementValue( index, idx_n + 1 ); + n_new = pcs_tmp->GetElementValue(index, idx_n + 1); // calculate new permeability // k_rel(n) = n_rel^{19/6} @@ -4481,370 +4440,339 @@ double* CMediumProperties::PermeabilityTensor(long index) n_rel = n_new / permeability_porosity_model_values[0]; // then relative permeability change - k_rel = - (pow( ( n_rel - - permeability_porosity_model_values[0] ) / - (1 - permeability_porosity_model_values[0]), - permeability_porosity_model_values[2] ) \ - + permeability_porosity_model_values[3] ) / \ - ( 1 + permeability_porosity_model_values[3]); + k_rel = (pow((n_rel - permeability_porosity_model_values[0]) + / (1 - permeability_porosity_model_values[0]), + permeability_porosity_model_values[2]) + + permeability_porosity_model_values[3]) + / (1 + permeability_porosity_model_values[3]); // finially permeability k_new = k_rel * permeability_porosity_model_values[1]; // save new permeability - m_pcs->SetElementValue( index, idx_k + 1, k_new ); + m_pcs->SetElementValue(index, idx_k + 1, k_new); // now gives the newly calculated value to tensor[] tensor[0] = k_new; } } - else if((permeability_model==8)&&(porosity_model==13)) - { // ABM 11.2010 + else if ((permeability_model == 8) && (porosity_model == 13)) + { // ABM 11.2010 idx_k = m_pcs_tmp->GetElementValueIndex("PERMEABILITY"); - tensor[0] = m_pcs_tmp->GetElementValue( index, idx_k + 1 ); + tensor[0] = m_pcs_tmp->GetElementValue(index, idx_k + 1); } - // end of K-C relationship----------------------------------------------------------------------------------- + // end of K-C relationship----------------------------------------------------------------------------------- } - switch(geo_dimension) + switch (geo_dimension) { - case 1: // 1-D - // HS: tensor[0] already set, doing nothing here; - break; - case 2: // 2-D - if(permeability_tensor_type == 0) - { - // tensor[0] = permeability_tensor[0]; // HS: done already; - tensor[1] = 0.0; - tensor[2] = 0.0; - // tensor[3] = permeability_tensor[0]; - tensor[3] = tensor[0]; // HS: use the existing value; - - // HS: this is not needed any more-------------------------------- - // if(permeability_model==2) { - //SB 4218 tensor[0] = GetHetValue(index,"permeability"); - // tensor[0] = m_msh->ele_vector[index]->mat_vector(perm_index); - // tensor[3] = tensor[0]; - // } - // end of comment out section------------------------------------- - } - else if(permeability_tensor_type == 1) - { - if ((permeability_model == 8) && (porosity_model == 13)) - { // AB 11.2010 - idx_k = m_pcs_tmp->GetElementValueIndex("PERMEABILITY"); - tensor[0] = m_pcs_tmp->GetElementValue(index, idx_k + 1); + case 1: // 1-D + // HS: tensor[0] already set, doing nothing here; + break; + case 2: // 2-D + if (permeability_tensor_type == 0) + { + // tensor[0] = permeability_tensor[0]; // HS: done already; tensor[1] = 0.0; tensor[2] = 0.0; - idx_k = m_pcs_tmp->GetElementValueIndex("PERMEABILITY_YY"); - tensor[3] = m_pcs_tmp->GetElementValue(index, idx_k + 1); + // tensor[3] = permeability_tensor[0]; + tensor[3] = tensor[0]; // HS: use the existing value; + + // HS: this is not needed any more-------------------------------- + // if(permeability_model==2) { + // SB 4218 tensor[0] = GetHetValue(index,"permeability"); + // tensor[0] = m_msh->ele_vector[index]->mat_vector(perm_index); + // tensor[3] = tensor[0]; + // } + // end of comment out section------------------------------------- } - else + else if (permeability_tensor_type == 1) + { + if ((permeability_model == 8) && (porosity_model == 13)) + { // AB 11.2010 + idx_k = m_pcs_tmp->GetElementValueIndex("PERMEABILITY"); + tensor[0] = m_pcs_tmp->GetElementValue(index, idx_k + 1); + tensor[1] = 0.0; + tensor[2] = 0.0; + idx_k = m_pcs_tmp->GetElementValueIndex("PERMEABILITY_YY"); + tensor[3] = m_pcs_tmp->GetElementValue(index, idx_k + 1); + } + else + { + tensor[0] = permeability_tensor[0]; + tensor[1] = 0.0; + tensor[2] = 0.0; + tensor[3] = permeability_tensor[1]; + } + } + else if (permeability_tensor_type == 2) { tensor[0] = permeability_tensor[0]; - tensor[1] = 0.0; - tensor[2] = 0.0; - tensor[3] = permeability_tensor[1]; + tensor[1] = permeability_tensor[1]; + tensor[2] = permeability_tensor[2]; + tensor[3] = permeability_tensor[3]; } - } - else if(permeability_tensor_type == 2) - { - tensor[0] = permeability_tensor[0]; - tensor[1] = permeability_tensor[1]; - tensor[2] = permeability_tensor[2]; - tensor[3] = permeability_tensor[3]; - } - break; - case 3: // 3-D - if(permeability_tensor_type == 0) - { - // tensor[0] = permeability_tensor[0]; // HS: not needed. already done before - tensor[1] = 0.0; - tensor[2] = 0.0; - tensor[3] = 0.0; - // tensor[4] = permeability_tensor[0]; // HS: using the line below instead; - tensor[4] = tensor[0]; // using the existing value - tensor[5] = 0.0; - tensor[6] = 0.0; - tensor[7] = 0.0; - // tensor[8] = permeability_tensor[0]; // HS: using the line below instead; - tensor[8] = tensor[0]; // using the existing value - // HS: this is not needed any more-------------------------------- - // if(permeability_model==2) { - // SB 4218 tensor[0] = GetHetValue(index,"permeability"); - // tensor[0] = m_pcs->m_msh->ele_vector[index]->mat_vector(perm_index); - // tensor[4] = tensor[0]; - // tensor[8] = tensor[0]; - // } - // end of comment out section------------------------------------- - } - else if(permeability_tensor_type == 1) - { - if((permeability_model==8)&&(porosity_model==13)) - { // AB 11.2010 - idx_k = m_pcs_tmp->GetElementValueIndex("PERMEABILITY"); - tensor[0] = m_pcs_tmp->GetElementValue(index, idx_k + 1); + break; + case 3: // 3-D + if (permeability_tensor_type == 0) + { + // tensor[0] = permeability_tensor[0]; // HS: not needed. already done before tensor[1] = 0.0; tensor[2] = 0.0; tensor[3] = 0.0; - idx_k = m_pcs_tmp->GetElementValueIndex("PERMEABILITY_YY"); - tensor[4] = m_pcs_tmp->GetElementValue(index, idx_k + 1); + // tensor[4] = permeability_tensor[0]; // HS: using the line below instead; + tensor[4] = tensor[0]; // using the existing value tensor[5] = 0.0; tensor[6] = 0.0; tensor[7] = 0.0; - idx_k = m_pcs_tmp->GetElementValueIndex("PERMEABILITY_ZZ"); - tensor[8] = m_pcs_tmp->GetElementValue(index, idx_k + 1); + // tensor[8] = permeability_tensor[0]; // HS: using the line below instead; + tensor[8] = tensor[0]; // using the existing value + // HS: this is not needed any more-------------------------------- + // if(permeability_model==2) { + // SB 4218 tensor[0] = GetHetValue(index,"permeability"); + // tensor[0] = m_pcs->m_msh->ele_vector[index]->mat_vector(perm_index); + // tensor[4] = tensor[0]; + // tensor[8] = tensor[0]; + // } + // end of comment out section------------------------------------- } - else + else if (permeability_tensor_type == 1) + { + if ((permeability_model == 8) && (porosity_model == 13)) + { // AB 11.2010 + idx_k = m_pcs_tmp->GetElementValueIndex("PERMEABILITY"); + tensor[0] = m_pcs_tmp->GetElementValue(index, idx_k + 1); + tensor[1] = 0.0; + tensor[2] = 0.0; + tensor[3] = 0.0; + idx_k = m_pcs_tmp->GetElementValueIndex("PERMEABILITY_YY"); + tensor[4] = m_pcs_tmp->GetElementValue(index, idx_k + 1); + tensor[5] = 0.0; + tensor[6] = 0.0; + tensor[7] = 0.0; + idx_k = m_pcs_tmp->GetElementValueIndex("PERMEABILITY_ZZ"); + tensor[8] = m_pcs_tmp->GetElementValue(index, idx_k + 1); + } + else + { + tensor[0] = permeability_tensor[0]; + tensor[1] = 0.0; + tensor[2] = 0.0; + tensor[3] = 0.0; + tensor[4] = permeability_tensor[1]; + tensor[5] = 0.0; + tensor[6] = 0.0; + tensor[7] = 0.0; + tensor[8] = permeability_tensor[2]; + } + } + else if (permeability_tensor_type == 2) { tensor[0] = permeability_tensor[0]; - tensor[1] = 0.0; - tensor[2] = 0.0; - tensor[3] = 0.0; - tensor[4] = permeability_tensor[1]; - tensor[5] = 0.0; - tensor[6] = 0.0; - tensor[7] = 0.0; - tensor[8] = permeability_tensor[2]; + tensor[1] = permeability_tensor[1]; + tensor[2] = permeability_tensor[2]; + tensor[3] = permeability_tensor[3]; + tensor[4] = permeability_tensor[4]; + tensor[5] = permeability_tensor[5]; + tensor[6] = permeability_tensor[6]; + tensor[7] = permeability_tensor[7]; + tensor[8] = permeability_tensor[8]; } - } - else if(permeability_tensor_type == 2) - { - tensor[0] = permeability_tensor[0]; - tensor[1] = permeability_tensor[1]; - tensor[2] = permeability_tensor[2]; - tensor[3] = permeability_tensor[3]; - tensor[4] = permeability_tensor[4]; - tensor[5] = permeability_tensor[5]; - tensor[6] = permeability_tensor[6]; - tensor[7] = permeability_tensor[7]; - tensor[8] = permeability_tensor[8]; - } - break; + break; } return tensor; } //------------------------------------------------------------------------ -//12.(i) PERMEABILITY_FUNCTION_DEFORMATION +// 12.(i) PERMEABILITY_FUNCTION_DEFORMATION //------------------------------------------------------------------------ // //------------------------------------------------------------------------ -//12.(ii) PERMEABILITY_FUNCTION_PRESSURE +// 12.(ii) PERMEABILITY_FUNCTION_PRESSURE //------------------------------------------------------------------------ -//WX: implementation of ths permeability_function_pressure. 1. version only for multi_phase_flow. 05.2010 +// WX: implementation of ths permeability_function_pressure. 1. version only for multi_phase_flow. 05.2010 double CMediumProperties::PermeabilityFunctionPressure(long /*index*/, double PG2) { - int gueltig; //WX: for function GetCurveValue(). 11.05.2010 + int gueltig; // WX: for function GetCurveValue(). 11.05.2010 double fac_perm_pressure = 1; - //WX: permeability as function of gas pressure. 11.05.2010 - switch(permeability_pressure_model) + // WX: permeability as function of gas pressure. 11.05.2010 + switch (permeability_pressure_model) { - case 10: //WX: case 10, factor directly calculated from curve. 05.2010 - if (m_pcs->getProcessType() == FiniteElement::MULTI_PHASE_FLOW) - //WX: now it's only works for Multi_Phase_Flow. 05.2010 - fac_perm_pressure = GetCurveValue((int) permeability_pressure_model_values[0], 0, PG2, - &gueltig); - //WX: PG2 = gas pressue. 11.05.2010 - break; - default: - break; + case 10: // WX: case 10, factor directly calculated from curve. 05.2010 + if (m_pcs->getProcessType() == FiniteElement::MULTI_PHASE_FLOW) + // WX: now it's only works for Multi_Phase_Flow. 05.2010 + fac_perm_pressure = GetCurveValue((int)permeability_pressure_model_values[0], 0, PG2, &gueltig); + // WX: PG2 = gas pressue. 11.05.2010 + break; + default: + break; } return fac_perm_pressure; } -//WX: Permeability_function_stain: 05.2010 -double CMediumProperties::PermeabilityFunctionStrain(long index, - int nnodes, - CFiniteElementStd* h_fem) //WW:02.08.2010 +// WX: Permeability_function_stain: 05.2010 +double CMediumProperties::PermeabilityFunctionStrain(long index, int nnodes, CFiniteElementStd* h_fem) // WW:02.08.2010 { double fac_perm_strain = 1.; - //WW int ele_index, + // WW int ele_index, int gueltig; - //WW CRFProcessDeformation *dm_pcs = (CRFProcessDeformation *) this; + // WW CRFProcessDeformation *dm_pcs = (CRFProcessDeformation *) this; - //get plas strain and volume strain + // get plas strain and volume strain int idStrainP; double strainp_nodes[20] = {0.}; double strainp = 0.; idStrainP = h_fem->dm_pcs->GetNodeValueIndex("STRAIN_PLS"); - for(int i = 0; i < nnodes; i++) - strainp_nodes[i] = h_fem->dm_pcs->GetNodeValue( - h_fem->dm_pcs->m_msh->ele_vector[index]->getNodeIndices()[i], - idStrainP); + for (int i = 0; i < nnodes; i++) + strainp_nodes[i] + = h_fem->dm_pcs->GetNodeValue(h_fem->dm_pcs->m_msh->ele_vector[index]->getNodeIndices()[i], idStrainP); strainp = h_fem->interpolate(strainp_nodes); - double strain_temp[3] = {0}, vol_strain_temp = 0; - int idx_temp[3]; - int dim = m_pcs->m_msh->GetCoordinateFlag() / 10; - if (dim == 2) - if(h_fem->axisymmetry) - dim = 3; - idx_temp[0] = h_fem->dm_pcs->GetNodeValueIndex("STRAIN_XX"); - idx_temp[1] = h_fem->dm_pcs->GetNodeValueIndex("STRAIN_YY"); - idx_temp[2] = h_fem->dm_pcs->GetNodeValueIndex("STRAIN_ZZ"); - double strain_nodes[20] = {0}; - for (int j = 0; j < dim; j++) - { - for (int i = 0; i < nnodes; i++) - strain_nodes[i] = h_fem->dm_pcs->GetNodeValue( - h_fem->dm_pcs->m_msh->ele_vector[index]->getNodeIndices()[i], - idx_temp[j]); - strain_temp[j] = h_fem->interpolate(strain_nodes); - } - for (int j = 0; j < dim; j++) - vol_strain_temp += strain_temp[j]; - - switch(permeability_strain_model) - { - case 1: - { - fac_perm_strain = GetCurveValue(permeability_strain_model_value[0], - 0, - vol_strain_temp, - &gueltig); - if(fac_perm_strain <= 0.) - fac_perm_strain = 1.; - break; - } - case 2: //equivalent plasical strain + double strain_temp[3] = {0}, vol_strain_temp = 0; + int idx_temp[3]; + int dim = m_pcs->m_msh->GetCoordinateFlag() / 10; + if (dim == 2) + if (h_fem->axisymmetry) + dim = 3; + idx_temp[0] = h_fem->dm_pcs->GetNodeValueIndex("STRAIN_XX"); + idx_temp[1] = h_fem->dm_pcs->GetNodeValueIndex("STRAIN_YY"); + idx_temp[2] = h_fem->dm_pcs->GetNodeValueIndex("STRAIN_ZZ"); + double strain_nodes[20] = {0}; + for (int j = 0; j < dim; j++) { - fac_perm_strain = GetCurveValue(permeability_strain_model_value[0], - 0, - strainp, - &gueltig); - if(fac_perm_strain <= 0.) - fac_perm_strain = 1.; - break; + for (int i = 0; i < nnodes; i++) + strain_nodes[i] = h_fem->dm_pcs->GetNodeValue(h_fem->dm_pcs->m_msh->ele_vector[index]->getNodeIndices()[i], + idx_temp[j]); + strain_temp[j] = h_fem->interpolate(strain_nodes); } - case 3: //if StrainP>0, factor=f(StrainP), else factor=f(strain_Volume) + for (int j = 0; j < dim; j++) + vol_strain_temp += strain_temp[j]; + + switch (permeability_strain_model) { - if(strainp > 0) - fac_perm_strain = GetCurveValue(permeability_strain_model_value[1], - 0, - strainp, - &gueltig); - else + case 1: { - fac_perm_strain = GetCurveValue(permeability_strain_model_value[0], - 0, - vol_strain_temp, - &gueltig); + fac_perm_strain = GetCurveValue(permeability_strain_model_value[0], 0, vol_strain_temp, &gueltig); + if (fac_perm_strain <= 0.) + fac_perm_strain = 1.; + break; } - if(fac_perm_strain <= 0.) - fac_perm_strain = 1.; - break; - } - case 4: //factor = f(strainP+strain_Volume) - { - double tmpfkt = 1.; - if(strainp > 0.) + case 2: // equivalent plasical strain { - tmpfkt = GetCurveValue(permeability_strain_model_value[1], - 0, - strainp, - &gueltig); - if(tmpfkt < 1.) - tmpfkt = 1.; + fac_perm_strain = GetCurveValue(permeability_strain_model_value[0], 0, strainp, &gueltig); + if (fac_perm_strain <= 0.) + fac_perm_strain = 1.; + break; } - fac_perm_strain = GetCurveValue(permeability_strain_model_value[0], - 0, - vol_strain_temp, - &gueltig); - if(fac_perm_strain <= 0.) - fac_perm_strain = 1.; - fac_perm_strain *= tmpfkt; - break; - } - case 5: + case 3: // if StrainP>0, factor=f(StrainP), else factor=f(strain_Volume) + { + if (strainp > 0) + fac_perm_strain = GetCurveValue(permeability_strain_model_value[1], 0, strainp, &gueltig); + else + { + fac_perm_strain = GetCurveValue(permeability_strain_model_value[0], 0, vol_strain_temp, &gueltig); + } + if (fac_perm_strain <= 0.) + fac_perm_strain = 1.; + break; + } + case 4: // factor = f(strainP+strain_Volume) + { + double tmpfkt = 1.; + if (strainp > 0.) + { + tmpfkt = GetCurveValue(permeability_strain_model_value[1], 0, strainp, &gueltig); + if (tmpfkt < 1.) + tmpfkt = 1.; + } + fac_perm_strain = GetCurveValue(permeability_strain_model_value[0], 0, vol_strain_temp, &gueltig); + if (fac_perm_strain <= 0.) + fac_perm_strain = 1.; + fac_perm_strain *= tmpfkt; + break; + } + case 5: { double threshold = 0.; threshold = permeability_strain_model_value[0]; // TODO: Error index out of bounds - if(permeability_strain_model_value[3] > MKleinsteZahl) - threshold = GetCurveValue(permeability_strain_model_value[3], - 0, - vol_strain_temp, - &gueltig); - if(vol_strain_temp <= threshold) - fac_perm_strain = 1 - permeability_strain_model_value[1] - * (threshold - vol_strain_temp); + if (permeability_strain_model_value[3] > MKleinsteZahl) + threshold = GetCurveValue(permeability_strain_model_value[3], 0, vol_strain_temp, &gueltig); + if (vol_strain_temp <= threshold) + fac_perm_strain = 1 - permeability_strain_model_value[1] * (threshold - vol_strain_temp); else - fac_perm_strain = 1 + permeability_strain_model_value[2] - * (vol_strain_temp - threshold); - fac_perm_strain = MRange(permeability_strain_model_value[4], fac_perm_strain - ,permeability_strain_model_value[5]); + fac_perm_strain = 1 + permeability_strain_model_value[2] * (vol_strain_temp - threshold); + fac_perm_strain + = MRange(permeability_strain_model_value[4], fac_perm_strain, permeability_strain_model_value[5]); break; } - default: - break; + default: + break; } return fac_perm_strain; } //------------------------------------------------------------------------ -//12.(iv) PERMEABILITY_FUNCTION_EFFSTRESS +// 12.(iv) PERMEABILITY_FUNCTION_EFFSTRESS //------------------------------------------------------------------------ -//AS: permeability as function of effective stress for liquid flow. 08.2012 -double CMediumProperties::PermeabilityFunctionEffStress(long index, int nnodes, CFiniteElementStd *h_fem) +// AS: permeability as function of effective stress for liquid flow. 08.2012 +double CMediumProperties::PermeabilityFunctionEffStress(long index, int nnodes, CFiniteElementStd* h_fem) { int i, j, size; double perm_stress = 1.0; - //calculate principal effective stress - double stress[6]={0.}, prin_str[6]={0.}, prin_dir[9]={0.}; + // calculate principal effective stress + double stress[6] = {0.}, prin_str[6] = {0.}, prin_dir[9] = {0.}; int stress_index[6]; - //model dimension - int dim = h_fem->dm_pcs->m_msh->GetCoordinateFlag()/10; + // model dimension + int dim = h_fem->dm_pcs->m_msh->GetCoordinateFlag() / 10; size = 6; - if (dim==2) + if (dim == 2) { - size=4; - if(h_fem->axisymmetry) - dim=3; + size = 4; + if (h_fem->axisymmetry) + dim = 3; } stress_index[0] = h_fem->dm_pcs->GetNodeValueIndex("STRESS_XX"); stress_index[1] = h_fem->dm_pcs->GetNodeValueIndex("STRESS_YY"); stress_index[2] = h_fem->dm_pcs->GetNodeValueIndex("STRESS_ZZ"); stress_index[3] = h_fem->dm_pcs->GetNodeValueIndex("STRESS_XY"); - if(size==6) + if (size == 6) { stress_index[4] = h_fem->dm_pcs->GetNodeValueIndex("STRESS_XZ"); stress_index[5] = h_fem->dm_pcs->GetNodeValueIndex("STRESS_YZ"); } - double stress_nodes[20]={0.}; + double stress_nodes[20] = {0.}; - switch(permeability_effstress_model) + switch (permeability_effstress_model) { - //AS: case 1, permeability directly calculated from curve. 16.08.2012 - case 1: - for (j=0; jdm_pcs->GetNodeValue( - h_fem->dm_pcs->m_msh->ele_vector[index]->getNodeIndices()[i], - stress_index[j]); - stress[j] = h_fem->interpolate(stress_nodes); - } - h_fem->SolidProp->CalPrinStrDir(stress, prin_str, prin_dir, dim); - //permeability from curve with minimum (absolute value) principal effective stress as input - perm_stress = GetCurveValue((int)permeability_effstress_model_value[0], 0, prin_str[0], &i); - break; - default: - break; + // AS: case 1, permeability directly calculated from curve. 16.08.2012 + case 1: + for (j = 0; j < size; j++) + { + for (i = 0; i < nnodes; i++) + stress_nodes[i] = h_fem->dm_pcs->GetNodeValue( + h_fem->dm_pcs->m_msh->ele_vector[index]->getNodeIndices()[i], stress_index[j]); + stress[j] = h_fem->interpolate(stress_nodes); + } + h_fem->SolidProp->CalPrinStrDir(stress, prin_str, prin_dir, dim); + // permeability from curve with minimum (absolute value) principal effective stress as input + perm_stress = GetCurveValue((int)permeability_effstress_model_value[0], 0, prin_str[0], &i); + break; + default: + break; } return perm_stress; } //------------------------------------------------------------------------ -//12.(i) PERMEABILITY_FUNCTION_SATURATION +// 12.(i) PERMEABILITY_FUNCTION_SATURATION //------------------------------------------------------------------------ //------------------------------------------------------------------------ -//12.(vi) PERMEABILITY_FUNCTION_POROSITY +// 12.(vi) PERMEABILITY_FUNCTION_POROSITY //------------------------------------------------------------------------ //--------------------------------------------------------------------------------- -//12.(vii) PERMEABILITY_FUNCTION_FRAC_APERTURE -//RFW 07/2005 +// 12.(vii) PERMEABILITY_FUNCTION_FRAC_APERTURE +// RFW 07/2005 //--------------------------------------------------------------------------------- //------------------------------------------------------------------------ -//13. CAPILLARY_PRESSURE_FUNCTION +// 13. CAPILLARY_PRESSURE_FUNCTION //------------------------------------------------------------------------ /************************************************************************** @@ -4866,7 +4794,7 @@ double CMediumProperties::CapillaryPressureFunction(const double wetting_saturat int gueltig; sl = wetting_saturation; // - switch(capillary_pressure_model) + switch (capillary_pressure_model) { default: ScreenMessage("Error in CFluidProperties::CapillaryPressure: no valid material model.\n"); @@ -4874,7 +4802,7 @@ double CMediumProperties::CapillaryPressureFunction(const double wetting_saturat break; // case 0: // k=f(x) - pc = GetCurveValue((int)capillary_pressure_values[0],0,sl,&gueltig); + pc = GetCurveValue((int)capillary_pressure_values[0], 0, sl, &gueltig); break; // case 1: // Constant capillary pressure for ps models @@ -4888,32 +4816,32 @@ double CMediumProperties::CapillaryPressureFunction(const double wetting_saturat break; // case 4: // van Genuchten - pb = capillary_pressure_values[0]; + pb = capillary_pressure_values[0]; slr = capillary_pressure_values[1]; slm = capillary_pressure_values[2]; - m = capillary_pressure_values[3]; // always <= 1.0. Input is exponent = 1 / (1-lambda) + m = capillary_pressure_values[3]; // always <= 1.0. Input is exponent = 1 / (1-lambda) // // Convert alpha to entry pressure? - if(entry_pressure_conversion) - pb = (mfp_vector[0]->Density()*9.81)/pb; + if (entry_pressure_conversion) + pb = (mfp_vector[0]->Density() * 9.81) / pb; // - //sl = MRange(slr, sl, slm); - sl = MRange(slr+DBL_EPSILON, sl, slm-DBL_EPSILON); - se = (sl-slr)/(slm-slr); - pc = pb * pow(pow(se,(-1.0/m)) - 1.0, 1.0-m); - pc = MRange(DBL_EPSILON,pc,capillary_pressure_values[4]); + // sl = MRange(slr, sl, slm); + sl = MRange(slr + DBL_EPSILON, sl, slm - DBL_EPSILON); + se = (sl - slr) / (slm - slr); + pc = pb * pow(pow(se, (-1.0 / m)) - 1.0, 1.0 - m); + pc = MRange(DBL_EPSILON, pc, capillary_pressure_values[4]); break; // case 6: // Brook & Corey - pb = capillary_pressure_values[0]; + pb = capillary_pressure_values[0]; slr = capillary_pressure_values[1]; slm = capillary_pressure_values[2]; - m = capillary_pressure_values[3]; // always >= 1.0 + m = capillary_pressure_values[3]; // always >= 1.0 // - sl = MRange(slr, sl, slm); - se = (sl-slr)/(slm-slr); - pc = pb*pow(se,-1.0/m); - pc = MRange(DBL_EPSILON,pc,capillary_pressure_values[4]); + sl = MRange(slr, sl, slm); + se = (sl - slr) / (slm - slr); + pc = pb * pow(se, -1.0 / m); + pc = MRange(DBL_EPSILON, pc, capillary_pressure_values[4]); break; } return pc; @@ -4937,7 +4865,7 @@ double CMediumProperties::SaturationCapillaryPressureFunction(const double capil pc = capillary_pressure; // // Get Se - switch(capillary_pressure_model) + switch (capillary_pressure_model) { default: ScreenMessage("Error in CFluidProperties::SaturationCapillaryPressureFunction: no valid material model.\n"); @@ -4946,13 +4874,14 @@ double CMediumProperties::SaturationCapillaryPressureFunction(const double capil // case 0: // k=f(x) // Note: Use Inverse curve value because .rfd file has x=S, y=Pc as columns, and Pc is our input. - sl = GetCurveValueInverse((int)capillary_pressure_values[0],0,pc,&gueltig); - sl = MRange(capillary_pressure_values[1]+DBL_EPSILON,sl,capillary_pressure_values[2]-DBL_EPSILON); + sl = GetCurveValueInverse((int)capillary_pressure_values[0], 0, pc, &gueltig); + sl = MRange(capillary_pressure_values[1] + DBL_EPSILON, sl, capillary_pressure_values[2] - DBL_EPSILON); break; // case 1: // Constant capillary pressure for ps models ScreenMessage("ERROR: in CFluidProperties::SaturationCapillaryPressureFunction:"); - ScreenMessage("Constant capillary pressure is not possible for a pressure model (PcPnw, PwPnw, or Richards).\n"); + ScreenMessage( + "Constant capillary pressure is not possible for a pressure model (PcPnw, PwPnw, or Richards).\n"); exit(0); break; // @@ -4964,40 +4893,43 @@ double CMediumProperties::SaturationCapillaryPressureFunction(const double capil pb = capillary_pressure_values[0]; slr = capillary_pressure_values[1]; slm = capillary_pressure_values[2]; - m = capillary_pressure_values[3]; // always <= 1.0. Input is exponent = 1 / (1-lambda) + m = capillary_pressure_values[3]; // always <= 1.0. Input is exponent = 1 / (1-lambda) // // Convert alpha to entry pressure? - if(entry_pressure_conversion) - pb = (mfp_vector[0]->Density()*9.81)/pb; + if (entry_pressure_conversion) + pb = (mfp_vector[0]->Density() * 9.81) / pb; // - if(pc < 0.0) pc = 0.0; - se = pow(pc/pb, 1.0/(1.0-m)) + 1.0; - se = pow(se,-m); - sl = se*(slm-slr) + slr; - sl = MRange(slr+DBL_EPSILON,sl,slm-DBL_EPSILON); + if (pc < 0.0) + pc = 0.0; + se = pow(pc / pb, 1.0 / (1.0 - m)) + 1.0; + se = pow(se, -m); + sl = se * (slm - slr) + slr; + sl = MRange(slr + DBL_EPSILON, sl, slm - DBL_EPSILON); break; // case 6: // Brook & Corey pb = capillary_pressure_values[0]; slr = capillary_pressure_values[1]; slm = capillary_pressure_values[2]; - m = capillary_pressure_values[3]; // always >= 1.0 - if(pc < pb) pc = pb; - se = pow(pc/pb,-m); - sl = se*(slm-slr) + slr; - sl = MRange(slr+DBL_EPSILON,sl,slm-DBL_EPSILON); + m = capillary_pressure_values[3]; // always >= 1.0 + if (pc < pb) + pc = pb; + se = pow(pc / pb, -m); + sl = se * (slm - slr) + slr; + sl = MRange(slr + DBL_EPSILON, sl, slm - DBL_EPSILON); break; case 10: // unconfined 3D GW. 5.3.07 JOD - //MW: remove comment to provide variables, not constants to PermeabilitySaturationFunction + // MW: remove comment to provide variables, not constants to PermeabilitySaturationFunction pb = capillary_pressure_values[0]; slr = capillary_pressure_values[1]; - if(pc > 0) { - sl = max(0., 1 - (pc / pb)); - sl = pow(sl, 2* (1 - sl)); - sl = slr + (1 - slr) * sl; + if (pc > 0) + { + sl = max(0., 1 - (pc / pb)); + sl = pow(sl, 2 * (1 - sl)); + sl = slr + (1 - slr) * sl; } else - sl = 1; + sl = 1; break; } return sl; @@ -5022,62 +4954,62 @@ double CMediumProperties::SaturationCapillaryPressureFunction(const double capil double CMediumProperties::SaturationPressureDependency(const double capillary_pressure, bool allow_zero) { - double dsdp,v1,v2,pc,pb,slr,slm,m; - int gueltig; - pc = capillary_pressure; - // - if(allow_zero && pc < DBL_EPSILON) // If we allow dSw/dPc = 0.0 (i.e. Richard's flow) - return 0.0; - // - switch(capillary_pressure_model) - { - default: - ScreenMessage("Error in CFluidProperties::SaturationPressureDependency: no valid material model.\n"); - exit(0); - break; - - case 0: // Curve value - // Note: Use Inverse curve value because .rfd file has x=S, y=Pc as columns, and Pc is our input. - dsdp = GetCurveInverseDerivative((int)capillary_pressure_values[0],1,pc,&gueltig); - break; - - case 1: // Pc = CONSTANT - dsdp = 0.0; - break; - - case 2: // Sw = CONSTANT - dsdp = 0.0; - break; - - case 4: // Van Genuchten: 01.3.2007 WW // 05.2010 JT. - pb = capillary_pressure_values[0]; - slr = capillary_pressure_values[1]; - slm = capillary_pressure_values[2]; - m = capillary_pressure_values[3]; // always <= 1.0. Input is exponent = 1 / (1-lambda) - pc = MRange(FLT_EPSILON,pc,capillary_pressure_values[4]); - // - // Convert alpha to entry pressure? - if(entry_pressure_conversion) - pb = (mfp_vector[0]->Density()*9.81)/pb; - // - v1 = pow((pc/pb),(1.0/(1.0-m))); - v2 = pow((1.0+v1),(-1.0-m)); - dsdp = (m*v1*v2*(slm-slr)) / ((m-1.0)*pc); - break; - - case 6: // Brooks & Corey. 10/2010 JT - pb = capillary_pressure_values[0]; - pc = MRange(FLT_EPSILON,pc,capillary_pressure_values[4]); - slr = capillary_pressure_values[1]; - slm = capillary_pressure_values[2]; - m = capillary_pressure_values[3]; // always >= 1.0 - // - v1 = pow((pc/pb),-m); - dsdp = (m*v1*(slr - slm)) / pc; - break; - } - // - return dsdp; + double dsdp,v1,v2,pc,pb,slr,slm,m; + int gueltig; + pc = capillary_pressure; + // + if(allow_zero && pc < DBL_EPSILON) // If we allow dSw/dPc = 0.0 (i.e. Richard's flow) + return 0.0; + // + switch(capillary_pressure_model) + { + default: + ScreenMessage("Error in CFluidProperties::SaturationPressureDependency: no valid material model.\n"); + exit(0); + break; + + case 0: // Curve value + // Note: Use Inverse curve value because .rfd file has x=S, y=Pc as columns, and Pc is our input. + dsdp = GetCurveInverseDerivative((int)capillary_pressure_values[0],1,pc,&gueltig); + break; + + case 1: // Pc = CONSTANT + dsdp = 0.0; + break; + + case 2: // Sw = CONSTANT + dsdp = 0.0; + break; + + case 4: // Van Genuchten: 01.3.2007 WW // 05.2010 JT. + pb = capillary_pressure_values[0]; + slr = capillary_pressure_values[1]; + slm = capillary_pressure_values[2]; + m = capillary_pressure_values[3]; // always <= 1.0. Input is exponent = 1 / (1-lambda) + pc = MRange(FLT_EPSILON,pc,capillary_pressure_values[4]); + // + // Convert alpha to entry pressure? + if(entry_pressure_conversion) + pb = (mfp_vector[0]->Density()*9.81)/pb; + // + v1 = pow((pc/pb),(1.0/(1.0-m))); + v2 = pow((1.0+v1),(-1.0-m)); + dsdp = (m*v1*v2*(slm-slr)) / ((m-1.0)*pc); + break; + + case 6: // Brooks & Corey. 10/2010 JT + pb = capillary_pressure_values[0]; + pc = MRange(FLT_EPSILON,pc,capillary_pressure_values[4]); + slr = capillary_pressure_values[1]; + slm = capillary_pressure_values[2]; + m = capillary_pressure_values[3]; // always >= 1.0 + // + v1 = pow((pc/pb),-m); + dsdp = (m*v1*(slr - slm)) / pc; + break; + } + // + return dsdp; } */ @@ -5093,11 +5025,11 @@ double CMediumProperties::SaturationPressureDependency(const double capillary_pr **************************************************************************/ double CMediumProperties::PressureSaturationDependency(const double wetting_saturation, bool invert) { - double dpds,dsdp,v1,v2,pb,sl,slr,slm,m,lim,ds,dpc; + double dpds, dsdp, v1, v2, pb, sl, slr, slm, m, lim, ds, dpc; int gueltig; sl = wetting_saturation; // - switch(capillary_pressure_model) + switch (capillary_pressure_model) { default: ScreenMessage("Error in CFluidProperties::PressureSaturationDependency: no valid material model.\n"); @@ -5105,8 +5037,8 @@ double CMediumProperties::PressureSaturationDependency(const double wetting_satu break; case 0: // curve value - sl = MRange(capillary_pressure_values[1]+DBL_EPSILON, sl, capillary_pressure_values[2]-DBL_EPSILON); - dpds = GetCurveDerivative((int)capillary_pressure_values[0],1,sl,&gueltig); + sl = MRange(capillary_pressure_values[1] + DBL_EPSILON, sl, capillary_pressure_values[2] - DBL_EPSILON); + dpds = GetCurveDerivative((int)capillary_pressure_values[0], 1, sl, &gueltig); break; case 1: // Pc = CONSTANT @@ -5116,47 +5048,49 @@ double CMediumProperties::PressureSaturationDependency(const double wetting_satu return 0.0; case 4: // Van Genuchten: 01.3.2007 WW // 05.2010 JT. - pb = capillary_pressure_values[0]; + pb = capillary_pressure_values[0]; slr = capillary_pressure_values[1]; slm = capillary_pressure_values[2]; - m = capillary_pressure_values[3]; // always <= 1.0. Input is exponent = 1 / (1-lambda) - sl = MRange(slr+DBL_EPSILON, sl, slm-DBL_EPSILON); // (infinity also occurs at sl=slmax for van Genuchten) + m = capillary_pressure_values[3]; // always <= 1.0. Input is exponent = 1 / (1-lambda) + sl = MRange(slr + DBL_EPSILON, sl, + slm - DBL_EPSILON); // (infinity also occurs at sl=slmax for van Genuchten) // // Convert alpha to entry pressure? - if(entry_pressure_conversion) - pb = (mfp_vector[0]->Density()*9.81)/pb; + if (entry_pressure_conversion) + pb = (mfp_vector[0]->Density() * 9.81) / pb; // // Get dPc/dSw - v1 = pow(((sl-slr) / (slm-slr)),(-1.0/m)); - v2 = pow(v1-1.0,-m); - dpds = (pb*(m-1.0)*v1*v2) / (m*(sl-slr)); + v1 = pow(((sl - slr) / (slm - slr)), (-1.0 / m)); + v2 = pow(v1 - 1.0, -m); + dpds = (pb * (m - 1.0) * v1 * v2) / (m * (sl - slr)); break; case 6: // Brooks & Corey. 10/2010 JT - pb = capillary_pressure_values[0]; + pb = capillary_pressure_values[0]; slr = capillary_pressure_values[1]; slm = capillary_pressure_values[2]; - m = capillary_pressure_values[3]; // always >= 1.0 - sl = MRange(slr+DBL_EPSILON, sl, slm); // No upper bound needed for B&C + m = capillary_pressure_values[3]; // always >= 1.0 + sl = MRange(slr + DBL_EPSILON, sl, slm); // No upper bound needed for B&C // // Get dPc/dSw - v1 = pow(((sl-slr) / (slm-slr)),(-1.0/m)); - dpds = (pb*v1) / (m*(slr-sl)); + v1 = pow(((sl - slr) / (slm - slr)), (-1.0 / m)); + dpds = (pb * v1) / (m * (slr - sl)); break; case 10: // unconfined 3D GW 6/2012 JOD - return 0; // set phi/(rho * g) in storage - case 99: // The old iterative method. Should anyone need it (but it is somewhat inaccurate at low and high saturations) + return 0; // set phi/(rho * g) in storage + case 99: // The old iterative method. Should anyone need it (but it is somewhat inaccurate at low and high + // saturations) ds = 1.0e-2; - do{ + do + { ds /= 10.; v1 = CapillaryPressureFunction(sl - ds); v2 = CapillaryPressureFunction(sl + ds); dpc = v1 - v2; - } - while((ds > DBL_EPSILON) && (v2 < DBL_EPSILON / 100.)); - if (((v1 > DBL_EPSILON) || (v2 > DBL_EPSILON)) && (dpc > DBL_EPSILON) ) - dsdp = (-2.0*ds) / dpc; + } while ((ds > DBL_EPSILON) && (v2 < DBL_EPSILON / 100.)); + if (((v1 > DBL_EPSILON) || (v2 > DBL_EPSILON)) && (dpc > DBL_EPSILON)) + dsdp = (-2.0 * ds) / dpc; else dsdp = 0.0; // @@ -5165,15 +5099,19 @@ double CMediumProperties::PressureSaturationDependency(const double wetting_satu } // // Note: Sw and Pc are inversly related.. i.e. dsdp and dpds are always <= 0.0 - lim = (-1.0)/DBL_EPSILON; + lim = (-1.0) / DBL_EPSILON; // - if(invert){ // Return dSw/dPc - dsdp = 1.0/dpds; - if(dsdp < lim) dsdp = lim; + if (invert) + { // Return dSw/dPc + dsdp = 1.0 / dpds; + if (dsdp < lim) + dsdp = lim; return dsdp; } - else{ // Return dPc/dSw - if(dpds < lim) dpds = lim; + else + { // Return dPc/dSw + if (dpds < lim) + dpds = lim; return dpds; } } @@ -5191,28 +5129,29 @@ double CMediumProperties::PressureSaturationDependency(const double wetting_satu Programing: 11/2004 OK Implementation **************************************************************************/ -double CMediumProperties::Density(long element,double* gp,double theta) +double CMediumProperties::Density(long element, double* gp, double theta) { - //OK411 + // OK411 gp = gp; int no_phases = (int)mfp_vector.size(); double density = 0.0; int i; CFluidProperties* m_mfp = NULL; - //OK411 CSolidProperties* m_msp = NULL; + // OK411 CSolidProperties* m_msp = NULL; char saturation_name[15]; - if(no_phases == 1) + if (no_phases == 1) { m_mfp = mfp_vector[0]; - density = Porosity(element,theta) * m_mfp->Density(); + density = Porosity(element, theta) * m_mfp->Density(); } else - for(i = 0; i < no_phases; i++) + for (i = 0; i < no_phases; i++) { m_mfp = mfp_vector[i]; - sprintf(saturation_name,"SATURATION%i",i + 1); - //OK411 density += Porosity(element,theta) * m_mfp->Density() * PCSGetELEValue(element,gp,theta,saturation_name); + sprintf(saturation_name, "SATURATION%i", i + 1); + // OK411 density += Porosity(element,theta) * m_mfp->Density() * + // PCSGetELEValue(element,gp,theta,saturation_name); } /*OK411 long group = ElGetElementGroupNumber(element); @@ -5233,7 +5172,7 @@ void MMPDelete() { long i; int no_mmp = (int)mmp_vector.size(); - for(i = 0; i < no_mmp; i++) + for (i = 0; i < no_mmp; i++) delete mmp_vector[i]; mmp_vector.clear(); } @@ -5250,18 +5189,18 @@ void MMP2PCSRelation(CRFProcess* m_pcs) { CMediumProperties* m_mmp = NULL; MeshLib::CElem* m_ele = NULL; - if(m_pcs->m_msh) - for(long i = 0; i < (long)m_pcs->m_msh->ele_vector.size(); i++) + if (m_pcs->m_msh) + for (long i = 0; i < (long)m_pcs->m_msh->ele_vector.size(); i++) { m_ele = m_pcs->m_msh->ele_vector[i]; - if(m_ele->GetPatchIndex() < mmp_vector.size()) + if (m_ele->GetPatchIndex() < mmp_vector.size()) { m_mmp = mmp_vector[m_ele->GetPatchIndex()]; m_mmp->m_pcs = m_pcs; } } else - for(int j = 0; j < (int)mmp_vector.size(); j++) + for (int j = 0; j < (int)mmp_vector.size(); j++) { m_mmp = mmp_vector[j]; m_mmp->m_pcs = m_pcs; @@ -5282,11 +5221,11 @@ void MMP2PCSRelation(CRFProcess* m_pcs) 11/2005 OK GEOMETRY_AREA 04/2006 CMCD Constant area **************************************************************************/ -//MMPGetHeterogeneousFields +// MMPGetHeterogeneousFields void GetHeterogeneousFields() { - //OK411 int ok=0; - //OK411 char* name_file=NULL; + // OK411 int ok=0; + // OK411 char* name_file=NULL; CMediumProperties* m_mmp = NULL; //---------------------------------------------------------------------- // File handling @@ -5295,48 +5234,48 @@ void GetHeterogeneousFields() //---------------------------------------------------------------------- // Tests - if(mmp_vector.size() == 0) + if (mmp_vector.size() == 0) return; //---------------------------------------------------------------------- - //Schleife über alle Gruppen - for(int i = 0; i < (int)mmp_vector.size(); i++) + // Schleife über alle Gruppen + for (int i = 0; i < (int)mmp_vector.size(); i++) { m_mmp = mmp_vector[i]; //.................................................................... // For Permeability - if(m_mmp->permeability_file.size() > 0) + if (m_mmp->permeability_file.size() > 0) { - //OK name_file = (char *) m_mmp->permeability_file.data(); - //OK if(name_file != NULL) - //OK ok = FctReadHeterogeneousFields(name_file,m_mmp); + // OK name_file = (char *) m_mmp->permeability_file.data(); + // OK if(name_file != NULL) + // OK ok = FctReadHeterogeneousFields(name_file,m_mmp); - //WW file_path_base_ext = file_path + m_mmp->permeability_file; - //WW + // WW file_path_base_ext = file_path + m_mmp->permeability_file; + // WW m_mmp->SetDistributedELEProperties(m_mmp->permeability_file); m_mmp->WriteTecplotDistributedProperties(); } //.................................................................... // For Porosity - if(m_mmp->porosity_file.size() > 0) + if (m_mmp->porosity_file.size() > 0) { - //CB name_file = (char *) m_mmp->porosity_file.data(); - //CB if(name_file != NULL) - //CB ok = FctReadHeterogeneousFields(name_file,m_mmp); - //file_path_base_ext = file_path + m_mmp->porosity_file; - //m_mmp->SetDistributedELEProperties(file_path_base_ext); // CB Removed bugs in this function + // CB name_file = (char *) m_mmp->porosity_file.data(); + // CB if(name_file != NULL) + // CB ok = FctReadHeterogeneousFields(name_file,m_mmp); + // file_path_base_ext = file_path + m_mmp->porosity_file; + // m_mmp->SetDistributedELEProperties(file_path_base_ext); // CB Removed bugs in this function // CB Removed bugs in this function m_mmp->SetDistributedELEProperties(m_mmp->porosity_file); m_mmp->WriteTecplotDistributedProperties(); } //.................................................................... // GEOMETRY_AREA - if(m_mmp->geo_area_file.size() > 0) + if (m_mmp->geo_area_file.size() > 0) { file_path_base_ext = file_path + m_mmp->geo_area_file; m_mmp->SetDistributedELEProperties(file_path_base_ext); m_mmp->WriteTecplotDistributedProperties(); } - //NW else m_mmp->SetConstantELEarea(m_mmp->geo_area,i); + // NW else m_mmp->SetConstantELEarea(m_mmp->geo_area,i); //.................................................................... } //---------------------------------------------------------------------- @@ -5349,17 +5288,17 @@ void GetHeterogeneousFields() **************************************************************************/ void CMediumProperties::SetConstantELEarea(double area, int group) { - long i,j, ele_group; + long i, j, ele_group; long no_ele; - int no_processes = (int) pcs_vector.size(); + int no_processes = (int)pcs_vector.size(); if (area != 1.0) for (i = 0; i < no_processes; i++) { - _mesh = FEMGet(convertProcessTypeToString (pcs_vector[i]->getProcessType())); - if(!_mesh) - return; //WW - no_ele = (long) _mesh->ele_vector.size(); - for(j = 0; j < no_ele; j++) + _mesh = FEMGet(convertProcessTypeToString(pcs_vector[i]->getProcessType())); + if (!_mesh) + return; // WW + no_ele = (long)_mesh->ele_vector.size(); + for (j = 0; j < no_ele; j++) { ele_group = _mesh->ele_vector[j]->GetPatchIndex(); if (ele_group == group) @@ -5383,14 +5322,14 @@ void CMediumProperties::SetDistributedELEProperties(string file_name) bool element_area = false; long i, j, ihet; double mmp_property_value; - int mat_vector_size = 0; // Init WW - double ddummy, conversion_factor = 1.0; //init WW - vector xvals, yvals, zvals, mmpvals; - vectortemp_store; + int mat_vector_size = 0; // Init WW + double ddummy, conversion_factor = 1.0; // init WW + vector xvals, yvals, zvals, mmpvals; + vector temp_store; int c_vals; double x, y, z, mmpv; std::stringstream in; - //CB + // CB vector garage; int mat_vec_size = 0; int por_index = 0; @@ -5401,54 +5340,51 @@ void CMediumProperties::SetDistributedELEProperties(string file_name) cout << " SetDistributedELEProperties: "; //---------------------------------------------------------------------- // File handling - ifstream mmp_property_file(file_name.data(),ios::in); - if(!mmp_property_file.good()) + ifstream mmp_property_file(file_name.data(), ios::in); + if (!mmp_property_file.good()) { - cout << - "Warning in CMediumProperties::SetDistributedELEProperties: no MMP property data" - << - "\n"; + cout << "Warning in CMediumProperties::SetDistributedELEProperties: no MMP property data" + << "\n"; return; } mmp_property_file.clear(); - mmp_property_file.seekg(0,ios::beg); + mmp_property_file.seekg(0, ios::beg); //---------------------------------------------------------------------- line_string = GetLineFromFile1(&mmp_property_file); - if(!(line_string.find("#MEDIUM_PROPERTIES_DISTRIBUTED") != string::npos)) + if (!(line_string.find("#MEDIUM_PROPERTIES_DISTRIBUTED") != string::npos)) { - cout << "Keyword #MEDIUM_PROPERTIES_DISTRIBUTED not found" << "\n"; + cout << "Keyword #MEDIUM_PROPERTIES_DISTRIBUTED not found" + << "\n"; return; } //---------------------------------------------------------------------- - while(!mmp_property_file.eof()) + while (!mmp_property_file.eof()) { line_string = GetLineFromFile1(&mmp_property_file); - if(line_string.find("STOP") != string::npos) + if (line_string.find("STOP") != string::npos) return; - if(line_string.empty()) + if (line_string.empty()) { - cout << - "Error in CMediumProperties::SetDistributedELEProperties - no enough data sets" + cout << "Error in CMediumProperties::SetDistributedELEProperties - no enough data sets" << "\n"; return; } //.................................................................... - if(line_string.find("$MSH_TYPE") != string::npos) + if (line_string.find("$MSH_TYPE") != string::npos) { line_string = GetLineFromFile1(&mmp_property_file); mmp_property_mesh = line_string; _mesh = FEMGet(line_string); - if(!_mesh) + if (!_mesh) { - cout << - "CMediumProperties::SetDistributedELEProperties: no MSH data" << - "\n"; + cout << "CMediumProperties::SetDistributedELEProperties: no MSH data" + << "\n"; return; } continue; } //.................................................................... - if(line_string.find("$MMP_TYPE") != string::npos) + if (line_string.find("$MMP_TYPE") != string::npos) { element_area = false; mmp_property_file >> mmp_property_name; @@ -5459,205 +5395,196 @@ void CMediumProperties::SetDistributedELEProperties(string file_name) continue; } //.................................................................... - if(line_string.find("$DIS_TYPE") != string::npos) + if (line_string.find("$DIS_TYPE") != string::npos) { mmp_property_file >> mmp_property_dis_type; continue; } //.................................................................... - if(line_string.find("$CONVERSION_FACTOR") != string::npos) + if (line_string.find("$CONVERSION_FACTOR") != string::npos) { mmp_property_file >> conversion_factor; continue; } //.................................................................... - if(line_string.find("$DATA") != string::npos) + if (line_string.find("$DATA") != string::npos) { - switch(mmp_property_dis_type[0]) + switch (mmp_property_dis_type[0]) { - case 'N': // Next neighbour - case 'G': // Geometric mean - // Read in all values given, store in vectors for x, y, z and value - i = 0; - while(i == 0) - { - line1 = GetLineFromFile1(&mmp_property_file); - if(line1.find("STOP") != string::npos) - break; - in.str((string)line1); - in >> x >> y >> z >> mmpv; - in.clear(); - mmpv *= conversion_factor; // convert values - xvals.push_back(x); - yvals.push_back(y); - zvals.push_back(z); - mmpvals.push_back(mmpv); - } - // sort values to mesh - for(i = 0; i < (long)_mesh->ele_vector.size(); i++) - { - m_ele_geo = _mesh->ele_vector[i]; - mat_vector_size = m_ele_geo->mat_vector.Size(); - // CB Store old values as they are set to zero after resizing - for(j = 0; j < mat_vector_size; j++) - garage.push_back(m_ele_geo->mat_vector(j)); - m_ele_geo->mat_vector.resize(mat_vector_size + 1); - // CB Refill old values as they were set to zero after resizing - for(j = 0; j < mat_vector_size; j++) - m_ele_geo->mat_vector(j) = garage[j]; - garage.clear(); - if(mmp_property_dis_type[0] == 'N') + case 'N': // Next neighbour + case 'G': // Geometric mean + // Read in all values given, store in vectors for x, y, z and value + i = 0; + while (i == 0) { - // Search for all elements of the mesh, which is the nearest given value in the input file - // Return value ihet is the index of the het. val in the mmpval-vector - ihet = GetNearestHetVal2(i, - _mesh, - xvals, - yvals, - zvals, - mmpvals); - m_ele_geo->mat_vector(mat_vector_size) = - mmpvals[ihet]; - } - if(mmp_property_dis_type[0] == 'G') - { - mmpv = GetAverageHetVal2(i, - _mesh, - xvals, - yvals, - zvals, - mmpvals); - m_ele_geo->mat_vector(mat_vector_size) = mmpv; - } - } - break; - case 'E': // Element data - for(i = 0; i < (long)_mesh->ele_vector.size(); i++) - { - m_ele_geo = _mesh->ele_vector[i]; - mmp_property_file >> ddummy >> mmp_property_value; - mat_vector_size = m_ele_geo->mat_vector.Size(); - if (mat_vector_size > 0) - { - for (c_vals = 0; c_vals < mat_vector_size; c_vals++) - temp_store.push_back(m_ele_geo->mat_vector( - c_vals)); - m_ele_geo->mat_vector.resize(mat_vector_size + 1); - for (c_vals = 0; c_vals < mat_vector_size; c_vals++) - m_ele_geo->mat_vector(c_vals) = - temp_store[c_vals]; - m_ele_geo->mat_vector(mat_vector_size) = - mmp_property_value; - temp_store.clear(); + line1 = GetLineFromFile1(&mmp_property_file); + if (line1.find("STOP") != string::npos) + break; + in.str((string)line1); + in >> x >> y >> z >> mmpv; + in.clear(); + mmpv *= conversion_factor; // convert values + xvals.push_back(x); + yvals.push_back(y); + zvals.push_back(z); + mmpvals.push_back(mmpv); } - else + // sort values to mesh + for (i = 0; i < (long)_mesh->ele_vector.size(); i++) { + m_ele_geo = _mesh->ele_vector[i]; + mat_vector_size = m_ele_geo->mat_vector.Size(); + // CB Store old values as they are set to zero after resizing + for (j = 0; j < mat_vector_size; j++) + garage.push_back(m_ele_geo->mat_vector(j)); m_ele_geo->mat_vector.resize(mat_vector_size + 1); - m_ele_geo->mat_vector(mat_vector_size) = - mmp_property_value; + // CB Refill old values as they were set to zero after resizing + for (j = 0; j < mat_vector_size; j++) + m_ele_geo->mat_vector(j) = garage[j]; + garage.clear(); + if (mmp_property_dis_type[0] == 'N') + { + // Search for all elements of the mesh, which is the nearest given value in the input file + // Return value ihet is the index of the het. val in the mmpval-vector + ihet = GetNearestHetVal2(i, _mesh, xvals, yvals, zvals, mmpvals); + m_ele_geo->mat_vector(mat_vector_size) = mmpvals[ihet]; + } + if (mmp_property_dis_type[0] == 'G') + { + mmpv = GetAverageHetVal2(i, _mesh, xvals, yvals, zvals, mmpvals); + m_ele_geo->mat_vector(mat_vector_size) = mmpv; + } } - if (element_area) - _mesh->ele_vector[i]->SetFluxArea( - mmp_property_value); - if(line_string.empty()) + break; + case 'E': // Element data + for (i = 0; i < (long)_mesh->ele_vector.size(); i++) { - cout << - "Error in CMediumProperties::SetDistributedELEProperties - not enough data sets" - << "\n"; - return; + m_ele_geo = _mesh->ele_vector[i]; + mmp_property_file >> ddummy >> mmp_property_value; + mat_vector_size = m_ele_geo->mat_vector.Size(); + if (mat_vector_size > 0) + { + for (c_vals = 0; c_vals < mat_vector_size; c_vals++) + temp_store.push_back(m_ele_geo->mat_vector(c_vals)); + m_ele_geo->mat_vector.resize(mat_vector_size + 1); + for (c_vals = 0; c_vals < mat_vector_size; c_vals++) + m_ele_geo->mat_vector(c_vals) = temp_store[c_vals]; + m_ele_geo->mat_vector(mat_vector_size) = mmp_property_value; + temp_store.clear(); + } + else + { + m_ele_geo->mat_vector.resize(mat_vector_size + 1); + m_ele_geo->mat_vector(mat_vector_size) = mmp_property_value; + } + if (element_area) + _mesh->ele_vector[i]->SetFluxArea(mmp_property_value); + if (line_string.empty()) + { + cout << "Error in CMediumProperties::SetDistributedELEProperties - not enough data sets" + << "\n"; + return; + } } - } - break; - default: - cout << " Unknown interpolation option for the values!" << "\n"; - break; + break; + default: + cout << " Unknown interpolation option for the values!" + << "\n"; + break; } continue; } //.................................................................... } // CB now set VOL_MAT & VOL_BIO as heterogeneous values, if defined as model 2 and het Porosity - if( (mmp_property_name == "POROSITY") && (this->vol_bio_model == 2) ) + if ((mmp_property_name == "POROSITY") && (this->vol_bio_model == 2)) { _mesh->mat_names_vector.push_back("VOL_BIO"); - for(i = 0; i < (long)_mesh->ele_vector.size(); i++) + for (i = 0; i < (long)_mesh->ele_vector.size(); i++) { m_ele_geo = _mesh->ele_vector[i]; // Get the element mat_vec_size = m_ele_geo->mat_vector.Size(); // CB Store old values as they are set to zero after resizing - for(j = 0; j < mat_vec_size; j++) + for (j = 0; j < mat_vec_size; j++) garage.push_back(m_ele_geo->mat_vector(j)); m_ele_geo->mat_vector.resize(mat_vec_size + 1); // CB Refill old values as they were set to zero after resizing - for(j = 0; j < mat_vec_size; j++) + for (j = 0; j < mat_vec_size; j++) m_ele_geo->mat_vector(j) = garage[j]; garage.clear(); // Set the VOL_BIO value from mmp file input m_ele_geo->mat_vector(mat_vec_size) = this->vol_bio; } } - if( (mmp_property_name == "POROSITY") && (this->vol_mat_model == 2) ) + if ((mmp_property_name == "POROSITY") && (this->vol_mat_model == 2)) { _mesh->mat_names_vector.push_back("VOL_MAT"); // Get the porosity index - for(por_index = 0; por_index < (int)_mesh->mat_names_vector.size(); por_index++) - if(_mesh->mat_names_vector[por_index].compare("POROSITY") == 0) + for (por_index = 0; por_index < (int)_mesh->mat_names_vector.size(); por_index++) + if (_mesh->mat_names_vector[por_index].compare("POROSITY") == 0) break; // Get the vol_bio index - for(vol_bio_index = 0; vol_bio_index < (int)_mesh->mat_names_vector.size(); - vol_bio_index++) - if(_mesh->mat_names_vector[vol_bio_index].compare("VOL_BIO") == 0) + for (vol_bio_index = 0; vol_bio_index < (int)_mesh->mat_names_vector.size(); vol_bio_index++) + if (_mesh->mat_names_vector[vol_bio_index].compare("VOL_BIO") == 0) break; - for(i = 0; i < (long)_mesh->ele_vector.size(); i++) + for (i = 0; i < (long)_mesh->ele_vector.size(); i++) { m_ele_geo = _mesh->ele_vector[i]; // Get the element mat_vec_size = m_ele_geo->mat_vector.Size(); // CB Store old values as they are set to zero after resizing - for(j = 0; j < mat_vec_size; j++) + for (j = 0; j < mat_vec_size; j++) garage.push_back(m_ele_geo->mat_vector(j)); m_ele_geo->mat_vector.resize(mat_vec_size + 1); // CB Refill old values as they were set to zero after resizing - for(j = 0; j < mat_vec_size; j++) + for (j = 0; j < mat_vec_size; j++) m_ele_geo->mat_vector(j) = garage[j]; garage.clear(); // Set the VOL_MAT value from (1-POROSITY-VOL_BIO) - m_ele_geo->mat_vector(mat_vec_size) = 1 - - m_ele_geo->mat_vector(por_index) - - m_ele_geo->mat_vector(vol_bio_index); + m_ele_geo->mat_vector(mat_vec_size) + = 1 - m_ele_geo->mat_vector(por_index) - m_ele_geo->mat_vector(vol_bio_index); } } //---------------------------------------------------------------------- - //Write sorted output file + // Write sorted output file //---------------------------------------------------------------------- // File handling // CB - for(k = 0; k < (int)_mesh->mat_names_vector.size(); k++) + for (k = 0; k < (int)_mesh->mat_names_vector.size(); k++) { - //file_name +="_sorted"; + // file_name +="_sorted"; outfile = _mesh->mat_names_vector[k] + "_sorted"; ofstream mmp_property_file_out(outfile.data()); - if(!mmp_property_file_out.good()) + if (!mmp_property_file_out.good()) { - cout << - "Warning in CMediumProperties::WriteDistributedELEProperties: no MMP property data file to write to" + cout << "Warning in CMediumProperties::WriteDistributedELEProperties: no MMP property data file to write to" << "\n"; return; } - mmp_property_file_out << "#MEDIUM_PROPERTIES_DISTRIBUTED" << "\n"; - mmp_property_file_out << "$MSH_TYPE" << "\n" << " " << mmp_property_mesh << "\n"; - //mmp_property_file_out << "$MSH_TYPE" << "\n" << " " << mmp_property_mesh << "\n"; - //mmp_property_file_out << "$MMP_TYPE" << "\n" << " " << "PERMEABILITY" << "\n"; - mmp_property_file_out << "$MMP_TYPE" << "\n" << " " << - _mesh->mat_names_vector[k] << "\n"; - mmp_property_file_out << "$DIS_TYPE" << "\n" << " " << "ELEMENT" << "\n"; - mmp_property_file_out << "$DATA" << "\n"; - for(i = 0; i < (long)_mesh->ele_vector.size(); i++) + mmp_property_file_out << "#MEDIUM_PROPERTIES_DISTRIBUTED" + << "\n"; + mmp_property_file_out << "$MSH_TYPE" + << "\n" + << " " << mmp_property_mesh << "\n"; + // mmp_property_file_out << "$MSH_TYPE" << "\n" << " " << mmp_property_mesh << "\n"; + // mmp_property_file_out << "$MMP_TYPE" << "\n" << " " << "PERMEABILITY" << "\n"; + mmp_property_file_out << "$MMP_TYPE" + << "\n" + << " " << _mesh->mat_names_vector[k] << "\n"; + mmp_property_file_out << "$DIS_TYPE" + << "\n" + << " " + << "ELEMENT" + << "\n"; + mmp_property_file_out << "$DATA" + << "\n"; + for (i = 0; i < (long)_mesh->ele_vector.size(); i++) { m_ele_geo = _mesh->ele_vector[i]; mmp_property_file_out << i << " " << m_ele_geo->mat_vector(k) << "\n"; } - mmp_property_file_out << "#STOP" << "\n"; + mmp_property_file_out << "#STOP" + << "\n"; mmp_property_file_out.close(); //---------------------------------------------------------------------- } @@ -5686,8 +5613,7 @@ void CMediumProperties::WriteTecplotDistributedProperties() return; //-------------------------------------------------------------------- // File handling - string mat_file_name = path + name + "_" + _mesh->pcs_name + "_PROPERTIES" - + TEC_FILE_EXTENSION; + string mat_file_name = path + name + "_" + _mesh->pcs_name + "_PROPERTIES" + TEC_FILE_EXTENSION; fstream mat_file(mat_file_name.data(), ios::trunc | ios::out); mat_file.setf(ios::scientific, ios::floatfield); mat_file.precision(12); @@ -5695,128 +5621,111 @@ void CMediumProperties::WriteTecplotDistributedProperties() return; mat_file.seekg(0L, ios::beg); //-------------------------------------------------------------------- - if ((long) _mesh->ele_vector.size() > 0) + if ((long)_mesh->ele_vector.size() > 0) { m_ele = _mesh->ele_vector[0]; switch (m_ele->GetElementType()) { - case MshElemType::LINE: - element_type = "QUADRILATERAL"; - break; - case MshElemType::QUAD: - element_type = "QUADRILATERAL"; - break; - case MshElemType::HEXAHEDRON: - element_type = "BRICK"; - break; - case MshElemType::TRIANGLE: - element_type = "TRIANGLE"; - break; - case MshElemType::TETRAHEDRON: - element_type = "TETRAHEDRON"; - break; - case MshElemType::PRISM: - element_type = "BRICK"; - break; - default: - std::cerr - << - "CMediumProperties::WriteTecplotDistributedProperties MshElemType not handled" - << "\n"; + case MshElemType::LINE: + element_type = "QUADRILATERAL"; + break; + case MshElemType::QUAD: + element_type = "QUADRILATERAL"; + break; + case MshElemType::HEXAHEDRON: + element_type = "BRICK"; + break; + case MshElemType::TRIANGLE: + element_type = "TRIANGLE"; + break; + case MshElemType::TETRAHEDRON: + element_type = "TETRAHEDRON"; + break; + case MshElemType::PRISM: + element_type = "BRICK"; + break; + default: + std::cerr << "CMediumProperties::WriteTecplotDistributedProperties MshElemType not handled" + << "\n"; } } //-------------------------------------------------------------------- // Header mat_file << "VARIABLES = X,Y,Z"; - for (j = 0; j < (int) _mesh->mat_names_vector.size(); j++) + for (j = 0; j < (int)_mesh->mat_names_vector.size(); j++) mat_file << "," << _mesh->mat_names_vector[j]; mat_file << "\n"; - mat_file << "ZONE T = " << name << ", " << "N = " - << (long) _mesh->nod_vector.size() << ", " << "E = " - << (long) _mesh->ele_vector.size() << ", " << "F = FEPOINT" << ", " + mat_file << "ZONE T = " << name << ", " + << "N = " << (long)_mesh->nod_vector.size() << ", " + << "E = " << (long)_mesh->ele_vector.size() << ", " + << "F = FEPOINT" + << ", " << "ET = " << element_type << "\n"; //-------------------------------------------------------------------- // Nodes - for (i = 0; i < (long) _mesh->nod_vector.size(); i++) + for (i = 0; i < (long)_mesh->nod_vector.size(); i++) { m_nod = _mesh->nod_vector[i]; - double const* const pnt (m_nod->getData()); + double const* const pnt(m_nod->getData()); mat_file << pnt[0] << " " << pnt[1] << " " << pnt[2]; for (size_t j = 0; j < _mesh->mat_names_vector.size(); j++) { m_mat_prop_nod = 0.0; - for (k = 0; k < (int) m_nod->getConnectedElementIDs().size(); k++) + for (k = 0; k < (int)m_nod->getConnectedElementIDs().size(); k++) { m_ele = _mesh->ele_vector[m_nod->getConnectedElementIDs()[k]]; m_mat_prop_nod += m_ele->mat_vector(j); } - m_mat_prop_nod /= (int) m_nod->getConnectedElementIDs().size(); + m_mat_prop_nod /= (int)m_nod->getConnectedElementIDs().size(); mat_file << " " << m_mat_prop_nod; } mat_file << "\n"; } //-------------------------------------------------------------------- // Elements - for (i = 0; i < (long) _mesh->ele_vector.size(); i++) + for (i = 0; i < (long)_mesh->ele_vector.size(); i++) { m_ele = _mesh->ele_vector[i]; - //OK if(m_ele->GetPatchIndex()==number) { + // OK if(m_ele->GetPatchIndex()==number) { switch (m_ele->GetElementType()) { - case MshElemType::LINE: - mat_file << m_ele->getNodeIndices()[0] + 1 << " " - << m_ele->getNodeIndices()[1] + 1 << " " - << m_ele->getNodeIndices()[1] + 1 << " " - << m_ele->getNodeIndices()[0] + 1 << "\n"; - element_type = "QUADRILATERAL"; - break; - case MshElemType::QUAD: - mat_file << m_ele->getNodeIndices()[0] + 1 << " " - << m_ele->getNodeIndices()[1] + 1 << " " - << m_ele->getNodeIndices()[2] + 1 << " " - << m_ele->getNodeIndices()[3] + 1 << "\n"; - element_type = "QUADRILATERAL"; - break; - case MshElemType::HEXAHEDRON: - mat_file << m_ele->getNodeIndices()[0] + 1 << " " - << m_ele->getNodeIndices()[1] + 1 << " " - << m_ele->getNodeIndices()[2] + 1 << " " - << m_ele->getNodeIndices()[3] + 1 << " " - << m_ele->getNodeIndices()[4] + 1 << " " - << m_ele->getNodeIndices()[5] + 1 << " " - << m_ele->getNodeIndices()[6] + 1 << " " - << m_ele->getNodeIndices()[7] + 1 << "\n"; - element_type = "BRICK"; - break; - case MshElemType::TRIANGLE: - mat_file << m_ele->getNodeIndices()[0] + 1 << " " - << m_ele->getNodeIndices()[1] + 1 << " " - << m_ele->getNodeIndices()[2] + 1 << "\n"; - element_type = "TRIANGLE"; - break; - case MshElemType::TETRAHEDRON: - mat_file << m_ele->getNodeIndices()[0] + 1 << " " - << m_ele->getNodeIndices()[1] + 1 << " " - << m_ele->getNodeIndices()[2] + 1 << " " - << m_ele->getNodeIndices()[3] + 1 << "\n"; - element_type = "TETRAHEDRON"; - break; - case MshElemType::PRISM: - mat_file << m_ele->getNodeIndices()[0] + 1 << " " - << m_ele->getNodeIndices()[0] + 1 << " " - << m_ele->getNodeIndices()[1] + 1 << " " - << m_ele->getNodeIndices()[2] + 1 << " " - << m_ele->getNodeIndices()[3] + 1 << " " - << m_ele->getNodeIndices()[3] + 1 << " " - << m_ele->getNodeIndices()[4] + 1 << " " - << m_ele->getNodeIndices()[5] + 1 << "\n"; - element_type = "BRICK"; - break; - default: - std::cerr - << - "CMediumProperties::WriteTecplotDistributedProperties MshElemType not handled" - << "\n"; + case MshElemType::LINE: + mat_file << m_ele->getNodeIndices()[0] + 1 << " " << m_ele->getNodeIndices()[1] + 1 << " " + << m_ele->getNodeIndices()[1] + 1 << " " << m_ele->getNodeIndices()[0] + 1 << "\n"; + element_type = "QUADRILATERAL"; + break; + case MshElemType::QUAD: + mat_file << m_ele->getNodeIndices()[0] + 1 << " " << m_ele->getNodeIndices()[1] + 1 << " " + << m_ele->getNodeIndices()[2] + 1 << " " << m_ele->getNodeIndices()[3] + 1 << "\n"; + element_type = "QUADRILATERAL"; + break; + case MshElemType::HEXAHEDRON: + mat_file << m_ele->getNodeIndices()[0] + 1 << " " << m_ele->getNodeIndices()[1] + 1 << " " + << m_ele->getNodeIndices()[2] + 1 << " " << m_ele->getNodeIndices()[3] + 1 << " " + << m_ele->getNodeIndices()[4] + 1 << " " << m_ele->getNodeIndices()[5] + 1 << " " + << m_ele->getNodeIndices()[6] + 1 << " " << m_ele->getNodeIndices()[7] + 1 << "\n"; + element_type = "BRICK"; + break; + case MshElemType::TRIANGLE: + mat_file << m_ele->getNodeIndices()[0] + 1 << " " << m_ele->getNodeIndices()[1] + 1 << " " + << m_ele->getNodeIndices()[2] + 1 << "\n"; + element_type = "TRIANGLE"; + break; + case MshElemType::TETRAHEDRON: + mat_file << m_ele->getNodeIndices()[0] + 1 << " " << m_ele->getNodeIndices()[1] + 1 << " " + << m_ele->getNodeIndices()[2] + 1 << " " << m_ele->getNodeIndices()[3] + 1 << "\n"; + element_type = "TETRAHEDRON"; + break; + case MshElemType::PRISM: + mat_file << m_ele->getNodeIndices()[0] + 1 << " " << m_ele->getNodeIndices()[0] + 1 << " " + << m_ele->getNodeIndices()[1] + 1 << " " << m_ele->getNodeIndices()[2] + 1 << " " + << m_ele->getNodeIndices()[3] + 1 << " " << m_ele->getNodeIndices()[3] + 1 << " " + << m_ele->getNodeIndices()[4] + 1 << " " << m_ele->getNodeIndices()[5] + 1 << "\n"; + element_type = "BRICK"; + break; + default: + std::cerr << "CMediumProperties::WriteTecplotDistributedProperties MshElemType not handled" + << "\n"; } } } @@ -5831,41 +5740,45 @@ void CMediumProperties::WriteTecplotDistributedProperties() **************************************************************************/ long GetNearestHetVal2(long EleIndex, CFEMesh* m_msh, - vector xvals, - vector yvals, - vector zvals, - vector mmpvals) + vector + xvals, + vector + yvals, + vector + zvals, + vector + mmpvals) { (void)mmpvals; long i, nextele, no_values; - double ex, ey, ez, dist, dist1; //WW , dist2; + double ex, ey, ez, dist, dist1; // WW , dist2; double x, y, z; MeshLib::CElem* m_ele = NULL; - no_values = (long) xvals.size(); + no_values = (long)xvals.size(); x = 0.0; y = 0.0; z = 0.0; - dist = 10000000.0; //Startwert - //WW dist2 = 0.01; // Abstand zwischen eingelesenen Knoten und Geometrieknoten-RF; + dist = 10000000.0; // Startwert + // WW dist2 = 0.01; // Abstand zwischen eingelesenen Knoten und Geometrieknoten-RF; // Achtung, doppelbelegung möglich bei kleinen Gitterabständen nextele = -1; - //Get element data + // Get element data m_ele = m_msh->ele_vector[EleIndex]; - double const* center (m_ele->GetGravityCenter()); + double const* center(m_ele->GetGravityCenter()); x = center[0]; y = center[1]; z = center[2]; - //Calculate distances - for(i = 0; i < no_values; i++) + // Calculate distances + for (i = 0; i < no_values; i++) { ex = xvals[i]; ey = yvals[i]; ez = zvals[i]; dist1 = (ex - x) * (ex - x) + (ey - y) * (ey - y) + (ez - z) * (ez - z); - if(dist1 < dist) + if (dist1 < dist) { dist = dist1; nextele = i; @@ -5884,72 +5797,76 @@ long GetNearestHetVal2(long EleIndex, **************************************************************************/ double GetAverageHetVal2(long EleIndex, CFEMesh* m_msh, - vector xvals, - vector yvals, - vector zvals, - vector mmpvals) + vector + xvals, + vector + yvals, + vector + zvals, + vector + mmpvals) { long i, j, ihet; double average; - double xp[3],yp[3]; + double xp[3], yp[3]; double value; double NumberOfValues; - //WW double InvNumberOfValues; + // WW double InvNumberOfValues; CGLPoint* m_point = NULL; MeshLib::CElem* m_ele = NULL; - long no_values = (long) xvals.size(); + long no_values = (long)xvals.size(); - j = 0; //only for 1 value + j = 0; // only for 1 value //----------------------------------------------------------------------- - //Get element data + // Get element data m_ele = m_msh->ele_vector[EleIndex]; - for(j = 0; j < 3; j++) + for (j = 0; j < 3; j++) { double const* const pnt(m_ele->GetNode(j)->getData()); xp[j] = pnt[0]; yp[j] = pnt[1]; - //zp[j] = 0.0; + // zp[j] = 0.0; } //----------------------------------------------------------------------- - //Find data points in the element + // Find data points in the element NumberOfValues = 0; - //WW InvNumberOfValues = 0; + // WW InvNumberOfValues = 0; m_point = new CGLPoint; average = -1; value = 0; - for(i = 0; i < no_values; i++) - if(mmpvals[i] != -999999.0) //Data point not within an element yet + for (i = 0; i < no_values; i++) + if (mmpvals[i] != -999999.0) // Data point not within an element yet { m_point->x = xvals[i]; m_point->y = yvals[i]; m_point->z = 0.0; //.................................................................... - //Calculate the product of values in element - //CC 10/05 - if(m_point->IsInTriangleXYProjection(xp,yp)) + // Calculate the product of values in element + // CC 10/05 + if (m_point->IsInTriangleXYProjection(xp, yp)) { value = value + zvals[i]; NumberOfValues++; - mmpvals[i] = -999999.0; //used as marker + mmpvals[i] = -999999.0; // used as marker } } - //end for + // end for //........................................................................ - if(NumberOfValues == 0) //if no data points in element --> get neares value + if (NumberOfValues == 0) // if no data points in element --> get neares value { ihet = GetNearestHetVal2(EleIndex, m_msh, xvals, yvals, zvals, mmpvals); - if(ihet < 0) + if (ihet < 0) DisplayMsgLn(" Error getting nearest het_value location"); else average = mmpvals[ihet]; } //........................................................................ - else //if data points in element --> Calculate arithmetic mean + else // if data points in element --> Calculate arithmetic mean average = value / NumberOfValues; delete m_point; @@ -5964,25 +5881,26 @@ double GetAverageHetVal2(long EleIndex, **************************************************************************/ void CMediumPropertiesGroup::Set(CRFProcess* m_pcs) { - long j,k; + long j, k; CFEMesh* m_msh = m_pcs->m_msh; CMediumProperties* m_mmp = NULL; MeshLib::CElem* elem = NULL; //---------------------------------------------------------------------- // Tests // - if(!m_msh) - cout << "Warning in CSourceTermGroup::Set - no MSH data" << "\n"; - //return; + if (!m_msh) + cout << "Warning in CSourceTermGroup::Set - no MSH data" + << "\n"; + // return; //---------------------------------------------------------------------- long no_mmp = (long)mmp_vector.size(); - for(j = 0; j < no_mmp; j++) + for (j = 0; j < no_mmp; j++) { m_mmp = mmp_vector[j]; //==================================================================== - if(m_mmp->pcs_type_name.compare(pcs_type_name) == 0) + if (m_mmp->pcs_type_name.compare(pcs_type_name) == 0) { m_mmp = mmp_vector[j]; - for(k = 0; k < (long)m_msh->ele_vector.size(); k++) + for (k = 0; k < (long)m_msh->ele_vector.size(); k++) { elem = m_msh->ele_vector[k]; elem->SetPatchIndex(j); @@ -5999,14 +5917,14 @@ void CMediumPropertiesGroup::Set(CRFProcess* m_pcs) **************************************************************************/ void CMediumProperties::CalStressPermeabilityFactor(double* kfac, const double T) { - switch(permeability_stress_mode) + switch (permeability_stress_mode) { - case 2: - CalStressPermeabilityFactor2(kfac, T); - break; - case 3: - CalStressPermeabilityFactor3(kfac); - break; + case 2: + CalStressPermeabilityFactor2(kfac, T); + break; + case 3: + CalStressPermeabilityFactor3(kfac); + break; } } @@ -6024,33 +5942,30 @@ void CMediumProperties::CalStressPermeabilityFactor2(double* kfac, const double ele_index = Fem_Ele_Std->Index; Fem_Ele_Std->RealCoordinates(xyz); b0 = pow(6.0 * permeability_tensor[0] / c_coefficient[5], 1.0 / 3.0); - if((long)ele_value_dm.size() > 0) // Deformation process coupled + if ((long)ele_value_dm.size() > 0) // Deformation process coupled { e_valDM = ele_value_dm[ele_index]; - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) { sig[i] = (*e_valDM->Stress)(i, Fem_Ele_Std->GetGPindex()); - b[i] = c_coefficient[2 + i] + c_coefficient[0] * exp( - c_coefficient[1] * sig[i] / (T * PhysicalConstant::IdealGasConstant)); + b[i] = c_coefficient[2 + i] + + c_coefficient[0] * exp(c_coefficient[1] * sig[i] / (T * PhysicalConstant::IdealGasConstant)); // } } else - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) { - sig[i] = c_coefficient[6 + i * 4] + c_coefficient[7 + i * 4] * xyz[0] - + c_coefficient[8 + i * - 4] * xyz[1] + c_coefficient[9 + i * 4] * xyz[2]; - b[i] = c_coefficient[2 + i] + c_coefficient[0] * exp( - c_coefficient[1] * sig[i] / (T * PhysicalConstant::IdealGasConstant)); + sig[i] = c_coefficient[6 + i * 4] + c_coefficient[7 + i * 4] * xyz[0] + c_coefficient[8 + i * 4] * xyz[1] + + c_coefficient[9 + i * 4] * xyz[2]; + b[i] = c_coefficient[2 + i] + + c_coefficient[0] * exp(c_coefficient[1] * sig[i] / (T * PhysicalConstant::IdealGasConstant)); } - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) { ia = (i + 1) % 3; ib = (i + 2) % 3; - kfac[i] = 0.5 * - (MathLib::fastpow(b[ia], - 3) + MathLib::fastpow(b[ib],3)) / MathLib::fastpow(b0,3); + kfac[i] = 0.5 * (MathLib::fastpow(b[ia], 3) + MathLib::fastpow(b[ib], 3)) / MathLib::fastpow(b0, 3); } } @@ -6072,52 +5987,46 @@ void CMediumProperties::CalStressPermeabilityFactor3(double* kfac) ElementValue_DM* e_valDM = NULL; ele_index = Fem_Ele_Std->Index; pG = Fem_Ele_Std->PG; - if(pG < 0.0) + if (pG < 0.0) pG = 0.0; Fem_Ele_Std->RealCoordinates(xyz); - if((long)ele_value_dm.size() > 0) // Deformation process coupled + if ((long)ele_value_dm.size() > 0) // Deformation process coupled { e_valDM = ele_value_dm[ele_index]; - for(i = 0; i < 3; i++) - sig[i] = 1.e-6 * - ((*e_valDM->Stress)(i, Fem_Ele_Std->GetGPindex()) - max(pG,0.0)); + for (i = 0; i < 3; i++) + sig[i] = 1.e-6 * ((*e_valDM->Stress)(i, Fem_Ele_Std->GetGPindex()) - max(pG, 0.0)); } else - for(i = 0; i < 3; i++) - sig[i] = 1.0e-6 * - (c_coefficient[9 + i * 4] + c_coefficient[10 + i * 4] * xyz[0] - + c_coefficient[11 + i * - 4] * xyz[1] + - c_coefficient[12 + i * 4] * xyz[2] - max(pG,0.0)); + for (i = 0; i < 3; i++) + sig[i] = 1.0e-6 * (c_coefficient[9 + i * 4] + c_coefficient[10 + i * 4] * xyz[0] + + c_coefficient[11 + i * 4] * xyz[1] + + c_coefficient[12 + i * 4] * xyz[2] + - max(pG, 0.0)); // am at 100 - double am0_h = a01 - - (c_coefficient[7] / - (-Kn + c_coefficient[7] / - c_coefficient[3]) + c_coefficient[4] + c_coefficient[5] + c_coefficient[6]); - double am0_H = a01 - - (c_coefficient[8] / - (-Kn + c_coefficient[8] / - c_coefficient[3]) + c_coefficient[4] + c_coefficient[5] + c_coefficient[6]); + double am0_h + = a01 - (c_coefficient[7] / (-Kn + c_coefficient[7] / c_coefficient[3]) + c_coefficient[4] + c_coefficient[5] + + c_coefficient[6]); + double am0_H + = a01 - (c_coefficient[8] / (-Kn + c_coefficient[8] / c_coefficient[3]) + c_coefficient[4] + c_coefficient[5] + + c_coefficient[6]); double ah0_h = am0_h * am0_h; double ah0_H = am0_H * am0_H; - if(ah0_h > am0_h) + if (ah0_h > am0_h) ah0_h = am0_h; - if(ah0_H > am0_H) + if (ah0_H > am0_H) ah0_H = am0_h; - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) { - am = a01 - - (sig[i] / - (-Kn + sig[i] / - c_coefficient[3]) + c_coefficient[4] + c_coefficient[5] + c_coefficient[6]); + am = a01 + - (sig[i] / (-Kn + sig[i] / c_coefficient[3]) + c_coefficient[4] + c_coefficient[5] + c_coefficient[6]); ah[i] = am * am; - if(ah[i] > am) + if (ah[i] > am) ah[i] = am; // - c_coefficient[21 + i] = ah[i] / MathLib::fastpow(sqrt(JRC),5); + c_coefficient[21 + i] = ah[i] / MathLib::fastpow(sqrt(JRC), 5); } kfac[0] = ah[0] * ah[0] / (ah0_h * ah0_h); - if(geo_dimension == 2) + if (geo_dimension == 2) { fy = ah[2] * ah[2] / (ah0_H * ah0_H); kfac[1] = 0.5 * (fy + kfac[0]); @@ -6141,33 +6050,33 @@ void CMediumProperties::CalStressPermeabilityFactor3_Coef() int i; double d_max = 0.0; double a[4], delta[4], Kni[4]; - double A[] = {-0.296, -0.1005, -0.1031, -0.1031 }; - double B[] = {-0.0056, -0.0073, -0.0074, -0.0074 }; - double C[] = {2.241, 1.0082, 1.135, 1.135 }; - double D[] = {-0.245, -0.23, -0.251, -0.251 }; + double A[] = {-0.296, -0.1005, -0.1031, -0.1031}; + double B[] = {-0.0056, -0.0073, -0.0074, -0.0074}; + double C[] = {2.241, 1.0082, 1.135, 1.135}; + double D[] = {-0.245, -0.23, -0.251, -0.251}; // - double C1[] = {84.77, 44.37, 31.38, 20 }; - double C2[] = {0.02, 0.01, 0.01, 0.01 }; + double C1[] = {84.77, 44.37, 31.38, 20}; + double C2[] = {0.02, 0.01, 0.01, 0.01}; // double JRC = c_coefficient[0]; double JCS = c_coefficient[1]; double UCS = c_coefficient[2]; double a0 = 0.2 * JRC * (0.2 * UCS / JCS - 0.1); // - for(i = 0; i < 4; i++) + for (i = 0; i < 4; i++) { a[i] = a0; - d_max = A[i] + B[i] * JRC + C[i] * pow(JCS / a0,D[i]); + d_max = A[i] + B[i] * JRC + C[i] * pow(JCS / a0, D[i]); Kni[i] = 0.0178 * JCS / a[i] + 1.748 * JRC - 7.155; delta[i] = 0.01 * (C1[i] - C2[i] * JCS / a0) * d_max; - a0 -= delta[i]; + a0 -= delta[i]; } // // c_coefficient[1] = a[0]; c_coefficient[2] = Kni[3]; c_coefficient[3] = d_max; - for(i = 4; i < 7; i++) + for (i = 4; i < 7; i++) c_coefficient[i] = delta[i - 4]; // Unit of stresses is MPa c_coefficient[7] *= 1.0e-6; @@ -6181,14 +6090,14 @@ void CMediumProperties::CalStressPermeabilityFactor3_Coef() 01/2006 YD Implementation last modification: **************************************************************************/ -CMediumPropertiesGroup* MMPGetGroup(const string &pcs_type_name) +CMediumPropertiesGroup* MMPGetGroup(const string& pcs_type_name) { CMediumPropertiesGroup* m_mmp_group = NULL; list::const_iterator p_mmp_group = mmp_group_list.begin(); - while(p_mmp_group != mmp_group_list.end()) + while (p_mmp_group != mmp_group_list.end()) { m_mmp_group = *p_mmp_group; - if(m_mmp_group->pcs_type_name.compare(pcs_type_name) == 0) + if (m_mmp_group->pcs_type_name.compare(pcs_type_name) == 0) return m_mmp_group; ++p_mmp_group; } @@ -6228,18 +6137,18 @@ bool MMPExist(ifstream* mmp_file) std::stringstream in; string name; //====================================================================== - while(!mmp_file->eof()) + while (!mmp_file->eof()) { line_string = GetLineFromFile1(mmp_file); //-------------------------------------------------------------------- - //NAME - if(line_string.find("$NAME") != string::npos) + // NAME + if (line_string.find("$NAME") != string::npos) { in.str(GetLineFromFile1(mmp_file)); - in >> name; //sub_line + in >> name; // sub_line // Test whether MMP already exists - for(int i = 0; i < (int)mmp_vector.size(); i++) - if(name.compare(mmp_vector[i]->name) == 0) + for (int i = 0; i < (int)mmp_vector.size(); i++) + if (name.compare(mmp_vector[i]->name) == 0) return true; in.clear(); @@ -6258,12 +6167,12 @@ bool MMPExist(ifstream* mmp_file) **************************************************************************/ bool MMPExist() { - for(int i = 0; i < (int)mmp_vector.size(); i++) - for(int j = 0; j < (int)mmp_vector.size(); j++) + for (int i = 0; i < (int)mmp_vector.size(); i++) + for (int j = 0; j < (int)mmp_vector.size(); j++) { - if(i == j) + if (i == j) continue; - if(mmp_vector[i]->name.compare(mmp_vector[j]->name) == 0) + if (mmp_vector[i]->name.compare(mmp_vector[j]->name) == 0) return true; } return false; @@ -6282,13 +6191,13 @@ double CMediumProperties::KozenyCarman(double k0, double n0, double n) double rt = 0.0; // TODO: here it should be the min_porosity and max_porosity instead of 0 and 1 - if (k0 < 1.0e-40 || k0 > 1.0 || n0 <= 0 || n0 >= 1 || n <= 0 || n >= 1 ) + if (k0 < 1.0e-40 || k0 > 1.0 || n0 <= 0 || n0 >= 1 || n <= 0 || n >= 1) return k0; else { rt = k0; - rt *= MathLib::fastpow( n / n0, 3 ); + rt *= MathLib::fastpow(n / n0, 3); } return rt; @@ -6307,13 +6216,13 @@ double CMediumProperties::KozenyCarman_normalized(double k0, double n0, double n double rt = 0.0; // TODO: here it should be the min_porosity and max_porosity instead of 0 and 1 - if (k0 < 1.0e-40 || k0 > 1.0 || n0 <= 0 || n0 >= 1 || n <= 0 || n >= 1 ) + if (k0 < 1.0e-40 || k0 > 1.0 || n0 <= 0 || n0 >= 1 || n <= 0 || n >= 1) return k0; else { rt = k0; - rt *= MathLib::fastpow( n / n0, 3 ); + rt *= MathLib::fastpow(n / n0, 3); rt *= ((1 - n0) / (1 - n) * (1 - n0) / (1 - n)); } @@ -6325,7 +6234,7 @@ double CMediumProperties::KozenyCarman_normalized(double k0, double n0, double n FEMLib-Method: Task: Returns the new permeability which will be calculated using Kozeny-Carman formulation. It takes intial permeability& porosity - and also the new/updated porosity as an input. + and also the new/updated porosity as an input. Programing: 11.2010 AB Implementation last modification: @@ -6335,21 +6244,21 @@ double CMediumProperties::KozenyCarmanNew(double k_init, double n_init, double n double k_t = 0.0; // Limit minimum and maximum values. - if (k_init <= 0.0 || n_init <=0. || n_init >= 1. || n_t <=0. || n_t >= 1. ) + if (k_init <= 0.0 || n_init <= 0. || n_init >= 1. || n_t <= 0. || n_t >= 1.) return k_init; else { - k_t = k_init * (pow( (1. - n_init) / (1 - n_t) , 2))*(pow( n_t / n_init , 3 )) ; + k_t = k_init * (pow((1. - n_init) / (1 - n_t), 2)) * (pow(n_t / n_init, 3)); } -return k_t; + return k_t; } /************************************************************************************* FEMLib-Method: Task: Returns the new permeability which will be calculated using Verma-Pruess formulation. It takes intial permeability& porosity, - the new/updated porosity, critical porosity and a power law exponent as an input. + the new/updated porosity, critical porosity and a power law exponent as an input. Programing: 11.2010 AB Implementation last modification: @@ -6360,17 +6269,17 @@ double CMediumProperties::VermaPruess(double k_init, double n_init, double n_t) double n_crit, a; n_crit = permeability_porosity_updating_values[0]; // critical porosity - a = permeability_porosity_updating_values[1]; // a power law exponent + a = permeability_porosity_updating_values[1]; // a power law exponent // Limit minimum and maximum values. - if (k_init <= 0.0 || k_init >= 1.0 || n_init <=0 || n_init >= 1 || n_t <=0 || n_t >= 1 ) + if (k_init <= 0.0 || k_init >= 1.0 || n_init <= 0 || n_init >= 1 || n_t <= 0 || n_t >= 1) return k_init; else { - k_t = k_init * (pow( (n_t - n_crit) / (n_init - n_crit) , a)); + k_t = k_init * (pow((n_t - n_crit) / (n_init - n_crit), a)); } -return k_t; + return k_t; } /////////////////////////////////////////////////////////////////////////// // old data structure functions //OK411 @@ -6395,7 +6304,7 @@ return k_t; **************************************************************************/ double CMediumProperties::PorosityEffectiveStress(long index, double element_pressure) { - //OK411 + // OK411 element_pressure = element_pressure; index = index; @@ -6546,7 +6455,7 @@ double CMediumProperties::PorosityVolumetricFreeSwellingConstantIonicstrength(lo double saturation, double temperature) { - //OK411 + // OK411 index = index; saturation = saturation; temperature = temperature; @@ -6611,7 +6520,7 @@ double CMediumProperties::PorosityEffectiveConstrainedSwelling(long index, double temperature, double* porosity_sw) { - //OK411 + // OK411 index = index; saturation = saturation; temperature = temperature; @@ -6766,8 +6675,10 @@ double CMediumProperties::PorosityEffectiveConstrainedSwelling(long index, rho = GetFluidDensity(0, index, 0., 0., 0., theta); if (GetTracerSolubilityModel(index, 0, 0) == 1) { //if (GetRFProcessHeatReactModel()) - solubility_coefficient = CalcTracerSolubilityCoefficient(index,0,0,1,PCSGetNODValueIndex("CONCENTRATION1",timelevel),1,PCSGetNODValueIndex("CONCENTRATION1",timelevel)); - //else solubility_coefficient = CalcTracerSolubilityCoefficient(index,0,0,1,PCSGetNODValueIndex("CONCENTRATION1",timelevel),0,PCSGetNODValueIndex("CONCENTRATION1",timelevel)); + solubility_coefficient = + CalcTracerSolubilityCoefficient(index,0,0,1,PCSGetNODValueIndex("CONCENTRATION1",timelevel),1,PCSGetNODValueIndex("CONCENTRATION1",timelevel)); + //else solubility_coefficient = + CalcTracerSolubilityCoefficient(index,0,0,1,PCSGetNODValueIndex("CONCENTRATION1",timelevel),0,PCSGetNODValueIndex("CONCENTRATION1",timelevel)); } else { solubility_coefficient = GetTracerSolubilityCoefficient(index, 0, 0); } @@ -6797,11 +6708,9 @@ double CMediumProperties::PorosityEffectiveConstrainedSwelling(long index, 05/2005 MX Implementation last modification: **************************************************************************/ -double CMediumProperties::PorosityVolumetricFreeSwelling(long index, - double saturation, - double temperature) +double CMediumProperties::PorosityVolumetricFreeSwelling(long index, double saturation, double temperature) { - //OK411 + // OK411 index = index; saturation = saturation; temperature = temperature; @@ -6865,7 +6774,7 @@ double CMediumProperties::PorosityVolumetricFreeSwelling(long index, **************************************************************************/ double CMediumProperties::PorosityVolumetricChemicalReaction(long index) { - //OK411 + // OK411 index = index; /*OK411 @@ -6937,35 +6846,33 @@ double CMediumProperties::PorosityVolumetricChemicalReaction(long index) return porosity; } -//WX: 03.2011. Porosity = n0 + vol_strain -double CMediumProperties::PorosityVolStrain(long index, double val0, CFiniteElementStd* assem ) +// WX: 03.2011. Porosity = n0 + vol_strain +double CMediumProperties::PorosityVolStrain(long index, double val0, CFiniteElementStd* assem) { double val = val0, vol_strain_temp = 0., strain_temp[3] = {0.}, strain_nodes[20] = {0.}; - //WW int idx_temp[3]={0}, ele_index, nnodes = assem->nnodes; + // WW int idx_temp[3]={0}, ele_index, nnodes = assem->nnodes; int idx_temp[3] = {0}, nnodes = assem->nnodes; - //WW CRFProcessDeformation *dm_pcs = (CRFProcessDeformation *) this; + // WW CRFProcessDeformation *dm_pcs = (CRFProcessDeformation *) this; int dim = m_pcs->m_msh->GetCoordinateFlag() / 10; if (dim == 2) - if(assem->axisymmetry) + if (assem->axisymmetry) dim = 3; idx_temp[0] = assem->dm_pcs->GetNodeValueIndex("STRAIN_XX"); idx_temp[1] = assem->dm_pcs->GetNodeValueIndex("STRAIN_YY"); idx_temp[2] = assem->dm_pcs->GetNodeValueIndex("STRAIN_ZZ"); - //WW ele_index = index; + // WW ele_index = index; for (int j = 0; j < dim; j++) { for (int i = 0; i < nnodes; i++) - strain_nodes[i] = assem->dm_pcs->GetNodeValue( - assem->dm_pcs->m_msh->ele_vector[index]-> \ - getNodeIndices()[i], - idx_temp[j]); + strain_nodes[i] = assem->dm_pcs->GetNodeValue(assem->dm_pcs->m_msh->ele_vector[index]->getNodeIndices()[i], + idx_temp[j]); strain_temp[j] = assem->interpolate(strain_nodes); } for (int j = 0; j < dim; j++) vol_strain_temp += strain_temp[j]; val += vol_strain_temp; - if(val < MKleinsteZahl) - val = 1e-6; //lower limit of porostity + if (val < MKleinsteZahl) + val = 1e-6; // lower limit of porostity return val; } @@ -6977,12 +6884,9 @@ double CMediumProperties::PorosityVolStrain(long index, double val0, CFiniteElem permeability. Agreed with GK last modification: **************************************************************************/ -double CMediumProperties::TortuosityFunction(long number, - double* gp, - double theta, - CFiniteElementStd* assem) +double CMediumProperties::TortuosityFunction(long number, double* gp, double theta, CFiniteElementStd* assem) { - //OK411 + // OK411 theta = theta; gp = gp; number = number; @@ -7018,18 +6922,18 @@ double CMediumProperties::TortuosityFunction(long number, */ switch (tortuosity_model) { - case 0: // Tortuosity is read from a curve - //To do - break; - case 1: // Constant Tortuosity - tortuosity = tortuosity_model_values[0]; - break; - case 2: /* Tortuosity is lin. fct. of porosity*/ - tortuosity = Porosity(number, theta) * tortuosity_model_values[0]; - break; - default: - DisplayMsgLn("Unknown tortuosisty model!"); - break; + case 0: // Tortuosity is read from a curve + // To do + break; + case 1: // Constant Tortuosity + tortuosity = tortuosity_model_values[0]; + break; + case 2: /* Tortuosity is lin. fct. of porosity*/ + tortuosity = Porosity(number, theta) * tortuosity_model_values[0]; + break; + default: + DisplayMsgLn("Unknown tortuosisty model!"); + break; } return tortuosity; } @@ -7054,79 +6958,82 @@ double CMediumProperties::TortuosityFunction(long number, double CMediumProperties::NonlinearFlowFunction(long index, int gp, double /*theta*/, CFiniteElementStd* assem) { double k_rel = 1.0; - //OK411 - /* + // OK411 + /* if (flowlinearity_model==3 || flowlinearity_model==6) // Forchheimer for DLR - { - assert (assem->PcsType==EnumProcessType::A || assem->PcsType==EnumProcessType::S); - ElementValue* gp_ele = ele_gp_value[index]; - //Velocity - double vel[3] = {}; - vel[0] = gp_ele->Velocity(0, gp); - vel[1] = gp_ele->Velocity(1, gp); - vel[2] = gp_ele->Velocity(2, gp); - double v_mag = sqrt(vel[0]*vel[0]+vel[1]*vel[1]+vel[2]*vel[2]); - if (v_mag != 0.0) { - double* k = PermeabilityTensor(index); //temporary assuming isotropic - double dens_arg[3] = {}; - dens_arg[0] = (1.0-theta)*assem->interpolate(assem->NodalVal0) + theta*assem->interpolate(assem->NodalVal1); - dens_arg[1] = (1.0-theta)*assem->interpolate(assem->NodalVal_t0) + theta*assem->interpolate(assem->NodalVal_t1); - //dens_arg[1] = assem->interpolate(assem->NodalValC1)+T_KILVIN_ZERO; - dens_arg[2] = (1.0-theta)*assem->interpolate(assem->NodalVal_X0) + theta*assem->interpolate(assem->NodalVal_X1); - //dens_arg[2] = index; - double vis = assem->FluidProp->Viscosity(dens_arg); - double rhog = assem->FluidProp->Density(dens_arg); // which model? - if (flowlinearity_model==6) { - if (ParticleDiameter()==.0) { - std::cout << "***Error: dp = .0" << std::endl; - exit(0); - } - forchheimer_cf = 0.55*(1.-5.5*ParticleDiameter()/forchheimer_De); - } - k_rel = 1.0/(1.0+forchheimer_cf*rhog*sqrt(k[0])/vis*v_mag); - } - } + { + assert (assem->PcsType==EnumProcessType::A || assem->PcsType==EnumProcessType::S); + ElementValue* gp_ele = ele_gp_value[index]; + //Velocity + double vel[3] = {}; + vel[0] = gp_ele->Velocity(0, gp); + vel[1] = gp_ele->Velocity(1, gp); + vel[2] = gp_ele->Velocity(2, gp); + double v_mag = sqrt(vel[0]*vel[0]+vel[1]*vel[1]+vel[2]*vel[2]); + if (v_mag != 0.0) { + double* k = PermeabilityTensor(index); //temporary assuming isotropic + double dens_arg[3] = {}; + dens_arg[0] = (1.0-theta)*assem->interpolate(assem->NodalVal0) + theta*assem->interpolate(assem->NodalVal1); + dens_arg[1] = (1.0-theta)*assem->interpolate(assem->NodalVal_t0) + + theta*assem->interpolate(assem->NodalVal_t1); + //dens_arg[1] = assem->interpolate(assem->NodalValC1)+T_KILVIN_ZERO; + dens_arg[2] = (1.0-theta)*assem->interpolate(assem->NodalVal_X0) + + theta*assem->interpolate(assem->NodalVal_X1); + //dens_arg[2] = index; + double vis = assem->FluidProp->Viscosity(dens_arg); + double rhog = assem->FluidProp->Density(dens_arg); // which model? + if (flowlinearity_model==6) { + if (ParticleDiameter()==.0) { + std::cout << "***Error: dp = .0" << std::endl; + exit(0); + } + forchheimer_cf = 0.55*(1.-5.5*ParticleDiameter()/forchheimer_De); + } + k_rel = 1.0/(1.0+forchheimer_cf*rhog*sqrt(k[0])/vis*v_mag); + } + } */ - if (flowlinearity_model==4) // general Forchheimer, -dp/dx = a1 q + a2 q^2 - { - assert (gp!=-1); - ElementValue* gp_ele = ele_gp_value[index]; - //Velocity - double vel[3] = {}; - vel[0] = gp_ele->Velocity(0, gp); - vel[1] = gp_ele->Velocity(1, gp); - vel[2] = gp_ele->Velocity(2, gp); - //double v_mag = sqrt(vel[0]*vel[0]+vel[1]*vel[1]+vel[2]*vel[2]); - double v_mag = MBtrgVec(vel, 3); + if (flowlinearity_model == 4) // general Forchheimer, -dp/dx = a1 q + a2 q^2 + { + assert(gp != -1); + ElementValue* gp_ele = ele_gp_value[index]; + // Velocity + double vel[3] = {}; + vel[0] = gp_ele->Velocity(0, gp); + vel[1] = gp_ele->Velocity(1, gp); + vel[2] = gp_ele->Velocity(2, gp); + // double v_mag = sqrt(vel[0]*vel[0]+vel[1]*vel[1]+vel[2]*vel[2]); + double v_mag = MBtrgVec(vel, 3); #ifdef STATIC_K1 - k_rel = 1.0/(1.0+forchheimer_a2/forchheimer_a1*v_mag); //k0=1/a1 + k_rel = 1.0 / (1.0 + forchheimer_a2 / forchheimer_a1 * v_mag); // k0=1/a1 #else - k_rel = 1.0/(forchheimer_a1+forchheimer_a2*v_mag); //k0=1.0 + k_rel = 1.0 / (forchheimer_a1 + forchheimer_a2 * v_mag); // k0=1.0 #endif - //if (k_rel!=1.0) - // std::cout << index << "-" << gp << ": k_rel=" << k_rel << endl; - } - else if (flowlinearity_model==5) // general Forchheimer, -dp/dx = a1 q + a2 q^2 - { - assert (gp!=-1); - ElementValue* gp_ele = ele_gp_value[index]; - //Velocity - double vel[3] = {}; - vel[0] = gp_ele->Velocity(0, gp); - vel[1] = gp_ele->Velocity(1, gp); - vel[2] = gp_ele->Velocity(2, gp); - //double v_mag = sqrt(vel[0]*vel[0]+vel[1]*vel[1]+vel[2]*vel[2]); - double v_mag = MBtrgVec(vel, 3); - if (v_mag != 0.0) { - double *k_tensor = assem->MediaProp->PermeabilityTensor(index); - double k0 = k_tensor[0]; - k_rel = 1.0/(1.0+forchheimer_a2*k0*v_mag); - } - } - else - { - std::cout << "***ERROR: not supported flow linearity model " << flowlinearity_model << std::endl; - } + // if (k_rel!=1.0) + // std::cout << index << "-" << gp << ": k_rel=" << k_rel << endl; + } + else if (flowlinearity_model == 5) // general Forchheimer, -dp/dx = a1 q + a2 q^2 + { + assert(gp != -1); + ElementValue* gp_ele = ele_gp_value[index]; + // Velocity + double vel[3] = {}; + vel[0] = gp_ele->Velocity(0, gp); + vel[1] = gp_ele->Velocity(1, gp); + vel[2] = gp_ele->Velocity(2, gp); + // double v_mag = sqrt(vel[0]*vel[0]+vel[1]*vel[1]+vel[2]*vel[2]); + double v_mag = MBtrgVec(vel, 3); + if (v_mag != 0.0) + { + double* k_tensor = assem->MediaProp->PermeabilityTensor(index); + double k0 = k_tensor[0]; + k_rel = 1.0 / (1.0 + forchheimer_a2 * k0 * v_mag); + } + } + else + { + std::cout << "***ERROR: not supported flow linearity model " << flowlinearity_model << std::endl; + } /*OK411 //Pressure variable name (PRESSURE 1) not used as yet in this function @@ -7234,7 +7141,8 @@ double CMediumProperties::NonlinearFlowFunction(long index, int gp, double /*the //Input parameters porosity = CMediumProperties::Porosity(index,theta); alpha = flowlinearity_model_values[0]; - apperture = porosity / flowlinearity_model_values[1]; //Change equivalent porosity to individual fracture porosity + apperture = porosity / flowlinearity_model_values[1]; //Change equivalent porosity to individual fracture + porosity Re = flowlinearity_model_values[2]; //Fluid properties @@ -7326,33 +7234,33 @@ double CMediumProperties::NonlinearFlowFunction(long index, int gp, double /*the 6 Storage as normal stress in element in stress field defined by KTB stress field, function to increase storage with distance from borehole. **************************************************************************/ -double CMediumProperties::StorageFunction(long index,double* gp,double theta) +double CMediumProperties::StorageFunction(long index, double* gp, double theta) { - //OK411 + // OK411 theta = theta; gp = gp; index = index; - //int nn, i, Type; - //int idummy; - //double p; //WW, sigma, z[8]; - //int phase; - //double density_solid, stress_eff,S; - //double coords[3]; - //double znodes[8],ynodes[8],xnodes[8]; - //double zelnodes[8],yelnodes[8],xelnodes[8]; - //double Pie,angle; - //double sigma1,sigma2,sigma3; - //double a1,a2,a3,b1,b2,b3; - //double normx,normy,normz,normlen; - //WW double dircosl, dircosm, dircosn; - //double tot_norm_stress, eff_norm_stress; - //int material_group; - //double x_mid, y_mid, z_mid, x_bore, y_bore, z_bore, distance; - //WW dircosl = dircosm = dircosn = 0.0; //Initialise variable + // int nn, i, Type; + // int idummy; + // double p; //WW, sigma, z[8]; + // int phase; + // double density_solid, stress_eff,S; + // double coords[3]; + // double znodes[8],ynodes[8],xnodes[8]; + // double zelnodes[8],yelnodes[8],xelnodes[8]; + // double Pie,angle; + // double sigma1,sigma2,sigma3; + // double a1,a2,a3,b1,b2,b3; + // double normx,normy,normz,normlen; + // WW double dircosl, dircosm, dircosn; + // double tot_norm_stress, eff_norm_stress; + // int material_group; + // double x_mid, y_mid, z_mid, x_bore, y_bore, z_bore, distance; + // WW dircosl = dircosm = dircosn = 0.0; //Initialise variable // static int nidx0,nidx1; - //double primary_variable[10]; //OK To Do - //int count_nodes; + // double primary_variable[10]; //OK To Do + // int count_nodes; /*OK411 long* element_nodes = NULL; int no_pcs_names =(int)pcs_name_vector.size(); @@ -7383,210 +7291,88 @@ double CMediumProperties::StorageFunction(long index,double* gp,double theta) */ switch (storage_model) { - case 0: - - //OK411 storage = GetCurveValue((int) storage_model_values[0], 0, primary_variable[0], &idummy); - - break; - - case 1: - // Konstanter Wert - storage = storage_model_values[0]; - break; - - case 2: - // Funktion der effektiven Spannung und des Drucks in Elementmitte -#ifdef obsolete //WW. 06.11.2008 - // Den Druck holen - p = primary_variable[0]; - - /* Mittlere Tiefe */ - nn = ElNumberOfNodes[ElGetElementType(index) - 1]; - element_nodes = ElGetElementNodes(index); - - for (i = 0; i < nn; i++) - z[i] = GetNodeZ(element_nodes[i]); - - /* Spannung = sigma(z0) + d_sigma/d_z*z */ - //OKsigma = storage_model_values[2] + storage_model_values[3] * InterpolValueVector(index, z, 0., 0., 0.); - sigma = storage_model_values[2] + storage_model_values[3] * InterpolValueVector( - ElGetElementType(index), - z, - 0., - 0., - 0.); - - /* Auf effektive Spannung umrechnen */ - sigma -= p; - - storage = exp(storage_model_values[0] - storage_model_values[1] * log(sigma)); -#endif //#ifdef obsolete //WW. 06.11.2008 - break; - - case 3: - /* Funktion der effektiven Spannung und des Drucks in Elementmitte - ueber Kurve */ -#ifdef obsolete //WW. 06.11.2008 - /* Den Druck holen */ - p = primary_variable[0]; - - /* Mittlere Tiefe */ - nn = ElNumberOfNodes[ElGetElementType(index) - 1]; - element_nodes = ElGetElementNodes(index); - - for (i = 0; i < nn; i++) - z[i] = GetNodeZ(element_nodes[i]); - - /* Spannung = sigma(z0) + d_sigma/d_z*z */ - sigma = storage_model_values[1] + storage_model_values[2] * InterpolValueVector( - ElGetElementType(index), - z, - 0., - 0., - 0.); - - /* Auf effektive Spannung umrechnen */ - sigma -= p; - - storage = GetCurveValue((int)storage_model_values[0],0,sigma,&i); -#endif - break; + case 0: - case 4: /* McD Storage as function of effective stress read from curve */ - /*OK411 - CalculateSimpleMiddelPointElement(index, coords); - p = primary_variable[0]; - density_solid = storage_model_values[2]; - stress_eff = (fabs(coords[2])*gravity_constant*density_solid) - p; - storage =GetCurveValue((int) storage_model_values[0], 0, stress_eff, &idummy); - break; - */ - case 5: /* Stroage : Normal stress calculated according to the orientation of the fracture element*/ - /*OK411 - Type=ElGetElementType(index); - material_group = ElGetElementGroupNumber(index); + // OK411 storage = GetCurveValue((int) storage_model_values[0], 0, primary_variable[0], &idummy); - if (Type == 2||Type == 3||Type == 4) //Function defined for square, triangular and cubic elements - { - nn = ElNumberOfNodes[Type - 1]; - element_nodes = ElGetElementNodes(index); + break; - for (i=0;i220000000.){ - phase=0; - } + /* Auf effektive Spannung umrechnen */ + sigma -= p; - //Take value of storage from a curve - S=GetCurveValue((int) storage_model_values[0], 0, eff_norm_stress, &idummy); - } + storage = GetCurveValue((int)storage_model_values[0], 0, sigma, &i); +#endif + break; - // default value if element type is not included in the method for calculating the normal - else S=storage_model_values[2]; - storage = S; - break; - */ - case 6: /* Normal stress calculated according to the orientation of the fracture element*/ + case 4: /* McD Storage as function of effective stress read from curve */ + /*OK411 + CalculateSimpleMiddelPointElement(index, coords); + p = primary_variable[0]; + density_solid = storage_model_values[2]; + stress_eff = (fabs(coords[2])*gravity_constant*density_solid) - p; + storage =GetCurveValue((int) storage_model_values[0], 0, stress_eff, &idummy); + break; + */ + case 5: /* Stroage : Normal stress calculated according to the orientation of the fracture element*/ /*OK411 Type=ElGetElementType(index); material_group = ElGetElementGroupNumber(index); - if (material_group == 0) - { - if (Type == 2||Type == 3||Type == 4) + if (Type == 2||Type == 3||Type == 4) //Function defined for square, triangular and cubic elements { nn = ElNumberOfNodes[Type - 1]; element_nodes = ElGetElementNodes(index); - for (i=0;i storage_model_values[7]){ - distance = storage_model_values[7]; - } - if (distance > 2) S = S + (S * (distance-2) * storage_model_values[8]); + // special stop CMCD + if (eff_norm_stress>220000000.){ + phase=0; } - else S=storage_model_values[2]; + //Take value of storage from a curve + S=GetCurveValue((int) storage_model_values[0], 0, eff_norm_stress, &idummy); } + // default value if element type is not included in the method for calculating the normal else S=storage_model_values[2]; storage = S; + break; */ - break; - case 7: // poroelasticity RW - storage = storage_model_values[1]; - break; - case 10: - if(permeability_saturation_model[0]==10) //MW - storage = porosity_model_values[0] / ( gravity_constant * gravity_constant * mfp_vector[0]->Density()); - // MW I have no idea, why I need 1/(g^2*rho) here; it should only be 1/(g*rho) - // maybe, the mass term in richards flow has been normalized on g ??? - else - std::cout << "Wrong PERMEABILITY_SATURATION_MODEL for STORAGE model 10." << std::endl; - break; - case 11: - if(m_pcs->getProcessType()==FiniteElement::LIQUID_FLOW) - storage = porosity_model_values[0] / ( gravity_constant * mfp_vector[0]->Density()); - else - std::cout << "Wrong process type for STORAGE model 11 (only intended for LIQUID_FLOW)." << std::endl; - break; - default: - storage = 0.0; //OK DisplayMsgLn("The requested storativity model is unknown!!!"); - break; + case 6: /* Normal stress calculated according to the orientation of the fracture element*/ + /*OK411 + Type=ElGetElementType(index); + material_group = ElGetElementGroupNumber(index); + + if (material_group == 0) + { + if (Type == 2||Type == 3||Type == 4) + { + nn = ElNumberOfNodes[Type - 1]; + element_nodes = ElGetElementNodes(index); + + for (i=0;i storage_model_values[7]){ + distance = storage_model_values[7]; + } + if (distance > 2) S = S + (S * (distance-2) * storage_model_values[8]); + } + + else S=storage_model_values[2]; + } + + else S=storage_model_values[2]; + storage = S; + */ + break; + case 7: // poroelasticity RW + storage = storage_model_values[1]; + break; + case 10: + if (permeability_saturation_model[0] == 10) // MW + storage = porosity_model_values[0] / (gravity_constant * gravity_constant * mfp_vector[0]->Density()); + // MW I have no idea, why I need 1/(g^2*rho) here; it should only be 1/(g*rho) + // maybe, the mass term in richards flow has been normalized on g ??? + else + std::cout << "Wrong PERMEABILITY_SATURATION_MODEL for STORAGE model 10." << std::endl; + break; + case 11: + if (m_pcs->getProcessType() == FiniteElement::LIQUID_FLOW) + storage = porosity_model_values[0] / (gravity_constant * mfp_vector[0]->Density()); + else + std::cout << "Wrong process type for STORAGE model 11 (only intended for LIQUID_FLOW)." << std::endl; + break; + default: + storage = 0.0; // OK DisplayMsgLn("The requested storativity model is unknown!!!"); + break; } return storage; } -//AS:08.2012 storgae function eff stress -double CMediumProperties::StorageFunctionEffStress(long index, int nnodes, CFiniteElementStd *h_fem) +// AS:08.2012 storgae function eff stress +double CMediumProperties::StorageFunctionEffStress(long index, int nnodes, CFiniteElementStd* h_fem) { int i, j, size; double storage_stress = 1.0; - //calculate principal effective stress - double stress[6]={0.}, prin_str[6]={0.}, prin_dir[9]={0.}; + // calculate principal effective stress + double stress[6] = {0.}, prin_str[6] = {0.}, prin_dir[9] = {0.}; int stress_index[6]; - //model dimension - int dim = h_fem->dm_pcs->m_msh->GetCoordinateFlag()/10; + // model dimension + int dim = h_fem->dm_pcs->m_msh->GetCoordinateFlag() / 10; size = 6; - if (dim==2) + if (dim == 2) { - size=4; - if(h_fem->axisymmetry) - dim=3; + size = 4; + if (h_fem->axisymmetry) + dim = 3; } stress_index[0] = h_fem->dm_pcs->GetNodeValueIndex("STRESS_XX"); stress_index[1] = h_fem->dm_pcs->GetNodeValueIndex("STRESS_YY"); stress_index[2] = h_fem->dm_pcs->GetNodeValueIndex("STRESS_ZZ"); stress_index[3] = h_fem->dm_pcs->GetNodeValueIndex("STRESS_XY"); - if(size==6) + if (size == 6) { stress_index[4] = h_fem->dm_pcs->GetNodeValueIndex("STRESS_XZ"); stress_index[5] = h_fem->dm_pcs->GetNodeValueIndex("STRESS_YZ"); } - double stress_nodes[20]={0.}; + double stress_nodes[20] = {0.}; - switch(storage_effstress_model) + switch (storage_effstress_model) { - //AS: case 1, permeability directly calculated from curve. 16.08.2012 - case 1: - for (j=0; jdm_pcs->GetNodeValue( - h_fem->dm_pcs->m_msh->ele_vector[index]->getNodeIndices()[i], - stress_index[j]); - stress[j] = h_fem->interpolate(stress_nodes); - } - h_fem->SolidProp->CalPrinStrDir(stress, prin_str, prin_dir, dim); - //permeability from curve with minimum (absolute value) principal effective stress as input - storage_stress = GetCurveValue((int)storage_effstress_model_value[0], 0, prin_str[0], &i); - break; - default: - break; + // AS: case 1, permeability directly calculated from curve. 16.08.2012 + case 1: + for (j = 0; j < size; j++) + { + for (i = 0; i < nnodes; i++) + stress_nodes[i] = h_fem->dm_pcs->GetNodeValue( + h_fem->dm_pcs->m_msh->ele_vector[index]->getNodeIndices()[i], stress_index[j]); + stress[j] = h_fem->interpolate(stress_nodes); + } + h_fem->SolidProp->CalPrinStrDir(stress, prin_str, prin_dir, dim); + // permeability from curve with minimum (absolute value) principal effective stress as input + storage_stress = GetCurveValue((int)storage_effstress_model_value[0], 0, prin_str[0], &i); + break; + default: + break; } return storage_stress; } -double CMediumProperties::PermeabilityPressureFunction(long index,double* gp,double theta) +double CMediumProperties::PermeabilityPressureFunction(long index, double* gp, double theta) { double k_rel = 0.0; - //OK411 + // OK411 theta = theta; gp = gp; index = index; -#ifdef obsolete //OK411 - int nn, i, idummy,p_idx1; +#ifdef obsolete // OK411 + int nn, i, idummy, p_idx1; long* element_nodes; - static double gh, p, eins_durch_rho_g, sigma, z[8], h[8], grad_h[3]; + static double gh, p, eins_durch_rho_g, sigma, z[8], h[8], grad_h[3]; static double invjac[8], detjac, grad_omega[8]; static double mult[3]; - double x_mid,y_mid,z_mid,coords[3]; + double x_mid, y_mid, z_mid, coords[3]; double density_solid, stress_eff; // double porosity, factora, factorb,valuelogk; CFluidProperties* m_mfp = NULL; - //Collect primary variables - static int nidx0,nidx1; - double primary_variable[10]; //OK To Do + // Collect primary variables + static int nidx0, nidx1; + double primary_variable[10]; // OK To Do int count_nodes; int no_pcs_names = (int)pcs_name_vector.size(); - for(i = 0; i < no_pcs_names; i++) + for (i = 0; i < no_pcs_names; i++) { - nidx0 = PCSGetNODValueIndex(pcs_name_vector[i],0); - nidx1 = PCSGetNODValueIndex(pcs_name_vector[i],1); - if(mode == 0) // Gauss point values - - primary_variable[i] = (1. - theta) * InterpolValue(number, - nidx0, - gp[0], - gp[1], - gp[2]) \ - + theta* InterpolValue(number,nidx1,gp[0],gp[1],gp[2]); - else if(mode == 1) // Node values - - primary_variable[i] = (1. - theta) * GetNodeVal(number,nidx0) \ - + theta* GetNodeVal(number,nidx1); - else if(mode == 2) // Element average value + nidx0 = PCSGetNODValueIndex(pcs_name_vector[i], 0); + nidx1 = PCSGetNODValueIndex(pcs_name_vector[i], 1); + if (mode == 0) // Gauss point values + + primary_variable[i] = (1. - theta) * InterpolValue(number, nidx0, gp[0], gp[1], gp[2]) + + theta * InterpolValue(number, nidx1, gp[0], gp[1], gp[2]); + else if (mode == 1) // Node values + + primary_variable[i] = (1. - theta) * GetNodeVal(number, nidx0) + theta * GetNodeVal(number, nidx1); + else if (mode == 2) // Element average value { count_nodes = ElNumberOfNodes[ElGetElementType(number) - 1]; element_nodes = ElGetElementNodes(number); for (i = 0; i < count_nodes; i++) - primary_variable[i] += GetNodeVal(element_nodes[i],nidx1); + primary_variable[i] += GetNodeVal(element_nodes[i], nidx1); primary_variable[i] /= count_nodes; } } switch (permeability_pressure_model) { - case 0: //Curve function - k_rel = 1.0; - break; - case 1: //No functional dependence - k_rel = 1.0; - break; - /* Funktion der effektiven Spannung */ - case 2: -#ifdef obsolete //WW. 06.11.2008 - /* Den Druck holen */ - p = primary_variable[0]; - /* Mittlere Tiefe */ - nn = ElNumberOfNodes[ElGetElementType(index) - 1]; - element_nodes = ElGetElementNodes(index); - for (i = 0; i < nn; i++) - z[i] = GetNodeZ(element_nodes[i]); - /* Spannung = sigma(z0) + d_sigma/d_z*z */ - sigma = permeability_pressure_model_values[2] + - permeability_pressure_model_values[3] * InterpolValueVector( - ElGetElementType( - index), - z, - 0., - 0., - 0.); - /* Auf effektive Spannung umrechnen */ - sigma -= p; - k_rel = exp( - permeability_pressure_model_values[0] - - permeability_pressure_model_values[1] * - log(sigma)); -#endif - break; - case 3: /* Turbulentes Fliessen */ - /* k_rel = max(min((grad(h)*alpha1)^(alpha2-1), alpha4),alpha3) */ - m_mfp = MFPGet("LIQUID"); - // YDGetFluidDensity(0, index, 0., 0., 0., 1.); - eins_durch_rho_g = 1. / gravity_constant / m_mfp->Density(); - nn = ElNumberOfNodes[ElGetElementType(index) - 1]; - element_nodes = ElGetElementNodes(index); - p_idx1 = PCSGetNODValueIndex("PRESSURE1",1); - for (i = 0; i < nn; i++) - h[i] = GetNodeVal(element_nodes[i], p_idx1) * eins_durch_rho_g - + GetNodeZ(element_nodes[i]); - switch (ElGetElementType(index)) - { - default: - DisplayMsgLn("Error in GetSoilRelPermPress!"); - DisplayMsgLn(" Nonlinear permeability not available!"); - abort(); + case 0: // Curve function + k_rel = 1.0; + break; + case 1: // No functional dependence + k_rel = 1.0; + break; + /* Funktion der effektiven Spannung */ case 2: - Calc2DElementJacobiMatrix(index,0.0,0.0,invjac,&detjac); - MGradOmega2D(grad_omega,0,0); /* Gradientenmatrix */ - MMultMatVec(grad_omega,2,4,h,4,mult,2); - MMultVecMat(mult,2,invjac,2,2,grad_h,2); - gh = - sqrt(grad_h[0] * grad_h[0] + grad_h[1] * - grad_h[1]) * permeability_pressure_model_values[0]; - if(gh < MKleinsteZahl) - k_rel = 1.0; - else - k_rel = - max(min(pow(gh, - permeability_pressure_model_values[1] - 1.0), - permeability_pressure_model_values[3]), - permeability_pressure_model_values[2]); - } - case 4: -#ifdef obsolete //WW. 06.11.2008 - /* Funktion der effektiven Spannung ueber Kurve */ - /* Den Druck holen */ - p = primary_variable[0]; - /* Mittlere Tiefe */ - nn = ElNumberOfNodes[ElGetElementType(index) - 1]; - element_nodes = ElGetElementNodes(index); - for (i = 0; i < nn; i++) - z[i] = GetNodeZ(element_nodes[i]); - /* Spannung = sigma(z0) + d_sigma/d_z*z */ - sigma = permeability_pressure_model_values[1] + - permeability_pressure_model_values[2] * InterpolValueVector( - ElGetElementType( - index), - z, - 0., - 0., - 0.); - /* Auf effektive Spannung umrechnen */ - sigma -= p; - k_rel = GetCurveValue((int)permeability_pressure_model_values[0], 0, sigma, &i); +#ifdef obsolete // WW. 06.11.2008 + /* Den Druck holen */ + p = primary_variable[0]; + /* Mittlere Tiefe */ + nn = ElNumberOfNodes[ElGetElementType(index) - 1]; + element_nodes = ElGetElementNodes(index); + for (i = 0; i < nn; i++) + z[i] = GetNodeZ(element_nodes[i]); + /* Spannung = sigma(z0) + d_sigma/d_z*z */ + sigma + = permeability_pressure_model_values[2] + + permeability_pressure_model_values[3] * InterpolValueVector(ElGetElementType(index), z, 0., 0., 0.); + /* Auf effektive Spannung umrechnen */ + sigma -= p; + k_rel = exp(permeability_pressure_model_values[0] - permeability_pressure_model_values[1] * log(sigma)); #endif - break; - case 5: - /* Funktion der effektiven Spannung ueber Kurve CMCD 26.06.2003*/ - /* Average depth */ - CalculateSimpleMiddelPointElement(index,coords); - x_mid = coords[0]; - y_mid = coords[1]; - z_mid = coords[2]; - p = primary_variable[0]; - density_solid = permeability_pressure_model_values[2]; - stress_eff = (fabs(z_mid) * gravity_constant * density_solid) - p; - k_rel = GetCurveValue((int) permeability_pressure_model_values[0], - 0, - stress_eff, - &idummy); - break; - case 6: - k_rel = PermeabilityPressureFunctionMethod1(index,primary_variable[0]); - break; - case 7: - k_rel = PermeabilityPressureFunctionMethod2(index,primary_variable[0]); - break; - case 8: - k_rel = PermeabilityPressureFunctionMethod3(index,primary_variable[0]); - break; - case 9: - k_rel = PermeabilityPressureFunctionMethod4(index, - primary_variable[0], - primary_variable[1]); - break; - default: // CMCD Einbau - k_rel = 1.0; // CMCD Einbau - break; // CMCD Einbau + break; + case 3: /* Turbulentes Fliessen */ + /* k_rel = max(min((grad(h)*alpha1)^(alpha2-1), alpha4),alpha3) */ + m_mfp = MFPGet("LIQUID"); + // YDGetFluidDensity(0, index, 0., 0., 0., 1.); + eins_durch_rho_g = 1. / gravity_constant / m_mfp->Density(); + nn = ElNumberOfNodes[ElGetElementType(index) - 1]; + element_nodes = ElGetElementNodes(index); + p_idx1 = PCSGetNODValueIndex("PRESSURE1", 1); + for (i = 0; i < nn; i++) + h[i] = GetNodeVal(element_nodes[i], p_idx1) * eins_durch_rho_g + GetNodeZ(element_nodes[i]); + switch (ElGetElementType(index)) + { + default: + DisplayMsgLn("Error in GetSoilRelPermPress!"); + DisplayMsgLn(" Nonlinear permeability not available!"); + abort(); + case 2: + Calc2DElementJacobiMatrix(index, 0.0, 0.0, invjac, &detjac); + MGradOmega2D(grad_omega, 0, 0); /* Gradientenmatrix */ + MMultMatVec(grad_omega, 2, 4, h, 4, mult, 2); + MMultVecMat(mult, 2, invjac, 2, 2, grad_h, 2); + gh = sqrt(grad_h[0] * grad_h[0] + grad_h[1] * grad_h[1]) * permeability_pressure_model_values[0]; + if (gh < MKleinsteZahl) + k_rel = 1.0; + else + k_rel = max(min(pow(gh, permeability_pressure_model_values[1] - 1.0), + permeability_pressure_model_values[3]), + permeability_pressure_model_values[2]); + } + case 4: +#ifdef obsolete // WW. 06.11.2008 + /* Funktion der effektiven Spannung ueber Kurve */ + /* Den Druck holen */ + p = primary_variable[0]; + /* Mittlere Tiefe */ + nn = ElNumberOfNodes[ElGetElementType(index) - 1]; + element_nodes = ElGetElementNodes(index); + for (i = 0; i < nn; i++) + z[i] = GetNodeZ(element_nodes[i]); + /* Spannung = sigma(z0) + d_sigma/d_z*z */ + sigma + = permeability_pressure_model_values[1] + + permeability_pressure_model_values[2] * InterpolValueVector(ElGetElementType(index), z, 0., 0., 0.); + /* Auf effektive Spannung umrechnen */ + sigma -= p; + k_rel = GetCurveValue((int)permeability_pressure_model_values[0], 0, sigma, &i); +#endif + break; + case 5: + /* Funktion der effektiven Spannung ueber Kurve CMCD 26.06.2003*/ + /* Average depth */ + CalculateSimpleMiddelPointElement(index, coords); + x_mid = coords[0]; + y_mid = coords[1]; + z_mid = coords[2]; + p = primary_variable[0]; + density_solid = permeability_pressure_model_values[2]; + stress_eff = (fabs(z_mid) * gravity_constant * density_solid) - p; + k_rel = GetCurveValue((int)permeability_pressure_model_values[0], 0, stress_eff, &idummy); + break; + case 6: + k_rel = PermeabilityPressureFunctionMethod1(index, primary_variable[0]); + break; + case 7: + k_rel = PermeabilityPressureFunctionMethod2(index, primary_variable[0]); + break; + case 8: + k_rel = PermeabilityPressureFunctionMethod3(index, primary_variable[0]); + break; + case 9: + k_rel = PermeabilityPressureFunctionMethod4(index, primary_variable[0], primary_variable[1]); + break; + default: // CMCD Einbau + k_rel = 1.0; // CMCD Einbau + break; // CMCD Einbau } #endif return k_rel; @@ -7962,24 +7833,24 @@ double CMediumProperties::PermeabilityPressureFunction(long index,double* gp,dou Programmaenderungen: 09/2004 CMCD Inclusion in GeoSys 4 **************************************************************************/ -double CMediumProperties::PermeabilityPressureFunctionMethod1(long index,double pressure) +double CMediumProperties::PermeabilityPressureFunctionMethod1(long index, double pressure) { - //OK411 + // OK411 index = index; pressure = pressure; -#ifdef obsolete //OK411 - double R,Pie,p; - double znodes[8],ynodes[8],xnodes[8], angle; +#ifdef obsolete // OK411 + double R, Pie, p; + double znodes[8], ynodes[8], xnodes[8], angle; double x_mid, y_mid, z_mid, coords[3]; - double zelnodes[8],yelnodes[8],xelnodes[8]; - double sigma1,sigma2,sigma3; - double a1,a2,a3,b1,b2,b3; - double normx,normy,normz,normlen; + double zelnodes[8], yelnodes[8], xelnodes[8]; + double sigma1, sigma2, sigma3; + double a1, a2, a3, b1, b2, b3; + double normx, normy, normz, normlen; double dircosl, dircosm, dircosn; double tot_norm_stress, eff_norm_stress; - int material_group,Type; - int phase,nn,i,idummy; + int material_group, Type; + int phase, nn, i, idummy; long* element_nodes; dircosl = dircosm = dircosn = 0.0; Type = ElGetElementType(index); @@ -8020,7 +7891,7 @@ double CMediumProperties::PermeabilityPressureFunctionMethod1(long index,double ynodes[i] = xelnodes[i] * sin(angle) + yelnodes[i] * cos(angle); } - if (Type == 2) /*Square*/ + if (Type == 2) /*Square*/ { a1 = xnodes[2] - xnodes[0]; a2 = ynodes[2] - ynodes[0]; @@ -8037,7 +7908,7 @@ double CMediumProperties::PermeabilityPressureFunctionMethod1(long index,double dircosn = normx / normlen; } - if (Type == 3) /*Cube*/ + if (Type == 3) /*Cube*/ { a1 = xnodes[2] - xnodes[0]; a2 = ynodes[2] - ynodes[0]; @@ -8054,7 +7925,7 @@ double CMediumProperties::PermeabilityPressureFunctionMethod1(long index,double dircosn = normx / normlen; } - if (Type == 4) /*Triangle*/ + if (Type == 4) /*Triangle*/ { a1 = xnodes[1] - xnodes[0]; a2 = ynodes[1] - ynodes[0]; @@ -8072,7 +7943,7 @@ double CMediumProperties::PermeabilityPressureFunctionMethod1(long index,double } /* Calculation of average location of element*/ - CalculateSimpleMiddelPointElement(index,coords); + CalculateSimpleMiddelPointElement(index, coords); x_mid = coords[0]; y_mid = coords[1]; z_mid = coords[2]; @@ -8087,17 +7958,13 @@ double CMediumProperties::PermeabilityPressureFunctionMethod1(long index,double /*Calculate total normal stress on element Note in this case sigma2 corresponds to the vertical stress*/ - tot_norm_stress = sigma1 * dircosl * dircosl + sigma2 * dircosm * dircosm + - sigma3 * dircosn * dircosn; + tot_norm_stress = sigma1 * dircosl * dircosl + sigma2 * dircosm * dircosm + sigma3 * dircosn * dircosn; /*Calculate normal effective stress*/ eff_norm_stress = tot_norm_stress - p; /*Take value of storage from a curve*/ - R = GetCurveValue((int) permeability_pressure_model_values[0], - 0, - eff_norm_stress, - &idummy); + R = GetCurveValue((int)permeability_pressure_model_values[0], 0, eff_norm_stress, &idummy); return R; } @@ -8129,25 +7996,25 @@ double CMediumProperties::PermeabilityPressureFunctionMethod1(long index,double Programmaenderungen: 09/2004 CMCD Inclusion in GeoSys 4 **************************************************************************/ -double CMediumProperties::PermeabilityPressureFunctionMethod2(long index,double pressure) +double CMediumProperties::PermeabilityPressureFunctionMethod2(long index, double pressure) { - //OK411 + // OK411 index = index; pressure = pressure; -#ifdef obsolete //OK411 - double R,Pie,p; - double znodes[8],ynodes[8],xnodes[8], angle; +#ifdef obsolete // OK411 + double R, Pie, p; + double znodes[8], ynodes[8], xnodes[8], angle; double x_mid, y_mid, z_mid, coords[3]; - double zelnodes[8],yelnodes[8],xelnodes[8]; - double sigma1,sigma2,sigma3; - double a1,a2,a3,b1,b2,b3; - double normx,normy,normz,normlen; + double zelnodes[8], yelnodes[8], xelnodes[8]; + double sigma1, sigma2, sigma3; + double a1, a2, a3, b1, b2, b3; + double normx, normy, normz, normlen; double dircosl, dircosm, dircosn; double tot_norm_stress, eff_norm_stress; - int material_group,Type; + int material_group, Type; double x_bore, y_bore, z_bore, distance; - int nn,i,idummy; + int nn, i, idummy; long* element_nodes; dircosl = dircosm = dircosn = 0.0; Type = ElGetElementType(index); @@ -8186,7 +8053,7 @@ double CMediumProperties::PermeabilityPressureFunctionMethod2(long index,double ynodes[i] = xelnodes[i] * sin(angle) + yelnodes[i] * cos(angle); } - if (Type == 2) /*Square*/ + if (Type == 2) /*Square*/ { a1 = xnodes[2] - xnodes[0]; a2 = ynodes[2] - ynodes[0]; @@ -8203,7 +8070,7 @@ double CMediumProperties::PermeabilityPressureFunctionMethod2(long index,double dircosn = normx / normlen; } - if (Type == 3) /*Cube*/ + if (Type == 3) /*Cube*/ { a1 = xnodes[2] - xnodes[0]; a2 = ynodes[2] - ynodes[0]; @@ -8220,7 +8087,7 @@ double CMediumProperties::PermeabilityPressureFunctionMethod2(long index,double dircosn = normx / normlen; } - if (Type == 4) /*Triangle*/ + if (Type == 4) /*Triangle*/ { a1 = xnodes[1] - xnodes[0]; a2 = ynodes[1] - ynodes[0]; @@ -8237,7 +8104,7 @@ double CMediumProperties::PermeabilityPressureFunctionMethod2(long index,double dircosn = normx / normlen; } - CalculateSimpleMiddelPointElement(index,coords); + CalculateSimpleMiddelPointElement(index, coords); x_mid = coords[0]; y_mid = coords[1]; z_mid = coords[2]; @@ -8250,14 +8117,8 @@ double CMediumProperties::PermeabilityPressureFunctionMethod2(long index,double y_bore = permeability_pressure_model_values[5]; z_bore = permeability_pressure_model_values[6]; - distance = - sqrt( - (x_mid - - x_bore) * - (x_mid - - x_bore) + - (y_mid - - y_bore) * (y_mid - y_bore) + (z_mid - z_bore) * (z_mid - z_bore)); + distance = sqrt((x_mid - x_bore) * (x_mid - x_bore) + (y_mid - y_bore) * (y_mid - y_bore) + + (z_mid - z_bore) * (z_mid - z_bore)); /*Calcualtion of stress according to Ito & Zoback 2000 for KTB hole*/ @@ -8265,19 +8126,15 @@ double CMediumProperties::PermeabilityPressureFunctionMethod2(long index,double sigma2 = z_mid * 0.028 * -1e6; sigma3 = z_mid * 0.02 * -1e6; - ///Calculate total normal stress on element + /// Calculate total normal stress on element /*Note in this case sigma2 corresponds to the vertical stress*/ - tot_norm_stress = sigma1 * dircosl * dircosl + sigma2 * dircosm * dircosm + - sigma3 * dircosn * dircosn; + tot_norm_stress = sigma1 * dircosl * dircosl + sigma2 * dircosm * dircosm + sigma3 * dircosn * dircosn; /*Calculate normal effective stress*/ eff_norm_stress = tot_norm_stress - p; /*Take value of storage from a curve*/ - R = GetCurveValue((int) permeability_pressure_model_values[0], - 0, - eff_norm_stress, - &idummy); + R = GetCurveValue((int)permeability_pressure_model_values[0], 0, eff_norm_stress, &idummy); if (distance > permeability_pressure_model_values[7]) distance = permeability_pressure_model_values[7]; @@ -8313,20 +8170,20 @@ double CMediumProperties::PermeabilityPressureFunctionMethod2(long index,double Programmaenderungen: 09/2004 CMCD Inclusion in GeoSys 4 **************************************************************************/ -double CMediumProperties::PermeabilityPressureFunctionMethod3(long index,double pressure) +double CMediumProperties::PermeabilityPressureFunctionMethod3(long index, double pressure) { - //OK411 + // OK411 index = index; pressure = pressure; double perm = 0.0; -#ifdef obsolete //OK411 +#ifdef obsolete // OK411 /* Funktion der effektiven Spannung ueber Kurve CMCD 26.06.2003*/ double x_mid, y_mid, z_mid, coords[3]; - double stress_eff,p,perm; + double stress_eff, p, perm; int idummy; /* Average depth */ - CalculateSimpleMiddelPointElement(index,coords); + CalculateSimpleMiddelPointElement(index, coords); x_mid = coords[0]; y_mid = coords[1]; z_mid = coords[2]; @@ -8334,7 +8191,7 @@ double CMediumProperties::PermeabilityPressureFunctionMethod3(long index,double /*Calculate fluid pressure in element*/ p = pressure; stress_eff = (fabs(z_mid) * permeability_pressure_model_values[1] * 1e6) - p; - perm = GetCurveValue((int) permeability_pressure_model_values[0], 0, stress_eff, &idummy); + perm = GetCurveValue((int)permeability_pressure_model_values[0], 0, stress_eff, &idummy); #endif return perm; } @@ -8360,23 +8217,21 @@ double CMediumProperties::PermeabilityPressureFunctionMethod3(long index,double Programmaenderungen: 09/2004 CMCD Inclusion in GeoSys 4 **************************************************************************/ -double CMediumProperties::PermeabilityPressureFunctionMethod4(long index, - double pressure, - double temperature) +double CMediumProperties::PermeabilityPressureFunctionMethod4(long index, double pressure, double temperature) { - //OK411 + // OK411 index = index; pressure = pressure; temperature = temperature; double perm = 0.0; -#ifdef obsolete //OK411 +#ifdef obsolete // OK411 /* Funktion der effektiven Spannung ueber Kurve CMCD 26.06.2003*/ double x_mid, y_mid, z_mid, coords[3]; - double stress_eff,p,perm, thermal_stress; + double stress_eff, p, perm, thermal_stress; int idummy; /* Average depth */ - CalculateSimpleMiddelPointElement(index,coords); + CalculateSimpleMiddelPointElement(index, coords); x_mid = coords[0]; y_mid = coords[1]; z_mid = coords[2]; @@ -8386,145 +8241,148 @@ double CMediumProperties::PermeabilityPressureFunctionMethod4(long index, stress_eff = (fabs(z_mid) * permeability_pressure_model_values[1] * 1e6) - p; /*Impact of thermal stress*/ - thermal_stress = - (permeability_pressure_model_values[2] - - temperature) * permeability_pressure_model_values[3] * - permeability_pressure_model_values[4]; + thermal_stress = (permeability_pressure_model_values[2] - temperature) * permeability_pressure_model_values[3] + * permeability_pressure_model_values[4]; stress_eff = stress_eff - thermal_stress; if (stress_eff < 0.0) stress_eff = 0.0; /*Read value effective stress against curve*/ - perm = GetCurveValue((int) permeability_pressure_model_values[0], 0, stress_eff, &idummy); + perm = GetCurveValue((int)permeability_pressure_model_values[0], 0, stress_eff, &idummy); #endif return perm; } -double CMediumProperties::PermeabilityPorosityFunction(long number,double* gp,double theta) +double CMediumProperties::PermeabilityPorosityFunction(long number, double* gp, double theta) { double k_rel = 0.0; - //OK411 + // OK411 theta = theta; gp = gp; number = number; -#ifdef obsolete //OK411 +#ifdef obsolete // OK411 int i; long* element_nodes; - double factora, factorb,valuelogk; + double factora, factorb, valuelogk; - //Collect primary variables - static int nidx0,nidx1; - double primary_variable[10]; //OK To Do + // Collect primary variables + static int nidx0, nidx1; + double primary_variable[10]; // OK To Do int count_nodes; int no_pcs_names = (int)pcs_name_vector.size(); - for(i = 0; i < no_pcs_names; i++) + for (i = 0; i < no_pcs_names; i++) { - nidx0 = PCSGetNODValueIndex(pcs_name_vector[i],0); - nidx1 = PCSGetNODValueIndex(pcs_name_vector[i],1); - if(mode == 0) // Gauss point values - - primary_variable[i] = (1. - theta) * InterpolValue(number, - nidx0, - gp[0], - gp[1], - gp[2]) \ - + theta* InterpolValue(number,nidx1,gp[0],gp[1],gp[2]); - else if(mode == 1) // Node values - - primary_variable[i] = (1. - theta) * GetNodeVal(number,nidx0) \ - + theta* GetNodeVal(number,nidx1); - else if(mode == 2) // Element average value + nidx0 = PCSGetNODValueIndex(pcs_name_vector[i], 0); + nidx1 = PCSGetNODValueIndex(pcs_name_vector[i], 1); + if (mode == 0) // Gauss point values + + primary_variable[i] = (1. - theta) * InterpolValue(number, nidx0, gp[0], gp[1], gp[2]) + + theta * InterpolValue(number, nidx1, gp[0], gp[1], gp[2]); + else if (mode == 1) // Node values + + primary_variable[i] = (1. - theta) * GetNodeVal(number, nidx0) + theta * GetNodeVal(number, nidx1); + else if (mode == 2) // Element average value { count_nodes = ElNumberOfNodes[ElGetElementType(number) - 1]; element_nodes = ElGetElementNodes(number); for (i = 0; i < count_nodes; i++) - primary_variable[i] += GetNodeVal(element_nodes[i],nidx1); + primary_variable[i] += GetNodeVal(element_nodes[i], nidx1); primary_variable[i] /= count_nodes; } } switch (permeability_porosity_model) { - case 0: //Reserved for a curve function - k_rel = 1.0; - break; - case 1: //Constant value function - k_rel = 1.0; - break; - case 2: //Ming Lian function - factora = permeability_porosity_model_values[0]; - factorb = permeability_porosity_model_values[1]; - valuelogk = factora + (factorb * porosity); - k_rel = 0.987e-12 * pow(10.,valuelogk); - CMediumProperties* m_mmp = NULL; - long group = ElGetElementGroupNumber(number); - m_mmp = mmp_vector[group]; - double* k_ij; - k_ij = m_mmp->PermeabilityTensor(number); //permeability; - k_rel /= k_ij[0]; - break; + case 0: // Reserved for a curve function + k_rel = 1.0; + break; + case 1: // Constant value function + k_rel = 1.0; + break; + case 2: // Ming Lian function + factora = permeability_porosity_model_values[0]; + factorb = permeability_porosity_model_values[1]; + valuelogk = factora + (factorb * porosity); + k_rel = 0.987e-12 * pow(10., valuelogk); + CMediumProperties* m_mmp = NULL; + long group = ElGetElementGroupNumber(number); + m_mmp = mmp_vector[group]; + double* k_ij; + k_ij = m_mmp->PermeabilityTensor(number); // permeability; + k_rel /= k_ij[0]; + break; } #endif return k_rel; } double CMediumProperties::ParticleDiameter() { - double val = .0; - switch (particle_diameter_model) { - case 0: - break; - case 1: - val = particle_diameter_model_value; - break; - default: - break; - } + double val = .0; + switch (particle_diameter_model) + { + case 0: + break; + case 1: + val = particle_diameter_model_value; + break; + default: + break; + } - return val; + return val; } -double CMediumProperties::HeatTransferCoefficient(long number,double theta, CFiniteElementStd* assem) +double CMediumProperties::HeatTransferCoefficient(long number, double theta, CFiniteElementStd* assem) { - double val = .0; - switch (heat_transfer_model) { - case 0: - break; - case 1: - val = heat_transfer_model_value; - break; - case 2: - { - const double dp = ParticleDiameter(); - assert (dp>.0); - double h = .0; - if (effective_heat_transfer_model==1) { - h = heat_transfer_model_value; - } else if (effective_heat_transfer_model==2) { - h = .0; - } else { - std::cout << "***Error: Effective heat transfer model is not supported. " << effective_heat_transfer_model << '\n'; - } - const double &n = Porosity(number, theta); - const int dimen = assem->pcs->m_msh->GetCoordinateFlag() / 10; - for (int i=0; i SolidProp->HeatConductivityTensor(dimen, heat_conductivity_tensor, assem->MeshElement->GetPatchIndex()); - const double lamda_s = heat_conductivity_tensor[0]; //assume isotropic - val = 6.*(1-n)/dp*1./(1./h+dp/10.0/lamda_s); // confirmed with DLR people. typo in Schaube2011 - } - break; - default: - break; - } + double val = .0; + switch (heat_transfer_model) + { + case 0: + break; + case 1: + val = heat_transfer_model_value; + break; + case 2: + { + const double dp = ParticleDiameter(); + assert(dp > .0); + double h = .0; + if (effective_heat_transfer_model == 1) + { + h = heat_transfer_model_value; + } + else if (effective_heat_transfer_model == 2) + { + h = .0; + } + else + { + std::cout << "***Error: Effective heat transfer model is not supported. " + << effective_heat_transfer_model << '\n'; + } + const double& n = Porosity(number, theta); + const int dimen = assem->pcs->m_msh->GetCoordinateFlag() / 10; + for (int i = 0; i < dimen * dimen; i++) + heat_conductivity_tensor[i] = 0.0; + assem->SolidProp->HeatConductivityTensor(dimen, heat_conductivity_tensor, + assem->MeshElement->GetPatchIndex()); + const double lamda_s = heat_conductivity_tensor[0]; // assume isotropic + val = 6. * (1 - n) / dp * 1. + / (1. / h + dp / 10.0 / lamda_s); // confirmed with DLR people. typo in Schaube2011 + } + break; + default: + break; + } - return val; + return val; } -//TN - added for TNEQ/TEQ process -void CMediumProperties::setFrictionPhase (FiniteElement::FrictionPhase fric_phase) +// TN - added for TNEQ/TEQ process +void CMediumProperties::setFrictionPhase(FiniteElement::FrictionPhase fric_phase) { _fric_phase = fric_phase; } -FiniteElement::FrictionPhase CMediumProperties::getFrictionPhase () const +FiniteElement::FrictionPhase CMediumProperties::getFrictionPhase() const { return _fric_phase; } diff --git a/FEM/rf_mmp_new.h b/FEM/rf_mmp_new.h index 4c0cae9b4..7ec0077fc 100644 --- a/FEM/rf_mmp_new.h +++ b/FEM/rf_mmp_new.h @@ -32,151 +32,148 @@ #include "rf_pcs.h" namespace FiniteElement -{class CFiniteElementStd; +{ +class CFiniteElementStd; } using FiniteElement::CFiniteElementStd; class CMediumProperties { public: CFiniteElementStd* Fem_Ele_Std; + private: - //WW + // WW friend class FiniteElement::CFiniteElementStd; // Data base - void SetMediumPropertiesDefaultsClay(void); //CMCD 9/2004 GeoSys 4 - void SetMediumPropertiesDefaultsSilt(void); //CMCD 9/2004 GeoSys 4 - void SetMediumPropertiesDefaultsSand(void); //CMCD 9/2004 GeoSys 4 - //CMCD 9/2004 GeoSys 4 + void SetMediumPropertiesDefaultsClay(void); // CMCD 9/2004 GeoSys 4 + void SetMediumPropertiesDefaultsSilt(void); // CMCD 9/2004 GeoSys 4 + void SetMediumPropertiesDefaultsSand(void); // CMCD 9/2004 GeoSys 4 + // CMCD 9/2004 GeoSys 4 void SetMediumPropertiesDefaultsGravel(void); - //CMCD 9/2004 GeoSys 4 + // CMCD 9/2004 GeoSys 4 void SetMediumPropertiesDefaultsCrystalline(void); - //CMCD 9/2004 GeoSys 4 + // CMCD 9/2004 GeoSys 4 void SetMediumPropertiesDefaultsBordenAquifer(void); // Porosity - //CMCD 9/2004 GeoSys 4 - double PorosityEffectiveStress(long,double ); - double PorosityVolumetricFreeSwellingConstantIonicstrength(long,double,double); - //MX 1/2005 - double PorosityEffectiveConstrainedSwelling(long,double,double, double*); - //MX 1/2005 - double PorosityVolumetricFreeSwelling(long,double,double); - //MX 1/2005 - double PorosityEffectiveConstrainedSwellingConstantIonicStrength(long, - double, - double, - double*); + // CMCD 9/2004 GeoSys 4 + double PorosityEffectiveStress(long, double); + double PorosityVolumetricFreeSwellingConstantIonicstrength(long, double, double); + // MX 1/2005 + double PorosityEffectiveConstrainedSwelling(long, double, double, double*); + // MX 1/2005 + double PorosityVolumetricFreeSwelling(long, double, double); + // MX 1/2005 + double PorosityEffectiveConstrainedSwellingConstantIonicStrength(long, double, double, double*); // Permeability // Permeabilty stress corrector WW double* c_coefficient; unsigned geo_dimension; - unsigned geo_inclination; //inclination of domain/sub domain from horizontal anticloclwise: AKS + unsigned geo_inclination; // inclination of domain/sub domain from horizontal anticloclwise: AKS int permeability_stress_mode; // - //CMCD 9/2004 GeoSys 4 - double PermeabilityPressureFunctionMethod1(long,double ); - //CMCD 9/2004 GeoSys 4 - double PermeabilityPressureFunctionMethod2(long,double ); - //CMCD 9/2004 GeoSys 4 - double PermeabilityPressureFunctionMethod3(long,double ); - //CMCD 9/2004 GeoSys 4 - double PermeabilityPressureFunctionMethod4(long,double, double ); + // CMCD 9/2004 GeoSys 4 + double PermeabilityPressureFunctionMethod1(long, double); + // CMCD 9/2004 GeoSys 4 + double PermeabilityPressureFunctionMethod2(long, double); + // CMCD 9/2004 GeoSys 4 + double PermeabilityPressureFunctionMethod3(long, double); + // CMCD 9/2004 GeoSys 4 + double PermeabilityPressureFunctionMethod4(long, double, double); friend class CMediumPropertiesGroup; - public: - //------------------------------------------- - // Methods - CMediumProperties(void); // constructor - ~CMediumProperties(void); // destructor - CMediumProperties* Get(std::string); - CMediumProperties* GetDB(std::string); - CMediumProperties* GetByGroupNumber(int); - void Set(std::string,std::string,double); - void SetDB(std::string,std::string,double); - int GetPropertyType(std::string); - std::ios::pos_type Read(std::ifstream*); - void Write(std::fstream*); - void WriteTecplot(std::string); - double* PermeabilityTensor(long index); - //CMCD 9/2004 GeoSys 4 + +public: + //------------------------------------------- + // Methods + CMediumProperties(void); // constructor + ~CMediumProperties(void); // destructor + CMediumProperties* Get(std::string); + CMediumProperties* GetDB(std::string); + CMediumProperties* GetByGroupNumber(int); + void Set(std::string, std::string, double); + void SetDB(std::string, std::string, double); + int GetPropertyType(std::string); + std::ios::pos_type Read(std::ifstream*); + void Write(std::fstream*); + void WriteTecplot(std::string); + double* PermeabilityTensor(long index); + // CMCD 9/2004 GeoSys 4 double Porosity(FiniteElement::CElement* assem = NULL); - //CMCD 9/2004 GeoSys 4 - double TortuosityFunction(long number, - double* gp, - double theta, - CFiniteElementStd* assem = NULL); - //CMCD 9/2004 GeoSys 4 - double NonlinearFlowFunction(long number, int gp, double theta, CFiniteElementStd* assem=NULL); - //CMCD 9/2004 GeoSys 4 - double PermeabilityPressureFunction(long index,double* gp,double theta); - //CMCD 9/2004 GeoSys 4 - double PermeabilityPorosityFunction(long index,double* gp,double theta); - double PermeabilityFunctionPressure(long index, double PG2); //WX: 05.2010 - double PermeabilityFunctionStrain(long index, int nnodes, CFiniteElementStd* h_fem); //WX - double PermeabilityFunctionEffStress(long index, int nnodes, CFiniteElementStd *h_fem);//AS:08.2012 - double StorageFunctionEffStress(long index, int nnodes, CFiniteElementStd *h_fem);//AS 08.2012 - double PorosityVolStrain(long index, double val0, CFiniteElementStd* assem); //WX: 03.2011 + // CMCD 9/2004 GeoSys 4 + double TortuosityFunction(long number, double* gp, double theta, CFiniteElementStd* assem = NULL); + // CMCD 9/2004 GeoSys 4 + double NonlinearFlowFunction(long number, int gp, double theta, CFiniteElementStd* assem = NULL); + // CMCD 9/2004 GeoSys 4 + double PermeabilityPressureFunction(long index, double* gp, double theta); + // CMCD 9/2004 GeoSys 4 + double PermeabilityPorosityFunction(long index, double* gp, double theta); + double PermeabilityFunctionPressure(long index, double PG2); // WX: 05.2010 + double PermeabilityFunctionStrain(long index, int nnodes, CFiniteElementStd* h_fem); // WX + double PermeabilityFunctionEffStress(long index, int nnodes, CFiniteElementStd* h_fem); // AS:08.2012 + double StorageFunctionEffStress(long index, int nnodes, CFiniteElementStd* h_fem); // AS 08.2012 + double PorosityVolStrain(long index, double val0, CFiniteElementStd* assem); // WX: 03.2011 double KozenyCarman(double k0 /*old permeability*/, double n0 /*old porosity*/, - double n /*new porosity*/); //HS: 11.2008 + double n /*new porosity*/); // HS: 11.2008 double KozenyCarman_normalized(double k0 /*old permeability*/, double n0 /*old porosity*/, - double n /*new porosity*/); //HS: 11.2008 - //WW - double KozenyCarmanNew(double k_init, double n_init, double n_t); //AB - double VermaPruess(double k_init, double n_init, double n_t); //AB + double n /*new porosity*/); // HS: 11.2008 + // WW + double KozenyCarmanNew(double k_init, double n_init, double n_t); // AB + double VermaPruess(double k_init, double n_init, double n_t); // AB void CalStressPermeabilityFactor(double* kfac, const double T = 273.0); - //WW + // WW void CalStressPermeabilityFactor2(double* kfac, const double T = 273.0); - //WW + // WW void CalStressPermeabilityFactor3(double* kfac); - void CalStressPermeabilityFactor3_Coef(); //WW + void CalStressPermeabilityFactor3_Coef(); // WW void CalStressPermeabilityFactor4(double* kfac, double); - //CMCD 9/2004 GeoSys 4 - double StorageFunction(long number,double* gp,double theta); - double HeatCapacity(long number,double theta, CFiniteElementStd* assem = NULL); - double* HeatConductivityTensor(int number); //MX - double* HeatDispersionTensorNew(int ip); //CMCD - double* MassDispersionTensorNew(int ip, int phase); //CMCD, SB, BG + // CMCD 9/2004 GeoSys 4 + double StorageFunction(long number, double* gp, double theta); + double HeatCapacity(long number, double theta, CFiniteElementStd* assem = NULL); + double* HeatConductivityTensor(int number); // MX + double* HeatDispersionTensorNew(int ip); // CMCD + double* MassDispersionTensorNew(int ip, int phase); // CMCD, SB, BG double* DispersionTensorMCF(int ip, int PCSIndex, int CIndex, double* variables = NULL); - //OK - double Density(long number,double* gp,double theta); + // OK + double Density(long number, double* gp, double theta); // Capillary pressure functions double CapillaryPressureFunction(const double wetting_saturation); double PressureSaturationDependency(double wetting_saturation, bool invert); - //JT: No longer used // double SaturationPressureDependency(const double capillary_pressure, bool allow_zero = false); + // JT: No longer used // double SaturationPressureDependency(const double capillary_pressure, bool allow_zero = + // false); double SaturationCapillaryPressureFunction(const double capillary_pressure); - //WW + // WW double PermeabilitySaturationFunction(const double wetting_saturation, int phase); double GetEffectiveSaturationForPerm(const double wetting_saturation, int phase); // JT - //MX 1/2005 + // MX 1/2005 double PorosityVolumetricChemicalReaction(long); - double Porosity(long number,double theta); //CMCD 9/2004 GeoSys 4 - //CMCD 4/2005 + double Porosity(long number, double theta); // CMCD 9/2004 GeoSys 4 + // CMCD 4/2005 void SetConstantELEarea(double area, int group); - //OK + // OK void SetDistributedELEProperties(std::string); - void WriteTecplotDistributedProperties(); //OK - double HeatTransferCoefficient(long number,double theta, CFiniteElementStd* assem); //NW - double ParticleDiameter(); - unsigned GetGeoDimension(void ){ return geo_dimension; } + void WriteTecplotDistributedProperties(); // OK + double HeatTransferCoefficient(long number, double theta, CFiniteElementStd* assem); // NW + double ParticleDiameter(); + unsigned GetGeoDimension(void) { return geo_dimension; } /** * the type of the geometric entity, the material property is assigned to * @return a value of the enum GEOLIB::GEOTYPE */ GEOLIB::GEOTYPE getGeoType() const { return _geo_type; } - - CFEMesh* getMesh(void) { return _mesh; } - + CFEMesh* getMesh(void) { return _mesh; } // Properties private: // PCS - std::string pcs_type_name; //YD + std::string pcs_type_name; // YD public: - CRFProcess* m_pcs; //OK - std::vectorpcs_name_vector; + CRFProcess* m_pcs; // OK + std::vector pcs_name_vector; + private: std::vector porosity_pcs_name_vector; - CFEMesh* _mesh; //OK + CFEMesh* _mesh; // OK /** * attribute describes the type of the geometric entity the @@ -184,58 +181,60 @@ class CMediumProperties */ GEOLIB::GEOTYPE _geo_type; FiniteElement::FrictionPhase _fric_phase; + public: - //GEO + // GEO std::string geo_name; - std::vectorgeo_name_vector; //OK + std::vector geo_name_vector; // OK double geo_area; - std::string geo_area_file; //OK + std::string geo_area_file; // OK double density; std::string name; int number; - int porosity_model; // porosity + int porosity_model; // porosity int porosity_curve; double porosity_model_values[15]; double porosity; - double KC_porosity_initial; // HS 11.2008 - double KC_permeability_initial; // HS 11.2008 - std::string porosity_file; //OK/MB + double KC_porosity_initial; // HS 11.2008 + double KC_permeability_initial; // HS 11.2008 + std::string porosity_file; // OK/MB int tortuosity_model; double tortuosity_model_values[10]; double tortuosity; int flowlinearity_model; double flowlinearity_model_values[10]; - int storage_model; // storativity + int storage_model; // storativity double storage_model_values[10]; double storage; int conductivity_model; double conductivity; int unconfined_flow_group; - int permeability_model; // permeability + int permeability_model; // permeability double permeability; - double local_permeability; //CB + double local_permeability; // CB double permeability_tensor[9]; - double permeability_porosity_updating_values[5]; //ABM: Maximum of 2 values in Verma-Pruess case + double permeability_porosity_updating_values[5]; // ABM: Maximum of 2 values in Verma-Pruess case std::string permeability_tensor_type_name; - std::string permeability_porosity_updating_type_name; //ABM + std::string permeability_porosity_updating_type_name; // ABM std::string tortuosity_tensor_type_name; int permeability_tensor_type; - int permeability_porosity_updating_type; //ABM + int permeability_porosity_updating_type; // ABM int tortuosity_tensor_type; double ElementVolumeMultiplyer; // Multiplyer of element volume - std::string PhaseHeatedByFriction; //In TNEQ/TES models: dissipated heat due to friction into solid or fluid energy balance + std::string + PhaseHeatedByFriction; // In TNEQ/TES models: dissipated heat due to friction into solid or fluid energy balance int permeability_pressure_model; double permeability_pressure_model_values[10]; double permeability_pressure_rel; - int permeability_strain_model; //WX: permeability function strain model. 05.2010 - int permeability_strain_model_value[6]; //WX:permeability fuction strain model value. 05.2010 - int permeability_effstress_model_value[3]; //AS:perlmeability function eff stress 08.2012 + int permeability_strain_model; // WX: permeability function strain model. 05.2010 + int permeability_strain_model_value[6]; // WX:permeability fuction strain model value. 05.2010 + int permeability_effstress_model_value[3]; // AS:perlmeability function eff stress 08.2012 int permeability_effstress_model; - int storage_effstress_model_value[3]; //AS:storage function eff stress 08.2012 + int storage_effstress_model_value[3]; // AS:storage function eff stress 08.2012 int storage_effstress_model; // // Relative permeability (JT) @@ -246,30 +245,31 @@ class CMediumProperties double saturation_exponent[MAX_FLUID_PHASES]; double perm_saturation_value[MAX_FLUID_PHASES]; // - std::string permeability_file; //SB //OK/MB string permeability_dis_type_file; - std::string tortuosity_file; // PCH - bool entry_pressure_conversion; //JT + std::string permeability_file; // SB //OK/MB string permeability_dis_type_file; + std::string tortuosity_file; // PCH + bool entry_pressure_conversion; // JT int capillary_pressure_model; int permeability_porosity_model; double permeability_porosity_model_values[10]; double storativity; - double capillary_pressure_values[5]; //JT2012 - double heat_capacity; // thermal properties + double capillary_pressure_values[5]; // JT2012 + double heat_capacity; // thermal properties int mass_dispersion_model; double mass_dispersion_longitudinal; double mass_dispersion_transverse; - double lgpn; //local grid peclet number + double lgpn; // local grid peclet number int heat_dispersion_model; double heat_dispersion_longitudinal; double heat_dispersion_transverse; double heat_conductivity_tensor[9]; - int fct_number; // functions + int fct_number; // functions int heat_diffusion_model; double base_heat_diffusion_coefficient; - int evaporation; // if it is 647 then evaporation ON, else OFF: and corresponding heat loss will compensated by heat ST + int evaporation; // if it is 647 then evaporation ON, else OFF: and corresponding heat loss will compensated by heat + // ST double heatflux; double vaporfraction; - //aux + // aux int m_color[3]; bool selected; int mode; @@ -279,86 +279,95 @@ class CMediumProperties // JOD double overland_width, rill_height, rill_epsilon; bool channel; - double argument; //OK - //Dual Richards transfer coefficient YD + double argument; // OK + // Dual Richards transfer coefficient YD double transfer_coefficient; - //double unsaturated_hydraulic_conductivity; + // double unsaturated_hydraulic_conductivity; double specific_storage; - int vol_mat_model; // CB - double vol_mat; //SB - int vol_bio_model; // CB - double vol_bio; //SB - double foc; // organic carbon content - double forchheimer_cf; //NW geometric constant for Forchheimer equation - double forchheimer_De; //NW equivalent diameter of the bed - double forchheimer_a1; //NW - double forchheimer_a2; //NW + int vol_mat_model; // CB + double vol_mat; // SB + int vol_bio_model; // CB + double vol_bio; // SB + double foc; // organic carbon content + double forchheimer_cf; // NW geometric constant for Forchheimer equation + double forchheimer_De; // NW equivalent diameter of the bed + double forchheimer_a1; // NW + double forchheimer_a2; // NW - int heat_transfer_model; //NW - int effective_heat_transfer_model; //NW - double heat_transfer_model_value; //NW + int heat_transfer_model; // NW + int effective_heat_transfer_model; // NW + double heat_transfer_model_value; // NW - int particle_diameter_model; - double particle_diameter_model_value; - //Get friction phase - TN - FiniteElement::FrictionPhase getFrictionPhase () const; + int particle_diameter_model; + double particle_diameter_model_value; + // Get friction phase - TN + FiniteElement::FrictionPhase getFrictionPhase() const; - //Set value for friction phase - TN - void setFrictionPhase (FiniteElement::FrictionPhase fric_phase); + // Set value for friction phase - TN + void setFrictionPhase(FiniteElement::FrictionPhase fric_phase); - //CB Chiogna et al alpha-t model - int alpha_t_model ; - double graindiameter; - double hydraulicrad; - double betaexpo; + // CB Chiogna et al alpha-t model + int alpha_t_model; + double graindiameter; + double hydraulicrad; + double betaexpo; }; -class CMediumPropertiesGroup //YD +class CMediumPropertiesGroup // YD { - public: - CMediumPropertiesGroup() : m_msh(NULL), OrigSize(0) {} - void Set(CRFProcess* m_pcs); - std::string pcs_name; - std::string pcs_type_name; - CFEMesh* m_msh; - std::vectormmp_group_vector; - private: - int OrigSize; // For excavation simulation. +public: + CMediumPropertiesGroup() : m_msh(NULL), OrigSize(0) {} + void Set(CRFProcess* m_pcs); + std::string pcs_name; + std::string pcs_type_name; + CFEMesh* m_msh; + std::vector mmp_group_vector; + +private: + int OrigSize; // For excavation simulation. }; - //YD -extern CMediumPropertiesGroup* MMPGetGroup(const std::string &pcs_type_name); - //YD -extern std::listmmp_group_list; +// YD +extern CMediumPropertiesGroup* MMPGetGroup(const std::string& pcs_type_name); +// YD +extern std::list mmp_group_list; extern void MMPGroupDelete(/*string pcs_type_name*/); -extern std::vectormmp_vector; +extern std::vector mmp_vector; extern void MATLoadDB(std::string); -extern std::list keywd_list; //keyword-referenzliste "kw" +extern std::list keywd_list; // keyword-referenzliste "kw" extern void comp_keywd_list(std::string); extern void read_keywd_list(void); -extern std::listmat_name_list; +extern std::list mat_name_list; extern void MMPWrite(std::string); extern bool MMPRead(std::string); extern void MMPDelete(); extern CMediumProperties* MMPGet(const std::string&); extern void MMP2PCSRelation(CRFProcess*); -extern void GetHeterogeneousFields(); //SB +extern void GetHeterogeneousFields(); // SB extern long GetNearestHetVal2(long EleIndex, CFEMesh* m_msh, - std::vector xvals, - std::vector yvals, - std::vector zvals, - std::vector mmpvals); + std::vector + xvals, + std::vector + yvals, + std::vector + zvals, + std::vector + mmpvals); double GetAverageHetVal2(long EleIndex, CFEMesh* m_msh, - std::vector xvals, - std::vector yvals, - std::vector zvals, - std::vector mmpvals); -extern bool MMPExist(std::ifstream* mmp_file); //OK -extern bool MMPExist(); //OK + std::vector + xvals, + std::vector + yvals, + std::vector + zvals, + std::vector + mmpvals); +extern bool MMPExist(std::ifstream* mmp_file); // OK +extern bool MMPExist(); // OK #define MMP_FILE_EXTENSION ".mmp" #endif diff --git a/FEM/rf_msp_new.cpp b/FEM/rf_msp_new.cpp index 3bc7e6aba..79289de73 100644 --- a/FEM/rf_msp_new.cpp +++ b/FEM/rf_msp_new.cpp @@ -36,17 +36,17 @@ #include "pcs_dm.h" #include "StringTools.h" -#include "files0.h" // GetLineFromFile1 -#include "tools.h" // GetLineFromFile +#include "files0.h" // GetLineFromFile1 +#include "tools.h" // GetLineFromFile std::vector msp_vector; -std::vector msp_key_word_vector; //OK +std::vector msp_key_word_vector; // OK namespace SolidProp { - using namespace std; - using FiniteElement::ElementValue_DM; - using Math_Group::Matrix; +using namespace std; +using FiniteElement::ElementValue_DM; +using Math_Group::Matrix; /************************************************************************** FEMLib-Method: @@ -67,7 +67,7 @@ std::ios::pos_type CSolidProperties::Read(std::ifstream* msp_file) std::ios::pos_type position; // ios::pos_type position0; std::string sub_string; - //WW bool new_subkeyword = false; + // WW bool new_subkeyword = false; std::string dollar("$"); std::string delimiter_type(":"); std::stringstream in_sd; @@ -78,44 +78,44 @@ std::ios::pos_type CSolidProperties::Read(std::ifstream* msp_file) // Schleife ueber alle Phasen bzw. Komponenten while (!new_keyword) { - //WW new_subkeyword = false; + // WW new_subkeyword = false; position = msp_file->tellg(); - if(!GetLineFromFile(buffer,msp_file)) + if (!GetLineFromFile(buffer, msp_file)) break; line_string = buffer; - trim(line_string); //NW - trim(line_string, ':'); //NW - if(line_string.find(hash) != string::npos) + trim(line_string); // NW + trim(line_string, ':'); // NW + if (line_string.find(hash) != string::npos) { new_keyword = true; break; } //.................................................................... - //NAME //OK - //subkeyword found - if(line_string.find("$NAME") != string::npos) + // NAME //OK + // subkeyword found + if (line_string.find("$NAME") != string::npos) { in_sd.str(GetLineFromFile1(msp_file)); - in_sd >> name; //sub_line + in_sd >> name; // sub_line in_sd.clear(); continue; } //.................................................................... // subkeyword found - if(line_string.find("$SWELLING_PRESSURE_TYPE") != string::npos) + if (line_string.find("$SWELLING_PRESSURE_TYPE") != string::npos) { in_sd.str(GetLineFromFile1(msp_file)); in_sd >> SwellingPressureType; - if(SwellingPressureType == 1 || SwellingPressureType == 2) + if (SwellingPressureType == 1 || SwellingPressureType == 2) { in_sd >> Max_SwellingPressure; in_sd.clear(); } - //10.03.2008 WW + // 10.03.2008 WW else if (SwellingPressureType == 3 || SwellingPressureType == 4) { - if(!PCSGet("MULTI_PHASE_FLOW") || !PCSGet("RICHARDS_FLOW")) + if (!PCSGet("MULTI_PHASE_FLOW") || !PCSGet("RICHARDS_FLOW")) { data_Youngs = new Matrix(9); //! 0: \f$ \kappa_i0 \f$ @@ -126,44 +126,42 @@ std::ios::pos_type CSolidProperties::Read(std::ifstream* msp_file) //! 5: \f$ p_ref \f$ //! 6: \f$ buffer \f$ if (SwellingPressureType == 3) - in_sd >> (*data_Youngs)(0) >> (*data_Youngs)(1) >> - (*data_Youngs)(2) - >> (*data_Youngs)(3) >> (*data_Youngs)(4) >> - (*data_Youngs)(5); + in_sd >> (*data_Youngs)(0) >> (*data_Youngs)(1) >> (*data_Youngs)(2) >> (*data_Youngs)(3) + >> (*data_Youngs)(4) >> (*data_Youngs)(5); else if (SwellingPressureType == 4) - in_sd >> (*data_Youngs)(0) >> (*data_Youngs)(1) >> - (*data_Youngs)(2); + in_sd >> (*data_Youngs)(0) >> (*data_Youngs)(1) >> (*data_Youngs)(2); in_sd.clear(); } else { - std::cout << - "No multi-phase flow coupled. The thermal elatic model can only be used in H2 coupled proccess." + std::cout << "No multi-phase flow coupled. The thermal elatic model can only be used in H2 coupled " + "proccess." + << "\n"; + std::cout << "Quit the simulation now!" << "\n"; - std::cout << "Quit the simulation now!" << "\n"; abort(); } } } //.................................................................... // subkeyword found - if(line_string.find("$DENSITY") != string::npos) + if (line_string.find("$DENSITY") != string::npos) { in_sd.str(GetLineFromFile1(msp_file)); in_sd >> Density_mode; - if(Density_mode == 0) // rho = f(x) + if (Density_mode == 0) // rho = f(x) { in_sd >> Size; in_sd.clear(); data_Density = new Matrix(Size, 2); - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) { in_sd.str(GetLineFromFile1(msp_file)); - in_sd >> (*data_Density)(i,0) >> (*data_Density)(i,1); + in_sd >> (*data_Density)(i, 0) >> (*data_Density)(i, 1); in_sd.clear(); } } - else if(Density_mode == 1) // rho = const + else if (Density_mode == 1) // rho = const { data_Density = new Matrix(1); in_sd >> (*data_Density)(0); @@ -171,7 +169,7 @@ std::ios::pos_type CSolidProperties::Read(std::ifstream* msp_file) } } //.................................................................... - if(line_string.find("$THERMAL") != string::npos) + if (line_string.find("$THERMAL") != string::npos) { in_sd.str(GetLineFromFile1(msp_file)); in_sd >> sub_line >> ThermalExpansion; @@ -179,321 +177,311 @@ std::ios::pos_type CSolidProperties::Read(std::ifstream* msp_file) } //.................................................................... // subkeyword found - if(line_string.find("CAPACITY") != string::npos) + if (line_string.find("CAPACITY") != string::npos) { in_sd.str(GetLineFromFile1(msp_file)); in_sd >> Capacity_mode; - switch(Capacity_mode) + switch (Capacity_mode) { - case 0: // = f(x) - in_sd >> Size; - in_sd.clear(); - data_Capacity = new Matrix(Size, 2); - for(i = 0; i < Size; i++) - { - in_sd.str(GetLineFromFile1(msp_file)); - in_sd >> (*data_Capacity)(i,0) >> (*data_Capacity)(i,1); + case 0: // = f(x) + in_sd >> Size; in_sd.clear(); - } - break; - case 1: // = const - data_Capacity = new Matrix(1); - in_sd >> (*data_Capacity)(0); - in_sd.clear(); - break; - case 2: // boiling model for rock. WW - // 0. Wet capacity - // 1. Dry capacity - // 2. Boiling temperature - // 3. Boiling temperature range - // 4. Latent of vaporization - data_Capacity = new Matrix(5); - for(i = 0; i < 5; i++) - in_sd >> (*data_Capacity)(i); - in_sd.clear(); - break; - case 3: // DECOVALEX THM1, Bentonite - in_sd.clear(); - break; - case 4: - //0. Capacity at density 1 - //1. Capacity at density 2 - //2. density 1 - //3. density 2 - data_Capacity = new Matrix(5); - for(i=0; i<4; i++) - in_sd>> (*data_Capacity)(i); - in_sd.clear(); - break; + data_Capacity = new Matrix(Size, 2); + for (i = 0; i < Size; i++) + { + in_sd.str(GetLineFromFile1(msp_file)); + in_sd >> (*data_Capacity)(i, 0) >> (*data_Capacity)(i, 1); + in_sd.clear(); + } + break; + case 1: // = const + data_Capacity = new Matrix(1); + in_sd >> (*data_Capacity)(0); + in_sd.clear(); + break; + case 2: // boiling model for rock. WW + // 0. Wet capacity + // 1. Dry capacity + // 2. Boiling temperature + // 3. Boiling temperature range + // 4. Latent of vaporization + data_Capacity = new Matrix(5); + for (i = 0; i < 5; i++) + in_sd >> (*data_Capacity)(i); + in_sd.clear(); + break; + case 3: // DECOVALEX THM1, Bentonite + in_sd.clear(); + break; + case 4: + // 0. Capacity at density 1 + // 1. Capacity at density 2 + // 2. density 1 + // 3. density 2 + data_Capacity = new Matrix(5); + for (i = 0; i < 4; i++) + in_sd >> (*data_Capacity)(i); + in_sd.clear(); + break; // TES - case 5: //Capacity depending on solid conversion - //0. Capacity at lower_density_limit (reactive system property) - //1. Capacity at upper_density_limit (reactive system property) - data_Capacity = new Matrix(3); - for(i=0; i<2; i++) - in_sd>> (*data_Capacity)(i); - in_sd.clear(); - break; - case 6: //Capacity depending on loading with adsorbate - //0. Capacity at desorbed state (lower density limit) - //1. Capacity of adsorbate - data_Capacity = new Matrix(3); - for(i=0; i<2; i++) - in_sd>> (*data_Capacity)(i); - in_sd.clear(); - break; + case 5: // Capacity depending on solid conversion + // 0. Capacity at lower_density_limit (reactive system property) + // 1. Capacity at upper_density_limit (reactive system property) + data_Capacity = new Matrix(3); + for (i = 0; i < 2; i++) + in_sd >> (*data_Capacity)(i); + in_sd.clear(); + break; + case 6: // Capacity depending on loading with adsorbate + // 0. Capacity at desorbed state (lower density limit) + // 1. Capacity of adsorbate + data_Capacity = new Matrix(3); + for (i = 0; i < 2; i++) + in_sd >> (*data_Capacity)(i); + in_sd.clear(); + break; } } //.................................................................... // subkeyword found - if(line_string.compare("CONDUCTIVITY") == 0) + if (line_string.compare("CONDUCTIVITY") == 0) { in_sd.str(GetLineFromFile1(msp_file)); in_sd >> Conductivity_mode; - switch(Conductivity_mode) + switch (Conductivity_mode) { - case 0: // = f(T) //21.12.2009 WW - in_sd >> Size; - in_sd.clear(); - data_Conductivity = new Matrix(Size, 2); - for(i = 0; i < Size; i++) - { - in_sd.str(GetLineFromFile1(msp_file)); - in_sd >> - (*data_Conductivity)(i, - 0) >> (*data_Conductivity)(i,1); + case 0: // = f(T) //21.12.2009 WW + in_sd >> Size; in_sd.clear(); - } - //WW - conductivity_pcs_name_vector.push_back("TEMPERATURE1"); - break; - case 1: // = const - data_Conductivity = new Matrix(1); - in_sd >> (*data_Conductivity)(0); - in_sd.clear(); - break; - case 2: // boiling model for rock. WW - // 0. Wet conductivity - // 1. Dry conductivity - // 2. Boiling temperature - // 3. Boiling temperature range - data_Conductivity = new Matrix(4); - for(i = 0; i < 4; i++) - in_sd >> (*data_Conductivity)(i); - in_sd.clear(); - capacity_pcs_name_vector.push_back("TEMPERATURE1"); - capacity_pcs_name_vector.push_back("SATURATION1"); - break; - case 3: // DECOVALEX THM1, Bentonite - in_sd.clear(); - capacity_pcs_name_vector.push_back("TEMPERATURE1"); - capacity_pcs_name_vector.push_back("SATURATION1"); - break; - case 30: // another model for bentonite. WW - // 0. maximum conductivity - // 1. minimum conductivity - // 2. saturation - data_Conductivity = new Matrix(3); - for(i = 0; i < 3; i++) - in_sd >> (*data_Conductivity)(i); - in_sd.clear(); - capacity_pcs_name_vector.push_back("SATURATION1"); - break; - case 4: // = f(S) //21.12.2009 WW - in_sd >> Size; - in_sd.clear(); - data_Conductivity = new Matrix(Size, 2); - for(i = 0; i < Size; i++) - { - in_sd.str(GetLineFromFile1(msp_file)); - in_sd >> - (*data_Conductivity)(i, - 0) >> (*data_Conductivity)(i,1); + data_Conductivity = new Matrix(Size, 2); + for (i = 0; i < Size; i++) + { + in_sd.str(GetLineFromFile1(msp_file)); + in_sd >> (*data_Conductivity)(i, 0) >> (*data_Conductivity)(i, 1); + in_sd.clear(); + } + // WW + conductivity_pcs_name_vector.push_back("TEMPERATURE1"); + break; + case 1: // = const + data_Conductivity = new Matrix(1); + in_sd >> (*data_Conductivity)(0); in_sd.clear(); - } - break; - case 5: // DECOVALEX2015, Task B2, Buffer: f(S,T) by matrix function - in_sd >> T_0; - in_sd.clear(); - conductivity_pcs_name_vector.push_back("TEMPERATURE1"); - conductivity_pcs_name_vector.push_back("SATURATION1"); - break; + break; + case 2: // boiling model for rock. WW + // 0. Wet conductivity + // 1. Dry conductivity + // 2. Boiling temperature + // 3. Boiling temperature range + data_Conductivity = new Matrix(4); + for (i = 0; i < 4; i++) + in_sd >> (*data_Conductivity)(i); + in_sd.clear(); + capacity_pcs_name_vector.push_back("TEMPERATURE1"); + capacity_pcs_name_vector.push_back("SATURATION1"); + break; + case 3: // DECOVALEX THM1, Bentonite + in_sd.clear(); + capacity_pcs_name_vector.push_back("TEMPERATURE1"); + capacity_pcs_name_vector.push_back("SATURATION1"); + break; + case 30: // another model for bentonite. WW + // 0. maximum conductivity + // 1. minimum conductivity + // 2. saturation + data_Conductivity = new Matrix(3); + for (i = 0; i < 3; i++) + in_sd >> (*data_Conductivity)(i); + in_sd.clear(); + capacity_pcs_name_vector.push_back("SATURATION1"); + break; + case 4: // = f(S) //21.12.2009 WW + in_sd >> Size; + in_sd.clear(); + data_Conductivity = new Matrix(Size, 2); + for (i = 0; i < Size; i++) + { + in_sd.str(GetLineFromFile1(msp_file)); + in_sd >> (*data_Conductivity)(i, 0) >> (*data_Conductivity)(i, 1); + in_sd.clear(); + } + break; + case 5: // DECOVALEX2015, Task B2, Buffer: f(S,T) by matrix function + in_sd >> T_0; + in_sd.clear(); + conductivity_pcs_name_vector.push_back("TEMPERATURE1"); + conductivity_pcs_name_vector.push_back("SATURATION1"); + break; } in_sd.clear(); } //.................................................................... - if(line_string.find("CONDUCTIVITY_TENSOR") != string::npos) //subkeyword found + if (line_string.find("CONDUCTIVITY_TENSOR") != string::npos) // subkeyword found { in_sd.str(GetLineFromFile1(msp_file)); in_sd >> thermal_conductivity_tensor_type_name; - thermal_conductivity_tensor_dim = 0; //NW - switch(thermal_conductivity_tensor_type_name[0]) + thermal_conductivity_tensor_dim = 0; // NW + switch (thermal_conductivity_tensor_type_name[0]) { - case 'I': // isotropic - thermal_conductivity_tensor_type = 0; - in_sd >> thermal_conductivity_tensor[0]; - thermal_conductivity_tensor[1] = thermal_conductivity_tensor[2] = - thermal_conductivity_tensor - [0]; - break; - case 'O': // orthotropic - thermal_conductivity_tensor_type = 1; - in_sd >> thermal_conductivity_tensor_dim; - if(thermal_conductivity_tensor_dim == 0) - std::cout << - "Error in CSolidProperties::Read: no tensor dimension" - << "\n"; - if(thermal_conductivity_tensor_dim == 2) - { - in_sd >> thermal_conductivity_tensor[0]; - in_sd >> thermal_conductivity_tensor[1]; - } - if(thermal_conductivity_tensor_dim == 3) - { - in_sd >> thermal_conductivity_tensor[0]; - in_sd >> thermal_conductivity_tensor[1]; - in_sd >> thermal_conductivity_tensor[2]; - } - break; - case 'A': // anisotropic - thermal_conductivity_tensor_type = 2; - in_sd >> thermal_conductivity_tensor_dim; - if(thermal_conductivity_tensor_dim == 0) - std::cout << - "Error in CSolidProperties::Read: no tensor dimension" - << "\n"; - if(thermal_conductivity_tensor_dim == 2) - { - in_sd >> thermal_conductivity_tensor[0]; - in_sd >> thermal_conductivity_tensor[1]; - in_sd >> thermal_conductivity_tensor[2]; - in_sd >> thermal_conductivity_tensor[3]; - } - if(thermal_conductivity_tensor_dim == 3) - { + case 'I': // isotropic + thermal_conductivity_tensor_type = 0; in_sd >> thermal_conductivity_tensor[0]; - in_sd >> thermal_conductivity_tensor[1]; - in_sd >> thermal_conductivity_tensor[2]; - in_sd >> thermal_conductivity_tensor[3]; - in_sd >> thermal_conductivity_tensor[4]; - in_sd >> thermal_conductivity_tensor[5]; - in_sd >> thermal_conductivity_tensor[6]; - in_sd >> thermal_conductivity_tensor[7]; - in_sd >> thermal_conductivity_tensor[8]; - } - break; - default: - cout << - "Error in CSolidProperties::Read: no valid thermal conductivity tensor type" - << "\n"; - break; + thermal_conductivity_tensor[1] = thermal_conductivity_tensor[2] = thermal_conductivity_tensor[0]; + break; + case 'O': // orthotropic + thermal_conductivity_tensor_type = 1; + in_sd >> thermal_conductivity_tensor_dim; + if (thermal_conductivity_tensor_dim == 0) + std::cout << "Error in CSolidProperties::Read: no tensor dimension" + << "\n"; + if (thermal_conductivity_tensor_dim == 2) + { + in_sd >> thermal_conductivity_tensor[0]; + in_sd >> thermal_conductivity_tensor[1]; + } + if (thermal_conductivity_tensor_dim == 3) + { + in_sd >> thermal_conductivity_tensor[0]; + in_sd >> thermal_conductivity_tensor[1]; + in_sd >> thermal_conductivity_tensor[2]; + } + break; + case 'A': // anisotropic + thermal_conductivity_tensor_type = 2; + in_sd >> thermal_conductivity_tensor_dim; + if (thermal_conductivity_tensor_dim == 0) + std::cout << "Error in CSolidProperties::Read: no tensor dimension" + << "\n"; + if (thermal_conductivity_tensor_dim == 2) + { + in_sd >> thermal_conductivity_tensor[0]; + in_sd >> thermal_conductivity_tensor[1]; + in_sd >> thermal_conductivity_tensor[2]; + in_sd >> thermal_conductivity_tensor[3]; + } + if (thermal_conductivity_tensor_dim == 3) + { + in_sd >> thermal_conductivity_tensor[0]; + in_sd >> thermal_conductivity_tensor[1]; + in_sd >> thermal_conductivity_tensor[2]; + in_sd >> thermal_conductivity_tensor[3]; + in_sd >> thermal_conductivity_tensor[4]; + in_sd >> thermal_conductivity_tensor[5]; + in_sd >> thermal_conductivity_tensor[6]; + in_sd >> thermal_conductivity_tensor[7]; + in_sd >> thermal_conductivity_tensor[8]; + } + break; + default: + cout << "Error in CSolidProperties::Read: no valid thermal conductivity tensor type" + << "\n"; + break; } in_sd.clear(); } //.................................................................... // subkeyword found - if(line_string.find("$ELASTICITY") != string::npos) + if (line_string.find("$ELASTICITY") != string::npos) { in_sd.str(GetLineFromFile1(msp_file)); in_sd >> sub_line >> PoissonRatio; in_sd.clear(); } //.................................................................... - //12.2009. WW - if(line_string.find("$EXCAVATION") != string::npos) + // 12.2009. WW + if (line_string.find("$EXCAVATION") != string::npos) { in_sd.str(GetLineFromFile1(msp_file)); in_sd >> excavation; in_sd.clear(); } //.................................................................... - if(line_string.find("YOUNGS_MODULUS") != string::npos) - { // subkeyword found + if (line_string.find("YOUNGS_MODULUS") != string::npos) + { // subkeyword found in_sd.str(GetLineFromFile1(msp_file)); in_sd >> Youngs_mode; int type = Youngs_mode; - if(type > 9 && type < 14) + if (type > 9 && type < 14) type = 1000; - switch(type) // 15.03.2008 WW + switch (type) // 15.03.2008 WW { - case 0: // = f(x) - in_sd >> Size; - in_sd.clear(); - data_Youngs = new Matrix(Size, 2); - for(i = 0; i < Size; i++) - { - in_sd.str(GetLineFromFile1(msp_file)); - in_sd >> (*data_Youngs)(i,0) >> (*data_Youngs)(i,1); + case 0: // = f(x) + in_sd >> Size; in_sd.clear(); - } - break; - case 1: // = const - data_Youngs = new Matrix(1); - in_sd >> (*data_Youngs)(0); - in_sd.clear(); - break; // UJG 24.11.2009 - case 2: // = const - // data_Youngs Lubby1 model - // 0: E_0 - // 1: a (factor) - // 2: n (exponent) - data_Youngs = new Matrix(3); - in_sd >> (*data_Youngs)(0) >> (*data_Youngs)(1) >> (*data_Youngs)(2); - in_sd.clear(); - break; - case 1000: // case 10-13: transverse isotropic linear elasticity (UJG 24.11.2009) - // data_Youngs transverse isotropic linear elasticity - // 0: E_i (Young's modulus of the plane of isotropy) - // 1: E_a (Young's modulus w.r.t. the anisotropy direction) - // 2: nu_{ia} (Poisson's ratio w.r.t. the anisotropy direction) - // 3: G_a (shear modulus w.r.t. the anisotropy direction) - // 4: n_x (x-coefficient of the local axis of anisotropy (2D case: -\sin\phi)) - // 5: n_y (y-coefficient of the local axis of anisotropy (2D case: \cos\phi)) - // 6: n_z (z-coefficient of the local axis of anisotropy (2D case: 0)) - data_Youngs = new Matrix(7); - in_sd >> (*data_Youngs)(0) >> (*data_Youngs)(1) >> - (*data_Youngs)(2) >> (*data_Youngs)(3) - >> (*data_Youngs)(4) >> (*data_Youngs)(5) >> (*data_Youngs)(6); - in_sd.clear(); - break; + data_Youngs = new Matrix(Size, 2); + for (i = 0; i < Size; i++) + { + in_sd.str(GetLineFromFile1(msp_file)); + in_sd >> (*data_Youngs)(i, 0) >> (*data_Youngs)(i, 1); + in_sd.clear(); + } + break; + case 1: // = const + data_Youngs = new Matrix(1); + in_sd >> (*data_Youngs)(0); + in_sd.clear(); + break; // UJG 24.11.2009 + case 2: // = const + // data_Youngs Lubby1 model + // 0: E_0 + // 1: a (factor) + // 2: n (exponent) + data_Youngs = new Matrix(3); + in_sd >> (*data_Youngs)(0) >> (*data_Youngs)(1) >> (*data_Youngs)(2); + in_sd.clear(); + break; + case 1000: // case 10-13: transverse isotropic linear elasticity (UJG 24.11.2009) + // data_Youngs transverse isotropic linear elasticity + // 0: E_i (Young's modulus of the plane of isotropy) + // 1: E_a (Young's modulus w.r.t. the anisotropy direction) + // 2: nu_{ia} (Poisson's ratio w.r.t. the anisotropy direction) + // 3: G_a (shear modulus w.r.t. the anisotropy direction) + // 4: n_x (x-coefficient of the local axis of anisotropy (2D case: -\sin\phi)) + // 5: n_y (y-coefficient of the local axis of anisotropy (2D case: \cos\phi)) + // 6: n_z (z-coefficient of the local axis of anisotropy (2D case: 0)) + data_Youngs = new Matrix(7); + in_sd >> (*data_Youngs)(0) >> (*data_Youngs)(1) >> (*data_Youngs)(2) >> (*data_Youngs)(3) + >> (*data_Youngs)(4) >> (*data_Youngs)(5) >> (*data_Youngs)(6); + in_sd.clear(); + break; } } //.................................................................... - //WX:06.2012 E_Function - if(line_string.find("$E_Function")!=string::npos) + // WX:06.2012 E_Function + if (line_string.find("$E_Function") != string::npos) { in_sd.str(GetLineFromFile1(msp_file)); - in_sd>>E_Function_Model>>E_Function_Model_Value[0]; + in_sd >> E_Function_Model >> E_Function_Model_Value[0]; in_sd.clear(); } - //Time dependent YOUNGS POISSON - if(line_string.find("$TIME_DEPENDENT_YOUNGS_POISSON")!=string::npos) + // Time dependent YOUNGS POISSON + if (line_string.find("$TIME_DEPENDENT_YOUNGS_POISSON") != string::npos) { in_sd.str(GetLineFromFile1(msp_file)); - in_sd>>Time_Dependent_E_nv_mode; - switch(Time_Dependent_E_nv_mode) + in_sd >> Time_Dependent_E_nv_mode; + switch (Time_Dependent_E_nv_mode) { - case 1://isotropic - in_sd>>Time_Dependent_E_nv_value[0]>>Time_Dependent_E_nv_value[1];//[0] for E, [1] for nv - break; - case 2://transversely isotropic - in_sd>>Time_Dependent_E_nv_value[0]>>Time_Dependent_E_nv_value[1]>>Time_Dependent_E_nv_value[2]>> - Time_Dependent_E_nv_value[3]>>Time_Dependent_E_nv_value[4]; - //[0]: Ei, [1]: Ea, [2]: ni, [3]: Eia, [4]: Ga - break; - default: - cout<<"!ERROR in msp file, no valid TIME_DEPENDENT_YOUNG_POISSON mode!"<> Time_Dependent_E_nv_value[0] >> Time_Dependent_E_nv_value[1]; //[0] for E, [1] for nv + break; + case 2: // transversely isotropic + in_sd >> Time_Dependent_E_nv_value[0] >> Time_Dependent_E_nv_value[1] + >> Time_Dependent_E_nv_value[2] >> Time_Dependent_E_nv_value[3] >> Time_Dependent_E_nv_value[4]; + //[0]: Ei, [1]: Ea, [2]: ni, [3]: Eia, [4]: Ga + break; + default: + cout << "!ERROR in msp file, no valid TIME_DEPENDENT_YOUNG_POISSON mode!" << endl; + break; } in_sd.clear(); } //.................................................................... - if(line_string.find("$CREEP") != string::npos) + if (line_string.find("$CREEP") != string::npos) { - if(line_string.find("NORTON") != string::npos) + if (line_string.find("NORTON") != string::npos) { Creep_mode = 1; /*! \subsection Norton creep model */ @@ -507,7 +495,7 @@ std::ios::pos_type CSolidProperties::Read(std::ifstream* msp_file) in_sd >> (*data_Creep)(1); in_sd.clear(); } - if(line_string.find("BGRA") != string::npos) + if (line_string.find("BGRA") != string::npos) { Creep_mode = 2; /*! \subsection Temperature dependent creep model by BGR */ @@ -523,10 +511,10 @@ std::ios::pos_type CSolidProperties::Read(std::ifstream* msp_file) in_sd >> (*data_Creep)(2); in_sd.clear(); } - //TN.................................................................. - if(line_string.find("BGRB")!=string::npos) + // TN.................................................................. + if (line_string.find("BGRB") != string::npos) { - Creep_mode=3; + Creep_mode = 3; // data_Creep: // 0: A1, coefficient A1 // 1: n1, exponential n1 @@ -536,17 +524,17 @@ std::ios::pos_type CSolidProperties::Read(std::ifstream* msp_file) // 5: Q2, activation energy Q2 data_Creep = new Matrix(6); in_sd.str(GetLineFromFile1(msp_file)); - in_sd>>(*data_Creep)(0); - in_sd>>(*data_Creep)(1); - in_sd>>(*data_Creep)(2); - in_sd>>(*data_Creep)(3); - in_sd>>(*data_Creep)(4); - in_sd>>(*data_Creep)(5); + in_sd >> (*data_Creep)(0); + in_sd >> (*data_Creep)(1); + in_sd >> (*data_Creep)(2); + in_sd >> (*data_Creep)(3); + in_sd >> (*data_Creep)(4); + in_sd >> (*data_Creep)(5); in_sd.clear(); } - if(line_string.find("BGRSF")!=string::npos) + if (line_string.find("BGRSF") != string::npos) { - Creep_mode=4; + Creep_mode = 4; // data_Creep: // 0: A, coefficient A // 1: n, exponential @@ -554,14 +542,14 @@ std::ios::pos_type CSolidProperties::Read(std::ifstream* msp_file) // 3: C, coefficient C data_Creep = new Matrix(4); in_sd.str(GetLineFromFile1(msp_file)); - in_sd>>(*data_Creep)(0); - in_sd>>(*data_Creep)(1); - in_sd>>(*data_Creep)(2); - in_sd>>(*data_Creep)(3); + in_sd >> (*data_Creep)(0); + in_sd >> (*data_Creep)(1); + in_sd >> (*data_Creep)(2); + in_sd >> (*data_Creep)(3); in_sd.clear(); } //.................................................................... - if(line_string.find("LUBBY2") != string::npos) + if (line_string.find("LUBBY2") != string::npos) { Creep_mode = 1000; // data_Creep: @@ -572,100 +560,100 @@ std::ios::pos_type CSolidProperties::Read(std::ifstream* msp_file) // 4: k1 // 5: k2 // 6: G_k - data_Creep = new Matrix(7,2); + data_Creep = new Matrix(7, 2); in_sd.str(GetLineFromFile1(msp_file)); - for(i = 0; i < 7; i++) - in_sd >> (*data_Creep)(i,0); + for (i = 0; i < 7; i++) + in_sd >> (*data_Creep)(i, 0); in_sd.clear(); } } - //WX:10.2012, threshold dev. stress for Lubby2 - if(line_string.find("$THRESHOLD_DEV_STR")!=string::npos) + // WX:10.2012, threshold dev. stress for Lubby2 + if (line_string.find("$THRESHOLD_DEV_STR") != string::npos) { in_sd.str(GetLineFromFile1(msp_file)); - in_sd>>threshold_dev_str; + in_sd >> threshold_dev_str; in_sd.clear(); } //.................................................................... - if(line_string.find("$BIOT_CONSTANT") != string::npos) + if (line_string.find("$BIOT_CONSTANT") != string::npos) { in_sd.str(GetLineFromFile1(msp_file)); in_sd >> biot_const; in_sd.clear(); } //.................................................................... - if(line_string.find("$SOLID_BULK_MODULUS") != string::npos)//WX: 04.2013 + if (line_string.find("$SOLID_BULK_MODULUS") != string::npos) // WX: 04.2013 { in_sd.str(GetLineFromFile1(msp_file)); in_sd >> Ks; in_sd.clear(); } //.................................................................... - if(line_string.find("BISHOP_COEFFICIENT") != string::npos) //WX + if (line_string.find("BISHOP_COEFFICIENT") != string::npos) // WX { in_sd.str(GetLineFromFile1(msp_file)); in_sd >> bishop_model; - switch(bishop_model) + switch (bishop_model) { - case 1: //constant - in_sd >> bishop_model_value; - break; - case 2: //pow(Se, parameter) - in_sd >> bishop_model_value; - break; - case 3: // JM model 3: if p bishop_parameter=0.0; else -> bishop_parameter=1.0 - in_sd >> bishop_model_value; - break; - default: - break; + case 1: // constant + in_sd >> bishop_model_value; + break; + case 2: // pow(Se, parameter) + in_sd >> bishop_model_value; + break; + case 3: // JM model 3: if p bishop_parameter=0.0; else -> bishop_parameter=1.0 + in_sd >> bishop_model_value; + break; + default: + break; } in_sd.clear(); } //.................................................................... - if(line_string.find("$STRESS_INTEGRATION_TOLERANCE") != string::npos) + if (line_string.find("$STRESS_INTEGRATION_TOLERANCE") != string::npos) { in_sd.str(GetLineFromFile1(msp_file)); in_sd >> f_tol >> s_tol; in_sd.clear(); } - if(line_string.find("$STRESS_UNIT") != string::npos) + if (line_string.find("$STRESS_UNIT") != string::npos) { in_sd.str(GetLineFromFile1(msp_file)); in_sd >> sub_line; - if(sub_line.compare("MegaPascal") == 0) + if (sub_line.compare("MegaPascal") == 0) grav_const = 9.81e-6; - else if(sub_line.find("KiloPascal") == 0) + else if (sub_line.find("KiloPascal") == 0) grav_const = 9.81e-3; in_sd.clear(); } - //WX:08.2011 define gravity constant - if(line_string.find("$GRAVITY_CONSTANT")!=string::npos) + // WX:08.2011 define gravity constant + if (line_string.find("$GRAVITY_CONSTANT") != string::npos) { in_sd.str(GetLineFromFile1(msp_file)); - in_sd>>grav_const; + in_sd >> grav_const; in_sd.clear(); } //.................................................................... // subkeyword found - if(line_string.find("$PLASTICITY") != string::npos) + if (line_string.find("$PLASTICITY") != string::npos) { in_sd.str(GetLineFromFile1(msp_file)); in_sd >> sub_line; in_sd.clear(); - if(sub_line.find("DRUCKER-PRAGER") != string::npos) + if (sub_line.find("DRUCKER-PRAGER") != string::npos) { devS = new double[6]; Plasticity_type = 1; // No return mapping - if(sub_line.find("NORETURNMAPPING") != string::npos) + if (sub_line.find("NORETURNMAPPING") != string::npos) { Plasticity_type = 10; - if (sub_line.find("TENSIONCUTOFF") != string::npos) //WX: 08.2010 + if (sub_line.find("TENSIONCUTOFF") != string::npos) // WX: 08.2010 { Plasticity_type = 11; - dFtds = new double[6]; //WX: 08.2010 Tensile yield function + dFtds = new double[6]; // WX: 08.2010 Tensile yield function dGtds = new double[6]; - ConstitutiveMatrix = new Matrix(6,6); //WX: 08.2010 + ConstitutiveMatrix = new Matrix(6, 6); // WX: 08.2010 } dFds = new double[6]; dGds = new double[6]; @@ -673,7 +661,7 @@ std::ios::pos_type CSolidProperties::Read(std::ifstream* msp_file) D_dGds = new double[6]; } Size = 5; - if(Plasticity_type == 11) + if (Plasticity_type == 11) Size = 6; /* Material parameters for Cam-Clay model @@ -686,7 +674,7 @@ std::ios::pos_type CSolidProperties::Read(std::ifstream* msp_file) 5 : Tensile strength //WX */ } - else if(sub_line.find("SINGLE_YIELD_SURFACE") != string::npos) + else if (sub_line.find("SINGLE_YIELD_SURFACE") != string::npos) { Plasticity_type = 2; Size = 23; @@ -723,7 +711,7 @@ std::ios::pos_type CSolidProperties::Read(std::ifstream* msp_file) 22: Initial stress_zz */ } - else if(sub_line.find("CAM-CLAY") != string::npos) + else if (sub_line.find("CAM-CLAY") != string::npos) { Plasticity_type = 3; Size = 10; @@ -742,22 +730,22 @@ std::ios::pos_type CSolidProperties::Read(std::ifstream* msp_file) 9 : Mimimum p: ( stress_xx + stress_yy + stress_zz )/3 */ } - else if(sub_line.find("MOHR-COULOMB") != string::npos) //WX + else if (sub_line.find("MOHR-COULOMB") != string::npos) // WX { devS = new double[6]; - TransMatrixA = new Matrix(6,6);//WX:08.2011 - TransMatrixA_T = new Matrix(6,6); - Inv_TransA = new Matrix(6,6); - Inv_TransA_T = new Matrix(6,6); - TmpDe = new Matrix(6,6); - Inv_De = new Matrix(6,6); - TMatrix = new Matrix(6,6); - TmpMatrix = new Matrix(6,6); - TmpMatrix2 = new Matrix(6,6); - Dep_l = new Matrix(3,3); - dDep_l = new Matrix(3,3); - dGds_dFds = new Matrix(6,6);//WX:08.2011 - ConstitutiveMatrix = new Matrix(6,6); + TransMatrixA = new Matrix(6, 6); // WX:08.2011 + TransMatrixA_T = new Matrix(6, 6); + Inv_TransA = new Matrix(6, 6); + Inv_TransA_T = new Matrix(6, 6); + TmpDe = new Matrix(6, 6); + Inv_De = new Matrix(6, 6); + TMatrix = new Matrix(6, 6); + TmpMatrix = new Matrix(6, 6); + TmpMatrix2 = new Matrix(6, 6); + Dep_l = new Matrix(3, 3); + dDep_l = new Matrix(3, 3); + dGds_dFds = new Matrix(6, 6); // WX:08.2011 + ConstitutiveMatrix = new Matrix(6, 6); Plasticity_type = 4; Size = 6; /* @@ -770,10 +758,10 @@ std::ios::pos_type CSolidProperties::Read(std::ifstream* msp_file) 5 hardening curve for cohesion */ } - else if(sub_line.find("HOEK-BROWN") != string::npos) //WX + else if (sub_line.find("HOEK-BROWN") != string::npos) // WX { devS = new double[6]; - ConstitutiveMatrix = new Matrix(6,6); + ConstitutiveMatrix = new Matrix(6, 6); Plasticity_type = 5; Size = 4; /* @@ -788,93 +776,92 @@ std::ios::pos_type CSolidProperties::Read(std::ifstream* msp_file) data_Plasticity = new Matrix(Size + 1); else data_Plasticity = new Matrix(Size); - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) { in_sd.str(GetLineFromFile1(msp_file)); in_sd >> (*data_Plasticity)(i); in_sd.clear(); } } - //Solid reaction system - if(line_string.find("$REACTIVE_SYSTEM")!=string::npos) - { - in_sd.str(GetLineFromFile1(msp_file)); - in_sd >> reaction_system; - this->setSolidReactiveSystem(FiniteElement::convertSolidReactiveSystem(reaction_system)); - in_sd.clear(); - if (reaction_system.compare("SINUSOIDAL") == 0) { //For Benchmarks + // Solid reaction system + if (line_string.find("$REACTIVE_SYSTEM") != string::npos) + { + in_sd.str(GetLineFromFile1(msp_file)); + in_sd >> reaction_system; + this->setSolidReactiveSystem(FiniteElement::convertSolidReactiveSystem(reaction_system)); + in_sd.clear(); + if (reaction_system.compare("SINUSOIDAL") == 0) + { // For Benchmarks in_sd.str(GetLineFromFile1(msp_file)); - in_sd >> reaction_enthalpy; //in J/kg, negative for exothermic composition reaction + in_sd >> reaction_enthalpy; // in J/kg, negative for exothermic composition reaction in_sd.clear(); - } - SetSolidReactiveSystemProperties(); - - } - - //Solid non reactive fraction - if(line_string.find("$NON_REACTIVE_FRACTION")!=string::npos) - { - in_sd.str(GetLineFromFile1(msp_file)); - in_sd >> non_reactive_solid_volume_fraction >> non_reactive_solid_density; - in_sd.clear(); + } + SetSolidReactiveSystemProperties(); + } - } + // Solid non reactive fraction + if (line_string.find("$NON_REACTIVE_FRACTION") != string::npos) + { + in_sd.str(GetLineFromFile1(msp_file)); + in_sd >> non_reactive_solid_volume_fraction >> non_reactive_solid_density; + in_sd.clear(); + } - if(line_string.find("$SPECIFIC_HEAT_SOURCE")!=string::npos) - { - in_sd.str(GetLineFromFile1(msp_file)); - in_sd >> specific_heat_source; - in_sd.clear(); - } + if (line_string.find("$SPECIFIC_HEAT_SOURCE") != string::npos) + { + in_sd.str(GetLineFromFile1(msp_file)); + in_sd >> specific_heat_source; + in_sd.clear(); + } - if(line_string.find("$MICRO_STRUCTURE_PLAS")!=string::npos)//WX:09.2011 for anisotropic plasticity + if (line_string.find("$MICRO_STRUCTURE_PLAS") != string::npos) // WX:09.2011 for anisotropic plasticity { - if (line_string.find("NORETURNMAPPING")!=string::npos) - Plasticity_type=44;//direct stress intergration anisotropic plas. - Plasticity_Bedding=true; + if (line_string.find("NORETURNMAPPING") != string::npos) + Plasticity_type = 44; // direct stress intergration anisotropic plas. + Plasticity_Bedding = true; MicroStruTensor = new double[3]; Bedding_Norm = new double[3]; - TransMicroStru = new Matrix(6,6); - TransMicroStru_T = new Matrix(6,6); - TransMicroStru_TInv = new Matrix(6,6); - for(i=0; i<4; i++) + TransMicroStru = new Matrix(6, 6); + TransMicroStru_T = new Matrix(6, 6); + TransMicroStru_TInv = new Matrix(6, 6); + for (i = 0; i < 4; i++) { in_sd.str(GetLineFromFile1(msp_file)); - in_sd>>line_string; - if(line_string.find("MICRO_STRUCTURE_TENSOR")!=string::npos) + in_sd >> line_string; + if (line_string.find("MICRO_STRUCTURE_TENSOR") != string::npos) { - in_sd>>MicroStruTensor[0]>>MicroStruTensor[1]>>MicroStruTensor[2]; + in_sd >> MicroStruTensor[0] >> MicroStruTensor[1] >> MicroStruTensor[2]; } - else if(line_string.find("BEDDING_NORM")!=string::npos) + else if (line_string.find("BEDDING_NORM") != string::npos) { - in_sd>>Bedding_Norm[0]>>Bedding_Norm[1]>>Bedding_Norm[2]; + in_sd >> Bedding_Norm[0] >> Bedding_Norm[1] >> Bedding_Norm[2]; } /*else if(line_string.find("FRICTION_CURVE")!=string::npos) { in_sd>>bedding_fric_curve; }*/ - else if(line_string.find("UNIAXI_COMP_CURVE")!=string::npos) + else if (line_string.find("UNIAXI_COMP_CURVE") != string::npos) { - in_sd>>bedding_uc_curve_order; - comp_para = new double [bedding_uc_curve_order+1]; - for(int ii=0; ii>comp_para[ii]; + in_sd >> bedding_uc_curve_order; + comp_para = new double[bedding_uc_curve_order + 1]; + for (int ii = 0; ii < bedding_uc_curve_order + 1; ii++) + in_sd >> comp_para[ii]; } - else if(line_string.find("TENSION_CURVE")!=string::npos) + else if (line_string.find("TENSION_CURVE") != string::npos) { - in_sd>>bedding_tens_curve_order; - tens_para = new double [bedding_tens_curve_order+1]; - for(int ii=0; ii>tens_para[ii]; + in_sd >> bedding_tens_curve_order; + tens_para = new double[bedding_tens_curve_order + 1]; + for (int ii = 0; ii < bedding_tens_curve_order + 1; ii++) + in_sd >> tens_para[ii]; } - in_sd.clear(); - } + in_sd.clear(); + } CalTransMatrixMicroStru(TransMicroStru, Bedding_Norm); TransMicroStru->GetTranspose(*TransMicroStru_T); Cal_Inv_Matrix(6, TransMicroStru_T, TransMicroStru_TInv); - //TransMicroStru_T->Write(); - //TransMicroStru_TInv->Write(); - //TransMicroStru->Write(); + // TransMicroStru_T->Write(); + // TransMicroStru_TInv->Write(); + // TransMicroStru->Write(); } in_sd.clear(); } @@ -887,41 +874,46 @@ std::ios::pos_type CSolidProperties::Read(std::ifstream* msp_file) FEMLib-Method: Task: Set values for solid reactive system **************************************************************************/ -void CSolidProperties::SetSolidReactiveSystemProperties() //Definition auch in conversion_rate::conversion_rate +void CSolidProperties::SetSolidReactiveSystemProperties() // Definition auch in conversion_rate::conversion_rate { - if (reaction_system.compare("CaOH2") == 0) { - lower_solid_density_limit = 1656.0; //density Calciumoxid - upper_solid_density_limit = 2200.0; //density Calciumhydroxid - reaction_enthalpy = -1.12e+05/0.018; //in J/kg (Molar heat of reaction divided by molar mass of water) negative for exothermic composition reaction - reaction_entropy = -143.5/0.018; //in J/kgK + if (reaction_system.compare("CaOH2") == 0) + { + lower_solid_density_limit = 1656.0; // density Calciumoxid + upper_solid_density_limit = 2200.0; // density Calciumhydroxid + reaction_enthalpy = -1.12e+05 / 0.018; // in J/kg (Molar heat of reaction divided by molar mass of water) + // negative for exothermic composition reaction + reaction_entropy = -143.5 / 0.018; // in J/kgK } - else if (reaction_system.compare("Mn3O4") == 0) { - lower_solid_density_limit = 4500.0; //density Mn2O3 (Mangan(III)-oxid) - upper_solid_density_limit = 4860.0; //density Mn3O4 (Mangan(II,III)-oxid) - reaction_enthalpy = -1.376e+05/0.032; //in J/kg (Molar heat of reaction divided by molar mass of oxygen) negative for exothermic composition reaction - reaction_entropy = -114.1/0.032; //in J/kgK + else if (reaction_system.compare("Mn3O4") == 0) + { + lower_solid_density_limit = 4500.0; // density Mn2O3 (Mangan(III)-oxid) + upper_solid_density_limit = 4860.0; // density Mn3O4 (Mangan(II,III)-oxid) + reaction_enthalpy = -1.376e+05 / 0.032; // in J/kg (Molar heat of reaction divided by molar mass of oxygen) + // negative for exothermic composition reaction + reaction_entropy = -114.1 / 0.032; // in J/kgK } - else if (reaction_system.compare("Z13XBF") == 0) { - lower_solid_density_limit = 1150.0; //Dehydrated Zeolite pellet - upper_solid_density_limit = 1.e6; //state dependent; not needed for calculation - reaction_enthalpy = 0.0; //state dependent; calculated where needed - reaction_entropy = 0.0; //state dependent; calculated where needed + else if (reaction_system.compare("Z13XBF") == 0) + { + lower_solid_density_limit = 1150.0; // Dehydrated Zeolite pellet + upper_solid_density_limit = 1.e6; // state dependent; not needed for calculation + reaction_enthalpy = 0.0; // state dependent; calculated where needed + reaction_entropy = 0.0; // state dependent; calculated where needed } return; } - //========================================================================== +//========================================================================== - /************************************************************************** - FEMLib-Method: - Task: Constructor and destructor - Programing: - 08/2004 WW Implementation - 04/2005 WW Curve dependency +/************************************************************************** +FEMLib-Method: +Task: Constructor and destructor +Programing: +08/2004 WW Implementation +04/2005 WW Curve dependency **************************************************************************/ CSolidProperties::CSolidProperties() - : data_Youngs(NULL), data_Density(NULL), data_Capacity(NULL), - data_Conductivity(NULL), data_Plasticity(NULL), data_Creep(NULL) + : data_Youngs(NULL), data_Density(NULL), data_Capacity(NULL), data_Conductivity(NULL), data_Plasticity(NULL), + data_Creep(NULL) { PoissonRatio = 0.2; ThermalExpansion = 0.0; @@ -933,13 +925,13 @@ CSolidProperties::CSolidProperties() Conductivity_mode = -1; T_0 = 0.0; Creep_mode = -1; - grav_const = 9.81; //WW - excavation = -1; //12.2009. WW - excavated = false; //To be ..... 12.2009. WW - E_Function_Model = -1; //WX:06.2012 E dependence - threshold_dev_str = -1.; //WX:12.2012 - Time_Dependent_E_nv_mode = -1;//WX:01.2013 - Time_Dependent_E_nv_value[0] = -1;//WX:01.2013 + grav_const = 9.81; // WW + excavation = -1; // 12.2009. WW + excavated = false; // To be ..... 12.2009. WW + E_Function_Model = -1; // WX:06.2012 E dependence + threshold_dev_str = -1.; // WX:12.2012 + Time_Dependent_E_nv_mode = -1; // WX:01.2013 + Time_Dependent_E_nv_value[0] = -1; // WX:01.2013 SwellingPressureType = -1; Max_SwellingPressure = 0.0; @@ -947,7 +939,7 @@ CSolidProperties::CSolidProperties() Plasticity_type = -1; E = Lambda = G = K = 0.0; - Ks = 0.; //WX: 04.2013 + Ks = 0.; // WX: 04.2013 devS = NULL; axisymmetry = false; dl2 = 0.0; @@ -965,10 +957,10 @@ CSolidProperties::CSolidProperties() dGds = NULL; D_dFds = NULL; D_dGds = NULL; - dFtds = NULL; //WX - dGtds = NULL; //WX - ConstitutiveMatrix = NULL; //WX - //WX:08.2011 for mohr coulomb + dFtds = NULL; // WX + dGtds = NULL; // WX + ConstitutiveMatrix = NULL; // WX + // WX:08.2011 for mohr coulomb TransMatrixA = NULL; TransMatrixA_T = NULL; Inv_TransA = NULL; @@ -981,31 +973,31 @@ CSolidProperties::CSolidProperties() Dep_l = NULL; dDep_l = NULL; dGds_dFds = NULL; - Plasticity_Bedding = false; //WX:09.2011 - TransMicroStru = NULL;//WX:11.2011 - MicroStruTensor=NULL;//WX:11.2011 - TransMicroStru_T=NULL; - TransMicroStru_TInv=NULL; + Plasticity_Bedding = false; // WX:09.2011 + TransMicroStru = NULL; // WX:11.2011 + MicroStruTensor = NULL; // WX:11.2011 + TransMicroStru_T = NULL; + TransMicroStru_TInv = NULL; comp_para = NULL; tens_para = NULL; // Curve variable type // 0: Time // 1: ... CurveVariableType_Conductivity = -1; - mode = 0; // Gauss point values //OK + mode = 0; // Gauss point values //OK // s_tol = 1e-9; f_tol = 1e-9; - Crotm = NULL; // rotation matrix for matrices: UJG 25.11.2009 - D_tran = NULL; //UJG/WW + Crotm = NULL; // rotation matrix for matrices: UJG 25.11.2009 + D_tran = NULL; // UJG/WW // Thermal conductivity tensor (default: iso) thermal_conductivity_tensor_type = 0; thermal_conductivity_tensor_dim = 1; thermal_conductivity_tensor[0] = 1.0; - //Reactive system + // Reactive system reaction_system = "INERT"; _reactive_system = FiniteElement::INERT; lower_solid_density_limit = 0.0; @@ -1017,29 +1009,29 @@ CSolidProperties::CSolidProperties() specific_heat_source = 0.0; - bishop_model = -1; //15.08.2011. WW - } + bishop_model = -1; // 15.08.2011. WW +} CSolidProperties::~CSolidProperties() { - if(data_Density) + if (data_Density) delete data_Density; - if(data_Density) + if (data_Density) delete data_Youngs; - if(data_Plasticity) + if (data_Plasticity) delete data_Plasticity; - if(data_Capacity) + if (data_Capacity) delete data_Capacity; - if(data_Conductivity) + if (data_Conductivity) delete data_Conductivity; - if(data_Creep) + if (data_Creep) delete data_Creep; - if(devS) - delete [] devS; + if (devS) + delete[] devS; - if(Crotm) - delete Crotm; // rotation matrix for matrices: UJG 25.11.2009 - if(D_tran) - delete D_tran; // rotation matrix for matrices: UJG 25.11.2009 + if (Crotm) + delete Crotm; // rotation matrix for matrices: UJG 25.11.2009 + if (D_tran) + delete D_tran; // rotation matrix for matrices: UJG 25.11.2009 data_Density = NULL; data_Youngs = NULL; data_Plasticity = NULL; @@ -1050,81 +1042,81 @@ CSolidProperties::~CSolidProperties() Crotm = NULL; D_tran = NULL; - if(d2G_dSdS) + if (d2G_dSdS) delete d2G_dSdS; - if(d2G_dSdM) + if (d2G_dSdM) delete d2G_dSdM; - if(LocalJacobi) - delete LocalJacobi; // To store local Jacobi matrix - if(inv_Jac) - delete inv_Jac; // To store the inverse of the Jacobi matrix - if(sumA_Matrix) + if (LocalJacobi) + delete LocalJacobi; // To store local Jacobi matrix + if (inv_Jac) + delete inv_Jac; // To store the inverse of the Jacobi matrix + if (sumA_Matrix) delete sumA_Matrix; - if(rhs_l) - delete [] rhs_l; // To store local unknowns of 15 - if(x_l) - delete [] x_l; // To store local unknowns of 15 - if(Li) - delete [] Li; - - if(dFds) - delete [] dFds; - if(dGds) - delete [] dGds; - if(D_dFds) - delete [] D_dFds; - if(D_dGds) - delete [] D_dGds; - if(dFtds) - delete [] dFtds; //WX: - if(dGtds) - delete [] dGtds; //WX: - if(ConstitutiveMatrix) - delete ConstitutiveMatrix; //WX: - if(TransMatrixA) - delete TransMatrixA;//WX:08.2011 - if(TransMatrixA_T) + if (rhs_l) + delete[] rhs_l; // To store local unknowns of 15 + if (x_l) + delete[] x_l; // To store local unknowns of 15 + if (Li) + delete[] Li; + + if (dFds) + delete[] dFds; + if (dGds) + delete[] dGds; + if (D_dFds) + delete[] D_dFds; + if (D_dGds) + delete[] D_dGds; + if (dFtds) + delete[] dFtds; // WX: + if (dGtds) + delete[] dGtds; // WX: + if (ConstitutiveMatrix) + delete ConstitutiveMatrix; // WX: + if (TransMatrixA) + delete TransMatrixA; // WX:08.2011 + if (TransMatrixA_T) delete TransMatrixA_T; - if(Inv_TransA) + if (Inv_TransA) delete Inv_TransA; - if(Inv_TransA_T) + if (Inv_TransA_T) delete Inv_TransA_T; - if(TmpDe) + if (TmpDe) delete TmpDe; - if(Inv_De) + if (Inv_De) delete Inv_De; - if(TMatrix) + if (TMatrix) delete TMatrix; - if(TmpMatrix) + if (TmpMatrix) delete TmpMatrix; - if(TmpMatrix2) + if (TmpMatrix2) delete TmpMatrix2; - if(Dep_l) + if (Dep_l) delete Dep_l; - if(dDep_l) + if (dDep_l) delete dDep_l; - if(dGds_dFds) - delete dGds_dFds;//WX:08.2011 - if(TransMicroStru) - delete TransMicroStru;//WX:11.2011 - if(MicroStruTensor) - delete MicroStruTensor;//WX:11.2011 - if(TransMicroStru_T) + if (dGds_dFds) + delete dGds_dFds; // WX:08.2011 + if (TransMicroStru) + delete TransMicroStru; // WX:11.2011 + if (MicroStruTensor) + delete MicroStruTensor; // WX:11.2011 + if (TransMicroStru_T) delete TransMicroStru_T; - if(TransMicroStru_TInv) + if (TransMicroStru_TInv) delete TransMicroStru_TInv; - if(comp_para) + if (comp_para) delete comp_para; - if(tens_para) + if (tens_para) delete tens_para; dFds = NULL; dGds = NULL; D_dFds = NULL; D_dGds = NULL; - dFtds = NULL; //WX: - dGtds = NULL; //WX: - TransMatrixA = NULL;//WX:08.2011 + dFtds = NULL; // WX: + dGtds = NULL; // WX: + TransMatrixA = NULL; // WX:08.2011 TransMatrixA_T = NULL; Inv_TransA = NULL; Inv_TransA_T = NULL; @@ -1135,14 +1127,14 @@ CSolidProperties::~CSolidProperties() TmpMatrix2 = NULL; Dep_l = NULL; dDep_l = NULL; - dGds_dFds = NULL;//WX:08.2011 - ConstitutiveMatrix = NULL; //WX: - TransMicroStru=NULL;//WX:11.2011 - MicroStruTensor = NULL;//WX:11.2011 + dGds_dFds = NULL; // WX:08.2011 + ConstitutiveMatrix = NULL; // WX: + TransMicroStru = NULL; // WX:11.2011 + MicroStruTensor = NULL; // WX:11.2011 TransMicroStru_T = NULL; - TransMicroStru_TInv=NULL; + TransMicroStru_TInv = NULL; comp_para = NULL; - tens_para = NULL;//WX + tens_para = NULL; // WX d2G_dSdS = NULL; d2G_dSdM = NULL; LocalJacobi = NULL; @@ -1160,26 +1152,25 @@ CSolidProperties::~CSolidProperties() Programing: 08/2004 WW Implementation **************************************************************************/ -double CSolidProperties::CalulateValue - (const Matrix* data, const double x) const +double CSolidProperties::CalulateValue(const Matrix* data, const double x) const { int i; double Val = 0.0; - if(!data) + if (!data) return 0.0; const int Size = data->Rows(); // If given varial is not in the range of data - if(x < (*data)(0,0)) - Val = (*data)(0,1); - else if(x >= (*data)(Size - 1,0)) - Val = (*data)(Size - 1,1); + if (x < (*data)(0, 0)) + Val = (*data)(0, 1); + else if (x >= (*data)(Size - 1, 0)) + Val = (*data)(Size - 1, 1); else - for(i = 0; i < Size - 1; i++) - if((x >= (*data)(i,0)) && (x < (*data)(i + 1,0))) - Val = (x - (*data)(i,0)) * ((*data)(i + 1,1) - (*data)(i,1)) - / ((*data)(i + 1,0) - (*data)(i,0)) + (*data)(i,1); + for (i = 0; i < Size - 1; i++) + if ((x >= (*data)(i, 0)) && (x < (*data)(i + 1, 0))) + Val = (x - (*data)(i, 0)) * ((*data)(i + 1, 1) - (*data)(i, 1)) / ((*data)(i + 1, 0) - (*data)(i, 0)) + + (*data)(i, 1); return Val; } @@ -1190,17 +1181,17 @@ double CSolidProperties::CalulateValue Programing: 08/2004 WW Implementation **************************************************************************/ -double CSolidProperties::Density(double refence ) +double CSolidProperties::Density(double refence) { double val = 0.0; - switch(Density_mode) + switch (Density_mode) { - case 0: - val = CalulateValue(data_Density, refence); - break; - case 1: - val = (*data_Density)(0); - break; + case 0: + val = CalulateValue(data_Density, refence); + break; + case 1: + val = (*data_Density)(0); + break; } return val; } @@ -1214,89 +1205,93 @@ double CSolidProperties::Density(double refence ) double CSolidProperties::Heat_Capacity(double refence) { double val = 0.0; - switch(Capacity_mode) + switch (Capacity_mode) { - case 0: - val = CalulateValue(data_Capacity, refence); - break; - case 1: - val = (*data_Capacity)(0); - break; - case 3: - //WW val=1.38*(273.15+refence)+732.5; - val=1.38*refence+732.5; - break; - case 4: //solid capacity depending on solid density (for thermochemical heat storage) - TN - //refence contains value of solid density (current) - val = (*data_Capacity)(0) + ((*data_Capacity)(1)-(*data_Capacity)(0))/((*data_Capacity)(3)-(*data_Capacity)(2))*(refence - (*data_Capacity)(2)); - break; - case 5: - // TODO [CL]: TES heat capacity model number changed 4-->5 - val = (*data_Capacity)(0) + ((*data_Capacity)(1)-(*data_Capacity)(0))/(upper_solid_density_limit - lower_solid_density_limit)*(refence - lower_solid_density_limit); - break; - case 6: //in a sorption system - { - // TODO [CL]: TES heat capacity model number changed 5-->6 - double C = refence/lower_solid_density_limit - 1.0; - val = lower_solid_density_limit/refence * ((*data_Capacity)(0) + C * (*data_Capacity)(1)); - } - break; - default: - val = (*data_Capacity)(0); + case 0: + val = CalulateValue(data_Capacity, refence); + break; + case 1: + val = (*data_Capacity)(0); + break; + case 3: + // WW val=1.38*(273.15+refence)+732.5; + val = 1.38 * refence + 732.5; + break; + case 4: // solid capacity depending on solid density (for thermochemical heat storage) - TN + // refence contains value of solid density (current) + val = (*data_Capacity)(0) + + ((*data_Capacity)(1) - (*data_Capacity)(0)) / ((*data_Capacity)(3) - (*data_Capacity)(2)) + * (refence - (*data_Capacity)(2)); + break; + case 5: + // TODO [CL]: TES heat capacity model number changed 4-->5 + val = (*data_Capacity)(0) + + ((*data_Capacity)(1) - (*data_Capacity)(0)) + / (upper_solid_density_limit - lower_solid_density_limit) + * (refence - lower_solid_density_limit); + break; + case 6: // in a sorption system + { + // TODO [CL]: TES heat capacity model number changed 5-->6 + double C = refence / lower_solid_density_limit - 1.0; + val = lower_solid_density_limit / refence * ((*data_Capacity)(0) + C * (*data_Capacity)(1)); + } break; + default: + val = (*data_Capacity)(0); + break; } return val; } - /************************************************************************* - FEMLib-Method: - Task: Get heat phase change temperature - Programing: - 09/2005 WW Implementation - **************************************************************************/ - bool CSolidProperties:: CheckTemperature_in_PhaseChange - (const double T0, const double T1) - { - bool stat = false; - double T_a=(*data_Capacity)(2); - double T_b=(*data_Capacity)(2)+(*data_Capacity)(3); - switch(Capacity_mode) - { - case 0: - break; - case 1: - break; - case 2: - if((T1>T0)&&(*data_Capacity)(4)>0.0) - { - if((T0T_a)) - stat = true; - else if((T0T_b)) - stat = true; - else if((T0T_b)) - stat = true; - else if((T1>=T_a)&&(T1<=T_b)) - stat = true; - } - break; - } - return stat; - } - - /************************************************************************* - FEMLib-Method: - Task: Get heat capacity with boiling model - latent_factor=density_w*porosity*saturation - Programing: - 09/2005 WW Implementation - **************************************************************************/ +/************************************************************************* +FEMLib-Method: +Task: Get heat phase change temperature +Programing: +09/2005 WW Implementation +**************************************************************************/ +bool CSolidProperties::CheckTemperature_in_PhaseChange(const double T0, const double T1) +{ + bool stat = false; + double T_a = (*data_Capacity)(2); + double T_b = (*data_Capacity)(2) + (*data_Capacity)(3); + switch (Capacity_mode) + { + case 0: + break; + case 1: + break; + case 2: + if ((T1 > T0) && (*data_Capacity)(4) > 0.0) + { + if ((T0 < T_a) && (T1 > T_a)) + stat = true; + else if ((T0 < T_a) && (T1 > T_b)) + stat = true; + else if ((T0 < T_b) && (T1 > T_b)) + stat = true; + else if ((T1 >= T_a) && (T1 <= T_b)) + stat = true; + } + break; + } + return stat; +} + +/************************************************************************* +FEMLib-Method: +Task: Get heat capacity with boiling model + latent_factor=density_w*porosity*saturation +Programing: +09/2005 WW Implementation +**************************************************************************/ double CSolidProperties::Heat_Capacity(double temperature, double porosity, double Sat) { double val = 0.0; double sign = 1; double dens = fabs(Density()); // If sign =1, temperature increases in evolution. Otherwise, decrease. - if(fabs(temperature) > 1.e-9) + if (fabs(temperature) > 1.e-9) sign = fabs(temperature) / temperature; temperature *= sign; CFluidProperties* m_mfp = NULL; @@ -1307,24 +1302,22 @@ double CSolidProperties::Heat_Capacity(double temperature, double porosity, doub // 2. Boiling temperature // 3. Boiling temperature range // 4. Latent of vaporization - if(temperature < (*data_Capacity)(2)) // Wet - val = dens * (*data_Capacity)(0); - else if((temperature >= (*data_Capacity)(2)) && - (temperature < ((*data_Capacity)(2) + (*data_Capacity)(3)))) + if (temperature < (*data_Capacity)(2)) // Wet + val = dens * (*data_Capacity)(0); + else if ((temperature >= (*data_Capacity)(2)) && (temperature < ((*data_Capacity)(2) + (*data_Capacity)(3)))) { - if(sign > 0.0) // Temperature increase - val = dens * (*data_Capacity)(0) + dens * - ((*data_Capacity)(1) - (*data_Capacity)(0)) - * (temperature - (*data_Capacity)(2)) / (*data_Capacity)(3) - + porosity* Sat* m_mfp->Density() * (*data_Capacity)(4) / - (*data_Capacity)(3); + if (sign > 0.0) // Temperature increase + val = dens * (*data_Capacity)(0) + + dens * ((*data_Capacity)(1) - (*data_Capacity)(0)) * (temperature - (*data_Capacity)(2)) + / (*data_Capacity)(3) + + porosity * Sat * m_mfp->Density() * (*data_Capacity)(4) / (*data_Capacity)(3); else - val = dens * (*data_Capacity)(0) + dens * - ((*data_Capacity)(1) - (*data_Capacity)(0)) - * (temperature - (*data_Capacity)(2)) / (*data_Capacity)(3); + val = dens * (*data_Capacity)(0) + + dens * ((*data_Capacity)(1) - (*data_Capacity)(0)) * (temperature - (*data_Capacity)(2)) + / (*data_Capacity)(3); } else - val = (*data_Capacity)(1); + val = (*data_Capacity)(1); return val; } @@ -1336,10 +1329,10 @@ double CSolidProperties::Heat_Capacity(double temperature, double porosity, doub Programing: 09/2005 WW Implementation **************************************************************************/ -double CSolidProperties::Enthalpy(double temperature, const double latent_factor ) +double CSolidProperties::Enthalpy(double temperature, const double latent_factor) { double val = 0.0; - double T0 = 0.0; //�C, a reference temperature + double T0 = 0.0; //�C, a reference temperature double dT = 0.0; // 0. Wet capacity @@ -1347,28 +1340,24 @@ double CSolidProperties::Enthalpy(double temperature, const double latent_factor // 2. Boiling temperature // 3. Boiling temperature range // 4. Latent of vaporization - if(temperature < (*data_Capacity)(2)) // Wet - val = (*data_Capacity)(0) * (temperature - T0); - else if((temperature >= (*data_Capacity)(2)) && - (temperature < ((*data_Capacity)(2) + (*data_Capacity)(3)))) + if (temperature < (*data_Capacity)(2)) // Wet + val = (*data_Capacity)(0) * (temperature - T0); + else if ((temperature >= (*data_Capacity)(2)) && (temperature < ((*data_Capacity)(2) + (*data_Capacity)(3)))) { dT = temperature - (*data_Capacity)(2) - T0; - val = (*data_Capacity)(0) * ((*data_Capacity)(2) - T0); + val = (*data_Capacity)(0) * ((*data_Capacity)(2) - T0); val += dT * latent_factor * (*data_Capacity)(4) / (*data_Capacity)(3) / Density(); - val += (*data_Capacity)(0) * dT - + 0.5 * dT * dT * - ((*data_Capacity)(1) - (*data_Capacity)(0)) / (*data_Capacity)(3); + val += (*data_Capacity)(0) * dT + + 0.5 * dT * dT * ((*data_Capacity)(1) - (*data_Capacity)(0)) / (*data_Capacity)(3); } else { - dT = (*data_Capacity)(3); - val = (*data_Capacity)(0) * ((*data_Capacity)(2) - T0); + dT = (*data_Capacity)(3); + val = (*data_Capacity)(0) * ((*data_Capacity)(2) - T0); val += dT * latent_factor * (*data_Capacity)(4) / (*data_Capacity)(3) / Density(); - val += (*data_Capacity)(0) * dT - + 0.5 * dT * dT * - ((*data_Capacity)(1) - (*data_Capacity)(0)) / (*data_Capacity)(3); - val += (*data_Capacity)(1) * - (temperature - (*data_Capacity)(3) - (*data_Capacity)(2) - T0); + val += (*data_Capacity)(0) * dT + + 0.5 * dT * dT * ((*data_Capacity)(1) - (*data_Capacity)(0)) / (*data_Capacity)(3); + val += (*data_Capacity)(1) * (temperature - (*data_Capacity)(3) - (*data_Capacity)(2) - T0); } return val * fabs(Density()); } @@ -1383,50 +1372,49 @@ double CSolidProperties::Heat_Conductivity(double refence) { double val = 0.0; int gueltig; - switch(Conductivity_mode) + switch (Conductivity_mode) { - case 0: - val = CalulateValue(data_Conductivity, refence); - break; - case 1: - val = (*data_Conductivity)(0); - break; - case 2: + case 0: + val = CalulateValue(data_Conductivity, refence); + break; + case 1: + val = (*data_Conductivity)(0); + break; + case 2: { - const double *k_T = data_Conductivity->getEntryArray(); - - // 0. Wet conductivity - // 1. Dry conductivity - // 2. Boiling temperature - // 3. Boiling temperature range - if(refence < k_T[2]) // Wet - val = k_T[0]; - else if((refence >= k_T[2]) && - (refence < (k_T[2] + k_T[3]))) - val = k_T[0] + (k_T[0] - k_T[1]) * (refence - k_T[2]) / k_T[3]; - else - val = k_T[1]; + const double* k_T = data_Conductivity->getEntryArray(); + + // 0. Wet conductivity + // 1. Dry conductivity + // 2. Boiling temperature + // 3. Boiling temperature range + if (refence < k_T[2]) // Wet + val = k_T[0]; + else if ((refence >= k_T[2]) && (refence < (k_T[2] + k_T[3]))) + val = k_T[0] + (k_T[0] - k_T[1]) * (refence - k_T[2]) / k_T[3]; + else + val = k_T[1]; } break; - case 3: // refence: saturation - //val = 1.28-0.71/(1+10.0*exp(refence-0.65)); //MX - val = 1.28 - 0.71 / (1 + exp(10.0 * (refence - 0.65))); - break; - case 30: // Another model for bentonite. 10.2013. WW + case 3: // refence: saturation + // val = 1.28-0.71/(1+10.0*exp(refence-0.65)); //MX + val = 1.28 - 0.71 / (1 + exp(10.0 * (refence - 0.65))); + break; + case 30: // Another model for bentonite. 10.2013. WW { - //val = k_max-k_min/(1+10.0*exp(refence-S0)); - const double *k_T = data_Conductivity->getEntryArray(); -// val = k_T[0] - (k_T[0]-k_T[1]) / (1 + exp(10.0 * (refence - k_T[2]))); - val = k_T[0] + k_T[1]* (refence - k_T[2]); + // val = k_max-k_min/(1+10.0*exp(refence-S0)); + const double* k_T = data_Conductivity->getEntryArray(); + // val = k_T[0] - (k_T[0]-k_T[1]) / (1 + exp(10.0 * (refence - k_T[2]))); + val = k_T[0] + k_T[1] * (refence - k_T[2]); } break; - case 4: //21.12.2009. WW - val = CalulateValue(data_Conductivity, refence); - break; - case 5: // DECOVALEX2015, TaskB2 JM - CalPrimaryVariable(capacity_pcs_name_vector); - val = GetMatrixValue(primary_variable[0]+T_0,primary_variable[1],name,&gueltig); - break; + case 4: // 21.12.2009. WW + val = CalulateValue(data_Conductivity, refence); + break; + case 5: // DECOVALEX2015, TaskB2 JM + CalPrimaryVariable(capacity_pcs_name_vector); + val = GetMatrixValue(primary_variable[0] + T_0, primary_variable[1], name, &gueltig); + break; } return val; } @@ -1443,96 +1431,94 @@ double CSolidProperties::Heat_Conductivity(double refence) **************************************************************************/ void CSolidProperties::HeatConductivityTensor(const int dim, double* tensor, int group) { - group = group; //OK411 - //static double tensor[9]; + group = group; // OK411 + // static double tensor[9]; double temperature = 0.0; double saturation = 0.0; int i = 0; - //WW + // WW CalPrimaryVariable(conductivity_pcs_name_vector); //-------------------------------------------------------------------- // MMP medium properties - //WW CMediumProperties *m_mmp = NULL; - //WW m_mmp = mmp_vector[group]; //MX + // WW CMediumProperties *m_mmp = NULL; + // WW m_mmp = mmp_vector[group]; //MX // Test for DECOVALEX // thermal_conductivity_tensor[0] =0.5+0.8*PCSGetELEValue(number,NULL,theta,"SATURATION1"); //-------------------------------------------------------------------- - //There are a number of cases where the heat conductivity tensor is defined by the capacity model; + // There are a number of cases where the heat conductivity tensor is defined by the capacity model; double base_thermal_conductivity = .0; - int gueltig=1; + int gueltig = 1; switch (Conductivity_mode) { - case 0: - //WW - base_thermal_conductivity = Heat_Conductivity(primary_variable[0]); - break; - case 1: - //WW - base_thermal_conductivity = Heat_Conductivity(0); - break; - case 2: // Boiling model. DECOVALEX THM2 - temperature = primary_variable[0]; - base_thermal_conductivity = Heat_Conductivity(temperature); - break; - case 3: // DECOVALEX THM1 - saturation = primary_variable[1]; - base_thermal_conductivity = Heat_Conductivity(saturation); - break; - case 5: - base_thermal_conductivity = GetMatrixValue(primary_variable[1],primary_variable[0]+T_0,name,&gueltig); - break; - default: //Normal case - cout << - "***Error in CSolidProperties::HeatConductivityTensor(): conductivity mode is not supported " - << "\n"; - //base_thermal_conductivity = Heat_Conductivity(); + case 0: + // WW + base_thermal_conductivity = Heat_Conductivity(primary_variable[0]); + break; + case 1: + // WW + base_thermal_conductivity = Heat_Conductivity(0); + break; + case 2: // Boiling model. DECOVALEX THM2 + temperature = primary_variable[0]; + base_thermal_conductivity = Heat_Conductivity(temperature); + break; + case 3: // DECOVALEX THM1 + saturation = primary_variable[1]; + base_thermal_conductivity = Heat_Conductivity(saturation); + break; + case 5: + base_thermal_conductivity = GetMatrixValue(primary_variable[1], primary_variable[0] + T_0, name, &gueltig); + break; + default: // Normal case + cout << "***Error in CSolidProperties::HeatConductivityTensor(): conductivity mode is not supported " + << "\n"; + // base_thermal_conductivity = Heat_Conductivity(); } //-------------------------------------------------------------------- - //Set unit tensor - //check + // Set unit tensor + // check if (thermal_conductivity_tensor_type > 0 && dim != thermal_conductivity_tensor_dim) - cout << - "***Error in CSolidProperties::HeatConductivityTensor(): problem dimension and the given tensor dimension are not same." + cout << "***Error in CSolidProperties::HeatConductivityTensor(): problem dimension and the given tensor " + "dimension are not same." << "\n"; - //reset - for(i = 0; i < 9; i++) + // reset + for (i = 0; i < 9; i++) tensor[i] = 0.0; - //set + // set switch (thermal_conductivity_tensor_type) { - case 0: //Iso - for(i = 0; i < dim; i++) - tensor[i * dim + i] = 1.0; - break; - case 1: //Ortho - switch (thermal_conductivity_tensor_dim) - { - case 1: // 1-D - tensor[0] = thermal_conductivity_tensor[0]; + case 0: // Iso + for (i = 0; i < dim; i++) + tensor[i * dim + i] = 1.0; break; - case 2: // 2-D - tensor[0] = thermal_conductivity_tensor[0]; - tensor[3] = thermal_conductivity_tensor[1]; + case 1: // Ortho + switch (thermal_conductivity_tensor_dim) + { + case 1: // 1-D + tensor[0] = thermal_conductivity_tensor[0]; + break; + case 2: // 2-D + tensor[0] = thermal_conductivity_tensor[0]; + tensor[3] = thermal_conductivity_tensor[1]; + break; + case 3: // 3-D + tensor[0] = thermal_conductivity_tensor[0]; + tensor[4] = thermal_conductivity_tensor[1]; + tensor[8] = thermal_conductivity_tensor[2]; + break; + } break; - case 3: // 3-D - tensor[0] = thermal_conductivity_tensor[0]; - tensor[4] = thermal_conductivity_tensor[1]; - tensor[8] = thermal_conductivity_tensor[2]; + case 2: // Aniso + for (i = 0; i < thermal_conductivity_tensor_dim * thermal_conductivity_tensor_dim; i++) + tensor[i] = thermal_conductivity_tensor[i]; break; - } - break; - case 2: //Aniso - for(i = 0; i < thermal_conductivity_tensor_dim * thermal_conductivity_tensor_dim; - i++) - tensor[i] = thermal_conductivity_tensor[i]; - break; } //-------------------------------------------------------------------- - //tensor form - for(i = 0; i < dim * dim; i++) + // tensor form + for (i = 0; i < dim * dim; i++) tensor[i] *= base_thermal_conductivity; } @@ -1545,14 +1531,14 @@ void CSolidProperties::HeatConductivityTensor(const int dim, double* tensor, int double CSolidProperties::Youngs_Modulus(double refence) { double val = 0.0; - switch(Youngs_mode) + switch (Youngs_mode) { - case 0: - val = CalulateValue(data_Youngs, refence); - break; - case 1: - val = (*data_Youngs)(0); - break; + case 0: + val = CalulateValue(data_Youngs, refence); + break; + case 1: + val = (*data_Youngs)(0); + break; } return val; } @@ -1562,7 +1548,7 @@ double CSolidProperties::Youngs_Modulus(double refence) double CSolidProperties::Kronecker(const int ii, const int jj) { double delta = 0.0; - if(ii == jj) + if (ii == jj) delta = 1.0; return delta; } @@ -1576,23 +1562,23 @@ double CSolidProperties::Kronecker(const int ii, const int jj) void CSolidProperties::Calculate_Lame_Constant() { double nv = Poisson_Ratio(); - E = Youngs_Modulus(); // Constant at present - //WX:1.2013. time dependet - if(Time_Dependent_E_nv_mode>0) + E = Youngs_Modulus(); // Constant at present + // WX:1.2013. time dependet + if (Time_Dependent_E_nv_mode > 0) { int valid = 1; - switch(Time_Dependent_E_nv_mode) + switch (Time_Dependent_E_nv_mode) { - case 1: - nv *= GetCurveValue(Time_Dependent_E_nv_value[1],0,aktuelle_zeit,&valid); - E *= GetCurveValue(Time_Dependent_E_nv_value[0],0,aktuelle_zeit,&valid); - break; - case 2: - cout<<"WARNING: for isotropic elasticity, please use TIME_DEPENDENT_YOUNG_POISSON mode=1"<0) + // WX:01.2013, time dependet + if (Time_Dependent_E_nv_mode > 0) { int valid = 1; - switch(Time_Dependent_E_nv_mode) + switch (Time_Dependent_E_nv_mode) { - case 1: - cout<<"WARNING: for transversely isotropic elasticity, please use TIME_DEPENDENT_YOUNG_POISSON mode=2"< 9 && Youngs_mode < 14)) //WW + if (!(Youngs_mode > 9 && Youngs_mode < 14)) // WW return; - if(Youngs_mode != 10) + if (Youngs_mode != 10) { ElasticConstitutiveTransverseIsotropic(Dimension); return; @@ -1872,23 +1857,23 @@ void CSolidProperties::CalculateTransformMatrixFromNormalVector(const int Dimens double Disk(1.0), t1(0.0), t2(0.0), t3(0.0), ax(1.0), ay(0.0), az(0.0); // rotation matrix for vectors: UJG 25.11.2009 - Matrix* Crotv = new Matrix(Dimension,Dimension); - Crotm = new Matrix(Dimension * 2,Dimension * 2); // rotation matrix for matrices: UJG 25.11.2009 + Matrix* Crotv = new Matrix(Dimension, Dimension); + Crotm = new Matrix(Dimension * 2, Dimension * 2); // rotation matrix for matrices: UJG 25.11.2009 - if(Dimension == 3) + if (Dimension == 3) { - if(nz < -1.0) + if (nz < -1.0) { - t1 = 0.01745329252 * nx; - t2 = 0.01745329252 * ny; + t1 = 0.01745329252 * nx; + t2 = 0.01745329252 * ny; e3[0] = sin(t1) * cos(t2); e3[1] = -sin(t2); e3[2] = cos(t1) * cos(t2); } - else if(nz > 1.0) + else if (nz > 1.0) { - t1 = 0.01745329252 * nx; - t2 = 0.01745329252 * ny; + t1 = 0.01745329252 * nx; + t2 = 0.01745329252 * ny; e3[0] = sin(t2) * sin(t1); e3[1] = sin(t2) * cos(t1); e3[2] = cos(t2); @@ -1904,7 +1889,7 @@ void CSolidProperties::CalculateTransformMatrixFromNormalVector(const int Dimens ay = e3[1]; az = e3[2]; - if(ax == 0.0) + if (ax == 0.0) { e1[0] = 1.0; e1[1] = 0.0; @@ -1926,11 +1911,11 @@ void CSolidProperties::CalculateTransformMatrixFromNormalVector(const int Dimens e1[1] = 0.0; e1[2] = -Disk; - t1 = ay * e1[2]; - t2 = az * e1[0] - ax * e1[2]; - t3 = -ay * e1[0]; + t1 = ay * e1[2]; + t2 = az * e1[0] - ax * e1[2]; + t3 = -ay * e1[0]; - Disk = t1 * t1; + Disk = t1 * t1; Disk += t2 * t2; Disk += t3 * t3; @@ -1941,63 +1926,63 @@ void CSolidProperties::CalculateTransformMatrixFromNormalVector(const int Dimens e2[2] = Disk * t3; } - (*Crotv)(0,0) = e1[0]; - (*Crotv)(0,1) = e1[1]; - (*Crotv)(0,2) = e1[2]; - - (*Crotv)(1,0) = e2[0]; - (*Crotv)(1,1) = e2[1]; - (*Crotv)(1,2) = e2[2]; - - (*Crotv)(2,0) = e3[0]; - (*Crotv)(2,1) = e3[1]; - (*Crotv)(2,2) = e3[2]; - - (*Crotm)(0,0) = (*Crotv)(0,0) * (*Crotv)(0,0); - (*Crotm)(0,1) = (*Crotv)(0,1) * (*Crotv)(0,1); - (*Crotm)(0,2) = (*Crotv)(0,2) * (*Crotv)(0,2); - (*Crotm)(0,3) = (*Crotv)(0,0) * (*Crotv)(0,1); - (*Crotm)(0,4) = (*Crotv)(0,0) * (*Crotv)(0,2); - (*Crotm)(0,5) = (*Crotv)(0,1) * (*Crotv)(0,2); - - (*Crotm)(1,0) = (*Crotv)(1,0) * (*Crotv)(1,0); - (*Crotm)(1,1) = (*Crotv)(1,1) * (*Crotv)(1,1); - (*Crotm)(1,2) = (*Crotv)(1,2) * (*Crotv)(1,2); - (*Crotm)(1,3) = (*Crotv)(1,0) * (*Crotv)(1,1); - (*Crotm)(1,4) = (*Crotv)(1,0) * (*Crotv)(1,2); - (*Crotm)(1,5) = (*Crotv)(1,1) * (*Crotv)(1,2); - - (*Crotm)(2,0) = (*Crotv)(2,0) * (*Crotv)(2,0); - (*Crotm)(2,1) = (*Crotv)(2,1) * (*Crotv)(2,1); - (*Crotm)(2,2) = (*Crotv)(2,2) * (*Crotv)(2,2); - (*Crotm)(2,3) = (*Crotv)(2,0) * (*Crotv)(2,1); - (*Crotm)(2,4) = (*Crotv)(2,0) * (*Crotv)(2,2); - (*Crotm)(2,5) = (*Crotv)(2,1) * (*Crotv)(2,2); - - (*Crotm)(3,0) = 2.0 * (*Crotv)(0,0) * (*Crotv)(1,0); - (*Crotm)(3,1) = 2.0 * (*Crotv)(0,1) * (*Crotv)(1,1); - (*Crotm)(3,2) = 2.0 * (*Crotv)(0,2) * (*Crotv)(1,2); - (*Crotm)(3,3) = (*Crotv)(0,0) * (*Crotv)(1,1) + (*Crotv)(1,0) * (*Crotv)(0,1); - (*Crotm)(3,4) = (*Crotv)(0,0) * (*Crotv)(1,2) + (*Crotv)(0,2) * (*Crotv)(1,0); - (*Crotm)(3,5) = (*Crotv)(0,1) * (*Crotv)(1,2) + (*Crotv)(0,2) * (*Crotv)(1,1); - - (*Crotm)(4,0) = 2.0 * (*Crotv)(0,0) * (*Crotv)(2,0); - (*Crotm)(4,1) = 2.0 * (*Crotv)(0,1) * (*Crotv)(2,1); - (*Crotm)(4,2) = 2.0 * (*Crotv)(0,2) * (*Crotv)(2,2); - (*Crotm)(4,3) = (*Crotv)(0,0) * (*Crotv)(2,1) + (*Crotv)(0,1) * (*Crotv)(2,0); - (*Crotm)(4,4) = (*Crotv)(0,0) * (*Crotv)(2,2) + (*Crotv)(2,0) * (*Crotv)(0,2); - (*Crotm)(4,5) = (*Crotv)(0,1) * (*Crotv)(2,2) + (*Crotv)(0,2) * (*Crotv)(2,1); - - (*Crotm)(5,0) = 2.0 * (*Crotv)(1,0) * (*Crotv)(2,0); - (*Crotm)(5,1) = 2.0 * (*Crotv)(1,1) * (*Crotv)(2,1); - (*Crotm)(5,2) = 2.0 * (*Crotv)(1,2) * (*Crotv)(2,2); - (*Crotm)(5,3) = (*Crotv)(1,0) * (*Crotv)(2,1) + (*Crotv)(1,1) * (*Crotv)(2,0); - (*Crotm)(5,4) = (*Crotv)(1,0) * (*Crotv)(2,2) + (*Crotv)(1,2) * (*Crotv)(2,0); - (*Crotm)(5,5) = (*Crotv)(1,1) * (*Crotv)(2,2) + (*Crotv)(2,1) * (*Crotv)(1,2); + (*Crotv)(0, 0) = e1[0]; + (*Crotv)(0, 1) = e1[1]; + (*Crotv)(0, 2) = e1[2]; + + (*Crotv)(1, 0) = e2[0]; + (*Crotv)(1, 1) = e2[1]; + (*Crotv)(1, 2) = e2[2]; + + (*Crotv)(2, 0) = e3[0]; + (*Crotv)(2, 1) = e3[1]; + (*Crotv)(2, 2) = e3[2]; + + (*Crotm)(0, 0) = (*Crotv)(0, 0) * (*Crotv)(0, 0); + (*Crotm)(0, 1) = (*Crotv)(0, 1) * (*Crotv)(0, 1); + (*Crotm)(0, 2) = (*Crotv)(0, 2) * (*Crotv)(0, 2); + (*Crotm)(0, 3) = (*Crotv)(0, 0) * (*Crotv)(0, 1); + (*Crotm)(0, 4) = (*Crotv)(0, 0) * (*Crotv)(0, 2); + (*Crotm)(0, 5) = (*Crotv)(0, 1) * (*Crotv)(0, 2); + + (*Crotm)(1, 0) = (*Crotv)(1, 0) * (*Crotv)(1, 0); + (*Crotm)(1, 1) = (*Crotv)(1, 1) * (*Crotv)(1, 1); + (*Crotm)(1, 2) = (*Crotv)(1, 2) * (*Crotv)(1, 2); + (*Crotm)(1, 3) = (*Crotv)(1, 0) * (*Crotv)(1, 1); + (*Crotm)(1, 4) = (*Crotv)(1, 0) * (*Crotv)(1, 2); + (*Crotm)(1, 5) = (*Crotv)(1, 1) * (*Crotv)(1, 2); + + (*Crotm)(2, 0) = (*Crotv)(2, 0) * (*Crotv)(2, 0); + (*Crotm)(2, 1) = (*Crotv)(2, 1) * (*Crotv)(2, 1); + (*Crotm)(2, 2) = (*Crotv)(2, 2) * (*Crotv)(2, 2); + (*Crotm)(2, 3) = (*Crotv)(2, 0) * (*Crotv)(2, 1); + (*Crotm)(2, 4) = (*Crotv)(2, 0) * (*Crotv)(2, 2); + (*Crotm)(2, 5) = (*Crotv)(2, 1) * (*Crotv)(2, 2); + + (*Crotm)(3, 0) = 2.0 * (*Crotv)(0, 0) * (*Crotv)(1, 0); + (*Crotm)(3, 1) = 2.0 * (*Crotv)(0, 1) * (*Crotv)(1, 1); + (*Crotm)(3, 2) = 2.0 * (*Crotv)(0, 2) * (*Crotv)(1, 2); + (*Crotm)(3, 3) = (*Crotv)(0, 0) * (*Crotv)(1, 1) + (*Crotv)(1, 0) * (*Crotv)(0, 1); + (*Crotm)(3, 4) = (*Crotv)(0, 0) * (*Crotv)(1, 2) + (*Crotv)(0, 2) * (*Crotv)(1, 0); + (*Crotm)(3, 5) = (*Crotv)(0, 1) * (*Crotv)(1, 2) + (*Crotv)(0, 2) * (*Crotv)(1, 1); + + (*Crotm)(4, 0) = 2.0 * (*Crotv)(0, 0) * (*Crotv)(2, 0); + (*Crotm)(4, 1) = 2.0 * (*Crotv)(0, 1) * (*Crotv)(2, 1); + (*Crotm)(4, 2) = 2.0 * (*Crotv)(0, 2) * (*Crotv)(2, 2); + (*Crotm)(4, 3) = (*Crotv)(0, 0) * (*Crotv)(2, 1) + (*Crotv)(0, 1) * (*Crotv)(2, 0); + (*Crotm)(4, 4) = (*Crotv)(0, 0) * (*Crotv)(2, 2) + (*Crotv)(2, 0) * (*Crotv)(0, 2); + (*Crotm)(4, 5) = (*Crotv)(0, 1) * (*Crotv)(2, 2) + (*Crotv)(0, 2) * (*Crotv)(2, 1); + + (*Crotm)(5, 0) = 2.0 * (*Crotv)(1, 0) * (*Crotv)(2, 0); + (*Crotm)(5, 1) = 2.0 * (*Crotv)(1, 1) * (*Crotv)(2, 1); + (*Crotm)(5, 2) = 2.0 * (*Crotv)(1, 2) * (*Crotv)(2, 2); + (*Crotm)(5, 3) = (*Crotv)(1, 0) * (*Crotv)(2, 1) + (*Crotv)(1, 1) * (*Crotv)(2, 0); + (*Crotm)(5, 4) = (*Crotv)(1, 0) * (*Crotv)(2, 2) + (*Crotv)(1, 2) * (*Crotv)(2, 0); + (*Crotm)(5, 5) = (*Crotv)(1, 1) * (*Crotv)(2, 2) + (*Crotv)(2, 1) * (*Crotv)(1, 2); } else { - if(ny > 1.0) + if (ny > 1.0) { e1[0] = cos(0.01745329252 * nx); e1[1] = sin(0.01745329252 * nx); @@ -2014,31 +1999,31 @@ void CSolidProperties::CalculateTransformMatrixFromNormalVector(const int Dimens e1[1] = -nx; } - (*Crotv)(0,0) = e1[0]; - (*Crotv)(0,1) = e1[1]; + (*Crotv)(0, 0) = e1[0]; + (*Crotv)(0, 1) = e1[1]; - (*Crotv)(1,0) = e2[0]; - (*Crotv)(1,1) = e2[1]; + (*Crotv)(1, 0) = e2[0]; + (*Crotv)(1, 1) = e2[1]; - (*Crotm)(0,0) = (*Crotv)(0,0) * (*Crotv)(0,0); - (*Crotm)(0,1) = (*Crotv)(1,0) * (*Crotv)(1,0); - (*Crotm)(0,2) = 0.0; - (*Crotm)(0,3) = -(*Crotv)(0,0) * (*Crotv)(1,0); + (*Crotm)(0, 0) = (*Crotv)(0, 0) * (*Crotv)(0, 0); + (*Crotm)(0, 1) = (*Crotv)(1, 0) * (*Crotv)(1, 0); + (*Crotm)(0, 2) = 0.0; + (*Crotm)(0, 3) = -(*Crotv)(0, 0) * (*Crotv)(1, 0); - (*Crotm)(1,0) = (*Crotv)(0,1) * (*Crotv)(0,1); - (*Crotm)(1,1) = (*Crotv)(1,1) * (*Crotv)(1,1); - (*Crotm)(1,2) = 0.0; - (*Crotm)(1,3) = -(*Crotv)(0,1) * (*Crotv)(1,1); + (*Crotm)(1, 0) = (*Crotv)(0, 1) * (*Crotv)(0, 1); + (*Crotm)(1, 1) = (*Crotv)(1, 1) * (*Crotv)(1, 1); + (*Crotm)(1, 2) = 0.0; + (*Crotm)(1, 3) = -(*Crotv)(0, 1) * (*Crotv)(1, 1); - (*Crotm)(2,0) = 0.0; - (*Crotm)(2,1) = 0.0; - (*Crotm)(2,2) = 1.0; - (*Crotm)(2,3) = 0.0; + (*Crotm)(2, 0) = 0.0; + (*Crotm)(2, 1) = 0.0; + (*Crotm)(2, 2) = 1.0; + (*Crotm)(2, 3) = 0.0; - (*Crotm)(3,0) = -2.0 * (*Crotv)(0,0) * (*Crotv)(0,1); - (*Crotm)(3,1) = -2.0 * (*Crotv)(1,0) * (*Crotv)(1,1); - (*Crotm)(3,2) = 0.0; - (*Crotm)(3,3) = (*Crotv)(0,0) * (*Crotv)(1,1) + (*Crotv)(1,0) * (*Crotv)(0,1); + (*Crotm)(3, 0) = -2.0 * (*Crotv)(0, 0) * (*Crotv)(0, 1); + (*Crotm)(3, 1) = -2.0 * (*Crotv)(1, 0) * (*Crotv)(1, 1); + (*Crotm)(3, 2) = 0.0; + (*Crotm)(3, 3) = (*Crotv)(0, 0) * (*Crotv)(1, 1) + (*Crotv)(1, 0) * (*Crotv)(0, 1); } delete Crotv; Crotv = NULL; @@ -2052,9 +2037,9 @@ double CSolidProperties::GetAngleCoefficent_DP(const double Angle) { double val = 0.0; // Input as a coefficent - if(Angle < 0.0) + if (Angle < 0.0) val = fabs(Angle); - else // Input as a dialatant angle + else // Input as a dialatant angle { double D_Angle = Angle * PI / 180.0; double sinA = sin(D_Angle); @@ -2072,9 +2057,9 @@ double CSolidProperties::GetYieldCoefficent_DP(const double Angle) { double val = 0.0; // Input as a coefficent - if(Angle < 0.0 || Angle < MKleinsteZahl) + if (Angle < 0.0 || Angle < MKleinsteZahl) val = 1.0; - else // Input as a dialatant angle + else // Input as a dialatant angle { double D_Angle = Angle * PI / 180.0; double sinA = sin(D_Angle); @@ -2091,63 +2076,64 @@ void CSolidProperties::CalulateCoefficent_DP() Al = GetAngleCoefficent_DP((*data_Plasticity)(2)); Xi = GetAngleCoefficent_DP((*data_Plasticity)(3)); BetaN = GetYieldCoefficent_DP((*data_Plasticity)(2)); - if(fabs(Al) < MKleinsteZahl && fabs(Xi) < MKleinsteZahl) + if (fabs(Al) < MKleinsteZahl && fabs(Xi) < MKleinsteZahl) BetaN = 1.0; BetaN *= sqrt(2.0 / 3.0); Hard_Loc = (*data_Plasticity)(4); - tension = (*data_Plasticity)(5); //WX: + tension = (*data_Plasticity)(5); // WX: } -void CSolidProperties::CalculateCoefficent_MOHR(double ep, double scalar_comp, double scalar_tens) //WX:11.2010, 09.2011 +void CSolidProperties::CalculateCoefficent_MOHR(double ep, double scalar_comp, double scalar_tens) // WX:11.2010, +// 09.2011 { int valid = 1; double scalar_comp_tmp = scalar_comp; double scalar_tens_tmp = scalar_tens; double theta = (*data_Plasticity)(1) * PI / 180; - double phi = (*data_Plasticity)(2)*PI/180; + double phi = (*data_Plasticity)(2) * PI / 180; Y0 = (*data_Plasticity)(0); tension = (*data_Plasticity)(3); - if((*data_Plasticity)(5) > 0 && (*data_Plasticity)(5) < 100) - theta = GetCurveValue((int)(*data_Plasticity)(5),0,ep,&valid) * PI / 180; - if((*data_Plasticity)(4) > 0 && (*data_Plasticity)(4) < 100) - Y0 = GetCurveValue((int)(*data_Plasticity)(4),0,ep,&valid); + if ((*data_Plasticity)(5) > 0 && (*data_Plasticity)(5) < 100) + theta = GetCurveValue((int)(*data_Plasticity)(5), 0, ep, &valid) * PI / 180; + if ((*data_Plasticity)(4) > 0 && (*data_Plasticity)(4) < 100) + Y0 = GetCurveValue((int)(*data_Plasticity)(4), 0, ep, &valid); - if(Plasticity_Bedding&&((scalar_comp_tmp!=0)||(scalar_tens_tmp!=0))) + if (Plasticity_Bedding && ((scalar_comp_tmp != 0) || (scalar_tens_tmp != 0))) { - //csn=GetCurveValue(bedding_uc_curve,0,scalar_comp_tmp,&valid); - //theta = GetCurveValue(bedding_fric_curve,0,scalar_comp_tmp,&valid)*hPI/180; - //tension=GetCurveValue(bedding_tens_curve,0,scalar_tens_tmp,&valid); + // csn=GetCurveValue(bedding_uc_curve,0,scalar_comp_tmp,&valid); + // theta = GetCurveValue(bedding_fric_curve,0,scalar_comp_tmp,&valid)*hPI/180; + // tension=GetCurveValue(bedding_tens_curve,0,scalar_tens_tmp,&valid); csn = 0; tension = 0; int i; - for(i=0; i Y0 / tan(theta)) - tension = Y0 / tan(theta); + for (i = 0; i < bedding_uc_curve_order + 1; i++) + csn += comp_para[i] * pow(scalar_comp_tmp, i); + for (i = 0; i < bedding_tens_curve_order + 1; i++) + tension += tens_para[i] * pow(scalar_tens_tmp, i); + Ntheta = (1 + sin(theta)) / (1 - sin(theta)); + Nphi = (1 + sin(phi)) / (1 - sin(phi)); + if (tension < 0 || tension > Y0 / tan(theta)) + tension = Y0 / tan(theta); } else { - Ntheta = (1+sin(theta))/(1-sin(theta)); - Nphi = (1+sin(phi))/(1-sin(phi)); - csn = 2* Y0* sqrt(Ntheta); - if(tension<0||tension>Y0/tan(theta)) - tension=Y0/tan(theta); -} + Ntheta = (1 + sin(theta)) / (1 - sin(theta)); + Nphi = (1 + sin(phi)) / (1 - sin(phi)); + csn = 2 * Y0 * sqrt(Ntheta); + if (tension < 0 || tension > Y0 / tan(theta)) + tension = Y0 / tan(theta); + } } -void CSolidProperties::CalculateCoefficent_HOEKBROWN() //WX: 02.2011 +void CSolidProperties::CalculateCoefficent_HOEKBROWN() // WX: 02.2011 { HoekB_a = (*data_Plasticity)(0); HoekB_s = (*data_Plasticity)(1); HoekB_mb = (*data_Plasticity)(2); HoekB_sigci = (*data_Plasticity)(3); HoekB_tens = HoekB_s * HoekB_sigci / HoekB_mb; - HoekB_cohe = HoekB_sigci * pow(HoekB_s,HoekB_a); + HoekB_cohe = HoekB_sigci * pow(HoekB_s, HoekB_a); } /************************************************************************** @@ -2181,14 +2167,13 @@ void CSolidProperties::CalculateCoefficent_HOEKBROWN() //WX: 02.2011 08/2004 WW Set As a member of material class 03/2007 WW Multi-yield surface **************************************************************************/ -bool CSolidProperties::StressIntegrationDP(const int GPiGPj, - const ElementValue_DM* ele_val, double* TryStress, +bool CSolidProperties::StressIntegrationDP(const int GPiGPj, const ElementValue_DM* ele_val, double* TryStress, double& dPhi, const int Update) { int i = 0; double I1 = 0.0; double ep, ep0; - double F = 0.0, F0 = 0.0; //, yl; + double F = 0.0, F0 = 0.0; //, yl; // double RF0 = 0.0; double sqrtJ2 = 0.0; double Beta = 0.0; @@ -2197,20 +2182,20 @@ bool CSolidProperties::StressIntegrationDP(const int GPiGPj, int ite = 0; // double dstrs[6]; - bool isLoop = true; // Used only to avoid warnings with .net + bool isLoop = true; // Used only to avoid warnings with .net bool ploading = false; const int Size = ele_val->Stress->Rows(); - //static double DevStress[6]; + // static double DevStress[6]; int Dim = 2; - if(Size > 4) + if (Size > 4) Dim = 3; // Get the total effective plastic strain ep = (*ele_val->pStrain)(GPiGPj); - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) { // dstrs[i] = TryStress[i]; // d_stress TryStress[i] += (*ele_val->Stress)(i, GPiGPj); @@ -2227,99 +2212,95 @@ bool CSolidProperties::StressIntegrationDP(const int GPiGPj, dPhi = 0.0; F0 = sqrtJ2 + Al * I1; F = F0 - BetaN * (Y0 + Hard * ep); - //if(pcs_deformation==1) F=-1.0; + // if(pcs_deformation==1) F=-1.0; // yl = sqrt(TensorMutiplication2(devS, dstrs, Dim))/sqrtJ2; // yl += (dstrs[0]+dstrs[1]+dstrs[2])*Al; // if(yl<=0.0) // F = -1.0; // - if(F0 <= (*ele_val->y_surface)(GPiGPj)) // unloading + if (F0 <= (*ele_val->y_surface)(GPiGPj)) // unloading F = -1.0; // - if(F > 0.0 && (!PreLoad)) // in yield status + if (F > 0.0 && (!PreLoad)) // in yield status { ploading = true; - //err = 1.0e+5; + // err = 1.0e+5; ep0 = ep; - //TEST + // TEST // Check the corner region - err_corner = 4.5 * Xi * K * normXi / G + BetaN * - (0.5 * Hard * - sqrt(1.0 + 3.0 * Xi * Xi) * normXi / G + Y0 + Hard * ep ) / Al; + err_corner = 4.5 * Xi * K * normXi / G + + BetaN * (0.5 * Hard * sqrt(1.0 + 3.0 * Xi * Xi) * normXi / G + Y0 + Hard * ep) / Al; // Multi-surface - if(p3 > err_corner) + if (p3 > err_corner) { // RF0 = F; dl2 = 0.0; - while(isLoop) + while (isLoop) { ite++; // dl1 dPhi = 0.5 * normXi / G; fac = sqrt(dPhi * dPhi + 3.0 * Xi * Xi * (dPhi + dl2) * (dPhi + dl2)); - Jac = 9.0 * Xi * K + 3.0 * Xi * Xi * BetaN * Hard * - (dPhi + dl2) / (fac * Al); - F = 9.0 * Xi * K * - (dPhi + dl2) + BetaN * (Y0 + Hard * (ep0 + fac)) / Al - p3; + Jac = 9.0 * Xi * K + 3.0 * Xi * Xi * BetaN * Hard * (dPhi + dl2) / (fac * Al); + F = 9.0 * Xi * K * (dPhi + dl2) + BetaN * (Y0 + Hard * (ep0 + fac)) / Al - p3; dl2 -= F / Jac; - if(fabs(F) < 1000.0 * Tolerance_Local_Newton) + if (fabs(F) < 1000.0 * Tolerance_Local_Newton) break; - if(ite > max_ite) + if (ite > max_ite) break; } ep = ep0 + fac; - for(i = 0; i < 3; i++) - TryStress[i] = I1 / 3.0 - 3.0 * (dPhi + dl2) * K * Xi; - for(i = 3; i < Size; i++) + for (i = 0; i < 3; i++) + TryStress[i] = I1 / 3.0 - 3.0 * (dPhi + dl2) * K * Xi; + for (i = 3; i < Size; i++) TryStress[4] = 0.0; } else { // Local Newton-Raphson procedure // If non-perfect plasticity, the below line has to be change - Jac = -2.0 * G - 9.0 * K * Al * Xi - - BetaN* Hard* sqrt(1.0 + 3.0 * Xi * Xi); + Jac = -2.0 * G - 9.0 * K * Al * Xi - BetaN * Hard * sqrt(1.0 + 3.0 * Xi * Xi); // RF0 = F; - while(isLoop) + while (isLoop) { ite++; - if(ite > max_ite) + if (ite > max_ite) break; - if(F < 0.0 || fabs(F) < 10.0 * Tolerance_Local_Newton) + if (F < 0.0 || fabs(F) < 10.0 * Tolerance_Local_Newton) break; - //if(err 0) + if (Update > 0) { - if(dPhi > 0.0) + if (dPhi > 0.0) (*ele_val->pStrain)(GPiGPj) = ep; (*ele_val->y_surface)(GPiGPj) = F0; } @@ -2360,26 +2341,26 @@ bool CSolidProperties::DirectStressIntegrationDP(const int GPiGPj, int i = 0, m = 0, m_max = 100; double I1 = 0.0; double sy0, sy, ep, dlambda = 0.0; - double F = 0.0, yy; //, yl; + double F = 0.0, yy; //, yl; double R = 1.0; double sqrtJ2 = 0.0; double A_H = 0.0, domA = 0.0; double dstrs[6]; bool ploading = false; const int Size = ele_val->Stress->Rows(); - //static double DevStress[6]; + // static double DevStress[6]; int Dim = 2; - if(Size > 4) + if (Size > 4) Dim = 3; // Get the total effective plastic strain ep = (*ele_val->pStrain)(GPiGPj); - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) { - dstrs[i] = TryStress[i]; // d_stress - // stress_0 + dstrs[i] = TryStress[i]; // d_stress + // stress_0 TryStress[i] = (*ele_val->Stress)(i, GPiGPj); devS[i] = TryStress[i] + dstrs[i]; } @@ -2391,67 +2372,67 @@ bool CSolidProperties::DirectStressIntegrationDP(const int GPiGPj, yy = BetaN * (Y0 + Hard * ep); F = sy - yy; sy0 = (*ele_val->y_surface)(GPiGPj); - //yl = sqrt(TensorMutiplication2(devS, dstrs, Dim))/sqrtJ2; - //yl += (dstrs[0]+dstrs[1]+dstrs[2])*Al; - //if(yl<=0.0) + // yl = sqrt(TensorMutiplication2(devS, dstrs, Dim))/sqrtJ2; + // yl += (dstrs[0]+dstrs[1]+dstrs[2])*Al; + // if(yl<=0.0) // F = -1.0; - if(sy <= sy0) // unloading + if (sy <= sy0) // unloading F = -1.0; - if(F > 0.0 && (!PreLoad)) // in yield status + if (F > 0.0 && (!PreLoad)) // in yield status { - if(ep < MKleinsteZahl) // Elastic in previous load step + if (ep < MKleinsteZahl) // Elastic in previous load step R = F / (sy - sy0); m = (int)(8.0 * F / yy) + 1; - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) { TryStress[i] += (1.0 - R) * dstrs[i]; dstrs[i] *= R / (double)m; } - if(m > m_max) + if (m > m_max) m = m_max; // sub-inrement - while(m > 0) + while (m > 0) { // Compute dlamda A_H = BetaN * Hard * sqrt(1 + 3.0 * Xi * Xi); // Hard: if it is not constant.... - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) devS[i] = TryStress[i]; I1 = DeviatoricStress(devS); sqrtJ2 = sqrt(TensorMutiplication2(devS, devS, Dim)); - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) { devS[i] /= sqrtJ2; dFds[i] = devS[i]; } - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) dFds[i] += Al; // dlambda dlambda = 0.0; domA = A_H + 2.0 * G + 9.0 * Al * Xi * K; - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) dlambda += dFds[i] * dstrs[i]; dlambda /= domA; - if(dlambda < 0.0) + if (dlambda < 0.0) dlambda = 0.0; ep += dlambda * sqrt(1.0 + 3.0 * Xi * Xi); // Update stress - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) TryStress[i] += dstrs[i] - 2.0 * dlambda * G * devS[i]; dlambda *= 3.0 * Xi * K; - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) TryStress[i] -= dlambda; m--; } - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) devS[i] = TryStress[i]; I1 = DeviatoricStress(devS); sqrtJ2 = sqrt(TensorMutiplication2(devS, devS, Dim)); sy = sqrtJ2 + Al * I1; yy = BetaN * (Y0 + Hard * ep); R = 1.0; - if(sy > yy) + if (sy > yy) R = yy / sy; - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) { TryStress[i] *= R; devS[i] *= R / sqrtJ2; @@ -2460,10 +2441,10 @@ bool CSolidProperties::DirectStressIntegrationDP(const int GPiGPj, ploading = true; } else - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) TryStress[i] += dstrs[i]; // Save the current stresses - if(Update > 0) + if (Update > 0) { (*ele_val->pStrain)(GPiGPj) = ep; (*ele_val->y_surface)(GPiGPj) = sy; @@ -2471,40 +2452,36 @@ bool CSolidProperties::DirectStressIntegrationDP(const int GPiGPj, return ploading; } -//WX -int CSolidProperties::DirectStressIntegrationDPwithTension(const int GPiGPj, - Matrix* De, - const ElementValue_DM* ele_val, - double* TryStress, - const int Update, - double &mm) +// WX +int CSolidProperties::DirectStressIntegrationDPwithTension(const int GPiGPj, Matrix* De, const ElementValue_DM* ele_val, + double* TryStress, const int Update, double& mm) { int i = 0, j = 0; //, m=0, m_max=100; double I1 = 0.0; - //WW double sy0, - //WW double sy, ep, dlambda=0.0, tmpvalue=0., tmpvalue2=0., sqrtJ2I1; //dTaun, dSign, - double sy, ep, tmpvalue = 0., sqrtJ2I1; //dTaun, dSign, + // WW double sy0, + // WW double sy, ep, dlambda=0.0, tmpvalue=0., tmpvalue2=0., sqrtJ2I1; //dTaun, dSign, + double sy, ep, tmpvalue = 0., sqrtJ2I1; // dTaun, dSign, double F = 0.0, Ft = 0, yy; //, yl; Ft: tension failure WX: 11.08.2010 - //WW double R=1.0; + // WW double R=1.0; double sqrtJ2 = 0.0; - //WW double A_H = 0.0, domA=0.0; + // WW double A_H = 0.0, domA=0.0; double dstrs[6]; double dTempStr[6] = {0.}, dTempStr2[6] = {0.}, TmpStress0[6] = {0}, dStrainP[6] = {0.}; - //WW bool ploading = false; + // WW bool ploading = false; const int Size = ele_val->Stress->Rows(); - //WW double H=0; // + // WW double H=0; // int failurestate = 0; - //static double DevStress[6]; + // static double DevStress[6]; int Dim = 2; - if(Size > 4) + if (Size > 4) Dim = 3; // Get the total effective plastic strain ep = (*ele_val->pStrain)(GPiGPj); - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) { dstrs[i] = TryStress[i]; // d_stress TryStress[i] = (*ele_val->Stress)(i, GPiGPj); // stress_0 @@ -2514,38 +2491,38 @@ int CSolidProperties::DirectStressIntegrationDPwithTension(const int GPiGPj, I1 = DeviatoricStress(devS); sqrtJ2 = sqrt(TensorMutiplication2(devS, devS, Dim)); - Hard = 0; //WX:20.09.2010. no hardning in this model + Hard = 0; // WX:20.09.2010. no hardning in this model // sy = sqrtJ2 + Al * I1; yy = BetaN * (Y0 + Hard * ep); sqrtJ2I1 = yy - Al * 3 * tension; - if(tension < 0) + if (tension < 0) tension = 0; - if(tension > (yy / Al / 3.0)) - tension = yy / Al / 3.0; //WX: tension strength must be positiv and has a max limit. + if (tension > (yy / Al / 3.0)) + tension = yy / Al / 3.0; // WX: tension strength must be positiv and has a max limit. F = sy - yy; - Ft = I1 / 3 - tension; //WX: 11.08.2010 tension strength. - //WW double Tau_P = (BetaN*Y0 - 3*Al*tension)/sqrt(2.0); - //WW double Al_P = sqrt(1+4.5*Al*Al) - (3 * Al / (sqrt(2.0))); - //WW H = sqrtJ2/sqrt(2.0) - Tau_P - (Al_P * (I1/3. - tension)); //WX:16.09.2010.correct H. - //WW sy0 = (*ele_val->y_surface)(GPiGPj); + Ft = I1 / 3 - tension; // WX: 11.08.2010 tension strength. + // WW double Tau_P = (BetaN*Y0 - 3*Al*tension)/sqrt(2.0); + // WW double Al_P = sqrt(1+4.5*Al*Al) - (3 * Al / (sqrt(2.0))); + // WW H = sqrtJ2/sqrt(2.0) - Tau_P - (Al_P * (I1/3. - tension)); //WX:16.09.2010.correct H. + // WW sy0 = (*ele_val->y_surface)(GPiGPj); - if(tmpvalue == 0) + if (tmpvalue == 0) Ft = F = -1; - if(F > 0.0 && (!PreLoad)) + if (F > 0.0 && (!PreLoad)) { - //return to Fs - Matrix* tmpMatrix = new Matrix(Size,Size); - for(i = 0; i < Size; i++) + // return to Fs + Matrix* tmpMatrix = new Matrix(Size, Size); + for (i = 0; i < Size; i++) { - D_dGds[i] = 0.0; //initialisation + D_dGds[i] = 0.0; // initialisation dFds[i] = devS[i] / (sqrtJ2 * sqrt(2.0)); dGds[i] = dFds[i]; - if(i < 3) + if (i < 3) { dFds[i] += Al / sqrt(2.0); dGds[i] += Xi / sqrt(2.0); @@ -2554,82 +2531,75 @@ int CSolidProperties::DirectStressIntegrationDPwithTension(const int GPiGPj, De->multi(dGds, D_dGds); tmpvalue = 0.; - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) tmpvalue += dFds[i] * D_dGds[i]; - for(i = 0; i < Size; i++) - for(j = 0; j < Size; j++) - (*tmpMatrix)(i,j) = D_dGds[i] * dFds[j]; + for (i = 0; i < Size; i++) + for (j = 0; j < Size; j++) + (*tmpMatrix)(i, j) = D_dGds[i] * dFds[j]; - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) { - if(i < 3) + if (i < 3) dTempStr2[i] = TryStress[i] + dstrs[i] - yy / Al / 3.0; else dTempStr2[i] = TryStress[i] + dstrs[i]; } tmpMatrix->multi(dTempStr2, dTempStr); - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) { dTempStr[i] /= tmpvalue; TryStress[i] += dstrs[i] - dTempStr[i]; } tmpvalue = (TryStress[0] + TryStress[1] + TryStress[2]) / 3.0; - if((tmpvalue - tension) < MKleinsteZahl) + if ((tmpvalue - tension) < MKleinsteZahl) { - failurestate = 1; //shear + failurestate = 1; // shear delete tmpMatrix; } else { - //return to Ft - for(i = 0; i < Size; i++) + // return to Ft + for (i = 0; i < Size; i++) { dFtds[i] = dGtds[i] = 1.0 / 3.0; - if(i > 2) + if (i > 2) dFtds[i] = dGtds[i] = 0.0; } - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) TryStress[i] = (*ele_val->Stress)(i, GPiGPj) + dstrs[i]; I1 = TryStress[0] + TryStress[1] + TryStress[2]; dTempStr[0] = dTempStr[1] = dTempStr[2] = I1 / 3.0 - tension; - for(i = 3; i < Size; i++) + for (i = 3; i < Size; i++) dTempStr[i] = 0.0; - for(i = 0; i < Size; i++) - TryStress[i] = - (*ele_val->Stress)(i, GPiGPj) + dstrs[i] - dTempStr[i]; + for (i = 0; i < Size; i++) + TryStress[i] = (*ele_val->Stress)(i, GPiGPj) + dstrs[i] - dTempStr[i]; - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) devS[i] = TryStress[i]; I1 = DeviatoricStress(devS); sqrtJ2 = sqrt(TensorMutiplication2(devS, devS, Dim)); - if(sqrtJ2 <= sqrtJ2I1) + if (sqrtJ2 <= sqrtJ2I1) { - if((dstrs[0] + dstrs[1] + dstrs[2]) != 0.0) - mm = - (3 * tension - - ((*ele_val->Stress)(0, - GPiGPj) + - (*ele_val->Stress)(1, - GPiGPj) + - (*ele_val->Stress)(2, - GPiGPj))) / - (dstrs[0] + dstrs[1] + dstrs[2]); + if ((dstrs[0] + dstrs[1] + dstrs[2]) != 0.0) + mm = (3 * tension - ((*ele_val->Stress)(0, GPiGPj) + (*ele_val->Stress)(1, GPiGPj) + + (*ele_val->Stress)(2, GPiGPj))) + / (dstrs[0] + dstrs[1] + dstrs[2]); else mm = 1.; - //mm: Ft(stress0 + mm*dstrs)=0 for Dep calculation - failurestate = 2; //tensile failure + // mm: Ft(stress0 + mm*dstrs)=0 for Dep calculation + failurestate = 2; // tensile failure } else { - //return to corner between Fs and Ft + // return to corner between Fs and Ft double A, B, C; - Matrix* tmpMatrix = new Matrix(Size,Size); - for(i = 0; i < Size; i++) //initialize stress devstress + Matrix* tmpMatrix = new Matrix(Size, Size); + for (i = 0; i < Size; i++) // initialize stress devstress { TryStress[i] = (*ele_val->Stress)(i, GPiGPj); devS[i] = TryStress[i] + dstrs[i]; @@ -2639,12 +2609,12 @@ int CSolidProperties::DirectStressIntegrationDPwithTension(const int GPiGPj, I1 = DeviatoricStress(devS); - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) { - D_dGds[i] = 0.0; //initialization + D_dGds[i] = 0.0; // initialization dFds[i] = devS[i] / (sqrtJ2 * sqrt(2.0)); dGds[i] = dFds[i]; - if(i < 3) + if (i < 3) { dFds[i] += Al / sqrt(2.0); dGds[i] += Xi / sqrt(2.0); @@ -2653,24 +2623,23 @@ int CSolidProperties::DirectStressIntegrationDPwithTension(const int GPiGPj, De->multi(dGds, D_dGds); tmpvalue = 0.; - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) tmpvalue += dFds[i] * D_dGds[i]; - for(i = 0; i < Size; i++) - for(j = 0; j < Size; j++) - (*tmpMatrix)(i,j) = D_dGds[i] * dFds[j]; + for (i = 0; i < Size; i++) + for (j = 0; j < Size; j++) + (*tmpMatrix)(i, j) = D_dGds[i] * dFds[j]; - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) { dTempStr[i] = 0.0; - if(i < 3) - dTempStr2[i] = TryStress[i] + dstrs[i] - yy / Al / - 3.0; + if (i < 3) + dTempStr2[i] = TryStress[i] + dstrs[i] - yy / Al / 3.0; else dTempStr2[i] = TryStress[i] + dstrs[i]; } tmpMatrix->multi(dTempStr2, dTempStr); - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) { dTempStr[i] /= tmpvalue; TryStress[i] += dstrs[i]; @@ -2683,104 +2652,103 @@ int CSolidProperties::DirectStressIntegrationDPwithTension(const int GPiGPj, dI1 = DeviatoricStress(dTempStr); A = 0.; - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) { - if(i < 3) + if (i < 3) A += dTempStr[i] * dTempStr[i]; else A += 2 * dTempStr[i] * dTempStr[i]; } B = 0.; - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) { - if(i < 3) + if (i < 3) B += -2 * TryStress[i] * dTempStr[i]; else B += -4 * TryStress[i] * dTempStr[i]; } C = 0.; - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) { - if(i < 3) + if (i < 3) C += TryStress[i] * TryStress[i]; else C += 2 * TryStress[i] * TryStress[i]; } C -= sqrtJ2I1 * sqrtJ2I1; - if((B * B - 4 * A * C) < 0.0 || (A == 0)) + if ((B * B - 4 * A * C) < 0.0 || (A == 0)) tmpvalue = 1.0; else { tmpvalue = (-B - sqrt(B * B - 4 * A * C)) / (2 * A); - if(tmpvalue < 0) + if (tmpvalue < 0) { tmpvalue = (-B + sqrt(B * B - 4 * A * C)) / (2 * A); - if(tmpvalue > 1) + if (tmpvalue > 1) tmpvalue = 1; } } double tmpStr[6] = {0.}; - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) { - if(i < 3) - tmpStr[i] = - (TryStress[i] + I1 / - 3.0) - tmpvalue * (dTempStr[i] + dI1 / 3.0); + if (i < 3) + tmpStr[i] = (TryStress[i] + I1 / 3.0) - tmpvalue * (dTempStr[i] + dI1 / 3.0); else tmpStr[i] = TryStress[i] - tmpvalue * dTempStr[i]; } double tmpI1 = 0.; tmpI1 = DeviatoricStress(tmpStr); - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) { - if(i < 3) + if (i < 3) TryStress[i] = tmpStr[i] + tension; else TryStress[i] = tmpStr[i]; - //test - //cout<Stress)(i, GPiGPj); dTempStr[i] = dstrs[i]; - dTempStr2[i] = TmpStress0[i] + dstrs[i]; //stress0+dstrs + dTempStr2[i] = TmpStress0[i] + dstrs[i]; // stress0+dstrs // cout< 3 * tension) - n1 = (tmpI1 - 3 * tension) / (dI2 - 3 * tension); //n1 = (I1(sigtmp)-I1(tension))/ (I1(SigB)-I1(tension)) + if (tmpI1 > 3 * tension) + n1 = (tmpI1 - 3 * tension) + / (dI2 - 3 * tension); // n1 = (I1(sigtmp)-I1(tension))/ (I1(SigB)-I1(tension)) else n1 = 0; - if(dI1 != 0.0) + if (dI1 != 0.0) { n2 = (3 * tension - I1) / dI1; - if(n2 < 0) + if (n2 < 0) n2 = 0.; } else n2 = 1.; A = 0.; - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) { - if(i < 3) + if (i < 3) A -= dTempStr[i] * dTempStr[i]; else A -= 2 * dTempStr[i] * dTempStr[i]; @@ -2788,9 +2756,9 @@ int CSolidProperties::DirectStressIntegrationDPwithTension(const int GPiGPj, A += (Al * dI1) * (Al * dI1); B = 0.; - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) { - if(i < 3) + if (i < 3) B -= 2 * TmpStress0[i] * dTempStr[i]; else B -= 4 * TmpStress0[i] * dTempStr[i]; @@ -2798,64 +2766,55 @@ int CSolidProperties::DirectStressIntegrationDPwithTension(const int GPiGPj, B += 2 * (Al * I1 - yy) * Al * dI1; C = 0.; - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) { - if(i < 3) + if (i < 3) C -= TmpStress0[i] * TmpStress0[i]; else C -= 2 * TmpStress0[i] * TmpStress0[i]; } C += (Al * I1 - yy) * (Al * I1 - yy); - if(((B * B - 4 * A * C) < 0) || (A == 0)) + if (((B * B - 4 * A * C) < 0) || (A == 0)) m2 = 1; else { m2 = (-B - sqrt(B * B - 4 * A * C)) / (2 * A); - if(m2 < 0) + if (m2 < 0) { - m2 = - (-B + - sqrt(B * B - 4 * A * C)) / (2 * A); - if(m2 > 1) + m2 = (-B + sqrt(B * B - 4 * A * C)) / (2 * A); + if (m2 > 1) m2 = 0; } } - Matrix* Dp_shear = new Matrix (Size,Size); - Matrix* Dp_tension = new Matrix (Size,Size); - Matrix* M_ds = new Matrix (Size,Size); //dGsds*dFsdsT + Matrix* Dp_shear = new Matrix(Size, Size); + Matrix* Dp_tension = new Matrix(Size, Size); + Matrix* M_ds = new Matrix(Size, Size); // dGsds*dFsdsT - tmpvalue = 0.; //dFsdsT*De*dGsds - //WW tmpvalue2 =0.; //dFtdsT*De*dGtds + tmpvalue = 0.; // dFsdsT*De*dGsds + // WW tmpvalue2 =0.; //dFtdsT*De*dGtds - for(i = 0; i < 3; i++) - for(j = 0; j < 3; j++) - (*Dp_tension)(i,j) = K; + for (i = 0; i < 3; i++) + for (j = 0; j < 3; j++) + (*Dp_tension)(i, j) = K; - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) tmpvalue += dFds[i] * D_dGds[i]; - for(i = 0; i < Size; i++) - for(j = 0; j < Size; j++) - (*M_ds)(i,j) = dGds[i] * dFds[j]; + for (i = 0; i < Size; i++) + for (j = 0; j < Size; j++) + (*M_ds)(i, j) = dGds[i] * dFds[j]; De->multi(*M_ds, *De, *Dp_shear); *Dp_shear /= tmpvalue; - ConstitutiveMatrix->resize(Size,Size); + ConstitutiveMatrix->resize(Size, Size); - for(i = 0; i < Size; i++) - for(j = 0; j < Size; j++) - (*ConstitutiveMatrix)(i, - j) = - (*De)(i, - j) - - (1 - - m2) * m1 * - (*Dp_shear)(i, - j) - - (1 - n2) * n1 * (*Dp_tension)(i,j); + for (i = 0; i < Size; i++) + for (j = 0; j < Size; j++) + (*ConstitutiveMatrix)(i, j) + = (*De)(i, j) - (1 - m2) * m1 * (*Dp_shear)(i, j) - (1 - n2) * n1 * (*Dp_tension)(i, j); delete Dp_shear; delete Dp_tension; @@ -2866,69 +2825,65 @@ int CSolidProperties::DirectStressIntegrationDPwithTension(const int GPiGPj, } } } - else if(Ft > 0) //muss be tensile + else if (Ft > 0) // muss be tensile { - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) { dFtds[i] = dGtds[i] = 1.0 / 3.0; - if(i > 2) + if (i > 2) dFtds[i] = dGtds[i] = 0.0; } - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) TryStress[i] = (*ele_val->Stress)(i, GPiGPj) + dstrs[i]; I1 = TryStress[0] + TryStress[1] + TryStress[2]; dTempStr[0] = dTempStr[1] = dTempStr[2] = I1 / 3.0 - tension; - for(i = 3; i < Size; i++) + for (i = 3; i < Size; i++) dTempStr[i] = 0.0; - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) TryStress[i] -= dTempStr[i]; - if((dstrs[0] + dstrs[1] + dstrs[2]) != 0.0) - mm = - (3 * tension - - ((*ele_val->Stress)(0, - GPiGPj) + - (*ele_val->Stress)(1, - GPiGPj) + - (*ele_val->Stress)(2, GPiGPj))) / (dstrs[0] + dstrs[1] + dstrs[2]); + if ((dstrs[0] + dstrs[1] + dstrs[2]) != 0.0) + mm = (3 * tension + - ((*ele_val->Stress)(0, GPiGPj) + (*ele_val->Stress)(1, GPiGPj) + (*ele_val->Stress)(2, GPiGPj))) + / (dstrs[0] + dstrs[1] + dstrs[2]); else mm = 1.; - failurestate = 2; //tensile failure + failurestate = 2; // tensile failure } - if(F <= 0 && Ft <= 0) + if (F <= 0 && Ft <= 0) { - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) TryStress[i] += dstrs[i]; failurestate = 0; } - //update ep - if(failurestate != 0) + // update ep + if (failurestate != 0) { - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) { - dTempStr[i] = (*ele_val->Stress)(i, GPiGPj) + dstrs[i] - TryStress[i]; //d plas stress + dTempStr[i] = (*ele_val->Stress)(i, GPiGPj) + dstrs[i] - TryStress[i]; // d plas stress dStrainP[i] = 0.; } - Matrix* invDe = new Matrix (Size,Size); + Matrix* invDe = new Matrix(Size, Size); Cal_Inv_Matrix(Size, De, invDe); - invDe->multi(dTempStr,dStrainP); + invDe->multi(dTempStr, dStrainP); - ep += sqrt(TensorMutiplication2(dStrainP,dStrainP,Dim)) * sqrt(2.0 / 3.0); + ep += sqrt(TensorMutiplication2(dStrainP, dStrainP, Dim)) * sqrt(2.0 / 3.0); delete invDe; } // Save the current stresses - if(Update > 0) + if (Update > 0) { (*ele_val->pStrain)(GPiGPj) = ep; (*ele_val->y_surface)(GPiGPj) = sy; } - //return ploading; + // return ploading; return failurestate; } @@ -2955,12 +2910,12 @@ void CSolidProperties::TangentialDP(Matrix* Dep) Size = Dep->Rows(); domA = BetaN * Hard * sqrt(1 + 3.0 * Xi * Xi); // Hard: if it is not constant.... // - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) { D_dFds[i] = 2.0 * G * devS[i]; D_dGds[i] = 2.0 * G * devS[i]; } - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) { D_dFds[i] += 3.0 * Al * K; D_dGds[i] += 3.0 * Xi * K; @@ -2968,14 +2923,14 @@ void CSolidProperties::TangentialDP(Matrix* Dep) // domA += 2.0 * G + 9.0 * Al * Xi * K; // - for(i = 0; i < Size; i++) - for(j = 0; j < Size; j++) - (*Dep)(i,j) -= D_dGds[i] * D_dFds[j] / domA; + for (i = 0; i < Size; i++) + for (j = 0; j < Size; j++) + (*Dep)(i, j) -= D_dGds[i] * D_dFds[j] / domA; - //Dep->Write(); + // Dep->Write(); } -//WX: return to shear +// WX: return to shear void CSolidProperties::TangentialDP2(Matrix* Dep) { int i, j, Size; @@ -2993,12 +2948,12 @@ void CSolidProperties::TangentialDP2(Matrix* Dep) Dim = 3; sqrtJ2 = sqrt(TensorMutiplication2(devS, devS, Dim)); - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) { D_dFds[i] = 0.5 * devS[i] / sqrtJ2; D_dGds[i] = 0.5 * devS[i] / sqrtJ2; } - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) { D_dFds[i] += Al; D_dGds[i] += Xi; @@ -3008,19 +2963,19 @@ void CSolidProperties::TangentialDP2(Matrix* Dep) for (i = 0; i < Size; i++) dTemp2 += D_dFds[i] * dTempStr2[i]; - for(i = 0; i < Size; i++) - for(j = 0; j < Size; j++) - D_temp(i,j) = D_dGds[i] * D_dFds[j]; + for (i = 0; i < Size; i++) + for (j = 0; j < Size; j++) + D_temp(i, j) = D_dGds[i] * D_dFds[j]; Dep->multi(D_temp, *Dep, D_temp2); // - for(i = 0; i < Size; i++) - for(j = 0; j < Size; j++) - (*Dep)(i,j) -= D_temp2(i,j) / dTemp2; + for (i = 0; i < Size; i++) + for (j = 0; j < Size; j++) + (*Dep)(i, j) -= D_temp2(i, j) / dTemp2; } -//WX: return to tension +// WX: return to tension void CSolidProperties::TangentialDPwithTension(Matrix* Dep, double mm) { int i, j, Size; @@ -3028,12 +2983,12 @@ void CSolidProperties::TangentialDPwithTension(Matrix* Dep, double mm) Size = Dep->Rows(); // double dTemp2 = 0; // double dTempStr3[6] = {0}; - Matrix* D_temp = new Matrix (Size, Size); - for(i = 0; i < 3; i++) - for(j = 0; j < 3; j++) - (*D_temp)(i,j) = K; - //Matrix D_temp2(Size, Size); - //mm=0.; + Matrix* D_temp = new Matrix(Size, Size); + for (i = 0; i < 3; i++) + for (j = 0; j < 3; j++) + (*D_temp)(i, j) = K; + // Matrix D_temp2(Size, Size); + // mm=0.; /* Dep->multi(dGtds, dTempStr3); // dTemp = De * dGt/ds @@ -3051,38 +3006,38 @@ void CSolidProperties::TangentialDPwithTension(Matrix* Dep, double mm) for (i = 0; i < Size; i++) for (j = 0; j < Size; j++) - (*Dep)(i,j) = mm * (*Dep)(i,j) + (1 - mm) * ((*Dep)(i,j) - (*D_temp)(i,j)); + (*Dep)(i, j) = mm * (*Dep)(i, j) + (1 - mm) * ((*Dep)(i, j) - (*D_temp)(i, j)); delete D_temp; } -//WX: return to corner +// WX: return to corner void CSolidProperties::TangentialDPwithTensionCorner(Matrix* Dep, double /*mm*/) { - //return to corner + // return to corner *Dep = *ConstitutiveMatrix; - //Dep->Write(); + // Dep->Write(); } /******************************************************* WX: Mohr coulomb, directe stress integration, also for aniso. *******************************************************/ -int CSolidProperties::StressIntegrationMOHR_Aniso(const int GPiGPj, const ElementValue_DM *ele_val, - double* TryStress, const int Update, Matrix* Dep ) +int CSolidProperties::StressIntegrationMOHR_Aniso(const int GPiGPj, const ElementValue_DM* ele_val, double* TryStress, + const int Update, Matrix* Dep) { int i, j, counter; int yield = 0; int Dim = 2; int Size = std::min(std::size_t(6ul), ele_val->Stress->Rows()); - double normdstr=0., TmpValue1, TmpValue2; + double normdstr = 0., TmpValue1, TmpValue2; double LodeAngle, I1, J2, J3, sqrtJ2; double AnisoParaComp, AnisoParaTens = 0.0; double shearsurf, tensionsurf, ep, dlamda = 0.0 /*, dlamda_0, dlamda_1*/; //, ddlamda, Jacob; - //initialize all vectors - double dstrs[6] = {0.}, TryStress_0[6]={0.}, TryStr_buff[6] ={0.}, TmpStress[6] = {0.}; + // initialize all vectors + double dstrs[6] = {0.}, TryStress_0[6] = {0.}, TryStr_buff[6] = {0.}, TmpStress[6] = {0.}; double tmp_prin_str[6] = {0.}, tmp_prin_dir[9] = {0.}, TmpPrinStrComp[6] = {0.}, TmpPrinStrTens[6] = {0.}; - double TmpStrComp[6]={0.}, TmpStrTens[6]={0.}, devStr[6]={0.}, dstrainP[6]={0.}, dstressP[6]={0.}; + double TmpStrComp[6] = {0.}, TmpStrTens[6] = {0.}, devStr[6] = {0.}, dstrainP[6] = {0.}, dstressP[6] = {0.}; double sqrt3 = sqrt(3.0); bool lode_out_range = false; double TryStress_local[6]={0,}, dstrs_local[6]={0.}; @@ -3095,59 +3050,60 @@ int CSolidProperties::StressIntegrationMOHR_Aniso(const int GPiGPj, const Elemen *TmpDe = *Dep; - //ConstitutiveMatrix->resize(Size,Size); //in head already defined, and is used for later as global variable + // ConstitutiveMatrix->resize(Size,Size); //in head already defined, and is used for later as global variable *ConstitutiveMatrix = (0.); - ep = (*ele_val->pStrain)(GPiGPj); //get eff plas strain + ep = (*ele_val->pStrain)(GPiGPj); // get eff plas strain - if(Size>4) Dim = 3; + if (Size > 4) + Dim = 3; - for(i=0; iStress)(i, GPiGPj); // stress_0 TryStr_buff[i] = TryStress[i] + dstrs[i]; - TryStress_0[i]=TryStr_buff[i]; + TryStress_0[i] = TryStr_buff[i]; normdstr += fabs(dstrs[i]); } if (normdstr < MKleinsteZahl) return 0; - //if(Size==4) + // if(Size==4) // devStr[4]=devStr[5]=0.; if (!Plasticity_Bedding) { CalculateCoefficent_MOHR(ep, 0, 0); - for(i=0;imulti(TryStr_buff,TmpStress); + TransMicroStru_TInv->multi(TryStr_buff, TmpStress); TransMicroStru_TInv->multi(dstrs, dstrs_local); TransMicroStru_TInv->multi(TryStress, TryStress_local); - for(i=0; iGetTranspose(*TmpMatrix2); - for(i=0; imulti(TmpPrinStrComp,TmpStrComp); - TmpMatrix2->multi(TmpPrinStrTens,TmpStrTens); - AnisoParaComp = CalAnisoPara(TmpStrComp,MicroStruTensor); - AnisoParaTens = CalAnisoPara(TmpStrTens,MicroStruTensor); + TmpMatrix2->multi(TmpPrinStrComp, TmpStrComp); + TmpMatrix2->multi(TmpPrinStrTens, TmpStrTens); + AnisoParaComp = CalAnisoPara(TmpStrComp, MicroStruTensor); + AnisoParaTens = CalAnisoPara(TmpStrTens, MicroStruTensor); CalculateCoefficent_MOHR(ep, AnisoParaComp, AnisoParaTens); } - double Kronecker[6]={1,1,1,0,0,0}; + double Kronecker[6] = {1, 1, 1, 0, 0, 0}; - I1 = TmpStress[0]+TmpStress[1]+TmpStress[2]; - for (i=0;i1-1e-6) + if ((-3 * sqrt3 / 2. * J3 / pow(sqrtJ2, 3)) > 1 - 1e-6) { - LodeAngle = PI/6.; + LodeAngle = PI / 6.; lode_out_range = true; } - else if ((-3*sqrt3/2.*J3/pow(sqrtJ2,3))<-1+1e-6) + else if ((-3 * sqrt3 / 2. * J3 / pow(sqrtJ2, 3)) < -1 + 1e-6) { - LodeAngle = -PI/6.; + LodeAngle = -PI / 6.; lode_out_range = true; } else { - LodeAngle = asin(-3*sqrt3/2.*J3/pow(sqrtJ2,3))/3.; + LodeAngle = asin(-3 * sqrt3 / 2. * J3 / pow(sqrtJ2, 3)) / 3.; lode_out_range = false; } } - shearsurf=Ntheta*(I1/3.+2/sqrt3*sqrtJ2*sin(LodeAngle+2/3.*PI)) - -(I1/3.+2/sqrt3*sqrtJ2*sin(LodeAngle-2/3.*PI))-csn; - tensionsurf=(I1/3.+2/sqrt3*sqrtJ2*sin(LodeAngle+2/3.*PI))-tension; + shearsurf = Ntheta * (I1 / 3. + 2 / sqrt3 * sqrtJ2 * sin(LodeAngle + 2 / 3. * PI)) + - (I1 / 3. + 2 / sqrt3 * sqrtJ2 * sin(LodeAngle - 2 / 3. * PI)) - csn; + tensionsurf = (I1 / 3. + 2 / sqrt3 * sqrtJ2 * sin(LodeAngle + 2 / 3. * PI)) - tension; - if(shearsurf>1e-5 || tensionsurf>1e-5) + if (shearsurf > 1e-5 || tensionsurf > 1e-5) { yield = 1; - double dsqrtJ2_dsig[6]={0.}, dlode_dsig[6]={0.}; - double dAniso_dsig_tens[6]={0.}, dAniso_dsig_comp[6]={0.}; + double dsqrtJ2_dsig[6] = {0.}, dlode_dsig[6] = {0.}; + double dAniso_dsig_tens[6] = {0.}, dAniso_dsig_comp[6] = {0.}; double dcsn_dsig[6] = {0.}, dtens_dsig[6] = {0.}; - double dsig_dlamda[6]={0.}, /*dsig_dlamda_k1[6]={0.},*/ dfs_dsig[6]={0.}, dft_dsig[6]={0.}, dgs_dsig[6]={0.}, dgt_dsig[6]={0.}; + double dsig_dlamda[6] = {0.}, /*dsig_dlamda_k1[6]={0.},*/ dfs_dsig[6] = {0.}, dft_dsig[6] = {0.}, + dgs_dsig[6] = {0.}, dgt_dsig[6] = {0.}; bool first_step; - double shearsurf_k1, tensionsurf_k1 /*, local_damp, tmp_pos = 1., tmp_neg=1.*/; //Newton downhill - double lamda_pos=0., lamda_neg=0., shearsurf_pos, shearsurf_neg, tensionsurf_pos, tensionsurf_neg; - if(tensionsurf>MKleinsteZahl)//if tension + double shearsurf_k1, tensionsurf_k1 /*, local_damp, tmp_pos = 1., tmp_neg=1.*/; // Newton downhill + double lamda_pos = 0., lamda_neg = 0., shearsurf_pos, shearsurf_neg, tensionsurf_pos, tensionsurf_neg; + if (tensionsurf > MKleinsteZahl) // if tension { // dlamda = 0, dlamda_1=1; counter = 0; first_step = true; tensionsurf_k1 = tensionsurf; - for(i=0;i 0) + if (tensionsurf_k1 > 0) { lamda_pos = dlamda; TmpValue1 = 0.; - if(first_step) + if (first_step) { - for(i=0;imulti(dgt_dsig,dsig_dlamda,-1); + for (i = 0; i < Size; i++) + dsig_dlamda[i] = 0.; + Dep->multi(dgt_dsig, dsig_dlamda, -1); lamda_pos = 0.; tensionsurf_pos = tensionsurf; first_step = false; } - for (i=0; imulti(dgt_dsig,dsig_dlamda,-1); + // Dep->multi(dgt_dsig,dsig_dlamda,-1); break; } - else if(tensionsurf_k1<0) + else if (tensionsurf_k1 < 0) { - //for(i=0;imulti(dgt_dsig,dsig_dlamda,-1); - shearsurf_neg=tensionsurf_k1; + // Dep->multi(dgt_dsig,dsig_dlamda,-1); + shearsurf_neg = tensionsurf_k1; lamda_neg = dlamda; - dlamda = lamda_pos-tensionsurf_pos*(lamda_neg-lamda_pos)/(tensionsurf_neg-tensionsurf_pos); - if(fabs(lamda_neg-lamda_pos)<1e-8) + dlamda = lamda_pos + - tensionsurf_pos * (lamda_neg - lamda_pos) / (tensionsurf_neg - tensionsurf_pos); + if (fabs(lamda_neg - lamda_pos) < 1e-8) break; - //dlamda = (lamda_pos+lamda_neg)/2.; + // dlamda = (lamda_pos+lamda_neg)/2.; } else { - //for(i=0;imulti(dgt_dsig,dsig_dlamda,-1); + // Dep->multi(dgt_dsig,dsig_dlamda,-1); lamda_pos = dlamda; tensionsurf_pos = tensionsurf_k1; - dlamda = lamda_pos-tensionsurf_pos*(lamda_neg-lamda_pos)/(tensionsurf_neg-tensionsurf_pos); - if(fabs(lamda_neg-lamda_pos)<1e-8) + dlamda = lamda_pos + - tensionsurf_pos * (lamda_neg - lamda_pos) / (tensionsurf_neg - tensionsurf_pos); + if (fabs(lamda_neg - lamda_pos) < 1e-8) break; - //dlamda = (lamda_pos+lamda_neg)/2.; + // dlamda = (lamda_pos+lamda_neg)/2.; } } - for(i=0;iGetTranspose(*TmpMatrix2); - for(i=0; imulti(TmpPrinStrComp,TmpStrComp); - TmpMatrix2->multi(TmpPrinStrTens,TmpStrTens); - AnisoParaComp = CalAnisoPara(TmpStrComp,MicroStruTensor); - AnisoParaTens = CalAnisoPara(TmpStrTens,MicroStruTensor); + TmpMatrix2->multi(TmpPrinStrComp, TmpStrComp); + TmpMatrix2->multi(TmpPrinStrTens, TmpStrTens); + AnisoParaComp = CalAnisoPara(TmpStrComp, MicroStruTensor); + AnisoParaTens = CalAnisoPara(TmpStrTens, MicroStruTensor); CalculateCoefficent_MOHR(ep, AnisoParaComp, AnisoParaTens); } - I1 = TmpStress[0]+TmpStress[1]+TmpStress[2]; - for (i=0;i1-1e-6) + if ((-3 * sqrt3 / 2. * J3 / pow(sqrtJ2, 3)) > 1 - 1e-6) { - LodeAngle = PI/6.; + LodeAngle = PI / 6.; lode_out_range = true; } - else if ((-3*sqrt3/2.*J3/pow(sqrtJ2,3))<-1+1e-6) + else if ((-3 * sqrt3 / 2. * J3 / pow(sqrtJ2, 3)) < -1 + 1e-6) { - LodeAngle = -PI/6.; + LodeAngle = -PI / 6.; lode_out_range = true; } else { - LodeAngle = asin(-3*sqrt3/2.*J3/pow(sqrtJ2,3))/3.; + LodeAngle = asin(-3 * sqrt3 / 2. * J3 / pow(sqrtJ2, 3)) / 3.; lode_out_range = false; } } - shearsurf=Ntheta*(I1/3+2/sqrt3*sqrtJ2*sin(LodeAngle+2/3.*PI)) - -(I1/3.+2/sqrt3*sqrtJ2*sin(LodeAngle-2/3.*PI))-csn; - tensionsurf_k1=(I1/3.+2/sqrt3*sqrtJ2*sin(LodeAngle+2/3.*PI))-tension; - }// end while for dlamda - //calculate Dep + shearsurf = Ntheta * (I1 / 3 + 2 / sqrt3 * sqrtJ2 * sin(LodeAngle + 2 / 3. * PI)) + - (I1 / 3. + 2 / sqrt3 * sqrtJ2 * sin(LodeAngle - 2 / 3. * PI)) - csn; + tensionsurf_k1 = (I1 / 3. + 2 / sqrt3 * sqrtJ2 * sin(LodeAngle + 2 / 3. * PI)) - tension; + } // end while for dlamda + // calculate Dep // dsig_dlamda = -De dG/dstr TmpValue1 = 0.; TmpValue2 = 0.; - for (i=0; iWrite(); - //TmpMatrix2->Write(); + // TEST + // TmpMatrix->Write(); + // TmpMatrix2->Write(); // - for(i=0; imulti(*TmpMatrix, *Dep, *TmpMatrix2);//De (dG/dstr)T dF/dstr De + for (i = 0; i < Size; i++) + for (j = 0; j < Size; j++) + (*TmpMatrix)(i, j) = dgt_dsig[i] * dft_dsig[j]; + Dep->multi(*TmpMatrix, *Dep, *TmpMatrix2); // De (dG/dstr)T dF/dstr De // - //TmpDe->Write(); - //TmpMatrix2->Write(); + // TmpDe->Write(); + // TmpMatrix2->Write(); // - for(i=0; iWrite(); + // TEST + // TmpDe->Write(); // - }//end if tension + } // end if tension - if(shearsurf>1e-5) + if (shearsurf > 1e-5) { dlamda = 0; //, dlamda_1=1, dlamda_0=0.; counter = 0; first_step = true; // local_damp = 1.; - shearsurf_k1=shearsurf; - for(i=0;i 0) + if (shearsurf_k1 > 0) { lamda_pos = dlamda; TmpValue1 = 0.; - if(first_step) + if (first_step) { - for(i=0;imulti(dgs_dsig,dsig_dlamda,-1); + for (i = 0; i < Size; i++) + dsig_dlamda[i] = 0.; + Dep->multi(dgs_dsig, dsig_dlamda, -1); lamda_pos = 0.; shearsurf_pos = shearsurf; - //first_step = false; + // first_step = false; } - for (i=0; imulti(dgs_dsig,dsig_dlamda,-1);//update De dG/dsig + // Dep->multi(dgs_dsig,dsig_dlamda,-1);//update De dG/dsig break; } - else if(shearsurf_k1<0) + else if (shearsurf_k1 < 0) { - //for(i=0;imulti(dgs_dsig,dsig_dlamda,-1);//update De dG/dsig - shearsurf_neg=shearsurf_k1; + // Dep->multi(dgs_dsig,dsig_dlamda,-1);//update De dG/dsig + shearsurf_neg = shearsurf_k1; lamda_neg = dlamda; - dlamda = lamda_pos-shearsurf_pos*(lamda_neg-lamda_pos)/(shearsurf_neg-shearsurf_pos); - if(fabs(lamda_neg-lamda_pos)<1e-12) + dlamda = lamda_pos - shearsurf_pos * (lamda_neg - lamda_pos) / (shearsurf_neg - shearsurf_pos); + if (fabs(lamda_neg - lamda_pos) < 1e-12) break; - //dlamda = (lamda_pos+lamda_neg)/2.; + // dlamda = (lamda_pos+lamda_neg)/2.; } else { - //for(i=0;imulti(dgs_dsig,dsig_dlamda,-1);//update De dG/dsig + // Dep->multi(dgs_dsig,dsig_dlamda,-1);//update De dG/dsig lamda_pos = dlamda; shearsurf_pos = shearsurf_k1; - dlamda = lamda_pos-shearsurf_pos*(lamda_neg-lamda_pos)/(shearsurf_neg-shearsurf_pos); - if(fabs(lamda_neg-lamda_pos)<1e-12) + dlamda = lamda_pos - shearsurf_pos * (lamda_neg - lamda_pos) / (shearsurf_neg - shearsurf_pos); + if (fabs(lamda_neg - lamda_pos) < 1e-12) break; - //dlamda = (lamda_pos+lamda_neg)/2.; + // dlamda = (lamda_pos+lamda_neg)/2.; } } - for(i=0;iGetTranspose(*TmpMatrix2); - for(i=0; imulti(TmpPrinStrComp,TmpStrComp); - TmpMatrix2->multi(TmpPrinStrTens,TmpStrTens); - AnisoParaComp = CalAnisoPara(TmpStrComp,MicroStruTensor); - AnisoParaTens = CalAnisoPara(TmpStrTens,MicroStruTensor); + TmpMatrix2->multi(TmpPrinStrComp, TmpStrComp); + TmpMatrix2->multi(TmpPrinStrTens, TmpStrTens); + AnisoParaComp = CalAnisoPara(TmpStrComp, MicroStruTensor); + AnisoParaTens = CalAnisoPara(TmpStrTens, MicroStruTensor); CalculateCoefficent_MOHR(ep, AnisoParaComp, AnisoParaTens); } - I1 = TmpStress[0]+TmpStress[1]+TmpStress[2]; - for (i=0;i1-1e-6) + if ((-3 * sqrt3 / 2. * J3 / pow(sqrtJ2, 3)) > 1 - 1e-6) { - LodeAngle = PI/6.; + LodeAngle = PI / 6.; lode_out_range = true; } - else if ((-3*sqrt3/2.*J3/pow(sqrtJ2,3))<-1+1e-6) + else if ((-3 * sqrt3 / 2. * J3 / pow(sqrtJ2, 3)) < -1 + 1e-6) { - LodeAngle = -PI/6.; + LodeAngle = -PI / 6.; lode_out_range = true; } else { - LodeAngle = asin(-3*sqrt3/2.*J3/pow(sqrtJ2,3))/3.; + LodeAngle = asin(-3 * sqrt3 / 2. * J3 / pow(sqrtJ2, 3)) / 3.; lode_out_range = false; } } - //shearsurf=Ntheta*(I1/3+2/sqrt3*sqrtJ2*sin(LodeAngle+2/3.*PI)) + // shearsurf=Ntheta*(I1/3+2/sqrt3*sqrtJ2*sin(LodeAngle+2/3.*PI)) // -(I1/3.+2/sqrt3*sqrtJ2*sin(LodeAngle-2/3.*PI))-csn; - shearsurf_k1=Ntheta*(I1/3+2/sqrt3*sqrtJ2*sin(LodeAngle+2/3.*PI)) - -(I1/3.+2/sqrt3*sqrtJ2*sin(LodeAngle-2/3.*PI))-csn; - tensionsurf=(I1/3.+2/sqrt3*sqrtJ2*sin(LodeAngle+2/3.*PI))-tension; - }// end while for dlamda - //calculate Dep + shearsurf_k1 = Ntheta * (I1 / 3 + 2 / sqrt3 * sqrtJ2 * sin(LodeAngle + 2 / 3. * PI)) + - (I1 / 3. + 2 / sqrt3 * sqrtJ2 * sin(LodeAngle - 2 / 3. * PI)) - csn; + tensionsurf = (I1 / 3. + 2 / sqrt3 * sqrtJ2 * sin(LodeAngle + 2 / 3. * PI)) - tension; + } // end while for dlamda + // calculate Dep // dsig_dlamda = -De dG/dstr TmpValue1 = 0.; TmpValue2 = 0.; - for (i=0; iWrite(); - //TmpMatrix2->Write(); + // TEST + // TmpMatrix->Write(); + // TmpMatrix2->Write(); // - for(i=0; imulti(*TmpMatrix, *Dep, *TmpMatrix2);//De (dG/dstr)T dF/dstr De + for (i = 0; i < Size; i++) + for (j = 0; j < Size; j++) + (*TmpMatrix)(i, j) = dgs_dsig[i] * dfs_dsig[j]; + Dep->multi(*TmpMatrix, *Dep, *TmpMatrix2); // De (dG/dstr)T dF/dstr De // - //TmpDe->Write(); - //TmpMatrix2->Write(); + // TmpDe->Write(); + // TmpMatrix2->Write(); // - for(i=0; iWrite(); - //TransMicroStru_T->Write(); - //TransMicroStru_TInv->Write(); - //TmpDe->Write(); - //Dep->Write(); + // TEST + // TransMicroStru->Write(); + // TransMicroStru_T->Write(); + // TransMicroStru_TInv->Write(); + // TmpDe->Write(); + // Dep->Write(); // - }//end if shear + } // end if shear - for (i=0;imulti(TmpStress,TryStress); + for (i = 0; i < Size; i++) + TryStress[i] = 0; + TransMicroStru_T->multi(TmpStress, TryStress); *ConstitutiveMatrix = (0.); TransMicroStru_T->multi(*TmpDe, *TransMicroStru, *ConstitutiveMatrix); - //TEST - //ConstitutiveMatrix->Write(); + // TEST + // ConstitutiveMatrix->Write(); // - }//end if shear if tension + } // end if shear if tension else { - for(i=0; imulti(dstressP,dstrainP); - ep += sqrt(2.0/3.0*(TensorMutiplication2(dstrainP, dstrainP, Dim))); + for (i = 0; i < Size; i++) + dstressP[i] = TryStress[i] - TryStress_0[i]; + Inv_De->multi(dstressP, dstrainP); + ep += sqrt(2.0 / 3.0 * (TensorMutiplication2(dstrainP, dstrainP, Dim))); (*ele_val->pStrain)(GPiGPj) = ep; } return yield; @@ -3806,25 +3795,25 @@ int CSolidProperties::StressIntegrationMOHR_Aniso(const int GPiGPj, const Elemen /******************************************************* WX: calculate aniso. plas. parameters *******************************************************/ -double CSolidProperties::CalAnisoPara(double *Stress, double *MicroStruTensor ) +double CSolidProperties::CalAnisoPara(double* Stress, double* MicroStruTensor) { double L1, L2, L3, LkLk, AnisoPara; - double l[3]={0.}; - L1 = sqrt(Stress[0]*Stress[0]+Stress[3]*Stress[3]+Stress[4]*Stress[4]); - L2 = sqrt(Stress[3]*Stress[3]+Stress[1]*Stress[1]+Stress[5]*Stress[5]); - L3 = sqrt(Stress[4]*Stress[4]+Stress[5]*Stress[5]+Stress[2]*Stress[2]); + double l[3] = {0.}; + L1 = sqrt(Stress[0] * Stress[0] + Stress[3] * Stress[3] + Stress[4] * Stress[4]); + L2 = sqrt(Stress[3] * Stress[3] + Stress[1] * Stress[1] + Stress[5] * Stress[5]); + L3 = sqrt(Stress[4] * Stress[4] + Stress[5] * Stress[5] + Stress[2] * Stress[2]); - LkLk = sqrt(L1*L1+L2*L2+L3*L3); - if(LkLkStress->Rows(); double TmpValue1, TmpValue2, dstrNorm = 0; - //double LodeAngle, I1, J2, J3; + // double LodeAngle, I1, J2, J3; double shearsurf, tensionsurf, ep; - //initialize all vectors + // initialize all vectors double dstrs[6] = {0.}, TmpStress[6] = {0.}, prin_str[6] = {0.}, prin_str0[6] = {0.}, prin_dir[9] = {0.}; *TransMatrixA = (0.); @@ -3859,13 +3848,14 @@ int CSolidProperties::DirectStressIntegrationMOHR(const int GPiGPj, ElementValue *TmpDe = *Dep; - *ConstitutiveMatrix = (0.); //in head already defined, and is used for later as global variable + *ConstitutiveMatrix = (0.); // in head already defined, and is used for later as global variable - ep = (*ele_val->pStrain)(GPiGPj); //get equ plas strain + ep = (*ele_val->pStrain)(GPiGPj); // get equ plas strain - if(Size>4) Dim = 3; + if (Size > 4) + Dim = 3; - for(i=0; iStress)(i, GPiGPj); // stress_0 @@ -3873,7 +3863,7 @@ int CSolidProperties::DirectStressIntegrationMOHR(const int GPiGPj, ElementValue TmpStress[i] = devS[i]; dstrNorm += dstrs[i] * dstrs[i]; } - if(Size == 4) + if (Size == 4) devS[4] = devS[5] = 0.; //////////// @@ -3885,20 +3875,20 @@ int CSolidProperties::DirectStressIntegrationMOHR(const int GPiGPj, ElementValue devS[4]=TmpStress[4]=-2.8646737121460246e-007; devS[5]=TmpStress[5]=7.9612875121132550e-007; - */ /////////// - //test + */ /////////// + // test CalPrinStrDir(devS, prin_str, prin_dir, Dim); - //CalPrinStrs(devS, prin_str, Size); //prin. stresses guess - //CalPrinDir(prin_str, TmpStress, prin_dir, Size); + // CalPrinStrs(devS, prin_str, Size); //prin. stresses guess + // CalPrinDir(prin_str, TmpStress, prin_dir, Size); CalTransMatrixA(prin_dir, TransMatrixA, Size); TransMatrixA->GetTranspose(*TransMatrixA_T); Cal_Inv_Matrix(Size, TransMatrixA, Inv_TransA); Inv_TransA->GetTranspose(*Inv_TransA_T); - //Inv_TransA_T->multi(*Dep, *Inv_TransA, *PrinDe); //De in prin. (A^-T De A^-1) + // Inv_TransA_T->multi(*Dep, *Inv_TransA, *PrinDe); //De in prin. (A^-T De A^-1) *TmpDe = (0.); - Inv_TransA_T->multi(*Dep, *Inv_TransA, *TmpDe);//De in prin. coord. + Inv_TransA_T->multi(*Dep, *Inv_TransA, *TmpDe); // De in prin. coord. double TmpStress0[6] = {0.}, tmp_prin_str[6] = {0.}, tmp_prin_dir[9] = {0.}; for (i = 0; i < Size; i++) @@ -3908,48 +3898,48 @@ int CSolidProperties::DirectStressIntegrationMOHR(const int GPiGPj, ElementValue if (Size == 4) TmpStress0[4] = TmpStress[5] = 0.; - //CalPrinStrs(TmpStress0, tmp_prin_str, Size); - CalPrinStrDir(TmpStress0, tmp_prin_str, tmp_prin_dir, Dim); //prin. stresses t0 + // CalPrinStrs(TmpStress0, tmp_prin_str, Size); + CalPrinStrDir(TmpStress0, tmp_prin_str, tmp_prin_dir, Dim); // prin. stresses t0 /*///////// double tmpresult[6]={0.}; TransMatrixA_T->multi(prin_str, tmpresult); for(i=0; iGetIteSteps()==1) + // if(m_pcs->GetIteSteps()==1) - if(Plasticity_Bedding)//WX:09.2011 + if (Plasticity_Bedding) // WX:09.2011 { - if(itesteps==2||Update>0) + if (itesteps == 2 || Update > 0) { /*double tmp_load_dir_major = 0; double tmp_load_dir_minor = 0; for(i=0; i<3; i++) { - tmp_load_dir_major += Bedding_Norm[i]*prin_dir[3*i+2]; - tmp_load_dir_minor += Bedding_Norm[i]*prin_dir[3*i]; + tmp_load_dir_major += Bedding_Norm[i]*prin_dir[3*i+2]; + tmp_load_dir_minor += Bedding_Norm[i]*prin_dir[3*i]; }*/ - double Stress_Bedding_comp[6]={0.},Stress_Bedding_tens[6]={0.}; //Stress_Bedding[6]={0.} - double prin_str_comp[6]={0.}, prin_str_tens[6]={0.}; - double TmpStress_comp[6]={0.}, TmpStress_tens[6]={0.}; - double L_sqr_comp[3]={0.}, L_sqr_tens[3]={0.}; + double Stress_Bedding_comp[6] = {0.}, Stress_Bedding_tens[6] = {0.}; // Stress_Bedding[6]={0.} + double prin_str_comp[6] = {0.}, prin_str_tens[6] = {0.}; + double TmpStress_comp[6] = {0.}, TmpStress_tens[6] = {0.}; + double L_sqr_comp[3] = {0.}, L_sqr_tens[3] = {0.}; double tr_sig_comp = 0., tr_sig_tens = 0., tr_a_sig_comp = 0., tr_a_sig_tens = 0.; double scalar_comp = 0, scalar_tens = 0; - for(i=0;i<3;i++) + for (i = 0; i < 3; i++) { - if(prin_str[i]<=0) + if (prin_str[i] <= 0) { - prin_str_comp[i]=prin_str[i]; - prin_str_tens[i]=0; + prin_str_comp[i] = prin_str[i]; + prin_str_tens[i] = 0; } else { - prin_str_comp[i]=0; - prin_str_tens[i]=prin_str[i]; + prin_str_comp[i] = 0; + prin_str_tens[i] = prin_str[i]; } } TransMatrixA_T->multi(prin_str_comp, TmpStress_comp); @@ -3958,104 +3948,104 @@ int CSolidProperties::DirectStressIntegrationMOHR(const int GPiGPj, ElementValue TransMicroStru_TInv->multi(TmpStress_tens, Stress_Bedding_tens); /*for(i=0;i<6;i++) { - if(Stress_Bedding[i]<=0) - { - Stress_Bedding_comp[i]=Stress_Bedding[i]; - Stress_Bedding_tens[i]=0; - } - else - { - Stress_Bedding_comp[i]=0; - Stress_Bedding_tens[i]=Stress_Bedding[i]; - } + if(Stress_Bedding[i]<=0) + { + Stress_Bedding_comp[i]=Stress_Bedding[i]; + Stress_Bedding_tens[i]=0; + } + else + { + Stress_Bedding_comp[i]=0; + Stress_Bedding_tens[i]=Stress_Bedding[i]; + } }*/ - //for(i=0;i<6;i++) + // for(i=0;i<6;i++) //{ // tr_sig_comp += Stress_Bedding_comp[i]*Stress_Bedding_comp[i]; // tr_sig_tens += Stress_Bedding_tens[i]*Stress_Bedding_tens[i]; //} - L_sqr_comp[0] = Stress_Bedding_comp[0]*Stress_Bedding_comp[0] - +Stress_Bedding_comp[3]*Stress_Bedding_comp[3] - +Stress_Bedding_comp[4]*Stress_Bedding_comp[4]; - L_sqr_comp[1] = Stress_Bedding_comp[1]*Stress_Bedding_comp[1] - +Stress_Bedding_comp[3]*Stress_Bedding_comp[3] - +Stress_Bedding_comp[5]*Stress_Bedding_comp[5]; - L_sqr_comp[2] = Stress_Bedding_comp[2]*Stress_Bedding_comp[2] - +Stress_Bedding_comp[5]*Stress_Bedding_comp[5] - +Stress_Bedding_comp[4]*Stress_Bedding_comp[4]; + L_sqr_comp[0] = Stress_Bedding_comp[0] * Stress_Bedding_comp[0] + + Stress_Bedding_comp[3] * Stress_Bedding_comp[3] + + Stress_Bedding_comp[4] * Stress_Bedding_comp[4]; + L_sqr_comp[1] = Stress_Bedding_comp[1] * Stress_Bedding_comp[1] + + Stress_Bedding_comp[3] * Stress_Bedding_comp[3] + + Stress_Bedding_comp[5] * Stress_Bedding_comp[5]; + L_sqr_comp[2] = Stress_Bedding_comp[2] * Stress_Bedding_comp[2] + + Stress_Bedding_comp[5] * Stress_Bedding_comp[5] + + Stress_Bedding_comp[4] * Stress_Bedding_comp[4]; tr_sig_comp = L_sqr_comp[0] + L_sqr_comp[1] + L_sqr_comp[2]; - L_sqr_tens[0] = Stress_Bedding_tens[0]*Stress_Bedding_tens[0] - +Stress_Bedding_tens[3]*Stress_Bedding_tens[3] - +Stress_Bedding_tens[4]*Stress_Bedding_tens[4]; - L_sqr_tens[1] = Stress_Bedding_tens[1]*Stress_Bedding_tens[1] - +Stress_Bedding_tens[3]*Stress_Bedding_tens[3] - +Stress_Bedding_tens[5]*Stress_Bedding_tens[5]; - L_sqr_tens[2] = Stress_Bedding_tens[2]*Stress_Bedding_tens[2] - +Stress_Bedding_tens[5]*Stress_Bedding_tens[5] - +Stress_Bedding_tens[4]*Stress_Bedding_tens[4]; + L_sqr_tens[0] = Stress_Bedding_tens[0] * Stress_Bedding_tens[0] + + Stress_Bedding_tens[3] * Stress_Bedding_tens[3] + + Stress_Bedding_tens[4] * Stress_Bedding_tens[4]; + L_sqr_tens[1] = Stress_Bedding_tens[1] * Stress_Bedding_tens[1] + + Stress_Bedding_tens[3] * Stress_Bedding_tens[3] + + Stress_Bedding_tens[5] * Stress_Bedding_tens[5]; + L_sqr_tens[2] = Stress_Bedding_tens[2] * Stress_Bedding_tens[2] + + Stress_Bedding_tens[5] * Stress_Bedding_tens[5] + + Stress_Bedding_tens[4] * Stress_Bedding_tens[4]; tr_sig_tens = L_sqr_tens[0] + L_sqr_tens[1] + L_sqr_tens[2]; - for(i=0;i<3;i++) + for (i = 0; i < 3; i++) { - tr_a_sig_comp += MicroStruTensor[i]*L_sqr_comp[i]; - tr_a_sig_tens += MicroStruTensor[i]*L_sqr_tens[i]; + tr_a_sig_comp += MicroStruTensor[i] * L_sqr_comp[i]; + tr_a_sig_tens += MicroStruTensor[i] * L_sqr_tens[i]; } // - //tr_a_sig_comp += MicroStruTensor[i]*(Stress_Bedding_comp[i]*Stress_Bedding_comp[i] - //+); - //tr_a_sig_tens += MicroStruTensor[i]*Stress_Bedding_tens[i]*Stress_Bedding_tens[i]; - if(tr_sig_comp==0) + // tr_a_sig_comp += MicroStruTensor[i]*(Stress_Bedding_comp[i]*Stress_Bedding_comp[i] + //+); + // tr_a_sig_tens += MicroStruTensor[i]*Stress_Bedding_tens[i]*Stress_Bedding_tens[i]; + if (tr_sig_comp == 0) scalar_comp = 0; else - scalar_comp = tr_a_sig_comp/tr_sig_comp ; - if(tr_sig_tens==0) + scalar_comp = tr_a_sig_comp / tr_sig_comp; + if (tr_sig_tens == 0) scalar_tens = 0; else - scalar_tens = tr_a_sig_tens/tr_sig_tens ; - if (scalar_tens < MKleinsteZahl ) + scalar_tens = tr_a_sig_tens / tr_sig_tens; + if (scalar_tens < MKleinsteZahl) scalar_tens = 1; - //if((fabs(tmp_load_dir_major)>(1+1e-6))||(fabs(tmp_load_dir_minor)>(1+1e-6))) + // if((fabs(tmp_load_dir_major)>(1+1e-6))||(fabs(tmp_load_dir_minor)>(1+1e-6))) //{ // cout<<"ERROR: Please check input value for BEDDING_NORM in .msp"<1) + // if(fabs(tmp_load_dir_major)>1) // tmp_load_dir_major = 1; - //if (fabs(tmp_load_dir_minor)>1) + // if (fabs(tmp_load_dir_minor)>1) // tmp_load_dir_minor = 1; - //tmp_load_dir_major = acos(fabs(tmp_load_dir_major))*180/PI; //because ||bedding_norm|| and ||prin_dir|| is 1 - //tmp_load_dir_minor = acos(fabs(tmp_load_dir_minor))*180/PI; - (*ele_val->scalar_aniso_comp)(GPiGPj)=scalar_comp; - (*ele_val->scalar_aniso_tens)(GPiGPj)=scalar_tens; + // tmp_load_dir_major = acos(fabs(tmp_load_dir_major))*180/PI; //because ||bedding_norm|| and ||prin_dir|| + // is 1 + // tmp_load_dir_minor = acos(fabs(tmp_load_dir_minor))*180/PI; + (*ele_val->scalar_aniso_comp)(GPiGPj) = scalar_comp; + (*ele_val->scalar_aniso_tens)(GPiGPj) = scalar_tens; } - CalculateCoefficent_MOHR(ep,(*ele_val->scalar_aniso_comp)(GPiGPj),(*ele_val->scalar_aniso_tens)(GPiGPj)); + CalculateCoefficent_MOHR(ep, (*ele_val->scalar_aniso_comp)(GPiGPj), (*ele_val->scalar_aniso_tens)(GPiGPj)); } else - CalculateCoefficent_MOHR(ep,0,0); - + CalculateCoefficent_MOHR(ep, 0, 0); shearsurf = Ntheta * prin_str[0] - prin_str[2] - csn; tensionsurf = prin_str[0] - tension; - if(dstrNorm == 0) + if (dstrNorm == 0) { shearsurf = -1; tensionsurf = -1; } - if((shearsurf > 0) || (tensionsurf > 0)) + if ((shearsurf > 0) || (tensionsurf > 0)) { double P_12, P_31, P_41, P_63, P_64, P_52, P_85, P_74, P_78, P_98, P_45 /*, P_X7*/; - double t1, t2 /*, t1ra*/ ,t1r1 /*, t2ra, t2r2*/, t3r1 /*, t3r2*/; + double t1, t2 /*, t1ra*/, t1r1 /*, t2ra, t2r2*/, t3r1 /*, t3r2*/; double fkt1, fkt2; double mm = 0.; - double l1[6] = {0.},l2[6] = {0.},l1g[6] = {0.},l2g[6] = {0.},l1R[6] = {0.},l2R[6] = {0.},l3R[6] = {0.}; - double rsp[6] = {0.},rtp[6] = {0.}; - double sigA[6] = {0.},sig1R[6] = {0.},sig2R[6] = {0.},sigaR[6] = {0.}; - double dFsdprin_s[6] = {0.},dFtdprin_s[6] = {0.},dGsdprin_s[6] = {0.},dGtdprin_s[6] = {0.}; - double De_dGsdprin_s[6] = {0.},De_dGtdprin_s[6] = {0.}; - double dStressP[6] = {0.},dStrainP[6] = {0.}; + double l1[6] = {0.}, l2[6] = {0.}, l1g[6] = {0.}, l2g[6] = {0.}, l1R[6] = {0.}, l2R[6] = {0.}, l3R[6] = {0.}; + double rsp[6] = {0.}, rtp[6] = {0.}; + double sigA[6] = {0.}, sig1R[6] = {0.}, sig2R[6] = {0.}, sigaR[6] = {0.}; + double dFsdprin_s[6] = {0.}, dFtdprin_s[6] = {0.}, dGsdprin_s[6] = {0.}, dGtdprin_s[6] = {0.}; + double De_dGsdprin_s[6] = {0.}, De_dGtdprin_s[6] = {0.}; + double dStressP[6] = {0.}, dStrainP[6] = {0.}; double cVec[6] = {0}; yield = 1; @@ -4075,48 +4065,46 @@ int CSolidProperties::DirectStressIntegrationMOHR(const int GPiGPj, ElementValue dGsdprin_s[0] = Nphi; dFsdprin_s[2] = dGsdprin_s[2] = -1.; TmpDe->multi(dGsdprin_s, De_dGsdprin_s); - //PrinDe->multi(dGsdprin_s, De_dGsdprin_s);// + // PrinDe->multi(dGsdprin_s, De_dGsdprin_s);// TmpValue1 = 0.; - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) TmpValue1 += dFsdprin_s[i] * De_dGsdprin_s[i]; - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) rsp[i] = De_dGsdprin_s[i] / TmpValue1; dFtdprin_s[0] = dGtdprin_s[0] = 1.; TmpDe->multi(dGtdprin_s, De_dGtdprin_s); - //PrinDe->multi(dGtdprin_s, De_dGtdprin_s);// + // PrinDe->multi(dGtdprin_s, De_dGtdprin_s);// TmpValue2 = 0.; - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) TmpValue2 += dFtdprin_s[i] * De_dGtdprin_s[i]; - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) rtp[i] = De_dGtdprin_s[i] / TmpValue2; double tmp_shearsurf = Ntheta * tmp_prin_str[0] - tmp_prin_str[2] - csn; double tmp_tensionsurf = tmp_prin_str[0] - tension; - if(((tmp_tensionsurf)==0&&(tmp_shearsurf)<=0)||((tmp_tensionsurf)<=0&&(tmp_shearsurf)==0)) + if (((tmp_tensionsurf) == 0 && (tmp_shearsurf) <= 0) || ((tmp_tensionsurf) <= 0 && (tmp_shearsurf) == 0)) mm = 0.; - else - if(prin_str[0] != tmp_prin_str[0]) + else if (prin_str[0] != tmp_prin_str[0]) { mm = (tension - tmp_prin_str[0]) / (prin_str[0] - tmp_prin_str[0]); - if(mm >= 0 && mm <= 1) + if (mm >= 0 && mm <= 1) { - double tmp_prin_str_3 = tmp_prin_str[2] + mm*(prin_str[2]-tmp_prin_str[2]); - if (tmp_prin_str_3 < (Ntheta*tension-csn)||tmp_prin_str_3>tension) + double tmp_prin_str_3 = tmp_prin_str[2] + mm * (prin_str[2] - tmp_prin_str[2]); + if (tmp_prin_str_3 < (Ntheta * tension - csn) || tmp_prin_str_3 > tension) mm = (csn + tmp_prin_str[2] - Ntheta * tmp_prin_str[0]) - /(Ntheta*(prin_str[0]-tmp_prin_str[0])-(prin_str[2]-tmp_prin_str[2])); + / (Ntheta * (prin_str[0] - tmp_prin_str[0]) - (prin_str[2] - tmp_prin_str[2])); } else mm = (csn + tmp_prin_str[2] - Ntheta * tmp_prin_str[0]) - /(Ntheta*(prin_str[0]-tmp_prin_str[0])-(prin_str[2]-tmp_prin_str[2])); + / (Ntheta * (prin_str[0] - tmp_prin_str[0]) - (prin_str[2] - tmp_prin_str[2])); } else mm = (csn + tmp_prin_str[2] - Ntheta * tmp_prin_str[0]) - /(Ntheta*(prin_str[0]-tmp_prin_str[0])-(prin_str[2]-tmp_prin_str[2])); - + / (Ntheta * (prin_str[0] - tmp_prin_str[0]) - (prin_str[2] - tmp_prin_str[2])); Cal_Inv_Matrix(Size, TmpDe, Inv_De); - //Cal_Inv_Matrix(Size, PrinDe, Inv_De); + // Cal_Inv_Matrix(Size, PrinDe, Inv_De); t1 = CalVar_t(l1, l1g, Inv_De, prin_str, sig1R, Size); t2 = CalVar_t(l2, l2g, Inv_De, prin_str, sig2R, Size); @@ -4130,156 +4118,154 @@ int CSolidProperties::DirectStressIntegrationMOHR(const int GPiGPj, ElementValue P_12 = CalVarP(rsp, l1, prin_str, sig1R); P_31 = CalVarP(rsp, l2, prin_str, sig2R); P_41 = CalVarP(rsp, l3R, prin_str, sig1R); - //P_63 = 0; - //P_63 = CalVarP(rsp, l2R, prin_str, sig2R); + // P_63 = 0; + // P_63 = CalVarP(rsp, l2R, prin_str, sig2R); P_63 = P_41; P_45 = CalVarP(rsp, rtp, prin_str, sig1R); - //P_64 = CalVarP(rsp, rtp, prin_str, sig2R); + // P_64 = CalVarP(rsp, rtp, prin_str, sig2R); P_64 = CalVarP(rsp, rtp, prin_str, sig2R); - //P_52 = 0; - //P_52 = CalVarP(rsp, l1R, prin_str, sig1R); + // P_52 = 0; + // P_52 = CalVarP(rsp, l1R, prin_str, sig1R); P_52 = P_41; P_74 = CalVarP(rtp, l3R, prin_str, sig1R); - //P_85 = 0; - //P_85 = CalVarP(rtp, l1, prin_str, sig1R); + // P_85 = 0; + // P_85 = CalVarP(rtp, l1, prin_str, sig1R); P_85 = P_74; P_78 = CalVarP(rtp, l1R, prin_str, sig1R); - //P_98 = 0; + // P_98 = 0; P_98 = CalVarP(rtp, l2R, prin_str, sig2R); // P_X7 = CalVarP(rtp, l2R, prin_str, sig2R); - if( P_12 >= 0 && P_31 <= 0 && P_41 <= 0 ) //return to fmc + if (P_12 >= 0 && P_31 <= 0 && P_41 <= 0) // return to fmc { double tmpvalue = 0.; - //Matrix *tmpMatrix2 = new Matrix (Size,Size); - //Matrix *dGds_dFds = new Matrix (Size,Size); - *TmpMatrix2 = (0.);//WX:08.2011 - *dGds_dFds = (0.);//WX:08.2011 - for(i = 0; i < 3; i++) + // Matrix *tmpMatrix2 = new Matrix (Size,Size); + // Matrix *dGds_dFds = new Matrix (Size,Size); + *TmpMatrix2 = (0.); // WX:08.2011 + *dGds_dFds = (0.); // WX:08.2011 + for (i = 0; i < 3; i++) { tmpvalue += dFsdprin_s[i] * (prin_str[i] - sigA[i]); } - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) { prin_str0[i] = prin_str[i]; prin_str[i] -= tmpvalue * rsp[i]; dStressP[i] = prin_str[i] - prin_str0[i]; } - Inv_De->multi(dStressP,dStrainP); - for(i = 0; i < 3; i++) - for(j = 0; j < 3; j++) - (*dGds_dFds)(i,j) = rsp[i]*dFsdprin_s[j]; //(D*dGds/(dFds*D*dGds))*dFds + Inv_De->multi(dStressP, dStrainP); + for (i = 0; i < 3; i++) + for (j = 0; j < 3; j++) + (*dGds_dFds)(i, j) = rsp[i] * dFsdprin_s[j]; //(D*dGds/(dFds*D*dGds))*dFds dGds_dFds->multi(*TmpDe, *TmpMatrix2); - //dGds_dFds->multi(*PrinDe, *tmpMatrix2); + // dGds_dFds->multi(*PrinDe, *tmpMatrix2); *TmpDe -= *TmpMatrix2; //*PrinDe -= *tmpMatrix2; - //for(i=3; imulti(dStressP,dStrainP); //dstrainP = D-1 * dstressp - VecCrossProduct(dStrainP,l1g,cVec); //cVec = dstrainP X l1g + Inv_De->multi(dStressP, dStrainP); // dstrainP = D-1 * dstressp + VecCrossProduct(dStrainP, l1g, cVec); // cVec = dstrainP X l1g - CalDep_l(l1, l1g, Inv_De, Dep_l, 1.0); //Dep_l = l*lgT/(lT*D-1*lg) - CalDep_l(cVec, cVec, Inv_De, dDep_l, fkt2); //dDep_l = fkt2*cVec*cVecT/(cVecT*D-1*cVec) + CalDep_l(l1, l1g, Inv_De, Dep_l, 1.0); // Dep_l = l*lgT/(lT*D-1*lg) + CalDep_l(cVec, cVec, Inv_De, dDep_l, fkt2); // dDep_l = fkt2*cVec*cVecT/(cVecT*D-1*cVec) //*TmpDe=(0.); - for(i = 0; i < 3; i++) - for(j = 0; j < 3; j++) - (*TmpDe)(i,j) = (*Dep_l)(i,j) + (*dDep_l)(i,j); - //for(i=3; i0 && t2<0 ) //return to l2 - else if( P_31>0 && P_63<0 ) //return to l2 + // else if( P_31>0 && t2<0 ) //return to l2 + else if (P_31 > 0 && P_63 < 0) // return to l2 { - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) { prin_str0[i] = prin_str[i]; prin_str[i] = t2 * l2[i] + sig2R[i]; dStressP[i] = prin_str[i] - prin_str0[i]; } - Inv_De->multi(dStressP,dStrainP); - VecCrossProduct(dStrainP,l2g,cVec); + Inv_De->multi(dStressP, dStrainP); + VecCrossProduct(dStrainP, l2g, cVec); CalDep_l(l2, l2g, Inv_De, Dep_l, 1.0); CalDep_l(cVec, cVec, Inv_De, dDep_l, fkt2); //*TmpDe=(0.); - for(i = 0; i < 3; i++) - for(j = 0; j < 3; j++) - (*TmpDe)(i,j) = (*Dep_l)(i,j) + (*dDep_l)(i,j); - //for(i=3; i0 && P_74<0 && t3r2>0 && t3r1<0 ) //return to l3R - else if( P_41>0 && P_45>0 && P_64<0 && P_74<0 ) //return to l3R + // else if( P_41>0 && P_74<0 && t3r2>0 && t3r1<0 ) //return to l3R + else if (P_41 > 0 && P_45 > 0 && P_64 < 0 && P_74 < 0) // return to l3R { - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) { prin_str0[i] = prin_str[i]; prin_str[i] = t3r1 * l3R[i] + sig1R[i]; dStressP[i] = prin_str[i] - prin_str0[i]; } - Inv_De->multi(dStressP,dStrainP); - VecCrossProduct(dStrainP,l3R,cVec); + Inv_De->multi(dStressP, dStrainP); + VecCrossProduct(dStrainP, l3R, cVec); CalDep_l(l3R, l3R, Inv_De, Dep_l, 1.0); CalDep_l(cVec, cVec, Inv_De, dDep_l, fkt2); //*TmpDe=(0.); - for(i = 0; i < 3; i++) - for(j = 0; j < 3; j++) - (*TmpDe)(i,j) = (*Dep_l)(i,j) + (*dDep_l)(i,j); - //for(i=3; i= 0 && P_78 >= 0 ) //return to ft, && P_X7<=0 + else if (P_74 >= 0 && P_78 >= 0) // return to ft, && P_X7<=0 { double tmpvalue = 0.; - //Matrix *tmpMatrix2 = new Matrix (Size,Size); - //Matrix *dGds_dFds = new Matrix (Size,Size); - *TmpMatrix2 = (0.);//WX:08.2011 - *dGds_dFds = (0.);//WX:08.2011 - for(i = 0; i < 3; i++) + // Matrix *tmpMatrix2 = new Matrix (Size,Size); + // Matrix *dGds_dFds = new Matrix (Size,Size); + *TmpMatrix2 = (0.); // WX:08.2011 + *dGds_dFds = (0.); // WX:08.2011 + for (i = 0; i < 3; i++) tmpvalue += dFtdprin_s[i] * (prin_str[i] - sigaR[i]); - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) { prin_str0[i] = prin_str[i]; prin_str[i] -= tmpvalue * rtp[i]; dStressP[i] = prin_str[i] - prin_str0[i]; } - Inv_De->multi(dStressP,dStrainP); + Inv_De->multi(dStressP, dStrainP); - for(i = 0; i < 3; i++) - for(j = 0; j < 3; j++) - (*dGds_dFds)(i,j) = rtp[i] * dFtdprin_s[j]; + for (i = 0; i < 3; i++) + for (j = 0; j < 3; j++) + (*dGds_dFds)(i, j) = rtp[i] * dFtdprin_s[j]; dGds_dFds->multi(*TmpDe, *TmpMatrix2); - //dGds_dFds->multi(*PrinDe, *tmpMatrix2); + // dGds_dFds->multi(*PrinDe, *tmpMatrix2); *TmpDe -= *TmpMatrix2; //*PrinDe -= *tmpMatrix2; - for(i = 0; i < 3; i++) - for(j = 0; j < 3; j++) - if(abs((*TmpDe)(i,j))Write(); + // TmpDe->Write(); //*TmpDe = *Dep; //to be improved - //delete tmpMatrix2; - //delete dGds_dFds; + // delete tmpMatrix2; + // delete dGds_dFds; } - //else if(P_X7>0 && t2r2>0 && t2ra<0) //return to l2R + // else if(P_X7>0 && t2r2>0 && t2ra<0) //return to l2R //{ // for(i=0; i<3; i++) // { @@ -4298,193 +4284,195 @@ int CSolidProperties::DirectStressIntegrationMOHR(const int GPiGPj, ElementValue // for(i=3; i0 && t1ra<0 ) //return to l1R - //else if( P_52>=0 && P_45<=0 && P_85<=0 ) //return to l1R - else if( P_85>=0 && P_78<=0 && P_98<=0 )//return to l1R + // else if( P_78<0 && t1r1>0 && t1ra<0 ) //return to l1R + // else if( P_52>=0 && P_45<=0 && P_85<=0 ) //return to l1R + else if (P_85 >= 0 && P_78 <= 0 && P_98 <= 0) // return to l1R { - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) { prin_str0[i] = prin_str[i]; prin_str[i] = t1r1 * l1R[i] + sig1R[i]; dStressP[i] = prin_str[i] - prin_str0[i]; } - Inv_De->multi(dStressP,dStrainP); - VecCrossProduct(dStrainP,l1R,cVec); + Inv_De->multi(dStressP, dStrainP); + VecCrossProduct(dStrainP, l1R, cVec); CalDep_l(l1R, l1R, Inv_De, Dep_l, 1.0); CalDep_l(cVec, cVec, Inv_De, dDep_l, fkt2); //*TmpDe=(0.); - for(i = 0; i < 3; i++) - for(j = 0; j < 3; j++) - (*TmpDe)(i,j) = (*Dep_l)(i,j) + (*dDep_l)(i,j); - //for(i=3; i=0 && t1ra>=0 ) //return to sigRa - else if( P_98>=0 ) //return to sigRa + // else if( t2ra>=0 && t1ra>=0 ) //return to sigRa + else if (P_98 >= 0) // return to sigRa { double tmpvalue = 0.; - //Matrix *dGds_dFds = new Matrix (Size,Size); - *dGds_dFds = (0.);//WX:08.2011 + // Matrix *dGds_dFds = new Matrix (Size,Size); + *dGds_dFds = (0.); // WX:08.2011 - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) { prin_str0[i] = prin_str[i]; prin_str[i] = sigaR[i]; dStressP[i] = prin_str[i] - prin_str0[i]; } - Inv_De->multi(dStressP,dStrainP); - for(i = 0; i < 3; i++) - for(j = 0; j < 3; j++) - (*dGds_dFds)(i,j) = dStressP[i] * dStressP[j]; + Inv_De->multi(dStressP, dStrainP); + for (i = 0; i < 3; i++) + for (j = 0; j < 3; j++) + (*dGds_dFds)(i, j) = dStressP[i] * dStressP[j]; tmpvalue = 0.; - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) tmpvalue += dStrainP[i] * dStressP[i]; *dGds_dFds /= tmpvalue; *TmpDe -= *dGds_dFds; //*PrinDe -= *dGds_dFds; //*TmpDe *= fkt1; - for(i=0; i=0) //return to sig1R - else if(P_52>=0 && P_45<=0 && P_85<=0) //return to sig1R + // else if(t3r1>=0) //return to sig1R + else if (P_52 >= 0 && P_45 <= 0 && P_85 <= 0) // return to sig1R { double tmpvalue = 0.; - //Matrix *dGds_dFds = new Matrix (Size,Size); - *dGds_dFds = (0.);//WX:08.2011 + // Matrix *dGds_dFds = new Matrix (Size,Size); + *dGds_dFds = (0.); // WX:08.2011 - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) { prin_str0[i] = prin_str[i]; prin_str[i] = sig1R[i]; dStressP[i] = prin_str[i] - prin_str0[i]; } - Inv_De->multi(dStressP,dStrainP); - for(i = 0; i < 3; i++) - for(j = 0; j < 3; j++) - (*dGds_dFds)(i,j) = dStressP[i] * dStressP[j]; + Inv_De->multi(dStressP, dStrainP); + for (i = 0; i < 3; i++) + for (j = 0; j < 3; j++) + (*dGds_dFds)(i, j) = dStressP[i] * dStressP[j]; tmpvalue = 0.; - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) tmpvalue += dStrainP[i] * dStressP[i]; *dGds_dFds /= tmpvalue; *TmpDe -= *dGds_dFds; //*PrinDe -= *dGds_dFds; //*TmpDe *= fkt1; - for(i=0; i=0 && P_64>=0) //return to sig2R + // else if(t3r2<=0) //return to sig2R + else if (P_63 >= 0 && P_64 >= 0) // return to sig2R { double tmpvalue = 0.; - //Matrix *dGds_dFds = new Matrix (Size,Size); - *dGds_dFds = (0.);//WX:08.2011 + // Matrix *dGds_dFds = new Matrix (Size,Size); + *dGds_dFds = (0.); // WX:08.2011 - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) { prin_str0[i] = prin_str[i]; prin_str[i] = sig2R[i]; dStressP[i] = prin_str[i] - prin_str0[i]; } - Inv_De->multi(dStressP,dStrainP); - for(i = 0; i < 3; i++) - for(j = 0; j < 3; j++) - (*dGds_dFds)(i,j) = dStressP[i] * dStressP[j]; + Inv_De->multi(dStressP, dStrainP); + for (i = 0; i < 3; i++) + for (j = 0; j < 3; j++) + (*dGds_dFds)(i, j) = dStressP[i] * dStressP[j]; tmpvalue = 0.; - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) tmpvalue += dStrainP[i] * dStressP[i]; *dGds_dFds /= tmpvalue; *TmpDe -= *dGds_dFds; //*PrinDe -= *dGds_dFds; //*TmpDe *= fkt1; - for(i=0; i 0) - ep += dlmd * sqrt(2.0 * TensorMutiplication2(dG_dS, - dG_dS, - dim) / 3.0); + if (subPLASTIC > 0) + ep += dlmd * sqrt(2.0 * TensorMutiplication2(dG_dS, dG_dS, dim) / 3.0); //------- Compute the consistent tangential matrix - if(Update <= 0 && subPLASTIC > 0) + if (Update <= 0 && subPLASTIC > 0) { //--- 1. Compute the inverse of the Jacobian - - for(j = 0; j < LocDim - 1; j++) + for (j = 0; j < LocDim - 1; j++) { - for(i = 0; i < LocDim; i++) + for (i = 0; i < LocDim; i++) { rhs_l[i] = 0.0; - if(i == j) + if (i == j) rhs_l[i] = 1.0; } // the i_th column of the invJac matrix Gauss_Back(LocDim, *LocalJacobi, rhs_l, Li, x_l); - for(i = 0; i < LocDim - 1; i++) + for (i = 0; i < LocDim - 1; i++) (*inv_Jac)(i, j) = x_l[i]; } //- 2. A*A*A*... - - if(subPLASTIC == 1) //First substep, which has plasticity + if (subPLASTIC == 1) // First substep, which has plasticity - for(i = 0; i < LocDim - 1; i++) - for(j = 0; j < LengthStrs; j++) - (*sumA_Matrix)(i, - j) = - (*inv_Jac)(i, j) * factor; + for (i = 0; i < LocDim - 1; i++) + for (j = 0; j < LengthStrs; j++) + (*sumA_Matrix)(i, j) = (*inv_Jac)(i, j) * factor; else { - for(i = 0; i < LocDim - 1; i++) - for(j = 0; j < LengthStrs; j++) - if(i == j) - (*sumA_Matrix)(i,j) += factor; + for (i = 0; i < LocDim - 1; i++) + for (j = 0; j < LengthStrs; j++) + if (i == j) + (*sumA_Matrix)(i, j) += factor; - LocalJacobi->LimitSize(LocDim - 1,LengthStrs); + LocalJacobi->LimitSize(LocDim - 1, LengthStrs); (*LocalJacobi) = 0.0; inv_Jac->multi(*sumA_Matrix, *LocalJacobi); - for(i = 0; i < LocDim - 1; i++) - for(j = 0; j < LengthStrs; j++) - (*sumA_Matrix)(i,j) = (*LocalJacobi)(i,j); + for (i = 0; i < LocDim - 1; i++) + for (j = 0; j < LengthStrs; j++) + (*sumA_Matrix)(i, j) = (*LocalJacobi)(i, j); LocalJacobi->LimitSize(LocDim, LocDim); } //- 3. D_ep - - if(iSub == preSub - 1) + if (iSub == preSub - 1) { - for(i = 0; i < LengthStrs; i++) - for(j = 0; j < LengthStrs; j++) + for (i = 0; i < LengthStrs; i++) + for (j = 0; j < LengthStrs; j++) { - (*D_ep)(i,j) = 0.0; - for(k = 0; k < LengthStrs; k++) - (*D_ep)(i,j) - += (*sumA_Matrix)(i, - k) * - (*De)(k,j); + (*D_ep)(i, j) = 0.0; + for (k = 0; k < LengthStrs; k++) + (*D_ep)(i, j) += (*sumA_Matrix)(i, k) * (*De)(k, j); } } } /// End Compute the consistent tangential matrix // Update the substep - for(i = 0; i < LengthStrs; i++) + for (i = 0; i < LengthStrs; i++) { Stress_n[i] = Stress_n1[i]; xi_n[i] = xi_n1[i]; } - for(i = 0; i < LengthStrs; i++) + for (i = 0; i < LengthStrs; i++) Mat_n[i] = Mat_n1[i]; - } // End of Compute stresses by substepping - } // If F>0.0 + } // End of Compute stresses by substepping + } // If F>0.0 // Save the current stresses - if(Update > 0) + if (Update > 0) { (*ele_val->pStrain)(GPiGPj) = ep; - //for(i=0; iStress)(i, GPiGPj) = Stress_n1[i]; - for(i = 0; i < LengthStrs - 1; i++) + for (i = 0; i < LengthStrs - 1; i++) (*ele_val->xi)(i, GPiGPj) = xi_n1[i]; - for(i = 0; i < LengthMat; i++) + for (i = 0; i < LengthMat; i++) (*ele_val->MatP)(i, GPiGPj) = Mat_n1[i]; } // else // { // New stresses passed through dStress for the residual computation - for(i = 0; i < LengthStrs; i++) + for (i = 0; i < LengthStrs; i++) dStress[i] = Stress_n1[i]; // } @@ -6059,10 +5854,7 @@ int CSolidProperties::CalStress_and_TangentialMatrix_SYS 02/2004 WW Modification for the 3D case 08/2004 WW Set as a member of CSolidProperties ***************************************************************************/ -void CSolidProperties::dF_dNStress(double* dFdS, - const double* DevS, - const double* S_Invariants, - const double* MatN1, +void CSolidProperties::dF_dNStress(double* dFdS, const double* DevS, const double* S_Invariants, const double* MatN1, const int LengthStrs) { int i; @@ -6073,47 +5865,46 @@ void CSolidProperties::dF_dNStress(double* dFdS, /* 1. Compute the derivatives of the yield function with respect to stresses */ /* 1.1 s_{jk}s_{ki} */ - if(LengthStrs == 4) // 2D + if (LengthStrs == 4) // 2D { // s11*s11+s12*s21 - dFdS[0] = DevS[0] * DevS[0] + DevS[3] * DevS[3]; + dFdS[0] = DevS[0] * DevS[0] + DevS[3] * DevS[3]; // s21*s12+s22*s22 - dFdS[1] = DevS[3] * DevS[3] + DevS[1] * DevS[1]; - dFdS[2] = DevS[2] * DevS[2]; // s33*s33 - // s11*s12+s12*s22 - dFdS[3] = DevS[0] * DevS[3] + DevS[3] * DevS[1]; + dFdS[1] = DevS[3] * DevS[3] + DevS[1] * DevS[1]; + dFdS[2] = DevS[2] * DevS[2]; // s33*s33 + // s11*s12+s12*s22 + dFdS[3] = DevS[0] * DevS[3] + DevS[3] * DevS[1]; } else { // s11*s11+s12*s21+s13*s31 - dFdS[0] = DevS[0] * DevS[0] + DevS[3] * DevS[3] + DevS[4] * DevS[4]; + dFdS[0] = DevS[0] * DevS[0] + DevS[3] * DevS[3] + DevS[4] * DevS[4]; // s21*s12+s22*s22+s23*s32 - dFdS[1] = DevS[3] * DevS[3] + DevS[1] * DevS[1] + DevS[5] * DevS[5]; + dFdS[1] = DevS[3] * DevS[3] + DevS[1] * DevS[1] + DevS[5] * DevS[5]; // s31*s13+s32*s23+s33*s33 - dFdS[2] = DevS[4] * DevS[4] + DevS[5] * DevS[5] + DevS[2] * DevS[2]; + dFdS[2] = DevS[4] * DevS[4] + DevS[5] * DevS[5] + DevS[2] * DevS[2]; // s11*s12+s12*s22+s13*s32 - dFdS[3] = DevS[0] * DevS[3] + DevS[3] * DevS[1] + DevS[4] * DevS[5]; + dFdS[3] = DevS[0] * DevS[3] + DevS[3] * DevS[1] + DevS[4] * DevS[5]; // s11*s13+s12*s23+s13*s33 - dFdS[4] = DevS[0] * DevS[4] + DevS[3] * DevS[5] + DevS[4] * DevS[2]; + dFdS[4] = DevS[0] * DevS[4] + DevS[3] * DevS[5] + DevS[4] * DevS[2]; // s21*s13+s22*s23+s23*s33 - dFdS[5] = DevS[3] * DevS[4] + DevS[1] * DevS[5] + DevS[5] * DevS[2]; + dFdS[5] = DevS[3] * DevS[4] + DevS[1] * DevS[5] + DevS[5] * DevS[2]; } /* 1.2 dtheta/ds*/ - for(i = 0; i < LengthStrs; i++) + for (i = 0; i < LengthStrs; i++) { dFdS[i] -= 1.5 * S_Invariants[2] * DevS[i] / S_Invariants[1]; - if(i < 3) + if (i < 3) dFdS[i] -= 2.0 * S_Invariants[1] / 3.0; dFdS[i] /= MathLib::fastpow(sqrt(S_Invariants[1]), 3); } /* 1.3 dF/ds .. */ - for(i = 0; i < LengthStrs; i++) + for (i = 0; i < LengthStrs; i++) { - dFdS[i] *= MatN1[5] * MatN1[6] * S_Invariants[1] * pow(1 + MatN1[5] * ang, - MatN1[6] - 1.0); + dFdS[i] *= MatN1[5] * MatN1[6] * S_Invariants[1] * pow(1 + MatN1[5] * ang, MatN1[6] - 1.0); dFdS[i] += pow(1 + MatN1[5] * ang, MatN1[6]) * DevS[i]; dFdS[i] /= (2 * PHI); - if(i < 3) + if (i < 3) { dFdS[i] += (MatN1[0] * In1 + 4.0 * MatN1[2] * MatN1[2] * I_p3) / (2 * PHI); dFdS[i] += MatN1[1] + 2.0 * MatN1[3] * In1; @@ -6144,10 +5935,7 @@ void CSolidProperties::dF_dNStress(double* dFdS, 02/2004 WW Modification for the 3D case 08/2004 WW Set as a member of CSolidProperties ***************************************************************************/ -void CSolidProperties::dF_dStress(double* dFdS, - const double* RotV, - const double* S_Invariants, - const double* MatN1, +void CSolidProperties::dF_dStress(double* dFdS, const double* RotV, const double* S_Invariants, const double* MatN1, const int LengthStrs) { int i; @@ -6155,9 +5943,9 @@ void CSolidProperties::dF_dStress(double* dFdS, double I_p3 = In1 * In1 * In1; double PHI = S_Invariants[4]; - for(i = 0; i < LengthStrs; i++) - dFdS[i] -= ((MatN1[0] * In1 + 4.0 * MatN1[2] * MatN1[2] * I_p3) / (2 * PHI) - + MatN1[1] + 2.0 * MatN1[3] * In1) * RotV[i]; + for (i = 0; i < LengthStrs; i++) + dFdS[i] -= ((MatN1[0] * In1 + 4.0 * MatN1[2] * MatN1[2] * I_p3) / (2 * PHI) + MatN1[1] + 2.0 * MatN1[3] * In1) + * RotV[i]; } /************************************************************************** @@ -6200,11 +5988,9 @@ void CSolidProperties::dF_dMat(double* dFdM, const double* S_Invariants, const d /*dF_dKappa*/ dFdM[4] = -1.0; /*dF_dGamma*/ - dFdM[5] = 0.5 * S_Invariants[1] * - MatN1[6]* ang* pow(1.0 + MatN1[5] * ang, MatN1[6] - 1.0) / PHI; + dFdM[5] = 0.5 * S_Invariants[1] * MatN1[6] * ang * pow(1.0 + MatN1[5] * ang, MatN1[6] - 1.0) / PHI; /*dF_dM*/ - dFdM[6] = 0.5 * S_Invariants[1] * pow(1.0 + MatN1[5] * ang, MatN1[6]) - * log(1.0 + MatN1[5] * ang) / PHI; + dFdM[6] = 0.5 * S_Invariants[1] * pow(1.0 + MatN1[5] * ang, MatN1[6]) * log(1.0 + MatN1[5] * ang) / PHI; } /************************************************************************** @@ -6230,10 +6016,7 @@ void CSolidProperties::dF_dMat(double* dFdM, const double* S_Invariants, const d 02/2004 WW Modification for the 3D case 08/2004 WW Set as a member of CSolidProperties ***************************************************************************/ -void CSolidProperties::dG_dNStress(double* dGdS, - const double* DevS, - const double* S_Invariants, - const double* MatN1, +void CSolidProperties::dG_dNStress(double* dGdS, const double* DevS, const double* S_Invariants, const double* MatN1, const int LengthStrs) { int i; @@ -6243,12 +6026,12 @@ void CSolidProperties::dG_dNStress(double* dGdS, double I_p3 = In1 * In1 * In1; double PSI = S_Invariants[5]; - for(i = 0; i < LengthStrs; i++) + for (i = 0; i < LengthStrs; i++) { dGdS[i] = 0.5 * DevS[i] / PSI / psi1; - if(i < 3) - dGdS[i] += 0.5 * (MatN1[0] * In1 + 4.0 * MatN1[2] * MatN1[2] * I_p3) / PSI - + (1.0 + psi2) * MatN1[1] + 2.0 * MatN1[3] * In1; + if (i < 3) + dGdS[i] += 0.5 * (MatN1[0] * In1 + 4.0 * MatN1[2] * MatN1[2] * I_p3) / PSI + (1.0 + psi2) * MatN1[1] + + 2.0 * MatN1[3] * In1; } } @@ -6278,9 +6061,9 @@ void CSolidProperties::dG_dNStress(double* dGdS, void CSolidProperties::dG__dNStress_dNStress(const double* DevS, const double* S_Invariants, const double* MatN1, - const int LengthStrs ) + const int LengthStrs) { - int i,j; + int i, j; int ii, jj, kk, ll; double delta_ij_kl; const double psi1 = (*data_Plasticity)(14); @@ -6290,63 +6073,58 @@ void CSolidProperties::dG__dNStress_dNStress(const double* DevS, double PSI = S_Invariants[5]; double PSI_p3 = S_Invariants[6]; - for(i = 0; i < LengthStrs; i++) + for (i = 0; i < LengthStrs; i++) { ii = i; jj = i; - if(i == 3) //s_12 + if (i == 3) // s_12 { ii = 1; jj = 2; } - //For 3D - else if(i == 4) //s_13 + // For 3D + else if (i == 4) // s_13 { ii = 1; jj = 3; } - else if(i == 5) //s_23 + else if (i == 5) // s_23 { ii = 2; jj = 3; } - for(j = 0; j < LengthStrs; j++) + for (j = 0; j < LengthStrs; j++) { kk = j; ll = j; - if(j == 3) + if (j == 3) { kk = 1; ll = 2; } - //For 3D - else if(j == 4) //s_13 + // For 3D + else if (j == 4) // s_13 { kk = 1; ll = 3; } - else if(j == 5) //s_23 + else if (j == 5) // s_23 { kk = 2; ll = 3; } - delta_ij_kl = Kronecker(ii,jj) * Kronecker(kk,ll); - //dG_dSdS[i*LengthStrs+j] = - (*d2G_dSdS)(i,j) = - 0.5 * - ((Kronecker(ii,kk) * Kronecker(jj,ll) - delta_ij_kl / 3.0) / psi1 - + (MatN1[0] + 12.0 * MatN1[2] * MatN1[2] * - I_p2) * delta_ij_kl) / PSI - - 0.25 * - (DevS[i] / psi1 + - (MatN1[0] * In1 + 4.0 * MatN1[2] * MatN1[2] * - I_p3) * Kronecker(ii,jj)) - * (DevS[j] / psi1 + - (MatN1[0] * In1 + 4.0 * MatN1[2] * MatN1[2] * - I_p3) * Kronecker(kk,ll)) / PSI_p3 - + 2.0 * MatN1[3] * delta_ij_kl; + delta_ij_kl = Kronecker(ii, jj) * Kronecker(kk, ll); + // dG_dSdS[i*LengthStrs+j] = + (*d2G_dSdS)(i, j) + = 0.5 * ((Kronecker(ii, kk) * Kronecker(jj, ll) - delta_ij_kl / 3.0) / psi1 + + (MatN1[0] + 12.0 * MatN1[2] * MatN1[2] * I_p2) * delta_ij_kl) + / PSI + - 0.25 * (DevS[i] / psi1 + (MatN1[0] * In1 + 4.0 * MatN1[2] * MatN1[2] * I_p3) * Kronecker(ii, jj)) + * (DevS[j] / psi1 + (MatN1[0] * In1 + 4.0 * MatN1[2] * MatN1[2] * I_p3) * Kronecker(kk, ll)) + / PSI_p3 + + 2.0 * MatN1[3] * delta_ij_kl; } } } @@ -6375,13 +6153,10 @@ void CSolidProperties::dG__dNStress_dNStress(const double* DevS, 02/2004 WW Extended to 3D 08/2004 WW Set as a member of CSolidProperties ***************************************************************************/ -void CSolidProperties::dG__dStress_dStress(const double* DevS, - const double* RotV, - const double* S_Invariants, - const double* MatN1, - const int LengthStrs) +void CSolidProperties::dG__dStress_dStress(const double* DevS, const double* RotV, const double* S_Invariants, + const double* MatN1, const int LengthStrs) { - int i,j; + int i, j; int ii, jj; const double psi1 = (*data_Plasticity)(14); double In1 = S_Invariants[0]; @@ -6390,39 +6165,33 @@ void CSolidProperties::dG__dStress_dStress(const double* DevS, double PSI = S_Invariants[5]; double PSI_p3 = S_Invariants[6]; - for(i = 0; i < LengthStrs; i++) + for (i = 0; i < LengthStrs; i++) { ii = i; jj = i; - if(i == 3) + if (i == 3) { ii = 1; jj = 2; } - //For 3D - else if(i == 4) //s_13 + // For 3D + else if (i == 4) // s_13 { ii = 1; jj = 3; } - else if(i == 5) //s_23 + else if (i == 5) // s_23 { ii = 2; jj = 3; } - for(j = 0; j < LengthStrs; j++) - (*d2G_dSdS)(i,j) -= - 0.5 * (MatN1[0] + 12.0 * MatN1[2] * MatN1[2] * I_p2) * Kronecker(ii, - jj) - * RotV[j] / PSI - - 0.25 * - (DevS[i] / psi1 + - (MatN1[0] * In1 + 4.0 * MatN1[2] * MatN1[2] * - I_p3) * Kronecker(ii,jj)) - * (MatN1[0] * In1 + 4.0 * MatN1[2] * MatN1[2] * - I_p3) * RotV[j] / PSI_p3 - + 2.0 * MatN1[3] * Kronecker(ii,jj) * RotV[j]; + for (j = 0; j < LengthStrs; j++) + (*d2G_dSdS)(i, j) + -= 0.5 * (MatN1[0] + 12.0 * MatN1[2] * MatN1[2] * I_p2) * Kronecker(ii, jj) * RotV[j] / PSI + - 0.25 * (DevS[i] / psi1 + (MatN1[0] * In1 + 4.0 * MatN1[2] * MatN1[2] * I_p3) * Kronecker(ii, jj)) + * (MatN1[0] * In1 + 4.0 * MatN1[2] * MatN1[2] * I_p3) * RotV[j] / PSI_p3 + + 2.0 * MatN1[3] * Kronecker(ii, jj) * RotV[j]; } } @@ -6472,48 +6241,44 @@ void CSolidProperties::dG_dSTress_dMat(const double* DevS, int ii, jj; double delta_ij; - for(i = 0; i < LengthStrs; i++) + for (i = 0; i < LengthStrs; i++) { ii = i; jj = i; - if(i == 3) + if (i == 3) { ii = 1; jj = 2; } - //For 3D - else if(i == 4) //s_13 + // For 3D + else if (i == 4) // s_13 { ii = 1; jj = 3; } - else if(i == 5) //s_23 + else if (i == 5) // s_23 { ii = 2; jj = 3; } - delta_ij = Kronecker(ii,jj); - //dG_dSdM[i*LengthStrs] //dG_dS_dAlpha - (*d2G_dSdM)(i,0) //dG_dS_dAlpha - = 0.5 * In1 * delta_ij / PSI - - 0.125 * - (DevS[i] / psi1 + - (MatN1[0] * In1 + 4.0 * MatN1[2] * MatN1[2] * I_p3) * delta_ij) - * I_p2 / PSI_p3; - //dG_dSdM[i*LengthStrs+1] //dG_dS_dBeta - (*d2G_dSdM)(i,1) //dG_dS_dBeta - = (1 + psi2) * delta_ij; - //dG_dSdM[i*LengthStrs+2] // dG_dS_dDelta - (*d2G_dSdM)(i,2) // dG_dS_dDelta - = 4.0 * MatN1[2] * I_p3 * delta_ij / PSI - - 0.5 * - (DevS[i] / psi1 + - (MatN1[0] * In1 + 4.0 * MatN1[2] * MatN1[2] * I_p3) * delta_ij) - * MatN1[2] * I_p4 / PSI_p3; - //dG_dSdM[i*LengthStrs+3] // dG_dS_dEpsilon - (*d2G_dSdM)(i,3) // dG_dS_dEpsilon - = 2.0 * In1 * delta_ij; + delta_ij = Kronecker(ii, jj); + // dG_dSdM[i*LengthStrs] //dG_dS_dAlpha + (*d2G_dSdM)(i, 0) // dG_dS_dAlpha + = 0.5 * In1 * delta_ij / PSI + - 0.125 * (DevS[i] / psi1 + (MatN1[0] * In1 + 4.0 * MatN1[2] * MatN1[2] * I_p3) * delta_ij) * I_p2 + / PSI_p3; + // dG_dSdM[i*LengthStrs+1] //dG_dS_dBeta + (*d2G_dSdM)(i, 1) // dG_dS_dBeta + = (1 + psi2) * delta_ij; + // dG_dSdM[i*LengthStrs+2] // dG_dS_dDelta + (*d2G_dSdM)(i, 2) // dG_dS_dDelta + = 4.0 * MatN1[2] * I_p3 * delta_ij / PSI + - 0.5 * (DevS[i] / psi1 + (MatN1[0] * In1 + 4.0 * MatN1[2] * MatN1[2] * I_p3) * delta_ij) * MatN1[2] + * I_p4 / PSI_p3; + // dG_dSdM[i*LengthStrs+3] // dG_dS_dEpsilon + (*d2G_dSdM)(i, 3) // dG_dS_dEpsilon + = 2.0 * In1 * delta_ij; } } @@ -6546,11 +6311,10 @@ void CSolidProperties::dG_dSTress_dMat(const double* DevS, 02/2004 WW Extended to 3D 08/2004 WW Set as a member of CSolidProperties ***************************************************************************/ -void CSolidProperties::dfun2(const double* DevS, - const double* RotV, const double* S_Invariants, - const double* MatN1, const int LengthStrs) +void CSolidProperties::dfun2(const double* DevS, const double* RotV, const double* S_Invariants, const double* MatN1, + const int LengthStrs) { - int i,j, l; + int i, j, l; int ii, jj, kk, ll; const double mr = (*data_Plasticity)(19); const double psi1 = (*data_Plasticity)(14); @@ -6561,86 +6325,75 @@ void CSolidProperties::dfun2(const double* DevS, double PSI_p3 = S_Invariants[6]; double var = sqrt(S_Invariants[1] / 3.0); l = 0; - for(i = 0; i < LengthStrs; i++) + for (i = 0; i < LengthStrs; i++) { // if(i<2) l = i*LengthStrs; - if(i == 2) - continue; // + if (i == 2) + continue; // // if(i>2) l = (i-1)*LengthStrs; ii = i; jj = i; - if(i == 3) + if (i == 3) { ii = 1; jj = 2; } - //For 3D - else if(i == 4) //s_13 + // For 3D + else if (i == 4) // s_13 { ii = 1; jj = 3; } - else if(i == 5) //s_23 + else if (i == 5) // s_23 { ii = 2; jj = 3; } - for(j = 0; j < LengthStrs; j++) + for (j = 0; j < LengthStrs; j++) { kk = j; ll = j; - if(j == 3) + if (j == 3) { kk = 1; ll = 2; } - //For 3D - else if(j == 4) //s_13 + // For 3D + else if (j == 4) // s_13 { kk = 1; ll = 3; } - else if(j == 5) //s_23 + else if (j == 5) // s_23 { kk = 2; ll = 3; } // Derivative with respect to normal stresses - (*d2G_dSdS)(l,j) = -( - (In1 * RotV[i] - mr * DevS[i]) * DevS[j] / (6.0 * var * PSI) - - 0.5 * var * (In1 * RotV[i] - mr * DevS[i]) - * (DevS[j] / psi1 + - (MatN1[0] * In1 + 4.0 * MatN1[2] * MatN1[2] * - I_p3) * Kronecker(kk,ll)) / PSI_p3 - + var * (RotV[i] * Kronecker(kk,ll) - - mr * - (Kronecker(ii, - kk) * - Kronecker(jj, - ll) - - Kronecker(ii,jj) * Kronecker(kk,ll) / 3.0)) / PSI); - - (*d2G_dSdS)(l,j) /= In1; - (*d2G_dSdS)(l, - j) -= 0.5 * - (In1 * RotV[i] - mr * - DevS[i]) * Kronecker(kk,ll) / (PSI * In1 * In1); - - if(j < 4) - (*d2G_dSdM)(l,j) = -In1 * (*d2G_dSdS)(i,j) / 3.0 - - var* In1* Kronecker(ii, - kk) * - Kronecker(jj,ll) / (PSI * In1); + (*d2G_dSdS)(l, j) = -( + (In1 * RotV[i] - mr * DevS[i]) * DevS[j] / (6.0 * var * PSI) + - 0.5 * var * (In1 * RotV[i] - mr * DevS[i]) + * (DevS[j] / psi1 + (MatN1[0] * In1 + 4.0 * MatN1[2] * MatN1[2] * I_p3) * Kronecker(kk, ll)) + / PSI_p3 + + var * (RotV[i] * Kronecker(kk, ll) + - mr * (Kronecker(ii, kk) * Kronecker(jj, ll) - Kronecker(ii, jj) * Kronecker(kk, ll) / 3.0)) + / PSI); + + (*d2G_dSdS)(l, j) /= In1; + (*d2G_dSdS)(l, j) -= 0.5 * (In1 * RotV[i] - mr * DevS[i]) * Kronecker(kk, ll) / (PSI * In1 * In1); + + if (j < 4) + (*d2G_dSdM)(l, j) + = -In1 * (*d2G_dSdS)(i, j) / 3.0 - var * In1 * Kronecker(ii, kk) * Kronecker(jj, ll) / (PSI * In1); // Derivative with respect to stresses - (*d2G_dSdS)(l,j) += - -0.5 * var * (In1 * RotV[i] - mr * DevS[i]) - * (MatN1[0] * In1 + 4.0 * MatN1[2] * MatN1[2] * - I_p3) * RotV[j] / PSI_p3 + var * RotV[i] * RotV[j] / PSI - + 0.5 * (In1 * RotV[i] - mr * DevS[i]) * RotV[j] / (PSI * In1 * In1); + (*d2G_dSdS)(l, j) += -0.5 * var * (In1 * RotV[i] - mr * DevS[i]) + * (MatN1[0] * In1 + 4.0 * MatN1[2] * MatN1[2] * I_p3) * RotV[j] / PSI_p3 + + var * RotV[i] * RotV[j] / PSI + + 0.5 * (In1 * RotV[i] - mr * DevS[i]) * RotV[j] / (PSI * In1 * In1); } } } @@ -6664,33 +6417,33 @@ void CSolidProperties::dfun2(const double* DevS, 08/2003 WW Erste Version 08/2004 WW Set as a member of CSolidProperties ***************************************************************************/ -void CSolidProperties::Gauss_Elimination(const int DimE, Matrix& AA, int* L, double* xx) +void CSolidProperties::Gauss_Elimination(const int DimE, Matrix& AA, int* L, double* xx) { - int i,j, k, jj, lk; + int i, j, k, jj, lk; double var, R; - for(i = 0; i < DimE; i++) + for (i = 0; i < DimE; i++) { L[i] = i; var = 0.0; - for(j = 0; j < DimE; j++) + for (j = 0; j < DimE; j++) { - if(fabs(AA(i,j)) > var) - var = fabs(AA(i,j)); + if (fabs(AA(i, j)) > var) + var = fabs(AA(i, j)); L[i] = i; } xx[i] = var; } - for(k = 0; k < DimE - 1; k++) + for (k = 0; k < DimE - 1; k++) { var = 0.0; jj = 0; - for(i = k; i < DimE; i++) + for (i = k; i < DimE; i++) { R = fabs(AA(L[i], k) / xx[L[i]]); - if(R > var) + if (R > var) { jj = i; var = R; @@ -6700,12 +6453,12 @@ void CSolidProperties::Gauss_Elimination(const int DimE, Matrix& AA, int* L, do L[jj] = L[k]; L[k] = lk; - for(i = k + 1; i < DimE; i++) + for (i = k + 1; i < DimE; i++) { var = AA(L[i], k) / AA(lk, k); - for(j = k + 1; j < DimE; j++) - AA(L[i],j) -= var * AA(lk, j); + for (j = k + 1; j < DimE; j++) + AA(L[i], j) -= var * AA(lk, j); AA(L[i], k) = var; } } @@ -6713,19 +6466,19 @@ void CSolidProperties::Gauss_Elimination(const int DimE, Matrix& AA, int* L, do void CSolidProperties::Gauss_Back(const int DimE, Matrix& AA, double* rhs, int* L, double* xx) { - int i,j, k; + int i, j, k; double var; /* Back substituting */ - for(k = 0; k < DimE - 1; k++) - for(i = k + 1; i < DimE; i++) + for (k = 0; k < DimE - 1; k++) + for (i = k + 1; i < DimE; i++) rhs[L[i]] -= AA(L[i], k) * rhs[L[k]]; xx[DimE - 1] = rhs[L[DimE - 1]] / AA(L[DimE - 1], DimE - 1); - for(i = DimE - 2; i >= 0; i--) + for (i = DimE - 2; i >= 0; i--) { var = rhs[L[i]]; - for(j = i + 1; j < DimE; j++) + for (j = i + 1; j < DimE; j++) var -= AA(L[i], j) * xx[j]; xx[i] = var / AA(L[i], i); } @@ -6761,11 +6514,8 @@ void CSolidProperties::Gauss_Back(const int DimE, Matrix& AA, double* rhs, int* **************************************************************************/ //#define New #define associative -void CSolidProperties::CalStress_and_TangentialMatrix_CC(const int GPiGPj, - const ElementValue_DM* ele_val, - double* dStrain, - Matrix* Dep, - const int Update) +void CSolidProperties::CalStress_and_TangentialMatrix_CC(const int GPiGPj, const ElementValue_DM* ele_val, + double* dStrain, Matrix* Dep, const int Update) { int i, ns; double p, q, p_tr, q_tr, p_c, p_cn; @@ -6773,11 +6523,11 @@ void CSolidProperties::CalStress_and_TangentialMatrix_CC(const int GPiGPj, double e_0, dev; double F0, F, vep, vep0, TolP; double var1, alpha1, alpha2, beta1, beta2; - double gamma1, gamma2,gamma3,gamma4,gamma5; + double gamma1, gamma2, gamma3, gamma4, gamma5; double dfdp, dfdq, dampFac; const double fac = sqrt(2.0 / 3.0); #ifdef New - double J11,J12, J21, J22; + double J11, J12, J21, J22; #else double alpha3, Jac; #endif @@ -6798,12 +6548,12 @@ void CSolidProperties::CalStress_and_TangentialMatrix_CC(const int GPiGPj, int dim = 2; ns = 4; - if(Dep->Cols() > 4) + if (Dep->Cols() > 4) { dim = 3; ns = 6; } - bool isLoop = true; // Used only to avoid warnings with .net + bool isLoop = true; // Used only to avoid warnings with .net // Get the total effective plastic strain ep = (*ele_val->pStrain)(GPiGPj); @@ -6814,23 +6564,21 @@ void CSolidProperties::CalStress_and_TangentialMatrix_CC(const int GPiGPj, // Get the void ratio of the previous time step e_0 = (*ele_val->e_i)(GPiGPj); - p = -( (*ele_val->Stress)(0,GPiGPj) - + (*ele_val->Stress)(1,GPiGPj) - + (*ele_val->Stress)(2,GPiGPj)) / 3.0; + p = -((*ele_val->Stress)(0, GPiGPj) + (*ele_val->Stress)(1, GPiGPj) + (*ele_val->Stress)(2, GPiGPj)) / 3.0; - if(fabs(p) < pmin) + if (fabs(p) < pmin) p = pmin; // Volume strain increment dev = -(dStrain[0] + dStrain[1] + dStrain[2]); - //TEST. Sign? + // TEST. Sign? vartheta = (1.0 + e_0) / (CompressIndex - SwellIndex); // if(fabs(dev)multi(dStrain, TryStress); - for(i = 0; i < ns; i++) + for (i = 0; i < ns; i++) { - TryStress[i] += (*ele_val->Stress)(i,GPiGPj); + TryStress[i] += (*ele_val->Stress)(i, GPiGPj); DevStress[i] = TryStress[i]; } @@ -6871,25 +6619,25 @@ void CSolidProperties::CalStress_and_TangentialMatrix_CC(const int GPiGPj, NPStep = 0; F0 = F; - if(pcs_deformation == 1) + if (pcs_deformation == 1) F = -1.0; - if((*data_Plasticity)(3) < MKleinsteZahl) // p_c0=0 + if ((*data_Plasticity)(3) < MKleinsteZahl) // p_c0=0 F = -1.0; - //TEST CAM-CLAY - if(p_tr < 0) + // TEST CAM-CLAY + if (p_tr < 0) F = -1.0; - if(F > 0.0 && !PreLoad) // in yield status + if (F > 0.0 && !PreLoad) // in yield status { // Local Newton-Raphson procedure to compute the volume plastic strain vep = 0.0; #ifdef associative #ifdef New - //Associative flow rule - while(isLoop) // Newton step for the plastic multiplier + // Associative flow rule + while (isLoop) // Newton step for the plastic multiplier { NPStep++; - if(NPStep > MaxI) + if (NPStep > MaxI) // printf("\n Too much iteration in Newton step in the integration of Cam-Clay \n"); break; // abort(); @@ -6911,9 +6659,9 @@ void CSolidProperties::CalStress_and_TangentialMatrix_CC(const int GPiGPj, F = q * q / M2 + p * (p - p_c); beta1 = gamma2 - p_c; // g; - if(fabs(beta1) < TolP) + if (fabs(beta1) < TolP) // if(fabs(F) MaxI) + if (NPStep > MaxI) // printf("\n Too much iteration in Newton step the integration of Cam-Clay \n"); - //TEST abort(); - //test + // TEST abort(); + // test break; // alpha1 = vartheta * vep / (1.0 + 2.0 * vep * K); alpha2 = p_cn * exp(alpha1 * (2.0 * p_tr - p_c)); - beta1 = -alpha1 * alpha2 - 1.0; //dG(p_c) - alpha2 -= p_c; //G(p_c) + beta1 = -alpha1 * alpha2 - 1.0; // dG(p_c) + alpha2 -= p_c; // G(p_c) p_c -= alpha2 / beta1; - if(fabs(alpha2) < TolP) + if (fabs(alpha2) < TolP) break; - if(p_c < 0.0) + if (p_c < 0.0) break; } @@ -6971,14 +6718,14 @@ void CSolidProperties::CalStress_and_TangentialMatrix_CC(const int GPiGPj, q = q_tr / (1.0 + 6.0 * G * vep / M2); F = q * q / M2 + p * (p - p_c); - if(F > 0.0) + if (F > 0.0) break; - if(fabs(F / F0) < TolP) + if (fabs(F / F0) < TolP) break; dampFac = 0.8; } vep0 = vep; - if(fabs(F / F0) < TolP) + if (fabs(F / F0) < TolP) break; } #endif @@ -6989,13 +6736,12 @@ void CSolidProperties::CalStress_and_TangentialMatrix_CC(const int GPiGPj, #else // ifdef associative double var2 = 0.0; - while(1) + while (1) { NPStep++; - if(NPStep > MaxI) + if (NPStep > MaxI) { - printf( - "\n Too much iteration in Newton step in the integration of Cam-Clay \n"); + printf("\n Too much iteration in Newton step in the integration of Cam-Clay \n"); abort(); } @@ -7004,14 +6750,13 @@ void CSolidProperties::CalStress_and_TangentialMatrix_CC(const int GPiGPj, dfdp = 2.0 * p - p_c; dfdq = 2.0 * q / M2; Jac = -K * dfdp // dF/dp * dp/dv - - dfdq * q_tr * (K + 0.5 * p_c * vartheta * var1) - / (p_tr - 0.5 * p_c) //dF/dq * dq/dv + - dfdq * q_tr * (K + 0.5 * p_c * vartheta * var1) / (p_tr - 0.5 * p_c) // dF/dq * dq/dv - p * vartheta * p_c; // df/dp_c * dp_c/dv - //Update + // Update dampFac = 1.0; - while(1) + while (1) { vep = vep0 - dampFac * F / Jac; @@ -7020,16 +6765,16 @@ void CSolidProperties::CalStress_and_TangentialMatrix_CC(const int GPiGPj, q = q_tr * (p - 0.5 * p_c) / (p_tr - 0.5 * p_c); F = q * q / M2 + p * (p - p_c); - if(F > 0.0) + if (F > 0.0) break; - //if(fabs(F)/RF0 0) + if (Update > 0) { - if((*data_Plasticity)(3) < MKleinsteZahl) // p_c0=0 + if ((*data_Plasticity)(3) < MKleinsteZahl) // p_c0=0 { p_c = p + q * q / (M2 * p); (*ele_val->prep0)(GPiGPj) = p_c; } - if(ep > 0.0) + if (ep > 0.0) { var1 = dev * (1. + e_0); e_0 -= var1; @@ -7239,11 +6983,8 @@ void CSolidProperties::CalStress_and_TangentialMatrix_CC(const int GPiGPj, Programmaenderungen: 06/2008 WW Programming **************************************************************************/ -void CSolidProperties::CalStress_and_TangentialMatrix_CC_SubStep(const int GPiGPj, - const ElementValue_DM* ele_val, - double* dStrain, - Matrix* Dep, - const int Update) +void CSolidProperties::CalStress_and_TangentialMatrix_CC_SubStep(const int GPiGPj, const ElementValue_DM* ele_val, + double* dStrain, Matrix* Dep, const int Update) { int i, ns; double p, q, p_tr, q_tr, p_c, p_cn; @@ -7251,7 +6992,7 @@ void CSolidProperties::CalStress_and_TangentialMatrix_CC_SubStep(const int GPiGP double e_0, dev; double F0, F, vep, vep0; double var1, alpha1, alpha2, beta1, beta2; - double gamma1, gamma2,gamma3,gamma4,gamma5; + double gamma1, gamma2, gamma3, gamma4, gamma5; double dfdp, dfdq, dampFac; const double fac = sqrt(2.0 / 3.0); double alpha3, Jac; @@ -7278,12 +7019,12 @@ void CSolidProperties::CalStress_and_TangentialMatrix_CC_SubStep(const int GPiGP // int dim = 2; ns = 4; - if(Dep->Cols() > 4) + if (Dep->Cols() > 4) { dim = 3; ns = 6; } - bool isLoop = true; // Used only to avoid warnings with .net + bool isLoop = true; // Used only to avoid warnings with .net // Get the total effective plastic strain ep = (*ele_val->pStrain)(GPiGPj); @@ -7295,60 +7036,60 @@ void CSolidProperties::CalStress_and_TangentialMatrix_CC_SubStep(const int GPiGP e_0 = (*ele_val->e_i)(GPiGPj); // Stress of previous load step dev = -(dStrain[0] + dStrain[1] + dStrain[2]); - for(i = 0; i < ns; i++) + for (i = 0; i < ns; i++) { - TryStress[i] = (*ele_val->Stress)(i,GPiGPj); + TryStress[i] = (*ele_val->Stress)(i, GPiGPj); dStress0[i] = dStress1[i] = 0.; } - //TEST + // TEST int test_c = 0; // Begin substeps - //WW bool OK = true; //OK411 - for(;; ) //WW while(OK) + // WW bool OK = true; //OK411 + for (;;) // WW while(OK) { /* if(test_c>2) test_c = test_c; */ - //TEST + // TEST test_c++; - //if(test_c>20) + // if(test_c>20) // test_c = test_c; - if(test_c > 100) + if (test_c > 100) break; - for(int kk = 0; kk < 2; kk++) + for (int kk = 0; kk < 2; kk++) { double* dsig = NULL; double de_vsw = 0.; - if(kk == 0) + if (kk == 0) { dsig = dStress0; - for(i = 0; i < ns; i++) + for (i = 0; i < ns; i++) dsig[i] = TryStress[i]; } else { dsig = dStress1; - for(i = 0; i < ns; i++) + for (i = 0; i < ns; i++) dsig[i] = TryStress[i] + dStress0[0]; } - p = -( dsig[0] + dsig[1] + dsig[2]) / 3.0; - if(fabs(p) < pmin) + p = -(dsig[0] + dsig[1] + dsig[2]) / 3.0; + if (fabs(p) < pmin) p = pmin; // Volume strain increment vartheta = (1.0 + e_0) / (CompressIndex - SwellIndex); // if(fabs(dev)multi(dStrain, dsig, sub_step); // Recover strain increment - if(SwellingPressureType == 3) - for(i = 0; i < 3; i++) + if (SwellingPressureType == 3) + for (i = 0; i < 3; i++) dStrain[i] -= de_vsw; } // Stress estimation // double norm_ds = 0.; // double norm_s = 0.; - for(i = 0; i < ns; i++) + for (i = 0; i < ns; i++) { TryStress[i] += 0.5 * (dStress0[i] + dStress1[i]); - //DevStress as temporary buffer + // DevStress as temporary buffer DevStress[i] = dStress0[i] - dStress1[i]; } double norms = StressNorm(TryStress, dim); double q_f = 1.0; double R_n = 1.0; - if(norms > DBL_EPSILON) + if (norms > DBL_EPSILON) { R_n = 0.5 * StressNorm(DevStress, dim) / norms; - if(R_n > DBL_EPSILON) + if (R_n > DBL_EPSILON) q_f = 0.95 * sqrt(s_tol / R_n); } else R_n = 0.0; - if(q_f < 0.2) + if (q_f < 0.2) q_f = 0.2; - if(q_f > 1.2) + if (q_f > 1.2) q_f = 1.2; sub_step *= q_f; - if((sub_step_sum + sub_step) > 1.0) + if ((sub_step_sum + sub_step) > 1.0) sub_step = 1.0 - sub_step_sum; // Ckeck convergence - if(R_n < s_tol) //accepted + if (R_n < s_tol) // accepted sub_step_sum += sub_step; else { - for(i = 0; i < ns; i++) + for (i = 0; i < ns; i++) TryStress[i] -= 0.5 * (dStress0[i] + dStress1[i]); continue; } // - for(i = 0; i < ns; i++) + for (i = 0; i < ns; i++) DevStress[i] = TryStress[i]; p_tr = -DeviatoricStress(DevStress) / 3.0; @@ -7427,21 +7168,21 @@ void CSolidProperties::CalStress_and_TangentialMatrix_CC_SubStep(const int GPiGP NPStep = 0; F0 = F; - if(pcs_deformation == 1) + if (pcs_deformation == 1) F = -1.0; - if((*data_Plasticity)(3) < MKleinsteZahl) // p_c0=0 + if ((*data_Plasticity)(3) < MKleinsteZahl) // p_c0=0 F = -1.0; - //TEST CAM-CLAY - if(p_tr < 0) + // TEST CAM-CLAY + if (p_tr < 0) F = -1.0; - if(F > f_tol && !PreLoad) // in yield status + if (F > f_tol && !PreLoad) // in yield status { // Local Newton-Raphson procedure to compute the volume plastic strain vep = 0.0; - //Associative flow rule - while(isLoop) // Newton step for the plastic multiplier + // Associative flow rule + while (isLoop) // Newton step for the plastic multiplier { NPStep++; @@ -7455,30 +7196,30 @@ void CSolidProperties::CalStress_and_TangentialMatrix_CC_SubStep(const int GPiGP Jac = alpha1 * dfdp + dfdq * alpha2 - p * alpha3; - while(isLoop) // Damp + while (isLoop) // Damp { vep = vep0 - dampFac * F / Jac; p_c = 0.0; dampFac = 1.0; - while(isLoop) // Newton step for p_c + while (isLoop) // Newton step for p_c { NPStep++; - if(NPStep > MaxI) + if (NPStep > MaxI) // printf("\n Too much iteration in Newton step the integration of Cam-Clay \n"); - //TEST abort(); - //test + // TEST abort(); + // test break; // alpha1 = vartheta * vep / (1.0 + 2.0 * vep * K); alpha2 = p_cn * exp(alpha1 * (2.0 * p_tr - p_c)); - beta1 = -alpha1 * alpha2 - 1.0; //dG(p_c) - alpha2 -= p_c; //G(p_c) + beta1 = -alpha1 * alpha2 - 1.0; // dG(p_c) + alpha2 -= p_c; // G(p_c) p_c -= alpha2 / beta1; - if(fabs(alpha2) < s_tol) + if (fabs(alpha2) < s_tol) break; - if(p_c < 0.0) + if (p_c < 0.0) break; } @@ -7486,40 +7227,40 @@ void CSolidProperties::CalStress_and_TangentialMatrix_CC_SubStep(const int GPiGP q = q_tr / (1.0 + 6.0 * G * vep / M2); F = q * q / M2 + p * (p - p_c); - if(F > 0.0) + if (F > 0.0) break; - if(fabs(F / F0) < s_tol) + if (fabs(F / F0) < s_tol) break; dampFac = 0.8; } vep0 = vep; - if(fabs(F / F0) < s_tol) + if (fabs(F / F0) < s_tol) break; } } - //End substep + // End substep // Plastic strain // alpha1 = 6.0*q*q/(M2*M2*(2.0*p-p_c)*(2.0*p-p_c)); // ep += fabs(vep)*sqrt(2.0*(1.0/9.0+alpha1)/3.0); ep += 3.0 * fabs(vep) * q / M2; - if(fabs(sub_step_sum - 1.0) < DBL_EPSILON) + if (fabs(sub_step_sum - 1.0) < DBL_EPSILON) break; } //------------------------------------------------------------- // Consistent tangential matrix - if(Update < 1 && NPStep > 0) + if (Update < 1 && NPStep > 0) { - alpha1 = 1.0 + 2.0 * K * vep + p_c * vartheta * vep; //a - //a1 + alpha1 = 1.0 + 2.0 * K * vep + p_c * vartheta * vep; // a + // a1 double a1 = (1.0 + p_c * vartheta * vep) / alpha1; - double a2 = -(2.0 * p - p_c) / alpha1; //a2 - double a3 = 2.0 * p_c * vartheta * vep / alpha1; //a3 - //a4 + double a2 = -(2.0 * p - p_c) / alpha1; // a2 + double a3 = 2.0 * p_c * vartheta * vep / alpha1; // a3 + // a4 double a4 = vartheta * p_c * (2.0 * p - p_c) / (K * alpha1); - double a5 = sqrt(1.5) / (1.0 + 6.0 * G * vep / M2); //a5 - //a6 - double a6 = -3.0 * q / (1.0 + 6.0 * G * vep / M2) / M2; + double a5 = sqrt(1.5) / (1.0 + 6.0 * G * vep / M2); // a5 + // a6 + double a6 = -3.0 * q / (1.0 + 6.0 * G * vep / M2) / M2; alpha1 = -4.0 * G * q * a6 / M2 - K * ((2.0 * a2 - a4) * p - a2 * p_c); double b1 = -K * ((a3 - 2.0 * a1) * p + a1 * p_c) / alpha1; @@ -7532,7 +7273,7 @@ void CSolidProperties::CalStress_and_TangentialMatrix_CC_SubStep(const int GPiGP gamma5 = 2.0 * G * fac * (a5 + a6 * b2) - gamma1; // // Normalize the stress - for(i = 0; i < ns; i++) + for (i = 0; i < ns; i++) { TryStress[i] = DevStress[i]; TryStress[i] /= q_tr * fac; @@ -7541,103 +7282,103 @@ void CSolidProperties::CalStress_and_TangentialMatrix_CC_SubStep(const int GPiGP // Row 1 beta1 = gamma2 + gamma4 * TryStress[0]; beta2 = gamma3 + gamma5 * TryStress[0]; - (*Dep)(0,0) = gamma1 + beta1 + beta2 * TryStress[0]; - (*Dep)(0,1) = beta1 + beta2 * TryStress[1]; - (*Dep)(0,2) = beta1 + beta2 * TryStress[2]; - (*Dep)(0,3) = beta2 * TryStress[3]; - if(dim == 3) + (*Dep)(0, 0) = gamma1 + beta1 + beta2 * TryStress[0]; + (*Dep)(0, 1) = beta1 + beta2 * TryStress[1]; + (*Dep)(0, 2) = beta1 + beta2 * TryStress[2]; + (*Dep)(0, 3) = beta2 * TryStress[3]; + if (dim == 3) { - (*Dep)(0,4) = beta2 * TryStress[4]; - (*Dep)(0,5) = beta2 * TryStress[5]; + (*Dep)(0, 4) = beta2 * TryStress[4]; + (*Dep)(0, 5) = beta2 * TryStress[5]; } // Row 2 beta1 = gamma2 + gamma4 * TryStress[1]; beta2 = gamma3 + gamma5 * TryStress[1]; - (*Dep)(1,0) = beta1 + beta2 * TryStress[0]; - (*Dep)(1,1) = gamma1 + beta1 + beta2 * TryStress[1]; - (*Dep)(1,2) = beta1 + beta2 * TryStress[2]; - (*Dep)(1,3) = beta2 * TryStress[3]; - if(dim == 3) + (*Dep)(1, 0) = beta1 + beta2 * TryStress[0]; + (*Dep)(1, 1) = gamma1 + beta1 + beta2 * TryStress[1]; + (*Dep)(1, 2) = beta1 + beta2 * TryStress[2]; + (*Dep)(1, 3) = beta2 * TryStress[3]; + if (dim == 3) { - (*Dep)(1,4) = beta2 * TryStress[4]; - (*Dep)(1,5) = beta2 * TryStress[5]; + (*Dep)(1, 4) = beta2 * TryStress[4]; + (*Dep)(1, 5) = beta2 * TryStress[5]; } // Row 3 beta1 = gamma2 + gamma4 * TryStress[2]; beta2 = gamma3 + gamma5 * TryStress[2]; - (*Dep)(2,0) = beta1 + beta2 * TryStress[0]; - (*Dep)(2,1) = beta1 + beta2 * TryStress[1]; - (*Dep)(2,2) = gamma1 + beta1 + beta2 * TryStress[2]; - (*Dep)(2,3) = beta2 * TryStress[3]; - if(dim == 3) + (*Dep)(2, 0) = beta1 + beta2 * TryStress[0]; + (*Dep)(2, 1) = beta1 + beta2 * TryStress[1]; + (*Dep)(2, 2) = gamma1 + beta1 + beta2 * TryStress[2]; + (*Dep)(2, 3) = beta2 * TryStress[3]; + if (dim == 3) { - (*Dep)(2,4) = beta2 * TryStress[4]; - (*Dep)(2,5) = beta2 * TryStress[5]; + (*Dep)(2, 4) = beta2 * TryStress[4]; + (*Dep)(2, 5) = beta2 * TryStress[5]; } // Row 4 beta1 = gamma4 * TryStress[3]; beta2 = gamma5 * TryStress[3]; - (*Dep)(3,0) = beta1 + beta2 * TryStress[0]; - (*Dep)(3,1) = beta1 + beta2 * TryStress[1]; - (*Dep)(3,2) = beta1 + beta2 * TryStress[2]; - (*Dep)(3,3) = gamma1 + beta2 * TryStress[3]; - if(dim == 3) + (*Dep)(3, 0) = beta1 + beta2 * TryStress[0]; + (*Dep)(3, 1) = beta1 + beta2 * TryStress[1]; + (*Dep)(3, 2) = beta1 + beta2 * TryStress[2]; + (*Dep)(3, 3) = gamma1 + beta2 * TryStress[3]; + if (dim == 3) { - (*Dep)(3,4) = beta2 * TryStress[4]; - (*Dep)(3,5) = beta2 * TryStress[5]; + (*Dep)(3, 4) = beta2 * TryStress[4]; + (*Dep)(3, 5) = beta2 * TryStress[5]; // End row 4 // Row 5 beta1 = gamma4 * TryStress[4]; beta2 = gamma5 * TryStress[4]; - (*Dep)(4,0) = beta1 + beta2 * TryStress[0]; - (*Dep)(4,1) = beta1 + beta2 * TryStress[1]; - (*Dep)(4,2) = beta1 + beta2 * TryStress[2]; - (*Dep)(4,3) = beta2 * TryStress[3]; - (*Dep)(4,4) = gamma1 + beta2 * TryStress[4]; - (*Dep)(4,5) = beta2 * TryStress[5]; + (*Dep)(4, 0) = beta1 + beta2 * TryStress[0]; + (*Dep)(4, 1) = beta1 + beta2 * TryStress[1]; + (*Dep)(4, 2) = beta1 + beta2 * TryStress[2]; + (*Dep)(4, 3) = beta2 * TryStress[3]; + (*Dep)(4, 4) = gamma1 + beta2 * TryStress[4]; + (*Dep)(4, 5) = beta2 * TryStress[5]; // Row 6 beta1 = gamma4 * TryStress[5]; beta2 = gamma5 * TryStress[5]; - (*Dep)(5,0) = beta1 + beta2 * TryStress[0]; - (*Dep)(5,1) = beta1 + beta2 * TryStress[1]; - (*Dep)(5,2) = beta1 + beta2 * TryStress[2]; - (*Dep)(5,3) = beta2 * TryStress[3]; - (*Dep)(5,4) = beta2 * TryStress[4]; - (*Dep)(5,5) = gamma1 + beta2 * TryStress[5]; + (*Dep)(5, 0) = beta1 + beta2 * TryStress[0]; + (*Dep)(5, 1) = beta1 + beta2 * TryStress[1]; + (*Dep)(5, 2) = beta1 + beta2 * TryStress[2]; + (*Dep)(5, 3) = beta2 * TryStress[3]; + (*Dep)(5, 4) = beta2 * TryStress[4]; + (*Dep)(5, 5) = gamma1 + beta2 * TryStress[5]; } //------------------------------------------------------------- // Update stresses - for(i = 0; i < ns; i++) + for (i = 0; i < ns; i++) { DevStress[i] /= 1.0 + 6.0 * G * vep / M2; TryStress[i] = DevStress[i]; } // True stress - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) TryStress[i] -= p; } - else if(Update < 1) + else if (Update < 1) ElasticConsitutive(dim, Dep); - for(i = 0; i < ns; i++) + for (i = 0; i < ns; i++) dStrain[i] = TryStress[i]; // Save the current stresses - if(Update > 0) + if (Update > 0) { - if((*data_Plasticity)(3) < MKleinsteZahl) // p_c0=0 + if ((*data_Plasticity)(3) < MKleinsteZahl) // p_c0=0 { p_c = p + q * q / (M2 * p); (*ele_val->prep0)(GPiGPj) = p_c; } - if(ep > 0.0) + if (ep > 0.0) { var1 = dev * (1. + e_0); e_0 -= var1; @@ -7662,44 +7403,45 @@ void CSolidProperties::CalStress_and_TangentialMatrix_CC_SubStep(const int GPiGP 12/2005 WW last modified: **************************************************************************/ -void CSolidProperties::AddStain_by_Creep(const int ns, double* stress_n, - double* dstrain, double temperature) +void CSolidProperties::AddStain_by_Creep(const int ns, double* stress_n, double* dstrain, double temperature) { int i, dim; double norn_S, fac = 0.0; DeviatoricStress(stress_n); dim = 2; - if(ns > 4) + if (ns > 4) dim = 3; norn_S = sqrt(3.0 * TensorMutiplication2(stress_n, stress_n, dim) / 2.0); - if(norn_S < DBL_MIN) + if (norn_S < DBL_MIN) return; - switch(Creep_mode) + switch (Creep_mode) { - case 1: - // fac = pow(1.5, (*data_Creep)(1)+1.0)*(*data_Creep)(0)*pow(norn_S, (*data_Creep)(1)-1.0)*dt; - // fac = pow(2.0/3.0, (*data_Creep)(1))*(*data_Creep)(0)*pow(norn_S, (*data_Creep)(1))*dt; - fac = (*data_Creep)(0) * pow(norn_S, (*data_Creep)(1)) * dt; - break; - case 2: - // gas constant = R = 8.314472(15) J ?K-1 ?mol-1 - // ec= A*exp(-G/RT)s^n - fac = 1.5 * dt * (*data_Creep)(0) * - exp(-(*data_Creep)(2) / (8.314472 * (temperature + 273.15))) * - pow(norn_S, (*data_Creep)(1)); - break; - //TN: BGRb - case 3: - fac = 1.5*dt*((*data_Creep)(0)*exp(-(*data_Creep)(2)/(8.314472*(temperature+273.15)))*pow(norn_S, (*data_Creep)(1))+ - (*data_Creep)(3)*exp(-(*data_Creep)(5)/(8.314472*(temperature+273.15)))*pow(norn_S, (*data_Creep)(4))); - break; - //TN: BGRsf - case 4: - fac = 1.5*dt*((*data_Creep)(0)*exp(-(*data_Creep)(2)/(8.314472*(temperature+273.15)))* - pow(norn_S, (*data_Creep)(1))+(*data_Creep)(4)*pow(norn_S, 2)); - break; + case 1: + // fac = pow(1.5, (*data_Creep)(1)+1.0)*(*data_Creep)(0)*pow(norn_S, (*data_Creep)(1)-1.0)*dt; + // fac = pow(2.0/3.0, (*data_Creep)(1))*(*data_Creep)(0)*pow(norn_S, (*data_Creep)(1))*dt; + fac = (*data_Creep)(0) * pow(norn_S, (*data_Creep)(1)) * dt; + break; + case 2: + // gas constant = R = 8.314472(15) J ?K-1 ?mol-1 + // ec= A*exp(-G/RT)s^n + fac = 1.5 * dt * (*data_Creep)(0) * exp(-(*data_Creep)(2) / (8.314472 * (temperature + 273.15))) + * pow(norn_S, (*data_Creep)(1)); + break; + // TN: BGRb + case 3: + fac = 1.5 * dt * ((*data_Creep)(0) * exp(-(*data_Creep)(2) / (8.314472 * (temperature + 273.15))) + * pow(norn_S, (*data_Creep)(1)) + + (*data_Creep)(3) * exp(-(*data_Creep)(5) / (8.314472 * (temperature + 273.15))) + * pow(norn_S, (*data_Creep)(4))); + break; + // TN: BGRsf + case 4: + fac = 1.5 * dt * ((*data_Creep)(0) * exp(-(*data_Creep)(2) / (8.314472 * (temperature + 273.15))) + * pow(norn_S, (*data_Creep)(1)) + + (*data_Creep)(4) * pow(norn_S, 2)); + break; } - for(i = 0; i < ns; i++) + for (i = 0; i < ns; i++) dstrain[i] -= fac * stress_n[i] / norn_S; } /************************************************************************** @@ -7711,8 +7453,8 @@ void CSolidProperties::AddStain_by_Creep(const int ns, double* stress_n, **************************************************************************/ void CSolidProperties::CleanTrBuffer_HL_ODS() { - for(int i = 0; i < 6; i++) - (*data_Creep)(i,1) = 0.0; + for (int i = 0; i < 6; i++) + (*data_Creep)(i, 1) = 0.0; } /************************************************************************** FEMLib-Method: @@ -7726,7 +7468,7 @@ void CSolidProperties::AccumulateEtr_HL_ODS(const ElementValue_DM* ele_val, cons int i, ns; ns = ele_val->xi->Size(); // - for(i = 0; i < ns; i++) + for (i = 0; i < ns; i++) (*ele_val->xi)(i) += (*data_Creep)(i, 1) / (double)nGS; } /************************************************************************** @@ -7751,41 +7493,40 @@ void CSolidProperties::CalcYoungs_SVV(const double strain_v) 10/2008 UJG/WW last modified: **************************************************************************/ -void CSolidProperties::AddStain_by_HL_ODS(const ElementValue_DM* ele_val, double* stress_n, - double* dstrain, double temperature) +void CSolidProperties::AddStain_by_HL_ODS(const ElementValue_DM* ele_val, double* stress_n, double* dstrain, + double temperature) { int i, ns, dim; double norn_S, norm_str; static double epsilon_tr[6]; ns = ele_val->xi->Size(); dim = 2; - if(ns > 4) + if (ns > 4) dim = 3; DeviatoricStress(stress_n); norn_S = sqrt(1.5 * TensorMutiplication2(stress_n, stress_n, dim)); - //WX:12.2012 threshold dev str for lubby2 - if(norn_S <= threshold_dev_str) + // WX:12.2012 threshold dev str for lubby2 + if (norn_S <= threshold_dev_str) return; // - for(i = 0; i < ns; i++) + for (i = 0; i < ns; i++) epsilon_tr[i] = (*ele_val->xi)(i); // norm_str = sqrt(2.0 * TensorMutiplication2(epsilon_tr, epsilon_tr, dim) / 3.0); - double max_etr = norn_S / ((*data_Creep)(6, 0) * exp((*data_Creep)(4, 0) * norn_S));//WX:12.2012 bug fixed + double max_etr = norn_S / ((*data_Creep)(6, 0) * exp((*data_Creep)(4, 0) * norn_S)); // WX:12.2012 bug fixed double eta_k = (*data_Creep)(3, 0) * exp((*data_Creep)(5, 0) * norn_S); - double eta_m = (*data_Creep)(0, 0) * exp((*data_Creep)(1, 0) * norn_S) - * exp((temperature + 273.16) * (*data_Creep)(2, 0)); - if(max_etr < DBL_EPSILON) + double eta_m + = (*data_Creep)(0, 0) * exp((*data_Creep)(1, 0) * norn_S) * exp((temperature + 273.16) * (*data_Creep)(2, 0)); + if (max_etr < DBL_EPSILON) return; - if(threshold_dev_str>=0) - norm_str = min(norm_str,max_etr); - //WX:12.2012, change "norm_str" to "min(norm_str,max_etr)" - //the norm_str should not be higher than max_etr - for(i = 0; i < ns; i++) + if (threshold_dev_str >= 0) + norm_str = min(norm_str, max_etr); + // WX:12.2012, change "norm_str" to "min(norm_str,max_etr)" + // the norm_str should not be higher than max_etr + for (i = 0; i < ns; i++) { (*data_Creep)(i, 1) += 1.5 * dt * (1 - norm_str / max_etr) * stress_n[i] / eta_k; - dstrain[i] -= 1.5 * dt * - ((1 - norm_str / max_etr) / eta_k + 1 / eta_m) * stress_n[i]; + dstrain[i] -= 1.5 * dt * ((1 - norm_str / max_etr) / eta_k + 1 / eta_m) * stress_n[i]; } } @@ -7800,40 +7541,31 @@ void CSolidProperties::CalPrimaryVariable(vector& pcs_name_vector) { CRFProcess* m_pcs = NULL; - int nidx0,nidx1; - if(!Fem_Ele_Std) //OK + int nidx0, nidx1; + if (!Fem_Ele_Std) // OK return; - for(size_t i = 0; i < pcs_name_vector.size(); i++) + for (size_t i = 0; i < pcs_name_vector.size(); i++) { - m_pcs = PCSGet(pcs_name_vector[i],true); + m_pcs = PCSGet(pcs_name_vector[i], true); if (!m_pcs) - return; //MX + return; // MX nidx0 = m_pcs->GetNodeValueIndex(pcs_name_vector[i]); nidx1 = nidx0 + 1; - if(mode == 0) // Gauss point values + if (mode == 0) // Gauss point values { - primary_variable_t0[i] = Fem_Ele_Std->interpolate(nidx0,m_pcs); - primary_variable_t1[i] = Fem_Ele_Std->interpolate(nidx1,m_pcs); - primary_variable[i] = - (1. - Fem_Ele_Std->pcs->m_num->ls_theta) * Fem_Ele_Std->interpolate( - nidx0, - m_pcs) - + Fem_Ele_Std->pcs->m_num->ls_theta* Fem_Ele_Std-> - interpolate(nidx1,m_pcs); + primary_variable_t0[i] = Fem_Ele_Std->interpolate(nidx0, m_pcs); + primary_variable_t1[i] = Fem_Ele_Std->interpolate(nidx1, m_pcs); + primary_variable[i] = (1. - Fem_Ele_Std->pcs->m_num->ls_theta) * Fem_Ele_Std->interpolate(nidx0, m_pcs) + + Fem_Ele_Std->pcs->m_num->ls_theta * Fem_Ele_Std->interpolate(nidx1, m_pcs); } - else if(mode == 2) // Element average value + else if (mode == 2) // Element average value { - primary_variable[i] = - (1. - - Fem_Ele_Std->pcs->m_num->ls_theta) * Fem_Ele_Std->elemnt_average( - nidx0, - m_pcs) - + Fem_Ele_Std->pcs->m_num->ls_theta* Fem_Ele_Std-> - elemnt_average(nidx1,m_pcs); - primary_variable_t0[i] = Fem_Ele_Std->elemnt_average(nidx0,m_pcs); - primary_variable_t1[i] = Fem_Ele_Std->elemnt_average(nidx1,m_pcs); + primary_variable[i] = (1. - Fem_Ele_Std->pcs->m_num->ls_theta) * Fem_Ele_Std->elemnt_average(nidx0, m_pcs) + + Fem_Ele_Std->pcs->m_num->ls_theta * Fem_Ele_Std->elemnt_average(nidx1, m_pcs); + primary_variable_t0[i] = Fem_Ele_Std->elemnt_average(nidx0, m_pcs); + primary_variable_t1[i] = Fem_Ele_Std->elemnt_average(nidx1, m_pcs); } } } @@ -7848,12 +7580,14 @@ void CSolidProperties::Write(std::fstream* msp_file) { //---------------------------------------------------------------------- // KEYWORD - *msp_file << "#SOLID_PROPERTIES" << "\n"; + *msp_file << "#SOLID_PROPERTIES" + << "\n"; //----------------------------------------------------------------------- - //NAME - if(name.length() > 0) + // NAME + if (name.length() > 0) { - *msp_file << " $NAME" << "\n"; + *msp_file << " $NAME" + << "\n"; *msp_file << " "; *msp_file << name << "\n"; } @@ -7864,38 +7598,46 @@ void CSolidProperties::Write(std::fstream* msp_file) //----------------------------------------------------------------------- // PROPERTIES //....................................................................... - *msp_file << " $DENSITY" << "\n"; + *msp_file << " $DENSITY" + << "\n"; *msp_file << " " << Density_mode; - if(data_Density) //OK410 + if (data_Density) // OK410 *msp_file << " " << (*data_Density)(0) << "\n"; else - *msp_file << " Warning: no density data" << "\n"; + *msp_file << " Warning: no density data" + << "\n"; //....................................................................... // Elasticity properties - *msp_file << " $ELASTICITY" << "\n"; - if(Poisson_Ratio()) //OK410 + *msp_file << " $ELASTICITY" + << "\n"; + if (Poisson_Ratio()) // OK410 *msp_file << " POISSION " << Poisson_Ratio() << "\n"; - *msp_file << " YOUNGS_MODULUS" << "\n"; + *msp_file << " YOUNGS_MODULUS" + << "\n"; *msp_file << " " << Youngs_mode; - if(data_Youngs) //OK410 + if (data_Youngs) // OK410 *msp_file << " " << (*data_Youngs)(0) << "\n"; //....................................................................... // Thermal properties - *msp_file << " $THERMAL" << "\n"; - if(ThermalExpansion >= 0) + *msp_file << " $THERMAL" + << "\n"; + if (ThermalExpansion >= 0) { - *msp_file << " EXPANSION" << "\n"; + *msp_file << " EXPANSION" + << "\n"; *msp_file << " " << ThermalExpansion << "\n"; } - if(Capacity_mode > 0) + if (Capacity_mode > 0) { - *msp_file << " CAPACITY" << "\n"; + *msp_file << " CAPACITY" + << "\n"; *msp_file << " " << Capacity_mode; *msp_file << " " << (*data_Capacity)(0) << "\n"; } - if(this->Conductivity_mode > 0) //OK410 + if (this->Conductivity_mode > 0) // OK410 { - *msp_file << " CONDUCTIVITY" << "\n"; + *msp_file << " CONDUCTIVITY" + << "\n"; *msp_file << " " << Conductivity_mode; *msp_file << " " << (*data_Conductivity)(0) << "\n"; } @@ -7914,7 +7656,7 @@ void CSolidProperties::TEPSwellingParameter_kis(const double suction) val = 1.0 + alf_i * suction; // else // val = 0.001; - if(val < 0.0) + if (val < 0.0) val = 0.001; // Swelling index. Kappa (*data_Youngs)(6) = val * (*data_Youngs)(0); @@ -7934,108 +7676,108 @@ double CSolidProperties::TEPSwellingParameter(const double mean_stress) // k_(s) TEPSwellingParameter_kis(suction); // - if(mean_stress < 1.0e-20) - val = 1.0 + alf_sp* log(1.0e-20 / pref); - else if(mean_stress >= pref * exp(-1.0 / alf_sp)) + if (mean_stress < 1.0e-20) + val = 1.0 + alf_sp * log(1.0e-20 / pref); + else if (mean_stress >= pref * exp(-1.0 / alf_sp)) { val = 0.; return val; } else - val = 1. + alf_sp* log(mean_stress / pref); + val = 1. + alf_sp * log(mean_stress / pref); return val * (*data_Youngs)(2) * exp((*data_Youngs)(4) * suction) / (3. + 3. * e0); } /************************************************************************ 11.2011 WX calculate the transform matrix for micro structure tensor *************************************************************************/ -void CSolidProperties::CalTransMatrixMicroStru(Matrix *Trans, double *bedding_norm) +void CSolidProperties::CalTransMatrixMicroStru(Matrix* Trans, double* bedding_norm) { - double tmp_dir[9]={0.}; - double i,j,k,tmp_sqrt; - i=bedding_norm[0]; - j=bedding_norm[1]; - k=bedding_norm[2]; - tmp_sqrt=sqrt(1-k*k); - if(fabs(i)==1) - tmp_dir[2]=tmp_dir[3]=tmp_dir[7]=1.; - else if (fabs(j)==1) - tmp_dir[1]=tmp_dir[5]=tmp_dir[6]=1.; - else if (fabs(k)==1) - tmp_dir[0]=tmp_dir[4]=tmp_dir[8]=1.; + double tmp_dir[9] = {0.}; + double i, j, k, tmp_sqrt; + i = bedding_norm[0]; + j = bedding_norm[1]; + k = bedding_norm[2]; + tmp_sqrt = sqrt(1 - k * k); + if (fabs(i) == 1) + tmp_dir[2] = tmp_dir[3] = tmp_dir[7] = 1.; + else if (fabs(j) == 1) + tmp_dir[1] = tmp_dir[5] = tmp_dir[6] = 1.; + else if (fabs(k) == 1) + tmp_dir[0] = tmp_dir[4] = tmp_dir[8] = 1.; else { - tmp_dir[0]=j/tmp_sqrt; - tmp_dir[1]=k*i/tmp_sqrt; - tmp_dir[2]=i; - tmp_dir[3]=-i/tmp_sqrt; - tmp_dir[4]=k*j/tmp_sqrt; - tmp_dir[5]=j; - tmp_dir[6]=0; - tmp_dir[7]=-(i*i+j*j)/tmp_sqrt; - tmp_dir[8]=k; + tmp_dir[0] = j / tmp_sqrt; + tmp_dir[1] = k * i / tmp_sqrt; + tmp_dir[2] = i; + tmp_dir[3] = -i / tmp_sqrt; + tmp_dir[4] = k * j / tmp_sqrt; + tmp_dir[5] = j; + tmp_dir[6] = 0; + tmp_dir[7] = -(i * i + j * j) / tmp_sqrt; + tmp_dir[8] = k; } - for(int ii=0; ii<9; ii++) + for (int ii = 0; ii < 9; ii++) { - if (fabs(tmp_dir[ii])>1) - cout << "WARNING: Please check the input value for $BEDDING_NORM !"< 1) + cout << "WARNING: Please check the input value for $BEDDING_NORM !" << endl; break; } CalTransMatrixA(tmp_dir, Trans, 6); } -//WX:06.2012 E dependents on stress, strain ... -double CSolidProperties::E_Function(int dim, const ElementValue_DM *ele_val, int ngp) +// WX:06.2012 E dependents on stress, strain ... +double CSolidProperties::E_Function(int dim, const ElementValue_DM* ele_val, int ngp) { - int nGauss = ngp, ele_dim = dim, valid=1, size=6; - double tmp_stress=0., return_value = 1., I1 = 0.; - double stress[6]={0.}; - if (ele_dim==2) - size=4; - switch(E_Function_Model) + int nGauss = ngp, ele_dim = dim, valid = 1, size = 6; + double tmp_stress = 0., return_value = 1., I1 = 0.; + double stress[6] = {0.}; + if (ele_dim == 2) + size = 4; + switch (E_Function_Model) { - case 1 : - for (int i=0; i<3; i++) - { - tmp_stress=0.; - for (int j=0; jStress)(i,j)/nGauss; - stress[i] = tmp_stress; - } - I1 = (stress[0]+stress[1]+stress[2])/3.; - return_value = GetCurveValue((int)E_Function_Model_Value[0], 0, I1, &valid); - break; - case 2: + case 1: + for (int i = 0; i < 3; i++) + { + tmp_stress = 0.; + for (int j = 0; j < nGauss; j++) + tmp_stress += (*ele_val->Stress)(i, j) / nGauss; + stress[i] = tmp_stress; + } + I1 = (stress[0] + stress[1] + stress[2]) / 3.; + return_value = GetCurveValue((int)E_Function_Model_Value[0], 0, I1, &valid); + break; + case 2: { - double prin_str[6]={0.}, prin_dir[6]={0.}; - for (int i=0; iStress)(i,j)/nGauss; + tmp_stress = 0.; + for (int j = 0; j < nGauss; j++) + tmp_stress += (*ele_val->Stress)(i, j) / nGauss; stress[i] = tmp_stress; } CalPrinStrDir(stress, prin_str, prin_dir, size); return_value = GetCurveValue((int)E_Function_Model_Value[0], 0, prin_str[0], &valid); } - default : - return_value = 1.; - break; + default: + return_value = 1.; + break; } return return_value; } -//TN - added for TNEQ/TEQ process -void CSolidProperties::setSolidReactiveSystem (FiniteElement::SolidReactiveSystem reactive_system) +// TN - added for TNEQ/TEQ process +void CSolidProperties::setSolidReactiveSystem(FiniteElement::SolidReactiveSystem reactive_system) { _reactive_system = reactive_system; } -FiniteElement::SolidReactiveSystem CSolidProperties::getSolidReactiveSystem () const +FiniteElement::SolidReactiveSystem CSolidProperties::getSolidReactiveSystem() const { return _reactive_system; } -} // end namespace +} // end namespace ///////////////////////////////////////////////////////////////////////////// @@ -8051,7 +7793,7 @@ FiniteElement::SolidReactiveSystem CSolidProperties::getSolidReactiveSystem () c bool MSPRead(const std::string& given_file_base_name) { //---------------------------------------------------------------------- - //OK MSPDelete(); + // OK MSPDelete(); //---------------------------------------------------------------------- SolidProp::CSolidProperties* m_msp = NULL; char line[MAX_ZEILE]; @@ -8061,30 +7803,31 @@ bool MSPRead(const std::string& given_file_base_name) //======================================================================== // File handling std::string msp_file_name = given_file_base_name + MSP_FILE_EXTENSION; - std::ifstream msp_file (msp_file_name.data(),std::ios::in); + std::ifstream msp_file(msp_file_name.data(), std::ios::in); if (!msp_file.good()) return false; - msp_file.seekg(0L,std::ios::beg); + msp_file.seekg(0L, std::ios::beg); //======================================================================== // Keyword loop - std::cout << "MSPRead" << "\n"; + std::cout << "MSPRead" + << "\n"; while (!msp_file.eof()) { - msp_file.getline(line,MAX_ZEILE); + msp_file.getline(line, MAX_ZEILE); line_string = line; - if(line_string.find("#STOP") != string::npos) + if (line_string.find("#STOP") != string::npos) return true; //---------------------------------------------------------------------- // keyword found - if(line_string.find("#SOLID_PROPERTIES") != std::string::npos) + if (line_string.find("#SOLID_PROPERTIES") != std::string::npos) { m_msp = new SolidProp::CSolidProperties(); m_msp->file_base_name = given_file_base_name; position = m_msp->Read(&msp_file); msp_vector.push_back(m_msp); - msp_file.seekg(position,std::ios::beg); - } // keyword found - } // eof + msp_file.seekg(position, std::ios::beg); + } // keyword found + } // eof return true; //======================================================================== } @@ -8109,17 +7852,17 @@ bool MSPRead(const std::string& given_file_base_name) **************************************************************************/ double TensorMutiplication2(const double* s1, const double* s2, const int Dim) { - switch(Dim) + switch (Dim) { - case 2: - return s1[0] * s2[0] + s1[1] * s2[1] + s1[2] * s2[2] + 2.0 * s1[3] * s2[3]; - break; - case 3: - return s1[0] * s2[0] + s1[1] * s2[1] + s1[2] * s2[2] + 2.0 * s1[3] * s2[3] - + 2.0 * s1[4] * s2[4] + 2.0 * s1[5] * s2[5]; - break; + case 2: + return s1[0] * s2[0] + s1[1] * s2[1] + s1[2] * s2[2] + 2.0 * s1[3] * s2[3]; + break; + case 3: + return s1[0] * s2[0] + s1[1] * s2[1] + s1[2] * s2[2] + 2.0 * s1[3] * s2[3] + 2.0 * s1[4] * s2[4] + + 2.0 * s1[5] * s2[5]; + break; } - return 0.0; // To avoid warnings + return 0.0; // To avoid warnings } /************************************************************************** @@ -8135,7 +7878,7 @@ double StressNorm(const double* s, const int Dim) double s2 = s[1] - mean_s; double s3 = s[2] - mean_s; val = s1 * s1 + s2 * s2 + s3 * s3 + 2.0 * s[3] * s[3]; - if(Dim == 3) + if (Dim == 3) val += +2.0 * s[4] * s[4] + 2.0 * s[5] * s[5]; return val; } @@ -8159,42 +7902,42 @@ double StressNorm(const double* s, const int Dim) 04/2003 WW Erste Version **************************************************************************/ -double TensorMutiplication3(const double* s1, const double* s2, const double* s3, - const int Dim) +double TensorMutiplication3(const double* s1, const double* s2, const double* s3, const int Dim) { - switch(Dim) + switch (Dim) { - case 2: - return ( - s1[0] * (s2[0] * s3[0] + s2[3] * s3[3]) // s1_11*(s2_11*s3_11+s2_12*s3_21) - + s1[3] * (s2[0] * s3[3] + s2[3] * s3[1]) // s1_12*(s2_11*s3_12+s2_12*s3_22) - + s1[3] * (s2[3] * s3[0] + s2[1] * s3[3]) // s1_21*(s2_21*s3_11+s2_22*s3_21) - + s1[1] * (s2[3] * s3[3] + s2[1] * s3[1]) // s1_22*(s2_21*s3_12+s2_22*s3_22) - + s1[2] * s2[2] * s3[2]) / 3.0; // s33*s33*s33 - break; - case 3: - return ( - // s1_11*(s2_11*s3_11+s2_12*s3_21+s2_13*s3_31) - s1[0] * (s2[0] * s3[0] + s2[3] * s3[3] + s2[4] * s3[4]) - // s1_12*(s2_11*s3_12+s2_12*s3_22+s2_13*s3_32) - + s1[3] * (s2[0] * s3[3] + s2[3] * s3[1] + s2[4] * s3[5]) - // s1_13*(s2_11*s3_13+s2_12*s3_23+s2_13*s3_33) - + s1[4] * (s2[0] * s3[4] + s2[3] * s3[5] + s2[4] * s3[2]) - // s1_21*(s2_21*s3_11+s2_22*s3_21+s2_23*s3_31) - + s1[3] * (s2[3] * s3[0] + s2[1] * s3[3] + s2[5] * s3[4]) - // s1_22*(s2_21*s3_12+s2_22*s3_22+s2_23*s3_32) - + s1[1] * (s2[3] * s3[3] + s2[1] * s3[1] + s2[5] * s3[5]) - // s1_23*(s2_21*s3_13+s2_22*s3_23+s2_23*s3_33) - + s1[5] * (s2[3] * s3[4] + s2[1] * s3[5] + s2[5] * s3[2]) - // s1_31*(s2_31*s3_11+s2_32*s3_21+s2_33*s3_31) - + s1[4] * (s2[4] * s3[0] + s2[5] * s3[3] + s2[2] * s3[4])//WX:bug fixed s3_31 is s3[4] - // s1_32*(s2_31*s3_12+s2_32*s3_22+s2_33*s3_32) - + s1[5] * (s2[4] * s3[3] + s2[5] * s3[1] + s2[2] * s3[5]) - // s1_33*(s2_31*s3_13+s2_32*s3_23+s2_33*s3_33) - + s1[2] * (s2[4] * s3[4] + s2[5] * s3[5] + s2[2] * s3[2])) / 3.0; - break; + case 2: + return (s1[0] * (s2[0] * s3[0] + s2[3] * s3[3]) // s1_11*(s2_11*s3_11+s2_12*s3_21) + + s1[3] * (s2[0] * s3[3] + s2[3] * s3[1]) // s1_12*(s2_11*s3_12+s2_12*s3_22) + + s1[3] * (s2[3] * s3[0] + s2[1] * s3[3]) // s1_21*(s2_21*s3_11+s2_22*s3_21) + + s1[1] * (s2[3] * s3[3] + s2[1] * s3[1]) // s1_22*(s2_21*s3_12+s2_22*s3_22) + + s1[2] * s2[2] * s3[2]) + / 3.0; // s33*s33*s33 + break; + case 3: + return ( + // s1_11*(s2_11*s3_11+s2_12*s3_21+s2_13*s3_31) + s1[0] * (s2[0] * s3[0] + s2[3] * s3[3] + s2[4] * s3[4]) + // s1_12*(s2_11*s3_12+s2_12*s3_22+s2_13*s3_32) + + s1[3] * (s2[0] * s3[3] + s2[3] * s3[1] + s2[4] * s3[5]) + // s1_13*(s2_11*s3_13+s2_12*s3_23+s2_13*s3_33) + + s1[4] * (s2[0] * s3[4] + s2[3] * s3[5] + s2[4] * s3[2]) + // s1_21*(s2_21*s3_11+s2_22*s3_21+s2_23*s3_31) + + s1[3] * (s2[3] * s3[0] + s2[1] * s3[3] + s2[5] * s3[4]) + // s1_22*(s2_21*s3_12+s2_22*s3_22+s2_23*s3_32) + + s1[1] * (s2[3] * s3[3] + s2[1] * s3[1] + s2[5] * s3[5]) + // s1_23*(s2_21*s3_13+s2_22*s3_23+s2_23*s3_33) + + s1[5] * (s2[3] * s3[4] + s2[1] * s3[5] + s2[5] * s3[2]) + // s1_31*(s2_31*s3_11+s2_32*s3_21+s2_33*s3_31) + + s1[4] * (s2[4] * s3[0] + s2[5] * s3[3] + s2[2] * s3[4]) // WX:bug fixed s3_31 is s3[4] + // s1_32*(s2_31*s3_12+s2_32*s3_22+s2_33*s3_32) + + s1[5] * (s2[4] * s3[3] + s2[5] * s3[1] + s2[2] * s3[5]) + // s1_33*(s2_31*s3_13+s2_32*s3_23+s2_33*s3_33) + + s1[2] * (s2[4] * s3[4] + s2[5] * s3[5] + s2[2] * s3[2])) + / 3.0; + break; } - return 0.0; // To avoid warnings + return 0.0; // To avoid warnings } /************************************************************************** @@ -8217,7 +7960,7 @@ double DeviatoricStress(double* Stress) { int i; double I1 = Stress[0] + Stress[1] + Stress[2]; - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) Stress[i] -= I1 / 3.0; return I1; @@ -8234,7 +7977,7 @@ void MSPDelete() { long i; int no_msp = (int)msp_vector.size(); - for(i = 0; i < no_msp; i++) + for (i = 0; i < no_msp; i++) delete msp_vector[i]; msp_vector.clear(); } @@ -8250,15 +7993,16 @@ void MSPWrite(const std::string& base_file_name) // File handling std::fstream msp_file; std::string msp_file_name = base_file_name + MSP_FILE_EXTENSION; - msp_file.open(msp_file_name.data(),ios::trunc | ios::out); - msp_file.setf(ios::scientific,ios::floatfield); + msp_file.open(msp_file_name.data(), ios::trunc | ios::out); + msp_file.setf(ios::scientific, ios::floatfield); msp_file.precision(12); if (!msp_file.good()) return; //---------------------------------------------------------------------- - msp_file << "GeoSys-MSP: Material Solid Properties -------------" << "\n"; + msp_file << "GeoSys-MSP: Material Solid Properties -------------" + << "\n"; //---------------------------------------------------------------------- - for(int i = 0; i < (int)msp_vector.size(); i++) + for (int i = 0; i < (int)msp_vector.size(); i++) { m_msp = msp_vector[i]; m_msp->Write(&msp_file); diff --git a/FEM/rf_msp_new.h b/FEM/rf_msp_new.h index 1bbe9e81b..bbe4308cf 100644 --- a/FEM/rf_msp_new.h +++ b/FEM/rf_msp_new.h @@ -49,406 +49,369 @@ namespace SolidProp { class CSolidProperties { - public: - // - CSolidProperties(); - ~CSolidProperties(); - - std::ios::pos_type Read(std::ifstream*); - - // Output - void Write(std::fstream*); - - //------------------------------------------------------------- - // Access to data - //------------------------------------------------------------- - // 1. Density - double Density(double refence = 0.0); - // 2. Thermal - double Heat_Capacity(double refence = 0.0); - // Boiling model - double Heat_Capacity(double temperature, double porosity, double Sat); - - void HeatConductivityTensor(const int dim, double* tensor, int group); - - double Heat_Conductivity(double refence = 0.0); - - int GetCapacityModel() const - { - return Capacity_mode; - } - - int GetConductModel() const - { - return Conductivity_mode; - } - - double Thermal_Expansion() const - { - return ThermalExpansion; - } - - double Poisson_Ratio() const - { - return PoissonRatio; - } - - // Elasticity - void Calculate_Lame_Constant(); - - // For thermal elastic model - void ElasticConsitutive(const int Dimension, Math_Group::Matrix* D_e) const; - - Math_Group::Matrix* getD_tran() const - { - return D_tran; - } - - // Creep - int CreepModel() const - { - return Creep_mode; - } - - // Plasticity - int Plastictity() const - { - return Plasticity_type; - } - - // Drucker-Prager - bool StressIntegrationDP(const int GPiGPj, const FiniteElement::ElementValue_DM* ele_val, - double* TryStress, double& dPhi, const int Update); - void ConsistentTangentialDP(Math_Group::Matrix* Dep, const double dPhi, const int Dim); - bool DirectStressIntegrationDP(const int GPiGPj, - const FiniteElement::ElementValue_DM* ele_val, - double* TryStress, - const int Update); - int DirectStressIntegrationDPwithTension(const int GPiGPj, - Math_Group::Matrix* De, - const FiniteElement::ElementValue_DM* ele_val, - double* TryStress, - const int Update, - double &mm); //WX - void TangentialDP(Math_Group::Matrix* Dep); - void TangentialDP2(Math_Group::Matrix* Dep); //WX - void TangentialDPwithTension(Math_Group::Matrix* Dep, double mm); //WX - void TangentialDPwithTensionCorner(Math_Group::Matrix* Dep, double mm); //WX - - // Single yield surface model - int CalStress_and_TangentialMatrix_SYS(const int GPiGPj, const FiniteElement::ElementValue_DM* ele_val, - const Math_Group::Matrix* De, Math_Group::Matrix* D_ep, double* dStress, - const int Update); - // Cam-clay model - void CalStress_and_TangentialMatrix_CC(const int GPiGPj, - const FiniteElement::ElementValue_DM* ele_val, - double* dStrain, - Math_Group::Matrix* Dep, - const int Update); - // Substep integration. 16.05.2008 WW - void CalStress_and_TangentialMatrix_CC_SubStep(const int GPiGPj, - const FiniteElement::ElementValue_DM* ele_val, - double* dStrain, - Math_Group::Matrix* Dep, - const int Update); - - void CalPrinStrDir(double* stress, double* prin_str, double* prin_dir, int Dim); - - bool GetBoolExcavated() - { - return excavated; //WX:01.2013 - } - //Solid Chemical Reactive System - void SetSolidReactiveSystemProperties(); - - //Set value for solid reactive system - TN - void setSolidReactiveSystem (FiniteElement::SolidReactiveSystem reactive_system); - - private: - //CMCD - FiniteElement::CFiniteElementStd *Fem_Ele_Std; - std::string name; - // IO - std::string file_base_name; - - // Material parameters - double PoissonRatio; - int Youngs_mode; - int excavation; //12.2009. WW - bool excavated; //12.2009. To be ..... WW - Math_Group::Matrix* data_Youngs; - double ThermalExpansion; - // - double s_tol; //16.06.2008 WW - double f_tol; //16.06.2008 WW - double biot_const; - int bishop_model; //05.2011 WX - double bishop_model_value; //05.2011 WX - double threshold_dev_str; //12.2012 WX - double grav_const; //WW - Math_Group::Matrix* data_Density; - // - Math_Group::Matrix* data_Capacity; - Math_Group::Matrix* data_Conductivity; - // - Math_Group::Matrix* data_Plasticity; - Math_Group::Matrix* data_Creep; - // - int Density_mode; - // - int Capacity_mode; - int Conductivity_mode; - double T_0; - int Plasticity_type; - double primary_variable[10]; //CMCD - double primary_variable_t0[10]; //CMCD - double primary_variable_t1[10]; //CMCD - // Creep property - // 1. Stationary Norton model - int Creep_mode; - // - bool axisymmetry; - - int mode; //CMCD - // Swelling pressure - int SwellingPressureType; - double Max_SwellingPressure; - // - std::string CurveVariable_Conductivity; - int CurveVariableType_Conductivity; - // Secondary data - // Elasticity - double E; // Youngs moduls calculated from data_Youngs - double Lambda; - double G; // Shear stress modulus - double K; // Bulk modulus - double Ks; //WX solid Bulk modulus - int E_Function_Model; //WX:06.2012. E depends on stress - double E_Function_Model_Value[3]; //WX:06.2012 - int Time_Dependent_E_nv_mode;//WX:01.2013. E nv is changed with time - int Time_Dependent_E_nv_value[5];//WX:01.2013 - - // Rotation matrices and their transpose: UJG 25.11.2009 - Math_Group::Matrix* Crotm; // If this is needed by permaebility calculation, we keep it. Otherwise remove it. (To do, UJG/WW) - Math_Group::Matrix* D_tran; - - // Plasticity - // 1. Drucker-Prager - double Al; - double Xi; - double Y0; - double BetaN; - double Hard; - double Hard_Loc; - double tension; //WX:08.2010 Tension strength - - // Mohr-Coulomb //WX: 11.2010. Mohr-Coulomb model - double Ntheta; - double Nphi; - double csn; - - // Plasticity - double dl2; - // Single yield surface - Math_Group::Matrix *d2G_dSdS; - Math_Group::Matrix *d2G_dSdM; - Math_Group::Matrix *LocalJacobi; // To store local Jacobi matrix - Math_Group::Matrix *inv_Jac; // To store the inverse of the Jacobi matrix - Math_Group::Matrix *sumA_Matrix; - double *rhs_l; // To store local unknowns of 15 - double *x_l; // To store local unknowns of 15 - int *Li; - void AllocateMemoryforSYS(); - void ResizeMatricesSYS(const int Dim); - - // Direct stress integration for Drucker-Prager - double *devS; - double *dFds; - double *dGds; - double *D_dFds; - double *D_dGds; - double *dFtds; //WX: 08.2010 - double *dGtds; //WX: 08.2010 - //Direct stress integration for Mohr-Coulomb. WX:08.11.2010. - Math_Group::Matrix *TransMatrixA; - Math_Group::Matrix *TransMatrixA_T; - Math_Group::Matrix *Inv_TransA; - Math_Group::Matrix *Inv_TransA_T; - Math_Group::Matrix *TmpDe; - Math_Group::Matrix *Inv_De; - Math_Group::Matrix *TMatrix; - Math_Group::Matrix *TmpMatrix; - Math_Group::Matrix *TmpMatrix2; - Math_Group::Matrix *Dep_l; - Math_Group::Matrix *dDep_l; - Math_Group::Matrix *dGds_dFds; - Math_Group::Matrix *ConstitutiveMatrix; - Math_Group::Matrix *TransMicroStru;//WX: 11.2011 micro structure tensor transform matrix - Math_Group::Matrix *TransMicroStru_T; - Math_Group::Matrix *TransMicroStru_TInv; - double *MicroStruTensor;//WX: 11.2011 - double *comp_para;//WX:12.2011 - double *tens_para; - - //WX:09.2011 - double *Bedding_Norm;//Norm vector of bedding plane, used for anisotropic elasto-plasticity - int bedding_fric_curve; - int bedding_uc_curve; - int bedding_tens_curve; - int bedding_uc_curve_order; - int bedding_tens_curve_order; - bool Plasticity_Bedding; - void CalTransMatrixMicroStru(Math_Group::Matrix *A, double *v); - - // Hoek-Brown WX - double HoekB_a; - double HoekB_s; - double HoekB_mb; - double HoekB_sigci; - double HoekB_tens; - double HoekB_cohe; - void CalculateCoefficent_HOEKBROWN(); - int StressIntegrationHoekBrown(const int GPiGPj, const FiniteElement::ElementValue_DM* ele_val, - double* TryStress, const int Update, Math_Group::Matrix* Dep ); - void TangentialHoekBrown(Math_Group::Matrix* Dep); - - std::vector capacity_pcs_name_vector; - std::vector conductivity_pcs_name_vector; - - // Mini linear solver - void Gauss_Elimination(const int DimE, Math_Group::Matrix& AA, int* L, double* xx); - void Gauss_Back(const int DimE, Math_Group::Matrix& AA, double* rhs, int* L, double* xx); - // Thermal properties - int thermal_conductivity_tensor_type; - int thermal_conductivity_tensor_dim; - double thermal_conductivity_tensor[9]; - std::string thermal_conductivity_tensor_type_name; - // Handles. May be used by GUI - std::string solid_name; - - //Solid reactive system properties - TN - std::string reaction_system; - double lower_solid_density_limit; - double upper_solid_density_limit; - double reaction_enthalpy; - double reaction_entropy; - double non_reactive_solid_volume_fraction; - double non_reactive_solid_density; - - double specific_heat_source; - - //CMCD - void CalPrimaryVariable(std::vector& pcs_name_vector); - - bool CheckTemperature_in_PhaseChange(const double T0, const double T1); - double Enthalpy(double temperature, const double latent_factor ); +public: + // + CSolidProperties(); + ~CSolidProperties(); + + std::ios::pos_type Read(std::ifstream*); + + // Output + void Write(std::fstream*); + + //------------------------------------------------------------- + // Access to data + //------------------------------------------------------------- + // 1. Density + double Density(double refence = 0.0); + // 2. Thermal + double Heat_Capacity(double refence = 0.0); + // Boiling model + double Heat_Capacity(double temperature, double porosity, double Sat); + + void HeatConductivityTensor(const int dim, double* tensor, int group); + + double Heat_Conductivity(double refence = 0.0); + + int GetCapacityModel() const { return Capacity_mode; } + int GetConductModel() const { return Conductivity_mode; } + double Thermal_Expansion() const { return ThermalExpansion; } + double Poisson_Ratio() const { return PoissonRatio; } + // Elasticity + void Calculate_Lame_Constant(); + + // For thermal elastic model + void ElasticConsitutive(const int Dimension, Math_Group::Matrix* D_e) const; + + Math_Group::Matrix* getD_tran() const { return D_tran; } + // Creep + int CreepModel() const { return Creep_mode; } + // Plasticity + int Plastictity() const { return Plasticity_type; } + // Drucker-Prager + bool StressIntegrationDP(const int GPiGPj, const FiniteElement::ElementValue_DM* ele_val, double* TryStress, + double& dPhi, const int Update); + void ConsistentTangentialDP(Math_Group::Matrix* Dep, const double dPhi, const int Dim); + bool DirectStressIntegrationDP(const int GPiGPj, + const FiniteElement::ElementValue_DM* ele_val, + double* TryStress, + const int Update); + int DirectStressIntegrationDPwithTension(const int GPiGPj, + Math_Group::Matrix* De, + const FiniteElement::ElementValue_DM* ele_val, + double* TryStress, + const int Update, + double& mm); // WX + void TangentialDP(Math_Group::Matrix* Dep); + void TangentialDP2(Math_Group::Matrix* Dep); // WX + void TangentialDPwithTension(Math_Group::Matrix* Dep, double mm); // WX + void TangentialDPwithTensionCorner(Math_Group::Matrix* Dep, double mm); // WX + + // Single yield surface model + int CalStress_and_TangentialMatrix_SYS(const int GPiGPj, const FiniteElement::ElementValue_DM* ele_val, + const Math_Group::Matrix* De, Math_Group::Matrix* D_ep, double* dStress, + const int Update); + // Cam-clay model + void CalStress_and_TangentialMatrix_CC(const int GPiGPj, + const FiniteElement::ElementValue_DM* ele_val, + double* dStrain, + Math_Group::Matrix* Dep, + const int Update); + // Substep integration. 16.05.2008 WW + void CalStress_and_TangentialMatrix_CC_SubStep(const int GPiGPj, + const FiniteElement::ElementValue_DM* ele_val, + double* dStrain, + Math_Group::Matrix* Dep, + const int Update); + + void CalPrinStrDir(double* stress, double* prin_str, double* prin_dir, int Dim); + + bool GetBoolExcavated() + { + return excavated; // WX:01.2013 + } + // Solid Chemical Reactive System + void SetSolidReactiveSystemProperties(); + + // Set value for solid reactive system - TN + void setSolidReactiveSystem(FiniteElement::SolidReactiveSystem reactive_system); + +private: + // CMCD + FiniteElement::CFiniteElementStd* Fem_Ele_Std; + std::string name; + // IO + std::string file_base_name; + + // Material parameters + double PoissonRatio; + int Youngs_mode; + int excavation; // 12.2009. WW + bool excavated; // 12.2009. To be ..... WW + Math_Group::Matrix* data_Youngs; + double ThermalExpansion; + // + double s_tol; // 16.06.2008 WW + double f_tol; // 16.06.2008 WW + double biot_const; + int bishop_model; // 05.2011 WX + double bishop_model_value; // 05.2011 WX + double threshold_dev_str; // 12.2012 WX + double grav_const; // WW + Math_Group::Matrix* data_Density; + // + Math_Group::Matrix* data_Capacity; + Math_Group::Matrix* data_Conductivity; + // + Math_Group::Matrix* data_Plasticity; + Math_Group::Matrix* data_Creep; + // + int Density_mode; + // + int Capacity_mode; + int Conductivity_mode; + double T_0; + int Plasticity_type; + double primary_variable[10]; // CMCD + double primary_variable_t0[10]; // CMCD + double primary_variable_t1[10]; // CMCD + // Creep property + // 1. Stationary Norton model + int Creep_mode; + // + bool axisymmetry; + + int mode; // CMCD + // Swelling pressure + int SwellingPressureType; + double Max_SwellingPressure; + // + std::string CurveVariable_Conductivity; + int CurveVariableType_Conductivity; + // Secondary data + // Elasticity + double E; // Youngs moduls calculated from data_Youngs + double Lambda; + double G; // Shear stress modulus + double K; // Bulk modulus + double Ks; // WX solid Bulk modulus + int E_Function_Model; // WX:06.2012. E depends on stress + double E_Function_Model_Value[3]; // WX:06.2012 + int Time_Dependent_E_nv_mode; // WX:01.2013. E nv is changed with time + int Time_Dependent_E_nv_value[5]; // WX:01.2013 + + // Rotation matrices and their transpose: UJG 25.11.2009 + Math_Group::Matrix* + Crotm; // If this is needed by permaebility calculation, we keep it. Otherwise remove it. (To do, UJG/WW) + Math_Group::Matrix* D_tran; + + // Plasticity + // 1. Drucker-Prager + double Al; + double Xi; + double Y0; + double BetaN; + double Hard; + double Hard_Loc; + double tension; // WX:08.2010 Tension strength + + // Mohr-Coulomb //WX: 11.2010. Mohr-Coulomb model + double Ntheta; + double Nphi; + double csn; + + // Plasticity + double dl2; + // Single yield surface + Math_Group::Matrix* d2G_dSdS; + Math_Group::Matrix* d2G_dSdM; + Math_Group::Matrix* LocalJacobi; // To store local Jacobi matrix + Math_Group::Matrix* inv_Jac; // To store the inverse of the Jacobi matrix + Math_Group::Matrix* sumA_Matrix; + double* rhs_l; // To store local unknowns of 15 + double* x_l; // To store local unknowns of 15 + int* Li; + void AllocateMemoryforSYS(); + void ResizeMatricesSYS(const int Dim); + + // Direct stress integration for Drucker-Prager + double* devS; + double* dFds; + double* dGds; + double* D_dFds; + double* D_dGds; + double* dFtds; // WX: 08.2010 + double* dGtds; // WX: 08.2010 + // Direct stress integration for Mohr-Coulomb. WX:08.11.2010. + Math_Group::Matrix* TransMatrixA; + Math_Group::Matrix* TransMatrixA_T; + Math_Group::Matrix* Inv_TransA; + Math_Group::Matrix* Inv_TransA_T; + Math_Group::Matrix* TmpDe; + Math_Group::Matrix* Inv_De; + Math_Group::Matrix* TMatrix; + Math_Group::Matrix* TmpMatrix; + Math_Group::Matrix* TmpMatrix2; + Math_Group::Matrix* Dep_l; + Math_Group::Matrix* dDep_l; + Math_Group::Matrix* dGds_dFds; + Math_Group::Matrix* ConstitutiveMatrix; + Math_Group::Matrix* TransMicroStru; // WX: 11.2011 micro structure tensor transform matrix + Math_Group::Matrix* TransMicroStru_T; + Math_Group::Matrix* TransMicroStru_TInv; + double* MicroStruTensor; // WX: 11.2011 + double* comp_para; // WX:12.2011 + double* tens_para; + + // WX:09.2011 + double* Bedding_Norm; // Norm vector of bedding plane, used for anisotropic elasto-plasticity + int bedding_fric_curve; + int bedding_uc_curve; + int bedding_tens_curve; + int bedding_uc_curve_order; + int bedding_tens_curve_order; + bool Plasticity_Bedding; + void CalTransMatrixMicroStru(Math_Group::Matrix* A, double* v); + + // Hoek-Brown WX + double HoekB_a; + double HoekB_s; + double HoekB_mb; + double HoekB_sigci; + double HoekB_tens; + double HoekB_cohe; + void CalculateCoefficent_HOEKBROWN(); + int StressIntegrationHoekBrown(const int GPiGPj, const FiniteElement::ElementValue_DM* ele_val, double* TryStress, + const int Update, Math_Group::Matrix* Dep); + void TangentialHoekBrown(Math_Group::Matrix* Dep); + + std::vector capacity_pcs_name_vector; + std::vector conductivity_pcs_name_vector; + + // Mini linear solver + void Gauss_Elimination(const int DimE, Math_Group::Matrix& AA, int* L, double* xx); + void Gauss_Back(const int DimE, Math_Group::Matrix& AA, double* rhs, int* L, double* xx); + // Thermal properties + int thermal_conductivity_tensor_type; + int thermal_conductivity_tensor_dim; + double thermal_conductivity_tensor[9]; + std::string thermal_conductivity_tensor_type_name; + // Handles. May be used by GUI + std::string solid_name; + + // Solid reactive system properties - TN + std::string reaction_system; + double lower_solid_density_limit; + double upper_solid_density_limit; + double reaction_enthalpy; + double reaction_entropy; + double non_reactive_solid_volume_fraction; + double non_reactive_solid_density; + + double specific_heat_source; + + // CMCD + void CalPrimaryVariable(std::vector& pcs_name_vector); + + bool CheckTemperature_in_PhaseChange(const double T0, const double T1); + double Enthalpy(double temperature, const double latent_factor); #ifdef RFW_FRACTURE - double Youngs_Modulus(CElem* elem, double refence = 0.0); - //RFW, for fracture calc - double Get_Youngs_Min_Aperture(CElem *elem); + double Youngs_Modulus(CElem* elem, double refence = 0.0); + // RFW, for fracture calc + double Get_Youngs_Min_Aperture(CElem* elem); #else - double Youngs_Modulus(double refence = 0.0); + double Youngs_Modulus(double refence = 0.0); #endif - void CalcYoungs_SVV(const double strain_v); - - // For transverse isotropic linear elasticity: UJG 24.11.2009 - void ElasticConstitutiveTransverseIsotropic(const int Dimension); - void CalculateTransformMatrixFromNormalVector(const int Dimension); - double E_Function(int dim, const FiniteElement::ElementValue_DM *ele_val, int ngp);//WX:06.2012 - - // Plasticity - // Drucker-Prager - double GetAngleCoefficent_DP(const double Angle); - double GetYieldCoefficent_DP(const double Angle); - void CalulateCoefficent_DP(); - - // for single yield surface. - void dF_dNStress(double* dFdS, const double* DevS, const double* S_Invariants, - const double* MatN1, const int LengthStrs); - void dF_dStress(double* dFdS, const double* RotV, const double* S_Invariants, - const double* MatN1, const int LengthStrs); - void dF_dMat(double* dFdM, const double* S_Invariants, const double* MatN1); - void dG_dNStress(double* dGdS, const double* DevS, const double* S_Invariants, - const double* MatN1, const int LengthStrs); - void dG__dNStress_dNStress(const double* DevS, const double* S_Invariants, - const double* MatN1, const int LengthStrs ); - void dG__dStress_dStress(const double* DevS, const double* RotV, - const double* S_Invariants, const double* MatN1, - const int LengthStrs); - void dG_dSTress_dMat(const double* DevS, const double* S_Invariants, - const double* MatN1, const int LengthStrs); - void dfun2(const double* DevS, const double* RotV, const double* S_Invariants, - const double* MatN1, const int LengthStrs); - - // Strain increment by creep - void AddStain_by_Creep(const int ns, - double* stress_n, - double* dstrain, - double temperature = 0.0); - void AddStain_by_HL_ODS(const FiniteElement::ElementValue_DM* ele_val, - double* stress_n, - double* dstrain, - double temperature = 30); - void CleanTrBuffer_HL_ODS(); - void AccumulateEtr_HL_ODS(const FiniteElement::ElementValue_DM* ele_val, const int nGS); - - // Parameter function for thermal elatic model. Last modifed on 15.03.2008 //WW - double TEPSwellingParameter(const double mean_stress); - void TEPSwellingParameter_kis(const double suction); - - void CalculateCoefficent_MOHR(double ep, double scalar_comp, double scalar_tens); - void CalPrinStrs(double* stresses, double* prin_stresses, int Size); - void CalPrinDir(double* prin_str, double* stress, double* v, int Size); - void CalTransMatrixA(double* v, Math_Group::Matrix* A, int Size); - int DirectStressIntegrationMOHR(const int GPiGPj, FiniteElement::ElementValue_DM *ele_val, - double *TryStress, const int Update, Math_Group::Matrix *Dep, int itesteps ); - int StressIntegrationMOHR_Aniso(const int GPiGPj, const FiniteElement::ElementValue_DM *ele_val, - double *TryStress, const int Update, Math_Group::Matrix *Dep);//WX:12.2011 aniso mohr - double CalAnisoPara(double *Stress, double *MicroStruTensor);//WX:12.2011 cal. aniso parameter - int MohrCheckFailure(double* NormStr, int &failurestate, int Size); - void TangentialMohrShear(Math_Group::Matrix* Dep); - void TangentialMohrTension(Math_Group::Matrix* Dep); - void Cal_Inv_Matrix(int Size, Math_Group::Matrix* MatrixA, Math_Group::Matrix* xx); - double CalVarP(double* vec1, double* vec2, double* sigma_B, double* sigma_l); - double CalVar_t(double* vecl, - double* veclg, - Math_Group::Matrix* D, - double* sigma_B, - double* sigma_l, - int Size); - void CalDep_l(double* vecl, double* veclg, Math_Group::Matrix* D, Math_Group::Matrix* Dep_l, double fkt); - void VecCrossProduct(double* vec1, double* vec2, double* result_vec); - - // Numeric - double CalulateValue(const Math_Group::Matrix *data, const double x) const; - double Kronecker(const int ii, const int jj); - - //Get solid reactive system - TN - FiniteElement::SolidReactiveSystem getSolidReactiveSystem () const; - - FiniteElement::SolidReactiveSystem _reactive_system; - - // Friends that can access to this data explicitly - friend bool ::MSPRead(const std::string& given_file_base_name); - friend void MSPWrite(const std::string& base_file_name); - - friend class FiniteElement::CFiniteElementVec; - friend class FiniteElement::CFiniteElementStd; - friend class FiniteElement::ElementValue; - friend class FiniteElement::ElementValue_DM; - friend class process::CRFProcessDeformation; - friend class CMediumProperties; - friend class ::CRFProcess; + void CalcYoungs_SVV(const double strain_v); + + // For transverse isotropic linear elasticity: UJG 24.11.2009 + void ElasticConstitutiveTransverseIsotropic(const int Dimension); + void CalculateTransformMatrixFromNormalVector(const int Dimension); + double E_Function(int dim, const FiniteElement::ElementValue_DM* ele_val, int ngp); // WX:06.2012 + + // Plasticity + // Drucker-Prager + double GetAngleCoefficent_DP(const double Angle); + double GetYieldCoefficent_DP(const double Angle); + void CalulateCoefficent_DP(); + + // for single yield surface. + void dF_dNStress(double* dFdS, const double* DevS, const double* S_Invariants, const double* MatN1, + const int LengthStrs); + void dF_dStress(double* dFdS, const double* RotV, const double* S_Invariants, const double* MatN1, + const int LengthStrs); + void dF_dMat(double* dFdM, const double* S_Invariants, const double* MatN1); + void dG_dNStress(double* dGdS, const double* DevS, const double* S_Invariants, const double* MatN1, + const int LengthStrs); + void dG__dNStress_dNStress(const double* DevS, const double* S_Invariants, const double* MatN1, + const int LengthStrs); + void dG__dStress_dStress(const double* DevS, const double* RotV, const double* S_Invariants, const double* MatN1, + const int LengthStrs); + void dG_dSTress_dMat(const double* DevS, const double* S_Invariants, const double* MatN1, const int LengthStrs); + void dfun2(const double* DevS, const double* RotV, const double* S_Invariants, const double* MatN1, + const int LengthStrs); + + // Strain increment by creep + void AddStain_by_Creep(const int ns, double* stress_n, double* dstrain, double temperature = 0.0); + void AddStain_by_HL_ODS(const FiniteElement::ElementValue_DM* ele_val, + double* stress_n, + double* dstrain, + double temperature = 30); + void CleanTrBuffer_HL_ODS(); + void AccumulateEtr_HL_ODS(const FiniteElement::ElementValue_DM* ele_val, const int nGS); + + // Parameter function for thermal elatic model. Last modifed on 15.03.2008 //WW + double TEPSwellingParameter(const double mean_stress); + void TEPSwellingParameter_kis(const double suction); + + void CalculateCoefficent_MOHR(double ep, double scalar_comp, double scalar_tens); + void CalPrinStrs(double* stresses, double* prin_stresses, int Size); + void CalPrinDir(double* prin_str, double* stress, double* v, int Size); + void CalTransMatrixA(double* v, Math_Group::Matrix* A, int Size); + int DirectStressIntegrationMOHR(const int GPiGPj, FiniteElement::ElementValue_DM* ele_val, double* TryStress, + const int Update, Math_Group::Matrix* Dep, int itesteps); + int StressIntegrationMOHR_Aniso(const int GPiGPj, const FiniteElement::ElementValue_DM* ele_val, double* TryStress, + const int Update, Math_Group::Matrix* Dep); // WX:12.2011 aniso mohr + double CalAnisoPara(double* Stress, double* MicroStruTensor); // WX:12.2011 cal. aniso parameter + int MohrCheckFailure(double* NormStr, int& failurestate, int Size); + void TangentialMohrShear(Math_Group::Matrix* Dep); + void TangentialMohrTension(Math_Group::Matrix* Dep); + void Cal_Inv_Matrix(int Size, Math_Group::Matrix* MatrixA, Math_Group::Matrix* xx); + double CalVarP(double* vec1, double* vec2, double* sigma_B, double* sigma_l); + double CalVar_t(double* vecl, double* veclg, Math_Group::Matrix* D, double* sigma_B, double* sigma_l, int Size); + void CalDep_l(double* vecl, double* veclg, Math_Group::Matrix* D, Math_Group::Matrix* Dep_l, double fkt); + void VecCrossProduct(double* vec1, double* vec2, double* result_vec); + + // Numeric + double CalulateValue(const Math_Group::Matrix* data, const double x) const; + double Kronecker(const int ii, const int jj); + + // Get solid reactive system - TN + FiniteElement::SolidReactiveSystem getSolidReactiveSystem() const; + + FiniteElement::SolidReactiveSystem _reactive_system; + + // Friends that can access to this data explicitly + friend bool ::MSPRead(const std::string& given_file_base_name); + friend void MSPWrite(const std::string& base_file_name); + + friend class FiniteElement::CFiniteElementVec; + friend class FiniteElement::CFiniteElementStd; + friend class FiniteElement::ElementValue; + friend class FiniteElement::ElementValue_DM; + friend class process::CRFProcessDeformation; + friend class CMediumProperties; + friend class ::CRFProcess; }; -} // end namespace +} // end namespace extern std::vector msp_vector; -extern double StressNorm(const double *s, const int Dim); -extern double TensorMutiplication2(const double *s1, const double *s2, const int Dim); -extern double TensorMutiplication3(const double *s1, const double *s2, const double *s3, const int Dim); -extern double DeviatoricStress(double *Stress); +extern double StressNorm(const double* s, const int Dim); +extern double TensorMutiplication2(const double* s1, const double* s2, const int Dim); +extern double TensorMutiplication3(const double* s1, const double* s2, const double* s3, const int Dim); +extern double DeviatoricStress(double* Stress); #endif diff --git a/FEM/rf_node.cpp b/FEM/rf_node.cpp index d7fd752db..14fa2476c 100644 --- a/FEM/rf_node.cpp +++ b/FEM/rf_node.cpp @@ -23,26 +23,24 @@ Task: constructor 04/2005 OK/WW Implementation last modification: **************************************************************************/ -CNodeValue::CNodeValue() : -_node_distype (FiniteElement::INVALID_DIS_TYPE) +CNodeValue::CNodeValue() : _node_distype(FiniteElement::INVALID_DIS_TYPE) { - geo_node_number = -1; - msh_node_number = -1; - msh_node_number_conditional = -1; - node_value = 0.; - node_area = 0.; - node_parameterA = 0.; - node_parameterB = 0.; - node_parameterC = 0.; - node_parameterD = 0.; - node_parameterE = 0.; - CurveIndex = -1; - conditional = -1; - check_me = true; //OK - _isConstrainedSTNode = false; + geo_node_number = -1; + msh_node_number = -1; + msh_node_number_conditional = -1; + node_value = 0.; + node_area = 0.; + node_parameterA = 0.; + node_parameterB = 0.; + node_parameterC = 0.; + node_parameterD = 0.; + node_parameterE = 0.; + CurveIndex = -1; + conditional = -1; + check_me = true; // OK + _isConstrainedSTNode = false; } - /************************************************************************** FEMLib-Method: Task: destructor @@ -52,10 +50,9 @@ last modification: **************************************************************************/ CNodeValue::~CNodeValue() { - check_me = false; //OK + check_me = false; // OK } - /************************************************************************** FEMLib-Method: Task: destructor @@ -65,28 +62,27 @@ last modification: **************************************************************************/ void CNodeValue::Write(std::ostream& os) const { - std::string deli = " "; - os<>geo_node_number; - is>>msh_node_number; - is>> CurveIndex ; - is>> node_value ; - /* - // This is for river flow - // This writing will be valid for river flow when some - // of its parameters being moved from CSourceTerm to here - is>> node_distype ; - is>> node_area ; - is>> node_parameterA ; - is>> node_parameterB ; - is>> node_parameterC ; - is>> node_parameterD ; - is>> node_parameterE ; - is>> conditional ; - */ - is>> std::ws; + is >> geo_node_number; + is >> msh_node_number; + is >> CurveIndex; + is >> node_value; + /* + // This is for river flow + // This writing will be valid for river flow when some + // of its parameters being moved from CSourceTerm to here + is>> node_distype ; + is>> node_area ; + is>> node_parameterA ; + is>> node_parameterB ; + is>> node_parameterC ; + is>> node_parameterD ; + is>> node_parameterE ; + is>> conditional ; + */ + is >> std::ws; } diff --git a/FEM/rf_node.h b/FEM/rf_node.h index 06b9959fe..39c6a7ffc 100644 --- a/FEM/rf_node.h +++ b/FEM/rf_node.h @@ -30,51 +30,46 @@ last modified class CNodeValue { - public: - CNodeValue(void); - ~CNodeValue(void); +public: + CNodeValue(void); + ~CNodeValue(void); - void setProcessDistributionType (FiniteElement::DistributionType distype) - { - _node_distype = - distype; - } - FiniteElement::DistributionType getProcessDistributionType () const { return _node_distype; } - // - long geo_node_number; - long msh_node_number; - double node_value; - double node_area; + void setProcessDistributionType(FiniteElement::DistributionType distype) { _node_distype = distype; } + FiniteElement::DistributionType getProcessDistributionType() const { return _node_distype; } + // + long geo_node_number; + long msh_node_number; + double node_value; + double node_area; - // int node_distype; - double node_parameterA; - double node_parameterB; - double node_parameterC; - double node_parameterD; - double node_parameterE; - int CurveIndex; - int conditional; - //std::vectorhistory_value; - long msh_node_number_conditional; - // JOD st-coupling 4.7.10 - std::vector msh_node_numbers_averaging; - // JOD - std::vector msh_node_weights_averaging; - std::string tim_type_name; - //WW - void Write(std::ostream& os=std::cout) const; - void Read(std::istream& is=std::cin); //WW - bool check_me; //OK - bool _isConstrainedSTNode; + // int node_distype; + double node_parameterA; + double node_parameterB; + double node_parameterC; + double node_parameterD; + double node_parameterE; + int CurveIndex; + int conditional; + // std::vectorhistory_value; + long msh_node_number_conditional; + // JOD st-coupling 4.7.10 + std::vector msh_node_numbers_averaging; + // JOD + std::vector msh_node_weights_averaging; + std::string tim_type_name; + // WW + void Write(std::ostream& os = std::cout) const; + void Read(std::istream& is = std::cin); // WW + bool check_me; // OK + bool _isConstrainedSTNode; - std::size_t getSTVectorIndex() const { return _st_vector_index; } - void setSTVectorIndex(int index) { _st_vector_index = index; } - std::size_t getSTVectorGroup() const { return _st_vector_group; } - void setSTVectorGroup(int group) { _st_vector_group = group; } - - private: - FiniteElement::DistributionType _node_distype; - std::size_t _st_vector_index; - std::size_t _st_vector_group; + std::size_t getSTVectorIndex() const { return _st_vector_index; } + void setSTVectorIndex(int index) { _st_vector_index = index; } + std::size_t getSTVectorGroup() const { return _st_vector_group; } + void setSTVectorGroup(int group) { _st_vector_group = group; } +private: + FiniteElement::DistributionType _node_distype; + std::size_t _st_vector_index; + std::size_t _st_vector_group; }; #endif diff --git a/FEM/rf_num_new.cpp b/FEM/rf_num_new.cpp index aee365310..00969bb73 100644 --- a/FEM/rf_num_new.cpp +++ b/FEM/rf_num_new.cpp @@ -24,7 +24,7 @@ // #error to indicate a fatal error. Users can either #undef // the names before including mpi.h or include mpi.h *before* stdio.h // or iostream. -#ifdef USE_MPI //WW +#ifdef USE_MPI // WW #include "mpi.h" #include "par_ddc.h" //#undef SEEK_SET @@ -49,7 +49,7 @@ #include "makros.h" // GeoSys-GeoLib // GeoSys-FEMLib -#ifndef NEW_EQS //WW. 06.11.2008 +#ifndef NEW_EQS // WW. 06.11.2008 #include "matrix_routines.h" #endif #include "StringTools.h" @@ -60,11 +60,11 @@ using namespace std; -extern std::ios::pos_type GetNextSubKeyword(ifstream* file,string* line, bool* keyword); -extern size_t max_dim; //OK411 todo +extern std::ios::pos_type GetNextSubKeyword(ifstream* file, string* line, bool* keyword); +extern size_t max_dim; // OK411 todo //========================================================================== -vectornum_vector; +vector num_vector; /************************************************************************** FEMLib-Method: Task: constructor @@ -75,62 +75,62 @@ vectornum_vector; **************************************************************************/ CNumerics::CNumerics(string name) { - pcs_type_name = name; //OK + pcs_type_name = name; // OK // GLOBAL renumber_method = 0; // // LS - Linear Solver - ls_method = 2; //OK41 + ls_method = 2; // OK41 ls_max_iterations = 1000; ls_error_method = 1; ls_error_tolerance = 1e-12; ls_theta = 1.0; ls_precond = 1; - ls_storage_method = 2; //OK41 - m_cols = 5; // 06.2010. WW - ls_extra_arg = ""; //NW + ls_storage_method = 2; // OK41 + m_cols = 5; // 06.2010. WW + ls_extra_arg = ""; // NW // // NLS - Nonlinear Solver nls_method_name = "PICARD"; - nls_method = -1; //Default linear, 0: Picard. 1: Newton. 2:JFNK - nls_error_method = 1; //JT2012 - nls_max_iterations = 1; //OK + nls_method = -1; // Default linear, 0: Picard. 1: Newton. 2:JFNK + nls_error_method = 1; // JT2012 + nls_max_iterations = 1; // OK nls_relaxation = 0.0; - for(size_t i=0; iRead(&num_file); num_vector.push_back(m_num); - num_file.seekg(position,ios::beg); - m_num->NumConfigure(overall_coupling_exists); // JT2012 - } // keyword found - } // eof + num_file.seekg(position, ios::beg); + m_num->NumConfigure(overall_coupling_exists); // JT2012 + } // keyword found + } // eof return true; } @@ -230,7 +232,7 @@ bool NUMRead(string file_base_name) **************************************************************************/ bool CNumerics::CheckDynamic() { - if(DynamicDamping) + if (DynamicDamping) return true; else return false; @@ -244,64 +246,76 @@ Task: After a read of each m_num, configure any defaults here **************************************************************************/ void CNumerics::NumConfigure(bool overall_coupling_exists) { - // Overall coupling check - if(overall_coupling_exists && !cpl_error_specified){ - if(this->nls_method < 0){ - std::cout<<"ERROR in NUMRead. Overall coupling requested, but "; - std::cout<< this->pcs_type_name << " was not\n"; - std::cout<<"supplied with coupling tolerance. See $COUPLING_CONTROL keyword to enter this.\n"; - exit(1); - } - else{ // Can take the non-linear tolerance as an emergency backup - std::cout<<"WARNING in NUMRead. Overall coupling requested, but "; - std::cout<< this->pcs_type_name << " was not\n"; - std::cout<<"supplied with coupling tolerance. Adopting 10*non_linear_tolerance.\n"; - setCouplingErrorMethod(getNonLinearErrorMethod()); - for(size_t i=0; ipcs_type_name << " was not\n"; - std::cout<<"supplied with coupling tolerance. See $COUPLING_CONTROL keyword to enter this.\n"; - exit(1); - } - // - // We are ok. Now check the tolerances. - if(this->nls_method < 0){ // linear solution - if(cpl_error_specified){ // A coupling error was entered. Adopt this for error calculations. - for(size_t i=0; inls_method < 0) + { + std::cout << "ERROR in NUMRead. Overall coupling requested, but "; + std::cout << this->pcs_type_name << " was not\n"; + std::cout << "supplied with coupling tolerance. See $COUPLING_CONTROL keyword to enter this.\n"; + exit(1); + } + else + { // Can take the non-linear tolerance as an emergency backup + std::cout << "WARNING in NUMRead. Overall coupling requested, but "; + std::cout << this->pcs_type_name << " was not\n"; + std::cout << "supplied with coupling tolerance. Adopting 10*non_linear_tolerance.\n"; + setCouplingErrorMethod(getNonLinearErrorMethod()); + for (size_t i = 0; i < DOF_NUMBER_MAX; i++) + { + cpl_error_tolerance[i] = 10.0 * nls_error_tolerance[i]; + } + cpl_error_specified = true; + } + } + // + // Check master processes + if (cpl_master_process && !cpl_error_specified) + { + std::cout << "ERROR in NUMRead. Process coupling requested, but "; + std::cout << this->pcs_type_name << " was not\n"; + std::cout << "supplied with coupling tolerance. See $COUPLING_CONTROL keyword to enter this.\n"; + exit(1); + } + // + // We are ok. Now check the tolerances. + if (this->nls_method < 0) + { // linear solution + if (cpl_error_specified) + { // A coupling error was entered. Adopt this for error calculations. + for (size_t i = 0; i < DOF_NUMBER_MAX; i++) + { + nls_error_tolerance[i] = cpl_error_tolerance[i]; + } + setNonLinearErrorMethod(getCouplingErrorMethod()); + } + else + { // We have no error tolerances for non-linear or coupled simulations. Force some defaults. + setNonLinearErrorMethod(FiniteElement::LMAX); + setCouplingErrorMethod(FiniteElement::LMAX); + nls_error_tolerance[0] = cpl_error_tolerance[0] = 1.0; + } + } + // Default CPL error method to NLS method. Just so error is not checked twice + if (!cpl_error_specified) + { + setCouplingErrorMethod(getNonLinearErrorMethod()); + } + // + // Default all NLS tolerances to the previous DOF, if they were not entered. + for (size_t i = 1; i < DOF_NUMBER_MAX; i++) + { + if (nls_error_tolerance[i] < 0.0) + nls_error_tolerance[i] = nls_error_tolerance[i - 1]; + } + // + // Default all CPL tolerances to the previous DOF, if they were not entered. + for (size_t i = 1; i < DOF_NUMBER_MAX; i++) + { + if (cpl_error_tolerance[i] < 0.0) + cpl_error_tolerance[i] = cpl_error_tolerance[i - 1]; + } } /************************************************************************** @@ -322,17 +336,17 @@ ios::pos_type CNumerics::Read(ifstream* num_file) std::stringstream line; //======================================================================== // Schleife ueber alle Phasen bzw. Komponenten - while(!new_keyword) + while (!new_keyword) { - if(new_subkeyword) - num_file->seekg(position,ios::beg); + if (new_subkeyword) + num_file->seekg(position, ios::beg); new_subkeyword = false; - position = GetNextSubKeyword(num_file,&line_string,&new_keyword); - if(new_keyword) + position = GetNextSubKeyword(num_file, &line_string, &new_keyword); + if (new_keyword) return position; //.................................................................... // subkeyword found - if(line_string.find("$PCS_TYPE") != string::npos) + if (line_string.find("$PCS_TYPE") != string::npos) { line.str(GetLineFromFile1(num_file)); line >> pcs_type_name; @@ -341,25 +355,25 @@ ios::pos_type CNumerics::Read(ifstream* num_file) } //.................................................................... // subkeyword found - if(line_string.find("$RENUMBER") != string::npos) + if (line_string.find("$RENUMBER") != string::npos) { line.str(GetLineFromFile1(num_file)); line >> renumber_method; - if(renumber_method == 2) + if (renumber_method == 2) line >> renumber_parameter; line.clear(); continue; } //.................................................................... // JT->WW: Local tolerance previously found in $NON_LINEAR_SOLVER for NEWTON. Moved here for now. - if(line_string.find("$PLASTICITY_TOLERANCE") != string::npos) + if (line_string.find("$PLASTICITY_TOLERANCE") != string::npos) { line.str(GetLineFromFile1(num_file)); line >> nls_plasticity_local_tolerance; } //.................................................................... // subkeyword found ($NON_LINEAR_ITERATION -or- $NON_LINEAR_ITERATIONS) - if(line_string.find("$NON_LINEAR_ITERATION") != string::npos) + if (line_string.find("$NON_LINEAR_ITERATION") != string::npos) { // JT: in >> nls_method_name // in >> error_method_name @@ -374,7 +388,7 @@ ios::pos_type CNumerics::Read(ifstream* num_file) line >> nls_relaxation; // setNonLinearErrorMethod(FiniteElement::convertErrorMethod(error_method_name)); - switch(getNonLinearErrorMethod()) + switch (getNonLinearErrorMethod()) { case FiniteElement::ENORM: // only 1 tolerance required line >> nls_error_tolerance[0]; @@ -384,13 +398,15 @@ ios::pos_type CNumerics::Read(ifstream* num_file) line >> nls_error_tolerance[0]; break; // - case FiniteElement::EVNORM: // 1 tolerance for each primary variable (for Deformation, only 1 tolerance required. Applies to x,y,z) - for(int i=0; i> nls_error_tolerance[i]; break; // - case FiniteElement::LMAX: // 1 tolerance for each primary variable (for Deformation, only 1 tolerance required. Applies to x,y,z) - for(int i=0; i> nls_error_tolerance[i]; break; // @@ -405,15 +421,15 @@ ios::pos_type CNumerics::Read(ifstream* num_file) } nls_method = 0; - if(nls_method_name.find("NEWTON") != string::npos) + if (nls_method_name.find("NEWTON") != string::npos) nls_method = 1; - else if(nls_method_name.find("JFNK") != string::npos) // Jacobian free Newton-Krylov method + else if (nls_method_name.find("JFNK") != string::npos) // Jacobian free Newton-Krylov method nls_method = 2; // line.clear(); continue; } - else if(line_string.find("$NON_LINEAR_SOLVER") != string::npos) + else if (line_string.find("$NON_LINEAR_SOLVER") != string::npos) { ScreenMessage(" --\n Using old $NON_LINEAR_SOLVER keyword.\n"); ScreenMessage(" Eventually this will be obsolete. Consider switching to\n"); @@ -431,17 +447,19 @@ ios::pos_type CNumerics::Read(ifstream* num_file) line >> nls_method_name; // nls_method = 0; - if(nls_method_name.find("NEWTON") != string::npos) + if (nls_method_name.find("NEWTON") != string::npos) nls_method = 1; - else if(nls_method_name.find("JFNK") != string::npos) // Jacobian free Newton-Krylov method + else if (nls_method_name.find("JFNK") != string::npos) // Jacobian free Newton-Krylov method nls_method = 2; // - if(nls_method > 0){ + if (nls_method > 0) + { line >> nls_error_tolerance[0]; line >> nls_plasticity_local_tolerance; error_method_name = "BNORM"; // JT: this is hardwired in old version } - else{ + else + { line >> nls_error_tolerance[0]; error_method_name = "LMAX"; // JT: this is hardwired in old version } @@ -454,19 +472,14 @@ ios::pos_type CNumerics::Read(ifstream* num_file) } //.................................................................... // subkeyword found - if(line_string.find("$LINEAR_SOLVER") != string::npos) + if (line_string.find("$LINEAR_SOLVER") != string::npos) { - std::string str_buf = GetLineFromFile1(num_file); //WW + std::string str_buf = GetLineFromFile1(num_file); // WW line.str(str_buf); #ifdef USE_PETSC - if(str_buf.find("petsc") != string::npos) //03.2012. WW + if (str_buf.find("petsc") != string::npos) // 03.2012. WW { - line >> str_buf - >> lsover_name - >> pres_name - >> ls_error_tolerance - >> ls_max_iterations - >> ls_theta; + line >> str_buf >> lsover_name >> pres_name >> ls_error_tolerance >> ls_max_iterations >> ls_theta; } else #endif @@ -479,7 +492,7 @@ ios::pos_type CNumerics::Read(ifstream* num_file) line >> ls_precond; line >> ls_storage_method; /// For GMRES. 06.2010. WW - if(ls_method == 13) + if (ls_method == 13) line >> m_cols; } line.clear(); @@ -487,7 +500,7 @@ ios::pos_type CNumerics::Read(ifstream* num_file) } //.................................................................... // JT subkeyword found - if(line_string.find("$COUPLING_ITERATIONS") != string::npos) + if (line_string.find("$COUPLING_ITERATIONS") != string::npos) { ScreenMessage("$COUPLING_ITERATIONS keyword obsolete.\n"); ScreenMessage("Use $COUPLING_CONTROL and $COUPLED_PROCESS for process couplings.\n"); @@ -495,7 +508,8 @@ ios::pos_type CNumerics::Read(ifstream* num_file) } //.................................................................... // JT subkeyword found - if(line_string.find("$COUPLING_CONTROL") != string::npos) // JT: For this process, how is coupling error handled? + if (line_string.find("$COUPLING_CONTROL") + != string::npos) // JT: For this process, how is coupling error handled? { // JT: in >> error_method_name // in >> tolerance[1:dof] @@ -505,7 +519,7 @@ ios::pos_type CNumerics::Read(ifstream* num_file) // cpl_error_specified = true; setCouplingErrorMethod(FiniteElement::convertErrorMethod(error_method_name)); - switch(getCouplingErrorMethod()) + switch (getCouplingErrorMethod()) { case FiniteElement::ENORM: // only 1 tolerance required line >> cpl_error_tolerance[0]; @@ -515,13 +529,15 @@ ios::pos_type CNumerics::Read(ifstream* num_file) line >> cpl_error_tolerance[0]; break; // - case FiniteElement::EVNORM: // 1 tolerance for each primary variable (for Deformation, only 1 tolerance required. Applies to x,y,z) - for(int i=0; i> cpl_error_tolerance[i]; break; // - case FiniteElement::LMAX: // 1 tolerance for each primary variable (for Deformation, only 1 tolerance required. Applies to x,y,z) - for(int i=0; i> cpl_error_tolerance[i]; break; // @@ -542,26 +558,32 @@ ios::pos_type CNumerics::Read(ifstream* num_file) } //.................................................................... // JT subkeyword found - if(line_string.find("$COUPLED_PROCESS") != string::npos) // JT: Is this process coupled to another process in an inner loop? + if (line_string.find("$COUPLED_PROCESS") + != string::npos) // JT: Is this process coupled to another process in an inner loop? { // in >> process name >> min iter >> max iter // line.str(GetLineFromFile1(num_file)); - line >> coupling_target; // name of coupled process -OR- process variable + line >> coupling_target; // name of coupled process -OR- process variable line >> cpl_min_iterations; line >> cpl_max_iterations; // cpl_master_process = true; // // Is coupling through a process name or a primary variable? - if(FiniteElement::convertPrimaryVariable(coupling_target) != FiniteElement::INVALID_PV){ // Then a valid process VARIABLE is entered. Use this. + if (FiniteElement::convertPrimaryVariable(coupling_target) != FiniteElement::INVALID_PV) + { // Then a valid process VARIABLE is entered. Use this. cpl_variable = coupling_target; } - else if(PCSGet(coupling_target)){ // Then a valid process is entered - cpl_process = coupling_target; + else if (PCSGet(coupling_target)) + { // Then a valid process is entered + cpl_process = coupling_target; } - else{ - ScreenMessage("WARNING. $COUPLED_PROCESS keyword encountered, but a valid process OR primary variable was not found.\n"); + else + { + ScreenMessage( + "WARNING. $COUPLED_PROCESS keyword encountered, but a valid process OR primary variable was not " + "found.\n"); cpl_master_process = false; } // @@ -569,7 +591,7 @@ ios::pos_type CNumerics::Read(ifstream* num_file) continue; } //.................................................................... - if(line_string.find("$EXTERNAL_SOLVER_OPTION") != string::npos) // subkeyword found + if (line_string.find("$EXTERNAL_SOLVER_OPTION") != string::npos) // subkeyword found { ls_extra_arg = GetLineFromFile1(num_file); trim(ls_extra_arg); @@ -577,7 +599,7 @@ ios::pos_type CNumerics::Read(ifstream* num_file) } //.................................................................... // subkeyword found - if(line_string.find("$ELE_GAUSS_POINTS") != string::npos) + if (line_string.find("$ELE_GAUSS_POINTS") != string::npos) { line.str(GetLineFromFile1(num_file)); line >> ele_gauss_points; // probably element-type-wise @@ -585,46 +607,46 @@ ios::pos_type CNumerics::Read(ifstream* num_file) continue; } // subkeyword found - if(line_string.find("$ELE_MASS_LUMPING") != string::npos) + if (line_string.find("$ELE_MASS_LUMPING") != string::npos) { line.str(GetLineFromFile1(num_file)); line >> ele_mass_lumping; line.clear(); - cout << "-> Mass lumping selected for " << pcs_type_name << "\n";// JOD 2014-11-10 + cout << "-> Mass lumping selected for " << pcs_type_name << "\n"; // JOD 2014-11-10 continue; } // subkeyword found - if(line_string.find("$ELE_UPWINDING") != string::npos) + if (line_string.find("$ELE_UPWINDING") != string::npos) { line.str(GetLineFromFile1(num_file)); - //CB now read also upwinding method + // CB now read also upwinding method line >> ele_upwinding >> ele_upwind_method; line.clear(); continue; } // subkeyword found - if(line_string.find("$ELE_SUPG") != string::npos) + if (line_string.find("$ELE_SUPG") != string::npos) { line.str(GetLineFromFile1(num_file)); - //NW - line >> ele_supg_method >> ele_supg_method_length >> - ele_supg_method_diffusivity; + // NW + line >> ele_supg_method >> ele_supg_method_length >> ele_supg_method_diffusivity; line.clear(); - cout << "->SUPG method is selected." << "\n"; + cout << "->SUPG method is selected." + << "\n"; continue; } // subkeyword found - if(line_string.find("$GRAVITY_PROFILE") != string::npos) + if (line_string.find("$GRAVITY_PROFILE") != string::npos) { - line.str(GetLineFromFile1(num_file)); //WW + line.str(GetLineFromFile1(num_file)); // WW line >> GravityProfile; line.clear(); continue; } // subkeyword found - if(line_string.find("$DYNAMIC_DAMPING") != string::npos) + if (line_string.find("$DYNAMIC_DAMPING") != string::npos) { - line.str(GetLineFromFile1(num_file)); //WW + line.str(GetLineFromFile1(num_file)); // WW DynamicDamping = new double[3]; // Default DynamicDamping[0] = 0.515; @@ -634,31 +656,32 @@ ios::pos_type CNumerics::Read(ifstream* num_file) line.clear(); continue; } - //Flux corrected transport by Kuzmin (2009) - if(line_string.find("$LOCAL_PICARD1")!=string::npos) //NW - { - line.str(GetLineFromFile1(num_file)); - line >> local_picard1_max_iterations; - line >> local_picard1_tolerance; - line.clear(); - continue; - } - if(line_string.find("$NON_LINEAR_UPDATE_VELOCITY")!=string::npos) //NW - { - line.str(GetLineFromFile1(num_file)); - line >> update_velocity_within_nonlinear; - line.clear(); - continue; - } + // Flux corrected transport by Kuzmin (2009) + if (line_string.find("$LOCAL_PICARD1") != string::npos) // NW + { + line.str(GetLineFromFile1(num_file)); + line >> local_picard1_max_iterations; + line >> local_picard1_tolerance; + line.clear(); + continue; + } + if (line_string.find("$NON_LINEAR_UPDATE_VELOCITY") != string::npos) // NW + { + line.str(GetLineFromFile1(num_file)); + line >> update_velocity_within_nonlinear; + line.clear(); + continue; + } // NW - if(line_string.find("$FEM_FCT") != string::npos) + if (line_string.find("$FEM_FCT") != string::npos) { line.str(GetLineFromFile1(num_file)); - line >> fct_method; //1: linearized FCT - line >> fct_prelimiter_type; //0: just cancel, 1: minmod, 2: superbee + line >> fct_method; // 1: linearized FCT + line >> fct_prelimiter_type; // 0: just cancel, 1: minmod, 2: superbee line >> fct_const_alpha; //-1: off, [0.0,1.0] 0: Upwind, 1: Galerkin line.clear(); - cout << "->FEM_FCT method is selected." << "\n"; + cout << "->FEM_FCT method is selected." + << "\n"; continue; } @@ -704,19 +727,19 @@ void NUMWrite(string base_file_name) //======================================================================== // File handling string num_file_name = base_file_name + NUM_FILE_EXTENSION; - fstream num_file (num_file_name.data(),ios::trunc | ios::out); - num_file.setf(ios::scientific,ios::floatfield); + fstream num_file(num_file_name.data(), ios::trunc | ios::out); + num_file.setf(ios::scientific, ios::floatfield); num_file.precision(12); if (!num_file.good()) return; - num_file.seekg(0L,ios::beg); + num_file.seekg(0L, ios::beg); //======================================================================== num_file << "GeoSys-NUM: Numerics ------------------------------------------------\n"; //======================================================================== // OUT vector int num_vector_size = (int)num_vector.size(); int i; - for(i = 0; i < num_vector_size; i++) + for (i = 0; i < num_vector_size; i++) { m_num = num_vector[i]; m_num->Write(&num_file); @@ -734,8 +757,9 @@ void NUMWrite(string base_file_name) **************************************************************************/ void CNumerics::Write(fstream* num_file) { - //KEYWORD - *num_file << "#NUMERICS" << "\n"; + // KEYWORD + *num_file << "#NUMERICS" + << "\n"; //-------------------------------------------------------------------- /*OK *num_file << " $METHOD" << "\n"; @@ -748,35 +772,41 @@ void CNumerics::Write(fstream* num_file) } */ //-------------------------------------------------------------------- - *num_file << " $PCS_TYPE" << "\n"; + *num_file << " $PCS_TYPE" + << "\n"; *num_file << " " << pcs_type_name << "\n"; //-------------------------------------------------------------------- - *num_file << " $NON_LINEAR_SOLVER" << "\n"; + *num_file << " $NON_LINEAR_SOLVER" + << "\n"; *num_file << " " << nls_method_name; - *num_file << " " << nls_error_tolerance; - *num_file << " " << nls_max_iterations; - *num_file << " " << nls_relaxation; + *num_file << " " << nls_error_tolerance; + *num_file << " " << nls_max_iterations; + *num_file << " " << nls_relaxation; *num_file << "\n"; //-------------------------------------------------------------------- - *num_file << " $LINEAR_SOLVER" << "\n"; + *num_file << " $LINEAR_SOLVER" + << "\n"; *num_file << " " << ls_method; - *num_file << " " << ls_error_method; - *num_file << " " << ls_error_tolerance; - *num_file << " " << ls_max_iterations; - *num_file << " " << ls_theta; - *num_file << " " << ls_precond; - *num_file << " " << ls_storage_method; + *num_file << " " << ls_error_method; + *num_file << " " << ls_error_tolerance; + *num_file << " " << ls_max_iterations; + *num_file << " " << ls_theta; + *num_file << " " << ls_precond; + *num_file << " " << ls_storage_method; *num_file << "\n"; //-------------------------------------------------------------------- - *num_file << " $ELE_GAUSS_POINTS" << "\n"; + *num_file << " $ELE_GAUSS_POINTS" + << "\n"; *num_file << " " << ele_gauss_points; *num_file << "\n"; //-------------------------------------------------------------------- - *num_file << " $ELE_MASS_LUMPING" << "\n"; + *num_file << " $ELE_MASS_LUMPING" + << "\n"; *num_file << " " << ele_mass_lumping; *num_file << "\n"; //-------------------------------------------------------------------- - *num_file << " $ELE_UPWINDING" << "\n"; + *num_file << " $ELE_UPWINDING" + << "\n"; *num_file << " " << ele_upwinding; *num_file << "\n"; //-------------------------------------------------------------------- @@ -899,17 +929,16 @@ LINEAR_SOLVER* DestroyLinearSolver(LINEAR_SOLVER* ls) SetLinearSolver(ls); if (ls->system_time_name) - ls->system_time_name = (char*) Free(ls->system_time_name); + ls->system_time_name = (char*)Free(ls->system_time_name); if (ls->system_time_assemble_function_name) - ls->system_time_assemble_function_name = (char*) Free( - ls->system_time_assemble_function_name); + ls->system_time_assemble_function_name = (char*)Free(ls->system_time_assemble_function_name); - //OK if (ls->name) - //OK ls->name = (char *) Free(ls->name); + // OK if (ls->name) + // OK ls->name = (char *) Free(ls->name); if (ls->b) - ls->b = (double*) Free(ls->b); + ls->b = (double*)Free(ls->b); if (ls->x) - ls->x = (double*) Free(ls->x); + ls->x = (double*)Free(ls->x); /* //WW if (ls->bc_name) ls->bc_name = (char *) Free(ls->bc_name); @@ -923,15 +952,15 @@ LINEAR_SOLVER* DestroyLinearSolver(LINEAR_SOLVER* ls) ls->sousin_name2 = (char *) Free(ls->sousin_name2); */ if (ls->lsp_name) - ls->lsp_name = (char*) Free(ls->lsp_name); + ls->lsp_name = (char*)Free(ls->lsp_name); if (ls->r) - ls->r = (double*) Free(ls->r); + ls->r = (double*)Free(ls->r); if (ls->xx) - ls->xx = (double*) Free(ls->xx); + ls->xx = (double*)Free(ls->xx); if (ls->memory) - ls->memory = (double*) Free(ls->memory); + ls->memory = (double*)Free(ls->memory); if (ls->new_memory) - ls->new_memory = (double**) DestroyMemoryLinearSolver(ls); + ls->new_memory = (double**)DestroyMemoryLinearSolver(ls); if (ls->matrix) { MXSetMatrixPointer(ls->matrix); @@ -939,12 +968,12 @@ LINEAR_SOLVER* DestroyLinearSolver(LINEAR_SOLVER* ls) } /* Multiple unknowns (Dim) / multiple solvers (MultSolvers) */ if (ls->name_ls) - ls->name_ls = (char*) Free(ls->name_ls); + ls->name_ls = (char*)Free(ls->name_ls); if (ls->name_group_ls) - ls->name_group_ls = (char*) Free(ls->name_group_ls); + ls->name_group_ls = (char*)Free(ls->name_group_ls); if (ls) - ls = (LINEAR_SOLVER*) Free(ls); + ls = (LINEAR_SOLVER*)Free(ls); return NULL; } @@ -974,9 +1003,9 @@ LINEAR_SOLVER* DestroyMemoryLinearSolver(LINEAR_SOLVER* ls) for (i = 0; i < ls->memory_number; i++) if (ls->new_memory[i]) - ls->new_memory[i] = (double*) Free(ls->new_memory[i]); + ls->new_memory[i] = (double*)Free(ls->new_memory[i]); if (ls->new_memory) - ls->new_memory = (double**) Free(ls->new_memory); + ls->new_memory = (double**)Free(ls->new_memory); return ls; } @@ -1019,26 +1048,26 @@ LINEAR_SOLVER* InitLinearSolver(LINEAR_SOLVER* ls) return ls; if (ls->b) - ls->b = (double*) Free(ls->b); - ls->b = (double*) Malloc(ls->dim * sizeof(double)); + ls->b = (double*)Free(ls->b); + ls->b = (double*)Malloc(ls->dim * sizeof(double)); if (ls->x) - ls->x = (double*) Free(ls->x); - ls->x = (double*) Malloc(ls->dim * sizeof(double)); + ls->x = (double*)Free(ls->x); + ls->x = (double*)Malloc(ls->dim * sizeof(double)); if (ls->r) - ls->r = (double*) Free(ls->r); - ls->r = (double*) Malloc(ls->dim * sizeof(double)); + ls->r = (double*)Free(ls->r); + ls->r = (double*)Malloc(ls->dim * sizeof(double)); if (ls->xx) - ls->xx = (double*) Free(ls->xx); - ls->xx = (double*) Malloc(ls->dim * sizeof(double)); + ls->xx = (double*)Free(ls->xx); + ls->xx = (double*)Malloc(ls->dim * sizeof(double)); if (ls->memory) - ls->memory = (double*) Free(ls->memory); - ls->memory = (double*) Malloc(ls->dim * sizeof(double)); + ls->memory = (double*)Free(ls->memory); + ls->memory = (double*)Malloc(ls->dim * sizeof(double)); return ls; } -#ifdef USE_MPI //WW +#ifdef USE_MPI // WW ///////////////////////////////////////////////////////////////////// /************************************************************************** FEMLib-Method: @@ -1056,21 +1085,21 @@ LINEAR_SOLVER* InitVectorLinearSolver(LINEAR_SOLVER* ls) return ls; if (ls->b) - ls->b = (double*) Free(ls->b); - ls->b = (double*) Malloc(ls->dim * sizeof(double)); + ls->b = (double*)Free(ls->b); + ls->b = (double*)Malloc(ls->dim * sizeof(double)); if (ls->x) - ls->x = (double*) Free(ls->x); - ls->x = (double*) Malloc(ls->dim * sizeof(double)); + ls->x = (double*)Free(ls->x); + ls->x = (double*)Malloc(ls->dim * sizeof(double)); if (ls->r) - ls->r = (double*) Free(ls->r); - ls->r = (double*) Malloc(ls->dim * sizeof(double)); + ls->r = (double*)Free(ls->r); + ls->r = (double*)Malloc(ls->dim * sizeof(double)); if (ls->xx) - ls->xx = (double*) Free(ls->xx); - ls->xx = (double*) Malloc(ls->dim * sizeof(double)); + ls->xx = (double*)Free(ls->xx); + ls->xx = (double*)Malloc(ls->dim * sizeof(double)); if (ls->memory) - ls->memory = (double*) Free(ls->memory); - ls->memory = (double*) Malloc(ls->dim * sizeof(double)); + ls->memory = (double*)Free(ls->memory); + ls->memory = (double*)Malloc(ls->dim * sizeof(double)); return ls; } @@ -1097,21 +1126,21 @@ void ConfigSolverProperties(void) /* Speichertechnik automatisch optimieren */ switch (max_dim) { - case 0: - sp2_start = 3; - sp2_inc = 1; - break; - case 1: - sp2_start = 11; - sp2_inc = 2; - break; - case 2: - sp2_start = 33; - sp2_inc = 6; - break; + case 0: + sp2_start = 3; + sp2_inc = 1; + break; + case 1: + sp2_start = 11; + sp2_inc = 2; + break; + case 2: + sp2_start = 33; + sp2_inc = 6; + break; } /* Umnummerierer-Methode auswaehlen */ - //WW ConfigRenumberProperties(); + // WW ConfigRenumberProperties(); /* umnummerierer muss definiert sein ! */ } @@ -1132,8 +1161,8 @@ void ConfigSolverProperties(void) 08/1999 AH Erweiterung memory (neq) 09/2004 Remove BC/Sink incoorperation *************************************************************************/ -//WW -void SetLinearSolverType(LINEAR_SOLVER* ls,CNumerics* m_num) +// WW +void SetLinearSolverType(LINEAR_SOLVER* ls, CNumerics* m_num) { if (!ls) return; @@ -1165,64 +1194,65 @@ void SetLinearSolverType(LINEAR_SOLVER* ls,CNumerics* m_num) } */ ls->store = m_num->ls_storage_method; - switch(m_num->ls_method) //OK (ls->lsp->type){ + switch (m_num->ls_method) // OK (ls->lsp->type){ { - case 1: - ls->LinearSolver = SpGauss; - break; - case 2: + case 1: + ls->LinearSolver = SpGauss; + break; + case 2: #ifndef USE_MPI - ls->LinearSolver = SpBICGSTAB; + ls->LinearSolver = SpBICGSTAB; #endif - break; - case 3: - ls->LinearSolver = SpBICG; - break; - case 4: - ls->LinearSolver = SpQMRCGSTAB; - break; - case 5: - ls->LinearSolver = SpCG; - break; - case 6: - ls->LinearSolver = SpCGNR; - break; - case 7: - ls->LinearSolver = SpCGS; - break; - case 8: - ls->LinearSolver = SpRichardson; - break; - case 9: - ls->LinearSolver = SpJOR; - break; - case 10: - ls->LinearSolver = SpSOR; - break; - case 11: - ls->LinearSolver = SpAMG1R5; - break; - case 12: - ls->LinearSolver = SpUMF; - break; - default: - cout << "***ERROR in SetLinearSolverType(): Specified linear solver type (" << - m_num->ls_method << ") is not supported. " << "\n"; - exit(1); + break; + case 3: + ls->LinearSolver = SpBICG; + break; + case 4: + ls->LinearSolver = SpQMRCGSTAB; + break; + case 5: + ls->LinearSolver = SpCG; + break; + case 6: + ls->LinearSolver = SpCGNR; + break; + case 7: + ls->LinearSolver = SpCGS; + break; + case 8: + ls->LinearSolver = SpRichardson; + break; + case 9: + ls->LinearSolver = SpJOR; + break; + case 10: + ls->LinearSolver = SpSOR; + break; + case 11: + ls->LinearSolver = SpAMG1R5; + break; + case 12: + ls->LinearSolver = SpUMF; + break; + default: + cout << "***ERROR in SetLinearSolverType(): Specified linear solver type (" << m_num->ls_method + << ") is not supported. " + << "\n"; + exit(1); } } -//WW -LINEAR_SOLVER* InitializeLinearSolver(LINEAR_SOLVER* ls,CNumerics* m_num) +// WW +LINEAR_SOLVER* InitializeLinearSolver(LINEAR_SOLVER* ls, CNumerics* m_num) { - SetLinearSolverType(ls,m_num); -//#ifdef USE_MPI //WW -// InitVectorLinearSolver(ls); -//#else + SetLinearSolverType(ls, m_num); + //#ifdef USE_MPI //WW + // InitVectorLinearSolver(ls); + //#else InitLinearSolver(ls); -//#endif + //#endif /* Internen Speicher allokieren */ - InitMemoryLinearSolver(ls,ls->memory_number); + InitMemoryLinearSolver(ls, ls->memory_number); /* Speicher initialisieren */ SetMemoryZeroLinearSolver(ls); return ls; @@ -1255,7 +1285,7 @@ LINEAR_SOLVER* InitMemoryLinearSolver(LINEAR_SOLVER* ls, int memory_number) if (ls->new_memory) DestroyMemoryLinearSolver(ls); - ls->new_memory = (double**) Malloc(memory_number * sizeof(double*)); + ls->new_memory = (double**)Malloc(memory_number * sizeof(double*)); if (ls->new_memory == NULL) return NULL; for (i = 0; i < memory_number; i++) @@ -1263,7 +1293,7 @@ LINEAR_SOLVER* InitMemoryLinearSolver(LINEAR_SOLVER* ls, int memory_number) for (i = 0; i < memory_number; i++) { - ls->new_memory[i] = (double*) Malloc(ls->dim * sizeof(double)); + ls->new_memory[i] = (double*)Malloc(ls->dim * sizeof(double)); if (ls->new_memory[i] == NULL) return DestroyMemoryLinearSolver(ls); } @@ -1325,11 +1355,11 @@ LINEAR_SOLVER* CreateLinearSolver(long store, long dim) { LINEAR_SOLVER* ls; - ls = (LINEAR_SOLVER*) Malloc(sizeof(LINEAR_SOLVER)); + ls = (LINEAR_SOLVER*)Malloc(sizeof(LINEAR_SOLVER)); if (ls == NULL) return NULL; - //OK ls->name = NULL; + // OK ls->name = NULL; ls->store = store; ls->dim = dim; ls->matrix = NULL; @@ -1402,11 +1432,11 @@ LINEAR_SOLVER* CreateLinearSolverDim(long store, int unknown_vector_dimension, l { LINEAR_SOLVER* ls; - ls = (LINEAR_SOLVER*) Malloc(sizeof(LINEAR_SOLVER)); + ls = (LINEAR_SOLVER*)Malloc(sizeof(LINEAR_SOLVER)); if (ls == NULL) return NULL; - //OK ls->name = NULL; + // OK ls->name = NULL; ls->store = store; ls->dim = dim; ls->matrix = NULL; @@ -1466,11 +1496,12 @@ double GetNumericalTimeCollocation(char* name) { CRFProcess* m_pcs = NULL; m_pcs = PCSGet(name); - if(m_pcs) + if (m_pcs) return m_pcs->m_num->ls_theta; else - cout << "Fatal error in GetNumericalTimeCollocation: No valid PCS" << "\n"; - //OK return np_array[GetNumericsIndex(name)].time_collocation; + cout << "Fatal error in GetNumericalTimeCollocation: No valid PCS" + << "\n"; + // OK return np_array[GetNumericsIndex(name)].time_collocation; return 1.0; } @@ -1494,11 +1525,7 @@ double GetNumericalTimeCollocation(char* name) /* Programmaenderungen: 1/1999 C.Thorenz Zweite Version */ /**************************************************************************/ -double NUMCalcIterationError(double* new_iteration, - double* old_iteration, - double* reference, - long length, - int method) +double NUMCalcIterationError(double* new_iteration, double* old_iteration, double* reference, long length, int method) { static long i; static double error, change, max_c, min_c; @@ -1511,84 +1538,77 @@ double NUMCalcIterationError(double* new_iteration, switch (method) { - default: - case 0: - return 0.; - /* Max. Unterschied zwischen altem und neuem Iterationsschritt */ - case 1: - for (i = 0l; i < length; i++) - error = max(error, fabs(new_iteration[i] - old_iteration[i])); - return error; - - /* Max. Unterschied zwischen altem und neuem Iterationsschritt, - jeweils normiert mit dem Mittelwert der Groesse des Wertes */ - case 2: - for (i = 0l; i < length; i++) - error = - max(error, 2. * - fabs(new_iteration[i] - - old_iteration[i]) / - (fabs(new_iteration[i]) + fabs(old_iteration[i]) + - MKleinsteZahl)); - return error; - - /* Max. Unterschied zwischen altem und neuem Iterationsschritt, - normiert mit dem groessten Wert */ - case 3: - for (i = 0l; i < length; i++) - { - error = max(error, fabs(new_iteration[i] - old_iteration[i])); - max_c = max(max(max_c, fabs(new_iteration[i])),fabs(old_iteration[i])); - } - return error / (max_c + MKleinsteZahl); + default: + case 0: + return 0.; + /* Max. Unterschied zwischen altem und neuem Iterationsschritt */ + case 1: + for (i = 0l; i < length; i++) + error = max(error, fabs(new_iteration[i] - old_iteration[i])); + return error; + + /* Max. Unterschied zwischen altem und neuem Iterationsschritt, + jeweils normiert mit dem Mittelwert der Groesse des Wertes */ + case 2: + for (i = 0l; i < length; i++) + error = max(error, 2. * fabs(new_iteration[i] - old_iteration[i]) + / (fabs(new_iteration[i]) + fabs(old_iteration[i]) + MKleinsteZahl)); + return error; + + /* Max. Unterschied zwischen altem und neuem Iterationsschritt, + normiert mit dem groessten Wert */ + case 3: + for (i = 0l; i < length; i++) + { + error = max(error, fabs(new_iteration[i] - old_iteration[i])); + max_c = max(max(max_c, fabs(new_iteration[i])), fabs(old_iteration[i])); + } + return error / (max_c + MKleinsteZahl); - /* Max. Unterschied zwischen altem und neuem Iterationsschritt, - normiert mit der Spanne der Werte */ - case 4: - for (i = 0l; i < length; i++) - { - error = max(error, fabs(new_iteration[i] - old_iteration[i])); - min_c = min(min_c, fabs(new_iteration[i])); - max_c = max(max_c, fabs(new_iteration[i])); - } - return error / (max_c - min_c + MKleinsteZahl); - - /* Max. Unterschied zwischen altem und neuem Iterationsschritt, - normiert mit dem Unterschied zum alten Zeitschritt. Die - genaueste Methode, da die Fehlerberechnung dann Zeitschritt- - unabhaengig wird! */ - case 5: - for (i = 0l; i < length; i++) - error = - max(error, - fabs(new_iteration[i] - - old_iteration[i]) / - (fabs(new_iteration[i] - reference[i]) + MKleinsteZahl)); - return error; - - /* Max. Unterschied zwischen altem und neuem Iterationsschritt, - normiert mit dem maximalen Unterschied zum alten Zeitschritt */ - case 6: - for (i = 0l; i < length; i++) - { - error = max(error, fabs(new_iteration[i] - old_iteration[i])); - change = max(change, fabs(new_iteration[i] - reference[i])); - } - return error / (change + MKleinsteZahl); - - /* Der Vektorabstand */ - case 7: - return MVekDist(old_iteration, new_iteration, length); - - /* Der Vektorabstand der Iteration, normiert mit dem Vektorabstand - zur alten Zeitebene */ - case 8: - return MVekDist(old_iteration, new_iteration, - length) / - (MVekDist(reference, new_iteration, length) + MKleinsteZahl); + /* Max. Unterschied zwischen altem und neuem Iterationsschritt, + normiert mit der Spanne der Werte */ + case 4: + for (i = 0l; i < length; i++) + { + error = max(error, fabs(new_iteration[i] - old_iteration[i])); + min_c = min(min_c, fabs(new_iteration[i])); + max_c = max(max_c, fabs(new_iteration[i])); + } + return error / (max_c - min_c + MKleinsteZahl); + + /* Max. Unterschied zwischen altem und neuem Iterationsschritt, + normiert mit dem Unterschied zum alten Zeitschritt. Die + genaueste Methode, da die Fehlerberechnung dann Zeitschritt- + unabhaengig wird! */ + case 5: + for (i = 0l; i < length; i++) + error = max(error, + fabs(new_iteration[i] - old_iteration[i]) + / (fabs(new_iteration[i] - reference[i]) + MKleinsteZahl)); + return error; + + /* Max. Unterschied zwischen altem und neuem Iterationsschritt, + normiert mit dem maximalen Unterschied zum alten Zeitschritt */ + case 6: + for (i = 0l; i < length; i++) + { + error = max(error, fabs(new_iteration[i] - old_iteration[i])); + change = max(change, fabs(new_iteration[i] - reference[i])); + } + return error / (change + MKleinsteZahl); + + /* Der Vektorabstand */ + case 7: + return MVekDist(old_iteration, new_iteration, length); + + /* Der Vektorabstand der Iteration, normiert mit dem Vektorabstand + zur alten Zeitebene */ + case 8: + return MVekDist(old_iteration, new_iteration, length) + / (MVekDist(reference, new_iteration, length) + MKleinsteZahl); } } -#endif //ifndef NEW_EQS //WW. 06.11.2008 +#endif // ifndef NEW_EQS //WW. 06.11.2008 int GetNumericsGaussPoints(int element_dimension) { @@ -1596,18 +1616,18 @@ int GetNumericsGaussPoints(int element_dimension) int g_gaussian_points = 3; switch (element_dimension) { - case 1: - m_gaussian_points = 1; - break; - case 2: - m_gaussian_points = g_gaussian_points; - break; - case 3: - m_gaussian_points = g_gaussian_points; - break; - case 4: - m_gaussian_points = g_gaussian_points; - break; + case 1: + m_gaussian_points = 1; + break; + case 2: + m_gaussian_points = g_gaussian_points; + break; + case 3: + m_gaussian_points = g_gaussian_points; + break; + case 4: + m_gaussian_points = g_gaussian_points; + break; } return m_gaussian_points; } @@ -1622,10 +1642,10 @@ int GetNumericsGaussPoints(int element_dimension) CNumerics* NUMGet(string num_name) { CNumerics* m_num = NULL; - for(int i = 0; i < (int)num_vector.size(); i++) + for (int i = 0; i < (int)num_vector.size(); i++) { m_num = num_vector[i]; - if(m_num->pcs_type_name.compare(num_name) == 0) + if (m_num->pcs_type_name.compare(num_name) == 0) return m_num; } return NULL; @@ -1642,7 +1662,7 @@ void NUMDelete() { long i; int no_num = (int)num_vector.size(); - for(i = 0; i < no_num; i++) + for (i = 0; i < no_num; i++) delete num_vector[i]; num_vector.clear(); } diff --git a/FEM/rf_num_new.h b/FEM/rf_num_new.h index 4cfe7bfad..02a6774ba 100644 --- a/FEM/rf_num_new.h +++ b/FEM/rf_num_new.h @@ -32,7 +32,7 @@ class CNumerics { public: // method - std::string method_name; //OK + std::string method_name; // OK // PCS std::string pcs_type_name; // RENUMBER @@ -47,47 +47,48 @@ class CNumerics double ls_theta; int ls_precond; int ls_storage_method; - std::string ls_extra_arg; //NW + std::string ls_extra_arg; // NW // // NLS - Non-linear Solver std::string nls_method_name; - int nls_method; // Picard or Newton - int nls_error_method; //WW + int nls_method; // Picard or Newton + int nls_error_method; // WW int nls_max_iterations; double nls_relaxation; - double nls_error_tolerance[DOF_NUMBER_MAX]; //JT2012: array function of dof + double nls_error_tolerance[DOF_NUMBER_MAX]; // JT2012: array function of dof double nls_plasticity_local_tolerance; - void setNonLinearErrorMethod (FiniteElement::ErrorMethod nls_method) { _pcs_nls_error_method = nls_method; } - FiniteElement::ErrorMethod getNonLinearErrorMethod () const { return _pcs_nls_error_method; } + void setNonLinearErrorMethod(FiniteElement::ErrorMethod nls_method) { _pcs_nls_error_method = nls_method; } + FiniteElement::ErrorMethod getNonLinearErrorMethod() const { return _pcs_nls_error_method; } // // CPL WW - std::string cpl_variable; // MB - std::string cpl_process; // JT - std::string cpl_variable_JOD; //JT->JOD. This one defaults to FLUX. I'm not sure what you want to do with it, but cpl_variable must default to "NONE". + std::string cpl_variable; // MB + std::string cpl_process; // JT + std::string cpl_variable_JOD; // JT->JOD. This one defaults to FLUX. I'm not sure what you want to do with it, but + // cpl_variable must default to "NONE". int cpl_max_iterations; - int cpl_min_iterations; // JT2012 + int cpl_min_iterations; // JT2012 double cpl_error_tolerance[DOF_NUMBER_MAX]; // JT2012: array function of dof - bool cpl_error_specified; // JT2012 + bool cpl_error_specified; // JT2012 bool cpl_master_process; - void setCouplingErrorMethod (FiniteElement::ErrorMethod cpl_method) { _pcs_cpl_error_method = cpl_method; } - FiniteElement::ErrorMethod getCouplingErrorMethod () const { return _pcs_cpl_error_method; } - // local_picard1 - double local_picard1_tolerance; - int local_picard1_max_iterations; - // velocity update within picard - int update_velocity_within_nonlinear; + void setCouplingErrorMethod(FiniteElement::ErrorMethod cpl_method) { _pcs_cpl_error_method = cpl_method; } + FiniteElement::ErrorMethod getCouplingErrorMethod() const { return _pcs_cpl_error_method; } + // local_picard1 + double local_picard1_tolerance; + int local_picard1_max_iterations; + // velocity update within picard + int update_velocity_within_nonlinear; // ELE - int ele_gauss_points; // probably element-type-wise + int ele_gauss_points; // probably element-type-wise int ele_mass_lumping; - int ele_upwind_method; //CB + int ele_upwind_method; // CB double ele_upwinding; - int ele_supg_method; //NW - int ele_supg_method_length; //NW - int ele_supg_method_diffusivity; //NW - //FEM-FCT - int fct_method; //NW - unsigned int fct_prelimiter_type; //NW - double fct_const_alpha; //NW + int ele_supg_method; // NW + int ele_supg_method_length; // NW + int ele_supg_method_diffusivity; // NW + // FEM-FCT + int fct_method; // NW + unsigned int fct_prelimiter_type; // NW + double fct_const_alpha; // NW // Deformation int GravityProfile; // LAGRANGE method //OK @@ -100,30 +101,24 @@ class CNumerics int lag_vel_method; // // Configure - void NumConfigure(bool overall_coupling_exists); //JT2012 + void NumConfigure(bool overall_coupling_exists); // JT2012 // // Dynamics bool CheckDynamic(); - double GetDynamicDamping_beta1 () const {return DynamicDamping[0]; } - double GetDynamicDamping_beta2 () const {return DynamicDamping[1]; } - double GetDynamicDamping_bbeta () const {return DynamicDamping[2]; } + double GetDynamicDamping_beta1() const { return DynamicDamping[0]; } + double GetDynamicDamping_beta2() const { return DynamicDamping[1]; } + double GetDynamicDamping_bbeta() const { return DynamicDamping[2]; } // /// For GMRES. WW - long Get_m() const {return m_cols; } + long Get_m() const { return m_cols; } CNumerics(std::string); ~CNumerics(void); std::ios::pos_type Read(std::ifstream*); void Write(std::fstream*); #ifdef USE_PETSC - const char *getLinearSolverName() const - { - return lsover_name.c_str(); - } - const char *getPreconditionerName() const - { - return pres_name.c_str(); - } + const char* getLinearSolverName() const { return lsover_name.c_str(); } + const char* getPreconditionerName() const { return pres_name.c_str(); } #endif private: @@ -135,12 +130,12 @@ class CNumerics FiniteElement::ErrorMethod _pcs_cpl_error_method; #ifdef USE_PETSC - std::string lsover_name; //WW + std::string lsover_name; // WW std::string pres_name; #endif }; -extern std::vectornum_vector; +extern std::vector num_vector; extern bool NUMRead(std::string); extern void NUMWrite(std::string); extern void NUMDelete(); @@ -181,8 +176,8 @@ struct LINEAR_SOLVER double* memory; int memory_number; double** new_memory; - void (* init_function)(); - void (* assemble_function)(double*, double*, double); + void (*init_function)(); + void (*assemble_function)(double*, double*, double); long assemble_index; long level; IntFuncDXDXL LinearSolver; @@ -194,14 +189,14 @@ struct LINEAR_SOLVER char* name_ls; long number_ls; long num_of_unknowns_ls; - //OK UNKNOWN_LINEAR_SOLVER **unknown_ls; - int unknown_vector_dimension; /* nodal degree of freedom */ - int* unknown_vector_indeces; /* pointer of field unknown_vector_index[unknown_vector_dimension] */ - long* unknown_node_numbers; /* pointer of field unknown_node_numbers[unknown_vector_dimension] */ - int* unknown_update_methods; /* pointer of field unknown_update_methods[unknown_vector_dimension] */ + // OK UNKNOWN_LINEAR_SOLVER **unknown_ls; + int unknown_vector_dimension; /* nodal degree of freedom */ + int* unknown_vector_indeces; /* pointer of field unknown_vector_index[unknown_vector_dimension] */ + long* unknown_node_numbers; /* pointer of field unknown_node_numbers[unknown_vector_dimension] */ + int* unknown_update_methods; /* pointer of field unknown_update_methods[unknown_vector_dimension] */ }; -#ifdef USE_MPI //WW +#ifdef USE_MPI // WW extern LINEAR_SOLVER* InitVectorLinearSolver(LINEAR_SOLVER*); #endif //#ifndef NEW_EQS //WW 07.11.2008 @@ -209,9 +204,9 @@ extern LINEAR_SOLVER* InitVectorLinearSolver(LINEAR_SOLVER*); extern LINEAR_SOLVER* InitLinearSolver(LINEAR_SOLVER*); // -extern void SetLinearSolverType(LINEAR_SOLVER*,CNumerics*); -extern LINEAR_SOLVER* InitializeLinearSolver(LINEAR_SOLVER*,CNumerics*); -extern LINEAR_SOLVER* InitMemoryLinearSolver(LINEAR_SOLVER*,int); +extern void SetLinearSolverType(LINEAR_SOLVER*, CNumerics*); +extern LINEAR_SOLVER* InitializeLinearSolver(LINEAR_SOLVER*, CNumerics*); +extern LINEAR_SOLVER* InitMemoryLinearSolver(LINEAR_SOLVER*, int); extern LINEAR_SOLVER* SetMemoryZeroLinearSolver(LINEAR_SOLVER*); extern LINEAR_SOLVER* SetZeroLinearSolver(LINEAR_SOLVER*); extern LINEAR_SOLVER* DestroyLinearSolver(LINEAR_SOLVER*); @@ -223,16 +218,13 @@ extern void ConfigSolverProperties(void); // // extern int GetUnknownVectorDimensionLinearSolver(LINEAR_SOLVER*); -#endif //ifndef NEW_EQS //WW 07.11.2008 +#endif // ifndef NEW_EQS //WW 07.11.2008 ////////////////////////////////////////////////////////////////////////// // NUM ////////////////////////////////////////////////////////////////////////// extern double GetNumericalTimeCollocation(char* name); extern int GetNumericsGaussPoints(int element_dimension); -extern double NUMCalcIterationError(double* new_iteration, - double* old_iteration, - double* reference, - long length, +extern double NUMCalcIterationError(double* new_iteration, double* old_iteration, double* reference, long length, int method); #endif diff --git a/FEM/rf_out_new.cpp b/FEM/rf_out_new.cpp index f51b59fad..98365eaea 100644 --- a/FEM/rf_out_new.cpp +++ b/FEM/rf_out_new.cpp @@ -61,7 +61,7 @@ using namespace std; #include "StringTools.h" #include "FileTools.h" -extern size_t max_dim; //OK411 todo +extern size_t max_dim; // OK411 todo #ifdef CHEMAPP #include "eqlink.h" @@ -73,7 +73,8 @@ extern size_t max_dim; //OK411 todo #include "SplitMPI_Communicator.h" #endif -#if defined(USE_PETSC) || defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL)//|| defined(other parallel libs)//03.3012. WW +#if defined(USE_PETSC) || defined(USE_MPI) || defined(USE_MPI_PARPROC) \ + || defined(USE_MPI_REGSOIL) //|| defined(other parallel libs)//03.3012. WW #include #endif @@ -87,12 +88,10 @@ extern size_t max_dim; //OK411 todo #endif using MeshLib::CFEMesh; //========================================================================== -vectorout_vector; - +vector out_vector; std::string defaultOutputPath = ""; // CL - /************************************************************************** FEMLib-Method: Task: OUT read function @@ -104,9 +103,7 @@ std::string defaultOutputPath = ""; // CL 06/2006 WW Remove the old files by new way 06/2010 TF reformated, restructured, signature changed, use new GEOLIB data structures **************************************************************************/ -bool OUTRead(const std::string& file_base_name, - const GEOLIB::GEOObjects& geo_obj, - const std::string& unique_name) +bool OUTRead(const std::string& file_base_name, const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) { char line[MAX_ZEILE]; std::string line_string; @@ -120,12 +117,12 @@ bool OUTRead(const std::string& file_base_name, #endif #if defined(USE_PETSC) || defined(USE_MPI) //|| defined(other parallel libs)//03.3012. WW - int rank , msize; + int rank, msize; string rank_str; MPI_Comm_rank(communicator, &rank); MPI_Comm_size(communicator, &msize); std::ifstream is; - stringstream ss (stringstream::in | stringstream::out); + stringstream ss(stringstream::in | stringstream::out); ss.clear(); ss.str(""); ss << rank; @@ -140,7 +137,8 @@ bool OUTRead(const std::string& file_base_name, out_file.seekg(0L, ios::beg); // Keyword loop - cout << "OUTRead" << "\n"; + cout << "OUTRead" + << "\n"; while (!out_file.eof()) { out_file.getline(line, MAX_ZEILE); @@ -155,21 +153,21 @@ bool OUTRead(const std::string& file_base_name, #endif out->setFileBaseName(file_base_name); // Give version in file name - //15.01.2008. WW + // 15.01.2008. WW if (line_string.find("#VERSION") != string::npos) - output_version = true; // 02.2011. WW + output_version = true; // 02.2011. WW //---------------------------------------------------------------------- // keyword found if (line_string.find("#OUTPUT") != string::npos) { position = out->Read(out_file, geo_obj, unique_name); - if(output_version) //// 02.2011. WW + if (output_version) //// 02.2011. WW { - std::string VersionStr = BuildInfo::OGS_VERSION; //02.2011 WX + std::string VersionStr = BuildInfo::OGS_VERSION; // 02.2011 WX int curPos = 0; int pos = 0; - while((pos = VersionStr.find("/",curPos)) != -1) + while ((pos = VersionStr.find("/", curPos)) != -1) { VersionStr.replace(pos, 1, "_"); curPos = pos + 1; @@ -185,8 +183,8 @@ bool OUTRead(const std::string& file_base_name, // out->setID (out_vector.size() - 1); out_file.seekg(position, ios::beg); - } // keyword found - } // eof + } // keyword found + } // eof return true; } @@ -202,24 +200,24 @@ void OUTWrite(string base_file_name) //======================================================================== // File handling string out_file_name = base_file_name + OUT_FILE_EXTENSION; - fstream out_file (out_file_name.data(),ios::trunc | ios::out); - out_file.setf(ios::scientific,ios::floatfield); + fstream out_file(out_file_name.data(), ios::trunc | ios::out); + out_file.setf(ios::scientific, ios::floatfield); out_file.precision(12); if (!out_file.good()) return; - out_file.seekg(0L,ios::beg); + out_file.seekg(0L, ios::beg); #ifdef SUPERCOMPUTER // kg44 buffer the output - char mybuffer [MY_IO_BUFSIZE * MY_IO_BUFSIZE]; - out_file.rdbuf()->pubsetbuf(mybuffer,MY_IO_BUFSIZE * MY_IO_BUFSIZE); - // + char mybuffer[MY_IO_BUFSIZE * MY_IO_BUFSIZE]; + out_file.rdbuf()->pubsetbuf(mybuffer, MY_IO_BUFSIZE * MY_IO_BUFSIZE); +// #endif //======================================================================== out_file << "GeoSys-OUT: Output ------------------------------------------------\n"; //======================================================================== // OUT vector - size_t out_vector_size (out_vector.size()); - for(size_t i = 0; i < out_vector_size; i++) + size_t out_vector_size(out_vector.size()); + for (size_t i = 0; i < out_vector_size; i++) out_vector[i]->Write(&out_file); out_file << "#STOP"; out_file.close(); @@ -242,7 +240,8 @@ void OUTWrite(string base_file_name) void OUTData(double time_current, int time_step_number, bool force_output) { #if defined(USE_MPI) // JT2012 - if(myrank != 0) return; + if (myrank != 0) + return; #endif // COutput* m_out = NULL; @@ -253,40 +252,40 @@ void OUTData(double time_current, int time_step_number, bool force_output) for (size_t i = 0; i < out_vector.size(); i++) { - OutputBySteps = false; // reset this flag for each COutput + OutputBySteps = false; // reset this flag for each COutput m_out = out_vector[i]; // MSH // m_msh = m_out->GetMSH(); m_msh = m_out->getMesh(); if (!m_msh) - cout << "Warning in OUTData - no MSH data" << "\n"; - //OK continue; + cout << "Warning in OUTData - no MSH data" + << "\n"; + // OK continue; // PCS if (m_out->_nod_value_vector.size() > 0) m_pcs = m_out->GetPCS(m_out->_nod_value_vector[0]); if (m_out->getElementValueVector().size() > 0) m_pcs = m_out->GetPCS_ELE(m_out->getElementValueVector()[0]); if (!m_pcs) - m_pcs = m_out->GetPCS(); //OK + m_pcs = m_out->GetPCS(); // OK if (!m_pcs) - cout << "Warning in OUTData - no PCS data" << "\n"; - //OK4704 continue; + cout << "Warning in OUTData - no PCS data" + << "\n"; + // OK4704 continue; //-------------------------------------------------------------------- - m_out->setTime (time_current); - size_t no_times (m_out->time_vector.size()); + m_out->setTime(time_current); + size_t no_times(m_out->time_vector.size()); //-------------------------------------------------------------------- - if (no_times == 0 && (m_out->nSteps > 0) && (time_step_number - % m_out->nSteps == 0)) + if (no_times == 0 && (m_out->nSteps > 0) && (time_step_number % m_out->nSteps == 0)) OutputBySteps = true; - if (time_step_number == 0 || force_output) //WW//JT + if (time_step_number == 0 || force_output) // WW//JT OutputBySteps = true; //====================================================================== // TECPLOT - if (m_out->dat_type_name.compare("TECPLOT") == 0 - || m_out->dat_type_name.compare("MATLAB") == 0 || m_out->dat_type_name.compare("GNUPLOT") == 0 + if (m_out->dat_type_name.compare("TECPLOT") == 0 || m_out->dat_type_name.compare("MATLAB") == 0 + || m_out->dat_type_name.compare("GNUPLOT") == 0 || m_out->dat_type_name.compare("BINARY") == 0 // 08.2012. WW - || m_out->dat_type_name.compare("CSV") == 0 - ) + || m_out->dat_type_name.compare("CSV") == 0) { // m_out->matlab_delim = " "; // if (m_out->dat_type_name.compare("MATLAB") == 0) // JT, just for commenting header for matlab @@ -295,189 +294,179 @@ void OUTData(double time_current, int time_step_number, bool force_output) switch (m_out->getGeoType()) { - case GEOLIB::GEODOMAIN: // domain data - cout << "Data output: Domain" << "\n"; - if (OutputBySteps) - { -#if defined (USE_PETSC) // || defined (other parallel solver lib). 12.2012 WW - if(m_out->dat_type_name.compare("BINARY") == 0) // 08.2012. WW - { - m_out->NODDomainWriteBinary(); - } - else - { -#endif - if (m_out->_pcon_value_vector.size() > 0) - m_out->PCONWriteDOMDataTEC(); //MX - else + case GEOLIB::GEODOMAIN: // domain data + cout << "Data output: Domain" + << "\n"; + if (OutputBySteps) { - m_out->NODWriteDOMDataTEC(); - m_out->ELEWriteDOMDataTEC(); - } -#if defined (USE_PETSC) // || defined (other parallel solver lib). 12.2012 WW - } -#endif - if (!m_out->_new_file_opened) - //WW - m_out->_new_file_opened = true; - } - else - { - for (size_t j = 0; j < no_times; j++) - if ((time_current > m_out->time_vector[j]) || fabs( - time_current - m_out->time_vector[j]) - < MKleinsteZahl) //WW MKleinsteZahl - { -#if defined (USE_PETSC) // || defined (other parallel solver lib). 01.2014 WW - if(m_out->dat_type_name.compare("BINARY") == 0) // 01.2014. WW - { - m_out->NODDomainWriteBinary(); - } - else - { +#if defined(USE_PETSC) // || defined (other parallel solver lib). 12.2012 WW + if (m_out->dat_type_name.compare("BINARY") == 0) // 08.2012. WW + { + m_out->NODDomainWriteBinary(); + } + else + { #endif if (m_out->_pcon_value_vector.size() > 0) - //MX - m_out->PCONWriteDOMDataTEC(); + m_out->PCONWriteDOMDataTEC(); // MX else { m_out->NODWriteDOMDataTEC(); m_out->ELEWriteDOMDataTEC(); } -#if defined (USE_PETSC) // || defined (other parallel solver lib). 01.2014 WW - } -#endif - m_out->time_vector.erase( - m_out->time_vector.begin() - + j); - if (!m_out->_new_file_opened) - //WW - m_out->_new_file_opened = true; - break; - } - } - break; - //------------------------------------------------------------------ - case GEOLIB::POLYLINE: // profiles along polylines - if (m_out->dat_type_name.compare("GNUPLOT") != 0) // JOD 5.3.07 - std::cout << "Data output: Polyline profile - " << m_out->getGeoName() << "\n"; - if (OutputBySteps) - { - tim_value = m_out->NODWritePLYDataTEC(time_step_number); - if (tim_value > 0.0) - //OK - m_out->TIMValue_TEC(tim_value); - if (!m_out->_new_file_opened) - //WW - m_out->_new_file_opened = true; - } - else - { - for (size_t j = 0; j < no_times; j++) - if ((time_current > m_out->time_vector[j]) || fabs( - time_current - m_out->time_vector[j]) - < MKleinsteZahl) //WW MKleinsteZahl - { - //OK - tim_value = m_out->NODWritePLYDataTEC(j + 1); - if (tim_value > 0.0) - m_out->TIMValue_TEC(tim_value); - m_out->time_vector.erase( - m_out->time_vector.begin() - + j); - if (!m_out->_new_file_opened) - //WW - m_out->_new_file_opened = true; - break; +#if defined(USE_PETSC) // || defined (other parallel solver lib). 12.2012 WW } - } - //.............................................................. - break; - //------------------------------------------------------------------ - case GEOLIB::POINT: // breakthrough curves in points - if (m_out->dat_type_name.compare("GNUPLOT") != 0) // JOD 5.3.07 - cout << "Data output: Breakthrough curves - " << m_out->getGeoName() << "\n"; - m_out->NODWritePNTDataTEC(time_current, time_step_number); - if (!m_out->_new_file_opened) - m_out->_new_file_opened = true; //WW - break; - //------------------------------------------------------------------ - case GEOLIB::SURFACE: // profiles at surfaces - cout << "Data output: Surface profile" << "\n"; - //.............................................................. - // if (m_out->_dis_type_name.compare("AVERAGE") == 0) { - if (m_out->getProcessDistributionType() == FiniteElement::AVERAGE) - { - if (OutputBySteps) - { - m_out->NODWriteSFCAverageDataTEC(time_current, - time_step_number); +#endif if (!m_out->_new_file_opened) - //WW + // WW m_out->_new_file_opened = true; } - } - //.............................................................. - else - { + else + { + for (size_t j = 0; j < no_times; j++) + if ((time_current > m_out->time_vector[j]) + || fabs(time_current - m_out->time_vector[j]) < MKleinsteZahl) // WW MKleinsteZahl + { +#if defined(USE_PETSC) // || defined (other parallel solver lib). 01.2014 WW + if (m_out->dat_type_name.compare("BINARY") == 0) // 01.2014. WW + { + m_out->NODDomainWriteBinary(); + } + else + { +#endif + if (m_out->_pcon_value_vector.size() > 0) + // MX + m_out->PCONWriteDOMDataTEC(); + else + { + m_out->NODWriteDOMDataTEC(); + m_out->ELEWriteDOMDataTEC(); + } +#if defined(USE_PETSC) // || defined (other parallel solver lib). 01.2014 WW + } +#endif + m_out->time_vector.erase(m_out->time_vector.begin() + j); + if (!m_out->_new_file_opened) + // WW + m_out->_new_file_opened = true; + break; + } + } + break; + //------------------------------------------------------------------ + case GEOLIB::POLYLINE: // profiles along polylines + if (m_out->dat_type_name.compare("GNUPLOT") != 0) // JOD 5.3.07 + std::cout << "Data output: Polyline profile - " << m_out->getGeoName() << "\n"; if (OutputBySteps) { - m_out->NODWriteSFCDataTEC(time_step_number); + tim_value = m_out->NODWritePLYDataTEC(time_step_number); + if (tim_value > 0.0) + // OK + m_out->TIMValue_TEC(tim_value); if (!m_out->_new_file_opened) - //WW + // WW m_out->_new_file_opened = true; } else { for (size_t j = 0; j < no_times; j++) - if ((time_current > - m_out->time_vector[j]) || fabs( - time_current - - m_out->time_vector[j]) - < MKleinsteZahl) //WW MKleinsteZahl m_out->NODWriteSFCDataTEC(j); + if ((time_current > m_out->time_vector[j]) + || fabs(time_current - m_out->time_vector[j]) < MKleinsteZahl) // WW MKleinsteZahl { - m_out->NODWriteSFCDataTEC(j); - m_out->time_vector.erase( - m_out->time_vector.begin() - + j); + // OK + tim_value = m_out->NODWritePLYDataTEC(j + 1); + if (tim_value > 0.0) + m_out->TIMValue_TEC(tim_value); + m_out->time_vector.erase(m_out->time_vector.begin() + j); if (!m_out->_new_file_opened) - //WW - m_out->_new_file_opened = - true; + // WW + m_out->_new_file_opened = true; break; } } - } - //.............................................................. - // ELE data - if (m_out->getElementValueVector().size() > 0) - m_out->ELEWriteSFC_TEC(); - //.............................................................. - break; - - // case 'Y': // Layer - // cout << "Data output: Layer" << "\n"; - // if (OutputBySteps) { - // m_out->NODWriteLAYDataTEC(time_step_number); - // OutputBySteps = false; - // } else { - // for (j = 0; j < no_times; j++) { - // if ((time_current > m_out->time_vector[j]) || fabs( - // time_current - m_out->time_vector[j]) - // NODWriteLAYDataTEC(j); - // m_out->time_vector.erase(m_out->time_vector.begin() - // + j); - // break; - // } - // } - // } - // - // break; - //------------------------------------------------------------------ - - default: - break; + //.............................................................. + break; + //------------------------------------------------------------------ + case GEOLIB::POINT: // breakthrough curves in points + if (m_out->dat_type_name.compare("GNUPLOT") != 0) // JOD 5.3.07 + cout << "Data output: Breakthrough curves - " << m_out->getGeoName() << "\n"; + m_out->NODWritePNTDataTEC(time_current, time_step_number); + if (!m_out->_new_file_opened) + m_out->_new_file_opened = true; // WW + break; + //------------------------------------------------------------------ + case GEOLIB::SURFACE: // profiles at surfaces + cout << "Data output: Surface profile" + << "\n"; + //.............................................................. + // if (m_out->_dis_type_name.compare("AVERAGE") == 0) { + if (m_out->getProcessDistributionType() == FiniteElement::AVERAGE) + { + if (OutputBySteps) + { + m_out->NODWriteSFCAverageDataTEC(time_current, time_step_number); + if (!m_out->_new_file_opened) + // WW + m_out->_new_file_opened = true; + } + } + //.............................................................. + else + { + if (OutputBySteps) + { + m_out->NODWriteSFCDataTEC(time_step_number); + if (!m_out->_new_file_opened) + // WW + m_out->_new_file_opened = true; + } + else + { + for (size_t j = 0; j < no_times; j++) + if ((time_current > m_out->time_vector[j]) + || fabs(time_current - m_out->time_vector[j]) + < MKleinsteZahl) // WW MKleinsteZahl m_out->NODWriteSFCDataTEC(j); + { + m_out->NODWriteSFCDataTEC(j); + m_out->time_vector.erase(m_out->time_vector.begin() + j); + if (!m_out->_new_file_opened) + // WW + m_out->_new_file_opened = true; + break; + } + } + } + //.............................................................. + // ELE data + if (m_out->getElementValueVector().size() > 0) + m_out->ELEWriteSFC_TEC(); + //.............................................................. + break; + + // case 'Y': // Layer + // cout << "Data output: Layer" << "\n"; + // if (OutputBySteps) { + // m_out->NODWriteLAYDataTEC(time_step_number); + // OutputBySteps = false; + // } else { + // for (j = 0; j < no_times; j++) { + // if ((time_current > m_out->time_vector[j]) || fabs( + // time_current - m_out->time_vector[j]) + // NODWriteLAYDataTEC(j); + // m_out->time_vector.erase(m_out->time_vector.begin() + // + j); + // break; + // } + // } + // } + // + // break; + //------------------------------------------------------------------ + + default: + break; } } //-------------------------------------------------------------------- @@ -486,79 +475,63 @@ void OUTData(double time_current, int time_step_number, bool force_output) { switch (m_out->getGeoType()) { - case GEOLIB::GEODOMAIN: // domain data - if (OutputBySteps) - { - //OK - //m_out->WriteDataVTK(time_step_number); - LegacyVtkInterface vtkOutput(m_msh, - m_out->_nod_value_vector, - m_out->_ele_value_vector, - m_out->mmp_value_vector, - m_out->msh_type_name, - m_out); + case GEOLIB::GEODOMAIN: // domain data + if (OutputBySteps) + { + // OK + // m_out->WriteDataVTK(time_step_number); + LegacyVtkInterface vtkOutput(m_msh, + m_out->_nod_value_vector, + m_out->_ele_value_vector, + m_out->mmp_value_vector, + m_out->msh_type_name, + m_out); #if defined(USE_PETSC) - vtkOutput.WriteDataVTKPETSC( - time_step_number, - m_out->_time, - m_out->file_base_name); + vtkOutput.WriteDataVTKPETSC(time_step_number, m_out->_time, m_out->file_base_name); #else - vtkOutput.WriteDataVTK(time_step_number, - m_out->_time, - m_out->file_base_name); + vtkOutput.WriteDataVTK(time_step_number, m_out->_time, m_out->file_base_name); #endif - if (!m_out->_new_file_opened) - //WW - m_out->_new_file_opened = true; - } - else - { - for (size_t j = 0; j < no_times; j++) + if (!m_out->_new_file_opened) + // WW + m_out->_new_file_opened = true; + } + else { - if (time_current >= m_out->time_vector[j]) + for (size_t j = 0; j < no_times; j++) { - //OK - //m_out->WriteDataVTK(time_step_number); - LegacyVtkInterface vtkOutput( - m_msh, - m_out->_nod_value_vector, - m_out->_ele_value_vector, - m_out->mmp_value_vector, - m_out->msh_type_name, - m_out); + if (time_current >= m_out->time_vector[j]) + { + // OK + // m_out->WriteDataVTK(time_step_number); + LegacyVtkInterface vtkOutput(m_msh, + m_out->_nod_value_vector, + m_out->_ele_value_vector, + m_out->mmp_value_vector, + m_out->msh_type_name, + m_out); #if defined(USE_PETSC) - vtkOutput.WriteDataVTKPETSC( - time_step_number, - m_out->_time, - m_out->file_base_name); - m_out->time_vector.erase( - m_out->time_vector.begin() - + j); + vtkOutput.WriteDataVTKPETSC(time_step_number, m_out->_time, m_out->file_base_name); + m_out->time_vector.erase(m_out->time_vector.begin() + j); #else - vtkOutput.WriteDataVTK( - time_step_number, - m_out->_time, - m_out->file_base_name); - m_out->time_vector.erase( - m_out->time_vector.begin() - + j); + vtkOutput.WriteDataVTK(time_step_number, m_out->_time, m_out->file_base_name); + m_out->time_vector.erase(m_out->time_vector.begin() + j); #endif - if (!m_out->_new_file_opened) - //WW - m_out->_new_file_opened = true; - break; + if (!m_out->_new_file_opened) + // WW + m_out->_new_file_opened = true; + break; + } } } - } - break; - default: - break; + break; + default: + break; } - } // PVD (ParaView) + } // PVD (ParaView) else if (m_out->dat_type_name.find("PVD") != string::npos) { if (m_out->vtk == NULL) - m_out->CreateVTKInstance(); //WW m_out->vtk = new CVTK(); + m_out->CreateVTKInstance(); // WW m_out->vtk = new CVTK(); CVTK* vtk = m_out->vtk; bool vtk_appended = false; @@ -567,75 +540,66 @@ void OUTData(double time_current, int time_step_number, bool force_output) switch (m_out->getGeoType()) { - case GEOLIB::GEODOMAIN: // domain data - { - if (time_step_number == 0) + case GEOLIB::GEODOMAIN: // domain data { - std::string pcs_type (""); - if (m_out->getProcessType() != FiniteElement::INVALID_PROCESS) - pcs_type = FiniteElement::convertProcessTypeToString ( - m_out->getProcessType()); - vtk->InitializePVD(m_out->file_base_name, - pcs_type, - vtk_appended); - } + if (time_step_number == 0) + { + std::string pcs_type(""); + if (m_out->getProcessType() != FiniteElement::INVALID_PROCESS) + pcs_type = FiniteElement::convertProcessTypeToString(m_out->getProcessType()); + vtk->InitializePVD(m_out->file_base_name, pcs_type, vtk_appended); + } - // Set VTU file name and path - std::string pvd_vtk_file_name = vtk->pvd_vtk_file_name_base; - std::stringstream stm; - stm << time_step_number; - pvd_vtk_file_name += stm.str() + ".vtu"; - std::string pvd_vtk_file_path = pathJoin(vtk->pvd_vtk_file_path_base, pvd_vtk_file_name); + // Set VTU file name and path + std::string pvd_vtk_file_name = vtk->pvd_vtk_file_name_base; + std::stringstream stm; + stm << time_step_number; + pvd_vtk_file_name += stm.str() + ".vtu"; + std::string pvd_vtk_file_path = pathJoin(vtk->pvd_vtk_file_path_base, pvd_vtk_file_name); - // Output - if (OutputBySteps) - { - vtk->WriteXMLUnstructuredGrid(pvd_vtk_file_path, m_out, - time_step_number); - VTK_Info dat; - dat.timestep = m_out->getTime(); - dat.vtk_file = pvd_vtk_file_name; - vtk->vec_dataset.push_back(dat); - vtk->UpdatePVD(vtk->pvd_file_name, vtk->vec_dataset); - } - else - { - for (size_t j = 0; j < no_times; j++) - if (time_current >= m_out->time_vector[j]) - { - vtk->WriteXMLUnstructuredGrid( - pvd_vtk_file_name, - m_out, - time_step_number); - m_out->time_vector.erase( - m_out->time_vector.begin() - + j); - VTK_Info dat; - dat.timestep = m_out->getTime(); - dat.vtk_file = pvd_vtk_file_name; - vtk->vec_dataset.push_back(dat); - vtk->UpdatePVD(vtk->pvd_file_name, - vtk->vec_dataset); - break; - } + // Output + if (OutputBySteps) + { + vtk->WriteXMLUnstructuredGrid(pvd_vtk_file_path, m_out, time_step_number); + VTK_Info dat; + dat.timestep = m_out->getTime(); + dat.vtk_file = pvd_vtk_file_name; + vtk->vec_dataset.push_back(dat); + vtk->UpdatePVD(vtk->pvd_file_name, vtk->vec_dataset); + } + else + { + for (size_t j = 0; j < no_times; j++) + if (time_current >= m_out->time_vector[j]) + { + vtk->WriteXMLUnstructuredGrid(pvd_vtk_file_name, m_out, time_step_number); + m_out->time_vector.erase(m_out->time_vector.begin() + j); + VTK_Info dat; + dat.timestep = m_out->getTime(); + dat.vtk_file = pvd_vtk_file_name; + vtk->vec_dataset.push_back(dat); + vtk->UpdatePVD(vtk->pvd_file_name, vtk->vec_dataset); + break; + } + } } - } break; - default: - break; + default: + break; } } else if (m_out->dat_type_name.compare("TOTAL_FLUX") == 0) m_out->NODWriteTotalFlux(time_current, time_step_number); // 6/2012 JOD, MW - else if (m_out->dat_type_name.compare("COMBINE_POINTS") == 0) m_out->NODWritePointsCombined(time_current); // 6/2012 for calibration JOD + else if (m_out->dat_type_name.compare("COMBINE_POINTS") == 0) + m_out->NODWritePointsCombined(time_current); // 6/2012 for calibration JOD else if (m_out->dat_type_name.compare("PRIMARY_VARIABLES") == 0) - m_out->NODWritePrimaryVariableList(time_current); //JOD 2014-11-10 + m_out->NODWritePrimaryVariableList(time_current); // JOD 2014-11-10 // ELE values, only called if ele values are defined for output, 05/2012 BG if (m_out->getElementValueVector().size() > 0) m_out->CalcELEFluxes(); - } // OUT loop + } // OUT loop //====================================================================== } @@ -649,7 +613,7 @@ void OUTData(double time_current, int time_step_number, bool force_output) void OUTDelete() { const size_t no_out = out_vector.size(); - for(size_t i = 0; i < no_out; i++) + for (size_t i = 0; i < no_out; i++) delete out_vector[i]; out_vector.clear(); } @@ -662,9 +626,9 @@ void OUTDelete() last modification: 03/2010 JT 09/2010 TF **************************************************************************/ -COutput* OUTGet(const std::string & out_name) +COutput* OUTGet(const std::string& out_name) { - FiniteElement::ProcessType pcs_type (FiniteElement::convertProcessType (out_name)); + FiniteElement::ProcessType pcs_type(FiniteElement::convertProcessType(out_name)); for (size_t i = 0; i < out_vector.size(); i++) if (out_vector[i]->getProcessType() == pcs_type) return out_vector[i]; @@ -678,14 +642,13 @@ COutput* OUTGet(const std::string & out_name) 03/2010 JT Implementation last modification: **************************************************************************/ -COutput* OUTGetRWPT(const std::string & out_name) +COutput* OUTGetRWPT(const std::string& out_name) { for (size_t i = 0; i < out_vector.size(); i++) { COutput* out(out_vector[i]); for (size_t j = 0; j < out->getRandomWalkParticleTracingValueVector().size(); j++) - if (out->getRandomWalkParticleTracingValueVector()[j].compare(out_name) == - 0) + if (out->getRandomWalkParticleTracingValueVector()[j].compare(out_name) == 0) return out; } return NULL; @@ -698,9 +661,9 @@ COutput* OUTGetRWPT(const std::string & out_name) *****************************************************************************************/ void OUTCheck() { - std::cout << "Checking output data " << "\n"; + std::cout << "Checking output data " + << "\n"; // Go through all out objects (#OUTPUT-section in input file) for (size_t i = 0; i < out_vector.size(); i++) out_vector[i]->checkConsistency(); } - diff --git a/FEM/rf_out_new.h b/FEM/rf_out_new.h index dbcefdbba..1f312ed0a 100644 --- a/FEM/rf_out_new.h +++ b/FEM/rf_out_new.h @@ -34,15 +34,13 @@ extern std::string defaultOutputPath; * @param unique_name unique name to access the geometric entities in geo_obj * @return true if file reading was successful, else false */ -bool OUTRead(const std::string& file_base_name, - const GEOLIB::GEOObjects& geo_obj, - const std::string& unique_name); +bool OUTRead(const std::string& file_base_name, const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name); extern void OUTWrite(std::string); #define OUT_FILE_EXTENSION ".out" extern void OUTData(double, const int step, bool force_output); extern void OUTDelete(); -extern COutput* OUTGet(const std::string &); -extern void OUTCheck(void); // new SB -extern COutput* OUTGetRWPT(const std::string &); //JT +extern COutput* OUTGet(const std::string&); +extern void OUTCheck(void); // new SB +extern COutput* OUTGetRWPT(const std::string&); // JT #endif diff --git a/FEM/rf_pcs.cpp b/FEM/rf_pcs.cpp index abe84caea..ff9c23266 100644 --- a/FEM/rf_pcs.cpp +++ b/FEM/rf_pcs.cpp @@ -44,7 +44,7 @@ // C++ #include -#include //WW +#include //WW #include #include #include @@ -63,11 +63,11 @@ /* Objects */ #include "pcs_dm.h" #include "rf_pcs.h" -#include "rf_st_new.h" // ST +#include "rf_st_new.h" // ST //#include "rf_bc_new.h" // ST //#include "rf_mmp_new.h" // MAT -#include "fem_ele_std.h" // ELE -#include "rf_ic_new.h" // IC +#include "fem_ele_std.h" // ELE +#include "rf_ic_new.h" // IC //#include "msh_lib.h" // ELE //#include "rf_tim_new.h" //#include "rf_out_new.h" @@ -81,9 +81,9 @@ #include "rf_msp_new.h" #include "rf_node.h" #include "rf_kinreact.h" -#include "fem_ele_vec.h"//WX:08.2011 +#include "fem_ele_vec.h" //WX:08.2011 -#ifdef MFC //WW +#ifdef MFC // WW #include "rf_fluid_momentum.h" #endif /* Tools */ @@ -110,7 +110,7 @@ REACT_BRNS* m_vec_BRNS; #elif defined(NEW_EQS) #include "equation_class.h" #else -#include "solver.h" // ConfigRenumberProperties +#include "solver.h" // ConfigRenumberProperties #include "matrix_routines.h" #endif #include "problem.h" @@ -141,8 +141,8 @@ extern void transM2toM5(void); /*-------------------- JAD ---------------------------*/ /*-----------------------------------------------------------------------*/ /* LOP */ -//16.12.2008. WW #include "rf_apl.h" // Loop... -//16.12.2008. WW #include "loop_pcs.h" +// 16.12.2008. WW #include "rf_apl.h" // Loop... +// 16.12.2008. WW #include "loop_pcs.h" extern VoidFuncVoid LOPCalcSecondaryVariables_USER; //------------------------------------------------------------------------ // PCS @@ -160,62 +160,64 @@ bool show_onces_density = true; int memory_opt = 0; int problem_2d_plane_dm; int anz_nval = 0; -int anz_nval0 = 0; //WW +int anz_nval0 = 0; // WW // -int size_eval = 0; //WW +int size_eval = 0; // WW NvalInfo* nval_data = NULL; int anz_eval = 0; EvalInfo* eval_data = NULL; -string project_title("New project"); //OK41 +string project_title("New project"); // OK41 -bool hasAnyProcessDeactivatedSubdomains = false; //NW +bool hasAnyProcessDeactivatedSubdomains = false; // NW extern double gravity_constant; //-------------------------------------------------------- // Coupling Flag. WW -bool T_Process = false; // Heat -bool H_Process = false; // Fluid -bool H2_Process = false; // Multi-phase -bool H3_Process = false; // 3-phase -bool M_Process = false; // Mechanical -bool RD_Process = false; // Richards -bool MH_Process = false; // MH monolithic scheme -bool MASS_TRANSPORT_Process = false; // Mass transport -bool FLUID_MOMENTUM_Process = false; // Momentum -bool RANDOM_WALK_Process = false; // RWPT -bool MULTI_COMPONENTIAL_FLOW_Process = false; // MCF +bool T_Process = false; // Heat +bool H_Process = false; // Fluid +bool H2_Process = false; // Multi-phase +bool H3_Process = false; // 3-phase +bool M_Process = false; // Mechanical +bool RD_Process = false; // Richards +bool MH_Process = false; // MH monolithic scheme +bool MASS_TRANSPORT_Process = false; // Mass transport +bool FLUID_MOMENTUM_Process = false; // Momentum +bool RANDOM_WALK_Process = false; // RWPT +bool MULTI_COMPONENTIAL_FLOW_Process = false; // MCF bool pcs_created = false; // -int pcs_number_deformation = -1; // JT2012 -int pcs_number_flow = -1; // JT2012 -int pcs_number_heat = -1; // JT2012 -vectorpcs_number_mass; // JT2012 +int pcs_number_deformation = -1; // JT2012 +int pcs_number_flow = -1; // JT2012 +int pcs_number_heat = -1; // JT2012 +vector pcs_number_mass; // JT2012 namespace process -{class CRFProcessDeformation; +{ +class CRFProcessDeformation; } using process::CRFProcessDeformation; using MeshLib::CNode; using MeshLib::CElem; using FiniteElement::ElementValue; -using FiniteElement::ElementValue_DM;//WX:07.2011 +using FiniteElement::ElementValue_DM; // WX:07.2011 using Math_Group::vec; #define NOCHECK_EQS #define noCHECK_ST_GROUP #define noCHECK_BC_GROUP -extern size_t max_dim; //OK411 todo +extern size_t max_dim; // OK411 todo ////////////////////////////////////////////////////////////////////////// // PCS vector ////////////////////////////////////////////////////////////////////////// // It is better to have space between data type and data name. WW -vector PCS_Solver; //WW +vector PCS_Solver; // WW vector pcs_vector; -vector ele_val_vector; //PCH -//vector ele_val_name_vector; // PCH -template T* resize(T* array, size_t old_size, size_t new_size); +vector ele_val_vector; // PCH +// vector ele_val_name_vector; // PCH +template +T* resize(T* array, size_t old_size, size_t new_size); ////////////////////////////////////////////////////////////////////////// // Construction / destruction ////////////////////////////////////////////////////////////////////////// @@ -228,13 +230,13 @@ template T* resize(T* array, size_t old_size, size_t new_size); 02/2005 WW Local elment assembly (all protected members) last modified: **************************************************************************/ -CRFProcess::CRFProcess(void) : - _problem (NULL), p_var_index(NULL), num_nodes_p_var(NULL), - fem(NULL), Memory_Type(0), Write_Matrix(false), matrix_file(NULL),WriteSourceNBC_RHS(0), +CRFProcess::CRFProcess(void) + : _problem(NULL), p_var_index(NULL), num_nodes_p_var(NULL), fem(NULL), Memory_Type(0), Write_Matrix(false), + matrix_file(NULL), WriteSourceNBC_RHS(0), #ifdef JFNK_H2M - JFNK_precond(false), norm_u_JFNK(NULL), array_u_JFNK(NULL), array_Fu_JFNK(NULL), + JFNK_precond(false), norm_u_JFNK(NULL), array_u_JFNK(NULL), array_Fu_JFNK(NULL), #endif - ele_val_name_vector (std::vector()) + ele_val_name_vector(std::vector()) { iter_lin = 0; iter_lin_max = 0; @@ -243,7 +245,7 @@ CRFProcess::CRFProcess(void) : iter_inner_cpl = 0; iter_outer_cpl = 0; TempArry = NULL; - //SB:GS4 pcs_component_number=0; //SB: counter for transport components + // SB:GS4 pcs_component_number=0; //SB: counter for transport components pcs_component_number = pcs_no_components - 1; //---------------------------------------------------------------------- // NUM @@ -251,26 +253,26 @@ CRFProcess::CRFProcess(void) : pcs_num_name[1] = NULL; pcs_sol_name = NULL; m_num = NULL; - cpl_type_name = "PARTITIONED"; //OK - num_type_name = "FEM"; //OK - rwpt_app = 0; // PCH Application types for RWPT such as Cell Dynamics, Crypto, etc. - rwpt_count = 0; // YS 05.2013 - // - for(size_t i=0; iEclipseData = NULL; //BG 09/2009, coupling to Eclipse - this->DuMuxData = NULL; //SBG 09/2009, coupling to DuMux + adaption = false; // HS 03.2008 + this->EclipseData = NULL; // BG 09/2009, coupling to Eclipse + this->DuMuxData = NULL; // SBG 09/2009, coupling to DuMux cpl_overlord = NULL; cpl_underling = NULL; pcs_is_cpl_overlord = false; pcs_is_cpl_underling = false; //---------------------------------------------------------------------- // CPL - for(int i = 0; i < 10; i++) + for (int i = 0; i < 10; i++) Shift[i] = 0; - selected = true; //OK + selected = true; // OK // MSH OK m_msh = NULL; // Reload solutions reload = -1; - nwrite_restart = 1; // kg44 write every timestep is default + nwrite_restart = 1; // kg44 write every timestep is default pcs_nval_data = NULL; pcs_eval_data = NULL; - non_linear = false; //OK/CMCD - cal_integration_point_value = false; //WW + non_linear = false; // OK/CMCD + cal_integration_point_value = false; // WW continuum = 0; - //adaption = false; JOD removed - compute_domain_face_normal = false; //WW + // adaption = false; JOD removed + compute_domain_face_normal = false; // WW use_velocities_for_transport = false; // - additioanl2ndvar_print = -1; //WW - flow_pcs_type = 0; //CB default: liquid flow, Sat = 1 - simulator = "GEOSYS"; // BG, 09/2009 - simulator_model_path = ""; // BG, 09/2009, folder with the Eclipse or DuMux files - simulator_path = ""; // BG, 09/2009, Eclipse or Dumux - simulator_well_path = ""; //KB 02/2011, Eclipse - PrecalculatedFiles = false; // BG, 01/2011, flag for using already calculated files from Eclipse or DuMux + additioanl2ndvar_print = -1; // WW + flow_pcs_type = 0; // CB default: liquid flow, Sat = 1 + simulator = "GEOSYS"; // BG, 09/2009 + simulator_model_path = ""; // BG, 09/2009, folder with the Eclipse or DuMux files + simulator_path = ""; // BG, 09/2009, Eclipse or Dumux + simulator_well_path = ""; // KB 02/2011, Eclipse + PrecalculatedFiles = false; // BG, 01/2011, flag for using already calculated files from Eclipse or DuMux SaveEclipseDataFiles = false; // Standard case: do not save files - Phase_Transition_Model = 0; // BG, 11/2010, flag for using CO2 Phase transition (0...not used, 1...used) + Phase_Transition_Model = 0; // BG, 11/2010, flag for using CO2 Phase transition (0...not used, 1...used) // SB redo wtp - dissolved_co2_pcs_name = ""; // SB, CB 10/2011 Name of MASS_TRANSPORT process used to store dissolved total CO2 in water + dissolved_co2_pcs_name + = ""; // SB, CB 10/2011 Name of MASS_TRANSPORT process used to store dissolved total CO2 in water dissolved_co2_ingas_pcs_name = ""; //---------------------------------------------------------------------- - m_bCheck = false; //OK - m_bCheckOBJ = false; //OK - m_bCheckNOD = false; //OK - m_bCheckELE = false; //OK - m_bCheckEQS = false; //OK + m_bCheck = false; // OK + m_bCheckOBJ = false; // OK + m_bCheckNOD = false; // OK + m_bCheckELE = false; // OK + m_bCheckEQS = false; // OK // - write_boundary_condition = false; //15.01.2008. WW - OutputMassOfGasInModel = false; //05/2012 BG - WriteProcessed_BC = -1; //26.08.2011. WW - accepted = true; //25.08.2008. WW - accept_steps = 0; //27.08.1008. WW - reject_steps = 0; //27.08.1008. WW - ML_Cap = 0; // 23.01.2009 PCH - PartialPS = 0; // 16.02 2009 PCH - -#if defined( USE_MPI) || defined( USE_PETSC) //WW + write_boundary_condition = false; // 15.01.2008. WW + OutputMassOfGasInModel = false; // 05/2012 BG + WriteProcessed_BC = -1; // 26.08.2011. WW + accepted = true; // 25.08.2008. WW + accept_steps = 0; // 27.08.1008. WW + reject_steps = 0; // 27.08.1008. WW + ML_Cap = 0; // 23.01.2009 PCH + PartialPS = 0; // 16.02 2009 PCH + +#if defined(USE_MPI) || defined(USE_PETSC) // WW cpu_time_assembly = 0; #endif - // New equation and solver WW +// New equation and solver WW #ifdef NEW_EQS eqs_new = NULL; configured_in_nonlinearloop = false; #endif - flag_couple_GEMS = 0; // 11.2009 HS - femFCTmode = false; //NW - this->Gl_ML = NULL; //NW - this->Gl_Vec = NULL; //NW - this->Gl_Vec1 = NULL; //NW - this->FCT_AFlux = NULL; //NW + flag_couple_GEMS = 0; // 11.2009 HS + femFCTmode = false; // NW + this->Gl_ML = NULL; // NW + this->Gl_Vec = NULL; // NW + this->Gl_Vec1 = NULL; // NW + this->FCT_AFlux = NULL; // NW #ifdef USE_PETSC this->FCT_K = NULL; this->FCT_d = NULL; #endif - ExcavMaterialGroup = -1; //01.2010 WX - PCS_ExcavState = -1; //WX - Neglect_H_ini = -1; //WX - m_conversion_rate = NULL; //WW - isRSM = false; //WW + ExcavMaterialGroup = -1; // 01.2010 WX + PCS_ExcavState = -1; // WX + Neglect_H_ini = -1; // WX + m_conversion_rate = NULL; // WW + isRSM = false; // WW eqs_x = NULL; - _hasConstrainedBC=false; + _hasConstrainedBC = false; _hasConstrainedST = false; _pcs_constant_model = 0; _pcs_constant_value = .0; _pcs_constant_curve = 0; } - -void CRFProcess::setProblemObjectPointer (Problem* problem) +void CRFProcess::setProblemObjectPointer(Problem* problem) { _problem = problem; } - -Problem* CRFProcess::getProblemObjectPointer () const +Problem* CRFProcess::getProblemObjectPointer() const { return _problem; } - /************************************************************************** FEMLib-Method: Task: @@ -412,20 +412,21 @@ Problem* CRFProcess::getProblemObjectPointer () const CRFProcess::~CRFProcess(void) { #ifdef USE_PETSC - PetscPrintf(PETSC_COMM_WORLD,"\t\n>>Total Wall clock time in the assembly for %s (with PETSC):%f s\n", FiniteElement::convertProcessTypeToString(this->getProcessType()).c_str(), cpu_time_assembly); + PetscPrintf(PETSC_COMM_WORLD, "\t\n>>Total Wall clock time in the assembly for %s (with PETSC):%f s\n", + FiniteElement::convertProcessTypeToString(this->getProcessType()).c_str(), cpu_time_assembly); #endif long i; //---------------------------------------------------------------------- // Finite element - if(fem) - delete fem; //WW + if (fem) + delete fem; // WW fem = NULL; //---------------------------------------------------------------------- // ELE: Element matrices ElementMatrix* eleMatrix = NULL; ElementValue* gp_ele = NULL; - if(Ele_Matrices.size() > 0) + if (Ele_Matrices.size() > 0) { for (i = 0; i < (long)Ele_Matrices.size(); i++) { @@ -437,9 +438,9 @@ CRFProcess::~CRFProcess(void) } //---------------------------------------------------------------------- // ELE: Element Gauss point values - if(ele_gp_value.size() > 0) + if (ele_gp_value.size() > 0) { - for(i = 0; i < (long)ele_gp_value.size(); i++) + for (i = 0; i < (long)ele_gp_value.size(); i++) { gp_ele = ele_gp_value[i]; delete gp_ele; @@ -456,9 +457,9 @@ CRFProcess::~CRFProcess(void) } //---------------------------------------------------------------------- // NOD: Release memory of node values - for(i = 0; i < (int)nod_val_vector.size(); i++) + for (i = 0; i < (int)nod_val_vector.size(); i++) { - delete [] nod_val_vector[i]; // Add []. WW + delete[] nod_val_vector[i]; // Add []. WW nod_val_vector[i] = NULL; } nod_val_vector.clear(); @@ -466,15 +467,15 @@ CRFProcess::~CRFProcess(void) // ST: CNodeValue* m_nod_val = NULL; - //Added &&m_nod_val for RSM model. 15.08.2011. WW - if(!isRSM) + // Added &&m_nod_val for RSM model. 15.08.2011. WW + if (!isRSM) { - for(i = 0; i < (int)st_node_value.size(); i++) + for (i = 0; i < (int)st_node_value.size(); i++) { m_nod_val = st_node_value[i]; - //OK delete st_node_value[i]; - //OK st_node_value[i] = NULL; - if(m_nod_val->check_me) //OK + // OK delete st_node_value[i]; + // OK st_node_value[i] = NULL; + if (m_nod_val->check_me) // OK { m_nod_val->check_me = false; delete m_nod_val; @@ -484,7 +485,7 @@ CRFProcess::~CRFProcess(void) st_node_value.clear(); } //---------------------------------------------------------------------- - for(i = 0; i < (int)bc_node_value.size(); i++) + for (i = 0; i < (int)bc_node_value.size(); i++) { delete bc_node_value[i]; bc_node_value[i] = NULL; @@ -495,23 +496,23 @@ CRFProcess::~CRFProcess(void) //---------------------------------------------------------------------- // CON continuum_vector.clear(); - //Haibing 13112006------------------------------------------------------ - for(i = 0; i < (long)ele_val_vector.size(); i++) + // Haibing 13112006------------------------------------------------------ + for (i = 0; i < (long)ele_val_vector.size(); i++) delete[] ele_val_vector[i]; ele_val_vector.clear(); //---------------------------------------------------------------------- - DeleteArray(Deactivated_SubDomain); //05.09.2007 WW + DeleteArray(Deactivated_SubDomain); // 05.09.2007 WW // 11.08.2010. WW DeleteArray(num_nodes_p_var); // 20.08.2010. WW DeleteArray(p_var_index); #ifdef JFNK_H2M - DeleteArray(array_u_JFNK); // 13.08.2010. WW - DeleteArray(array_Fu_JFNK); // 31.08.2010. WW - DeleteArray(norm_u_JFNK); //24.11.2010. WW + DeleteArray(array_u_JFNK); // 13.08.2010. WW + DeleteArray(array_Fu_JFNK); // 31.08.2010. WW + DeleteArray(norm_u_JFNK); // 24.11.2010. WW #endif //---------------------------------------------------------------------- - if (this->m_num && this->m_num->fct_method > 0) //NW + if (this->m_num && this->m_num->fct_method > 0) // NW { delete this->Gl_ML; delete this->Gl_Vec; @@ -529,21 +530,18 @@ CRFProcess::~CRFProcess(void) #endif } - // HS, 11.2011 + // HS, 11.2011 if (m_conversion_rate) delete m_conversion_rate; #if defined(USE_PETSC) // || defined(other parallel libs)//10.3012. WW - PetscPrintf(PETSC_COMM_WORLD,"\n>>PETSc solver info for %s :\n",\ - FiniteElement::convertProcessTypeToString(this->getProcessType()).c_str()); + PetscPrintf(PETSC_COMM_WORLD, "\n>>PETSc solver info for %s :\n", + FiniteElement::convertProcessTypeToString(this->getProcessType()).c_str()); delete eqs_new; - eqs_new = NULL; + eqs_new = NULL; #endif - - } - /************************************************************************** FEMLib-Method: Task: Gauss point values for CFEMSH @@ -554,8 +552,9 @@ void CRFProcess::AllocateMemGPoint() { // if (_pcs_type_name.find("FLOW") == 0) // return; - if (!ele_gp_value.empty()) return; - const size_t mesh_ele_vector_size (m_msh->ele_vector.size()); + if (!ele_gp_value.empty()) + return; + const size_t mesh_ele_vector_size(m_msh->ele_vector.size()); for (size_t i = 0; i < mesh_ele_vector_size; i++) ele_gp_value.push_back(new ElementValue(this, m_msh->ele_vector[i])); } @@ -574,12 +573,11 @@ void CRFProcess::AllocateMemGPoint() **************************************************************************/ void CRFProcess::Create() { - if (hasAnyProcessDeactivatedSubdomains) - CheckMarkedElement(); //01.2014 WW + if (hasAnyProcessDeactivatedSubdomains) + CheckMarkedElement(); // 01.2014 WW // we need the string representation of process type at some points - std::string pcs_type_name( - convertProcessTypeToString(this->getProcessType())); + std::string pcs_type_name(convertProcessTypeToString(this->getProcessType())); // Element matrix output. WW if (Write_Matrix) @@ -587,12 +585,10 @@ void CRFProcess::Create() std::cout << "->Write Matrix" << '\n'; #if defined(USE_MPI) || defined(USE_PETSC) char stro[32]; - sprintf(stro, "%d",myrank); - string m_file_name = FileName + "_" + pcs_type_name + (string)stro + - "_element_matrix.txt"; + sprintf(stro, "%d", myrank); + string m_file_name = FileName + "_" + pcs_type_name + (string)stro + "_element_matrix.txt"; #else - std::string m_file_name = FileName + "_" + pcs_type_name - + "_element_matrix.txt"; + std::string m_file_name = FileName + "_" + pcs_type_name + "_element_matrix.txt"; #endif matrix_file = new std::fstream(m_file_name.c_str(), ios::trunc | ios::out); if (!matrix_file->good()) @@ -600,18 +596,19 @@ void CRFProcess::Create() << "\n"; } //---------------------------------------------------------------------------- - if (m_msh) //OK->MB please shift to Config() + if (m_msh) // OK->MB please shift to Config() // if (_pcs_type_name.compare("GROUNDWATER_FLOW") == 0) if (this->getProcessType() == FiniteElement::GROUNDWATER_FLOW) MSHDefineMobile(this); //---------------------------------------------------------------------------- - int DOF = GetPrimaryVNumber(); //OK should be PCS member variable + int DOF = GetPrimaryVNumber(); // OK should be PCS member variable //---------------------------------------------------------------------------- // MMP - create mmp groups for each process //YD - std::cout << "->Create MMP" << "\n"; + std::cout << "->Create MMP" + << "\n"; CMediumPropertiesGroup* m_mmp_group = NULL; - int continua = 1; //WW + int continua = 1; // WW if (RD_Process) continua = 2; m_mmp_group = MMPGetGroup(pcs_type_name); @@ -626,7 +623,8 @@ void CRFProcess::Create() m_mmp_group = NULL; //---------------------------------------------------------------------------- // NUM_NEW - std::cout << "->Create NUM" << "\n"; + std::cout << "->Create NUM" + << "\n"; // if (pcs_type_name.compare("RANDOM_WALK")) { // PCH RWPT does not need this. if (this->getProcessType() != FiniteElement::RANDOM_WALK) // PCH RWPT does not need this. { @@ -637,8 +635,7 @@ void CRFProcess::Create() m_num_tmp = num_vector[i]; if ((pcs_type_name.compare(m_num_tmp->pcs_type_name) == 0) - || (m_num_tmp->pcs_type_name.compare( - pcs_primary_function_name[0]) == 0)) + || (m_num_tmp->pcs_type_name.compare(pcs_primary_function_name[0]) == 0)) { m_num = m_num_tmp; break; @@ -647,18 +644,19 @@ void CRFProcess::Create() } if (!m_num) { - std::cout << "Warning in CRFProcess::Create() - no NUM data" << "\n"; - m_num = new CNumerics(pcs_type_name); //OK + std::cout << "Warning in CRFProcess::Create() - no NUM data" + << "\n"; + m_num = new CNumerics(pcs_type_name); // OK // m_num = m_num_tmp; } else { - if (m_num->nls_max_iterations > 1) //WW + if (m_num->nls_max_iterations > 1) // WW non_linear = true; } - if (m_num->fct_method > 0) //NW + if (m_num->fct_method > 0) // NW { - //Memory_Type = 1; +// Memory_Type = 1; #ifdef USE_PETSC long gl_size = m_msh->getNumNodesGlobal(); this->FCT_K = new SparseMatrixDOK(gl_size, gl_size); @@ -673,69 +671,64 @@ void CRFProcess::Create() } //---------------------------------------------------------------------------- // EQS - create equation system - //WW CreateEQS(); + // WW CreateEQS(); std::cout << "->Create EQS" << '\n'; #if !defined(USE_PETSC) // && !defined(other parallel solver lib). 04.2012 WW #if defined(NEW_EQS) size_t k; - for(k = 0; k < fem_msh_vector.size(); k++) - if(m_msh == fem_msh_vector[k]) + for (k = 0; k < fem_msh_vector.size(); k++) + if (m_msh == fem_msh_vector[k]) break; -//WW 02.2013. Pardiso - int eqs_num = 3; + // WW 02.2013. Pardiso + int eqs_num = 3; #ifdef USE_MPI - eqs_num = 2; + eqs_num = 2; #endif - //if(type==4||type==41) - // eqs_new = EQS_Vector[2*k+1]; - if(type == 4 || (type / 10 == 4)) // 03.08.2010. WW - eqs_new = EQS_Vector[eqs_num * k + 1]; - else - { - //eqs_new = EQS_Vector[2*k]; -#ifdef USE_MPI - eqs_new = EQS_Vector[eqs_num * k]; -#else - if (getProcessType() == FiniteElement::MULTI_PHASE_FLOW || getProcessType() == FiniteElement::PS_GLOBAL - || getProcessType() == FiniteElement::TNEQ - || getProcessType() == FiniteElement::TES) - { - eqs_new = EQS_Vector[eqs_num * k + 2 ]; - } + // if(type==4||type==41) + // eqs_new = EQS_Vector[2*k+1]; + if (type == 4 || (type / 10 == 4)) // 03.08.2010. WW + eqs_new = EQS_Vector[eqs_num * k + 1]; else { +// eqs_new = EQS_Vector[2*k]; +#ifdef USE_MPI eqs_new = EQS_Vector[eqs_num * k]; - } +#else + if (getProcessType() == FiniteElement::MULTI_PHASE_FLOW || getProcessType() == FiniteElement::PS_GLOBAL + || getProcessType() == FiniteElement::TNEQ + || getProcessType() == FiniteElement::TES) + { + eqs_new = EQS_Vector[eqs_num * k + 2]; + } + else + { + eqs_new = EQS_Vector[eqs_num * k]; + } #endif - } //WW 02.2013. Pardiso + } // WW 02.2013. Pardiso #else - //WW phase=1; - //CRFProcess *m_pcs = NULL; // + // WW phase=1; + // CRFProcess *m_pcs = NULL; // // create EQS /// Configure EQS (old matrx) . WW 06.2011 - if ( getProcessType() == FiniteElement::DEFORMATION - || getProcessType() == FiniteElement::DEFORMATION_FLOW - || getProcessType() == FiniteElement::DEFORMATION_H2 ) + if (getProcessType() == FiniteElement::DEFORMATION || getProcessType() == FiniteElement::DEFORMATION_FLOW + || getProcessType() == FiniteElement::DEFORMATION_H2) { - if ( getProcessType() == FiniteElement::DEFORMATION ) - eqs = CreateLinearSolverDim(m_num->ls_storage_method, DOF, DOF - * m_msh->GetNodesNumber(true)); + if (getProcessType() == FiniteElement::DEFORMATION) + eqs = CreateLinearSolverDim(m_num->ls_storage_method, DOF, DOF * m_msh->GetNodesNumber(true)); else if (getProcessType() == FiniteElement::DEFORMATION_FLOW) { if (num_type_name.find("EXCAVATION") != string::npos) - eqs = CreateLinearSolverDim(m_num->ls_storage_method, DOF - 1, DOF - * m_msh->GetNodesNumber(true)); + eqs = CreateLinearSolverDim(m_num->ls_storage_method, DOF - 1, DOF * m_msh->GetNodesNumber(true)); else eqs = CreateLinearSolverDim(m_num->ls_storage_method, DOF, - (DOF - 1) * m_msh->GetNodesNumber(true) - + m_msh->GetNodesNumber(false)); + (DOF - 1) * m_msh->GetNodesNumber(true) + m_msh->GetNodesNumber(false)); } else if (getProcessType() == FiniteElement::DEFORMATION_H2) - if(m_num->nls_method == 1) + if (m_num->nls_method == 1) eqs = CreateLinearSolverDim(m_num->ls_storage_method, DOF, - (DOF - 2) * m_msh->GetNodesNumber(true) - + 2 * m_msh->GetNodesNumber(false)); + (DOF - 2) * m_msh->GetNodesNumber(true) + 2 * m_msh->GetNodesNumber(false)); InitializeLinearSolver(eqs, m_num); PCS_Solver.push_back(eqs); @@ -758,15 +751,14 @@ void CRFProcess::Create() eqs = m_pcs->eqs; else { - eqs = CreateLinearSolver(m_num->ls_storage_method, - m_msh->GetNodesNumber(false) * DOF); + eqs = CreateLinearSolver(m_num->ls_storage_method, m_msh->GetNodesNumber(false) * DOF); InitializeLinearSolver(eqs, m_num); PCS_Solver.push_back(eqs); } - size_unknowns = eqs->dim; //WW + size_unknowns = eqs->dim; // WW } -#endif // If NEW_EQS -#endif //END: if not use PETSC +#endif // If NEW_EQS +#endif // END: if not use PETSC // Set solver properties: EQS<->SOL // Internen Speicher allokieren // Speicher initialisieren @@ -774,23 +766,26 @@ void CRFProcess::Create() //---------------------------------------------------------------------------- // Time unit factor //WW std::cout << "->Create TIM" << '\n'; - //CTimeDiscretization* Tim = TIMGet(_pcs_type_name); + // CTimeDiscretization* Tim = TIMGet(_pcs_type_name); Tim = TIMGet(pcs_type_name); if (!Tim) { - //21.08.2008. WW - /* JT->WW: It doesn't seem like a good idea to give a non-existent Tim the properties of some specified [0] vector. + // 21.08.2008. WW + /* JT->WW: It doesn't seem like a good idea to give a non-existent Tim the properties of some specified [0] + vector. Why not set default values, and then let other "Tim" control the stepping? - In other words. If HEAT_TRANSPORT doesn't have time control, - we cannot assign a time control type for a FLOW process to a HEAT process, this could give incorrect results. - THE DEFAULTS ARE NOW SET UP SUCH THAT... if "Tim" doesn't exist, this process has no influence on the time step. + In other words. If HEAT_TRANSPORT doesn't have time control, + we cannot assign a time control type for a FLOW process to a HEAT process, this could give incorrect + results. + THE DEFAULTS ARE NOW SET UP SUCH THAT... if "Tim" doesn't exist, this process has no influence on the + time step. Tim = new CTimeDiscretization(*time_vector[0], pcs_type_name); */ Tim = new CTimeDiscretization(); Tim->pcs_type_name = pcs_type_name; - time_vector.push_back(Tim); //21.08.2008. WW + time_vector.push_back(Tim); // 21.08.2008. WW } - if(Tim->time_control_type == TimeControlType::INVALID && Tim->time_step_vector.size() > 0) + if (Tim->time_control_type == TimeControlType::INVALID && Tim->time_step_vector.size() > 0) Tim->time_control_type = TimeControlType::FIXED_STEPS; // if (Tim->time_unit.find("MINUTE") != std::string::npos) @@ -810,8 +805,7 @@ void CRFProcess::Create() else m_msh->SwitchOnQuadraticNodes(false); // - if (pcs_type_name_vector.size() && pcs_type_name_vector[0].find("DYNAMIC") - != string::npos) //WW + if (pcs_type_name_vector.size() && pcs_type_name_vector[0].find("DYNAMIC") != string::npos) // WW { setBC_danymic_problems(); setST_danymic_problems(); @@ -822,32 +816,30 @@ void CRFProcess::Create() cout << "->Create BC" << '\n'; CBoundaryConditionsGroup* m_bc_group = NULL; - //25.08.2011. WW - if(WriteProcessed_BC == 2) + // 25.08.2011. WW + if (WriteProcessed_BC == 2) Read_Processed_BC(); else { for (int i = 0; i < DOF; i++) { - //OKm_bc_group = BCGetGroup(_pcs_type_name,pcs_primary_function_name[i]); - //OKif(!m_bc_group){ + // OKm_bc_group = BCGetGroup(_pcs_type_name,pcs_primary_function_name[i]); + // OKif(!m_bc_group){ BCGroupDelete(pcs_type_name, pcs_primary_function_name[i]); m_bc_group = new CBoundaryConditionsGroup(); - //OK + // OK m_bc_group->setProcessTypeName(pcs_type_name); - m_bc_group->setProcessPrimaryVariableName( - pcs_primary_function_name[i]); //OK + m_bc_group->setProcessPrimaryVariableName(pcs_primary_function_name[i]); // OK m_bc_group->Set(this, Shift[i]); - bc_group_list.push_back(m_bc_group); //Useless, to be removed. WW + bc_group_list.push_back(m_bc_group); // Useless, to be removed. WW m_bc_group = NULL; - //OK} + // OK} } - if (bc_node_value.size() < 1) //WW - cout << "Warning: no boundary conditions specified for " - << pcs_type_name << "\n"; + if (bc_node_value.size() < 1) // WW + cout << "Warning: no boundary conditions specified for " << pcs_type_name << "\n"; - if(WriteProcessed_BC == 1) + if (WriteProcessed_BC == 1) Write_Processed_BC(); } // ST - create ST groups for each process @@ -856,22 +848,21 @@ void CRFProcess::Create() if (WriteSourceNBC_RHS == 2) // Read from file ReadRHS_of_ST_NeumannBC(); - else // WW // Calculate directly + else // WW // Calculate directly { for (int i = 0; i < DOF; i++) { - //OK m_st_group = m_st_group->Get(pcs_primary_function_name[i]); - m_st_group = STGetGroup(pcs_type_name, - pcs_primary_function_name[i]); + // OK m_st_group = m_st_group->Get(pcs_primary_function_name[i]); + m_st_group = STGetGroup(pcs_type_name, pcs_primary_function_name[i]); if (!m_st_group) { m_st_group = new CSourceTermGroup(); - //OK + // OK m_st_group->pcs_type_name = pcs_type_name; - //OK + // OK m_st_group->pcs_pv_name = pcs_primary_function_name[i]; m_st_group->Set(this, Shift[i]); - //Useless, to be removed. WW + // Useless, to be removed. WW st_group_list.push_back(m_st_group); } } @@ -892,7 +883,7 @@ void CRFProcess::Create() // NOD - config and create node values cout << "->Config NOD values" << '\n'; double* nod_values = NULL; - double* ele_values = NULL; // PCH + double* ele_values = NULL; // PCH number_of_nvals = 2 * DOF + pcs_number_of_secondary_nvals; for (int i = 0; i < pcs_number_of_primary_nvals; i++) @@ -909,14 +900,14 @@ void CRFProcess::Create() long m_msh_nod_vector_size = m_msh->NodesNumber_Quadratic; for (long j = 0; j < number_of_nvals; j++) // Swap number_of_nvals and mesh size. WW 19.12.2012 { - nod_values = new double[m_msh_nod_vector_size]; - for (int i = 0; i < m_msh_nod_vector_size; i++) - nod_values[i] = 0.0; - nod_val_vector.push_back(nod_values); + nod_values = new double[m_msh_nod_vector_size]; + for (int i = 0; i < m_msh_nod_vector_size; i++) + nod_values[i] = 0.0; + nod_val_vector.push_back(nod_values); } // Create element values - PCH - int number_of_evals = 2 * pcs_number_of_evals; //PCH, increase memory - if (number_of_evals > 0) // WW added this "if" condition + int number_of_evals = 2 * pcs_number_of_evals; // PCH, increase memory + if (number_of_evals > 0) // WW added this "if" condition { for (int i = 0; i < pcs_number_of_evals; i++) { @@ -930,7 +921,7 @@ void CRFProcess::Create() for (size_t j = 0; j < m_msh_ele_vector_size; j++) { ele_values = new double[number_of_evals]; - size_eval += number_of_evals; //WW + size_eval += number_of_evals; // WW for (int i = 0; i < number_of_evals; i++) ele_values[i] = 0.0; ele_val_vector.push_back(ele_values); @@ -939,21 +930,21 @@ void CRFProcess::Create() for (size_t j = 0; j < m_msh_ele_vector_size; j++) { ele_values = ele_val_vector[j]; - ele_values = resize(ele_values, size_eval, size_eval - + number_of_evals); + ele_values = resize(ele_values, size_eval, size_eval + number_of_evals); size_eval += number_of_evals; ele_val_vector[j] = ele_values; } } // - if(reload >= 2 && type != 4 && type / 10 != 4) // Modified at 03.08.2010. WW + if (reload >= 2 && type != 4 && type / 10 != 4) // Modified at 03.08.2010. WW { // PCH - cout << "Reloading the primary variables... " << "\n"; - ReadSolution(); //WW + cout << "Reloading the primary variables... " + << "\n"; + ReadSolution(); // WW } - if (reload < 2) // PCH: If reload is set, no need to have ICs + if (reload < 2) // PCH: If reload is set, no need to have ICs { // IC cout << "->Assign IC" << '\n'; @@ -964,30 +955,27 @@ void CRFProcess::Create() cout << "RELOAD is set to be " << reload << ". So, bypassing IC's" << "\n"; - if (pcs_type_name_vector.size() && pcs_type_name_vector[0].find("DYNAMIC") - != string::npos) //WW + if (pcs_type_name_vector.size() && pcs_type_name_vector[0].find("DYNAMIC") != string::npos) // WW setIC_danymic_problems(); // Keep all local matrices in the memory - if (type != 55) //Not for fluid momentum. WW + if (type != 55) // Not for fluid momentum. WW { if (Memory_Type != 0) AllocateLocalMatrixMemory(); - if(type == 4 || type / 10 == 4) + if (type == 4 || type / 10 == 4) { // Set initialization function // CRFProcessDeformation *dm_pcs = (CRFProcessDeformation *) (this); - CRFProcessDeformation* dm_pcs = - static_cast (this); + CRFProcessDeformation* dm_pcs = static_cast(this); dm_pcs->Initialization(); } - else // Initialize FEM calculator + else // Initialize FEM calculator { int Axisymm = 1; // ani-axisymmetry if (m_msh->isAxisymmetry()) - Axisymm = -1; // Axisymmetry is true - fem = new CFiniteElementStd(this, Axisymm - * m_msh->GetCoordinateFlag()); + Axisymm = -1; // Axisymmetry is true + fem = new CFiniteElementStd(this, Axisymm * m_msh->GetCoordinateFlag()); } } @@ -995,19 +983,19 @@ void CRFProcess::Create() if (PCSSetIC_USER) PCSSetIC_USER(pcs_type_number); - if (compute_domain_face_normal) //WW + if (compute_domain_face_normal) // WW m_msh->FaceNormal(); /// Variable index for equation. 20.08.2010. WW - if(p_var_index) - for(int i = 0; i < pcs_number_of_primary_nvals; i++) + if (p_var_index) + for (int i = 0; i < pcs_number_of_primary_nvals; i++) p_var_index[i] = GetNodeValueIndex(pcs_primary_function_name[i]) + 1; #if defined(USE_PETSC) // || defined(other parallel libs)//03.3012. WW - size_unknowns = m_msh->NodesNumber_Quadratic * pcs_number_of_primary_nvals; + size_unknowns = m_msh->NodesNumber_Quadratic * pcs_number_of_primary_nvals; #elif defined(NEW_EQS) - /// For JFNK. 01.10.2010. WW +/// For JFNK. 01.10.2010. WW #ifdef JFNK_H2M - if(m_num->nls_method == 2) + if (m_num->nls_method == 2) { size_unknowns = eqs_new->size_global; array_u_JFNK = new double[eqs_new->size_global]; @@ -1015,23 +1003,22 @@ void CRFProcess::Create() } else #endif - { + { #ifdef USE_MPI - size_unknowns = eqs_new->size_global; + size_unknowns = eqs_new->size_global; #else - size_unknowns = eqs_new->A->Dim(); + size_unknowns = eqs_new->A->Dim(); #endif - } + } #endif } - -void initializeConstrainedProcesses(std::vector &pcs_vector) +void initializeConstrainedProcesses(std::vector& pcs_vector) { // set bool for existing constrained BCs for (std::size_t i = 0; i < pcs_vector.size(); i++) { - for (std::size_t j = 0; jbc_node.size(); j++) + for (std::size_t j = 0; j < pcs_vector[i]->bc_node.size(); j++) { if (pcs_vector[i]->bc_node[j]->isConstrainedBC()) { @@ -1053,35 +1040,33 @@ void initializeConstrainedProcesses(std::vector &pcs_vector) // get the indices of velocity of flow process if contrained BC for (std::size_t i = 0; i < pcs_vector.size(); i++) { - if ( !(pcs_vector[i]->hasConstrainedBC()) ) + if (!(pcs_vector[i]->hasConstrainedBC())) continue; bool found(false); - for (std::size_t j = 0; jbc_node.size(); j++) + for (std::size_t j = 0; j < pcs_vector[i]->bc_node.size(); j++) { if (found) break; - for (std::size_t k = 0; kbc_node[j]->getNumberOfConstrainedBCs(); k++) + for (std::size_t k = 0; k < pcs_vector[i]->bc_node[j]->getNumberOfConstrainedBCs(); k++) { if (found) break; Constrained tmp(pcs_vector[i]->bc_node[j]->getConstrainedBC(k)); if (tmp.constrainedVariable == ConstrainedVariable::VELOCITY) { - CRFProcess *pcs = PCSGetFlow(); + CRFProcess* pcs = PCSGetFlow(); pcs_vector[i]->setidxVx(pcs->GetNodeValueIndex("VELOCITY_X1", true)); pcs_vector[i]->setidxVy(pcs->GetNodeValueIndex("VELOCITY_Y1", true)); pcs_vector[i]->setidxVz(pcs->GetNodeValueIndex("VELOCITY_Z1", true)); - //jump out of j & k loop - found=true; + // jump out of j & k loop + found = true; } } } } } - - /************************************************************************** FEMLib-Method: Task: Write the contribution of ST or Neumann BC to RHS to a file after @@ -1094,7 +1079,7 @@ void initializeConstrainedProcesses(std::vector &pcs_vector) **************************************************************************/ void CRFProcess::WriteRHS_of_ST_NeumannBC() { - std::string pcs_type_name (convertProcessTypeToString(this->getProcessType())); + std::string pcs_type_name(convertProcessTypeToString(this->getProcessType())); std::string m_file_name = FileName + "_" + pcs_type_name + "_ST_RHS.asc"; std::ofstream os(m_file_name.c_str(), ios::trunc | ios::out); if (!os.good()) @@ -1103,7 +1088,8 @@ void CRFProcess::WriteRHS_of_ST_NeumannBC() abort(); } - os << "$PCS_TYPE " << "\n"; + os << "$PCS_TYPE " + << "\n"; os << pcs_type_name << "\n"; os << "geo_node_number "; @@ -1130,12 +1116,13 @@ void CRFProcess::WriteRHS_of_ST_NeumannBC() **************************************************************************/ void CRFProcess::ReadRHS_of_ST_NeumannBC() { - std::string pcs_type_name (convertProcessTypeToString(this->getProcessType())); + std::string pcs_type_name(convertProcessTypeToString(this->getProcessType())); std::string m_file_name = FileName + "_" + pcs_type_name + "_ST_RHS.asc"; std::ifstream is(m_file_name.c_str(), std::ios::in); if (!is.good()) { - cout << "File " << m_file_name << " is not found" << "\n"; + cout << "File " << m_file_name << " is not found" + << "\n"; abort(); } @@ -1164,12 +1151,13 @@ void CRFProcess::ReadRHS_of_ST_NeumannBC() **************************************************************************/ void CRFProcess::Read_Processed_BC() { - std::string pcs_type_name (convertProcessTypeToString(this->getProcessType())); + std::string pcs_type_name(convertProcessTypeToString(this->getProcessType())); std::string m_file_name = FileName + "_" + pcs_type_name + "_eqs_BC.asc"; std::ifstream is(m_file_name.c_str(), std::ios::in); if (!is.good()) { - cout << "File " << m_file_name << " is not found" << "\n"; + cout << "File " << m_file_name << " is not found" + << "\n"; abort(); } @@ -1198,7 +1186,7 @@ void CRFProcess::Read_Processed_BC() **************************************************************************/ void CRFProcess::Write_Processed_BC() { - std::string pcs_type_name (convertProcessTypeToString(this->getProcessType())); + std::string pcs_type_name(convertProcessTypeToString(this->getProcessType())); std::string m_file_name = FileName + "_" + pcs_type_name + "_eqs_BC.asc"; std::ofstream os(m_file_name.c_str(), ios::trunc | ios::out); if (!os.good()) @@ -1207,7 +1195,8 @@ void CRFProcess::Write_Processed_BC() abort(); } - os << "$PCS_TYPE " << "\n"; + os << "$PCS_TYPE " + << "\n"; os << pcs_type_name << "\n"; os << "geo_node_number "; @@ -1231,53 +1220,51 @@ void CRFProcess::Write_Processed_BC() 04/2006 WW last modified: **************************************************************************/ -void CRFProcess:: WriteSolution() +void CRFProcess::WriteSolution() { - if ( reload == 2 || reload <= 0 ) + if (reload == 2 || reload <= 0) return; - //kg44 write out only between nwrite_restart timesteps - if ( ( aktueller_zeitschritt % nwrite_restart ) > 0 ) + // kg44 write out only between nwrite_restart timesteps + if ((aktueller_zeitschritt % nwrite_restart) > 0) return; - std::string pcs_type_name (convertProcessTypeToString(this->getProcessType())); + std::string pcs_type_name(convertProcessTypeToString(this->getProcessType())); #if defined(USE_PETSC) //|| defined(other parallel libs)//03.3012. WW int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); - std::string m_file_name = FileName + "_" + pcs_type_name + "_" - + pcs_primary_function_name[0] + "_primary_value_" + std::string m_file_name = FileName + "_" + pcs_type_name + "_" + pcs_primary_function_name[0] + "_primary_value_" + number2str(rank) + ".asc"; #else - std::string m_file_name = FileName + "_" + pcs_type_name + "_" + - pcs_primary_function_name[0] + "_primary_value.asc"; + std::string m_file_name + = FileName + "_" + pcs_type_name + "_" + pcs_primary_function_name[0] + "_primary_value.asc"; #endif - std::ofstream os ( m_file_name.c_str(), ios::trunc | ios::out ); - if (!os.good() ) + std::ofstream os(m_file_name.c_str(), ios::trunc | ios::out); + if (!os.good()) { cout << "Failure to open file: " << m_file_name << "\n"; abort(); } - os.precision(15); // 15 digits accuracy seems enough? more fields are filled up with random numbers! - os.setf(std::ios_base::scientific,std::ios_base::floatfield); + os.precision(15); // 15 digits accuracy seems enough? more fields are filled up with random numbers! + os.setf(std::ios_base::scientific, std::ios_base::floatfield); int j; - int* idx(new int [2 * pcs_number_of_primary_nvals]); - for ( j = 0; j < pcs_number_of_primary_nvals; j++ ) + int* idx(new int[2 * pcs_number_of_primary_nvals]); + for (j = 0; j < pcs_number_of_primary_nvals; j++) { - idx[j] = GetNodeValueIndex ( pcs_primary_function_name[j] ); + idx[j] = GetNodeValueIndex(pcs_primary_function_name[j]); idx[j + pcs_number_of_primary_nvals] = idx[j] + 1; } - for (size_t i = 0; i < m_msh->GetNodesNumber ( false ); i++ ) + for (size_t i = 0; i < m_msh->GetNodesNumber(false); i++) { - for ( j = 0; j < 2 * pcs_number_of_primary_nvals; j++ ) - os << GetNodeValue ( i,idx[j] ) << " "; + for (j = 0; j < 2 * pcs_number_of_primary_nvals; j++) + os << GetNodeValue(i, idx[j]) << " "; os << "\n"; } os.close(); - cout << "Write solutions for timestep " << aktueller_zeitschritt << " into file " << - m_file_name << "\n"; - delete [] idx; + cout << "Write solutions for timestep " << aktueller_zeitschritt << " into file " << m_file_name << "\n"; + delete[] idx; } /************************************************************************** @@ -1287,21 +1274,20 @@ void CRFProcess:: WriteSolution() 04/2006 WW last modified: **************************************************************************/ -void CRFProcess:: ReadSolution() +void CRFProcess::ReadSolution() { - std::string pcs_type_name (convertProcessTypeToString(this->getProcessType())); + std::string pcs_type_name(convertProcessTypeToString(this->getProcessType())); #if defined(USE_PETSC) int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); - std::string m_file_name = FileName + "_" + pcs_type_name + "_" - + pcs_primary_function_name[0] + "_primary_value_" + std::string m_file_name = FileName + "_" + pcs_type_name + "_" + pcs_primary_function_name[0] + "_primary_value_" + number2str(rank) + ".asc"; #else - std::string m_file_name = FileName + "_" + pcs_type_name + "_" + - pcs_primary_function_name[0] + "_primary_value.asc"; + std::string m_file_name + = FileName + "_" + pcs_type_name + "_" + pcs_primary_function_name[0] + "_primary_value.asc"; #endif - std::ifstream is ( m_file_name.c_str(), ios::in ); + std::ifstream is(m_file_name.c_str(), ios::in); if (!is.good()) { cout << "Failure to open file: " << m_file_name << "\n"; @@ -1309,27 +1295,28 @@ void CRFProcess:: ReadSolution() } int j; - int* idx (new int [2 * pcs_number_of_primary_nvals]); - double* val (new double [2 * pcs_number_of_primary_nvals]); + int* idx(new int[2 * pcs_number_of_primary_nvals]); + double* val(new double[2 * pcs_number_of_primary_nvals]); - for (j = 0; j < pcs_number_of_primary_nvals; j++ ) + for (j = 0; j < pcs_number_of_primary_nvals; j++) { - idx[j] = GetNodeValueIndex ( pcs_primary_function_name[j] ); + idx[j] = GetNodeValueIndex(pcs_primary_function_name[j]); idx[j + pcs_number_of_primary_nvals] = idx[j] + 1; } - for (size_t i = 0; i < m_msh->GetNodesNumber ( false ); i++ ) + for (size_t i = 0; i < m_msh->GetNodesNumber(false); i++) { - for (j = 0; j < 2 * pcs_number_of_primary_nvals; j++ ) + for (j = 0; j < 2 * pcs_number_of_primary_nvals; j++) is >> val[j]; is >> ws; - for (int j = 0; j < pcs_number_of_primary_nvals; j++ ) { - SetNodeValue (i, idx[j], val[j+pcs_number_of_primary_nvals] ); - SetNodeValue (i, idx[j+pcs_number_of_primary_nvals], val[j+pcs_number_of_primary_nvals] ); + for (int j = 0; j < pcs_number_of_primary_nvals; j++) + { + SetNodeValue(i, idx[j], val[j + pcs_number_of_primary_nvals]); + SetNodeValue(i, idx[j + pcs_number_of_primary_nvals], val[j + pcs_number_of_primary_nvals]); } } is.close(); - delete [] idx; - delete [] val; + delete[] idx; + delete[] val; } /************************************************************************** @@ -1344,7 +1331,7 @@ void CRFProcess::setIC_danymic_problems() const char* function_name[7]; int i, j, nv; nv = 0; - if(max_dim == 1) // 2D + if (max_dim == 1) // 2D { nv = 5; function_name[0] = "DISPLACEMENT_X1"; @@ -1353,7 +1340,7 @@ void CRFProcess::setIC_danymic_problems() function_name[3] = "VELOCITY_DM_Y"; function_name[4] = "PRESSURE1"; } - else //3D + else // 3D { nv = 7; function_name[0] = "DISPLACEMENT_X1"; @@ -1368,14 +1355,13 @@ void CRFProcess::setIC_danymic_problems() CInitialCondition* m_ic = NULL; long no_ics = (long)ic_vector.size(); int nidx; - for(i = 0; i < nv; i++) + for (i = 0; i < nv; i++) { nidx = GetNodeValueIndex(function_name[i]); - for(j = 0; j < no_ics; j++) + for (j = 0; j < no_ics; j++) { m_ic = ic_vector[j]; - if(m_ic->getProcessPrimaryVariable() == - FiniteElement::convertPrimaryVariable(function_name[i])) + if (m_ic->getProcessPrimaryVariable() == FiniteElement::convertPrimaryVariable(function_name[i])) m_ic->Set(nidx); } } @@ -1392,7 +1378,7 @@ void CRFProcess::setST_danymic_problems() { const char* function_name[7]; size_t nv = 0; - if (max_dim == 1) // 2D + if (max_dim == 1) // 2D { nv = 5; function_name[0] = "DISPLACEMENT_X1"; @@ -1400,7 +1386,7 @@ void CRFProcess::setST_danymic_problems() function_name[2] = "VELOCITY_DM_X"; function_name[3] = "VELOCITY_DM_Y"; function_name[4] = "PRESSURE1"; - } //3D + } // 3D else { nv = 7; @@ -1415,7 +1401,7 @@ void CRFProcess::setST_danymic_problems() // ST - create ST groups for each process CSourceTermGroup* m_st_group = NULL; - std::string pcs_type_name (convertProcessTypeToString(this->getProcessType())); + std::string pcs_type_name(convertProcessTypeToString(this->getProcessType())); for (size_t i = 0; i < nv; i++) { m_st_group = STGetGroup(pcs_type_name, function_name[i]); @@ -1425,7 +1411,7 @@ void CRFProcess::setST_danymic_problems() m_st_group->pcs_type_name = pcs_type_name; m_st_group->pcs_pv_name = function_name[i]; m_st_group->Set(this, Shift[i], function_name[i]); - st_group_list.push_back(m_st_group); //Useless, to be removed. WW + st_group_list.push_back(m_st_group); // Useless, to be removed. WW } } } @@ -1441,7 +1427,7 @@ void CRFProcess::setBC_danymic_problems() { const char* function_name[7]; size_t nv = 0; - if (max_dim == 1) // 2D + if (max_dim == 1) // 2D { nv = 5; function_name[0] = "DISPLACEMENT_X1"; @@ -1449,7 +1435,7 @@ void CRFProcess::setBC_danymic_problems() function_name[2] = "VELOCITY_DM_X"; function_name[3] = "VELOCITY_DM_Y"; function_name[4] = "PRESSURE1"; - } //3D + } // 3D else { nv = 7; @@ -1464,17 +1450,17 @@ void CRFProcess::setBC_danymic_problems() cout << "->Create BC" << '\n'; CBoundaryConditionsGroup* m_bc_group = NULL; - std::string pcs_type_name (convertProcessTypeToString(this->getProcessType())); + std::string pcs_type_name(convertProcessTypeToString(this->getProcessType())); for (size_t i = 0; i < nv; i++) { BCGroupDelete(pcs_type_name, function_name[i]); m_bc_group = new CBoundaryConditionsGroup(); - //OK + // OK m_bc_group->setProcessTypeName(pcs_type_name); - //OK + // OK m_bc_group->setProcessPrimaryVariableName(function_name[i]); m_bc_group->Set(this, Shift[i], function_name[i]); - bc_group_list.push_back(m_bc_group); //Useless, to be removed. WW + bc_group_list.push_back(m_bc_group); // Useless, to be removed. WW } } @@ -1488,9 +1474,9 @@ void CRFProcess::setBC_danymic_problems() void CRFProcess::ConfigureCouplingForLocalAssemblier() { bool Dyn = false; - if(pcs_type_name_vector.size() && pcs_type_name_vector[0].find("DYNAMIC") != string::npos) + if (pcs_type_name_vector.size() && pcs_type_name_vector[0].find("DYNAMIC") != string::npos) Dyn = true; - if(fem) + if (fem) fem->ConfigureCoupling(this, Shift, Dyn); } @@ -1504,17 +1490,17 @@ void PCSDestroyAllProcesses(void) CRFProcess* m_process = NULL; long i; int j; - //---------------------------------------------------------------------- +//---------------------------------------------------------------------- #if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW - // SOLver -#ifdef NEW_EQS //WW +// SOLver +#ifdef NEW_EQS // WW #if defined(USE_MPI) - for(j = 0; j < (int)EQS_Vector.size(); j += 2) //WW + for (j = 0; j < (int)EQS_Vector.size(); j += 2) // WW #else - for(j = 0; j < (int)EQS_Vector.size(); j++) //WW + for (j = 0; j < (int)EQS_Vector.size(); j++) // WW #endif { - if(EQS_Vector[j]) + if (EQS_Vector[j]) delete EQS_Vector[j]; EQS_Vector[j] = NULL; #if defined(USE_MPI) @@ -1524,72 +1510,67 @@ void PCSDestroyAllProcesses(void) #else // ifdef NEW_EQS // SOLDelete() LINEAR_SOLVER* eqs; - for(j = 0; j < (int)PCS_Solver.size(); j++) + for (j = 0; j < (int)PCS_Solver.size(); j++) { eqs = PCS_Solver[j]; - if(eqs->unknown_vector_indeces) - eqs->unknown_vector_indeces = \ - (int*) Free(eqs->unknown_vector_indeces); - if(eqs->unknown_node_numbers) - eqs->unknown_node_numbers = \ - (long*) Free(eqs->unknown_node_numbers); - if(eqs->unknown_update_methods) - eqs->unknown_update_methods = \ - (int*) Free(eqs->unknown_update_methods); + if (eqs->unknown_vector_indeces) + eqs->unknown_vector_indeces = (int*)Free(eqs->unknown_vector_indeces); + if (eqs->unknown_node_numbers) + eqs->unknown_node_numbers = (long*)Free(eqs->unknown_node_numbers); + if (eqs->unknown_update_methods) + eqs->unknown_update_methods = (int*)Free(eqs->unknown_update_methods); eqs = DestroyLinearSolver(eqs); } - PCS_Solver.clear(); //WW + PCS_Solver.clear(); // WW #endif - //------ +//------ #endif //#if defined(USE_PETSC) // || defined(other parallel libs)//03.3012. WW - //---------------------------------------------------------------------- // PCS - for(j = 0; j < (int)pcs_vector.size(); j++) + for (j = 0; j < (int)pcs_vector.size(); j++) { m_process = pcs_vector[j]; -#ifdef USE_MPI //WW +#ifdef USE_MPI // WW // if(myrank==0) m_process->Print_CPU_time_byAssembly(); #endif - if(m_process->pcs_nval_data) - m_process->pcs_nval_data = (PCS_NVAL_DATA*) Free(m_process->pcs_nval_data); - if(m_process->pcs_eval_data) - m_process->pcs_eval_data = (PCS_EVAL_DATA*) Free(m_process->pcs_eval_data); + if (m_process->pcs_nval_data) + m_process->pcs_nval_data = (PCS_NVAL_DATA*)Free(m_process->pcs_nval_data); + if (m_process->pcs_eval_data) + m_process->pcs_eval_data = (PCS_EVAL_DATA*)Free(m_process->pcs_eval_data); #ifdef PCS_NOD for (i = 0; i < NodeListSize(); i++) { k = GetNode(i); - k->values[m_process->pcs_number] = - (double*)Free(k->values[m_process->pcs_number]); + k->values[m_process->pcs_number] = (double*)Free(k->values[m_process->pcs_number]); } #endif - if(m_process->TempArry) //MX - m_process->TempArry = (double*) Free(m_process->TempArry); + if (m_process->TempArry) // MX + m_process->TempArry = (double*)Free(m_process->TempArry); delete (m_process); } - pcs_vector.clear(); //WW + pcs_vector.clear(); // WW //---------------------------------------------------------------------- // MSH - for(i = 0; i < (long)fem_msh_vector.size(); i++) + for (i = 0; i < (long)fem_msh_vector.size(); i++) { - if(fem_msh_vector[i]) + if (fem_msh_vector[i]) delete fem_msh_vector[i]; fem_msh_vector[i] = NULL; } fem_msh_vector.clear(); - //---------------------------------------------------------------------- +//---------------------------------------------------------------------- - // DOM WW +// DOM WW #if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW #if defined(USE_MPI) - //if(myrank==0) - dom_vector[myrank]->PrintEQS_CPUtime(); //WW + // if(myrank==0) + dom_vector[myrank]->PrintEQS_CPUtime(); // WW #endif - for(i = 0; i < (long)dom_vector.size(); i++) + for (i = 0; i < (long)dom_vector.size(); i++) { - if(dom_vector[i]) + if (dom_vector[i]) delete dom_vector[i]; dom_vector[i] = NULL; } @@ -1597,24 +1578,24 @@ void PCSDestroyAllProcesses(void) #endif //#if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW //---------------------------------------------------------------------- // ELE - for(i = 0; i < (long)ele_val_vector.size(); i++) + for (i = 0; i < (long)ele_val_vector.size(); i++) delete ele_val_vector[i]; ele_val_vector.clear(); //---------------------------------------------------------------------- // IC ICDelete() - for(i = 0; i < (long)ic_vector.size(); i++) + for (i = 0; i < (long)ic_vector.size(); i++) delete ic_vector[i]; ic_vector.clear(); //---------------------------------------------------------------------- - MSPDelete(); //WW - BCDelete(); //WW - ICDelete(); //HS - BCGroupDelete(); //HS - STDelete(); //WW - STGroupsDelete(); //HS - GEOLIB_Clear_GeoLib_Data(); //HS + MSPDelete(); // WW + BCDelete(); // WW + ICDelete(); // HS + BCGroupDelete(); // HS + STDelete(); // WW + STGroupsDelete(); // HS + GEOLIB_Clear_GeoLib_Data(); // HS //...................................................................... - TIMDelete(); //OK + TIMDelete(); // OK OUTDelete(); NUMDelete(); MFPDelete(); @@ -1650,7 +1631,8 @@ bool PCSRead(std::string file_base_name) std::ifstream pcs_file(pcs_file_name.data(), ios::in); if (!pcs_file.good()) { - cout << "Warning: no PCS data *.pcs file is missing" << "\n"; + cout << "Warning: no PCS data *.pcs file is missing" + << "\n"; return false; } @@ -1667,20 +1649,20 @@ bool PCSRead(std::string file_base_name) line_string = GetUncommentedLine(line_string); if (line_string.find("#STOP") != string::npos) break; - indexCh1a = (int) line_string.find_first_of(CommentK.c_str()); - indexCh2a = (int) line_string.find("#PROCESS"); + indexCh1a = (int)line_string.find_first_of(CommentK.c_str()); + indexCh2a = (int)line_string.find("#PROCESS"); //---------------------------------------------------------------------- // keyword found if (indexCh2a > indexCh1a && (indexCh1a == -1)) { CRFProcess* m_pcs = new CRFProcess(); - m_pcs->file_name_base = file_base_name; //OK + m_pcs->file_name_base = file_base_name; // OK position = m_pcs->Read(&pcs_file); - m_pcs->PCSReadConfigurations(); //JT + m_pcs->PCSReadConfigurations(); // JT m_pcs->pcs_number = pcs_vector.size(); - //RelocateDeformationProcess(m_pcs); + // RelocateDeformationProcess(m_pcs); // if (m_pcs->_pcs_type_name.find("DEFORMATION") != string::npos) { // TF if (isDeformationProcess(m_pcs->getProcessType())) { @@ -1688,20 +1670,21 @@ bool PCSRead(std::string file_base_name) pcs_vector[pcs_vector.size() - 1]->pcs_number = pcs_vector.size(); delete m_pcs; } - else{ + else + { pcs_vector.push_back(m_pcs); } pcs_file.seekg(position, std::ios::beg); - } // keyword found - } // eof + } // keyword found + } // eof - std::cout << "done, read " << pcs_vector.size() << " processes" << "\n"; + std::cout << "done, read " << pcs_vector.size() << " processes" + << "\n"; return true; } - /************************************************************************** FEMLib-Method: Task: Copy data to dm_pcs from PCS read function @@ -1712,11 +1695,11 @@ bool PCSRead(std::string file_base_name) CRFProcess* CRFProcess::CopyPCStoDM_PCS() { // Numerics - if(num_type_name.compare("STRONG_DISCONTINUITY") == 0) + if (num_type_name.compare("STRONG_DISCONTINUITY") == 0) enhanced_strain_dm = 1; - CRFProcessDeformation* dm_pcs (new CRFProcessDeformation()); - dm_pcs->setProcessType (this->getProcessType()); + CRFProcessDeformation* dm_pcs(new CRFProcessDeformation()); + dm_pcs->setProcessType(this->getProcessType()); dm_pcs->pcs_type_name_vector.push_back(pcs_type_name_vector[0].data()); dm_pcs->Write_Matrix = Write_Matrix; dm_pcs->WriteSourceNBC_RHS = WriteSourceNBC_RHS; @@ -1726,27 +1709,27 @@ CRFProcess* CRFProcess::CopyPCStoDM_PCS() dm_pcs->reload = reload; dm_pcs->nwrite_restart = nwrite_restart; dm_pcs->isPCSDeformation = true; - dm_pcs->isPCSFlow = this->isPCSFlow; //JT - dm_pcs->isPCSMultiFlow = this->isPCSMultiFlow; //JT - //WW - dm_pcs->write_boundary_condition = write_boundary_condition; - if(!dm_pcs->Deactivated_SubDomain) + dm_pcs->isPCSFlow = this->isPCSFlow; // JT + dm_pcs->isPCSMultiFlow = this->isPCSMultiFlow; // JT + // WW + dm_pcs->write_boundary_condition = write_boundary_condition; + if (!dm_pcs->Deactivated_SubDomain) dm_pcs->Deactivated_SubDomain = new int[NumDeactivated_SubDomains]; - for(int i = 0; i < NumDeactivated_SubDomains; i++) + for (int i = 0; i < NumDeactivated_SubDomains; i++) dm_pcs->Deactivated_SubDomain[i] = Deactivated_SubDomain[i]; pcs_deformation = 1; - //WX:01.2011 for coupled excavation - if(ExcavMaterialGroup >= 0) + // WX:01.2011 for coupled excavation + if (ExcavMaterialGroup >= 0) { dm_pcs->ExcavMaterialGroup = ExcavMaterialGroup; dm_pcs->ExcavDirection = ExcavDirection; dm_pcs->ExcavBeginCoordinate = ExcavBeginCoordinate; dm_pcs->ExcavCurve = ExcavCurve; } - dm_pcs->Neglect_H_ini = Neglect_H_ini;//WX:08.2011 - dm_pcs->UpdateIniState = UpdateIniState;//WX:10.2011 + dm_pcs->Neglect_H_ini = Neglect_H_ini; // WX:08.2011 + dm_pcs->UpdateIniState = UpdateIniState; // WX:10.2011 // - return dynamic_cast (dm_pcs); + return dynamic_cast(dm_pcs); } /************************************************************************** @@ -1757,35 +1740,38 @@ CRFProcess* CRFProcess::CopyPCStoDM_PCS() **************************************************************************/ void CRFProcess::PCSReadConfigurations() { - if(pcs_type_name_vector.size() > 1) + if (pcs_type_name_vector.size() > 1) { string pname = pcs_type_name_vector[0] + pcs_type_name_vector[1]; pcs_type_name_vector.pop_back(); - if(pname.find("FLOW") != string::npos && pname.find("DEFORMATION") != string::npos) + if (pname.find("FLOW") != string::npos && pname.find("DEFORMATION") != string::npos) { - setProcessType (FiniteElement::DEFORMATION_FLOW); + setProcessType(FiniteElement::DEFORMATION_FLOW); MH_Process = true; // MH monolithic scheme if (pname.find("DYNAMIC") != string::npos) pcs_type_name_vector[0] = "DYNAMIC"; } } - else if(getProcessType() == FiniteElement::DEFORMATION_FLOW) + else if (getProcessType() == FiniteElement::DEFORMATION_FLOW) { - //NW - std::cout << "***Error: DEFORMATION_FLOW is vague definition." << - "\n"; + // NW + std::cout << "***Error: DEFORMATION_FLOW is vague definition." + << "\n"; exit(0); } - if(isFlowProcess(getProcessType())){ + if (isFlowProcess(getProcessType())) + { this->isPCSFlow = true; H_Process = true; } - if(isMultiFlowProcess(getProcessType())){ + if (isMultiFlowProcess(getProcessType())) + { this->isPCSMultiFlow = true; H2_Process = true; } - if(isDeformationProcess(getProcessType())){ + if (isDeformationProcess(getProcessType())) + { this->isPCSDeformation = true; M_Process = true; } @@ -1814,7 +1800,7 @@ std::ios::pos_type CRFProcess::Read(std::ifstream* pcs_file) std::stringstream line_stream; std::string pcs_type_name; - saturation_switch = false; // JOD for Richards + saturation_switch = false; // JOD for Richards //---------------------------------------------------------------------- while (!new_keyword) { @@ -1830,7 +1816,7 @@ std::ios::pos_type CRFProcess::Read(std::ifstream* pcs_file) // WW Comment line if (line_string.find_first_of(CommentK.c_str()) != string::npos) return position; - //SB check for comment sign ; + // SB check for comment sign ; line_string = GetUncommentedLine(line_string); //.................................................................... // subkeyword found @@ -1849,48 +1835,54 @@ std::ios::pos_type CRFProcess::Read(std::ifstream* pcs_file) line_stream.str(line_string); line_stream >> pcs_type_name; pcs_type_name_vector.push_back(pcs_type_name); - this->setProcessType (FiniteElement::convertProcessType(pcs_type_name)); + this->setProcessType(FiniteElement::convertProcessType(pcs_type_name)); line_stream.clear(); - if (isFlowProcess (this->getProcessType())) + if (isFlowProcess(this->getProcessType())) { H_Process = true; - this->isPCSFlow = true; //JT2012 - pcs_number_flow = pcs_vector.size(); //JT2012 - if(this->getProcessType() == FiniteElement::PS_GLOBAL || - this->getProcessType() == FiniteElement::MULTI_PHASE_FLOW || - //this->getProcessType() == FiniteElement::TNEQ || no multiphase flow - pcs_type_name.find("H2") != string::npos){ - this->isPCSMultiFlow = true; + this->isPCSFlow = true; // JT2012 + pcs_number_flow = pcs_vector.size(); // JT2012 + if (this->getProcessType() == FiniteElement::PS_GLOBAL + || this->getProcessType() == FiniteElement::MULTI_PHASE_FLOW + || + // this->getProcessType() == FiniteElement::TNEQ || no multiphase flow + pcs_type_name.find("H2") != string::npos) + { + this->isPCSMultiFlow = true; } } if (isDeformationProcess(this->getProcessType())) { M_Process = true; - this->isPCSDeformation = true; //JT2012 - //JT: "pcs_number_deformation" is set in CRFProcessDeformation::Initialization() + this->isPCSDeformation = true; // JT2012 + // JT: "pcs_number_deformation" is set in CRFProcessDeformation::Initialization() } if (this->getProcessType() == FiniteElement::MASS_TRANSPORT) { H_Process = true; MASS_TRANSPORT_Process = true; - this->isPCSMass = true; //JT2012 - pcs_number_mass[pcs_no_components] = pcs_vector.size(); //JT2012 + this->isPCSMass = true; // JT2012 + pcs_number_mass[pcs_no_components] = pcs_vector.size(); // JT2012 pcs_no_components++; this->setProcessPrimaryVariable(FiniteElement::CONCENTRATION); } - if (this->getProcessType() == FiniteElement::MULTI_COMPONENTIAL_FLOW){ + if (this->getProcessType() == FiniteElement::MULTI_COMPONENTIAL_FLOW) + { MULTI_COMPONENTIAL_FLOW_Process = true; } - if (this->getProcessType() == FiniteElement::HEAT_TRANSPORT){ + if (this->getProcessType() == FiniteElement::HEAT_TRANSPORT) + { T_Process = true; - this->isPCSHeat = true; //JT2012 - pcs_number_heat = pcs_vector.size(); //JT2012 + this->isPCSHeat = true; // JT2012 + pcs_number_heat = pcs_vector.size(); // JT2012 } - if (this->getProcessType() == FiniteElement::FLUID_MOMENTUM){ + if (this->getProcessType() == FiniteElement::FLUID_MOMENTUM) + { FLUID_MOMENTUM_Process = true; } - if (this->getProcessType() == FiniteElement::RANDOM_WALK){ + if (this->getProcessType() == FiniteElement::RANDOM_WALK) + { RANDOM_WALK_Process = true; } } @@ -1953,19 +1945,19 @@ std::ios::pos_type CRFProcess::Read(std::ifstream* pcs_file) // subkeyword found if (line_string.find("$ELEMENT_MATRIX_OUTPUT") != string::npos) { - *pcs_file >> Write_Matrix; //WW + *pcs_file >> Write_Matrix; // WW pcs_file->ignore(MAX_ZEILE, '\n'); continue; } //.................................................................... - //WW + // WW if (line_string.find("$BOUNDARY_CONDITION_OUTPUT") != string::npos) { write_boundary_condition = true; continue; } //.................................................................... - //BG 05/2012 + // BG 05/2012 if (line_string.find("$OutputMassOfGasInModel") != string::npos) { OutputMassOfGasInModel = true; @@ -1975,23 +1967,22 @@ std::ios::pos_type CRFProcess::Read(std::ifstream* pcs_file) // subkeyword found if (line_string.find("$ST_RHS") != string::npos) { - *pcs_file >> WriteSourceNBC_RHS; //WW + *pcs_file >> WriteSourceNBC_RHS; // WW pcs_file->ignore(MAX_ZEILE, '\n'); continue; } - if (line_string.find("$PROCESSED_BC") != string::npos) //25.08.2011. WW + if (line_string.find("$PROCESSED_BC") != string::npos) // 25.08.2011. WW { *pcs_file >> WriteProcessed_BC; pcs_file->ignore(MAX_ZEILE, '\n'); continue; } - //.................................................................... // subkeyword found if (line_string.find("$MEMORY_TYPE") != string::npos) { - *pcs_file >> Memory_Type; //WW + *pcs_file >> Memory_Type; // WW pcs_file->ignore(MAX_ZEILE, '\n'); continue; } @@ -1999,16 +1990,16 @@ std::ios::pos_type CRFProcess::Read(std::ifstream* pcs_file) // subkeyword found if (line_string.find("$RELOAD") != string::npos) { - *pcs_file >> reload; //WW + *pcs_file >> reload; // WW if (reload == 1 || reload == 3) - *pcs_file >> nwrite_restart; //kg44 read number of timesteps between writing restart files + *pcs_file >> nwrite_restart; // kg44 read number of timesteps between writing restart files pcs_file->ignore(MAX_ZEILE, '\n'); continue; } // subkeyword found if (line_string.find("$DEACTIVATED_SUBDOMAIN") != string::npos) { - //WW + // WW *pcs_file >> NumDeactivated_SubDomains >> ws; Deactivated_SubDomain = new int[NumDeactivated_SubDomains]; for (int i = 0; i < NumDeactivated_SubDomains; i++) @@ -2051,70 +2042,70 @@ std::ios::pos_type CRFProcess::Read(std::ifstream* pcs_file) if (line_string.find("CONTINUUM") != string::npos) { *pcs_file >> line_string; - //WW + // WW double w_m = strtod(line_string.data(), NULL); continuum_vector.push_back(w_m); - //WW + // WW continuum_vector.push_back(1.0 - w_m); - break; //WW + break; // WW } pcs_file->ignore(MAX_ZEILE, '\n'); } continue; } - //OK + // OK if (line_string.find("$SATURATION_SWITCH") != string::npos) { saturation_switch = true; - ; + ; continue; } - //SB4900 + // SB4900 if (line_string.find("$USE_VELOCITIES_FOR_TRANSPORT") != string::npos) { // Only for fluid momentum process - if (this->getProcessType () == FiniteElement::FLUID_MOMENTUM) + if (this->getProcessType() == FiniteElement::FLUID_MOMENTUM) use_velocities_for_transport = true; continue; } - //Interface to Eclipse and Dumux, BG, 09/2010 + // Interface to Eclipse and Dumux, BG, 09/2010 // if(line_string.find("$SIMULATOR")!=string::npos) { //OK - if(line_string.compare("$SIMULATOR") == 0) // BG, 09/2010, coupling to Eclipse and DuMux + if (line_string.compare("$SIMULATOR") == 0) // BG, 09/2010, coupling to Eclipse and DuMux { *pcs_file >> this->simulator; continue; } - if(line_string.find("$SIMULATOR_PATH") == 0) // BG, 09/2010, coupling to Eclipse and DuMux + if (line_string.find("$SIMULATOR_PATH") == 0) // BG, 09/2010, coupling to Eclipse and DuMux { *pcs_file >> this->simulator_path; continue; } // BG, 09/2010, coupling to Eclipse and DuMux - if(line_string.find("$SIMULATOR_MODEL_PATH") == 0) + if (line_string.find("$SIMULATOR_MODEL_PATH") == 0) { *pcs_file >> this->simulator_model_path; continue; } // BG, 09/2010, coupling to Eclipse and DuMux - if(line_string.find("$USE_PRECALCULATED_FILES") == 0) + if (line_string.find("$USE_PRECALCULATED_FILES") == 0) { this->PrecalculatedFiles = true; continue; } // WTP, 04/2013, coupling to Eclipse (save data files) - if(line_string.find("$SAVE_ECLIPSE_DATA_FILES") == 0) + if (line_string.find("$SAVE_ECLIPSE_DATA_FILES") == 0) { this->SaveEclipseDataFiles = true; continue; } // KB, 02/2011, coupling to Eclipse and DuMux - if(line_string.find("$SIMULATOR_WELL_PATH") == 0) + if (line_string.find("$SIMULATOR_WELL_PATH") == 0) { *pcs_file >> this->simulator_well_path; continue; } // BG, NB 11/2010, calculating phase transition for CO2 - if(line_string.find("$PHASE_TRANSITION") == 0) + if (line_string.find("$PHASE_TRANSITION") == 0) { string tempstring; *pcs_file >> tempstring; @@ -2123,28 +2114,29 @@ std::ios::pos_type CRFProcess::Read(std::ifstream* pcs_file) continue; } // SB redo WTP - if(line_string.find("$DISSOLVED_CO2_PCS_NAME")==0){ //SB, CB 10/2011 - *pcs_file >> this->dissolved_co2_pcs_name; + if (line_string.find("$DISSOLVED_CO2_PCS_NAME") == 0) + { // SB, CB 10/2011 + *pcs_file >> this->dissolved_co2_pcs_name; continue; } - if(line_string.find("$DISSOLVED_CO2_INGAS_PCS_NAME")==0){ //SB, CB 10/2011 + if (line_string.find("$DISSOLVED_CO2_INGAS_PCS_NAME") == 0) + { // SB, CB 10/2011 *pcs_file >> this->dissolved_co2_ingas_pcs_name; continue; } - //WX:07.2011 - if(line_string.find("$TIME_CONTROLLED_EXCAVATION") == 0) + // WX:07.2011 + if (line_string.find("$TIME_CONTROLLED_EXCAVATION") == 0) { - *pcs_file >> ExcavMaterialGroup >> ExcavDirection >> - ExcavBeginCoordinate >> ExcavCurve; + *pcs_file >> ExcavMaterialGroup >> ExcavDirection >> ExcavBeginCoordinate >> ExcavCurve; continue; } - if(line_string.find("$NEGLECT_H_INI_EFFECT")==0)//WX:10.2011 + if (line_string.find("$NEGLECT_H_INI_EFFECT") == 0) // WX:10.2011 { *pcs_file >> Neglect_H_ini; continue; } - if(line_string.find("$UPDATE_INI_STATE")==0)//WX:10.2011 + if (line_string.find("$UPDATE_INI_STATE") == 0) // WX:10.2011 { *pcs_file >> UpdateIniState; continue; @@ -2154,17 +2146,17 @@ std::ios::pos_type CRFProcess::Read(std::ifstream* pcs_file) *pcs_file >> _pcs_constant_model; switch (_pcs_constant_model) { - case 0: - break; - case 1: - *pcs_file >> _pcs_constant_value; - break; - case 2: - *pcs_file >> _pcs_constant_curve; - break; - default: - std::cout << "-> invalid CONSTANT model " << _pcs_constant_model << std::endl; - break; + case 0: + break; + case 1: + *pcs_file >> _pcs_constant_value; + break; + case 2: + *pcs_file >> _pcs_constant_curve; + break; + default: + std::cout << "-> invalid CONSTANT model " << _pcs_constant_model << std::endl; + break; } if (_pcs_constant_model > 0) std::cout << "-> CONSTAT is activated." << std::endl; @@ -2176,7 +2168,6 @@ std::ios::pos_type CRFProcess::Read(std::ifstream* pcs_file) return position; } - /************************************************************************** FEMLib-Method: 01/2004 OK Implementation @@ -2186,28 +2177,30 @@ std::ios::pos_type CRFProcess::Read(std::ifstream* pcs_file) **************************************************************************/ void PCSWrite(string file_base_name) { - if((int)pcs_vector.size() < 1) + if ((int)pcs_vector.size() < 1) return; //---------------------------------------------------------------------- // File handling string pcs_file_name = file_base_name + PCS_FILE_EXTENSION; - fstream pcs_file (pcs_file_name.data(),ios::trunc | ios::out); + fstream pcs_file(pcs_file_name.data(), ios::trunc | ios::out); pcs_file.clear(); //---------------------------------------------------------------------- // PCS loop - cout << "PCSWrite" << "\n"; + cout << "PCSWrite" + << "\n"; CRFProcess* m_pcs = NULL; - for(int i = 0; i < (int)pcs_vector.size(); i++) + for (int i = 0; i < (int)pcs_vector.size(); i++) { m_pcs = pcs_vector[i]; - pcs_file << "#PROCESS" << "\n"; + pcs_file << "#PROCESS" + << "\n"; m_pcs->Write(&pcs_file); } //---------------------------------------------------------------------- - pcs_file << "#STOP" << "\n"; + pcs_file << "#STOP" + << "\n"; } - /************************************************************************** FEMLib-Method: Task: @@ -2218,26 +2211,30 @@ void PCSWrite(string file_base_name) **************************************************************************/ void CRFProcess::Write(std::fstream* pcs_file) { - *pcs_file << " $PCS_TYPE" << "\n"; + *pcs_file << " $PCS_TYPE" + << "\n"; *pcs_file << " " << convertProcessTypeToString(this->getProcessType()) << "\n"; - *pcs_file << " $NUM_TYPE" << "\n"; + *pcs_file << " $NUM_TYPE" + << "\n"; *pcs_file << " " << num_type_name << "\n"; - *pcs_file << " $CPL_TYPE" << "\n"; + *pcs_file << " $CPL_TYPE" + << "\n"; *pcs_file << " " << cpl_type_name << "\n"; - *pcs_file << " $TIM_TYPE" << "\n"; + *pcs_file << " $TIM_TYPE" + << "\n"; *pcs_file << " " << convertTimTypeToString(tim_type) << "\n"; if (msh_type_name.size() > 0) { - *pcs_file << " $MSH_TYPE" << "\n"; + *pcs_file << " $MSH_TYPE" + << "\n"; *pcs_file << " " << msh_type_name << "\n"; } } - /************************************************************************** FEMLib-Method: Task: @@ -2246,7 +2243,7 @@ void CRFProcess::Write(std::fstream* pcs_file) last modified: 10/2010 changed access to process type **************************************************************************/ -CRFProcess* PCSGet(const std::string &pcs_type_name) +CRFProcess* PCSGet(const std::string& pcs_type_name) { FiniteElement::ProcessType pcs_type(FiniteElement::convertProcessType(pcs_type_name)); for (size_t i = 0; i < pcs_vector.size(); i++) @@ -2275,18 +2272,18 @@ CRFProcess* PCSGet(FiniteElement::ProcessType pcs_type) last modified: 10/2010 TF changed access to process type **************************************************************************/ -CRFProcess* PCSGetNew(const string &pcs_type_name, const string &primary_variable_name) +CRFProcess* PCSGetNew(const string& pcs_type_name, const string& primary_variable_name) { CRFProcess* m_pcs_return = NULL; - FiniteElement::ProcessType pcs_type (FiniteElement::convertProcessType (pcs_type_name)); + FiniteElement::ProcessType pcs_type(FiniteElement::convertProcessType(pcs_type_name)); int matches = 0; for (size_t i = 0; i < pcs_vector.size(); i++) { CRFProcess* pcs = pcs_vector[i]; // if (pcs->pcs_type_name.compare(pcs_type_name) == 0) { TF - if (pcs->getProcessType () == pcs_type) + if (pcs->getProcessType() == pcs_type) { for (size_t j = 0; j < pcs->GetPrimaryVNumber(); j++) if (primary_variable_name.compare(pcs->GetPrimaryVName(j)) == 0) @@ -2304,7 +2301,6 @@ CRFProcess* PCSGetNew(const string &pcs_type_name, const string &primary_variabl return m_pcs_return; } - ////////////////////////////////////////////////////////////////////////// // Access ////////////////////////////////////////////////////////////////////////// @@ -2318,16 +2314,16 @@ CRFProcess* CRFProcess::GetProcessByFunctionName(char* name) return m_process; int i; int no_processes = (int)pcs_vector.size(); - for(i = 0; i < no_processes; i++) + for (i = 0; i < no_processes; i++) { m_process = pcs_vector[i]; - if ( strcmp(StrUp(m_process->pcs_primary_function_name[0]),StrUp(name)) == 0 ) + if (strcmp(StrUp(m_process->pcs_primary_function_name[0]), StrUp(name)) == 0) break; } return m_process; } -//SB: new 3912 +// SB: new 3912 CRFProcess* CRFProcess::GetProcessByNumber(int number) { CRFProcess* m_process = NULL; @@ -2336,10 +2332,10 @@ CRFProcess* CRFProcess::GetProcessByNumber(int number) return m_process; int i; int no_processes = (int)pcs_vector.size(); - for(i = 0; i < no_processes; i++) + for (i = 0; i < no_processes; i++) { m_process = pcs_vector[i]; - if ( m_process->pcs_number == number ) + if (m_process->pcs_number == number) break; } return m_process; @@ -2370,20 +2366,22 @@ void CRFProcess::Config(void) m_msh = FEMGet(pcs_type_name); if (!m_msh) { - cout << "Error in CRFProcess::Config - no MSH data" << "\n"; + cout << "Error in CRFProcess::Config - no MSH data" + << "\n"; return; } - if (hasAnyProcessDeactivatedSubdomains) - CheckMarkedElement(); //WW + if (hasAnyProcessDeactivatedSubdomains) + CheckMarkedElement(); // WW - if (continuum_vector.size() == 0) // YD + if (continuum_vector.size() == 0) // YD continuum_vector.push_back(1.0); // if (_pcs_type_name.compare("LIQUID_FLOW") == 0) { if (this->getProcessType() == FiniteElement::LIQUID_FLOW || this->getProcessType() == FiniteElement::FLUID_FLOW) { - std::cout << "CRFProcess::Config LIQUID_FLOW" << "\n"; + std::cout << "CRFProcess::Config LIQUID_FLOW" + << "\n"; type = 1; ConfigLiquidFlow(); } @@ -2402,10 +2400,9 @@ void CRFProcess::Config(void) type = 22; } else - { + { type = 14; - - } + } ConfigUnsaturatedFlow(); } // if (_pcs_type_name.compare("OVERLAND_FLOW") == 0) { @@ -2416,7 +2413,7 @@ void CRFProcess::Config(void) ConfigGroundwaterFlow(); } // if (_pcs_type_name.compare("AIR_FLOW") == 0) { //OK - if (this->getProcessType() == FiniteElement::AIR_FLOW) //OK + if (this->getProcessType() == FiniteElement::AIR_FLOW) // OK { type = 5; ConfigGasFlow(); @@ -2446,51 +2443,50 @@ void CRFProcess::Config(void) } // if (_pcs_type_name.find("DEFORMATION") != string::npos) if (isDeformationProcess(getProcessType())) - { + { ConfigDeformation(); - } + } // if (_pcs_type_name.find("FLUID_MOMENTUM") != string::npos if (this->getProcessType() == FiniteElement::FLUID_MOMENTUM) { - type = 55; //WW + type = 55; // WW ConfigFluidMomentum(); } // if (_pcs_type_name.find("RANDOM_WALK") != string::npos) { if (this->getProcessType() == FiniteElement::RANDOM_WALK) { - type = 55; //WW + type = 55; // WW ConfigRandomWalk(); } // if (_pcs_type_name.find("MULTI_PHASE_FLOW") != string::npos) {//24.02.2007 WW - if (this->getProcessType() == FiniteElement::MULTI_PHASE_FLOW) //24.02.2007 WW + if (this->getProcessType() == FiniteElement::MULTI_PHASE_FLOW) // 24.02.2007 WW { type = 1212; ConfigMultiPhaseFlow(); } // if (_pcs_type_name.find("PS_GLOBAL") != string::npos) {//24.02.2007 WW - if (this->getProcessType() == FiniteElement::PS_GLOBAL) //24.02.2007 WW + if (this->getProcessType() == FiniteElement::PS_GLOBAL) // 24.02.2007 WW { type = 1313; ConfigPS_Global(); } - if (this->getProcessType() == FiniteElement::MULTI_COMPONENTIAL_FLOW) //24.02.2007 WW + if (this->getProcessType() == FiniteElement::MULTI_COMPONENTIAL_FLOW) // 24.02.2007 WW { type = 1111; ConfigMULTI_COMPONENTIAL_FLOW(); } - if (this->getProcessType() == FiniteElement::TNEQ) //24.02.2007 WW + if (this->getProcessType() == FiniteElement::TNEQ) // 24.02.2007 WW { type = 1414; ConfigTNEQ(); } - if (this->getProcessType() == FiniteElement::TES) //24.02.2007 WW + if (this->getProcessType() == FiniteElement::TES) // 24.02.2007 WW { type = 1415; ConfigTES(); } } - /************************************************************************** FEMLib-Method: Task: @@ -2502,18 +2498,17 @@ void CRFProcess::Config(void) **************************************************************************/ void CRFProcess::ConfigLiquidFlow() { - //pcs_num_name[0] = "PRESSURE0"; - //pcs_sol_name = "LINEAR_SOLVER_PROPERTIES_PRESSURE1"; + // pcs_num_name[0] = "PRESSURE0"; + // pcs_sol_name = "LINEAR_SOLVER_PROPERTIES_PRESSURE1"; pcs_number_of_primary_nvals = 0; pcs_number_of_secondary_nvals = 0; pcs_number_of_evals = 0; - Def_Variable_LiquidFlow(); //NW + Def_Variable_LiquidFlow(); // NW // Output material parameters configMaterialParameters(); } - /************************************************************************** FEMLib-Method: 03/2003 OK Implementation @@ -2543,10 +2538,10 @@ void CRFProcess::ConfigGroundwaterFlow() pcs_eval_unit[4] = "m^2"; pcs_eval_name[5] = "POROSITY"; pcs_eval_unit[5] = "-"; - pcs_eval_name[6] = "PERMEABILITY_YY"; - pcs_eval_unit[6] = "m^2"; - pcs_eval_name[7] = "PERMEABILITY_ZZ"; - pcs_eval_unit[7] = "m^2"; + pcs_eval_name[6] = "PERMEABILITY_YY"; + pcs_eval_unit[6] = "m^2"; + pcs_eval_name[7] = "PERMEABILITY_ZZ"; + pcs_eval_unit[7] = "m^2"; //---------------------------------------------------------------------- // Secondary variables pcs_number_of_secondary_nvals = 5; @@ -2556,32 +2551,32 @@ void CRFProcess::ConfigGroundwaterFlow() pcs_secondary_function_name[1] = "WDEPTH"; pcs_secondary_function_unit[1] = "m"; pcs_secondary_function_timelevel[1] = 1; - pcs_secondary_function_name[2] = "COUPLING"; //JOD + pcs_secondary_function_name[2] = "COUPLING"; // JOD pcs_secondary_function_unit[2] = "m/s"; pcs_secondary_function_timelevel[2] = 0; - pcs_secondary_function_name[3] = "COUPLING"; //JOD + pcs_secondary_function_name[3] = "COUPLING"; // JOD pcs_secondary_function_unit[3] = "m/s"; pcs_secondary_function_timelevel[3] = 1; - pcs_secondary_function_name[4] = "STORE"; //JOD for subtiming 4.7.10 + pcs_secondary_function_name[4] = "STORE"; // JOD for subtiming 4.7.10 pcs_secondary_function_unit[4] = "m"; pcs_secondary_function_timelevel[4] = 1; - pcs_number_of_secondary_nvals = 5; //WW - //WW + pcs_number_of_secondary_nvals = 5; // WW + // WW pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "VELOCITY_X1"; pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "m/s"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; //WW + pcs_number_of_secondary_nvals++; // WW pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "VELOCITY_Y1"; pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "m/s"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; //WW + pcs_number_of_secondary_nvals++; // WW pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "VELOCITY_Z1"; pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "m/s"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; //WW + pcs_number_of_secondary_nvals++; // WW //---------------------------------------------------------------------- - //WW / TF + // WW / TF // Output material parameters configMaterialParameters(); @@ -2589,7 +2584,6 @@ void CRFProcess::ConfigGroundwaterFlow() m_msh->DefineMobileNodes(this); } - /************************************************************************** FEMLib-Method: Task: @@ -2622,10 +2616,9 @@ void CRFProcess::ConfigGasFlow() //---------------------------------------------------------------------- // NUM pcs_num_name[0] = "PRESSURE0"; - pcs_sol_name = "LINEAR_SOLVER_PROPERTIES_PRESSURE1"; + pcs_sol_name = "LINEAR_SOLVER_PROPERTIES_PRESSURE1"; } - /************************************************************************** FEMLib-Method: Task: @@ -2636,156 +2629,155 @@ void CRFProcess::ConfigGasFlow() **************************************************************************/ void CRFProcess::ConfigMultiphaseFlow() { - switch(pcs_type_number) + switch (pcs_type_number) { - case 0: - pcs_num_name[0] = "PRESSURE0"; - pcs_sol_name = "LINEAR_SOLVER_PROPERTIES_PRESSURE1"; - break; - case 1: - pcs_num_name[0] = "SATURATION0"; - pcs_sol_name = "LINEAR_SOLVER_PROPERTIES_SATURATION1"; - break; + case 0: + pcs_num_name[0] = "PRESSURE0"; + pcs_sol_name = "LINEAR_SOLVER_PROPERTIES_PRESSURE1"; + break; + case 1: + pcs_num_name[0] = "SATURATION0"; + pcs_sol_name = "LINEAR_SOLVER_PROPERTIES_SATURATION1"; + break; } //---------------------------------------------------------------------- // NOD Primary variables pcs_number_of_primary_nvals = 1; - switch(pcs_type_number) + switch (pcs_type_number) { - case 0: - pcs_primary_function_name[0] = "PRESSURE1"; - pcs_primary_function_unit[0] = "Pa"; - break; - case 1: - pcs_primary_function_name[0] = "SATURATION2"; - pcs_primary_function_unit[0] = "m3/m3"; - break; + case 0: + pcs_primary_function_name[0] = "PRESSURE1"; + pcs_primary_function_unit[0] = "Pa"; + break; + case 1: + pcs_primary_function_name[0] = "SATURATION2"; + pcs_primary_function_unit[0] = "m3/m3"; + break; } //---------------------------------------------------------------------- // NOD Secondary variables - pcs_number_of_secondary_nvals = 12; // BG - switch(pcs_type_number) + pcs_number_of_secondary_nvals = 12; // BG + switch (pcs_type_number) { - case 0: - pcs_secondary_function_name[0] = "PRESSURE2"; - pcs_secondary_function_unit[0] = "Pa"; - pcs_secondary_function_timelevel[0] = 0; - pcs_secondary_function_name[1] = "PRESSURE2"; - pcs_secondary_function_unit[1] = "Pa"; - pcs_secondary_function_timelevel[1] = 1; - pcs_secondary_function_name[2] = "PRESSURE_CAP"; - pcs_secondary_function_unit[2] = "Pa"; - pcs_secondary_function_timelevel[2] = 0; - pcs_secondary_function_name[3] = "FLUX"; - pcs_secondary_function_unit[3] = "m3/s"; - pcs_secondary_function_timelevel[3] = 0; - pcs_secondary_function_name[4] = "DENSITY1"; - pcs_secondary_function_unit[4] = "kg/m3"; - pcs_secondary_function_timelevel[4] = 1; - pcs_secondary_function_name[5] = "VISCOSITY1"; - pcs_secondary_function_unit[5] = "Pa s"; - pcs_secondary_function_timelevel[5] = 1; - //BG - pcs_secondary_function_name[6] = "VELOCITY_X1"; - pcs_secondary_function_unit[6] = "m/s"; - pcs_secondary_function_timelevel[6] = 1; - pcs_secondary_function_name[7] = "VELOCITY_Y1"; - pcs_secondary_function_unit[7] = "m/s"; - pcs_secondary_function_timelevel[7] = 1; - pcs_secondary_function_name[8] = "VELOCITY_Z1"; - pcs_secondary_function_unit[8] = "m/s"; - pcs_secondary_function_timelevel[8] = 1; - pcs_secondary_function_name[9] = "VELOCITY_X2"; - pcs_secondary_function_unit[9] = "m/s"; - pcs_secondary_function_timelevel[9] = 1; - pcs_secondary_function_name[10] = "VELOCITY_Y2"; - pcs_secondary_function_unit[10] = "m/s"; - pcs_secondary_function_timelevel[10] = 1; - pcs_secondary_function_name[11] = "VELOCITY_Z2"; - pcs_secondary_function_unit[11] = "m/s"; - pcs_secondary_function_timelevel[11] = 1; - break; - case 1: - pcs_secondary_function_name[0] = "SATURATION1"; - pcs_secondary_function_timelevel[0] = 0; - pcs_secondary_function_unit[0] = "m3/m3"; - pcs_secondary_function_name[1] = "SATURATION1"; - pcs_secondary_function_timelevel[1] = 1; - pcs_secondary_function_unit[1] = "m3/m3"; - pcs_secondary_function_name[2] = "PRESSURE_CAP"; - pcs_secondary_function_unit[2] = "Pa"; - pcs_secondary_function_timelevel[2] = 1; - pcs_secondary_function_name[3] = "FLUX"; - pcs_secondary_function_unit[3] = "m3/s"; - pcs_secondary_function_timelevel[3] = 1; - pcs_secondary_function_name[4] = "DENSITY2"; - pcs_secondary_function_unit[4] = "kg/m3"; - pcs_secondary_function_timelevel[4] = 1; - pcs_secondary_function_name[5] = "VISCOSITY2"; - pcs_secondary_function_unit[5] = "Pa s"; - pcs_secondary_function_timelevel[5] = 1; - //BG - pcs_secondary_function_name[6] = "VELOCITY_X1"; - pcs_secondary_function_unit[6] = "m/s"; - pcs_secondary_function_timelevel[6] = 1; - pcs_secondary_function_name[7] = "VELOCITY_Y1"; - pcs_secondary_function_unit[7] = "m/s"; - pcs_secondary_function_timelevel[7] = 1; - pcs_secondary_function_name[8] = "VELOCITY_Z1"; - pcs_secondary_function_unit[8] = "m/s"; - pcs_secondary_function_timelevel[8] = 1; - pcs_secondary_function_name[9] = "VELOCITY_X2"; - pcs_secondary_function_unit[9] = "m/s"; - pcs_secondary_function_timelevel[9] = 1; - pcs_secondary_function_name[10] = "VELOCITY_Y2"; - pcs_secondary_function_unit[10] = "m/s"; - pcs_secondary_function_timelevel[10] = 1; - pcs_secondary_function_name[11] = "VELOCITY_Z2"; - pcs_secondary_function_unit[11] = "m/s"; - pcs_secondary_function_timelevel[11] = 1; - break; + case 0: + pcs_secondary_function_name[0] = "PRESSURE2"; + pcs_secondary_function_unit[0] = "Pa"; + pcs_secondary_function_timelevel[0] = 0; + pcs_secondary_function_name[1] = "PRESSURE2"; + pcs_secondary_function_unit[1] = "Pa"; + pcs_secondary_function_timelevel[1] = 1; + pcs_secondary_function_name[2] = "PRESSURE_CAP"; + pcs_secondary_function_unit[2] = "Pa"; + pcs_secondary_function_timelevel[2] = 0; + pcs_secondary_function_name[3] = "FLUX"; + pcs_secondary_function_unit[3] = "m3/s"; + pcs_secondary_function_timelevel[3] = 0; + pcs_secondary_function_name[4] = "DENSITY1"; + pcs_secondary_function_unit[4] = "kg/m3"; + pcs_secondary_function_timelevel[4] = 1; + pcs_secondary_function_name[5] = "VISCOSITY1"; + pcs_secondary_function_unit[5] = "Pa s"; + pcs_secondary_function_timelevel[5] = 1; + // BG + pcs_secondary_function_name[6] = "VELOCITY_X1"; + pcs_secondary_function_unit[6] = "m/s"; + pcs_secondary_function_timelevel[6] = 1; + pcs_secondary_function_name[7] = "VELOCITY_Y1"; + pcs_secondary_function_unit[7] = "m/s"; + pcs_secondary_function_timelevel[7] = 1; + pcs_secondary_function_name[8] = "VELOCITY_Z1"; + pcs_secondary_function_unit[8] = "m/s"; + pcs_secondary_function_timelevel[8] = 1; + pcs_secondary_function_name[9] = "VELOCITY_X2"; + pcs_secondary_function_unit[9] = "m/s"; + pcs_secondary_function_timelevel[9] = 1; + pcs_secondary_function_name[10] = "VELOCITY_Y2"; + pcs_secondary_function_unit[10] = "m/s"; + pcs_secondary_function_timelevel[10] = 1; + pcs_secondary_function_name[11] = "VELOCITY_Z2"; + pcs_secondary_function_unit[11] = "m/s"; + pcs_secondary_function_timelevel[11] = 1; + break; + case 1: + pcs_secondary_function_name[0] = "SATURATION1"; + pcs_secondary_function_timelevel[0] = 0; + pcs_secondary_function_unit[0] = "m3/m3"; + pcs_secondary_function_name[1] = "SATURATION1"; + pcs_secondary_function_timelevel[1] = 1; + pcs_secondary_function_unit[1] = "m3/m3"; + pcs_secondary_function_name[2] = "PRESSURE_CAP"; + pcs_secondary_function_unit[2] = "Pa"; + pcs_secondary_function_timelevel[2] = 1; + pcs_secondary_function_name[3] = "FLUX"; + pcs_secondary_function_unit[3] = "m3/s"; + pcs_secondary_function_timelevel[3] = 1; + pcs_secondary_function_name[4] = "DENSITY2"; + pcs_secondary_function_unit[4] = "kg/m3"; + pcs_secondary_function_timelevel[4] = 1; + pcs_secondary_function_name[5] = "VISCOSITY2"; + pcs_secondary_function_unit[5] = "Pa s"; + pcs_secondary_function_timelevel[5] = 1; + // BG + pcs_secondary_function_name[6] = "VELOCITY_X1"; + pcs_secondary_function_unit[6] = "m/s"; + pcs_secondary_function_timelevel[6] = 1; + pcs_secondary_function_name[7] = "VELOCITY_Y1"; + pcs_secondary_function_unit[7] = "m/s"; + pcs_secondary_function_timelevel[7] = 1; + pcs_secondary_function_name[8] = "VELOCITY_Z1"; + pcs_secondary_function_unit[8] = "m/s"; + pcs_secondary_function_timelevel[8] = 1; + pcs_secondary_function_name[9] = "VELOCITY_X2"; + pcs_secondary_function_unit[9] = "m/s"; + pcs_secondary_function_timelevel[9] = 1; + pcs_secondary_function_name[10] = "VELOCITY_Y2"; + pcs_secondary_function_unit[10] = "m/s"; + pcs_secondary_function_timelevel[10] = 1; + pcs_secondary_function_name[11] = "VELOCITY_Z2"; + pcs_secondary_function_unit[11] = "m/s"; + pcs_secondary_function_timelevel[11] = 1; + break; } //---------------------------------------------------------------------- // ELE values pcs_number_of_evals = 7; - switch(pcs_type_number) - { - case 0: - pcs_eval_name[0] = "VELOCITY1_X"; - pcs_eval_unit[0] = "m/s"; - pcs_eval_name[1] = "VELOCITY1_Y"; - pcs_eval_unit[1] = "m/s"; - pcs_eval_name[2] = "VELOCITY1_Z"; - pcs_eval_unit[2] = "m/s"; - pcs_eval_name[3] = "POROSITY1"; //MX 03.2005 - pcs_eval_unit[3] = "-"; - pcs_eval_name[4] = "POROSITY1_IL"; //MX 03.2005 - pcs_eval_unit[4] = "-"; - pcs_eval_name[5] = "PERMEABILITY1"; //MX 03.2005 - pcs_eval_unit[5] = "-"; - pcs_eval_name[6] = "POROSITY1_SW"; //MX 03.2005 - pcs_eval_unit[6] = "-"; - break; - case 1: - pcs_eval_name[0] = "VELOCITY2_X"; - pcs_eval_unit[0] = "m/s"; - pcs_eval_name[1] = "VELOCITY2_Y"; - pcs_eval_unit[1] = "m/s"; - pcs_eval_name[2] = "VELOCITY2_Z"; - pcs_eval_unit[2] = "m/s"; - pcs_eval_name[3] = "POROSITY"; //MX 03.2005 - pcs_eval_unit[3] = "-"; - pcs_eval_name[4] = "POROSITY_IL"; //MX 03.2005 - pcs_eval_unit[4] = "-"; - pcs_eval_name[5] = "PERMEABILITY"; //MX 03.2005 - pcs_eval_unit[5] = "-"; - pcs_eval_name[6] = "POROSITY_SW"; //MX 03.2005 - pcs_eval_unit[6] = "-"; - break; + switch (pcs_type_number) + { + case 0: + pcs_eval_name[0] = "VELOCITY1_X"; + pcs_eval_unit[0] = "m/s"; + pcs_eval_name[1] = "VELOCITY1_Y"; + pcs_eval_unit[1] = "m/s"; + pcs_eval_name[2] = "VELOCITY1_Z"; + pcs_eval_unit[2] = "m/s"; + pcs_eval_name[3] = "POROSITY1"; // MX 03.2005 + pcs_eval_unit[3] = "-"; + pcs_eval_name[4] = "POROSITY1_IL"; // MX 03.2005 + pcs_eval_unit[4] = "-"; + pcs_eval_name[5] = "PERMEABILITY1"; // MX 03.2005 + pcs_eval_unit[5] = "-"; + pcs_eval_name[6] = "POROSITY1_SW"; // MX 03.2005 + pcs_eval_unit[6] = "-"; + break; + case 1: + pcs_eval_name[0] = "VELOCITY2_X"; + pcs_eval_unit[0] = "m/s"; + pcs_eval_name[1] = "VELOCITY2_Y"; + pcs_eval_unit[1] = "m/s"; + pcs_eval_name[2] = "VELOCITY2_Z"; + pcs_eval_unit[2] = "m/s"; + pcs_eval_name[3] = "POROSITY"; // MX 03.2005 + pcs_eval_unit[3] = "-"; + pcs_eval_name[4] = "POROSITY_IL"; // MX 03.2005 + pcs_eval_unit[4] = "-"; + pcs_eval_name[5] = "PERMEABILITY"; // MX 03.2005 + pcs_eval_unit[5] = "-"; + pcs_eval_name[6] = "POROSITY_SW"; // MX 03.2005 + pcs_eval_unit[6] = "-"; + break; } } - /************************************************************************** FEMLib-Method: Task: @@ -2799,102 +2791,101 @@ void CRFProcess::ConfigNonIsothermalFlow() //---------------------------------------------------------------------- // Primary variables pcs_number_of_primary_nvals = 1; - switch(pcs_type_number) + switch (pcs_type_number) { - case 0: - pcs_num_name[0] = "PRESSURE0"; - pcs_sol_name = "LINEAR_SOLVER_PROPERTIES_PRESSURE1"; - pcs_primary_function_name[0] = "PRESSURE1"; - pcs_primary_function_unit[0] = "Pa"; - break; - case 1: - pcs_num_name[0] = "SATURATION0"; - pcs_sol_name = "LINEAR_SOLVER_PROPERTIES_SATURATION1"; - pcs_primary_function_name[0] = "SATURATION2"; - pcs_primary_function_unit[0] = "m3/m3"; - break; + case 0: + pcs_num_name[0] = "PRESSURE0"; + pcs_sol_name = "LINEAR_SOLVER_PROPERTIES_PRESSURE1"; + pcs_primary_function_name[0] = "PRESSURE1"; + pcs_primary_function_unit[0] = "Pa"; + break; + case 1: + pcs_num_name[0] = "SATURATION0"; + pcs_sol_name = "LINEAR_SOLVER_PROPERTIES_SATURATION1"; + pcs_primary_function_name[0] = "SATURATION2"; + pcs_primary_function_unit[0] = "m3/m3"; + break; } //---------------------------------------------------------------------- // Secondary variables pcs_number_of_secondary_nvals = 6; - switch(pcs_type_number) + switch (pcs_type_number) { - case 0: - pcs_secondary_function_name[0] = "PRESSURE2"; - pcs_secondary_function_timelevel[0] = 0; - pcs_secondary_function_unit[0] = "Pa"; - pcs_secondary_function_name[1] = "PRESSURE2"; - pcs_secondary_function_timelevel[1] = 1; - pcs_secondary_function_unit[1] = "Pa"; - pcs_secondary_function_name[2] = "MASS_FRACTION1"; - pcs_secondary_function_timelevel[2] = 0; - pcs_secondary_function_unit[2] = "kg/kg"; - pcs_secondary_function_name[3] = "MASS_FRACTION1"; - pcs_secondary_function_timelevel[3] = 1; - pcs_secondary_function_unit[3] = "kg/kg"; - pcs_secondary_function_name[4] = "PRESSURE_CAP"; - pcs_secondary_function_timelevel[4] = 0; - pcs_secondary_function_unit[4] = "Pa"; - pcs_secondary_function_name[5] = "DENSITY1"; - pcs_secondary_function_timelevel[5] = 1; - pcs_secondary_function_unit[5] = "kg/m3"; - break; - case 1: - pcs_secondary_function_name[0] = "SATURATION1"; - pcs_secondary_function_timelevel[0] = 0; - pcs_secondary_function_unit[0] = "m3/m3"; - pcs_secondary_function_name[1] = "SATURATION1"; - pcs_secondary_function_timelevel[1] = 1; - pcs_secondary_function_unit[1] = "m3/m3"; - pcs_secondary_function_name[2] = "MASS_FRACTION2"; - pcs_secondary_function_timelevel[2] = 0; - pcs_secondary_function_unit[2] = "kg/kg"; - pcs_secondary_function_name[3] = "MASS_FRACTION2"; - pcs_secondary_function_timelevel[3] = 1; - pcs_secondary_function_unit[3] = "kg/kg"; - pcs_secondary_function_name[4] = "PRESSURE_CAP"; - pcs_secondary_function_timelevel[4] = 1; - pcs_secondary_function_unit[4] = "Pa"; - pcs_secondary_function_name[5] = "DENSITY2"; - pcs_secondary_function_timelevel[5] = 1; - pcs_secondary_function_unit[5] = "kg/m3"; - break; + case 0: + pcs_secondary_function_name[0] = "PRESSURE2"; + pcs_secondary_function_timelevel[0] = 0; + pcs_secondary_function_unit[0] = "Pa"; + pcs_secondary_function_name[1] = "PRESSURE2"; + pcs_secondary_function_timelevel[1] = 1; + pcs_secondary_function_unit[1] = "Pa"; + pcs_secondary_function_name[2] = "MASS_FRACTION1"; + pcs_secondary_function_timelevel[2] = 0; + pcs_secondary_function_unit[2] = "kg/kg"; + pcs_secondary_function_name[3] = "MASS_FRACTION1"; + pcs_secondary_function_timelevel[3] = 1; + pcs_secondary_function_unit[3] = "kg/kg"; + pcs_secondary_function_name[4] = "PRESSURE_CAP"; + pcs_secondary_function_timelevel[4] = 0; + pcs_secondary_function_unit[4] = "Pa"; + pcs_secondary_function_name[5] = "DENSITY1"; + pcs_secondary_function_timelevel[5] = 1; + pcs_secondary_function_unit[5] = "kg/m3"; + break; + case 1: + pcs_secondary_function_name[0] = "SATURATION1"; + pcs_secondary_function_timelevel[0] = 0; + pcs_secondary_function_unit[0] = "m3/m3"; + pcs_secondary_function_name[1] = "SATURATION1"; + pcs_secondary_function_timelevel[1] = 1; + pcs_secondary_function_unit[1] = "m3/m3"; + pcs_secondary_function_name[2] = "MASS_FRACTION2"; + pcs_secondary_function_timelevel[2] = 0; + pcs_secondary_function_unit[2] = "kg/kg"; + pcs_secondary_function_name[3] = "MASS_FRACTION2"; + pcs_secondary_function_timelevel[3] = 1; + pcs_secondary_function_unit[3] = "kg/kg"; + pcs_secondary_function_name[4] = "PRESSURE_CAP"; + pcs_secondary_function_timelevel[4] = 1; + pcs_secondary_function_unit[4] = "Pa"; + pcs_secondary_function_name[5] = "DENSITY2"; + pcs_secondary_function_timelevel[5] = 1; + pcs_secondary_function_unit[5] = "kg/m3"; + break; } // Node pcs_number_of_primary_nvals = 1; // ELE values pcs_number_of_evals = 14; - pcs_eval_name[0] = "COMP_FLUX"; - pcs_eval_name[1] = "POROSITY"; - pcs_eval_name[2] = "PERMEABILITY"; - pcs_eval_name[3] = "VELOCITY1_X"; - pcs_eval_name[4] = "VELOCITY1_Y"; - pcs_eval_name[5] = "VELOCITY1_Z"; - pcs_eval_name[6] = "VELOCITY2_X"; - pcs_eval_name[7] = "VELOCITY2_Y"; - pcs_eval_name[8] = "VELOCITY2_Z"; - pcs_eval_name[9] = "POROSITY_IL"; + pcs_eval_name[0] = "COMP_FLUX"; + pcs_eval_name[1] = "POROSITY"; + pcs_eval_name[2] = "PERMEABILITY"; + pcs_eval_name[3] = "VELOCITY1_X"; + pcs_eval_name[4] = "VELOCITY1_Y"; + pcs_eval_name[5] = "VELOCITY1_Z"; + pcs_eval_name[6] = "VELOCITY2_X"; + pcs_eval_name[7] = "VELOCITY2_Y"; + pcs_eval_name[8] = "VELOCITY2_Z"; + pcs_eval_name[9] = "POROSITY_IL"; pcs_eval_name[10] = "VoidRatio"; pcs_eval_name[11] = "PorosityChange"; pcs_eval_name[12] = "n_sw_Rate"; - pcs_eval_name[13] = "POROSITY_SW"; - pcs_eval_unit[0] = "kg/s"; - pcs_eval_unit[1] = "m3/m3"; - pcs_eval_unit[2] = "m2"; - pcs_eval_unit[3] = "m/s"; - pcs_eval_unit[4] = "m/s"; - pcs_eval_unit[5] = "m/s"; - pcs_eval_unit[6] = "m/s"; - pcs_eval_unit[7] = "m/s"; - pcs_eval_unit[8] = "m/s"; - pcs_eval_unit[9] = "-"; + pcs_eval_name[13] = "POROSITY_SW"; + pcs_eval_unit[0] = "kg/s"; + pcs_eval_unit[1] = "m3/m3"; + pcs_eval_unit[2] = "m2"; + pcs_eval_unit[3] = "m/s"; + pcs_eval_unit[4] = "m/s"; + pcs_eval_unit[5] = "m/s"; + pcs_eval_unit[6] = "m/s"; + pcs_eval_unit[7] = "m/s"; + pcs_eval_unit[8] = "m/s"; + pcs_eval_unit[9] = "-"; pcs_eval_unit[10] = "-"; pcs_eval_unit[11] = "-"; pcs_eval_unit[12] = "-"; pcs_eval_unit[13] = "-"; } - /************************************************************************** FEMLib-Method: Task: @@ -2903,7 +2894,7 @@ void CRFProcess::ConfigNonIsothermalFlow() WW Splitted for processes last modified: **************************************************************************/ -//void CRFProcess::ConfigNonIsothermalFlowRichards() +// void CRFProcess::ConfigNonIsothermalFlowRichards() /************************************************************************** FEMLib-Method: @@ -2927,61 +2918,60 @@ void CRFProcess::ConfigMassTransport() // sprintf(pcs_primary_function_name[0], "%s%li","CONCENTRATION",comp); //---------------------------------------------------------------------- // Tests - //WW int size; - //WW size = (int)cp_vec.size(); - //int comb; //OK411 - //comb = pcs_component_number; + // WW int size; + // WW size = (int)cp_vec.size(); + // int comb; //OK411 + // comb = pcs_component_number; - if((int)cp_vec.size() < pcs_component_number + 1) + if ((int)cp_vec.size() < pcs_component_number + 1) { - cout << "Error in CRFProcess::ConfigMassTransport - not enough MCP data" << '\n'; + cout << "Error in CRFProcess::ConfigMassTransport - not enough MCP data" << '\n'; return; } //---------------------------------------------------------------------- pcs_primary_function_name[0] = cp_vec[pcs_component_number]->compname.c_str(); - //sprintf(pcs_primary_function_name[0], "%s", cp_vec[pcs_component_number]->compname.c_str()); - pcs_primary_function_unit[0] = "kg/m3"; //SB - /* SB: Eintrag component name in Ausgabestruktur */ //SB:todo : just one phase todo:name + // sprintf(pcs_primary_function_name[0], "%s", cp_vec[pcs_component_number]->compname.c_str()); + pcs_primary_function_unit[0] = "kg/m3"; // SB + /* SB: Eintrag component name in Ausgabestruktur */ // SB:todo : just one phase todo:name /* pcs_primary_function_name[0] = GetTracerCompName(0,this->pcs_component_number-1); name_initial_condition_tracer_component = pcs_primary_function_name[0]; pcs_ic_name_mass = pcs_primary_function_name[0]; */ // 1.2 secondary variables - pcs_number_of_secondary_nvals = 3; //SB3909 + pcs_number_of_secondary_nvals = 3; // SB3909 pcs_secondary_function_name[0] = new char[80]; - char pcs_secondary_function_name_tmp [80]; - sprintf(pcs_secondary_function_name_tmp, "%s%li","MASS_FLUX_",comp); + char pcs_secondary_function_name_tmp[80]; + sprintf(pcs_secondary_function_name_tmp, "%s%li", "MASS_FLUX_", comp); strncpy((char*)pcs_secondary_function_name[0], pcs_secondary_function_name_tmp, 80); // pcs_secondary_function_name[0] = "MASS_FLUX1"; pcs_secondary_function_unit[0] = "kg/m3/s"; pcs_secondary_function_timelevel[0] = 0; pcs_secondary_function_name[1] = new char[80]; - sprintf(pcs_secondary_function_name_tmp, "%s%li","MASS_FLUX_",comp); + sprintf(pcs_secondary_function_name_tmp, "%s%li", "MASS_FLUX_", comp); strncpy((char*)pcs_secondary_function_name[1], pcs_secondary_function_name_tmp, 80); pcs_secondary_function_unit[1] = "kg/m3/s"; pcs_secondary_function_timelevel[1] = 1; - //KG44 added secondary function for adaptive time stepping - string comp_name = "DELTA_" + convertPrimaryVariableToString(this->getProcessPrimaryVariable());// JOD 2014-11-10 + // KG44 added secondary function for adaptive time stepping + string comp_name = "DELTA_" + convertPrimaryVariableToString(this->getProcessPrimaryVariable()); // JOD 2014-11-10 pcs_secondary_function_name[2] = new char[80]; strncpy((char*)pcs_secondary_function_name[2], comp_name.c_str(), 80); pcs_secondary_function_unit[2] = "kg/m3"; pcs_secondary_function_timelevel[2] = 0; - if (adaption) { pcs_number_of_secondary_nvals = 4; pcs_secondary_function_name[3] = new char[80]; - sprintf(pcs_secondary_function_name_tmp, "%s%li","CONC_BACK_",comp); + sprintf(pcs_secondary_function_name_tmp, "%s%li", "CONC_BACK_", comp); strncpy((char*)pcs_secondary_function_name[3], pcs_secondary_function_name_tmp, 80); pcs_secondary_function_unit[3] = "kg/m3"; pcs_secondary_function_timelevel[3] = 0; } - //OK LOPCalcSecondaryVariables_USER = MTM2CalcSecondaryVariables; //SB:todo + // OK LOPCalcSecondaryVariables_USER = MTM2CalcSecondaryVariables; //SB:todo // 2 ELE values pcs_number_of_evals = 0; - // pcs_eval_name[0] = "Darcy velocity"; +// pcs_eval_name[0] = "Darcy velocity"; #ifdef REACTION_ELEMENT pcs_number_of_evals = 1; pcs_eval_name[0] = pcs_primary_function_name[0]; @@ -2991,11 +2981,10 @@ void CRFProcess::ConfigMassTransport() // NUM pcs_num_name[0] = "CONCENTRATION0"; /* SB: immer solver properties der ersten Komponente nehmen */ - //SB ?? + // SB ?? pcs_sol_name = "LINEAR_SOLVER_PROPERTIES_CONCENTRATION1"; } - /************************************************************************** FEMLib-Method: Task: @@ -3007,27 +2996,25 @@ void CRFProcess::ConfigMassTransport() void CRFProcess::ConfigHeatTransport() { pcs_num_name[0] = "TEMPERATURE0"; - pcs_sol_name = "LINEAR_SOLVER_PROPERTIES_TEMPERATURE1"; + pcs_sol_name = "LINEAR_SOLVER_PROPERTIES_TEMPERATURE1"; // NOD - if((int)continuum_vector.size() == 1) + if ((int)continuum_vector.size() == 1) { pcs_number_of_primary_nvals = 1; pcs_primary_function_name[0] = "TEMPERATURE1"; pcs_primary_function_unit[0] = "K"; - pcs_number_of_secondary_nvals = 1; //JOD 2014-11-10 + pcs_number_of_secondary_nvals = 1; // JOD 2014-11-10 pcs_secondary_function_name[0] = "DELTA_TEMPERATURE1"; pcs_secondary_function_unit[0] = "K"; pcs_secondary_function_timelevel[0] = 0; - - #ifdef REACTION_ELEMENT - pcs_number_of_evals = 1; //MX + pcs_number_of_evals = 1; // MX pcs_eval_name[0] = "TEMPERATURE1"; pcs_eval_unit[0] = "K"; #endif } - if((int)continuum_vector.size() == 2) + if ((int)continuum_vector.size() == 2) { pcs_number_of_primary_nvals = 2; pcs_primary_function_name[0] = "TEMPERATURE1"; @@ -3039,7 +3026,6 @@ void CRFProcess::ConfigHeatTransport() } } - /************************************************************************** FEMLib-Method: Task: @@ -3049,20 +3035,20 @@ void CRFProcess::ConfigHeatTransport() **************************************************************************/ void CRFProcess::ConfigDeformation() { - // Generate high order nodes for all elements. +// Generate high order nodes for all elements. #if defined(USE_PETSC) // || defined (other parallel linear solver lib). //WW. 05.2013 - m_msh->ConfigHighOrderElements(); + m_msh->ConfigHighOrderElements(); #else - m_msh->GenerateHighOrderNodes(); //WW + m_msh->GenerateHighOrderNodes(); // WW #endif type = 4; // if (_pcs_type_name.find("DEFORMATION") != string::npos // && _pcs_type_name.find("FLOW") != string::npos) { - if (getProcessType() == FiniteElement::DEFORMATION_FLOW || getProcessType() == FiniteElement::DEFORMATION_H2 ) + if (getProcessType() == FiniteElement::DEFORMATION_FLOW || getProcessType() == FiniteElement::DEFORMATION_H2) { type = 41; - if (getProcessType() == FiniteElement::DEFORMATION_H2 ) + if (getProcessType() == FiniteElement::DEFORMATION_H2) type = 42; cpl_type_name = "MONOLITHIC"; pcs_deformation = 11; @@ -3076,7 +3062,7 @@ void CRFProcess::ConfigDeformation() if (num->pcs_type_name.find("DEFORMATION") != string::npos) { num->pcs_type_name = FiniteElement::convertProcessTypeToString(this->getProcessType()); - if(num->nls_method >= 1) // Newton-Raphson + if (num->nls_method >= 1) // Newton-Raphson { pcs_deformation = 101; if (type / 10 == 4) @@ -3087,7 +3073,7 @@ void CRFProcess::ConfigDeformation() } // Prepare for restart - //RFConfigRenumber(); + // RFConfigRenumber(); // NUM pcs_sol_name = "LINEAR_SOLVER_PROPERTIES_DISPLACEMENT1"; @@ -3104,39 +3090,38 @@ void CRFProcess::ConfigDeformation() // Coupling int i; - for(i = 0; i < problem_dimension_dm; i++) + for (i = 0; i < problem_dimension_dm; i++) Shift[i] = i * m_msh->GetNodesNumber(true); /// 11-20.08.2010 WW long nn_H = (long)m_msh->GetNodesNumber(true); - if(type == 4) + if (type == 4) { num_nodes_p_var = new long[problem_dimension_dm]; p_var_index = new int[problem_dimension_dm]; - for(int i = 0; i < problem_dimension_dm; i++) + for (int i = 0; i < problem_dimension_dm; i++) num_nodes_p_var[i] = nn_H; } - else if(type == 41) + else if (type == 41) { num_nodes_p_var = new long[problem_dimension_dm + 1]; p_var_index = new int[problem_dimension_dm + 1]; - for(i = 0; i < problem_dimension_dm; i++) + for (i = 0; i < problem_dimension_dm; i++) num_nodes_p_var[i] = nn_H; num_nodes_p_var[problem_dimension_dm] = (long)m_msh->GetNodesNumber(false); Shift[problem_dimension_dm] = problem_dimension_dm * m_msh->GetNodesNumber(true); } - else if(type == 42) + else if (type == 42) { num_nodes_p_var = new long[problem_dimension_dm + 2]; p_var_index = new int[problem_dimension_dm + 2]; - for(i = 0; i < problem_dimension_dm; i++) + for (i = 0; i < problem_dimension_dm; i++) num_nodes_p_var[i] = nn_H; - for(i = problem_dimension_dm; i < problem_dimension_dm + 2; i++) + for (i = problem_dimension_dm; i < problem_dimension_dm + 2; i++) num_nodes_p_var[i] = (long)m_msh->GetNodesNumber(false); Shift[problem_dimension_dm] = problem_dimension_dm * m_msh->GetNodesNumber(true); - Shift[problem_dimension_dm + - 1] = Shift[problem_dimension_dm] + m_msh->GetNodesNumber(false); + Shift[problem_dimension_dm + 1] = Shift[problem_dimension_dm] + m_msh->GetNodesNumber(false); #ifdef JFNK_H2M norm_u_JFNK = new double[2]; @@ -3155,14 +3140,14 @@ void CRFProcess::VariableStaticProblem() { //---------------------------------------------------------------------- // NOD Primary functions - pcs_number_of_primary_nvals = 2; //OK distinguish 2/3D problems, problem_dimension_dm; + pcs_number_of_primary_nvals = 2; // OK distinguish 2/3D problems, problem_dimension_dm; dm_number_of_primary_nvals = 2; pcs_number_of_evals = 0; pcs_primary_function_name[0] = "DISPLACEMENT_X1"; pcs_primary_function_name[1] = "DISPLACEMENT_Y1"; pcs_primary_function_unit[0] = "m"; pcs_primary_function_unit[1] = "m"; - if(max_dim == 2) + if (max_dim == 2) { pcs_number_of_primary_nvals = 3; dm_number_of_primary_nvals = 3; @@ -3226,7 +3211,7 @@ void CRFProcess::VariableStaticProblem() // pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; // pcs_number_of_secondary_nvals++; - if(max_dim == 2) // 3D + if (max_dim == 2) // 3D { pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "STRESS_XZ"; pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "Pa"; @@ -3245,63 +3230,62 @@ void CRFProcess::VariableStaticProblem() pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; pcs_number_of_secondary_nvals++; } - if (max_dim > 0) // >1D + if (max_dim > 0) // >1D { - pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_1_X"; // i.e. Sigma_1 - pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; - pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; - - pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_1_Y"; // i.e. Sigma_1 - pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; - pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_1_X"; // i.e. Sigma_1 + pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; + pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; + pcs_number_of_secondary_nvals++; - pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_1_Z"; // i.e. Sigma_1 - pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; - pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_1_Y"; // i.e. Sigma_1 + pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; + pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; + pcs_number_of_secondary_nvals++; - pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_2_X"; // i.e. Sigma_1 - pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; - pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_1_Z"; // i.e. Sigma_1 + pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; + pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; + pcs_number_of_secondary_nvals++; - pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_2_Y"; // i.e. Sigma_1 - pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; - pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_2_X"; // i.e. Sigma_1 + pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; + pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; + pcs_number_of_secondary_nvals++; - pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_2_Z"; // i.e. Sigma_1 - pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; - pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_2_Y"; // i.e. Sigma_1 + pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; + pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; + pcs_number_of_secondary_nvals++; - pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_3_X"; // i.e. Sigma_1 - pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; - pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_2_Z"; // i.e. Sigma_1 + pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; + pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; + pcs_number_of_secondary_nvals++; - pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_3_Y"; // i.e. Sigma_1 - pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; - pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_3_X"; // i.e. Sigma_1 + pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; + pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; + pcs_number_of_secondary_nvals++; - pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_3_Z"; // i.e. Sigma_1 - pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; - pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; -} + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_3_Y"; // i.e. Sigma_1 + pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; + pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; + pcs_number_of_secondary_nvals++; + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_3_Z"; // i.e. Sigma_1 + pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; + pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; + pcs_number_of_secondary_nvals++; + } - if(type == 41) - { //Monolithic scheme + if (type == 41) + { // Monolithic scheme Def_Variable_LiquidFlow(); // Output material parameters configMaterialParameters(); } - else if (type == 42) //Monolithic scheme H2M. 03.08.2010. WW + else if (type == 42) // Monolithic scheme H2M. 03.08.2010. WW { Def_Variable_MultiPhaseFlow(); @@ -3310,7 +3294,6 @@ void CRFProcess::VariableStaticProblem() } } - /************************************************************************** FEMLib-Method: Dynamic problems Task: @@ -3328,7 +3311,7 @@ void CRFProcess::VariableDynamics() pcs_primary_function_name[1] = "ACCELERATION_Y1"; pcs_primary_function_unit[0] = "m/s^2"; pcs_primary_function_unit[1] = "m/s^2"; - if(max_dim == 2) + if (max_dim == 2) { pcs_number_of_primary_nvals = 3; dm_number_of_primary_nvals = 3; @@ -3418,7 +3401,7 @@ void CRFProcess::VariableDynamics() pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; pcs_number_of_secondary_nvals++; // 3D - if(max_dim == 2) // 3D + if (max_dim == 2) // 3D { pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "STRESS_XZ"; pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "Pa"; @@ -3445,57 +3428,55 @@ void CRFProcess::VariableDynamics() pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; pcs_number_of_secondary_nvals++; } - if (max_dim > 0) // >1D + if (max_dim > 0) // >1D { - pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_1_X"; // i.e. Sigma_1 - pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; - pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; - - pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_1_Y"; // i.e. Sigma_1 - pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; - pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_1_X"; // i.e. Sigma_1 + pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; + pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; + pcs_number_of_secondary_nvals++; - pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_1_Z"; // i.e. Sigma_1 - pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; - pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_1_Y"; // i.e. Sigma_1 + pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; + pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; + pcs_number_of_secondary_nvals++; - pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_2_X"; // i.e. Sigma_1 - pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; - pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_1_Z"; // i.e. Sigma_1 + pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; + pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; + pcs_number_of_secondary_nvals++; - pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_2_Y"; // i.e. Sigma_1 - pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; - pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_2_X"; // i.e. Sigma_1 + pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; + pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; + pcs_number_of_secondary_nvals++; - pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_2_Z"; // i.e. Sigma_1 - pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; - pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_2_Y"; // i.e. Sigma_1 + pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; + pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; + pcs_number_of_secondary_nvals++; - pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_3_X"; // i.e. Sigma_1 - pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; - pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_2_Z"; // i.e. Sigma_1 + pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; + pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; + pcs_number_of_secondary_nvals++; - pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_3_Y"; // i.e. Sigma_1 - pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; - pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_3_X"; // i.e. Sigma_1 + pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; + pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; + pcs_number_of_secondary_nvals++; - pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_3_Z"; // i.e. Sigma_1 - pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; - pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; -} + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_3_Y"; // i.e. Sigma_1 + pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; + pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; + pcs_number_of_secondary_nvals++; + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "NORM_STRESS_3_Z"; // i.e. Sigma_1 + pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; + pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; + pcs_number_of_secondary_nvals++; + } } - /************************************************************************** FEMLib-Method: Task: @@ -3505,50 +3486,47 @@ void CRFProcess::VariableDynamics() **************************************************************************/ void CRFProcess::ConfigUnsaturatedFlow() { - if ((int) continuum_vector.size() == 1) + if ((int)continuum_vector.size() == 1) { // 1.1 primary variables pcs_number_of_primary_nvals = 1; pcs_primary_function_name[0] = "PRESSURE1"; pcs_primary_function_unit[0] = "Pa"; // 1.2 secondary variables - //OK LOPCalcSecondaryVariables_USER = MMPCalcSecondaryVariablesRichards; // p_c and S^l + // OK LOPCalcSecondaryVariables_USER = MMPCalcSecondaryVariablesRichards; // p_c and S^l pcs_number_of_secondary_nvals = 0; - pcs_secondary_function_name[pcs_number_of_secondary_nvals] - = "SATURATION1"; + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "SATURATION1"; pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "m3/m3"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 0; pcs_number_of_secondary_nvals++; - pcs_secondary_function_name[pcs_number_of_secondary_nvals] - = "SATURATION1"; + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "SATURATION1"; pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "m3/m3"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; pcs_number_of_secondary_nvals++; - pcs_secondary_function_name[pcs_number_of_secondary_nvals] - = "PRESSURE_CAP1"; + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "PRESSURE_CAP1"; pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "Pa"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 0; pcs_number_of_secondary_nvals++; - //MB + // MB pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "FLUX"; pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "m/s"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 0; pcs_number_of_secondary_nvals++; - //MB + // MB pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "FLUX"; pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "m/s"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; pcs_number_of_secondary_nvals++; - if(Neglect_H_ini==2) + if (Neglect_H_ini == 2) { pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "PRESSURE1_Ini"; pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "Pa"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++;//WX:08.2011 + pcs_number_of_secondary_nvals++; // WX:08.2011 } - //TEST - //#define DECOVALEX +// TEST +//#define DECOVALEX #ifdef DECOVALEX // DECOVALEX Test pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "PRESSURE_I"; @@ -3556,125 +3534,110 @@ void CRFProcess::ConfigUnsaturatedFlow() pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 0; pcs_number_of_secondary_nvals++; #endif - if(adaption) //WW, JOD removed //MW added - { - pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "STORAGE_P"; - pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "Pa"; - pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 0; - pcs_number_of_secondary_nvals++; - } + if (adaption) // WW, JOD removed //MW added + { + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "STORAGE_P"; + pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "Pa"; + pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 0; + pcs_number_of_secondary_nvals++; + } // Nodal velocity. WW - pcs_secondary_function_name[pcs_number_of_secondary_nvals] - = "VELOCITY_X1"; + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "VELOCITY_X1"; pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "m/s"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; pcs_number_of_secondary_nvals++; - pcs_secondary_function_name[pcs_number_of_secondary_nvals] - = "VELOCITY_Y1"; + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "VELOCITY_Y1"; pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "m/s"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; pcs_number_of_secondary_nvals++; - pcs_secondary_function_name[pcs_number_of_secondary_nvals] - = "VELOCITY_Z1"; + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "VELOCITY_Z1"; pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "m/s"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; pcs_number_of_secondary_nvals++; - //JOD + // JOD pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "COUPLING"; pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "m/s"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 0; pcs_number_of_secondary_nvals++; - //JOD + // JOD pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "COUPLING"; pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "m/s"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; pcs_number_of_secondary_nvals++; - // for calibration (unconfined groundwater flow with variable density) 5.3.07 JOD - pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "HEAD"; - pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "m"; - pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; + // for calibration (unconfined groundwater flow with variable density) 5.3.07 JOD + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "HEAD"; + pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "m"; + pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; + pcs_number_of_secondary_nvals++; } - else if ((int) continuum_vector.size() == 2) + else if ((int)continuum_vector.size() == 2) { - dof = 2; //WW + dof = 2; // WW // 1.1 primary variables - pcs_number_of_primary_nvals = 2; //YD + pcs_number_of_primary_nvals = 2; // YD pcs_primary_function_name[0] = "PRESSURE1"; pcs_primary_function_unit[0] = "Pa"; pcs_primary_function_name[1] = "PRESSURE2"; pcs_primary_function_unit[1] = "Pa"; // 1.2 secondary variables - //OK LOPCalcSecondaryVariables_USER = MMPCalcSecondaryVariablesRichards; // p_c and S^l + // OK LOPCalcSecondaryVariables_USER = MMPCalcSecondaryVariablesRichards; // p_c and S^l pcs_number_of_secondary_nvals = 0; - pcs_secondary_function_name[pcs_number_of_secondary_nvals] - = "SATURATION1"; + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "SATURATION1"; pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "m3/m3"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 0; - pcs_number_of_secondary_nvals++; //WW - pcs_secondary_function_name[pcs_number_of_secondary_nvals] - = "SATURATION1"; + pcs_number_of_secondary_nvals++; // WW + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "SATURATION1"; pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "m3/m3"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; //WW - pcs_secondary_function_name[pcs_number_of_secondary_nvals] - = "SATURATION2"; + pcs_number_of_secondary_nvals++; // WW + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "SATURATION2"; pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "m3/m3"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 0; - pcs_number_of_secondary_nvals++; //WW - pcs_secondary_function_name[pcs_number_of_secondary_nvals] - = "SATURATION2"; + pcs_number_of_secondary_nvals++; // WW + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "SATURATION2"; pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "m3/m3"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; //WW - pcs_secondary_function_name[pcs_number_of_secondary_nvals] - = "PRESSURE_CAP1"; + pcs_number_of_secondary_nvals++; // WW + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "PRESSURE_CAP1"; pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "Pa"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 0; - pcs_number_of_secondary_nvals++; //WW - pcs_secondary_function_name[pcs_number_of_secondary_nvals] - = "PRESSURE_CAP2"; + pcs_number_of_secondary_nvals++; // WW + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "PRESSURE_CAP2"; pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "Pa"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 0; - pcs_number_of_secondary_nvals++; //WW + pcs_number_of_secondary_nvals++; // WW // Nodal velocity. WW - pcs_secondary_function_name[pcs_number_of_secondary_nvals] - = "VELOCITY_X1"; + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "VELOCITY_X1"; pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "m/s"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; //WW - pcs_secondary_function_name[pcs_number_of_secondary_nvals] - = "VELOCITY_Y1"; + pcs_number_of_secondary_nvals++; // WW + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "VELOCITY_Y1"; pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "m/s"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; //WW - pcs_secondary_function_name[pcs_number_of_secondary_nvals] - = "VELOCITY_Z1"; + pcs_number_of_secondary_nvals++; // WW + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "VELOCITY_Z1"; pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "m/s"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; //WW - pcs_secondary_function_name[pcs_number_of_secondary_nvals] - = "VELOCITY_X2"; + pcs_number_of_secondary_nvals++; // WW + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "VELOCITY_X2"; pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "m/s"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; //WW - pcs_secondary_function_name[pcs_number_of_secondary_nvals] - = "VELOCITY_Y2"; + pcs_number_of_secondary_nvals++; // WW + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "VELOCITY_Y2"; pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "m/s"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; //WW - pcs_secondary_function_name[pcs_number_of_secondary_nvals] - = "VELOCITY_Z2"; + pcs_number_of_secondary_nvals++; // WW + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "VELOCITY_Z2"; pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "m/s"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; //WW - // 03.03.2008. WW + pcs_number_of_secondary_nvals++; // WW + // 03.03.2008. WW for (size_t i = 0; i < GetPrimaryVNumber(); i++) Shift[i] = i * m_msh->GetNodesNumber(true); } // Output material parameters - //WW // TF + // WW // TF configMaterialParameters(); // 2 ELE values @@ -3685,19 +3648,18 @@ void CRFProcess::ConfigUnsaturatedFlow() pcs_eval_unit[1] = "m/s"; pcs_eval_name[2] = "VELOCITY1_Z"; pcs_eval_unit[2] = "m/s"; - pcs_eval_name[3] = "POROSITY"; //MX 11.2005 + pcs_eval_name[3] = "POROSITY"; // MX 11.2005 pcs_eval_unit[3] = "-"; - pcs_eval_name[4] = "POROSITY_IL"; //MX 11.2005 + pcs_eval_name[4] = "POROSITY_IL"; // MX 11.2005 pcs_eval_unit[4] = "-"; - pcs_eval_name[5] = "PERMEABILITY"; //MX 11.2005 + pcs_eval_name[5] = "PERMEABILITY"; // MX 11.2005 pcs_eval_unit[5] = "-"; - pcs_eval_name[6] = "n_sw"; //MX 11.2005 + pcs_eval_name[6] = "n_sw"; // MX 11.2005 pcs_eval_unit[6] = "-"; - pcs_eval_name[7] = "n_sw_rate"; //MX 11.2005 + pcs_eval_name[7] = "n_sw_rate"; // MX 11.2005 pcs_eval_unit[7] = "-"; } - /************************************************************************** FEMLib-Method: Task: @@ -3707,7 +3669,7 @@ void CRFProcess::ConfigUnsaturatedFlow() **************************************************************************/ void CRFProcess::ConfigFluidMomentum() { - //pcs_num_name[0] = "VELOCITY1_X"; + // pcs_num_name[0] = "VELOCITY1_X"; // Nothing added in terms of matrix solver. // Just linear solver is good enough. pcs_sol_name = "LINEAR_SOLVER_PROPERTIES_PRESSURE1"; @@ -3732,13 +3694,12 @@ void CRFProcess::ConfigFluidMomentum() pcs_eval_unit[2] = "m/s"; } - /**************************************************************************/ void CRFProcess::ConfigRandomWalk() { // Nothing added in terms of matrix solver. // Just linear solver is good enough. - pcs_sol_name = "LINEAR_SOLVER_PROPERTIES_PRESSURE1"; + pcs_sol_name = "LINEAR_SOLVER_PROPERTIES_PRESSURE1"; // NOD values pcs_number_of_primary_nvals = 0; @@ -3747,16 +3708,15 @@ void CRFProcess::ConfigRandomWalk() // 2 ELE values pcs_number_of_evals = 1; pcs_eval_name[0] = "CONCENTRATION0"; - pcs_eval_unit[0] = "kg/m3"; + pcs_eval_unit[0] = "kg/m3"; - for(size_t e = 0; eele_vector.size(); e++) + for (size_t e = 0; e < m_msh->ele_vector.size(); e++) { - m_msh->ele_vector[e]->AllocateMeomoryforAngle(); - m_msh->ele_vector[e]->SetAngle(0, 0.); - m_msh->ele_vector[e]->SetAngle(1, 0.); - m_msh->ele_vector[e]->SetAngle(2, 0.); -} - + m_msh->ele_vector[e]->AllocateMeomoryforAngle(); + m_msh->ele_vector[e]->SetAngle(0, 0.); + m_msh->ele_vector[e]->SetAngle(1, 0.); + m_msh->ele_vector[e]->SetAngle(2, 0.); + } } //////////////////////////////////////////////////////////////////////////// @@ -3764,7 +3724,7 @@ void CRFProcess::ConfigRandomWalk() /// Define variables of multi-phase flow model (WW 08.2010) // //////////////////////////////////////////////////////////////////////////// -void CRFProcess:: Def_Variable_MultiPhaseFlow() +void CRFProcess::Def_Variable_MultiPhaseFlow() { // 1.1 primary variables pcs_primary_function_name[pcs_number_of_primary_nvals] = "PRESSURE1"; @@ -3815,21 +3775,20 @@ void CRFProcess:: Def_Variable_MultiPhaseFlow() pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; pcs_number_of_secondary_nvals++; - if(Neglect_H_ini==2) + if (Neglect_H_ini == 2) { pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "PRESSURE1_Ini"; pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "Pa"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++;//WX:08.2011 + pcs_number_of_secondary_nvals++; // WX:08.2011 pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "PRESSURE2_Ini"; pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "Pa"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++;//WX:08.2011 + pcs_number_of_secondary_nvals++; // WX:08.2011 } - // 1.3 elemental variables // BG, 04/2012 - //pcs_number_of_evals = 0; + // pcs_number_of_evals = 0; pcs_eval_name[pcs_number_of_evals] = "VELOCITY1_X"; pcs_eval_unit[pcs_number_of_evals] = "m/s"; pcs_number_of_evals++; @@ -3848,48 +3807,46 @@ void CRFProcess:: Def_Variable_MultiPhaseFlow() pcs_eval_name[pcs_number_of_evals] = "VELOCITY2_Z"; pcs_eval_unit[pcs_number_of_evals] = "m/s"; pcs_number_of_evals++; - // CB_merge_0513 added some additional ELE values - pcs_eval_name[pcs_number_of_evals] = "PERMEABILITY"; - pcs_eval_unit[pcs_number_of_evals] = "m^2"; + // CB_merge_0513 added some additional ELE values + pcs_eval_name[pcs_number_of_evals] = "PERMEABILITY"; + pcs_eval_unit[pcs_number_of_evals] = "m^2"; + pcs_number_of_evals++; + pcs_eval_name[pcs_number_of_evals] = "POROSITY"; + pcs_eval_unit[pcs_number_of_evals] = "-"; pcs_number_of_evals++; - pcs_eval_name[pcs_number_of_evals] = "POROSITY"; - pcs_eval_unit[pcs_number_of_evals] = "-"; - pcs_number_of_evals++; - pcs_eval_name[pcs_number_of_evals] = "PERMEABILITY_YY"; - pcs_eval_unit[pcs_number_of_evals] = "m^2"; - pcs_number_of_evals++; - pcs_eval_name[pcs_number_of_evals] = "PERMEABILITY_ZZ"; - pcs_eval_unit[pcs_number_of_evals] = "m^2"; + pcs_eval_name[pcs_number_of_evals] = "PERMEABILITY_YY"; + pcs_eval_unit[pcs_number_of_evals] = "m^2"; + pcs_number_of_evals++; + pcs_eval_name[pcs_number_of_evals] = "PERMEABILITY_ZZ"; + pcs_eval_unit[pcs_number_of_evals] = "m^2"; pcs_number_of_evals++; - if(simulator.compare("ECLIPSE") == 0) //02.2013. WW - { - // BG 01/2011, variables necessary for ECLIPSE - pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "DENSITY1"; - pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "kg/m3"; - pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; - pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "VISCOSITY1"; - pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "Pa s"; - pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; - pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "DENSITY2"; - pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "kg/m3"; - pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; - pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "VISCOSITY2"; - pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "Pa s"; - pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; - - //// WTP: Add Temp support - //pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "TEMPERATURE1"; - //pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "K"; - //pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - //pcs_number_of_secondary_nvals++; - - } + if (simulator.compare("ECLIPSE") == 0) // 02.2013. WW + { + // BG 01/2011, variables necessary for ECLIPSE + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "DENSITY1"; + pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "kg/m3"; + pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; + pcs_number_of_secondary_nvals++; + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "VISCOSITY1"; + pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "Pa s"; + pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; + pcs_number_of_secondary_nvals++; + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "DENSITY2"; + pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "kg/m3"; + pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; + pcs_number_of_secondary_nvals++; + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "VISCOSITY2"; + pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "Pa s"; + pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; + pcs_number_of_secondary_nvals++; + //// WTP: Add Temp support + // pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "TEMPERATURE1"; + // pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "K"; + // pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; + // pcs_number_of_secondary_nvals++; + } } //////////////////////////////////////////////////////////////////////////// @@ -3897,14 +3854,13 @@ void CRFProcess:: Def_Variable_MultiPhaseFlow() /// Define variables of liquid flow model (NW 09.2011) // //////////////////////////////////////////////////////////////////////////// -void CRFProcess:: Def_Variable_LiquidFlow() +void CRFProcess::Def_Variable_LiquidFlow() { // 1.1 primary variables pcs_primary_function_name[pcs_number_of_primary_nvals] = "PRESSURE1"; pcs_primary_function_unit[pcs_number_of_primary_nvals] = "Pa"; pcs_number_of_primary_nvals++; - pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "HEAD"; pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "m"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; @@ -3927,16 +3883,16 @@ void CRFProcess:: Def_Variable_LiquidFlow() pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 0; pcs_number_of_secondary_nvals++; - if(Neglect_H_ini==2) + if (Neglect_H_ini == 2) { pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "PRESSURE1_Ini"; pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "Pa"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; //WX 08.2011 + pcs_number_of_secondary_nvals++; // WX 08.2011 } // 1.3 elemental variables - //pcs_number_of_evals = 0; + // pcs_number_of_evals = 0; pcs_eval_name[pcs_number_of_evals] = "VOLUME"; pcs_eval_unit[pcs_number_of_evals] = "m3"; pcs_number_of_evals++; @@ -3949,30 +3905,29 @@ void CRFProcess:: Def_Variable_LiquidFlow() pcs_eval_name[pcs_number_of_evals] = "VELOCITY1_Z"; pcs_eval_unit[pcs_number_of_evals] = "m/s"; pcs_number_of_evals++; - pcs_eval_name[pcs_number_of_evals] = "POROSITY"; //MX, test for n=n(c), 04.2005 + pcs_eval_name[pcs_number_of_evals] = "POROSITY"; // MX, test for n=n(c), 04.2005 pcs_eval_unit[pcs_number_of_evals] = "-"; pcs_number_of_evals++; - pcs_eval_name[pcs_number_of_evals] = "PERMEABILITY"; //JT 2010 -- need this for index call of heterogeneous permeability + pcs_eval_name[pcs_number_of_evals] + = "PERMEABILITY"; // JT 2010 -- need this for index call of heterogeneous permeability pcs_eval_unit[pcs_number_of_evals] = "m2"; pcs_number_of_evals++; // WTP: needed? // CB_merge_0513 ?? why only for eclipse?? - // if(simulator.compare("ECLIPSE") == 0) //02.2013. WW - // { + // if(simulator.compare("ECLIPSE") == 0) //02.2013. WW + // { // BG 01/2011, variables necessary for ECLIPSE - pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "DENSITY1"; - pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "kg/m3"; + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "DENSITY1"; + pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "kg/m3"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; pcs_number_of_secondary_nvals++; - pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "VISCOSITY1"; - pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "Pa s"; + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "VISCOSITY1"; + pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "Pa s"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; pcs_number_of_secondary_nvals++; - // } - - + // } } /************************************************************************** @@ -3996,14 +3951,13 @@ void CRFProcess::ConfigMultiPhaseFlow() // 11.08.2010. WW long nn = m_msh->GetNodesNumber(false); // - for(size_t i = 0; i < GetPrimaryVNumber(); i++) // 03.03.2008. WW + for (size_t i = 0; i < GetPrimaryVNumber(); i++) // 03.03.2008. WW Shift[i] = i * nn; num_nodes_p_var = new long[2]; num_nodes_p_var[0] = num_nodes_p_var[1] = nn; } - /************************************************************************** FEMLib-Method: For PS model for multiphase flow Task: @@ -4033,11 +3987,11 @@ void CRFProcess::ConfigPS_Global() pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "m3/m3"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; pcs_number_of_secondary_nvals++; - // CB_merge_0513 additional secondary variable - pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "DENSITY2"; - pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "kg/m3"; - pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; + // CB_merge_0513 additional secondary variable + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "DENSITY2"; + pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "kg/m3"; + pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; + pcs_number_of_secondary_nvals++; // Nodal velocity. pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "VELOCITY_X1"; pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "m/s"; @@ -4064,22 +4018,20 @@ void CRFProcess::ConfigPS_Global() pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; pcs_number_of_secondary_nvals++; - // CB_merge_0513 added some ELE values - //pcs_number_of_evals = 2; - pcs_eval_name[pcs_number_of_evals] = "PERMEABILITY"; - pcs_eval_unit[pcs_number_of_evals] = "m^2"; + // CB_merge_0513 added some ELE values + // pcs_number_of_evals = 2; + pcs_eval_name[pcs_number_of_evals] = "PERMEABILITY"; + pcs_eval_unit[pcs_number_of_evals] = "m^2"; pcs_number_of_evals++; - pcs_eval_name[pcs_number_of_evals] = "POROSITY"; - pcs_eval_unit[pcs_number_of_evals] = "-"; + pcs_eval_name[pcs_number_of_evals] = "POROSITY"; + pcs_eval_unit[pcs_number_of_evals] = "-"; pcs_number_of_evals++; - // - for(size_t i = 0; i < GetPrimaryVNumber(); i++) // 03.03.2008. WW + for (size_t i = 0; i < GetPrimaryVNumber(); i++) // 03.03.2008. WW Shift[i] = i * m_msh->GetNodesNumber(true); } - /************************************************************************** FEMLib-Method: For Pressure-temperature-coupled flow for fluids Task: @@ -4089,18 +4041,19 @@ void CRFProcess::ConfigPS_Global() void CRFProcess::ConfigMULTI_COMPONENTIAL_FLOW() { const char* CmpName[6]; - CFluidProperties* m_mfp = NULL; - m_mfp = mfp_vector[0]; - dof = 2 + m_mfp->cmpN; - CmpName[2] = (char*) m_mfp->cmpNm1.data(); - CmpName[3] = (char*) m_mfp->cmpNm2.data(); - CmpName[4] = (char*) m_mfp->cmpNm3.data(); - CmpName[5] = (char*) m_mfp->cmpNm4.data(); + CFluidProperties* m_mfp = NULL; + m_mfp = mfp_vector[0]; + dof = 2 + m_mfp->cmpN; + CmpName[2] = (char*)m_mfp->cmpNm1.data(); + CmpName[3] = (char*)m_mfp->cmpNm2.data(); + CmpName[4] = (char*)m_mfp->cmpNm3.data(); + CmpName[5] = (char*)m_mfp->cmpNm4.data(); // 1.1 primary variables pcs_number_of_primary_nvals = dof; pcs_primary_function_name[0] = "PRESSURE1"; pcs_primary_function_name[1] = "TEMPERATURE1"; - for(int CIndex=2; CIndex < m_mfp->cmpN+2; CIndex++) pcs_primary_function_name[CIndex] = CmpName[CIndex]; + for (int CIndex = 2; CIndex < m_mfp->cmpN + 2; CIndex++) + pcs_primary_function_name[CIndex] = CmpName[CIndex]; // 1.2 secondary variables pcs_number_of_secondary_nvals = 0; @@ -4118,7 +4071,7 @@ void CRFProcess::ConfigMULTI_COMPONENTIAL_FLOW() pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; pcs_number_of_secondary_nvals++; - for(size_t i = 0; i < GetPrimaryVNumber(); i++) + for (size_t i = 0; i < GetPrimaryVNumber(); i++) Shift[i] = i * m_msh->GetNodesNumber(true); } /************************************************************************** @@ -4156,12 +4109,12 @@ void CRFProcess::ConfigTNEQ() pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; pcs_number_of_secondary_nvals++; // this is the nodal based reaction rate of solid density in PTC flow. - pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "REACT_RATE_N"; //TN TEST + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "REACT_RATE_N"; // TN TEST pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "kg/m3s"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; pcs_number_of_secondary_nvals++; // this is the nodal based solid density in PTC flow. - pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "SOLID_DENSITY_N"; //TN TEST + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "SOLID_DENSITY_N"; // TN TEST pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "kg/m3"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; pcs_number_of_secondary_nvals++; @@ -4176,9 +4129,9 @@ void CRFProcess::ConfigTNEQ() pcs_eval_name[pcs_number_of_evals] = "VELOCITY1_Z"; pcs_eval_unit[pcs_number_of_evals] = "m/s"; pcs_number_of_evals++; - //pcs_eval_name[pcs_number_of_evals] = "POROSITY"; - //pcs_eval_unit[pcs_number_of_evals] = "-"; - //pcs_number_of_evals++; + // pcs_eval_name[pcs_number_of_evals] = "POROSITY"; + // pcs_eval_unit[pcs_number_of_evals] = "-"; + // pcs_number_of_evals++; pcs_eval_name[pcs_number_of_evals] = "PERMEABILITY"; pcs_eval_unit[pcs_number_of_evals] = "m2"; pcs_number_of_evals++; @@ -4188,28 +4141,27 @@ void CRFProcess::ConfigTNEQ() pcs_eval_name[pcs_number_of_evals] = "REACT_RATE"; pcs_eval_unit[pcs_number_of_evals] = "kg/m3s"; pcs_number_of_evals++; - //pcs_eval_name[pcs_number_of_evals] = "T_EQUIL"; //TN - //pcs_eval_unit[pcs_number_of_evals] = "K"; - //pcs_number_of_evals++; + // pcs_eval_name[pcs_number_of_evals] = "T_EQUIL"; //TN + // pcs_eval_unit[pcs_number_of_evals] = "K"; + // pcs_number_of_evals++; - for(size_t i=0; iGetNodesNumber(false); + for (size_t i = 0; i < GetPrimaryVNumber(); i++) + Shift[i] = i * m_msh->GetNodesNumber(false); long group_count = 0; - m_rho_s_0 = msp_vector[group_count]->Density(); // get initial solid density + m_rho_s_0 = msp_vector[group_count]->Density(); // get initial solid density double poro = mmp_vector[group_count]->porosity; FiniteElement::SolidReactiveSystem react_syst = msp_vector[group_count]->getSolidReactiveSystem(); - m_conversion_rate = new conversion_rate(573.0, // T_solid, Kelvin - 573.0, // T_gas, Kelvin - 0.0, // p_gas - 0.0, // w_water, mass fraction unitless + m_conversion_rate = new conversion_rate(573.0, // T_solid, Kelvin + 573.0, // T_gas, Kelvin + 0.0, // p_gas + 0.0, // w_water, mass fraction unitless m_rho_s_0, // kg/m3, // rho_s_initial, - 1.0-poro, // solid volume fraction - 1.0, // delta_t + 1.0 - poro, // solid volume fraction + 1.0, // delta_t react_syst); } - /************************************************************************** FEMLib-Method: For reactive thermal non-equilibrium flow Task: @@ -4243,12 +4195,12 @@ void CRFProcess::ConfigTES() pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; pcs_number_of_secondary_nvals++; // this is the nodal based reaction rate of solid density in PTC flow. - pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "REACT_RATE_N"; //TN TEST + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "REACT_RATE_N"; // TN TEST pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "kg/m3s"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; pcs_number_of_secondary_nvals++; // this is the nodal based solid density in PTC flow. - pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "SOLID_DENSITY_N"; //TN TEST + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "SOLID_DENSITY_N"; // TN TEST pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "kg/m3"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; pcs_number_of_secondary_nvals++; @@ -4263,9 +4215,9 @@ void CRFProcess::ConfigTES() pcs_eval_name[pcs_number_of_evals] = "VELOCITY1_Z"; pcs_eval_unit[pcs_number_of_evals] = "m/s"; pcs_number_of_evals++; - //pcs_eval_name[pcs_number_of_evals] = "POROSITY"; - //pcs_eval_unit[pcs_number_of_evals] = "-"; - //pcs_number_of_evals++; + // pcs_eval_name[pcs_number_of_evals] = "POROSITY"; + // pcs_eval_unit[pcs_number_of_evals] = "-"; + // pcs_number_of_evals++; pcs_eval_name[pcs_number_of_evals] = "PERMEABILITY"; pcs_eval_unit[pcs_number_of_evals] = "m2"; pcs_number_of_evals++; @@ -4275,29 +4227,27 @@ void CRFProcess::ConfigTES() pcs_eval_name[pcs_number_of_evals] = "REACT_RATE"; pcs_eval_unit[pcs_number_of_evals] = "kg/m3s"; pcs_number_of_evals++; - //pcs_eval_name[pcs_number_of_evals] = "T_EQUIL"; //TN - //pcs_eval_unit[pcs_number_of_evals] = "K"; - //pcs_number_of_evals++; + // pcs_eval_name[pcs_number_of_evals] = "T_EQUIL"; //TN + // pcs_eval_unit[pcs_number_of_evals] = "K"; + // pcs_number_of_evals++; - for(size_t i=0; iGetNodesNumber(false); + for (size_t i = 0; i < GetPrimaryVNumber(); i++) + Shift[i] = i * m_msh->GetNodesNumber(false); long group_count = 0; - m_rho_s_0 = msp_vector[group_count]->Density(); // get initial solid density + m_rho_s_0 = msp_vector[group_count]->Density(); // get initial solid density double poro = mmp_vector[group_count]->porosity; FiniteElement::SolidReactiveSystem react_syst = msp_vector[group_count]->getSolidReactiveSystem(); - m_conversion_rate = new conversion_rate(573.0, // T_solid, Kelvin - 573.0, // T_gas, Kelvin - 0.0, // p_gas - 0.0, // w_water, mass fraction unitless + m_conversion_rate = new conversion_rate(573.0, // T_solid, Kelvin + 573.0, // T_gas, Kelvin + 0.0, // p_gas + 0.0, // w_water, mass fraction unitless m_rho_s_0, // kg/m3, // rho_s_initial, - 1.0-poro, // solid volume fraction - 1.0, // delta_t + 1.0 - poro, // solid volume fraction + 1.0, // delta_t react_syst); } - - ////////////////////////////////////////////////////////////////////////// // Configuration NOD ////////////////////////////////////////////////////////////////////////// @@ -4317,16 +4267,15 @@ void CRFProcess::ConfigNODValues1(void) const int DOF = GetPrimaryVNumber(); anz_nval0 = anz_nval; number_of_nvals = 2 * DOF + pcs_number_of_secondary_nvals; - //NVAL - pcs_nval_data = (PCS_NVAL_DATA*) \ - Malloc(number_of_nvals * sizeof(PCS_NVAL_DATA)); + // NVAL + pcs_nval_data = (PCS_NVAL_DATA*)Malloc(number_of_nvals * sizeof(PCS_NVAL_DATA)); /*----------------------------------------------------------------*/ - for(i = 0; i < DOF; i++) + for (i = 0; i < DOF; i++) { /* Primary variable - old time */ - //NVAL pcs_nval_data[pcs_nval] = (PCS_NVAL_DATA *) Malloc(sizeof(PCS_NVAL_DATA)); - strcpy(pcs_nval_data[pcs_nval].name,pcs_primary_function_name[pcs_nval - i]); - //Change name for the previous time level + // NVAL pcs_nval_data[pcs_nval] = (PCS_NVAL_DATA *) Malloc(sizeof(PCS_NVAL_DATA)); + strcpy(pcs_nval_data[pcs_nval].name, pcs_primary_function_name[pcs_nval - i]); + // Change name for the previous time level /* char *ch = strchr(pcs_nval_data[pcs_nval].name, '1'); if( ch != NULL ) @@ -4337,9 +4286,9 @@ void CRFProcess::ConfigNODValues1(void) else strcat(pcs_nval_data[pcs_nval].name, "0"); */ //------------------------------------------------------------------------------- - strcpy(pcs_nval_data[pcs_nval].einheit,pcs_primary_function_unit[pcs_nval - i]); + strcpy(pcs_nval_data[pcs_nval].einheit, pcs_primary_function_unit[pcs_nval - i]); pcs_nval_data[pcs_nval].timelevel = 0; - pcs_nval_data[pcs_nval].speichern = 0; //WW + pcs_nval_data[pcs_nval].speichern = 0; // WW pcs_nval_data[pcs_nval].laden = 0; pcs_nval_data[pcs_nval].restart = 1; pcs_nval_data[pcs_nval].adapt_interpol = 1; @@ -4351,9 +4300,9 @@ void CRFProcess::ConfigNODValues1(void) #endif pcs_nval++; /* Primary variable - new time */ - //NVAL pcs_nval_data[pcs_nval] = (PCS_NVAL_DATA *) Malloc(sizeof(PCS_NVAL_DATA)); - strcpy(pcs_nval_data[pcs_nval].name,pcs_primary_function_name[pcs_nval - i - 1]); - strcpy(pcs_nval_data[pcs_nval].einheit,pcs_primary_function_unit[pcs_nval - i - 1]); + // NVAL pcs_nval_data[pcs_nval] = (PCS_NVAL_DATA *) Malloc(sizeof(PCS_NVAL_DATA)); + strcpy(pcs_nval_data[pcs_nval].name, pcs_primary_function_name[pcs_nval - i - 1]); + strcpy(pcs_nval_data[pcs_nval].einheit, pcs_primary_function_unit[pcs_nval - i - 1]); pcs_nval_data[pcs_nval].timelevel = 1; pcs_nval_data[pcs_nval].speichern = 1; @@ -4371,14 +4320,14 @@ void CRFProcess::ConfigNODValues1(void) /*----------------------------------------------------------------*/ /* Secondary variables */ - for(i = 0; i < pcs_number_of_secondary_nvals; i++) + for (i = 0; i < pcs_number_of_secondary_nvals; i++) { - //NVAL pcs_nval_data[pcs_nval] = (PCS_NVAL_DATA *) Malloc(sizeof(PCS_NVAL_DATA)); - strcpy(pcs_nval_data[pcs_nval].name,pcs_secondary_function_name[i]); - strcpy(pcs_nval_data[pcs_nval].einheit,pcs_secondary_function_unit[i]); + // NVAL pcs_nval_data[pcs_nval] = (PCS_NVAL_DATA *) Malloc(sizeof(PCS_NVAL_DATA)); + strcpy(pcs_nval_data[pcs_nval].name, pcs_secondary_function_name[i]); + strcpy(pcs_nval_data[pcs_nval].einheit, pcs_secondary_function_unit[i]); // pcs_nval_data[i+2]->timelevel = 1; // always at new time level pcs_nval_data[pcs_nval].timelevel = pcs_secondary_function_timelevel[i]; - if(pcs_nval_data[pcs_nval].timelevel == 1) + if (pcs_nval_data[pcs_nval].timelevel == 1) pcs_nval_data[pcs_nval].speichern = 1; else pcs_nval_data[pcs_nval].speichern = 0; @@ -4391,19 +4340,18 @@ void CRFProcess::ConfigNODValues1(void) #else pcs_nval_data[pcs_nval].nval_index = anz_nval + pcs_nval; #endif - if(type == 4 || type == 41) - if(dm_number_of_primary_nvals == 2 || - (dm_number_of_primary_nvals == 3 && this->type == 41)) + if (type == 4 || type == 41) + if (dm_number_of_primary_nvals == 2 || (dm_number_of_primary_nvals == 3 && this->type == 41)) { - //Block: - //STRESS_ZX, STRESS_YZ, STRAIN_ZX, STRAIN_ZY and LUMPED_STRESS - if(i == 3 || i == 4 || i == 9 || i == 10 || i == 13) + // Block: + // STRESS_ZX, STRESS_YZ, STRAIN_ZX, STRAIN_ZY and LUMPED_STRESS + if (i == 3 || i == 4 || i == 9 || i == 10 || i == 13) pcs_nval_data[pcs_nval].speichern = 0; - if(!problem_2d_plane_dm) + if (!problem_2d_plane_dm) // Block STRESS_ZZ and STRAIN_ZZ - if(i == 5 || i == 11) + if (i == 5 || i == 11) pcs_nval_data[pcs_nval].speichern = 0; - //if(!pcs_plasticity) + // if(!pcs_plasticity) // { // if(i==12) pcs_nval_data[pcs_nval].speichern = 0; //STRAIN_PLS // } @@ -4424,35 +4372,31 @@ void CRFProcess::ConfigNODValues2(void) int i; number_of_nvals = 2 * GetPrimaryVNumber() + pcs_number_of_secondary_nvals; - for(i = 0; i < number_of_nvals; i++) - ModelsAddNodeValInfoStructure(pcs_nval_data[i].name, \ - pcs_nval_data[i].einheit, \ - pcs_nval_data[i].speichern, \ - pcs_nval_data[i].laden, \ - pcs_nval_data[i].restart, \ - pcs_nval_data[i].adapt_interpol, \ + for (i = 0; i < number_of_nvals; i++) + ModelsAddNodeValInfoStructure(pcs_nval_data[i].name, pcs_nval_data[i].einheit, pcs_nval_data[i].speichern, + pcs_nval_data[i].laden, pcs_nval_data[i].restart, pcs_nval_data[i].adapt_interpol, pcs_nval_data[i].vorgabe); } -#endif //#ifndef NEW_EQS //WW. 07.11.2008 +#endif //#ifndef NEW_EQS //WW. 07.11.2008 /************************************************************************** FEMLib-Method: Task: Programing: 07/2004 OK Implementation **************************************************************************/ -int PCSGetNODValueIndex(const string &name,int timelevel) +int PCSGetNODValueIndex(const string& name, int timelevel) { // PCS primary variables int pcs_vector_size = (int)pcs_vector.size(); - int i,j; + int i, j; CRFProcess* m_pcs = NULL; - if(pcs_vector_size > 0) - for(i = 0; i < pcs_vector_size; i++) + if (pcs_vector_size > 0) + for (i = 0; i < pcs_vector_size; i++) { m_pcs = pcs_vector[i]; - for(j = 0; j < m_pcs->number_of_nvals; j++) - if((name.compare(m_pcs->pcs_nval_data[j].name) == 0) && \ - (m_pcs->pcs_nval_data[j].timelevel == timelevel)) + for (j = 0; j < m_pcs->number_of_nvals; j++) + if ((name.compare(m_pcs->pcs_nval_data[j].name) == 0) + && (m_pcs->pcs_nval_data[j].timelevel == timelevel)) return m_pcs->pcs_nval_data[j].nval_index; } cout << "Error in PCSGetNODValueIndex: " << name << "\n"; @@ -4473,20 +4417,20 @@ int PCSGetNODValueIndex(const string &name,int timelevel) void CRFProcess::ConfigELEValues1(void) { int i; - if(pcs_number_of_evals) - pcs_eval_data = (PCS_EVAL_DATA*) Malloc(pcs_number_of_evals * sizeof(PCS_EVAL_DATA)); - for(i = 0; i < pcs_number_of_evals; i++) + if (pcs_number_of_evals) + pcs_eval_data = (PCS_EVAL_DATA*)Malloc(pcs_number_of_evals * sizeof(PCS_EVAL_DATA)); + for (i = 0; i < pcs_number_of_evals; i++) { - //pcs_eval_data[i] = (PCS_EVAL_DATA *) Malloc(sizeof(PCS_EVAL_DATA)); - strcpy(pcs_eval_data[i].name,pcs_eval_name[i]); - strcpy(pcs_eval_data[i].einheit,pcs_eval_unit[i]); + // pcs_eval_data[i] = (PCS_EVAL_DATA *) Malloc(sizeof(PCS_EVAL_DATA)); + strcpy(pcs_eval_data[i].name, pcs_eval_name[i]); + strcpy(pcs_eval_data[i].einheit, pcs_eval_unit[i]); pcs_eval_data[i].speichern = 1; pcs_eval_data[i].laden = 0; pcs_eval_data[i].restart = 1; pcs_eval_data[i].adapt_interpol = 1; pcs_eval_data[i].vorgabe = 0.0; pcs_eval_data[i].index = anz_eval + i; - pcs_eval_data[i].eval_index = anz_eval + i; //SB + pcs_eval_data[i].eval_index = anz_eval + i; // SB } } @@ -4499,14 +4443,10 @@ void CRFProcess::ConfigELEValues1(void) void CRFProcess::ConfigELEValues2(void) { int i; - for(i = 0; i < pcs_number_of_evals; i++) - ModelsAddElementValInfoStructure(pcs_eval_data[i].name, \ - pcs_eval_data[i].einheit, \ - pcs_eval_data[i].speichern, \ - pcs_eval_data[i].laden, \ - pcs_eval_data[i].restart, \ - pcs_eval_data[i].adapt_interpol, \ - pcs_eval_data[i].vorgabe); + for (i = 0; i < pcs_number_of_evals; i++) + ModelsAddElementValInfoStructure(pcs_eval_data[i].name, pcs_eval_data[i].einheit, pcs_eval_data[i].speichern, + pcs_eval_data[i].laden, pcs_eval_data[i].restart, + pcs_eval_data[i].adapt_interpol, pcs_eval_data[i].vorgabe); } /************************************************************************* @@ -4521,15 +4461,15 @@ int PCSGetELEValueIndex(char* name) CRFProcess* m_process = NULL; int j; int no_processes = (int)pcs_vector.size(); - for(j = 0; j < no_processes; j++) + for (j = 0; j < no_processes; j++) { m_process = pcs_vector[j]; - for(i = 0; i < m_process->pcs_number_of_evals; i++) - if(strcmp(m_process->pcs_eval_data[i].name,name) == 0) + for (i = 0; i < m_process->pcs_number_of_evals; i++) + if (strcmp(m_process->pcs_eval_data[i].name, name) == 0) return m_process->pcs_eval_data[i].eval_index; } printf("PCSGetELEValueIndex Alert\n"); - printf("%s \n",name); + printf("%s \n", name); return -1; } @@ -4550,56 +4490,56 @@ void CRFProcess::CheckMarkedElement() CElem* elem = NULL; CNode* node = NULL; - size_t ele_vector_size (m_msh->ele_vector.size()); + size_t ele_vector_size(m_msh->ele_vector.size()); for (size_t l = 0; l < ele_vector_size; l++) { elem = m_msh->ele_vector[l]; done = false; - for(i = 0; i < (size_t)NumDeactivated_SubDomains; i++) + for (i = 0; i < (size_t)NumDeactivated_SubDomains; i++) { - if(elem->GetPatchIndex() == static_cast(Deactivated_SubDomain[i])) + if (elem->GetPatchIndex() == static_cast(Deactivated_SubDomain[i])) { elem->MarkingAll(false); done = true; break; } } - //WX:02.2013: excav with deactivated subdomain - if(ExcavMaterialGroup==(int)elem->GetPatchIndex()) + // WX:02.2013: excav with deactivated subdomain + if (ExcavMaterialGroup == (int)elem->GetPatchIndex()) { - if(!elem->GetMark()||abs(elem->GetExcavState())GetMark() || abs(elem->GetExcavState()) < MKleinsteZahl) { elem->MarkingAll(false); done = true; } } - if(done) + if (done) continue; else elem->MarkingAll(true); } size_t node_vector_size = m_msh->nod_vector.size(); for (size_t l = 0; l < node_vector_size; l++) - while(m_msh->nod_vector[l]->getConnectedElementIDs().size()) + while (m_msh->nod_vector[l]->getConnectedElementIDs().size()) m_msh->nod_vector[l]->getConnectedElementIDs().pop_back(); for (size_t l = 0; l < ele_vector_size; l++) { elem = m_msh->ele_vector[l]; - if(!elem->GetMark()) + if (!elem->GetMark()) continue; - for(i = 0; i < elem->GetNodesNumber(m_msh->getOrder()); i++) + for (i = 0; i < elem->GetNodesNumber(m_msh->getOrder()); i++) { done = false; node = elem->GetNode(i); - for(j = 0; j < node->getConnectedElementIDs().size(); j++) - if(l == node->getConnectedElementIDs()[j]) + for (j = 0; j < node->getConnectedElementIDs().size(); j++) + if (l == node->getConnectedElementIDs()[j]) { done = true; break; } - if(!done) + if (!done) node->getConnectedElementIDs().push_back(l); } } @@ -4615,19 +4555,18 @@ void CRFProcess::CheckExcavedElement() { int valid; long l; - //bool done; + // bool done; CElem* elem = NULL; - //CNode *node = NULL; + // CNode *node = NULL; for (l = 0; l < (long)m_msh->ele_vector.size(); l++) { elem = m_msh->ele_vector[l]; - if((int)elem->GetPatchIndex() == ExcavMaterialGroup && elem->GetExcavState()==-1)//WX:04.2012 + if ((int)elem->GetPatchIndex() == ExcavMaterialGroup && elem->GetExcavState() == -1) // WX:04.2012 { double const* ele_center(elem->GetGravityCenter()); - if((GetCurveValue(ExcavCurve,0,aktuelle_zeit, - &valid) + ExcavBeginCoordinate) > - (ele_center[ExcavDirection]) - && (ele_center[ExcavDirection] - ExcavBeginCoordinate) > -0.001) + if ((GetCurveValue(ExcavCurve, 0, aktuelle_zeit, &valid) + ExcavBeginCoordinate) + > (ele_center[ExcavDirection]) + && (ele_center[ExcavDirection] - ExcavBeginCoordinate) > -0.001) elem->SetExcavState(1); } } @@ -4656,9 +4595,9 @@ void CRFProcess::CheckExcavedElement() **************************************************************************/ double CRFProcess::Execute() { - int nidx1; + int nidx1; double pcs_error, nl_theta; - long j, k, g_nnodes; //07.01.07 WW + long j, k, g_nnodes; // 07.01.07 WW pcs_error = DBL_MAX; g_nnodes = m_msh->GetNodesNumber(false); @@ -4673,9 +4612,11 @@ double CRFProcess::Execute() const_val = GetCurveValue(_pcs_constant_curve, 0, aktuelle_zeit, &valid); } std::cout << "-> set given constant value. no need to solve a linear system.\n"; - for (int ii = 0; ii < pcs_number_of_primary_nvals; ii++) { + for (int ii = 0; ii < pcs_number_of_primary_nvals; ii++) + { nidx1 = GetNodeValueIndex(pcs_primary_function_name[ii]) + 1; - for (j = 0; j < g_nnodes; j++) { + for (j = 0; j < g_nnodes; j++) + { k = m_msh->Eqs2Global_NodeIndex[j]; SetNodeValue(k, nidx1, const_val); } @@ -4684,7 +4625,7 @@ double CRFProcess::Execute() } #if !defined(USE_PETSC) // || defined(other parallel libs)//03.3012. WW - double implicit_lim = 1.0 - DBL_EPSILON; + double implicit_lim = 1.0 - DBL_EPSILON; #ifdef NEW_EQS eqs_x = eqs_new->x; #else @@ -4692,22 +4633,22 @@ double CRFProcess::Execute() #endif #endif -#ifdef USE_MPI //WW +#ifdef USE_MPI // WW long global_eqs_dim = pcs_number_of_primary_nvals * m_msh->GetNodesNumber(false); CPARDomain* dom = dom_vector[myrank]; #endif #if defined(USE_PETSC) // || defined(other parallel libs)//03.3012. WW eqs_new->Initialize(); -#elif defined(NEW_EQS) //WW - if(!configured_in_nonlinearloop) +#elif defined(NEW_EQS) // WW + if (!configured_in_nonlinearloop) #if defined(USE_MPI) { - //02.2010. WW + // 02.2010. WW dom->eqs->SetDOF(pcs_number_of_primary_nvals); dom->ConfigEQS(m_num, global_eqs_dim); } - // TEST eqs_new->Initialize(); +// TEST eqs_new->Initialize(); #else // Also allocate temporary memory for linear solver. WW { @@ -4718,7 +4659,7 @@ double CRFProcess::Execute() eqs_new->Initialize(); #endif #else - SetLinearSolverType(eqs, m_num); //WW + SetLinearSolverType(eqs, m_num); // WW SetZeroLinearSolver(eqs); #endif /* @@ -4733,67 +4674,70 @@ double CRFProcess::Execute() exit(1); */ //---------------------------------------------------------------------- - nl_theta = 1.0 - m_num->nls_relaxation; - if(nl_theta < DBL_EPSILON) nl_theta = 1.0; + nl_theta = 1.0 - m_num->nls_relaxation; + if (nl_theta < DBL_EPSILON) + nl_theta = 1.0; - //NW. should mark active elements if any process uses deactivation - //if(NumDeactivated_SubDomains>0) - //TODO if it's nonlinear, CheckMarkedElement() has been already called + // NW. should mark active elements if any process uses deactivation + // if(NumDeactivated_SubDomains>0) + // TODO if it's nonlinear, CheckMarkedElement() has been already called if (hasAnyProcessDeactivatedSubdomains) -#ifdef NEW_EQS //WW - if(!configured_in_nonlinearloop) +#ifdef NEW_EQS // WW + if (!configured_in_nonlinearloop) #endif CheckMarkedElement(); m_msh->SwitchOnQuadraticNodes(false); // If not Newton-Raphson method. 20.07.2011. WW - if(m_num->nls_method < 1 ) + if (m_num->nls_method < 1) { #if defined(USE_PETSC) // || defined(other parallel libs)//03.3012. WW - InitializeRHS_with_u0(); + InitializeRHS_with_u0(); #else for (int ii = 0; ii < pcs_number_of_primary_nvals; ii++) { nidx1 = GetNodeValueIndex(pcs_primary_function_name[ii]) + 1; - long const ish = ii * g_nnodes; - for (j = 0; j < g_nnodes; j++) //WW + long const ish = ii * g_nnodes; + for (j = 0; j < g_nnodes; j++) // WW eqs_x[j + ish] = GetNodeValue(m_msh->Eqs2Global_NodeIndex[j], nidx1); } #endif } - //--------------------------------------------------------------------- - // Assembly -#if defined( USE_MPI) || defined( USE_PETSC) //WW - clock_t cpu_time = 0; //WW +//--------------------------------------------------------------------- +// Assembly +#if defined(USE_MPI) || defined(USE_PETSC) // WW + clock_t cpu_time = 0; // WW cpu_time = -clock(); - if(myrank == 0) + if (myrank == 0) #endif - cout << " Assembling equation system..." << "\n"; + cout << " Assembling equation system..." + << "\n"; GlobalAssembly(); -#if defined( USE_MPI) || defined( USE_PETSC) //WW +#if defined(USE_MPI) || defined(USE_PETSC) // WW cpu_time += clock(); cpu_time_assembly += cpu_time; - if(myrank == 0) + if (myrank == 0) #endif - cout << " Calling linear solver..." << "\n"; + cout << " Calling linear solver..." + << "\n"; #ifdef CHECK_EQS std::string eqs_name = convertProcessTypeToString(this->getProcessType()) + "_EQS.txt"; - MXDumpGLS((char*)eqs_name.c_str(),1,eqs->b,eqs->x); + MXDumpGLS((char*)eqs_name.c_str(), 1, eqs->b, eqs->x); #endif - //---------------------------------------------------------------------- - // Execute linear solver +//---------------------------------------------------------------------- +// Execute linear solver #if defined(USE_PETSC) // || defined(other parallel libs)//03.3012. WW - eqs_new->Solver(); - //TEST double x_norm = eqs_new->GetVecNormX(); - eqs_new->MappingSolution(); -#elif defined(NEW_EQS) //WW + eqs_new->Solver(); + // TEST double x_norm = eqs_new->GetVecNormX(); + eqs_new->MappingSolution(); +#elif defined(NEW_EQS) // WW #if defined(USE_MPI) - //21.12.2007 + // 21.12.2007 iter_lin = dom->eqs->Solver(eqs_new->x, global_eqs_dim); #else #if defined(LIS) || defined(MKL) - iter_lin = eqs_new->Solver(this->m_num); //NW + iter_lin = eqs_new->Solver(this->m_num); // NW #else iter_lin = eqs_new->Solver(); #endif @@ -4806,45 +4750,47 @@ double CRFProcess::Execute() //---------------------------------------------------------------------- // Linearized Flux corrected transport (FCT) by Kuzmin 2009 //---------------------------------------------------------------------- - if(m_num->fct_method > 0) //NW + if (m_num->fct_method > 0) // NW { #if defined(USE_PETSC) - eqs_x = eqs_new->GetGlobalSolution(); + eqs_x = eqs_new->GetGlobalSolution(); pcs_error = CalcIterationNODError(1); #else - pcs_error = CalcIterationNODError(m_num->getNonLinearErrorMethod(),true,false); // JT + pcs_error = CalcIterationNODError(m_num->getNonLinearErrorMethod(), true, false); // JT #endif #if defined(USE_MPI) || defined(USE_PETSC) - if(myrank == 0) + if (myrank == 0) { #endif - cout << " Relative PCS error: " << pcs_error << "\n"; - cout << " Start FCT calculation" << "\n"; + cout << " Relative PCS error: " << pcs_error << "\n"; + cout << " Start FCT calculation" + << "\n"; #if defined(USE_MPI) || defined(USE_PETSC) } #endif // Set u^H: use the solution as the higher-order solution - for(int ii = 0; ii < pcs_number_of_primary_nvals; ii++) + for (int ii = 0; ii < pcs_number_of_primary_nvals; ii++) { nidx1 = GetNodeValueIndex(pcs_primary_function_name[ii]) + 1; - for(j = 0; j < g_nnodes; j++){ + for (j = 0; j < g_nnodes; j++) + { #if defined(USE_PETSC) - k = m_msh->Eqs2Global_NodeIndex[j] * pcs_number_of_primary_nvals + ii; - SetNodeValue(j, nidx1, eqs_x[k]); + k = m_msh->Eqs2Global_NodeIndex[j] * pcs_number_of_primary_nvals + ii; + SetNodeValue(j, nidx1, eqs_x[k]); #else - k = m_msh->Eqs2Global_NodeIndex[j]; - SetNodeValue(k,nidx1,eqs_x[j + ii*g_nnodes]); + k = m_msh->Eqs2Global_NodeIndex[j]; + SetNodeValue(k, nidx1, eqs_x[j + ii * g_nnodes]); #endif } } - // Initialize the algebra system +// Initialize the algebra system #if defined(USE_PETSC) - eqs_new->Initialize(); + eqs_new->Initialize(); #else -#ifdef NEW_EQS //WW - if(!configured_in_nonlinearloop) +#ifdef NEW_EQS // WW + if (!configured_in_nonlinearloop) #if defined(USE_MPI) dom->ConfigEQS(m_num, global_eqs_dim); #else @@ -4855,21 +4801,22 @@ double CRFProcess::Execute() #endif #endif - // Set initial guess +// Set initial guess #if !defined(USE_PETSC) - for(int ii = 0; ii < pcs_number_of_primary_nvals; ii++) + for (int ii = 0; ii < pcs_number_of_primary_nvals; ii++) { nidx1 = GetNodeValueIndex(pcs_primary_function_name[ii]) + 1; - for(j = 0; j < g_nnodes; j++){ + for (j = 0; j < g_nnodes; j++) + { k = m_msh->Eqs2Global_NodeIndex[j]; - eqs_x[j + ii*g_nnodes] = GetNodeValue(k,nidx1); + eqs_x[j + ii * g_nnodes] = GetNodeValue(k, nidx1); } } #endif - // Assembly +// Assembly #if defined(USE_MPI) || defined(USE_PETSC) - clock_t cpu_time = 0; //WW + clock_t cpu_time = 0; // WW cpu_time = -clock(); #endif femFCTmode = true; @@ -4880,25 +4827,25 @@ double CRFProcess::Execute() cpu_time_assembly += cpu_time; #endif - // Solve the algebra +// Solve the algebra #ifdef CHECK_EQS string eqs_name = pcs_type_name + "_EQS.txt"; - MXDumpGLS((char*)eqs_name.c_str(),1,eqs->b,eqs->x); + MXDumpGLS((char*)eqs_name.c_str(), 1, eqs->b, eqs->x); #endif #if defined(USE_PETSC) -// std::string eqs_output_file = FileName + number2str(aktueller_zeitschritt); -// eqs_new->EQSV_Viewer(eqs_output_file); + // std::string eqs_output_file = FileName + number2str(aktueller_zeitschritt); + // eqs_new->EQSV_Viewer(eqs_output_file); eqs_new->Solver(); eqs_new->MappingSolution(); #else -#ifdef NEW_EQS //WW +#ifdef NEW_EQS // WW #if defined(USE_MPI) - //21.12.2007 + // 21.12.2007 dom->eqs->Solver(eqs_new->x, global_eqs_dim); #else #if defined(LIS) || defined(MKL) - eqs_new->Solver(this->m_num); //NW + eqs_new->Solver(this->m_num); // NW #else eqs_new->Solver(); // kg44 the next lines are for debug? @@ -4911,43 +4858,43 @@ double CRFProcess::Execute() #else // ifdef NEW_EQS ExecuteLinearSolver(); #endif -#endif //USE_PETSC +#endif // USE_PETSC } //---------------------------------------------------------------------- // END OF FLUX CORRECTED TRANSPORT //---------------------------------------------------------------------- - //PCSDumpModelNodeValues(); + // PCSDumpModelNodeValues(); //---------------------------------------------------------------------- // ERROR CALCULATION //---------------------------------------------------------------------- - // - // Save the solution of the prevoius iteration of the nonlinear step for - // the automatic time stepping. Modified for PETsc solver. 03.07.2012. WW - if(Tim->GetPITimeStepCrtlType() > 0) - { - double *x_k = NULL; - bool get_buffer_u_k = true; - x_k= _problem->GetBufferArray(get_buffer_u_k); - for (int i = 0; i < pcs_number_of_primary_nvals; i++) - { - nidx1 = GetNodeValueIndex(pcs_primary_function_name[i]) + 1; + // + // Save the solution of the prevoius iteration of the nonlinear step for + // the automatic time stepping. Modified for PETsc solver. 03.07.2012. WW + if (Tim->GetPITimeStepCrtlType() > 0) + { + double* x_k = NULL; + bool get_buffer_u_k = true; + x_k = _problem->GetBufferArray(get_buffer_u_k); + for (int i = 0; i < pcs_number_of_primary_nvals; i++) + { + nidx1 = GetNodeValueIndex(pcs_primary_function_name[i]) + 1; #if !defined(USE_PETSC) // && !defined(other parallel libs) - const long ish = i * g_nnodes; + const long ish = i * g_nnodes; #endif - for (j = 0; j < g_nnodes; j++) - { + for (j = 0; j < g_nnodes; j++) + { #if defined(USE_PETSC) // || defined(other parallel libs) - x_k[j*pcs_number_of_primary_nvals + i] = GetNodeValue(j, nidx1); + x_k[j * pcs_number_of_primary_nvals + i] = GetNodeValue(j, nidx1); #else - x_k[j + ish] = GetNodeValue(m_msh->Eqs2Global_NodeIndex[j], nidx1); + x_k[j + ish] = GetNodeValue(m_msh->Eqs2Global_NodeIndex[j], nidx1); #endif - } - } - } + } + } + } #if defined(USE_PETSC) // || defined(other parallel libs)//03.3012. WW - //PICARD + // PICARD //---------------------------------------------------------------------- // Error calculation //---------------------------------------------------------------------- @@ -4955,34 +4902,37 @@ double CRFProcess::Execute() { eqs_x = eqs_new->GetGlobalSolution(); //...................................................................... - pcs_error = CalcIterationNODError(1); //OK4105//WW4117 - if(myrank == 0) - cout << " PCS error: " << pcs_error << "\n"; - + pcs_error = CalcIterationNODError(1); // OK4105//WW4117 + if (myrank == 0) + cout << " PCS error: " << pcs_error << "\n"; //-------------------------------------------------------------------- // 7 Store solution vector in model node values table //.................................................................... for (int i = 0; i < pcs_number_of_primary_nvals; i++) { - nidx1 = GetNodeValueIndex(pcs_primary_function_name[i]) + 1; - for (j = 0; j < g_nnodes; j++) - { - k = m_msh->Eqs2Global_NodeIndex[j] * pcs_number_of_primary_nvals + i; - SetNodeValue(j, nidx1, (1.-nl_theta )* GetNodeValue(j, nidx1) + nl_theta * eqs_x[k]); - } + nidx1 = GetNodeValueIndex(pcs_primary_function_name[i]) + 1; + for (j = 0; j < g_nnodes; j++) + { + k = m_msh->Eqs2Global_NodeIndex[j] * pcs_number_of_primary_nvals + i; + SetNodeValue(j, nidx1, (1. - nl_theta) * GetNodeValue(j, nidx1) + nl_theta * eqs_x[k]); + } } - } // END PICARD + } // END PICARD #else // JT: Coupling error was wrong. Now ok. - if(iter_nlin > 0){ // Just getting NL error - pcs_error = CalcIterationNODError(m_num->getNonLinearErrorMethod(),true,false); //OK4105//WW4117//JT + if (iter_nlin > 0) + { // Just getting NL error + pcs_error = CalcIterationNODError(m_num->getNonLinearErrorMethod(), true, false); // OK4105//WW4117//JT } - else{ // Getting NL and CPL error - pcs_error = CalcIterationNODError(m_num->getCouplingErrorMethod(),true,true); //JT2012 - if(m_num->getNonLinearErrorMethod() != m_num->getCouplingErrorMethod()) //JT: If CPL error method is different, must call separately - pcs_error = CalcIterationNODError(m_num->getNonLinearErrorMethod(),true,false); //JT2012 // get the NLS error. CPL was obtained before. + else + { // Getting NL and CPL error + pcs_error = CalcIterationNODError(m_num->getCouplingErrorMethod(), true, true); // JT2012 + if (m_num->getNonLinearErrorMethod() + != m_num->getCouplingErrorMethod()) // JT: If CPL error method is different, must call separately + pcs_error = CalcIterationNODError(m_num->getNonLinearErrorMethod(), true, + false); // JT2012 // get the NLS error. CPL was obtained before. } //---------------------------------------------------------------------- @@ -4990,76 +4940,75 @@ double CRFProcess::Execute() //---------------------------------------------------------------------- if (m_num->nls_method_name.find("PICARD") != string::npos) { - if(pcs_error < 1.0) // JT: Then the solution has converged, take the final value + if (pcs_error < 1.0) // JT: Then the solution has converged, take the final value nl_theta = 1.0; #if defined(USE_PETSC) // || defined(other parallel libs)//03.3012. WW eqs_x = eqs_new->GetGlobalSolution(); #endif - // - if(nl_theta > implicit_lim) // This is most common. So go for the lesser calculations. + // + if (nl_theta > implicit_lim) // This is most common. So go for the lesser calculations. { for (int ii = 0; ii < pcs_number_of_primary_nvals; ii++) { - nidx1 = GetNodeValueIndex(pcs_primary_function_name[ii]) + 1; - const long nshift = ii*g_nnodes; - for(j=0; jEqs2Global_NodeIndex[j] + ii; - const double val_n = GetNodeValue(j, nidx1); //03.04.2009. WW - SetNodeValue(j, nidx1, eqs_x[k] ); - eqs_x[k] = val_n; // Used for time stepping. 03.04.2009. WW + k = pcs_number_of_primary_nvals * m_msh->Eqs2Global_NodeIndex[j] + ii; + const double val_n = GetNodeValue(j, nidx1); // 03.04.2009. WW + SetNodeValue(j, nidx1, eqs_x[k]); + eqs_x[k] = val_n; // Used for time stepping. 03.04.2009. WW #else - k = m_msh->Eqs2Global_NodeIndex[j]; - const double val_n = GetNodeValue(k, nidx1); //03.04.2009. WW - SetNodeValue(k, nidx1, eqs_x[j + nshift]); - eqs_x[j + nshift] = val_n; // Used for time stepping. 03.04.2009. WW + k = m_msh->Eqs2Global_NodeIndex[j]; + const double val_n = GetNodeValue(k, nidx1); // 03.04.2009. WW + SetNodeValue(k, nidx1, eqs_x[j + nshift]); + eqs_x[j + nshift] = val_n; // Used for time stepping. 03.04.2009. WW #endif - } + } } } else { for (int ii = 0; ii < pcs_number_of_primary_nvals; ii++) { - nidx1 = GetNodeValueIndex(pcs_primary_function_name[ii]) + 1; - const long nshift = ii*g_nnodes; - for(j=0; jEqs2Global_NodeIndex[j] + ii; - const double val_n = GetNodeValue(j, nidx1); - SetNodeValue(j, nidx1, (1.0-nl_theta)*val_n + nl_theta * eqs_x[k]); - eqs_x[k] = val_n; // Used for time stepping. 03.04.2009. WW + k = pcs_number_of_primary_nvals * m_msh->Eqs2Global_NodeIndex[j] + ii; + const double val_n = GetNodeValue(j, nidx1); + SetNodeValue(j, nidx1, (1.0 - nl_theta) * val_n + nl_theta * eqs_x[k]); + eqs_x[k] = val_n; // Used for time stepping. 03.04.2009. WW #else - k = m_msh->Eqs2Global_NodeIndex[j]; - const double val_n = GetNodeValue(k, nidx1); //03.04.2009. WW - SetNodeValue(k, nidx1, (1.0-nl_theta)*val_n + nl_theta*eqs_x[j + nshift]); - eqs_x[j + nshift] = val_n; // Used for time stepping. 03.04.2009. WW + k = m_msh->Eqs2Global_NodeIndex[j]; + const double val_n = GetNodeValue(k, nidx1); // 03.04.2009. WW + SetNodeValue(k, nidx1, (1.0 - nl_theta) * val_n + nl_theta * eqs_x[j + nshift]); + eqs_x[j + nshift] = val_n; // Used for time stepping. 03.04.2009. WW #endif - } + } } } // maybe works also for other processes involving velocities // update nod velocity if constrained BC // do I really need to check every single bc node, or how can I access a bc group? - if ( (this->hasConstrainedBC() || this->hasConstrainedST()) - && this->accepted - && (this->getProcessType() == FiniteElement::RICHARDS_FLOW - || this->getProcessType() == FiniteElement::LIQUID_FLOW) ) + if ((this->hasConstrainedBC() || this->hasConstrainedST()) && this->accepted + && (this->getProcessType() == FiniteElement::RICHARDS_FLOW + || this->getProcessType() == FiniteElement::LIQUID_FLOW)) { this->CalIntegrationPointValue(); this->Extropolation_GaussValue(); } } - //---------------------------------------------------------------------- - // END OF PICARD - //---------------------------------------------------------------------- +//---------------------------------------------------------------------- +// END OF PICARD +//---------------------------------------------------------------------- #endif -#ifdef NEW_EQS //WW - if(!configured_in_nonlinearloop) +#ifdef NEW_EQS // WW + if (!configured_in_nonlinearloop) #if defined(USE_MPI) dom->eqs->Clean(); #else @@ -5068,7 +5017,7 @@ double CRFProcess::Execute() #endif #endif - if(BASELIB::isNAN(pcs_error)) + if (BASELIB::isNAN(pcs_error)) { accepted = false; } @@ -5089,12 +5038,12 @@ void CRFProcess::CopyU_n() int i, nidx1; long g_nnodes, j; - double *temp_v = _problem->GetBufferArray(); + double* temp_v = _problem->GetBufferArray(); - for(i = 0; i < pcs_number_of_primary_nvals; i++) + for (i = 0; i < pcs_number_of_primary_nvals; i++) { /// H2M with monilithic scheme. 02.2011. WW - if(type == 42) + if (type == 42) { nidx1 = p_var_index[i] + 1; g_nnodes = num_nodes_p_var[i]; @@ -5102,23 +5051,22 @@ void CRFProcess::CopyU_n() else { nidx1 = GetNodeValueIndex(pcs_primary_function_name[i]) + 1; - g_nnodes = m_msh->GetNodesNumber(false); //DOF>1, WW + g_nnodes = m_msh->GetNodesNumber(false); // DOF>1, WW } #if !defined(USE_PETSC) // && !defined(other parallel libs) - const long ish = i * g_nnodes; + const long ish = i * g_nnodes; #endif - for(j = 0; j < g_nnodes; j++) - { + for (j = 0; j < g_nnodes; j++) + { #if defined(USE_PETSC) // || defined(other parallel libs)//03.3012. WW - temp_v[j* pcs_number_of_primary_nvals + i] = GetNodeValue(j,nidx1); + temp_v[j * pcs_number_of_primary_nvals + i] = GetNodeValue(j, nidx1); #else - temp_v[j + ish] = GetNodeValue(m_msh->Eqs2Global_NodeIndex[j],nidx1); + temp_v[j + ish] = GetNodeValue(m_msh->Eqs2Global_NodeIndex[j], nidx1); #endif } } } - /************************************************************************* ROCKFLOW - Function: Task: Calculate element matrices @@ -5129,26 +5077,25 @@ void CRFProcess::CopyU_n() **************************************************************************/ void CRFProcess::CalculateElementMatrices(void) { - switch(this->type) - { - case 1: //SM - case 2: //MTM2 - case 3: //HTM - case 5: // Gas flow - case 11: - case 12: //MMP - case 13: //MPC - case 14: //TNEQ - case 15: //TES - case 66: //OF - break; - default: - DisplayMsgLn("CalculateElementMatrices: no CalculateElementMatrices specified"); - abort(); + switch (this->type) + { + case 1: // SM + case 2: // MTM2 + case 3: // HTM + case 5: // Gas flow + case 11: + case 12: // MMP + case 13: // MPC + case 14: // TNEQ + case 15: // TES + case 66: // OF + break; + default: + DisplayMsgLn("CalculateElementMatrices: no CalculateElementMatrices specified"); + abort(); } } - /************************************************************************* GeoSys-Function: Task: Algebraic operation for the flux corrected transport (FCT) @@ -5163,16 +5110,16 @@ void CRFProcess::AddFCT_CorrectionVector() int idx1 = idx0 + 1; const double theta = this->m_num->ls_theta; const size_t node_size = m_msh->GetNodesNumber(false); - SparseMatrixDOK::mat_t &fct_f = this->FCT_AFlux->GetRawData(); + SparseMatrixDOK::mat_t& fct_f = this->FCT_AFlux->GetRawData(); SparseMatrixDOK::col_t* col; SparseMatrixDOK::mat_t::const_iterator ii; SparseMatrixDOK::col_t::const_iterator jj; Math_Group::Vec* ML = this->Gl_ML; #if defined(NEW_EQS) - CSparseMatrix* A = NULL; //WW - //if(m_dom) + CSparseMatrix* A = NULL; // WW + // if(m_dom) // A = m_dom->eqs->A; - //else + // else A = this->eqs_new->A; #endif @@ -5208,52 +5155,53 @@ void CRFProcess::AddFCT_CorrectionVector() for (size_t i = 0; i < node_size; i++) { col = &fct_f[i]; - for(jj = col->begin(); jj != col->end(); jj++) + for (jj = col->begin(); jj != col->end(); jj++) { const size_t j = (*jj).first; if (i > j) - continue; //symmetric part, off-diagonal + continue; // symmetric part, off-diagonal double diff_uH = this->GetNodeValue(i, idx1) - this->GetNodeValue(j, idx1); double diff_u0 = this->GetNodeValue(i, idx0) - this->GetNodeValue(j, idx0); double v = 1.0 / dt * (diff_uH - diff_u0); - (*FCT_AFlux)(i,j) *= v; //MC is already done in local ele assembly - (*FCT_AFlux)(j,i) *= -v; //MC is already done in local ele assembly + (*FCT_AFlux)(i, j) *= v; // MC is already done in local ele assembly + (*FCT_AFlux)(j, i) *= -v; // MC is already done in local ele assembly } } - //Complete f, L - //Remark: Using iteration is only possible after the sparse table has been constructed. - for(size_t i = 0; i < node_size; i++) + // Complete f, L + // Remark: Using iteration is only possible after the sparse table has been constructed. + for (size_t i = 0; i < node_size; i++) { #ifdef USE_PETSC const size_t i_global = FCT_GLOB_ADDRESS(i); #endif col = &fct_f[i]; - for(jj = col->begin(); jj != col->end(); jj++) + for (jj = col->begin(); jj != col->end(); jj++) { const size_t j = (*jj).first; - if (i > j || i==j) - continue; //do below only for upper triangle due to symmetric + if (i > j || i == j) + continue; // do below only for upper triangle due to symmetric - // Get artificial diffusion operator D +// Get artificial diffusion operator D #ifdef USE_PETSC const size_t j_global = FCT_GLOB_ADDRESS(j); double d1 = (*FCT_d)(i_global, j_global); #else #if defined(NEW_EQS) - double K_ij = (*A)(i,j); - double K_ji = (*A)(j,i); + double K_ij = (*A)(i, j); + double K_ji = (*A)(j, i); #else - double K_ij = MXGet(i,j); - double K_ji = MXGet(j,i); + double K_ij = MXGet(i, j); + double K_ji = MXGet(j, i); #endif if (K_ij == 0.0 && K_ji == 0.0) continue; double d1 = GetFCTADiff(K_ij, K_ji); #endif - if (d1 == 0.0) continue; - double d0 = d1; //TODO should use AuxMatrix at the previous time step - //if (list_bc_nodes.find(i)!=list_bc_nodes.end() || list_bc_nodes.find(j)!=list_bc_nodes.end()) { + if (d1 == 0.0) + continue; + double d0 = d1; // TODO should use AuxMatrix at the previous time step + // if (list_bc_nodes.find(i)!=list_bc_nodes.end() || list_bc_nodes.find(j)!=list_bc_nodes.end()) { // d1 = d0 = 0.0; //} @@ -5261,10 +5209,10 @@ void CRFProcess::AddFCT_CorrectionVector() double diff_uH = this->GetNodeValue(i, idx1) - this->GetNodeValue(j, idx1); double diff_u0 = this->GetNodeValue(i, idx0) - this->GetNodeValue(j, idx0); double v = -(theta * d1 * diff_uH + (1.0 - theta) * d0 * diff_u0); - (*FCT_AFlux)(i,j) += v; + (*FCT_AFlux)(i, j) += v; - //prelimiting f - v = (*FCT_AFlux)(i,j); + // prelimiting f + v = (*FCT_AFlux)(i, j); if (this->m_num->fct_prelimiter_type == 0) { if (v * (-diff_uH) > 0.0) @@ -5283,28 +5231,30 @@ void CRFProcess::AddFCT_CorrectionVector() #ifdef USE_PETSC // A += theta * D - if (i < (size_t)m_msh->getNumNodesLocal()) { - eqs_new->addMatrixEntry(i_global, i_global, -d1*theta); - eqs_new->addMatrixEntry(i_global, j_global, d1*theta); + if (i < (size_t)m_msh->getNumNodesLocal()) + { + eqs_new->addMatrixEntry(i_global, i_global, -d1 * theta); + eqs_new->addMatrixEntry(i_global, j_global, d1 * theta); } - if (j < (size_t)m_msh->getNumNodesLocal()) { - eqs_new->addMatrixEntry(j_global, i_global, d1*theta); - eqs_new->addMatrixEntry(j_global, j_global, -d1*theta); + if (j < (size_t)m_msh->getNumNodesLocal()) + { + eqs_new->addMatrixEntry(j_global, i_global, d1 * theta); + eqs_new->addMatrixEntry(j_global, j_global, -d1 * theta); } #else - // L = K + D +// L = K + D #if defined(NEW_EQS) - (*A)(i,i) += -d1; - (*A)(i,j) += d1; - (*A)(j,i) += d1; - (*A)(j,j) += -d1; + (*A)(i, i) += -d1; + (*A)(i, j) += d1; + (*A)(j, i) += d1; + (*A)(j, j) += -d1; #else // add off-diagonal term - MXInc(i,j,d1); - MXInc(j,i,d1); + MXInc(i, j, d1); + MXInc(j, i, d1); // add diagonal term - MXInc(i,i,-d1); - MXInc(j,j,-d1); + MXInc(i, i, -d1); + MXInc(j, j, -d1); #endif #endif } @@ -5330,7 +5280,7 @@ void CRFProcess::AddFCT_CorrectionVector() { // u^n for (size_t i = 0; i < node_size; i++) - (*V1)(i) = this->GetNodeValue(i,idx0); + (*V1)(i) = this->GetNodeValue(i, idx0); // L*u^n for (size_t i = 0; i < node_size; i++) { @@ -5342,25 +5292,27 @@ void CRFProcess::AddFCT_CorrectionVector() #ifdef USE_PETSC const size_t j_global = FCT_GLOB_ADDRESS(j); // b+=-(1-theta)*D*u^n - (*V)(i) += (*FCT_d)(i_global, j_global) * (*V1)(j); + (*V)(i) += (*FCT_d)(i_global, j_global) * (*V1)(j); #else #ifdef NEW_EQS - (*V)(i) += (*A)(i,j) * (*V1)(j); + (*V)(i) += (*A)(i, j) * (*V1)(j); #else - (*V)(i) += MXGet(i,j) * (*V1)(j); + (*V)(i) += MXGet(i, j) * (*V1)(j); #endif #endif } } - for (size_t i = 0; i < node_size; i++) { + for (size_t i = 0; i < node_size; i++) + { #if defined(USE_PETSC) - if (i < (size_t)m_msh->getNumNodesLocal()) { + if (i < (size_t)m_msh->getNumNodesLocal()) + { const size_t i_global = FCT_GLOB_ADDRESS(i); - eqs_new->add_bVectorEntry(i_global, - (1.0 - theta) * (*V)(i), ADD_VALUES); + eqs_new->add_bVectorEntry(i_global, -(1.0 - theta) * (*V)(i), ADD_VALUES); } #else eqs_rhs[i] -= (1.0 - theta) * (*V)(i); - //(*RHS)(i+LocalShift) += NodalVal[i]; +//(*RHS)(i+LocalShift) += NodalVal[i]; #endif } } @@ -5377,13 +5329,13 @@ void CRFProcess::AddFCT_CorrectionVector() #else for (size_t i = 0; i < node_size; i++) for (size_t j = 0; j < node_size; j++) - MXSet(i,j,0.0); + MXSet(i, j, 0.0); #endif } else if (theta == 1.0) { - //keep + // keep } else { @@ -5392,7 +5344,7 @@ void CRFProcess::AddFCT_CorrectionVector() #else for (size_t i = 0; i < node_size; i++) for (size_t j = 0; j < node_size; j++) - MXMul(i,j,theta); + MXMul(i, j, theta); #endif } @@ -5401,9 +5353,9 @@ void CRFProcess::AddFCT_CorrectionVector() { double v = 1.0 / dt * (*ML)(i); #ifdef NEW_EQS - (*A)(i,i) += v; + (*A)(i, i) += v; #else - MXInc(i,i,v); + MXInc(i, i, v); #endif } #endif @@ -5416,20 +5368,20 @@ void CRFProcess::AddFCT_CorrectionVector() Math_Group::Vec* R_min = this->Gl_Vec; (*R_plus) = 0.0; (*R_min) = 0.0; - for(size_t i = 0; i < node_size; i++) + for (size_t i = 0; i < node_size; i++) { - const size_t i_global = FCT_GLOB_ADDRESS(i); + const size_t i_global = FCT_GLOB_ADDRESS(i); double P_plus, P_min; double Q_plus, Q_min; P_plus = P_min = 0.0; Q_plus = Q_min = 0.0; col = &fct_f[i]; - for(jj = col->begin(); jj != col->end(); jj++) + for (jj = col->begin(); jj != col->end(); jj++) { const size_t j = (*jj).first; if (i == j) continue; - double f = (*jj).second; //double f = (*FCT_AFlux)(i,j); + double f = (*jj).second; // double f = (*FCT_AFlux)(i,j); #ifndef USE_PETSC if (i > j) f *= -1.0; @@ -5454,7 +5406,7 @@ void CRFProcess::AddFCT_CorrectionVector() } #ifdef USE_PETSC - FCT_MPI::gatherR(FCT_MPI::ct, *R_plus, *R_min); + FCT_MPI::gatherR(FCT_MPI::ct, *R_plus, *R_min); #endif // for Dirichlet nodes @@ -5462,7 +5414,7 @@ void CRFProcess::AddFCT_CorrectionVector() { CBoundaryConditionNode* bc_node = bc_node_value[i]; long nod_id = bc_node->geo_node_number; - const size_t i_global = FCT_GLOB_ADDRESS(nod_id); + const size_t i_global = FCT_GLOB_ADDRESS(nod_id); (*R_plus)(i_global) = 1.0; (*R_min)(i_global) = 1.0; } @@ -5475,14 +5427,14 @@ void CRFProcess::AddFCT_CorrectionVector() for (jj = col->begin(); jj != col->end(); jj++) { const size_t j = (*jj).first; - const size_t j_global = FCT_GLOB_ADDRESS(j); + const size_t j_global = FCT_GLOB_ADDRESS(j); if (i == j) continue; - double f = (*jj).second; //double f = (*FCT_AFlux)(i,j); + double f = (*jj).second; // double f = (*FCT_AFlux)(i,j); #ifndef USE_PETSC if (i > j) - f *= -1; // symmetric + f *= -1; // symmetric #endif double alpha = 1.0; if (f > 0) @@ -5500,11 +5452,11 @@ void CRFProcess::AddFCT_CorrectionVector() if (i < (size_t)m_msh->getNumNodesLocal()) eqs_new->add_bVectorEntry(i_global, val, ADD_VALUES); #else - eqs_rhs[i] += val; + eqs_rhs[i] += val; #endif - //Note: Galerkin FEM is recovered if alpha = 1 as below, - //eqs_rhs[i] += 1.0*f; + // Note: Galerkin FEM is recovered if alpha = 1 as below, + // eqs_rhs[i] += 1.0*f; } } } @@ -5526,7 +5478,7 @@ void CRFProcess::AddFCT_CorrectionVector() void CRFProcess::GlobalAssembly() { #ifdef USE_PETSC - PetscLogDouble v1,v2; + PetscLogDouble v1, v2; #ifdef USEPETSC34 PetscTime(&v1); #else @@ -5539,7 +5491,8 @@ void CRFProcess::GlobalAssembly() Tim = TIMGet(convertProcessTypeToString(this->getProcessType())); if (!Tim) { - cout << "Error in CRFProcess::GlobalAssembly() - no TIM data" << "\n"; + cout << "Error in CRFProcess::GlobalAssembly() - no TIM data" + << "\n"; return; } @@ -5553,21 +5506,21 @@ void CRFProcess::GlobalAssembly() CElem* elem = NULL; - if(m_num->nls_method == 2) //06.09.2010. WW + if (m_num->nls_method == 2) // 06.09.2010. WW IncorporateBoundaryConditions(); bool Check2D3D; Check2D3D = false; - if (type == 66) //Overland flow + if (type == 66) // Overland flow Check2D3D = true; - if (this->femFCTmode) //NW + if (this->femFCTmode) // NW { (*this->FCT_AFlux) = 0.0; (*this->Gl_ML) = 0.0; (*this->Gl_Vec) = 0.0; (*this->Gl_Vec1) = 0.0; #ifdef USE_PETSC - (*this->FCT_K) = 0.0; - (*this->FCT_d) = .0; + (*this->FCT_K) = 0.0; + (*this->FCT_d) = .0; #endif } @@ -5578,7 +5531,7 @@ void CRFProcess::GlobalAssembly() cout << " Domain Decomposition" << '\n'; CPARDomain* m_dom = NULL; size_t j = 0; -#if defined(USE_MPI) //WW +#if defined(USE_MPI) // WW j = myrank; #else for (j = 0; j < dom_vector.size(); j++) @@ -5588,142 +5541,142 @@ void CRFProcess::GlobalAssembly() #ifdef NEW_EQS m_dom->InitialEQS(this); #else - SetLinearSolver(m_dom->eqs); - SetZeroLinearSolver(m_dom->eqs); + SetLinearSolver(m_dom->eqs); + SetZeroLinearSolver(m_dom->eqs); #endif for (size_t i = 0; i < m_dom->elements.size(); i++) { elem = m_msh->ele_vector[m_dom->elements[i]]; - if (elem->GetMark() && elem->GetExcavState()==-1)//WX:10.2012 + if (elem->GetMark() && elem->GetExcavState() == -1) // WX:10.2012 { elem->SetOrder(false); - //WW + // WW fem->SetElementNodesDomain(m_dom->element_nodes_dom[i]); fem->ConfigElement(elem, m_num->ele_gauss_points, Check2D3D); - fem->m_dom = m_dom; //OK + fem->m_dom = m_dom; // OK fem->Assembly(); } } // m_dom->WriteMatrix(); - //MXDumpGLS("rf_pcs.txt",1,m_dom->eqs->b,m_dom->eqs->x); - //ofstream Dum("rf_pcs.txt", ios::out); // WW - //m_dom->eqs->Write(Dum); - //Dum.close(); + // MXDumpGLS("rf_pcs.txt",1,m_dom->eqs->b,m_dom->eqs->x); + // ofstream Dum("rf_pcs.txt", ios::out); // WW + // m_dom->eqs->Write(Dum); + // Dum.close(); IncorporateSourceTerms(j); - if(m_num->nls_method != 2) //06.09.2010. WW + if (m_num->nls_method != 2) // 06.09.2010. WW IncorporateBoundaryConditions(j); - /* - //TEST - string test = "rank"; - char stro[64]; - sprintf(stro, "%d",j); - string test1 = test+(string)stro+"Assemble.txt"; - ofstream Dum(test1.c_str(), ios::out); - m_dom->eqs->Write(Dum); - Dum.close(); - exit(1); - */ +/* + //TEST + string test = "rank"; + char stro[64]; + sprintf(stro, "%d",j); + string test1 = test+(string)stro+"Assemble.txt"; + ofstream Dum(test1.c_str(), ios::out); + m_dom->eqs->Write(Dum); + Dum.close(); + exit(1); + */ #ifndef USE_MPI } // Assemble global system DDCAssembleGlobalMatrix(); #endif - } - else +} +else #endif //#if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW - { // STD - //YDTEST. Changed to DOF 15.02.2007 WW - for (size_t ii = 0; ii < continuum_vector.size(); ii++) +{ // STD + // YDTEST. Changed to DOF 15.02.2007 WW + for (size_t ii = 0; ii < continuum_vector.size(); ii++) + { + continuum = ii; + for (size_t i = 0; i < m_msh->ele_vector.size(); i++) { - continuum = ii; - for (size_t i = 0; i < m_msh->ele_vector.size(); i++) + elem = m_msh->ele_vector[i]; + // Marked for use //WX: modified for coupled excavation + if (elem->GetMark() && elem->GetExcavState() == -1) { - elem = m_msh->ele_vector[i]; - // Marked for use //WX: modified for coupled excavation - if (elem->GetMark() && elem->GetExcavState() == -1) + elem->SetOrder(false); + fem->ConfigElement(elem, m_num->ele_gauss_points, Check2D3D); + fem->Assembly(); + // NEUMANN CONTROL--------- + if (Tim->time_control_type == TimeControlType::NEUMANN) { - elem->SetOrder(false); - fem->ConfigElement(elem, m_num->ele_gauss_points, Check2D3D); - fem->Assembly(); - // NEUMANN CONTROL--------- - if (Tim->time_control_type == TimeControlType::NEUMANN) - { - Tim->time_step_length_neumann = MMin( - Tim->time_step_length_neumann, timebuffer); - Tim->time_step_length_neumann *= 0.5 - * elem->GetVolume() - * elem->GetVolume(); - if (Tim->time_step_length_neumann < MKleinsteZahl) - Tim->time_step_length_neumann = 1.0e-5; - } - //------------------------------ + Tim->time_step_length_neumann = MMin(Tim->time_step_length_neumann, timebuffer); + Tim->time_step_length_neumann *= 0.5 * elem->GetVolume() * elem->GetVolume(); + if (Tim->time_step_length_neumann < MKleinsteZahl) + Tim->time_step_length_neumann = 1.0e-5; } + //------------------------------ } } + } - if (femFCTmode) //NW - AddFCT_CorrectionVector(); + if (femFCTmode) // NW + AddFCT_CorrectionVector(); - // MXDumpGLS("rf_pcs1.txt",1,eqs->b,eqs->x); //abort(); - //eqs_new->Write(); - IncorporateSourceTerms(); + // MXDumpGLS("rf_pcs1.txt",1,eqs->b,eqs->x); //abort(); + // eqs_new->Write(); + IncorporateSourceTerms(); - //MXDumpGLS("rf_pcs1.txt",1,eqs->b,eqs->x); //abort(); +// MXDumpGLS("rf_pcs1.txt",1,eqs->b,eqs->x); //abort(); #ifdef GEM_REACT - if( getProcessType() == FiniteElement::MASS_TRANSPORT && aktueller_zeitschritt > 1) - { // JT->KG. New coupling system. - if( _problem->GetCPLMaxIterations() > 1 || // Then there is a coupling on all processes - (this->pcs_is_cpl_overlord && this->m_num->cpl_max_iterations > 1) || // This process (the overlord) controls coupling for another (the underling) process. - (this->pcs_is_cpl_underling && this->cpl_overlord->m_num->cpl_max_iterations > 1)) // This process (the underling) has a coupling with a controlling (the overlord) process - { - //IncorporateSourceTerms_GEMS(); - } + if (getProcessType() == FiniteElement::MASS_TRANSPORT && aktueller_zeitschritt > 1) + { // JT->KG. New coupling system. + if (_problem->GetCPLMaxIterations() > 1 || // Then there is a coupling on all processes + (this->pcs_is_cpl_overlord && this->m_num->cpl_max_iterations > 1) + || // This process (the overlord) controls coupling for another (the underling) process. + (this->pcs_is_cpl_underling + && this->cpl_overlord->m_num->cpl_max_iterations + > 1)) // This process (the underling) has a coupling with a controlling (the overlord) process + { + // IncorporateSourceTerms_GEMS(); } + } #endif #if !defined(USE_PETSC) && !defined(NEW_EQS) // && !defined(other parallel libs)//03~04.3012. WW - //#ifndef NEW_EQS //WW. 07.11.2008 - SetCPL(); //OK + //#ifndef NEW_EQS //WW. 07.11.2008 + SetCPL(); // OK #endif -#if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. - eqs_new->AssembleRHS_PETSc(); - eqs_new->AssembleMatrixPETSc(MAT_FINAL_ASSEMBLY ); +#if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. + eqs_new->AssembleRHS_PETSc(); + eqs_new->AssembleMatrixPETSc(MAT_FINAL_ASSEMBLY); #endif - IncorporateBoundaryConditions(); + IncorporateBoundaryConditions(); - //ofstream Dum("rf_pcs.txt", ios::out); // WW - // eqs_new->Write(Dum); Dum.close(); +// ofstream Dum("rf_pcs.txt", ios::out); // WW +// eqs_new->Write(Dum); Dum.close(); #define nOUTPUT_EQS_BIN #ifdef OUTPUT_EQS_BIN - string fname = FileName + "_equation.bin"; - ofstream dum_bin(fname.c_str(), ios::out | ios::binary | ios::trunc); - if(dum_bin.good()) - { - eqs_new->Write_BIN(dum_bin); - dum_bin.close(); - exit(1); - } + string fname = FileName + "_equation.bin"; + ofstream dum_bin(fname.c_str(), ios::out | ios::binary | ios::trunc); + if (dum_bin.good()) + { + eqs_new->Write_BIN(dum_bin); + dum_bin.close(); + exit(1); + } #endif - // - // +// +// - // MXDumpGLS("rf_pcs1.txt",1,eqs->b,eqs->x); //abort(); -#if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. - MPI_Barrier (MPI_COMM_WORLD); - // eqs_new->AssembleRHS_PETSc(); - //eqs_new->AssembleMatrixPETSc(MAT_FINAL_ASSEMBLY ); +// MXDumpGLS("rf_pcs1.txt",1,eqs->b,eqs->x); //abort(); +#if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. + MPI_Barrier(MPI_COMM_WORLD); +// eqs_new->AssembleRHS_PETSc(); +// eqs_new->AssembleMatrixPETSc(MAT_FINAL_ASSEMBLY ); #endif - } +} #ifdef USE_PETSC #ifdef USEPETSC34 - PetscTime(&v2); +PetscTime(&v2); #else - PetscGetTime(&v2); + PetscGetTime(&v2); #endif - cpu_time_assembly += v2 - v1; +cpu_time_assembly += v2 - v1; #endif } @@ -5738,11 +5691,11 @@ void CRFProcess::GlobalAssembly_std(bool is_quad, bool Check2D3D) long i; CElem* elem = NULL; - for(i = 0; i < (long)m_msh->ele_vector.size(); i++) + for (i = 0; i < (long)m_msh->ele_vector.size(); i++) { elem = m_msh->ele_vector[i]; - if (!elem->GetMark()) // Marked for use - continue; // For OpenMP. WW + if (!elem->GetMark()) // Marked for use + continue; // For OpenMP. WW elem->SetOrder(is_quad); fem->ConfigElement(elem, m_num->ele_gauss_points, Check2D3D); @@ -5756,7 +5709,7 @@ void CRFProcess::GlobalAssembly_std(bool is_quad, bool Check2D3D) Programming: 05/2009 WW Implementation **************************************************************************/ -void CRFProcess::Integration(vector &node_velue) +void CRFProcess::Integration(vector& node_velue) { //---------------------------------------------------------------------- size_t k; @@ -5766,27 +5719,27 @@ void CRFProcess::Integration(vector &node_velue) Check2D3D = false; double n_val[8]; - if(type == 66) //Overland flow + if (type == 66) // Overland flow Check2D3D = true; vector buffer((long)node_velue.size()); - for(i = 0; i < (long)buffer.size(); i++) + for (i = 0; i < (long)buffer.size(); i++) buffer[i] = 0.; - for(i = 0; i < (long)m_msh->ele_vector.size(); i++) + for (i = 0; i < (long)m_msh->ele_vector.size(); i++) { elem = m_msh->ele_vector[i]; - if(!elem->GetMark()) + if (!elem->GetMark()) continue; - for(k = 0; k < elem->GetNodesNumber(false); k++) + for (k = 0; k < elem->GetNodesNumber(false); k++) n_val[k] = node_velue[elem->GetNodeIndex(k)]; elem->SetOrder(false); fem->ConfigElement(elem, m_num->ele_gauss_points, Check2D3D); fem->FaceIntegration(n_val); - for(k = 0; k < elem->GetNodesNumber(false); k++) + for (k = 0; k < elem->GetNodesNumber(false); k++) buffer[elem->GetNodeIndex(k)] += n_val[k]; } //---------------------------------------------------------------------- @@ -5802,7 +5755,7 @@ void CRFProcess::Integration(vector &node_velue) void CRFProcess::CalIntegrationPointValue() { CElem* elem = NULL; - continuum = 0; //15.02.2007/ + continuum = 0; // 15.02.2007/ // cal_integration_point_value = true; // Currently, extropolation only valid for liquid and Richards flow. // if (_pcs_type_name.find("LIQUID") != string::npos || _pcs_type_name.find( @@ -5815,118 +5768,127 @@ void CRFProcess::CalIntegrationPointValue() switch (getProcessType()) { - case FiniteElement::LIQUID_FLOW: - case FiniteElement::RICHARDS_FLOW: - case FiniteElement::MULTI_PHASE_FLOW: - case FiniteElement::GROUNDWATER_FLOW: - case FiniteElement::TWO_PHASE_FLOW: - case FiniteElement::DEFORMATION_H2: // 07.2011. WW - case FiniteElement::AIR_FLOW: - case FiniteElement::PS_GLOBAL: - case FiniteElement::MULTI_COMPONENTIAL_FLOW: //AKS/NB - case FiniteElement::DEFORMATION_FLOW: //NW - case FiniteElement::TNEQ: //HS, TN - case FiniteElement::TES: //HS, TN - case FiniteElement::HEAT_TRANSPORT: //JOD 2014-11-10 - case FiniteElement::MASS_TRANSPORT: // JOD 2014-11-10 - cal_integration_point_value = true; - break; - default: - cal_integration_point_value = false; - return; + case FiniteElement::LIQUID_FLOW: + case FiniteElement::RICHARDS_FLOW: + case FiniteElement::MULTI_PHASE_FLOW: + case FiniteElement::GROUNDWATER_FLOW: + case FiniteElement::TWO_PHASE_FLOW: + case FiniteElement::DEFORMATION_H2: // 07.2011. WW + case FiniteElement::AIR_FLOW: + case FiniteElement::PS_GLOBAL: + case FiniteElement::MULTI_COMPONENTIAL_FLOW: // AKS/NB + case FiniteElement::DEFORMATION_FLOW: // NW + case FiniteElement::TNEQ: // HS, TN + case FiniteElement::TES: // HS, TN + case FiniteElement::HEAT_TRANSPORT: // JOD 2014-11-10 + case FiniteElement::MASS_TRANSPORT: // JOD 2014-11-10 + cal_integration_point_value = true; + break; + default: + cal_integration_point_value = false; + return; } std::cout << "->Calculate velocity" << '\n'; - //check linear flow or not + // check linear flow or not bool isLinearFlow = true; - for (size_t i=0; iflowlinearity_model > 1) { + for (size_t i = 0; i < mmp_vector.size(); i++) + { + if (mmp_vector[i]->flowlinearity_model > 1) + { isLinearFlow = false; break; } } - if (isLinearFlow) { - const size_t mesh_ele_vector_size(m_msh->ele_vector.size()); - for (size_t i = 0; i < mesh_ele_vector_size; i++) + if (isLinearFlow) { - elem = m_msh->ele_vector[i]; - if (elem->GetMark()) // Marked for use + const size_t mesh_ele_vector_size(m_msh->ele_vector.size()); + for (size_t i = 0; i < mesh_ele_vector_size; i++) { - if ((getProcessType() == FiniteElement::HEAT_TRANSPORT || getProcessType() == FiniteElement::MASS_TRANSPORT) && !elem->selected) - continue; // not selected for TOTAL_FLUX calculation JOD 2014-11-10 - fem->ConfigElement(elem, m_num->ele_gauss_points); - fem->Config(); //OK4709 - // fem->m_dom = NULL; // To be used for parallization - if(getProcessType() == FiniteElement::MULTI_COMPONENTIAL_FLOW) - fem->Cal_VelocityMCF(); - else - fem->Cal_Velocity(); - - //moved here from additional lower loop - if (getProcessType() == FiniteElement::TNEQ || getProcessType() == FiniteElement::TES) - { - fem->CalcSolidDensityRate(); // HS, thermal storage reactions - } - } - } - } else { //NW - const size_t mesh_ele_vector_size(m_msh->ele_vector.size()); - const size_t v_itr_max(this->m_num->local_picard1_max_iterations); - double pre_v[3] = {}; - double new_v[3] = {}; - //std::cout << " Start local Picard iteration: tolerance = " << this->m_num->local_picard1_tolerance << std::endl; - size_t i_itr = 0; - double vel_error = .0; - for (i_itr=0; i_itrele_vector[i]; - if (elem->GetMark()) // Marked for use - { - ElementValue* gp_ele = ele_gp_value[i]; - gp_ele->GetEleVelocity(pre_v); - - fem->ConfigElement(elem, m_num->ele_gauss_points); - fem->Config(); //OK4709 - // fem->m_dom = NULL; // To be used for parallization - - fem->Cal_Velocity(); - - gp_ele->GetEleVelocity(new_v); - vel_error = max(vel_error, fabs(new_v[0]-pre_v[0])); - vel_error = max(vel_error, fabs(new_v[1]-pre_v[1])); - vel_error = max(vel_error, fabs(new_v[2]-pre_v[2])); - } - } - //std::cout << " error (max. norm): " << vel_error << std::endl; - bool isConverged = (vel_error < this->m_num->local_picard1_tolerance); - if (isConverged) break; - } - std::cout << " Local Picard iteration: itr. count = " << i_itr << "/" << v_itr_max << ", error(max. norm)=" << vel_error << std::endl; - } + elem = m_msh->ele_vector[i]; + if (elem->GetMark()) // Marked for use + { + if ((getProcessType() == FiniteElement::HEAT_TRANSPORT + || getProcessType() == FiniteElement::MASS_TRANSPORT) + && !elem->selected) + continue; // not selected for TOTAL_FLUX calculation JOD 2014-11-10 + fem->ConfigElement(elem, m_num->ele_gauss_points); + fem->Config(); // OK4709 + // fem->m_dom = NULL; // To be used for parallization + if (getProcessType() == FiniteElement::MULTI_COMPONENTIAL_FLOW) + fem->Cal_VelocityMCF(); + else + fem->Cal_Velocity(); + + // moved here from additional lower loop + if (getProcessType() == FiniteElement::TNEQ || getProcessType() == FiniteElement::TES) + { + fem->CalcSolidDensityRate(); // HS, thermal storage reactions + } + } + } + } + else + { // NW + const size_t mesh_ele_vector_size(m_msh->ele_vector.size()); + const size_t v_itr_max(this->m_num->local_picard1_max_iterations); + double pre_v[3] = {}; + double new_v[3] = {}; + // std::cout << " Start local Picard iteration: tolerance = " << this->m_num->local_picard1_tolerance << + // std::endl; + size_t i_itr = 0; + double vel_error = .0; + for (i_itr = 0; i_itr < v_itr_max; ++i_itr) + { + // std::cout << " non-linear iteration: " << i_itr << "/" << v_itr_max << std::endl; + vel_error = .0; + for (size_t i = 0; i < mesh_ele_vector_size; i++) + { + elem = m_msh->ele_vector[i]; + if (elem->GetMark()) // Marked for use + { + ElementValue* gp_ele = ele_gp_value[i]; + gp_ele->GetEleVelocity(pre_v); - //if (getProcessType() == FiniteElement::TNEQ || getProcessType() == FiniteElement::TEQ) { - // const size_t mesh_ele_vector_size(m_msh->ele_vector.size()); - // for (size_t i = 0; i < mesh_ele_vector_size; i++) - // { - // elem = m_msh->ele_vector[i]; - // if (elem->GetMark()) // Marked for use - // { - // fem->ConfigElement(elem); - // fem->Config(); - // fem->CalcSolidDensityRate(); // HS, thermal storage reactions - // } - // } - //} + fem->ConfigElement(elem, m_num->ele_gauss_points); + fem->Config(); // OK4709 + // fem->m_dom = NULL; // To be used for parallization + fem->Cal_Velocity(); + + gp_ele->GetEleVelocity(new_v); + vel_error = max(vel_error, fabs(new_v[0] - pre_v[0])); + vel_error = max(vel_error, fabs(new_v[1] - pre_v[1])); + vel_error = max(vel_error, fabs(new_v[2] - pre_v[2])); + } + } + // std::cout << " error (max. norm): " << vel_error << std::endl; + bool isConverged = (vel_error < this->m_num->local_picard1_tolerance); + if (isConverged) + break; + } + std::cout << " Local Picard iteration: itr. count = " << i_itr << "/" << v_itr_max + << ", error(max. norm)=" << vel_error << std::endl; + } + + // if (getProcessType() == FiniteElement::TNEQ || getProcessType() == FiniteElement::TEQ) { + // const size_t mesh_ele_vector_size(m_msh->ele_vector.size()); + // for (size_t i = 0; i < mesh_ele_vector_size; i++) + // { + // elem = m_msh->ele_vector[i]; + // if (elem->GetMark()) // Marked for use + // { + // fem->ConfigElement(elem); + // fem->Config(); + // fem->CalcSolidDensityRate(); // HS, thermal storage reactions + // } + // } + //} // if (_pcs_type_name.find("TWO_PHASE_FLOW") != string::npos) //WW/CB - if (getProcessType() == FiniteElement::TWO_PHASE_FLOW || getProcessType() == FiniteElement::MASS_TRANSPORT - || getProcessType() == FiniteElement::HEAT_TRANSPORT) //WW/CB/JOD 2014-11-10 + if (getProcessType() == FiniteElement::TWO_PHASE_FLOW || getProcessType() == FiniteElement::MASS_TRANSPORT + || getProcessType() == FiniteElement::HEAT_TRANSPORT) // WW/CB/JOD 2014-11-10 cal_integration_point_value = false; } @@ -5944,42 +5906,44 @@ void CRFProcess::CalGPVelocitiesfromFluidMomentum() MeshLib::CElem* elem = NULL; int i_ind[3]; - cout << " CalGPVelocitiesfromFluidMomentum()" << "\n"; + cout << " CalGPVelocitiesfromFluidMomentum()" + << "\n"; // Get fluid_momentum process - CRFProcess* m_pcs_fm = PCSGet(FiniteElement::FLUID_MOMENTUM); + CRFProcess* m_pcs_fm = PCSGet(FiniteElement::FLUID_MOMENTUM); // check all possibilities for grid orientation (ccord_flag) int coordinateflag = this->m_msh->GetCoordinateFlag(); // get index of velocity i_ind[0] = m_pcs_fm->GetNodeValueIndex("VELOCITY1_X") + 1; - if(coordinateflag == 11) + if (coordinateflag == 11) // get index of velocity i_ind[0] = m_pcs_fm->GetNodeValueIndex("VELOCITY1_Y") + 1; - if(coordinateflag == 12) + if (coordinateflag == 12) // get index of velocity i_ind[0] = m_pcs_fm->GetNodeValueIndex("VELOCITY1_Z") + 1; // get index of velocity i_ind[1] = m_pcs_fm->GetNodeValueIndex("VELOCITY1_Y") + 1; - if(coordinateflag == 22) + if (coordinateflag == 22) // get index of velocity i_ind[1] = m_pcs_fm->GetNodeValueIndex("VELOCITY1_Z") + 1; // get index of velocity i_ind[2] = m_pcs_fm->GetNodeValueIndex("VELOCITY1_Z") + 1; - if((i_ind[0] < 0) || (i_ind[1] < 0) || (i_ind[2] < 0)) - cout << " Error - wrong index in Cal_GP_Velocity_FM " << "\n"; + if ((i_ind[0] < 0) || (i_ind[1] < 0) || (i_ind[2] < 0)) + cout << " Error - wrong index in Cal_GP_Velocity_FM " + << "\n"; // Loop over all elements for (i = 0; i < (long)m_msh->ele_vector.size(); i++) { elem = m_msh->ele_vector[i]; // get element - if (elem->GetMark()) // Marked for use + if (elem->GetMark()) // Marked for use { fem->ConfigElement(elem, m_num->ele_gauss_points); fem->Cal_GP_Velocity_FM(i_ind); } - } // end element loop + } // end element loop } /************************************************************************* @@ -5995,24 +5959,24 @@ void CRFProcess::AllocateLocalMatrixMemory() long i; //---------------------------------------------------------------------- int up_type = 0; - if(!M_Process) + if (!M_Process) up_type = 0; - if(H_Process && M_Process) + if (H_Process && M_Process) { - if(type != 4 && type != 41) + if (type != 4 && type != 41) up_type = 1; else { - if(type == 4) + if (type == 4) up_type = 3; - if(type == 41) + if (type == 41) up_type = 4; } } - if(!H_Process) + if (!H_Process) up_type = 2; - //SB for steady state element matrices in transport - if(MASS_TRANSPORT_Process || T_Process) + // SB for steady state element matrices in transport + if (MASS_TRANSPORT_Process || T_Process) up_type = 5; //---------------------------------------------------------------------- ElementMatrix* eleMatrix = NULL; @@ -6020,13 +5984,13 @@ void CRFProcess::AllocateLocalMatrixMemory() for (i = 0; i < (long)m_msh->ele_vector.size(); i++) { elem = m_msh->ele_vector[i]; -// CB THMBM - // CB removed if condition due to conflict with deactivated subdomains -// if (elem->GetMark()) { // Marked for use - eleMatrix = new ElementMatrix(); - eleMatrix->AllocateMemory(elem,up_type); - Ele_Matrices.push_back(eleMatrix); -// } + // CB THMBM + // CB removed if condition due to conflict with deactivated subdomains + // if (elem->GetMark()) { // Marked for use + eleMatrix = new ElementMatrix(); + eleMatrix->AllocateMemory(elem, up_type); + Ele_Matrices.push_back(eleMatrix); + // } } } @@ -6043,29 +6007,29 @@ void CRFProcess::AllocateLocalMatrixMemory() #if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW void CRFProcess::DDCAssembleGlobalMatrix() { - int ii,jj, dof; - long i,j,j0,ig,jg, ncol; + int ii, jj, dof; + long i, j, j0, ig, jg, ncol; CPARDomain* m_dom = NULL; - long* nodes2node = NULL; //WW - double* rhs = NULL, * rhs_dom = NULL; + long* nodes2node = NULL; // WW + double *rhs = NULL, *rhs_dom = NULL; double a_ij; double b_i = 0.0; - b_i = b_i; //OK411 + b_i = b_i; // OK411 long no_dom_nodes; - dof = pcs_number_of_primary_nvals; //WW - ncol = 0; //WW + dof = pcs_number_of_primary_nvals; // WW + ncol = 0; // WW #ifndef USE_MPI int no_domains = (int)dom_vector.size(); - for(int k = 0; k < no_domains; k++) + for (int k = 0; k < no_domains; k++) { m_dom = dom_vector[k]; #else - m_dom = dom_vector[myrank]; + m_dom = dom_vector[myrank]; #endif - // RHS +// RHS #if defined(NEW_EQS) rhs = eqs_new->b; - if(type == 4) + if (type == 4) rhs_dom = m_dom->eqsH->b; else rhs_dom = m_dom->eqs->b; @@ -6074,65 +6038,56 @@ void CRFProcess::DDCAssembleGlobalMatrix() rhs_dom = m_dom->eqs->b; #endif - no_dom_nodes = m_dom->nnodes_dom; //WW - if(type == 4 || type == 41) - no_dom_nodes = m_dom->nnodesHQ_dom; //WW - if(type == 41) + no_dom_nodes = m_dom->nnodes_dom; // WW + if (type == 4 || type == 41) + no_dom_nodes = m_dom->nnodesHQ_dom; // WW + if (type == 41) dof--; - for(i = 0; i < no_dom_nodes; i++) + for (i = 0; i < no_dom_nodes; i++) { //------------------------------------------ // Use the feature of sparse matrix of FEM - //WW + // WW ig = m_dom->nodes[i]; ncol = m_dom->num_nodes2_node[i]; - nodes2node = m_dom->node_conneted_nodes[i]; - for(j0 = 0; j0 < ncol; j0++) + nodes2node = m_dom->node_conneted_nodes[i]; + for (j0 = 0; j0 < ncol; j0++) { j = nodes2node[j0]; - if(j >= no_dom_nodes) + if (j >= no_dom_nodes) continue; jg = m_dom->nodes[j]; //------------------------------------------ // DOF loop ---------------------------WW - for(ii = 0; ii < dof; ii++) + for (ii = 0; ii < dof; ii++) { - for(jj = 0; jj < dof; jj++) + for (jj = 0; jj < dof; jj++) { - // get domain system matrix -#ifdef NEW_EQS //WW - if(type == 4) - a_ij = - (*m_dom->eqsH->A)(i + - no_dom_nodes * ii, - j + - no_dom_nodes * jj); +// get domain system matrix +#ifdef NEW_EQS // WW + if (type == 4) + a_ij = (*m_dom->eqsH->A)(i + no_dom_nodes * ii, j + no_dom_nodes * jj); else - a_ij = - (*m_dom->eqs->A)(i + no_dom_nodes * - ii,j + - no_dom_nodes * jj); - (*eqs_new->A)(ig + Shift[ii],jg + - Shift[jj]) += a_ij; + a_ij = (*m_dom->eqs->A)(i + no_dom_nodes * ii, j + no_dom_nodes * jj); + (*eqs_new->A)(ig + Shift[ii], jg + Shift[jj]) += a_ij; #else // ifdef NEW_EQS SetLinearSolver(m_dom->eqs); - a_ij = MXGet(i + no_dom_nodes * ii, - j + no_dom_nodes * jj); + a_ij = MXGet(i + no_dom_nodes * ii, j + no_dom_nodes * jj); // set global system matrix SetLinearSolver(eqs); - MXInc(ig + Shift[ii],jg + Shift[jj],a_ij); + MXInc(ig + Shift[ii], jg + Shift[jj], a_ij); #endif } } // DOF loop ---------------------------WW } // set global RHS vector //OK - for(ii = 0; ii < dof; ii++) //WW + for (ii = 0; ii < dof; ii++) // WW rhs[ig + Shift[ii]] += rhs_dom[i + no_dom_nodes * ii]; } // Mono HM------------------------------------WW - if(type != 41) + if (type != 41) #ifndef USE_MPI continue; #else @@ -6141,81 +6096,68 @@ void CRFProcess::DDCAssembleGlobalMatrix() no_dom_nodes = m_dom->nnodes_dom; long no_dom_nodesHQ = m_dom->nnodesHQ_dom; double a_ji = 0.0; - for(i = 0; i < no_dom_nodes; i++) + for (i = 0; i < no_dom_nodes; i++) { - ig = m_dom->nodes[i]; //WW + ig = m_dom->nodes[i]; // WW ncol = m_dom->num_nodes2_node[i]; - nodes2node = m_dom->node_conneted_nodes[i]; - for(j0 = 0; j0 < ncol; j0++) + nodes2node = m_dom->node_conneted_nodes[i]; + for (j0 = 0; j0 < ncol; j0++) { j = nodes2node[j0]; jg = m_dom->nodes[j]; - for(ii = 0; ii < dof; ii++) //ww + for (ii = 0; ii < dof; ii++) // ww { #if defined(NEW_EQS) // dom to global. WW - a_ij = - (*m_dom->eqsH->A)(i + no_dom_nodesHQ * dof,j + - no_dom_nodesHQ * ii); - a_ji = - (*m_dom->eqsH->A)(j + no_dom_nodesHQ * ii, i + - no_dom_nodesHQ * dof); - (*eqs_new->A)(ig + Shift[ii],jg + - Shift[problem_dimension_dm]) += a_ij; - (*eqs_new->A)(jg + Shift[problem_dimension_dm],ig + - Shift[ii]) += a_ji; + a_ij = (*m_dom->eqsH->A)(i + no_dom_nodesHQ * dof, j + no_dom_nodesHQ * ii); + a_ji = (*m_dom->eqsH->A)(j + no_dom_nodesHQ * ii, i + no_dom_nodesHQ * dof); + (*eqs_new->A)(ig + Shift[ii], jg + Shift[problem_dimension_dm]) += a_ij; + (*eqs_new->A)(jg + Shift[problem_dimension_dm], ig + Shift[ii]) += a_ji; #else // if defined(NEW_EQS) // get domain system matrix SetLinearSolver(m_dom->eqs); - a_ij = MXGet(i + no_dom_nodesHQ * dof, - j + no_dom_nodesHQ * ii); - a_ji = MXGet(j + no_dom_nodesHQ * ii, - i + no_dom_nodesHQ * dof); + a_ij = MXGet(i + no_dom_nodesHQ * dof, j + no_dom_nodesHQ * ii); + a_ji = MXGet(j + no_dom_nodesHQ * ii, i + no_dom_nodesHQ * dof); // set global system matrix SetLinearSolver(eqs); - MXInc(ig + Shift[ii],jg + Shift[problem_dimension_dm],a_ij); - MXInc(jg + Shift[problem_dimension_dm],ig + Shift[ii],a_ji); + MXInc(ig + Shift[ii], jg + Shift[problem_dimension_dm], a_ij); + MXInc(jg + Shift[problem_dimension_dm], ig + Shift[ii], a_ji); #endif } } } - for(i = 0; i < no_dom_nodes; i++) + for (i = 0; i < no_dom_nodes; i++) { ig = m_dom->nodes[i]; ncol = m_dom->num_nodes2_node[i]; - nodes2node = m_dom->node_conneted_nodes[i]; - for(j0 = 0; j0 < ncol; j0++) + nodes2node = m_dom->node_conneted_nodes[i]; + for (j0 = 0; j0 < ncol; j0++) { j = nodes2node[j0]; jg = m_dom->nodes[j]; - if(jg >= no_dom_nodes) + if (jg >= no_dom_nodes) continue; - // get domain system matrix +// get domain system matrix #if defined(NEW_EQS) // dom to global. WW - a_ij = - (*m_dom->eqsH->A)(i + no_dom_nodesHQ * dof,j + - no_dom_nodesHQ * dof); - (*eqs_new->A)(ig + Shift[problem_dimension_dm],jg + - Shift[problem_dimension_dm]) - += a_ij; + a_ij = (*m_dom->eqsH->A)(i + no_dom_nodesHQ * dof, j + no_dom_nodesHQ * dof); + (*eqs_new->A)(ig + Shift[problem_dimension_dm], jg + Shift[problem_dimension_dm]) += a_ij; #else SetLinearSolver(m_dom->eqs); - a_ij = MXGet(i + no_dom_nodesHQ * dof,j + no_dom_nodesHQ * dof); + a_ij = MXGet(i + no_dom_nodesHQ * dof, j + no_dom_nodesHQ * dof); // set global system matrix SetLinearSolver(eqs); - MXInc(ig + Shift[problem_dimension_dm],jg + - Shift[problem_dimension_dm],a_ij); + MXInc(ig + Shift[problem_dimension_dm], jg + Shift[problem_dimension_dm], a_ij); #endif } // rhs[ig + Shift[problem_dimension_dm]] += rhs_dom[i + no_dom_nodesHQ * dof]; } - // Mono HM------------------------------------WW +// Mono HM------------------------------------WW #ifndef USE_MPI } #endif - } +} #endif //#if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW /************************************************************************* @@ -6225,19 +6167,19 @@ void CRFProcess::DDCAssembleGlobalMatrix() ToDo: Prototyp function last modified: **************************************************************************/ - void CRFProcess::AssembleSystemMatrixNew(void) +void CRFProcess::AssembleSystemMatrixNew(void) +{ + switch (type) { - switch(type) - { case 1: - //MakeGS_ASM_NEW(eqs->b,eqs->x,ddummy); + // MakeGS_ASM_NEW(eqs->b,eqs->x,ddummy); // SMAssembleMatrix(eqs->b,eqs->x,ddummy,this); break; - case 2: //MTM2 + case 2: // MTM2 break; - case 3: //HTM + case 3: // HTM break; - case 5: // Gas flow + case 5: // Gas flow break; case 11: break; @@ -6245,26 +6187,25 @@ void CRFProcess::DDCAssembleGlobalMatrix() break; case 13: break; - case 14: - break; + case 14: + break; case 66: - //MakeGS_ASM_NEW(eqs->b,eqs->x,ddummy); + // MakeGS_ASM_NEW(eqs->b,eqs->x,ddummy); // SMAssembleMatrix(eqs->b,eqs->x,ddummy,this); break; default: - DisplayMsgLn( - "CalculateElementMatrices: no CalculateElementMatrices specified"); + DisplayMsgLn("CalculateElementMatrices: no CalculateElementMatrices specified"); abort(); - } + } #ifdef PARALLEL - DDCAssembleGlobalMatrix(); + DDCAssembleGlobalMatrix(); #else - IncorporateSourceTerms(); - IncorporateBoundaryConditions(); + IncorporateSourceTerms(); + IncorporateBoundaryConditions(); #endif - //SetLinearSolver(eqs); - //MXDumpGLS("global_matrix_dd.txt",1,eqs->b,eqs->x); - } + // SetLinearSolver(eqs); + // MXDumpGLS("global_matrix_dd.txt",1,eqs->b,eqs->x); +} /************************************************************************** FEMLib-Method: CRFProcess::IncorporateBoundaryConditions @@ -6273,53 +6214,53 @@ void CRFProcess::DDCAssembleGlobalMatrix() 05/2006 WW Implementation **************************************************************************/ #if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW - void CRFProcess::SetBoundaryConditionSubDomain() +void CRFProcess::SetBoundaryConditionSubDomain() +{ + int k; + long i, j; + CPARDomain* m_dom = NULL; + CBoundaryConditionNode* m_bc_nv = NULL; + CNodeValue* m_st_nv = NULL; + // + for (k = 0; k < (int)dom_vector.size(); k++) { - int k; - long i,j; - CPARDomain* m_dom = NULL; - CBoundaryConditionNode* m_bc_nv = NULL; - CNodeValue* m_st_nv = NULL; - // - for(k = 0; k < (int)dom_vector.size(); k++) + m_dom = dom_vector[k]; + // BC + for (i = 0; i < (long)bc_node_value.size(); i++) { - m_dom = dom_vector[k]; - // BC - for(i = 0; i < (long)bc_node_value.size(); i++) - { - m_bc_nv = bc_node_value[i]; - for(j = 0; j < (long)m_dom->nodes.size(); j++) - if(m_bc_nv->geo_node_number == m_dom->nodes[j]) - { - bc_node_value_in_dom.push_back(i); - bc_local_index_in_dom.push_back(j); - break; - } - } - rank_bc_node_value_in_dom.push_back((long)bc_node_value_in_dom.size()); - // ST - for(i = 0; i < (long)st_node_value.size(); i++) - { - m_st_nv = st_node_value[i]; - for(j = 0; j < (long)m_dom->nodes.size(); j++) - if(m_st_nv->geo_node_number == m_dom->nodes[j]) - { - st_node_value_in_dom.push_back(i); - st_local_index_in_dom.push_back(j); - break; - } - } - rank_st_node_value_in_dom.push_back((long)st_node_value_in_dom.size()); + m_bc_nv = bc_node_value[i]; + for (j = 0; j < (long)m_dom->nodes.size(); j++) + if (m_bc_nv->geo_node_number == m_dom->nodes[j]) + { + bc_node_value_in_dom.push_back(i); + bc_local_index_in_dom.push_back(j); + break; + } } - long Size = (long)st_node_value.size(); - long l_index; - for(i = 0; i < Size; i++) + rank_bc_node_value_in_dom.push_back((long)bc_node_value_in_dom.size()); + // ST + for (i = 0; i < (long)st_node_value.size(); i++) { - l_index = st_node_value[i]->geo_node_number; - if(node_connected_doms[l_index] > 0) - st_node_value[i]->node_value /= (double)node_connected_doms[l_index]; + m_st_nv = st_node_value[i]; + for (j = 0; j < (long)m_dom->nodes.size(); j++) + if (m_st_nv->geo_node_number == m_dom->nodes[j]) + { + st_node_value_in_dom.push_back(i); + st_local_index_in_dom.push_back(j); + break; + } } + rank_st_node_value_in_dom.push_back((long)st_node_value_in_dom.size()); + } + long Size = (long)st_node_value.size(); + long l_index; + for (i = 0; i < Size; i++) + { + l_index = st_node_value[i]->geo_node_number; + if (node_connected_doms[l_index] > 0) + st_node_value[i]->node_value /= (double)node_connected_doms[l_index]; } +} /************************************************************************** FEMLib-Method: CRFProcess::SetSTWaterGemSubDomain @@ -6328,50 +6269,50 @@ void CRFProcess::DDCAssembleGlobalMatrix() 05/2006 WW Implementation 03/2010 KG44 modified to GEM **************************************************************************/ - void CRFProcess::SetSTWaterGemSubDomain(int myrank) +void CRFProcess::SetSTWaterGemSubDomain(int myrank) +{ + int k; + long i, j; // WW, dsize=0; + CPARDomain* m_dom = NULL; + long int m_stgem_nv = -1; + // + long Size = (long)Water_ST_vec.size(); + long l_index = -1; + + // cout << "dom_vec_size: " << dom_vector.size() << "\n"; + // for ( k=0;k< ( int ) dom_vector.size();k++ ) + // { + k = myrank; // do it for each domain only once! + m_dom = dom_vector[k]; + // WW dsize=(long) m_dom->nodes.size(); + // ST + for (i = 0; i < Size; i++) { - int k; - long i,j; //WW, dsize=0; - CPARDomain* m_dom = NULL; - long int m_stgem_nv = -1; - // - long Size = ( long ) Water_ST_vec.size(); - long l_index = -1; + m_stgem_nv = Water_ST_vec[i].index_node; + for (j = 0; j < (long)m_dom->nodes.size(); j++) + if (m_stgem_nv == m_dom->nodes[j]) + { + // index for Water_ST_vec + stgem_node_value_in_dom.push_back(i); + // index for RHS + stgem_local_index_in_dom.push_back(j); + // cout << "dom " << k << " i, j " << i << " " << j << "\n"; + } + } + // only one element per domain! + rank_stgem_node_value_in_dom.push_back((long)stgem_node_value_in_dom.size()); + // cout << "dom " << k << " rank_stgem_node_value_in_dom " << (long) rank_stgem_node_value_in_dom[0] << "\n"; - // cout << "dom_vec_size: " << dom_vector.size() << "\n"; - // for ( k=0;k< ( int ) dom_vector.size();k++ ) - // { - k = myrank; //do it for each domain only once! - m_dom = dom_vector[k]; - //WW dsize=(long) m_dom->nodes.size(); - // ST - for ( i = 0; i < Size; i++ ) - { - m_stgem_nv = Water_ST_vec[i].index_node; - for ( j = 0; j < ( long ) m_dom->nodes.size(); j++ ) - if ( m_stgem_nv == m_dom->nodes[j] ) - { - //index for Water_ST_vec - stgem_node_value_in_dom.push_back ( i ); - //index for RHS - stgem_local_index_in_dom.push_back ( j ); - // cout << "dom " << k << " i, j " << i << " " << j << "\n"; - } - } - // only one element per domain! - rank_stgem_node_value_in_dom.push_back ( ( long ) stgem_node_value_in_dom.size() ); - // cout << "dom " << k << " rank_stgem_node_value_in_dom " << (long) rank_stgem_node_value_in_dom[0] << "\n"; - - // } + // } - for ( i = 0; i < Size; i++ ) - { - l_index = Water_ST_vec[i].index_node; - // cout << i << " " << node_connected_doms[l_index] << " " << "\n"; - //values for shared nodes are scaled - Water_ST_vec[i].water_st_value /= ( double ) node_connected_doms[l_index]; - } + for (i = 0; i < Size; i++) + { + l_index = Water_ST_vec[i].index_node; + // cout << i << " " << node_connected_doms[l_index] << " " << "\n"; + // values for shared nodes are scaled + Water_ST_vec[i].water_st_value /= (double)node_connected_doms[l_index]; } +} #endif //#if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW /************************************************************************** @@ -6389,554 +6330,532 @@ void CRFProcess::DDCAssembleGlobalMatrix() 10/2007 WW Changes for the new classes of sparse matrix and linear solver last modification: **************************************************************************/ - void CRFProcess::IncorporateBoundaryConditions(const int rank) - { - static long i; - static double bc_value, fac = 1.0, time_fac = 1.0; - long bc_msh_node = -1; +void CRFProcess::IncorporateBoundaryConditions(const int rank) +{ + static long i; + static double bc_value, fac = 1.0, time_fac = 1.0; + long bc_msh_node = -1; #ifndef USE_PETSC - long bc_eqs_index; -#endif - long shift; - int interp_method = 0; - int curve, valid = 0; - int ii, idx0 = -1; - CBoundaryConditionNode* m_bc_node; //WW - CBoundaryCondition* m_bc; //WW - CFunction* m_fct = NULL; //OK - bool is_valid = false; //OK + long bc_eqs_index; +#endif + long shift; + int interp_method = 0; + int curve, valid = 0; + int ii, idx0 = -1; + CBoundaryConditionNode* m_bc_node; // WW + CBoundaryCondition* m_bc; // WW + CFunction* m_fct = NULL; // OK + bool is_valid = false; // OK #ifndef USE_PETSC - bool onExBoundary = false; //WX + bool onExBoundary = false; // WX #endif - bool excavated = false; //WX - bool onDeactiveBoundary=true;//WX:09.2011 + bool excavated = false; // WX + bool onDeactiveBoundary = true; // WX:09.2011 #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - vector bc_eqs_id; - vector bc_eqs_value; + vector bc_eqs_id; + vector bc_eqs_value; #else #if !defined(NEW_EQS) - double* eqs_rhs = NULL; + double* eqs_rhs = NULL; #endif - CPARDomain* m_dom = NULL; + CPARDomain* m_dom = NULL; #endif - // +// #ifdef NEW_EQS - Linear_EQS* eqs_p = NULL; + Linear_EQS* eqs_p = NULL; #endif - //------------------------------------------------------------WW +//------------------------------------------------------------WW #ifdef JFNK_H2M - if(m_num->nls_method == 2 && BC_JFNK.size() > 0) //29.10.2010. WW - return; + if (m_num->nls_method == 2 && BC_JFNK.size() > 0) // 29.10.2010. WW + return; - /// For JFNK - bool bc_inre_flag = false; - double bc_init_value = 0.; + /// For JFNK + bool bc_inre_flag = false; + double bc_init_value = 0.; #endif - // WW - double Scaling = 1.0; - if(type == 4 || type / 10 == 4) - { - fac = Scaling; - } - long begin = 0; - long end = 0; - long gindex = 0; - if(rank == -1) - { - begin = 0; - end = (long)bc_node_value.size(); + // WW + double Scaling = 1.0; + if (type == 4 || type / 10 == 4) + { + fac = Scaling; + } + long begin = 0; + long end = 0; + long gindex = 0; + if (rank == -1) + { + begin = 0; + end = (long)bc_node_value.size(); #if !defined(USE_PETSC) // && !defined(other parallel libs)//03~04.3012. WW - //TODO -#ifdef NEW_EQS //WW - eqs_p = eqs_new; +// TODO +#ifdef NEW_EQS // WW + eqs_p = eqs_new; #else eqs_rhs = eqs->b; #endif #endif - } + } #if !defined(USE_PETSC) // && !defined(other parallel libs)//03~04.3012. WW - else - { - m_dom = dom_vector[rank]; + else + { + m_dom = dom_vector[rank]; #ifdef NEW_EQS - eqs_p = m_dom->eqs; - if(type == 4 ) //WW - { - eqs_p = m_dom->eqsH; - } + eqs_p = m_dom->eqs; + if (type == 4) // WW + { + eqs_p = m_dom->eqsH; + } #else eqs_rhs = m_dom->eqs->b; #endif - if(rank == 0) - begin = 0; - else - begin = rank_bc_node_value_in_dom[rank - 1]; - end = rank_bc_node_value_in_dom[rank]; - } -#endif //END: #if !defined(USE_PETSC) // && !defined(other parallel libs) + if (rank == 0) + begin = 0; + else + begin = rank_bc_node_value_in_dom[rank - 1]; + end = rank_bc_node_value_in_dom[rank]; + } +#endif // END: #if !defined(USE_PETSC) // && !defined(other parallel libs) - // update nod velocity before eval of constrained BC - if ( (this->hasConstrainedBC() || this->hasConstrainedST()) - && (this->getProcessType() == FiniteElement::RICHARDS_FLOW - || this->getProcessType() == FiniteElement::LIQUID_FLOW) ) - { - this->CalIntegrationPointValue(); - this->Extropolation_GaussValue(); - } + // update nod velocity before eval of constrained BC + if ((this->hasConstrainedBC() || this->hasConstrainedST()) + && (this->getProcessType() == FiniteElement::RICHARDS_FLOW + || this->getProcessType() == FiniteElement::LIQUID_FLOW)) + { + this->CalIntegrationPointValue(); + this->Extropolation_GaussValue(); + } - for(i = begin; i < end; i++) - { - gindex = i; + for (i = begin; i < end; i++) + { + gindex = i; #if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW - if(rank > -1) - gindex = bc_node_value_in_dom[i]; + if (rank > -1) + gindex = bc_node_value_in_dom[i]; #endif - m_bc_node = bc_node_value[gindex]; - m_bc = bc_node[gindex]; - // - //WX: check if bc is aktive, when Time_Controlled_Aktive for this bc is defined - if(m_bc->getTimeContrCurve() > 0) - if(GetCurveValue(m_bc->getTimeContrCurve(),0,aktuelle_zeit, - &valid) < MKleinsteZahl) - continue; + m_bc_node = bc_node_value[gindex]; + m_bc = bc_node[gindex]; + // + // WX: check if bc is aktive, when Time_Controlled_Aktive for this bc is defined + if (m_bc->getTimeContrCurve() > 0) + if (GetCurveValue(m_bc->getTimeContrCurve(), 0, aktuelle_zeit, &valid) < MKleinsteZahl) + continue; - //WX: 01.2011. for excavation bc, check if excavated and if on boundary - if(m_bc->getExcav() > 0) - { - CNode* node; - //unsigned int counter; //void warning + // WX: 01.2011. for excavation bc, check if excavated and if on boundary + if (m_bc->getExcav() > 0) + { + CNode* node; +// unsigned int counter; //void warning #ifndef USE_PETSC - onExBoundary = false; //WX:01.2011 + onExBoundary = false; // WX:01.2011 #endif - excavated = false; + excavated = false; - node = m_msh->nod_vector[m_bc_node->geo_node_number]; - double const* node_coordinate (node->getData()); //Coordinates(node_coordinate); + node = m_msh->nod_vector[m_bc_node->geo_node_number]; + double const* node_coordinate(node->getData()); // Coordinates(node_coordinate); - if((node_coordinate[ExcavDirection]>=ExcavBeginCoordinate&&(GetCurveValue(ExcavCurve,0,aktuelle_zeit,&valid) - +ExcavBeginCoordinate)>=node_coordinate[ExcavDirection]) - ||(node_coordinate[ExcavDirection]= ExcavBeginCoordinate + && (GetCurveValue(ExcavCurve, 0, aktuelle_zeit, &valid) + ExcavBeginCoordinate) + >= node_coordinate[ExcavDirection]) + || (node_coordinate[ExcavDirection] < ExcavBeginCoordinate + && (GetCurveValue(ExcavCurve, 0, aktuelle_zeit, &valid) + ExcavBeginCoordinate) + < node_coordinate[ExcavDirection])) + { + excavated = true; #ifndef USE_PETSC - for(unsigned int j=0; jgetConnectedElementIDs().size(); j++) + for (unsigned int j = 0; j < node->getConnectedElementIDs().size(); j++) + { + CElem* elem = m_msh->ele_vector[node->getConnectedElementIDs()[j]]; + double const* tmp_ele_coor(elem->GetGravityCenter()); + // if(elem->GetPatchIndex()!=ExcavMaterialGroup){ + // if(elem->GetExcavState()==-1) + if (elem->GetPatchIndex() != static_cast(ExcavMaterialGroup)) + // to be improved for more than 1 MG excavation { - CElem* elem = m_msh->ele_vector[node->getConnectedElementIDs()[j]]; - double const* tmp_ele_coor (elem->GetGravityCenter()); - //if(elem->GetPatchIndex()!=ExcavMaterialGroup){ - //if(elem->GetExcavState()==-1) - if(elem->GetPatchIndex() != static_cast(ExcavMaterialGroup)) - //to be improved for more than 1 MG excavation - { - onExBoundary = true; - break; - } - else if (tmp_ele_coor[ExcavDirection]-(GetCurveValue(ExcavCurve,0,aktuelle_zeit,&valid) - -ExcavBeginCoordinate)>-0.001) - { onExBoundary = true; - //tmp_counter1++; break; - } } -#endif + else if (tmp_ele_coor[ExcavDirection] + - (GetCurveValue(ExcavCurve, 0, aktuelle_zeit, &valid) - ExcavBeginCoordinate) + > -0.001) + { + onExBoundary = true; + // tmp_counter1++; + break; + } } +#endif } + } - if((m_bc->getExcav() > 0) && !excavated) //WX:01.2011. excav bc but is not excavated jet - continue; - if(m_bc->getGeoTypeAsString().compare("DOMAIN")==0)//WX + if ((m_bc->getExcav() > 0) && !excavated) // WX:01.2011. excav bc but is not excavated jet + continue; + if (m_bc->getGeoTypeAsString().compare("DOMAIN") == 0) // WX + { + CNode* node; + CElem* elem; + onDeactiveBoundary = false; + node = m_msh->nod_vector[m_bc_node->geo_node_number]; + for (size_t j = 0; j < node->getConnectedElementIDs().size(); j++) { - CNode * node; - CElem * elem; - onDeactiveBoundary = false; - node = m_msh->nod_vector[m_bc_node->geo_node_number]; - for(size_t j=0; jgetConnectedElementIDs().size(); j++) + elem = m_msh->ele_vector[node->getConnectedElementIDs()[j]]; + if (elem->GetMark()) { - elem = m_msh->ele_vector[node->getConnectedElementIDs()[j]]; - if(elem->GetMark()) - { - onDeactiveBoundary = true; - break; - } + onDeactiveBoundary = true; + break; } } - if(!onDeactiveBoundary) - continue; - // + } + if (!onDeactiveBoundary) + continue; +// #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - bc_msh_node = m_bc_node->geo_node_number; - // Check whether the node is in this subdomain - const long id_act_l_max = m_msh->getNumNodesLocal(); - const long id_h = static_cast( m_msh->GetNodesNumber(false) ); - const long id_act_h_max = static_cast( m_msh->getLargestActiveNodeID_Quadratic() ); - // If ghost node - if( !( (bc_msh_node < id_act_l_max) || - ( (bc_msh_node >= id_h) && (bc_msh_node < id_act_h_max) ) ) ) - continue; - - int dof_per_node = 0; - if (m_msh->NodesNumber_Linear == m_msh->NodesNumber_Quadratic) - { + bc_msh_node = m_bc_node->geo_node_number; + // Check whether the node is in this subdomain + const long id_act_l_max = m_msh->getNumNodesLocal(); + const long id_h = static_cast(m_msh->GetNodesNumber(false)); + const long id_act_h_max = static_cast(m_msh->getLargestActiveNodeID_Quadratic()); + // If ghost node + if (!((bc_msh_node < id_act_l_max) || ((bc_msh_node >= id_h) && (bc_msh_node < id_act_h_max)))) + continue; + + int dof_per_node = 0; + if (m_msh->NodesNumber_Linear == m_msh->NodesNumber_Quadratic) + { + dof_per_node = pcs_number_of_primary_nvals; + shift = m_bc_node->msh_node_number / m_msh->NodesNumber_Linear; + } + else + { + if (bc_msh_node < static_cast(m_msh->NodesNumber_Linear)) dof_per_node = pcs_number_of_primary_nvals; + else + dof_per_node = m_msh->GetCoordinateFlag() / 10; + if (type == 4 || type / 10 == 4) + { + shift = m_bc_node->msh_node_number / m_msh->NodesNumber_Quadratic; + } + else + { shift = m_bc_node->msh_node_number / m_msh->NodesNumber_Linear; } + } +#else + shift = m_bc_node->msh_node_number - m_bc_node->geo_node_number; + if (rank > -1) + { + bc_msh_node = bc_local_index_in_dom[i]; + int dim_space = 0; + if (shift == 0) + // 15.4.2008 WW if(m_msh->NodesNumber_Linear==m_msh->NodesNumber_Quadratic) + dim_space = 0; else { - if(bc_msh_node < static_cast(m_msh->NodesNumber_Linear)) - dof_per_node = pcs_number_of_primary_nvals; + // 02.2010. WW + if (type == 4 || type / 10 == 4) + dim_space = shift / m_msh->NodesNumber_Quadratic; else - dof_per_node = m_msh->GetCoordinateFlag() / 10; - if(type == 4 || type / 10 == 4) - { - shift = m_bc_node->msh_node_number / m_msh->NodesNumber_Quadratic; - } - else - { - shift = m_bc_node->msh_node_number / m_msh->NodesNumber_Linear; - } + dim_space = shift / m_msh->NodesNumber_Linear; } -#else - shift = m_bc_node->msh_node_number - m_bc_node->geo_node_number; - if(rank > -1) + shift = m_dom->shift[dim_space]; + } + else + bc_msh_node = m_bc_node->geo_node_number; +#endif // END: if defined(USE_PETSC) // || defined(other parallel libs + //------------------------------------------------------------WW + if (m_msh) // OK + // if(!m_msh->nod_vector[bc_msh_node]->GetMark()) //WW + // continue; + time_fac = 1.0; + if (bc_msh_node >= 0) + { + //................................................................ + // Time dependencies - CURVE + curve = m_bc_node->CurveIndex; + if (curve > 0) { - bc_msh_node = bc_local_index_in_dom[i]; - int dim_space = 0; - if(shift == 0) - // 15.4.2008 WW if(m_msh->NodesNumber_Linear==m_msh->NodesNumber_Quadratic) - dim_space = 0; + if (curve > 10000000) /// 16.08.2010. WW + time_fac = GetCurveValue(curve - 10000000, interp_method, aktuelle_zeit, &valid); else - { - // 02.2010. WW - if(type == 4 || type / 10 == 4) - dim_space = shift / m_msh->NodesNumber_Quadratic; - else - dim_space = shift / m_msh->NodesNumber_Linear; - } - shift = m_dom->shift[dim_space]; + time_fac = GetCurveValue(curve, interp_method, aktuelle_zeit, &valid); + if (!valid) + continue; } else - bc_msh_node = m_bc_node->geo_node_number; -#endif// END: if defined(USE_PETSC) // || defined(other parallel libs - //------------------------------------------------------------WW - if(m_msh) //OK - // if(!m_msh->nod_vector[bc_msh_node]->GetMark()) //WW - // continue; time_fac = 1.0; - if(bc_msh_node >= 0) - { - //................................................................ - // Time dependencies - CURVE - curve = m_bc_node->CurveIndex; - if(curve > 0) - { - if(curve > 10000000) /// 16.08.2010. WW - time_fac = GetCurveValue(curve - 10000000, - interp_method, - aktuelle_zeit, - &valid); - else - time_fac = GetCurveValue(curve, - interp_method, - aktuelle_zeit, - &valid); - if(!valid) - continue; - } + //................................................................ + // Time dependencies - FCT + if (m_bc_node->fct_name.length() > 0) + { + m_fct = FCTGet(m_bc_node->fct_name); + if (m_fct) + time_fac = m_fct->GetValue(aktuelle_zeit, &is_valid); + // if(!valid) continue; else - time_fac = 1.0; - //................................................................ - // Time dependencies - FCT - if(m_bc_node->fct_name.length() > 0) - { - m_fct = FCTGet(m_bc_node->fct_name); - if(m_fct) - time_fac = m_fct->GetValue(aktuelle_zeit,&is_valid); - //if(!valid) continue; - else - cout << - "Warning in CRFProcess::IncorporateBoundaryConditions - no FCT data" - << "\n"; - } - //................................................................ - // copy values SB 09.2012 - if(m_bc_node->bc_node_copy_geom.length() > 0) - { - size_t geo_node_id; - //std::string geo_file_name = (std::string)this->m_msh->_geo_name; - GEOLIB::GEOObjects * geo_obj; - geo_obj = this->m_msh->getGEOObjects(); - // Get geometry node - const std::vector* pnt_vec(geo_obj->getPointVec(* this->m_msh->getProjectName())); - //const GEOLIB::PointVec* pnt_vec(geo_obj->getPointVecObj(m_bc_node->bc_node_copy_geom)); - //const GEOLIB::Point* pnt(pnt_vec->getElementIDByName(m_bc_node->bc_node_copy_geom, msh_node_id)); - if (!((geo_obj->getPointVecObj(* this->m_msh->getProjectName()))->getElementIDByName(m_bc_node->bc_node_copy_geom_name, geo_node_id))) - { cout << " Error !" << "\n";} - // get node Index of geometry node - only POINT so far - long msh_node_id = m_msh->GetNODOnPNT((*pnt_vec)[geo_node_id]); - // get value from last time step - std::string help; - help = m_bc_node->pcs_pv_name; - if(this->pcs_type_name_vector[0] == "MASS_TRANSPORT") - help = this->pcs_primary_function_name[0]; - int ind = this->GetNodeValueIndex(help) + 1; // new time level - time_fac = this->GetNodeValue(msh_node_id, ind); - std::cout << " Copy value " << time_fac << " from " << m_bc_node->bc_node_copy_geom << " " << m_bc_node->bc_node_copy_geom_name << " to POLYLINE " << "\n"; - - } - //................................................................ - // Conditions - if(m_bc_node->conditional) + cout << "Warning in CRFProcess::IncorporateBoundaryConditions - no FCT data" + << "\n"; + } + //................................................................ + // copy values SB 09.2012 + if (m_bc_node->bc_node_copy_geom.length() > 0) + { + size_t geo_node_id; + // std::string geo_file_name = (std::string)this->m_msh->_geo_name; + GEOLIB::GEOObjects* geo_obj; + geo_obj = this->m_msh->getGEOObjects(); + // Get geometry node + const std::vector* pnt_vec(geo_obj->getPointVec(*this->m_msh->getProjectName())); + // const GEOLIB::PointVec* pnt_vec(geo_obj->getPointVecObj(m_bc_node->bc_node_copy_geom)); + // const GEOLIB::Point* pnt(pnt_vec->getElementIDByName(m_bc_node->bc_node_copy_geom, msh_node_id)); + if (!((geo_obj->getPointVecObj(*this->m_msh->getProjectName())) + ->getElementIDByName(m_bc_node->bc_node_copy_geom_name, geo_node_id))) { - int idx_1 = -1; //28.2.2007 WW - for(ii = 0; ii < dof; ii++) //28.2.2007 WW - - if (convertPrimaryVariableToString(m_bc-> - getProcessPrimaryVariable()) - .find( - pcs_primary_function_name[ii]) != - string::npos) - { - idx_1 = GetNodeValueIndex( - pcs_primary_function_name[ii]) + 1; - break; - } - bc_value = time_fac * fac * GetNodeValue( - m_bc_node->msh_node_number_subst, - idx_1); + cout << " Error !" + << "\n"; } - else - { - if (m_bc->getPressureAsHeadModel() == -1) //this is the default case - { - // time_fac*fac*PCSGetNODValue(bc_msh_node,"PRESSURE1",0); - bc_value = time_fac * fac * m_bc_node->node_value; - } - else //this is the PressureAsHead case + // get node Index of geometry node - only POINT so far + long msh_node_id = m_msh->GetNODOnPNT((*pnt_vec)[geo_node_id]); + // get value from last time step + std::string help; + help = m_bc_node->pcs_pv_name; + if (this->pcs_type_name_vector[0] == "MASS_TRANSPORT") + help = this->pcs_primary_function_name[0]; + int ind = this->GetNodeValueIndex(help) + 1; // new time level + time_fac = this->GetNodeValue(msh_node_id, ind); + std::cout << " Copy value " << time_fac << " from " << m_bc_node->bc_node_copy_geom << " " + << m_bc_node->bc_node_copy_geom_name << " to POLYLINE " + << "\n"; + } + //................................................................ + // Conditions + if (m_bc_node->conditional) + { + int idx_1 = -1; // 28.2.2007 WW + for (ii = 0; ii < dof; ii++) // 28.2.2007 WW + + if (convertPrimaryVariableToString(m_bc->getProcessPrimaryVariable()) + .find(pcs_primary_function_name[ii]) + != string::npos) { - bc_value = calcPressureFromHead(*m_bc, m_bc_node->msh_node_number, m_bc_node->node_value, time_fac, fac); + idx_1 = GetNodeValueIndex(pcs_primary_function_name[ii]) + 1; + break; } + bc_value = time_fac * fac * GetNodeValue(m_bc_node->msh_node_number_subst, idx_1); + } + else + { + if (m_bc->getPressureAsHeadModel() == -1) // this is the default case + { + // time_fac*fac*PCSGetNODValue(bc_msh_node,"PRESSURE1",0); + bc_value = time_fac * fac * m_bc_node->node_value; } - if(m_bc->isSwitchBC()) + else // this is the PressureAsHead case { - bc_value = evaluteSwitchBC(*m_bc, *m_bc_node, time_fac, fac); + bc_value + = calcPressureFromHead(*m_bc, m_bc_node->msh_node_number, m_bc_node->node_value, time_fac, fac); } - //---------------------------------------------------------------- - // MSH - /// 16.08.2010. WW - if(curve > 10000000 && fabs(time_fac) > DBL_EPSILON) - bc_value = bc_value / time_fac + time_fac; /// bc_value +time_fac; + } + if (m_bc->isSwitchBC()) + { + bc_value = evaluteSwitchBC(*m_bc, *m_bc_node, time_fac, fac); + } + //---------------------------------------------------------------- + // MSH + /// 16.08.2010. WW + if (curve > 10000000 && fabs(time_fac) > DBL_EPSILON) + bc_value = bc_value / time_fac + time_fac; /// bc_value +time_fac; - if(m_bc->isPeriodic()) // JOD - bc_value *= sin( - 2 * 3.14159 * aktuelle_zeit / - m_bc->getPeriodeTimeLength() + - m_bc->getPeriodePhaseShift()); + if (m_bc->isPeriodic()) // JOD + bc_value + *= sin(2 * 3.14159 * aktuelle_zeit / m_bc->getPeriodeTimeLength() + m_bc->getPeriodePhaseShift()); - //---------------------------------------------------------------- +//---------------------------------------------------------------- #ifndef USE_PETSC - if(rank > -1) - bc_eqs_index = bc_msh_node; - else - //WW# - bc_eqs_index = - m_msh->nod_vector[bc_msh_node]->GetEquationIndex(); -#endif - //.............................................................. - // NEWTON WW //Modified for JFNK. 09.2010. WW - if(m_num->nls_method >= 1 // 04.08.2010. WW _name.find("NEWTON")!=string::npos - || type == 4 || type / 10 == 4 ) - { //Solution is in the manner of increment ! - idx0 = - GetNodeValueIndex(convertPrimaryVariableToString( - m_bc-> - getProcessPrimaryVariable())); - if(m_bc_node->pcs_pv_name.find("DISPLACEMENT") != - string::npos) - { - bc_value -= GetNodeValue( - m_bc_node->geo_node_number, - idx0) - + GetNodeValue( - m_bc_node->geo_node_number, - idx0 + 1); - /// if JFNK and if the first Newton step - /// In the successive Newton steps, node BC value taken from the previous Newton step. - if(m_num->nls_method == 2 && ite_steps == 1) - SetNodeValue(m_bc_node->geo_node_number, - idx0, - bc_value); - if (m_bc->getNoDispIncre()>0)//WX - bc_value = 0; + if (rank > -1) + bc_eqs_index = bc_msh_node; + else + // WW# + bc_eqs_index = m_msh->nod_vector[bc_msh_node]->GetEquationIndex(); +#endif + //.............................................................. + // NEWTON WW //Modified for JFNK. 09.2010. WW + if (m_num->nls_method >= 1 // 04.08.2010. WW _name.find("NEWTON")!=string::npos + || type == 4 + || type / 10 == 4) + { // Solution is in the manner of increment ! + idx0 = GetNodeValueIndex(convertPrimaryVariableToString(m_bc->getProcessPrimaryVariable())); + if (m_bc_node->pcs_pv_name.find("DISPLACEMENT") != string::npos) + { + bc_value -= GetNodeValue(m_bc_node->geo_node_number, idx0) + + GetNodeValue(m_bc_node->geo_node_number, idx0 + 1); + /// if JFNK and if the first Newton step + /// In the successive Newton steps, node BC value taken from the previous Newton step. + if (m_num->nls_method == 2 && ite_steps == 1) + SetNodeValue(m_bc_node->geo_node_number, idx0, bc_value); + if (m_bc->getNoDispIncre() > 0) // WX + bc_value = 0; #ifdef JFNK_H2M - bc_inre_flag = false; - bc_init_value = 0.; + bc_inre_flag = false; + bc_init_value = 0.; #endif - } - else - { + } + else + { #ifdef JFNK_H2M - bc_inre_flag = true; - bc_init_value = bc_value; -#endif - /// if JFNK and if the first Newton step. 11.11.2010. WW - //if(m_num->nls_method==2&&ite_steps==1) /// JFNK - /// p_{n+1} = p_b, - // SetNodeValue(m_bc_node->geo_node_number, idx0++, bc_value); - /// dp = u_b-u_n - bc_value -= GetNodeValue( - m_bc_node->geo_node_number, - ++idx0); - // SetNodeValue(m_bc_node->geo_node_number, idx0, bc_value); - //SetNodeValue(m_bc_node->geo_node_number, idx0+1, bc_value); - //bc_value = 0.; - } + bc_inre_flag = true; + bc_init_value = bc_value; +#endif + /// if JFNK and if the first Newton step. 11.11.2010. WW + // if(m_num->nls_method==2&&ite_steps==1) /// JFNK + /// p_{n+1} = p_b, + // SetNodeValue(m_bc_node->geo_node_number, idx0++, bc_value); + /// dp = u_b-u_n + bc_value -= GetNodeValue(m_bc_node->geo_node_number, ++idx0); + // SetNodeValue(m_bc_node->geo_node_number, idx0, bc_value); + // SetNodeValue(m_bc_node->geo_node_number, idx0+1, bc_value); + // bc_value = 0.; } + } #if !defined(USE_PETSC) // && !defined(other parallel solver). //WW 04.2012. WW - bc_eqs_index += shift; + bc_eqs_index += shift; #endif #ifdef JFNK_H2M - /// If JFNK method (09.2010. WW): - if(m_num->nls_method == 2) - { - bc_JFNK new_bc_entry; - new_bc_entry.var_idx = idx0 + 1; - new_bc_entry.bc_node = m_bc_node->geo_node_number; - new_bc_entry.bc_eqs_idx = bc_eqs_index; - new_bc_entry.bc_value = bc_value; - - new_bc_entry.incremental = bc_inre_flag; - new_bc_entry.bc_value0 = bc_init_value; - BC_JFNK.push_back(new_bc_entry); - } - else - { + /// If JFNK method (09.2010. WW): + if (m_num->nls_method == 2) + { + bc_JFNK new_bc_entry; + new_bc_entry.var_idx = idx0 + 1; + new_bc_entry.bc_node = m_bc_node->geo_node_number; + new_bc_entry.bc_eqs_idx = bc_eqs_index; + new_bc_entry.bc_value = bc_value; + + new_bc_entry.incremental = bc_inre_flag; + new_bc_entry.bc_value0 = bc_init_value; + BC_JFNK.push_back(new_bc_entry); + } + else + { #endif - //---------------------------------------------------------------- - //---------------------------------------------------------------- - /* // Make the follows as comment by WW. 04.03.2008 - //YD dual - if(dof>1) //WW - { - for(ii=0;iipcs_pv_name.find(pcs_primary_function_name[ii]) != string::npos) - { - //YD/WW - //WW bc_eqs_index += ii*(long)eqs->dim/dof; //YD dual //DOF>1 WW - bc_eqs_index += fem->NodeShift[ii]; //DOF>1 WW - - break; - } - } - } - */ +//---------------------------------------------------------------- +//---------------------------------------------------------------- +/* // Make the follows as comment by WW. 04.03.2008 + //YD dual + if(dof>1) //WW + { + for(ii=0;iipcs_pv_name.find(pcs_primary_function_name[ii]) != string::npos) + { + //YD/WW + //WW bc_eqs_index += ii*(long)eqs->dim/dof; //YD dual //DOF>1 WW + bc_eqs_index += fem->NodeShift[ii]; //DOF>1 WW + + break; + } + } + } + */ #if !defined(USE_PETSC) // && !defined(other parallel libs)//04.3013. WW - if(m_bc->getExcav()>0) + if (m_bc->getExcav() > 0) { - if(excavated&&!onExBoundary) + if (excavated && !onExBoundary) { #ifdef NEW_EQS - eqs_p->SetKnownX_i(bc_eqs_index, bc_value); //WX:12.2012 + eqs_p->SetKnownX_i(bc_eqs_index, bc_value); // WX:12.2012 #else - MXRandbed(bc_eqs_index,bc_value,eqs_rhs); + MXRandbed(bc_eqs_index, bc_value, eqs_rhs); #endif - continue;//WX:09.2011 + continue; // WX:09.2011 } - else if (m_bc_node->pcs_pv_name.find("DISPLACEMENT")!=string::npos) - continue;// + else if (m_bc_node->pcs_pv_name.find("DISPLACEMENT") != string::npos) + continue; // } -#endif //end defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - +#endif // end defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - //save last bc_value for later usage (in constrained BC) + // save last bc_value for later usage (in constrained BC) m_bc_node->node_value_pre_calc = bc_value; - if(m_bc->isConstrainedBC()) + if (m_bc->isConstrainedBC()) { if (checkConstrainedBC(*m_bc, *m_bc_node, bc_value)) continue; } - ////////////////////////////////// +////////////////////////////////// #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - bc_eqs_id.push_back(static_cast( m_msh->nod_vector[bc_msh_node]->GetEquationIndex() - * dof_per_node + shift)); - bc_eqs_value.push_back(bc_value); + bc_eqs_id.push_back( + static_cast(m_msh->nod_vector[bc_msh_node]->GetEquationIndex() * dof_per_node + shift)); + bc_eqs_value.push_back(bc_value); -#elif defined(NEW_EQS) //WW - eqs_p->SetKnownX_i(bc_eqs_index, bc_value); +#elif defined(NEW_EQS) // WW + eqs_p->SetKnownX_i(bc_eqs_index, bc_value); #else - MXRandbed(bc_eqs_index,bc_value,eqs_rhs); + MXRandbed(bc_eqs_index, bc_value, eqs_rhs); #endif #ifdef JFNK_H2M } #endif - } } + } #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - int nbc = static_cast(bc_eqs_id.size()); - if(nbc>0) - { - eqs_new->setArrayValues(0, nbc, &bc_eqs_id[0], &bc_eqs_value[0], INSERT_VALUES); - eqs_new->setArrayValues(1, nbc, &bc_eqs_id[0], &bc_eqs_value[0], INSERT_VALUES); - } + int nbc = static_cast(bc_eqs_id.size()); + if (nbc > 0) + { + eqs_new->setArrayValues(0, nbc, &bc_eqs_id[0], &bc_eqs_value[0], INSERT_VALUES); + eqs_new->setArrayValues(1, nbc, &bc_eqs_id[0], &bc_eqs_value[0], INSERT_VALUES); + } #ifdef petsc_zero_row_test - //We have do the following collection because MatZeroR must be called by all processes - const int mpi_size = eqs_new->getMPI_Size(); - vector r_cnt(mpi_size); - vector r_disp(mpi_size); - vector r_vec(mpi_size); - int k; - for(k=0; kgetMPI_Rank()]; - for(k=0; kzeroRows_in_Matrix(v_disp, &r_vec[0]); -#endif // petsc_zero_row_test - eqs_new->AssembleUnkowns_PETSc(); - eqs_new->AssembleRHS_PETSc(); - + // We have do the following collection because MatZeroR must be called by all processes + const int mpi_size = eqs_new->getMPI_Size(); + vector r_cnt(mpi_size); + vector r_disp(mpi_size); + vector r_vec(mpi_size); + int k; + for (k = 0; k < mpi_size; k++) + { + r_cnt[k] = 1; + r_disp[k] = k; + } + // Get nbc + MPI_Allgatherv(&nbc, 1, MPI_INT, &r_vec[0], &r_cnt[0], &r_disp[0], MPI_INT, PETSC_COMM_WORLD); + int v_disp = 0; + for (k = 0; k < mpi_size; k++) + { + r_disp[k] = v_disp; + v_disp += r_vec[k]; + } + r_cnt.resize(v_disp); + r_vec.resize(v_disp); + for (k = 0; k < v_disp; k++) + { + r_cnt[k] = 0; + } + const int v_shift = r_disp[eqs_new->getMPI_Rank()]; + for (k = 0; k < nbc; k++) + { + r_cnt[v_shift + k] = bc_eqs_id[k]; + } + MPI_Allreduce(&r_cnt[0], &r_vec[0], v_disp, MPI_INT, MPI_SUM, PETSC_COMM_WORLD); - //TEST - //PetscViewer viewer; - //eqs_new->EQSV_Viewer(FileName, viewer); + MPI_Barrier(MPI_COMM_WORLD); + eqs_new->zeroRows_in_Matrix(v_disp, &r_vec[0]); +#endif // petsc_zero_row_test + eqs_new->AssembleUnkowns_PETSc(); + eqs_new->AssembleRHS_PETSc(); + // TEST + // PetscViewer viewer; + // eqs_new->EQSV_Viewer(FileName, viewer); - eqs_new->zeroRows_in_Matrix(nbc, &bc_eqs_id[0]); - eqs_new->AssembleMatrixPETSc(); + eqs_new->zeroRows_in_Matrix(nbc, &bc_eqs_id[0]); + eqs_new->AssembleMatrixPETSc(); #endif - } +} /************************************************************************** FEMLib-Method: CRFProcess::IncorporateBoundaryConditions @@ -6945,519 +6864,469 @@ void CRFProcess::DDCAssembleGlobalMatrix() 01/2007 PCH Implementation last modification: **************************************************************************/ - void CRFProcess::IncorporateBoundaryConditions(const int rank, const int axis) - { - static long i; - static double bc_value, fac = 1.0, time_fac = 1.0; - long bc_msh_node; - long bc_eqs_index, shift; - int interp_method = 0; - int curve, valid = 0; - int idx0, idx1; - CBoundaryConditionNode* m_bc_node; //WW - CBoundaryCondition* m_bc; //WW +void CRFProcess::IncorporateBoundaryConditions(const int rank, const int axis) +{ + static long i; + static double bc_value, fac = 1.0, time_fac = 1.0; + long bc_msh_node; + long bc_eqs_index, shift; + int interp_method = 0; + int curve, valid = 0; + int idx0, idx1; + CBoundaryConditionNode* m_bc_node; // WW + CBoundaryCondition* m_bc; // WW #if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW - CPARDomain* m_dom = NULL; + CPARDomain* m_dom = NULL; #endif - CFunction* m_fct = NULL; //OK - bool is_valid = false; //OK + CFunction* m_fct = NULL; // OK + bool is_valid = false; // OK #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - vector bc_eqs_id; - vector bc_eqs_value; + vector bc_eqs_id; + vector bc_eqs_value; #elif !defined(NEW_EQS) - double* eqs_rhs = NULL; + double* eqs_rhs = NULL; #endif #ifdef NEW_EQS - Linear_EQS* eqs_p = NULL; + Linear_EQS* eqs_p = NULL; #endif - //------------------------------------------------------------WW - // WW - double Scaling = 1.0; - if(type == 4 || type == 41) - fac = Scaling; + //------------------------------------------------------------WW + // WW + double Scaling = 1.0; + if (type == 4 || type == 41) + fac = Scaling; - long begin = 0; - long end = 0; - long gindex = 0; + long begin = 0; + long end = 0; + long gindex = 0; - //WW CBoundaryConditionsGroup *m_bc_group = NULL; - // m_bc_group = BCGetGroup(this->_pcs_type_name,this->pcs_primary_function_name[axis]); - // TF - //WW m_bc_group = BCGetGroup(convertProcessTypeToString(this->getProcessType()),this->pcs_primary_function_name[axis]); + // WW CBoundaryConditionsGroup *m_bc_group = NULL; + // m_bc_group = BCGetGroup(this->_pcs_type_name,this->pcs_primary_function_name[axis]); + // TF + // WW m_bc_group = + // BCGetGroup(convertProcessTypeToString(this->getProcessType()),this->pcs_primary_function_name[axis]); - if(rank == -1) - { - begin = 0; - end = (long)bc_node_value.size(); + if (rank == -1) + { + begin = 0; + end = (long)bc_node_value.size(); #if !defined(USE_PETSC) // && !defined(other parallel libs)//03~04.3012. WW -#ifdef NEW_EQS //WW - eqs_p = eqs_new; +#ifdef NEW_EQS // WW + eqs_p = eqs_new; #else eqs_rhs = eqs->b; #endif #endif - } + } #if !defined(USE_PETSC) // && !defined(other parallel libs)//03~04.3012. WW - else - { - m_dom = dom_vector[rank]; + else + { + m_dom = dom_vector[rank]; #ifdef NEW_EQS - eqs_p = m_dom->eqs; - if(type == 4 ) //WW - { - eqs_p = m_dom->eqsH; - } + eqs_p = m_dom->eqs; + if (type == 4) // WW + { + eqs_p = m_dom->eqsH; + } #else eqs_rhs = m_dom->eqs->b; #endif - if(rank == 0) - begin = 0; - else - begin = rank_bc_node_value_in_dom[rank - 1]; - end = rank_bc_node_value_in_dom[rank]; - } -#endif //END: !defined(USE_PETSC) // && !defined(other parallel libs)/ - for(i = begin; i < end; i++) - { - gindex = i; + if (rank == 0) + begin = 0; + else + begin = rank_bc_node_value_in_dom[rank - 1]; + end = rank_bc_node_value_in_dom[rank]; + } +#endif // END: !defined(USE_PETSC) // && !defined(other parallel libs)/ + for (i = begin; i < end; i++) + { + gindex = i; #if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW - if(rank > -1) - gindex = bc_node_value_in_dom[i]; + if (rank > -1) + gindex = bc_node_value_in_dom[i]; #endif - m_bc_node = bc_node_value[gindex]; + m_bc_node = bc_node_value[gindex]; - // PCH - if(axis == 0 && m_bc_node->pcs_pv_name.find("VELOCITY1_X") != string::npos) - { - m_bc = bc_node[gindex]; + // PCH + if (axis == 0 && m_bc_node->pcs_pv_name.find("VELOCITY1_X") != string::npos) + { + m_bc = bc_node[gindex]; #if defined(USE_PETSC) // ||defined(other parallel libs)//03~04.3012. WW - bc_msh_node = m_bc_node->geo_node_number; + bc_msh_node = m_bc_node->geo_node_number; #else - shift = m_bc_node->msh_node_number - m_bc_node->geo_node_number; - // - if(rank > -1) - { - bc_msh_node = bc_local_index_in_dom[i]; - int dim_space = 0; - if(m_msh->NodesNumber_Linear == - m_msh->NodesNumber_Quadratic) - dim_space = 0; - else - { - if(shift % m_msh->NodesNumber_Quadratic == 0) - dim_space = shift / - m_msh->NodesNumber_Quadratic; - else - dim_space = m_msh->msh_max_dim; - } - shift = m_dom->shift[dim_space]; - } + shift = m_bc_node->msh_node_number - m_bc_node->geo_node_number; + // + if (rank > -1) + { + bc_msh_node = bc_local_index_in_dom[i]; + int dim_space = 0; + if (m_msh->NodesNumber_Linear == m_msh->NodesNumber_Quadratic) + dim_space = 0; else - bc_msh_node = m_bc_node->geo_node_number; + { + if (shift % m_msh->NodesNumber_Quadratic == 0) + dim_space = shift / m_msh->NodesNumber_Quadratic; + else + dim_space = m_msh->msh_max_dim; + } + shift = m_dom->shift[dim_space]; + } + else + bc_msh_node = m_bc_node->geo_node_number; #endif - //------------------------------------------------------------WW - if(m_msh) //OK - // if(!m_msh->nod_vector[bc_msh_node]->GetMark()) //WW - // continue; + //------------------------------------------------------------WW + if (m_msh) // OK + // if(!m_msh->nod_vector[bc_msh_node]->GetMark()) //WW + // continue; + time_fac = 1.0; + if (bc_msh_node >= 0) + { + //................................................................ + // Time dependencies - CURVE + curve = m_bc_node->CurveIndex; + if (curve > 0) + { + time_fac = GetCurveValue(curve, interp_method, aktuelle_zeit, &valid); + if (!valid) + continue; + } + else time_fac = 1.0; - if(bc_msh_node >= 0) + //................................................................ + // Time dependencies - FCT + if (m_bc_node->fct_name.length() > 0) { - //................................................................ - // Time dependencies - CURVE - curve = m_bc_node->CurveIndex; - if(curve > 0) - { - time_fac = GetCurveValue(curve, - interp_method, - aktuelle_zeit, - &valid); - if(!valid) - continue; - } - else - time_fac = 1.0; - //................................................................ - // Time dependencies - FCT - if(m_bc_node->fct_name.length() > 0) - { - m_fct = FCTGet(m_bc_node->fct_name); - if(m_fct) - time_fac = m_fct->GetValue(aktuelle_zeit, - &is_valid); - //if(!valid) continue; - else - cout << - "Warning in CRFProcess::IncorporateBoundaryConditions - no FCT data" - << "\n"; - } - //................................................................ - // Conditions - if(m_bc_node->conditional) - bc_value = time_fac * fac * GetNodeValue( - m_bc_node->msh_node_number_subst, - //WW bc_value = time_fac*fac* GetNodeVal(bc_msh_node+1,GetNODValueIndex(pcs_primary_function_name[0])+1); // YD-----TEST--- - GetNodeValueIndex( - pcs_primary_function_name[0]) + 1); - else - // time_fac*fac*PCSGetNODValue(bc_msh_node,"PRESSURE1",0); - bc_value = time_fac * fac * m_bc_node->node_value; - //---------------------------------------------------------------- - // MSH - if(rank > -1) - bc_eqs_index = bc_msh_node; + m_fct = FCTGet(m_bc_node->fct_name); + if (m_fct) + time_fac = m_fct->GetValue(aktuelle_zeit, &is_valid); + // if(!valid) continue; else - //WW# - bc_eqs_index = - m_msh->nod_vector[bc_msh_node]-> - GetEquationIndex(); - //.............................................................. - // NEWTON WW - if(m_num->nls_method >= 1 //_name.find("NEWTON")!=string::npos - || type == 4 || type == 41 ) //Solution is in the manner of increment ! + cout << "Warning in CRFProcess::IncorporateBoundaryConditions - no FCT data" + << "\n"; + } + //................................................................ + // Conditions + if (m_bc_node->conditional) + bc_value + = time_fac * fac + * GetNodeValue(m_bc_node->msh_node_number_subst, + // WW bc_value = time_fac*fac* + // GetNodeVal(bc_msh_node+1,GetNODValueIndex(pcs_primary_function_name[0])+1); + // // YD-----TEST--- + GetNodeValueIndex(pcs_primary_function_name[0]) + 1); + else + // time_fac*fac*PCSGetNODValue(bc_msh_node,"PRESSURE1",0); + bc_value = time_fac * fac * m_bc_node->node_value; + //---------------------------------------------------------------- + // MSH + if (rank > -1) + bc_eqs_index = bc_msh_node; + else + // WW# + bc_eqs_index = m_msh->nod_vector[bc_msh_node]->GetEquationIndex(); + //.............................................................. + // NEWTON WW + if (m_num->nls_method >= 1 //_name.find("NEWTON")!=string::npos + || type == 4 + || type == 41) // Solution is in the manner of increment ! + { + idx0 = GetNodeValueIndex(convertPrimaryVariableToString(m_bc->getProcessPrimaryVariable())); + if (type == 4 || type == 41) { - idx0 = GetNodeValueIndex( - convertPrimaryVariableToString(m_bc-> - getProcessPrimaryVariable())); - if(type == 4 || type == 41) + // 30.08.2010. WW + if (m_bc_node->pcs_pv_name.find("PRESSURE") == string::npos) { - //30.08.2010. WW - if(m_bc_node->pcs_pv_name.find("PRESSURE") - == string::npos) - { - idx1 = idx0 + 1; - bc_value -= GetNodeValue( - m_bc_node->geo_node_number, - idx0) - + GetNodeValue( - m_bc_node->geo_node_number, - idx1); - } + idx1 = idx0 + 1; + bc_value -= GetNodeValue(m_bc_node->geo_node_number, idx0) + + GetNodeValue(m_bc_node->geo_node_number, idx1); } - else - bc_value = bc_value - GetNodeValue( - m_bc_node->geo_node_number, - idx0); } - //---------------------------------------------------------------- - bc_eqs_index += shift; - if((int)continuum_vector.size() > 1) - //YD/WW - if(m_bc_node->pcs_pv_name.find( - pcs_primary_function_name[continuum]) == - string::npos) - continue; + else + bc_value = bc_value - GetNodeValue(m_bc_node->geo_node_number, idx0); + } + //---------------------------------------------------------------- + bc_eqs_index += shift; + if ((int)continuum_vector.size() > 1) + // YD/WW + if (m_bc_node->pcs_pv_name.find(pcs_primary_function_name[continuum]) == string::npos) + continue; #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - //TODO -#elif defined(NEW_EQS) //WW - eqs_p->SetKnownX_i(bc_eqs_index, bc_value); +// TODO +#elif defined(NEW_EQS) // WW + eqs_p->SetKnownX_i(bc_eqs_index, bc_value); #else - MXRandbed(bc_eqs_index,bc_value,eqs_rhs); + MXRandbed(bc_eqs_index, bc_value, eqs_rhs); #endif - } } - // PCH - else if(axis == 1 && m_bc_node->pcs_pv_name.find("VELOCITY1_Y") != - string::npos) - { - m_bc = bc_node[gindex]; - shift = m_bc_node->msh_node_number - m_bc_node->geo_node_number; - // + } + // PCH + else if (axis == 1 && m_bc_node->pcs_pv_name.find("VELOCITY1_Y") != string::npos) + { + m_bc = bc_node[gindex]; + shift = m_bc_node->msh_node_number - m_bc_node->geo_node_number; +// #if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW - if(rank > -1) + if (rank > -1) + { + bc_msh_node = bc_local_index_in_dom[i]; + int dim_space = 0; + if (m_msh->NodesNumber_Linear == m_msh->NodesNumber_Quadratic) + dim_space = 0; + else { - bc_msh_node = bc_local_index_in_dom[i]; - int dim_space = 0; - if(m_msh->NodesNumber_Linear == - m_msh->NodesNumber_Quadratic) - dim_space = 0; + if (shift % m_msh->NodesNumber_Quadratic == 0) + dim_space = shift / m_msh->NodesNumber_Quadratic; else - { - if(shift % m_msh->NodesNumber_Quadratic == 0) - dim_space = shift / - m_msh->NodesNumber_Quadratic; - else - dim_space = m_msh->msh_max_dim; - } - shift = m_dom->shift[dim_space]; + dim_space = m_msh->msh_max_dim; } - else + shift = m_dom->shift[dim_space]; + } + else #endif - bc_msh_node = m_bc_node->geo_node_number; - //------------------------------------------------------------WW - if(m_msh) //OK - // if(!m_msh->nod_vector[bc_msh_node]->GetMark()) //WW - // continue; + bc_msh_node = m_bc_node->geo_node_number; + //------------------------------------------------------------WW + if (m_msh) // OK + // if(!m_msh->nod_vector[bc_msh_node]->GetMark()) //WW + // continue; + time_fac = 1.0; + if (bc_msh_node >= 0) + { + //................................................................ + // Time dependencies - CURVE + curve = m_bc_node->CurveIndex; + if (curve > 0) + { + time_fac = GetCurveValue(curve, interp_method, aktuelle_zeit, &valid); + if (!valid) + continue; + } + else time_fac = 1.0; - if(bc_msh_node >= 0) + //................................................................ + // Time dependencies - FCT + if (m_bc_node->fct_name.length() > 0) { - //................................................................ - // Time dependencies - CURVE - curve = m_bc_node->CurveIndex; - if(curve > 0) - { - time_fac = GetCurveValue(curve, - interp_method, - aktuelle_zeit, - &valid); - if(!valid) - continue; - } + m_fct = FCTGet(m_bc_node->fct_name); + if (m_fct) + time_fac = m_fct->GetValue(aktuelle_zeit, &is_valid); + // if(!valid) continue; else - time_fac = 1.0; - //................................................................ - // Time dependencies - FCT - if(m_bc_node->fct_name.length() > 0) + cout << "Warning in CRFProcess::IncorporateBoundaryConditions - no FCT data" + << "\n"; + } + //................................................................ + // Conditions + if (m_bc_node->conditional) + bc_value + = time_fac * fac + * GetNodeValue(m_bc_node->msh_node_number_subst, + // WW bc_value = time_fac*fac* + // GetNodeVal(bc_msh_node+1,GetNODValueIndex(pcs_primary_function_name[0])+1); + // // YD-----TEST--- + GetNodeValueIndex(pcs_primary_function_name[0]) + 1); + else + // time_fac*fac*PCSGetNODValue(bc_msh_node,"PRESSURE1",0); + bc_value = time_fac * fac * m_bc_node->node_value; + //---------------------------------------------------------------- + // MSH + if (rank > -1) + bc_eqs_index = bc_msh_node; + else + // WW# + bc_eqs_index = m_msh->nod_vector[bc_msh_node]->GetEquationIndex(); + //.............................................................. + // NEWTON WW + if (m_num->nls_method >= 1 //_name.find("NEWTON")!=string::npos + || type == 4 + || type == 41) // Solution is in the manner of increment ! + { + idx0 = GetNodeValueIndex(convertPrimaryVariableToString(m_bc->getProcessPrimaryVariable()).c_str()); + if (type == 4 || type == 41) { - m_fct = FCTGet(m_bc_node->fct_name); - if(m_fct) - time_fac = m_fct->GetValue(aktuelle_zeit, - &is_valid); - //if(!valid) continue; - else - cout << - "Warning in CRFProcess::IncorporateBoundaryConditions - no FCT data" - << "\n"; + idx1 = idx0 + 1; + bc_value -= GetNodeValue(m_bc_node->geo_node_number, idx0) + + GetNodeValue(m_bc_node->geo_node_number, idx1); } - //................................................................ - // Conditions - if(m_bc_node->conditional) - bc_value = time_fac * fac * GetNodeValue( - m_bc_node->msh_node_number_subst, - //WW bc_value = time_fac*fac* GetNodeVal(bc_msh_node+1,GetNODValueIndex(pcs_primary_function_name[0])+1); // YD-----TEST--- - GetNodeValueIndex( - pcs_primary_function_name[0]) + 1); else - // time_fac*fac*PCSGetNODValue(bc_msh_node,"PRESSURE1",0); - bc_value = time_fac * fac * m_bc_node->node_value; - //---------------------------------------------------------------- - // MSH - if(rank > -1) - bc_eqs_index = bc_msh_node; - else - //WW# - bc_eqs_index = - m_msh->nod_vector[bc_msh_node]-> - GetEquationIndex(); - //.............................................................. - // NEWTON WW - if(m_num->nls_method >= 1 //_name.find("NEWTON")!=string::npos - || type == 4 || type == 41 ) //Solution is in the manner of increment ! - { - idx0 = GetNodeValueIndex( - convertPrimaryVariableToString(m_bc-> - getProcessPrimaryVariable( - )). - c_str()); - if(type == 4 || type == 41) - { - idx1 = idx0 + 1; - bc_value -= GetNodeValue( - m_bc_node->geo_node_number, - idx0) - + GetNodeValue( - m_bc_node->geo_node_number, - idx1); - } - else - bc_value = bc_value - GetNodeValue( - m_bc_node->geo_node_number, - idx0); - } - //---------------------------------------------------------------- - bc_eqs_index += shift; - if((int)continuum_vector.size() > 1) - //YD/WW - if(m_bc_node->pcs_pv_name.find( - pcs_primary_function_name[continuum]) == - string::npos) - continue; + bc_value = bc_value - GetNodeValue(m_bc_node->geo_node_number, idx0); + } + //---------------------------------------------------------------- + bc_eqs_index += shift; + if ((int)continuum_vector.size() > 1) + // YD/WW + if (m_bc_node->pcs_pv_name.find(pcs_primary_function_name[continuum]) == string::npos) + continue; #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - //TODO -#elif defined(NEW_EQS) //WW - eqs_p->SetKnownX_i(bc_eqs_index, bc_value); +// TODO +#elif defined(NEW_EQS) // WW + eqs_p->SetKnownX_i(bc_eqs_index, bc_value); #else - MXRandbed(bc_eqs_index,bc_value,eqs_rhs); + MXRandbed(bc_eqs_index, bc_value, eqs_rhs); #endif - } } - // PCH - else if(axis == 2 && m_bc_node->pcs_pv_name.find("VELOCITY1_Z") != - string::npos) - { - m_bc = bc_node[gindex]; - shift = m_bc_node->msh_node_number - m_bc_node->geo_node_number; - // + } + // PCH + else if (axis == 2 && m_bc_node->pcs_pv_name.find("VELOCITY1_Z") != string::npos) + { + m_bc = bc_node[gindex]; + shift = m_bc_node->msh_node_number - m_bc_node->geo_node_number; +// #if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW - if(rank > -1) + if (rank > -1) + { + bc_msh_node = bc_local_index_in_dom[i]; + int dim_space = 0; + if (m_msh->NodesNumber_Linear == m_msh->NodesNumber_Quadratic) + dim_space = 0; + else { - bc_msh_node = bc_local_index_in_dom[i]; - int dim_space = 0; - if(m_msh->NodesNumber_Linear == - m_msh->NodesNumber_Quadratic) - dim_space = 0; + if (shift % m_msh->NodesNumber_Quadratic == 0) + dim_space = shift / m_msh->NodesNumber_Quadratic; else - { - if(shift % m_msh->NodesNumber_Quadratic == 0) - dim_space = shift / - m_msh->NodesNumber_Quadratic; - else - dim_space = m_msh->msh_max_dim; - } - shift = m_dom->shift[dim_space]; + dim_space = m_msh->msh_max_dim; } - else + shift = m_dom->shift[dim_space]; + } + else #endif - bc_msh_node = m_bc_node->geo_node_number; - //------------------------------------------------------------WW - if(m_msh) //OK - // if(!m_msh->nod_vector[bc_msh_node]->GetMark()) //WW - // continue; + bc_msh_node = m_bc_node->geo_node_number; + //------------------------------------------------------------WW + if (m_msh) // OK + // if(!m_msh->nod_vector[bc_msh_node]->GetMark()) //WW + // continue; + time_fac = 1.0; + if (bc_msh_node >= 0) + { + //................................................................ + // Time dependencies - CURVE + curve = m_bc_node->CurveIndex; + if (curve > 0) + { + time_fac = GetCurveValue(curve, interp_method, aktuelle_zeit, &valid); + if (!valid) + continue; + } + else time_fac = 1.0; - if(bc_msh_node >= 0) + //................................................................ + // Time dependencies - FCT + if (m_bc_node->fct_name.length() > 0) { - //................................................................ - // Time dependencies - CURVE - curve = m_bc_node->CurveIndex; - if(curve > 0) - { - time_fac = GetCurveValue(curve, - interp_method, - aktuelle_zeit, - &valid); - if(!valid) - continue; - } + m_fct = FCTGet(m_bc_node->fct_name); + if (m_fct) + time_fac = m_fct->GetValue(aktuelle_zeit, &is_valid); + // if(!valid) continue; else - time_fac = 1.0; - //................................................................ - // Time dependencies - FCT - if(m_bc_node->fct_name.length() > 0) + cout << "Warning in CRFProcess::IncorporateBoundaryConditions - no FCT data" + << "\n"; + } + //................................................................ + // Conditions + if (m_bc_node->conditional) + bc_value + = time_fac * fac + * GetNodeValue(m_bc_node->msh_node_number_subst, + // WW bc_value = time_fac*fac* + // GetNodeVal(bc_msh_node+1,GetNODValueIndex(pcs_primary_function_name[0])+1); + // // YD-----TEST--- + GetNodeValueIndex(pcs_primary_function_name[0]) + 1); + else + // time_fac*fac*PCSGetNODValue(bc_msh_node,"PRESSURE1",0); + bc_value = time_fac * fac * m_bc_node->node_value; + //---------------------------------------------------------------- + // MSH + if (rank > -1) + bc_eqs_index = bc_msh_node; + else + // WW# + bc_eqs_index = m_msh->nod_vector[bc_msh_node]->GetEquationIndex(); + //.............................................................. + // NEWTON WW + if (m_num->nls_method >= 1 //_name.find("NEWTON")!=std::string::npos + || type == 4 + || type == 41) // Solution is in the manner of increment ! + { + idx0 = GetNodeValueIndex(convertPrimaryVariableToString(m_bc->getProcessPrimaryVariable()).c_str()); + if (type == 4 || type == 41) { - m_fct = FCTGet(m_bc_node->fct_name); - if(m_fct) - time_fac = m_fct->GetValue(aktuelle_zeit, - &is_valid); - //if(!valid) continue; - else - cout << - "Warning in CRFProcess::IncorporateBoundaryConditions - no FCT data" - << "\n"; + idx1 = idx0 + 1; + bc_value -= GetNodeValue(m_bc_node->geo_node_number, idx0) + + GetNodeValue(m_bc_node->geo_node_number, idx1); } - //................................................................ - // Conditions - if(m_bc_node->conditional) - bc_value = time_fac * fac * GetNodeValue( - m_bc_node->msh_node_number_subst, - //WW bc_value = time_fac*fac* GetNodeVal(bc_msh_node+1,GetNODValueIndex(pcs_primary_function_name[0])+1); // YD-----TEST--- - GetNodeValueIndex( - pcs_primary_function_name[0]) + 1); else - // time_fac*fac*PCSGetNODValue(bc_msh_node,"PRESSURE1",0); - bc_value = time_fac * fac * m_bc_node->node_value; - //---------------------------------------------------------------- - // MSH - if(rank > -1) - bc_eqs_index = bc_msh_node; - else - //WW# - bc_eqs_index = - m_msh->nod_vector[bc_msh_node]-> - GetEquationIndex(); - //.............................................................. - // NEWTON WW - if(m_num->nls_method >= 1 //_name.find("NEWTON")!=std::string::npos - || type == 4 || type == 41 ) //Solution is in the manner of increment ! - { - idx0 = GetNodeValueIndex( - convertPrimaryVariableToString(m_bc-> - getProcessPrimaryVariable( - )). - c_str()); - if(type == 4 || type == 41) - { - idx1 = idx0 + 1; - bc_value -= GetNodeValue( - m_bc_node->geo_node_number, - idx0) - + GetNodeValue( - m_bc_node->geo_node_number, - idx1); - } - else - bc_value = bc_value - GetNodeValue( - m_bc_node->geo_node_number, - idx0); - } - //---------------------------------------------------------------- - bc_eqs_index += shift; - if((int)continuum_vector.size() > 1) - //YD/WW - if(m_bc_node->pcs_pv_name.find( - pcs_primary_function_name[continuum]) == - std::string::npos) - continue; + bc_value = bc_value - GetNodeValue(m_bc_node->geo_node_number, idx0); + } + //---------------------------------------------------------------- + bc_eqs_index += shift; + if ((int)continuum_vector.size() > 1) + // YD/WW + if (m_bc_node->pcs_pv_name.find(pcs_primary_function_name[continuum]) == std::string::npos) + continue; #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - //TODO -#elif defined(NEW_EQS) //WW - eqs_p->SetKnownX_i(bc_eqs_index, bc_value); +// TODO +#elif defined(NEW_EQS) // WW + eqs_p->SetKnownX_i(bc_eqs_index, bc_value); #else - MXRandbed(bc_eqs_index,bc_value,eqs_rhs); + MXRandbed(bc_eqs_index, bc_value, eqs_rhs); #endif - } } } - - //----------------------------------------------------------------------- - /* irreg. Zeilen/Spalten regularisieren */ - /* - else if (GetNodeState(NodeNumber[i]) == -2 || GetNodeState(NodeNumber[i]) == -4) { // irreg.Knoten - if (GetRFControlGridAdapt()) - if (AdaptGetMethodIrrNodes() == 1) { - MXSet(i, i, MKleinsteZahl); - rechts[i] = 0.0; - } - } - } - */ } + //----------------------------------------------------------------------- + /* irreg. Zeilen/Spalten regularisieren */ + /* + else if (GetNodeState(NodeNumber[i]) == -2 || GetNodeState(NodeNumber[i]) == -4) { // irreg.Knoten + if (GetRFControlGridAdapt()) + if (AdaptGetMethodIrrNodes() == 1) { + MXSet(i, i, MKleinsteZahl); + rechts[i] = 0.0; + } + } + } + */ +} -bool CRFProcess::checkConstrainedST(std::vector & st_vector, CSourceTerm const & st, CNodeValue const & st_node) +bool CRFProcess::checkConstrainedST(std::vector& st_vector, CSourceTerm const& st, + CNodeValue const& st_node) { bool return_value(false); for (std::size_t i = 0; i < st.getNumberOfConstrainedSTs(); i++) { bool constrained_bool(false); - const Constrained &local_constrained(st.getConstrainedST(i)); + const Constrained& local_constrained(st.getConstrainedST(i)); if (local_constrained.constrainedPrimVar == FiniteElement::PRESSURE - || local_constrained.constrainedPrimVar == FiniteElement::CONCENTRATION - || local_constrained.constrainedPrimVar == FiniteElement::TEMPERATURE) + || local_constrained.constrainedPrimVar == FiniteElement::CONCENTRATION + || local_constrained.constrainedPrimVar == FiniteElement::TEMPERATURE) { - //other process + // other process CRFProcess* pcs(PCSGet(local_constrained.constrainedProcessType)); - //other variable + // other variable for (std::size_t k = 0; k < pcs->GetPrimaryVNumber(); k++) { - if (pcs->GetPrimaryVName(k) == FiniteElement::convertPrimaryVariableToString(local_constrained.constrainedPrimVar)) + if (pcs->GetPrimaryVName(k) + == FiniteElement::convertPrimaryVariableToString(local_constrained.constrainedPrimVar)) { - //value of PrimVar of other process at current node - double local_value = pcs->GetNodeValue(st_node.geo_node_number, 2*k+1); + // value of PrimVar of other process at current node + double local_value = pcs->GetNodeValue(st_node.geo_node_number, 2 * k + 1); // FIXME: if getPressureAsHead != -1, then the head is expected // however, getPressureAsHead is part of CBoundaryCondition (m_bc in IncorporateBoundaryConditions) - if (local_constrained.constrainedDirection == ConstrainedType::GREATER) //exclude greater and equal values + if (local_constrained.constrainedDirection + == ConstrainedType::GREATER) // exclude greater and equal values { - if (local_value >= local_constrained.constrainedValue) //check if calculated value (eg of other process) meets criterium + if (local_value + >= local_constrained + .constrainedValue) // check if calculated value (eg of other process) meets criterium constrained_bool = true; - } - else if (local_constrained.constrainedDirection == ConstrainedType::SMALLER) // exclude smaller values + else if (local_constrained.constrainedDirection + == ConstrainedType::SMALLER) // exclude smaller values { if (local_value < local_constrained.constrainedValue) constrained_bool = true; @@ -7467,34 +7336,35 @@ bool CRFProcess::checkConstrainedST(std::vector & st_vector, CSour } } } - st_vector[st_node.getSTVectorGroup()]->setConstrainedSTNode( - i, constrained_bool, st_node.getSTVectorIndex()); + st_vector[st_node.getSTVectorGroup()]->setConstrainedSTNode(i, constrained_bool, st_node.getSTVectorIndex()); if (constrained_bool) - return_value=true; + return_value = true; } return return_value; } -bool CRFProcess::checkConstrainedBC(CBoundaryCondition const & bc, CBoundaryConditionNode & bc_node, double & bc_value) +bool CRFProcess::checkConstrainedBC(CBoundaryCondition const& bc, CBoundaryConditionNode& bc_node, double& bc_value) { - for (std::size_t i=0; i < bc.getNumberOfConstrainedBCs(); i++) + for (std::size_t i = 0; i < bc.getNumberOfConstrainedBCs(); i++) { - const Constrained &local_constrained(bc.getConstrainedBC(i)); + const Constrained& local_constrained(bc.getConstrainedBC(i)); if (local_constrained.constrainedVariable == ConstrainedVariable::VELOCITY) { - //get velocity vector at node - std::valarrayvel(0.0, 3); // ini valarray with size=3 and element values=0 + // get velocity vector at node + std::valarray vel(0.0, 3); // ini valarray with size=3 and element values=0 if (local_constrained._isConstrainedVelStable) { - const std::size_t no_connected_nodes = m_msh->nod_vector[bc_node.geo_node_number]->getNumConnectedNodes(); - for (std::size_t j=0; j < no_connected_nodes; j++) + const std::size_t no_connected_nodes + = m_msh->nod_vector[bc_node.geo_node_number]->getNumConnectedNodes(); + for (std::size_t j = 0; j < no_connected_nodes; j++) { - std::size_t const connected_node_id = m_msh->nod_vector[bc_node.geo_node_number]->getConnectedNodes()[j]; + std::size_t const connected_node_id + = m_msh->nod_vector[bc_node.geo_node_number]->getConnectedNodes()[j]; if (connected_node_id == static_cast(bc_node.geo_node_number)) { - std::valarraytemp_vel(this->getNodeVelocityVector(connected_node_id)); + std::valarray temp_vel(this->getNodeVelocityVector(connected_node_id)); temp_vel *= (no_connected_nodes - 1); vel += temp_vel; } @@ -7505,76 +7375,88 @@ bool CRFProcess::checkConstrainedBC(CBoundaryCondition const & bc, CBoundaryCond else vel += this->getNodeVelocityVector(bc_node.geo_node_number); - //nomalize velocity vector + // nomalize velocity vector double magn_vel_v(MBtrgVec(&vel[0], 3)); - if ( !(magn_vel_v > 0) ) //check if velocity is not zero + if (!(magn_vel_v > 0)) // check if velocity is not zero { - #ifdef DEBUG +#ifdef DEBUG std::cout << "No constrained applied at node " << bc_node.msh_node_number - << " as magnitude of velocity " << magn_vel_v - << " is not > than 0 " - << std::endl; - #endif + << " as magnitude of velocity " << magn_vel_v << " is not > than 0 " << std::endl; +#endif continue; } - //NormalizeVector(&vel[0], 3); can use other way to calc normalized vector, as vector now valarray: + // NormalizeVector(&vel[0], 3); can use other way to calc normalized vector, as vector now valarray: vel /= magn_vel_v; - //calculate scalar product of velocity vector and BC surface normal + // calculate scalar product of velocity vector and BC surface normal double const scalar_prod(MathLib::scpr(&(vel)[0], bc_node.GetNormalVector(), 3)); - //select case to handle BC - if (scalar_prod < 0.05 && scalar_prod >= -1.01 // small tolerance of ~5° - && local_constrained.constrainedDirection == ConstrainedType::NEGATIVE) // velocity vector and bc surface normal point in opposite directions + // select case to handle BC + if (scalar_prod < 0.05 && scalar_prod >= -1.01 // small tolerance of ~5° + && local_constrained.constrainedDirection == ConstrainedType::NEGATIVE) // velocity vector and bc + // surface normal point in + // opposite directions { - return true; //do not apply BC (maybe later implementation: change BC to ST at this node) + return true; // do not apply BC (maybe later implementation: change BC to ST at this node) } - else if(scalar_prod <= 1.01 && scalar_prod >= -0.05 // small tolerance of ~5° - && local_constrained.constrainedDirection == ConstrainedType::POSITIVE) // velocity vector points in same direction as bc surface normal + else if (scalar_prod <= 1.01 && scalar_prod >= -0.05 // small tolerance of ~5° + && local_constrained.constrainedDirection == ConstrainedType::POSITIVE) // velocity vector points + // in same direction as bc + // surface normal { - return true; //do not apply BC (maybe later implementation: change BC to ST at this node) + return true; // do not apply BC (maybe later implementation: change BC to ST at this node) } - } if (local_constrained.constrainedPrimVar == FiniteElement::PRESSURE - || local_constrained.constrainedPrimVar == FiniteElement::CONCENTRATION - || local_constrained.constrainedPrimVar == FiniteElement::TEMPERATURE) + || local_constrained.constrainedPrimVar == FiniteElement::CONCENTRATION + || local_constrained.constrainedPrimVar == FiniteElement::TEMPERATURE) { - //other process + // other process CRFProcess* pcs(PCSGet(local_constrained.constrainedProcessType)); - //other variable + // other variable for (std::size_t k = 0; k < pcs->GetPrimaryVNumber(); k++) { - if (pcs->GetPrimaryVName(k) == FiniteElement::convertPrimaryVariableToString(local_constrained.constrainedPrimVar)) + if (pcs->GetPrimaryVName(k) + == FiniteElement::convertPrimaryVariableToString(local_constrained.constrainedPrimVar)) { - // TODO: check case GREATER - maybe not thoroughly enough evaluated - if (local_constrained.constrainedDirection == ConstrainedType::GREATER) //exclude greater and equal values + if (local_constrained.constrainedDirection + == ConstrainedType::GREATER) // exclude greater and equal values { - //value of PrimVar of other process at current node - double local_value ( 0.1 * pcs->GetNodeValue(bc_node.geo_node_number, 2*k+1) - + 0.9 * pcs->GetNodeValue(bc_node.geo_node_number, 2*k) ); - if (local_value >= local_constrained.constrainedValue) //check if calculated value (eg of other process) meets criterium + // value of PrimVar of other process at current node + double local_value(0.1 * pcs->GetNodeValue(bc_node.geo_node_number, 2 * k + 1) + + 0.9 * pcs->GetNodeValue(bc_node.geo_node_number, 2 * k)); + if (local_value + >= local_constrained + .constrainedValue) // check if calculated value (eg of other process) meets criterium return true; if (bc.getProcessType() == local_constrained.constrainedProcessType - && bc_node.node_value_pre_calc >= local_constrained.constrainedValue) //check if BC value meets criterium + && bc_node.node_value_pre_calc + >= local_constrained.constrainedValue) // check if BC value meets criterium return true; } - else if (local_constrained.constrainedDirection == ConstrainedType::SMALLER) // exclude smaller values + else if (local_constrained.constrainedDirection + == ConstrainedType::SMALLER) // exclude smaller values { - if (bc.getProcessType() == local_constrained.constrainedProcessType) // check if correct process type + if (bc.getProcessType() + == local_constrained.constrainedProcessType) // check if correct process type { - if(bc_node.node_value_pre_calc < local_constrained.constrainedValue) //limit BC if constrained below BC value + if (bc_node.node_value_pre_calc + < local_constrained.constrainedValue) // limit BC if constrained below BC value { - if(local_constrained._isSeepageBC) + if (local_constrained._isSeepageBC) { - //value of PrimVar of other process at current node - double local_value ( 0.1 * pcs->GetNodeValue(bc_node.geo_node_number, 2*k+1) //slight averaging with last time step for stability - + 0.9 * pcs->GetNodeValue(bc_node.geo_node_number, 2*k) ); - - if(local_value < local_constrained.constrainedValue) + // value of PrimVar of other process at current node + double local_value( + 0.1 + * pcs->GetNodeValue( + bc_node.geo_node_number, + 2 * k + 1) // slight averaging with last time step for stability + + 0.9 * pcs->GetNodeValue(bc_node.geo_node_number, 2 * k)); + + if (local_value < local_constrained.constrainedValue) return true; else bc_value = local_constrained.constrainedValue; @@ -7592,15 +7474,14 @@ bool CRFProcess::checkConstrainedBC(CBoundaryCondition const & bc, CBoundaryCond return false; } - /************************************************************************** Copied & modified from rf_kinreact.cpp (Reaction-Method:) **************************************************************************/ std::valarray CRFProcess::getNodeVelocityVector(const long node_id) { - CRFProcess *m_pcs = NULL; - std::valarray vel_nod (0.0, 3); + CRFProcess* m_pcs = NULL; + std::valarray vel_nod(0.0, 3); m_pcs = PCSGetFlow(); @@ -7626,139 +7507,139 @@ std::valarray CRFProcess::getNodeVelocityVector(const long node_id) return vel_nod; } +int CRFProcess::getFirstNodeBelowGWL(size_t current_node) +{ + // searches for PRESSURE1<0 and returns the node below or above node i - int CRFProcess::getFirstNodeBelowGWL(size_t current_node) + int sorted_node(-1); + for (size_t i(0); i < this->m_msh->sorted_nodes.size(); i++) { - //searches for PRESSURE1<0 and returns the node below or above node i - - int sorted_node(-1); - for (size_t i(0);im_msh->sorted_nodes.size();i++) + if (current_node == this->m_msh->sorted_nodes[i]) { - if (current_node == this->m_msh->sorted_nodes[i]) - { - sorted_node=i; - break; - } + sorted_node = i; + break; } + } - const int val_idx=this->GetNodeValueIndex("PRESSURE1",true); - int new_GWL_st_node(-1); + const int val_idx = this->GetNodeValueIndex("PRESSURE1", true); + int new_GWL_st_node(-1); - for(size_t k(1);km_msh->xy_change.size();k++) //look for range of xy-coordinates + for (size_t k(1); k < this->m_msh->xy_change.size(); k++) // look for range of xy-coordinates + { + const long node_id = this->m_msh->xy_change[k]; + if (node_id >= sorted_node) // found range { - const long node_id = this->m_msh->xy_change[k]; - if(node_id >= sorted_node) //found range - { - - new_GWL_st_node=this->m_msh->sorted_nodes[this->m_msh->xy_change[k-1]+1]; //set to bottom node first + new_GWL_st_node = this->m_msh->sorted_nodes[this->m_msh->xy_change[k - 1] + 1]; // set to bottom node first - if(this->GetNodeValue(this->m_msh->sorted_nodes[node_id],val_idx) > 0) //top node has p>0 - { - new_GWL_st_node=this->m_msh->sorted_nodes[node_id]; //return top node id - break; - } - else + if (this->GetNodeValue(this->m_msh->sorted_nodes[node_id], val_idx) > 0) // top node has p>0 + { + new_GWL_st_node = this->m_msh->sorted_nodes[node_id]; // return top node id + break; + } + else + { + for (size_t j(node_id - 1); j > this->m_msh->xy_change[k - 1] + 1; + j--) // look in range from top to bottom (but skip top node) { - for(size_t j(node_id-1);j>this->m_msh->xy_change[k-1]+1;j--) //look in range from top to bottom (but skip top node) + if (this->GetNodeValue(this->m_msh->sorted_nodes[j], val_idx) > 0) // look for first node with p>0 { - - if(this->GetNodeValue(this->m_msh->sorted_nodes[j],val_idx) > 0) //look for first node with p>0 - { - new_GWL_st_node=this->m_msh->sorted_nodes[j-1]; //for p<0, return node id two nodes below gwl - break; - } + new_GWL_st_node + = this->m_msh->sorted_nodes[j - 1]; // for p<0, return node id two nodes below gwl + break; } } - break; } - + break; } - - return new_GWL_st_node; } + return new_GWL_st_node; +} -//MW if set, calculate pressure from given head at bc with density, gravity constant and geodetic height for PRESSURE as primary variable -double CRFProcess::calcPressureFromHead(CBoundaryCondition const & bc, std::size_t node_number, double head_value, - double const & time_fac, double const & fac) +// MW if set, calculate pressure from given head at bc with density, gravity constant and geodetic height for PRESSURE +// as primary variable +double CRFProcess::calcPressureFromHead(CBoundaryCondition const& bc, std::size_t node_number, double head_value, + double const& time_fac, double const& fac) { double local_density; switch (bc.getPressureAsHeadModel()) { - case 0: - //use current density at node - local_density = MFPGetNodeValue(node_number, "DENSITY", 0); - break; - case 1: - //use given density - local_density = bc.getPressureAsHeadDensity(); - break; - default: - std::cout << "Warning! No PressureAsHeadDensity specified. Calculating density (i.e. PressureAsHeadModel 0)!" << std::endl; - local_density = MFPGetNodeValue(node_number, "DENSITY", 0); - break; + case 0: + // use current density at node + local_density = MFPGetNodeValue(node_number, "DENSITY", 0); + break; + case 1: + // use given density + local_density = bc.getPressureAsHeadDensity(); + break; + default: + std::cout + << "Warning! No PressureAsHeadDensity specified. Calculating density (i.e. PressureAsHeadModel 0)!" + << std::endl; + local_density = MFPGetNodeValue(node_number, "DENSITY", 0); + break; } const double local_node_elevation = this->m_msh->nod_vector[node_number]->Z(); // pressure = gravitational_constant * density * ( head - geodetic_height ) - double pressure_value( fac * gravity_constant * local_density * ( time_fac * head_value - local_node_elevation ) ); + double pressure_value(fac * gravity_constant * local_density * (time_fac * head_value - local_node_elevation)); return pressure_value; } - -double CRFProcess::calcHeadFromPressure(CBoundaryCondition const & bc, std::size_t node_number, double pressure_value, - double const & time_fac, double const & fac) +double CRFProcess::calcHeadFromPressure(CBoundaryCondition const& bc, std::size_t node_number, double pressure_value, + double const& time_fac, double const& fac) { double local_density; switch (bc.getPressureAsHeadModel()) { - case 0: - //use current density at node - local_density = MFPGetNodeValue(node_number, "DENSITY", 0); - break; - case 1: - //use given density - local_density = bc.getPressureAsHeadDensity(); - break; - default: - std::cout << "Warning! No PressureAsHeadDensity specified. Calculating density (i.e. PressureAsHeadModel 0)!" << std::endl; - local_density = MFPGetNodeValue(node_number, "DENSITY", 0); - break; + case 0: + // use current density at node + local_density = MFPGetNodeValue(node_number, "DENSITY", 0); + break; + case 1: + // use given density + local_density = bc.getPressureAsHeadDensity(); + break; + default: + std::cout + << "Warning! No PressureAsHeadDensity specified. Calculating density (i.e. PressureAsHeadModel 0)!" + << std::endl; + local_density = MFPGetNodeValue(node_number, "DENSITY", 0); + break; } const double local_node_elevation = this->m_msh->nod_vector[node_number]->Z(); // pressure = gravitational_constant * density * ( head - geodetic_height ) - double head_value( fac * ( pressure_value * time_fac / ( gravity_constant * local_density ) + local_node_elevation ) ); + double head_value(fac * (pressure_value * time_fac / (gravity_constant * local_density) + local_node_elevation)); return head_value; } - -double CRFProcess::evaluteSwitchBC(CBoundaryCondition const & bc, CBoundaryConditionNode const & bc_node, double time_fac, double fac) +double CRFProcess::evaluteSwitchBC(CBoundaryCondition const& bc, CBoundaryConditionNode const& bc_node, double time_fac, + double fac) { - - const SwitchBC &localSwitchBC(bc.getSwitchBC()); + const SwitchBC& localSwitchBC(bc.getSwitchBC()); // assume, normally to use on value - double returnValue ( time_fac * fac * localSwitchBC.switchOnValue ); + double returnValue(time_fac * fac * localSwitchBC.switchOnValue); CRFProcess* pcs(PCSGet(localSwitchBC.switchProcessType)); - //other variable + // other variable for (std::size_t i(0); i < pcs->GetPrimaryVNumber(); i++) { if (pcs->GetPrimaryVName(i) == FiniteElement::convertPrimaryVariableToString(localSwitchBC.switchPrimVar)) { - //value of PrimVar of other process at current node - double localValue ( 0.1 * pcs->GetNodeValue(bc_node.geo_node_number, 2*i+1) - + 0.9 * pcs->GetNodeValue(bc_node.geo_node_number, 2*i) ); + // value of PrimVar of other process at current node + double localValue(0.1 * pcs->GetNodeValue(bc_node.geo_node_number, 2 * i + 1) + + 0.9 * pcs->GetNodeValue(bc_node.geo_node_number, 2 * i)); - if ( localValue < localSwitchBC.switchValue ) + if (localValue < localSwitchBC.switchValue) { // set off value, if other value lower than switchValue - returnValue = ( time_fac * fac * localSwitchBC.switchOffValue ); + returnValue = (time_fac * fac * localSwitchBC.switchOffValue); } break; } @@ -7766,7 +7647,6 @@ double CRFProcess::evaluteSwitchBC(CBoundaryCondition const & bc, CBoundaryCondi return returnValue; } - /************************************************************************** FEMLib-Method: Task: PCS source terms into EQS @@ -7782,491 +7662,481 @@ double CRFProcess::evaluteSwitchBC(CBoundaryCondition const & bc, CBoundaryCondi 05/2006 WW DDC 08/2006 YD FCT use **************************************************************************/ - void CRFProcess::IncorporateSourceTerms(const int rank) - { - double value = 0, fac = 1.0, time_fac; - int interp_method = 0; - int curve, valid = 0; - long msh_node, shift; - MshElemType::type EleType; //ii - double q_face = 0.0; - CElem* elem = NULL; - CElem* face = NULL; - ElementValue* gp_ele = NULL; +void CRFProcess::IncorporateSourceTerms(const int rank) +{ + double value = 0, fac = 1.0, time_fac; + int interp_method = 0; + int curve, valid = 0; + long msh_node, shift; + MshElemType::type EleType; // ii + double q_face = 0.0; + CElem* elem = NULL; + CElem* face = NULL; + ElementValue* gp_ele = NULL; #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - vector st_eqs_id; - vector st_eqs_value; + vector st_eqs_id; + vector st_eqs_value; #else - CPARDomain* m_dom = NULL; - double* eqs_rhs = NULL; - long bc_eqs_index = -1; - int dim_space = 0; //kg44 better define here and not in a loop! + CPARDomain* m_dom = NULL; + double* eqs_rhs = NULL; + long bc_eqs_index = -1; + int dim_space = 0; // kg44 better define here and not in a loop! #endif - double vel[3]; - bool is_valid; //YD - CFunction* m_fct = NULL; //YD - long i; //, group_vector_length; + double vel[3]; + bool is_valid; // YD + CFunction* m_fct = NULL; // YD + long i; //, group_vector_length; - double Scaling = 1.0; - if(type == 4 || type / 10 == 4) - { - fac = Scaling; - } + double Scaling = 1.0; + if (type == 4 || type / 10 == 4) + { + fac = Scaling; + } - CNodeValue* cnodev = NULL; - CSourceTerm* m_st = NULL; - // - long begin = 0; - long end = 0; - long gindex = 0; + CNodeValue* cnodev = NULL; + CSourceTerm* m_st = NULL; + // + long begin = 0; + long end = 0; + long gindex = 0; -//############################### -//NB Climate Data -//MW Use loop for constrained ST evaluation + //############################### + // NB Climate Data + // MW Use loop for constrained ST evaluation + + for (size_t i = 0; i < st_vector.size(); i++) + { + // for constrainedST + if (!(st_vector[i]->isConstrainedST())) + continue; - for (size_t i=0; igetNumberOfConstrainedSTs(); j++) { - // for constrainedST - if ( !(st_vector[i]->isConstrainedST()) ) + if (!(st_vector[i]->isCompleteConstrainST(j))) continue; - for (std::size_t j(0); j < st_vector[i]->getNumberOfConstrainedSTs(); j++) + st_vector[i]->setCompleteConstrainedSTStateOff(false, j); + size_t end = st_vector[i]->getNumberOfConstrainedSTNodes(j); + for (std::size_t k(0); k < end; k++) { - if ( !(st_vector[i]->isCompleteConstrainST(j)) ) - continue; - - st_vector[i]->setCompleteConstrainedSTStateOff(false,j); - size_t end = st_vector[i]->getNumberOfConstrainedSTNodes(j); - for (std::size_t k(0); k < end; k++) + if (st_vector[i]->getConstrainedSTNode(j, k)) { - if (st_vector[i]->getConstrainedSTNode(j,k)) - { - st_vector[i]->setCompleteConstrainedSTStateOff(true,j); - break; - } + st_vector[i]->setCompleteConstrainedSTStateOff(true, j); + break; } } + } - // NOTE (KR): This only works correctly if there is only ONE source term with DisType CLIMATE! TODO - // If more are needed pls let me know - if (st_vector[i]->getProcessDistributionType()==FiniteElement::CLIMATE) - { - m_st = st_vector[i]; - const MathLib::InverseDistanceInterpolation *distances (m_st->getClimateStationDistanceInterpolation()); + // NOTE (KR): This only works correctly if there is only ONE source term with DisType CLIMATE! TODO + // If more are needed pls let me know + if (st_vector[i]->getProcessDistributionType() == FiniteElement::CLIMATE) + { + m_st = st_vector[i]; + const MathLib::InverseDistanceInterpolation* distances( + m_st->getClimateStationDistanceInterpolation()); - // Interpolate each ST to every surface node; - const std::vector &weather_stations (m_st->getClimateStations()); - const size_t nStations = weather_stations.size(); - vector vec_etr(nStations); - for (size_t j=0; j(weather_stations[j])->getSensorData()->getData(SensorDataType::RECHARGE, aktuelle_zeit, true); + // Interpolate each ST to every surface node; + const std::vector& weather_stations(m_st->getClimateStations()); + const size_t nStations = weather_stations.size(); + vector vec_etr(nStations); + for (size_t j = 0; j < nStations; j++) + vec_etr[j] = static_cast(weather_stations[j]) + ->getSensorData() + ->getData(SensorDataType::RECHARGE, aktuelle_zeit, true); - // Interpolate the point data onto the Mesh surface - const size_t nSTNodeValues ( st_node_value.size() ); - const size_t nDistances ( distances->getNDomainPoints() ); - for (size_t j=0; jgetNDomainPoints()); + for (size_t j = 0; j < nSTNodeValues; j++) + { + // search the first node value index not set (this should be the start for the CLIMATE data + if (st_node_value[j]->node_value == std::numeric_limits::min()) { - // search the first node value index not set (this should be the start for the CLIMATE data - if (st_node_value[j]->node_value == std::numeric_limits::min()) + // Interpolate for each surface node + for (size_t w = 0; w < nDistances; w++) { - // Interpolate for each surface node - for (size_t w=0;wgetDistance(w,q) / distances->getSumOfDistances(w); - - const size_t n (distances->getDomainPoint(w)->getID()); - st_node_value[j+w]->node_value = st_value * m_msh->nod_vector[n]->patch_area; - } - break; + // for each ST_node, the distance to all weather stations has been determined before + // (InverseDistranceInterpolation) + // Value ETR(n) at node n by inverse distance weighting of ETR(WS) for each weather station WS + double st_value(0); + for (size_t q = 0; q < nStations; q++) + st_value += vec_etr[q] * distances->getDistance(w, q) / distances->getSumOfDistances(w); + + const size_t n(distances->getDomainPoint(w)->getID()); + st_node_value[j + w]->node_value = st_value * m_msh->nod_vector[n]->patch_area; } + break; } + } #ifndef NDEBUG - /* output of interpolated data */ - ofstream file; - stringstream filename ("interpolation"); + /* output of interpolated data */ + ofstream file; + stringstream filename("interpolation"); - filename << FilePath << filename.str(); + filename << FilePath << filename.str(); - if(Tim->step_current<1000) + if (Tim->step_current < 1000) + { + filename << 0; + if (Tim->step_current < 100) { filename << 0; - if(Tim->step_current<100) - { + if (Tim->step_current < 10) filename << 0; - if (Tim->step_current<10) - filename << 0; - } } + } - filename << Tim->step_current << ".csv"; - cout << " Interpolation result written in " << filename.str() << "\n"; + filename << Tim->step_current << ".csv"; + cout << " Interpolation result written in " << filename.str() << "\n"; - file.open(filename.str().c_str()); - file << "node,x,y,z,recharge,area"<< "\n"; + file.open(filename.str().c_str()); + file << "node,x,y,z,recharge,area" + << "\n"; - for (size_t i=0;imsh_node_number; - const double *coords (m_msh->nod_vector[z]->getData()); - file << z << "," << coords[0] << "," << coords[1] << "," << "0" << ","<< st_node_value[i]->node_value << "," << m_msh->nod_vector[z]->patch_area<< "\n"; - } + for (size_t i = 0; i < st_node_value.size(); i++) + { + const long z = st_node_value[i]->msh_node_number; + const double* coords(m_msh->nod_vector[z]->getData()); + file << z << "," << coords[0] << "," << coords[1] << "," + << "0" + << "," << st_node_value[i]->node_value << "," << m_msh->nod_vector[z]->patch_area << "\n"; + } - file.close(); + file.close(); #endif - } } + } - m_st=NULL; + m_st = NULL; -//##################### + //##################### - if (rank == -1) - { - begin = 0; - end = (long) st_node_value.size(); + if (rank == -1) + { + begin = 0; + end = (long)st_node_value.size(); #if !defined(USE_PETSC) // && !defined(other parallel libs)//03~04.3012. WW -#ifdef NEW_EQS //WW - eqs_rhs = eqs_new->b; //27.11.2007 WW +#ifdef NEW_EQS // WW + eqs_rhs = eqs_new->b; // 27.11.2007 WW #else eqs_rhs = eqs->b; #endif #endif - } + } #if !defined(USE_PETSC) // && !defined(other parallel libs)//03~04.3012. WW - else - { - m_dom = dom_vector[rank]; + else + { + m_dom = dom_vector[rank]; #ifdef NEW_EQS - if(type == 4 ) - eqs_rhs = m_dom->eqsH->b; - else - eqs_rhs = m_dom->eqs->b; + if (type == 4) + eqs_rhs = m_dom->eqsH->b; + else + eqs_rhs = m_dom->eqs->b; #else eqs_rhs = m_dom->eqs->b; #endif - if (rank == 0) - begin = 0; - else - begin = rank_st_node_value_in_dom[rank - 1]; - end = rank_st_node_value_in_dom[rank]; - } -#endif //END: #if !defined(USE_PETSC) // && !defined(other parallel libs) - - for (i = begin; i < end; i++) - { + if (rank == 0) + begin = 0; + else + begin = rank_st_node_value_in_dom[rank - 1]; + end = rank_st_node_value_in_dom[rank]; + } +#endif // END: #if !defined(USE_PETSC) // && !defined(other parallel libs) - gindex = i; + for (i = begin; i < end; i++) + { + gindex = i; #if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW - if (rank > -1) - gindex = st_node_value_in_dom[i]; + if (rank > -1) + gindex = st_node_value_in_dom[i]; #endif - cnodev = st_node_value[gindex]; + cnodev = st_node_value[gindex]; - // MW Recharge applied at GW Surface (p>0), tested only with LIQUID_FLOW or RICHARDS_FLOW and mmp $PERMEABILITY_SATURATION = 10 - if(cnodev->getProcessDistributionType()==FiniteElement::RECHARGE - || cnodev->getProcessDistributionType()==FiniteElement::RECHARGE_DIRECT) - { - cnodev->msh_node_number = getFirstNodeBelowGWL(cnodev->msh_node_number); - cnodev->geo_node_number = cnodev->msh_node_number; - } + // MW Recharge applied at GW Surface (p>0), tested only with LIQUID_FLOW or RICHARDS_FLOW and mmp + // $PERMEABILITY_SATURATION = 10 + if (cnodev->getProcessDistributionType() == FiniteElement::RECHARGE + || cnodev->getProcessDistributionType() == FiniteElement::RECHARGE_DIRECT) + { + cnodev->msh_node_number = getFirstNodeBelowGWL(cnodev->msh_node_number); + cnodev->geo_node_number = cnodev->msh_node_number; + } #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - msh_node = cnodev->geo_node_number; - // Check whether the node is in this subdomain - const long id_act_l_max = m_msh->getNumNodesLocal(); - const long id_h = static_cast( m_msh->GetNodesNumber(false) ); - const long id_act_h_max = static_cast( m_msh->getLargestActiveNodeID_Quadratic() ); - - // If ghost node - if( !( (msh_node < id_act_l_max) || - ( (msh_node >= id_h) && (msh_node < id_act_h_max)) ) ) - continue; - - int dof_per_node = 0; - if (m_msh->NodesNumber_Linear == m_msh->NodesNumber_Quadratic) - { + msh_node = cnodev->geo_node_number; + // Check whether the node is in this subdomain + const long id_act_l_max = m_msh->getNumNodesLocal(); + const long id_h = static_cast(m_msh->GetNodesNumber(false)); + const long id_act_h_max = static_cast(m_msh->getLargestActiveNodeID_Quadratic()); + + // If ghost node + if (!((msh_node < id_act_l_max) || ((msh_node >= id_h) && (msh_node < id_act_h_max)))) + continue; + + int dof_per_node = 0; + if (m_msh->NodesNumber_Linear == m_msh->NodesNumber_Quadratic) + { + dof_per_node = pcs_number_of_primary_nvals; + shift = cnodev->msh_node_number / m_msh->NodesNumber_Linear; + } + else + { + if (msh_node < static_cast(m_msh->NodesNumber_Linear)) dof_per_node = pcs_number_of_primary_nvals; - shift = cnodev->msh_node_number / m_msh->NodesNumber_Linear; + else + dof_per_node = m_msh->GetCoordinateFlag() / 10; + if (type == 4 || type / 10 == 4) + { + shift = cnodev->msh_node_number / m_msh->NodesNumber_Quadratic; } else { - if(msh_node < static_cast(m_msh->NodesNumber_Linear)) - dof_per_node = pcs_number_of_primary_nvals; - else - dof_per_node = m_msh->GetCoordinateFlag() / 10; - if(type == 4 || type / 10 == 4) - { - shift = cnodev->msh_node_number / m_msh->NodesNumber_Quadratic; - } - else - { - shift = cnodev->msh_node_number / m_msh->NodesNumber_Linear; - } + shift = cnodev->msh_node_number / m_msh->NodesNumber_Linear; } + } #else - shift = cnodev->msh_node_number - cnodev->geo_node_number; - if (rank > -1) - { - msh_node = st_local_index_in_dom[i]; + shift = cnodev->msh_node_number - cnodev->geo_node_number; + if (rank > -1) + { + msh_node = st_local_index_in_dom[i]; + dim_space = 0; + if (m_msh->NodesNumber_Linear == m_msh->NodesNumber_Quadratic) dim_space = 0; - if (m_msh->NodesNumber_Linear == m_msh->NodesNumber_Quadratic) - dim_space = 0; - else - { - if (shift % m_msh->NodesNumber_Quadratic == 0) - dim_space = shift / m_msh->NodesNumber_Quadratic; - else - dim_space = m_msh->msh_max_dim; - } - shift = m_dom->shift[dim_space]; - } else { - msh_node = cnodev->msh_node_number; - msh_node -= shift; + if (shift % m_msh->NodesNumber_Quadratic == 0) + dim_space = shift / m_msh->NodesNumber_Quadratic; + else + dim_space = m_msh->msh_max_dim; } + shift = m_dom->shift[dim_space]; + } + else + { + msh_node = cnodev->msh_node_number; + msh_node -= shift; + } #endif - value = cnodev->node_value; - //-------------------------------------------------------------------- - // Tests - if (msh_node < 0) - continue; - m_st = NULL; - if (st_node.size() > 0 && (long) st_node.size() > i) + value = cnodev->node_value; + //-------------------------------------------------------------------- + // Tests + if (msh_node < 0) + continue; + m_st = NULL; + if (st_node.size() > 0 && (long)st_node.size() > i) + { + m_st = st_node[gindex]; + + if (m_st->isConstrainedST()) { - m_st = st_node[gindex]; + bool continue_bool(false); + continue_bool = checkConstrainedST(st_vector, *m_st, *cnodev); - if (m_st->isConstrainedST()) + for (std::size_t temp_i(0); temp_i < m_st->getNumberOfConstrainedSTs(); temp_i++) { - bool continue_bool(false); - continue_bool = checkConstrainedST(st_vector, *m_st, *cnodev); - - for (std::size_t temp_i(0); temp_i < m_st->getNumberOfConstrainedSTs(); temp_i++) + if (st_vector[cnodev->getSTVectorGroup()]->isCompleteConstrainST(temp_i) + && st_vector[cnodev->getSTVectorGroup()]->getCompleteConstrainedSTStateOff(temp_i)) { - if (st_vector[cnodev->getSTVectorGroup()]->isCompleteConstrainST(temp_i) - && st_vector[cnodev->getSTVectorGroup()]->getCompleteConstrainedSTStateOff(temp_i)) - { - continue_bool = true; - break; - } + continue_bool = true; + break; } - - if (continue_bool) - continue; } - //-------------------------------------------------------------------- - // CPL - //if(m_st->_pcs_type_name_cond.size()>0) continue; // this is a CPL source term, JOD removed - //-------------------------------------------------------------------- - // system dependent YD - if (cnodev->getProcessDistributionType() == - FiniteElement::SYSTEM_DEPENDENT) + if (continue_bool) + continue; + } + + //-------------------------------------------------------------------- + // CPL + // if(m_st->_pcs_type_name_cond.size()>0) continue; // this is a CPL source term, JOD removed + //-------------------------------------------------------------------- + // system dependent YD + if (cnodev->getProcessDistributionType() == FiniteElement::SYSTEM_DEPENDENT) + { + long no_st_ele = (long)m_st->element_st_vector.size(); + for (long i_st = 0; i_st < no_st_ele; i_st++) { - long no_st_ele = (long) m_st->element_st_vector.size(); - for (long i_st = 0; i_st < no_st_ele; i_st++) + long ele_index = m_st->element_st_vector[i_st]; + elem = m_msh->ele_vector[ele_index]; + if (elem->GetMark()) { - long ele_index = m_st->element_st_vector[i_st]; - elem = m_msh->ele_vector[ele_index]; - if (elem->GetMark()) - { - fem->ConfigElement(elem, m_num->ele_gauss_points); - if(getProcessType() == FiniteElement::MULTI_COMPONENTIAL_FLOW) fem->Cal_VelocityMCF(); - else + fem->ConfigElement(elem, m_num->ele_gauss_points); + if (getProcessType() == FiniteElement::MULTI_COMPONENTIAL_FLOW) + fem->Cal_VelocityMCF(); + else fem->Cal_Velocity(); - } - gp_ele = ele_gp_value[ele_index]; - gp_ele->GetEleVelocity(vel); - EleType = elem->GetElementType(); - if (EleType == MshElemType::LINE) //Line - cnodev->node_value += vel[0]; - //Traingle & Qua - if (EleType == MshElemType::TRIANGLE || EleType == - MshElemType::QUAD) + } + gp_ele = ele_gp_value[ele_index]; + gp_ele->GetEleVelocity(vel); + EleType = elem->GetElementType(); + if (EleType == MshElemType::LINE) // Line + cnodev->node_value += vel[0]; + // Traingle & Qua + if (EleType == MshElemType::TRIANGLE || EleType == MshElemType::QUAD) + { + for (size_t i_face = 0; i_face < m_msh->face_vector.size(); i_face++) { - for (size_t i_face = 0; - i_face < m_msh->face_vector.size(); - i_face++) - { - face = m_msh->face_vector[i_face]; - if ((size_t) m_st-> - element_st_vector[i_st] == - face->GetOwner()->GetIndex()) - // - q_face = PointProduction( - vel, - m_msh->face_normal[ - i_face]) - * face->GetVolume(); - //for(i_node) - } - cnodev->node_value = +q_face / 2; + face = m_msh->face_vector[i_face]; + if ((size_t)m_st->element_st_vector[i_st] == face->GetOwner()->GetIndex()) + // + q_face = PointProduction(vel, m_msh->face_normal[i_face]) * face->GetVolume(); + // for(i_node) } + cnodev->node_value = +q_face / 2; } } - //-------------------------------------------------------------------- - // MB - //if(m_st->conditional && !m_st->river) - //{ - - GetNODValue(value, cnodev, m_st); - } // st_node.size()>0&&(long)st_node.size()>i - //---------------------------------------------------------------------------------------- + } //-------------------------------------------------------------------- - // Please do not move the this section - curve = cnodev->CurveIndex; - if (curve > 0) - { - //Reading Time interpolation method; BG - if (m_st != NULL) // in some cases the m_st is not defined -> interp_method is not changed for this cases - if (interp_method != m_st->TimeInterpolation) - interp_method = m_st->TimeInterpolation; + // MB + // if(m_st->conditional && !m_st->river) + //{ - time_fac = GetCurveValue(curve, interp_method, aktuelle_zeit, - &valid); - //cout << "step: " << this->Tim->step_current << " Time: " << aktuelle_zeit << " Laenge: " << this->Tim->this_stepsize << " Beginn: " << this->Tim->time_start << " Ende " << this->Tim->time_end << " Faktor: " << time_fac << "\n"; - if (!valid) - { - cout << - "\n!!! Time dependent curve is not found. Results are not guaranteed " - << "\n"; - cout << - " in void CRFProcess::IncorporateSourceTerms(const double Scaling)" - << "\n"; - time_fac = 1.0; - } - } - else + GetNODValue(value, cnodev, m_st); + } // st_node.size()>0&&(long)st_node.size()>i + //---------------------------------------------------------------------------------------- + //-------------------------------------------------------------------- + // Please do not move the this section + curve = cnodev->CurveIndex; + if (curve > 0) + { + // Reading Time interpolation method; BG + if (m_st != NULL) // in some cases the m_st is not defined -> interp_method is not changed for this cases + if (interp_method != m_st->TimeInterpolation) + interp_method = m_st->TimeInterpolation; + + time_fac = GetCurveValue(curve, interp_method, aktuelle_zeit, &valid); + // cout << "step: " << this->Tim->step_current << " Time: " << aktuelle_zeit << " Laenge: " << + // this->Tim->this_stepsize << " Beginn: " << this->Tim->time_start << " Ende " << this->Tim->time_end << " + // Faktor: " << time_fac << "\n"; + if (!valid) + { + cout << "\n!!! Time dependent curve is not found. Results are not guaranteed " + << "\n"; + cout << " in void CRFProcess::IncorporateSourceTerms(const double Scaling)" + << "\n"; time_fac = 1.0; + } + } + else + time_fac = 1.0; - // Time dependencies - FCT //YD - if (m_st) //WW + // Time dependencies - FCT //YD + if (m_st) // WW + { + // WW/YD //OK + if (m_msh && m_msh->geo_name.find("LOCAL") != string::npos) { - //WW/YD //OK - if (m_msh && m_msh->geo_name.find("LOCAL") != string::npos) - { - if (m_st->getFunctionName().length() > 0) - { - m_fct = FCTGet(pcs_number); - if (m_fct) - time_fac = m_fct->GetValue( - aktuelle_zeit, - &is_valid, - m_st-> - getFunctionMethod()); //fct_method. WW - else - cout << - "Warning in CRFProcess::IncorporateSourceTerms - no FCT data" - << "\n"; - } - } - else if (m_st->getFunctionName().length() > 0) + if (m_st->getFunctionName().length() > 0) { - m_fct = FCTGet(m_st->getFunctionName()); + m_fct = FCTGet(pcs_number); if (m_fct) - time_fac = m_fct->GetValue(aktuelle_zeit, &is_valid); + time_fac = m_fct->GetValue(aktuelle_zeit, + &is_valid, + m_st->getFunctionMethod()); // fct_method. WW else - cout << - "Warning in CRFProcess::IncorporateSourceTerms - no FCT data" + cout << "Warning in CRFProcess::IncorporateSourceTerms - no FCT data" << "\n"; } } - //---------------------------------------------------------------------------------------- - value *= time_fac * fac; - //------------------------------------------------------------------ - // EQS->RHS + else if (m_st->getFunctionName().length() > 0) + { + m_fct = FCTGet(m_st->getFunctionName()); + if (m_fct) + time_fac = m_fct->GetValue(aktuelle_zeit, &is_valid); + else + cout << "Warning in CRFProcess::IncorporateSourceTerms - no FCT data" + << "\n"; + } + } + //---------------------------------------------------------------------------------------- + value *= time_fac * fac; +//------------------------------------------------------------------ +// EQS->RHS #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - st_eqs_id.push_back(static_cast(m_msh->nod_vector[msh_node]->GetEquationIndex() * dof_per_node + shift)); - st_eqs_value.push_back(value); + st_eqs_id.push_back(static_cast(m_msh->nod_vector[msh_node]->GetEquationIndex() * dof_per_node + shift)); + st_eqs_value.push_back(value); #else - if (rank > -1) - bc_eqs_index = msh_node + shift; - else - bc_eqs_index = m_msh->nod_vector[msh_node]->GetEquationIndex() + - shift; - eqs_rhs[bc_eqs_index] += value; + if (rank > -1) + bc_eqs_index = msh_node + shift; + else + bc_eqs_index = m_msh->nod_vector[msh_node]->GetEquationIndex() + shift; + eqs_rhs[bc_eqs_index] += value; #endif - } - //==================================================================== - - // if coupling to GEMS exist---------------------------------------------------- - // HS, added 11.2008 - // KG44 03/03/2010 modified to hopefully soon work with parallel solvers - long gem_node_index = -1, glocalindex = -1; - if (flag_couple_GEMS == 1 && aktueller_zeitschritt > 1) - { + } + //==================================================================== - begin = 0; - if (rank == -1) // serial version and also Version for PETSC!! + // if coupling to GEMS exist---------------------------------------------------- + // HS, added 11.2008 + // KG44 03/03/2010 modified to hopefully soon work with parallel solvers + long gem_node_index = -1, glocalindex = -1; + if (flag_couple_GEMS == 1 && aktueller_zeitschritt > 1) + { + begin = 0; + if (rank == -1) // serial version and also Version for PETSC!! - end = (long ) Water_ST_vec.size(); - else // parallel version - { - end = 0; - if (rank_stgem_node_value_in_dom.size() > 0) - end = rank_stgem_node_value_in_dom[0]; - } - // only when switch is on and not in the first time step - // loop over the Water_ST_vec vector, - // add the excess water to the right-hand-side of the equation - for (i = begin; i < end; i++) + end = (long)Water_ST_vec.size(); + else // parallel version + { + end = 0; + if (rank_stgem_node_value_in_dom.size() > 0) + end = rank_stgem_node_value_in_dom[0]; + } + // only when switch is on and not in the first time step + // loop over the Water_ST_vec vector, + // add the excess water to the right-hand-side of the equation + for (i = begin; i < end; i++) + { + if (rank > -1) // parallel version: stgem_node_value_in_dom and stgem_local_index_in_dom contain only values + // for the corresponding domain == rank { - if (rank > -1) // parallel version: stgem_node_value_in_dom and stgem_local_index_in_dom contain only values for the corresponding domain == rank - { - // cout << "rank " << rank ; - gindex = stgem_node_value_in_dom[i]; //contains indexes to water-st_vec - // cout << " gindex " << gindex << " i " << i << endl ; - // contains index to node - glocalindex = stgem_local_index_in_dom[i]; - // cout << " gem_node_index " << gem_node_index << "\n"; + // cout << "rank " << rank ; + gindex = stgem_node_value_in_dom[i]; // contains indexes to water-st_vec + // cout << " gindex " << gindex << " i " << i << endl ; + // contains index to node + glocalindex = stgem_local_index_in_dom[i]; +// cout << " gem_node_index " << gem_node_index << "\n"; #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - st_eqs_id.push_back(static_cast(m_msh->nod_vector[glocalindex]->GetEquationIndex())); - st_eqs_value.push_back(Water_ST_vec[gindex].water_st_value); + st_eqs_id.push_back(static_cast(m_msh->nod_vector[glocalindex]->GetEquationIndex())); + st_eqs_value.push_back(Water_ST_vec[gindex].water_st_value); #else - eqs_rhs[glocalindex] += Water_ST_vec[gindex].water_st_value; + eqs_rhs[glocalindex] += Water_ST_vec[gindex].water_st_value; #endif - } - else // serial version - { - gem_node_index = Water_ST_vec[i].index_node; + } + else // serial version + { + gem_node_index = Water_ST_vec[i].index_node; #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - st_eqs_id.push_back(static_cast(m_msh->nod_vector[gem_node_index]->GetEquationIndex())); - st_eqs_value.push_back(Water_ST_vec[i].water_st_value); + st_eqs_id.push_back(static_cast(m_msh->nod_vector[gem_node_index]->GetEquationIndex())); + st_eqs_value.push_back(Water_ST_vec[i].water_st_value); #else - eqs_rhs[gem_node_index] += Water_ST_vec[i].water_st_value; + eqs_rhs[gem_node_index] += Water_ST_vec[i].water_st_value; #endif - } - } - // after finished adding to RHS, clear the vector - Water_ST_vec.clear(); - if (rank > -1) - { - stgem_node_value_in_dom.clear(); - stgem_local_index_in_dom.clear(); - rank_stgem_node_value_in_dom.clear(); } } + // after finished adding to RHS, clear the vector + Water_ST_vec.clear(); + if (rank > -1) + { + stgem_node_value_in_dom.clear(); + stgem_local_index_in_dom.clear(); + rank_stgem_node_value_in_dom.clear(); + } + } #if defined(USE_PETSC) // || defined(other parallel libs)//03~04.3012. WW - if(st_eqs_id.size()>0) - { - eqs_new->setArrayValues(1, static_cast(st_eqs_id.size()), - &st_eqs_id[0], &st_eqs_value[0]); - //eqs_new->AssembleRHS_PETSc(); - } -#endif + if (st_eqs_id.size() > 0) + { + eqs_new->setArrayValues(1, static_cast(st_eqs_id.size()), &st_eqs_id[0], &st_eqs_value[0]); + // eqs_new->AssembleRHS_PETSc(); } +#endif +} -#if !defined(USE_PETSC) && !defined(NEW_EQS)// || defined(other parallel libs)//03~04.3012. +#if !defined(USE_PETSC) && !defined(NEW_EQS) // || defined(other parallel libs)//03~04.3012. /************************************************************************** FEMLib-Method: Task: @@ -8276,68 +8146,66 @@ double CRFProcess::evaluteSwitchBC(CBoundaryCondition const & bc, CBoundaryCondi 07/2006 WW Parallel BiCGStab last modification: **************************************************************************/ - int CRFProcess::ExecuteLinearSolver(void) - { - long iter_count = 0; - long iter_sum = 0; - //WW int found = 0; - //----------------------------------------------------------------------- - // Set EQS - //cout << "Before SetLinearSolver(eqs) myrank = "<< myrank<< '\n'; - SetLinearSolver(eqs); - //-------------------------------------------------------------------- - // NUM - //WW found = 1; - cg_maxiter = m_num->ls_max_iterations; //OK lsp->maxiter; - cg_eps = m_num->ls_error_tolerance; //OK lsp->eps; - //cg_repeat = lsp->repeat; - vorkond = m_num->ls_precond; //OK lsp->precond; - linear_error_type = m_num->ls_error_method; //OK lsp->criterium; +int CRFProcess::ExecuteLinearSolver(void) +{ + long iter_count = 0; + long iter_sum = 0; + // WW int found = 0; + //----------------------------------------------------------------------- + // Set EQS + // cout << "Before SetLinearSolver(eqs) myrank = "<< myrank<< '\n'; + SetLinearSolver(eqs); + //-------------------------------------------------------------------- + // NUM + // WW found = 1; + cg_maxiter = m_num->ls_max_iterations; // OK lsp->maxiter; + cg_eps = m_num->ls_error_tolerance; // OK lsp->eps; + // cg_repeat = lsp->repeat; + vorkond = m_num->ls_precond; // OK lsp->precond; + linear_error_type = m_num->ls_error_method; // OK lsp->criterium; - // cout << "Before eqs->LinearSolver(eqs) myrank = "<< myrank<< '\n'; +// cout << "Before eqs->LinearSolver(eqs) myrank = "<< myrank<< '\n'; #ifdef USE_MPI - //WW - long dim_eqs = 0; - if(type == 41 || type == 4) // DOF >1 - { - dom_vector[myrank]->quadratic = true; - if(type == 4) - dim_eqs = pcs_number_of_primary_nvals * m_msh->GetNodesNumber(true); - else if(type == 41) - dim_eqs = pcs_number_of_primary_nvals * m_msh->GetNodesNumber(true) - + m_msh->GetNodesNumber(false); - } - else - { - dom_vector[myrank]->quadratic = false; - dim_eqs = m_msh->GetNodesNumber(false); - } - iter_count = SpBICGSTAB_Parallel(dom_vector[myrank], eqs->x, dim_eqs); + // WW + long dim_eqs = 0; + if (type == 41 || type == 4) // DOF >1 + { + dom_vector[myrank]->quadratic = true; + if (type == 4) + dim_eqs = pcs_number_of_primary_nvals * m_msh->GetNodesNumber(true); + else if (type == 41) + dim_eqs = pcs_number_of_primary_nvals * m_msh->GetNodesNumber(true) + m_msh->GetNodesNumber(false); + } + else + { + dom_vector[myrank]->quadratic = false; + dim_eqs = m_msh->GetNodesNumber(false); + } + iter_count = SpBICGSTAB_Parallel(dom_vector[myrank], eqs->x, dim_eqs); #else // ifdef USE_MPI - iter_count = eqs->LinearSolver(eqs->b,eqs->x,eqs->dim); + iter_count = eqs->LinearSolver(eqs->b, eqs->x, eqs->dim); #endif - eqs->master_iter = iter_count; - if(iter_count >= cg_maxiter) - { - cout << - "Warning in CRFProcess::ExecuteLinearSolver() - Maximum iteration number reached" - << "\n"; - return -1; - } - iter_sum += iter_count; - //----------------------------------------------------------------------- - // Clean results ? - /* - for (i=0;idim;i++) - if (fabs(eqs->x[i])x[i] = 0.0; - */ - //----------------------------------------------------------------------- - return iter_sum; + eqs->master_iter = iter_count; + if (iter_count >= cg_maxiter) + { + cout << "Warning in CRFProcess::ExecuteLinearSolver() - Maximum iteration number reached" + << "\n"; + return -1; } + iter_sum += iter_count; + //----------------------------------------------------------------------- + // Clean results ? + /* + for (i=0;idim;i++) + if (fabs(eqs->x[i])x[i] = 0.0; + */ + //----------------------------------------------------------------------- + return iter_sum; +} #endif /************************************************************************** FEMLib-Method: @@ -8348,47 +8216,45 @@ double CRFProcess::evaluteSwitchBC(CBoundaryCondition const & bc, CBoundaryCondi **************************************************************************/ #if !defined(USE_PETSC) && !defined(NEW_EQS) // && defined(other parallel libs)//03~04.3012. WW //#ifndef NEW_EQS //WW 07.11.2008 - int CRFProcess::ExecuteLinearSolver(LINEAR_SOLVER* eqs) - { - long iter_count; - long iter_sum = 0; - //WW int found = 0; - //----------------------------------------------------------------------- - // Set EQS - SetLinearSolver(eqs); - //-------------------------------------------------------------------- - // NUM - //WW found = 1; - cg_maxiter = m_num->ls_max_iterations; //OK lsp->maxiter; - cg_eps = m_num->ls_error_tolerance; //OK lsp->eps; - //cg_repeat = lsp->repeat; - vorkond = m_num->ls_precond; //OK lsp->precond; - linear_error_type = m_num->ls_error_method; //OK lsp->criterium; - - iter_count = eqs->LinearSolver(eqs->b,eqs->x,eqs->dim); - eqs->master_iter = iter_count; - if(iter_count >= cg_maxiter) - { - cout << - "Warning in CRFProcess::ExecuteLinearSolver() - Maximum iteration number reached" - << "\n"; - return -1; - } - iter_sum += iter_count; - //----------------------------------------------------------------------- - return iter_sum; - } -#endif -//WW - int CRFProcess::GetNODValueIndex(const string &name,int timelevel) - { - for(int j = 0; j < number_of_nvals; j++) - if((name.compare(pcs_nval_data[j].name) == 0) && \ - (pcs_nval_data[j].timelevel == timelevel)) - return pcs_nval_data[j].nval_index; - cout << "Error in PCSGetNODValueIndex: " << name << "\n"; +int CRFProcess::ExecuteLinearSolver(LINEAR_SOLVER* eqs) +{ + long iter_count; + long iter_sum = 0; + // WW int found = 0; + //----------------------------------------------------------------------- + // Set EQS + SetLinearSolver(eqs); + //-------------------------------------------------------------------- + // NUM + // WW found = 1; + cg_maxiter = m_num->ls_max_iterations; // OK lsp->maxiter; + cg_eps = m_num->ls_error_tolerance; // OK lsp->eps; + // cg_repeat = lsp->repeat; + vorkond = m_num->ls_precond; // OK lsp->precond; + linear_error_type = m_num->ls_error_method; // OK lsp->criterium; + + iter_count = eqs->LinearSolver(eqs->b, eqs->x, eqs->dim); + eqs->master_iter = iter_count; + if (iter_count >= cg_maxiter) + { + cout << "Warning in CRFProcess::ExecuteLinearSolver() - Maximum iteration number reached" + << "\n"; return -1; } + iter_sum += iter_count; + //----------------------------------------------------------------------- + return iter_sum; +} +#endif +// WW +int CRFProcess::GetNODValueIndex(const string& name, int timelevel) +{ + for (int j = 0; j < number_of_nvals; j++) + if ((name.compare(pcs_nval_data[j].name) == 0) && (pcs_nval_data[j].timelevel == timelevel)) + return pcs_nval_data[j].nval_index; + cout << "Error in PCSGetNODValueIndex: " << name << "\n"; + return -1; +} /////////////////////////////////////////////////////////////////////////// // Specials @@ -8402,37 +8268,37 @@ double CRFProcess::evaluteSwitchBC(CBoundaryCondition const & bc, CBoundaryCondi 11/2004 OK file_name_base last modified: -------------------------------------------------------------------------*/ - void PCSRestart() - { - /*OK411 - int j; - CRFProcess *m_pcs = NULL; - int nidx0,nidx1; - int i; - int no_processes =(int)pcs_vector.size(); - if(no_processes==0) - return; //OK41 - int ok = 0; - //---------------------------------------------------------------------- - string file_name_base = pcs_vector[0]->file_name_base; - //OK ok = ReadRFRRestartData(file_name_base); - if(ok==0){ - cout << "RFR: no restart data" << "\n"; - return; - } - //---------------------------------------------------------------------- - for(i=0;iGetPrimaryVNumber();j++) { - // timelevel=0; - nidx0 = m_pcs->GetNodeValueIndex(m_pcs->GetPrimaryVName(j)); - // timelevel= 1; - nidx1 = nidx0+1; - CopyNodeVals(nidx1,nidx0); - } - } - */ - } +void PCSRestart() +{ + /*OK411 + int j; + CRFProcess *m_pcs = NULL; + int nidx0,nidx1; + int i; + int no_processes =(int)pcs_vector.size(); + if(no_processes==0) + return; //OK41 + int ok = 0; + //---------------------------------------------------------------------- + string file_name_base = pcs_vector[0]->file_name_base; + //OK ok = ReadRFRRestartData(file_name_base); + if(ok==0){ + cout << "RFR: no restart data" << "\n"; + return; + } + //---------------------------------------------------------------------- + for(i=0;iGetPrimaryVNumber();j++) { + // timelevel=0; + nidx0 = m_pcs->GetNodeValueIndex(m_pcs->GetPrimaryVName(j)); + // timelevel= 1; + nidx1 = nidx0+1; + CopyNodeVals(nidx1,nidx0); + } + } + */ +} /************************************************************************** FEMLib-Method: @@ -8441,27 +8307,27 @@ double CRFProcess::evaluteSwitchBC(CBoundaryCondition const & bc, CBoundaryCondi 09/2004 WW Implementation 10/2010 TF changes due to conversion from std::string to enum for process type **************************************************************************/ - void RelocateDeformationProcess(CRFProcess* m_pcs) +void RelocateDeformationProcess(CRFProcess* m_pcs) +{ + // string pcs_name_dm = m_pcs->_pcs_type_name; + FiniteElement::ProcessType pcs_name_dm(m_pcs->getProcessType()); + + string num_type_name_dm; + // Numerics + if (m_pcs->num_type_name.compare("STRONG_DISCONTINUITY") == 0) { - // string pcs_name_dm = m_pcs->_pcs_type_name; - FiniteElement::ProcessType pcs_name_dm (m_pcs->getProcessType()); + num_type_name_dm = m_pcs->num_type_name; + enhanced_strain_dm = 1; + } - string num_type_name_dm; - // Numerics - if(m_pcs->num_type_name.compare("STRONG_DISCONTINUITY") == 0) - { - num_type_name_dm = m_pcs->num_type_name; - enhanced_strain_dm = 1; - } + delete m_pcs; + m_pcs = dynamic_cast(new CRFProcessDeformation()); + m_pcs->setProcessType(pcs_name_dm); - delete m_pcs; - m_pcs = dynamic_cast (new CRFProcessDeformation()); - m_pcs->setProcessType (pcs_name_dm); - - if(enhanced_strain_dm == 1) - m_pcs->num_type_name = num_type_name_dm; - pcs_deformation = 1; - } + if (enhanced_strain_dm == 1) + m_pcs->num_type_name = num_type_name_dm; + pcs_deformation = 1; +} /************************************************************************* ROCKFLOW - Function: CRFProcess::PCSMoveNOD @@ -8470,18 +8336,18 @@ double CRFProcess::evaluteSwitchBC(CBoundaryCondition const & bc, CBoundaryCondi 08/2004 MB/OK Implementation last modified: **************************************************************************/ - void CRFProcess::PCSMoveNOD(void) +void CRFProcess::PCSMoveNOD(void) +{ + switch (this->type) { - switch(this->type) - { case 1: MSHMoveNODUcFlow(this); break; default: DisplayMsgLn("PCSMoveNOD: no valid process"); abort(); - } } +} /************************************************************************** FEMLib-Method: @@ -8490,15 +8356,15 @@ double CRFProcess::evaluteSwitchBC(CBoundaryCondition const & bc, CBoundaryCondi 09/2004 OK Implementation 10/2004 OK 2nd version **************************************************************************/ - std::string PCSProblemType() - { - std::string pcs_problem_type; - size_t no_processes(pcs_vector.size()); +std::string PCSProblemType() +{ + std::string pcs_problem_type; + size_t no_processes(pcs_vector.size()); - for (size_t i = 0; i < no_processes; i++) + for (size_t i = 0; i < no_processes; i++) + { + switch (pcs_vector[i]->getProcessType()) { - switch (pcs_vector[i]->getProcessType()) - { case FiniteElement::LIQUID_FLOW: pcs_problem_type = "LIQUID_FLOW"; break; @@ -8511,7 +8377,7 @@ double CRFProcess::evaluteSwitchBC(CBoundaryCondition const & bc, CBoundaryCondi case FiniteElement::TWO_PHASE_FLOW: pcs_problem_type = "TWO_PHASE_FLOW"; break; - case FiniteElement::RICHARDS_FLOW: //MX test 04.2005 + case FiniteElement::RICHARDS_FLOW: // MX test 04.2005 pcs_problem_type = "RICHARDS_FLOW"; break; case FiniteElement::DEFORMATION: @@ -8552,106 +8418,107 @@ double CRFProcess::evaluteSwitchBC(CBoundaryCondition const & bc, CBoundaryCondi break; default: pcs_problem_type = ""; - } } + } - // //---------------------------------------------------------------------- - // CRFProcess* m_pcs = NULL; - // // H process - // for (i = 0; i < no_processes; i++) { - // m_pcs = pcs_vector[i]; - // switch (m_pcs->pcs_type_name[0]) { - // case 'L': - // pcs_problem_type = "LIQUID_FLOW"; - // break; - // // case 'U': - // // pcs_problem_type = "UNCONFINED_FLOW"; - // // break; - // case 'O': - // pcs_problem_type = "OVERLAND_FLOW"; - // break; - // case 'G': - // pcs_problem_type = "GROUNDWATER_FLOW"; - // break; - // case 'T': - // pcs_problem_type = "TWO_PHASE_FLOW"; - // break; - // case 'C': - // pcs_problem_type = "COMPONENTAL_FLOW"; - // break; - // case 'R': //MX test 04.2005 - // pcs_problem_type = "RICHARDS_FLOW"; - // break; - // } - // } - // //---------------------------------------------------------------------- - // // M process - // for (i = 0; i < no_processes; i++) { - // m_pcs = pcs_vector[i]; - // switch (m_pcs->pcs_type_name[0]) { - // case 'D': - // if (pcs_problem_type.empty()) - // pcs_problem_type = "DEFORMATION"; - // else - // pcs_problem_type += "+DEFORMATION"; - // break; - // } - // } - // //---------------------------------------------------------------------- - // // T process - // for (i = 0; i < no_processes; i++) { - // m_pcs = pcs_vector[i]; - // switch (m_pcs->pcs_type_name[0]) { - // case 'H': - // if (pcs_problem_type.empty()) - // pcs_problem_type = "HEAT_TRANSPORT"; - // else - // pcs_problem_type += "+HEAT_TRANSPORT"; - // break; - // } - // } - // //---------------------------------------------------------------------- - // // CB process - // for (i = 0; i < no_processes; i++) { - // m_pcs = pcs_vector[i]; - // switch (m_pcs->pcs_type_name[0]) { - // case 'M': - // if (pcs_problem_type.empty()) - // pcs_problem_type = "MASS_TRANSPORT"; - // else - // pcs_problem_type += "+MASS_TRANSPORT"; - // break; - // } - // } - // //---------------------------------------------------------------------- - // //---------------------------------------------------------------------- - // // FM process - // for (i = 0; i < no_processes; i++) { - // m_pcs = pcs_vector[i]; - // switch (m_pcs->pcs_type_name[0]) { - // case 'F': - // if (pcs_problem_type.empty()) - // pcs_problem_type = "FLUID_MOMENTUM"; - // else - // pcs_problem_type += "+FLUID_MOMENTUM"; - // break; - // } - // } - // //---------------------------------------------------------------------- - // for (i = 0; i < no_processes; i++) { - // m_pcs = pcs_vector[i]; - // switch (m_pcs->pcs_type_name[7]) { // _pcs_type_name[7] should be 'W' because 'R' is reserved for Richard Flow. - // case 'W': - // if (pcs_problem_type.empty()) - // pcs_problem_type = "RANDOM_WALK"; - // else - // pcs_problem_type += "+RANDOM_WALK"; - // break; - // } - // } + // //---------------------------------------------------------------------- + // CRFProcess* m_pcs = NULL; + // // H process + // for (i = 0; i < no_processes; i++) { + // m_pcs = pcs_vector[i]; + // switch (m_pcs->pcs_type_name[0]) { + // case 'L': + // pcs_problem_type = "LIQUID_FLOW"; + // break; + // // case 'U': + // // pcs_problem_type = "UNCONFINED_FLOW"; + // // break; + // case 'O': + // pcs_problem_type = "OVERLAND_FLOW"; + // break; + // case 'G': + // pcs_problem_type = "GROUNDWATER_FLOW"; + // break; + // case 'T': + // pcs_problem_type = "TWO_PHASE_FLOW"; + // break; + // case 'C': + // pcs_problem_type = "COMPONENTAL_FLOW"; + // break; + // case 'R': //MX test 04.2005 + // pcs_problem_type = "RICHARDS_FLOW"; + // break; + // } + // } + // //---------------------------------------------------------------------- + // // M process + // for (i = 0; i < no_processes; i++) { + // m_pcs = pcs_vector[i]; + // switch (m_pcs->pcs_type_name[0]) { + // case 'D': + // if (pcs_problem_type.empty()) + // pcs_problem_type = "DEFORMATION"; + // else + // pcs_problem_type += "+DEFORMATION"; + // break; + // } + // } + // //---------------------------------------------------------------------- + // // T process + // for (i = 0; i < no_processes; i++) { + // m_pcs = pcs_vector[i]; + // switch (m_pcs->pcs_type_name[0]) { + // case 'H': + // if (pcs_problem_type.empty()) + // pcs_problem_type = "HEAT_TRANSPORT"; + // else + // pcs_problem_type += "+HEAT_TRANSPORT"; + // break; + // } + // } + // //---------------------------------------------------------------------- + // // CB process + // for (i = 0; i < no_processes; i++) { + // m_pcs = pcs_vector[i]; + // switch (m_pcs->pcs_type_name[0]) { + // case 'M': + // if (pcs_problem_type.empty()) + // pcs_problem_type = "MASS_TRANSPORT"; + // else + // pcs_problem_type += "+MASS_TRANSPORT"; + // break; + // } + // } + // //---------------------------------------------------------------------- + // //---------------------------------------------------------------------- + // // FM process + // for (i = 0; i < no_processes; i++) { + // m_pcs = pcs_vector[i]; + // switch (m_pcs->pcs_type_name[0]) { + // case 'F': + // if (pcs_problem_type.empty()) + // pcs_problem_type = "FLUID_MOMENTUM"; + // else + // pcs_problem_type += "+FLUID_MOMENTUM"; + // break; + // } + // } + // //---------------------------------------------------------------------- + // for (i = 0; i < no_processes; i++) { + // m_pcs = pcs_vector[i]; + // switch (m_pcs->pcs_type_name[7]) { // _pcs_type_name[7] should be 'W' because 'R' is reserved for Richard + // Flow. + // case 'W': + // if (pcs_problem_type.empty()) + // pcs_problem_type = "RANDOM_WALK"; + // else + // pcs_problem_type += "+RANDOM_WALK"; + // break; + // } + // } - return pcs_problem_type; - } + return pcs_problem_type; +} /************************************************************************** FEMLib-Method: @@ -8659,48 +8526,48 @@ double CRFProcess::evaluteSwitchBC(CBoundaryCondition const & bc, CBoundaryCondi Programing: 11/2004 OK Implementation **************************************************************************/ - //void CRFProcess::CalcELEMassFluxes(void) - //{ - /*OK411 - int i; - double e_value = -1.0; - string e_value_name; - double geo_factor, density; - double velocity = 0.0; - int e_idx; - int phase = 0; - long e; - CMediumProperties* m_mmp = NULL; - CFluidProperties* m_mfp = NULL; - m_mfp = mfp_vector[phase]; //OK ToDo - //====================================================================== - for(e=0;egeo_area; - density = m_mfp->Density(); - for(i=0;igeo_area; + density = m_mfp->Density(); + for(i=0;i0) + if (aktueller_zeitschritt > 0) CalcSecondaryVariablesLiquidFlow(); break; case FiniteElement::GROUNDWATER_FLOW: break; case FiniteElement::TWO_PHASE_FLOW: break; - case FiniteElement::RICHARDS_FLOW: // Richards flow + case FiniteElement::RICHARDS_FLOW: // Richards flow // WW CalcSecondaryVariablesUnsaturatedFlow(initial); break; case FiniteElement::DEFORMATION || FiniteElement::DEFORMATION_FLOW || FiniteElement::DEFORMATION_DYNAMIC: - if (type == 42) //H2M //WW + if (type == 42) // H2M //WW CalcSecondaryVariablesUnsaturatedFlow(initial); break; case FiniteElement::PS_GLOBAL: - CalcSecondaryVariablesPSGLOBAL(); //WW + CalcSecondaryVariablesPSGLOBAL(); // WW break; default: if (type == 1212) - //WW + // WW CalcSecondaryVariablesUnsaturatedFlow(initial); break; - } } - +} ////////////////////////////////////////////////////////////////////////// // ReMove site @@ -8793,32 +8659,30 @@ double CRFProcess::evaluteSwitchBC(CBoundaryCondition const & bc, CBoundaryCondi input: datafield_n[j].name wenn dar Name "CONCENTRATIONx" ist, wird er durch den enstprechenden Komponentennamen ersetzt, sonst bleibts */ - char* GetCompNamehelp(char* inname) +char* GetCompNamehelp(char* inname) +{ + int comp; // WW, phase; + char *outname, help[MAX_ZEILE]; + CRFProcess* m_pcs = NULL; + outname = inname; + // WW phase = 0; + for (comp = 0; comp < GetRFProcessNumComponents(); comp++) { - int comp; //WW, phase; - char* outname, help[MAX_ZEILE]; - CRFProcess* m_pcs = NULL; - outname = inname; - //WW phase = 0; - for(comp = 0; comp < GetRFProcessNumComponents(); comp++) + sprintf(help, "%s%d", "CONCENTRATION", comp + 1); + /* help has to be a part of inname (strstr) and also have the same length (strcmp) */ + if (strstr(inname, help) && (strcmp(inname, help) == 0)) { - sprintf(help,"%s%d","CONCENTRATION",comp + 1); - /* help has to be a part of inname (strstr) and also have the same length (strcmp) */ - if(strstr(inname, help) && (strcmp(inname,help) == 0)) - { - m_pcs = m_pcs->GetProcessByFunctionName(help); - if(m_pcs == NULL) - break; - // outname = GetTracerCompName(phase,m_pcs->GetProcessComponentNumber()-1); - // outname = cp_vec[m_pcs->GetProcessComponentNumber()-1]->compname; - outname = - (char*) cp_vec[m_pcs->GetProcessComponentNumber() - - 1]->compname.data(); - return outname; - } + m_pcs = m_pcs->GetProcessByFunctionName(help); + if (m_pcs == NULL) + break; + // outname = GetTracerCompName(phase,m_pcs->GetProcessComponentNumber()-1); + // outname = cp_vec[m_pcs->GetProcessComponentNumber()-1]->compname; + outname = (char*)cp_vec[m_pcs->GetProcessComponentNumber() - 1]->compname.data(); + return outname; } - return outname; - } //SB:namepatch + } + return outname; +} // SB:namepatch /************************************************************************* ROCKFLOW - Function: GetCPNamebyPFName(string ) @@ -8828,173 +8692,184 @@ double CRFProcess::evaluteSwitchBC(CBoundaryCondition const & bc, CBoundaryCondi Programming: 10/2004 SB Implementation 10/2010 TF changed access to process type **************************************************************************/ - string GetPFNamebyCPName(string inname) - { - int i, j; //WW, k; - int pcs_vector_size = (int) pcs_vector.size(); - string outname; - char help[MAX_ZEILE]; - CRFProcess* m_pcs = NULL; - outname = "dummy"; - if(pcs_vector_size > 0) - for(i = 0; i < pcs_vector_size; i++) +string GetPFNamebyCPName(string inname) +{ + int i, j; // WW, k; + int pcs_vector_size = (int)pcs_vector.size(); + string outname; + char help[MAX_ZEILE]; + CRFProcess* m_pcs = NULL; + outname = "dummy"; + if (pcs_vector_size > 0) + for (i = 0; i < pcs_vector_size; i++) + { + m_pcs = pcs_vector[i]; + // if(m_pcs->_pcs_type_name.compare("MASS_TRANSPORT") == 0){ // if this is mass transport // TF + if (m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) { - m_pcs = pcs_vector[i]; - // if(m_pcs->_pcs_type_name.compare("MASS_TRANSPORT") == 0){ // if this is mass transport // TF - if(m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) + j = m_pcs->GetProcessComponentNumber(); + // WW k = cp_vec[j]->transport_phase; + outname = cp_vec[m_pcs->GetProcessComponentNumber()]->compname; + if (outname == inname) // right process found { - j = m_pcs->GetProcessComponentNumber(); - //WW k = cp_vec[j]->transport_phase; - outname = - cp_vec[m_pcs->GetProcessComponentNumber()]-> - compname; - if(outname == inname) //right process found - { - sprintf(help,"%s%d","CONCENTRATION",j); - outname = help; - return outname; - } + sprintf(help, "%s%d", "CONCENTRATION", j); + outname = help; + return outname; } } - // for(i=0;compGetProcessByFunctionName(help); - // if(m_pcs == NULL) break; - // outname = cp_vec[m_pcs->GetProcessComponentNumber()-1]->compname; - // outname = (char *) cp_vec[m_pcs->GetProcessComponentNumber()-1]->compname.data(); - // if(outname.compare(inname) == 0) - // return outname; - // }; - // }; - // Inname is not from a mass transport process, therefore return inname - return inname; - } //SB:namepatch + } + // for(i=0;compGetProcessByFunctionName(help); + // if(m_pcs == NULL) break; + // outname = cp_vec[m_pcs->GetProcessComponentNumber()-1]->compname; + // outname = (char *) cp_vec[m_pcs->GetProcessComponentNumber()-1]->compname.data(); + // if(outname.compare(inname) == 0) + // return outname; + // }; + // }; + // Inname is not from a mass transport process, therefore return inname + return inname; +} // SB:namepatch //======================================================================== -//OK former model functions - int GetRFControlGridAdapt(void) - { - //OK return (get_rfcp_adaptive_mesh_refinement_flag(rfcp)); - if(show_onces_adp) - cout << "GetRFControlGridAdapt - to be removed" << "\n"; - show_onces_adp = false; - return 0; - } +// OK former model functions +int GetRFControlGridAdapt(void) +{ + // OK return (get_rfcp_adaptive_mesh_refinement_flag(rfcp)); + if (show_onces_adp) + cout << "GetRFControlGridAdapt - to be removed" + << "\n"; + show_onces_adp = false; + return 0; +} - int GetRFControlModel(void) - { - if(show_onces_mod) - cout << "GetRFControlModel - to be removed" << "\n"; - show_onces_mod = false; - return -1; - } +int GetRFControlModel(void) +{ + if (show_onces_mod) + cout << "GetRFControlModel - to be removed" + << "\n"; + show_onces_mod = false; + return -1; +} - int GetRFProcessChemicalModel(void) - { - cout << "GetRFProcessChemicalModel - to be removed" << "\n"; - return 0; - } +int GetRFProcessChemicalModel(void) +{ + cout << "GetRFProcessChemicalModel - to be removed" + << "\n"; + return 0; +} - int GetRFProcessFlowModel(void) - { - if(show_onces_mod_flow) - cout << "GetRFProcessFlowModel - to be removed" << "\n"; - show_onces_mod_flow = false; - return 0; - } +int GetRFProcessFlowModel(void) +{ + if (show_onces_mod_flow) + cout << "GetRFProcessFlowModel - to be removed" + << "\n"; + show_onces_mod_flow = false; + return 0; +} - int GetRFProcessHeatReactModel(void) - { - cout << "GetRFProcessHeatReactModel - to be removed" << "\n"; - return 0; - } +int GetRFProcessHeatReactModel(void) +{ + cout << "GetRFProcessHeatReactModel - to be removed" + << "\n"; + return 0; +} - int GetRFProcessNumPhases(void) - { - //DisplayMsgLn("GetRFProcessNumPhases - to be removed"); - int no_phases = (int)mfp_vector.size(); - return no_phases; - } +int GetRFProcessNumPhases(void) +{ + // DisplayMsgLn("GetRFProcessNumPhases - to be removed"); + int no_phases = (int)mfp_vector.size(); + return no_phases; +} - int GetRFProcessProcessing(char* rfpp_type) +int GetRFProcessProcessing(char* rfpp_type) +{ + bool pcs_flow = false; + bool pcs_deform = false; + CRFProcess* m_pcs = NULL; + size_t no_processes = pcs_vector.size(); + for (size_t i = 0; i < no_processes; i++) { - bool pcs_flow = false; - bool pcs_deform = false; - CRFProcess* m_pcs = NULL; - size_t no_processes = pcs_vector.size(); - for (size_t i = 0; i < no_processes; i++) - { - m_pcs = pcs_vector[i]; - // if (m_pcs->_pcs_type_name.find("DEFORMATION") != string::npos) - if (isDeformationProcess (m_pcs->getProcessType())) - pcs_deform = true; - // if (m_pcs->_pcs_type_name.find("FLOW") != string::npos) - if (isFlowProcess (m_pcs->getProcessType())) - pcs_flow = true; - } - - if (strcmp(rfpp_type, "SD") == 0) - { - if (pcs_flow && pcs_deform) - return 1; - } - else - cout << "GetRFProcessProcessing - to be removed" << "\n"; - return 0; + m_pcs = pcs_vector[i]; + // if (m_pcs->_pcs_type_name.find("DEFORMATION") != string::npos) + if (isDeformationProcess(m_pcs->getProcessType())) + pcs_deform = true; + // if (m_pcs->_pcs_type_name.find("FLOW") != string::npos) + if (isFlowProcess(m_pcs->getProcessType())) + pcs_flow = true; } - int GetRFProcessProcessingAndActivation(const char*) + if (strcmp(rfpp_type, "SD") == 0) { - cout << "GetRFProcessProcessingAndActivation - to be removed" << "\n"; - return 0; + if (pcs_flow && pcs_deform) + return 1; } + else + cout << "GetRFProcessProcessing - to be removed" + << "\n"; + return 0; +} - long GetRFProcessNumComponents(void) - { - //DisplayMsgLn("GetRFProcessNumComponents - to be removed"); - int no_components = (int)cp_vec.size(); - return no_components; - } +int GetRFProcessProcessingAndActivation(const char*) +{ + cout << "GetRFProcessProcessingAndActivation - to be removed" + << "\n"; + return 0; +} - int GetRFControlModex(void) - { - cout << "GetRFControlModex - to be removed" << "\n"; - return 0; - } +long GetRFProcessNumComponents(void) +{ + // DisplayMsgLn("GetRFProcessNumComponents - to be removed"); + int no_components = (int)cp_vec.size(); + return no_components; +} - int GetRFProcessDensityFlow(void) - { - if(show_onces_density) - cout << "GetRFProcessDensityFlow - to be removed" << "\n"; - show_onces_density = false; - return 0; - } +int GetRFControlModex(void) +{ + cout << "GetRFControlModex - to be removed" + << "\n"; + return 0; +} - int GetRFProcessNumContinua(void) - { - cout << "GetRFProcessNumContinua - to be removed" << "\n"; - return 0; - } +int GetRFProcessDensityFlow(void) +{ + if (show_onces_density) + cout << "GetRFProcessDensityFlow - to be removed" + << "\n"; + show_onces_density = false; + return 0; +} - int GetRFProcessNumElectricFields(void) - { - cout << "GetRFProcessNumElectricFields - to be removed" << "\n"; - return 0; - } +int GetRFProcessNumContinua(void) +{ + cout << "GetRFProcessNumContinua - to be removed" + << "\n"; + return 0; +} - int GetRFProcessNumTemperatures(void) - { - cout << "GetRFProcessNumTemperatures - to be removed" << "\n"; - return -1; - } +int GetRFProcessNumElectricFields(void) +{ + cout << "GetRFProcessNumElectricFields - to be removed" + << "\n"; + return 0; +} - int GetRFProcessSimulation(void) - { - cout << "GetRFProcessSimulation - to be removed" << "\n"; - return -1; - } +int GetRFProcessNumTemperatures(void) +{ + cout << "GetRFProcessNumTemperatures - to be removed" + << "\n"; + return -1; +} + +int GetRFProcessSimulation(void) +{ + cout << "GetRFProcessSimulation - to be removed" + << "\n"; + return -1; +} /************************************************************************** ROCKFLOW - Funktion: ModelsAddNodeValInfoStructure @@ -9019,43 +8894,34 @@ double CRFProcess::evaluteSwitchBC(CBoundaryCondition const & bc, CBoundaryCondi 09/2000 CT Erste Version **************************************************************************/ - int ModelsAddNodeValInfoStructure(char* name, - char* einheit, - int speichern, - int laden, - int restart, - int adapt_interpol, - double vorgabe) - { - anz_nval++; - nval_data = (NvalInfo*) Realloc(nval_data, anz_nval * sizeof(NvalInfo)); +int ModelsAddNodeValInfoStructure(char* name, char* einheit, int speichern, int laden, int restart, int adapt_interpol, + double vorgabe) +{ + anz_nval++; + nval_data = (NvalInfo*)Realloc(nval_data, anz_nval * sizeof(NvalInfo)); - nval_data[anz_nval - 1].name = NULL; - nval_data[anz_nval - 1].einheit = NULL; + nval_data[anz_nval - 1].name = NULL; + nval_data[anz_nval - 1].einheit = NULL; - if (name) - { - nval_data[anz_nval - 1].name = (char*) Malloc(((int)strlen( - name) + - 1) * sizeof(char)); - strcpy(nval_data[anz_nval - 1].name, name); - } - if (einheit) - { - nval_data[anz_nval - 1].einheit = (char*) Malloc(((int)strlen( - einheit) + - 1) * sizeof(char)); - strcpy(nval_data[anz_nval - 1].einheit, einheit); - } + if (name) + { + nval_data[anz_nval - 1].name = (char*)Malloc(((int)strlen(name) + 1) * sizeof(char)); + strcpy(nval_data[anz_nval - 1].name, name); + } + if (einheit) + { + nval_data[anz_nval - 1].einheit = (char*)Malloc(((int)strlen(einheit) + 1) * sizeof(char)); + strcpy(nval_data[anz_nval - 1].einheit, einheit); + } - nval_data[anz_nval - 1].speichern = speichern; - nval_data[anz_nval - 1].laden = laden; - nval_data[anz_nval - 1].restart = restart; - nval_data[anz_nval - 1].adapt_interpol = adapt_interpol; - nval_data[anz_nval - 1].vorgabe = vorgabe; + nval_data[anz_nval - 1].speichern = speichern; + nval_data[anz_nval - 1].laden = laden; + nval_data[anz_nval - 1].restart = restart; + nval_data[anz_nval - 1].adapt_interpol = adapt_interpol; + nval_data[anz_nval - 1].vorgabe = vorgabe; - return anz_nval - 1; - } + return anz_nval - 1; +} /************************************************************************** ROCKFLOW - Funktion: ModelsAddElementValInfoStructure @@ -9080,43 +8946,34 @@ double CRFProcess::evaluteSwitchBC(CBoundaryCondition const & bc, CBoundaryCondi 09/2000 CT Erste Version **************************************************************************/ - int ModelsAddElementValInfoStructure(char* name, - char* einheit, - int speichern, - int laden, - int restart, - int adapt_interpol, - double vorgabe) - { - anz_eval++; - eval_data = (EvalInfo*) Realloc(eval_data, anz_eval * sizeof(EvalInfo)); +int ModelsAddElementValInfoStructure(char* name, char* einheit, int speichern, int laden, int restart, + int adapt_interpol, double vorgabe) +{ + anz_eval++; + eval_data = (EvalInfo*)Realloc(eval_data, anz_eval * sizeof(EvalInfo)); - eval_data[anz_eval - 1].name = NULL; - eval_data[anz_eval - 1].einheit = NULL; + eval_data[anz_eval - 1].name = NULL; + eval_data[anz_eval - 1].einheit = NULL; - if (name) - { - eval_data[anz_eval - 1].name = (char*) Malloc(((int)strlen( - name) + - 1) * sizeof(char)); - strcpy(eval_data[anz_eval - 1].name, name); - } - if (einheit) - { - eval_data[anz_eval - 1].einheit = (char*) Malloc(((int)strlen( - einheit) + - 1) * sizeof(char)); - strcpy(eval_data[anz_eval - 1].einheit, einheit); - } + if (name) + { + eval_data[anz_eval - 1].name = (char*)Malloc(((int)strlen(name) + 1) * sizeof(char)); + strcpy(eval_data[anz_eval - 1].name, name); + } + if (einheit) + { + eval_data[anz_eval - 1].einheit = (char*)Malloc(((int)strlen(einheit) + 1) * sizeof(char)); + strcpy(eval_data[anz_eval - 1].einheit, einheit); + } - eval_data[anz_eval - 1].speichern = speichern; - eval_data[anz_eval - 1].laden = laden; - eval_data[anz_eval - 1].restart = restart; - eval_data[anz_eval - 1].adapt_interpol = adapt_interpol; - eval_data[anz_eval - 1].vorgabe = vorgabe; + eval_data[anz_eval - 1].speichern = speichern; + eval_data[anz_eval - 1].laden = laden; + eval_data[anz_eval - 1].restart = restart; + eval_data[anz_eval - 1].adapt_interpol = adapt_interpol; + eval_data[anz_eval - 1].vorgabe = vorgabe; - return anz_eval - 1; - } + return anz_eval - 1; +} /************************************************************************** FEMLib-Method: @@ -9125,13 +8982,13 @@ double CRFProcess::evaluteSwitchBC(CBoundaryCondition const & bc, CBoundaryCondi 01/2005 OK Implementation last modified: **************************************************************************/ - void PCSDelete() - { - for(int i = 0; i < (int)pcs_vector.size(); i++) - delete pcs_vector[i]; - pcs_vector.clear(); - pcs_no_components = 0; - } +void PCSDelete() +{ + for (int i = 0; i < (int)pcs_vector.size(); i++) + delete pcs_vector[i]; + pcs_vector.clear(); + pcs_no_components = 0; +} /************************************************************************** FEMLib-Method: @@ -9140,18 +8997,19 @@ double CRFProcess::evaluteSwitchBC(CBoundaryCondition const & bc, CBoundaryCondi 03/2005 OK Implementation last modified: **************************************************************************/ - void CRFProcess::SetNodeValue(long n,int nidx,double value) - { +void CRFProcess::SetNodeValue(long n, int nidx, double value) +{ #ifdef gDEBUG - if(nidx < 0) - { - cout << " Fatal error in CRFProcess::SetNodeValue() " << "\n"; - abort(); - } -#endif - //WW 11.12.2012 nod_val_vector[n][nidx] = value; - nod_val_vector[nidx][n] = value; + if (nidx < 0) + { + cout << " Fatal error in CRFProcess::SetNodeValue() " + << "\n"; + abort(); } +#endif + // WW 11.12.2012 nod_val_vector[n][nidx] = value; + nod_val_vector[nidx][n] = value; +} /************************************************************************** FEMLib-Method: @@ -9160,17 +9018,18 @@ double CRFProcess::evaluteSwitchBC(CBoundaryCondition const & bc, CBoundaryCondi 09/2005 PCH Implementation last modified: **************************************************************************/ - void CRFProcess::SetElementValue(long n,int nidx,double value) - { +void CRFProcess::SetElementValue(long n, int nidx, double value) +{ #ifdef gDEBUG - if(nidx < 0) - { - cout << " Fatal error in CRFProcess::SetElementValue() " << "\n"; - abort(); - } -#endif - ele_val_vector[n][nidx] = value; + if (nidx < 0) + { + cout << " Fatal error in CRFProcess::SetElementValue() " + << "\n"; + abort(); } +#endif + ele_val_vector[n][nidx] = value; +} /************************************************************************** FEMLib-Method: @@ -9179,20 +9038,21 @@ double CRFProcess::evaluteSwitchBC(CBoundaryCondition const & bc, CBoundaryCondi 03/2005 OK Implementation last modified: **************************************************************************/ - double CRFProcess::GetNodeValue(size_t n,int nidx) - { - double value; +double CRFProcess::GetNodeValue(size_t n, int nidx) +{ + double value; #ifdef gDEBUG - if(nidx < 0) - { - cout << " Fatal error in CRFProcess::GetNodeValue() " << "\n"; - abort(); - } -#endif - //WW 11.12.2012 value = nod_val_vector[n][nidx]; - value = nod_val_vector[nidx][n]; - return value; + if (nidx < 0) + { + cout << " Fatal error in CRFProcess::GetNodeValue() " + << "\n"; + abort(); } +#endif + // WW 11.12.2012 value = nod_val_vector[n][nidx]; + value = nod_val_vector[nidx][n]; + return value; +} /************************************************************************** FEMLib-Method: @@ -9201,19 +9061,20 @@ double CRFProcess::evaluteSwitchBC(CBoundaryCondition const & bc, CBoundaryCondi 09/2005 PCH Implementation last modified: **************************************************************************/ - double CRFProcess::GetElementValue(size_t n,int nidx) - { - double value; +double CRFProcess::GetElementValue(size_t n, int nidx) +{ + double value; #ifdef gDEBUG - if(nidx < 0) - { - cout << " Fatal error in CRFProcess::GetElementValue() " << "\n"; - abort(); - } -#endif - value = ele_val_vector[n][nidx]; - return value; + if (nidx < 0) + { + cout << " Fatal error in CRFProcess::GetElementValue() " + << "\n"; + abort(); } +#endif + value = ele_val_vector[n][nidx]; + return value; +} /************************************************************************** FEMLib-Method: @@ -9223,28 +9084,28 @@ double CRFProcess::evaluteSwitchBC(CBoundaryCondition const & bc, CBoundaryCondi 01/2006 OK Test 03/2012 JT: Checks are unnecessary. Allow reverse order. **************************************************************************/ - int CRFProcess::GetNodeValueIndex(const std::string &var_name, bool reverse_order) // JT: Allow reverse order +int CRFProcess::GetNodeValueIndex(const std::string& var_name, bool reverse_order) // JT: Allow reverse order +{ + if (!reverse_order) { - if(!reverse_order) + for (size_t i = 0; i < nod_val_name_vector.size(); i++) { - for(size_t i = 0; i < nod_val_name_vector.size(); i++) - { - if (nod_val_name_vector[i].compare(var_name) == 0) - return i; - } + if (nod_val_name_vector[i].compare(var_name) == 0) + return i; } - else + } + else + { + int nvals = ((int)nod_val_name_vector.size()) - 1; + for (int j = nvals; j > -1; j--) { - int nvals = ((int)nod_val_name_vector.size()) - 1; - for(int j = nvals; j > -1; j--) - { - if (nod_val_name_vector[j].compare(var_name) == 0) - return j; - } + if (nod_val_name_vector[j].compare(var_name) == 0) + return j; } - // - return -2; } + // + return -2; +} /************************************************************************** FEMLib-Method: @@ -9253,29 +9114,29 @@ double CRFProcess::evaluteSwitchBC(CBoundaryCondition const & bc, CBoundaryCondi 09/2005 PCH Implementation last modified: **************************************************************************/ - int CRFProcess::GetElementValueIndex(const string &var_name, bool reverse_order) +int CRFProcess::GetElementValueIndex(const string& var_name, bool reverse_order) +{ + if (!reverse_order) { - if(!reverse_order) + for (size_t i = 0; i < ele_val_name_vector.size(); i++) { - for(size_t i = 0; i < ele_val_name_vector.size(); i++) - { - if(ele_val_name_vector[i].compare(var_name) == 0) - return i; - } + if (ele_val_name_vector[i].compare(var_name) == 0) + return i; } - else + } + else + { + int nvals = ((int)ele_val_name_vector.size()) - 1; + for (int j = nvals; j > -1; j--) { - int nvals = ((int)ele_val_name_vector.size()) - 1; - for(int j = nvals; j > -1; j--) - { - if(ele_val_name_vector[j].compare(var_name) == 0) - return j; - } + if (ele_val_name_vector[j].compare(var_name) == 0) + return j; } - // - return -2; } - + // + return -2; +} + /************************************************************************** FEMLib-Method: Task: @@ -9285,56 +9146,55 @@ double CRFProcess::evaluteSwitchBC(CBoundaryCondition const & bc, CBoundaryCondi 12/2005 OK RESTART 07/2006 OK/MX MSH **************************************************************************/ - void CRFProcess::SetIC() - { - CInitialCondition* m_ic = NULL; - // HS, for MASS_TRANSPORT PCS, - // it is not necessary to use PrimaryVarible as second check. - // nidx will give the proper IC pointer. - if ( this->getProcessType() == FiniteElement::MASS_TRANSPORT ) - for (int i = 0; i < pcs_number_of_primary_nvals; i++) +void CRFProcess::SetIC() +{ + CInitialCondition* m_ic = NULL; + // HS, for MASS_TRANSPORT PCS, + // it is not necessary to use PrimaryVarible as second check. + // nidx will give the proper IC pointer. + if (this->getProcessType() == FiniteElement::MASS_TRANSPORT) + for (int i = 0; i < pcs_number_of_primary_nvals; i++) + { + int nidx = GetNodeValueIndex(pcs_primary_function_name[i]); + + // PrimaryVariable pv_i (convertPrimaryVariable(pcs_primary_function_name[i])); + for (size_t j = 0; j < ic_vector.size(); j++) { - int nidx = GetNodeValueIndex(pcs_primary_function_name[i]); + m_ic = ic_vector[j]; + m_ic->m_msh = m_msh; // OK/MX - // PrimaryVariable pv_i (convertPrimaryVariable(pcs_primary_function_name[i])); - for (size_t j = 0; j < ic_vector.size(); j++) + if (m_ic->getProcess() == this) { - m_ic = ic_vector[j]; - m_ic->m_msh = m_msh; //OK/MX - - if (m_ic->getProcess() == this ) - { - m_ic->Set(nidx); - m_ic->Set(nidx + 1); - } + m_ic->Set(nidx); + m_ic->Set(nidx + 1); } } - else // otherwise PrimaryVariable check is still performed. + } + else // otherwise PrimaryVariable check is still performed. - for (int i = 0; i < pcs_number_of_primary_nvals; i++) + for (int i = 0; i < pcs_number_of_primary_nvals; i++) + { + int nidx = GetNodeValueIndex(pcs_primary_function_name[i]); + FiniteElement::PrimaryVariable pv_i(FiniteElement::convertPrimaryVariable(pcs_primary_function_name[i])); + for (size_t j = 0; j < ic_vector.size(); j++) { - int nidx = GetNodeValueIndex(pcs_primary_function_name[i]); - FiniteElement::PrimaryVariable pv_i (FiniteElement::convertPrimaryVariable( - pcs_primary_function_name[i])); - for (size_t j = 0; j < ic_vector.size(); j++) - { - m_ic = ic_vector[j]; - m_ic->m_msh = m_msh; //OK/MX + m_ic = ic_vector[j]; + m_ic->m_msh = m_msh; // OK/MX - if (m_ic->getProcessType() != this->getProcessType()) - continue; + if (m_ic->getProcessType() != this->getProcessType()) + continue; - m_ic->setProcess(this); - if (m_ic->getProcessPrimaryVariable() == pv_i) - { - m_ic->Set(nidx); - m_ic->Set(nidx + 1); - } // end of if - } // end of for j - } // end of for i + m_ic->setProcess(this); + if (m_ic->getProcessPrimaryVariable() == pv_i) + { + m_ic->Set(nidx); + m_ic->Set(nidx + 1); + } // end of if + } // end of for j + } // end of for i - // end of if-else - } + // end of if-else +} /************************************************************************** FEMLib-Method: @@ -9343,19 +9203,19 @@ double CRFProcess::evaluteSwitchBC(CBoundaryCondition const & bc, CBoundaryCondi 03/2005 OK Implementation last modified: **************************************************************************/ -#if !defined(NEW_EQS) && !defined(USE_PETSC) //WW. 07.11.2008. 04.2012 - void CRFProcess::SetNODValues() +#if !defined(NEW_EQS) && !defined(USE_PETSC) // WW. 07.11.2008. 04.2012 +void CRFProcess::SetNODValues() +{ + for (long i = 0; i < (long)m_msh->nod_vector.size(); i++) { - for(long i = 0; i < (long)m_msh->nod_vector.size(); i++) - { - // SetNODValue(i,GetNODValueIndex(_pcs_type_name),eqs->x[i]); - // SetNODValue(i,GetNODValueIndex(_pcs_type_name)+1,eqs->x[i]); - //WW - SetNodeValue(m_msh->Eqs2Global_NodeIndex[i],0,eqs->x[i]); - //WW - SetNodeValue(m_msh->Eqs2Global_NodeIndex[i],1,eqs->x[i]); - } + // SetNODValue(i,GetNODValueIndex(_pcs_type_name),eqs->x[i]); + // SetNODValue(i,GetNODValueIndex(_pcs_type_name)+1,eqs->x[i]); + // WW + SetNodeValue(m_msh->Eqs2Global_NodeIndex[i], 0, eqs->x[i]); + // WW + SetNodeValue(m_msh->Eqs2Global_NodeIndex[i], 1, eqs->x[i]); } +} #endif /************************************************************************** @@ -9380,7 +9240,7 @@ double CRFProcess::CalcIterationNODError(FiniteElement::ErrorMethod method, bool static long i, k, g_nnodes; static double error, error_g, val1, val2, value; int nidx1, ii; - double* eqs_x = NULL; // 11.2007. WW + double* eqs_x = NULL; // 11.2007. WW int num_dof_errors = pcs_number_of_primary_nvals; double unknowns_norm = 0.0; double absolute_error[DOF_NUMBER_MAX]; @@ -9388,17 +9248,17 @@ double CRFProcess::CalcIterationNODError(FiniteElement::ErrorMethod method, bool g_nnodes = m_msh->getNumNodesLocal(); eqs_x = eqs_new->GetGlobalSolution(); #else - g_nnodes = m_msh->GetNodesNumber(false); + g_nnodes = m_msh->GetNodesNumber(false); #ifdef NEW_EQS - eqs_x = eqs_new->x; + eqs_x = eqs_new->x; #else - eqs_x = eqs->x; + eqs_x = eqs->x; #endif #endif // if defined(USE_PETSC) - switch(method) + switch (method) { // // --> ENORM: |x1-x0| @@ -9406,31 +9266,37 @@ double CRFProcess::CalcIterationNODError(FiniteElement::ErrorMethod method, bool // Norm taken over entire solution vector (all primary variables) and checked against a single tolerance. // case FiniteElement::ENORM: - if(m_num->nls_method > 0){ // NEWTON-RAPHSON - for(ii=0;iinls_method > 0) + { // NEWTON-RAPHSON + for (ii = 0; ii < pcs_number_of_primary_nvals; ii++) + { + for (i = 0; i < g_nnodes; i++) + { #if defined(USE_PETSC) // || defined(other parallel libs)//08.2014. WW - val1 = eqs_x[ pcs_number_of_primary_nvals * m_msh->Eqs2Global_NodeIndex[i] + ii]; + val1 = eqs_x[pcs_number_of_primary_nvals * m_msh->Eqs2Global_NodeIndex[i] + ii]; #else - val1 = eqs_x[i+ii*g_nnodes]; + val1 = eqs_x[i + ii * g_nnodes]; #endif - unknowns_norm += val1*val1; + unknowns_norm += val1 * val1; } } } - else{ // PICARD - for(ii=0; iiEqs2Global_NodeIndex[i] + ii]; + val1 = GetNodeValue(i, nidx1) + - eqs_x[pcs_number_of_primary_nvals * m_msh->Eqs2Global_NodeIndex[i] + ii]; #else - k = m_msh->Eqs2Global_NodeIndex[i]; - val1 = GetNodeValue(k, nidx1) - eqs_x[i+ii*g_nnodes]; + k = m_msh->Eqs2Global_NodeIndex[i]; + val1 = GetNodeValue(k, nidx1) - eqs_x[i + ii * g_nnodes]; #endif - unknowns_norm += val1*val1; + unknowns_norm += val1 * val1; } } } @@ -9445,87 +9311,97 @@ double CRFProcess::CalcIterationNODError(FiniteElement::ErrorMethod method, bool // case FiniteElement::ERNORM: value = 0.0; - if(m_num->nls_method > 0){ // NEWTON-RAPHSON - for(ii=0;iinls_method > 0) + { // NEWTON-RAPHSON + for (ii = 0; ii < pcs_number_of_primary_nvals; ii++) { nidx1 = GetNodeValueIndex(pcs_primary_function_name[ii]) + 1; // - for(i = 0; i < g_nnodes; i++){ + for (i = 0; i < g_nnodes; i++) + { #if defined(USE_PETSC) // || defined(other parallel libs)//02.2018. WW - val1 = eqs_x[pcs_number_of_primary_nvals*m_msh->Eqs2Global_NodeIndex[i] + ii]; - val2 = GetNodeValue(i, nidx1); + val1 = eqs_x[pcs_number_of_primary_nvals * m_msh->Eqs2Global_NodeIndex[i] + ii]; + val2 = GetNodeValue(i, nidx1); #else - k = m_msh->Eqs2Global_NodeIndex[i]; - val1 = eqs_x[i+ii*g_nnodes]; - val2 = GetNodeValue(k, nidx1); + k = m_msh->Eqs2Global_NodeIndex[i]; + val1 = eqs_x[i + ii * g_nnodes]; + val2 = GetNodeValue(k, nidx1); #endif - // - unknowns_norm += val1*val1; - value += val2*val2; + // + unknowns_norm += val1 * val1; + value += val2 * val2; } } } - else{ // PICARD - for(ii=0; iiEqs2Global_NodeIndex[i] + ii]; + val2 = val1 - eqs_x[pcs_number_of_primary_nvals * m_msh->Eqs2Global_NodeIndex[i] + ii]; #else - k = m_msh->Eqs2Global_NodeIndex[i]; - val1 = GetNodeValue(k, nidx1); - val2 = val1 - eqs_x[i+ii*g_nnodes]; + k = m_msh->Eqs2Global_NodeIndex[i]; + val1 = GetNodeValue(k, nidx1); + val2 = val1 - eqs_x[i + ii * g_nnodes]; #endif // - unknowns_norm += val2*val2; - value += val1*val1; + unknowns_norm += val2 * val2; + value += val1 * val1; } } } num_dof_errors = 1; unknowns_norm = sqrt(unknowns_norm); - absolute_error[0] = unknowns_norm / (sqrt(value)+DBL_EPSILON); + absolute_error[0] = unknowns_norm / (sqrt(value) + DBL_EPSILON); break; // // --> EVNORM: |x1-x0| // Norm of the solution vector delta (absolute error). - // Norm taken over solution vector of each primary variable, checked againes a tolerence specific to each variable. + // Norm taken over solution vector of each primary variable, checked againes a tolerence specific to each + // variable. // case FiniteElement::EVNORM: - if(m_num->nls_method > 0){ // NEWTON-RAPHSON - for(ii=0;iinls_method > 0) + { // NEWTON-RAPHSON + for (ii = 0; ii < pcs_number_of_primary_nvals; ii++) { error = 0.0; - for(i = 0; i < g_nnodes; i++){ + for (i = 0; i < g_nnodes; i++) + { #if defined(USE_PETSC) // || defined(other parallel libs)//08.2014. WW - val1 = eqs_x[pcs_number_of_primary_nvals*m_msh->Eqs2Global_NodeIndex[i] + ii]; + val1 = eqs_x[pcs_number_of_primary_nvals * m_msh->Eqs2Global_NodeIndex[i] + ii]; #else - val1 = eqs_x[i+ii*g_nnodes]; + val1 = eqs_x[i + ii * g_nnodes]; #endif - error += val1*val1; + error += val1 * val1; } unknowns_norm += error; absolute_error[ii] = sqrt(error); } } - else{ // PICARD - for(ii=0; iiEqs2Global_NodeIndex[i] + ii]; + val1 = GetNodeValue(i, nidx1) + - eqs_x[pcs_number_of_primary_nvals * m_msh->Eqs2Global_NodeIndex[i] + ii]; #else - k = m_msh->Eqs2Global_NodeIndex[i]; - val1 = GetNodeValue(k, nidx1) - eqs_x[i+ii*g_nnodes]; + k = m_msh->Eqs2Global_NodeIndex[i]; + val1 = GetNodeValue(k, nidx1) - eqs_x[i + ii * g_nnodes]; #endif - error += val1*val1; + error += val1 * val1; } unknowns_norm += error; absolute_error[ii] = sqrt(error); @@ -9539,31 +9415,37 @@ double CRFProcess::CalcIterationNODError(FiniteElement::ErrorMethod method, bool // Norm taken over entire solution vector (all primary variables) and checked against a single tolerance. // case FiniteElement::BNORM: - if(m_num->nls_method > 0){ // NEWTON-RAPHSON - for(ii=0;iinls_method > 0) + { // NEWTON-RAPHSON + for (ii = 0; ii < pcs_number_of_primary_nvals; ii++) + { + for (i = 0; i < g_nnodes; i++) + { #if defined(USE_PETSC) // || defined(other parallel libs)//08.2014. WW - val1 = eqs_x[pcs_number_of_primary_nvals*m_msh->Eqs2Global_NodeIndex[i] + ii]; + val1 = eqs_x[pcs_number_of_primary_nvals * m_msh->Eqs2Global_NodeIndex[i] + ii]; #else - val1 = eqs_x[i+ii*g_nnodes]; + val1 = eqs_x[i + ii * g_nnodes]; #endif - unknowns_norm += val1*val1; + unknowns_norm += val1 * val1; } } } - else{ // PICARD - for(ii=0; iiEqs2Global_NodeIndex[i] + ii]; + val1 = GetNodeValue(i, nidx1) + - eqs_x[pcs_number_of_primary_nvals * m_msh->Eqs2Global_NodeIndex[i] + ii]; #else - k = m_msh->Eqs2Global_NodeIndex[i]; - val1 = GetNodeValue(k, nidx1) - eqs_x[i+ii*g_nnodes]; + k = m_msh->Eqs2Global_NodeIndex[i]; + val1 = GetNodeValue(k, nidx1) - eqs_x[i + ii * g_nnodes]; #endif - unknowns_norm += val1*val1; + unknowns_norm += val1 * val1; } } } @@ -9577,41 +9459,46 @@ double CRFProcess::CalcIterationNODError(FiniteElement::ErrorMethod method, bool // Tolerance required for each primary variable. // case FiniteElement::LMAX: - if(m_num->nls_method > 0){ // NEWTON-RAPHSON - for(ii=0;iinls_method > 0) + { // NEWTON-RAPHSON + for (ii = 0; ii < pcs_number_of_primary_nvals; ii++) { error = 0.0; - for (i = 0; i < g_nnodes; i++){ + for (i = 0; i < g_nnodes; i++) + { #if defined(USE_PETSC) // || defined(other parallel libs)//08.3014. WW - val1 = eqs_x[pcs_number_of_primary_nvals*m_msh->Eqs2Global_NodeIndex[i] + ii]; + val1 = eqs_x[pcs_number_of_primary_nvals * m_msh->Eqs2Global_NodeIndex[i] + ii]; #else - val1 = eqs_x[i+ii*g_nnodes]; + val1 = eqs_x[i + ii * g_nnodes]; #endif - unknowns_norm += val1*val1; - val1 = fabs(val1); - if(val1 > error) - error = val1; + unknowns_norm += val1 * val1; + val1 = fabs(val1); + if (val1 > error) + error = val1; } absolute_error[ii] = error; } } - else{ // PICARD - for(ii=0; iiEqs2Global_NodeIndex[i] + ii]; + val1 = GetNodeValue(i, nidx1) + - eqs_x[pcs_number_of_primary_nvals * m_msh->Eqs2Global_NodeIndex[i] + ii]; #else - k = m_msh->Eqs2Global_NodeIndex[i]; - val1 = GetNodeValue(k, nidx1) - eqs_x[i+ii*g_nnodes]; + k = m_msh->Eqs2Global_NodeIndex[i]; + val1 = GetNodeValue(k, nidx1) - eqs_x[i + ii * g_nnodes]; #endif - unknowns_norm += val1*val1; - val1 = fabs(val1); - if(val1 > error) - error = val1; + unknowns_norm += val1 * val1; + val1 = fabs(val1); + if (val1 > error) + error = val1; } absolute_error[ii] = error; } @@ -9622,116 +9509,123 @@ double CRFProcess::CalcIterationNODError(FiniteElement::ErrorMethod method, bool default: ScreenMessage("ERROR: Invalid error method for Iteration or Coupling Node error.\n"); return 0.0; - // - /* - ----------------------------------------------------------------------------------------------- - ALTERNATIVE METHODS NOT YET IMPLEMENTED. MODIFY THEM AND ADD THEIR ENUM VALUES IF YOU WANT THEM. - ----------------------------------------------------------------------------------------------- - // METHOD 4 - case 4: - for(ii=0;iiEqs2Global_NodeIndex[i]; - error = MMax(error, fabs(eqs_x[i+ii*g_nnodes] - GetNodeValue(k, nidx1))); - max_c = MMax(MMax(max_c, fabs(fabs(eqs_x[i+ii*g_nnodes]))),fabs(GetNodeValue(k, nidx1))); - } - pcs_absolute_error[ii] = error / (max_c + MKleinsteZahl); - } - break; - // - // METHOD 5 - case 5: - for(ii=0;iiEqs2Global_NodeIndex[i]; - error = MMax(error, fabs(eqs_x[i+ii*g_nnodes] - GetNodeValue(k, nidx1))); - min_c = MMin(min_c, fabs(eqs_x[i+ii*g_nnodes])); - max_c = MMax(max_c, fabs(eqs_x[i+ii*g_nnodes])); - } - pcs_absolute_error[ii] = error / (max_c - min_c + MKleinsteZahl) ; - } - break; - // - // METHOD 6 - case 6: - for(ii=0;iiEqs2Global_NodeIndex[i]; - error = MMax(error, fabs(eqs_x[i+ii*g_nnodes] - GetNodeValue(k, nidx1)) - / (fabs(eqs_x[i+ii*g_nnodes] - GetNodeValue(k, nidx1-1)) + MKleinsteZahl)); - } - pcs_absolute_error[ii] = error; - } - break; - // - // METHOD 7 - case 7: - for(ii=0;iiEqs2Global_NodeIndex[i]; - error = MMax(error, fabs(eqs_x[i+ii*g_nnodes] - GetNodeValue(k, nidx1))); - change = MMax(change, fabs(eqs_x[i+ii*g_nnodes] - GetNodeValue(k, nidx1-1))); - } - pcs_absolute_error[ii] = error / (change + MKleinsteZahl); - } - break; - // - */ + // + /* + ----------------------------------------------------------------------------------------------- + ALTERNATIVE METHODS NOT YET IMPLEMENTED. MODIFY THEM AND ADD THEIR ENUM VALUES IF YOU WANT THEM. + ----------------------------------------------------------------------------------------------- + // METHOD 4 + case 4: + for(ii=0;iiEqs2Global_NodeIndex[i]; + error = MMax(error, fabs(eqs_x[i+ii*g_nnodes] - GetNodeValue(k, nidx1))); + max_c = MMax(MMax(max_c, fabs(fabs(eqs_x[i+ii*g_nnodes]))),fabs(GetNodeValue(k, nidx1))); + } + pcs_absolute_error[ii] = error / (max_c + MKleinsteZahl); + } + break; + // + // METHOD 5 + case 5: + for(ii=0;iiEqs2Global_NodeIndex[i]; + error = MMax(error, fabs(eqs_x[i+ii*g_nnodes] - GetNodeValue(k, nidx1))); + min_c = MMin(min_c, fabs(eqs_x[i+ii*g_nnodes])); + max_c = MMax(max_c, fabs(eqs_x[i+ii*g_nnodes])); + } + pcs_absolute_error[ii] = error / (max_c - min_c + MKleinsteZahl) ; + } + break; + // + // METHOD 6 + case 6: + for(ii=0;iiEqs2Global_NodeIndex[i]; + error = MMax(error, fabs(eqs_x[i+ii*g_nnodes] - GetNodeValue(k, nidx1)) + / (fabs(eqs_x[i+ii*g_nnodes] - GetNodeValue(k, nidx1-1)) + MKleinsteZahl)); + } + pcs_absolute_error[ii] = error; + } + break; + // + // METHOD 7 + case 7: + for(ii=0;iiEqs2Global_NodeIndex[i]; + error = MMax(error, fabs(eqs_x[i+ii*g_nnodes] - GetNodeValue(k, nidx1))); + change = MMax(change, fabs(eqs_x[i+ii*g_nnodes] - GetNodeValue(k, nidx1-1))); + } + pcs_absolute_error[ii] = error / (change + MKleinsteZahl); + } + break; + // + */ } #if defined(USE_PETSC) // || defined(other parallel libs)//08.2014. WW - for(ii=0;ii 1 AND EACH DOF MAY HAVE DIFFERENT CHARACTER - if(cpl_error){ // Return coupling error - error_g = 0.0; - for(ii=0; iicpl_error_tolerance[ii]; - error_g = MMax(error_g, error); // Coupling error just stores the maximum - } - cpl_max_relative_error = error_g; - cpl_num_dof_errors = num_dof_errors; + if (cpl_error) + { // Return coupling error + error_g = 0.0; + for (ii = 0; ii < num_dof_errors; ii++) + { + cpl_absolute_error[ii] = absolute_error[ii]; + error = absolute_error[ii] / m_num->cpl_error_tolerance[ii]; + error_g = MMax(error_g, error); // Coupling error just stores the maximum + } + cpl_max_relative_error = error_g; + cpl_num_dof_errors = num_dof_errors; } - if(nls_error){ // Return Non-Linear iteration error + if (nls_error) + { // Return Non-Linear iteration error error_g = 0.0; - for(ii=0; iinls_error_tolerance[ii]; - error_g = MMax(error_g, pcs_relative_error[ii]); + for (ii = 0; ii < num_dof_errors; ii++) + { + pcs_absolute_error[ii] = absolute_error[ii]; + pcs_relative_error[ii] = absolute_error[ii] / m_num->nls_error_tolerance[ii]; + error_g = MMax(error_g, pcs_relative_error[ii]); } nls_max_relative_error = error_g; pcs_num_dof_errors = num_dof_errors; pcs_unknowns_norm = unknowns_norm; } - if(!nls_error && !cpl_error){ // Then this routine called from somewhere else to get the error (i.e. time control). Store it in a temporary vector for access. - for(ii=0; iinls_relaxation; //JT - if(nl_theta < DBL_EPSILON) nl_theta = 1.0; - g_nnodes = m_msh->GetNodesNumber(false); +double CRFProcess::ExecuteNonLinear(int loop_process_number, bool print_pcs) +{ + double nonlinear_iteration_error = 0.0; + double nl_theta, damping, norm_x0, norm_b0, norm_x, norm_b; + double error_x1, error_x2, error_b1, error_b2 = 0, error, last_error, percent_difference; + // double* eqs_x = NULL; // + bool converged, diverged; + int ii, nidx1, num_fail = 0; + size_t j, g_nnodes; + + string delim = " "; + damping = 1.0; + norm_x0 = norm_b0 = norm_x = norm_b = 0.; + error = 1.; + error_x2 = DBL_MAX; + nl_theta = 1.0 - m_num->nls_relaxation; // JT + if (nl_theta < DBL_EPSILON) + nl_theta = 1.0; + g_nnodes = m_msh->GetNodesNumber(false); #if defined(USE_PETSC) // || defined(other parallel libs)//03.3012. WW - eqs_x = eqs_new->GetGlobalSolution(); + eqs_x = eqs_new->GetGlobalSolution(); #endif #if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW - double* eqs_b = NULL; - int k; + double* eqs_b = NULL; + int k; #ifdef NEW_EQS - eqs_x = eqs_new->x; - eqs_b = eqs_new->b; - configured_in_nonlinearloop = true; - // Also allocate temporary memory for linear solver. WW - // + eqs_x = eqs_new->x; + eqs_b = eqs_new->b; + configured_in_nonlinearloop = true; +// Also allocate temporary memory for linear solver. WW +// #if defined(USE_MPI) - CPARDomain* dom = dom_vector[myrank]; - dom->eqs->SetDOF(pcs_number_of_primary_nvals); //_new 02/2010 WW - dom->ConfigEQS(m_num, pcs_number_of_primary_nvals - * m_msh->GetNodesNumber(false)); + CPARDomain* dom = dom_vector[myrank]; + dom->eqs->SetDOF(pcs_number_of_primary_nvals); //_new 02/2010 WW + dom->ConfigEQS(m_num, pcs_number_of_primary_nvals * m_msh->GetNodesNumber(false)); #else - eqs_new->SetDOF(pcs_number_of_primary_nvals); //_new 02/2010. WW - eqs_new->ConfigNumerics(m_num); + eqs_new->SetDOF(pcs_number_of_primary_nvals); //_new 02/2010. WW + eqs_new->ConfigNumerics(m_num); #endif - // +// #else // ifdef NEW_EQS eqs_x = eqs->x; eqs_b = eqs->b; #endif #endif - //.................................................................. - // PI time step size control. 29.08.2008. WW - if(Tim->GetPITimeStepCrtlType() > 0 ) - CopyU_n(); - if (hasAnyProcessDeactivatedSubdomains) - this->CheckMarkedElement(); //NW - if (ExcavMaterialGroup>-1)//WX:07.2011 HM excavation - this->CheckExcavedElement(); - Tim->last_dt_accepted = true; // JT2012 - -#if defined(USE_PETSC) || defined (USE_MPI) // || defined(other parallel libs)//01.3013. WW - if(myrank==0) - { -#endif - if(print_pcs){ // JT: need check because of Regional Richards - std::cout << "\n ================================================" << "\n"; - if(getProcessType() == FiniteElement::MASS_TRANSPORT){ - std::cout << " ->Process " << loop_process_number << ": " << convertProcessTypeToString (getProcessType()) << "\n"; + //.................................................................. + // PI time step size control. 29.08.2008. WW + if (Tim->GetPITimeStepCrtlType() > 0) + CopyU_n(); + if (hasAnyProcessDeactivatedSubdomains) + this->CheckMarkedElement(); // NW + if (ExcavMaterialGroup > -1) // WX:07.2011 HM excavation + this->CheckExcavedElement(); + Tim->last_dt_accepted = true; // JT2012 + +#if defined(USE_PETSC) || defined(USE_MPI) // || defined(other parallel libs)//01.3013. WW + if (myrank == 0) + { +#endif + if (print_pcs) + { // JT: need check because of Regional Richards + std::cout << "\n ================================================" + << "\n"; + if (getProcessType() == FiniteElement::MASS_TRANSPORT) + { + std::cout << " ->Process " << loop_process_number << ": " + << convertProcessTypeToString(getProcessType()) << "\n"; std::cout << " ->Component " << pcs_component_number << ": " << pcs_primary_function_name[0] << "\n"; } - else{ - std::cout << " ->Process " << loop_process_number << ": " << convertProcessTypeToString (getProcessType()) << "\n"; + else + { + std::cout << " ->Process " << loop_process_number << ": " + << convertProcessTypeToString(getProcessType()) << "\n"; } - std::cout << " ================================================" << "\n"; - } -#if defined(USE_PETSC) || defined (USE_MPI) // || defined(other parallel libs)//01.3013. WW#ifdef USE_MPI + std::cout << " ================================================" + << "\n"; } +#if defined(USE_PETSC) || defined(USE_MPI) // || defined(other parallel libs)//01.3013. WW#ifdef USE_MPI + } #endif - // ------------------------------------------------------------ - // NON-LINEAR ITERATIONS (OR SINGLE ITERATION IF LINEAR) - // ------------------------------------------------------------ - diverged = false; - converged = false; - accepted = true; - last_error = 1.0; - for(iter_nlin = 0; iter_nlin < m_num->nls_max_iterations; iter_nlin++) + // ------------------------------------------------------------ + // NON-LINEAR ITERATIONS (OR SINGLE ITERATION IF LINEAR) + // ------------------------------------------------------------ + diverged = false; + converged = false; + accepted = true; + last_error = 1.0; + for (iter_nlin = 0; iter_nlin < m_num->nls_max_iterations; iter_nlin++) + { + cout << " PCS non-linear iteration: " << iter_nlin << "/" << m_num->nls_max_iterations << '\n'; + nonlinear_iteration_error = Execute(); + // + // --------------------------------------------------- + // LINEAR SOLUTION + // --------------------------------------------------- + if (m_num->nls_method < 0) + { + PrintStandardIterationInformation(true); + converged = true; + } + else { - cout << " PCS non-linear iteration: " << iter_nlin << "/" - << m_num->nls_max_iterations << '\n'; - nonlinear_iteration_error = Execute(); - // - // --------------------------------------------------- - // LINEAR SOLUTION - // --------------------------------------------------- - if(m_num->nls_method < 0) - { - PrintStandardIterationInformation(true); - converged = true; - } - else - { // --------------------------------------------------- // NON-LINEAR SOLUTION // --------------------------------------------------- // - damping = nl_theta; - switch(m_num->getNonLinearErrorMethod()) - { - // For most error methods (also works for Newton) - default: - PrintStandardIterationInformation(true); + damping = nl_theta; + switch (m_num->getNonLinearErrorMethod()) + { + // For most error methods (also works for Newton) + default: + PrintStandardIterationInformation(true); + // + if (nonlinear_iteration_error <= 1.0) + { + converged = true; + } + else + { // Check for stagnation + percent_difference = 100.0 * ((last_error - nonlinear_iteration_error) / last_error); + if (iter_nlin > 0 + && percent_difference + < 1.0) // less than 1% difference (or an error increase) from previous error + num_fail++; + else + num_fail = 0; // - if(nonlinear_iteration_error <= 1.0){ - converged = true; - } - else{ // Check for stagnation - percent_difference = 100.0 * ((last_error - nonlinear_iteration_error) / last_error); - if(iter_nlin > 0 && percent_difference < 1.0) // less than 1% difference (or an error increase) from previous error - num_fail++; - else - num_fail = 0; - // - if(num_fail > 1) diverged = true; // require 2 consecutive failures - last_error = nonlinear_iteration_error; - } - break; + if (num_fail > 1) + diverged = true; // require 2 consecutive failures + last_error = nonlinear_iteration_error; + } + break; - // For (OGS) classic Newton error control - case FiniteElement::BNORM: - PrintStandardIterationInformation(false); - // + // For (OGS) classic Newton error control + case FiniteElement::BNORM: + PrintStandardIterationInformation(false); +// #if defined(USE_PETSC) // || defined(other parallel libs)//06.3012. WW - norm_x = eqs_new->GetVecNormX(); - norm_b = eqs_new->GetVecNormRHS(); + norm_x = eqs_new->GetVecNormX(); + norm_b = eqs_new->GetVecNormRHS(); #else - norm_x = pcs_unknowns_norm; // JT: this is already obtained in CalcIterationNodeError. - norm_b = 0.0; // must calculate this - for(ii = 0; ii < pcs_number_of_primary_nvals; ii++){ - for (j = 0; j < g_nnodes; j++){ - double val = eqs_b[j + ii*g_nnodes]; - norm_b += val*val; - } + norm_x = pcs_unknowns_norm; // JT: this is already obtained in CalcIterationNodeError. + norm_b = 0.0; // must calculate this + for (ii = 0; ii < pcs_number_of_primary_nvals; ii++) + { + for (j = 0; j < g_nnodes; j++) + { + double val = eqs_b[j + ii * g_nnodes]; + norm_b += val * val; } - norm_b = sqrt(norm_b); + } + norm_b = sqrt(norm_b); #endif + // + if (iter_nlin == 0) + { + norm_x0 = norm_x; + norm_b0 = norm_b; + error_x2 = error_b2 = DBL_MAX; + } + else + { + error_x1 = norm_x / norm_x0; + error_b1 = norm_b / norm_b0; + + if (norm_x < m_num->nls_error_tolerance[0] && error_x1 > norm_x) + error_x1 = norm_x; + if (norm_b < m_num->nls_error_tolerance[0] && error_b1 > norm_b) + error_b1 = norm_b; + if (error_x1 / error_x2 > 0.1 || error_b1 / error_b2 > 0.1) + damping *= 0.5; // take 1/2 of original theta // - if(iter_nlin == 0){ - norm_x0 = norm_x; - norm_b0 = norm_b; - error_x2 = error_b2 = DBL_MAX; - } - else{ - error_x1 = norm_x / norm_x0; - error_b1 = norm_b / norm_b0; - - if(norm_x < m_num->nls_error_tolerance[0] && error_x1 > norm_x) - error_x1 = norm_x; - if(norm_b < m_num->nls_error_tolerance[0] && error_b1 > norm_b) - error_b1 = norm_b; - if(error_x1 / error_x2 > 0.1 || error_b1 / error_b2 > 0.1) - damping *= 0.5; // take 1/2 of original theta - // - error = max(error_x1, error_b1); - error_x2 = error_x1; - error_b2 = error_b1; - // - // Check for divergence - if(error > 10.0 && iter_nlin > 1) + error = max(error_x1, error_b1); + error_x2 = error_x1; + error_b2 = error_b1; + // + // Check for divergence + if (error > 10.0 && iter_nlin > 1) + { + diverged = true; + if (Tim->GetPITimeStepCrtlType() > 0) + { // if PI automatic time control + accepted = false; + PI_TimeStepSize(); + return error; + } + else { - diverged = true; - if(Tim->GetPITimeStepCrtlType() > 0){ // if PI automatic time control - accepted = false; - PI_TimeStepSize(); - return error; - } - else - { - cout <<"Attention: Newton-Raphson step is diverged. Programme halt!" << "\n"; + cout << "Attention: Newton-Raphson step is diverged. Programme halt!" + << "\n"; #if defined(USE_PETSC) // || defined(other parallel libs)//08.3012. WW - PetscFinalize(); + PetscFinalize(); #endif #if defined(USE_MPI) - MPI_Finalize(); + MPI_Finalize(); #endif - exit(1); - - } - } - // - // Check convergence - if(norm_x0 < m_num->nls_error_tolerance[0]){ - error = norm_x0; - converged = true; - } - if(norm_b0 < 10 * m_num->nls_error_tolerance[0]){ - error = norm_b0; - converged = true; - } - if(norm_b < 0.001 * norm_b0){ - error = norm_b; - converged = true; - } - if(error <= m_num->nls_error_tolerance[0]){ - converged = true; + exit(1); } } - // Newton information printout. -#if defined (USE_MPI) || defined(USE_PETSC) - if(myrank == 0) - { + // + // Check convergence + if (norm_x0 < m_num->nls_error_tolerance[0]) + { + error = norm_x0; + converged = true; + } + if (norm_b0 < 10 * m_num->nls_error_tolerance[0]) + { + error = norm_b0; + converged = true; + } + if (norm_b < 0.001 * norm_b0) + { + error = norm_b; + converged = true; + } + if (error <= m_num->nls_error_tolerance[0]) + { + converged = true; + } + } +// Newton information printout. +#if defined(USE_MPI) || defined(USE_PETSC) + if (myrank == 0) + { #endif cout.width(10); cout.precision(3); cout.setf(ios::scientific); - cout << " NR-Error |" << " RHS Norm|" << " Unknowns Norm|" << " Damping\n"; + cout << " NR-Error |" + << " RHS Norm|" + << " Unknowns Norm|" + << " Damping\n"; cout << " " << setw(10) << error << "| " << setw(9) << norm_b << "| "; - cout << setw(14) << norm_x << "| "<< setw(9) << damping << "\n"; -#if defined (USE_MPI) || defined(USE_PETSC) - } + cout << setw(14) << norm_x << "| " << setw(9) << damping << "\n"; +#if defined(USE_MPI) || defined(USE_PETSC) + } #endif - break; - } + break; } + } + // CHECK FOR TIME STEP FAILURE + // --------------------------------------------------- - // CHECK FOR TIME STEP FAILURE - // --------------------------------------------------- - - if (m_num->nls_max_iterations>1 && !converged && iter_nlin+1 == m_num->nls_max_iterations) accepted = false; + if (m_num->nls_max_iterations > 1 && !converged && iter_nlin + 1 == m_num->nls_max_iterations) + accepted = false; - if(!accepted || Tim->isDynamicTimeFailureSuggested(this)){ - accepted = false; - Tim->last_dt_accepted = false; - break; - } + if (!accepted || Tim->isDynamicTimeFailureSuggested(this)) + { + accepted = false; + Tim->last_dt_accepted = false; + break; + } - // FOR NEWTON: COPY DAMPED CHANGES TO NEW TIME - // --------------------------------------------------- - if(m_num->nls_method > 0) + // FOR NEWTON: COPY DAMPED CHANGES TO NEW TIME + // --------------------------------------------------- + if (m_num->nls_method > 0) + { + if (converged) + damping = 1.0; // Solution has converged. Take newest values. + // + for (ii = 0; ii < pcs_number_of_primary_nvals; ii++) { - if(converged) - damping = 1.0; // Solution has converged. Take newest values. - // - for(ii = 0; ii < pcs_number_of_primary_nvals; ii++) - { - nidx1 = GetNodeValueIndex(pcs_primary_function_name[ii]) + 1; + nidx1 = GetNodeValueIndex(pcs_primary_function_name[ii]) + 1; #if defined(USE_PETSC) // || defined(other parallel libs)//03.3012. WW - for (j = 0; j < g_nnodes; j++) - { - SetNodeValue(j, nidx1, GetNodeValue(j,nidx1) + - damping * eqs_x[m_msh->Eqs2Global_NodeIndex[j]*pcs_number_of_primary_nvals + ii]); - } + for (j = 0; j < g_nnodes; j++) + { + SetNodeValue( + j, nidx1, + GetNodeValue(j, nidx1) + + damping * eqs_x[m_msh->Eqs2Global_NodeIndex[j] * pcs_number_of_primary_nvals + ii]); + } #else - const long ish = ii * g_nnodes; - for(j = 0; j < g_nnodes; j++){ - k = m_msh->Eqs2Global_NodeIndex[j]; - double val = GetNodeValue(k,nidx1) + damping*eqs_x[j + ish]; - SetNodeValue(k,nidx1,val); - } -#endif + const long ish = ii * g_nnodes; + for (j = 0; j < g_nnodes; j++) + { + k = m_msh->Eqs2Global_NodeIndex[j]; + double val = GetNodeValue(k, nidx1) + damping * eqs_x[j + ish]; + SetNodeValue(k, nidx1, val); } +#endif } + } - // OTHER CONFIGURATIONS AT THE END OF THIS NON-LINEAR ITERATION - // --------------------------------------------------- - if(mobile_nodes_flag ==1){ - PCSMoveNOD(); - } - /* JT: I don't know if this time control method is used anymore. But it relies on a single error - produced from CalcIterationNodeError(), but this now depends on the type of error to use. - Therefore, I simply provide the error of the first dof, and not depending on the error type. If - this time step is still used, someone will need to find another way to calculate the error it uses. - */ - Tim->repeat = true; - if(converged){ - Tim->repeat = false; - Tim->nonlinear_iteration_error = pcs_absolute_error[0]; - } - - // BREAK CRITERIA - if(converged || diverged) - { - break; - } + // OTHER CONFIGURATIONS AT THE END OF THIS NON-LINEAR ITERATION + // --------------------------------------------------- + if (mobile_nodes_flag == 1) + { + PCSMoveNOD(); } - iter_nlin_max = std::max(iter_nlin_max, iter_nlin); - // ------------------------------------------------------------ - // NON-LINEAR ITERATIONS COMPLETE - // ------------------------------------------------------------ - // PI time step size control. 27.08.2008. WW - if(Tim->GetPITimeStepCrtlType() > 0){ - PI_TimeStepSize(); // might also set accepted to false here. + /* JT: I don't know if this time control method is used anymore. But it relies on a single error + produced from CalcIterationNodeError(), but this now depends on the type of error to use. + Therefore, I simply provide the error of the first dof, and not depending on the error type. If + this time step is still used, someone will need to find another way to calculate the error it uses. + */ + Tim->repeat = true; + if (converged) + { + Tim->repeat = false; + Tim->nonlinear_iteration_error = pcs_absolute_error[0]; } - // - if(m_num->nls_max_iterations > 1) // only for non-linear iterations + + // BREAK CRITERIA + if (converged || diverged) { - if(diverged){ - if(accepted) // only increment if not fixed by a failed time step. - num_diverged++; - std::cout << "\nNon-linear iteration stabilized."; - } - else if(!converged){ - if(accepted) // only increment if not fixed by a failed time step. - num_notsatisfied++; - if(Tim->GetPITimeStepCrtlType() < 1) // PI has the intrinsic property of doing this. So don't print it. - std::cout << "\nMax number of non-linear iterations reached."; - } + break; } - // - // Calculate secondary variables - if(accepted){ - CalcSecondaryVariables(); + } + iter_nlin_max = std::max(iter_nlin_max, iter_nlin); + // ------------------------------------------------------------ + // NON-LINEAR ITERATIONS COMPLETE + // ------------------------------------------------------------ + // PI time step size control. 27.08.2008. WW + if (Tim->GetPITimeStepCrtlType() > 0) + { + PI_TimeStepSize(); // might also set accepted to false here. + } + // + if (m_num->nls_max_iterations > 1) // only for non-linear iterations + { + if (diverged) + { + if (accepted) // only increment if not fixed by a failed time step. + num_diverged++; + std::cout << "\nNon-linear iteration stabilized."; + } + else if (!converged) + { + if (accepted) // only increment if not fixed by a failed time step. + num_notsatisfied++; + if (Tim->GetPITimeStepCrtlType() < 1) // PI has the intrinsic property of doing this. So don't print it. + std::cout << "\nMax number of non-linear iterations reached."; } + } + // + // Calculate secondary variables + if (accepted) + { + CalcSecondaryVariables(); + } #if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW - // Release temporary memory of linear solver. WW -#ifdef NEW_EQS //WW +// Release temporary memory of linear solver. WW +#ifdef NEW_EQS // WW #if defined(USE_MPI) - dom->eqs->Clean(); + dom->eqs->Clean(); #else - eqs_new->Clean(); // Release buffer momery WW + eqs_new->Clean(); // Release buffer momery WW #endif - configured_in_nonlinearloop = false; + configured_in_nonlinearloop = false; #endif #endif - return nonlinear_iteration_error; - } - - - - + return nonlinear_iteration_error; +} /************************************************************************** FEMLib-Method: @@ -10090,41 +10011,50 @@ double CRFProcess::CalcIterationNODError(FiniteElement::ErrorMethod method, bool Programing: 3/2012 JT **************************************************************************/ - void CRFProcess::PrintStandardIterationInformation(bool write_std_errors) - { - int ii; - // - // LINEAR SOLUTION - if(m_num->nls_method < 0) +void CRFProcess::PrintStandardIterationInformation(bool write_std_errors) +{ + int ii; + // + // LINEAR SOLUTION + if (m_num->nls_method < 0) + { + std::cout << " -->LINEAR solution complete. " + << "\n"; + if (write_std_errors) { - std::cout << " -->LINEAR solution complete. " << "\n"; - if(write_std_errors){ - for(ii = 0; ii < pcs_number_of_primary_nvals; ii++){ - std::cout << " PCS error DOF["<< ii <<"]: " << pcs_absolute_error[ii] << "\n"; - } + for (ii = 0; ii < pcs_number_of_primary_nvals; ii++) + { + std::cout << " PCS error DOF[" << ii << "]: " << pcs_absolute_error[ii] << "\n"; } - return; } - // - // NON-LINEAR METHODS - if(m_num->nls_method == 0) - std::cout << " -->End of PICARD iteration: " << iter_nlin << "/" << m_num->nls_max_iterations << "\n"; + return; + } + // + // NON-LINEAR METHODS + if (m_num->nls_method == 0) + std::cout << " -->End of PICARD iteration: " << iter_nlin << "/" << m_num->nls_max_iterations << "\n"; + else + std::cout << " -->End of NEWTON-RAPHSON iteration: " << iter_nlin << "/" << m_num->nls_max_iterations + << "\n"; + // + // Errors + // -------------------------------------------------- + if (write_std_errors) + { + if (pcs_num_dof_errors == 1) + { + std::cout << " PCS error: " << pcs_absolute_error[0] << "\n"; + } else - std::cout << " -->End of NEWTON-RAPHSON iteration: " << iter_nlin << "/" << m_num->nls_max_iterations << "\n"; - // - // Errors - // -------------------------------------------------- - if(write_std_errors){ - if(pcs_num_dof_errors == 1){ - std::cout << " PCS error: " << pcs_absolute_error[0] << "\n"; - }else{ - for (ii = 0; ii < pcs_number_of_primary_nvals; ii++){ - std::cout << " PCS error DOF["<< ii <<"]: " << pcs_absolute_error[ii] << "\n"; - } + { + for (ii = 0; ii < pcs_number_of_primary_nvals; ii++) + { + std::cout << " PCS error DOF[" << ii << "]: " << pcs_absolute_error[ii] << "\n"; } - std::cout <<" ->Euclidian norm of unknowns: " << pcs_unknowns_norm << "\n"; } + std::cout << " ->Euclidian norm of unknowns: " << pcs_unknowns_norm << "\n"; } +} /************************************************************************** FEMLib-Method: @@ -10132,43 +10062,43 @@ double CRFProcess::CalcIterationNODError(FiniteElement::ErrorMethod method, bool Programing: 02/2007 WW Implementation **************************************************************************/ - void CRFProcess::Extropolation_GaussValue() - { - int k, NS; - long i = 0; - int idx[3]; - // const long LowOrderNodes= m_msh->GetNodesNumber(false); - MeshLib::CElem* elem = NULL; +void CRFProcess::Extropolation_GaussValue() +{ + int k, NS; + long i = 0; + int idx[3]; + // const long LowOrderNodes= m_msh->GetNodesNumber(false); + MeshLib::CElem* elem = NULL; - // - NS = m_msh->GetCoordinateFlag() / 10; - idx[0] = GetNodeValueIndex("VELOCITY_X1"); - idx[1] = GetNodeValueIndex("VELOCITY_Y1"); - idx[2] = GetNodeValueIndex("VELOCITY_Z1"); + // + NS = m_msh->GetCoordinateFlag() / 10; + idx[0] = GetNodeValueIndex("VELOCITY_X1"); + idx[1] = GetNodeValueIndex("VELOCITY_Y1"); + idx[2] = GetNodeValueIndex("VELOCITY_Z1"); + for (i = 0; i < (long)m_msh->GetNodesNumber(false); i++) + for (k = 0; k < NS; k++) + SetNodeValue(i, idx[k], 0.0); + if (type == 1212 || type == 1313) // Multi-phase flow + { + idx[0] = GetNodeValueIndex("VELOCITY_X2"); + idx[1] = GetNodeValueIndex("VELOCITY_Y2"); + idx[2] = GetNodeValueIndex("VELOCITY_Z2"); for (i = 0; i < (long)m_msh->GetNodesNumber(false); i++) - for(k = 0; k < NS; k++) + for (k = 0; k < NS; k++) SetNodeValue(i, idx[k], 0.0); - if(type == 1212 || type == 1313) // Multi-phase flow - { - idx[0] = GetNodeValueIndex("VELOCITY_X2"); - idx[1] = GetNodeValueIndex("VELOCITY_Y2"); - idx[2] = GetNodeValueIndex("VELOCITY_Z2"); - for (i = 0; i < (long)m_msh->GetNodesNumber(false); i++) - for(k = 0; k < NS; k++) - SetNodeValue(i, idx[k], 0.0); - } - // - for (i = 0; i < (long)m_msh->ele_vector.size(); i++) + } + // + for (i = 0; i < (long)m_msh->ele_vector.size(); i++) + { + elem = m_msh->ele_vector[i]; + if (elem->GetMark()) // Marked for use { - elem = m_msh->ele_vector[i]; - if (elem->GetMark()) // Marked for use - { - fem->ConfigElement(elem, m_num->ele_gauss_points); - for(k = 0; k < NS; k++) - fem->ExtropolateGauss(this, k); - } + fem->ConfigElement(elem, m_num->ele_gauss_points); + for (k = 0; k < NS; k++) + fem->ExtropolateGauss(this, k); } } +} /************************************************************************** FEMLib-Method: @@ -10177,52 +10107,52 @@ double CRFProcess::CalcIterationNODError(FiniteElement::ErrorMethod method, bool Programing: 04/2007 WW Implementation **************************************************************************/ - void CRFProcess::Extropolation_MatValue() - { - // if (_pcs_type_name.find("FLOW") == string::npos) - if (!isFlowProcess(this->getProcessType())) - return; - if (additioanl2ndvar_print < 0) - return; +void CRFProcess::Extropolation_MatValue() +{ + // if (_pcs_type_name.find("FLOW") == string::npos) + if (!isFlowProcess(this->getProcessType())) + return; + if (additioanl2ndvar_print < 0) + return; - // - int NS = m_msh->GetCoordinateFlag() / 10; - // - if ((additioanl2ndvar_print > 0) && (additioanl2ndvar_print < 3)) - { - int idx[3]; - idx[0] = GetNodeValueIndex("PERMEABILITY_X1"); - idx[1] = GetNodeValueIndex("PERMEABILITY_Y1"); - if (NS > 2) - idx[2] = GetNodeValueIndex("PERMEABILITY_Z1"); - else - idx[2] = 0; - for (size_t i = 0; i < m_msh->GetNodesNumber(false); i++) - for (int k = 0; k < NS; k++) - SetNodeValue(i, idx[k], 0.0); - } - if (additioanl2ndvar_print > 1) - { - int idxp = GetNodeValueIndex("POROSITY"); - for (size_t i = 0; i < m_msh->GetNodesNumber(false); i++) - SetNodeValue(i, idxp, 0.0); - } - // - continuum = 0; - if (continuum_vector.size() == 2) - continuum = 1; + // + int NS = m_msh->GetCoordinateFlag() / 10; + // + if ((additioanl2ndvar_print > 0) && (additioanl2ndvar_print < 3)) + { + int idx[3]; + idx[0] = GetNodeValueIndex("PERMEABILITY_X1"); + idx[1] = GetNodeValueIndex("PERMEABILITY_Y1"); + if (NS > 2) + idx[2] = GetNodeValueIndex("PERMEABILITY_Z1"); + else + idx[2] = 0; + for (size_t i = 0; i < m_msh->GetNodesNumber(false); i++) + for (int k = 0; k < NS; k++) + SetNodeValue(i, idx[k], 0.0); + } + if (additioanl2ndvar_print > 1) + { + int idxp = GetNodeValueIndex("POROSITY"); + for (size_t i = 0; i < m_msh->GetNodesNumber(false); i++) + SetNodeValue(i, idxp, 0.0); + } + // + continuum = 0; + if (continuum_vector.size() == 2) + continuum = 1; - MeshLib::CElem* elem = NULL; - for (size_t i = 0; i < m_msh->ele_vector.size(); i++) + MeshLib::CElem* elem = NULL; + for (size_t i = 0; i < m_msh->ele_vector.size(); i++) + { + elem = m_msh->ele_vector[i]; + if (elem->GetMark()) // Marked for use { - elem = m_msh->ele_vector[i]; - if (elem->GetMark()) // Marked for use - { - fem->ConfigElement(elem, m_num->ele_gauss_points); - fem->CalcNodeMatParatemer(); - } + fem->ConfigElement(elem, m_num->ele_gauss_points); + fem->CalcNodeMatParatemer(); } } +} /************************************************************************** FEMLib-Method: @@ -10230,21 +10160,21 @@ double CRFProcess::CalcIterationNODError(FiniteElement::ErrorMethod method, bool Programing: 04/2005 OK Implementation **************************************************************************/ - void PCSDelete(const std::string &m_pcs_type_name) +void PCSDelete(const std::string& m_pcs_type_name) +{ + FiniteElement::ProcessType pcs_type(FiniteElement::convertProcessType(m_pcs_type_name)); + CRFProcess* m_pcs = NULL; + for (size_t i = 0; i < pcs_vector.size(); i++) { - FiniteElement::ProcessType pcs_type (FiniteElement::convertProcessType (m_pcs_type_name)); - CRFProcess* m_pcs = NULL; - for (size_t i = 0; i < pcs_vector.size(); i++) + m_pcs = pcs_vector[i]; + // if (m_pcs->_pcs_type_name.compare(m_pcs_type_name) == 0) { TF + if (m_pcs->getProcessType() == pcs_type) { - m_pcs = pcs_vector[i]; - // if (m_pcs->_pcs_type_name.compare(m_pcs_type_name) == 0) { TF - if (m_pcs->getProcessType () == pcs_type) - { - delete m_pcs; - pcs_vector.erase(pcs_vector.begin() + i); - } + delete m_pcs; + pcs_vector.erase(pcs_vector.begin() + i); } } +} /************************************************************************** GeoSys - Function: Reallocation @@ -10254,17 +10184,18 @@ double CRFProcess::CalcIterationNODError(FiniteElement::ErrorMethod method, bool 09/2005 WW Erste Version **************************************************************************/ - template T* resize(T* array, size_t old_size, size_t new_size) - { - T* temp = new T[new_size]; - for(size_t i = 0; i < old_size; i++) - temp[i] = array[i]; - for(size_t i = old_size; i < new_size; i++) - temp[i] = 0; - delete [] array; - array = temp; - return temp; - } +template +T* resize(T* array, size_t old_size, size_t new_size) +{ + T* temp = new T[new_size]; + for (size_t i = 0; i < old_size; i++) + temp[i] = array[i]; + for (size_t i = old_size; i < new_size; i++) + temp[i] = 0; + delete[] array; + array = temp; + return temp; +} /************************************************************************** FEMLib-Method: @@ -10272,140 +10203,139 @@ double CRFProcess::CalcIterationNODError(FiniteElement::ErrorMethod method, bool Programing: 11/2005 MB Implementation **************************************************************************/ -#if !defined(NEW_EQS) && !defined(USE_PETSC) //WW. 07.11.2008. 04.2012 - void CRFProcess::CalcFluxesForCoupling(void) - { - int i, j; - double flux; - long n_index; - long NodeIndex_GW; - long NodeIndex_OLF; - int no_nodes = m_msh->getNumberOfMeshLayers() + 1; - long no_richards_problems = (long) (m_msh->ele_vector.size() - / m_msh->getNumberOfMeshLayers()); - long IndexBottomNode; - long IndexTopNode; - int NoOfGWNodes = 0; - double AverageZ_GW = 0.0; - double AverageZ_OLF = 0.0; - double AverageH_GW = 0.0; - double AverageH_OLF = 0.0; - double dh; - int idxFLUX; - int idxHead_GW; - int idxHead_OLF; - MeshLib::CElem* m_ele_GW = NULL; - MeshLib::CElem* m_ele_OLF = NULL; - - // Get processes - CRFProcess* m_pcs_GW(PCSGet(FiniteElement::GROUNDWATER_FLOW)); - if (!m_pcs_GW) //OK - { - cout << "Fatal error: no GROUNDWATER_FLOW process" << "\n"; - return; - } - CRFProcess* m_pcs_OLF(PCSGet(FiniteElement::OVERLAND_FLOW)); - if (!m_pcs_OLF) //OK - { - cout << "Fatal error: no OVERLAND_FLOW process" << "\n"; - return; - } +#if !defined(NEW_EQS) && !defined(USE_PETSC) // WW. 07.11.2008. 04.2012 +void CRFProcess::CalcFluxesForCoupling(void) +{ + int i, j; + double flux; + long n_index; + long NodeIndex_GW; + long NodeIndex_OLF; + int no_nodes = m_msh->getNumberOfMeshLayers() + 1; + long no_richards_problems = (long)(m_msh->ele_vector.size() / m_msh->getNumberOfMeshLayers()); + long IndexBottomNode; + long IndexTopNode; + int NoOfGWNodes = 0; + double AverageZ_GW = 0.0; + double AverageZ_OLF = 0.0; + double AverageH_GW = 0.0; + double AverageH_OLF = 0.0; + double dh; + int idxFLUX; + int idxHead_GW; + int idxHead_OLF; + MeshLib::CElem* m_ele_GW = NULL; + MeshLib::CElem* m_ele_OLF = NULL; + + // Get processes + CRFProcess* m_pcs_GW(PCSGet(FiniteElement::GROUNDWATER_FLOW)); + if (!m_pcs_GW) // OK + { + cout << "Fatal error: no GROUNDWATER_FLOW process" + << "\n"; + return; + } + CRFProcess* m_pcs_OLF(PCSGet(FiniteElement::OVERLAND_FLOW)); + if (!m_pcs_OLF) // OK + { + cout << "Fatal error: no OVERLAND_FLOW process" + << "\n"; + return; + } - // Get meshes - CFEMesh* m_msh_GW = m_pcs_GW->m_msh; - CFEMesh* m_msh_OLF = m_pcs_OLF->m_msh; + // Get meshes + CFEMesh* m_msh_GW = m_pcs_GW->m_msh; + CFEMesh* m_msh_OLF = m_pcs_OLF->m_msh; - //Get indeces - idxHead_GW = m_pcs_GW->GetNodeValueIndex("HEAD") + 1; - idxHead_OLF = m_pcs_OLF->GetNodeValueIndex("HEAD") + 1; - idxFLUX = GetNodeValueIndex("FLUX") + 1; + // Get indeces + idxHead_GW = m_pcs_GW->GetNodeValueIndex("HEAD") + 1; + idxHead_OLF = m_pcs_OLF->GetNodeValueIndex("HEAD") + 1; + idxFLUX = GetNodeValueIndex("FLUX") + 1; - for (i = 0; i < no_richards_problems; i++) - { - IndexBottomNode = ((i + 1) * no_nodes) - 1; + for (i = 0; i < no_richards_problems; i++) + { + IndexBottomNode = ((i + 1) * no_nodes) - 1; - // ToDo safe somewhere else so that this has to be done only once - //----------------------------------------------------------------- - // Get Nearest GW and OLF Element - GEOLIB::Point pnt (m_msh->nod_vector[IndexBottomNode]->getData()); + // ToDo safe somewhere else so that this has to be done only once + //----------------------------------------------------------------- + // Get Nearest GW and OLF Element + GEOLIB::Point pnt(m_msh->nod_vector[IndexBottomNode]->getData()); - long EleNumber = m_msh_GW->GetNearestELEOnPNT(&pnt); + long EleNumber = m_msh_GW->GetNearestELEOnPNT(&pnt); - //GW and OLF use the same Numbering !!! - m_ele_GW = m_msh_GW->ele_vector[EleNumber]; - m_ele_OLF = m_msh_OLF->ele_vector[EleNumber]; + // GW and OLF use the same Numbering !!! + m_ele_GW = m_msh_GW->ele_vector[EleNumber]; + m_ele_OLF = m_msh_OLF->ele_vector[EleNumber]; - //----------------------------------------------------------------- - // Get Average values for element //ToDo encapsulate //WW: CElement::elemnt_averag??e - NoOfGWNodes = m_ele_OLF->GetNodesNumber(m_msh_GW->getOrder()); - for (j = 0; j < NoOfGWNodes; j++) - { - NodeIndex_GW = m_ele_GW->GetNodeIndex(j); - NodeIndex_OLF = m_ele_OLF->GetNodeIndex(j); + //----------------------------------------------------------------- + // Get Average values for element //ToDo encapsulate //WW: CElement::elemnt_averag??e + NoOfGWNodes = m_ele_OLF->GetNodesNumber(m_msh_GW->getOrder()); + for (j = 0; j < NoOfGWNodes; j++) + { + NodeIndex_GW = m_ele_GW->GetNodeIndex(j); + NodeIndex_OLF = m_ele_OLF->GetNodeIndex(j); - AverageZ_GW += m_pcs_GW->GetNodeValue(NodeIndex_GW, idxHead_GW); - AverageZ_OLF += m_msh_OLF->nod_vector[NodeIndex_OLF]->getData()[2]; - } - AverageZ_GW = AverageZ_GW / NoOfGWNodes; - AverageZ_OLF = AverageZ_OLF / NoOfGWNodes; + AverageZ_GW += m_pcs_GW->GetNodeValue(NodeIndex_GW, idxHead_GW); + AverageZ_OLF += m_msh_OLF->nod_vector[NodeIndex_OLF]->getData()[2]; + } + AverageZ_GW = AverageZ_GW / NoOfGWNodes; + AverageZ_OLF = AverageZ_OLF / NoOfGWNodes; - //----------------------------------------------------------------- - // UsatZone exists -> Flux from this - if (AverageZ_GW < AverageZ_OLF) + //----------------------------------------------------------------- + // UsatZone exists -> Flux from this + if (AverageZ_GW < AverageZ_OLF) + { + n_index = m_msh->Eqs2Global_NodeIndex[IndexBottomNode]; + if (m_msh->nod_vector[IndexBottomNode]->GetMark()) { - n_index = m_msh->Eqs2Global_NodeIndex[IndexBottomNode]; - if (m_msh->nod_vector[IndexBottomNode]->GetMark()) - { - flux = eqs->b[IndexBottomNode]; - //FLUXES IN NEW VERSION WITH VELOCITIES !!!!! - //WAIT FOR SEBASTIANS MASS TRANSPORT IN USAT ZONE !!!!! - //TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST - flux = 0.00001; - //flux = 1; - SetNodeValue(n_index, idxFLUX, flux); - } + flux = eqs->b[IndexBottomNode]; + // FLUXES IN NEW VERSION WITH VELOCITIES !!!!! + // WAIT FOR SEBASTIANS MASS TRANSPORT IN USAT ZONE !!!!! + // TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST + flux = 0.00001; + // flux = 1; + SetNodeValue(n_index, idxFLUX, flux); } + } + //----------------------------------------------------------------- + // No UsatZone -> Calculate Flux from leakage terms + if (AverageZ_GW >= AverageZ_OLF) + { + // SetRichardsNodesToFullySaturated?? + IndexTopNode = i * no_nodes; // Top Node of Richard Column -> Flux for OLF + // Bottom Node of Richards Column -> Flux for GW + IndexBottomNode = ((i + 1) * no_nodes) - 1; //----------------------------------------------------------------- - // No UsatZone -> Calculate Flux from leakage terms - if (AverageZ_GW >= AverageZ_OLF) - { - //SetRichardsNodesToFullySaturated?? - IndexTopNode = i * no_nodes; // Top Node of Richard Column -> Flux for OLF - // Bottom Node of Richards Column -> Flux for GW - IndexBottomNode = ((i + 1) * no_nodes) - 1; - //----------------------------------------------------------------- - // Get Average values for element //ToDo encapsulate - for (j = 0; j < NoOfGWNodes; j++) - { - NodeIndex_GW = m_ele_GW->GetNodeIndex(j); - NodeIndex_OLF = m_ele_OLF->GetNodeIndex(j); - AverageH_GW += m_pcs_GW->GetNodeValue(NodeIndex_GW, - idxHead_GW); - AverageH_OLF += m_pcs_OLF->GetNodeValue(NodeIndex_OLF, - idxHead_OLF); - } - AverageH_GW = AverageH_GW / NoOfGWNodes; - AverageH_OLF = AverageH_OLF / NoOfGWNodes; - //Calculate the vertical leakage - dh = AverageH_GW - AverageH_OLF; - // get kf fully saturated of uppermost element ? - // or user defined value: entry resistance / leakage factor ? - //flux = dh * 0.001; - flux = dh * 1.; + // Get Average values for element //ToDo encapsulate + for (j = 0; j < NoOfGWNodes; j++) + { + NodeIndex_GW = m_ele_GW->GetNodeIndex(j); + NodeIndex_OLF = m_ele_OLF->GetNodeIndex(j); + AverageH_GW += m_pcs_GW->GetNodeValue(NodeIndex_GW, idxHead_GW); + AverageH_OLF += m_pcs_OLF->GetNodeValue(NodeIndex_OLF, idxHead_OLF); + } + AverageH_GW = AverageH_GW / NoOfGWNodes; + AverageH_OLF = AverageH_OLF / NoOfGWNodes; + // Calculate the vertical leakage + dh = AverageH_GW - AverageH_OLF; + // get kf fully saturated of uppermost element ? + // or user defined value: entry resistance / leakage factor ? + // flux = dh * 0.001; + flux = dh * 1.; - //1. Add reacharge value to GW flow -> Add to flux off IndexBottomNode - //Achtung nur zum Testen Source für GW flow durchgehend !!!!!! - //SetNodeValue(IndexBottomNode, idxFLUX, -flux); //H_OLF > H_GW -> + flux_GW - SetNodeValue(IndexBottomNode, idxFLUX, 0.00001); + // 1. Add reacharge value to GW flow -> Add to flux off IndexBottomNode + // Achtung nur zum Testen Source für GW flow durchgehend !!!!!! + // SetNodeValue(IndexBottomNode, idxFLUX, -flux); //H_OLF > H_GW -> + flux_GW + SetNodeValue(IndexBottomNode, idxFLUX, 0.00001); - //2. Add reacharge value to OLF -> Add to flux off IndexTopNode - //H_OLF > H_GW -> - flux_OLF - SetNodeValue(IndexTopNode, idxFLUX, flux); - //3. Set flag to set reacharge to Usat to zero ??? - } + // 2. Add reacharge value to OLF -> Add to flux off IndexTopNode + // H_OLF > H_GW -> - flux_OLF + SetNodeValue(IndexTopNode, idxFLUX, flux); + // 3. Set flag to set reacharge to Usat to zero ??? } } +} #endif /************************************************************************** FEMLib-Method: @@ -10413,20 +10343,20 @@ double CRFProcess::CalcIterationNODError(FiniteElement::ErrorMethod method, bool Programing: 11/2005 MB implementation **************************************************************************/ - void CRFProcess::CopyCouplingNODValues() - { - //Carefull if cpl_variable = primary variable -> need extra column in NodeValueTable ! - int nidx0 = GetNodeValueIndex(m_num->cpl_variable_JOD); +void CRFProcess::CopyCouplingNODValues() +{ + // Carefull if cpl_variable = primary variable -> need extra column in NodeValueTable ! + int nidx0 = GetNodeValueIndex(m_num->cpl_variable_JOD); + for (size_t l = 0; l < m_msh->GetNodesNumber(false); l++) + SetNodeValue(l, nidx0, GetNodeValue(l, nidx0 + 1)); + // if (_pcs_type_name.find("RICHARDS") != string::npos) { //WW + if (this->getProcessType() == FiniteElement::RICHARDS_FLOW) // WW + { + nidx0 = GetNodeValueIndex("SATURATION1"); for (size_t l = 0; l < m_msh->GetNodesNumber(false); l++) SetNodeValue(l, nidx0, GetNodeValue(l, nidx0 + 1)); - // if (_pcs_type_name.find("RICHARDS") != string::npos) { //WW - if (this->getProcessType() == FiniteElement::RICHARDS_FLOW) //WW - { - nidx0 = GetNodeValueIndex("SATURATION1"); - for (size_t l = 0; l < m_msh->GetNodesNumber(false); l++) - SetNodeValue(l, nidx0, GetNodeValue(l, nidx0 + 1)); - } } +} /************************************************************************** FEMLib-Method: @@ -10436,46 +10366,46 @@ double CRFProcess::CalcIterationNODError(FiniteElement::ErrorMethod method, bool 02/2006 WW Modified for the cases of high order element and saturation 08/2008 WW Make it twofold copy: forward and backward **************************************************************************/ - void CRFProcess::CopyTimestepNODValues(bool forward) - { - bool Quadr = false; //WW - if (type == 4 || type == 41) - Quadr = true; +void CRFProcess::CopyTimestepNODValues(bool forward) +{ + bool Quadr = false; // WW + if (type == 4 || type == 41) + Quadr = true; - for (int j = 0; j < pcs_number_of_primary_nvals; j++) + for (int j = 0; j < pcs_number_of_primary_nvals; j++) + { + int nidx0 = GetNodeValueIndex(pcs_primary_function_name[j]); + int nidx1 = nidx0 + 1; + if (!forward) // 08.2008. WW { - int nidx0 = GetNodeValueIndex(pcs_primary_function_name[j]); - int nidx1 = nidx0 + 1; - if (!forward) //08.2008. WW + nidx0++; + nidx1--; + } + for (size_t l = 0; l < m_msh->GetNodesNumber(Quadr); l++) + SetNodeValue(l, nidx0, GetNodeValue(l, nidx1)); + // WW + // if (_pcs_type_name.find("RICHARDS") != string::npos || type == 1212) { //Multiphase. WW + // Multiphase. WW + if (this->getProcessType() == FiniteElement::RICHARDS_FLOW || type == 1212 || type == 42) + { + if (j == 1 && (type == 1212 || type == 42)) // Multiphase. WW + continue; + if (j == 0) + nidx0 = GetNodeValueIndex("SATURATION1"); + else if (j == 1) + nidx0 = GetNodeValueIndex("SATURATION2"); + nidx1 = nidx0 + 1; + if (!forward) // 27.08.2008. WW { nidx0++; nidx1--; } - for (size_t l = 0; l < m_msh->GetNodesNumber(Quadr); l++) + // + for (size_t l = 0; l < m_msh->GetNodesNumber(false); l++) SetNodeValue(l, nidx0, GetNodeValue(l, nidx1)); - //WW - // if (_pcs_type_name.find("RICHARDS") != string::npos || type == 1212) { //Multiphase. WW - //Multiphase. WW - if (this->getProcessType() == FiniteElement::RICHARDS_FLOW || type == 1212 || type == 42) - { - if (j == 1 && (type == 1212 || type == 42)) // Multiphase. WW - continue; - if (j == 0) - nidx0 = GetNodeValueIndex("SATURATION1"); - else if (j == 1) - nidx0 = GetNodeValueIndex("SATURATION2"); - nidx1 = nidx0 + 1; - if (!forward) //27.08.2008. WW - { - nidx0++; - nidx1--; - } - // - for (size_t l = 0; l < m_msh->GetNodesNumber(false); l++) - SetNodeValue(l, nidx0, GetNodeValue(l, nidx1)); - } } } +} /************************************************************************** FEMLib-Method: @@ -10483,38 +10413,42 @@ double CRFProcess::CalcIterationNODError(FiniteElement::ErrorMethod method, bool Programing: 3/2012 JT. Based on the nodal version **************************************************************************/ - void CRFProcess::CopyTimestepELEValues(bool forward) - { - size_t j, nvals, nidx0, nidx1; - long iel, num_ele; - bool copy_porosity = true; - nvals = ele_val_name_vector.size(); - if(nvals < 2) return; // then we don't have 2 time levels of anything - num_ele = (long)m_msh->ele_vector.size(); +void CRFProcess::CopyTimestepELEValues(bool forward) +{ + size_t j, nvals, nidx0, nidx1; + long iel, num_ele; + bool copy_porosity = true; + nvals = ele_val_name_vector.size(); + if (nvals < 2) + return; // then we don't have 2 time levels of anything + num_ele = (long)m_msh->ele_vector.size(); // #ifdef GEM_REACT - // do nothing as porosity update is handled by REACT_GEMS after!! flow and transport solution - copy_porosity = false; + // do nothing as porosity update is handled by REACT_GEMS after!! flow and transport solution + copy_porosity = false; #endif -// - for(j = 0; j < nvals-1; j++) + // + for (j = 0; j < nvals - 1; j++) + { + if (ele_val_name_vector[j].compare(ele_val_name_vector[j + 1]) + != 0) // If not the same, then we only have a single time slot + continue; + if (ele_val_name_vector[j].find("POROSITY") != string::npos && !copy_porosity) // Porosity + continue; + // + nidx0 = j; + nidx1 = j + 1; + if (!forward) { - if(ele_val_name_vector[j].compare(ele_val_name_vector[j+1]) != 0) // If not the same, then we only have a single time slot - continue; - if(ele_val_name_vector[j].find("POROSITY") != string::npos && !copy_porosity) // Porosity - continue; - // - nidx0 = j; - nidx1 = j+1; - if(!forward){ - nidx0++; - nidx1--; - } - for(iel = 0; iel < num_ele; iel++){ - SetElementValue(iel,nidx0,GetElementValue(iel,nidx1)); - } + nidx0++; + nidx1--; + } + for (iel = 0; iel < num_ele; iel++) + { + SetElementValue(iel, nidx0, GetElementValue(iel, nidx1)); } } +} /************************************************************************** FEMLib-Method: @@ -10523,33 +10457,35 @@ double CRFProcess::CalcIterationNODError(FiniteElement::ErrorMethod method, bool 03/2006 SB Implementation last modified: **************************************************************************/ - int PCSGetPCSIndex(const string &pcs_type_name, const string &comp_name) - { - FiniteElement::ProcessType pcs_type (FiniteElement::convertProcessType (pcs_type_name)); +int PCSGetPCSIndex(const string& pcs_type_name, const string& comp_name) +{ + FiniteElement::ProcessType pcs_type(FiniteElement::convertProcessType(pcs_type_name)); - CRFProcess* m_pcs = NULL; - int i, pcs_no; - int no_processes = (int) pcs_vector.size(); - string testname; - pcs_no = -1; - for (i = 0; i < no_processes; i++) + CRFProcess* m_pcs = NULL; + int i, pcs_no; + int no_processes = (int)pcs_vector.size(); + string testname; + pcs_no = -1; + for (i = 0; i < no_processes; i++) + { + m_pcs = pcs_vector[i]; + // if (m_pcs->pcs_type_name.compare(pcs_type_name) == 0) { + if (m_pcs->getProcessType() == pcs_type) { - m_pcs = pcs_vector[i]; - // if (m_pcs->pcs_type_name.compare(pcs_type_name) == 0) { - if (m_pcs->getProcessType () == pcs_type) + testname = m_pcs->pcs_primary_function_name[0]; + if (testname.compare(comp_name) == 0) { - testname = m_pcs->pcs_primary_function_name[0]; - if (testname.compare(comp_name) == 0) - { - // cout << " Found in PCSGetbyTypeandCompName for PCSType/Compname " << pcs_type_name << ", " << comp_name; - // cout << " Process number " << m_pcs->pcs_number << ", compnumber " << m_pcs->pcs_component_number << "\n"; - pcs_no = i; - return pcs_no; - } + // cout << " Found in PCSGetbyTypeandCompName for PCSType/Compname " << pcs_type_name << ", " << + // comp_name; + // cout << " Process number " << m_pcs->pcs_number << ", compnumber " << + // m_pcs->pcs_component_number << "\n"; + pcs_no = i; + return pcs_no; } } - return pcs_no; } + return pcs_no; +} /************************************************************************** FEMLib-Method: @@ -10559,94 +10495,92 @@ double CRFProcess::CalcIterationNODError(FiniteElement::ErrorMethod method, bool last modified: 10/2010 TF restructured function **************************************************************************/ - CRFProcess* PCSGet(const std::string &pcs_type_name, const std::string &comp_name) - { - FiniteElement::ProcessType pcs_type (FiniteElement::convertProcessType (pcs_type_name)); - size_t no_processes (pcs_vector.size()); - for (size_t i = 0; i < no_processes; i++) - // if (pcs_vector[i]->pcs_type_name.compare(pcs_type_name) == 0) { // TF - if (pcs_vector[i]->getProcessType () == pcs_type) - if (comp_name.compare (pcs_vector[i]->pcs_primary_function_name[0]) - == 0) - return pcs_vector[i]; +CRFProcess* PCSGet(const std::string& pcs_type_name, const std::string& comp_name) +{ + FiniteElement::ProcessType pcs_type(FiniteElement::convertProcessType(pcs_type_name)); + size_t no_processes(pcs_vector.size()); + for (size_t i = 0; i < no_processes; i++) + // if (pcs_vector[i]->pcs_type_name.compare(pcs_type_name) == 0) { // TF + if (pcs_vector[i]->getProcessType() == pcs_type) + if (comp_name.compare(pcs_vector[i]->pcs_primary_function_name[0]) == 0) + return pcs_vector[i]; - return NULL; - } + return NULL; +} - CRFProcess* PCSGet(FiniteElement::ProcessType pcs_type, const std::string &comp_name) - { - size_t no_processes (pcs_vector.size()); - for (size_t i = 0; i < no_processes; i++) - if (pcs_vector[i]->getProcessType () == pcs_type) - if (comp_name.compare (pcs_vector[i]->pcs_primary_function_name[0]) - == 0) - return pcs_vector[i]; +CRFProcess* PCSGet(FiniteElement::ProcessType pcs_type, const std::string& comp_name) +{ + size_t no_processes(pcs_vector.size()); + for (size_t i = 0; i < no_processes; i++) + if (pcs_vector[i]->getProcessType() == pcs_type) + if (comp_name.compare(pcs_vector[i]->pcs_primary_function_name[0]) == 0) + return pcs_vector[i]; - return NULL; - } + return NULL; +} /************************************************************************** PCSLib-Method: 12/2005 OK Implementation **************************************************************************/ - CRFProcess* PCSGet(const string &var_name,bool bdummy) +CRFProcess* PCSGet(const string& var_name, bool bdummy) +{ + string pcs_var_name; + CRFProcess* m_pcs = NULL; + bdummy = bdummy; // WW + for (size_t i = 0; i < pcs_vector.size(); i++) { - string pcs_var_name; - CRFProcess* m_pcs = NULL; - bdummy = bdummy; //WW - for(size_t i = 0; i < pcs_vector.size(); i++) + m_pcs = pcs_vector[i]; + for (size_t j = 0; j < m_pcs->GetPrimaryVNumber(); j++) { - m_pcs = pcs_vector[i]; - for(size_t j = 0; j < m_pcs->GetPrimaryVNumber(); j++) - { - pcs_var_name = m_pcs->pcs_primary_function_name[j]; - if(pcs_var_name.compare(var_name) == 0) - return m_pcs; - } - for(size_t j = 0; j < m_pcs->GetSecondaryVNumber(); j++) - { - pcs_var_name = m_pcs->pcs_secondary_function_name[j]; - if(pcs_var_name.compare(var_name) == 0) - return m_pcs; - } + pcs_var_name = m_pcs->pcs_primary_function_name[j]; + if (pcs_var_name.compare(var_name) == 0) + return m_pcs; + } + for (size_t j = 0; j < m_pcs->GetSecondaryVNumber(); j++) + { + pcs_var_name = m_pcs->pcs_secondary_function_name[j]; + if (pcs_var_name.compare(var_name) == 0) + return m_pcs; } - return NULL; } + return NULL; +} /************************************************************************** PCSLib-Method: 05/2006 CMCD Implementation **************************************************************************/ - CRFProcess* PCSGetFluxProcess() - { - CRFProcess* m_pcs = NULL; - bool found = false; - const size_t no_processes (pcs_vector.size()); +CRFProcess* PCSGetFluxProcess() +{ + CRFProcess* m_pcs = NULL; + bool found = false; + const size_t no_processes(pcs_vector.size()); - for (size_t i = 0; i < no_processes; i++) + for (size_t i = 0; i < no_processes; i++) + { + // if (pcs_vector[i]->_pcs_type_name == "LIQUID_FLOW") { // TF + if (pcs_vector[i]->getProcessType() == FiniteElement::LIQUID_FLOW) { - // if (pcs_vector[i]->_pcs_type_name == "LIQUID_FLOW") { // TF - if (pcs_vector[i]->getProcessType () == FiniteElement::LIQUID_FLOW) - { - m_pcs = pcs_vector[i]; - found = true; - } - // if (pcs_vector[i]->_pcs_type_name == "GROUNDWATER_FLOW") { - if (pcs_vector[i]->getProcessType() == FiniteElement::GROUNDWATER_FLOW) - { - m_pcs = pcs_vector[i]; - found = true; - } - if (pcs_vector[i]->getProcessType () == FiniteElement::RICHARDS_FLOW) - { - m_pcs = pcs_vector[i]; - found = true; - } - if (found) - return m_pcs; + m_pcs = pcs_vector[i]; + found = true; } - return NULL; + // if (pcs_vector[i]->_pcs_type_name == "GROUNDWATER_FLOW") { + if (pcs_vector[i]->getProcessType() == FiniteElement::GROUNDWATER_FLOW) + { + m_pcs = pcs_vector[i]; + found = true; + } + if (pcs_vector[i]->getProcessType() == FiniteElement::RICHARDS_FLOW) + { + m_pcs = pcs_vector[i]; + found = true; + } + if (found) + return m_pcs; } + return NULL; +} /************************************************************************* GeoSys-FEM Function: @@ -10655,92 +10589,92 @@ double CRFProcess::CalcIterationNODError(FiniteElement::ErrorMethod method, bool Programming: 02/2007 WW Implementation **************************************************************************/ - void CRFProcess::CalcSecondaryVariablesUnsaturatedFlow(bool initial) - { - int ii, jj; - long i; - double p_cap; - int idxp,idxcp,idxS; - //---------------------------------------------- - vector secondSNames; - vector secondCPNames; - secondSNames.push_back("SATURATION1"); - if(type == 1212 || type == 42) // Multiphase flow - secondCPNames.push_back("PRESSURE1"); - else - secondCPNames.push_back("PRESSURE_CAP1"); - if(continuum_vector.size() == 2) - { - secondSNames.push_back("SATURATION2"); - secondCPNames.push_back("PRESSURE_CAP2"); - } - - // - CElem* elem = NULL; - CFiniteElementStd* fem = GetAssembler(); +void CRFProcess::CalcSecondaryVariablesUnsaturatedFlow(bool initial) +{ + int ii, jj; + long i; + double p_cap; + int idxp, idxcp, idxS; + //---------------------------------------------- + vector secondSNames; + vector secondCPNames; + secondSNames.push_back("SATURATION1"); + if (type == 1212 || type == 42) // Multiphase flow + secondCPNames.push_back("PRESSURE1"); + else + secondCPNames.push_back("PRESSURE_CAP1"); + if (continuum_vector.size() == 2) + { + secondSNames.push_back("SATURATION2"); + secondCPNames.push_back("PRESSURE_CAP2"); + } + + // + CElem* elem = NULL; + CFiniteElementStd* fem = GetAssembler(); + //---------------------------------------------------------------------- + for (ii = 0; ii < (int)secondSNames.size(); ii++) + { + idxS = GetNodeValueIndex(secondSNames[ii].c_str()) + 1; + if (type == 1212 || type == 42) // Multiphase flow + { + jj = ii; + if (type == 42) + jj += problem_dimension_dm; + idxcp = GetNodeValueIndex(pcs_primary_function_name[jj]) + 1; + idxp = GetNodeValueIndex("PRESSURE_W"); + } + else + { + idxp = GetNodeValueIndex(pcs_primary_function_name[ii]) + 1; + idxcp = GetNodeValueIndex(secondCPNames[ii].c_str()); + } //---------------------------------------------------------------------- - for(ii = 0; ii < (int)secondSNames.size(); ii++) + // Capillary pressure + for (i = 0; i < (long)m_msh->GetNodesNumber(false); i++) { - idxS = GetNodeValueIndex(secondSNames[ii].c_str()) + 1; - if(type == 1212 || type == 42) // Multiphase flow + // Copy the new saturation to the old level + // + if (type == 1212 || type == 42) // Multiphase flow { - jj = ii; - if(type == 42) - jj += problem_dimension_dm; - idxcp = GetNodeValueIndex(pcs_primary_function_name[jj]) + 1; - idxp = GetNodeValueIndex("PRESSURE_W"); + // p_w = p_g-p_c + p_cap = GetNodeValue(i, idxcp + 2) - GetNodeValue(i, idxcp); + SetNodeValue(i, idxp, p_cap); } else { - idxp = GetNodeValueIndex(pcs_primary_function_name[ii]) + 1; - idxcp = GetNodeValueIndex(secondCPNames[ii].c_str()); - } - //---------------------------------------------------------------------- - // Capillary pressure - for(i = 0; i < (long)m_msh->GetNodesNumber(false); i++) - { - // Copy the new saturation to the old level - // - if(type == 1212 || type == 42) // Multiphase flow - { - // p_w = p_g-p_c - p_cap = GetNodeValue(i,idxcp + 2) - GetNodeValue(i,idxcp); - SetNodeValue(i,idxp,p_cap); - } - else - { - p_cap = -GetNodeValue(i,idxp); - SetNodeValue(i,idxcp,p_cap); - } - SetNodeValue(i,idxS, 0.0); + p_cap = -GetNodeValue(i, idxp); + SetNodeValue(i, idxcp, p_cap); } + SetNodeValue(i, idxS, 0.0); } - // Cal S - for(ii = 0; ii < (int)secondSNames.size(); ii++) + } + // Cal S + for (ii = 0; ii < (int)secondSNames.size(); ii++) + { + continuum = ii; + for (i = 0; i < (long)m_msh->ele_vector.size(); i++) { - continuum = ii; - for(i = 0; i < (long)m_msh->ele_vector.size(); i++) + elem = m_msh->ele_vector[i]; + if (elem->GetMark()) // Marked for use { - elem = m_msh->ele_vector[i]; - if (elem->GetMark()) // Marked for use - { - elem->SetOrder(false); - fem->ConfigElement(elem, m_num->ele_gauss_points, false); - fem->CalcSatution(); - } + elem->SetOrder(false); + fem->ConfigElement(elem, m_num->ele_gauss_points, false); + fem->CalcSatution(); } } - // - if(!initial) - return; - //---------- - for(ii = 0; ii < (int)secondSNames.size(); ii++) - { - idxS = GetNodeValueIndex(secondSNames[ii].c_str()) + 1; - for(i = 0; i < (long)m_msh->GetNodesNumber(false); i++) - SetNodeValue(i,idxS - 1, GetNodeValue(i, idxS)); - } } + // + if (!initial) + return; + //---------- + for (ii = 0; ii < (int)secondSNames.size(); ii++) + { + idxS = GetNodeValueIndex(secondSNames[ii].c_str()) + 1; + for (i = 0; i < (long)m_msh->GetNodesNumber(false); i++) + SetNodeValue(i, idxS - 1, GetNodeValue(i, idxS)); + } +} /************************************************************************* GeoSys-FEM Function: @@ -10760,10 +10694,10 @@ void CRFProcess::CalcSecondaryVariablesTNEQ() const int idx_nodal_react_rate = this->GetNodeValueIndex("REACT_RATE_N"); const int idx_nodal_solid_density = this->GetNodeValueIndex("SOLID_DENSITY_N"); - for (size_t idx_node=0; idx_nodeSetNodeValue( idx_node, idx_nodal_react_rate, 0.0 ); - this->SetNodeValue( idx_node, idx_nodal_solid_density, 0.0); + this->SetNodeValue(idx_node, idx_nodal_react_rate, 0.0); + this->SetNodeValue(idx_node, idx_nodal_solid_density, 0.0); } // loop over all the elements and update the rho_s values. @@ -10771,16 +10705,15 @@ void CRFProcess::CalcSecondaryVariablesTNEQ() for (i = 0; i < mesh_ele_vector_size; i++) { elem = m_msh->ele_vector[i]; - if (elem->GetMark()) // Marked for use + if (elem->GetMark()) // Marked for use { fem->ConfigElement(elem, m_num->ele_gauss_points); - fem->UpdateSolidDensity(i); // HS, thermal storage reactions - fem->ExtrapolateGauss_ReactRate_TNEQ_TES( this ); // HS added 19.02.2013 + fem->UpdateSolidDensity(i); // HS, thermal storage reactions + fem->ExtrapolateGauss_ReactRate_TNEQ_TES(this); // HS added 19.02.2013 } } } - /************************************************************************* GeoSys-FEM Function: Task: Updating rho_s values in TES @@ -10793,31 +10726,30 @@ void CRFProcess::CalcSecondaryVariablesTES() // TODO [CL] merge with TNEQ // loop over all the nodes, // clean the nodal reaction rate values - const size_t node_vector_size = m_msh->nod_vector.size(); - const int idx_nodal_react_rate = GetNodeValueIndex("REACT_RATE_N"); + const size_t node_vector_size = m_msh->nod_vector.size(); + const int idx_nodal_react_rate = GetNodeValueIndex("REACT_RATE_N"); const int idx_nodal_solid_density = GetNodeValueIndex("SOLID_DENSITY_N"); - for (size_t idx_node=0; idx_nodeele_vector.size()); for (size_t i = 0; i < mesh_ele_vector_size; i++) { - CElem *const elem = m_msh->ele_vector[i]; - if (elem->GetMark()) // Marked for use + CElem* const elem = m_msh->ele_vector[i]; + if (elem->GetMark()) // Marked for use { fem->ConfigElement(elem, m_num->ele_gauss_points); - fem->UpdateSolidDensity(i); // HS, thermal storage reactions - fem->ExtrapolateGauss_ReactRate_TNEQ_TES( this ); // HS added 19.02.2013 + fem->UpdateSolidDensity(i); // HS, thermal storage reactions + fem->ExtrapolateGauss_ReactRate_TNEQ_TES(this); // HS added 19.02.2013 } } } - /************************************************************************* GeoSys-FEM Function: Task: Updating secondary variables for Multiphase flow in PS_GLOBAL @@ -10825,92 +10757,86 @@ void CRFProcess::CalcSecondaryVariablesTES() Programming: 03/2009 PCH Implementation **************************************************************************/ - void CRFProcess::CalcSecondaryVariablesPSGLOBAL() - { - long i; - int ndx_pressure1, ndx_p_cap, ndx_pressure2, ndx_s_wetting; //WW, ndx_s_nonwetting; - - // The primary variables - ndx_pressure1 = GetNodeValueIndex("PRESSURE1"); - //WW ndx_s_nonwetting = GetNodeValueIndex("SATURATION2"); - - // The secondary variables - ndx_pressure2 = GetNodeValueIndex("PRESSURE2"); - ndx_p_cap = GetNodeValueIndex("PRESSURE_CAP"); - ndx_s_wetting = GetNodeValueIndex("SATURATION1"); - - double pressure1, pressure2, p_cap, s_wetting; - for(i = 0; i < (long)m_msh->GetNodesNumber(false); i++) - { - pressure1 = GetNodeValue(i,ndx_pressure1 + 1); // New - pressure2 = GetNodeValue(i,ndx_pressure1); // Old - - // Let's get capillary pressure before updating pressure2 - // by accessing the primary variable of the saturation equation - // not the secondary variable of it. - int ndx_sat2 = GetNodeValueIndex("SATURATION2"); - double sat2 = GetNodeValue(i,ndx_sat2 + 1); - // Due to the iterative solution scheme in solving Snw with no - // explicit boundary condition for non-zero flux condition, - // Snw may become negative particularly the density difference - // between two fluids is big. To prevent negative Snw, the - // saturation restriction added. - CMediumProperties* mmp = NULL; - if(sat2 != .0 && mmp_vector.size() > 1) - { - double sum = 0.0; - CNode* thisNode = m_msh->nod_vector[i]; - int NumOfNeighborElements = - (int)thisNode->getConnectedElementIDs().size(); - // Harmonic mean - for(int i = 0; i < NumOfNeighborElements; ++i) - { - // Mount neighboring elemenets and get the corresponding material group one by one. - size_t eleIdx = thisNode->getConnectedElementIDs()[i]; - CElem* thisEle = m_msh->ele_vector[eleIdx]; - size_t matgrp = thisEle->GetPatchIndex(); - mmp = mmp_vector[matgrp]; - mmp->mode = 2; - sum += 1.0 / sat2; - } - sat2 = (double)NumOfNeighborElements / sum; - } - else - mmp = mmp_vector[0]; - s_wetting = 1.0 - sat2; - // Assigning the secondary variable, Sw - SetNodeValue(i,ndx_s_wetting,s_wetting); - // Assigning the primary variable Snw here one more time - // to completely bound the range of saturation - // SetNodeValue(i,ndx_s_nonwetting,sat2); - // SetNodeValue(i,ndx_s_nonwetting+1,sat2); - - // Assigning the secondary variable, Pc - if((mmp->capillary_pressure_model == 4 || mmp->capillary_pressure_model == 6) - && fabs(mmp->capillary_pressure_values[0]) < DBL_EPSILON) +void CRFProcess::CalcSecondaryVariablesPSGLOBAL() +{ + long i; + int ndx_pressure1, ndx_p_cap, ndx_pressure2, ndx_s_wetting; // WW, ndx_s_nonwetting; + + // The primary variables + ndx_pressure1 = GetNodeValueIndex("PRESSURE1"); + // WW ndx_s_nonwetting = GetNodeValueIndex("SATURATION2"); + + // The secondary variables + ndx_pressure2 = GetNodeValueIndex("PRESSURE2"); + ndx_p_cap = GetNodeValueIndex("PRESSURE_CAP"); + ndx_s_wetting = GetNodeValueIndex("SATURATION1"); + + double pressure1, pressure2, p_cap, s_wetting; + for (i = 0; i < (long)m_msh->GetNodesNumber(false); i++) + { + pressure1 = GetNodeValue(i, ndx_pressure1 + 1); // New + pressure2 = GetNodeValue(i, ndx_pressure1); // Old + + // Let's get capillary pressure before updating pressure2 + // by accessing the primary variable of the saturation equation + // not the secondary variable of it. + int ndx_sat2 = GetNodeValueIndex("SATURATION2"); + double sat2 = GetNodeValue(i, ndx_sat2 + 1); + // Due to the iterative solution scheme in solving Snw with no + // explicit boundary condition for non-zero flux condition, + // Snw may become negative particularly the density difference + // between two fluids is big. To prevent negative Snw, the + // saturation restriction added. + CMediumProperties* mmp = NULL; + if (sat2 != .0 && mmp_vector.size() > 1) + { + double sum = 0.0; + CNode* thisNode = m_msh->nod_vector[i]; + int NumOfNeighborElements = (int)thisNode->getConnectedElementIDs().size(); + // Harmonic mean + for (int i = 0; i < NumOfNeighborElements; ++i) { - p_cap = 0.; + // Mount neighboring elemenets and get the corresponding material group one by one. + size_t eleIdx = thisNode->getConnectedElementIDs()[i]; + CElem* thisEle = m_msh->ele_vector[eleIdx]; + size_t matgrp = thisEle->GetPatchIndex(); + mmp = mmp_vector[matgrp]; + mmp->mode = 2; + sum += 1.0 / sat2; } + sat2 = (double)NumOfNeighborElements / sum; + } + else + mmp = mmp_vector[0]; + s_wetting = 1.0 - sat2; + // Assigning the secondary variable, Sw + SetNodeValue(i, ndx_s_wetting, s_wetting); + // Assigning the primary variable Snw here one more time + // to completely bound the range of saturation + // SetNodeValue(i,ndx_s_nonwetting,sat2); + // SetNodeValue(i,ndx_s_nonwetting+1,sat2); + + // Assigning the secondary variable, Pc + if ((mmp->capillary_pressure_model == 4 || mmp->capillary_pressure_model == 6) + && fabs(mmp->capillary_pressure_values[0]) < DBL_EPSILON) + { + p_cap = 0.; + } + else + { + if (mmp_vector.size() > 1) + p_cap = GetCapillaryPressureOnNodeByNeighobringElementPatches(i, 2, 1.0 - sat2); else - { - if(mmp_vector.size() > 1) - p_cap = GetCapillaryPressureOnNodeByNeighobringElementPatches( - i, - 2, - 1.0 - - sat2); - else - p_cap = mmp->CapillaryPressureFunction(1.0 - sat2); - } + p_cap = mmp->CapillaryPressureFunction(1.0 - sat2); + } - SetNodeValue(i,ndx_p_cap,p_cap); + SetNodeValue(i, ndx_p_cap, p_cap); - pressure2 = pressure1 + p_cap; - // Assigning the secondary variables, Pnw - SetNodeValue(i,ndx_pressure2,pressure2); - } + pressure2 = pressure1 + p_cap; + // Assigning the secondary variables, Pnw + SetNodeValue(i, ndx_pressure2, pressure2); } - +} /************************************************************************* GeoSys-FEM Function: @@ -10921,35 +10847,34 @@ Task: Updating secondary variables for Multiphase flow in PS_GLOBAL **************************************************************************/ void CRFProcess::CalcSecondaryVariablesLiquidFlow() { - long i; - int ndx_dens; - double var[3]={0,0,0}; - bool heattransport = false; - - ndx_dens = GetNodeValueIndex("DENSITY1"); - - CRFProcess *m_pcs = NULL; - if((m_pcs = PCSGet("HEAT_TRANSPORT"))) - heattransport=true; - - CFluidProperties* m_mfp = NULL; - m_mfp = mfp_vector[0]; + long i; + int ndx_dens; + double var[3] = {0, 0, 0}; + bool heattransport = false; - double dens; - for(i=0;i<(long)m_msh->GetNodesNumber(false);i++) - { - // get pressure - var[0] = this->GetNodeValue(i,this->GetNodeValueIndex("PRESSURE1")); - // get temperature - if(heattransport) - var[1] = m_pcs->GetNodeValue(i,m_pcs->GetNodeValueIndex("TEMPERATURE1")); - // Set salinity - var[2] = 0.0; - dens = m_mfp->Density(var); - // Assigning the secondary variable - SetNodeValue(i,ndx_dens,dens); - } + ndx_dens = GetNodeValueIndex("DENSITY1"); + CRFProcess* m_pcs = NULL; + if ((m_pcs = PCSGet("HEAT_TRANSPORT"))) + heattransport = true; + + CFluidProperties* m_mfp = NULL; + m_mfp = mfp_vector[0]; + + double dens; + for (i = 0; i < (long)m_msh->GetNodesNumber(false); i++) + { + // get pressure + var[0] = this->GetNodeValue(i, this->GetNodeValueIndex("PRESSURE1")); + // get temperature + if (heattransport) + var[1] = m_pcs->GetNodeValue(i, m_pcs->GetNodeValueIndex("TEMPERATURE1")); + // Set salinity + var[2] = 0.0; + dens = m_mfp->Density(var); + // Assigning the secondary variable + SetNodeValue(i, ndx_dens, dens); + } } /************************************************************************** @@ -10965,23 +10890,21 @@ void CRFProcess::CalcSecondaryVariablesLiquidFlow() 03/2009 PCH Implementation last modification: *************************************************************************/ - double CRFProcess::GetCapillaryPressureOnNodeByNeighobringElementPatches(int nodeIdx, - int meanOption, - double Sw) - { - double p_cap = 0.0, sum = 0.0; +double CRFProcess::GetCapillaryPressureOnNodeByNeighobringElementPatches(int nodeIdx, int meanOption, double Sw) +{ + double p_cap = 0.0, sum = 0.0; - CNode* thisNode = m_msh->nod_vector[nodeIdx]; - int NumOfNeighborElements = (int)thisNode->getConnectedElementIDs().size(); + CNode* thisNode = m_msh->nod_vector[nodeIdx]; + int NumOfNeighborElements = (int)thisNode->getConnectedElementIDs().size(); - switch (meanOption) - { + switch (meanOption) + { case 0: break; case 1: break; - case 2: // Harmonic mean - for(int i = 0; i < NumOfNeighborElements; ++i) + case 2: // Harmonic mean + for (int i = 0; i < NumOfNeighborElements; ++i) { // Mount neighboring elemenets and get the corresponding material group one by one. int eleIdx = thisNode->getConnectedElementIDs()[i]; @@ -10994,17 +10917,17 @@ void CRFProcess::CalcSecondaryVariablesLiquidFlow() break; default: - cout << "Please define the option for various means!" << "\n"; - cout << - "The code stops at GetCapillaryPressureOnNodeByNeighobringElementPatches function!" + cout << "Please define the option for various means!" + << "\n"; + cout << "The code stops at GetCapillaryPressureOnNodeByNeighobringElementPatches function!" << "\n"; abort(); break; - } - - return p_cap; } + return p_cap; +} + /************************************************************************* GeoSys-FEM Function: Task: Calculates saturation for richards flow, @@ -11014,91 +10937,79 @@ void CRFProcess::CalcSecondaryVariablesLiquidFlow() Programming: 06/2007 JOD Implementation **************************************************************************/ - void CRFProcess::CalcSaturationRichards(int timelevel, bool update) - { - double p_cap, saturation, volume_sum; - int idxp, idxcp, idxS, idx_tS = -1; - const size_t number_continuum (continuum_vector.size()); - size_t i_s, i_e; +void CRFProcess::CalcSaturationRichards(int timelevel, bool update) +{ + double p_cap, saturation, volume_sum; + int idxp, idxcp, idxS, idx_tS = -1; + const size_t number_continuum(continuum_vector.size()); + size_t i_s, i_e; - CMediumProperties* m_mmp = NULL; - CElem* elem = NULL; - //WW CFiniteElementStd* fem = GetAssembler(); + CMediumProperties* m_mmp = NULL; + CElem* elem = NULL; + // WW CFiniteElementStd* fem = GetAssembler(); - if (continuum_ic) //Create IC: for both continua - { - i_s = 0; - i_e = number_continuum; - } - else - { - i_s = continuum; - i_e = continuum + 1; - } + if (continuum_ic) // Create IC: for both continua + { + i_s = 0; + i_e = number_continuum; + } + else + { + i_s = continuum; + i_e = continuum + 1; + } + + for (size_t i_pv = i_s; i_pv < i_e; i_pv++) + { + idxp = GetNodeValueIndex(pcs_primary_function_name[i_pv]) + timelevel; + idxS = GetNodeValueIndex(pcs_secondary_function_name[i_pv * number_continuum]) + timelevel; + idxcp = GetNodeValueIndex(pcs_secondary_function_name[i_pv * number_continuum + number_continuum * 2]) + + timelevel; + if (continuum_vector.size() > 1) + idx_tS = GetNodeValueIndex("TOTAL_SATURATION") + timelevel; - for (size_t i_pv = i_s; i_pv < i_e; i_pv++) + for (long i = 0; i < (long)m_msh->GetNodesNumber(false); i++) { - idxp = GetNodeValueIndex(pcs_primary_function_name[i_pv]) + timelevel; - idxS = GetNodeValueIndex(pcs_secondary_function_name[i_pv - * number_continuum]) + - timelevel; - idxcp = GetNodeValueIndex(pcs_secondary_function_name[i_pv - * number_continuum + - number_continuum * - 2]) + timelevel; + // Capillary pressure + p_cap = -GetNodeValue(i, idxp); + if (timelevel == 1 && update) + SetNodeValue(i, idxcp - 1, GetNodeValue(i, idxcp)); + SetNodeValue(i, idxcp, p_cap); + if (timelevel == 1 && update) + SetNodeValue(i, idxS - 1, GetNodeValue(i, idxS)); + + // Liquid saturation if (continuum_vector.size() > 1) - idx_tS = GetNodeValueIndex("TOTAL_SATURATION") + timelevel; - - for (long i = 0; i < (long) m_msh->GetNodesNumber(false); i++) - { - // Capillary pressure - p_cap = -GetNodeValue(i, idxp); - if (timelevel == 1 && update) - SetNodeValue(i, idxcp - 1, GetNodeValue(i, idxcp)); - SetNodeValue(i, idxcp, p_cap); - if (timelevel == 1 && update) - SetNodeValue(i, idxS - 1, GetNodeValue(i, idxS)); - - // Liquid saturation - if (continuum_vector.size() > 1) - SetNodeValue(i, idx_tS, 0.0); - // + SetNodeValue(i, idx_tS, 0.0); + // - saturation = 0., volume_sum = 0.; - size_t elemsCnode = - m_msh->nod_vector[i]->getConnectedElementIDs().size(); + saturation = 0., volume_sum = 0.; + size_t elemsCnode = m_msh->nod_vector[i]->getConnectedElementIDs().size(); - for (size_t j = 0; j < elemsCnode; j++) - { - elem = - m_msh->ele_vector[m_msh->nod_vector[i]-> - getConnectedElementIDs() - [j]]; - m_mmp = mmp_vector[elem->GetPatchIndex()]; - volume_sum += elem->volume; - saturation += m_mmp->SaturationCapillaryPressureFunction(p_cap) * elem->volume; - } - saturation /= volume_sum; - SetNodeValue(i, idxS, saturation); + for (size_t j = 0; j < elemsCnode; j++) + { + elem = m_msh->ele_vector[m_msh->nod_vector[i]->getConnectedElementIDs()[j]]; + m_mmp = mmp_vector[elem->GetPatchIndex()]; + volume_sum += elem->volume; + saturation += m_mmp->SaturationCapillaryPressureFunction(p_cap) * elem->volume; } + saturation /= volume_sum; + SetNodeValue(i, idxS, saturation); } + } - if (continuum > 0) - for (long i = 0; i < (long) m_msh->GetNodesNumber(false); i++) + if (continuum > 0) + for (long i = 0; i < (long)m_msh->GetNodesNumber(false); i++) + { + double total_S = 0; + for (size_t j = 0; j < continuum_vector.size(); j++) { - double total_S = 0; - for (size_t j = 0; j < continuum_vector.size(); j++) - { - idxS = GetNodeValueIndex( - pcs_secondary_function_name[j - * - number_continuum - ]) + timelevel; - total_S += GetNodeValue(i, idxS) * continuum_vector[j]; - } - SetNodeValue(i, idx_tS, total_S); + idxS = GetNodeValueIndex(pcs_secondary_function_name[j * number_continuum]) + timelevel; + total_S += GetNodeValue(i, idxS) * continuum_vector[j]; } - } + SetNodeValue(i, idx_tS, total_S); + } +} /************************************************************************** GeoSys - Function: Get mean element value for element index from secondary node values @@ -11106,60 +11017,59 @@ void CRFProcess::CalcSecondaryVariablesLiquidFlow() 01/2006 SB Implementation 02/2008 CB generalization **************************************************************************/ - double PCSGetEleMeanNodeSecondary_2(long index, - int pcsT, - const string &var_name, - int timelevel) - { - double val = 1.0; // As this returns saturation, default is fully saturated = 1.0; - int idx = 0, j; //OK411 - long enode; - CRFProcess* m_pcs = NULL; - CRFProcess* cplpcs = NULL; - CElem* elem = NULL; +double PCSGetEleMeanNodeSecondary_2(long index, int pcsT, const string& var_name, int timelevel) +{ + double val = 1.0; // As this returns saturation, default is fully saturated = 1.0; + int idx = 0, j; // OK411 + long enode; + CRFProcess* m_pcs = NULL; + CRFProcess* cplpcs = NULL; + CElem* elem = NULL; - // Get index of secondary node value - switch(pcsT) - { - case 0: //Liquid_Flow + // Get index of secondary node value + switch (pcsT) + { + case 0: // Liquid_Flow break; - case 1: //Groundwater Flow + case 1: // Groundwater Flow break; - case 66: //Overland Flow + case 66: // Overland Flow break; - case 5: //Air Flow + case 5: // Air Flow break; - case 11: //Componental Flow + case 11: // Componental Flow break; - case 1212: //Multiphase Flow + case 1212: // Multiphase Flow m_pcs = PCSGet("MULTI_PHASE_FLOW"); // SB, BG - if(m_pcs) + if (m_pcs) { idx = m_pcs->GetNodeValueIndex(var_name) + timelevel; cplpcs = m_pcs; } break; - case 12: // Two_phase_Flow + case 12: // Two_phase_Flow m_pcs = PCSGet(FiniteElement::TWO_PHASE_FLOW); - if(m_pcs) + if (m_pcs) { - if(m_pcs->pcs_type_number == 0) + if (m_pcs->pcs_type_number == 0) cplpcs = pcs_vector[m_pcs->pcs_number + 1]; - else if(m_pcs->pcs_type_number == 1) + else if (m_pcs->pcs_type_number == 1) cplpcs = pcs_vector[m_pcs->pcs_number - 1]; idx = cplpcs->GetNodeValueIndex(var_name) + timelevel; } break; case 1313: // Two_phase_Flow - m_pcs = PCSGet("PS_GLOBAL"); - if(m_pcs){ - idx = m_pcs->GetNodeValueIndex(var_name); // +timelevel; CB SATURATION1 in PS_GLOBAL is only for old time level - cplpcs = m_pcs; - } - break; - case 22: // Richards flow + m_pcs = PCSGet("PS_GLOBAL"); + if (m_pcs) + { + idx = m_pcs->GetNodeValueIndex( + var_name); // +timelevel; CB SATURATION1 in PS_GLOBAL is only for old time level + cplpcs = m_pcs; + } + break; + case 22: // Richards flow m_pcs = PCSGet(FiniteElement::RICHARDS_FLOW); - if(m_pcs) + if (m_pcs) { idx = m_pcs->GetNodeValueIndex(var_name) + timelevel; cplpcs = m_pcs; @@ -11167,112 +11077,111 @@ void CRFProcess::CalcSecondaryVariablesLiquidFlow() break; default: break; - } + } - if(m_pcs) + if (m_pcs) + { + // Get element with index index + elem = m_pcs->m_msh->ele_vector[index]; + val = 0.0; + for (j = 0; j < elem->GetVertexNumber(); j++) // average all adjoining nodes { - // Get element with index index - elem = m_pcs->m_msh->ele_vector[index]; - val = 0.0; - for(j = 0; j < elem->GetVertexNumber(); j++) // average all adjoining nodes - { - enode = elem->GetNodeIndex(j); - val += cplpcs->GetNodeValue(enode,idx); - } - val = val / ((double)elem->GetVertexNumber()); + enode = elem->GetNodeIndex(j); + val += cplpcs->GetNodeValue(enode, idx); } - return val; + val = val / ((double)elem->GetVertexNumber()); } + return val; +} /************************************************************************** GeoSys - Function: Get mean element value for element index from secondary node values of process pcs_name and for variable var_name; old and new timelevel 01/2006 SB Implementation **************************************************************************/ - double PCSGetEleMeanNodeSecondary(long index, const string &pcs_name, - const string &var_name, int timelevel) - { - double val = 1.0; // As this returns saturation, default is fully saturated = 1.0; - int idx, j; - long enode; - CRFProcess* m_pcs = NULL; +double PCSGetEleMeanNodeSecondary(long index, const string& pcs_name, const string& var_name, int timelevel) +{ + double val = 1.0; // As this returns saturation, default is fully saturated = 1.0; + int idx, j; + long enode; + CRFProcess* m_pcs = NULL; - // Get process by process name - FiniteElement::ProcessType pcs_type (FiniteElement::convertProcessType (pcs_name)); - m_pcs = PCSGet(pcs_type); - if (m_pcs) + // Get process by process name + FiniteElement::ProcessType pcs_type(FiniteElement::convertProcessType(pcs_name)); + m_pcs = PCSGet(pcs_type); + if (m_pcs) + { + // Get index of secondary node value + idx = m_pcs->GetNodeValueIndex(var_name) + timelevel; + // Get element with index index + CElem* elem = NULL; + elem = m_pcs->m_msh->ele_vector[index]; + val = 0.0; + // average all adjoining nodes + for (j = 0; j < elem->GetVertexNumber(); j++) { - // Get index of secondary node value - idx = m_pcs->GetNodeValueIndex(var_name) + timelevel; - // Get element with index index - CElem* elem = NULL; - elem = m_pcs->m_msh->ele_vector[index]; - val = 0.0; - // average all adjoining nodes - for (j = 0; j < elem->GetVertexNumber(); j++) - { - enode = elem->GetNodeIndex(j); - val += m_pcs->GetNodeValue(enode, idx); - } - val = val / ((double) elem->GetVertexNumber()); + enode = elem->GetNodeIndex(j); + val += m_pcs->GetNodeValue(enode, idx); } - return val; + val = val / ((double)elem->GetVertexNumber()); } + return val; +} /************************************************************************* GeoSys-FEM Function: 01/2006 OK Implementation **************************************************************************/ -#if !defined(NEW_EQS) && !defined(USE_PETSC) //WW. 07.11.2008. 04.2012 - void CRFProcess::SetNODFlux() +#if !defined(NEW_EQS) && !defined(USE_PETSC) // WW. 07.11.2008. 04.2012 +void CRFProcess::SetNODFlux() +{ + long i; + //---------------------------------------------------------------------- + int nidx; + nidx = GetNodeValueIndex("FLUX"); + if (nidx < 0) + return; + double m_val; + for (i = 0; i < (long)m_msh->nod_vector.size(); i++) { - long i; - //---------------------------------------------------------------------- - int nidx; - nidx = GetNodeValueIndex("FLUX"); - if(nidx < 0) - return; - double m_val; - for(i = 0; i < (long)m_msh->nod_vector.size(); i++) - { - m_val = eqs->b[i]; //? m_nod->eqs_index - SetNodeValue(i,nidx,m_val); - } - //---------------------------------------------------------------------- + m_val = eqs->b[i]; //? m_nod->eqs_index + SetNodeValue(i, nidx, m_val); } + //---------------------------------------------------------------------- +} #endif /************************************************************************* GeoSys-FEM Function: 01/2006 OK Implementation **************************************************************************/ -#if !defined(NEW_EQS) && !defined(USE_PETSC) //WW. 07.11.2008. 04.2012 - void CRFProcess::AssembleParabolicEquationRHSVector() - { - //OK long i; - //---------------------------------------------------------------------- - // Init - /* PCH & WW - for(i=0;idim;i++) - { - eqs->b[i] = 0.0; - } - //---------------------------------------------------------------------- - CElem* m_ele = NULL; - for(i=0;i<(long)m_msh->ele_vector.size();i++) - { - m_ele = m_msh->ele_vector[i]; - if(m_ele->GetMark()) // Marked for use - { - fem->ConfigElement(m_ele,false); - fem->AssembleParabolicEquationRHSVector(); - //fem->AssembleParabolicEquationLHSMatrix(); - } - } - */ - //---------------------------------------------------------------------- - } -#endif //#ifndef NEW_EQS //WW. 07.11.2008 +#if !defined(NEW_EQS) && !defined(USE_PETSC) // WW. 07.11.2008. 04.2012 +void CRFProcess::AssembleParabolicEquationRHSVector() +{ + // OK long i; + //---------------------------------------------------------------------- + // Init + /* PCH & WW + for(i=0;idim;i++) + { + eqs->b[i] = 0.0; + } + //---------------------------------------------------------------------- + CElem* m_ele = NULL; + for(i=0;i<(long)m_msh->ele_vector.size();i++) + { + m_ele = m_msh->ele_vector[i]; + if(m_ele->GetMark()) // Marked for use + { + fem->ConfigElement(m_ele,false); + fem->AssembleParabolicEquationRHSVector(); + //fem->AssembleParabolicEquationLHSMatrix(); + } + } + */ + //---------------------------------------------------------------------- +} +#endif //#ifndef NEW_EQS //WW. 07.11.2008 /************************************************************************* GeoSys-FEM Function: 06/2006 YD Implementation @@ -11280,31 +11189,31 @@ void CRFProcess::CalcSecondaryVariablesLiquidFlow() 03/2008 HS/KG activated for adaptive time step Reload primary variable **************************************************************************/ - void CRFProcess::PrimaryVariableReload() - { - // char pcsT; - // pcsT = _pcs_type_name[0]; - // switch(pcsT){ - // case 'L': - // break; - // case 'U': - // break; - // case 'G': - // break; - // case 'T': - // break; - // case 'C': - // break; - // case 'M': - // PrimaryVariableReloadTransport(); - // break; - // case 'R': // Richards flow - // PrimaryVariableReloadRichards(); - // break; - // } - - switch (this->getProcessType()) - { +void CRFProcess::PrimaryVariableReload() +{ + // char pcsT; + // pcsT = _pcs_type_name[0]; + // switch(pcsT){ + // case 'L': + // break; + // case 'U': + // break; + // case 'G': + // break; + // case 'T': + // break; + // case 'C': + // break; + // case 'M': + // PrimaryVariableReloadTransport(); + // break; + // case 'R': // Richards flow + // PrimaryVariableReloadRichards(); + // break; + // } + + switch (this->getProcessType()) + { case FiniteElement::MASS_TRANSPORT: PrimaryVariableReloadTransport(); break; @@ -11313,8 +11222,8 @@ void CRFProcess::CalcSecondaryVariablesLiquidFlow() break; default: break; - } } +} /************************************************************************* GeoSys-FEM Function: @@ -11322,141 +11231,140 @@ void CRFProcess::CalcSecondaryVariablesLiquidFlow() 02/2008 JOD removed Reload primary variable of Richards Flow **************************************************************************/ - void CRFProcess::PrimaryVariableReloadRichards() - { - size_t i; - int idxp,idx_storage; - double storage_p; +void CRFProcess::PrimaryVariableReloadRichards() +{ + size_t i; + int idxp, idx_storage; + double storage_p; - idxp = GetNodeValueIndex(pcs_primary_function_name[0]); - idx_storage = GetNodeValueIndex("STORAGE_P"); - for(i = 0; i < m_msh->GetNodesNumber(false); i++) - { - storage_p = GetNodeValue(i,idx_storage); - SetNodeValue(i,idxp,storage_p); - SetNodeValue(i,idxp + 1,storage_p); - } - CalcSecondaryVariables(0); - CalcSecondaryVariables(1); + idxp = GetNodeValueIndex(pcs_primary_function_name[0]); + idx_storage = GetNodeValueIndex("STORAGE_P"); + for (i = 0; i < m_msh->GetNodesNumber(false); i++) + { + storage_p = GetNodeValue(i, idx_storage); + SetNodeValue(i, idxp, storage_p); + SetNodeValue(i, idxp + 1, storage_p); } + CalcSecondaryVariables(0); + CalcSecondaryVariables(1); +} /************************************************************************* GeoSys-FEM Function: 12/2007 kg44 Implementation Reload primary variable for Transport **************************************************************************/ - void CRFProcess::PrimaryVariableReloadTransport() - { - size_t i; - int idxp,idx_storage; - double conc_back; - char* mcomp_name; - - //kg44 test - idxp = GetNodeValueIndex(pcs_primary_function_name[0]); +void CRFProcess::PrimaryVariableReloadTransport() +{ + size_t i; + int idxp, idx_storage; + double conc_back; + char* mcomp_name; - mcomp_name = new char[80]; - sprintf(mcomp_name, "%s%i","CONC_BACK_",pcs_component_number); + // kg44 test + idxp = GetNodeValueIndex(pcs_primary_function_name[0]); - idx_storage = GetNodeValueIndex(mcomp_name); + mcomp_name = new char[80]; + sprintf(mcomp_name, "%s%i", "CONC_BACK_", pcs_component_number); - for(i = 0; i < m_msh->GetNodesNumber(false); i++) - { - conc_back = GetNodeValue(i,idx_storage); - SetNodeValue(i,idxp,conc_back); - SetNodeValue(i,idxp + 1,conc_back); - } + idx_storage = GetNodeValueIndex(mcomp_name); - CalcSecondaryVariables(0); - CalcSecondaryVariables(1); + for (i = 0; i < m_msh->GetNodesNumber(false); i++) + { + conc_back = GetNodeValue(i, idx_storage); + SetNodeValue(i, idxp, conc_back); + SetNodeValue(i, idxp + 1, conc_back); } + CalcSecondaryVariables(0); + CalcSecondaryVariables(1); +} + /************************************************************************* GeoSys-FEM Function: 12/2007 kg44 Implementation Reload primary variable for Transport **************************************************************************/ - void CRFProcess::PrimaryVariableStorageTransport() - { - size_t i; - int idxp,idx_storage; - double concentration; - char* mcomp_name; +void CRFProcess::PrimaryVariableStorageTransport() +{ + size_t i; + int idxp, idx_storage; + double concentration; + char* mcomp_name; - idxp = GetNodeValueIndex(pcs_primary_function_name[0]); - mcomp_name = new char[80]; - sprintf(mcomp_name, "%s%i","CONC_BACK_",pcs_component_number); - // cout << "mcomp_name"<< mcomp_name<<"\n"; - idx_storage = GetNodeValueIndex(mcomp_name); + idxp = GetNodeValueIndex(pcs_primary_function_name[0]); + mcomp_name = new char[80]; + sprintf(mcomp_name, "%s%i", "CONC_BACK_", pcs_component_number); + // cout << "mcomp_name"<< mcomp_name<<"\n"; + idx_storage = GetNodeValueIndex(mcomp_name); - for(i = 0; i < m_msh->GetNodesNumber(false); i++) - { - concentration = GetNodeValue(i,idxp); - SetNodeValue(i,idx_storage,concentration); - // SetNodeValue(i,idx_storage+1,concentration); - } + for (i = 0; i < m_msh->GetNodesNumber(false); i++) + { + concentration = GetNodeValue(i, idxp); + SetNodeValue(i, idx_storage, concentration); + // SetNodeValue(i,idx_storage+1,concentration); } +} /************************************************************************* GeoSys-FEM Function: 06/2006 YD Implementation Reload primary variable of Richards Flow **************************************************************************/ - void CRFProcess::PrimaryVariableStorageRichards() - { - size_t i; - int idxp,idx_storage; - double pressure; +void CRFProcess::PrimaryVariableStorageRichards() +{ + size_t i; + int idxp, idx_storage; + double pressure; - idxp = GetNodeValueIndex(pcs_primary_function_name[0]) + 1; - idx_storage = GetNodeValueIndex("STORAGE_P"); - for(i = 0; i < m_msh->GetNodesNumber(false); i++) - { - pressure = GetNodeValue(i,idxp); - SetNodeValue(i,idx_storage,pressure); - SetNodeValue(i,idx_storage + 1,pressure); - } + idxp = GetNodeValueIndex(pcs_primary_function_name[0]) + 1; + idx_storage = GetNodeValueIndex("STORAGE_P"); + for (i = 0; i < m_msh->GetNodesNumber(false); i++) + { + pressure = GetNodeValue(i, idxp); + SetNodeValue(i, idx_storage, pressure); + SetNodeValue(i, idx_storage + 1, pressure); } +} //************************************************************************* -//GeoSys-FEM Function: -//12/2007 kg44 Implementation -//check change of concentration and set new time step factor +// GeoSys-FEM Function: +// 12/2007 kg44 Implementation +// check change of concentration and set new time step factor //**************************************************************************/ -#ifdef kg44 // WW - double CRFProcess::GetNewTimeStepSizeTransport(double mchange) - { - size_t i; - long mnode = -1; - int comp; - int idxn,idxo; - double conc_new, conc_old,/*time_coeff,*/ max_change = 1.0e-10, tchange = 1.0; - char* mcomp_name; - - idxo = GetNodeValueIndex(pcs_primary_function_name[0]); - comp = pcs_component_number; // get component number - // cout << "comp number "<GetNodesNumber(false); i++) - { - conc_old = abs(GetNodeValue(i,idxo)); - conc_new = abs(GetNodeValue(i,idxn)); - if (((conc_old) > MKleinsteZahl) && ((conc_new) > MKleinsteZahl)) - { - max_change = MMax(max_change,conc_new / conc_old); - mnode = i; - } - } - tchange = mchange / max_change; - if (tchange > 2.0) - tchange = 2.0; - cout << "Transport: max change of " << max_change << " at node " << mnode << - " factor " << tchange << "\n"; - return tchange; - } +#ifdef kg44 // WW +double CRFProcess::GetNewTimeStepSizeTransport(double mchange) +{ + size_t i; + long mnode = -1; + int comp; + int idxn, idxo; + double conc_new, conc_old, /*time_coeff,*/ max_change = 1.0e-10, tchange = 1.0; + char* mcomp_name; + + idxo = GetNodeValueIndex(pcs_primary_function_name[0]); + comp = pcs_component_number; // get component number + // cout << "comp number "<GetNodesNumber(false); i++) + { + conc_old = abs(GetNodeValue(i, idxo)); + conc_new = abs(GetNodeValue(i, idxn)); + if (((conc_old) > MKleinsteZahl) && ((conc_new) > MKleinsteZahl)) + { + max_change = MMax(max_change, conc_new / conc_old); + mnode = i; + } + } + tchange = mchange / max_change; + if (tchange > 2.0) + tchange = 2.0; + cout << "Transport: max change of " << max_change << " at node " << mnode << " factor " << tchange << "\n"; + return tchange; +} #endif /************************************************************************** @@ -11464,958 +11372,1049 @@ void CRFProcess::CalcSecondaryVariablesLiquidFlow() 11/2005 MB Implementation 03/2006 OK 2nd version (binary coupling) **************************************************************************/ -#if !defined(NEW_EQS) && !defined(USE_PETSC) //WW. 07.11.2008. 04.2012 - void CRFProcess::SetCPL() +#if !defined(NEW_EQS) && !defined(USE_PETSC) // WW. 07.11.2008. 04.2012 +void CRFProcess::SetCPL() +{ + int i; + double value = 0.0; + //---------------------------------------------------------------------- + // Nothing to do + if ((cpl_type_name.size() == 0) || (cpl_type_name.compare("PARTITIONED") == 0)) + return; + //---------------------------------------------------------------------- + // PCS CPL + CRFProcess* m_pcs_cpl = PCSGet(cpl_type_name); + if (!m_pcs_cpl) { - int i; - double value = 0.0; - //---------------------------------------------------------------------- - // Nothing to do - if ((cpl_type_name.size() == 0) || (cpl_type_name.compare("PARTITIONED") - == 0)) - return; - //---------------------------------------------------------------------- - // PCS CPL - CRFProcess* m_pcs_cpl = PCSGet(cpl_type_name); - if (!m_pcs_cpl) - { - cout << "Fatal error in CRFProcess::SetCPL: no PCS data" << "\n"; - return; - } - //---------------------------------------------------------------------- - // MSH data for PCS CPL - CFEMesh* m_msh_cpl = m_pcs_cpl->m_msh; - if (!m_msh_cpl) - { - cout << "Fatal error in CRFProcess::SetCPL: no MSH data" << "\n"; - return; - } - //---------------------------------------------------------------------- - // GEO data for PCS CPL - Surface* m_sfc = GEOGetSFCByName(m_msh_cpl->geo_name); - if (!m_sfc) - { - cout << "Fatal error in CRFProcess::SetCPL: no GEO data" << "\n"; - return; - } + cout << "Fatal error in CRFProcess::SetCPL: no PCS data" + << "\n"; + return; + } + //---------------------------------------------------------------------- + // MSH data for PCS CPL + CFEMesh* m_msh_cpl = m_pcs_cpl->m_msh; + if (!m_msh_cpl) + { + cout << "Fatal error in CRFProcess::SetCPL: no MSH data" + << "\n"; + return; + } + //---------------------------------------------------------------------- + // GEO data for PCS CPL + Surface* m_sfc = GEOGetSFCByName(m_msh_cpl->geo_name); + if (!m_sfc) + { + cout << "Fatal error in CRFProcess::SetCPL: no GEO data" + << "\n"; + return; + } + //---------------------------------------------------------------------- + //...................................................................... + // MSH nodes of PCS CPL + cout << " ->CPL: " << cpl_type_name << ": "; + vector cpl_msh_nodes_vector; + m_msh_cpl->GetNODOnSFC(m_sfc, cpl_msh_nodes_vector); + if ((int)cpl_msh_nodes_vector.size() == 0) + cout << "Warning in CRFProcess::SetCPL: no MSH nodes found" + << "\n"; + cout << "CPL nodes = " << (int)cpl_msh_nodes_vector.size() << "\n"; + //.....................................................................- + // MSH nodes of PCS + cout << " ->CPL: " << convertProcessTypeToString(this->getProcessType()) << ": "; + vector msh_nodes_vector; + m_msh->GetNODOnSFC(m_sfc, msh_nodes_vector); + if ((int)msh_nodes_vector.size() == 0) + cout << "Warning in CRFProcess::SetCPL: no MSH nodes found" + << "\n"; + cout << "CPL nodes = " << (int)msh_nodes_vector.size() << "\n"; + //---------------------------------------------------------------------- + if (m_msh_cpl->pcs_name.compare("RICHARDS_FLOW") == 0) + { + m_msh->SetNODPatchAreas(); + int nidx = GetNodeValueIndex("WDEPTH"); + long st_node_number; + double st_node_value = 0.0; + CNode* m_nod = NULL; + for (i = 0; i < (int)msh_nodes_vector.size(); i++) + { + value = -2.314e-02; + st_node_number = msh_nodes_vector[i]; + m_nod = m_msh->nod_vector[st_node_number]; + st_node_value = GetNodeValue(st_node_number, nidx); + st_node_value /= m_nod->patch_area; + value *= st_node_value; + // cout << "CPL value = " << value << "\n"; + eqs->b[st_node_number] += value; + } + } + + // if (_pcs_type_name.compare("RICHARDS_FLOW") == 0 + // && m_msh_cpl->pcs_name.compare("OVERLAND_FLOW") == 0) { // ToDo + if (this->getProcessType() == FiniteElement::RICHARDS_FLOW + // ToDo + && m_msh_cpl->pcs_name.compare("OVERLAND_FLOW") == 0) + { + long msh_node_number; + // WW long cpl_msh_nod_number; + long cpl_msh_ele_number; + value = 0.0; + cout << "CPL value = " << value << "\n"; + // PCS-CON + CRFProcess* m_pcs_cond = PCSGet(cpl_type_name); + // int nidx = m_pcs_cond->GetNodeValueIndex(m_pcs_cond->pcs_primary_function_name[0]); + int cpl_nidx = m_pcs_cond->GetNodeValueIndex("WDEPTH"); //---------------------------------------------------------------------- - //...................................................................... - // MSH nodes of PCS CPL - cout << " ->CPL: " << cpl_type_name << ": "; - vector cpl_msh_nodes_vector; - m_msh_cpl->GetNODOnSFC(m_sfc, cpl_msh_nodes_vector); - if ((int) cpl_msh_nodes_vector.size() == 0) - cout << "Warning in CRFProcess::SetCPL: no MSH nodes found" << "\n"; - cout << "CPL nodes = " << (int) cpl_msh_nodes_vector.size() << "\n"; - //.....................................................................- - // MSH nodes of PCS - cout << " ->CPL: " << convertProcessTypeToString(this->getProcessType()) << - ": "; - vector msh_nodes_vector; - m_msh->GetNODOnSFC(m_sfc, msh_nodes_vector); - if ((int) msh_nodes_vector.size() == 0) - cout << "Warning in CRFProcess::SetCPL: no MSH nodes found" << "\n"; - cout << "CPL nodes = " << (int) msh_nodes_vector.size() << "\n"; + // ELE of PCS_CPL related to NOD of PCS + // CFEMesh* m_msh_this = MSHGet("RICHARDS_FLOW_LOCAL"); + CElem* m_ele_cnd = NULL; //---------------------------------------------------------------------- - if (m_msh_cpl->pcs_name.compare("RICHARDS_FLOW") == 0) - { - m_msh->SetNODPatchAreas(); - int nidx = GetNodeValueIndex("WDEPTH"); - long st_node_number; - double st_node_value = 0.0; - CNode* m_nod = NULL; - for (i = 0; i < (int) msh_nodes_vector.size(); i++) - { - value = -2.314e-02; - st_node_number = msh_nodes_vector[i]; - m_nod = m_msh->nod_vector[st_node_number]; - st_node_value = GetNodeValue(st_node_number, nidx); - st_node_value /= m_nod->patch_area; - value *= st_node_value; - //cout << "CPL value = " << value << "\n"; - eqs->b[st_node_number] += value; - } - } - - // if (_pcs_type_name.compare("RICHARDS_FLOW") == 0 - // && m_msh_cpl->pcs_name.compare("OVERLAND_FLOW") == 0) { // ToDo - if (this->getProcessType() == FiniteElement::RICHARDS_FLOW - // ToDo - && m_msh_cpl->pcs_name.compare("OVERLAND_FLOW") == 0) - { - long msh_node_number; - //WW long cpl_msh_nod_number; - long cpl_msh_ele_number; - value = 0.0; - cout << "CPL value = " << value << "\n"; - // PCS-CON - CRFProcess* m_pcs_cond = PCSGet(cpl_type_name); - //int nidx = m_pcs_cond->GetNodeValueIndex(m_pcs_cond->pcs_primary_function_name[0]); - int cpl_nidx = m_pcs_cond->GetNodeValueIndex("WDEPTH"); - //---------------------------------------------------------------------- - // ELE of PCS_CPL related to NOD of PCS - // CFEMesh* m_msh_this = MSHGet("RICHARDS_FLOW_LOCAL"); - CElem* m_ele_cnd = NULL; - //---------------------------------------------------------------------- - // CSourceTermGroup *m_st_group = NULL; - // CSourceTerm *m_st = NULL; - // m_st_group = STGetGroup(_pcs_type_name,pcs_primary_function_name[0]); - //---------------------------------------------------------------------- - double cpl_ele_val = 0.0; - size_t j; - CNodeValue* cnodev = NULL; - // for(i=0;i<(int)m_st_group->group_vector.size();i++) - // ofstream st_out_file("st_out_file.txt",ios::app); - for (i = 0; i < (int) st_node_value.size(); i++) - { - cnodev = st_node_value[i]; - // MSH-PCS - //m_nod = m_msh_this->nod_vector[m_st_group->group_vector[i]->msh_node_number]; - //m_st_group->group_vector[i]->msh_node_number; //0 - msh_node_number = cnodev->msh_node_number; - // MSH-PCS-CPL - //WW cpl_msh_nod_number = msh_node_number; - cpl_msh_ele_number = pcs_number; //OK:TODO - m_ele_cnd = m_pcs_cond->m_msh->ele_vector[cpl_msh_ele_number]; - for (j = 0; j < m_ele_cnd->GetNodesNumber(false); j++) - cpl_ele_val += m_pcs_cond->GetNodeValue( - m_ele_cnd->nodes_index[j], cpl_nidx); - cpl_ele_val /= m_ele_cnd->GetNodesNumber(false); - // VAL-CON - value = 2.314e-02 * cpl_ele_val * 1e-2; - // st_out_file << value << "\n"; - // EQS-RHS - eqs->b[msh_node_number] += value; - } - //---------------------------------------------------------------------- - /* - CNodeValue* m_node_value = NULL; - m_node_value = new CNodeValue(); - m_node_value->msh_node_number = msh_node_number; - m_node_value->geo_node_number = m_pnt->id; - m_node_value->node_value = value; - CSourceTermGroup *m_st_group = NULL; - m_st_group = STGetGroup(_pcs_type_name,pcs_primary_function_name[0]); - m_st_group->group_vector.push_back(m_node_value); - m_st_group->st_group_vector.push_back(m_st); //OK - */ + // CSourceTermGroup *m_st_group = NULL; + // CSourceTerm *m_st = NULL; + // m_st_group = STGetGroup(_pcs_type_name,pcs_primary_function_name[0]); + //---------------------------------------------------------------------- + double cpl_ele_val = 0.0; + size_t j; + CNodeValue* cnodev = NULL; + // for(i=0;i<(int)m_st_group->group_vector.size();i++) + // ofstream st_out_file("st_out_file.txt",ios::app); + for (i = 0; i < (int)st_node_value.size(); i++) + { + cnodev = st_node_value[i]; + // MSH-PCS + // m_nod = m_msh_this->nod_vector[m_st_group->group_vector[i]->msh_node_number]; + // m_st_group->group_vector[i]->msh_node_number; //0 + msh_node_number = cnodev->msh_node_number; + // MSH-PCS-CPL + // WW cpl_msh_nod_number = msh_node_number; + cpl_msh_ele_number = pcs_number; // OK:TODO + m_ele_cnd = m_pcs_cond->m_msh->ele_vector[cpl_msh_ele_number]; + for (j = 0; j < m_ele_cnd->GetNodesNumber(false); j++) + cpl_ele_val += m_pcs_cond->GetNodeValue(m_ele_cnd->nodes_index[j], cpl_nidx); + cpl_ele_val /= m_ele_cnd->GetNodesNumber(false); + // VAL-CON + value = 2.314e-02 * cpl_ele_val * 1e-2; + // st_out_file << value << "\n"; + // EQS-RHS + eqs->b[msh_node_number] += value; } + //---------------------------------------------------------------------- + /* + CNodeValue* m_node_value = NULL; + m_node_value = new CNodeValue(); + m_node_value->msh_node_number = msh_node_number; + m_node_value->geo_node_number = m_pnt->id; + m_node_value->node_value = value; + CSourceTermGroup *m_st_group = NULL; + m_st_group = STGetGroup(_pcs_type_name,pcs_primary_function_name[0]); + m_st_group->group_vector.push_back(m_node_value); + m_st_group->st_group_vector.push_back(m_st); //OK + */ + } - // if (_pcs_type_name.compare("GROUNDWATER_FLOW") == 0 - // && m_msh_cpl->pcs_name.compare("OVERLAND_FLOW") == 0) { // ToDo - if (this->getProcessType() == FiniteElement::GROUNDWATER_FLOW - // ToDo - && m_msh_cpl->pcs_name.compare("OVERLAND_FLOW") == 0) - { - long ie = (long) msh_nodes_vector.size() - / (m_msh->getNumberOfMeshLayers() + 1); - long of_node_number, gf_node_number; - double of_node_value, gf_node_value; - // CNode* m_nod = NULL; - int of_nidx = GetNodeValueIndex("WDEPTH"); + // if (_pcs_type_name.compare("GROUNDWATER_FLOW") == 0 + // && m_msh_cpl->pcs_name.compare("OVERLAND_FLOW") == 0) { // ToDo + if (this->getProcessType() == FiniteElement::GROUNDWATER_FLOW + // ToDo + && m_msh_cpl->pcs_name.compare("OVERLAND_FLOW") == 0) + { + long ie = (long)msh_nodes_vector.size() / (m_msh->getNumberOfMeshLayers() + 1); + long of_node_number, gf_node_number; + double of_node_value, gf_node_value; + // CNode* m_nod = NULL; + int of_nidx = GetNodeValueIndex("WDEPTH"); - for (i = 0; i < ie; i++) - { - of_node_number = msh_nodes_vector[i]; //ToDo - of_node_value = m_pcs_cpl->GetNodeValue(of_node_number, of_nidx); - //m_nod = m_msh->nod_vector[gf_node_number]; - //st_node_value /= m_nod->patch_area; - gf_node_value = of_node_value * 2e-11; - if (gf_node_value > 1e-13) - cout << "CPL value = " << gf_node_value << "\n"; - gf_node_number = msh_nodes_vector[i]; - eqs->b[gf_node_number] += gf_node_value; - } + for (i = 0; i < ie; i++) + { + of_node_number = msh_nodes_vector[i]; // ToDo + of_node_value = m_pcs_cpl->GetNodeValue(of_node_number, of_nidx); + // m_nod = m_msh->nod_vector[gf_node_number]; + // st_node_value /= m_nod->patch_area; + gf_node_value = of_node_value * 2e-11; + if (gf_node_value > 1e-13) + cout << "CPL value = " << gf_node_value << "\n"; + gf_node_number = msh_nodes_vector[i]; + eqs->b[gf_node_number] += gf_node_value; } - - int idx = GetNodeValueIndex("FLUX") + 1; - //for(i=0;i<(int)msh_nodes_vector.size();i++) - for (i = 0; i < 1; i++) - SetNodeValue(msh_nodes_vector[i], idx, value); } + + int idx = GetNodeValueIndex("FLUX") + 1; + // for(i=0;i<(int)msh_nodes_vector.size();i++) + for (i = 0; i < 1; i++) + SetNodeValue(msh_nodes_vector[i], idx, value); +} #endif /************************************************************************** PCSLib-Method: 04/2006 OK Implementation **************************************************************************/ - void CRFProcess::CreateBCGroup() - { - cout << "->Create BC" << '\n'; - CBoundaryConditionsGroup* m_bc_group = NULL; +void CRFProcess::CreateBCGroup() +{ + cout << "->Create BC" << '\n'; + CBoundaryConditionsGroup* m_bc_group = NULL; - std::string pcs_type_name (convertProcessTypeToString(this->getProcessType())); + std::string pcs_type_name(convertProcessTypeToString(this->getProcessType())); - for (size_t i = 0; i < GetPrimaryVNumber(); i++) - { - BCGroupDelete(pcs_type_name, pcs_primary_function_name[i]); - m_bc_group = new CBoundaryConditionsGroup(); - //OK - m_bc_group->setProcessTypeName(pcs_type_name); - //OK - m_bc_group->setProcessPrimaryVariableName(pcs_primary_function_name[i]); - m_bc_group->Set(this, Shift[i]); - bc_group_list.push_back(m_bc_group); - } + for (size_t i = 0; i < GetPrimaryVNumber(); i++) + { + BCGroupDelete(pcs_type_name, pcs_primary_function_name[i]); + m_bc_group = new CBoundaryConditionsGroup(); + // OK + m_bc_group->setProcessTypeName(pcs_type_name); + // OK + m_bc_group->setProcessPrimaryVariableName(pcs_primary_function_name[i]); + m_bc_group->Set(this, Shift[i]); + bc_group_list.push_back(m_bc_group); } +} /************************************************************************** PCSLib-Method: 04/2006 OK Implementation **************************************************************************/ - void CRFProcess::CreateSTGroup() - { - cout << "->Create ST" << '\n'; - CSourceTermGroup* m_st_group = NULL; - // WW - std::ifstream* iSourceNBC_RHS_file = NULL; - std::ofstream* oSourceNBC_RHS_file = NULL; +void CRFProcess::CreateSTGroup() +{ + cout << "->Create ST" << '\n'; + CSourceTermGroup* m_st_group = NULL; + // WW + std::ifstream* iSourceNBC_RHS_file = NULL; + std::ofstream* oSourceNBC_RHS_file = NULL; - std::string pcs_type_name (convertProcessTypeToString (this->getProcessType())); + std::string pcs_type_name(convertProcessTypeToString(this->getProcessType())); - if (WriteSourceNBC_RHS == 1) - { - string m_file_name = FileName + "_" + pcs_type_name - + "_source_Neumann_RHS.bin"; - oSourceNBC_RHS_file = new ofstream(m_file_name.c_str(), ios::binary); - } - else if (WriteSourceNBC_RHS == 2) + if (WriteSourceNBC_RHS == 1) + { + string m_file_name = FileName + "_" + pcs_type_name + "_source_Neumann_RHS.bin"; + oSourceNBC_RHS_file = new ofstream(m_file_name.c_str(), ios::binary); + } + else if (WriteSourceNBC_RHS == 2) + { + string m_file_name = FileName + "_" + pcs_type_name + "_source_Neumann_RHS.bin"; + iSourceNBC_RHS_file = new ifstream(m_file_name.c_str(), ios::binary); + if (!iSourceNBC_RHS_file->good()) + cout << "_source_Neumann_RHS file is not found" + << "\n"; + } + + for (size_t i = 0; i < GetPrimaryVNumber(); i++) + { + // OK m_st_group = m_st_group->Get(pcs_primary_function_name[i]); + m_st_group = STGetGroup(pcs_type_name, pcs_primary_function_name[i]); + if (!m_st_group) { - string m_file_name = FileName + "_" + pcs_type_name - + "_source_Neumann_RHS.bin"; - iSourceNBC_RHS_file = new ifstream(m_file_name.c_str(), ios::binary); - if (!iSourceNBC_RHS_file->good()) - cout << "_source_Neumann_RHS file is not found" << "\n"; + m_st_group = new CSourceTermGroup(); + // OK + m_st_group->pcs_type_name = pcs_type_name; + // OK + m_st_group->pcs_pv_name = pcs_primary_function_name[i]; + // if(iSourceNBC_RHS_file) // Read from data. WW + // m_st_group->Read(*iSourceNBC_RHS_file); + // else + m_st_group->Set(this, Shift[i]); + st_group_list.push_back(m_st_group); } + } + if (oSourceNBC_RHS_file) // WW + // WriteRHS_of_ST_NeumannBC(*oSourceNBC_RHS_file); - for (size_t i = 0; i < GetPrimaryVNumber(); i++) + if (iSourceNBC_RHS_file) // WW { - //OK m_st_group = m_st_group->Get(pcs_primary_function_name[i]); - m_st_group = STGetGroup(pcs_type_name, pcs_primary_function_name[i]); - if (!m_st_group) - { - m_st_group = new CSourceTermGroup(); - //OK - m_st_group->pcs_type_name = pcs_type_name; - //OK - m_st_group->pcs_pv_name = pcs_primary_function_name[i]; - // if(iSourceNBC_RHS_file) // Read from data. WW - // m_st_group->Read(*iSourceNBC_RHS_file); - // else - m_st_group->Set(this, Shift[i]); - st_group_list.push_back(m_st_group); - } - } - if (oSourceNBC_RHS_file) // WW - // WriteRHS_of_ST_NeumannBC(*oSourceNBC_RHS_file); - - if (iSourceNBC_RHS_file) //WW - { - iSourceNBC_RHS_file->close(); - delete iSourceNBC_RHS_file; - iSourceNBC_RHS_file = NULL; - } - if (oSourceNBC_RHS_file) //WW - { - oSourceNBC_RHS_file->close(); - delete oSourceNBC_RHS_file; - oSourceNBC_RHS_file = NULL; - } - } - - /************************************************************************** - PCSLib-Method: - 08/2006 OK Implementation - 04/2012 BG Extension to 2 Phases - **************************************************************************/ - void CRFProcess::CalcELEFluxes(const GEOLIB::Polyline* const ply, double *result) - { - int coordinateflag, dimension = 0, axis = 0; - bool Edge_already_used; - //bool Node_already_used; - bool Use_Element; - vector vecConsideredEdges; - vector vec_nodes_edge; - bool Edge_on_Geo = false, Point_on_Geo; - std::vector nod_vector_at_geo; - CElem* m_ele = NULL; - CEdge* m_edg = NULL; - vec ele_edges_vector(15); - double edg_normal_vector[3]; - double vn; - double edg_length = 0.0; - double vn_vec[3]; - double edge_vector[3]; - double f_n_sum = 0.0; - vec element_nodes(20); - double f[3], v[3]; - double v_2[3], f_2[3]; - double f_n_sum_2 = 0.0; - - result[0] = result[1] = 0; - FiniteElement::ProcessType pcs_type(getProcessType()); - - CRFProcess* m_pcs_flow = NULL; - // if (_pcs_type_name.find("FLOW") != string::npos) { - if (isFlowProcess(this->getProcessType())) - m_pcs_flow = this; - else m_pcs_flow = PCSGet(FiniteElement::GROUNDWATER_FLOW); - - // calculates element velocity based on 1 GP - //CalcELEVelocities(); - - int v_eidx[3]; - int v_eidx_2[3]; - v_eidx[0] = m_pcs_flow->GetElementValueIndex("VELOCITY1_X"); - v_eidx[1] = m_pcs_flow->GetElementValueIndex("VELOCITY1_Y"); - v_eidx[2] = m_pcs_flow->GetElementValueIndex("VELOCITY1_Z"); - - if (pcs_type == FiniteElement::MULTI_PHASE_FLOW) { - v_eidx_2[0] = m_pcs_flow->GetElementValueIndex("VELOCITY2_X"); - v_eidx_2[1] = m_pcs_flow->GetElementValueIndex("VELOCITY2_Y"); - v_eidx_2[2] = m_pcs_flow->GetElementValueIndex("VELOCITY2_Z"); + iSourceNBC_RHS_file->close(); + delete iSourceNBC_RHS_file; + iSourceNBC_RHS_file = NULL; } + if (oSourceNBC_RHS_file) // WW + { + oSourceNBC_RHS_file->close(); + delete oSourceNBC_RHS_file; + oSourceNBC_RHS_file = NULL; + } +} - for (size_t i = 0; i < 3; i++) - if (v_eidx[i] < 0) { - std::cout << i << " " << v_eidx[i] << "Velocity output is not specified" << "\n"; - exit(0); //return 0.0; - } - if (pcs_type == FiniteElement::MULTI_PHASE_FLOW) for (size_t i = 0; i < 3; i++) - if (v_eidx_2[i] < 0) { - std::cout << i << " " << v_eidx[i] << "Velocity output is not specified" << "\n"; - exit(0); //return 0.0; - } - - //determine the dimension and the orientation of the mesh - coordinateflag = m_msh->GetCoordinateFlag(); - if (coordinateflag == 10) { - dimension = 1; - axis = 0; - } // x only - else if (coordinateflag == 11) { - dimension = 1; - axis = 1; - } // y only - else if (coordinateflag == 12) { - dimension = 1; - axis = 2; - } // z only - else if (coordinateflag == 21) { - dimension = 2; - axis = 1; - } // x, y only - else if (coordinateflag == 22) { - dimension = 2; - axis = 2; - } // x, z only - else if (coordinateflag == 32) { - dimension = 3; - axis = 3; - } // x, y, z only - - // Get elements at GEO - std::vector ele_vector_at_geo; - m_msh->GetELEOnPLY(ply, ele_vector_at_geo, true); - //BG: 04/2011 nodes are needed to provide the correct edge - m_msh->GetNODOnPLY(ply, nod_vector_at_geo); - - for (size_t i = 0; i < ele_vector_at_geo.size(); i++) { - m_ele = m_msh->ele_vector[ele_vector_at_geo[i]]; - m_ele->SetNormalVector(); - m_ele->GetNodeIndeces(element_nodes); - Use_Element = true; +/************************************************************************** + PCSLib-Method: + 08/2006 OK Implementation + 04/2012 BG Extension to 2 Phases +**************************************************************************/ +void CRFProcess::CalcELEFluxes(const GEOLIB::Polyline* const ply, double* result) +{ + int coordinateflag, dimension = 0, axis = 0; + bool Edge_already_used; + // bool Node_already_used; + bool Use_Element; + vector vecConsideredEdges; + vector vec_nodes_edge; + bool Edge_on_Geo = false, Point_on_Geo; + std::vector nod_vector_at_geo; + CElem* m_ele = NULL; + CEdge* m_edg = NULL; + vec ele_edges_vector(15); + double edg_normal_vector[3]; + double vn; + double edg_length = 0.0; + double vn_vec[3]; + double edge_vector[3]; + double f_n_sum = 0.0; + vec element_nodes(20); + double f[3], v[3]; + double v_2[3], f_2[3]; + double f_n_sum_2 = 0.0; + + result[0] = result[1] = 0; + FiniteElement::ProcessType pcs_type(getProcessType()); + + CRFProcess* m_pcs_flow = NULL; + // if (_pcs_type_name.find("FLOW") != string::npos) { + if (isFlowProcess(this->getProcessType())) + m_pcs_flow = this; + else + m_pcs_flow = PCSGet(FiniteElement::GROUNDWATER_FLOW); - // Configure Element for interpolation of node velocities to GP velocities - fem->ConfigElement(m_ele, m_num->ele_gauss_points); - // velocity vector - for (size_t j = 0; j < 3; j++) { - //v[j] = m_pcs_flow->GetElementValue(m_ele->GetIndex(), v_eidx[j]); - // Calculate Element velocity - v[j] = fem->Get_Element_Velocity(m_ele->GetIndex(), m_pcs_flow, 0, j); - } - //Test mit Knotengeschwindigkeiten - //double temp_v[3]; - //temp_v[0] = temp_v[1] = temp_v[2] = 0.0; - //int variable_index[3]; - //variable_index[0] = m_pcs_flow->GetNodeValueIndex("VELOCITY_X1"); - //variable_index[1] = m_pcs_flow->GetNodeValueIndex("VELOCITY_Y1"); - //variable_index[2] = m_pcs_flow->GetNodeValueIndex("VELOCITY_Z1"); - // - //for (size_t j = 0; j < 3; j++) - //{ - // for (size_t k = 0; k < m_ele->GetNodesNumber(false); k++) - // { - // temp_v[j] += m_pcs_flow->GetNodeValue(element_nodes[k], variable_index[j]); - // } - // temp_v[j] /= m_ele->GetNodesNumber(false); - // v[j] = temp_v[j]; - //} + // calculates element velocity based on 1 GP + // CalcELEVelocities(); + + int v_eidx[3]; + int v_eidx_2[3]; + v_eidx[0] = m_pcs_flow->GetElementValueIndex("VELOCITY1_X"); + v_eidx[1] = m_pcs_flow->GetElementValueIndex("VELOCITY1_Y"); + v_eidx[2] = m_pcs_flow->GetElementValueIndex("VELOCITY1_Z"); - //BG 04/2011: MassFlux Calculation is not working correctly if it is a 2D mesh in x-z-direction - //z-velocity is stored a y-position -> this is corrected here - if ((dimension == 2) && (axis == 2)) { - v[2] = v[1]; - v[1] = 0; + if (pcs_type == FiniteElement::MULTI_PHASE_FLOW) + { + v_eidx_2[0] = m_pcs_flow->GetElementValueIndex("VELOCITY2_X"); + v_eidx_2[1] = m_pcs_flow->GetElementValueIndex("VELOCITY2_Y"); + v_eidx_2[2] = m_pcs_flow->GetElementValueIndex("VELOCITY2_Z"); + } + + for (size_t i = 0; i < 3; i++) + if (v_eidx[i] < 0) + { + std::cout << i << " " << v_eidx[i] << "Velocity output is not specified" + << "\n"; + exit(0); // return 0.0; + } + if (pcs_type == FiniteElement::MULTI_PHASE_FLOW) + for (size_t i = 0; i < 3; i++) + if (v_eidx_2[i] < 0) + { + std::cout << i << " " << v_eidx[i] << "Velocity output is not specified" + << "\n"; + exit(0); // return 0.0; + } + + // determine the dimension and the orientation of the mesh + coordinateflag = m_msh->GetCoordinateFlag(); + if (coordinateflag == 10) + { + dimension = 1; + axis = 0; + } // x only + else if (coordinateflag == 11) + { + dimension = 1; + axis = 1; + } // y only + else if (coordinateflag == 12) + { + dimension = 1; + axis = 2; + } // z only + else if (coordinateflag == 21) + { + dimension = 2; + axis = 1; + } // x, y only + else if (coordinateflag == 22) + { + dimension = 2; + axis = 2; + } // x, z only + else if (coordinateflag == 32) + { + dimension = 3; + axis = 3; + } // x, y, z only + + // Get elements at GEO + std::vector ele_vector_at_geo; + m_msh->GetELEOnPLY(ply, ele_vector_at_geo, true); + // BG: 04/2011 nodes are needed to provide the correct edge + m_msh->GetNODOnPLY(ply, nod_vector_at_geo); + + for (size_t i = 0; i < ele_vector_at_geo.size(); i++) + { + m_ele = m_msh->ele_vector[ele_vector_at_geo[i]]; + m_ele->SetNormalVector(); + m_ele->GetNodeIndeces(element_nodes); + Use_Element = true; + + // Configure Element for interpolation of node velocities to GP velocities + fem->ConfigElement(m_ele, m_num->ele_gauss_points); + // velocity vector + for (size_t j = 0; j < 3; j++) + { + // v[j] = m_pcs_flow->GetElementValue(m_ele->GetIndex(), v_eidx[j]); + // Calculate Element velocity + v[j] = fem->Get_Element_Velocity(m_ele->GetIndex(), m_pcs_flow, 0, j); + } + // Test mit Knotengeschwindigkeiten + // double temp_v[3]; + // temp_v[0] = temp_v[1] = temp_v[2] = 0.0; + // int variable_index[3]; + // variable_index[0] = m_pcs_flow->GetNodeValueIndex("VELOCITY_X1"); + // variable_index[1] = m_pcs_flow->GetNodeValueIndex("VELOCITY_Y1"); + // variable_index[2] = m_pcs_flow->GetNodeValueIndex("VELOCITY_Z1"); + // + // for (size_t j = 0; j < 3; j++) + //{ + // for (size_t k = 0; k < m_ele->GetNodesNumber(false); k++) + // { + // temp_v[j] += m_pcs_flow->GetNodeValue(element_nodes[k], variable_index[j]); + // } + // temp_v[j] /= m_ele->GetNodesNumber(false); + // v[j] = temp_v[j]; + //} + + // BG 04/2011: MassFlux Calculation is not working correctly if it is a 2D mesh in x-z-direction + // z-velocity is stored a y-position -> this is corrected here + if ((dimension == 2) && (axis == 2)) + { + v[2] = v[1]; + v[1] = 0; + } + // edge projection // edge marked + m_ele->GetEdges(ele_edges_vector); + // cout << "Element: " << "\n"; + edg_length = 0; + // loop over the edges of the element to find the edge at the polyline + for (size_t j = 0; j < static_cast(m_ele->GetEdgesNumber()); j++) + { + m_edg = ele_edges_vector[j]; + // check if edge was already used + Edge_already_used = false; + for (size_t k = 0; k < vecConsideredEdges.size(); k++) + if (m_edg->GetIndex() == vecConsideredEdges[k]) + Edge_already_used = true; + if (Edge_already_used == true) + { + Edge_on_Geo = false; + Use_Element = false; } - // edge projection // edge marked - m_ele->GetEdges(ele_edges_vector); - //cout << "Element: " << "\n"; - edg_length = 0; - //loop over the edges of the element to find the edge at the polyline - for (size_t j = 0; j < static_cast (m_ele->GetEdgesNumber()); j++) { - m_edg = ele_edges_vector[j]; - //check if edge was already used - Edge_already_used = false; - for (size_t k = 0; k < vecConsideredEdges.size(); k++) - if (m_edg->GetIndex() == vecConsideredEdges[k]) Edge_already_used = true; - if (Edge_already_used == true) { - Edge_on_Geo = false; - Use_Element = false; - } else { - vec_nodes_edge.clear(); - //BG 04/2011: check if edge is completely on the polyline - Edge_on_Geo = true; - vec_nodes_edge.push_back(m_edg->GetNode(0)); - vec_nodes_edge.push_back(m_edg->GetNode(1)); - //loop over the nodes of the edge to check if all of them are on the polyline - for (int k = 0; k < int(vec_nodes_edge.size()); k++) { - Point_on_Geo = false; - for (int l = 0; l < int(nod_vector_at_geo.size()); l++) { - if (vec_nodes_edge[k]->GetIndex() == nod_vector_at_geo[l]) { - Point_on_Geo = true; - l = nod_vector_at_geo.size(); - } + else + { + vec_nodes_edge.clear(); + // BG 04/2011: check if edge is completely on the polyline + Edge_on_Geo = true; + vec_nodes_edge.push_back(m_edg->GetNode(0)); + vec_nodes_edge.push_back(m_edg->GetNode(1)); + // loop over the nodes of the edge to check if all of them are on the polyline + for (int k = 0; k < int(vec_nodes_edge.size()); k++) + { + Point_on_Geo = false; + for (int l = 0; l < int(nod_vector_at_geo.size()); l++) + { + if (vec_nodes_edge[k]->GetIndex() == nod_vector_at_geo[l]) + { + Point_on_Geo = true; + l = nod_vector_at_geo.size(); } - //cout << " Node: " << vec_nodes_edge[k]->GetIndex() << " " << Point_on_Geo << "\n"; - if (Point_on_Geo == false) Edge_on_Geo = false; } - if (Edge_on_Geo == true) j = m_ele->GetEdgesNumber(); + // cout << " Node: " << vec_nodes_edge[k]->GetIndex() << " " << Point_on_Geo << "\n"; + if (Point_on_Geo == false) + Edge_on_Geo = false; } + if (Edge_on_Geo == true) + j = m_ele->GetEdgesNumber(); } - if ((m_edg->GetMark()) && (Use_Element == true) && (Edge_on_Geo == true)) { - vecConsideredEdges.push_back(m_edg->GetIndex()); //all edges that were already used are stored - m_edg->SetNormalVector(m_ele->normal_vector, edg_normal_vector); - edg_length = m_edg->getLength(); - //cout << "Element: " << m_ele->GetIndex() << " Länge: " << edg_length << " Normalvektor: x=" << edg_normal_vector[0] << " y=" << edg_normal_vector[1] << " z=" << edg_normal_vector[2] << "\n"; - m_edg->GetEdgeVector(edge_vector); + } + if ((m_edg->GetMark()) && (Use_Element == true) && (Edge_on_Geo == true)) + { + vecConsideredEdges.push_back(m_edg->GetIndex()); // all edges that were already used are stored + m_edg->SetNormalVector(m_ele->normal_vector, edg_normal_vector); + edg_length = m_edg->getLength(); + // cout << "Element: " << m_ele->GetIndex() << " Länge: " << edg_length << " Normalvektor: x=" << + // edg_normal_vector[0] << " y=" << edg_normal_vector[1] << " z=" << edg_normal_vector[2] << "\n"; + m_edg->GetEdgeVector(edge_vector); - vn = MSkalarprodukt(v, edg_normal_vector, 3); - for (size_t j = 0; j < 3; j++) - vn_vec[j] = vn * edg_normal_vector[j]; + vn = MSkalarprodukt(v, edg_normal_vector, 3); + for (size_t j = 0; j < 3; j++) + vn_vec[j] = vn * edg_normal_vector[j]; - for (size_t j = 0; j < 3; j++) - f[j] = vn_vec[j] * edg_length * m_ele->GetFluxArea(); + for (size_t j = 0; j < 3; j++) + f[j] = vn_vec[j] * edg_length * m_ele->GetFluxArea(); - f_n_sum += MBtrgVec(f, 3); + f_n_sum += MBtrgVec(f, 3); - if (pcs_type == FiniteElement::MULTI_PHASE_FLOW) // BG, 04/2012 + if (pcs_type == FiniteElement::MULTI_PHASE_FLOW) // BG, 04/2012 + { + // velocity vector + for (size_t j = 0; j < 3; j++) { - // velocity vector - for (size_t j = 0; j < 3; j++) { - //v_2[j] = m_pcs_flow->GetElementValue(m_ele->GetIndex(), v_eidx_2[j]); - // Calculate Element velocity - v_2[j] = fem->Get_Element_Velocity(m_ele->GetIndex(), m_pcs_flow, 1, j); - } + // v_2[j] = m_pcs_flow->GetElementValue(m_ele->GetIndex(), v_eidx_2[j]); + // Calculate Element velocity + v_2[j] = fem->Get_Element_Velocity(m_ele->GetIndex(), m_pcs_flow, 1, j); + } - //variable_index[0] = m_pcs_flow->GetNodeValueIndex("VELOCITY_X2"); - //variable_index[1] = m_pcs_flow->GetNodeValueIndex("VELOCITY_Y2"); - //variable_index[2] = m_pcs_flow->GetNodeValueIndex("VELOCITY_Z2"); - // - //for (size_t j = 0; j < 3; j++) - //{ - // for (size_t k = 0; k < m_ele->GetNodesNumber(false); k++) - // { - // temp_v[j] += m_pcs_flow->GetNodeValue(element_nodes[k], variable_index[j]); - // } - // temp_v[j] /= m_ele->GetNodesNumber(false); - // v_2[j] = temp_v[j]; - //} - - //BG 04/2011: MassFlux Calculation is not working correctly if it is a 2D mesh in x-z-direction - //z-velocity is stored a y-position -> this is corrected here - if ((dimension == 2) && (axis == 2)) { - v_2[2] = v_2[1]; - v_2[1] = 0; - } + // variable_index[0] = m_pcs_flow->GetNodeValueIndex("VELOCITY_X2"); + // variable_index[1] = m_pcs_flow->GetNodeValueIndex("VELOCITY_Y2"); + // variable_index[2] = m_pcs_flow->GetNodeValueIndex("VELOCITY_Z2"); + // + // for (size_t j = 0; j < 3; j++) + //{ + // for (size_t k = 0; k < m_ele->GetNodesNumber(false); k++) + // { + // temp_v[j] += m_pcs_flow->GetNodeValue(element_nodes[k], variable_index[j]); + // } + // temp_v[j] /= m_ele->GetNodesNumber(false); + // v_2[j] = temp_v[j]; + //} + + // BG 04/2011: MassFlux Calculation is not working correctly if it is a 2D mesh in x-z-direction + // z-velocity is stored a y-position -> this is corrected here + if ((dimension == 2) && (axis == 2)) + { + v_2[2] = v_2[1]; + v_2[1] = 0; + } - vn = MSkalarprodukt(v_2, edg_normal_vector, 3); - for (size_t j = 0; j < 3; j++) - vn_vec[j] = vn * edg_normal_vector[j]; + vn = MSkalarprodukt(v_2, edg_normal_vector, 3); + for (size_t j = 0; j < 3; j++) + vn_vec[j] = vn * edg_normal_vector[j]; - for (size_t j = 0; j < 3; j++) - f_2[j] = vn_vec[j] * edg_length * m_ele->GetFluxArea(); + for (size_t j = 0; j < 3; j++) + f_2[j] = vn_vec[j] * edg_length * m_ele->GetFluxArea(); - f_n_sum_2 += MBtrgVec(f_2, 3); - } + f_n_sum_2 += MBtrgVec(f_2, 3); } } - result[0] = f_n_sum; - result[1] = f_n_sum_2; - ele_vector_at_geo.clear(); - - } - - /************************************************************************** - GeoSys - Function: CalcELEMassFluxes - Task: Calculate the Mass Flux for Elements at Polylines - Return: MassFlux - Programming: 05/2011 BG - Modification: - **************************************************************************/ - void CRFProcess::CalcELEMassFluxes(const GEOLIB::Polyline* const ply, std::string const& NameofPolyline, double* result) - { - CRFProcess* m_pcs_flow = NULL; - std::vector ele_vector_at_geo; - std::vector nod_vector_at_geo; - vector vec_nodes_edge; - vec ele_edges_vector(15); - vec element_nodes(20); - vector vecConsideredEdges; - vector vecConsideredNodes; - CElem* m_ele = NULL; - CEdge* m_edg = NULL; - CompProperties *m_cp = NULL; - CMediumProperties *m_mat_mp = NULL; - CNode* m_node = NULL; - bool Edge_on_Geo, Point_on_Geo; - double edg_normal_vector[3]; - double vn; - double edg_length = 0.0; - double vn_vec[3]; - double edge_vector[3]; + } + result[0] = f_n_sum; + result[1] = f_n_sum_2; + ele_vector_at_geo.clear(); +} + +/************************************************************************** +GeoSys - Function: CalcELEMassFluxes +Task: Calculate the Mass Flux for Elements at Polylines +Return: MassFlux +Programming: 05/2011 BG +Modification: + **************************************************************************/ +void CRFProcess::CalcELEMassFluxes(const GEOLIB::Polyline* const ply, std::string const& NameofPolyline, double* result) +{ + CRFProcess* m_pcs_flow = NULL; + std::vector ele_vector_at_geo; + std::vector nod_vector_at_geo; + vector vec_nodes_edge; + vec ele_edges_vector(15); + vec element_nodes(20); + vector vecConsideredEdges; + vector vecConsideredNodes; + CElem* m_ele = NULL; + CEdge* m_edg = NULL; + CompProperties* m_cp = NULL; + CMediumProperties* m_mat_mp = NULL; + CNode* m_node = NULL; + bool Edge_on_Geo, Point_on_Geo; + double edg_normal_vector[3]; + double vn; + double edg_length = 0.0; + double vn_vec[3]; + double edge_vector[3]; // double f_n_sum = 0.0; // TF 2012-08 // removed warning unused variable - double J_adv_sum = 0.0, J_disp_sum = 0.0, J_diff_sum = 0.0, J_sum = 0.0; - double C_ele = 0.0; // C1 = 0, C2 = 0; // TF 2012-08 // removed warning unused variable + double J_adv_sum = 0.0, J_disp_sum = 0.0, J_diff_sum = 0.0, J_sum = 0.0; + double C_ele = 0.0; // C1 = 0, C2 = 0; // TF 2012-08 // removed warning unused variable // int number_nodes_at_edge = 0; // TF 2012-08 // removed warning unused variable - double J_adv[3], J_disp[3], J_diff[3], v[3], temp_j, j_diff[3], j_disp[3], norm_v; - double J_adv_temp, J_disp_temp, J_diff_temp, J_temp; - int coordinateflag, dimension = 0, axis = 0; - bool Edge_already_used, Node_already_used; - bool Use_Element; - double ElementConcentration[4]; - double Dm, Dm_eff, tortuosity, porosity, alpha_l, alpha_t, Disp_xx, Disp_yy, Disp_xy; - //double Disp_zz, Disp_xz, Disp_yz; - int group; + double J_adv[3], J_disp[3], J_diff[3], v[3], temp_j, j_diff[3], j_disp[3], norm_v; + double J_adv_temp, J_disp_temp, J_diff_temp, J_temp; + int coordinateflag, dimension = 0, axis = 0; + bool Edge_already_used, Node_already_used; + bool Use_Element; + double ElementConcentration[4]; + double Dm, Dm_eff, tortuosity, porosity, alpha_l, alpha_t, Disp_xx, Disp_yy, Disp_xy; + // double Disp_zz, Disp_xz, Disp_yz; + int group; // double totalmass; // 2012-08 TF not used // double totalmassflux; // 2012-08 TF / unused - double *ConcentrationGradient (new double[3]); - int numberPolyline = 0; + double* ConcentrationGradient(new double[3]); + int numberPolyline = 0; - if (this->Tim->step_current == 0) { - this->PolylinesforOutput.push_back(NameofPolyline); - numberPolyline = this->PolylinesforOutput.size() - 1; - this->TotalMass[numberPolyline] = 0; - } - else { - for (int i = 0; i < int(this->PolylinesforOutput.size()); i++) - if (NameofPolyline == this->PolylinesforOutput[i]) - numberPolyline = i; - } + if (this->Tim->step_current == 0) + { + this->PolylinesforOutput.push_back(NameofPolyline); + numberPolyline = this->PolylinesforOutput.size() - 1; + this->TotalMass[numberPolyline] = 0; + } + else + { + for (int i = 0; i < int(this->PolylinesforOutput.size()); i++) + if (NameofPolyline == this->PolylinesforOutput[i]) + numberPolyline = i; + } - m_msh->GetELEOnPLY(ply, ele_vector_at_geo, true); - //BG: 04/2011 nodes are needed to provide the correct edge - m_msh->GetNODOnPLY(ply, nod_vector_at_geo); + m_msh->GetELEOnPLY(ply, ele_vector_at_geo, true); + // BG: 04/2011 nodes are needed to provide the correct edge + m_msh->GetNODOnPLY(ply, nod_vector_at_geo); - //get the current flow and transport process - if (isFlowProcess (this->getProcessType())) - { - m_pcs_flow = this; - } - else - { - m_pcs_flow = PCSGet(FiniteElement::GROUNDWATER_FLOW); - } + // get the current flow and transport process + if (isFlowProcess(this->getProcessType())) + { + m_pcs_flow = this; + } + else + { + m_pcs_flow = PCSGet(FiniteElement::GROUNDWATER_FLOW); + } - // get the indices of the velocity - int v_eidx[3]; - v_eidx[0] = m_pcs_flow->GetElementValueIndex("VELOCITY1_X"); - v_eidx[1] = m_pcs_flow->GetElementValueIndex("VELOCITY1_Y"); - v_eidx[2] = m_pcs_flow->GetElementValueIndex("VELOCITY1_Z"); - //check if velocity exists - for (size_t i = 0; i < 3; i++) + // get the indices of the velocity + int v_eidx[3]; + v_eidx[0] = m_pcs_flow->GetElementValueIndex("VELOCITY1_X"); + v_eidx[1] = m_pcs_flow->GetElementValueIndex("VELOCITY1_Y"); + v_eidx[2] = m_pcs_flow->GetElementValueIndex("VELOCITY1_Z"); + // check if velocity exists + for (size_t i = 0; i < 3; i++) + { + if (v_eidx[i] < 0) { - if (v_eidx[i] < 0) - { - std::cout << i << " " << v_eidx[i] << "Velocity output is not specified" << "\n"; - exit(0); - } + std::cout << i << " " << v_eidx[i] << "Velocity output is not specified" + << "\n"; + exit(0); + } + } + // determine the dimension and the orientation of the mesh + coordinateflag = m_msh->GetCoordinateFlag(); + if (coordinateflag == 10) + { + dimension = 1; + axis = 0; + } // x only + else if (coordinateflag == 11) + { + dimension = 1; + axis = 1; + } // y only + else if (coordinateflag == 12) + { + dimension = 1; + axis = 2; + } // z only + else if (coordinateflag == 21) + { + dimension = 2; + axis = 1; + } // x, y only + else if (coordinateflag == 22) + { + dimension = 2; + axis = 2; + } // x, z only + else if (coordinateflag == 32) + { + dimension = 3; + axis = 3; + } // x, y, z only + + // loop over all elements at the polyline + for (size_t i = 0; i < ele_vector_at_geo.size(); i++) + { + m_ele = m_msh->ele_vector[ele_vector_at_geo[i]]; + if (m_ele->GetIndex() == 4421) + cout << i << "\n"; + m_ele->SetNormalVector(); + m_ele->GetNodeIndeces(element_nodes); + Use_Element = true; + // velocity vector + for (size_t j = 0; j < 3; j++) + v[j] = m_pcs_flow->GetElementValue(m_ele->GetIndex(), v_eidx[j]); + + // BG 04/2011: MassFlux Calculation is not working correctly if it is a 2D mesh in x-z-direction + // z-velocity is stored a y-position -> this is corrected here + if ((dimension == 2) && (axis == 2)) + { + v[2] = v[1]; + v[1] = 0; + } + //-------------------------------------------------------------------- + // get properties + // get porosity of the element + group = m_ele->GetPatchIndex(); + m_mat_mp = mmp_vector[group]; + porosity = m_mat_mp->Porosity(m_ele->GetIndex(), 1); // CB Now provides also heterogeneous porosity, model 11 + // get diffusion coefficient + m_cp = cp_vec[this->pcs_component_number]; + Dm = m_cp->CalcDiffusionCoefficientCP(0, 0, this); + tortuosity = m_mat_mp->TortuosityFunction(m_ele->GetIndex(), 0, 0); + Dm_eff = Dm * tortuosity * porosity; + // get element concentration + C_ele = 0.0; + for (int j = 0; j < int(m_ele->GetNodesNumber(false)); j++) + { + // element concentration = average over all points + size_t nidx = GetNodeValueIndex(pcs_primary_function_name[0]) + 1; + ElementConcentration[j] = GetNodeValue(element_nodes[j], nidx); + // if (ElementConcentration[j] > 0) + C_ele += ElementConcentration[j]; // BG: 04/2011 sum was not calculated correctly + } + C_ele /= (double)m_ele->GetNodesNumber(false); + // calculate the norm (Betrag) of the velocity vector + norm_v = MBtrgVec(v, 3); + for (size_t j = 0; j < 3; j++) + { + J_adv[j] = 0; + J_disp[j] = 0; + J_diff[j] = 0; + j_diff[j] = 0; + j_disp[j] = 0; } - //determine the dimension and the orientation of the mesh - coordinateflag = m_msh->GetCoordinateFlag(); - if(coordinateflag == 10) {dimension = 1; axis = 0;} // x only - else if(coordinateflag == 11) {dimension = 1; axis = 1;} // y only - else if(coordinateflag == 12) {dimension = 1; axis = 2;} // z only - else if(coordinateflag == 21) {dimension = 2; axis = 1;} // x, y only - else if(coordinateflag == 22) {dimension = 2; axis = 2;} // x, z only - else if(coordinateflag == 32) {dimension = 3; axis = 3;} // x, y, z only - //loop over all elements at the polyline - for (size_t i = 0; i < ele_vector_at_geo.size(); i++) + //-------------------------------------------------------------------- + // Calculate Flux depending on element dimension + if (m_ele->GetDimension() == 2) { - m_ele = m_msh->ele_vector[ele_vector_at_geo[i]]; - if (m_ele->GetIndex() == 4421) - cout << i << "\n"; - m_ele->SetNormalVector(); - m_ele->GetNodeIndeces(element_nodes); - Use_Element = true; - // velocity vector - for (size_t j = 0; j < 3; j++) - v[j] = m_pcs_flow->GetElementValue(m_ele->GetIndex(), v_eidx[j]); - - //BG 04/2011: MassFlux Calculation is not working correctly if it is a 2D mesh in x-z-direction - //z-velocity is stored a y-position -> this is corrected here - if ((dimension == 2) && (axis == 2)) - { - v[2] = v[1]; - v[1] = 0; - } - //-------------------------------------------------------------------- - //get properties - //get porosity of the element - group = m_ele->GetPatchIndex(); - m_mat_mp = mmp_vector[group]; - porosity = m_mat_mp->Porosity(m_ele->GetIndex(), 1); // CB Now provides also heterogeneous porosity, model 11 - //get diffusion coefficient - m_cp = cp_vec[this->pcs_component_number]; - Dm = m_cp->CalcDiffusionCoefficientCP(0, 0, this); - tortuosity = m_mat_mp->TortuosityFunction(m_ele->GetIndex(),0,0); - Dm_eff = Dm * tortuosity * porosity; - //get element concentration - C_ele = 0.0; - for (int j = 0; j < int(m_ele->GetNodesNumber(false)); j++) - { - // element concentration = average over all points - size_t nidx = GetNodeValueIndex(pcs_primary_function_name[0]) + 1; - ElementConcentration[j] = GetNodeValue(element_nodes[j], nidx); - //if (ElementConcentration[j] > 0) - C_ele += ElementConcentration[j]; //BG: 04/2011 sum was not calculated correctly - } - C_ele /= (double) m_ele->GetNodesNumber(false); - // calculate the norm (Betrag) of the velocity vector - norm_v = MBtrgVec(v, 3); - for (size_t j = 0; j < 3; j++) - { - J_adv[j] = 0; - J_disp[j] = 0; - J_diff[j] = 0; - j_diff[j] = 0; - j_disp[j] = 0; - } - - //-------------------------------------------------------------------- - //Calculate Flux depending on element dimension - if (m_ele->GetDimension() == 2) + // edge projection // edge marked + m_ele->GetEdges(ele_edges_vector); + // cout << "Element: " << "\n"; + edg_length = 0; + // loop over the edges of the element to find the edge at the polyline + for (size_t j = 0; j < static_cast(m_ele->GetEdgesNumber()); j++) { - // edge projection // edge marked - m_ele->GetEdges(ele_edges_vector); - //cout << "Element: " << "\n"; - edg_length = 0; - //loop over the edges of the element to find the edge at the polyline - for (size_t j = 0; j < static_cast(m_ele->GetEdgesNumber()); j++) + m_edg = ele_edges_vector[j]; + // check if edge was already used + Edge_already_used = false; + for (int k = 0; k < int(vecConsideredEdges.size()); k++) + if (m_edg->GetIndex() == vecConsideredEdges[k]) + Edge_already_used = true; + if (Edge_already_used == true) { - m_edg = ele_edges_vector[j]; - //check if edge was already used - Edge_already_used = false; - for (int k=0; k < int(vecConsideredEdges.size()); k++) - if (m_edg->GetIndex() == vecConsideredEdges[k]) - Edge_already_used = true; - if (Edge_already_used == true) - { - Edge_on_Geo = false; - Use_Element = false; - } - else + Edge_on_Geo = false; + Use_Element = false; + } + else + { + vec_nodes_edge.clear(); + // BG 04/2011: check if edge is completely on the polyline + Edge_on_Geo = true; + vec_nodes_edge.push_back(m_edg->GetNode(0)); + vec_nodes_edge.push_back(m_edg->GetNode(1)); + // loop over the nodes of the edge to check if all of them are on the polyline + for (int k = 0; k < int(vec_nodes_edge.size()); k++) { - vec_nodes_edge.clear(); - //BG 04/2011: check if edge is completely on the polyline - Edge_on_Geo = true; - vec_nodes_edge.push_back(m_edg->GetNode(0)); - vec_nodes_edge.push_back(m_edg->GetNode(1)); - //loop over the nodes of the edge to check if all of them are on the polyline - for (int k = 0; k < int(vec_nodes_edge.size()); k ++) + Point_on_Geo = false; + for (int l = 0; l < int(nod_vector_at_geo.size()); l++) { - Point_on_Geo = false; - for (int l = 0; l < int(nod_vector_at_geo.size()); l ++) + if (vec_nodes_edge[k]->GetIndex() == nod_vector_at_geo[l]) { - if (vec_nodes_edge[k]->GetIndex() == nod_vector_at_geo[l]) - { - Point_on_Geo = true; - l = nod_vector_at_geo.size(); - } + Point_on_Geo = true; + l = nod_vector_at_geo.size(); } - //cout << " Node: " << vec_nodes_edge[k]->GetIndex() << " " << Point_on_Geo << "\n"; - if (Point_on_Geo == false) - Edge_on_Geo = false; - } - if (Edge_on_Geo == true) - j = m_ele->GetEdgesNumber(); - } - if ((m_edg->GetMark()) && (Use_Element == true) && (Edge_on_Geo == true)) - { - vecConsideredEdges.push_back(m_edg->GetIndex()); //all edges that were already used are stored - m_edg->SetNormalVector(m_ele->normal_vector, edg_normal_vector); - edg_length = m_edg->getLength(); - //cout << "Element: " << m_ele->GetIndex() << " Länge: " << edg_length << " Normalvektor: x=" << edg_normal_vector[0] << " y=" << edg_normal_vector[1] << " z=" << edg_normal_vector[2] << "\n"; - m_edg->GetEdgeVector(edge_vector); - - //cout << i << " " << m_ele->GetIndex() << "\n"; - //calculate the velocity vector perpendicular to the edge - vn = MSkalarprodukt(v, edg_normal_vector, 3); //vn = MSkalarprodukt(v, edg_normal_vector, 3); - for (size_t j = 0; j < 3; j++) - { - vn_vec[j] = vn * edg_normal_vector[j]; - } - - //------------------------------------------------------------------------------ - //calculate advective mass flux = v_n * l^e * z^e * C^e - for (size_t j = 0; j < 3; j++) //for (size_t j = 0; j < 3; j++) - { - //Darcy velocity times concentration times cross-section area - J_adv[j] = vn_vec[j] * edg_length * m_ele->GetFluxArea() * C_ele; // unit: [mol/s] - } - //cout << " element: " << m_ele->GetIndex() << " vx: " << vn_vec[0] << " vy: " << vn_vec[1] << " vz: " << vn_vec[2] << " c1: " << ElementConcentration[0] << " c2: " << ElementConcentration[1] << " c3: " << ElementConcentration[2] << " c: " << C_ele << "\n"; - //cout << " J_adv_x: " << J_adv[0] << " J_adv_y: " << J_adv[1] << " J_adv_z: " << J_adv[2] << "\n"; - - //------------------------------------------------------------------------------ - // diffusive mass flux - //calculate concentration gradient for the element - Calc2DElementGradient(m_ele, ElementConcentration, ConcentrationGradient); - //calculate diffusive mass flux - for (size_t j = 0; j < 3; j++) - j_diff[j] = Dm_eff * ConcentrationGradient[j]; // [mol/m2.s] - //calculated the mass flux perpendicular to the edge - temp_j = MSkalarprodukt(j_diff, edg_normal_vector, 3); - for (size_t j = 0; j < 3; j++) - { - j_diff[j] = temp_j * edg_normal_vector[j]; - J_diff[j] = j_diff[j] * edg_length * m_ele->GetFluxArea(); // [mol/s] - } - //cout << " Dm: " << Dm_eff << " dc_x: " << ConcentrationGradient[0] << " dc_y: " << ConcentrationGradient[1] << " J_diff_x: " << J_diff[0] << " J_diff_y: " << J_diff[1] << " J_diff_z: " << J_diff[2] << "\n"; - - //------------------------------------------------------------------------------ - // dispersive mass flux - //get dispersivities - alpha_l = m_mat_mp->mass_dispersion_longitudinal; - alpha_t = m_mat_mp->mass_dispersion_transverse; - - if (norm_v != 0) - { - Disp_xx = alpha_l * pow(v[0],2) / norm_v + alpha_t * pow(v[1],2) / norm_v; //ToDo: z-Dimension - Disp_yy = alpha_l * pow(v[1],2) / norm_v + alpha_t * pow(v[0],2) / norm_v; //ToDo: z-Dimension - Disp_xy = (alpha_l - alpha_t) * v[0] * v[1] / norm_v; //ToDo: z-Dimension - //calculate dispersive mass flux - j_disp[0] = porosity * (Disp_xx * ConcentrationGradient[0] + Disp_xy * ConcentrationGradient[1]); // [mol/m2.s] - j_disp[1] = porosity * (Disp_yy * ConcentrationGradient[1] + Disp_xy * ConcentrationGradient[0]); // [mol/m2.s] - j_disp[2] = 0; // [mol/m2.s] - } - else - for (size_t j = 0; j < 3; j++) - j_disp[j] = 0; - //calculated the mass flux perpendicular to the edge - temp_j = MSkalarprodukt(j_disp, edg_normal_vector, 3); - for (size_t j = 0; j < 3; j++) - { - j_disp[j] = temp_j * edg_normal_vector[j]; - J_disp[j] = j_disp[j] * edg_length * m_ele->GetFluxArea(); // [mol/s] } + // cout << " Node: " << vec_nodes_edge[k]->GetIndex() << " " << Point_on_Geo << "\n"; + if (Point_on_Geo == false) + Edge_on_Geo = false; } + if (Edge_on_Geo == true) + j = m_ele->GetEdgesNumber(); } - } - if (m_ele->GetDimension() == 1) - { - //loop over the nodes of the element to check if the node at the polyline was already used, BG 11/2011 - Use_Element = true; - for (size_t j = 0; j < static_cast(m_ele->GetNodesNumber(false)); j++) + if ((m_edg->GetMark()) && (Use_Element == true) && (Edge_on_Geo == true)) { - m_node = m_ele->GetNode(j); - //check if edge was already used - Node_already_used = false; - for (int k=0; k < int(vecConsideredNodes.size()); k++) - if (m_node->GetIndex() == vecConsideredNodes[k]) - Node_already_used = true; - if (Node_already_used == true) + vecConsideredEdges.push_back(m_edg->GetIndex()); // all edges that were already used are stored + m_edg->SetNormalVector(m_ele->normal_vector, edg_normal_vector); + edg_length = m_edg->getLength(); + // cout << "Element: " << m_ele->GetIndex() << " Länge: " << edg_length << " Normalvektor: x=" << + // edg_normal_vector[0] << " y=" << edg_normal_vector[1] << " z=" << edg_normal_vector[2] << "\n"; + m_edg->GetEdgeVector(edge_vector); + + // cout << i << " " << m_ele->GetIndex() << "\n"; + // calculate the velocity vector perpendicular to the edge + vn = MSkalarprodukt(v, edg_normal_vector, 3); // vn = MSkalarprodukt(v, edg_normal_vector, 3); + for (size_t j = 0; j < 3; j++) { - Use_Element = false; + vn_vec[j] = vn * edg_normal_vector[j]; } - } - if (Use_Element == true) - { - for (int l = 0; l < int(nod_vector_at_geo.size()); l ++) + //------------------------------------------------------------------------------ + // calculate advective mass flux = v_n * l^e * z^e * C^e + for (size_t j = 0; j < 3; j++) // for (size_t j = 0; j < 3; j++) { - if (static_cast(m_ele->GetNodeIndex(0)) == nod_vector_at_geo[l]) - { - vecConsideredNodes.push_back(m_ele->GetNodeIndex(0)); - l = int(nod_vector_at_geo.size()); - } - if (static_cast(m_ele->GetNodeIndex(1)) == nod_vector_at_geo[l]) - { - vecConsideredNodes.push_back(m_ele->GetNodeIndex(1)); - l = int(nod_vector_at_geo.size()); - } + // Darcy velocity times concentration times cross-section area + J_adv[j] = vn_vec[j] * edg_length * m_ele->GetFluxArea() * C_ele; // unit: [mol/s] } - //calculate advective mass flux = v_n * l^e * z^e * C^e - //Darcy velocity times concentration times cross-section area - J_adv[0] = norm_v * m_ele->GetFluxArea() * C_ele; // unit: [mol/s] - //cout << " element: " << m_ele->GetIndex() << " vx: " << vn_vec[0] << " vy: " << vn_vec[1] << " vz: " << vn_vec[2] << " c1: " << ElementConcentration[0] << " c2: " << ElementConcentration[1] << " c3: " << ElementConcentration[2] << " c: " << C_ele << "\n"; - //cout << " J_adv_x: " << J_adv[0] << " J_adv_y: " << J_adv[1] << " J_adv_z: " << J_adv[2] << "\n"; + // cout << " element: " << m_ele->GetIndex() << " vx: " << vn_vec[0] << " vy: " << vn_vec[1] << " + // vz: " << vn_vec[2] << " c1: " << ElementConcentration[0] << " c2: " << ElementConcentration[1] << + // " c3: " << ElementConcentration[2] << " c: " << C_ele << "\n"; + // cout << " J_adv_x: " << J_adv[0] << " J_adv_y: " << J_adv[1] << " J_adv_z: " << J_adv[2] << + // "\n"; //------------------------------------------------------------------------------ // diffusive mass flux - //calculate concentration gradient for the element + // calculate concentration gradient for the element Calc2DElementGradient(m_ele, ElementConcentration, ConcentrationGradient); - //calculate diffusive mass flux - j_diff[0] = Dm_eff * ConcentrationGradient[0]; // [mol/m2.s] - J_diff[0] = j_diff[0] * m_ele->GetFluxArea(); // [mol/s] - //cout << " Dm: " << Dm_eff << " dc_x: " << ConcentrationGradient[0] << " dc_y: " << ConcentrationGradient[1] << " J_diff_x: " << J_diff[0] << " J_diff_y: " << J_diff[1] << " J_diff_z: " << J_diff[2] << "\n"; + // calculate diffusive mass flux + for (size_t j = 0; j < 3; j++) + j_diff[j] = Dm_eff * ConcentrationGradient[j]; // [mol/m2.s] + // calculated the mass flux perpendicular to the edge + temp_j = MSkalarprodukt(j_diff, edg_normal_vector, 3); + for (size_t j = 0; j < 3; j++) + { + j_diff[j] = temp_j * edg_normal_vector[j]; + J_diff[j] = j_diff[j] * edg_length * m_ele->GetFluxArea(); // [mol/s] + } + // cout << " Dm: " << Dm_eff << " dc_x: " << ConcentrationGradient[0] << " dc_y: " << + // ConcentrationGradient[1] << " J_diff_x: " << J_diff[0] << " J_diff_y: " << J_diff[1] << " + // J_diff_z: " << J_diff[2] << "\n"; //------------------------------------------------------------------------------ // dispersive mass flux - //get dispersivity along the element direction + // get dispersivities alpha_l = m_mat_mp->mass_dispersion_longitudinal; + alpha_t = m_mat_mp->mass_dispersion_transverse; - //calculate dispersion coefficients based on velocity of the element if (norm_v != 0) { - Disp_xx = alpha_l * norm_v; - //calculate dispersive mass flux - j_disp[0] = porosity * Disp_xx * ConcentrationGradient[0]; // [mol/m2.s] + Disp_xx = alpha_l * pow(v[0], 2) / norm_v + alpha_t * pow(v[1], 2) / norm_v; // ToDo: + // z-Dimension + Disp_yy = alpha_l * pow(v[1], 2) / norm_v + alpha_t * pow(v[0], 2) / norm_v; // ToDo: + // z-Dimension + Disp_xy = (alpha_l - alpha_t) * v[0] * v[1] / norm_v; // ToDo: z-Dimension + // calculate dispersive mass flux + j_disp[0] = porosity * (Disp_xx * ConcentrationGradient[0] + + Disp_xy * ConcentrationGradient[1]); // [mol/m2.s] + j_disp[1] = porosity * (Disp_yy * ConcentrationGradient[1] + + Disp_xy * ConcentrationGradient[0]); // [mol/m2.s] + j_disp[2] = 0; // [mol/m2.s] } else - j_disp[0] = 0; - //calculated the mass flux perpendicular to the edge - J_disp[0] = j_disp[0] * m_ele->GetFluxArea(); // [mol/s] - + for (size_t j = 0; j < 3; j++) + j_disp[j] = 0; + // calculated the mass flux perpendicular to the edge + temp_j = MSkalarprodukt(j_disp, edg_normal_vector, 3); + for (size_t j = 0; j < 3; j++) + { + j_disp[j] = temp_j * edg_normal_vector[j]; + J_disp[j] = j_disp[j] * edg_length * m_ele->GetFluxArea(); // [mol/s] + } } } - //-------------------------------------------------------------------- - //sum the mass flux over all considered elements - J_adv_temp = MBtrgVec(J_adv, 3); - J_disp_temp = MBtrgVec(J_disp, 3); - J_diff_temp = MBtrgVec(J_diff, 3); - J_temp = J_adv_temp + J_disp_temp + J_diff_temp; - //mass check - // totalmassflux = 0.0; // 2012-08 TF not used - // totalmass = C_ele * porosity * m_ele->GetVolume(); // 2012-08 TF not used - - // 2012-08 TF, since totalmassflux is not used we can comment out the following two lines - // if (this->Tim->time_step_length > 0) - // totalmassflux = totalmass / this->Tim->time_step_length; - //cout << "Element: " << i << " Masse: " << totalmass << " Abstrom_adv: " << this->Tim->this_stepsize * MBtrgVec(J_adv, 3) << " Abstrom_diff: " << this->Tim->this_stepsize * MBtrgVec(J_diff, 3) << " Abstrom_disp: " << this->Tim->this_stepsize * MBtrgVec(J_disp, 3); - //cout << "\n"; - //correct mass flux - //if (J_temp > totalmassflux) - //{ - // J_adv_temp += J_adv_temp / J_temp * (totalmassflux - J_temp); - // J_disp_temp += J_disp_temp / J_temp * (totalmassflux - J_temp); - // J_diff_temp += J_diff_temp / J_temp * (totalmassflux - J_temp); - // J_temp = totalmassflux; - //} - J_adv_sum += J_adv_temp; - J_disp_sum += J_disp_temp; - J_diff_sum += J_diff_temp; - J_sum += J_temp; - if (this->Tim->time_step_length > 0) - this->TotalMass[numberPolyline] += J_temp * this->Tim->time_step_length; - } - result[0] = J_adv_sum; - result[1] = J_disp_sum; - result[2] = J_diff_sum; - result[3] = J_sum; - result[4] = this->TotalMass[numberPolyline]; - ele_vector_at_geo.clear(); - - delete [] ConcentrationGradient; - } - - - /************************************************************************** - GeoSys - Function: Calc2DElementGradient - Task: Calculate the Gradient for an 2D Element - Return: nothing - Programming: 05/2011 BG - Modification: - **************************************************************************/ - void CRFProcess::Calc2DElementGradient(MeshLib::CElem* m_ele, double ElementConcentration[4], double *grad) - { - double coord_Point1[3]; - double coord_Point2[3]; - double coord_Point3[3]; - double coord_Point4[3]; - double *normal_vector; - - //get the nodes of the 2D Element - vector vecElementNodes; - m_ele->GetNodes(vecElementNodes); - CPlaneEquation *PlaneEquation; - PlaneEquation = new CPlaneEquation(); - + } if (m_ele->GetDimension() == 1) { - if (m_ele->GetElementType() == MshElemType::LINE) + // loop over the nodes of the element to check if the node at the polyline was already used, BG 11/2011 + Use_Element = true; + for (size_t j = 0; j < static_cast(m_ele->GetNodesNumber(false)); j++) + { + m_node = m_ele->GetNode(j); + // check if edge was already used + Node_already_used = false; + for (int k = 0; k < int(vecConsideredNodes.size()); k++) + if (m_node->GetIndex() == vecConsideredNodes[k]) + Node_already_used = true; + if (Node_already_used == true) + { + Use_Element = false; + } + } + + if (Use_Element == true) { - //calculate gradient based on the concentration difference and the length of the element - grad[0] = (ElementConcentration[1] - ElementConcentration[0]) / (m_ele->GetVolume() / m_ele->GetFluxArea()); - grad[1] = 0; - grad[2] = 0; + for (int l = 0; l < int(nod_vector_at_geo.size()); l++) + { + if (static_cast(m_ele->GetNodeIndex(0)) == nod_vector_at_geo[l]) + { + vecConsideredNodes.push_back(m_ele->GetNodeIndex(0)); + l = int(nod_vector_at_geo.size()); + } + if (static_cast(m_ele->GetNodeIndex(1)) == nod_vector_at_geo[l]) + { + vecConsideredNodes.push_back(m_ele->GetNodeIndex(1)); + l = int(nod_vector_at_geo.size()); + } + } + // calculate advective mass flux = v_n * l^e * z^e * C^e + // Darcy velocity times concentration times cross-section area + J_adv[0] = norm_v * m_ele->GetFluxArea() * C_ele; // unit: [mol/s] + // cout << " element: " << m_ele->GetIndex() << " vx: " << vn_vec[0] << " vy: " << vn_vec[1] << " vz: " + // << vn_vec[2] << " c1: " << ElementConcentration[0] << " c2: " << ElementConcentration[1] << " c3: " + // << ElementConcentration[2] << " c: " << C_ele << "\n"; + // cout << " J_adv_x: " << J_adv[0] << " J_adv_y: " << J_adv[1] << " J_adv_z: " << J_adv[2] << + // "\n"; + + //------------------------------------------------------------------------------ + // diffusive mass flux + // calculate concentration gradient for the element + Calc2DElementGradient(m_ele, ElementConcentration, ConcentrationGradient); + // calculate diffusive mass flux + j_diff[0] = Dm_eff * ConcentrationGradient[0]; // [mol/m2.s] + J_diff[0] = j_diff[0] * m_ele->GetFluxArea(); // [mol/s] + // cout << " Dm: " << Dm_eff << " dc_x: " << ConcentrationGradient[0] << " dc_y: " << + // ConcentrationGradient[1] << " J_diff_x: " << J_diff[0] << " J_diff_y: " << J_diff[1] << " J_diff_z: " + // << J_diff[2] << "\n"; + + //------------------------------------------------------------------------------ + // dispersive mass flux + // get dispersivity along the element direction + alpha_l = m_mat_mp->mass_dispersion_longitudinal; + + // calculate dispersion coefficients based on velocity of the element + if (norm_v != 0) + { + Disp_xx = alpha_l * norm_v; + // calculate dispersive mass flux + j_disp[0] = porosity * Disp_xx * ConcentrationGradient[0]; // [mol/m2.s] + } + else + j_disp[0] = 0; + // calculated the mass flux perpendicular to the edge + J_disp[0] = j_disp[0] * m_ele->GetFluxArea(); // [mol/s] } - else - cout << "This element option is not yet considered for calculating the concentration gradient!" << "\n"; } + //-------------------------------------------------------------------- + // sum the mass flux over all considered elements + J_adv_temp = MBtrgVec(J_adv, 3); + J_disp_temp = MBtrgVec(J_disp, 3); + J_diff_temp = MBtrgVec(J_diff, 3); + J_temp = J_adv_temp + J_disp_temp + J_diff_temp; + // mass check + // totalmassflux = 0.0; // 2012-08 TF not used + // totalmass = C_ele * porosity * m_ele->GetVolume(); // 2012-08 TF not used + + // 2012-08 TF, since totalmassflux is not used we can comment out the following two lines + // if (this->Tim->time_step_length > 0) + // totalmassflux = totalmass / this->Tim->time_step_length; + // cout << "Element: " << i << " Masse: " << totalmass << " Abstrom_adv: " << this->Tim->this_stepsize * + // MBtrgVec(J_adv, 3) << " Abstrom_diff: " << this->Tim->this_stepsize * MBtrgVec(J_diff, 3) << " Abstrom_disp: + // " << this->Tim->this_stepsize * MBtrgVec(J_disp, 3); + // cout << "\n"; + // correct mass flux + // if (J_temp > totalmassflux) + //{ + // J_adv_temp += J_adv_temp / J_temp * (totalmassflux - J_temp); + // J_disp_temp += J_disp_temp / J_temp * (totalmassflux - J_temp); + // J_diff_temp += J_diff_temp / J_temp * (totalmassflux - J_temp); + // J_temp = totalmassflux; + //} + J_adv_sum += J_adv_temp; + J_disp_sum += J_disp_temp; + J_diff_sum += J_diff_temp; + J_sum += J_temp; + if (this->Tim->time_step_length > 0) + this->TotalMass[numberPolyline] += J_temp * this->Tim->time_step_length; + } + result[0] = J_adv_sum; + result[1] = J_disp_sum; + result[2] = J_diff_sum; + result[3] = J_sum; + result[4] = this->TotalMass[numberPolyline]; + ele_vector_at_geo.clear(); + + delete[] ConcentrationGradient; +} - else if (m_ele->GetDimension() == 2) - { - if (m_ele->GetElementType() == MshElemType::QUAD) //BG 04/2011: calculation of the normal vector of a quad element - { - //define the points used for the plane equation - // order of points: 1, 2, 3, 4 against clock direction -> points are given in the order 1, 2, 4 to get a positive normal vector - double const* const p0 (vecElementNodes[0]->getData()); - double const* const p1 (vecElementNodes[1]->getData()); - double const* const p2 (vecElementNodes[2]->getData()); - double const* const p3 (vecElementNodes[3]->getData()); +/************************************************************************** +GeoSys - Function: Calc2DElementGradient +Task: Calculate the Gradient for an 2D Element +Return: nothing +Programming: 05/2011 BG +Modification: + **************************************************************************/ +void CRFProcess::Calc2DElementGradient(MeshLib::CElem* m_ele, double ElementConcentration[4], double* grad) +{ + double coord_Point1[3]; + double coord_Point2[3]; + double coord_Point3[3]; + double coord_Point4[3]; + double* normal_vector; - coord_Point1[0] = p0[0]; coord_Point1[1] = p0[1]; coord_Point1[2] = ElementConcentration[0]; - coord_Point2[0] = p1[0]; coord_Point2[1] = p1[1]; coord_Point2[2] = ElementConcentration[1]; - coord_Point3[0] = p2[0]; coord_Point3[1] = p2[1]; coord_Point3[2] = ElementConcentration[2]; - coord_Point4[0] = p3[0]; coord_Point4[1] = p3[1]; coord_Point4[2] = ElementConcentration[3]; + // get the nodes of the 2D Element + vector vecElementNodes; + m_ele->GetNodes(vecElementNodes); + CPlaneEquation* PlaneEquation; + PlaneEquation = new CPlaneEquation(); - //Calculate the plane equation - PlaneEquation->CalculatePlaneEquationFrom3Points(coord_Point1, coord_Point2, coord_Point4); - //check if 4. point lies within the plane - if (PlaneEquation->CheckIfPointInPlane(coord_Point3)==false) - return; - } + if (m_ele->GetDimension() == 1) + { + if (m_ele->GetElementType() == MshElemType::LINE) + { + // calculate gradient based on the concentration difference and the length of the element + grad[0] = (ElementConcentration[1] - ElementConcentration[0]) / (m_ele->GetVolume() / m_ele->GetFluxArea()); + grad[1] = 0; + grad[2] = 0; + } + else + cout << "This element option is not yet considered for calculating the concentration gradient!" + << "\n"; + } - if (m_ele->GetElementType() == MshElemType::TRIANGLE) - { - //define the points used for the plane equation - // order of points: 1, 2, 3 against clock direction -> points are given in the order 2, 3, 1 to get a positive normal vector - double const* const p0 (vecElementNodes[0]->getData()); - double const* const p1 (vecElementNodes[1]->getData()); - double const* const p2 (vecElementNodes[2]->getData()); + else if (m_ele->GetDimension() == 2) + { + if (m_ele->GetElementType() + == MshElemType::QUAD) // BG 04/2011: calculation of the normal vector of a quad element + { + // define the points used for the plane equation + // order of points: 1, 2, 3, 4 against clock direction -> points are given in the order 1, 2, 4 to get a + // positive normal vector + double const* const p0(vecElementNodes[0]->getData()); + double const* const p1(vecElementNodes[1]->getData()); + double const* const p2(vecElementNodes[2]->getData()); + double const* const p3(vecElementNodes[3]->getData()); + + coord_Point1[0] = p0[0]; + coord_Point1[1] = p0[1]; + coord_Point1[2] = ElementConcentration[0]; + coord_Point2[0] = p1[0]; + coord_Point2[1] = p1[1]; + coord_Point2[2] = ElementConcentration[1]; + coord_Point3[0] = p2[0]; + coord_Point3[1] = p2[1]; + coord_Point3[2] = ElementConcentration[2]; + coord_Point4[0] = p3[0]; + coord_Point4[1] = p3[1]; + coord_Point4[2] = ElementConcentration[3]; + + // Calculate the plane equation + PlaneEquation->CalculatePlaneEquationFrom3Points(coord_Point1, coord_Point2, coord_Point4); + // check if 4. point lies within the plane + if (PlaneEquation->CheckIfPointInPlane(coord_Point3) == false) + return; + } - coord_Point1[0] = p0[0]; coord_Point1[1] = p0[1]; coord_Point1[2] = ElementConcentration[0]; - coord_Point2[0] = p1[0]; coord_Point2[1] = p1[1]; coord_Point2[2] = ElementConcentration[1]; - coord_Point3[0] = p2[0]; coord_Point3[1] = p2[1]; coord_Point3[2] = ElementConcentration[2]; + if (m_ele->GetElementType() == MshElemType::TRIANGLE) + { + // define the points used for the plane equation + // order of points: 1, 2, 3 against clock direction -> points are given in the order 2, 3, 1 to get a + // positive normal vector + double const* const p0(vecElementNodes[0]->getData()); + double const* const p1(vecElementNodes[1]->getData()); + double const* const p2(vecElementNodes[2]->getData()); - //Calculate the plane equation - PlaneEquation->CalculatePlaneEquationFrom3Points(coord_Point2, coord_Point3, coord_Point1); - } - else - cout << "This element option is not yet considered for calculating the concentration gradient!" << "\n"; + coord_Point1[0] = p0[0]; + coord_Point1[1] = p0[1]; + coord_Point1[2] = ElementConcentration[0]; + coord_Point2[0] = p1[0]; + coord_Point2[1] = p1[1]; + coord_Point2[2] = ElementConcentration[1]; + coord_Point3[0] = p2[0]; + coord_Point3[1] = p2[1]; + coord_Point3[2] = ElementConcentration[2]; - //calculate gradient - normal_vector = PlaneEquation->GetNormalVector(); - grad[0] = normal_vector[0] / normal_vector[2]; - grad[1] = normal_vector[1] / normal_vector[2]; - grad[2] = 0; //grad[2] = normal_vector[2] / normal_vector[2]; + // Calculate the plane equation + PlaneEquation->CalculatePlaneEquationFrom3Points(coord_Point2, coord_Point3, coord_Point1); } - else - cout << "This element option is not yet considered for calculating the concentration gradient!" << "\n"; + cout << "This element option is not yet considered for calculating the concentration gradient!" + << "\n"; + + // calculate gradient + normal_vector = PlaneEquation->GetNormalVector(); + grad[0] = normal_vector[0] / normal_vector[2]; + grad[1] = normal_vector[1] / normal_vector[2]; + grad[2] = 0; // grad[2] = normal_vector[2] / normal_vector[2]; } + else + cout << "This element option is not yet considered for calculating the concentration gradient!" + << "\n"; +} + /************************************************************************** FEMLib-Method: Task: @@ -12423,153 +12422,151 @@ void CRFProcess::CalcSecondaryVariablesLiquidFlow() 11/2004 OK Implementation 08/2006 OK new **************************************************************************/ - void CRFProcess::CalcELEVelocities(void) - { - int eidx[3]; +void CRFProcess::CalcELEVelocities(void) +{ + int eidx[3]; - // If not FLUID_MOMENTUM, - // if (_pcs_type_name.compare("RANDOM_WALK") != 0) { - FiniteElement::ProcessType pcs_type (getProcessType()); //BG + // If not FLUID_MOMENTUM, + // if (_pcs_type_name.compare("RANDOM_WALK") != 0) { + FiniteElement::ProcessType pcs_type(getProcessType()); // BG - if (this->getProcessType() != FiniteElement::RANDOM_WALK) - { - int eidx[3]; - eidx[0] = GetElementValueIndex("VELOCITY1_X"); - eidx[1] = GetElementValueIndex("VELOCITY1_Y"); - eidx[2] = GetElementValueIndex("VELOCITY1_Z"); - for (size_t i = 0; i < 3; i++) - if (eidx[i] < 0) - cout << - "Fatal error in CRFProcess::CalcELEVelocities - abort" - << "\n"; - //abort(); // PCH commented abort() out for FM. + if (this->getProcessType() != FiniteElement::RANDOM_WALK) + { + int eidx[3]; + eidx[0] = GetElementValueIndex("VELOCITY1_X"); + eidx[1] = GetElementValueIndex("VELOCITY1_Y"); + eidx[2] = GetElementValueIndex("VELOCITY1_Z"); + for (size_t i = 0; i < 3; i++) + if (eidx[i] < 0) + cout << "Fatal error in CRFProcess::CalcELEVelocities - abort" + << "\n"; + // abort(); // PCH commented abort() out for FM. - FiniteElement::ElementValue* gp_ele = NULL; - double vx, vy, vz; - const size_t mesh_ele_vector_size(m_msh->ele_vector.size()); - for (size_t i = 0; i < mesh_ele_vector_size; i++) - { - gp_ele = ele_gp_value[i]; - vx = gp_ele->Velocity(0, 0); - SetElementValue(i, eidx[0], vx); - SetElementValue(i, eidx[0] + 1, vx); - vy = gp_ele->Velocity(1, 0); - SetElementValue(i, eidx[1], vy); - SetElementValue(i, eidx[1] + 1, vy); - vz = gp_ele->Velocity(2, 0); - SetElementValue(i, eidx[2], vz); - SetElementValue(i, eidx[2] + 1, vz); - } - } - if (pcs_type == FiniteElement::MULTI_PHASE_FLOW) + FiniteElement::ElementValue* gp_ele = NULL; + double vx, vy, vz; + const size_t mesh_ele_vector_size(m_msh->ele_vector.size()); + for (size_t i = 0; i < mesh_ele_vector_size; i++) { - eidx[0] = GetElementValueIndex("VELOCITY2_X"); - eidx[1] = GetElementValueIndex("VELOCITY2_Y"); - eidx[2] = GetElementValueIndex("VELOCITY2_Z"); - for (size_t i = 0; i < 3; i++) + gp_ele = ele_gp_value[i]; + vx = gp_ele->Velocity(0, 0); + SetElementValue(i, eidx[0], vx); + SetElementValue(i, eidx[0] + 1, vx); + vy = gp_ele->Velocity(1, 0); + SetElementValue(i, eidx[1], vy); + SetElementValue(i, eidx[1] + 1, vy); + vz = gp_ele->Velocity(2, 0); + SetElementValue(i, eidx[2], vz); + SetElementValue(i, eidx[2] + 1, vz); + } + } + if (pcs_type == FiniteElement::MULTI_PHASE_FLOW) + { + eidx[0] = GetElementValueIndex("VELOCITY2_X"); + eidx[1] = GetElementValueIndex("VELOCITY2_Y"); + eidx[2] = GetElementValueIndex("VELOCITY2_Z"); + for (size_t i = 0; i < 3; i++) if (eidx[i] < 0) - cout << - "Fatal error in CRFProcess::CalcELEVelocities - abort" + cout << "Fatal error in CRFProcess::CalcELEVelocities - abort" << "\n"; - //abort(); // PCH commented abort() out for FM. + // abort(); // PCH commented abort() out for FM. - FiniteElement::ElementValue* gp_ele = NULL; - double vx, vy, vz; - const size_t mesh_ele_vector_size(m_msh->ele_vector.size()); - for (size_t i = 0; i < mesh_ele_vector_size; i++) - { - gp_ele = ele_gp_value[i]; - vx = gp_ele->Velocity_g(0, 0); - SetElementValue(i, eidx[0], vx); - SetElementValue(i, eidx[0] + 1, vx); - vy = gp_ele->Velocity_g(1, 0); - SetElementValue(i, eidx[1], vy); - SetElementValue(i, eidx[1] + 1, vy); - vz = gp_ele->Velocity_g(2, 0); - SetElementValue(i, eidx[2], vz); - SetElementValue(i, eidx[2] + 1, vz); - } + FiniteElement::ElementValue* gp_ele = NULL; + double vx, vy, vz; + const size_t mesh_ele_vector_size(m_msh->ele_vector.size()); + for (size_t i = 0; i < mesh_ele_vector_size; i++) + { + gp_ele = ele_gp_value[i]; + vx = gp_ele->Velocity_g(0, 0); + SetElementValue(i, eidx[0], vx); + SetElementValue(i, eidx[0] + 1, vx); + vy = gp_ele->Velocity_g(1, 0); + SetElementValue(i, eidx[1], vy); + SetElementValue(i, eidx[1] + 1, vy); + vz = gp_ele->Velocity_g(2, 0); + SetElementValue(i, eidx[2], vz); + SetElementValue(i, eidx[2] + 1, vz); } } +} /************************************************************************* GeoSys-FEM Function: 08/2006 OK Implementation **************************************************************************/ -#if !defined(NEW_EQS) && !defined(USE_PETSC) //WW. 07.11.2008. 04.2012 - //(vector&ele_number_vector) - void CRFProcess::AssembleParabolicEquationRHSVector(CNode* m_nod) - { - //cout << "CRFProcess::AssembleParabolicEquationRHSVector" << "\n"; - //int i; - //WW long ldummy; - //WW double ddummy; - //---------------------------------------------------------------------- - // Init - for(size_t i = 0; i < m_nod->getConnectedElementIDs().size(); i++) - eqs->b[m_nod->getConnectedElementIDs()[i]] = 0.0; - //---------------------------------------------------------------------- - CElem* m_ele = NULL; - CEdge* m_edg = NULL; - double edg_normal_vector[3]; - double edge_mid_point[3]; - vecele_edges_vector(15); - int j; - double aux_vector[3]; - double check_sign; - //---------------------------------------------------------------------- - // Element velocity - int v_eidx[3]; - //kg44 v_eidx[0] = GetElementValueIndex("VELOCITY1_X"); - //kg44 v_eidx[1] = GetElementValueIndex("VELOCITY1_Y"); - //kg44 v_eidx[2] = GetElementValueIndex("VELOCITY1_Z"); - CRFProcess* m_pcs_flow = NULL; - // if(_pcs_type_name.find("FLOW")!=string::npos) { - if(isFlowProcess(this->getProcessType())) - m_pcs_flow = this; - else - m_pcs_flow = PCSGet(FiniteElement::GROUNDWATER_FLOW); - v_eidx[0] = m_pcs_flow->GetElementValueIndex("VELOCITY1_X"); - v_eidx[1] = m_pcs_flow->GetElementValueIndex("VELOCITY1_Y"); - v_eidx[2] = m_pcs_flow->GetElementValueIndex("VELOCITY1_Z"); - for(size_t i = 0; i < 3; i++) - if(v_eidx[i] < 0) - { - cout << v_eidx[i] << i << - " Warning in CRFProcess::AssembleParabolicEquationRHSVector - no PCS-VEL data" - << "\n"; - return; - } - double v[3]; - //====================================================================== - // Topology - for(size_t i = 0; i < m_nod->getConnectedElementIDs().size(); i++) +#if !defined(NEW_EQS) && !defined(USE_PETSC) // WW. 07.11.2008. 04.2012 +//(vector&ele_number_vector) +void CRFProcess::AssembleParabolicEquationRHSVector(CNode* m_nod) +{ + // cout << "CRFProcess::AssembleParabolicEquationRHSVector" << "\n"; + // int i; + // WW long ldummy; + // WW double ddummy; + //---------------------------------------------------------------------- + // Init + for (size_t i = 0; i < m_nod->getConnectedElementIDs().size(); i++) + eqs->b[m_nod->getConnectedElementIDs()[i]] = 0.0; + //---------------------------------------------------------------------- + CElem* m_ele = NULL; + CEdge* m_edg = NULL; + double edg_normal_vector[3]; + double edge_mid_point[3]; + vec ele_edges_vector(15); + int j; + double aux_vector[3]; + double check_sign; + //---------------------------------------------------------------------- + // Element velocity + int v_eidx[3]; + // kg44 v_eidx[0] = GetElementValueIndex("VELOCITY1_X"); + // kg44 v_eidx[1] = GetElementValueIndex("VELOCITY1_Y"); + // kg44 v_eidx[2] = GetElementValueIndex("VELOCITY1_Z"); + CRFProcess* m_pcs_flow = NULL; + // if(_pcs_type_name.find("FLOW")!=string::npos) { + if (isFlowProcess(this->getProcessType())) + m_pcs_flow = this; + else + m_pcs_flow = PCSGet(FiniteElement::GROUNDWATER_FLOW); + v_eidx[0] = m_pcs_flow->GetElementValueIndex("VELOCITY1_X"); + v_eidx[1] = m_pcs_flow->GetElementValueIndex("VELOCITY1_Y"); + v_eidx[2] = m_pcs_flow->GetElementValueIndex("VELOCITY1_Z"); + for (size_t i = 0; i < 3; i++) + if (v_eidx[i] < 0) + { + cout << v_eidx[i] << i << " Warning in CRFProcess::AssembleParabolicEquationRHSVector - no PCS-VEL data" + << "\n"; + return; + } + double v[3]; + //====================================================================== + // Topology + for (size_t i = 0; i < m_nod->getConnectedElementIDs().size(); i++) + { + m_ele = m_msh->ele_vector[m_nod->getConnectedElementIDs()[i]]; + m_ele->SetNormalVector(); // OK_BUGFIX + v[0] = m_pcs_flow->GetElementValue(m_ele->GetIndex(), v_eidx[0]); + v[1] = m_pcs_flow->GetElementValue(m_ele->GetIndex(), v_eidx[1]); + v[2] = m_pcs_flow->GetElementValue(m_ele->GetIndex(), v_eidx[2]); + m_ele->SetMark(false); + switch (m_ele->GetElementType()) { - m_ele = m_msh->ele_vector[m_nod->getConnectedElementIDs()[i]]; - m_ele->SetNormalVector(); //OK_BUGFIX - v[0] = m_pcs_flow->GetElementValue(m_ele->GetIndex(),v_eidx[0]); - v[1] = m_pcs_flow->GetElementValue(m_ele->GetIndex(),v_eidx[1]); - v[2] = m_pcs_flow->GetElementValue(m_ele->GetIndex(),v_eidx[2]); - m_ele->SetMark(false); - switch(m_ele->GetElementType()) - { //------------------------------------------------------------------ // line elements - case MshElemType::LINE: { - v[1] = GetElementValue(m_ele->GetIndex(),v_eidx[0]); - v[0] = GetElementValue(m_ele->GetIndex(),v_eidx[1]); - if(m_nod->getConnectedElementIDs().size() == 1) + case MshElemType::LINE: + { + v[1] = GetElementValue(m_ele->GetIndex(), v_eidx[0]); + v[0] = GetElementValue(m_ele->GetIndex(), v_eidx[1]); + if (m_nod->getConnectedElementIDs().size() == 1) { m_ele->SetMark(true); break; } double const* gravity_center(m_ele->GetGravityCenter()); - double const* const pnt (m_nod->getData()); + double const* const pnt(m_nod->getData()); aux_vector[0] = gravity_center[0] - pnt[0]; aux_vector[1] = gravity_center[1] - pnt[1]; aux_vector[2] = gravity_center[2] - pnt[2]; - check_sign = MSkalarprodukt(v,aux_vector,3); - if(check_sign < 0.0) + check_sign = MSkalarprodukt(v, aux_vector, 3); + if (check_sign < 0.0) m_ele->SetMark(true); break; } @@ -12577,13 +12574,12 @@ void CRFProcess::CalcSecondaryVariablesLiquidFlow() // tri elements case MshElemType::TRIANGLE: m_ele->GetEdges(ele_edges_vector); - for(j = 0; j < (int)m_ele->GetEdgesNumber(); j++) + for (j = 0; j < (int)m_ele->GetEdgesNumber(); j++) { m_edg = ele_edges_vector[j]; - if(m_edg->GetMark()) + if (m_edg->GetMark()) { - m_edg->SetNormalVector(m_ele->normal_vector, - edg_normal_vector); + m_edg->SetNormalVector(m_ele->normal_vector, edg_normal_vector); break; /* m_edg->GetEdgeMidPoint(edge_mid_point); @@ -12596,49 +12592,50 @@ void CRFProcess::CalcSecondaryVariablesLiquidFlow() */ } } - if(m_edg->GetMark()) + if (m_edg->GetMark()) break; //---------------------------------------------------------------- // ToDo default: - cout << - "Warning in CRFProcess::AssembleParabolicEquationRHSVector - not implemented for this element type" + cout << "Warning in CRFProcess::AssembleParabolicEquationRHSVector - not implemented for this element " + "type" << "\n"; break; - } // switch - } - //====================================================================== - for(size_t i = 0; i < m_nod->getConnectedElementIDs().size(); i++) + } // switch + } + //====================================================================== + for (size_t i = 0; i < m_nod->getConnectedElementIDs().size(); i++) + { + m_ele = m_msh->ele_vector[m_nod->getConnectedElementIDs()[i]]; + switch (m_ele->GetElementType()) { - m_ele = m_msh->ele_vector[m_nod->getConnectedElementIDs()[i]]; - switch(m_ele->GetElementType()) - { //------------------------------------------------------------------ // line elements case MshElemType::LINE: - if(m_ele->GetMark()) + if (m_ele->GetMark()) { cout << m_ele->GetIndex() << "\n"; - //WW ldummy = m_nod->GetIndex(); - //WW ddummy = eqs->b[m_nod->GetIndex()]; + // WW ldummy = m_nod->GetIndex(); + // WW ddummy = eqs->b[m_nod->GetIndex()]; fem->ConfigElement(m_ele, m_num->ele_gauss_points, false); fem->AssembleParabolicEquationRHSVector(); - //WW ddummy = eqs->b[m_nod->GetIndex()]; + // WW ddummy = eqs->b[m_nod->GetIndex()]; } break; //------------------------------------------------------------------ // tri elements - case MshElemType::TRIANGLE: { + case MshElemType::TRIANGLE: + { m_edg->GetEdgeMidPoint(edge_mid_point); double const* gravity_center(m_ele->GetGravityCenter()); aux_vector[0] = gravity_center[0] - edge_mid_point[0]; aux_vector[1] = gravity_center[1] - edge_mid_point[1]; aux_vector[2] = gravity_center[2] - edge_mid_point[2]; - check_sign = MSkalarprodukt(edg_normal_vector,aux_vector,3); - if(check_sign < 0.0) + check_sign = MSkalarprodukt(edg_normal_vector, aux_vector, 3); + if (check_sign < 0.0) continue; { - //cout << m_ele->GetIndex() << "\n"; + // cout << m_ele->GetIndex() << "\n"; fem->ConfigElement(m_ele, m_num->ele_gauss_points, false); fem->AssembleParabolicEquationRHSVector(); } @@ -12647,14 +12644,14 @@ void CRFProcess::CalcSecondaryVariablesLiquidFlow() //---------------------------------------------------------------- // ToDo default: - cout << - "Warning in CRFProcess::AssembleParabolicEquationRHSVector - not implemented for this element type" + cout << "Warning in CRFProcess::AssembleParabolicEquationRHSVector - not implemented for this element " + "type" << "\n"; break; - } // switch - } - //====================================================================== + } // switch } + //====================================================================== +} #endif /************************************************************************** @@ -12665,7 +12662,7 @@ compare with CMCDs PCSGetFluxProcess **************************************************************************/ CRFProcess* PCSGetFlow() { - if(pcs_number_flow >= 0) + if (pcs_number_flow >= 0) return pcs_vector[pcs_number_flow]; return NULL; } @@ -12676,7 +12673,7 @@ PCSLib-Method: **************************************************************************/ CRFProcess* PCSGetHeat() { - if(pcs_number_heat >= 0) + if (pcs_number_heat >= 0) return pcs_vector[pcs_number_heat]; return NULL; } @@ -12687,7 +12684,7 @@ PCSLib-Method: **************************************************************************/ CRFProcess* PCSGetDeformation() { - if(pcs_number_deformation >= 0) + if (pcs_number_deformation >= 0) return pcs_vector[pcs_number_deformation]; return NULL; } @@ -12698,8 +12695,10 @@ PCSLib-Method: **************************************************************************/ CRFProcess* PCSGetMass(size_t component_number) { - if(component_number < DOF_NUMBER_MAX){ // don't exceed array dimensions - if(pcs_number_mass[component_number] >= 0){ + if (component_number < DOF_NUMBER_MAX) + { // don't exceed array dimensions + if (pcs_number_mass[component_number] >= 0) + { return pcs_vector[pcs_number_mass[component_number]]; } } @@ -12711,23 +12710,21 @@ CRFProcess* PCSGetMass(size_t component_number) based on MMPCalcSecondaryVariables 01/2007 OK Implementation **************************************************************************/ - void CRFProcess::SetBC() - { - //WW CBoundaryCondition *m_bc = NULL; - CBoundaryConditionNode* m_node = NULL; - int nidx = GetNodeValueIndex(pcs_primary_function_name[0]); - for(long i = 0; i < (long)bc_node_value.size(); i++) - { - m_node = bc_node_value[i]; - //WW m_bc = bc_node[i]; - // old time - SetNodeValue(m_node->msh_node_number,nidx,m_node->node_value); - // new time - SetNodeValue(m_node->msh_node_number,nidx + 1,m_node->node_value); - } +void CRFProcess::SetBC() +{ + // WW CBoundaryCondition *m_bc = NULL; + CBoundaryConditionNode* m_node = NULL; + int nidx = GetNodeValueIndex(pcs_primary_function_name[0]); + for (long i = 0; i < (long)bc_node_value.size(); i++) + { + m_node = bc_node_value[i]; + // WW m_bc = bc_node[i]; + // old time + SetNodeValue(m_node->msh_node_number, nidx, m_node->node_value); + // new time + SetNodeValue(m_node->msh_node_number, nidx + 1, m_node->node_value); } - - +} /************************************************************************** Task: Preprocessing function set flag pcs->flow_pcs_type for @@ -12737,24 +12734,24 @@ CRFProcess* PCSGetMass(size_t component_number) Programing: 01/2008 CB Implementation */ /**************************************************************************/ - void SetFlowProcessType() - { - int i; - int no_processes, flowtype; - CRFProcess* m_pcs = NULL; +void SetFlowProcessType() +{ + int i; + int no_processes, flowtype; + CRFProcess* m_pcs = NULL; - m_pcs = PCSGetFlow(); - flowtype = m_pcs->type; - no_processes = (int)pcs_vector.size(); + m_pcs = PCSGetFlow(); + flowtype = m_pcs->type; + no_processes = (int)pcs_vector.size(); - for(i = 0; i < no_processes; i++) - { - m_pcs = pcs_vector[i]; - //if(m_pcs->_pcs_type_name.compare("MASS_TRANSPORT")==0) - //m_pcs->twophaseflow=true; - m_pcs->flow_pcs_type = flowtype; - } + for (i = 0; i < no_processes; i++) + { + m_pcs = pcs_vector[i]; + // if(m_pcs->_pcs_type_name.compare("MASS_TRANSPORT")==0) + // m_pcs->twophaseflow=true; + m_pcs->flow_pcs_type = flowtype; } +} /************************************************************************** Task: Postprocessing function copies the new time step node values of @@ -12763,100 +12760,93 @@ CRFProcess* PCSGetMass(size_t component_number) Programing: 13/2008 CB Implementation */ /**************************************************************************/ - void CopyTimestepNODValuesSVTPhF() - { - long i, j; - int idx0, idx1; - long nnodes; - double val = 0; - CRFProcess* m_pcs = NULL; +void CopyTimestepNODValuesSVTPhF() +{ + long i, j; + int idx0, idx1; + long nnodes; + double val = 0; + CRFProcess* m_pcs = NULL; - nnodes = (long) fem_msh_vector[0]->nod_vector.size(); + nnodes = (long)fem_msh_vector[0]->nod_vector.size(); - for (j = 0; j < 2; j++) //pcs 1 and 2 + for (j = 0; j < 2; j++) // pcs 1 and 2 + { + m_pcs = pcs_vector[j]; + // if (m_pcs->_pcs_type_name.compare("TWO_PHASE_FLOW") != 0) + if (m_pcs->getProcessType() == FiniteElement::TWO_PHASE_FLOW) + break; + if (j == 0) + // old timelevel + idx0 = m_pcs->GetNodeValueIndex("PRESSURE2"); + else + // old timelevel + idx0 = m_pcs->GetNodeValueIndex("SATURATION1"); + idx1 = idx0 + 1; + for (i = 0; i < nnodes; i++) { - m_pcs = pcs_vector[j]; - // if (m_pcs->_pcs_type_name.compare("TWO_PHASE_FLOW") != 0) - if (m_pcs->getProcessType () == FiniteElement::TWO_PHASE_FLOW) - break; - if (j == 0) - // old timelevel - idx0 = m_pcs->GetNodeValueIndex("PRESSURE2"); - else - // old timelevel - idx0 = m_pcs->GetNodeValueIndex("SATURATION1"); - idx1 = idx0 + 1; - for (i = 0; i < nnodes; i++) - { - val = m_pcs->GetNodeValue(i, idx1); - m_pcs->SetNodeValue(i, idx0, val); - } - //m_pcs->WriteAllVariables(); + val = m_pcs->GetNodeValue(i, idx1); + m_pcs->SetNodeValue(i, idx0, val); } + // m_pcs->WriteAllVariables(); } - +} /************************************************************************** PCSLib-Method: based on WriteSolution by WW 01/2007 OK Implementation **************************************************************************/ - void CRFProcess::WriteAllVariables() +void CRFProcess::WriteAllVariables() +{ + std::string pcs_type_name(convertProcessTypeToString(this->getProcessType())); + string m_file_name = FileName + "_" + pcs_type_name + "_" + pcs_primary_function_name[0] + ".asc"; + ofstream os(m_file_name.c_str(), ios::trunc | ios::out); + if (!os.good()) { - std::string pcs_type_name (convertProcessTypeToString(this->getProcessType())); - string m_file_name = FileName + "_" + pcs_type_name + "_" - + pcs_primary_function_name[0] + ".asc"; - ofstream os(m_file_name.c_str(), ios::trunc | ios::out); - if (!os.good()) - { - cout << "Failure to open file: " << m_file_name << "\n"; - abort(); - } - // - int j; - int idx[20]; - for (j = 0; j < pcs_number_of_primary_nvals; j++) + cout << "Failure to open file: " << m_file_name << "\n"; + abort(); + } + // + int j; + int idx[20]; + for (j = 0; j < pcs_number_of_primary_nvals; j++) + { + os << pcs_primary_function_name[j] << " "; + idx[j] = GetNodeValueIndex(pcs_primary_function_name[j]); + os << pcs_primary_function_name[j] << " "; + idx[j + pcs_number_of_primary_nvals] = idx[j] + 1; + } + if (this->type == 12) // output of old & new time step for secondary variables PRESSURE2 and SATURATION1 + { + os << pcs_secondary_function_name[0] << " "; + idx[2 * pcs_number_of_primary_nvals + 0] = GetNodeValueIndex(pcs_secondary_function_name[0]); + os << pcs_secondary_function_name[0] << " "; + idx[2 * pcs_number_of_primary_nvals + 1] = GetNodeValueIndex(pcs_secondary_function_name[0]) + 1; + // other secondary variables + for (j = 2; j < pcs_number_of_secondary_nvals; j++) { - os << pcs_primary_function_name[j] << " "; - idx[j] = GetNodeValueIndex(pcs_primary_function_name[j]); - os << pcs_primary_function_name[j] << " "; - idx[j + pcs_number_of_primary_nvals] = idx[j] + 1; + os << pcs_secondary_function_name[j] << " "; + idx[2 * pcs_number_of_primary_nvals + j] = GetNodeValueIndex(pcs_secondary_function_name[j]); } - if (this->type == 12) //output of old & new time step for secondary variables PRESSURE2 and SATURATION1 + } + else + for (j = 0; j < pcs_number_of_secondary_nvals; j++) { - os << pcs_secondary_function_name[0] << " "; - idx[2 * pcs_number_of_primary_nvals + 0] = GetNodeValueIndex( - pcs_secondary_function_name[0]); - os << pcs_secondary_function_name[0] << " "; - idx[2 * pcs_number_of_primary_nvals + 1] = GetNodeValueIndex( - pcs_secondary_function_name[0]) + 1; - //other secondary variables - for (j = 2; j < pcs_number_of_secondary_nvals; j++) - { - os << pcs_secondary_function_name[j] << " "; - idx[2 * pcs_number_of_primary_nvals + j] = GetNodeValueIndex( - pcs_secondary_function_name[j]); - } + os << pcs_secondary_function_name[j] << " "; + idx[2 * pcs_number_of_primary_nvals + j] = GetNodeValueIndex(pcs_secondary_function_name[j]); } - else - for (j = 0; j < pcs_number_of_secondary_nvals; j++) - { - os << pcs_secondary_function_name[j] << " "; - idx[2 * pcs_number_of_primary_nvals + j] = GetNodeValueIndex( - pcs_secondary_function_name[j]); - } + os << "\n"; + for (size_t i = 0; i < m_msh->GetNodesNumber(false); i++) + { + for (j = 0; j < 2 * pcs_number_of_primary_nvals; j++) + os << GetNodeValue(i, idx[j]) << " "; + for (j = 0; j < pcs_number_of_secondary_nvals; j++) + os << GetNodeValue(i, idx[2 * pcs_number_of_primary_nvals + j]) << " "; os << "\n"; - for (size_t i = 0; i < m_msh->GetNodesNumber(false); i++) - { - for (j = 0; j < 2 * pcs_number_of_primary_nvals; j++) - os << GetNodeValue(i, idx[j]) << " "; - for (j = 0; j < pcs_number_of_secondary_nvals; j++) - os << GetNodeValue(i, idx[2 * pcs_number_of_primary_nvals + j]) - << " "; - os << "\n"; - } - os.close(); } + os.close(); +} /************************************************************************** PCSLib-Method: @@ -12864,36 +12854,36 @@ CRFProcess* PCSGetMass(size_t component_number) 01/2007 OK Implementation 08/2008 CB NAPLdissolution **************************************************************************/ - void MMPCalcSecondaryVariablesNew(CRFProcess* m_pcs, bool NAPLdiss) - { - long i; +void MMPCalcSecondaryVariablesNew(CRFProcess* m_pcs, bool NAPLdiss) +{ + long i; - //---------------------------------------------------------------------- - int ndx_density_phase; - int ndx_viscosity_phase; - ndx_density_phase = -1; //WW - ndx_viscosity_phase = -1; //WW - CFEMesh* m_msh = m_pcs->m_msh; // PCH - //---------------------------------------------------------------------- - m_pcs->SetBC(); + //---------------------------------------------------------------------- + int ndx_density_phase; + int ndx_viscosity_phase; + ndx_density_phase = -1; // WW + ndx_viscosity_phase = -1; // WW + CFEMesh* m_msh = m_pcs->m_msh; // PCH + //---------------------------------------------------------------------- + m_pcs->SetBC(); - // For accessing the other process - CRFProcess* cpl_pcs = NULL; - if(m_pcs->pcs_type_number == 0) - cpl_pcs = pcs_vector[m_pcs->pcs_number + 1]; - else if(m_pcs->pcs_type_number == 1) - cpl_pcs = pcs_vector[m_pcs->pcs_number - 1]; + // For accessing the other process + CRFProcess* cpl_pcs = NULL; + if (m_pcs->pcs_type_number == 0) + cpl_pcs = pcs_vector[m_pcs->pcs_number + 1]; + else if (m_pcs->pcs_type_number == 1) + cpl_pcs = pcs_vector[m_pcs->pcs_number - 1]; - int ndx_pressure1, ndx_p_cap, ndx_pressure2, ndx_s_wetting, ndx_s_nonwetting; - //====================================================================== - //---------------------------------------------------------------------- - // Capillary pressure - p_c (S) <- This is always the secondary variable - // in both phase1 and phase2 // PCH - CMediumProperties* mmp = NULL; + int ndx_pressure1, ndx_p_cap, ndx_pressure2, ndx_s_wetting, ndx_s_nonwetting; + //====================================================================== + //---------------------------------------------------------------------- + // Capillary pressure - p_c (S) <- This is always the secondary variable + // in both phase1 and phase2 // PCH + CMediumProperties* mmp = NULL; - //====================================================================== - switch(m_pcs->pcs_type_number) - { + //====================================================================== + switch (m_pcs->pcs_type_number) + { case 0: //.................................................................. //.................................................................. @@ -12905,27 +12895,26 @@ CRFProcess* PCSGetMass(size_t component_number) ndx_pressure2 = m_pcs->GetNodeValueIndex("PRESSURE2"); ndx_p_cap = m_pcs->GetNodeValueIndex("PRESSURE_CAP"); double pressure1, pressure2, p_cap; - for(i = 0; i < (long)m_pcs->m_msh->nod_vector.size(); i++) + for (i = 0; i < (long)m_pcs->m_msh->nod_vector.size(); i++) { // New - pressure1 = m_pcs->GetNodeValue(i,ndx_pressure1 + 1); + pressure1 = m_pcs->GetNodeValue(i, ndx_pressure1 + 1); // Old - pressure2 = m_pcs->GetNodeValue(i,ndx_pressure1); + pressure2 = m_pcs->GetNodeValue(i, ndx_pressure1); // Let's get capillary pressure before updating pressure2 // by accessing the primary variable of the saturation equation // not the secondary variable of it. int cpl_ndx_sat2 = cpl_pcs->GetNodeValueIndex("SATURATION2"); - double cpl_sat2 = cpl_pcs->GetNodeValue(i,cpl_ndx_sat2 + 1); + double cpl_sat2 = cpl_pcs->GetNodeValue(i, cpl_ndx_sat2 + 1); - if(mmp_vector.size() > 1) + if (mmp_vector.size() > 1) { double sum = 0.0; CNode* thisNode = m_msh->nod_vector[i]; - int NumOfNeighborElements = - (int)thisNode->getConnectedElementIDs().size(); + int NumOfNeighborElements = (int)thisNode->getConnectedElementIDs().size(); // Harmonic mean - for(int p = 0; p < NumOfNeighborElements; ++p) + for (int p = 0; p < NumOfNeighborElements; ++p) { // Mount neighboring elemenets and get the corresponding material group one by one. int eleIdx = thisNode->getConnectedElementIDs()[p]; @@ -12938,25 +12927,20 @@ CRFProcess* PCSGetMass(size_t component_number) cpl_sat2 = (double)NumOfNeighborElements / sum; } // Assigning the secondary variable, Pc - if(mmp_vector.size() > 1) - p_cap = - m_pcs-> - GetCapillaryPressureOnNodeByNeighobringElementPatches( - i, - 2, - 1.0 - cpl_sat2); + if (mmp_vector.size() > 1) + p_cap = m_pcs->GetCapillaryPressureOnNodeByNeighobringElementPatches(i, 2, 1.0 - cpl_sat2); else p_cap = mmp->CapillaryPressureFunction(1.0 - cpl_sat2); - m_pcs->SetNodeValue(i,ndx_p_cap,p_cap); - m_pcs->SetNodeValue(i,ndx_p_cap + 1,p_cap); + m_pcs->SetNodeValue(i, ndx_p_cap, p_cap); + m_pcs->SetNodeValue(i, ndx_p_cap + 1, p_cap); pressure2 = pressure1 + p_cap; // Assigning the secondary variables // Previous - m_pcs->SetNodeValue(i,ndx_pressure2,pressure2); + m_pcs->SetNodeValue(i, ndx_pressure2, pressure2); // Now - m_pcs->SetNodeValue(i,ndx_pressure2 + 1,pressure2); + m_pcs->SetNodeValue(i, ndx_pressure2 + 1, pressure2); } //...................................................................... ndx_density_phase = m_pcs->GetNodeValueIndex("DENSITY1"); @@ -12975,23 +12959,22 @@ CRFProcess* PCSGetMass(size_t component_number) ndx_s_nonwetting = m_pcs->GetNodeValueIndex("SATURATION2"); ndx_p_cap = cpl_pcs->GetNodeValueIndex("PRESSURE_CAP"); - double s_wetting,s_nonwetting; - for(i = 0; i < (long)m_pcs->m_msh->nod_vector.size(); i++) + double s_wetting, s_nonwetting; + for (i = 0; i < (long)m_pcs->m_msh->nod_vector.size(); i++) { - s_nonwetting = m_pcs->GetNodeValue(i,ndx_s_nonwetting + 1); + s_nonwetting = m_pcs->GetNodeValue(i, ndx_s_nonwetting + 1); // Due to the iterative solution scheme in solving Snw with no // explicit boundary condition for non-zero flux condition, // Snw may become negative particularly the density difference // between two fluids is big. To prevent negative Snw, the // saturation restriction added. - if(mmp_vector.size() > 1) + if (mmp_vector.size() > 1) { double sum = 0.0; CNode* thisNode = m_msh->nod_vector[i]; - int NumOfNeighborElements = - (int)thisNode->getConnectedElementIDs().size(); + int NumOfNeighborElements = (int)thisNode->getConnectedElementIDs().size(); // Harmonic mean - for(int p = 0; p < NumOfNeighborElements; ++p) + for (int p = 0; p < NumOfNeighborElements; ++p) { // Mount neighboring elemenets and get the corresponding material group one by one. int eleIdx = thisNode->getConnectedElementIDs()[p]; @@ -13004,435 +12987,416 @@ CRFProcess* PCSGetMass(size_t component_number) s_nonwetting = (double)NumOfNeighborElements / sum; } // Assigning the secondary variable, Pc - if(mmp_vector.size() > 1) - p_cap = - m_pcs-> - GetCapillaryPressureOnNodeByNeighobringElementPatches( - i, - 2, - 1.0 - s_nonwetting); + if (mmp_vector.size() > 1) + p_cap = m_pcs->GetCapillaryPressureOnNodeByNeighobringElementPatches(i, 2, 1.0 - s_nonwetting); else p_cap = mmp->CapillaryPressureFunction(1.0 - s_nonwetting); - m_pcs->SetNodeValue(i,ndx_s_nonwetting,s_nonwetting); - m_pcs->SetNodeValue(i,ndx_s_nonwetting + 1,s_nonwetting); + m_pcs->SetNodeValue(i, ndx_s_nonwetting, s_nonwetting); + m_pcs->SetNodeValue(i, ndx_s_nonwetting + 1, s_nonwetting); s_wetting = 1.0 - s_nonwetting; // Assigning the secondary variables // Previous - m_pcs->SetNodeValue(i,ndx_s_wetting,s_wetting); + m_pcs->SetNodeValue(i, ndx_s_wetting, s_wetting); // Now - m_pcs->SetNodeValue(i,ndx_s_wetting + 1,s_wetting); + m_pcs->SetNodeValue(i, ndx_s_wetting + 1, s_wetting); - cpl_pcs->SetNodeValue(i,ndx_p_cap,p_cap); - cpl_pcs->SetNodeValue(i,ndx_p_cap + 1,p_cap); + cpl_pcs->SetNodeValue(i, ndx_p_cap, p_cap); + cpl_pcs->SetNodeValue(i, ndx_p_cap + 1, p_cap); } //...................................................................... ndx_density_phase = m_pcs->GetNodeValueIndex("DENSITY2"); ndx_viscosity_phase = m_pcs->GetNodeValueIndex("VISCOSITY2"); printf("Saturation1 from the known Saturation2 is updated for Process 1\n"); break; - } + } - //---------------------------------------------------------------------- - // Fluid properties - double density; - double viscosity; - CFluidProperties* m_mfp = NULL; - m_mfp = mfp_vector[m_pcs->pcs_type_number]; - m_mfp->mode = 1; - for(i = 0; i < (long)m_pcs->m_msh->nod_vector.size(); i++) - { - // CB NAPL dissolution reqiuires update of Density based on new composition of NAPL phase - //CB phase 2 - if(NAPLdiss == true && m_pcs->pcs_type_number == 1) - density = CalcNAPLDens(i); - else - density = m_mfp->Density(); - m_pcs->SetNodeValue(i,ndx_density_phase,density); - viscosity = m_mfp->Viscosity(); - m_pcs->SetNodeValue(i,ndx_viscosity_phase,viscosity); - } - m_mfp->mode = 0; - //---------------------------------------------------------------------- + //---------------------------------------------------------------------- + // Fluid properties + double density; + double viscosity; + CFluidProperties* m_mfp = NULL; + m_mfp = mfp_vector[m_pcs->pcs_type_number]; + m_mfp->mode = 1; + for (i = 0; i < (long)m_pcs->m_msh->nod_vector.size(); i++) + { + // CB NAPL dissolution reqiuires update of Density based on new composition of NAPL phase + // CB phase 2 + if (NAPLdiss == true && m_pcs->pcs_type_number == 1) + density = CalcNAPLDens(i); + else + density = m_mfp->Density(); + m_pcs->SetNodeValue(i, ndx_density_phase, density); + viscosity = m_mfp->Viscosity(); + m_pcs->SetNodeValue(i, ndx_viscosity_phase, viscosity); } + m_mfp->mode = 0; + //---------------------------------------------------------------------- +} /************************************************************************** PCSLib-Method: 07/2007 OK Implementation **************************************************************************/ - bool CRFProcess::OBJRelations() - { - bool succeed = true; - std::cout << "OBJ->PCS relations" << '\n'; - - std::string pcs_type_name (convertProcessTypeToString (this->getProcessType())); +bool CRFProcess::OBJRelations() +{ + bool succeed = true; + std::cout << "OBJ->PCS relations" << '\n'; - // NUM - std::cout << " - NUM->PCS" << '\n'; - m_num = NUMGet(pcs_type_name); - if (!m_num) - { - std::cout << "Warning in CRFProcess::Create() - no NUM data - default" - << "\n"; - succeed = false; - } - else - { - num_type_name = "NEW"; //OK - } + std::string pcs_type_name(convertProcessTypeToString(this->getProcessType())); - // TIM - cout << " - TIM->PCS" << '\n'; - Tim = TIMGet(pcs_type_name); - if (Tim) - { - // Time unit factor //WW OK: -> TIM - if (Tim->time_unit.find("MINUTE") != string::npos) - time_unit_factor = 60.0; - else if (Tim->time_unit.find("HOUR") != string::npos) - time_unit_factor = 3600.0; - else if (Tim->time_unit.find("DAY") != string::npos) - time_unit_factor = 86400.0; - else if (Tim->time_unit.find("MONTH") != string::npos) - time_unit_factor = 2592000.0; - else if (Tim->time_unit.find("YEAR") != string::npos) - time_unit_factor = 31536000; - } - else - cout << "Warning in CRFProcess::Create() - no TIM data - default" - << "\n"; + // NUM + std::cout << " - NUM->PCS" << '\n'; + m_num = NUMGet(pcs_type_name); + if (!m_num) + { + std::cout << "Warning in CRFProcess::Create() - no NUM data - default" + << "\n"; + succeed = false; + } + else + { + num_type_name = "NEW"; // OK + } - // OUT + // TIM + cout << " - TIM->PCS" << '\n'; + Tim = TIMGet(pcs_type_name); + if (Tim) + { + // Time unit factor //WW OK: -> TIM + if (Tim->time_unit.find("MINUTE") != string::npos) + time_unit_factor = 60.0; + else if (Tim->time_unit.find("HOUR") != string::npos) + time_unit_factor = 3600.0; + else if (Tim->time_unit.find("DAY") != string::npos) + time_unit_factor = 86400.0; + else if (Tim->time_unit.find("MONTH") != string::npos) + time_unit_factor = 2592000.0; + else if (Tim->time_unit.find("YEAR") != string::npos) + time_unit_factor = 31536000; + } + else + cout << "Warning in CRFProcess::Create() - no TIM data - default" + << "\n"; - // MSH - if (fem_msh_vector.size() == 1) - m_msh = fem_msh_vector[0]; - else - m_msh = MSHGet(pcs_type_name); - if (!m_msh) - { - cout << "Warning in CRFProcess::Create() - no MSH data" << "\n"; - succeed = false; - } + // OUT - return succeed; + // MSH + if (fem_msh_vector.size() == 1) + m_msh = fem_msh_vector[0]; + else + m_msh = MSHGet(pcs_type_name); + if (!m_msh) + { + cout << "Warning in CRFProcess::Create() - no MSH data" + << "\n"; + succeed = false; } + return succeed; +} + /************************************************************************** PCSLib-Method: 07/2007 OK Implementation **************************************************************************/ - bool CRFProcess::NODRelations() - { - bool succeed = true; - size_t DOF = GetPrimaryVNumber(); //OK should be PCS member variable +bool CRFProcess::NODRelations() +{ + bool succeed = true; + size_t DOF = GetPrimaryVNumber(); // OK should be PCS member variable - cout << "NOD->PCS relations" << '\n'; + cout << "NOD->PCS relations" << '\n'; - // BC - cout << " - BC->PCS" << '\n'; - if (pcs_type_name_vector.size() && pcs_type_name_vector[0].find("DYNAMIC") - != string::npos) //WW + // BC + cout << " - BC->PCS" << '\n'; + if (pcs_type_name_vector.size() && pcs_type_name_vector[0].find("DYNAMIC") != string::npos) // WW - setBC_danymic_problems(); - else + setBC_danymic_problems(); + else + { + // create BC groups for each process + CBoundaryConditionsGroup* m_bc_group = NULL; + std::string pcs_type_name(convertProcessTypeToString(this->getProcessType())); + for (size_t i = 0; i < DOF; i++) { - // create BC groups for each process - CBoundaryConditionsGroup* m_bc_group = NULL; - std::string pcs_type_name (convertProcessTypeToString(this->getProcessType())); - for (size_t i = 0; i < DOF; i++) - { - BCGroupDelete(pcs_type_name, pcs_primary_function_name[i]); - m_bc_group = new CBoundaryConditionsGroup(); - //OK - m_bc_group->setProcessTypeName(pcs_type_name); - m_bc_group->setProcessPrimaryVariableName( - pcs_primary_function_name[i]); //OK - m_bc_group->Set(this, Shift[i]); - } + BCGroupDelete(pcs_type_name, pcs_primary_function_name[i]); + m_bc_group = new CBoundaryConditionsGroup(); + // OK + m_bc_group->setProcessTypeName(pcs_type_name); + m_bc_group->setProcessPrimaryVariableName(pcs_primary_function_name[i]); // OK + m_bc_group->Set(this, Shift[i]); } + } - // ST - if (pcs_type_name_vector.size() && pcs_type_name_vector[0].find("DYNAMIC") - != string::npos) //WW + // ST + if (pcs_type_name_vector.size() && pcs_type_name_vector[0].find("DYNAMIC") != string::npos) // WW - setST_danymic_problems(); + setST_danymic_problems(); - CSourceTermGroup* m_st_group = NULL; - if (WriteSourceNBC_RHS == 2) // Read from file - ReadRHS_of_ST_NeumannBC(); - else // WW - { // Calculate directly - std::string pcs_type_name (convertProcessTypeToString(this->getProcessType())); - for (size_t i = 0; i < DOF; i++) + CSourceTermGroup* m_st_group = NULL; + if (WriteSourceNBC_RHS == 2) // Read from file + ReadRHS_of_ST_NeumannBC(); + else // WW + { // Calculate directly + std::string pcs_type_name(convertProcessTypeToString(this->getProcessType())); + for (size_t i = 0; i < DOF; i++) + { + m_st_group = STGetGroup(pcs_type_name, pcs_primary_function_name[i]); + if (!m_st_group) { - m_st_group = STGetGroup(pcs_type_name, pcs_primary_function_name[i]); - if (!m_st_group) - { - m_st_group = new CSourceTermGroup(); - //OK - m_st_group->pcs_type_name = pcs_type_name; - //OK - m_st_group->pcs_pv_name = pcs_primary_function_name[i]; - m_st_group->Set(this, Shift[i]); - } + m_st_group = new CSourceTermGroup(); + // OK + m_st_group->pcs_type_name = pcs_type_name; + // OK + m_st_group->pcs_pv_name = pcs_primary_function_name[i]; + m_st_group->Set(this, Shift[i]); } - if (WriteSourceNBC_RHS == 1) // WW - WriteRHS_of_ST_NeumannBC(); } + if (WriteSourceNBC_RHS == 1) // WW + WriteRHS_of_ST_NeumannBC(); + } - // NOD values - cout << "->Config NOD values" << '\n'; + // NOD values + cout << "->Config NOD values" << '\n'; - // Names - nod_val_name_vector.clear(); - // - for (int i = 0; i < pcs_number_of_primary_nvals; i++) - { - // new time - nod_val_name_vector.push_back(pcs_primary_function_name[i]); - // old time //need this MB! - nod_val_name_vector.push_back(pcs_primary_function_name[i]); - } - for (int i = 0; i < pcs_number_of_secondary_nvals; i++) - // new time - nod_val_name_vector.push_back(pcs_secondary_function_name[i]); - if ((int) nod_val_name_vector.size() != (2 * pcs_number_of_primary_nvals - + pcs_number_of_secondary_nvals)) - succeed = false; + // Names + nod_val_name_vector.clear(); + // + for (int i = 0; i < pcs_number_of_primary_nvals; i++) + { + // new time + nod_val_name_vector.push_back(pcs_primary_function_name[i]); + // old time //need this MB! + nod_val_name_vector.push_back(pcs_primary_function_name[i]); + } + for (int i = 0; i < pcs_number_of_secondary_nvals; i++) + // new time + nod_val_name_vector.push_back(pcs_secondary_function_name[i]); + if ((int)nod_val_name_vector.size() != (2 * pcs_number_of_primary_nvals + pcs_number_of_secondary_nvals)) + succeed = false; - // Values - double* nod_values = NULL; - const size_t nod_val_vector_size (nod_val_vector.size()); - for (size_t i = 0; i < nod_val_vector_size; i++) - { - delete [] nod_val_vector[i]; - nod_val_vector[i] = NULL; - } - nod_val_vector.clear(); - // - //OK m_msh->NodesNumber_Quadratic; - number_of_nvals = 2 * DOF + pcs_number_of_secondary_nvals; - size_t nn = m_msh->nod_vector.size(); //11.12.2012. WW - for (long j = 0; j < number_of_nvals ; j++) - { - nod_values = new double[nn]; - for (size_t i = 0; i < nn; i++) - nod_values[i] = 0.0; - nod_val_vector.push_back(nod_values); - } - if ((long) nod_val_vector.size() != (long) m_msh->nod_vector.size()) - succeed = false; + // Values + double* nod_values = NULL; + const size_t nod_val_vector_size(nod_val_vector.size()); + for (size_t i = 0; i < nod_val_vector_size; i++) + { + delete[] nod_val_vector[i]; + nod_val_vector[i] = NULL; + } + nod_val_vector.clear(); + // + // OK m_msh->NodesNumber_Quadratic; + number_of_nvals = 2 * DOF + pcs_number_of_secondary_nvals; + size_t nn = m_msh->nod_vector.size(); // 11.12.2012. WW + for (long j = 0; j < number_of_nvals; j++) + { + nod_values = new double[nn]; + for (size_t i = 0; i < nn; i++) + nod_values[i] = 0.0; + nod_val_vector.push_back(nod_values); + } + if ((long)nod_val_vector.size() != (long)m_msh->nod_vector.size()) + succeed = false; - // IC - cout << "->Assign IC" << '\n'; - if (reload == 2 && type != 4 && type != 41) - ReadSolution(); //WW - SetIC(); + // IC + cout << "->Assign IC" << '\n'; + if (reload == 2 && type != 4 && type != 41) + ReadSolution(); // WW + SetIC(); - if (pcs_type_name_vector.size() && pcs_type_name_vector[0].find("DYNAMIC") - != string::npos) //WW - setIC_danymic_problems(); - return succeed; - } + if (pcs_type_name_vector.size() && pcs_type_name_vector[0].find("DYNAMIC") != string::npos) // WW + setIC_danymic_problems(); + return succeed; +} /************************************************************************** PCSLib-Method: 07/2007 OK Implementation **************************************************************************/ - bool CRFProcess::ELERelations() - { - bool succeed = true; - //OK->MB please shift to Config() - // if (_pcs_type_name.compare("GROUNDWATER_FLOW") == 0) - if (this->getProcessType() == FiniteElement::GROUNDWATER_FLOW) - MSHDefineMobile(this); - // - if (type == 4 || type == 41) - m_msh->SwitchOnQuadraticNodes(true); - else - m_msh->SwitchOnQuadraticNodes(false); - CheckMarkedElement(); +bool CRFProcess::ELERelations() +{ + bool succeed = true; + // OK->MB please shift to Config() + // if (_pcs_type_name.compare("GROUNDWATER_FLOW") == 0) + if (this->getProcessType() == FiniteElement::GROUNDWATER_FLOW) + MSHDefineMobile(this); + // + if (type == 4 || type == 41) + m_msh->SwitchOnQuadraticNodes(true); + else + m_msh->SwitchOnQuadraticNodes(false); + CheckMarkedElement(); - // ELE - GP values - AllocateMemGPoint(); + // ELE - GP values + AllocateMemGPoint(); - // ELE values - double* ele_values = NULL; // PCH - int number_of_evals = 2 * pcs_number_of_evals; //PCH, increase memory - if (number_of_evals > 0) // WW added this "if" condition + // ELE values + double* ele_values = NULL; // PCH + int number_of_evals = 2 * pcs_number_of_evals; // PCH, increase memory + if (number_of_evals > 0) // WW added this "if" condition + { + // Names + for (int i = 0; i < pcs_number_of_evals; i++) { - // Names - for (int i = 0; i < pcs_number_of_evals; i++) - { - // new time - ele_val_name_vector.push_back(pcs_eval_name[i]); - // old time - ele_val_name_vector.push_back(pcs_eval_name[i]); - } - if (ele_val_name_vector.size() == 0) - succeed = false; - - // Values - size_t m_msh_ele_vector_size (m_msh->ele_vector.size()); - if (ele_val_vector.size() == 0) - for (size_t j = 0; j < m_msh_ele_vector_size; j++) - { - ele_values = new double[number_of_evals]; - size_eval += number_of_evals; //WW - for (int i = 0; i < number_of_evals; i++) - ele_values[i] = 0.0; - ele_val_vector.push_back(ele_values); - } - else - for (size_t j = 0; j < m_msh_ele_vector_size; j++) - { - ele_values = ele_val_vector[j]; - /* //Comment by WW - #ifndef SX - #ifdef GCC - size = malloc_usable_size( ele_values )/sizeof(double); - #elif HORIZON - //KG44: malloc_usable_size and _msize are not available - #else - size= _msize( ele_values )/sizeof(double); - #endif - #endif - */ - ele_values = resize(ele_values, size_eval, size_eval - + number_of_evals); - size_eval += number_of_evals; - ele_val_vector[j] = ele_values; - } - if (ele_val_vector.size() != m_msh->ele_vector.size()) - succeed = false; + // new time + ele_val_name_vector.push_back(pcs_eval_name[i]); + // old time + ele_val_name_vector.push_back(pcs_eval_name[i]); } + if (ele_val_name_vector.size() == 0) + succeed = false; - // ELE matrices - if (Memory_Type != 0) - { - AllocateLocalMatrixMemory(); - if ((long) Ele_Matrices.size() != (long) m_msh->ele_vector.size()) - succeed = false; - } + // Values + size_t m_msh_ele_vector_size(m_msh->ele_vector.size()); + if (ele_val_vector.size() == 0) + for (size_t j = 0; j < m_msh_ele_vector_size; j++) + { + ele_values = new double[number_of_evals]; + size_eval += number_of_evals; // WW + for (int i = 0; i < number_of_evals; i++) + ele_values[i] = 0.0; + ele_val_vector.push_back(ele_values); + } + else + for (size_t j = 0; j < m_msh_ele_vector_size; j++) + { + ele_values = ele_val_vector[j]; + /* //Comment by WW + #ifndef SX + #ifdef GCC + size = malloc_usable_size( ele_values )/sizeof(double); + #elif HORIZON + //KG44: malloc_usable_size and _msize are not available + #else + size= _msize( ele_values )/sizeof(double); + #endif + #endif + */ + ele_values = resize(ele_values, size_eval, size_eval + number_of_evals); + size_eval += number_of_evals; + ele_val_vector[j] = ele_values; + } + if (ele_val_vector.size() != m_msh->ele_vector.size()) + succeed = false; + } - // Element matrix output. WW - if (Write_Matrix) - { - cout << "->Write Matrix" << '\n'; - string m_file_name = FileName + "_" + convertProcessTypeToString ( - this->getProcessType()) - + "_element_matrix.txt"; - matrix_file = new fstream(m_file_name.c_str(), ios::trunc | ios::out); - if (!matrix_file->good()) - cout << "Warning in GlobalAssembly: Matrix files are not found" - << "\n"; - } + // ELE matrices + if (Memory_Type != 0) + { + AllocateLocalMatrixMemory(); + if ((long)Ele_Matrices.size() != (long)m_msh->ele_vector.size()) + succeed = false; + } - // FEM - if (type == 4 || type == 41) - { - // Set initialization function - CRFProcessDeformation* dm_pcs = (CRFProcessDeformation*) this; - dm_pcs->Initialization(); - if (!dm_pcs->GetFEM_Assembler()) - succeed = false; - } - else // Initialize FEM calculator - { - int Axisymm = 1; // ani-axisymmetry - if (m_msh->isAxisymmetry()) - Axisymm = -1; // Axisymmetry is true - //OK4801 needs NUM - fem = new CFiniteElementStd(this, Axisymm * m_msh->GetCoordinateFlag()); - if (!fem) - succeed = false; - } + // Element matrix output. WW + if (Write_Matrix) + { + cout << "->Write Matrix" << '\n'; + string m_file_name + = FileName + "_" + convertProcessTypeToString(this->getProcessType()) + "_element_matrix.txt"; + matrix_file = new fstream(m_file_name.c_str(), ios::trunc | ios::out); + if (!matrix_file->good()) + cout << "Warning in GlobalAssembly: Matrix files are not found" + << "\n"; + } - return succeed; + // FEM + if (type == 4 || type == 41) + { + // Set initialization function + CRFProcessDeformation* dm_pcs = (CRFProcessDeformation*)this; + dm_pcs->Initialization(); + if (!dm_pcs->GetFEM_Assembler()) + succeed = false; + } + else // Initialize FEM calculator + { + int Axisymm = 1; // ani-axisymmetry + if (m_msh->isAxisymmetry()) + Axisymm = -1; // Axisymmetry is true + // OK4801 needs NUM + fem = new CFiniteElementStd(this, Axisymm * m_msh->GetCoordinateFlag()); + if (!fem) + succeed = false; } + return succeed; +} + /************************************************************************** PCSLib-Method: 07/2007 OK Implementation **************************************************************************/ -#if !defined(NEW_EQS) && !defined(USE_PETSC) //WW. 07.11.2008. 04.2012 - bool CRFProcess::CreateEQS() - { - if(!m_num) - return false; //OK46 - bool succeed = true; - //---------------------------------------------------------------------------- - if(eqs) - return false; - //---------------------------------------------------------------------------- - int DOF = GetPrimaryVNumber(); //OK should be PCS member variable - //---------------------------------------------------------------------------- - // EQS - create equation system - cout << "->Create EQS" << '\n'; - //---------------------------------------------------------------------------- - if(type == 4) - { - eqs = CreateLinearSolverDim(m_num->ls_storage_method, - DOF, - DOF * m_msh->GetNodesNumber(true)); - InitializeLinearSolver(eqs,m_num); - PCS_Solver.push_back(eqs); //WW - } - //---------------------------------------------------------------------------- - else if(type == 41) - { - if(num_type_name.find("EXCAVATION") != string::npos) - eqs = CreateLinearSolverDim(m_num->ls_storage_method, - DOF - 1, - DOF * m_msh->GetNodesNumber(true)); - else - eqs = CreateLinearSolverDim(m_num->ls_storage_method,DOF, - (DOF - 1) * m_msh->GetNodesNumber( - true) + - m_msh->GetNodesNumber(false)); - InitializeLinearSolver(eqs,m_num); - PCS_Solver.push_back(eqs); //WW - } - //---------------------------------------------------------------------------- +#if !defined(NEW_EQS) && !defined(USE_PETSC) // WW. 07.11.2008. 04.2012 +bool CRFProcess::CreateEQS() +{ + if (!m_num) + return false; // OK46 + bool succeed = true; + //---------------------------------------------------------------------------- + if (eqs) + return false; + //---------------------------------------------------------------------------- + int DOF = GetPrimaryVNumber(); // OK should be PCS member variable + //---------------------------------------------------------------------------- + // EQS - create equation system + cout << "->Create EQS" << '\n'; + //---------------------------------------------------------------------------- + if (type == 4) + { + eqs = CreateLinearSolverDim(m_num->ls_storage_method, DOF, DOF * m_msh->GetNodesNumber(true)); + InitializeLinearSolver(eqs, m_num); + PCS_Solver.push_back(eqs); // WW + } + //---------------------------------------------------------------------------- + else if (type == 41) + { + if (num_type_name.find("EXCAVATION") != string::npos) + eqs = CreateLinearSolverDim(m_num->ls_storage_method, DOF - 1, DOF * m_msh->GetNodesNumber(true)); else - { - /* - // If there is a solver exsiting. WW - CRFProcess* m_pcs = NULL; - for(int i=0; i<(int)pcs_vector.size(); i++) - { - m_pcs = pcs_vector[i]; - if(m_pcs&&m_pcs->eqs) - { - if(m_pcs->_pcs_type_name.find("DEFORMATION")==string::npos) - break; - } - } - // If unique mesh - if(m_pcs&&m_pcs->eqs&&(fem_msh_vector.size()==1)) - eqs = m_pcs->eqs; - // - else - { - */ - eqs = - CreateLinearSolver(m_num->ls_storage_method, - m_msh->GetNodesNumber(false)); - InitializeLinearSolver(eqs,m_num); - PCS_Solver.push_back(eqs); - //} - } - //---------------------------------------------------------------------------- - std::string pcs_type_name (convertProcessTypeToString (this->getProcessType())); - strcpy(eqs->pcs_type_name,pcs_type_name.data()); - //---------------------------------------------------------------------------- - if((int)PCS_Solver.size() == 0) - succeed = false; - //---------------------------------------------------------------------------- - return succeed; + eqs = CreateLinearSolverDim(m_num->ls_storage_method, DOF, + (DOF - 1) * m_msh->GetNodesNumber(true) + m_msh->GetNodesNumber(false)); + InitializeLinearSolver(eqs, m_num); + PCS_Solver.push_back(eqs); // WW + } + //---------------------------------------------------------------------------- + else + { + /* + // If there is a solver exsiting. WW + CRFProcess* m_pcs = NULL; + for(int i=0; i<(int)pcs_vector.size(); i++) + { + m_pcs = pcs_vector[i]; + if(m_pcs&&m_pcs->eqs) + { + if(m_pcs->_pcs_type_name.find("DEFORMATION")==string::npos) + break; + } + } + // If unique mesh + if(m_pcs&&m_pcs->eqs&&(fem_msh_vector.size()==1)) + eqs = m_pcs->eqs; + // + else + { + */ + eqs = CreateLinearSolver(m_num->ls_storage_method, m_msh->GetNodesNumber(false)); + InitializeLinearSolver(eqs, m_num); + PCS_Solver.push_back(eqs); + //} } + //---------------------------------------------------------------------------- + std::string pcs_type_name(convertProcessTypeToString(this->getProcessType())); + strcpy(eqs->pcs_type_name, pcs_type_name.data()); + //---------------------------------------------------------------------------- + if ((int)PCS_Solver.size() == 0) + succeed = false; + //---------------------------------------------------------------------------- + return succeed; +} #endif /************************************************************************** PCSLib-Method: @@ -13440,231 +13404,228 @@ CRFProcess* PCSGetMass(size_t component_number) **************************************************************************/ #if !defined(USE_PETSC) && !defined(NEW_EQS) // && defined(other parallel libs)//03~04.3012. WW //#ifndef NEW_EQS //WW. 07.11.2008 - void PCSCreateNew() +void PCSCreateNew() +{ + int i; + CRFProcess* m_pcs = NULL; + //---------------------------------------------------------------------- + for (i = 0; i < (int)pcs_vector.size(); i++) { - int i; - CRFProcess* m_pcs = NULL; + m_pcs = pcs_vector[i]; + m_pcs->CreateNew(); //---------------------------------------------------------------------- - for(i = 0; i < (int)pcs_vector.size(); i++) - { - m_pcs = pcs_vector[i]; - m_pcs->CreateNew(); - //---------------------------------------------------------------------- - } } +} /************************************************************************** PCSLib-Method: 07/2007 OK Implementation **************************************************************************/ - void CRFProcess::CreateNew() - { - pcs_type_number = (int)pcs_vector.size(); - Config(); - m_bCheckOBJ = OBJRelations(); - m_bCheckEQS = CreateEQS(); - m_bCheckNOD = NODRelations(); - m_bCheckELE = ELERelations(); - MMP2PCSRelation(this); - ConfigureCouplingForLocalAssemblier(); - } +void CRFProcess::CreateNew() +{ + pcs_type_number = (int)pcs_vector.size(); + Config(); + m_bCheckOBJ = OBJRelations(); + m_bCheckEQS = CreateEQS(); + m_bCheckNOD = NODRelations(); + m_bCheckELE = ELERelations(); + MMP2PCSRelation(this); + ConfigureCouplingForLocalAssemblier(); +} #endif /************************************************************************** PCSLib-Method: 07/2007 OK Implementation **************************************************************************/ - bool CRFProcess::Check() - { - // MMP - MSHTestMATGroups(); - return true; - } +bool CRFProcess::Check() +{ + // MMP + MSHTestMATGroups(); + return true; +} /************************************************************************** PCSLib-Method: 07/2007 OK Implementation **************************************************************************/ - bool PCSCheck() +bool PCSCheck() +{ + if ((int)pcs_vector.size() == 0) + return false; + CRFProcess* m_pcs = NULL; + for (int i = 0; i < (int)pcs_vector.size(); i++) { - if((int)pcs_vector.size() == 0) + m_pcs = pcs_vector[i]; + // if(m_pcs->m_bCheck) + if (!m_pcs->Check()) return false; - CRFProcess* m_pcs = NULL; - for(int i = 0; i < (int)pcs_vector.size(); i++) - { - m_pcs = pcs_vector[i]; - //if(m_pcs->m_bCheck) - if(!m_pcs->Check()) - return false; #ifdef MFC - FMRead(); //WW + FMRead(); // WW #endif - } - - return true; } + return true; +} + /************************************************************************** PCSLib-Method: 07/2007 OK Implementation **************************************************************************/ -#if !defined(NEW_EQS) && !defined(USE_PETSC) //WW. 07.11.2008. 04.2012 - void EQSDelete() - { - LINEAR_SOLVER* eqs = NULL; - //---------------------------------------------------------------------- - for(size_t i = 0; i < PCS_Solver.size(); i++) - { - eqs = PCS_Solver[i]; - if(eqs->unknown_vector_indeces) - eqs->unknown_vector_indeces = \ - (int*) Free(eqs->unknown_vector_indeces); - if(eqs->unknown_node_numbers) - eqs->unknown_node_numbers = \ - (long*) Free(eqs->unknown_node_numbers); - if(eqs->unknown_update_methods) - eqs->unknown_update_methods = \ - (int*) Free(eqs->unknown_update_methods); - eqs = DestroyLinearSolver(eqs); - PCS_Solver.erase((PCS_Solver.begin() + i)); - } - //PCS_Solver.clear(); +#if !defined(NEW_EQS) && !defined(USE_PETSC) // WW. 07.11.2008. 04.2012 +void EQSDelete() +{ + LINEAR_SOLVER* eqs = NULL; + //---------------------------------------------------------------------- + for (size_t i = 0; i < PCS_Solver.size(); i++) + { + eqs = PCS_Solver[i]; + if (eqs->unknown_vector_indeces) + eqs->unknown_vector_indeces = (int*)Free(eqs->unknown_vector_indeces); + if (eqs->unknown_node_numbers) + eqs->unknown_node_numbers = (long*)Free(eqs->unknown_node_numbers); + if (eqs->unknown_update_methods) + eqs->unknown_update_methods = (int*)Free(eqs->unknown_update_methods); + eqs = DestroyLinearSolver(eqs); + PCS_Solver.erase((PCS_Solver.begin() + i)); } + // PCS_Solver.clear(); +} #endif /************************************************************************** PCSLib-Method: 07/2007 OK Implementation **************************************************************************/ - void CRFProcess::NODRelationsDelete() +void CRFProcess::NODRelationsDelete() +{ + std::string pcs_type_name(convertProcessTypeToString(getProcessType())); + // BC + for (size_t i = 0; i < GetPrimaryVNumber(); i++) + BCGroupDelete(pcs_type_name, pcs_primary_function_name[i]); + const size_t bc_node_value_size(bc_node_value.size()); + for (size_t i = 0; i < bc_node_value_size; i++) { - std::string pcs_type_name (convertProcessTypeToString (getProcessType())); - // BC - for (size_t i = 0; i < GetPrimaryVNumber(); i++) - BCGroupDelete(pcs_type_name, pcs_primary_function_name[i]); - const size_t bc_node_value_size(bc_node_value.size()); - for (size_t i = 0; i < bc_node_value_size; i++) - { - delete bc_node_value[i]; - bc_node_value[i] = NULL; - } - bc_node_value.clear(); + delete bc_node_value[i]; + bc_node_value[i] = NULL; + } + bc_node_value.clear(); - // ST - for (size_t i = 0; i < GetPrimaryVNumber(); i++) - STGroupDelete(pcs_type_name, pcs_primary_function_name[i]); + // ST + for (size_t i = 0; i < GetPrimaryVNumber(); i++) + STGroupDelete(pcs_type_name, pcs_primary_function_name[i]); - CNodeValue* nod_val = NULL; - const size_t st_node_value_size (st_node_value.size()); - for (size_t i = 0; i < st_node_value_size; i++) + CNodeValue* nod_val = NULL; + const size_t st_node_value_size(st_node_value.size()); + for (size_t i = 0; i < st_node_value_size; i++) + { + nod_val = st_node_value[i]; + // OK delete st_node_value[i]; + // OK st_node_value[i] = NULL; + if (nod_val->check_me) // OK { - nod_val = st_node_value[i]; - //OK delete st_node_value[i]; - //OK st_node_value[i] = NULL; - if (nod_val->check_me) //OK - { - nod_val->check_me = false; - delete nod_val; - nod_val = NULL; - } + nod_val->check_me = false; + delete nod_val; + nod_val = NULL; } - st_node_value.clear(); + } + st_node_value.clear(); - // NOD values - nod_val_name_vector.clear(); - const size_t nod_val_vector_size(nod_val_vector.size()); - for (size_t i = 0; i < nod_val_vector_size; i++) - { - delete nod_val_vector[i]; - nod_val_vector[i] = NULL; - } - nod_val_vector.clear(); + // NOD values + nod_val_name_vector.clear(); + const size_t nod_val_vector_size(nod_val_vector.size()); + for (size_t i = 0; i < nod_val_vector_size; i++) + { + delete nod_val_vector[i]; + nod_val_vector[i] = NULL; } + nod_val_vector.clear(); +} /************************************************************************** PCSLib-Method: 07/2007 OK Implementation **************************************************************************/ - void CRFProcess::ELERelationsDelete() +void CRFProcess::ELERelationsDelete() +{ + long i; + //---------------------------------------------------------------------- + // FEM element + if (fem) + delete fem; // WW + fem = NULL; + //---------------------------------------------------------------------- + // ELE matrices + ElementMatrix* eleMatrix = NULL; + ElementValue* gp_ele = NULL; + if (Ele_Matrices.size() > 0) { - long i; - //---------------------------------------------------------------------- - // FEM element - if(fem) - delete fem; //WW - fem = NULL; - //---------------------------------------------------------------------- - // ELE matrices - ElementMatrix* eleMatrix = NULL; - ElementValue* gp_ele = NULL; - if(Ele_Matrices.size() > 0) - { - for (i = 0; i < (long)Ele_Matrices.size(); i++) - { - eleMatrix = Ele_Matrices[i]; - delete eleMatrix; - eleMatrix = NULL; - } - Ele_Matrices.clear(); - } - //---------------------------------------------------------------------- - // ELE - GP values - if(ele_gp_value.size() > 0) + for (i = 0; i < (long)Ele_Matrices.size(); i++) { - for(i = 0; i < (long)ele_gp_value.size(); i++) - { - gp_ele = ele_gp_value[i]; - delete gp_ele; - gp_ele = NULL; - } - ele_gp_value.clear(); + eleMatrix = Ele_Matrices[i]; + delete eleMatrix; + eleMatrix = NULL; } - //---------------------------------------------------------------------- - // ELE values - ele_val_name_vector.clear(); - for(i = 0; i < (long)ele_val_vector.size(); i++) + Ele_Matrices.clear(); + } + //---------------------------------------------------------------------- + // ELE - GP values + if (ele_gp_value.size() > 0) + { + for (i = 0; i < (long)ele_gp_value.size(); i++) { - delete ele_val_vector[i]; - //delete[] ele_val_vector[i]; - ele_val_vector[i] = NULL; + gp_ele = ele_gp_value[i]; + delete gp_ele; + gp_ele = NULL; } - ele_val_vector.clear(); - //---------------------------------------------------------------------- + ele_gp_value.clear(); + } + //---------------------------------------------------------------------- + // ELE values + ele_val_name_vector.clear(); + for (i = 0; i < (long)ele_val_vector.size(); i++) + { + delete ele_val_vector[i]; + // delete[] ele_val_vector[i]; + ele_val_vector[i] = NULL; } + ele_val_vector.clear(); + //---------------------------------------------------------------------- +} /************************************************************************** PCSLib-Method: 07/2007 OK Implementation **************************************************************************/ - void CRFProcess::OBJRelationsDelete() - { - //---------------------------------------------------------------------------- - cout << "OBJ->PCS relations delete" << '\n'; - //---------------------------------------------------------------------------- - m_num = NULL; - Tim = NULL; - m_msh = NULL; - //---------------------------------------------------------------------------- - } +void CRFProcess::OBJRelationsDelete() +{ + //---------------------------------------------------------------------------- + cout << "OBJ->PCS relations delete" << '\n'; + //---------------------------------------------------------------------------- + m_num = NULL; + Tim = NULL; + m_msh = NULL; + //---------------------------------------------------------------------------- +} /************************************************************************** PCSLib-Method: 07/2007 OK Implementation **************************************************************************/ - void CRFProcess::Delete() - { - //---------------------------------------------------------------------------- - cout << "PCS delete" << '\n'; - //---------------------------------------------------------------------------- - ELERelationsDelete(); - NODRelationsDelete(); +void CRFProcess::Delete() +{ + //---------------------------------------------------------------------------- + cout << "PCS delete" << '\n'; + //---------------------------------------------------------------------------- + ELERelationsDelete(); + NODRelationsDelete(); #if !defined(USE_PETSC) && !defined(NEW_EQS) // && defined(other parallel libs)//03~04.3012. WW - //#ifndef NEW_EQS //WW. 07.11.2008 - EQSDelete(); + //#ifndef NEW_EQS //WW. 07.11.2008 + EQSDelete(); #endif - OBJRelationsDelete(); - //MMP2PCSRelation(this); - //ConfigureCouplingForLocalAssemblier(); - //---------------------------------------------------------------------------- - } + OBJRelationsDelete(); + // MMP2PCSRelation(this); + // ConfigureCouplingForLocalAssemblier(); + //---------------------------------------------------------------------------- +} /************************************************************************** PCSLib-Method: @@ -13672,36 +13633,33 @@ CRFProcess* PCSGetMass(size_t component_number) **************************************************************************/ #if !defined(USE_PETSC) && !defined(NEW_EQS) // && defined(other parallel libs)//03~04.3012. WW //#ifndef NEW_EQS //WW 07.11.2008 - void CRFProcess::EQSDelete() - { - std::string pcs_type_name (convertProcessTypeToString (this->getProcessType())); - LINEAR_SOLVER* eqs = NULL; - for (size_t i = 0; i < PCS_Solver.size(); i++) - { - eqs = PCS_Solver[i]; - if (pcs_type_name.compare(eqs->pcs_type_name) == 0) - { - if (eqs->unknown_vector_indeces) - eqs->unknown_vector_indeces = (int*) Free( - eqs->unknown_vector_indeces); - if (eqs->unknown_node_numbers) - eqs->unknown_node_numbers = (long*) Free( - eqs->unknown_node_numbers); - if (eqs->unknown_update_methods) - eqs->unknown_update_methods = (int*) Free( - eqs->unknown_update_methods); - eqs = DestroyLinearSolver(eqs); - eqs = NULL; - } +void CRFProcess::EQSDelete() +{ + std::string pcs_type_name(convertProcessTypeToString(this->getProcessType())); + LINEAR_SOLVER* eqs = NULL; + for (size_t i = 0; i < PCS_Solver.size(); i++) + { + eqs = PCS_Solver[i]; + if (pcs_type_name.compare(eqs->pcs_type_name) == 0) + { + if (eqs->unknown_vector_indeces) + eqs->unknown_vector_indeces = (int*)Free(eqs->unknown_vector_indeces); + if (eqs->unknown_node_numbers) + eqs->unknown_node_numbers = (long*)Free(eqs->unknown_node_numbers); + if (eqs->unknown_update_methods) + eqs->unknown_update_methods = (int*)Free(eqs->unknown_update_methods); + eqs = DestroyLinearSolver(eqs); + eqs = NULL; } + } - for (size_t i = 0; i < PCS_Solver.size(); i++) - { - eqs = PCS_Solver[i]; - if (pcs_type_name.compare(eqs->pcs_type_name) == 0) - PCS_Solver.erase((PCS_Solver.begin() + i)); - } + for (size_t i = 0; i < PCS_Solver.size(); i++) + { + eqs = PCS_Solver[i]; + if (pcs_type_name.compare(eqs->pcs_type_name) == 0) + PCS_Solver.erase((PCS_Solver.begin() + i)); } +} #endif /************************************************************************* @@ -13710,142 +13668,142 @@ CRFProcess* PCSGetMass(size_t component_number) Programming: 09/2007 WW Implementation **************************************************************************/ -#if defined(USE_PETSC) //WW. 07.11.2008. 04.2012 +#if defined(USE_PETSC) // WW. 07.11.2008. 04.2012 // New solvers WW -#elif defined(NEW_EQS) //1.09.2007 WW +#elif defined(NEW_EQS) // 1.09.2007 WW - void CreateEQS_LinearSolver() - { - size_t i; - // CB_merge_0513 - //int dof_DM = 1; - int dof_DM = 0; //WW 02.2023. Pardiso - CRFProcess* m_pcs = NULL; - CFEMesh* a_msh = NULL; +void CreateEQS_LinearSolver() +{ + size_t i; + // CB_merge_0513 + // int dof_DM = 1; + int dof_DM = 0; // WW 02.2023. Pardiso + CRFProcess* m_pcs = NULL; + CFEMesh* a_msh = NULL; #ifndef USE_MPI - bool need_eqs = false; //WW 02.2013. Pardiso - bool need_eqs_dof = false; //WW 02.2013. Pardiso + bool need_eqs = false; // WW 02.2013. Pardiso + bool need_eqs_dof = false; // WW 02.2013. Pardiso #endif - int dof = 1; - // - //size_t dof_nonDM (1); //WW 02.2013. Pardiso - size_t dof_nonDM (0); + int dof = 1; + // + // size_t dof_nonDM (1); //WW 02.2013. Pardiso + size_t dof_nonDM(0); - int dof_max = 0; - size_t dof_nonDM_max = 0; - for(i = 0; i < pcs_vector.size(); i++) + int dof_max = 0; + size_t dof_nonDM_max = 0; + for (i = 0; i < pcs_vector.size(); i++) + { + m_pcs = pcs_vector[i]; + if (m_pcs->type == 1212) // Important for parallel computing. 24.1.2011 WW { - m_pcs = pcs_vector[i]; - if(m_pcs->type == 1212) //Important for parallel computing. 24.1.2011 WW + dof_nonDM = m_pcs->GetPrimaryVNumber(); + dof = dof_nonDM; + } + if (m_pcs->type == 4 || m_pcs->type / 10 == 4) // Deformation + { + dof_DM = m_pcs->GetPrimaryVNumber(); + dof = dof_DM; + if (m_pcs->type == 42) + dof = m_pcs->m_msh->GetMaxElementDim(); + } + else // Monolithic scheme for the process with linear elements + { + // CB_merge_0513 + // if(dof_nonDM < m_pcs->GetPrimaryVNumber()) //WW 02.2023. Pardiso + //{ + // dof_nonDM = m_pcs->GetPrimaryVNumber(); + // // PCH: DOF Handling for FLUID_MOMENTUM in case that the LIS and PARDISO solvers + // // are chosen. + // // if(m_pcs->_pcs_type_name.compare("FLUID_MOMENTUM")==0) + // if(m_pcs->getProcessType() == FLUID_MOMENTUM) + // dof_nonDM = 1; + //} //WW 02.2023. Pardiso + + // 02.2013. WW //WW 02.2023. Pardiso + // Assume that the system with linear element only have one equation with DOF >1; + if (m_pcs->GetPrimaryVNumber() > 1) { dof_nonDM = m_pcs->GetPrimaryVNumber(); dof = dof_nonDM; - } - if(m_pcs->type == 4 || m_pcs->type / 10 == 4) // Deformation - { - dof_DM = m_pcs->GetPrimaryVNumber(); - dof = dof_DM; - if(m_pcs->type == 42) - dof = m_pcs->m_msh->GetMaxElementDim(); - } - else // Monolithic scheme for the process with linear elements - { - // CB_merge_0513 - //if(dof_nonDM < m_pcs->GetPrimaryVNumber()) //WW 02.2023. Pardiso - //{ - // dof_nonDM = m_pcs->GetPrimaryVNumber(); - // // PCH: DOF Handling for FLUID_MOMENTUM in case that the LIS and PARDISO solvers - // // are chosen. - // // if(m_pcs->_pcs_type_name.compare("FLUID_MOMENTUM")==0) - // if(m_pcs->getProcessType() == FLUID_MOMENTUM) - // dof_nonDM = 1; - //} //WW 02.2023. Pardiso - - // 02.2013. WW //WW 02.2023. Pardiso - // Assume that the system with linear element only have one equation with DOF >1; - if( m_pcs->GetPrimaryVNumber() > 1) - { - dof_nonDM = m_pcs->GetPrimaryVNumber(); - dof = dof_nonDM; #ifndef USE_MPI - need_eqs_dof = true; + need_eqs_dof = true; #endif - } - else - { - dof = 1; + } + else + { + dof = 1; #ifndef USE_MPI - need_eqs = true; + need_eqs = true; #endif - } //WW 02.2023. Pardiso - } - dof_max = std::max(dof_max, dof); - dof_nonDM_max = std::max(dof_nonDM_max, dof_nonDM); + } // WW 02.2023. Pardiso } - //Check whether the JFNK method is employed for deformation problem 04.08.2010 WW - CNumerics* num = NULL; - for(i = 0; i < num_vector.size(); i++) + dof_max = std::max(dof_max, dof); + dof_nonDM_max = std::max(dof_nonDM_max, dof_nonDM); + } + // Check whether the JFNK method is employed for deformation problem 04.08.2010 WW + CNumerics* num = NULL; + for (i = 0; i < num_vector.size(); i++) + { + num = num_vector[i]; + if (num->nls_method == 2) { - num = num_vector[i]; - if(num->nls_method == 2) - { - // Stiffness matrix of lower order grid may be used by more than one processes. - // Therefore, memo allocation is performed for it. - // Indicator: Not allocate memo for stiffness matrix for deformation - dof_DM *= -1; - break; - } + // Stiffness matrix of lower order grid may be used by more than one processes. + // Therefore, memo allocation is performed for it. + // Indicator: Not allocate memo for stiffness matrix for deformation + dof_DM *= -1; + break; } + } #ifndef USE_MPI - SparseTable* sp = NULL; - SparseTable* spH = NULL; - Linear_EQS* eqs_dof = NULL; //WW 02.2023. Pardiso - Linear_EQS* eqsH = NULL; + SparseTable* sp = NULL; + SparseTable* spH = NULL; + Linear_EQS* eqs_dof = NULL; // WW 02.2023. Pardiso + Linear_EQS* eqsH = NULL; #endif - // - Linear_EQS* eqs = NULL; - for(i = 0; i < fem_msh_vector.size(); i++) - { - a_msh = fem_msh_vector[i]; + // + Linear_EQS* eqs = NULL; + for (i = 0; i < fem_msh_vector.size(); i++) + { + a_msh = fem_msh_vector[i]; #if defined(USE_MPI) - eqs = new Linear_EQS(a_msh->GetNodesNumber(true) * dof_max); - EQS_Vector.push_back(eqs); - EQS_Vector.push_back(eqs); + eqs = new Linear_EQS(a_msh->GetNodesNumber(true) * dof_max); + EQS_Vector.push_back(eqs); + EQS_Vector.push_back(eqs); #else - a_msh->CreateSparseTable(); - // sparse pattern with linear elements exists - sp = a_msh->GetSparseTable(); - // sparse pattern with quadratic elements exists - spH = a_msh->GetSparseTable(true); - // - eqs = NULL; - eqsH = NULL; - // CB_merge_0513 - eqs_dof = NULL; //WW 02.2023. Pardiso - if(sp)//WW 02.2023. Pardiso + a_msh->CreateSparseTable(); + // sparse pattern with linear elements exists + sp = a_msh->GetSparseTable(); + // sparse pattern with quadratic elements exists + spH = a_msh->GetSparseTable(true); + // + eqs = NULL; + eqsH = NULL; + // CB_merge_0513 + eqs_dof = NULL; // WW 02.2023. Pardiso + if (sp) // WW 02.2023. Pardiso + { + if (need_eqs) // 02.2013. WW { - if(need_eqs) // 02.2013. WW - { - //eqs = new Linear_EQS(*sp, dof_nonDM);//WW 02.2023. Pardiso - eqs = new Linear_EQS(*sp, 1); - } - if(need_eqs_dof) - { - eqs_dof = new Linear_EQS(*sp, dof_nonDM_max); - } - }//WW 02.2023. Pardiso - if(spH) - eqsH = new Linear_EQS(*spH, dof_DM); - EQS_Vector.push_back(eqs); - EQS_Vector.push_back(eqsH); - EQS_Vector.push_back(eqs_dof); //WW 02.2023. Pardiso + // eqs = new Linear_EQS(*sp, dof_nonDM);//WW 02.2023. Pardiso + eqs = new Linear_EQS(*sp, 1); + } + if (need_eqs_dof) + { + eqs_dof = new Linear_EQS(*sp, dof_nonDM_max); + } + } // WW 02.2023. Pardiso + if (spH) + eqsH = new Linear_EQS(*spH, dof_DM); + EQS_Vector.push_back(eqs); + EQS_Vector.push_back(eqsH); + EQS_Vector.push_back(eqs_dof); // WW 02.2023. Pardiso #endif - } } +} -#else // NEW_EQS +#else // NEW_EQS /************************************************************************* ROCKFLOW - Function: CRFProcess:: Task: @@ -13853,33 +13811,33 @@ CRFProcess* PCSGetMass(size_t component_number) 09/2007 WW Implementation **************************************************************************/ #include - void CRFProcess::DumpEqs(string file_name) +void CRFProcess::DumpEqs(string file_name) +{ + fstream eqs_out; + eqs_out.open(file_name.c_str(), ios::out); + eqs_out.setf(ios::scientific, ios::floatfield); + setw(14); + eqs_out.precision(14); + // + long nnode = eqs->dim / eqs->unknown_vector_dimension; + for (long i = 0; i < eqs->dim; i++) { - fstream eqs_out; - eqs_out.open(file_name.c_str(), ios::out ); - eqs_out.setf(ios::scientific, ios::floatfield); - setw(14); - eqs_out.precision(14); - // - long nnode = eqs->dim / eqs->unknown_vector_dimension; - for(long i = 0; i < eqs->dim; i++) - { - CNode const* const node (m_msh->nod_vector[i % nnode]); - std::vector const& connected_nodes (node->getConnectedNodes()); - const size_t n_connected_nodes (connected_nodes.size()); - for(int ii = 0; ii < eqs->unknown_vector_dimension; ii++) - for(size_t j = 0; j < n_connected_nodes; j++) - { - const long k = ii * nnode + connected_nodes[j]; - if(k >= eqs->dim) - continue; - eqs_out << i << " " << k << " " << MXGet(i,k) << "\n"; - } - eqs_out << i << " " << eqs->b[i] << " " << eqs->x[i] << "\n"; - } - eqs_out.close(); + CNode const* const node(m_msh->nod_vector[i % nnode]); + std::vector const& connected_nodes(node->getConnectedNodes()); + const size_t n_connected_nodes(connected_nodes.size()); + for (int ii = 0; ii < eqs->unknown_vector_dimension; ii++) + for (size_t j = 0; j < n_connected_nodes; j++) + { + const long k = ii * nnode + connected_nodes[j]; + if (k >= eqs->dim) + continue; + eqs_out << i << " " << k << " " << MXGet(i, k) << "\n"; + } + eqs_out << i << " " << eqs->b[i] << " " << eqs->x[i] << "\n"; } -#endif //ifdef NEW_QES + eqs_out.close(); +} +#endif // ifdef NEW_QES /************************************************************************* ROCKFLOW - Function: CRFProcess:: @@ -13887,87 +13845,86 @@ CRFProcess* PCSGetMass(size_t component_number) Programming: 01/2008 WW Implementation **************************************************************************/ - void CRFProcess::WriteBC() - { - const size_t size_bc (bc_node_value.size()); - const size_t size_st (st_node_value.size()); +void CRFProcess::WriteBC() +{ + const size_t size_bc(bc_node_value.size()); + const size_t size_st(st_node_value.size()); - if (size_bc == 0 && size_st == 0) - return; + if (size_bc == 0 && size_st == 0) + return; #ifdef USE_PETSC - std::string m_file_name = FileName + "_" + convertProcessTypeToString( - this->getProcessType()) + "_BC_ST_" + number2str(myrank) + ".asc"; + std::string m_file_name + = FileName + "_" + convertProcessTypeToString(this->getProcessType()) + "_BC_ST_" + number2str(myrank) + ".asc"; #else - std::string m_file_name = FileName + "_" + convertProcessTypeToString( - this->getProcessType()) + "_BC_ST.asc"; + std::string m_file_name = FileName + "_" + convertProcessTypeToString(this->getProcessType()) + "_BC_ST.asc"; #endif - std::ofstream os(m_file_name.c_str(), ios::trunc | ios::out); - if (!os.good()) - { - cout << "Failure to open file: " << m_file_name << "\n"; - abort(); - } - os.setf(ios::scientific, ios::floatfield); - os.precision(12); - long nindex = 0; - if (size_bc > 0) + std::ofstream os(m_file_name.c_str(), ios::trunc | ios::out); + if (!os.good()) + { + cout << "Failure to open file: " << m_file_name << "\n"; + abort(); + } + os.setf(ios::scientific, ios::floatfield); + os.precision(12); + long nindex = 0; + if (size_bc > 0) + { + os << "#Dirchilet BC (from " << m_file_name << ".bc file) " + << "\n"; + os << "#Total BC nodes " << size_bc << "\n"; + os << "#Node index, name, x, y, z, value: " + << "\n"; + for (size_t i = 0; i < size_bc; i++) { - os << "#Dirchilet BC (from " << m_file_name << ".bc file) " << "\n"; - os << "#Total BC nodes " << size_bc << "\n"; - os << "#Node index, name, x, y, z, value: " << "\n"; - for (size_t i = 0; i < size_bc; i++) - { - nindex = bc_node_value[i]->geo_node_number; + nindex = bc_node_value[i]->geo_node_number; #ifdef USE_PETSC - std::size_t id_in_eqs = m_msh->nod_vector[nindex]->GetEquationIndex(); + std::size_t id_in_eqs = m_msh->nod_vector[nindex]->GetEquationIndex(); #else - std::size_t id_in_eqs = nindex; + std::size_t id_in_eqs = nindex; #endif -// anode = m_msh->nod_vector[nindex]; -// os << nindex << " " << bc_node_value[i]->pcs_pv_name << " " -// << std::setw(14) << anode->X() << " " << std::setw(14) << anode->Y() -// << " " << std::setw(14) << anode->Z() << " " << std::setw(14) -// << bc_node_value[i]->node_value << "\n"; - double const* const pnt (m_msh->nod_vector[nindex]->getData()); - os << id_in_eqs << " " << bc_node_value[i]->pcs_pv_name << " " - << std::setw(14) << pnt[0] << " " << std::setw(14) << pnt[1] - << " " << std::setw(14) << pnt[2] << " " << std::setw(14) - << bc_node_value[i]->node_value << "\n"; - } + // anode = m_msh->nod_vector[nindex]; + // os << nindex << " " << bc_node_value[i]->pcs_pv_name << " " + // << std::setw(14) << anode->X() << " " << std::setw(14) << anode->Y() + // << " " << std::setw(14) << anode->Z() << " " << std::setw(14) + // << bc_node_value[i]->node_value << "\n"; + double const* const pnt(m_msh->nod_vector[nindex]->getData()); + os << id_in_eqs << " " << bc_node_value[i]->pcs_pv_name << " " << std::setw(14) << pnt[0] << " " + << std::setw(14) << pnt[1] << " " << std::setw(14) << pnt[2] << " " << std::setw(14) + << bc_node_value[i]->node_value << "\n"; } - if (size_st > 0) + } + if (size_st > 0) + { + os << "#Source term or Neumann BC (from " << m_file_name << ".st file) " + << "\n"; + os << "#Total ST nodes " << size_st << "\n"; + os << "#Node index, x, y, z, name value: " + << "\n"; + for (size_t i = 0; i < size_st; i++) { - os << "#Source term or Neumann BC (from " << m_file_name - << ".st file) " << "\n"; - os << "#Total ST nodes " << size_st << "\n"; - os << "#Node index, x, y, z, name value: " << "\n"; - for (size_t i = 0; i < size_st; i++) - { - nindex = st_node_value[i]->geo_node_number; + nindex = st_node_value[i]->geo_node_number; #ifdef USE_PETSC - std::size_t id_in_eqs = m_msh->nod_vector[nindex]->GetEquationIndex(); + std::size_t id_in_eqs = m_msh->nod_vector[nindex]->GetEquationIndex(); #else - std::size_t id_in_eqs = nindex; -#endif -// anode = m_msh->nod_vector[nindex]; -// os << nindex << " " << convertPrimaryVariableToString( -// st_node[i]->getProcessPrimaryVariable()) << " " << std::setw(14) -// << anode->X() << " " << std::setw(14) << anode->Y() << " " -// << std::setw(14) << anode->Z() << " " << std::setw(14) -// << st_node_value[i]->node_value << "\n"; - double const* const pnt (m_msh->nod_vector[nindex]->getData()); - os << id_in_eqs << " " << convertPrimaryVariableToString( - st_node[i]->getProcessPrimaryVariable()) << " " << - std::setw(14) - << pnt[0] << " " << std::setw(14) << pnt[1] << " " - << std::setw(14) << pnt[2] << " " << std::setw(14) - << st_node_value[i]->node_value << "\n"; - } - } - os << "#STOP" << "\n"; - os.close(); - } + std::size_t id_in_eqs = nindex; +#endif + // anode = m_msh->nod_vector[nindex]; + // os << nindex << " " << convertPrimaryVariableToString( + // st_node[i]->getProcessPrimaryVariable()) << " " << std::setw(14) + // << anode->X() << " " << std::setw(14) << anode->Y() << " " + // << std::setw(14) << anode->Z() << " " << std::setw(14) + // << st_node_value[i]->node_value << "\n"; + double const* const pnt(m_msh->nod_vector[nindex]->getData()); + os << id_in_eqs << " " << convertPrimaryVariableToString(st_node[i]->getProcessPrimaryVariable()) << " " + << std::setw(14) << pnt[0] << " " << std::setw(14) << pnt[1] << " " << std::setw(14) << pnt[2] << " " + << std::setw(14) << st_node_value[i]->node_value << "\n"; + } + } + os << "#STOP" + << "\n"; + os.close(); +} /************************************************************************* GeoSys-Function: @@ -13977,287 +13934,286 @@ CRFProcess* PCSGetMass(size_t component_number) 10/2008 WW Node value criteria (test) 03/2009 WW Euclidean norm **************************************************************************/ - void CRFProcess::PI_TimeStepSize() +void CRFProcess::PI_TimeStepSize() +{ + //---------------------------------------------------------------------- + //---------------------------------------------------------------------- + // Time step control + double hmin; + double hmax; + double factor1; // 1/hmin + double factor2; // 1/hmax + double sfactor = 0.9; + // WW double reject_factor; // BG + + double* u_n = _problem->GetBufferArray(); + + double* eqs_x = NULL; + if (m_num->nls_method == 1) // Newton-Raphson { - //---------------------------------------------------------------------- - //---------------------------------------------------------------------- - // Time step control - double hmin; - double hmax; - double factor1; // 1/hmin - double factor2; // 1/hmax - double sfactor = 0.9; - //WW double reject_factor; // BG - - double* u_n = _problem->GetBufferArray(); - - double *eqs_x = NULL; - if (m_num->nls_method == 1) // Newton-Raphson - { #if defined(USE_PETSC) // || defined(other parallel libs)//03.3012. WW - eqs_x = eqs_new->GetGlobalSolution(); + eqs_x = eqs_new->GetGlobalSolution(); #else #ifdef NEW_EQS - eqs_x = eqs_new->x; + eqs_x = eqs_new->x; #else - eqs_x = eqs->x; + eqs_x = eqs->x; #endif #endif - } + } - // - // - hmax = Tim->GetMaximumTSizeRestric(); - hmin = Tim->GetMinimumTSizeRestric(); - // - if (hmin < DBL_MIN) - factor1 = 5.0; - else - factor1 = 1.0 / hmin; - if (hmax < DBL_MIN) - factor2 = 0.166666666666666666667e+00; - else - factor2 = 1.0 / hmax; - if (factor1 < 1.0e0) - factor1 = 5.0; - if (factor2 > 1.0e0) - factor2 = 0.166666666666666666667e+00; - // - hmax = Tim->max_time_step; - if(hmax < DBL_MIN) - hmax = fabs(Tim->time_end - aktuelle_zeit); - // - //esitmate the error - double hnew; - double err, fac; - double factorGus; - double hacc = Tim->GetHacc(); - double erracc = Tim->GetErracc(); - // + // + // + hmax = Tim->GetMaximumTSizeRestric(); + hmin = Tim->GetMinimumTSizeRestric(); + // + if (hmin < DBL_MIN) + factor1 = 5.0; + else + factor1 = 1.0 / hmin; + if (hmax < DBL_MIN) + factor2 = 0.166666666666666666667e+00; + else + factor2 = 1.0 / hmax; + if (factor1 < 1.0e0) + factor1 = 5.0; + if (factor2 > 1.0e0) + factor2 = 0.166666666666666666667e+00; + // + hmax = Tim->max_time_step; + if (hmax < DBL_MIN) + hmax = fabs(Tim->time_end - aktuelle_zeit); + // + // esitmate the error + double hnew; + double err, fac; + double factorGus; + double hacc = Tim->GetHacc(); + double erracc = Tim->GetErracc(); +// #define aE_NORM #ifdef E_NORM - // - long i; - CElem* elem = NULL; - bool Check2D3D; - double norm_e, norm_en; - double norm_e_rank, norm_en_rank; - norm_e = norm_en = norm_e_rank = norm_en_rank = 0.; - - Check2D3D = false; - if(type == 66) //Overland flow - Check2D3D = true; - //---------------------------------------------------------------------- - // DDC - if(dom_vector.size() > 0) - { - cout << " Domain Decomposition" << '\n'; - CPARDomain* m_dom = NULL; - int j = 0; - // + // + long i; + CElem* elem = NULL; + bool Check2D3D; + double norm_e, norm_en; + double norm_e_rank, norm_en_rank; + norm_e = norm_en = norm_e_rank = norm_en_rank = 0.; + + Check2D3D = false; + if (type == 66) // Overland flow + Check2D3D = true; + //---------------------------------------------------------------------- + // DDC + if (dom_vector.size() > 0) + { + cout << " Domain Decomposition" << '\n'; + CPARDomain* m_dom = NULL; + int j = 0; +// #if defined(USE_MPI) - j = myrank; + j = myrank; #else - for(j = 0; j < (int)dom_vector.size(); j++) + for (j = 0; j < (int)dom_vector.size(); j++) { #endif - m_dom = dom_vector[j]; - for(int ii = 0; ii < (int)continuum_vector.size(); ii++) + m_dom = dom_vector[j]; + for (int ii = 0; ii < (int)continuum_vector.size(); ii++) + { + continuum = ii; + // + for (i = 0; i < (long)m_dom->elements.size(); i++) { - continuum = ii; - // - for(i = 0; i < (long)m_dom->elements.size(); i++) + elem = m_msh->ele_vector[m_dom->elements[i]]; + if (elem->GetMark()) { - elem = m_msh->ele_vector[m_dom->elements[i]]; - if(elem->GetMark()) - { - elem->SetOrder(false); - fem->SetElementNodesDomain( - m_dom->element_nodes_dom[i]); - fem->ConfigElement(elem,Check2D3D); - fem->m_dom = m_dom; - fem->CalcEnergyNorm(norm_e_rank, norm_en_rank); - // _new - if(ii == 1) - fem->CalcEnergyNorm_Dual(norm_e_rank, norm_en_rank); - } + elem->SetOrder(false); + fem->SetElementNodesDomain(m_dom->element_nodes_dom[i]); + fem->ConfigElement(elem, Check2D3D); + fem->m_dom = m_dom; + fem->CalcEnergyNorm(norm_e_rank, norm_en_rank); + // _new + if (ii == 1) + fem->CalcEnergyNorm_Dual(norm_e_rank, norm_en_rank); } } -#if defined(USE_MPI) - MPI_Allreduce(&norm_e_rank, &norm_e, 1, MPI_DOUBLE,MPI_SUM,comm_DDC); - MPI_Allreduce(&norm_en_rank, &norm_en, 1, MPI_DOUBLE,MPI_SUM,comm_DDC); -#else //USE_MPI - norm_e += norm_e_rank; - norm_en += norm_en_rank; } - //.................................................................... +#if defined(USE_MPI) + MPI_Allreduce(&norm_e_rank, &norm_e, 1, MPI_DOUBLE, MPI_SUM, comm_DDC); + MPI_Allreduce(&norm_en_rank, &norm_en, 1, MPI_DOUBLE, MPI_SUM, comm_DDC); +#else // USE_MPI + norm_e += norm_e_rank; + norm_en += norm_en_rank; + } +//.................................................................... #endif - } - //---------------------------------------------------------------------- - // STD - else - for(int ii = 0; ii < (int)continuum_vector.size(); ii++) + } + //---------------------------------------------------------------------- + // STD + else + for (int ii = 0; ii < (int)continuum_vector.size(); ii++) + { + continuum = ii; + for (i = 0; i < (long)m_msh->ele_vector.size(); i++) { - continuum = ii; - for(i = 0; i < (long)m_msh->ele_vector.size(); i++) + elem = m_msh->ele_vector[i]; + if (elem->GetMark()) // Marked for use { - elem = m_msh->ele_vector[i]; - if (elem->GetMark()) // Marked for use - { - elem->SetOrder(false); - fem->ConfigElement(elem,Check2D3D); - fem->CalcEnergyNorm(u_n, norm_e, norm_en); - // _new - if(ii == 1) - fem->CalcEnergyNorm_Dual(u_n, - norm_e, - norm_en); - } + elem->SetOrder(false); + fem->ConfigElement(elem, Check2D3D); + fem->CalcEnergyNorm(u_n, norm_e, norm_en); + // _new + if (ii == 1) + fem->CalcEnergyNorm_Dual(u_n, norm_e, norm_en); } } - //compute energy norm as the error - err = sqrt(fabs(norm_e / norm_en)); + } + // compute energy norm as the error + err = sqrt(fabs(norm_e / norm_en)); #else // ifdef E_NORM - err = 0.0; - // - int ii, nidx1; - long g_nnodes, j, k, l, size_x; - double x0, x1; - double Rtol = Tim->GetRTol(); - double Atol = Tim->GetATol(); - double *u_k = _problem->GetBufferArray(true); + err = 0.0; + // + int ii, nidx1; + long g_nnodes, j, k, l, size_x; + double x0, x1; + double Rtol = Tim->GetRTol(); + double Atol = Tim->GetATol(); + double* u_k = _problem->GetBufferArray(true); - size_x = 0; - for(ii = 0; ii < pcs_number_of_primary_nvals; ii++) - { - nidx1 = GetNodeValueIndex(pcs_primary_function_name[ii]) + 1; + size_x = 0; + for (ii = 0; ii < pcs_number_of_primary_nvals; ii++) + { + nidx1 = GetNodeValueIndex(pcs_primary_function_name[ii]) + 1; #if defined(USE_PETSC) // || defined(other parallel libs)//03.3012. WW - g_nnodes = m_msh->getNumNodesLocal(); + g_nnodes = m_msh->getNumNodesLocal(); #else - g_nnodes = m_msh->GetNodesNumber(false); + g_nnodes = m_msh->GetNodesNumber(false); #endif - size_x += g_nnodes; + size_x += g_nnodes; - if (m_num->nls_method == 1) // Newton-Raphson + if (m_num->nls_method == 1) // Newton-Raphson + { + for (j = 0; j < g_nnodes; j++) { - for(j = 0; j < g_nnodes; j++) - { #if defined(USE_PETSC) // || defined(other parallel libs)//03.3012. WW - k = j; - l = pcs_number_of_primary_nvals * j + ii; + k = j; + l = pcs_number_of_primary_nvals * j + ii; #else - k = m_msh->Eqs2Global_NodeIndex[j]; - l = j + ii * g_nnodes; -#endif - x0 = u_n[l]; - x1 = GetNodeValue(k,nidx1); - err += pow( (eqs_x[l]) / (Atol + Rtol * max(fabs(x0),fabs( x1))), 2); - } - } - else + k = m_msh->Eqs2Global_NodeIndex[j]; + l = j + ii * g_nnodes; +#endif + x0 = u_n[l]; + x1 = GetNodeValue(k, nidx1); + err += pow((eqs_x[l]) / (Atol + Rtol * max(fabs(x0), fabs(x1))), 2); + } + } + else + { + for (j = 0; j < g_nnodes; j++) { - for(j = 0; j < g_nnodes; j++) - { #if defined(USE_PETSC) // || defined(other parallel libs)//03.3012. WW - k = j; - l = pcs_number_of_primary_nvals * j + ii; + k = j; + l = pcs_number_of_primary_nvals * j + ii; #else - k = m_msh->Eqs2Global_NodeIndex[j]; - l = j + ii * g_nnodes; + k = m_msh->Eqs2Global_NodeIndex[j]; + l = j + ii * g_nnodes; #endif - x0 = u_n[l]; - x1 = GetNodeValue(k,nidx1); - err += pow( (x1 - u_k[l]) / (Atol + Rtol * max(fabs(x0),fabs( x1))), 2); - } + x0 = u_n[l]; + x1 = GetNodeValue(k, nidx1); + err += pow((x1 - u_k[l]) / (Atol + Rtol * max(fabs(x0), fabs(x1))), 2); } } + } #if defined(USE_PETSC) // || defined(other parallel libs)//04.3012. WW - double err_l = err; - MPI_Allreduce(&err_l, &err, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); - long size_xloc = size_x; - MPI_Allreduce(&size_xloc, &size_x, 1, MPI_LONG, MPI_SUM, MPI_COMM_WORLD); + double err_l = err; + MPI_Allreduce(&err_l, &err, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + long size_xloc = size_x; + MPI_Allreduce(&size_xloc, &size_x, 1, MPI_LONG, MPI_SUM, MPI_COMM_WORLD); #endif - err = sqrt(err / (double)size_x); + err = sqrt(err / (double)size_x); #endif - //---------------------------------------------------------------------- + //---------------------------------------------------------------------- + // + // Set the reject factor for the first timestep BG + // if (Tim->step_current == 1) + // Tim->reject_factor = 1; + + // compute hnew with the resriction: 0.2<=hnew/h<=6.0; + fac = max(factor2, min(factor1, pow(err, 0.25) / sfactor)); + hnew = Tim->time_step_length + / fac; //*Tim->reject_factor; // BG, use the reject factor to lower timestep after rejection BG + + // determine if the error is small enough + if (err <= 1.0e0 && accepted) // step is accept (unless Newton diverged!) + { + accept_steps++; + if (Tim->GetPITimeStepCrtlType() == 2) // Mod. predictive step size controller (Gustafsson) + { + if (accept_steps > 1) + { + factorGus = (hacc / Tim->time_step_length) * pow(err * err / erracc, 0.25) / sfactor; + factorGus = max(factor2, min(factor1, factorGus)); + fac = max(fac, factorGus); + hnew = Tim->time_step_length / fac; + } + hacc = Tim->time_step_length; + erracc = max(1.0e-2, err); + Tim->SetHacc(hacc); + Tim->setErracc(erracc); + } + if (fabs(hnew) > hmax) + hnew = hmax; + if (!accepted) + hnew = min(fabs(hnew), Tim->time_step_length); + Tim->SetTimeStep(fabs(hnew)); + // store the used time steps for post-processing BG + if (Tim->step_current == 1) // BG + Tim->time_step_vector.push_back(Tim->time_step_length); + Tim->time_step_vector.push_back(hnew); + // WW reject_factor = 1; + // end of time storage BG + } // end if(err<=1.0e0) + else + { + if (!accepted && err <= 1.0e0) + { // JT: Then error suggests success, but the iteration diverged. + if (hnew / Tim->time_step_length > 0.99) // Shock the system to escape the stagnation. + hnew = Tim->time_step_length * 0.8; + } // - //Set the reject factor for the first timestep BG - //if (Tim->step_current == 1) - // Tim->reject_factor = 1; - - //compute hnew with the resriction: 0.2<=hnew/h<=6.0; - fac = max(factor2,min(factor1,pow(err,0.25) / sfactor)); - hnew = Tim->time_step_length / fac; //*Tim->reject_factor; // BG, use the reject factor to lower timestep after rejection BG - - //determine if the error is small enough - if(err <= 1.0e0 && accepted) //step is accept (unless Newton diverged!) - { - accept_steps++; - if(Tim->GetPITimeStepCrtlType() == 2) //Mod. predictive step size controller (Gustafsson) - { - if(accept_steps > 1) - { - factorGus = - (hacc / - Tim->time_step_length) * pow(err * err / erracc,0.25) / sfactor; - factorGus = max(factor2, min(factor1,factorGus)); - fac = max(fac, factorGus); - hnew = Tim->time_step_length / fac; - } - hacc = Tim->time_step_length; - erracc = max(1.0e-2,err); - Tim->SetHacc(hacc); - Tim->setErracc(erracc); - } - if(fabs(hnew) > hmax) - hnew = hmax; - if(!accepted) - hnew = min(fabs(hnew), Tim->time_step_length); - Tim->SetTimeStep(fabs(hnew)); - //store the used time steps for post-processing BG - if (Tim->step_current == 1) // BG - Tim->time_step_vector.push_back(Tim->time_step_length); - Tim->time_step_vector.push_back(hnew); - //WW reject_factor = 1; - // end of time storage BG - } //end if(err<=1.0e0) - else + // WW Tim->reject_factor = 1; //BG; if the time step is rejected the next timestep increase + // is reduced by the reject factor (choose reject factor between 0.1 and 0.9); 1.0 means no change + reject_steps++; + accepted = false; + // WW hnew = hnew / Tim->reject_factor; //BG + Tim->SetTimeStep(hnew); + Tim->time_step_vector.push_back(hnew); // BG + if (reject_steps > 100 && accept_steps == 0) { - if(!accepted && err <= 1.0e0){ //JT: Then error suggests success, but the iteration diverged. - if(hnew/Tim->time_step_length > 0.99) // Shock the system to escape the stagnation. - hnew = Tim->time_step_length * 0.8; - } - // - //WW Tim->reject_factor = 1; //BG; if the time step is rejected the next timestep increase is reduced by the reject factor (choose reject factor between 0.1 and 0.9); 1.0 means no change - reject_steps++; - accepted = false; - //WW hnew = hnew / Tim->reject_factor; //BG - Tim->SetTimeStep(hnew); - Tim->time_step_vector.push_back(hnew); //BG - if(reject_steps > 100 && accept_steps == 0) - { - cout << - "!!! More than 100 steps rejected and none of steps accepted. Quit the simulation now" - << "\n"; - exit(1); - } - // Recover solutions + cout << "!!! More than 100 steps rejected and none of steps accepted. Quit the simulation now" + << "\n"; + exit(1); } + // Recover solutions } +} -#ifdef NEW_EQS //WW +#ifdef NEW_EQS // WW /************************************************************************* ROCKFLOW - Function: CRFProcess:: Task: //For fluid momentum, WW Programming: 01/2008 WW Implementation **************************************************************************/ - void CRFProcess::EQSInitialize() - {eqs_new->Initialize(); } +void CRFProcess::EQSInitialize() +{ + eqs_new->Initialize(); +} -#if defined(LIS) //11.03.2008 WW +#if defined(LIS) // 11.03.2008 WW /************************************************************************* ROCKFLOW - Function: CRFProcess:: Task: //For fluid momentum, @@ -14265,53 +14221,53 @@ CRFProcess* PCSGetMass(size_t component_number) 02/2008 PCH Implementation 03/2009 PCH option to tell if this is FLUID_MOMENTUM **************************************************************************/ - void CRFProcess::EQSSolver(double* x) - { - eqs_new->Solver(this->m_num); //NW +void CRFProcess::EQSSolver(double* x) +{ + eqs_new->Solver(this->m_num); // NW - //OK411 - for(int i = 0; i < (int)m_msh->nod_vector.size(); ++i) - x[i] = eqs_new->X(i); - } + // OK411 + for (int i = 0; i < (int)m_msh->nod_vector.size(); ++i) + x[i] = eqs_new->X(i); +} #endif #endif #ifdef GEM_REACT - void CRFProcess::IncorporateSourceTerms_GEMS(void) - { - // Initialization - long it; // iterator - long N_Nodes; // Number of Nodes - int nDC; // Number of mass transport components. - int i = 0; // index of the component - - // Get a vector pointing to the REACT_GEM class - if (m_vec_GEM) - { - // Get needed informations.---------------------------- - // Number of Nodes - N_Nodes = (long) m_msh->GetNodesNumber(false); - // Number of DC - nDC = m_vec_GEM->nDC; - // Identify which PCS it is and its sequence in mcp. - i = this->pcs_component_number; - // ---------------------------------------------------- - - // Loop over all the nodes----------------------------- - for ( it = 0; it < N_Nodes /*Number of Nodes*/; it++ ) - { - // Adding the rate of concentration change to the right hand side of the equation. -#ifdef NEW_EQS //15.12.2008. WW - eqs_new->b[it] -= m_vec_GEM->m_xDC_Chem_delta[it * nDC + i] / Tim->time_step_length; +void CRFProcess::IncorporateSourceTerms_GEMS(void) +{ + // Initialization + long it; // iterator + long N_Nodes; // Number of Nodes + int nDC; // Number of mass transport components. + int i = 0; // index of the component + + // Get a vector pointing to the REACT_GEM class + if (m_vec_GEM) + { + // Get needed informations.---------------------------- + // Number of Nodes + N_Nodes = (long)m_msh->GetNodesNumber(false); + // Number of DC + nDC = m_vec_GEM->nDC; + // Identify which PCS it is and its sequence in mcp. + i = this->pcs_component_number; + // ---------------------------------------------------- + + // Loop over all the nodes----------------------------- + for (it = 0; it < N_Nodes /*Number of Nodes*/; it++) + { +// Adding the rate of concentration change to the right hand side of the equation. +#ifdef NEW_EQS // 15.12.2008. WW + eqs_new->b[it] -= m_vec_GEM->m_xDC_Chem_delta[it * nDC + i] / Tim->time_step_length; #elif defined(USE_PETSC) - // eqs_new->b[it] -= m_vec_GEM->m_xDC_Chem_delta[it * nDC + i] / Tim->time_step_length; +// eqs_new->b[it] -= m_vec_GEM->m_xDC_Chem_delta[it * nDC + i] / Tim->time_step_length; #else - eqs->b[it] -= m_vec_GEM->m_xDC_Chem_delta[it * nDC + i] / Tim->time_step_length; + eqs->b[it] -= m_vec_GEM->m_xDC_Chem_delta[it * nDC + i] / Tim->time_step_length; #endif - } - // ---------------------------------------------------- } + // ---------------------------------------------------- } +} #endif /************************************************************************* ROCKFLOW - Function: CRFProcess:: @@ -14322,370 +14278,329 @@ CRFProcess* PCSGetMass(size_t component_number) 03/2010 WW Read binary file of precipitation 06/2010 WW Output top surface flux and head to a raster file **************************************************************************/ - void CRFProcess::UpdateTransientBC() - { - //--------------- 24.03.2010. WW - long i; - CSourceTerm* precip; - CSourceTerm* a_st; - precip = NULL; +void CRFProcess::UpdateTransientBC() +{ + //--------------- 24.03.2010. WW + long i; + CSourceTerm* precip; + CSourceTerm* a_st; + precip = NULL; - for(i = 0; i < (long)st_vector.size(); i++) + for (i = 0; i < (long)st_vector.size(); i++) + { + a_st = st_vector[i]; + if (a_st->getProcessDistributionType() == FiniteElement::PRECIPITATION + && a_st->getProcessType() == getProcessType()) { - a_st = st_vector[i]; - if( a_st->getProcessDistributionType() == FiniteElement::PRECIPITATION - && a_st->getProcessType() == getProcessType() ) + precip = a_st; + if (!m_msh->top_surface_checked) // 07.06--19.08.2010. WW { - precip = a_st; - if(!m_msh->top_surface_checked) // 07.06--19.08.2010. WW - { - if(m_msh->GetCoordinateFlag() / 10 == 3) - m_msh->MarkInterface_mHM_Hydro_3D(); - m_msh->top_surface_checked = true; - } - break; + if (m_msh->GetCoordinateFlag() / 10 == 3) + m_msh->MarkInterface_mHM_Hydro_3D(); + m_msh->top_surface_checked = true; } + break; } - if(precip) // 08-07.06.2010. WW - { - string ofile_name; - ofile_name = precip->DirectAssign_Precipitation(aktuelle_zeit); - - if( m_msh->GetCoordinateFlag() / 10 == 3 ) //19.08.2010. WW - { - /// Remove .bin from the file name - i = (int)ofile_name.find_last_of("."); - if(i > 0) - ofile_name.erase(ofile_name.begin() + i,ofile_name.end()); - i = (int)ofile_name.find_last_of("."); - if(i > 0) - ofile_name.erase(ofile_name.begin() + i,ofile_name.end()); - string of_name = ofile_name + ".flx.asc"; - ofstream of_flux(of_name.c_str(), ios::trunc | ios::out); - - of_name = ofile_name + ".pri.asc"; - ofstream of_primary(of_name.c_str(), ios::trunc | ios::out); - - /// GIS_shape_head[0]: ncols - /// GIS_shape_head[1]: nrows - /// GIS_shape_head[2]: xllcorner - /// GIS_shape_head[3]: yllcorner - /// GIS_shape_head[4]: cellsize - /// GIS_shape_head[5]: NONDATA_value - double* g_para = precip->GIS_shape_head; - long size = (long)(g_para[0] * g_para[1]); - vector cell_data_p(size); - vector cell_data_v(size); - for(i = 0; i < size; i++) - { - cell_data_p[i] = g_para[5]; - cell_data_v[i] = g_para[5]; - } + } + if (precip) // 08-07.06.2010. WW + { + string ofile_name; + ofile_name = precip->DirectAssign_Precipitation(aktuelle_zeit); - int j, k, nnodes; - int node_xmin, node_xmax, node_ymin, node_ymax; - long m, n, mm, nn, l; - CElem* elem; - double* cent; - double vel_av[3], x1[3], x2[3], x3[3], sub_area[3], area, tol_a; + if (m_msh->GetCoordinateFlag() / 10 == 3) // 19.08.2010. WW + { + /// Remove .bin from the file name + i = (int)ofile_name.find_last_of("."); + if (i > 0) + ofile_name.erase(ofile_name.begin() + i, ofile_name.end()); + i = (int)ofile_name.find_last_of("."); + if (i > 0) + ofile_name.erase(ofile_name.begin() + i, ofile_name.end()); + string of_name = ofile_name + ".flx.asc"; + ofstream of_flux(of_name.c_str(), ios::trunc | ios::out); - double x_min, y_min, x_max, y_max; - long row_min, col_min, row_max, col_max; + of_name = ofile_name + ".pri.asc"; + ofstream of_primary(of_name.c_str(), ios::trunc | ios::out); - int* vel_idx; - int idx = fem->idx0 + 1; - vel_idx = fem->idx_vel; + /// GIS_shape_head[0]: ncols + /// GIS_shape_head[1]: nrows + /// GIS_shape_head[2]: xllcorner + /// GIS_shape_head[3]: yllcorner + /// GIS_shape_head[4]: cellsize + /// GIS_shape_head[5]: NONDATA_value + double* g_para = precip->GIS_shape_head; + long size = (long)(g_para[0] * g_para[1]); + vector cell_data_p(size); + vector cell_data_v(size); + for (i = 0; i < size; i++) + { + cell_data_p[i] = g_para[5]; + cell_data_v[i] = g_para[5]; + } - long n_idx, irow, icol, nrow, ncol; - nrow = (long)g_para[1]; - ncol = (long)g_para[0]; + int j, k, nnodes; + int node_xmin, node_xmax, node_ymin, node_ymax; + long m, n, mm, nn, l; + CElem* elem; + double* cent; + double vel_av[3], x1[3], x2[3], x3[3], sub_area[3], area, tol_a; - node_xmin = node_xmax = node_ymin = node_ymax = 0; + double x_min, y_min, x_max, y_max; + long row_min, col_min, row_max, col_max; - tol_a = 1.e-8; + int* vel_idx; + int idx = fem->idx0 + 1; + vel_idx = fem->idx_vel; - of_flux.setf(ios::fixed, ios::floatfield); - of_primary.setf(ios::fixed, ios::floatfield); - of_flux.precision(1); - of_primary.precision(1); + long n_idx, irow, icol, nrow, ncol; + nrow = (long)g_para[1]; + ncol = (long)g_para[0]; - of_flux << "ncols" << setw(19) << ncol << "\n"; - of_flux << "nrows" << setw(19) << nrow << "\n"; - of_flux << "xllcorner" << setw(15) << g_para[2] << "\n"; - of_flux << "yllcorner" << setw(15) << g_para[3] << "\n"; - of_flux << "cellsize" << setw(16) << (long)g_para[4] << "\n"; - of_flux << "NODATA_value" << setw(11) << (long)g_para[5] << "\n"; + node_xmin = node_xmax = node_ymin = node_ymax = 0; - of_primary << "ncols" << setw(19) << ncol << "\n"; - of_primary << "nrows" << setw(19) << nrow << "\n"; - of_primary << "xllcorner" << setw(15) << g_para[2] << "\n"; - of_primary << "yllcorner" << setw(15) << g_para[3] << "\n"; - of_primary << "cellsize" << setw(16) << (long)g_para[4] << "\n"; - of_primary << "NODATA_value" << setw(11) << (long)g_para[5] << "\n"; + tol_a = 1.e-8; - for(i = 0; i < (long)m_msh->face_vector.size(); i++) - { - elem = m_msh->face_vector[i]; - if(!elem->GetMark()) - continue; + of_flux.setf(ios::fixed, ios::floatfield); + of_primary.setf(ios::fixed, ios::floatfield); + of_flux.precision(1); + of_primary.precision(1); - if(elem->GetElementType() != 4) /// If not triangle - continue; + of_flux << "ncols" << setw(19) << ncol << "\n"; + of_flux << "nrows" << setw(19) << nrow << "\n"; + of_flux << "xllcorner" << setw(15) << g_para[2] << "\n"; + of_flux << "yllcorner" << setw(15) << g_para[3] << "\n"; + of_flux << "cellsize" << setw(16) << (long)g_para[4] << "\n"; + of_flux << "NODATA_value" << setw(11) << (long)g_para[5] << "\n"; + + of_primary << "ncols" << setw(19) << ncol << "\n"; + of_primary << "nrows" << setw(19) << nrow << "\n"; + of_primary << "xllcorner" << setw(15) << g_para[2] << "\n"; + of_primary << "yllcorner" << setw(15) << g_para[3] << "\n"; + of_primary << "cellsize" << setw(16) << (long)g_para[4] << "\n"; + of_primary << "NODATA_value" << setw(11) << (long)g_para[5] << "\n"; + + for (i = 0; i < (long)m_msh->face_vector.size(); i++) + { + elem = m_msh->face_vector[i]; + if (!elem->GetMark()) + continue; + + if (elem->GetElementType() != 4) /// If not triangle + continue; + + //// In element + nnodes = elem->GetNodesNumber(false); + cent = elem->gravity_center; - //// In element - nnodes = elem->GetNodesNumber(false); - cent = elem->gravity_center; + /// Find the range of this element + x_min = y_min = 1.e+20; + x_max = y_max = -1.e+20; + for (k = 0; k < nnodes; k++) + { + double const* const pnt(elem->nodes[k]->getData()); + if (pnt[0] < x_min) + { + x_min = pnt[0]; + node_xmin = k; + } + if (pnt[0] > x_max) + { + x_max = pnt[0]; + node_xmax = k; + } + if (pnt[1] < y_min) + { + y_min = pnt[1]; + node_ymin = k; + } + if (pnt[1] > y_max) + { + y_max = pnt[1]; + node_ymax = k; + } + } - /// Find the range of this element - x_min = y_min = 1.e+20; - x_max = y_max = -1.e+20; - for (k = 0; k < nnodes; k++) + /// Determine the cells that this element covers. 05.10. 2010 + col_min = (long)((x_min - g_para[2]) / g_para[4]); + row_min = nrow - (long)((y_max - g_para[3]) / g_para[4]); + col_max = (long)((x_max - g_para[2]) / g_para[4]); + row_max = nrow - (long)((y_min - g_para[3]) / g_para[4]); + + double const* const pnt1(elem->nodes[0]->getData()); + x1[0] = pnt1[0]; + x1[1] = pnt1[1]; + double const* const pnt2(elem->nodes[1]->getData()); + x2[0] = pnt2[0]; + x2[1] = pnt2[1]; + double const* const pnt3(elem->nodes[2]->getData()); + x3[0] = pnt3[0]; + x3[1] = pnt3[1]; + + x3[2] = x2[2] = x1[2] = 0.; + cent[2] = 0.; + + for (m = col_min; m <= col_max; m++) + { + mm = m; + if (m > ncol - 1) + mm = ncol - 1; + if (m < 0) + mm = 0; + cent[0] = g_para[2] + g_para[4] * (mm + 0.5); + + for (n = row_min; n <= row_max; n++) { - double const* const pnt(elem->nodes[k]->getData()); - if (pnt[0] < x_min) + nn = n; + if (n > nrow - 1) + nn = nrow - 1; + if (nn < 0) + nn = 0; + cent[1] = g_para[3] + g_para[4] * (nrow - nn + 0.5); + + if (cent[0] < x_min) { - x_min = pnt[0]; - node_xmin = k; + double const* const pnt(elem->nodes[node_xmin]->getData()); + cent[0] = pnt[0]; + cent[1] = pnt[1]; } - if (pnt[0] > x_max) + if (cent[0] > x_max) { - x_max = pnt[0]; - node_xmax = k; + double const* const pnt(elem->nodes[node_xmax]->getData()); + cent[0] = pnt[0]; + cent[1] = pnt[1]; } - if (pnt[1] < y_min) + if (cent[1] < y_min) { - y_min = pnt[1]; - node_ymin = k; + double const* const pnt(elem->nodes[node_ymin]->getData()); + cent[0] = pnt[0]; + cent[1] = pnt[1]; } - if (pnt[1] > y_max) + if (cent[1] < y_max) { - y_max = pnt[1]; - node_ymax = k; + double const* const pnt(elem->nodes[node_ymax]->getData()); + cent[0] = pnt[0]; + cent[1] = pnt[1]; } - } - /// Determine the cells that this element covers. 05.10. 2010 - col_min = (long)((x_min - g_para[2]) / g_para[4]); - row_min = nrow - (long)((y_max - g_para[3]) / g_para[4]); - col_max = (long)((x_max - g_para[2]) / g_para[4]); - row_max = nrow - (long)((y_min - g_para[3]) / g_para[4]); - - double const* const pnt1 (elem->nodes[0]->getData()); - x1[0] = pnt1[0]; - x1[1] = pnt1[1]; - double const* const pnt2 (elem->nodes[1]->getData()); - x2[0] = pnt2[0]; - x2[1] = pnt2[1]; - double const* const pnt3 (elem->nodes[2]->getData()); - x3[0] = pnt3[0]; - x3[1] = pnt3[1]; - - x3[2] = x2[2] = x1[2] = 0.; - cent[2] = 0.; - - for(m = col_min; m <= col_max; m++) - { - mm = m; - if(m > ncol - 1) - mm = ncol - 1; - if(m < 0) - mm = 0; - cent[0] = g_para[2] + g_para[4] * (mm + 0.5); - - for(n = row_min; n <= row_max; n++) + /// Check whether this point is in this element. + sub_area[0] = ComputeDetTri(cent, x2, x3); + sub_area[1] = ComputeDetTri(cent, x3, x1); + sub_area[2] = ComputeDetTri(cent, x1, x2); + area = ComputeDetTri(x1, x2, x3); + + /// This point locates within the element + if (fabs(area - sub_area[0] - sub_area[1] - sub_area[2]) < tol_a) { - nn = n; - if(n > nrow - 1) - nn = nrow - 1; - if(nn < 0) - nn = 0; - cent[1] = g_para[3] + g_para[4] * - (nrow - nn + 0.5); - - if(cent[0] < x_min) - { - double const* const pnt ( - elem->nodes[node_xmin]-> - getData()); - cent[0] = pnt[0]; - cent[1] = pnt[1]; - } - if(cent[0] > x_max) - { - double const* const pnt ( - elem->nodes[node_xmax]-> - getData()); - cent[0] = pnt[0]; - cent[1] = pnt[1]; - } - if(cent[1] < y_min) - { - double const* const pnt ( - elem->nodes[node_ymin]-> - getData()); - cent[0] = pnt[0]; - cent[1] = pnt[1]; - } - if(cent[1] < y_max) - { - double const* const pnt ( - elem->nodes[node_ymax]-> - getData()); - cent[0] = pnt[0]; - cent[1] = pnt[1]; - } + /// Use sub_area[k] as shape function + for (k = 0; k < 3; k++) + sub_area[k] /= area; - /// Check whether this point is in this element. - sub_area[0] = ComputeDetTri(cent, x2, x3); - sub_area[1] = ComputeDetTri(cent, x3, x1); - sub_area[2] = ComputeDetTri(cent, x1, x2); - area = ComputeDetTri(x1, x2, x3); + l = nn * ncol + mm; + cell_data_p[l] = 0.0; - /// This point locates within the element - if(fabs(area - sub_area[0] - sub_area[1] - - sub_area[2]) < tol_a) - { - /// Use sub_area[k] as shape function - for(k = 0; k < 3; k++) - sub_area[k] /= area; + for (k = 0; k < 3; k++) + vel_av[k] = 0.; - l = nn * ncol + mm; - cell_data_p[l] = 0.0; + for (j = 0; j < nnodes; j++) + { + n_idx = elem->GetNodeIndex(j); - for(k = 0; k < 3; k++) - vel_av[k] = 0.; + cell_data_p[l] += sub_area[j] * GetNodeValue(n_idx, idx); - for(j = 0; j < nnodes; j++) - { - n_idx = elem->GetNodeIndex( - j); - - cell_data_p[l] += - sub_area[j] * - GetNodeValue( - n_idx, - idx); - - for(k = 0; k < 3; k++) - vel_av[k] += - sub_area[j] - * - GetNodeValue( - n_idx, - vel_idx - [k]); - } - cell_data_v[l] = 1000.0 * - (vel_av[0] * - (*elem-> - transform_tensor)( - 0,2) - + - vel_av[1] * - (*elem-> - transform_tensor)( - 1,2) - // 1000*: m-->mm - + - vel_av[2] * - (*elem-> - transform_tensor)( - 2,2)); + for (k = 0; k < 3; k++) + vel_av[k] += sub_area[j] * GetNodeValue(n_idx, vel_idx[k]); } + cell_data_v[l] = 1000.0 * (vel_av[0] * (*elem->transform_tensor)(0, 2) + + vel_av[1] * (*elem->transform_tensor)(1, 2) + // 1000*: m-->mm + + vel_av[2] * (*elem->transform_tensor)(2, 2)); } } } + } - of_flux.precision(4); - //of_flux.setf(ios::scientific, ios::floatfield); - of_primary.precision(2); - for(irow = 0; irow < nrow; irow++) + of_flux.precision(4); + // of_flux.setf(ios::scientific, ios::floatfield); + of_primary.precision(2); + for (irow = 0; irow < nrow; irow++) + { + for (icol = 0; icol < ncol; icol++) { - for(icol = 0; icol < ncol; icol++) - { - m = irow * ncol + icol; - of_flux << " " << setw(9) << cell_data_v[m]; - of_primary << setw(11) << cell_data_p[m]; - } - of_flux << "\n"; - of_primary << "\n"; + m = irow * ncol + icol; + of_flux << " " << setw(9) << cell_data_v[m]; + of_primary << setw(11) << cell_data_p[m]; } - - cell_data_p.clear(); - cell_data_v.clear(); - of_flux.close(); - of_primary.close(); + of_flux << "\n"; + of_primary << "\n"; } + + cell_data_p.clear(); + cell_data_v.clear(); + of_flux.close(); + of_primary.close(); } + } - // transient boundary condition - if (bc_transient_index.size() == 0) - return; + // transient boundary condition + if (bc_transient_index.size() == 0) + return; - bool valid = false; - long end_i = 0; - double t_fac = 0.; - std::vector node_value; + bool valid = false; + long end_i = 0; + double t_fac = 0.; + std::vector node_value; - for (size_t i = 0; i < bc_transient_index.size(); i++) - { - std::vector interpolation_points; - std::vector interpolation_values; + for (size_t i = 0; i < bc_transient_index.size(); i++) + { + std::vector interpolation_points; + std::vector interpolation_values; - CBoundaryCondition* bc = bc_node[bc_transient_index[i]]; - long start_i = bc_transient_index[i]; - if (i == bc_transient_index.size() - 1) - end_i = (long) bc_node.size(); - else - end_i = bc_transient_index[i + 1]; - - // fetch points (representing mesh nodes) along polyline for interpolation - std::vector nodes_as_interpol_points; - GEOLIB::Polyline const* ply ( - static_cast (bc->getGeoObj())); - m_msh->getPointsForInterpolationAlongPolyline (ply, - nodes_as_interpol_points); - - valid = false; - t_fac = 0.0; - // Piecewise linear distributed. - for (size_t i(0); i < bc->getDistribedBC().size(); i++) - { - for (size_t j = 0; j < ply->getNumberOfPoints(); j++) - if (bc->getPointsWithDistribedBC()[i] == - (int)ply->getPointID(j)) - { - if (fabs(bc->getDistribedBC()[i]) < MKleinsteZahl) - bc->getDistribedBC()[i] = 1.0e-20; - interpolation_points.push_back (ply->getLength(j)); - interpolation_values.push_back ( - bc->getDistribedBC()[i]); - - CFunction* fct (FCTGet(bc->getPointsFCTNames()[i])); - if (fct) - t_fac = fct->GetValue(aktuelle_zeit, &valid); - else - std::cout << - "Warning in CBoundaryConditionsGroup - no FCT data" - << "\n"; + CBoundaryCondition* bc = bc_node[bc_transient_index[i]]; + long start_i = bc_transient_index[i]; + if (i == bc_transient_index.size() - 1) + end_i = (long)bc_node.size(); + else + end_i = bc_transient_index[i + 1]; - if (valid) - interpolation_values[interpolation_values. - size() - 1] *= t_fac; + // fetch points (representing mesh nodes) along polyline for interpolation + std::vector nodes_as_interpol_points; + GEOLIB::Polyline const* ply(static_cast(bc->getGeoObj())); + m_msh->getPointsForInterpolationAlongPolyline(ply, nodes_as_interpol_points); - break; - } - } - std::vector interpol_res; - MathLib::PiecewiseLinearInterpolation (interpolation_points, - interpolation_values, - nodes_as_interpol_points, - interpol_res); + valid = false; + t_fac = 0.0; + // Piecewise linear distributed. + for (size_t i(0); i < bc->getDistribedBC().size(); i++) + { + for (size_t j = 0; j < ply->getNumberOfPoints(); j++) + if (bc->getPointsWithDistribedBC()[i] == (int)ply->getPointID(j)) + { + if (fabs(bc->getDistribedBC()[i]) < MKleinsteZahl) + bc->getDistribedBC()[i] = 1.0e-20; + interpolation_points.push_back(ply->getLength(j)); + interpolation_values.push_back(bc->getDistribedBC()[i]); + + CFunction* fct(FCTGet(bc->getPointsFCTNames()[i])); + if (fct) + t_fac = fct->GetValue(aktuelle_zeit, &valid); + else + std::cout << "Warning in CBoundaryConditionsGroup - no FCT data" + << "\n"; + + if (valid) + interpolation_values[interpolation_values.size() - 1] *= t_fac; - for (long k = start_i; k < end_i; k++) - bc_node_value[k]->node_value = interpol_res[k - start_i]; + break; + } } + std::vector interpol_res; + MathLib::PiecewiseLinearInterpolation(interpolation_points, interpolation_values, nodes_as_interpol_points, + interpol_res); + + for (long k = start_i; k < end_i; k++) + bc_node_value[k]->node_value = interpol_res[k - start_i]; } +} /************************************************************************* ROCKFLOW - Function: CRFProcess::Add_GEMS_Water_ST @@ -14694,115 +14609,105 @@ CRFProcess* PCSGetMass(size_t component_number) 11/2008 //HS Implementation **************************************************************************/ - void CRFProcess::Add_GEMS_Water_ST(long idx, double val) - { - Water_ST_GEMS tmp_st; +void CRFProcess::Add_GEMS_Water_ST(long idx, double val) +{ + Water_ST_GEMS tmp_st; - tmp_st.index_node = idx; - tmp_st.water_st_value = val; + tmp_st.index_node = idx; + tmp_st.water_st_value = val; - Water_ST_vec.push_back(tmp_st); - } + Water_ST_vec.push_back(tmp_st); +} - void CRFProcess::Clean_Water_ST_vec() - { - Water_ST_vec.clear(); - } +void CRFProcess::Clean_Water_ST_vec() +{ + Water_ST_vec.clear(); +} - void CRFProcess::configMaterialParameters () - { - // Output material parameters - //WW - const size_t out_vector_size (out_vector.size()); +void CRFProcess::configMaterialParameters() +{ + // Output material parameters + // WW + const size_t out_vector_size(out_vector.size()); - for (size_t i = 0; i < out_vector_size; i++) - { - COutput* out = out_vector[i]; - const size_t size (out->_nod_value_vector.size()); - for (size_t k = 0; k < size; k++) - if (out->_nod_value_vector[k].find("PERMEABILITY_X1") != - string::npos) - { - additioanl2ndvar_print = 1; - break; - } - if (additioanl2ndvar_print == 1) + for (size_t i = 0; i < out_vector_size; i++) + { + COutput* out = out_vector[i]; + const size_t size(out->_nod_value_vector.size()); + for (size_t k = 0; k < size; k++) + if (out->_nod_value_vector[k].find("PERMEABILITY_X1") != string::npos) + { + additioanl2ndvar_print = 1; break; - } + } + if (additioanl2ndvar_print == 1) + break; + } - for (size_t i = 0; i < out_vector_size; i++) + for (size_t i = 0; i < out_vector_size; i++) + { + COutput* out = out_vector[i]; + const size_t size(out->_nod_value_vector.size()); + for (size_t k = 0; k < size; k++) { - COutput* out = out_vector[i]; - const size_t size (out->_nod_value_vector.size()); - for (size_t k = 0; k < size; k++) + if (out->_nod_value_vector[k].find("POROSITY") != string::npos) { - if (out->_nod_value_vector[k].find("POROSITY") != string::npos) - { - if (additioanl2ndvar_print > 0) - additioanl2ndvar_print = 2; - else - additioanl2ndvar_print = 3; - } - if (additioanl2ndvar_print > 1) - break; + if (additioanl2ndvar_print > 0) + additioanl2ndvar_print = 2; + else + additioanl2ndvar_print = 3; } if (additioanl2ndvar_print > 1) break; } + if (additioanl2ndvar_print > 1) + break; + } - if (additioanl2ndvar_print > 0) //WW + if (additioanl2ndvar_print > 0) // WW + { + if (additioanl2ndvar_print < 3) { - if (additioanl2ndvar_print < 3) - { - pcs_secondary_function_name[pcs_number_of_secondary_nvals] - = "PERMEABILITY_X1"; - pcs_secondary_function_unit[pcs_number_of_secondary_nvals] - = "1/m^2"; - pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; - pcs_secondary_function_name[pcs_number_of_secondary_nvals] - = "PERMEABILITY_Y1"; - pcs_secondary_function_unit[pcs_number_of_secondary_nvals] - = "1/m^2"; - pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; - pcs_number_of_secondary_nvals++; - if (max_dim == 2) // 3D - { - pcs_secondary_function_name[pcs_number_of_secondary_nvals] - = "PERMEABILITY_Z1"; - pcs_secondary_function_unit[pcs_number_of_secondary_nvals] - = "1/m^2"; - pcs_secondary_function_timelevel[ - pcs_number_of_secondary_nvals] - = 1; - pcs_number_of_secondary_nvals++; - } - } - if (additioanl2ndvar_print > 1) //WW + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "PERMEABILITY_X1"; + pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "1/m^2"; + pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; + pcs_number_of_secondary_nvals++; + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "PERMEABILITY_Y1"; + pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "1/m^2"; + pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; + pcs_number_of_secondary_nvals++; + if (max_dim == 2) // 3D { - pcs_secondary_function_name[pcs_number_of_secondary_nvals] - = "POROSITY"; - pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "PERMEABILITY_Z1"; + pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "1/m^2"; pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; pcs_number_of_secondary_nvals++; } } + if (additioanl2ndvar_print > 1) // WW + { + pcs_secondary_function_name[pcs_number_of_secondary_nvals] = "POROSITY"; + pcs_secondary_function_unit[pcs_number_of_secondary_nvals] = "-"; + pcs_secondary_function_timelevel[pcs_number_of_secondary_nvals] = 1; + pcs_number_of_secondary_nvals++; + } } +} /************************************************************************* GeoSys - Function: 06/2009 OK Implementation **************************************************************************/ - bool PCSConfig() +bool PCSConfig() +{ + bool some_thing_done = false; + for (int i = 0; i < (int)pcs_vector.size(); i++) // OK { - bool some_thing_done = false; - for(int i = 0; i < (int)pcs_vector.size(); i++) //OK - { - pcs_vector[i]->Config(); - some_thing_done = true; - } - return some_thing_done; + pcs_vector[i]->Config(); + some_thing_done = true; } + return some_thing_done; +} /************************************************************************* GeoSys-Function: CalGPVelocitiesfromEclipse @@ -14812,28 +14717,24 @@ CRFProcess* PCSGetMass(size_t component_number) 09/2009 SB BG Implementation **************************************************************************/ -void CRFProcess::CalGPVelocitiesfromECLIPSE(string path, - int timestep, - int phase_index, - string phase) +void CRFProcess::CalGPVelocitiesfromECLIPSE(string path, int timestep, int phase_index, string phase) { - (void)path; // unused - (void)timestep; // unused + (void)path; // unused + (void)timestep; // unused long i; MeshLib::CElem* elem = NULL; - clock_t start,finish; + clock_t start, finish; double time; start = clock(); cout << " CalGPVelocitiesfromECLIPSE() "; - //Test Output - vector vec_string; + // Test Output + vector vec_string; string tempstring; ostringstream temp; - vec_string.push_back( - "Element; X; Y; Z; v_Geosys_x; v_Geosys_y; v_Geosys_z; v_Eclipse_x; v_Eclipse_y; v_Eclipse_z"); + vec_string.push_back("Element; X; Y; Z; v_Geosys_x; v_Geosys_y; v_Geosys_z; v_Eclipse_x; v_Eclipse_y; v_Eclipse_z"); // Loop over all elements for (i = 0; i < (long)m_msh->ele_vector.size(); i++) @@ -14841,7 +14742,7 @@ void CRFProcess::CalGPVelocitiesfromECLIPSE(string path, elem = m_msh->ele_vector[i]; // get element if (elem->GetMark()) // Marked for use { - //Test Output + // Test Output tempstring = ""; temp.str(""); temp.clear(); @@ -14864,1111 +14765,1070 @@ void CRFProcess::CalGPVelocitiesfromECLIPSE(string path, // Configure Element for interpolation of node velocities to GP velocities fem->ConfigElement(elem, m_num->ele_gauss_points); // Interpolate from nodes to GP of actual element - //cout << "Element: " << i << "\n"; - tempstring = fem->Cal_GP_Velocity_ECLIPSE(tempstring, - true, - phase_index, - phase); + // cout << "Element: " << i << "\n"; + tempstring = fem->Cal_GP_Velocity_ECLIPSE(tempstring, true, phase_index, phase); // Test Output vec_string.push_back(tempstring); } - } // end element loop - - // // Test Output - // if (timestep == 1 || timestep % 10 == 0 ) { - //int position = path.find_last_of("\\"); - //path = path.substr(0,position); - //position = path.find_last_of("\\"); - //path = path.substr(0,position); - //temp.str(""); temp.clear(); temp << timestep; tempstring = temp.str(); - //string aus_file = path + "\\CheckVelocity_" + phase + "_" + tempstring + ".csv"; - //ofstream aus; - //aus.open(aus_file.data(),ios::out); - //for (i = 0; i < vec_string.size(); i++) { - // aus << vec_string[i] << "\n"; - //} - //aus.close(); - //} - - finish = clock(); - time = (double(finish) - double(start)) / CLOCKS_PER_SEC; - cout << " Time: " << time << " seconds." << "\n"; -} - - -//------------------------------------------------------------------------- -//GeoSys - Function: CO2_H2O_NaCl_VLE_isobaric -//Task: Calculates the isobaric vapour liquid equilibrium for the CO2-H2O-NaCl System -//Return: nothing -//Programming: 11/2010 DL, BG -//Modification: -//------------------------------------------------------------------------- - void CRFProcess::CO2_H2O_NaCl_VLE_isobaric(double T, - double P, - Phase_Properties &vapor, - Phase_Properties &liquid, - Phase_Properties &solid, - int f) - { - //f --- 1 V-L-S, 2 V-L, 3 CO2-L-S, 4 CO2-L - - double tCO2,tH2O,tNaCl; - double wH2O,mNaCl=0,soluCO2=0,xCO2,yH2O,AW = 1.0; // ,mCO2; unused - double a,b,tvCO2=0,tvH2O=0,tH2Or=0,er = 1.0e-6,err = 1.0e-6; - int i,iter_max = 100; - double Molweight_CO2, Molweight_H2O,Molweight_NaCl; - - Molweight_CO2 = 44.009; - Molweight_H2O = 18.0148; - Molweight_NaCl = 58.443; //ToDo: provide constants once in the whole project - - tCO2 = vapor.CO2 + liquid.CO2 + solid.CO2; - tH2O = vapor.H2O + liquid.H2O + solid.H2O; - tNaCl = vapor.NaCl + liquid.NaCl + solid.NaCl; - yH2O = VLE::fraction_H2O(T,P,AW); //water fraction in vapor - // //cout << " yH2O " << yH2O << " xCO2 " << xCO2 << "\n"; - - //cout << " flag " << f << "\n"; - //V-L-S - if(f == 1 || f == 2) - { - //cout << " >>>>> phase equilibrium <<<<< " << "\n"; - a = 0.0; - b = tCO2; - for(i = 0; i < iter_max; i++) - { - tvCO2 = (a + b) / 2.0; - tvH2O = tvCO2 * yH2O / (1 - yH2O); - wH2O = (tH2O - tvH2O) * Molweight_H2O / 1000; - - mNaCl = tNaCl / wH2O; - if(f == 1) - if(mNaCl > 4.5) - mNaCl = 4.5; - //NaCl solubility calc - - soluCO2 = VLE::solubility_CO2(T,P,mNaCl); - //???????????????????????????? (soluCO2 <= tCO2?) - xCO2 = soluCO2 / (soluCO2 + 1000 / Molweight_H2O); - tH2Or = tvH2O + (tCO2 - tvCO2) * (1 - xCO2) / xCO2; - //cout << " tH2Or " << tH2Or << " tH2O " << tH2O << "\n"; - - if(abs(tH2Or - tH2O) < er) - break; // two phases coexisting - if(tvCO2 < err) // single liquid phase - { - tvCO2 = 0; - break; - } - if(tCO2 - tvCO2 < err) // single vapor phase - { - tvCO2 = tCO2; - break; - } - if(tH2Or > tH2O) - a = tvCO2; - else - b = tvCO2; - } - - // single liquid phase - if(tvCO2 == 0) - { - //cout << " >>>>> single liquid phase <<<<< " << "\n"; - vapor.CO2 = 0.0; - vapor.H2O = 0.0; - vapor.NaCl = 0.0; + } // end element loop - wH2O = tH2O * Molweight_H2O / 1000; - mNaCl = tNaCl / wH2O; - if(f == 1) - if(mNaCl > 4.5) - mNaCl = 4.5; - //NaCl solubility calc + // // Test Output + // if (timestep == 1 || timestep % 10 == 0 ) { + // int position = path.find_last_of("\\"); + // path = path.substr(0,position); + // position = path.find_last_of("\\"); + // path = path.substr(0,position); + // temp.str(""); temp.clear(); temp << timestep; tempstring = temp.str(); + // string aus_file = path + "\\CheckVelocity_" + phase + "_" + tempstring + ".csv"; + // ofstream aus; + // aus.open(aus_file.data(),ios::out); + // for (i = 0; i < vec_string.size(); i++) { + // aus << vec_string[i] << "\n"; + //} + // aus.close(); + //} - liquid.CO2 = tCO2; - liquid.H2O = tH2O; - liquid.NaCl = mNaCl * wH2O; + finish = clock(); + time = (double(finish) - double(start)) / CLOCKS_PER_SEC; + cout << " Time: " << time << " seconds." + << "\n"; +} - vapor.temperature = T; - vapor.pressure = P; - vapor.density = -1.0; - vapor.viscosity = -1.0; - vapor.volume = 0.0; - vapor.mass = 0.0; +//------------------------------------------------------------------------- +// GeoSys - Function: CO2_H2O_NaCl_VLE_isobaric +// Task: Calculates the isobaric vapour liquid equilibrium for the CO2-H2O-NaCl System +// Return: nothing +// Programming: 11/2010 DL, BG +// Modification: +//------------------------------------------------------------------------- +void CRFProcess::CO2_H2O_NaCl_VLE_isobaric(double T, double P, Phase_Properties& vapor, Phase_Properties& liquid, + Phase_Properties& solid, int f) +{ + // f --- 1 V-L-S, 2 V-L, 3 CO2-L-S, 4 CO2-L - liquid.temperature = T; - liquid.pressure = P; - liquid.density = density::CO2brine(T,P,mNaCl,liquid.CO2 / wH2O); - liquid.viscosity = -1.0; - liquid.mass = liquid.H2O * Molweight_H2O + liquid.CO2 * - Molweight_CO2 + liquid.NaCl * Molweight_NaCl; - liquid.volume = liquid.mass / liquid.density; - } + double tCO2, tH2O, tNaCl; + double wH2O, mNaCl = 0, soluCO2 = 0, xCO2, yH2O, AW = 1.0; // ,mCO2; unused + double a, b, tvCO2 = 0, tvH2O = 0, tH2Or = 0, er = 1.0e-6, err = 1.0e-6; + int i, iter_max = 100; + double Molweight_CO2, Molweight_H2O, Molweight_NaCl; - // single vapor phase - else if(tvCO2 == tCO2) - { - //cout << " >>>>> single vapor phase <<<<< " << "\n"; - vapor.CO2 = tCO2; - vapor.H2O = tH2O; - vapor.NaCl = 0.0; + Molweight_CO2 = 44.009; + Molweight_H2O = 18.0148; + Molweight_NaCl = 58.443; // ToDo: provide constants once in the whole project - liquid.CO2 = 0.0; - liquid.H2O = 0.0; - liquid.NaCl = 0.0; + tCO2 = vapor.CO2 + liquid.CO2 + solid.CO2; + tH2O = vapor.H2O + liquid.H2O + solid.H2O; + tNaCl = vapor.NaCl + liquid.NaCl + solid.NaCl; + yH2O = VLE::fraction_H2O(T, P, AW); // water fraction in vapor + // //cout << " yH2O " << yH2O << " xCO2 " << xCO2 << "\n"; - liquid.mass = 0.0; - liquid.volume = 0.0; + // cout << " flag " << f << "\n"; + // V-L-S + if (f == 1 || f == 2) + { + // cout << " >>>>> phase equilibrium <<<<< " << "\n"; + a = 0.0; + b = tCO2; + for (i = 0; i < iter_max; i++) + { + tvCO2 = (a + b) / 2.0; + tvH2O = tvCO2 * yH2O / (1 - yH2O); + wH2O = (tH2O - tvH2O) * Molweight_H2O / 1000; - solid.NaCl = tNaCl; + mNaCl = tNaCl / wH2O; + if (f == 1) + if (mNaCl > 4.5) + mNaCl = 4.5; + // NaCl solubility calc - vapor.temperature = T; - vapor.pressure = P; + soluCO2 = VLE::solubility_CO2(T, P, mNaCl); + //???????????????????????????? (soluCO2 <= tCO2?) + xCO2 = soluCO2 / (soluCO2 + 1000 / Molweight_H2O); + tH2Or = tvH2O + (tCO2 - tvCO2) * (1 - xCO2) / xCO2; + // cout << " tH2Or " << tH2Or << " tH2O " << tH2O << "\n"; - vapor.density = VLE::density_CO2(T,P); //to use mixture fluid EoS - vapor.viscosity = -1.0; - vapor.mass = vapor.CO2 * Molweight_CO2 + vapor.H2O * Molweight_H2O; - vapor.volume = vapor.mass / vapor.density; + if (abs(tH2Or - tH2O) < er) + break; // two phases coexisting + if (tvCO2 < err) // single liquid phase + { + tvCO2 = 0; + break; } - - // two phases coexisting - else + if (tCO2 - tvCO2 < err) // single vapor phase { - //cout << " >>>>> two phases coexisting <<<<< " << "\n"; - vapor.H2O = tvH2O; - vapor.CO2 = tvCO2; - vapor.NaCl = 0.0; - - liquid.H2O = tH2O - tvH2O; - liquid.CO2 = tCO2 - tvCO2; - liquid.NaCl = mNaCl * wH2O; - - vapor.temperature = T; - vapor.density = VLE::density_CO2(T,P); //to use mixture fluid EoS - vapor.viscosity = -1; - vapor.mass = vapor.CO2 * Molweight_CO2 + vapor.H2O * Molweight_H2O; - vapor.pressure = VLE::pressure_CO2(T,vapor.density); - vapor.volume = vapor.mass / vapor.density; - - liquid.temperature = T; - liquid.pressure = P; - liquid.density = density::CO2brine(T,P,mNaCl,soluCO2); - liquid.viscosity = -1.0; - liquid.mass = liquid.CO2 * Molweight_CO2 + liquid.H2O * - Molweight_H2O + liquid.NaCl * Molweight_NaCl; - liquid.volume = liquid.mass / liquid.density; + tvCO2 = tCO2; + break; } + if (tH2Or > tH2O) + a = tvCO2; + else + b = tvCO2; } - else if(f == 3 || f == 4) + // single liquid phase + if (tvCO2 == 0) { + // cout << " >>>>> single liquid phase <<<<< " << "\n"; + vapor.CO2 = 0.0; + vapor.H2O = 0.0; + vapor.NaCl = 0.0; + wH2O = tH2O * Molweight_H2O / 1000; mNaCl = tNaCl / wH2O; - if(f == 3) - if(mNaCl > 4.5) + if (f == 1) + if (mNaCl > 4.5) mNaCl = 4.5; - //NaCl solubility calc - soluCO2 = VLE::solubility_CO2(T,P,mNaCl); - - // single liquid phase - if(tCO2 < soluCO2 * wH2O) - { - //cout << " >>>>> single liquid phase <<<<< " << "\n"; - vapor.CO2 = 0.0; - vapor.H2O = 0.0; - vapor.NaCl = 0.0; - - liquid.CO2 = tCO2; - liquid.H2O = tH2O; - liquid.NaCl = mNaCl * wH2O; - - vapor.temperature = T; - vapor.pressure = P; - vapor.density = -1.0; - vapor.viscosity = -1.0; - vapor.volume = 0.0; - vapor.mass = 0.0; - - liquid.temperature = T; - liquid.pressure = P; - liquid.density = density::CO2brine(T,P,mNaCl,liquid.CO2 / wH2O); - liquid.viscosity = -1.0; - liquid.mass = liquid.H2O * Molweight_H2O + liquid.CO2 * - Molweight_CO2 + liquid.NaCl * Molweight_NaCl; - liquid.volume = liquid.mass / liquid.density; - } - - // two phases coexisting - else - { - //cout << " >>>>> two phases coexisting <<<<< " << "\n"; - vapor.H2O = 0.0; - vapor.CO2 = tCO2 - soluCO2 * wH2O; - vapor.NaCl = 0.0; + // NaCl solubility calc - liquid.H2O = tH2O; - liquid.CO2 = soluCO2 * wH2O; - liquid.NaCl = mNaCl * wH2O; + liquid.CO2 = tCO2; + liquid.H2O = tH2O; + liquid.NaCl = mNaCl * wH2O; - vapor.temperature = T; - vapor.density = VLE::density_CO2(T,P); //to use mixture fluid EoS - vapor.viscosity = -1; - vapor.mass = vapor.CO2 * Molweight_CO2 + vapor.H2O * Molweight_H2O; - vapor.pressure = VLE::pressure_CO2(T,vapor.density); - vapor.volume = vapor.mass / vapor.density; + vapor.temperature = T; + vapor.pressure = P; + vapor.density = -1.0; + vapor.viscosity = -1.0; + vapor.volume = 0.0; + vapor.mass = 0.0; - liquid.temperature = T; - liquid.pressure = P; - liquid.density = density::CO2brine(T,P,mNaCl,soluCO2); - liquid.viscosity = -1.0; - liquid.mass = liquid.CO2 * Molweight_CO2 + liquid.H2O * - Molweight_H2O + liquid.NaCl * Molweight_NaCl; - liquid.volume = liquid.mass / liquid.density; - } + liquid.temperature = T; + liquid.pressure = P; + liquid.density = density::CO2brine(T, P, mNaCl, liquid.CO2 / wH2O); + liquid.viscosity = -1.0; + liquid.mass = liquid.H2O * Molweight_H2O + liquid.CO2 * Molweight_CO2 + liquid.NaCl * Molweight_NaCl; + liquid.volume = liquid.mass / liquid.density; } - } -//------------------------------------------------------------------------- -//GeoSys - Function: CO2_H2O_NaCl_VLE_isobaric -//Task: Calculates the isobaric vapour liquid equilibrium for the CO2-H2O-NaCl System -//Return: nothing -//Programming: 11/2010 DL, BG -//Modification: -//------------------------------------------------------------------------- - void CRFProcess::CO2_H2O_NaCl_VLE_isochoric(Phase_Properties &vapor, - Phase_Properties &liquid, - Phase_Properties &solid, - int f) - { - //f --- 1 V-L-S, 2 V-L, 3 CO2-L-S, 4 CO2-L + // single vapor phase + else if (tvCO2 == tCO2) + { + // cout << " >>>>> single vapor phase <<<<< " << "\n"; + vapor.CO2 = tCO2; + vapor.H2O = tH2O; + vapor.NaCl = 0.0; - int i,i_max = 100; - double V, V0, P1 = 0.0, P2 = 0.0; - double err = 1.0e-4; - double T, P; + liquid.CO2 = 0.0; + liquid.H2O = 0.0; + liquid.NaCl = 0.0; - T = vapor.temperature; - P = vapor.pressure; + liquid.mass = 0.0; + liquid.volume = 0.0; - V0 = vapor.volume + liquid.volume; - CO2_H2O_NaCl_VLE_isobaric(T, P, vapor, liquid, solid, f); - V = vapor.volume + liquid.volume; + solid.NaCl = tNaCl; - //cout << " V input " << V << "\n"; + vapor.temperature = T; + vapor.pressure = P; - if(abs(V - V0) < err) - return; - else if(V > V0) - { - P1 = P; - P2 = 5.0 * P; //P2=5.0*P; - } - else if(V < V0) - { - P1 = 0.2 * P; //P1=0.2*P; - P2 = P; + vapor.density = VLE::density_CO2(T, P); // to use mixture fluid EoS + vapor.viscosity = -1.0; + vapor.mass = vapor.CO2 * Molweight_CO2 + vapor.H2O * Molweight_H2O; + vapor.volume = vapor.mass / vapor.density; } - for(i = 0; i < i_max; i++) + // two phases coexisting + else { - P = 0.5 * (P1 + P2); - CO2_H2O_NaCl_VLE_isobaric(T, P, vapor, liquid, solid, f); - V = vapor.volume + liquid.volume; - //cout << P << " " << V << "\n"; - if(abs(V0 - V) < err) - break; - else if(V < V0) - P2 = P; - else if(V > V0) - P1 = P; - } - } - -//------------------------------------------------------------------------- -//GeoSys - Function: CalculateFluidDensitiesAndViscositiesAtNodes -//Task: Calculates density and viscosity of a multiphase flow system -//Return: nothing -//Programming: 11/2010 BG, NB -//Modification: -//------------------------------------------------------------------------- - void CRFProcess::CalculateFluidDensitiesAndViscositiesAtNodes(CRFProcess* m_pcs) - { - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt - MeshLib::CElem* m_ele = NULL; - MeshLib::CNode* m_node = NULL; - double saturation_gas, saturation_liquid; - double Molweight_CO2, Molweight_H2O, Molweight_NaCl; - double Density_gas=0, Density_liquid=0, Density_pureCO2, Viscosity_liquid, - Viscosity_gas; - // ,c_H2OinLiquid; unused - double c_CO2inLiquid, c_NaClinLiquid, c_H2OinGas; - double b_CO2inPureWater, b_NaClinPureWater; //WW, b_H2OinPureCO2; - double mass_gas; - // ,Volume_eff; unused - //WW double volume_liquid, - double volume_gas, node_volume, porosity; - // ,saturation_liquid_effective ,saturation_gas_effective; unused - //WW double saturation_gas_min, saturation_liquid_min; - int variable_index, indexProcess; - CMediumProperties* MediaProp; - CFluidProperties* FluidProp; - CRFProcess* pcs_MassTransport; - double pressure, temperature; - int MassTransportID[5] = {0,0,0,0,0}; - int MaterialGroup = 0; - int TimeStepVariableIndex = 1; - clock_t start,finish; - double time; - double a, b, temp_density; // unit: [kg/m³] - double wCO2, wNaCl, wH2O; // unit: [kg/kg] - double epsilon = 1e-2; - int iter_max = 100; - - start = clock(); - - //for initial conditions variable index is the first index, for other timesteps variable index is the second index - if (m_pcs->Tim->step_current == 1) - TimeStepVariableIndex = 0; + // cout << " >>>>> two phases coexisting <<<<< " << "\n"; + vapor.H2O = tvH2O; + vapor.CO2 = tvCO2; + vapor.NaCl = 0.0; + + liquid.H2O = tH2O - tvH2O; + liquid.CO2 = tCO2 - tvCO2; + liquid.NaCl = mNaCl * wH2O; + + vapor.temperature = T; + vapor.density = VLE::density_CO2(T, P); // to use mixture fluid EoS + vapor.viscosity = -1; + vapor.mass = vapor.CO2 * Molweight_CO2 + vapor.H2O * Molweight_H2O; + vapor.pressure = VLE::pressure_CO2(T, vapor.density); + vapor.volume = vapor.mass / vapor.density; + + liquid.temperature = T; + liquid.pressure = P; + liquid.density = density::CO2brine(T, P, mNaCl, soluCO2); + liquid.viscosity = -1.0; + liquid.mass = liquid.CO2 * Molweight_CO2 + liquid.H2O * Molweight_H2O + liquid.NaCl * Molweight_NaCl; + liquid.volume = liquid.mass / liquid.density; + } + } + + else if (f == 3 || f == 4) + { + wH2O = tH2O * Molweight_H2O / 1000; + mNaCl = tNaCl / wH2O; + if (f == 3) + if (mNaCl > 4.5) + mNaCl = 4.5; + // NaCl solubility calc + soluCO2 = VLE::solubility_CO2(T, P, mNaCl); + + // single liquid phase + if (tCO2 < soluCO2 * wH2O) + { + // cout << " >>>>> single liquid phase <<<<< " << "\n"; + vapor.CO2 = 0.0; + vapor.H2O = 0.0; + vapor.NaCl = 0.0; + + liquid.CO2 = tCO2; + liquid.H2O = tH2O; + liquid.NaCl = mNaCl * wH2O; + + vapor.temperature = T; + vapor.pressure = P; + vapor.density = -1.0; + vapor.viscosity = -1.0; + vapor.volume = 0.0; + vapor.mass = 0.0; + + liquid.temperature = T; + liquid.pressure = P; + liquid.density = density::CO2brine(T, P, mNaCl, liquid.CO2 / wH2O); + liquid.viscosity = -1.0; + liquid.mass = liquid.H2O * Molweight_H2O + liquid.CO2 * Molweight_CO2 + liquid.NaCl * Molweight_NaCl; + liquid.volume = liquid.mass / liquid.density; + } + + // two phases coexisting else - TimeStepVariableIndex = 1; - - Molweight_CO2 = 44.009; // [g/mol] - Molweight_H2O = 18.0148; // [g/mol] - Molweight_NaCl = 58.443; // [g/mol] //ToDo: provide constants once in the whole project + { + // cout << " >>>>> two phases coexisting <<<<< " << "\n"; + vapor.H2O = 0.0; + vapor.CO2 = tCO2 - soluCO2 * wH2O; + vapor.NaCl = 0.0; - //WW saturation_gas_min = 0.00001; - //WW saturation_liquid_min = 0.00001; + liquid.H2O = tH2O; + liquid.CO2 = soluCO2 * wH2O; + liquid.NaCl = mNaCl * wH2O; - for (long i = 0; i < (long)m_msh->nod_vector.size(); i++) - { - m_node = m_msh->nod_vector[i]; // get element - node_volume = 0; + vapor.temperature = T; + vapor.density = VLE::density_CO2(T, P); // to use mixture fluid EoS + vapor.viscosity = -1; + vapor.mass = vapor.CO2 * Molweight_CO2 + vapor.H2O * Molweight_H2O; + vapor.pressure = VLE::pressure_CO2(T, vapor.density); + vapor.volume = vapor.mass / vapor.density; - //calculate Porevolume for the node based on connected elements - for (size_t j = 0; j < m_node->getConnectedElementIDs().size(); j++) - { - m_ele = m_msh->ele_vector[m_node->getConnectedElementIDs()[j]]; - MaterialGroup = m_ele->GetPatchIndex(); - MediaProp = mmp_vector[MaterialGroup]; - porosity = MediaProp->Porosity( - m_ele->GetIndex(), m_pcs->m_num->ls_theta); - // ToDo: Correct calculation of node volume - node_volume = node_volume + m_ele->GetVolume() / - m_ele->GetNodesNumber(false) * porosity; - } + liquid.temperature = T; + liquid.pressure = P; + liquid.density = density::CO2brine(T, P, mNaCl, soluCO2); + liquid.viscosity = -1.0; + liquid.mass = liquid.CO2 * Molweight_CO2 + liquid.H2O * Molweight_H2O + liquid.NaCl * Molweight_NaCl; + liquid.volume = liquid.mass / liquid.density; + } + } +} - //get pressure, temperature and saturations - //+1... new time level - variable_index = m_pcs->GetNodeValueIndex("PRESSURE2") + - TimeStepVariableIndex; - // unit: bar!!! Assuming that the non wetting phase pressure is the correct one - pressure = m_pcs->GetNodeValue(i, variable_index) / 1e5; - if(!T_Process) - { - // Get reference temperature if no heat transport is used - FluidProp = MFPGet("LIQUID"); - temperature = FluidProp->getReferenceTemperature(); - } - else - { - CRFProcess* HeatProcess = PCSGet("HEAT_TRANSPORT"); - //+1... new time level - variable_index = HeatProcess->GetNodeValueIndex("TEMPERATURE1") + - TimeStepVariableIndex; - temperature = m_pcs->GetNodeValue(i, variable_index); - } - //+1... new time level - variable_index = m_pcs->GetNodeValueIndex("SATURATION1") + - TimeStepVariableIndex; - saturation_liquid = m_pcs->GetNodeValue(i, variable_index); - saturation_gas = 1 - saturation_liquid; - - //calculate liquid and gas volume from saturation - //Volume_eff = node_volume * (1 - saturation_gas_min - saturation_liquid_min); //[m³] - //[m³] - //WW volume_liquid = node_volume * saturation_liquid; - volume_gas = node_volume * saturation_gas; - - //get ID's of mass transport processes - for(int j = 0; j < int(pcs_vector.size()); j++) - { - pcs_MassTransport = pcs_vector[j]; - if (pcs_MassTransport->nod_val_name_vector[0] == "H2O") - MassTransportID[0] = j; - if ((pcs_MassTransport->nod_val_name_vector[0] == "C(4)") || - (pcs_MassTransport->nod_val_name_vector[0] == "CO2")) // "CO2_w" CB - MassTransportID[1] = j; - if (pcs_MassTransport->nod_val_name_vector[0] == "NaCl") - MassTransportID[2] = j; - if (pcs_MassTransport->nod_val_name_vector[0] == "CO2") - MassTransportID[3] = j; - if (pcs_MassTransport->nod_val_name_vector[0] == "H2O_gas") - MassTransportID[4] = j; - } - - //Read CO2 concentration in water and calculate moles of CO2 in liquid phase - indexProcess = MassTransportID[1]; - // +1: new timelevel - variable_index = - pcs_vector[indexProcess]->GetNodeValueIndex( - pcs_vector[indexProcess]->pcs_primary_function_name[0]) + - TimeStepVariableIndex; - //[mol/m³] - c_CO2inLiquid = pcs_vector[indexProcess]->GetNodeValue(i, variable_index); +//------------------------------------------------------------------------- +// GeoSys - Function: CO2_H2O_NaCl_VLE_isobaric +// Task: Calculates the isobaric vapour liquid equilibrium for the CO2-H2O-NaCl System +// Return: nothing +// Programming: 11/2010 DL, BG +// Modification: +//------------------------------------------------------------------------- +void CRFProcess::CO2_H2O_NaCl_VLE_isochoric(Phase_Properties& vapor, + Phase_Properties& liquid, + Phase_Properties& solid, + int f) +{ + // f --- 1 V-L-S, 2 V-L, 3 CO2-L-S, 4 CO2-L - //Read NaCl concentration in water and calculate moles of NaCl in liquid phase - indexProcess = MassTransportID[2]; - // +1: new timelevel - variable_index = - pcs_vector[indexProcess]->GetNodeValueIndex( - pcs_vector[indexProcess]->pcs_primary_function_name[0]) + - TimeStepVariableIndex; - //[mol/m³] - c_NaClinLiquid = pcs_vector[indexProcess]->GetNodeValue(i, variable_index); + int i, i_max = 100; + double V, V0, P1 = 0.0, P2 = 0.0; + double err = 1.0e-4; + double T, P; - if (saturation_liquid > 0) - { - //Determine moles of water in liquid phase - //calculate liquid density for initial conditions - //estimate density -> calculate moles of components -> calculate real density -> compare with estimation -> loop until similar values - a = 800; //estimated range of valid density [kg/m³] - b = 1800; - for(int j = 0; j < iter_max; j++) - { - temp_density = (a + b) / 2.0; - // mass fraction of kg CO2 per kg liquid (mol/m³ * m³/kg * g/mol / 1000) = kg/kg - wCO2 = c_CO2inLiquid / temp_density * Molweight_CO2 / 1000; - // mass fraction of kg NaCl per kg liquid (mol/m³ * m³/kg * g/mol / 1000) = kg/kg - wNaCl = c_NaClinLiquid / temp_density * Molweight_NaCl / - 1000; - wH2O = 1 - wCO2 - wNaCl; // mass fraction of kg H2O per kg liquid - //Molality = concentration in mol per kg of solution / mass fraction of solvent = mol per kg solvent - // Molality of CO2 in mol per kg pure water (mol/m³ * m³/kg) = mol/kg - b_CO2inPureWater = c_CO2inLiquid / temp_density * 1 / wH2O; - // Molality of NaCl in mol per kg pure water (mol/m³ * m³/kg) = mol/kg - b_NaClinPureWater = c_NaClinLiquid / temp_density * 1 / - wH2O; - // new estimate of density of brine with estimated concentration of CO2 and NaCl in mol per kg pure water - //function provides g/cm³ -> Density_liquid [kg/m³] - Density_liquid = 1000 * density::CO2brine(temperature, - pressure, - b_NaClinPureWater, - b_CO2inPureWater); - //cout.precision(8); - //cout << "Iteration: " << j << " estimated: " << temp_density << " calculated: " << Density_liquid << " a: " << a << " b: " << b << "\n"; - //compare density with density estimation - if (Density_liquid < 0) - break; - if (fabs(Density_liquid - temp_density) < epsilon) - break; - else if (Density_liquid < temp_density) - b = temp_density; - else if (Density_liquid > temp_density) - a = temp_density; - } - //if (i == 230) - // cout << i << "\n"; + T = vapor.temperature; + P = vapor.pressure; - if (Density_liquid < 0) - { - cout << "Density calculation of water was not possible" << - "\n"; - system("Pause"); - exit(0); - } - //calculate new moles of H2O - //c_H2OinLiquid = (Density_liquid - c_CO2inLiquid * Molweight_CO2 * 1e-3 - c_NaClinLiquid * Molweight_NaCl * 1e-3) / (Molweight_H2O * 1e-3); //[mol] - //indexProcess = MassTransportID[0]; //H2O in liquid - //variable_index = pcs_vector[indexProcess]->GetNodeValueIndex(pcs_vector[indexProcess]->pcs_primary_function_name[0]) + 1; // +1: new timelevel - //pcs_vector[indexProcess]->SetNodeValue(i, variable_index, c_H2OinLiquid); - - //set new density to nodes - variable_index = m_pcs->GetNodeValueIndex("DENSITY1"); - m_pcs->SetNodeValue(i, variable_index, Density_liquid); - - //set new viscosity to nodes - variable_index = m_pcs->GetNodeValueIndex("VISCOSITY1"); - Viscosity_liquid = 5.1e-4; - m_pcs->SetNodeValue(i, variable_index, Viscosity_liquid); - } - - if (saturation_gas > 0) - { - //components in gas - //Read H2O concentration in gas and calculate moles of H2O in gas phase - indexProcess = MassTransportID[4]; - // +1: new timelevel - variable_index = pcs_vector[indexProcess]->GetNodeValueIndex( - pcs_vector[indexProcess]->pcs_primary_function_name[0]) + - TimeStepVariableIndex; - //[mol/m³] - c_H2OinGas = pcs_vector[indexProcess]->GetNodeValue(i, - variable_index); - - //calculate gas density for initial conditions - a = 0.1; //estimated range of valid gas density [kg/m³] - b = 1000; - epsilon = 1e-3; - iter_max = 100; - for(int j = 0; j < iter_max; j++) - { - temp_density = (a + b) / 2.0; - // mass fraction of kg H2O per kg gas (mol/m³ * m³/kg * g/mol / 1000) = kg/kg - wH2O = c_H2OinGas / temp_density * Molweight_H2O / 1000; - wCO2 = 1 - wH2O; // mass fraction of kg CO2 per kg gas - // Molality of H2O in pure CO2 (mol/m³ * m³/kg) = mol/kg) - //WW b_H2OinPureCO2 = c_H2OinGas / temp_density * 1 / wCO2; - // new estimate of density of brine with estimated concentration of CO2 and NaCl in mol per kg pure water - Density_pureCO2 = 1000 * VLE::density_CO2(temperature, - pressure); - Density_gas = Density_pureCO2; - - //Using Norberts EOS, uses mole fractions of components, temperature and pressure [Pa] - double m_CO2, m_H2O; // mass [kg] - double n_CO2, n_H2O; // [mol] - double x_CO2; //WW, x_H2O; // mole fraction [mol/mol] - mass_gas = volume_gas * Density_gas; // mass of gas phase [kg] = m³ * kg/m³ - m_CO2 = mass_gas * wCO2; // mas of CO2 [kg] = kg * kg/kg - m_H2O = mass_gas * wH2O; // mass of H2O [kg] = kg * kg/kg - n_CO2 = m_CO2 * Molweight_CO2 / 1000; // moles of CO2 [mol] = kg * g/mol / 1000 g/kg - n_H2O = m_H2O * Molweight_H2O / 1000; // moles of H2O [mol] = kg * g/mol / 1000 g/kg - x_CO2 = n_CO2 / (n_CO2 + n_H2O); // mole fraction of CO2 [mol/mol] - //WW x_H2O = n_H2O / (n_CO2 + n_H2O); // mole fraction of H2O [mol/mol] - // ToDo: reorganisation of the code [kg/m³] - Density_gas = DuansMixingRule(temperature, pressure * 1e5, x_CO2, 0, 1, 0); - //cout.precision(8); - //cout << "Iteration: " << j << " estimated: " << temp_density << " calculated: " << Density_gas << " a: " << a << " b: " << b << "\n"; - - //compare density with density estimation - if (Density_gas < 0) - break; - if (fabs(Density_gas - temp_density) < epsilon) - break; - if (Density_gas < temp_density) - b = temp_density; - if (Density_gas > temp_density) - a = temp_density; - } + V0 = vapor.volume + liquid.volume; + CO2_H2O_NaCl_VLE_isobaric(T, P, vapor, liquid, solid, f); + V = vapor.volume + liquid.volume; - if (Density_gas < 0) - { - cout << "Density calculation of gas was not possible" << - "\n"; - system("Pause"); - exit(0); - } - //set new density to nodes - variable_index = m_pcs->GetNodeValueIndex("DENSITY2"); - m_pcs->SetNodeValue(i, variable_index, Density_gas); - //set new viscosity to nodes - variable_index = m_pcs->GetNodeValueIndex("VISCOSITY2"); - Viscosity_gas = 5.5e-5; - m_pcs->SetNodeValue(i, variable_index, Viscosity_gas); - } + // cout << " V input " << V << "\n"; - //cout << " node: " << i << " Dichte_Wasser: " << Density_liquid << " Dichte_Gas: " << Density_gas << "\n"; - } - finish = clock(); - time = (double(finish) - double(start)) / CLOCKS_PER_SEC; + if (abs(V - V0) < err) + return; + else if (V > V0) + { + P1 = P; + P2 = 5.0 * P; // P2=5.0*P; + } + else if (V < V0) + { + P1 = 0.2 * P; // P1=0.2*P; + P2 = P; + } - cout << " Calculating Density and Viscosity " << time << " seconds." << "\n"; - cout << "\n"; + for (i = 0; i < i_max; i++) + { + P = 0.5 * (P1 + P2); + CO2_H2O_NaCl_VLE_isobaric(T, P, vapor, liquid, solid, f); + V = vapor.volume + liquid.volume; + // cout << P << " " << V << "\n"; + if (abs(V0 - V) < err) + break; + else if (V < V0) + P2 = P; + else if (V > V0) + P1 = P; } +} //------------------------------------------------------------------------- -//GeoSys - Function: Phase_Transition_CO2 -//Task: Calculations Phasetransition for CO2 between gas and liquid phase, calls a DLL -//Return: nothing -//Programming: 11/2010 BG, NB -//Modification: +// GeoSys - Function: CalculateFluidDensitiesAndViscositiesAtNodes +// Task: Calculates density and viscosity of a multiphase flow system +// Return: nothing +// Programming: 11/2010 BG, NB +// Modification: //------------------------------------------------------------------------- - void CRFProcess::Phase_Transition_CO2(CRFProcess* m_pcs, int Step) - { - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt - MeshLib::CElem* m_ele = NULL; - MeshLib::CNode* m_node = NULL; - double saturation_gas, saturation_liquid; - double Molweight_CO2, Molweight_H2O, Molweight_NaCl; - // ,Density_liquid_old, Density_purewater, Density_pureCO2; unused - double Volume_eff, Density_gas, Density_liquid, p_cap; - // , c_CO2inLiquid_old; unused - double c_H2OinLiquid, c_CO2inLiquid, c_NaClinLiquid, c_H2OinGas, c_CO2inGas; - //double b_CO2inPureWater, b_NaClinPureWater, b_H2OinPureCO2; - // double mass_gas, mass_liquid; unused - double saturation_gas_min, saturation_liquid_min, saturation_gas_effective, - saturation_liquid_effective; - double porosity, node_volume; - int variable_index, indexProcess; - CMediumProperties* MediaProp; - CFluidProperties* FluidProp; - Phase_Properties gas; - Phase_Properties liquid; - Phase_Properties solid; - CRFProcess* pcs_MassTransport; - int MassTransportID[6] = {0,0,0,0,0,0}; - int MaterialGroup = 0; - int TimeStepVariableIndex = 1; - // double c_oldCO2inLiquid; unused - //WW double p_cap_1, pressure_1; +void CRFProcess::CalculateFluidDensitiesAndViscositiesAtNodes(CRFProcess* m_pcs) +{ + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt + MeshLib::CElem* m_ele = NULL; + MeshLib::CNode* m_node = NULL; + double saturation_gas, saturation_liquid; + double Molweight_CO2, Molweight_H2O, Molweight_NaCl; + double Density_gas = 0, Density_liquid = 0, Density_pureCO2, Viscosity_liquid, Viscosity_gas; + // ,c_H2OinLiquid; unused + double c_CO2inLiquid, c_NaClinLiquid, c_H2OinGas; + double b_CO2inPureWater, b_NaClinPureWater; // WW, b_H2OinPureCO2; + double mass_gas; + // ,Volume_eff; unused + // WW double volume_liquid, + double volume_gas, node_volume, porosity; + // ,saturation_liquid_effective ,saturation_gas_effective; unused + // WW double saturation_gas_min, saturation_liquid_min; + int variable_index, indexProcess; + CMediumProperties* MediaProp; + CFluidProperties* FluidProp; + CRFProcess* pcs_MassTransport; + double pressure, temperature; + int MassTransportID[5] = {0, 0, 0, 0, 0}; + int MaterialGroup = 0; + int TimeStepVariableIndex = 1; + clock_t start, finish; + double time; + double a, b, temp_density; // unit: [kg/m³] + double wCO2, wNaCl, wH2O; // unit: [kg/kg] + double epsilon = 1e-2; + int iter_max = 100; - //--------------------------------------------------------------------------------------------------------- - //Data preprocessing + start = clock(); + + // for initial conditions variable index is the first index, for other timesteps variable index is the second index + if (m_pcs->Tim->step_current == 1) + TimeStepVariableIndex = 0; + else + TimeStepVariableIndex = 1; - //for initial conditions variable index is the first index, for other timesteps variable index is the second index - if (m_pcs->Tim->step_current == 1) - TimeStepVariableIndex = 0; + Molweight_CO2 = 44.009; // [g/mol] + Molweight_H2O = 18.0148; // [g/mol] + Molweight_NaCl = 58.443; // [g/mol] //ToDo: provide constants once in the whole project - Molweight_CO2 = 44.009; // [g/mol] - Molweight_H2O = 18.0148; // [g/mol] - Molweight_NaCl = 58.443; // [g/mol] //ToDo: provide constants once in the whole project + // WW saturation_gas_min = 0.00001; + // WW saturation_liquid_min = 0.00001; - saturation_gas_min = 0.00001; - saturation_liquid_min = 0.00001; + for (long i = 0; i < (long)m_msh->nod_vector.size(); i++) + { + m_node = m_msh->nod_vector[i]; // get element + node_volume = 0; - for (long i = 0; i < (long)m_msh->nod_vector.size(); i++) + // calculate Porevolume for the node based on connected elements + for (size_t j = 0; j < m_node->getConnectedElementIDs().size(); j++) { - if (i == 230) - cout << i << "\n"; - m_node = m_msh->nod_vector[i]; // get element - node_volume = 0; - //calculate Porevolume for the node based on connected elements - for (size_t j = 0; j < m_node->getConnectedElementIDs().size(); j++) - { - m_ele = m_msh->ele_vector[m_node->getConnectedElementIDs()[j]]; - MaterialGroup = m_ele->GetPatchIndex(); - MediaProp = mmp_vector[MaterialGroup]; - porosity = MediaProp->Porosity( - m_ele->GetIndex(), m_pcs->m_num->ls_theta); - // ToDo: Correct calculation of node volume - node_volume = node_volume + m_ele->GetVolume() / - m_ele->GetNodesNumber(false) * porosity; - } + m_ele = m_msh->ele_vector[m_node->getConnectedElementIDs()[j]]; + MaterialGroup = m_ele->GetPatchIndex(); + MediaProp = mmp_vector[MaterialGroup]; + porosity = MediaProp->Porosity(m_ele->GetIndex(), m_pcs->m_num->ls_theta); + // ToDo: Correct calculation of node volume + node_volume = node_volume + m_ele->GetVolume() / m_ele->GetNodesNumber(false) * porosity; + } - //get pressure, temperature and saturations - //+1... new time level - variable_index = m_pcs->GetNodeValueIndex("PRESSURE1") + 1; - p_cap = m_pcs->GetNodeValue(i, variable_index); - //+1... new time level - variable_index = m_pcs->GetNodeValueIndex("PRESSURE1"); - //WW p_cap_1 = m_pcs->GetNodeValue(i, variable_index); - //+1... new time level - variable_index = m_pcs->GetNodeValueIndex("PRESSURE2") + 1; - // unit: bar!!! Assuming that the non wetting phase pressure is the correct one - gas.pressure = liquid.pressure = solid.pressure = m_pcs->GetNodeValue( - i, - variable_index) - / 1e5; + // get pressure, temperature and saturations + //+1... new time level + variable_index = m_pcs->GetNodeValueIndex("PRESSURE2") + TimeStepVariableIndex; + // unit: bar!!! Assuming that the non wetting phase pressure is the correct one + pressure = m_pcs->GetNodeValue(i, variable_index) / 1e5; + if (!T_Process) + { + // Get reference temperature if no heat transport is used + FluidProp = MFPGet("LIQUID"); + temperature = FluidProp->getReferenceTemperature(); + } + else + { + CRFProcess* HeatProcess = PCSGet("HEAT_TRANSPORT"); //+1... new time level - variable_index = m_pcs->GetNodeValueIndex("PRESSURE2"); - //WW pressure_1 = m_pcs->GetNodeValue(i, variable_index) / 1e5; - if(!T_Process) - { - // Get reference temperature if no heat transport is used - FluidProp = MFPGet("LIQUID"); - gas.temperature = liquid.temperature = solid.temperature = - FluidProp->getReferenceTemperature(); + variable_index = HeatProcess->GetNodeValueIndex("TEMPERATURE1") + TimeStepVariableIndex; + temperature = m_pcs->GetNodeValue(i, variable_index); + } + //+1... new time level + variable_index = m_pcs->GetNodeValueIndex("SATURATION1") + TimeStepVariableIndex; + saturation_liquid = m_pcs->GetNodeValue(i, variable_index); + saturation_gas = 1 - saturation_liquid; + + // calculate liquid and gas volume from saturation + // Volume_eff = node_volume * (1 - saturation_gas_min - saturation_liquid_min); //[m³] + //[m³] + // WW volume_liquid = node_volume * saturation_liquid; + volume_gas = node_volume * saturation_gas; + + // get ID's of mass transport processes + for (int j = 0; j < int(pcs_vector.size()); j++) + { + pcs_MassTransport = pcs_vector[j]; + if (pcs_MassTransport->nod_val_name_vector[0] == "H2O") + MassTransportID[0] = j; + if ((pcs_MassTransport->nod_val_name_vector[0] == "C(4)") + || (pcs_MassTransport->nod_val_name_vector[0] == "CO2")) // "CO2_w" CB + MassTransportID[1] = j; + if (pcs_MassTransport->nod_val_name_vector[0] == "NaCl") + MassTransportID[2] = j; + if (pcs_MassTransport->nod_val_name_vector[0] == "CO2") + MassTransportID[3] = j; + if (pcs_MassTransport->nod_val_name_vector[0] == "H2O_gas") + MassTransportID[4] = j; + } + + // Read CO2 concentration in water and calculate moles of CO2 in liquid phase + indexProcess = MassTransportID[1]; + // +1: new timelevel + variable_index + = pcs_vector[indexProcess]->GetNodeValueIndex(pcs_vector[indexProcess]->pcs_primary_function_name[0]) + + TimeStepVariableIndex; + //[mol/m³] + c_CO2inLiquid = pcs_vector[indexProcess]->GetNodeValue(i, variable_index); + + // Read NaCl concentration in water and calculate moles of NaCl in liquid phase + indexProcess = MassTransportID[2]; + // +1: new timelevel + variable_index + = pcs_vector[indexProcess]->GetNodeValueIndex(pcs_vector[indexProcess]->pcs_primary_function_name[0]) + + TimeStepVariableIndex; + //[mol/m³] + c_NaClinLiquid = pcs_vector[indexProcess]->GetNodeValue(i, variable_index); + + if (saturation_liquid > 0) + { + // Determine moles of water in liquid phase + // calculate liquid density for initial conditions + // estimate density -> calculate moles of components -> calculate real density -> compare with estimation -> + // loop until similar values + a = 800; // estimated range of valid density [kg/m³] + b = 1800; + for (int j = 0; j < iter_max; j++) + { + temp_density = (a + b) / 2.0; + // mass fraction of kg CO2 per kg liquid (mol/m³ * m³/kg * g/mol / 1000) = kg/kg + wCO2 = c_CO2inLiquid / temp_density * Molweight_CO2 / 1000; + // mass fraction of kg NaCl per kg liquid (mol/m³ * m³/kg * g/mol / 1000) = kg/kg + wNaCl = c_NaClinLiquid / temp_density * Molweight_NaCl / 1000; + wH2O = 1 - wCO2 - wNaCl; // mass fraction of kg H2O per kg liquid + // Molality = concentration in mol per kg of solution / mass fraction of solvent = mol per kg solvent + // Molality of CO2 in mol per kg pure water (mol/m³ * m³/kg) = mol/kg + b_CO2inPureWater = c_CO2inLiquid / temp_density * 1 / wH2O; + // Molality of NaCl in mol per kg pure water (mol/m³ * m³/kg) = mol/kg + b_NaClinPureWater = c_NaClinLiquid / temp_density * 1 / wH2O; + // new estimate of density of brine with estimated concentration of CO2 and NaCl in mol per kg pure + // water + // function provides g/cm³ -> Density_liquid [kg/m³] + Density_liquid = 1000 * density::CO2brine(temperature, pressure, b_NaClinPureWater, b_CO2inPureWater); + // cout.precision(8); + // cout << "Iteration: " << j << " estimated: " << temp_density << " calculated: " << Density_liquid << + // " a: " << a << " b: " << b << "\n"; + // compare density with density estimation + if (Density_liquid < 0) + break; + if (fabs(Density_liquid - temp_density) < epsilon) + break; + else if (Density_liquid < temp_density) + b = temp_density; + else if (Density_liquid > temp_density) + a = temp_density; } - else + // if (i == 230) + // cout << i << "\n"; + + if (Density_liquid < 0) { - CRFProcess* HeatProcess = PCSGet("HEAT_TRANSPORT"); - //+1... new time level - variable_index = HeatProcess->GetNodeValueIndex("TEMPERATURE1") + 1; - gas.temperature = liquid.temperature = solid.temperature = - m_pcs->GetNodeValue( - i, - variable_index); + cout << "Density calculation of water was not possible" + << "\n"; + system("Pause"); + exit(0); } - //+1... new time level - variable_index = m_pcs->GetNodeValueIndex("SATURATION1"); - saturation_liquid = m_pcs->GetNodeValue(i, variable_index); - saturation_gas = 1 - saturation_liquid; - // calculate new effective saturation that sum up to 1 - saturation_liquid_effective = - (saturation_liquid - - saturation_liquid_min) / - ( 1 - saturation_liquid_min - saturation_gas_min); - saturation_gas_effective = - (saturation_gas - - saturation_gas_min) / - ( 1 - saturation_liquid_min - saturation_gas_min); - if (saturation_liquid_effective < 1e-10) - { - saturation_liquid_effective = 0; - saturation_gas_effective = 1; - } - if (saturation_gas_effective < 1e-10) - { - saturation_gas_effective = 0; - saturation_liquid_effective = 1; - } - - //calculate liquid and gas volume from saturation - //[m³] - Volume_eff = node_volume * (1 - saturation_gas_min - saturation_liquid_min); - //[m³] - liquid.volume = Volume_eff * saturation_liquid_effective; - //[m³] - gas.volume = Volume_eff * saturation_gas_effective; - - //cout << "node: " << i << " p_cap: " << p_cap << " P2: " << gas.pressure << " sat_liquid: " << saturation_liquid << " sat_gas: " << saturation_gas << " V_liquid: " << liquid.volume << " V_gas: " << gas.volume << "\n"; - - //get ID's of mass transport processes - for(int j = 0; j < int(pcs_vector.size()); j++) - { - pcs_MassTransport = pcs_vector[j]; - if (pcs_MassTransport->nod_val_name_vector[0] == "H2O") - MassTransportID[0] = j; - if ((pcs_MassTransport->nod_val_name_vector[0] == "C(4)") || - (pcs_MassTransport->nod_val_name_vector[0] == "CO2")) // "CO2_w" CB - MassTransportID[1] = j; - if (pcs_MassTransport->nod_val_name_vector[0] == "NaCl") - MassTransportID[2] = j; - if (pcs_MassTransport->nod_val_name_vector[0] == "CO2") - MassTransportID[3] = j; - if (pcs_MassTransport->nod_val_name_vector[0] == "H2O_gas") - MassTransportID[4] = j; - if (pcs_MassTransport->nod_val_name_vector[0] == "oldC(4)") - MassTransportID[5] = j; - } - //get concentration of phase components and calculate moles of components per phase - //Read CO2 concentration in water and calculate moles of CO2 in liquid phase - indexProcess = MassTransportID[1]; - solid.CO2 = 0; - // +1: new timelevel - variable_index = - pcs_vector[indexProcess]->GetNodeValueIndex( - pcs_vector[indexProcess]->pcs_primary_function_name[0]) + - TimeStepVariableIndex; - //[mol/m³] - c_CO2inLiquid = pcs_vector[indexProcess]->GetNodeValue(i, variable_index); - liquid.CO2 = c_CO2inLiquid * liquid.volume; //[mol] = mol/m³ * m³ - - //Read NaCl concentration in water and calculate moles of NaCl in liquid phase - indexProcess = MassTransportID[2]; - gas.NaCl = 0; - solid.NaCl = 0; - // +1: new timelevel - variable_index = - pcs_vector[indexProcess]->GetNodeValueIndex( - pcs_vector[indexProcess]->pcs_primary_function_name[0]) + - TimeStepVariableIndex; - //[mol/m³] - c_NaClinLiquid = pcs_vector[indexProcess]->GetNodeValue(i, variable_index); - //[mol] = mol/m³ * m³ - liquid.NaCl = c_NaClinLiquid * liquid.volume; + // calculate new moles of H2O + // c_H2OinLiquid = (Density_liquid - c_CO2inLiquid * Molweight_CO2 * 1e-3 - c_NaClinLiquid * Molweight_NaCl + // * 1e-3) / (Molweight_H2O * 1e-3); //[mol] + // indexProcess = MassTransportID[0]; //H2O in liquid + // variable_index = + // pcs_vector[indexProcess]->GetNodeValueIndex(pcs_vector[indexProcess]->pcs_primary_function_name[0]) + 1; + // // +1: new timelevel + // pcs_vector[indexProcess]->SetNodeValue(i, variable_index, c_H2OinLiquid); - //Determine moles of water in liquid phase - // get liquid density from the last step - solid.H2O = 0; - //+1... new time level + // set new density to nodes variable_index = m_pcs->GetNodeValueIndex("DENSITY1"); - // [kg/m³] - Density_liquid = m_pcs->GetNodeValue(i, variable_index); - - // Test 1: Berechnung T_H2O aus alter Dichte und alter CO2-Konz, - //variable_index = m_pcs->GetNodeValueIndex("DENSITY1_old"); //+1... new time level - //if (m_pcs->Tim->step_current == 1) - // Density_liquid_old = Density_liquid; - //else - // Density_liquid_old = m_pcs->GetNodeValue(i, variable_index); // [kg/m³ - ////set new Density as old value - //m_pcs->SetNodeValue(i, variable_index, Density_liquid); - // - //indexProcess = MassTransportID[5]; - //variable_index = pcs_vector[indexProcess]->GetNodeValueIndex(pcs_vector[indexProcess]->pcs_primary_function_name[0]) + TimeStepVariableIndex; // +1: new timelevel - //c_CO2inLiquid_old = pcs_vector[indexProcess]->GetNodeValue(i, variable_index); //[mol/m³] - //if (i == 230) - // cout << i << "\n"; - //liquid.H2O = (Density_liquid_old * liquid.volume - c_CO2inLiquid_old * liquid.volume * Molweight_CO2 * 1e-3 - liquid.NaCl * Molweight_NaCl * 1e-3 ) / (Molweight_H2O * 1e-3); //[mol] - - if (i == 230) - cout << i << "\n"; - - // Test 2: - if (Step == 1) - { - // phase transition after reactions -> use old liquid.H2O because no phase movement - indexProcess = MassTransportID[0]; - // +1: new timelevel - variable_index = pcs_vector[indexProcess]->GetNodeValueIndex( - pcs_vector[indexProcess]->pcs_primary_function_name[0]) + 1; - //[mol/m³] - c_H2OinLiquid = pcs_vector[indexProcess]->GetNodeValue( - i, - variable_index); - //[mol] = mol/m³ * m³ - liquid.H2O = c_H2OinLiquid * liquid.volume; - } - else - // calculate new liquid.H2O after multiphase flow calculation based on new pressure, new density because of this new pressure, new phase saturations - //[mol] - liquid.H2O = - (Density_liquid * liquid.volume - liquid.CO2 * - Molweight_CO2 * - 1e-3 - liquid.NaCl * Molweight_NaCl * - 1e-3 ) / (Molweight_H2O * 1e-3); - - //if (m_pcs->Tim->step_current == 1) - //liquid.H2O = (Density_liquid * liquid.volume - liquid.CO2 * Molweight_CO2 * 1e-3 - liquid.NaCl * Molweight_NaCl * 1e-3 ) / (Molweight_H2O * 1e-3); //[mol] - //else { - //indexProcess = MassTransportID[0]; - //variable_index = pcs_vector[indexProcess]->GetNodeValueIndex(pcs_vector[indexProcess]->pcs_primary_function_name[0]) + 1; // +1: new timelevel - //c_H2OinLiquid = pcs_vector[indexProcess]->GetNodeValue(i, variable_index); //[mol/m³] - //liquid.H2O = c_H2OinLiquid * liquid.volume; //[mol] = mol/m³ * m³ - //} + m_pcs->SetNodeValue(i, variable_index, Density_liquid); + + // set new viscosity to nodes + variable_index = m_pcs->GetNodeValueIndex("VISCOSITY1"); + Viscosity_liquid = 5.1e-4; + m_pcs->SetNodeValue(i, variable_index, Viscosity_liquid); + } - //components in gas - //Read H2O concentration in gas and calculate moles of H2O in gas phase + if (saturation_gas > 0) + { + // components in gas + // Read H2O concentration in gas and calculate moles of H2O in gas phase indexProcess = MassTransportID[4]; // +1: new timelevel - variable_index = - pcs_vector[indexProcess]->GetNodeValueIndex( - pcs_vector[indexProcess]->pcs_primary_function_name[0]) + - TimeStepVariableIndex; + variable_index + = pcs_vector[indexProcess]->GetNodeValueIndex(pcs_vector[indexProcess]->pcs_primary_function_name[0]) + + TimeStepVariableIndex; //[mol/m³] c_H2OinGas = pcs_vector[indexProcess]->GetNodeValue(i, variable_index); - gas.H2O = c_H2OinGas * gas.volume; //[mol] = mol/m³ * m³ - //Determine moles of CO2 in gas phase - // get gas density from the last step - //+1... new time level - variable_index = m_pcs->GetNodeValueIndex("DENSITY2"); - //[kg/m³] - Density_gas = m_pcs->GetNodeValue(i, variable_index); - - // Test 2: - if (Step == 1) - { - // phase transition after reactions -> use old liquid.H2O because no phase movement - indexProcess = MassTransportID[3]; - // +1: new timelevel - variable_index = pcs_vector[indexProcess]->GetNodeValueIndex( - pcs_vector[indexProcess]->pcs_primary_function_name[0]) + 1; - //[mol/m³] - c_CO2inGas = pcs_vector[indexProcess]->GetNodeValue(i, - variable_index); - gas.CO2 = c_CO2inGas * gas.volume; //[mol] = mol/m³ * m³ + // calculate gas density for initial conditions + a = 0.1; // estimated range of valid gas density [kg/m³] + b = 1000; + epsilon = 1e-3; + iter_max = 100; + for (int j = 0; j < iter_max; j++) + { + temp_density = (a + b) / 2.0; + // mass fraction of kg H2O per kg gas (mol/m³ * m³/kg * g/mol / 1000) = kg/kg + wH2O = c_H2OinGas / temp_density * Molweight_H2O / 1000; + wCO2 = 1 - wH2O; // mass fraction of kg CO2 per kg gas + // Molality of H2O in pure CO2 (mol/m³ * m³/kg) = mol/kg) + // WW b_H2OinPureCO2 = c_H2OinGas / temp_density * 1 / wCO2; + // new estimate of density of brine with estimated concentration of CO2 and NaCl in mol per kg pure + // water + Density_pureCO2 = 1000 * VLE::density_CO2(temperature, pressure); + Density_gas = Density_pureCO2; + + // Using Norberts EOS, uses mole fractions of components, temperature and pressure [Pa] + double m_CO2, m_H2O; // mass [kg] + double n_CO2, n_H2O; // [mol] + double x_CO2; // WW, x_H2O; // mole fraction [mol/mol] + mass_gas = volume_gas * Density_gas; // mass of gas phase [kg] = m³ * kg/m³ + m_CO2 = mass_gas * wCO2; // mas of CO2 [kg] = kg * kg/kg + m_H2O = mass_gas * wH2O; // mass of H2O [kg] = kg * kg/kg + n_CO2 = m_CO2 * Molweight_CO2 / 1000; // moles of CO2 [mol] = kg * g/mol / 1000 g/kg + n_H2O = m_H2O * Molweight_H2O / 1000; // moles of H2O [mol] = kg * g/mol / 1000 g/kg + x_CO2 = n_CO2 / (n_CO2 + n_H2O); // mole fraction of CO2 [mol/mol] + // WW x_H2O = n_H2O / (n_CO2 + n_H2O); // mole fraction of H2O [mol/mol] + // ToDo: reorganisation of the code [kg/m³] + Density_gas = DuansMixingRule(temperature, pressure * 1e5, x_CO2, 0, 1, 0); + // cout.precision(8); + // cout << "Iteration: " << j << " estimated: " << temp_density << " calculated: " << Density_gas << " + // a: " << a << " b: " << b << "\n"; + + // compare density with density estimation + if (Density_gas < 0) + break; + if (fabs(Density_gas - temp_density) < epsilon) + break; + if (Density_gas < temp_density) + b = temp_density; + if (Density_gas > temp_density) + a = temp_density; } - else - // calculate new liquid.H2O after multiphase flow calculation based on new pressure, new density because of this new pressure, new phase saturations - // [mol] = kg / (kg / mol) - gas.CO2 = - (Density_gas * gas.volume - gas.H2O * Molweight_H2O * - 1e-3) / (Molweight_CO2 * 1e-3); - - //--------------------------------------------------------------------------------------------------------- - //Calculating phase transition with Dedong's method - - //recalculate units - // kg/m³ -> g/cm³ - gas.density /= 1000; - liquid.density /= 1000; - solid.density /= 1000; - // m³ -> cm³ - gas.volume *= 1e6; - liquid.volume *= 1e6; - solid.volume *= 1e6; - // kg -> g - gas.mass *= 1000; - liquid.mass *= 1000; - solid.mass *= 1000; - - if (m_pcs->Tim->step_current == 14) - cout << i << "\n"; - - if (i == 230) - cout << i << " gas pressure: " << gas.pressure << - " liquid pressure: " << liquid.pressure << "\n"; - - //call Dedongs method to calculate CO2 phase transition - CO2_H2O_NaCl_VLE_isochoric(gas, liquid, solid, 1); - - if (i == 230) - cout << i << " gas pressure: " << gas.pressure << - " liquid pressure: " << liquid.pressure << "\n"; - - // g/cm³ -> kg/m³ - gas.density *= 1000; - liquid.density *= 1000; - solid.density *= 1000; - // cm³ -> m³ - gas.volume /= 1e6; - liquid.volume /= 1e6; - solid.volume /= 1e6; - // g -> kg - gas.mass /= 1000; - liquid.mass /= 1000; - solid.mass /= 1000; - // bar -> Pa - gas.pressure *= 1e5; - liquid.pressure *= 1e5; - solid.pressure *= 1e5; - - //--------------------------------------------------------------------------------------------------------- - //Postprocessing of results to recalculate volume, pressure, saturation - - //calculate saturation of phases - //double error = fabs((gas.volume + liquid.volume) - Volume_eff); - //error = error / Volume_eff; - if (fabs((gas.volume + liquid.volume) - Volume_eff) / Volume_eff > 1e-3) - { - cout << - "The volume is not equal before and after the calculation of CO2 phase transition! " + + if (Density_gas < 0) + { + cout << "Density calculation of gas was not possible" << "\n"; - cout << "Before: " << Volume_eff << " After: " << gas.volume + - liquid.volume << "\n"; system("Pause"); exit(0); } + // set new density to nodes + variable_index = m_pcs->GetNodeValueIndex("DENSITY2"); + m_pcs->SetNodeValue(i, variable_index, Density_gas); + // set new viscosity to nodes + variable_index = m_pcs->GetNodeValueIndex("VISCOSITY2"); + Viscosity_gas = 5.5e-5; + m_pcs->SetNodeValue(i, variable_index, Viscosity_gas); + } - //set new densities to nodes - if (liquid.density >= 0) - { - variable_index = m_pcs->GetNodeValueIndex("DENSITY1"); - m_pcs->SetNodeValue(i, variable_index, liquid.density); - } - if (gas.density >= 0) - { - variable_index = m_pcs->GetNodeValueIndex("DENSITY2"); - m_pcs->SetNodeValue(i, variable_index, gas.density); - } + // cout << " node: " << i << " Dichte_Wasser: " << Density_liquid << " Dichte_Gas: " << Density_gas << "\n"; + } + finish = clock(); + time = (double(finish) - double(start)) / CLOCKS_PER_SEC; - //set new viscosities to nodes - if (liquid.viscosity >= 0) - { - variable_index = m_pcs->GetNodeValueIndex("VISCOSITY1"); - m_pcs->SetNodeValue(i, variable_index, liquid.viscosity); - } - if (gas.viscosity >= 0) - { - variable_index = m_pcs->GetNodeValueIndex("VISCOSITY2"); - m_pcs->SetNodeValue(i, variable_index, gas.viscosity); - } + cout << " Calculating Density and Viscosity " << time << " seconds." + << "\n"; + cout << "\n"; +} - // ToDo: check calculation - saturation_gas = max(gas.volume / Volume_eff, saturation_gas_min); - //saturation_liquid = max(liquid.volume / Volume_eff, saturation_liquid_min); - saturation_liquid = max(1 - saturation_gas, saturation_liquid_min); +//------------------------------------------------------------------------- +// GeoSys - Function: Phase_Transition_CO2 +// Task: Calculations Phasetransition for CO2 between gas and liquid phase, calls a DLL +// Return: nothing +// Programming: 11/2010 BG, NB +// Modification: +//------------------------------------------------------------------------- +void CRFProcess::Phase_Transition_CO2(CRFProcess* m_pcs, int Step) +{ + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt + MeshLib::CElem* m_ele = NULL; + MeshLib::CNode* m_node = NULL; + double saturation_gas, saturation_liquid; + double Molweight_CO2, Molweight_H2O, Molweight_NaCl; + // ,Density_liquid_old, Density_purewater, Density_pureCO2; unused + double Volume_eff, Density_gas, Density_liquid, p_cap; + // , c_CO2inLiquid_old; unused + double c_H2OinLiquid, c_CO2inLiquid, c_NaClinLiquid, c_H2OinGas, c_CO2inGas; + // double b_CO2inPureWater, b_NaClinPureWater, b_H2OinPureCO2; + // double mass_gas, mass_liquid; unused + double saturation_gas_min, saturation_liquid_min, saturation_gas_effective, saturation_liquid_effective; + double porosity, node_volume; + int variable_index, indexProcess; + CMediumProperties* MediaProp; + CFluidProperties* FluidProp; + Phase_Properties gas; + Phase_Properties liquid; + Phase_Properties solid; + CRFProcess* pcs_MassTransport; + int MassTransportID[6] = {0, 0, 0, 0, 0, 0}; + int MaterialGroup = 0; + int TimeStepVariableIndex = 1; + // double c_oldCO2inLiquid; unused + // WW double p_cap_1, pressure_1; + + //--------------------------------------------------------------------------------------------------------- + // Data preprocessing + + // for initial conditions variable index is the first index, for other timesteps variable index is the second index + if (m_pcs->Tim->step_current == 1) + TimeStepVariableIndex = 0; + + Molweight_CO2 = 44.009; // [g/mol] + Molweight_H2O = 18.0148; // [g/mol] + Molweight_NaCl = 58.443; // [g/mol] //ToDo: provide constants once in the whole project + + saturation_gas_min = 0.00001; + saturation_liquid_min = 0.00001; + + for (long i = 0; i < (long)m_msh->nod_vector.size(); i++) + { + if (i == 230) + cout << i << "\n"; + m_node = m_msh->nod_vector[i]; // get element + node_volume = 0; + // calculate Porevolume for the node based on connected elements + for (size_t j = 0; j < m_node->getConnectedElementIDs().size(); j++) + { + m_ele = m_msh->ele_vector[m_node->getConnectedElementIDs()[j]]; + MaterialGroup = m_ele->GetPatchIndex(); + MediaProp = mmp_vector[MaterialGroup]; + porosity = MediaProp->Porosity(m_ele->GetIndex(), m_pcs->m_num->ls_theta); + // ToDo: Correct calculation of node volume + node_volume = node_volume + m_ele->GetVolume() / m_ele->GetNodesNumber(false) * porosity; + } + + // get pressure, temperature and saturations + //+1... new time level + variable_index = m_pcs->GetNodeValueIndex("PRESSURE1") + 1; + p_cap = m_pcs->GetNodeValue(i, variable_index); + //+1... new time level + variable_index = m_pcs->GetNodeValueIndex("PRESSURE1"); + // WW p_cap_1 = m_pcs->GetNodeValue(i, variable_index); + //+1... new time level + variable_index = m_pcs->GetNodeValueIndex("PRESSURE2") + 1; + // unit: bar!!! Assuming that the non wetting phase pressure is the correct one + gas.pressure = liquid.pressure = solid.pressure = m_pcs->GetNodeValue(i, variable_index) / 1e5; + //+1... new time level + variable_index = m_pcs->GetNodeValueIndex("PRESSURE2"); + // WW pressure_1 = m_pcs->GetNodeValue(i, variable_index) / 1e5; + if (!T_Process) + { + // Get reference temperature if no heat transport is used + FluidProp = MFPGet("LIQUID"); + gas.temperature = liquid.temperature = solid.temperature = FluidProp->getReferenceTemperature(); + } + else + { + CRFProcess* HeatProcess = PCSGet("HEAT_TRANSPORT"); + //+1... new time level + variable_index = HeatProcess->GetNodeValueIndex("TEMPERATURE1") + 1; + gas.temperature = liquid.temperature = solid.temperature = m_pcs->GetNodeValue(i, variable_index); + } + //+1... new time level + variable_index = m_pcs->GetNodeValueIndex("SATURATION1"); + saturation_liquid = m_pcs->GetNodeValue(i, variable_index); + saturation_gas = 1 - saturation_liquid; + // calculate new effective saturation that sum up to 1 + saturation_liquid_effective + = (saturation_liquid - saturation_liquid_min) / (1 - saturation_liquid_min - saturation_gas_min); + saturation_gas_effective + = (saturation_gas - saturation_gas_min) / (1 - saturation_liquid_min - saturation_gas_min); + if (saturation_liquid_effective < 1e-10) + { + saturation_liquid_effective = 0; + saturation_gas_effective = 1; + } + if (saturation_gas_effective < 1e-10) + { + saturation_gas_effective = 0; + saturation_liquid_effective = 1; + } + + // calculate liquid and gas volume from saturation + //[m³] + Volume_eff = node_volume * (1 - saturation_gas_min - saturation_liquid_min); + //[m³] + liquid.volume = Volume_eff * saturation_liquid_effective; + //[m³] + gas.volume = Volume_eff * saturation_gas_effective; + + // cout << "node: " << i << " p_cap: " << p_cap << " P2: " << gas.pressure << " sat_liquid: " << + // saturation_liquid << " sat_gas: " << saturation_gas << " V_liquid: " << liquid.volume << " V_gas: " << + // gas.volume << "\n"; + + // get ID's of mass transport processes + for (int j = 0; j < int(pcs_vector.size()); j++) + { + pcs_MassTransport = pcs_vector[j]; + if (pcs_MassTransport->nod_val_name_vector[0] == "H2O") + MassTransportID[0] = j; + if ((pcs_MassTransport->nod_val_name_vector[0] == "C(4)") + || (pcs_MassTransport->nod_val_name_vector[0] == "CO2")) // "CO2_w" CB + MassTransportID[1] = j; + if (pcs_MassTransport->nod_val_name_vector[0] == "NaCl") + MassTransportID[2] = j; + if (pcs_MassTransport->nod_val_name_vector[0] == "CO2") + MassTransportID[3] = j; + if (pcs_MassTransport->nod_val_name_vector[0] == "H2O_gas") + MassTransportID[4] = j; + if (pcs_MassTransport->nod_val_name_vector[0] == "oldC(4)") + MassTransportID[5] = j; + } + // get concentration of phase components and calculate moles of components per phase + // Read CO2 concentration in water and calculate moles of CO2 in liquid phase + indexProcess = MassTransportID[1]; + solid.CO2 = 0; + // +1: new timelevel + variable_index + = pcs_vector[indexProcess]->GetNodeValueIndex(pcs_vector[indexProcess]->pcs_primary_function_name[0]) + + TimeStepVariableIndex; + //[mol/m³] + c_CO2inLiquid = pcs_vector[indexProcess]->GetNodeValue(i, variable_index); + liquid.CO2 = c_CO2inLiquid * liquid.volume; //[mol] = mol/m³ * m³ + + // Read NaCl concentration in water and calculate moles of NaCl in liquid phase + indexProcess = MassTransportID[2]; + gas.NaCl = 0; + solid.NaCl = 0; + // +1: new timelevel + variable_index + = pcs_vector[indexProcess]->GetNodeValueIndex(pcs_vector[indexProcess]->pcs_primary_function_name[0]) + + TimeStepVariableIndex; + //[mol/m³] + c_NaClinLiquid = pcs_vector[indexProcess]->GetNodeValue(i, variable_index); + //[mol] = mol/m³ * m³ + liquid.NaCl = c_NaClinLiquid * liquid.volume; + + // Determine moles of water in liquid phase + // get liquid density from the last step + solid.H2O = 0; + //+1... new time level + variable_index = m_pcs->GetNodeValueIndex("DENSITY1"); + // [kg/m³] + Density_liquid = m_pcs->GetNodeValue(i, variable_index); + + // Test 1: Berechnung T_H2O aus alter Dichte und alter CO2-Konz, + // variable_index = m_pcs->GetNodeValueIndex("DENSITY1_old"); //+1... new time level + // if (m_pcs->Tim->step_current == 1) + // Density_liquid_old = Density_liquid; + // else + // Density_liquid_old = m_pcs->GetNodeValue(i, variable_index); // [kg/m³ + ////set new Density as old value + // m_pcs->SetNodeValue(i, variable_index, Density_liquid); + // + // indexProcess = MassTransportID[5]; + // variable_index = + // pcs_vector[indexProcess]->GetNodeValueIndex(pcs_vector[indexProcess]->pcs_primary_function_name[0]) + + // TimeStepVariableIndex; // +1: new timelevel + // c_CO2inLiquid_old = pcs_vector[indexProcess]->GetNodeValue(i, variable_index); //[mol/m³] + // if (i == 230) + // cout << i << "\n"; + // liquid.H2O = (Density_liquid_old * liquid.volume - c_CO2inLiquid_old * liquid.volume * Molweight_CO2 * 1e-3 + // - liquid.NaCl * Molweight_NaCl * 1e-3 ) / (Molweight_H2O * 1e-3); //[mol] + + if (i == 230) + cout << i << "\n"; + + // Test 2: + if (Step == 1) + { + // phase transition after reactions -> use old liquid.H2O because no phase movement + indexProcess = MassTransportID[0]; + // +1: new timelevel + variable_index + = pcs_vector[indexProcess]->GetNodeValueIndex(pcs_vector[indexProcess]->pcs_primary_function_name[0]) + + 1; + //[mol/m³] + c_H2OinLiquid = pcs_vector[indexProcess]->GetNodeValue(i, variable_index); + //[mol] = mol/m³ * m³ + liquid.H2O = c_H2OinLiquid * liquid.volume; + } + else + // calculate new liquid.H2O after multiphase flow calculation based on new pressure, new density because of + // this new pressure, new phase saturations + //[mol] + liquid.H2O = (Density_liquid * liquid.volume - liquid.CO2 * Molweight_CO2 * 1e-3 + - liquid.NaCl * Molweight_NaCl * 1e-3) + / (Molweight_H2O * 1e-3); + + // if (m_pcs->Tim->step_current == 1) + // liquid.H2O = (Density_liquid * liquid.volume - liquid.CO2 * Molweight_CO2 * 1e-3 - liquid.NaCl * + // Molweight_NaCl * 1e-3 ) / (Molweight_H2O * 1e-3); //[mol] + // else { + // indexProcess = MassTransportID[0]; + // variable_index = + // pcs_vector[indexProcess]->GetNodeValueIndex(pcs_vector[indexProcess]->pcs_primary_function_name[0]) + 1; // + // +1: new timelevel + // c_H2OinLiquid = pcs_vector[indexProcess]->GetNodeValue(i, variable_index); //[mol/m³] + // liquid.H2O = c_H2OinLiquid * liquid.volume; //[mol] = mol/m³ * m³ + //} + + // components in gas + // Read H2O concentration in gas and calculate moles of H2O in gas phase + indexProcess = MassTransportID[4]; + // +1: new timelevel + variable_index + = pcs_vector[indexProcess]->GetNodeValueIndex(pcs_vector[indexProcess]->pcs_primary_function_name[0]) + + TimeStepVariableIndex; + //[mol/m³] + c_H2OinGas = pcs_vector[indexProcess]->GetNodeValue(i, variable_index); + gas.H2O = c_H2OinGas * gas.volume; //[mol] = mol/m³ * m³ + + // Determine moles of CO2 in gas phase + // get gas density from the last step + //+1... new time level + variable_index = m_pcs->GetNodeValueIndex("DENSITY2"); + //[kg/m³] + Density_gas = m_pcs->GetNodeValue(i, variable_index); + + // Test 2: + if (Step == 1) + { + // phase transition after reactions -> use old liquid.H2O because no phase movement + indexProcess = MassTransportID[3]; + // +1: new timelevel + variable_index + = pcs_vector[indexProcess]->GetNodeValueIndex(pcs_vector[indexProcess]->pcs_primary_function_name[0]) + + 1; + //[mol/m³] + c_CO2inGas = pcs_vector[indexProcess]->GetNodeValue(i, variable_index); + gas.CO2 = c_CO2inGas * gas.volume; //[mol] = mol/m³ * m³ + } + else + // calculate new liquid.H2O after multiphase flow calculation based on new pressure, new density because of + // this new pressure, new phase saturations + // [mol] = kg / (kg / mol) + gas.CO2 = (Density_gas * gas.volume - gas.H2O * Molweight_H2O * 1e-3) / (Molweight_CO2 * 1e-3); - //set new saturations to nodes - if (Step == 1) - //+1... new time level - variable_index = m_pcs->GetNodeValueIndex("SATURATION1"); - else - //+1... new time level - variable_index = m_pcs->GetNodeValueIndex("SATURATION1") + 1; - m_pcs->SetNodeValue(i, variable_index, saturation_liquid); + //--------------------------------------------------------------------------------------------------------- + // Calculating phase transition with Dedong's method + + // recalculate units + // kg/m³ -> g/cm³ + gas.density /= 1000; + liquid.density /= 1000; + solid.density /= 1000; + // m³ -> cm³ + gas.volume *= 1e6; + liquid.volume *= 1e6; + solid.volume *= 1e6; + // kg -> g + gas.mass *= 1000; + liquid.mass *= 1000; + solid.mass *= 1000; + + if (m_pcs->Tim->step_current == 14) + cout << i << "\n"; + + if (i == 230) + cout << i << " gas pressure: " << gas.pressure << " liquid pressure: " << liquid.pressure << "\n"; + + // call Dedongs method to calculate CO2 phase transition + CO2_H2O_NaCl_VLE_isochoric(gas, liquid, solid, 1); + + if (i == 230) + cout << i << " gas pressure: " << gas.pressure << " liquid pressure: " << liquid.pressure << "\n"; + + // g/cm³ -> kg/m³ + gas.density *= 1000; + liquid.density *= 1000; + solid.density *= 1000; + // cm³ -> m³ + gas.volume /= 1e6; + liquid.volume /= 1e6; + solid.volume /= 1e6; + // g -> kg + gas.mass /= 1000; + liquid.mass /= 1000; + solid.mass /= 1000; + // bar -> Pa + gas.pressure *= 1e5; + liquid.pressure *= 1e5; + solid.pressure *= 1e5; - //new calculation of capillary pressue + //--------------------------------------------------------------------------------------------------------- + // Postprocessing of results to recalculate volume, pressure, saturation - //ToDo: works only for homogenouse properties - MediaProp = mmp_vector[MaterialGroup]; - p_cap = MediaProp->CapillaryPressureFunction(saturation_liquid); + // calculate saturation of phases + // double error = fabs((gas.volume + liquid.volume) - Volume_eff); + // error = error / Volume_eff; + if (fabs((gas.volume + liquid.volume) - Volume_eff) / Volume_eff > 1e-3) + { + cout << "The volume is not equal before and after the calculation of CO2 phase transition! " + << "\n"; + cout << "Before: " << Volume_eff << " After: " << gas.volume + liquid.volume << "\n"; + system("Pause"); + exit(0); + } - if (i == 230) - cout << i << " gas pressure: " << gas.pressure << - " liquid pressure: " << liquid.pressure << "\n"; + // set new densities to nodes + if (liquid.density >= 0) + { + variable_index = m_pcs->GetNodeValueIndex("DENSITY1"); + m_pcs->SetNodeValue(i, variable_index, liquid.density); + } + if (gas.density >= 0) + { + variable_index = m_pcs->GetNodeValueIndex("DENSITY2"); + m_pcs->SetNodeValue(i, variable_index, gas.density); + } - //set new pressure to nodes - if (Step == 1) - //+1... new time level - variable_index = m_pcs->GetNodeValueIndex("PRESSURE1"); - else - //+1... new time level - variable_index = m_pcs->GetNodeValueIndex("PRESSURE1") + 1; - m_pcs->SetNodeValue(i, variable_index, p_cap); - if (Step == 1) - //+1... new time level - variable_index = m_pcs->GetNodeValueIndex("PRESSURE2"); - else - //+1... new time level - variable_index = m_pcs->GetNodeValueIndex("PRESSURE2") + 1; - m_pcs->SetNodeValue(i, variable_index, gas.pressure); - //cout << "node: " << i << " p_cap: " << p_cap << " P2: " << gas.pressure << " sat_liquid: " << saturation_liquid << " sat_gas: " << saturation_gas << " V_liquid: " << liquid.volume << " V_gas: " << gas.volume << "\n"; + // set new viscosities to nodes + if (liquid.viscosity >= 0) + { + variable_index = m_pcs->GetNodeValueIndex("VISCOSITY1"); + m_pcs->SetNodeValue(i, variable_index, liquid.viscosity); + } + if (gas.viscosity >= 0) + { + variable_index = m_pcs->GetNodeValueIndex("VISCOSITY2"); + m_pcs->SetNodeValue(i, variable_index, gas.viscosity); + } - // set new component concentration - if (liquid.volume > 0) - { - //[mol/m³] = mol / m³ - c_H2OinLiquid = liquid.H2O / liquid.volume; - //[mol/L] = mol / m³ - c_CO2inLiquid = liquid.CO2 / liquid.volume; - //[mol/L] = mol / m³ - c_NaClinLiquid = liquid.NaCl / liquid.volume; - } - else - { - c_H2OinLiquid = 0; - c_CO2inLiquid = 0; - c_NaClinLiquid = 0; - } + // ToDo: check calculation + saturation_gas = max(gas.volume / Volume_eff, saturation_gas_min); + // saturation_liquid = max(liquid.volume / Volume_eff, saturation_liquid_min); + saturation_liquid = max(1 - saturation_gas, saturation_liquid_min); - indexProcess = MassTransportID[0]; //H2O in liquid - // +1: new timelevel - variable_index = - pcs_vector[indexProcess]->GetNodeValueIndex( - pcs_vector[indexProcess]->pcs_primary_function_name[0]) + 1; - pcs_vector[indexProcess]->SetNodeValue(i, variable_index, c_H2OinLiquid); + // set new saturations to nodes + if (Step == 1) + //+1... new time level + variable_index = m_pcs->GetNodeValueIndex("SATURATION1"); + else + //+1... new time level + variable_index = m_pcs->GetNodeValueIndex("SATURATION1") + 1; + m_pcs->SetNodeValue(i, variable_index, saturation_liquid); - indexProcess = MassTransportID[1]; //CO2 in liquid - // +1: new timelevel - variable_index = - pcs_vector[indexProcess]->GetNodeValueIndex( - pcs_vector[indexProcess]->pcs_primary_function_name[0]) + 1; - pcs_vector[indexProcess]->SetNodeValue(i, variable_index, c_CO2inLiquid); + // new calculation of capillary pressue - indexProcess = MassTransportID[2]; //NaCl in liquid - // +1: new timelevel - variable_index = - pcs_vector[indexProcess]->GetNodeValueIndex( - pcs_vector[indexProcess]->pcs_primary_function_name[0]) + 1; - pcs_vector[indexProcess]->SetNodeValue(i, variable_index, c_NaClinLiquid); + // ToDo: works only for homogenouse properties + MediaProp = mmp_vector[MaterialGroup]; + p_cap = MediaProp->CapillaryPressureFunction(saturation_liquid); - if (gas.volume > 0) - { - c_CO2inGas = gas.CO2 / gas.volume; //[mol/L] = mol / m³ - c_H2OinGas = gas.H2O / gas.volume; //[mol/L] = mol / m³ - } - else - { - c_CO2inGas = 0; - c_H2OinGas = 0; - } - indexProcess = MassTransportID[3]; //CO2 in gas - // +1: new timelevel - variable_index = - pcs_vector[indexProcess]->GetNodeValueIndex( - pcs_vector[indexProcess]->pcs_primary_function_name[0]) + 1; - pcs_vector[indexProcess]->SetNodeValue(i, variable_index, c_CO2inGas); + if (i == 230) + cout << i << " gas pressure: " << gas.pressure << " liquid pressure: " << liquid.pressure << "\n"; - indexProcess = MassTransportID[4]; //H2O in gas - // +1: new timelevel - variable_index = - pcs_vector[indexProcess]->GetNodeValueIndex( - pcs_vector[indexProcess]->pcs_primary_function_name[0]) + 1; - pcs_vector[indexProcess]->SetNodeValue(i, variable_index, c_H2OinGas); + // set new pressure to nodes + if (Step == 1) + //+1... new time level + variable_index = m_pcs->GetNodeValueIndex("PRESSURE1"); + else + //+1... new time level + variable_index = m_pcs->GetNodeValueIndex("PRESSURE1") + 1; + m_pcs->SetNodeValue(i, variable_index, p_cap); + if (Step == 1) + //+1... new time level + variable_index = m_pcs->GetNodeValueIndex("PRESSURE2"); + else + //+1... new time level + variable_index = m_pcs->GetNodeValueIndex("PRESSURE2") + 1; + m_pcs->SetNodeValue(i, variable_index, gas.pressure); + // cout << "node: " << i << " p_cap: " << p_cap << " P2: " << gas.pressure << " sat_liquid: " << + // saturation_liquid << " sat_gas: " << saturation_gas << " V_liquid: " << liquid.volume << " V_gas: " << + // gas.volume << "\n"; - indexProcess = MassTransportID[5]; //old CO2 in liquid - // +1: new timelevel - variable_index = - pcs_vector[indexProcess]->GetNodeValueIndex( - pcs_vector[indexProcess]->pcs_primary_function_name[0]) + 1; - pcs_vector[indexProcess]->SetNodeValue(i, variable_index, c_CO2inLiquid); + // set new component concentration + if (liquid.volume > 0) + { + //[mol/m³] = mol / m³ + c_H2OinLiquid = liquid.H2O / liquid.volume; + //[mol/L] = mol / m³ + c_CO2inLiquid = liquid.CO2 / liquid.volume; + //[mol/L] = mol / m³ + c_NaClinLiquid = liquid.NaCl / liquid.volume; } - } -//-------------------END------------------ + else + { + c_H2OinLiquid = 0; + c_CO2inLiquid = 0; + c_NaClinLiquid = 0; + } + + indexProcess = MassTransportID[0]; // H2O in liquid + // +1: new timelevel + variable_index + = pcs_vector[indexProcess]->GetNodeValueIndex(pcs_vector[indexProcess]->pcs_primary_function_name[0]) + 1; + pcs_vector[indexProcess]->SetNodeValue(i, variable_index, c_H2OinLiquid); + indexProcess = MassTransportID[1]; // CO2 in liquid + // +1: new timelevel + variable_index + = pcs_vector[indexProcess]->GetNodeValueIndex(pcs_vector[indexProcess]->pcs_primary_function_name[0]) + 1; + pcs_vector[indexProcess]->SetNodeValue(i, variable_index, c_CO2inLiquid); + indexProcess = MassTransportID[2]; // NaCl in liquid + // +1: new timelevel + variable_index + = pcs_vector[indexProcess]->GetNodeValueIndex(pcs_vector[indexProcess]->pcs_primary_function_name[0]) + 1; + pcs_vector[indexProcess]->SetNodeValue(i, variable_index, c_NaClinLiquid); + if (gas.volume > 0) + { + c_CO2inGas = gas.CO2 / gas.volume; //[mol/L] = mol / m³ + c_H2OinGas = gas.H2O / gas.volume; //[mol/L] = mol / m³ + } + else + { + c_CO2inGas = 0; + c_H2OinGas = 0; + } + indexProcess = MassTransportID[3]; // CO2 in gas + // +1: new timelevel + variable_index + = pcs_vector[indexProcess]->GetNodeValueIndex(pcs_vector[indexProcess]->pcs_primary_function_name[0]) + 1; + pcs_vector[indexProcess]->SetNodeValue(i, variable_index, c_CO2inGas); + + indexProcess = MassTransportID[4]; // H2O in gas + // +1: new timelevel + variable_index + = pcs_vector[indexProcess]->GetNodeValueIndex(pcs_vector[indexProcess]->pcs_primary_function_name[0]) + 1; + pcs_vector[indexProcess]->SetNodeValue(i, variable_index, c_H2OinGas); + + indexProcess = MassTransportID[5]; // old CO2 in liquid + // +1: new timelevel + variable_index + = pcs_vector[indexProcess]->GetNodeValueIndex(pcs_vector[indexProcess]->pcs_primary_function_name[0]) + 1; + pcs_vector[indexProcess]->SetNodeValue(i, variable_index, c_CO2inLiquid); + } +} +//-------------------END------------------ // CB _ctx_ /*************************************************************************** - Calculate electric field from charges of ions present - No external field included jet - 04/2010 CB Implementation + Calculate electric field from charges of ions present + No external field included jet + 04/2010 CB Implementation ****************************************************************************/ // CB _ctx_ CB_merge_0513 ?? @@ -16034,65 +15894,67 @@ for(i = 0; i < nelements; i++) { nnodes = elem->nodes_index.Size(); if (elem->GetMark()){ - // for each element calculate grad(Substrate) - // get number of gauss points for this element - m_fem = m_pcs->GetAssember(); - m_fem->ConfigElement(elem); - n_gauss = m_fem->GetNumGaussPoints(); - gp_ele = ele_gp_value[i]; - - // gauss point loop + // for each element calculate grad(Substrate) + // get number of gauss points for this element + m_fem = m_pcs->GetAssember(); + m_fem->ConfigElement(elem); + n_gauss = m_fem->GetNumGaussPoints(); + gp_ele = ele_gp_value[i]; + + // gauss point loop for(gp=0;gpgetIPvalue_vec(gp,vel); - //for(i_dim=0;i_dim < ele_dim;i_dim++) cout << " i_dim " << i_dim << ", vel: " << vel[i_dim] << "\n"; + //gp_ele->getIPvalue_vec(gp,vel); + //for(i_dim=0;i_dim < ele_dim;i_dim++) cout << " i_dim " << i_dim << ", vel: " << vel[i_dim] << "\n"; - i_idx = 1; // as this is in the end of transport loop, take c_new + i_idx = 1; // as this is in the end of transport loop, take c_new - fkt = m_fem->GetGaussData(gp, gp_r, gp_s, gp_t); - m_fem->ComputeShapefct(1); - m_fem->ComputeGradShapefct(1); + fkt = m_fem->GetGaussData(gp, gp_r, gp_s, gp_t); + m_fem->ComputeShapefct(1); + m_fem->ComputeGradShapefct(1); // Get C of substrate at Meshnodes of this ele for(int l=0; lGetNodeValue(elem->GetNodeIndex(l), i_idx); - node_concs[l] = fabs(conc_help); - //if(i<5) cout << " l, node_conc[l]: " << l << " " << node_concs[l] << "\n"; - } + conc_help = m_pcs2->GetNodeValue(elem->GetNodeIndex(l), i_idx); + node_concs[l] = fabs(conc_help); + //if(i<5) cout << " l, node_conc[l]: " << l << " " << node_concs[l] << "\n"; + } // interpolate conc to GP //Conc = m_fem->interpolate(node_concs); - //if(i< 5) cout << " Conc[gp]: " << Conc << " " << "\n"; + //if(i< 5) cout << " Conc[gp]: " << Conc << " " << "\n"; // calc grad_C for(i_dim=0; i_dim < ele_dim; i_dim++) gradConc[i_dim] = 0.0; - for(i_dim=0; i_dim < ele_dim; i_dim++){ + for(i_dim=0; i_dim < ele_dim; i_dim++){ for(int l=0; lGetdshapefct(i_dim*nnodes+l); - //if(i< 5) cout << "i_dim, l, gradConc, node_concs, shapefunction : " << i_dim << ", " << l ; - //if(i< 5) cout << " , " << gradConc[i_dim] << ", " << node_concs[l] << " , " << m_fem->Getdshapefct(i_dim*m_fem->Getnnodes()+l) << "\n"; - } - } + gradConc[i_dim] += node_concs[l]* m_fem->Getdshapefct(i_dim*nnodes+l); + //if(i< 5) cout << "i_dim, l, gradConc, node_concs, shapefunction : " << i_dim << ", " << l ; + //if(i< 5) cout << " , " << gradConc[i_dim] << ", " << node_concs[l] << " , " << +m_fem->Getdshapefct(i_dim*m_fem->Getnnodes()+l) << "\n"; + } + } // save result for element in gauss point for(i_dim=0; i_dim < ele_dim; i_dim++){ - S_gradConc[i_dim] = 0.0; - //if(fabs(sum_C) > 1.0e-15) - S_gradConc[i_dim] = -1.0 * X_s * gradConc[i_dim] ; - //if(i<5) cout << el_field[i_dim] << " " << sum_gradC[i_dim] << " " << sum_vC[i_dim] << " " << sum_C << "\n"; + S_gradConc[i_dim] = 0.0; + //if(fabs(sum_C) > 1.0e-15) + S_gradConc[i_dim] = -1.0 * X_s * gradConc[i_dim] ; + //if(i<5) cout << el_field[i_dim] << " " << sum_gradC[i_dim] << " " << sum_vC[i_dim] << " " << sum_C << +"\n"; m_fem->Set_ctx_(i,S_gradConc[i_dim], gp, i_dim); //gp_ele->_ctx_Gauss(i_dim,gp) = el_field[i_dim]; - //if(i<500) cout << " (" << gp << ", " << el_field[i_dim] << ") " << "\n"; - //cout << " Test: GetElectricField2: " << m_fem->GetElField(i,gp,i_dim) << "\n"; + //if(i<500) cout << " (" << gp << ", " << el_field[i_dim] << ") " << "\n"; + //cout << " Test: GetElectricField2: " << m_fem->GetElField(i,gp,i_dim) << "\n"; } } // end gauss point loop diff --git a/FEM/rf_pcs.h b/FEM/rf_pcs.h index 642d503a1..a34a7024c 100644 --- a/FEM/rf_pcs.h +++ b/FEM/rf_pcs.h @@ -30,7 +30,7 @@ #include "rf_bc_new.h" #include "rf_num_new.h" #include "rf_tim_new.h" -#include "conversion_rate.h" // HS, 10.2011 +#include "conversion_rate.h" // HS, 10.2011 #include "SparseMatrixDOK.h" #include "Eigen/Eigen" @@ -42,7 +42,10 @@ // The follows are implicit declaration. WW //--------------------------------------------------------------------------- #if defined(USE_PETSC) // || defined(using other parallel scheme) -namespace petsc_group {class PETScLinearSolver;} +namespace petsc_group +{ +class PETScLinearSolver; +} #endif namespace FiniteElement @@ -54,17 +57,19 @@ class ElementValue; } namespace MeshLib -{class CFEMesh; +{ +class CFEMesh; } -#ifdef NEW_EQS //WW +#ifdef NEW_EQS // WW namespace Math_Group -{class Linear_EQS; +{ +class Linear_EQS; } using Math_Group::Linear_EQS; #endif -//using Math_Group::SparseMatrixDOK; +// using Math_Group::SparseMatrixDOK; // /* @@ -72,18 +77,18 @@ class etr_data { public: double x; - double y; - double val; + double y; + double val; }; */ class CSourceTermGroup; class CSourceTerm; class CNodeValue; -class Problem; //WW -class CECLIPSEData; //BG Coupling to Eclipse -class CDUMUXData; //BG Coupling to DuMux -class CPlaneEquation; //BG Calculating Plane Equation +class Problem; // WW +class CECLIPSEData; // BG Coupling to Eclipse +class CDUMUXData; // BG Coupling to DuMux +class CPlaneEquation; // BG Calculating Plane Equation using FiniteElement::CFiniteElementStd; using FiniteElement::CFiniteElementVec; using FiniteElement::ElementMatrix; @@ -93,29 +98,29 @@ using MeshLib::CFEMesh; #define PCS_FILE_EXTENSION ".pcs" -typedef struct /* Knotenwert-Informationen */ +typedef struct /* Knotenwert-Informationen */ { - char name[80]; /* Name der Knotengroesse */ - char einheit[10]; /* Einheit der Knotengroesse */ - int speichern; /* s.u., wird Wert gespeichert ? */ - int laden; /* s.u., wird Wert zu Beginn geladen ? */ - int restart; /* s.u., wird Wert bei Restart geladen ? */ - int adapt_interpol; /* Soll Wert bei Adaption auf Kinder interpoliert werden? */ - double vorgabe; /* Default-Wert fuer Initialisierung */ + char name[80]; /* Name der Knotengroesse */ + char einheit[10]; /* Einheit der Knotengroesse */ + int speichern; /* s.u., wird Wert gespeichert ? */ + int laden; /* s.u., wird Wert zu Beginn geladen ? */ + int restart; /* s.u., wird Wert bei Restart geladen ? */ + int adapt_interpol; /* Soll Wert bei Adaption auf Kinder interpoliert werden? */ + double vorgabe; /* Default-Wert fuer Initialisierung */ int nval_index; int pcs_this; int timelevel; } PCS_NVAL_DATA; -typedef struct /* element data info */ +typedef struct /* element data info */ { - char name[80]; /* Name der Elementgroesse */ - char einheit[10]; /* Einheit der Elementgroesse */ - int speichern; /* s.u., wird Wert gespeichert ? */ - int laden; /* s.u., wird Wert zu Beginn geladen ? */ - int restart; /* s.u., wird Wert bei Restart geladen ? */ - int adapt_interpol; /* Soll Wert bei Adaption auf Kinder vererbt werden? */ - double vorgabe; /* Default-Wert fuer Initialisierung */ + char name[80]; /* Name der Elementgroesse */ + char einheit[10]; /* Einheit der Elementgroesse */ + int speichern; /* s.u., wird Wert gespeichert ? */ + int laden; /* s.u., wird Wert zu Beginn geladen ? */ + int restart; /* s.u., wird Wert bei Restart geladen ? */ + int adapt_interpol; /* Soll Wert bei Adaption auf Kinder vererbt werden? */ + double vorgabe; /* Default-Wert fuer Initialisierung */ int eval_index; int index; } PCS_EVAL_DATA; @@ -124,25 +129,23 @@ typedef struct { long index_node; double water_st_value; -} Water_ST_GEMS; // HS 11.2008 - +} Water_ST_GEMS; // HS 11.2008 typedef struct // CB DL CO2 phase transition { - std::string name; //fluid name + std::string name; // fluid name double temperature; double pressure; - double density; //density g/cm^3 - double viscosity; //viscosity mPa.s - double volume; //volume cm^3 - double mass; //weight g - double CO2; //mole of CO2 - double H2O; //mole of H2O - double NaCl; //mole of NaCl - double C_GAS; //mole of CO2 in Gas - double H2; //mole of H2 -}Phase_Properties; - + double density; // density g/cm^3 + double viscosity; // viscosity mPa.s + double volume; // volume cm^3 + double mass; // weight g + double CO2; // mole of CO2 + double H2O; // mole of H2O + double NaCl; // mole of NaCl + double C_GAS; // mole of CO2 in Gas + double H2; // mole of H2 +} Phase_Properties; typedef struct { @@ -154,11 +157,11 @@ typedef struct double b; double G; double Vc; - double V2,V3,V5,V6; - double Tc,Pc; + double V2, V3, V5, V6; + double Tc, Pc; double M; int id; -}VirialCoefficients; +} VirialCoefficients; #ifdef JFNK_H2M /// Dirchlet BC at node. 09.2010. WW @@ -173,20 +176,20 @@ typedef struct } bc_JFNK; #endif -//MB moved inside the Process object -//extern vectornod_val_vector; //OK -//extern vectornod_val_name_vector; //OK -//extern void pcs->SetNodeValue(long,int,double); //OK -//extern double pcs->GetNodeValue(long,int); //OK -//extern int pcs->GetNodeValueIndex(string); //OK +// MB moved inside the Process object +// extern vectornod_val_vector; //OK +// extern vectornod_val_name_vector; //OK +// extern void pcs->SetNodeValue(long,int,double); //OK +// extern double pcs->GetNodeValue(long,int); //OK +// extern int pcs->GetNodeValueIndex(string); //OK // Element values for all process -//Moved inside Process object -//extern vectorele_val_vector; //PCH -//extern vectoreld_val_name_vector; //PCH -//extern void SetElementValue(long,int,double); //PCH -//extern double GetElementValue(long,int); //PCH -//extern int GetElementValueIndex(string); //PCH +// Moved inside Process object +// extern vectorele_val_vector; //PCH +// extern vectoreld_val_name_vector; //PCH +// extern void SetElementValue(long,int,double); //PCH +// extern double GetElementValue(long,int); //PCH +// extern int GetElementValueIndex(string); //PCH /************************************************************************** FEMLib-Class: Task: @@ -214,26 +217,26 @@ class CRFProcess : public ProcessInfo void VariableStaticProblem(); void VariableDynamics(); - bool compute_domain_face_normal; //WW + bool compute_domain_face_normal; // WW int continuum; bool continuum_ic; bool isRSM; // WW - double *eqs_x; //> Pointer to x array of eqs (added due to PETSC) + double* eqs_x; //> Pointer to x array of eqs (added due to PETSC) std::vector pcs_type_name_vector; bool _hasConstrainedBC; bool _hasConstrainedST; long _idxVx, _idxVy, _idxVz; -protected: //WW +protected: // WW friend class FiniteElement::CFiniteElementStd; friend class FiniteElement::CFiniteElementVec; friend class FiniteElement::ElementValue; friend class ::CSourceTermGroup; friend class ::Problem; - friend class CECLIPSEData; //BG - friend class CDUMUXData; //SBG + friend class CECLIPSEData; // BG + friend class CDUMUXData; // SBG /// Number of nodes to a primary variable. 11.08.2010. WW int* p_var_index; long* num_nodes_p_var; @@ -243,19 +246,19 @@ class CRFProcess : public ProcessInfo // Assembler CFiniteElementStd* fem; // Time step control - bool accepted; //25.08.1008. WW - int accept_steps; //27.08.1008. WW - int reject_steps; //27.08.1008. WW + bool accepted; // 25.08.1008. WW + int accept_steps; // 27.08.1008. WW + int reject_steps; // 27.08.1008. WW // - int dof; //WW - long orig_size; // Size of source term nodes + int dof; // WW + long orig_size; // Size of source term nodes // ELE std::vector Ele_Matrices; - //Global matrix - Math_Group::Vec* Gl_Vec; //NW - Math_Group::Vec* Gl_Vec1; //NW - Math_Group::Vec* Gl_ML; //NW - Math_Group::SparseMatrixDOK* FCT_AFlux; //NW + // Global matrix + Math_Group::Vec* Gl_Vec; // NW + Math_Group::Vec* Gl_Vec1; // NW + Math_Group::Vec* Gl_ML; // NW + Math_Group::SparseMatrixDOK* FCT_AFlux; // NW #ifdef USE_PETSC Math_Group::SparseMatrixDOK* FCT_K; Math_Group::SparseMatrixDOK* FCT_d; @@ -268,43 +271,43 @@ class CRFProcess : public ProcessInfo */ int Memory_Type; //.................................................................... - int additioanl2ndvar_print; //WW + int additioanl2ndvar_print; // WW // TIM friend class CTimeDiscretization; - CTimeDiscretization* Tim; //time - bool femFCTmode; //NW - void CopyU_n(); //29.08.2008. WW + CTimeDiscretization* Tim; // time + bool femFCTmode; // NW + void CopyU_n(); // 29.08.2008. WW // Time unit factor double time_unit_factor; int NumDeactivated_SubDomains; int* Deactivated_SubDomain; - //New equation and solver objects WW +// New equation and solver objects WW #if defined(USE_PETSC) // || defined(other parallel libs)//03.3012. WW - petsc_group::PETScLinearSolver *eqs_new; - int mysize; - int myrank; + petsc_group::PETScLinearSolver* eqs_new; + int mysize; + int myrank; #elif defined(NEW_EQS) #if defined(LIS) || defined(MKL) public: Linear_EQS* eqs_new; #else Linear_EQS* eqs_new; -#endif // LIS endif for Fluid Momentum // PCH +#endif // LIS endif for Fluid Momentum // PCH bool configured_in_nonlinearloop; #else - LINEAR_SOLVER* eqs; + LINEAR_SOLVER* eqs; #endif - // -#if defined( USE_MPI) || defined( USE_PETSC) //WW +// +#if defined(USE_MPI) || defined(USE_PETSC) // WW clock_t cpu_time_assembly; #endif // Position of unknowns from different DOFs in the system equation //.................................................................... // OUT // Write indices of the nodes with boundary conditons - bool write_boundary_condition; //15.01.2008. WW - bool OutputMassOfGasInModel; // BG 05/2012 + bool write_boundary_condition; // 15.01.2008. WW + bool OutputMassOfGasInModel; // BG 05/2012 // Element matrices output void Def_Variable_LiquidFlow(); void Def_Variable_MultiPhaseFlow(); @@ -323,15 +326,15 @@ class CRFProcess : public ProcessInfo // 3 read and write int reload; long nwrite_restart; - void WriteRHS_of_ST_NeumannBC(); - void ReadRHS_of_ST_NeumannBC(); - void Write_Processed_BC(); // 05.08.2011. WW - void Read_Processed_BC(); // 05.08.2011. WW + void WriteRHS_of_ST_NeumannBC(); + void ReadRHS_of_ST_NeumannBC(); + void Write_Processed_BC(); // 05.08.2011. WW + void Read_Processed_BC(); // 05.08.2011. WW friend bool PCSRead(std::string); //.................................................................... // 1-GEO - int ite_steps; ///Newton step index; + int ite_steps; /// Newton step index; #ifdef JFNK_H2M /// Norn of F for Newton method @@ -345,35 +348,28 @@ class CRFProcess : public ProcessInfo #endif public: // BG, DL Calculate phase transition of CO2 - void CO2_H2O_NaCl_VLE_isobaric(double T, - double P, - Phase_Properties &vapor, - Phase_Properties &liquid, - Phase_Properties &solid, - int f); + void CO2_H2O_NaCl_VLE_isobaric(double T, double P, Phase_Properties& vapor, Phase_Properties& liquid, + Phase_Properties& solid, int f); // BG, DL Calculate phase transition of CO2 - void CO2_H2O_NaCl_VLE_isochoric(Phase_Properties &vapor, - Phase_Properties &liquid, - Phase_Properties &solid, - int f); + void CO2_H2O_NaCl_VLE_isochoric(Phase_Properties& vapor, Phase_Properties& liquid, Phase_Properties& solid, int f); // BG, NB Calculate phase transition of CO2 void Phase_Transition_CO2(CRFProcess* m_pcs, int Step); - int Phase_Transition_Model; //BG, NB flag of Phase_Transition_Model (1...CO2-H2O-NaCl) - // BG 11/2010 Sets the initial conditions for multi phase flow if Phase_Transition_CO2 is used + int Phase_Transition_Model; // BG, NB flag of Phase_Transition_Model (1...CO2-H2O-NaCl) + // BG 11/2010 Sets the initial conditions for multi phase flow if Phase_Transition_CO2 is used void CalculateFluidDensitiesAndViscositiesAtNodes(CRFProcess* m_pcs); /** * Sets the value for pointer _problem. * @param problem the value for _problem */ - void setProblemObjectPointer (Problem* problem); + void setProblemObjectPointer(Problem* problem); /** * get access to the instance of class Problem * @return */ - Problem* getProblemObjectPointer () const; - std::string geo_type; //OK - std::string geo_type_name; //OK + Problem* getProblemObjectPointer() const; + std::string geo_type; // OK + std::string geo_type_name; // OK //.................................................................... // 2-MSH //.................................................................... @@ -382,33 +378,33 @@ class CRFProcess : public ProcessInfo // 4-IC //.................................................................... // 5-BC - //WW + // WW std::vector bc_node_value; - std::vector bc_node; //WW + std::vector bc_node; // WW #if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW - std::vector bc_node_value_in_dom; //WW for domain decomposition - std::vector bc_local_index_in_dom; //WW for domain decomposition - std::vector rank_bc_node_value_in_dom; //WW + std::vector bc_node_value_in_dom; // WW for domain decomposition + std::vector bc_local_index_in_dom; // WW for domain decomposition + std::vector rank_bc_node_value_in_dom; // WW #endif //#if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW - std::vector bc_transient_index; //WW/CB - std::vector st_transient_index; //WW/CB...BG - void UpdateTransientBC(); //WW/CB - void UpdateTransientST(); //WW/CB...BG + std::vector bc_transient_index; // WW/CB + std::vector st_transient_index; // WW/CB...BG + void UpdateTransientBC(); // WW/CB + void UpdateTransientST(); // WW/CB...BG //.................................................................... // 6-ST // Node values from sourse/sink or Neumann BC. WW - std::vector st_node_value; //WW - std::vector st_node; //WW + std::vector st_node_value; // WW + std::vector st_node; // WW #if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW - std::vector st_node_value_in_dom; //WW for domain decomposition - std::vector st_local_index_in_dom; //WW for domain decomposition - std::vector rank_st_node_value_in_dom; //WW + std::vector st_node_value_in_dom; // WW for domain decomposition + std::vector st_local_index_in_dom; // WW for domain decomposition + std::vector rank_st_node_value_in_dom; // WW #endif //#if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW - void RecordNodeVSize(const int Size) //WW + void RecordNodeVSize(const int Size) // WW { orig_size = Size; } - int GetOrigNodeVSize () const //WW + int GetOrigNodeVSize() const // WW { return orig_size; } @@ -419,15 +415,15 @@ class CRFProcess : public ProcessInfo // 8-MSP //.................................................................... // 9-MMP - int GetContinnumType() const {return continuum; } + int GetContinnumType() const { return continuum; } // const int number_continuum=1; - std:: vector continuum_vector; + std::vector continuum_vector; //.................................................................... // 10-MCP //.................................................................... // 11-OUT - void WriteSolution(); //WW - void ReadSolution(); //WW + void WriteSolution(); // WW + void ReadSolution(); // WW //.................................................................... // 12-NUM //.................................................................... @@ -460,8 +456,8 @@ class CRFProcess : public ProcessInfo //.................................................................... // 5-BC void CreateBCGroup(); - void SetBC(); //OK - void WriteBC(); //15.01.2008. WW + void SetBC(); // OK + void WriteBC(); // 15.01.2008. WW //.................................................................... // 6-ST void CreateSTGroup(); @@ -475,25 +471,25 @@ class CRFProcess : public ProcessInfo // 10-MCP //.................................................................... // 11-OUT - void WriteAllVariables(); //OK + void WriteAllVariables(); // OK //.................................................................... // 12-NUM //.................................................................... // 13-ELE //.................................................................... // 14-CPL - void SetCPL(); //OK8 OK4310 + void SetCPL(); // OK8 OK4310 //.................................................................... // 15-EQS - //WW void AssembleParabolicEquationRHSVector(CNode*); //(vector&); //OK + // WW void AssembleParabolicEquationRHSVector(CNode*); //(vector&); //OK //.................................................................... int Shift[10]; // 16-GEM // HS 11.2008 - int flag_couple_GEMS; // 0-no couple; 1-coupled + int flag_couple_GEMS; // 0-no couple; 1-coupled std::vector Water_ST_vec; - std::vector stgem_node_value_in_dom; //KG for domain decomposition - std::vector stgem_local_index_in_dom; //KG for domain decomposition - //KG + std::vector stgem_node_value_in_dom; // KG for domain decomposition + std::vector stgem_local_index_in_dom; // KG for domain decomposition + // KG std::vector rank_stgem_node_value_in_dom; void Clean_Water_ST_vec(void); @@ -502,34 +498,33 @@ class CRFProcess : public ProcessInfo void SetSTWaterGemSubDomain(int myrank); #endif // ECLIPSE interface: - CDUMUXData* DuMuxData; //SBG - CECLIPSEData* EclipseData; //BG - void CalGPVelocitiesfromECLIPSE(std::string path, - int timestep, - int phase_index, - std::string phase); - std::string simulator; // which solver to use, i.e. GeoSys, ECLIPSE or DuMux - std::string simulator_path; // path for executable of external simulator - std::string simulator_model_path; // path to exclipse input data file (*.data), with extension - bool PrecalculatedFiles; // defines if Eclipse or dumux is calculated or if precalculated files are used - bool SaveEclipseDataFiles; // WTP: save Eclipse data input files for benchmarking on systems with no Eclipse licenses; use in combination with Precalculated Files - std::string simulator_well_path; // path to well schedule ( *.well), with extension - // SB redo wtp - std::string dissolved_co2_pcs_name; // Keyword DISSOLVED_CO2_PCS_NAME; Name of MASS_TRANSPORT Process which is used to store total dissolved CO2 from ECLIPSE + CDUMUXData* DuMuxData; // SBG + CECLIPSEData* EclipseData; // BG + void CalGPVelocitiesfromECLIPSE(std::string path, int timestep, int phase_index, std::string phase); + std::string simulator; // which solver to use, i.e. GeoSys, ECLIPSE or DuMux + std::string simulator_path; // path for executable of external simulator + std::string simulator_model_path; // path to exclipse input data file (*.data), with extension + bool PrecalculatedFiles; // defines if Eclipse or dumux is calculated or if precalculated files are used + bool SaveEclipseDataFiles; // WTP: save Eclipse data input files for benchmarking on systems with no Eclipse + // licenses; use in combination with Precalculated Files + std::string simulator_well_path; // path to well schedule ( *.well), with extension + // SB redo wtp + std::string dissolved_co2_pcs_name; // Keyword DISSOLVED_CO2_PCS_NAME; Name of MASS_TRANSPORT Process which is used + // to store total dissolved CO2 from ECLIPSE std::string dissolved_co2_ingas_pcs_name; //.................................................................... // Construction / destruction - char pcs_name[MAX_ZEILE]; //string pcs_name; + char pcs_name[MAX_ZEILE]; // string pcs_name; int pcs_number; int mobile_nodes_flag; int pcs_type_number; int type; - int GetObjType() const {return type; } - int pcs_component_number; //SB: counter for transport components - int ML_Cap; // 23.01 2009 PCH - int PartialPS; // 16.02 2009 PCH + int GetObjType() const { return type; } + int pcs_component_number; // SB: counter for transport components + int ML_Cap; // 23.01 2009 PCH + int PartialPS; // 16.02 2009 PCH // // JT2012: Process type identifiers bool isPCSFlow; @@ -538,41 +533,38 @@ class CRFProcess : public ProcessInfo bool isPCSMass; bool isPCSDeformation; - int GetProcessComponentNumber() const //SB:namepatch + int GetProcessComponentNumber() const // SB:namepatch { return pcs_component_number; } - std::string file_name_base; //OK + std::string file_name_base; // OK // Access to PCS // Configuration 1 - NOD - PCS_NVAL_DATA* pcs_nval_data; ///OK + PCS_NVAL_DATA* pcs_nval_data; /// OK int number_of_nvals; int pcs_number_of_primary_nvals; - size_t GetPrimaryVNumber() const {return static_cast(pcs_number_of_primary_nvals); } + size_t GetPrimaryVNumber() const { return static_cast(pcs_number_of_primary_nvals); } const char* pcs_primary_function_unit[7]; const char* pcs_primary_function_name[7]; - const char* GetPrimaryVName(const int index) const {return pcs_primary_function_name[index]; } - std::string primary_variable_name; //OK + const char* GetPrimaryVName(const int index) const { return pcs_primary_function_name[index]; } + std::string primary_variable_name; // OK int pcs_number_of_secondary_nvals; - size_t GetSecondaryVNumber() const - { - return static_cast ( - pcs_number_of_secondary_nvals); - } + size_t GetSecondaryVNumber() const { return static_cast(pcs_number_of_secondary_nvals); } const char* pcs_secondary_function_name[PCS_NUMBER_MAX]; - const char* GetSecondaryVName(const int index) const - { - return pcs_secondary_function_name[index]; - } + const char* GetSecondaryVName(const int index) const { return pcs_secondary_function_name[index]; } const char* pcs_secondary_function_unit[PCS_NUMBER_MAX]; int pcs_secondary_function_timelevel[PCS_NUMBER_MAX]; int pcs_number_of_history_values; /*double pcs_secondary_function_time_history[PCS_NUMBER_MAX];//CMCD for analytical solution double pcs_secondary_function_value_history[PCS_NUMBER_MAX];//CMCD for analytical solution - void Set_secondary_function_time_history(const int index, double value) {pcs_secondary_function_time_history[index]=value;}//CMCD for analytical solution - void Set_secondary_function_value_history(const int index, double value) {pcs_secondary_function_value_history[index]=value;}//CMCD for analytical solution - double Get_secondary_function_time_history(const int index){return pcs_secondary_function_time_history[index];}//CMCD for analytical solution - double Get_secondary_function_value_history(const int index){return pcs_secondary_function_value_history[index];}//CMCD for analytical solution*/ + void Set_secondary_function_time_history(const int index, double value) + {pcs_secondary_function_time_history[index]=value;}//CMCD for analytical solution + void Set_secondary_function_value_history(const int index, double value) + {pcs_secondary_function_value_history[index]=value;}//CMCD for analytical solution + double Get_secondary_function_time_history(const int index){return + pcs_secondary_function_time_history[index];}//CMCD for analytical solution + double Get_secondary_function_value_history(const int index){return + pcs_secondary_function_value_history[index];}//CMCD for analytical solution*/ // Configuration 2 - ELE PCS_EVAL_DATA* pcs_eval_data; int pcs_number_of_evals; @@ -583,51 +575,52 @@ class CRFProcess : public ProcessInfo // NUM std::string num_type_name; int rwpt_app; - int rwpt_count; //YS 05.2013 Count the number of particles. + int rwpt_count; // YS 05.2013 Count the number of particles. int srand_seed; - const char* pcs_num_name[2]; //For monolithic scheme + const char* pcs_num_name[2]; // For monolithic scheme TimType::type tim_type; const char* pcs_sol_name; std::string cpl_type_name; CNumerics* m_num; // - bool selected; //OK - bool saturation_switch; // JOD + bool selected; // OK + bool saturation_switch; // JOD // MSH - CFEMesh* m_msh; //OK - std::string msh_type_name; //OK - //MB------------- - std::vector nod_val_vector; //OK - //OK + CFEMesh* m_msh; // OK + std::string msh_type_name; // OK + // MB------------- + std::vector nod_val_vector; // OK + // OK std::vector nod_val_name_vector; - void SetNodeValue(long,int,double); //OK - double GetNodeValue(size_t,int); //OK - double *getNodeValue_per_Variable(const int entry_id) const //WW + void SetNodeValue(long, int, double); // OK + double GetNodeValue(size_t, int); // OK + double* getNodeValue_per_Variable(const int entry_id) const // WW { - return nod_val_vector[entry_id]; + return nod_val_vector[entry_id]; } - int GetNodeValueIndex(const std::string&, bool reverse_order = false); //OK + int GetNodeValueIndex(const std::string&, bool reverse_order = false); // OK //----------------------------- - std::vector const& getElementValueNameVector () { return ele_val_name_vector; } + std::vector const& getElementValueNameVector() { return ele_val_name_vector; } private: - //PCH + // PCH std::vector ele_val_name_vector; + public: - std::vector ele_val_vector; //PCH - void SetElementValue(long,int,double); //PCH - double GetElementValue(size_t,int); //PCH - //PCH + std::vector ele_val_vector; // PCH + void SetElementValue(long, int, double); // PCH + double GetElementValue(size_t, int); // PCH + // PCH int GetElementValueIndex(const std::string&, bool reverse_order = false); - //CB----------------------------- + // CB----------------------------- int flow_pcs_type; //---------------------------------------------------------------------- // Methods // Access to PCS CRFProcess* GetProcessByFunctionName(char* name); CRFProcess* GetProcessByNumber(int); - CFiniteElementStd* GetAssembler() {return fem; } - int GetDOF() {return dof;} + CFiniteElementStd* GetAssembler() { return fem; } + int GetDOF() { return dof; } bool pcs_is_cpl_overlord; bool pcs_is_cpl_underling; CRFProcess* cpl_overlord; @@ -644,84 +637,84 @@ class CRFProcess : public ProcessInfo void ConfigDeformation(); void ConfigMultiphaseFlow(); void ConfigGasFlow(); - void ConfigUnsaturatedFlow(); //OK4104 + void ConfigUnsaturatedFlow(); // OK4104 void ConfigFluidMomentum(); void ConfigRandomWalk(); void ConfigMultiPhaseFlow(); - void ConfigPS_Global(); // PCH - void ConfigMULTI_COMPONENTIAL_FLOW(); // AKS/NB - void ConfigTNEQ(); //HS,TN - void ConfigTES(); //HS,TN - // Configuration 1 - NOD + void ConfigPS_Global(); // PCH + void ConfigMULTI_COMPONENTIAL_FLOW(); // AKS/NB + void ConfigTNEQ(); // HS,TN + void ConfigTES(); // HS,TN +// Configuration 1 - NOD #if defined(USE_PETSC) // || defined(other parallel libs)//03.3012. WW - void setSolver( petsc_group::PETScLinearSolver *petsc_solver ); - double CalcIterationNODError(int method); //OK // PETSC version in rf_pcs1.cpp WW + void setSolver(petsc_group::PETScLinearSolver* petsc_solver); + double CalcIterationNODError(int method); // OK // PETSC version in rf_pcs1.cpp WW #endif #if !defined(USE_PETSC) && !defined(NEW_EQS) // && defined(other parallel libs)//03~04.3012. WW void ConfigNODValues1(void); void ConfigNODValues2(void); void CreateNODValues(void); - void SetNODValues(); //OK - void CalcFluxesForCoupling(); //MB - void SetNODFlux(); //OK + void SetNODValues(); // OK + void CalcFluxesForCoupling(); // MB + void SetNODFlux(); // OK // - void AssembleParabolicEquationRHSVector(); //OK + void AssembleParabolicEquationRHSVector(); // OK // 15-EQS //(vector&); //OK void AssembleParabolicEquationRHSVector(MeshLib::CNode*); #endif - double CalcIterationNODError(FiniteElement::ErrorMethod method, bool nls_error, bool cpl_error=false); //OK - // Add bool forward = true. WW + double CalcIterationNODError(FiniteElement::ErrorMethod method, bool nls_error, bool cpl_error = false); // OK + // Add bool forward = true. WW void CopyTimestepNODValues(bool forward = true); void CopyTimestepELEValues(bool forward = true); - //Coupling - //WW double CalcCouplingNODError(); //MB + // Coupling + // WW double CalcCouplingNODError(); //MB void CopyCouplingNODValues(); - //WWvoid CalcFluxesForCoupling(); //MB + // WWvoid CalcFluxesForCoupling(); //MB // Configuration 2 - ELE void ConfigELEValues1(void); void ConfigELEValues2(void); void CreateELEValues(void); void CreateELEGPValues(); - void AllocateMemGPoint(); //NEW Gauss point values for CFEMSH WW + void AllocateMemGPoint(); // NEW Gauss point values for CFEMSH WW void CalcELEVelocities(void); - //void CalcELEMassFluxes(); //BG - //WW double GetELEValue(long index,double*gp,double theta,string nod_fct_name); - void CheckMarkedElement(); //WW - void CheckExcavedElement(); //WX + // void CalcELEMassFluxes(); //BG + // WW double GetELEValue(long index,double*gp,double theta,string nod_fct_name); + void CheckMarkedElement(); // WW + void CheckExcavedElement(); // WX // Configuration 3 - ELE matrices void CreateELEMatricesPointer(void); // Equation system //---WW - CFiniteElementStd* GetAssember () { return fem; } + CFiniteElementStd* GetAssember() { return fem; } void AllocateLocalMatrixMemory(); - virtual void GlobalAssembly(); // Make as a virtul function. //10.09.201l. WW + virtual void GlobalAssembly(); // Make as a virtul function. //10.09.201l. WW /// For all PDEs excluding that for deformation. 24.11.2010l. WW void GlobalAssembly_std(bool is_quad, bool Check2D3D = false); /// Assemble EQS for deformation process. - virtual void GlobalAssembly_DM() {}; -#if defined (NEW_EQS) && defined(JFNK_H2M) + virtual void GlobalAssembly_DM(){}; +#if defined(NEW_EQS) && defined(JFNK_H2M) /// Jacobian free methid to calculate J*v. - //11.08.2010. + // 11.08.2010. void Jacobian_Multi_Vector_JFNK(double* v = NULL, double* Jv = NULL); /// Recovery du from the temporary vector. - void Recovery_du_JFNK(); //02.11.2010. + void Recovery_du_JFNK(); // 02.11.2010. /// Line serach for Newton method. - double LineSearch(); //10.12.2010. + double LineSearch(); // 10.12.2010. /// Force term control for inexact Newton method. 01.2011. bool ForceTermCriterion(double* Jdx, const int num_iteration); #endif - void AddFCT_CorrectionVector(); //NW + void AddFCT_CorrectionVector(); // NW void ConfigureCouplingForLocalAssemblier(); void CalIntegrationPointValue(); - bool cal_integration_point_value; //WW - void CalGPVelocitiesfromFluidMomentum(); //SB 4900 - bool use_velocities_for_transport; //SB4900 + bool cal_integration_point_value; // WW + void CalGPVelocitiesfromFluidMomentum(); // SB 4900 + bool use_velocities_for_transport; // SB4900 //--- double Execute(); - double ExecuteNonLinear(int loop_process_number, bool print_pcs=true); + double ExecuteNonLinear(int loop_process_number, bool print_pcs = true); void PrintStandardIterationInformation(bool write_std_errors = true); virtual void CalculateElementMatrices(void); @@ -730,45 +723,43 @@ class CRFProcess : public ProcessInfo #endif virtual void AssembleSystemMatrixNew(void); - //MW + // MW int getFirstNodeBelowGWL(size_t i); - bool hasConstrainedBC(){ return _hasConstrainedBC; } - bool hasConstrainedST(){ return _hasConstrainedST; } - void hasConstrainedBC(const bool state){ _hasConstrainedBC = state; } - void hasConstrainedST(const bool state){ _hasConstrainedST = state; } - - void setidxVx(int index){ _idxVx = index; } - void setidxVy(int index){ _idxVy = index; } - void setidxVz(int index){ _idxVz = index; } - + bool hasConstrainedBC() { return _hasConstrainedBC; } + bool hasConstrainedST() { return _hasConstrainedST; } + void hasConstrainedBC(const bool state) { _hasConstrainedBC = state; } + void hasConstrainedST(const bool state) { _hasConstrainedST = state; } + void setidxVx(int index) { _idxVx = index; } + void setidxVy(int index) { _idxVy = index; } + void setidxVz(int index) { _idxVz = index; } // ST void IncorporateSourceTerms(const int rank = -1); - //WW void CheckSTGroup(); //OK +// WW void CheckSTGroup(); //OK #ifdef GEM_REACT - void IncorporateSourceTerms_GEMS(void); //HS: dC/dt from GEMS chemical solver. - int GetRestartFlag() const {return reload; } + void IncorporateSourceTerms_GEMS(void); // HS: dC/dt from GEMS chemical solver. + int GetRestartFlag() const { return reload; } #endif // BC void IncorporateBoundaryConditions(const int rank = -1); // PCH for FLUID_MOMENTUM void IncorporateBoundaryConditions(const int rank, const int axis); #if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW - void SetBoundaryConditionSubDomain(); //WW + void SetBoundaryConditionSubDomain(); // WW #endif //#if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW - //WW void CheckBCGroup(); //OK +// WW void CheckBCGroup(); //OK #if !defined(USE_PETSC) // && !defined(other parallel libs)//03~04.3012. WW -#ifdef NEW_EQS //WW +#ifdef NEW_EQS // WW void EQSInitialize(); - void EQSSolver(double* x); // PCH + void EQSSolver(double* x); // PCH #else int ExecuteLinearSolver(void); int ExecuteLinearSolver(LINEAR_SOLVER* eqs); - LINEAR_SOLVER *getEQSPointer() const { return eqs; } // WW + LINEAR_SOLVER* getEQSPointer() const { return eqs; } // WW #endif #endif - CTimeDiscretization* GetTimeStepping() const {return Tim; } - double timebuffer; //YD + CTimeDiscretization* GetTimeStepping() const { return Tim; } + double timebuffer; // YD // // NLS and CPL error and looping control int num_diverged; @@ -777,45 +768,45 @@ class CRFProcess : public ProcessInfo int iter_nlin_max; int iter_lin; int iter_lin_max; - int iter_outer_cpl; // JT2012 - int iter_inner_cpl; // JT2012 - int pcs_num_dof_errors; // JT2012 - double pcs_relative_error[DOF_NUMBER_MAX]; // JT2012: for NLS, we store relative error for each DOF - double pcs_absolute_error[DOF_NUMBER_MAX]; // JT2012: for NLS, we store error for each DOF + int iter_outer_cpl; // JT2012 + int iter_inner_cpl; // JT2012 + int pcs_num_dof_errors; // JT2012 + double pcs_relative_error[DOF_NUMBER_MAX]; // JT2012: for NLS, we store relative error for each DOF + double pcs_absolute_error[DOF_NUMBER_MAX]; // JT2012: for NLS, we store error for each DOF double pcs_unknowns_norm; - double cpl_max_relative_error; // JT2012: For CPL, we just store the maximum, not each dof value + double cpl_max_relative_error; // JT2012: For CPL, we just store the maximum, not each dof value double cpl_max_relative_error_overall; double nls_max_relative_error; - double cpl_absolute_error[DOF_NUMBER_MAX]; // JT2012: - double temporary_absolute_error[DOF_NUMBER_MAX]; // JT2012: + double cpl_absolute_error[DOF_NUMBER_MAX]; // JT2012: + double temporary_absolute_error[DOF_NUMBER_MAX]; // JT2012: int temporary_num_dof_errors; - int cpl_num_dof_errors; // JT2012 - bool first_coupling_iteration; // JT2012 + int cpl_num_dof_errors; // JT2012 + bool first_coupling_iteration; // JT2012 // // Specials void PCSMoveNOD(); void PCSDumpModelNodeValues(void); - //WW - int GetNODValueIndex(const std::string &name,int timelevel); + // WW + int GetNODValueIndex(const std::string& name, int timelevel); // BC for dynamic problems. WW inline void setBC_danymic_problems(); inline void setST_danymic_problems(); inline void setIC_danymic_problems(); // Extropolate Gauss point values to node values. WW void Extropolation_GaussValue(); - void Extropolation_MatValue(); //WW - //WW. 05.2009 - void Integration(std::vector &node_velue); + void Extropolation_MatValue(); // WW + // WW. 05.2009 + void Integration(std::vector& node_velue); // Auto time step size control. WW - void PI_TimeStepSize(); //WW + void PI_TimeStepSize(); // WW bool TimeStepAccept() const { return accepted; } void SetDefaultTimeStepAccepted() { accepted = true; } // USER - //ToDo - double* TempArry; //MX + // ToDo + double* TempArry; // MX void PCSOutputNODValues(void); - void PCSSetTempArry(void); //MX - double GetTempArryVal(int index) const //MX + void PCSSetTempArry(void); // MX + double GetTempArryVal(int index) const // MX { return TempArry[index]; } @@ -825,32 +816,30 @@ class CRFProcess : public ProcessInfo // Remove argument. WW void CalcSecondaryVariables(bool initial = false); void MMPCalcSecondaryVariablesRichards(int timelevel, bool update); - //WW Reomve int timelevel, bool update - //WW + // WW Reomve int timelevel, bool update + // WW - void CalcSecondaryVariablesTNEQ(); //HS - void CalcSecondaryVariablesTES(); //HS + void CalcSecondaryVariablesTNEQ(); // HS + void CalcSecondaryVariablesTES(); // HS void CalcSecondaryVariablesUnsaturatedFlow(bool initial = false); void CalcSecondaryVariablesPSGLOBAL(); // PCH - void CalcSecondaryVariablesLiquidFlow(); // PCH - double GetCapillaryPressureOnNodeByNeighobringElementPatches(int nodeIdx, - int meanOption, - double Sw); + void CalcSecondaryVariablesLiquidFlow(); // PCH + double GetCapillaryPressureOnNodeByNeighobringElementPatches(int nodeIdx, int meanOption, double Sw); // JOD void CalcSaturationRichards(int timelevel, bool update); - bool non_linear; //OK/CMCD - //MX + bool non_linear; // OK/CMCD + // MX void InterpolateTempGP(CRFProcess*, std::string); - //MX + // MX void ExtropolateTempGP(CRFProcess*, std::string); - //Repeat Calculation, JOD removed // HS reactivated - void PrimaryVariableReload(); //YD - void PrimaryVariableReloadRichards(); //YD - void PrimaryVariableStorageRichards(); //YD + // Repeat Calculation, JOD removed // HS reactivated + void PrimaryVariableReload(); // YD + void PrimaryVariableReloadRichards(); // YD + void PrimaryVariableStorageRichards(); // YD bool adaption; - void PrimaryVariableReloadTransport(); //kg44 - void PrimaryVariableStorageTransport(); //kg44 - //double GetNewTimeStepSizeTransport(double mchange); //kg44 + void PrimaryVariableReloadTransport(); // kg44 + void PrimaryVariableStorageTransport(); // kg44 + // double GetNewTimeStepSizeTransport(double mchange); //kg44 // FLX void CalcELEFluxes(const GEOLIB::Polyline* const ply, double* result); /** @@ -859,9 +848,9 @@ class CRFProcess : public ProcessInfo * @param NameofPolyline the name of the polyline * @param result */ - void CalcELEMassFluxes(const GEOLIB::Polyline* const ply, std::string const& NameofPolyline, double *result); - double TotalMass[10]; // Necessary for the output of mass fluxes over polylines, BG 08/2011 - std::vector PolylinesforOutput; // Necessary for the output of mass fluxes over polylines, BG 08/2011 + void CalcELEMassFluxes(const GEOLIB::Polyline* const ply, std::string const& NameofPolyline, double* result); + double TotalMass[10]; // Necessary for the output of mass fluxes over polylines, BG 08/2011 + std::vector PolylinesforOutput; // Necessary for the output of mass fluxes over polylines, BG 08/2011 /** * Necessary for the output of mass fluxes over polylines, BG 08/2011 @@ -869,53 +858,53 @@ class CRFProcess : public ProcessInfo * @param ElementConcentration * @param grad */ - void Calc2DElementGradient(MeshLib::CElem* ele, double ElementConcentration[4], double *grad); + void Calc2DElementGradient(MeshLib::CElem* ele, double ElementConcentration[4], double* grad); // NEW CRFProcess* CopyPCStoDM_PCS(); - bool OBJRelations(); //OK - void OBJRelationsDelete(); //OK - bool NODRelations(); //OK - bool ELERelations(); //OK + bool OBJRelations(); // OK + void OBJRelationsDelete(); // OK + bool NODRelations(); // OK + bool ELERelations(); // OK #if !defined(USE_PETSC) && !defined(NEW_EQS) // && defined(other parallel libs)//03~04.3012. WW - bool CreateEQS(); //OK - void EQSDelete(); //OK + bool CreateEQS(); // OK + void EQSDelete(); // OK // Dumping matrix and RHS. WW void DumpEqs(std::string file_name); #endif - bool Check(); //OK - void NODRelationsDelete(); //OK - void ELERelationsDelete(); //OK - bool m_bCheckOBJ; //OK - bool m_bCheckNOD; //OK - bool m_bCheckELE; //OK - bool m_bCheckEQS; //OK - void Delete(); //OK - bool m_bCheck; //OK - int ExcavMaterialGroup; //WX - int ExcavDirection; //WX - int ExcavCurve; //WX - double ExcavBeginCoordinate; //WX - int PCS_ExcavState; //WX - int Neglect_H_ini; //WX - int UpdateIniState; //WX -#if defined(USE_MPI) || defined (USE_PETSC) //WW - void Print_CPU_time_byAssembly(std::ostream &os = std::cout) const + bool Check(); // OK + void NODRelationsDelete(); // OK + void ELERelationsDelete(); // OK + bool m_bCheckOBJ; // OK + bool m_bCheckNOD; // OK + bool m_bCheckELE; // OK + bool m_bCheckEQS; // OK + void Delete(); // OK + bool m_bCheck; // OK + int ExcavMaterialGroup; // WX + int ExcavDirection; // WX + int ExcavCurve; // WX + double ExcavBeginCoordinate; // WX + int PCS_ExcavState; // WX + int Neglect_H_ini; // WX + int UpdateIniState; // WX +#if defined(USE_MPI) || defined(USE_PETSC) // WW + void Print_CPU_time_byAssembly(std::ostream& os = std::cout) const { - os << "\n***\nCPU time elapsed in the linear equation of " << - convertProcessTypeToString(getProcessType()) << "\n"; + os << "\n***\nCPU time elapsed in the linear equation of " << convertProcessTypeToString(getProcessType()) + << "\n"; os << "--Global assembly: " << (double)cpu_time_assembly / CLOCKS_PER_SEC << "\n"; } #endif // HS 10.2011 double m_rho_s_0; - conversion_rate *m_conversion_rate; + conversion_rate* m_conversion_rate; -#if defined(USE_PETSC) //03.3012. WW - /// Initialize the RHS array of the system of equations with the previous solution. - void InitializeRHS_with_u0(const bool quad = false); //in rf_pcs1.cpp +#if defined(USE_PETSC) // 03.3012. WW + /// Initialize the RHS array of the system of equations with the previous solution. + void InitializeRHS_with_u0(const bool quad = false); // in rf_pcs1.cpp - /// Initialize the unknows of equations with existing solutions within a index range. - void initializeRHS_with_u0(const int min_id, const int max_id); //in rf_pcs1.cpp + /// Initialize the unknows of equations with existing solutions within a index range. + void initializeRHS_with_u0(const int min_id, const int max_id); // in rf_pcs1.cpp #endif private: @@ -924,18 +913,19 @@ class CRFProcess : public ProcessInfo * COutput objects (in the vector _nod_value_vector) for the values * PERMEABILITY_X1 and POROSITY */ - void configMaterialParameters (); + void configMaterialParameters(); // method to check on constrained source terms - bool checkConstrainedST(std::vector & st_vector, CSourceTerm const & st, CNodeValue const & st_node); + bool checkConstrainedST(std::vector& st_vector, CSourceTerm const& st, CNodeValue const& st_node); // method to check on constrained boundary conditions - bool checkConstrainedBC(CBoundaryCondition const & bc, CBoundaryConditionNode & bc_node, double & bc_value); + bool checkConstrainedBC(CBoundaryCondition const& bc, CBoundaryConditionNode& bc_node, double& bc_value); std::valarray getNodeVelocityVector(const long node_id); - double calcPressureFromHead(CBoundaryCondition const & bc, std::size_t node_number, double pressure_value, - double const & time_fac = 1, double const & fac = 1); - double calcHeadFromPressure(CBoundaryCondition const & bc, std::size_t node_number, double pressure_value, - double const & time_fac = 1, double const & fac = 1); + double calcPressureFromHead(CBoundaryCondition const& bc, std::size_t node_number, double pressure_value, + double const& time_fac = 1, double const& fac = 1); + double calcHeadFromPressure(CBoundaryCondition const& bc, std::size_t node_number, double pressure_value, + double const& time_fac = 1, double const& fac = 1); - double evaluteSwitchBC(CBoundaryCondition const & bc, CBoundaryConditionNode const & bc_node, double time_fac, double fac); + double evaluteSwitchBC(CBoundaryCondition const& bc, CBoundaryConditionNode const& bc_node, double time_fac, + double fac); int _pcs_constant_model; double _pcs_constant_value; @@ -944,8 +934,8 @@ class CRFProcess : public ProcessInfo //======================================================================== // PCS -extern std::vectorpcs_vector; -extern std::vector ele_gp_value; // Gauss point value for velocity. WW +extern std::vector pcs_vector; +extern std::vector ele_gp_value; // Gauss point value for velocity. WW extern bool PCSRead(std::string); extern void PCSWrite(std::string); extern void RelocateDeformationProcess(CRFProcess* m_pcs); @@ -957,16 +947,16 @@ extern CRFProcess* PCSGet(const std::string&); * @param pcs_type process type * @return a pointer the the appropriate process or NULL (if not found) */ -CRFProcess* PCSGet (FiniteElement::ProcessType pcs_type); // TF +CRFProcess* PCSGet(FiniteElement::ProcessType pcs_type); // TF -extern CRFProcess* PCSGetNew(const std::string&,const std::string&); +extern CRFProcess* PCSGetNew(const std::string&, const std::string&); extern void PCSDelete(); extern void PCSDelete(const std::string&); extern void PCSCreate(); -//SB -extern int PCSGetPCSIndex(const std::string&,const std::string&); -//SB -extern CRFProcess* PCSGet(const std::string&,const std::string&); +// SB +extern int PCSGetPCSIndex(const std::string&, const std::string&); +// SB +extern CRFProcess* PCSGet(const std::string&, const std::string&); /** * Function searchs in the global pcs_vector for a process @@ -977,23 +967,23 @@ extern CRFProcess* PCSGet(const std::string&,const std::string&); * @return */ // TF -CRFProcess* PCSGet(FiniteElement::ProcessType pcs_type, const std::string &pv_name); - -//OK -extern CRFProcess* PCSGet(const std::string &variable_name, bool dummy); -extern CRFProcess* PCSGetFluxProcess(); //CMCD -extern CRFProcess* PCSGetFlow(); //OK//JT -extern CRFProcess* PCSGetHeat(); //JT -extern CRFProcess* PCSGetMass(size_t component_number); //JT -extern CRFProcess* PCSGetDeformation(); //JT -extern bool PCSConfig(); // +CRFProcess* PCSGet(FiniteElement::ProcessType pcs_type, const std::string& pv_name); + +// OK +extern CRFProcess* PCSGet(const std::string& variable_name, bool dummy); +extern CRFProcess* PCSGetFluxProcess(); // CMCD +extern CRFProcess* PCSGetFlow(); // OK//JT +extern CRFProcess* PCSGetHeat(); // JT +extern CRFProcess* PCSGetMass(size_t component_number); // JT +extern CRFProcess* PCSGetDeformation(); // JT +extern bool PCSConfig(); // // NOD -extern int PCSGetNODValueIndex(const std::string&,int); -extern double PCSGetNODValue(long,char*,int); -extern void PCSSetNODValue(long,const std::string&,double,int); +extern int PCSGetNODValueIndex(const std::string&, int); +extern double PCSGetNODValue(long, char*, int); +extern void PCSSetNODValue(long, const std::string&, double, int); // ELE extern int PCSGetELEValueIndex(char*); -extern double PCSGetELEValue(long index,double* gp,double theta,const std::string &nod_fct_name); +extern double PCSGetELEValue(long index, double* gp, double theta, const std::string& nod_fct_name); // Specials extern void PCSRestart(); extern std::string PCSProblemType(); @@ -1003,53 +993,50 @@ extern bool pcs_monolithic_flow; extern int pcs_deformation; // ToDo -//SB +// SB extern double PCSGetNODConcentration(long index, long component, long timelevel); -//SB +// SB extern void PCSSetNODConcentration(long index, long component, long timelevel, double value); -extern char* GetCompNamehelp(char* name); //SB:namepatch - superseded by GetPFNamebyCPName - //SB4218 +extern char* GetCompNamehelp(char* name); // SB:namepatch - superseded by GetPFNamebyCPName +// SB4218 extern double PCSGetEleMeanNodeSecondary(long index, - const std::string &pcs_name, - const std::string &var_name, + const std::string& pcs_name, + const std::string& var_name, int timelevel); -//CB -extern double PCSGetEleMeanNodeSecondary_2(long index, - int pcsT, - const std::string &var_name, - int timelevel); +// CB +extern double PCSGetEleMeanNodeSecondary_2(long index, int pcsT, const std::string& var_name, int timelevel); extern std::string GetPFNamebyCPName(std::string line_string); extern int memory_opt; -typedef struct /* Knotenwert-Informationen */ +typedef struct /* Knotenwert-Informationen */ { - char* name; /* Name der Knotengroesse */ - char* einheit; /* Einheit der Knotengroesse */ - int speichern; /* s.u., wird Wert gespeichert ? */ - int laden; /* s.u., wird Wert zu Beginn geladen ? */ - int restart; /* s.u., wird Wert bei Restart geladen ? */ - int adapt_interpol; /* Soll Wert bei Adaption auf Kinder interpoliert werden? */ - double vorgabe; /* Default-Wert fuer Initialisierung */ + char* name; /* Name der Knotengroesse */ + char* einheit; /* Einheit der Knotengroesse */ + int speichern; /* s.u., wird Wert gespeichert ? */ + int laden; /* s.u., wird Wert zu Beginn geladen ? */ + int restart; /* s.u., wird Wert bei Restart geladen ? */ + int adapt_interpol; /* Soll Wert bei Adaption auf Kinder interpoliert werden? */ + double vorgabe; /* Default-Wert fuer Initialisierung */ } NvalInfo; -extern int anz_nval; /* Anzahl der Knotenwerte */ -extern int anz_nval0; /* Anzahl der Knotenwerte */ +extern int anz_nval; /* Anzahl der Knotenwerte */ +extern int anz_nval0; /* Anzahl der Knotenwerte */ extern NvalInfo* nval_data; -extern int ModelsAddNodeValInfoStructure(char*,char*,int,int,int,int,double); +extern int ModelsAddNodeValInfoStructure(char*, char*, int, int, int, int, double); -typedef struct /* Elementwert-Informationen */ +typedef struct /* Elementwert-Informationen */ { - char* name; /* Name der Elementgroesse */ - char* einheit; /* Einheit der Elementgroesse */ - int speichern; /* s.u., wird Wert gespeichert ? */ - int laden; /* s.u., wird Wert zu Beginn geladen ? */ - int restart; /* s.u., wird Wert bei Restart geladen ? */ - int adapt_interpol; /* Soll Wert bei Adaption auf Kinder vererbt werden? */ - double vorgabe; /* Default-Wert fuer Initialisierung */ + char* name; /* Name der Elementgroesse */ + char* einheit; /* Einheit der Elementgroesse */ + int speichern; /* s.u., wird Wert gespeichert ? */ + int laden; /* s.u., wird Wert zu Beginn geladen ? */ + int restart; /* s.u., wird Wert bei Restart geladen ? */ + int adapt_interpol; /* Soll Wert bei Adaption auf Kinder vererbt werden? */ + double vorgabe; /* Default-Wert fuer Initialisierung */ } EvalInfo; -extern int anz_eval; /* Anzahl der Elementwerte */ +extern int anz_eval; /* Anzahl der Elementwerte */ extern EvalInfo* eval_data; -extern int ModelsAddElementValInfoStructure(char*,char*,int,int,int,int,double); +extern int ModelsAddElementValInfoStructure(char*, char*, int, int, int, int, double); extern int GetRFControlGridAdapt(void); extern int GetRFControlModel(void); @@ -1067,38 +1054,38 @@ extern int GetRFProcessNumElectricFields(void); extern int GetRFProcessNumTemperatures(void); extern int GetRFProcessSimulation(void); -extern void initializeConstrainedProcesses(std::vector &pcs_vector); +extern void initializeConstrainedProcesses(std::vector& pcs_vector); // Coupling Flag. WW -extern bool T_Process; // Heat -extern bool H_Process; // Fluid -extern bool H2_Process; // Multi-phase -extern bool H3_Process; // 3-phase -extern bool M_Process; // Mechanical -extern bool RD_Process; // Richards -extern bool MH_Process; // MH monolithic scheme -extern bool MASS_TRANSPORT_Process; // Mass transport -extern bool FLUID_MOMENTUM_Process; // Momentum -extern bool RANDOM_WALK_Process; // RWPT -extern bool MULTI_COMPONENTIAL_FLOW_Process; //MCF +extern bool T_Process; // Heat +extern bool H_Process; // Fluid +extern bool H2_Process; // Multi-phase +extern bool H3_Process; // 3-phase +extern bool M_Process; // Mechanical +extern bool RD_Process; // Richards +extern bool MH_Process; // MH monolithic scheme +extern bool MASS_TRANSPORT_Process; // Mass transport +extern bool FLUID_MOMENTUM_Process; // Momentum +extern bool RANDOM_WALK_Process; // RWPT +extern bool MULTI_COMPONENTIAL_FLOW_Process; // MCF // -extern int pcs_number_deformation; // JT2012 -extern int pcs_number_flow; // JT2012 -extern int pcs_number_heat; // JT2012 -extern std::vectorpcs_number_mass; // JT2012 (allow DOF_NUMBER_MAX components) +extern int pcs_number_deformation; // JT2012 +extern int pcs_number_flow; // JT2012 +extern int pcs_number_heat; // JT2012 +extern std::vector pcs_number_mass; // JT2012 (allow DOF_NUMBER_MAX components) // -extern std::string project_title; //OK41 +extern std::string project_title; // OK41 extern bool pcs_created; -extern std::vector PCS_Solver; //WW - //OK +extern std::vector PCS_Solver; // WW +// OK extern void MMPCalcSecondaryVariablesNew(CRFProcess* m_pcs, bool NAPLdiss); -extern void SetFlowProcessType(); //CB 01/08 -extern void CopyTimestepNODValuesSVTPhF(); //CB 13/08 +extern void SetFlowProcessType(); // CB 01/08 +extern void CopyTimestepNODValuesSVTPhF(); // CB 13/08 #if !defined(USE_PETSC) && !defined(NEW_EQS) // && defined(other parallel libs)//03~04.3012. WW //#ifndef NEW_EQS //WW. 07.11.2008 -extern void PCSCreateNew(); //OK +extern void PCSCreateNew(); // OK #endif -extern bool PCSCheck(); //OK +extern bool PCSCheck(); // OK // New solvers WW // Create sparse graph for each mesh //1.11.2007 WW #if defined(NEW_EQS) || defined(USE_PETSC) // || defined(other solver libs)//03.3012. WW @@ -1115,5 +1102,5 @@ class REACT_BRNS; extern REACT_BRNS* m_vec_BRNS; #endif -extern bool hasAnyProcessDeactivatedSubdomains; //NW +extern bool hasAnyProcessDeactivatedSubdomains; // NW #endif diff --git a/FEM/rf_pcs1.cpp b/FEM/rf_pcs1.cpp old mode 100755 new mode 100644 index 5642d5a4b..b8520e693 --- a/FEM/rf_pcs1.cpp +++ b/FEM/rf_pcs1.cpp @@ -14,14 +14,14 @@ for JFNK method */ -#if defined (NEW_EQS) && defined(JFNK_H2M) +#if defined(NEW_EQS) && defined(JFNK_H2M) #include "equation_class.h" #include "pcs_dm.h" #include "rf_pcs.h" #include #include -#include //WW +#include //WW #include using namespace std; @@ -38,13 +38,13 @@ void CRFProcess::Recovery_du_JFNK() long i, j; j = 0; - for(k = 0; k < pcs_number_of_primary_nvals; k++) + for (k = 0; k < pcs_number_of_primary_nvals; k++) { p_idx = p_var_index[k]; - if(k < problem_dimension_dm) + if (k < problem_dimension_dm) p_idx--; - for(i = 0; i < num_nodes_p_var[k]; i++) + for (i = 0; i < num_nodes_p_var[k]; i++) { SetNodeValue(i, p_idx, array_u_JFNK[j]); j++; @@ -53,10 +53,10 @@ void CRFProcess::Recovery_du_JFNK() /// Recovery Dirchlet BC /// 03.11.2010 - for(i = 0; i < (long)BC_JFNK.size(); i++) + for (i = 0; i < (long)BC_JFNK.size(); i++) { bc_JFNK bc_entry = BC_JFNK[i]; - if(bc_entry.incremental) + if (bc_entry.incremental) continue; SetNodeValue(bc_entry.bc_node, bc_entry.var_idx, GetNodeValue(bc_entry.bc_node, bc_entry.var_idx) - bc_entry.bc_value); @@ -76,20 +76,20 @@ bool CRFProcess::ForceTermCriterion(double* Jdx, const int num_iteration) double norm_f_pls_Jdx, f_factor = 0.5; bool done = false; - if(num_iteration) + if (num_iteration) f_factor = 0.1; /// Calculate ||J*dx+F(x)|| norm_f_pls_Jdx = 0.; double diff_v; - for(i = 0; i < eqs_new->size_global; i++) + for (i = 0; i < eqs_new->size_global; i++) { diff_v = Jdx[i] + array_Fu_JFNK[i]; - norm_f_pls_Jdx += diff_v * diff_v; + norm_f_pls_Jdx += diff_v * diff_v; } norm_f_pls_Jdx = sqrt(norm_f_pls_Jdx); - if(norm_f_pls_Jdx < f_factor * norm_F0) + if (norm_f_pls_Jdx < f_factor * norm_F0) done = true; return done; @@ -102,25 +102,25 @@ bool CRFProcess::ForceTermCriterion(double* Jdx, const int num_iteration) /// /// 10.2010. WW /////////////////////////////////////////////////////////////////////////////////// -void CRFProcess:: Jacobian_Multi_Vector_JFNK(double* v, double* Jv) +void CRFProcess::Jacobian_Multi_Vector_JFNK(double* v, double* Jv) { //---------------------------------------------------------------------- int k, p_idx; long i, j; - //float sign_rhs; + // float sign_rhs; bool HM = false; - if(problem_dimension_dm != pcs_number_of_primary_nvals) + if (problem_dimension_dm != pcs_number_of_primary_nvals) HM = true; /// Calculate F(u): u --> array_u_JFNK - if(v == NULL) + if (v == NULL) { BC_JFNK.clear(); JFNK_precond = false; /// Assemble Jacabin preconditioner - if(m_num->ls_precond == 1) + if (m_num->ls_precond == 1) { JFNK_precond = true; eqs_new->Init_Precond_Jacobi_JFNK(); @@ -129,7 +129,7 @@ void CRFProcess:: Jacobian_Multi_Vector_JFNK(double* v, double* Jv) /// Assemble F(u)--> eqs->f IncorporateBoundaryConditions(); GlobalAssembly(); - for(i = 0; i < (long)BC_JFNK.size(); i++) + for (i = 0; i < (long)BC_JFNK.size(); i++) { bc_JFNK bc_entry = BC_JFNK[i]; eqs_new->b[bc_entry.bc_eqs_idx] = bc_entry.bc_value; @@ -138,12 +138,12 @@ void CRFProcess:: Jacobian_Multi_Vector_JFNK(double* v, double* Jv) j = 0; /// Calculate norm_F0 for line search norm_F0 = 0.; - for(k = 0; k < pcs_number_of_primary_nvals; k++) - //sign_rhs = 1.0; - //if(k>=problem_dimension_dm) + for (k = 0; k < pcs_number_of_primary_nvals; k++) + // sign_rhs = 1.0; + // if(k>=problem_dimension_dm) // sign_rhs = -1.0; - for(i = 0; i < num_nodes_p_var[k]; i++) + for (i = 0; i < num_nodes_p_var[k]; i++) { array_Fu_JFNK[j] = -eqs_new->b[j]; norm_F0 += array_Fu_JFNK[j] * array_Fu_JFNK[j]; @@ -152,26 +152,26 @@ void CRFProcess:: Jacobian_Multi_Vector_JFNK(double* v, double* Jv) norm_F0 = sqrt(norm_F0); norm_u_JFNK[0] = 0.; - if(HM) + if (HM) norm_u_JFNK[1] = 0.; j = 0; - for(k = 0; k < pcs_number_of_primary_nvals; k++) + for (k = 0; k < pcs_number_of_primary_nvals; k++) { p_idx = p_var_index[k]; - if(k < problem_dimension_dm && HM) + if (k < problem_dimension_dm && HM) p_idx--; - for(i = 0; i < num_nodes_p_var[k]; i++) + for (i = 0; i < num_nodes_p_var[k]; i++) { array_u_JFNK[j] = GetNodeValue(i, p_idx); norm_u_JFNK[0] += array_u_JFNK[j] * array_u_JFNK[j]; j++; } - if((k == problem_dimension_dm - 1) && HM) + if ((k == problem_dimension_dm - 1) && HM) norm_u_JFNK[1] = norm_u_JFNK[0]; } - if(HM) + if (HM) { norm_u_JFNK[0] -= norm_u_JFNK[1]; norm_u_JFNK[1] = sqrt(norm_u_JFNK[1]); @@ -184,9 +184,9 @@ void CRFProcess:: Jacobian_Multi_Vector_JFNK(double* v, double* Jv) long size; double perturbation[2], pert = 0.; double norm_v[2]; -#define pert_2 +#define pert_2 #ifdef pert_2 - double b_fac = sqrt(DBL_EPSILON); + double b_fac = sqrt(DBL_EPSILON); #endif double pert_defalt = sqrt(DBL_EPSILON); int num_pcs = 1; @@ -196,17 +196,17 @@ void CRFProcess:: Jacobian_Multi_Vector_JFNK(double* v, double* Jv) norm_v[0] = norm_v[1] = 0.; j = 0; - for(k = 0; k < pcs_number_of_primary_nvals; k++) + for (k = 0; k < pcs_number_of_primary_nvals; k++) { - for(i = 0; i < num_nodes_p_var[k]; i++) + for (i = 0; i < num_nodes_p_var[k]; i++) { norm_v[0] += v[j] * v[j]; j++; } - if((k == problem_dimension_dm - 1) && HM) + if ((k == problem_dimension_dm - 1) && HM) norm_v[1] = norm_v[0]; } - if(HM) + if (HM) { norm_v[0] -= norm_v[1]; norm_v[1] = sqrt(norm_v[1]); @@ -215,46 +215,44 @@ void CRFProcess:: Jacobian_Multi_Vector_JFNK(double* v, double* Jv) norm_v[0] = sqrt(norm_v[0]); size = j; - if((norm_v[0] + norm_v[1]) > DBL_MIN) + if ((norm_v[0] + norm_v[1]) > DBL_MIN) { #define apert_a #ifdef pert_a - for(k = 0; k < num_pcs; k++) + for (k = 0; k < num_pcs; k++) { - if(norm_v[k] > DBL_MIN) + if (norm_v[k] > DBL_MIN) { -#define apert_2 +#define apert_2 #ifdef pert_2 perturbation[k] = 0.; - for(i = 0; i < size; i++) + for (i = 0; i < size; i++) perturbation[k] += fabs(array_u_JFNK[i]); - perturbation[k] = b_fac * perturbation[k] / - (norm_v[k] * size) + b_fac; - if(perturbation[k] < DBL_MIN) + perturbation[k] = b_fac * perturbation[k] / (norm_v[k] * size) + b_fac; + if (perturbation[k] < DBL_MIN) perturbation[k] = pert_defalt; #else - perturbation[k] = - sqrt((1. + norm_u_JFNK[k]) * sqrt(DBL_EPSILON)) / norm_v[k]; + perturbation[k] = sqrt((1. + norm_u_JFNK[k]) * sqrt(DBL_EPSILON)) / norm_v[k]; #endif - if(perturbation[k] < DBL_MIN) + if (perturbation[k] < DBL_MIN) perturbation[k] = pert_defalt; } else perturbation[k] = pert_defalt; } -#else //pert_b +#else // pert_b double udv[2], uv[2], suv[2], typu[2], sign = 1.; - for(k = 0; k < num_pcs; k++) + for (k = 0; k < num_pcs; k++) { udv[k] = uv[k] = suv[k] = 0.; - typu[k] = 0.; + typu[k] = 0.; } j = 0; - for(k = 0; k < pcs_number_of_primary_nvals; k++) + for (k = 0; k < pcs_number_of_primary_nvals; k++) { - for(i = 0; i < num_nodes_p_var[k]; i++) + for (i = 0; i < num_nodes_p_var[k]; i++) { udv[0] += fabs(array_u_JFNK[j] * v[j]); uv[0] += fabs(v[j]); @@ -263,7 +261,7 @@ void CRFProcess:: Jacobian_Multi_Vector_JFNK(double* v, double* Jv) typu[0] = max(typu[0], fabs(array_u_JFNK[j])); j++; } - if((k == problem_dimension_dm - 1) && HM) + if ((k == problem_dimension_dm - 1) && HM) { udv[1] = udv[0]; uv[1] = uv[0]; @@ -271,7 +269,7 @@ void CRFProcess:: Jacobian_Multi_Vector_JFNK(double* v, double* Jv) typu[1] = typu[0]; } } - if(HM) + if (HM) { udv[0] -= udv[1]; uv[0] -= uv[1]; @@ -279,41 +277,40 @@ void CRFProcess:: Jacobian_Multi_Vector_JFNK(double* v, double* Jv) swap(typu[0], typu[1]); } - for(k = 0; k < num_pcs; k++) + for (k = 0; k < num_pcs; k++) { - if(norm_v[k] > DBL_MIN) + if (norm_v[k] > DBL_MIN) { - if(fabs(suv[k]) > DBL_EPSILON) + if (fabs(suv[k]) > DBL_EPSILON) sign = fabs(suv[k]) / suv[k]; else sign = 1.0; - perturbation[k] = sign * b_fac * - max(udv[k], typu[k] * uv[k]) / norm_v[k]; + perturbation[k] = sign * b_fac * max(udv[k], typu[k] * uv[k]) / norm_v[k]; } else perturbation[k] = pert_defalt; - if(perturbation[k] < DBL_MIN) + if (perturbation[k] < DBL_MIN) perturbation[k] = pert_defalt; } #endif /// Initialize rhs - for(i = 0; i < eqs_new->size_global; i++) - eqs_new->b[i] = 0.0; ///-F(u) + for (i = 0; i < eqs_new->size_global; i++) + eqs_new->b[i] = 0.0; ///-F(u) - //TEST + // TEST perturbation[0] = sqrt(DBL_EPSILON); - ///1. For PDEs excluding that of deformation. 24.22.2010 + /// 1. For PDEs excluding that of deformation. 24.22.2010 j = 0; - for(k = 0; k < pcs_number_of_primary_nvals; k++) + for (k = 0; k < pcs_number_of_primary_nvals; k++) { p_idx = p_var_index[k]; - if(k < problem_dimension_dm && HM) + if (k < problem_dimension_dm && HM) p_idx--; - for(i = 0; i < num_nodes_p_var[k]; i++) + for (i = 0; i < num_nodes_p_var[k]; i++) { SetNodeValue(i, p_idx, array_u_JFNK[j] + perturbation[0] * v[j]); j++; @@ -322,40 +319,38 @@ void CRFProcess:: Jacobian_Multi_Vector_JFNK(double* v, double* Jv) /// Assemble F(u+epsilon*v) and calculate F(u+epsilon*v)-F(u) /// Apply Dirchlet BC. u_b --> node_value /// 01.11.2010 - for(i = 0; i < (long)BC_JFNK.size(); i++) + for (i = 0; i < (long)BC_JFNK.size(); i++) { bc_JFNK bc_entry = BC_JFNK[i]; - if(!bc_entry.incremental) + if (!bc_entry.incremental) continue; SetNodeValue(bc_entry.bc_node, bc_entry.var_idx, bc_entry.bc_value0); } GlobalAssembly_std(true); - ///2. For the PDE of deformation - if(HM) + /// 2. For the PDE of deformation + if (HM) { j = 0; - for(k = 0; k < pcs_number_of_primary_nvals; k++) + for (k = 0; k < pcs_number_of_primary_nvals; k++) { p_idx = p_var_index[k]; - if(k < problem_dimension_dm && HM) + if (k < problem_dimension_dm && HM) p_idx--; - for(i = 0; i < num_nodes_p_var[k]; i++) + for (i = 0; i < num_nodes_p_var[k]; i++) { - SetNodeValue(i, - p_idx, - array_u_JFNK[j] + perturbation[1] * v[j]); + SetNodeValue(i, p_idx, array_u_JFNK[j] + perturbation[1] * v[j]); j++; } } /// Assemble F(u+epsilon*v) and calculate F(u+epsilon*v)-F(u) /// Apply Dirchlet BC. u_b --> node_value /// 01.11.2010 - for(i = 0; i < (long)BC_JFNK.size(); i++) + for (i = 0; i < (long)BC_JFNK.size(); i++) { bc_JFNK bc_entry = BC_JFNK[i]; - if(bc_entry.incremental) + if (bc_entry.incremental) continue; SetNodeValue(bc_entry.bc_node, bc_entry.var_idx, bc_entry.bc_value); } @@ -371,20 +366,20 @@ void CRFProcess:: Jacobian_Multi_Vector_JFNK(double* v, double* Jv) */ j = 0; - for(k = 0; k < pcs_number_of_primary_nvals; k++) + for (k = 0; k < pcs_number_of_primary_nvals; k++) { - //sign_rhs = 1.0; - //if(k>=problem_dimension_dm) + // sign_rhs = 1.0; + // if(k>=problem_dimension_dm) // sign_rhs = -1.0; - if(k < problem_dimension_dm && HM) + if (k < problem_dimension_dm && HM) pert = perturbation[1]; else pert = perturbation[0]; - for(i = 0; i < num_nodes_p_var[k]; i++) + for (i = 0; i < num_nodes_p_var[k]; i++) { - ///Jv + /// Jv Jv[j] = (-eqs_new->b[j] - array_Fu_JFNK[j]) / pert; j++; } @@ -392,18 +387,18 @@ void CRFProcess:: Jacobian_Multi_Vector_JFNK(double* v, double* Jv) /// Apply Dirchlet BC. x_i = x_i^0 as /// F(u_u) = F(u_i) x_i = F(u_i)*x_i^0 = b_i /// 20.09.2010 - for(i = 0; i < (long)BC_JFNK.size(); i++) + for (i = 0; i < (long)BC_JFNK.size(); i++) { bc_JFNK bc_entry = BC_JFNK[i]; Jv[bc_entry.bc_eqs_idx] = v[bc_entry.bc_eqs_idx]; } } - else /// If x is zero. + else /// If x is zero. { j = 0; - for(k = 0; k < pcs_number_of_primary_nvals; k++) + for (k = 0; k < pcs_number_of_primary_nvals; k++) - for(i = 0; i < num_nodes_p_var[k]; i++) + for (i = 0; i < num_nodes_p_var[k]; i++) { Jv[j] = 0.; j++; @@ -423,32 +418,32 @@ double CRFProcess::LineSearch() int k, p_idx; long i, j; double damping = 1.0; - //float sign_rhs; + // float sign_rhs; bool HM = false; - if(problem_dimension_dm != pcs_number_of_primary_nvals) + if (problem_dimension_dm != pcs_number_of_primary_nvals) HM = true; - for(;; ) + for (;;) { /// Initialize rhs - for(i = 0; i < eqs_new->size_global; i++) - eqs_new->b[i] = 0.0; ///-F(u) + for (i = 0; i < eqs_new->size_global; i++) + eqs_new->b[i] = 0.0; ///-F(u) j = 0; - for(k = 0; k < pcs_number_of_primary_nvals; k++) + for (k = 0; k < pcs_number_of_primary_nvals; k++) { p_idx = p_var_index[k]; - if(k < problem_dimension_dm && HM) + if (k < problem_dimension_dm && HM) p_idx--; - for(i = 0; i < num_nodes_p_var[k]; i++) + for (i = 0; i < num_nodes_p_var[k]; i++) { SetNodeValue(i, p_idx, array_u_JFNK[j] + damping * eqs_new->x[j]); j++; } } GlobalAssembly(); - for(i = 0; i < (long)BC_JFNK.size(); i++) + for (i = 0; i < (long)BC_JFNK.size(); i++) { bc_JFNK bc_entry = BC_JFNK[i]; eqs_new->b[bc_entry.bc_eqs_idx] = bc_entry.bc_value; @@ -456,15 +451,15 @@ double CRFProcess::LineSearch() double normFplsX = 0.; /// j is the size of the vector - for(i = 0; i < j; i++) + for (i = 0; i < j; i++) normFplsX += eqs_new->b[i] * eqs_new->b[i]; - if(sqrt(normFplsX) < norm_F0) + if (sqrt(normFplsX) < norm_F0) break; else damping *= 0.5; /// If the damping is too small, jump out - if(damping < 1.e-3) + if (damping < 1.e-3) break; } @@ -497,41 +492,41 @@ using namespace FiniteElement; */ void CRFProcess::InitializeRHS_with_u0(const bool quad) { - initializeRHS_with_u0( 0, m_msh->getNumNodesLocal() ); + initializeRHS_with_u0(0, m_msh->getNumNodesLocal()); - if(quad) - { - initializeRHS_with_u0( m_msh-> GetNodesNumber(false), - static_cast(m_msh->getLargestActiveNodeID_Quadratic()) ); - } + if (quad) + { + initializeRHS_with_u0(m_msh->GetNodesNumber(false), + static_cast(m_msh->getLargestActiveNodeID_Quadratic())); + } - eqs_new->AssembleUnkowns_PETSc(); - } + eqs_new->AssembleUnkowns_PETSc(); +} -void CRFProcess::initializeRHS_with_u0(const int min_id, const int max_id) +void CRFProcess::initializeRHS_with_u0(const int min_id, const int max_id) { - vector ix; - vector val; - int nidx1; - - const int size = (max_id - min_id) * pcs_number_of_primary_nvals; - ix.resize(size); - val.resize(size); - - int counter = 0; - for (int i = 0; i < pcs_number_of_primary_nvals; i++) - { - //new time - nidx1 = GetNodeValueIndex(pcs_primary_function_name[i]) + 1; - for (int j = min_id; j < max_id; j++) - { - ix[counter] = pcs_number_of_primary_nvals*m_msh->Eqs2Global_NodeIndex[j] + i; - val[counter] = GetNodeValue(j, nidx1); - counter++; - } - } - // Assign u0 to x - eqs_new->setArrayValues(0, size, &ix[0], &val[0], INSERT_VALUES); + vector ix; + vector val; + int nidx1; + + const int size = (max_id - min_id) * pcs_number_of_primary_nvals; + ix.resize(size); + val.resize(size); + + int counter = 0; + for (int i = 0; i < pcs_number_of_primary_nvals; i++) + { + // new time + nidx1 = GetNodeValueIndex(pcs_primary_function_name[i]) + 1; + for (int j = min_id; j < max_id; j++) + { + ix[counter] = pcs_number_of_primary_nvals * m_msh->Eqs2Global_NodeIndex[j] + i; + val[counter] = GetNodeValue(j, nidx1); + counter++; + } + } + // Assign u0 to x + eqs_new->setArrayValues(0, size, &ix[0], &val[0], INSERT_VALUES); } /* @@ -541,138 +536,136 @@ void CRFProcess::initializeRHS_with_u0(const int min_id, const int max_id) */ double CRFProcess::CalcIterationNODError(int method) { - static long i, g_nnodes; - static double error_l, change_l, max_cl, min_cl; - static double error, change, max_c, min_c; - //----------------------------------------------------- - int nidx1; - int ii; - g_nnodes = m_msh->getNumNodesLocal(); - //----------------------------------------------------- - //double* eqs_x = NULL; // local solution - - error_l = 0.; - change_l = 0.; - - max_cl = 0.; - min_cl = 1.e99; - - double val = 0.; - switch (method) - { - default: - case 0: - return 0.; - // Maximum error - case 1: - // - for(ii = 0; ii < pcs_number_of_primary_nvals; ii++) + static long i, g_nnodes; + static double error_l, change_l, max_cl, min_cl; + static double error, change, max_c, min_c; + //----------------------------------------------------- + int nidx1; + int ii; + g_nnodes = m_msh->getNumNodesLocal(); + //----------------------------------------------------- + // double* eqs_x = NULL; // local solution + + error_l = 0.; + change_l = 0.; + + max_cl = 0.; + min_cl = 1.e99; + + double val = 0.; + switch (method) { - //new time - nidx1 = GetNodeValueIndex(pcs_primary_function_name[ii]) + 1; - for (i = 0l; i < g_nnodes; i++) - { - val = eqs_x[pcs_number_of_primary_nvals*m_msh->Eqs2Global_NodeIndex[i] + ii]; - error_l = max(error_l, fabs(GetNodeValue(i, nidx1) - val)); - } - } - MPI_Allreduce(&error_l, &error, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD); - break; - case 2: - for(ii = 0; ii < pcs_number_of_primary_nvals; ii++) - { - //new time - nidx1 = GetNodeValueIndex(pcs_primary_function_name[ii]) + 1; - for (i = 0l; i < g_nnodes; i++) - { - val = eqs_x[pcs_number_of_primary_nvals*m_msh->Eqs2Global_NodeIndex[i] + ii]; - error_l = max(error_l, fabs(val - GetNodeValue(i, nidx1)) - / (fabs(val) + fabs(GetNodeValue(i, nidx1)) + MKleinsteZahl) ); - } - } - MPI_Allreduce(&error_l, &error, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD); - break; - case 3: - for(ii = 0; ii < pcs_number_of_primary_nvals; ii++) - { - //new time - nidx1 = GetNodeValueIndex(pcs_primary_function_name[ii]) + 1; - for (i = 0l; i < g_nnodes; i++) - { - val = eqs_x[pcs_number_of_primary_nvals*m_msh->Eqs2Global_NodeIndex[i] + ii]; - error_l = max(error_l, fabs(val - GetNodeValue(i, nidx1))); - max_cl = max(max(max_cl, fabs(fabs( val ))), fabs(GetNodeValue(i, nidx1))); - } - } - MPI_Allreduce(&error_l, &error, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD); - MPI_Allreduce(&max_cl, &max_c, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD); - error /= (max_c + MKleinsteZahl); - break; - case 4: - for(ii = 0; ii < pcs_number_of_primary_nvals; ii++) - { - //new time - nidx1 = GetNodeValueIndex(pcs_primary_function_name[ii]) + 1; - for (i = 0l; i < g_nnodes; i++) - { - val = eqs_x[pcs_number_of_primary_nvals*m_msh->Eqs2Global_NodeIndex[i] + ii]; - error_l = - max(error_l, fabs(val - GetNodeValue(i, nidx1))); - min_cl = min(min_cl, fabs(val)); - max_cl = max(max_cl, fabs(val)); - } - } - MPI_Allreduce(&error_l, &error, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD); - MPI_Allreduce(&max_cl, &max_c, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD); - MPI_Allreduce(&min_cl, &min_c, 1, MPI_DOUBLE, MPI_MIN, MPI_COMM_WORLD); - error /= (max_c - min_c + MKleinsteZahl); - break; - case 5: - // - for(ii = 0; ii < pcs_number_of_primary_nvals; ii++) - { - //new time - nidx1 = GetNodeValueIndex(pcs_primary_function_name[ii]) + 1; - for (i = 0l; i < g_nnodes; i++) - { - val = eqs_x[pcs_number_of_primary_nvals*m_msh->Eqs2Global_NodeIndex[i] + ii]; - error_l = max(error_l, fabs(val - GetNodeValue(i, nidx1)) - / (fabs(val - GetNodeValue(i, nidx1 - 1)) + MKleinsteZahl)); - } - } - MPI_Allreduce(&error_l, &error, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD); - break; - case 6: - for(ii = 0; ii < pcs_number_of_primary_nvals; ii++) - { - //new time - nidx1 = GetNodeValueIndex(pcs_primary_function_name[ii]) + 1; - for (i = 0l; i < g_nnodes; i++) - { - val = eqs_x[pcs_number_of_primary_nvals*m_msh->Eqs2Global_NodeIndex[i] + ii]; - error_l = max(error_l, fabs(val - GetNodeValue(i, nidx1))); - change_l = max(change_l, fabs(val - GetNodeValue(i, nidx1 - 1))); - } + default: + case 0: + return 0.; + // Maximum error + case 1: + // + for (ii = 0; ii < pcs_number_of_primary_nvals; ii++) + { + // new time + nidx1 = GetNodeValueIndex(pcs_primary_function_name[ii]) + 1; + for (i = 0l; i < g_nnodes; i++) + { + val = eqs_x[pcs_number_of_primary_nvals * m_msh->Eqs2Global_NodeIndex[i] + ii]; + error_l = max(error_l, fabs(GetNodeValue(i, nidx1) - val)); + } + } + MPI_Allreduce(&error_l, &error, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD); + break; + case 2: + for (ii = 0; ii < pcs_number_of_primary_nvals; ii++) + { + // new time + nidx1 = GetNodeValueIndex(pcs_primary_function_name[ii]) + 1; + for (i = 0l; i < g_nnodes; i++) + { + val = eqs_x[pcs_number_of_primary_nvals * m_msh->Eqs2Global_NodeIndex[i] + ii]; + error_l = max(error_l, fabs(val - GetNodeValue(i, nidx1)) + / (fabs(val) + fabs(GetNodeValue(i, nidx1)) + MKleinsteZahl)); + } + } + MPI_Allreduce(&error_l, &error, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD); + break; + case 3: + for (ii = 0; ii < pcs_number_of_primary_nvals; ii++) + { + // new time + nidx1 = GetNodeValueIndex(pcs_primary_function_name[ii]) + 1; + for (i = 0l; i < g_nnodes; i++) + { + val = eqs_x[pcs_number_of_primary_nvals * m_msh->Eqs2Global_NodeIndex[i] + ii]; + error_l = max(error_l, fabs(val - GetNodeValue(i, nidx1))); + max_cl = max(max(max_cl, fabs(fabs(val))), fabs(GetNodeValue(i, nidx1))); + } + } + MPI_Allreduce(&error_l, &error, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD); + MPI_Allreduce(&max_cl, &max_c, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD); + error /= (max_c + MKleinsteZahl); + break; + case 4: + for (ii = 0; ii < pcs_number_of_primary_nvals; ii++) + { + // new time + nidx1 = GetNodeValueIndex(pcs_primary_function_name[ii]) + 1; + for (i = 0l; i < g_nnodes; i++) + { + val = eqs_x[pcs_number_of_primary_nvals * m_msh->Eqs2Global_NodeIndex[i] + ii]; + error_l = max(error_l, fabs(val - GetNodeValue(i, nidx1))); + min_cl = min(min_cl, fabs(val)); + max_cl = max(max_cl, fabs(val)); + } + } + MPI_Allreduce(&error_l, &error, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD); + MPI_Allreduce(&max_cl, &max_c, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD); + MPI_Allreduce(&min_cl, &min_c, 1, MPI_DOUBLE, MPI_MIN, MPI_COMM_WORLD); + error /= (max_c - min_c + MKleinsteZahl); + break; + case 5: + // + for (ii = 0; ii < pcs_number_of_primary_nvals; ii++) + { + // new time + nidx1 = GetNodeValueIndex(pcs_primary_function_name[ii]) + 1; + for (i = 0l; i < g_nnodes; i++) + { + val = eqs_x[pcs_number_of_primary_nvals * m_msh->Eqs2Global_NodeIndex[i] + ii]; + error_l = max(error_l, fabs(val - GetNodeValue(i, nidx1)) + / (fabs(val - GetNodeValue(i, nidx1 - 1)) + MKleinsteZahl)); + } + } + MPI_Allreduce(&error_l, &error, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD); + break; + case 6: + for (ii = 0; ii < pcs_number_of_primary_nvals; ii++) + { + // new time + nidx1 = GetNodeValueIndex(pcs_primary_function_name[ii]) + 1; + for (i = 0l; i < g_nnodes; i++) + { + val = eqs_x[pcs_number_of_primary_nvals * m_msh->Eqs2Global_NodeIndex[i] + ii]; + error_l = max(error_l, fabs(val - GetNodeValue(i, nidx1))); + change_l = max(change_l, fabs(val - GetNodeValue(i, nidx1 - 1))); + } + } + MPI_Allreduce(&error_l, &error, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD); + MPI_Allreduce(&change_l, &change, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD); + error /= (change + MKleinsteZahl); + break; } - MPI_Allreduce(&error_l, &error, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD); - MPI_Allreduce(&change_l, &change, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD); - error /= (change + MKleinsteZahl); - break; - } - return error; + return error; } - /// Set PETSc solver. 10.2012. WW -void CRFProcess::setSolver( petsc_group::PETScLinearSolver *petsc_solver ) +void CRFProcess::setSolver(petsc_group::PETScLinearSolver* petsc_solver) { - eqs_new = petsc_solver; - eqs_new->Config(m_num->ls_error_tolerance, - m_num->ls_max_iterations, - m_num->getLinearSolverName(), - m_num->getPreconditionerName(), - convertProcessTypeToString(this->getProcessType())+"_"); + eqs_new = petsc_solver; + eqs_new->Config(m_num->ls_error_tolerance, + m_num->ls_max_iterations, + m_num->getLinearSolverName(), + m_num->getPreconditionerName(), + convertProcessTypeToString(this->getProcessType()) + "_"); } //------------------------------------------------------------ /*! @@ -682,103 +675,95 @@ void CRFProcess::setSolver( petsc_group::PETScLinearSolver *petsc_solver ) */ void CreateEQS_LinearSolver() { - int sparse_info[4]; - int max_cnct_nodes; - int rank_p; - int size_p; - size_t i; - CRFProcess* a_pcs = NULL; - FiniteElement::ProcessType pcs_type = MULTI_PHASE_FLOW; - MeshLib::CFEMesh *mesh = fem_msh_vector[0]; - - - MPI_Comm_rank(PETSC_COMM_WORLD, &rank_p); - MPI_Comm_size(PETSC_COMM_WORLD, &size_p); - - - max_cnct_nodes = mesh->calMaximumConnectedNodes(); - - const int nn = mesh->getNumNodesGlobal(); - const int nn_q = mesh->getNumNodesGlobal_Q(); - //const int nnl = mesh->getNumNodesLocal(); - //const int nnl_q = mesh->getNumNodesLocal_Q(); - int dim = mesh->GetMaxElementDim(); - - - const size_t npcs = pcs_vector.size(); - for(i = 0; i < npcs; i++) - { - a_pcs = pcs_vector[i]; - pcs_type = a_pcs->getProcessType(); - - PETScLinearSolver *eqs = NULL; - - if( pcs_type == FLUID_MOMENTUM ) - { - continue; - } - - if( (pcs_type == DEFORMATION_H2) - ||(pcs_type == DEFORMATION_FLOW) - ||(pcs_type == DEFORMATION_DYNAMIC) - ||(pcs_type == DEFORMATION) ) - { - int eqs_dim = nn_q*dim; - vector global_n_id; - if(pcs_type == DEFORMATION_H2) - { - eqs_dim += 2*nn; - } - else if( (pcs_type == DEFORMATION_FLOW) - ||(pcs_type == DEFORMATION_DYNAMIC) ) - eqs_dim += nn; - - sparse_info[0] = max_cnct_nodes * dim; - sparse_info[1] = max_cnct_nodes * dim; - sparse_info[2] = max_cnct_nodes * dim; - sparse_info[3] = mesh->getNumNodesLocal_Q() * dim; - eqs = new PETScLinearSolver(eqs_dim); - eqs->Init(sparse_info); - eqs->set_rank_size(rank_p, size_p); - } - else if( (pcs_type == MULTI_PHASE_FLOW) - ||(pcs_type == TWO_PHASE_FLOW) - ||(pcs_type == PS_GLOBAL) ) - { - sparse_info[0] = max_cnct_nodes * 2; - sparse_info[1] = max_cnct_nodes * 2; - sparse_info[2] = max_cnct_nodes * 2; - sparse_info[3] = mesh->getNumNodesLocal() * 2; - - eqs = new PETScLinearSolver(2 * nn); - eqs->Init(sparse_info); - eqs->set_rank_size(rank_p, size_p); - } - else if( pcs_type == TES) - { - sparse_info[0] = max_cnct_nodes * 3; - sparse_info[1] = max_cnct_nodes * 3; - sparse_info[2] = max_cnct_nodes * 3; - sparse_info[3] = mesh->getNumNodesLocal() * 3; - - eqs = new PETScLinearSolver(3 * nn); - eqs->Init(sparse_info); - eqs->set_rank_size(rank_p, size_p); - } - //else if( pcs_type == FLUID_MOMENTUM ) {} - else - { - sparse_info[0] = max_cnct_nodes; - sparse_info[1] = max_cnct_nodes; - sparse_info[2] = max_cnct_nodes; - sparse_info[3] = mesh->getNumNodesLocal(); - - eqs = new PETScLinearSolver(nn); - eqs->Init(sparse_info); - eqs->set_rank_size(rank_p, size_p); - } - a_pcs->setSolver(eqs); - } + int sparse_info[4]; + int max_cnct_nodes; + int rank_p; + int size_p; + size_t i; + CRFProcess* a_pcs = NULL; + FiniteElement::ProcessType pcs_type = MULTI_PHASE_FLOW; + MeshLib::CFEMesh* mesh = fem_msh_vector[0]; + + MPI_Comm_rank(PETSC_COMM_WORLD, &rank_p); + MPI_Comm_size(PETSC_COMM_WORLD, &size_p); + + max_cnct_nodes = mesh->calMaximumConnectedNodes(); + + const int nn = mesh->getNumNodesGlobal(); + const int nn_q = mesh->getNumNodesGlobal_Q(); + // const int nnl = mesh->getNumNodesLocal(); + // const int nnl_q = mesh->getNumNodesLocal_Q(); + int dim = mesh->GetMaxElementDim(); + + const size_t npcs = pcs_vector.size(); + for (i = 0; i < npcs; i++) + { + a_pcs = pcs_vector[i]; + pcs_type = a_pcs->getProcessType(); + + PETScLinearSolver* eqs = NULL; + + if (pcs_type == FLUID_MOMENTUM) + { + continue; + } + + if ((pcs_type == DEFORMATION_H2) || (pcs_type == DEFORMATION_FLOW) || (pcs_type == DEFORMATION_DYNAMIC) + || (pcs_type == DEFORMATION)) + { + int eqs_dim = nn_q * dim; + vector global_n_id; + if (pcs_type == DEFORMATION_H2) + { + eqs_dim += 2 * nn; + } + else if ((pcs_type == DEFORMATION_FLOW) || (pcs_type == DEFORMATION_DYNAMIC)) + eqs_dim += nn; + + sparse_info[0] = max_cnct_nodes * dim; + sparse_info[1] = max_cnct_nodes * dim; + sparse_info[2] = max_cnct_nodes * dim; + sparse_info[3] = mesh->getNumNodesLocal_Q() * dim; + eqs = new PETScLinearSolver(eqs_dim); + eqs->Init(sparse_info); + eqs->set_rank_size(rank_p, size_p); + } + else if ((pcs_type == MULTI_PHASE_FLOW) || (pcs_type == TWO_PHASE_FLOW) || (pcs_type == PS_GLOBAL)) + { + sparse_info[0] = max_cnct_nodes * 2; + sparse_info[1] = max_cnct_nodes * 2; + sparse_info[2] = max_cnct_nodes * 2; + sparse_info[3] = mesh->getNumNodesLocal() * 2; + + eqs = new PETScLinearSolver(2 * nn); + eqs->Init(sparse_info); + eqs->set_rank_size(rank_p, size_p); + } + else if (pcs_type == TES) + { + sparse_info[0] = max_cnct_nodes * 3; + sparse_info[1] = max_cnct_nodes * 3; + sparse_info[2] = max_cnct_nodes * 3; + sparse_info[3] = mesh->getNumNodesLocal() * 3; + + eqs = new PETScLinearSolver(3 * nn); + eqs->Init(sparse_info); + eqs->set_rank_size(rank_p, size_p); + } + // else if( pcs_type == FLUID_MOMENTUM ) {} + else + { + sparse_info[0] = max_cnct_nodes; + sparse_info[1] = max_cnct_nodes; + sparse_info[2] = max_cnct_nodes; + sparse_info[3] = mesh->getNumNodesLocal(); + + eqs = new PETScLinearSolver(nn); + eqs->Init(sparse_info); + eqs->set_rank_size(rank_p, size_p); + } + a_pcs->setSolver(eqs); + } } #endif diff --git a/FEM/rf_random_walk.cpp b/FEM/rf_random_walk.cpp index 37119b9db..51d22bf2d 100644 --- a/FEM/rf_random_walk.cpp +++ b/FEM/rf_random_walk.cpp @@ -33,7 +33,13 @@ using namespace std; using namespace Math_Group; #define PCT_FILE_EXTENSION ".pct" -#define SWAP(x,y) {double t; t = x; x = y; y = t; } //WW data type is change to double +#define SWAP(x, y) \ + { \ + double t; \ + t = x; \ + x = y; \ + y = t; \ + } // WW data type is change to double //#define CountParticleNumber //YS: to count the number of particles leave the domain /************************************************************************** @@ -51,41 +57,40 @@ RandomWalk::RandomWalk(int srand_seed) // This is going to be reset by user input. // Further, used for allocating dynamic memory. numOfParticles = 0; - leavingParticles = 0; //YS: to count the number of particles in the outflow - UniformOrNormal = 1; // Uniform random number generation - RWPTMode = 0; // Initialized to be homogeneous media + leavingParticles = 0; // YS: to count the number of particles in the outflow + UniformOrNormal = 1; // Uniform random number generation + RWPTMode = 0; // Initialized to be homogeneous media PURERWPT = 0; CurrentTime = 0.0; FDMIndexSwitch = 0; GridOption = 0; - ChanceOfIrreversed = NULL; //YS: judgement for decay + ChanceOfIrreversed = NULL; // YS: judgement for decay // To produce a different pseudo-random series each time your program is run. - if(srand_seed == 0) + if (srand_seed == 0) srand((int)time(0)); // To produce same pseudo-random series each time your program is run. - else if(srand_seed == 1) + else if (srand_seed == 1) srand(1); // These are the allowable outputs (input as options to file .out rwpt_out_strings.push_back("PARTICLES"); // output particle locations - // output particles as elemental concentration + // output particles as elemental concentration rwpt_out_strings.push_back("PARTICLE_CONCENTRATION"); - //FM_TEST - flow_pcs = NULL; - for (size_t i = 0; i < pcs_vector.size(); i++) - { - CRFProcess *pcs_e = pcs_vector[i]; - if ( pcs_e->getProcessType() == FiniteElement::GROUNDWATER_FLOW - || pcs_e->getProcessType() == FiniteElement::LIQUID_FLOW - || pcs_e->getProcessType() == FiniteElement::RICHARDS_FLOW - || pcs_e->getProcessType() == FiniteElement::MULTI_PHASE_FLOW - || pcs_e->getProcessType() == FiniteElement::TWO_PHASE_FLOW - ) - { - flow_pcs = pcs_e; - break; - } + // FM_TEST + flow_pcs = NULL; + for (size_t i = 0; i < pcs_vector.size(); i++) + { + CRFProcess* pcs_e = pcs_vector[i]; + if (pcs_e->getProcessType() == FiniteElement::GROUNDWATER_FLOW + || pcs_e->getProcessType() == FiniteElement::LIQUID_FLOW + || pcs_e->getProcessType() == FiniteElement::RICHARDS_FLOW + || pcs_e->getProcessType() == FiniteElement::MULTI_PHASE_FLOW + || pcs_e->getProcessType() == FiniteElement::TWO_PHASE_FLOW) + { + flow_pcs = pcs_e; + break; + } } } @@ -101,13 +106,13 @@ Particle::Particle(void) dVxdx = dVydy = dVzdz = 0.0; - for(int i = 0; i < 9; ++i) + for (int i = 0; i < 9; ++i) D[i] = 0.0; // Time t = 0.0; identity = 0; - on_boundary = 0; //YS + on_boundary = 0; // YS } /************************************************************************** @@ -120,8 +125,8 @@ Particle::Particle(void) RandomWalk::~RandomWalk(void) { // if(X) delete [] X; - if(ChanceOfIrreversed) - delete [] ChanceOfIrreversed; + if (ChanceOfIrreversed) + delete[] ChanceOfIrreversed; ChanceOfIrreversed = NULL; } @@ -147,18 +152,18 @@ double RandomWalk::Marsaglia(void) do { // Create two random numbers which are uniform between 0 to 1. - u1 = (double) (1.0 * rand() / (RAND_MAX + 1.0)); - u2 = (double) (1.0 * rand() / (RAND_MAX + 1.0)); + u1 = (double)(1.0 * rand() / (RAND_MAX + 1.0)); + u2 = (double)(1.0 * rand() / (RAND_MAX + 1.0)); v1 = 2. * u1 - 1.0; v2 = 2. * u2 - 1.0; s = v1 * v1 + v2 * v2; - } while (s >= 1.0 || s == 0.0); // To fit log definition + } while (s >= 1.0 || s == 0.0); // To fit log definition double fac = sqrt(-2.0 * log(s) / s); // This will create either 0 or 1. - whichOne = (int) (1.0 * rand() / (RAND_MAX + 1.0)); + whichOne = (int)(1.0 * rand() / (RAND_MAX + 1.0)); if (whichOne == 0) return v1 * fac; @@ -176,13 +181,13 @@ double RandomWalk::randomZeroToOne(void) return (double)(1.0 * rand() / (RAND_MAX + 1.0)); } -CFEMesh* RandomWalk::selectMeshForFluidMomentumProcess () +CFEMesh* RandomWalk::selectMeshForFluidMomentumProcess() { - size_t n_pcs (pcs_vector.size()); + size_t n_pcs(pcs_vector.size()); FiniteElement::ProcessType pcs_type; - CFEMesh* msh (NULL); + CFEMesh* msh(NULL); - for(size_t i = 0; i < n_pcs; ++i) + for (size_t i = 0; i < n_pcs; ++i) { pcs_type = pcs_vector[i]->getProcessType(); // Select the mesh whose process name has the mesh for Fluid_Momentum @@ -194,8 +199,8 @@ CFEMesh* RandomWalk::selectMeshForFluidMomentumProcess () msh = FEMGet("GROUNDWATER_FLOW"); } - if(!msh) //FM_TEST - msh = FEMGet("FLUID_MOMENTUM"); + if (!msh) // FM_TEST + msh = FEMGet("FLUID_MOMENTUM"); return msh; } @@ -210,7 +215,7 @@ void RandomWalk::InterpolateVelocity(Particle* A) { // Get the mesh first // TF - CFEMesh* m_msh (selectMeshForFluidMomentumProcess()); + CFEMesh* m_msh(selectMeshForFluidMomentumProcess()); // // Mount the proper mesh // for(int i=0; i< (int)pcs_vector.size(); ++i) @@ -228,44 +233,44 @@ void RandomWalk::InterpolateVelocity(Particle* A) // Mount the element fromthe first particle from particles initially MeshLib::CElem* theEle = m_msh->ele_vector[A->elementIndex]; - //OK411 double tolerance = 1e-8; + // OK411 double tolerance = 1e-8; // If a quad element, int nnode = theEle->GetEdgesNumber(); m_pcs = PCSGet("FLUID_MOMENTUM"); - //FM_TEST - int idx, idy, idz; - if(m_pcs) - { - idx= m_pcs->GetNodeValueIndex("VELOCITY1_X")+1; - idy= m_pcs->GetNodeValueIndex("VELOCITY1_Y")+1; - idz= m_pcs->GetNodeValueIndex("VELOCITY1_Z")+1; - } - else if(flow_pcs) - { - idx= flow_pcs->GetNodeValueIndex("VELOCITY_X1"); - idy= flow_pcs->GetNodeValueIndex("VELOCITY_Y1"); - idz= flow_pcs->GetNodeValueIndex("VELOCITY_Z1"); - - if(m_msh->GetCoordinateFlag()/10 == 1) - { - if(m_msh->GetCoordinateFlag() == 11) - { - int ibuff = idy; - idy = idx; - idx = ibuff; - } - if(m_msh->GetCoordinateFlag() == 12) - { - int ibuff = idz; - idz = idx; - idx = ibuff; - } - } + // FM_TEST + int idx, idy, idz; + if (m_pcs) + { + idx = m_pcs->GetNodeValueIndex("VELOCITY1_X") + 1; + idy = m_pcs->GetNodeValueIndex("VELOCITY1_Y") + 1; + idz = m_pcs->GetNodeValueIndex("VELOCITY1_Z") + 1; + } + else if (flow_pcs) + { + idx = flow_pcs->GetNodeValueIndex("VELOCITY_X1"); + idy = flow_pcs->GetNodeValueIndex("VELOCITY_Y1"); + idz = flow_pcs->GetNodeValueIndex("VELOCITY_Z1"); + + if (m_msh->GetCoordinateFlag() / 10 == 1) + { + if (m_msh->GetCoordinateFlag() == 11) + { + int ibuff = idy; + idy = idx; + idx = ibuff; + } + if (m_msh->GetCoordinateFlag() == 12) + { + int ibuff = idz; + idz = idx; + idx = ibuff; + } + } - m_pcs = flow_pcs; - } + m_pcs = flow_pcs; + } /* // Let's solve pore velocity. @@ -274,23 +279,23 @@ void RandomWalk::InterpolateVelocity(Particle* A) CMediumProperties *MediaProp = mmp_vector[theEle->GetPatchIndex()]; double porosity = 0.0; if(MediaProp->porosity > 10-6) - porosity = MediaProp->porosity; // This is for simple one. + porosity = MediaProp->porosity; // This is for simple one. else - // This will get you porosity. - porosity = MediaProp->porosity_model_values[0]; + // This will get you porosity. + porosity = MediaProp->porosity_model_values[0]; */ // I guess for Dual Porosity stuff, // this code should be revisited. - if(nnode == 4) + if (nnode == 4) { // Get physical coordinates of four corner points double x[4], y[4] /*, z[4]*/; // double vx[4], vy[4], vz[4]; - for(int i = 0; i < nnode; ++i) + for (int i = 0; i < nnode; ++i) { - double const* const pnt (theEle->GetNode(i)->getData()); + double const* const pnt(theEle->GetNode(i)->getData()); x[i] = pnt[0]; y[i] = pnt[1]; // z[i] = pnt[2]; @@ -302,36 +307,30 @@ void RandomWalk::InterpolateVelocity(Particle* A) // solve for Jm at xm = (xhat,yhat)=(1/2,1/2) <- RT0 double Jm; - Jm = 0.5 * - (x[0] * y[1] - y[0] * x[1] + x[1] * y[2] - y[1] * x[2] + y[0] * x[3] - x[0] * - y[3] + - x[2] * y[3] - y[2] * x[3]); + Jm = 0.5 * (x[0] * y[1] - y[0] * x[1] + x[1] * y[2] - y[1] * x[2] + y[0] * x[3] - x[0] * y[3] + x[2] * y[3] + - y[2] * x[3]); // Mount the edges of the element - vectheEdgesOfThisElement(nnode); + vec theEdgesOfThisElement(nnode); theEle->GetEdges(theEdgesOfThisElement); // Mount the nodes of the edge - vectheNodesOfThisEdge(3); + vec theNodesOfThisEdge(3); // Solve for proper index in reference space double const* Ecenter = theEle->GetGravityCenter(); - double u[4]; // Edge flux in reference space - for(int i = 0; i < 4; ++i) + double u[4]; // Edge flux in reference space + for (int i = 0; i < 4; ++i) u[i] = 0.0; - for(int i = 0; i < 4; ++i) + for (int i = 0; i < 4; ++i) { // Get the nodes of the edge i theEdgesOfThisElement[i]->GetNodes(theNodesOfThisEdge); - double node1[3] = - {(theNodesOfThisEdge[0]->getData())[0], - (theNodesOfThisEdge[0]->getData())[1], 0.0}; - double node2[3] = - {(theNodesOfThisEdge[1]->getData())[0], - (theNodesOfThisEdge[1]->getData())[1], 0.0}; -// TF node1[0] = theNodesOfThisEdge[0]->X(); node1[1] = theNodesOfThisEdge[0]->Y(); -// TF node2[0] = theNodesOfThisEdge[1]->X(); node2[1] = theNodesOfThisEdge[1]->Y(); + double node1[3] = {(theNodesOfThisEdge[0]->getData())[0], (theNodesOfThisEdge[0]->getData())[1], 0.0}; + double node2[3] = {(theNodesOfThisEdge[1]->getData())[0], (theNodesOfThisEdge[1]->getData())[1], 0.0}; + // TF node1[0] = theNodesOfThisEdge[0]->X(); node1[1] = theNodesOfThisEdge[0]->Y(); + // TF node2[0] = theNodesOfThisEdge[1]->X(); node2[1] = theNodesOfThisEdge[1]->Y(); // Get the referece position of these two ending points of the edge IsoparametricMappingQuadfromPtoR(A->elementIndex, node1); IsoparametricMappingQuadfromPtoR(A->elementIndex, node2); @@ -342,29 +341,27 @@ void RandomWalk::InterpolateVelocity(Particle* A) double edge2mid[3], EdgeMidPoint[3]; theEdgesOfThisElement[i]->GetEdgeMidPoint(EdgeMidPoint); - for(int j = 0; j < 3; ++j) + for (int j = 0; j < 3; ++j) edge2mid[j] = Ecenter[j] - EdgeMidPoint[j]; - double angle = acos((dx * edge2mid[0] + dy * edge2mid[1]) - / (sqrt(dx * dx + dy * - dy) * - sqrt(edge2mid[0] * edge2mid[0] + edge2mid[1] * - edge2mid[1]))); + double angle + = acos((dx * edge2mid[0] + dy * edge2mid[1]) + / (sqrt(dx * dx + dy * dy) * sqrt(edge2mid[0] * edge2mid[0] + edge2mid[1] * edge2mid[1]))); // EA and EB: x1hat = x2hat and x1hat*x2hat > 0 - if(fabs(node1[0] - node2[0]) < 0.5 && (node1[0] * node2[0]) > 0.0) + if (fabs(node1[0] - node2[0]) < 0.5 && (node1[0] * node2[0]) > 0.0) { // EA: x1hat < 0 - if(node1[0] < 0.0) + if (node1[0] < 0.0) { - if(angle > 3.141592 / 2.0) + if (angle > 3.141592 / 2.0) u[0] = -sqrt(dx * dx + dy * dy) / Jm; else u[0] = sqrt(dx * dx + dy * dy) / Jm; } else // EB { - if(angle > 3.141592 / 2.0) + if (angle > 3.141592 / 2.0) u[1] = sqrt(dx * dx + dy * dy) / Jm; else u[1] = -sqrt(dx * dx + dy * dy) / Jm; @@ -374,16 +371,16 @@ void RandomWalk::InterpolateVelocity(Particle* A) else { // EC: y1hat < 0 - if(node1[1] < 0.0) + if (node1[1] < 0.0) { - if(angle > 3.141592 / 2.0) + if (angle > 3.141592 / 2.0) u[2] = -sqrt(dx * dx + dy * dy) / Jm; else u[2] = sqrt(dx * dx + dy * dy) / Jm; } else // ED { - if(angle > 3.141592 / 2.0) + if (angle > 3.141592 / 2.0) u[3] = sqrt(dx * dx + dy * dy) / Jm; else u[3] = -sqrt(dx * dx + dy * dy) / Jm; @@ -407,17 +404,17 @@ void RandomWalk::InterpolateVelocity(Particle* A) double t[4], bigTime = 1e10, tmin; - t[0] = TA(Gx,uT,u[0],R[0]); - if(t[0] < 0.0) + t[0] = TA(Gx, uT, u[0], R[0]); + if (t[0] < 0.0) t[0] = bigTime; - t[1] = TB(Gx,uT,u[0],u[1],R[1]); - if(t[1] < 0.0) + t[1] = TB(Gx, uT, u[0], u[1], R[1]); + if (t[1] < 0.0) t[1] = bigTime; - t[2] = TA(Gy,vT,u[2],R[1]); - if(t[2] < 0.0) + t[2] = TA(Gy, vT, u[2], R[1]); + if (t[2] < 0.0) t[2] = bigTime; - t[3] = TB(Gy,vT,u[2],u[3],R[1]); - if(t[3] < 0.0) + t[3] = TB(Gy, vT, u[2], u[3], R[1]); + if (t[3] < 0.0) t[3] = bigTime; int idx = -10; @@ -448,7 +445,7 @@ void RandomWalk::InterpolateVelocity(Particle* A) void RandomWalk::TracePathlineInThisElement(Particle* A) { // Get the mesh first - CFEMesh* m_msh (selectMeshForFluidMomentumProcess()); + CFEMesh* m_msh(selectMeshForFluidMomentumProcess()); // // Mount the proper mesh // for(int i=0; i< (int)pcs_vector.size(); ++i) // { @@ -470,13 +467,13 @@ void RandomWalk::TracePathlineInThisElement(Particle* A) // If a quad element, int nnode = theEle->GetEdgesNumber(); m_pcs = PCSGet("FLUID_MOMENTUM"); - if(!m_pcs) //FM_TEST - m_pcs = flow_pcs; + if (!m_pcs) // FM_TEST + m_pcs = flow_pcs; // Let's solve pore velocity. // It is simple because Sw stuff automatically handles in Richards Flow. // Thus, I only divide Darcy velocity by porosity only to get pore velocity. - //WW CMediumProperties *MediaProp = mmp_vector[theEle->GetPatchIndex()]; + // WW CMediumProperties *MediaProp = mmp_vector[theEle->GetPatchIndex()]; /* //WW double porosity = 0.0; if(MediaProp->porosity > 10-6) @@ -488,13 +485,13 @@ void RandomWalk::TracePathlineInThisElement(Particle* A) // I guess for Dual Porocity stuff, // this code should be revisited. - if(nnode == 4) + if (nnode == 4) { // Mount the edges of the element - vectheEdgesOfThisElement(nnode); + vec theEdgesOfThisElement(nnode); theEle->GetEdges(theEdgesOfThisElement); // Mount the nodes of the edge - vectheNodesOfThisEdge(3); + vec theNodesOfThisEdge(3); // Let's do Pollock's method here. // Solve for the reference position of this particle; @@ -503,7 +500,7 @@ void RandomWalk::TracePathlineInThisElement(Particle* A) R[1] = A->y; R[2] = A->z; - double x0,x1,y0,y1; + double x0, x1, y0, y1; // Get the nodes of the edge i theEdgesOfThisElement[0]->GetNodes(theNodesOfThisEdge); // x0 = theNodesOfThisEdge[0]->X(); @@ -515,13 +512,13 @@ void RandomWalk::TracePathlineInThisElement(Particle* A) y0 = R[1]; y1 = pnt[1]; - double Fx0,Fx1,Fy0,Fy1; // Flux at each edge in physical space + double Fx0, Fx1, Fy0, Fy1; // Flux at each edge in physical space Fx0 = theEdgesOfThisElement[3]->GetVelocity(0); Fx1 = theEdgesOfThisElement[1]->GetVelocity(0); Fy0 = theEdgesOfThisElement[0]->GetVelocity(1); Fy1 = theEdgesOfThisElement[2]->GetVelocity(1); - double ax,bx,cx,ay,by,cy; + double ax, bx, cx, ay, by, cy; ax = Fx1 - Fx0; bx = Fx0 * x1 - x0 * x1; cx = x1 - x0; @@ -529,46 +526,46 @@ void RandomWalk::TracePathlineInThisElement(Particle* A) by = Fy0 * y1 - y0 * y1; cy = y1 - y0; - //Solve the T + // Solve the T double tolerance = 1e-8; double tx, ty; - if(fabs(ax) > tolerance) - tx = cx / ax* log((ax * x1 + bx) / (ax * x0 + bx)); + if (fabs(ax) > tolerance) + tx = cx / ax * log((ax * x1 + bx) / (ax * x0 + bx)); else abort(); - if(fabs(ay) > tolerance) - ty = cy / ay* log((ay * y1 + by) / (ay * y0 + by)); + if (fabs(ay) > tolerance) + ty = cy / ay * log((ay * y1 + by) / (ay * y0 + by)); else abort(); double tmin; - if(tx > ty) + if (tx > ty) tmin = ty; else tmin = tx; - if(cx > tolerance) + if (cx > tolerance) R[0] = (x0 + bx / ax) * exp(ax / cx * tmin) - bx / ax; - if(cy > tolerance) + if (cy > tolerance) R[1] = (y0 + by / ay) * exp(ay / cy * tmin) - by / ay; R[2] = pnt_z_min; A->x = R[0]; A->y = R[1]; A->z = R[2]; - //update the element index // JT 2010; - long i,j,k; + // update the element index // JT 2010; + long i, j, k; i = (int)((A->x - pnt_x_min) / dx); j = (int)((A->y - pnt_y_min) / dy); k = (int)((A->z - pnt_z_min) / dz); long iFDM = k * (nx * ny) + j * nx + i; - if((size_t)iFDM < indexFDM.size()) + if ((size_t)iFDM < indexFDM.size()) A->elementIndex = indexFDM[iFDM].eleIndex; else - A->elementIndex = -10; // Outside of the domain + A->elementIndex = -10; // Outside of the domain } } @@ -576,8 +573,8 @@ double RandomWalk::Tmin(double* a, int* idx) { double Tmin = 1e20; - for(int i = 0; i < 4; ++i) - if(Tmin > a[i]) + for (int i = 0; i < 4; ++i) + if (Tmin > a[i]) { Tmin = a[i]; *idx = i; @@ -586,33 +583,33 @@ double RandomWalk::Tmin(double* a, int* idx) return Tmin; } -double RandomWalk::TA(double Gx,double uT, double uA, double xTA) +double RandomWalk::TA(double Gx, double uT, double uA, double xTA) { double tolerance = 1e-10, bigTime = 1e10; - if(fabs(Gx) > tolerance) // If Gx is not zero + if (fabs(Gx) > tolerance) // If Gx is not zero { - if(fabs(uA) > tolerance) + if (fabs(uA) > tolerance) { - if(uA * uT > 0.0) + if (uA * uT > 0.0) { if (1.0 / Gx * log(uT / uA) < 0.0) return bigTime; else - return 1.0 / Gx* log(uT / uA); + return 1.0 / Gx * log(uT / uA); } else return bigTime; } else - return bigTime; // Assume T is infinite. + return bigTime; // Assume T is infinite. } else { - if(fabs(uA) > tolerance) // uA is not zero + if (fabs(uA) > tolerance) // uA is not zero { double xA = -1.0; // In my reference space - if( (xTA - xA) * uA < 0.0) + if ((xTA - xA) * uA < 0.0) return bigTime; else return xTA / uA; @@ -622,33 +619,33 @@ double RandomWalk::TA(double Gx,double uT, double uA, double xTA) } } -double RandomWalk::TB(double Gx,double uT, double uA, double uB, double xTB) +double RandomWalk::TB(double Gx, double uT, double uA, double uB, double xTB) { double tolerance = 1e-10, bigTime = 1e10; - if(fabs(Gx) > tolerance) // If Gx is not zero + if (fabs(Gx) > tolerance) // If Gx is not zero { - if(fabs(uB) > tolerance) + if (fabs(uB) > tolerance) { - if(uB * uT > 0.0) + if (uB * uT > 0.0) { if (1.0 / Gx * log(uT / uB) < 0.0) return bigTime; else - return 1.0 / Gx* log(uT / uB); + return 1.0 / Gx * log(uT / uB); } else return bigTime; } else - return bigTime; // Assume T is infinite. + return bigTime; // Assume T is infinite. } else { - if(fabs(uB) > tolerance) // uA is not zero + if (fabs(uB) > tolerance) // uA is not zero { double xB = 1.0; // In my reference space - if( (xTB - xB) * uB < 0.0) + if ((xTB - xB) * uB < 0.0) return bigTime; else return (xTB - 1.0) / uA; @@ -692,7 +689,7 @@ void RandomWalk::InterpolateVelocityOfTheParticleByInverseDistance(Particle* A) // Let's get the hydraulic conductivity first. CMediumProperties* MediaProp = mmp_vector[m_ele->GetPatchIndex()]; - //OK411 int phase = 0; + // OK411 int phase = 0; CFluidProperties* FluidProp = mfp_vector[0]; double* kTensor = MediaProp->PermeabilityTensor(A->elementIndex); double k = kTensor[0]; @@ -703,15 +700,15 @@ void RandomWalk::InterpolateVelocityOfTheParticleByInverseDistance(Particle* A) int nnodes = m_ele->GetVertexNumber(); // Allocate the memory accordingly Particle* vertex = NULL; - vertex = new Particle [nnodes]; + vertex = new Particle[nnodes]; double* d = NULL; - d = new double [nnodes] ; + d = new double[nnodes]; double SumOfdInverse = 0.0; // Get the cooridinate of the nodes in the element - for(int i = 0; i < nnodes; ++i) + for (int i = 0; i < nnodes; ++i) { - double const* const coords (m_ele->GetNode(i)->getData()); + double const* const coords(m_ele->GetNode(i)->getData()); vertex[i].x = coords[0]; vertex[i].y = coords[1]; vertex[i].z = coords[2]; @@ -726,35 +723,35 @@ void RandomWalk::InterpolateVelocityOfTheParticleByInverseDistance(Particle* A) // Let's get the weight of each node double* w = NULL; - w = new double [nnodes] ; + w = new double[nnodes]; // Initialize the velocity A->Vx = A->Vy = A->Vz = 0.0; - //FM_TEST + // FM_TEST m_pcs = PCSGet("FLUID_MOMENTUM"); int idx = -1, idy = -1, idz = -1; - if(m_pcs) + if (m_pcs) { - idx= m_pcs->GetNodeValueIndex("VELOCITY1_X")+1; - idy= m_pcs->GetNodeValueIndex("VELOCITY1_Y")+1; - idz= m_pcs->GetNodeValueIndex("VELOCITY1_Z")+1; + idx = m_pcs->GetNodeValueIndex("VELOCITY1_X") + 1; + idy = m_pcs->GetNodeValueIndex("VELOCITY1_Y") + 1; + idz = m_pcs->GetNodeValueIndex("VELOCITY1_Z") + 1; } - else if(flow_pcs) + else if (flow_pcs) { - idx= flow_pcs->GetNodeValueIndex("VELOCITY_X1"); - idy= flow_pcs->GetNodeValueIndex("VELOCITY_Y1"); - idz= flow_pcs->GetNodeValueIndex("VELOCITY_Z1"); + idx = flow_pcs->GetNodeValueIndex("VELOCITY_X1"); + idy = flow_pcs->GetNodeValueIndex("VELOCITY_Y1"); + idz = flow_pcs->GetNodeValueIndex("VELOCITY_Z1"); m_pcs = flow_pcs; - if(m_msh->GetCoordinateFlag()/10 == 1) + if (m_msh->GetCoordinateFlag() / 10 == 1) { - if(m_msh->GetCoordinateFlag() == 11) + if (m_msh->GetCoordinateFlag() == 11) { int ibuff = idy; idy = idx; idx = ibuff; } - if(m_msh->GetCoordinateFlag() == 12) + if (m_msh->GetCoordinateFlag() == 12) { int ibuff = idz; idz = idx; @@ -762,48 +759,43 @@ void RandomWalk::InterpolateVelocityOfTheParticleByInverseDistance(Particle* A) } } } - for(int i = 0; i < nnodes; ++i) + for (int i = 0; i < nnodes; ++i) { w[i] = 1.0 / (d[i] * SumOfdInverse); double vx = 0.0, vy = 0.0, vz = 0.0; // If this node is crossroad, - if(m_msh->nod_vector[m_ele->GetNodeIndex(i)]->crossroad) + if (m_msh->nod_vector[m_ele->GetNodeIndex(i)]->crossroad) { // Get the velocity contributed in this element CrossRoad* crossroad = NULL; - for(int j = 0; j < (int)(m_msh->fm_pcs->crossroads.size()); ++j) - if( (size_t)m_msh->fm_pcs->crossroads[j]->Index == - m_msh->nod_vector[m_ele->GetNodeIndex(i)]->GetIndex() ) + for (int j = 0; j < (int)(m_msh->fm_pcs->crossroads.size()); ++j) + if ((size_t)m_msh->fm_pcs->crossroads[j]->Index + == m_msh->nod_vector[m_ele->GetNodeIndex(i)]->GetIndex()) crossroad = m_msh->fm_pcs->crossroads[j]; - if(crossroad) + if (crossroad) { } - else // Failed to find the crossroad although it is a crossroad + else // Failed to find the crossroad although it is a crossroad abort(); // Find the velocity of the crossroad associated with the connected planes. - for(int k = 0; k < crossroad->numOfThePlanes; ++k) + for (int k = 0; k < crossroad->numOfThePlanes; ++k) { // I am going to check the normal vector of the element and the connected plane. double tolerance = 1e-10; double E[3], P[3]; - for(int p = 0; p < 3; ++p) + for (int p = 0; p < 3; ++p) { E[p] = m_ele->getTransformTensor(6 + p); P[p] = crossroad->plane[k].norm[p]; } - double same = - (E[0] - - P[0]) * - (E[0] - - P[0]) + - (E[1] - - P[1]) * (E[1] - P[1]) + (E[2] - P[2]) * (E[2] - P[2]); + double same + = (E[0] - P[0]) * (E[0] - P[0]) + (E[1] - P[1]) * (E[1] - P[1]) + (E[2] - P[2]) * (E[2] - P[2]); - if(same < tolerance) + if (same < tolerance) { vx = crossroad->plane[k].V[0]; vy = crossroad->plane[k].V[1]; @@ -813,9 +805,9 @@ void RandomWalk::InterpolateVelocityOfTheParticleByInverseDistance(Particle* A) } else { - vx = m_pcs->GetNodeValue(m_ele->GetNodeIndex(i),idx); //FM_TEST - vy = m_pcs->GetNodeValue(m_ele->GetNodeIndex(i),idy); - vz = m_pcs->GetNodeValue(m_ele->GetNodeIndex(i),idz); + vx = m_pcs->GetNodeValue(m_ele->GetNodeIndex(i), idx); // FM_TEST + vy = m_pcs->GetNodeValue(m_ele->GetNodeIndex(i), idy); + vz = m_pcs->GetNodeValue(m_ele->GetNodeIndex(i), idz); // Let's solve pore velocity. // It is simple because Sw stuff automatically handles in Richards Flow. @@ -838,9 +830,9 @@ void RandomWalk::InterpolateVelocityOfTheParticleByInverseDistance(Particle* A) } // Release the temperary memory in this function - delete [] vertex; - delete [] d; - delete [] w; + delete[] vertex; + delete[] d; + delete[] w; } /************************************************************************** @@ -874,21 +866,21 @@ void RandomWalk::InterpolateVelocityOfTheParticleByBilinear(int option, Particle // } // Let's allocate some memory for miniFEM - CFEMesh* m_mini (new CFEMesh(m_msh->getGEOObjects(), m_msh->getProjectName())); + CFEMesh* m_mini(new CFEMesh(m_msh->getGEOObjects(), m_msh->getProjectName())); MeshLib::CElem* miniEle = new MeshLib::CElem(); - if(option == 0) // FDM method + if (option == 0) // FDM method { - int eleIndex = IndexOfTheElementThatThisParticleBelong(0,A); + int eleIndex = IndexOfTheElementThatThisParticleBelong(0, A); - if(eleIndex == -5) + if (eleIndex == -5) // This is a temperary measure. // Gotta be written better later on. eleIndex = 0; // Element is outside of the domain or in the sink // Do not do anything. If not, then proceed. - if(eleIndex != -10) + if (eleIndex != -10) { A->elementIndex = eleIndex; MeshLib::CElem* m_ele = m_msh->ele_vector[eleIndex]; @@ -906,8 +898,8 @@ void RandomWalk::InterpolateVelocityOfTheParticleByBilinear(int option, Particle // Get porosity // I guess for Dual Porocity stuff this code should be revisited. double porosity = 0.0; - if(MediaProp->porosity > 10 - 6) - porosity = MediaProp->porosity; // This is for simple one. + if (MediaProp->porosity > 10 - 6) + porosity = MediaProp->porosity; // This is for simple one. else // This will get you porosity. porosity = MediaProp->porosity_model_values[0]; @@ -916,7 +908,7 @@ void RandomWalk::InterpolateVelocityOfTheParticleByBilinear(int option, Particle // int nnodes = m_ele->GetVertexNumber(); // Mount the edges of the element - vectheEdgesOfThisElement(nnode); + vec theEdgesOfThisElement(nnode); m_ele->GetEdges(theEdgesOfThisElement); double E1[3], E2[3], E3[3], E4[3]; // mid points of each edge @@ -927,7 +919,7 @@ void RandomWalk::InterpolateVelocityOfTheParticleByBilinear(int option, Particle // ux = a+b(x-x0); uy = c + d(y-y0) - double vx1,vx2,vy1,vy2,a,b,x0,y0; + double vx1, vx2, vy1, vy2, a, b, x0, y0; vx2 = theEdgesOfThisElement[1]->GetVelocity(0); vx1 = theEdgesOfThisElement[3]->GetVelocity(0); @@ -936,8 +928,8 @@ void RandomWalk::InterpolateVelocityOfTheParticleByBilinear(int option, Particle x0 = E4[0]; y0 = E1[1]; - a = (vx2 - vx1) / dx; - b = (vy1 - vy2) / dy; + a = (vx2 - vx1) / dx; + b = (vy1 - vy2) / dy; // Let's solve pore velocity. // It is simple because Sw stuff automatically handles in Richards Flow. @@ -946,43 +938,43 @@ void RandomWalk::InterpolateVelocityOfTheParticleByBilinear(int option, Particle A->Vy = (vy2 + b * (A->y - y0)) / porosity; A->Vz = 0.0; } - //else + // else // ; // Think later for out of boundary particles. } - else if(option == 1) // miniFEM Way + else if (option == 1) // miniFEM Way { m_pcs = PCSGet("FLUID_MOMENTUM"); - //FM_TEST - int idx, idy, idz; - if(m_pcs) - { - idx= m_pcs->GetNodeValueIndex("VELOCITY1_X")+1; - idy= m_pcs->GetNodeValueIndex("VELOCITY1_Y")+1; - idz= m_pcs->GetNodeValueIndex("VELOCITY1_Z")+1; - } - else if(flow_pcs) - { - idx= flow_pcs->GetNodeValueIndex("VELOCITY_X1"); - idy= flow_pcs->GetNodeValueIndex("VELOCITY_Y1"); - idz= flow_pcs->GetNodeValueIndex("VELOCITY_Z1"); - m_pcs = flow_pcs; - - if(m_msh->GetCoordinateFlag()/10 == 1) - { - if(m_msh->GetCoordinateFlag() == 11) - { - int ibuff = idy; - idy = idx; - idx = ibuff; - } - if(m_msh->GetCoordinateFlag() == 12) - { - int ibuff = idz; - idz = idx; - idx = ibuff; - } - } - } + // FM_TEST + int idx, idy, idz; + if (m_pcs) + { + idx = m_pcs->GetNodeValueIndex("VELOCITY1_X") + 1; + idy = m_pcs->GetNodeValueIndex("VELOCITY1_Y") + 1; + idz = m_pcs->GetNodeValueIndex("VELOCITY1_Z") + 1; + } + else if (flow_pcs) + { + idx = flow_pcs->GetNodeValueIndex("VELOCITY_X1"); + idy = flow_pcs->GetNodeValueIndex("VELOCITY_Y1"); + idz = flow_pcs->GetNodeValueIndex("VELOCITY_Z1"); + m_pcs = flow_pcs; + + if (m_msh->GetCoordinateFlag() / 10 == 1) + { + if (m_msh->GetCoordinateFlag() == 11) + { + int ibuff = idy; + idy = idx; + idx = ibuff; + } + if (m_msh->GetCoordinateFlag() == 12) + { + int ibuff = idz; + idz = idx; + idx = ibuff; + } + } + } MeshLib::CElem* theEle = m_msh->ele_vector[A->elementIndex]; int eleIndex = A->elementIndex; // Set the pointer that leads to the nodes of element @@ -992,7 +984,7 @@ void RandomWalk::InterpolateVelocityOfTheParticleByBilinear(int option, Particle // Check if the particle is on the edge or node. int IsOnTheEdge = IsParticleOnTheEdge(A); int nnode = theEle->GetEdgesNumber(); - if(eleIndex != -10 && IsOnTheEdge == 0) + if (eleIndex != -10 && IsOnTheEdge == 0) { // Let's solve pore velocity. // It is simple because Sw stuff automatically handles in Richards Flow. @@ -1002,10 +994,10 @@ void RandomWalk::InterpolateVelocityOfTheParticleByBilinear(int option, Particle CMediumProperties *MediaProp = mmp_vector[theEle->GetPatchIndex()]; double porosity = 0.0; if(MediaProp->porosity > 10-6) - porosity = MediaProp->porosity; // This is for simple one. + porosity = MediaProp->porosity; // This is for simple one. else - // This will get you porosity. - porosity = MediaProp->porosity_model_values[0]; + // This will get you porosity. + porosity = MediaProp->porosity_model_values[0]; */ // I guess for Dual Porocity stuff, @@ -1014,7 +1006,7 @@ void RandomWalk::InterpolateVelocityOfTheParticleByBilinear(int option, Particle // Get the number of nodes // Mount the edges of the element - vectheEdgesOfThisElement(nnode); + vec theEdgesOfThisElement(nnode); theEle->GetEdges(theEdgesOfThisElement); // Get physical coordinates of four corner points @@ -1023,24 +1015,24 @@ void RandomWalk::InterpolateVelocityOfTheParticleByBilinear(int option, Particle double vx[8], vy[8], vz[8]; for(int i=0; iGetNode(i); - x[i] = theNode->X(); - y[i] = theNode->Y(); - z[i] = theNode->Z(); - - vx[i] = m_pcs->GetNodeValue(theEle->GetNodeIndex(i),idx)/porosity; //FM_TEST - vy[i] = m_pcs->GetNodeValue(theEle->GetNodeIndex(i),idy)/porosity; - vz[i] = m_pcs->GetNodeValue(theEle->GetNodeIndex(i),idz)/porosity; + MeshLib::CNode* theNode = NULL; + theNode = theEle->GetNode(i); + x[i] = theNode->X(); + y[i] = theNode->Y(); + z[i] = theNode->Z(); + + vx[i] = m_pcs->GetNodeValue(theEle->GetNodeIndex(i),idx)/porosity; //FM_TEST + vy[i] = m_pcs->GetNodeValue(theEle->GetNodeIndex(i),idy)/porosity; + vz[i] = m_pcs->GetNodeValue(theEle->GetNodeIndex(i),idz)/porosity; } */ // Mount the nodes of the edge - vectheNodesOfThisEdge(3); + vec theNodesOfThisEdge(3); // MiniFEM for 2D elements starts here // Find all the nodes for miniFEM first - if(nnode == 4) // Quad + if (nnode == 4) // Quad { MeshLib::CNode* theNode = NULL; // Node 0 for miniFEM for quad @@ -1103,13 +1095,13 @@ void RandomWalk::InterpolateVelocityOfTheParticleByBilinear(int option, Particle fem = new CFiniteElementStd(m_pcs, m_msh->GetCoordinateFlag()); // I am going to create global matrix here MeshLib::CElem* elem = NULL; - for(int d = 0; d < 2; ++d) + for (int d = 0; d < 2; ++d) { - /* Initializations */ - /* System matrix */ -#if defined (USE_PETSC) // || defined (other parallel solver lib). 04.2012 WW - //Todo -#elif defined(NEW_EQS) //WW +/* Initializations */ +/* System matrix */ +#if defined(USE_PETSC) // || defined (other parallel solver lib). 04.2012 WW +// Todo +#elif defined(NEW_EQS) // WW m_pcs->EQSInitialize(); #else SetZeroLinearSolver(m_pcs->getEQSPointer()); @@ -1123,11 +1115,11 @@ void RandomWalk::InterpolateVelocityOfTheParticleByBilinear(int option, Particle fem->Assembly(0, d); } - m_pcs->IncorporateBoundaryConditions(-1,d); + m_pcs->IncorporateBoundaryConditions(-1, d); - // Solve for velocity -#if defined (USE_PETSC) // || defined (other parallel solver lib). 04.2012 WW - //Todo +// Solve for velocity +#if defined(USE_PETSC) // || defined (other parallel solver lib). 04.2012 WW +// Todo #elif defined(NEW_EQS) #if defined(LIS) @@ -1135,70 +1127,71 @@ void RandomWalk::InterpolateVelocityOfTheParticleByBilinear(int option, Particle int size = m_msh->nod_vector.size(); x = new double[size]; m_pcs->EQSSolver(x); // an option added to tell FLUID_MOMENTUM for sparse matrix system. - cout << "Solver passed in FLUID_MOMENTUM." << "\n"; + cout << "Solver passed in FLUID_MOMENTUM." + << "\n"; #endif #else m_pcs->ExecuteLinearSolver(m_pcs->getEQSPointer()); #endif } } - else if(nnode == 3) + else if (nnode == 3) { } - //else + // else // ; // This shouldn't happen here. There are only tri or quad ele's in 2D } - else if(IsOnTheEdge != 0) // The particle is on the edge. + else if (IsOnTheEdge != 0) // The particle is on the edge. { // We have update edge index for this particle performing // IsParticleOnTheEdge() function // Thus, we only need to interpolate particle velocity along this edge. // Even for this, I will use 1d Galerkin method. } - //else + // else // ; // Think later for out of boundary particles. } - else // Real Space and reference space way + else // Real Space and reference space way { m_pcs = PCSGet("FLUID_MOMENTUM"); - //FM_TEST - int idx, idy, idz; - if(m_pcs) - { - idx= m_pcs->GetNodeValueIndex("VELOCITY1_X")+1; - idy= m_pcs->GetNodeValueIndex("VELOCITY1_Y")+1; - idz= m_pcs->GetNodeValueIndex("VELOCITY1_Z")+1; - } - else if(flow_pcs) - { - idx= flow_pcs->GetNodeValueIndex("VELOCITY_X1"); - idy= flow_pcs->GetNodeValueIndex("VELOCITY_Y1"); - idz= flow_pcs->GetNodeValueIndex("VELOCITY_Z1"); - m_pcs = flow_pcs; - if(m_msh->GetCoordinateFlag()/10 == 1) - { - if(m_msh->GetCoordinateFlag() == 11) - { - int ibuff = idy; - idy = idx; - idx = ibuff; - } - if(m_msh->GetCoordinateFlag() == 12) - { - int ibuff = idz; - idz = idx; - idx = ibuff; - } - } - } + // FM_TEST + int idx, idy, idz; + if (m_pcs) + { + idx = m_pcs->GetNodeValueIndex("VELOCITY1_X") + 1; + idy = m_pcs->GetNodeValueIndex("VELOCITY1_Y") + 1; + idz = m_pcs->GetNodeValueIndex("VELOCITY1_Z") + 1; + } + else if (flow_pcs) + { + idx = flow_pcs->GetNodeValueIndex("VELOCITY_X1"); + idy = flow_pcs->GetNodeValueIndex("VELOCITY_Y1"); + idz = flow_pcs->GetNodeValueIndex("VELOCITY_Z1"); + m_pcs = flow_pcs; + if (m_msh->GetCoordinateFlag() / 10 == 1) + { + if (m_msh->GetCoordinateFlag() == 11) + { + int ibuff = idy; + idy = idx; + idx = ibuff; + } + if (m_msh->GetCoordinateFlag() == 12) + { + int ibuff = idz; + idz = idx; + idx = ibuff; + } + } + } MeshLib::CElem* theEle = m_msh->ele_vector[A->elementIndex]; int eleIndex = A->elementIndex; // Set the pointer that leads to the nodes of element - //OK411 CNode* node = NULL; + // OK411 CNode* node = NULL; // Element is outside of the domain or in the sink // Do not do anything. If not, then proceed. - if(eleIndex != -10) + if (eleIndex != -10) { int nnode = theEle->GetEdgesNumber(); @@ -1210,28 +1203,28 @@ void RandomWalk::InterpolateVelocityOfTheParticleByBilinear(int option, Particle CMediumProperties *MediaProp = mmp_vector[theEle->GetPatchIndex()]; double porosity = 0.0; if(MediaProp->porosity > 10-6) - porosity = MediaProp->porosity; // This is for simple one. + porosity = MediaProp->porosity; // This is for simple one. else - // This will get you porosity. - porosity = MediaProp->porosity_model_values[0]; + // This will get you porosity. + porosity = MediaProp->porosity_model_values[0]; */ // I guess for Dual Porocity stuff, // this code should be revisited. // Get the number of nodes - //OK411 int nnodes = theEle->GetVertexNumber(); + // OK411 int nnodes = theEle->GetVertexNumber(); // Mount the edges of the element - vectheEdgesOfThisElement(nnode); + vec theEdgesOfThisElement(nnode); theEle->GetEdges(theEdgesOfThisElement); // Get physical coordinates of four corner points double x[4], y[4] /*, z[4]*/; // double vx[4], vy[4], vz[4]; - for(int i = 0; i < nnode; ++i) + for (int i = 0; i < nnode; ++i) { - double const* const pnt (theEle->GetNode(i)->getData()); + double const* const pnt(theEle->GetNode(i)->getData()); x[i] = pnt[0]; y[i] = pnt[1]; /* @@ -1244,32 +1237,27 @@ void RandomWalk::InterpolateVelocityOfTheParticleByBilinear(int option, Particle } // solve for Jm at xm = (xhat,yhat)=(1/2,1/2) <- RT0 double Jm; - Jm = 0.5 * - (x[0] * y[1] - y[0] * x[1] + x[1] * y[2] - y[1] * x[2] + y[0] * x[3] - - x[0] * y[3] + x[2] * y[3] - y[2] * x[3]); + Jm = 0.5 * (x[0] * y[1] - y[0] * x[1] + x[1] * y[2] - y[1] * x[2] + y[0] * x[3] - x[0] * y[3] + x[2] * y[3] + - y[2] * x[3]); // Mount the nodes of the edge - vectheNodesOfThisEdge(3); + vec theNodesOfThisEdge(3); // Solve for proper index in reference space double const* Ecenter = theEle->GetGravityCenter(); - double u[4]; // Edge flux in reference space - for(int i = 0; i < 4; ++i) + double u[4]; // Edge flux in reference space + for (int i = 0; i < 4; ++i) u[i] = 0.0; - for(int i = 0; i < 4; ++i) + for (int i = 0; i < 4; ++i) { // Get the nodes of the edge i theEdgesOfThisElement[i]->GetNodes(theNodesOfThisEdge); - double node1[3] = - {theNodesOfThisEdge[0]->getData()[0], - theNodesOfThisEdge[0]->getData()[1], 0.0}; - double node2[3] = - {theNodesOfThisEdge[1]->getData()[0], - theNodesOfThisEdge[1]->getData()[1], 0.0}; -// TF node1[0] = theNodesOfThisEdge[0]->X(); node1[1] = theNodesOfThisEdge[0]->Y(); -// TF node2[0] = theNodesOfThisEdge[1]->X(); node2[1] = theNodesOfThisEdge[1]->Y(); + double node1[3] = {theNodesOfThisEdge[0]->getData()[0], theNodesOfThisEdge[0]->getData()[1], 0.0}; + double node2[3] = {theNodesOfThisEdge[1]->getData()[0], theNodesOfThisEdge[1]->getData()[1], 0.0}; + // TF node1[0] = theNodesOfThisEdge[0]->X(); node1[1] = theNodesOfThisEdge[0]->Y(); + // TF node2[0] = theNodesOfThisEdge[1]->X(); node2[1] = theNodesOfThisEdge[1]->Y(); // Get the referece position of these two ending points of the edge IsoparametricMappingQuadfromPtoR(A->elementIndex, node1); IsoparametricMappingQuadfromPtoR(A->elementIndex, node2); @@ -1280,29 +1268,27 @@ void RandomWalk::InterpolateVelocityOfTheParticleByBilinear(int option, Particle double edge2mid[3], EdgeMidPoint[3]; theEdgesOfThisElement[i]->GetEdgeMidPoint(EdgeMidPoint); - for(int j = 0; j < 3; ++j) + for (int j = 0; j < 3; ++j) edge2mid[j] = Ecenter[j] - EdgeMidPoint[j]; - double angle = acos((dx * edge2mid[0] + dy * edge2mid[1]) - / (sqrt(dx * dx + dy * - dy) * - sqrt(edge2mid[0] * edge2mid[0] + - edge2mid[1] * edge2mid[1]))); + double angle + = acos((dx * edge2mid[0] + dy * edge2mid[1]) + / (sqrt(dx * dx + dy * dy) * sqrt(edge2mid[0] * edge2mid[0] + edge2mid[1] * edge2mid[1]))); // EA and EB: x1hat = x2hat and x1hat*x2hat > 0 - if(fabs(node1[0] - node2[0]) < 0.5 && (node1[0] * node2[0]) > 0.0) + if (fabs(node1[0] - node2[0]) < 0.5 && (node1[0] * node2[0]) > 0.0) { // EA: x1hat < 0 - if(node1[0] < 0.0) + if (node1[0] < 0.0) { - if(angle > 3.141592 / 2.0) + if (angle > 3.141592 / 2.0) u[0] = -sqrt(dx * dx + dy * dy) / Jm; else u[0] = sqrt(dx * dx + dy * dy) / Jm; } else // EB { - if(angle > 3.141592 / 2.0) + if (angle > 3.141592 / 2.0) u[1] = sqrt(dx * dx + dy * dy) / Jm; else u[1] = -sqrt(dx * dx + dy * dy) / Jm; @@ -1312,16 +1298,16 @@ void RandomWalk::InterpolateVelocityOfTheParticleByBilinear(int option, Particle else { // EC: y1hat < 0 - if(node1[1] < 0.0) + if (node1[1] < 0.0) { - if(angle > 3.141592 / 2.0) + if (angle > 3.141592 / 2.0) u[2] = -sqrt(dx * dx + dy * dy) / Jm; else u[2] = sqrt(dx * dx + dy * dy) / Jm; } else // ED { - if(angle > 3.141592 / 2.0) + if (angle > 3.141592 / 2.0) u[3] = sqrt(dx * dx + dy * dy) / Jm; else u[3] = -sqrt(dx * dx + dy * dy) / Jm; @@ -1340,7 +1326,7 @@ void RandomWalk::InterpolateVelocityOfTheParticleByBilinear(int option, Particle IsoparametricMappingQuadfromPtoR(A->elementIndex, E4); // ux = a+b(x-x0); uy = c + d(y-y0) - double a,b,c,d,x0,y0; + double a, b, c, d, x0, y0; x0 = E4[0]; y0 = E1[1]; @@ -1358,7 +1344,7 @@ void RandomWalk::InterpolateVelocityOfTheParticleByBilinear(int option, Particle A->Vy = (c + d * (R[1] - y0)); A->Vz = 0.0; } - //else + // else // ; // Think later for out of boundary particles. } @@ -1366,8 +1352,7 @@ void RandomWalk::InterpolateVelocityOfTheParticleByBilinear(int option, Particle delete m_mini; } -void RandomWalk::GetNodeOfMiniFEMforTheEdge(MeshLib::CNode* theNode, - MeshLib::CEdge* theEdge, Particle* A) +void RandomWalk::GetNodeOfMiniFEMforTheEdge(MeshLib::CNode* theNode, MeshLib::CEdge* theEdge, Particle* A) { // Just for two nodes of the edge double x[2] = {theEdge->GetNode(0)->getData()[0], theEdge->GetNode(0)->getData()[1]}; @@ -1406,26 +1391,26 @@ int RandomWalk::IsParticleOnTheEdge(Particle* A) int nnode = theEle->GetVertexNumber(); // If element is triangle or quadrilateral. - if(nnode == 3 || nnode == 4) + if (nnode == 3 || nnode == 4) { // Mount the edges of the element - vectheEdgesOfThisElement(nnode); + vec theEdgesOfThisElement(nnode); theEle->GetEdges(theEdgesOfThisElement); -// double x1[3], x2[3]; //OK411 , v[3]; - vectheNodesOfThisEdge(3); + // double x1[3], x2[3]; //OK411 , v[3]; + vec theNodesOfThisEdge(3); - for(int i = 0; i < nnode; ++i) + for (int i = 0; i < nnode; ++i) { theEdgesOfThisElement[i]->GetNodes(theNodesOfThisEdge); - double const* const x1 (theNodesOfThisEdge[0]->getData()); -// x1[0]=pnt1[0]; -// x1[1]=pnt1[1]; -// x1[2]=pnt1[2]; - double const* const x2 (theNodesOfThisEdge[1]->getData()); -// x2[0]=pnt2[0]; -// x2[1]=pnt2[1]; -// x2[2]=pnt2[2]; + double const* const x1(theNodesOfThisEdge[0]->getData()); + // x1[0]=pnt1[0]; + // x1[1]=pnt1[1]; + // x1[2]=pnt1[2]; + double const* const x2(theNodesOfThisEdge[1]->getData()); + // x2[0]=pnt2[0]; + // x2[1]=pnt2[1]; + // x2[2]=pnt2[2]; double x2x1[3], x1x0[3]; x2x1[0] = x2[0] - x1[0]; @@ -1435,23 +1420,16 @@ int RandomWalk::IsParticleOnTheEdge(Particle* A) x1x0[1] = x1[1] - A->y; x1x0[2] = x1[2] - A->z; double x2x1square; - x2x1square = - (x2[0] - - x1[0]) * - (x2[0] - - x1[0]) + - (x2[1] - - x1[1]) * (x2[1] - x1[1]) + (x2[2] - x1[2]) * (x2[2] - x1[2]); + x2x1square = (x2[0] - x1[0]) * (x2[0] - x1[0]) + (x2[1] - x1[1]) * (x2[1] - x1[1]) + + (x2[2] - x1[2]) * (x2[2] - x1[2]); double cvec[3]; - CrossProduction(x2x1,x1x0,cvec); + CrossProduction(x2x1, x1x0, cvec); double distance; - distance = sqrt( - (cvec[0] * cvec[0] + cvec[1] * cvec[1] + cvec[2] * - cvec[2]) / x2x1square); + distance = sqrt((cvec[0] * cvec[0] + cvec[1] * cvec[1] + cvec[2] * cvec[2]) / x2x1square); - if(distance < tolerance) // The particle is on this edge + if (distance < tolerance) // The particle is on this edge { // Update the edge that the particle is on now. A->edgeIndex = theEdgesOfThisElement[i]->GetIndex(); @@ -1461,9 +1439,9 @@ int RandomWalk::IsParticleOnTheEdge(Particle* A) } } else - return 0; // For 3D element, later.... + return 0; // For 3D element, later.... - return 0; // No, The particle is not any edge in the element. + return 0; // No, The particle is not any edge in the element. } /************************************************************************** @@ -1477,7 +1455,7 @@ int RandomWalk::IsParticleOnTheEdge(Particle* A) **************************************************************************/ double* RandomWalk::InterpolateLocationOfTheParticleByBilinear(Particle* A, double dt) { - double* x = new double [3]; + double* x = new double[3]; // Get the element that the particle belongs m_msh = selectMeshForFluidMomentumProcess(); @@ -1495,15 +1473,15 @@ double* RandomWalk::InterpolateLocationOfTheParticleByBilinear(Particle* A, doub // m_msh = FEMGet("GROUNDWATER_FLOW"); // } - int eleIndex = IndexOfTheElementThatThisParticleBelong(0,A); - if(eleIndex == -5) + int eleIndex = IndexOfTheElementThatThisParticleBelong(0, A); + if (eleIndex == -5) // This is a temperary measure. // Gotta be written better later on. eleIndex = 0; // Element is outside of the domain or in the sink // Do not do anything. If not, then proceed. - if(eleIndex != -10) + if (eleIndex != -10) { A->elementIndex = eleIndex; MeshLib::CElem* m_ele = m_msh->ele_vector[eleIndex]; @@ -1512,7 +1490,7 @@ double* RandomWalk::InterpolateLocationOfTheParticleByBilinear(Particle* A, doub // Let's get the hydraulic conductivity first. CMediumProperties* MediaProp = mmp_vector[m_ele->GetPatchIndex()]; - //OK411 int phase = 0; + // OK411 int phase = 0; CFluidProperties* FluidProp = mfp_vector[0]; double* kTensor = MediaProp->PermeabilityTensor(eleIndex); double k = kTensor[0]; @@ -1520,10 +1498,10 @@ double* RandomWalk::InterpolateLocationOfTheParticleByBilinear(Particle* A, doub A->K = k * FluidProp->Density() * 9.81 / FluidProp->Viscosity(); // Get the number of nodes - //OK411 int nnodes = m_ele->GetVertexNumber(); + // OK411 int nnodes = m_ele->GetVertexNumber(); // Mount the edges of the element - vectheEdgesOfThisElement(nnode); + vec theEdgesOfThisElement(nnode); m_ele->GetEdges(theEdgesOfThisElement); double E1[3], E2[3], E3[3], E4[3]; // mid points of each edge @@ -1533,23 +1511,19 @@ double* RandomWalk::InterpolateLocationOfTheParticleByBilinear(Particle* A, doub theEdgesOfThisElement[3]->GetEdgeMidPoint(E4); // ux = a+b(x-x0); uy = c + d(y-y0) - double a,b,c,d,x0,y0; + double a, b, c, d, x0, y0; x0 = E4[0]; y0 = E1[1]; a = theEdgesOfThisElement[3]->GetVelocity(0); - b = - (theEdgesOfThisElement[1]->GetVelocity(0) - - theEdgesOfThisElement[3]->GetVelocity(0)) / dx; + b = (theEdgesOfThisElement[1]->GetVelocity(0) - theEdgesOfThisElement[3]->GetVelocity(0)) / dx; c = theEdgesOfThisElement[0]->GetVelocity(1); - d = - (theEdgesOfThisElement[2]->GetVelocity(1) - - theEdgesOfThisElement[0]->GetVelocity(1)) / dy; + d = (theEdgesOfThisElement[2]->GetVelocity(1) - theEdgesOfThisElement[0]->GetVelocity(1)) / dy; - A->x = (a + b * (A->x - x0)) / b* exp(b* dt) - a / b; - A->y = (c + d * (A->y - y0)) / d* exp(d* dt) - c / d; + A->x = (a + b * (A->x - x0)) / b * exp(b * dt) - a / b; + A->y = (c + d * (A->y - y0)) / d * exp(d * dt) - c / d; A->z = 0.0; } - //else + // else // ; // Think later for out of boundary particles. return x; @@ -1565,31 +1539,31 @@ int RandomWalk::IndexOfTheElementThatThisParticleBelong(int option, Particle* A) { int index = -10; - if(option == 0) + if (option == 0) { - long i,j,k,iFDM; - double x,y,z; + long i, j, k, iFDM; + double x, y, z; x = A->x; y = A->y; z = A->z; i = j = k = 0; // Set off the domain first - if(xrw_range > 1.e-12) // only if non-negligible range in this direction + if (xrw_range > 1.e-12) // only if non-negligible range in this direction { - if(x > pnt_x_max || x < pnt_x_min) + if (x > pnt_x_max || x < pnt_x_min) return index; i = (long int)floor((x - pnt_x_min) / dx); } - if(yrw_range > 1.e-12) + if (yrw_range > 1.e-12) { - if(y > pnt_y_max || y < pnt_y_min) + if (y > pnt_y_max || y < pnt_y_min) return index; j = (long int)floor((y - pnt_y_min) / dy); } - if(zrw_range > 1.e-12) + if (zrw_range > 1.e-12) { - if(z > pnt_z_max || x < pnt_z_min) + if (z > pnt_z_max || x < pnt_z_min) return index; k = (long int)floor((z - pnt_z_min) / dz); } @@ -1632,15 +1606,15 @@ int RandomWalk::SolveForTwoIntersectionsInTheElement(Particle* A, double* P1, do int nnodes = m_ele->GetVertexNumber(); // Allocate the memory accordingly Particle* vertex = NULL; - vertex = new Particle [nnodes] (); + vertex = new Particle[nnodes](); int R = 0, L = 0; // Set the size of displacement - double disp = 1e4; // This should be bigger the largest element size. + double disp = 1e4; // This should be bigger the largest element size. // RWPT-IM // Get the cooridinate of the nodes in the element - for(int i = 0; i < nnodes; ++i) + for (int i = 0; i < nnodes; ++i) { node = m_ele->GetNode(i); double X[3] = {node->getData()[0], node->getData()[1], node->getData()[2]}; @@ -1651,7 +1625,7 @@ int RandomWalk::SolveForTwoIntersectionsInTheElement(Particle* A, double* P1, do } // Solve for the line equation - for(int i = 0; i < nnodes; ++i) + for (int i = 0; i < nnodes; ++i) { double p1[3], p2[3], p3[3], p4[3]; // Need coordinate transform here. @@ -1667,53 +1641,42 @@ int RandomWalk::SolveForTwoIntersectionsInTheElement(Particle* A, double* P1, do X[1] = A->y; X[2] = A->z; ToTheXYPlane(m_ele, X); - for(int p = 0; p < 3; ++p) + for (int p = 0; p < 3; ++p) p3[p] = p4[p] = X[p]; - for(int j = 0; j < 2; ++j) + for (int j = 0; j < 2; ++j) { // See if there is an intersection in this line. // if a line is set to be parallel to x axis on the right - if(axis == 0 && j == 0) + if (axis == 0 && j == 0) p4[0] = X[0] + disp; // if a line is set to be parallel to y axis on the right, - else if(axis == 1 && j == 0) + else if (axis == 1 && j == 0) p4[1] = X[1] + disp; // if a line is set to be parallel to z axis on the right, - else if(axis == 2 && j == 0) + else if (axis == 2 && j == 0) p4[2] = X[2] + disp; // if a line is set to be parallel to x axis on the left - else if(axis == 0 && j == 1) + else if (axis == 0 && j == 1) p4[0] = X[0] - disp; // if a line is set to be parallel to y axis on the left, - else if(axis == 1 && j == 1) + else if (axis == 1 && j == 1) p4[1] = X[1] - disp; // if a line is set to be parallel to z axis on the left, - else if(axis == 2 && j == 1) + else if (axis == 2 && j == 1) p4[2] = X[2] - disp; else { - printf( - "Axis type in searching the intersection failed. Wrong axis type.\n"); + printf("Axis type in searching the intersection failed. Wrong axis type.\n"); abort(); } double x = 0.0, y = 0.0, ra = 0.0, rb = 0.0; - int status = G_intersect_line_segments( p1[0], - p1[1], - p2[0], - p2[1], - p3[0], - p3[1], - p4[0], - p4[1], - &ra, - &rb, - &x, - &y); + int status + = G_intersect_line_segments(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1], p4[0], p4[1], &ra, &rb, &x, &y); // RWPT-IM P1 and P2 are already on the XY plane. - if(status == 1 && j == 0) + if (status == 1 && j == 0) { P1[0] = x; P1[1] = y; @@ -1723,7 +1686,7 @@ int RandomWalk::SolveForTwoIntersectionsInTheElement(Particle* A, double* P1, do ++R; } - else if(status == 1 && j == 1) + else if (status == 1 && j == 1) { P2[0] = x; P2[1] = y; @@ -1737,14 +1700,14 @@ int RandomWalk::SolveForTwoIntersectionsInTheElement(Particle* A, double* P1, do } // Free the memory for this function - delete [] vertex; + delete[] vertex; - if(R + L == 2) - return 2; // The job succeeded - else if(R + L == 1) + if (R + L == 2) + return 2; // The job succeeded + else if (R + L == 1) return 1; else - return -1; // The job failed. + return -1; // The job failed. } /************************************************************************** @@ -1764,8 +1727,8 @@ int RandomWalk::SolveForDisplacementByDerivativeOfDispersion(Particle* A, double // Solve for the derivative of velocity first // statusForDeivativeOfVelocity is never further used down the code. - //WW int statusForDeivativeOfVelocity = -10; - //WW statusForDeivativeOfVelocity = SolveForDerivativeOfVelocity(A); + // WW int statusForDeivativeOfVelocity = -10; + // WW statusForDeivativeOfVelocity = SolveForDerivativeOfVelocity(A); // Solve for the tensor of dispersion derivatives // Extract the dispersivities from the group that the particle belongs @@ -1790,23 +1753,17 @@ int RandomWalk::SolveForDisplacementByDerivativeOfDispersion(Particle* A, double double U = sqrt(V[0] * V[0] + V[1] * V[1] + V[2] * V[2]); TensorOfdD[0] = V[0] * A->dVxdx * (alphaL * (2.0 / U - V[0] * V[0] / (U * U * U)) - - alphaT * (V[1] * V[1] + V[2] * V[2]) / (U * U * U) ); - TensorOfdD[1] = (alphaL - alphaT) * (A->dVydy * V[0] / U - - V[0] * V[1] * V[1] / (U * U * U) * A->dVydy); - TensorOfdD[2] = (alphaL - alphaT) * (A->dVzdz * V[0] / U - - V[0] * V[2] * V[2] / (U * U * U) * A->dVzdz); - TensorOfdD[3] = (alphaL - alphaT) * (A->dVxdx * V[1] / U - - V[1] * V[0] * V[0] / (U * U * U) * A->dVxdx); + - alphaT * (V[1] * V[1] + V[2] * V[2]) / (U * U * U)); + TensorOfdD[1] = (alphaL - alphaT) * (A->dVydy * V[0] / U - V[0] * V[1] * V[1] / (U * U * U) * A->dVydy); + TensorOfdD[2] = (alphaL - alphaT) * (A->dVzdz * V[0] / U - V[0] * V[2] * V[2] / (U * U * U) * A->dVzdz); + TensorOfdD[3] = (alphaL - alphaT) * (A->dVxdx * V[1] / U - V[1] * V[0] * V[0] / (U * U * U) * A->dVxdx); TensorOfdD[4] = V[1] * A->dVydy * (alphaL * (2.0 / U - V[1] * V[1] / (U * U * U)) - - alphaT * (V[0] * V[0] + V[2] * V[2]) / (U * U * U) ); - TensorOfdD[5] = (alphaL - alphaT) * (A->dVzdz * V[1] / U - - V[1] * V[2] * V[2] / (U * U * U) * A->dVzdz); - TensorOfdD[6] = (alphaL - alphaT) * (A->dVxdx * V[2] / U - - V[2] * V[0] * V[0] / (U * U * U) * A->dVxdx); - TensorOfdD[7] = (alphaL - alphaT) * (A->dVydy * V[2] / U - - V[2] * V[1] * V[1] / (U * U * U) * A->dVydy); + - alphaT * (V[0] * V[0] + V[2] * V[2]) / (U * U * U)); + TensorOfdD[5] = (alphaL - alphaT) * (A->dVzdz * V[1] / U - V[1] * V[2] * V[2] / (U * U * U) * A->dVzdz); + TensorOfdD[6] = (alphaL - alphaT) * (A->dVxdx * V[2] / U - V[2] * V[0] * V[0] / (U * U * U) * A->dVxdx); + TensorOfdD[7] = (alphaL - alphaT) * (A->dVydy * V[2] / U - V[2] * V[1] * V[1] / (U * U * U) * A->dVydy); TensorOfdD[8] = V[2] * A->dVzdz * (alphaL * (2.0 / U - V[2] * V[2] / (U * U * U)) - - alphaT * (V[0] * V[0] + V[1] * V[1]) / (U * U * U) ); + - alphaT * (V[0] * V[0] + V[1] * V[1]) / (U * U * U)); // Solve the three displacement by the tensor of dispersion derivative. dD[0] = TensorOfdD[0] + TensorOfdD[1] + TensorOfdD[2]; @@ -1829,25 +1786,25 @@ int RandomWalk::SolveForDisplacementByDerivativeOfDispersion(Particle* A, double **************************************************************************/ int RandomWalk::SolveForDerivativeOfVelocity(Particle* A) { - int status = -10; // Set to be meaningliss in the beginning + int status = -10; // Set to be meaningliss in the beginning m_msh = fem_msh_vector[0]; MeshLib::CElem* m_ele = m_msh->ele_vector[A->elementIndex]; // If not 1D, - if(m_ele->GetDimension()==3) - { - ///1. Get coordinates of the particles, x, y, z - ///2. Find the element where the particle is. - ///3. Compute Gradient of velocity - - ///4. Convert real coordinates to local coordinates - /// Gradient of shape function: CElement::dshapefct - /// Gradient of velocity: - /// =V_i*dshapefct[i]; - return -1; // not supported yet - } - else if(m_ele->GetDimension()==2) - { + if (m_ele->GetDimension() == 3) + { + /// 1. Get coordinates of the particles, x, y, z + /// 2. Find the element where the particle is. + /// 3. Compute Gradient of velocity + + /// 4. Convert real coordinates to local coordinates + /// Gradient of shape function: CElement::dshapefct + /// Gradient of velocity: + /// =V_i*dshapefct[i]; + return -1; // not supported yet + } + else if (m_ele->GetDimension() == 2) + { // intersections for x and y axis double x1[3], x2[3], y1[3], y2[3]; // I don't put the intersections for z direction for now. @@ -1858,9 +1815,9 @@ int RandomWalk::SolveForDerivativeOfVelocity(Particle* A) // RWPT-IM After SolveForTwoIntersectionsInTheElement, // All the coordinates are on the real plane. // Check if the function succeeded. - if(status == -1) + if (status == -1) // printf("Solving two intersections parallel to x axis failed\n"); - return -1; // Failed + return -1; // Failed // Solve for the velocity for two intersections Particle XR, XL; // RWPT-IM @@ -1874,7 +1831,7 @@ int RandomWalk::SolveForDerivativeOfVelocity(Particle* A) XL.z = x2[2]; // Interpolating velocity by the real coordinates should be no problem. - if(PURERWPT != 2) + if (PURERWPT != 2) { InterpolateVelocityOfTheParticleByInverseDistance(&XR); InterpolateVelocityOfTheParticleByInverseDistance(&XL); @@ -1898,14 +1855,14 @@ int RandomWalk::SolveForDerivativeOfVelocity(Particle* A) Vx[1] = XR.Vy - XL.Vy; Vx[2] = XR.Vz - XL.Vz; ToTheXYPlane(A->elementIndex, Vx); - A->dVxdx = Vx[0] / dx; // A->dVxdx = (XR.Vx - XL.Vx) / dx; + A->dVxdx = Vx[0] / dx; // A->dVxdx = (XR.Vx - XL.Vx) / dx; // RWPT-IM Just the same thing one more time. // Get the two intersecitions parallel to y axis status = SolveForTwoIntersectionsInTheElement(A, y1, y2, 1); - if(status == -1) + if (status == -1) // printf("Solving two intersections parallel to y axis failed\n"); - return -1; // Failed + return -1; // Failed // Solve for the velocity for two intersections Particle YR, YL; @@ -1916,7 +1873,7 @@ int RandomWalk::SolveForDerivativeOfVelocity(Particle* A) YL.x = y2[0]; YL.y = y2[1]; YL.z = y2[2]; - if(PURERWPT != 2) + if (PURERWPT != 2) { InterpolateVelocityOfTheParticleByInverseDistance(&YR); InterpolateVelocityOfTheParticleByInverseDistance(&YL); @@ -1937,7 +1894,7 @@ int RandomWalk::SolveForDerivativeOfVelocity(Particle* A) Vy[1] = YR.Vy - YL.Vy; Vy[2] = YR.Vz - YL.Vz; ToTheXYPlane(A->elementIndex, Vy); - A->dVydy = Vy[1] / dy; // A->dVydy = (YR.Vy - YL.Vy) / dy; + A->dVydy = Vy[1] / dy; // A->dVydy = (YR.Vy - YL.Vy) / dy; // Just set dVzdz to be zero for now A->dVzdz = 0.0; @@ -1945,36 +1902,36 @@ int RandomWalk::SolveForDerivativeOfVelocity(Particle* A) // Return 1 for success return 1; } - else // 1D line element + else // 1D line element { // Solve the length of the element double length = m_ele->GetVolume(); m_pcs = PCSGet("FLUID_MOMENTUM"); - //FM_TEST + // FM_TEST int idx = -1, idy = -1, idz = -1; - if(m_pcs) + if (m_pcs) { - idx= m_pcs->GetNodeValueIndex("VELOCITY1_X")+1; - idy= m_pcs->GetNodeValueIndex("VELOCITY1_Y")+1; - idz= m_pcs->GetNodeValueIndex("VELOCITY1_Z")+1; + idx = m_pcs->GetNodeValueIndex("VELOCITY1_X") + 1; + idy = m_pcs->GetNodeValueIndex("VELOCITY1_Y") + 1; + idz = m_pcs->GetNodeValueIndex("VELOCITY1_Z") + 1; } - else if(flow_pcs) + else if (flow_pcs) { - idx= flow_pcs->GetNodeValueIndex("VELOCITY_X1"); - idy= flow_pcs->GetNodeValueIndex("VELOCITY_Y1"); - idz= flow_pcs->GetNodeValueIndex("VELOCITY_Z1"); + idx = flow_pcs->GetNodeValueIndex("VELOCITY_X1"); + idy = flow_pcs->GetNodeValueIndex("VELOCITY_Y1"); + idz = flow_pcs->GetNodeValueIndex("VELOCITY_Z1"); m_pcs = flow_pcs; - if(m_msh->GetCoordinateFlag()/10 == 1) + if (m_msh->GetCoordinateFlag() / 10 == 1) { - if(m_msh->GetCoordinateFlag() == 11) + if (m_msh->GetCoordinateFlag() == 11) { int ibuff = idy; idy = idx; idx = ibuff; } - if(m_msh->GetCoordinateFlag() == 12) + if (m_msh->GetCoordinateFlag() == 12) { int ibuff = idz; idz = idx; @@ -1984,7 +1941,7 @@ int RandomWalk::SolveForDerivativeOfVelocity(Particle* A) } double v1[3], v2[3]; - v1[0] = m_pcs->GetNodeValue(m_ele->GetNodeIndex(0), idx); //FM_TEST + v1[0] = m_pcs->GetNodeValue(m_ele->GetNodeIndex(0), idx); // FM_TEST v1[1] = m_pcs->GetNodeValue(m_ele->GetNodeIndex(0), idy); v1[2] = m_pcs->GetNodeValue(m_ele->GetNodeIndex(0), idz); v2[0] = m_pcs->GetNodeValue(m_ele->GetNodeIndex(0), idx); @@ -1992,30 +1949,29 @@ int RandomWalk::SolveForDerivativeOfVelocity(Particle* A) v2[2] = m_pcs->GetNodeValue(m_ele->GetNodeIndex(0), idz); int coordinateflag = m_msh->GetCoordinateFlag(); - if(coordinateflag == 10) // x only + if (coordinateflag == 10) // x only { A->dVxdx = (v2[0] - v1[0]) / length; A->dVydy = A->dVzdz = 0.0; } - else if(coordinateflag == 11) // y only + else if (coordinateflag == 11) // y only { A->dVydy = (v2[1] - v1[1]) / length; A->dVxdx = A->dVzdz = 0.0; } - else if(coordinateflag == 12) // z only + else if (coordinateflag == 12) // z only { A->dVzdz = (v2[2] - v1[2]) / length; A->dVydy = A->dVxdx = 0.0; } - else // Something Wrong. + else // Something Wrong. abort(); return 1; } } -void RandomWalk::CopyParticleCoordToArray(Particle* A, double* x1buff, - double* x2buff, double* x3buff, double* x4buff) +void RandomWalk::CopyParticleCoordToArray(Particle* A, double* x1buff, double* x2buff, double* x3buff, double* x4buff) { x1buff[0] = A[0].x; x1buff[1] = A[0].y; @@ -2039,10 +1995,10 @@ void RandomWalk::CopyParticleCoordToArray(Particle* A, double* x1buff, **************************************************************************/ double RandomWalk::ComputeVolume(Particle* A, MeshLib::CElem* m_ele) { -// double x1buff[3]; -// double x2buff[3]; -// double x3buff[3]; -// double x4buff[3]; + // double x1buff[3]; + // double x2buff[3]; + // double x3buff[3]; + // double x4buff[3]; double volume = 0.0; double* PieceOfVolume = NULL; @@ -2053,48 +2009,45 @@ double RandomWalk::ComputeVolume(Particle* A, MeshLib::CElem* m_ele) A2buff[2] = A->z; // If this is not a line element, get three verteces. -// if(m_ele->GetElementType()!=MshElemType::LINE) -// { -// node = m_ele->GetNode(0); -// x1buff[0] = node->X(); -// x1buff[1] = node->Y(); -// x1buff[2] = node->Z(); -// -// node = m_ele->GetNode(1); -// x2buff[0] = node->X(); -// x2buff[1] = node->Y(); -// x2buff[2] = node->Z(); -// -// node = m_ele->GetNode(2); -// x3buff[0] = node->X(); -// x3buff[1] = node->Y(); -// x3buff[2] = node->Z(); -// } + // if(m_ele->GetElementType()!=MshElemType::LINE) + // { + // node = m_ele->GetNode(0); + // x1buff[0] = node->X(); + // x1buff[1] = node->Y(); + // x1buff[2] = node->Z(); + // + // node = m_ele->GetNode(1); + // x2buff[0] = node->X(); + // x2buff[1] = node->Y(); + // x2buff[2] = node->Z(); + // + // node = m_ele->GetNode(2); + // x3buff[0] = node->X(); + // x3buff[1] = node->Y(); + // x3buff[2] = node->Z(); + // } - //LINES = 1 + // LINES = 1 if (m_ele->GetElementType() == MshElemType::LINE) { PieceOfVolume = new double[2](); - for(int i = 0; i < 2; ++i) + for (int i = 0; i < 2; ++i) { double const* const pnt(m_ele->GetNode(i)->getData()); - double x2buff[3] = - {pnt[0] - A2buff[0], pnt[1] - A2buff[1], pnt[2] - A2buff[2]}; - PieceOfVolume[i] = sqrt( - x2buff[0] * x2buff[0] + x2buff[1] * x2buff[1] + x2buff[2] * - x2buff[2]); + double x2buff[3] = {pnt[0] - A2buff[0], pnt[1] - A2buff[1], pnt[2] - A2buff[2]}; + PieceOfVolume[i] = sqrt(x2buff[0] * x2buff[0] + x2buff[1] * x2buff[1] + x2buff[2] * x2buff[2]); volume += PieceOfVolume[i]; } } - //RECTANGLES = 2 + // RECTANGLES = 2 if (m_ele->GetElementType() == MshElemType::QUAD) { PieceOfVolume = new double[4](); -// node = m_ele->GetNode(3); -// x4buff[0] = node->X(); -// x4buff[1] = node->Y(); -// x4buff[2] = node->Z(); + // node = m_ele->GetNode(3); + // x4buff[0] = node->X(); + // x4buff[1] = node->Y(); + // x4buff[2] = node->Z(); double const* const x1buff(m_ele->GetNode(0)->getData()); double const* const x2buff(m_ele->GetNode(1)->getData()); double const* const x3buff(m_ele->GetNode(2)->getData()); @@ -2105,31 +2058,31 @@ double RandomWalk::ComputeVolume(Particle* A, MeshLib::CElem* m_ele) PieceOfVolume[2] = ComputeDetTri(x3buff, x4buff, A2buff); PieceOfVolume[3] = ComputeDetTri(x4buff, x1buff, A2buff); - for(int i = 0; i < 4; ++i) + for (int i = 0; i < 4; ++i) volume += PieceOfVolume[i]; } - //HEXAHEDRA = 3 + // HEXAHEDRA = 3 if (m_ele->GetElementType() == MshElemType::HEXAHEDRON) { PieceOfVolume = new double[12](); // 2,1,4,3 face -// node = m_ele->GetNode(1); -// x1buff[0] = node->X(); -// x1buff[1] = node->Y(); -// x1buff[2] = node->Z(); -// node = m_ele->GetNode(0); -// x2buff[0] = node->X(); -// x2buff[1] = node->Y(); -// x2buff[2] = node->Z(); -// node = m_ele->GetNode(3); -// x3buff[0] = node->X(); -// x3buff[1] = node->Y(); -// x3buff[2] = node->Z(); -// node = m_ele->GetNode(2); -// x4buff[0] = node->X(); -// x4buff[1] = node->Y(); -// x4buff[2] = node->Z(); + // node = m_ele->GetNode(1); + // x1buff[0] = node->X(); + // x1buff[1] = node->Y(); + // x1buff[2] = node->Z(); + // node = m_ele->GetNode(0); + // x2buff[0] = node->X(); + // x2buff[1] = node->Y(); + // x2buff[2] = node->Z(); + // node = m_ele->GetNode(3); + // x3buff[0] = node->X(); + // x3buff[1] = node->Y(); + // x3buff[2] = node->Z(); + // node = m_ele->GetNode(2); + // x4buff[0] = node->X(); + // x4buff[1] = node->Y(); + // x4buff[2] = node->Z(); double const* const x1buff(m_ele->GetNode(1)->getData()); double const* const x2buff(m_ele->GetNode(0)->getData()); @@ -2140,22 +2093,22 @@ double RandomWalk::ComputeVolume(Particle* A, MeshLib::CElem* m_ele) PieceOfVolume[1] = ComputeDetTex(A2buff, x2buff, x3buff, x4buff); // 5,6,7,8 face -// node = m_ele->GetNode(4); -// x1buff[0] = node->X(); -// x1buff[1] = node->Y(); -// x1buff[2] = node->Z(); -// node = m_ele->GetNode(5); -// x2buff[0] = node->X(); -// x2buff[1] = node->Y(); -// x2buff[2] = node->Z(); -// node = m_ele->GetNode(6); -// x3buff[0] = node->X(); -// x3buff[1] = node->Y(); -// x3buff[2] = node->Z(); -// node = m_ele->GetNode(7); -// x4buff[0] = node->X(); -// x4buff[1] = node->Y(); -// x4buff[2] = node->Z(); + // node = m_ele->GetNode(4); + // x1buff[0] = node->X(); + // x1buff[1] = node->Y(); + // x1buff[2] = node->Z(); + // node = m_ele->GetNode(5); + // x2buff[0] = node->X(); + // x2buff[1] = node->Y(); + // x2buff[2] = node->Z(); + // node = m_ele->GetNode(6); + // x3buff[0] = node->X(); + // x3buff[1] = node->Y(); + // x3buff[2] = node->Z(); + // node = m_ele->GetNode(7); + // x4buff[0] = node->X(); + // x4buff[1] = node->Y(); + // x4buff[2] = node->Z(); double const* const x1buff1(m_ele->GetNode(4)->getData()); double const* const x2buff1(m_ele->GetNode(5)->getData()); @@ -2166,22 +2119,22 @@ double RandomWalk::ComputeVolume(Particle* A, MeshLib::CElem* m_ele) PieceOfVolume[3] = ComputeDetTex(A2buff, x2buff1, x3buff1, x4buff1); // 1,5,8,4 face -// node = m_ele->GetNode(0); -// x1buff[0] = node->X(); -// x1buff[1] = node->Y(); -// x1buff[2] = node->Z(); -// node = m_ele->GetNode(4); -// x2buff[0] = node->X(); -// x2buff[1] = node->Y(); -// x2buff[2] = node->Z(); -// node = m_ele->GetNode(7); -// x3buff[0] = node->X(); -// x3buff[1] = node->Y(); -// x3buff[2] = node->Z(); -// node = m_ele->GetNode(3); -// x4buff[0] = node->X(); -// x4buff[1] = node->Y(); -// x4buff[2] = node->Z(); + // node = m_ele->GetNode(0); + // x1buff[0] = node->X(); + // x1buff[1] = node->Y(); + // x1buff[2] = node->Z(); + // node = m_ele->GetNode(4); + // x2buff[0] = node->X(); + // x2buff[1] = node->Y(); + // x2buff[2] = node->Z(); + // node = m_ele->GetNode(7); + // x3buff[0] = node->X(); + // x3buff[1] = node->Y(); + // x3buff[2] = node->Z(); + // node = m_ele->GetNode(3); + // x4buff[0] = node->X(); + // x4buff[1] = node->Y(); + // x4buff[2] = node->Z(); double const* const x1buff2(m_ele->GetNode(0)->getData()); double const* const x2buff2(m_ele->GetNode(4)->getData()); @@ -2192,22 +2145,22 @@ double RandomWalk::ComputeVolume(Particle* A, MeshLib::CElem* m_ele) PieceOfVolume[5] = ComputeDetTex(A2buff, x2buff2, x3buff2, x4buff2); // 8,7,3,4 face -// node = m_ele->GetNode(7); -// x1buff[0] = node->X(); -// x1buff[1] = node->Y(); -// x1buff[2] = node->Z(); -// node = m_ele->GetNode(6); -// x2buff[0] = node->X(); -// x2buff[1] = node->Y(); -// x2buff[2] = node->Z(); -// node = m_ele->GetNode(2); -// x3buff[0] = node->X(); -// x3buff[1] = node->Y(); -// x3buff[2] = node->Z(); -// node = m_ele->GetNode(3); -// x4buff[0] = node->X(); -// x4buff[1] = node->Y(); -// x4buff[2] = node->Z(); + // node = m_ele->GetNode(7); + // x1buff[0] = node->X(); + // x1buff[1] = node->Y(); + // x1buff[2] = node->Z(); + // node = m_ele->GetNode(6); + // x2buff[0] = node->X(); + // x2buff[1] = node->Y(); + // x2buff[2] = node->Z(); + // node = m_ele->GetNode(2); + // x3buff[0] = node->X(); + // x3buff[1] = node->Y(); + // x3buff[2] = node->Z(); + // node = m_ele->GetNode(3); + // x4buff[0] = node->X(); + // x4buff[1] = node->Y(); + // x4buff[2] = node->Z(); double const* const x1buff3(m_ele->GetNode(7)->getData()); double const* const x2buff3(m_ele->GetNode(6)->getData()); @@ -2218,22 +2171,22 @@ double RandomWalk::ComputeVolume(Particle* A, MeshLib::CElem* m_ele) PieceOfVolume[7] = ComputeDetTex(A2buff, x2buff3, x3buff3, x4buff3); // 2,3,7,6 face -// node = m_ele->GetNode(1); -// x1buff[0] = node->X(); -// x1buff[1] = node->Y(); -// x1buff[2] = node->Z(); -// node = m_ele->GetNode(2); -// x2buff[0] = node->X(); -// x2buff[1] = node->Y(); -// x2buff[2] = node->Z(); -// node = m_ele->GetNode(6); -// x3buff[0] = node->X(); -// x3buff[1] = node->Y(); -// x3buff[2] = node->Z(); -// node = m_ele->GetNode(5); -// x4buff[0] = node->X(); -// x4buff[1] = node->Y(); -// x4buff[2] = node->Z(); + // node = m_ele->GetNode(1); + // x1buff[0] = node->X(); + // x1buff[1] = node->Y(); + // x1buff[2] = node->Z(); + // node = m_ele->GetNode(2); + // x2buff[0] = node->X(); + // x2buff[1] = node->Y(); + // x2buff[2] = node->Z(); + // node = m_ele->GetNode(6); + // x3buff[0] = node->X(); + // x3buff[1] = node->Y(); + // x3buff[2] = node->Z(); + // node = m_ele->GetNode(5); + // x4buff[0] = node->X(); + // x4buff[1] = node->Y(); + // x4buff[2] = node->Z(); double const* const x1buff4(m_ele->GetNode(1)->getData()); double const* const x2buff4(m_ele->GetNode(2)->getData()); @@ -2244,22 +2197,22 @@ double RandomWalk::ComputeVolume(Particle* A, MeshLib::CElem* m_ele) PieceOfVolume[9] = ComputeDetTex(A2buff, x2buff4, x3buff4, x4buff4); // 1,2,6,5 face -// node = m_ele->GetNode(0); -// x1buff[0] = node->X(); -// x1buff[1] = node->Y(); -// x1buff[2] = node->Z(); -// node = m_ele->GetNode(1); -// x2buff[0] = node->X(); -// x2buff[1] = node->Y(); -// x2buff[2] = node->Z(); -// node = m_ele->GetNode(5); -// x3buff[0] = node->X(); -// x3buff[1] = node->Y(); -// x3buff[2] = node->Z(); -// node = m_ele->GetNode(4); -// x4buff[0] = node->X(); -// x4buff[1] = node->Y(); -// x4buff[2] = node->Z(); + // node = m_ele->GetNode(0); + // x1buff[0] = node->X(); + // x1buff[1] = node->Y(); + // x1buff[2] = node->Z(); + // node = m_ele->GetNode(1); + // x2buff[0] = node->X(); + // x2buff[1] = node->Y(); + // x2buff[2] = node->Z(); + // node = m_ele->GetNode(5); + // x3buff[0] = node->X(); + // x3buff[1] = node->Y(); + // x3buff[2] = node->Z(); + // node = m_ele->GetNode(4); + // x4buff[0] = node->X(); + // x4buff[1] = node->Y(); + // x4buff[2] = node->Z(); double const* const x1buff5(m_ele->GetNode(0)->getData()); double const* const x2buff5(m_ele->GetNode(1)->getData()); @@ -2269,10 +2222,10 @@ double RandomWalk::ComputeVolume(Particle* A, MeshLib::CElem* m_ele) PieceOfVolume[10] = ComputeDetTex(A2buff, x1buff5, x2buff5, x4buff5); PieceOfVolume[11] = ComputeDetTex(A2buff, x2buff5, x3buff5, x4buff5); - for(int i = 0; i < 12; ++i) + for (int i = 0; i < 12; ++i) volume += PieceOfVolume[i]; } - //TRIANGLES = 4 + // TRIANGLES = 4 if (m_ele->GetElementType() == MshElemType::TRIANGLE) { PieceOfVolume = new double[3](); @@ -2285,18 +2238,18 @@ double RandomWalk::ComputeVolume(Particle* A, MeshLib::CElem* m_ele) PieceOfVolume[1] = ComputeDetTri(x2buff, x3buff, A2buff); PieceOfVolume[2] = ComputeDetTri(x3buff, x1buff, A2buff); - for(int i = 0; i < 3; ++i) + for (int i = 0; i < 3; ++i) volume += PieceOfVolume[i]; } - //TETRAHEDRAS = 5 + // TETRAHEDRAS = 5 if (m_ele->GetElementType() == MshElemType::TETRAHEDRON) { PieceOfVolume = new double[4](); -// node = m_ele->GetNode(3); -// x4buff[0] = node->X(); -// x4buff[1] = node->Y(); -// x4buff[2] = node->Z(); + // node = m_ele->GetNode(3); + // x4buff[0] = node->X(); + // x4buff[1] = node->Y(); + // x4buff[2] = node->Z(); double const* const x1buff(m_ele->GetNode(0)->getData()); double const* const x2buff(m_ele->GetNode(1)->getData()); @@ -2308,27 +2261,27 @@ double RandomWalk::ComputeVolume(Particle* A, MeshLib::CElem* m_ele) PieceOfVolume[2] = ComputeDetTex(A2buff, x1buff, x4buff, x2buff); PieceOfVolume[3] = ComputeDetTex(A2buff, x2buff, x3buff, x4buff); - for(int i = 0; i < 4; ++i) + for (int i = 0; i < 4; ++i) volume += PieceOfVolume[i]; } - //PRISMS = 6 + // PRISMS = 6 if (m_ele->GetElementType() == MshElemType::PRISM) { PieceOfVolume = new double[8](); // 2,1,3 face -// node = m_ele->GetNode(1); -// x1buff[0] = node->X(); -// x1buff[1] = node->Y(); -// x1buff[2] = node->Z(); -// node = m_ele->GetNode(0); -// x2buff[0] = node->X(); -// x2buff[1] = node->Y(); -// x2buff[2] = node->Z(); -// node = m_ele->GetNode(2); -// x3buff[0] = node->X(); -// x3buff[1] = node->Y(); -// x3buff[2] = node->Z(); + // node = m_ele->GetNode(1); + // x1buff[0] = node->X(); + // x1buff[1] = node->Y(); + // x1buff[2] = node->Z(); + // node = m_ele->GetNode(0); + // x2buff[0] = node->X(); + // x2buff[1] = node->Y(); + // x2buff[2] = node->Z(); + // node = m_ele->GetNode(2); + // x3buff[0] = node->X(); + // x3buff[1] = node->Y(); + // x3buff[2] = node->Z(); double const* const x1buff(m_ele->GetNode(1)->getData()); double const* const x2buff(m_ele->GetNode(0)->getData()); @@ -2337,18 +2290,18 @@ double RandomWalk::ComputeVolume(Particle* A, MeshLib::CElem* m_ele) PieceOfVolume[0] = ComputeDetTex(A2buff, x1buff, x2buff, x3buff); // 4,5,6 face -// node = m_ele->GetNode(3); -// x1buff[0] = node->X(); -// x1buff[1] = node->Y(); -// x1buff[2] = node->Z(); -// node = m_ele->GetNode(4); -// x2buff[0] = node->X(); -// x2buff[1] = node->Y(); -// x2buff[2] = node->Z(); -// node = m_ele->GetNode(5); -// x3buff[0] = node->X(); -// x3buff[1] = node->Y(); -// x3buff[2] = node->Z(); + // node = m_ele->GetNode(3); + // x1buff[0] = node->X(); + // x1buff[1] = node->Y(); + // x1buff[2] = node->Z(); + // node = m_ele->GetNode(4); + // x2buff[0] = node->X(); + // x2buff[1] = node->Y(); + // x2buff[2] = node->Z(); + // node = m_ele->GetNode(5); + // x3buff[0] = node->X(); + // x3buff[1] = node->Y(); + // x3buff[2] = node->Z(); double const* const x1buff1(m_ele->GetNode(3)->getData()); double const* const x2buff1(m_ele->GetNode(4)->getData()); @@ -2357,22 +2310,22 @@ double RandomWalk::ComputeVolume(Particle* A, MeshLib::CElem* m_ele) PieceOfVolume[1] = ComputeDetTex(A2buff, x1buff1, x2buff1, x3buff1); // 1,4,6,3 face -// node = m_ele->GetNode(0); -// x1buff[0] = node->X(); -// x1buff[1] = node->Y(); -// x1buff[2] = node->Z(); -// node = m_ele->GetNode(3); -// x2buff[0] = node->X(); -// x2buff[1] = node->Y(); -// x2buff[2] = node->Z(); -// node = m_ele->GetNode(5); -// x3buff[0] = node->X(); -// x3buff[1] = node->Y(); -// x3buff[2] = node->Z(); -// node = m_ele->GetNode(2); -// x4buff[0] = node->X(); -// x4buff[1] = node->Y(); -// x4buff[2] = node->Z(); + // node = m_ele->GetNode(0); + // x1buff[0] = node->X(); + // x1buff[1] = node->Y(); + // x1buff[2] = node->Z(); + // node = m_ele->GetNode(3); + // x2buff[0] = node->X(); + // x2buff[1] = node->Y(); + // x2buff[2] = node->Z(); + // node = m_ele->GetNode(5); + // x3buff[0] = node->X(); + // x3buff[1] = node->Y(); + // x3buff[2] = node->Z(); + // node = m_ele->GetNode(2); + // x4buff[0] = node->X(); + // x4buff[1] = node->Y(); + // x4buff[2] = node->Z(); double const* const x1buff2(m_ele->GetNode(0)->getData()); double const* const x2buff2(m_ele->GetNode(3)->getData()); @@ -2383,22 +2336,22 @@ double RandomWalk::ComputeVolume(Particle* A, MeshLib::CElem* m_ele) PieceOfVolume[3] = ComputeDetTex(A2buff, x2buff2, x3buff2, x4buff2); // 2,5,4,1 face -// node = m_ele->GetNode(1); -// x1buff[0] = node->X(); -// x1buff[1] = node->Y(); -// x1buff[2] = node->Z(); -// node = m_ele->GetNode(4); -// x2buff[0] = node->X(); -// x2buff[1] = node->Y(); -// x2buff[2] = node->Z(); -// node = m_ele->GetNode(3); -// x3buff[0] = node->X(); -// x3buff[1] = node->Y(); -// x3buff[2] = node->Z(); -// node = m_ele->GetNode(0); -// x4buff[0] = node->X(); -// x4buff[1] = node->Y(); -// x4buff[2] = node->Z(); + // node = m_ele->GetNode(1); + // x1buff[0] = node->X(); + // x1buff[1] = node->Y(); + // x1buff[2] = node->Z(); + // node = m_ele->GetNode(4); + // x2buff[0] = node->X(); + // x2buff[1] = node->Y(); + // x2buff[2] = node->Z(); + // node = m_ele->GetNode(3); + // x3buff[0] = node->X(); + // x3buff[1] = node->Y(); + // x3buff[2] = node->Z(); + // node = m_ele->GetNode(0); + // x4buff[0] = node->X(); + // x4buff[1] = node->Y(); + // x4buff[2] = node->Z(); double const* const x1buff3(m_ele->GetNode(1)->getData()); double const* const x2buff3(m_ele->GetNode(4)->getData()); @@ -2409,22 +2362,22 @@ double RandomWalk::ComputeVolume(Particle* A, MeshLib::CElem* m_ele) PieceOfVolume[5] = ComputeDetTex(A2buff, x2buff3, x3buff3, x4buff3); // 5,2,3,6 face -// node = m_ele->GetNode(4); -// x1buff[0] = node->X(); -// x1buff[1] = node->Y(); -// x1buff[2] = node->Z(); -// node = m_ele->GetNode(1); -// x2buff[0] = node->X(); -// x2buff[1] = node->Y(); -// x2buff[2] = node->Z(); -// node = m_ele->GetNode(2); -// x3buff[0] = node->X(); -// x3buff[1] = node->Y(); -// x3buff[2] = node->Z(); -// node = m_ele->GetNode(5); -// x4buff[0] = node->X(); -// x4buff[1] = node->Y(); -// x4buff[2] = node->Z(); + // node = m_ele->GetNode(4); + // x1buff[0] = node->X(); + // x1buff[1] = node->Y(); + // x1buff[2] = node->Z(); + // node = m_ele->GetNode(1); + // x2buff[0] = node->X(); + // x2buff[1] = node->Y(); + // x2buff[2] = node->Z(); + // node = m_ele->GetNode(2); + // x3buff[0] = node->X(); + // x3buff[1] = node->Y(); + // x3buff[2] = node->Z(); + // node = m_ele->GetNode(5); + // x4buff[0] = node->X(); + // x4buff[1] = node->Y(); + // x4buff[2] = node->Z(); double const* const x1buff4(m_ele->GetNode(4)->getData()); double const* const x2buff4(m_ele->GetNode(1)->getData()); @@ -2434,12 +2387,12 @@ double RandomWalk::ComputeVolume(Particle* A, MeshLib::CElem* m_ele) PieceOfVolume[6] = ComputeDetTex(A2buff, x1buff4, x2buff4, x4buff4); PieceOfVolume[7] = ComputeDetTex(A2buff, x2buff4, x3buff4, x4buff4); - for(int i = 0; i < 8; ++i) + for (int i = 0; i < 8; ++i) volume += PieceOfVolume[i]; } // Release the memory - delete [] PieceOfVolume; + delete[] PieceOfVolume; return volume; } @@ -2475,7 +2428,7 @@ double RandomWalk::ComputeVolume(Particle* A, Particle* element, MeshLib::CElem* x3buff[1] = element[2].y; x3buff[2] = element[2].z; - //TRIANGLES = 4, RECTANGLE = 2 + // TRIANGLES = 4, RECTANGLE = 2 int eleType = m_ele->GetElementType(); if (eleType == MshElemType::TRIANGLE || eleType == MshElemType::QUAD) { @@ -2485,12 +2438,11 @@ double RandomWalk::ComputeVolume(Particle* A, Particle* element, MeshLib::CElem* PieceOfVolume[1] = ComputeDetTri(x2buff, x3buff, A2buff); PieceOfVolume[2] = ComputeDetTri(x3buff, x1buff, A2buff); - for(int i = 0; i < 3; ++i) + for (int i = 0; i < 3; ++i) volume += PieceOfVolume[i]; } - //TETRAHEDRAS = 5, HEXAHEDRA = 3, PRISM = 6 - else if (eleType == MshElemType::TETRAHEDRON || eleType == MshElemType::HEXAHEDRON || - eleType == MshElemType::PRISM) + // TETRAHEDRAS = 5, HEXAHEDRA = 3, PRISM = 6 + else if (eleType == MshElemType::TETRAHEDRON || eleType == MshElemType::HEXAHEDRON || eleType == MshElemType::PRISM) { PieceOfVolume = new double[4](); @@ -2503,14 +2455,14 @@ double RandomWalk::ComputeVolume(Particle* A, Particle* element, MeshLib::CElem* PieceOfVolume[2] = ComputeDetTex(A2buff, x1buff, x4buff, x2buff); PieceOfVolume[3] = ComputeDetTex(A2buff, x2buff, x3buff, x4buff); - for(int i = 0; i < 4; ++i) + for (int i = 0; i < 4; ++i) volume += PieceOfVolume[i]; } else abort(); // Release the memory - delete [] PieceOfVolume; + delete[] PieceOfVolume; return volume; } @@ -2525,11 +2477,11 @@ double RandomWalk::ComputeVolume(Particle* A, Particle* element, MeshLib::CElem* void RandomWalk::AdvanceBySplitTime(double dt, int numOfSplit) { double subdt = dt / (double)numOfSplit; - double ctime = 0.0; //JT 05.2010: for continuous source compatible with SplitTimes. + double ctime = 0.0; // JT 05.2010: for continuous source compatible with SplitTimes. leavingParticles = 0; - for(int i = 0; i < numOfSplit; ++i) + for (int i = 0; i < numOfSplit; ++i) { - AdvanceToNextTimeStep(subdt,ctime); + AdvanceToNextTimeStep(subdt, ctime); ctime += subdt; } } @@ -2542,17 +2494,17 @@ void RandomWalk::AdvanceBySplitTime(double dt, int numOfSplit) **************************************************************************/ void RandomWalk::TraceStreamline(void) { - //OK411 double tolerance = 1e-18; + // OK411 double tolerance = 1e-18; // Loop over all the particles - for(int i = 0; i < numOfParticles; ++i) - if(X[i].Now.elementIndex != -10) + for (int i = 0; i < numOfParticles; ++i) + if (X[i].Now.elementIndex != -10) { // Let's record the current to the past // InterpolateVelocity(&(X[i].Now)); TracePathlineInThisElement(&(X[i].Now)); // Record path - if(i < 50) + if (i < 50) RecordPath(i, &(X[i].Now)); } @@ -2561,7 +2513,7 @@ void RandomWalk::TraceStreamline(void) // This messagebox is for debugging the primary variables at every time step. // Should combine with the picking... CWnd* pWnd = NULL; - pWnd->MessageBox("Split second!!!","Debug help", MB_ICONINFORMATION); + pWnd->MessageBox("Split second!!!", "Debug help", MB_ICONINFORMATION); #endif } @@ -2573,14 +2525,14 @@ void RandomWalk::TraceStreamline(void) 05/2009 PCH mobiility of particle now defined in .mcp via components 06/2009 PCH Case specific apps for RWPT defined by rwpt_app **************************************************************************/ -void RandomWalk::AdvanceToNextTimeStep(double dt,double ctime) +void RandomWalk::AdvanceToNextTimeStep(double dt, double ctime) { double tolerance = 1e-18; double tol = 1e-10; int TimeMobility; // 05.2010 JT double exceedtime = aktuelle_zeit + MKleinsteZahl + ctime; - // Loop over all the particles +// Loop over all the particles #ifdef _OPENMP std::cout << "[RandomWalk::AdvanceToNextTimeStep] OpenMP parallelized loop ... " << std::flush; #else @@ -2590,12 +2542,12 @@ void RandomWalk::AdvanceToNextTimeStep(double dt,double ctime) start = clock(); m_pcs = PCSGet("FLUID_MOMENTUM"); - if(!m_pcs && flow_pcs) + if (!m_pcs && flow_pcs) { m_pcs = flow_pcs; } - if(!m_pcs) + if (!m_pcs) { std::cerr << "No flow process defined\n"; exit(1); @@ -2604,38 +2556,36 @@ void RandomWalk::AdvanceToNextTimeStep(double dt,double ctime) #ifdef _OPENMP #pragma omp parallel for #endif - for(int i = 0; i < numOfParticles; ++i) + for (int i = 0; i < numOfParticles; ++i) { - TimeMobility = 0; //JT 2010, using this for now. Setting identity = 1 causes simulation failure... not sure why?? - //X[i].Now.identity=1; - if((X[i].Now.StartingTime < exceedtime) || - fabs(X[i].Now.StartingTime - exceedtime) < tol) + TimeMobility + = 0; // JT 2010, using this for now. Setting identity = 1 causes simulation failure... not sure why?? + // X[i].Now.identity=1; + if ((X[i].Now.StartingTime < exceedtime) || fabs(X[i].Now.StartingTime - exceedtime) < tol) TimeMobility = 1; - //X[i].Now.identity=0; + // X[i].Now.identity=0; // components defined in .mcp should be syncronized with identity of particles. CompProperties* m_cp = cp_vec[0]; // If mobile, do transport. - if(m_cp->mobil && TimeMobility > 0) + if (m_cp->mobil && TimeMobility > 0) { - Particle Y; // the displaced particle + Particle Y; // the displaced particle int Astatus = 100; // Set to be meaningless - if(X[i].Now.elementIndex != -10 && X[i].Now.identity != 2) + if (X[i].Now.elementIndex != -10 && X[i].Now.identity != 2) { // Let's record the current to the past - if(PURERWPT != 2) - InterpolateVelocityOfTheParticleByInverseDistance(&(X[i]. - Now)); + if (PURERWPT != 2) + InterpolateVelocityOfTheParticleByInverseDistance(&(X[i].Now)); else - InterpolateVelocityOfTheParticleByBilinear(GridOption, - &(X[i].Now)); + InterpolateVelocityOfTheParticleByBilinear(GridOption, &(X[i].Now)); // If the mode is for heterogeneous media - if(RWPTMode == 0 || RWPTMode == 1 || RWPTMode == 3) + if (RWPTMode == 0 || RWPTMode == 1 || RWPTMode == 3) SolveForDerivativeOfVelocity(&(X[i].Now)); - if(RWPTMode < 2 || RWPTMode > 3) // 0 or 1 for advection and dispersion cases. + if (RWPTMode < 2 || RWPTMode > 3) // 0 or 1 for advection and dispersion cases. SolveDispersionCoefficient(&(X[i].Now)); // Initialize the reference and past particles @@ -2645,61 +2595,52 @@ void RandomWalk::AdvanceToNextTimeStep(double dt,double ctime) Y.t = dt; // Record path - //if(i<50) // JT :: no longer needed... just use .particle outpus and Paraview - //RecordPath(i, &Y); + // if(i<50) // JT :: no longer needed... just use .particle outpus and Paraview + // RecordPath(i, &Y); do { // Let's update the info of Particle Y. - if(PURERWPT != 2) - InterpolateVelocityOfTheParticleByInverseDistance( - &Y); + if (PURERWPT != 2) + InterpolateVelocityOfTheParticleByInverseDistance(&Y); else - InterpolateVelocityOfTheParticleByBilinear( - GridOption, - &Y); + InterpolateVelocityOfTheParticleByBilinear(GridOption, &Y); - if(RWPTMode < 4) + if (RWPTMode < 4) SolveForDerivativeOfVelocity(&Y); - if(RWPTMode < 2 || RWPTMode > 3) // whenever dispersion is on + if (RWPTMode < 2 || RWPTMode > 3) // whenever dispersion is on SolveDispersionCoefficient(&Y); - if(Astatus == -1) + if (Astatus == -1) Y.t = dt; - //YS: absorbed and filtered particles don't move, but absorbed particles can be desorpted - if(X[i].Now.identity == 0) + // YS: absorbed and filtered particles don't move, but absorbed particles can be desorpted + if (X[i].Now.identity == 0) Astatus = SolveForNextPosition(&(X[i].Now), &Y); -//#ifdef CountParticleNumber - if((m_pcs->rwpt_count == 1) && (Y.identity != 2)) - { - if((fabs(Y.x - 0.1)<0.001 && fabs(Y.y - 0.0)<0.001 && fabs(Y.z - 0.0)<0.001)) + //#ifdef CountParticleNumber + if ((m_pcs->rwpt_count == 1) && (Y.identity != 2)) + { + if ((fabs(Y.x - 0.1) < 0.001 && fabs(Y.y - 0.0) < 0.001 && fabs(Y.z - 0.0) < 0.001)) { leavingParticles++; - Y.elementIndex = -10; //YS: out of the domain + Y.elementIndex = -10; // YS: out of the domain } - } -//#endif + } + //#endif // Just get the element index after this movement // if not Homogeneous aquifer - if(RWPTMode % 2 == 1) + if (RWPTMode % 2 == 1) { - if(PURERWPT != 2) - Y.elementIndex = - IndexOfTheElementThatThisParticleBelong( - 1, - &Y); + if (PURERWPT != 2) + Y.elementIndex = IndexOfTheElementThatThisParticleBelong(1, &Y); // Y.elementIndex = GetTheElementOfTheParticle(&(X[i].Now), &Y); else - Y.elementIndex = - IndexOfTheElementThatThisParticleBelong( - 0, - &Y); + Y.elementIndex = IndexOfTheElementThatThisParticleBelong(0, &Y); } // We let the particle go outside of the domain - if(Y.elementIndex == -10) + if (Y.elementIndex == -10) { // Before letting this particle outside of the domain, // record the particle postion that includes the element index = -10. @@ -2707,28 +2648,28 @@ void RandomWalk::AdvanceToNextTimeStep(double dt,double ctime) break; } - // 07.2011 YS - if(Y.on_boundary != 0) - { - // record particle position - X[i].Now = Y; - break; - } + // 07.2011 YS + if (Y.on_boundary != 0) + { + // record particle position + X[i].Now = Y; + break; + } // The result of the function is unknown error. - if(Astatus == -2) + if (Astatus == -2) { printf("Astatus = %d\n", Astatus); abort(); } // Particle goes outside of the domain. // Thus, do it again. - else if(Astatus == -1) + else if (Astatus == -1) Y = X[i].Now; // Right on track. Keep going. else { // If particle stays in the element, Y.t = dt. - if(Y.t < tolerance) + if (Y.t < tolerance) Y.t = dt; // Update the current info @@ -2740,18 +2681,18 @@ void RandomWalk::AdvanceToNextTimeStep(double dt,double ctime) // Keep looping if the time is not spent all or // if the particle is outside of the domain or // if the function fails - } while ( Y.t < dt ); + } while (Y.t < dt); // Record path - //if(i<50) // JT :: no longer needed - //RecordPath(i, &Y); + // if(i<50) // JT :: no longer needed + // RecordPath(i, &Y); // Update the correct dt X[i].Now.t = X[i].Past.t + dt; } } // Now ODE parts in RWPT - if(m_pcs->rwpt_app == 1) // Is the application is Cell Dynamics? + if (m_pcs->rwpt_app == 1) // Is the application is Cell Dynamics? { /* // Do mobile-Immobile by switching the identity of particles @@ -2783,7 +2724,8 @@ void RandomWalk::AdvanceToNextTimeStep(double dt,double ctime) else ; } - else if( ChanceOfMobile < ( (1.0-exp(-Koff[0]*dt))*Kon[0]/Koff[0] + (1.0-exp(-Koff[1]*dt))*Kon[1]/Koff[1]) ) + else if( ChanceOfMobile < ( (1.0-exp(-Koff[0]*dt))*Kon[0]/Koff[0] + + (1.0-exp(-Koff[1]*dt))*Kon[1]/Koff[1]) ) { if(numOfComps > 2) // If the number of components is bigger than 2, X[i].Now.identity = 2; // Make another kind of immobile @@ -2817,46 +2759,43 @@ void RandomWalk::AdvanceToNextTimeStep(double dt,double ctime) delete [] Kon; delete [] Koff; */ } - else if(m_pcs->rwpt_app == 2) // Is the application Cryptosporidium oocysts? + else if (m_pcs->rwpt_app == 2) // Is the application Cryptosporidium oocysts? { - if(X[i].Now.elementIndex != -10 && X[i].Now.identity != 2) - { - // Do sorption-desorption by switching the identity of particles - double ChanceOfSorbtion = randomZeroToOne(); - // Two-Rate Model: N/N0=Ae^(-k1t)+(1-A)e^(-k2t) - if(m_cp->isotherm_model == 5) + if (X[i].Now.elementIndex != -10 && X[i].Now.identity != 2) { - double A = m_cp->isotherm_model_values[0]; - double k1 = m_cp->isotherm_model_values[1]; - double k2 = m_cp->isotherm_model_values[2]; - double FractionRemainingOnMedia = Two_rateModel(A, - k1, - k2, - X[i].Now.t); - - if( ChanceOfSorbtion < FractionRemainingOnMedia ) - X[i].Now.identity = 1; // Temporarily absorbed - else - X[i].Now.identity = 0; - } + // Do sorption-desorption by switching the identity of particles + double ChanceOfSorbtion = randomZeroToOne(); + // Two-Rate Model: N/N0=Ae^(-k1t)+(1-A)e^(-k2t) + if (m_cp->isotherm_model == 5) + { + double A = m_cp->isotherm_model_values[0]; + double k1 = m_cp->isotherm_model_values[1]; + double k2 = m_cp->isotherm_model_values[2]; + double FractionRemainingOnMedia = Two_rateModel(A, k1, k2, X[i].Now.t); - // Irreversible Reactions - Oocysts filtered for good or some chemicals decayed - // C/C0 = exp(-kt) - // For oocyst irreversible filtration, k = vp * lambda + if (ChanceOfSorbtion < FractionRemainingOnMedia) + X[i].Now.identity = 1; // Temporarily absorbed + else + X[i].Now.identity = 0; + } + + // Irreversible Reactions - Oocysts filtered for good or some chemicals decayed + // C/C0 = exp(-kt) + // For oocyst irreversible filtration, k = vp * lambda double lamda = m_cp->decay_model_values[0]; double k = X[i].Now.Vx * lamda; double Irreversed = exp(-k * X[i].Now.t); - if( ChanceOfIrreversed[i] > Irreversed ) - X[i].Now.identity = 2; // Permanently filtered + if (ChanceOfIrreversed[i] > Irreversed) + X[i].Now.identity = 2; // Permanently filtered } } - else // For some other applications with different kinetics + else // For some other applications with different kinetics { } } - stop = clock(); - std::cout << " took " << (stop-start)/(double)(CLOCKS_PER_SEC) << " seconds" << std::endl; + stop = clock(); + std::cout << " took " << (stop - start) / (double)(CLOCKS_PER_SEC) << " seconds" << std::endl; } /************************************************************************** @@ -2896,11 +2835,10 @@ void RandomWalk::RandomWalkOutput(double dbl_time, int current_time_step) continue; outputornot = false; - out->setTime (CurrentTime); + out->setTime(CurrentTime); size_t no_times = out->getRWPTTimeVector().size(); - if (no_times == 0 && (out->getNSteps() > 0) && - (current_time_step % out->getNSteps() == 0)) + if (no_times == 0 && (out->getNSteps() > 0) && (current_time_step % out->getNSteps() == 0)) outputornot = true; if (current_time_step < 2) outputornot = true; @@ -2908,8 +2846,8 @@ void RandomWalk::RandomWalkOutput(double dbl_time, int current_time_step) if (outputornot) if (current_name.compare("PARTICLES") == 0) DATWriteParticleFile(current_time_step); - //else if(current_name.compare("PARTICLE_CONCENTRATION")==0) - //DATWriteParticleConcFile(current_time_step); // routine not yet configured + // else if(current_name.compare("PARTICLE_CONCENTRATION")==0) + // DATWriteParticleConcFile(current_time_step); // routine not yet configured { for (size_t j = 0; j < no_times; j++) if (CurrentTime >= out->getRWPTTimeVector()[j]) @@ -2917,11 +2855,11 @@ void RandomWalk::RandomWalkOutput(double dbl_time, int current_time_step) if (current_name.compare("PARTICLES") == 0) DATWriteParticleFile(current_time_step); - //else if(current_name.compare("PARTICLE_CONCENTRATION")==0) - //DATWriteParticleConcFile(current_time_step); // routine not yet configured (see commented text below) + // else if(current_name.compare("PARTICLE_CONCENTRATION")==0) + // DATWriteParticleConcFile(current_time_step); // routine not yet configured (see commented text + // below) - out->getRWPTTimeVector().erase( - out->getRWPTTimeVector().begin() + j); + out->getRWPTTimeVector().erase(out->getRWPTTimeVector().begin() + j); break; } } @@ -2987,7 +2925,7 @@ void RandomWalk::ConcPTFile(const char* file_name) FILE* pct_file = NULL; char pct_file_name[MAX_ZEILE]; - CFEMesh* m_msh (selectMeshForFluidMomentumProcess()); + CFEMesh* m_msh(selectMeshForFluidMomentumProcess()); // // Mount the proper mesh // for(int i=0; i< (int)pcs_vector.size(); ++i) // { @@ -3002,20 +2940,20 @@ void RandomWalk::ConcPTFile(const char* file_name) // m_msh = FEMGet("GROUNDWATER_FLOW"); // } - sprintf(pct_file_name,"%s.conc",file_name); - pct_file = fopen(pct_file_name,"w+t"); + sprintf(pct_file_name, "%s.conc", file_name); + pct_file = fopen(pct_file_name, "w+t"); // Make a grid int gridDensity = 0; // Search Max and Min of each axis double MaxX = -1e6, MinX = 1e6; - for(size_t i = 0; i < m_msh->nod_vector.size(); ++i) + for (size_t i = 0; i < m_msh->nod_vector.size(); ++i) { -// TF MeshLib::CNode* thisNode = m_msh->nod_vector[i] + // TF MeshLib::CNode* thisNode = m_msh->nod_vector[i] double x_coord(m_msh->nod_vector[i]->getData()[0]); - if(MaxX < x_coord) + if (MaxX < x_coord) MaxX = x_coord; - if(MinX > x_coord) + if (MinX > x_coord) MinX = x_coord; } @@ -3024,16 +2962,16 @@ void RandomWalk::ConcPTFile(const char* file_name) fprintf(pct_file, "VARIABLES = X,Y,Z,CONCENTRATION0\n"); fprintf(pct_file, "ZONE T=\"%fs\", I=%d, F=POINT, C=BLACK\n", X[0].Now.t, gridDensity); - for(int i = 0; i < gridDensity; ++i) + for (int i = 0; i < gridDensity; ++i) { int count = 0; double seg_start = 0.0, seg_end = 0.0; - for(int j = 0; j < numOfParticles; ++j) + for (int j = 0; j < numOfParticles; ++j) { seg_start = MinX + i; seg_end = MinX + i + 1.0; - if( (X[j].Now.x >= seg_start) && (X[j].Now.x < seg_end) ) + if ((X[j].Now.x >= seg_start) && (X[j].Now.x < seg_end)) ++count; } // fprintf(pct_file, "%f 0.0 0.0 %f\n", (seg_start+seg_end)/2.0, count / numOfParticles); @@ -3065,7 +3003,7 @@ double RandomWalk::Two_rateModel(double A, double k1, double k2, double t) **************************************************************************/ void RandomWalk::RandomlyDriftAway(Particle* A, double dt, double* delta, int type) { - //OK411 + // OK411 type = type; dt = dt; @@ -3076,9 +3014,9 @@ void RandomWalk::RandomlyDriftAway(Particle* A, double dt, double* delta, int ty // Here I tell the dimension for the element that contains the particle A int ele_dim = m_ele->GetDimension(); - if(ele_dim == 1) + if (ele_dim == 1) { - if(UniformOrNormal == 1) + if (UniformOrNormal == 1) { Z[0] = randomMinusOneToOne(); delta[0] = sqrt(6.0 * A->D[0] * dt) * Z[0]; @@ -3093,66 +3031,50 @@ void RandomWalk::RandomlyDriftAway(Particle* A, double dt, double* delta, int ty delta[2] = 0.0; } } - else if(ele_dim == 2) + else if (ele_dim == 2) { - if(UniformOrNormal == 1) + if (UniformOrNormal == 1) { Z[0] = randomMinusOneToOne(); Z[1] = randomMinusOneToOne(); - delta[0] = - sqrt(6.0 * A->D[0] * dt) * Z[0] + sqrt(6.0 * A->D[1] * dt) * Z[1]; - delta[1] = - sqrt(6.0 * A->D[3] * dt) * Z[0] + sqrt(6.0 * A->D[4] * dt) * Z[1]; + delta[0] = sqrt(6.0 * A->D[0] * dt) * Z[0] + sqrt(6.0 * A->D[1] * dt) * Z[1]; + delta[1] = sqrt(6.0 * A->D[3] * dt) * Z[0] + sqrt(6.0 * A->D[4] * dt) * Z[1]; delta[2] = 0.0; } else { Z[0] = Marsaglia(); Z[1] = Marsaglia(); - delta[0] = - sqrt(2.0 * A->D[0] * dt) * Z[0] + sqrt(2.0 * A->D[1] * dt) * Z[1]; - delta[1] = - sqrt(2.0 * A->D[3] * dt) * Z[0] + sqrt(2.0 * A->D[4] * dt) * Z[1]; + delta[0] = sqrt(2.0 * A->D[0] * dt) * Z[0] + sqrt(2.0 * A->D[1] * dt) * Z[1]; + delta[1] = sqrt(2.0 * A->D[3] * dt) * Z[0] + sqrt(2.0 * A->D[4] * dt) * Z[1]; delta[2] = 0.0; } } - else if(ele_dim == 3) + else if (ele_dim == 3) { - if(UniformOrNormal == 1) + if (UniformOrNormal == 1) { Z[0] = randomMinusOneToOne(); Z[1] = randomMinusOneToOne(); Z[2] = randomMinusOneToOne(); - delta[0] = - sqrt(6.0 * A->D[0] * - dt) * Z[0] + sqrt(6.0 * A->D[1] * dt) * Z[1] + sqrt( - 6.0 * A->D[2] * dt) * Z[2]; - delta[1] = - sqrt(6.0 * A->D[3] * - dt) * Z[0] + sqrt(6.0 * A->D[4] * dt) * Z[1] + sqrt( - 6.0 * A->D[5] * dt) * Z[2]; - delta[2] = - sqrt(6.0 * A->D[6] * - dt) * Z[0] + sqrt(6.0 * A->D[7] * dt) * Z[1] + sqrt( - 6.0 * A->D[8] * dt) * Z[2]; + delta[0] + = sqrt(6.0 * A->D[0] * dt) * Z[0] + sqrt(6.0 * A->D[1] * dt) * Z[1] + sqrt(6.0 * A->D[2] * dt) * Z[2]; + delta[1] + = sqrt(6.0 * A->D[3] * dt) * Z[0] + sqrt(6.0 * A->D[4] * dt) * Z[1] + sqrt(6.0 * A->D[5] * dt) * Z[2]; + delta[2] + = sqrt(6.0 * A->D[6] * dt) * Z[0] + sqrt(6.0 * A->D[7] * dt) * Z[1] + sqrt(6.0 * A->D[8] * dt) * Z[2]; } else { Z[0] = Marsaglia(); Z[1] = Marsaglia(); Z[2] = Marsaglia(); - delta[0] = - sqrt(2.0 * A->D[0] * - dt) * Z[0] + sqrt(2.0 * A->D[1] * dt) * Z[1] + sqrt( - 2.0 * A->D[2] * dt) * Z[2]; - delta[1] = - sqrt(2.0 * A->D[3] * - dt) * Z[0] + sqrt(2.0 * A->D[4] * dt) * Z[1] + sqrt( - 2.0 * A->D[5] * dt) * Z[2]; - delta[2] = - sqrt(2.0 * A->D[6] * - dt) * Z[0] + sqrt(2.0 * A->D[7] * dt) * Z[1] + sqrt( - 2.0 * A->D[8] * dt) * Z[2]; + delta[0] + = sqrt(2.0 * A->D[0] * dt) * Z[0] + sqrt(2.0 * A->D[1] * dt) * Z[1] + sqrt(2.0 * A->D[2] * dt) * Z[2]; + delta[1] + = sqrt(2.0 * A->D[3] * dt) * Z[0] + sqrt(2.0 * A->D[4] * dt) * Z[1] + sqrt(2.0 * A->D[5] * dt) * Z[2]; + delta[2] + = sqrt(2.0 * A->D[6] * dt) * Z[0] + sqrt(2.0 * A->D[7] * dt) * Z[1] + sqrt(2.0 * A->D[8] * dt) * Z[2]; } } } @@ -3166,22 +3088,22 @@ void RandomWalk::RandomlyDriftAway(Particle* A, double dt, double* delta, int ty **************************************************************************/ int RandomWalk::RandomWalkDrift(double* Z, int dim) { - if(dim == 1) // Generate the faster one. + if (dim == 1) // Generate the faster one. { - Z[0] = randomMinusOneToOne(); + Z[0] = randomMinusOneToOne(); Z[1] = Z[2] = 0.0; return 1; } - else if(dim == 2) // Generate the normal distribution one + else if (dim == 2) // Generate the normal distribution one { - Z[0] = randomMinusOneToOne(); + Z[0] = randomMinusOneToOne(); Z[1] = randomMinusOneToOne(); Z[2] = 0.0; return 1; } - else if(dim == 3) + else if (dim == 3) { Z[0] = randomMinusOneToOne(); Z[1] = randomMinusOneToOne(); @@ -3195,7 +3117,7 @@ int RandomWalk::RandomWalkDrift(double* Z, int dim) abort(); } - return -1; // Failed. + return -1; // Failed. } /************************************************************************** @@ -3242,8 +3164,8 @@ void RandomWalk::SolveDispersionCoefficient(Particle* A) // Thus, I only divide Darcy velocity by porosity only to get pore velocity. CMediumProperties* MediaProp = mmp_vector[m_ele->GetPatchIndex()]; double porosity = 0.0; - if(MediaProp->porosity > 10 - 6) - porosity = MediaProp->porosity; // This is for simple one. + if (MediaProp->porosity > 10 - 6) + porosity = MediaProp->porosity; // This is for simple one. else // This will get you porosity. porosity = MediaProp->porosity_model_values[0]; @@ -3251,14 +3173,10 @@ void RandomWalk::SolveDispersionCoefficient(Particle* A) double molecular_diffusion_value = 0.0; // components defined in .mcp should be syncronized with identity of particles. CompProperties* m_cp = cp_vec[0]; - double g[3] = {0.,0.,0.}; - double theta = 1.0; // I'll just set it to be unity for moment. - molecular_diffusion_value = - m_cp->CalcDiffusionCoefficientCP(A->elementIndex,1.0, - m_pcs) * MediaProp->TortuosityFunction( - A->elementIndex, - g, - theta); + double g[3] = {0., 0., 0.}; + double theta = 1.0; // I'll just set it to be unity for moment. + molecular_diffusion_value = m_cp->CalcDiffusionCoefficientCP(A->elementIndex, 1.0, m_pcs) + * MediaProp->TortuosityFunction(A->elementIndex, g, theta); molecular_diffusion_value /= porosity; // This should be divided by porosity in this RWPT method. // Just solve for the magnitude of the velocity to compute the dispersion tensor @@ -3269,44 +3187,38 @@ void RandomWalk::SolveDispersionCoefficient(Particle* A) // RWPT-IM // Let's transform this velocity to be on the xy plane // Some nice if condition to tell the need for transform will be nice. Later.... - if(m_ele->GetDimension() < 3 && (m_ele->GetDimension() != m_msh->GetMaxElementDim())) + if (m_ele->GetDimension() < 3 && (m_ele->GetDimension() != m_msh->GetMaxElementDim())) ToTheXYPlane(m_ele, V); double Vmagnitude = sqrt(V[0] * V[0] + V[1] * V[1] + V[2] * V[2]); // Compute the dispersion tensor at the particle location // If the magnitude of velocity is not zero. - if(Vmagnitude > tolerance) + if (Vmagnitude > tolerance) { // Dxx - A->D[0] = - (alphaT * - (V[1] * V[1] + V[2] * - V[2]) + alphaL * V[0] * V[0]) / Vmagnitude + molecular_diffusion_value; + A->D[0] + = (alphaT * (V[1] * V[1] + V[2] * V[2]) + alphaL * V[0] * V[0]) / Vmagnitude + molecular_diffusion_value; // Dxy = Dyz A->D[1] = A->D[3] = (alphaL - alphaT) * V[0] * V[1] / Vmagnitude; // Dxz = Dzx A->D[2] = A->D[6] = (alphaL - alphaT) * V[0] * V[2] / Vmagnitude; // Dyy - A->D[4] = - (alphaT * - (V[0] * V[0] + V[2] * - V[2]) + alphaL * V[1] * V[1]) / Vmagnitude + molecular_diffusion_value; + A->D[4] + = (alphaT * (V[0] * V[0] + V[2] * V[2]) + alphaL * V[1] * V[1]) / Vmagnitude + molecular_diffusion_value; // Dyz = Dzy A->D[5] = A->D[7] = (alphaL - alphaT) * V[1] * V[2] / Vmagnitude; // Dzz - A->D[8] = - (alphaT * - (V[0] * V[0] + V[1] * - V[1]) + alphaL * V[2] * V[2]) / Vmagnitude + molecular_diffusion_value; + A->D[8] + = (alphaT * (V[0] * V[0] + V[1] * V[1]) + alphaL * V[2] * V[2]) / Vmagnitude + molecular_diffusion_value; } else { A->D[0] = molecular_diffusion_value; // Dxx - A->D[1] = A->D[3] = 0.0; // Dxy = Dyz - A->D[2] = A->D[6] = 0.0; // Dxz = Dzx + A->D[1] = A->D[3] = 0.0; // Dxy = Dyz + A->D[2] = A->D[6] = 0.0; // Dxz = Dzx A->D[4] = molecular_diffusion_value; // Dyy - A->D[5] = A->D[7] = 0.0; // Dyz = Dzy + A->D[5] = A->D[7] = 0.0; // Dyz = Dzy A->D[8] = molecular_diffusion_value; // Dzz } } @@ -3318,63 +3230,68 @@ Task: Check whether the particle is out of the domain and get the pierced point */ void RandomWalk::CheckBoundary2D(Particle* A, Particle* B) { - //firstly, check if the particle is inside of the domain + // firstly, check if the particle is inside of the domain int eleindex = SearchElementFromNeighbor(B); - if(eleindex > -1) + if (eleindex > -1) { - B->elementIndex = eleindex; - B->on_boundary = 0; - return; + B->elementIndex = eleindex; + B->on_boundary = 0; + return; } // If the particle is out of domain, find the intersection point between the path line and // the boundary. // But check the old position first, in case it is already on the boundary. - if ( A->on_boundary ) - { - // drag B back to the A position - B->x = A->x; B->y = A->y; - B->elementIndex = A->elementIndex; - B->on_boundary = A->on_boundary; - B->identity = A->identity; - } + if (A->on_boundary) + { + // drag B back to the A position + B->x = A->x; + B->y = A->y; + B->elementIndex = A->elementIndex; + B->on_boundary = A->on_boundary; + B->identity = A->identity; + } else - { - double p1[2], p2[2], p3[2], p4[2]; - double xx, yy, ua, ub; + { + double p1[2], p2[2], p3[2], p4[2]; + double xx, yy, ua, ub; - p3[0] = A->x; p3[1] = A->y; - p4[0] = B->x; p4[1] = B->y; + p3[0] = A->x; + p3[1] = A->y; + p4[0] = B->x; + p4[1] = B->y; - MeshLib::CElem *n_ele; - MeshLib::CNode *a_node; + MeshLib::CElem* n_ele; + MeshLib::CNode* a_node; - for(size_t j=0; jface_vector.size(); j++) + for (size_t j = 0; j < m_msh->face_vector.size(); j++) + { + n_ele = m_msh->face_vector[j]; + a_node = n_ele->GetNode(0); + p1[0] = a_node->X(); + p1[1] = a_node->Y(); + a_node = n_ele->GetNode(1); + p2[0] = a_node->X(); + p2[1] = a_node->Y(); + + xx = yy = ua = ub = 0.; + if (G_intersect_line_segments(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1], p4[0], p4[1], &ua, &ub, &xx, &yy) + == 1) { - n_ele = m_msh->face_vector[j]; - a_node = n_ele->GetNode(0); - p1[0] = a_node->X(); p1[1] = a_node->Y(); - a_node = n_ele->GetNode(1); - p2[0] = a_node->X(); p2[1] = a_node->Y(); - - xx = yy = ua = ub = 0.; - if(G_intersect_line_segments( p1[0], p1[1], p2[0], p2[1], p3[0], p3[1], p4[0], p4[1], - &ua, &ub, &xx, &yy)==1) + if (ua >= 0.0 && ua <= 1.0) { - if( ua>=0.0 && ua <= 1.0) - { - B->x = xx; - B->y = yy; - B->elementIndex = n_ele->GetOwner()->GetIndex(); - B->on_boundary = 1; - break; - } + B->x = xx; + B->y = yy; + B->elementIndex = n_ele->GetOwner()->GetIndex(); + B->on_boundary = 1; + break; } } } - } + } +} //------------------------------------------------------------------------------- /* Task: Check whether the particle is out of the domain and get the pierced point @@ -3395,183 +3312,185 @@ Programing: 11/2011 YS/WW */ void RandomWalk::CheckBoundary3D(Particle* A, Particle* B) { - //Only for tetrahedral and prismatic mesh for now - //firstly, check if the particle is inside of the domain + // Only for tetrahedral and prismatic mesh for now + // firstly, check if the particle is inside of the domain int eleindex = SearchElementFromNeighbor(B); - if( eleindex > -1) + if (eleindex > -1) + { + B->elementIndex = eleindex; + B->on_boundary = 0; + return; + } + + // The new position is in none of the elements, i.e., outside of the domain. + // Find the intersection point between the path line and the boundary. + // But check the old position first, in case it is already on the boundary. + + if (A->on_boundary) { - B->elementIndex = eleindex; - B->on_boundary = 0; - return; - } - - // The new position is in none of the elements, i.e., outside of the domain. - // Find the intersection point between the path line and the boundary. - // But check the old position first, in case it is already on the boundary. - - if ( A->on_boundary ) - { - // drag B back to the A position - B->x = A->x; B->y = A->y; B->z = A->z; - B->elementIndex = A->elementIndex; - B->on_boundary = A->on_boundary; - B->identity = A->identity; + // drag B back to the A position + B->x = A->x; + B->y = A->y; + B->z = A->z; + B->elementIndex = A->elementIndex; + B->on_boundary = A->on_boundary; + B->identity = A->identity; } else { - int kk, itr, ntr; - double x1[3], x2[3], x3[3], x4[3]; - MeshLib::CNode *a_node; - MeshLib::CElem *n_ele; - double us[3], vs[3], ws[3], bs[3]; - double f_buff; - bool s_cond; - - x4[0] = A->x; // point p on the path line - x4[1] = A->y; - x4[2] = A->z; - - double x_new[3]; - x_new[0] = B->x; // point q on the path line - x_new[1] = B->y; - x_new[2] = B->z; - - //search all the element facets which are on the boundary of the domain - for(int j=0; j<(long)m_msh->face_vector.size(); j++) - { - n_ele = m_msh->face_vector[j]; - - ntr = 1; - //if the element facet is quadrilateral, divide it into two triangles - if(n_ele->GetElementType() == MshElemType::QUAD) - ntr = 2; - - for(itr = 0; itrGetNode(0); // point r on the boundary plane - x1[0] = a_node->X(); - x1[1] = a_node->Y(); - x1[2] = a_node->Z(); - a_node = n_ele->GetNode(1); // point s on the boundary plane - x2[0] = a_node->X(); - x2[1] = a_node->Y(); - x2[2] = a_node->Z(); - a_node = n_ele->GetNode(2); // point t on the boundary plane - x3[0] = a_node->X(); - x3[1] = a_node->Y(); - x3[2] = a_node->Z(); - } - else - { - a_node = n_ele->GetNode(0); // point r on the boundary plane - x1[0] = a_node->X(); - x1[1] = a_node->Y(); - x1[2] = a_node->Z(); - a_node = n_ele->GetNode(2); // point s on the boundary plane - x2[0] = a_node->X(); - x2[1] = a_node->Y(); - x2[2] = a_node->Z(); - a_node = n_ele->GetNode(3); // point t on the boundary plane - x3[0] = a_node->X(); - x3[1] = a_node->Y(); - x3[2] = a_node->Z(); - } - - for(kk=0; kk<3; kk++) - { - us[kk] = x2[kk] - x1[kk]; //s-r - vs[kk] = x3[kk] - x1[kk]; //t-r - ws[kk] = x4[kk] - x_new[kk]; //p-q - bs[kk] = x4[kk] - x1[kk]; //p-r - } - - if(fabs(us[0])DBL_MIN) - { - SWAP(us[0], us[1]); - SWAP(vs[0], vs[1]); - SWAP(ws[0], ws[1]); - SWAP(bs[0], bs[1]); - } - else if(fabs(us[2])>DBL_MIN) - { - SWAP(us[0], us[2]); - SWAP(vs[0], vs[2]); - SWAP(ws[0], ws[2]); - SWAP(bs[0], bs[2]); - } - else - continue; - } - - // Solve the mini equation - f_buff = -us[1]/us[0]; - x1[0] = vs[1] + vs[0]*f_buff; //a11 - x1[1] = ws[1] + ws[0]*f_buff; //a12 - x1[2] = bs[1] + bs[0]*f_buff; //b1 - - f_buff = -us[2]/us[0]; - x2[0] = vs[2] + vs[0]*f_buff; //a21 - x2[1] = ws[2] + ws[0]*f_buff; //a22 - x2[2] = bs[2] + bs[0]*f_buff; //b2 - - f_buff = x1[0]*x2[1] - x1[1]*x2[0]; - - if(fabs(f_buff)1.0 ) - { - s_cond = false; - break; - } - } - if(!s_cond) - continue; - - if(x3[0]+x3[1]>1.0) - continue; - - // Assign the intersection point to B - // B_X = p + \lambda * (q -p) - B->x = x4[0] + x3[2] *(x_new[0] - x4[0]); - B->y = x4[1] + x3[2] *(x_new[1] - x4[1]); - B->z = x4[2] + x3[2] *(x_new[2] - x4[2]); - - B->elementIndex = n_ele->GetOwner()->GetIndex(); - B->on_boundary = 1; - break; - } - } - } - } + int kk, itr, ntr; + double x1[3], x2[3], x3[3], x4[3]; + MeshLib::CNode* a_node; + MeshLib::CElem* n_ele; + double us[3], vs[3], ws[3], bs[3]; + double f_buff; + bool s_cond; + + x4[0] = A->x; // point p on the path line + x4[1] = A->y; + x4[2] = A->z; + + double x_new[3]; + x_new[0] = B->x; // point q on the path line + x_new[1] = B->y; + x_new[2] = B->z; + + // search all the element facets which are on the boundary of the domain + for (int j = 0; j < (long)m_msh->face_vector.size(); j++) + { + n_ele = m_msh->face_vector[j]; + + ntr = 1; + // if the element facet is quadrilateral, divide it into two triangles + if (n_ele->GetElementType() == MshElemType::QUAD) + ntr = 2; + + for (itr = 0; itr < ntr; itr++) + { + if (itr == 0) + { + a_node = n_ele->GetNode(0); // point r on the boundary plane + x1[0] = a_node->X(); + x1[1] = a_node->Y(); + x1[2] = a_node->Z(); + a_node = n_ele->GetNode(1); // point s on the boundary plane + x2[0] = a_node->X(); + x2[1] = a_node->Y(); + x2[2] = a_node->Z(); + a_node = n_ele->GetNode(2); // point t on the boundary plane + x3[0] = a_node->X(); + x3[1] = a_node->Y(); + x3[2] = a_node->Z(); + } + else + { + a_node = n_ele->GetNode(0); // point r on the boundary plane + x1[0] = a_node->X(); + x1[1] = a_node->Y(); + x1[2] = a_node->Z(); + a_node = n_ele->GetNode(2); // point s on the boundary plane + x2[0] = a_node->X(); + x2[1] = a_node->Y(); + x2[2] = a_node->Z(); + a_node = n_ele->GetNode(3); // point t on the boundary plane + x3[0] = a_node->X(); + x3[1] = a_node->Y(); + x3[2] = a_node->Z(); + } + + for (kk = 0; kk < 3; kk++) + { + us[kk] = x2[kk] - x1[kk]; // s-r + vs[kk] = x3[kk] - x1[kk]; // t-r + ws[kk] = x4[kk] - x_new[kk]; // p-q + bs[kk] = x4[kk] - x1[kk]; // p-r + } + + if (fabs(us[0]) < DBL_MIN) + { + if (fabs(us[1]) > DBL_MIN) + { + SWAP(us[0], us[1]); + SWAP(vs[0], vs[1]); + SWAP(ws[0], ws[1]); + SWAP(bs[0], bs[1]); + } + else if (fabs(us[2]) > DBL_MIN) + { + SWAP(us[0], us[2]); + SWAP(vs[0], vs[2]); + SWAP(ws[0], ws[2]); + SWAP(bs[0], bs[2]); + } + else + continue; + } + + // Solve the mini equation + f_buff = -us[1] / us[0]; + x1[0] = vs[1] + vs[0] * f_buff; // a11 + x1[1] = ws[1] + ws[0] * f_buff; // a12 + x1[2] = bs[1] + bs[0] * f_buff; // b1 + + f_buff = -us[2] / us[0]; + x2[0] = vs[2] + vs[0] * f_buff; // a21 + x2[1] = ws[2] + ws[0] * f_buff; // a22 + x2[2] = bs[2] + bs[0] * f_buff; // b2 + + f_buff = x1[0] * x2[1] - x1[1] * x2[0]; + + if (fabs(f_buff) < DBL_MIN) + continue; + + if (fabs(x1[0]) < DBL_MIN) + { + // lambda + x3[2] = x1[2] / x1[1]; + // ita + x3[1] = (x2[2] - x2[1] * x3[2]) / x2[0]; + } + + else + { + // lambda + x3[2] = (x1[0] * x2[2] - x1[2] * x2[0]) / f_buff; + // ita + x3[1] = (x1[2] - x1[1] * x3[2]) / x1[0]; + } + + // mu + x3[0] = (bs[0] - vs[0] * x3[1] - ws[0] * x3[2]) / us[0]; + + // Whether 0<=lambda, ita, mu<=1 + s_cond = true; + for (kk = 0; kk < 3; kk++) + { + if (x3[kk] < 0.0 || x3[kk] > 1.0) + { + s_cond = false; + break; + } + } + if (!s_cond) + continue; + + if (x3[0] + x3[1] > 1.0) + continue; + + // Assign the intersection point to B + // B_X = p + \lambda * (q -p) + B->x = x4[0] + x3[2] * (x_new[0] - x4[0]); + B->y = x4[1] + x3[2] * (x_new[1] - x4[1]); + B->z = x4[2] + x3[2] * (x_new[2] - x4[2]); + + B->elementIndex = n_ele->GetOwner()->GetIndex(); + B->on_boundary = 1; + break; + } + } + } +} /************************************************************************** Task: Get the index of the element that contains the particle @@ -3581,88 +3500,88 @@ Programing: 03/2012 YS Implementation using namespace MeshLib; int RandomWalk::SearchElementFromNeighbor(Particle* A) { - int index; - double xyz[3]; - // Mount the proper mesh - m_msh = selectMeshForFluidMomentumProcess(); - CElem* theElement = m_msh->ele_vector[A->elementIndex]; + int index; + double xyz[3]; + // Mount the proper mesh + m_msh = selectMeshForFluidMomentumProcess(); + CElem* theElement = m_msh->ele_vector[A->elementIndex]; - // Let's check this element first. - index = CheckElementIndex(A); - if(index != -1) - return index; + // Let's check this element first. + index = CheckElementIndex(A); + if (index != -1) + return index; - // First neighbor's search around the main element - for(size_t i=0; iGetFacesNumber(); ++i) - { - CElem* theNeighbor = theElement->GetNeighbor(i); - - if(theNeighbor->GetDimension() == theElement->GetDimension()) - { - A->elementIndex = theNeighbor->GetIndex(); - - index = CheckElementIndex(A); - if(index != -1) - return index; - - // Second, search the neighbor's neighbor - for(size_t j=0; jGetFacesNumber(); ++j) - { - CElem* theNNeighbor = theNeighbor->GetNeighbor(j); - - if(theNNeighbor->GetDimension() == theNeighbor->GetDimension()) - { - A->elementIndex = theNNeighbor->GetIndex(); - - index = CheckElementIndex(A); - if(index != -1) - return index; - - // Third, search the neighbor's neighbor's neighbor - for(size_t k=0; k< theNNeighbor->GetFacesNumber(); ++k) - { - CElem* theNNNeighbor = theNNeighbor->GetNeighbor(k); - - if(theNNNeighbor->GetDimension() == theNNeighbor->GetDimension()) - { - A->elementIndex = theNNNeighbor->GetIndex(); - - index = CheckElementIndex(A); - if(index != -1) - return index; - - //Try one more time, the neighbor's neighbor's neighbor's neighbor - for(size_t l=0; l< theNNNeighbor->GetFacesNumber(); ++l) - { - CElem* theNNNNeighbor = theNNNeighbor->GetNeighbor(l); - - if(theNNNNeighbor->GetDimension() == theNNNeighbor->GetDimension()) - { - A->elementIndex = theNNNNeighbor->GetIndex(); - - index = CheckElementIndex(A); - if(index != -1) - return index; + // First neighbor's search around the main element + for (size_t i = 0; i < theElement->GetFacesNumber(); ++i) + { + CElem* theNeighbor = theElement->GetNeighbor(i); + + if (theNeighbor->GetDimension() == theElement->GetDimension()) + { + A->elementIndex = theNeighbor->GetIndex(); + + index = CheckElementIndex(A); + if (index != -1) + return index; + + // Second, search the neighbor's neighbor + for (size_t j = 0; j < theNeighbor->GetFacesNumber(); ++j) + { + CElem* theNNeighbor = theNeighbor->GetNeighbor(j); + + if (theNNeighbor->GetDimension() == theNeighbor->GetDimension()) + { + A->elementIndex = theNNeighbor->GetIndex(); + + index = CheckElementIndex(A); + if (index != -1) + return index; + + // Third, search the neighbor's neighbor's neighbor + for (size_t k = 0; k < theNNeighbor->GetFacesNumber(); ++k) + { + CElem* theNNNeighbor = theNNeighbor->GetNeighbor(k); + + if (theNNNeighbor->GetDimension() == theNNeighbor->GetDimension()) + { + A->elementIndex = theNNNeighbor->GetIndex(); + + index = CheckElementIndex(A); + if (index != -1) + return index; + + // Try one more time, the neighbor's neighbor's neighbor's neighbor + for (size_t l = 0; l < theNNNeighbor->GetFacesNumber(); ++l) + { + CElem* theNNNNeighbor = theNNNeighbor->GetNeighbor(l); + + if (theNNNNeighbor->GetDimension() == theNNNeighbor->GetDimension()) + { + A->elementIndex = theNNNNeighbor->GetIndex(); + + index = CheckElementIndex(A); + if (index != -1) + return index; + } + } } - } - } - } - } - } - } - } + } + } + } + } + } - // The particle is not in the neighboring elements. Have to search all. + // The particle is not in the neighboring elements. Have to search all. - xyz[0] = A->x; - xyz[1] = A->y; - xyz[2] = A->z; - index = m_msh->FindElementByPoint(xyz); - if(index != -1) - return index; + xyz[0] = A->x; + xyz[1] = A->y; + xyz[2] = A->z; + index = m_msh->FindElementByPoint(xyz); + if (index != -1) + return index; - // The particle is in none of the elements. - return -1; + // The particle is in none of the elements. + return -1; } //--------------------------------------------------------------------------- /* @@ -3672,212 +3591,218 @@ int RandomWalk::SearchElementFromNeighbor(Particle* A) */ int RandomWalk::CheckElementIndex(Particle* A) { - // Mount the proper mesh - m_msh = selectMeshForFluidMomentumProcess(); - - double xyz[3], x1[3], x2[3], x3[3], x4[3], x5[3], x6[3], x7[3], x8[3]; - double a, a_sub[12]; - CNode *a_node; - CElem *n_ele; - double tol = 1e-9; - - xyz[0] = A->x; - xyz[1] = A->y; - xyz[2] = A->z; - - n_ele = m_msh->ele_vector[A->elementIndex]; - a = n_ele->GetVolume(); - - a_node = n_ele->GetNode(0); - x1[0] = a_node->X(); - x1[1] = a_node->Y(); - x1[2] = a_node->Z(); - a_node = n_ele->GetNode(1); - x2[0] = a_node->X(); - x2[1] = a_node->Y(); - x2[2] = a_node->Z(); - if(n_ele->GetElementType()!=MshElemType::LINE ) - { - a_node = n_ele->GetNode(2); - x3[0] = a_node->X(); - x3[1] = a_node->Y(); - x3[2] = a_node->Z(); - } - - if(n_ele->GetElementType()==MshElemType::QUAD || n_ele->GetElementType()==MshElemType::TETRAHEDRON) - { - a_node = n_ele->GetNode(3); - x4[0] = a_node->X(); - x4[1] = a_node->Y(); - x4[2] = a_node->Z(); - } + // Mount the proper mesh + m_msh = selectMeshForFluidMomentumProcess(); - if(n_ele->GetElementType()==MshElemType::PYRAMID) - { - a_node = n_ele->GetNode(3); - x4[0] = a_node->X(); - x4[1] = a_node->Y(); - x4[2] = a_node->Z(); - a_node = n_ele->GetNode(4); - x5[0] = a_node->X(); - x5[1] = a_node->Y(); - x5[2] = a_node->Z(); - } + double xyz[3], x1[3], x2[3], x3[3], x4[3], x5[3], x6[3], x7[3], x8[3]; + double a, a_sub[12]; + CNode* a_node; + CElem* n_ele; + double tol = 1e-9; + + xyz[0] = A->x; + xyz[1] = A->y; + xyz[2] = A->z; + + n_ele = m_msh->ele_vector[A->elementIndex]; + a = n_ele->GetVolume(); + + a_node = n_ele->GetNode(0); + x1[0] = a_node->X(); + x1[1] = a_node->Y(); + x1[2] = a_node->Z(); + a_node = n_ele->GetNode(1); + x2[0] = a_node->X(); + x2[1] = a_node->Y(); + x2[2] = a_node->Z(); + if (n_ele->GetElementType() != MshElemType::LINE) + { + a_node = n_ele->GetNode(2); + x3[0] = a_node->X(); + x3[1] = a_node->Y(); + x3[2] = a_node->Z(); + } - if(n_ele->GetElementType()==MshElemType::PRISM) - { - a_node = n_ele->GetNode(3); - x4[0] = a_node->X(); - x4[1] = a_node->Y(); - x4[2] = a_node->Z(); - a_node = n_ele->GetNode(4); - x5[0] = a_node->X(); - x5[1] = a_node->Y(); - x5[2] = a_node->Z(); - a_node = n_ele->GetNode(5); - x6[0] = a_node->X(); - x6[1] = a_node->Y(); - x6[2] = a_node->Z(); - } + if (n_ele->GetElementType() == MshElemType::QUAD || n_ele->GetElementType() == MshElemType::TETRAHEDRON) + { + a_node = n_ele->GetNode(3); + x4[0] = a_node->X(); + x4[1] = a_node->Y(); + x4[2] = a_node->Z(); + } - if(n_ele->GetElementType()==MshElemType::HEXAHEDRON) - { - a_node = n_ele->GetNode(3); - x4[0] = a_node->X(); - x4[1] = a_node->Y(); - x4[2] = a_node->Z(); - a_node = n_ele->GetNode(4); - x5[0] = a_node->X(); - x5[1] = a_node->Y(); - x5[2] = a_node->Z(); - a_node = n_ele->GetNode(5); - x6[0] = a_node->X(); - x6[1] = a_node->Y(); - x6[2] = a_node->Z(); - a_node = n_ele->GetNode(6); - x7[0] = a_node->X(); - x7[1] = a_node->Y(); - x7[2] = a_node->Z(); - a_node = n_ele->GetNode(7); - x8[0] = a_node->X(); - x8[1] = a_node->Y(); - x8[2] = a_node->Z(); - } + if (n_ele->GetElementType() == MshElemType::PYRAMID) + { + a_node = n_ele->GetNode(3); + x4[0] = a_node->X(); + x4[1] = a_node->Y(); + x4[2] = a_node->Z(); + a_node = n_ele->GetNode(4); + x5[0] = a_node->X(); + x5[1] = a_node->Y(); + x5[2] = a_node->Z(); + } - switch(n_ele->GetElementType()) - { - case MshElemType::LINE: - double d1, d2, d3; - d1 = 0.; - d2 = 0.; - d3 = 0.; - for(int kk=0; kk<3; kk++) - { - d1 += (x1[kk] - xyz[kk]) * (x1[kk] - xyz[kk]); - d2 += (x2[kk] - xyz[kk]) * (x2[kk] - xyz[kk]); - d3 += (x1[kk] - x2[kk]) * (x1[kk] - x2[kk]); - } - d1 = sqrt(d1); - d2 = sqrt(d2); - d3 = sqrt(d3); - - if(fabs((d1+d2-d3)/d3)elementIndex; - } - break; - case MshElemType::TRIANGLE: - a_sub[0] = ComputeDetTri(x1, x2, xyz); - a_sub[1] = ComputeDetTri(x2, x3, xyz); - a_sub[2] = ComputeDetTri(x3, x1, xyz); - - if(fabs((a_sub[0]+a_sub[1]+a_sub[2]-a)/a)elementIndex; - } - break; - - case MshElemType::QUAD: - a_sub[0] = ComputeDetTri(x1, x2, xyz); - a_sub[1] = ComputeDetTri(x2, x3, xyz); - a_sub[2] = ComputeDetTri(x3, x4, xyz); - a_sub[3] = ComputeDetTri(x4, x1, xyz); - - if(fabs((a_sub[0]+a_sub[1]+a_sub[2]+a_sub[3]-a)/a)elementIndex; - } - break; - - case MshElemType::TETRAHEDRON: - a_sub[0] = ComputeDetTex(x2, x4, x3, xyz); - a_sub[1] = ComputeDetTex(x1, x3, x4, xyz); - a_sub[2] = ComputeDetTex(x2, x1, x4, xyz); - a_sub[3] = ComputeDetTex(x2, x3, x1, xyz); - - if(fabs((a_sub[0]+a_sub[1]+a_sub[2]+a_sub[3]-a)/a)elementIndex; - } - break; - - case MshElemType::PYRAMID: - a_sub[0] = ComputeDetTex(x1, x2, x4, xyz); - a_sub[1] = ComputeDetTex(x2, x3, x4, xyz); - a_sub[2] = ComputeDetTex(x1, x5, x2, xyz); - a_sub[3] = ComputeDetTex(x2, x5, x4, xyz); - a_sub[4] = ComputeDetTex(x3, x5, x4, xyz); - a_sub[5] = ComputeDetTex(x4, x5, x1, xyz); - - if(fabs((a_sub[0]+a_sub[1]+a_sub[2]+a_sub[3]+a_sub[4]+a_sub[5]-a)/a)elementIndex; - } - break; - - case MshElemType::PRISM: - a_sub[0] = ComputeDetTex(x1, x2, x3, xyz); - a_sub[1] = ComputeDetTex(x4, x6, x5, xyz); - a_sub[2] = ComputeDetTex(x1, x4, x2, xyz); - a_sub[3] = ComputeDetTex(x2, x4, x5, xyz); - a_sub[4] = ComputeDetTex(x2, x5, x3, xyz); - a_sub[5] = ComputeDetTex(x3, x5, x6, xyz); - a_sub[6] = ComputeDetTex(x3, x6, x1, xyz); - a_sub[7] = ComputeDetTex(x1, x6, x4, xyz); - - if(fabs((a_sub[0]+a_sub[1]+a_sub[2]+a_sub[3]+a_sub[4]+a_sub[5]+a_sub[6]+a_sub[7]-a)/a)elementIndex; - } - break; - - case MshElemType::HEXAHEDRON: - a_sub[0] = ComputeDetTex(x1, x2, x4, xyz); - a_sub[1] = ComputeDetTex(x4, x2, x3, xyz); - a_sub[2] = ComputeDetTex(x2, x6, x3, xyz); - a_sub[3] = ComputeDetTex(x3, x6, x7, xyz); - a_sub[4] = ComputeDetTex(x3, x7, x4, xyz); - a_sub[5] = ComputeDetTex(x4, x7, x8, xyz); - a_sub[6] = ComputeDetTex(x4, x8, x1, xyz); - a_sub[7] = ComputeDetTex(x1, x8, x5, xyz); - a_sub[8] = ComputeDetTex(x1, x5, x2, xyz); - a_sub[9] = ComputeDetTex(x2, x5, x6, xyz); - a_sub[10] = ComputeDetTex(x5, x8, x6, xyz); - a_sub[11] = ComputeDetTex(x6, x8, x7, xyz); - - if(fabs((a_sub[0]+a_sub[1]+a_sub[2]+a_sub[3]+a_sub[4]+a_sub[5]+a_sub[6]+a_sub[7]+a_sub[8] - +a_sub[9]+a_sub[10]+a_sub[11]-a)/a)elementIndex; - } - break; - - default: - // do nothing with other elements - break; - } - // the particle is not in this element - return -1; + if (n_ele->GetElementType() == MshElemType::PRISM) + { + a_node = n_ele->GetNode(3); + x4[0] = a_node->X(); + x4[1] = a_node->Y(); + x4[2] = a_node->Z(); + a_node = n_ele->GetNode(4); + x5[0] = a_node->X(); + x5[1] = a_node->Y(); + x5[2] = a_node->Z(); + a_node = n_ele->GetNode(5); + x6[0] = a_node->X(); + x6[1] = a_node->Y(); + x6[2] = a_node->Z(); + } + + if (n_ele->GetElementType() == MshElemType::HEXAHEDRON) + { + a_node = n_ele->GetNode(3); + x4[0] = a_node->X(); + x4[1] = a_node->Y(); + x4[2] = a_node->Z(); + a_node = n_ele->GetNode(4); + x5[0] = a_node->X(); + x5[1] = a_node->Y(); + x5[2] = a_node->Z(); + a_node = n_ele->GetNode(5); + x6[0] = a_node->X(); + x6[1] = a_node->Y(); + x6[2] = a_node->Z(); + a_node = n_ele->GetNode(6); + x7[0] = a_node->X(); + x7[1] = a_node->Y(); + x7[2] = a_node->Z(); + a_node = n_ele->GetNode(7); + x8[0] = a_node->X(); + x8[1] = a_node->Y(); + x8[2] = a_node->Z(); + } + + switch (n_ele->GetElementType()) + { + case MshElemType::LINE: + double d1, d2, d3; + d1 = 0.; + d2 = 0.; + d3 = 0.; + for (int kk = 0; kk < 3; kk++) + { + d1 += (x1[kk] - xyz[kk]) * (x1[kk] - xyz[kk]); + d2 += (x2[kk] - xyz[kk]) * (x2[kk] - xyz[kk]); + d3 += (x1[kk] - x2[kk]) * (x1[kk] - x2[kk]); + } + d1 = sqrt(d1); + d2 = sqrt(d2); + d3 = sqrt(d3); + + if (fabs((d1 + d2 - d3) / d3) < tol) + { + return A->elementIndex; + } + break; + case MshElemType::TRIANGLE: + a_sub[0] = ComputeDetTri(x1, x2, xyz); + a_sub[1] = ComputeDetTri(x2, x3, xyz); + a_sub[2] = ComputeDetTri(x3, x1, xyz); + + if (fabs((a_sub[0] + a_sub[1] + a_sub[2] - a) / a) < tol) + { + return A->elementIndex; + } + break; + + case MshElemType::QUAD: + a_sub[0] = ComputeDetTri(x1, x2, xyz); + a_sub[1] = ComputeDetTri(x2, x3, xyz); + a_sub[2] = ComputeDetTri(x3, x4, xyz); + a_sub[3] = ComputeDetTri(x4, x1, xyz); + + if (fabs((a_sub[0] + a_sub[1] + a_sub[2] + a_sub[3] - a) / a) < tol) + { + return A->elementIndex; + } + break; + + case MshElemType::TETRAHEDRON: + a_sub[0] = ComputeDetTex(x2, x4, x3, xyz); + a_sub[1] = ComputeDetTex(x1, x3, x4, xyz); + a_sub[2] = ComputeDetTex(x2, x1, x4, xyz); + a_sub[3] = ComputeDetTex(x2, x3, x1, xyz); + + if (fabs((a_sub[0] + a_sub[1] + a_sub[2] + a_sub[3] - a) / a) < tol) + { + return A->elementIndex; + } + break; + + case MshElemType::PYRAMID: + a_sub[0] = ComputeDetTex(x1, x2, x4, xyz); + a_sub[1] = ComputeDetTex(x2, x3, x4, xyz); + a_sub[2] = ComputeDetTex(x1, x5, x2, xyz); + a_sub[3] = ComputeDetTex(x2, x5, x4, xyz); + a_sub[4] = ComputeDetTex(x3, x5, x4, xyz); + a_sub[5] = ComputeDetTex(x4, x5, x1, xyz); + + if (fabs((a_sub[0] + a_sub[1] + a_sub[2] + a_sub[3] + a_sub[4] + a_sub[5] - a) / a) < tol) + { + return A->elementIndex; + } + break; + + case MshElemType::PRISM: + a_sub[0] = ComputeDetTex(x1, x2, x3, xyz); + a_sub[1] = ComputeDetTex(x4, x6, x5, xyz); + a_sub[2] = ComputeDetTex(x1, x4, x2, xyz); + a_sub[3] = ComputeDetTex(x2, x4, x5, xyz); + a_sub[4] = ComputeDetTex(x2, x5, x3, xyz); + a_sub[5] = ComputeDetTex(x3, x5, x6, xyz); + a_sub[6] = ComputeDetTex(x3, x6, x1, xyz); + a_sub[7] = ComputeDetTex(x1, x6, x4, xyz); + + if (fabs((a_sub[0] + a_sub[1] + a_sub[2] + a_sub[3] + a_sub[4] + a_sub[5] + a_sub[6] + a_sub[7] - a) / a) + < tol) + { + return A->elementIndex; + } + break; + + case MshElemType::HEXAHEDRON: + a_sub[0] = ComputeDetTex(x1, x2, x4, xyz); + a_sub[1] = ComputeDetTex(x4, x2, x3, xyz); + a_sub[2] = ComputeDetTex(x2, x6, x3, xyz); + a_sub[3] = ComputeDetTex(x3, x6, x7, xyz); + a_sub[4] = ComputeDetTex(x3, x7, x4, xyz); + a_sub[5] = ComputeDetTex(x4, x7, x8, xyz); + a_sub[6] = ComputeDetTex(x4, x8, x1, xyz); + a_sub[7] = ComputeDetTex(x1, x8, x5, xyz); + a_sub[8] = ComputeDetTex(x1, x5, x2, xyz); + a_sub[9] = ComputeDetTex(x2, x5, x6, xyz); + a_sub[10] = ComputeDetTex(x5, x8, x6, xyz); + a_sub[11] = ComputeDetTex(x6, x8, x7, xyz); + + if (fabs((a_sub[0] + a_sub[1] + a_sub[2] + a_sub[3] + a_sub[4] + a_sub[5] + a_sub[6] + a_sub[7] + a_sub[8] + + a_sub[9] + + a_sub[10] + + a_sub[11] + - a) + / a) + < tol) + { + return A->elementIndex; + } + break; + + default: + // do nothing with other elements + break; + } + // the particle is not in this element + return -1; } /************************************************************************** @@ -3914,7 +3839,8 @@ int RandomWalk::SolveForNextPosition(Particle* A, Particle* B) // TF - to avoid an abort while processing line elements // Is the handling for the mesh element type LINE not correct implemented? - if (theElement->GetElementType() == MshElemType::LINE) { + if (theElement->GetElementType() == MshElemType::LINE) + { nEdges = 0; } @@ -3930,12 +3856,12 @@ int RandomWalk::SolveForNextPosition(Particle* A, Particle* B) // Initialize some variables. double dtt = 0.0, dt1 = 0.0, dt2 = 0.0, d1 = 0.0, d = 0.0; double tolerance = 1e-6; - double timeSplit = 100; // Important: This timeSplit is a bit sensitive. + double timeSplit = 100; // Important: This timeSplit is a bit sensitive. - if(ele_dim < 3) + if (ele_dim < 3) { // Loop over the edges - for(int i = 0; i < nEdges; ++i) + for (int i = 0; i < nEdges; ++i) { // Get the edges of the element vec theEdges(nEdges); @@ -3948,17 +3874,13 @@ int RandomWalk::SolveForNextPosition(Particle* A, Particle* B) double p1[3], p2[3], p3[3], p4[3]; // RWPT - IM // Two points in the edge - double X1[3] = - {theNodes[0]->getData()[0], theNodes[0]->getData()[1], - theNodes[0]->getData()[2]}; - double X2[3] = - {theNodes[1]->getData()[0], theNodes[1]->getData()[1], - theNodes[1]->getData()[2]}; -// X1[0] = theNodes[0]->X(); X1[1] = theNodes[0]->Y(); X1[2] = theNodes[0]->Z(); -// X2[0] = theNodes[1]->X(); X2[1] = theNodes[1]->Y(); X2[2] = theNodes[1]->Z(); + double X1[3] = {theNodes[0]->getData()[0], theNodes[0]->getData()[1], theNodes[0]->getData()[2]}; + double X2[3] = {theNodes[1]->getData()[0], theNodes[1]->getData()[1], theNodes[1]->getData()[2]}; + // X1[0] = theNodes[0]->X(); X1[1] = theNodes[0]->Y(); X1[2] = theNodes[0]->Z(); + // X2[0] = theNodes[1]->X(); X2[1] = theNodes[1]->Y(); X2[2] = theNodes[1]->Z(); ToTheXYPlane(theElement, X1); ToTheXYPlane(theElement, X2); - for(int j = 0; j < 3; ++j) + for (int j = 0; j < 3; ++j) { p1[j] = X1[j]; p2[j] = X2[j]; @@ -3973,7 +3895,7 @@ int RandomWalk::SolveForNextPosition(Particle* A, Particle* B) int dDStatus = 1; // If the mode is for heterogeneous media - if(RWPTMode % 2 == 1) + if (RWPTMode % 2 == 1) // This currently only return TRUE (1) dDStatus = SolveForDisplacementByDerivativeOfDispersion(A, dD); @@ -3981,15 +3903,16 @@ int RandomWalk::SolveForNextPosition(Particle* A, Particle* B) double V[3]; // Create random drift according to the element dimension - if(RWPTMode < 2 || RWPTMode > 3) // whenever dispersion is on + if (RWPTMode < 2 || RWPTMode > 3) // whenever dispersion is on RandomWalkDrift(Z, ele_dim); - if(dDStatus == 1) + if (dDStatus == 1) { - if(ele_dim == 2) + if (ele_dim == 2) { // RWPT - IM // This should be done carefully. Velocity should be transformed to be on the XY plane. - // dD[] should be fine because it is handled in the SolveForDisplacementByDerivativeOfDispersion function. + // dD[] should be fine because it is handled in the SolveForDisplacementByDerivativeOfDispersion + // function. // Z[] should also be fine. Just randome nubmers. // D[] Yes, this should be fine too. It is handled in the SolveDispersionCoefficient function. // OK. Just velocity left. @@ -4023,21 +3946,11 @@ int RandomWalk::SolveForNextPosition(Particle* A, Particle* B) dtt = B->t; double x = 0.0, y = 0.0, ra = 0.0, rb = 0.0; - int status = G_intersect_line_segments( p1[0], - p1[1], - p2[0], - p2[1], - p3[0], - p3[1], - p4[0], - p4[1], - &ra, - &rb, - &x, - &y); + int status + = G_intersect_line_segments(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1], p4[0], p4[1], &ra, &rb, &x, &y); // If intersection is a sinle point - if(status == 1) + if (status == 1) { // Compute the time left over. double I[3]; @@ -4051,7 +3964,7 @@ int RandomWalk::SolveForNextPosition(Particle* A, Particle* B) dt2 = dtt - dt1; // dt2 should be positive - if(dt2 < 0.0) + if (dt2 < 0.0) /* printf("The program aborts because dt2 < 0.0\n"); abort(); @@ -4062,7 +3975,7 @@ int RandomWalk::SolveForNextPosition(Particle* A, Particle* B) { double dsp[3]; dsp[0] = dsp[1] = dsp[2] = 0.0; - if(d1 > tolerance) + if (d1 > tolerance) { // Update the record. B->t = dt2; @@ -4082,7 +3995,7 @@ int RandomWalk::SolveForNextPosition(Particle* A, Particle* B) B->x = IC[0]; B->y = IC[1]; B->z = IC[2]; - CheckBoundary2D(A,B); + CheckBoundary2D(A, B); return 1; // The element index switched to the neighbor element } else // It finds the wrong intersection. @@ -4102,20 +4015,20 @@ int RandomWalk::SolveForNextPosition(Particle* A, Particle* B) B->x = IC[0]; B->y = IC[1]; B->z = IC[2]; - CheckBoundary2D(A,B); + CheckBoundary2D(A, B); return 1; } } } // It couldn't reach to the edge - else if(status == 0) + else if (status == 0) ++countNoIntersection; // If two segments are parallel - else if(status == -1) + else if (status == -1) ++countNoIntersection; // keep going. // If two segments are colinear - else if(status == 2) + else if (status == 2) { printf("The program aborts because two segments are colinear.\n"); ++countNoIntersection; @@ -4123,15 +4036,14 @@ int RandomWalk::SolveForNextPosition(Particle* A, Particle* B) } else { - printf( - "The program aborts because status of intersection search is not 1 or 0 or -1.\n"); + printf("The program aborts because status of intersection search is not 1 or 0 or -1.\n"); abort(); } } // Check if the time left advances the particle within this element - if(countNoIntersection == nEdges) + if (countNoIntersection == nEdges) { - if(ele_dim == 2) + if (ele_dim == 2) { double V[3]; // In fact, V[2] gotta be zero. @@ -4156,10 +4068,12 @@ int RandomWalk::SolveForNextPosition(Particle* A, Particle* B) P[1] += dsp[1]; P[2] = theElement->GetAngle(2); ToTheRealPlane(B->elementIndex, P); - B->x = P[0]; B->y = P[1]; B->z = P[2]; - CheckBoundary2D(A,B); + B->x = P[0]; + B->y = P[1]; + B->z = P[2]; + CheckBoundary2D(A, B); } - else if(ele_dim == 1) + else if (ele_dim == 1) { // Create random numbers according to dimension RandomWalkDrift(Z, ele_dim); @@ -4175,7 +4089,7 @@ int RandomWalk::SolveForNextPosition(Particle* A, Particle* B) B->y += dsp[1]; B->z += dsp[2]; - //OK411 double dt = B->t; + // OK411 double dt = B->t; } else { @@ -4184,27 +4098,29 @@ int RandomWalk::SolveForNextPosition(Particle* A, Particle* B) } B->t = 0.0; - return 0; // Particle stays in the same element. + return 0; // Particle stays in the same element. } else - return -2; // The function failed + return -2; // The function failed } - else // For 3D elements + else // For 3D elements { // Currently 3D elements only work for dispersion in Homogeneous. - //WW int dDStatus = 1; + // WW int dDStatus = 1; // If the mode is for heterogeneous media - if(RWPTMode % 2 == 1) + if (RWPTMode % 2 == 1) // This currently only return TRUE (1) - //WW dDStatus = SolveForDisplacementByDerivativeOfDispersion(A, dD); + // WW dDStatus = SolveForDisplacementByDerivativeOfDispersion(A, dD); SolveForDisplacementByDerivativeOfDispersion(A, dD); // Let's get the local vector for particle velocity double V[3]; - V[0] = B->Vx; V[1] = B->Vy; V[2] = B->Vz; + V[0] = B->Vx; + V[1] = B->Vy; + V[2] = B->Vz; // Create random drift according to the element dimension - if(RWPTMode < 2 || RWPTMode > 3) // whenever dispersion is on + if (RWPTMode < 2 || RWPTMode > 3) // whenever dispersion is on { RandomWalkDrift(Z, ele_dim); double dsp[3]; @@ -4216,8 +4132,8 @@ int RandomWalk::SolveForNextPosition(Particle* A, Particle* B) // Initialize the values for getting the intersection B->t = 0.0; - CheckBoundary3D(A, B); - return 1; + CheckBoundary3D(A, B); + return 1; } return -2; } @@ -4228,12 +4144,7 @@ int RandomWalk::SolveForNextPosition(Particle* A, Particle* B) Programing: 03/2006 PCH Implementation **************************************************************************/ -void RandomWalk::GetDisplacement(Particle* B, - double* Z, - double* V, - double* dD, - double time, - double* dsp) +void RandomWalk::GetDisplacement(Particle* B, double* Z, double* V, double* dD, double time, double* dsp) { // Mount the proper mesh m_msh = selectMeshForFluidMomentumProcess(); @@ -4251,15 +4162,14 @@ void RandomWalk::GetDisplacement(Particle* B, // } MeshLib::CElem* theElement = m_msh->ele_vector[B->elementIndex]; int ele_dim = theElement->GetDimension(); - double Dxx = 0.0, Dxy = 0.0, Dxz = 0.0, Dyx = 0.0, Dyy = 0.0, Dyz = 0.0, Dzx = 0.0, Dzy = - 0.0, Dzz = 0.0; + double Dxx = 0.0, Dxy = 0.0, Dxz = 0.0, Dyx = 0.0, Dyy = 0.0, Dyz = 0.0, Dzx = 0.0, Dzy = 0.0, Dzz = 0.0; - if(ele_dim == 2) // If 2D, + if (ele_dim == 2) // If 2D, { // If the mode is for heterogeneous media - if(RWPTMode % 2 == 1) + if (RWPTMode % 2 == 1) { - if(RWPTMode < 2 || RWPTMode > 3) // whenever dispersion is on + if (RWPTMode < 2 || RWPTMode > 3) // whenever dispersion is on { Dxx = sqrt(6.0 * B->D[0] * time) * Z[0]; Dxy = sqrt(6.0 * fabs(B->D[1]) * time) * Z[1]; @@ -4269,16 +4179,16 @@ void RandomWalk::GetDisplacement(Particle* B, dsp[0] = V[0] * time + dD[0] * time + Dxx + Dxy; dsp[1] = V[1] * time + dD[1] * time + Dyx + Dyy; } - else // advection only + else // advection only { // Do nothing for dipsersive transport. dsp[0] = V[0] * time + dD[0] * time; dsp[1] = V[1] * time + dD[1] * time; } } - else // Homogeneous case + else // Homogeneous case { - if(RWPTMode < 2 || RWPTMode > 3) // whenever dispersion is on + if (RWPTMode < 2 || RWPTMode > 3) // whenever dispersion is on { // Homo and hetero in this case are the same. Dxx = sqrt(6.0 * B->D[0] * time) * Z[0]; @@ -4289,7 +4199,7 @@ void RandomWalk::GetDisplacement(Particle* B, dsp[0] = V[0] * time + Dxx + Dxy; dsp[1] = V[1] * time + Dyx + Dyy; } - else // advection only + else // advection only { dsp[0] = V[0] * time; dsp[1] = V[1] * time; @@ -4298,65 +4208,65 @@ void RandomWalk::GetDisplacement(Particle* B, // Fix for translation dsp[2] = theElement->GetAngle(2); } - else if(ele_dim == 1) // If 1D, + else if (ele_dim == 1) // If 1D, { double VV = 0.0, DD = 0.0, Dsp = 0.0; int coordinateflag = m_msh->GetCoordinateFlag(); - if(coordinateflag == 10) // x only + if (coordinateflag == 10) // x only { VV = V[0]; DD = sqrt(6.0 * B->D[0] * time) * Z[0]; } - else if(coordinateflag == 11) // y only + else if (coordinateflag == 11) // y only { VV = V[1]; DD = sqrt(6.0 * B->D[4] * time) * Z[0]; } - else if(coordinateflag == 12) // z only + else if (coordinateflag == 12) // z only { VV = V[2]; DD = sqrt(6.0 * B->D[8] * time) * Z[0]; } - else // Something Wrong. + else // Something Wrong. abort(); // If the mode is for heterogeneous media - if(RWPTMode % 2 == 1) + if (RWPTMode % 2 == 1) { - if(RWPTMode < 2 || RWPTMode > 3) // whenever dispersion is on + if (RWPTMode < 2 || RWPTMode > 3) // whenever dispersion is on Dsp = VV * time + dD[0] * time + DD; - else // advection only + else // advection only // Do nothing for dipsersive transport. Dsp = VV * time + dD[0] * time; } - else // Homogeneous case + else // Homogeneous case { - if(RWPTMode < 2 || RWPTMode > 3) // whenever dispersion is on + if (RWPTMode < 2 || RWPTMode > 3) // whenever dispersion is on // Homo and hetero in this case are the same. Dsp = VV * time + DD; - else // advection only + else // advection only Dsp = VV * time; } - if(coordinateflag == 10) // x only + if (coordinateflag == 10) // x only dsp[0] = Dsp; - else if(coordinateflag == 11) // y only + else if (coordinateflag == 11) // y only dsp[1] = Dsp; - else if(coordinateflag == 12) // z only + else if (coordinateflag == 12) // z only dsp[2] = Dsp; - else // Something Wrong. + else // Something Wrong. abort(); } - else // 3D elements + else // 3D elements { // If the mode is for heterogeneous media - if(RWPTMode % 2 == 1) + if (RWPTMode % 2 == 1) { - if(RWPTMode < 2 || RWPTMode > 3) // whenever dispersion is on + if (RWPTMode < 2 || RWPTMode > 3) // whenever dispersion is on { Dxx = sqrt(6.0 * B->D[0] * time) * Z[0]; Dxy = sqrt(6.0 * fabs(B->D[1]) * time) * Z[1]; @@ -4372,7 +4282,7 @@ void RandomWalk::GetDisplacement(Particle* B, dsp[1] = V[1] * time + dD[1] * time + Dyx + Dyy + Dxz; dsp[2] = V[2] * time + dD[2] * time + Dzx + Dzy + Dzz; } - else // advection only + else // advection only { // Do nothing for dipsersive transport. dsp[0] = V[0] * time + dD[0] * time; @@ -4380,9 +4290,9 @@ void RandomWalk::GetDisplacement(Particle* B, dsp[2] = V[2] * time + dD[2] * time; } } - else // Homogeneous case + else // Homogeneous case { - if(RWPTMode < 2 || RWPTMode > 3) // whenever dispersion is on + if (RWPTMode < 2 || RWPTMode > 3) // whenever dispersion is on { // Homo and hetero in this case are the same. Dxx = sqrt(6.0 * B->D[0] * time) * Z[0]; @@ -4399,7 +4309,7 @@ void RandomWalk::GetDisplacement(Particle* B, dsp[1] = V[1] * time + Dyx + Dyy + Dyz; dsp[2] = V[2] * time + Dzx + Dzy + Dzz; } - else // advection only + else // advection only { dsp[0] = V[0] * time; dsp[1] = V[1] * time; @@ -4422,112 +4332,100 @@ int RandomWalk::GetTheElementOfTheParticle(Particle* Pold, Particle* Pnew) // Mount the proper mesh m_msh = selectMeshForFluidMomentumProcess(); - // for(int i=0; i< (int)pcs_vector.size(); ++i) - // { - // m_pcs = pcs_vector[i]; - // - // // Select the mesh whose process name has the mesh for Fluid_Momentum - // if( m_pcs->pcs_type_name.find("RICHARDS_FLOW")!=string::npos) - // m_msh = FEMGet("RICHARDS_FLOW"); - // else if( m_pcs->pcs_type_name.find("LIQUID_FLOW")!=string::npos) - // m_msh = FEMGet("LIQUID_FLOW"); - // else if( m_pcs->pcs_type_name.find("GROUNDWATER_FLOW")!=string::npos) - // m_msh = FEMGet("GROUNDWATER_FLOW"); - // } +// for(int i=0; i< (int)pcs_vector.size(); ++i) +// { +// m_pcs = pcs_vector[i]; +// +// // Select the mesh whose process name has the mesh for Fluid_Momentum +// if( m_pcs->pcs_type_name.find("RICHARDS_FLOW")!=string::npos) +// m_msh = FEMGet("RICHARDS_FLOW"); +// else if( m_pcs->pcs_type_name.find("LIQUID_FLOW")!=string::npos) +// m_msh = FEMGet("LIQUID_FLOW"); +// else if( m_pcs->pcs_type_name.find("GROUNDWATER_FLOW")!=string::npos) +// m_msh = FEMGet("GROUNDWATER_FLOW"); +// } #ifdef ALLOW_PARTICLES_GO_OUTSIDE - if(Pold->elementIndex != -10) + if (Pold->elementIndex != -10) { #endif - MeshLib::CElem* theElement = m_msh->ele_vector[Pold->elementIndex]; - // Let's check this element first. - index = IsTheParticleInThisElement(Pold); - if(index != -1) - return index; + MeshLib::CElem* theElement = m_msh->ele_vector[Pold->elementIndex]; + // Let's check this element first. + index = IsTheParticleInThisElement(Pold); + if (index != -1) + return index; - // First find the edge of the previous element - // Mount the edges of the element - int nnode = theElement->GetEdgesNumber(); - vectheEdgesOfThisElement(nnode); - theElement->GetEdges(theEdgesOfThisElement); - // Mount the nodes of the edge - vectheNodesOfThisEdge(3); + // First find the edge of the previous element + // Mount the edges of the element + int nnode = theElement->GetEdgesNumber(); + vec theEdgesOfThisElement(nnode); + theElement->GetEdges(theEdgesOfThisElement); + // Mount the nodes of the edge + vec theNodesOfThisEdge(3); - for(int i = 0; i < nnode; ++i) - { - // Get the nodes of the edge - theEdgesOfThisElement[i]->GetNodes(theNodesOfThisEdge); + for (int i = 0; i < nnode; ++i) + { + // Get the nodes of the edge + theEdgesOfThisElement[i]->GetNodes(theNodesOfThisEdge); - double p1[3], p2[3], p3[3], p4[3]; - // RWPT - IM - // Two points in the edge - double X1[3] = - {theNodesOfThisEdge[0]->getData()[0], theNodesOfThisEdge[0]->getData()[1], - theNodesOfThisEdge[0]->getData()[2]}; - double X2[3] = - {theNodesOfThisEdge[1]->getData()[0], theNodesOfThisEdge[1]->getData()[1], - theNodesOfThisEdge[1]->getData()[2]}; + double p1[3], p2[3], p3[3], p4[3]; + // RWPT - IM + // Two points in the edge + double X1[3] = {theNodesOfThisEdge[0]->getData()[0], theNodesOfThisEdge[0]->getData()[1], + theNodesOfThisEdge[0]->getData()[2]}; + double X2[3] = {theNodesOfThisEdge[1]->getData()[0], theNodesOfThisEdge[1]->getData()[1], + theNodesOfThisEdge[1]->getData()[2]}; // double X1[3], X2[3]; // X1[0] = theNodesOfThisEdge[0]->X(); X1[1] = theNodesOfThisEdge[0]->Y(); X1[2] = theNodesOfThisEdge[0]->Z(); // X2[0] = theNodesOfThisEdge[1]->X(); X2[1] = theNodesOfThisEdge[1]->Y(); X2[2] = theNodesOfThisEdge[1]->Z(); #ifdef TWODINTHREED - ToTheXYPlane(theElement, X1); - ToTheXYPlane(theElement, X2); + ToTheXYPlane(theElement, X1); + ToTheXYPlane(theElement, X2); #endif - for(int j = 0; j < 3; ++j) - { - p1[j] = X1[j]; - p2[j] = X2[j]; - } + for (int j = 0; j < 3; ++j) + { + p1[j] = X1[j]; + p2[j] = X2[j]; + } - // The starting point which is the previous position - p3[0] = Pold->x; - p3[1] = Pold->y; - p3[2] = Pold->z; + // The starting point which is the previous position + p3[0] = Pold->x; + p3[1] = Pold->y; + p3[2] = Pold->z; #ifdef TWODINTHREED - // RWPT - IM - ToTheXYPlane(theElement, p3); + // RWPT - IM + ToTheXYPlane(theElement, p3); #endif - // The ending point which is the current position - p4[0] = Pnew->x; - p4[1] = Pnew->y; - p4[2] = Pnew->z; - - double x = 0.0, y = 0.0, ra = 0.0, rb = 0.0; - - int status = G_intersect_line_segments( p1[0], - p1[1], - p2[0], - p2[1], - p3[0], - p3[1], - p4[0], - p4[1], - &ra, - &rb, - &x, - &y); - - if(status == 0) // Not intersect but extension intersects - ; - else if(status == -1) // Parallel - ; - else if(status == 1) // single intersection - Means the current position is outside of this element - - // Do further implementation here. - index = theEdgesOfThisElement[i]->connected_elements[1]; - else if(status == 2) // Overlap just do nothing - index = Pold->elementIndex; // This should indicate the particle in this element, then. - else - { - printf("Not making any sense.\n"); - abort(); + // The ending point which is the current position + p4[0] = Pnew->x; + p4[1] = Pnew->y; + p4[2] = Pnew->z; + + double x = 0.0, y = 0.0, ra = 0.0, rb = 0.0; + + int status + = G_intersect_line_segments(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1], p4[0], p4[1], &ra, &rb, &x, &y); + + if (status == 0) // Not intersect but extension intersects + ; + else if (status == -1) // Parallel + ; + else if (status == 1) // single intersection - Means the current position is outside of this element + + // Do further implementation here. + index = theEdgesOfThisElement[i]->connected_elements[1]; + else if (status == 2) // Overlap just do nothing + index = Pold->elementIndex; // This should indicate the particle in this element, then. + else + { + printf("Not making any sense.\n"); + abort(); + } } - } #ifdef ALLOW_PARTICLES_GO_OUTSIDE -} + } #endif return index; @@ -4546,110 +4444,105 @@ int RandomWalk::GetTheElementOfTheParticleFromNeighbor(Particle* A) // Mount the proper mesh m_msh = selectMeshForFluidMomentumProcess(); - // for(int i=0; i< (int)pcs_vector.size(); ++i) - // { - // m_pcs = pcs_vector[i]; - // - // // Select the mesh whose process name has the mesh for Fluid_Momentum - // if( m_pcs->pcs_type_name.find("RICHARDS_FLOW")!=string::npos) - // m_msh = FEMGet("RICHARDS_FLOW"); - // else if( m_pcs->pcs_type_name.find("LIQUID_FLOW")!=string::npos) - // m_msh = FEMGet("LIQUID_FLOW"); - // else if( m_pcs->pcs_type_name.find("GROUNDWATER_FLOW")!=string::npos) - // m_msh = FEMGet("GROUNDWATER_FLOW"); - // } +// for(int i=0; i< (int)pcs_vector.size(); ++i) +// { +// m_pcs = pcs_vector[i]; +// +// // Select the mesh whose process name has the mesh for Fluid_Momentum +// if( m_pcs->pcs_type_name.find("RICHARDS_FLOW")!=string::npos) +// m_msh = FEMGet("RICHARDS_FLOW"); +// else if( m_pcs->pcs_type_name.find("LIQUID_FLOW")!=string::npos) +// m_msh = FEMGet("LIQUID_FLOW"); +// else if( m_pcs->pcs_type_name.find("GROUNDWATER_FLOW")!=string::npos) +// m_msh = FEMGet("GROUNDWATER_FLOW"); +// } #ifdef ALLOW_PARTICLES_GO_OUTSIDE - if(A->elementIndex != -10) + if (A->elementIndex != -10) { #endif - MeshLib::CElem* theElement = m_msh->ele_vector[A->elementIndex]; - // Let's check this element first. - index = IsTheParticleInThisElement(A); - if(index != -1) - { - A->elementIndex = index; - return index; - } - - // First meighbor's search around the main element - for(size_t i = 0; i < theElement->GetFacesNumber(); ++i) - { - MeshLib::CElem* thisNeighbor = theElement->GetNeighbor(i); + MeshLib::CElem* theElement = m_msh->ele_vector[A->elementIndex]; + // Let's check this element first. + index = IsTheParticleInThisElement(A); + if (index != -1) + { + A->elementIndex = index; + return index; + } - // If element type has more dimension than line. - if(thisNeighbor->GetElementType() != MshElemType::LINE) + // First meighbor's search around the main element + for (size_t i = 0; i < theElement->GetFacesNumber(); ++i) { - // If the particle belongs to this element - A->elementIndex = thisNeighbor->GetIndex(); - index = IsTheParticleInThisElement(A); - if(index != -1) - return index; + MeshLib::CElem* thisNeighbor = theElement->GetNeighbor(i); - // Second, search the neighbor's neighbor - for(size_t j = 0; j < thisNeighbor->GetFacesNumber(); ++j) + // If element type has more dimension than line. + if (thisNeighbor->GetElementType() != MshElemType::LINE) { - MeshLib::CElem* theNeighborsNeighbor = thisNeighbor->GetNeighbor(j); - - if(theNeighborsNeighbor->GetElementType() != MshElemType::LINE) + // If the particle belongs to this element + A->elementIndex = thisNeighbor->GetIndex(); + index = IsTheParticleInThisElement(A); + if (index != -1) + return index; + + // Second, search the neighbor's neighbor + for (size_t j = 0; j < thisNeighbor->GetFacesNumber(); ++j) { - // If the particle belongs to this element - A->elementIndex = theNeighborsNeighbor->GetIndex(); - index = IsTheParticleInThisElement(A); - if(index != -1) - return index; + MeshLib::CElem* theNeighborsNeighbor = thisNeighbor->GetNeighbor(j); - // Third, search the neighbor's neighbor's neighbor - for(size_t k = 0; k < theNeighborsNeighbor->GetFacesNumber(); - ++k) + if (theNeighborsNeighbor->GetElementType() != MshElemType::LINE) { - MeshLib::CElem* theNeighborsNeighborsNeighbor = - theNeighborsNeighbor->GetNeighbor(k); - - if(theNeighborsNeighborsNeighbor->GetElementType() - != MshElemType::LINE) + // If the particle belongs to this element + A->elementIndex = theNeighborsNeighbor->GetIndex(); + index = IsTheParticleInThisElement(A); + if (index != -1) + return index; + + // Third, search the neighbor's neighbor's neighbor + for (size_t k = 0; k < theNeighborsNeighbor->GetFacesNumber(); ++k) { - // If the particle belongs to this element - A->elementIndex = - theNeighborsNeighborsNeighbor-> - GetIndex(); - index = IsTheParticleInThisElement(A); - if(index != -1) - return index; + MeshLib::CElem* theNeighborsNeighborsNeighbor = theNeighborsNeighbor->GetNeighbor(k); + + if (theNeighborsNeighborsNeighbor->GetElementType() != MshElemType::LINE) + { + // If the particle belongs to this element + A->elementIndex = theNeighborsNeighborsNeighbor->GetIndex(); + index = IsTheParticleInThisElement(A); + if (index != -1) + return index; + } } } } } } - } - // If the code pases the following loop, it means I am not lucky in this neighbor search. - int numberOfElements = (int)m_msh->ele_vector.size(); - for(int i = 0; i < numberOfElements; ++i) - { - MeshLib::CElem* thisElement = m_msh->ele_vector[i]; - - if(thisElement->GetElementType() != MshElemType::LINE) + // If the code pases the following loop, it means I am not lucky in this neighbor search. + int numberOfElements = (int)m_msh->ele_vector.size(); + for (int i = 0; i < numberOfElements; ++i) { - // If the particle belongs to this element - A->elementIndex = thisElement->GetIndex(); - index = IsTheParticleInThisElement(A); - if(index != -1) - return index; + MeshLib::CElem* thisElement = m_msh->ele_vector[i]; + + if (thisElement->GetElementType() != MshElemType::LINE) + { + // If the particle belongs to this element + A->elementIndex = thisElement->GetIndex(); + index = IsTheParticleInThisElement(A); + if (index != -1) + return index; + } } - } - // The search failed - if(index == -1) - { - index = -10; - printf("Searching the index from the neighbor failed\n"); - printf("The particle should be outside of the domain.\n"); - } + // The search failed + if (index == -1) + { + index = -10; + printf("Searching the index from the neighbor failed\n"); + printf("The particle should be outside of the domain.\n"); + } #ifdef ALLOW_PARTICLES_GO_OUTSIDE -} + } #endif return index; } @@ -4684,14 +4577,14 @@ int RandomWalk::IsTheParticleInThisElement(Particle* A) int ele_dim = theElement->GetDimension(); - if(ele_dim == 2) + if (ele_dim == 2) { // Getting the number of the edges in the element that Particle P belongs int nEdges = theElement->GetEdgesNumber(); int countOfInterception = 0; - //WW int parallel = 0; + // WW int parallel = 0; // Loop over the edges - for(int i = 0; i < nEdges; ++i) + for (int i = 0; i < nEdges; ++i) { // Get the edges of the element vec theEdges(nEdges); @@ -4705,19 +4598,15 @@ int RandomWalk::IsTheParticleInThisElement(Particle* A) // RWPT - IM // Two points in the edge - double X1[3] = - {theNodes[0]->getData()[0], theNodes[0]->getData()[1], - theNodes[0]->getData()[2]}; - double X2[3] = - {theNodes[1]->getData()[0], theNodes[1]->getData()[1], - theNodes[1]->getData()[2]}; + double X1[3] = {theNodes[0]->getData()[0], theNodes[0]->getData()[1], theNodes[0]->getData()[2]}; + double X2[3] = {theNodes[1]->getData()[0], theNodes[1]->getData()[1], theNodes[1]->getData()[2]}; -// double X1[3], X2[3]; -// X1[0] = theNodes[0]->X(); X1[1] = theNodes[0]->Y(); X1[2] = theNodes[0]->Z(); -// X2[0] = theNodes[1]->X(); X2[1] = theNodes[1]->Y(); X2[2] = theNodes[1]->Z(); + // double X1[3], X2[3]; + // X1[0] = theNodes[0]->X(); X1[1] = theNodes[0]->Y(); X1[2] = theNodes[0]->Z(); + // X2[0] = theNodes[1]->X(); X2[1] = theNodes[1]->Y(); X2[2] = theNodes[1]->Z(); ToTheXYPlane(theElement, X1); ToTheXYPlane(theElement, X2); - for(int j = 0; j < 3; ++j) + for (int j = 0; j < 3; ++j) { p1[j] = X1[j]; p2[j] = X2[j]; @@ -4737,27 +4626,17 @@ int RandomWalk::IsTheParticleInThisElement(Particle* A) double x = 0.0, y = 0.0, ra = 0.0, rb = 0.0; - int status = G_intersect_line_segments( p1[0], - p1[1], - p2[0], - p2[1], - p3[0], - p3[1], - p4[0], - p4[1], - &ra, - &rb, - &x, - &y); - - if(status == 0) // Not intersect but extension intersects + int status + = G_intersect_line_segments(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1], p4[0], p4[1], &ra, &rb, &x, &y); + + if (status == 0) // Not intersect but extension intersects ; - //WW else if(status == -1) // Parallel - //WW parallel = 1; - else if(status == 1) - ++countOfInterception; // single intersection - else if(status == 2) // Overlap just do nothing - ; // This should indicate the particle in this element, then. + // WW else if(status == -1) // Parallel + // WW parallel = 1; + else if (status == 1) + ++countOfInterception; // single intersection + else if (status == 2) // Overlap just do nothing + ; // This should indicate the particle in this element, then. else { printf("Not making any sense.\n"); @@ -4767,53 +4646,48 @@ int RandomWalk::IsTheParticleInThisElement(Particle* A) // Check if this particle is inside of the element // If the number of interceptions is odd, // then, it is inside of this element. - if(countOfInterception % 2 == 1) + if (countOfInterception % 2 == 1) return A->elementIndex; // if the number is even, // then, it is outside else - return -1; // This element does not have the particle. + return -1; // This element does not have the particle. } - else if(ele_dim == 3) + else if (ele_dim == 3) { // double volumePism = theElement->GetVolume();// ComputeVolume(); // theElement->nodes } - else if(ele_dim == 1) + else if (ele_dim == 1) { // Since this is 1D, I'll do exhaustive search. // Checking the coordinateflag for proper solution. int coordinateflag = m_msh->GetCoordinateFlag(); - //OK411??? long - for(int i = 0; i < (int)m_msh->ele_vector.size(); ++i) + // OK411??? long + for (int i = 0; i < (int)m_msh->ele_vector.size(); ++i) { - double const* const pnt1 ( - m_msh->nod_vector[m_msh->ele_vector[i]->GetNodeIndex(0)]->getData()); - double const* const pnt2 ( - m_msh->nod_vector[m_msh->ele_vector[i]->GetNodeIndex(1)]->getData()); - if(coordinateflag == 10) // x only + double const* const pnt1(m_msh->nod_vector[m_msh->ele_vector[i]->GetNodeIndex(0)]->getData()); + double const* const pnt2(m_msh->nod_vector[m_msh->ele_vector[i]->GetNodeIndex(1)]->getData()); + if (coordinateflag == 10) // x only { - if( (A->x >= pnt1[0] && A->x < pnt2[0]) || - (A->x >= pnt2[0] && A->x < pnt1[0]) ) + if ((A->x >= pnt1[0] && A->x < pnt2[0]) || (A->x >= pnt2[0] && A->x < pnt1[0])) return i; } - else if(coordinateflag == 11) // y only + else if (coordinateflag == 11) // y only { - if( (A->y >= pnt1[1] && A->y < pnt2[1]) || - (A->y >= pnt2[1] && A->y < pnt1[1]) ) + if ((A->y >= pnt1[1] && A->y < pnt2[1]) || (A->y >= pnt2[1] && A->y < pnt1[1])) return i; } - else if(coordinateflag == 12) // z only + else if (coordinateflag == 12) // z only { - if( (A->z >= pnt1[2] && A->z < pnt2[2]) || - (A->z >= pnt2[2] && A->z < pnt1[2]) ) + if ((A->z >= pnt1[2] && A->z < pnt2[2]) || (A->z >= pnt2[2] && A->z < pnt1[2])) return i; } else - return -1; // Something is wrong. + return -1; // Something is wrong. } - return -10; // The particle is outside of domain + return -10; // The particle is outside of domain } return -1; @@ -4905,20 +4779,17 @@ double RandomWalk::SolveDistanceBetweenTwoPoints(double* p1, double* p2) * D2 ((ax2-ax1)*(by1-ay1) - (ay2-ay1)*(bx1-ax1)) ***********************************************************************/ -int RandomWalk::G_intersect_line_segments ( - double ax1,double ay1, double ax2,double ay2, - double bx1,double by1, double bx2,double by2, - double* ra,double* rb, - double* x,double* y) +int RandomWalk::G_intersect_line_segments(double ax1, double ay1, double ax2, double ay2, double bx1, double by1, + double bx2, double by2, double* ra, double* rb, double* x, double* y) { - double D = ((ax2 - ax1) * (by1 - by2) - (ay2 - ay1) * (bx1 - bx2)); + double D = ((ax2 - ax1) * (by1 - by2) - (ay2 - ay1) * (bx1 - bx2)); double D1 = ((bx1 - ax1) * (by1 - by2) - (by1 - ay1) * (bx1 - bx2)); double D2 = ((ax2 - ax1) * (by1 - ay1) - (ay2 - ay1) * (bx1 - ax1)); double d; d = D; - if (d) /* lines are not parallel */ + if (d) /* lines are not parallel */ { *ra = D1 / d; *rb = D2 / d; @@ -4929,15 +4800,15 @@ int RandomWalk::G_intersect_line_segments ( } if (D1 || D2) - return -1; /* lines are parallel, not colinear */ + return -1; /* lines are parallel, not colinear */ if (ax1 > ax2) { - SWAP (ax1, ax2) + SWAP(ax1, ax2) } if (bx1 > bx2) { - SWAP (bx1, bx2) + SWAP(bx1, bx2) } if (ax1 > bx2) return -1; @@ -4949,16 +4820,16 @@ int RandomWalk::G_intersect_line_segments ( { *x = ax1; *y = ay1; - return 1; /* at endpoints only */ + return 1; /* at endpoints only */ } if (ax2 == bx1) { *x = ax2; *y = ay2; - return 1; /* at endpoints only */ + return 1; /* at endpoints only */ } - return 2; /* colinear with overlap on an interval, not just a single point*/ + return 2; /* colinear with overlap on an interval, not just a single point*/ } /************************************************************** @@ -4972,16 +4843,15 @@ int RandomWalk::G_intersect_line_segments ( * 2 on the plane **************************************************************/ -int RandomWalk::G_intersect_line_segments_3D ( - double* pl1,double* pl2, double* pp1,double* pp2, - double* pp3,double* pi) +int RandomWalk::G_intersect_line_segments_3D(double* pl1, double* pl2, double* pp1, double* pp2, double* pp3, + double* pi) { // Solve for norm of the plane by performing cross product to solve for the plane double p2p1[3], p3p1[3], normOfThePlane[3]; - CrossProduction(pp2,pp1,p2p1); - CrossProduction(pp3,pp1,p3p1); - CrossProduction(p2p1,p3p1,normOfThePlane); + CrossProduction(pp2, pp1, p2p1); + CrossProduction(pp3, pp1, p3p1); + CrossProduction(p2p1, p3p1, normOfThePlane); double a, b, c, d; a = normOfThePlane[0]; @@ -4990,28 +4860,28 @@ int RandomWalk::G_intersect_line_segments_3D ( d = -(a * pp1[0] + b * pp1[1] + c * pp1[2]); // Refer pp1 point for solving d of the plane // Now solution of intersection - double u, denominator; // The line eqn: P=P1+u(P2-P1) where P1 and P2 is on the line + double u, denominator; // The line eqn: P=P1+u(P2-P1) where P1 and P2 is on the line denominator = a * (pl1[0] - pl2[0]) + b * (pl1[1] - pl2[1]) + c * (pl1[2] - pl2[2]); // Check if denominator is zero or not - if(fabs(denominator) < 10e-8) // If this is zero + if (fabs(denominator) < 10e-8) // If this is zero { // The line is either parallel or on the plane. // Check if the line is on the plane first by sustituting P1 into the plane eqn. double onThePlane = a * pl1[0] + b * pl1[1] + c * pl1[2] + d; - if(fabs(onThePlane) < 10e-8) // If the line is on the plane + if (fabs(onThePlane) < 10e-8) // If the line is on the plane return -1; - else // If the line is parallel + else // If the line is parallel return 2; } - else // The line segment either is in the element or has an intersectional point. + else // The line segment either is in the element or has an intersectional point. { u = (a * pl1[0] + b * pl1[1] + c * pl1[2] + d) / denominator; - if (u > 0 && u < 1) // The line is in this element + if (u > 0 && u < 1) // The line is in this element return 0; - else // The line intersects the plane + else // The line intersects the plane { // Solve for the intersection pi[0] = pl1[0] + u * (pl2[0] - pl1[0]); @@ -5034,7 +4904,7 @@ int RandomWalk::G_intersect_line_segments_3D ( void RandomWalk::IsoparametricMappingQuadfromPtoR(int index, double* R) { // Get the mesh first - CFEMesh* m_msh (selectMeshForFluidMomentumProcess()); + CFEMesh* m_msh(selectMeshForFluidMomentumProcess()); // Mount the proper mesh // for(int i=0; i< (int)pcs_vector.size(); ++i) // { @@ -5055,11 +4925,11 @@ void RandomWalk::IsoparametricMappingQuadfromPtoR(int index, double* R) // If a quad element, int nnode = theEle->GetEdgesNumber(); - if(nnode == 4) + if (nnode == 4) { // Get physical coordinates of four corner points double x[4], y[4]; - for(int i = 0; i < nnode; ++i) + for (int i = 0; i < nnode; ++i) { double const* const coords(theEle->GetNode(i)->getData()); x[i] = coords[0]; @@ -5067,7 +4937,7 @@ void RandomWalk::IsoparametricMappingQuadfromPtoR(int index, double* R) } // Some coeff's for convenience - double ax,ay,bx,by,cx,cy,dx,dy; + double ax, ay, bx, by, cx, cy, dx, dy; double X = R[0]; double Y = R[1]; /* @@ -5087,7 +4957,7 @@ void RandomWalk::IsoparametricMappingQuadfromPtoR(int index, double* R) dy = -Y + 0.25 * (y[0] + y[1] + y[2] + y[3]); // Cases for solution - if( fabs(ax) > tolerance) // ax is not zero CASE 1 + if (fabs(ax) > tolerance) // ax is not zero CASE 1 { double s, r, t; @@ -5095,31 +4965,31 @@ void RandomWalk::IsoparametricMappingQuadfromPtoR(int index, double* R) r = ay / ax * cx - cy; t = ay / ax * dx - dy; - if( fabs(s) > tolerance) // s is not zero + if (fabs(s) > tolerance) // s is not zero { - if( fabs(r) > tolerance) // r is not zero + if (fabs(r) > tolerance) // r is not zero { - double A,B,C; + double A, B, C; A = -r * ax; B = r * bx - t * ax - s * cx; C = t * bx - s * dx; double d, y1, y2; d = B * B - 4.0 * A * C; - if(d >= 0.0) // Only for real roots + if (d >= 0.0) // Only for real roots { y1 = (-B + sqrt(d)) / (2.0 * A); y2 = (-B - sqrt(d)) / (2.0 * A); // Get the right y // if(y1 >= 0.0 && y1 <= 1.0) - if(y1 >= -1.0 && y1 <= 1.0) + if (y1 >= -1.0 && y1 <= 1.0) { R[1] = y1; R[0] = -r / s * y1 - t / s; R[2] = 0.0; // For now for 2D elemenets } // else if(y2 >= 0.0 && y2 <= 1.0) - else if(y2 >= -1.0 && y2 <= 1.0) + else if (y2 >= -1.0 && y2 <= 1.0) { R[1] = y2; R[0] = -r / s * y2 - t / s; @@ -5127,8 +4997,7 @@ void RandomWalk::IsoparametricMappingQuadfromPtoR(int index, double* R) } else { - printf( - "Failed to solve reference position for the particle\n"); + printf("Failed to solve reference position for the particle\n"); abort(); // Failed find the solution. } } @@ -5141,19 +5010,19 @@ void RandomWalk::IsoparametricMappingQuadfromPtoR(int index, double* R) { } } - else // Case 3 + else // Case 3 { // x undefined. This should not happen } } - else // if ax = 0 CASE 2 + else // if ax = 0 CASE 2 { - if( fabs(cx) > tolerance) // cx is not zero + if (fabs(cx) > tolerance) // cx is not zero { // If ay is not zero and bx is not zero - if( (fabs(ay) > tolerance) && (fabs(bx) > tolerance) ) + if ((fabs(ay) > tolerance) && (fabs(bx) > tolerance)) { - double A,B,C; + double A, B, C; A = -ay * bx; B = bx * cy - by * cx - ay * dx; C = cy * dx - cx * dy; @@ -5161,24 +5030,22 @@ void RandomWalk::IsoparametricMappingQuadfromPtoR(int index, double* R) double d, x1, x2; // If ay = 0 or bx = 0 - if(fabs(ay) < tolerance || fabs(bx) < tolerance ) + if (fabs(ay) < tolerance || fabs(bx) < tolerance) { - R[0] = - (dy * cx - cy * - dx) / (cy * bx - dy * cx - ay * dx); + R[0] = (dy * cx - cy * dx) / (cy * bx - dy * cx - ay * dx); R[1] = (-bx * R[0] - dx) / cx; R[2] = 0.0; } else // If ay is not zero and bx is not zero, { d = B * B - 4.0 * A * C; - if(d >= 0.0) // Only for real roots + if (d >= 0.0) // Only for real roots { x1 = (-B + sqrt(d)) / (2.0 * A); x2 = (-B - sqrt(d)) / (2.0 * A); // Get the right y - if(x1 >= -1.0 && x1 <= 1.0) + if (x1 >= -1.0 && x1 <= 1.0) // if(x1 >= 0.0 && x1 <= 1.0) { R[0] = x1; @@ -5186,7 +5053,7 @@ void RandomWalk::IsoparametricMappingQuadfromPtoR(int index, double* R) R[2] = 0.0; // For now for 2D elemenets } // else if(x2 >= 0.0 && x2 <= 1.0) - else if(x2 >= -1.0 && x2 <= 1.0) + else if (x2 >= -1.0 && x2 <= 1.0) { R[0] = x2; R[1] = (-bx * R[0] - dx) / cx; @@ -5194,15 +5061,14 @@ void RandomWalk::IsoparametricMappingQuadfromPtoR(int index, double* R) } else { - printf( - "Failed to solve reference position for the particle\n"); + printf("Failed to solve reference position for the particle\n"); abort(); // Failed find the solution. } } } } } - else // If cx = 0, CASE 3 + else // If cx = 0, CASE 3 { R[0] = -dx / bx; R[1] = (by * dx - dy * dx) / (ay * dx + cy * bx); @@ -5215,7 +5081,7 @@ void RandomWalk::IsoparametricMappingQuadfromPtoR(int index, double* R) R[1] = 2*R[1]-1.0; */ } - //else // the element is not quad. + // else // the element is not quad. //{ //} } @@ -5231,7 +5097,7 @@ void RandomWalk::IsoparametricMappingQuadfromPtoR(int index, double* R) void RandomWalk::IsoparametricMappingQuadfromRtoP(int index, double* P) { // Get the mesh first - CFEMesh* m_msh (selectMeshForFluidMomentumProcess()); + CFEMesh* m_msh(selectMeshForFluidMomentumProcess()); // Mount the proper mesh // for(int i=0; i< (int)pcs_vector.size(); ++i) // { @@ -5247,18 +5113,18 @@ void RandomWalk::IsoparametricMappingQuadfromRtoP(int index, double* P) // } // Mount the element fromthe first particle from particles initially MeshLib::CElem* theEle = m_msh->ele_vector[index]; - //OK411 double tolerance = 1e-8; + // OK411 double tolerance = 1e-8; // If a quad element, int nnode = theEle->GetEdgesNumber(); - if(nnode == 4) + if (nnode == 4) { // Get physical coordinates of four corner points double x[4], y[4]; - for(int i = 0; i < nnode; ++i) + for (int i = 0; i < nnode; ++i) { - double const* const coords (theEle->GetNode(i)->getData()); + double const* const coords(theEle->GetNode(i)->getData()); x[i] = coords[0]; y[i] = coords[1]; } @@ -5268,23 +5134,15 @@ void RandomWalk::IsoparametricMappingQuadfromRtoP(int index, double* P) phat[1] = P[1]; phat[2] = P[2]; - P[0] = 0.25 * - ( x[0] * - (1.0 - - phat[0]) * (1.0 - phat[1]) + x[1] * (1.0 + phat[0]) * (1.0 - phat[1]) + - x[2] * - (1.0 + - phat[0]) * (1.0 + phat[1]) + x[3] * (1.0 - phat[0]) * (1.0 + phat[1]) ); - P[1] = 0.25 * - ( y[0] * - (1.0 - - phat[0]) * (1.0 - phat[1]) + y[1] * (1.0 + phat[0]) * (1.0 - phat[1]) + - y[2] * - (1.0 + - phat[0]) * (1.0 + phat[1]) + y[3] * (1.0 - phat[0]) * (1.0 + phat[1]) ); + P[0] = 0.25 * (x[0] * (1.0 - phat[0]) * (1.0 - phat[1]) + x[1] * (1.0 + phat[0]) * (1.0 - phat[1]) + + x[2] * (1.0 + phat[0]) * (1.0 + phat[1]) + + x[3] * (1.0 - phat[0]) * (1.0 + phat[1])); + P[1] = 0.25 * (y[0] * (1.0 - phat[0]) * (1.0 - phat[1]) + y[1] * (1.0 + phat[0]) * (1.0 - phat[1]) + + y[2] * (1.0 + phat[0]) * (1.0 + phat[1]) + + y[3] * (1.0 - phat[0]) * (1.0 + phat[1])); P[2] = 0.0; } - //else // the element is not quad. + // else // the element is not quad. //{ //} } @@ -5301,7 +5159,7 @@ void RandomWalk::IsoparametricMappingQuadfromRtoP(int index, double* P) void RandomWalk::DoJointEffectOfElementInitially(void) { // Get the mesh first - CFEMesh* m_msh (selectMeshForFluidMomentumProcess()); + CFEMesh* m_msh(selectMeshForFluidMomentumProcess()); // Mount the proper mesh // for(int i=0; i< (int)pcs_vector.size(); ++i) // { @@ -5318,7 +5176,7 @@ void RandomWalk::DoJointEffectOfElementInitially(void) // Looping all over the particles to have a choice which plane to go. // Because all of the particles are on the joint initially. - for(int p = 0; p < m_msh->PT->numOfParticles; ++p) + for (int p = 0; p < m_msh->PT->numOfParticles; ++p) { // Mount the element fromthe first particle from particles initially int eleIdx = m_msh->PT->X[p].Now.elementIndex; @@ -5330,9 +5188,9 @@ void RandomWalk::DoJointEffectOfElementInitially(void) MeshLib::CEdge* theJoint = NULL; // Now, 1. find the joint out of theses edges - for(int i = 0; i < numOfEdgeIntheElement; ++i) + for (int i = 0; i < numOfEdgeIntheElement; ++i) // Is this a joint? - if(theEdges[i]->GetJoint() == 1) + if (theEdges[i]->GetJoint() == 1) theJoint = theEdges[i]; // 2. Get multiple planes out of the joint @@ -5344,19 +5202,18 @@ void RandomWalk::DoJointEffectOfElementInitially(void) MeshLib::CNode* crossnode = theNodes[0]; // Let's mount the crossroad class CrossRoad* crossroad = NULL; - for(int i = 0; i < (int)(m_msh->fm_pcs->crossroads.size()); ++i) - if( (size_t)m_msh->fm_pcs->crossroads[i]->Index == crossnode->GetIndex() ) + for (int i = 0; i < (int)(m_msh->fm_pcs->crossroads.size()); ++i) + if ((size_t)m_msh->fm_pcs->crossroads[i]->Index == crossnode->GetIndex()) crossroad = m_msh->fm_pcs->crossroads[i]; // Let's get the contribution of each connected plane. - double chances[100]; // I just set 100 as a maximum number of + double chances[100]; // I just set 100 as a maximum number of // connected planes. - for(int i = 0; i < crossroad->numOfThePlanes; ++i) + for (int i = 0; i < crossroad->numOfThePlanes; ++i) chances[i] = crossroad->plane[i].ratio; // 3. Roulette Wheel Selection int whichWay = RouletteWheelSelection(chances, crossroad->numOfThePlanes); - m_msh->PT->X[p].Now.elementIndex = m_msh->PT->X[p].Past.elementIndex = - crossroad->plane[whichWay].eleIndex; + m_msh->PT->X[p].Now.elementIndex = m_msh->PT->X[p].Past.elementIndex = crossroad->plane[whichWay].eleIndex; } } @@ -5367,12 +5224,12 @@ void RandomWalk::DoJointEffectOfElementInitially(void) **************************************************************************/ void RandomWalk::ToTheXYPlane(MeshLib::CElem* E, double* X) { - if(E->GetDimension() == m_msh->GetMaxElementDim() ) + if (E->GetDimension() == m_msh->GetMaxElementDim()) return; double x[3], xx[3]; // Get the norm of the element plane and do some initialization - for(int k = 0; k < 3; ++k) + for (int k = 0; k < 3; ++k) x[k] = xx[k] = 0.0; double alpha = E->GetAngle(0); @@ -5388,7 +5245,7 @@ void RandomWalk::ToTheXYPlane(MeshLib::CElem* E, double* X) xx[1] = cos(beta) * x[1] - sin(beta) * x[2]; xx[2] = sin(beta) * x[1] + cos(beta) * x[2]; - for(int i = 0; i < 3; ++i) + for (int i = 0; i < 3; ++i) X[i] = xx[i]; // Do translation along z'' axis. // X[2] -= E->GetAngle(2); @@ -5397,8 +5254,8 @@ void RandomWalk::ToTheXYPlane(MeshLib::CElem* E, double* X) void RandomWalk::ToTheXYPlane(int idx, double* X) { CFEMesh* m_msh = NULL; - if(fem_msh_vector.size() == 0) - return; //OK + if (fem_msh_vector.size() == 0) + return; // OK m_msh = selectMeshForFluidMomentumProcess(); // // Mount the proper mesh // for(int i=0; i< (int)pcs_vector.size(); ++i) @@ -5415,12 +5272,12 @@ void RandomWalk::ToTheXYPlane(int idx, double* X) // } MeshLib::CElem* E = m_msh->ele_vector[idx]; - if(E->GetDimension() == m_msh->GetMaxElementDim() ) + if (E->GetDimension() == m_msh->GetMaxElementDim()) return; double x[3], xx[3]; // Get the norm of the element plane and do some initialization - for(int k = 0; k < 3; ++k) + for (int k = 0; k < 3; ++k) x[k] = xx[k] = 0.0; double alpha = E->GetAngle(0); @@ -5436,7 +5293,7 @@ void RandomWalk::ToTheXYPlane(int idx, double* X) xx[1] = cos(beta) * x[1] - sin(beta) * x[2]; xx[2] = sin(beta) * x[1] + cos(beta) * x[2]; - for(int i = 0; i < 3; ++i) + for (int i = 0; i < 3; ++i) X[i] = xx[i]; // Do translation along z'' axis. // X[2] -= E->GetAngle(2); @@ -5450,12 +5307,12 @@ void RandomWalk::ToTheXYPlane(int idx, double* X) **************************************************************************/ void RandomWalk::ToTheRealPlane(MeshLib::CElem* E, double* X) { - if(E->GetDimension() == m_msh->GetMaxElementDim() ) + if (E->GetDimension() == m_msh->GetMaxElementDim()) return; double x[3], xx[3]; // Get the norm of the element plane and do some initialization - for(int k = 0; k < 3; ++k) + for (int k = 0; k < 3; ++k) x[k] = xx[k] = 0.0; double alpha = E->GetAngle(0); @@ -5471,7 +5328,7 @@ void RandomWalk::ToTheRealPlane(MeshLib::CElem* E, double* X) xx[1] = cos(beta) * x[1] + sin(beta) * x[2]; xx[2] = -sin(beta) * x[1] + cos(beta) * x[2]; - for(int i = 0; i < 3; ++i) + for (int i = 0; i < 3; ++i) X[i] = xx[i]; // Let's translate back to z axis. // X[2] += E->GetAngle(2); @@ -5480,7 +5337,7 @@ void RandomWalk::ToTheRealPlane(MeshLib::CElem* E, double* X) void RandomWalk::ToTheRealPlane(int idx, double* X) { CFEMesh* m_msh = NULL; - if(fem_msh_vector.size() == 0) + if (fem_msh_vector.size() == 0) return; m_msh = selectMeshForFluidMomentumProcess(); // // Mount the proper mesh @@ -5498,12 +5355,12 @@ void RandomWalk::ToTheRealPlane(int idx, double* X) // } MeshLib::CElem* E = m_msh->ele_vector[idx]; - if(E->GetDimension() == m_msh->GetMaxElementDim() ) + if (E->GetDimension() == m_msh->GetMaxElementDim()) return; double x[3], xx[3]; // Get the norm of the element plane and do some initialization - for(int k = 0; k < 3; ++k) + for (int k = 0; k < 3; ++k) x[k] = xx[k] = 0.0; double alpha = E->GetAngle(0); @@ -5519,7 +5376,7 @@ void RandomWalk::ToTheRealPlane(int idx, double* X) xx[1] = cos(beta) * x[1] + sin(beta) * x[2]; xx[2] = -sin(beta) * x[1] + cos(beta) * x[2]; - for(int i = 0; i < 3; ++i) + for (int i = 0; i < 3; ++i) X[i] = xx[i]; // Let's translate back to z axis. // X[2] += E->GetAngle(2); @@ -5533,7 +5390,7 @@ void RandomWalk::ToTheRealPlane(int idx, double* X) void RandomWalk::SolveAnglesOfTheElment(MeshLib::CElem* E) { CFEMesh* m_msh = NULL; - if(fem_msh_vector.size() == 0) + if (fem_msh_vector.size() == 0) return; m_msh = selectMeshForFluidMomentumProcess(); // Mount the proper mesh @@ -5552,36 +5409,36 @@ void RandomWalk::SolveAnglesOfTheElment(MeshLib::CElem* E) double tolerance = 1e-20, Enorm[3]; // Allocate angle memory dynamically. - //E->AllocateMeomoryforAngle(); + // E->AllocateMeomoryforAngle(); // Get the norm of the element plane and do some initialization int coordinate_system = m_msh->GetCoordinateFlag(); // If the coordinate system is xz plane or xyz, solve the angles. - if( coordinate_system != 32 && coordinate_system != 22 ) + if (coordinate_system != 32 && coordinate_system != 22) { Enorm[0] = 0.0; Enorm[1] = 0.0; Enorm[2] = 1.0; } else - for(int k = 0; k < 3; ++k) + for (int k = 0; k < 3; ++k) Enorm[k] = E->getTransformTensor(k + 6); // solve for two angles for two rotation transformation. // Solving alpha that will be used for rotation along y axis. double alpha = 0.0; - if(Enorm[0] * Enorm[0] + Enorm[2] * Enorm[2] < tolerance) - ; // have alpha to be zero. No need to rotate. + if (Enorm[0] * Enorm[0] + Enorm[2] * Enorm[2] < tolerance) + ; // have alpha to be zero. No need to rotate. else alpha = acos(Enorm[2] / sqrt(Enorm[0] * Enorm[0] + Enorm[2] * Enorm[2])); // The following if condition is required because // the acos function is not distintive in the case that Enorm[0]'s of // the two planes are opposite each other. - if(Enorm[0] < 0.0) - E->SetAngle(0, alpha ); + if (Enorm[0] < 0.0) + E->SetAngle(0, alpha); else - E->SetAngle(0, alpha + 2.0 * (PI - alpha) ); + E->SetAngle(0, alpha + 2.0 * (PI - alpha)); // Solving beta that will be used for rotation along x' axis double beta = 0.0, BB[3], TranZ; @@ -5589,19 +5446,19 @@ void RandomWalk::SolveAnglesOfTheElment(MeshLib::CElem* E) BB[0] = cos(E->GetAngle(0)) * Enorm[0] + sin(E->GetAngle(0)) * Enorm[2]; BB[1] = Enorm[1]; BB[2] = -sin(E->GetAngle(0)) * Enorm[0] + cos(E->GetAngle(0)) * Enorm[2]; - if(BB[2] > tolerance) + if (BB[2] > tolerance) beta = atan(BB[1] / BB[2]); - else // if BB[2] is zero + else // if BB[2] is zero beta = 0.5 * PI; - E->SetAngle(1, beta ); + E->SetAngle(1, beta); // Solve for the translation. // I'll use the center of the element for this translation. double const* center = E->GetGravityCenter(); double x[3], xx[3]; // Get the norm of the element plane and do some initialization - for(int k = 0; k < 3; ++k) + for (int k = 0; k < 3; ++k) x[k] = xx[k] = 0.0; // Let's rotate the original Enorm to the BB coordinate system // along the y axis @@ -5626,14 +5483,14 @@ void RandomWalk::SolveAnglesOfTheElment(MeshLib::CElem* E) **************************************************************************/ int RandomWalk::RouletteWheelSelection(double* chances, int numOfCases) { - int whichOne = -1000; // Set it meaningless + int whichOne = -1000; // Set it meaningless double* roulette; - roulette = new double [numOfCases] (); + roulette = new double[numOfCases](); MakeRoulette(chances, roulette, numOfCases); whichOne = Select(roulette, numOfCases); - delete [] roulette; + delete[] roulette; return whichOne; } @@ -5651,10 +5508,10 @@ void RandomWalk::MakeRoulette(double* fit, double* roulette, int numOfCases) double fitTotal = 0.0, ProbTotal = 0.0; // Create memory for these two arrays dynamically - pi = new double [numOfCases] (); - fitProbability = new double [numOfCases] (); + pi = new double[numOfCases](); + fitProbability = new double[numOfCases](); - for(int i = 0; i < numOfCases; ++i) + for (int i = 0; i < numOfCases; ++i) { // Function modification can be done here. pi[i] = 1. / exp(-fit[i]); @@ -5662,15 +5519,15 @@ void RandomWalk::MakeRoulette(double* fit, double* roulette, int numOfCases) } // Making Roulette - for(int i = 0; i < numOfCases; ++i) + for (int i = 0; i < numOfCases; ++i) { fitProbability[i] = pi[i] / fitTotal; ProbTotal += fitProbability[i]; roulette[i] = ProbTotal; } - delete [] pi; - delete [] fitProbability; + delete[] pi; + delete[] fitProbability; } /************************************************************************** @@ -5684,8 +5541,8 @@ int RandomWalk::Select(double* roulette, int numOfCases) double probability; probability = randomZeroToOne(); - for(int i = 0; i < numOfCases; ++i) - if(probability < roulette[i]) + for (int i = 0; i < numOfCases; ++i) + if (probability < roulette[i]) return i; return 0; } @@ -5700,7 +5557,7 @@ int RandomWalk::Select(double* roulette, int numOfCases) int RandomWalk::ReadInVelocityFieldOnNodes(string file_base_name) { // Something must be done later on here. - CFEMesh* m_msh (selectMeshForFluidMomentumProcess()); + CFEMesh* m_msh(selectMeshForFluidMomentumProcess()); // Mount the proper mesh // for(int i=0; i< (int)pcs_vector.size(); ++i) // { @@ -5721,27 +5578,26 @@ int RandomWalk::ReadInVelocityFieldOnNodes(string file_base_name) ios::pos_type position; vel_file_name = file_base_name + ".vel"; - ifstream vel_file (vel_file_name.data(),ios::in); + ifstream vel_file(vel_file_name.data(), ios::in); int End = 1; string strbuffer; - while(End) + while (End) { - //OK411??? long - for(int i = 0; i < (int)m_msh->nod_vector.size(); ++i) + // OK411??? long + for (int i = 0; i < (int)m_msh->nod_vector.size(); ++i) { double v[3]; - for(int p = 0; p < 3; ++p) + for (int p = 0; p < 3; ++p) v[p] = 0.0; vel_file >> v[0] >> v[1] >> v[2] >> ws; // Let's assign the velocity - for(int j = 0; j < 3; ++j) + for (int j = 0; j < 3; ++j) { - int nidx1 = m_pcs->GetNodeValueIndex( - m_pcs->pcs_primary_function_name[j]) + 1; - m_pcs->SetNodeValue(m_msh->Eqs2Global_NodeIndex[i],nidx1,v[j]); + int nidx1 = m_pcs->GetNodeValueIndex(m_pcs->pcs_primary_function_name[j]) + 1; + m_pcs->SetNodeValue(m_msh->Eqs2Global_NodeIndex[i], nidx1, v[j]); } } End = 0; @@ -5760,30 +5616,30 @@ void RandomWalk::buildFDMIndex(void) { double xmax, ymax, zmax; double xmin, ymin, zmin; - long i,j,k,iel,ic,jc,kc, nels; - //WW long ne, nels; + long i, j, k, iel, ic, jc, kc, nels; + // WW long ne, nels; int index; neFDM = -1; // get mesh - CFEMesh* m_msh (NULL); - for(index = 0; index < (int)pcs_vector.size(); index++) + CFEMesh* m_msh(NULL); + for (index = 0; index < (int)pcs_vector.size(); index++) { m_pcs = pcs_vector[index]; // if( m_pcs->pcs_type_name.find("RICHARDS_FLOW")!=string::npos){ - if( m_pcs->getProcessType () == FiniteElement::RICHARDS_FLOW) + if (m_pcs->getProcessType() == FiniteElement::RICHARDS_FLOW) { m_msh = FEMGet("RICHARDS_FLOW"); break; } // else if( m_pcs->pcs_type_name.find("LIQUID_FLOW")!=string::npos){ - else if( m_pcs->getProcessType () == FiniteElement::LIQUID_FLOW) + else if (m_pcs->getProcessType() == FiniteElement::LIQUID_FLOW) { m_msh = FEMGet("LIQUID_FLOW"); break; } // else if( m_pcs->pcs_type_name.find("GROUNDWATER_FLOW")!=string::npos){ - else if( m_pcs->getProcessType() == FiniteElement::GROUNDWATER_FLOW) + else if (m_pcs->getProcessType() == FiniteElement::GROUNDWATER_FLOW) { m_msh = FEMGet("GROUNDWATER_FLOW"); break; @@ -5800,39 +5656,38 @@ void RandomWalk::buildFDMIndex(void) // element size xmax = ymax = zmax = -1e+12; xmin = ymin = zmin = 1e+12; - for(index = 0; index < 4; index++) // 4 nodes because FDM method only for equa-sized quads + for (index = 0; index < 4; index++) // 4 nodes because FDM method only for equa-sized quads { -// x = m_msh->nod_vector[m_msh->ele_vector[0]->GetNodeIndex(index)]->X(); -// y = m_msh->nod_vector[m_msh->ele_vector[0]->GetNodeIndex(index)]->Y(); -// z = m_msh->nod_vector[m_msh->ele_vector[0]->GetNodeIndex(index)]->Z(); - double const* const xyz (m_msh->nod_vector[m_msh->ele_vector[0]->GetNodeIndex( - index)]->getData()); - if(xyz[0] > xmax) + // x = m_msh->nod_vector[m_msh->ele_vector[0]->GetNodeIndex(index)]->X(); + // y = m_msh->nod_vector[m_msh->ele_vector[0]->GetNodeIndex(index)]->Y(); + // z = m_msh->nod_vector[m_msh->ele_vector[0]->GetNodeIndex(index)]->Z(); + double const* const xyz(m_msh->nod_vector[m_msh->ele_vector[0]->GetNodeIndex(index)]->getData()); + if (xyz[0] > xmax) xmax = xyz[0]; - if(xyz[0] < xmin) + if (xyz[0] < xmin) xmin = xyz[0]; - if(xyz[1] > ymax) + if (xyz[1] > ymax) ymax = xyz[1]; - if(xyz[1] < ymin) + if (xyz[1] < ymin) ymin = xyz[1]; - if(xyz[2] > zmax) + if (xyz[2] > zmax) zmax = xyz[2]; - if(xyz[2] < zmin) + if (xyz[2] < zmin) zmin = xyz[2]; } dx = xmax - xmin; dy = ymax - ymin; dz = zmax - zmin; - if(dx < 1.e-12) + if (dx < 1.e-12) dx = 1.e-12; - if(dy < 1.e-12) + if (dy < 1.e-12) dy = 1.e-12; - if(dz < 1.e-12) + if (dz < 1.e-12) dz = 1.e-12; nx = (int)floor(xrw_range / dx) + 1; ny = (int)floor(yrw_range / dy) + 1; nz = (int)floor(zrw_range / dz) + 1; - //WW ne = nx*ny*nz; + // WW ne = nx*ny*nz; nels = m_msh->ele_vector.size(); for (k = 0; k < nz; k++) // loop over the dummy element set @@ -5847,11 +5702,10 @@ void RandomWalk::buildFDMIndex(void) one.eleIndex = -5; // eleIndex -5 is dummy index different from -10 for (iel = 0; iel < nels; iel++) // loop over mesh elements, assign them to dummy elements { - double const* center = - m_msh->ele_vector[iel]->GetGravityCenter(); - ic = (int) floor((center[0] - pnt_x_min) / dx); - jc = (int) floor((center[1] - pnt_y_min) / dy); - kc = (int) floor((center[2] - pnt_z_min) / dz); + double const* center = m_msh->ele_vector[iel]->GetGravityCenter(); + ic = (int)floor((center[0] - pnt_x_min) / dx); + jc = (int)floor((center[1] - pnt_y_min) / dy); + kc = (int)floor((center[2] - pnt_z_min) / dz); if (ic != i || jc != j || kc != k) continue; one.eleIndex = iel; @@ -5991,19 +5845,19 @@ void PCTRead(string file_base_name) { CFEMesh* m_msh = NULL; - if(fem_msh_vector.size() == 0) - return; //OK + if (fem_msh_vector.size() == 0) + return; // OK double xyz[3]; // Mount the proper mesh - m_msh = fem_msh_vector[0]; // Something must be done later on here. + m_msh = fem_msh_vector[0]; // Something must be done later on here. // File handling string pct_file_name; ios::pos_type position; pct_file_name = file_base_name + PCT_FILE_EXTENSION; - ifstream pct_file (pct_file_name.data(),ios::in); + ifstream pct_file(pct_file_name.data(), ios::in); if (!pct_file) return; @@ -6018,15 +5872,15 @@ void PCTRead(string file_base_name) int End = 1; string strbuffer; RandomWalk* RW = NULL; - m_msh->PT = new RandomWalk(srand_seed); //PCH + m_msh->PT = new RandomWalk(srand_seed); // PCH RW = m_msh->PT; // Create pathline RandomWalk::Pathline path; - while(End) + while (End) { // Later on from this line, I can put which mesh I am dealing with. - //pct_file >> RW->numOfParticles >> ws; + // pct_file >> RW->numOfParticles >> ws; getline(pct_file, s_flag); ss.str(s_flag); @@ -6034,17 +5888,16 @@ void PCTRead(string file_base_name) ss.clear(); Trace one; - RW->ChanceOfIrreversed = new double[RW->numOfParticles]; //YS + RW->ChanceOfIrreversed = new double[RW->numOfParticles]; // YS int counter = 0; - for(int i = 0; i < RW->numOfParticles; ++i) + for (int i = 0; i < RW->numOfParticles; ++i) { // Assign the number to the particle int idx = 0, identity = 0; double x = 0.0, y = 0.0, z = 0.0, Starting = 0, vx = 0.0, vy = 0.0, vz = 0.0, K = 0.0; - pct_file >> idx >> x >> y >> z >> identity >> Starting >> vx >> vy >> vz >> - K >> ws; + pct_file >> idx >> x >> y >> z >> identity >> Starting >> vx >> vy >> vz >> K >> ws; xyz[0] = x; xyz[1] = y; @@ -6052,14 +5905,14 @@ void PCTRead(string file_base_name) idx = m_msh->FindElementByPoint(xyz); - if(idx == -1) + if (idx == -1) continue; one.Past.elementIndex = one.Now.elementIndex = idx; one.Past.x = one.Now.x = x; one.Past.y = one.Now.y = y; one.Past.z = one.Now.z = z; - //JT 2010 + // JT 2010 one.Past.StartingTime = one.Now.StartingTime = Starting; one.Past.identity = one.Now.identity = identity; one.Past.Vx = one.Now.Vx = vx; @@ -6073,7 +5926,7 @@ void PCTRead(string file_base_name) counter++; // Creat pathline - if(i < 50) + if (i < 50) RW->pathline.push_back(path); } RW->numOfParticles = counter; @@ -6093,24 +5946,24 @@ void DATWriteParticleFile(int current_time_step) RandomWalk* RW = NULL; // Gather the momentum mesh - size_t pcs_vector_size (pcs_vector.size()); - for(size_t i = 0; i < pcs_vector_size; ++i) + size_t pcs_vector_size(pcs_vector.size()); + for (size_t i = 0; i < pcs_vector_size; ++i) { // m_pcs = pcs_vector[i]; const FiniteElement::ProcessType pcs_type(pcs_vector[i]->getProcessType()); // if( m_pcs->pcs_type_name.find("RICHARDS_FLOW")!=string::npos){ - if( pcs_type == FiniteElement::RICHARDS_FLOW) + if (pcs_type == FiniteElement::RICHARDS_FLOW) { m_msh = FEMGet("RICHARDS_FLOW"); break; } // else if( m_pcs->pcs_type_name.find("LIQUID_FLOW")!=string::npos){ - else if( pcs_type == FiniteElement::LIQUID_FLOW) + else if (pcs_type == FiniteElement::LIQUID_FLOW) { m_msh = FEMGet("LIQUID_FLOW"); break; } - else if( pcs_type == FiniteElement::GROUNDWATER_FLOW) + else if (pcs_type == FiniteElement::GROUNDWATER_FLOW) { m_msh = FEMGet("GROUNDWATER_FLOW"); break; @@ -6122,58 +5975,62 @@ void DATWriteParticleFile(int current_time_step) // file naming char now[10]; - sprintf(now,"%i",current_time_step); + sprintf(now, "%i", current_time_step); string nowstr = now; string vtk_file_name = FileName + "_RWPT_"; vtk_file_name += nowstr; vtk_file_name += ".particles.vtk"; - fstream vtk_file (vtk_file_name.data(),ios::out); - vtk_file.setf(ios::scientific,ios::floatfield); + fstream vtk_file(vtk_file_name.data(), ios::out); + vtk_file.setf(ios::scientific, ios::floatfield); vtk_file.precision(12); - if(!vtk_file.good()) + if (!vtk_file.good()) return; - vtk_file.seekg(0L,ios::beg); + vtk_file.seekg(0L, ios::beg); // Write Header - vtk_file << "# vtk DataFile Version 3.6.2" << "\n"; - vtk_file << "Particle file: OpenGeoSys->Paraview. Current time (s) = " << - RW->CurrentTime << "\n"; - vtk_file << "ASCII" << "\n"; + vtk_file << "# vtk DataFile Version 3.6.2" + << "\n"; + vtk_file << "Particle file: OpenGeoSys->Paraview. Current time (s) = " << RW->CurrentTime << "\n"; + vtk_file << "ASCII" + << "\n"; vtk_file << "\n"; - vtk_file << "DATASET POLYDATA" << "\n"; //KR vtk_file << "DATASET PARTICLES" << "\n"; - vtk_file << "POINTS " << RW->numOfParticles << " double" << "\n"; + vtk_file << "DATASET POLYDATA" + << "\n"; // KR vtk_file << "DATASET PARTICLES" << "\n"; + vtk_file << "POINTS " << RW->numOfParticles << " double" + << "\n"; // Write particle locations - for(int i = 0; i < np; ++i) - vtk_file << RW->X[i].Now.x << " " << RW->X[i].Now.y << " " << RW->X[i].Now.z << - "\n"; + for (int i = 0; i < np; ++i) + vtk_file << RW->X[i].Now.x << " " << RW->X[i].Now.y << " " << RW->X[i].Now.z << "\n"; // KR add "vertices" block to create a correct VTK file - vtk_file << "VERTICES " << np << " " << (2 * np) << "\n"; - for(int i = 0; i < np; ++i) + vtk_file << "VERTICES " << np << " " << (2 * np) << "\n"; + for (int i = 0; i < np; ++i) vtk_file << 1 << " " << i << "\n"; // Write particle identities vtk_file << "\n"; vtk_file << "POINT_DATA " << RW->numOfParticles << "\n"; - vtk_file << "SCALARS identity float 1" << "\n"; - vtk_file << "LOOKUP_TABLE default" << "\n"; - for(int i = 0; i < np; ++i) + vtk_file << "SCALARS identity float 1" + << "\n"; + vtk_file << "LOOKUP_TABLE default" + << "\n"; + for (int i = 0; i < np; ++i) vtk_file << RW->X[i].Now.identity << "\n"; - // Write particle on_boundary or not - vtk_file << endl; - vtk_file << "SCALARS on_boundary float 1" << endl; - vtk_file << "LOOKUP_TABLE default" << endl; - for(int i=0; iX[i].Now.on_boundary << endl; + // Write particle on_boundary or not + vtk_file << endl; + vtk_file << "SCALARS on_boundary float 1" << endl; + vtk_file << "LOOKUP_TABLE default" << endl; + for (int i = 0; i < np; ++i) + vtk_file << RW->X[i].Now.on_boundary << endl; // Write particle vectors vtk_file << endl; vtk_file << "VECTORS velocity float" << endl; - for(int i=0; iX[i].Now.Vx << " " << RW->X[i].Now.Vy << " " << RW->X[i].Now.Vz << endl; + for (int i = 0; i < np; ++i) + vtk_file << RW->X[i].Now.Vx << " " << RW->X[i].Now.Vy << " " << RW->X[i].Now.Vz << endl; // Let's close it, now vtk_file.close(); diff --git a/FEM/rf_random_walk.h b/FEM/rf_random_walk.h index f6e9587ec..c674250b0 100644 --- a/FEM/rf_random_walk.h +++ b/FEM/rf_random_walk.h @@ -13,8 +13,8 @@ Programing: 07/2005 PCH Implementation **************************************************************************/ -#ifndef break_RWPT //OK -#define break_RWPT //OK +#ifndef break_RWPT // OK +#define break_RWPT // OK #include "rf_mmp_new.h" #include "rfmat_cp.h" @@ -28,7 +28,7 @@ class Particle double x; double y; double z; - int on_boundary; //YS + int on_boundary; // YS // Velocity Vector double Vx; @@ -48,7 +48,7 @@ class Particle // Time double t; - double StartingTime; // JT 2010, added for continuous particle boundary, segemented by StartingTime + double StartingTime; // JT 2010, added for continuous particle boundary, segemented by StartingTime // the element it belongs to int elementIndex; @@ -77,9 +77,9 @@ class Particle dVxdx = B.dVxdx; dVydy = B.dVydy; dVzdz = B.dVzdz; - on_boundary = B.on_boundary; + on_boundary = B.on_boundary; - for(int i = 0; i < 9; ++i) + for (int i = 0; i < 9; ++i) D[i] = B.D[i]; return *this; @@ -110,16 +110,16 @@ class RandomWalk int UniformOrNormal; int leavingParticles; int srand_seed; - int RWPTMode; // 0: Advection and dispersion for homogeneous media + int RWPTMode; // 0: Advection and dispersion for homogeneous media // 1: Advection and dispersion for heterogeneous media // 2: Advection only for homogeneous media // 3: Advection only for heterogeneous media // 4: Dispersion only for homogeneous media // 5: Dispersion only for heterogeneous media - int PURERWPT; // 0: Defualt - Velocity solved by GeoSys + int PURERWPT; // 0: Defualt - Velocity solved by GeoSys // 1: Velocity fields on nodes are given in a separate file. // 2: Velocity solved as in FDM approach - int FDMIndexSwitch; // 0: Build + int FDMIndexSwitch; // 0: Build // 1: No need to build int GridOption; @@ -128,34 +128,31 @@ class RandomWalk class FDMIndex { -public: + public: int i; int j; int k; int eleIndex; - FDMIndex(void) - { - i = j = k = eleIndex = -10; - } + FDMIndex(void) { i = j = k = eleIndex = -10; } }; class Position { -public: + public: double p[3]; }; class Pathline { -public: + public: std::vector path; }; std::vector X; std::vector pathline; - double Marsaglia(void); // N(0,1) sample generator + double Marsaglia(void); // N(0,1) sample generator int IsTheParticleInThisElement(Particle* A); void InterpolateVelocityOfTheParticleByInverseDistance(Particle* A); @@ -165,23 +162,18 @@ class RandomWalk void TracePathlineInThisElement(Particle* A); int IndexOfTheElementThatThisParticleBelong(int option, Particle* A); - double randomMinusOneToOne(void); // create uniform random number between -1 and 1 - double randomZeroToOne(void); // create uniform random number between 0 and 1 + double randomMinusOneToOne(void); // create uniform random number between -1 and 1 + double randomZeroToOne(void); // create uniform random number between 0 and 1 - void AdvanceToNextTimeStep(double dt,double ctime); + void AdvanceToNextTimeStep(double dt, double ctime); void AdvanceBySplitTime(double dt, int numOfSplit); void TraceStreamline(void); - void GetDisplacement(Particle* B, - double* Z, - double* V, - double* dD, - double time, - double* dsp); + void GetDisplacement(Particle* B, double* Z, double* V, double* dD, double time, double* dsp); void RandomlyDriftAway(Particle* A, double dt, double* delta, int type); int RandomWalkDrift(double* Z, int type); void SolveDispersionCoefficient(Particle* A); - void RandomWalkOutput(double,int); //JT 2010 + void RandomWalkOutput(double, int); // JT 2010 int SolveForNextPosition(Particle* A, Particle* B); @@ -211,8 +203,8 @@ class RandomWalk void SolveAnglesOfTheElment(MeshLib::CElem* E); void IsoparametricMappingQuadfromPtoR(int index, double* R); void IsoparametricMappingQuadfromRtoP(int index, double* P); - double TA(double Gx,double uT, double uA, double xTA); - double TB(double Gx,double uT, double uA, double uB, double xTB); + double TA(double Gx, double uT, double uA, double xTA); + double TB(double Gx, double uT, double uA, double uB, double xTB); double Tmin(double* a, int* idx); // Read in velocity fields from an separate file @@ -222,60 +214,48 @@ class RandomWalk // Rate-limited reaction - sorption and desorption double Two_rateModel(double A, double k1, double k2, double t); - CRFProcess *getFlowPCS() const {return flow_pcs;} - + CRFProcess* getFlowPCS() const { return flow_pcs; } protected: FiniteElement::CFiniteElementStd* fem; private: CRFProcess* m_pcs; - CRFProcess* flow_pcs; //FM_TEST + CRFProcess* flow_pcs; // FM_TEST CFEMesh* m_msh; std::vector indexFDM; - std::vectorrwpt_out_strings; //JT + std::vector rwpt_out_strings; // JT int nx; int ny; int nz; - int neFDM; // JT + int neFDM; // JT double dx; double dy; double dz; - double xrw_range; //JT + double xrw_range; // JT double yrw_range; double zrw_range; double ComputeVolume(Particle* A, MeshLib::CElem* m_ele); double ComputeVolume(Particle* A, Particle* element, MeshLib::CElem* m_ele); - void CopyParticleCoordToArray(Particle* A, - double* x1buff, - double* x2buff, - double* x3buff, - double* x4buff); - - void GetNodeOfMiniFEMforTheEdge(MeshLib::CNode* theNode, - MeshLib::CEdge* theEdge, - Particle* A); - void CheckBoundary2D(Particle* A, Particle* B); - void CheckBoundary3D(Particle* A, Particle* B); - - int G_intersect_line_segments ( - double ax1,double ay1, double ax2,double ay2, - double bx1,double by1, double bx2,double by2, - double* ra,double* rb, - double* x,double* y); - int G_intersect_line_segments_3D( - double* pl1,double* pl2, double* pp1,double* pp2, - double* pp3,double* pi); + void CopyParticleCoordToArray(Particle* A, double* x1buff, double* x2buff, double* x3buff, double* x4buff); + + void GetNodeOfMiniFEMforTheEdge(MeshLib::CNode* theNode, MeshLib::CEdge* theEdge, Particle* A); + void CheckBoundary2D(Particle* A, Particle* B); + void CheckBoundary3D(Particle* A, Particle* B); + + int G_intersect_line_segments(double ax1, double ay1, double ax2, double ay2, double bx1, double by1, double bx2, + double by2, double* ra, double* rb, double* x, double* y); + int G_intersect_line_segments_3D(double* pl1, double* pl2, double* pp1, double* pp2, double* pp3, double* pi); void ConcPTFile(const char* file_name); /** * Select the mesh whose process name has the mesh for Fluid_Momentum * @return */ - CFEMesh* selectMeshForFluidMomentumProcess (); + CFEMesh* selectMeshForFluidMomentumProcess(); }; extern void PCTRead(std::string); extern void DATWriteParticleFile(int); -#endif //OK +#endif // OK diff --git a/FEM/rf_react.cpp b/FEM/rf_react.cpp index cd70d5e71..b92730c70 100644 --- a/FEM/rf_react.cpp +++ b/FEM/rf_react.cpp @@ -38,7 +38,7 @@ // Elem object #include "fem_ele_std.h" #ifdef CHEMAPP - #include "eqlink.h" +#include "eqlink.h" #endif #include @@ -50,14 +50,13 @@ void destroy_react(void* item); int NR_INORG_COMP_EQU; int NR_MIN_EQU; extern char* file_name; -extern char* crdat; /* MX */ -//REACTION_MODEL *rcml=NULL; +extern char* crdat; /* MX */ +// REACTION_MODEL *rcml=NULL; extern double gravity_constant; // MDL: new coupling #ifdef LIBPHREEQC -extern "C" -{ +extern "C" { #include "phreeqc.h" } @@ -69,12 +68,12 @@ string libphreeqc_print; #include #endif -#if defined (USE_MPI) +#if defined(USE_MPI) #include #include "SplitMPI_Communicator.h" #endif -vector REACT_vec; +vector REACT_vec; /************************************************************************** ROCKFLOW - Funktion: ExecuteReactionsPHREEQC @@ -94,10 +93,10 @@ vector REACT_vec; **************************************************************************/ void REACT::ExecuteReactionsPHREEQC(void) { - long i, ok = 0; + long i, ok = 0; // CRFProcess *m_pcs = NULL; // static REACTION_MODEL *rcml; - FILE* indatei, * fphinp, * fsel_out = NULL; + FILE *indatei, *fphinp, *fsel_out = NULL; char fsout[80]; DisplayMsgLn("ExecuteReactionsPHREEQC:"); @@ -107,9 +106,9 @@ void REACT::ExecuteReactionsPHREEQC(void) /* Perform reaction step */ /* --------------------------------------------------------------------------*/ - if(flag_pqc) + if (flag_pqc) { - indatei = fopen(crdat,"r"); + indatei = fopen(crdat, "r"); /* do only at first timestep */ if (indatei != NULL) // if (aktueller_zeitschritt<2){ @@ -129,11 +128,11 @@ void REACT::ExecuteReactionsPHREEQC(void) fphinp = fopen("phinp.dat", "w"); if ((fphinp) && ok) { - for(i = 0; i < this->nodenumber; i++) - if(this->rateflag[i] > 0) + for (i = 0; i < this->nodenumber; i++) + if (this->rateflag[i] > 0) { rewind(indatei); - ok = ReadInputPhreeqc(i,indatei, fphinp); + ok = ReadInputPhreeqc(i, indatei, fphinp); } fclose(indatei); fclose(fphinp); @@ -145,26 +144,26 @@ void REACT::ExecuteReactionsPHREEQC(void) } /* Extern Program call to PHREEQC */ - if(ok) + if (ok) ok = Call_Phreeqc(); - if(ok == 0) + if (ok == 0) exit(1); /* Set up the output values for rockflow after Phreeqc reaction*/ - fsel_out = fopen(fsout,"r"); + fsel_out = fopen(fsout, "r"); if ((ok) && !fsel_out) { DisplayMsgLn("The selected output file doesn't exist!!!"); exit(1); } - else if(ok) + else if (ok) { ok = ReadOutputPhreeqc(fsout); - if(!ok) + if (!ok) DisplayMsgLn(" Error in call to PHREEQC !!!"); fclose(fsel_out); } - } /* if flag */ + } /* if flag */ /* Calculate Rates */ CalculateReactionRates(); @@ -180,7 +179,8 @@ void REACT::ExecuteReactionsPHREEQC(void) /* test output*/ /* for(comp=0; compnumber_of_comp;comp++){ - DisplayMsg("component : "); DisplayLong(comp);DisplayMsg(", name = "); DisplayMsg(this->name[comp]);DisplayMsgLn(". "); + DisplayMsg("component : "); DisplayLong(comp);DisplayMsg(", name = "); + DisplayMsg(this->name[comp]);DisplayMsgLn(". "); DisplayMsgLn("val_in: "); for(i=0;inodenumber;i++){ DisplayDouble(this->val_in[comp][i],0,0); DisplayMsg(", ");} DisplayMsgLn(" "); @@ -196,7 +196,7 @@ void REACT::ExecuteReactionsPHREEQC(void) for(i=0;inodenumber;i++){ DisplayDouble((double) this->rateflag[i],0,0); DisplayMsg(", ");} DisplayMsgLn(" "); */ -} /* End of ExecuteReactionsPHREEQC */ +} /* End of ExecuteReactionsPHREEQC */ /************************************************************************** ROCKFLOW - Funktion: ExecuteReactionsPHREEQCNew @@ -217,45 +217,48 @@ void REACT::ExecuteReactionsPHREEQC(void) **************************************************************************/ void REACT::ExecuteReactionsPHREEQCNew(void) { - long i, ii, ok = 0; + long i, ii, ok = 0; - std::cout << " ExecuteReactionsPHREEQCNew:" << "\n"; + std::cout << " ExecuteReactionsPHREEQCNew:" + << "\n"; /* File handling - GeoSys input file */ - std::ifstream pqc_file (this->file_name_pqc.data(),ios::in); + std::ifstream pqc_file(this->file_name_pqc.data(), ios::in); if (!pqc_file.good()) - std::cout << - "! Error in ExecuteReactionsPHREEQCNew: no Input File (*.pqc) found !" << "\n"; + std::cout << "! Error in ExecuteReactionsPHREEQCNew: no Input File (*.pqc) found !" + << "\n"; // exit(1); // File handling - data exchange file to phreeqc, input to PHREEQC - std::ofstream outfile (this->outfile_name.data(),ios::out); - if(!outfile.is_open()) - std::cout << "Error: Outfile phinp.dat could not be opened for writing " << - "\n"; + std::ofstream outfile(this->outfile_name.data(), ios::out); + if (!outfile.is_open()) + std::cout << "Error: Outfile phinp.dat could not be opened for writing " + << "\n"; // exit(1); // Set up reaction model - if((int)this->pqc_names.size() == 0) + if ((int)this->pqc_names.size() == 0) { ok = this->ReadReactionModelNew(&pqc_file); - if(!ok) - std::cout << "Error setting up reaction model" << "\n"; + if (!ok) + std::cout << "Error setting up reaction model" + << "\n"; } // Check for nodes without reactions - if((int)this->check_no_reaction_nodes == false) + if ((int)this->check_no_reaction_nodes == false) { ok = this->CheckNoReactionNodes(); - if(!ok) - std::cout << "Error when checking for nodes without reactions" << "\n"; + if (!ok) + std::cout << "Error when checking for nodes without reactions" + << "\n"; } /* Read the input file (*.pqc) and set up the input file for PHREEQC ("phinp.dat")*/ // Write input data block to PHREEQC for each node ii = 0; - for(i = 0; i < this->nodenumber; i++) - if(this->rateflag[i] > 0) + for (i = 0; i < this->nodenumber; i++) + if (this->rateflag[i] > 0) { - pqc_file.seekg(0L,ios_base::beg); + pqc_file.seekg(0L, ios_base::beg); ok = WriteInputPhreeqc(i, /*&pqc_file,*/ &outfile); ii++; } @@ -266,25 +269,28 @@ void REACT::ExecuteReactionsPHREEQCNew(void) outfile.close(); /* Extern Program call to PHREEQC */ - if(ok) + if (ok) ok = Call_Phreeqc(); - if(ok == 0) + if (ok == 0) { - std::cout << " Error executing PHREEQC.exe - Stopping " << "\n"; + std::cout << " Error executing PHREEQC.exe - Stopping " + << "\n"; std::cout.flush(); // exit(1); } - if(aktueller_zeitschritt==0) - this->rcml_number_of_pqcsteps = this->Teststeps(ii); - if(ok) + if (aktueller_zeitschritt == 0) + this->rcml_number_of_pqcsteps = this->Teststeps(ii); + if (ok) { ok = ReadOutputPhreeqcNew(); - if(!ok) - std::cout << " Error in call to PHREEQC !!!" << "\n"; + if (!ok) + std::cout << " Error in call to PHREEQC !!!" + << "\n"; } - std::cout << " Calculated equilibrium geochemistry at " << ii << " nodes." << "\n"; + std::cout << " Calculated equilibrium geochemistry at " << ii << " nodes." + << "\n"; /* Calculate Rates */ // CalculateReactionRates(); @@ -294,16 +300,15 @@ void REACT::ExecuteReactionsPHREEQCNew(void) /* pH and pe constant or variable */ // ResetpHpe(rc, rcml); -} /* End of ExecuteReactionsPHREEQCNew */ +} /* End of ExecuteReactionsPHREEQCNew */ /*ExecutePQCString WH*/ void REACT::ExecutePQCString(void) { - int myrank = 0; - long ii, ok = 0; - bool initial=false; + long ii, ok = 0; + bool initial = false; #if defined(USE_MPI) int mysize, mysize_all; @@ -312,30 +317,33 @@ void REACT::ExecutePQCString(void) MPI_Comm_size(MPI_COMM_WORLD, &mysize_all); std::cout << " Execute IPhreeqc MPI on rank:" << myrank << "\n"; #else - std::cout << " Execute IPhreeqc:" << "\n"; + std::cout << " Execute IPhreeqc:" + << "\n"; #endif /* File handling - GeoSys input file */ - std::ifstream pqc_file (this->file_name_pqc.data(),ios::in); + std::ifstream pqc_file(this->file_name_pqc.data(), ios::in); if (!pqc_file.good()) - std::cout << - "! Error in ExecutePQCString: no Input File (*.pqc) found !" << "\n"; + std::cout << "! Error in ExecutePQCString: no Input File (*.pqc) found !" + << "\n"; // Set up reaction model - if((int)this->pqc_names.size() == 0) + if ((int)this->pqc_names.size() == 0) { initial = true; ok = this->ReadReactionModelNew(&pqc_file); - if(!ok) - std::cout << "Error setting up reaction model" << "\n"; + if (!ok) + std::cout << "Error setting up reaction model" + << "\n"; } // Check for nodes without reactions - if((int)this->check_no_reaction_nodes == false) + if ((int)this->check_no_reaction_nodes == false) { ok = this->CheckNoReactionNodes(); - if(!ok) - std::cout << "Error when checking for nodes without reactions" << "\n"; + if (!ok) + std::cout << "Error when checking for nodes without reactions" + << "\n"; } std::vector ranknodelistvec; @@ -347,7 +355,6 @@ void REACT::ExecutePQCString(void) std::vector ranklistoutstring; std::vector > ranklistoutstringstore; - // set up return data arrays int n1 = this->rcml_number_of_master_species; int n2 = this->rcml_number_of_equi_phases; @@ -355,54 +362,61 @@ void REACT::ExecutePQCString(void) int n4 = this->rcml_number_of_gas_species; int n5 = this->rcml_number_of_kinetics; int n6 = this->rcml_number_of_secondary_species; - // get total number of species in PHREEQC output file + // get total number of species in PHREEQC output file int ntot = n1 + n2 + n3 + n4 + n5 + n6 + 3; // 3 extra for pH, H+ and pe - double *Concentration; - Concentration = new double[ntot *nodenumber]; - for (int it = 0; it < (ntot )*nodenumber; it++) Concentration[it] = 0.0; + double* Concentration; + Concentration = new double[ntot * nodenumber]; + for (int it = 0; it < (ntot)*nodenumber; it++) + Concentration[it] = 0.0; #if defined(USE_MPI) // Concentration buffer for data distribution and collection - double *Concentration_buff; - Concentration_buff = new double[ntot *nodenumber]; - for (int it = 0; it < (long)(ntot)*nodenumber; it++) Concentration_buff[it] = 0.0; + double* Concentration_buff; + Concentration_buff = new double[ntot * nodenumber]; + for (int it = 0; it < (long)(ntot)*nodenumber; it++) + Concentration_buff[it] = 0.0; - for (int j = 0; j < mysize; j++){ + for (int j = 0; j < mysize; j++) + { rankranklistvec.clear(); rankliststring.clear(); for (int ii = 0; ii < mysize_all; ii++) - if ((ii%mysize) == j) { - rankranklistvec.push_back(ii); - rankliststring.push_back (new stringstream); - ranklistoutstring.push_back (new stringstream); + if ((ii % mysize) == j) + { + rankranklistvec.push_back(ii); + rankliststring.push_back(new stringstream); + ranklistoutstring.push_back(new stringstream); } - rankrankliststore.push_back(rankranklistvec); - rankliststringstore.push_back(rankliststring); - ranklistoutstringstore.push_back(ranklistoutstring); + rankrankliststore.push_back(rankranklistvec); + rankliststringstore.push_back(rankliststring); + ranklistoutstringstore.push_back(ranklistoutstring); } // in parallel version, push back a vector of selected node indices for each rank - for (int j = 0; j < mysize_all; j++){ + for (int j = 0; j < mysize_all; j++) + { ranknodelistvec.clear(); for (ii = 0; ii < nodenumber; ii++) - if ((ii%mysize_all) == j) { + if ((ii % mysize_all) == j) + { ranknodelistvec.push_back(ii); } - ranknodeliststore.push_back(ranknodelistvec); + ranknodeliststore.push_back(ranknodelistvec); } // now distribute the tasks - //MPI_Barrier(comm_DDC); + // MPI_Barrier(comm_DDC); long nNodes = (long)nodenumber; MPI_Bcast(&nNodes, 1, MPI_LONG, 0, comm_DDC); -#else +#else rankranklistvec.push_back(0); rankrankliststore.push_back(rankranklistvec); - rankliststring.push_back (new stringstream); - ranklistoutstring.push_back (new stringstream); + rankliststring.push_back(new stringstream); + ranklistoutstring.push_back(new stringstream); rankliststringstore.push_back(rankliststring); ranklistoutstringstore.push_back(ranklistoutstring); // in serial version, just push back a single vector of all node indices - for (ii = 0; ii < this->nodenumber; ii++) { + for (ii = 0; ii < this->nodenumber; ii++) + { ranknodelistvec.push_back(ii); } ranknodeliststore.push_back(ranknodelistvec); @@ -414,14 +428,16 @@ void REACT::ExecutePQCString(void) int idx, idy; bool firstinput; char string[4]; //, string1[4], string2[4]; - for (std::size_t j = 0; j < rankrankliststore[myrank].size(); j++){ + for (std::size_t j = 0; j < rankrankliststore[myrank].size(); j++) + { firstinput = true; idy = rankrankliststore[myrank][j]; - sprintf(string, "%li", static_cast(idy) ); - for (std::size_t i = 0; i < ranknodeliststore[idy].size(); i++){ + sprintf(string, "%li", static_cast(idy)); + for (std::size_t i = 0; i < ranknodeliststore[idy].size(); i++) + { idx = ranknodeliststore[idy][i]; if (this->rateflag[idx] > 0) - { + { pqc_file.seekg(0L, ios_base::beg); ok = WriteInputPQCString(idx, rankliststringstore[myrank][j], firstinput); firstinput = false; @@ -431,63 +447,71 @@ void REACT::ExecutePQCString(void) } // Close *.pqc input file pqc_file.close(); - + #if defined(USE_MPI) - MPI_Barrier (comm_DDC); //add barrier to avoid race condition + MPI_Barrier(comm_DDC); // add barrier to avoid race condition MPI_Request req1; //, req2; - //int signal; - int strlength; + // int signal; + int strlength; if (mysize_all > mysize) // if group_IPQC exists, send the input strings to relevant ranks - for (std::size_t j = 1; j < rankrankliststore[myrank].size(); j++){ + for (std::size_t j = 1; j < rankrankliststore[myrank].size(); j++) + { idy = rankrankliststore[myrank][j]; strlength = rankliststringstore[myrank][j]->str().size(); - //signal = myrank_all; + // signal = myrank_all; MPI_Isend(&strlength, 1, MPI_INT, idy, myrank, MPI_COMM_WORLD, &req1); std::string tmp = rankliststringstore[myrank][j]->str(); - char message[tmp.length()+1]; - for(std::size_t i=0; i mysize) // if group_IPQC exists, receive the output strings from relevant ranks - while (num_signal < static_cast(rankrankliststore[myrank].size() )){ - MPI_Recv(&strlength, 1, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status1); - char string_RT[strlength+1]; - MPI_Recv(string_RT, strlength+1, MPI_CHAR, status1.MPI_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status2); - std::size_t rank_RT = 0; - for (std::size_t j = 1; j < rankrankliststore[myrank].size(); j++){ - if (rankrankliststore[myrank][j] == status1.MPI_SOURCE){ - rank_RT = j; - break; + if (mysize_all > mysize) // if group_IPQC exists, receive the output strings from relevant ranks + while (num_signal < static_cast(rankrankliststore[myrank].size())) + { + MPI_Recv(&strlength, 1, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status1); + char string_RT[strlength + 1]; + MPI_Recv(string_RT, strlength + 1, MPI_CHAR, status1.MPI_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status2); + std::size_t rank_RT = 0; + for (std::size_t j = 1; j < rankrankliststore[myrank].size(); j++) + { + if (rankrankliststore[myrank][j] == status1.MPI_SOURCE) + { + rank_RT = j; + break; + } + } + (*ranklistoutstringstore[myrank][rank_RT]) << string_RT; + num_signal++; } - } - (*ranklistoutstringstore[myrank][rank_RT]) << string_RT; - num_signal++; - } MPI_Barrier(comm_DDC); #endif - if(ok){ - #if defined(USE_MPI) - for (std::size_t j = 0; j < rankrankliststore[myrank].size(); j++){ + if (ok) + { +#if defined(USE_MPI) + for (std::size_t j = 0; j < rankrankliststore[myrank].size(); j++) + { int idy = rankrankliststore[myrank][j]; std::stringstream idexr; idexr << idy; @@ -496,62 +520,69 @@ void REACT::ExecutePQCString(void) ok = ReadOutputIPQC(ranknodeliststore[idy], ranklistoutstringstore[myrank][j], Concentration_buff); } MPI_Barrier(comm_DDC); - MPI_Allreduce(Concentration_buff, Concentration, ntot*nodenumber, MPI_DOUBLE, MPI_SUM, comm_DDC); + MPI_Allreduce(Concentration_buff, Concentration, ntot * nodenumber, MPI_DOUBLE, MPI_SUM, comm_DDC); MPI_Barrier(comm_DDC); - #else +#else ok = ReadOutputIPQC(ranknodeliststore[myrank], ranklistoutstringstore[myrank][0], Concentration); - #endif +#endif - if(!ok) - std::cout << " Error in call to PHREEQC !!!" << "\n"; + if (!ok) + std::cout << " Error in call to PHREEQC !!!" + << "\n"; } // return data to mass transport processes // loop over ranks / over number of nodelist vectors - for (std::size_t kk = 0; kk < ranknodeliststore.size(); kk++){ - // loop over the nodelist for a single rank - for (std::size_t jj = 0; jj < ranknodeliststore[kk].size(); jj++){ + for (std::size_t kk = 0; kk < ranknodeliststore.size(); kk++) + { + // loop over the nodelist for a single rank + for (std::size_t jj = 0; jj < ranknodeliststore[kk].size(); jj++) + { // get start position of concentration vector for this node in Concentration data array int nidx = ranknodeliststore[kk][jj]; - int position = nidx*ntot; + int position = nidx * ntot; // for deactivated nodes, do nothing if (rateflag[nidx] == 0) continue; // master species - for (int i=0; iSetNodeValue(nidx, pqc_index[i] + 0, Concentration[position + i]); - // pH, H+, pe - for (int i=n1; i= 0) && (pqc_process[i]>=0)) // check if H+ is defined as pcs - pcs_vector[pqc_process[i]]->SetNodeValue(nidx, pqc_index[i] + 0, Concentration[position + i]); - if (!initial){ + // pH, H+, pe + for (int i = n1; i < n1 + 3; i++) + if ((pqc_index[i] >= 0) && (pqc_process[i] >= 0)) // check if H+ is defined as pcs + pcs_vector[pqc_process[i]]->SetNodeValue(nidx, pqc_index[i] + 0, Concentration[position + i]); + if (!initial) + { // equilibrium phases - for (int i=n1+3; iSetNodeValue(nidx, pqc_index[i] + 0, Concentration[position + i]); - // ion exchangers - for (int i=n1+3+n2; iSetNodeValue(nidx, pqc_index[i] + 0, Concentration[position + i]); } // gas phase species - for (int i=n1+3+n2+n3; iSetNodeValue(nidx, pqc_index[i] + 0, Concentration[position + i]); - if (!initial){ + if (!initial) + { // kinetic phases - for (int i=n1+3+n2+n3+n4; iSetNodeValue(nidx, pqc_index[i] + 0, Concentration[position + i]); // additional species - for (int i=n1+3+n2+n3+n4+n5; iSetNodeValue(nidx, pqc_index[i] + 0, Concentration[position + i]); - } + } } // loop over nodelist for a single rank } // loop over all ranks #if defined(USE_MPI) delete[] Concentration_buff; - MPI_Barrier(comm_DDC); - std::cout << " Calculated equilibrium geochemistry at " << ii << " nodes on rank "<< myrank << "." << "\n"; + MPI_Barrier(comm_DDC); + std::cout << " Calculated equilibrium geochemistry at " << ii << " nodes on rank " << myrank << "." + << "\n"; #else - std::cout << " Calculated equilibrium geochemistry at " << ii << " nodes." << "\n"; + std::cout << " Calculated equilibrium geochemistry at " << ii << " nodes." + << "\n"; #endif delete[] Concentration; @@ -560,9 +591,9 @@ void REACT::ExecutePQCString(void) rankranklistvec.clear(); rankrankliststore.clear(); - for(std::size_t j = 0; j < rankliststringstore[myrank].size(); ++j) + for (std::size_t j = 0; j < rankliststringstore[myrank].size(); ++j) delete rankliststringstore[myrank][j]; - for(std::size_t j = 0; j < ranklistoutstringstore[myrank].size(); ++j) + for (std::size_t j = 0; j < ranklistoutstringstore[myrank].size(); ++j) delete ranklistoutstringstore[myrank][j]; } @@ -572,44 +603,47 @@ int REACT::WriteInputPQCString(long index, /*ifstream *pqc_iinfile,*/ stringstre std::stringstream in; string name, line_string, speciesname, dummy; CRFProcess* m_pcs = NULL; - int i, ii, idx, n1, n2, n3, n4, n5, n6, count=-1, stepsflag, found=0; + int i, ii, idx, n1, n2, n3, n4, n5, n6, count = -1, stepsflag, found = 0; double dval, dval1, sat_index = 0.0; double z, h, dens, press, partial_press, volume, temp = -1.0, mm; double unitfactor_l = 1, unitfactor_s = 1; - //CB 19.1.2011 + // CB 19.1.2011 // Get the reaction interface data - REACTINT *m_rei = NULL; - if(REACTINT_vec.size()>0){ + REACTINT* m_rei = NULL; + if (REACTINT_vec.size() > 0) + { m_rei = REACTINT_vec[0]; - if(m_rei->unitconversion){ + if (m_rei->unitconversion) + { m_rei->CalcUnitConversionFactors(index, &unitfactor_l, &unitfactor_s, true); } } cout.flush(); - ifstream pqc_infile (this->file_name_pqc.data(),ios::in); - pqc_infile.seekg(0L,ios::beg); + ifstream pqc_infile(this->file_name_pqc.data(), ios::in); + pqc_infile.seekg(0L, ios::beg); // precision output file - out_buff->setf(ios::scientific,ios::floatfield); + out_buff->setf(ios::scientific, ios::floatfield); out_buff->precision(16); /* zeilenweise lesen */ - while(!pqc_infile.eof()) + while (!pqc_infile.eof()) { - pqc_infile.getline(line,MAX_ZEILE); + pqc_infile.getline(line, MAX_ZEILE); line_string = line; - if(line_string.find("#STOP") != string::npos) + if (line_string.find("#STOP") != string::npos) break; //------------------------------------------------------------------------------------------------------------- /* Schleife ueber Keyword Solution */ - if(line_string.find("SOLUTION") != string::npos) // keyword found + if (line_string.find("SOLUTION") != string::npos) // keyword found { - *out_buff << "SOLUTION " << index + 1 << " #New Version " << "\n"; + *out_buff << "SOLUTION " << index + 1 << " #New Version " + << "\n"; *out_buff << "#GRID " << index + 1 << "\n"; - while(line_string.find("#ende") == string::npos) + while (line_string.find("#ende") == string::npos) { - pqc_infile.getline(line,MAX_ZEILE); + pqc_infile.getline(line, MAX_ZEILE); line_string = line; if (line_string.find("# comp") != string::npos) { @@ -619,84 +653,96 @@ int REACT::WriteInputPQCString(long index, /*ifstream *pqc_iinfile,*/ stringstre count++; speciesname = pqc_names[count]; dval = pcs_vector[pqc_process[count]]->GetNodeValue(index, pqc_index[count]); - //CB 19.1.2011 + // CB 19.1.2011 // based on porosity, calculate molality mi,w before coputing equilirium chemistry - if(m_rei) { - if(m_rei->unitconversion) { + if (m_rei) + { + if (m_rei->unitconversion) + { idx = pcs_vector[pqc_process[count]]->GetProcessComponentNumber(); - //mi,w = Ci,w * n *55.5 / CH2O - //mi,s = Ci,w * (1-n) *55.5 / CH2O - if(cp_vec[idx]->transport_phase==0) // liquid phase - dval *= unitfactor_l; - else if(cp_vec[idx]->transport_phase==1) // solid phase - dval *= unitfactor_s; + // mi,w = Ci,w * n *55.5 / CH2O + // mi,s = Ci,w * (1-n) *55.5 / CH2O + if (cp_vec[idx]->transport_phase == 0) // liquid phase + dval *= unitfactor_l; + else if (cp_vec[idx]->transport_phase == 1) // solid phase + dval *= unitfactor_s; } } - if(speciesname.compare("pe")) // if this is not pe - if(dval < 1.0e-19) + if (speciesname.compare("pe")) // if this is not pe + if (dval < 1.0e-19) dval = 0.0; - *out_buff << speciesname << " " << dval << " # comp " << "\n"; + *out_buff << speciesname << " " << dval << " # comp " + << "\n"; } } else if (line_string.find("# temp") != string::npos) { // check if heat transport process is calculated in GeoSys - if(this->rcml_heat_flag > 0) + if (this->rcml_heat_flag > 0) { m_pcs = PCSGet("HEAT_TRANSPORT"); idx = m_pcs->GetNodeValueIndex("TEMPERATURE1"); - dval = m_pcs->GetNodeValue(index,idx); + dval = m_pcs->GetNodeValue(index, idx); if (dval < 273.0) - dval += 273.15; //change from °C to Kelvin if necessary + dval += 273.15; // change from °C to Kelvin if necessary dval -= 273.15; // Input to PHREEQC is in °C - *out_buff << "temp " << dval << " # temp " << "\n"; + *out_buff << "temp " << dval << " # temp " + << "\n"; temp = dval; // save for gas phase input } } else // Write units and temperature in the standard case - if (line_string.find("pH") == string::npos && - line_string.find("pe") == string::npos && - line_string.find("#ende") == string::npos) + if (line_string.find("pH") == string::npos && line_string.find("pe") == string::npos + && line_string.find("#ende") == string::npos) *out_buff << line_string << "\n"; } // end while // special treat pH, and pe n1 = this->rcml_number_of_master_species; count++; - if(count != n1) - cout << "Error in index of pqc_vectors !" << "\n"; - dval = pcs_vector[pqc_process[count]]->GetNodeValue(index,pqc_index[count]); + if (count != n1) + cout << "Error in index of pqc_vectors !" + << "\n"; + dval = pcs_vector[pqc_process[count]]->GetNodeValue(index, pqc_index[count]); count++; - if(this->gamma_Hplus > 0) // pH and H+ in GeoSys species, calculate pH from H+ + if (this->gamma_Hplus > 0) // pH and H+ in GeoSys species, calculate pH from H+ { - dval1 = fabs(pcs_vector[pqc_process[n1+1]]->GetNodeValue(index,pqc_index[n1+1])); // CB 01/11 probably safer taking abs before calculating log(H+) - //CB 19.1.2011 + dval1 = fabs(pcs_vector[pqc_process[n1 + 1]]->GetNodeValue( + index, pqc_index[n1 + 1])); // CB 01/11 probably safer taking abs before calculating log(H+) + // CB 19.1.2011 // based on porosity, calculate molality mi,w before coputing equilirium chemistry - if(m_rei) - if(m_rei->unitconversion) //mi,w = Ci,w * n *55.5 / CH2O - dval1 *= unitfactor_l; + if (m_rei) + if (m_rei->unitconversion) // mi,w = Ci,w * n *55.5 / CH2O + dval1 *= unitfactor_l; dval = -log10(dval1 * gamma_Hplus); } - if(this->rcml_pH_charge > 0) - *out_buff << "pH" << " " << dval << " charge " << - " # comp " << "\n"; + if (this->rcml_pH_charge > 0) + *out_buff << "pH" + << " " << dval << " charge " + << " # comp " + << "\n"; else - *out_buff << "pH" << " " << dval << " # comp " << "\n"; + *out_buff << "pH" + << " " << dval << " # comp " + << "\n"; // write pe count++; dval = pcs_vector[pqc_process[n1 + 2]]->GetNodeValue(index, pqc_index[n1 + 2]); - *out_buff << "pe" << " " << dval << " # comp " << "\n"; + *out_buff << "pe" + << " " << dval << " # comp " + << "\n"; *out_buff << line_string << "\n"; - } // end SOLUTION + } // end SOLUTION //------------------------------------------------------------------------------------------------------------- /* Schleife ueber Keyword EQUILIBRIUM PHASES */ // keyword found - if(line_string.find("EQUILIBRIUM_PHASES") != string::npos) + if (line_string.find("EQUILIBRIUM_PHASES") != string::npos) { - *out_buff << "\n" << "EQUILIBRIUM_PHASES " << index + 1 << "\n"; - while(line_string.find("#ende") == string::npos) + *out_buff << "\n" + << "EQUILIBRIUM_PHASES " << index + 1 << "\n"; + while (line_string.find("#ende") == string::npos) { - pqc_infile.getline(line,MAX_ZEILE); + pqc_infile.getline(line, MAX_ZEILE); line_string = line; if (line_string.find("# comp") != string::npos) { @@ -704,105 +750,112 @@ int REACT::WriteInputPQCString(long index, /*ifstream *pqc_iinfile,*/ stringstre in.str(line_string); in >> speciesname >> sat_index; speciesname = pqc_names[count]; - dval = pcs_vector[pqc_process[count]]->GetNodeValue(index,pqc_index[count]); - if(dval < 1.0e-19) + dval = pcs_vector[pqc_process[count]]->GetNodeValue(index, pqc_index[count]); + if (dval < 1.0e-19) dval = 0.0; - //CB 19.1.2011 + // CB 19.1.2011 // based on porosity, calculate molality mj before coputing equilirium chemistry - if(m_rei) { - if(m_rei->unitconversion) { + if (m_rei) + { + if (m_rei->unitconversion) + { idx = pcs_vector[pqc_process[count]]->GetProcessComponentNumber(); - //mi,w = Ci,w * n *55.5 / CH2O - //mi,s = Ci,w * (1-n) *55.5 / CH2O - if(cp_vec[idx]->transport_phase==0) // liquid phase - dval *= unitfactor_l; - else if(cp_vec[idx]->transport_phase==1) // solid phase - dval *= unitfactor_s; + // mi,w = Ci,w * n *55.5 / CH2O + // mi,s = Ci,w * (1-n) *55.5 / CH2O + if (cp_vec[idx]->transport_phase == 0) // liquid phase + dval *= unitfactor_l; + else if (cp_vec[idx]->transport_phase == 1) // solid phase + dval *= unitfactor_s; } } - *out_buff << speciesname << " " << sat_index << " " << - dval << " # comp " << "\n"; + *out_buff << speciesname << " " << sat_index << " " << dval << " # comp " + << "\n"; in.clear(); } else *out_buff << line_string << "\n"; } - } // end EQUILIBRIUM PHASES + } // end EQUILIBRIUM PHASES //------------------------------------------------------------------------------------------------------------- /* Schleife ueber Keyword EXCHANGE */ - if(line_string.find("EXCHANGE") != string::npos) // keyword found + if (line_string.find("EXCHANGE") != string::npos) // keyword found { - *out_buff << "\n" << "EXCHANGE " << index + 1 << "\n"; - while(line_string.find("#ende") == string::npos) + *out_buff << "\n" + << "EXCHANGE " << index + 1 << "\n"; + while (line_string.find("#ende") == string::npos) { - pqc_infile.getline(line,MAX_ZEILE); + pqc_infile.getline(line, MAX_ZEILE); line_string = line; if (line_string.find("# comp") != string::npos) { count++; speciesname = pqc_names[count]; dval = pcs_vector[pqc_process[count]]->GetNodeValue(index, pqc_index[count]); - if(dval < 1.0e-19) + if (dval < 1.0e-19) dval = 0.0; - *out_buff << speciesname << " " << dval << - " # comp " << "\n"; + *out_buff << speciesname << " " << dval << " # comp " + << "\n"; } else *out_buff << line_string << "\n"; } - } // end EXCHANGE + } // end EXCHANGE //------------------------------------------------------------------------------------------------------------- /* Schleife ueber Keyword GAS_PHASE */ - if(line_string.find("GAS_PHASE") != string::npos) // keyword found + if (line_string.find("GAS_PHASE") != string::npos) // keyword found { - *out_buff << "\n" << "GAS_PHASE " << index + 1 << "\n"; + *out_buff << "\n" + << "GAS_PHASE " << index + 1 << "\n"; - // get necessary values for conversion of molar concentrations to partial pressures, and to calculate total pressure and total volume + // get necessary values for conversion of molar concentrations to partial pressures, and to calculate total + // pressure and total volume // get height of node z - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt - //WW MeshLib::CNode* m_nod = NULL; - //WW m_nod = m_msh->nod_vector[index]; + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt + // WW MeshLib::CNode* m_nod = NULL; + // WW m_nod = m_msh->nod_vector[index]; z = m_msh->nod_vector[index]->getData()[2]; // get piezometric hight h m_pcs = PCSGet("GROUNDWATER_FLOW"); - if(m_pcs == NULL) - cout << " Error - no flow process found!" << "\n"; + if (m_pcs == NULL) + cout << " Error - no flow process found!" + << "\n"; idx = m_pcs->GetNodeValueIndex("HEAD") + 1; - h = m_pcs->GetNodeValue(index,idx); + h = m_pcs->GetNodeValue(index, idx); // get fluid density dens = mfp_vector[0]->Density(); // calculate pressure in [Pa] press = dens * gravity_constant * (h - z); - // cout << " Pressure: " << press << " = " << dens << " * " << gravity_constant << " * ( " << h << " - " << z << " ) " << "\n"; + // cout << " Pressure: " << press << " = " << dens << " * " << gravity_constant << " * ( " << h << " - " << + // z << " ) " << "\n"; // get temperature in [°C] - if(rcml_heat_flag < 1) + if (rcml_heat_flag < 1) temp = this->temperature; // get molar masses of gas phase - mm = 0.0; // mm is total molar mass of gas phase in [mol] - ii = rcml_number_of_master_species + 3 + rcml_number_of_ion_exchanges + - rcml_number_of_equi_phases; - for(i = ii; i < ii + rcml_number_of_gas_species; i++) + mm = 0.0; // mm is total molar mass of gas phase in [mol] + ii = rcml_number_of_master_species + 3 + rcml_number_of_ion_exchanges + rcml_number_of_equi_phases; + for (i = ii; i < ii + rcml_number_of_gas_species; i++) { speciesname = this->pqc_names[i]; - // cout << "Testing index vectors: " << speciesname << ", With vectors: " << pqc_names[i] << ", " << pcs_vector[pqc_process[i]]->pcs_number << ", " << pqc_index[i]; - dval = pcs_vector[pqc_process[i]]->GetNodeValue(index,pqc_index[i]); + // cout << "Testing index vectors: " << speciesname << ", With vectors: " << pqc_names[i] << + //", + //" + //<< pcs_vector[pqc_process[i]]->pcs_number << ", " << pqc_index[i]; + dval = pcs_vector[pqc_process[i]]->GetNodeValue(index, pqc_index[i]); // cout << dval << "\n"; mm += dval; } // calculate Volume of gas phase in [mol * Pa * m^3 / K / mol * K / Pa = m^3 ] volume = mm * 8.314472 * (273.15 + temp) / press; - while(line_string.find("#ende") == string::npos) + while (line_string.find("#ende") == string::npos) { - pqc_infile.getline(line,MAX_ZEILE); + pqc_infile.getline(line, MAX_ZEILE); line_string = line; if (line_string.find("-pressure") != string::npos) // pressure in atmospheres - *out_buff << " -pressure " << press / - 101325.0 << "\n"; + *out_buff << " -pressure " << press / 101325.0 << "\n"; else if (line_string.find("-volume") != string::npos) // volume in Liters - *out_buff << " -volume " << volume * 1000.0 << - "\n"; + *out_buff << " -volume " << volume * 1000.0 << "\n"; else if (line_string.find("-temperature") != string::npos) // temperature in °Celsius *out_buff << " -temperature " << temp << "\n"; @@ -810,37 +863,35 @@ int REACT::WriteInputPQCString(long index, /*ifstream *pqc_iinfile,*/ stringstre { count++; speciesname = pqc_names[count]; - dval = pcs_vector[pqc_process[count]]->GetNodeValue( - index, - pqc_index - [count]); - if(dval < 1.0e-19) + dval = pcs_vector[pqc_process[count]]->GetNodeValue(index, pqc_index[count]); + if (dval < 1.0e-19) dval = 0.0; if (mm > 0.0) partial_press = press * dval / mm; else partial_press = 0.0; - *out_buff << " " << speciesname << " " << - partial_press / 101325.0 << " # comp " << "\n"; + *out_buff << " " << speciesname << " " << partial_press / 101325.0 << " # comp " + << "\n"; } else - *out_buff << line_string << "\n"; //write line unchanged + *out_buff << line_string << "\n"; // write line unchanged } - } // end GAS_PHASE + } // end GAS_PHASE //------------------------------------------------------------------------------------------------------------- /* Schleife ueber Keyword SELECTED_OUTPUT */ // keyword found - if(line_string.find("SELECTED_OUTPUT") != string::npos) - if(firstinput/*index < 1*/) + if (line_string.find("SELECTED_OUTPUT") != string::npos) + if (firstinput /*index < 1*/) { - *out_buff << "\n" << "SELECTED_OUTPUT" << "\n"; - while(line_string.find("#ende") == string::npos) + *out_buff << "\n" + << "SELECTED_OUTPUT" + << "\n"; + while (line_string.find("#ende") == string::npos) { - pqc_infile.getline(line,MAX_ZEILE); + pqc_infile.getline(line, MAX_ZEILE); line_string = line; if (line_string.find("-file") != string::npos) - *out_buff << "-file " << this->results_file_name_new << - "\n"; + *out_buff << "-file " << this->results_file_name_new << "\n"; else *out_buff << line_string << "\n"; } @@ -848,14 +899,16 @@ int REACT::WriteInputPQCString(long index, /*ifstream *pqc_iinfile,*/ stringstre // end SELECTED OUTPUT //------------------------------------------------------------------------------------------------------------- /* Schleife ueber Keyword PRINT */ - if(line_string.find("PRINT") != string::npos) // keyword found + if (line_string.find("PRINT") != string::npos) // keyword found - if(firstinput/*index < 1*/) + if (firstinput /*index < 1*/) { - *out_buff << "\n" << "PRINT" << "\n"; - while(line_string.find("#ende") == string::npos) + *out_buff << "\n" + << "PRINT" + << "\n"; + while (line_string.find("#ende") == string::npos) { - pqc_infile.getline(line,MAX_ZEILE); + pqc_infile.getline(line, MAX_ZEILE); line_string = line; *out_buff << line_string << "\n"; } @@ -864,11 +917,13 @@ int REACT::WriteInputPQCString(long index, /*ifstream *pqc_iinfile,*/ stringstre //------------------------------------------------------------------------------------------------------------- /* Schleife ueber Keyword USER_PUNCH */ // keyword found - if(line_string.find("USER_PUNCH") != string::npos) - { - if(firstinput/*index < 1*/) + if (line_string.find("USER_PUNCH") != string::npos) + { + if (firstinput /*index < 1*/) { - *out_buff << "\n" << "USER_PUNCH" << "\n"; + *out_buff << "\n" + << "USER_PUNCH" + << "\n"; // Write Header n1 = this->rcml_number_of_master_species; n2 = this->rcml_number_of_equi_phases; @@ -877,27 +932,27 @@ int REACT::WriteInputPQCString(long index, /*ifstream *pqc_iinfile,*/ stringstre n5 = this->rcml_number_of_kinetics; n6 = this->rcml_number_of_secondary_species; *out_buff << "-head "; - for(i = 0; i < n1; i++) + for (i = 0; i < n1; i++) *out_buff << " " << pqc_names[i]; *out_buff << " pH "; *out_buff << " H+ "; *out_buff << " pe "; - for(i = n1 + 3; i < n1 + 3 + n2; i++) + for (i = n1 + 3; i < n1 + 3 + n2; i++) *out_buff << " " << pqc_names[i]; - for(i = n1 + 3 + n2; i < n1 + 3 + n2 + n3; i++) + for (i = n1 + 3 + n2; i < n1 + 3 + n2 + n3; i++) *out_buff << " " << pqc_names[i]; - for(i = n1 + 3 + n2 + n3; i < n1 + 3 + n2 + n3 + n4; i++) + for (i = n1 + 3 + n2 + n3; i < n1 + 3 + n2 + n3 + n4; i++) *out_buff << " " << pqc_names[i]; - for(i=n1+3+n2+n3+n4; i 0) + if (n2 > 0) { *out_buff << " 40 PUNCH "; - for(i = n1 + 3; i < n1 + 3 + n2; i++) + for (i = n1 + 3; i < n1 + 3 + n2; i++) *out_buff << " EQUI(\"" << pqc_names[i] << "\"),"; *out_buff << "\n"; } // Write ion exchangers - if(n3 > 0) + if (n3 > 0) { *out_buff << " 60 PUNCH "; - for(i = n1 + 3 + n2; i < n1 + 3 + n2 + n3; i++) + for (i = n1 + 3 + n2; i < n1 + 3 + n2 + n3; i++) *out_buff << " MOL(\"" << pqc_names[i] << "\"),"; *out_buff << "\n"; } // Write gas phase species - if(n4 > 0) + if (n4 > 0) { *out_buff << " 70 PUNCH "; - for(i = n1 + 3 + n2 + n3; i < n1 + 3 + n2 + n3 + n4; i++) + for (i = n1 + 3 + n2 + n3; i < n1 + 3 + n2 + n3 + n4; i++) *out_buff << " GAS(\"" << pqc_names[i] << "\"),"; *out_buff << "\n"; } - // Write (exclusively) kinetic species - if(n5 > 0){ + // Write (exclusively) kinetic species + if (n5 > 0) + { *out_buff << " 80 PUNCH "; - for(i=n1+3+n2+n3+n4; i 0){ - for(i=0;i 0) + { + for (i = 0; i < n6; i++) + *out_buff << " " << 90 + i * 10 << " " << additional_punches[i] << "\n"; } } // end if index < 1 // search for end of USER_PUNCH data block in *.pqc input file - while(!pqc_infile.eof()) + while (!pqc_infile.eof()) { - pqc_infile.getline(line,MAX_ZEILE); + pqc_infile.getline(line, MAX_ZEILE); line_string = line; - if((line_string.find("#ende") != string::npos) || - (line_string.find("END") != string::npos)) + if ((line_string.find("#ende") != string::npos) || (line_string.find("END") != string::npos)) break; } - } // end USER_PUNCH + } // end USER_PUNCH //------------------------------------------------------------------------------------------------------------- - if(line_string.find("-steps") != string::npos) // keyword found + if (line_string.find("-steps") != string::npos) // keyword found { in.str(line_string); in >> dummy >> dval >> this->rcml_number_of_pqcsteps >> dummy; CTimeDiscretization* m_tim = NULL; - if(time_vector.size() > 0) + if (time_vector.size() > 0) m_tim = time_vector[0]; else - cout << - "Error in WriteInputPhreeqc: no time discretization data !" << "\n"; + cout << "Error in WriteInputPhreeqc: no time discretization data !" + << "\n"; dval = m_tim->CalcTimeStep(); - *out_buff << "-steps " << dval << " in " << - this->rcml_number_of_pqcsteps << " steps" << "\n"; - } // end -steps + *out_buff << "-steps " << dval << " in " << this->rcml_number_of_pqcsteps << " steps" + << "\n"; + } // end -steps //------------------------------------------------------------------------------------------------------------- - if(line_string.find("KNOBS") != string::npos) - if(firstinput/*index < 1*/) + if (line_string.find("KNOBS") != string::npos) + if (firstinput /*index < 1*/) { - *out_buff << "\n" << "KNOBS" << "\n"; - while(line_string.find("#ende") == string::npos) + *out_buff << "\n" + << "KNOBS" + << "\n"; + while (line_string.find("#ende") == string::npos) { - pqc_infile.getline(line,MAX_ZEILE); + pqc_infile.getline(line, MAX_ZEILE); line_string = line; *out_buff << line_string << "\n"; } } -//------------------------------------------------------------------------------------------------------------- - // Schleife ueber Keyword KINETICS - if(line_string.find("KINETICS")!=string::npos){ + //------------------------------------------------------------------------------------------------------------- + // Schleife ueber Keyword KINETICS + if (line_string.find("KINETICS") != string::npos) + { stepsflag = 0; - *out_buff << "\n" << "KINETICS " << index+1 << "\n"; - while(line_string.find("#ende")==string::npos){ - pqc_infile.getline(line,MAX_ZEILE); + *out_buff << "\n" + << "KINETICS " << index + 1 << "\n"; + while (line_string.find("#ende") == string::npos) + { + pqc_infile.getline(line, MAX_ZEILE); line_string = line; // Check if this is a new kinetic formulation, i.e. kinetics name = speciesname (phase) - if (line_string.find("# comp") !=string::npos){ + if (line_string.find("# comp") != string::npos) + { in.str(line_string); - in >> speciesname ; + in >> speciesname; in.clear(); found = 0; - for(int i=0;icount) count=i; - found=i; - break; + for (int i = 0; i < int(pqc_index.size()); i++) + if (speciesname.compare(pqc_names[i]) == 0) + { + if (i > count) + count = i; + found = i; + break; } *out_buff << line_string << "\n"; } // This is just to avoid mix-up with subkeyword "-m" - else if(line_string.find("-m0")!=string::npos) { // keyword found + else if (line_string.find("-m0") != string::npos) + { // keyword found *out_buff << line_string << "\n"; } // here get current node concentration after transport - else if(line_string.find("-m")!=string::npos) { // keyword found - dval = pcs_vector[pqc_process[found]]->GetNodeValue(index,pqc_index[found]); - if(dval < 1.0e-19) dval = 0.0; - //CB 19.1.2011 - // based on porosity, calculate molality mj before coputing equilirium chemistry - if(m_rei){ - if(m_rei->unitconversion) { + else if (line_string.find("-m") != string::npos) + { // keyword found + dval = pcs_vector[pqc_process[found]]->GetNodeValue(index, pqc_index[found]); + if (dval < 1.0e-19) + dval = 0.0; + // CB 19.1.2011 + // based on porosity, calculate molality mj before coputing equilirium chemistry + if (m_rei) + { + if (m_rei->unitconversion) + { idx = pcs_vector[pqc_process[found]]->GetProcessComponentNumber(); - //mi,w = Ci,w * n *55.5 / CH2O - //mi,s = Ci,w * (1-n) *55.5 / CH2O - if(cp_vec[idx]->transport_phase==0) // liquid phase - dval *= unitfactor_l; - else if(cp_vec[idx]->transport_phase==1) // solid phase - dval *= unitfactor_s; + // mi,w = Ci,w * n *55.5 / CH2O + // mi,s = Ci,w * (1-n) *55.5 / CH2O + if (cp_vec[idx]->transport_phase == 0) // liquid phase + dval *= unitfactor_l; + else if (cp_vec[idx]->transport_phase == 1) // solid phase + dval *= unitfactor_s; } } *out_buff << "-m " << dval << "\n"; } // time discretization for phreeqc - else if(line_string.find("-steps")!=string::npos) { - if(stepsflag == 0) { // keyword found + else if (line_string.find("-steps") != string::npos) + { + if (stepsflag == 0) + { // keyword found stepsflag++; in.str(line_string); in >> dummy >> dval >> dummy >> this->rcml_number_of_pqcsteps >> dummy; in.clear(); - CTimeDiscretization *m_tim = NULL; - if(time_vector.size()>0) + CTimeDiscretization* m_tim = NULL; + if (time_vector.size() > 0) m_tim = time_vector[0]; else - cout << "Error in WriteInputPhreeqc: no time discretization data !" << "\n"; + cout << "Error in WriteInputPhreeqc: no time discretization data !" + << "\n"; dval = m_tim->CalcTimeStep(); - *out_buff << "-steps " << dval << " in " << this->rcml_number_of_pqcsteps << " steps" << "\n"; + *out_buff << "-steps " << dval << " in " << this->rcml_number_of_pqcsteps << " steps" + << "\n"; } } // end -steps // any other subkeyword - else{ + else + { line_string = line; *out_buff << line_string << "\n"; } } } -//------------------------------------------------------------------------------------------------------------- - // Schleife ueber Keyword RATES - if(line_string.find("RATES")!=string::npos){ - *out_buff << "\n" << "RATES " << index+1 << "\n"; - while(line_string.find("#ende")==string::npos){ - pqc_infile.getline(line,MAX_ZEILE); + //------------------------------------------------------------------------------------------------------------- + // Schleife ueber Keyword RATES + if (line_string.find("RATES") != string::npos) + { + *out_buff << "\n" + << "RATES " << index + 1 << "\n"; + while (line_string.find("#ende") == string::npos) + { + pqc_infile.getline(line, MAX_ZEILE); line_string = line; *out_buff << line_string << "\n"; } } -//------------------------------------------------------------------------------------------------------------- - } /*end while zeilenweises lesen */ + //------------------------------------------------------------------------------------------------------------- + } /*end while zeilenweises lesen */ - *out_buff << "END" << "\n" << "\n"; + *out_buff << "END" + << "\n" + << "\n"; pqc_infile.close(); return 1; } @@ -1073,35 +1155,35 @@ int Call_IPQC(stringstream* out_buff, stringstream* outIPQC) { int returnCode = 1; #ifdef OGS_FEM_IPQC - std::string ipqc_database; //WH: database name for IPQC + std::string ipqc_database; // WH: database name for IPQC ipqc_database = "phreeqc.dat"; int pqcId = CreateIPhreeqc(); // Load phreeqc database, the old one used in the benchmark for calcite dissolution - if(LoadDatabase(pqcId, (FilePath + ipqc_database).c_str()) > 0) + if (LoadDatabase(pqcId, (FilePath + ipqc_database).c_str()) > 0) { OutputErrorString(pqcId); returnCode = 0; } - if(returnCode == 1) + if (returnCode == 1) { SetSelectedOutputStringOn(pqcId, 1); - std::string tmp1 = out_buff->str(); - if (RunString(pqcId,tmp1.c_str()) > 0) + std::string tmp1 = out_buff->str(); + if (RunString(pqcId, tmp1.c_str()) > 0) { OutputErrorString(pqcId); returnCode = 0; } } - if(returnCode == 1) + if (returnCode == 1) { - const char* outtemp = GetSelectedOutputString(pqcId); - *outIPQC << std::string(outtemp) ; + const char* outtemp = GetSelectedOutputString(pqcId); + *outIPQC << std::string(outtemp); } - if(DestroyIPhreeqc(pqcId) != IPQ_OK) + if (DestroyIPhreeqc(pqcId) != IPQ_OK) { OutputErrorString(pqcId); returnCode = 0; @@ -1113,33 +1195,34 @@ int Call_IPQC(stringstream* out_buff, stringstream* outIPQC) return returnCode; } -int REACT::ReadOutputIPQC(std::vector ranknodelist, stringstream* ein, double *m_Conc ) +int REACT::ReadOutputIPQC(std::vector ranknodelist, stringstream* ein, double* m_Conc) { int ok = 0; int ntot; - int index, j, ii, zeilenlaenge=10000, anz, idx; + int index, j, ii, zeilenlaenge = 10000, anz, idx; char str[4000]; double dval, dval1; string speciesname; - int n1, n2, n3, n4, n5, n6, dix=0; + int n1, n2, n3, n4, n5, n6, dix = 0; CTimeDiscretization* m_tim = NULL; double unitfactor_l = 1, unitfactor_s = 1; bool initial = false; - //CB 19.1.2011 + // CB 19.1.2011 // Get the reaction interface data - REACTINT *m_rei = NULL; - if(REACTINT_vec.size()>0) + REACTINT* m_rei = NULL; + if (REACTINT_vec.size() > 0) m_rei = REACTINT_vec[0]; - // Get time step number - // CB dix is no longer required, as we now do all reactions on new TL - // and copy to old TL before first time step - if(time_vector.size()>0){ + // Get time step number + // CB dix is no longer required, as we now do all reactions on new TL + // and copy to old TL before first time step + if (time_vector.size() > 0) + { m_tim = time_vector[0]; - if(m_tim->step_current == 0) // instead, do not update values for solid species in initial pqc computation - initial = true; //dix = -1; + if (m_tim->step_current == 0) // instead, do not update values for solid species in initial pqc computation + initial = true; // dix = -1; } n1 = this->rcml_number_of_master_species; @@ -1148,174 +1231,207 @@ int REACT::ReadOutputIPQC(std::vector ranknodelist, stringstream* ein, doub n4 = this->rcml_number_of_gas_species; n5 = this->rcml_number_of_kinetics; n6 = this->rcml_number_of_secondary_species; - // get total number of species in PHREEQC output file - ntot = rcml_number_of_master_species + 3 + rcml_number_of_equi_phases + rcml_number_of_ion_exchanges + rcml_number_of_gas_species + rcml_number_of_kinetics + rcml_number_of_secondary_species; + // get total number of species in PHREEQC output file + ntot = rcml_number_of_master_species + 3 + rcml_number_of_equi_phases + rcml_number_of_ion_exchanges + + rcml_number_of_gas_species + rcml_number_of_kinetics + rcml_number_of_secondary_species; /* get lines to skip */ - anz = 1; //hard coded by WH - ein -> getline(str,zeilenlaenge); + anz = 1; // hard coded by WH + ein->getline(str, zeilenlaenge); - for (std::size_t nn = 0; nn < ranknodelist.size(); nn++){ - // get start position of concentration vector for this node in Concentration data array + for (std::size_t nn = 0; nn < ranknodelist.size(); nn++) + { + // get start position of concentration vector for this node in Concentration data array index = ranknodelist[nn]; - int position = index*ntot; - // for deactivated nodes, do nothing + int position = index * ntot; + // for deactivated nodes, do nothing if (rateflag[index] == 0) continue; - //CB 19.1.2011 - // calculate unit conversion factors for phreeqc molarity-->molality - if(m_rei) { - if(m_rei->unitconversion){ + // CB 19.1.2011 + // calculate unit conversion factors for phreeqc molarity-->molality + if (m_rei) + { + if (m_rei->unitconversion) + { m_rei->CalcUnitConversionFactors(index, &unitfactor_l, &unitfactor_s, true); } } /* skip one line, if keyword steps larger than 1 even more lines */ - for(j = 0; j < anz; j++) - for(ii = 0; ii < ntot; ii++){ + for (j = 0; j < anz; j++) + for (ii = 0; ii < ntot; ii++) + { *ein >> dval; } /*-----------Read the concentration of all master species and pH pe values-------*/ - for (j = 0; j < n1; j++){ - if(*ein >> dval){ - //CB 19.1.2011 + for (j = 0; j < n1; j++) + { + if (*ein >> dval) + { + // CB 19.1.2011 // convert molality -> molarity - if(m_rei) { - if(m_rei->unitconversion){ + if (m_rei) + { + if (m_rei->unitconversion) + { idx = pcs_vector[pqc_process[j]]->GetProcessComponentNumber(); - if(cp_vec[idx]->transport_phase==0) // liquid phase - dval /= unitfactor_l; - else if(cp_vec[idx]->transport_phase==1){ // solid phase - dval /= unitfactor_s; - cout << " phreeqc concentration " << dval << " " << unitfactor_s << "\n"; + if (cp_vec[idx]->transport_phase == 0) // liquid phase + dval /= unitfactor_l; + else if (cp_vec[idx]->transport_phase == 1) + { // solid phase + dval /= unitfactor_s; + cout << " phreeqc concentration " << dval << " " << unitfactor_s << "\n"; } } } - //pcs_vector[pqc_process[j]]->SetNodeValue(index,pqc_index[j]+dix,dval); + // pcs_vector[pqc_process[j]]->SetNodeValue(index,pqc_index[j]+dix,dval); m_Conc[position + j] = dval; } } - /* Read pH and pe */ - if(*ein >> dval){ // read pH - j = n1; - m_Conc[position + j] = dval; - } - if(*ein >> dval) { // read H+ - j++; - //CB 19.1.2011 - // convert molality -> molarity - if(m_rei) - if(m_rei->unitconversion) - dval /= unitfactor_l; // H+ mol/kg --> mol/m³l - if(this->gamma_Hplus > 0){ - m_Conc[position + j] = dval; - } - } - if(*ein >> dval) { // read pe - j++; - m_Conc[position + j] = dval; - } - /*--------------------Read the concentration of all equilibrium phases -------*/ - for (j = n1 + 3; j < n1 + 3 + n2; j++){ - if(*ein >> dval){ - //CB 19.1.2011 - // convert molality -> molarity, equilibrium species = solid phase species - if(m_rei){ - if(m_rei->unitconversion){ - idx = pcs_vector[pqc_process[j]]->GetProcessComponentNumber(); - //mi,w = Ci,w * n *55.5 / CH2O - //mi,s = Ci,w * (1-n) *55.5 / CH2O - if(cp_vec[idx]->transport_phase==0) // liquid phase - dval /= unitfactor_l; - else if(cp_vec[idx]->transport_phase==1) // solid phase - dval /= unitfactor_s; - } - } - if(initial==false){ + /* Read pH and pe */ + if (*ein >> dval) + { // read pH + j = n1; + m_Conc[position + j] = dval; + } + if (*ein >> dval) + { // read H+ + j++; + // CB 19.1.2011 + // convert molality -> molarity + if (m_rei) + if (m_rei->unitconversion) + dval /= unitfactor_l; // H+ mol/kg --> mol/m³l + if (this->gamma_Hplus > 0) + { m_Conc[position + j] = dval; } } - } - - /*--------------------Read the concentration of all ion exchangers -------*/ - for (j = n1 + 3 + n2; j < n1 + 3 + n2 + n3; j++){ - if(*ein >> dval) - if(initial==false) - m_Conc[position + j] = dval; - } - /*--------------------Read the concentration of all gas phase species -------*/ - for (j=n1+3+n2+n3; j> dval){ - //CB 19.1.2011 - // we should probably do something about gas species concentration unit conversion... - // pcs_vector[pqc_process[j]]->SetNodeValue(index,pqc_index[j]+dix,dval); + if (*ein >> dval) + { // read pe + j++; m_Conc[position + j] = dval; } - } - /*--------------------Read the concentration of all (exclusively) kinetic species -------*/ - for (j=n1+3+n2+n3+n4; j> dval){ - //CB 19.1.2011 - // convert molality -> molarity - if(m_rei) { - if(m_rei->unitconversion){ - idx = pcs_vector[pqc_process[j]]->GetProcessComponentNumber(); - //m_Conc[position + j] = dval; - //mi,w = Ci,w * n *55.5 / CH2O - //mi,s = Ci,w * (1-n) *55.5 / CH2O - if(cp_vec[idx]->transport_phase==0) // liquid phase - dval /= unitfactor_l; - else if(cp_vec[idx]->transport_phase==1) // solid phase - dval /= unitfactor_s; + /*--------------------Read the concentration of all equilibrium phases -------*/ + for (j = n1 + 3; j < n1 + 3 + n2; j++) + { + if (*ein >> dval) + { + // CB 19.1.2011 + // convert molality -> molarity, equilibrium species = solid phase species + if (m_rei) + { + if (m_rei->unitconversion) + { + idx = pcs_vector[pqc_process[j]]->GetProcessComponentNumber(); + // mi,w = Ci,w * n *55.5 / CH2O + // mi,s = Ci,w * (1-n) *55.5 / CH2O + if (cp_vec[idx]->transport_phase == 0) // liquid phase + dval /= unitfactor_l; + else if (cp_vec[idx]->transport_phase == 1) // solid phase + dval /= unitfactor_s; + } + } + if (initial == false) + { + m_Conc[position + j] = dval; } } - if(initial==false) - m_Conc[position + j] = dval; } - } - /*--------------------Read the concentration of all (additional) secondary species -------*/ - for (j=n1+3+n2+n3+n4+n5; j> dval){ - //CB 19.1.2011 - // convert molality -> molarity - if((additional_punches[j-(n1+3+n2+n3+n4+n5)].find(" MOL")!=string::npos) || - (additional_punches[j-(n1+3+n2+n3+n4+n5)].find(" ACT")!=string::npos)){ - if(m_rei) { - if(m_rei->unitconversion){ + /*--------------------Read the concentration of all ion exchangers -------*/ + for (j = n1 + 3 + n2; j < n1 + 3 + n2 + n3; j++) + { + if (*ein >> dval) + if (initial == false) + m_Conc[position + j] = dval; + } + /*--------------------Read the concentration of all gas phase species -------*/ + for (j = n1 + 3 + n2 + n3; j < n1 + 3 + n2 + n3 + n4; j++) + { + if (*ein >> dval) + { + // CB 19.1.2011 + // we should probably do something about gas species concentration unit conversion... + // pcs_vector[pqc_process[j]]->SetNodeValue(index,pqc_index[j]+dix,dval); + m_Conc[position + j] = dval; + } + } + /*--------------------Read the concentration of all (exclusively) kinetic species -------*/ + for (j = n1 + 3 + n2 + n3 + n4; j < n1 + 3 + n2 + n3 + n4 + n5; j++) + { + if (*ein >> dval) + { + // CB 19.1.2011 + // convert molality -> molarity + if (m_rei) + { + if (m_rei->unitconversion) + { idx = pcs_vector[pqc_process[j]]->GetProcessComponentNumber(); - //m_Conc[position + j] = dval; - //mi,w = Ci,w * n *55.5 / CH2O - //mi,s = Ci,w * (1-n) *55.5 / CH2O - if(cp_vec[idx]->transport_phase==0) // liquid phase - dval /= unitfactor_l; - else if(cp_vec[idx]->transport_phase==1) // solid phase - dval /= unitfactor_s; + // m_Conc[position + j] = dval; + // mi,w = Ci,w * n *55.5 / CH2O + // mi,s = Ci,w * (1-n) *55.5 / CH2O + if (cp_vec[idx]->transport_phase == 0) // liquid phase + dval /= unitfactor_l; + else if (cp_vec[idx]->transport_phase == 1) // solid phase + dval /= unitfactor_s; } } + if (initial == false) + m_Conc[position + j] = dval; } - if(initial==false) - m_Conc[position + j] = dval; } - } - // Determine new gamma_Hplus - if (gamma_Hplus > 0){ - //CB 19.1.2011 - // Calculate new gamma_Hplus - // node value is in units of molarity: mol/m³ - dval = pcs_vector[pqc_process[n1+1]]->GetNodeValue(index,pqc_index[n1+1]+dix); // molarity H+ - if(m_rei) - if(m_rei->unitconversion){ - dval *= unitfactor_l; // mol/m³l --> mol/kg H2o - dval1 = m_Conc[position + n1]; - dval1 = pow(10.0,-dval1); // activity H+ from pH - this->gamma_Hplus = dval1/dval; + /*--------------------Read the concentration of all (additional) secondary species -------*/ + for (j = n1 + 3 + n2 + n3 + n4 + n5; j < n1 + 3 + n2 + n3 + n4 + n5 + n6; j++) + { + if (*ein >> dval) + { + // CB 19.1.2011 + // convert molality -> molarity + if ((additional_punches[j - (n1 + 3 + n2 + n3 + n4 + n5)].find(" MOL") != string::npos) + || (additional_punches[j - (n1 + 3 + n2 + n3 + n4 + n5)].find(" ACT") != string::npos)) + { + if (m_rei) + { + if (m_rei->unitconversion) + { + idx = pcs_vector[pqc_process[j]]->GetProcessComponentNumber(); + // m_Conc[position + j] = dval; + // mi,w = Ci,w * n *55.5 / CH2O + // mi,s = Ci,w * (1-n) *55.5 / CH2O + if (cp_vec[idx]->transport_phase == 0) // liquid phase + dval /= unitfactor_l; + else if (cp_vec[idx]->transport_phase == 1) // solid phase + dval /= unitfactor_s; + } + } + } + if (initial == false) + m_Conc[position + j] = dval; } - } // end for(index... + } + + // Determine new gamma_Hplus + if (gamma_Hplus > 0) + { + // CB 19.1.2011 + // Calculate new gamma_Hplus + // node value is in units of molarity: mol/m³ + dval = pcs_vector[pqc_process[n1 + 1]]->GetNodeValue(index, pqc_index[n1 + 1] + dix); // molarity H+ + if (m_rei) + if (m_rei->unitconversion) + { + dval *= unitfactor_l; // mol/m³l --> mol/kg H2o + dval1 = m_Conc[position + n1]; + dval1 = pow(10.0, -dval1); // activity H+ from pH + this->gamma_Hplus = dval1 / dval; + } + } // end for(index... } ok = 1; - ein -> clear(); + ein->clear(); return ok; } @@ -1333,19 +1449,19 @@ REACT::REACT(void) nodenumber = 0; flag_pqc = false; this->check_no_reaction_nodes = false; - file_name_database = ""; + file_name_database = ""; rcml_number_of_master_species = 0; rcml_number_of_equi_phases = 0; rcml_number_of_ion_exchanges = 0; rcml_number_of_gas_species = 0; rcml_number_of_kinetics = 0; - rcml_number_of_secondary_species=0; + rcml_number_of_secondary_species = 0; rcml_pH_flag = 1; rcml_pe_flag = 1; rcml_heat_flag = 0; rcml_pH_charge = 0; - rcml_number_of_pqcsteps = 1; //standard = 1; + rcml_number_of_pqcsteps = 1; // standard = 1; outfile = NULL; outfile_name = "phinp.dat"; results_file_name = "phout_sel.dat"; @@ -1372,12 +1488,12 @@ void REACT::CreateREACT(void) { int np = 0; - //rc = new REACT; - size_t vector_size (pcs_vector.size()); + // rc = new REACT; + size_t vector_size(pcs_vector.size()); for (size_t i = 0; i < vector_size; i++) { // CRFProcess *m_pcs = pcs_vector[i]; - const FiniteElement::ProcessType pcs_type (pcs_vector[i]->getProcessType()); + const FiniteElement::ProcessType pcs_type(pcs_vector[i]->getProcessType()); // if (m_pcs->pcs_type_name.compare("MASS_TRANSPORT") == 0) if (pcs_type == FiniteElement::MASS_TRANSPORT) np++; @@ -1385,30 +1501,30 @@ void REACT::CreateREACT(void) if (pcs_type == FiniteElement::HEAT_TRANSPORT) heatflag = 1; nodenumber = pcs_vector[i]->m_msh->GetNodesNumber(false); - elenumber = (long) pcs_vector[i]->m_msh->ele_vector.size(); + elenumber = (long)pcs_vector[i]->m_msh->ele_vector.size(); #ifdef REACTION_ELEMENT - //MX 06/2006 + // MX 06/2006 if (nodenumber < elenumber) nodenumber = elenumber; #endif } number_of_comp = np; - np = np + heatflag; // allocate one for temperature + np = np + heatflag; // allocate one for temperature // allocate memory for the concentration arrays - name = (const char**) Malloc(sizeof(char*) * np); - val_in = (double**) Malloc(sizeof(double*) * np); - val_out = (double**) Malloc(sizeof(double*) * np); - rate = (double**) Malloc(sizeof(double*) * np); - rateflag = (int*) Malloc(sizeof(int) * nodenumber); + name = (const char**)Malloc(sizeof(char*) * np); + val_in = (double**)Malloc(sizeof(double*) * np); + val_out = (double**)Malloc(sizeof(double*) * np); + rate = (double**)Malloc(sizeof(double*) * np); + rateflag = (int*)Malloc(sizeof(int) * nodenumber); for (int comp = 0; comp < np; comp++) { - val_in[comp] = (double*) Malloc(sizeof(double) * nodenumber); - val_out[comp] = (double*) Malloc(sizeof(double) * nodenumber); - rate[comp] = (double*) Malloc(sizeof(double) * nodenumber); - name[comp] = (char*) Malloc(sizeof(char) * 80); + val_in[comp] = (double*)Malloc(sizeof(double) * nodenumber); + val_out[comp] = (double*)Malloc(sizeof(double) * nodenumber); + rate[comp] = (double*)Malloc(sizeof(double) * nodenumber); + name[comp] = (char*)Malloc(sizeof(char) * 80); } // REACT_vec.push_back(rc); @@ -1428,14 +1544,14 @@ void DestroyREACT(void) REACT* rc = NULL; rc = rc->GetREACT(); /* Free memeory for concentration arrays */ - if(rc != NULL) + if (rc != NULL) { - rc->val_in = (double**)Free(rc->val_in); - rc->val_out = (double**)Free(rc->val_in); - rc->rate = (double**)Free(rc->val_in); - rc->name = (const char**) Free(rc->name); - rc->rateflag = (int*) Free(rc->rateflag); - rc = (REACT*) Free(rc); + rc->val_in = (double**)Free(rc->val_in); + rc->val_out = (double**)Free(rc->val_in); + rc->rate = (double**)Free(rc->val_in); + rc->name = (const char**)Free(rc->name); + rc->rateflag = (int*)Free(rc->rateflag); + rc = (REACT*)Free(rc); } } @@ -1454,40 +1570,34 @@ void REACT::InitREACT(void) int comp; long i; CRFProcess* m_pcs = NULL; - int timelevel = 1; // concentrations are in new timelevel + int timelevel = 1; // concentrations are in new timelevel // int phase = 0; //single phase so far // TF not used /* Initialize arrays of concentrations and array for reaction rates */ - size_t np (pcs_vector.size()); - for (size_t j = 0; j < np; j++) // for all processes + size_t np(pcs_vector.size()); + for (size_t j = 0; j < np; j++) // for all processes { m_pcs = pcs_vector[j]; // if (m_pcs->pcs_type_name.compare("MASS_TRANSPORT") == 0) { // if it is a mass transport process // if it is a mass transport process - if (m_pcs->getProcessType () == FiniteElement::MASS_TRANSPORT) + if (m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) { comp = m_pcs->pcs_component_number; // get component number - // get component name - this->name[comp] = (char*) cp_vec[comp]->compname.data(); + // get component name + this->name[comp] = (char*)cp_vec[comp]->compname.data(); for (i = 0; i < this->nodenumber; i++) { // get concentration values - this->val_in[comp][i] = m_pcs->GetNodeValue( - i, - m_pcs-> - GetNodeValueIndex( - m_pcs-> - pcs_primary_function_name[0]) - + timelevel); - if ((this->val_in[comp][i] < 0.0) && (strcmp(this->name[comp], - "pe") != 0)) //MX, 01.2005 + this->val_in[comp][i] + = m_pcs->GetNodeValue(i, m_pcs->GetNodeValueIndex(m_pcs->pcs_primary_function_name[0]) + timelevel); + if ((this->val_in[comp][i] < 0.0) && (strcmp(this->name[comp], "pe") != 0)) // MX, 01.2005 { if (abs(this->val_in[comp][i]) > MKleinsteZahl) { DisplayMsg(" Neg. conc for component "); - DisplayLong((long) comp); + DisplayLong((long)comp); DisplayMsg(" at node "); - DisplayLong((long) i); + DisplayLong((long)i); DisplayMsg("; conc = "); DisplayDouble(this->val_in[comp][i], 0, 0); DisplayMsgLn(" "); @@ -1507,11 +1617,11 @@ void REACT::InitREACT(void) // Get Temperature values if (this->heatflag > 0) { - this->name[np - 2] = "temp"; //MX CMCD + this->name[np - 2] = "temp"; // MX CMCD m_pcs = PCSGet("HEAT_TRANSPORT"); int index = m_pcs->GetNodeValueIndex("TEMPERATURE1"); for (i = 0; i < this->nodenumber; i++) - //OK PCSGetNODTemperature1L(i)//MX CMCD -2, Liquid Flow, Heat Transport + // OK PCSGetNODTemperature1L(i)//MX CMCD -2, Liquid Flow, Heat Transport this->val_in[np - 2][i] = m_pcs->GetNodeValue(i, index); } } @@ -1532,20 +1642,20 @@ void REACT::InitREACT0() CRFProcess* pcs = NULL; CInitialCondition* ic = NULL; - int timelevel = 1; // concentrations are in new timelevel + int timelevel = 1; // concentrations are in new timelevel // int phase = 0; //single phase so far /* Initialize arrays of concentrations and array for reaction rates */ - size_t np (pcs_vector.size()); - for (size_t j = 0; j < np; j++) // for all processes + size_t np(pcs_vector.size()); + for (size_t j = 0; j < np; j++) // for all processes { pcs = pcs_vector[j]; // if (pcs->pcs_type_name.compare("MASS_TRANSPORT") == 0) { // if it is a mass transport process - if (pcs->getProcessType () == FiniteElement::MASS_TRANSPORT) + if (pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) { int comp = pcs->pcs_component_number; // get component number - // get component name - this->name[comp] = (char*) cp_vec[comp]->compname.data(); + // get component name + this->name[comp] = (char*)cp_vec[comp]->compname.data(); if (comp >= 0 && (cp_vec[comp]->mobil > 0)) pcs->InterpolateTempGP(pcs, this->name[comp]); @@ -1554,34 +1664,27 @@ void REACT::InitREACT0() { ic = ic_vector[j]; ic->setProcess(pcs); - if (ic->getProcessPrimaryVariable() - == FiniteElement::convertPrimaryVariable(this->name[comp])) + if (ic->getProcessPrimaryVariable() == FiniteElement::convertPrimaryVariable(this->name[comp])) { int nidxe = pcs->GetElementValueIndex(this->name[comp]); - ic->SetEle(nidxe); //set IC to elements for reactions //MX 06/2006 + ic->SetEle(nidxe); // set IC to elements for reactions //MX 06/2006 ic->SetEle(nidxe + 1); - } //for + } // for } for (i = 0; i < this->elenumber; i++) { // get concentration values - this->val_in[comp][i] = pcs->GetElementValue( - i, - pcs-> - GetElementValueIndex( - pcs-> - pcs_primary_function_name[0]) - + timelevel); - if ((this->val_in[comp][i] < 0.0) && (strcmp(this->name[comp], - "pe") != 0)) //MX, 01.2005 + this->val_in[comp][i] + = pcs->GetElementValue(i, pcs->GetElementValueIndex(pcs->pcs_primary_function_name[0]) + timelevel); + if ((this->val_in[comp][i] < 0.0) && (strcmp(this->name[comp], "pe") != 0)) // MX, 01.2005 { if (abs(this->val_in[comp][i]) > MKleinsteZahl) { DisplayMsg(" Neg. conc for component "); - DisplayLong((long) comp); + DisplayLong((long)comp); DisplayMsg(" at node "); - DisplayLong((long) i); + DisplayLong((long)i); DisplayMsg("; conc = "); DisplayDouble(this->val_in[comp][i], 0, 0); DisplayMsgLn(" "); @@ -1610,7 +1713,7 @@ void REACT::InitREACT0() } } -//MX +// MX void CRFProcess::InterpolateTempGP(CRFProcess* m_pcs, std::string name) { MshElemType::type EleType; @@ -1620,12 +1723,12 @@ void CRFProcess::InterpolateTempGP(CRFProcess* m_pcs, std::string name) double T_ele; double GP[3]; static double Node_T[8]; - int index1; //idxp,idxcp,idxS; + int index1; // idxp,idxcp,idxS; CMediumProperties* m_mmp = NULL; MeshLib::CElem* elem = NULL; index1 = m_pcs->GetElementValueIndex(name) + 1; //->fem->interpolate( - for (i = 0; i < (long) m_pcs->m_msh->ele_vector.size(); i++) + for (i = 0; i < (long)m_pcs->m_msh->ele_vector.size(); i++) { elem = m_pcs->m_msh->ele_vector[i]; m_pcs->GetAssembler(); @@ -1633,14 +1736,14 @@ void CRFProcess::InterpolateTempGP(CRFProcess* m_pcs, std::string name) // Activated Element group = elem->GetPatchIndex(); m_mmp = mmp_vector[group]; - m_mmp->m_pcs = m_pcs; //m_pcs_mmp + m_mmp->m_pcs = m_pcs; // m_pcs_mmp EleType = elem->GetElementType(); - if(EleType == MshElemType::TRIANGLE) // Traingle + if (EleType == MshElemType::TRIANGLE) // Traingle { GP[0] = GP[1] = 0.1 / 0.3; GP[2] = 0.0; } - else if(EleType == MshElemType::TETRAHEDRON) + else if (EleType == MshElemType::TETRAHEDRON) GP[0] = GP[1] = GP[2] = 0.25; else GP[0] = GP[1] = GP[2] = 0.0; @@ -1648,19 +1751,19 @@ void CRFProcess::InterpolateTempGP(CRFProcess* m_pcs, std::string name) m_pcs->fem->ConfigElement(elem, m_num->ele_gauss_points); m_pcs->fem->setUnitCoordinates(GP); m_pcs->fem->ComputeShapefct(1); // Linear - for(j = 0; j < elem->GetVertexNumber(); j++) + for (j = 0; j < elem->GetVertexNumber(); j++) { enode = elem->GetNodeIndex(j); - //m_pcs_mmp - Node_T[j] = m_pcs->GetNodeValue(enode,m_pcs->GetNodeValueIndex(name) + 1); + // m_pcs_mmp + Node_T[j] = m_pcs->GetNodeValue(enode, m_pcs->GetNodeValueIndex(name) + 1); } T_ele = fem->interpolate(Node_T); - m_pcs->SetElementValue(i,index1,T_ele); - m_pcs->SetElementValue(i,index1 - 1,T_ele); + m_pcs->SetElementValue(i, index1, T_ele); + m_pcs->SetElementValue(i, index1 - 1, T_ele); } } -//MX +// MX void CRFProcess::ExtropolateTempGP(CRFProcess* m_pcs, std::string name) { MshElemType::type EleType; @@ -1671,7 +1774,7 @@ void CRFProcess::ExtropolateTempGP(CRFProcess* m_pcs, std::string name) double GP[3]; static double Node_T[8]; double T_sum = 0.0; - int index1, index_nod; //idxp,idxcp,idxS; + int index1, index_nod; // idxp,idxcp,idxS; CMediumProperties* m_mmp = NULL; MeshLib::CElem* elem = NULL; @@ -1679,7 +1782,7 @@ void CRFProcess::ExtropolateTempGP(CRFProcess* m_pcs, std::string name) index_nod = m_pcs->GetNodeValueIndex(name) + 1; for (i = 0; i < m_msh->GetNodesNumber(false); i++) - SetNodeValue(i,index_nod, 0.0); + SetNodeValue(i, index_nod, 0.0); for (i = 0; i < m_pcs->m_msh->ele_vector.size(); i++) { @@ -1689,14 +1792,14 @@ void CRFProcess::ExtropolateTempGP(CRFProcess* m_pcs, std::string name) // Activated Element group = elem->GetPatchIndex(); m_mmp = mmp_vector[group]; - m_mmp->m_pcs = m_pcs; //m_pcs_mmp + m_mmp->m_pcs = m_pcs; // m_pcs_mmp EleType = elem->GetElementType(); - if(EleType == MshElemType::TRIANGLE) // Traingle + if (EleType == MshElemType::TRIANGLE) // Traingle { GP[0] = GP[1] = 0.1 / 0.3; GP[2] = 0.0; } - else if(EleType == MshElemType::TETRAHEDRON) + else if (EleType == MshElemType::TETRAHEDRON) GP[0] = GP[1] = GP[2] = 0.25; else GP[0] = GP[1] = GP[2] = 0.0; @@ -1704,24 +1807,24 @@ void CRFProcess::ExtropolateTempGP(CRFProcess* m_pcs, std::string name) m_pcs->fem->ConfigElement(elem, m_pcs->m_num->ele_gauss_points); m_pcs->fem->setUnitCoordinates(GP); m_pcs->fem->ComputeShapefct(1); // Linear - for(j = 0; j < elem->GetVertexNumber(); j++) + for (j = 0; j < elem->GetVertexNumber(); j++) { enode = elem->GetNodeIndex(j); - Node_T[j] = m_pcs->GetElementValue(i,index1); + Node_T[j] = m_pcs->GetElementValue(i, index1); T_sum = m_pcs->GetNodeValue(enode, index_nod); - m_pcs->SetNodeValue(enode,index_nod, T_sum + Node_T[j]); + m_pcs->SetNodeValue(enode, index_nod, T_sum + Node_T[j]); } - } //for + } // for // Average for (i = 0; i < m_msh->GetNodesNumber(false); i++) { T_sum = m_pcs->GetNodeValue(i, index_nod); - nn = (int) m_msh->nod_vector[i]->getConnectedElementIDs().size(); - if(nn == 0) + nn = (int)m_msh->nod_vector[i]->getConnectedElementIDs().size(); + if (nn == 0) nn = 1; T_sum /= (double)nn; - m_pcs->SetNodeValue(i,index_nod, T_sum); + m_pcs->SetNodeValue(i, index_nod, T_sum); } } @@ -1739,37 +1842,31 @@ void REACT::CalculateReactionRates(void) /* Calculate Rates */ int comp, i; - //WW double teta, help=0.0, maxi, dc, delta_t; + // WW double teta, help=0.0, maxi, dc, delta_t; double teta, help = 0.0, maxi, delta_t; CTimeDiscretization* m_tim = NULL; - if(time_vector.size() > 0) + if (time_vector.size() > 0) m_tim = time_vector[0]; else - std::cout << - "Error in MPCCalcCharacteristicNumbers: no time discretization data !" << "\n"; + std::cout << "Error in MPCCalcCharacteristicNumbers: no time discretization data !" + << "\n"; delta_t = m_tim->CalcTimeStep(); - //OK_TIM delta_t = GetDt(aktueller_zeitschritt-1l); - teta = 0.0; /* teta = 0; concentration before reactions */ - for(comp = 0; comp < this->number_of_comp; comp++) + // OK_TIM delta_t = GetDt(aktueller_zeitschritt-1l); + teta = 0.0; /* teta = 0; concentration before reactions */ + for (comp = 0; comp < this->number_of_comp; comp++) { maxi = 0.0; - for(i = 0; i < this->nodenumber; i++) + for (i = 0; i < this->nodenumber; i++) { maxi = max(maxi, this->val_out[comp][i]); - this->rate[comp][i] = - (this->val_out[comp][i] - this->val_in[comp][i]) / delta_t; + this->rate[comp][i] = (this->val_out[comp][i] - this->val_in[comp][i]) / delta_t; - help = - (teta * this->val_out[comp][i] + - (1.0 - teta) * this->val_in[comp][i]); - if(help < MKleinsteZahl) // umgekehrt wichten + help = (teta * this->val_out[comp][i] + (1.0 - teta) * this->val_in[comp][i]); + if (help < MKleinsteZahl) // umgekehrt wichten { - help = - (1.0 - - teta) * this->val_out[comp][i] + teta * - this->val_in[comp][i]; - if(help < MKleinsteZahl) + help = (1.0 - teta) * this->val_out[comp][i] + teta * this->val_in[comp][i]; + if (help < MKleinsteZahl) this->rate[comp][i] = 0.0; else this->rate[comp][i] = this->rate[comp][i] / help; @@ -1789,7 +1886,7 @@ void REACT::CalculateReactionRates(void) //SB:todo MTM2SetElementDamkohlerNumNew(i,0,comp,dc); } */ - } /* end for(comp=... */ + } /* end for(comp=... */ } /************************************************************************** @@ -1804,16 +1901,16 @@ void REACT::CalculateReactionRates(void) void REACT::SetConcentrationResults(void) { /* */ - int comp, idx; //WW, timelevel, np; + int comp, idx; // WW, timelevel, np; long i; string name; CRFProcess* m_pcs = NULL; - //Fix Process here ?? - //Rücksrache mit Sebastian + // Fix Process here ?? + // Rücksrache mit Sebastian - //WW timelevel = 1; // concentrations are in new timelevel - //WW np = (int)pcs_vector.size(); + // WW timelevel = 1; // concentrations are in new timelevel + // WW np = (int)pcs_vector.size(); /* SB4218 for(comp=0; compnumber_of_comp;comp++){ for(i=0;inodenumber;i++){ @@ -1823,14 +1920,14 @@ void REACT::SetConcentrationResults(void) } } */ - for(comp = 0; comp < this->number_of_comp; comp++) + for (comp = 0; comp < this->number_of_comp; comp++) { name = this->name[comp]; - // m_pcs = PCSGet("MASS_TRANSPORT",name); //??? // CB HS update - m_pcs = cp_vec[cp_name_2_idx[name]]->getProcess(); + // m_pcs = PCSGet("MASS_TRANSPORT",name); //??? // CB HS update + m_pcs = cp_vec[cp_name_2_idx[name]]->getProcess(); idx = m_pcs->GetNodeValueIndex(name) + 1; - for(i = 0; i < this->nodenumber; i++) - m_pcs->SetNodeValue(i, idx,this->val_out[comp][i]); + for (i = 0; i < this->nodenumber; i++) + m_pcs->SetNodeValue(i, idx, this->val_out[comp][i]); } } @@ -1845,25 +1942,25 @@ void REACT::SetConcentrationResults(void) **************************************************************************/ void REACT::SetConcentrationResultsEle(void) { - int comp,idx; //WW, timelevel, np,; + int comp, idx; // WW, timelevel, np,; long i; string name; CRFProcess* m_pcs = NULL; - //WW timelevel = 1; // concentrations are in new timelevel - //WW np = (int)pcs_vector.size(); + // WW timelevel = 1; // concentrations are in new timelevel + // WW np = (int)pcs_vector.size(); - for(comp = 0; comp < this->number_of_comp; comp++) + for (comp = 0; comp < this->number_of_comp; comp++) { name = this->name[comp]; - //m_pcs = PCSGet("MASS_TRANSPORT",name); //???// CB HS update - m_pcs = cp_vec[cp_name_2_idx[name]]->getProcess(); + // m_pcs = PCSGet("MASS_TRANSPORT",name); //???// CB HS update + m_pcs = cp_vec[cp_name_2_idx[name]]->getProcess(); idx = m_pcs->GetElementValueIndex(name) + 1; - for(i = 0; i < this->elenumber; i++) - m_pcs->SetElementValue(i, idx,this->val_out[comp][i]); + for (i = 0; i < this->elenumber; i++) + m_pcs->SetElementValue(i, idx, this->val_out[comp][i]); - //Extropolate element data (center) to nodes + // Extropolate element data (center) to nodes if (CPGetMobil(m_pcs->GetProcessComponentNumber()) >= 0) m_pcs->ExtropolateTempGP(m_pcs, name); } @@ -1873,7 +1970,7 @@ REACT* REACT::GetREACT(void) { REACT* rc = NULL; /* Tests */ - if(REACT_vec.capacity() > 0) + if (REACT_vec.capacity() > 0) rc = REACT_vec[0]; return rc; } @@ -1900,10 +1997,10 @@ int REACT::ReadReactionModel(FILE* File) int n_master_species = 0; int n_equi_phases = 0; int n_ion_exchange = 0, p = 0; - //WW int beginn = 0, p = 0; - //WW int pos; + // WW int beginn = 0, p = 0; + // WW int pos; int nj; - char str[256], * sub, * sub1; + char str[256], *sub, *sub1; FILE* indatei = NULL; indatei = File; @@ -1911,22 +2008,21 @@ int REACT::ReadReactionModel(FILE* File) CRFProcess* m_pcs = NULL; /* Open input file and read the reaction model values*/ - if (indatei == NULL) /*input dateien does not exist*/ + if (indatei == NULL) /*input dateien does not exist*/ { DisplayMsgLn(""); DisplayMsgLn(" The input file *.pqc does not exist!!!"); exit(1); - } /*end if*/ + } /*end if*/ /* zeilenweise lesen */ while (fgets(str, 256, indatei)) { /* Schleife ueber Keyword Solution */ - //WW pos = 0; - //WW beginn = 1; + // WW pos = 0; + // WW beginn = 1; p = 0; - while ((!strstr(str, "END")) && (!strstr(str, "#ende")) - && StringReadStr(&sub, str, &p)) + while ((!strstr(str, "END")) && (!strstr(str, "#ende")) && StringReadStr(&sub, str, &p)) { if (strcmp(sub, "SOLUTION") == 0) { @@ -1935,18 +2031,18 @@ int REACT::ReadReactionModel(FILE* File) if (strstr(str, "# comp")) { StringReadStr(&sub, str, &p); - if (!strcmp(sub, - "pH") == 0 && !strcmp(sub, "pe") == 0) + if (!strcmp(sub, "pH") == 0 && !strcmp(sub, "pe") == 0) n_master_species += 1; } if (strstr(str, "# temp")) { - size_t no_processes (pcs_vector.size()); + size_t no_processes(pcs_vector.size()); for (size_t i = 0; i < no_processes; i++) { m_pcs = pcs_vector[i]; - // if (m_pcs->pcs_type_name.find("HEAT_TRANSPORT") != string::npos) { - if (m_pcs->getProcessType () == FiniteElement::HEAT_TRANSPORT) + // if (m_pcs->pcs_type_name.find("HEAT_TRANSPORT") != string::npos) + //{ + if (m_pcs->getProcessType() == FiniteElement::HEAT_TRANSPORT) { // if(GetRFProcessProcessingAndActivation("HT")) this->rcml_heat_flag = 1; @@ -1966,7 +2062,7 @@ int REACT::ReadReactionModel(FILE* File) n_equi_phases += 1; } this->rcml_number_of_equi_phases = n_equi_phases; - } /*end if*/ + } /*end if*/ else if (strcmp(sub, "EXCHANGE") == 0) { while (fgets(str, 256, indatei) && (!strstr(str, "#ende"))) @@ -1976,8 +2072,8 @@ int REACT::ReadReactionModel(FILE* File) n_ion_exchange += 1; } this->rcml_number_of_ion_exchanges = n_ion_exchange; - } /*end if*/ - //SB:neu + } /*end if*/ + // SB:neu else if (strcmp(sub, "SELECTED_OUTPUT") == 0) { while (fgets(str, 256, indatei) && (!strstr(str, "#ende"))) @@ -1999,13 +2095,11 @@ int REACT::ReadReactionModel(FILE* File) break; // return 1; } - } /*end while 2*/ - } /*end while 1*/ - nj = rcml_number_of_master_species + rcml_number_of_equi_phases - + rcml_number_of_ion_exchanges; + } /*end while 2*/ + } /*end while 1*/ + nj = rcml_number_of_master_species + rcml_number_of_equi_phases + rcml_number_of_ion_exchanges; if (nj + 2 != this->number_of_comp) - DisplayMsgLn( - "!!!Error:Number of components in file *.pqc is not equal to that in file *.rfd!"); + DisplayMsgLn("!!!Error:Number of components in file *.pqc is not equal to that in file *.rfd!"); // fclose(indatei); // return 0; // fclose(indatei); @@ -2037,69 +2131,67 @@ int REACT::ReadReactionModel(FILE* File) 01/2006 SB Erste Version 10/2010 TF restructured method a little bit, changed access to process type **************************************************************************/ -int REACT::ReadReactionModelNew( ifstream* pqc_infile) +int REACT::ReadReactionModelNew(ifstream* pqc_infile) { int n_master_species = 0; int n_equi_phases = 0; int n_ion_exchange = 0; int n_gas_species = 0; - int n_kin_phases=0; // CB kr - int n_secondary_species=0; //CB krc + int n_kin_phases = 0; // CB kr + int n_secondary_species = 0; // CB krc int idx; - //int nj; - int found=0; + // int nj; + int found = 0; char line[MAX_ZEILE]; string line_string, dummy, speciesname; CRFProcess* m_pcs = NULL; std::stringstream in; - //int pH_found = 0; // Hplus_found = 0, count = -1; + // int pH_found = 0; // Hplus_found = 0, count = -1; /* File handling */ - pqc_infile->seekg(0L,ios::beg); + pqc_infile->seekg(0L, ios::beg); /* zeilenweise lesen */ - while(!pqc_infile->eof()) + while (!pqc_infile->eof()) { - pqc_infile->getline(line,MAX_ZEILE); + pqc_infile->getline(line, MAX_ZEILE); line_string = line; - if(line_string.find("#STOP") != string::npos) + if (line_string.find("#STOP") != string::npos) break; - /* Schleife ueber Keyword DATABASE */ - if(line_string.find("DATABASE")!=string::npos) - { - // the database name is listed on the same line as the DATABASE keyword - in.str(line_string); - in >> dummy >> this->file_name_database; - while(line_string.find("#ende")==string::npos) - { - pqc_infile->getline(line,MAX_ZEILE); - line_string = line; - } - } + /* Schleife ueber Keyword DATABASE */ + if (line_string.find("DATABASE") != string::npos) + { + // the database name is listed on the same line as the DATABASE keyword + in.str(line_string); + in >> dummy >> this->file_name_database; + while (line_string.find("#ende") == string::npos) + { + pqc_infile->getline(line, MAX_ZEILE); + line_string = line; + } + } /* Schleife ueber Keyword Solution */ // keyword found - if(line_string.find("SOLUTION") != string::npos) + if (line_string.find("SOLUTION") != string::npos) { - while(line_string.find("#ende") == string::npos) + while (line_string.find("#ende") == string::npos) { - pqc_infile->getline(line,MAX_ZEILE); + pqc_infile->getline(line, MAX_ZEILE); line_string = line; if (line_string.find("# comp") != string::npos) { - if (line_string.find("pH") == string::npos && - line_string.find("pe") == string::npos) + if (line_string.find("pH") == string::npos && line_string.find("pe") == string::npos) { n_master_species += 1; // this excludes now pH and pe in.str(line_string); in >> speciesname; - //m_pcs = PCSGet("MASS_TRANSPORT",speciesname);// CB HS update - m_pcs = cp_vec[cp_name_2_idx[speciesname]]->getProcess(); - if(m_pcs == NULL) + // m_pcs = PCSGet("MASS_TRANSPORT",speciesname);// CB HS update + m_pcs = cp_vec[cp_name_2_idx[speciesname]]->getProcess(); + if (m_pcs == NULL) { - cout << - " PHREEQC SOLUTION SPECIES not in GeoSys components - Stopping" + cout << " PHREEQC SOLUTION SPECIES not in GeoSys components - Stopping" << "\n"; cout.flush(); exit(1); @@ -2107,7 +2199,7 @@ int REACT::ReadReactionModelNew( ifstream* pqc_infile) // old timelevel idx = m_pcs->GetNodeValueIndex(speciesname) + 1; in.clear(); - //store species name in vector names + // store species name in vector names pqc_names.push_back(speciesname); // store process name in vector processes pqc_process.push_back(m_pcs->pcs_number); @@ -2115,11 +2207,12 @@ int REACT::ReadReactionModelNew( ifstream* pqc_infile) /* if(speciesname.compare("H+") == 0){ Hplus_found = 1; cout << "H+ found in GeoSys species" << "\n"; - this->pqc_Hplus_index = n_master_species-1; // Store index for H+ in vectors + this->pqc_Hplus_index = n_master_species-1; // Store index for H+ in + vectors } */ } else if (line_string.find("pH") != string::npos) - //WW pH_found = 1; + // WW pH_found = 1; // cout << " pH found in GeoSys species" << "\n"; if (line_string.find("charge") != string::npos) this->rcml_pH_charge = 1; @@ -2127,7 +2220,7 @@ int REACT::ReadReactionModelNew( ifstream* pqc_infile) if (line_string.find("# temp") != string::npos) { // check if heat transport process is calculated in GeoSys - size_t no_processes (pcs_vector.size()); + size_t no_processes(pcs_vector.size()); for (size_t i = 0; i < no_processes; i++) { m_pcs = pcs_vector[i]; @@ -2139,8 +2232,8 @@ int REACT::ReadReactionModelNew( ifstream* pqc_infile) } } } - if(line_string.find("temp") != string::npos) - if(this->rcml_heat_flag < 1) // if no heat transport is calculated + if (line_string.find("temp") != string::npos) + if (this->rcml_heat_flag < 1) // if no heat transport is calculated { in.str(line_string); // save temperature @@ -2152,22 +2245,22 @@ int REACT::ReadReactionModelNew( ifstream* pqc_infile) // Handle pH, H+ and pe speciesname = "pH"; - //m_pcs = PCSGet("MASS_TRANSPORT",speciesname);// CB HS update - m_pcs = cp_vec[cp_name_2_idx[speciesname]]->getProcess(); - // old timelevel + // m_pcs = PCSGet("MASS_TRANSPORT",speciesname);// CB HS update + m_pcs = cp_vec[cp_name_2_idx[speciesname]]->getProcess(); + // old timelevel idx = m_pcs->GetNodeValueIndex(speciesname) + 1; - pqc_names.push_back(speciesname); //store species name in vector names + pqc_names.push_back(speciesname); // store species name in vector names pqc_process.push_back(m_pcs->pcs_number); // store process name in vector processes pqc_index.push_back(idx); // check, if H+ is a GEoSys transport process speciesname = "H+"; - m_pcs = PCSGet("MASS_TRANSPORT",speciesname); - if(m_pcs != NULL) + m_pcs = PCSGet("MASS_TRANSPORT", speciesname); + if (m_pcs != NULL) { // old timelevel idx = m_pcs->GetNodeValueIndex(speciesname) + 1; - pqc_names.push_back(speciesname); //store species name in vector names - // store process name in vector processes + pqc_names.push_back(speciesname); // store species name in vector names + // store process name in vector processes pqc_process.push_back(m_pcs->pcs_number); pqc_index.push_back(idx); this->gamma_Hplus = 1.0; @@ -2181,20 +2274,20 @@ int REACT::ReadReactionModelNew( ifstream* pqc_infile) } // Treat pe speciesname = "pe"; - //m_pcs = PCSGet("MASS_TRANSPORT",speciesname);// CB HS update - m_pcs = cp_vec[cp_name_2_idx[speciesname]]->getProcess(); + // m_pcs = PCSGet("MASS_TRANSPORT",speciesname);// CB HS update + m_pcs = cp_vec[cp_name_2_idx[speciesname]]->getProcess(); idx = m_pcs->GetNodeValueIndex(speciesname) + 1; - pqc_names.push_back(speciesname); //store species name in vector names + pqc_names.push_back(speciesname); // store species name in vector names pqc_process.push_back(m_pcs->pcs_number); // store process name in vector processes pqc_index.push_back(idx); } /* Schleife ueber Keyword EQUILIBRIUM PHASES */ // keyword found - if(line_string.find("EQUILIBRIUM_PHASES") != string::npos) + if (line_string.find("EQUILIBRIUM_PHASES") != string::npos) { - while(line_string.find("#ende") == string::npos) + while (line_string.find("#ende") == string::npos) { - pqc_infile->getline(line,MAX_ZEILE); + pqc_infile->getline(line, MAX_ZEILE); line_string = line; if (line_string.find("# comp") != string::npos) { @@ -2202,11 +2295,11 @@ int REACT::ReadReactionModelNew( ifstream* pqc_infile) in.str(line_string); in >> speciesname; in.clear(); - //m_pcs = PCSGet("MASS_TRANSPORT",speciesname);// CB HS update - m_pcs = cp_vec[cp_name_2_idx[speciesname]]->getProcess(); + // m_pcs = PCSGet("MASS_TRANSPORT",speciesname);// CB HS update + m_pcs = cp_vec[cp_name_2_idx[speciesname]]->getProcess(); idx = m_pcs->GetNodeValueIndex(speciesname) + 1; - pqc_names.push_back(speciesname); //store species name in vector names - // store process name in vector processes + pqc_names.push_back(speciesname); // store species name in vector names + // store process name in vector processes pqc_process.push_back(m_pcs->pcs_number); pqc_index.push_back(idx); } @@ -2216,11 +2309,11 @@ int REACT::ReadReactionModelNew( ifstream* pqc_infile) /* Schleife ueber Keyword EXCHANGE */ // keyword found - if(line_string.find("EXCHANGE") != string::npos) + if (line_string.find("EXCHANGE") != string::npos) { - while(line_string.find("#ende") == string::npos) + while (line_string.find("#ende") == string::npos) { - pqc_infile->getline(line,MAX_ZEILE); + pqc_infile->getline(line, MAX_ZEILE); line_string = line; if (line_string.find("# comp") != string::npos) { @@ -2228,12 +2321,12 @@ int REACT::ReadReactionModelNew( ifstream* pqc_infile) in.str(line_string); in >> speciesname; in.clear(); - //m_pcs = PCSGet("MASS_TRANSPORT",speciesname);// CB HS update - m_pcs = cp_vec[cp_name_2_idx[speciesname]]->getProcess(); - // old timelevel + // m_pcs = PCSGet("MASS_TRANSPORT",speciesname);// CB HS update + m_pcs = cp_vec[cp_name_2_idx[speciesname]]->getProcess(); + // old timelevel idx = m_pcs->GetNodeValueIndex(speciesname) + 1; - pqc_names.push_back(speciesname); //store species name in vector names - // store process name in vector processes + pqc_names.push_back(speciesname); // store species name in vector names + // store process name in vector processes pqc_process.push_back(m_pcs->pcs_number); pqc_index.push_back(idx); } @@ -2242,11 +2335,11 @@ int REACT::ReadReactionModelNew( ifstream* pqc_infile) } /* Scleife über Keyword GAS_PHASE */ // keyword found - if(line_string.find("GAS_PHASE") != string::npos) + if (line_string.find("GAS_PHASE") != string::npos) { - while(line_string.find("#ende") == string::npos) + while (line_string.find("#ende") == string::npos) { - pqc_infile->getline(line,MAX_ZEILE); + pqc_infile->getline(line, MAX_ZEILE); line_string = line; if (line_string.find("# comp") != string::npos) { @@ -2254,99 +2347,108 @@ int REACT::ReadReactionModelNew( ifstream* pqc_infile) in.str(line_string); in >> speciesname; in.clear(); - //m_pcs = PCSGet("MASS_TRANSPORT",speciesname);// CB HS update - m_pcs = cp_vec[cp_name_2_idx[speciesname]]->getProcess(); - // old timelevel + // m_pcs = PCSGet("MASS_TRANSPORT",speciesname);// CB HS update + m_pcs = cp_vec[cp_name_2_idx[speciesname]]->getProcess(); + // old timelevel idx = m_pcs->GetNodeValueIndex(speciesname) + 1; - pqc_names.push_back(speciesname); //store species name in vector names - // store process name in vector processes + pqc_names.push_back(speciesname); // store species name in vector names + // store process name in vector processes pqc_process.push_back(m_pcs->pcs_number); pqc_index.push_back(idx); } } this->rcml_number_of_gas_species = n_gas_species; } - /* Schleife über Keyword KINETICS */ - if(line_string.find("KINETICS")!=string::npos){ - while(line_string.find("#ende")==string::npos){ - pqc_infile->getline(line,MAX_ZEILE); - line_string = line; - if (line_string.find("# comp") !=string::npos){ - in.str(line_string); - in >> speciesname ; - in.clear(); - //m_pcs = PCSGet("MASS_TRANSPORT",speciesname);// CB HS update - m_pcs = cp_vec[cp_name_2_idx[speciesname]]->getProcess(); - idx = m_pcs->GetNodeValueIndex(speciesname)+1; // old timelevel - // now, only store kinetic species if it has not been defined previously as another species type - found = 0; - for(int i=0;ipcs_number); // store process name in vector processes - pqc_index.push_back(idx); - } - } - // This is just to avoid mix-up with subkeyword "-m" - else if(line_string.find("-m0")!=string::npos) { // keyword found - - } - // here get current node concentration after transport - else if(line_string.find("-m")!=string::npos) { // keyword found - - } - // time discretization for phreeqc - else if(line_string.find("-steps")!=string::npos) { // keyword found - - } - // any other subkeyword - else{ - - } - } - this->rcml_number_of_kinetics = n_kin_phases; - } - /* Schleife über Keyword ADDITIONAL_OUTPUT */ - //if(line_string.find("SECONDARY_SPECIES_OUTPUT")!=string::npos) { // keyword found - if(line_string.find("ADDITIONAL_OUTPUT")!=string::npos) { // keyword found - while(line_string.find("#ende")==string::npos){ - in.clear(); - pqc_infile->getline(line,MAX_ZEILE); - line_string = line; - if (line_string.find("# comp") !=string::npos){ - n_secondary_species +=1; - in.str(line_string); - in >> speciesname ; - in.clear(); - //m_pcs = PCSGet("MASS_TRANSPORT",speciesname);// CB HS update - m_pcs = cp_vec[cp_name_2_idx[speciesname]]->getProcess(); - idx = m_pcs->GetNodeValueIndex(speciesname)+1; // old timelevel - pqc_names.push_back(speciesname); //store species name in vector names - pqc_process.push_back(m_pcs->pcs_number); // store process name in vector processes - pqc_index.push_back(idx); - } - } - this->rcml_number_of_secondary_species = n_secondary_species; - } - /* Schleife über Keyword ADDITIONAL_PUNCH */ - if(line_string.find("ADDITIONAL_PUNCH")!=string::npos) { // keyword found - while(line_string.find("#ende")==string::npos){ - in.clear(); - pqc_infile->getline(line,MAX_ZEILE); - line_string = line; - if (line_string.find("#ende") ==string::npos) - additional_punches.push_back(line_string); - } - } + /* Schleife über Keyword KINETICS */ + if (line_string.find("KINETICS") != string::npos) + { + while (line_string.find("#ende") == string::npos) + { + pqc_infile->getline(line, MAX_ZEILE); + line_string = line; + if (line_string.find("# comp") != string::npos) + { + in.str(line_string); + in >> speciesname; + in.clear(); + // m_pcs = PCSGet("MASS_TRANSPORT",speciesname);// CB HS update + m_pcs = cp_vec[cp_name_2_idx[speciesname]]->getProcess(); + idx = m_pcs->GetNodeValueIndex(speciesname) + 1; // old timelevel + // now, only store kinetic species if it has not been defined previously as another species type + found = 0; + for (int i = 0; i < int(pqc_index.size()); i++) + if (speciesname.compare(pqc_names[i]) == 0) + found++; + if (found == 0) + { + n_kin_phases += 1; + pqc_names.push_back(speciesname); // store species name in vector names + pqc_process.push_back(m_pcs->pcs_number); // store process name in vector processes + pqc_index.push_back(idx); + } + } + // This is just to avoid mix-up with subkeyword "-m" + else if (line_string.find("-m0") != string::npos) + { // keyword found + } + // here get current node concentration after transport + else if (line_string.find("-m") != string::npos) + { // keyword found + } + // time discretization for phreeqc + else if (line_string.find("-steps") != string::npos) + { // keyword found + } + // any other subkeyword + else + { + } + } + this->rcml_number_of_kinetics = n_kin_phases; + } + /* Schleife über Keyword ADDITIONAL_OUTPUT */ + // if(line_string.find("SECONDARY_SPECIES_OUTPUT")!=string::npos) { // keyword found + if (line_string.find("ADDITIONAL_OUTPUT") != string::npos) + { // keyword found + while (line_string.find("#ende") == string::npos) + { + in.clear(); + pqc_infile->getline(line, MAX_ZEILE); + line_string = line; + if (line_string.find("# comp") != string::npos) + { + n_secondary_species += 1; + in.str(line_string); + in >> speciesname; + in.clear(); + // m_pcs = PCSGet("MASS_TRANSPORT",speciesname);// CB HS update + m_pcs = cp_vec[cp_name_2_idx[speciesname]]->getProcess(); + idx = m_pcs->GetNodeValueIndex(speciesname) + 1; // old timelevel + pqc_names.push_back(speciesname); // store species name in vector names + pqc_process.push_back(m_pcs->pcs_number); // store process name in vector processes + pqc_index.push_back(idx); + } + } + this->rcml_number_of_secondary_species = n_secondary_species; + } + /* Schleife über Keyword ADDITIONAL_PUNCH */ + if (line_string.find("ADDITIONAL_PUNCH") != string::npos) + { // keyword found + while (line_string.find("#ende") == string::npos) + { + in.clear(); + pqc_infile->getline(line, MAX_ZEILE); + line_string = line; + if (line_string.find("#ende") == string::npos) + additional_punches.push_back(line_string); + } + } /* Schleife ueber Keyword SELECTED_OUTPUT */ // keyword found - if(line_string.find("SELECTED_OUTPUT") != string::npos) - while(line_string.find("#ende") == string::npos) + if (line_string.find("SELECTED_OUTPUT") != string::npos) + while (line_string.find("#ende") == string::npos) { - pqc_infile->getline(line,MAX_ZEILE); + pqc_infile->getline(line, MAX_ZEILE); line_string = line; if (line_string.find("-file") != string::npos) { @@ -2354,28 +2456,36 @@ int REACT::ReadReactionModelNew( ifstream* pqc_infile) in >> dummy >> this->results_file_name; } } - } /*end while */ - - if((this->gamma_Hplus > 0)) - cout << - " pH found and H+ found, pH for PHREEQC input is calculated using gamma_H+ and [H+] " - << gamma_Hplus << "\n"; - - //WW nj=rcml_number_of_master_species + rcml_number_of_equi_phases + rcml_number_of_ion_exchanges + rcml_number_of_gas_species; - cout << " Found in *.pqc file: " << rcml_number_of_master_species << " master species (excluding pH, H+ and pe), " ; - cout << rcml_number_of_equi_phases << " equilibrium phases, " << rcml_number_of_ion_exchanges << " ion exchangers, " ; - cout << rcml_number_of_kinetics << " (exclusively) kinetic species, " << rcml_number_of_gas_species << " gas species and "; - cout << rcml_number_of_secondary_species << " secondary species, " ; - cout << additional_punches.size() << " additional punch commands." << "\n"; + } /*end while */ + + if ((this->gamma_Hplus > 0)) + cout << " pH found and H+ found, pH for PHREEQC input is calculated using gamma_H+ and [H+] " << gamma_Hplus + << "\n"; + + // WW nj=rcml_number_of_master_species + rcml_number_of_equi_phases + rcml_number_of_ion_exchanges + + // rcml_number_of_gas_species; + cout << " Found in *.pqc file: " << rcml_number_of_master_species << " master species (excluding pH, H+ and pe), "; + cout << rcml_number_of_equi_phases << " equilibrium phases, " << rcml_number_of_ion_exchanges + << " ion exchangers, "; + cout << rcml_number_of_kinetics << " (exclusively) kinetic species, " << rcml_number_of_gas_species + << " gas species and "; + cout << rcml_number_of_secondary_species << " secondary species, "; + cout << additional_punches.size() << " additional punch commands." + << "\n"; // for(i=0; i< (int) pqc_names.size();i++) // cout << pqc_names[i] << ", " << pqc_index[i] << ", " << pqc_process[i] << "\n"; - if(rcml_number_of_secondary_species != additional_punches.size()){ - cout << " Warning in PhreeqC-Interface: " << "\n"; - cout << " No. of additional output species is different from " << "\n"; - cout << " No. of additional PUNCH commands. " << "\n"; - cout << " Check Keywords ADDITIONAL_OUTPUT and ADDITIONAL_PUNCH!" << "\n"; - } + if (rcml_number_of_secondary_species != additional_punches.size()) + { + cout << " Warning in PhreeqC-Interface: " + << "\n"; + cout << " No. of additional output species is different from " + << "\n"; + cout << " No. of additional PUNCH commands. " + << "\n"; + cout << " Check Keywords ADDITIONAL_OUTPUT and ADDITIONAL_PUNCH!" + << "\n"; + } return 1; } @@ -2398,44 +2508,42 @@ int REACT::ReadReactionModelNew( ifstream* pqc_infile) int REACT::ReadInputPhreeqc(long index, FILE* fpqc, FILE* Fphinp) { int i = 0, np; - int nn = 0,nep = 0, nj = 0, nk = 0; - //WW int beginn=0, + int nn = 0, nep = 0, nj = 0, nk = 0; + // WW int beginn=0, int p = 0, found; int pH_flag = -1, pe_flag = -1, iheat; - int pos,j; + int pos, j; double dvalue, d_help; - char str[256],sub[256], s[256]; - char* s1, * s2; + char str[256], sub[256], s[256]; + char *s1, *s2; s1 = s2 = NULL; - FILE* indatei = NULL, * f; + FILE *indatei = NULL, *f; np = this->number_of_comp; // crdat = (char *) Malloc((int)(int)strlen(file_name)); // crdat = strcat(strcpy(crdat,file_name),CHEM_REACTION_EXTENSION); /*MX:0603*/ /* Open input and output file */ // indatei = fopen(crdat, "r"); /*input dateien*/ - indatei = fpqc; /*input dateien*/ - f = Fphinp; /*output dateien*/ + indatei = fpqc; /*input dateien*/ + f = Fphinp; /*output dateien*/ - if(indatei == NULL) + if (indatei == NULL) { DisplayMsgLn("Erro:The input file *.pqc doesn't exist!!!"); return 0; } /* zeilenweise lesen */ - while(fgets(str,256,indatei)) + while (fgets(str, 256, indatei)) { // DisplayMsgLn(""); // DisplayMsgLn(str); pos = 0; - //WW beginn=1; + // WW beginn=1; p = 0; - while ((!strstr(str, - "END")) && - (!strstr(str, "#ende")) && StrOnlyReadStr(sub, str, f, /*TFString,*/ &p)) + while ((!strstr(str, "END")) && (!strstr(str, "#ende")) && StrOnlyReadStr(sub, str, f, /*TFString,*/ &p)) { LineFeed(f); found = 0; @@ -2454,7 +2562,7 @@ int REACT::ReadInputPhreeqc(long index, FILE* fpqc, FILE* Fphinp) LineFeed(f); // while (fgets(str,256,indatei) && (!StrTestDollar(str, &pos))){ - while (fgets(str,256,indatei) && (!strstr(str, "#ende"))) + while (fgets(str, 256, indatei) && (!strstr(str, "#ende"))) { if ((!strstr(str, "# comp")) && (!strstr(str, "# temp"))) // DisplayMsgLn(" #ende and # not found"); @@ -2463,25 +2571,21 @@ int REACT::ReadInputPhreeqc(long index, FILE* fpqc, FILE* Fphinp) else { // DisplayMsgLn(" # comp found "); - //sscanf(str, "%s"); + // sscanf(str, "%s"); StrReadStr(s, str, f, /*TFString,*/ &pos); /* SB: temperature introduced */ - if(strcmp(s,"temp") == 0) + if (strcmp(s, "temp") == 0) { - if(rcml_heat_flag == 1) + if (rcml_heat_flag == 1) { iheat = np; // printf("Temperature is %lf", val_in[iheat][index]); /* convert temperature from Kelvin to degree celsius for PHREEQC */ - //MX 03.05 + // MX 03.05 if (val_in[iheat][index] < 273.0) - val_in[iheat][index] += - 273.15; - FilePrintDouble( - f, - val_in[iheat][index - ] - 273.15); + val_in[iheat][index] += 273.15; + FilePrintDouble(f, val_in[iheat][index] - 273.15); FilePrintString(f, " # temp "); LineFeed(f); } @@ -2495,22 +2599,20 @@ int REACT::ReadInputPhreeqc(long index, FILE* fpqc, FILE* Fphinp) /* find the concentration of each component from val_in*/ for (j = 0; j < np; j++) { - if (strcmp(s,name[j]) == 0) + if (strcmp(s, name[j]) == 0) { - if(strcmp("pH",name[j]) != 0) + if (strcmp("pH", name[j]) != 0) { nn += 1; d_help = val_in[j][index]; // printf("Component %s: concentration %lf", s, d_help); - if(fabs(d_help) < 1.0e-019) + if (fabs(d_help) < 1.0e-019) d_help = 0.0; FilePrintDouble(f, d_help); - FilePrintString(f, - " # comp "); + FilePrintString(f, " # comp "); FilePrintInt(f, j + 1); LineFeed(f); - if (strcmp("pe", - name[j]) == 0) + if (strcmp("pe", name[j]) == 0) pe_flag = 0; break; } @@ -2527,40 +2629,24 @@ int REACT::ReadInputPhreeqc(long index, FILE* fpqc, FILE* Fphinp) */ } - else if (strcmp(s,"pH") == 0) /* if pH will change with the reaction! */ + else if (strcmp(s, "pH") == 0) /* if pH will change with the reaction! */ { for (i = 0; i < np; i++) { - if (strcmp(s,name[i]) == 0) + if (strcmp(s, name[i]) == 0) /* pH in RF input file */ - if(strcmp("pH", - name[i]) - == 0) + if (strcmp("pH", name[i]) == 0) { pH_flag = 0; - // printf("Component %s: concentration %lf", s, val_in[i][index]); - FilePrintDouble( - f, - val_in - [i] - [ - index - ]); - //MX FilePrintString(f, " charge "); - - if (strstr( - str, - "charge")) - FilePrintString( - f, - " charge "); - FilePrintString( - f, - " # comp "); - FilePrintInt( - f, - rcml_number_of_master_species - + 1); + // printf("Component %s: concentration %lf", s, + // val_in[i][index]); + FilePrintDouble(f, val_in[i][index]); + // MX FilePrintString(f, " charge "); + + if (strstr(str, "charge")) + FilePrintString(f, " charge "); + FilePrintString(f, " # comp "); + FilePrintInt(f, rcml_number_of_master_species + 1); LineFeed(f); break; } @@ -2569,62 +2655,37 @@ int REACT::ReadInputPhreeqc(long index, FILE* fpqc, FILE* Fphinp) if (pH_flag < 0) { DisplayMsgLn( - "pH is not included in the transport but will be calculated in the reaction"); + "pH is not included in the transport but will be calculated in the reaction"); pH_flag = 1; p = 0; - StrReadDouble( - &dvalue, - &str[p += - pos], - f, - &pos); - StrReadStr( - s, - &str[p += pos], - f, - /*TFString,*/ & - pos); - FilePrintString(f, - " # comp "); - FilePrintInt( - f, - rcml_number_of_master_species - + 1); + StrReadDouble(&dvalue, &str[p += pos], f, &pos); + StrReadStr(s, + &str[p += pos], + f, + /*TFString,*/ &pos); + FilePrintString(f, " # comp "); + FilePrintInt(f, rcml_number_of_master_species + 1); LineFeed(f); - name[ - rcml_number_of_master_species - + 1] = "pH"; + name[rcml_number_of_master_species + 1] = "pH"; break; } break; } - else if (strcmp(s,"pe") == 0) /* if pe will change with the reaction! */ + else if (strcmp(s, "pe") == 0) /* if pe will change with the reaction! */ { for (i = 0; i < np; i++) { - if (strcmp(s,name[i]) == 0) + if (strcmp(s, name[i]) == 0) /* pe in RF input file */ - if(strcmp("pe", - name[i]) - == 0) + if (strcmp("pe", name[i]) == 0) { pe_flag = 0; - // printf("Component %s: concentration %lf", s, val_in[i][index]); - FilePrintDouble( - f, - val_in - [i] - [ - index - ]); - FilePrintString( - f, - " # comp "); - FilePrintInt( - f, - rcml_number_of_master_species - + 2); + // printf("Component %s: concentration %lf", s, + // val_in[i][index]); + FilePrintDouble(f, val_in[i][index]); + FilePrintString(f, " # comp "); + FilePrintInt(f, rcml_number_of_master_species + 2); LineFeed(f); break; } @@ -2633,18 +2694,11 @@ int REACT::ReadInputPhreeqc(long index, FILE* fpqc, FILE* Fphinp) if (pe_flag < 0) { DisplayMsgLn( - "pe is not included in the transport but will be calculated in the reaction"); + "pe is not included in the transport but will be calculated in the reaction"); pe_flag = 1; - StrReadDouble(&dvalue, - &str[pos], - f, - &pos); - FilePrintString(f, - " # comp "); - FilePrintInt( - f, - rcml_number_of_master_species - + 2); + StrReadDouble(&dvalue, &str[pos], f, &pos); + FilePrintString(f, " # comp "); + FilePrintInt(f, rcml_number_of_master_species + 2); LineFeed(f); break; } @@ -2654,13 +2708,11 @@ int REACT::ReadInputPhreeqc(long index, FILE* fpqc, FILE* Fphinp) } /*end-else*/ } /*end while -3*/ if (nn != rcml_number_of_master_species) - FilePrintString( - f, - "Warnung:Concentration of master species not found in *.rfd file!!!"); + FilePrintString(f, "Warnung:Concentration of master species not found in *.rfd file!!!"); pos = 0; - //WW beginn=1; + // WW beginn=1; p = 0; - } /*if_SOLUTION*/ + } /*if_SOLUTION*/ /* Schleife ueber Keyword SOLUTION_SPECIES */ /*-------------------------------------------------------------------------------------*/ @@ -2670,7 +2722,7 @@ int REACT::ReadInputPhreeqc(long index, FILE* fpqc, FILE* Fphinp) FilePrintString(f, "SOLUTION_SPECIES "); FilePrintInt(f, index + 1); LineFeed(f); - while (fgets(str,256,indatei) && (!strstr(str, "#ende"))) + while (fgets(str, 256, indatei) && (!strstr(str, "#ende"))) FilePrintString(f, str); } @@ -2682,7 +2734,7 @@ int REACT::ReadInputPhreeqc(long index, FILE* fpqc, FILE* Fphinp) FilePrintString(f, "SOLUTION_MASTER_SPECIES "); FilePrintInt(f, index + 1); LineFeed(f); - while (fgets(str,256,indatei) && (!strstr(str, "#ende"))) + while (fgets(str, 256, indatei) && (!strstr(str, "#ende"))) FilePrintString(f, str); } @@ -2694,18 +2746,18 @@ int REACT::ReadInputPhreeqc(long index, FILE* fpqc, FILE* Fphinp) FilePrintString(f, "EQUILIBRIUM_PHASES "); FilePrintInt(f, index + 1); LineFeed(f); - while (fgets(str,256,indatei) && (!strstr(str, "#ende"))) + while (fgets(str, 256, indatei) && (!strstr(str, "#ende"))) { pos = 0; p = 0; StrReadStr(s, &str[p += pos], f, /*TFString,*/ &pos); - if (strcmp(s,"") == 0) + if (strcmp(s, "") == 0) break; StrReadDouble(&dvalue, &str[pos], f, &pos); /* find the mass of each phase from val_in*/ for (i = 0; i < np; i++) - if (strcmp(s,name[i]) == 0) + if (strcmp(s, name[i]) == 0) { nep += 1; // printf(" Phase %s: %lf \n", s, val_in[i][index]); @@ -2719,11 +2771,10 @@ int REACT::ReadInputPhreeqc(long index, FILE* fpqc, FILE* Fphinp) } /*end while*/ if (nep != rcml_number_of_equi_phases) FilePrintString( - f, - "Warning: One or more solid phase(s) in EQUILIBRIUM_PHASES not found in *.rfd file!!!"); + f, "Warning: One or more solid phase(s) in EQUILIBRIUM_PHASES not found in *.rfd file!!!"); // FilePrintString(f, "Value(s) in *.pqc file used!!!"); // FilePrintString(f, str); - } /*end if*/ + } /*end if*/ /* Schleife ueber Keyword KINETICS */ /*-------------------------------------------------------------------------------------*/ @@ -2733,28 +2784,27 @@ int REACT::ReadInputPhreeqc(long index, FILE* fpqc, FILE* Fphinp) FilePrintString(f, "KINETICS "); FilePrintInt(f, index + 1); LineFeed(f); - while (fgets(str,256,indatei) && (!strstr(str, "#ende"))) + while (fgets(str, 256, indatei) && (!strstr(str, "#ende"))) { - if(strstr(str,"-steps")) + if (strstr(str, "-steps")) { /* zerlegen und RockFlow timestep einfügen */ - ///OK - sscanf(str," %s %lf %s %i %s", s1,&dvalue,s,&j,s2); + /// OK + sscanf(str, " %s %lf %s %i %s", s1, &dvalue, s, &j, s2); /* steps in reaction model eintragen */ this->rcml_number_of_pqcsteps = j; - if(index > -1) + if (index > -1) { FilePrintString(f, " -steps "); CTimeDiscretization* m_tim = NULL; - if(time_vector.size() > 0) + if (time_vector.size() > 0) m_tim = time_vector[0]; else - cout << - "Error in MPCCalcCharacteristicNumbers: no time discretization data !" + cout << "Error in MPCCalcCharacteristicNumbers: no time discretization data !" << "\n"; - FilePrintDouble(f,m_tim->CalcTimeStep()); - //OK_TIM FilePrintDouble(f, GetDt(aktueller_zeitschritt-1l)); + FilePrintDouble(f, m_tim->CalcTimeStep()); + // OK_TIM FilePrintDouble(f, GetDt(aktueller_zeitschritt-1l)); FilePrintString(f, " in "); FilePrintInt(f, j); FilePrintString(f, " steps "); @@ -2774,7 +2824,7 @@ int REACT::ReadInputPhreeqc(long index, FILE* fpqc, FILE* Fphinp) FilePrintString(f, "RATES "); FilePrintInt(f, index + 1); LineFeed(f); - while (fgets(str,256,indatei) && (!strstr(str, "#ende"))) + while (fgets(str, 256, indatei) && (!strstr(str, "#ende"))) FilePrintString(f, str); } @@ -2786,7 +2836,7 @@ int REACT::ReadInputPhreeqc(long index, FILE* fpqc, FILE* Fphinp) FilePrintString(f, "PHASE "); FilePrintInt(f, index + 1); LineFeed(f); - while (fgets(str,256,indatei) && (!strstr(str, "#ende"))) + while (fgets(str, 256, indatei) && (!strstr(str, "#ende"))) FilePrintString(f, str); } @@ -2798,7 +2848,7 @@ int REACT::ReadInputPhreeqc(long index, FILE* fpqc, FILE* Fphinp) FilePrintString(f, "EXCHANGE "); FilePrintInt(f, index + 1); LineFeed(f); - while (fgets(str,256,indatei) && (!strstr(str, "#ende"))) + while (fgets(str, 256, indatei) && (!strstr(str, "#ende"))) { pos = 0; p = 0; @@ -2806,7 +2856,7 @@ int REACT::ReadInputPhreeqc(long index, FILE* fpqc, FILE* Fphinp) /* find the mass of each phase from val_in*/ for (i = 0; i < np; i++) - if (strcmp(s,name[i]) == 0) + if (strcmp(s, name[i]) == 0) { nj += 1; // printf(" Phase %s: %lf \n", s, val_in[i][index]); @@ -2819,12 +2869,10 @@ int REACT::ReadInputPhreeqc(long index, FILE* fpqc, FILE* Fphinp) /*end for*/ } /*end while*/ if (nj != rcml_number_of_ion_exchanges) - FilePrintString( - f, - "Warning: Problem in reading EXCHANGE in *.rfd or *.pqc file!!!"); + FilePrintString(f, "Warning: Problem in reading EXCHANGE in *.rfd or *.pqc file!!!"); // FilePrintString(f, "Value(s) in *.pqc file used!!!"); // FilePrintString(f, str); - } /*end if*/ + } /*end if*/ /* Keyword PRINT */ /*-------------------------------------------------------------------------------------*/ @@ -2835,11 +2883,11 @@ int REACT::ReadInputPhreeqc(long index, FILE* fpqc, FILE* Fphinp) { FilePrintString(f, "PRINT "); LineFeed(f); - while (fgets(str,256,indatei) && (!strstr(str, "#ende"))) + while (fgets(str, 256, indatei) && (!strstr(str, "#ende"))) FilePrintString(f, str); } else - while (fgets(str,256,indatei) && (!strstr(str, "#ende"))) + while (fgets(str, 256, indatei) && (!strstr(str, "#ende"))) { } } @@ -2852,7 +2900,7 @@ int REACT::ReadInputPhreeqc(long index, FILE* fpqc, FILE* Fphinp) { FilePrintString(f, "SELECTED_OUTPUT "); LineFeed(f); - while (fgets(str,256,indatei) && (!strstr(str, "#ende"))) + while (fgets(str, 256, indatei) && (!strstr(str, "#ende"))) { FilePrintString(f, str); p = 0; @@ -2868,7 +2916,7 @@ int REACT::ReadInputPhreeqc(long index, FILE* fpqc, FILE* Fphinp) } } else - while (fgets(str,256,indatei) && (!strstr(str, "#ende"))) + while (fgets(str, 256, indatei) && (!strstr(str, "#ende"))) { } } @@ -2886,30 +2934,24 @@ int REACT::ReadInputPhreeqc(long index, FILE* fpqc, FILE* Fphinp) /*------------head------------------------------*/ fprintf(f, " -head"); for (j = 0; j < rcml_number_of_master_species; j++) - if((strcmp("pH", - name[j]) != 0) && - (strcmp("pe",name[j]) != 0)) + if ((strcmp("pH", name[j]) != 0) && (strcmp("pe", name[j]) != 0)) fprintf(f, " %s", name[j]); fprintf(f, " pH pe"); nj = rcml_number_of_master_species; nk = rcml_number_of_equi_phases; - for (j = nj + 2; j < nj + rcml_number_of_equi_phases + 2; - j++) + for (j = nj + 2; j < nj + rcml_number_of_equi_phases + 2; j++) fprintf(f, " %s", name[j]); - for (j = nj + nk + 2; - j < nj + nk + rcml_number_of_ion_exchanges + 2; j++) + for (j = nj + nk + 2; j < nj + nk + rcml_number_of_ion_exchanges + 2; j++) fprintf(f, " %s", name[j]); LineFeed(f); /*------------master speciese---------------------*/ fprintf(f, " 10 PUNCH"); for (j = 0; j < nj - 1; j++) - if((strcmp("pH", - name[j]) != 0) && - (strcmp("pe",name[j]) != 0)) + if ((strcmp("pH", name[j]) != 0) && (strcmp("pe", name[j]) != 0)) fprintf(f, " TOT(%c%s%c),", 34, name[j], 34); fprintf(f, " TOT(%c%s%c)", 34, name[nj - 1], 34); @@ -2924,18 +2966,9 @@ int REACT::ReadInputPhreeqc(long index, FILE* fpqc, FILE* Fphinp) { LineFeed(f); fprintf(f, " 40 PUNCH"); - for (j = nj + 2; - j < nj + rcml_number_of_equi_phases + 1; j++) - fprintf(f, - " EQUI(%c%s%c),", - 34, - name[j], - 34); - fprintf(f, - " EQUI(%c%s%c),", - 34, - name[nj + rcml_number_of_equi_phases + 1], - 34); + for (j = nj + 2; j < nj + rcml_number_of_equi_phases + 1; j++) + fprintf(f, " EQUI(%c%s%c),", 34, name[j], 34); + fprintf(f, " EQUI(%c%s%c),", 34, name[nj + rcml_number_of_equi_phases + 1], 34); } /*------------exchange-------------------*/ @@ -2943,44 +2976,37 @@ int REACT::ReadInputPhreeqc(long index, FILE* fpqc, FILE* Fphinp) { LineFeed(f); fprintf(f, " 60 PUNCH"); - for (j = nj + nk + 2; - j < nj + nk + rcml_number_of_ion_exchanges + 1; - j++) + for (j = nj + nk + 2; j < nj + nk + rcml_number_of_ion_exchanges + 1; j++) fprintf(f, " MOL(%c%s%c),", 34, name[j], 34); - fprintf(f, " MOL(%c%s%c),", 34, - name[nj + nk + - rcml_number_of_ion_exchanges + 1], 34); + fprintf(f, " MOL(%c%s%c),", 34, name[nj + nk + rcml_number_of_ion_exchanges + 1], 34); } - while (fgets(str,256,indatei) && (!strstr(str, "#ende"))) + while (fgets(str, 256, indatei) && (!strstr(str, "#ende"))) { // FilePrintString(f, str); } } else - while (fgets(str,256, - indatei) && - ((!strstr(str, "#ende")) || (!strstr(str, "END")))) + while (fgets(str, 256, indatei) && ((!strstr(str, "#ende")) || (!strstr(str, "END")))) { } - } /* end if_USER_PUNCH */ + } /* end if_USER_PUNCH */ /* SB: added: time discretisation: Keyword is "-steps" */ else if (!strcmp(sub, "-steps")) { found = 1; - ///OK - sscanf(str," %s %lf %s %i %s", s1, &dvalue,s,&j,s2); - if(index > -1) + /// OK + sscanf(str, " %s %lf %s %i %s", s1, &dvalue, s, &j, s2); + if (index > -1) { FilePrintString(f, " -steps "); CTimeDiscretization* m_tim = NULL; - if(time_vector.size() > 0) + if (time_vector.size() > 0) m_tim = time_vector[0]; else - cout << - "Error in MPCCalcCharacteristicNumbers: no time discretization data !" + cout << "Error in MPCCalcCharacteristicNumbers: no time discretization data !" << "\n"; - FilePrintDouble(f,m_tim->CalcTimeStep()); - //OK_TIM FilePrintDouble(f, GetDt(aktueller_zeitschritt-1l)); + FilePrintDouble(f, m_tim->CalcTimeStep()); + // OK_TIM FilePrintDouble(f, GetDt(aktueller_zeitschritt-1l)); FilePrintString(f, " in "); FilePrintInt(f, j); FilePrintString(f, " steps "); @@ -2990,14 +3016,11 @@ int REACT::ReadInputPhreeqc(long index, FILE* fpqc, FILE* Fphinp) /* Not found */ else if (found != 1) { - fprintf(f, - " %s %s ", - str, - " in the *.pqc file is an unknown keyword!!!"); + fprintf(f, " %s %s ", str, " in the *.pqc file is an unknown keyword!!!"); exit(1); } - } /* end while - 2 */ - } /* end while - 1 */ + } /* end while - 2 */ + } /* end while - 1 */ LineFeed(f); fprintf(f, "END"); @@ -3006,7 +3029,7 @@ int REACT::ReadInputPhreeqc(long index, FILE* fpqc, FILE* Fphinp) // if (indatei !=NULL) fclose(indatei); return 1; -} /* end-if */ +} /* end-if */ /************************************************************************** ROCKFLOW - Funktion: WriteInputPhreeqc @@ -3031,161 +3054,177 @@ int REACT::WriteInputPhreeqc(long index, /*ifstream *pqc_iinfile,*/ ofstream* ou std::stringstream in; string name, line_string, speciesname, dummy; CRFProcess* m_pcs = NULL; -int i, ii, idx, n1, n2, n3, n4, n5, n6, count=-1, stepsflag, found=0; + int i, ii, idx, n1, n2, n3, n4, n5, n6, count = -1, stepsflag, found = 0; double dval, dval1, sat_index = 0.0; double z, h, dens, press, partial_press, volume, temp = -1.0, mm; -double unitfactor_l = 1, unitfactor_s = 1; - -//CB 19.1.2011 - // Get the reaction interface data - REACTINT *m_rei = NULL; - if(REACTINT_vec.size()>0){ - m_rei = REACTINT_vec[0]; - if(m_rei->unitconversion){ - m_rei->CalcUnitConversionFactors(index, &unitfactor_l, &unitfactor_s, true); - } - } -// cout << " WriteInputPhreeqc for node " << index << "\n"; + double unitfactor_l = 1, unitfactor_s = 1; + + // CB 19.1.2011 + // Get the reaction interface data + REACTINT* m_rei = NULL; + if (REACTINT_vec.size() > 0) + { + m_rei = REACTINT_vec[0]; + if (m_rei->unitconversion) + { + m_rei->CalcUnitConversionFactors(index, &unitfactor_l, &unitfactor_s, true); + } + } + // cout << " WriteInputPhreeqc for node " << index << "\n"; cout.flush(); -/* File handling - rewind file */ -// pqc_infile->seekg(0L,ios_base::beg); -// pqc_infile->close(); - ifstream pqc_infile (this->file_name_pqc.data(),ios::in); - pqc_infile.seekg(0L,ios::beg); - -// precision output file - out_file->setf(ios::scientific,ios::floatfield); + /* File handling - rewind file */ + // pqc_infile->seekg(0L,ios_base::beg); + // pqc_infile->close(); + ifstream pqc_infile(this->file_name_pqc.data(), ios::in); + pqc_infile.seekg(0L, ios::beg); + + // precision output file + out_file->setf(ios::scientific, ios::floatfield); out_file->precision(12); -/* zeilenweise lesen */ - while(!pqc_infile.eof()) + /* zeilenweise lesen */ + while (!pqc_infile.eof()) { - pqc_infile.getline(line,MAX_ZEILE); + pqc_infile.getline(line, MAX_ZEILE); line_string = line; - if(line_string.find("#STOP") != string::npos) + if (line_string.find("#STOP") != string::npos) break; //------------------------------------------------------------------------------------------------------------- /* Schleife ueber Keyword Solution */ - if(line_string.find("SOLUTION") != string::npos) // keyword found + if (line_string.find("SOLUTION") != string::npos) // keyword found { - *out_file << "SOLUTION " << index + 1 << " #New Version " << "\n"; + *out_file << "SOLUTION " << index + 1 << " #New Version " + << "\n"; *out_file << "#GRID " << index + 1 << "\n"; - while(line_string.find("#ende") == string::npos) + while (line_string.find("#ende") == string::npos) { - pqc_infile.getline(line,MAX_ZEILE); + pqc_infile.getline(line, MAX_ZEILE); line_string = line; if (line_string.find("# comp") != string::npos) { - if (line_string.find("pH") == string::npos && - line_string.find("pe") == string::npos) + if (line_string.find("pH") == string::npos && line_string.find("pe") == string::npos) { // Component found; write name and concentration of component count++; /* in.str(line_string); in >> speciesname ; - //m_pcs = PCSGet("MASS_TRANSPORT",speciesname);// CB HS update - m_pcs = cp_vec[cp_name_2_idx[speciesname]]->getProcess(); + //m_pcs = PCSGet("MASS_TRANSPORT",speciesname);// CB HS update + m_pcs = cp_vec[cp_name_2_idx[speciesname]]->getProcess(); idx = m_pcs->GetNodeValueIndex(speciesname)+1; // old timelevel dval = m_pcs->GetNodeValue(index,idx); */ speciesname = pqc_names[count]; - dval = pcs_vector[pqc_process[count]]->GetNodeValue( - index, - pqc_index[count]); - /* cout << "Testing index vectors: " << speciesname << ", " << m_pcs->pcs_number << ", "<< idx <<", With vectors: " << pqc_names[count] << ", " << pcs_vector[pqc_process[count]]->pcs_number << ", " << pqc_index[count]; + dval = pcs_vector[pqc_process[count]]->GetNodeValue(index, pqc_index[count]); + /* cout << "Testing index vectors: " << speciesname << ", " << m_pcs->pcs_number + << ", "<< idx <<", With vectors: " << pqc_names[count] << ", " << + pcs_vector[pqc_process[count]]->pcs_number << ", " << pqc_index[count]; cout << " Values: " << dval << ", " << dval1 << "\n"; */ -//CB 19.1.2011 - // based on porosity, calculate molality mi,w before coputing equilirium chemistry - if(m_rei) { - if(m_rei->unitconversion) { - idx = pcs_vector[pqc_process[count]]->GetProcessComponentNumber(); - //mi,w = Ci,w * n *55.5 / CH2O - //mi,s = Ci,w * (1-n) *55.5 / CH2O - if(cp_vec[idx]->transport_phase==0) // liquid phase - dval *= unitfactor_l; - else if(cp_vec[idx]->transport_phase==1) // solid phase - dval *= unitfactor_s; - } - } - if(speciesname.compare("pe")) // if this is not pe - if(dval < 1.0e-19) + // CB 19.1.2011 + // based on porosity, calculate molality mi,w before coputing equilirium chemistry + if (m_rei) + { + if (m_rei->unitconversion) + { + idx = pcs_vector[pqc_process[count]]->GetProcessComponentNumber(); + // mi,w = Ci,w * n *55.5 / CH2O + // mi,s = Ci,w * (1-n) *55.5 / CH2O + if (cp_vec[idx]->transport_phase == 0) // liquid phase + dval *= unitfactor_l; + else if (cp_vec[idx]->transport_phase == 1) // solid phase + dval *= unitfactor_s; + } + } + if (speciesname.compare("pe")) // if this is not pe + if (dval < 1.0e-19) dval = 0.0; // if(speciesname.compare("pH")) - *out_file << speciesname << " " << dval << - " # comp " << "\n"; + *out_file << speciesname << " " << dval << " # comp " + << "\n"; // if(index <2) cout << speciesname << " " << dval << "\n"; // else - // *out_file << speciesname << " " << dval << " charge " << " # comp " <<"\n"; + // *out_file << speciesname << " " << dval << " charge " << " # + // comp " <<"\n"; // in.clear(); } } else if (line_string.find("# temp") != string::npos) { // check if heat transport process is calculated in GeoSys - if(this->rcml_heat_flag > 0) + if (this->rcml_heat_flag > 0) { m_pcs = PCSGet("HEAT_TRANSPORT"); idx = m_pcs->GetNodeValueIndex("TEMPERATURE1"); - dval = m_pcs->GetNodeValue(index,idx); + dval = m_pcs->GetNodeValue(index, idx); if (dval < 273.0) - dval += 273.15; //change from °C to Kelvin if necessary + dval += 273.15; // change from °C to Kelvin if necessary dval -= 273.15; // Input to PHREEQC is in °C - *out_file << "temp " << dval << " # temp " << "\n"; + *out_file << "temp " << dval << " # temp " + << "\n"; temp = dval; // save for gas phase input } } else // Write units and temperature in the standard case - if (line_string.find("pH") == string::npos && - line_string.find("pe") == string::npos && - line_string.find("#ende") == string::npos) + if (line_string.find("pH") == string::npos && line_string.find("pe") == string::npos + && line_string.find("#ende") == string::npos) *out_file << line_string << "\n"; - } // end while + } // end while // special treat pH, and pe n1 = this->rcml_number_of_master_species; count++; - if(count != n1) - cout << "Error in index of pqc_vectors !" << "\n"; - dval = pcs_vector[pqc_process[count]]->GetNodeValue(index,pqc_index[count]); + if (count != n1) + cout << "Error in index of pqc_vectors !" + << "\n"; + dval = pcs_vector[pqc_process[count]]->GetNodeValue(index, pqc_index[count]); // if(index <2) cout << " pH: " << dval; // H+ count++; - if(this->gamma_Hplus > 0) // pH and H+ in GeoSys species, calculate pH from H+ + if (this->gamma_Hplus > 0) // pH and H+ in GeoSys species, calculate pH from H+ { - dval1 = fabs(pcs_vector[pqc_process[n1+1]]->GetNodeValue(index,pqc_index[n1+1])); // CB 01/11 probably safer taking abs before calculating log(H+) -//CB 19.1.2011 - // based on porosity, calculate molality mi,w before coputing equilirium chemistry - if(m_rei) - if(m_rei->unitconversion) //mi,w = Ci,w * n *55.5 / CH2O - dval1 *= unitfactor_l; + dval1 = fabs(pcs_vector[pqc_process[n1 + 1]]->GetNodeValue( + index, pqc_index[n1 + 1])); // CB 01/11 probably safer taking abs before calculating log(H+) + // CB 19.1.2011 + // based on porosity, calculate molality mi,w before coputing equilirium chemistry + if (m_rei) + if (m_rei->unitconversion) // mi,w = Ci,w * n *55.5 / CH2O + dval1 *= unitfactor_l; dval = -log10(dval1 * gamma_Hplus); - // if(index<2) cout << " . Resetting pH to: " << dval << "; MOL[H+]= " << dval1 << ", gamma_H+ = " << gamma_Hplus; + // if(index<2) cout << " . Resetting pH to: " << dval << "; MOL[H+]= " << dval1 << ", + // gamma_H+ = " << gamma_Hplus; } - if(this->rcml_pH_charge > 0) - *out_file << "pH" << " " << dval << " charge " << - " # comp " << "\n"; + if (this->rcml_pH_charge > 0) + *out_file << "pH" + << " " << dval << " charge " + << " # comp " + << "\n"; else - *out_file << "pH" << " " << dval << " # comp " << "\n"; - //SB to do screen output if(index <2) cout << " pH: " << dval << ", " << pcs_vector[pqc_process[count]]->pcs_number << "\n"; + *out_file << "pH" + << " " << dval << " # comp " + << "\n"; + // SB to do screen output if(index <2) cout << " pH: " << dval << ", " << + // pcs_vector[pqc_process[count]]->pcs_number << "\n"; // write pe count++; - dval = pcs_vector[pqc_process[n1 + 2]]->GetNodeValue(index, - pqc_index[n1 + 2]); - *out_file << "pe" << " " << dval << " # comp " << "\n"; - //SB to do screen output if(index <2) cout << " pe: " << dval << ", " << pcs_vector[pqc_process[count]]->pcs_number << "\n"; + dval = pcs_vector[pqc_process[n1 + 2]]->GetNodeValue(index, pqc_index[n1 + 2]); + *out_file << "pe" + << " " << dval << " # comp " + << "\n"; + // SB to do screen output if(index <2) cout << " pe: " << dval << ", " << + // pcs_vector[pqc_process[count]]->pcs_number << "\n"; *out_file << line_string << "\n"; - } // end SOLUTION + } // end SOLUTION //------------------------------------------------------------------------------------------------------------- /* Schleife ueber Keyword EQUILIBRIUM PHASES */ // keyword found - if(line_string.find("EQUILIBRIUM_PHASES") != string::npos) + if (line_string.find("EQUILIBRIUM_PHASES") != string::npos) { - *out_file << "\n" << "EQUILIBRIUM_PHASES " << index + 1 << "\n"; - while(line_string.find("#ende") == string::npos) + *out_file << "\n" + << "EQUILIBRIUM_PHASES " << index + 1 << "\n"; + while (line_string.find("#ende") == string::npos) { - pqc_infile.getline(line,MAX_ZEILE); + pqc_infile.getline(line, MAX_ZEILE); line_string = line; if (line_string.find("# comp") != string::npos) { @@ -3193,51 +3232,53 @@ double unitfactor_l = 1, unitfactor_s = 1; in.str(line_string); in >> speciesname >> sat_index; - /* //m_pcs = PCSGet("MASS_TRANSPORT",speciesname);// CB HS update - m_pcs = cp_vec[cp_name_2_idx[speciesname]]->getProcess(); - idx = m_pcs->GetNodeValueIndex(speciesname)+1; // old timelevel - dval = m_pcs->GetNodeValue(index,idx); - */ + /* //m_pcs = PCSGet("MASS_TRANSPORT",speciesname);// CB HS update + m_pcs = cp_vec[cp_name_2_idx[speciesname]]->getProcess(); + idx = m_pcs->GetNodeValueIndex(speciesname)+1; // old timelevel + dval = m_pcs->GetNodeValue(index,idx); + */ // if(count != (n1+3)) cout << " Error in index pqc " << "\n"; speciesname = pqc_names[count]; - dval = pcs_vector[pqc_process[count]]->GetNodeValue( - index, - pqc_index - [count]); - if(dval < 1.0e-19) + dval = pcs_vector[pqc_process[count]]->GetNodeValue(index, pqc_index[count]); + if (dval < 1.0e-19) dval = 0.0; - // cout << "Testing index vectors: " << speciesname << ", " << m_pcs->pcs_number << ", "<< idx <<", With vectors: " << pqc_names[count] << ", " << pcs_vector[pqc_process[count]]->pcs_number << ", " << pqc_index[count]; + // cout << "Testing index vectors: " << speciesname << ", " << m_pcs->pcs_number << + // ", "<< idx <<", With vectors: " << pqc_names[count] << ", " << + // pcs_vector[pqc_process[count]]->pcs_number << ", " << pqc_index[count]; // if(index <2) cout << " EQ-Species " << speciesname << " " << dval << "\n"; -//CB 19.1.2011 - // based on porosity, calculate molality mj before coputing equilirium chemistry - if(m_rei) { - if(m_rei->unitconversion) { - idx = pcs_vector[pqc_process[count]]->GetProcessComponentNumber(); - //mi,w = Ci,w * n *55.5 / CH2O - //mi,s = Ci,w * (1-n) *55.5 / CH2O - if(cp_vec[idx]->transport_phase==0) // liquid phase - dval *= unitfactor_l; - else if(cp_vec[idx]->transport_phase==1) // solid phase - dval *= unitfactor_s; - } - } - *out_file << speciesname << " " << sat_index << " " << - dval << " # comp " << "\n"; + // CB 19.1.2011 + // based on porosity, calculate molality mj before coputing equilirium chemistry + if (m_rei) + { + if (m_rei->unitconversion) + { + idx = pcs_vector[pqc_process[count]]->GetProcessComponentNumber(); + // mi,w = Ci,w * n *55.5 / CH2O + // mi,s = Ci,w * (1-n) *55.5 / CH2O + if (cp_vec[idx]->transport_phase == 0) // liquid phase + dval *= unitfactor_l; + else if (cp_vec[idx]->transport_phase == 1) // solid phase + dval *= unitfactor_s; + } + } + *out_file << speciesname << " " << sat_index << " " << dval << " # comp " + << "\n"; in.clear(); } else *out_file << line_string << "\n"; } - } // end EQUILIBRIUM PHASES + } // end EQUILIBRIUM PHASES //------------------------------------------------------------------------------------------------------------- /* Schleife ueber Keyword EXCHANGE */ - if(line_string.find("EXCHANGE") != string::npos) // keyword found + if (line_string.find("EXCHANGE") != string::npos) // keyword found { - *out_file << "\n" << "EXCHANGE " << index + 1 << "\n"; - while(line_string.find("#ende") == string::npos) + *out_file << "\n" + << "EXCHANGE " << index + 1 << "\n"; + while (line_string.find("#ende") == string::npos) { - pqc_infile.getline(line,MAX_ZEILE); + pqc_infile.getline(line, MAX_ZEILE); line_string = line; if (line_string.find("# comp") != string::npos) { @@ -3250,64 +3291,69 @@ double unitfactor_l = 1, unitfactor_s = 1; dval = m_pcs->GetNodeValue(index,idx); */ speciesname = pqc_names[count]; - dval = pcs_vector[pqc_process[count]]->GetNodeValue( - index, - pqc_index - [count]); - if(dval < 1.0e-19) + dval = pcs_vector[pqc_process[count]]->GetNodeValue(index, pqc_index[count]); + if (dval < 1.0e-19) dval = 0.0; - /* cout << "Testing index vectors: " << speciesname << ", " << m_pcs->pcs_number << ", "<< idx <<", With vectors: " << pqc_names[count] << ", " << pcs_vector[pqc_process[count]]->pcs_number << ", " << pqc_index[count]; + /* cout << "Testing index vectors: " << speciesname << ", " << m_pcs->pcs_number << + ", "<< idx <<", With vectors: " << pqc_names[count] << ", " << + pcs_vector[pqc_process[count]]->pcs_number << ", " << pqc_index[count]; cout << " Values: " << dval << ", " << dval1 << "\n"; */ - *out_file << speciesname << " " << dval << - " # comp " << "\n"; + *out_file << speciesname << " " << dval << " # comp " + << "\n"; // in.clear(); } else *out_file << line_string << "\n"; } - } // end EXCHANGE + } // end EXCHANGE //------------------------------------------------------------------------------------------------------------- /* Schleife ueber Keyword GAS_PHASE */ - if(line_string.find("GAS_PHASE") != string::npos) // keyword found + if (line_string.find("GAS_PHASE") != string::npos) // keyword found { - *out_file << "\n" << "GAS_PHASE " << index + 1 << "\n"; + *out_file << "\n" + << "GAS_PHASE " << index + 1 << "\n"; - // get necessary values for conversion of molar concentrations to partial pressures, and to calculate total pressure and total volume + // get necessary values for conversion of molar concentrations to partial pressures, and to calculate total + // pressure and total volume // get height of node z - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt - //WW MeshLib::CNode* m_nod = NULL; - //WW m_nod = m_msh->nod_vector[index]; + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt + // WW MeshLib::CNode* m_nod = NULL; + // WW m_nod = m_msh->nod_vector[index]; z = m_msh->nod_vector[index]->getData()[2]; // get piezometric hight h m_pcs = PCSGet("GROUNDWATER_FLOW"); - if(m_pcs == NULL) - cout << " Error - no flow process found!" << "\n"; + if (m_pcs == NULL) + cout << " Error - no flow process found!" + << "\n"; idx = m_pcs->GetNodeValueIndex("HEAD") + 1; - h = m_pcs->GetNodeValue(index,idx); + h = m_pcs->GetNodeValue(index, idx); // get fluid density dens = mfp_vector[0]->Density(); // calculate pressure in [Pa] press = dens * gravity_constant * (h - z); - // cout << " Pressure: " << press << " = " << dens << " * " << gravity_constant << " * ( " << h << " - " << z << " ) " << "\n"; + // cout << " Pressure: " << press << " = " << dens << " * " << gravity_constant << " * ( " << h << " - " << + // z << " ) " << "\n"; // get temperature in [°C] - if(rcml_heat_flag < 1) + if (rcml_heat_flag < 1) temp = this->temperature; // get molar masses of gas phase - mm = 0.0; // mm is total molar mass of gas phase in [mol] - ii = rcml_number_of_master_species + 3 + rcml_number_of_ion_exchanges + - rcml_number_of_equi_phases; - for(i = ii; i < ii + rcml_number_of_gas_species; i++) + mm = 0.0; // mm is total molar mass of gas phase in [mol] + ii = rcml_number_of_master_species + 3 + rcml_number_of_ion_exchanges + rcml_number_of_equi_phases; + for (i = ii; i < ii + rcml_number_of_gas_species; i++) { speciesname = this->pqc_names[i]; - // cout << "Testing index vectors: " << speciesname << ", With vectors: " << pqc_names[i] << ", " << pcs_vector[pqc_process[i]]->pcs_number << ", " << pqc_index[i]; - dval = pcs_vector[pqc_process[i]]->GetNodeValue(index,pqc_index[i]); + // cout << "Testing index vectors: " << speciesname << ", With vectors: " << pqc_names[i] << + //", + //" + //<< pcs_vector[pqc_process[i]]->pcs_number << ", " << pqc_index[i]; + dval = pcs_vector[pqc_process[i]]->GetNodeValue(index, pqc_index[i]); // cout << dval << "\n"; mm += dval; } @@ -3315,18 +3361,16 @@ double unitfactor_l = 1, unitfactor_s = 1; // calculate Volume of gas phase in [mol * Pa * m^3 / K / mol * K / Pa = m^3 ] volume = mm * 8.314472 * (273.15 + temp) / press; - while(line_string.find("#ende") == string::npos) + while (line_string.find("#ende") == string::npos) { - pqc_infile.getline(line,MAX_ZEILE); + pqc_infile.getline(line, MAX_ZEILE); line_string = line; if (line_string.find("-pressure") != string::npos) // pressure in atmospheres - *out_file << " -pressure " << press / - 101325.0 << "\n"; + *out_file << " -pressure " << press / 101325.0 << "\n"; else if (line_string.find("-volume") != string::npos) // volume in Liters - *out_file << " -volume " << volume * 1000.0 << - "\n"; + *out_file << " -volume " << volume * 1000.0 << "\n"; else if (line_string.find("-temperature") != string::npos) // temperature in °Celsius *out_file << " -temperature " << temp << "\n"; @@ -3334,42 +3378,42 @@ double unitfactor_l = 1, unitfactor_s = 1; { count++; speciesname = pqc_names[count]; - dval = pcs_vector[pqc_process[count]]->GetNodeValue( - index, - pqc_index - [count]); - if(dval < 1.0e-19) + dval = pcs_vector[pqc_process[count]]->GetNodeValue(index, pqc_index[count]); + if (dval < 1.0e-19) dval = 0.0; - // cout << "Testing index vectors: " << speciesname << " , with vectors: " << pqc_names[count] << ", " << pcs_vector[pqc_process[count]]->pcs_number << ", " << pqc_index[count]; + // cout << "Testing index vectors: " << speciesname << " , with vectors: " << pqc_names[count] << ", + // " << pcs_vector[pqc_process[count]]->pcs_number << ", " << pqc_index[count]; // cout << " Molar mass: " << dval << ", component / total mass: " << dval/mm << "\n"; // dval is molar mass of gas component, convert to partial pressure [Pa] if (mm > 0.0) partial_press = press * dval / mm; else partial_press = 0.0; - // cout << " partial pressure: " << partial_press << ", partial/total press: " << (partial_press/press) << "\n"; + // cout << " partial pressure: " << partial_press << ", partial/total press: " << + // (partial_press/press) << "\n"; - *out_file << " " << speciesname << " " << - partial_press / 101325.0 << " # comp " << "\n"; + *out_file << " " << speciesname << " " << partial_press / 101325.0 << " # comp " + << "\n"; } else - *out_file << line_string << "\n"; //write line unchanged + *out_file << line_string << "\n"; // write line unchanged } - } // end GAS_PHASE + } // end GAS_PHASE //------------------------------------------------------------------------------------------------------------- /* Schleife ueber Keyword SELECTED_OUTPUT */ // keyword found - if(line_string.find("SELECTED_OUTPUT") != string::npos) - if(index < 1) + if (line_string.find("SELECTED_OUTPUT") != string::npos) + if (index < 1) { - *out_file << "\n" << "SELECTED_OUTPUT" << "\n"; - while(line_string.find("#ende") == string::npos) + *out_file << "\n" + << "SELECTED_OUTPUT" + << "\n"; + while (line_string.find("#ende") == string::npos) { - pqc_infile.getline(line,MAX_ZEILE); + pqc_infile.getline(line, MAX_ZEILE); line_string = line; if (line_string.find("-file") != string::npos) - *out_file << "-file " << this->results_file_name << - "\n"; + *out_file << "-file " << this->results_file_name << "\n"; else *out_file << line_string << "\n"; } @@ -3377,14 +3421,16 @@ double unitfactor_l = 1, unitfactor_s = 1; // end SELECTED OUTPUT //------------------------------------------------------------------------------------------------------------- /* Schleife ueber Keyword PRINT */ - if(line_string.find("PRINT") != string::npos) // keyword found + if (line_string.find("PRINT") != string::npos) // keyword found - if(index < 1) + if (index < 1) { - *out_file << "\n" << "PRINT" << "\n"; - while(line_string.find("#ende") == string::npos) + *out_file << "\n" + << "PRINT" + << "\n"; + while (line_string.find("#ende") == string::npos) { - pqc_infile.getline(line,MAX_ZEILE); + pqc_infile.getline(line, MAX_ZEILE); line_string = line; *out_file << line_string << "\n"; } @@ -3393,40 +3439,42 @@ double unitfactor_l = 1, unitfactor_s = 1; //------------------------------------------------------------------------------------------------------------- /* Schleife ueber Keyword USER_PUNCH */ // keyword found - if(line_string.find("USER_PUNCH") != string::npos) - { - if(index < 1) + if (line_string.find("USER_PUNCH") != string::npos) + { + if (index < 1) { - *out_file << "\n" << "USER_PUNCH" << "\n"; + *out_file << "\n" + << "USER_PUNCH" + << "\n"; // Write Header n1 = this->rcml_number_of_master_species; n2 = this->rcml_number_of_equi_phases; n3 = this->rcml_number_of_ion_exchanges; n4 = this->rcml_number_of_gas_species; - n5 = this->rcml_number_of_kinetics; - n6 = this->rcml_number_of_secondary_species; + n5 = this->rcml_number_of_kinetics; + n6 = this->rcml_number_of_secondary_species; *out_file << "-head "; - for(i = 0; i < n1; i++) + for (i = 0; i < n1; i++) *out_file << " " << pqc_names[i]; *out_file << " pH "; *out_file << " H+ "; *out_file << " pe "; - for(i = n1 + 3; i < n1 + 3 + n2; i++) + for (i = n1 + 3; i < n1 + 3 + n2; i++) + *out_file << " " << pqc_names[i]; + for (i = n1 + 3 + n2; i < n1 + 3 + n2 + n3; i++) *out_file << " " << pqc_names[i]; - for(i = n1 + 3 + n2; i < n1 + 3 + n2 + n3; i++) + for (i = n1 + 3 + n2 + n3; i < n1 + 3 + n2 + n3 + n4; i++) *out_file << " " << pqc_names[i]; - for(i = n1 + 3 + n2 + n3; i < n1 + 3 + n2 + n3 + n4; i++) + for (i = n1 + 3 + n2 + n3 + n4; i < n1 + 3 + n2 + n3 + n4 + n5; i++) + *out_file << " " << pqc_names[i]; + for (i = n1 + 3 + n2 + n3 + n4 + n5; i < n1 + 3 + n2 + n3 + n4 + n5 + n6; i++) *out_file << " " << pqc_names[i]; - for(i=n1+3+n2+n3+n4; i 0) + if (n2 > 0) { *out_file << " 40 PUNCH "; - for(i = n1 + 3; i < n1 + 3 + n2; i++) + for (i = n1 + 3; i < n1 + 3 + n2; i++) *out_file << " EQUI(\"" << pqc_names[i] << "\"),"; *out_file << "\n"; } // Write ion exchangers - if(n3 > 0) + if (n3 > 0) { *out_file << " 60 PUNCH "; - for(i = n1 + 3 + n2; i < n1 + 3 + n2 + n3; i++) + for (i = n1 + 3 + n2; i < n1 + 3 + n2 + n3; i++) *out_file << " MOL(\"" << pqc_names[i] << "\"),"; *out_file << "\n"; } // Write gas phase species - if(n4 > 0) + if (n4 > 0) { *out_file << " 70 PUNCH "; - for(i = n1 + 3 + n2 + n3; i < n1 + 3 + n2 + n3 + n4; i++) + for (i = n1 + 3 + n2 + n3; i < n1 + 3 + n2 + n3 + n4; i++) *out_file << " GAS(\"" << pqc_names[i] << "\"),"; *out_file << "\n"; } - // Write (exclusively) kinetic species - if(n5 > 0){ - *out_file << " 80 PUNCH "; - for(i=n1+3+n2+n3+n4; i 0){ - for(i=0;i 0) + { + *out_file << " 80 PUNCH "; + for (i = n1 + 3 + n2 + n3 + n4; i < n1 + 3 + n2 + n3 + n4 + n5; i++) + *out_file << " KIN(\"" << pqc_names[i] << "\"),"; + *out_file << "\n"; + } + // Write additional output species + if (n6 > 0) + { + for (i = 0; i < n6; i++) + *out_file << " " << 90 + i * 10 << " " << additional_punches[i] << "\n"; + //*out_file << " 90 PUNCH "; + // for(i=n1+3+n2+n3+n4+n5; i> dummy >> dval >> this->rcml_number_of_pqcsteps >> dummy; CTimeDiscretization* m_tim = NULL; - if(time_vector.size() > 0) + if (time_vector.size() > 0) m_tim = time_vector[0]; else - cout << - "Error in WriteInputPhreeqc: no time discretization data !" << "\n"; + cout << "Error in WriteInputPhreeqc: no time discretization data !" + << "\n"; dval = m_tim->CalcTimeStep(); - *out_file << "-steps " << dval << " in " << - this->rcml_number_of_pqcsteps << " steps" << "\n"; - } // end -steps + *out_file << "-steps " << dval << " in " << this->rcml_number_of_pqcsteps << " steps" + << "\n"; + } // end -steps //------------------------------------------------------------------------------------------------------------- - if(line_string.find("KNOBS") != string::npos) - if(index < 1) + if (line_string.find("KNOBS") != string::npos) + if (index < 1) { - *out_file << "\n" << "KNOBS" << "\n"; - while(line_string.find("#ende") == string::npos) + *out_file << "\n" + << "KNOBS" + << "\n"; + while (line_string.find("#ende") == string::npos) { - pqc_infile.getline(line,MAX_ZEILE); + pqc_infile.getline(line, MAX_ZEILE); line_string = line; *out_file << line_string << "\n"; } } -//------------------------------------------------------------------------------------------------------------- - // Schleife ueber Keyword KINETICS - if(line_string.find("KINETICS")!=string::npos){ - stepsflag = 0; - *out_file << "\n" << "KINETICS " << index+1 << "\n"; - while(line_string.find("#ende")==string::npos){ - pqc_infile.getline(line,MAX_ZEILE); - line_string = line; - // Check if this is a new kinetic formulation, i.e. kinetics name = speciesname (phase) - if (line_string.find("# comp") !=string::npos){ - in.str(line_string); - in >> speciesname ; - in.clear(); - found = 0; - for(int i=0;icount) count=i; - found=i; - break; - } - *out_file << line_string << "\n"; - } - // This is just to avoid mix-up with subkeyword "-m" - else if(line_string.find("-m0")!=string::npos) { // keyword found - *out_file << line_string << "\n"; - } - // here get current node concentration after transport - else if(line_string.find("-m")!=string::npos) { // keyword found - - dval = pcs_vector[pqc_process[found]]->GetNodeValue(index,pqc_index[found]); - if(dval < 1.0e-19) dval = 0.0; - -//CB 19.1.2011 - // based on porosity, calculate molality mj before coputing equilirium chemistry - if(m_rei){ - if(m_rei->unitconversion) { - idx = pcs_vector[pqc_process[found]]->GetProcessComponentNumber(); - //mi,w = Ci,w * n *55.5 / CH2O - //mi,s = Ci,w * (1-n) *55.5 / CH2O - if(cp_vec[idx]->transport_phase==0) // liquid phase - dval *= unitfactor_l; - else if(cp_vec[idx]->transport_phase==1) // solid phase - dval *= unitfactor_s; - } - } - ////m_pcs = PCSGet("MASS_TRANSPORT", speciesname);// CB HS update - //m_pcs = cp_vec[cp_name_2_idx[speciesname]]->getProcess(); - //idx = m_pcs->GetNodeValueIndex(speciesname)+1; // new time level - //dval = m_pcs->GetNodeValue(index,idx); - *out_file << "-m " << dval << "\n"; - } - // time discretization for phreeqc - else if(line_string.find("-steps")!=string::npos) { - if(stepsflag == 0) { // keyword found - stepsflag++; - in.str(line_string); - in >> dummy >> dval >> dummy >> this->rcml_number_of_pqcsteps >> dummy; - in.clear(); - CTimeDiscretization *m_tim = NULL; - if(time_vector.size()>0) - m_tim = time_vector[0]; - else - cout << "Error in WriteInputPhreeqc: no time discretization data !" << "\n"; - dval = m_tim->CalcTimeStep(); - *out_file << "-steps " << dval << " in " << this->rcml_number_of_pqcsteps << " steps" << "\n"; - } - } // end -steps - // any other subkeyword - else{ - line_string = line; - *out_file << line_string << "\n"; - } - } - } -//------------------------------------------------------------------------------------------------------------- - // Schleife ueber Keyword RATES - if(line_string.find("RATES")!=string::npos){ - *out_file << "\n" << "RATES " << index+1 << "\n"; - while(line_string.find("#ende")==string::npos){ - pqc_infile.getline(line,MAX_ZEILE); - line_string = line; - *out_file << line_string << "\n"; - } - } -//------------------------------------------------------------------------------------------------------------- - - - } /*end while zeilenweises lesen */ - - *out_file << "END" << "\n" << "\n"; + //------------------------------------------------------------------------------------------------------------- + // Schleife ueber Keyword KINETICS + if (line_string.find("KINETICS") != string::npos) + { + stepsflag = 0; + *out_file << "\n" + << "KINETICS " << index + 1 << "\n"; + while (line_string.find("#ende") == string::npos) + { + pqc_infile.getline(line, MAX_ZEILE); + line_string = line; + // Check if this is a new kinetic formulation, i.e. kinetics name = speciesname (phase) + if (line_string.find("# comp") != string::npos) + { + in.str(line_string); + in >> speciesname; + in.clear(); + found = 0; + for (int i = 0; i < int(pqc_index.size()); i++) + if (speciesname.compare(pqc_names[i]) == 0) + { + if (i > count) + count = i; + found = i; + break; + } + *out_file << line_string << "\n"; + } + // This is just to avoid mix-up with subkeyword "-m" + else if (line_string.find("-m0") != string::npos) + { // keyword found + *out_file << line_string << "\n"; + } + // here get current node concentration after transport + else if (line_string.find("-m") != string::npos) + { // keyword found + + dval = pcs_vector[pqc_process[found]]->GetNodeValue(index, pqc_index[found]); + if (dval < 1.0e-19) + dval = 0.0; + + // CB 19.1.2011 + // based on porosity, calculate molality mj before coputing equilirium chemistry + if (m_rei) + { + if (m_rei->unitconversion) + { + idx = pcs_vector[pqc_process[found]]->GetProcessComponentNumber(); + // mi,w = Ci,w * n *55.5 / CH2O + // mi,s = Ci,w * (1-n) *55.5 / CH2O + if (cp_vec[idx]->transport_phase == 0) // liquid phase + dval *= unitfactor_l; + else if (cp_vec[idx]->transport_phase == 1) // solid phase + dval *= unitfactor_s; + } + } + ////m_pcs = PCSGet("MASS_TRANSPORT", speciesname);// CB HS update + // m_pcs = cp_vec[cp_name_2_idx[speciesname]]->getProcess(); + // idx = m_pcs->GetNodeValueIndex(speciesname)+1; // new time level + // dval = m_pcs->GetNodeValue(index,idx); + *out_file << "-m " << dval << "\n"; + } + // time discretization for phreeqc + else if (line_string.find("-steps") != string::npos) + { + if (stepsflag == 0) + { // keyword found + stepsflag++; + in.str(line_string); + in >> dummy >> dval >> dummy >> this->rcml_number_of_pqcsteps >> dummy; + in.clear(); + CTimeDiscretization* m_tim = NULL; + if (time_vector.size() > 0) + m_tim = time_vector[0]; + else + cout << "Error in WriteInputPhreeqc: no time discretization data !" + << "\n"; + dval = m_tim->CalcTimeStep(); + *out_file << "-steps " << dval << " in " << this->rcml_number_of_pqcsteps << " steps" + << "\n"; + } + } // end -steps + // any other subkeyword + else + { + line_string = line; + *out_file << line_string << "\n"; + } + } + } + //------------------------------------------------------------------------------------------------------------- + // Schleife ueber Keyword RATES + if (line_string.find("RATES") != string::npos) + { + *out_file << "\n" + << "RATES " << index + 1 << "\n"; + while (line_string.find("#ende") == string::npos) + { + pqc_infile.getline(line, MAX_ZEILE); + line_string = line; + *out_file << line_string << "\n"; + } + } + //------------------------------------------------------------------------------------------------------------- + + } /*end while zeilenweises lesen */ + + *out_file << "END" + << "\n" + << "\n"; pqc_infile.close(); -// out_file.close(); + // out_file.close(); return 1; } @@ -3630,59 +3705,59 @@ double unitfactor_l = 1, unitfactor_s = 1; int REACT::Call_Phreeqc(void) { -//WH: run IPQC +// WH: run IPQC #ifdef OGS_FEM_IPQC - std::string ipqc_database; //WH: database name for IPQC - int returnCode = 1; - int pqcId = CreateIPhreeqc(); // create IPQC instance - - if(this->file_name_database.size()==0) - ipqc_database = "phreeqc.dat"; - else - ipqc_database = this->file_name_database; - - // Load phreeqc database - if(LoadDatabase(pqcId, (FilePath + ipqc_database).c_str()) > 0) - { - OutputErrorString(pqcId); - returnCode = 0; - } - - //run the specified phreeqc input file "phinp.dat". - if(returnCode == 1) - { - //Sets the selected-output file switch on, so that phreeqc will write output to the SELECTED_OUTPUT file "phout_sel.dat" - SetSelectedOutputFileOn(pqcId, 1); - - if(RunFile(pqcId, "phinp.dat") > 0) - { - OutputErrorString(pqcId); - returnCode = 0; - } - } - - if(DestroyIPhreeqc(pqcId) != IPQ_OK) // destroy IPQC instance - { - OutputErrorString(pqcId); - returnCode = 0; - } - - return returnCode; -#else + std::string ipqc_database; // WH: database name for IPQC + int returnCode = 1; + int pqcId = CreateIPhreeqc(); // create IPQC instance + + if (this->file_name_database.size() == 0) + ipqc_database = "phreeqc.dat"; + else + ipqc_database = this->file_name_database; + + // Load phreeqc database + if (LoadDatabase(pqcId, (FilePath + ipqc_database).c_str()) > 0) + { + OutputErrorString(pqcId); + returnCode = 0; + } + + // run the specified phreeqc input file "phinp.dat". + if (returnCode == 1) + { + // Sets the selected-output file switch on, so that phreeqc will write output to the SELECTED_OUTPUT file + // "phout_sel.dat" + SetSelectedOutputFileOn(pqcId, 1); + + if (RunFile(pqcId, "phinp.dat") > 0) + { + OutputErrorString(pqcId); + returnCode = 0; + } + } + + if (DestroyIPhreeqc(pqcId) != IPQ_OK) // destroy IPQC instance + { + OutputErrorString(pqcId); + returnCode = 0; + } - std::string mm_phreeqc = "phreeqc phinp.dat phinp.out "; - //const char *m_phreeqc; - // m_phreeqc="phrqc phinp.dat phinp.out phreeqc.dat"; + return returnCode; +#else + std::string mm_phreeqc = "phreeqc phinp.dat phinp.out "; + // const char *m_phreeqc; + // m_phreeqc="phrqc phinp.dat phinp.out phreeqc.dat"; - if(this->file_name_database.size()==0) - mm_phreeqc+="phreeqc.dat"; - else - mm_phreeqc+=this->file_name_database; + if (this->file_name_database.size() == 0) + mm_phreeqc += "phreeqc.dat"; + else + mm_phreeqc += this->file_name_database; - char * m_phreeqc; - m_phreeqc = new char [mm_phreeqc.size()+1]; - strcpy (m_phreeqc, mm_phreeqc.c_str()); + char* m_phreeqc; + m_phreeqc = new char[mm_phreeqc.size() + 1]; + strcpy(m_phreeqc, mm_phreeqc.c_str()); #ifdef PHREEQC if (!system(m_phreeqc)) // DisplayMsgLn("Phreeqc runs succesfully! "); @@ -3722,7 +3797,7 @@ int REACT::Call_Phreeqc(void) int REACT::ReadOutputPhreeqc(char* fout) { int ok = 0; - int nj,nk, ntot; + int nj, nk, ntot; int i, j, ii, zeilenlaenge = 10000, anz; char str[4000]; double dval; @@ -3735,43 +3810,42 @@ int REACT::ReadOutputPhreeqc(char* fout) return 0; } /* get total number of species in PHREEQC output file */ - ntot = rcml_number_of_master_species + 2 + rcml_number_of_equi_phases + - rcml_number_of_ion_exchanges; + ntot = rcml_number_of_master_species + 2 + rcml_number_of_equi_phases + rcml_number_of_ion_exchanges; /* get lines to skip */ anz = this->rcml_number_of_pqcsteps; - ein.getline(str,zeilenlaenge); /* lies header-Zeile */ + ein.getline(str, zeilenlaenge); /* lies header-Zeile */ for (i = 0; i < this->nodenumber; i++) { - if(this->rateflag[i] > 0) + if (this->rateflag[i] > 0) { /* skip one line, if keyword steps larger than 1 even more lines */ - for(j = 0; j < anz; j++) - for(ii = 0; ii < ntot; ii++) + for (j = 0; j < anz; j++) + for (ii = 0; ii < ntot; ii++) ein >> dval; // if(1 == 1){ /*-----------Read the concentration of all master species and pH pe values-------*/ for (j = 0; j < rcml_number_of_master_species + 2; j++) - if(ein >> dval) + if (ein >> dval) this->val_out[j][i] = dval; /*--------------------Read the concentration of all equilibrium phases -------*/ nj = rcml_number_of_master_species; for (j = nj + 2; j < nj + 2 + rcml_number_of_equi_phases; j++) - if(ein >> dval) + if (ein >> dval) this->val_out[j][i] = dval; /*--------------------Read the concentration of all ion exchangers -------*/ nk = rcml_number_of_equi_phases; for (j = nj + nk + 2; j < nj + nk + 2 + rcml_number_of_ion_exchanges; j++) - if(ein >> dval) + if (ein >> dval) this->val_out[j][i] = dval; // } - } //if rateflag + } // if rateflag else - for(j = 0; j < ntot; j++) - this->val_out[j][i] = this->val_in[j][i]; + for (j = 0; j < ntot; j++) + this->val_out[j][i] = this->val_in[j][i]; } ok = 1; @@ -3800,262 +3874,275 @@ int REACT::ReadOutputPhreeqc(char* fout) ************************************************************************************************/ int REACT::ReadOutputPhreeqcNew(void) { -int ok = 0; -int ntot; -int index, j, ii, zeilenlaenge=10000, anz, idx; -char str[4000]; -double dval, dval1; -string speciesname; -//WW CRFProcess* m_pcs = NULL; -int n1, n2, n3, n4, n5, n6, dix=0; -CTimeDiscretization* m_tim = NULL; -double unitfactor_l = 1, unitfactor_s = 1; - bool initial = false; - -//CB 19.1.2011 -// Get the reaction interface data -REACTINT *m_rei = NULL; -if(REACTINT_vec.size()>0) - m_rei = REACTINT_vec[0]; - -// Get time step number -// CB dix is no longer required, as we now do all reactions on new TL -// and copy to old TL before first time step -if(time_vector.size()>0){ - m_tim = time_vector[0]; - if(m_tim->step_current == 0) // instead, do not update values for solid species in initial pqc computation - initial = true; //dix = -1; -} + int ok = 0; + int ntot; + int index, j, ii, zeilenlaenge = 10000, anz, idx; + char str[4000]; + double dval, dval1; + string speciesname; + // WW CRFProcess* m_pcs = NULL; + int n1, n2, n3, n4, n5, n6, dix = 0; + CTimeDiscretization* m_tim = NULL; + double unitfactor_l = 1, unitfactor_s = 1; + bool initial = false; -ifstream ein (this->results_file_name.data(),ios::in); -if (!ein) -{ - cout << "The selected output file doesn't exist!!!" << "\n"; - return 0; -} -n1 = this->rcml_number_of_master_species; -n2 = this->rcml_number_of_equi_phases; -n3 = this->rcml_number_of_ion_exchanges; -n4 = this->rcml_number_of_gas_species; - n5 = this->rcml_number_of_kinetics; - n6 = this->rcml_number_of_secondary_species; -// get total number of species in PHREEQC output file - ntot = rcml_number_of_master_species + 3 + rcml_number_of_equi_phases + rcml_number_of_ion_exchanges - + rcml_number_of_gas_species + rcml_number_of_kinetics + rcml_number_of_secondary_species; -/* get lines to skip */ -anz = this->rcml_number_of_pqcsteps; - -ein.getline(str,zeilenlaenge); /* lies header-Zeile */ - -for (index = 0; index < this->nodenumber; index++) -{ - if(this->rateflag[index] > 0) - { -//CB 19.1.2011 - // calculate unit conversion factors for phreeqc molarity-->molality - if(m_rei) { - if(m_rei->unitconversion){ - m_rei->CalcUnitConversionFactors(index, &unitfactor_l, &unitfactor_s, true); - //unitfactor_l = MOLH2OPERKG / m_rei->water_conc[index]; - //unitfactor_s = (1 - m_rei->node_porosity[index]) * MOLH2OPERKG / (m_rei->water_conc[index] * m_rei->node_porosity[index] * m_rei->GetWaterSaturation(index)); - //if(unitfactor_s ==0) unitfactor_s = (1 - m_rei->node_porosity[index]) * MOLH2OPERKG / (m_rei->water_conc[index] * m_rei->node_porosity[index] * 1); - } - } - /* skip one line, if keyword steps larger than 1 even more lines */ - for(j = 0; j < anz; j++) - for(ii = 0; ii < ntot; ii++) - ein >> dval; - // if(1 == 1){ - /*-----------Read the concentration of all master species and pH pe values-------*/ - for (j = 0; j < n1; j++) - { - if(ein >> dval) - { - // this->val_out[j][i] = dval; - // speciesname = pqc_names[j]; - // m_pcs = PCSGet("MASS_TRANSPORT",speciesname); - // idx = m_pcs->GetNodeValueIndex(speciesname)+1; - // m_pcs->SetNodeValue(index,idx,dval); -//CB 19.1.2011 - // convert molality -> molarity - if(m_rei) { - if(m_rei->unitconversion){ - idx = pcs_vector[pqc_process[j]]->GetProcessComponentNumber(); - //mi,w = Ci,w * n *55.5 / CH2O - //mi,s = Ci,w * (1-n) *55.5 / CH2O - if(cp_vec[idx]->transport_phase==0) // liquid phase - dval /= unitfactor_l; - else if(cp_vec[idx]->transport_phase==1) { // solid phase - dval /= unitfactor_s; - cout << " phreeqc concentration " << dval << " " << unitfactor_s << "\n"; - } - } - } - pcs_vector[pqc_process[j]]->SetNodeValue(index,pqc_index[j]+dix,dval); - // if(index <2) cout << " Read aqu. for " << pqc_names[j] << " " << dval << "\n"; - - - } - - } - - - -/* Read pH and pe */ -if(ein >> dval) // read pH -{ - j = n1; - pcs_vector[pqc_process[j]]->SetNodeValue(index, - pqc_index[j] + dix, - dval); - // if(index <2) cout << " Read for pH: " << dval << ", "; -} -if(ein >> dval) // read H+ -{ - j++; -//CB 19.1.2011 - // convert molality -> molarity - if(m_rei) - if(m_rei->unitconversion) - dval /= unitfactor_l; // H+ mol/kg --> mol/m³l - if(this->gamma_Hplus > 0){ - //m_pcs = pcs_vector[pqc_process[j]]; - //if(index<2) cout << " H+: " << dval << ", "; - pcs_vector[pqc_process[j]]->SetNodeValue(index,pqc_index[j]+dix,dval); - } -} -if(ein >> dval) // read pe -{ - j++; - //WW m_pcs = pcs_vector[pqc_process[j]]; - // if(index <2) cout << " pe: " << dval << "\n"; - pcs_vector[pqc_process[j]]->SetNodeValue(index, - pqc_index[j] + dix, - dval); -} -/*--------------------Read the concentration of all equilibrium phases -------*/ -for (j = n1 + 3; j < n1 + 3 + n2; j++) -{ - if(ein >> dval){ - //speciesname = pqc_names[j]; - ////m_pcs = PCSGet("MASS_TRANSPORT",speciesname);// CB HS update - //m_pcs = cp_vec[cp_name_2_idx[speciesname]]->getProcess(); - //idx = m_pcs->GetNodeValueIndex(speciesname)+1; - //m_pcs->SetNodeValue(index,idx,dval); - //CB 19.1.2011 - // convert molality -> molarity, equilibrium species = solid phase species - if(m_rei){ - if(m_rei->unitconversion){ - idx = pcs_vector[pqc_process[j]]->GetProcessComponentNumber(); - //mi,w = Ci,w * n *55.5 / CH2O - //mi,s = Ci,w * (1-n) *55.5 / CH2O - if(cp_vec[idx]->transport_phase==0) // liquid phase - dval /= unitfactor_l; - else if(cp_vec[idx]->transport_phase==1) // solid phase - dval /= unitfactor_s; - } - } - if(initial==false) - pcs_vector[pqc_process[j]]->SetNodeValue(index,pqc_index[j]+dix,dval); - // if(index <2) cout << " Read equi. for " << pqc_names[j] << " " << dval << "\n"; - } -} + // CB 19.1.2011 + // Get the reaction interface data + REACTINT* m_rei = NULL; + if (REACTINT_vec.size() > 0) + m_rei = REACTINT_vec[0]; + + // Get time step number + // CB dix is no longer required, as we now do all reactions on new TL + // and copy to old TL before first time step + if (time_vector.size() > 0) + { + m_tim = time_vector[0]; + if (m_tim->step_current == 0) // instead, do not update values for solid species in initial pqc computation + initial = true; // dix = -1; + } -/*--------------------Read the concentration of all ion exchangers -------*/ -for (j = n1 + 3 + n2; j < n1 + 3 + n2 + n3; j++){ - if(ein >> dval) + ifstream ein(this->results_file_name.data(), ios::in); + if (!ein) + { + cout << "The selected output file doesn't exist!!!" + << "\n"; + return 0; + } + n1 = this->rcml_number_of_master_species; + n2 = this->rcml_number_of_equi_phases; + n3 = this->rcml_number_of_ion_exchanges; + n4 = this->rcml_number_of_gas_species; + n5 = this->rcml_number_of_kinetics; + n6 = this->rcml_number_of_secondary_species; + // get total number of species in PHREEQC output file + ntot = rcml_number_of_master_species + 3 + rcml_number_of_equi_phases + rcml_number_of_ion_exchanges + + rcml_number_of_gas_species + rcml_number_of_kinetics + rcml_number_of_secondary_species; + /* get lines to skip */ + anz = this->rcml_number_of_pqcsteps; + + ein.getline(str, zeilenlaenge); /* lies header-Zeile */ + + for (index = 0; index < this->nodenumber; index++) + { + if (this->rateflag[index] > 0) + { + // CB 19.1.2011 + // calculate unit conversion factors for phreeqc molarity-->molality + if (m_rei) + { + if (m_rei->unitconversion) + { + m_rei->CalcUnitConversionFactors(index, &unitfactor_l, &unitfactor_s, true); + // unitfactor_l = MOLH2OPERKG / m_rei->water_conc[index]; + // unitfactor_s = (1 - m_rei->node_porosity[index]) * MOLH2OPERKG / (m_rei->water_conc[index] * + // m_rei->node_porosity[index] * m_rei->GetWaterSaturation(index)); + // if(unitfactor_s ==0) unitfactor_s = (1 - m_rei->node_porosity[index]) * MOLH2OPERKG / + // (m_rei->water_conc[index] * m_rei->node_porosity[index] * 1); + } + } + /* skip one line, if keyword steps larger than 1 even more lines */ + for (j = 0; j < anz; j++) + for (ii = 0; ii < ntot; ii++) + ein >> dval; + // if(1 == 1){ + /*-----------Read the concentration of all master species and pH pe values-------*/ + for (j = 0; j < n1; j++) + { + if (ein >> dval) + { + // this->val_out[j][i] = dval; + // speciesname = pqc_names[j]; + // m_pcs = PCSGet("MASS_TRANSPORT",speciesname); + // idx = m_pcs->GetNodeValueIndex(speciesname)+1; + // m_pcs->SetNodeValue(index,idx,dval); + // CB 19.1.2011 + // convert molality -> molarity + if (m_rei) + { + if (m_rei->unitconversion) + { + idx = pcs_vector[pqc_process[j]]->GetProcessComponentNumber(); + // mi,w = Ci,w * n *55.5 / CH2O + // mi,s = Ci,w * (1-n) *55.5 / CH2O + if (cp_vec[idx]->transport_phase == 0) // liquid phase + dval /= unitfactor_l; + else if (cp_vec[idx]->transport_phase == 1) + { // solid phase + dval /= unitfactor_s; + cout << " phreeqc concentration " << dval << " " << unitfactor_s << "\n"; + } + } + } + pcs_vector[pqc_process[j]]->SetNodeValue(index, pqc_index[j] + dix, dval); + // if(index <2) cout << " Read aqu. for " << pqc_names[j] << " " << dval << "\n"; + } + } + + /* Read pH and pe */ + if (ein >> dval) // read pH + { + j = n1; + pcs_vector[pqc_process[j]]->SetNodeValue(index, pqc_index[j] + dix, dval); + // if(index <2) cout << " Read for pH: " << dval << ", "; + } + if (ein >> dval) // read H+ + { + j++; + // CB 19.1.2011 + // convert molality -> molarity + if (m_rei) + if (m_rei->unitconversion) + dval /= unitfactor_l; // H+ mol/kg --> mol/m³l + if (this->gamma_Hplus > 0) + { + // m_pcs = pcs_vector[pqc_process[j]]; + // if(index<2) cout << " H+: " << dval << ", "; + pcs_vector[pqc_process[j]]->SetNodeValue(index, pqc_index[j] + dix, dval); + } + } + if (ein >> dval) // read pe + { + j++; + // WW m_pcs = pcs_vector[pqc_process[j]]; + // if(index <2) cout << " pe: " << dval << "\n"; + pcs_vector[pqc_process[j]]->SetNodeValue(index, pqc_index[j] + dix, dval); + } + /*--------------------Read the concentration of all equilibrium phases -------*/ + for (j = n1 + 3; j < n1 + 3 + n2; j++) + { + if (ein >> dval) + { + // speciesname = pqc_names[j]; + ////m_pcs = PCSGet("MASS_TRANSPORT",speciesname);// CB HS update + // m_pcs = cp_vec[cp_name_2_idx[speciesname]]->getProcess(); + // idx = m_pcs->GetNodeValueIndex(speciesname)+1; + // m_pcs->SetNodeValue(index,idx,dval); + // CB 19.1.2011 + // convert molality -> molarity, equilibrium species = solid phase species + if (m_rei) + { + if (m_rei->unitconversion) + { + idx = pcs_vector[pqc_process[j]]->GetProcessComponentNumber(); + // mi,w = Ci,w * n *55.5 / CH2O + // mi,s = Ci,w * (1-n) *55.5 / CH2O + if (cp_vec[idx]->transport_phase == 0) // liquid phase + dval /= unitfactor_l; + else if (cp_vec[idx]->transport_phase == 1) // solid phase + dval /= unitfactor_s; + } + } + if (initial == false) + pcs_vector[pqc_process[j]]->SetNodeValue(index, pqc_index[j] + dix, dval); + // if(index <2) cout << " Read equi. for " << pqc_names[j] << " " << dval << "\n"; + } + } + + /*--------------------Read the concentration of all ion exchangers -------*/ + for (j = n1 + 3 + n2; j < n1 + 3 + n2 + n3; j++) + { + if (ein >> dval) /* speciesname = pqc_names[j]; m_pcs = PCSGet("MASS_TRANSPORT",speciesname); idx = m_pcs->GetNodeValueIndex(speciesname)+1; m_pcs->SetNodeValue(index,idx,dval); */ -if(initial==false) - pcs_vector[pqc_process[j]]->SetNodeValue(index, - pqc_index[j] + dix, - dval); - // cout << " Read ex. for " << pqc_names[j] << " " << dval << "\n"; -} -/*--------------------Read the concentration of all gas phase species -------*/ - for (j=n1+3+n2+n3; j> dval){ -//CB 19.1.2011 -// we should probably do something about gas species concentration unit conversion... - pcs_vector[pqc_process[j]]->SetNodeValue(index,pqc_index[j]+dix,dval); - if(index <2) cout << " Read gas phase for " << pqc_names[j] << " " << dval << "\n"; - } - } -/*--------------------Read the concentration of all (exclusively) kinetic species -------*/ -for (j=n1+3+n2+n3+n4; j> dval){ - -//CB 19.1.2011 - // convert molality -> molarity - if(m_rei) { - if(m_rei->unitconversion){ - idx = pcs_vector[pqc_process[j]]->GetProcessComponentNumber(); - //mi,w = Ci,w * n *55.5 / CH2O - //mi,s = Ci,w * (1-n) *55.5 / CH2O - if(cp_vec[idx]->transport_phase==0) // liquid phase - dval /= unitfactor_l; - else if(cp_vec[idx]->transport_phase==1) // solid phase - dval /= unitfactor_s; - } - } - if(initial==false) - pcs_vector[pqc_process[j]]->SetNodeValue(index,pqc_index[j]+dix,dval); - //if(index <2) cout << " Read kinetic for " << pqc_names[j] << " " << dval << "\n"; - } -} + if (initial == false) + pcs_vector[pqc_process[j]]->SetNodeValue(index, pqc_index[j] + dix, dval); + // cout << " Read ex. for " << pqc_names[j] << " " << dval << "\n"; + } + /*--------------------Read the concentration of all gas phase species -------*/ + for (j = n1 + 3 + n2 + n3; j < n1 + 3 + n2 + n3 + n4; j++) + { + if (ein >> dval) + { + // CB 19.1.2011 + // we should probably do something about gas species concentration unit conversion... + pcs_vector[pqc_process[j]]->SetNodeValue(index, pqc_index[j] + dix, dval); + if (index < 2) + cout << " Read gas phase for " << pqc_names[j] << " " << dval << "\n"; + } + } + /*--------------------Read the concentration of all (exclusively) kinetic species -------*/ + for (j = n1 + 3 + n2 + n3 + n4; j < n1 + 3 + n2 + n3 + n4 + n5; j++) + { + if (ein >> dval) + { + // CB 19.1.2011 + // convert molality -> molarity + if (m_rei) + { + if (m_rei->unitconversion) + { + idx = pcs_vector[pqc_process[j]]->GetProcessComponentNumber(); + // mi,w = Ci,w * n *55.5 / CH2O + // mi,s = Ci,w * (1-n) *55.5 / CH2O + if (cp_vec[idx]->transport_phase == 0) // liquid phase + dval /= unitfactor_l; + else if (cp_vec[idx]->transport_phase == 1) // solid phase + dval /= unitfactor_s; + } + } + if (initial == false) + pcs_vector[pqc_process[j]]->SetNodeValue(index, pqc_index[j] + dix, dval); + // if(index <2) cout << " Read kinetic for " << pqc_names[j] << " " << dval << "\n"; + } + } -/*--------------------Read the concentration of all (additional) secondary species -------*/ -for (j=n1+3+n2+n3+n4+n5; j> dval){ - -//CB 19.1.2011 - // convert molality -> molarity - if((additional_punches[j-(n1+3+n2+n3+n4+n5)].find(" MOL")!=string::npos) || - (additional_punches[j-(n1+3+n2+n3+n4+n5)].find(" ACT")!=string::npos)){ - if(m_rei) { - if(m_rei->unitconversion){ - idx = pcs_vector[pqc_process[j]]->GetProcessComponentNumber(); - //mi,w = Ci,w * n *55.5 / CH2O - //mi,s = Ci,w * (1-n) *55.5 / CH2O - if(cp_vec[idx]->transport_phase==0) // liquid phase - dval /= unitfactor_l; - else if(cp_vec[idx]->transport_phase==1) // solid phase - dval /= unitfactor_s; - } - } - } - if(initial==false) - pcs_vector[pqc_process[j]]->SetNodeValue(index,pqc_index[j]+dix,dval); - //if(index <2) cout << " Read kinetic for " << pqc_names[j] << " " << dval << "\n"; - } - } - }//if rateflag - - - // Determine new gamma_Hplus - if (gamma_Hplus > 0) - { -//CB 19.1.2011 - // Calculate new gamma_Hplus - // node value is in units of molarity: mol/m³ - dval = pcs_vector[pqc_process[n1+1]]->GetNodeValue(index,pqc_index[n1+1]+dix); // molarity H+ - if(m_rei) - if(m_rei->unitconversion){ - dval *= unitfactor_l; // mol/m³l --> mol/kg H2o - dval1 = pcs_vector[pqc_process[n1]]->GetNodeValue(index,pqc_index[n1]+dix); - dval1 = pow(10.0,-dval1); // activity H+ from pH - this->gamma_Hplus = dval1/dval; - // cout << " New gamma_Hplus: " << gamma_Hplus << "\n"; - } - - } // end for(index... -} + /*--------------------Read the concentration of all (additional) secondary species -------*/ + for (j = n1 + 3 + n2 + n3 + n4 + n5; j < n1 + 3 + n2 + n3 + n4 + n5 + n6; j++) + { + if (ein >> dval) + { + // CB 19.1.2011 + // convert molality -> molarity + if ((additional_punches[j - (n1 + 3 + n2 + n3 + n4 + n5)].find(" MOL") != string::npos) + || (additional_punches[j - (n1 + 3 + n2 + n3 + n4 + n5)].find(" ACT") != string::npos)) + { + if (m_rei) + { + if (m_rei->unitconversion) + { + idx = pcs_vector[pqc_process[j]]->GetProcessComponentNumber(); + // mi,w = Ci,w * n *55.5 / CH2O + // mi,s = Ci,w * (1-n) *55.5 / CH2O + if (cp_vec[idx]->transport_phase == 0) // liquid phase + dval /= unitfactor_l; + else if (cp_vec[idx]->transport_phase == 1) // solid phase + dval /= unitfactor_s; + } + } + } + if (initial == false) + pcs_vector[pqc_process[j]]->SetNodeValue(index, pqc_index[j] + dix, dval); + // if(index <2) cout << " Read kinetic for " << pqc_names[j] << " " << dval << "\n"; + } + } + } // if rateflag + + // Determine new gamma_Hplus + if (gamma_Hplus > 0) + { + // CB 19.1.2011 + // Calculate new gamma_Hplus + // node value is in units of molarity: mol/m³ + dval = pcs_vector[pqc_process[n1 + 1]]->GetNodeValue(index, pqc_index[n1 + 1] + dix); // molarity H+ + if (m_rei) + if (m_rei->unitconversion) + { + dval *= unitfactor_l; // mol/m³l --> mol/kg H2o + dval1 = pcs_vector[pqc_process[n1]]->GetNodeValue(index, pqc_index[n1] + dix); + dval1 = pow(10.0, -dval1); // activity H+ from pH + this->gamma_Hplus = dval1 / dval; + // cout << " New gamma_Hplus: " << gamma_Hplus << "\n"; + } + + } // end for(index... + } ok = 1; ein.close(); - // additional_punches.clear(); + // additional_punches.clear(); return ok; } @@ -4073,7 +4160,7 @@ for (j=n1+3+n2+n3+n4+n5; j 0.0) + if (dt > 0.0) schwellwert = 1.0e-4 / dt; ni = this->nodenumber; @@ -4111,65 +4198,65 @@ void REACT::CalculateReactionRateFlag(void) /* Calculate chemmistry all rc->countsteps timesteps as well as always in the first and second timestep */ counti++; // test = (aktueller_zeitschritt+1) % rc->count7steps; - if(((aktueller_zeitschritt + 1) % this->countsteps) == 0) + if (((aktueller_zeitschritt + 1) % this->countsteps) == 0) counti = 0; - if(aktueller_zeitschritt < 2) + if (aktueller_zeitschritt < 2) counti = 0; - if(counti == 0) - for(i = 0; i < ni; i++) + if (counti == 0) + for (i = 0; i < ni; i++) this->rateflag[i] = 1; else { - //determine for each node separately + // determine for each node separately DisplayMsgLn(" sum of rates "); - helprates = (double*) Malloc(np * sizeof(double)); - for(j = 0; j < np; j++) + helprates = (double*)Malloc(np * sizeof(double)); + for (j = 0; j < np; j++) helprates[j] = 0.0; /* Go through all nodes */ - for(i = 0; i < ni; i++) + for (i = 0; i < ni; i++) { rate = 0.0; - for(comp = 0; comp < np; comp++) + for (comp = 0; comp < np; comp++) rate = rate + fabs(this->rate[comp][i] * this->val_in[comp][i]); DisplayLong(i); DisplayMsg(": "); - DisplayDouble(rate,0,0); + DisplayDouble(rate, 0, 0); DisplayMsgLn(" "); - if(rate > schwellwert) + if (rate > schwellwert) this->rateflag[i] = 1; else this->rateflag[i] = 0; - } //end for(irateflag[i]; - for(i = 0; i < ni; i++) - if(this->rateflag[i] > 0) - //get sourrounding elements and nodes + for (i = 0; i < ni; i++) + if (this->rateflag[i] > 0) + // get sourrounding elements and nodes /* Aussuchen der Nachbarknoten */ - SetNeighborNodesActive (i,level,help); + SetNeighborNodesActive(i, level, help); // DisplayMsgLn(" "); - //set nodes active finally + // set nodes active finally j = 0; - for(i = 0; i < ni; i++) + for (i = 0; i < ni; i++) { DisplayMsg(" i: "); DisplayLong(i); DisplayMsg(", this->rf[i]: "); DisplayLong(this->rateflag[i]); DisplayMsg(", this->rate[i]: "); - DisplayDouble(this->rate[0][i],0,0); + DisplayDouble(this->rate[0][i], 0, 0); DisplayMsg(", help[i]: "); DisplayLong(help[i]); DisplayMsgLn(" "); - if(help[i] > 0) + if (help[i] > 0) { this->rateflag[i] = 1; j++; @@ -4179,9 +4266,9 @@ void REACT::CalculateReactionRateFlag(void) DisplayLong(j); DisplayMsgLn(" "); - //give back storage - help = (int*) Free(help); - helprates = (double*) Free(helprates); + // give back storage + help = (int*)Free(help); + helprates = (double*)Free(helprates); } } @@ -4198,11 +4285,11 @@ void REACT::CalculateReactionRateFlag(void) void REACT::GetTransportResults(void) { CRFProcess* pcs = NULL; - int timelevel = 1; // concentrations are in new timelevel + int timelevel = 1; // concentrations are in new timelevel // int phase = 0; //single phase so far size_t np(pcs_vector.size()); - for (size_t j = 0; j < np; j++) // for all processes + for (size_t j = 0; j < np; j++) // for all processes { pcs = pcs_vector[j]; // if (pcs->pcs_type_name.compare("MASS_TRANSPORT") == 0) { // if it is a mass transport process @@ -4212,21 +4299,17 @@ void REACT::GetTransportResults(void) for (long i = 0; i < nodenumber; i++) { // get concentration values - val_in[comp][i] = pcs->GetNodeValue(i, - pcs->GetNodeValueIndex( - pcs-> - pcs_primary_function_name - [0]) - + timelevel); - //MX, 01.2005 + val_in[comp][i] + = pcs->GetNodeValue(i, pcs->GetNodeValueIndex(pcs->pcs_primary_function_name[0]) + timelevel); + // MX, 01.2005 if ((val_in[comp][i] < 0.0) && (strcmp(name[comp], "pe") != 0)) { if (abs(val_in[comp][i]) > MKleinsteZahl) { DisplayMsg(" Neg. conc for component "); - DisplayLong((long) comp); + DisplayLong((long)comp); DisplayMsg(" at node "); - DisplayLong((long) i); + DisplayLong((long)i); DisplayMsg("; conc = "); DisplayDouble(val_in[comp][i], 0, 0); DisplayMsgLn(" "); @@ -4239,16 +4322,16 @@ void REACT::GetTransportResults(void) if (heatflag > 0) { - name[np - 2] = "temp"; //MX CMCD + name[np - 2] = "temp"; // MX CMCD pcs = PCSGet("HEAT_TRANSPORT"); long index = pcs->GetNodeValueIndex("TEMPERATURE1"); for (long i = 0; i < this->nodenumber; i++) - //OK PCSGetNODTemperature1L(i)//MX CMCD -2, Liquid Flow, Heat Transport + // OK PCSGetNODTemperature1L(i)//MX CMCD -2, Liquid Flow, Heat Transport this->val_in[np - 2][i] = pcs->GetNodeValue(i, index); } } -//ToDo - reactivate with new structure +// ToDo - reactivate with new structure void REACT::SetNeighborNodesActive(long startnode, long level, int* help) { startnode = startnode; @@ -4264,7 +4347,8 @@ void REACT::SetNeighborNodesActive(long startnode, long level, int* help) long *elems1d,*elems2d,*elems3d; int num_elems1d,num_elems2d,num_elems3d,num_elems; - // DisplayMsg(" RSNNA: startnode: "); DisplayLong(startnode); DisplayMsg(", level: "); DisplayLong(level); DisplayMsgLn(""); + // DisplayMsg(" RSNNA: startnode: "); DisplayLong(startnode); DisplayMsg(", level: "); DisplayLong(level); + DisplayMsgLn(""); // Ende rekursiv if(level == 0) { help[startnode] = 1; @@ -4316,11 +4400,11 @@ void REACT::ResetpHpe(void) for (j = 0; j < rcml_number_of_master_species + 2; j++) { - if(strcmp(this->name[j], "pe") == 0) - for(i = 0; i < this->nodenumber; i++) + if (strcmp(this->name[j], "pe") == 0) + for (i = 0; i < this->nodenumber; i++) this->val_out[j][i] = this->val_in[j][i]; - if(strcmp(this->name[j], "pH") == 0) - for(i = 0; i < this->nodenumber; i++) + if (strcmp(this->name[j], "pH") == 0) + for (i = 0; i < this->nodenumber; i++) this->val_out[j][i] = this->val_in[j][i]; } } @@ -4367,9 +4451,9 @@ double MATCalcIonicStrengthNew(long index) void RCRead(std::string filename) { - REACT* rc = new REACT(); //SB - rc->TestPHREEQC(filename); // Test if *.pqc file is present - if (rc->flag_pqc) //MX + REACT* rc = new REACT(); // SB + rc->TestPHREEQC(filename); // Test if *.pqc file is present + if (rc->flag_pqc) // MX REACT_vec.push_back(rc); else delete rc; @@ -4389,11 +4473,11 @@ void RCRead(std::string filename) **************************************************************************/ void REACT::ExecuteReactionsPHREEQC0(void) { - long i, ok = 0; - FILE* indatei, * fphinp, * fsel_out = NULL; + long i, ok = 0; + FILE *indatei, *fphinp, *fsel_out = NULL; char fsout[80]; - //MDL: + // MDL: DisplayMsgLn("ExecuteReactionsPHREEQC0:"); // DisplayMsgLn("ExecuteReactionsPHREEQC:"); @@ -4402,9 +4486,9 @@ void REACT::ExecuteReactionsPHREEQC0(void) /* Perform reaction step */ /* --------------------------------------------------------------------------*/ - if(flag_pqc) + if (flag_pqc) { - indatei = fopen(crdat,"r"); + indatei = fopen(crdat, "r"); if (indatei != NULL) ok = this->ReadReactionModel(indatei); else @@ -4420,11 +4504,11 @@ void REACT::ExecuteReactionsPHREEQC0(void) fphinp = fopen("phinp.dat", "w"); if ((fphinp) && ok) { - for(i = 0; i < this->elenumber; i++) - if(this->rateflag[i] > 0) + for (i = 0; i < this->elenumber; i++) + if (this->rateflag[i] > 0) { rewind(indatei); - ok = ReadInputPhreeqc(i,indatei, fphinp); + ok = ReadInputPhreeqc(i, indatei, fphinp); } fclose(indatei); fclose(fphinp); @@ -4436,33 +4520,33 @@ void REACT::ExecuteReactionsPHREEQC0(void) } /* Extern Program call to PHREEQC */ - if(ok) + if (ok) ok = Call_Phreeqc(); - if(ok == 0) + if (ok == 0) exit(1); /* Set up the output values for rockflow after Phreeqc reaction*/ - fsel_out = fopen(fsout,"r"); + fsel_out = fopen(fsout, "r"); if ((ok) && !fsel_out) { DisplayMsgLn("The selected output file doesn't exist!!!"); exit(1); } - else if(ok) + else if (ok) { ok = ReadOutputPhreeqc(fsout); - if(!ok) + if (!ok) DisplayMsgLn(" Error in call to PHREEQC !!!"); fclose(fsel_out); } - } /* if flag */ + } /* if flag */ /* Calculate Rates */ CalculateReactionRates(); // SetConcentrationResults(); SetConcentrationResultsEle(); -} /* End of ExecuteReactionsPHREEQC */ +} /* End of ExecuteReactionsPHREEQC */ /************************************************************************** ROCKFLOW - Funktion: REACT::GetTransportResults2Element @@ -4477,37 +4561,35 @@ void REACT::ExecuteReactionsPHREEQC0(void) void REACT::GetTransportResults2Element() { CRFProcess* pcs = NULL; - int timelevel = 1; // concentrations are in new timelevel + int timelevel = 1; // concentrations are in new timelevel // int phase = 0; //single phase so far - size_t np (pcs_vector.size()); - for (size_t j = 0; j < np; j++) // for all processes + size_t np(pcs_vector.size()); + for (size_t j = 0; j < np; j++) // for all processes { pcs = pcs_vector[j]; // if (pcs->pcs_type_name.compare("MASS_TRANSPORT") == 0) { // if it is a mass transport process // if it is a mass transport process - if (pcs->getProcessType () == FiniteElement::MASS_TRANSPORT) + if (pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) { int comp = pcs->pcs_component_number; // get component number - std::string cname (pcs->pcs_primary_function_name[0]); + std::string cname(pcs->pcs_primary_function_name[0]); if (CPGetMobil(pcs->GetProcessComponentNumber()) > 0) - pcs->InterpolateTempGP(pcs, cname); //line Interpolate to elements for ions + pcs->InterpolateTempGP(pcs, cname); // line Interpolate to elements for ions for (long i = 0; i < elenumber; i++) { // get concentration values - val_in[comp][i] = pcs->GetElementValue(i, - pcs->GetElementValueIndex( - cname) + timelevel); - //MX, 01.2005 + val_in[comp][i] = pcs->GetElementValue(i, pcs->GetElementValueIndex(cname) + timelevel); + // MX, 01.2005 if ((val_in[comp][i] < 0.0) && (strcmp(name[comp], "pe") != 0)) { if (abs(val_in[comp][i]) > MKleinsteZahl) { DisplayMsg(" Neg. conc for component "); - DisplayLong((long) comp); + DisplayLong((long)comp); DisplayMsg(" at node "); - DisplayLong((long) i); + DisplayLong((long)i); DisplayMsg("; conc = "); DisplayDouble(val_in[comp][i], 0, 0); DisplayMsgLn(" "); @@ -4521,12 +4603,12 @@ void REACT::GetTransportResults2Element() // Get Temperature values for elements if (this->heatflag > 0) { - this->name[np - 2] = "temp"; //MX CMCD + this->name[np - 2] = "temp"; // MX CMCD pcs = PCSGet("HEAT_TRANSPORT"); int idxT = pcs->GetElementValueIndex("TEMPERATURE1") + 1; pcs->InterpolateTempGP(pcs, "TEMPERATURE1"); for (long i = 0; i < this->elenumber; i++) - //OK PCSGetNODTemperature1L(i)//MX CMCD -2, Liquid Flow, Heat Transport + // OK PCSGetNODTemperature1L(i)//MX CMCD -2, Liquid Flow, Heat Transport this->val_in[np - 2][i] = pcs->GetElementValue(i, idxT); } } @@ -4538,39 +4620,40 @@ void REACT::GetTransportResults2Element() **************************************************************************/ void REACTInit() { - REACT* rc = NULL; //SB + REACT* rc = NULL; // SB // rc->TestPHREEQC(); // Test if *.pqc file is present rc = rc->GetREACT(); - if(rc) //OK + if (rc) // OK { - if(rc->flag_pqc) + if (rc->flag_pqc) { - if(cp_vec.size() > 0) - { //OK + if (cp_vec.size() > 0) + { // OK #ifdef REACTION_ELEMENT - rc->CreateREACT(); //SB + rc->CreateREACT(); // SB rc->InitREACT0(); rc->ExecuteReactionsPHREEQC0(); REACT_vec.clear(); REACT_vec.push_back(rc); #else - //-------------------------------------------------- - // HB, for the GEM chemical reaction engine 05.2007 +//-------------------------------------------------- +// HB, for the GEM chemical reaction engine 05.2007 #ifdef REAC_GEM REACT_GEM* p_REACT_GEM = NULL; p_REACT_GEM->REACT_GEM(); #else //-------------------------------------------------- - rc->CreateREACT(); //SB + rc->CreateREACT(); // SB rc->InitREACT(); #ifdef OGS_FEM_IPQC - rc->ExecutePQCString(); //WH + rc->ExecutePQCString(); // WH #elif LIBPHREEQC - cout << "MDL Calling ExecuteReactionsPHREEQCNewLib" << "\n"; + cout << "MDL Calling ExecuteReactionsPHREEQCNewLib" + << "\n"; rc->ExecuteReactionsPHREEQCNewLib(); #else rc->ExecuteReactionsPHREEQCNew(); -#endif //LIBPHREEQC +#endif // LIBPHREEQC REACT_vec.clear(); REACT_vec.push_back(rc); #endif @@ -4582,7 +4665,7 @@ void REACTInit() #ifdef CHEMAPP CEqlink* eq = NULL; eq = eq->GetREACTION(); - if(cp_vec.size() > 0 && eq) //MX + if (cp_vec.size() > 0 && eq) // MX { eq->TestCHEMAPPParameterFile(pcs_vector[0]->file_name_base); if (eq->flag_chemapp) @@ -4611,83 +4694,97 @@ int REACT::CheckNoReactionNodes(void) int ok = 0; long l; - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt - if(m_msh == NULL) {cout << "No mesh in CheckNoReactionNodes" << "\n"; exit(1);} + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt + if (m_msh == NULL) + { + cout << "No mesh in CheckNoReactionNodes" + << "\n"; + exit(1); + } -//CB 19.1.2011 - // Get the reaction interface data for checking for dried out nodes from eclipse coupling --> rateflag = 0 - REACTINT *m_rei = NULL; - if(REACTINT_vec.size()>0) - m_rei = REACTINT_vec[0]; + // CB 19.1.2011 + // Get the reaction interface data for checking for dried out nodes from eclipse coupling --> rateflag = 0 + REACTINT* m_rei = NULL; + if (REACTINT_vec.size() > 0) + m_rei = REACTINT_vec[0]; - cout << " CheckNoReactionNodes " << "\n"; + cout << " CheckNoReactionNodes " + << "\n"; - if(aktueller_zeitschritt < 2) //do not in the very first calculation before first time step and in the first time step + if (aktueller_zeitschritt + < 2) // do not in the very first calculation before first time step and in the first time step this->check_no_reaction_nodes = false; else { CKinReactData* m_krd = NULL; - if(KinReactData_vector.size() > 0) + if (KinReactData_vector.size() > 0) m_krd = KinReactData_vector[0]; - if(m_krd == NULL) + if (m_krd == NULL) // no KinReactData specified in *.krc file - cout << "No CKinReactData available in CheckNoReactionNodes" << "\n"; - else if(m_krd->is_a_CCBC.size() > 0) // reaction nodes specified in krc input file + cout << "No CKinReactData available in CheckNoReactionNodes" + << "\n"; + else if (m_krd->is_a_CCBC.size() > 0) // reaction nodes specified in krc input file { - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt - if(m_msh == NULL) + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt + if (m_msh == NULL) { - cout << "No mesh in CheckNoReactionNodes" << "\n"; + cout << "No mesh in CheckNoReactionNodes" + << "\n"; exit(1); } // Initialize vector is_a_CCBC // node 1 needed for phreeqc-input - for(l = 1; l < (long)m_msh->nod_vector.size(); l++) + for (l = 1; l < (long)m_msh->nod_vector.size(); l++) // rateflag == 0 means no reactions calculated - if(m_krd->is_a_CCBC[l] == true) + if (m_krd->is_a_CCBC[l] == true) this->rateflag[l] = 0; // cout << " Node " << l << " is " << this->rateflag[l] << "\n"; } - // also, switch off reactions for nodes with Sat Water < WaterSatLimit to avoid dryout problem in Eclipse coupling - if(m_rei){ - if(m_rei->s_water_limit) - for(l=1; l< (long)m_msh->nod_vector.size();l++) // node 1 needed for phreeqc-input - if(m_rei->dried_out_nodes[l]) - rateflag[l] = 0; - } + // also, switch off reactions for nodes with Sat Water < WaterSatLimit to avoid dryout problem in Eclipse + // coupling + if (m_rei) + { + if (m_rei->s_water_limit) + for (l = 1; l < (long)m_msh->nod_vector.size(); l++) // node 1 needed for phreeqc-input + if (m_rei->dried_out_nodes[l]) + rateflag[l] = 0; + } - this->check_no_reaction_nodes = true; - } // aktueller_zeitschritt < 2 + this->check_no_reaction_nodes = true; + } // aktueller_zeitschritt < 2 ok = 1; return ok; } -int REACT::Teststeps(long nodes){ - - int zeilenlaenge=10000; - char str[4000]; - int length = 0, steps = 1; +int REACT::Teststeps(long nodes) +{ + int zeilenlaenge = 10000; + char str[4000]; + int length = 0, steps = 1; - ifstream ein (this->results_file_name.data(),ios::in); - if (!ein){ - cout << "The selected output file doesn't exist!!!" << "\n"; - return 1; // standard no of steps - } + ifstream ein(this->results_file_name.data(), ios::in); + if (!ein) + { + cout << "The selected output file doesn't exist!!!" + << "\n"; + return 1; // standard no of steps + } - while(!ein.eof()){ - ein.getline(str, zeilenlaenge); - length++; - } - ein.close(); + while (!ein.eof()) + { + ein.getline(str, zeilenlaenge); + length++; + } + ein.close(); - steps = (length-2)/nodes - 1; - //if (steps<1) - // steps = 1; + steps = (length - 2) / nodes - 1; + // if (steps<1) + // steps = 1; - return steps; + return steps; } // MDL: here the new functions begin #ifdef LIBPHREEQC @@ -4722,48 +4819,45 @@ int REACT::WriteInputPhreeqcLib(long index, stringstream* out_buff, int* nl) cout.flush(); // cout << "WriteInputPhreeqcLib starting ..." << "\n"; - ifstream pqc_infile (this->file_name_pqc.data(),ios::in); - pqc_infile.seekg(0L,ios::beg); + ifstream pqc_infile(this->file_name_pqc.data(), ios::in); + pqc_infile.seekg(0L, ios::beg); // precision output file - out_buff->setf(ios::scientific,ios::floatfield); + out_buff->setf(ios::scientific, ios::floatfield); out_buff->precision(12); // reset the (partial) counter of lines nline = 0; // cout << "Write: *nline =" << *nline << "; nline++ ="<< nline++ << "\n"; // linewise read - while(!pqc_infile.eof()) + while (!pqc_infile.eof()) { - pqc_infile.getline(line,MAX_ZEILE); + pqc_infile.getline(line, MAX_ZEILE); line_string = line; - if(line_string.find("#STOP") != string::npos) + if (line_string.find("#STOP") != string::npos) break; //------------------------------------------------------------------------------------------------------------- /* loop for Keyword SOLUTION */ // keyword found - if(line_string.find("SOLUTION") != string::npos) + if (line_string.find("SOLUTION") != string::npos) { *out_buff << "SOLUTION " << index + 1 << "\n"; nline++; - while(line_string.find("#ende") == string::npos) + while (line_string.find("#ende") == string::npos) { - pqc_infile.getline(line,MAX_ZEILE); + pqc_infile.getline(line, MAX_ZEILE); line_string = line; if (line_string.find("# comp") != string::npos) { - if (line_string.find("pH") == string::npos && - line_string.find("pe") == string::npos) + if (line_string.find("pH") == string::npos && line_string.find("pe") == string::npos) { // Component found; write name and concentration of component count++; speciesname = pqc_names[count]; - dval = pcs_vector[pqc_process[count]]->GetNodeValue( - index, - pqc_index[count]); + dval = pcs_vector[pqc_process[count]]->GetNodeValue(index, pqc_index[count]); - if(speciesname.compare("pe")) // if this is not pe - if(dval < 1.0e-19) + if (speciesname.compare("pe")) // if this is not pe + if (dval < 1.0e-19) dval = 0.0; *out_buff << speciesname << " " << dval << "\n"; nline++; @@ -4772,13 +4866,13 @@ int REACT::WriteInputPhreeqcLib(long index, stringstream* out_buff, int* nl) else if (line_string.find("# temp") != string::npos) { // check if heat transport process is calculated in GeoSys - if(this->rcml_heat_flag > 0) + if (this->rcml_heat_flag > 0) { m_pcs = PCSGet("HEAT_TRANSPORT"); idx = m_pcs->GetNodeValueIndex("TEMPERATURE1"); - dval = m_pcs->GetNodeValue(index,idx); + dval = m_pcs->GetNodeValue(index, idx); if (dval < 273.0) - dval += 273.15; //change from °C to Kelvin if necessary + dval += 273.15; // change from °C to Kelvin if necessary dval -= 273.15; // Input to PHREEQC is in °C *out_buff << "temp " << dval << "\n"; nline++; @@ -4786,35 +4880,32 @@ int REACT::WriteInputPhreeqcLib(long index, stringstream* out_buff, int* nl) } } else - // Write units and temperature in the standard case - if (line_string.find("pH") == string::npos && - line_string.find("pe") == string::npos && - line_string.find("#ende") == string::npos) + // Write units and temperature in the standard case + if (line_string.find("pH") == string::npos && line_string.find("pe") == string::npos + && line_string.find("#ende") == string::npos) { *out_buff << line_string << "\n"; nline++; } - } // end while + } // end while // special treat pH, and pe n1 = this->rcml_number_of_master_species; count++; - if(count != n1) - cout << "Error in index of pqc_vectors !" << "\n"; - dval = pcs_vector[pqc_process[count]]->GetNodeValue(index,pqc_index[count]); + if (count != n1) + cout << "Error in index of pqc_vectors !" + << "\n"; + dval = pcs_vector[pqc_process[count]]->GetNodeValue(index, pqc_index[count]); count++; - if(this->gamma_Hplus > 0) // pH and H+ in GeoSys species, calculate pH from H+ + if (this->gamma_Hplus > 0) // pH and H+ in GeoSys species, calculate pH from H+ { - dval1 = pcs_vector[pqc_process[n1 + 1]]->GetNodeValue( - index, - pqc_index[n1 - + 1 - ]); + dval1 = pcs_vector[pqc_process[n1 + 1]]->GetNodeValue(index, pqc_index[n1 + 1]); dval = -log10(dval1 * gamma_Hplus); } - if(this->rcml_pH_charge > 0) + if (this->rcml_pH_charge > 0) { - *out_buff << "pH " << dval << " charge " << "\n"; + *out_buff << "pH " << dval << " charge " + << "\n"; nline++; } else @@ -4824,8 +4915,7 @@ int REACT::WriteInputPhreeqcLib(long index, stringstream* out_buff, int* nl) } // pe count++; - dval = pcs_vector[pqc_process[n1 + 2]]->GetNodeValue(index, - pqc_index[n1 + 2]); + dval = pcs_vector[pqc_process[n1 + 2]]->GetNodeValue(index, pqc_index[n1 + 2]); *out_buff << "pe " << dval << "\n"; nline++; if (line_string.find("#ende") != 0) @@ -4833,87 +4923,81 @@ int REACT::WriteInputPhreeqcLib(long index, stringstream* out_buff, int* nl) *out_buff << line_string << "\n"; nline++; } - } // end SOLUTION + } // end SOLUTION // Keyword EQUILIBRIUM PHASES - if(line_string.find("EQUILIBRIUM_PHASES") != string::npos) - { // keyword found + if (line_string.find("EQUILIBRIUM_PHASES") != string::npos) + { // keyword found *out_buff << "PURE " << index + 1 << "\n"; nline++; - while(line_string.find("#ende") == string::npos) + while (line_string.find("#ende") == string::npos) { - pqc_infile.getline(line,MAX_ZEILE); + pqc_infile.getline(line, MAX_ZEILE); line_string = line; if (line_string.find("# comp") != string::npos) { count++; speciesname = pqc_names[count]; - dval = pcs_vector[pqc_process[count]]->GetNodeValue( - index, - pqc_index - [count]); - if(dval < 1.0e-19) + dval = pcs_vector[pqc_process[count]]->GetNodeValue(index, pqc_index[count]); + if (dval < 1.0e-19) dval = 0.0; *out_buff << speciesname << " 0.0 " << dval << "\n"; nline++; } - else - if (line_string.find("#ende") != 0) + else if (line_string.find("#ende") != 0) *out_buff << line_string << "\n"; } - } // end EQUILIBRIUM PHASES + } // end EQUILIBRIUM PHASES // Keyword EXCHANGE - if(line_string.find("EXCHANGE") != string::npos) - { // keyword found - *out_buff << "EXCHANGE " << index + 1 << "\n"; + if (line_string.find("EXCHANGE") != string::npos) + { // keyword found + *out_buff << "EXCHANGE " << index + 1 << "\n"; nline++; - while(line_string.find("#ende") == string::npos) + while (line_string.find("#ende") == string::npos) { - pqc_infile.getline(line,MAX_ZEILE); + pqc_infile.getline(line, MAX_ZEILE); line_string = line; if (line_string.find("# comp") != string::npos) { count++; speciesname = pqc_names[count]; - dval = pcs_vector[pqc_process[count]]->GetNodeValue( - index, - pqc_index - [count]); - if(dval < 1.0e-19) + dval = pcs_vector[pqc_process[count]]->GetNodeValue(index, pqc_index[count]); + if (dval < 1.0e-19) dval = 0.0; *out_buff << speciesname << " " << dval << "\n"; nline++; } - else - if (line_string.find("#ende") != 0) + else if (line_string.find("#ende") != 0) { *out_buff << line_string << "\n"; nline++; } } - } // end EXCHANGE + } // end EXCHANGE // Keyword GAS_PHASE - if(line_string.find("GAS_PHASE") != string::npos) - { // keyword found - *out_buff << "GAS_PHASE " << index + 1 << "\n"; + if (line_string.find("GAS_PHASE") != string::npos) + { // keyword found + *out_buff << "GAS_PHASE " << index + 1 << "\n"; nline++; - // get necessary values for conversion of molar concentrations to partial pressures, and to calculate total pressure and total volume + // get necessary values for conversion of molar concentrations to partial pressures, and to calculate total + // pressure and total volume // get height of node z - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt MeshLib::CNode* m_nod = NULL; m_nod = m_msh->nod_vector[index]; z = m_msh->nod_vector[index]->getData()[2]; // get piezometric hight h m_pcs = PCSGet("GROUNDWATER_FLOW"); - if(m_pcs == NULL) - cout << " Error - no flow process found!" << "\n"; + if (m_pcs == NULL) + cout << " Error - no flow process found!" + << "\n"; idx = m_pcs->GetNodeValueIndex("HEAD") + 1; - h = m_pcs->GetNodeValue(index,idx); + h = m_pcs->GetNodeValue(index, idx); // get fluid density dens = mfp_vector[0]->Density(); @@ -4922,26 +5006,25 @@ int REACT::WriteInputPhreeqcLib(long index, stringstream* out_buff, int* nl) press = dens * gravity_constant * (h - z); // get temperature in [°C] - if(rcml_heat_flag < 1) + if (rcml_heat_flag < 1) temp = this->temperature; // get molar masses of gas phase - mm = 0.0; // mm is total molar mass of gas phase in [mol] - ii = rcml_number_of_master_species + 3 + rcml_number_of_ion_exchanges + - rcml_number_of_equi_phases; - for(i = ii; i < ii + rcml_number_of_gas_species; i++) + mm = 0.0; // mm is total molar mass of gas phase in [mol] + ii = rcml_number_of_master_species + 3 + rcml_number_of_ion_exchanges + rcml_number_of_equi_phases; + for (i = ii; i < ii + rcml_number_of_gas_species; i++) { speciesname = this->pqc_names[i]; - dval = pcs_vector[pqc_process[i]]->GetNodeValue(index,pqc_index[i]); + dval = pcs_vector[pqc_process[i]]->GetNodeValue(index, pqc_index[i]); mm += dval; } // calculate Volume of gas phase in [mol * Pa * m^3 / K / mol * K / Pa = m^3 ] volume = mm * 8.314472 * (273.15 + temp) / press; - while(line_string.find("#ende") == string::npos) + while (line_string.find("#ende") == string::npos) { - pqc_infile.getline(line,MAX_ZEILE); + pqc_infile.getline(line, MAX_ZEILE); line_string = line; if (line_string.find("-pressure") != string::npos) { @@ -4965,48 +5048,42 @@ int REACT::WriteInputPhreeqcLib(long index, stringstream* out_buff, int* nl) { count++; speciesname = pqc_names[count]; - dval = pcs_vector[pqc_process[count]]->GetNodeValue( - index, - pqc_index - [count]); - if(dval < 1.0e-19) + dval = pcs_vector[pqc_process[count]]->GetNodeValue(index, pqc_index[count]); + if (dval < 1.0e-19) dval = 0.0; if (mm > 0.0) partial_press = press * dval / mm; else partial_press = 0.0; - *out_buff << " " << speciesname << " " << partial_press / - 101325.0 << "\n"; + *out_buff << " " << speciesname << " " << partial_press / 101325.0 << "\n"; nline++; } - else - if (line_string.find("#ende") != 0) + else if (line_string.find("#ende") != 0) { - *out_buff << line_string << "\n"; //write line unchanged + *out_buff << line_string << "\n"; // write line unchanged nline++; } } - } // end GAS_PHASE + } // end GAS_PHASE // Keyword SELECTED_OUTPUT - if(line_string.find("SELECTED_OUTPUT") != string::npos) // keyword found - if(index < 1) // this block has to appear just in the first solution + if (line_string.find("SELECTED_OUTPUT") != string::npos) // keyword found + if (index < 1) // this block has to appear just in the first solution { - *out_buff << "SELECTED_OUTPUT" << "\n"; + *out_buff << "SELECTED_OUTPUT" + << "\n"; nline++; - while(line_string.find("#ende") == string::npos) + while (line_string.find("#ende") == string::npos) { - pqc_infile.getline(line,MAX_ZEILE); + pqc_infile.getline(line, MAX_ZEILE); line_string = line; if (line_string.find("-file") != string::npos) { - *out_buff << "-file " << this->results_file_name << - "\n"; + *out_buff << "-file " << this->results_file_name << "\n"; nline++; } - else - if (line_string.find("#ende") != 0) + else if (line_string.find("#ende") != 0) { *out_buff << line_string << "\n"; nline++; @@ -5016,14 +5093,15 @@ int REACT::WriteInputPhreeqcLib(long index, stringstream* out_buff, int* nl) // end SELECTED OUTPUT // Keyword PRINT - if(line_string.find("PRINT") != string::npos) // keyword found - if(index < 1) // this block has to appear just in the first solution + if (line_string.find("PRINT") != string::npos) // keyword found + if (index < 1) // this block has to appear just in the first solution { - *out_buff << "PRINT" << "\n"; + *out_buff << "PRINT" + << "\n"; nline++; - while(line_string.find("#ende") == string::npos) + while (line_string.find("#ende") == string::npos) { - pqc_infile.getline(line,MAX_ZEILE); + pqc_infile.getline(line, MAX_ZEILE); line_string = line; if (line_string.find("#libprint") != string::npos) libphreeqc_print = "T"; @@ -5037,11 +5115,12 @@ int REACT::WriteInputPhreeqcLib(long index, stringstream* out_buff, int* nl) // end PRINT // Keyword USER_PUNCH - if(line_string.find("USER_PUNCH") != string::npos) - { // keyword found - if(index < 1) + if (line_string.find("USER_PUNCH") != string::npos) + { // keyword found + if (index < 1) { - *out_buff << "USER_PUNCH" << "\n"; + *out_buff << "USER_PUNCH" + << "\n"; nline++; // Write Header n1 = this->rcml_number_of_master_species; @@ -5049,24 +5128,24 @@ int REACT::WriteInputPhreeqcLib(long index, stringstream* out_buff, int* nl) n3 = this->rcml_number_of_ion_exchanges; n4 = this->rcml_number_of_gas_species; *out_buff << "-head "; - for(i = 0; i < n1; i++) + for (i = 0; i < n1; i++) *out_buff << " " << pqc_names[i]; *out_buff << " pH "; *out_buff << " H+ "; *out_buff << " pe "; - for(i = n1 + 3; i < n1 + 3 + n2; i++) + for (i = n1 + 3; i < n1 + 3 + n2; i++) *out_buff << " " << pqc_names[i]; - for(i = n1 + 3 + n2; i < n1 + 3 + n2 + n3; i++) + for (i = n1 + 3 + n2; i < n1 + 3 + n2 + n3; i++) *out_buff << " " << pqc_names[i]; - for(i = n1 + 3 + n2 + n3; i < n1 + 3 + n2 + n3 + n4; i++) + for (i = n1 + 3 + n2 + n3; i < n1 + 3 + n2 + n3 + n4; i++) *out_buff << " " << pqc_names[i]; *out_buff << "\n"; nline++; // Write everything in just 1 line *out_buff << "10 PUNCH "; - for(i = 0; i < n1; i++) + for (i = 0; i < n1; i++) { - if(pqc_names[i].compare("H+") == 0) + if (pqc_names[i].compare("H+") == 0) // extra treat H+ *out_buff << " MOL(\"" << pqc_names[i] << "\"),"; else @@ -5077,68 +5156,68 @@ int REACT::WriteInputPhreeqcLib(long index, stringstream* out_buff, int* nl) *out_buff << " -LA(\"H+\"), MOL(\"H+\"), -LA(\"e-\")"; // Write equilibrium phases - if(n2 > 0) - for(i = n1 + 3; i < n1 + 3 + n2; i++) + if (n2 > 0) + for (i = n1 + 3; i < n1 + 3 + n2; i++) *out_buff << ", EQUI(\"" << pqc_names[i] << "\")"; // Write ion exchangers - if(n3 > 0) - for(i = n1 + 3 + n2; i < n1 + 3 + n2 + n3; i++) + if (n3 > 0) + for (i = n1 + 3 + n2; i < n1 + 3 + n2 + n3; i++) *out_buff << ", MOL(\"" << pqc_names[i] << "\")"; // Write gas phase species - if(n4 > 0) - for(i = n1 + 3 + n2 + n3; i < n1 + 3 + n2 + n3 + n4; i++) + if (n4 > 0) + for (i = n1 + 3 + n2 + n3; i < n1 + 3 + n2 + n3 + n4; i++) *out_buff << ", GAS(\"" << pqc_names[i] << "\")"; // MDL: now the "\n" *out_buff << "\n"; nline++; - } // end if index < 1 + } // end if index < 1 // search for end of USER_PUNCH data block in *.pqc input file - while(!pqc_infile.eof()) + while (!pqc_infile.eof()) { - pqc_infile.getline(line,MAX_ZEILE); + pqc_infile.getline(line, MAX_ZEILE); line_string = line; - if((line_string.find("#ende") != string::npos) || - (line_string.find("END") != string::npos)) + if ((line_string.find("#ende") != string::npos) || (line_string.find("END") != string::npos)) break; } - } // end USER_PUNCH + } // end USER_PUNCH - if(line_string.find("-steps") != string::npos) - { // keyword found + if (line_string.find("-steps") != string::npos) + { // keyword found in.str(line_string); in >> dummy >> dval >> this->rcml_number_of_pqcsteps >> dummy; CTimeDiscretization* m_tim = NULL; - if(time_vector.size() > 0) + if (time_vector.size() > 0) m_tim = time_vector[0]; else - cout << - "Error in WriteInputPhreeqcLib: no time discretization data !" << - "\n"; + cout << "Error in WriteInputPhreeqcLib: no time discretization data !" + << "\n"; dval = m_tim->CalcTimeStep(); - *out_buff << "-steps " << dval << " in " << - this->rcml_number_of_pqcsteps << " steps" << "\n"; + *out_buff << "-steps " << dval << " in " << this->rcml_number_of_pqcsteps << " steps" + << "\n"; nline++; - } // end -steps + } // end -steps - if(line_string.find("KNOBS") != string::npos) - if(index < 1) + if (line_string.find("KNOBS") != string::npos) + if (index < 1) { - *out_buff << "KNOBS" << "\n"; + *out_buff << "KNOBS" + << "\n"; nline++; - while(line_string.find("#ende") == string::npos) + while (line_string.find("#ende") == string::npos) { - pqc_infile.getline(line,MAX_ZEILE); + pqc_infile.getline(line, MAX_ZEILE); line_string = line; *out_buff << line_string << "\n"; nline++; } } - } // end of "while" linewise read - *out_buff << "END" << "\n"; + } // end of "while" linewise read + *out_buff << "END" + << "\n"; nline++; *nl = nline; pqc_infile.close(); @@ -5154,93 +5233,102 @@ int REACT::WriteInputPhreeqcLib(long index, stringstream* out_buff, int* nl) **************************************************************************/ void REACT::ExecuteReactionsPHREEQCNewLib(void) { - long i, ii, ok = 0; + long i, ii, ok = 0; int nl, nline, npunch; // File handling - GeoSys input file - ifstream pqc_file (this->file_name_pqc.data(),ios::in); + ifstream pqc_file(this->file_name_pqc.data(), ios::in); if (!pqc_file.good()) - cout << "! Error in ExecuteReactionsPHREEQCNew: no Input File (*.pqc) found !" << - "\n"; + cout << "! Error in ExecuteReactionsPHREEQCNew: no Input File (*.pqc) found !" + << "\n"; // data exchange buffer to libphreeqc, as stringstream stringstream out_buff; // Set up reaction model - if((int)this->pqc_names.size() == 0) + if ((int)this->pqc_names.size() == 0) { ok = this->ReadReactionModelNew(&pqc_file); - if(!ok) - cout << "Error setting up reaction model" << "\n"; + if (!ok) + cout << "Error setting up reaction model" + << "\n"; } // Check for nodes without reactions - if((int)this->check_no_reaction_nodes == false) + if ((int)this->check_no_reaction_nodes == false) { ok = this->CheckNoReactionNodes(); - if(!ok) - cout << "Error when checking for nodes without reactions" << "\n"; + if (!ok) + cout << "Error when checking for nodes without reactions" + << "\n"; } // Read the input file (*.pqc) and set up the input for PHREEQC; // Write input data block to PHREEQC for each node; // sum number of lines of input. - cout << "\n" << "Preparing phreeqc's input..."; + cout << "\n" + << "Preparing phreeqc's input..."; ii = 0; nline = 0; // Should libphreeqc print to file? Defaults to no (=="F") libphreeqc_print = "F"; - for(i = 0; i < this->nodenumber; i++) - if(this->rateflag[i] > 0) + for (i = 0; i < this->nodenumber; i++) + if (this->rateflag[i] > 0) { - pqc_file.seekg(0L,ios_base::beg); + pqc_file.seekg(0L, ios_base::beg); ok = WriteInputPhreeqcLib(i, &out_buff, &nl); ii++; nline = nline + nl; } - if(ok) - cout << " [OK]" << "\n"; + if (ok) + cout << " [OK]" + << "\n"; else - cout << " [ERROR]" << "\n"; + cout << " [ERROR]" + << "\n"; - // TODO: don't try to run phreeqc if output is not ok +// TODO: don't try to run phreeqc if output is not ok #ifdef MDL_DEBUG cout << "MDL_DEBUG: libphreeqc_print = " << libphreeqc_print << "\n"; - cout << "MDL_DEBUG: final input is " << nline << " lines, nodes " << ii << "/" << - this->nodenumber << "\n"; - cout << "\n" << "MDL_DEBUG: ****** Current input:" << "\n" << out_buff.str() << "\n" << - "MDL_DEBUG: ****** end of input" << "\n"; + cout << "MDL_DEBUG: final input is " << nline << " lines, nodes " << ii << "/" << this->nodenumber << "\n"; + cout << "\n" + << "MDL_DEBUG: ****** Current input:" + << "\n" + << out_buff.str() << "\n" + << "MDL_DEBUG: ****** end of input" + << "\n"; #endif // Close *.pqc input file pqc_file.close(); - npunch = this->rcml_number_of_master_species + this->rcml_number_of_equi_phases + - this->rcml_number_of_ion_exchanges + this->rcml_number_of_gas_species + 3; + npunch = this->rcml_number_of_master_species + this->rcml_number_of_equi_phases + this->rcml_number_of_ion_exchanges + + this->rcml_number_of_gas_species + 3; - double* out_vec = new double [ npunch * ii ]; + double* out_vec = new double[npunch * ii]; // call to libphreeqc - std::cout << "\n" << "\n"; - ok = Call_PhreeqcLib(ii,npunch, nline, &out_buff, out_vec); + std::cout << "\n" + << "\n"; + ok = Call_PhreeqcLib(ii, npunch, nline, &out_buff, out_vec); - if(ok) + if (ok) { cout << "Reading phreeqc's output..."; ok = ReadOutputPhreeqcNewLib(out_vec); - if(!ok) - std::cout << - " [ERROR] ExecuteReactionsPHREEQCNewLib: Error reading phreeqc's output" << - "\n"; + if (!ok) + std::cout << " [ERROR] ExecuteReactionsPHREEQCNewLib: Error reading phreeqc's output" + << "\n"; else - std::cout << " [OK]" << "\n"; + std::cout << " [OK]" + << "\n"; } // deallocation - delete [] out_vec; + delete[] out_vec; /* Calculate Rates */ // CalculateReactionRates(); @@ -5250,7 +5338,7 @@ void REACT::ExecuteReactionsPHREEQCNewLib(void) /* pH and pe constant or variable */ // ResetpHpe(rc, rcml); -} /* End of ExecuteReactionsPHREEQCNewLib */ +} /* End of ExecuteReactionsPHREEQCNewLib */ /************************************************************************** ROCKFLOW - Funktion: ReadOutputPhreeqcNewLib @@ -5271,10 +5359,10 @@ int REACT::ReadOutputPhreeqcNewLib(double* pqc_vec) CTimeDiscretization* m_tim = NULL; // Get time step number - if(time_vector.size() > 0) + if (time_vector.size() > 0) { m_tim = time_vector[0]; - if(m_tim->step_current == 0) + if (m_tim->step_current == 0) dix = -1; } @@ -5288,75 +5376,56 @@ int REACT::ReadOutputPhreeqcNewLib(double* pqc_vec) for (index = 0; index < this->nodenumber; index++) { - if(this->rateflag[index] > 0) + if (this->rateflag[index] > 0) { // concentrations of master species and pH pe values for (j = 0; j < n1; j++) - pcs_vector[pqc_process[j]]->SetNodeValue(index, - pqc_index[j] + dix, - pqc_vec[index * ntot + j]); + pcs_vector[pqc_process[j]]->SetNodeValue(index, pqc_index[j] + dix, pqc_vec[index * ntot + j]); // pH j = n1; - pcs_vector[pqc_process[j]]->SetNodeValue(index,pqc_index[j] + dix, - pqc_vec[index * ntot + j]); + pcs_vector[pqc_process[j]]->SetNodeValue(index, pqc_index[j] + dix, pqc_vec[index * ntot + j]); // H+ j++; - if(this->gamma_Hplus > 0) + if (this->gamma_Hplus > 0) { m_pcs = pcs_vector[pqc_process[j]]; - pcs_vector[pqc_process[j]]->SetNodeValue(index, - pqc_index[j] + dix, - pqc_vec[index * ntot + j]); + pcs_vector[pqc_process[j]]->SetNodeValue(index, pqc_index[j] + dix, pqc_vec[index * ntot + j]); } // pe j++; m_pcs = pcs_vector[pqc_process[j]]; - pcs_vector[pqc_process[j]]->SetNodeValue(index,pqc_index[j] + dix, - pqc_vec[index * ntot + j]); + pcs_vector[pqc_process[j]]->SetNodeValue(index, pqc_index[j] + dix, pqc_vec[index * ntot + j]); // concentrations of all equilibrium phases if (n2 > 0) for (j = n1 + 3; j < n1 + 3 + n2; j++) - pcs_vector[pqc_process[j]]->SetNodeValue(index, - pqc_index[j] + dix, - pqc_vec[index * - ntot + j]); + pcs_vector[pqc_process[j]]->SetNodeValue(index, pqc_index[j] + dix, pqc_vec[index * ntot + j]); // concentrations of all ion exchangers if (n3 > 0) for (j = n1 + 3 + n2; j < n1 + 3 + n2 + n3; j++) - pcs_vector[pqc_process[j]]->SetNodeValue(index, - pqc_index[j] + dix, - pqc_vec[index * - ntot + j]); + pcs_vector[pqc_process[j]]->SetNodeValue(index, pqc_index[j] + dix, pqc_vec[index * ntot + j]); // concentrations of all gas phase species if (n4 > 0) for (j = n1 + 3 + n2 + n3; j < n1 + 3 + n2 + n3 + n4; j++) - pcs_vector[pqc_process[j]]->SetNodeValue(index, - pqc_index[j] + dix, - pqc_vec[index * - ntot + j]); - } //endif rateflag + pcs_vector[pqc_process[j]]->SetNodeValue(index, pqc_index[j] + dix, pqc_vec[index * ntot + j]); + } // endif rateflag // Determine new gamma_Hplus - if(this->gamma_Hplus > 0) + if (this->gamma_Hplus > 0) { // Calculate new gamma_Hplus // molality H+ - dval = - pcs_vector[pqc_process[n1 + 1]]->GetNodeValue( - index, - pqc_index[n1 + - 1] + dix); - //pH - dval1 = pcs_vector[pqc_process[n1]]->GetNodeValue(index,pqc_index[n1] + dix); - dval1 = pow(10.0,-dval1); // activity H+ from pH + dval = pcs_vector[pqc_process[n1 + 1]]->GetNodeValue(index, pqc_index[n1 + 1] + dix); + // pH + dval1 = pcs_vector[pqc_process[n1]]->GetNodeValue(index, pqc_index[n1] + dix); + dval1 = pow(10.0, -dval1); // activity H+ from pH this->gamma_Hplus = dval1 / dval; } - } // end for (index... + } // end for (index... ok = 1; @@ -5373,30 +5442,25 @@ int REACT::ReadOutputPhreeqcNewLib(double* pqc_vec) 04/2009 MDL First Version **************************************************************************/ -int REACT::Call_PhreeqcLib(int nsim, - int npunch, - int nline, - stringstream* pqc_buffer, - double* pqc_out) +int REACT::Call_PhreeqcLib(int nsim, int npunch, int nline, stringstream* pqc_buffer, double* pqc_out) { int i, out; string line; size_t length; #ifdef MDL_DEBUG - cout << "MDL_DEB:: Call_PhreeqcLib -> nsim = " << nsim << "; npunch = " << npunch << - "; nline = " << nline << "\n"; + cout << "MDL_DEB:: Call_PhreeqcLib -> nsim = " << nsim << "; npunch = " << npunch << "; nline = " << nline << "\n"; #endif // copy the stringstream to a char ** for the c library - char** buffer = new char* [nline]; + char** buffer = new char*[nline]; for (i = 0; i < nline; i++) { getline(*pqc_buffer, line); buffer[i] = new char[line.size() + 1]; - length = line.copy(buffer[i],line.size() + 1,0); + length = line.copy(buffer[i], line.size() + 1, 0); buffer[i][length] = '\0'; } @@ -5405,11 +5469,11 @@ int REACT::Call_PhreeqcLib(int nsim, for (i = 0; i < 5; i++) libargs[i] = new char[30]; - strcpy(libargs[0],"libphreeqc"); - strcpy(libargs[1],"FIXME"); - strcpy(libargs[2],"phinp.out"); - strcpy(libargs[3],"phreeqc.dat"); - strcpy(libargs[4],libphreeqc_print.c_str()); + strcpy(libargs[0], "libphreeqc"); + strcpy(libargs[1], "FIXME"); + strcpy(libargs[2], "phinp.out"); + strcpy(libargs[3], "phreeqc.dat"); + strcpy(libargs[4], libphreeqc_print.c_str()); #ifdef MDL_DEBUG cout << "libargs assigned\n"; @@ -5417,26 +5481,24 @@ int REACT::Call_PhreeqcLib(int nsim, // call to libphreeqc // NB: Phreeqcmain returns 1 if everything is fine, 0 if errors - out = Phreeqcmain( 5, libargs, nsim, npunch, - nline, buffer, pqc_out); + out = Phreeqcmain(5, libargs, nsim, npunch, nline, buffer, pqc_out); // deallocations for (i = 0; i < nline; i++) - delete [] buffer[i]; + delete[] buffer[i]; - delete [] buffer; + delete[] buffer; for (i = 0; i < 5; i++) - delete [] libargs[i]; - delete [] libargs; + delete[] libargs[i]; + delete[] libargs; if (out == 1) - return 1; // ok == 1 for Geosys conventions + return 1; // ok == 1 for Geosys conventions else { DisplayMsgLn("Warning: libphreeqc doesn't run properly!!! "); exit(1); } } -#endif // LIBPHREEQC - +#endif // LIBPHREEQC diff --git a/FEM/rf_react.h b/FEM/rf_react.h index 31dd0a469..2300730da 100644 --- a/FEM/rf_react.h +++ b/FEM/rf_react.h @@ -22,45 +22,46 @@ class REACT REACT(void); ~REACT(void); // Data - const char** name; /* names of reactants */ - double** val_in; /* input concentration values to reaction module */ - double** val_out; /* output concentration values of reaction module */ - double** rate; /* reaction rates for MTM2 */ - int* rateflag; /* flag used for determining if reaction are calculated with PHREEQC */ - int countsteps; /* number of timesteps, after which reactions are recalculated in the whole model domain */ - int number_of_comp; /* Number of components in above data structures: size = number_of_comp * NodeListLength */ - int heatflag; /* if 1, heat transport is active and passed to phreeqc */ - long nodenumber; /* number of nodes, on which reactions are calculated */ - bool flag_pqc; /* flag if *.pqc file exists */ - bool check_no_reaction_nodes; /* flag if CheckNoReactionNodes has been performed */ - double temperature; /* temperature of water at node as specified in input file */ - long elenumber; //number of elements + const char** name; /* names of reactants */ + double** val_in; /* input concentration values to reaction module */ + double** val_out; /* output concentration values of reaction module */ + double** rate; /* reaction rates for MTM2 */ + int* rateflag; /* flag used for determining if reaction are calculated with PHREEQC */ + int countsteps; /* number of timesteps, after which reactions are recalculated in the whole model domain */ + int number_of_comp; /* Number of components in above data structures: size = number_of_comp * NodeListLength */ + int heatflag; /* if 1, heat transport is active and passed to phreeqc */ + long nodenumber; /* number of nodes, on which reactions are calculated */ + bool flag_pqc; /* flag if *.pqc file exists */ + bool check_no_reaction_nodes; /* flag if CheckNoReactionNodes has been performed */ + double temperature; /* temperature of water at node as specified in input file */ + long elenumber; // number of elements /* hier später arrays of reactions reinhängen ?*/ // rcml moved here - int rcml_number_of_master_species; /* number of master species (inorgan. equilibrium) */ - int rcml_number_of_equi_phases; /* number of phases (in equilibrium) */ - int rcml_number_of_kinetics; /* number of kinetic reactions */ - int rcml_number_of_ion_exchanges; /* number of phases (in equilibrium) */ - int rcml_number_of_gas_species; /* number of species in gas phase */ + int rcml_number_of_master_species; /* number of master species (inorgan. equilibrium) */ + int rcml_number_of_equi_phases; /* number of phases (in equilibrium) */ + int rcml_number_of_kinetics; /* number of kinetic reactions */ + int rcml_number_of_ion_exchanges; /* number of phases (in equilibrium) */ + int rcml_number_of_gas_species; /* number of species in gas phase */ size_t rcml_number_of_secondary_species; /* number of species in gas phase */ /* hier später reaction models reinhängen ?*/ - int rcml_pH_flag; /* =0, pH constant; =1 (default), pH will change */ - int rcml_pe_flag; /* =0, pe constant; =1 (default), pe will change */ - int rcml_heat_flag; /* =0, temp constant (default); =1 , temp will change */ - int rcml_number_of_pqcsteps; /* Anzahl der Reaktionsschritte in PHREEQC aus dem Befehl: -steps "time" in "pqcsteps" steps */ - int rcml_pH_charge; /* =0, no charge balance for pH; =1, used for charge balance (keyword charge in line with pH*/ - char* outfile; /* Ausgabefile von PHREEQC */ - std::string file_name_pqc; // Name of pqc file in GeoSys project (*.pqc) - std::string file_name_database; // Name of pqc database file in GeoSys project (*.pqc) + int rcml_pH_flag; /* =0, pH constant; =1 (default), pH will change */ + int rcml_pe_flag; /* =0, pe constant; =1 (default), pe will change */ + int rcml_heat_flag; /* =0, temp constant (default); =1 , temp will change */ + int rcml_number_of_pqcsteps; /* Anzahl der Reaktionsschritte in PHREEQC aus dem Befehl: -steps "time" in "pqcsteps" + steps */ + int rcml_pH_charge; /* =0, no charge balance for pH; =1, used for charge balance (keyword charge in line with pH*/ + char* outfile; /* Ausgabefile von PHREEQC */ + std::string file_name_pqc; // Name of pqc file in GeoSys project (*.pqc) + std::string file_name_database; // Name of pqc database file in GeoSys project (*.pqc) std::string outfile_name; std::string results_file_name; std::string results_file_name_new; - std::vector < std::string > pqc_names; // species names in *-pqc input file - std::vector < int > pqc_index; // index in process array - std::vector < int > pqc_process; // process number in pcs_vector - double gamma_Hplus; //activity coefficent of H+ ion - std::vector < std::string > additional_punches; + std::vector pqc_names; // species names in *-pqc input file + std::vector pqc_index; // index in process array + std::vector pqc_process; // process number in pcs_vector + double gamma_Hplus; // activity coefficent of H+ ion + std::vector additional_punches; // Member functions REACT* GetREACT(void); @@ -68,26 +69,26 @@ class REACT void InitREACT(void); void ExecuteReactionsPHREEQC(void); void ExecuteReactionsPHREEQCNew(void); - void ExecutePQCString(void); //WH - int WriteInputPQCString(long, std::stringstream*, bool); //WH + void ExecutePQCString(void); // WH + int WriteInputPQCString(long, std::stringstream*, bool); // WH void TestPHREEQC(std::string); - int Call_Phreeqc(void); + int Call_Phreeqc(void); void GetTransportResults(void); - int ReadReactionModel(FILE* File); - int ReadReactionModelNew(std::ifstream*); - //fsout removed 3912 - int ReadInputPhreeqc( long index, FILE* fpqc, FILE* Fphinp); - int WriteInputPhreeqc(long, /*ifstream*,*/ std::ofstream*); - int ReadOutputPhreeqc(char* fout); - int ReadOutputPhreeqcNew(void); - int ReadOutputIPQC(std::vector ranknodelist, std::stringstream*, double *m_Conc); + int ReadReactionModel(FILE* File); + int ReadReactionModelNew(std::ifstream*); + // fsout removed 3912 + int ReadInputPhreeqc(long index, FILE* fpqc, FILE* Fphinp); + int WriteInputPhreeqc(long, /*ifstream*,*/ std::ofstream*); + int ReadOutputPhreeqc(char* fout); + int ReadOutputPhreeqcNew(void); + int ReadOutputIPQC(std::vector ranknodelist, std::stringstream*, double* m_Conc); void ResetpHpe(void); void CalculateReactionRates(void); void SetConcentrationResults(void); void CalculateReactionRateFlag(void); void SetNeighborNodesActive(long startnode, long level, int* help); - int CheckNoReactionNodes(void); - int Teststeps(long nodes); + int CheckNoReactionNodes(void); + int Teststeps(long nodes); // Reaction at elements //MX void InitREACT0(void); void ExecuteReactionsPHREEQC0(void); @@ -96,21 +97,21 @@ class REACT #ifdef LIBPHREEQC // MDL: libphreeqc void ExecuteReactionsPHREEQCNewLib(void); // MDL: - // MDL: - int WriteInputPhreeqcLib(long, std::stringstream*, int*); - int ReadOutputPhreeqcNewLib(double*); // MDL: - int Call_PhreeqcLib(int, int, int, std::stringstream*, double*); -#endif // LIBPHREEQC + // MDL: + int WriteInputPhreeqcLib(long, std::stringstream*, int*); + int ReadOutputPhreeqcNewLib(double*); // MDL: + int Call_PhreeqcLib(int, int, int, std::stringstream*, double*); +#endif // LIBPHREEQC }; -extern std::vector REACT_vec; +extern std::vector REACT_vec; extern void DestroyREACT(void); extern void RCRead(std::string); extern double MATCalcIonicStrengthNew(long index); -extern void REACTInit(); //OK +extern void REACTInit(); // OK -extern int Call_IPQC(std::stringstream*, std::stringstream*); -//Water moles per kg of water +extern int Call_IPQC(std::stringstream*, std::stringstream*); +// Water moles per kg of water //#define MOLH2OPERKG 55.50843506 #endif diff --git a/FEM/rf_react_cap.cpp b/FEM/rf_react_cap.cpp index 5c1ed740f..56afc2bdf 100644 --- a/FEM/rf_react_cap.cpp +++ b/FEM/rf_react_cap.cpp @@ -9,7 +9,7 @@ /* - rf_react_cap.cpp + rf_react_cap.cpp Reaction package to go with CHEMAPP @@ -32,13 +32,12 @@ Kiel, 11/2008 #include "rfmat_cp.h" #include "rf_react_cap.h" #include "rf_react.h" -#include "rf_react_int.h" // new reaction interface +#include "rf_react_int.h" // new reaction interface #include "rf_ic_new.h" #include "stdio.h" //#include "geo_strings.h" - #include "rf_pcs.h" //OK_MOD" #include "files0.h" //#include "files.h" @@ -55,15 +54,15 @@ Kiel, 11/2008 #include "fem_ele_std.h" #ifdef OGS_FEM_CAP // CAP_REACT - #include "cacint.h" //DL +#include "cacint.h" //DL #else - /* Length of a TQ String */ - #define TQSTRLEN 25 +/* Length of a TQ String */ +#define TQSTRLEN 25 #endif #include "CAP_IO.h" #include "VLE.h" #include "HKF.h" -//CB2406 #endif +// CB2406 #endif using namespace std; /* @@ -76,12 +75,12 @@ extern char *crdat; // MX extern double gravity_constant; */ -vector REACT_CAP_vec; +vector REACT_CAP_vec; /**************************************************************************/ /* Constructor */ -REACT_CAP::REACT_CAP(void){ - +REACT_CAP::REACT_CAP(void) +{ flag_cap = false; /* DL 28,10,08*/ data_file = "false"; data_format = "false"; @@ -89,17 +88,14 @@ REACT_CAP::REACT_CAP(void){ check_no_reaction_nodes = false; // ToDo nodenumber = 0; - CAP_MODE = 0; // default case, when Chemapp IS available - - - - } + CAP_MODE = 0; // default case, when Chemapp IS available +} /* Destructor */ -REACT_CAP::~REACT_CAP(void){ +REACT_CAP::~REACT_CAP(void) +{ } /**************************************************************************/ - /************************************************************************** Function: REACT_CAP::Read @@ -109,486 +105,551 @@ REACT_CAP::~REACT_CAP(void){ Programming: 11/2008 DL/SB First Version **************************************************************************/ - ios::pos_type REACT_CAP::Read(ifstream *rfd_file, const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name){ - - bool new_keyword = false; - std::string hash("#"); - std::string line_string; - std::stringstream in; - ios::pos_type position; +ios::pos_type REACT_CAP::Read(ifstream* rfd_file, const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) +{ + bool new_keyword = false; + std::string hash("#"); + std::string line_string; + std::stringstream in; + ios::pos_type position; - int ipx, ik=0, ikh=0, ieh=0, j; + int ipx, ik = 0, ikh = 0, ieh = 0, j; std::string ncomp_x, idphase; - char *ncomp; - long value; + char* ncomp; + long value; std::string geometry_type, geometry_name; std::string line_str1, line_str2; double diff_value; vector pcs_name1; - vector pcs_stoi1; - + vector pcs_stoi1; this->species_relative_activity.clear(); this->species_relative_activity_name.clear(); - this->show_data_file=false; + this->show_data_file = false; this->Node_All_SI.clear(); - // go through input file - while (!new_keyword) { - - line_string = GetLineFromFile1(rfd_file); - //if(line_string.size() < 1) break; - - if(line_string.find(hash)!=string::npos) { - new_keyword = true; - break; - } - - /* read keywords */ - //.................................................................... - if(line_string.find("$CAP_MODE")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> CAP_MODE; //sub_line - in.clear(); - } - //.................................................................... - if(line_string.find("$DATA_FILE")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> data_file; //sub_line - in.clear(); - } - //.................................................................... - if(line_string.find("$DATA_FORMAT")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> data_format; //sub_line - in.clear(); - } - if(line_string.find("$SHOW_DATA_FILE")!=string::npos) // subkeyword found - this->show_data_file=true; - //.................................................................... - if(line_string.find("$MASS_NUM")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> mass_num; //sub_line - in.clear(); - } - //.................................................................... - if(line_string.find("$MASS_TYPE")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> mass_type; //sub_line - in.clear(); - } - //.................................................................... - if(line_string.find("$PHASE_LIST")!=string::npos){ // subkeyword found - this->phase_list.clear(); - this->phase_post.clear(); - while(1){ - in.str(GetLineFromFile1(rfd_file)); - in >> idphase; - if(!idphase.find("END")) { - in.clear(); - break; - } - this->phase_list.push_back(atoi(idphase.c_str())); - ncomp_x=""; + // go through input file + while (!new_keyword) + { + line_string = GetLineFromFile1(rfd_file); + // if(line_string.size() < 1) break; - in >> ncomp_x; - ncomp = new char [(int)ncomp_x.size()+1]; - strcpy(ncomp, ncomp_x.c_str()); - this->phase_post.push_back(ncomp); + if (line_string.find(hash) != string::npos) + { + new_keyword = true; + break; + } + + /* read keywords */ + //.................................................................... + if (line_string.find("$CAP_MODE") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> CAP_MODE; // sub_line in.clear(); } - } - //.................................................................... - if(line_string.find("$SPECIES_DEFINE")!=string::npos){ // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> species_define; //sub_line - in.clear(); - } - //.................................................................... - if(line_string.find("$SPECIES_LIST")!=string::npos){ // subkeyword found - this->species_list_name.clear(); - this->species_list_phase.clear(); - while(1){ + //.................................................................... + if (line_string.find("$DATA_FILE") != string::npos) + { // subkeyword found in.str(GetLineFromFile1(rfd_file)); - in >> ncomp_x; + in >> data_file; // sub_line in.clear(); - if(!ncomp_x.find("END")) break; - this->CompNamePhase(ncomp_x, ncomp, ipx); - species_list_name.push_back(ncomp); - species_list_phase.push_back(ipx); } - } - //.................................................................... - if(line_string.find("$KINETIC_SPECIES")!=string::npos){ // subkeyword found - this->species_kin_name.clear(); - this->species_kin_phase.clear(); - while(1){ + //.................................................................... + if (line_string.find("$DATA_FORMAT") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> data_format; // sub_line in.clear(); + } + if (line_string.find("$SHOW_DATA_FILE") != string::npos) // subkeyword found + this->show_data_file = true; + //.................................................................... + if (line_string.find("$MASS_NUM") != string::npos) + { // subkeyword found in.str(GetLineFromFile1(rfd_file)); - in >> ncomp_x; + in >> mass_num; // sub_line in.clear(); - if(!ncomp_x.find("END")) break; - this->CompNamePhase(ncomp_x, ncomp, ipx); - species_kin_name.push_back(ncomp); - species_kin_phase.push_back(ipx); } - } - - //.................................................................... - if(line_string.find("$KINETIC_REACTIONS")!=string::npos){ // subkeyword found - this->Kin_Reactions.clear(); - while(1){ + //.................................................................... + if (line_string.find("$MASS_TYPE") != string::npos) + { // subkeyword found in.str(GetLineFromFile1(rfd_file)); - in >> ncomp_x; - if(!ncomp_x.find("END")){ - if(ik>0) - this->Kin_Reactions.push_back(this->React); + in >> mass_type; // sub_line + in.clear(); + } + //.................................................................... + if (line_string.find("$PHASE_LIST") != string::npos) + { // subkeyword found + this->phase_list.clear(); + this->phase_post.clear(); + while (1) + { + in.str(GetLineFromFile1(rfd_file)); + in >> idphase; + if (!idphase.find("END")) + { + in.clear(); + break; + } + this->phase_list.push_back(atoi(idphase.c_str())); + ncomp_x = ""; + + in >> ncomp_x; + ncomp = new char[(int)ncomp_x.size() + 1]; + strcpy(ncomp, ncomp_x.c_str()); + this->phase_post.push_back(ncomp); in.clear(); - break; } - else if(!ncomp_x.find("REACTION")) { - if(ik>0) - this->Kin_Reactions.push_back(this->React); - in >> this->React.type; - this->React.species_stoi.clear(); - this->React.species_idx.clear(); - this->React.species_name.clear(); - this->React.species_phase.clear(); + } + //.................................................................... + if (line_string.find("$SPECIES_DEFINE") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> species_define; // sub_line + in.clear(); + } + //.................................................................... + if (line_string.find("$SPECIES_LIST") != string::npos) + { // subkeyword found + this->species_list_name.clear(); + this->species_list_phase.clear(); + while (1) + { + in.str(GetLineFromFile1(rfd_file)); + in >> ncomp_x; in.clear(); - ik++; + if (!ncomp_x.find("END")) + break; + this->CompNamePhase(ncomp_x, ncomp, ipx); + species_list_name.push_back(ncomp); + species_list_phase.push_back(ipx); } - else { - React.species_stoi.push_back((double)atof(ncomp_x.c_str())); + } + //.................................................................... + if (line_string.find("$KINETIC_SPECIES") != string::npos) + { // subkeyword found + this->species_kin_name.clear(); + this->species_kin_phase.clear(); + while (1) + { + in.clear(); + in.str(GetLineFromFile1(rfd_file)); in >> ncomp_x; in.clear(); + if (!ncomp_x.find("END")) + break; this->CompNamePhase(ncomp_x, ncomp, ipx); - React.species_name.push_back(ncomp); - React.species_phase.push_back(ipx); - React.species_idx.push_back(-1); + species_kin_name.push_back(ncomp); + species_kin_phase.push_back(ipx); } } - } - //.................................................................... - if(line_string.find("$KINETIC_HKF_REACTIONS")!=string::npos){ // subkeyword found - this->Kin_HKF_Reactions.clear(); - while(1){ - in.str(GetLineFromFile1(rfd_file)); - in >> ncomp_x; - if(!ncomp_x.find("END")){ - if(ikh>0) - this->Kin_HKF_Reactions.push_back(this->React); - in.clear(); - break; + + //.................................................................... + if (line_string.find("$KINETIC_REACTIONS") != string::npos) + { // subkeyword found + this->Kin_Reactions.clear(); + while (1) + { + in.str(GetLineFromFile1(rfd_file)); + in >> ncomp_x; + if (!ncomp_x.find("END")) + { + if (ik > 0) + this->Kin_Reactions.push_back(this->React); + in.clear(); + break; + } + else if (!ncomp_x.find("REACTION")) + { + if (ik > 0) + this->Kin_Reactions.push_back(this->React); + in >> this->React.type; + this->React.species_stoi.clear(); + this->React.species_idx.clear(); + this->React.species_name.clear(); + this->React.species_phase.clear(); + in.clear(); + ik++; + } + else + { + React.species_stoi.push_back((double)atof(ncomp_x.c_str())); + in >> ncomp_x; + in.clear(); + this->CompNamePhase(ncomp_x, ncomp, ipx); + React.species_name.push_back(ncomp); + React.species_phase.push_back(ipx); + React.species_idx.push_back(-1); + } } - else if(!ncomp_x.find("REACTION")) { - if(ikh>0) - this->Kin_HKF_Reactions.push_back(this->React); - in >> this->React.type; - this->React.species_stoi.clear(); - this->React.species_idx.clear(); - this->React.species_name.clear(); - this->React.species_phase.clear(); - in.clear(); - ikh++; + } + //.................................................................... + if (line_string.find("$KINETIC_HKF_REACTIONS") != string::npos) + { // subkeyword found + this->Kin_HKF_Reactions.clear(); + while (1) + { + in.str(GetLineFromFile1(rfd_file)); + in >> ncomp_x; + if (!ncomp_x.find("END")) + { + if (ikh > 0) + this->Kin_HKF_Reactions.push_back(this->React); + in.clear(); + break; + } + else if (!ncomp_x.find("REACTION")) + { + if (ikh > 0) + this->Kin_HKF_Reactions.push_back(this->React); + in >> this->React.type; + this->React.species_stoi.clear(); + this->React.species_idx.clear(); + this->React.species_name.clear(); + this->React.species_phase.clear(); + in.clear(); + ikh++; + } + else + { + React.species_stoi.push_back((double)atof(ncomp_x.c_str())); + in >> ncomp_x; + in.clear(); + this->CompNamePhase(ncomp_x, ncomp, ipx); + React.species_name.push_back(ncomp); + React.species_phase.push_back(ipx); + React.species_idx.push_back(-1); + } } - else { - React.species_stoi.push_back((double)atof(ncomp_x.c_str())); + } + if (line_string.find("$NLOG_AC") != string::npos) + { // subkeyword found + this->species_nlog_name.clear(); + this->species_nlog_phase.clear(); + while (1) + { + in.str(GetLineFromFile1(rfd_file)); + in >> ncomp_x; + if (!ncomp_x.find("END")) + { + in.clear(); + break; + } + ncomp = new char[(int)ncomp_x.size()]; + strcpy(ncomp, ncomp_x.c_str()); + this->nlog_name.push_back(ncomp); in >> ncomp_x; in.clear(); this->CompNamePhase(ncomp_x, ncomp, ipx); - React.species_name.push_back(ncomp); - React.species_phase.push_back(ipx); - React.species_idx.push_back(-1); + species_nlog_name.push_back(ncomp); + species_nlog_phase.push_back(ipx); } } - } - if(line_string.find("$NLOG_AC")!=string::npos){ // subkeyword found - this->species_nlog_name.clear(); - this->species_nlog_phase.clear(); - while(1){ - in.str(GetLineFromFile1(rfd_file)); - in >> ncomp_x; - if(!ncomp_x.find("END")) { + + if (line_string.find("$PCS_RENAME") != string::npos) + { // subkeyword found + this->pcs_rename0.clear(); + this->pcs_rename1.clear(); + while (1) + { + pcs_name1.clear(); + pcs_stoi1.clear(); + in.str(GetLineFromFile1(rfd_file)); + line_str2 = in.str(); + in >> ncomp_x; + if (!ncomp_x.find("END")) + { + in.clear(); + break; + } + this->pcs_rename0.push_back(ncomp_x); + // for(j=1;j<(int)REACT_PRQ::string2vector(line_str2).size();j+=2){ + for (j = 1; j < (int)REACTINT::string2vector(line_str2).size(); j += 2) + { + in >> ncomp_x; + if (ncomp_x == "*") + pcs_stoi1.push_back(999999); + else if (ncomp_x == "/") + pcs_stoi1.push_back(-999999); + else + pcs_stoi1.push_back((double)atof(ncomp_x.c_str())); + in >> ncomp_x; + pcs_name1.push_back(ncomp_x); + } + this->pcs_rename1.push_back(pcs_name1); + this->pcs_rename_stoi.push_back(pcs_stoi1); in.clear(); - break; } - ncomp = new char [(int)ncomp_x.size()]; - strcpy(ncomp, ncomp_x.c_str()); - this->nlog_name.push_back(ncomp); - in >> ncomp_x; - in.clear(); - this->CompNamePhase(ncomp_x, ncomp, ipx); - species_nlog_name.push_back(ncomp); - species_nlog_phase.push_back(ipx); } - } - if(line_string.find("$PCS_RENAME")!=string::npos){ // subkeyword found - this->pcs_rename0.clear(); - this->pcs_rename1.clear(); - while(1){ - pcs_name1.clear(); - pcs_stoi1.clear(); - in.str(GetLineFromFile1(rfd_file)); - line_str2=in.str(); - in >> ncomp_x; - if(!ncomp_x.find("END")) { + if (line_string.find("$PCS_PRE_RENAME") != string::npos) + { // subkeyword found + this->pcs_rename0_pre.clear(); + this->pcs_rename1_pre.clear(); + while (1) + { + pcs_name1.clear(); + pcs_stoi1.clear(); + in.str(GetLineFromFile1(rfd_file)); + line_str2 = in.str(); + in >> ncomp_x; + if (!ncomp_x.find("END")) + { + in.clear(); + break; + } + this->pcs_rename0_pre.push_back(ncomp_x); + // for(j=1;j<(int)REACT_PRQ::string2vector(line_str2).size();j+=2){ + for (j = 1; j < (int)REACTINT::string2vector(line_str2).size(); j += 2) + { + in >> ncomp_x; + if (ncomp_x == "*") + pcs_stoi1.push_back(999999); + else if (ncomp_x == "/") + pcs_stoi1.push_back(-999999); + else + pcs_stoi1.push_back((double)atof(ncomp_x.c_str())); + in >> ncomp_x; + pcs_name1.push_back(ncomp_x); + } + this->pcs_rename1_pre.push_back(pcs_name1); + this->pcs_rename_stoi_pre.push_back(pcs_stoi1); in.clear(); - break; } - this->pcs_rename0.push_back(ncomp_x); - //for(j=1;j<(int)REACT_PRQ::string2vector(line_str2).size();j+=2){ - for(j=1;j<(int)REACTINT::string2vector(line_str2).size();j+=2){ + } + + if (line_string.find("$RELATIVE_ACTIVITY") != string::npos) + { // subkeyword found + this->species_relative_activity_name.clear(); + this->species_relative_activity.clear(); + while (1) + { + in.str(GetLineFromFile1(rfd_file)); + line_str2 = in.str(); in >> ncomp_x; - if(ncomp_x=="*") - pcs_stoi1.push_back(999999); - else if(ncomp_x=="/") - pcs_stoi1.push_back(-999999); - else - pcs_stoi1.push_back((double)atof(ncomp_x.c_str())); + if (!ncomp_x.find("END")) + { + in.clear(); + break; + } + + this->CompNamePhase(ncomp_x, ncomp, ipx); + this->species_relative_activity_name.push_back(ncomp); in >> ncomp_x; - pcs_name1.push_back(ncomp_x); + this->species_relative_activity.push_back((double)atof(ncomp_x.c_str())); + in.clear(); } - this->pcs_rename1.push_back(pcs_name1); - this->pcs_rename_stoi.push_back(pcs_stoi1); - in.clear(); } - } - if(line_string.find("$PCS_PRE_RENAME")!=string::npos){ // subkeyword found - this->pcs_rename0_pre.clear(); - this->pcs_rename1_pre.clear(); - while(1){ - pcs_name1.clear(); - pcs_stoi1.clear(); - in.str(GetLineFromFile1(rfd_file)); - line_str2=in.str(); - in >> ncomp_x; - if(!ncomp_x.find("END")) { + if (line_string.find("$NODE_ALL_SI") != string::npos) + { // subkeyword found + this->Node_All_SI.clear(); + while (1) + { + in.str(GetLineFromFile1(rfd_file)); + line_str2 = in.str(); + in >> ncomp_x; + if (!ncomp_x.find("END")) + { + in.clear(); + break; + } + this->Node_All_SI.push_back((int)atoi(ncomp_x.c_str())); in.clear(); - break; } - this->pcs_rename0_pre.push_back(ncomp_x); - //for(j=1;j<(int)REACT_PRQ::string2vector(line_str2).size();j+=2){ - for(j=1;j<(int)REACTINT::string2vector(line_str2).size();j+=2){ + } + //.................................................................... + if (line_string.find("$REDOX_EH") != string::npos) + { // subkeyword found + this->species_redox_name.clear(); + this->species_redox_phase.clear(); + this->redox_stoi.clear(); + while (1) + { + in.str(GetLineFromFile1(rfd_file)); in >> ncomp_x; - if(ncomp_x=="*") - pcs_stoi1.push_back(999999); - else if(ncomp_x=="/") - pcs_stoi1.push_back(-999999); + if (!ncomp_x.find("END")) + { + in.clear(); + break; + } + if (ieh < 2) + { + ncomp = new char[(int)ncomp_x.size()]; + strcpy(ncomp, ncomp_x.c_str()); + ipx = 0; + } else - pcs_stoi1.push_back((double)atof(ncomp_x.c_str())); - in >> ncomp_x; - pcs_name1.push_back(ncomp_x); - } - this->pcs_rename1_pre.push_back(pcs_name1); - this->pcs_rename_stoi_pre.push_back(pcs_stoi1); - in.clear(); - } - } - - - - if(line_string.find("$RELATIVE_ACTIVITY")!=string::npos){ // subkeyword found - this->species_relative_activity_name.clear(); - this->species_relative_activity.clear(); - while(1){ - in.str(GetLineFromFile1(rfd_file)); - line_str2=in.str(); - in >> ncomp_x; - if(!ncomp_x.find("END")) { + this->CompNamePhase(ncomp_x, ncomp, ipx); + species_redox_name.push_back(ncomp); + species_redox_phase.push_back(ipx); + in >> value; in.clear(); - break; + this->redox_stoi.push_back(value); + ieh++; } - - this->CompNamePhase(ncomp_x, ncomp, ipx); - this->species_relative_activity_name.push_back(ncomp); - in >> ncomp_x; - this->species_relative_activity.push_back((double)atof(ncomp_x.c_str())); - in.clear(); } - } + //.................................................................... + if (line_string.find("$SET_BC_EQ_GEO") != string::npos) + { // subkeyword found + this->ic_2_bc_geometry_type.clear(); + this->ic_2_bc_geometry_name.clear(); + this->ic_2_bc_GeoID.clear(); + while (1) + { + line_str1 = GetLineFromFile1(rfd_file); + if ((line_str1.find("$") != string::npos) || (line_str1.find("#STOP") != string::npos) + || (line_str1.find("END") != string::npos)) + { + break; + } + in.str(line_str1); + in >> geometry_type >> geometry_name; + ic_2_bc_geometry_type.push_back(geometry_type); + ic_2_bc_geometry_name.push_back(geometry_name); + + // TF 06/2010 - for the change string-ID to size_t-ID + size_t geo_obj_idx(std::numeric_limits::max()); + + if (geometry_type.find("POINT") != std::string::npos) + { + // get the point vector and set the geo_obj_idx + if (!((geo_obj.getPointVecObj(unique_name))->getElementIDByName(geometry_name, geo_obj_idx))) + { + std::cerr << "error in CKinReactData::Read: (type=" << geometry_type << "): " << geometry_name + << " point name not found!" + << "\n"; + exit(1); + } + } + if (geometry_type.find("POLYLINE") != std::string::npos) + { + // get the point vector and set the geo_obj_idx + if (!((geo_obj.getPolylineVecObj(unique_name))->getElementIDByName(geometry_name, geo_obj_idx))) + { + std::cerr << "error in CKinReactData::Read: polyline name " << geometry_name << " not found!" + << "\n"; + exit(1); + } + } - if(line_string.find("$NODE_ALL_SI")!=string::npos){ // subkeyword found - this->Node_All_SI.clear(); - while(1){ - in.str(GetLineFromFile1(rfd_file)); - line_str2=in.str(); - in >> ncomp_x; - if(!ncomp_x.find("END")) { + ic_2_bc_GeoID.push_back(geo_obj_idx); in.clear(); - break; + // break; } - this->Node_All_SI.push_back((int)atoi(ncomp_x.c_str())); - in.clear(); } - } - //.................................................................... - if(line_string.find("$REDOX_EH")!=string::npos){ // subkeyword found - this->species_redox_name.clear(); - this->species_redox_phase.clear(); - this->redox_stoi.clear(); - while(1){ - in.str(GetLineFromFile1(rfd_file)); - in >> ncomp_x; - if(!ncomp_x.find("END")){ + //.................................................................... + if (line_string.find("$SET_BC_EQ_SPECIES") != std::string::npos) + { // subkeyword found + this->ic_2_bc_species.clear(); + this->ic_2_bc_species_value.clear(); + while (1) + { + line_str1 = GetLineFromFile1(rfd_file); + if ((line_str1.find("$") != string::npos) || (line_str1.find("#STOP") != string::npos) + || (line_str1.find("END") != string::npos)) + { + break; + } + in.str(line_str1); + in >> geometry_name; // actually, this reads in a species name ... + ic_2_bc_species.push_back(geometry_name); + diff_value = 0.0; + in >> diff_value; + this->ic_2_bc_species_value.push_back(diff_value); in.clear(); - break; + // break; } - if(ieh<2) { - ncomp = new char [(int)ncomp_x.size()]; - strcpy(ncomp, ncomp_x.c_str()); - ipx=0; - } - else - this->CompNamePhase(ncomp_x, ncomp, ipx); - species_redox_name.push_back(ncomp); - species_redox_phase.push_back(ipx); - in >> value; - in.clear(); - this->redox_stoi.push_back(value); - ieh++; } - } - //.................................................................... - if(line_string.find("$SET_BC_EQ_GEO")!=string::npos){ // subkeyword found - this->ic_2_bc_geometry_type.clear(); - this->ic_2_bc_geometry_name.clear(); - this->ic_2_bc_GeoID.clear(); - while(1){ - line_str1 = GetLineFromFile1(rfd_file); - if((line_str1.find("$")!=string::npos)||(line_str1.find("#STOP")!=string::npos)||(line_str1.find("END")!=string::npos)) { - break; - } - in.str(line_str1); - in >> geometry_type >> geometry_name; - ic_2_bc_geometry_type.push_back(geometry_type); - ic_2_bc_geometry_name.push_back(geometry_name); - - // TF 06/2010 - for the change string-ID to size_t-ID - size_t geo_obj_idx(std::numeric_limits::max()); - - if (geometry_type.find("POINT") != std::string::npos) - { - // get the point vector and set the geo_obj_idx - if (!((geo_obj.getPointVecObj(unique_name))->getElementIDByName( - geometry_name, geo_obj_idx))) - { - std::cerr - << "error in CKinReactData::Read: (type=" << geometry_type << "): " << geometry_name << " point name not found!" - << "\n"; - exit(1); - } - } - if (geometry_type.find("POLYLINE") != std::string::npos) - { - // get the point vector and set the geo_obj_idx - if (!((geo_obj.getPolylineVecObj(unique_name))->getElementIDByName( - geometry_name, geo_obj_idx))) - { - std::cerr - << "error in CKinReactData::Read: polyline name " << geometry_name << " not found!" - << "\n"; - exit(1); - } - } - - ic_2_bc_GeoID.push_back(geo_obj_idx); - in.clear(); - //break; - } - } - //.................................................................... - if(line_string.find("$SET_BC_EQ_SPECIES")!=std::string::npos){ // subkeyword found - this->ic_2_bc_species.clear(); - this->ic_2_bc_species_value.clear(); - while(1){ - line_str1 = GetLineFromFile1(rfd_file); - if((line_str1.find("$")!=string::npos)||(line_str1.find("#STOP")!=string::npos)||(line_str1.find("END")!=string::npos)) { - break; - } - in.str(line_str1); - in >> geometry_name; // actually, this reads in a species name ... - ic_2_bc_species.push_back(geometry_name); - diff_value = 0.0; - in >> diff_value; - this->ic_2_bc_species_value.push_back(diff_value); - in.clear(); - //break; - } - } - } // end while - return position; + } // end while + return position; } -void REACT_CAP::RecoverChemSystem(void){ - //int i,ii; - //LI nphase, npcon, noerr; - if(!this->species_define.compare("TRANS")) +void REACT_CAP::RecoverChemSystem(void) +{ + // int i,ii; + // LI nphase, npcon, noerr; + if (!this->species_define.compare("TRANS")) this->DefSpeciesInChemApp(); - else if(!this->species_define.compare("LIST")) + else if (!this->species_define.compare("LIST")) this->DefSpeciesInChemAppList(); else this->DefSpeciesInChemAppAll(); } - /* ChemApp subroutine for chemical reaction calculation DL 28,10,08 */ -void REACT_CAP::ExecuteReactionsChemApp(int f, int nodeflag){ - - //CAP_MODE=2; // now from input file - CAP_icount=1; - CAP_Time=0; - CAP_Node=0; +void REACT_CAP::ExecuteReactionsChemApp(int f, int nodeflag) +{ + // CAP_MODE=2; // now from input file + CAP_icount = 1; + CAP_Time = 0; + CAP_Node = 0; int ii, ok = 0, ik = 0; - if(f==0){ + if (f == 0) + { this->CreateREACT(); // set nodenumber and rateflag this->InitChemApp(); // read DATAFILE - if(this->show_data_file){ - cout << " ==> Show Data File" << "\n"; + if (this->show_data_file) + { + cout << " ==> Show Data File" + << "\n"; this->ShowDataFile(); } this->LoadMassPCS(); // read process and get MASS TRANSPORT list - this->CmpSpeciesListPCS(); //consistent checking between TRANS and DATAFILE - this->CmpSpeciesListKIN();//DL 03.2010 + this->CmpSpeciesListPCS(); // consistent checking between TRANS and DATAFILE + this->CmpSpeciesListKIN(); // DL 03.2010 - if(!this->species_define.compare("TRANS")) { - cout << " Define TRANS as Chemical Reaction Species " << "\n"; + if (!this->species_define.compare("TRANS")) + { + cout << " Define TRANS as Chemical Reaction Species " + << "\n"; this->DefSpeciesInChemApp(); } - else if(!this->species_define.compare("LIST")) { - cout << " Define LIST as Chemical Reaction Species " << "\n"; - this->CmpSpeciesListDAT(); //consistent checking between .cap species_list and DATAFILE - if(this->CmpSpeciesList()) //consistent checking between .cap species_list and TRANS - cout << " The two species lists are compatible. OK..." << "\n"; - else cout << " Incompatibility checking ERROR..." << "\n"; + else if (!this->species_define.compare("LIST")) + { + cout << " Define LIST as Chemical Reaction Species " + << "\n"; + this->CmpSpeciesListDAT(); // consistent checking between .cap species_list and DATAFILE + if (this->CmpSpeciesList()) // consistent checking between .cap species_list and TRANS + cout << " The two species lists are compatible. OK..." + << "\n"; + else + cout << " Incompatibility checking ERROR..." + << "\n"; this->DefSpeciesInChemAppList(); } - else{ - //this->UndefOutSpecies(); - cout << " UNDEF SPECIES, USING THE TOTAL SPECIES LIST " << "\n"; + else + { + // this->UndefOutSpecies(); + cout << " UNDEF SPECIES, USING THE TOTAL SPECIES LIST " + << "\n"; this->DefSpeciesInChemAppAll(); } - - if(!this->mass_type.compare("ELEMENT")){ - cout << " SET MASS TRANSPORT AS ELEMENT " << "\n"; - if(CAP_MODE==2) - cout << " File Mode " << "\n"; + if (!this->mass_type.compare("ELEMENT")) + { + cout << " SET MASS TRANSPORT AS ELEMENT " + << "\n"; + if (CAP_MODE == 2) + cout << " File Mode " + << "\n"; else this->ResetElement(); - }else - cout << " SET MASS TRANSPORT AS SPECIES (defualt) " << "\n"; + } + else + cout << " SET MASS TRANSPORT AS SPECIES (defualt) " + << "\n"; - this->CmpSpeciesListKinReact();//DL 03.2010 + this->CmpSpeciesListKinReact(); // DL 03.2010 - this->SetKinHKFspecies(); //DL 11.2010 - if(this->Kin_HKF_species.size()>0) + this->SetKinHKFspecies(); // DL 11.2010 + if (this->Kin_HKF_species.size() > 0) this->LoadHKFparam(); this->CmpSpeciesListNLOG(); @@ -599,124 +660,145 @@ void REACT_CAP::ExecuteReactionsChemApp(int f, int nodeflag){ this->warning_out.clear(); this->warning_out.open("ChemApp_Warning.txt", ios::out); + cout << "-------------------------------" + << "\n"; + cout << " END CHEMAPP INITIAL " + << "\n"; + cout << "-------------------------------" + << "\n"; - cout << "-------------------------------" << "\n"; - cout << " END CHEMAPP INITIAL " << "\n"; - cout << "-------------------------------" << "\n"; - - - //this->KinInit(); + // this->KinInit(); - cout.flush() << " Calculating geochemical equilibrium at all nodes using initial values." << "\n"; + cout.flush() << " Calculating geochemical equilibrium at all nodes using initial values." + << "\n"; this->LoopNodeReact(0, nodeflag); } // f == 0 - if(f==1 || f==-1){ + if (f == 1 || f == -1) + { // Check for nodes without reactions - if((int)this->check_no_reaction_nodes == false){ - ok = this->CheckNoReactionNodes(); //default rateflag=1 for reaction calc - if(!ok) cout << "Error when checking for nodes without reactions" << "\n" << "\n"; + if ((int)this->check_no_reaction_nodes == false) + { + ok = this->CheckNoReactionNodes(); // default rateflag=1 for reaction calc + if (!ok) + cout << "Error when checking for nodes without reactions" + << "\n" + << "\n"; } - for(ii=0;iinodenumber;ii++) if(this->rateflag[ii] != 0) ik++; - cout << " Calculating geochemical equilibrium at " << ik << " nodes." << "\n"; - - if(f==1) - this->LoopNodeReact(1, nodeflag); - else if(f==-1) - this->LoopNodeReact_Liquid_Vapor(1, nodeflag); + for (ii = 0; ii < this->nodenumber; ii++) + if (this->rateflag[ii] != 0) + ik++; + cout << " Calculating geochemical equilibrium at " << ik << " nodes." + << "\n"; + if (f == 1) + this->LoopNodeReact(1, nodeflag); + else if (f == -1) + this->LoopNodeReact_Liquid_Vapor(1, nodeflag); } - //if(f==2){ + // if(f==2){ // for(ii=0;iinodenumber;ii++) if(this->rateflag[ii] != 0) ik++; // cout << " Calculating geochemical kinetic at " << ik << " nodes." << "\n"; //} - } - /*********************************************************************************************** ************************************************************************************************/ -int REACT_CAP::CheckNoReactionNodes(void){ - +int REACT_CAP::CheckNoReactionNodes(void) +{ int ok = 0; long l; - cout << " CheckNoReactionNodes " << "\n"; - - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt - if(m_msh == NULL) {cout << "No mesh in CheckNoReactionNodes" << "\n"; exit(0);} - -//CB 19.1.2011 - // Get the reaction interface data for checking for dried out nodes from eclipse coupling --> rateflag = 0 - REACTINT *m_rei = NULL; - if(REACTINT_vec.size()>0) - m_rei = REACTINT_vec[0]; + cout << " CheckNoReactionNodes " + << "\n"; + + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt + if (m_msh == NULL) + { + cout << "No mesh in CheckNoReactionNodes" + << "\n"; + exit(0); + } + // CB 19.1.2011 + // Get the reaction interface data for checking for dried out nodes from eclipse coupling --> rateflag = 0 + REACTINT* m_rei = NULL; + if (REACTINT_vec.size() > 0) + m_rei = REACTINT_vec[0]; - if(aktueller_zeitschritt < 2){ //do not in the very first calculation before first time step and in the first time step + if (aktueller_zeitschritt < 2) + { // do not in the very first calculation before first time step and in the first time step this->check_no_reaction_nodes = false; } - else{ - CKinReactData *m_krd = NULL; - if(KinReactData_vector.size()>0) + else + { + CKinReactData* m_krd = NULL; + if (KinReactData_vector.size() > 0) m_krd = KinReactData_vector[0]; - if(m_krd == NULL){ + if (m_krd == NULL) + { // no KinReactData specified in *.krc file - cout << "No CKinReactData available in CheckNoReactionNodes" << "\n"; + cout << "No CKinReactData available in CheckNoReactionNodes" + << "\n"; } - else{ - if(m_krd->is_a_CCBC.size() > 0){ // reaction nodes specified in krc input file + else + { + if (m_krd->is_a_CCBC.size() > 0) + { // reaction nodes specified in krc input file // Initialize vector is_a_CCBC - for(l=0; l< (long)m_msh->nod_vector.size();l++) { // node 1 needed for phreeqc-input + for (l = 0; l < (long)m_msh->nod_vector.size(); l++) + { // node 1 needed for phreeqc-input this->rateflag[l] = 1; - if(m_krd->is_a_CCBC[l] == true) this->rateflag[l] = 0; // rateflag == 0 means no reactions calculated + if (m_krd->is_a_CCBC[l] == true) + this->rateflag[l] = 0; // rateflag == 0 means no reactions calculated // cout << " Node " << l << " is " << this->rateflag[l] << "\n"; } } } - // also, switch off reactions for nodes with Sat Water < WaterSatLimit to avoid dryout problem in Eclipse coupling - if(m_rei){ - if(m_rei->s_water_limit) - for(l=0; l< (long)m_msh->nod_vector.size();l++) - if(m_rei->dried_out_nodes[l]) - rateflag[l] = 0; - } + // also, switch off reactions for nodes with Sat Water < WaterSatLimit to avoid dryout problem in Eclipse + // coupling + if (m_rei) + { + if (m_rei->s_water_limit) + for (l = 0; l < (long)m_msh->nod_vector.size(); l++) + if (m_rei->dried_out_nodes[l]) + rateflag[l] = 0; + } this->check_no_reaction_nodes = true; } - ok=1; + ok = 1; return ok; } - -void REACT_CAP::CreateREACT(void){ - +void REACT_CAP::CreateREACT(void) +{ int i, vector_size; long l; - CRFProcess *m_pcs = NULL; + CRFProcess* m_pcs = NULL; - vector_size = (int) pcs_vector.size(); - for(i=0;ipcs_type_name.compare("MASS_TRANSPORT")==0){ - if(m_pcs->getProcessType()==FiniteElement::MASS_TRANSPORT){ - nodenumber = (long) m_pcs->m_msh->GetNodesNumber(false); + // if(m_pcs->pcs_type_name.compare("MASS_TRANSPORT")==0){ + if (m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) + { + nodenumber = (long)m_pcs->m_msh->GetNodesNumber(false); // elenumber = (long) m_pcs->m_msh->ele_vector.size(); } } - rateflag = (int *) Malloc(sizeof(int) * nodenumber); - for(l=0; l< nodenumber;l++) - rateflag[l] = 1; - CAP_count=0; - + rateflag = (int*)Malloc(sizeof(int) * nodenumber); + for (l = 0; l < nodenumber; l++) + rateflag[l] = 1; + CAP_count = 0; } - /************************************************************** Function: REACT_CAP::InitChemApp @@ -724,170 +806,212 @@ void REACT_CAP::CreateREACT(void){ Loading DATABASE file. DL 12.2008 **************************************************************/ -void REACT_CAP::InitChemApp(void){ - - LI noerr, version; - //CRFProcess* m_pcs = NULL; - char *cap_datafile; - +void REACT_CAP::InitChemApp(void) +{ + LI noerr, version; + // CRFProcess* m_pcs = NULL; + char* cap_datafile; #ifndef OGS_FEM_CAP // CAP_REACT - cout << " Warning in REACT_CAP::InitChemApp():" << "\n"; - cout << " ChemApp source files are not included in this configuration." << "\n"; - cout << " Installation of ChemApp and usage of CMake option OGS_FEM_CAP" << "\n"; - cout << " is required for coupled OGS_CAP simulation." << "\n"; - - if(CAP_MODE!=2){ - cout << " CAP_MODE = " << CAP_MODE << " was defined in *.cap input file:" << "\n"; - if(CAP_MODE==0){ - cout << " (normal ChemApp calculation, this is the default case, " << "\n"; - cout << " also when $CAP_MODE Keyword is not used in *.cap input file." << "\n"; - } - else if(CAP_MODE==1){ - cout << " (normal ChemApp calculation with storage of results in text files." << "\n"; - } - cout << " Options for $CAP_MODE Keyword: " << "\n"; - cout << " 0: default, 1: write result files, 2: read result files)" << "\n"; - CAP_MODE = 2; // default case, when Chemapp IS NOT available - cout << " Setting CAP_MODE = " << CAP_MODE << ": Read ChemApp results from precalculated files." << "\n"; - } - else - cout << " CAP_MODE = " << CAP_MODE << ": Read ChemApp results from precalculated files." << "\n"; + cout << " Warning in REACT_CAP::InitChemApp():" + << "\n"; + cout << " ChemApp source files are not included in this configuration." + << "\n"; + cout << " Installation of ChemApp and usage of CMake option OGS_FEM_CAP" + << "\n"; + cout << " is required for coupled OGS_CAP simulation." + << "\n"; + + if (CAP_MODE != 2) + { + cout << " CAP_MODE = " << CAP_MODE << " was defined in *.cap input file:" + << "\n"; + if (CAP_MODE == 0) + { + cout << " (normal ChemApp calculation, this is the default case, " + << "\n"; + cout << " also when $CAP_MODE Keyword is not used in *.cap input file." + << "\n"; + } + else if (CAP_MODE == 1) + { + cout << " (normal ChemApp calculation with storage of results in text files." + << "\n"; + } + cout << " Options for $CAP_MODE Keyword: " + << "\n"; + cout << " 0: default, 1: write result files, 2: read result files)" + << "\n"; + CAP_MODE = 2; // default case, when Chemapp IS NOT available + cout << " Setting CAP_MODE = " << CAP_MODE << ": Read ChemApp results from precalculated files." + << "\n"; + } + else + cout << " CAP_MODE = " << CAP_MODE << ": Read ChemApp results from precalculated files." + << "\n"; #endif -if(CAP_MODE==2){ - // check for results file folder - cout << "\n" << " CAP_MODE = " << CAP_MODE << "\n"; - cout << " Checking OGS input files..." << "\n"; - bool files = CAP_check_file(); - - if (files==false){ - cout << "\n" << " Warning: No ChemApp results files available. Exiting now..."; - exit(0); - } - cout << " Read ChemApp results from precalculated files" << "\n"; -} - + if (CAP_MODE == 2) + { + // check for results file folder + cout << "\n" + << " CAP_MODE = " << CAP_MODE << "\n"; + cout << " Checking OGS input files..." + << "\n"; + bool files = CAP_check_file(); - - CAP_tqini(&noerr); - CAP_tqvers(&version,&noerr); - cout <<"\n" << "---------------------------------------------------------------"<< "\n"; - cout <<" This program has been compiled with ChemApp version " << version << "\n"; - cout <<" ChemApp Module for Chemical Reaction Calculation...Start... "<< "\n"; - cout <<"---------------------------------------------------------------"<< "\n"; - //CGSProject* m_gsp = NULL; - //m_gsp = GSPGetMember("mmp"); - //if(m_gsp) - // cap_datafile = new char [m_gsp->path.length() + this->data_file.length()]; - //strcpy(cap_datafile, m_gsp->path.c_str()); - //strcat(cap_datafile, this->data_file.c_str()); - cap_datafile = new char [this->data_file.length()]; + if (files == false) + { + cout << "\n" + << " Warning: No ChemApp results files available. Exiting now..."; + exit(0); + } + cout << " Read ChemApp results from precalculated files" + << "\n"; + } + + CAP_tqini(&noerr); + CAP_tqvers(&version, &noerr); + cout << "\n" + << "---------------------------------------------------------------" + << "\n"; + cout << " This program has been compiled with ChemApp version " << version << "\n"; + cout << " ChemApp Module for Chemical Reaction Calculation...Start... " + << "\n"; + cout << "---------------------------------------------------------------" + << "\n"; + // CGSProject* m_gsp = NULL; + // m_gsp = GSPGetMember("mmp"); + // if(m_gsp) + // cap_datafile = new char [m_gsp->path.length() + this->data_file.length()]; + // strcpy(cap_datafile, m_gsp->path.c_str()); + // strcat(cap_datafile, this->data_file.c_str()); + cap_datafile = new char[this->data_file.length()]; strcpy(cap_datafile, this->data_file.c_str()); cout << "THERMOCHEM DATA FILE --> " << cap_datafile << "\n"; - noerr=1; - if(data_format=="DAT"){ - CAP_tqopna(cap_datafile,10,&noerr); + noerr = 1; + if (data_format == "DAT") + { + CAP_tqopna(cap_datafile, 10, &noerr); CAP_tqrfil(&noerr); } - if(data_format=="BIN"){ - CAP_tqopnb(cap_datafile,10,&noerr); + if (data_format == "BIN") + { + CAP_tqopnb(cap_datafile, 10, &noerr); CAP_tqrbin(&noerr); } - if(data_format=="CST"){ - CAP_tqopnt(cap_datafile,10,&noerr); + if (data_format == "CST") + { + CAP_tqopnt(cap_datafile, 10, &noerr); CAP_tqrcst(&noerr); } - if(!noerr) cout << " READ DATA FILE OK ..." << "\n" << "\n"; - else { cout << " READ DATA FILE ERROR !!! STOP." << "\n" << "\n"; - exit (1); } //STOP and EXIT - CAP_tqclos(10,&noerr); + if (!noerr) + cout << " READ DATA FILE OK ..." + << "\n" + << "\n"; + else + { + cout << " READ DATA FILE ERROR !!! STOP." + << "\n" + << "\n"; + exit(1); + } // STOP and EXIT + CAP_tqclos(10, &noerr); - //pH Eh save as species output - //for(ii=this->mass_num; ii<(int)pcs_mass_idx.size(); ii++){ + // pH Eh save as species output + // for(ii=this->mass_num; ii<(int)pcs_mass_idx.size(); ii++){ // m_pcs = pcs_vector[pcs_mass_idx[ii]]; - // if(strcmp(m_pcs->pcs_primary_function_name[0], "pH")==0 || strcmp(m_pcs->pcs_primary_function_name[0], "Eh")==0){ + // if(strcmp(m_pcs->pcs_primary_function_name[0], "pH")==0 || strcmp(m_pcs->pcs_primary_function_name[0], + //"Eh")==0){ // cout << " --> " << m_pcs->pcs_primary_function_name[0] << "\n"; // pcs_ospecies_idx.push_back(pcs_mass_idx[ii]); // } //} } -void REACT_CAP::ShowDataFile(void){ +void REACT_CAP::ShowDataFile(void) +{ LI noerr, nscom, npcon, i; char scname[TQSTRLEN]; CAP_tqnosc(&nscom, &noerr); printf("--> %li elements\n", nscom); - for (i = 1; i <= nscom; i++) { //elements list + for (i = 1; i <= nscom; i++) + { // elements list CAP_tqgnsc(i, scname, &noerr); printf("%li: %s\n", i, scname); } CAP_tqnop(&nscom, &noerr); printf("--> %li phases\n", nscom); - for (i = 1; i <= nscom; i++) { //phases list + for (i = 1; i <= nscom; i++) + { // phases list CAP_tqgnp(i, scname, &noerr); printf("%li: %s\n", i, scname); } CAP_tqnopc(1, &npcon, &noerr); printf("--> %li constituents in gas phase\n", npcon); - for (i = 1; i <= npcon; i++) { //gas species + for (i = 1; i <= npcon; i++) + { // gas species CAP_tqgnpc(1, i, scname, &noerr); printf("%li: %s\n", i, scname); } CAP_tqnopc(2, &npcon, &noerr); printf("--> %li constituents in aqueous solution\n", npcon); - for (i = 1; i <= npcon; i++) { //aqueous solution species + for (i = 1; i <= npcon; i++) + { // aqueous solution species CAP_tqgnpc(2, i, scname, &noerr); printf("%li: %s\n", i, scname); } } - -void REACT_CAP::CompNamePhase(std::string ncomp_x, char* &ncomp, int &ipx){ - +void REACT_CAP::CompNamePhase(std::string ncomp_x, char*& ncomp, int& ipx) +{ size_t i, np; - int flag=0; + int flag = 0; std::string postfix; - for(i=0; iphase_list.size(); i++){ - postfix=phase_post[i]; - np = ncomp_x.size()-postfix.size(); - if(ncomp_x.rfind(postfix)==np && postfix!=""){ - flag=1; - ipx=phase_list[i]; - ncomp = (char *)malloc(25); // new char [np]; //CB-DL?? - //ncomp = new char [np]; // (char *)malloc(25); // CB200412: I'm not sure, mallloc was in my version - strcpy(ncomp, ncomp_x.substr(0,np).c_str()); - } - if(flag==0 && postfix==""){ - flag=1; - ipx=phase_list[i]; - ncomp = new char [np]; - strcpy(ncomp, ncomp_x.substr(0,np).c_str()); + for (i = 0; i < this->phase_list.size(); i++) + { + postfix = phase_post[i]; + np = ncomp_x.size() - postfix.size(); + if (ncomp_x.rfind(postfix) == np && postfix != "") + { + flag = 1; + ipx = phase_list[i]; + ncomp = (char*)malloc(25); // new char [np]; //CB-DL?? + // ncomp = new char [np]; // (char *)malloc(25); // CB200412: I'm not sure, mallloc was in my version + strcpy(ncomp, ncomp_x.substr(0, np).c_str()); + } + if (flag == 0 && postfix == "") + { + flag = 1; + ipx = phase_list[i]; + ncomp = new char[np]; + strcpy(ncomp, ncomp_x.substr(0, np).c_str()); } } - if(flag==0){ - cout << " ERROR!... " << ncomp_x << " out of PHASE LIST. STOP!" << "\n"; + if (flag == 0) + { + cout << " ERROR!... " << ncomp_x << " out of PHASE LIST. STOP!" + << "\n"; exit(0); } - } - /************************************************************** Function: REACT_CAP::LoadMassPCS - Task: + Task: Loading Mass_Transport from Processes list. - Get index of phases by postfix of name - check name of species validity + Get index of phases by postfix of name + check name of species validity DL 01.2009 **************************************************************/ -void REACT_CAP::LoadMassPCS(void){ - int i, ims, no_pcs, ipx;//number of process and transport species ipx 0-solid 1-gas 2-aqueous +void REACT_CAP::LoadMassPCS(void) +{ + int i, ims, no_pcs, ipx; // number of process and transport species ipx 0-solid 1-gas 2-aqueous CRFProcess* m_pcs = NULL; char* ncomp = new char[TQSTRLEN]; std::string ncomp_x; @@ -896,11 +1020,13 @@ void REACT_CAP::LoadMassPCS(void){ vector idx0, idx1, idx0_pre, idx1_pre; vector > pcs_idx1, pcs_idx1_pre; - cout << "\n" << " => LoadMassPCS() " << "\n"; + cout << "\n" + << " => LoadMassPCS() " + << "\n"; cout << " REACTIVE_MASS_NUM " << this->mass_num << "\n"; pcs_mass_idx.clear(); - ims=0; - //loading in mass_transport from processes list + ims = 0; + // loading in mass_transport from processes list species_idx.clear(); species_phase.clear(); species_name.clear(); @@ -909,1517 +1035,1904 @@ void REACT_CAP::LoadMassPCS(void){ idx0.clear(); pcs_idx1.clear(); - nrs=(int)pcs_rename0.size(); - for(j=0;jgetProcessType() << " " << m_pcs->pcs_primary_function_name[0] << "\n"; - //if(!m_pcs->pcs_type_name.compare("MASS_TRANSPORT")){ - if(m_pcs->getProcessType()==FiniteElement::MASS_TRANSPORT){ - pcs_mass_idx.push_back(i); //mass index storage + cout << left << " Process " << setw(6) << i << setw(18) << m_pcs->getProcessType() << " " + << m_pcs->pcs_primary_function_name[0] << "\n"; + // if(!m_pcs->pcs_type_name.compare("MASS_TRANSPORT")){ + if (m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) + { + pcs_mass_idx.push_back(i); // mass index storage species_mobil.push_back(cp_vec[m_pcs->pcs_component_number]->mobil); - if(imspcs_primary_function_name[0]; + ncomp_x = m_pcs->pcs_primary_function_name[0]; this->CompNamePhase(ncomp_x, ncomp, ipx); species_name.push_back(ncomp); species_phase.push_back(ipx); } } - for(j=0;jpcs_primary_function_name[0] == pcs_rename0[j]) - idx0[j]=i; - for(jx=0;jx<(int)pcs_rename1[j].size();jx++) - if(m_pcs->pcs_primary_function_name[0] == pcs_rename1[j][jx]) - pcs_idx1[j][jx]=i; + for (j = 0; j < nrs; j++) + { + if (m_pcs->pcs_primary_function_name[0] == pcs_rename0[j]) + idx0[j] = i; + for (jx = 0; jx < (int)pcs_rename1[j].size(); jx++) + if (m_pcs->pcs_primary_function_name[0] == pcs_rename1[j][jx]) + pcs_idx1[j][jx] = i; } - for(j=0;jpcs_primary_function_name[0] == pcs_rename0_pre[j]) - idx0_pre[j]=i; - for(jx=0;jx<(int)pcs_rename1_pre[j].size();jx++) - if(m_pcs->pcs_primary_function_name[0] == pcs_rename1_pre[j][jx]) - pcs_idx1_pre[j][jx]=i; + for (j = 0; j < nrs_pre; j++) + { + if (m_pcs->pcs_primary_function_name[0] == pcs_rename0_pre[j]) + idx0_pre[j] = i; + for (jx = 0; jx < (int)pcs_rename1_pre[j].size(); jx++) + if (m_pcs->pcs_primary_function_name[0] == pcs_rename1_pre[j][jx]) + pcs_idx1_pre[j][jx] = i; } } - - //set pcs rename - cout << "\n" << " PCS_RENAME " << "\n"; + // set pcs rename + cout << "\n" + << " PCS_RENAME " + << "\n"; this->pcs_rename_idx0.clear(); this->pcs_rename_idx1.clear(); - for(i=0;ipcs_rename_idx0_pre.clear(); this->pcs_rename_idx1_pre.clear(); - for(i=0;i CmpSpeciesListREDOX() " << "\n"; - //compare REDOX_EH LIST with DATAFILE and get redox_idx - this->pcs_redox=-1; + cout << "\n" + << "\n" + << " => CmpSpeciesListREDOX() " + << "\n"; + // compare REDOX_EH LIST with DATAFILE and get redox_idx + this->pcs_redox = -1; ns = (int)species_redox_name.size(); - for(i=0;imass_num; ii<(int)pcs_mass_idx.size(); ii++){ + for (i = 0; i < ns; i++) + { + if (i == 0) + { + for (ii = this->mass_num; ii < (int)pcs_mass_idx.size(); ii++) + { m_pcs = pcs_vector[pcs_mass_idx[ii]]; - if(this->species_mobil[ii]==0 && strcmp(m_pcs->pcs_primary_function_name[0], species_redox_name[i])==0){ + if (this->species_mobil[ii] == 0 + && strcmp(m_pcs->pcs_primary_function_name[0], species_redox_name[i]) == 0) + { cout << " --> " << species_redox_name[i] << "\n"; - pcs_redox=pcs_mass_idx[ii]; + pcs_redox = pcs_mass_idx[ii]; } } species_redox_idx.push_back(0); } - else if(i==1) // electron element + else if (i == 1) // electron element species_redox_idx.push_back(0); - else{ - if(species_redox_phase[i]==0) CAP_tqinp(species_redox_name[i], &ipc, &noerr); - else CAP_tqinpc(species_redox_name[i], species_redox_phase[i], &ipc, &noerr); - if(noerr) { cout << " ERROR !!! SPECIES REDOX INPUT out of DATAFILE. STOP." << "\n"; - exit (1); }//STOP and EXIT + else + { + if (species_redox_phase[i] == 0) + CAP_tqinp(species_redox_name[i], &ipc, &noerr); + else + CAP_tqinpc(species_redox_name[i], species_redox_phase[i], &ipc, &noerr); + if (noerr) + { + cout << " ERROR !!! SPECIES REDOX INPUT out of DATAFILE. STOP." + << "\n"; + exit(1); + } // STOP and EXIT species_redox_idx.push_back(ipc); - cout << " " << setw(4) << redox_stoi[i] << setw(4) << species_redox_phase[i] << setw(4) << species_redox_idx[i] << species_redox_name[i] << "\n"; + cout << " " << setw(4) << redox_stoi[i] << setw(4) << species_redox_phase[i] << setw(4) + << species_redox_idx[i] << species_redox_name[i] << "\n"; } } - cout << " REDOX_Eh OF SPECIES DEFINE OK ..." << "\n"; + cout << " REDOX_Eh OF SPECIES DEFINE OK ..." + << "\n"; return sr; } - /************************************************************** Function: REACT_CAP::CmpSpeciesListNLOG - Task: + Task: Compare the species NLOG_AC list with DATAFILE. - Get index of phases and species. - Get pcs_No. for nlog output species. - DL 01.2009 + Get index of phases and species. + Get pcs_No. for nlog output species. + DL 01.2009 **************************************************************/ -bool REACT_CAP::CmpSpeciesListNLOG(void){ - bool sr=true; - LI ipc, noerr = 0; - int i, ii, ns;//number of process and transport species +bool REACT_CAP::CmpSpeciesListNLOG(void) +{ + bool sr = true; + LI ipc, noerr = 0; + int i, ii, ns; // number of process and transport species CRFProcess* m_pcs = NULL; std::string ncomp_x; - cout << "\n" << " => CmpSpeciesListNLOG() " << "\n"; - //compare NLOG_AC LIST with DATAFILE and get list_idx - pcs_nspecies_idx.clear(); //clear up nlog-pcs-idx vector - nspecies_idx.clear(); //clear up nlog-idx vector + cout << "\n" + << " => CmpSpeciesListNLOG() " + << "\n"; + // compare NLOG_AC LIST with DATAFILE and get list_idx + pcs_nspecies_idx.clear(); // clear up nlog-pcs-idx vector + nspecies_idx.clear(); // clear up nlog-idx vector ns = (int)species_nlog_name.size(); - for(i=0;imass_num; ii<(int)pcs_mass_idx.size(); ii++){ + // DL 02.02.2009 nlog value output + for (ii = this->mass_num; ii < (int)pcs_mass_idx.size(); ii++) + { m_pcs = pcs_vector[pcs_mass_idx[ii]]; - if(this->species_mobil[ii]==0 && strcmp(m_pcs->pcs_primary_function_name[0], nlog_name[i])==0){ + if (this->species_mobil[ii] == 0 && strcmp(m_pcs->pcs_primary_function_name[0], nlog_name[i]) == 0) + { cout << " --> " << species_nlog_name[i] << "\n"; pcs_nspecies_idx.push_back(pcs_mass_idx[ii]); - nspecies_idx.push_back(i); + nspecies_idx.push_back(i); } } } - cout << " NLOG(ACTIVITY) OF SPECIES DEFINE OK ..." << "\n"; + cout << " NLOG(ACTIVITY) OF SPECIES DEFINE OK ..." + << "\n"; return sr; } /************************************************************** Function: REACT_CAP::CmpSpeciesListPCS - Task: + Task: Compare the species MASS_TRANSPORT list with DATAFILE. - Get index of phases and species. + Get index of phases and species. DL 01.2009 **************************************************************/ -bool REACT_CAP::CmpSpeciesListPCS(void){ - bool sr=true; - LI ipc, noerr = 0; - int i, ns;//number of process and transport species - //CRFProcess* m_pcs = NULL; +bool REACT_CAP::CmpSpeciesListPCS(void) +{ + bool sr = true; + LI ipc, noerr = 0; + int i, ns; // number of process and transport species + // CRFProcess* m_pcs = NULL; std::string ncomp_x; - cout << "\n" << "\n" << " => CmpSpeciesListPCS() " << "\n"; - //check up consistency between pcs_mass_transport and DATAFILE - cout << " Pcs Phase Index Species List for Chemical Reactive Mass" << "\n"; + cout << "\n" + << "\n" + << " => CmpSpeciesListPCS() " + << "\n"; + // check up consistency between pcs_mass_transport and DATAFILE + cout << " Pcs Phase Index Species List for Chemical Reactive Mass" + << "\n"; ns = (int)species_name.size(); - for(i=0;i24){ + for (i = 0; i < ns; i++) + { + if (strcmp(species_name[i], "EA") == 0) + ipc = 0; + else + { + noerr = 0; + // std::string name_st(species_name[i]); + // if(name_st.size()>24){ // species_name[i] = new char [24]; // strcpy(species_name[i], name_st.substr(0,24).c_str()); //} - //cout << species_name[i] << " " << name_st << " " << name_st.size() << "\n"; - if(species_phase[i]==0) CAP_tqinp(species_name[i], &ipc, &noerr); - else CAP_tqinpc(species_name[i], species_phase[i], &ipc, &noerr); - if(noerr) { cout << " SPECIES INPUT ERROR !!! STOP." << "\n"; - exit (1); }//STOP and EXIT + // cout << species_name[i] << " " << name_st << " " << name_st.size() << "\n"; + if (species_phase[i] == 0) + CAP_tqinp(species_name[i], &ipc, &noerr); + else + CAP_tqinpc(species_name[i], species_phase[i], &ipc, &noerr); + if (noerr) + { + cout << " SPECIES INPUT ERROR !!! STOP." + << "\n"; + exit(1); + } // STOP and EXIT } species_idx.push_back(ipc); species_dormant.push_back(0); - cout << " " << setw(4) << pcs_mass_idx[i] << setw(6) << species_phase[i] << setw(6) << species_idx[i] << species_name[i] << "\n"; + cout << " " << setw(4) << pcs_mass_idx[i] << setw(6) << species_phase[i] << setw(6) << species_idx[i] + << species_name[i] << "\n"; } - cout << " TRANSPORT SPECIES INPUT OK ..." << "\n"; + cout << " TRANSPORT SPECIES INPUT OK ..." + << "\n"; return sr; } - /************************************************************** Function: REACT_CAP::CmpSpeciesListDAT - Task: + Task: Compare the two species .cap list with DATAFILE. - Get index of phases and species. - Get pcs_No. for output species. - respectively, find out incompatible species. + Get index of phases and species. + Get pcs_No. for output species. + respectively, find out incompatible species. DL 01.2009 **************************************************************/ -bool REACT_CAP::CmpSpeciesListDAT(void){ - bool sr=true; - LI ipc, noerr = 0; - int i, ii, ns;//number of process and transport species +bool REACT_CAP::CmpSpeciesListDAT(void) +{ + bool sr = true; + LI ipc, noerr = 0; + int i, ii, ns; // number of process and transport species CRFProcess* m_pcs = NULL; std::string ncomp_x; - cout << "\n" << "\n" << " => CmpSpeciesListDAT() " << "\n"; - //compare LIST with DATAFILE and get list_idx - pcs_ospecies_idx.clear(); //clear up species output vector - cout << " SPECIES LIST FOR CHEMICAL REACTION CALCULATION " << "\n"; - cout << " Phase Index Species List for Chemical Reaction" << "\n"; + cout << "\n" + << "\n" + << " => CmpSpeciesListDAT() " + << "\n"; + // compare LIST with DATAFILE and get list_idx + pcs_ospecies_idx.clear(); // clear up species output vector + cout << " SPECIES LIST FOR CHEMICAL REACTION CALCULATION " + << "\n"; + cout << " Phase Index Species List for Chemical Reaction" + << "\n"; ns = (int)species_list_name.size(); - for(i=0;imass_num; ii<(int)pcs_mass_idx.size(); ii++){ + // DL 21.01.2009 species value output + if (species_list_phase[i] == 2) + for (ii = this->mass_num; ii < (int)pcs_mass_idx.size(); ii++) + { m_pcs = pcs_vector[pcs_mass_idx[ii]]; - if(/*this->species_mobil[ii]==0 &&*/ strcmp(m_pcs->pcs_primary_function_name[0], species_list_name[i])==0){ + if (/*this->species_mobil[ii]==0 &&*/ strcmp(m_pcs->pcs_primary_function_name[0], species_list_name[i]) + == 0) + { cout << " --> " << species_list_name[i] << "\n"; pcs_ospecies_idx.push_back(pcs_mass_idx[ii]); } } } - cout << " REACTION SPECIES LIST INPUT OK ..." << "\n"; + cout << " REACTION SPECIES LIST INPUT OK ..." + << "\n"; return sr; } /************************************************************** Function: REACT_CAP::CmpSpeciesListKIN - Task: + Task: Compare the species KINETIC list with DATAFILE. - Get index of phases and species. - DL 03.2010 + Get index of phases and species. + DL 03.2010 **************************************************************/ -bool REACT_CAP::CmpSpeciesListKIN(void){ - bool sr=true; - LI ipc, noerr = 0; +bool REACT_CAP::CmpSpeciesListKIN(void) +{ + bool sr = true; + LI ipc, noerr = 0; int i, j; - //CRFProcess* m_pcs = NULL; - - cout << "\n" << " => CmpSpeciesListKIN() " << "\n"; //compare KIN LIST with DATAFILE and get list_idx - for(i=0;i<(int)this->species_kin_name.size();i++){ - if(this->species_kin_phase[i]==0) - CAP_tqinp(this->species_kin_name[i], &ipc, &noerr); - else CAP_tqinpc(this->species_kin_name[i], this->species_kin_phase[i], &ipc, &noerr); - if(noerr) { cout << " ERROR !!! SPECIES KIN INPUT out of DATAFILE. STOP." << "\n"; - exit (1); }//STOP and EXIT + // CRFProcess* m_pcs = NULL; + + cout << "\n" + << " => CmpSpeciesListKIN() " + << "\n"; // compare KIN LIST with DATAFILE and get list_idx + for (i = 0; i < (int)this->species_kin_name.size(); i++) + { + if (this->species_kin_phase[i] == 0) + CAP_tqinp(this->species_kin_name[i], &ipc, &noerr); + else + CAP_tqinpc(this->species_kin_name[i], this->species_kin_phase[i], &ipc, &noerr); + if (noerr) + { + cout << " ERROR !!! SPECIES KIN INPUT out of DATAFILE. STOP." + << "\n"; + exit(1); + } // STOP and EXIT this->species_kin_idx.push_back(ipc); cout << " " << setw(4) << right << this->species_kin_phase[i]; cout << setw(4) << this->species_kin_idx[i] << " "; cout << setw(10) << left << this->species_kin_name[i] << "\n"; } - for(i=0;i<(int)this->species_name.size();i++) - for(j=0;j<(int)this->species_kin_name.size();j++) - if(strcmp(species_name[i], species_kin_name[j])==0 && species_phase[i]==species_kin_phase[j]) - species_dormant[i]=1; + for (i = 0; i < (int)this->species_name.size(); i++) + for (j = 0; j < (int)this->species_kin_name.size(); j++) + if (strcmp(species_name[i], species_kin_name[j]) == 0 && species_phase[i] == species_kin_phase[j]) + species_dormant[i] = 1; - cout << " KINETIC SPECIES DEFINITION OK ..." << "\n"; + cout << " KINETIC SPECIES DEFINITION OK ..." + << "\n"; return sr; } +// DL 04.2013 -//DL 04.2013 - -bool REACT_CAP::CmpSpeciesListRelativeActivity(void){ - bool sr=true,is_pcs; - LI ipc, noerr = 0; +bool REACT_CAP::CmpSpeciesListRelativeActivity(void) +{ + bool sr = true, is_pcs; + LI ipc, noerr = 0; int i, j; - //CRFProcess* m_pcs = NULL; - cout << "\n" << " => CmpSpeciesListRelativeActivity() " << "\n"; + // CRFProcess* m_pcs = NULL; + cout << "\n" + << " => CmpSpeciesListRelativeActivity() " + << "\n"; - for(i=0;i<(int)this->species_relative_activity_name.size();i++){ + for (i = 0; i < (int)this->species_relative_activity_name.size(); i++) + { CAP_tqinp(this->species_relative_activity_name[i], &ipc, &noerr); - if(noerr) { cout << " ERROR !!! SPECIES RELATIVE ACTIVITY INPUT out of DATAFILE. STOP." << "\n"; - exit (1); }//STOP and EXIT + if (noerr) + { + cout << " ERROR !!! SPECIES RELATIVE ACTIVITY INPUT out of DATAFILE. STOP." + << "\n"; + exit(1); + } // STOP and EXIT this->species_relative_activity_idx.push_back(ipc); cout << " " << setw(8) << left << this->species_relative_activity_idx[i]; cout << setw(10) << left << this->species_relative_activity_name[i]; cout << " " << right << this->species_relative_activity[i] << "\n"; - is_pcs=false; - for(j=0;j<(int)species_name.size();j++){ - if(strcmp(species_name[j], species_relative_activity_name[i])==0){ + is_pcs = false; + for (j = 0; j < (int)species_name.size(); j++) + { + if (strcmp(species_name[j], species_relative_activity_name[i]) == 0) + { this->species_relative_activity_idx_pcs.push_back(j); - is_pcs=true; + is_pcs = true; } } - if(!is_pcs) { cout << " ERROR !!! SPECIES RELATIVE ACTIVITY INPUT out of PCS-MT list. STOP." << "\n"; - exit (1); }//STOP and EXIT - - - + if (!is_pcs) + { + cout << " ERROR !!! SPECIES RELATIVE ACTIVITY INPUT out of PCS-MT list. STOP." + << "\n"; + exit(1); + } // STOP and EXIT } return sr; } - /************************************************************** Function: REACT_CAP::CmpSpeciesListKinReact - Task: + Task: Compare the species Kin React list with DATAFILE. - Get index of phases and species. - DL 03.2010 + Get index of phases and species. + DL 03.2010 **************************************************************/ -bool REACT_CAP::CmpSpeciesListKinReact(void){ - bool sr=true; - LI ipc=0, noerr=0; +bool REACT_CAP::CmpSpeciesListKinReact(void) +{ + bool sr = true; + LI ipc = 0, noerr = 0; int i, ii; - //CRFProcess* m_pcs = NULL; + // CRFProcess* m_pcs = NULL; - cout << "\n" << " => CmpSpeciesListKinReact() " << "\n"; //compare Kin React LIST with DATAFILE and get list_idx - for(ii=0;ii<(int)this->Kin_Reactions.size();ii++){ + cout << "\n" + << " => CmpSpeciesListKinReact() " + << "\n"; // compare Kin React LIST with DATAFILE and get list_idx + for (ii = 0; ii < (int)this->Kin_Reactions.size(); ii++) + { cout << " Reaction " << Kin_Reactions[ii].type << "\n"; - for(i=0;i<(int)this->Kin_Reactions[ii].species_name.size();i++){ - if(this->Kin_Reactions[ii].species_phase[i]==0) - CAP_tqinp(this->Kin_Reactions[ii].species_name[i], &ipc, &noerr); - else CAP_tqinpc(this->Kin_Reactions[ii].species_name[i], this->Kin_Reactions[ii].species_phase[i], &ipc, &noerr); - if(noerr) { cout << " ERROR !!! SPECIES LOGK INPUT out of DATAFILE. STOP." << "\n"; - exit (1); }//STOP and EXIT - this->Kin_Reactions[ii].species_idx[i]=ipc; + for (i = 0; i < (int)this->Kin_Reactions[ii].species_name.size(); i++) + { + if (this->Kin_Reactions[ii].species_phase[i] == 0) + CAP_tqinp(this->Kin_Reactions[ii].species_name[i], &ipc, &noerr); + else + CAP_tqinpc( + this->Kin_Reactions[ii].species_name[i], this->Kin_Reactions[ii].species_phase[i], &ipc, &noerr); + if (noerr) + { + cout << " ERROR !!! SPECIES LOGK INPUT out of DATAFILE. STOP." + << "\n"; + exit(1); + } // STOP and EXIT + this->Kin_Reactions[ii].species_idx[i] = ipc; cout << " " << setw(4) << right << this->Kin_Reactions[ii].species_phase[i]; cout << setw(4) << this->Kin_Reactions[ii].species_idx[i]; cout << setw(4) << this->Kin_Reactions[ii].species_stoi[i] << " "; cout << setw(10) << left << this->Kin_Reactions[ii].species_name[i] << "\n"; } } - cout << " KINETIC REACTIONS DEFINITION OK ..." << "\n"; + cout << " KINETIC REACTIONS DEFINITION OK ..." + << "\n"; return sr; } - /************************************************************** Function: REACT_CAP::UndefOutSpecies - Task: + Task: Search and find the species in PCS list for output of value. DL 10.09.2009 **************************************************************/ -void REACT_CAP::UndefOutSpecies(void){ - LI ipc=0, noerr = 0; - int ii;//number of process and transport species +void REACT_CAP::UndefOutSpecies(void) +{ + LI ipc = 0, noerr = 0; + int ii; // number of process and transport species CRFProcess* m_pcs = NULL; - for(ii=this->mass_num; ii<(int)pcs_mass_idx.size(); ii++){ + for (ii = this->mass_num; ii < (int)pcs_mass_idx.size(); ii++) + { m_pcs = pcs_vector[pcs_mass_idx[ii]]; - CAP_tqinpc((char *)m_pcs->pcs_primary_function_name[0], 2, &ipc, &noerr); - if(this->species_mobil[ii]==0 && (!noerr)){ + CAP_tqinpc((char*)m_pcs->pcs_primary_function_name[0], 2, &ipc, &noerr); + if (this->species_mobil[ii] == 0 && (!noerr)) + { cout << " --> " << m_pcs->pcs_primary_function_name[0] << "\n"; pcs_ospecies_idx.push_back(pcs_mass_idx[ii]); } } } - /************************************************************** Function: REACT_CAP::CmpSpeciesList - Task: + Task: Compare the two species lists from MASS_TRANSPORT and .cap - respectively, find out incompatible species. + respectively, find out incompatible species. DL 12.2008 **************************************************************/ -bool REACT_CAP::CmpSpeciesList(void){ - +bool REACT_CAP::CmpSpeciesList(void) +{ int i, j, ns, nls, sf; - bool sr=true; + bool sr = true; ns = (int)this->species_name.size(); - nls= (int)this->species_list_name.size(); - - cout << "\n" << "\n" << " => CmpSpeciesList() " << "\n"; - for(i=0;i0 can not find - for(j=0;jspecies_list_name.size(); + + cout << "\n" + << "\n" + << " => CmpSpeciesList() " + << "\n"; + for (i = 0; i < ns; i++) + { + sf = 0; // flag sf->0 can not find + for (j = 0; j < nls; j++) + if (strcmp(species_name[i], species_list_name[j]) == 0) + sf = 1; + if (sf != 1) + { + cout << " WARNING... " << species_name[i] << " is incompatible with SPECIES LIST in .cap" + << "\n"; + sr = false; } } return sr; } - /************************************************************** Function: REACT_CAP::DefSpeciesInChemApp - Task: + Task: Eliminate redundant species from DataBase for reaction DL 12.2008 **************************************************************/ -void REACT_CAP::DefSpeciesInChemApp(void){ - - LI i, ii, ns, nphase=0, npcon=0, noerr = 0; //, numcon=0; - //cout << "\n" << "\n" << "\n" << " => DefSpeciesInChemApp() " << "\n"; - ns = (LI) species_name.size(); - CAP_tqnop(&nphase, &noerr); //get the number of phase --> nphase - if(!noerr){ - for(i=1;i<=nphase;i++) { - CAP_tqnopc(i, &npcon, &noerr); - if(npcon==1) CAP_tqcsp(i, (char *)"eliminated", &noerr); - else for(ii=1;ii<=npcon;ii++) CAP_tqcspc(i, ii, (char *)"eliminated", &noerr); - } - for(i=0;i0) CAP_tqcspc(species_phase[i], species_idx[i], (char *)"entered", &noerr); - } - for(i=0;i<(int)species_kin_name.size();i++) { - if(species_kin_phase[i]==0) CAP_tqcsp(species_kin_idx[i], (char *)"dormant", &noerr); - if(species_kin_phase[i] >0) CAP_tqcspc(species_kin_phase[i], species_kin_idx[i], (char *)"dormant", &noerr); - } +void REACT_CAP::DefSpeciesInChemApp(void) +{ + LI i, ii, ns, nphase = 0, npcon = 0, noerr = 0; //, numcon=0; + // cout << "\n" << "\n" << "\n" << " => DefSpeciesInChemApp() " << "\n"; + ns = (LI)species_name.size(); + CAP_tqnop(&nphase, &noerr); // get the number of phase --> nphase + if (!noerr) + { + for (i = 1; i <= nphase; i++) + { + CAP_tqnopc(i, &npcon, &noerr); + if (npcon == 1) + CAP_tqcsp(i, (char*)"eliminated", &noerr); + else + for (ii = 1; ii <= npcon; ii++) + CAP_tqcspc(i, ii, (char*)"eliminated", &noerr); + } + for (i = 0; i < ns; i++) + { + if (species_phase[i] == 0) + CAP_tqcsp(species_idx[i], (char*)"entered", &noerr); + if (species_phase[i] > 0) + CAP_tqcspc(species_phase[i], species_idx[i], (char*)"entered", &noerr); + } + for (i = 0; i < (int)species_kin_name.size(); i++) + { + if (species_kin_phase[i] == 0) + CAP_tqcsp(species_kin_idx[i], (char*)"dormant", &noerr); + if (species_kin_phase[i] > 0) + CAP_tqcspc(species_kin_phase[i], species_kin_idx[i], (char*)"dormant", &noerr); + } } } -void REACT_CAP::DefSpeciesInChemAppList(void){ - - LI i, ii, ns, nphase=0, npcon=0, noerr = 0; - //cout << "\n" << "\n" << " => DefSpeciesInChemAppList() " << "\n"; - ns = (LI) species_list_name.size(); - CAP_tqnop(&nphase, &noerr); //get the number of phase --> nphase - for(i=1;i<=nphase;i++) { +void REACT_CAP::DefSpeciesInChemAppList(void) +{ + LI i, ii, ns, nphase = 0, npcon = 0, noerr = 0; + // cout << "\n" << "\n" << " => DefSpeciesInChemAppList() " << "\n"; + ns = (LI)species_list_name.size(); + CAP_tqnop(&nphase, &noerr); // get the number of phase --> nphase + for (i = 1; i <= nphase; i++) + { CAP_tqnopc(i, &npcon, &noerr); - if(npcon==1) CAP_tqcsp(i, (char *)"eliminated", &noerr); - else for(ii=1;ii<=npcon;ii++) CAP_tqcspc(i, ii, (char *)"eliminated", &noerr); - } - for(i=0;i0) CAP_tqcspc(species_list_phase[i], species_list_idx[i], (char *)"entered", &noerr); - } - for(i=0;i<(int)species_kin_name.size();i++) { - if(species_kin_phase[i]==0) CAP_tqcsp(species_kin_idx[i], (char *)"dormant", &noerr); - if(species_kin_phase[i] >0) CAP_tqcspc(species_kin_phase[i], species_kin_idx[i], (char *)"dormant", &noerr); + if (npcon == 1) + CAP_tqcsp(i, (char*)"eliminated", &noerr); + else + for (ii = 1; ii <= npcon; ii++) + CAP_tqcspc(i, ii, (char*)"eliminated", &noerr); + } + for (i = 0; i < ns; i++) + { + if (species_list_phase[i] == 0) + CAP_tqcsp(species_list_idx[i], (char*)"entered", &noerr); + if (species_list_phase[i] > 0) + CAP_tqcspc(species_list_phase[i], species_list_idx[i], (char*)"entered", &noerr); + } + for (i = 0; i < (int)species_kin_name.size(); i++) + { + if (species_kin_phase[i] == 0) + CAP_tqcsp(species_kin_idx[i], (char*)"dormant", &noerr); + if (species_kin_phase[i] > 0) + CAP_tqcspc(species_kin_phase[i], species_kin_idx[i], (char*)"dormant", &noerr); } } -void REACT_CAP::DefSpeciesInChemAppAll(void){ - int i,ii; +void REACT_CAP::DefSpeciesInChemAppAll(void) +{ + int i, ii; LI nphase, npcon, noerr; CAP_tqnop(&nphase, &noerr); - for(i=1;i<=nphase;i++) { + for (i = 1; i <= nphase; i++) + { CAP_tqnopc(i, &npcon, &noerr); - if(npcon==1) - CAP_tqcsp(i, (char *)"entered", &noerr); + if (npcon == 1) + CAP_tqcsp(i, (char*)"entered", &noerr); else - for(ii=1;ii<=npcon;ii++) - CAP_tqcspc(i, ii, (char *)"entered", &noerr); + for (ii = 1; ii <= npcon; ii++) + CAP_tqcspc(i, ii, (char*)"entered", &noerr); } } -void REACT_CAP::SetAllSolidAsDormant(void){ - LI i, nphase=0, npcon=0, noerr = 0; +void REACT_CAP::SetAllSolidAsDormant(void) +{ + LI i, nphase = 0, npcon = 0, noerr = 0; // LI ii, ns ; - //cout << "\n" << "\n" << " => SetAllSolidAsDormant() " << "\n"; - CAP_tqnop(&nphase, &noerr); //get the number of phase --> nphase - for(i=1;i<=nphase;i++) { + // cout << "\n" << "\n" << " => SetAllSolidAsDormant() " << "\n"; + CAP_tqnop(&nphase, &noerr); // get the number of phase --> nphase + for (i = 1; i <= nphase; i++) + { CAP_tqnopc(i, &npcon, &noerr); - if(npcon==1) CAP_tqcsp(i, (char *)"dormant", &noerr); + if (npcon == 1) + CAP_tqcsp(i, (char*)"dormant", &noerr); } } /*********************************************************** Function: REACT_CAP::ResetElement - Task: - Change Elements as Component for ChemApp - DL 12/08 + Task: + Change Elements as Component for ChemApp + DL 12/08 ***********************************************************/ -void REACT_CAP::ResetElement(void){ - - int i, j, ipw, ns, nm=0; +void REACT_CAP::ResetElement(void) +{ + int i, j, ipw, ns, nm = 0; LI noerr, nscom; DB *stoi, *zstoi, wmass; typedef char charsc[TQSTRLEN]; charsc *newsc, scname; vector newscv; - cout << "\n" << "\n" << " => ResetElement() " << "\n"; - cout << " RESET ELEMENT..." << "\n"; - ipw=0; + cout << "\n" + << "\n" + << " => ResetElement() " + << "\n"; + cout << " RESET ELEMENT..." + << "\n"; + ipw = 0; newscv.clear(); - ns=(int)species_name.size(); - for(i=0;i=ipw){ - stoi =new DB[nscom]; - zstoi=new DB[nscom]; - for(i=0;i= ipw) + { + stoi = new DB[nscom]; + zstoi = new DB[nscom]; + for (i = 0; i < nscom; i++) + zstoi[i] = 0; + for (i = 0; i < ns; i++) + if (strcmp(species_name[i], "EA") != 0 && species_phase[i] == 2 && species_mobil[i] == 1) + { newscv.push_back(species_name[i]); CAP_tqstpc(species_phase[i], species_idx[i], stoi, &wmass, &noerr); - for(j=0;j sum of electronic charge in solution -CRFProcess* m_pcs = NULL; - -vector species_value_d, kin_value, residual_value; -vector species_value, species_value_b; //back up the value DL 2012.2.12 - -vector residual_idx; -bool first_time = true; -//bool is_2nd_try; -int number_UnderSat; - -bool MinKinReact = KMinKinCheck(); // CB 3-12-2010 Check, if KinReact module is used -//double mv[8], cv_CO2, cv[8], mCO2, dens ; -double unitfactor_l = 1, unitfactor_s = 1; -// CB / DL 21.1.2011: Attention: Gas phase volume fraction : (1-S)*n - - -stringstream ss; -// int i_r, i_s; -int i_np; //for residual value return back pcs -int np, precision_type; -double sp_value; - -double delta, err_vle=1.0e-12; //VLE -bool is_equilibrium; -bool is_VLE; -int iter_eq; -vector iv_eq; -vector a,b,x; -vector species_value_s; - - -ff=f; // if ff=0-->initial calculation, ff=1->full geochemical system, ff=-1->for liquid system -fg=f; -f=1; //old time level or new time level - -cout << " ChemApp Reaction node loop." << "\n"; -cout.flush(); - -//CB 19.1.2011 -// Get the reaction interface data -REACTINT *m_rei = NULL; -if(REACTINT_vec.size()>0){ - m_rei = REACTINT_vec[0]; - if(ff==0 && m_rei->icSolidUpdate) - ff=1; // allow update of solid matrix concentrations -} +void REACT_CAP::LoopNodeReact(int f, int nodeflag) +{ + int ff; + int ii, ns, isc, ix, widx = 0, fg; // idx, + size_t i, iv; + + LI ipc, iEA, noerr, numcon = 0, nscom = 0; + DB TT = 298.15, PP = 1.0, vals[2], value = 0.0, value1 = 0.0, *stoi, + wmass; //, zEA; // zEA -> sum of electronic charge in solution + CRFProcess* m_pcs = NULL; -ns = (int)species_name.size(); + vector species_value_d, kin_value, residual_value; + vector species_value, species_value_b; // back up the value DL 2012.2.12 + + vector residual_idx; + bool first_time = true; + // bool is_2nd_try; + int number_UnderSat; + + bool MinKinReact = KMinKinCheck(); // CB 3-12-2010 Check, if KinReact module is used + // double mv[8], cv_CO2, cv[8], mCO2, dens ; + double unitfactor_l = 1, unitfactor_s = 1; + // CB / DL 21.1.2011: Attention: Gas phase volume fraction : (1-S)*n + + stringstream ss; + // int i_r, i_s; + int i_np; // for residual value return back pcs + int np, precision_type; + double sp_value; + + double delta, err_vle = 1.0e-12; // VLE + bool is_equilibrium; + bool is_VLE; + int iter_eq; + vector iv_eq; + vector a, b, x; + vector species_value_s; + + ff = f; // if ff=0-->initial calculation, ff=1->full geochemical system, ff=-1->for liquid system + fg = f; + f = 1; // old time level or new time level + + cout << " ChemApp Reaction node loop." + << "\n"; + cout.flush(); + + // CB 19.1.2011 + // Get the reaction interface data + REACTINT* m_rei = NULL; + if (REACTINT_vec.size() > 0) + { + m_rei = REACTINT_vec[0]; + if (ff == 0 && m_rei->icSolidUpdate) + ff = 1; // allow update of solid matrix concentrations + } -CAP_tqinsc((char *)"EA", &iEA, &noerr); -CAP_tqnosc(&nscom, &noerr); -stoi=new DB[nscom]; -//cout << " iEA= " << iEA << " " << nscom << "\n"; + ns = (int)species_name.size(); + CAP_tqinsc((char*)"EA", &iEA, &noerr); + CAP_tqnosc(&nscom, &noerr); + stoi = new DB[nscom]; + // cout << " iEA= " << iEA << " " << nscom << "\n"; -//if(ff != -1){ -if(nodeflag<0){ - node_logK.clear(); - node_ac.clear(); - node_HKF_logK.clear(); -} -//} -CAP_tqcio((char *)"ERROR", 0, &noerr); - -// node loop -for(ii=0;iinodenumber;ii++){ //ii==0 as boundary point without reaction calc - - CAP_icount=0; - CAP_Time=aktueller_zeitschritt; - CAP_Node=ii; - - this->RecoverChemSystem(); - - if(nodeflag>=0) - if(nodeflag!=ii) - continue; - - CAP_tqremc(0,&noerr); //removes all input conditions relating to incoming amounts - - //return pcs rename pre - // in new version, set in problem.cpp ? - for(i=0;iGetNodeValue(ii,f); - else if(pcs_rename_stoi_pre[i][ix]==-999999) - value /= m_pcs->GetNodeValue(ii,f); - else - value += m_pcs->GetNodeValue(ii,f) *pcs_rename_stoi_pre[i][ix]; - } - m_pcs= pcs_vector[pcs_rename_idx0_pre[i]]; - m_pcs->SetNodeValue(ii,f,value); - } - - // only for nodes, where Cnew != Cold - if(rateflag[ii]!=0) - { - //CAP_tqremc(-2, &noerr); // remove all condition and targets set previously - //CAP_tqstrm("inputs", &noerr); // remove stream input - - // get species conc. after transport mol/m2 Liquid - species_value.clear(); - for(i=0;i<(size_t)ns;i++){ - m_pcs = pcs_vector[this->pcs_mass_idx[i]]; - species_value.push_back(m_pcs->GetNodeValue(ii,f)); - //if(ii==1) cout << i << " " << species_name[i] << " " << species_value[i] << "\n"; + // if(ff != -1){ + if (nodeflag < 0) + { + node_logK.clear(); + node_ac.clear(); + node_HKF_logK.clear(); } + //} + CAP_tqcio((char*)"ERROR", 0, &noerr); + + // node loop + for (ii = 0; ii < this->nodenumber; ii++) + { // ii==0 as boundary point without reaction calc + + CAP_icount = 0; + CAP_Time = aktueller_zeitschritt; + CAP_Node = ii; - //CB 19.1.2011 - // based on porosity, calculate TOTALS Ti,w Tj,s before coputing equilirium chemistry - // mol (/m3aquifer) - if(m_rei) { - if(m_rei->unitconversion){ - m_rei->CalcUnitConversionFactors(ii, &unitfactor_l, &unitfactor_s, false); - //unitfactor_l = m_rei->node_porosity[ii] * m_rei->GetWaterSaturation(ii); - //if(unitfactor_l==0.0) unitfactor_l = m_rei->node_porosity[ii]* 1; - // unitfactor_s = 1 - m_rei->node_porosity[ii]; - for( i=0;i<(size_t)ns;i++){ - //idx = pcs_vector[pcs_mass_idx[i]]->GetProcessComponentNumber(); - if(species_phase[i]==2){ // liquid phase - if(strcmp(species_name[i],"H2O")==0 || strcmp(species_name[i],"H2O_liquid")==0 || strcmp(species_name[i],"water_liquid")==0) - { - // the water pcs node value is now updated after preprocessing, - // and after kinreact anyway, so use the node value - //species_value[i] = m_rei->water_conc[ii] * unitfactor_l ; // set the total amount of water - widx = i; // save the species index of watre species - } - //else - species_value[i] *= unitfactor_l ; //Ti,w = Ci,w * n * S - } - else if(species_phase[i]==0)// solid phase - species_value[i] *= unitfactor_s ; //Tj,s = Cj,s * (1-n) - // CB / DL 21.1.2011: Attention: Gas phase volume fraction : (1-S)*n - //else if (species_phase[i]==1)// gas phase - } - } - // set P, T input values - TT = m_rei->GetTemperature(ii); - PP = m_rei->GetPressure(ii); - } - - //for(i=0;iVLE_conditions.size();iv++){ - iv_eq.push_back(false); - a.push_back(0); - b.push_back(0); - x.push_back(0); - m_pcs = pcs_vector[m_rei->VLE_conditions[iv].vp_idx]; - m_rei->VLE_conditions[iv].vp_value = m_pcs->GetNodeValue(ii,f); - for( i=0;i<(size_t)ns;i++) - if(this->pcs_mass_idx[i]==m_rei->VLE_conditions[iv].aq_idx){ - m_rei->VLE_conditions[iv].idx_aq_species=i; - m_rei->VLE_conditions[iv].aq_value=species_value[i]; + this->RecoverChemSystem(); + + if (nodeflag >= 0) + if (nodeflag != ii) + continue; + + CAP_tqremc(0, &noerr); // removes all input conditions relating to incoming amounts + + // return pcs rename pre + // in new version, set in problem.cpp ? + for (i = 0; i < pcs_rename_idx0_pre.size(); i++) + { + value = 0.0; + for (ix = 0; ix < (int)pcs_rename_idx1_pre[i].size(); ix++) + { + m_pcs = pcs_vector[pcs_rename_idx1_pre[i][ix]]; + if (pcs_rename_stoi_pre[i][ix] == 999999) + value *= m_pcs->GetNodeValue(ii, f); + else if (pcs_rename_stoi_pre[i][ix] == -999999) + value /= m_pcs->GetNodeValue(ii, f); + else + value += m_pcs->GetNodeValue(ii, f) * pcs_rename_stoi_pre[i][ix]; } - } - - //----END--init-- - - //----VLE_P--init---- - if(m_rei) - for(iv=0;ivVLE_pressure.size();iv++){ - iv_eq.push_back(false); - a.push_back(0); - b.push_back(0); - x.push_back(0); - m_pcs = pcs_vector[m_rei->VLE_pressure[iv].vp_idx]; - m_rei->VLE_pressure[iv].vp_value = m_pcs->GetNodeValue(ii,f); //vp_value is the partial pressure of the gas, from current node value (IC or BC ??) - for( i=0;i<(size_t)ns;i++) - if(this->pcs_mass_idx[i]==m_rei->VLE_pressure[iv].aq_idx){ - m_rei->VLE_pressure[iv].idx_aq_species=i; - //m_rei->VLE_pressure[iv].aq_value=species_value[i]; - //m_rei->VLE_pressure[iv].aq_value= m_rei->VLE_pressure[iv].vp_value; // species_value[i]; //should get value from geochemcalc - } - } - - iter_eq=0; - is_equilibrium=false; - //record input species_values - - while(!is_equilibrium){ - - //====RECOVERING LOOP START==== - - for(i_np=-1;i_np<4;i_np++){ //ChemApp eq calc recovering - - //set P, T input values - //TT = 273.15; - //PP = 100.0; - //CALL ChemAppCalc(species_name, species_value, T, P) - CAP_tqsetc((char *)"T", 0, 0, TT, &numcon, &noerr); - CAP_tqsetc((char *)"P", 0, 0, PP, &numcon, &noerr); - //cout << ii << " T " << TT << " P " << PP << "\n"; - - //for(i=0;i kinetic species, does not take part in eq reactions - - if(strcmp(species_name[i],"EA")==0) { - CAP_tqinsc((char *)"EA", &iEA, &noerr); // for electrons, e- - CAP_tqsetc((char *)"ia", 0, iEA, species_value[i], &numcon, &noerr); - } - else - { - if(species_phase[i]==0 && species_value[i] < 0.0e0 && species_value[i]> -50 ) { //DL to set different solid composition using IC flag "-100" - residual_value.push_back(species_value[i]); - residual_idx.push_back(i); - species_value[i]=0; // solid, negative c - } - - if(m_rei){ // set precision type for old version, in new version it is no used - if(m_rei->unitconversion){ - if(species_phase[i]!=0 && species_value[i] < 1.0e-7 && species_value[i]!=0) - precision_type=1; - //H and O element - if(species_value[i] < 1.0e-5 && species_value[i]!=0) - if(m_rei->formula2index(species_name[i])[8]!=0 || m_rei->formula2index(species_name[i])[9]!=0) - precision_type=1; - } - else{ - if(species_phase[i]!=0 && species_value[i] < 1.0e-10 && species_value[i]!=0) - precision_type=1; - //H and O element - if(species_value[i] < 1.0e-8 && species_value[i]!=0) - if(m_rei->formula2index(species_name[i])[8]!=0 || m_rei->formula2index(species_name[i])[9]!=0) - precision_type=1; - } - } - else{ - if(species_phase[i]!=0 && species_value[i] < 1.0e-10 && species_value[i]!=0) - precision_type=1; - //H and O element - if(species_value[i] < 1.0e-8 && species_value[i]!=0) - if(m_rei->formula2index(species_name[i])[8]!=0 || m_rei->formula2index(species_name[i])[9]!=0) - precision_type=1; - } - - //new version for precision setting - if(species_phase[i]==0){ - if(ff != -1) // for full system, ff==-1 for the liquid system - if(species_value[i]>-50){ - CAP_tqsetc((char *)"ia", species_idx[i], 0, species_value[i], &numcon, &noerr); // single comp phase (solid) - } - } - else{ - if(i_np==-1) - sp_value=species_value[i]; - else if((precision_type==0 || precision_type==1) && i_np>=0 && i_np<3){ - if(species_value[i]>0){ - np=(int)log10(species_value[i]); - if(np> 0) np=7; - else if(np> -2) np=6; - else if(np> -4) np=5; - else if(np> -5) np=4; - else if(np<=-5 && np>=-7) np=3; - else if(np< -7 && np> -16) np=2; - else if(np<= -16) np=1; - - np -= i_np; - if(np < 0) np=0; - ss.clear(); - ss << setprecision(np) << species_value[i]; - ss >> sp_value; - } - else - sp_value =0; - } - else if(precision_type==1 && i_np==3) - sp_value =0; - else - sp_value=species_value[i]; - - residual_value.push_back(species_value[i]-sp_value); - residual_idx.push_back(i); - CAP_tqsetc((char *)"ia", species_phase[i], species_idx[i], sp_value, &numcon, &noerr); // any mixture phase - CAP_tqstpc(species_phase[i], species_idx[i], stoi, &wmass, &noerr); - //zEA=zEA+stoi[iEA-1]*species_value[i]; //set charge balance automatically - } - } // if strcmp - } // if dormant - } // for ns - - //cout << " zEA= " << zEA << "\n"; - //CAP_tqsetc("ia", 0, iEA, zEA, &numcon, &noerr); // set electronic charge balance - //if(zEA>0) CAP_tqsetc("ia", 2, 34, zEA, &numcon, &noerr); - //if(zEA<0) CAP_tqsetc("ia", 2, 71, -zEA, &numcon, &noerr); - //cout << "\n" << ii << "-----------------------------" << "\n" << "Input P Id Name" << "\n"; - //if(ii==2) - //for(i=0;ispecies_relative_activity_name.size()==0) - //if(!this->species_relative_activity_name.size()>0) - { //no relative activity - - for( i=0;i<(size_t)ns;i++){ //DL set the solid species as eliminated when the value is -100 - if(species_phase[i]==0 && species_value[i] < -50 && species_value[i]> -200) - CAP_tqcsp(this->species_idx[i], (char *)"eliminated", &noerr); - } - // here, calculate equilibrium geochemistry for a node - noerr=0; - if(first_time && fg==0){ // do when the first node is called - CAP_tqce(const_cast(" "), 0, 0, vals, &noerr); - first_time = false; - } - else { - if(ii==1 /*|| ii==1 || ii==8 || ii==12 || ii==16 || ii==20 */) - CAP_tqce(const_cast(" "), 0, 0, vals, &noerr); // this is faster, using previuos result as start for iteration - else - CAP_tqce(const_cast(" "), 0, 0, vals, &noerr); // this is faster, using previuos result as start for iteration - } - } - //DL ---------------relative activity---------------start - else if(this->species_relative_activity_name.size()>0) - { - this->species_relative_activity_state.clear(); - for(i=0;i-50){ - if(species_value[species_relative_activity_idx_pcs[i]] > 1.0e-16 ) {//precision - if(species_relative_activity_state[i]==1 || species_relative_activity_state[i]==0){ - CAP_tqcsp(species_relative_activity_idx[i], (char *)"entered", &noerr);//DL - CAP_tqsetc((char *)"ac",species_relative_activity_idx[i],0,species_relative_activity[i],&numcon,&noerr); //DL - species_relative_activity_state[i]=1; - } - if(species_relative_activity_state[i]==2){ - CAP_tqcsp(species_relative_activity_idx[i], (char *)"dormant", &noerr);//DL - CAP_tqsetc((char *)"ia",species_relative_activity_idx[i],0,species_value[this->species_relative_activity_idx_pcs[i]],&numcon,&noerr); - } - } - else if(species_value[this->species_relative_activity_idx_pcs[i]] <= 1.0e-16 ){ - if(this->species_relative_activity_state[i]==3 || this->species_relative_activity_state[i]==0){ - CAP_tqcsp(this->species_relative_activity_idx[i], (char *)"dormant", &noerr);//DL - CAP_tqsetc((char *)"ia",this->species_relative_activity_idx[i],0,0.0,&numcon,&noerr); - this->species_relative_activity_state[i]=3; - } - if(this->species_relative_activity_state[i]==4){ - CAP_tqcsp(this->species_relative_activity_idx[i], (char *)"entered", &noerr);//DL - CAP_tqsetc((char *)"ac",this->species_relative_activity_idx[i],0,this->species_relative_activity[i],&numcon,&noerr); //DL - } - } - } - } - - for( i=0;i<(size_t)ns;i++){ //DL set the solid species as eliminated when the value is -100 - if(species_phase[i]==0 && species_value[i] < -50 && species_value[i]> -200) - CAP_tqcsp(this->species_idx[i], (char *)"eliminated", &noerr); + m_pcs = pcs_vector[pcs_rename_idx0_pre[i]]; + m_pcs->SetNodeValue(ii, f, value); + } + + // only for nodes, where Cnew != Cold + if (rateflag[ii] != 0) + { + // CAP_tqremc(-2, &noerr); // remove all condition and targets set previously + // CAP_tqstrm("inputs", &noerr); // remove stream input + + // get species conc. after transport mol/m2 Liquid + species_value.clear(); + for (i = 0; i < (size_t)ns; i++) + { + m_pcs = pcs_vector[this->pcs_mass_idx[i]]; + species_value.push_back(m_pcs->GetNodeValue(ii, f)); + // if(ii==1) cout << i << " " << species_name[i] << " " << species_value[i] << "\n"; } - //CAP_tqshow(&noerr); - // calculate - noerr=0; - if(first_time && fg==0){ // do when the first node is called - CAP_tqce(const_cast(" "), 0, 0, vals, &noerr); - first_time = false; + // CB 19.1.2011 + // based on porosity, calculate TOTALS Ti,w Tj,s before coputing equilirium chemistry + // mol (/m3aquifer) + if (m_rei) + { + if (m_rei->unitconversion) + { + m_rei->CalcUnitConversionFactors(ii, &unitfactor_l, &unitfactor_s, false); + // unitfactor_l = m_rei->node_porosity[ii] * m_rei->GetWaterSaturation(ii); + // if(unitfactor_l==0.0) unitfactor_l = m_rei->node_porosity[ii]* 1; + // unitfactor_s = 1 - m_rei->node_porosity[ii]; + for (i = 0; i < (size_t)ns; i++) + { + // idx = pcs_vector[pcs_mass_idx[i]]->GetProcessComponentNumber(); + if (species_phase[i] == 2) + { // liquid phase + if (strcmp(species_name[i], "H2O") == 0 || strcmp(species_name[i], "H2O_liquid") == 0 + || strcmp(species_name[i], "water_liquid") == 0) + { + // the water pcs node value is now updated after preprocessing, + // and after kinreact anyway, so use the node value + // species_value[i] = m_rei->water_conc[ii] * unitfactor_l ; // set the total amount of + // water + widx = i; // save the species index of watre species + } + // else + species_value[i] *= unitfactor_l; // Ti,w = Ci,w * n * S + } + else if (species_phase[i] == 0) // solid phase + species_value[i] *= unitfactor_s; // Tj,s = Cj,s * (1-n) + // CB / DL 21.1.2011: Attention: Gas phase volume fraction : (1-S)*n + // else if (species_phase[i]==1)// gas phase + } + } + // set P, T input values + TT = m_rei->GetTemperature(ii); + PP = m_rei->GetPressure(ii); } - else { - if(ii==1 || ii==6 /*|| ii==8 || ii==12 || ii==16 || ii==20 */) - CAP_tqcen((char *)" ", 0, 0, vals, &noerr); // this is faster, using previuos result as start for iteration + + // for(i=0;iVLE_conditions.size(); iv++) + { + iv_eq.push_back(false); + a.push_back(0); + b.push_back(0); + x.push_back(0); + m_pcs = pcs_vector[m_rei->VLE_conditions[iv].vp_idx]; + m_rei->VLE_conditions[iv].vp_value = m_pcs->GetNodeValue(ii, f); + for (i = 0; i < (size_t)ns; i++) + if (this->pcs_mass_idx[i] == m_rei->VLE_conditions[iv].aq_idx) + { + m_rei->VLE_conditions[iv].idx_aq_species = i; + m_rei->VLE_conditions[iv].aq_value = species_value[i]; + } + } + + //----END--init-- + + //----VLE_P--init---- + if (m_rei) + for (iv = 0; iv < m_rei->VLE_pressure.size(); iv++) + { + iv_eq.push_back(false); + a.push_back(0); + b.push_back(0); + x.push_back(0); + m_pcs = pcs_vector[m_rei->VLE_pressure[iv].vp_idx]; + m_rei->VLE_pressure[iv].vp_value = m_pcs->GetNodeValue( + ii, f); // vp_value is the partial pressure of the gas, from current node value (IC or BC ??) + for (i = 0; i < (size_t)ns; i++) + if (this->pcs_mass_idx[i] == m_rei->VLE_pressure[iv].aq_idx) + { + m_rei->VLE_pressure[iv].idx_aq_species = i; + // m_rei->VLE_pressure[iv].aq_value=species_value[i]; + // m_rei->VLE_pressure[iv].aq_value= m_rei->VLE_pressure[iv].vp_value; // + // species_value[i]; //should get value from geochemcalc + } + } + + iter_eq = 0; + is_equilibrium = false; + // record input species_values + + while (!is_equilibrium) + { + //====RECOVERING LOOP START==== + + for (i_np = -1; i_np < 4; i_np++) + { // ChemApp eq calc recovering + + // set P, T input values + // TT = 273.15; + // PP = 100.0; + // CALL ChemAppCalc(species_name, species_value, T, P) + CAP_tqsetc((char*)"T", 0, 0, TT, &numcon, &noerr); + CAP_tqsetc((char*)"P", 0, 0, PP, &numcon, &noerr); + // cout << ii << " T " << TT << " P " << PP << "\n"; + + // for(i=0;i kinetic species, does not take part in eq reactions + + if (strcmp(species_name[i], "EA") == 0) + { + CAP_tqinsc((char*)"EA", &iEA, &noerr); // for electrons, e- + CAP_tqsetc((char*)"ia", 0, iEA, species_value[i], &numcon, &noerr); + } + else + { + if (species_phase[i] == 0 && species_value[i] < 0.0e0 && species_value[i] > -50) + { // DL to set different solid composition using IC flag "-100" + residual_value.push_back(species_value[i]); + residual_idx.push_back(i); + species_value[i] = 0; // solid, negative c + } + + if (m_rei) + { // set precision type for old version, in new version it is no used + if (m_rei->unitconversion) + { + if (species_phase[i] != 0 && species_value[i] < 1.0e-7 && species_value[i] != 0) + precision_type = 1; + // H and O element + if (species_value[i] < 1.0e-5 && species_value[i] != 0) + if (m_rei->formula2index(species_name[i])[8] != 0 + || m_rei->formula2index(species_name[i])[9] != 0) + precision_type = 1; + } + else + { + if (species_phase[i] != 0 && species_value[i] < 1.0e-10 + && species_value[i] != 0) + precision_type = 1; + // H and O element + if (species_value[i] < 1.0e-8 && species_value[i] != 0) + if (m_rei->formula2index(species_name[i])[8] != 0 + || m_rei->formula2index(species_name[i])[9] != 0) + precision_type = 1; + } + } + else + { + if (species_phase[i] != 0 && species_value[i] < 1.0e-10 && species_value[i] != 0) + precision_type = 1; + // H and O element + if (species_value[i] < 1.0e-8 && species_value[i] != 0) + if (m_rei->formula2index(species_name[i])[8] != 0 + || m_rei->formula2index(species_name[i])[9] != 0) + precision_type = 1; + } + + // new version for precision setting + if (species_phase[i] == 0) + { + if (ff != -1) // for full system, ff==-1 for the liquid system + if (species_value[i] > -50) + { + CAP_tqsetc((char*)"ia", + species_idx[i], + 0, + species_value[i], + &numcon, + &noerr); // single comp phase (solid) + } + } + else + { + if (i_np == -1) + sp_value = species_value[i]; + else if ((precision_type == 0 || precision_type == 1) && i_np >= 0 && i_np < 3) + { + if (species_value[i] > 0) + { + np = (int)log10(species_value[i]); + if (np > 0) + np = 7; + else if (np > -2) + np = 6; + else if (np > -4) + np = 5; + else if (np > -5) + np = 4; + else if (np <= -5 && np >= -7) + np = 3; + else if (np < -7 && np > -16) + np = 2; + else if (np <= -16) + np = 1; + + np -= i_np; + if (np < 0) + np = 0; + ss.clear(); + ss << setprecision(np) << species_value[i]; + ss >> sp_value; + } + else + sp_value = 0; + } + else if (precision_type == 1 && i_np == 3) + sp_value = 0; + else + sp_value = species_value[i]; + + residual_value.push_back(species_value[i] - sp_value); + residual_idx.push_back(i); + CAP_tqsetc((char*)"ia", + species_phase[i], + species_idx[i], + sp_value, + &numcon, + &noerr); // any mixture phase + CAP_tqstpc(species_phase[i], species_idx[i], stoi, &wmass, &noerr); + // zEA=zEA+stoi[iEA-1]*species_value[i]; //set charge balance automatically + } + } // if strcmp + } // if dormant + } // for ns + + // cout << " zEA= " << zEA << "\n"; + // CAP_tqsetc("ia", 0, iEA, zEA, &numcon, &noerr); // set electronic charge balance + // if(zEA>0) CAP_tqsetc("ia", 2, 34, zEA, &numcon, &noerr); + // if(zEA<0) CAP_tqsetc("ia", 2, 71, -zEA, &numcon, &noerr); + // cout << "\n" << ii << "-----------------------------" << "\n" << "Input P Id Name" << + // "\n"; + // if(ii==2) + // for(i=0;ispecies_relative_activity_name.size() == 0) + // if(!this->species_relative_activity_name.size()>0) + { // no relative activity + + for (i = 0; i < (size_t)ns; i++) + { // DL set the solid species as eliminated when the value is -100 + if (species_phase[i] == 0 && species_value[i] < -50 && species_value[i] > -200) + CAP_tqcsp(this->species_idx[i], (char*)"eliminated", &noerr); + } + // here, calculate equilibrium geochemistry for a node + noerr = 0; + if (first_time && fg == 0) + { // do when the first node is called + CAP_tqce(const_cast(" "), 0, 0, vals, &noerr); + first_time = false; + } + else + { + if (ii == 1 /*|| ii==1 || ii==8 || ii==12 || ii==16 || ii==20 */) + CAP_tqce(const_cast(" "), + 0, + 0, + vals, + &noerr); // this is faster, using previuos result as start for iteration + else + CAP_tqce(const_cast(" "), + 0, + 0, + vals, + &noerr); // this is faster, using previuos result as start for iteration + } + } + // DL ---------------relative activity---------------start + else if (this->species_relative_activity_name.size() > 0) + { + this->species_relative_activity_state.clear(); + for (i = 0; i < species_relative_activity_name.size(); i++) + species_relative_activity_state.push_back(0); + for (ix = 0; ix < 5; ix++) + { + // pre setting + for (i = 0; i < species_relative_activity_name.size(); i++) + { + if (species_value[species_relative_activity_idx_pcs[i]] > -50) + { + if (species_value[species_relative_activity_idx_pcs[i]] > 1.0e-16) + { // precision + if (species_relative_activity_state[i] == 1 + || species_relative_activity_state[i] == 0) + { + CAP_tqcsp(species_relative_activity_idx[i], (char*)"entered", &noerr); // DL + CAP_tqsetc((char*)"ac", + species_relative_activity_idx[i], + 0, + species_relative_activity[i], + &numcon, + &noerr); // DL + species_relative_activity_state[i] = 1; + } + if (species_relative_activity_state[i] == 2) + { + CAP_tqcsp(species_relative_activity_idx[i], (char*)"dormant", &noerr); // DL + CAP_tqsetc((char*)"ia", + species_relative_activity_idx[i], + 0, + species_value[this->species_relative_activity_idx_pcs[i]], + &numcon, + &noerr); + } + } + else if (species_value[this->species_relative_activity_idx_pcs[i]] <= 1.0e-16) + { + if (this->species_relative_activity_state[i] == 3 + || this->species_relative_activity_state[i] == 0) + { + CAP_tqcsp( + this->species_relative_activity_idx[i], (char*)"dormant", &noerr); // DL + CAP_tqsetc((char*)"ia", + this->species_relative_activity_idx[i], + 0, + 0.0, + &numcon, + &noerr); + this->species_relative_activity_state[i] = 3; + } + if (this->species_relative_activity_state[i] == 4) + { + CAP_tqcsp( + this->species_relative_activity_idx[i], (char*)"entered", &noerr); // DL + CAP_tqsetc((char*)"ac", + this->species_relative_activity_idx[i], + 0, + this->species_relative_activity[i], + &numcon, + &noerr); // DL + } + } + } + } + + for (i = 0; i < (size_t)ns; i++) + { // DL set the solid species as eliminated when the value is -100 + if (species_phase[i] == 0 && species_value[i] < -50 && species_value[i] > -200) + CAP_tqcsp(this->species_idx[i], (char*)"eliminated", &noerr); + } + // CAP_tqshow(&noerr); + + // calculate + noerr = 0; + if (first_time && fg == 0) + { // do when the first node is called + CAP_tqce(const_cast(" "), 0, 0, vals, &noerr); + first_time = false; + } + else + { + if (ii == 1 || ii == 6 /*|| ii==8 || ii==12 || ii==16 || ii==20 */) + CAP_tqcen((char*)" ", + 0, + 0, + vals, + &noerr); // this is faster, using previuos result as start for iteration + else + CAP_tqcen((char*)" ", + 0, + 0, + vals, + &noerr); // this is faster, using previuos result as start for iteration + } + + // post checking + if (noerr) + ix = 100; + else + { + this->species_relative_activity_ia.clear(); + this->species_relative_activity_calc.clear(); + number_UnderSat = 0; + for (i = 0; i < species_relative_activity_name.size(); i++) + { + if (species_value[this->species_relative_activity_idx_pcs[i]] > -50) + { // DL==== + CAP_tqgetr((char*)"ia", + this->species_relative_activity_idx[i], + 0, + &value, + &noerr); // get income amount, "ia" + this->species_relative_activity_ia.push_back(value); + CAP_tqgetr((char*)"ac", + this->species_relative_activity_idx[i], + 0, + &value, + &noerr); // get relative activity after calc, "ac" + this->species_relative_activity_calc.push_back(value); + } + else + { + this->species_relative_activity_ia.push_back(-100); + this->species_relative_activity_calc.push_back(-100); + } + if (species_value[this->species_relative_activity_idx_pcs[i]] > -50) + { // DL==== + if (this->species_relative_activity_state[i] == 1 + || this->species_relative_activity_state[i] == 4) + { // ra case + if (this->species_relative_activity_ia[i] > 0.0 + && this->species_relative_activity_ia[i] + > species_value[this->species_relative_activity_idx_pcs[i]]) + { + this->species_relative_activity_state[i] = 2; + number_UnderSat++; + } + else + { + this->species_relative_activity_state[i] = 1; + this->species_relative_activity_ia[i] + = species_value[this->species_relative_activity_idx_pcs[i]] + - this->species_relative_activity_ia[i]; + } + } + else if (this->species_relative_activity_state[i] == 2 + || this->species_relative_activity_state[i] == 3) + { // dormant case + if (this->species_relative_activity_calc[i] + > this->species_relative_activity[i]) + { + this->species_relative_activity_state[i] = 4; + number_UnderSat++; + } + else + { + this->species_relative_activity_state[i] = 3; + this->species_relative_activity_ia[i] = 0.0; + } + } + // cout << ix << " state " << this->species_relative_activity_state[i] << "\n"; + } // > -50 + } + if (number_UnderSat == 0) + ix = 100; + } + } // for ix< 5 + } + // DL --------------------------------------------end ra + + if (noerr) + warning_out << " Time Step " << aktueller_zeitschritt << " Node " << ii + << ". Recovering ... i_np = " << i_np << " --> " << i_np + 1 << "\n"; + else + break; + } // end ChemApp Eq calc Recovering + + //====RECOVERING LOOP END==== + + if (noerr) + { + cout << "\n" + << "\n" + << " Time Step " << aktueller_zeitschritt << "\n"; + cout << " WARNING... At node " << ii << " ChemApp ERROR... NO CHEMICAL REACTION CALCULATION!" + << "\n"; // exit(1) + cout << ii << "-----------------------------" + << "\n" + << " Input P Id Name" + << "\n"; + for (i = 0; i < (size_t)ns; i++) + { + if (species_dormant[i] == 0) + cout << setprecision(8) << setw(14) << species_value[i] << " " << species_phase[i] << " " + << setw(4) << species_idx[i] << " " << species_name[i] << "\n"; + } + + // CAP_tqshow(&noerr); + // Kinetic Parameters Updata, in case of error, an empty vector will be stored + if (MinKinReact && ff != 1 && nodeflag < 0) + { + // if(MinKinReact && ff != -1){ + species_value_d.clear(); + for (i = 0; i < species_value.size(); i++) + species_value_d.push_back(species_value[i]); + this->KinParamUpdata(ii, noerr, species_value_d); + this->KinParamUpdataHKF(ii, TT, PP, noerr); // CB include noerr + } + } else - CAP_tqcen((char *)" ", 0, 0, vals, &noerr); // this is faster, using previuos result as start for iteration - } + { + // show sateration index list + if (fg == 0 && this->Node_All_SI.size() > 0) + { + for (i = 0; i < Node_All_SI.size(); i++) + { + if (ii == this->Node_All_SI[i]) + { + cout << " => show all SI at Node : " << ii << "\n"; + this->SetAllSolidAsDormant(); + CAP_tqcel((char*)" ", 0, 0, vals, &noerr); + this->RecoverChemSystem(); + } + } + } + + species_value_b.clear(); + for (i = 0; i < species_value.size(); i++) + species_value_b.push_back(species_value[i]); // back up the input value + // cout << "\n" << ii << "-----------------------------" << "\n" << "Output P Id Name" << + // "\n"; + isc = 0; + // get results from Chemapp mol + for (i = 0; i < (size_t)ns; i++) + { + if (species_value[i] > -50) + { + if (species_phase[i] == 0) + CAP_tqgetr((char*)"a", + species_idx[i], + 0, + &value, + &noerr); // a = amount, phase 0, value = C, error flag + else + { + if (species_phase[i] == 2) + { // aqueous + if (this->mass_type.compare("ELEMENT")) // element //DL 2013 + CAP_tqgetr( + (char*)"a", 2, species_idx[i], &value, &noerr); // A Equilibrium amount + else + { // species + isc++; + CAP_tqgetr((char*)"ap", 2, isc, &value, &noerr); // AP Equilibrium amount / + // Equilibrium amount of system + // component in a phase , isc + // counter + } + } + else // other phases + CAP_tqgetr((char*)"a", species_phase[i], species_idx[i], &value, &noerr); + } + if (species_dormant[i] == 0) + species_value[i] = value; // get eq value from chemapp, set to input vector + + // DL 04.2013 for relative activity --------------------- + for (ix = 0; ix < (int)this->species_relative_activity_name.size(); ix++) + if (this->species_relative_activity_idx_pcs[ix] + == (int)i) // found the pcs mt in relative activity list + species_value[i] = this->species_relative_activity_ia[ix]; + } + //--------------------------------------- + // if(ii==1) + // cout << setprecision(20) << species_value[i] << " " << isc << " " << species_phase[i] << " " + //<< setw(4) << species_idx[i] << " " << species_name[i] << "\n"; + + } // for ns + + } // end ChemApp calc + + //----VLE--calc-- direct iteration method + // for(i=0;iVLE_conditions.size();i++){ + // //cout << " VLE calc ... " << iter_eq << "\n"; + // if(m_rei->VLE_conditions[i].vp_value > 1.0e-8 ){ + // delta= m_rei->VLE_conditions[i].aq_value - + // species_value[m_rei->VLE_conditions[i].idx_aq_species]; + // delta *= 1000.0; + // if(abs(delta)>1.0e-8){ + // if(delta>0) + // if(delta<=m_rei->VLE_conditions[i].vp_value){ + // m_rei->VLE_conditions[i].vp_value -= delta; + // species_value[m_rei->VLE_conditions[i].idx_aq_species] += delta; + // } + // else{ + // m_rei->VLE_conditions[i].vp_value =0; + // species_value[m_rei->VLE_conditions[i].idx_aq_species] += + // m_rei->VLE_conditions[i].vp_value; + // } + // else{ + // m_rei->VLE_conditions[i].vp_value -= delta; + // species_value[m_rei->VLE_conditions[i].idx_aq_species] += delta; + // } + // } + // else + // iv_eq[i]=true; + // } + // else + // iv_eq[i]=true; + //} + + //----bisection method-- VLE + if (m_rei) + if (m_rei->VLE_conditions.size() > 0) + { + for (i = 0; i < m_rei->VLE_conditions.size(); i++) + { + m_rei->VLE_conditions[i].delta = 0.0; + if (m_rei->VLE_conditions[i].vp_value > 0) + { + delta = m_rei->VLE_conditions[i].aq_value + - species_value[m_rei->VLE_conditions[i].idx_aq_species]; + if (iter_eq == 0) + { + a[i] = delta; + b[i] = 1.0; // 10.0*m_rei->VLE_conditions[i].aq_value; + } + if (abs(m_rei->VLE_conditions[i].aq_value) > 0) + err_vle = 1.0e-6 * abs(m_rei->VLE_conditions[i].aq_value); + else + err_vle = 1.0e-12; + if (abs(delta) < err_vle) + iv_eq[i] = true; + else + { + if (delta >= m_rei->VLE_conditions[i].vp_value) + { + m_rei->VLE_conditions[i].delta = m_rei->VLE_conditions[i].vp_value; + // m_rei->VLE_conditions[i].vp_value = 0; + } + else + { + if (iter_eq > 0) + { + if (delta > 0) + a[i] = x[i]; + else + b[i] = x[i]; + } + x[i] = 0.5 * (a[i] + b[i]); + m_rei->VLE_conditions[i].delta = x[i]; + } + } + } + else + iv_eq[i] = true; + } + + is_equilibrium = true; + for (i = 0; i < m_rei->VLE_conditions.size(); i++) + { + if (!iv_eq[i]) + is_equilibrium = false; + } + iter_eq++; + if (iter_eq >= 20) + { + is_equilibrium = true; + cout << " warning..., at node " << ii << ", iter_eq max is 20. "; + } + if (!is_equilibrium) + { + for (i = 0; i < species_value.size(); i++) + species_value[i] = species_value_s[i]; + for (i = 0; i < m_rei->VLE_conditions.size(); i++) + species_value[m_rei->VLE_conditions[i].idx_aq_species] + += m_rei->VLE_conditions[i].delta; + } + } + + //----bisection method-- VLE pressure + if (m_rei) + if (m_rei->VLE_pressure.size() > 0) + { + for (i = 0; i < m_rei->VLE_pressure.size(); i++) + { + m_rei->VLE_pressure[i].aq_value = exp(VLE::LnPHI_CO2(TT, PP)) + * m_rei->VLE_pressure[i].vp_value + / exp(VLE::Henry_const_CO2(TT)); + + std::cout << m_rei->VLE_pressure[i].aq_value << "\n"; + std::cout << (VLE::LnPHI_CO2(TT, PP)) << "\n"; + std::cout << m_rei->VLE_pressure[i].vp_value << "\n"; + std::cout << VLE::Henry_const_CO2(TT) << "\n"; + + // calc the real solubility of gas from geochemcalc, and store the value + m_rei->VLE_pressure[i].delta = 0.0; + if (m_rei->VLE_pressure[i].vp_value > 0) + { + delta = m_rei->VLE_pressure[i].aq_value + - species_value[m_rei->VLE_pressure[i].idx_aq_species] + / (species_value[widx] / 55.51); + // compare with the new value after reaction + if (iter_eq == 0) + { + a[i] = 0.0; // delta; + // b[i]=2.0; //up limiting + b[i] = 10.0 * species_value[widx] / 55.51; + } + if (abs(m_rei->VLE_pressure[i].aq_value) > 0) + err_vle = 1.0e-3 * abs(m_rei->VLE_pressure[i].aq_value); + else + err_vle = 1.0e-6; + if (abs(delta) < err_vle) + iv_eq[i] = true; + else + { + if (iter_eq > 0) + { + if (delta > 0) + a[i] = x[i]; + else + b[i] = x[i]; + } + x[i] = 0.5 * (a[i] + b[i]); + // cout << " aq " << m_rei->VLE_pressure[i].aq_value << " sp " << + // species_value[m_rei->VLE_pressure[i].idx_aq_species]/(species_value[widx]/55.51) + // << " delta " << delta<< " x[i] " << x[i] << "\n"; + m_rei->VLE_pressure[i].delta = x[i]; + } + } + else + iv_eq[i] = true; + } + is_equilibrium = true; + for (i = 0; i < m_rei->VLE_pressure.size(); i++) + { + if (!iv_eq[i]) + is_equilibrium = false; + } + + // cout << " iter_eq " << iter_eq << " water " << species_value[widx] << "\n"; + iter_eq++; + if (iter_eq >= 20) + { + is_equilibrium = true; + cout << " warning..., at node " << ii << ", iter_eq max is 20. for VLE_P "; + } + + if (!is_equilibrium) + { + for (i = 0; i < species_value.size(); i++) + species_value[i] = species_value_s[i]; + for (i = 0; i < m_rei->VLE_pressure.size(); i++) + species_value[m_rei->VLE_pressure[i].idx_aq_species] += m_rei->VLE_pressure[i].delta; + } + } + //----------------- - //post checking - if(noerr) - ix=100; - else{ - this->species_relative_activity_ia.clear(); - this->species_relative_activity_calc.clear(); - number_UnderSat=0; - for(i=0;ispecies_relative_activity_idx_pcs[i]]>-50){ //DL==== - CAP_tqgetr((char *)"ia", this->species_relative_activity_idx[i], 0, &value, &noerr); //get income amount, "ia" - this->species_relative_activity_ia.push_back(value); - CAP_tqgetr((char *)"ac", this->species_relative_activity_idx[i], 0, &value, &noerr); //get relative activity after calc, "ac" - this->species_relative_activity_calc.push_back(value); + if (m_rei) + { + if (m_rei->VLE_pressure.size() == 0 && m_rei->VLE_conditions.size() == 0) + is_equilibrium = true; } - else{ - this->species_relative_activity_ia.push_back(-100); - this->species_relative_activity_calc.push_back(-100); - } - if(species_value[this->species_relative_activity_idx_pcs[i]]>-50){ //DL==== - if(this->species_relative_activity_state[i]==1 || this->species_relative_activity_state[i]==4){ // ra case - if(this->species_relative_activity_ia[i]>0.0 - && this->species_relative_activity_ia[i]> species_value[this->species_relative_activity_idx_pcs[i]]){ - this->species_relative_activity_state[i]=2; - number_UnderSat++; - } - else{ - this->species_relative_activity_state[i]=1; - this->species_relative_activity_ia[i]= - species_value[this->species_relative_activity_idx_pcs[i]]-this->species_relative_activity_ia[i]; - } - } - else if(this->species_relative_activity_state[i]==2 || this->species_relative_activity_state[i]==3){ // dormant case - if(this->species_relative_activity_calc[i]>this->species_relative_activity[i]){ - this->species_relative_activity_state[i]=4; - number_UnderSat++; - } - else{ - this->species_relative_activity_state[i]=3; - this->species_relative_activity_ia[i]=0.0; + else + is_equilibrium = true; + + } // END while(!is_equilibrium) + //====Final Chemical Equilibria at the Node==== + + is_VLE = false; + + if (m_rei) + { + if (m_rei->VLE_pressure.size() > 0) + { + for (i = 0; i < m_rei->VLE_pressure.size(); i++) + { + if (m_rei->VLE_pressure[i].vp_value > 0) + is_VLE = true; } - } - //cout << ix << " state " << this->species_relative_activity_state[i] << "\n"; - } // > -50 - } - if(number_UnderSat==0) - ix=100; - } - } // for ix< 5 - } - //DL --------------------------------------------end ra - - - if(noerr) - warning_out << " Time Step " << aktueller_zeitschritt << " Node " << ii << ". Recovering ... i_np = " << i_np << " --> " << i_np+1 << "\n"; - else - break; - }//end ChemApp Eq calc Recovering - - //====RECOVERING LOOP END==== - - if(noerr) { - cout << "\n" << "\n" << " Time Step " << aktueller_zeitschritt << "\n"; - cout << " WARNING... At node " << ii << " ChemApp ERROR... NO CHEMICAL REACTION CALCULATION!" << "\n";//exit(1) - cout << ii << "-----------------------------" << "\n" << " Input P Id Name" << "\n"; - for( i=0;i<(size_t)ns;i++){ - if(species_dormant[i]==0) - cout << setprecision(8) << setw(14) << species_value[i] << " " << species_phase[i] << " " << setw(4) << species_idx[i] << " " << species_name[i] << "\n"; - } - - //CAP_tqshow(&noerr); - // Kinetic Parameters Updata, in case of error, an empty vector will be stored - if(MinKinReact && ff != 1 && nodeflag < 0){ - //if(MinKinReact && ff != -1){ - species_value_d.clear(); - for(i=0;iKinParamUpdata(ii, noerr, species_value_d); - this->KinParamUpdataHKF(ii,TT,PP,noerr); // CB include noerr - } - } - else{ - - //show sateration index list - if(fg==0 && this->Node_All_SI.size()>0){ - for(i=0;iNode_All_SI[i]){ - cout << " => show all SI at Node : " << ii << "\n"; - this->SetAllSolidAsDormant(); - CAP_tqcel((char *)" ", 0, 0, vals, &noerr); - this->RecoverChemSystem(); - } + } } - } - species_value_b.clear(); - for(i=0;i-50){ - if(species_phase[i]==0) - CAP_tqgetr((char *)"a", species_idx[i], 0, &value, &noerr); // a = amount, phase 0, value = C, error flag - else { - if(species_phase[i]==2){ // aqueous - if(this->mass_type.compare("ELEMENT")) // element //DL 2013 - CAP_tqgetr((char *)"a", 2, species_idx[i], &value, &noerr); // A Equilibrium amount - else { // species - isc++; - CAP_tqgetr((char *)"ap", 2, isc, &value, &noerr); // AP Equilibrium amount / Equilibrium amount of system component in a phase , isc counter - } - } - else // other phases - CAP_tqgetr((char *)"a", species_phase[i], species_idx[i], &value, &noerr); - } - if(species_dormant[i]==0) - species_value[i] = value; //get eq value from chemapp, set to input vector - - //DL 04.2013 for relative activity --------------------- - for(ix=0;ix<(int)this->species_relative_activity_name.size();ix++) - if(this->species_relative_activity_idx_pcs[ix]==(int)i) //found the pcs mt in relative activity list - species_value[i]=this->species_relative_activity_ia[ix]; - } - //--------------------------------------- - //if(ii==1) - // cout << setprecision(20) << species_value[i] << " " << isc << " " << species_phase[i] << " " << setw(4) << species_idx[i] << " " << species_name[i] << "\n"; - - } // for ns - - }//end ChemApp calc - - //----VLE--calc-- direct iteration method - //for(i=0;iVLE_conditions.size();i++){ - // //cout << " VLE calc ... " << iter_eq << "\n"; - // if(m_rei->VLE_conditions[i].vp_value > 1.0e-8 ){ - // delta= m_rei->VLE_conditions[i].aq_value - species_value[m_rei->VLE_conditions[i].idx_aq_species]; - // delta *= 1000.0; - // if(abs(delta)>1.0e-8){ - // if(delta>0) - // if(delta<=m_rei->VLE_conditions[i].vp_value){ - // m_rei->VLE_conditions[i].vp_value -= delta; - // species_value[m_rei->VLE_conditions[i].idx_aq_species] += delta; - // } - // else{ - // m_rei->VLE_conditions[i].vp_value =0; - // species_value[m_rei->VLE_conditions[i].idx_aq_species] += m_rei->VLE_conditions[i].vp_value; - // } - // else{ - // m_rei->VLE_conditions[i].vp_value -= delta; - // species_value[m_rei->VLE_conditions[i].idx_aq_species] += delta; - // } - // } - // else - // iv_eq[i]=true; - // } - // else - // iv_eq[i]=true; - //} + if (is_VLE) + cout << "at node " << ii << " VLE_P iterations " << iter_eq << "\n"; + + if (!noerr) + { + if (m_rei) + // revise VLE vp_value + for (i = 0; i < m_rei->VLE_conditions.size(); i++) + { + m_rei->VLE_conditions[i].vp_value -= m_rei->VLE_conditions[i].delta; + m_pcs = pcs_vector[m_rei->VLE_conditions[i].vp_idx]; + m_pcs->SetNodeValue(ii, f, m_rei->VLE_conditions[i].vp_value); + } - //----bisection method-- VLE - if(m_rei) - if(m_rei->VLE_conditions.size()>0 ) - { - for(i=0;iVLE_conditions.size();i++){ - m_rei->VLE_conditions[i].delta=0.0; - if(m_rei->VLE_conditions[i].vp_value>0){ - delta=m_rei->VLE_conditions[i].aq_value - species_value[m_rei->VLE_conditions[i].idx_aq_species]; - if(iter_eq==0){ - a[i]=delta; - b[i]=1.0; //10.0*m_rei->VLE_conditions[i].aq_value; - } - if (abs(m_rei->VLE_conditions[i].aq_value)>0) - err_vle= 1.0e-6*abs(m_rei->VLE_conditions[i].aq_value); - else - err_vle=1.0e-12; - if(abs(delta)< err_vle) - iv_eq[i]=true; - else{ - if(delta >= m_rei->VLE_conditions[i].vp_value){ - m_rei->VLE_conditions[i].delta = m_rei->VLE_conditions[i].vp_value; - //m_rei->VLE_conditions[i].vp_value = 0; + // for(i=0;i 1.0e-8 ) + //} + // pass parameters from pcs-eclipse + + ////delete amount for charge balance + // for(i=0;i=0 && species_idx[i]==34) + // species_value[i] -= zEA; + // if(zEA <=0 && species_idx[i]==71) + // species_value[i] += zEA; + // } + //} + + //----------------------------------- + // Kinetic Parameters Updata + if (MinKinReact && ff != 1 && nodeflag < 0) + { + // if(MinKinReact && ff != -1){ + + species_value_d.clear(); + for (i = 0; i < species_value.size(); i++) + species_value_d.push_back(species_value[i]); + this->KinParamUpdata( + ii, noerr, species_value_d); // in case of no error, a filled vector will be stored + this->KinParamUpdataHKF(ii, TT, PP, noerr); // CB include noerr + //----------------------------------- + // species_value_d=this->KineticReact(species_value_d); + //----------------------------------- } - else{ - if(iter_eq>0){ - if(delta>0) a[i]=x[i]; - else b[i]=x[i]; + + //----------------------------------- + // return back the residual value + if (m_rei) + if (m_rei->residual_back) + for (i = 0; i < residual_idx.size(); i++) + species_value[residual_idx[i]] += residual_value[i]; + //----------------------------------- + // species_value=this->KineticReact(species_value); + //----------------------------------- + + // if(ii==1) cout << " value " << species_value.back() << "\n"; + // unit factors are only different from 1 if(m_rei && m_rei->unitconversion) + for (i = 0; i < (size_t)ns; i++) + { // mol/m3 + if (species_dormant[ns - i - 1] == 0) + { // return only values of non-dormant species + m_pcs = pcs_vector[pcs_mass_idx[ns - i - 1]]; + if (this->species_phase[ns - i - 1] == 0) + { + if (ff == 1) // full geochemistry calculation + m_pcs->SetNodeValue( + ii, f, species_value.back() / unitfactor_s); // old f==0 or new f==1 time step + } + else if (this->species_phase[ns - i - 1] == 2) + { + m_pcs->SetNodeValue(ii, f, species_value.back() / unitfactor_l); // old or new time step + if (ns - (int)i - 1 == widx && m_rei) // update water concentration vector as well + if (m_rei->unitconversion) + m_rei->water_conc[ii] = species_value.back() / unitfactor_l; + } + else // CB / DL 21.1.2011: Attention: Gas phase volume fraction : (1-S)*n + m_pcs->SetNodeValue(ii, f, species_value.back()); // new time step } - x[i]=0.5*(a[i]+b[i]); - m_rei->VLE_conditions[i].delta = x[i]; + species_value.pop_back(); + } // push back chemical equilibrium values + + // TEST CB + // species_value.clear(); + // for(i=0;ipcs_mass_idx[i]]; + // species_value.push_back(m_pcs->GetNodeValue(ii,1)); + // } + + // return species value at this node and time step, if pcs_ospecies_idx.size>0 22.01.2009 + for (i = 0; i < pcs_ospecies_idx.size(); i++) + { + m_pcs = pcs_vector[pcs_ospecies_idx[i]]; + CAP_tqinpc((char*)m_pcs->pcs_primary_function_name[0], 2, &ipc, &noerr); + CAP_tqgetr((char*)"a", 2, ipc, &value, &noerr); + value /= unitfactor_l; + m_pcs->SetNodeValue(ii, f, value); + } // end return species value + + // return nlog value of species at this node, if pcs_nspecies_idx.size>0 + for (i = 0; i < pcs_nspecies_idx.size(); i++) + { + m_pcs = pcs_vector[pcs_nspecies_idx[i]]; + if (species_nlog_phase[nspecies_idx[i]] == 0) + CAP_tqgetr((char*)"ac", species_nlog_idx[nspecies_idx[i]], 0, &value, &noerr); + else + CAP_tqgetr((char*)"ac", + species_nlog_phase[nspecies_idx[i]], + species_nlog_idx[nspecies_idx[i]], + &value, + &noerr); + // if(value==0) exit(1); + if (abs(value - 1.0) < 1.0e-8) + value = 1.0; + value = 0.0 - log10(value); + m_pcs->SetNodeValue(ii, f, value); + } + // return redox Eh value of given reaction at this node + if (pcs_redox > -1) + { + value1 = 0.0; + for (i = 2; i < species_redox_name.size(); i++) + { + if (species_redox_phase[i] == 0) + CAP_tqgetr((char*)"ac", species_redox_idx[i], 0, &value, &noerr); + else + CAP_tqgetr((char*)"ac", species_redox_phase[i], species_redox_idx[i], &value, &noerr); + if (value > 0) + value1 = value1 + redox_stoi[i] * log(value); + } + if (redox_stoi[1] != 0) + value1 = redox_stoi[0] + 8.31451 * TT / 96485.3 * value1 / redox_stoi[1]; + else + value1 = redox_stoi[0]; + m_pcs = pcs_vector[pcs_redox]; + m_pcs->SetNodeValue(ii, f, value1); } - } - } - else - iv_eq[i]=true; - } - - is_equilibrium=true; - for(i=0;iVLE_conditions.size();i++){ - if(!iv_eq[i]) - is_equilibrium=false; - } - iter_eq ++; - if(iter_eq >=20){ - is_equilibrium=true; - cout << " warning..., at node " << ii << ", iter_eq max is 20. "; - } - if(!is_equilibrium){ - for(i=0;iVLE_conditions.size();i++) - species_value[m_rei->VLE_conditions[i].idx_aq_species] += m_rei->VLE_conditions[i].delta; - } - } - - //----bisection method-- VLE pressure - if(m_rei) - if(m_rei->VLE_pressure.size()>0){ - for(i=0;iVLE_pressure.size();i++){ - m_rei->VLE_pressure[i].aq_value= exp(VLE::LnPHI_CO2(TT,PP))*m_rei->VLE_pressure[i].vp_value/exp(VLE::Henry_const_CO2(TT)); - - std::cout << m_rei->VLE_pressure[i].aq_value << "\n"; - std::cout << (VLE::LnPHI_CO2(TT,PP)) << "\n"; - std::cout << m_rei->VLE_pressure[i].vp_value << "\n"; - std::cout << VLE::Henry_const_CO2(TT) << "\n"; - - //calc the real solubility of gas from geochemcalc, and store the value - m_rei->VLE_pressure[i].delta=0.0; - if(m_rei->VLE_pressure[i].vp_value>0){ - delta=m_rei->VLE_pressure[i].aq_value - species_value[m_rei->VLE_pressure[i].idx_aq_species]/(species_value[widx]/55.51); - //compare with the new value after reaction - if(iter_eq==0){ - a[i]=0.0; //delta; - //b[i]=2.0; //up limiting - b[i]=10.0*species_value[widx]/55.51; - } - if (abs(m_rei->VLE_pressure[i].aq_value)>0) - err_vle= 1.0e-3*abs(m_rei->VLE_pressure[i].aq_value); - else - err_vle=1.0e-6; - if(abs(delta)< err_vle) - iv_eq[i]=true; - else{ - if(iter_eq>0){ - if(delta>0) a[i]=x[i]; - else b[i]=x[i]; - } - x[i]=0.5*(a[i]+b[i]); - //cout << " aq " << m_rei->VLE_pressure[i].aq_value << " sp " << species_value[m_rei->VLE_pressure[i].idx_aq_species]/(species_value[widx]/55.51) << " delta " << delta<< " x[i] " << x[i] << "\n"; - m_rei->VLE_pressure[i].delta = x[i]; - - } - } - else - iv_eq[i]=true; - } - is_equilibrium=true; - for(i=0;iVLE_pressure.size();i++){ - if(!iv_eq[i]) - is_equilibrium=false; - } - - //cout << " iter_eq " << iter_eq << " water " << species_value[widx] << "\n"; - iter_eq ++; - if(iter_eq >=20){ - is_equilibrium=true; - cout << " warning..., at node " << ii << ", iter_eq max is 20. for VLE_P "; - } - - if(!is_equilibrium){ - for(i=0;iVLE_pressure.size();i++) - species_value[m_rei->VLE_pressure[i].idx_aq_species] += m_rei->VLE_pressure[i].delta; - } - } - //----------------- - - if(m_rei) - { - if(m_rei->VLE_pressure.size()==0 && m_rei->VLE_conditions.size()==0) - is_equilibrium=true; - } - else - is_equilibrium=true; - - }// END while(!is_equilibrium) -//====Final Chemical Equilibria at the Node==== - - - - is_VLE=false; - - if(m_rei) { - if(m_rei->VLE_pressure.size()>0){ - for(i=0;iVLE_pressure.size();i++){ - if(m_rei->VLE_pressure[i].vp_value>0) - is_VLE=true; - } - } - } - - if(is_VLE) cout << "at node " << ii << " VLE_P iterations " << iter_eq << "\n"; - - if(!noerr) { - if(m_rei) - //revise VLE vp_value - for(i=0;iVLE_conditions.size();i++){ - m_rei->VLE_conditions[i].vp_value -= m_rei->VLE_conditions[i].delta; - m_pcs = pcs_vector[m_rei->VLE_conditions[i].vp_idx]; - m_pcs->SetNodeValue(ii,f,m_rei->VLE_conditions[i].vp_value); - } - - //for(i=0;i 1.0e-8 ) - //} - // pass parameters from pcs-eclipse - - ////delete amount for charge balance - //for(i=0;i=0 && species_idx[i]==34) - // species_value[i] -= zEA; - // if(zEA <=0 && species_idx[i]==71) - // species_value[i] += zEA; - // } - //} - - //----------------------------------- - // Kinetic Parameters Updata - if(MinKinReact && ff != 1 && nodeflag < 0){ - //if(MinKinReact && ff != -1){ - - species_value_d.clear(); - for(i=0;iKinParamUpdata(ii, noerr, species_value_d); // in case of no error, a filled vector will be stored - this->KinParamUpdataHKF(ii,TT,PP,noerr); // CB include noerr - //----------------------------------- - //species_value_d=this->KineticReact(species_value_d); - //----------------------------------- - } - - //----------------------------------- - //return back the residual value - if(m_rei) - if(m_rei->residual_back) - for(i=0;iKineticReact(species_value); - //----------------------------------- - - //if(ii==1) cout << " value " << species_value.back() << "\n"; - // unit factors are only different from 1 if(m_rei && m_rei->unitconversion) - for( i=0;i<(size_t)ns;i++){ //mol/m3 - if( species_dormant[ns-i-1]==0){ // return only values of non-dormant species - m_pcs = pcs_vector[pcs_mass_idx[ns-i-1]]; - if(this->species_phase[ns-i-1]==0){ - if(ff==1) // full geochemistry calculation - m_pcs->SetNodeValue(ii,f,species_value.back()/unitfactor_s); // old f==0 or new f==1 time step - } - else if(this->species_phase[ns-i-1]==2){ - m_pcs->SetNodeValue(ii,f,species_value.back()/unitfactor_l); // old or new time step - if( ns-(int)i-1 == widx && m_rei) // update water concentration vector as well - if(m_rei->unitconversion) - m_rei->water_conc[ii] = species_value.back()/unitfactor_l; - } - else // CB / DL 21.1.2011: Attention: Gas phase volume fraction : (1-S)*n - m_pcs->SetNodeValue(ii,f,species_value.back()); // new time step - } - species_value.pop_back(); - }//push back chemical equilibrium values - - //TEST CB - //species_value.clear(); - // for(i=0;ipcs_mass_idx[i]]; - // species_value.push_back(m_pcs->GetNodeValue(ii,1)); - // } - - //return species value at this node and time step, if pcs_ospecies_idx.size>0 22.01.2009 - for(i=0;ipcs_primary_function_name[0], 2, &ipc, &noerr); - CAP_tqgetr((char *)"a", 2, ipc, &value, &noerr); - value /= unitfactor_l; - m_pcs->SetNodeValue(ii,f,value); - }//end return species value - - //return nlog value of species at this node, if pcs_nspecies_idx.size>0 - for(i=0;iSetNodeValue(ii,f,value); - } - //return redox Eh value of given reaction at this node - if(pcs_redox>-1){ - value1=0.0; - for(i=2;i0) - value1=value1+redox_stoi[i]*log(value); - } - if(redox_stoi[1]!=0) - value1=redox_stoi[0]+ 8.31451 *TT /96485.3 *value1 /redox_stoi[1]; - else value1=redox_stoi[0]; - m_pcs=pcs_vector[pcs_redox]; - m_pcs->SetNodeValue(ii,f,value1); - } - - } // if(noerr) - - } // if(rateflag[ii]!=0) - else if(MinKinReact && ff != 1 && nodeflag < 0){ // Kinetic Parameters Updata // - // when rateflag[ii] == 0, noerr is not defined. Do so for Kinetic Parameters Updating - this->KinParamUpdata(ii, 1, species_value_d); - this->KinParamUpdataHKF(ii,TT,PP,1); // CB include noerr - } - - //return pcs rename - for(i=0;iGetNodeValue(ii,f); - else if(pcs_rename_stoi[i][ix]==-999999) - value /= m_pcs->GetNodeValue(ii,f); - else - value += m_pcs->GetNodeValue(ii,f) *pcs_rename_stoi[i][ix];; - } - m_pcs= pcs_vector[pcs_rename_idx0[i]]; - m_pcs->SetNodeValue(ii,f,value); - } + } // if(noerr) -} // for (ii node loop) + } // if(rateflag[ii]!=0) + else if (MinKinReact && ff != 1 && nodeflag < 0) + { // Kinetic Parameters Updata // + // when rateflag[ii] == 0, noerr is not defined. Do so for Kinetic Parameters Updating + this->KinParamUpdata(ii, 1, species_value_d); + this->KinParamUpdataHKF(ii, TT, PP, 1); // CB include noerr + } -} // end of function loopnodereact + // return pcs rename + for (i = 0; i < pcs_rename_idx0.size(); i++) + { + value = 0.0; + for (ix = 0; ix < (int)pcs_rename_idx1[i].size(); ix++) + { + //--return back residual + // for(i_s=0;i_s<(int)pcs_mass_idx.size();i_s++){ + // if(pcs_rename_idx1[i][ix]==pcs_mass_idx[i_s]) + // for(i_r=0;i_r<(int)residual_value.size();i_r++){ + // if(residual_idx[i_r]==i_s) + // value += residual_value[i_r]; + // } + //} + + m_pcs = pcs_vector[pcs_rename_idx1[i][ix]]; + if (pcs_rename_stoi[i][ix] == 999999) + value *= m_pcs->GetNodeValue(ii, f); + else if (pcs_rename_stoi[i][ix] == -999999) + value /= m_pcs->GetNodeValue(ii, f); + else + value += m_pcs->GetNodeValue(ii, f) * pcs_rename_stoi[i][ix]; + ; + } + m_pcs = pcs_vector[pcs_rename_idx0[i]]; + m_pcs->SetNodeValue(ii, f, value); + } + + } // for (ii node loop) +} // end of function loopnodereact -void REACT_CAP::LoopNodeReact_Liquid_Vapor(int /*f*/, int nodeflag){ +void REACT_CAP::LoopNodeReact_Liquid_Vapor(int /*f*/, int nodeflag) +{ LI i, noerr = 0; - cout << "\n" << " --> Liquid Vapor Reactions " << "\n"; + cout << "\n" + << " --> Liquid Vapor Reactions " + << "\n"; - for(i=0;i<(int)species_name.size();i++) - if(species_phase[i]==0) CAP_tqcsp(species_idx[i], (char *)"dormant", &noerr); + for (i = 0; i < (int)species_name.size(); i++) + if (species_phase[i] == 0) + CAP_tqcsp(species_idx[i], (char*)"dormant", &noerr); this->LoopNodeReact(-1, nodeflag); - for(i=0;i<(int)species_name.size();i++) - if(species_phase[i]==0) CAP_tqcsp(species_idx[i], (char *)"entered", &noerr); - for(i=0;i<(int)species_kin_name.size();i++) - if(species_kin_phase[i]==0) CAP_tqcsp(species_kin_idx[i], (char *)"dormant", &noerr); + for (i = 0; i < (int)species_name.size(); i++) + if (species_phase[i] == 0) + CAP_tqcsp(species_idx[i], (char*)"entered", &noerr); + for (i = 0; i < (int)species_kin_name.size(); i++) + if (species_kin_phase[i] == 0) + CAP_tqcsp(species_kin_idx[i], (char*)"dormant", &noerr); } -void REACT_CAP::LoopNodeReact_Liquid_Solid(int /*f*/, int /*nodeflag*/){ - //LI i, noerr=0; - cout << "\n" << " --> Liquid Solid Reactions " << "\n"; +void REACT_CAP::LoopNodeReact_Liquid_Solid(int /*f*/, int /*nodeflag*/) +{ + // LI i, noerr=0; + cout << "\n" + << " --> Liquid Solid Reactions " + << "\n"; - //for(i=0;i<(int)species_name.size();i++) + // for(i=0;i<(int)species_name.size();i++) // if(species_phase[i]==0) CAP_tqcsp(species_idx[i], "dormant", &noerr); - //this->LoopNodeReact(-1, nodeflag); + // this->LoopNodeReact(-1, nodeflag); - //for(i=0;i<(int)species_name.size();i++) + // for(i=0;i<(int)species_name.size();i++) // if(species_phase[i]==0) CAP_tqcsp(species_idx[i], "entered", &noerr); - //for(i=0;i<(int)species_kin_name.size();i++) + // for(i=0;i<(int)species_kin_name.size();i++) // if(species_kin_phase[i]==0) CAP_tqcsp(species_kin_idx[i], "dormant", &noerr); } - /*********************************************************** Function: REACT_CAP::KinParamUpdat(void) - Task: - kinetic parameters updata at the ChemApp state - DL 10/10 + Task: + kinetic parameters updata at the ChemApp state + DL 10/10 ***********************************************************/ -void REACT_CAP::KinParamUpdata(int /*ii*/, int err, vector & spvc){ - +void REACT_CAP::KinParamUpdata(int /*ii*/, int err, vector& spvc) +{ int i, i_re, i_resp; long noerr = 0; double value_ac, value_dG, logK; @@ -2428,190 +2941,215 @@ void REACT_CAP::KinParamUpdata(int /*ii*/, int err, vector & spvc){ species_ac.clear(); reaction_logK.clear(); - if(err == 0){ // value was calculated - for(i=0;i<(int)species_name.size();i++){ // loop over species - if(species_phase[i]==0) // mineral phase - species_ac.push_back(1.0); - //CAP_tqgetr("ac", species_idx[i], 0, &value_ac, &noerr); // this is activity!! not a.coeff - else{ - CAP_tqgetr((char *)"ac", species_phase[i], species_idx[i], &value_ac, &noerr); // liquid phase - if(strcmp(species_name[i],"H2O")==0 || strcmp(species_name[i],"H2O_liquid")==0 || strcmp(species_name[i],"water_liquid")==0 ) // for H2O use value_ac directly - species_ac.push_back(value_ac); - else if(value_ac/*spvc[i]*/>0) // otherwise divide by molality to obtain gamma, if species conc > 0 - species_ac.push_back(value_ac/spvc[i] * spvc[0]/MOLH2OPERKG ); - else // store activity coefficient = 1, of species concentration = 0 - species_ac.push_back(1.0); - } - } - - for(i_re=0;i_re<(int)this->Kin_Reactions.size();i_re++){ // loop over reactions - logK=0; - for(i_resp=0;i_resp<(int)this->Kin_Reactions[i_re].species_name.size();i_resp++){ // loop over species of reaction - if(Kin_Reactions[i_re].species_phase[i_resp]==0){ - CAP_tqgdpc((char *)"G", Kin_Reactions[i_re].species_idx[i_resp], 0, &value_dG, &noerr); // Get Gibbs energy for species - } - else { - CAP_tqgdpc((char *)"G", Kin_Reactions[i_re].species_phase[i_resp], Kin_Reactions[i_re].species_idx[i_resp], &value_dG, &noerr); - } - logK += -value_dG*Kin_Reactions[i_re].species_stoi[i_resp]/2.302585; // calculate logK for reaction - } - reaction_logK.push_back(logK); // store logK of a reaction - } - //node_logK.push_back(reaction_logK); - } - // pushback species_ac and reaction_logK vectors, - // or empty vectors instead when noerr = 1 or rateflag == 0 - node_ac.push_back(species_ac); - node_logK.push_back(reaction_logK); -} + if (err == 0) + { // value was calculated + for (i = 0; i < (int)species_name.size(); i++) + { // loop over species + if (species_phase[i] == 0) // mineral phase + species_ac.push_back(1.0); + // CAP_tqgetr("ac", species_idx[i], 0, &value_ac, &noerr); // this is activity!! not a.coeff + else + { + CAP_tqgetr((char*)"ac", species_phase[i], species_idx[i], &value_ac, &noerr); // liquid phase + if (strcmp(species_name[i], "H2O") == 0 || strcmp(species_name[i], "H2O_liquid") == 0 + || strcmp(species_name[i], "water_liquid") == 0) // for H2O use value_ac directly + species_ac.push_back(value_ac); + else if (value_ac /*spvc[i]*/ > 0) // otherwise divide by molality to obtain gamma, if species conc > 0 + species_ac.push_back(value_ac / spvc[i] * spvc[0] / MOLH2OPERKG); + else // store activity coefficient = 1, of species concentration = 0 + species_ac.push_back(1.0); + } + } + for (i_re = 0; i_re < (int)this->Kin_Reactions.size(); i_re++) + { // loop over reactions + logK = 0; + for (i_resp = 0; i_resp < (int)this->Kin_Reactions[i_re].species_name.size(); i_resp++) + { // loop over species of reaction + if (Kin_Reactions[i_re].species_phase[i_resp] == 0) + { + CAP_tqgdpc((char*)"G", + Kin_Reactions[i_re].species_idx[i_resp], + 0, + &value_dG, + &noerr); // Get Gibbs energy for species + } + else + { + CAP_tqgdpc((char*)"G", + Kin_Reactions[i_re].species_phase[i_resp], + Kin_Reactions[i_re].species_idx[i_resp], + &value_dG, + &noerr); + } + logK += -value_dG * Kin_Reactions[i_re].species_stoi[i_resp] / 2.302585; // calculate logK for reaction + } + reaction_logK.push_back(logK); // store logK of a reaction + } + // node_logK.push_back(reaction_logK); + } + // pushback species_ac and reaction_logK vectors, + // or empty vectors instead when noerr = 1 or rateflag == 0 + node_ac.push_back(species_ac); + node_logK.push_back(reaction_logK); +} /*********************************************************** Function: REACT_CAP::KinParamUpdataHKF(void) - Task: - kinetic parameters updata HKF - DL 11/10 + Task: + kinetic parameters updata HKF + DL 11/10 ***********************************************************/ -void REACT_CAP::KinParamUpdataHKF(int /*ii*/, double T, double P, int err){ - - int i=-1, i_re, i_resp; - //long noerr = 0; - //double value_ac; - double value_dG, logK; +void REACT_CAP::KinParamUpdataHKF(int /*ii*/, double T, double P, int err) +{ + int i = -1, i_re, i_resp; + // long noerr = 0; + // double value_ac; + double value_dG, logK; vector species_ac, reaction_logK; - //cout << " KinParamUpdataHKF " << "\n"; + // cout << " KinParamUpdataHKF " << "\n"; reaction_logK.clear(); - if(err == 0){ // value was calculated - HKFcalc(T,P); - for(i_re=0;i_re<(int)this->Kin_HKF_Reactions.size();i_re++){ - logK=0; - for(i_resp=0;i_resp<(int)this->Kin_HKF_Reactions[i_re].species_name.size();i_resp++){ - i++; - value_dG=Kin_HKF_species[Kin_HKF_index[i]].G; - logK += Kin_HKF_Reactions[i_re].species_stoi[i_resp]*value_dG*4.18/2.302585/8.314/T; - } - reaction_logK.push_back(logK); - } - //node_HKF_logK.push_back(reaction_logK); - } - // pushback reaction logK vector, - // or empty vector instead when noerr = 1 or rateflag == 0 - node_HKF_logK.push_back(reaction_logK); + if (err == 0) + { // value was calculated + HKFcalc(T, P); + for (i_re = 0; i_re < (int)this->Kin_HKF_Reactions.size(); i_re++) + { + logK = 0; + for (i_resp = 0; i_resp < (int)this->Kin_HKF_Reactions[i_re].species_name.size(); i_resp++) + { + i++; + value_dG = Kin_HKF_species[Kin_HKF_index[i]].G; + logK += Kin_HKF_Reactions[i_re].species_stoi[i_resp] * value_dG * 4.18 / 2.302585 / 8.314 / T; + } + reaction_logK.push_back(logK); + } + // node_HKF_logK.push_back(reaction_logK); + } + // pushback reaction logK vector, + // or empty vector instead when noerr = 1 or rateflag == 0 + node_HKF_logK.push_back(reaction_logK); } - - /*********************************************************** Function: REACT_CAP::KineticReact(int) - Task: - calc Kinetic reaction and updata the pcs_vector - DL 10/10 + Task: + calc Kinetic reaction and updata the pcs_vector + DL 10/10 ***********************************************************/ -vector REACT_CAP::KineticReact(vector species_value0){ - - int i, iter_max=5; +vector REACT_CAP::KineticReact(vector species_value0) +{ + int i, iter_max = 5; double t_step, h_calc; vector h, species_value1; vector dcdt0; - t_step=0.01; + t_step = 0.01; h.clear(); - for(i=0;i<(int)species_value0.size();i++){ - h_calc=1/(log10(species_value0[i])+5); + for (i = 0; i < (int)species_value0.size(); i++) + { + h_calc = 1 / (log10(species_value0[i]) + 5); - h.push_back(h_calc+10); + h.push_back(h_calc + 10); } - - - species_value1=this->ODE(species_value0, h, iter_max, t_step); - for(i=0;i<(int)species_value0.size();i++){ + species_value1 = this->ODE(species_value0, h, iter_max, t_step); + for (i = 0; i < (int)species_value0.size(); i++) + { cout << setw(32) << species_name[i] << setw(16) << species_value0[i] << setw(10) << species_value1[i] << "\n"; } - //dcdt0=derivs(species_value0); - //for(i=0;i<(int)species_value0.size();i++){ - // cout << setw(32) << species_name[i] << setw(16) << species_value0[i] /*<< setw(10) << species_value1[i] */<< " dcdt " << dcdt0[i] << "\n"; + // dcdt0=derivs(species_value0); + // for(i=0;i<(int)species_value0.size();i++){ + // cout << setw(32) << species_name[i] << setw(16) << species_value0[i] /*<< setw(10) << species_value1[i] */<< " + // dcdt " << dcdt0[i] << "\n"; //} + cout << "\n" + << "\n"; - cout << "\n" << "\n"; - - //this->KinRate(); - return species_value0;// species_value1 + // this->KinRate(); + return species_value0; // species_value1 } - - /*********************************************************** Function: REACT_CAP::ODE - DL 10/10 + DL 10/10 ***********************************************************/ -vector REACT_CAP::ODE(vector c0, vector h, int iter_max, double t_step){ - +vector REACT_CAP::ODE(vector c0, vector h, int iter_max, double t_step) +{ vector dcdt0, dcdt1; - double k=0, t0, t1, t_sum=0.0; - int i,j=0,n; + double k = 0, t0, t1, t_sum = 0.0; + int i, j = 0, n; - while(j1) dcdt1=dcdt0; + if (j > 1) + dcdt1 = dcdt0; - dcdt0=derivs(c0); + dcdt0 = derivs(c0); - if(j>1) - for(i=0;i<(int)c0.size();i++) - if(dcdt0[i]*dcdt1[i]<=0) + if (j > 1) + for (i = 0; i < (int)c0.size(); i++) + if (dcdt0[i] * dcdt1[i] <= 0) n++; - for(i=0;i<(int)c0.size();i++){ - if(h[i]>0){ - if(dcdt0[i]>0) - k=1-pow(10,h[i]); - if(dcdt0[i]<0) - k=1-pow(10,-h[i]); - if(dcdt0[i]==0) - k=0.0; - if(dcdt0[i]!=0 && c0[i]!=0) - t1=abs(c0[i]*k/dcdt0[i]); - cout << " dcdt0 " << setw(16) << dcdt0[i] << " c0 " << setw(16) << c0[i] << " h " << h[i] << " t1 " << setw(16) << t1 /*<< "\n"*/; + for (i = 0; i < (int)c0.size(); i++) + { + if (h[i] > 0) + { + if (dcdt0[i] > 0) + k = 1 - pow(10, h[i]); + if (dcdt0[i] < 0) + k = 1 - pow(10, -h[i]); + if (dcdt0[i] == 0) + k = 0.0; + if (dcdt0[i] != 0 && c0[i] != 0) + t1 = abs(c0[i] * k / dcdt0[i]); + cout << " dcdt0 " << setw(16) << dcdt0[i] << " c0 " << setw(16) << c0[i] << " h " << h[i] << " t1 " + << setw(16) << t1 /*<< "\n"*/; cout << " i " << i << " k " << k << " t0 " << t0 << "\n"; - if(t1= t_step){ - for(i=0;i<(int)c0.size();i++) - c0[i]+= dcdt0[i]*(t_step-t_sum+t0); - cout << " Kinetic... " << "\n"; + if (t_sum >= t_step) + { + for (i = 0; i < (int)c0.size(); i++) + c0[i] += dcdt0[i] * (t_step - t_sum + t0); + cout << " Kinetic... " + << "\n"; break; } - if(n==(int)c0.size()){ - cout << " Equilibrium... " << "\n"; + if (n == (int)c0.size()) + { + cout << " Equilibrium... " + << "\n"; break; } - for(i=0;i<(int)c0.size();i++) - c0[i]+= dcdt0[i]*t0; + for (i = 0; i < (int)c0.size(); i++) + c0[i] += dcdt0[i] * t0; } - if(j==iter_max) - cout << " WARNING... MAX ITERATION" << "\n"; + if (j == iter_max) + cout << " WARNING... MAX ITERATION" + << "\n"; cout << " iter " << j << "\n"; return c0; } @@ -2619,86 +3157,103 @@ vector REACT_CAP::ODE(vector c0, vector h, int iter_max, /*********************************************************** Function: REACT_CAP::derivs - Task: - dc/dt=f(c) for Kinetic rate - DL 10/10 + Task: + dc/dt=f(c) for Kinetic rate + DL 10/10 ***********************************************************/ -vector REACT_CAP::derivs(vector c){ - +vector REACT_CAP::derivs(vector c) +{ vector dcdt; double *stoi, wmass; int i, ii, i_sp, i_re, i_resp; long nscom, noerr = 0; - //initial output vector + // initial output vector dcdt.clear(); - for(i=0;i<(int)c.size();i++) + for (i = 0; i < (int)c.size(); i++) dcdt.push_back(0); - - //for(i=0;i<(int)species_idx.size();i++){ + // for(i=0;i<(int)species_idx.size();i++){ // cout << " " << setw(6) << species_phase[i] << setw(6) << species_idx[i] << species_name[i] << "\n"; //} - //for(i=0;i<(int)species_kin_idx.size();i++){ + // for(i=0;i<(int)species_kin_idx.size();i++){ // cout << " " << setw(6) << species_kin_phase[i] << setw(6) << species_kin_idx[i] << species_kin_name[i] << "\n"; //} this->KinRate(); - //for(i_re=0;i_re<(int)Kin_Reactions.size();i_re++){ + // for(i_re=0;i_re<(int)Kin_Reactions.size();i_re++){ - //cout << Kin_Reactions[i_re].type << " " << Kin_Reactions[i_re].rate; - //for(i_resp=0;i_resp<(int)Kin_Reactions[i_re].species_name.size();i_resp++){ - // cout << " " << Kin_Reactions[i_re].species_stoi[i_resp] << " " << Kin_Reactions[i_re].species_name[i_resp]; - //} - //cout << "\n"; + // cout << Kin_Reactions[i_re].type << " " << Kin_Reactions[i_re].rate; + // for(i_resp=0;i_resp<(int)Kin_Reactions[i_re].species_name.size();i_resp++){ + // cout << " " << Kin_Reactions[i_re].species_stoi[i_resp] << " " << Kin_Reactions[i_re].species_name[i_resp]; + //} + // cout << "\n"; //} - if(this->mass_type=="SPECIES"){ - for(i_sp=0;i_sp<(int)this->species_name.size();i_sp++){ - for(i_re=0;i_re<(int)this->Kin_Reactions.size();i_re++){ - if(this->Kin_Reactions[i_re].is_Kin){ - for(i_resp=0;i_resp<(int)this->Kin_Reactions[i_re].species_name.size();i_resp++){ - if(strcmp(species_name[i_sp], Kin_Reactions[i_re].species_name[i_resp])==0 - && species_phase[i_sp]==Kin_Reactions[i_re].species_phase[i_resp]){ - dcdt[i_sp]+= Kin_Reactions[i_re].species_stoi[i_resp]*Kin_Reactions[i_re].rate; + if (this->mass_type == "SPECIES") + { + for (i_sp = 0; i_sp < (int)this->species_name.size(); i_sp++) + { + for (i_re = 0; i_re < (int)this->Kin_Reactions.size(); i_re++) + { + if (this->Kin_Reactions[i_re].is_Kin) + { + for (i_resp = 0; i_resp < (int)this->Kin_Reactions[i_re].species_name.size(); i_resp++) + { + if (strcmp(species_name[i_sp], Kin_Reactions[i_re].species_name[i_resp]) == 0 + && species_phase[i_sp] == Kin_Reactions[i_re].species_phase[i_resp]) + { + dcdt[i_sp] += Kin_Reactions[i_re].species_stoi[i_resp] * Kin_Reactions[i_re].rate; } } } } } - //cout << " SPECIES " << "\n"; + // cout << " SPECIES " << "\n"; } - - - - - if(this->mass_type=="ELEMENT"){ + if (this->mass_type == "ELEMENT") + { CAP_tqnosc(&nscom, &noerr); - stoi =new double[nscom]; - - for(i_re=0;i_re<(int)this->Kin_Reactions.size();i_re++){ - for(i_resp=0;i_resp<(int)this->Kin_Reactions[i_re].species_name.size();i_resp++){ - if(this->Kin_Reactions[i_re].is_Kin){ - //for non-aq phase species, renew value directly - if(Kin_Reactions[i_re].species_phase[i_resp]!=2) - for(i_sp=0;i_sp<(int)this->species_name.size();i_sp++){ - if(strcmp(species_name[i_sp], Kin_Reactions[i_re].species_name[i_resp])==0 - && species_phase[i_sp]==Kin_Reactions[i_re].species_phase[i_resp]){ - dcdt[i_sp]+= Kin_Reactions[i_re].species_stoi[i_resp]*Kin_Reactions[i_re].rate; - //cout << " " << species_name[i_sp] << "\n"; + stoi = new double[nscom]; + + for (i_re = 0; i_re < (int)this->Kin_Reactions.size(); i_re++) + { + for (i_resp = 0; i_resp < (int)this->Kin_Reactions[i_re].species_name.size(); i_resp++) + { + if (this->Kin_Reactions[i_re].is_Kin) + { + // for non-aq phase species, renew value directly + if (Kin_Reactions[i_re].species_phase[i_resp] != 2) + for (i_sp = 0; i_sp < (int)this->species_name.size(); i_sp++) + { + if (strcmp(species_name[i_sp], Kin_Reactions[i_re].species_name[i_resp]) == 0 + && species_phase[i_sp] == Kin_Reactions[i_re].species_phase[i_resp]) + { + dcdt[i_sp] += Kin_Reactions[i_re].species_stoi[i_resp] * Kin_Reactions[i_re].rate; + // cout << " " << species_name[i_sp] << "\n"; } } - //for aq species, need to calc new stoichiometry of the species in system - if(Kin_Reactions[i_re].species_phase[i_resp]==2){ - CAP_tqstpc(Kin_Reactions[i_re].species_phase[i_resp],Kin_Reactions[i_re].species_idx[i_resp],stoi,&wmass,&noerr); - ii=0; - for(i_sp=0;i_sp<(int)this->species_name.size();i_sp++){ - if(species_phase[i_sp]==2){ - dcdt[i_sp]+= stoi[ii]*Kin_Reactions[i_re].species_stoi[i_resp]*Kin_Reactions[i_re].rate; - //cout << species_name[i_sp] << " " << Kin_Reactions[i_re].type << " " << stoi[ii] << " " << Kin_Reactions[i_re].species_stoi[i_resp] << " " << Kin_Reactions[i_re].species_name[i_resp] << "\n"; + // for aq species, need to calc new stoichiometry of the species in system + if (Kin_Reactions[i_re].species_phase[i_resp] == 2) + { + CAP_tqstpc(Kin_Reactions[i_re].species_phase[i_resp], + Kin_Reactions[i_re].species_idx[i_resp], + stoi, + &wmass, + &noerr); + ii = 0; + for (i_sp = 0; i_sp < (int)this->species_name.size(); i_sp++) + { + if (species_phase[i_sp] == 2) + { + dcdt[i_sp] + += stoi[ii] * Kin_Reactions[i_re].species_stoi[i_resp] * Kin_Reactions[i_re].rate; + // cout << species_name[i_sp] << " " << Kin_Reactions[i_re].type << " " << stoi[ii] << " + // " << Kin_Reactions[i_re].species_stoi[i_resp] << " " << + // Kin_Reactions[i_re].species_name[i_resp] << "\n"; ii++; } } @@ -2706,113 +3261,131 @@ vector REACT_CAP::derivs(vector c){ } } } - //cout << " ELEMENT " << "\n"; + // cout << " ELEMENT " << "\n"; } - //for(i=0;i<(int)c.size();i++) + // for(i=0;i<(int)c.size();i++) // cout << dcdt[i] << " " << species_name[i] << "\n"; return dcdt; } +void REACT_CAP::KinRate(void) +{ + int i, ix, n_r, ii; // j, + double Kin_rate, T; //, P; -void REACT_CAP::KinRate(void){ - - int i, ix, n_r, ii; // j, - double Kin_rate, T;//, P; + ii = current_node; + T = current_TT; + // P=current_PP; + // cout << " kinetic minerals " << "\n"; + n_r = (int)this->Kin_Reactions.size(); - ii=current_node; - T=current_TT; - //P=current_PP; - //cout << " kinetic minerals " << "\n"; - n_r=(int)this->Kin_Reactions.size(); - - for(i=0;iKin_Reactions.size(); - for(i=0;iKin_Reactions.size(); + for (i = 0; i < n_r; i++) + Kin_Reactions[i].is_Kin = false; - for (i=0; i<(int)KinReact_vector.size(); i++){ + for (i = 0; i < (int)KinReact_vector.size(); i++) + { m_kr = KinReact_vector[i]; - for(ix=0;ixchemapp_name.compare(Kin_Reactions[ix].type)==0){ // found - Kin_Reactions[ix].is_Kin=true; - if(m_kr->Km_uniform){ - Kin_Reactions[ix].logK_type=0; + for (ix = 0; ix < n_r; ix++) + { + if (m_kr->chemapp_name.compare(Kin_Reactions[ix].type) == 0) + { // found + Kin_Reactions[ix].is_Kin = true; + if (m_kr->Km_uniform) + { + Kin_Reactions[ix].logK_type = 0; Kin_Reactions[ix].logK_kin = m_kr->Km_default; } - else if(m_kr->Km_CHEMAPP){ - Kin_Reactions[ix].logK_type=1; + else if (m_kr->Km_CHEMAPP) + { + Kin_Reactions[ix].logK_type = 1; Kin_Reactions[ix].logK_kin = -99; } - else if(m_kr->Km_HKF){ - Kin_Reactions[ix].logK_type=2; + else if (m_kr->Km_HKF) + { + Kin_Reactions[ix].logK_type = 2; Kin_Reactions[ix].logK_kin = -99; } - else { - Kin_Reactions[ix].logK_type=-1; + else + { + Kin_Reactions[ix].logK_type = -1; Kin_Reactions[ix].logK_kin = -99; } - Kin_Reactions[ix].eta = m_kr->Eta; + Kin_Reactions[ix].eta = m_kr->Eta; Kin_Reactions[ix].theta = m_kr->Theta; - Kin_Reactions[ix].SA = m_kr->Am_ini; - Kin_Reactions[ix].PF = m_kr->precipfactor; + Kin_Reactions[ix].SA = m_kr->Am_ini; + Kin_Reactions[ix].PF = m_kr->precipfactor; - Kin_Reactions[ix].EA.clear(); //energy activity - Kin_Reactions[ix].K25.clear(); //logK_25C + Kin_Reactions[ix].EA.clear(); // energy activity + Kin_Reactions[ix].K25.clear(); // logK_25C Kin_Reactions[ix].ref_species.clear(); Kin_Reactions[ix].ref_idx.clear(); Kin_Reactions[ix].ref_expo.clear(); - for(j=0;jmechvec.size();j++){ + for (j = 0; j < m_kr->mechvec.size(); j++) + { Kin_Reactions[ix].EA.push_back(m_kr->mechvec[j]->Eact); Kin_Reactions[ix].K25.push_back(m_kr->mechvec[j]->k25); - if(m_kr->mechvec[j]->mechSpeciesNames.size()>0){ - ref_name_kr=m_kr->mechvec[j]->mechSpeciesNames[0]; + if (m_kr->mechvec[j]->mechSpeciesNames.size() > 0) + { + ref_name_kr = m_kr->mechvec[j]->mechSpeciesNames[0]; Kin_Reactions[ix].ref_species.push_back(ref_name_kr); Kin_Reactions[ix].ref_expo.push_back(m_kr->mechvec[j]->mechSpeciesExpo[0]); - is_species=false; - for(jx=0;jx<(int)species_name.size();jx++){ - if(ref_name_kr==species_name[jx] && species_phase[jx]==2){ - is_species=true; + is_species = false; + for (jx = 0; jx < (int)species_name.size(); jx++) + { + if (ref_name_kr == species_name[jx] && species_phase[jx] == 2) + { + is_species = true; Kin_Reactions[ix].ref_idx.push_back(jx); } } - if(is_species==false){ - cout << " WARNING ... " << ref_name_kr << " is NOT ChemApp species " << "\n"; + if (is_species == false) + { + cout << " WARNING ... " << ref_name_kr << " is NOT ChemApp species " + << "\n"; exit(0); } - } - else{ + else + { Kin_Reactions[ix].ref_species.push_back(""); Kin_Reactions[ix].ref_expo.push_back(-99); Kin_Reactions[ix].ref_idx.push_back(-99); @@ -2822,8 +3395,7 @@ void REACT_CAP::KinInit(void){ } } - - //for(i=0;iKin_HKF_index.clear(); this->Kin_HKF_species.clear(); - cout << "\n" << " => SetKinHKFspecies() " << "\n"; + cout << "\n" + << " => SetKinHKFspecies() " + << "\n"; - for(i_re=0;i_re<(int)this->Kin_HKF_Reactions.size();i_re++){ + for (i_re = 0; i_re < (int)this->Kin_HKF_Reactions.size(); i_re++) + { cout << " Reaction " << Kin_HKF_Reactions[i_re].type << "\n"; - for(i_resp=0;i_resp<(int)this->Kin_HKF_Reactions[i_re].species_name.size();i_resp++){ - - for(i_sp=0;i_sp<(int)Kin_HKF_species.size();i_sp++){ - if(strcmp(this->Kin_HKF_species[i_sp].name0.c_str(), - this->Kin_HKF_Reactions[i_re].species_name[i_resp])==0){ - is_new=0; - this->Kin_HKF_index.push_back(i_sp); + for (i_resp = 0; i_resp < (int)this->Kin_HKF_Reactions[i_re].species_name.size(); i_resp++) + { + for (i_sp = 0; i_sp < (int)Kin_HKF_species.size(); i_sp++) + { + if (strcmp(this->Kin_HKF_species[i_sp].name0.c_str(), + this->Kin_HKF_Reactions[i_re].species_name[i_resp]) + == 0) + { + is_new = 0; + this->Kin_HKF_index.push_back(i_sp); } } - if(is_new==1){ + if (is_new == 1) + { i++; - HKFspecies.name0=Kin_HKF_Reactions[i_re].species_name[i_resp]; - //cout << " HKFspecies.name " << HKFspecies.name << " " - //<< Kin_HKF_Reactions[i_re].species_name[i_resp] <<"\n"; - //HKFspecies.type= + HKFspecies.name0 = Kin_HKF_Reactions[i_re].species_name[i_resp]; + // cout << " HKFspecies.name " << HKFspecies.name << " " + //<< Kin_HKF_Reactions[i_re].species_name[i_resp] <<"\n"; + // HKFspecies.type= this->Kin_HKF_species.push_back(HKFspecies); this->Kin_HKF_index.push_back(i); } - is_new=1; + is_new = 1; cout << " " << setw(4) << right << this->Kin_HKF_Reactions[i_re].species_phase[i_resp]; cout << setw(4) << this->Kin_HKF_Reactions[i_re].species_stoi[i_resp] << " "; cout << setw(10) << left << this->Kin_HKF_Reactions[i_re].species_name[i_resp] << "\n"; - } } - //for(i=0;i<(int)this->Kin_HKF_index.size();i++) + // for(i=0;i<(int)this->Kin_HKF_index.size();i++) // cout << i << " KIN index " << this->Kin_HKF_index[i] << "\n"; return sr; } -bool REACT_CAP::LoadHKFparam(){ - cout << "\n" << " => LoadHKFparam " << "\n"; - bool sr=true; - int i, ix, iy, is_load, type=-1; - double charge=-99, HKFparam[9][4]; +bool REACT_CAP::LoadHKFparam() +{ + cout << "\n" + << " => LoadHKFparam " + << "\n"; + bool sr = true; + int i, ix, iy, is_load, type = -1; + double charge = -99, HKFparam[9][4]; std::string species_name0; - //for(ix=0;ix<9;ix++) + // for(ix=0;ix<9;ix++) // for(iy=0;iy<4;iy++) // HKFparam[ix][iy]=0.0; - //cout << " size " << this->Kin_HKF_species.size() << "\n"; - for(i=0;i<(int)this->Kin_HKF_species.size();i++){ - //cout << i << " " << Kin_HKF_species[i].name0 << " " << "\n"; - if(Kin_HKF_species[i].name0.size()>14) { - cout << " Warning ... " << Kin_HKF_species[i].name0 << - " is not Kin_HKF_species in slop98.dat. EXIT" << "\n"; + // cout << " size " << this->Kin_HKF_species.size() << "\n"; + for (i = 0; i < (int)this->Kin_HKF_species.size(); i++) + { + // cout << i << " " << Kin_HKF_species[i].name0 << " " << "\n"; + if (Kin_HKF_species[i].name0.size() > 14) + { + cout << " Warning ... " << Kin_HKF_species[i].name0 << " is not Kin_HKF_species in slop98.dat. EXIT" + << "\n"; exit(0); } - if(Kin_HKF_species[i].name0=="H2O" || Kin_HKF_species[i].name0=="H2O_liquid" || Kin_HKF_species[i].name0=="water_liquid") - Kin_HKF_species[i].type=-1; - else{ - species_name0=Kin_HKF_species[i].name0; - is_load=HKF::HKF_OGS_loadparam(species_name0, type, charge, HKFparam); - - if(is_load==1){ - Kin_HKF_species[i].type=type; - Kin_HKF_species[i].charge=charge; - for(ix=0;ix<9;ix++) - for(iy=0;iy<4;iy++) - Kin_HKF_species[i].param[ix][iy]=HKFparam[ix][iy]; + if (Kin_HKF_species[i].name0 == "H2O" || Kin_HKF_species[i].name0 == "H2O_liquid" + || Kin_HKF_species[i].name0 == "water_liquid") + Kin_HKF_species[i].type = -1; + else + { + species_name0 = Kin_HKF_species[i].name0; + is_load = HKF::HKF_OGS_loadparam(species_name0, type, charge, HKFparam); + + if (is_load == 1) + { + Kin_HKF_species[i].type = type; + Kin_HKF_species[i].charge = charge; + for (ix = 0; ix < 9; ix++) + for (iy = 0; iy < 4; iy++) + Kin_HKF_species[i].param[ix][iy] = HKFparam[ix][iy]; } - else{ - Kin_HKF_species[i].type=-1; - cout << " Warning ... load " << Kin_HKF_species[i].name0 << " parameters failed ... " << "\n" ; + else + { + Kin_HKF_species[i].type = -1; + cout << " Warning ... load " << Kin_HKF_species[i].name0 << " parameters failed ... " + << "\n"; } } } + // is_load=HKF_load_param(spec,name_type,phase_type); - - - - //is_load=HKF_load_param(spec,name_type,phase_type); - - //if(HKF_load_param(spec,name_type,phase_type)==1){ + // if(HKF_load_param(spec,name_type,phase_type)==1){ // cout << " HKF load param...... OK! " << "\n"; // i_counter=0; // for(i=0;iKin_HKF_species.size();i++){ - if(Kin_HKF_species[i].type !=-1){ - HKF::HKF_OGS_calc(T, P, G, H, S, Kin_HKF_species[i].type, Kin_HKF_species[i].charge, Kin_HKF_species[i].param); - //cout << Kin_HKF_species[i].name0 << " " << G << " " << H << " " << S << "\n"; - Kin_HKF_species[i].G=G; - Kin_HKF_species[i].H=H; - Kin_HKF_species[i].S=S; + for (i = 0; i < (int)this->Kin_HKF_species.size(); i++) + { + if (Kin_HKF_species[i].type != -1) + { + HKF::HKF_OGS_calc( + T, P, G, H, S, Kin_HKF_species[i].type, Kin_HKF_species[i].charge, Kin_HKF_species[i].param); + // cout << Kin_HKF_species[i].name0 << " " << G << " " << H << " " << S << "\n"; + Kin_HKF_species[i].G = G; + Kin_HKF_species[i].H = H; + Kin_HKF_species[i].S = S; } - else if(Kin_HKF_species[i].name0=="H2O" || Kin_HKF_species[i].name0=="H2O_liquid" || Kin_HKF_species[i].name0=="water_liquid"){ - Kin_HKF_species[i].G=HKF::HKFcalcw(T, P, 0); - Kin_HKF_species[i].H=HKF::HKFcalcw(T, P, 1); - Kin_HKF_species[i].S=HKF::HKFcalcw(T, P, 2); + else if (Kin_HKF_species[i].name0 == "H2O" || Kin_HKF_species[i].name0 == "H2O_liquid" + || Kin_HKF_species[i].name0 == "water_liquid") + { + Kin_HKF_species[i].G = HKF::HKFcalcw(T, P, 0); + Kin_HKF_species[i].H = HKF::HKFcalcw(T, P, 1); + Kin_HKF_species[i].S = HKF::HKFcalcw(T, P, 2); } - } return sr; } - /**************************************************************************/ /* Global function */ /**************************************************************************/ -bool REACT_CAP_Read(std::string file_base_name, const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name){ - +bool REACT_CAP_Read(std::string file_base_name, const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) +{ char line[MAX_ZEILE]; std::string file_name_cap, line_string; ios::pos_type position; - REACT_CAP *rc_cap = new REACT_CAP(); - // look if file is there + REACT_CAP* rc_cap = new REACT_CAP(); + // look if file is there file_name_cap = file_base_name + REACTION_EXTENSION_CHEMAPP; - ifstream cap_file (file_name_cap.data(),ios::in); - if (!cap_file.good()){ - delete rc_cap; - rc_cap =NULL; + ifstream cap_file(file_name_cap.data(), ios::in); + if (!cap_file.good()) + { + delete rc_cap; + rc_cap = NULL; } - else{ // file is there - use ChemApp - if(REACT_vec.capacity() > 0){ //Test, if PHREEQC is used also - cout << "\n" << " Warning! ChemApp and PHREEQC both actived. ChemApp will NOT be used ! " << "\n"; + else + { // file is there - use ChemApp + if (REACT_vec.capacity() > 0) + { // Test, if PHREEQC is used also + cout << "\n" + << " Warning! ChemApp and PHREEQC both actived. ChemApp will NOT be used ! " + << "\n"; delete rc_cap; - rc_cap =NULL; + rc_cap = NULL; } - else{ + else + { rc_cap->flag_cap = true; // Read input file *.cap cap_file.clear(); - cap_file.seekg(0,ios::beg); - cout << "ChemApp_Read" << "\n"; - cap_file.getline(line,MAX_ZEILE); // first line - cap_file.getline(line,MAX_ZEILE); // second line ToDo + cap_file.seekg(0, ios::beg); + cout << "ChemApp_Read" + << "\n"; + cap_file.getline(line, MAX_ZEILE); // first line + cap_file.getline(line, MAX_ZEILE); // second line ToDo line_string = line; - if(line_string.find("#STOP")!=string::npos) + if (line_string.find("#STOP") != string::npos) return true; // Call the object read function @@ -3028,133 +3615,151 @@ bool REACT_CAP_Read(std::string file_base_name, const GEOLIB::GEOObjects& geo_ob /*********************************************************** Function: REACT_CAP::ConvertIC2BC - Task: - Convert calculated equilibrium values - at all mass transport processes to be used as - boundary condition for the remainsing simulation - at a specified geometry + Task: + Convert calculated equilibrium values + at all mass transport processes to be used as + boundary condition for the remainsing simulation + at a specified geometry - SB 10/2009 First Implementation + SB 10/2009 First Implementation ***********************************************************/ -void REACT_CAP::ConvertIC2BC(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name){ - +void REACT_CAP::ConvertIC2BC(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) +{ double species_value; - int ns=0, i, ii, j, l, ll; + int ns = 0, i, ii, j, l, ll; CRFProcess* m_pcs = NULL; - vector node_nr; + vector node_nr; ns = (int)species_name.size(); std::string s_geo_name, s_geo_type, testname; - vectornodes_vector; + vector nodes_vector; bool replace = false; // Do only if flag is specified - if(this->ic_2_bc_geometry_name.size() > 0){ - - cout << "\n" << "\n" << " => ConvertIC2BC() " << "\n"; + if (this->ic_2_bc_geometry_name.size() > 0) + { + cout << "\n" + << "\n" + << " => ConvertIC2BC() " + << "\n"; // Get nodes at specified geometry - -/********************************************************/ - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt - if(m_msh == NULL) {cout << "ConvertIC2BC" << "\n"; exit(0);} - // Go through specified geometry elements - for(j=0;j<(int)this->ic_2_bc_geometry_name.size();j++){ - s_geo_name = this->ic_2_bc_geometry_name[j]; - s_geo_type = this->ic_2_bc_geometry_type[j]; - //------------------------------------------------------------------ - if(s_geo_type.compare("POINT")==0) - { - // 06/2010 TF switch to new GEOLIB - //CGLPoint* m_geo_point = NULL; // make new GEO point - //m_geo_point = GEOGetPointByName(s_geo_name);//Get GEO point by name - //if(m_geo_point) - // l = m_msh->GetNODOnPNT(m_geo_point); // + ShiftInNodeVector; // find MSH point number stored in l - const std::vector* pnt_vec (geo_obj.getPointVec(unique_name)); - l = m_msh->GetNODOnPNT ((*pnt_vec)[this->ic_2_bc_GeoID[j]]); - node_nr.push_back(l); - } - //------------------------------------------------------------------ - if(s_geo_type.compare("POLYLINE")==0) - { - //CGLPolyline *m_polyline = NULL; - //m_polyline = GEOGetPLYByName(s_geo_name);// get Polyline by name - //CGLPolyline *m_polyline (polyline_vector[this->ic_2_bc_GeoID[j]]); - std::vector const* const ply_vec( - geo_obj.getPolylineVec(unique_name)); - GEOLIB::Polyline const* const m_polyline((*ply_vec)[this->ic_2_bc_GeoID[j]]); - - if(m_polyline) { - //if(m_polyline->getType()==100) //WW - //m_msh->GetNodesOnArc(m_polyline,nodes_vector); - //else - m_msh->GetNODOnPLY(m_polyline,nodes_vector); - for(i=0;i<(long)nodes_vector.size();i++){ - ll = nodes_vector[i]; - l = ll; //+ShiftInNodeVector; - node_nr.push_back(l); - } - } - } // if(POLYLINE) - //------------------------------------------------------------------ - if(s_geo_type.compare("SURFACE")==0) { - Surface *m_surface = NULL; - m_surface = GEOGetSFCByName(s_geo_name); - if(m_surface){ - m_msh->GetNODOnSFC(m_surface,nodes_vector); - for(i=0;i<(long)nodes_vector.size();i++){ - ll = nodes_vector[i]; - l = ll; //+ShiftInNodeVector; - node_nr.push_back(l); - } - } - } - } // end of for(j=0;jNoReactGeoName.size()... - //test output - /* */ cout << " Vector node_nr: " << "\n"; - for(l=0; l< (long)node_nr.size();l++) - cout << " Node number: " << node_nr[l] <<", "; - cout << "\n"; - - - + /********************************************************/ + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt + if (m_msh == NULL) + { + cout << "ConvertIC2BC" + << "\n"; + exit(0); + } + // Go through specified geometry elements + for (j = 0; j < (int)this->ic_2_bc_geometry_name.size(); j++) + { + s_geo_name = this->ic_2_bc_geometry_name[j]; + s_geo_type = this->ic_2_bc_geometry_type[j]; + //------------------------------------------------------------------ + if (s_geo_type.compare("POINT") == 0) + { + // 06/2010 TF switch to new GEOLIB + // CGLPoint* m_geo_point = NULL; // make new GEO point + // m_geo_point = GEOGetPointByName(s_geo_name);//Get GEO point by name + // if(m_geo_point) + // l = m_msh->GetNODOnPNT(m_geo_point); // + ShiftInNodeVector; // find MSH point number stored in l + const std::vector* pnt_vec(geo_obj.getPointVec(unique_name)); + l = m_msh->GetNODOnPNT((*pnt_vec)[this->ic_2_bc_GeoID[j]]); + node_nr.push_back(l); + } + //------------------------------------------------------------------ + if (s_geo_type.compare("POLYLINE") == 0) + { + // CGLPolyline *m_polyline = NULL; + // m_polyline = GEOGetPLYByName(s_geo_name);// get Polyline by name + // CGLPolyline *m_polyline (polyline_vector[this->ic_2_bc_GeoID[j]]); + std::vector const* const ply_vec(geo_obj.getPolylineVec(unique_name)); + GEOLIB::Polyline const* const m_polyline((*ply_vec)[this->ic_2_bc_GeoID[j]]); + + if (m_polyline) + { + // if(m_polyline->getType()==100) //WW + // m_msh->GetNodesOnArc(m_polyline,nodes_vector); + // else + m_msh->GetNODOnPLY(m_polyline, nodes_vector); + for (i = 0; i < (long)nodes_vector.size(); i++) + { + ll = nodes_vector[i]; + l = ll; //+ShiftInNodeVector; + node_nr.push_back(l); + } + } + } // if(POLYLINE) + //------------------------------------------------------------------ + if (s_geo_type.compare("SURFACE") == 0) + { + Surface* m_surface = NULL; + m_surface = GEOGetSFCByName(s_geo_name); + if (m_surface) + { + m_msh->GetNODOnSFC(m_surface, nodes_vector); + for (i = 0; i < (long)nodes_vector.size(); i++) + { + ll = nodes_vector[i]; + l = ll; //+ShiftInNodeVector; + node_nr.push_back(l); + } + } + } + } // end of for(j=0;jNoReactGeoName.size()... + // test output + /* */ cout << " Vector node_nr: " + << "\n"; + for (l = 0; l < (long)node_nr.size(); l++) + cout << " Node number: " << node_nr[l] << ", "; + cout << "\n"; // Transfer simulated value to bc data structure // First get them from results vectors of mass transport processes and store new values in species_value - for(ii=0; ii < (int)node_nr.size(); ii++){ // count through nodes on geometry - for(i=0;ipcs_mass_idx[i]]; - //species_value = m_pcs->GetNodeValue(ii,0); // CB DL todo check, which one is the correct - species_value = m_pcs->GetNodeValue(ii,1); - //check if bc replacement is wanted for this species = process + // species_value = m_pcs->GetNodeValue(ii,0); // CB DL todo check, which one is the correct + species_value = m_pcs->GetNodeValue(ii, 1); + // check if bc replacement is wanted for this species = process replace = false; - for(int jj=0;jj< (int)this->ic_2_bc_species.size();jj++){ + for (int jj = 0; jj < (int)this->ic_2_bc_species.size(); jj++) + { testname = this->ic_2_bc_species[jj]; - if(testname.compare(m_pcs->pcs_primary_function_name[0]) == 0) { + if (testname.compare(m_pcs->pcs_primary_function_name[0]) == 0) + { replace = true; species_value += this->ic_2_bc_species_value[jj]; break; } } - if(ic_2_bc_species.size() == 0) replace = true; + if (ic_2_bc_species.size() == 0) + replace = true; - if(replace){ - cout << " Species : " << setw(4) << this->pcs_mass_idx[i] << " " << setw(16) << m_pcs->pcs_primary_function_name[0] << " "; - // cout << old/new c in m_pcs: " << m_pcs->GetNodeValue(ii,0) <<" / " << m_pcs->GetNodeValue(ii,1) << "\n"; + if (replace) + { + cout << " Species : " << setw(4) << this->pcs_mass_idx[i] << " " << setw(16) + << m_pcs->pcs_primary_function_name[0] << " "; + // cout << old/new c in m_pcs: " << m_pcs->GetNodeValue(ii,0) <<" / " << m_pcs->GetNodeValue(ii,1) + // << "\n"; // Store new value in boundary condition - for(j=0;j< (int) m_pcs->bc_node_value.size();j++){ - if(m_pcs->bc_node_value[j]->msh_node_number == node_nr[ii]){ - cout << " Replaced bc value " << m_pcs->bc_node_value[j]->node_value << " by " << species_value << "\n"; + for (j = 0; j < (int)m_pcs->bc_node_value.size(); j++) + { + if (m_pcs->bc_node_value[j]->msh_node_number == node_nr[ii]) + { + cout << " Replaced bc value " << m_pcs->bc_node_value[j]->node_value << " by " + << species_value << "\n"; pcs_vector[this->pcs_mass_idx[i]]->bc_node_value[j]->node_value = species_value; } } - }// end if(replace) + } // end if(replace) } - }// end for(ii - + } // end for(ii } - } - diff --git a/FEM/rf_react_cap.h b/FEM/rf_react_cap.h index 69446d54c..355b9d655 100644 --- a/FEM/rf_react_cap.h +++ b/FEM/rf_react_cap.h @@ -7,164 +7,164 @@ * */ - /* reaction package header file */ +/* reaction package header file */ //#ifndef reaction_INC //#define reactions_INC #include -//using namespace std; +// using namespace std; -//CB2406 #ifdef OGS_FEM_CAP // CAP_REACT +// CB2406 #ifdef OGS_FEM_CAP // CAP_REACT /* Structure for exchange of reaction rates */ -class REACT_CAP{ - private: - public: - REACT_CAP(void); // Initialize - ~REACT_CAP(void); // Clean up - -// Data - int *rateflag; /* flag used for determining if reaction are calculated */ - long nodenumber; /* number of nodes, on which reactions are calculated */ - bool flag_cap; /* flag if *.cap file exists DL 28,10,08*/ - std::string data_file; +class REACT_CAP +{ +private: +public: + REACT_CAP(void); // Initialize + ~REACT_CAP(void); // Clean up + + // Data + int* rateflag; /* flag used for determining if reaction are calculated */ + long nodenumber; /* number of nodes, on which reactions are calculated */ + bool flag_cap; /* flag if *.cap file exists DL 28,10,08*/ + std::string data_file; std::string data_format; - int mass_num; + int mass_num; std::string mass_type; std::string species_define; - std::vector pcs_mass_idx; //index of mass_trans order-number in processes list, (some other process are not mass transport) - std::vector pcs_ospecies_idx; //index of output species order-number in processes list 21.01.2009 - std::vector pcs_nspecies_idx; //index of nlog-output species order-number in processes list 02.02.2009 - std::vector nspecies_idx; //index of nlog-output species order-number in NLOG_AC list - - std::vector phase_list; - std::vector phase_post; - - std::vector species_list_name; //From .cap list section, species name - std::vector species_list_phase;//From .cap list section, phase flag for species 0-solid, 1-gas, 2-aqueous - std::vector species_list_idx; //From .cap list section, index of species in ChemApp DATA file - - std::vector species_name; // From Process, list of species name for chemical reaction - std::vector species_phase; // From Process, phase flag for species 0-solid, 1-gas, 2-aqueous - std::vector species_idx; // From Process, index of species in ChemApp DATA file - std::vector species_mobil; // From Process, process mobile - std::vector species_dormant;// From KINETIC_SPECIES, 0-equilibrium 1-kinetic - - std::vector species_kin_name; //DL 03.2010 - std::vector species_kin_phase;// - std::vector species_kin_idx; // - - std::vector species_relative_activity_name; //DL 03.2013 - std::vector species_relative_activity_idx; + std::vector + pcs_mass_idx; // index of mass_trans order-number in processes list, (some other process are not mass transport) + std::vector pcs_ospecies_idx; // index of output species order-number in processes list 21.01.2009 + std::vector pcs_nspecies_idx; // index of nlog-output species order-number in processes list 02.02.2009 + std::vector nspecies_idx; // index of nlog-output species order-number in NLOG_AC list + + std::vector phase_list; + std::vector phase_post; + + std::vector species_list_name; // From .cap list section, species name + std::vector species_list_phase; // From .cap list section, phase flag for species 0-solid, 1-gas, 2-aqueous + std::vector species_list_idx; // From .cap list section, index of species in ChemApp DATA file + + std::vector species_name; // From Process, list of species name for chemical reaction + std::vector species_phase; // From Process, phase flag for species 0-solid, 1-gas, 2-aqueous + std::vector species_idx; // From Process, index of species in ChemApp DATA file + std::vector species_mobil; // From Process, process mobile + std::vector species_dormant; // From KINETIC_SPECIES, 0-equilibrium 1-kinetic + + std::vector species_kin_name; // DL 03.2010 + std::vector species_kin_phase; // + std::vector species_kin_idx; // + + std::vector species_relative_activity_name; // DL 03.2013 + std::vector species_relative_activity_idx; std::vector species_relative_activity_idx_pcs; - std::vector species_relative_activity, species_relative_activity_ia,species_relative_activity_calc; - std::vector species_relative_activity_state; + std::vector species_relative_activity, species_relative_activity_ia, species_relative_activity_calc; + std::vector species_relative_activity_state; - std::vector Node_All_SI; + std::vector Node_All_SI; bool show_data_file; - std::vector pcs_rename0, pcs_rename0_pre; + std::vector pcs_rename0, pcs_rename0_pre; std::vector > pcs_rename1, pcs_rename1_pre; - std::vector > pcs_rename_stoi, pcs_rename_stoi_pre; - std::vector pcs_rename_idx0, pcs_rename_idx0_pre; - std::vector > pcs_rename_idx1, pcs_rename_idx1_pre; + std::vector > pcs_rename_stoi, pcs_rename_stoi_pre; + std::vector pcs_rename_idx0, pcs_rename_idx0_pre; + std::vector > pcs_rename_idx1, pcs_rename_idx1_pre; int current_node; // for Kin Reaction calc double current_TT, current_PP; // for Kin Reaction calc typedef struct { - std::string type; - double logK; - double rate; - std::vector species_name; - std::vector species_phase; + std::string type; + double logK; + double rate; + std::vector species_name; + std::vector species_phase; std::vector species_idx; - std::vector species_stoi; - //for Kinetic reaction - bool is_Kin; - int logK_type; + std::vector species_stoi; + // for Kinetic reaction + bool is_Kin; + int logK_type; double logK_kin; double theta; double eta; double SA; double PF; - std::vector EA; - std::vector K25; - std::vector ref_species; - std::vector ref_idx; // position in mass trans list --> node_ac matrix - std::vector ref_expo; - }reaction; + std::vector EA; + std::vector K25; + std::vector ref_species; + std::vector ref_idx; // position in mass trans list --> node_ac matrix + std::vector ref_expo; + } reaction; reaction React; std::vector Kin_Reactions, Kin_HKF_Reactions; - std::vector Kin_HKF_index; //look up table between Reactions and HKF_Species + std::vector Kin_HKF_index; // look up table between Reactions and HKF_Species typedef struct { - //input - std::string name0; //name in Helgeson datafile - //from datafile + // input + std::string name0; // name in Helgeson datafile + // from datafile std::string name; - std::string abbrev; //abbreviation - std::string scform; //structural chemical formula - std::string ecform; //elemental chemical formula + std::string abbrev; // abbreviation + std::string scform; // structural chemical formula + std::string ecform; // elemental chemical formula std::string ref[2]; - double charge; //charge - int type ; //phase flag - //0-minerals that do not undergo phase transitions - //1-minerals that undergo one phase transition - //2-minerals that undergo two phase transitions - //3-minerals that undergo three phase transitions - //4-gases - //5-aqueous species - double param[9][4]; //parameters - //calculating result - double S; //entropy - double H; //enthalpy - double G; //Gibbs free energy - double V; //volume - double Cp;//heat capacity - }SpeciesData; - + double charge; // charge + int type; // phase flag + // 0-minerals that do not undergo phase transitions + // 1-minerals that undergo one phase transition + // 2-minerals that undergo two phase transitions + // 3-minerals that undergo three phase transitions + // 4-gases + // 5-aqueous species + double param[9][4]; // parameters + // calculating result + double S; // entropy + double H; // enthalpy + double G; // Gibbs free energy + double V; // volume + double Cp; // heat capacity + } SpeciesData; std::vector > node_logK; // node, reaction - std::vector > node_ac; // node, spec + std::vector > node_ac; // node, spec std::vector Kin_HKF_species; std::vector > node_HKF_logK; - - std::vector nlog_name; //correspond name with pcs and nlog - std::vector species_nlog_name; //use .cap to define -log(ac) value - std::vector species_nlog_phase; + std::vector nlog_name; // correspond name with pcs and nlog + std::vector species_nlog_name; // use .cap to define -log(ac) value + std::vector species_nlog_phase; std::vector species_nlog_idx; int pcs_redox; - std::vector species_redox_name; - std::vector species_redox_phase; + std::vector species_redox_name; + std::vector species_redox_phase; std::vector species_redox_idx; - std::vector redox_stoi; + std::vector redox_stoi; bool check_no_reaction_nodes; /* flag if CheckNoReactionNodes has been performed */ -// double temperature; /* temperature of water at node as specified in input file */ -// int heatflag; /* if 1, heat transport is active and passed to phreeqc */ - std::vector ic_2_bc_geometry_type; // Convert eq concentrations at this gemetry to BC there - std::vector ic_2_bc_geometry_name; - std::vector ic_2_bc_GeoID; - - std::vector ic_2_bc_species; - std::vector ic_2_bc_species_value; - /** - * @param geo_obj object of class GEOObjects managing the geometric entities - * @param unique_name unique name to access the geometric entities in geo_obj - */ + // double temperature; /* temperature of water at node as specified in input file */ + // int heatflag; /* if 1, heat transport is active and passed to phreeqc */ + std::vector ic_2_bc_geometry_type; // Convert eq concentrations at this gemetry to BC there + std::vector ic_2_bc_geometry_name; + std::vector ic_2_bc_GeoID; + + std::vector ic_2_bc_species; + std::vector ic_2_bc_species_value; + /** + * @param geo_obj object of class GEOObjects managing the geometric entities + * @param unique_name unique name to access the geometric entities in geo_obj + */ void ConvertIC2BC(const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name); std::ofstream warning_out; -// Member functions + // Member functions -/** - * @param geo_obj object of class GEOObjects managing the geometric entities - * @param unique_name unique name to access the geometric entities in geo_obj - */ + /** + * @param geo_obj object of class GEOObjects managing the geometric entities + * @param unique_name unique name to access the geometric entities in geo_obj + */ std::ios::pos_type Read(std::ifstream*, const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name); void CreateREACT(void); @@ -183,12 +183,12 @@ class REACT_CAP{ bool CmpSpeciesListPCS(void); bool CmpSpeciesListNLOG(void); bool CmpSpeciesListREDOX(void); - bool CmpSpeciesListKinReact(void); //DL 03.2010 - bool CmpSpeciesListKIN(void); //DL 03.2010 + bool CmpSpeciesListKinReact(void); // DL 03.2010 + bool CmpSpeciesListKIN(void); // DL 03.2010 bool CmpSpeciesListRelativeActivity(void); // DL 04.2013 - bool SetKinHKFspecies(void); //DL 11.2010 + bool SetKinHKFspecies(void); // DL 11.2010 bool LoadHKFparam(void); bool HKFcalc(double T, double P); @@ -196,25 +196,24 @@ class REACT_CAP{ void CompNamePhase(std::string, char*&, int&); - int CheckNoReactionNodes(void); + int CheckNoReactionNodes(void); void LoopNodeReact(int, int); - std::vector KineticReact(std::vector); //DL 05.10.10 - void KinInit(void); - void KinRate(void); - std::vector derivs(std::vector); //DL 05.10.10 - std::vector ODE(std::vector, std::vector, int, double); - void KinParamUpdata(int, int, std::vector & spvc); - void KinParamUpdataHKF(int,double T, double P, int err); + std::vector KineticReact(std::vector); // DL 05.10.10 + void KinInit(void); + void KinRate(void); + std::vector derivs(std::vector); // DL 05.10.10 + std::vector ODE(std::vector, std::vector, int, double); + void KinParamUpdata(int, int, std::vector& spvc); + void KinParamUpdataHKF(int, double T, double P, int err); void LoopNodeReact_Liquid_Vapor(int, int); void LoopNodeReact_Liquid_Solid(int, int); - void ExecuteReactionsChemApp(int, int); //DL 28,10,08 + void ExecuteReactionsChemApp(int, int); // DL 28,10,08 void ShowDataFile(void); void SetAllSolidAsDormant(void); - }; -extern std::vector REACT_CAP_vec; +extern std::vector REACT_CAP_vec; extern bool REACT_CAP_Read(std::string, const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name); #ifdef OGS_FEM_CAP // CAP_REACT diff --git a/FEM/rf_react_int.cpp b/FEM/rf_react_int.cpp index 09cd9847c..b3dd9953b 100644 --- a/FEM/rf_react_int.cpp +++ b/FEM/rf_react_int.cpp @@ -7,10 +7,10 @@ * */ - /* - rf_react_int.cpp - Reaction interface - */ +/* + rf_react_int.cpp + Reaction interface +*/ #include "rf_react_int.h" #include "display.h" @@ -40,69 +40,63 @@ #include "Density.h" #include "VLE.h" - - #include using namespace std; extern double gravity_constant; -vector REACTINT_vec; - +vector REACTINT_vec; /**************************************************************************/ // REACINT class /**************************************************************************/ - - /************************************************************************** ReacInt-Method: Task: Constructor Programing: //CB 01.2011 CB First implementation **************************************************************************/ -REACTINT::REACTINT(void){ - - unitconversion = false; - constantdensity = true; - constanttemperature = true; - constantpressure = true; - c_TT = 298.15; // std conditions 25°C - c_PP = 1.0; // std conditions 1 bar - ssp_outstep = -1; - pcs_outstep = -1; - dump_min_moles = false; - dump_all_pcs = false; - dump_mass_integrals = false; - s_water_limit = false; - WaterSatLimit = 0.0; - WaterSpeciesName = "NULL"; - NeutralCO2name = "NULL"; - SodiumSpeciesName = "NULL"; - icOutput = false; - icSolidUpdate = false; - readNodePoro = false; - vle_flag = false; - pcs_rename_init_flag = false; - pcs_rename_pre_flag = false; - pcs_rename_post_flag = false; - poroupdate_flag = false; - heatpump_2DhTO2Dv = false; - heatpump_Z = -9999; - //0-Li, 1-Na, 2-K, 3-Mg, 4-Ca, 5-Cl, 6-SO4, 7-CO3 - //double mv[8]; - //mv[0]=0; mv[1]=2.71; mv[2]=0; mv[3]=0; mv[4]=0; mv[5]=2.71; mv[6]=0; mv[7]=0; - //double test = Density_CO2brine(393.15, 202, 2.71, 0.0); - //test = Density_CO2_MultiBrine(393.15, 202, mv, 0); - this->node_porosity.clear(); - this->node_ini_porosity.clear(); - this->water_conc.clear(); - this->water_conc_species.clear(); - this->sp_varind.clear(); - //this->sp_pcsind.clear(); - this->Temp_store.clear(); - Temp_GHP_mapidx.clear(); - +REACTINT::REACTINT(void) +{ + unitconversion = false; + constantdensity = true; + constanttemperature = true; + constantpressure = true; + c_TT = 298.15; // std conditions 25°C + c_PP = 1.0; // std conditions 1 bar + ssp_outstep = -1; + pcs_outstep = -1; + dump_min_moles = false; + dump_all_pcs = false; + dump_mass_integrals = false; + s_water_limit = false; + WaterSatLimit = 0.0; + WaterSpeciesName = "NULL"; + NeutralCO2name = "NULL"; + SodiumSpeciesName = "NULL"; + icOutput = false; + icSolidUpdate = false; + readNodePoro = false; + vle_flag = false; + pcs_rename_init_flag = false; + pcs_rename_pre_flag = false; + pcs_rename_post_flag = false; + poroupdate_flag = false; + heatpump_2DhTO2Dv = false; + heatpump_Z = -9999; + // 0-Li, 1-Na, 2-K, 3-Mg, 4-Ca, 5-Cl, 6-SO4, 7-CO3 + // double mv[8]; + // mv[0]=0; mv[1]=2.71; mv[2]=0; mv[3]=0; mv[4]=0; mv[5]=2.71; mv[6]=0; mv[7]=0; + // double test = Density_CO2brine(393.15, 202, 2.71, 0.0); + // test = Density_CO2_MultiBrine(393.15, 202, mv, 0); + this->node_porosity.clear(); + this->node_ini_porosity.clear(); + this->water_conc.clear(); + this->water_conc_species.clear(); + this->sp_varind.clear(); + // this->sp_pcsind.clear(); + this->Temp_store.clear(); + Temp_GHP_mapidx.clear(); } /************************************************************************** ReacInt-Method: @@ -110,7 +104,8 @@ REACTINT::REACTINT(void){ Programing: //CB 01.2011 CB First implementation **************************************************************************/ -REACTINT::~REACTINT(void){ +REACTINT::~REACTINT(void) +{ } /************************************************************************** @@ -119,49 +114,54 @@ REACTINT::~REACTINT(void){ Programing: //CB 01.2011 CB First implementation **************************************************************************/ -bool REACINTRead(string file_base_name){ - - char line[MAX_ZEILE]; - string sub_line; - string line_string; - string rei_file_name; - ios::pos_type position; - string m_name, sp_name; - - //======================================================================== - // File handling - rei_file_name = file_base_name + REI_FILE_EXTENSION; - ifstream rei_file (rei_file_name.data(),ios::in); - if (!rei_file.good()) - return false; - - REACTINT *m_rei = NULL; - - rei_file.seekg(0L,ios::beg); // rewind? - //======================================================================== - // Keyword loop - cout << "REIRead" << "\n"; - while (!rei_file.eof()) { - rei_file.getline(line,MAX_ZEILE); - line_string = line; - if(line_string.find("#STOP")!=string::npos) - break; - //---------------------------------------------------------------------- - if(line_string.find("#REACTION_INTERFACE")!=string::npos) { // keyword found // set up object - m_rei = new REACTINT(); - m_rei->Read(&rei_file); - REACTINT_vec.push_back(m_rei); - } // keyword found - } // eof - // Close input file - rei_file.close(); - - if(!m_rei){ - cout << " No keyword #REACTION_INTERFACE specified - setting defaults" << "\n"; - m_rei = new REACTINT(); - REACTINT_vec.push_back(m_rei); - } - return true; +bool REACINTRead(string file_base_name) +{ + char line[MAX_ZEILE]; + string sub_line; + string line_string; + string rei_file_name; + ios::pos_type position; + string m_name, sp_name; + + //======================================================================== + // File handling + rei_file_name = file_base_name + REI_FILE_EXTENSION; + ifstream rei_file(rei_file_name.data(), ios::in); + if (!rei_file.good()) + return false; + + REACTINT* m_rei = NULL; + + rei_file.seekg(0L, ios::beg); // rewind? + //======================================================================== + // Keyword loop + cout << "REIRead" + << "\n"; + while (!rei_file.eof()) + { + rei_file.getline(line, MAX_ZEILE); + line_string = line; + if (line_string.find("#STOP") != string::npos) + break; + //---------------------------------------------------------------------- + if (line_string.find("#REACTION_INTERFACE") != string::npos) + { // keyword found // set up object + m_rei = new REACTINT(); + m_rei->Read(&rei_file); + REACTINT_vec.push_back(m_rei); + } // keyword found + } // eof + // Close input file + rei_file.close(); + + if (!m_rei) + { + cout << " No keyword #REACTION_INTERFACE specified - setting defaults" + << "\n"; + m_rei = new REACTINT(); + REACTINT_vec.push_back(m_rei); + } + return true; } /************************************************************************** @@ -170,339 +170,387 @@ bool REACINTRead(string file_base_name){ Programing: //CB 01.2011 CB First implementation **************************************************************************/ -bool REACTINT::Read(ifstream *rfd_file) +bool REACTINT::Read(ifstream* rfd_file) { - char line[MAX_ZEILE]; - string dummystring, speciesname; - string line_string, line_str1; - bool new_keyword = false, new_subkeyword = false; - string hash("#"), dollar("$"); - std::stringstream in; - long index, index1; - double temp = 0; - - //for pcs rename - std::vector pcs_name; - std::vector pcs_stoi; - std::string line_str2, ncomp_x; - int j; - VLE_type condition, condition_p; - VLE_conditions.clear(); - VLE_pressure.clear(); - - - //======================================================================== - while (!new_keyword) { - index = rfd_file->tellg(); - if(!GetLineFromFile(line,rfd_file)) - break; - line_string = line; - if(line_string.find(hash)!=string::npos) { - new_keyword = true; - rfd_file->seekg(index); //Dateipointer zurücksetzen, sonst ist das nächste keyword weg - break; - } - /* Keywords nacheinander durchsuchen */ - //.................................................................... - if(line_string.find("$MOL_PER")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> dummystring ; - if(dummystring.compare("VOLUME")==0) - unitconversion = true; - else if(dummystring.compare("WEIGHT")==0) - unitconversion = false; - else - cout << " Warning in REACTINT::Read - No valid keyword for $MOL_PER (unit conversions)." << "\n"; - in.clear(); - } - if(line_string.find("$WATER_CONCENTRATION")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> dummystring ; - in.clear(); - if(dummystring.compare("CONSTANT")==0) - constantdensity = true; - else if(dummystring.compare("VARIABLE")==0){ - constantdensity = false; - // Now read water concentration species list - - while(!new_subkeyword){ - index1 = rfd_file->tellg(); - line_str1 = GetLineFromFile1(rfd_file); - // Check for end of data block - if((line_str1.find(hash)!=string::npos) || (line_str1.find(dollar)!=string::npos)) { - if(line_str1.find(hash)!=string::npos) - new_keyword = true; - rfd_file->seekg(index1); //Dateipointer zurücksetzen, sonst ist das nächste subkeyword weg - break; - } - // Here, read individual species data - in.str(line_str1); - in >> speciesname ; - if(speciesname.compare("NIX")!=0){ //check for read in - water_conc_species.push_back(speciesname); - // store in osme vector - speciesname = "NIX"; - } - else - DisplayMsgLn(" ERROR reading Water concentration relevant Species - skipping"); - in.clear(); - } - - } - else - cout << " Warning in REACTINT::Read - No valid keyword for $WATER_CONCENTRATION." << "\n"; - } - // water species name - if(line_string.find("$WATER_SPECIES_NAME")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> WaterSpeciesName ; - in.clear(); - } - // co2 species name - if(line_string.find("$DISSOLVED_NEUTRAL_CO2_SPECIES_NAME")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> NeutralCO2name ; - in.clear(); - } - if(line_string.find("$SODIUM_SPECIES_NAME")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> SodiumSpeciesName ; - in.clear(); - } - if(line_string.find("$PRESSURE")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> dummystring >> temp; - if(dummystring.compare("CONSTANT")==0){ - constantpressure = true; - c_PP = temp; - } - else if(dummystring.compare("VARIABLE")==0) - constantpressure = false; - else - cout << " Warning in REACTINT::Read - No valid keyword for $PRESSURE." << "\n"; - in.clear(); - } - if(line_string.find("$TEMPERATURE")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> dummystring >> temp; - if(dummystring.compare("CONSTANT")==0){ - constanttemperature = true; - c_TT = temp; - } - else if(dummystring.compare("VARIABLE")==0) - constanttemperature = false; - else - cout << " Warning in REACTINT::Read - No valid keyword for $TEMPERATURE." << "\n"; - in.clear(); - } - if(line_string.find("$WATER_SATURATION_LIMIT")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> this->WaterSatLimit ; - s_water_limit = true; - in.clear(); - } - if(line_string.find("$RESIDUAL")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> dummystring ; - if(dummystring.compare("RECORD")==0) - residual_back = true; - else if(dummystring.compare("REMOVE")==0) - residual_back = false; - else - cout << " Warning in REACTINT::Read - No valid keyword for $RESIDUAL (for equilibrium reaction input value)." << "\n"; - in.clear(); - } - if(line_string.find("$SOLID_SPECIES_DUMP_MOLES")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> this->ssp_outstep ; - dump_min_moles = true; - in.clear(); - } - if(line_string.find("$ALL_PCS_DUMP")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> this->pcs_outstep ; - dump_all_pcs = true; - in.clear(); - } - if(line_string.find("$INITIAL_CONDITION_OUTPUT")!=string::npos) { // subkeyword found - icOutput = true; - } - if(line_string.find("$UPDATE_INITIAL_SOLID_COMPOSITION")!=string::npos) { // subkeyword found - icSolidUpdate = true; - } - if(line_string.find("$VLE")!=string::npos){ // subkeyword found - vle_flag = true; - cout << " VLE load..." << "\n"; - in.str(GetLineFromFile1(rfd_file)); - in >> ncomp_x; condition.vp_name=ncomp_x; - in >> ncomp_x; condition.aq_name=ncomp_x; - in.clear(); - this->VLE_conditions.push_back(condition); - } - - if(line_string.find("$P_VLE")!=string::npos){ // subkeyword found - vle_p_flag = true; - cout << " P_VLE load..." << "\n"; - in.str(GetLineFromFile1(rfd_file)); - in >> ncomp_x; condition_p.vp_name=ncomp_x; - in >> ncomp_x; condition_p.aq_name=ncomp_x; - in.clear(); - this->VLE_pressure.push_back(condition_p); - } - - if(line_string.find("$POROSITY_RESTART")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> this->porofile ; - readNodePoro = true; - in.clear(); - } - if(line_string.find("$HEATPUMP_2DH_TO_2DV")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> heatpump_Z; - in.clear(); - heatpump_2DhTO2Dv = true; - } - - //for pcs rename init, pre, post position - if(line_string.find("$PCS_RENAME_INIT")!=string::npos){ // subkeyword found - pcs_rename_init_flag = true; - this->pcs_rename0_init.clear(); - this->pcs_rename1_init.clear(); - this->pcs_rename1_stoi_init.clear(); - this->pow_stoi_init.clear(); - while(1){ - pcs_name.clear(); - pcs_stoi.clear(); + char line[MAX_ZEILE]; + string dummystring, speciesname; + string line_string, line_str1; + bool new_keyword = false, new_subkeyword = false; + string hash("#"), dollar("$"); + std::stringstream in; + long index, index1; + double temp = 0; + + // for pcs rename + std::vector pcs_name; + std::vector pcs_stoi; + std::string line_str2, ncomp_x; + int j; + VLE_type condition, condition_p; + VLE_conditions.clear(); + VLE_pressure.clear(); + + //======================================================================== + while (!new_keyword) + { + index = rfd_file->tellg(); + if (!GetLineFromFile(line, rfd_file)) + break; + line_string = line; + if (line_string.find(hash) != string::npos) + { + new_keyword = true; + rfd_file->seekg(index); // Dateipointer zurücksetzen, sonst ist das nächste keyword weg + break; + } + /* Keywords nacheinander durchsuchen */ + //.................................................................... + if (line_string.find("$MOL_PER") != string::npos) + { // subkeyword found in.str(GetLineFromFile1(rfd_file)); - line_str2=in.str(); - in >> ncomp_x; - if(!ncomp_x.find("END")) { - in.clear(); - break; - } - this->pcs_rename0_init.push_back(ncomp_x); - for(j=1;j<(int)string2vector(line_str2).size();j+=2){ - in >> ncomp_x; - if(ncomp_x=="*") - pcs_stoi.push_back(999999); - else if(ncomp_x=="/") - pcs_stoi.push_back(-999999); - else if(ncomp_x=="exp") - pcs_stoi.push_back(-999998); - else if(ncomp_x=="log") - pcs_stoi.push_back(-999997); - else if(ncomp_x=="log10") - pcs_stoi.push_back(-999996); - else if(ncomp_x=="delta") - pcs_stoi.push_back(-999990); - else if(ncomp_x.substr(0,3)=="pow"){ - pcs_stoi.push_back(-999995); - this->pow_stoi_init.push_back((double)atof(ncomp_x.substr(3).c_str())); + in >> dummystring; + if (dummystring.compare("VOLUME") == 0) + unitconversion = true; + else if (dummystring.compare("WEIGHT") == 0) + unitconversion = false; + else + cout << " Warning in REACTINT::Read - No valid keyword for $MOL_PER (unit conversions)." + << "\n"; + in.clear(); + } + if (line_string.find("$WATER_CONCENTRATION") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> dummystring; + in.clear(); + if (dummystring.compare("CONSTANT") == 0) + constantdensity = true; + else if (dummystring.compare("VARIABLE") == 0) + { + constantdensity = false; + // Now read water concentration species list + + while (!new_subkeyword) + { + index1 = rfd_file->tellg(); + line_str1 = GetLineFromFile1(rfd_file); + // Check for end of data block + if ((line_str1.find(hash) != string::npos) || (line_str1.find(dollar) != string::npos)) + { + if (line_str1.find(hash) != string::npos) + new_keyword = true; + rfd_file->seekg(index1); // Dateipointer zurücksetzen, sonst ist das nächste subkeyword weg + break; + } + // Here, read individual species data + in.str(line_str1); + in >> speciesname; + if (speciesname.compare("NIX") != 0) + { // check for read in + water_conc_species.push_back(speciesname); + // store in osme vector + speciesname = "NIX"; + } + else + DisplayMsgLn(" ERROR reading Water concentration relevant Species - skipping"); + in.clear(); } - else - pcs_stoi.push_back((double)atof(ncomp_x.c_str())); - in >> ncomp_x; - pcs_name.push_back(ncomp_x); } - this->pcs_rename1_init.push_back(pcs_name); - this->pcs_rename1_stoi_init.push_back(pcs_stoi); + else + cout << " Warning in REACTINT::Read - No valid keyword for $WATER_CONCENTRATION." + << "\n"; + } + // water species name + if (line_string.find("$WATER_SPECIES_NAME") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> WaterSpeciesName; in.clear(); } - } - if(line_string.find("$PCS_RENAME_PRE")!=string::npos){ // subkeyword found - pcs_rename_pre_flag = true; - this->pcs_rename0_pre.clear(); - this->pcs_rename1_pre.clear(); - this->pcs_rename1_stoi_pre.clear(); - while(1){ - pcs_name.clear(); - pcs_stoi.clear(); + // co2 species name + if (line_string.find("$DISSOLVED_NEUTRAL_CO2_SPECIES_NAME") != string::npos) + { // subkeyword found in.str(GetLineFromFile1(rfd_file)); - line_str2=in.str(); - in >> ncomp_x; - if(!ncomp_x.find("END")) { - in.clear(); - break; + in >> NeutralCO2name; + in.clear(); + } + if (line_string.find("$SODIUM_SPECIES_NAME") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> SodiumSpeciesName; + in.clear(); + } + if (line_string.find("$PRESSURE") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> dummystring >> temp; + if (dummystring.compare("CONSTANT") == 0) + { + constantpressure = true; + c_PP = temp; } - this->pcs_rename0_pre.push_back(ncomp_x); - for(j=1;j<(int)string2vector(line_str2).size();j+=2){ - in >> ncomp_x; - if(ncomp_x=="*") - pcs_stoi.push_back(999999); - else if(ncomp_x=="/") - pcs_stoi.push_back(-999999); - else if(ncomp_x=="exp") - pcs_stoi.push_back(-999998); - else if(ncomp_x=="log") - pcs_stoi.push_back(-999997); - else if(ncomp_x=="log10") - pcs_stoi.push_back(-999996); - else if(ncomp_x=="delta") - pcs_stoi.push_back(-999990); - else if(ncomp_x.substr(0,3)=="pow"){ - pcs_stoi.push_back(-999995); - this->pow_stoi_pre.push_back((double)atof(ncomp_x.substr(3).c_str())); - } - else - pcs_stoi.push_back((double)atof(ncomp_x.c_str())); - in >> ncomp_x; - pcs_name.push_back(ncomp_x); + else if (dummystring.compare("VARIABLE") == 0) + constantpressure = false; + else + cout << " Warning in REACTINT::Read - No valid keyword for $PRESSURE." + << "\n"; + in.clear(); + } + if (line_string.find("$TEMPERATURE") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> dummystring >> temp; + if (dummystring.compare("CONSTANT") == 0) + { + constanttemperature = true; + c_TT = temp; } - this->pcs_rename1_pre.push_back(pcs_name); - this->pcs_rename1_stoi_pre.push_back(pcs_stoi); + else if (dummystring.compare("VARIABLE") == 0) + constanttemperature = false; + else + cout << " Warning in REACTINT::Read - No valid keyword for $TEMPERATURE." + << "\n"; in.clear(); } - } - if(line_string.find("$PCS_RENAME_POST")!=string::npos){ // subkeyword found - pcs_rename_post_flag = true; - this->pcs_rename0_post.clear(); - this->pcs_rename1_post.clear(); - this->pcs_rename1_stoi_post.clear(); - while(1){ - pcs_name.clear(); - pcs_stoi.clear(); + if (line_string.find("$WATER_SATURATION_LIMIT") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> this->WaterSatLimit; + s_water_limit = true; + in.clear(); + } + if (line_string.find("$RESIDUAL") != string::npos) + { // subkeyword found in.str(GetLineFromFile1(rfd_file)); - line_str2=in.str(); + in >> dummystring; + if (dummystring.compare("RECORD") == 0) + residual_back = true; + else if (dummystring.compare("REMOVE") == 0) + residual_back = false; + else + cout << " Warning in REACTINT::Read - No valid keyword for $RESIDUAL (for equilibrium reaction input " + "value)." + << "\n"; + in.clear(); + } + if (line_string.find("$SOLID_SPECIES_DUMP_MOLES") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> this->ssp_outstep; + dump_min_moles = true; + in.clear(); + } + if (line_string.find("$ALL_PCS_DUMP") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> this->pcs_outstep; + dump_all_pcs = true; + in.clear(); + } + if (line_string.find("$INITIAL_CONDITION_OUTPUT") != string::npos) + { // subkeyword found + icOutput = true; + } + if (line_string.find("$UPDATE_INITIAL_SOLID_COMPOSITION") != string::npos) + { // subkeyword found + icSolidUpdate = true; + } + if (line_string.find("$VLE") != string::npos) + { // subkeyword found + vle_flag = true; + cout << " VLE load..." + << "\n"; + in.str(GetLineFromFile1(rfd_file)); + in >> ncomp_x; + condition.vp_name = ncomp_x; + in >> ncomp_x; + condition.aq_name = ncomp_x; + in.clear(); + this->VLE_conditions.push_back(condition); + } + + if (line_string.find("$P_VLE") != string::npos) + { // subkeyword found + vle_p_flag = true; + cout << " P_VLE load..." + << "\n"; + in.str(GetLineFromFile1(rfd_file)); + in >> ncomp_x; + condition_p.vp_name = ncomp_x; in >> ncomp_x; - if(!ncomp_x.find("END")) { + condition_p.aq_name = ncomp_x; + in.clear(); + this->VLE_pressure.push_back(condition_p); + } + + if (line_string.find("$POROSITY_RESTART") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> this->porofile; + readNodePoro = true; + in.clear(); + } + if (line_string.find("$HEATPUMP_2DH_TO_2DV") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> heatpump_Z; + in.clear(); + heatpump_2DhTO2Dv = true; + } + + // for pcs rename init, pre, post position + if (line_string.find("$PCS_RENAME_INIT") != string::npos) + { // subkeyword found + pcs_rename_init_flag = true; + this->pcs_rename0_init.clear(); + this->pcs_rename1_init.clear(); + this->pcs_rename1_stoi_init.clear(); + this->pow_stoi_init.clear(); + while (1) + { + pcs_name.clear(); + pcs_stoi.clear(); + in.str(GetLineFromFile1(rfd_file)); + line_str2 = in.str(); + in >> ncomp_x; + if (!ncomp_x.find("END")) + { + in.clear(); + break; + } + this->pcs_rename0_init.push_back(ncomp_x); + for (j = 1; j < (int)string2vector(line_str2).size(); j += 2) + { + in >> ncomp_x; + if (ncomp_x == "*") + pcs_stoi.push_back(999999); + else if (ncomp_x == "/") + pcs_stoi.push_back(-999999); + else if (ncomp_x == "exp") + pcs_stoi.push_back(-999998); + else if (ncomp_x == "log") + pcs_stoi.push_back(-999997); + else if (ncomp_x == "log10") + pcs_stoi.push_back(-999996); + else if (ncomp_x == "delta") + pcs_stoi.push_back(-999990); + else if (ncomp_x.substr(0, 3) == "pow") + { + pcs_stoi.push_back(-999995); + this->pow_stoi_init.push_back((double)atof(ncomp_x.substr(3).c_str())); + } + else + pcs_stoi.push_back((double)atof(ncomp_x.c_str())); + in >> ncomp_x; + pcs_name.push_back(ncomp_x); + } + this->pcs_rename1_init.push_back(pcs_name); + this->pcs_rename1_stoi_init.push_back(pcs_stoi); in.clear(); - break; } - this->pcs_rename0_post.push_back(ncomp_x); - for(j=1;j<(int)string2vector(line_str2).size();j+=2){ + } + if (line_string.find("$PCS_RENAME_PRE") != string::npos) + { // subkeyword found + pcs_rename_pre_flag = true; + this->pcs_rename0_pre.clear(); + this->pcs_rename1_pre.clear(); + this->pcs_rename1_stoi_pre.clear(); + while (1) + { + pcs_name.clear(); + pcs_stoi.clear(); + in.str(GetLineFromFile1(rfd_file)); + line_str2 = in.str(); in >> ncomp_x; - if(ncomp_x=="*") - pcs_stoi.push_back(999999); - else if(ncomp_x=="/") - pcs_stoi.push_back(-999999); - else if(ncomp_x=="exp") - pcs_stoi.push_back(-999998); - else if(ncomp_x=="log") - pcs_stoi.push_back(-999997); - else if(ncomp_x=="log10") - pcs_stoi.push_back(-999996); - else if(ncomp_x=="delta") - pcs_stoi.push_back(-999990); - else if(ncomp_x.substr(0,3)=="pow"){ - pcs_stoi.push_back(-999995); - this->pow_stoi_post.push_back((double)atof(ncomp_x.substr(3).c_str())); + if (!ncomp_x.find("END")) + { + in.clear(); + break; } - else - pcs_stoi.push_back((double)atof(ncomp_x.c_str())); + this->pcs_rename0_pre.push_back(ncomp_x); + for (j = 1; j < (int)string2vector(line_str2).size(); j += 2) + { + in >> ncomp_x; + if (ncomp_x == "*") + pcs_stoi.push_back(999999); + else if (ncomp_x == "/") + pcs_stoi.push_back(-999999); + else if (ncomp_x == "exp") + pcs_stoi.push_back(-999998); + else if (ncomp_x == "log") + pcs_stoi.push_back(-999997); + else if (ncomp_x == "log10") + pcs_stoi.push_back(-999996); + else if (ncomp_x == "delta") + pcs_stoi.push_back(-999990); + else if (ncomp_x.substr(0, 3) == "pow") + { + pcs_stoi.push_back(-999995); + this->pow_stoi_pre.push_back((double)atof(ncomp_x.substr(3).c_str())); + } + else + pcs_stoi.push_back((double)atof(ncomp_x.c_str())); + in >> ncomp_x; + pcs_name.push_back(ncomp_x); + } + this->pcs_rename1_pre.push_back(pcs_name); + this->pcs_rename1_stoi_pre.push_back(pcs_stoi); + in.clear(); + } + } + if (line_string.find("$PCS_RENAME_POST") != string::npos) + { // subkeyword found + pcs_rename_post_flag = true; + this->pcs_rename0_post.clear(); + this->pcs_rename1_post.clear(); + this->pcs_rename1_stoi_post.clear(); + while (1) + { + pcs_name.clear(); + pcs_stoi.clear(); + in.str(GetLineFromFile1(rfd_file)); + line_str2 = in.str(); in >> ncomp_x; - pcs_name.push_back(ncomp_x); + if (!ncomp_x.find("END")) + { + in.clear(); + break; + } + this->pcs_rename0_post.push_back(ncomp_x); + for (j = 1; j < (int)string2vector(line_str2).size(); j += 2) + { + in >> ncomp_x; + if (ncomp_x == "*") + pcs_stoi.push_back(999999); + else if (ncomp_x == "/") + pcs_stoi.push_back(-999999); + else if (ncomp_x == "exp") + pcs_stoi.push_back(-999998); + else if (ncomp_x == "log") + pcs_stoi.push_back(-999997); + else if (ncomp_x == "log10") + pcs_stoi.push_back(-999996); + else if (ncomp_x == "delta") + pcs_stoi.push_back(-999990); + else if (ncomp_x.substr(0, 3) == "pow") + { + pcs_stoi.push_back(-999995); + this->pow_stoi_post.push_back((double)atof(ncomp_x.substr(3).c_str())); + } + else + pcs_stoi.push_back((double)atof(ncomp_x.c_str())); + in >> ncomp_x; + pcs_name.push_back(ncomp_x); + } + this->pcs_rename1_post.push_back(pcs_name); + this->pcs_rename1_stoi_post.push_back(pcs_stoi); + in.clear(); } - this->pcs_rename1_post.push_back(pcs_name); - this->pcs_rename1_stoi_post.push_back(pcs_stoi); - in.clear(); } } - } - return true; + return true; } - - /************************************************************************** ReacInt-Method: Task: return the ReacInt object @@ -511,11 +559,11 @@ bool REACTINT::Read(ifstream *rfd_file) **************************************************************************/ REACTINT* REACTINT::GetREACTINT(void) { - REACTINT *rei = NULL; - /* Tests */ - if(REACTINT_vec.capacity() > 0) - rei = REACTINT_vec[0]; - return rei; + REACTINT* rei = NULL; + /* Tests */ + if (REACTINT_vec.capacity() > 0) + rei = REACTINT_vec[0]; + return rei; } /************************************************************************** @@ -528,384 +576,454 @@ REACTINT* REACTINT::GetREACTINT(void) Programing: //CB 01.2011 CB First implementation **************************************************************************/ -void REACTINT::InitREACTINT(void){ - - long i,j; - double poro = 0; - int nc = (int)cp_vec.size(); - vector id; - string sp_name; - int idx;//,idummy - - // cout << VLE_solubility_CO2(398, 17.5, 6.5272E+00); - - - if(icOutput) - OUTData(0.0,aktueller_zeitschritt, true); - - //CompProperties *m_cp = NULL; - CRFProcess *m_pcs = NULL; - CFEMesh* m_msh = fem_msh_vector[0]; - long nnodes = (long) m_msh->nod_vector.size(); - - m_pcs = PCSGetFlow(); - flowtype = m_pcs->type; - - // for all mass transport processes, false: copy oldTL->newTL - CopyAllConcentrationsToOtherTimeLevel(false); - - // AB & CB - // Porosity & permeability preprocessing function - SetInitialPorosityAndPermToElementValue(); - - // set up vector for nodal porosities - for(i=0;ireadNodePoro) - ReadRestartNodePoro(nnodes); - - // set up and initialize vector for water concentration - - CFluidProperties* m_mfp = NULL; - m_mfp = MFPGet( "LIQUID" ); - double variables[3]; - variables[0]=variables[1]=variables[2]=0; - switch(m_mfp->density_model){ - case 0: // rho = f(x) - break; - case 1: // rho = const - break; - case 2: // rho(p) = rho_0*(1+beta_p*(p-p_0)) - variables[0] = GetPressure(0); - break; - case 3: // rho(C) = rho_0*(1+beta_C*(C-C_0)) - //variables[2] = GetConcentration(0); - break; - case 4: // rho(T) = rho_0*(1+beta_T*(T-T_0)) - variables[1] = GetTemperature(0); - break; - case 5: // rho(C,T) = rho_0*(1+beta_C*(C-C_0)+beta_T*(T-T_0)) - variables[1] = GetTemperature(0); - //variables[2] = GetConcentration(0); - break; - case 6: // rho(p,T) = rho_0*(1+beta_p*(p-p_0)+beta_T*(T-T_0)) - variables[0] = GetPressure(0); - variables[1] = GetTemperature(0); - break; - case 7: // Pefect gas. WW - break; - case 8: // M14 von JdJ // 25.1.12 Added by CB for density output AB-model - variables[0] = GetPressure(0); - variables[1] = GetTemperature(0); - //variables[2] = GetConcentration(0); - break; - default: - std::cout << "Density in ReactInt: no valid model" << "\n"; - break; - } - double dens = m_mfp->Density(variables); - if(unitconversion) - for(i=0;icompname; - //idummy = -1; - //m_pcs = PCSGet("MASS_TRANSPORT",sp_name);// CB HS update - m_pcs = cp_vec[cp_name_2_idx[sp_name]]->getProcess(); - if(m_pcs != NULL){ - //idummy = PCSGetPCSIndex("MASS_TRANSPORT",sp_name); - //sp_pcsind.push_back(idummy); - idx = m_pcs->GetNodeValueIndex(sp_name)+1; // new timelevel - sp_varind.push_back(idx); - } - } - //} - - if(unitconversion ){ - if(constantdensity == false){ - for(j=0;j<10;j++) id.push_back(0); - // set up and initialize matrix for water concentration computation - for(i=0;icompname.compare(water_conc_species[j])==0 && cp_vec[i]->transport_phase==0 ) {// species found - if(cp_vec[i]->iupac_formula[0]) // a formula has been defined - id=formula2index(cp_vec[i]->iupac_formula); - else // otherwise use species name directly. attention, this could result in wrong concentration of basis species!!! - id=formula2index(cp_vec[i]->compname); - break; // skip the rest of water_conc_species vector - } - } - - // Test - if(cp_vec[i]->iupac_formula[0]) cout << cp_vec[i]->iupac_formula << ": " << "\n"; - else cout << cp_vec[i]->compname << ": " << "\n"; - for(j=0;j<(int)id.size();j++) cout << " " << j ; cout << "\n"; - for(j=0;j<(int)id.size();j++) cout << " " << id[j]; cout << "\n"; - - // now store the id vector - ElementInSpecies.push_back(id); - } - } - // this should be called as well after transport and before any reaction calculations - // necessary here as well for calculation of initial equilibrium - CalcWaterConc(); - } // if(unitconversion) - - // prepare vector for reaction deactivation due to dry out from eclipse - if(s_water_limit && WaterSatLimit>0) - for(i=0;iVLE_conditions.size());i++){ - cond=0; - for(j=0;j<(int)pcs_vector.size();j++){ - if(pcs_vector[j]->pcs_primary_function_name[0] == VLE_conditions[i].aq_name){ - VLE_conditions[i].aq_idx=j; - cout << " " << VLE_conditions[i].aq_name; - cond=1; - } - } - if(cond==0){ - cout << " VLE aq_name is not a pcs name " << "\n"; - exit(0); - } - cond=0; - for(j=0;j<(int)pcs_vector.size();j++){ - if(pcs_vector[j]->pcs_primary_function_name[0] == VLE_conditions[i].vp_name){ - VLE_conditions[i].vp_idx=j; - cout << " " << VLE_conditions[i].vp_name; - cond=1; - } - } - if(cond==0){ - cout << " VLE vp_name is not a pcs name " << "\n"; - exit(0); - } - cout << "\n"; - } - } - - -//DL 2013.5.10 for VLE pressure conditions, set aq_idx and vp_idx - if(vle_p_flag == true){ - cout << " VLE_P " << "\n"; - int cond; - for(i=0;i<(long)this->VLE_pressure.size();i++){ - cond=0; - for(j=0;j<(int)pcs_vector.size();j++){ - if(pcs_vector[j]->pcs_primary_function_name[0] == VLE_pressure[i].aq_name){ - VLE_pressure[i].aq_idx=j; - cout << " " << VLE_pressure[i].aq_name; - cond=1; - } - } - if(cond==0){ - cout << " VLE_P aq_name is not a pcs name " << "\n"; - exit(0); - } - cond=0; - for(j=0;j<(int)pcs_vector.size();j++){ - if(pcs_vector[j]->pcs_primary_function_name[0] == VLE_pressure[i].vp_name){ - VLE_pressure[i].vp_idx=j; - cout << " " << VLE_pressure[i].vp_name; - cond=1; - } - } - if(cond==0){ - cout << " VLE_P vp_name is not a pcs name " << "\n"; - exit(0); - } - cout << "\n"; - } - } -//==================================== - - - - -//DL 2011.10.05 for pcs rename operation - int ii, ix, jx, is_idx, no_pcs; +void REACTINT::InitREACTINT(void) +{ + long i, j; + double poro = 0; + int nc = (int)cp_vec.size(); + vector id; + string sp_name; + int idx; //,idummy + + // cout << VLE_solubility_CO2(398, 17.5, 6.5272E+00); + + if (icOutput) + OUTData(0.0, aktueller_zeitschritt, true); + + // CompProperties *m_cp = NULL; + CRFProcess* m_pcs = NULL; + CFEMesh* m_msh = fem_msh_vector[0]; + long nnodes = (long)m_msh->nod_vector.size(); + + m_pcs = PCSGetFlow(); + flowtype = m_pcs->type; + + // for all mass transport processes, false: copy oldTL->newTL + CopyAllConcentrationsToOtherTimeLevel(false); + + // AB & CB + // Porosity & permeability preprocessing function + SetInitialPorosityAndPermToElementValue(); + + // set up vector for nodal porosities + for (i = 0; i < nnodes; i++) + { + poro = GetNodePhaseVolume(i, 0, 0); + node_porosity.push_back(poro); + node_ini_porosity.push_back(poro); + } + + if (this->readNodePoro) + ReadRestartNodePoro(nnodes); + + // set up and initialize vector for water concentration + + CFluidProperties* m_mfp = NULL; + m_mfp = MFPGet("LIQUID"); + double variables[3]; + variables[0] = variables[1] = variables[2] = 0; + switch (m_mfp->density_model) + { + case 0: // rho = f(x) + break; + case 1: // rho = const + break; + case 2: // rho(p) = rho_0*(1+beta_p*(p-p_0)) + variables[0] = GetPressure(0); + break; + case 3: // rho(C) = rho_0*(1+beta_C*(C-C_0)) + // variables[2] = GetConcentration(0); + break; + case 4: // rho(T) = rho_0*(1+beta_T*(T-T_0)) + variables[1] = GetTemperature(0); + break; + case 5: // rho(C,T) = rho_0*(1+beta_C*(C-C_0)+beta_T*(T-T_0)) + variables[1] = GetTemperature(0); + // variables[2] = GetConcentration(0); + break; + case 6: // rho(p,T) = rho_0*(1+beta_p*(p-p_0)+beta_T*(T-T_0)) + variables[0] = GetPressure(0); + variables[1] = GetTemperature(0); + break; + case 7: // Pefect gas. WW + break; + case 8: // M14 von JdJ // 25.1.12 Added by CB for density output AB-model + variables[0] = GetPressure(0); + variables[1] = GetTemperature(0); + // variables[2] = GetConcentration(0); + break; + default: + std::cout << "Density in ReactInt: no valid model" + << "\n"; + break; + } + double dens = m_mfp->Density(variables); + if (unitconversion) + for (i = 0; i < nnodes; i++) + water_conc.push_back(MOLH2OPERKG * dens); + + // set up vectors sp_pcs and sp_varind, taken from KinReactData + // if(unitconversion){ + for (i = 0; i < nc; i++) + { + sp_name = cp_vec[i]->compname; + // idummy = -1; + // m_pcs = PCSGet("MASS_TRANSPORT",sp_name);// CB HS update + m_pcs = cp_vec[cp_name_2_idx[sp_name]]->getProcess(); + if (m_pcs != NULL) + { + // idummy = PCSGetPCSIndex("MASS_TRANSPORT",sp_name); + // sp_pcsind.push_back(idummy); + idx = m_pcs->GetNodeValueIndex(sp_name) + 1; // new timelevel + sp_varind.push_back(idx); + } + } + //} + + if (unitconversion) + { + if (constantdensity == false) + { + for (j = 0; j < 10; j++) + id.push_back(0); + // set up and initialize matrix for water concentration computation + for (i = 0; i < nc; i++) + { // set the species relevant for water concentration + for (j = 0; j < (int)id.size(); j++) + id[j] = 0; + // search in list, if species is relevant + for (j = 0; j < int(water_conc_species.size()); j++) + { + if (cp_vec[i]->compname.compare(water_conc_species[j]) == 0 && cp_vec[i]->transport_phase == 0) + { // species found + if (cp_vec[i]->iupac_formula[0]) // a formula has been defined + id = formula2index(cp_vec[i]->iupac_formula); + else // otherwise use species name directly. attention, this could result in wrong concentration + // of basis species!!! + id = formula2index(cp_vec[i]->compname); + break; // skip the rest of water_conc_species vector + } + } + + // Test + if (cp_vec[i]->iupac_formula[0]) + cout << cp_vec[i]->iupac_formula << ": " + << "\n"; + else + cout << cp_vec[i]->compname << ": " + << "\n"; + for (j = 0; j < (int)id.size(); j++) + cout << " " << j; + cout << "\n"; + for (j = 0; j < (int)id.size(); j++) + cout << " " << id[j]; + cout << "\n"; + + // now store the id vector + ElementInSpecies.push_back(id); + } + } + // this should be called as well after transport and before any reaction calculations + // necessary here as well for calculation of initial equilibrium + CalcWaterConc(); + } // if(unitconversion) + + // prepare vector for reaction deactivation due to dry out from eclipse + if (s_water_limit && WaterSatLimit > 0) + for (i = 0; i < nnodes; i++) + dried_out_nodes.push_back(false); // initialize for eclipse coupling + + // clean up + id.clear(); + // DL 2012.2.17 for VLE conditions, set aq_idx and vp_idx + if (vle_flag == true) + { + cout << " VLE " + << "\n"; + int cond; + for (i = 0; i < long(this->VLE_conditions.size()); i++) + { + cond = 0; + for (j = 0; j < (int)pcs_vector.size(); j++) + { + if (pcs_vector[j]->pcs_primary_function_name[0] == VLE_conditions[i].aq_name) + { + VLE_conditions[i].aq_idx = j; + cout << " " << VLE_conditions[i].aq_name; + cond = 1; + } + } + if (cond == 0) + { + cout << " VLE aq_name is not a pcs name " + << "\n"; + exit(0); + } + cond = 0; + for (j = 0; j < (int)pcs_vector.size(); j++) + { + if (pcs_vector[j]->pcs_primary_function_name[0] == VLE_conditions[i].vp_name) + { + VLE_conditions[i].vp_idx = j; + cout << " " << VLE_conditions[i].vp_name; + cond = 1; + } + } + if (cond == 0) + { + cout << " VLE vp_name is not a pcs name " + << "\n"; + exit(0); + } + cout << "\n"; + } + } + + // DL 2013.5.10 for VLE pressure conditions, set aq_idx and vp_idx + if (vle_p_flag == true) + { + cout << " VLE_P " + << "\n"; + int cond; + for (i = 0; i < (long)this->VLE_pressure.size(); i++) + { + cond = 0; + for (j = 0; j < (int)pcs_vector.size(); j++) + { + if (pcs_vector[j]->pcs_primary_function_name[0] == VLE_pressure[i].aq_name) + { + VLE_pressure[i].aq_idx = j; + cout << " " << VLE_pressure[i].aq_name; + cond = 1; + } + } + if (cond == 0) + { + cout << " VLE_P aq_name is not a pcs name " + << "\n"; + exit(0); + } + cond = 0; + for (j = 0; j < (int)pcs_vector.size(); j++) + { + if (pcs_vector[j]->pcs_primary_function_name[0] == VLE_pressure[i].vp_name) + { + VLE_pressure[i].vp_idx = j; + cout << " " << VLE_pressure[i].vp_name; + cond = 1; + } + } + if (cond == 0) + { + cout << " VLE_P vp_name is not a pcs name " + << "\n"; + exit(0); + } + cout << "\n"; + } + } + //==================================== + + // DL 2011.10.05 for pcs rename operation + int ii, ix, jx, is_idx, no_pcs; double value; vector idx_tmp; - no_pcs = (int)pcs_vector.size(); - - if(pcs_rename_init_flag == true) { - cout << "\n" << " PCS_RENAME_INIT " << "\n"; - this->pcs_rename0_idx_init.clear(); - this->pcs_rename1_idx_init.clear(); - for(j=0;j<(int)pcs_rename0_init.size();j++){ - idx_tmp.clear(); - for(jx=0;jx<(int)pcs_rename1_init[j].size();jx++) - idx_tmp.push_back(-1); - pcs_rename1_idx_init.push_back(idx_tmp); - pcs_rename0_idx_init.push_back(-1); - } - for(i=0;ipcs_primary_function_name[0] == pcs_rename0_init[j]) - pcs_rename0_idx_init[j]=i; - for(jx=0;jx<(int)pcs_rename1_init[j].size();jx++) - if(m_pcs->pcs_primary_function_name[0] == pcs_rename1_init[j][jx]) - pcs_rename1_idx_init[j][jx]=i; - } - } - for(i=0;i<(int)pcs_rename0_init.size();i++){ - is_idx=1; - if(pcs_rename0_idx_init[i]==-1) - is_idx=0; - for(jx=0;jx<(int)pcs_rename1_init[i].size();jx++) - if(pcs_rename1_idx_init[i][jx]==-1) - is_idx=0; - if(is_idx==0){ - cout << " Warning!!!, line " << i+1 << " can not be found in PCS list ! " << "\n"; - exit(0); - } - cout << " " << setw(12) << pcs_rename0_init[i] << " <--- "; - for(jx=0;jx<(int)pcs_rename1_init[i].size();jx++) - cout << " " << pcs_rename1_stoi_init[i][jx] << " " << pcs_rename1_init[i][jx]; - cout << "\n"; - } - } - - - if(pcs_rename_pre_flag == true) { - cout << "\n" << " PCS_RENAME_PRE " << "\n"; - this->pcs_rename0_idx_pre.clear(); - this->pcs_rename1_idx_pre.clear(); - for(j=0;j<(int)pcs_rename0_pre.size();j++){ - idx_tmp.clear(); - for(jx=0;jx<(int)pcs_rename1_pre[j].size();jx++) - idx_tmp.push_back(-1); - pcs_rename1_idx_pre.push_back(idx_tmp); - pcs_rename0_idx_pre.push_back(-1); - } - for(i=0;ipcs_primary_function_name[0] == pcs_rename0_pre[j]) - pcs_rename0_idx_pre[j]=i; - for(jx=0;jx<(int)pcs_rename1_pre[j].size();jx++) - if(m_pcs->pcs_primary_function_name[0] == pcs_rename1_pre[j][jx]) - pcs_rename1_idx_pre[j][jx]=i; - } - } - for(i=0;i<(int)pcs_rename0_pre.size();i++){ - is_idx=1; - if(pcs_rename0_idx_pre[i]==-1) - is_idx=0; - for(jx=0;jx<(int)pcs_rename1_pre[i].size();jx++) - if(pcs_rename1_idx_pre[i][jx]==-1) - is_idx=0; - if(is_idx==0){ - cout << " Warning!!!, line " << i+1 << " can not be found in PCS list ! " << "\n"; - exit(0); - } - cout << " " << setw(12) << pcs_rename0_pre[i] << " <--- "; - for(jx=0;jx<(int)pcs_rename1_pre[i].size();jx++) - cout << " " << pcs_rename1_stoi_pre[i][jx] << " " << pcs_rename1_pre[i][jx]; - cout << "\n"; - } - } - - - if(pcs_rename_post_flag == true) { - cout << "\n" << " PCS_RENAME_POST " << "\n"; - this->pcs_rename0_idx_post.clear(); - this->pcs_rename1_idx_post.clear(); - for(j=0;j<(int)pcs_rename0_post.size();j++){ - idx_tmp.clear(); - for(jx=0;jx<(int)pcs_rename1_post[j].size();jx++) - idx_tmp.push_back(-1); - pcs_rename1_idx_post.push_back(idx_tmp); - pcs_rename0_idx_post.push_back(-1); - } - for(i=0;ipcs_primary_function_name[0] == pcs_rename0_post[j]) - pcs_rename0_idx_post[j]=i; - for(jx=0;jx<(int)pcs_rename1_post[j].size();jx++) - if(m_pcs->pcs_primary_function_name[0] == pcs_rename1_post[j][jx]) - pcs_rename1_idx_post[j][jx]=i; - } - } - for(i=0;i<(int)pcs_rename0_post.size();i++){ - is_idx=1; - if(pcs_rename0_idx_post[i]==-1) - is_idx=0; - for(jx=0;jx<(int)pcs_rename1_post[i].size();jx++) - if(pcs_rename1_idx_post[i][jx]==-1) - is_idx=0; - if(is_idx==0){ - cout << " Warning!!!, line " << i+1 << " can not be found in PCS list ! " << "\n"; - exit(0); - } - cout << " " << setw(12) << pcs_rename0_post[i] << " <--- "; - for(jx=0;jx<(int)pcs_rename1_post[i].size();jx++) - cout << " " << pcs_rename1_stoi_post[i][jx] << " " << pcs_rename1_post[i][jx]; - cout << "\n"; - } - } - - for(i=0;ipcs_rename0_idx_init.clear(); + this->pcs_rename1_idx_init.clear(); + for (j = 0; j < (int)pcs_rename0_init.size(); j++) + { + idx_tmp.clear(); + for (jx = 0; jx < (int)pcs_rename1_init[j].size(); jx++) + idx_tmp.push_back(-1); + pcs_rename1_idx_init.push_back(idx_tmp); + pcs_rename0_idx_init.push_back(-1); + } + for (i = 0; i < no_pcs; i++) + { + m_pcs = pcs_vector[i]; + for (j = 0; j < (int)pcs_rename0_init.size(); j++) + { + if (m_pcs->pcs_primary_function_name[0] == pcs_rename0_init[j]) + pcs_rename0_idx_init[j] = i; + for (jx = 0; jx < (int)pcs_rename1_init[j].size(); jx++) + if (m_pcs->pcs_primary_function_name[0] == pcs_rename1_init[j][jx]) + pcs_rename1_idx_init[j][jx] = i; + } + } + for (i = 0; i < (int)pcs_rename0_init.size(); i++) + { + is_idx = 1; + if (pcs_rename0_idx_init[i] == -1) + is_idx = 0; + for (jx = 0; jx < (int)pcs_rename1_init[i].size(); jx++) + if (pcs_rename1_idx_init[i][jx] == -1) + is_idx = 0; + if (is_idx == 0) + { + cout << " Warning!!!, line " << i + 1 << " can not be found in PCS list ! " + << "\n"; + exit(0); + } + cout << " " << setw(12) << pcs_rename0_init[i] << " <--- "; + for (jx = 0; jx < (int)pcs_rename1_init[i].size(); jx++) + cout << " " << pcs_rename1_stoi_init[i][jx] << " " << pcs_rename1_init[i][jx]; + cout << "\n"; + } + } + + if (pcs_rename_pre_flag == true) + { + cout << "\n" + << " PCS_RENAME_PRE " + << "\n"; + this->pcs_rename0_idx_pre.clear(); + this->pcs_rename1_idx_pre.clear(); + for (j = 0; j < (int)pcs_rename0_pre.size(); j++) + { + idx_tmp.clear(); + for (jx = 0; jx < (int)pcs_rename1_pre[j].size(); jx++) + idx_tmp.push_back(-1); + pcs_rename1_idx_pre.push_back(idx_tmp); + pcs_rename0_idx_pre.push_back(-1); + } + for (i = 0; i < no_pcs; i++) + { + m_pcs = pcs_vector[i]; + for (j = 0; j < (int)pcs_rename0_pre.size(); j++) + { + if (m_pcs->pcs_primary_function_name[0] == pcs_rename0_pre[j]) + pcs_rename0_idx_pre[j] = i; + for (jx = 0; jx < (int)pcs_rename1_pre[j].size(); jx++) + if (m_pcs->pcs_primary_function_name[0] == pcs_rename1_pre[j][jx]) + pcs_rename1_idx_pre[j][jx] = i; + } + } + for (i = 0; i < (int)pcs_rename0_pre.size(); i++) + { + is_idx = 1; + if (pcs_rename0_idx_pre[i] == -1) + is_idx = 0; + for (jx = 0; jx < (int)pcs_rename1_pre[i].size(); jx++) + if (pcs_rename1_idx_pre[i][jx] == -1) + is_idx = 0; + if (is_idx == 0) + { + cout << " Warning!!!, line " << i + 1 << " can not be found in PCS list ! " + << "\n"; + exit(0); + } + cout << " " << setw(12) << pcs_rename0_pre[i] << " <--- "; + for (jx = 0; jx < (int)pcs_rename1_pre[i].size(); jx++) + cout << " " << pcs_rename1_stoi_pre[i][jx] << " " << pcs_rename1_pre[i][jx]; + cout << "\n"; + } + } + + if (pcs_rename_post_flag == true) + { + cout << "\n" + << " PCS_RENAME_POST " + << "\n"; + this->pcs_rename0_idx_post.clear(); + this->pcs_rename1_idx_post.clear(); + for (j = 0; j < (int)pcs_rename0_post.size(); j++) + { + idx_tmp.clear(); + for (jx = 0; jx < (int)pcs_rename1_post[j].size(); jx++) + idx_tmp.push_back(-1); + pcs_rename1_idx_post.push_back(idx_tmp); + pcs_rename0_idx_post.push_back(-1); + } + for (i = 0; i < no_pcs; i++) + { + m_pcs = pcs_vector[i]; + for (j = 0; j < (int)pcs_rename0_post.size(); j++) + { + if (m_pcs->pcs_primary_function_name[0] == pcs_rename0_post[j]) + pcs_rename0_idx_post[j] = i; + for (jx = 0; jx < (int)pcs_rename1_post[j].size(); jx++) + if (m_pcs->pcs_primary_function_name[0] == pcs_rename1_post[j][jx]) + pcs_rename1_idx_post[j][jx] = i; + } + } + for (i = 0; i < (int)pcs_rename0_post.size(); i++) + { + is_idx = 1; + if (pcs_rename0_idx_post[i] == -1) + is_idx = 0; + for (jx = 0; jx < (int)pcs_rename1_post[i].size(); jx++) + if (pcs_rename1_idx_post[i][jx] == -1) + is_idx = 0; + if (is_idx == 0) + { + cout << " Warning!!!, line " << i + 1 << " can not be found in PCS list ! " + << "\n"; + exit(0); + } + cout << " " << setw(12) << pcs_rename0_post[i] << " <--- "; + for (jx = 0; jx < (int)pcs_rename1_post[i].size(); jx++) + cout << " " << pcs_rename1_stoi_post[i][jx] << " " << pcs_rename1_post[i][jx]; + cout << "\n"; + } + } + + for (i = 0; i < no_pcs; i++) + { m_pcs = pcs_vector[i]; - if(m_pcs->getProcessType()==FiniteElement::MASS_TRANSPORT){ - this->nodenumber = (long) m_pcs->m_msh->GetNodesNumber(false); + if (m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) + { + this->nodenumber = (long)m_pcs->m_msh->GetNodesNumber(false); // elenumber = (long) m_pcs->m_msh->ele_vector.size(); } } - if(pcs_rename_init_flag == true){ - int f=1, ic; - //return pcs rename init, do rename operation - for(ii=0;iinodenumber;ii++){ //node loop - ic=0; - for(i=0;i<(int)pcs_rename0_idx_init.size();i++){ - value=0.0; - for(ix=0;ix<(int)pcs_rename1_idx_init[i].size();ix++){ - m_pcs= pcs_vector[pcs_rename1_idx_init[i][ix]]; - if(pcs_rename1_stoi_init[i][ix]==999999) - value *= m_pcs->GetNodeValue(ii,f); - else if(pcs_rename1_stoi_init[i][ix]==-999999) - value /= m_pcs->GetNodeValue(ii,f); - else if(pcs_rename1_stoi_init[i][ix]==-999998) - value += exp(m_pcs->GetNodeValue(ii,f)); - else if(pcs_rename1_stoi_init[i][ix]==-999997) - value += log(m_pcs->GetNodeValue(ii,f)); - else if(pcs_rename1_stoi_init[i][ix]==-999996) - value += log10(m_pcs->GetNodeValue(ii,f)); - else if(pcs_rename1_stoi_init[i][ix]==-999990) - value += m_pcs->GetNodeValue(ii,f)-m_pcs->GetNodeValue(ii,0); - else if(pcs_rename1_stoi_init[i][ix]==-999995){ - value += pow(m_pcs->GetNodeValue(ii,f), this->pow_stoi_init[ic]); - ic ++; - } - else - value += m_pcs->GetNodeValue(ii,f) *pcs_rename1_stoi_init[i][ix]; - } - m_pcs= pcs_vector[pcs_rename0_idx_init[i]]; - m_pcs->SetNodeValue(ii,f,value); - } - } - } - - this->t_step=0; + if (pcs_rename_init_flag == true) + { + int f = 1, ic; + // return pcs rename init, do rename operation + for (ii = 0; ii < this->nodenumber; ii++) + { // node loop + ic = 0; + for (i = 0; i < (int)pcs_rename0_idx_init.size(); i++) + { + value = 0.0; + for (ix = 0; ix < (int)pcs_rename1_idx_init[i].size(); ix++) + { + m_pcs = pcs_vector[pcs_rename1_idx_init[i][ix]]; + if (pcs_rename1_stoi_init[i][ix] == 999999) + value *= m_pcs->GetNodeValue(ii, f); + else if (pcs_rename1_stoi_init[i][ix] == -999999) + value /= m_pcs->GetNodeValue(ii, f); + else if (pcs_rename1_stoi_init[i][ix] == -999998) + value += exp(m_pcs->GetNodeValue(ii, f)); + else if (pcs_rename1_stoi_init[i][ix] == -999997) + value += log(m_pcs->GetNodeValue(ii, f)); + else if (pcs_rename1_stoi_init[i][ix] == -999996) + value += log10(m_pcs->GetNodeValue(ii, f)); + else if (pcs_rename1_stoi_init[i][ix] == -999990) + value += m_pcs->GetNodeValue(ii, f) - m_pcs->GetNodeValue(ii, 0); + else if (pcs_rename1_stoi_init[i][ix] == -999995) + { + value += pow(m_pcs->GetNodeValue(ii, f), this->pow_stoi_init[ic]); + ic++; + } + else + value += m_pcs->GetNodeValue(ii, f) * pcs_rename1_stoi_init[i][ix]; + } + m_pcs = pcs_vector[pcs_rename0_idx_init[i]]; + m_pcs->SetNodeValue(ii, f, value); + } + } + } + this->t_step = 0; } /************************************************************************** @@ -915,47 +1033,53 @@ void REACTINT::InitREACTINT(void){ Programing: //CB 01.2011 CB First implementation **************************************************************************/ -void REACTINT::ReactionPreProcessing(void){ - if(unitconversion) - CalcWaterConc(); - if(s_water_limit && WaterSatLimit>0) - CheckForDriedOutNodes(); - - //return pcs rename pre, do rename operation - int i, ii, ix, f=1, ic; +void REACTINT::ReactionPreProcessing(void) +{ + if (unitconversion) + CalcWaterConc(); + if (s_water_limit && WaterSatLimit > 0) + CheckForDriedOutNodes(); + + // return pcs rename pre, do rename operation + int i, ii, ix, f = 1, ic; double value; - CRFProcess *m_pcs = NULL; - if (pcs_rename_pre_flag == true){ - for(ii=0;iinodenumber;ii++){ //node loop - ic=0; - for(i=0;i<(int)pcs_rename0_idx_pre.size();i++){ - value=0.0; - for(ix=0;ix<(int)pcs_rename1_idx_pre[i].size();ix++){ - m_pcs= pcs_vector[pcs_rename1_idx_pre[i][ix]]; - if(pcs_rename1_stoi_pre[i][ix]==999999) - value *= m_pcs->GetNodeValue(ii,f); - else if(pcs_rename1_stoi_pre[i][ix]==-999999) - value /= m_pcs->GetNodeValue(ii,f); - else if(pcs_rename1_stoi_pre[i][ix]==-999998) - value += exp(m_pcs->GetNodeValue(ii,f)); - else if(pcs_rename1_stoi_pre[i][ix]==-999997) - value += log(m_pcs->GetNodeValue(ii,f)); - else if(pcs_rename1_stoi_pre[i][ix]==-999996) - value += log10(m_pcs->GetNodeValue(ii,f)); - else if(pcs_rename1_stoi_pre[i][ix]==-999990) - value += m_pcs->GetNodeValue(ii,f)-m_pcs->GetNodeValue(ii,0); - else if(pcs_rename1_stoi_pre[i][ix]==-999995){ - value += pow(m_pcs->GetNodeValue(ii,f), this->pow_stoi_pre[ic]); - ic ++; - } - else - value += m_pcs->GetNodeValue(ii,f) *pcs_rename1_stoi_pre[i][ix]; - } - m_pcs= pcs_vector[pcs_rename0_idx_pre[i]]; - m_pcs->SetNodeValue(ii,f,value); - } - } - } + CRFProcess* m_pcs = NULL; + if (pcs_rename_pre_flag == true) + { + for (ii = 0; ii < this->nodenumber; ii++) + { // node loop + ic = 0; + for (i = 0; i < (int)pcs_rename0_idx_pre.size(); i++) + { + value = 0.0; + for (ix = 0; ix < (int)pcs_rename1_idx_pre[i].size(); ix++) + { + m_pcs = pcs_vector[pcs_rename1_idx_pre[i][ix]]; + if (pcs_rename1_stoi_pre[i][ix] == 999999) + value *= m_pcs->GetNodeValue(ii, f); + else if (pcs_rename1_stoi_pre[i][ix] == -999999) + value /= m_pcs->GetNodeValue(ii, f); + else if (pcs_rename1_stoi_pre[i][ix] == -999998) + value += exp(m_pcs->GetNodeValue(ii, f)); + else if (pcs_rename1_stoi_pre[i][ix] == -999997) + value += log(m_pcs->GetNodeValue(ii, f)); + else if (pcs_rename1_stoi_pre[i][ix] == -999996) + value += log10(m_pcs->GetNodeValue(ii, f)); + else if (pcs_rename1_stoi_pre[i][ix] == -999990) + value += m_pcs->GetNodeValue(ii, f) - m_pcs->GetNodeValue(ii, 0); + else if (pcs_rename1_stoi_pre[i][ix] == -999995) + { + value += pow(m_pcs->GetNodeValue(ii, f), this->pow_stoi_pre[ic]); + ic++; + } + else + value += m_pcs->GetNodeValue(ii, f) * pcs_rename1_stoi_pre[i][ix]; + } + m_pcs = pcs_vector[pcs_rename0_idx_pre[i]]; + m_pcs->SetNodeValue(ii, f, value); + } + } + } return; } @@ -967,62 +1091,69 @@ void REACTINT::ReactionPreProcessing(void){ Programing: //CB 01.2011 CB First implementation **************************************************************************/ -void REACTINT::ReactionPostProcessing(bool initial){ - - int i, ii, ix, f=1, ic; - double value; - CRFProcess *m_pcs = NULL; - - if(initial) // only after initial reactions, i.e. before first real time step - this->CopyAllConcentrationsToOtherTimeLevel(true); - else { - // CopySymmetricConcentrationsInRadialModel(); - if(poroupdate_flag==true){ - PorosityVolumetricReactionUpdate(); // porosity change - PermeabilityPorosityUpdate(); // resulting permeability change - } - if(dump_min_moles==true) - DumpSolidSpeciesMoles(); - if(dump_all_pcs==true) - DumpAllVariables(); - if(dump_mass_integrals==true) - DumpMassIntegrals(); - - //return pcs rename post, do rename operation - if(this->pcs_rename_post_flag==true){ - for(ii=0;iinodenumber;ii++){ //node loop - ic=0; - for(i=0;i<(int)pcs_rename0_idx_post.size();i++){ - value=0.0; - for(ix=0;ix<(int)pcs_rename1_idx_post[i].size();ix++){ - m_pcs= pcs_vector[pcs_rename1_idx_post[i][ix]]; - if(pcs_rename1_stoi_post[i][ix]==999999) - value *= m_pcs->GetNodeValue(ii,f); - else if(pcs_rename1_stoi_post[i][ix]==-999999) - value /= m_pcs->GetNodeValue(ii,f); - else if(pcs_rename1_stoi_post[i][ix]==-999998) - value += exp(m_pcs->GetNodeValue(ii,f)); - else if(pcs_rename1_stoi_post[i][ix]==-999997) - value += log(m_pcs->GetNodeValue(ii,f)); - else if(pcs_rename1_stoi_post[i][ix]==-999996) - value += log10(m_pcs->GetNodeValue(ii,f)); - else if(pcs_rename1_stoi_post[i][ix]==-999990) - value += m_pcs->GetNodeValue(ii,f)-m_pcs->GetNodeValue(ii,0); - else if(pcs_rename1_stoi_post[i][ix]==-999995){ - value += pow(m_pcs->GetNodeValue(ii,f), this->pow_stoi_post[ic]); - ic ++; - } - else - value += m_pcs->GetNodeValue(ii,f) *pcs_rename1_stoi_post[i][ix]; - } - m_pcs= pcs_vector[pcs_rename0_idx_post[i]]; - m_pcs->SetNodeValue(ii,f,value); - } - } - } - } - - return; +void REACTINT::ReactionPostProcessing(bool initial) +{ + int i, ii, ix, f = 1, ic; + double value; + CRFProcess* m_pcs = NULL; + + if (initial) // only after initial reactions, i.e. before first real time step + this->CopyAllConcentrationsToOtherTimeLevel(true); + else + { + // CopySymmetricConcentrationsInRadialModel(); + if (poroupdate_flag == true) + { + PorosityVolumetricReactionUpdate(); // porosity change + PermeabilityPorosityUpdate(); // resulting permeability change + } + if (dump_min_moles == true) + DumpSolidSpeciesMoles(); + if (dump_all_pcs == true) + DumpAllVariables(); + if (dump_mass_integrals == true) + DumpMassIntegrals(); + + // return pcs rename post, do rename operation + if (this->pcs_rename_post_flag == true) + { + for (ii = 0; ii < this->nodenumber; ii++) + { // node loop + ic = 0; + for (i = 0; i < (int)pcs_rename0_idx_post.size(); i++) + { + value = 0.0; + for (ix = 0; ix < (int)pcs_rename1_idx_post[i].size(); ix++) + { + m_pcs = pcs_vector[pcs_rename1_idx_post[i][ix]]; + if (pcs_rename1_stoi_post[i][ix] == 999999) + value *= m_pcs->GetNodeValue(ii, f); + else if (pcs_rename1_stoi_post[i][ix] == -999999) + value /= m_pcs->GetNodeValue(ii, f); + else if (pcs_rename1_stoi_post[i][ix] == -999998) + value += exp(m_pcs->GetNodeValue(ii, f)); + else if (pcs_rename1_stoi_post[i][ix] == -999997) + value += log(m_pcs->GetNodeValue(ii, f)); + else if (pcs_rename1_stoi_post[i][ix] == -999996) + value += log10(m_pcs->GetNodeValue(ii, f)); + else if (pcs_rename1_stoi_post[i][ix] == -999990) + value += m_pcs->GetNodeValue(ii, f) - m_pcs->GetNodeValue(ii, 0); + else if (pcs_rename1_stoi_post[i][ix] == -999995) + { + value += pow(m_pcs->GetNodeValue(ii, f), this->pow_stoi_post[ic]); + ic++; + } + else + value += m_pcs->GetNodeValue(ii, f) * pcs_rename1_stoi_post[i][ix]; + } + m_pcs = pcs_vector[pcs_rename0_idx_post[i]]; + m_pcs->SetNodeValue(ii, f, value); + } + } + } + } + + return; } /************************************************************************** @@ -1031,29 +1162,29 @@ void REACTINT::ReactionPostProcessing(bool initial){ Programing: //CB 01.2011 CB First implementation **************************************************************************/ -double REACTINT::CalcDensityOfWater(void){ - - double dens = 0; - /* - // Test density function water - // Li Na K Mg Ca Cl SO4 CO3 - mv[0]=0; - mv[1]=species_value[6]; - mv[2]=0; - mv[3]=species_value[9]; - mv[4]=species_value[8]; - mv[5]=species_value[7]; - mv[6]=0; - mv[7]=species_value[5]; - mCO2 = 0; - - t0=double(clock()); - dens = Density_CO2_MultiBrine(TT,PP,mv,mCO2); - t1+=double(clock())-t0; - cout << "\n" << dens ; - //cout << double(t1/CLOCKS_PER_SEC) << "\n"; - */ - return dens; +double REACTINT::CalcDensityOfWater(void) +{ + double dens = 0; + /* + // Test density function water + // Li Na K Mg Ca Cl SO4 CO3 + mv[0]=0; + mv[1]=species_value[6]; + mv[2]=0; + mv[3]=species_value[9]; + mv[4]=species_value[8]; + mv[5]=species_value[7]; + mv[6]=0; + mv[7]=species_value[5]; + mCO2 = 0; + + t0=double(clock()); + dens = Density_CO2_MultiBrine(TT,PP,mv,mCO2); + t1+=double(clock())-t0; + cout << "\n" << dens ; + //cout << double(t1/CLOCKS_PER_SEC) << "\n"; + */ + return dens; } /************************************************************************** @@ -1062,83 +1193,87 @@ double REACTINT::CalcDensityOfWater(void){ Programing: //CB 01.2011 CB First implementation **************************************************************************/ -double REACTINT::GetPressure(long node){ - - double PP = 1; - double factor = 1, z; - int idxp=0, idxp2=0, timelevel = 1; - bool ppmodel = false; - - CRFProcess *m_pcs_p = NULL; - CFEMesh* m_msh = fem_msh_vector[0]; - CFluidProperties* m_mfp = NULL; - - if(constantpressure) - return c_PP; - - m_mfp = MFPGet( "LIQUID" ); - - - if(aktueller_zeitschritt==0) timelevel = 0; - // get the Pressure info Todo: check this function for correct pressure conversion - m_pcs_p = PCSGetFlow(); - - if (flowtype==1) - if(m_pcs_p->getProcessType()==FiniteElement::LIQUID_FLOW) - flowtype=0; - - switch(flowtype){ - case 0: //Liquid_Flow - idxp = m_pcs_p->GetNodeValueIndex ("PRESSURE1") + timelevel; - factor = 1 / 1.0e+5 ; - break; - case 1: //Groundwater Flow - idxp = m_pcs_p->GetNodeValueIndex ("HEAD") + timelevel; - factor = gravity_constant * m_mfp->Density() / 1.0e+5 ; - break; - case 66: //Overland Flow - break; - case 5: //Air Flow - break; - case 11: //Componental Flow - break; - case 1212: //Multiphase Flow - idxp = m_pcs_p->GetNodeValueIndex ("PRESSURE1") + timelevel; // p_cap - idxp2 = m_pcs_p->GetNodeValueIndex ("PRESSURE2") + timelevel;// p_nw - factor = 1 / 1.0e+5 ; - ppmodel = true; - break; - case 12: // Two_phase_Flow - idxp = m_pcs_p->GetNodeValueIndex ("PRESSURE1") + timelevel; - factor = 1 / 1.0e+5 ; - break; - case 1313: // PS_GLOBAL - idxp = m_pcs_p->GetNodeValueIndex ("PRESSURE1") + timelevel; - factor = 1 / 1.0e+5 ; - break; - case 22: // Richards flow - idxp = m_pcs_p->GetNodeValueIndex ("PRESSURE1") + timelevel; - factor = 1 / 1.0e+5 ; - break; - default: - break; - } - - // get pressure todo CB - if(flowtype==1){ //Groundwater flow head --> Pressure - z = m_msh->nod_vector[node]->getData()[2]; // CB_merge_0513 ?? check - PP = (m_pcs_p->GetNodeValue (node, idxp) - z) * factor; - } - else - PP = m_pcs_p->GetNodeValue (node, idxp) * factor; - if(ppmodel) // add nw pressure to capillary pressure - PP += m_pcs_p->GetNodeValue (node, idxp2) * factor; - if(PP<=0 || PP > 1000){ // limit pressure - cout << "Warning in REACTINT::GetPressure(): unreasonable P: " << PP ; - cout << " bar; limiting to P = 1 bar" << "\n"; - PP = 1; - } - return PP; +double REACTINT::GetPressure(long node) +{ + double PP = 1; + double factor = 1, z; + int idxp = 0, idxp2 = 0, timelevel = 1; + bool ppmodel = false; + + CRFProcess* m_pcs_p = NULL; + CFEMesh* m_msh = fem_msh_vector[0]; + CFluidProperties* m_mfp = NULL; + + if (constantpressure) + return c_PP; + + m_mfp = MFPGet("LIQUID"); + + if (aktueller_zeitschritt == 0) + timelevel = 0; + // get the Pressure info Todo: check this function for correct pressure conversion + m_pcs_p = PCSGetFlow(); + + if (flowtype == 1) + if (m_pcs_p->getProcessType() == FiniteElement::LIQUID_FLOW) + flowtype = 0; + + switch (flowtype) + { + case 0: // Liquid_Flow + idxp = m_pcs_p->GetNodeValueIndex("PRESSURE1") + timelevel; + factor = 1 / 1.0e+5; + break; + case 1: // Groundwater Flow + idxp = m_pcs_p->GetNodeValueIndex("HEAD") + timelevel; + factor = gravity_constant * m_mfp->Density() / 1.0e+5; + break; + case 66: // Overland Flow + break; + case 5: // Air Flow + break; + case 11: // Componental Flow + break; + case 1212: // Multiphase Flow + idxp = m_pcs_p->GetNodeValueIndex("PRESSURE1") + timelevel; // p_cap + idxp2 = m_pcs_p->GetNodeValueIndex("PRESSURE2") + timelevel; // p_nw + factor = 1 / 1.0e+5; + ppmodel = true; + break; + case 12: // Two_phase_Flow + idxp = m_pcs_p->GetNodeValueIndex("PRESSURE1") + timelevel; + factor = 1 / 1.0e+5; + break; + case 1313: // PS_GLOBAL + idxp = m_pcs_p->GetNodeValueIndex("PRESSURE1") + timelevel; + factor = 1 / 1.0e+5; + break; + case 22: // Richards flow + idxp = m_pcs_p->GetNodeValueIndex("PRESSURE1") + timelevel; + factor = 1 / 1.0e+5; + break; + default: + break; + } + + // get pressure todo CB + if (flowtype == 1) + { // Groundwater flow head --> Pressure + z = m_msh->nod_vector[node]->getData()[2]; // CB_merge_0513 ?? check + PP = (m_pcs_p->GetNodeValue(node, idxp) - z) * factor; + } + else + PP = m_pcs_p->GetNodeValue(node, idxp) * factor; + if (ppmodel) // add nw pressure to capillary pressure + PP += m_pcs_p->GetNodeValue(node, idxp2) * factor; + if (PP <= 0 || PP > 1000) + { // limit pressure + cout << "Warning in REACTINT::GetPressure(): unreasonable P: " << PP; + cout << " bar; limiting to P = 1 bar" + << "\n"; + PP = 1; + } + return PP; } /************************************************************************** @@ -1147,28 +1282,30 @@ double REACTINT::GetPressure(long node){ Programing: //CB 01.2011 CB First implementation **************************************************************************/ -double REACTINT::GetTemperature(long node){ - - double TT=298.15; - int idxt=0, timelevel = 1; -// bool heattransport = false; +double REACTINT::GetTemperature(long node) +{ + double TT = 298.15; + int idxt = 0, timelevel = 1; + // bool heattransport = false; - if(constanttemperature) - return c_TT; + if (constanttemperature) + return c_TT; - if(aktueller_zeitschritt<1) timelevel = 0; -// if(aktueller_zeitschritt<=1) timelevel = 0; // CB-DL?? - CRFProcess *m_pcs_t = NULL; + if (aktueller_zeitschritt < 1) + timelevel = 0; + // if(aktueller_zeitschritt<=1) timelevel = 0; // CB-DL?? + CRFProcess* m_pcs_t = NULL; - // get the Temperature info - if((m_pcs_t = PCSGet("HEAT_TRANSPORT"))) { - idxt = m_pcs_t->GetNodeValueIndex ("TEMPERATURE1") + timelevel; - TT = m_pcs_t->GetNodeValue (node, idxt); - } - else - TT = c_TT; + // get the Temperature info + if ((m_pcs_t = PCSGet("HEAT_TRANSPORT"))) + { + idxt = m_pcs_t->GetNodeValueIndex("TEMPERATURE1") + timelevel; + TT = m_pcs_t->GetNodeValue(node, idxt); + } + else + TT = c_TT; - return TT; + return TT; } /************************************************************************** @@ -1177,26 +1314,27 @@ double REACTINT::GetTemperature(long node){ Programing: //CB 11.2011 CB First implementation **************************************************************************/ -void REACTINT::CheckForDriedOutNodes(void){ - - long i, nnode; +void REACTINT::CheckForDriedOutNodes(void) +{ + long i, nnode; - CFEMesh* m_msh = fem_msh_vector[0]; - nnode = (long) m_msh->nod_vector.size(); + CFEMesh* m_msh = fem_msh_vector[0]; + nnode = (long)m_msh->nod_vector.size(); - if(aktueller_zeitschritt>1){ - for (i=0;i 1) + { + for (i = 0; i < nnode; i++) + { + if (GetWaterSaturation(i) < WaterSatLimit) + dried_out_nodes[i] = true; + else + dried_out_nodes[i] = false; + } + } - return; + return; } - /************************************************************************** ReacInt-Method: Task: For all species, copy node values to another time level @@ -1205,15 +1343,15 @@ void REACTINT::CheckForDriedOutNodes(void){ Programing: //CB 10.2011 CB First implementation **************************************************************************/ -void REACTINT::CopyAllConcentrationsToOtherTimeLevel(bool forward){ - - int i; - //CRFProcess *m_pcs = NULL; +void REACTINT::CopyAllConcentrationsToOtherTimeLevel(bool forward) +{ + int i; + // CRFProcess *m_pcs = NULL; - for (i=0;igetProcess()->CopyTimestepNODValues(forward); // true: new->old + for (i = 0; i < int(cp_vec.size()); i++) + cp_vec[i]->getProcess()->CopyTimestepNODValues(forward); // true: new->old - return; + return; } /************************************************************************** @@ -1222,241 +1360,262 @@ void REACTINT::CopyAllConcentrationsToOtherTimeLevel(bool forward){ Programing: //CB 10.2011 CB First implementation **************************************************************************/ -void REACTINT::Heatpump_2DhTO2Dv_Mapping(bool forward){ - - int idxt=0, timelevel = 1; - long j=0; - long i=0; - double const *coord; //[3]={0,0,0}; - - - CRFProcess *m_pcs_t = NULL; - long nnode = long(fem_msh_vector[0]->nod_vector.size()); - - // get the Temperature info - if((m_pcs_t = PCSGet("HEAT_TRANSPORT"))) - idxt = m_pcs_t->GetNodeValueIndex("TEMPERATURE1") + timelevel; - else - return; - - // backward mapping - if(!forward){ - if(aktueller_zeitschritt==1) - return; - else - for(i=0;iSetNodeValue(i, idxt, Temp_store[i]); // new TL - m_pcs_t->SetNodeValue(i, idxt-1, Temp_store[i]); // old TL - } - } - - // forward mapping - - //check output - //if(aktueller_zeitschritt==25) return; - - std::vector > Temp_GHP_xyz; - std::vector > XYZ; - std::vector Temp_GHP_nod_idx; - std::vector xyz; - - if(aktueller_zeitschritt==1){ - for(i=0;i<3;i++) xyz.push_back(0); - for(i=0;iGetNodeValue(i, idxt)); - // now store mapping relations - coord = fem_msh_vector[0]->nod_vector[i]->getData(); - for(j=0;j<3;j++) xyz[j]=coord[j]; - // find nodes on plume center line and store xyz - if(coord[2]==heatpump_Z) { - Temp_GHP_xyz.push_back(xyz); - Temp_GHP_nod_idx.push_back(i); - } - // store all other node corrdinates - XYZ.push_back(xyz); - } - // now check for each node the corresponding map node on center line - for(i=0;i only regular mesh so far - Temp_GHP_mapidx.push_back(Temp_GHP_nod_idx[j]); - } - } - else{ // after 1st time step - for(i=0;iGetNodeValue(i, idxt); - } - - // now map center line to xz plane - for(i=0;iSetNodeValue(i, idxt, Temp_store[Temp_GHP_mapidx[i]]); - - // clean up - xyz.clear(); - Temp_GHP_xyz.clear(); - Temp_GHP_nod_idx.clear(); - XYZ.clear(); - - return; +void REACTINT::Heatpump_2DhTO2Dv_Mapping(bool forward) +{ + int idxt = 0, timelevel = 1; + long j = 0; + long i = 0; + double const* coord; //[3]={0,0,0}; + + CRFProcess* m_pcs_t = NULL; + long nnode = long(fem_msh_vector[0]->nod_vector.size()); + + // get the Temperature info + if ((m_pcs_t = PCSGet("HEAT_TRANSPORT"))) + idxt = m_pcs_t->GetNodeValueIndex("TEMPERATURE1") + timelevel; + else + return; + + // backward mapping + if (!forward) + { + if (aktueller_zeitschritt == 1) + return; + else + for (i = 0; i < nnode; i++) + { + m_pcs_t->SetNodeValue(i, idxt, Temp_store[i]); // new TL + m_pcs_t->SetNodeValue(i, idxt - 1, Temp_store[i]); // old TL + } + } + + // forward mapping + + // check output + // if(aktueller_zeitschritt==25) return; + std::vector > Temp_GHP_xyz; + std::vector > XYZ; + std::vector Temp_GHP_nod_idx; + std::vector xyz; + + if (aktueller_zeitschritt == 1) + { + for (i = 0; i < 3; i++) + xyz.push_back(0); + for (i = 0; i < nnode; i++) + { + // first save all Temperatures + Temp_store.push_back(m_pcs_t->GetNodeValue(i, idxt)); + // now store mapping relations + coord = fem_msh_vector[0]->nod_vector[i]->getData(); + for (j = 0; j < 3; j++) + xyz[j] = coord[j]; + // find nodes on plume center line and store xyz + if (coord[2] == heatpump_Z) + { + Temp_GHP_xyz.push_back(xyz); + Temp_GHP_nod_idx.push_back(i); + } + // store all other node corrdinates + XYZ.push_back(xyz); + } + // now check for each node the corresponding map node on center line + for (i = 0; i < nnode; i++) + { + for (j = 0; j < long(Temp_GHP_xyz.size()); j++) + if ((XYZ[i][0] == Temp_GHP_xyz[j][0])) // x cordinate matches -> only regular mesh so far + Temp_GHP_mapidx.push_back(Temp_GHP_nod_idx[j]); + } + } + else + { // after 1st time step + for (i = 0; i < nnode; i++) + Temp_store[i] = m_pcs_t->GetNodeValue(i, idxt); + } + + // now map center line to xz plane + for (i = 0; i < nnode; i++) + m_pcs_t->SetNodeValue(i, idxt, Temp_store[Temp_GHP_mapidx[i]]); + + // clean up + xyz.clear(); + Temp_GHP_xyz.clear(); + Temp_GHP_nod_idx.clear(); + XYZ.clear(); + + return; +} + +void REACTINT::ReadRestartNodePoro(long nnodes) +{ + long i, j; + char zeile[1000]; + double porosity; + // get medium property + // CMediumProperties *m_mat_mp = NULL; + MeshLib::CElem* m_ele = NULL; + CFEMesh* m_msh = fem_msh_vector[0]; + long n_ele = long(m_msh->ele_vector.size()); + CRFProcess* m_pcs_flow = NULL; + m_pcs_flow = PCSGetFlow(); + int idx_n = m_pcs_flow->GetElementValueIndex("POROSITY"); + int node_idx; + + ifstream ein(this->porofile.data(), ios::in); + if (!ein.good()) + { + cout << " Input file not found in ReadRestartNodePoro" + << "\n"; + exit(0); + } + + // ein.str(GetLineFromFile1(rfd_file)); + for (i = 0; i < nnodes; i++) + { + ein >> this->node_porosity[i]; + ein.getline(zeile, 1000); + } + + // now set the new element porosities from node_porosity for mass transport and other processes + // loop over all elements + for (long n = 0; n < n_ele; n++) + { + m_ele = m_msh->ele_vector[n]; + long nn = m_ele->GetNodesNumber(false); // nodes_index.Size(); + porosity = 0; + for (j = 0; j < nn; j++) + { + node_idx = m_ele->GetNodeIndex(j); + porosity += node_porosity[node_idx]; + } + // arithmetic average ... inverse distance? + porosity /= (double)nn; + // set the element value + m_pcs_flow->SetElementValue(n, idx_n + 1, porosity); + } + + return; } +/************************************************************************** + ReacInt-Method: + Task: Calculate water concentration at all nodes + Programing: + //CB 01.2011 CB First implementation + **************************************************************************/ +void REACTINT::CalcWaterConc(void) +{ + long i, j, k = 0; + double cv[8], cv_CO2, TT = 298.15, PP = 1; + double conc; // factor = 1, + int idxCO2 = 0, widx = -1; // timelevel = 1, idxp=0, idxp2=0, idxt=0, + // bool heattransport = false; + // bool ppmodel = false; + bool CO2 = false; + // bool timeflag = false; + int nc = (int)cp_vec.size(); + + CompProperties* m_cp = NULL; + // CRFProcess *m_pcs_t = NULL; + // CRFProcess *m_pcs_p = NULL; + CFEMesh* m_msh = fem_msh_vector[0]; + // MeshLib::CNode* m_nod = NULL; + long nnodes = (long)m_msh->nod_vector.size(); + CFluidProperties* m_mfp = NULL; + m_mfp = MFPGet("LIQUID"); + // double dens = 0; + + // if(aktueller_zeitschritt==0) timelevel = 0; + // Get water concentration index + for (j = 0; j < nc; j++) + { + m_cp = cp_vec[j]; + if (m_cp->compname.compare(WaterSpeciesName) == 0 || m_cp->compname.compare("H2O") == 0 + || m_cp->compname.compare("H2O_liquid") == 0 + || m_cp->compname.compare("water_liquid") == 0) + { + widx = j; + break; + } + } -void REACTINT::ReadRestartNodePoro(long nnodes){ + if (constantdensity) + { + for (i = 0; i < nnodes; i++) + { + water_conc[i] = m_mfp->Density() * MOLH2OPERKG; // here density of pure H2O phase must be used + // water_conc[i] = 4.54912323E+04; + if (widx > -1) + // pcs_vector[sp_pcsind[widx]]->SetNodeValue(i,1,water_conc[i]); + cp_vec[widx]->getProcess()->SetNodeValue(i, 1, water_conc[i]); + } + return; + } - long i,j; - char zeile[1000]; - double porosity; - // get medium property -// CMediumProperties *m_mat_mp = NULL; - MeshLib::CElem* m_ele = NULL; - CFEMesh* m_msh = fem_msh_vector[0]; - long n_ele = long(m_msh->ele_vector.size()); - CRFProcess* m_pcs_flow = NULL; - m_pcs_flow = PCSGetFlow(); - int idx_n = m_pcs_flow->GetElementValueIndex("POROSITY"); -int node_idx; - - - ifstream ein (this->porofile.data(),ios::in); - if (!ein.good()){ - cout << " Input file not found in ReadRestartNodePoro" << "\n"; - exit(0); - } - -// ein.str(GetLineFromFile1(rfd_file)); - for (i=0;i< nnodes;i++){ - ein >> this->node_porosity[i]; - ein.getline(zeile,1000); - } - - // now set the new element porosities from node_porosity for mass transport and other processes - // loop over all elements - for(long n = 0; n < n_ele; n++){ - m_ele = m_msh->ele_vector[n]; - long nn = m_ele->GetNodesNumber(false); // nodes_index.Size(); - porosity = 0; - for(j = 0; j < nn; j++){ - node_idx = m_ele->GetNodeIndex(j); - porosity += node_porosity[node_idx]; - } - //arithmetic average ... inverse distance? - porosity /= (double) nn; - //set the element value - m_pcs_flow->SetElementValue( n, idx_n+1, porosity ); - } - - return; -} + // Get CO2_in_water concentration index + // this should be CO2_dissolved, not total CO2, + // so get secondary species CO2, not C(4) if you are using Phreeqc + for (j = 0; j < nc; j++) + { + m_cp = cp_vec[j]; + if (m_cp->compname.compare(this->NeutralCO2name) == 0 || m_cp->compname.compare("CO2_w") == 0 + || m_cp->compname.compare("CO2") == 0) + { + CO2 = true; + idxCO2 = j; + break; + } + } + // if(aktueller_zeitschritt==0 || aktueller_zeitschritt==1) timeflag = true; + // node loop to calculate water concentration + for (i = 0; i < nnodes; i++) + { + TT = this->GetTemperature(i); + PP = this->GetPressure(i); + // Weight function of water + // Li Na K Mg Ca Cl SO4 CO3 (only charged CO2 species) + for (k = 0; k < 8; k++) + cv[k] = 0; + // loop over all species for current node + for (j = 0; j < nc; j++) + { + // get concentration; this requires existence of vectors sp_pcsind and sp_var_ind + // todo: what about double species, e.g. primary and secondary species?? + // conc = pcs_vector[sp_pcsind[j]]->GetNodeValue(i,sp_varind[j]);// CB HS update + // if(timeflag &! cp_vec[j]->mobil) + // conc = cp_vec[j]->getProcess()->GetNodeValue(i,sp_varind[j]-1); + // else + conc = cp_vec[j]->getProcess()->GetNodeValue(i, sp_varind[j]); // all concentrations are available at new TL + if (conc < 0) + conc = 0; + // distribute to density species + for (k = 0; k < 8; k++) + cv[k] += conc * ElementInSpecies[j][k]; + } + // here, get amount of CO2 phase + if (CO2) + { + // cv_CO2 = pcs_vector[sp_pcsind[idxCO2]]->GetNodeValue(i,sp_varind[idxCO2]);// CB HS update + // if(timeflag &! cp_vec[idxCO2]->mobil) + // cv_CO2 = cp_vec[idxCO2]->getProcess()->GetNodeValue(i,sp_varind[idxCO2]-1); + // else + cv_CO2 = cp_vec[idxCO2]->getProcess()->GetNodeValue( + i, sp_varind[idxCO2]); // all concentrations are available at new TL + } + else + cv_CO2 = 0; + // calculate and store water concentration for this node + water_conc[i] = density::concentration_water(TT, PP, cv, cv_CO2); // CB removed from ifdef OGS_FEM_CAP + // set the corrsponding node value of H2O transport process + // pcs_vector[sp_pcsind[widx]]->SetNodeValue(i,1,water_conc[i]);// CB HS update + cp_vec[widx]->getProcess()->SetNodeValue(i, 1, water_conc[i]); + } -/************************************************************************** - ReacInt-Method: - Task: Calculate water concentration at all nodes - Programing: - //CB 01.2011 CB First implementation - **************************************************************************/ -void REACTINT::CalcWaterConc(void){ - - long i,j,k=0; - double cv[8], cv_CO2, TT=298.15, PP = 1; - double conc;//factor = 1, - int idxCO2=0, widx=-1; // timelevel = 1, idxp=0, idxp2=0, idxt=0, - //bool heattransport = false; - //bool ppmodel = false; - bool CO2 = false; - //bool timeflag = false; - int nc = (int)cp_vec.size(); - - CompProperties *m_cp = NULL; - //CRFProcess *m_pcs_t = NULL; - //CRFProcess *m_pcs_p = NULL; - CFEMesh* m_msh = fem_msh_vector[0]; - //MeshLib::CNode* m_nod = NULL; - long nnodes = (long) m_msh->nod_vector.size(); - CFluidProperties* m_mfp = NULL; - m_mfp = MFPGet( "LIQUID" ); - //double dens = 0; - - //if(aktueller_zeitschritt==0) timelevel = 0; - - // Get water concentration index - for(j=0;jcompname.compare(WaterSpeciesName)==0 || m_cp->compname.compare("H2O")==0 || m_cp->compname.compare("H2O_liquid")==0 || m_cp->compname.compare("water_liquid")==0){ - widx = j; - break; - } - } - - if(constantdensity) { - for(i=0;iDensity() * MOLH2OPERKG; // here density of pure H2O phase must be used - //water_conc[i] = 4.54912323E+04; - if(widx > -1) - //pcs_vector[sp_pcsind[widx]]->SetNodeValue(i,1,water_conc[i]); - cp_vec[widx]->getProcess()->SetNodeValue(i,1,water_conc[i]); - } - return; - } - - // Get CO2_in_water concentration index - // this should be CO2_dissolved, not total CO2, - // so get secondary species CO2, not C(4) if you are using Phreeqc - for(j=0;jcompname.compare(this->NeutralCO2name)==0 || m_cp->compname.compare("CO2_w")==0 || m_cp->compname.compare("CO2")==0 ){ - CO2 = true; - idxCO2 = j; - break; - } - } - - //if(aktueller_zeitschritt==0 || aktueller_zeitschritt==1) timeflag = true; - - // node loop to calculate water concentration - for(i=0;iGetTemperature(i); - PP = this->GetPressure(i); - //Weight function of water - // Li Na K Mg Ca Cl SO4 CO3 (only charged CO2 species) - for(k=0;k<8;k++) cv[k]= 0; - // loop over all species for current node - for(j=0;jGetNodeValue(i,sp_varind[j]);// CB HS update - //if(timeflag &! cp_vec[j]->mobil) - // conc = cp_vec[j]->getProcess()->GetNodeValue(i,sp_varind[j]-1); - //else - conc = cp_vec[j]->getProcess()->GetNodeValue(i,sp_varind[j]); // all concentrations are available at new TL - if(conc<0) - conc = 0; - // distribute to density species - for(k=0;k<8;k++) - cv[k] += conc * ElementInSpecies[j][k]; - } - // here, get amount of CO2 phase - if(CO2){ - //cv_CO2 = pcs_vector[sp_pcsind[idxCO2]]->GetNodeValue(i,sp_varind[idxCO2]);// CB HS update - //if(timeflag &! cp_vec[idxCO2]->mobil) - // cv_CO2 = cp_vec[idxCO2]->getProcess()->GetNodeValue(i,sp_varind[idxCO2]-1); - //else - cv_CO2 = cp_vec[idxCO2]->getProcess()->GetNodeValue(i,sp_varind[idxCO2]); // all concentrations are available at new TL - } - else - cv_CO2 = 0; - // calculate and store water concentration for this node - water_conc[i] = density::concentration_water(TT,PP,cv,cv_CO2); // CB removed from ifdef OGS_FEM_CAP - // set the corrsponding node value of H2O transport process - //pcs_vector[sp_pcsind[widx]]->SetNodeValue(i,1,water_conc[i]);// CB HS update - cp_vec[widx]->getProcess()->SetNodeValue(i,1,water_conc[i]); - } - - return; + return; } /************************************************************************** @@ -1465,64 +1624,62 @@ void REACTINT::CalcWaterConc(void){ Programing: //CB 01.2012 CB First implementation **************************************************************************/ -void REACTINT::CalcUnitConversionFactors(long index, double *fl, double *fs, bool molal){ - - if(molal){ // mol/m³-->mol/kgw - *fl = MOLH2OPERKG / water_conc[index]; // mol/kgH2O * m³liquid/mol = m³l/kg - *fs = (1 - node_porosity[index]) * MOLH2OPERKG / (water_conc[index] * node_porosity[index] * GetWaterSaturation(index) ); - if(*fs == 0) - *fs = (1 - node_porosity[index]) * MOLH2OPERKG / (water_conc[index] * node_porosity[index] * 1 ); - } - else{ // Total moles mol/m³liquid -> mol/m³REV - *fl = node_porosity[index] * GetWaterSaturation(index); - if(*fl == 0.0) - *fl = node_porosity[index] * 1; - *fs = 1 - node_porosity[index]; - } - +void REACTINT::CalcUnitConversionFactors(long index, double* fl, double* fs, bool molal) +{ + if (molal) + { // mol/m³-->mol/kgw + *fl = MOLH2OPERKG / water_conc[index]; // mol/kgH2O * m³liquid/mol = m³l/kg + *fs = (1 - node_porosity[index]) * MOLH2OPERKG + / (water_conc[index] * node_porosity[index] * GetWaterSaturation(index)); + if (*fs == 0) + *fs = (1 - node_porosity[index]) * MOLH2OPERKG / (water_conc[index] * node_porosity[index] * 1); + } + else + { // Total moles mol/m³liquid -> mol/m³REV + *fl = node_porosity[index] * GetWaterSaturation(index); + if (*fl == 0.0) + *fl = node_porosity[index] * 1; + *fs = 1 - node_porosity[index]; + } } - - - /************************************************************************** ReacInt-Method: Task: Calculate water concentration at all nodes Programing: //CB 01.2012 CB First implementation **************************************************************************/ -double REACTINT::GetCO2SolubilityDuan(long node){ - - long j; - double TT=298.15, PP = 1, Sal = 0, Sol = 0; - int Naidx=-1; - int nc = (int)cp_vec.size(); - double unitfactor_l = 1; - CompProperties *m_cp = NULL; - - TT = this->GetTemperature(node); // is in K - PP = this->GetPressure(node); // is in ba - unitfactor_l = MOLH2OPERKG / water_conc[node]; - //unitfactor_l = MOLH2OPERKG / 55335.831251734664; - // Get water concentration index - for(j=0;jcompname.compare(SodiumSpeciesName)==0 ){ - Naidx = j; - break; - } - } - if(Naidx >= 0) - Sal = cp_vec[Naidx]->getProcess()->GetNodeValue(node,sp_varind[Naidx]); // mol/m³l - Sal *= unitfactor_l ; // mol/kgw - - Sol = VLE::solubility_CO2(TT,PP,Sal) ; // mol/kgw - Sol /= unitfactor_l; - return Sol ; -} - - +double REACTINT::GetCO2SolubilityDuan(long node) +{ + long j; + double TT = 298.15, PP = 1, Sal = 0, Sol = 0; + int Naidx = -1; + int nc = (int)cp_vec.size(); + double unitfactor_l = 1; + CompProperties* m_cp = NULL; + + TT = this->GetTemperature(node); // is in K + PP = this->GetPressure(node); // is in ba + unitfactor_l = MOLH2OPERKG / water_conc[node]; + // unitfactor_l = MOLH2OPERKG / 55335.831251734664; + // Get water concentration index + for (j = 0; j < nc; j++) + { + m_cp = cp_vec[j]; + if (m_cp->compname.compare(SodiumSpeciesName) == 0) + { + Naidx = j; + break; + } + } + if (Naidx >= 0) + Sal = cp_vec[Naidx]->getProcess()->GetNodeValue(node, sp_varind[Naidx]); // mol/m³l + Sal *= unitfactor_l; // mol/kgw + Sol = VLE::solubility_CO2(TT, PP, Sal); // mol/kgw + Sol /= unitfactor_l; + return Sol; +} /************************************************************************** FEMLib-Method: SettingInitialPorosityToElementValue() @@ -1537,116 +1694,137 @@ last modification: **************************************************************************/ void REACTINT::SetInitialPorosityAndPermToElementValue() { + double n_initial, k_initial_xx; + double k_initial_yy, k_initial_zz; + int idx_n, idx_k, idx_k_yy, idx_k_zz, i, k, kk; - double n_initial, k_initial_xx; - double k_initial_yy, k_initial_zz; - int idx_n, idx_k, idx_k_yy, idx_k_zz, i, k, kk; - - //CElem* m_ele = NULL; - CFEMesh* m_msh = fem_msh_vector[0]; - long n_ele = long(m_msh->ele_vector.size()); - - CRFProcess *m_pcs_flow; - m_pcs_flow = PCSGetFlow(); - - // get medium property - CMediumProperties *m_mat_mp = NULL; - - // return if porosity update is not required - for(long n = 0; n < n_ele; n++){ - // get material group - long n_group = m_msh->ele_vector[n]->GetPatchIndex(); - m_mat_mp = mmp_vector[n_group]; - if (m_mat_mp->porosity_model==13){ - poroupdate_flag = true; - break; - } - } - if(poroupdate_flag==false) - return; - - cout <<"SettingInitialPorosityAndPermToElementValue." << "\n"; - - // first check if necessary component properties is defined - k=kk=0; - for(i=0;itransport_phase==1){ - if(cp_vec[i]->molar_weight>0) k++; - if(cp_vec[i]->mineral_density>0) kk++; - } - } - if(k==0){ - cout << " Warning in REACINT: molar_weight has not been defined for ANY solid phase species." << "\n"; - cout << " No porosity update possible." << "\n"; - } - if(kk==0){ - cout << " Warning in REACINT: mineral_density has not been defined for ANY solid phase species." << "\n"; - cout << " No porosity update possible. " << "\n"; - } - - idx_n = m_pcs_flow->GetElementValueIndex("POROSITY"); - if(idx_n<0) cout << " Warning in REACINT: No POROSITY ele index found with PCS " << m_pcs_flow->getProcessType() << "." << "\n"; - idx_k = m_pcs_flow->GetElementValueIndex("PERMEABILITY"); - if(idx_k<0) cout << " Warning in REACINT: No PERMEABILITY ele index found with PCS " << m_pcs_flow->getProcessType() << "." << "\n"; - idx_k_yy = m_pcs_flow->GetElementValueIndex("PERMEABILITY_YY"); - if(idx_k_yy<0) cout << " Warning in REACINT: No PERMEABILITY_YY ele index found with PCS " << m_pcs_flow->getProcessType() << "." << "\n"; - idx_k_zz = m_pcs_flow->GetElementValueIndex("PERMEABILITY_ZZ"); - if(idx_k_zz<0) cout << " Warning in REACINT: No PERMEABILITY_ZZ ele index found with PCS " << m_pcs_flow->getProcessType() << "." << "\n"; - - for(long n = 0; n < n_ele; n++){ - - // get material group - long n_group = m_msh->ele_vector[n]->GetPatchIndex(); - m_mat_mp = mmp_vector[n_group]; - - if((m_mat_mp->porosity_model==13)&& (aktueller_zeitschritt == 0)){ - - n_initial = m_mat_mp->porosity_model_values[0]; - m_pcs_flow->SetElementValue( n, idx_n, n_initial ); // old time level - m_pcs_flow->SetElementValue( n, idx_n+1, n_initial ); // new time level - - //Isotropic permeability - if (m_mat_mp->permeability_tensor_type == 0){ - - k_initial_xx = m_mat_mp->permeability_tensor[0]; - m_pcs_flow->SetElementValue( n, idx_k, k_initial_xx ); // old time level - m_pcs_flow->SetElementValue( n, idx_k+1, k_initial_xx ); // new time level - } - //Orthogonal permeability - else if (m_mat_mp->permeability_tensor_type == 1){ - - if (m_mat_mp->GetGeoDimension() == 2){ - - k_initial_xx = m_mat_mp->permeability_tensor[0]; - k_initial_yy = m_mat_mp->permeability_tensor[1]; - - m_pcs_flow->SetElementValue( n, idx_k, k_initial_xx ); // old time level - m_pcs_flow->SetElementValue( n, idx_k+1, k_initial_xx ); // new time level - - m_pcs_flow->SetElementValue( n, idx_k_yy, k_initial_yy ); // old time level - m_pcs_flow->SetElementValue( n, idx_k_yy+1, k_initial_yy ); // new time level - } - else if (m_mat_mp->GetGeoDimension() == 3){ - - k_initial_xx = m_mat_mp->permeability_tensor[0]; - k_initial_yy = m_mat_mp->permeability_tensor[1]; - k_initial_zz = m_mat_mp->permeability_tensor[2]; - - m_pcs_flow->SetElementValue( n, idx_k, k_initial_xx ); // old time level - m_pcs_flow->SetElementValue( n, idx_k+1, k_initial_xx ); // new time level - - m_pcs_flow->SetElementValue( n, idx_k_yy, k_initial_yy ); // old time level - m_pcs_flow->SetElementValue( n, idx_k_yy+1, k_initial_yy ); // new time level - - m_pcs_flow->SetElementValue( n, idx_k_zz, k_initial_zz ); // old time level - m_pcs_flow->SetElementValue( n, idx_k_zz+1, k_initial_zz ); // new time level - } - } - } - } - return; -} + // CElem* m_ele = NULL; + CFEMesh* m_msh = fem_msh_vector[0]; + long n_ele = long(m_msh->ele_vector.size()); + + CRFProcess* m_pcs_flow; + m_pcs_flow = PCSGetFlow(); + + // get medium property + CMediumProperties* m_mat_mp = NULL; + + // return if porosity update is not required + for (long n = 0; n < n_ele; n++) + { + // get material group + long n_group = m_msh->ele_vector[n]->GetPatchIndex(); + m_mat_mp = mmp_vector[n_group]; + if (m_mat_mp->porosity_model == 13) + { + poroupdate_flag = true; + break; + } + } + if (poroupdate_flag == false) + return; + cout << "SettingInitialPorosityAndPermToElementValue." + << "\n"; + + // first check if necessary component properties is defined + k = kk = 0; + for (i = 0; i < int(cp_vec.size()); i++) + { + if (cp_vec[i]->transport_phase == 1) + { + if (cp_vec[i]->molar_weight > 0) + k++; + if (cp_vec[i]->mineral_density > 0) + kk++; + } + } + if (k == 0) + { + cout << " Warning in REACINT: molar_weight has not been defined for ANY solid phase species." + << "\n"; + cout << " No porosity update possible." + << "\n"; + } + if (kk == 0) + { + cout << " Warning in REACINT: mineral_density has not been defined for ANY solid phase species." + << "\n"; + cout << " No porosity update possible. " + << "\n"; + } + + idx_n = m_pcs_flow->GetElementValueIndex("POROSITY"); + if (idx_n < 0) + cout << " Warning in REACINT: No POROSITY ele index found with PCS " << m_pcs_flow->getProcessType() << "." + << "\n"; + idx_k = m_pcs_flow->GetElementValueIndex("PERMEABILITY"); + if (idx_k < 0) + cout << " Warning in REACINT: No PERMEABILITY ele index found with PCS " << m_pcs_flow->getProcessType() << "." + << "\n"; + idx_k_yy = m_pcs_flow->GetElementValueIndex("PERMEABILITY_YY"); + if (idx_k_yy < 0) + cout << " Warning in REACINT: No PERMEABILITY_YY ele index found with PCS " << m_pcs_flow->getProcessType() + << "." + << "\n"; + idx_k_zz = m_pcs_flow->GetElementValueIndex("PERMEABILITY_ZZ"); + if (idx_k_zz < 0) + cout << " Warning in REACINT: No PERMEABILITY_ZZ ele index found with PCS " << m_pcs_flow->getProcessType() + << "." + << "\n"; + + for (long n = 0; n < n_ele; n++) + { + // get material group + long n_group = m_msh->ele_vector[n]->GetPatchIndex(); + m_mat_mp = mmp_vector[n_group]; + + if ((m_mat_mp->porosity_model == 13) && (aktueller_zeitschritt == 0)) + { + n_initial = m_mat_mp->porosity_model_values[0]; + m_pcs_flow->SetElementValue(n, idx_n, n_initial); // old time level + m_pcs_flow->SetElementValue(n, idx_n + 1, n_initial); // new time level + + // Isotropic permeability + if (m_mat_mp->permeability_tensor_type == 0) + { + k_initial_xx = m_mat_mp->permeability_tensor[0]; + m_pcs_flow->SetElementValue(n, idx_k, k_initial_xx); // old time level + m_pcs_flow->SetElementValue(n, idx_k + 1, k_initial_xx); // new time level + } + // Orthogonal permeability + else if (m_mat_mp->permeability_tensor_type == 1) + { + if (m_mat_mp->GetGeoDimension() == 2) + { + k_initial_xx = m_mat_mp->permeability_tensor[0]; + k_initial_yy = m_mat_mp->permeability_tensor[1]; + + m_pcs_flow->SetElementValue(n, idx_k, k_initial_xx); // old time level + m_pcs_flow->SetElementValue(n, idx_k + 1, k_initial_xx); // new time level + + m_pcs_flow->SetElementValue(n, idx_k_yy, k_initial_yy); // old time level + m_pcs_flow->SetElementValue(n, idx_k_yy + 1, k_initial_yy); // new time level + } + else if (m_mat_mp->GetGeoDimension() == 3) + { + k_initial_xx = m_mat_mp->permeability_tensor[0]; + k_initial_yy = m_mat_mp->permeability_tensor[1]; + k_initial_zz = m_mat_mp->permeability_tensor[2]; + + m_pcs_flow->SetElementValue(n, idx_k, k_initial_xx); // old time level + m_pcs_flow->SetElementValue(n, idx_k + 1, k_initial_xx); // new time level + + m_pcs_flow->SetElementValue(n, idx_k_yy, k_initial_yy); // old time level + m_pcs_flow->SetElementValue(n, idx_k_yy + 1, k_initial_yy); // new time level + + m_pcs_flow->SetElementValue(n, idx_k_zz, k_initial_zz); // old time level + m_pcs_flow->SetElementValue(n, idx_k_zz + 1, k_initial_zz); // new time level + } + } + } + } + return; +} /************************************************************************** FEMLib-Method: PorosityVolumetricChemicalReactionupdate_kinetics @@ -1659,185 +1837,206 @@ last modification: **************************************************************************/ void REACTINT::PorosityVolumetricReactionUpdate() { - - double porosity = 0.0; // n_init=0; + double porosity = 0.0; // n_init=0; double conc_old = 0.0; double conc_new = 0.0; double change_in_conc; double mineral_volume_fraction, n_previous; - long node_idx, nnodes; - double unitfactor, phasevolume; + long node_idx, nnodes; + double unitfactor, phasevolume; - int i, j, k, l, idxC,idx_n, nImmobileComp; - int ns;//,no_processes, + int i, j, k, l, idxC, idx_n, nImmobileComp; + int ns; //,no_processes, i = j = k = l = idxC = idx_n = nImmobileComp = 0; - // the factors depend on units of concentration, molweight and mineraldensity - // I presume SI units, mol, kg, m³ - //this converts mol/m³ to m³ porosity change - if(unitconversion) - unitfactor = 1; // V=C*MW/rho*unitfactor : [-] = [mol/m³] * [kg/mol] * [m³/kg] - //this converts mol/L (or mol/kg) to L porosity change - else - unitfactor = 1000; // V=C*MW/rho*unitfactor : [-] = [mol/kg] * [kg/mol] * [m³/kg] * [kg/cm³] + // the factors depend on units of concentration, molweight and mineraldensity + // I presume SI units, mol, kg, m³ + // this converts mol/m³ to m³ porosity change + if (unitconversion) + unitfactor = 1; // V=C*MW/rho*unitfactor : [-] = [mol/m³] * [kg/mol] * [m³/kg] + // this converts mol/L (or mol/kg) to L porosity change + else + unitfactor = 1000; // V=C*MW/rho*unitfactor : [-] = [mol/kg] * [kg/mol] * [m³/kg] * [kg/cm³] - MeshLib::CElem* m_ele = NULL; + MeshLib::CElem* m_ele = NULL; CFEMesh* m_msh = fem_msh_vector[0]; - long n_ele = long(m_msh->ele_vector.size()); + long n_ele = long(m_msh->ele_vector.size()); - cout <<"Updating porosity from Chemical reaction." << "\n"; + cout << "Updating porosity from Chemical reaction." + << "\n"; - //vectorpcs_transport_comps_vector; // CB clear - vectorimmob_comps_vector; // CB clear - vectormineral_densities_vector; - vectormineral_molecular_weights_vector; + // vectorpcs_transport_comps_vector; // CB clear + vector immob_comps_vector; // CB clear + vector mineral_densities_vector; + vector mineral_molecular_weights_vector; - CRFProcess* m_pcs_flow = NULL; + CRFProcess* m_pcs_flow = NULL; m_pcs_flow = PCSGetFlow(); - idx_n = m_pcs_flow->GetElementValueIndex("POROSITY"); + idx_n = m_pcs_flow->GetElementValueIndex("POROSITY"); - // get the component data - for(i=0;itransport_phase==1){ - //pcs_transport_comps_vector.push_back(sp_pcsind[i]); - immob_comps_vector.push_back(i); - mineral_molecular_weights_vector.push_back(cp_vec[i]->molar_weight); - mineral_densities_vector.push_back(cp_vec[i]->mineral_density); - k ++; + if (cp_vec[i]->transport_phase == 1) + { + // pcs_transport_comps_vector.push_back(sp_pcsind[i]); + immob_comps_vector.push_back(i); + mineral_molecular_weights_vector.push_back(cp_vec[i]->molar_weight); + mineral_densities_vector.push_back(cp_vec[i]->mineral_density); + k++; } } nImmobileComp = k; - // CB: Instead of using the initial porosity always, we have to properly rescale concentrations - // of species by the new porosity or solid phase volume after each time step. - // see below ### - //if(unitconversion) // mineral species are defined in mol/volume solid - // phasevolume = 1-n_init; - //else // mineral species are defined in mol/kg (or L) liquid - // phasevolume = n_init; - - // loop over all nodes - nnodes = long(node_porosity.size()); - for(long n = 0; n < nnodes; n++){ - // get old porosity of node - n_previous = node_porosity[n]; - mineral_volume_fraction = 0.0; - - if(unitconversion) // mineral species are defined in mol/volume solid - phasevolume = 1-n_previous; - else // mineral species are defined in mol/kg (or L) liquid - phasevolume = n_previous; - - // Here the porosity is updated for a component - for(i = 0; i < nImmobileComp; i++) { - change_in_conc = 0.0; - l=immob_comps_vector[i]; - idxC = cp_vec[l]->getProcess()->GetNodeValueIndex(cp_vec[l]->getProcess()->pcs_primary_function_name[0]); - conc_old = cp_vec[l]->getProcess()->GetNodeValue(n, idxC);// old timelevel - conc_new = cp_vec[l]->getProcess()->GetNodeValue(n, (idxC+1));// new timelevel - change_in_conc = conc_new - conc_old; - //mineral_volume_fraction = change_in_conc[mol/m³solid]*molar_volume[m³min/mol] - // the last factor depends on units of concentration, molweight and mineraldensity - if(mineral_densities_vector[i]>0) - mineral_volume_fraction += change_in_conc* (mineral_molecular_weights_vector[i]/mineral_densities_vector[i]) *unitfactor; - else{ - cout << " Warning: mineral_density = 0 for a species in REACTINT::PorosityVolumetricReactionUpdate()" << "\n"; - cout << " PorosityVolumetricReactionUpdate() not possible" << "\n"; - } - } - porosity = n_previous - (phasevolume * mineral_volume_fraction); - // limit to reasonable values - node_porosity[n] = MRange(1e-6,porosity,1.0) ; - - //some modification for Lagneau Benchmark probably required here - //bool lagneau = false; - if(KinReactData_vector.size()>0){ - if(KinReactData_vector[0]->lagneau ){ - if(n==1) cout << " Attention: Lagneau-Benchmark with modified poro update" << "\n"; - int sp=0; - for(sp=0;spmobil==0){ - //l = sp_pcsind[sp]; - idxC = this->sp_varind[sp]; - break; - } - } - phasevolume = n_previous; - conc_old = cp_vec[sp]->getProcess()->GetNodeValue(n, idxC-1);// old timelevel - conc_new = cp_vec[sp]->getProcess()->GetNodeValue(n, (idxC));// new timelevel - change_in_conc = conc_new - conc_old; - mineral_volume_fraction = change_in_conc * (cp_vec[sp]->molar_weight/cp_vec[sp]->mineral_density) * unitfactor; - node_porosity[n] = n_previous - (phasevolume * mineral_volume_fraction); - } - } - // ### - // CB: Here, we should include a rescaling of concentrations in the phases, - // at least for solid phase concentrations - ns = cp_vec.size(); - for(i = 0; i < ns; i++) { - //l = sp_pcsind[i]; - idxC = sp_varind[i]; - conc_new = cp_vec[i]->getProcess()->GetNodeValue(n, idxC);// new timelevel - if(unitconversion){ // liquid and solid phase concentrations mol/m³phase - if(cp_vec[i]->transport_phase==1) - conc_new *= (1-n_previous)/(1-node_porosity[n]); - // for dissolved species, is this handled by dn/dt term in transport equation?? - // then comment out next two lines - else if(cp_vec[i]->transport_phase==0) - conc_new *= n_previous/node_porosity[n]; - } - else // in this case, alls species are related to liquid phase mol/kgH2O - conc_new *= n_previous/node_porosity[n]; - //pcs_vector[l]->SetNodeValue(n,idxC,conc_new); - cp_vec[i]->getProcess()->SetNodeValue(n,idxC,conc_new); - } - - } // loop over nodes - - // now set the new element porosities from node_porosity for mass transport and other processes - // loop over all elements - for(long n = 0; n < n_ele; n++){ - m_ele = m_msh->ele_vector[n]; - long nn = m_ele->GetNodesNumber(false); - porosity = 0; - for(j = 0; j < nn; j++){ - node_idx = m_ele->GetNodeIndex(j); - porosity += node_porosity[node_idx]; - } - //arithmetic average ... inverse distance? - porosity /= (double) nn; - //set the element value - m_pcs_flow->SetElementValue( n, idx_n+1, porosity ); - } - - //pcs_transport_comps_vector.clear(); - immob_comps_vector.clear(); - mineral_densities_vector.clear(); - mineral_molecular_weights_vector.clear(); - - - CTimeDiscretization *m_tim = NULL; - m_tim = time_vector[0]; - int steps = int(m_tim->time_step_vector.size()); - bool plot = false; - if(aktueller_zeitschritt == 1 || aktueller_zeitschritt % 10 == 0 || steps == int(aktueller_zeitschritt)) - plot = true; - - // debug output - if(KinReactData_vector.size()>0 && plot == true){ - if(KinReactData_vector[0]->debugoutflag){ - ofstream aus; - string file = FileName + "_node_porosities.dump"; - aus.setf(ios::scientific,ios::floatfield); - aus.precision(12); - aus.open(file.c_str()); - for(i=0;igetProcess()->GetNodeValueIndex(cp_vec[l]->getProcess()->pcs_primary_function_name[0]); + conc_old = cp_vec[l]->getProcess()->GetNodeValue(n, idxC); // old timelevel + conc_new = cp_vec[l]->getProcess()->GetNodeValue(n, (idxC + 1)); // new timelevel + change_in_conc = conc_new - conc_old; + // mineral_volume_fraction = change_in_conc[mol/m³solid]*molar_volume[m³min/mol] + // the last factor depends on units of concentration, molweight and mineraldensity + if (mineral_densities_vector[i] > 0) + mineral_volume_fraction += change_in_conc + * (mineral_molecular_weights_vector[i] / mineral_densities_vector[i]) + * unitfactor; + else + { + cout << " Warning: mineral_density = 0 for a species in REACTINT::PorosityVolumetricReactionUpdate()" + << "\n"; + cout << " PorosityVolumetricReactionUpdate() not possible" + << "\n"; + } + } + porosity = n_previous - (phasevolume * mineral_volume_fraction); + // limit to reasonable values + node_porosity[n] = MRange(1e-6, porosity, 1.0); + + // some modification for Lagneau Benchmark probably required here + // bool lagneau = false; + if (KinReactData_vector.size() > 0) + { + if (KinReactData_vector[0]->lagneau) + { + if (n == 1) + cout << " Attention: Lagneau-Benchmark with modified poro update" + << "\n"; + int sp = 0; + for (sp = 0; sp < int(cp_vec.size()); sp++) + { + if (cp_vec[sp]->mobil == 0) + { + // l = sp_pcsind[sp]; + idxC = this->sp_varind[sp]; + break; + } + } + phasevolume = n_previous; + conc_old = cp_vec[sp]->getProcess()->GetNodeValue(n, idxC - 1); // old timelevel + conc_new = cp_vec[sp]->getProcess()->GetNodeValue(n, (idxC)); // new timelevel + change_in_conc = conc_new - conc_old; + mineral_volume_fraction + = change_in_conc * (cp_vec[sp]->molar_weight / cp_vec[sp]->mineral_density) * unitfactor; + node_porosity[n] = n_previous - (phasevolume * mineral_volume_fraction); + } + } + // ### + // CB: Here, we should include a rescaling of concentrations in the phases, + // at least for solid phase concentrations + ns = cp_vec.size(); + for (i = 0; i < ns; i++) + { + // l = sp_pcsind[i]; + idxC = sp_varind[i]; + conc_new = cp_vec[i]->getProcess()->GetNodeValue(n, idxC); // new timelevel + if (unitconversion) + { // liquid and solid phase concentrations mol/m³phase + if (cp_vec[i]->transport_phase == 1) + conc_new *= (1 - n_previous) / (1 - node_porosity[n]); + // for dissolved species, is this handled by dn/dt term in transport equation?? + // then comment out next two lines + else if (cp_vec[i]->transport_phase == 0) + conc_new *= n_previous / node_porosity[n]; + } + else // in this case, alls species are related to liquid phase mol/kgH2O + conc_new *= n_previous / node_porosity[n]; + // pcs_vector[l]->SetNodeValue(n,idxC,conc_new); + cp_vec[i]->getProcess()->SetNodeValue(n, idxC, conc_new); + } + + } // loop over nodes + + // now set the new element porosities from node_porosity for mass transport and other processes + // loop over all elements + for (long n = 0; n < n_ele; n++) + { + m_ele = m_msh->ele_vector[n]; + long nn = m_ele->GetNodesNumber(false); + porosity = 0; + for (j = 0; j < nn; j++) + { + node_idx = m_ele->GetNodeIndex(j); + porosity += node_porosity[node_idx]; + } + // arithmetic average ... inverse distance? + porosity /= (double)nn; + // set the element value + m_pcs_flow->SetElementValue(n, idx_n + 1, porosity); + } + + // pcs_transport_comps_vector.clear(); + immob_comps_vector.clear(); + mineral_densities_vector.clear(); + mineral_molecular_weights_vector.clear(); + + CTimeDiscretization* m_tim = NULL; + m_tim = time_vector[0]; + int steps = int(m_tim->time_step_vector.size()); + bool plot = false; + if (aktueller_zeitschritt == 1 || aktueller_zeitschritt % 10 == 0 || steps == int(aktueller_zeitschritt)) + plot = true; + + // debug output + if (KinReactData_vector.size() > 0 && plot == true) + { + if (KinReactData_vector[0]->debugoutflag) + { + ofstream aus; + string file = FileName + "_node_porosities.dump"; + aus.setf(ios::scientific, ios::floatfield); + aus.precision(12); + aus.open(file.c_str()); + for (i = 0; i < nnodes; i++) + aus << node_porosity[i] << "\n"; + aus.close(); + } + } + + return; } /************************************************************************** @@ -1850,33 +2049,33 @@ last modification: **************************************************************************/ void REACTINT::CopySymmetricConcentrationsInRadialModel() { + // long i,j, nnodes; + // int nc = (int)cp_vec.size(); - // long i,j, nnodes; - // int nc = (int)cp_vec.size(); - - //CFEMesh* m_msh = fem_msh_vector[0]; - // nnodes = long(m_msh->nod_vector.size()); + // CFEMesh* m_msh = fem_msh_vector[0]; + // nnodes = long(m_msh->nod_vector.size()); - // CKinReactData *m_krd = NULL; - // if(KinReactData_vector.size()>0) + // CKinReactData *m_krd = NULL; + // if(KinReactData_vector.size()>0) // m_krd = KinReactData_vector[0]; - // if(m_krd == NULL){ - // // no KinReactData specified in *.krc file + // if(m_krd == NULL){ + // // no KinReactData specified in *.krc file // cout << "No CKinReactData available in CopySymmetricConcentrationsInRadialModel" << "\n"; - // return; - // } + // return; + // } - // double vecnodes[2]; + // double vecnodes[2]; - // vecnodes[0]=1; - // vecnodes[1]=2; + // vecnodes[0]=1; + // vecnodes[1]=2; - // for(i=0;jSetNodeValue( vecnodes[i], sp_varind[j], pcs_vector[sp_pcsind[j]]->GetNodeValue(i,sp_varind[j]) ); + // for(i=0;jSetNodeValue( vecnodes[i], sp_varind[j], + // pcs_vector[sp_pcsind[j]]->GetNodeValue(i,sp_varind[j]) ); - return ; + return; } /************************************************************************** @@ -1887,97 +2086,110 @@ Task: not used at the moment, functionality is currently implemented in 2.2011 CB Implementation last modification: **************************************************************************/ -void REACTINT::DumpSolidSpeciesMoles(void){ - - long i, j, nele, nnodes; - const double * coord; - MeshLib::CNode* m_nod = NULL; - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt - ofstream aus; - string filename = FileName + "_mineral_moles.tec"; - string eleType; - - if (dump_min_moles==false) - return; - - bool plot = false; - - CTimeDiscretization *m_tim = NULL; - m_tim = time_vector[0]; - int steps = int(m_tim->time_step_vector.size()); - - nnodes = (long) m_msh->nod_vector.size(); - nele = (long) m_msh->ele_vector.size(); - - CMediumProperties *m_mat_mp = NULL; - - for(long n = 0; n < nele; n++){ - long n_group = m_msh->ele_vector[n]->GetPatchIndex(); - m_mat_mp = mmp_vector[n_group]; - if (m_mat_mp->porosity_model==13){ - plot = true; - break; - } - } - - if(plot == true){ - if(aktueller_zeitschritt == 1 || aktueller_zeitschritt % ssp_outstep == 0 || steps == int(aktueller_zeitschritt)) - plot = true; - else - plot = false; - } - if(plot==false) - return; - - if (m_msh->getNumberOfLines () > 0) - eleType = "QUADRILATERAL"; - if (m_msh->getNumberOfQuads () > 0) - eleType = "QUADRILATERAL"; - if (m_msh->getNumberOfHexs () > 0) - eleType = "BRICK"; - if (m_msh->getNumberOfTris () > 0) - eleType = "QUADRILATERAL"; - if (m_msh->getNumberOfTets () > 0) - eleType = "TETRAHEDRON"; - if (m_msh->getNumberOfPrisms () > 0) - eleType = "BRICK"; - - if (aktueller_zeitschritt == 1) - aus.open(filename.c_str()); - else - aus.open(filename.c_str(), ios::app); - - //Header - aus << "VARIABLES = " << "\"x\"" << " " << "\"y\"" << " " << "\"z\"" << " " ; - for (i = 0; i < long(cp_vec.size()); i++) - if(cp_vec[i]->transport_phase==1) - aus << "\"" << cp_vec[i]->compname << "\" "; - aus << "\"" << "nodeporosity" << "\" " << "\n"; - aus << "ZONE T=" << "\"aktueller_zeitschritt=" << aktueller_zeitschritt - << "\""; - aus << ", N=" << nnodes << ", E=" << nele << " F=FEPOINT, ET=" - << eleType << "\n"; - //nodedata - aus.setf(ios::scientific,ios::floatfield); - aus.precision(12); - for (i = 0; i < nnodes; i++) - { - m_nod = m_msh->nod_vector[i]; - coord = m_nod->getData(); - aus << coord[0] << " " << coord[1] << " " << coord[2] << " "; - for (j = 0; j < long(cp_vec.size()); j++){ - if(cp_vec[j]->transport_phase==1) // plot total mol / m³ aquifer = c*(1-n) - aus << cp_vec[j]->getProcess()->GetNodeValue(i, sp_varind[j]) * (1-node_porosity[i]) << " "; - } - aus << node_porosity[i] << "\n"; - } - //eledata - for (i = 0l; i < nele; i++) - m_msh->ele_vector[i]->WriteIndex_TEC(aus); - - aus.close(); - - return; +void REACTINT::DumpSolidSpeciesMoles(void) +{ + long i, j, nele, nnodes; + const double* coord; + MeshLib::CNode* m_nod = NULL; + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt + ofstream aus; + string filename = FileName + "_mineral_moles.tec"; + string eleType; + + if (dump_min_moles == false) + return; + + bool plot = false; + + CTimeDiscretization* m_tim = NULL; + m_tim = time_vector[0]; + int steps = int(m_tim->time_step_vector.size()); + + nnodes = (long)m_msh->nod_vector.size(); + nele = (long)m_msh->ele_vector.size(); + + CMediumProperties* m_mat_mp = NULL; + + for (long n = 0; n < nele; n++) + { + long n_group = m_msh->ele_vector[n]->GetPatchIndex(); + m_mat_mp = mmp_vector[n_group]; + if (m_mat_mp->porosity_model == 13) + { + plot = true; + break; + } + } + + if (plot == true) + { + if (aktueller_zeitschritt == 1 || aktueller_zeitschritt % ssp_outstep == 0 + || steps == int(aktueller_zeitschritt)) + plot = true; + else + plot = false; + } + if (plot == false) + return; + + if (m_msh->getNumberOfLines() > 0) + eleType = "QUADRILATERAL"; + if (m_msh->getNumberOfQuads() > 0) + eleType = "QUADRILATERAL"; + if (m_msh->getNumberOfHexs() > 0) + eleType = "BRICK"; + if (m_msh->getNumberOfTris() > 0) + eleType = "QUADRILATERAL"; + if (m_msh->getNumberOfTets() > 0) + eleType = "TETRAHEDRON"; + if (m_msh->getNumberOfPrisms() > 0) + eleType = "BRICK"; + + if (aktueller_zeitschritt == 1) + aus.open(filename.c_str()); + else + aus.open(filename.c_str(), ios::app); + + // Header + aus << "VARIABLES = " + << "\"x\"" + << " " + << "\"y\"" + << " " + << "\"z\"" + << " "; + for (i = 0; i < long(cp_vec.size()); i++) + if (cp_vec[i]->transport_phase == 1) + aus << "\"" << cp_vec[i]->compname << "\" "; + aus << "\"" + << "nodeporosity" + << "\" " + << "\n"; + aus << "ZONE T=" + << "\"aktueller_zeitschritt=" << aktueller_zeitschritt << "\""; + aus << ", N=" << nnodes << ", E=" << nele << " F=FEPOINT, ET=" << eleType << "\n"; + // nodedata + aus.setf(ios::scientific, ios::floatfield); + aus.precision(12); + for (i = 0; i < nnodes; i++) + { + m_nod = m_msh->nod_vector[i]; + coord = m_nod->getData(); + aus << coord[0] << " " << coord[1] << " " << coord[2] << " "; + for (j = 0; j < long(cp_vec.size()); j++) + { + if (cp_vec[j]->transport_phase == 1) // plot total mol / m³ aquifer = c*(1-n) + aus << cp_vec[j]->getProcess()->GetNodeValue(i, sp_varind[j]) * (1 - node_porosity[i]) << " "; + } + aus << node_porosity[i] << "\n"; + } + // eledata + for (i = 0l; i < nele; i++) + m_msh->ele_vector[i]->WriteIndex_TEC(aus); + + aus.close(); + + return; } /************************************************************************** @@ -1990,50 +2202,56 @@ last modification: **************************************************************************/ void REACTINT::DumpAllVariables() { + int idx; + long nnodes; + string file; + ofstream _dump; + bool plot = false; - int idx; - long nnodes; - string file; - ofstream _dump; - bool plot = false; - - if(dump_all_pcs==false) - return; - - CTimeDiscretization *m_tim = NULL; - m_tim = time_vector[0]; - int step = int(m_tim->time_step_vector.size()); - - if(aktueller_zeitschritt % this->pcs_outstep == 0 || step == int(aktueller_zeitschritt)) - plot = true; - - if(plot == false) - return; - - nnodes = (long) fem_msh_vector[0]->nod_vector.size(); - - for(long i=0;ipcs_number_of_primary_nvals; j++){ - // each PV is stored twice: old TL, new TL - idx = pcs_vector[i]->GetNodeValueIndex(pcs_vector[i]->nod_val_name_vector[j*2])+1; - // Restartfiles ; each PV name is stored twice: old TL, new TL - file = FileName + "_" + pcs_vector[i]->nod_val_name_vector[j*2] + ".dump"; - _dump.setf(ios::scientific,ios::floatfield); - _dump.precision(12); - _dump.open(file.c_str()); - // header - _dump << "#0#0#0#1#100000#0#4.2.13 #########################################" << "\n"; - _dump << "1 1 4" << "\n" << "1 1" << "\n"; - _dump << pcs_vector[i]->nod_val_name_vector[j*2] << ", [-]" << "\n"; - // data - for(long k = 0; k < nnodes; k++) - _dump << k << " " << pcs_vector[i]->GetNodeValue(k, idx) << " " << "\n" << flush; - _dump.close(); - } - } + if (dump_all_pcs == false) + return; -} + CTimeDiscretization* m_tim = NULL; + m_tim = time_vector[0]; + int step = int(m_tim->time_step_vector.size()); + + if (aktueller_zeitschritt % this->pcs_outstep == 0 || step == int(aktueller_zeitschritt)) + plot = true; + + if (plot == false) + return; + + nnodes = (long)fem_msh_vector[0]->nod_vector.size(); + for (long i = 0; i < long(pcs_vector.size()); i++) + { + for (int j = 0; j < pcs_vector[i]->pcs_number_of_primary_nvals; j++) + { + // each PV is stored twice: old TL, new TL + idx = pcs_vector[i]->GetNodeValueIndex(pcs_vector[i]->nod_val_name_vector[j * 2]) + 1; + // Restartfiles ; each PV name is stored twice: old TL, new TL + file = FileName + "_" + pcs_vector[i]->nod_val_name_vector[j * 2] + ".dump"; + _dump.setf(ios::scientific, ios::floatfield); + _dump.precision(12); + _dump.open(file.c_str()); + // header + _dump << "#0#0#0#1#100000#0#4.2.13 #########################################" + << "\n"; + _dump << "1 1 4" + << "\n" + << "1 1" + << "\n"; + _dump << pcs_vector[i]->nod_val_name_vector[j * 2] << ", [-]" + << "\n"; + // data + for (long k = 0; k < nnodes; k++) + _dump << k << " " << pcs_vector[i]->GetNodeValue(k, idx) << " " + << "\n" + << flush; + _dump.close(); + } + } +} /************************************************************************** Task: Kill simulation when enough NAPL is infiltrated @@ -2043,101 +2261,98 @@ Task: Kill simulation when enough NAPL is infiltrated /**************************************************************************/ void REACTINT::DumpMassIntegrals() { + size_t k; + long j, i; + long nod; + double volume; // mass, + long nelems, nnodes; + string file; + ofstream _dump; + + CFEMesh* m_msh = NULL; + + std::vector massintegrals; + for (k = 0; k < cp_vec.size(); k++) + massintegrals.push_back(0); + + // m_tim = time_vector[0]; + m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt + // m_mat_mp = mmp_vector[0]; + nelems = (long)m_msh->ele_vector.size(); + // nnodes = (long) m_msh->nod_vector.size(); + + // Tecfile + file = FileName + "_masses_divide_by_phasevol.tec"; + _dump.setf(ios::scientific, ios::floatfield); + _dump.precision(12); + + if (aktueller_zeitschritt == 1) + { // new file + _dump.open(file.c_str()); + + // header + _dump << "VARIABLES = \"TIME\",\""; + for (k = 0; k < cp_vec.size(); k++) + _dump << cp_vec[k]->compname << "\",\""; + _dump << "\n" << flush; + + // integrate initial masses + for (i = 0; i < nelems; i++) + { + volume = m_msh->ele_vector[i]->GetVolume(); + nnodes = m_msh->ele_vector[i]->GetNodesNumber(false); + // mass = 0; + for (j = 0; j < nnodes; j++) + { + nod = m_msh->ele_vector[i]->GetNodeIndex(j); + for (k = 0; k < cp_vec.size(); k++) + { + massintegrals[k] += cp_vec[k]->getProcess()->GetNodeValue(nod, sp_varind[k] - 1) / nnodes * volume; + } + } + } + // output of initial masses + _dump << 0.0; + for (k = 0; k < cp_vec.size(); k++) + _dump << " " << massintegrals[k]; + _dump << "\n" << flush; + } + else + { // running model, append + _dump.open(file.c_str(), ios::app); + } - size_t k; - long j, i; - long nod; - double volume ;//mass, - long nelems, nnodes; - string file; - ofstream _dump; - - CFEMesh* m_msh = NULL; - - std::vector massintegrals; - for(k=0;kele_vector.size(); - //nnodes = (long) m_msh->nod_vector.size(); - - -// Tecfile -file = FileName + "_masses_divide_by_phasevol.tec"; - _dump.setf(ios::scientific,ios::floatfield); -_dump.precision(12); - -if(aktueller_zeitschritt == 1){ // new file - _dump.open(file.c_str()); - - // header - _dump << "VARIABLES = \"TIME\",\"" ; - for(k = 0; k < cp_vec.size(); k++) - _dump << cp_vec[k]->compname << "\",\""; - _dump << "\n"<< flush; - - // integrate initial masses - for(i = 0; i < nelems; i++){ - volume = m_msh->ele_vector[i]->GetVolume(); - nnodes = m_msh->ele_vector[i]->GetNodesNumber(false); - //mass = 0; - for(j = 0; j < nnodes; j++){ - nod = m_msh->ele_vector[i]->GetNodeIndex(j); - for(k = 0; k < cp_vec.size(); k++){ - massintegrals[k] += cp_vec[k]->getProcess()->GetNodeValue(nod, sp_varind[k]-1) / nnodes * volume; - } - } - } - // output of initial masses - _dump << 0.0 ; - for(k = 0; k < cp_vec.size(); k++) - _dump << " " << massintegrals[k] ; - _dump << "\n"<< flush; - -} -else { // running model, append - _dump.open(file.c_str(), ios::app); -} - -// integrate and output for current time step -for(k = 0; k < cp_vec.size(); k++) - massintegrals[k] = 0; -// integrate -for(i = 0; i < nelems; i++){ - volume = m_msh->ele_vector[i]->GetVolume(); - nnodes = m_msh->ele_vector[i]->GetNodesNumber(false); - //mass = 0; - for(j = 0; j < nnodes; j++){ - nod = m_msh->ele_vector[i]->GetNodeIndex(j); - for(k = 0; k < cp_vec.size(); k++){ - massintegrals[k] += cp_vec[k]->getProcess()->GetNodeValue(nod, sp_varind[k]) / nnodes * volume; - } - } -} - -// output -_dump << aktuelle_zeit ; -for(k = 0; k < cp_vec.size(); k++) - _dump << " " << massintegrals[k] ; -_dump << "\n"<< flush; + // integrate and output for current time step + for (k = 0; k < cp_vec.size(); k++) + massintegrals[k] = 0; + // integrate + for (i = 0; i < nelems; i++) + { + volume = m_msh->ele_vector[i]->GetVolume(); + nnodes = m_msh->ele_vector[i]->GetNodesNumber(false); + // mass = 0; + for (j = 0; j < nnodes; j++) + { + nod = m_msh->ele_vector[i]->GetNodeIndex(j); + for (k = 0; k < cp_vec.size(); k++) + { + massintegrals[k] += cp_vec[k]->getProcess()->GetNodeValue(nod, sp_varind[k]) / nnodes * volume; + } + } + } -// close -_dump.close(); + // output + _dump << aktuelle_zeit; + for (k = 0; k < cp_vec.size(); k++) + _dump << " " << massintegrals[k]; + _dump << "\n" << flush; -massintegrals.clear(); + // close + _dump.close(); + massintegrals.clear(); } - - - - - - /************************************************************************** FEMLib-Method: Task: Permeability will be calculated using either Kozeny-Carman or @@ -2151,169 +2366,164 @@ last modification: **************************************************************************/ void REACTINT::PermeabilityPorosityUpdate() { + // static double tensor[1]; + int idx_k = -1, idx_n = -1, idx_k_yy = -1, idx_k_zz = -1; + double k_init = 0.0, n_init = 0.0; + double n_t = 0.0, k_t = 0.0, k_t_new = 0.0; + double k_t_yy = 0.0, k_t_zz = 0.0, k_t_new_yy = 0.0; + double k_init_yy = 0.0, k_init_zz = 0.0, k_t_new_zz = 0.0; + long n; + + // CElem* m_ele = NULL; + CFEMesh* m_msh = fem_msh_vector[0]; + long n_ele = long(m_msh->ele_vector.size()); + CRFProcess* m_pcs_flow; + m_pcs_flow = PCSGetFlow(); - //static double tensor[1]; - int idx_k = -1, idx_n = -1, idx_k_yy = -1, idx_k_zz = -1; - double k_init = 0.0, n_init = 0.0; - double n_t = 0.0, k_t = 0.0, k_t_new = 0.0; - double k_t_yy = 0.0, k_t_zz = 0.0, k_t_new_yy = 0.0; - double k_init_yy =0.0, k_init_zz = 0.0, k_t_new_zz = 0.0; - long n; - - //CElem* m_ele = NULL; - CFEMesh* m_msh = fem_msh_vector[0]; - long n_ele = long(m_msh->ele_vector.size()); - CRFProcess *m_pcs_flow; - m_pcs_flow = PCSGetFlow(); - - // get variable index - idx_n = m_pcs_flow->GetElementValueIndex("POROSITY"); - idx_k = m_pcs_flow->GetElementValueIndex("PERMEABILITY"); - idx_k_yy = m_pcs_flow->GetElementValueIndex("PERMEABILITY_YY"); - idx_k_zz = m_pcs_flow->GetElementValueIndex("PERMEABILITY_ZZ"); - - // get medium property - CMediumProperties *m_mat_mp = NULL; - - for(n = 0; n < n_ele; n++){ - - // get material group - long n_group = m_msh->ele_vector[n]->GetPatchIndex(); - m_mat_mp = mmp_vector[n_group]; - - // Permeability updating is not required - if (((m_mat_mp->permeability_tensor_type!= 0) || (m_mat_mp->permeability_tensor_type!= 1))&& m_mat_mp->permeability_model != 8 ) - return; - - if(n==0) cout <<"Updating Permeability:" << "\n"; - - // get current & initial porosity: n_t, n_init. - n_init = m_mat_mp->porosity_model_values[0]; - n_t = m_pcs_flow->GetElementValue( n, idx_n+1 ); // new time level, recently set in PorosityVolumetricReactionUpdate - //double test1 = m_pcs_flow->GetElementValue( n, idx_n ); - //if(n==1) - // cout << test1 << " " << n_init << " " << n_t << "\n"; - - - if (m_mat_mp->permeability_tensor_type == 0){ - - k_init = m_mat_mp->permeability_tensor[0]; - - // get and save old permeability - k_t = m_pcs_flow->GetElementValue( n, idx_k + 1 ); - m_pcs_flow->SetElementValue( n, idx_k, k_t); - //double test = m_pcs_flow->GetElementValue( n, idx_k); - - - /*/ ***************************************************** /*/ - // If Kozeny-Carman formulation is choosen - if(m_mat_mp->permeability_porosity_updating_type == 0){ - - // Calculate for the new perm. k_t_new - k_t_new = m_mat_mp->KozenyCarmanNew( k_init,n_init,n_t ); - } - - // If Verma-Pruess formulation is choosen - else if(m_mat_mp->permeability_porosity_updating_type == 1){ - - // Calculate for the new perm. k_t_new - k_t_new = m_mat_mp->VermaPruess( k_init,n_init,n_t ); - } - /*/ ***************************************************** /*/ - - // save new permeability: in index+1 - m_pcs_flow->SetElementValue( n, idx_k+1, k_t_new ); - //double test_2 = m_pcs_flow->GetElementValue( n, idx_k+1); - - /*/ ***************************************************** /*/ - } - - if (m_mat_mp->permeability_tensor_type == 1){ - - if (m_mat_mp->GetGeoDimension()==2){ - - k_init = m_mat_mp->permeability_tensor[0]; - k_init_yy = m_mat_mp->permeability_tensor[1]; - - // get and save old permeability - k_t = m_pcs_flow->GetElementValue( n, idx_k + 1 ); - k_t_yy = m_pcs_flow->GetElementValue( n, idx_k_yy + 1 ); - m_pcs_flow->SetElementValue( n, idx_k, k_t); - m_pcs_flow->SetElementValue( n, idx_k_yy, k_t_yy); - - - /*/ ***************************************************** /*/ - // If Kozeny-Carman formulation is choosen - if(m_mat_mp->permeability_porosity_updating_type == 0){ - - k_t_new = m_mat_mp->KozenyCarmanNew( k_init,n_init,n_t ); - k_t_new_yy = m_mat_mp->KozenyCarmanNew( k_init_yy,n_init,n_t ); - } - - // If Verma-Pruess formulation is choosen - else if(m_mat_mp->permeability_porosity_updating_type == 1){ + // get variable index + idx_n = m_pcs_flow->GetElementValueIndex("POROSITY"); + idx_k = m_pcs_flow->GetElementValueIndex("PERMEABILITY"); + idx_k_yy = m_pcs_flow->GetElementValueIndex("PERMEABILITY_YY"); + idx_k_zz = m_pcs_flow->GetElementValueIndex("PERMEABILITY_ZZ"); - k_t_new = m_mat_mp->VermaPruess( k_init,n_init,n_t ); - k_t_new_yy = m_mat_mp->VermaPruess( k_init_yy,n_init,n_t ); - } - /*/ ***************************************************** /*/ + // get medium property + CMediumProperties* m_mat_mp = NULL; - // save new permeability: in index+1 - m_pcs_flow->SetElementValue( n, idx_k+1, k_t_new ); - m_pcs_flow->SetElementValue( n, idx_k_yy+1, k_t_new_yy ); + for (n = 0; n < n_ele; n++) + { + // get material group + long n_group = m_msh->ele_vector[n]->GetPatchIndex(); + m_mat_mp = mmp_vector[n_group]; + + // Permeability updating is not required + if (((m_mat_mp->permeability_tensor_type != 0) || (m_mat_mp->permeability_tensor_type != 1)) + && m_mat_mp->permeability_model != 8) + return; + + if (n == 0) + cout << "Updating Permeability:" + << "\n"; + + // get current & initial porosity: n_t, n_init. + n_init = m_mat_mp->porosity_model_values[0]; + n_t = m_pcs_flow->GetElementValue( + n, idx_n + 1); // new time level, recently set in PorosityVolumetricReactionUpdate + // double test1 = m_pcs_flow->GetElementValue( n, idx_n ); + // if(n==1) + // cout << test1 << " " << n_init << " " << n_t << "\n"; + + if (m_mat_mp->permeability_tensor_type == 0) + { + k_init = m_mat_mp->permeability_tensor[0]; + + // get and save old permeability + k_t = m_pcs_flow->GetElementValue(n, idx_k + 1); + m_pcs_flow->SetElementValue(n, idx_k, k_t); + // double test = m_pcs_flow->GetElementValue( n, idx_k); + + /*/ ***************************************************** /*/ + // If Kozeny-Carman formulation is choosen + if (m_mat_mp->permeability_porosity_updating_type == 0) + { + // Calculate for the new perm. k_t_new + k_t_new = m_mat_mp->KozenyCarmanNew(k_init, n_init, n_t); + } - /*/ ***************************************************** /*/ - } + // If Verma-Pruess formulation is choosen + else if (m_mat_mp->permeability_porosity_updating_type == 1) + { + // Calculate for the new perm. k_t_new + k_t_new = m_mat_mp->VermaPruess(k_init, n_init, n_t); + } + /*/ ***************************************************** /*/ - if (m_mat_mp->GetGeoDimension() ==3){ + // save new permeability: in index+1 + m_pcs_flow->SetElementValue(n, idx_k + 1, k_t_new); + // double test_2 = m_pcs_flow->GetElementValue( n, idx_k+1); - k_init = m_mat_mp->permeability_tensor[0]; - k_init_yy = m_mat_mp->permeability_tensor[1]; - k_init_zz = m_mat_mp->permeability_tensor[2]; + /*/ ***************************************************** /*/ + } - // get and save old permeability - k_t = m_pcs_flow->GetElementValue( n, idx_k + 1 ); - k_t_yy = m_pcs_flow->GetElementValue( n, idx_k_yy + 1 ); - k_t_zz = m_pcs_flow->GetElementValue( n, idx_k_zz + 1 ); - m_pcs_flow->SetElementValue( n, idx_k, k_t); - m_pcs_flow->SetElementValue( n, idx_k_yy, k_t_yy); - m_pcs_flow->SetElementValue( n, idx_k_zz, k_t_zz); + if (m_mat_mp->permeability_tensor_type == 1) + { + if (m_mat_mp->GetGeoDimension() == 2) + { + k_init = m_mat_mp->permeability_tensor[0]; + k_init_yy = m_mat_mp->permeability_tensor[1]; + + // get and save old permeability + k_t = m_pcs_flow->GetElementValue(n, idx_k + 1); + k_t_yy = m_pcs_flow->GetElementValue(n, idx_k_yy + 1); + m_pcs_flow->SetElementValue(n, idx_k, k_t); + m_pcs_flow->SetElementValue(n, idx_k_yy, k_t_yy); + + /*/ ***************************************************** /*/ + // If Kozeny-Carman formulation is choosen + if (m_mat_mp->permeability_porosity_updating_type == 0) + { + k_t_new = m_mat_mp->KozenyCarmanNew(k_init, n_init, n_t); + k_t_new_yy = m_mat_mp->KozenyCarmanNew(k_init_yy, n_init, n_t); + } + // If Verma-Pruess formulation is choosen + else if (m_mat_mp->permeability_porosity_updating_type == 1) + { + k_t_new = m_mat_mp->VermaPruess(k_init, n_init, n_t); + k_t_new_yy = m_mat_mp->VermaPruess(k_init_yy, n_init, n_t); + } + /*/ ***************************************************** /*/ - /*/ ***************************************************** /*/ - // If Kozeny-Carman formulation is choosen - if(m_mat_mp->permeability_porosity_updating_type == 0){ + // save new permeability: in index+1 + m_pcs_flow->SetElementValue(n, idx_k + 1, k_t_new); + m_pcs_flow->SetElementValue(n, idx_k_yy + 1, k_t_new_yy); - k_t_new = m_mat_mp->KozenyCarmanNew( k_init,n_init,n_t ); - k_t_new_yy = m_mat_mp->KozenyCarmanNew( k_init_yy,n_init,n_t ); - k_t_new_zz = m_mat_mp->KozenyCarmanNew( k_init_zz,n_init,n_t ); - } + /*/ ***************************************************** /*/ + } - // If Verma-Pruess formulation is choosen - else if(m_mat_mp->permeability_porosity_updating_type == 1){ + if (m_mat_mp->GetGeoDimension() == 3) + { + k_init = m_mat_mp->permeability_tensor[0]; + k_init_yy = m_mat_mp->permeability_tensor[1]; + k_init_zz = m_mat_mp->permeability_tensor[2]; + + // get and save old permeability + k_t = m_pcs_flow->GetElementValue(n, idx_k + 1); + k_t_yy = m_pcs_flow->GetElementValue(n, idx_k_yy + 1); + k_t_zz = m_pcs_flow->GetElementValue(n, idx_k_zz + 1); + m_pcs_flow->SetElementValue(n, idx_k, k_t); + m_pcs_flow->SetElementValue(n, idx_k_yy, k_t_yy); + m_pcs_flow->SetElementValue(n, idx_k_zz, k_t_zz); + + /*/ ***************************************************** /*/ + // If Kozeny-Carman formulation is choosen + if (m_mat_mp->permeability_porosity_updating_type == 0) + { + k_t_new = m_mat_mp->KozenyCarmanNew(k_init, n_init, n_t); + k_t_new_yy = m_mat_mp->KozenyCarmanNew(k_init_yy, n_init, n_t); + k_t_new_zz = m_mat_mp->KozenyCarmanNew(k_init_zz, n_init, n_t); + } - k_t_new = m_mat_mp->VermaPruess( k_init,n_init,n_t ); - k_t_new_yy = m_mat_mp->VermaPruess( k_init_yy,n_init,n_t ); - k_t_new_zz = m_mat_mp->VermaPruess( k_init_zz,n_init,n_t ); - } - /*/ ***************************************************** /*/ + // If Verma-Pruess formulation is choosen + else if (m_mat_mp->permeability_porosity_updating_type == 1) + { + k_t_new = m_mat_mp->VermaPruess(k_init, n_init, n_t); + k_t_new_yy = m_mat_mp->VermaPruess(k_init_yy, n_init, n_t); + k_t_new_zz = m_mat_mp->VermaPruess(k_init_zz, n_init, n_t); + } + /*/ ***************************************************** /*/ - // save new permeability: in index+1 - m_pcs_flow->SetElementValue( n, idx_k+1, k_t_new ); - m_pcs_flow->SetElementValue( n, idx_k_yy+1, k_t_new_yy ); - m_pcs_flow->SetElementValue( n, idx_k_zz+1, k_t_new_zz ); + // save new permeability: in index+1 + m_pcs_flow->SetElementValue(n, idx_k + 1, k_t_new); + m_pcs_flow->SetElementValue(n, idx_k_yy + 1, k_t_new_yy); + m_pcs_flow->SetElementValue(n, idx_k_zz + 1, k_t_new_zz); - /*/ ***************************************************** /*/ - } - } - } - return ; + /*/ ***************************************************** /*/ + } + } + } + return; } - - - - /************************************************************************** ReacInt-Method: Task: Convert name (chemical formula) of species to indices @@ -2323,18 +2533,19 @@ void REACTINT::PermeabilityPorosityUpdate() //DL 01.2011 DL First implementation **************************************************************************/ -std::vector REACTINT::formula2index(std::string formula){ - const string Chemical_Element[10]={"Li", "Na", "K", "Mg", "Ca", "Cl", "S", "C", "H", "O"}; - int i,j,n,symb_asc,is_bracket; - vector id_iz,type_x; +std::vector REACTINT::formula2index(std::string formula) +{ + const string Chemical_Element[10] = {"Li", "Na", "K", "Mg", "Ca", "Cl", "S", "C", "H", "O"}; + int i, j, n, symb_asc, is_bracket; + vector id_iz, type_x; vector bracket_ia, bracket_ib, bracket_iz, bracket_ia0, bracket_ib0; // CB clear vector element_ia, element_ib, element_iz; - vector number_ia, number_ib, number_iz; + vector number_ia, number_ib, number_iz; vector element_name; id_iz.clear(); type_x.clear(); - n=int(formula.size()); + n = int(formula.size()); element_ia.clear(); element_ib.clear(); @@ -2345,253 +2556,278 @@ std::vector REACTINT::formula2index(std::string formula){ number_ib.clear(); number_iz.clear(); - bracket_ia.clear(); //to store begin position of bracket - bracket_ib.clear(); //to store end position of bracket + bracket_ia.clear(); // to store begin position of bracket + bracket_ib.clear(); // to store end position of bracket bracket_iz.clear(); bracket_ia0.clear(); bracket_ib0.clear(); // 0-A-Z, 1-a-z, 2-0-9, 3-[(, 4-]), 5-others - for(i=0;i=65 && symb_asc<=90) //A-Z + if (symb_asc >= 65 && symb_asc <= 90) // A-Z type_x.push_back(0); - else if(symb_asc>=97 && symb_asc<=122) //a-z + else if (symb_asc >= 97 && symb_asc <= 122) // a-z type_x.push_back(1); - else if(symb_asc>=48 && symb_asc<=57) //0-9 + else if (symb_asc >= 48 && symb_asc <= 57) // 0-9 type_x.push_back(2); - else if(symb_asc==40 || symb_asc==91) // [( + else if (symb_asc == 40 || symb_asc == 91) // [( type_x.push_back(3); - else if(symb_asc==41 || symb_asc==93) // ]) + else if (symb_asc == 41 || symb_asc == 93) // ]) type_x.push_back(4); else type_x.push_back(5); } - type_x.push_back(-1); //set string end mark - + type_x.push_back(-1); // set string end mark // 0-A-Z, 1-a-z, 2-0-9, 3-[(, 4-]), 5-others - //search for chemical elements - for(i=0;i0 && type_x[i-1]!=2) + else if (type_x[i] == 2) + { + if (i > 0 && type_x[i - 1] != 2) number_ia.push_back(i); - if(i>0 && type_x[i]==2 && type_x[i+1]!=2) + if (i > 0 && type_x[i] == 2 && type_x[i + 1] != 2) number_ib.push_back(i); - } - else if(type_x[i]==3) + } + else if (type_x[i] == 3) bracket_ia0.push_back(i); - else if(type_x[i]==4) + else if (type_x[i] == 4) bracket_ib0.push_back(i); } - //to check the bracket symb is correct or not, e.g. (( ... )) - for(i=0;i<(int)bracket_ia0.size();i++){ - is_bracket=0; - for(j=0;j<(int)bracket_ib0.size();j++){ - if(i==(int)bracket_ia0.size()-1){ - if(bracket_ib0[j]>bracket_ia0[i]) - is_bracket=1; + // to check the bracket symb is correct or not, e.g. (( ... )) + for (i = 0; i < (int)bracket_ia0.size(); i++) + { + is_bracket = 0; + for (j = 0; j < (int)bracket_ib0.size(); j++) + { + if (i == (int)bracket_ia0.size() - 1) + { + if (bracket_ib0[j] > bracket_ia0[i]) + is_bracket = 1; } - else{ - if(bracket_ib0[j]>bracket_ia0[i] && bracket_ib0[j] bracket_ia0[i] && bracket_ib0[j] < bracket_ia0[i + 1]) + is_bracket = 1; } } - if(is_bracket==1) + if (is_bracket == 1) bracket_ia.push_back(bracket_ia0[i]); } - for(i=0;i<(int)bracket_ib0.size();i++){ - is_bracket=0; - for(j=0;j<(int)bracket_ia0.size();j++){ - if(i==0){ - if(bracket_ia0[j]bracket_ib0[i-1]) - is_bracket=1; + else + { + if (bracket_ia0[j] < bracket_ib0[i] && bracket_ia0[j] > bracket_ib0[i - 1]) + is_bracket = 1; } } - if(is_bracket==1) + if (is_bracket == 1) bracket_ib.push_back(bracket_ib0[i]); } + for (i = 0; i < (int)number_ia.size(); i++) + number_iz.push_back(atoi(formula.substr(number_ia[i], number_ib[i] - number_ia[i] + 1).c_str())); - - for(i=0;i<(int)number_ia.size();i++) - number_iz.push_back(atoi(formula.substr(number_ia[i],number_ib[i]-number_ia[i]+1).c_str())); - - for(i=0;i<(int)element_name.size();i++) - if(type_x[element_ib[i]+1]==2) - for(j=0;j<(int)number_iz.size();j++){ - if(element_ib[i]+1==number_ia[j]) + for (i = 0; i < (int)element_name.size(); i++) + if (type_x[element_ib[i] + 1] == 2) + for (j = 0; j < (int)number_iz.size(); j++) + { + if (element_ib[i] + 1 == number_ia[j]) element_iz.push_back(number_iz[j]); } else element_iz.push_back(1); - for(i=0;i<(int)bracket_ia.size();i++) - if(type_x[bracket_ib[i]+1]==2) - for(j=0;j<(int)number_iz.size();j++){ - if(bracket_ib[i]+1==number_ia[j]) + for (i = 0; i < (int)bracket_ia.size(); i++) + if (type_x[bracket_ib[i] + 1] == 2) + for (j = 0; j < (int)number_iz.size(); j++) + { + if (bracket_ib[i] + 1 == number_ia[j]) bracket_iz.push_back(number_iz[j]); } else bracket_iz.push_back(1); - for(i=0;i<(int)bracket_ia.size();i++) - for(j=0;j<(int)element_ia.size();j++) - if(element_ia[j]>bracket_ia[i] && element_ib[j] bracket_ia[i] && element_ib[j] < bracket_ib[i]) element_iz[j] *= bracket_iz[i]; - for(i=0;i<10;i++){ + for (i = 0; i < 10; i++) + { id_iz.push_back(0); - for(j=0;j REACTINT::string2vector(std::string line){ +// split string line to pieces, and store in a vector +vector REACTINT::string2vector(std::string line) +{ stringstream in; std::string sp; vector pies; pies.clear(); in.str(line); - while(1){ - if(in.eof()) break; - sp=""; + while (1) + { + if (in.eof()) + break; + sp = ""; in >> sp; - if(sp!="") pies.push_back(sp); + if (sp != "") + pies.push_back(sp); } return pies; } - /**************************************************************************/ /* Return the volume fraction of a particular phase at a node */ /* 0 pore space, 1 solid phase, 2 bio phase */ /* DS-TBC */ /* 09/2009 CB Introduced new C++ concept, Data structures */ /**************************************************************************/ -double GetNodePhaseVolume(long node, double theta, int phase){ - - CMediumProperties *m_mat_mp = NULL; - MeshLib::CNode* m_nod = NULL; - MeshLib::CElem* m_ele = NULL; - //OK411 CRFProcess *m_pcs = NULL; - CFEMesh* m_msh = fem_msh_vector[0]; //SB: ToDo hart gesetzt - - long idx=0, i, el, elem ,group; //OK411 - const double * coord; - double distance, weight, sum_w ; - const double* grav_c; - double vol = 0, poro = 0; - - // get Indices for phase 1 or 2, only if heterogeneous porosity model = 11, i.e. vol_mat_model = vol_bio_model = 2 - group = 0; //SB todo group = m_ele->GetPatchIndex(); Todo CB - m_mat_mp = mmp_vector[group]; - if(m_mat_mp->vol_bio_model == 2 && m_mat_mp->vol_mat_model == 2 ){ - CFEMesh* _mmesh = m_mat_mp->getMesh(); - switch(phase) { - case 1: //solid phase - // Get VOL_MAT index - for(idx=0;idx<(int)_mmesh->mat_names_vector.size();idx++){ - if(_mmesh->mat_names_vector[idx].compare("VOL_MAT")==0) break; - } - break; - case 2: //bio phase - // Get VOL_BIO index - for(idx=0;idx<(int)_mmesh->mat_names_vector.size();idx++){ - if(_mmesh->mat_names_vector[idx].compare("VOL_BIO")==0) break; - } - break; - default: - break; - } - } - - // initialize data structures - sum_w = 0; - - // Get node coordinates - m_nod = m_msh->nod_vector[node]; - coord = m_nod->getData(); - - for(el=0;el<(int)m_nod->getConnectedElementIDs().size();el++){ - // initialize for each connected element - distance = weight = poro = 0; - // Get the connected element - elem = m_nod->getConnectedElementIDs()[el]; // element index - m_ele = m_msh->ele_vector[elem]; - //get the phase volume of current element elem - group = m_ele->GetPatchIndex(); - m_mat_mp = mmp_vector[group]; - switch(phase) { - case 0: //pore space - poro = m_mat_mp->Porosity(elem, theta); // CB Now provides also heterogeneous porosity, model 11 - break; - case 1: //solid phase - if(m_mat_mp->vol_mat_model == 1) // homogeneous - poro = m_mat_mp->vol_mat; - else if(m_mat_mp->vol_mat_model == 2) // CB heterogeneous - poro = m_ele->mat_vector(idx) ; - else - cout << "Warning! No valid VOL_MAT model in CKinReact::GetPhaseVolumeAtNode, vol_mat_model =" << m_mat_mp->vol_mat_model << "\n"; - break; - case 2: //bio phase - if(m_mat_mp->vol_bio_model == 1) // homogeneous - poro = m_mat_mp->vol_bio; - else if(m_mat_mp->vol_bio_model == 2) // CB heterogeneous - poro = m_ele->mat_vector(idx) ; - else - cout << "Warning! No valid VOL_BIO model in CKinReact::GetPhaseVolumeAtNode, vol_bio_model =" << m_mat_mp->vol_bio_model << "\n"; - break; - case 3: // NAPL phase (refers to REV) - poro = 1.0; - break; - default: - cout << "Error in CKinReact::GetPhaseVolumeAtNode: no valid phase" << "\n"; - break; - } - // calculate distance node <-> element center of gravity - grav_c = m_ele->GetGravityCenter(); - for(i=0;i<3;i++) - distance += pow((coord[i]-grav_c[i]),2); - // linear inverse distance weight = 1/(distance) - distance = sqrt(distance);// for quadratic interpolation uncomment this line - weight=(1/distance); - sum_w += weight; - // add the weighted phase volume - vol += poro*weight; - } // loop over connected elements - - // normalize weighted sum by sum_of_weights sum_w - vol *= 1/sum_w; - if(sum_w==0) - vol = 0.99; - return vol; -} +double GetNodePhaseVolume(long node, double theta, int phase) +{ + CMediumProperties* m_mat_mp = NULL; + MeshLib::CNode* m_nod = NULL; + MeshLib::CElem* m_ele = NULL; + // OK411 CRFProcess *m_pcs = NULL; + CFEMesh* m_msh = fem_msh_vector[0]; // SB: ToDo hart gesetzt + + long idx = 0, i, el, elem, group; // OK411 + const double* coord; + double distance, weight, sum_w; + const double* grav_c; + double vol = 0, poro = 0; + + // get Indices for phase 1 or 2, only if heterogeneous porosity model = 11, i.e. vol_mat_model = vol_bio_model = 2 + group = 0; // SB todo group = m_ele->GetPatchIndex(); Todo CB + m_mat_mp = mmp_vector[group]; + if (m_mat_mp->vol_bio_model == 2 && m_mat_mp->vol_mat_model == 2) + { + CFEMesh* _mmesh = m_mat_mp->getMesh(); + switch (phase) + { + case 1: // solid phase + // Get VOL_MAT index + for (idx = 0; idx < (int)_mmesh->mat_names_vector.size(); idx++) + { + if (_mmesh->mat_names_vector[idx].compare("VOL_MAT") == 0) + break; + } + break; + case 2: // bio phase + // Get VOL_BIO index + for (idx = 0; idx < (int)_mmesh->mat_names_vector.size(); idx++) + { + if (_mmesh->mat_names_vector[idx].compare("VOL_BIO") == 0) + break; + } + break; + default: + break; + } + } + + // initialize data structures + sum_w = 0; + // Get node coordinates + m_nod = m_msh->nod_vector[node]; + coord = m_nod->getData(); + + for (el = 0; el < (int)m_nod->getConnectedElementIDs().size(); el++) + { + // initialize for each connected element + distance = weight = poro = 0; + // Get the connected element + elem = m_nod->getConnectedElementIDs()[el]; // element index + m_ele = m_msh->ele_vector[elem]; + // get the phase volume of current element elem + group = m_ele->GetPatchIndex(); + m_mat_mp = mmp_vector[group]; + switch (phase) + { + case 0: // pore space + poro = m_mat_mp->Porosity(elem, theta); // CB Now provides also heterogeneous porosity, model 11 + break; + case 1: // solid phase + if (m_mat_mp->vol_mat_model == 1) // homogeneous + poro = m_mat_mp->vol_mat; + else if (m_mat_mp->vol_mat_model == 2) // CB heterogeneous + poro = m_ele->mat_vector(idx); + else + cout << "Warning! No valid VOL_MAT model in CKinReact::GetPhaseVolumeAtNode, vol_mat_model =" + << m_mat_mp->vol_mat_model << "\n"; + break; + case 2: // bio phase + if (m_mat_mp->vol_bio_model == 1) // homogeneous + poro = m_mat_mp->vol_bio; + else if (m_mat_mp->vol_bio_model == 2) // CB heterogeneous + poro = m_ele->mat_vector(idx); + else + cout << "Warning! No valid VOL_BIO model in CKinReact::GetPhaseVolumeAtNode, vol_bio_model =" + << m_mat_mp->vol_bio_model << "\n"; + break; + case 3: // NAPL phase (refers to REV) + poro = 1.0; + break; + default: + cout << "Error in CKinReact::GetPhaseVolumeAtNode: no valid phase" + << "\n"; + break; + } + // calculate distance node <-> element center of gravity + grav_c = m_ele->GetGravityCenter(); + for (i = 0; i < 3; i++) + distance += pow((coord[i] - grav_c[i]), 2); + // linear inverse distance weight = 1/(distance) + distance = sqrt(distance); // for quadratic interpolation uncomment this line + weight = (1 / distance); + sum_w += weight; + // add the weighted phase volume + vol += poro * weight; + } // loop over connected elements + + // normalize weighted sum by sum_of_weights sum_w + vol *= 1 / sum_w; + if (sum_w == 0) + vol = 0.99; + return vol; +} /*****************************************************************************************/ /* Calculate the reference volume of a phase at a node */ @@ -2600,51 +2836,53 @@ double GetNodePhaseVolume(long node, double theta, int phase){ /* 08/2008 DS Consider saturation of water phase in case of multiphase flow */ /* 09/2009 CB Heterogeneous Porosities update */ /*****************************************************************************************/ -double REACTINT::GetWaterSaturation( long index ){ - - double saturation=1; - int timelevel = 1; - CRFProcess *m_pcs=NULL; - int idx; - // special case for initial computation - // saturation is not yet set for new time level - if(aktueller_zeitschritt==0) timelevel = 0; - - switch(flowtype){ - case 0: - break; - case 1: //Groundwater Flow //Liquid_Flow - break; - case 66: //Overland Flow - break; - case 5: //Air Flow - break; - case 11: //Componental Flow - break; - case 1212: //Multiphase Flow - m_pcs = PCSGetFlow(); - idx = m_pcs->GetNodeValueIndex("SATURATION1"); // Sat of water phase - saturation = m_pcs->GetNodeValue(index, idx + timelevel); - break; - case 12: // Two_phase_Flow - m_pcs = PCSGetFlow(); - idx = m_pcs->GetNodeValueIndex("SATURATION1"); // Sat of water phase - saturation = m_pcs->GetNodeValue(index, idx + timelevel); - break; - case 1313: // PS_GLOBAL - m_pcs = PCSGetFlow(); - idx = m_pcs->GetNodeValueIndex("SATURATION1"); // Sat of water phase - saturation = m_pcs->GetNodeValue(index, idx + timelevel); - break; - case 22: // Richards flow - m_pcs = PCSGetFlow(); - idx = m_pcs->GetNodeValueIndex("SATURATION1"); // Sat of water phase - saturation = m_pcs->GetNodeValue(index, idx + timelevel); - break; - default: - break; - } - return saturation; +double REACTINT::GetWaterSaturation(long index) +{ + double saturation = 1; + int timelevel = 1; + CRFProcess* m_pcs = NULL; + int idx; + // special case for initial computation + // saturation is not yet set for new time level + if (aktueller_zeitschritt == 0) + timelevel = 0; + + switch (flowtype) + { + case 0: + break; + case 1: // Groundwater Flow //Liquid_Flow + break; + case 66: // Overland Flow + break; + case 5: // Air Flow + break; + case 11: // Componental Flow + break; + case 1212: // Multiphase Flow + m_pcs = PCSGetFlow(); + idx = m_pcs->GetNodeValueIndex("SATURATION1"); // Sat of water phase + saturation = m_pcs->GetNodeValue(index, idx + timelevel); + break; + case 12: // Two_phase_Flow + m_pcs = PCSGetFlow(); + idx = m_pcs->GetNodeValueIndex("SATURATION1"); // Sat of water phase + saturation = m_pcs->GetNodeValue(index, idx + timelevel); + break; + case 1313: // PS_GLOBAL + m_pcs = PCSGetFlow(); + idx = m_pcs->GetNodeValueIndex("SATURATION1"); // Sat of water phase + saturation = m_pcs->GetNodeValue(index, idx + timelevel); + break; + case 22: // Richards flow + m_pcs = PCSGetFlow(); + idx = m_pcs->GetNodeValueIndex("SATURATION1"); // Sat of water phase + saturation = m_pcs->GetNodeValue(index, idx + timelevel); + break; + default: + break; + } + return saturation; } /************************************************************************** FEMLib-Method: @@ -2660,130 +2898,137 @@ last modification: **************************************************************************/ double REACTINT::LiquidViscosity_Yaws_1976(double T) { - double ln_my,my; - double A,B,C,D; - - A = -2.471e+01; - B = 4.209e+03; - C = 4.527e-02; - D = -3.376e-5; - - //A = -11.6225; //values for water viscosity after YAWS et al. (1976) - //B = 1.9490e+03; - //C = 2.1641e-02; - //D = -1.5990e-05; - - ln_my = A + B/T + C*T + D*T*T; - //my = pow(10.0, ln_my); - my = exp(ln_my); // CB exp --> pow(10) /* in cP */ - my *= 1.e-3; /* in Pa s */ - return my; + double ln_my, my; + double A, B, C, D; + + A = -2.471e+01; + B = 4.209e+03; + C = 4.527e-02; + D = -3.376e-5; + + // A = -11.6225; //values for water viscosity after YAWS et al. (1976) + // B = 1.9490e+03; + // C = 2.1641e-02; + // D = -1.5990e-05; + + ln_my = A + B / T + C * T + D * T * T; + // my = pow(10.0, ln_my); + my = exp(ln_my); // CB exp --> pow(10) /* in cP */ + my *= 1.e-3; /* in Pa s */ + return my; } - double REACTINT::LiquidDensity_Busch(double T) { - double density; - double rho_0, T_0, drho_dT; + double density; + double rho_0, T_0, drho_dT; - rho_0 = 998.203; - T_0 = 293; - drho_dT = -2.5e-4; + rho_0 = 998.203; + T_0 = 293; + drho_dT = -2.5e-4; - // rho(T) = rho_0*(1+beta_T*(T-T_0)) - density = rho_0 * (1.0 + drho_dT * (max(T,0.0) - T_0) ); + // rho(T) = rho_0*(1+beta_T*(T-T_0)) + density = rho_0 * (1.0 + drho_dT * (max(T, 0.0) - T_0)); - return density; + return density; } - - // External Functions //----for pressure update at fixed phases conditions---- // 2012.06.13 DL -void VLE_CalcNewPressure(double T, double &P, double &V_gas, double &V_liquid, double CO2_gas_old, double CO2_gas_new, double CO2_liquid_old, double CO2_liquid_new, double H2O_liquid_old, double H2O_liquid_new, double &rho){ - Phase_Properties2 gas,liquid,solid; - int f=1; +void VLE_CalcNewPressure(double T, double& P, double& V_gas, double& V_liquid, double CO2_gas_old, double CO2_gas_new, + double CO2_liquid_old, double CO2_liquid_new, double H2O_liquid_old, double H2O_liquid_new, + double& rho) +{ + Phase_Properties2 gas, liquid, solid; + int f = 1; - gas.CO2=CO2_gas_old; - gas.H2O=0.0; - gas.NaCl=0.0; + gas.CO2 = CO2_gas_old; + gas.H2O = 0.0; + gas.NaCl = 0.0; - liquid.CO2=CO2_liquid_old; - liquid.H2O=H2O_liquid_old; - liquid.NaCl=0.0; + liquid.CO2 = CO2_liquid_old; + liquid.H2O = H2O_liquid_old; + liquid.NaCl = 0.0; - solid.CO2=0.0; - solid.H2O=0.0; - solid.NaCl=0.0; + solid.CO2 = 0.0; + solid.H2O = 0.0; + solid.NaCl = 0.0; - VLE_isobaric_fixphase(T,P,gas,liquid,solid,f); + VLE_isobaric_fixphase(T, P, gas, liquid, solid, f); - gas.CO2=CO2_gas_new; - liquid.CO2=CO2_liquid_new; - liquid.H2O=H2O_liquid_new; + gas.CO2 = CO2_gas_new; + liquid.CO2 = CO2_liquid_new; + liquid.H2O = H2O_liquid_new; - VLE_isochoric_fixphase(T,P,gas,liquid,solid,f); + VLE_isochoric_fixphase(T, P, gas, liquid, solid, f); - V_gas=gas.volume; - V_liquid=liquid.volume; - rho = VLE::density_CO2(T,P); //to use mixture fluid EoS + V_gas = gas.volume; + V_liquid = liquid.volume; + rho = VLE::density_CO2(T, P); // to use mixture fluid EoS } -void VLE_isobaric_fixphase(double T, double P, Phase_Properties2 &vapor, Phase_Properties2 &liquid, Phase_Properties2 & /*solid*/, int /*f*/){ - double wH2O=0, mCO2=0, mNaCl=0; - wH2O=liquid.H2O/55.51; - mCO2=liquid.CO2/wH2O; - mNaCl=liquid.NaCl/wH2O; - - liquid.temperature=T; - liquid.pressure=P; - liquid.density=density::CO2brine(T,P,mNaCl,mCO2); - liquid.viscosity=-1.0; - liquid.mass=liquid.H2O*18.01528+liquid.CO2*44.009+liquid.NaCl*58.443; - liquid.volume=liquid.mass/liquid.density; - - vapor.temperature=T; - vapor.pressure=P; - vapor.density=VLE::density_CO2(T,P); //to use mixture fluid EoS - vapor.viscosity=-1.0; - vapor.mass=vapor.CO2*44.009+vapor.H2O*18.01528; - vapor.volume=vapor.mass/vapor.density; - +void VLE_isobaric_fixphase(double T, double P, Phase_Properties2& vapor, Phase_Properties2& liquid, + Phase_Properties2& /*solid*/, int /*f*/) +{ + double wH2O = 0, mCO2 = 0, mNaCl = 0; + wH2O = liquid.H2O / 55.51; + mCO2 = liquid.CO2 / wH2O; + mNaCl = liquid.NaCl / wH2O; + + liquid.temperature = T; + liquid.pressure = P; + liquid.density = density::CO2brine(T, P, mNaCl, mCO2); + liquid.viscosity = -1.0; + liquid.mass = liquid.H2O * 18.01528 + liquid.CO2 * 44.009 + liquid.NaCl * 58.443; + liquid.volume = liquid.mass / liquid.density; + + vapor.temperature = T; + vapor.pressure = P; + vapor.density = VLE::density_CO2(T, P); // to use mixture fluid EoS + vapor.viscosity = -1.0; + vapor.mass = vapor.CO2 * 44.009 + vapor.H2O * 18.01528; + vapor.volume = vapor.mass / vapor.density; } -void VLE_isochoric_fixphase(double T, double &P, Phase_Properties2 &vapor, Phase_Properties2 &liquid, Phase_Properties2 &solid, int f){ - int i=0,i_max=31; - double V=0, V0=0, P1=0, P2=0; - double err=1.0e-8; +void VLE_isochoric_fixphase(double T, double& P, Phase_Properties2& vapor, Phase_Properties2& liquid, + Phase_Properties2& solid, int f) +{ + int i = 0, i_max = 31; + double V = 0, V0 = 0, P1 = 0, P2 = 0; + double err = 1.0e-8; - V0 =vapor.volume+liquid.volume; + V0 = vapor.volume + liquid.volume; VLE_isobaric_fixphase(T, P, vapor, liquid, solid, f); - V=vapor.volume+liquid.volume; + V = vapor.volume + liquid.volume; - if(abs(V-V0)V0){ - P1=P; - P2=5.0*P; + else if (V > V0) + { + P1 = P; + P2 = 5.0 * P; } - else if(VV0) - P1=P; + else if (V < V0) + P2 = P; + else if (V > V0) + P1 = P; + } + if (i == i_max) + { + cout << "VLE_isochoric_fixphase() max.it.=" << i << " reached, dV=" << abs(V - V0) << " rho="; + cout << vapor.density * 1000 << "\n"; } - if(i==i_max){ - cout << "VLE_isochoric_fixphase() max.it.=" << i << " reached, dV=" << abs(V-V0) << " rho="; - cout << vapor.density*1000 << "\n"; - } } diff --git a/FEM/rf_react_int.h b/FEM/rf_react_int.h index 44c5f941f..5f37fc6ff 100644 --- a/FEM/rf_react_int.h +++ b/FEM/rf_react_int.h @@ -7,153 +7,152 @@ * */ - /* reaction interface header file */ +/* reaction interface header file */ - -//CB: What's the use of this? +// CB: What's the use of this? //#ifndef reaction_INC //#define reactions_INC #include #include -//Water moles per kg of water +// Water moles per kg of water #define MOLH2OPERKG 55.50843506 #define REI_FILE_EXTENSION ".rei" /* Structure for exchange of reaction related data */ -class REACTINT{ - private: - public: - REACTINT(void); +class REACTINT +{ +private: +public: + REACTINT(void); ~REACTINT(void); -// Data - int flowtype; - bool unitconversion ; - bool constantdensity ; - bool constanttemperature; - bool constantpressure; + // Data + int flowtype; + bool unitconversion; + bool constantdensity; + bool constanttemperature; + bool constantpressure; bool residual_back; - double c_TT, c_PP; // CB check for variable type c_PP - int ssp_outstep; - int pcs_outstep; - bool dump_min_moles; - bool dump_all_pcs ; - bool dump_mass_integrals; - bool s_water_limit ; - double WaterSatLimit; - std::string WaterSpeciesName; - std::string NeutralCO2name; - std::string SodiumSpeciesName; - bool icOutput; - bool icSolidUpdate ; - bool readNodePoro; - std::string porofile; - bool vle_flag, vle_p_flag ; - bool pcs_rename_init_flag ; - bool pcs_rename_pre_flag ; - bool pcs_rename_post_flag ; - bool poroupdate_flag; - bool heatpump_2DhTO2Dv; - double heatpump_Z; + double c_TT, c_PP; // CB check for variable type c_PP + int ssp_outstep; + int pcs_outstep; + bool dump_min_moles; + bool dump_all_pcs; + bool dump_mass_integrals; + bool s_water_limit; + double WaterSatLimit; + std::string WaterSpeciesName; + std::string NeutralCO2name; + std::string SodiumSpeciesName; + bool icOutput; + bool icSolidUpdate; + bool readNodePoro; + std::string porofile; + bool vle_flag, vle_p_flag; + bool pcs_rename_init_flag; + bool pcs_rename_pre_flag; + bool pcs_rename_post_flag; + bool poroupdate_flag; + bool heatpump_2DhTO2Dv; + double heatpump_Z; int t_step; - std::vector Temp_store; - std::vector Temp_GHP_mapidx; + std::vector Temp_store; + std::vector Temp_GHP_mapidx; - std::vector node_porosity; - std::vector node_ini_porosity; - std::vector water_conc; - std::vector water_conc_species; - std::vector > ElementInSpecies; - //std::vector sp_pcsind; // store pcs_idx of all species - std::vector sp_varind; // store node_value_idx+timelevel of all species - std::vector dried_out_nodes; // for eclipse coupling + std::vector node_porosity; + std::vector node_ini_porosity; + std::vector water_conc; + std::vector water_conc_species; + std::vector > ElementInSpecies; + // std::vector sp_pcsind; // store pcs_idx of all species + std::vector sp_varind; // store node_value_idx+timelevel of all species + std::vector dried_out_nodes; // for eclipse coupling int nodenumber; - std::vector pcs_rename0_init, pcs_rename0_pre, pcs_rename0_post; - std::vector pcs_rename0_idx_init, pcs_rename0_idx_pre, pcs_rename0_idx_post; - std::vector > pcs_rename1_init, pcs_rename1_pre, pcs_rename1_post; - std::vector > pcs_rename1_idx_init, pcs_rename1_idx_pre, pcs_rename1_idx_post; - std::vector > pcs_rename1_stoi_init, pcs_rename1_stoi_pre, pcs_rename1_stoi_post; - std::vector pow_stoi_init, pow_stoi_pre, pow_stoi_post; + std::vector pcs_rename0_init, pcs_rename0_pre, pcs_rename0_post; + std::vector pcs_rename0_idx_init, pcs_rename0_idx_pre, pcs_rename0_idx_post; + std::vector > pcs_rename1_init, pcs_rename1_pre, pcs_rename1_post; + std::vector > pcs_rename1_idx_init, pcs_rename1_idx_pre, pcs_rename1_idx_post; + std::vector > pcs_rename1_stoi_init, pcs_rename1_stoi_pre, pcs_rename1_stoi_post; + std::vector pow_stoi_init, pow_stoi_pre, pow_stoi_post; typedef struct { - int aq_idx, vp_idx; // check input species list and get the species idx + int aq_idx, vp_idx; // check input species list and get the species idx double aq_value, vp_value; // get the value from processes - std::string aq_name, vp_name; // from input file, name of process + std::string aq_name, vp_name; // from input file, name of process int idx_aq_species; double delta; double eq_ac; - }VLE_type; + } VLE_type; std::vector VLE_conditions, VLE_pressure; + // Member functions -// Member functions - - REACTINT* GetREACTINT(void); - bool Read(std::ifstream*); + REACTINT* GetREACTINT(void); + bool Read(std::ifstream*); void InitREACTINT(void); - void CalcWaterConc(void); - void CalcUnitConversionFactors(long index, double *fl, double *fs, bool molal); - double GetCO2SolubilityDuan(long node); - double GetPressure(long ); - double GetTemperature(long); - double CalcDensityOfWater(void); - std::vector formula2index(std::string formula); - static std::vector string2vector(std::string line); //split string line to pieces, and store in a vector - //std::vector string2vector(std::string line); - double GetWaterSaturation( long ); - void ReactionPreProcessing(void); - void ReactionPostProcessing(bool); - void SetInitialPorosityAndPermToElementValue(void); - void PorosityVolumetricReactionUpdate(void); - void PorosityVolumetricReactionUpdate_2(void); - void PermeabilityPorosityUpdate(void); - void CopySymmetricConcentrationsInRadialModel(void); - void DumpSolidSpeciesMoles(void); - void DumpAllVariables(void); - void DumpMassIntegrals(void); - void CheckForDriedOutNodes(void); - void CopyAllConcentrationsToOtherTimeLevel(bool); - void ReadRestartNodePoro(long); - double LiquidViscosity_Yaws_1976(double ); - double LiquidDensity_Busch(double); - void Heatpump_2DhTO2Dv_Mapping(bool); - - + void CalcWaterConc(void); + void CalcUnitConversionFactors(long index, double* fl, double* fs, bool molal); + double GetCO2SolubilityDuan(long node); + double GetPressure(long); + double GetTemperature(long); + double CalcDensityOfWater(void); + std::vector formula2index(std::string formula); + static std::vector string2vector( + std::string line); // split string line to pieces, and store in a vector + // std::vector string2vector(std::string line); + double GetWaterSaturation(long); + void ReactionPreProcessing(void); + void ReactionPostProcessing(bool); + void SetInitialPorosityAndPermToElementValue(void); + void PorosityVolumetricReactionUpdate(void); + void PorosityVolumetricReactionUpdate_2(void); + void PermeabilityPorosityUpdate(void); + void CopySymmetricConcentrationsInRadialModel(void); + void DumpSolidSpeciesMoles(void); + void DumpAllVariables(void); + void DumpMassIntegrals(void); + void CheckForDriedOutNodes(void); + void CopyAllConcentrationsToOtherTimeLevel(bool); + void ReadRestartNodePoro(long); + double LiquidViscosity_Yaws_1976(double); + double LiquidDensity_Busch(double); + void Heatpump_2DhTO2Dv_Mapping(bool); }; -extern std::vector REACTINT_vec; -extern double GetNodePhaseVolume(long , double , int ); +extern std::vector REACTINT_vec; +extern double GetNodePhaseVolume(long, double, int); extern bool REACINTRead(std::string); // CB moved here from rf_pcs.h file typedef struct // CB DL CO2 phase transition { - std::string name; //fluid name + std::string name; // fluid name double temperature; double pressure; - double density; //density g/cm^3 - double viscosity; //viscosity mPa.s - double volume; //volume cm^3 - double mass; //weight g - double CO2; //mole of CO2 - double H2O; //mole of H2O - double NaCl; //mole of NaCl - double C_GAS; //mole of CO2 in Gas - double H2; //mole of H2 -}Phase_Properties2; - -extern void VLE_CalcNewPressure(double T, double &P, double &V_gas, double &V_liquid, double CO2_gas_old, double CO2_gas_new, double CO2_liquid_old, double CO2_liquid_new, double H2O_liquid_old, double H2O_liquid_new, double &rho); -extern void VLE_isobaric_fixphase(double T, double P, Phase_Properties2 &vapor, Phase_Properties2 &liquid, Phase_Properties2 &solid, int f); -extern void VLE_isochoric_fixphase(double T, double &P, Phase_Properties2 &vapor, Phase_Properties2 &liquid, Phase_Properties2 &solid, int f); - -extern void VLE_isobaric_transphase_H2(double T, double P, Phase_Properties2 &vapor, Phase_Properties2 &liquid); -extern void VLE_isochoric_transphase_H2(double T, double P, Phase_Properties2 &vapor, Phase_Properties2 &liquid); - -extern void VLE_isobaric_fixphase_H2(double T, double P, Phase_Properties2 &vapor, Phase_Properties2 &liquid); -extern void VLE_isochoric_fixphase_H2(double T, double P, Phase_Properties2 &vapor, Phase_Properties2 &liquid); - - - + double density; // density g/cm^3 + double viscosity; // viscosity mPa.s + double volume; // volume cm^3 + double mass; // weight g + double CO2; // mole of CO2 + double H2O; // mole of H2O + double NaCl; // mole of NaCl + double C_GAS; // mole of CO2 in Gas + double H2; // mole of H2 +} Phase_Properties2; + +extern void VLE_CalcNewPressure(double T, double& P, double& V_gas, double& V_liquid, double CO2_gas_old, + double CO2_gas_new, double CO2_liquid_old, double CO2_liquid_new, double H2O_liquid_old, + double H2O_liquid_new, double& rho); +extern void VLE_isobaric_fixphase(double T, double P, Phase_Properties2& vapor, Phase_Properties2& liquid, + Phase_Properties2& solid, int f); +extern void VLE_isochoric_fixphase(double T, double& P, Phase_Properties2& vapor, Phase_Properties2& liquid, + Phase_Properties2& solid, int f); + +extern void VLE_isobaric_transphase_H2(double T, double P, Phase_Properties2& vapor, Phase_Properties2& liquid); +extern void VLE_isochoric_transphase_H2(double T, double P, Phase_Properties2& vapor, Phase_Properties2& liquid); + +extern void VLE_isobaric_fixphase_H2(double T, double P, Phase_Properties2& vapor, Phase_Properties2& liquid); +extern void VLE_isochoric_fixphase_H2(double T, double P, Phase_Properties2& vapor, Phase_Properties2& liquid); //#endif diff --git a/FEM/rf_react_phrq.cpp b/FEM/rf_react_phrq.cpp index f797b3a02..c75fbd455 100644 --- a/FEM/rf_react_phrq.cpp +++ b/FEM/rf_react_phrq.cpp @@ -7,7 +7,7 @@ * */ - /* +/* rf_react_phrq.cpp phrq Reaction package to go with PHREEQC Dedong Li @@ -49,7 +49,7 @@ Kiel, 01/2011 // Elem object #include "fem_ele_std.h" #ifdef OGS_FEM_CAP // CAP_REACT - #include "cacint.h" //DL +#include "cacint.h" //DL #endif #include "gs_project.h" // CB @@ -59,71 +59,85 @@ using namespace std; vector > PHREEQC_TEMPLATE; vector PHREEQC_replace_position; -vector REACT_PRQ_vec; +vector REACT_PRQ_vec; /**************************************************************************/ /* Constructor */ -REACT_PRQ::REACT_PRQ(void){ +REACT_PRQ::REACT_PRQ(void) +{ flag_prq = false; /* DL 28,10,08*/ check_no_reaction_nodes = false; // ToDo nodenumber = 0; - } +} /* Destructor */ -REACT_PRQ::~REACT_PRQ(void){ +REACT_PRQ::~REACT_PRQ(void) +{ } /**************************************************************************/ -//split string line to pieces, and store in a vector -vector REACT_PRQ::string2vector(std::string line){ +// split string line to pieces, and store in a vector +vector REACT_PRQ::string2vector(std::string line) +{ stringstream in; std::string sp; vector pies; pies.clear(); in.str(line); - while(1){ - if(in.eof()) break; - sp=""; + while (1) + { + if (in.eof()) + break; + sp = ""; in >> sp; - if(sp!="") pies.push_back(sp); + if (sp != "") + pies.push_back(sp); } return pies; } -void REACT_PRQ::CreateREACT(void){ +void REACT_PRQ::CreateREACT(void) +{ int i, vector_size; - CRFProcess *m_pcs = NULL; + CRFProcess* m_pcs = NULL; - vector_size = (int) pcs_vector.size(); - for(i=0;ipcs_type_name.compare("MASS_TRANSPORT")==0){ - if(m_pcs->getProcessType()==FiniteElement::MASS_TRANSPORT){ - nodenumber = (long) m_pcs->m_msh->GetNodesNumber(false); + // if(m_pcs->pcs_type_name.compare("MASS_TRANSPORT")==0){ + if (m_pcs->getProcessType() == FiniteElement::MASS_TRANSPORT) + { + nodenumber = (long)m_pcs->m_msh->GetNodesNumber(false); // elenumber = (long) m_pcs->m_msh->ele_vector.size(); } } - rateflag = (int *) Malloc(sizeof(int) * nodenumber); + rateflag = (int*)Malloc(sizeof(int) * nodenumber); } -vector > REACT_PRQ::file2vec(std::string phrq_file){ +vector > REACT_PRQ::file2vec(std::string phrq_file) +{ int i; ifstream in; std::string instr; - vector pies,piesr; + vector pies, piesr; vector > res; in.open(phrq_file.c_str(), ios::in); res.clear(); - if(in.good()){ - while(1){ - if(in.eof()) + if (in.good()) + { + while (1) + { + if (in.eof()) break; getline(in, instr); - pies=REACT_PRQ::string2vector(instr); + pies = REACT_PRQ::string2vector(instr); piesr.clear(); - if((int)pies.size()>0 && pies[0].substr(0,1)!="#"){ - for(i=0;i<(int)pies.size();i++){ - if(pies[i].substr(0,1)=="#") + if ((int)pies.size() > 0 && pies[0].substr(0, 1) != "#") + { + for (i = 0; i < (int)pies.size(); i++) + { + if (pies[i].substr(0, 1) == "#") break; else piesr.push_back(pies[i]); @@ -135,204 +149,236 @@ vector > REACT_PRQ::file2vec(std::string phrq_file){ return res; } - -int REACT_PRQ::isKey(std::string pies0){ - - int i,res=-1; - const std::string PHREEQC_KEYWORD[8]={"SOLUTION","EQUILIBRIUM_PHASES","KINETICS","PRINT","SELECTED_OUTPUT","USER_PUNCH","END","RATES"}; - for(i=0;i<8;i++){ - if(pies0==PHREEQC_KEYWORD[i]) - res=i; +int REACT_PRQ::isKey(std::string pies0) +{ + int i, res = -1; + const std::string PHREEQC_KEYWORD[8] + = {"SOLUTION", "EQUILIBRIUM_PHASES", "KINETICS", "PRINT", "SELECTED_OUTPUT", "USER_PUNCH", "END", "RATES"}; + for (i = 0; i < 8; i++) + { + if (pies0 == PHREEQC_KEYWORD[i]) + res = i; } return res; } -void REACT_PRQ::SetInterface(void){ - int i,j,ids,ips,no_pcs;//number of process and transport species - vector idx,ipx,ipcs,id; +void REACT_PRQ::SetInterface(void) +{ + int i, j, ids, ips, no_pcs; // number of process and transport species + vector idx, ipx, ipcs, id; CRFProcess* m_pcs = NULL; no_pcs = (int)pcs_vector.size(); - this->kin_no_steps=1; + this->kin_no_steps = 1; this->pcs_name.clear(); - for(i=0;ipcs_primary_function_name[0]); } id_key.clear(); - for(i=0;i<(int)PHREEQC_TEMPLATE.size();i++){ + for (i = 0; i < (int)PHREEQC_TEMPLATE.size(); i++) + { id_key.push_back(isKey(PHREEQC_TEMPLATE[i][0])); } - ids=-1; + ids = -1; idx.clear(); - for(i=0;i<(int)id_key.size();i++){ - if(id_key[i]!=-1) - ids=id_key[i]; + for (i = 0; i < (int)id_key.size(); i++) + { + if (id_key[i] != -1) + ids = id_key[i]; idx.push_back(ids); } ipcs.clear(); - for(i=0;i<(int)idx.size();i++){ - ips=-1; - for(j=0;jkin_no_steps=(int)atoi(PHREEQC_TEMPLATE[i][3].c_str()); + for (i = 0; i < (int)idx.size(); i++) + { + ips = -1; + if (ipcs[i] != -1) + { + if (idx[i] == 0) + ips = 1; + else if (idx[i] == 1) + ips = 2; + else if (idx[i] == 2 && PHREEQC_TEMPLATE[i][0] == "-m") + ips = 1; + else if (idx[i] == 2 && PHREEQC_TEMPLATE[i][0] == "-steps") + { + ips = 1; + ipcs[i] = -2; // mark for time step + this->kin_no_steps = (int)atoi(PHREEQC_TEMPLATE[i][3].c_str()); } } ipx.push_back(ips); - //cout << " " << id_key[i] << " " << idx[i] << " " << ipcs[i] << " " << ipx[i] << "\n"; + // cout << " " << id_key[i] << " " << idx[i] << " " << ipcs[i] << " " << ipx[i] << "\n"; // idx-id_KEY, ipcs process, ipx position } this->phrq_id.clear(); - for(i=0;i<(int)idx.size();i++){ - if(ipx[i]!=-1) + for (i = 0; i < (int)idx.size(); i++) + { + if (ipx[i] != -1) this->phrq_id.push_back(2); - else if(idx[i]==0 || idx[i]==1 || idx[i]==2 ||idx[i]==6) + else if (idx[i] == 0 || idx[i] == 1 || idx[i] == 2 || idx[i] == 6) this->phrq_id.push_back(1); else this->phrq_id.push_back(0); } - this->phrq_id_pos=ipx; - this->phrq_id_pcs=ipcs; - this->idx_key=idx; - - cout << " id_key idx_key id id_pos id_pcs " << "\n"; - for(i=0;i<(int)phrq_id.size();i++){ - cout << right << setw(7) << id_key[i] << setw(8) << idx_key[i] << setw(3) << phrq_id[i] << setw(7) << phrq_id_pos[i] << setw(7) << phrq_id_pcs[i] << "\n"; + this->phrq_id_pos = ipx; + this->phrq_id_pcs = ipcs; + this->idx_key = idx; + + cout << " id_key idx_key id id_pos id_pcs " + << "\n"; + for (i = 0; i < (int)phrq_id.size(); i++) + { + cout << right << setw(7) << id_key[i] << setw(8) << idx_key[i] << setw(3) << phrq_id[i] << setw(7) + << phrq_id_pos[i] << setw(7) << phrq_id_pcs[i] << "\n"; } } - -void REACT_PRQ::vec2file(int f){ - - int i,j,ii,n; +void REACT_PRQ::vec2file(int f) +{ + int i, j, ii, n; double pcs_node_value; ofstream out; CRFProcess* m_pcs = NULL; vector phrq_id, phrq_id_pcs, phrq_id_pos; double unitfactor_l = 1, unitfactor_s = 1; - REACTINT *m_rei = NULL; - if(REACTINT_vec.size()>0) + REACTINT* m_rei = NULL; + if (REACTINT_vec.size() > 0) m_rei = REACTINT_vec[0]; double dt; - CTimeDiscretization *m_tim = NULL; - if(time_vector.size()>0){ + CTimeDiscretization* m_tim = NULL; + if (time_vector.size() > 0) + { m_tim = time_vector[0]; dt = m_tim->this_stepsize; - //cout << " dt 0 " << dt << "\n"; + // cout << " dt 0 " << dt << "\n"; } out.clear(); out.open(in_file.c_str(), ios::out); - for(ii=0;iinodenumber;ii++){ //ii==0 as boundary point without reaction calc + for (ii = 0; ii < this->nodenumber; ii++) + { // ii==0 as boundary point without reaction calc - //CB 19.1.2011 + // CB 19.1.2011 // calculate unit conversion factors for phreeqc molarity-->molality - if(m_rei) { - if(m_rei->unitconversion){ - m_rei->CalcUnitConversionFactors(ii, &unitfactor_l, &unitfactor_s, true); - //unitfactor_l = MOLH2OPERKG / m_rei->water_conc[ii]; - //unitfactor_s = (1 - m_rei->node_porosity[ii]) * MOLH2OPERKG / (m_rei->water_conc[ii] * m_rei->node_porosity[ii] * m_rei->GetWaterSaturation(ii)); - //if(unitfactor_s ==0) unitfactor_s = (1 - m_rei->node_porosity[ii]) * MOLH2OPERKG / (m_rei->water_conc[ii] * m_rei->node_porosity[ii] * 1); - //cout << ii << " unitfactor_l " << unitfactor_l << " unitfactor_s " << unitfactor_s << "\n"; + if (m_rei) + { + if (m_rei->unitconversion) + { + m_rei->CalcUnitConversionFactors(ii, &unitfactor_l, &unitfactor_s, true); + // unitfactor_l = MOLH2OPERKG / m_rei->water_conc[ii]; + // unitfactor_s = (1 - m_rei->node_porosity[ii]) * MOLH2OPERKG / (m_rei->water_conc[ii] * + // m_rei->node_porosity[ii] * m_rei->GetWaterSaturation(ii)); + // if(unitfactor_s ==0) unitfactor_s = (1 - m_rei->node_porosity[ii]) * MOLH2OPERKG / + // (m_rei->water_conc[ii] * m_rei->node_porosity[ii] * 1); + // cout << ii << " unitfactor_l " << unitfactor_l << " unitfactor_s " << unitfactor_s << "\n"; } } - for(i=0;i<(int)this->phrq_id.size();i++){ - - if(this->id_key[i]==-1) - if(this->phrq_id[i]!=0 || ii==0) + for (i = 0; i < (int)this->phrq_id.size(); i++) + { + if (this->id_key[i] == -1) + if (this->phrq_id[i] != 0 || ii == 0) out << " "; - n=(int)PHREEQC_TEMPLATE[i].size(); - if(this->phrq_id[i]==0 && ii==0){ - for(j=0;jphrq_id[i] == 0 && ii == 0) + { + for (j = 0; j < n; j++) out << PHREEQC_TEMPLATE[i][j] << " "; out << "\n"; } - if(this->phrq_id[i]==1){ - for(j=0;jphrq_id[i] == 1) + { + for (j = 0; j < n; j++) out << PHREEQC_TEMPLATE[i][j] << " "; out << "\n"; } - if(this->phrq_id[i]==2){ - if(idx_key[i] != 1 || f != -1){ - for(j=0;jphrq_id_pos[i]==j){ - if(this->phrq_id_pcs[i]>=0){ - m_pcs = pcs_vector[this->phrq_id_pcs[i]]; - pcs_node_value=m_pcs->GetNodeValue(ii,1); - if(ii==1){ // DL to test - cout << this->phrq_id_pcs[i] << " value " << pcs_node_value << "\n"; + if (this->phrq_id[i] == 2) + { + if (idx_key[i] != 1 || f != -1) + { + for (j = 0; j < n; j++) + { + if (this->phrq_id_pos[i] == j) + { + if (this->phrq_id_pcs[i] >= 0) + { + m_pcs = pcs_vector[this->phrq_id_pcs[i]]; + pcs_node_value = m_pcs->GetNodeValue(ii, 1); + if (ii == 1) + { // DL to test + cout << this->phrq_id_pcs[i] << " value " << pcs_node_value << "\n"; + } } - } - else if(this->phrq_id_pcs[i]==-2) //mark for current time step - pcs_node_value=dt; - - //idx = pcs_vector[pqc_process[j]]->GetProcessComponentNumber(); - ////mi,w = Ci,w * n *55.5 / CH2O - ////mi,s = Ci,w * (1-n) *55.5 / CH2O - //if(cp_vec[idx]->transport_phase==0) // liquid phase - //dval /= unitfactor_l; - //else if(cp_vec[idx]->transport_phase==1) // solid phase - //dval /= unitfactor_s; - - if(this->phrq_id_pcs[i]>=0){ - if(idx_key[i]==0){ - pcs_node_value *= unitfactor_l; - if(pcs_node_value < 0) - pcs_node_value=0; //1.0e-16; - - //----for PHREEQC precision---- - if(pcs_node_value < 1.0e-9) - pcs_node_value=1.0e-9; - //----------------------------- - } - else if(idx_key[i]==1 || idx_key[i]==2){ - pcs_node_value *= unitfactor_s; - if (pcs_node_value< 0) //1.0e-16) - pcs_node_value=0; + else if (this->phrq_id_pcs[i] == -2) // mark for current time step + pcs_node_value = dt; + + // idx = pcs_vector[pqc_process[j]]->GetProcessComponentNumber(); + ////mi,w = Ci,w * n *55.5 / CH2O + ////mi,s = Ci,w * (1-n) *55.5 / CH2O + // if(cp_vec[idx]->transport_phase==0) // liquid phase + // dval /= unitfactor_l; + // else if(cp_vec[idx]->transport_phase==1) // solid phase + // dval /= unitfactor_s; + + if (this->phrq_id_pcs[i] >= 0) + { + if (idx_key[i] == 0) + { + pcs_node_value *= unitfactor_l; + if (pcs_node_value < 0) + pcs_node_value = 0; // 1.0e-16; + + //----for PHREEQC precision---- + if (pcs_node_value < 1.0e-9) + pcs_node_value = 1.0e-9; + //----------------------------- + } + else if (idx_key[i] == 1 || idx_key[i] == 2) + { + pcs_node_value *= unitfactor_s; + if (pcs_node_value < 0) // 1.0e-16) + pcs_node_value = 0; + } } + out << pcs_node_value << " "; } - out << pcs_node_value << " "; + else + out << PHREEQC_TEMPLATE[i][j] << " "; } - else - out << PHREEQC_TEMPLATE[i][j] << " "; - } } out << "\n"; } @@ -342,23 +388,25 @@ void REACT_PRQ::vec2file(int f){ out.close(); } -int REACT_PRQ::Call_Phreeqc(void){ - std::string m_phrq; - m_phrq= exe_file+" "+in_file+" "+out_file+" "+database_file; - if (!system(m_phrq.c_str())){ - DisplayMsgLn("Phreeqc runs succesfully! "); - return 1; - } - else { - DisplayMsgLn("Warnung: Phreeqc doesn't run properly!!! "); - exit(0); - } +int REACT_PRQ::Call_Phreeqc(void) +{ + std::string m_phrq; + m_phrq = exe_file + " " + in_file + " " + out_file + " " + database_file; + if (!system(m_phrq.c_str())) + { + DisplayMsgLn("Phreeqc runs succesfully! "); + return 1; + } + else + { + DisplayMsgLn("Warnung: Phreeqc doesn't run properly!!! "); + exit(0); + } } - -void REACT_PRQ::file2pcs(int f){ - - int i,ii,j,idx,iout_length=0,iout_step; +void REACT_PRQ::file2pcs(int f) +{ + int i, ii, j, idx, iout_length = 0, iout_step; double pcs_node_value; ifstream in, in0; std::string instr; @@ -367,140 +415,156 @@ void REACT_PRQ::file2pcs(int f){ CRFProcess* m_pcs = NULL; double unitfactor_l = 1, unitfactor_s = 1; - REACTINT *m_rei = NULL; - if(REACTINT_vec.size()>0) + REACTINT* m_rei = NULL; + if (REACTINT_vec.size() > 0) m_rei = REACTINT_vec[0]; in0.open(value_file.c_str(), ios::in); - if(in0.good()) - while(1) - if(in0.eof()) + if (in0.good()) + while (1) + if (in0.eof()) break; - else{ + else + { getline(in0, instr); - iout_length ++; + iout_length++; } else - cout << " Warning ! Could not open value file " << "\n"; + cout << " Warning ! Could not open value file " + << "\n"; in0.close(); - iout_step=(iout_length-2)/nodenumber-1; + iout_step = (iout_length - 2) / nodenumber - 1; in.open(value_file.c_str(), ios::in); - if(in.good()){ + if (in.good()) + { pcs_id.clear(); getline(in, instr); - pies=string2vector(instr); - for(i=0;i<(int)pies.size();i++){ + pies = string2vector(instr); + for (i = 0; i < (int)pies.size(); i++) + { pcs_id.push_back(-1); - for(j=0;j<(int)pcs_name.size();j++) - if(pies[i]==pcs_name[j]) - pcs_id[i]=j; + for (j = 0; j < (int)pcs_name.size(); j++) + if (pies[i] == pcs_name[j]) + pcs_id[i] = j; } - for(ii=0;iinodenumber;ii++){ + for (ii = 0; ii < this->nodenumber; ii++) + { // calculate unit conversion factors for phreeqc molarity-->molality - if(m_rei) { - if(m_rei->unitconversion){ - m_rei->CalcUnitConversionFactors(ii, &unitfactor_l, &unitfactor_s, true); - //unitfactor_l = MOLH2OPERKG / m_rei->water_conc[ii]; - //unitfactor_s = (1 - m_rei->node_porosity[ii]) * MOLH2OPERKG / (m_rei->water_conc[ii] * m_rei->node_porosity[ii] * m_rei->GetWaterSaturation(ii)); - //if(unitfactor_s ==0) unitfactor_s = (1 - m_rei->node_porosity[ii]) * MOLH2OPERKG / (m_rei->water_conc[ii] * m_rei->node_porosity[ii] * 1); + if (m_rei) + { + if (m_rei->unitconversion) + { + m_rei->CalcUnitConversionFactors(ii, &unitfactor_l, &unitfactor_s, true); + // unitfactor_l = MOLH2OPERKG / m_rei->water_conc[ii]; + // unitfactor_s = (1 - m_rei->node_porosity[ii]) * MOLH2OPERKG / (m_rei->water_conc[ii] * + // m_rei->node_porosity[ii] * m_rei->GetWaterSaturation(ii)); + // if(unitfactor_s ==0) unitfactor_s = (1 - m_rei->node_porosity[ii]) * MOLH2OPERKG / + // (m_rei->water_conc[ii] * m_rei->node_porosity[ii] * 1); } } - for(i=0;ikin_no_steps;*/i++) + for (i = 0; i < iout_step; /*ikin_no_steps;*/ i++) + getline(in, instr); getline(in, instr); - getline(in, instr); - pies=string2vector(instr); - for(i=0;i<(int)pies.size();i++){ - if(pcs_id[i]!=-1){ + pies = string2vector(instr); + for (i = 0; i < (int)pies.size(); i++) + { + if (pcs_id[i] != -1) + { m_pcs = pcs_vector[pcs_id[i]]; - pcs_node_value=atof(pies[i].c_str()); - //if(pcs_node_value< 1.0e-12) pcs_node_value=0; + pcs_node_value = atof(pies[i].c_str()); + // if(pcs_node_value< 1.0e-12) pcs_node_value=0; idx = pcs_vector[pcs_id[i]]->GetProcessComponentNumber(); - //mi,w = Ci,w * n *55.5 / CH2O - //mi,s = Ci,w * (1-n) *55.5 / CH2O - if(cp_vec[idx]->transport_phase==0) // liquid phase + // mi,w = Ci,w * n *55.5 / CH2O + // mi,s = Ci,w * (1-n) *55.5 / CH2O + if (cp_vec[idx]->transport_phase == 0) // liquid phase pcs_node_value /= unitfactor_l; - else if(cp_vec[idx]->transport_phase==1) // solid phase + else if (cp_vec[idx]->transport_phase == 1) // solid phase pcs_node_value /= unitfactor_s; - if(cp_vec[idx]->transport_phase ==0) // liquid phase - m_pcs->SetNodeValue(ii,1,pcs_node_value); - else if(cp_vec[idx]->transport_phase ==1){ // solid phase - if(f ==1)// for full system - m_pcs->SetNodeValue(ii,1,pcs_node_value); - else if( f==0 && m_rei->icSolidUpdate) - m_pcs->SetNodeValue(ii,1,pcs_node_value); + if (cp_vec[idx]->transport_phase == 0) // liquid phase + m_pcs->SetNodeValue(ii, 1, pcs_node_value); + else if (cp_vec[idx]->transport_phase == 1) + { // solid phase + if (f == 1) // for full system + m_pcs->SetNodeValue(ii, 1, pcs_node_value); + else if (f == 0 && m_rei->icSolidUpdate) + m_pcs->SetNodeValue(ii, 1, pcs_node_value); } } } } } else - cout << " Warning ! Could not open value file " << "\n"; + cout << " Warning ! Could not open value file " + << "\n"; in.close(); } - - -void REACT_PRQ::ExecuteReactionsPHRQ_new(int f){ - if(f==0){ +void REACT_PRQ::ExecuteReactionsPHRQ_new(int f) +{ + if (f == 0) + { this->CreateREACT(); - PHREEQC_TEMPLATE=this->file2vec(phrq_file); + PHREEQC_TEMPLATE = this->file2vec(phrq_file); this->SetInterface(); this->vec2file(f); this->Call_Phreeqc(); - //cin.get(); + // cin.get(); this->file2pcs(f); } - if(f==1 || f==-1){ + if (f == 1 || f == -1) + { this->vec2file(f); this->Call_Phreeqc(); - //cin.get(); + // cin.get(); this->file2pcs(f); } } - - - - /**************************************************************************/ /* Global function */ /**************************************************************************/ -bool REACT_PRQ_Read(std::string file_base_name){ - +bool REACT_PRQ_Read(std::string file_base_name) +{ char line[MAX_ZEILE]; std::string file_name_prq, line_string; ios::pos_type position; - REACT_PRQ *rc_prq = new REACT_PRQ(); - // look if file is there + REACT_PRQ* rc_prq = new REACT_PRQ(); + // look if file is there file_name_prq = file_base_name + REACTION_EXTENSION_PHRQ; - ifstream prq_file (file_name_prq.data(),ios::in); - if (!prq_file.good()){ - delete rc_prq; - rc_prq =NULL; + ifstream prq_file(file_name_prq.data(), ios::in); + if (!prq_file.good()) + { + delete rc_prq; + rc_prq = NULL; } else { // file is there - use NEW PHREEQC - if(REACT_vec.capacity() > 0){ //Test, if OLD PHREEQC is used also - cout << "\n" << " Warning! PHREEQC is actived. NEW PHREEQC will NOT be used ! " << "\n"; + if (REACT_vec.capacity() > 0) + { // Test, if OLD PHREEQC is used also + cout << "\n" + << " Warning! PHREEQC is actived. NEW PHREEQC will NOT be used ! " + << "\n"; delete rc_prq; - rc_prq =NULL; + rc_prq = NULL; } - else{ + else + { rc_prq->flag_prq = true; // Read input file *.prq prq_file.clear(); - prq_file.seekg(0,ios::beg); - cout << "PRQ_Read" << "\n"; - prq_file.getline(line,MAX_ZEILE); // first line - prq_file.getline(line,MAX_ZEILE); // second line ToDo + prq_file.seekg(0, ios::beg); + cout << "PRQ_Read" + << "\n"; + prq_file.getline(line, MAX_ZEILE); // first line + prq_file.getline(line, MAX_ZEILE); // second line ToDo line_string = line; - if(line_string.find("#STOP")!=string::npos) + if (line_string.find("#STOP") != string::npos) return true; // Call the object read function @@ -514,55 +578,63 @@ bool REACT_PRQ_Read(std::string file_base_name){ return true; } -ios::pos_type REACT_PRQ::Read(ifstream *prq_file){ - - bool new_keyword = false; - std::string hash("#"); - std::string line_string; - std::stringstream in; - ios::pos_type position; - - while (!new_keyword) { - line_string = GetLineFromFile1(prq_file); - //if(line_string.size() < 1) break; - if(line_string.find(hash)!=string::npos) { - new_keyword = true; - break; - } - /* read keywords */ - //.................................................................... - if(line_string.find("$PHRQ_FILE")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(prq_file)); - in >> phrq_file; //sub_line - in.clear(); - } - if(line_string.find("$EXE_FILE")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(prq_file)); - in >> exe_file; //sub_line - in.clear(); - } - if(line_string.find("$DATABASE_FILE")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(prq_file)); - in >> database_file; //sub_line - in.clear(); - } - if(line_string.find("$IN_FILE")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(prq_file)); - in >> in_file; //sub_line - in.clear(); - } - if(line_string.find("$OUT_FILE")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(prq_file)); - in >> out_file; //sub_line - in.clear(); - } - if(line_string.find("$VALUE_FILE")!=string::npos) { // subkeyword found - in.str(GetLineFromFile1(prq_file)); - in >> value_file; //sub_line - in.clear(); - } - } // end while - return position; +ios::pos_type REACT_PRQ::Read(ifstream* prq_file) +{ + bool new_keyword = false; + std::string hash("#"); + std::string line_string; + std::stringstream in; + ios::pos_type position; + + while (!new_keyword) + { + line_string = GetLineFromFile1(prq_file); + // if(line_string.size() < 1) break; + if (line_string.find(hash) != string::npos) + { + new_keyword = true; + break; + } + /* read keywords */ + //.................................................................... + if (line_string.find("$PHRQ_FILE") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(prq_file)); + in >> phrq_file; // sub_line + in.clear(); + } + if (line_string.find("$EXE_FILE") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(prq_file)); + in >> exe_file; // sub_line + in.clear(); + } + if (line_string.find("$DATABASE_FILE") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(prq_file)); + in >> database_file; // sub_line + in.clear(); + } + if (line_string.find("$IN_FILE") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(prq_file)); + in >> in_file; // sub_line + in.clear(); + } + if (line_string.find("$OUT_FILE") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(prq_file)); + in >> out_file; // sub_line + in.clear(); + } + if (line_string.find("$VALUE_FILE") != string::npos) + { // subkeyword found + in.str(GetLineFromFile1(prq_file)); + in >> value_file; // sub_line + in.clear(); + } + } // end while + return position; } #endif diff --git a/FEM/rf_react_phrq.h b/FEM/rf_react_phrq.h index 7b85fd6ad..864afdc7f 100644 --- a/FEM/rf_react_phrq.h +++ b/FEM/rf_react_phrq.h @@ -7,45 +7,44 @@ * */ - #include -//using namespace std; +#include +// using namespace std; #ifdef OGS_FEM_CAP // CAP_REACT +class REACT_PRQ +{ +private: +public: + REACT_PRQ(void); // Initialize + ~REACT_PRQ(void); // Clean up -class REACT_PRQ{ - private: - public: - REACT_PRQ(void); // Initialize - ~REACT_PRQ(void); // Clean up + // Data -// Data - - std::string phrq_file,exe_file,database_file,in_file,out_file,value_file; - int *rateflag; /* flag used for determining if reaction are calculated */ - long nodenumber; /* number of nodes, on which reactions are calculated */ - bool flag_prq; /* flag if *.prq file exists DL 28,10,08*/ + std::string phrq_file, exe_file, database_file, in_file, out_file, value_file; + int* rateflag; /* flag used for determining if reaction are calculated */ + long nodenumber; /* number of nodes, on which reactions are calculated */ + bool flag_prq; /* flag if *.prq file exists DL 28,10,08*/ bool check_no_reaction_nodes; /* flag if CheckNoReactionNodes has been performed */ - int kin_no_steps; + int kin_no_steps; std::vector id_key, idx_key, phrq_id, phrq_id_pcs, phrq_id_pos; std::vector pcs_name; - -// Member functions + // Member functions std::ios::pos_type Read(std::ifstream*); std::vector > file2vec(std::string); - static std::vector string2vector(std::string line); //split string line to pieces, and store in a vector - int isKey(std::string); //return the no. in Key words list + static std::vector string2vector( + std::string line); // split string line to pieces, and store in a vector + int isKey(std::string); // return the no. in Key words list void CreateREACT(void); void SetInterface(void); - void vec2file(int f); int Call_Phreeqc(void); void file2pcs(int f); @@ -54,9 +53,8 @@ class REACT_PRQ{ }; extern std::vector > PHREEQC_TEMPLATE; -extern std::vector REACT_PRQ_vec; -//extern bool REACT_PRQ_Read2(std::string); +extern std::vector REACT_PRQ_vec; +// extern bool REACT_PRQ_Read2(std::string); extern bool REACT_PRQ_Read(std::string); - #endif diff --git a/FEM/rf_st_new.cpp b/FEM/rf_st_new.cpp index 32c6b921e..4fd22e110 100644 --- a/FEM/rf_st_new.cpp +++ b/FEM/rf_st_new.cpp @@ -7,13 +7,13 @@ * */ - /************************************************************************** - FEMLib - Object: Source Terms ST - Task: - Programing: - 01/2004 OK Implementation - last modified - **************************************************************************/ +/************************************************************************** +FEMLib - Object: Source Terms ST +Task: +Programing: +01/2004 OK Implementation +last modified +**************************************************************************/ #include "makros.h" // C++ STL @@ -37,7 +37,7 @@ // GeoSys-MshLib #include "fem_ele.h" -#include "tools.h" //GetLineFromFile +#include "tools.h" //GetLineFromFile /* Tools */ #if !defined(USE_PETSC) && !defined(NEW_EQS) // && defined(other parallel libs)//03~04.3012. WW //#ifndef NEW_EQS //WW. 06.11.2008 @@ -45,7 +45,7 @@ #endif // GeoSys-FEMLib -//OK_IC #include "rfsousin.h" +// OK_IC #include "rfsousin.h" #include "rf_st_new.h" #include "rf_tim_new.h" @@ -93,37 +93,36 @@ std::vector st_vector; std::list st_group_list; std::vector analytical_processes; std::vector analytical_processes_polylines; -std::vector node_history_vector; //CMCD +std::vector node_history_vector; // CMCD /************************************************************************** FEMLib-Method: Task: ST constructor Programing: 01/2004 OK Implementation **************************************************************************/ -CSourceTerm::CSourceTerm() : - ProcessInfo(), GeoInfo(), _coupled (false), _sub_dom_idx(-1), dis_linear_f(NULL), GIS_shape_head(NULL), _distances(NULL) - // 07.06.2010, 03.2010. WW +CSourceTerm::CSourceTerm() + : ProcessInfo(), GeoInfo(), _coupled(false), _sub_dom_idx(-1), dis_linear_f(NULL), GIS_shape_head(NULL), + _distances(NULL) +// 07.06.2010, 03.2010. WW { - CurveIndex = -1; - //KR critical_depth = false; - // COUPLING_SWITCH = false; - geo_node_value = 0.0; - nodes = NULL; //OK - analytical = false; //CMCD - pressureBoundaryCondition = false; - // display_mode = false; //OK - this->TimeInterpolation = 0; //BG - _isConstrainedST = false; + CurveIndex = -1; + // KR critical_depth = false; + // COUPLING_SWITCH = false; + geo_node_value = 0.0; + nodes = NULL; // OK + analytical = false; // CMCD + pressureBoundaryCondition = false; + // display_mode = false; //OK + this->TimeInterpolation = 0; // BG + _isConstrainedST = false; } // KR: Conversion from GUI-ST-object to CSourceTerm CSourceTerm::CSourceTerm(const SourceTerm* st) - : ProcessInfo(st->getProcessType(),st->getProcessPrimaryVariable(),NULL), - GeoInfo(st->getGeoType(),st->getGeoObj()), - DistributionInfo(st->getProcessDistributionType()), - _distances(NULL) + : ProcessInfo(st->getProcessType(), st->getProcessPrimaryVariable(), NULL), + GeoInfo(st->getGeoType(), st->getGeoObj()), DistributionInfo(st->getProcessDistributionType()), _distances(NULL) { - setProcess( PCSGet( this->getProcessType() ) ); + setProcess(PCSGet(this->getProcessType())); this->geo_name = st->getGeoName(); const std::vector dis_nodes = st->getDisNodes(); const std::vector dis_values = st->getDisValues(); @@ -134,21 +133,22 @@ CSourceTerm::CSourceTerm(const SourceTerm* st) } else if (this->getProcessDistributionType() == FiniteElement::LINEAR_NEUMANN) { - for (size_t i=0; iPointsHaveDistribedBC.push_back(static_cast(dis_nodes[i])); this->DistribedBC.push_back(dis_values[i]); } } else if (this->getProcessDistributionType() == FiniteElement::DIRECT - || this->getProcessDistributionType() == FiniteElement::RECHARGE_DIRECT) + || this->getProcessDistributionType() == FiniteElement::RECHARGE_DIRECT) { // variable "fname" needs to be set, this must be done from outside! } else std::cout << "Error in CBoundaryCondition() - DistributionType \"" << FiniteElement::convertDisTypeToString(this->getProcessDistributionType()) - << "\" currently not supported." << "\n"; + << "\" currently not supported." + << "\n"; } /************************************************************************** @@ -160,50 +160,48 @@ CSourceTerm::CSourceTerm(const SourceTerm* st) CSourceTerm::~CSourceTerm() { delete _distances; - for (size_t i=0; i_weather_stations.size(); i++) // KR / NB clear climate data information - delete this->_weather_stations[i]; - - DeleteHistoryNodeMemory(); - // dis_file_name.clear(); - node_number_vector.clear(); - node_value_vector.clear(); - node_renumber_vector.clear(); - PointsHaveDistribedBC.clear(); - DistribedBC.clear(); - element_st_vector.clear(); - //WW----------22.02.2007------------------- - // TF 06/2010 - size_t size(normal2surface.size()); - for (size_t i = 0; i < size; i++) - delete normal2surface[i]; - size = pnt_parameter_vector.size(); - for (size_t i = 0; i < size; i++) - delete pnt_parameter_vector[i]; - if(GIS_shape_head) // 07.06.2010. WW - { - delete [] GIS_shape_head; - GIS_shape_head = NULL; - } - //WW - if(dis_linear_f) delete dis_linear_f; - dis_linear_f = NULL; - - //WW--------------------------------------- -} + for (size_t i = 0; i < this->_weather_stations.size(); i++) // KR / NB clear climate data information + delete this->_weather_stations[i]; + + DeleteHistoryNodeMemory(); + // dis_file_name.clear(); + node_number_vector.clear(); + node_value_vector.clear(); + node_renumber_vector.clear(); + PointsHaveDistribedBC.clear(); + DistribedBC.clear(); + element_st_vector.clear(); + // WW----------22.02.2007------------------- + // TF 06/2010 + size_t size(normal2surface.size()); + for (size_t i = 0; i < size; i++) + delete normal2surface[i]; + size = pnt_parameter_vector.size(); + for (size_t i = 0; i < size; i++) + delete pnt_parameter_vector[i]; + if (GIS_shape_head) // 07.06.2010. WW + { + delete[] GIS_shape_head; + GIS_shape_head = NULL; + } + // WW + if (dis_linear_f) + delete dis_linear_f; + dis_linear_f = NULL; + // WW--------------------------------------- +} const std::string& CSourceTerm::getGeoName() const { - return geo_name; + return geo_name; } - -double CSourceTerm::getCoupLeakance () const +double CSourceTerm::getCoupLeakance() const { - return _coup_leakance; + return _coup_leakance; } - /************************************************************************** FEMLib-Method: Task: ST read function @@ -217,281 +215,284 @@ double CSourceTerm::getCoupLeakance () const 04/2006 OK MSH_TYPE 06/2010 TF modification of the signature, added geo_obj and unique_name **************************************************************************/ -std::ios::pos_type CSourceTerm::Read(std::ifstream *st_file, - const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) +std::ios::pos_type CSourceTerm::Read(std::ifstream* st_file, const GEOLIB::GEOObjects& geo_obj, + const std::string& unique_name) { - char line[MAX_ZEILE]; - std::string line_string, sub_string; - bool new_keyword = false; - - std::stringstream in; - - // JOD - channel = 0, node_averaging = 0, air_breaking = false; - no_surface_water_pressure = 0, explicit_surface_water_pressure = false; - distribute_volume_flux = false; - std::ios::pos_type position; - - // read loop - while (!new_keyword) - { - position = st_file->tellg(); - if (!GetLineFromFile(line, st_file)) - break; - line_string = line; - if (line_string.find("#") != std::string::npos) - { - new_keyword = true; - break; - } - remove_white_space(&line_string); //OK - - /* search for keywords */ - // subkeyword found - if (line_string.find("$PCS_TYPE") != std::string::npos) - { - FileIO::ProcessIO::readProcessInfo (*st_file, _pcs_type); -// in.str(GetLineFromFile1(st_file)); -// std::string tmp; -// in >> tmp; -// setProcessType (convertProcessType (tmp)); -// in.clear(); - continue; - } - - // subkeyword found - if (line_string.find("$PRIMARY_VARIABLE") != std::string::npos) - { - in.str (readNonBlankLineFromInputStream (*st_file)); -// in.str(GetLineFromFile1(st_file)); - std::string tmp; - in >> tmp; - - if ( this->getProcessType() == FiniteElement::MASS_TRANSPORT ) - { - // HS set the pointer to MCP based on component name. - // first do a check whether this name is existing and unique. - if ( cp_name_2_idx.count( tmp ) == 1 ) - { - setProcess(cp_vec[cp_name_2_idx[tmp]]->getProcess() ); - setProcessPrimaryVariable( FiniteElement::CONCENTRATION ); - } - else - { - DisplayErrorMsg("Error: In reading ST file, the input component names are not found in MCP file!!!"); - exit(1); - } - } - else - { - setProcess( PCSGet( this->getProcessType() ) ); - setProcessPrimaryVariable (FiniteElement::convertPrimaryVariable (tmp)); - } - in.clear(); - continue; - } - - if (line_string.find("$COMP_NAME") != std::string::npos) - { - in.str(readNonBlankLineFromInputStream (*st_file)); -// in.str(GetLineFromFile1(st_file)); - std::string tmp; - in >> tmp; - // HS set the pointer to MCP based on component name. - // first do a check whether this name is existing and unique. - if ( cp_name_2_idx.count( tmp ) == 1 ) - { - setProcess(cp_vec[cp_name_2_idx[tmp]]->getProcess() ); - setProcessPrimaryVariable( FiniteElement::CONCENTRATION ); - } - else - { - DisplayErrorMsg("Error: In reading ST file, the input component names are not found in MCP file!!!"); - exit(1); - } - in.clear(); - continue; - } - - if (line_string.find("$GEO_TYPE") != std::string::npos) - { - ReadGeoType(st_file, geo_obj, unique_name); - continue; - } - - //05.09.2008 WW - if (line_string.find("$DIS_TYPE") != std::string::npos) - { - //10.04.2008. WW if(line_string.compare("$DIS_TYPE")==0) { - if (line_string.find("CONDITION") != std::string::npos) - { - _coupled = true; - ReadDistributionType(st_file); - in.str(readNonBlankLineFromInputStream(*st_file)); - in >> line_string >> pcs_type_name_cond; - in.clear(); - in.str(readNonBlankLineFromInputStream(*st_file)); // - in >> pcs_pv_name_cond; - in.clear(); -// in.str(GetLineFromFile1(st_file)); - in.str(readNonBlankLineFromInputStream(*st_file)); - in >> _coup_leakance >> st_rill_height >> coup_given_value >> coup_residualPerm; - in.clear(); - } //05.09.2008 WW - else - { - ReadDistributionType(st_file); - continue; - } - } - - if (line_string.find("$NODE_AVERAGING") != std::string::npos) - { - in.clear(); - node_averaging = true; - continue; - } - - if (line_string.find("$DISTRIBUTE_VOLUME_FLUX") != std::string::npos) // JOD 5.3.07 - { - in.clear(); - distribute_volume_flux = true; - continue; - } - - if (line_string.find("$NEGLECT_SURFACE_WATER_PRESSURE") != std::string::npos) - { // JOD 4.10.01 - in.clear(); - no_surface_water_pressure = true; - continue; - } - - if (line_string.find("$EXPLICIT_SURFACE_WATER_PRESSURE") != std::string::npos) - { // JOD 5.3.07 - in.clear(); - explicit_surface_water_pressure = true; - continue; - } - - if (line_string.find("$CHANNEL") != std::string::npos) - { - in.clear(); - in.str(readNonBlankLineFromInputStream(*st_file)); - in >> channel_width; - channel = 1; - continue; - } - - if (line_string.find("$AIR_BREAKING") != std::string::npos) // JOD 5.3.07 - { - in.clear(); - in.str(readNonBlankLineFromInputStream(*st_file)); - in >> air_breaking_factor >> air_breaking_capillaryPressure >> air_closing_capillaryPressure; - continue; - } - - if (line_string.find("$TIM_TYPE") != std::string::npos) - { - in.str(readNonBlankLineFromInputStream(*st_file)); - in >> tim_type_name; - if (tim_type_name.find("CURVE") != std::string::npos) - { - // dis_type = 0; - in >> CurveIndex; - } - in.clear(); - continue; - } - - //defines if time dependent source terms are use as piecewise constant or linear interpolated; BG 05/2011 - if (line_string.find("$TIME_INTERPOLATION") != std::string::npos) - { - in.str(GetLineFromFile1(st_file)); - in >> interpolation_method; - if (interpolation_method.find("LINEAR") != std::string::npos) - { - this->TimeInterpolation = 0; - } - if (interpolation_method.find("PIECEWISE_CONSTANT") != std::string::npos) - { - this->TimeInterpolation = 1; - } - in.clear(); - continue; - } - - if (line_string.find("$FCT_TYPE") != std::string::npos) - { - in.str(readNonBlankLineFromInputStream(*st_file)); - in >> fct_name; //sub_line - //WW - if (fct_name.find("METHOD") != std::string::npos) - in >> fct_method; - in.clear(); - } - - if (line_string.find("$MSH_TYPE") != std::string::npos) - { - in.str(readNonBlankLineFromInputStream(*st_file)); - std::string sub_string; - in >> sub_string; //sub_line - msh_type_name = "NODE"; - if (sub_string.find("NODE") != std::string::npos) - { - in >> msh_node_number; - in.clear(); - } - continue; - } - - if (line_string.find("$CONSTRAINED") != std::string::npos) - { - Constrained temp; - - _isConstrainedST = true; - in.str(readNonBlankLineFromInputStream(*st_file)); - std::string tempst; - - in >> tempst; //PROCESS_TYPE associated with PRIMARY_VARIABLE - temp.constrainedProcessType = FiniteElement::convertProcessType(tempst); - if (!(temp.constrainedProcessType == FiniteElement::MASS_TRANSPORT || - temp.constrainedProcessType == FiniteElement::HEAT_TRANSPORT || - temp.constrainedProcessType == FiniteElement::LIQUID_FLOW || - temp.constrainedProcessType == FiniteElement::RICHARDS_FLOW)) { - _isConstrainedST = false; - break; - } - - in >> tempst; //PRIMARY_VARIABLE to be constrained - temp.constrainedPrimVar = FiniteElement::convertPrimaryVariable(tempst); - - in >> temp.constrainedValue; //Constrained Value - - in >> tempst; //Constrain direction (greater/smaller than value) - temp.constrainedDirection = convertConstrainedType(tempst); - temp.constrainedVariable = ConstrainedVariable::INVALID_CONSTRAINED_VARIABLE; - if (!(temp.constrainedDirection == ConstrainedType::SMALLER || temp.constrainedDirection == ConstrainedType::GREATER)) - { - std::cout << "No valid constrainedDirection for " << FiniteElement::convertProcessTypeToString(temp.constrainedProcessType) - << " (" << tempst << ")" << std::endl; - _isConstrainedST = false; - } - - in >> tempst; //full constrain option - if (tempst == "COMPLETE_CONSTRAIN") - { - temp._isCompleteConstrained = true; - } - - if (_isConstrainedST) - this->_constrainedST.push_back(temp); - in.clear(); - } - - } // end !new_keyword - return position; -} + char line[MAX_ZEILE]; + std::string line_string, sub_string; + bool new_keyword = false; + + std::stringstream in; + + // JOD + channel = 0, node_averaging = 0, air_breaking = false; + no_surface_water_pressure = 0, explicit_surface_water_pressure = false; + distribute_volume_flux = false; + std::ios::pos_type position; + + // read loop + while (!new_keyword) + { + position = st_file->tellg(); + if (!GetLineFromFile(line, st_file)) + break; + line_string = line; + if (line_string.find("#") != std::string::npos) + { + new_keyword = true; + break; + } + remove_white_space(&line_string); // OK + + /* search for keywords */ + // subkeyword found + if (line_string.find("$PCS_TYPE") != std::string::npos) + { + FileIO::ProcessIO::readProcessInfo(*st_file, _pcs_type); + // in.str(GetLineFromFile1(st_file)); + // std::string tmp; + // in >> tmp; + // setProcessType (convertProcessType (tmp)); + // in.clear(); + continue; + } + + // subkeyword found + if (line_string.find("$PRIMARY_VARIABLE") != std::string::npos) + { + in.str(readNonBlankLineFromInputStream(*st_file)); + // in.str(GetLineFromFile1(st_file)); + std::string tmp; + in >> tmp; + + if (this->getProcessType() == FiniteElement::MASS_TRANSPORT) + { + // HS set the pointer to MCP based on component name. + // first do a check whether this name is existing and unique. + if (cp_name_2_idx.count(tmp) == 1) + { + setProcess(cp_vec[cp_name_2_idx[tmp]]->getProcess()); + setProcessPrimaryVariable(FiniteElement::CONCENTRATION); + } + else + { + DisplayErrorMsg( + "Error: In reading ST file, the input component names are not found in MCP file!!!"); + exit(1); + } + } + else + { + setProcess(PCSGet(this->getProcessType())); + setProcessPrimaryVariable(FiniteElement::convertPrimaryVariable(tmp)); + } + in.clear(); + continue; + } + + if (line_string.find("$COMP_NAME") != std::string::npos) + { + in.str(readNonBlankLineFromInputStream(*st_file)); + // in.str(GetLineFromFile1(st_file)); + std::string tmp; + in >> tmp; + // HS set the pointer to MCP based on component name. + // first do a check whether this name is existing and unique. + if (cp_name_2_idx.count(tmp) == 1) + { + setProcess(cp_vec[cp_name_2_idx[tmp]]->getProcess()); + setProcessPrimaryVariable(FiniteElement::CONCENTRATION); + } + else + { + DisplayErrorMsg("Error: In reading ST file, the input component names are not found in MCP file!!!"); + exit(1); + } + in.clear(); + continue; + } + + if (line_string.find("$GEO_TYPE") != std::string::npos) + { + ReadGeoType(st_file, geo_obj, unique_name); + continue; + } + + // 05.09.2008 WW + if (line_string.find("$DIS_TYPE") != std::string::npos) + { + // 10.04.2008. WW if(line_string.compare("$DIS_TYPE")==0) { + if (line_string.find("CONDITION") != std::string::npos) + { + _coupled = true; + ReadDistributionType(st_file); + in.str(readNonBlankLineFromInputStream(*st_file)); + in >> line_string >> pcs_type_name_cond; + in.clear(); + in.str(readNonBlankLineFromInputStream(*st_file)); // + in >> pcs_pv_name_cond; + in.clear(); + // in.str(GetLineFromFile1(st_file)); + in.str(readNonBlankLineFromInputStream(*st_file)); + in >> _coup_leakance >> st_rill_height >> coup_given_value >> coup_residualPerm; + in.clear(); + } // 05.09.2008 WW + else + { + ReadDistributionType(st_file); + continue; + } + } + + if (line_string.find("$NODE_AVERAGING") != std::string::npos) + { + in.clear(); + node_averaging = true; + continue; + } + + if (line_string.find("$DISTRIBUTE_VOLUME_FLUX") != std::string::npos) // JOD 5.3.07 + { + in.clear(); + distribute_volume_flux = true; + continue; + } + + if (line_string.find("$NEGLECT_SURFACE_WATER_PRESSURE") != std::string::npos) + { // JOD 4.10.01 + in.clear(); + no_surface_water_pressure = true; + continue; + } + + if (line_string.find("$EXPLICIT_SURFACE_WATER_PRESSURE") != std::string::npos) + { // JOD 5.3.07 + in.clear(); + explicit_surface_water_pressure = true; + continue; + } + + if (line_string.find("$CHANNEL") != std::string::npos) + { + in.clear(); + in.str(readNonBlankLineFromInputStream(*st_file)); + in >> channel_width; + channel = 1; + continue; + } + + if (line_string.find("$AIR_BREAKING") != std::string::npos) // JOD 5.3.07 + { + in.clear(); + in.str(readNonBlankLineFromInputStream(*st_file)); + in >> air_breaking_factor >> air_breaking_capillaryPressure >> air_closing_capillaryPressure; + continue; + } + + if (line_string.find("$TIM_TYPE") != std::string::npos) + { + in.str(readNonBlankLineFromInputStream(*st_file)); + in >> tim_type_name; + if (tim_type_name.find("CURVE") != std::string::npos) + { + // dis_type = 0; + in >> CurveIndex; + } + in.clear(); + continue; + } + + // defines if time dependent source terms are use as piecewise constant or linear interpolated; BG 05/2011 + if (line_string.find("$TIME_INTERPOLATION") != std::string::npos) + { + in.str(GetLineFromFile1(st_file)); + in >> interpolation_method; + if (interpolation_method.find("LINEAR") != std::string::npos) + { + this->TimeInterpolation = 0; + } + if (interpolation_method.find("PIECEWISE_CONSTANT") != std::string::npos) + { + this->TimeInterpolation = 1; + } + in.clear(); + continue; + } + + if (line_string.find("$FCT_TYPE") != std::string::npos) + { + in.str(readNonBlankLineFromInputStream(*st_file)); + in >> fct_name; // sub_line + // WW + if (fct_name.find("METHOD") != std::string::npos) + in >> fct_method; + in.clear(); + } + + if (line_string.find("$MSH_TYPE") != std::string::npos) + { + in.str(readNonBlankLineFromInputStream(*st_file)); + std::string sub_string; + in >> sub_string; // sub_line + msh_type_name = "NODE"; + if (sub_string.find("NODE") != std::string::npos) + { + in >> msh_node_number; + in.clear(); + } + continue; + } + + if (line_string.find("$CONSTRAINED") != std::string::npos) + { + Constrained temp; + + _isConstrainedST = true; + in.str(readNonBlankLineFromInputStream(*st_file)); + std::string tempst; + + in >> tempst; // PROCESS_TYPE associated with PRIMARY_VARIABLE + temp.constrainedProcessType = FiniteElement::convertProcessType(tempst); + if (!(temp.constrainedProcessType == FiniteElement::MASS_TRANSPORT + || temp.constrainedProcessType == FiniteElement::HEAT_TRANSPORT + || temp.constrainedProcessType == FiniteElement::LIQUID_FLOW + || temp.constrainedProcessType == FiniteElement::RICHARDS_FLOW)) + { + _isConstrainedST = false; + break; + } + + in >> tempst; // PRIMARY_VARIABLE to be constrained + temp.constrainedPrimVar = FiniteElement::convertPrimaryVariable(tempst); + + in >> temp.constrainedValue; // Constrained Value + + in >> tempst; // Constrain direction (greater/smaller than value) + temp.constrainedDirection = convertConstrainedType(tempst); + temp.constrainedVariable = ConstrainedVariable::INVALID_CONSTRAINED_VARIABLE; + if (!(temp.constrainedDirection == ConstrainedType::SMALLER + || temp.constrainedDirection == ConstrainedType::GREATER)) + { + std::cout << "No valid constrainedDirection for " + << FiniteElement::convertProcessTypeToString(temp.constrainedProcessType) << " (" << tempst + << ")" << std::endl; + _isConstrainedST = false; + } + + in >> tempst; // full constrain option + if (tempst == "COMPLETE_CONSTRAIN") + { + temp._isCompleteConstrained = true; + } + + if (_isConstrainedST) + this->_constrainedST.push_back(temp); + in.clear(); + } + } // end !new_keyword + return position; +} /************************************************************************** FEMLib-Method: @@ -500,198 +501,197 @@ std::ios::pos_type CSourceTerm::Read(std::ifstream *st_file, 11/2007 JOD Implementation 02/2009 WW Add a functionality to directly assign source terms to element nodes. **************************************************************************/ -void CSourceTerm::ReadDistributionType(std::ifstream *st_file) +void CSourceTerm::ReadDistributionType(std::ifstream* st_file) { - std::stringstream in; - // 03.2010 WW - std::string aline; - std::stringstream ss; - int abuff, nLBC = 0; - double bbuff; - - std::string dis_type_name; - in.str(GetLineFromFile1(st_file)); - in >> dis_type_name; - - this->setProcessDistributionType (FiniteElement::convertDisType(dis_type_name)); - - if (dis_type_name.compare (convertDisTypeToString (this->getProcessDistributionType())) != 0) - { - std::cerr << "Error in CSourceTerm::ReadDistributionType (): dist_type_name #" << dis_type_name << "#, new: " << convertDisTypeToString (this->getProcessDistributionType()) << "\n"; - exit (1); - } - - if ( this->getProcessDistributionType() == FiniteElement::CONSTANT - || this->getProcessDistributionType() == FiniteElement::CONSTANT_NEUMANN - || this->getProcessDistributionType() == FiniteElement::CONSTANT_GEO ) - { - in >> geo_node_value; - in.clear(); - if (geo_node_value==.0) - std::cout << "Warning in CSourceTerm::ReadDistributionType (): Zero is set to the distribution type " << dis_type_name << ", which actually does nothing. There might be a mistake in yoru ST file. \n"; - } - - //outflux to surrounding depending on current value of solution at boundary (e.g. heat transfer to surrounding dependent on current wall temperature) - if (this->getProcessDistributionType() == FiniteElement::TRANSFER_SURROUNDING){ - in >> transfer_coefficient; - in >> value_surrounding; - in.clear(); - } - - // if (dis_type_name.find("ANALYTICAL") != std::string::npos) { - if (this->getProcessDistributionType() == FiniteElement::ANALYTICAL) - { - in >> analytical_material_group; //Which material group is it being applied to - in >> analytical_diffusion; //D value - in >> analytical_porosity; //n value of matrix - in >> analytical_tortousity; //t value of matrix - in >> analytical_linear_sorption_Kd; //Linear sorption coefficient - in >> analytical_matrix_density; //Density of solid - in >> number_of_terms; //no timesteps to consider in solution - in >> resolution; //every nth term will be considered - in >> factor; //to convert temperature to energy - analytical = true; - analytical_processes.push_back(convertPrimaryVariableToString (getProcessPrimaryVariable())); - // if (geo_type_name.compare("POLYLINE") == 0) - if (this->getGeoType() == GEOLIB::POLYLINE) - analytical_processes_polylines.push_back(geo_name); - in.clear(); - } + std::stringstream in; + // 03.2010 WW + std::string aline; + std::stringstream ss; + int abuff, nLBC = 0; + double bbuff; + + std::string dis_type_name; + in.str(GetLineFromFile1(st_file)); + in >> dis_type_name; + + this->setProcessDistributionType(FiniteElement::convertDisType(dis_type_name)); + + if (dis_type_name.compare(convertDisTypeToString(this->getProcessDistributionType())) != 0) + { + std::cerr << "Error in CSourceTerm::ReadDistributionType (): dist_type_name #" << dis_type_name + << "#, new: " << convertDisTypeToString(this->getProcessDistributionType()) << "\n"; + exit(1); + } + + if (this->getProcessDistributionType() == FiniteElement::CONSTANT + || this->getProcessDistributionType() == FiniteElement::CONSTANT_NEUMANN + || this->getProcessDistributionType() == FiniteElement::CONSTANT_GEO) + { + in >> geo_node_value; + in.clear(); + if (geo_node_value == .0) + std::cout << "Warning in CSourceTerm::ReadDistributionType (): Zero is set to the distribution type " + << dis_type_name << ", which actually does nothing. There might be a mistake in yoru ST file. \n"; + } + + // outflux to surrounding depending on current value of solution at boundary (e.g. heat transfer to surrounding + // dependent on current wall temperature) + if (this->getProcessDistributionType() == FiniteElement::TRANSFER_SURROUNDING) + { + in >> transfer_coefficient; + in >> value_surrounding; + in.clear(); + } + + // if (dis_type_name.find("ANALYTICAL") != std::string::npos) { + if (this->getProcessDistributionType() == FiniteElement::ANALYTICAL) + { + in >> analytical_material_group; // Which material group is it being applied to + in >> analytical_diffusion; // D value + in >> analytical_porosity; // n value of matrix + in >> analytical_tortousity; // t value of matrix + in >> analytical_linear_sorption_Kd; // Linear sorption coefficient + in >> analytical_matrix_density; // Density of solid + in >> number_of_terms; // no timesteps to consider in solution + in >> resolution; // every nth term will be considered + in >> factor; // to convert temperature to energy + analytical = true; + analytical_processes.push_back(convertPrimaryVariableToString(getProcessPrimaryVariable())); + // if (geo_type_name.compare("POLYLINE") == 0) + if (this->getGeoType() == GEOLIB::POLYLINE) + analytical_processes_polylines.push_back(geo_name); + in.clear(); + } // If a linear function is given. 25.08.2011. WW if (getProcessDistributionType() == FiniteElement::FUNCTION) { - in.clear(); - dis_linear_f = new LinearFunctionData(*st_file); + in.clear(); + dis_linear_f = new LinearFunctionData(*st_file); } - if (this->getProcessDistributionType() == FiniteElement::LINEAR || this->getProcessDistributionType() == FiniteElement::LINEAR_NEUMANN) - { - in >> nLBC; - in.clear(); - for (int i = 0; i < nLBC; i++) - { - in.str(GetLineFromFile1(st_file)); - in >> abuff >> bbuff; - in.clear(); - PointsHaveDistribedBC.push_back(abuff); - DistribedBC.push_back(bbuff); - } - - // Read LINENODES AND VALUES...... - in.clear(); - } - - if (this->getProcessDistributionType() == FiniteElement::CRITICALDEPTH) - { - //KR critical_depth = true; - in >> geo_node_value; - in.clear(); - in.str(GetLineFromFile1(st_file)); - in >> st_rill_height; - in.clear(); - // dis_type = 6; - } - - if (this->getProcessDistributionType() == FiniteElement::NORMALDEPTH) - { - dis_type_name = "NORMALDEPTH"; - in >> geo_node_value; - in.clear(); - in.str(GetLineFromFile1(st_file)); - in >> normaldepth_slope >> st_rill_height; - in.clear(); - } - - - if (this->getProcessDistributionType() == FiniteElement::GREEN_AMPT) - { - dis_type_name = "GREEN_AMPT"; - in >> geo_node_value; - in.clear(); - in.str(GetLineFromFile1(st_file)); - in >> sorptivity >> constant >> rainfall >> moistureDeficit; - in.clear(); - } - // Soure terms are assign to element nodes directly. 23.02.2009. WW - if (this->getProcessDistributionType() == FiniteElement::DIRECT) - { - dis_type_name = "DIRECT"; - in >> fname; - fname = FilePath+fname; - in.clear(); - } - if (this->getProcessDistributionType() == FiniteElement::RECHARGE_DIRECT) - { - dis_type_name = "RECHARGE_DIRECT"; - in >> fname; - fname = FilePath+fname; - in.clear(); - } - - // Soure terms from precipitation are assign to element nodes directly.03.2010. WW - if(dis_type_name.find("PRECIPITATION")!=std::string::npos) - { - dis_type_name = "PRECIPITATION"; - in >> fname; - fname = FilePath+fname; - std::ifstream ins(fname.c_str()); - if(!ins.good()) - { - std::cout<<"Could not find file "<> aline >> GIS_shape_head[i]; - ss.clear(); - - } - while(!ins.eof()) - { - getline(ins, aline); - if(aline.find("#STOP")!=std::string::npos) - break; - ss.str(aline); - ss>> timess >> aline; - precip_times.push_back(timess); - precip_files.push_back(aline); - - ss.clear(); - } - in.clear(); - } -if (this->getProcessDistributionType() == FiniteElement::CLIMATE) - { - dis_type_name = "CLIMATE"; - in >> fname; // base filename for climate input - in.clear(); - - std::vector *stations (FileIO::RapidXMLInterface::readStationFile(FilePath + fname)); - - const size_t nStations(stations->size()); - for (size_t i=0; i((*stations)[i])); + if (this->getProcessDistributionType() == FiniteElement::LINEAR + || this->getProcessDistributionType() == FiniteElement::LINEAR_NEUMANN) + { + in >> nLBC; + in.clear(); + for (int i = 0; i < nLBC; i++) + { + in.str(GetLineFromFile1(st_file)); + in >> abuff >> bbuff; + in.clear(); + PointsHaveDistribedBC.push_back(abuff); + DistribedBC.push_back(bbuff); + } + + // Read LINENODES AND VALUES...... + in.clear(); + } + + if (this->getProcessDistributionType() == FiniteElement::CRITICALDEPTH) + { + // KR critical_depth = true; + in >> geo_node_value; + in.clear(); + in.str(GetLineFromFile1(st_file)); + in >> st_rill_height; + in.clear(); + // dis_type = 6; + } + + if (this->getProcessDistributionType() == FiniteElement::NORMALDEPTH) + { + dis_type_name = "NORMALDEPTH"; + in >> geo_node_value; + in.clear(); + in.str(GetLineFromFile1(st_file)); + in >> normaldepth_slope >> st_rill_height; + in.clear(); + } + + if (this->getProcessDistributionType() == FiniteElement::GREEN_AMPT) + { + dis_type_name = "GREEN_AMPT"; + in >> geo_node_value; + in.clear(); + in.str(GetLineFromFile1(st_file)); + in >> sorptivity >> constant >> rainfall >> moistureDeficit; + in.clear(); + } + // Soure terms are assign to element nodes directly. 23.02.2009. WW + if (this->getProcessDistributionType() == FiniteElement::DIRECT) + { + dis_type_name = "DIRECT"; + in >> fname; + fname = FilePath + fname; + in.clear(); + } + if (this->getProcessDistributionType() == FiniteElement::RECHARGE_DIRECT) + { + dis_type_name = "RECHARGE_DIRECT"; + in >> fname; + fname = FilePath + fname; + in.clear(); + } + + // Soure terms from precipitation are assign to element nodes directly.03.2010. WW + if (dis_type_name.find("PRECIPITATION") != std::string::npos) + { + dis_type_name = "PRECIPITATION"; + in >> fname; + fname = FilePath + fname; + std::ifstream ins(fname.c_str()); + if (!ins.good()) + { + std::cout << "Could not find file " << fname << "\n"; + exit(0); + } + double timess; + GIS_shape_head = new double[6]; // 07.06.2010. WW + for (int i = 0; i < 6; i++) + { + getline(ins, aline); + ss.str(aline); + ss >> aline >> GIS_shape_head[i]; + ss.clear(); + } + while (!ins.eof()) + { + getline(ins, aline); + if (aline.find("#STOP") != std::string::npos) + break; + ss.str(aline); + ss >> timess >> aline; + precip_times.push_back(timess); + precip_files.push_back(aline); - delete stations; - } + ss.clear(); + } + in.clear(); + } + if (this->getProcessDistributionType() == FiniteElement::CLIMATE) + { + dis_type_name = "CLIMATE"; + in >> fname; // base filename for climate input + in.clear(); + std::vector* stations(FileIO::RapidXMLInterface::readStationFile(FilePath + fname)); - if (this->getProcessDistributionType() == FiniteElement::RECHARGE) - { - dis_type_name = "RECHARGE"; - in >> geo_node_value; - in.clear(); - } + const size_t nStations(stations->size()); + for (size_t i = 0; i < nStations; i++) + _weather_stations.push_back(static_cast((*stations)[i])); + delete stations; + } + if (this->getProcessDistributionType() == FiniteElement::RECHARGE) + { + dis_type_name = "RECHARGE"; + in >> geo_node_value; + in.clear(); + } } - /************************************************************************** FEMLib-Method: Task: for CSourceTerm::Read @@ -699,22 +699,20 @@ if (this->getProcessDistributionType() == FiniteElement::CLIMATE) 11/2007 JOD Implementation 06/2010 TF modification of the signature, added geo_obj and unique_name **************************************************************************/ -void CSourceTerm::ReadGeoType(std::ifstream *st_file, -const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) +void CSourceTerm::ReadGeoType(std::ifstream* st_file, const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) { - FileIO::GeoIO::readGeoInfo(this, *st_file, geo_name, geo_obj, unique_name); - - if (getProcessPrimaryVariable() == FiniteElement::EXCAVATION) //WW - { - std::stringstream strstr; - strstr.str(GetLineFromFile1(st_file)); - //size_t tmp_geo_type; - std::string sub_string; - strstr >> sub_string >> _sub_dom_idx; - strstr.clear(); - } -} + FileIO::GeoIO::readGeoInfo(this, *st_file, geo_name, geo_obj, unique_name); + if (getProcessPrimaryVariable() == FiniteElement::EXCAVATION) // WW + { + std::stringstream strstr; + strstr.str(GetLineFromFile1(st_file)); + // size_t tmp_geo_type; + std::string sub_string; + strstr >> sub_string >> _sub_dom_idx; + strstr.clear(); + } +} /************************************************************************** FEMLib-Method: @@ -723,91 +721,91 @@ const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) 01/2004 OK Implementation 06/2010 TF modification of the signature, added geo_obj and unique_name **************************************************************************/ -bool STRead(const std::string &file_base_name, -const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) +bool STRead(const std::string& file_base_name, const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) { - char line[MAX_ZEILE]; - std::string line_string, st_file_name; - std::ios::pos_type position; - - // File handling - st_file_name = file_base_name + ST_FILE_EXTENSION; - std::ifstream st_file(st_file_name.data(), std::ios::in); - - if (!st_file.good()) - { - std::cout << "! Warning in STRead: No source terms !" << "\n"; - return false; - } - - // Keyword loop - std::cout << "STRead ... " << std::flush; - while (!st_file.eof()) - { - st_file.getline(line, MAX_ZEILE); - line_string = line; - //Code included to make dynamic memory for analytical solution - if (line_string.find("#STOP") != std::string::npos) - { - - size_t no_source_terms(st_vector.size()); - size_t no_an_sol = 0, number_of_terms = 0; - //Need to find the memory size limits for the anal. solution. - for (size_t i = 0; i < no_source_terms; i++) - { - if (st_vector[i]->isAnalytical()) - { - no_an_sol++; - number_of_terms = std::max(st_vector[i]->getNumberOfTerms(), number_of_terms); - } - } - if (no_an_sol > 0) - { - for (size_t i = 0; i < no_source_terms; i++) - { - st_vector[i]->setNumberOfAnalyticalSolutions (no_an_sol); - st_vector[i]->setMaxNumberOfTerms (number_of_terms); - } - } - - std::cout << "done, read " << st_vector.size() << " source terms" << "\n"; - - return true; - } - //---------------------------------------------------------------------- - // keyword found - if (line_string.find("#SOURCE_TERM") != std::string::npos) - { - CSourceTerm *st(new CSourceTerm()); - std::ios::pos_type pos (st_file.tellg()); - position = st->Read(&st_file, geo_obj, unique_name); - if (pos != position) - { - if (st->getProcessPrimaryVariable()==FiniteElement::DISPLACEMENT_N) - { - st->SetPressureBoundaryConditionFlag(true); - CSourceTerm *st2(new CSourceTerm (*st)); // copies st's properties onto st2 - st2->setProcessPrimaryVariable(FiniteElement::DISPLACEMENT_X); - st_vector.push_back(st2); - st->setProcessPrimaryVariable(FiniteElement::DISPLACEMENT_Y); - } - st_vector.push_back(st); - - } - else - { - std::cerr << "WARNING: in STRead: could not read source term" << "\n"; - delete st; - } - st_file.seekg(position, std::ios::beg); - } // keyword found - } // eof - - std::cout << "done, read " << st_vector.size() << " source terms" << "\n"; - - return true; -} + char line[MAX_ZEILE]; + std::string line_string, st_file_name; + std::ios::pos_type position; + + // File handling + st_file_name = file_base_name + ST_FILE_EXTENSION; + std::ifstream st_file(st_file_name.data(), std::ios::in); + + if (!st_file.good()) + { + std::cout << "! Warning in STRead: No source terms !" + << "\n"; + return false; + } + + // Keyword loop + std::cout << "STRead ... " << std::flush; + while (!st_file.eof()) + { + st_file.getline(line, MAX_ZEILE); + line_string = line; + // Code included to make dynamic memory for analytical solution + if (line_string.find("#STOP") != std::string::npos) + { + size_t no_source_terms(st_vector.size()); + size_t no_an_sol = 0, number_of_terms = 0; + // Need to find the memory size limits for the anal. solution. + for (size_t i = 0; i < no_source_terms; i++) + { + if (st_vector[i]->isAnalytical()) + { + no_an_sol++; + number_of_terms = std::max(st_vector[i]->getNumberOfTerms(), number_of_terms); + } + } + if (no_an_sol > 0) + { + for (size_t i = 0; i < no_source_terms; i++) + { + st_vector[i]->setNumberOfAnalyticalSolutions(no_an_sol); + st_vector[i]->setMaxNumberOfTerms(number_of_terms); + } + } + + std::cout << "done, read " << st_vector.size() << " source terms" + << "\n"; + + return true; + } + //---------------------------------------------------------------------- + // keyword found + if (line_string.find("#SOURCE_TERM") != std::string::npos) + { + CSourceTerm* st(new CSourceTerm()); + std::ios::pos_type pos(st_file.tellg()); + position = st->Read(&st_file, geo_obj, unique_name); + if (pos != position) + { + if (st->getProcessPrimaryVariable() == FiniteElement::DISPLACEMENT_N) + { + st->SetPressureBoundaryConditionFlag(true); + CSourceTerm* st2(new CSourceTerm(*st)); // copies st's properties onto st2 + st2->setProcessPrimaryVariable(FiniteElement::DISPLACEMENT_X); + st_vector.push_back(st2); + st->setProcessPrimaryVariable(FiniteElement::DISPLACEMENT_Y); + } + st_vector.push_back(st); + } + else + { + std::cerr << "WARNING: in STRead: could not read source term" + << "\n"; + delete st; + } + st_file.seekg(position, std::ios::beg); + } // keyword found + } // eof + + std::cout << "done, read " << st_vector.size() << " source terms" + << "\n"; + return true; +} /************************************************************************** FEMLib-Method: @@ -817,34 +815,32 @@ const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name) **************************************************************************/ void ST2RHS(std::string pcs_function, double* rhs_vector) { - int j; - long i; - long node_number_vector_length; - CSourceTerm *m_st = NULL; - long no_st = (long) st_vector.size(); - for (j = 0; j < no_st; j++) - { - m_st = st_vector[j]; - if (pcs_function.compare(convertPrimaryVariableToString (m_st->getProcessPrimaryVariable())) == 0) - { - node_number_vector_length = (long) m_st->node_number_vector.size(); - for (i = 0; i < node_number_vector_length; i++) - { - rhs_vector[m_st->node_number_vector[i]] - = m_st->node_value_vector[i]; - } - } - } + int j; + long i; + long node_number_vector_length; + CSourceTerm* m_st = NULL; + long no_st = (long)st_vector.size(); + for (j = 0; j < no_st; j++) + { + m_st = st_vector[j]; + if (pcs_function.compare(convertPrimaryVariableToString(m_st->getProcessPrimaryVariable())) == 0) + { + node_number_vector_length = (long)m_st->node_number_vector.size(); + for (i = 0; i < node_number_vector_length; i++) + { + rhs_vector[m_st->node_number_vector[i]] = m_st->node_value_vector[i]; + } + } + } } - /************************************************************************** FEMLib-Method: Task: ST to mesh nodes Programing: 01/2004 OK Implementation **************************************************************************/ -//void ST2NOD() +// void ST2NOD() //{ // CGLVolume *m_volume = NULL; // double st_value; @@ -922,27 +918,25 @@ void ST2RHS(std::string pcs_function, double* rhs_vector) **************************************************************************/ void STWrite(std::string base_file_name) { - // File handling - std::string st_file_name = base_file_name + ST_FILE_EXTENSION; - std::fstream st_file(st_file_name.data(), std::ios::trunc | std::ios::out); - st_file.setf(std::ios::scientific, std::ios::floatfield); - st_file.precision(12); - if (!st_file.good()) - return; - - st_file - << "GeoSys-ST: Source Terms ------------------------------------------------\n"; - - size_t no_st(st_vector.size()); - for (size_t j = 0; j < no_st; j++) - { - st_vector[j]->Write(&st_file); - } - st_file << "#STOP"; - st_file.close(); + // File handling + std::string st_file_name = base_file_name + ST_FILE_EXTENSION; + std::fstream st_file(st_file_name.data(), std::ios::trunc | std::ios::out); + st_file.setf(std::ios::scientific, std::ios::floatfield); + st_file.precision(12); + if (!st_file.good()) + return; + + st_file << "GeoSys-ST: Source Terms ------------------------------------------------\n"; + + size_t no_st(st_vector.size()); + for (size_t j = 0; j < no_st; j++) + { + st_vector[j]->Write(&st_file); + } + st_file << "#STOP"; + st_file.close(); } - /************************************************************************** FEMLib-Method: Task: write function @@ -954,73 +948,80 @@ void STWrite(std::string base_file_name) **************************************************************************/ void CSourceTerm::Write(std::fstream* st_file) { - //KEYWORD - *st_file << "#SOURCE_TERM" << "\n"; - //-------------------------------------------------------------------- - //NAME+NUMBER - *st_file << " $PCS_TYPE" << "\n"; - *st_file << " "; - // *st_file << pcs_type_name << "\n"; - *st_file << convertProcessTypeToString (getProcessType()) << "\n"; - *st_file << " $PRIMARY_VARIABLE" << "\n"; - *st_file << " "; - *st_file << convertPrimaryVariableToString (getProcessPrimaryVariable()) << "\n"; - //-------------------------------------------------------------------- - //GEO_TYPE - if (this->getProcessDistributionType() != FiniteElement::DIRECT - || this->getProcessDistributionType() != FiniteElement::RECHARGE_DIRECT) - { - *st_file << " $GEO_TYPE" << "\n"; - *st_file << " "; - *st_file << getGeoTypeAsString() << " " << geo_name << "\n"; - } - //-------------------------------------------------------------------- - // TIM_TYPE - if (tim_type_name.size() > 0) //OK - { - *st_file << " $TIM_TYPE" << "\n"; - *st_file << " "; - *st_file << tim_type_name << "\n"; - } - //-------------------------------------------------------------------- - //DIS_TYPE - *st_file << " $DIS_TYPE" << "\n"; - *st_file << " "; - *st_file << convertDisTypeToString(this->getProcessDistributionType()); - switch (this->getProcessDistributionType()) - { - case FiniteElement::CONSTANT: - *st_file << " " << geo_node_value; - *st_file << "\n"; - break; - case FiniteElement::CONSTANT_NEUMANN: - *st_file << " " << geo_node_value; - *st_file << "\n"; - break; - case FiniteElement::LINEAR: - *st_file << " " << (int) PointsHaveDistribedBC.size() << "\n"; - for (long i = 0; i < (long) PointsHaveDistribedBC.size(); i++) - { - *st_file << " " << PointsHaveDistribedBC[i] << " "; - *st_file << " " << DistribedBC[i] << "\n"; - } - break; - case FiniteElement::LINEAR_NEUMANN: - *st_file << " " << PointsHaveDistribedBC.size() << "\n"; - for (size_t i = 0; i < PointsHaveDistribedBC.size(); i++) - { - *st_file << " " << PointsHaveDistribedBC[i] << " "; - *st_file << " " << DistribedBC[i] << "\n"; - } - break; - case FiniteElement::DIRECT: - case FiniteElement::RECHARGE_DIRECT: - *st_file << " " << this->fname << "\n"; - break; - default: - std::cerr << "this distributition type is not handled in CSourceTerm::Write" << "\n"; - } - //-------------------------------------------------------------------- + // KEYWORD + *st_file << "#SOURCE_TERM" + << "\n"; + //-------------------------------------------------------------------- + // NAME+NUMBER + *st_file << " $PCS_TYPE" + << "\n"; + *st_file << " "; + // *st_file << pcs_type_name << "\n"; + *st_file << convertProcessTypeToString(getProcessType()) << "\n"; + *st_file << " $PRIMARY_VARIABLE" + << "\n"; + *st_file << " "; + *st_file << convertPrimaryVariableToString(getProcessPrimaryVariable()) << "\n"; + //-------------------------------------------------------------------- + // GEO_TYPE + if (this->getProcessDistributionType() != FiniteElement::DIRECT + || this->getProcessDistributionType() != FiniteElement::RECHARGE_DIRECT) + { + *st_file << " $GEO_TYPE" + << "\n"; + *st_file << " "; + *st_file << getGeoTypeAsString() << " " << geo_name << "\n"; + } + //-------------------------------------------------------------------- + // TIM_TYPE + if (tim_type_name.size() > 0) // OK + { + *st_file << " $TIM_TYPE" + << "\n"; + *st_file << " "; + *st_file << tim_type_name << "\n"; + } + //-------------------------------------------------------------------- + // DIS_TYPE + *st_file << " $DIS_TYPE" + << "\n"; + *st_file << " "; + *st_file << convertDisTypeToString(this->getProcessDistributionType()); + switch (this->getProcessDistributionType()) + { + case FiniteElement::CONSTANT: + *st_file << " " << geo_node_value; + *st_file << "\n"; + break; + case FiniteElement::CONSTANT_NEUMANN: + *st_file << " " << geo_node_value; + *st_file << "\n"; + break; + case FiniteElement::LINEAR: + *st_file << " " << (int)PointsHaveDistribedBC.size() << "\n"; + for (long i = 0; i < (long)PointsHaveDistribedBC.size(); i++) + { + *st_file << " " << PointsHaveDistribedBC[i] << " "; + *st_file << " " << DistribedBC[i] << "\n"; + } + break; + case FiniteElement::LINEAR_NEUMANN: + *st_file << " " << PointsHaveDistribedBC.size() << "\n"; + for (size_t i = 0; i < PointsHaveDistribedBC.size(); i++) + { + *st_file << " " << PointsHaveDistribedBC[i] << " "; + *st_file << " " << DistribedBC[i] << "\n"; + } + break; + case FiniteElement::DIRECT: + case FiniteElement::RECHARGE_DIRECT: + *st_file << " " << this->fname << "\n"; + break; + default: + std::cerr << "this distributition type is not handled in CSourceTerm::Write" + << "\n"; + } + //-------------------------------------------------------------------- } /************************************************************************** @@ -1031,7 +1032,7 @@ void CSourceTerm::Write(std::fstream* st_file) 11/2007 JOD Reaktivation last modification: **************************************************************************/ -//void CSourceTerm::SetDISType() +// void CSourceTerm::SetDISType() //{ //// if (this->getProcessDistributionType() == CONSTANT) //// dis_type = 1; @@ -1077,113 +1078,120 @@ void CSourceTerm::Write(std::fstream* st_file) 04/2006 OK MSH types 02/2009 WW Direct assign node source terms **************************************************************************/ -void CSourceTermGroup::Set(CRFProcess* m_pcs, const int ShiftInNodeVector, - std::string this_pv_name) +void CSourceTermGroup::Set(CRFProcess* m_pcs, const int ShiftInNodeVector, std::string this_pv_name) { - bool set = false; // CB - - if (this_pv_name.size() != 0) //WW - pcs_pv_name = this_pv_name; - m_msh = FEMGet(pcs_type_name); //m_pcs->m_msh; // - - if (m_msh) //WW - { - /// In case of P_U coupling monolithic scheme - if (m_pcs->type == 41) //WW Mono - { - //Deform - if (pcs_pv_name.find("DISPLACEMENT") != std::string::npos) - m_pcs->m_msh->SwitchOnQuadraticNodes(true); - else - m_pcs->m_msh->SwitchOnQuadraticNodes(false); - } else if (m_pcs->type == 4) - m_pcs->m_msh->SwitchOnQuadraticNodes(true); - else - m_pcs->m_msh->SwitchOnQuadraticNodes(false); - //==================================================================== - long no_st = (long) st_vector.size(); - for (long i = 0; i < no_st; i++) - { - CSourceTerm *source_term (st_vector[i]); - if(m_pcs->getProcessType() != source_term->getProcessType() ) - continue; - - source_term->setSTVectorGroup(i); - - // 07.01.2011. WW - if(source_term->getProcessDistributionType()==FiniteElement::PRECIPITATION) - continue; - - if (source_term->isCoupled()) - m_msh_cond = FEMGet(source_term->pcs_type_name_cond); - - if (source_term->getProcessType() == FiniteElement::MASS_TRANSPORT) - //if ( cp_vec[cp_name_2_idx[convertPrimaryVariableToString(source_term->getProcessPrimaryVariable())]]->getProcess() != m_pcs ) - if ( cp_vec[source_term->getProcessCompVecIndex()]->getProcess() != m_pcs ) //CB cannot match CONCENTRATION with comp name!! - continue; - //-- 23.02.3009. WW - if (source_term->getProcessDistributionType()==FiniteElement::DIRECT - || source_term->getProcessDistributionType()==FiniteElement::CLIMATE) - { //NB For climate ST, the source terms (recharge in this case) will also be assigned directly to surface nodes - source_term->DirectAssign(ShiftInNodeVector); - continue; - } - - if (source_term->getProcessDistributionType()==FiniteElement::RECHARGE_DIRECT) - { - source_term->DirectAssign(ShiftInNodeVector); - set = true; - } - - //CB cannot match CONCENRATION with comp name!! - // modified to fix bug with MASS_TRANSPORT - if (convertProcessTypeToString (source_term->getProcessType ()).compare(pcs_type_name) == 0) - { - if(convertPrimaryVariableToString(source_term->getProcessPrimaryVariable()).compare(pcs_pv_name) == 0) - set = true; - else if ((source_term->getProcessType() == FiniteElement::MASS_TRANSPORT) - && (cp_vec[source_term->getProcessCompVecIndex()]->compname.compare(pcs_pv_name) == 0)) - set = true; - } - - - // 05/2012 BG, it does not work for mass transport if the second part with "CONCENTRATION" is not added !! problem identified by GK und HS - //if ((convertProcessTypeToString (source_term->getProcessType ()).compare(pcs_type_name) == 0) - // && ((convertPrimaryVariableToString(source_term->getProcessPrimaryVariable()).compare(pcs_pv_name) == 0) || (convertPrimaryVariableToString(source_term->getProcessPrimaryVariable()).compare("CONCENTRATION1") == 0))) - // if ( source_term->getProcess() == m_pcs ) - //CB cannot match CONCENRATION with comp name!! - // modified to fix bug with MASS_TRANSPORT - if(set) - { - set=false; - source_term->setProcess (m_pcs); // HS: 01.09.2009 - if (source_term->getGeoType() == GEOLIB::POINT) - SetPNT(m_pcs, source_term, ShiftInNodeVector); - if (source_term->getGeoType () == GEOLIB::POLYLINE) { - SetPLY(source_term, ShiftInNodeVector); - } - if (source_term->getGeoType () == GEOLIB::SURFACE) - SetSFC(source_term, ShiftInNodeVector); - if (source_term->getGeoType () == GEOLIB::GEODOMAIN) - SetDMN(source_term, ShiftInNodeVector); - if (source_term->fct_name.size() > 0) - fct_name = source_term->fct_name; - // Recovery this functionality. 12.08.2011 WW - // MSH types //OK4310 - if(source_term->msh_type_name.compare("NODE")==0) - source_term->SetNOD(); - - - if (source_term->getProcessDistributionType()==FiniteElement::RECHARGE - || source_term->getProcessDistributionType()==FiniteElement::RECHARGE_DIRECT) //MW - MshEditor::sortNodesLexicographically(m_pcs->m_msh); - - } // end pcs name & pv - } // end st loop - } // end msh - else - std::cout << "Warning in CSourceTermGroup::Set - no MSH data" << "\n"; + bool set = false; // CB + + if (this_pv_name.size() != 0) // WW + pcs_pv_name = this_pv_name; + m_msh = FEMGet(pcs_type_name); // m_pcs->m_msh; // + + if (m_msh) // WW + { + /// In case of P_U coupling monolithic scheme + if (m_pcs->type == 41) // WW Mono + { + // Deform + if (pcs_pv_name.find("DISPLACEMENT") != std::string::npos) + m_pcs->m_msh->SwitchOnQuadraticNodes(true); + else + m_pcs->m_msh->SwitchOnQuadraticNodes(false); + } + else if (m_pcs->type == 4) + m_pcs->m_msh->SwitchOnQuadraticNodes(true); + else + m_pcs->m_msh->SwitchOnQuadraticNodes(false); + //==================================================================== + long no_st = (long)st_vector.size(); + for (long i = 0; i < no_st; i++) + { + CSourceTerm* source_term(st_vector[i]); + if (m_pcs->getProcessType() != source_term->getProcessType()) + continue; + + source_term->setSTVectorGroup(i); + + // 07.01.2011. WW + if (source_term->getProcessDistributionType() == FiniteElement::PRECIPITATION) + continue; + + if (source_term->isCoupled()) + m_msh_cond = FEMGet(source_term->pcs_type_name_cond); + + if (source_term->getProcessType() == FiniteElement::MASS_TRANSPORT) + // if ( + // cp_vec[cp_name_2_idx[convertPrimaryVariableToString(source_term->getProcessPrimaryVariable())]]->getProcess() + // != m_pcs ) + if (cp_vec[source_term->getProcessCompVecIndex()]->getProcess() + != m_pcs) // CB cannot match CONCENTRATION with comp name!! + continue; + //-- 23.02.3009. WW + if (source_term->getProcessDistributionType() == FiniteElement::DIRECT + || source_term->getProcessDistributionType() == FiniteElement::CLIMATE) + { // NB For climate ST, the source terms (recharge in this case) will also be assigned directly to surface + // nodes + source_term->DirectAssign(ShiftInNodeVector); + continue; + } + + if (source_term->getProcessDistributionType() == FiniteElement::RECHARGE_DIRECT) + { + source_term->DirectAssign(ShiftInNodeVector); + set = true; + } + + // CB cannot match CONCENRATION with comp name!! + // modified to fix bug with MASS_TRANSPORT + if (convertProcessTypeToString(source_term->getProcessType()).compare(pcs_type_name) == 0) + { + if (convertPrimaryVariableToString(source_term->getProcessPrimaryVariable()).compare(pcs_pv_name) == 0) + set = true; + else if ((source_term->getProcessType() == FiniteElement::MASS_TRANSPORT) + && (cp_vec[source_term->getProcessCompVecIndex()]->compname.compare(pcs_pv_name) == 0)) + set = true; + } + // 05/2012 BG, it does not work for mass transport if the second part with "CONCENTRATION" is not added !! + // problem identified by GK und HS + // if ((convertProcessTypeToString (source_term->getProcessType ()).compare(pcs_type_name) == 0) + // && ((convertPrimaryVariableToString(source_term->getProcessPrimaryVariable()).compare(pcs_pv_name) == + // 0) || + // (convertPrimaryVariableToString(source_term->getProcessPrimaryVariable()).compare("CONCENTRATION1") == + // 0))) + // if ( source_term->getProcess() == m_pcs ) + // CB cannot match CONCENRATION with comp name!! + // modified to fix bug with MASS_TRANSPORT + if (set) + { + set = false; + source_term->setProcess(m_pcs); // HS: 01.09.2009 + if (source_term->getGeoType() == GEOLIB::POINT) + SetPNT(m_pcs, source_term, ShiftInNodeVector); + if (source_term->getGeoType() == GEOLIB::POLYLINE) + { + SetPLY(source_term, ShiftInNodeVector); + } + if (source_term->getGeoType() == GEOLIB::SURFACE) + SetSFC(source_term, ShiftInNodeVector); + if (source_term->getGeoType() == GEOLIB::GEODOMAIN) + SetDMN(source_term, ShiftInNodeVector); + if (source_term->fct_name.size() > 0) + fct_name = source_term->fct_name; + // Recovery this functionality. 12.08.2011 WW + // MSH types //OK4310 + if (source_term->msh_type_name.compare("NODE") == 0) + source_term->SetNOD(); + + if (source_term->getProcessDistributionType() == FiniteElement::RECHARGE + || source_term->getProcessDistributionType() == FiniteElement::RECHARGE_DIRECT) // MW + MshEditor::sortNodesLexicographically(m_pcs->m_msh); + + } // end pcs name & pv + } // end st loop + } // end msh + else + std::cout << "Warning in CSourceTermGroup::Set - no MSH data" + << "\n"; } /************************************************************************** @@ -1194,7 +1202,7 @@ void CSourceTermGroup::Set(CRFProcess* m_pcs, const int ShiftInNodeVector, 07/2005 WW Re-Implementation 12/2005 WW Axismmetry **************************************************************************/ -//void CSourceTerm::EdgeIntegration(CFEMesh* msh, vector&nodes_on_ply, +// void CSourceTerm::EdgeIntegration(CFEMesh* msh, vector&nodes_on_ply, // vector&node_value_vector) { // long i, j, k, l; // long this_number_of_nodes; @@ -1366,287 +1374,280 @@ void CSourceTermGroup::Set(CRFProcess* m_pcs, const int ShiftInNodeVector, // e_edges.resize(0); //} -double AreaProjection(CEdge *edge, FiniteElement::PrimaryVariable primaryVariable) +double AreaProjection(CEdge* edge, FiniteElement::PrimaryVariable primaryVariable) { - double area_projection (0); -// const double epsilon (1.0e-8); //tolerance to decide whether projection is used - //compute edge normal vector - double edge_normal[3];//edge integration is 2 dimensional + double area_projection(0); + // const double epsilon (1.0e-8); //tolerance to decide whether projection is used + // compute edge normal vector + double edge_normal[3]; // edge integration is 2 dimensional double elemNormalVector[3]; elemNormalVector[0] = 0; elemNormalVector[1] = 0; elemNormalVector[2] = 1; - edge->SetNormalVector(elemNormalVector, edge_normal); // Attenzione! This only works if nodes are numbered counter-clockwise. - //TODO: distinguish coordinate systems! - //if coordinate axes are at an angle with edges -// if (fabs(edge_normal[0]) > epsilon && fabs(edge_normal[1]) > epsilon) { - if (primaryVariable == FiniteElement::DISPLACEMENT_X) - area_projection = edge_normal[0]; - else if (primaryVariable == FiniteElement::DISPLACEMENT_Y) - area_projection = edge_normal[1]; -// } + edge->SetNormalVector(elemNormalVector, + edge_normal); // Attenzione! This only works if nodes are numbered counter-clockwise. + // TODO: distinguish coordinate systems! + // if coordinate axes are at an angle with edges + // if (fabs(edge_normal[0]) > epsilon && fabs(edge_normal[1]) > epsilon) { + if (primaryVariable == FiniteElement::DISPLACEMENT_X) + area_projection = edge_normal[0]; + else if (primaryVariable == FiniteElement::DISPLACEMENT_Y) + area_projection = edge_normal[1]; + // } return area_projection; } - -void CSourceTerm::EdgeIntegration(CFEMesh* msh, const std::vector&nodes_on_ply, -std::vector&node_value_vector) const +void CSourceTerm::EdgeIntegration(CFEMesh* msh, const std::vector& nodes_on_ply, + std::vector& node_value_vector) const { - long i, j, k, l; - long this_number_of_nodes; - int elemsCnode; - int nedges, ii; - vec e_nodes(3); - vec e_edges(12); - - double Jac = 0.0; - double Weight = 0.0; - double eta = 0.0; - double v1, v2, radius = 0.0; - double Shfct[3]; - - double area_projection (1.0); //for projection of element areas for edges not parallel to the coordinate axes - bool Const = false; - if (this->getProcessDistributionType() == FiniteElement::CONSTANT || this->getProcessDistributionType() == FiniteElement::CONSTANT_NEUMANN) - Const = true; - - //CFEMesh* msh = m_pcs->m_msh; - //CFEMesh* msh; // JOD - //msh = FEMGet(pcs_type_name); - CElem* elem = NULL; - CEdge* edge = NULL; - CNode* node = NULL; - - int nSize = (long) msh->nod_vector.size(); - this_number_of_nodes = (long) nodes_on_ply.size(); - std::vector G2L(nSize); - std::vector NVal(this_number_of_nodes); - -// CB THMBM - // CB added to remove bug with deactivated Subdomains - //for(i=0;i<(long)pcs_vector.size();i++){ - // if(pcs_vector[i]->getProcessType()==this->getProcessType()) - // { - // pcs_vector[i]->CheckMarkedElement(); - // break; - // } - //} - - // Unmakr edges. - for (i = 0; i < (long) msh->edge_vector.size(); i++) - msh->edge_vector[i]->SetMark(false); - for (i = 0; i < nSize; i++) - { - msh->nod_vector[i]->SetMark(false); - G2L[i] = -1; - } - - // Search edges on polyline - for (i = 0; i < this_number_of_nodes; i++) - { - NVal[i] = 0.0; - k = nodes_on_ply[i]; - G2L[k] = i; - node = msh->nod_vector[k]; - elemsCnode = (int) node->getConnectedElementIDs().size(); - for (j = 0; j < elemsCnode; j++) - { - l = msh->nod_vector[k]->getConnectedElementIDs()[j]; - elem = msh->ele_vector[l]; - nedges = elem->GetEdgesNumber(); - elem->GetEdges(e_edges); - for (ii = 0; ii < nedges; ii++) - { - edge = e_edges[ii]; - if (edge->GetMark()) - continue; - edge->GetNodes(e_nodes); - // Edge A - if (*node == *e_nodes[0]) - e_nodes[0]->SetMark(true); - // Edge B - if (*node == *e_nodes[1]) - e_nodes[1]->SetMark(true); - if (msh->getOrder()) // Quadratic - { - if (*node == *e_nodes[2]) - e_nodes[2]->SetMark(true); - } - if (e_nodes[0]->GetMark() && e_nodes[1]->GetMark()) - { - if (msh->getOrder()) - { - if (e_nodes[2]->GetMark()) - edge->SetMark(true); - } else - edge->SetMark(true); - } - - } // e_edges - } - } + long i, j, k, l; + long this_number_of_nodes; + int elemsCnode; + int nedges, ii; + vec e_nodes(3); + vec e_edges(12); + + double Jac = 0.0; + double Weight = 0.0; + double eta = 0.0; + double v1, v2, radius = 0.0; + double Shfct[3]; + + double area_projection(1.0); // for projection of element areas for edges not parallel to the coordinate axes + bool Const = false; + if (this->getProcessDistributionType() == FiniteElement::CONSTANT + || this->getProcessDistributionType() == FiniteElement::CONSTANT_NEUMANN) + Const = true; + + // CFEMesh* msh = m_pcs->m_msh; + // CFEMesh* msh; // JOD + // msh = FEMGet(pcs_type_name); + CElem* elem = NULL; + CEdge* edge = NULL; + CNode* node = NULL; + + int nSize = (long)msh->nod_vector.size(); + this_number_of_nodes = (long)nodes_on_ply.size(); + std::vector G2L(nSize); + std::vector NVal(this_number_of_nodes); + + // CB THMBM + // CB added to remove bug with deactivated Subdomains + // for(i=0;i<(long)pcs_vector.size();i++){ + // if(pcs_vector[i]->getProcessType()==this->getProcessType()) + // { + // pcs_vector[i]->CheckMarkedElement(); + // break; + // } + //} + + // Unmakr edges. + for (i = 0; i < (long)msh->edge_vector.size(); i++) + msh->edge_vector[i]->SetMark(false); + for (i = 0; i < nSize; i++) + { + msh->nod_vector[i]->SetMark(false); + G2L[i] = -1; + } + + // Search edges on polyline + for (i = 0; i < this_number_of_nodes; i++) + { + NVal[i] = 0.0; + k = nodes_on_ply[i]; + G2L[k] = i; + node = msh->nod_vector[k]; + elemsCnode = (int)node->getConnectedElementIDs().size(); + for (j = 0; j < elemsCnode; j++) + { + l = msh->nod_vector[k]->getConnectedElementIDs()[j]; + elem = msh->ele_vector[l]; + nedges = elem->GetEdgesNumber(); + elem->GetEdges(e_edges); + for (ii = 0; ii < nedges; ii++) + { + edge = e_edges[ii]; + if (edge->GetMark()) + continue; + edge->GetNodes(e_nodes); + // Edge A + if (*node == *e_nodes[0]) + e_nodes[0]->SetMark(true); + // Edge B + if (*node == *e_nodes[1]) + e_nodes[1]->SetMark(true); + if (msh->getOrder()) // Quadratic + { + if (*node == *e_nodes[2]) + e_nodes[2]->SetMark(true); + } + if (e_nodes[0]->GetMark() && e_nodes[1]->GetMark()) + { + if (msh->getOrder()) + { + if (e_nodes[2]->GetMark()) + edge->SetMark(true); + } + else + edge->SetMark(true); + } + + } // e_edges + } + } #if defined(USE_PETSC) // || defined (other parallel linear solver lib). //WW. 05.2013 - const size_t id_act_l_max = static_cast(msh->getNumNodesLocal()); - const size_t id_l_max = msh->GetNodesNumber(false); - const size_t id_act_h_max = msh->getLargestActiveNodeID_Quadratic(); + const size_t id_act_l_max = static_cast(msh->getNumNodesLocal()); + const size_t id_l_max = msh->GetNodesNumber(false); + const size_t id_act_h_max = msh->getLargestActiveNodeID_Quadratic(); #endif - for (i = 0; i < (long) msh->edge_vector.size(); i++) - { - edge = msh->edge_vector[i]; - if (!edge->GetMark()) - continue; - edge->GetNodes(e_nodes); - - if (this->isPressureBoundaryCondition()) - { - area_projection=AreaProjection(edge, this->getProcessPrimaryVariable()); - - } - - if (msh->getOrder()) // Quadradic shape functions - { - if (e_nodes[0]->GetMark() && e_nodes[1]->GetMark() - && e_nodes[2]->GetMark()) - { - Jac = 0.5 * edge->getLength()*area_projection; - v1 = node_value_vector[G2L[e_nodes[0]->GetIndex()]]; - v2 = node_value_vector[G2L[e_nodes[1]->GetIndex()]]; - if (Const && (!msh->isAxisymmetry())) - { + for (i = 0; i < (long)msh->edge_vector.size(); i++) + { + edge = msh->edge_vector[i]; + if (!edge->GetMark()) + continue; + edge->GetNodes(e_nodes); + + if (this->isPressureBoundaryCondition()) + { + area_projection = AreaProjection(edge, this->getProcessPrimaryVariable()); + } + + if (msh->getOrder()) // Quadradic shape functions + { + if (e_nodes[0]->GetMark() && e_nodes[1]->GetMark() && e_nodes[2]->GetMark()) + { + Jac = 0.5 * edge->getLength() * area_projection; + v1 = node_value_vector[G2L[e_nodes[0]->GetIndex()]]; + v2 = node_value_vector[G2L[e_nodes[1]->GetIndex()]]; + if (Const && (!msh->isAxisymmetry())) + { #if defined(USE_PETSC) // || defined (other parallel linear solver lib). //WW. 05.2013 - if(e_nodes[0]->isNonGhost(id_act_l_max, id_l_max, id_act_h_max)) + if (e_nodes[0]->isNonGhost(id_act_l_max, id_l_max, id_act_h_max)) #endif - NVal[G2L[e_nodes[0]->GetIndex()]] += Jac * v1 / 3.0; + NVal[G2L[e_nodes[0]->GetIndex()]] += Jac * v1 / 3.0; #if defined(USE_PETSC) // || defined (other parallel linear solver lib). //WW. 05.2013 - if(e_nodes[1]->isNonGhost(id_act_l_max, id_l_max, id_act_h_max)) + if (e_nodes[1]->isNonGhost(id_act_l_max, id_l_max, id_act_h_max)) #endif - NVal[G2L[e_nodes[1]->GetIndex()]] += Jac * v1 / 3.0; + NVal[G2L[e_nodes[1]->GetIndex()]] += Jac * v1 / 3.0; #if defined(USE_PETSC) // || defined (other parallel linear solver lib). //WW. 05.2013 - if(e_nodes[2]->isNonGhost(id_act_l_max, id_l_max, id_act_h_max)) + if (e_nodes[2]->isNonGhost(id_act_l_max, id_l_max, id_act_h_max)) #endif - NVal[G2L[e_nodes[2]->GetIndex()]] += 4.0 * Jac * v1 / 3.0; - - } - else - { - for (k = 0; k < 3; k++) // Three nodes - { + NVal[G2L[e_nodes[2]->GetIndex()]] += 4.0 * Jac * v1 / 3.0; + } + else + { + for (k = 0; k < 3; k++) // Three nodes + { #if defined(USE_PETSC) // || defined (other parallel linear solver lib). //WW. 05.2013 - if( !e_nodes[k]->isNonGhost(id_act_l_max, id_l_max, id_act_h_max) ) - continue; + if (!e_nodes[k]->isNonGhost(id_act_l_max, id_l_max, id_act_h_max)) + continue; #endif - // Numerical integration - for (l = 0; l < 3; l++) // Gauss points - { - Weight = Jac * MXPGaussFkt(3, l); - eta = MXPGaussPkt(3, l); - ShapeFunctionLineHQ(Shfct, &eta); - //Axisymmetical problem - if (msh->isAxisymmetry()) - { - radius = 0.0; - for (ii = 0; ii < 3; ii++) - radius += Shfct[ii] * e_nodes[ii]->getData()[0]; - if ( fabs(radius) < DBL_MIN ) // At the symmetric axis. - radius = 1.0; - - Weight *= radius; //2.0*pai*radius; - } - NVal[G2L[e_nodes[k]->GetIndex()]] += 0.5 * (v1 + v2 - + eta * (v2 - v1)) * Shfct[k] * Weight; - - } - - } - } - } - } else // Linear shape functions - { - if (e_nodes[0]->GetMark() && e_nodes[1]->GetMark()) - { - Jac = 0.5 * edge->getLength()*area_projection; - v1 = node_value_vector[G2L[e_nodes[0]->GetIndex()]]; - v2 = node_value_vector[G2L[e_nodes[1]->GetIndex()]]; - if (!msh->isAxisymmetry()) - { - if (Const) - { + // Numerical integration + for (l = 0; l < 3; l++) // Gauss points + { + Weight = Jac * MXPGaussFkt(3, l); + eta = MXPGaussPkt(3, l); + ShapeFunctionLineHQ(Shfct, &eta); + // Axisymmetical problem + if (msh->isAxisymmetry()) + { + radius = 0.0; + for (ii = 0; ii < 3; ii++) + radius += Shfct[ii] * e_nodes[ii]->getData()[0]; + if (fabs(radius) < DBL_MIN) // At the symmetric axis. + radius = 1.0; + + Weight *= radius; // 2.0*pai*radius; + } + NVal[G2L[e_nodes[k]->GetIndex()]] += 0.5 * (v1 + v2 + eta * (v2 - v1)) * Shfct[k] * Weight; + } + } + } + } + } + else // Linear shape functions + { + if (e_nodes[0]->GetMark() && e_nodes[1]->GetMark()) + { + Jac = 0.5 * edge->getLength() * area_projection; + v1 = node_value_vector[G2L[e_nodes[0]->GetIndex()]]; + v2 = node_value_vector[G2L[e_nodes[1]->GetIndex()]]; + if (!msh->isAxisymmetry()) + { + if (Const) + { #if defined(USE_PETSC) // || defined (other parallel linear solver lib). //WW. 05.2013 - if(e_nodes[0]->isNonGhost(id_act_l_max, id_l_max, id_act_h_max)) + if (e_nodes[0]->isNonGhost(id_act_l_max, id_l_max, id_act_h_max)) #endif - NVal[G2L[e_nodes[0]->GetIndex()]] += Jac * v1; + NVal[G2L[e_nodes[0]->GetIndex()]] += Jac * v1; #if defined(USE_PETSC) // || defined (other parallel linear solver lib). //WW. 05.2013 - if(e_nodes[1]->isNonGhost(id_act_l_max, id_l_max, id_act_h_max)) + if (e_nodes[1]->isNonGhost(id_act_l_max, id_l_max, id_act_h_max)) #endif - NVal[G2L[e_nodes[1]->GetIndex()]] += Jac * v1; - } - else - { + NVal[G2L[e_nodes[1]->GetIndex()]] += Jac * v1; + } + else + { #if defined(USE_PETSC) // || defined (other parallel linear solver lib). //WW. 05.2013 - if(e_nodes[0]->isNonGhost(id_act_l_max, id_l_max, id_act_h_max)) + if (e_nodes[0]->isNonGhost(id_act_l_max, id_l_max, id_act_h_max)) #endif - NVal[G2L[e_nodes[0]->GetIndex()]] += Jac * (2.0 * v1 - + v2) / 3.0; + NVal[G2L[e_nodes[0]->GetIndex()]] += Jac * (2.0 * v1 + v2) / 3.0; #if defined(USE_PETSC) // || defined (other parallel linear solver lib). //WW. 05.2013 - if(e_nodes[1]->isNonGhost(id_act_l_max, id_l_max, id_act_h_max)) + if (e_nodes[1]->isNonGhost(id_act_l_max, id_l_max, id_act_h_max)) #endif - NVal[G2L[e_nodes[1]->GetIndex()]] += Jac * (v1 + 2.0 - * v2) / 3.0; - } - } else // Axisymmetry - { - - for (k = 0; k < 2; k++) // Three nodes - { + NVal[G2L[e_nodes[1]->GetIndex()]] += Jac * (v1 + 2.0 * v2) / 3.0; + } + } + else // Axisymmetry + { + for (k = 0; k < 2; k++) // Three nodes + { #if defined(USE_PETSC) // || defined (other parallel linear solver lib). //WW. 05.2013 - if( !e_nodes[k]->isNonGhost(id_act_l_max, id_l_max, id_act_h_max) ) - continue; + if (!e_nodes[k]->isNonGhost(id_act_l_max, id_l_max, id_act_h_max)) + continue; #endif - // Numerical integration - for (l = 0; l < 3; l++) // Gauss points - { - Weight = Jac * MXPGaussFkt(3, l); - eta = MXPGaussPkt(3, l); - ShapeFunctionLine(Shfct, &eta); - //Axisymmetical problem - if (msh->isAxisymmetry()) - { - radius = 0.0; - for (ii = 0; ii < 2; ii++) - radius += Shfct[ii] * e_nodes[ii]->getData()[0]; - if ( fabs(radius) < DBL_MIN ) // At the symmetric axis. - radius = 1.0; - - Weight *= radius; //2.0*pai*radius; - } - NVal[G2L[e_nodes[k]->GetIndex()]] += 0.5 * (v1 + v2 - + eta * (v2 - v1)) * Shfct[k] * Weight; - } - } - } // End of is (!axi) - } - } - } - for (i = 0; i < this_number_of_nodes; i++) - { - node_value_vector[i] = NVal[i]; - //node = msh->nod_vector[nodes_on_ply[i]]; - } - for (i = 0; i < (long) msh->edge_vector.size(); i++) - msh->edge_vector[i]->SetMark(true); - for (i = 0; i < nSize; i++) - msh->nod_vector[i]->SetMark(true); - NVal.clear(); - G2L.clear(); - e_nodes.resize(0); - e_edges.resize(0); + // Numerical integration + for (l = 0; l < 3; l++) // Gauss points + { + Weight = Jac * MXPGaussFkt(3, l); + eta = MXPGaussPkt(3, l); + ShapeFunctionLine(Shfct, &eta); + // Axisymmetical problem + if (msh->isAxisymmetry()) + { + radius = 0.0; + for (ii = 0; ii < 2; ii++) + radius += Shfct[ii] * e_nodes[ii]->getData()[0]; + if (fabs(radius) < DBL_MIN) // At the symmetric axis. + radius = 1.0; + + Weight *= radius; // 2.0*pai*radius; + } + NVal[G2L[e_nodes[k]->GetIndex()]] += 0.5 * (v1 + v2 + eta * (v2 - v1)) * Shfct[k] * Weight; + } + } + } // End of is (!axi) + } + } + } + for (i = 0; i < this_number_of_nodes; i++) + { + node_value_vector[i] = NVal[i]; + // node = msh->nod_vector[nodes_on_ply[i]]; + } + for (i = 0; i < (long)msh->edge_vector.size(); i++) + msh->edge_vector[i]->SetMark(true); + for (i = 0; i < nSize; i++) + msh->nod_vector[i]->SetMark(true); + NVal.clear(); + G2L.clear(); + e_nodes.resize(0); + e_edges.resize(0); } - /************************************************************************** ROCKFLOW - Funktion: FaceIntegration Task: Translate distributed Neumann boundary condition /source term on faces @@ -1657,325 +1658,320 @@ std::vector&node_value_vector) const 01/2010 NW improvement of efficiency to search faces **************************************************************************/ -void CSourceTerm::FaceIntegration(CFEMesh* msh, std::vector const &nodes_on_sfc, - std::vector&node_value_vector) +void CSourceTerm::FaceIntegration(CFEMesh* msh, std::vector const& nodes_on_sfc, + std::vector& node_value_vector) { - if (!msh) - { - std::cout - << "Warning in CSourceTerm::FaceIntegration: no MSH data, function doesn't function"; - return; - } - - long i, j, k, l; - long this_number_of_nodes; - int nfaces, nfn; - int nodesFace[8]; - double nodesFVal[8]; - - bool Const = false; - if (this->getProcessDistributionType() == FiniteElement::CONSTANT - || this->getProcessDistributionType() == FiniteElement::CONSTANT_NEUMANN - || this->getProcessDistributionType() == FiniteElement::RECHARGE) //MW - // if (dis_type_name.find("CONSTANT") != std::string::npos) - Const = true; - //---------------------------------------------------------------------- - // Interpolation of polygon values to nodes_on_sfc - if (!Const) // Get node BC by interpolation with surface - { - int nPointsPly = 0; - double Area1, Area2; - double Tol = 1.0e-9; - bool Passed; - const int Size = (int) nodes_on_sfc.size(); - double gC[3], p1[3], p2[3], vn[3], unit[3], NTri[3]; - - CGLPolyline* m_polyline = NULL; - Surface *m_surface = NULL; - m_surface = GEOGetSFCByName(geo_name); //CC - - // list::const_iterator p = m_surface->polyline_of_surface_list.begin(); - std::vector::iterator p = - m_surface->polyline_of_surface_vector.begin(); - - for (j = 0; j < Size; j++) - { - double const*const pn (msh->nod_vector[nodes_on_sfc[j]]->getData()); -// pn[0] = msh->nod_vector[nodes_on_sfc[j]]->X(); -// pn[1] = msh->nod_vector[nodes_on_sfc[j]]->Y(); -// pn[2] = msh->nod_vector[nodes_on_sfc[j]]->Z(); - node_value_vector[j] = 0.0; - Passed = false; - // nodes close to first polyline - p = m_surface->polyline_of_surface_vector.begin(); - while (p != m_surface->polyline_of_surface_vector.end()) - { - m_polyline = *p; - // Grativity center of this polygon - for (i = 0; i < 3; i++) - gC[i] = 0.0; - vn[2] = 0.0; - nPointsPly = (int) m_polyline->point_vector.size(); - if (m_polyline->point_vector.front() == m_polyline->point_vector.back()) - nPointsPly -= 1; - for (i = 0; i < nPointsPly; i++) - { - gC[0] += m_polyline->point_vector[i]->x; - gC[1] += m_polyline->point_vector[i]->y; - gC[2] += m_polyline->point_vector[i]->z; - - vn[2] += m_polyline->point_vector[i]->getPropert(); - } - for (i = 0; i < 3; i++) - gC[i] /= (double) nPointsPly; - // BC value at center is an average of all point values of polygon - vn[2] /= (double) nPointsPly; - - // Area of this polygon by the grativity center - for (i = 0; i < nPointsPly; i++) - { - p1[0] = m_polyline->point_vector[i]->x; - p1[1] = m_polyline->point_vector[i]->y; - p1[2] = m_polyline->point_vector[i]->z; - k = i + 1; - if (i == nPointsPly - 1) - k = 0; - p2[0] = m_polyline->point_vector[k]->x; - p2[1] = m_polyline->point_vector[k]->y; - p2[2] = m_polyline->point_vector[k]->z; - - vn[0] = m_polyline->point_vector[i]->getPropert(); - vn[1] = m_polyline->point_vector[k]->getPropert(); - - Area1 = fabs(ComputeDetTri(p1, gC, p2)); - - Area2 = 0.0; - // Check if pn is in the triangle by points (p1, gC, p2) - Area2 = fabs(ComputeDetTri(p2, gC, pn)); - unit[0] = fabs(ComputeDetTri(gC, p1, pn)); - unit[1] = fabs(ComputeDetTri(p1, p2, pn)); - Area2 += unit[0] + unit[1]; - if (fabs(Area1 - Area2) < Tol) - { - // Intopolation whin triangle (p1,p2,gC) - // Shape function - for (l = 0; l < 2; l++) - unit[l] /= Area1; - ShapeFunctionTri(NTri, unit); - for (l = 0; l < 3; l++) - node_value_vector[j] += vn[l] * NTri[l]; - Passed = true; - break; - } - - } - // - p++; - if (Passed) - break; - } // while - } //j - } - - int Axisymm = 1; // ani-axisymmetry - //CFEMesh* msh = m_pcs->m_msh; - if (msh->isAxisymmetry()) - Axisymm = -1; // Axisymmetry is true - CElem* elem = NULL; - CElem* face = new CElem(1); - CElement* fem = new CElement(Axisymm * msh->GetCoordinateFlag()); - CNode* e_node = NULL; - CElem* e_nei = NULL; - //vec e_nodes(20); - // vec e_neis(6); - - face->SetFace(); - this_number_of_nodes = (long) nodes_on_sfc.size(); - int nSize = (long) msh->nod_vector.size(); - std::vector G2L(nSize); - std::vector NVal(this_number_of_nodes); - - for (i = 0; i < nSize; i++) - { - msh->nod_vector[i]->SetMark(false); - G2L[i] = -1; - } - - for (i = 0; i < this_number_of_nodes; i++) - { - NVal[i] = 0.0; - k = nodes_on_sfc[i]; - G2L[k] = i; - } - - //---------------------------------------------------------------------- - // NW 15.01.2010 - // 1) search element faces on the surface - // 2) face integration - - //init - for (i = 0; i < (long) msh->ele_vector.size(); i++) - { - msh->ele_vector[i]->selected = 0; //TODO can use a new variable - } - std::set set_nodes_on_sfc; //unique set of node id on the surface - for (i = 0; i < (long) nodes_on_sfc.size(); i++) - { - set_nodes_on_sfc.insert(nodes_on_sfc[i]); - } - - //filtering elements: elements should have nodes on the surface - //Notice: node-elements relation has to be constructed beforehand - // CB THMBM - //this->getProcess()->CheckMarkedElement(); // CB added to remove bug with deactivated Subdomains - std::vector vec_possible_elements; - for (i = 0; i < this_number_of_nodes; i++) - { - k = nodes_on_sfc[i]; - for (j = 0; j < (long) msh->nod_vector[k]->getConnectedElementIDs().size(); j++) - { - l = msh->nod_vector[k]->getConnectedElementIDs()[j]; - if (msh->ele_vector[l]->selected == 0) - vec_possible_elements.push_back(l); - msh->ele_vector[l]->selected += 1; // remember how many nodes of an element are on the surface - } - } - - //search elements & face integration + if (!msh) + { + std::cout << "Warning in CSourceTerm::FaceIntegration: no MSH data, function doesn't function"; + return; + } + + long i, j, k, l; + long this_number_of_nodes; + int nfaces, nfn; + int nodesFace[8]; + double nodesFVal[8]; + + bool Const = false; + if (this->getProcessDistributionType() == FiniteElement::CONSTANT + || this->getProcessDistributionType() == FiniteElement::CONSTANT_NEUMANN + || this->getProcessDistributionType() == FiniteElement::RECHARGE) // MW + // if (dis_type_name.find("CONSTANT") != std::string::npos) + Const = true; + //---------------------------------------------------------------------- + // Interpolation of polygon values to nodes_on_sfc + if (!Const) // Get node BC by interpolation with surface + { + int nPointsPly = 0; + double Area1, Area2; + double Tol = 1.0e-9; + bool Passed; + const int Size = (int)nodes_on_sfc.size(); + double gC[3], p1[3], p2[3], vn[3], unit[3], NTri[3]; + + CGLPolyline* m_polyline = NULL; + Surface* m_surface = NULL; + m_surface = GEOGetSFCByName(geo_name); // CC + + // list::const_iterator p = m_surface->polyline_of_surface_list.begin(); + std::vector::iterator p = m_surface->polyline_of_surface_vector.begin(); + + for (j = 0; j < Size; j++) + { + double const* const pn(msh->nod_vector[nodes_on_sfc[j]]->getData()); + // pn[0] = msh->nod_vector[nodes_on_sfc[j]]->X(); + // pn[1] = msh->nod_vector[nodes_on_sfc[j]]->Y(); + // pn[2] = msh->nod_vector[nodes_on_sfc[j]]->Z(); + node_value_vector[j] = 0.0; + Passed = false; + // nodes close to first polyline + p = m_surface->polyline_of_surface_vector.begin(); + while (p != m_surface->polyline_of_surface_vector.end()) + { + m_polyline = *p; + // Grativity center of this polygon + for (i = 0; i < 3; i++) + gC[i] = 0.0; + vn[2] = 0.0; + nPointsPly = (int)m_polyline->point_vector.size(); + if (m_polyline->point_vector.front() == m_polyline->point_vector.back()) + nPointsPly -= 1; + for (i = 0; i < nPointsPly; i++) + { + gC[0] += m_polyline->point_vector[i]->x; + gC[1] += m_polyline->point_vector[i]->y; + gC[2] += m_polyline->point_vector[i]->z; + + vn[2] += m_polyline->point_vector[i]->getPropert(); + } + for (i = 0; i < 3; i++) + gC[i] /= (double)nPointsPly; + // BC value at center is an average of all point values of polygon + vn[2] /= (double)nPointsPly; + + // Area of this polygon by the grativity center + for (i = 0; i < nPointsPly; i++) + { + p1[0] = m_polyline->point_vector[i]->x; + p1[1] = m_polyline->point_vector[i]->y; + p1[2] = m_polyline->point_vector[i]->z; + k = i + 1; + if (i == nPointsPly - 1) + k = 0; + p2[0] = m_polyline->point_vector[k]->x; + p2[1] = m_polyline->point_vector[k]->y; + p2[2] = m_polyline->point_vector[k]->z; + + vn[0] = m_polyline->point_vector[i]->getPropert(); + vn[1] = m_polyline->point_vector[k]->getPropert(); + + Area1 = fabs(ComputeDetTri(p1, gC, p2)); + + Area2 = 0.0; + // Check if pn is in the triangle by points (p1, gC, p2) + Area2 = fabs(ComputeDetTri(p2, gC, pn)); + unit[0] = fabs(ComputeDetTri(gC, p1, pn)); + unit[1] = fabs(ComputeDetTri(p1, p2, pn)); + Area2 += unit[0] + unit[1]; + if (fabs(Area1 - Area2) < Tol) + { + // Intopolation whin triangle (p1,p2,gC) + // Shape function + for (l = 0; l < 2; l++) + unit[l] /= Area1; + ShapeFunctionTri(NTri, unit); + for (l = 0; l < 3; l++) + node_value_vector[j] += vn[l] * NTri[l]; + Passed = true; + break; + } + } + // + p++; + if (Passed) + break; + } // while + } // j + } + + int Axisymm = 1; // ani-axisymmetry + // CFEMesh* msh = m_pcs->m_msh; + if (msh->isAxisymmetry()) + Axisymm = -1; // Axisymmetry is true + CElem* elem = NULL; + CElem* face = new CElem(1); + CElement* fem = new CElement(Axisymm * msh->GetCoordinateFlag()); + CNode* e_node = NULL; + CElem* e_nei = NULL; + // vec e_nodes(20); + // vec e_neis(6); + + face->SetFace(); + this_number_of_nodes = (long)nodes_on_sfc.size(); + int nSize = (long)msh->nod_vector.size(); + std::vector G2L(nSize); + std::vector NVal(this_number_of_nodes); + + for (i = 0; i < nSize; i++) + { + msh->nod_vector[i]->SetMark(false); + G2L[i] = -1; + } + + for (i = 0; i < this_number_of_nodes; i++) + { + NVal[i] = 0.0; + k = nodes_on_sfc[i]; + G2L[k] = i; + } + + //---------------------------------------------------------------------- + // NW 15.01.2010 + // 1) search element faces on the surface + // 2) face integration + + // init + for (i = 0; i < (long)msh->ele_vector.size(); i++) + { + msh->ele_vector[i]->selected = 0; // TODO can use a new variable + } + std::set set_nodes_on_sfc; // unique set of node id on the surface + for (i = 0; i < (long)nodes_on_sfc.size(); i++) + { + set_nodes_on_sfc.insert(nodes_on_sfc[i]); + } + + // filtering elements: elements should have nodes on the surface + // Notice: node-elements relation has to be constructed beforehand + // CB THMBM + // this->getProcess()->CheckMarkedElement(); // CB added to remove bug with deactivated Subdomains + std::vector vec_possible_elements; + for (i = 0; i < this_number_of_nodes; i++) + { + k = nodes_on_sfc[i]; + for (j = 0; j < (long)msh->nod_vector[k]->getConnectedElementIDs().size(); j++) + { + l = msh->nod_vector[k]->getConnectedElementIDs()[j]; + if (msh->ele_vector[l]->selected == 0) + vec_possible_elements.push_back(l); + msh->ele_vector[l]->selected += 1; // remember how many nodes of an element are on the surface + } + } + +// search elements & face integration #if defined(USE_PETSC) // || defined (other parallel linear solver lib). //WW. 05.2013 - const size_t id_act_l_max = static_cast(msh->getNumNodesLocal()); - const size_t id_max_l = msh->GetNodesNumber(false); - const size_t id_act_h_max = msh->getLargestActiveNodeID_Quadratic(); + const size_t id_act_l_max = static_cast(msh->getNumNodesLocal()); + const size_t id_max_l = msh->GetNodesNumber(false); + const size_t id_act_h_max = msh->getLargestActiveNodeID_Quadratic(); #endif - int count; - double fac = 1.0; - for (i = 0; i < (long) vec_possible_elements.size(); i++) - { - elem = msh->ele_vector[vec_possible_elements[i]]; - if (!elem->GetMark()) - continue; - nfaces = elem->GetFacesNumber(); - elem->SetOrder(msh->getOrder()); - for (j = 0; j < nfaces; j++) - { - e_nei = elem->GetNeighbor(j); - nfn = elem->GetElementFaceNodes(j, nodesFace); - //1st check - if (elem->selected < nfn) - continue; - - if(elem->GetDimension() != 3) - continue; - - //2nd check: if all nodes of the face are on the surface - count = 0; - for (k = 0; k < nfn; k++) - { - e_node = elem->GetNode(nodesFace[k]); - if (set_nodes_on_sfc.count(e_node->GetIndex()) > 0) - { - count++; - } - } - if (count != nfn) - continue; - // face integration - for (k = 0; k < nfn; k++) - { - e_node = elem->GetNode(nodesFace[k]); - nodesFVal[k] = node_value_vector[G2L[e_node->GetIndex()]]; - } - fac = 1.0; - // Not a surface face - if (elem->GetDimension() == e_nei->GetDimension()) - fac = 0.5; - face->SetFace(elem, j); - face->SetOrder(msh->getOrder()); - face->ComputeVolume(); - fem->setOrder(msh->getOrder() + 1); - fem->ConfigElement(face, this->_pcs->m_num->ele_gauss_points, true); - fem->FaceIntegration(nodesFVal); - - for (k = 0; k < nfn; k++) - { - e_node = elem->GetNode(nodesFace[k]); + int count; + double fac = 1.0; + for (i = 0; i < (long)vec_possible_elements.size(); i++) + { + elem = msh->ele_vector[vec_possible_elements[i]]; + if (!elem->GetMark()) + continue; + nfaces = elem->GetFacesNumber(); + elem->SetOrder(msh->getOrder()); + for (j = 0; j < nfaces; j++) + { + e_nei = elem->GetNeighbor(j); + nfn = elem->GetElementFaceNodes(j, nodesFace); + // 1st check + if (elem->selected < nfn) + continue; + + if (elem->GetDimension() != 3) + continue; + + // 2nd check: if all nodes of the face are on the surface + count = 0; + for (k = 0; k < nfn; k++) + { + e_node = elem->GetNode(nodesFace[k]); + if (set_nodes_on_sfc.count(e_node->GetIndex()) > 0) + { + count++; + } + } + if (count != nfn) + continue; + // face integration + for (k = 0; k < nfn; k++) + { + e_node = elem->GetNode(nodesFace[k]); + nodesFVal[k] = node_value_vector[G2L[e_node->GetIndex()]]; + } + fac = 1.0; + // Not a surface face + if (elem->GetDimension() == e_nei->GetDimension()) + fac = 0.5; + face->SetFace(elem, j); + face->SetOrder(msh->getOrder()); + face->ComputeVolume(); + fem->setOrder(msh->getOrder() + 1); + fem->ConfigElement(face, this->_pcs->m_num->ele_gauss_points, true); + fem->FaceIntegration(nodesFVal); + + for (k = 0; k < nfn; k++) + { + e_node = elem->GetNode(nodesFace[k]); #if defined(USE_PETSC) // || defined (other parallel linear solver lib). //WW. 05.2013 - if( !e_node->isNonGhost(id_act_l_max, id_max_l, id_act_h_max) ) - { - continue; - } + if (!e_node->isNonGhost(id_act_l_max, id_max_l, id_act_h_max)) + { + continue; + } #endif - NVal[G2L[e_node->GetIndex()]] += fac * nodesFVal[k]; - } + NVal[G2L[e_node->GetIndex()]] += fac * nodesFVal[k]; + } + } + } + + /* + //---------------------------------------------------------------------- + int count; + double fac=1.0; + for (i = 0; i < (long)msh->ele_vector.size(); i++) + { + elem = msh->ele_vector[i]; + if(!elem->GetMark()) continue; + nfaces = elem->GetFacesNumber(); + elem->SetOrder(msh->getOrder()); + for(j=0; jGetNeighbor(j); + nfn = elem->GetElementFaceNodes(j, nodesFace); + count=0; + for(k=0; kGetNode(nodesFace[k]); + for (l = 0; l nod_vector[nodes_on_sfc[l]]) + { + count++; + break; + } + } + } + if(count!=nfn) continue; + for(k=0; kGetNode(nodesFace[k]); + nodesFVal[k] = node_value_vector[G2L[e_node->GetIndex()]]; + } + fac = 1.0; + if(elem->GetDimension()==e_nei->GetDimension()) // Not a surface face + fac = 0.5; + face->SetFace(elem, j); + face->SetOrder(msh->getOrder()); + face->ComputeVolume(); + fem->setOrder(msh->getOrder()+1); + fem->ConfigElement(face, true); + fem->FaceIntegration(nodesFVal); + for(k=0; kGetNode(nodesFace[k]); + NVal[G2L[e_node->GetIndex()]] += fac*nodesFVal[k]; + } + } + } + */ - } - } + for (i = 0; i < this_number_of_nodes; i++) + node_value_vector[i] = NVal[i]; + for (i = 0; i < nSize; i++) + msh->nod_vector[i]->SetMark(true); - /* - //---------------------------------------------------------------------- - int count; - double fac=1.0; - for (i = 0; i < (long)msh->ele_vector.size(); i++) - { - elem = msh->ele_vector[i]; - if(!elem->GetMark()) continue; - nfaces = elem->GetFacesNumber(); - elem->SetOrder(msh->getOrder()); - for(j=0; jGetNeighbor(j); - nfn = elem->GetElementFaceNodes(j, nodesFace); - count=0; - for(k=0; kGetNode(nodesFace[k]); - for (l = 0; l nod_vector[nodes_on_sfc[l]]) - { - count++; - break; - } - } - } - if(count!=nfn) continue; - for(k=0; kGetNode(nodesFace[k]); - nodesFVal[k] = node_value_vector[G2L[e_node->GetIndex()]]; - } - fac = 1.0; - if(elem->GetDimension()==e_nei->GetDimension()) // Not a surface face - fac = 0.5; - face->SetFace(elem, j); - face->SetOrder(msh->getOrder()); - face->ComputeVolume(); - fem->setOrder(msh->getOrder()+1); - fem->ConfigElement(face, true); - fem->FaceIntegration(nodesFVal); - for(k=0; kGetNode(nodesFace[k]); - NVal[G2L[e_node->GetIndex()]] += fac*nodesFVal[k]; - } - } - } - */ - - for (i = 0; i < this_number_of_nodes; i++) - node_value_vector[i] = NVal[i]; - for (i = 0; i < nSize; i++) - msh->nod_vector[i]->SetMark(true); - - NVal.clear(); - G2L.clear(); - delete fem; - delete face; + NVal.clear(); + G2L.clear(); + delete fem; + delete face; } - /************************************************************************** ROCKFLOW - Funktion: DomainIntegration Task: Translate distributed source term within elements into nodes value @@ -1984,74 +1980,74 @@ void CSourceTerm::FaceIntegration(CFEMesh* msh, std::vector const &nodes_o 08/2005 WW Re-Implementation 09/2010 TF re structured some things **************************************************************************/ -void CSourceTerm::DomainIntegration(CFEMesh* msh, const std::vector&nodes_in_dom, -std::vector&node_value_vector) const +void CSourceTerm::DomainIntegration(CFEMesh* msh, const std::vector& nodes_in_dom, + std::vector& node_value_vector) const { - double nodesFVal[8]; - - int Axisymm = 1; // ani-axisymmetry - if (msh->isAxisymmetry()) - Axisymm = -1; // Axisymmetry is true - CElement* fem = new CElement(Axisymm * msh->GetCoordinateFlag()); - vec e_nodes(20); - - const size_t this_number_of_nodes (nodes_in_dom.size()); - const size_t nSize (msh->nod_vector.size()); - std::vector G2L(nSize); - std::vector NVal(this_number_of_nodes); - - for (size_t i = 0; i < nSize; i++) - { - msh->nod_vector[i]->SetMark(false); - G2L[i] = -1; - } - - for (size_t i = 0; i < this_number_of_nodes; i++) - { - NVal[i] = 0.0; - G2L[nodes_in_dom[i]] = i; - } - - size_t count = 0; - for (size_t i = 0; i < msh->ele_vector.size(); i++) - { - CElem* elem (msh->ele_vector[i]); - if (!elem->GetMark()) - continue; - elem->GetNodes(e_nodes); - size_t nn = elem->GetNodesNumber(msh->getOrder()); - count = 0; - for (size_t j = 0; j < nn; j++) - { - for (size_t k = 0; k < this_number_of_nodes; k++) - { - if (*e_nodes[j] == *msh->nod_vector[nodes_in_dom[k]]) - { - count++; - break; - } - } - } - if (count != nn) - continue; - for (size_t j = 0; j < nn; j++) - nodesFVal[j] = node_value_vector[G2L[e_nodes[j]->GetIndex()]]; - fem->ConfigElement(elem, this->_pcs->m_num->ele_gauss_points, true); - fem->setOrder(msh->getOrder() + 1); - fem->FaceIntegration(nodesFVal); - for (size_t j = 0; j < nn; j++) - NVal[G2L[e_nodes[j]->GetIndex()]] += nodesFVal[j]; - } - - for (size_t i = 0; i < this_number_of_nodes; i++) - node_value_vector[i] = NVal[i]; - for (size_t i = 0; i < nSize; i++) - msh->nod_vector[i]->SetMark(true); - - NVal.clear(); - G2L.clear(); - e_nodes.resize(0); - delete fem; + double nodesFVal[8]; + + int Axisymm = 1; // ani-axisymmetry + if (msh->isAxisymmetry()) + Axisymm = -1; // Axisymmetry is true + CElement* fem = new CElement(Axisymm * msh->GetCoordinateFlag()); + vec e_nodes(20); + + const size_t this_number_of_nodes(nodes_in_dom.size()); + const size_t nSize(msh->nod_vector.size()); + std::vector G2L(nSize); + std::vector NVal(this_number_of_nodes); + + for (size_t i = 0; i < nSize; i++) + { + msh->nod_vector[i]->SetMark(false); + G2L[i] = -1; + } + + for (size_t i = 0; i < this_number_of_nodes; i++) + { + NVal[i] = 0.0; + G2L[nodes_in_dom[i]] = i; + } + + size_t count = 0; + for (size_t i = 0; i < msh->ele_vector.size(); i++) + { + CElem* elem(msh->ele_vector[i]); + if (!elem->GetMark()) + continue; + elem->GetNodes(e_nodes); + size_t nn = elem->GetNodesNumber(msh->getOrder()); + count = 0; + for (size_t j = 0; j < nn; j++) + { + for (size_t k = 0; k < this_number_of_nodes; k++) + { + if (*e_nodes[j] == *msh->nod_vector[nodes_in_dom[k]]) + { + count++; + break; + } + } + } + if (count != nn) + continue; + for (size_t j = 0; j < nn; j++) + nodesFVal[j] = node_value_vector[G2L[e_nodes[j]->GetIndex()]]; + fem->ConfigElement(elem, this->_pcs->m_num->ele_gauss_points, true); + fem->setOrder(msh->getOrder() + 1); + fem->FaceIntegration(nodesFVal); + for (size_t j = 0; j < nn; j++) + NVal[G2L[e_nodes[j]->GetIndex()]] += nodesFVal[j]; + } + + for (size_t i = 0; i < this_number_of_nodes; i++) + node_value_vector[i] = NVal[i]; + for (size_t i = 0; i < nSize; i++) + msh->nod_vector[i]->SetMark(true); + + NVal.clear(); + G2L.clear(); + e_nodes.resize(0); + delete fem; } /************************************************************************** @@ -2063,16 +2059,15 @@ std::vector&node_value_vector) const **************************************************************************/ void STDelete() { - long i; - int no_st = (int) st_vector.size(); - for (i = 0; i < no_st; i++) - { - delete st_vector[i]; - } - st_vector.clear(); + long i; + int no_st = (int)st_vector.size(); + for (i = 0; i < no_st; i++) + { + delete st_vector[i]; + } + st_vector.clear(); } - /************************************************************************** FEMLib-Method: Task: @@ -2082,19 +2077,18 @@ void STDelete() **************************************************************************/ void STGroupsDelete() { - CSourceTermGroup* m_st_group = NULL; - std::list::const_iterator p = st_group_list.begin(); - while (p != st_group_list.end()) - { - m_st_group = *p; - delete m_st_group; - //st_group_list.remove(*p); - ++p; - } - st_group_list.clear(); + CSourceTermGroup* m_st_group = NULL; + std::list::const_iterator p = st_group_list.begin(); + while (p != st_group_list.end()) + { + m_st_group = *p; + delete m_st_group; + // st_group_list.remove(*p); + ++p; + } + st_group_list.clear(); } - /************************************************************************** FEMLib-Method: Task: @@ -2103,7 +2097,7 @@ void STGroupsDelete() last modification: **************************************************************************/ // 05/2010 TF not needed for compilation -//void STCreateFromLIN(vectorlin_properties_vector) +// void STCreateFromLIN(vectorlin_properties_vector) //{ // long i; // CSourceTerm *m_st = NULL; @@ -2133,16 +2127,15 @@ void STGroupsDelete() **************************************************************************/ CSourceTerm* STGet(std::string geo_name) { - size_t st_vector_size(st_vector.size()); - for (size_t i = 0; i < st_vector_size; i++) - { - if (st_vector[i]->getGeoName().compare(geo_name) == 0) - return st_vector[i]; - } - return NULL; + size_t st_vector_size(st_vector.size()); + for (size_t i = 0; i < st_vector_size; i++) + { + if (st_vector[i]->getGeoName().compare(geo_name) == 0) + return st_vector[i]; + } + return NULL; } - /************************************************************************** FEMLib-Method: Task: @@ -2152,51 +2145,49 @@ CSourceTerm* STGet(std::string geo_name) **************************************************************************/ CSourceTermGroup* STGetGroup(std::string pcs_type_name, std::string pcs_pv_name) { - CSourceTermGroup *m_st_group = NULL; - std::list::const_iterator p_st_group = st_group_list.begin(); - while (p_st_group != st_group_list.end()) - { - m_st_group = *p_st_group; - if (m_st_group->pcs_type_name.compare(pcs_type_name) == 0 - && (m_st_group->pcs_pv_name.compare(pcs_pv_name) == 0)) - return m_st_group; - ++p_st_group; - } - return NULL; + CSourceTermGroup* m_st_group = NULL; + std::list::const_iterator p_st_group = st_group_list.begin(); + while (p_st_group != st_group_list.end()) + { + m_st_group = *p_st_group; + if (m_st_group->pcs_type_name.compare(pcs_type_name) == 0 + && (m_st_group->pcs_pv_name.compare(pcs_pv_name) == 0)) + return m_st_group; + ++p_st_group; + } + return NULL; } - /************************************************************************** FEMLib-Method: Task: Programing: 02/2006 MB Implementation **************************************************************************/ - //WW +// WW double GetConditionalNODValue(CSourceTerm* st, CNodeValue* cnodev) { - int nidx; - double value_cond = 0.0; - double NodeReachLength; - CRFProcess* pcs_cond (PCSGet(st->pcs_type_name_cond)); - long node_cond; - - //WW node_cond = group_vector[i]->msh_node_number_conditional; - //WW - node_cond = cnodev->msh_node_number_conditional; - nidx = pcs_cond->GetNodeValueIndex(st->pcs_pv_name_cond) + 1; - value_cond = pcs_cond->GetNodeValue(node_cond, nidx); - - if (st->pcs_pv_name_cond.find("FLUX") != std::string::npos) - { - //WW NodeReachLength = group_vector[i]->node_value; - NodeReachLength = cnodev->node_value; //WW - value_cond = value_cond * NodeReachLength; - } - - return value_cond; -} + int nidx; + double value_cond = 0.0; + double NodeReachLength; + CRFProcess* pcs_cond(PCSGet(st->pcs_type_name_cond)); + long node_cond; + + // WW node_cond = group_vector[i]->msh_node_number_conditional; + // WW + node_cond = cnodev->msh_node_number_conditional; + nidx = pcs_cond->GetNodeValueIndex(st->pcs_pv_name_cond) + 1; + value_cond = pcs_cond->GetNodeValue(node_cond, nidx); + + if (st->pcs_pv_name_cond.find("FLUX") != std::string::npos) + { + // WW NodeReachLength = group_vector[i]->node_value; + NodeReachLength = cnodev->node_value; // WW + value_cond = value_cond * NodeReachLength; + } + return value_cond; +} /************************************************************************** FEMLib-Method: @@ -2206,14 +2197,13 @@ double GetConditionalNODValue(CSourceTerm* st, CNodeValue* cnodev) 05/2007 JOD Implementation 09/2010 KR cleaned up code **************************************************************************/ -void GetPhilipNODValue(double &value, const CSourceTerm* m_st) +void GetPhilipNODValue(double& value, const CSourceTerm* m_st) { - double infiltration = m_st->constant + m_st->sorptivity / sqrt(aktuelle_zeit); - infiltration = std::min(m_st->rainfall, infiltration); - value = infiltration * (-value); + double infiltration = m_st->constant + m_st->sorptivity / sqrt(aktuelle_zeit); + infiltration = std::min(m_st->rainfall, infiltration); + value = infiltration * (-value); } - /************************************************************************** FEMLib-Method: Task: Calculate Green-Ampt infiltration flux term @@ -2226,59 +2216,53 @@ void GetPhilipNODValue(double &value, const CSourceTerm* m_st) 05/2007 JOD Implementation **************************************************************************/ -void GetGreenAmptNODValue(double &value, CSourceTerm* m_st, long msh_node) +void GetGreenAmptNODValue(double& value, CSourceTerm* m_st, long msh_node) { + double F, Fiter, Fold, infiltration; + double conductivity, suction, Theta, wdepth; + double a, b; + CFEMesh* m_msh = NULL; + CRFProcess* m_pcs_this = NULL; + m_pcs_this = PCSGet(convertProcessTypeToString(m_st->getProcessType())); + m_msh = m_pcs_this->m_msh; + + double area = value; + + wdepth = std::max(0., m_pcs_this->GetNodeValue(msh_node, m_pcs_this->GetNodeValueIndex("HEAD") + 1) + - m_msh->nod_vector[msh_node]->getData()[2]); + conductivity = m_st->constant; + suction = m_st->sorptivity + wdepth; // water depth included + Theta = m_st->moistureDeficit * suction; + + Fold = m_pcs_this->GetNodeValue(msh_node, m_pcs_this->GetNodeValueIndex("COUPLING")); + F = Fold; + + do // Newton iteration loop + { + Fiter = F; + if (Fiter == 0) // avoids a = 0 + Fiter = 1.e-5; + a = 1 - Theta / (Fiter + Theta); - double F, Fiter, Fold, infiltration; - double conductivity, suction, Theta, wdepth; - double a, b; - CFEMesh* m_msh = NULL; - CRFProcess* m_pcs_this = NULL; - m_pcs_this = PCSGet(convertProcessTypeToString (m_st->getProcessType())); - m_msh = m_pcs_this->m_msh; - - double area = value; - - wdepth = std::max(0., m_pcs_this->GetNodeValue(msh_node, - m_pcs_this->GetNodeValueIndex("HEAD") + 1) - - m_msh->nod_vector[msh_node]->getData()[2]); - conductivity = m_st->constant; - suction = m_st->sorptivity + wdepth; // water depth included - Theta = m_st->moistureDeficit * suction; - - Fold = m_pcs_this->GetNodeValue(msh_node, m_pcs_this->GetNodeValueIndex( - "COUPLING")); - F = Fold; - - do // Newton iteration loop - { - Fiter = F; - if (Fiter == 0) // avoids a = 0 - Fiter = 1.e-5; - a = 1 - Theta / (Fiter + Theta); - - b = Fold - Fiter + Theta * log((Fiter + Theta) / (Fold + Theta)) - + conductivity * dt; // dt = timeStep - F = Fiter + b / a; - } while (fabs(F - Fiter) > 1.e-10); - - infiltration = (F - Fold) / dt; + b = Fold - Fiter + Theta * log((Fiter + Theta) / (Fold + Theta)) + conductivity * dt; // dt = timeStep + F = Fiter + b / a; + } while (fabs(F - Fiter) > 1.e-10); - if (infiltration > m_st->rainfall) // + wdepth / timestep ) // compare with available water - infiltration = m_st->rainfall; // + wdepth / timestep ; + infiltration = (F - Fold) / dt; - F = infiltration * dt + Fold; + if (infiltration > m_st->rainfall) // + wdepth / timestep ) // compare with available water + infiltration = m_st->rainfall; // + wdepth / timestep ; - m_pcs_this->SetNodeValue(msh_node, - // output is cumulative infiltration - m_pcs_this->GetNodeValueIndex("COUPLING") + 1, F); + F = infiltration * dt + Fold; - infiltration *= -area; - value = infiltration; + m_pcs_this->SetNodeValue(msh_node, + // output is cumulative infiltration + m_pcs_this->GetNodeValueIndex("COUPLING") + 1, F); + infiltration *= -area; + value = infiltration; } - /************************************************************************** FEMLib-Method: Task: Calculate coupling flux @@ -2289,26 +2273,24 @@ void GetGreenAmptNODValue(double &value, CSourceTerm* m_st, long msh_node) **************************************************************************/ #if !defined(USE_PETSC) && !defined(NEW_EQS) // && defined(other parallel libs)//03~04.3012. WW //#ifndef NEW_EQS //WW. 06.11.2008 -void GetCouplingNODValue(double &value, CSourceTerm* st, CNodeValue* cnodev) +void GetCouplingNODValue(double& value, CSourceTerm* st, CNodeValue* cnodev) { - // if (st->COUPLING_SWITCH == true || - // st->getProcessType() == GROUNDWATER_FLOW || - // st->getProcessType() == RICHARDS_FLOW || - // st->getProcessType() == OVERLAND_FLOW) - // GetCouplingNODValuePicard(value, st, cnodev); - // else - // cout << "Error in GetCouplingNODValue"; - - if (st->isCoupled() && - (st->getProcessType() == FiniteElement::GROUNDWATER_FLOW || - st->getProcessType() == FiniteElement::RICHARDS_FLOW || - st->getProcessType() == FiniteElement::MULTI_PHASE_FLOW) ) - GetCouplingNODValuePicard(value, st, cnodev); - else if (st->isCoupled() && - st->getProcessType() == FiniteElement::OVERLAND_FLOW) - GetCouplingNODValueNewton(value, st, cnodev); - else - std::cout << "Error in GetCouplingNODValue"; + // if (st->COUPLING_SWITCH == true || + // st->getProcessType() == GROUNDWATER_FLOW || + // st->getProcessType() == RICHARDS_FLOW || + // st->getProcessType() == OVERLAND_FLOW) + // GetCouplingNODValuePicard(value, st, cnodev); + // else + // cout << "Error in GetCouplingNODValue"; + + if (st->isCoupled() && (st->getProcessType() == FiniteElement::GROUNDWATER_FLOW + || st->getProcessType() == FiniteElement::RICHARDS_FLOW + || st->getProcessType() == FiniteElement::MULTI_PHASE_FLOW)) + GetCouplingNODValuePicard(value, st, cnodev); + else if (st->isCoupled() && st->getProcessType() == FiniteElement::OVERLAND_FLOW) + GetCouplingNODValueNewton(value, st, cnodev); + else + std::cout << "Error in GetCouplingNODValue"; } #endif @@ -2324,102 +2306,95 @@ void GetCouplingNODValue(double &value, CSourceTerm* st, CNodeValue* cnodev) **************************************************************************/ #if !defined(USE_PETSC) && !defined(NEW_EQS) // && defined(other parallel libs)//03~04.3012. WW //#ifndef NEW_EQS //WW. 06.11.2008 -void GetCouplingNODValuePicard(double &value - , CSourceTerm* m_st, -CNodeValue* cnodev) +void GetCouplingNODValuePicard(double& value, CSourceTerm* m_st, CNodeValue* cnodev) { + double relPerm, condArea; + double h_this, h_cond, z_this, z_cond, h_cond_shifted, help; + double gamma = 1; + CRFProcess* m_pcs_this = NULL; + CRFProcess* m_pcs_cond = NULL; + m_pcs_this = PCSGet(convertProcessTypeToString(m_st->getProcessType())); + m_pcs_cond = PCSGet(m_st->pcs_type_name_cond); + long mesh_node_number, mesh_node_number_conditional; + + if ((mesh_node_number = cnodev->msh_node_number) < (long)m_pcs_this->m_msh->nod_vector.size()) + { // liquid + mesh_node_number_conditional = cnodev->msh_node_number_conditional; + if (m_st->getProcessType() == FiniteElement::RICHARDS_FLOW) + gamma = mfp_vector[0]->Density() * GRAVITY_CONSTANT; // liquid pressure as a primary variable + else if (m_st->getProcessType() == FiniteElement::MULTI_PHASE_FLOW) + gamma = -mfp_vector[0]->Density() * GRAVITY_CONSTANT; // capillary pressure as a primary variable + } + else + { // gas + mesh_node_number -= m_pcs_this->m_msh->nod_vector.size(); + /*if( m_st->pcs_type_name_cond == "MULTI_PHASE_FLOW") + mesh_node_number_conditional = cnodev->msh_node_number_conditional - m_pcs_this->m_msh->nod_vector.size(); + else*/ + mesh_node_number_conditional = cnodev->msh_node_number_conditional; + gamma = mfp_vector[1]->Density() * GRAVITY_CONSTANT; // gas pressure as a primary variable + } + + GetCouplingFieldVariables(m_pcs_this, m_pcs_cond, &h_this, &h_cond, &h_cond_shifted, &help, &z_this, &z_cond, m_st, + cnodev, mesh_node_number, mesh_node_number_conditional, + gamma); // z_cond shifted for soil columns - double relPerm, condArea; - double h_this, h_cond, z_this, z_cond, h_cond_shifted, help; - double gamma = 1; - CRFProcess* m_pcs_this = NULL; - CRFProcess* m_pcs_cond = NULL; - m_pcs_this = PCSGet(convertProcessTypeToString(m_st->getProcessType())); - m_pcs_cond = PCSGet(m_st->pcs_type_name_cond); - long mesh_node_number, mesh_node_number_conditional; - - if( (mesh_node_number = cnodev->msh_node_number) < (long)m_pcs_this->m_msh->nod_vector.size()) - { // liquid - mesh_node_number_conditional = cnodev->msh_node_number_conditional; - if (m_st->getProcessType() == FiniteElement::RICHARDS_FLOW) - gamma = mfp_vector[0]->Density() * GRAVITY_CONSTANT; // liquid pressure as a primary variable - else if (m_st->getProcessType() == FiniteElement::MULTI_PHASE_FLOW) - gamma = -mfp_vector[0]->Density() * GRAVITY_CONSTANT; // capillary pressure as a primary variable - } - else - { // gas - mesh_node_number -= m_pcs_this->m_msh->nod_vector.size(); - /*if( m_st->pcs_type_name_cond == "MULTI_PHASE_FLOW") - mesh_node_number_conditional = cnodev->msh_node_number_conditional - m_pcs_this->m_msh->nod_vector.size(); - else*/ - mesh_node_number_conditional = cnodev->msh_node_number_conditional; - gamma = mfp_vector[1]->Density() * GRAVITY_CONSTANT; // gas pressure as a primary variable - } - - GetCouplingFieldVariables(m_pcs_this, m_pcs_cond, &h_this, &h_cond, &h_cond_shifted, &help, - &z_this, &z_cond, m_st, cnodev, mesh_node_number, mesh_node_number_conditional, gamma); // z_cond shifted for soil columns - - ///// relative interface permeability - if(m_st->pcs_pv_name_cond == "PRESSURE2")// || m_st->pcs_type_name_cond == "OVERLAND_FLOW") - { // gas - CRFProcess* m_pcs_overland = NULL; + ///// relative interface permeability + if (m_st->pcs_pv_name_cond == "PRESSURE2") // || m_st->pcs_type_name_cond == "OVERLAND_FLOW") + { // gas + CRFProcess* m_pcs_overland = NULL; double head_overland; - m_pcs_overland = PCSGet(m_st->pcs_type_name_cond); - head_overland = m_pcs_overland->GetNodeValue(cnodev->msh_node_number_conditional, m_pcs_overland->GetNodeValueIndex("HEAD") + 1); + m_pcs_overland = PCSGet(m_st->pcs_type_name_cond); + head_overland = m_pcs_overland->GetNodeValue(cnodev->msh_node_number_conditional, + m_pcs_overland->GetNodeValueIndex("HEAD") + 1); relPerm = m_st->GetRelativeInterfacePermeability(m_pcs_overland, head_overland, - cnodev->msh_node_number_conditional); // overland + cnodev->msh_node_number_conditional); // overland } - else - { // liquid - if (h_this < h_cond_shifted) // flow direction from overland compartment - relPerm = m_st->GetRelativeInterfacePermeability(m_pcs_cond, h_cond, - cnodev->msh_node_number_conditional); - else // flow direction from subsurface compartment (, where now relPerm = 1) - relPerm = m_st->GetRelativeInterfacePermeability(m_pcs_this, h_this, - cnodev->msh_node_number_conditional); - } - - - if( m_st->explicit_surface_water_pressure) { // put hyrostatic surface liquid pressure explicitly in coupling flux - h_cond = m_pcs_cond->GetNodeValue(mesh_node_number_conditional, 0); - h_cond_shifted = h_cond - z_cond + z_this; + else + { // liquid + if (h_this < h_cond_shifted) // flow direction from overland compartment + relPerm = m_st->GetRelativeInterfacePermeability(m_pcs_cond, h_cond, cnodev->msh_node_number_conditional); + else // flow direction from subsurface compartment (, where now relPerm = 1) + relPerm = m_st->GetRelativeInterfacePermeability(m_pcs_this, h_this, cnodev->msh_node_number_conditional); } - condArea = value * relPerm * m_st->getCoupLeakance(); // area * total interface permeability (m^2/s) - - if (m_st->channel) // wetted perimeter, pcs_cond must be overland flow - condArea *= m_st->channel_width + (h_cond - z_cond); - ///// RHS part (a surface liquid pressure term) of coupling flux (m^3/s) - value = CalcCouplingValue(condArea, h_this, h_cond_shifted, z_cond, m_st); - - - if (m_st->getProcessType() == FiniteElement::GROUNDWATER_FLOW && h_this < z_cond - && m_st->pcs_type_name_cond == "OVERLAND_FLOW") - condArea = 0; // decoupled, only RHS + if (m_st->explicit_surface_water_pressure) + { // put hyrostatic surface liquid pressure explicitly in coupling flux + h_cond = m_pcs_cond->GetNodeValue(mesh_node_number_conditional, 0); + h_cond_shifted = h_cond - z_cond + z_this; + } + condArea = value * relPerm * m_st->getCoupLeakance(); // area * total interface permeability (m^2/s) - if ( m_st->getProcessPrimaryVariable() == FiniteElement::PRESSURE - && (mesh_node_number == cnodev->msh_node_number) ) // only for liquid phase - condArea /= gamma; // pressure as a primary variable - ///// - MXInc(cnodev->msh_node_number, cnodev->msh_node_number, condArea); + if (m_st->channel) // wetted perimeter, pcs_cond must be overland flow + condArea *= m_st->channel_width + (h_cond - z_cond); + ///// RHS part (a surface liquid pressure term) of coupling flux (m^3/s) + value = CalcCouplingValue(condArea, h_this, h_cond_shifted, z_cond, m_st); - if(m_st->getProcessType() == FiniteElement::MULTI_PHASE_FLOW && m_st->pcs_pv_name_cond == "HEAD" // - && m_st->pcs_type_name_cond == "OVERLAND_FLOW" ) // ??? - { // gas pressure term - MXInc(cnodev->msh_node_number , cnodev->msh_node_number+ m_pcs_this->m_msh->nod_vector.size(), -condArea); - value -= condArea * m_st->coup_given_value; - } + if (m_st->getProcessType() == FiniteElement::GROUNDWATER_FLOW && h_this < z_cond + && m_st->pcs_type_name_cond == "OVERLAND_FLOW") + condArea = 0; // decoupled, only RHS - if (m_st->getProcessType() == FiniteElement::GROUNDWATER_FLOW) - m_pcs_this->SetNodeValue( mesh_node_number, // for GW water balance ply / pnt - m_pcs_this->GetNodeValueIndex("FLUX") + 1, condArea); + if (m_st->getProcessPrimaryVariable() == FiniteElement::PRESSURE + && (mesh_node_number == cnodev->msh_node_number)) // only for liquid phase + condArea /= gamma; // pressure as a primary variable + ///// + MXInc(cnodev->msh_node_number, cnodev->msh_node_number, condArea); + if (m_st->getProcessType() == FiniteElement::MULTI_PHASE_FLOW && m_st->pcs_pv_name_cond == "HEAD" // + && m_st->pcs_type_name_cond == "OVERLAND_FLOW") // ??? + { // gas pressure term + MXInc(cnodev->msh_node_number, cnodev->msh_node_number + m_pcs_this->m_msh->nod_vector.size(), -condArea); + value -= condArea * m_st->coup_given_value; + } - if (m_st->no_surface_water_pressure) // neglect hydrostatic surface liquid pressure - value = 0; + if (m_st->getProcessType() == FiniteElement::GROUNDWATER_FLOW) + m_pcs_this->SetNodeValue(mesh_node_number, // for GW water balance ply / pnt + m_pcs_this->GetNodeValueIndex("FLUX") + 1, condArea); + if (m_st->no_surface_water_pressure) // neglect hydrostatic surface liquid pressure + value = 0; } #endif @@ -2435,99 +2410,89 @@ CNodeValue* cnodev) **************************************************************************/ #if !defined(USE_PETSC) && !defined(NEW_EQS) // && defined(other parallel libs)//03~04.3012. WW //#ifndef NEW_EQS //WW. 06.11.2008 -void GetCouplingNODValueNewton(double &value, CSourceTerm* m_st, -CNodeValue* cnodev) +void GetCouplingNODValueNewton(double& value, CSourceTerm* m_st, CNodeValue* cnodev) { - double relPerm, area, condArea, gamma = 0.0; - double h_this, h_cond, z_this, z_cond, h_this_shifted, h_this_averaged; - double epsilon = 1.e-7, value_jacobi, h_this_epsilon = 0.0, - relPerm_epsilon, condArea_epsilon; //OK411 epsilon as in pcs->assembleParabolicEquationNewton - - CRFProcess* m_pcs_cond = NULL; - CRFProcess* m_pcs_this = NULL; - m_pcs_this = PCSGet(convertProcessTypeToString(m_st->getProcessType())); - m_pcs_cond = PCSGet(m_st->pcs_type_name_cond); - ///// - if(m_st->pcs_type_name_cond == "RICHARDS_FLOW") - gamma = mfp_vector[0]->Density() * GRAVITY_CONSTANT; // liquid pressure as a primary variable - else if(m_st->pcs_type_name_cond == "MULTI_PHASE_FLOW") - gamma = -mfp_vector[0]->Density() * GRAVITY_CONSTANT; // capillary pressure as a primary variable - - GetCouplingFieldVariables(m_pcs_this, m_pcs_cond, &h_this, &h_cond, &h_this_shifted, - // if soil column, z_this, h_this_averaged, h_this_shifted are shifted to the column - &h_this_averaged, &z_this, &z_cond, m_st, cnodev, cnodev->msh_node_number, cnodev->msh_node_number_conditional, gamma); - - ///// relative coupling interface permeability (calculate ALWAYS implicitly) - if (h_this_shifted > h_cond) - { // flow direction from the overland compartment - relPerm = m_st->GetRelativeInterfacePermeability(m_pcs_this, h_this, - cnodev->msh_node_number); - relPerm_epsilon = m_st->GetRelativeInterfacePermeability(m_pcs_this, h_this + epsilon, // for jacobian - cnodev->msh_node_number); - } - else // flow direction from a subsurface compartment - relPerm = relPerm_epsilon = 1; - - if (m_st->node_averaging) - { // h_this_epsilon for jacobian if multiple overland nodes are coupled to a soil column - for (long i = 0; i < (long) cnodev->msh_node_numbers_averaging.size(); i++) - if (cnodev->msh_node_numbers_averaging[i] - == cnodev->msh_node_number) - h_this_epsilon = h_this_averaged + epsilon - * cnodev->msh_node_weights_averaging[i]; - } - else // h_this_epsilon for jacobian - h_this_epsilon = h_this + epsilon; - - if (m_st->no_surface_water_pressure) // neglect hydrostatic surface liquid pressure - h_this_epsilon = z_this; - - if (m_st->explicit_surface_water_pressure) - { // put hydrostatic surface liquid pressure explicitly in the coupling flux - h_this = m_pcs_this->GetNodeValue(cnodev->msh_node_number, 0); - h_this_epsilon = h_this; // for jacobian - - if (m_st->node_averaging) - { // shift overland node to soil column - h_this_shifted = h_this - m_pcs_this->m_msh->nod_vector[cnodev->msh_node_number]->getData()[2] + z_cond; - h_this_averaged = 0; - for (long i = 0; i - < (long) cnodev->msh_node_numbers_averaging.size(); i++) - h_this_averaged - += cnodev->msh_node_weights_averaging[i] - * (m_pcs_this->GetNodeValue( - cnodev->msh_node_numbers_averaging[i], - 0) - - m_pcs_this->m_msh->nod_vector[cnodev->msh_node_numbers_averaging[i]]->getData()[2]); - - h_this_averaged += z_cond; - - } - - } // end explicit - - area = value; - condArea = condArea_epsilon = area * m_st->getCoupLeakance(); - condArea *= relPerm; - condArea_epsilon *= relPerm_epsilon; - - if (m_st->channel) - { // wetted perimeter - condArea *= m_st->channel_width + (h_this - z_this); - condArea_epsilon *= m_st->channel_width + (h_this_epsilon - z_this); - } - ////// coupling flux as a source term (m^3/s) - value = CalcCouplingValue(condArea, h_this_averaged, h_cond, z_cond, m_st); + double relPerm, area, condArea, gamma = 0.0; + double h_this, h_cond, z_this, z_cond, h_this_shifted, h_this_averaged; + double epsilon = 1.e-7, value_jacobi, h_this_epsilon = 0.0, relPerm_epsilon, + condArea_epsilon; // OK411 epsilon as in pcs->assembleParabolicEquationNewton + + CRFProcess* m_pcs_cond = NULL; + CRFProcess* m_pcs_this = NULL; + m_pcs_this = PCSGet(convertProcessTypeToString(m_st->getProcessType())); + m_pcs_cond = PCSGet(m_st->pcs_type_name_cond); + ///// + if (m_st->pcs_type_name_cond == "RICHARDS_FLOW") + gamma = mfp_vector[0]->Density() * GRAVITY_CONSTANT; // liquid pressure as a primary variable + else if (m_st->pcs_type_name_cond == "MULTI_PHASE_FLOW") + gamma = -mfp_vector[0]->Density() * GRAVITY_CONSTANT; // capillary pressure as a primary variable + + GetCouplingFieldVariables(m_pcs_this, m_pcs_cond, &h_this, &h_cond, &h_this_shifted, + // if soil column, z_this, h_this_averaged, h_this_shifted are shifted to the column + &h_this_averaged, &z_this, &z_cond, m_st, cnodev, cnodev->msh_node_number, + cnodev->msh_node_number_conditional, gamma); + + ///// relative coupling interface permeability (calculate ALWAYS implicitly) + if (h_this_shifted > h_cond) + { // flow direction from the overland compartment + relPerm = m_st->GetRelativeInterfacePermeability(m_pcs_this, h_this, cnodev->msh_node_number); + relPerm_epsilon = m_st->GetRelativeInterfacePermeability(m_pcs_this, h_this + epsilon, // for jacobian + cnodev->msh_node_number); + } + else // flow direction from a subsurface compartment + relPerm = relPerm_epsilon = 1; + + if (m_st->node_averaging) + { // h_this_epsilon for jacobian if multiple overland nodes are coupled to a soil column + for (long i = 0; i < (long)cnodev->msh_node_numbers_averaging.size(); i++) + if (cnodev->msh_node_numbers_averaging[i] == cnodev->msh_node_number) + h_this_epsilon = h_this_averaged + epsilon * cnodev->msh_node_weights_averaging[i]; + } + else // h_this_epsilon for jacobian + h_this_epsilon = h_this + epsilon; + + if (m_st->no_surface_water_pressure) // neglect hydrostatic surface liquid pressure + h_this_epsilon = z_this; + + if (m_st->explicit_surface_water_pressure) + { // put hydrostatic surface liquid pressure explicitly in the coupling flux + h_this = m_pcs_this->GetNodeValue(cnodev->msh_node_number, 0); + h_this_epsilon = h_this; // for jacobian + + if (m_st->node_averaging) + { // shift overland node to soil column + h_this_shifted = h_this - m_pcs_this->m_msh->nod_vector[cnodev->msh_node_number]->getData()[2] + z_cond; + h_this_averaged = 0; + for (long i = 0; i < (long)cnodev->msh_node_numbers_averaging.size(); i++) + h_this_averaged + += cnodev->msh_node_weights_averaging[i] + * (m_pcs_this->GetNodeValue(cnodev->msh_node_numbers_averaging[i], 0) + - m_pcs_this->m_msh->nod_vector[cnodev->msh_node_numbers_averaging[i]]->getData()[2]); + + h_this_averaged += z_cond; + } - value_jacobi = -condArea_epsilon * (h_cond - h_this_epsilon) + value; // it's a Newton iteration - MXInc(cnodev->msh_node_number, cnodev->msh_node_number, value_jacobi - / epsilon); - ///// output - m_pcs_this->SetNodeValue(cnodev->msh_node_number, - // coupling flux (m/s) - m_pcs_this->GetNodeValueIndex("COUPLING") + 1, -value/ area); + } // end explicit + area = value; + condArea = condArea_epsilon = area * m_st->getCoupLeakance(); + condArea *= relPerm; + condArea_epsilon *= relPerm_epsilon; + if (m_st->channel) + { // wetted perimeter + condArea *= m_st->channel_width + (h_this - z_this); + condArea_epsilon *= m_st->channel_width + (h_this_epsilon - z_this); + } + ////// coupling flux as a source term (m^3/s) + value = CalcCouplingValue(condArea, h_this_averaged, h_cond, z_cond, m_st); + + value_jacobi = -condArea_epsilon * (h_cond - h_this_epsilon) + value; // it's a Newton iteration + MXInc(cnodev->msh_node_number, cnodev->msh_node_number, value_jacobi / epsilon); + ///// output + m_pcs_this->SetNodeValue(cnodev->msh_node_number, + // coupling flux (m/s) + m_pcs_this->GetNodeValueIndex("COUPLING") + 1, -value / area); } #endif @@ -2544,51 +2509,49 @@ CNodeValue* cnodev) double CSourceTerm::GetRelativeInterfacePermeability(CRFProcess* pcs, double head, long msh_node) { + double relPerm, sat, z; - double relPerm, sat, z; - - if(pcs->getProcessType() == FiniteElement::OVERLAND_FLOW) - { // flow direction from the overland compartment + if (pcs->getProcessType() == FiniteElement::OVERLAND_FLOW) + { // flow direction from the overland compartment - z = pcs->m_msh->nod_vector[msh_node]->getData()[2]; - sat = (head - z) / std::max(1.e-6, st_rill_height); // liquid content in an interface + z = pcs->m_msh->nod_vector[msh_node]->getData()[2]; + sat = (head - z) / std::max(1.e-6, st_rill_height); // liquid content in an interface - if( sat > 1 ) - relPerm = 1; // liquid-covered surface (interface is filled) - else if( sat < 0 ) - relPerm = 0; // no liquid on the surface - else - relPerm = pow(sat, 2*(1- sat)); // interface is partially filled by a liquid - - CRFProcess* m_pcs_multiPhase = NULL; - m_pcs_multiPhase = PCSGet("MULTI_PHASE_FLOW"); + if (sat > 1) + relPerm = 1; // liquid-covered surface (interface is filled) + else if (sat < 0) + relPerm = 0; // no liquid on the surface + else + relPerm = pow(sat, 2 * (1 - sat)); // interface is partially filled by a liquid - if(relPerm == 1 && pcs_pv_name_cond == "PRESSURE2") // surface closed for gas - { - double capillaryPressure = m_pcs_multiPhase->GetNodeValue(0, 3); + CRFProcess* m_pcs_multiPhase = NULL; + m_pcs_multiPhase = PCSGet("MULTI_PHASE_FLOW"); - if( capillaryPressure > air_breaking_capillaryPressure || air_breaking == true ) + if (relPerm == 1 && pcs_pv_name_cond == "PRESSURE2") // surface closed for gas { - relPerm *= air_breaking_factor; // air-breaking - air_breaking = true; + double capillaryPressure = m_pcs_multiPhase->GetNodeValue(0, 3); - if( capillaryPressure < air_closing_capillaryPressure ) - { // and air-breaking (hysteresis) - air_breaking = false; - } - } // end air_breaking - } // end relPerm = 1 + if (capillaryPressure > air_breaking_capillaryPressure || air_breaking == true) + { + relPerm *= air_breaking_factor; // air-breaking + air_breaking = true; + if (capillaryPressure < air_closing_capillaryPressure) + { // and air-breaking (hysteresis) + air_breaking = false; + } + } // end air_breaking + } // end relPerm = 1 - if (pcs_pv_name_cond == "PRESSURE2") - { // gas - relPerm = (1 - relPerm)* (1- coup_residualPerm) + coup_residualPerm; - } - } // end overland flow - else - relPerm = 1; // flow direction not from the overland compartment + if (pcs_pv_name_cond == "PRESSURE2") + { // gas + relPerm = (1 - relPerm) * (1 - coup_residualPerm) + coup_residualPerm; + } + } // end overland flow + else + relPerm = 1; // flow direction not from the overland compartment - return relPerm; + return relPerm; } /************************************************************************** @@ -2600,162 +2563,153 @@ double CSourceTerm::GetRelativeInterfacePermeability(CRFProcess* pcs, double hea phase = 0 in mfp, soil data in mmp_vetor[1] !!!!! 06/2007 JOD Implementation **************************************************************************/ -#if !defined(NEW_EQS) && !defined(USE_PETSC) //WW. 06.11.2008 -void GetCouplingNODValueMixed(double& value, CSourceTerm* m_st, -CNodeValue* cnodev) +#if !defined(NEW_EQS) && !defined(USE_PETSC) // WW. 06.11.2008 +void GetCouplingNODValueMixed(double& value, CSourceTerm* m_st, CNodeValue* cnodev) { + double cond1, cond0, pressure1, pressure0, bc_value, depth, gamma, sat, area; + double leakance, deltaZ; + int phase = 0; // RESTRICTION for mfp !!!!!!! + + // WW CElem *m_ele = NULL; + long msh_ele; + int group, nidx; + CRFProcess* m_pcs_cond = NULL; + CRFProcess* m_pcs_this = NULL; + m_pcs_this = PCSGet(convertProcessTypeToString(m_st->getProcessType())); + m_pcs_cond = PCSGet(m_st->pcs_type_name_cond); + + area = value; + leakance = m_st->getCoupLeakance(); + deltaZ = m_st->st_rill_height; + // phase = 0 !!!! + gamma = mfp_vector[0]->Density() * GRAVITY_CONSTANT; + long msh_node_2nd; + double const* const xyz_this(m_pcs_this->m_msh->nod_vector[cnodev->msh_node_number]->getData()); + // double y_this = m_pcs_this->m_msh->nod_vector[cnodev->msh_node_number]->Y(); + // double z_this = m_pcs_this->m_msh->nod_vector[cnodev->msh_node_number]->Z(); + + msh_node_2nd = -1; // WW + + cond0 = leakance * deltaZ; + cond1 = cond0; + + if (m_st->getProcessType() == FiniteElement::OVERLAND_FLOW) + { + ///// get number of second mesh node, provisional implementation + double epsilon = 1.e-5; + // double x_cond = m_pcs_cond->m_msh->nod_vector[cnodev->msh_node_number_conditional]->X(); + // double y_cond = m_pcs_cond->m_msh->nod_vector[cnodev->msh_node_number_conditional]->Y(); + // double z_cond = m_pcs_cond->m_msh->nod_vector[cnodev->msh_node_number_conditional]->Z(); + double const* const xyz_cond(m_pcs_cond->m_msh->nod_vector[cnodev->msh_node_number_conditional]->getData()); - double cond1, cond0, pressure1, pressure0, bc_value, depth, gamma, sat, - area; - double leakance, deltaZ; - int phase = 0; // RESTRICTION for mfp !!!!!!! - - //WW CElem *m_ele = NULL; - long msh_ele; - int group, nidx; - CRFProcess* m_pcs_cond = NULL; - CRFProcess* m_pcs_this = NULL; - m_pcs_this = PCSGet(convertProcessTypeToString (m_st->getProcessType())); - m_pcs_cond = PCSGet(m_st->pcs_type_name_cond); - - area = value; - leakance = m_st->getCoupLeakance(); - deltaZ = m_st->st_rill_height; - // phase = 0 !!!! - gamma = mfp_vector[0]->Density() * GRAVITY_CONSTANT; - long msh_node_2nd; - double const* const xyz_this (m_pcs_this->m_msh->nod_vector[cnodev->msh_node_number]->getData()); -// double y_this = m_pcs_this->m_msh->nod_vector[cnodev->msh_node_number]->Y(); -// double z_this = m_pcs_this->m_msh->nod_vector[cnodev->msh_node_number]->Z(); - - msh_node_2nd = -1; //WW - - cond0 = leakance * deltaZ; - cond1 = cond0; - - if (m_st->getProcessType () == FiniteElement::OVERLAND_FLOW) - { - - ///// get number of second mesh node, provisional implementation - double epsilon = 1.e-5; -// double x_cond = m_pcs_cond->m_msh->nod_vector[cnodev->msh_node_number_conditional]->X(); -// double y_cond = m_pcs_cond->m_msh->nod_vector[cnodev->msh_node_number_conditional]->Y(); -// double z_cond = m_pcs_cond->m_msh->nod_vector[cnodev->msh_node_number_conditional]->Z(); - double const* const xyz_cond (m_pcs_cond->m_msh->nod_vector[cnodev->msh_node_number_conditional]->getData()); - - for (size_t i = 0; i < m_pcs_cond->m_msh->nod_vector.size(); i++) { - double const* const pnt_i( - m_pcs_cond->m_msh->nod_vector[i]->getData()); - if (pnt_i[0] - xyz_cond[0] < epsilon) { - if (pnt_i[1] - xyz_cond[1] < epsilon) { - if (pnt_i[2] - (xyz_cond[2] - deltaZ) < epsilon) { + for (size_t i = 0; i < m_pcs_cond->m_msh->nod_vector.size(); i++) + { + double const* const pnt_i(m_pcs_cond->m_msh->nod_vector[i]->getData()); + if (pnt_i[0] - xyz_cond[0] < epsilon) + { + if (pnt_i[1] - xyz_cond[1] < epsilon) + { + if (pnt_i[2] - (xyz_cond[2] - deltaZ) < epsilon) + { msh_node_2nd = i; } } } } - ////////////////////////// + ////////////////////////// - nidx = m_pcs_cond->GetNodeValueIndex("PRESSURE1") + 1; + nidx = m_pcs_cond->GetNodeValueIndex("PRESSURE1") + 1; - pressure0 = m_pcs_cond->GetNodeValue( - cnodev->msh_node_number_conditional, nidx); - pressure1 = m_pcs_cond->GetNodeValue(msh_node_2nd, nidx); + pressure0 = m_pcs_cond->GetNodeValue(cnodev->msh_node_number_conditional, nidx); + pressure1 = m_pcs_cond->GetNodeValue(msh_node_2nd, nidx); - // only one phase - double gamma = mfp_vector[phase]->Density() * GRAVITY_CONSTANT; + // only one phase + double gamma = mfp_vector[phase]->Density() * GRAVITY_CONSTANT; - msh_ele - = m_pcs_cond->m_msh->nod_vector[cnodev->msh_node_number_conditional]->getConnectedElementIDs()[0]; - //WW m_ele = m_pcs_cond->m_msh->ele_vector[msh_ele]; - group = m_pcs_cond->m_msh->ele_vector[msh_ele]->GetPatchIndex(); + msh_ele = m_pcs_cond->m_msh->nod_vector[cnodev->msh_node_number_conditional]->getConnectedElementIDs()[0]; + // WW m_ele = m_pcs_cond->m_msh->ele_vector[msh_ele]; + group = m_pcs_cond->m_msh->ele_vector[msh_ele]->GetPatchIndex(); - //sat = mmp_vector[group]->SaturationCapillaryPressureFunction( -pressure0, 0); - //cond0 *= mmp_vector[group]->PermeabilitySaturationFunction(sat,0); + // sat = mmp_vector[group]->SaturationCapillaryPressureFunction( -pressure0, 0); + // cond0 *= mmp_vector[group]->PermeabilitySaturationFunction(sat,0); - sat = mmp_vector[group]->SaturationCapillaryPressureFunction(-pressure1); - cond1 *= mmp_vector[group]->PermeabilitySaturationFunction(sat, phase); - // use of relative permeability for second node (absolute perm. for top node !!!!) + sat = mmp_vector[group]->SaturationCapillaryPressureFunction(-pressure1); + cond1 *= mmp_vector[group]->PermeabilitySaturationFunction(sat, phase); + // use of relative permeability for second node (absolute perm. for top node !!!!) - value = (pressure1 - pressure0 - deltaZ * gamma) * (cond0 + cond1) - / (2* deltaZ * gamma); + value = (pressure1 - pressure0 - deltaZ * gamma) * (cond0 + cond1) / (2 * deltaZ * gamma); - m_pcs_this->SetNodeValue(cnodev->msh_node_number, - m_pcs_this->GetNodeValueIndex("COUPLING") + 1, -value); + m_pcs_this->SetNodeValue(cnodev->msh_node_number, m_pcs_this->GetNodeValueIndex("COUPLING") + 1, -value); - value *= area; - } // end overland - else { // Richards + value *= area; + } // end overland + else + { // Richards ///// get number of second mesh node, provisional implementation double epsilon = 1.e-5; - for (size_t i = 0; i < m_pcs_this->m_msh->nod_vector.size(); i++) { - double const* const pnt_i( - m_pcs_this->m_msh->nod_vector[i]->getData()); - if (pnt_i[0] - xyz_this[0] < epsilon) { - if (pnt_i[1] - xyz_this[1] < epsilon) { - if (pnt_i[2] - (xyz_this[2] - deltaZ) < epsilon) { + for (size_t i = 0; i < m_pcs_this->m_msh->nod_vector.size(); i++) + { + double const* const pnt_i(m_pcs_this->m_msh->nod_vector[i]->getData()); + if (pnt_i[0] - xyz_this[0] < epsilon) + { + if (pnt_i[1] - xyz_this[1] < epsilon) + { + if (pnt_i[2] - (xyz_this[2] - deltaZ) < epsilon) + { msh_node_2nd = i; } } } } - ////////////////////////// - - double inf_cap, supplyRate; //WW, rainfall; - long - bc_eqs_index = - m_pcs_this->m_msh->nod_vector[cnodev->msh_node_number]->GetEquationIndex(); - double z_cond = m_pcs_cond->m_msh->nod_vector[cnodev->msh_node_number_conditional]->getData()[2]; - depth = std::max(0., m_pcs_cond->GetNodeValue( - cnodev->msh_node_number_conditional, - m_pcs_cond->GetNodeValueIndex("HEAD") + 1) - z_cond); - - nidx = m_pcs_this->GetNodeValueIndex("PRESSURE1") + 1; - pressure0 = m_pcs_this->GetNodeValue(cnodev->msh_node_number, nidx); - pressure1 = m_pcs_this->GetNodeValue(msh_node_2nd, nidx); - - msh_ele - = m_pcs_this->m_msh->nod_vector[cnodev->msh_node_number]->getConnectedElementIDs()[0]; - //WW m_ele = m_pcs_this->m_msh->ele_vector[msh_ele]; - group = m_pcs_this->m_msh->ele_vector[msh_ele]->GetPatchIndex(); - - //sat = mmp_vector[group]->SaturationCapillaryPressureFunction( -pressure0); - //cond0 *= mmp_vector[group]->PermeabilitySaturationFunction(sat,phase); - - sat = mmp_vector[group]->SaturationCapillaryPressureFunction(-pressure1); - cond1 *= mmp_vector[group]->PermeabilitySaturationFunction(sat, phase); - // use of relative permeability for second node (absolute perm. for top node !!!!) - - // calculate infiltration capacity - /* //WW - if (aktuelle_zeit < m_st->rainfall_duration) - rainfall = m_st->rainfall; - else - rainfall = 0; - */ - inf_cap = (depth + deltaZ - pressure1 / gamma) * (cond0 + cond1) / (2 - * deltaZ); - supplyRate = m_st->rainfall; //+ (depth ) / dt; // dt = timeStep - - m_pcs_this->SetNodeValue(cnodev->msh_node_number, - // update coupling variable for error estimation - m_pcs_this->GetNodeValueIndex("COUPLING") + 1, inf_cap); - - if (inf_cap > supplyRate) - bc_value = pressure1 - deltaZ * gamma + gamma * supplyRate * deltaZ - * 2 / (cond0 + cond1); - else - bc_value = pressure1 - deltaZ * gamma + gamma * inf_cap * deltaZ - * 2 / (cond0 + cond1); - // bc_value = supplyRate * gamma * dt; - - MXRandbed(bc_eqs_index, bc_value, m_pcs_this->getEQSPointer()->b); //getEQSPointer. WW - value = 0; - - } // end Richards + ////////////////////////// + + double inf_cap, supplyRate; // WW, rainfall; + long bc_eqs_index = m_pcs_this->m_msh->nod_vector[cnodev->msh_node_number]->GetEquationIndex(); + double z_cond = m_pcs_cond->m_msh->nod_vector[cnodev->msh_node_number_conditional]->getData()[2]; + depth = std::max( + 0., m_pcs_cond->GetNodeValue(cnodev->msh_node_number_conditional, m_pcs_cond->GetNodeValueIndex("HEAD") + 1) + - z_cond); + + nidx = m_pcs_this->GetNodeValueIndex("PRESSURE1") + 1; + pressure0 = m_pcs_this->GetNodeValue(cnodev->msh_node_number, nidx); + pressure1 = m_pcs_this->GetNodeValue(msh_node_2nd, nidx); + + msh_ele = m_pcs_this->m_msh->nod_vector[cnodev->msh_node_number]->getConnectedElementIDs()[0]; + // WW m_ele = m_pcs_this->m_msh->ele_vector[msh_ele]; + group = m_pcs_this->m_msh->ele_vector[msh_ele]->GetPatchIndex(); + + // sat = mmp_vector[group]->SaturationCapillaryPressureFunction( -pressure0); + // cond0 *= mmp_vector[group]->PermeabilitySaturationFunction(sat,phase); + + sat = mmp_vector[group]->SaturationCapillaryPressureFunction(-pressure1); + cond1 *= mmp_vector[group]->PermeabilitySaturationFunction(sat, phase); + // use of relative permeability for second node (absolute perm. for top node !!!!) + + // calculate infiltration capacity + /* //WW + if (aktuelle_zeit < m_st->rainfall_duration) + rainfall = m_st->rainfall; + else + rainfall = 0; + */ + inf_cap = (depth + deltaZ - pressure1 / gamma) * (cond0 + cond1) / (2 * deltaZ); + supplyRate = m_st->rainfall; //+ (depth ) / dt; // dt = timeStep -} + m_pcs_this->SetNodeValue(cnodev->msh_node_number, + // update coupling variable for error estimation + m_pcs_this->GetNodeValueIndex("COUPLING") + 1, inf_cap); + + if (inf_cap > supplyRate) + bc_value = pressure1 - deltaZ * gamma + gamma * supplyRate * deltaZ * 2 / (cond0 + cond1); + else + bc_value = pressure1 - deltaZ * gamma + gamma * inf_cap * deltaZ * 2 / (cond0 + cond1); + // bc_value = supplyRate * gamma * dt; + MXRandbed(bc_eqs_index, bc_value, m_pcs_this->getEQSPointer()->b); // getEQSPointer. WW + value = 0; + + } // end Richards +} /************************************************************************** FEMLib-Method: @@ -2766,8 +2720,8 @@ CNodeValue* cnodev) 09/2010 KR cleaned up code 09/2010 TF commented out method **************************************************************************/ -//double CSourceTermGroup::GetRiverNODValue(int i,CSourceTerm* m_st, long msh_node) //WW -//void GetRiverNODValue(double &value, CNodeValue* cnodev, const CSourceTerm* m_st) //WW +// double CSourceTermGroup::GetRiverNODValue(int i,CSourceTerm* m_st, long msh_node) //WW +// void GetRiverNODValue(double &value, CNodeValue* cnodev, const CSourceTerm* m_st) //WW //{ // double h; // double paraA(cnodev->node_parameterA); //HRiver @@ -2821,53 +2775,47 @@ CNodeValue* cnodev) 02/2006 MB Implementation 02/2006 WW Change argument **************************************************************************/ -//double CSourceTermGroup::GetCriticalDepthNODValue(CNodeValue* cnodev,CSourceTerm* m_st, long msh_node) -void GetCriticalDepthNODValue(double &value, CSourceTerm* m_st, long msh_node) +// double CSourceTermGroup::GetCriticalDepthNODValue(CNodeValue* cnodev,CSourceTerm* m_st, long msh_node) +void GetCriticalDepthNODValue(double& value, CSourceTerm* m_st, long msh_node) { - double value_jacobi; - double width, flowdepth, flowdepth3, flowdepth3_epsilon; - long msh_ele; - double epsilon = 1.e-7; // like in pcs->assembleParabolicEquationNewton - - CRFProcess* m_pcs_this = NULL; - m_pcs_this = PCSGet(convertProcessTypeToString(m_st->getProcessType())); - long nidx1 = m_pcs_this->GetNodeValueIndex("HEAD") + 1; - flowdepth = m_pcs_this->GetNodeValue(msh_node, nidx1) - - m_pcs_this->m_msh->nod_vector[msh_node]->getData()[2] - m_st->st_rill_height; - - if (flowdepth < 0.0) - { - value = 0; - m_pcs_this->SetNodeValue(msh_node, - m_pcs_this->GetNodeValueIndex("FLUX") + 0, -value); - } - else - { - flowdepth3 = MathLib::fastpow(flowdepth, 3); - flowdepth3_epsilon = MathLib::fastpow(flowdepth + epsilon, 3); - - width = value; - if (m_pcs_this->m_msh->GetMaxElementDim() == 1) - { - msh_ele - = m_pcs_this->m_msh->nod_vector[msh_node]->getConnectedElementIDs()[0]; - int group = m_pcs_this->m_msh->ele_vector[msh_ele]->GetPatchIndex(); - width = mmp_vector[group]->overland_width; - } - - value = -sqrt(GRAVITY_CONSTANT * flowdepth3) * width; - - value_jacobi = sqrt(GRAVITY_CONSTANT * flowdepth3_epsilon) * width - + value; - // write source term into jacobi - MXInc(msh_node, msh_node, value_jacobi / epsilon); - - m_pcs_this->SetNodeValue(msh_node, - m_pcs_this->GetNodeValueIndex("FLUX") + 0, -value); - - } -} + double value_jacobi; + double width, flowdepth, flowdepth3, flowdepth3_epsilon; + long msh_ele; + double epsilon = 1.e-7; // like in pcs->assembleParabolicEquationNewton + + CRFProcess* m_pcs_this = NULL; + m_pcs_this = PCSGet(convertProcessTypeToString(m_st->getProcessType())); + long nidx1 = m_pcs_this->GetNodeValueIndex("HEAD") + 1; + flowdepth = m_pcs_this->GetNodeValue(msh_node, nidx1) - m_pcs_this->m_msh->nod_vector[msh_node]->getData()[2] + - m_st->st_rill_height; + + if (flowdepth < 0.0) + { + value = 0; + m_pcs_this->SetNodeValue(msh_node, m_pcs_this->GetNodeValueIndex("FLUX") + 0, -value); + } + else + { + flowdepth3 = MathLib::fastpow(flowdepth, 3); + flowdepth3_epsilon = MathLib::fastpow(flowdepth + epsilon, 3); + + width = value; + if (m_pcs_this->m_msh->GetMaxElementDim() == 1) + { + msh_ele = m_pcs_this->m_msh->nod_vector[msh_node]->getConnectedElementIDs()[0]; + int group = m_pcs_this->m_msh->ele_vector[msh_ele]->GetPatchIndex(); + width = mmp_vector[group]->overland_width; + } + + value = -sqrt(GRAVITY_CONSTANT * flowdepth3) * width; + + value_jacobi = sqrt(GRAVITY_CONSTANT * flowdepth3_epsilon) * width + value; + // write source term into jacobi + MXInc(msh_node, msh_node, value_jacobi / epsilon); + m_pcs_this->SetNodeValue(msh_node, m_pcs_this->GetNodeValueIndex("FLUX") + 0, -value); + } +} /************************************************************************** FEMLib-Method: @@ -2876,67 +2824,66 @@ void GetCriticalDepthNODValue(double &value, CSourceTerm* m_st, long msh_node) 02/2006 MB JOD Implementation 06/2007 JOD 2D case with slope in st-file **************************************************************************/ -void GetNormalDepthNODValue(double &value, CSourceTerm* st, long msh_node) +void GetNormalDepthNODValue(double& value, CSourceTerm* st, long msh_node) { - //WW int AnzNodes = 0; - //WW double Haverage = 0; - CRFProcess* pcs_this (PCSGet(st->getProcessType())); - CFEMesh* mesh (pcs_this->m_msh); - - double value_for_jacobi, S_0; - double epsilon = 1.e-7; // pcs->assembleParabolicEquationNewton !!!!!!!!! - - long msh_ele = mesh->nod_vector[msh_node]->getConnectedElementIDs()[0]; - CElem *m_ele = mesh->ele_vector[msh_ele]; - int group = mesh->ele_vector[msh_ele]->GetPatchIndex(); - double width = mmp_vector[group]->overland_width; - double fric_coef = mmp_vector[group]->friction_coefficient; - double slope_exp = mmp_vector[group]->friction_exp_slope; - double depth_exp = mmp_vector[group]->friction_exp_depth; - if (st->getNormalDepthSlope() == -1) // TF: WARNING comparison of double via == - { - if (mesh->GetMaxElementDim() > 1) - std::cout << "!!!!! give slope for NORMAL DEPTH in st-file !!!!!" - << "\n"; - - double elementlength = sqrt(MathLib::sqrDist(m_ele->GetNode(1)->getData(), m_ele->GetNode(0)->getData())); -// (MathLib::fastpow(m_ele->GetNode(1)->X()- m_ele->GetNode(0)->X(), 2) -// + MathLib::fastpow(m_ele->GetNode(1)->Y()-m_ele->GetNode(0)->Y(), 2) -// + MathLib::fastpow(m_ele->GetNode(1)->Z() - m_ele->GetNode(0)->Z(), 2)); - S_0 = (m_ele->GetNode(1)->getData()[2] - m_ele->GetNode(0)->getData()[2]) / elementlength; - if (S_0 < 0) - S_0 = -S_0; - } else - S_0 = st->getNormalDepthSlope(); - - double flowdepth = pcs_this->GetNodeValue(msh_node, 1) - - mesh->nod_vector[msh_node]->getData()[2] - st->st_rill_height; - double flowdepth_epsilon = flowdepth + epsilon; - if (flowdepth < 0.0) - { - flowdepth = 0.0; - flowdepth_epsilon = 0.0; - } - - double temp = width * fric_coef * pow(S_0, slope_exp); - if (mmp_vector[group]->channel == 1) - { - value = -pow(flowdepth * width / (2 * flowdepth + width), depth_exp) - * flowdepth * temp; - value_for_jacobi = pow(flowdepth_epsilon * width / (2 - * flowdepth_epsilon + width), depth_exp) * flowdepth_epsilon - * temp + value; - } - else - { - value = -pow(flowdepth, depth_exp + 1) * temp; - value_for_jacobi = pow(flowdepth_epsilon, depth_exp + 1) * temp + value; - } - - // write source term into jacobi - MXInc(msh_node, msh_node, value_for_jacobi / epsilon); - pcs_this->SetNodeValue(msh_node, pcs_this->GetNodeValueIndex("FLUX") - + 0, -value); + // WW int AnzNodes = 0; + // WW double Haverage = 0; + CRFProcess* pcs_this(PCSGet(st->getProcessType())); + CFEMesh* mesh(pcs_this->m_msh); + + double value_for_jacobi, S_0; + double epsilon = 1.e-7; // pcs->assembleParabolicEquationNewton !!!!!!!!! + + long msh_ele = mesh->nod_vector[msh_node]->getConnectedElementIDs()[0]; + CElem* m_ele = mesh->ele_vector[msh_ele]; + int group = mesh->ele_vector[msh_ele]->GetPatchIndex(); + double width = mmp_vector[group]->overland_width; + double fric_coef = mmp_vector[group]->friction_coefficient; + double slope_exp = mmp_vector[group]->friction_exp_slope; + double depth_exp = mmp_vector[group]->friction_exp_depth; + if (st->getNormalDepthSlope() == -1) // TF: WARNING comparison of double via == + { + if (mesh->GetMaxElementDim() > 1) + std::cout << "!!!!! give slope for NORMAL DEPTH in st-file !!!!!" + << "\n"; + + double elementlength = sqrt(MathLib::sqrDist(m_ele->GetNode(1)->getData(), m_ele->GetNode(0)->getData())); + // (MathLib::fastpow(m_ele->GetNode(1)->X()- m_ele->GetNode(0)->X(), 2) + // + MathLib::fastpow(m_ele->GetNode(1)->Y()-m_ele->GetNode(0)->Y(), 2) + // + MathLib::fastpow(m_ele->GetNode(1)->Z() - m_ele->GetNode(0)->Z(), 2)); + S_0 = (m_ele->GetNode(1)->getData()[2] - m_ele->GetNode(0)->getData()[2]) / elementlength; + if (S_0 < 0) + S_0 = -S_0; + } + else + S_0 = st->getNormalDepthSlope(); + + double flowdepth + = pcs_this->GetNodeValue(msh_node, 1) - mesh->nod_vector[msh_node]->getData()[2] - st->st_rill_height; + double flowdepth_epsilon = flowdepth + epsilon; + if (flowdepth < 0.0) + { + flowdepth = 0.0; + flowdepth_epsilon = 0.0; + } + + double temp = width * fric_coef * pow(S_0, slope_exp); + if (mmp_vector[group]->channel == 1) + { + value = -pow(flowdepth * width / (2 * flowdepth + width), depth_exp) * flowdepth * temp; + value_for_jacobi + = pow(flowdepth_epsilon * width / (2 * flowdepth_epsilon + width), depth_exp) * flowdepth_epsilon * temp + + value; + } + else + { + value = -pow(flowdepth, depth_exp + 1) * temp; + value_for_jacobi = pow(flowdepth_epsilon, depth_exp + 1) * temp + value; + } + + // write source term into jacobi + MXInc(msh_node, msh_node, value_for_jacobi / epsilon); + pcs_this->SetNodeValue(msh_node, pcs_this->GetNodeValueIndex("FLUX") + 0, -value); } #endif @@ -2949,46 +2896,49 @@ void GetNormalDepthNODValue(double &value, CSourceTerm* st, long msh_node) void GetNODValue(double& value, CNodeValue* cnodev, CSourceTerm* st) { #if !defined(USE_PETSC) && !defined(NEW_EQS) // && defined(other parallel libs)//03~04.3012. WW - //#ifndef NEW_EQS //WW. 06.11.2008 - if (st->isCoupled()) - GetCouplingNODValue(value, st, cnodev); - else if (st->isAnalytical()) - { - //WW m_st_group->m_msh = m_msh; - //WW - value = st->GetAnalyticalSolution(cnodev->msh_node_number); - //WW value = m_st_group->GetAnalyticalSolution(m_st,msh_node,(string)function_name[j]); - } - - // if (cnodev->node_distype == 5) // River Condition - // if (cnodev->getProcessDistributionType() == RIVER) - // GetRiverNODValue(value, cnodev, st); //MB - // if (cnodev->node_distype == 6) // CriticalDepth Condition - // CriticalDepth Condition - if (cnodev->getProcessDistributionType() == FiniteElement::CRITICALDEPTH) - //MB - GetCriticalDepthNODValue(value, st, cnodev->msh_node_number); - // if (cnodev->node_distype == 8) // NormalDepth Condition JOD - if (cnodev->getProcessDistributionType() == FiniteElement::NORMALDEPTH) - //MB - GetNormalDepthNODValue(value, st, cnodev->msh_node_number); -#endif - // if (cnodev->node_distype == 10) // Philip infiltration JOD - // GetPhilipNODValue(value, st); - // if (cnodev->node_distype == 11) // Green_Ampt infiltration JOD - if (cnodev->getProcessDistributionType() == FiniteElement::GREEN_AMPT) - GetGreenAmptNODValue(value, st, cnodev->msh_node_number); - - //TN - Test flux with heat transfer coefficient - if (st->getProcessPrimaryVariable() == FiniteElement::TEMPERATURE && st->getProcessDistributionType() == FiniteElement::TRANSFER_SURROUNDING) { - GetNODHeatTransfer(value, st, cnodev->geo_node_number); - //value = st->getTransferCoefficient()*cnodev->node_area*(cnodev->node_value - st->getValueSurrounding()); - } - else if (st->getProcessPrimaryVariable() == FiniteElement::TEMPERATURE2 && st->getProcessDistributionType() == FiniteElement::TRANSFER_SURROUNDING) { - GetNODHeatTransfer(value, st, cnodev->geo_node_number); - //value = st->getTransferCoefficient()*cnodev->node_area*(cnodev->node_value - st->getValueSurrounding()); - } + //#ifndef NEW_EQS //WW. 06.11.2008 + if (st->isCoupled()) + GetCouplingNODValue(value, st, cnodev); + else if (st->isAnalytical()) + { + // WW m_st_group->m_msh = m_msh; + // WW + value = st->GetAnalyticalSolution(cnodev->msh_node_number); + // WW value = m_st_group->GetAnalyticalSolution(m_st,msh_node,(string)function_name[j]); + } + // if (cnodev->node_distype == 5) // River Condition + // if (cnodev->getProcessDistributionType() == RIVER) + // GetRiverNODValue(value, cnodev, st); //MB + // if (cnodev->node_distype == 6) // CriticalDepth Condition + // CriticalDepth Condition + if (cnodev->getProcessDistributionType() == FiniteElement::CRITICALDEPTH) + // MB + GetCriticalDepthNODValue(value, st, cnodev->msh_node_number); + // if (cnodev->node_distype == 8) // NormalDepth Condition JOD + if (cnodev->getProcessDistributionType() == FiniteElement::NORMALDEPTH) + // MB + GetNormalDepthNODValue(value, st, cnodev->msh_node_number); +#endif + // if (cnodev->node_distype == 10) // Philip infiltration JOD + // GetPhilipNODValue(value, st); + // if (cnodev->node_distype == 11) // Green_Ampt infiltration JOD + if (cnodev->getProcessDistributionType() == FiniteElement::GREEN_AMPT) + GetGreenAmptNODValue(value, st, cnodev->msh_node_number); + + // TN - Test flux with heat transfer coefficient + if (st->getProcessPrimaryVariable() == FiniteElement::TEMPERATURE + && st->getProcessDistributionType() == FiniteElement::TRANSFER_SURROUNDING) + { + GetNODHeatTransfer(value, st, cnodev->geo_node_number); + // value = st->getTransferCoefficient()*cnodev->node_area*(cnodev->node_value - st->getValueSurrounding()); + } + else if (st->getProcessPrimaryVariable() == FiniteElement::TEMPERATURE2 + && st->getProcessDistributionType() == FiniteElement::TRANSFER_SURROUNDING) + { + GetNODHeatTransfer(value, st, cnodev->geo_node_number); + // value = st->getTransferCoefficient()*cnodev->node_area*(cnodev->node_value - st->getValueSurrounding()); + } } /************************************************************************** @@ -2998,57 +2948,58 @@ void GetNODValue(double& value, CNodeValue* cnodev, CSourceTerm* st) 04/2013 TN Implementation last modified: **************************************************************************/ -void GetNODHeatTransfer(double& value, CSourceTerm* st, long geo_node){ - CRFProcess* m_pcs_this = NULL; - double poro; - - //Get process type - m_pcs_this = PCSGet(convertProcessTypeToString(st->getProcessType())); - //Get Mesh - CFEMesh* mesh (m_pcs_this->m_msh); - - //Get number of conneted elements - size_t number_of_connected_elements = mesh->nod_vector[geo_node]->getConnectedElementIDs().size(); - - poro = 0.0; - double geo_area = 0.0; +void GetNODHeatTransfer(double& value, CSourceTerm* st, long geo_node) +{ + CRFProcess* m_pcs_this = NULL; + double poro; - //loop over connected elements and get average porosity - for (size_t i=0;inod_vector[geo_node]->getConnectedElementIDs()[i]; - int group = mesh->ele_vector[msh_ele]->GetPatchIndex(); - poro += mmp_vector[group]->porosity; - geo_area += mmp_vector[group]->geo_area; - } - poro /= number_of_connected_elements; - geo_area /= number_of_connected_elements; + // Get process type + m_pcs_this = PCSGet(convertProcessTypeToString(st->getProcessType())); + // Get Mesh + CFEMesh* mesh(m_pcs_this->m_msh); - //if (mesh->isAxisymmetry() && mesh->GetMaxElementDim()!=1) //For axisymmetric 2D meshes geometry area is irrelevant - // geo_area = 1.0; + // Get number of conneted elements + size_t number_of_connected_elements = mesh->nod_vector[geo_node]->getConnectedElementIDs().size(); + poro = 0.0; + double geo_area = 0.0; + // loop over connected elements and get average porosity + for (size_t i = 0; i < number_of_connected_elements; i++) + { + long msh_ele = mesh->nod_vector[geo_node]->getConnectedElementIDs()[i]; + int group = mesh->ele_vector[msh_ele]->GetPatchIndex(); + poro += mmp_vector[group]->porosity; + geo_area += mmp_vector[group]->geo_area; + } + poro /= number_of_connected_elements; + geo_area /= number_of_connected_elements; - //Get index of primary variable - long nidx1 = m_pcs_this->GetNodeValueIndex(convertPrimaryVariableToString(st->getProcessPrimaryVariable())) + 1; + // if (mesh->isAxisymmetry() && mesh->GetMaxElementDim()!=1) //For axisymmetric 2D meshes geometry area is + // irrelevant + // geo_area = 1.0; - //Get current primary variable value at that node - double temp = m_pcs_this->GetNodeValue(geo_node, nidx1); + // Get index of primary variable + long nidx1 = m_pcs_this->GetNodeValueIndex(convertPrimaryVariableToString(st->getProcessPrimaryVariable())) + 1; - //Find position of current node in st vectors - size_t i; - for (i=0; iget_node_value_vectorArea().size(); i++){ - if (geo_node == st->st_node_ids[i]) - break; - } + // Get current primary variable value at that node + double temp = m_pcs_this->GetNodeValue(geo_node, nidx1); - value = st->getTransferCoefficient()*(st->getValueSurrounding() - temp); - value *= st->get_node_value_vectorArea()[i]*geo_area; + // Find position of current node in st vectors + size_t i; + for (i = 0; i < st->get_node_value_vectorArea().size(); i++) + { + if (geo_node == st->st_node_ids[i]) + break; + } - if (st->getProcessPrimaryVariable() == FiniteElement::TEMPERATURE2) - value *= (1.0 - poro); - else if (st->getProcessPrimaryVariable() == FiniteElement::TEMPERATURE) - value *= poro; + value = st->getTransferCoefficient() * (st->getValueSurrounding() - temp); + value *= st->get_node_value_vectorArea()[i] * geo_area; + if (st->getProcessPrimaryVariable() == FiniteElement::TEMPERATURE2) + value *= (1.0 - poro); + else if (st->getProcessPrimaryVariable() == FiniteElement::TEMPERATURE) + value *= poro; } /************************************************************************** @@ -3060,23 +3011,22 @@ void GetNODHeatTransfer(double& value, CSourceTerm* st, long geo_node){ **************************************************************************/ void STGroupDelete(std::string pcs_type_name, std::string pcs_pv_name) { - CSourceTermGroup* m_st_group = NULL; - std::list::const_iterator p = st_group_list.begin(); - while (p != st_group_list.end()) - { - m_st_group = *p; - if ((m_st_group->pcs_type_name.compare(pcs_type_name) == 0) - && (m_st_group->pcs_pv_name.compare(pcs_pv_name) == 0)) - { - delete m_st_group; - st_group_list.remove(m_st_group); - return; - } - ++p; - } + CSourceTermGroup* m_st_group = NULL; + std::list::const_iterator p = st_group_list.begin(); + while (p != st_group_list.end()) + { + m_st_group = *p; + if ((m_st_group->pcs_type_name.compare(pcs_type_name) == 0) + && (m_st_group->pcs_pv_name.compare(pcs_pv_name) == 0)) + { + delete m_st_group; + st_group_list.remove(m_st_group); + return; + } + ++p; + } } - /************************************************************************** FEMLib-Method: Task: @@ -3085,171 +3035,169 @@ void STGroupDelete(std::string pcs_type_name, std::string pcs_pv_name) modification: 05/2010 **************************************************************************/ -void CSourceTermGroup::SetPNT(CRFProcess* pcs, CSourceTerm* st, -const int ShiftInNodeVector) +void CSourceTermGroup::SetPNT(CRFProcess* pcs, CSourceTerm* st, const int ShiftInNodeVector) { - //05.2012. WW - long node_id = m_msh->GetNODOnPNT(static_cast(st->getGeoObj())); - if(node_id < 0) - return; - CNodeValue *nod_val (new CNodeValue()); - - // TF removed some checks - check validity of data while reading data - - nod_val->msh_node_number = m_msh->GetNODOnPNT(static_cast(st->getGeoObj())) + ShiftInNodeVector; - - nod_val->CurveIndex = st->CurveIndex; - //WW - nod_val->geo_node_number = nod_val->msh_node_number - ShiftInNodeVector; - nod_val->node_value = st->geo_node_value; - nod_val->tim_type_name = st->tim_type_name; - - if (st->getProcessDistributionType() == FiniteElement::CRITICALDEPTH) - { - // if (st->dis_type_name.compare("CRITICALDEPTH") == 0) { - nod_val->setProcessDistributionType (st->getProcessDistributionType()); - nod_val->node_area = 1.0; - std::cout << " - Critical depth" << std::endl; - } - - if (st->getProcessDistributionType() == FiniteElement::NORMALDEPTH) - { - nod_val->setProcessDistributionType (st->getProcessDistributionType()); - nod_val->node_area = 1.0; - std::cout << " - Normal depth" << std::endl; - } - - // if (st->dis_type_name.compare("PHILIP") == 0) { // JOD - // nod_val->node_distype = 10; - // nod_val->node_area = 1.0; - // } - - if (st->getProcessDistributionType() == FiniteElement::GREEN_AMPT) - { - nod_val->setProcessDistributionType (st->getProcessDistributionType()); - nod_val->node_area = 1.0; - std::cout << " - Green-Ampt" << std::endl; - } - - if (st->getProcessDistributionType() == FiniteElement::SYSTEM_DEPENDENT) - { - nod_val->setProcessDistributionType (st->getProcessDistributionType()); - pcs->compute_domain_face_normal = true; //WW - CElem* elem = NULL; - CNode* cnode = NULL; //WW - for (size_t i = 0; i < m_msh->ele_vector.size(); i++) - { - elem = m_msh->ele_vector[i]; - if (!elem->GetMark()) - continue; - int nn = elem->GetNodesNumber(m_msh->getOrder()); - for (long j = 0; j < nn; j++) - { - cnode = elem->GetNode(j); //WW - if (cnode->GetIndex() == (size_t)st->geo_node_number) - st->element_st_vector.push_back(i); - } - } - } - - if (st->getProcessDistributionType() == FiniteElement::TRANSFER_SURROUNDING) { //TN - Belegung mit Fl�chenelementen + // 05.2012. WW + long node_id = m_msh->GetNODOnPNT(static_cast(st->getGeoObj())); + if (node_id < 0) + return; + CNodeValue* nod_val(new CNodeValue()); + + // TF removed some checks - check validity of data while reading data + + nod_val->msh_node_number + = m_msh->GetNODOnPNT(static_cast(st->getGeoObj())) + ShiftInNodeVector; + + nod_val->CurveIndex = st->CurveIndex; + // WW + nod_val->geo_node_number = nod_val->msh_node_number - ShiftInNodeVector; + nod_val->node_value = st->geo_node_value; + nod_val->tim_type_name = st->tim_type_name; + + if (st->getProcessDistributionType() == FiniteElement::CRITICALDEPTH) + { + // if (st->dis_type_name.compare("CRITICALDEPTH") == 0) { + nod_val->setProcessDistributionType(st->getProcessDistributionType()); + nod_val->node_area = 1.0; + std::cout << " - Critical depth" << std::endl; + } + + if (st->getProcessDistributionType() == FiniteElement::NORMALDEPTH) + { + nod_val->setProcessDistributionType(st->getProcessDistributionType()); + nod_val->node_area = 1.0; + std::cout << " - Normal depth" << std::endl; + } + + // if (st->dis_type_name.compare("PHILIP") == 0) { // JOD + // nod_val->node_distype = 10; + // nod_val->node_area = 1.0; + // } + + if (st->getProcessDistributionType() == FiniteElement::GREEN_AMPT) + { + nod_val->setProcessDistributionType(st->getProcessDistributionType()); + nod_val->node_area = 1.0; + std::cout << " - Green-Ampt" << std::endl; + } + + if (st->getProcessDistributionType() == FiniteElement::SYSTEM_DEPENDENT) + { + nod_val->setProcessDistributionType(st->getProcessDistributionType()); + pcs->compute_domain_face_normal = true; // WW + CElem* elem = NULL; + CNode* cnode = NULL; // WW + for (size_t i = 0; i < m_msh->ele_vector.size(); i++) + { + elem = m_msh->ele_vector[i]; + if (!elem->GetMark()) + continue; + int nn = elem->GetNodesNumber(m_msh->getOrder()); + for (long j = 0; j < nn; j++) + { + cnode = elem->GetNode(j); // WW + if (cnode->GetIndex() == (size_t)st->geo_node_number) + st->element_st_vector.push_back(i); + } + } + } + + if (st->getProcessDistributionType() == FiniteElement::TRANSFER_SURROUNDING) + { // TN - Belegung mit Fl�chenelementen st->node_value_vectorArea.resize(1); - st->node_value_vectorArea[0] = 1.0; - //nod_val->node_value = 0.0; + st->node_value_vectorArea[0] = 1.0; + // nod_val->node_value = 0.0; ////Get process type - //CRFProcess* m_pcs_this = PCSGet(convertProcessTypeToString(st->getProcessType())); + // CRFProcess* m_pcs_this = PCSGet(convertProcessTypeToString(st->getProcessType())); ////Get Mesh - //CFEMesh* mesh (m_pcs_this->m_msh); - //long msh_ele = mesh->nod_vector[nod_val->geo_node_number]->getConnectedElementIDs()[0]; - // int group = mesh->ele_vector[msh_ele]->GetPatchIndex(); + // CFEMesh* mesh (m_pcs_this->m_msh); + // long msh_ele = mesh->nod_vector[nod_val->geo_node_number]->getConnectedElementIDs()[0]; + // int group = mesh->ele_vector[msh_ele]->GetPatchIndex(); - //st->node_value_vectorArea[0] = mmp_vector[group]->geo_area; + // st->node_value_vectorArea[0] = mmp_vector[group]->geo_area; if (m_msh->isAxisymmetry() && m_msh->GetMaxElementDim() == 1) - st->node_value_vectorArea[0] *= m_msh->nod_vector[nod_val->geo_node_number]->X(); //2pi is mulitplicated during the integration process - } - - if (st->getProcessDistributionType()==FiniteElement::RECHARGE) //MW - { - nod_val->setProcessDistributionType (st->getProcessDistributionType()); - } + st->node_value_vectorArea[0] *= m_msh->nod_vector[nod_val->geo_node_number] + ->X(); // 2pi is mulitplicated during the integration process + } - st->st_node_ids.push_back(nod_val->geo_node_number); + if (st->getProcessDistributionType() == FiniteElement::RECHARGE) // MW + { + nod_val->setProcessDistributionType(st->getProcessDistributionType()); + } - if (st->isConstrainedST()) - { - st->_constrainedSTNodesIndices.push_back(-1); - for (std::size_t i(0); i < st->getNumberOfConstrainedSTs(); i++) - st->pushBackConstrainedSTNode(i,false); - } + st->st_node_ids.push_back(nod_val->geo_node_number); - //WW group_vector.push_back(m_node_value); - //WW st_group_vector.push_back(st); //OK - pcs->st_node_value.push_back(nod_val); //WW - pcs->st_node.push_back(st); //WW + if (st->isConstrainedST()) + { + st->_constrainedSTNodesIndices.push_back(-1); + for (std::size_t i(0); i < st->getNumberOfConstrainedSTs(); i++) + st->pushBackConstrainedSTNode(i, false); + } + // WW group_vector.push_back(m_node_value); + // WW st_group_vector.push_back(st); //OK + pcs->st_node_value.push_back(nod_val); // WW + pcs->st_node.push_back(st); // WW } - /************************************************************************** FEMLib-Method: Task: Programing: 11/2007 JOD Implementation **************************************************************************/ -void CSourceTermGroup::SetLIN(CRFProcess* m_pcs, CSourceTerm* m_st, -const int ShiftInNodeVector) +void CSourceTermGroup::SetLIN(CRFProcess* m_pcs, CSourceTerm* m_st, const int ShiftInNodeVector) { - (void)m_pcs; - (void)m_st; - (void)ShiftInNodeVector; - /*OK411 - long number_of_nodes; - vectorlin_nod_vector; - vectorlin_nod_val_vector; - CGLLine* m_lin = NULL; - CGLPolyline* m_ply = NULL; - long *nodes = NULL; - m_lin = m_lin->GEOGetLine(m_st->geo_id); - - if(m_lin){ - double* coordinates; - m_ply = new CGLPolyline; - m_ply->point_vector.push_back(m_lin->m_point1); - m_ply->point_vector.push_back(m_lin->m_point2); - nodes = MSHGetNodesClose(&number_of_nodes, m_ply);//CC - lin_nod_val_vector.resize(number_of_nodes); - for(long i = 0; i < number_of_nodes; i++){ - lin_nod_val_vector[i] = m_st->geo_node_value / number_of_nodes; - coordinates = new double[3]; - coordinates[0] = GetNodeX(nodes[i]); - coordinates[1] = GetNodeY(nodes[i]); - coordinates[2] = GetNodeZ(nodes[i]); - m_lin->nodes_coor_vector.push_back(coordinates); - } - //InterpolationAlongPolyline(m_polyline,node_value_vector); - for(long i=0; i < number_of_nodes; i++){ - CNodeValue* m_nod_val = NULL; - m_nod_val = new CNodeValue(); - m_nod_val->msh_node_number = -1; - m_nod_val->msh_node_number = nodes[i]+ShiftInNodeVector; - m_nod_val->geo_node_number = nodes[i]; - m_nod_val->node_value = lin_nod_val_vector[i]; - m_nod_val->CurveIndex = m_st->CurveIndex; - //WW group_vector.push_back(m_node_value); - //WW st_group_vector.push_back(m_st); //OK - m_pcs->st_node_value.push_back(m_nod_val); //WW - m_pcs->st_node.push_back(m_st); //WW - } - lin_nod_val_vector.clear(); - m_ply->point_vector.clear(); - delete m_ply; - } - else - cout << "Warning - CSourceTermGroup::Set: LIN not found" << '\n'; - */ + (void)m_pcs; + (void)m_st; + (void)ShiftInNodeVector; + /*OK411 + long number_of_nodes; + vectorlin_nod_vector; + vectorlin_nod_val_vector; + CGLLine* m_lin = NULL; + CGLPolyline* m_ply = NULL; + long *nodes = NULL; + m_lin = m_lin->GEOGetLine(m_st->geo_id); + + if(m_lin){ + double* coordinates; + m_ply = new CGLPolyline; + m_ply->point_vector.push_back(m_lin->m_point1); + m_ply->point_vector.push_back(m_lin->m_point2); + nodes = MSHGetNodesClose(&number_of_nodes, m_ply);//CC + lin_nod_val_vector.resize(number_of_nodes); + for(long i = 0; i < number_of_nodes; i++){ + lin_nod_val_vector[i] = m_st->geo_node_value / number_of_nodes; + coordinates = new double[3]; + coordinates[0] = GetNodeX(nodes[i]); + coordinates[1] = GetNodeY(nodes[i]); + coordinates[2] = GetNodeZ(nodes[i]); + m_lin->nodes_coor_vector.push_back(coordinates); + } + //InterpolationAlongPolyline(m_polyline,node_value_vector); + for(long i=0; i < number_of_nodes; i++){ + CNodeValue* m_nod_val = NULL; + m_nod_val = new CNodeValue(); + m_nod_val->msh_node_number = -1; + m_nod_val->msh_node_number = nodes[i]+ShiftInNodeVector; + m_nod_val->geo_node_number = nodes[i]; + m_nod_val->node_value = lin_nod_val_vector[i]; + m_nod_val->CurveIndex = m_st->CurveIndex; + //WW group_vector.push_back(m_node_value); + //WW st_group_vector.push_back(m_st); //OK + m_pcs->st_node_value.push_back(m_nod_val); //WW + m_pcs->st_node.push_back(m_st); //WW + } + lin_nod_val_vector.clear(); + m_ply->point_vector.clear(); + delete m_ply; + } + else + cout << "Warning - CSourceTermGroup::Set: LIN not found" << '\n'; + */ } - /************************************************************************** FEMLib-Method: Task: @@ -3260,23 +3208,24 @@ const int ShiftInNodeVector) **************************************************************************/ void CSourceTermGroup::SetPLY(CSourceTerm* st, int ShiftInNodeVector) { - CGLPolyline* old_ply (GEOGetPLYByName(st->geo_name)); - if (old_ply) { + CGLPolyline* old_ply(GEOGetPLYByName(st->geo_name)); + if (old_ply) + { std::vector ply_nod_vector; std::vector ply_nod_vector_cond; std::vector ply_nod_val_vector; - double min_edge_length (m_msh->getMinEdgeLength()); - m_msh->setMinEdgeLength (old_ply->epsilon); + double min_edge_length(m_msh->getMinEdgeLength()); + m_msh->setMinEdgeLength(old_ply->epsilon); m_msh->GetNODOnPLY(static_cast(st->getGeoObj()), ply_nod_vector, true); - m_msh->setMinEdgeLength (min_edge_length); + m_msh->setMinEdgeLength(min_edge_length); if (st->isCoupled()) SetPolylineNodeVectorConditional(st, ply_nod_vector, ply_nod_vector_cond); SetPolylineNodeValueVector(st, ply_nod_vector, ply_nod_vector_cond, ply_nod_val_vector); - if (st->distribute_volume_flux) // 5.3.07 JOD + if (st->distribute_volume_flux) // 5.3.07 JOD DistributeVolumeFlux(st, ply_nod_vector, ply_nod_val_vector); st->st_node_ids.clear(); @@ -3297,69 +3246,61 @@ void CSourceTermGroup::SetPLY(CSourceTerm* st, int ShiftInNodeVector) } // end polyline } - /************************************************************************** FEMLib-Method: Task: Programing: 11/2007 JOD Implementation **************************************************************************/ -void CSourceTermGroup::SetDMN(CSourceTerm *m_st, const int ShiftInNodeVector) +void CSourceTermGroup::SetDMN(CSourceTerm* m_st, const int ShiftInNodeVector) { - std::vector dmn_nod_vector; - std::vector dmn_nod_val_vector; - std::vector dmn_nod_vector_cond; - - GEOGetNodesInMaterialDomain(m_msh, m_st->analytical_material_group, - dmn_nod_vector, false); - size_t number_of_nodes (dmn_nod_vector.size()); - dmn_nod_val_vector.resize(number_of_nodes); + std::vector dmn_nod_vector; + std::vector dmn_nod_val_vector; + std::vector dmn_nod_vector_cond; - for (size_t i = 0; i < number_of_nodes; i++) - dmn_nod_val_vector[i] = 0; + GEOGetNodesInMaterialDomain(m_msh, m_st->analytical_material_group, dmn_nod_vector, false); + size_t number_of_nodes(dmn_nod_vector.size()); + dmn_nod_val_vector.resize(number_of_nodes); - m_st->SetNodeValues(dmn_nod_vector, dmn_nod_vector_cond, - dmn_nod_val_vector, ShiftInNodeVector); + for (size_t i = 0; i < number_of_nodes; i++) + dmn_nod_val_vector[i] = 0; + m_st->SetNodeValues(dmn_nod_vector, dmn_nod_vector_cond, dmn_nod_val_vector, ShiftInNodeVector); } - /************************************************************************** FEMLib-Method: Task: Programing: 02/2008 JOD Implementation **************************************************************************/ -void CSourceTermGroup::SetCOL(CSourceTerm *m_st, const int ShiftInNodeVector) +void CSourceTermGroup::SetCOL(CSourceTerm* m_st, const int ShiftInNodeVector) { - long number_of_nodes; - std::vector col_nod_vector; - std::vector col_nod_val_vector; - std::vector col_nod_vector_cond; - - long i = 0; - if (m_st->geo_name == "BOTTOM") - i = m_msh->getNumberOfMeshLayers() - 1; + long number_of_nodes; + std::vector col_nod_vector; + std::vector col_nod_val_vector; + std::vector col_nod_vector_cond; - while (i < (long) m_msh->nod_vector.size()) - { - col_nod_vector.push_back(i); - i += m_msh->getNumberOfMeshLayers(); - } - number_of_nodes = (long) col_nod_vector.size(); - col_nod_val_vector.resize(number_of_nodes); + long i = 0; + if (m_st->geo_name == "BOTTOM") + i = m_msh->getNumberOfMeshLayers() - 1; - for (long i = 0; i < number_of_nodes; i++) - col_nod_val_vector[i] = 1; + while (i < (long)m_msh->nod_vector.size()) + { + col_nod_vector.push_back(i); + i += m_msh->getNumberOfMeshLayers(); + } + number_of_nodes = (long)col_nod_vector.size(); + col_nod_val_vector.resize(number_of_nodes); - m_st->SetSurfaceNodeVectorConditional(col_nod_vector, col_nod_vector_cond); + for (long i = 0; i < number_of_nodes; i++) + col_nod_val_vector[i] = 1; - m_st->SetNodeValues(col_nod_vector, col_nod_vector_cond, - col_nod_val_vector, ShiftInNodeVector); + m_st->SetSurfaceNodeVectorConditional(col_nod_vector, col_nod_vector_cond); + m_st->SetNodeValues(col_nod_vector, col_nod_vector_cond, col_nod_val_vector, ShiftInNodeVector); } - /************************************************************************** FEMLib-Method: Task: @@ -3369,57 +3310,50 @@ void CSourceTermGroup::SetCOL(CSourceTerm *m_st, const int ShiftInNodeVector) **************************************************************************/ void CSourceTermGroup::SetSFC(CSourceTerm* m_st, const int ShiftInNodeVector) { - std::vector sfc_nod_vector; - std::vector sfc_node_ids; - std::vector sfc_nod_vector_cond; - std::vector sfc_nod_val_vector; - Surface* m_sfc = NULL; - - m_sfc = GEOGetSFCByName(m_st->geo_name); //CC - - if (m_sfc) - { - GEOLIB::Surface const& sfc( - *(dynamic_cast(m_st->getGeoObj())) - ); - std::cout << "Surface " << m_st->geo_name << ": " << sfc.getNTriangles() << "\n"; - SetSurfaceNodeVector(&sfc, sfc_node_ids); + std::vector sfc_nod_vector; + std::vector sfc_node_ids; + std::vector sfc_nod_vector_cond; + std::vector sfc_nod_val_vector; + Surface* m_sfc = NULL; -/* - SetSurfaceNodeVector(m_sfc, sfc_nod_vector); -*/ - sfc_nod_vector.insert(sfc_nod_vector.begin(), - sfc_node_ids.begin(), sfc_node_ids.end()); - if (m_st->isCoupled()) - m_st->SetSurfaceNodeVectorConditional(sfc_nod_vector, - sfc_nod_vector_cond); - // m_st->SetDISType(); - SetSurfaceNodeValueVector(m_st, m_sfc, sfc_nod_vector, - sfc_nod_val_vector); - - if (m_st->distribute_volume_flux) // 5.3.07 JOD - DistributeVolumeFlux(m_st, sfc_nod_vector, sfc_nod_val_vector); - - m_st->st_node_ids.clear(); - m_st->st_node_ids.resize(sfc_nod_vector.size()); - m_st->st_node_ids = sfc_nod_vector; - - if (m_st->isConstrainedST()) - { - for (std::size_t i(0); i < m_st->st_node_ids.size(); i++) - { - m_st->_constrainedSTNodesIndices.push_back(-1); - for (std::size_t i(0); i < m_st->getNumberOfConstrainedSTs(); i++) - m_st->pushBackConstrainedSTNode(i, false); - } - } - - m_st->SetNodeValues(sfc_nod_vector, sfc_nod_vector_cond, - sfc_nod_val_vector, ShiftInNodeVector); - - } // end surface -} + m_sfc = GEOGetSFCByName(m_st->geo_name); // CC + if (m_sfc) + { + GEOLIB::Surface const& sfc(*(dynamic_cast(m_st->getGeoObj()))); + std::cout << "Surface " << m_st->geo_name << ": " << sfc.getNTriangles() << "\n"; + SetSurfaceNodeVector(&sfc, sfc_node_ids); + + /* + SetSurfaceNodeVector(m_sfc, sfc_nod_vector); + */ + sfc_nod_vector.insert(sfc_nod_vector.begin(), sfc_node_ids.begin(), sfc_node_ids.end()); + if (m_st->isCoupled()) + m_st->SetSurfaceNodeVectorConditional(sfc_nod_vector, sfc_nod_vector_cond); + // m_st->SetDISType(); + SetSurfaceNodeValueVector(m_st, m_sfc, sfc_nod_vector, sfc_nod_val_vector); + + if (m_st->distribute_volume_flux) // 5.3.07 JOD + DistributeVolumeFlux(m_st, sfc_nod_vector, sfc_nod_val_vector); + + m_st->st_node_ids.clear(); + m_st->st_node_ids.resize(sfc_nod_vector.size()); + m_st->st_node_ids = sfc_nod_vector; + + if (m_st->isConstrainedST()) + { + for (std::size_t i(0); i < m_st->st_node_ids.size(); i++) + { + m_st->_constrainedSTNodesIndices.push_back(-1); + for (std::size_t i(0); i < m_st->getNumberOfConstrainedSTs(); i++) + m_st->pushBackConstrainedSTNode(i, false); + } + } + + m_st->SetNodeValues(sfc_nod_vector, sfc_nod_vector_cond, sfc_nod_val_vector, ShiftInNodeVector); + + } // end surface +} /************************************************************************** FEMLib-Method: @@ -3429,27 +3363,23 @@ void CSourceTermGroup::SetSFC(CSourceTerm* m_st, const int ShiftInNodeVector) **************************************************************************/ void CSourceTerm::SetNOD() { + std::vector nod_vector; + std::vector nod_vector_cond; + std::vector nod_val_vector; + int ShiftInNodeVector; - std::vector nod_vector; - std::vector nod_vector_cond; - std::vector nod_val_vector; - int ShiftInNodeVector; + nod_vector.push_back(msh_node_number); + nod_vector_cond.push_back(msh_node_number); + nod_val_vector.push_back(geo_node_value); - nod_vector.push_back(msh_node_number); - nod_vector_cond.push_back(msh_node_number); - nod_val_vector.push_back(geo_node_value); - - /*nod_vector[0] = msh_node_number; - nod_vector_cond[0] = msh_node_number; - nod_val_vector[0] =geo_node_value;*/ - ShiftInNodeVector = 0; - - SetNodeValues(nod_vector, nod_vector_cond, nod_val_vector, - ShiftInNodeVector); + /*nod_vector[0] = msh_node_number; + nod_vector_cond[0] = msh_node_number; + nod_val_vector[0] =geo_node_value;*/ + ShiftInNodeVector = 0; + SetNodeValues(nod_vector, nod_vector_cond, nod_val_vector, ShiftInNodeVector); } - /************************************************************************** MSHLib-Method: Task: @@ -3457,8 +3387,8 @@ void CSourceTerm::SetNOD() 11/2007 JOD last modification: **************************************************************************/ -//void CSourceTermGroup::SetPolylineNodeVector(CGLPolyline* m_ply, -//std::vector&ply_nod_vector) +// void CSourceTermGroup::SetPolylineNodeVector(CGLPolyline* m_ply, +// std::vector&ply_nod_vector) //{ // if (m_ply->getType() == 100) // WW // m_msh->GetNodesOnArc(m_ply, ply_nod_vector); @@ -3468,7 +3398,6 @@ void CSourceTerm::SetNOD() // m_msh->GetNODOnPLY(m_ply, ply_nod_vector); //} - /************************************************************************** MSHLib-Method: Task: @@ -3476,18 +3405,16 @@ void CSourceTerm::SetNOD() 11/2007 JOD last modification: **************************************************************************/ -void CSourceTermGroup::SetSurfaceNodeVector(Surface* m_sfc, - std::vector&sfc_nod_vector) +void CSourceTermGroup::SetSurfaceNodeVector(Surface* m_sfc, std::vector& sfc_nod_vector) { - const bool for_source = true; - m_msh->GetNODOnSFC(m_sfc, sfc_nod_vector, for_source); + const bool for_source = true; + m_msh->GetNODOnSFC(m_sfc, sfc_nod_vector, for_source); } -void CSourceTermGroup::SetSurfaceNodeVector(GEOLIB::Surface const* sfc, - std::vector & sfc_nod_vector) +void CSourceTermGroup::SetSurfaceNodeVector(GEOLIB::Surface const* sfc, std::vector& sfc_nod_vector) { - const bool for_source = true; - m_msh->GetNODOnSFC(sfc, sfc_nod_vector, for_source); + const bool for_source = true; + m_msh->GetNODOnSFC(sfc, sfc_nod_vector, for_source); } /************************************************************************** @@ -3498,97 +3425,98 @@ void CSourceTermGroup::SetSurfaceNodeVector(GEOLIB::Surface const* sfc, 12/2012 JOD Extension to TWO_PHASE_FLOW 5.3.07 last modification: **************************************************************************/ -void CSourceTermGroup::SetPolylineNodeVectorConditional(CSourceTerm* st, - std::vector& ply_nod_vector, std::vector& ply_nod_vector_cond) -{ - size_t assembled_mesh_node, number_of_nodes; - - if (st->node_averaging) - { - if (m_msh_cond) - { - if (pcs_type_name == "RICHARDS_FLOW" || pcs_type_name == "MULTI_PHASE_FLOW") - { - // m_msh_cond->GetNODOnPLY(m_ply, ply_nod_vector_cond); - m_msh_cond->GetNODOnPLY(static_cast(st->getGeoObj()), ply_nod_vector_cond); - number_of_nodes = ply_nod_vector_cond.size(); - assembled_mesh_node = 0;// ply_nod_vector[0]; // JOD carefull !!! ply sometimes fails - ply_nod_vector.resize(number_of_nodes); - for (size_t i = 0; i < number_of_nodes; i++) - ply_nod_vector[i] = assembled_mesh_node; - } // end richards / multi_phase - else if (pcs_type_name == "OVERLAND_FLOW" || pcs_type_name == "GROUNDWATER_FLOW") // JOD 4.10.01 - { - number_of_nodes = ply_nod_vector.size(); - // m_msh_cond->GetNODOnPLY(m_ply, ply_nod_vector_cond); - m_msh_cond->GetNODOnPLY(static_cast(st->getGeoObj()), ply_nod_vector_cond); - assembled_mesh_node = 0; // ply_nod_vector_cond[0]; // JOD carefull !!! ply sometimes fails - ply_nod_vector_cond.resize(number_of_nodes); - for (size_t i = 0; i < number_of_nodes; i++) - ply_nod_vector_cond[i] = assembled_mesh_node; - } // end overland, groundwater - else - std::cout - << "Warning in CSourceTermGroup::SetPolylineNodeVectorConditional - no area assembly for this process" - << "\n"; - } // end mesh_cond - else - std::cout << "Warning in CSourceTermGroup::SetPLY - no MSH_COND data" - << "\n"; - } // end area_assembly - else - { - number_of_nodes = ply_nod_vector.size(); - ply_nod_vector_cond.resize(number_of_nodes); - st->SetNOD2MSHNOD(ply_nod_vector, ply_nod_vector_cond); - } // end !area_assembly -} - -/* -// 09/2010 TF -void CSourceTermGroup::SetPolylineNodeVectorConditional(CSourceTerm* st, - std::vector& ply_nod_vector, - std::vector& ply_nod_vector_cond) +void CSourceTermGroup::SetPolylineNodeVectorConditional(CSourceTerm* st, std::vector& ply_nod_vector, + std::vector& ply_nod_vector_cond) { size_t assembled_mesh_node, number_of_nodes; - if (st->node_averaging) { - if (m_msh_cond) { - if (pcs_type_name == "RICHARDS_FLOW") { - m_msh_cond->GetNODOnPLY( - static_cast (st->getGeoObj()), - ply_nod_vector_cond); + if (st->node_averaging) + { + if (m_msh_cond) + { + if (pcs_type_name == "RICHARDS_FLOW" || pcs_type_name == "MULTI_PHASE_FLOW") + { + // m_msh_cond->GetNODOnPLY(m_ply, ply_nod_vector_cond); + m_msh_cond->GetNODOnPLY(static_cast(st->getGeoObj()), ply_nod_vector_cond); number_of_nodes = ply_nod_vector_cond.size(); - assembled_mesh_node = ply_nod_vector[0]; + assembled_mesh_node = 0; // ply_nod_vector[0]; // JOD carefull !!! ply sometimes fails ply_nod_vector.resize(number_of_nodes); for (size_t i = 0; i < number_of_nodes; i++) ply_nod_vector[i] = assembled_mesh_node; - } // end richards - else if (pcs_type_name == "OVERLAND_FLOW" - // JOD 4.10.01 - || pcs_type_name == "GROUNDWATER_FLOW") { + } // end richards / multi_phase + else if (pcs_type_name == "OVERLAND_FLOW" || pcs_type_name == "GROUNDWATER_FLOW") // JOD 4.10.01 + { number_of_nodes = ply_nod_vector.size(); - m_msh_cond->GetNODOnPLY( - static_cast (st->getGeoObj()), - ply_nod_vector_cond); - assembled_mesh_node = ply_nod_vector_cond[0]; + // m_msh_cond->GetNODOnPLY(m_ply, ply_nod_vector_cond); + m_msh_cond->GetNODOnPLY(static_cast(st->getGeoObj()), ply_nod_vector_cond); + assembled_mesh_node = 0; // ply_nod_vector_cond[0]; // JOD carefull !!! ply sometimes fails ply_nod_vector_cond.resize(number_of_nodes); for (size_t i = 0; i < number_of_nodes; i++) ply_nod_vector_cond[i] = assembled_mesh_node; } // end overland, groundwater - else std::cout - << "Warning in CSourceTermGroup::SetPolylineNodeVectorConditional - no area assembly for this process" - << "\n"; + else + std::cout << "Warning in CSourceTermGroup::SetPolylineNodeVectorConditional - no area assembly for " + "this process" + << "\n"; } // end mesh_cond - else std::cout - << "Warning in CSourceTermGroup::SetPLY - no MSH_COND data" - << "\n"; + else + std::cout << "Warning in CSourceTermGroup::SetPLY - no MSH_COND data" + << "\n"; } // end area_assembly - else { + else + { number_of_nodes = ply_nod_vector.size(); ply_nod_vector_cond.resize(number_of_nodes); st->SetNOD2MSHNOD(ply_nod_vector, ply_nod_vector_cond); } // end !area_assembly +} + +/* +// 09/2010 TF +void CSourceTermGroup::SetPolylineNodeVectorConditional(CSourceTerm* st, + std::vector& ply_nod_vector, + std::vector& ply_nod_vector_cond) +{ + size_t assembled_mesh_node, number_of_nodes; + + if (st->node_averaging) { + if (m_msh_cond) { + if (pcs_type_name == "RICHARDS_FLOW") { + m_msh_cond->GetNODOnPLY( + static_cast (st->getGeoObj()), + ply_nod_vector_cond); + number_of_nodes = ply_nod_vector_cond.size(); + assembled_mesh_node = ply_nod_vector[0]; + ply_nod_vector.resize(number_of_nodes); + for (size_t i = 0; i < number_of_nodes; i++) + ply_nod_vector[i] = assembled_mesh_node; + } // end richards + else if (pcs_type_name == "OVERLAND_FLOW" + // JOD 4.10.01 + || pcs_type_name == "GROUNDWATER_FLOW") { + number_of_nodes = ply_nod_vector.size(); + m_msh_cond->GetNODOnPLY( + static_cast (st->getGeoObj()), + ply_nod_vector_cond); + assembled_mesh_node = ply_nod_vector_cond[0]; + ply_nod_vector_cond.resize(number_of_nodes); + for (size_t i = 0; i < number_of_nodes; i++) + ply_nod_vector_cond[i] = assembled_mesh_node; + } // end overland, groundwater + else std::cout + << "Warning in CSourceTermGroup::SetPolylineNodeVectorConditional - no area assembly for this +process" + << "\n"; + } // end mesh_cond + else std::cout + << "Warning in CSourceTermGroup::SetPLY - no MSH_COND data" + << "\n"; + } // end area_assembly + else { + number_of_nodes = ply_nod_vector.size(); + ply_nod_vector_cond.resize(number_of_nodes); + st->SetNOD2MSHNOD(ply_nod_vector, ply_nod_vector_cond); + } // end !area_assembly }*/ /************************************************************************** @@ -3598,12 +3526,15 @@ void CSourceTermGroup::SetPolylineNodeVectorConditional(CSourceTerm* st, 11/2007 JOD last modification: **************************************************************************/ -void CSourceTerm::InterpolatePolylineNodeValueVector(CGLPolyline* m_ply, - std::vector& Distribed, std::vector& ply_nod_vector) +void CSourceTerm::InterpolatePolylineNodeValueVector(CGLPolyline* m_ply, std::vector& Distribed, + std::vector& ply_nod_vector) { - for (long k = 0; k < (long) DistribedBC.size(); k++) { - for (long l = 0; l < (long) m_ply->point_vector.size(); l++) { - if (PointsHaveDistribedBC[k] == m_ply->point_vector[l]->id) { + for (long k = 0; k < (long)DistribedBC.size(); k++) + { + for (long l = 0; l < (long)m_ply->point_vector.size(); l++) + { + if (PointsHaveDistribedBC[k] == m_ply->point_vector[l]->id) + { if (fabs(DistribedBC[k]) < MKleinsteZahl) DistribedBC[k] = 1.0e-20; m_ply->point_vector[l]->setPropert(Distribed[k]); @@ -3615,29 +3546,32 @@ void CSourceTerm::InterpolatePolylineNodeValueVector(CGLPolyline* m_ply, InterpolationAlongPolyline(m_ply, ply_nod_vector); } -void CSourceTerm::InterpolatePolylineNodeValueVector( - std::vector const & nodes_as_interpol_points, - std::vector& node_values) const +void CSourceTerm::InterpolatePolylineNodeValueVector(std::vector const& nodes_as_interpol_points, + std::vector& node_values) const { std::vector interpolation_points; std::vector interpolation_values; - GEOLIB::Polyline const * ply (dynamic_cast(this->getGeoObj())); + GEOLIB::Polyline const* ply(dynamic_cast(this->getGeoObj())); - for (size_t i(0); i < DistribedBC.size(); i++) { - for (size_t j = 0; j < ply->getNumberOfPoints(); j++) { - if ((size_t)(PointsHaveDistribedBC[i]) == ply->getPointID(j)) { - interpolation_points.push_back (ply->getLength(j)); + for (size_t i(0); i < DistribedBC.size(); i++) + { + for (size_t j = 0; j < ply->getNumberOfPoints(); j++) + { + if ((size_t)(PointsHaveDistribedBC[i]) == ply->getPointID(j)) + { + interpolation_points.push_back(ply->getLength(j)); if (fabs(DistribedBC[i]) < MKleinsteZahl) - interpolation_values.push_back (1.0e-20); + interpolation_values.push_back(1.0e-20); else - interpolation_values.push_back (DistribedBC[i]); + interpolation_values.push_back(DistribedBC[i]); break; } } } - MathLib::PiecewiseLinearInterpolation (interpolation_points, interpolation_values, nodes_as_interpol_points, node_values); + MathLib::PiecewiseLinearInterpolation(interpolation_points, interpolation_values, nodes_as_interpol_points, + node_values); } /************************************************************************** @@ -3648,72 +3582,73 @@ void CSourceTerm::InterpolatePolylineNodeValueVector( last modification: **************************************************************************/ /*void CSourceTermGroup::SetPolylineNodeValueVector(CSourceTerm* st, CGLPolyline * old_ply, - const std::vector& ply_nod_vector, - std::vector& ply_nod_vector_cond, - std::vector& ply_nod_val_vector) + const std::vector& ply_nod_vector, + std::vector& ply_nod_vector_cond, + std::vector& ply_nod_val_vector) { - long number_of_nodes = (long) ply_nod_vector.size(); - ply_nod_val_vector.resize(number_of_nodes); - - if (st->getProcessDistributionType() == FiniteElement::LINEAR - || st->getProcessDistributionType() == FiniteElement::LINEAR_NEUMANN) { - st->InterpolatePolylineNodeValueVector(old_ply, st->DistribedBC, ply_nod_val_vector); - } else if (st->getProcessDistributionType() == FiniteElement::SYSTEM_DEPENDENT) { - CRFProcess* m_pcs = NULL; - m_pcs = PCSGet(pcs_type_name); - m_pcs->compute_domain_face_normal = true; //WW - long no_face = (long) m_msh->face_vector.size(); - for (long i = 0; i < no_face; i++) { - int node_on_line = 0; - int no_vertex = m_msh->face_vector[i]->GetVertexNumber(); - for (long jj = 0; jj < no_vertex; jj++) { - for (long kk = 0; kk < number_of_nodes; kk++) { - if (ply_nod_vector[kk] - == m_msh->face_vector[i]->GetNodeIndex(jj)) node_on_line++; - } // end nodes - } // end vertices - if (node_on_line == 2) st->element_st_vector.push_back( - m_msh->face_vector[i]->GetOwner()->GetIndex()); - } // end faces - } // end system dependent - else //WW - { - for (long i = 0; i < number_of_nodes; i++) { - ply_nod_val_vector[i] = st->geo_node_value; - // if (st->dis_type == 12) - if (st->getProcessDistributionType() == FiniteElement::CONSTANT_GEO) - ply_nod_val_vector[i] = st->geo_node_value / (double) number_of_nodes; // distribute flow to nodes along polyline. To do.. 4.10.06 - } - } - - if (st->getProcessDistributionType() == FiniteElement::CONSTANT_NEUMANN - || st->getProcessDistributionType() - == FiniteElement::LINEAR_NEUMANN - || st->getProcessDistributionType() == FiniteElement::GREEN_AMPT) { - if (m_msh->GetMaxElementDim() == 1) // 1D //WW MB - st->DomainIntegration(m_msh, ply_nod_vector, ply_nod_val_vector); - else st->EdgeIntegration(m_msh, ply_nod_vector, ply_nod_val_vector); - } - - if ( st->getProcessDistributionType() == FiniteElement::CRITICALDEPTH - || st->getProcessDistributionType() == FiniteElement::NORMALDEPTH - || st->getProcessDistributionType() == FiniteElement::ANALYTICAL) { - st->node_value_vectorArea.resize(number_of_nodes); - for (long i = 0; i < number_of_nodes; i++) - st->node_value_vectorArea[i] = 1.0; //Element width ! - st->EdgeIntegration(m_msh, ply_nod_vector, st->node_value_vectorArea); - } - - if (st->isCoupled() && st->node_averaging) - AreaAssembly(st, ply_nod_vector_cond, ply_nod_val_vector); + long number_of_nodes = (long) ply_nod_vector.size(); + ply_nod_val_vector.resize(number_of_nodes); + + if (st->getProcessDistributionType() == FiniteElement::LINEAR + || st->getProcessDistributionType() == FiniteElement::LINEAR_NEUMANN) { + st->InterpolatePolylineNodeValueVector(old_ply, st->DistribedBC, ply_nod_val_vector); + } else if (st->getProcessDistributionType() == FiniteElement::SYSTEM_DEPENDENT) { + CRFProcess* m_pcs = NULL; + m_pcs = PCSGet(pcs_type_name); + m_pcs->compute_domain_face_normal = true; //WW + long no_face = (long) m_msh->face_vector.size(); + for (long i = 0; i < no_face; i++) { + int node_on_line = 0; + int no_vertex = m_msh->face_vector[i]->GetVertexNumber(); + for (long jj = 0; jj < no_vertex; jj++) { + for (long kk = 0; kk < number_of_nodes; kk++) { + if (ply_nod_vector[kk] + == m_msh->face_vector[i]->GetNodeIndex(jj)) node_on_line++; + } // end nodes + } // end vertices + if (node_on_line == 2) st->element_st_vector.push_back( + m_msh->face_vector[i]->GetOwner()->GetIndex()); + } // end faces + } // end system dependent + else //WW + { + for (long i = 0; i < number_of_nodes; i++) { + ply_nod_val_vector[i] = st->geo_node_value; + // if (st->dis_type == 12) + if (st->getProcessDistributionType() == FiniteElement::CONSTANT_GEO) + ply_nod_val_vector[i] = st->geo_node_value / (double) number_of_nodes; // distribute flow to nodes along +polyline. To do.. 4.10.06 + } + } + + if (st->getProcessDistributionType() == FiniteElement::CONSTANT_NEUMANN + || st->getProcessDistributionType() + == FiniteElement::LINEAR_NEUMANN + || st->getProcessDistributionType() == FiniteElement::GREEN_AMPT) { + if (m_msh->GetMaxElementDim() == 1) // 1D //WW MB + st->DomainIntegration(m_msh, ply_nod_vector, ply_nod_val_vector); + else st->EdgeIntegration(m_msh, ply_nod_vector, ply_nod_val_vector); + } + + if ( st->getProcessDistributionType() == FiniteElement::CRITICALDEPTH + || st->getProcessDistributionType() == FiniteElement::NORMALDEPTH + || st->getProcessDistributionType() == FiniteElement::ANALYTICAL) { + st->node_value_vectorArea.resize(number_of_nodes); + for (long i = 0; i < number_of_nodes; i++) + st->node_value_vectorArea[i] = 1.0; //Element width ! + st->EdgeIntegration(m_msh, ply_nod_vector, st->node_value_vectorArea); + } + + if (st->isCoupled() && st->node_averaging) + AreaAssembly(st, ply_nod_vector_cond, ply_nod_val_vector); } */ // 09/2010 TF void CSourceTermGroup::SetPolylineNodeValueVector(CSourceTerm* st, - std::vector const & ply_nod_vector, - std::vector const & ply_nod_vector_cond, - std::vector& ply_nod_val_vector) const + std::vector const& ply_nod_vector, + std::vector const& ply_nod_vector_cond, + std::vector& ply_nod_val_vector) const { size_t number_of_nodes(ply_nod_vector.size()); ply_nod_val_vector.resize(number_of_nodes); @@ -3721,84 +3656,90 @@ void CSourceTermGroup::SetPolylineNodeValueVector(CSourceTerm* st, FiniteElement::DistributionType distype(st->getProcessDistributionType()); // linear - if (distype == FiniteElement::LINEAR || distype == FiniteElement::LINEAR_NEUMANN) { + if (distype == FiniteElement::LINEAR || distype == FiniteElement::LINEAR_NEUMANN) + { // fetch data for the linear interpolation - GEOLIB::Polyline const* polyline (dynamic_cast(st->getGeoObj())); - if (polyline) { + GEOLIB::Polyline const* polyline(dynamic_cast(st->getGeoObj())); + if (polyline) + { std::vector nodes_as_interpol_points; - m_msh->getPointsForInterpolationAlongPolyline (polyline, nodes_as_interpol_points); + m_msh->getPointsForInterpolationAlongPolyline(polyline, nodes_as_interpol_points); st->InterpolatePolylineNodeValueVector(nodes_as_interpol_points, ply_nod_val_vector); } - } else if (distype == FiniteElement::SYSTEM_DEPENDENT) { //System Dependented YD + } + else if (distype == FiniteElement::SYSTEM_DEPENDENT) + { // System Dependented YD CRFProcess* m_pcs(PCSGet(pcs_type_name)); - m_pcs->compute_domain_face_normal = true; //WW - long no_face = (long) m_msh->face_vector.size(); - for (long i = 0; i < no_face; i++) { + m_pcs->compute_domain_face_normal = true; // WW + long no_face = (long)m_msh->face_vector.size(); + for (long i = 0; i < no_face; i++) + { int node_on_line = 0; int no_vertex = m_msh->face_vector[i]->GetVertexNumber(); - for (long jj = 0; jj < no_vertex; jj++) { - for (size_t kk = 0; kk < number_of_nodes; kk++) { + for (long jj = 0; jj < no_vertex; jj++) + { + for (size_t kk = 0; kk < number_of_nodes; kk++) + { if (ply_nod_vector[kk] == (m_msh->face_vector[i]->GetNodeIndex(jj))) node_on_line++; } // end nodes } // end vertices - if (node_on_line == 2) st->element_st_vector.push_back( - m_msh->face_vector[i]->GetOwner()->GetIndex()); + if (node_on_line == 2) + st->element_st_vector.push_back(m_msh->face_vector[i]->GetOwner()->GetIndex()); } // end faces } // end system dependent - else if (distype == FiniteElement::FUNCTION) // 25.08.2011. WW - { - for (size_t i = 0; i < number_of_nodes; i++) - { - double const*const pnt (m_msh->nod_vector[ply_nod_vector[i]]->getData()); - ply_nod_val_vector[i] = st->dis_linear_f->getValue(pnt[0], pnt[1], pnt[2]); - } - } - else //WW + else if (distype == FiniteElement::FUNCTION) // 25.08.2011. WW + { + for (size_t i = 0; i < number_of_nodes; i++) + { + double const* const pnt(m_msh->nod_vector[ply_nod_vector[i]]->getData()); + ply_nod_val_vector[i] = st->dis_linear_f->getValue(pnt[0], pnt[1], pnt[2]); + } + } + else // WW { - for (size_t i = 0; i < number_of_nodes; i++) { + for (size_t i = 0; i < number_of_nodes; i++) + { ply_nod_val_vector[i] = st->geo_node_value; if (st->getProcessDistributionType() == FiniteElement::CONSTANT_GEO) - ply_nod_val_vector[i] = st->geo_node_value / (double) number_of_nodes; + ply_nod_val_vector[i] = st->geo_node_value / (double)number_of_nodes; } } - if (distype == FiniteElement::CONSTANT_NEUMANN - || distype == FiniteElement::LINEAR_NEUMANN - || distype == FiniteElement::GREEN_AMPT - || distype==FiniteElement::RECHARGE) //MW + if (distype == FiniteElement::CONSTANT_NEUMANN || distype == FiniteElement::LINEAR_NEUMANN + || distype == FiniteElement::GREEN_AMPT + || distype == FiniteElement::RECHARGE) // MW { if (m_msh->GetMaxElementDim() == 1) // 1D //WW MB - st->DomainIntegration(m_msh, ply_nod_vector, - ply_nod_val_vector); - else st->EdgeIntegration(m_msh, ply_nod_vector, ply_nod_val_vector); + st->DomainIntegration(m_msh, ply_nod_vector, ply_nod_val_vector); + else + st->EdgeIntegration(m_msh, ply_nod_vector, ply_nod_val_vector); } - if (distype == FiniteElement::CRITICALDEPTH - || distype == FiniteElement::NORMALDEPTH - || distype == FiniteElement::ANALYTICAL) { + if (distype == FiniteElement::CRITICALDEPTH || distype == FiniteElement::NORMALDEPTH + || distype == FiniteElement::ANALYTICAL) + { st->node_value_vectorArea.resize(number_of_nodes); for (size_t i = 0; i < number_of_nodes; i++) - st->node_value_vectorArea[i] = 1.0; //Element width ! - st->EdgeIntegration(m_msh, ply_nod_vector, - st->node_value_vectorArea); + st->node_value_vectorArea[i] = 1.0; // Element width ! + st->EdgeIntegration(m_msh, ply_nod_vector, st->node_value_vectorArea); } - if (distype == FiniteElement::TRANSFER_SURROUNDING) { //TN - Belegung mit Fl�chenelementen + if (distype == FiniteElement::TRANSFER_SURROUNDING) + { // TN - Belegung mit Fl�chenelementen st->node_value_vectorArea.resize(number_of_nodes); - for (size_t i = 0; i < number_of_nodes; i++){ + for (size_t i = 0; i < number_of_nodes; i++) + { st->node_value_vectorArea[i] = 1.0; ply_nod_val_vector[i] = 0.0; } if (m_msh->GetMaxElementDim() == 1) // 1D //WW MB - st->DomainIntegration(m_msh, ply_nod_vector, - st->node_value_vectorArea); + st->DomainIntegration(m_msh, ply_nod_vector, st->node_value_vectorArea); else st->EdgeIntegration(m_msh, ply_nod_vector, st->node_value_vectorArea); - - //CNode * a_node; //Fl�che wird hier im Knoten als patch area abgelegt - //for (size_t i = 0; i < number_of_nodes; i++) + // CNode * a_node; //Fl�che wird hier im Knoten als patch area abgelegt + // for (size_t i = 0; i < number_of_nodes; i++) //{ // a_node = m_msh->nod_vector[ply_nod_vector[i]]; // a_node->patch_area = st->node_value_vectorArea[i]; @@ -3808,16 +3749,15 @@ void CSourceTermGroup::SetPolylineNodeValueVector(CSourceTerm* st, if (st->isCoupled() && st->node_averaging) AreaAssembly(st, ply_nod_vector_cond, ply_nod_val_vector); - if (distype==FiniteElement::RECHARGE) //MW + if (distype == FiniteElement::RECHARGE) // MW { CRFProcess* m_pcs = PCSGet(pcs_type_name); MshEditor::sortNodesLexicographically(m_pcs->m_msh); - st->setProcessDistributionType (st->getProcessDistributionType()); + st->setProcessDistributionType(st->getProcessDistributionType()); } } - /************************************************************************** MSHLib-Method: Task: @@ -3827,26 +3767,23 @@ void CSourceTermGroup::SetPolylineNodeValueVector(CSourceTerm* st, last modification: **************************************************************************/ void CSourceTermGroup::AreaAssembly(const CSourceTerm* const st, -const std::vector& ply_nod_vector_cond, -std::vector& ply_nod_val_vector) const + const std::vector& ply_nod_vector_cond, + std::vector& ply_nod_val_vector) const { - if (pcs_type_name == "RICHARDS_FLOW" || pcs_type_name == "MULTI_PHASE_FLOW") - { - if (m_msh_cond->GetMaxElementDim() == 1) // 1D //WW MB - st->DomainIntegration(m_msh_cond, ply_nod_vector_cond, - ply_nod_val_vector); - else - st->EdgeIntegration(m_msh_cond, ply_nod_vector_cond, - ply_nod_val_vector); - double sum_node_value = 0; - for (size_t i = 0; i < ply_nod_val_vector.size(); i++) - sum_node_value += ply_nod_val_vector[i]; - for (size_t i = 0; i < ply_nod_val_vector.size(); i++) - ply_nod_val_vector[i] /= sum_node_value; - } + if (pcs_type_name == "RICHARDS_FLOW" || pcs_type_name == "MULTI_PHASE_FLOW") + { + if (m_msh_cond->GetMaxElementDim() == 1) // 1D //WW MB + st->DomainIntegration(m_msh_cond, ply_nod_vector_cond, ply_nod_val_vector); + else + st->EdgeIntegration(m_msh_cond, ply_nod_vector_cond, ply_nod_val_vector); + double sum_node_value = 0; + for (size_t i = 0; i < ply_nod_val_vector.size(); i++) + sum_node_value += ply_nod_val_vector[i]; + for (size_t i = 0; i < ply_nod_val_vector.size(); i++) + ply_nod_val_vector[i] /= sum_node_value; + } } - /************************************************************************** MSHLib-Method: Task: @@ -3854,79 +3791,77 @@ std::vector& ply_nod_val_vector) const 11/2007 JOD last modification: **************************************************************************/ -void CSourceTermGroup::SetSurfaceNodeValueVector(CSourceTerm* st, - Surface* m_sfc, std::vector const &sfc_nod_vector, - std::vector&sfc_nod_val_vector) +void CSourceTermGroup::SetSurfaceNodeValueVector(CSourceTerm* st, Surface* m_sfc, + std::vector const& sfc_nod_vector, + std::vector& sfc_nod_val_vector) { - // CRFProcess* m_pcs = NULL; - // m_pcs = PCSGet(pcs_type_name); - long number_of_nodes = (long) sfc_nod_vector.size(); - sfc_nod_val_vector.resize(number_of_nodes); - - for (long i = 0; i < number_of_nodes; i++) - sfc_nod_val_vector[i] = st->geo_node_value; - // KR & TF - case not used - // if (m_st->dis_type == 12) //To do. 4.10.06 - // for (long i = 0; i < number_of_nodes; i++) - // sfc_nod_val_vector[i] = m_st->geo_node_value - // / (double) number_of_nodes; - - // if (st->dis_type == 2 || st->dis_type == 4) { // Piecewise linear distributed, polygon-wise WW - if (st->getProcessDistributionType() == FiniteElement::LINEAR || st->getProcessDistributionType() == FiniteElement::LINEAR_NEUMANN) - { - CGLPolyline* m_ply = NULL; - std::vector::iterator p = - m_sfc->polyline_of_surface_vector.begin(); - p = m_sfc->polyline_of_surface_vector.begin(); - while (p != m_sfc->polyline_of_surface_vector.end()) - { - m_ply = *p; - long nPointsPly = (long) m_ply->point_vector.size(); - if (m_ply->point_vector.front() == m_ply->point_vector.back()) - nPointsPly -= 1; - - for (long k = 0; k < (long) st->DistribedBC.size(); k++) - { - for (long l = 0; l < nPointsPly; l++) - { - if (st->PointsHaveDistribedBC[k] - == m_ply->point_vector[l]->id) - { - if (fabs(st->DistribedBC[k]) < MKleinsteZahl) - st->DistribedBC[k] = 1.0e-20; - m_ply->point_vector[l]->setPropert (st->DistribedBC[k]); - break; - } // end l - } // end k - } // end polyline - // InterpolationAlongPolyline(m_polyline, node_value_vector); - p++; - } // end while - } // end linear - - // neumann, Green-Ampt, Philip - // if (st->dis_type == 3 || st->dis_type == 4 || st->dis_type == 10 - // || st->dis_type == 11) { - /*|| st->getProcessDistributionType() == PHILIP */ - if (st->getProcessDistributionType() == FiniteElement::CONSTANT_NEUMANN - || st->getProcessDistributionType() == FiniteElement::LINEAR_NEUMANN - || st->getProcessDistributionType() == FiniteElement::GREEN_AMPT - || st->getProcessDistributionType() == FiniteElement::RECHARGE) - { - if (m_msh->GetMaxElementDim() == 2) // For all meshes with 1-D or 2-D elements - st->DomainIntegration(m_msh, sfc_nod_vector, sfc_nod_val_vector); - else if (m_msh->GetMaxElementDim() == 3) // For all meshes with 3-D elements - st->FaceIntegration(m_msh, sfc_nod_vector, sfc_nod_val_vector); - } // end neumann - else if (st->getProcessDistributionType() == FiniteElement::FUNCTION) // 25.08.2011. WW - { - for (size_t j = 0; j < sfc_nod_vector.size(); j++) - { - double const*const pnt (m_msh->nod_vector[sfc_nod_vector[j]]->getData()); - sfc_nod_val_vector[j] = st->dis_linear_f->getValue(pnt[0], pnt[1], pnt[2]); - } - } + // CRFProcess* m_pcs = NULL; + // m_pcs = PCSGet(pcs_type_name); + long number_of_nodes = (long)sfc_nod_vector.size(); + sfc_nod_val_vector.resize(number_of_nodes); + + for (long i = 0; i < number_of_nodes; i++) + sfc_nod_val_vector[i] = st->geo_node_value; + // KR & TF - case not used + // if (m_st->dis_type == 12) //To do. 4.10.06 + // for (long i = 0; i < number_of_nodes; i++) + // sfc_nod_val_vector[i] = m_st->geo_node_value + // / (double) number_of_nodes; + + // if (st->dis_type == 2 || st->dis_type == 4) { // Piecewise linear distributed, polygon-wise WW + if (st->getProcessDistributionType() == FiniteElement::LINEAR + || st->getProcessDistributionType() == FiniteElement::LINEAR_NEUMANN) + { + CGLPolyline* m_ply = NULL; + std::vector::iterator p = m_sfc->polyline_of_surface_vector.begin(); + p = m_sfc->polyline_of_surface_vector.begin(); + while (p != m_sfc->polyline_of_surface_vector.end()) + { + m_ply = *p; + long nPointsPly = (long)m_ply->point_vector.size(); + if (m_ply->point_vector.front() == m_ply->point_vector.back()) + nPointsPly -= 1; + for (long k = 0; k < (long)st->DistribedBC.size(); k++) + { + for (long l = 0; l < nPointsPly; l++) + { + if (st->PointsHaveDistribedBC[k] == m_ply->point_vector[l]->id) + { + if (fabs(st->DistribedBC[k]) < MKleinsteZahl) + st->DistribedBC[k] = 1.0e-20; + m_ply->point_vector[l]->setPropert(st->DistribedBC[k]); + break; + } // end l + } // end k + } // end polyline + // InterpolationAlongPolyline(m_polyline, node_value_vector); + p++; + } // end while + } // end linear + + // neumann, Green-Ampt, Philip + // if (st->dis_type == 3 || st->dis_type == 4 || st->dis_type == 10 + // || st->dis_type == 11) { + /*|| st->getProcessDistributionType() == PHILIP */ + if (st->getProcessDistributionType() == FiniteElement::CONSTANT_NEUMANN + || st->getProcessDistributionType() == FiniteElement::LINEAR_NEUMANN + || st->getProcessDistributionType() == FiniteElement::GREEN_AMPT + || st->getProcessDistributionType() == FiniteElement::RECHARGE) + { + if (m_msh->GetMaxElementDim() == 2) // For all meshes with 1-D or 2-D elements + st->DomainIntegration(m_msh, sfc_nod_vector, sfc_nod_val_vector); + else if (m_msh->GetMaxElementDim() == 3) // For all meshes with 3-D elements + st->FaceIntegration(m_msh, sfc_nod_vector, sfc_nod_val_vector); + } // end neumann + else if (st->getProcessDistributionType() == FiniteElement::FUNCTION) // 25.08.2011. WW + { + for (size_t j = 0; j < sfc_nod_vector.size(); j++) + { + double const* const pnt(m_msh->nod_vector[sfc_nod_vector[j]]->getData()); + sfc_nod_val_vector[j] = st->dis_linear_f->getValue(pnt[0], pnt[1], pnt[2]); + } + } } /************************************************************************** @@ -3934,39 +3869,39 @@ void CSourceTermGroup::SetSurfaceNodeValueVector(CSourceTerm* st, use GEO_TYPE CONSTANT_NEUMANN 12/2012 5.3.07 JOD Implementation **************************************************************************/ -void CSourceTermGroup::DistributeVolumeFlux(CSourceTerm* st, std::vector const & nod_vector, - std::vector& nod_val_vector) +void CSourceTermGroup::DistributeVolumeFlux(CSourceTerm* st, std::vector const& nod_vector, + std::vector& nod_val_vector) { - double area; - std::vector nod_val_vector_area; + std::vector nod_val_vector_area; area = 0; - st->geo_node_value = 1; + st->geo_node_value = 1; - if(st->getGeoType () == GEOLIB::POLYLINE) - SetPolylineNodeValueVector(st, nod_vector, nod_vector, nod_val_vector_area); - else if(st->getGeoType () == GEOLIB::SURFACE) + if (st->getGeoType() == GEOLIB::POLYLINE) + SetPolylineNodeValueVector(st, nod_vector, nod_vector, nod_val_vector_area); + else if (st->getGeoType() == GEOLIB::SURFACE) { - Surface* m_sfc = NULL; - m_sfc = GEOGetSFCByName(st->geo_name); - SetSurfaceNodeValueVector(st, m_sfc, nod_vector, nod_val_vector_area); + Surface* m_sfc = NULL; + m_sfc = GEOGetSFCByName(st->geo_name); + SetSurfaceNodeValueVector(st, m_sfc, nod_vector, nod_val_vector_area); } else - std::cout << "GEO_TYPE not supported in CSourceTermGroup::DistributeVolumeFlux()" << "\n"; + std::cout << "GEO_TYPE not supported in CSourceTermGroup::DistributeVolumeFlux()" + << "\n"; - for(int i=0; i<(int)nod_val_vector_area.size();i++) - area +=nod_val_vector_area[i]; - if(area>0) + for (int i = 0; i < (int)nod_val_vector_area.size(); i++) + area += nod_val_vector_area[i]; + if (area > 0) { - for(int i=0; i<(int)nod_val_vector.size();i++) + for (int i = 0; i < (int)nod_val_vector.size(); i++) nod_val_vector[i] /= area; } else { - std::cout << "Using the geometric object " << st->geo_name << " does not find any nearby nodes. No ST applied there!" << std::endl; + std::cout << "Using the geometric object " << st->geo_name + << " does not find any nearby nodes. No ST applied there!" << std::endl; } - } /************************************************************************** @@ -3976,17 +3911,16 @@ void CSourceTermGroup::DistributeVolumeFlux(CSourceTerm* st, std::vector c 11/2007 JOD last modification: **************************************************************************/ -void CSourceTerm::SetSurfaceNodeVectorConditional(std::vector&sfc_nod_vector, -std::vector&sfc_nod_vector_cond) +void CSourceTerm::SetSurfaceNodeVectorConditional(std::vector& sfc_nod_vector, + std::vector& sfc_nod_vector_cond) { - long number_of_nodes; - number_of_nodes = (long) sfc_nod_vector.size(); + long number_of_nodes; + number_of_nodes = (long)sfc_nod_vector.size(); - sfc_nod_vector_cond.resize(number_of_nodes); - SetNOD2MSHNOD(sfc_nod_vector, sfc_nod_vector_cond); + sfc_nod_vector_cond.resize(number_of_nodes); + SetNOD2MSHNOD(sfc_nod_vector, sfc_nod_vector_cond); } - /************************************************************************** MSHLib-Method: Task: @@ -3995,70 +3929,70 @@ std::vector&sfc_nod_vector_cond) last modification: **************************************************************************/ void CSourceTerm::SetNodeValues(const std::vector& nodes, const std::vector& nodes_cond, - const std::vector&node_values, int ShiftInNodeVector) + const std::vector& node_values, int ShiftInNodeVector) { - CNodeValue *m_nod_val = NULL; - size_t number_of_nodes (nodes.size()); - - for (size_t i = 0; i < number_of_nodes; i++) - { - m_nod_val = new CNodeValue(); - m_nod_val->msh_node_number = nodes[i] + ShiftInNodeVector; - m_nod_val->geo_node_number = nodes[i]; - m_nod_val->setProcessDistributionType (getProcessDistributionType()); - m_nod_val->node_value = node_values[i]; - m_nod_val->CurveIndex = CurveIndex; - if (_coupled) // JOD 4.7.10 - { - m_nod_val->msh_node_number_conditional = nodes_cond[i]; - // JOD 4.10.01 - if ((getProcessType() == FiniteElement::OVERLAND_FLOW || getProcessType() == FiniteElement::GROUNDWATER_FLOW) - && node_averaging) - { - double weights = 0; - for (size_t j = 0; j < number_of_nodes; j++) - { - m_nod_val->msh_node_numbers_averaging.push_back(nodes[j]); - m_nod_val->msh_node_weights_averaging.push_back( - node_values[j]); - weights += node_values[j]; - } - for (size_t j = 0; j < number_of_nodes; j++) - m_nod_val->msh_node_weights_averaging[j] /= weights; - } - } - //WW group_vector.push_back(m_node_value); - //WW st_group_vector.push_back(m_st); //OK - // if (getProcessDistributionType() == RIVER) { - // m_nod_val->node_value = node_value_vectorArea[i]; - // m_nod_val->node_parameterA = node_value_vectorA[i]; - // m_nod_val->node_parameterB = node_value_vectorB[i]; - // m_nod_val->node_parameterC = node_value_vectorC[i]; - // m_nod_val->node_parameterD = node_value_vectorD[i]; - // m_nod_val->node_parameterE = node_value_vectorE[i]; - // } - // if (dis_type == 6 || dis_type == 8 || dis_type == 9) // critical depth, normal depth, analytical - if (getProcessDistributionType() == FiniteElement::CRITICALDEPTH - || getProcessDistributionType() == FiniteElement::NORMALDEPTH - || getProcessDistributionType() == FiniteElement::ANALYTICAL) - { - m_nod_val->node_value = node_value_vectorArea[i]; - //CMCD bugfix on 4.9.06 - m_nod_val->node_area = node_value_vectorArea[i]; - } - - m_nod_val->setSTVectorIndex(i); - m_nod_val->setSTVectorGroup(this->getSTVectorGroup()); - if(st_vector[m_nod_val->getSTVectorGroup()]->isConstrainedST()) - st_vector[m_nod_val->getSTVectorGroup()]->setConstrainedSTNodesIndex(m_nod_val->geo_node_number, m_nod_val->getSTVectorIndex()); - _pcs->st_node_value.push_back(m_nod_val); //WW - _pcs->st_node.push_back(this); //WW - } // end nodes -} + CNodeValue* m_nod_val = NULL; + size_t number_of_nodes(nodes.size()); + + for (size_t i = 0; i < number_of_nodes; i++) + { + m_nod_val = new CNodeValue(); + m_nod_val->msh_node_number = nodes[i] + ShiftInNodeVector; + m_nod_val->geo_node_number = nodes[i]; + m_nod_val->setProcessDistributionType(getProcessDistributionType()); + m_nod_val->node_value = node_values[i]; + m_nod_val->CurveIndex = CurveIndex; + if (_coupled) // JOD 4.7.10 + { + m_nod_val->msh_node_number_conditional = nodes_cond[i]; + // JOD 4.10.01 + if ((getProcessType() == FiniteElement::OVERLAND_FLOW + || getProcessType() == FiniteElement::GROUNDWATER_FLOW) + && node_averaging) + { + double weights = 0; + for (size_t j = 0; j < number_of_nodes; j++) + { + m_nod_val->msh_node_numbers_averaging.push_back(nodes[j]); + m_nod_val->msh_node_weights_averaging.push_back(node_values[j]); + weights += node_values[j]; + } + for (size_t j = 0; j < number_of_nodes; j++) + m_nod_val->msh_node_weights_averaging[j] /= weights; + } + } + // WW group_vector.push_back(m_node_value); + // WW st_group_vector.push_back(m_st); //OK + // if (getProcessDistributionType() == RIVER) { + // m_nod_val->node_value = node_value_vectorArea[i]; + // m_nod_val->node_parameterA = node_value_vectorA[i]; + // m_nod_val->node_parameterB = node_value_vectorB[i]; + // m_nod_val->node_parameterC = node_value_vectorC[i]; + // m_nod_val->node_parameterD = node_value_vectorD[i]; + // m_nod_val->node_parameterE = node_value_vectorE[i]; + // } + // if (dis_type == 6 || dis_type == 8 || dis_type == 9) // critical depth, normal depth, analytical + if (getProcessDistributionType() == FiniteElement::CRITICALDEPTH + || getProcessDistributionType() == FiniteElement::NORMALDEPTH + || getProcessDistributionType() == FiniteElement::ANALYTICAL) + { + m_nod_val->node_value = node_value_vectorArea[i]; + // CMCD bugfix on 4.9.06 + m_nod_val->node_area = node_value_vectorArea[i]; + } + m_nod_val->setSTVectorIndex(i); + m_nod_val->setSTVectorGroup(this->getSTVectorGroup()); + if (st_vector[m_nod_val->getSTVectorGroup()]->isConstrainedST()) + st_vector[m_nod_val->getSTVectorGroup()]->setConstrainedSTNodesIndex(m_nod_val->geo_node_number, + m_nod_val->getSTVectorIndex()); + _pcs->st_node_value.push_back(m_nod_val); // WW + _pcs->st_node.push_back(this); // WW + } // end nodes +} // 09/2010 TF -//void CSourceTerm::SetNodeValues(const std::vector& nodes, const std::vector& nodes_cond, +// void CSourceTerm::SetNodeValues(const std::vector& nodes, const std::vector& nodes_cond, // const std::vector& node_values, int ShiftInNodeVector) //{ // size_t number_of_nodes (nodes.size()); @@ -4113,7 +4047,6 @@ void CSourceTerm::SetNodeValues(const std::vector& nodes, const std::vecto // } // end nodes //} - /************************************************************************** MSHLib-Method: Task: @@ -4121,7 +4054,7 @@ void CSourceTerm::SetNodeValues(const std::vector& nodes, const std::vecto 11/2005 MB last modification: **************************************************************************/ -//void CSourceTerm::SetNOD2MSHNOD(vector&nodes, +// void CSourceTerm::SetNOD2MSHNOD(vector&nodes, // vector&conditional_nodes) //{ // CGLPoint* m_pnt = NULL; @@ -4147,118 +4080,119 @@ void CSourceTerm::SetNodeValues(const std::vector& nodes, const std::vecto // //} -void CSourceTerm::SetNOD2MSHNOD(std::vector& nodes, - std::vector& conditional_nodes) +void CSourceTerm::SetNOD2MSHNOD(std::vector& nodes, std::vector& conditional_nodes) { CFEMesh* m_msh_cond(FEMGet(pcs_type_name_cond)); CFEMesh* m_msh_this(FEMGet(convertProcessTypeToString(getProcessType()))); - for (size_t i = 0; i < nodes.size(); i++) { + for (size_t i = 0; i < nodes.size(); i++) + { const GEOLIB::Point pnt(m_msh_this->nod_vector[nodes[i]]->getData()); -// pnt[0] = m_msh_this->nod_vector[nodes[i]]->X(); -// pnt[1] = m_msh_this->nod_vector[nodes[i]]->Y(); -// pnt[2] = m_msh_this->nod_vector[nodes[i]]->Z(); + // pnt[0] = m_msh_this->nod_vector[nodes[i]]->X(); + // pnt[1] = m_msh_this->nod_vector[nodes[i]]->Y(); + // pnt[2] = m_msh_this->nod_vector[nodes[i]]->Z(); conditional_nodes[i] = m_msh_cond->GetNODOnPNT(&pnt); } } - -void CSourceTerm::SetNOD2MSHNOD(const std::vector& nodes, - std::vector& conditional_nodes) const +void CSourceTerm::SetNOD2MSHNOD(const std::vector& nodes, std::vector& conditional_nodes) const { CFEMesh* m_msh_cond(FEMGet(pcs_type_name_cond)); CFEMesh* m_msh_this(FEMGet(convertProcessTypeToString(getProcessType()))); - for (size_t i = 0; i < nodes.size(); i++) { + for (size_t i = 0; i < nodes.size(); i++) + { const GEOLIB::Point pnt(m_msh_this->nod_vector[nodes[i]]->getData()); -// pnt[0] = m_msh_this->nod_vector[nodes[i]]->X(); -// pnt[1] = m_msh_this->nod_vector[nodes[i]]->Y(); -// pnt[2] = m_msh_this->nod_vector[nodes[i]]->Z(); + // pnt[0] = m_msh_this->nod_vector[nodes[i]]->X(); + // pnt[1] = m_msh_this->nod_vector[nodes[i]]->Y(); + // pnt[2] = m_msh_this->nod_vector[nodes[i]]->Z(); conditional_nodes[i] = m_msh_cond->GetNODOnPNT(&pnt); } } - /************************************************************************** GeoSys source term function: 02/2009 WW Implementation **************************************************************************/ void CSourceTerm::DirectAssign(long ShiftInNodeVector) { - CRFProcess* m_pcs = PCSGet(convertProcessTypeToString(getProcessType())); + CRFProcess* m_pcs = PCSGet(convertProcessTypeToString(getProcessType())); - if (getProcessDistributionType()==FiniteElement::CLIMATE) //NB for this type of ST, we assign a ST to each node on the Mesh surface (land surface) - { + if (getProcessDistributionType() == FiniteElement::CLIMATE) // NB for this type of ST, we assign a ST to each node + // on the Mesh surface (land surface) + { std::vector node_area_vec; MshEditor::getNodeAreas(m_pcs->m_msh, node_area_vec); - const std::vector &points ( MshEditor::getSurfaceNodes(*(m_pcs->m_msh)) ); + const std::vector& points(MshEditor::getSurfaceNodes(*(m_pcs->m_msh))); - size_t nPoints (points.size()); - std::cout << points.size() << " nodes found on mesh surface. " << "\n"; + size_t nPoints(points.size()); + std::cout << points.size() << " nodes found on mesh surface. " + << "\n"; - for (size_t i=0; igetID()); - CNodeValue* m_nod_val (new CNodeValue()); + size_t node_id(points[i]->getID()); + CNodeValue* m_nod_val(new CNodeValue()); m_nod_val->msh_node_number = node_id + ShiftInNodeVector; m_nod_val->geo_node_number = node_id; - m_nod_val->setProcessDistributionType (getProcessDistributionType()); - m_nod_val->node_value = std::numeric_limits::min(); // values will be assigned in IncorporateSoureTerms (rf_pcs.cpp) + m_nod_val->setProcessDistributionType(getProcessDistributionType()); + m_nod_val->node_value + = std::numeric_limits::min(); // values will be assigned in IncorporateSoureTerms (rf_pcs.cpp) m_nod_val->CurveIndex = CurveIndex; m_pcs->st_node_value.push_back(m_nod_val); m_pcs->st_node.push_back(this); m_pcs->m_msh->nod_vector[node_id]->patch_area = node_area_vec[node_id]; } - this->_distances = new MathLib::InverseDistanceInterpolation(points, this->_weather_stations); - } - else //NB this is the old version, where nodes were read from an separate input file - { - std::string line_string; - std::string st_file_name; - std::stringstream in; - long n_index; - double n_val; - - //======================================================================== - // File handling - std::ifstream d_file(fname.c_str(), std::ios::in); - //if (!st_file.good()) return; - - if (!d_file.good()) - { - std::cout << "! Error in direct node source terms: Could not find file:!\n" << fname << "\n"; - abort(); - } - // Rewind the file - d_file.clear(); - d_file.seekg(0L, std::ios::beg); - //======================================================================== - while (!d_file.eof()) - { - line_string = GetLineFromFile1(&d_file); - if (line_string.find("#STOP") != std::string::npos) - break; - - in.str(line_string); - in >> n_index >> n_val; - in.clear(); - // - CNodeValue* m_nod_val (new CNodeValue()); - m_nod_val->msh_node_number = n_index + ShiftInNodeVector; - m_nod_val->geo_node_number = n_index; - m_nod_val->setProcessDistributionType (getProcessDistributionType()); - m_nod_val->node_value = n_val; - m_nod_val->CurveIndex = CurveIndex; - m_pcs->st_node_value.push_back(m_nod_val); - m_pcs->st_node.push_back(this); - // - } // eof + this->_distances = new MathLib::InverseDistanceInterpolation( + points, this->_weather_stations); } -} + else // NB this is the old version, where nodes were read from an separate input file + { + std::string line_string; + std::string st_file_name; + std::stringstream in; + long n_index; + double n_val; + + //======================================================================== + // File handling + std::ifstream d_file(fname.c_str(), std::ios::in); + // if (!st_file.good()) return; + + if (!d_file.good()) + { + std::cout << "! Error in direct node source terms: Could not find file:!\n" << fname << "\n"; + abort(); + } + // Rewind the file + d_file.clear(); + d_file.seekg(0L, std::ios::beg); + //======================================================================== + while (!d_file.eof()) + { + line_string = GetLineFromFile1(&d_file); + if (line_string.find("#STOP") != std::string::npos) + break; + in.str(line_string); + in >> n_index >> n_val; + in.clear(); + // + CNodeValue* m_nod_val(new CNodeValue()); + m_nod_val->msh_node_number = n_index + ShiftInNodeVector; + m_nod_val->geo_node_number = n_index; + m_nod_val->setProcessDistributionType(getProcessDistributionType()); + m_nod_val->node_value = n_val; + m_nod_val->CurveIndex = CurveIndex; + m_pcs->st_node_value.push_back(m_nod_val); + m_pcs->st_node.push_back(this); + // + } // eof + } +} /************************************************************************** GeoSys source term function: @@ -4266,149 +4200,147 @@ GeoSys source term function: **************************************************************************/ std::string CSourceTerm::DirectAssign_Precipitation(double current_time) { - int i, size; - double stepA, stepB, tim_val; - - long l, nbc_node, n_index, osize = 0; - double n_val; - - std::string fileA, fileB; - - CRFProcess* m_pcs = NULL; - CNodeValue *m_nod_val = NULL; - //PCSGet(pcs_type_name); - m_pcs = PCSGet(convertProcessTypeToString (getProcessType())); - - if(start_pos_in_st<0) - osize = (long)m_pcs->st_node.size(); - - size = (int)precip_times.size(); - stepA = 0.; - stepB = 0.; - if(current_time < m_pcs->GetTimeStepping()->time_start||fabs(current_time - m_pcs->GetTimeStepping()->time_start) precip_times[size-1]||fabs(current_time - precip_times[size-1])tim_val) - { - if((current_time-tim_val)0.) - { - fileB = FilePath + fileB; - bin_sB.open(fileB.c_str(), ios::binary); - if(!bin_sB.good()) - { - cout<<"Could not find file "<< fileB<<'\n'; - exit(0); - } - bin_sB.setf(ios::scientific,ios::floatfield); - bin_sB.precision(14); - bin_sB.read((char*)(&nbc_node), sizeof(nbc_node)); - } - */ - - bin_sA.read((char*)(&nbc_node), sizeof(nbc_node)); - - double valA; //, valB = 0.; - for(l=0; l0.) - { - bin_sB.read((char*)(&n_index), sizeof(n_index)); - bin_sB.read((char*)(&valB), sizeof(valB)); - n_val = valA + (current_time - stepA)*(valB-valA)/(stepB-stepA); - } - else - */ - n_val = valA; - - // - if(start_pos_in_st<0) - { - m_nod_val = new CNodeValue(); - m_pcs->st_node_value.push_back(m_nod_val); - m_pcs->st_node.push_back(this); - } - else - m_nod_val = m_pcs->st_node_value[l+start_pos_in_st]; - - m_nod_val->msh_node_number = n_index ; - m_nod_val->geo_node_number = n_index; - //node_distype = dis_type; - m_nod_val->setProcessDistributionType (getProcessDistributionType()); - m_nod_val->node_value = n_val; - m_nod_val->CurveIndex = CurveIndex; - // - } // - - if(start_pos_in_st<0) - start_pos_in_st = osize; - - bin_sA.close(); - //bin_sB.close(); - - return fileA; -} + int i, size; + double stepA, stepB, tim_val; + + long l, nbc_node, n_index, osize = 0; + double n_val; + + std::string fileA, fileB; + + CRFProcess* m_pcs = NULL; + CNodeValue* m_nod_val = NULL; + // PCSGet(pcs_type_name); + m_pcs = PCSGet(convertProcessTypeToString(getProcessType())); + + if (start_pos_in_st < 0) + osize = (long)m_pcs->st_node.size(); + + size = (int)precip_times.size(); + stepA = 0.; + stepB = 0.; + if (current_time < m_pcs->GetTimeStepping()->time_start + || fabs(current_time - m_pcs->GetTimeStepping()->time_start) < DBL_MIN) + { + fileA = precip_files[0]; + stepB = -1.; + } + else if (current_time > precip_times[size - 1] || fabs(current_time - precip_times[size - 1]) < DBL_MIN) + { + fileA = precip_files[size - 1]; + stepB = -1.; + } + else + { + double step_b = DBL_MAX; + double step_f = DBL_MAX; + + for (i = 0; i < size; i++) + { + tim_val = precip_times[i]; + if (current_time > tim_val) + { + if ((current_time - tim_val) < step_b) + { + step_b = current_time - tim_val; + stepA = tim_val; + fileA = precip_files[i]; + } + } + else + { + if ((tim_val - current_time) < step_f) + { + step_f = tim_val - current_time; + stepB = tim_val; + fileB = precip_files[i]; + } + } + } + if (fabs(stepA - current_time) < DBL_MIN) + stepB = -1.; + if (fabs(current_time - stepB) < DBL_MIN) + { + fileA = fileB; + stepB = -1.; + } + if (fabs(stepA - stepB) < DBL_MIN) + stepB = -1.; + } + + fileA = FilePath + fileA; + std::ifstream bin_sA(fileA.c_str(), std::ios::binary); + std::ifstream bin_sB; + + if (!bin_sA.good()) + { + std::cout << "Could not find file " << fileA << '\n'; + exit(0); + } + bin_sA.setf(std::ios::scientific, std::ios::floatfield); + bin_sA.precision(14); + + /* + if(stepB>0.) + { + fileB = FilePath + fileB; + bin_sB.open(fileB.c_str(), ios::binary); + if(!bin_sB.good()) + { + cout<<"Could not find file "<< fileB<<'\n'; + exit(0); + } + bin_sB.setf(ios::scientific,ios::floatfield); + bin_sB.precision(14); + bin_sB.read((char*)(&nbc_node), sizeof(nbc_node)); + } + */ + + bin_sA.read((char*)(&nbc_node), sizeof(nbc_node)); + + double valA; //, valB = 0.; + for (l = 0; l < nbc_node; l++) + { + bin_sA.read((char*)(&n_index), sizeof(n_index)); + bin_sA.read((char*)(&valA), sizeof(valA)); + /* + if( stepB>0.) + { + bin_sB.read((char*)(&n_index), sizeof(n_index)); + bin_sB.read((char*)(&valB), sizeof(valB)); + n_val = valA + (current_time - stepA)*(valB-valA)/(stepB-stepA); + } + else + */ + n_val = valA; + + // + if (start_pos_in_st < 0) + { + m_nod_val = new CNodeValue(); + m_pcs->st_node_value.push_back(m_nod_val); + m_pcs->st_node.push_back(this); + } + else + m_nod_val = m_pcs->st_node_value[l + start_pos_in_st]; + + m_nod_val->msh_node_number = n_index; + m_nod_val->geo_node_number = n_index; + // node_distype = dis_type; + m_nod_val->setProcessDistributionType(getProcessDistributionType()); + m_nod_val->node_value = n_val; + m_nod_val->CurveIndex = CurveIndex; + // + } // + + if (start_pos_in_st < 0) + start_pos_in_st = osize; + bin_sA.close(); + // bin_sB.close(); + + return fileA; +} /************************************************************************** FEMLib-Method: @@ -4419,132 +4351,130 @@ std::string CSourceTerm::DirectAssign_Precipitation(double current_time) last modification: 04/2006 CMCD Updated **************************************************************************/ - // , CSourceTerm *m_st) +// , CSourceTerm *m_st) double CSourceTerm::GetAnalyticalSolution(long location) { - int idx, n; - int size, process_no; - long i; - long step, no_terms_included; - double value, source, gradient, ref_value = 0.0; - double timevalue; - double fac = 1.0; - double temp_time, temp_value; - double pi = 3.1415926; - double D = this->analytical_diffusion; - double ne = this->analytical_porosity; - double tort = this->analytical_tortousity; - double Kd = this->analytical_linear_sorption_Kd; - double rho = this->analytical_matrix_density; - double Dtrans = (D * ne) / ((ne + Kd * rho) * tort); - double Dsteady = D * ne / tort; - double t0, tn, tnn, val1, val2, node_area; - double tvol, vol, flux_area, tflux_area; - double mass_solute_present, mass_to_remove; - //WW bool out = false; - //WW int dimension = this->analytical_material_group; - std::string process; - CRFProcess* m_pcs = NULL; - m_pcs = PCSGet(convertProcessTypeToString(this->getProcessType()), convertPrimaryVariableToString(this->getProcessPrimaryVariable())); - CFEMesh* m_msh = m_pcs->m_msh; //WW - MeshLib::CElem* Ele = NULL; - long node_number = location; //WW m_pcs->st_node_value[location]->msh_node_number; - CNode* Node = m_msh->nod_vector[node_number]; - double area = m_pcs->st_node_value[location]->node_area; - std::vector time_history; - std::vector value_history; - //Initialise - time_history.clear(); - value_history.clear(); - t0 = tn = tnn = source = gradient = val1 = val2 = node_area = flux_area - = 0.0; - idx = m_pcs->GetNodeValueIndex(convertPrimaryVariableToString(this->getProcessPrimaryVariable())); - value = m_pcs->GetNodeValue(node_number, idx); - if (value < MKleinsteZahl) - value = 0.0; - timevalue = aktuelle_zeit; - step = aktueller_zeitschritt; - if (step < 10) - step = 10; - size = (int) analytical_processes.size(); - process_no = 0; - //Domain or Polyline - for (i = 0; i < size; i++) - { - if (analytical_processes[i] == convertPrimaryVariableToString(this->getProcessPrimaryVariable())) - { - if (this->getGeoType () == GEOLIB::POLYLINE) - { - if (this->getGeoName().compare( - analytical_processes_polylines[i]) == 0) - process_no = i; - } - // if (this->geo_type_name.compare("DOMAIN") == 0) - if (this->getGeoType () == GEOLIB::GEODOMAIN) - process_no = i; - } - } - //Identify process - if (process_no == 1) - { - process_no = process_no; - } - process_no *= 2; //first column time, second column value, hence two columns per process; - - //If time step require new calculation of source term then start - if ((aktueller_zeitschritt - 1) % this->resolution == 0) { - //Save data in a vector attached to the nodes - this->SetNodePastValue(node_number, process_no, 0, timevalue); - this->SetNodePastValue(node_number, process_no + 1, 0, value); - - //Recall historical data - ref_value = this->GetNodePastValueReference(node_number, (process_no - / 2)); - if ((size_t)step > this->number_of_terms) - no_terms_included = this->number_of_terms; - else - no_terms_included = step; - for (i = 0; i < no_terms_included; i++) - { - temp_time = this->GetNodePastValue(node_number, process_no, i); - temp_value - = (this->GetNodePastValue(node_number, process_no + 1, i) - - ref_value); - time_history.push_back(temp_time); - value_history.push_back(temp_value); - } - - //Calculate individual terms and sum for gradient - for (i = no_terms_included - 1; i > 0; i--) - { - t0 = time_history[0]; - if (i == no_terms_included - 1) - tn = (t0 - time_history[i]) + (time_history[i - 1] - - time_history[i]); - else - tn = t0 - time_history[i + 1]; - tnn = t0 - time_history[i]; - val1 = 1 / (sqrt(pi * Dtrans * tn)); - val2 = 1 / (sqrt(pi * Dtrans * tnn)); - gradient += ((val2 - val1) * value_history[i]); - } - tn = t0 - time_history[1]; - tnn = 0; - val1 = 1 / (sqrt(pi * Dtrans * tn)); - gradient -= (val1 * value_history[0]); - - //Area calculations - mass_solute_present = 1.e99; //Initially set value very high - - //Area for lines, triangles and quads in domain. - // if (area < 0) {//set in set source terms function, domain area = -1 to start with - if (area < DBL_MIN) { // HS 04.2008 + int idx, n; + int size, process_no; + long i; + long step, no_terms_included; + double value, source, gradient, ref_value = 0.0; + double timevalue; + double fac = 1.0; + double temp_time, temp_value; + double pi = 3.1415926; + double D = this->analytical_diffusion; + double ne = this->analytical_porosity; + double tort = this->analytical_tortousity; + double Kd = this->analytical_linear_sorption_Kd; + double rho = this->analytical_matrix_density; + double Dtrans = (D * ne) / ((ne + Kd * rho) * tort); + double Dsteady = D * ne / tort; + double t0, tn, tnn, val1, val2, node_area; + double tvol, vol, flux_area, tflux_area; + double mass_solute_present, mass_to_remove; + // WW bool out = false; + // WW int dimension = this->analytical_material_group; + std::string process; + CRFProcess* m_pcs = NULL; + m_pcs = PCSGet(convertProcessTypeToString(this->getProcessType()), + convertPrimaryVariableToString(this->getProcessPrimaryVariable())); + CFEMesh* m_msh = m_pcs->m_msh; // WW + MeshLib::CElem* Ele = NULL; + long node_number = location; // WW m_pcs->st_node_value[location]->msh_node_number; + CNode* Node = m_msh->nod_vector[node_number]; + double area = m_pcs->st_node_value[location]->node_area; + std::vector time_history; + std::vector value_history; + // Initialise + time_history.clear(); + value_history.clear(); + t0 = tn = tnn = source = gradient = val1 = val2 = node_area = flux_area = 0.0; + idx = m_pcs->GetNodeValueIndex(convertPrimaryVariableToString(this->getProcessPrimaryVariable())); + value = m_pcs->GetNodeValue(node_number, idx); + if (value < MKleinsteZahl) + value = 0.0; + timevalue = aktuelle_zeit; + step = aktueller_zeitschritt; + if (step < 10) + step = 10; + size = (int)analytical_processes.size(); + process_no = 0; + // Domain or Polyline + for (i = 0; i < size; i++) + { + if (analytical_processes[i] == convertPrimaryVariableToString(this->getProcessPrimaryVariable())) + { + if (this->getGeoType() == GEOLIB::POLYLINE) + { + if (this->getGeoName().compare(analytical_processes_polylines[i]) == 0) + process_no = i; + } + // if (this->geo_type_name.compare("DOMAIN") == 0) + if (this->getGeoType() == GEOLIB::GEODOMAIN) + process_no = i; + } + } + // Identify process + if (process_no == 1) + { + process_no = process_no; + } + process_no *= 2; // first column time, second column value, hence two columns per process; + + // If time step require new calculation of source term then start + if ((aktueller_zeitschritt - 1) % this->resolution == 0) + { + // Save data in a vector attached to the nodes + this->SetNodePastValue(node_number, process_no, 0, timevalue); + this->SetNodePastValue(node_number, process_no + 1, 0, value); + + // Recall historical data + ref_value = this->GetNodePastValueReference(node_number, (process_no / 2)); + if ((size_t)step > this->number_of_terms) + no_terms_included = this->number_of_terms; + else + no_terms_included = step; + for (i = 0; i < no_terms_included; i++) + { + temp_time = this->GetNodePastValue(node_number, process_no, i); + temp_value = (this->GetNodePastValue(node_number, process_no + 1, i) - ref_value); + time_history.push_back(temp_time); + value_history.push_back(temp_value); + } + + // Calculate individual terms and sum for gradient + for (i = no_terms_included - 1; i > 0; i--) + { + t0 = time_history[0]; + if (i == no_terms_included - 1) + tn = (t0 - time_history[i]) + (time_history[i - 1] - time_history[i]); + else + tn = t0 - time_history[i + 1]; + tnn = t0 - time_history[i]; + val1 = 1 / (sqrt(pi * Dtrans * tn)); + val2 = 1 / (sqrt(pi * Dtrans * tnn)); + gradient += ((val2 - val1) * value_history[i]); + } + tn = t0 - time_history[1]; + tnn = 0; + val1 = 1 / (sqrt(pi * Dtrans * tn)); + gradient -= (val1 * value_history[0]); + + // Area calculations + mass_solute_present = 1.e99; // Initially set value very high + + // Area for lines, triangles and quads in domain. + // if (area < 0) {//set in set source terms function, domain area = -1 to start with + if (area < DBL_MIN) + { // HS 04.2008 tvol = 0.0; tflux_area = 0.0; - for (i = 0; i < (int) Node->getConnectedElementIDs().size(); i++) { + for (i = 0; i < (int)Node->getConnectedElementIDs().size(); i++) + { Ele = m_msh->ele_vector[Node->getConnectedElementIDs()[i]]; - vol = Ele->GetVolume(); //Assuming 1m thickness - flux_area = Ele->GetFluxArea(); //Real thickness for a fracture + vol = Ele->GetVolume(); // Assuming 1m thickness + flux_area = Ele->GetFluxArea(); // Real thickness for a fracture n = Ele->GetVertexNumber(); tvol += (vol / n); tflux_area += (flux_area / n); @@ -4552,26 +4482,25 @@ double CSourceTerm::GetAnalyticalSolution(long location) node_area = tvol * 2.; //* 2 because the diffusion is in two direction perpendicular to the fracture mass_solute_present = tflux_area * tvol * value; } - //Area for polylines + // Area for polylines else - node_area = area; - - //factor for conversion to energy for temperature if necessary - fac = this->factor; - source = gradient * Dsteady * fac * node_area; - mass_to_remove = fabs(source) * dt; - if (mass_to_remove > mass_solute_present) - { - source *= (mass_solute_present / mass_to_remove); - } - this->SetNodeLastValue(node_number, (process_no / 2), source); - - } // If new source term calculation not required - else - source = this->GetNodeLastValue(node_number, (process_no / 2)); - return source; -} + node_area = area; + // factor for conversion to energy for temperature if necessary + fac = this->factor; + source = gradient * Dsteady * fac * node_area; + mass_to_remove = fabs(source) * dt; + if (mass_to_remove > mass_solute_present) + { + source *= (mass_solute_present / mass_to_remove); + } + this->SetNodeLastValue(node_number, (process_no / 2), source); + + } // If new source term calculation not required + else + source = this->GetNodeLastValue(node_number, (process_no / 2)); + return source; +} /************************************************************************** FEMLib-Method: @@ -4583,161 +4512,152 @@ double CSourceTerm::GetAnalyticalSolution(long location) **************************************************************************/ void CSourceTerm::SetNodePastValue(long n, int idx, int pos, double value) { - bool endstepreached = false; - pos = pos; //WW - - //Check whether this is the first call - CRFProcess* m_pcs = NULL; - m_pcs = PCSGet(convertProcessTypeToString(getProcessType()), convertPrimaryVariableToString (getProcessPrimaryVariable())); - if (!m_pcs) //OK - { - std::cout << "Warning in SetNodePastValue - no PCS data" << '\n'; - return; - } - - size_t size1 (m_pcs->nod_val_vector.size()); - - //Create memory for the values - if (node_history_vector.empty()) - { - //WW int number_of_terms = max_no_terms; - for (size_t k = 0; k < size1; k++) - { - NODE_HISTORY *nh = new NODE_HISTORY; - CreateHistoryNodeMemory(nh); - node_history_vector.push_back(nh); - } - for (size_t k = 0; k < size1; k++) - { - for (size_t j = 0; j < _no_an_sol; j++) - node_history_vector[k]->value_reference.push_back(-1.0); - } - } - - //Store the first set of values as reference values - int flipflop = idx % 2; - if (aktueller_zeitschritt == 1) - { - //if (size2 == idx) - if (flipflop == 1) - node_history_vector[n]->value_reference[(idx - 1) / 2] = value; - } - // size2 = (int) node_history_vector[n]->value_reference.size(); - size_t steps = 10; - if (aktueller_zeitschritt > steps) - steps = aktueller_zeitschritt; - if (_max_no_terms >= steps) - steps = aktueller_zeitschritt; - else - { - steps = _max_no_terms; - endstepreached = true; - } - //Enter the value and push the other values back - if (!endstepreached) - { - for (size_t k = steps - 1; k > 0; k--) - node_history_vector[n]->value_store[idx][k] - = node_history_vector[n]->value_store[idx][k - 1]; - node_history_vector[n]->value_store[idx][0] = value; - } - double cutvalue = 0.0; - double nextvalue = 0.0; - long no_steps_past_cutof = 0; - if (endstepreached) - { - no_steps_past_cutof = aktueller_zeitschritt - _max_no_terms; - cutvalue = node_history_vector[n]->value_store[idx][steps - 1]; - nextvalue = node_history_vector[n]->value_store[idx][steps - 2]; - node_history_vector[n]->value_store[idx][steps - 1] = (cutvalue - * (double) (no_steps_past_cutof) + nextvalue) - / ((double) no_steps_past_cutof + 1); - for (size_t k = steps - 2; k > 0; k--) - node_history_vector[n]->value_store[idx][k] - = node_history_vector[n]->value_store[idx][k - 1]; - node_history_vector[n]->value_store[idx][0] = value; - } -} + bool endstepreached = false; + pos = pos; // WW + + // Check whether this is the first call + CRFProcess* m_pcs = NULL; + m_pcs = PCSGet(convertProcessTypeToString(getProcessType()), + convertPrimaryVariableToString(getProcessPrimaryVariable())); + if (!m_pcs) // OK + { + std::cout << "Warning in SetNodePastValue - no PCS data" << '\n'; + return; + } + size_t size1(m_pcs->nod_val_vector.size()); + + // Create memory for the values + if (node_history_vector.empty()) + { + // WW int number_of_terms = max_no_terms; + for (size_t k = 0; k < size1; k++) + { + NODE_HISTORY* nh = new NODE_HISTORY; + CreateHistoryNodeMemory(nh); + node_history_vector.push_back(nh); + } + for (size_t k = 0; k < size1; k++) + { + for (size_t j = 0; j < _no_an_sol; j++) + node_history_vector[k]->value_reference.push_back(-1.0); + } + } + + // Store the first set of values as reference values + int flipflop = idx % 2; + if (aktueller_zeitschritt == 1) + { + // if (size2 == idx) + if (flipflop == 1) + node_history_vector[n]->value_reference[(idx - 1) / 2] = value; + } + // size2 = (int) node_history_vector[n]->value_reference.size(); + size_t steps = 10; + if (aktueller_zeitschritt > steps) + steps = aktueller_zeitschritt; + if (_max_no_terms >= steps) + steps = aktueller_zeitschritt; + else + { + steps = _max_no_terms; + endstepreached = true; + } + // Enter the value and push the other values back + if (!endstepreached) + { + for (size_t k = steps - 1; k > 0; k--) + node_history_vector[n]->value_store[idx][k] = node_history_vector[n]->value_store[idx][k - 1]; + node_history_vector[n]->value_store[idx][0] = value; + } + double cutvalue = 0.0; + double nextvalue = 0.0; + long no_steps_past_cutof = 0; + if (endstepreached) + { + no_steps_past_cutof = aktueller_zeitschritt - _max_no_terms; + cutvalue = node_history_vector[n]->value_store[idx][steps - 1]; + nextvalue = node_history_vector[n]->value_store[idx][steps - 2]; + node_history_vector[n]->value_store[idx][steps - 1] + = (cutvalue * (double)(no_steps_past_cutof) + nextvalue) / ((double)no_steps_past_cutof + 1); + for (size_t k = steps - 2; k > 0; k--) + node_history_vector[n]->value_store[idx][k] = node_history_vector[n]->value_store[idx][k - 1]; + node_history_vector[n]->value_store[idx][0] = value; + } +} void CSourceTerm::SetNodeLastValue(long n, int idx, double value) { - size_t size (node_history_vector[n]->last_source_value.size()); - if (size == 0) - { - for (size_t i = 0; i < _no_an_sol; i++) - node_history_vector[n]->last_source_value.push_back(0); - } - node_history_vector[n]->last_source_value[idx] = value; + size_t size(node_history_vector[n]->last_source_value.size()); + if (size == 0) + { + for (size_t i = 0; i < _no_an_sol; i++) + node_history_vector[n]->last_source_value.push_back(0); + } + node_history_vector[n]->last_source_value[idx] = value; } - double CSourceTerm::GetNodeLastValue(long n, int idx) { - double value = 0.0; - value = node_history_vector[n]->last_source_value[idx]; - return value; + double value = 0.0; + value = node_history_vector[n]->last_source_value[idx]; + return value; } - double CSourceTerm::GetNodePastValue(long n, int idx, int pos) { - double value; - value = node_history_vector[n]->value_store[idx][pos]; - return value; + double value; + value = node_history_vector[n]->value_store[idx][pos]; + return value; } - double CSourceTerm::GetNodePastValueReference(long n, int idx) { - double value; - value = node_history_vector[n]->value_reference[idx]; - return value; + double value; + value = node_history_vector[n]->value_reference[idx]; + return value; } - void CSourceTerm::CreateHistoryNodeMemory(NODE_HISTORY* nh) { - size_t s_col = _no_an_sol * 2; - size_t s_row = number_of_terms; - - nh->value_store = new double*[s_col]; - for (size_t i = 0; i < s_col; i++) - nh->value_store[i] = new double[s_row]; - - for (size_t k = 0; k < s_col; k++) - { - for (size_t j = 0; j < s_row; j++) - nh->value_store[k][j] = 0.0; - } -} + size_t s_col = _no_an_sol * 2; + size_t s_row = number_of_terms; + + nh->value_store = new double*[s_col]; + for (size_t i = 0; i < s_col; i++) + nh->value_store[i] = new double[s_row]; + for (size_t k = 0; k < s_col; k++) + { + for (size_t j = 0; j < s_row; j++) + nh->value_store[k][j] = 0.0; + } +} void CSourceTerm::DeleteHistoryNodeMemory() { - size_t size (node_history_vector.size()); - size_t s_row = _no_an_sol * 2; - - if (size > 0) - { - for (size_t j = 0; j < size; j++) - { - for (size_t i = 0; i < s_row; i++) - delete node_history_vector[j]->value_store[i]; - delete node_history_vector[j]->value_store; - } - node_history_vector.clear(); - } -} + size_t size(node_history_vector.size()); + size_t s_row = _no_an_sol * 2; + if (size > 0) + { + for (size_t j = 0; j < size; j++) + { + for (size_t i = 0; i < s_row; i++) + delete node_history_vector[j]->value_store[i]; + delete node_history_vector[j]->value_store; + } + node_history_vector.clear(); + } +} ///************************************************************************** -//FEMLib-Method: -//07/2007 OK Implementation -//modifications: -//05/2010 TF restructured a little bit +// FEMLib-Method: +// 07/2007 OK Implementation +// modifications: +// 05/2010 TF restructured a little bit //**************************************************************************/ -//CSourceTerm* STGet(const std::string& pcs_name, const std::string& geo_type_name, const std::string& geo_name) +// CSourceTerm* STGet(const std::string& pcs_name, const std::string& geo_type_name, const std::string& geo_name) //{ // for(size_t i=0;ipcs_type_name.compare(pcs_name)==0) && @@ -4761,135 +4681,129 @@ void CSourceTerm::DeleteHistoryNodeMemory() gives heads for liquids and pressures for gases overland / groundwater nodes are shifted to a soil column if required **************************************************************************/ -void GetCouplingFieldVariables( CRFProcess* m_pcs_this, CRFProcess* m_pcs_cond, double* h_this, double* h_cond, -double* h_shifted, double* h_averaged, double* z_this, double* z_cond, -CSourceTerm* m_st, CNodeValue* cnodev, long msh_node_number, long msh_node_number_cond, double gamma) +void GetCouplingFieldVariables(CRFProcess* m_pcs_this, CRFProcess* m_pcs_cond, double* h_this, double* h_cond, + double* h_shifted, double* h_averaged, double* z_this, double* z_cond, CSourceTerm* m_st, + CNodeValue* cnodev, long msh_node_number, long msh_node_number_cond, double gamma) { + int nidx, nidx_cond; + + *z_this = m_pcs_this->m_msh->nod_vector[msh_node_number]->getData()[2]; + *z_cond = m_pcs_cond->m_msh->nod_vector[msh_node_number_cond]->getData()[2]; + + nidx = m_pcs_this->GetNodeValueIndex(convertPrimaryVariableToString(m_st->getProcessPrimaryVariable())) + 1; + nidx_cond = m_pcs_cond->GetNodeValueIndex(m_st->pcs_pv_name_cond) + 1; + + *h_this = m_pcs_this->GetNodeValue(msh_node_number, nidx); + + if (m_st->pcs_pv_name_cond == "GIVEN_HEIGHT" || m_st->pcs_pv_name_cond == "PRESSURE2") + { + *h_cond = *h_shifted = m_st->coup_given_value; // coupled to fixed pressure head / or atmospheric pressure + *z_this = *z_cond = 0; + return; + } + else if (m_st->pcs_pv_name_cond == "GIVEN_PRESSURE") + { + *h_cond = *h_shifted + = m_st->coup_given_value / gamma; // coupled to fixed pressure head / or atmospheric pressure + *z_this = *z_cond = 0; + return; + } + else + *h_cond = m_pcs_cond->GetNodeValue(msh_node_number_cond, nidx_cond); // coupled to a liquid - int nidx, nidx_cond; - - *z_this = m_pcs_this->m_msh->nod_vector[msh_node_number]->getData()[2]; - *z_cond = m_pcs_cond->m_msh->nod_vector[msh_node_number_cond]->getData()[2]; - - nidx = m_pcs_this->GetNodeValueIndex (convertPrimaryVariableToString (m_st->getProcessPrimaryVariable())) + 1; - nidx_cond = m_pcs_cond->GetNodeValueIndex(m_st->pcs_pv_name_cond) + 1; - - *h_this = m_pcs_this->GetNodeValue(msh_node_number, nidx); - - if(m_st->pcs_pv_name_cond == "GIVEN_HEIGHT" || m_st->pcs_pv_name_cond == "PRESSURE2") - { - *h_cond = *h_shifted = m_st->coup_given_value; // coupled to fixed pressure head / or atmospheric pressure - *z_this = *z_cond = 0; - return; - } - else if(m_st->pcs_pv_name_cond == "GIVEN_PRESSURE") - { - *h_cond = *h_shifted = m_st->coup_given_value / gamma; // coupled to fixed pressure head / or atmospheric pressure - *z_this = *z_cond = 0; - return; - } - else - *h_cond = m_pcs_cond->GetNodeValue(msh_node_number_cond, nidx_cond); // coupled to a liquid - - if(m_st->pcs_pv_name_cond == "PRESSURE1") { - - if(m_st->pcs_type_name_cond == "MULTI_PHASE_FLOW") - { // capillary pressure as a primary variable in the coupled process - double gasPressure = m_pcs_cond->GetNodeValue(msh_node_number_cond, 3); - *h_cond -= (gasPressure - m_st->coup_given_value); - } - } - - if (m_st->getProcessType() == FiniteElement::OVERLAND_FLOW - || m_st->getProcessType() == FiniteElement::GROUNDWATER_FLOW) - { - if (m_st->node_averaging) - { // average pressures from overland / groundwater (soil column coupled to multiple nodes) - *h_shifted = *h_this - *z_this + *z_cond; // shift overland / groundwater node to soil column - *h_averaged = 0; - for (long i = 0; i - < (long) cnodev->msh_node_numbers_averaging.size(); i++) - *h_averaged - += cnodev->msh_node_weights_averaging[i] - * (m_pcs_this->GetNodeValue( - cnodev->msh_node_numbers_averaging[i], - nidx) - - m_pcs_this->m_msh->nod_vector[cnodev->msh_node_numbers_averaging[i]]->getData()[2]); - - *h_averaged += *z_cond; // convert to head - *z_this = *z_cond; - } // end averaging - else // no averaging - { // no column, no shifting - *h_shifted = *h_this; - *h_averaged = *h_this; - } // end no averaging - - if (m_st->pcs_pv_name_cond == "PRESSURE1") - { // convert to head - // if (m_st->pcs_type_name_cond == "MULTI_PHASE_FLOW") - // *h_cond /= -gamma; - //else - *h_cond /= gamma; - - *h_cond += *z_cond; - } - if (m_st->pcs_type_name_cond == "GROUNDWATER_FLOW") - h_cond = std::max(h_cond, z_this); //groundwater level might not reach surface - } // end overland flow - else - { // subsurface flow - if (m_st->pcs_pv_name_cond == "PRESSURE1") // JOD 4.10.01 - { // convert to head - //if (m_st->pcs_type_name_cond == "MULTI_PHASE_FLOW") - // *h_cond /= -gamma; - //else - *h_cond /= gamma; - - *h_cond += *z_cond; - } - if (m_st->node_averaging) - { // shift overland / groundwater node to the soil column - *h_shifted = *h_cond - *z_cond; - *h_shifted += *z_this; - *z_cond = *z_this; - } // end averaging - else - *h_shifted = *h_cond; // no column, no shifting - - if (m_st->getProcessPrimaryVariable() == FiniteElement::PRESSURE) - { // convert pressure into head - *h_this /= gamma; - *h_this += *z_this; - } - } // end subsurface flow + if (m_st->pcs_pv_name_cond == "PRESSURE1") + { + if (m_st->pcs_type_name_cond == "MULTI_PHASE_FLOW") + { // capillary pressure as a primary variable in the coupled process + double gasPressure = m_pcs_cond->GetNodeValue(msh_node_number_cond, 3); + *h_cond -= (gasPressure - m_st->coup_given_value); + } + } + if (m_st->getProcessType() == FiniteElement::OVERLAND_FLOW + || m_st->getProcessType() == FiniteElement::GROUNDWATER_FLOW) + { + if (m_st->node_averaging) + { // average pressures from overland / groundwater (soil column coupled to multiple nodes) + *h_shifted = *h_this - *z_this + *z_cond; // shift overland / groundwater node to soil column + *h_averaged = 0; + for (long i = 0; i < (long)cnodev->msh_node_numbers_averaging.size(); i++) + *h_averaged += cnodev->msh_node_weights_averaging[i] + * (m_pcs_this->GetNodeValue(cnodev->msh_node_numbers_averaging[i], nidx) + - m_pcs_this->m_msh->nod_vector[cnodev->msh_node_numbers_averaging[i]]->getData()[2]); + + *h_averaged += *z_cond; // convert to head + *z_this = *z_cond; + } // end averaging + else // no averaging + { // no column, no shifting + *h_shifted = *h_this; + *h_averaged = *h_this; + } // end no averaging + + if (m_st->pcs_pv_name_cond == "PRESSURE1") + { // convert to head + // if (m_st->pcs_type_name_cond == "MULTI_PHASE_FLOW") + // *h_cond /= -gamma; + // else + *h_cond /= gamma; + + *h_cond += *z_cond; + } + if (m_st->pcs_type_name_cond == "GROUNDWATER_FLOW") + h_cond = std::max(h_cond, z_this); // groundwater level might not reach surface + } // end overland flow + else + { // subsurface flow + if (m_st->pcs_pv_name_cond == "PRESSURE1") // JOD 4.10.01 + { // convert to head + // if (m_st->pcs_type_name_cond == "MULTI_PHASE_FLOW") + // *h_cond /= -gamma; + // else + *h_cond /= gamma; + + *h_cond += *z_cond; + } + if (m_st->node_averaging) + { // shift overland / groundwater node to the soil column + *h_shifted = *h_cond - *z_cond; + *h_shifted += *z_this; + *z_cond = *z_this; + } // end averaging + else + *h_shifted = *h_cond; // no column, no shifting + + if (m_st->getProcessPrimaryVariable() == FiniteElement::PRESSURE) + { // convert pressure into head + *h_this /= gamma; + *h_this += *z_this; + } + } // end subsurface flow } /************************************************************************** FEMLib-Method: 4.7.10 10/2008 JOD Implementation **************************************************************************/ -double CalcCouplingValue(double factor, double h_this, double h_cond, -double z_cond, CSourceTerm* m_st) +double CalcCouplingValue(double factor, double h_this, double h_cond, double z_cond, CSourceTerm* m_st) { - - if (m_st->getProcessType() == FiniteElement::OVERLAND_FLOW) - { - if (m_st->no_surface_water_pressure) - return factor * (h_cond - z_cond); // neglect hydrostatic surface liquid pressure - else - return factor * (h_cond - h_this); - } // Richards' & groundwater flow - else - { - if (m_st->getProcessType() == FiniteElement::GROUNDWATER_FLOW) - { - if (h_this < z_cond && m_st->pcs_type_name_cond == "OVERLAND_FLOW") - return factor * (h_cond - z_cond); // decoupled - else - return factor * h_cond; - } else - return factor * (h_cond - z_cond); // Richards', two-phase flow (liquid & gas) - } + if (m_st->getProcessType() == FiniteElement::OVERLAND_FLOW) + { + if (m_st->no_surface_water_pressure) + return factor * (h_cond - z_cond); // neglect hydrostatic surface liquid pressure + else + return factor * (h_cond - h_this); + } // Richards' & groundwater flow + else + { + if (m_st->getProcessType() == FiniteElement::GROUNDWATER_FLOW) + { + if (h_this < z_cond && m_st->pcs_type_name_cond == "OVERLAND_FLOW") + return factor * (h_cond - z_cond); // decoupled + else + return factor * h_cond; + } + else + return factor * (h_cond - z_cond); // Richards', two-phase flow (liquid & gas) + } } diff --git a/FEM/rf_st_new.h b/FEM/rf_st_new.h index 203bb0176..d2a298126 100644 --- a/FEM/rf_st_new.h +++ b/FEM/rf_st_new.h @@ -7,21 +7,21 @@ * */ - /************************************************************************** - FEMLib - Object: Source Terms ST - Task: class implementation - Programing: - 01/2003 OK Implementation - last modified +/************************************************************************** + FEMLib - Object: Source Terms ST + Task: class implementation + Programing: + 01/2003 OK Implementation + last modified **************************************************************************/ #ifndef rf_st_new_INC #define rf_st_new_INC // FEM #include "DistributionInfo.h" // TF -#include "GeoInfo.h" // TF +#include "GeoInfo.h" // TF #include "LinearFunctionData.h" // TF -#include "ProcessInfo.h" // TF +#include "ProcessInfo.h" // TF #include "fem_ele.h" #include "Constrained.h" @@ -30,14 +30,15 @@ class CGLPolyline; class CGLLine; class Surface; -namespace process //WW +namespace process // WW { class CRFProcessDeformation; }; namespace MathLib { -template class InverseDistanceInterpolation; +template +class InverseDistanceInterpolation; } namespace MeshLib @@ -46,15 +47,15 @@ class CFEMesh; class MeshNodesAlongPolyline; } - class SourceTerm; typedef struct { std::vector value_reference; std::vector last_source_value; - //double value_store[10][5000]; - double** value_store; //[PCS_NUMBER_MAX*2]First ref no processes(two fields per process..time, value), second ref no values + // double value_store[10][5000]; + double** value_store; //[PCS_NUMBER_MAX*2]First ref no processes(two fields per process..time, value), second ref no + // values } NODE_HISTORY; class CSourceTerm : public ProcessInfo, public GeoInfo, public DistributionInfo @@ -64,81 +65,76 @@ class CSourceTerm : public ProcessInfo, public GeoInfo, public DistributionInfo CSourceTerm(const SourceTerm* st); ~CSourceTerm(); - std::ios::pos_type Read(std::ifstream* in, - const GEOLIB::GEOObjects & geo_obj, - const std::string & unique_name); + std::ios::pos_type Read(std::ifstream* in, const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name); void Write(std::fstream*); void EdgeIntegration(MeshLib::CFEMesh* m_msh, - const std::vector & nodes_on_ply, - std::vector & node_value_vector) const; + const std::vector& nodes_on_ply, + std::vector& node_value_vector) const; void FaceIntegration(MeshLib::CFEMesh* m_msh, - std::vector const & nodes_on_sfc, - std::vector & node_value_vector); + std::vector const& nodes_on_sfc, + std::vector& node_value_vector); void DomainIntegration(MeshLib::CFEMesh* m_msh, - const std::vector & nodes_in_dom, - std::vector & node_value_vector) const; + const std::vector& nodes_in_dom, + std::vector& node_value_vector) const; - void SetNOD2MSHNOD(std::vector & nodes, std::vector & conditional_nodes); + void SetNOD2MSHNOD(std::vector& nodes, std::vector& conditional_nodes); /** * @param nodes * @param conditional_nodes */ // 09/2010 TF - void SetNOD2MSHNOD(const std::vector& nodes, - std::vector& conditional_nodes) const; + void SetNOD2MSHNOD(const std::vector& nodes, std::vector& conditional_nodes) const; double GetNodeLastValue(long n, int idx); // used only once in a global in rf_st_new - // used only once in a global in rf_st_new + // used only once in a global in rf_st_new void SetNodePastValue(long n, int idx, int pos, double value); // used only once in a global in rf_st_new void SetNodeLastValue(long n, int idx, double value); double GetNodePastValue(long, int, int); // used only once in a global in rf_st_new - // used only once in a global in rf_st_new + // used only once in a global in rf_st_new double GetNodePastValueReference(long n, int idx); // used only in sourcetermgroup - void SetSurfaceNodeVectorConditional(std::vector & sfc_nod_vector, - std::vector & sfc_nod_vector_cond); + void SetSurfaceNodeVectorConditional(std::vector& sfc_nod_vector, std::vector& sfc_nod_vector_cond); // used only once in sourcetermgroup void InterpolatePolylineNodeValueVector(CGLPolyline* m_ply, - std::vector & Distribed, - std::vector & ply_nod_vector); - void InterpolatePolylineNodeValueVector( - std::vector const & nodes_as_interpol_points, - std::vector& node_values) const; + std::vector& Distribed, + std::vector& ply_nod_vector); + void InterpolatePolylineNodeValueVector(std::vector const& nodes_as_interpol_points, + std::vector& node_values) const; - void SetNodeValues(const std::vector & nodes, const std::vector & nodes_cond, - const std::vector & node_values, int ShiftInNodeVector); // used only in sourcetermgroup + void SetNodeValues(const std::vector& nodes, const std::vector& nodes_cond, + const std::vector& node_values, int ShiftInNodeVector); // used only in sourcetermgroup void SetNOD(); - //23.02.2009. WW + // 23.02.2009. WW void DirectAssign(const long ShiftInNodeVector); // KR / NB // including climate data into source terms - const MathLib::InverseDistanceInterpolation *getClimateStationDistanceInterpolation() const { return this->_distances; }; - const std::vector& getClimateStations() const { return this->_weather_stations; }; //NB - - - //03.2010. WW + const MathLib::InverseDistanceInterpolation* + getClimateStationDistanceInterpolation() const + { + return this->_distances; + }; + const std::vector& getClimateStations() const { return this->_weather_stations; }; // NB + // 03.2010. WW std::string DirectAssign_Precipitation(double current_time); - double getCoupLeakance () const; - - const std::vector& getDistribution () const { return DistribedBC; } + double getCoupLeakance() const; + const std::vector& getDistribution() const { return DistribedBC; } /** * REMOVE CANDIDATE only for compatibility with old GEOLIB version * @return */ - const std::string & getGeoName() const; - - double getGeoNodeValue() const { return geo_node_value; } //KR + const std::string& getGeoName() const; + double getGeoNodeValue() const { return geo_node_value; } // KR int CurveIndex; std::vector element_st_vector; @@ -147,43 +143,63 @@ class CSourceTerm : public ProcessInfo, public GeoInfo, public DistributionInfo bool node_averaging, distribute_volume_flux; // JOD bool no_surface_water_pressure, explicit_surface_water_pressure; // JOD - bool isCoupled () const { return _coupled; } - double getNormalDepthSlope () const { return normaldepth_slope; } - + bool isCoupled() const { return _coupled; } + double getNormalDepthSlope() const { return normaldepth_slope; } // constrain a ST by other process bool isConstrainedST() const { return _isConstrainedST; } - Constrained const & getConstrainedST(std::size_t constrainedID) const { return _constrainedST[constrainedID]; } + Constrained const& getConstrainedST(std::size_t constrainedID) const { return _constrainedST[constrainedID]; } std::size_t getNumberOfConstrainedSTs() const { return _constrainedST.size(); } - bool isCompleteConstrainST(std::size_t constrainedID) const { return _constrainedST[constrainedID]._isCompleteConstrained; } - bool getCompleteConstrainedSTStateOff(std::size_t constrainedID) const { return _constrainedST[constrainedID]._completeConstrainedStateOff; } - void setCompleteConstrainedSTStateOff(bool status, std::size_t i) { _constrainedST[i]._completeConstrainedStateOff = status; } - - void pushBackConstrainedSTNode(std::size_t constrainedID, bool constrainedStatus) { _constrainedST[constrainedID]._constrainedNodes.push_back(constrainedStatus); } - bool getConstrainedSTNode(std::size_t constrainedID, int position) const { return _constrainedST[constrainedID]._constrainedNodes[position]; } - void setConstrainedSTNode(std::size_t constrainedID, bool node_status, int position) { _constrainedST[constrainedID]._constrainedNodes[position] = node_status; } - std::size_t getNumberOfConstrainedSTNodes(std::size_t constrainedID) const { return _constrainedST[constrainedID]._constrainedNodes.size(); } - int getConstrainedSTNodesIndex(int position) const { return _constrainedSTNodesIndices[position]; } - void setConstrainedSTNodesIndex(int st_node_index, int position) { _constrainedSTNodesIndices[position]=st_node_index; } + bool isCompleteConstrainST(std::size_t constrainedID) const + { + return _constrainedST[constrainedID]._isCompleteConstrained; + } + bool getCompleteConstrainedSTStateOff(std::size_t constrainedID) const + { + return _constrainedST[constrainedID]._completeConstrainedStateOff; + } + void setCompleteConstrainedSTStateOff(bool status, std::size_t i) + { + _constrainedST[i]._completeConstrainedStateOff = status; + } + void pushBackConstrainedSTNode(std::size_t constrainedID, bool constrainedStatus) + { + _constrainedST[constrainedID]._constrainedNodes.push_back(constrainedStatus); + } + bool getConstrainedSTNode(std::size_t constrainedID, int position) const + { + return _constrainedST[constrainedID]._constrainedNodes[position]; + } + void setConstrainedSTNode(std::size_t constrainedID, bool node_status, int position) + { + _constrainedST[constrainedID]._constrainedNodes[position] = node_status; + } + std::size_t getNumberOfConstrainedSTNodes(std::size_t constrainedID) const + { + return _constrainedST[constrainedID]._constrainedNodes.size(); + } + int getConstrainedSTNodesIndex(int position) const { return _constrainedSTNodesIndices[position]; } + void setConstrainedSTNodesIndex(int st_node_index, int position) + { + _constrainedSTNodesIndices[position] = st_node_index; + } std::size_t getSTVectorGroup() const { return _st_vector_group; } void setSTVectorGroup(int group) { _st_vector_group = group; } - - const std::string& getFunctionName () const { return fct_name; } - int getFunctionMethod () const { return fct_method; } - - const std::vector& getPointsWithDistribedST () const { return PointsHaveDistribedBC; } + const std::string& getFunctionName() const { return fct_name; } + int getFunctionMethod() const { return fct_method; } + const std::vector& getPointsWithDistribedST() const { return PointsHaveDistribedBC; } const std::vector& getDistribedST() const { return DistribedBC; } - bool isAnalytical () const { return analytical; } - bool isPressureBoundaryCondition () const { return pressureBoundaryCondition; } - void SetPressureBoundaryConditionFlag (bool pBC) { pressureBoundaryCondition = pBC;} + bool isAnalytical() const { return analytical; } + bool isPressureBoundaryCondition() const { return pressureBoundaryCondition; } + void SetPressureBoundaryConditionFlag(bool pBC) { pressureBoundaryCondition = pBC; } double GetAnalyticalSolution(long location); - size_t getNumberOfTerms () const { return number_of_terms; } - void setMaxNumberOfTerms (size_t max_no_terms) { _max_no_terms = max_no_terms; } - void setNumberOfAnalyticalSolutions (size_t no_an_sol) { _no_an_sol = no_an_sol; } - double GetRelativeInterfacePermeability(CRFProcess* m_pcs, // JOD - double head, - long msh_node); + size_t getNumberOfTerms() const { return number_of_terms; } + void setMaxNumberOfTerms(size_t max_no_terms) { _max_no_terms = max_no_terms; } + void setNumberOfAnalyticalSolutions(size_t no_an_sol) { _no_an_sol = no_an_sol; } + double GetRelativeInterfacePermeability(CRFProcess* m_pcs, // JOD + double head, + long msh_node); bool channel, channel_width, air_breaking; double air_breaking_factor, air_breaking_capillaryPressure, air_closing_capillaryPressure; @@ -194,27 +210,23 @@ class CSourceTerm : public ProcessInfo, public GeoInfo, public DistributionInfo std::vector node_value_vector; std::vector node_renumber_vector; std::string tim_type_name; - std::string interpolation_method; //BG - int TimeInterpolation; //BG + std::string interpolation_method; // BG + int TimeInterpolation; // BG std::string pcs_type_name_cond; std::string pcs_pv_name_cond; - int getSubDomainIndex () const { return _sub_dom_idx; } - + int getSubDomainIndex() const { return _sub_dom_idx; } std::string fname; - double getTransferCoefficient() { return transfer_coefficient; } //TN - double getValueSurrounding() { return value_surrounding;} //TN - std::vector get_node_value_vectorArea(){ return node_value_vectorArea;} //TN + double getTransferCoefficient() { return transfer_coefficient; } // TN + double getValueSurrounding() { return value_surrounding; } // TN + std::vector get_node_value_vectorArea() { return node_value_vectorArea; } // TN + std::vector st_node_ids; - std::vector st_node_ids; - -private: // TF, KR +private: // TF, KR void ReadDistributionType(std::ifstream* st_file); - void ReadGeoType(std::ifstream* st_file, - const GEOLIB::GEOObjects& geo_obj, - const std::string& unique_name); + void ReadGeoType(std::ifstream* st_file, const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name); void CreateHistoryNodeMemory(NODE_HISTORY* nh); void DeleteHistoryNodeMemory(); @@ -226,7 +238,7 @@ class CSourceTerm : public ProcessInfo, public GeoInfo, public DistributionInfo */ bool _coupled; - double normaldepth_slope; // used only once in a global in rf_st_new + double normaldepth_slope; // used only once in a global in rf_st_new /// Subdomain index for excvation simulation // 14.12.2010. WW @@ -235,25 +247,25 @@ class CSourceTerm : public ProcessInfo, public GeoInfo, public DistributionInfo int fct_method; std::string fct_name; - LinearFunctionData* dis_linear_f; //24.8.2011. WW + LinearFunctionData* dis_linear_f; // 24.8.2011. WW - bool analytical; //2x? + bool analytical; // 2x? bool pressureBoundaryCondition; // pressure load boundary condition size_t number_of_terms; - size_t _max_no_terms; // used only once in a global in rf_st_new + size_t _max_no_terms; // used only once in a global in rf_st_new size_t _no_an_sol; - int analytical_material_group; // used only once in a global in rf_st_new - int resolution; // used only once in a global in rf_st_new - double analytical_diffusion; // used only once in a global in rf_st_new - double analytical_porosity; // used only once in a global in rf_st_new - double analytical_tortousity; // used only once in a global in rf_st_new + int analytical_material_group; // used only once in a global in rf_st_new + int resolution; // used only once in a global in rf_st_new + double analytical_diffusion; // used only once in a global in rf_st_new + double analytical_porosity; // used only once in a global in rf_st_new + double analytical_tortousity; // used only once in a global in rf_st_new double analytical_linear_sorption_Kd; // used only once in a global in rf_st_new - double analytical_matrix_density; // used only once in a global in rf_st_new + double analytical_matrix_density; // used only once in a global in rf_st_new double factor; - double transfer_coefficient; //TN - for DIS_TYPE TRANSFER_SURROUNDING - double value_surrounding; //TN - for DIS_TYPE TRANSFER_SURROUNDING + double transfer_coefficient; // TN - for DIS_TYPE TRANSFER_SURROUNDING + double value_surrounding; // TN - for DIS_TYPE TRANSFER_SURROUNDING std::string nodes_file; int msh_node_number; @@ -265,38 +277,37 @@ class CSourceTerm : public ProcessInfo, public GeoInfo, public DistributionInfo std::vector pnt_parameter_vector; // 03.2010. WW long start_pos_in_st; - double* GIS_shape_head; // 07.06.2010. WW + double* GIS_shape_head; // 07.06.2010. WW std::vector precip_times; std::vector precip_files; friend class CSourceTermGroup; - friend class process::CRFProcessDeformation; //WW - friend class ::CRFProcess; //WW + friend class process::CRFProcessDeformation; // WW + friend class ::CRFProcess; // WW std::string geo_name; double _coup_leakance; // including climate data into source terms - MathLib::InverseDistanceInterpolation *_distances; // NB - std::vector _weather_stations; //NB + MathLib::InverseDistanceInterpolation* _distances; // NB + std::vector _weather_stations; // NB bool _isConstrainedST; std::vector _constrainedST; - //std::vector _constrainedSTNodes; + // std::vector _constrainedSTNodes; std::vector _constrainedSTNodesIndices; std::size_t _st_vector_group; - }; class CSourceTermGroup { public: - CSourceTermGroup() //WW + CSourceTermGroup() // WW { } void Set(CRFProcess* m_pcs, const int ShiftInNodeVector, std::string this_pv_name = ""); - //WW std::vectorgroup_vector; + // WW std::vectorgroup_vector; /** * \brief process type for the physical process * possible values are @@ -315,25 +326,25 @@ class CSourceTermGroup * */ std::string pcs_name; - std::string pcs_type_name; //OK - std::string pcs_pv_name; //OK + std::string pcs_type_name; // OK + std::string pcs_pv_name; // OK MeshLib::CFEMesh* m_msh; MeshLib::CFEMesh* m_msh_cond; - //WW std::vectorst_group_vector; //OK - //WW double GetConditionalNODValue(int,CSourceTerm*); //OK - //WW double GetRiverNODValue(int,CSourceTerm*, long msh_node); //MB - //WW double GetCriticalDepthNODValue(int,CSourceTerm*, long msh_node); //MB - //WW double GetNormalDepthNODValue(int,CSourceTerm*, long msh_node); //MB JOD - //WW Changed from the above + // WW std::vectorst_group_vector; //OK + // WW double GetConditionalNODValue(int,CSourceTerm*); //OK + // WW double GetRiverNODValue(int,CSourceTerm*, long msh_node); //MB + // WW double GetCriticalDepthNODValue(int,CSourceTerm*, long msh_node); //MB + // WW double GetNormalDepthNODValue(int,CSourceTerm*, long msh_node); //MB JOD + // WW Changed from the above // double GetAnalyticalSolution(CSourceTerm *m_st,long node_number, std::string process);//CMCD // TRANSFER OF DUAL RICHARDS - std::string fct_name; //YD + std::string fct_name; // YD private: // JOD void SetPNT(CRFProcess* m_pcs, CSourceTerm* m_st, const int ShiftInNodeVector); // JOD void SetLIN(CRFProcess* m_pcs, CSourceTerm* m_st, const int ShiftInNodeVector); - //OK + // OK void SetPLY(CSourceTerm* st, int ShiftInNodeVector); // JOD void SetDMN(CSourceTerm* m_st, const int ShiftInNodeVector); @@ -343,11 +354,11 @@ class CSourceTermGroup void SetCOL(CSourceTerm* m_st, const int ShiftInNodeVector); // JOD -// void SetPolylineNodeVector(CGLPolyline* m_ply, std::vector&ply_nod_vector); + // void SetPolylineNodeVector(CGLPolyline* m_ply, std::vector&ply_nod_vector); void SetPolylineNodeVectorConditional(CSourceTerm* st, - std::vector&ply_nod_vector, - std::vector&ply_nod_vector_cond); + std::vector& ply_nod_vector, + std::vector& ply_nod_vector_cond); /** * 09/2010 TF @@ -359,9 +370,8 @@ class CSourceTermGroup std::vector& ply_nod_vector, std::vector& ply_nod_vector_cond); - void SetPolylineNodeValueVector(CSourceTerm* st, CGLPolyline * old_ply, - const std::vector& ply_nod_vector, - std::vector& ply_nod_vector_cond, std::vector& ply_nod_val_vector); + void SetPolylineNodeValueVector(CSourceTerm* st, CGLPolyline* old_ply, const std::vector& ply_nod_vector, + std::vector& ply_nod_vector_cond, std::vector& ply_nod_val_vector); /** * 09/2010 / 03/2011 TF @@ -371,25 +381,24 @@ class CSourceTermGroup * @param ply_nod_val_vector */ void SetPolylineNodeValueVector(CSourceTerm* st, - std::vector const & ply_nod_vector, - std::vector const & ply_nod_vector_cond, + std::vector const& ply_nod_vector, + std::vector const& ply_nod_vector_cond, std::vector& ply_nod_val_vector) const; // JOD - void SetSurfaceNodeVector(Surface* m_sfc, std::vector&sfc_nod_vector); - void SetSurfaceNodeVector(GEOLIB::Surface const* sfc, - std::vector & sfc_nod_vector); - void SetSurfaceNodeValueVector( CSourceTerm* m_st, - Surface* m_sfc, - std::vector const &sfc_nod_vector, - std::vector&sfc_nod_val_vector); + void SetSurfaceNodeVector(Surface* m_sfc, std::vector& sfc_nod_vector); + void SetSurfaceNodeVector(GEOLIB::Surface const* sfc, std::vector& sfc_nod_vector); + void SetSurfaceNodeValueVector(CSourceTerm* m_st, + Surface* m_sfc, + std::vector const& sfc_nod_vector, + std::vector& sfc_nod_val_vector); void AreaAssembly(const CSourceTerm* const st, const std::vector& ply_nod_vector_cond, - std::vector& ply_nod_val_vector) const; - void DistributeVolumeFlux(CSourceTerm* st, std::vector const & ply_nod_vector, // 5.3.07 - std::vector& ply_nod_val_vector); + std::vector& ply_nod_val_vector) const; + void DistributeVolumeFlux(CSourceTerm* st, std::vector const& ply_nod_vector, // 5.3.07 + std::vector& ply_nod_val_vector); }; -extern CSourceTermGroup* STGetGroup(std::string pcs_type_name,std::string pcs_pv_name); +extern CSourceTermGroup* STGetGroup(std::string pcs_type_name, std::string pcs_pv_name); extern std::list st_group_list; /** @@ -399,31 +408,29 @@ extern std::list st_group_list; * @param unique_name unique name to access the geometric entities in geo_obj * @return true if source terms found in file, else false */ -bool STRead(const std::string& file_base_name, - const GEOLIB::GEOObjects& geo_obj, - const std::string& unique_name); +bool STRead(const std::string& file_base_name, const GEOLIB::GEOObjects& geo_obj, const std::string& unique_name); extern void STWrite(std::string); #define ST_FILE_EXTENSION ".st" -//extern void STCreateFromPNT(); +// extern void STCreateFromPNT(); extern std::vector st_vector; extern void STDelete(); void STCreateFromLIN(std::vector); CSourceTerm* STGet(std::string); -extern void STGroupDelete(std::string pcs_type_name,std::string pcs_pv_name); -extern void STGroupsDelete(void); //Haibing; +extern void STGroupDelete(std::string pcs_type_name, std::string pcs_pv_name); +extern void STGroupsDelete(void); // Haibing; extern size_t aktueller_zeitschritt; extern double aktuelle_zeit; -extern std::vectoranalytical_processes; -//OK +extern std::vector analytical_processes; +// OK extern CSourceTerm* STGet(const std::string&, const std::string&, const std::string&); // WW moved here -//CMCD, WW +// CMCD, WW extern double GetAnalyticalSolution(long node_number, CSourceTerm* m_st); -//extern void GetRiverNODValue(double& value, CNodeValue* cnodev, const CSourceTerm* m_st); +// extern void GetRiverNODValue(double& value, CNodeValue* cnodev, const CSourceTerm* m_st); extern double GetConditionalNODValue(CSourceTerm* m_st, CNodeValue* cnodev); -//MB +// MB extern void GetCriticalDepthNODValue(double& value, CSourceTerm*, long msh_node); // JOD extern void GetCouplingNODValue(double& value, CSourceTerm* m_st, CNodeValue* cnodev); @@ -431,23 +438,19 @@ extern void GetCouplingNODValue(double& value, CSourceTerm* m_st, CNodeValue* cn extern void GetCouplingNODValueNewton(double& value, CSourceTerm* m_st, CNodeValue* cnodev); #if !defined(USE_PETSC) && !defined(NEW_EQS) // && defined(other parallel libs)//03~04.3012. WW //#ifndef NEW_EQS //WW. 06.11.2008 - //MB JOD +// MB JOD extern void GetNormalDepthNODValue(double& value, CSourceTerm*, long msh_node); // JOD extern void GetCouplingNODValuePicard(double& value, CSourceTerm* m_st, CNodeValue* cnodev); #endif // JOD -extern double CalcCouplingValue(double factor, - double h_this, - double h_cond, - double z_cond, - CSourceTerm* m_st); +extern double CalcCouplingValue(double factor, double h_this, double h_cond, double z_cond, CSourceTerm* m_st); // JOD extern void GetCouplingNODValueMixed(double& value, CSourceTerm* m_st, CNodeValue* cnodev); // JOD extern void GetCouplingFieldVariables(CRFProcess* m_pcs_this, CRFProcess* m_pcs_cond, - double* h_this, + double* h_this, double* h_cond, double* h_shifted, double* h_averaged, @@ -455,16 +458,16 @@ extern void GetCouplingFieldVariables(CRFProcess* m_pcs_this, double* z_cond, CSourceTerm* m_st, CNodeValue* cnodev, - long msh_node_number, - long msh_node_number_cond, - double gamma); + long msh_node_number, + long msh_node_number_cond, + double gamma); // JOD extern void GetPhilipNODValue(double& value, const CSourceTerm* m_st); // JOD extern void GetGreenAmptNODValue(double& value, CSourceTerm* m_st, long msh_node); // JOD -extern void GetNODValue(double& value, CNodeValue* cnodev,CSourceTerm* m_st); +extern void GetNODValue(double& value, CNodeValue* cnodev, CSourceTerm* m_st); -extern void GetNODHeatTransfer(double& value, CSourceTerm* st, long geo_node); //TN +extern void GetNODHeatTransfer(double& value, CSourceTerm* st, long geo_node); // TN #endif diff --git a/FEM/rf_tim_new.cpp b/FEM/rf_tim_new.cpp index 32a54b555..9b71e2c33 100644 --- a/FEM/rf_tim_new.cpp +++ b/FEM/rf_tim_new.cpp @@ -7,12 +7,12 @@ * */ - /************************************************************************** - FEMLib - Object: TIM - Task: - Programing: - 08/2004 OK Implementation - last modified: +/************************************************************************** + FEMLib - Object: TIM + Task: + Programing: + 08/2004 OK Implementation + last modified: **************************************************************************/ // C++ STL //#include @@ -35,54 +35,54 @@ #include "rfmat_cp.h" #include "tools.h" #include -//WW #include "elements.h" //set functions for stability criteria +// WW #include "elements.h" //set functions for stability criteria // ToDo double aktuelle_zeit; size_t aktueller_zeitschritt = 0; double dt = 0.0; -int rwpt_numsplits = -1; //JT 2010 +int rwpt_numsplits = -1; // JT 2010 //========================================================================== -std::vectortime_vector; +std::vector time_vector; /************************************************************************** FEMLib-Method: Task: OBJ constructor Programing: 08/2004 OK Implementation **************************************************************************/ -CTimeDiscretization::CTimeDiscretization(void) - : Write_tim_discrete(false),tim_discrete(NULL) //YD +CTimeDiscretization::CTimeDiscretization(void) : Write_tim_discrete(false), tim_discrete(NULL) // YD { step_current = 0; time_start = 0.0; time_end = 1.0; - time_type_name = "CONSTANT"; //OK - time_control_type = TimeControlType::INVALID; //kg44//JT + time_type_name = "CONSTANT"; // OK + time_control_type = TimeControlType::INVALID; // kg44//JT time_unit = "SECOND"; - max_time_step = 1.e10; //YD - min_time_step = DBL_EPSILON; //YD//JT Minimum allowed timestep, this process + max_time_step = 1.e10; // YD + min_time_step = DBL_EPSILON; // YD//JT Minimum allowed timestep, this process initial_step_size = 1; adapt_itr_type = IterationType::LINEAR; - repeat = false; //OK/YD - step_current = 0; //WW - this_stepsize = 0.; //WW - dt_sum = .0; //WW - relative_error = 1.e-4; //26.08.2008. WW - absolute_error = 1.e-10; //26.08.2008. WW - h_max = 6; //27.08.2008. WW - h_min = 0.2; //27.08.2008. WW - hacc = 0.; //27.08.2008. WW - erracc = 0.; //27.08.2008. WW - PI_tsize_ctrl_type = -1; //27.08.2008. WW - minimum_dt_reached = false; //JT - time_active = true; //JT - time_independence = false; //JT - dt_failure_reduction_factor = 1.0; //JT - accepted_step_count = 0; //JT - rejected_step_count = 0; //JT - last_active_time = 0.0; //JT - next_active_time = 0.0; //JT - dynamic_time_buffer = 0; //JT - for(size_t ii=0; iiclose(); - if(tim_discrete) + if (tim_discrete) delete tim_discrete; time_step_vector.clear(); time_adapt_tim_vector.clear(); @@ -114,32 +113,38 @@ CTimeDiscretization::~CTimeDiscretization(void) } } -std::ios::pos_type GetNextSubKeyword(std::ifstream* file,std::string* line, bool* keyword) +std::ios::pos_type GetNextSubKeyword(std::ifstream* file, std::string* line, bool* keyword) { char buffer[MAX_ZEILE]; std::ios::pos_type position; position = file->tellg(); *keyword = false; std::string line_complete; - int i,j; + int i, j; // Look for next subkeyword - while(!(line_complete.find("$") != std::string::npos) && (!file->eof())) + while (!(line_complete.find("$") != std::string::npos) && (!file->eof())) { - file->getline(buffer,MAX_ZEILE); + file->getline(buffer, MAX_ZEILE); line_complete = buffer; - if(line_complete.find("#") != std::string::npos) + if (line_complete.find("#") != std::string::npos) { *keyword = true; return position; } - //Anf�ngliche Leerzeichen �berlesen, i=Position des ersten Nichtleerzeichens im string - i = (int) line_complete.find_first_not_of(" ",0); - j = (int) line_complete.find(";",i); //Nach Kommentarzeichen ; suchen. j = Position des Kommentarzeichens, j=-1 wenn es keines gibt. - if(j < 0) + // Anf�ngliche Leerzeichen �berlesen, i=Position des ersten Nichtleerzeichens im string + i = (int)line_complete.find_first_not_of(" ", 0); + j = (int)line_complete.find( + ";", i); // Nach Kommentarzeichen ; suchen. j = Position des Kommentarzeichens, j=-1 wenn es keines gibt. + if (j < 0) j = (int)line_complete.length(); - //if(j!=i) break; //Wenn das erste nicht-leerzeichen ein Kommentarzeichen ist, zeile �berlesen. Sonst ist das eine Datenzeile - if(i != -1) - *line = line_complete.substr(i,j - i); //Ab erstem nicht-Leerzeichen bis Kommentarzeichen rauskopieren in neuen substring, falls Zeile nicht leer ist + // if(j!=i) break; //Wenn das erste nicht-leerzeichen ein Kommentarzeichen ist, zeile + // �berlesen. + // Sonst + // ist + // das eine Datenzeile + if (i != -1) + *line = line_complete.substr(i, j - i); // Ab erstem nicht-Leerzeichen bis Kommentarzeichen rauskopieren in + // neuen substring, falls Zeile nicht leer ist } return position; } @@ -169,22 +174,22 @@ std::ios::pos_type CTimeDiscretization::Read(std::ifstream* tim_file) std::ios::pos_type position_subkeyword; std::stringstream line; std::string line_complete; - int iter_times; //YD - double multiply_coef; //YD + int iter_times; // YD + double multiply_coef; // YD int i; CRFProcess* m_pcs = NULL; // m_pcs = PCSGet("RICHARDS_FLOW"); - m_pcs = PCSGet("GROUNDWATER_FLOW"); //kg44 changed default + m_pcs = PCSGet("GROUNDWATER_FLOW"); // kg44 changed default //======================================================================== // Schleife ueber alle Phasen bzw. Komponenten - while(!new_keyword) + while (!new_keyword) { - if(new_subkeyword) - tim_file->seekg(position,std::ios::beg); + if (new_subkeyword) + tim_file->seekg(position, std::ios::beg); new_subkeyword = false; - position = GetNextSubKeyword(tim_file,&line_string,&new_keyword); - if(new_keyword) + position = GetNextSubKeyword(tim_file, &line_string, &new_keyword); + if (new_keyword) return position; /* position = tim_file->tellg(); @@ -201,7 +206,7 @@ std::ios::pos_type CTimeDiscretization::Read(std::ifstream* tim_file) //.................................................................... // subkeyword found - if(line_string.find("$PCS_TYPE") != std::string::npos) + if (line_string.find("$PCS_TYPE") != std::string::npos) { line.str(GetLineFromFile1(tim_file)); line >> pcs_type_name; @@ -212,17 +217,17 @@ std::ios::pos_type CTimeDiscretization::Read(std::ifstream* tim_file) } //.................................................................... // subkeyword found - if(line_string.find("$TIME_START") != std::string::npos) + if (line_string.find("$TIME_START") != std::string::npos) { line.str(GetLineFromFile1(tim_file)); line >> time_start; - last_active_time=time_start; // JOD for GK 5.3.07 + last_active_time = time_start; // JOD for GK 5.3.07 line.clear(); continue; } //.................................................................... // subkeyword found - if(line_string.find("$TIME_END") != std::string::npos) + if (line_string.find("$TIME_END") != std::string::npos) { line.str(GetLineFromFile1(tim_file)); line >> time_end; @@ -231,14 +236,14 @@ std::ios::pos_type CTimeDiscretization::Read(std::ifstream* tim_file) } //.................................................................... // subkeyword found - if(line_string.find("$TIME_UNIT") != std::string::npos) + if (line_string.find("$TIME_UNIT") != std::string::npos) { - *tim_file >> time_unit >> std::ws; //WW unit of time + *tim_file >> time_unit >> std::ws; // WW unit of time continue; } //.................................................................... // subkeyword found - if(line_string.find("$INDEPENDENT") != std::string::npos) // JT2012 + if (line_string.find("$INDEPENDENT") != std::string::npos) // JT2012 { line.str(GetLineFromFile1(tim_file)); line >> time_independence; @@ -266,14 +271,14 @@ std::ios::pos_type CTimeDiscretization::Read(std::ifstream* tim_file) */ //.................................................................... // subkeyword found - if(line_string.find("$TIME_STEPS") != std::string::npos) - while((!new_keyword) || (!new_subkeyword) || (!tim_file->eof())) + if (line_string.find("$TIME_STEPS") != std::string::npos) + while ((!new_keyword) || (!new_subkeyword) || (!tim_file->eof())) { position = tim_file->tellg(); line_string = GetLineFromFile1(tim_file); - if(line_string.find("#") != std::string::npos) + if (line_string.find("#") != std::string::npos) return position; - if(line_string.find("$") != std::string::npos) + if (line_string.find("$") != std::string::npos) { new_subkeyword = true; break; @@ -281,12 +286,12 @@ std::ios::pos_type CTimeDiscretization::Read(std::ifstream* tim_file) line.str(line_string); line >> no_time_steps; line >> time_step_length; - for(i = 0; i < no_time_steps; i++) + for (i = 0; i < no_time_steps; i++) time_step_vector.push_back(time_step_length); line.clear(); } // subkeyword found - if(line_string.find("$TIME_SPLITS") != std::string::npos) + if (line_string.find("$TIME_SPLITS") != std::string::npos) { line.str(GetLineFromFile1(tim_file)); line >> rwpt_numsplits; @@ -294,14 +299,14 @@ std::ios::pos_type CTimeDiscretization::Read(std::ifstream* tim_file) continue; } // 25.08.2008. WW - if(line_string.find("$CRITICAL_TIME") != std::string::npos) - while((!new_keyword) || (!new_subkeyword) || (!tim_file->eof())) + if (line_string.find("$CRITICAL_TIME") != std::string::npos) + while ((!new_keyword) || (!new_subkeyword) || (!tim_file->eof())) { position = tim_file->tellg(); line_string = GetLineFromFile1(tim_file); - if(line_string.find("#") != std::string::npos) + if (line_string.find("#") != std::string::npos) return position; - if(line_string.find("$") != std::string::npos) + if (line_string.find("$") != std::string::npos) { new_subkeyword = true; break; @@ -313,15 +318,15 @@ std::ios::pos_type CTimeDiscretization::Read(std::ifstream* tim_file) line.clear(); } // subkeyword found - if(line_string.find("$TIME_CONTROL") != std::string::npos) - while((!new_keyword) || (!new_subkeyword) || (!tim_file->eof())) + if (line_string.find("$TIME_CONTROL") != std::string::npos) + while ((!new_keyword) || (!new_subkeyword) || (!tim_file->eof())) { position = tim_file->tellg(); line_string = GetLineFromFile1(tim_file); - if(line_string.find("#") != std::string::npos) + if (line_string.find("#") != std::string::npos) return position; - if(line_string.find("$") != std::string::npos) + if (line_string.find("$") != std::string::npos) { new_subkeyword = true; break; @@ -332,14 +337,13 @@ std::ios::pos_type CTimeDiscretization::Read(std::ifstream* tim_file) line.clear(); time_control_type = convertTimeControlType(time_control_name); - if(time_control_type == TimeControlType::PI_AUTO_STEP_SIZE) // 26.08.2008. WW + if (time_control_type == TimeControlType::PI_AUTO_STEP_SIZE) // 26.08.2008. WW { line.str(GetLineFromFile1(tim_file)); - line >> PI_tsize_ctrl_type >> relative_error >> - absolute_error >> this_stepsize; - //13.03.2008. WW + line >> PI_tsize_ctrl_type >> relative_error >> absolute_error >> this_stepsize; + // 13.03.2008. WW int real_type = (int)(PI_tsize_ctrl_type / 10); - if(real_type < 10 && real_type > 0) // + if (real_type < 10 && real_type > 0) // { PI_tsize_ctrl_type = real_type; line >> h_min >> h_max >> max_time_step; @@ -348,7 +352,7 @@ std::ios::pos_type CTimeDiscretization::Read(std::ifstream* tim_file) max_time_step = 0.0; line.clear(); } - else if(time_control_type == TimeControlType::DYNAMIC_VARIABLE) // JT2012 + else if (time_control_type == TimeControlType::DYNAMIC_VARIABLE) // JT2012 { // DYNAMIC TIME STEP SERIES line.str(GetLineFromFile1(tim_file)); @@ -356,21 +360,27 @@ std::ios::pos_type CTimeDiscretization::Read(std::ifstream* tim_file) double include_third_variable = -1.0; double third_variable_tolerance = -1.0; // - line >> dynamic_control_error_method; // Corresponds to FiniteElement::ErrorMethod. Defines how tolerance is applied. - line >> time_step_length; // initial_dt - line >> min_time_step; // min_dt - line >> dynamic_failure_threshold; // threshold to force a time failure (recommend 1.1-2.0. If tolerance is exceeeded on first iteration by this factor, dt will be decreased and a failure forced) - line >> dynamic_control_tolerance[DOF_NUMBER_MAX]; // max_increase_factor (dt never allowed to increase faster than this factor (i.e. 1.5) + line >> dynamic_control_error_method; // Corresponds to FiniteElement::ErrorMethod. Defines how + // tolerance is applied. + line >> time_step_length; // initial_dt + line >> min_time_step; // min_dt + line >> dynamic_failure_threshold; // threshold to force a time failure (recommend 1.1-2.0. If + // tolerance is exceeeded on first iteration by this factor, dt + // will be decreased and a failure forced) + line >> dynamic_control_tolerance[DOF_NUMBER_MAX]; // max_increase_factor (dt never allowed to + // increase faster than this factor (i.e. 1.5) // - // tolerances[1:dof]: One tolerance for each degree of freedom in process (or only one tolerance for certain methods) - switch(FiniteElement::convertErrorMethod(dynamic_control_error_method)) + // tolerances[1:dof]: One tolerance for each degree of freedom in process (or only one tolerance for + // certain methods) + switch (FiniteElement::convertErrorMethod(dynamic_control_error_method)) { case FiniteElement::ENORM: // only 1 tolerance required num_tolerances = 1; line >> dynamic_control_tolerance[0]; // // Next entry is OPTIONAL (may be left blank)! - line >> include_third_variable; // if >0.0, include a 3rd variable in the global norm (PwSnw model: Pc -- PcPnw model: Snw -- PwPnw model: Snw) + line >> include_third_variable; // if >0.0, include a 3rd variable in the global norm (PwSnw + // model: Pc -- PcPnw model: Snw -- PwPnw model: Snw) break; // case FiniteElement::ERNORM: // only 1 tolerance required @@ -378,23 +388,28 @@ std::ios::pos_type CTimeDiscretization::Read(std::ifstream* tim_file) line >> dynamic_control_tolerance[0]; // // Next entry is OPTIONAL (may be left blank)! - line >> include_third_variable; // if >0.0, include a 3rd variable in the global norm (PwSnw model: Pc -- PcPnw model: Snw -- PwPnw model: Snw) + line >> include_third_variable; // if >0.0, include a 3rd variable in the global norm (PwSnw + // model: Pc -- PcPnw model: Snw -- PwPnw model: Snw) break; // - case FiniteElement::EVNORM: // 1 tolerance for each primary variable (for Deformation, only 1 tolerance required. Applies to x,y,z) - for(int i=0; i> dynamic_control_tolerance[i]; // // Next entry is OPTIONAL (may be left blank)! - line >> third_variable_tolerance; // tolerance of a third variable (PwSnw model: Pc -- PcPnw model: Snw -- PwPnw model: Snw) + line >> third_variable_tolerance; // tolerance of a third variable (PwSnw model: Pc -- PcPnw + // model: Snw -- PwPnw model: Snw) break; // - case FiniteElement::LMAX: // 1 tolerance for each primary variable (for Deformation, only 1 tolerance required. Applies to x,y,z) - for(int i=0; i> dynamic_control_tolerance[i]; // // Next entry is OPTIONAL (may be left blank)! - line >> third_variable_tolerance; // tolerance of a third variable (PwSnw model: Pc -- PcPnw model: Snw -- PwPnw model: Snw) + line >> third_variable_tolerance; // tolerance of a third variable (PwSnw model: Pc -- PcPnw + // model: Snw -- PwPnw model: Snw) break; // case FiniteElement::BNORM: @@ -404,100 +419,109 @@ std::ios::pos_type CTimeDiscretization::Read(std::ifstream* tim_file) break; // default: - ScreenMessage("ERROR in TIMRead. Invalid error method selected for dynamic time control.\n"); + ScreenMessage( + "ERROR in TIMRead. Invalid error method selected for dynamic time control.\n"); exit(1); break; } // - if(num_tolerances > 1) + if (num_tolerances > 1) dynamic_control_tolerance[DOF_NUMBER_MAX] = third_variable_tolerance; else dynamic_control_tolerance[DOF_NUMBER_MAX] = include_third_variable; line.clear(); } - else if(time_control_type == TimeControlType::DYNAMIC_COURANT) // JT2012 + else if (time_control_type == TimeControlType::DYNAMIC_COURANT) // JT2012 { - std::cout<<"Josh apologizes (especially to Marc), but promises DYNAMIC_COURANT will be merged into the next release."<<"\n"; - std::cout<<"emoticon:: sad face"<<"\n"; + std::cout << "Josh apologizes (especially to Marc), but promises DYNAMIC_COURANT will be merged " + "into the next release." + << "\n"; + std::cout << "emoticon:: sad face" + << "\n"; exit(1); // // DYNAMIC TIME STEP SERIES line.str(GetLineFromFile1(tim_file)); // - line >> time_step_length; // initial_dt - line >> min_time_step; // min_dt - line >> dynamic_control_tolerance[DOF_NUMBER_MAX]; // max_increase_factor (dt never allowed to increase faster than this factor (i.e. 1.5) - line >> dynamic_control_tolerance[0]; // desired courant number + line >> time_step_length; // initial_dt + line >> min_time_step; // min_dt + line >> dynamic_control_tolerance[DOF_NUMBER_MAX]; // max_increase_factor (dt never allowed to + // increase faster than this factor (i.e. 1.5) + line >> dynamic_control_tolerance[0]; // desired courant number // // ADDITIONAL OPTIONS TO RESTRICT CALCULATION TO CERTAIN ELEMENTS - if(time_control_name.find("CONCENTRATION") != std::string::npos){ // DYNAMIC_COURANT_CONCENTRATION - line >> dynamic_control_tolerance[1]; // Concentration threshold (elements with concentration beneath this value are not included in Courant restriction) + if (time_control_name.find("CONCENTRATION") != std::string::npos) + { // DYNAMIC_COURANT_CONCENTRATION + line >> dynamic_control_tolerance[1]; // Concentration threshold (elements with concentration + // beneath this value are not included in Courant + // restriction) } - else if(time_control_name.find("TEMPERATURE") != std::string::npos){// DYNAMIC_COURANT_TEMPERATURE - line >> dynamic_control_tolerance[1]; // Temperature threshold (elements with temperature BENEATH this value are not included in Courant restriction) - line >> dynamic_control_tolerance[2]; // Temperature threshold (elements with temperature ABOVE this value are not included in Courant restriction) + else if (time_control_name.find("TEMPERATURE") != std::string::npos) + { // DYNAMIC_COURANT_TEMPERATURE + line >> dynamic_control_tolerance[1]; // Temperature threshold (elements with temperature + // BENEATH this value are not included in Courant + // restriction) + line >> dynamic_control_tolerance[2]; // Temperature threshold (elements with temperature ABOVE + // this value are not included in Courant restriction) } // line.clear(); } - else if(time_control_type == TimeControlType::DYNAMIC_PRESSURE) // JT2012 + else if (time_control_type == TimeControlType::DYNAMIC_PRESSURE) // JT2012 { // DYNAMIC TIME STEP SERIES line.str(GetLineFromFile1(tim_file)); // - line >> time_step_length; // initial_dt - line >> min_time_step; // min_dt - line >> dynamic_control_tolerance[DOF_NUMBER_MAX]; // max_increase_factor (dt never allowed to increase faster than this factor (i.e. 1.5) - line >> dynamic_control_tolerance[0]; // pressure tolerance (mean pressure) + line >> time_step_length; // initial_dt + line >> min_time_step; // min_dt + line >> dynamic_control_tolerance[DOF_NUMBER_MAX]; // max_increase_factor (dt never allowed to + // increase faster than this factor (i.e. 1.5) + line >> dynamic_control_tolerance[0]; // pressure tolerance (mean pressure) // line.clear(); } - else if(time_control_type == TimeControlType::STEP_SIZE_RESTRICTION) // 26.08.2008. WW + else if (time_control_type == TimeControlType::STEP_SIZE_RESTRICTION) // 26.08.2008. WW { line.str(GetLineFromFile1(tim_file)); line >> h_min >> h_max; line.clear(); } - else if(time_control_type == TimeControlType::NEUMANN){ + else if (time_control_type == TimeControlType::NEUMANN) + { line.clear(); } - else if(time_control_type == TimeControlType::ERROR_CONTROL_ADAPTIVE) + else if (time_control_type == TimeControlType::ERROR_CONTROL_ADAPTIVE) { m_pcs->adaption = true; line.clear(); } - else if(time_control_type == TimeControlType::SELF_ADAPTIVE - || time_control_type == TimeControlType::STABLE_ERROR_ADAPTIVE) + else if (time_control_type == TimeControlType::SELF_ADAPTIVE + || time_control_type == TimeControlType::STABLE_ERROR_ADAPTIVE) { - //m_pcs->adaption = true; JOD removed - //WW minish = 10; - while((!new_keyword) || (!new_subkeyword) || - (!tim_file->eof())) + // m_pcs->adaption = true; JOD removed + // WW minish = 10; + while ((!new_keyword) || (!new_subkeyword) || (!tim_file->eof())) { position = tim_file->tellg(); line_string = GetLineFromFile1(tim_file); - if(line_string.find("#") != std::string::npos) + if (line_string.find("#") != std::string::npos) return position; - if(line_string.find("$") != std::string::npos) + if (line_string.find("$") != std::string::npos) { new_subkeyword = true; break; } - if(line_string.find("MAX_TIME_STEP") != - std::string::npos) + if (line_string.find("MAX_TIME_STEP") != std::string::npos) { *tim_file >> line_string; - max_time_step = strtod( - line_string.data(),NULL); + max_time_step = strtod(line_string.data(), NULL); line.clear(); // kg44 should not break break; } - else if(line_string.find("MIN_TIME_STEP") != - std::string::npos) + else if (line_string.find("MIN_TIME_STEP") != std::string::npos) { *tim_file >> line_string; - min_time_step = strtod( - line_string.data(),NULL); + min_time_step = strtod(line_string.data(), NULL); line.clear(); // kg44 should not break break; } @@ -508,45 +532,45 @@ std::ios::pos_type CTimeDiscretization::Read(std::ifstream* tim_file) line.clear(); } */ - else if(line_string.find("INITIAL_STEP_SIZE") != - std::string::npos) + else if (line_string.find("INITIAL_STEP_SIZE") != std::string::npos) { *tim_file >> line_string; - initial_step_size = strtod( - line_string.data(),NULL); + initial_step_size = strtod(line_string.data(), NULL); line.clear(); } - else if(line_string.find("ITERATIVE_TYPE") != - std::string::npos) + else if (line_string.find("ITERATIVE_TYPE") != std::string::npos) { *tim_file >> line_string; adapt_itr_type = convertIterationType(line_string); - if (line_string == "COUPLED_STABLE_ERROR") // convertIterationType() finds IterationType::COUPLED if that is part of the name... very unpractical. + if (line_string == "COUPLED_STABLE_ERROR") // convertIterationType() finds + // IterationType::COUPLED if that is part of the + // name... very unpractical. adapt_itr_type = IterationType::COUPLED_STABLE_ERROR; line.clear(); } - else if(line_string.find("STAY") != - std::string::npos) + else if (line_string.find("STAY") != std::string::npos) { *tim_file >> line_string; - stay_steps_after_rejection = strtod(line_string.data(),NULL); + stay_steps_after_rejection = strtod(line_string.data(), NULL); line.clear(); } - else if(line_string.find("MULTIPLIER") != std::string::npos - || (!line_string.empty() && isdigit(line_string[0]))) + else if (line_string.find("MULTIPLIER") != std::string::npos + || (!line_string.empty() && isdigit(line_string[0]))) { - if (line_string.find("MULTIPLIER") != std::string::npos) { + if (line_string.find("MULTIPLIER") != std::string::npos) + { position = tim_file->tellg(); line_string = GetLineFromFile1(tim_file); } - while(!tim_file->eof()) + while (!tim_file->eof()) { line.str(line_string); line >> iter_times; line >> multiply_coef; - if (line.fail()) { - tim_file->seekg(position,std::ios::beg); + if (line.fail()) + { + tim_file->seekg(position, std::ios::beg); line.clear(); break; } @@ -557,37 +581,36 @@ std::ios::pos_type CTimeDiscretization::Read(std::ifstream* tim_file) position = tim_file->tellg(); line_string = GetLineFromFile1(tim_file); } - if (time_adapt_tim_vector.size()<2) { - std::cout << "ERROR: at least two multipliers should be provided for SELF_ADAPTIVE time stepping" << std::endl; + if (time_adapt_tim_vector.size() < 2) + { + std::cout << "ERROR: at least two multipliers should be provided for SELF_ADAPTIVE " + "time stepping" + << std::endl; exit(1); } } - else if (line_string.find("DESIRED_ERROR") != - std::string::npos) + else if (line_string.find("DESIRED_ERROR") != std::string::npos) { *tim_file >> line_string; - desired_error = strtod(line_string.data(),NULL); + desired_error = strtod(line_string.data(), NULL); line.clear(); } - else if (line_string.find("MAX_INCREASE") != - std::string::npos) + else if (line_string.find("MAX_INCREASE") != std::string::npos) { *tim_file >> line_string; - max_increase = strtod(line_string.data(),NULL); + max_increase = strtod(line_string.data(), NULL); line.clear(); } - else if (line_string.find("MIN_INCREASE") != - std::string::npos) + else if (line_string.find("MIN_INCREASE") != std::string::npos) { *tim_file >> line_string; - min_increase = strtod(line_string.data(),NULL); + min_increase = strtod(line_string.data(), NULL); line.clear(); } - else if (line_string.find("DAMPENING") != - std::string::npos) + else if (line_string.find("DAMPENING") != std::string::npos) { *tim_file >> line_string; - dampening = strtod(line_string.data(),NULL); + dampening = strtod(line_string.data(), NULL); line.clear(); } else @@ -597,13 +620,14 @@ std::ios::pos_type CTimeDiscretization::Read(std::ifstream* tim_file) exit(1); } } // end of while loop adaptive - // end of if "SELF_ADAPTIVE" + // end of if "SELF_ADAPTIVE" } - else{ + else + { ScreenMessage("ERROR: Unrecognized time control type.\n"); exit(1); } - } // end of while + } // end of while // end of "TIME_CONTROL" //.................................................................... /* //WW @@ -613,7 +637,7 @@ std::ios::pos_type CTimeDiscretization::Read(std::ifstream* tim_file) } */ //.................................................................... - } // end of while(!new_keyword) + } // end of while(!new_keyword) return position; } @@ -629,7 +653,7 @@ std::ios::pos_type CTimeDiscretization::Read(std::ifstream* tim_file) bool TIMRead(std::string file_base_name) { //---------------------------------------------------------------------- - //OK TIMDelete(); + // OK TIMDelete(); //---------------------------------------------------------------------- CTimeDiscretization* m_tim = NULL; char line[MAX_ZEILE]; @@ -639,43 +663,44 @@ bool TIMRead(std::string file_base_name) //======================================================================== // File handling std::string tim_file_name = file_base_name + TIM_FILE_EXTENSION; - std::ifstream tim_file (tim_file_name.data(),std::ios::in); + std::ifstream tim_file(tim_file_name.data(), std::ios::in); if (!tim_file.good()) return false; - tim_file.seekg(0L,std::ios::beg); + tim_file.seekg(0L, std::ios::beg); //======================================================================== // Keyword loop - std::cout << "TIMRead" << "\n"; + std::cout << "TIMRead" + << "\n"; while (!tim_file.eof()) { - tim_file.getline(line,MAX_ZEILE); + tim_file.getline(line, MAX_ZEILE); line_string = line; - if(line_string.find("#STOP") != std::string::npos) + if (line_string.find("#STOP") != std::string::npos) return true; //---------------------------------------------------------------------- // keyword found - if(line_string.find("#TIME_STEPPING") != std::string::npos) + if (line_string.find("#TIME_STEPPING") != std::string::npos) { m_tim = new CTimeDiscretization(); position = m_tim->Read(&tim_file); m_tim->time_current = m_tim->time_start; //---------------------------------------------------------------------- - if(m_tim->Write_tim_discrete) //YD Write out Time Steps & Iterations + if (m_tim->Write_tim_discrete) // YD Write out Time Steps & Iterations { std::string m_file_name = file_base_name + "_TimeDiscrete.txt"; - m_tim->tim_discrete = new std::fstream( - m_file_name.c_str(),std::ios::trunc | std::ios::out); - std::fstream* tim_dis = m_tim->tim_discrete; - *tim_dis << " No. Time Tim-Disc Iter" << "\n"; + m_tim->tim_discrete = new std::fstream(m_file_name.c_str(), std::ios::trunc | std::ios::out); + std::fstream* tim_dis = m_tim->tim_discrete; + *tim_dis << " No. Time Tim-Disc Iter" + << "\n"; if (!m_tim->tim_discrete->good()) - std::cout << - "Warning : Time-Discrete files are not found" << "\n"; + std::cout << "Warning : Time-Discrete files are not found" + << "\n"; } //---------------------------------------------------------------------- time_vector.push_back(m_tim); - tim_file.seekg(position,std::ios::beg); - } // keyword found - } // eof + tim_file.seekg(position, std::ios::beg); + } // keyword found + } // eof return true; } @@ -688,7 +713,7 @@ bool TIMRead(std::string file_base_name) void TIMWrite(std::string base_file_name) { //---------------------------------------------------------------------- - if((int)time_vector.size() < 1) + if ((int)time_vector.size() < 1) return; //---------------------------------------------------------------------- CTimeDiscretization* m_tim = NULL; @@ -697,16 +722,16 @@ void TIMWrite(std::string base_file_name) //======================================================================== // File handling std::string tim_file_name = base_file_name + TIM_FILE_EXTENSION; - std::fstream tim_file (tim_file_name.data(),std::ios::trunc | std::ios::out); - tim_file.setf(std::ios::scientific,std::ios::floatfield); + std::fstream tim_file(tim_file_name.data(), std::ios::trunc | std::ios::out); + tim_file.setf(std::ios::scientific, std::ios::floatfield); tim_file.precision(12); if (!tim_file.good()) return; - tim_file.seekg(0L,std::ios::beg); + tim_file.seekg(0L, std::ios::beg); //======================================================================== // OUT vector tim_file << "GeoSys-TIM: ------------------------------------------------\n"; - for(int i = 0; i < (int)time_vector.size(); i++) + for (int i = 0; i < (int)time_vector.size(); i++) { m_tim = time_vector[i]; m_tim->Write(&tim_file); @@ -725,43 +750,49 @@ void CTimeDiscretization::Write(std::fstream* tim_file) int i; //-------------------------------------------------------------------- // KEYWORD - *tim_file << "#TIME_STEPPING" << "\n"; + *tim_file << "#TIME_STEPPING" + << "\n"; //-------------------------------------------------------------------- // PCS_TYPE - *tim_file << " $PCS_TYPE" << "\n"; + *tim_file << " $PCS_TYPE" + << "\n"; *tim_file << " " << pcs_type_name << "\n"; //-------------------------------------------------------------------- - *tim_file << " $TIME_START" << "\n"; + *tim_file << " $TIME_START" + << "\n"; *tim_file << " " << time_start << "\n"; //-------------------------------------------------------------------- - *tim_file << " $TIME_END" << "\n"; + *tim_file << " $TIME_END" + << "\n"; *tim_file << " " << time_end << "\n"; //-------------------------------------------------------------------- - if(time_control_type == TimeControlType::FIXED_STEPS) + if (time_control_type == TimeControlType::FIXED_STEPS) { - *tim_file << " $TIME_STEPS" << "\n"; - for(i = 0; i < (int)time_step_vector.size(); i++) + *tim_file << " $TIME_STEPS" + << "\n"; + for (i = 0; i < (int)time_step_vector.size(); i++) *tim_file << " " << 1 << " " << time_step_vector[i] << "\n"; } else { - *tim_file << " $TIME_CONTROL" << "\n"; + *tim_file << " $TIME_CONTROL" + << "\n"; *tim_file << " " << convertTimeControlTypeToString(time_control_type) << std::endl; -// if(time_control_name == "COURANT_MANIPULATE") -// { -// *tim_file << " " << time_control_name << std::endl; -// *tim_file << " " << time_control_manipulate << std::endl; -// } - if(time_control_type == TimeControlType::PI_AUTO_STEP_SIZE) + // if(time_control_name == "COURANT_MANIPULATE") + // { + // *tim_file << " " << time_control_name << std::endl; + // *tim_file << " " << time_control_manipulate << std::endl; + // } + if (time_control_type == TimeControlType::PI_AUTO_STEP_SIZE) { - *tim_file << " " << PI_tsize_ctrl_type << " " << relative_error << " " << - absolute_error << " " << this_stepsize << "\n"; + *tim_file << " " << PI_tsize_ctrl_type << " " << relative_error << " " << absolute_error << " " + << this_stepsize << "\n"; } - else if(time_control_type == TimeControlType::STEP_SIZE_RESTRICTION) + else if (time_control_type == TimeControlType::STEP_SIZE_RESTRICTION) { *tim_file << " " << h_min << " " << h_max << std::endl; } - else if(time_control_type == TimeControlType::SELF_ADAPTIVE) + else if (time_control_type == TimeControlType::SELF_ADAPTIVE) { *tim_file << " MAX_TIME_STEP " << max_time_step << "\n"; *tim_file << " MIM_TIME_STEP " << min_time_step << "\n"; @@ -786,54 +817,69 @@ double CTimeDiscretization::CalcTimeStep(double current_time) // // TIME STEP VECTOR // ----------------------------------- - if(no_time_steps > 0){ + if (no_time_steps > 0) + { time_step_length = time_step_vector[0]; - if(step_current < no_time_steps) + if (step_current < no_time_steps) time_step_length = time_step_vector[step_current]; } // // TIME CONTROL METHODS // ----------------------------------- - if(time_control_type == TimeControlType::NEUMANN || time_control_type == TimeControlType::SELF_ADAPTIVE){ - if(aktuelle_zeit < MKleinsteZahl && repeat == false){ + if (time_control_type == TimeControlType::NEUMANN || time_control_type == TimeControlType::SELF_ADAPTIVE) + { + if (aktuelle_zeit < MKleinsteZahl && repeat == false) + { time_step_length = FirstTimeStepEstimate(); } - else if( time_control_type == TimeControlType::NEUMANN){ + else if (time_control_type == TimeControlType::NEUMANN) + { time_step_length = NeumannTimeControl(); } - else if(time_control_type == TimeControlType::SELF_ADAPTIVE){ + else if (time_control_type == TimeControlType::SELF_ADAPTIVE) + { time_step_length = SelfAdaptiveTimeControl(); } } - else if(time_control_type == TimeControlType::STABLE_ERROR_ADAPTIVE){ - time_step_length = StableErrorAdaptive(); + else if (time_control_type == TimeControlType::STABLE_ERROR_ADAPTIVE) + { + time_step_length = StableErrorAdaptive(); } - else if(time_control_type == TimeControlType::ERROR_CONTROL_ADAPTIVE){ - if(aktuelle_zeit < MKleinsteZahl){ + else if (time_control_type == TimeControlType::ERROR_CONTROL_ADAPTIVE) + { + if (aktuelle_zeit < MKleinsteZahl) + { time_step_length = AdaptiveFirstTimeStepEstimate(); } - else{ + else + { time_step_length = ErrorControlAdaptiveTimeControl(); } } - else if(time_control_type == TimeControlType::PI_AUTO_STEP_SIZE){ + else if (time_control_type == TimeControlType::PI_AUTO_STEP_SIZE) + { time_step_length = this_stepsize; } - else if(time_control_type == TimeControlType::DYNAMIC_COURANT - || time_control_type == TimeControlType::DYNAMIC_PRESSURE - || time_control_type == TimeControlType::DYNAMIC_VARIABLE){ // JT2012: Soon to come. - if(!last_dt_accepted){ + else if (time_control_type == TimeControlType::DYNAMIC_COURANT + || time_control_type == TimeControlType::DYNAMIC_PRESSURE + || time_control_type == TimeControlType::DYNAMIC_VARIABLE) + { // JT2012: Soon to come. + if (!last_dt_accepted) + { time_step_length *= dt_failure_reduction_factor; dynamic_minimum_suggestion = time_step_length; } - else if(accepted_step_count > 1){ // initial time step is otherwise maintained for first 2 active time steps + else if (accepted_step_count > 1) + { // initial time step is otherwise maintained for first 2 active time steps } } - else if(no_time_steps==0){ // Processes without time control + else if (no_time_steps == 0) + { // Processes without time control time_step_length = DBL_MAX; // Large, thus other processes will control the step } // Restrict by minimum - if(time_step_length < min_time_step){ // Default value of min_time_step is DBL_EPSILON, unless entered otherwise in the .tim read + if (time_step_length < min_time_step) + { // Default value of min_time_step is DBL_EPSILON, unless entered otherwise in the .tim read time_step_length = min_time_step; } // JT: the recommended time step, before critical alteration (for dt control) @@ -842,21 +888,27 @@ double CTimeDiscretization::CalcTimeStep(double current_time) // WW. Critical time match (JT2012 modified) // ------------------------------------------------------ - for(int i = 0; i < (int)critical_time.size(); i++) + for (int i = 0; i < (int)critical_time.size(); i++) { - if(current_time < critical_time[i]) + if (current_time < critical_time[i]) { next = current_time + time_step_length; - tval = next + time_step_length/1.0e3; // JT2012. A tiny increase in dt is better than a miniscule dt on the next step - if(tval > critical_time[i]){ // Critical time is hit - if(next != critical_time[i]){ // otherwise, match is already exact + tval = next + + time_step_length + / 1.0e3; // JT2012. A tiny increase in dt is better than a miniscule dt on the next step + if (tval > critical_time[i]) + { // Critical time is hit + if (next != critical_time[i]) + { // otherwise, match is already exact time_step_length = (critical_time[i] - current_time); } break; } - else if(tval + time_step_length > critical_time[i]){ // We can hit the critical time in 2 time steps, smooth the transition - if(next + time_step_length != critical_time[i]){ // otherwise, match is already exact - time_step_length = (critical_time[i] - current_time)/2.0; + else if (tval + time_step_length > critical_time[i]) + { // We can hit the critical time in 2 time steps, smooth the transition + if (next + time_step_length != critical_time[i]) + { // otherwise, match is already exact + time_step_length = (critical_time[i] - current_time) / 2.0; } break; } @@ -887,7 +939,7 @@ CTimeDiscretization::CTimeDiscretization(const CTimeDiscretization& a_tim, std:: time_control_manipulate = a_tim.time_control_manipulate; step_current = a_tim.step_current; repeat = a_tim.repeat; - pcs_type_name = pcsname; // by argument + pcs_type_name = pcsname; // by argument time_type_name = a_tim.time_type_name; time_control_type = a_tim.time_control_type; time_unit = a_tim.time_unit; @@ -904,16 +956,16 @@ CTimeDiscretization::CTimeDiscretization(const CTimeDiscretization& a_tim, std:: time_independence = false; time_active = true; last_active_time = 0.0; - next_active_time = 0.0; //JT + next_active_time = 0.0; // JT // time_step_vector.clear(); time_adapt_tim_vector.clear(); time_adapt_coe_vector.clear(); - for(i = 0; i < (int)a_tim.time_step_vector.size(); i++) + for (i = 0; i < (int)a_tim.time_step_vector.size(); i++) time_step_vector.push_back(a_tim.time_step_vector[i]); - for(i = 0; i < (int)a_tim.time_adapt_tim_vector.size(); i++) + for (i = 0; i < (int)a_tim.time_adapt_tim_vector.size(); i++) time_adapt_tim_vector.push_back(a_tim.time_adapt_tim_vector[i]); - for(i = 0; i < (int)a_tim.time_adapt_coe_vector.size(); i++) + for (i = 0; i < (int)a_tim.time_adapt_coe_vector.size(); i++) time_adapt_coe_vector.push_back(a_tim.time_adapt_coe_vector[i]); } @@ -924,16 +976,16 @@ CTimeDiscretization::CTimeDiscretization(const CTimeDiscretization& a_tim, std:: 12/2004 OK Implementation last modified: **************************************************************************/ -//kg44 const string gave trouble for me -CTimeDiscretization* TIMGet(const std::string &pcs_type_name) +// kg44 const string gave trouble for me +CTimeDiscretization* TIMGet(const std::string& pcs_type_name) { CTimeDiscretization* m_tim = NULL; int i; int no_times = (int)time_vector.size(); - for(i = 0; i < no_times; i++) + for (i = 0; i < no_times; i++) { m_tim = time_vector[i]; - if(m_tim->pcs_type_name.compare(pcs_type_name) == 0) + if (m_tim->pcs_type_name.compare(pcs_type_name) == 0) return time_vector[i]; } return NULL; @@ -950,7 +1002,7 @@ void TIMDelete() { long i; int no_tim = (int)time_vector.size(); - for(i = 0; i < no_tim; i++) + for (i = 0; i < no_tim; i++) delete time_vector[i]; time_vector.clear(); } @@ -967,12 +1019,12 @@ void TIMDelete(std::string pcs_type_name) long i; CTimeDiscretization* m_tim = NULL; int no_tim = (int)time_vector.size(); - for(i = 0; i < no_tim; i++) + for (i = 0; i < no_tim; i++) { m_tim = TIMGet(pcs_type_name); - if(!m_tim) //OK + if (!m_tim) // OK continue; - if(m_tim->pcs_type_name.compare(pcs_type_name) == 0) + if (m_tim->pcs_type_name.compare(pcs_type_name) == 0) { delete time_vector[i]; time_vector.erase(time_vector.begin() + i); @@ -996,11 +1048,11 @@ double CTimeDiscretization::FirstTimeStepEstimate(void) double GP[3]; static double Node_Sat[8]; double buffer; - //WW int no_time_steps; - //WW int no_processes =(int)pcs_vector.size(); -// CFluidProperties* m_mfp = NULL; // 2012-08 TF not used -// m_mfp = MFPGet("LIQUID"); //WW -// double density_fluid = m_mfp->Density(); //WW // TF: set, but never used + // WW int no_time_steps; + // WW int no_processes =(int)pcs_vector.size(); + // CFluidProperties* m_mfp = NULL; // 2012-08 TF not used + // m_mfp = MFPGet("LIQUID"); //WW + // double density_fluid = m_mfp->Density(); //WW // TF: set, but never used const double initial_time_step = std::max(initial_step_size, min_time_step); @@ -1013,107 +1065,117 @@ double CTimeDiscretization::FirstTimeStepEstimate(void) // switch (m_pcs->pcs_type_name[0]) { switch (m_pcs->getProcessType()) // TF { - // case 'G': // kg44 groudnwater flow ---if steady state, time step should be greater zero...transient flow does not work with adaptive stepping - case FiniteElement::GROUNDWATER_FLOW: // TF, if steady state, time step should be greater zero...transient flow does not work with adaptive stepping - case FiniteElement::LIQUID_FLOW: // TF, if steady state, time step should be greater zero...transient flow does not work with adaptive stepping - time_step_length = initial_time_step; // take min time step as conservative best guess for testing - break; - // case 'M': // kg44 Mass transport ---if steady state, time step should be greater zero.. - case FiniteElement::HEAT_TRANSPORT: //MW copied from MASS_TRANSPORT // TF, if steady state, time step should be greater zero.. - case FiniteElement::MASS_TRANSPORT: // TF, if steady state, time step should be greater zero.. - time_step_length = initial_time_step; // take min time step as conservative best guess for testing - if(time_control_type == TimeControlType::SELF_ADAPTIVE) //MW - { - // time step will be reduced in an exponential way until min_time_step. - time_step_length = pow( time_adapt_coe_vector[time_adapt_coe_vector.size() - 1] , (double)rejected_step_count ) * initial_step_size; + // case 'G': // kg44 groudnwater flow ---if steady state, time step should be greater zero...transient + // flow does not work with adaptive stepping + case FiniteElement::GROUNDWATER_FLOW: // TF, if steady state, time step should be greater zero...transient + // flow does not work with adaptive stepping + case FiniteElement::LIQUID_FLOW: // TF, if steady state, time step should be greater zero...transient flow + // does not work with adaptive stepping + time_step_length = initial_time_step; // take min time step as conservative best guess for testing + break; + // case 'M': // kg44 Mass transport ---if steady state, time step should be greater zero.. + case FiniteElement::HEAT_TRANSPORT: // MW copied from MASS_TRANSPORT // TF, if steady state, time step + // should be greater zero.. + case FiniteElement::MASS_TRANSPORT: // TF, if steady state, time step should be greater zero.. + time_step_length = initial_time_step; // take min time step as conservative best guess for testing + if (time_control_type == TimeControlType::SELF_ADAPTIVE) // MW + { + // time step will be reduced in an exponential way until min_time_step. + time_step_length + = pow(time_adapt_coe_vector[time_adapt_coe_vector.size() - 1], (double)rejected_step_count) + * initial_step_size; - if (time_step_length < min_time_step) { - std::cout << "-> ***ERROR*** Next time step size is less than the given minimum size. The simulation is aborted." << std::endl; - exit(1); + if (time_step_length < min_time_step) + { + std::cout << "-> ***ERROR*** Next time step size is less than the given minimum size. The " + "simulation is aborted." + << std::endl; + exit(1); + } } - } - break; - // case 'R': // Richards - case FiniteElement::RICHARDS_FLOW: // TF - { - idxS = m_pcs->GetNodeValueIndex("SATURATION1"); - //WW no_time_steps = 1000000000; //OK (int)(1.0e10); - time_step_length = 1.e10; - size_t mmp_vector_size = mmp_vector.size(); - for (size_t m = 0; m < mmp_vector_size; m++) - m_mmp = mmp_vector[m]; - const size_t size (m_pcs->m_msh->ele_vector.size()); - for (size_t i = 0; i < size; i++) + break; + // case 'R': // Richards + case FiniteElement::RICHARDS_FLOW: // TF { - elem = m_pcs->m_msh->ele_vector[i]; - if (elem->GetMark()) // Element selected + idxS = m_pcs->GetNodeValueIndex("SATURATION1"); + // WW no_time_steps = 1000000000; //OK (int)(1.0e10); + time_step_length = 1.e10; + size_t mmp_vector_size = mmp_vector.size(); + for (size_t m = 0; m < mmp_vector_size; m++) + m_mmp = mmp_vector[m]; + const size_t size(m_pcs->m_msh->ele_vector.size()); + for (size_t i = 0; i < size; i++) { - // Activated Element - group = elem->GetPatchIndex(); - m_mmp = mmp_vector[group]; - m_mmp->m_pcs = m_pcs; - MshElemType::type EleType = elem->GetElementType(); - // Triangle - if (EleType == MshElemType::TRIANGLE) + elem = m_pcs->m_msh->ele_vector[i]; + if (elem->GetMark()) // Element selected { - GP[0] = GP[1] = 0.1 / 0.3; - GP[2] = 0.0; + // Activated Element + group = elem->GetPatchIndex(); + m_mmp = mmp_vector[group]; + m_mmp->m_pcs = m_pcs; + MshElemType::type EleType = elem->GetElementType(); + // Triangle + if (EleType == MshElemType::TRIANGLE) + { + GP[0] = GP[1] = 0.1 / 0.3; + GP[2] = 0.0; + } + else if (EleType == MshElemType::TETRAHEDRON) + GP[0] = GP[1] = GP[2] = 0.25; + else + GP[0] = GP[1] = GP[2] = 0.0; } - else if (EleType == MshElemType::TETRAHEDRON) - GP[0] = GP[1] = GP[2] = 0.25; - else - GP[0] = GP[1] = GP[2] = 0.0; + const int vertex_number(elem->GetVertexNumber()); + for (int j = 0; j < vertex_number; j++) + Node_Sat[j] = m_pcs->GetNodeValue(elem->GetNodeIndex(j), idxS); + // JT: dSdP now returns actual sign (<0) + buffer = -m_mmp->PressureSaturationDependency(fem->interpolate(Node_Sat), + true); // JT: now returns correct sign. + buffer *= 0.5 * elem->GetVolume() * elem->GetVolume(); + buffer + *= m_mmp->porosity_model_values[0] * mfp_vector[0]->Viscosity() / m_mmp->permeability_tensor[0]; + buffer /= m_pcs->time_unit_factor; + time_step_length = MMin(time_step_length, buffer); + } // ele_vector + + if (time_control_type == TimeControlType::SELF_ADAPTIVE) // MW + { + // if (rejected_step_count==0) + // time_step_length=ini_time_step; + // else + // { + time_step_length + = pow(time_adapt_coe_vector[time_adapt_coe_vector.size() - 1], (double)rejected_step_count) + * initial_step_size; + + if (time_step_length <= min_time_step) + { + std::cout << "-> ***ERROR*** Next time step size is less than or equal to the given minimum " + "size. The simulation is aborted." + << std::endl; + exit(1); + } + // } } - const int vertex_number (elem->GetVertexNumber()); - for (int j = 0; j < vertex_number; j++) - Node_Sat[j] = m_pcs->GetNodeValue(elem->GetNodeIndex(j), - idxS); - // JT: dSdP now returns actual sign (<0) - buffer = -m_mmp->PressureSaturationDependency(fem->interpolate(Node_Sat),true); //JT: now returns correct sign. - buffer *= 0.5 * elem->GetVolume() * elem->GetVolume(); - buffer *= m_mmp->porosity_model_values[0] - * mfp_vector[0]->Viscosity() - / m_mmp->permeability_tensor[0]; - buffer /= m_pcs->time_unit_factor; - time_step_length = MMin(time_step_length, buffer); - } // ele_vector - - if(time_control_type == TimeControlType::SELF_ADAPTIVE) //MW - { - // if (rejected_step_count==0) - // time_step_length=ini_time_step; - // else - // { - time_step_length = pow( time_adapt_coe_vector[time_adapt_coe_vector.size() - 1] , (double)rejected_step_count ) * initial_step_size; - if (time_step_length<=min_time_step) + if (time_step_length < MKleinsteZahl) { - std::cout << "-> ***ERROR*** Next time step size is less than or equal to the given minimum size. The simulation is aborted." << std::endl; - exit(1); + std::cout << "Warning : Time Control Step Wrong, dt = 0.0 " + << "\n"; + time_step_length = 1.e-6; } - // } - } - - if (time_step_length < MKleinsteZahl) - { - std::cout << "Warning : Time Control Step Wrong, dt = 0.0 " << - "\n"; - time_step_length = 1.e-6; + std::cout << "Neumann Time Step: " << time_step_length << "\n"; + time_step_length_neumann = 1.e10; + time_step_length = MMin(time_step_length, max_time_step); + if (Write_tim_discrete) + *tim_discrete << aktueller_zeitschritt << " " << aktuelle_zeit << " " << time_step_length << " " + << m_pcs->iter_lin << "\n"; + break; } - std::cout << "Neumann Time Step: " << time_step_length << "\n"; - time_step_length_neumann = 1.e10; - time_step_length = MMin(time_step_length, max_time_step); - if (Write_tim_discrete) - *tim_discrete << aktueller_zeitschritt << " " << aktuelle_zeit - << " " << time_step_length << " " << - m_pcs->iter_lin - << "\n"; - break; - } - default: - std::cout << "CTimeDiscretization::FirstTimeStepEstimate default case" << - "\n"; - break; + default: + std::cout << "CTimeDiscretization::FirstTimeStepEstimate default case" + << "\n"; + break; } } return time_step_length; @@ -1128,117 +1190,131 @@ double CTimeDiscretization::FirstTimeStepEstimate(void) double CTimeDiscretization::DynamicVariableTimeControl(void) { long node, gnodes; - int ii, idx0, idx1, idx[DOF_NUMBER_MAX+1]; - double error, tol, delta, edof, val, ndof, nerror, dof_error[DOF_NUMBER_MAX+1]; + int ii, idx0, idx1, idx[DOF_NUMBER_MAX + 1]; + double error, tol, delta, edof, val, ndof, nerror, dof_error[DOF_NUMBER_MAX + 1]; double suggested_time_step_change, suggested_time_step; - CRFProcess *m_pcs = PCSGet(pcs_type_name); + CRFProcess* m_pcs = PCSGet(pcs_type_name); int num_variables = m_pcs->GetDOF(); gnodes = (long)m_pcs->m_msh->GetNodesNumber(false); error = nerror = 0.0; // // Indices of primaries - for(ii=0; iiGetNodeValueIndex(m_pcs->pcs_primary_function_name[ii]); } // Is a third variable wished to be controlled (and is this allowed) - if(dynamic_control_tolerance[DOF_NUMBER_MAX] > 0.0 && m_pcs->isPCSMultiFlow){ - if(m_pcs->getProcessType() == FiniteElement::MULTI_PHASE_FLOW) + if (dynamic_control_tolerance[DOF_NUMBER_MAX] > 0.0 && m_pcs->isPCSMultiFlow) + { + if (m_pcs->getProcessType() == FiniteElement::MULTI_PHASE_FLOW) idx[num_variables] = m_pcs->GetNodeValueIndex("SATURATION2"); else idx[num_variables] = m_pcs->GetNodeValueIndex("PRESSURE2"); // - dynamic_control_tolerance[num_variables] = dynamic_control_tolerance[DOF_NUMBER_MAX]; // shift to 3rd variable slot + dynamic_control_tolerance[num_variables] + = dynamic_control_tolerance[DOF_NUMBER_MAX]; // shift to 3rd variable slot num_variables++; } // // Get error - switch(FiniteElement::convertErrorMethod(dynamic_control_error_method)) + switch (FiniteElement::convertErrorMethod(dynamic_control_error_method)) { default: return 0.0; // case FiniteElement::LMAX: // "LMAX" - for(ii=0; iiGetNodeValue(node,idx1) - m_pcs->GetNodeValue(node,idx0)) / tol; - edof = MMax(edof,delta); + for (node = 0; node < gnodes; node++) + { + delta = fabs(m_pcs->GetNodeValue(node, idx1) - m_pcs->GetNodeValue(node, idx0)) / tol; + edof = MMax(edof, delta); } - error = MMax(error,edof); + error = MMax(error, edof); dof_error[ii] = edof; } - break; + break; // case FiniteElement::ENORM: // Error of global norm (single tolerance) tol = dynamic_control_tolerance[0]; // - for(ii=0; iiGetNodeValue(node,idx1) - m_pcs->GetNodeValue(node,idx0); - edof += delta*delta; + for (node = 0; node < gnodes; node++) + { + delta = m_pcs->GetNodeValue(node, idx1) - m_pcs->GetNodeValue(node, idx0); + edof += delta * delta; } error += edof; dof_error[ii] = sqrt(edof) / tol; } error = sqrt(error) / tol; - break; + break; // case FiniteElement::EVNORM: // Error of global norm (DOF specific tolerance) - for(ii=0; iiGetNodeValue(node,idx1) - m_pcs->GetNodeValue(node,idx0); - edof += delta*delta; + for (node = 0; node < gnodes; node++) + { + delta = m_pcs->GetNodeValue(node, idx1) - m_pcs->GetNodeValue(node, idx0); + edof += delta * delta; } - dof_error[ii] = sqrt(edof)/tol; - error = MMax(error,dof_error[ii]); + dof_error[ii] = sqrt(edof) / tol; + error = MMax(error, dof_error[ii]); } - break; + break; // case FiniteElement::ERNORM: // Error of relative global norm (single tolerance) tol = dynamic_control_tolerance[0]; ndof = 0.0; // - for(ii=0; iiGetNodeValue(node,idx1); - delta = val - m_pcs->GetNodeValue(node,idx0); - edof += delta*delta; - ndof += val*val; + for (node = 0; node < gnodes; node++) + { + val = m_pcs->GetNodeValue(node, idx1); + delta = val - m_pcs->GetNodeValue(node, idx0); + edof += delta * delta; + ndof += val * val; } - error += edof; + error += edof; nerror += ndof; - dof_error[ii] = (sqrt(edof)/(sqrt(ndof)+DBL_EPSILON)) / tol; + dof_error[ii] = (sqrt(edof) / (sqrt(ndof) + DBL_EPSILON)) / tol; } - error = (sqrt(error)/(sqrt(nerror)+DBL_EPSILON)) / tol; - break; + error = (sqrt(error) / (sqrt(nerror) + DBL_EPSILON)) / tol; + break; } // Get suggested time step - if(error < DBL_EPSILON) error = DBL_EPSILON; - suggested_time_step_change = time_step_length*(1.0 / error - 1.0); + if (error < DBL_EPSILON) + error = DBL_EPSILON; + suggested_time_step_change = time_step_length * (1.0 / error - 1.0); suggested_time_step = suggested_time_step_change + time_step_length; // std::cout << "Dynamic Variable suggested time step: " << suggested_time_step << "\n"; - if(num_variables>1){ - for(ii=0; ii 1) + { + for (ii = 0; ii < num_variables; ii++) + { + edof = time_step_length + time_step_length * (1.0 / dof_error[ii] - 1.0); std::cout << "--> For DOF #: " << ii << " suggested time step is: " << edof << "\n"; } } @@ -1260,30 +1336,33 @@ double CTimeDiscretization::DynamicTimeSmoothing(double suggested_time_step_chan int number_of_time_steps_to_smooth = 2; // ddt = fabs(suggested_time_step_change); - val = 1.0 - ddt/(time_step_length + ddt); // how different is the suggestion from the current value + val = 1.0 - ddt / (time_step_length + ddt); // how different is the suggestion from the current value // - if(suggested_time_step_change>0.0) // increase suggested in dt (take at least 1% but not more than 50%) - val = MRange(0.01,val,0.5); - else // decrease suggested in dt (take at least 20% but not more than 90%) - val = MRange(0.2,val,0.9); - time_step = ddt*val + time_step_length; // the suggested time step (after weighting) + if (suggested_time_step_change > 0.0) // increase suggested in dt (take at least 1% but not more than 50%) + val = MRange(0.01, val, 0.5); + else // decrease suggested in dt (take at least 20% but not more than 90%) + val = MRange(0.2, val, 0.9); + time_step = ddt * val + time_step_length; // the suggested time step (after weighting) // Buffer the time step change over "number_of_time_steps_to_smooth" time steps (taking the worst case) dynamic_time_buffer++; - if(dynamic_time_buffer == 1) // Not yet tested 2 steps + if (dynamic_time_buffer == 1) // Not yet tested 2 steps dynamic_minimum_suggestion = time_step; else - dynamic_minimum_suggestion = MMin(time_step,dynamic_minimum_suggestion); + dynamic_minimum_suggestion = MMin(time_step, dynamic_minimum_suggestion); - if(dynamic_time_buffer < number_of_time_steps_to_smooth){ - time_step = recommended_time_step; // recommended_time_step is the m_tim variable of last suggested time step before any critical changes + if (dynamic_time_buffer < number_of_time_steps_to_smooth) + { + time_step = recommended_time_step; // recommended_time_step is the m_tim variable of last suggested time step + // before any critical changes } - else{ + else + { dynamic_time_buffer = 0; // reset time_step = dynamic_minimum_suggestion; // do not allow to increase faster than this user input factor // note, minimum time step is checked in CalcTimeStep() - time_step = MMin(time_step, recommended_time_step*dynamic_control_tolerance[DOF_NUMBER_MAX]); + time_step = MMin(time_step, recommended_time_step * dynamic_control_tolerance[DOF_NUMBER_MAX]); } return time_step; } @@ -1305,20 +1384,21 @@ double CTimeDiscretization::NeumannTimeControl(void) // case 'R': // Richards switch (m_pcs->getProcessType()) // TF { - case FiniteElement::RICHARDS_FLOW: - time_step_length = time_step_length_neumann; - break; - default: - std::cout << "Fatal error: No valid PCS type" << "\n"; - break; + case FiniteElement::RICHARDS_FLOW: + time_step_length = time_step_length_neumann; + break; + default: + std::cout << "Fatal error: No valid PCS type" + << "\n"; + break; } } std::cout << "Neumann Time Step: " << time_step_length << "\n"; time_step_length_neumann = 1.e10; if (Write_tim_discrete) - *tim_discrete << aktueller_zeitschritt << " " << aktuelle_zeit - << " " << time_step_length << " " << m_pcs->iter_lin << "\n"; + *tim_discrete << aktueller_zeitschritt << " " << aktuelle_zeit << " " << time_step_length << " " + << m_pcs->iter_lin << "\n"; return time_step_length; } @@ -1328,37 +1408,42 @@ double CTimeDiscretization::NeumannTimeControl(void) Programing: 04/2015 MW Implementation **************************************************************************/ -double CTimeDiscretization::StableErrorAdaptive ( void ) +double CTimeDiscretization::StableErrorAdaptive(void) { - CRFProcess* m_pcs = NULL; - const FiniteElement::ProcessType pcs_type (FiniteElement::convertProcessType (pcs_type_name)); + const FiniteElement::ProcessType pcs_type(FiniteElement::convertProcessType(pcs_type_name)); double current_error(0); for (size_t n_p = 0; n_p < pcs_vector.size(); n_p++) { - if (pcs_vector[n_p]->getProcessType() == pcs_type) { + if (pcs_vector[n_p]->getProcessType() == pcs_type) + { m_pcs = pcs_vector[n_p]; - if (!m_pcs) { // does this ever trigger? + if (!m_pcs) + { // does this ever trigger? ScreenMessage("-> ERROR in StableErrorAdaptive: PCS not found\n"); - //ScreenMessage("-> ERROR in " + convertTimeControlTypeToString(time_control_type).c_str() + ": PCS not found\n"); //why is this not possible? + // ScreenMessage("-> ERROR in " + convertTimeControlTypeToString(time_control_type).c_str() + ": PCS not + // found\n"); //why is this not possible? return 0.0; } - if (adapt_itr_type==IterationType::LINEAR || adapt_itr_type==IterationType::NONLINEAR) { + if (adapt_itr_type == IterationType::LINEAR || adapt_itr_type == IterationType::NONLINEAR) + { current_error = m_pcs->nls_max_relative_error; std::cout << "### Warning in " << convertTimeControlTypeToString(time_control_type) - << ": ITERATIVE_TYPE not \"COUPLED\"! \n" - << "### Time control " << convertTimeControlTypeToString(time_control_type) - << " not tested for other ITERATIVE_TYPES, use with caution. \n"; - } else if (adapt_itr_type==IterationType::COUPLED) { + << ": ITERATIVE_TYPE not \"COUPLED\"! \n" + << "### Time control " << convertTimeControlTypeToString(time_control_type) + << " not tested for other ITERATIVE_TYPES, use with caution. \n"; + } + else if (adapt_itr_type == IterationType::COUPLED) + { current_error = m_pcs->cpl_max_relative_error_overall; } else { std::cout << "### ERROR in " << convertTimeControlTypeToString(time_control_type) - << ": ITERATIVE_TYPE neither \"LINEAR\", \"NONLINEAR\" nor \"COUPLED\"! \n"; + << ": ITERATIVE_TYPE neither \"LINEAR\", \"NONLINEAR\" nor \"COUPLED\"! \n"; return 0.0; } } @@ -1368,25 +1453,26 @@ double CTimeDiscretization::StableErrorAdaptive ( void ) last_time_step_length = time_step_length; double multiplier(1); - if ( aktueller_zeitschritt == 0 ) + if (aktueller_zeitschritt == 0) { - //check validity of given parameters on very first time step - if ( (rejected_step_count < 1) && SEA_parameters_are_bad() ) + // check validity of given parameters on very first time step + if ((rejected_step_count < 1) && SEA_parameters_are_bad()) return 0; - //determine parameters of exponential function + // determine parameters of exponential function SEA_calc_parameters(); - //warning if nearly linear + // warning if nearly linear if (SEA_c < 1.2) { - std::cout << "\n" << pcs_type_name << " " << convertTimeControlTypeToString(time_control_type) - << ": The calculated base is pretty close to 1 (" << SEA_c << "), \n" - << " which will result in a nearly linear relation between time step size and error.\n" - << " -> You may want to increase MAX_INCREASE or MIN_INCREASE, or decrease DESIRED_ERROR.\n"; + std::cout << "\n" + << pcs_type_name << " " << convertTimeControlTypeToString(time_control_type) + << ": The calculated base is pretty close to 1 (" << SEA_c << "), \n" + << " which will result in a nearly linear relation between time step size and error.\n" + << " -> You may want to increase MAX_INCREASE or MIN_INCREASE, or decrease DESIRED_ERROR.\n"; } - //return multiplier for first time step + // return multiplier for first time step if (!repeat) time_step_length = last_time_step_length = initial_step_size; else @@ -1394,13 +1480,13 @@ double CTimeDiscretization::StableErrorAdaptive ( void ) multiplier = min_increase; } } - else //return multiplier for not first time step + else // return multiplier for not first time step { if (!repeat) { // calculating multiplier based on last error // multiplier = SEA_a+SEA_b/SEA_c^(error-desired_error) - multiplier = SEA_a+SEA_b/(std::pow(SEA_c,(current_error-desired_error))); + multiplier = SEA_a + SEA_b / (std::pow(SEA_c, (current_error - desired_error))); } else { @@ -1412,7 +1498,7 @@ double CTimeDiscretization::StableErrorAdaptive ( void ) time_step_length *= multiplier; // add dampening if selected, time step not repeated, and not first time step - if ( (dampening != 0) && !(repeat) && (aktueller_zeitschritt != 0) ) + if ((dampening != 0) && !(repeat) && (aktueller_zeitschritt != 0)) time_step_length = (time_step_length * dampening + last_time_step_length) / (dampening + 1); // check limits of time step size @@ -1420,66 +1506,68 @@ double CTimeDiscretization::StableErrorAdaptive ( void ) time_step_length = std::max(time_step_length, min_time_step); // screen output - std::cout << "\n" << pcs_type_name << " " << convertTimeControlTypeToString(time_control_type) - << " suggest " << ( (time_step_length / last_time_step_length > 1) ? "increasing" : "decreasing") - << " time step size with multiplier " << time_step_length / last_time_step_length << "." - << "\n"; + std::cout << "\n" + << pcs_type_name << " " << convertTimeControlTypeToString(time_control_type) << " suggest " + << ((time_step_length / last_time_step_length > 1) ? "increasing" : "decreasing") + << " time step size with multiplier " << time_step_length / last_time_step_length << "." + << "\n"; - if ( Write_tim_discrete ) - *tim_discrete << aktueller_zeitschritt << " " << aktuelle_zeit - << " " << time_step_length << "\n"; + if (Write_tim_discrete) + *tim_discrete << aktueller_zeitschritt << " " << aktuelle_zeit << " " << time_step_length << "\n"; return time_step_length; - } -bool CTimeDiscretization::SEA_parameters_are_bad( void ) +bool CTimeDiscretization::SEA_parameters_are_bad(void) { - //check on minima/maxima and relations of read parameters + // check on minima/maxima and relations of read parameters bool check(false); - if ( !(min_increase < 1) ) + if (!(min_increase < 1)) { - std::cout << "\n" << pcs_type_name << " " << convertTimeControlTypeToString(time_control_type) - << ": MIN_INCREASE must be < 1!\n"; - check=true; + std::cout << "\n" + << pcs_type_name << " " << convertTimeControlTypeToString(time_control_type) + << ": MIN_INCREASE must be < 1!\n"; + check = true; } - if ( !(max_increase > 1) ) + if (!(max_increase > 1)) { - std::cout << "\n" << pcs_type_name << " " << convertTimeControlTypeToString(time_control_type) - << ": MAX_INCREASE must be > 1!\n"; - check=true; + std::cout << "\n" + << pcs_type_name << " " << convertTimeControlTypeToString(time_control_type) + << ": MAX_INCREASE must be > 1!\n"; + check = true; } - if ( !(desired_error > 0) || !(desired_error < 1) ) + if (!(desired_error > 0) || !(desired_error < 1)) { - std::cout << "\n" << pcs_type_name << " " << convertTimeControlTypeToString(time_control_type) - << ": DESIRED_ERROR must be 0 < error < 1!\n"; - check=true; + std::cout << "\n" + << pcs_type_name << " " << convertTimeControlTypeToString(time_control_type) + << ": DESIRED_ERROR must be 0 < error < 1!\n"; + check = true; } - //determine parameters of y = m*x + n with points (desired_error, 1) & (1, min_increase) + // determine parameters of y = m*x + n with points (desired_error, 1) & (1, min_increase) // m = dy/dx - double const m ( (min_increase - 1) / (1 - desired_error) ); - double const n ( 1 - m*desired_error ); + double const m((min_increase - 1) / (1 - desired_error)); + double const n(1 - m * desired_error); - //check that n < max_increase - if( !(n= max_increase = " << max_increase << "! \n"; + check = true; + std::cout << "\n" + << pcs_type_name << " " << convertTimeControlTypeToString(time_control_type) + << ": MAX_INCREASE must be greater than \"n\" of y=m*x+n that is given through the two points \n" + << " ( DESIRED_ERROR, 1 ) & ( 1, MIN_INCREASE ) \n" + << " ( " << desired_error << ", 1 ) & ( 1, " << min_increase << " ), \n" + << " but it is currently n = " << n << " >= max_increase = " << max_increase << "! \n"; } return check; } - -void CTimeDiscretization::SEA_calc_parameters( void ) +void CTimeDiscretization::SEA_calc_parameters(void) { SEA_c = SEA_zbrent(1e-10); - SEA_b = ( max_increase - 1 ) / ( std::pow (SEA_c, desired_error) - 1 ); + SEA_b = (max_increase - 1) / (std::pow(SEA_c, desired_error) - 1); SEA_a = 1 - SEA_b; } @@ -1487,18 +1575,19 @@ void CTimeDiscretization::SEA_calc_parameters( void ) double CTimeDiscretization::SEA_zbrent(const double tol) { const int ITMAX = 100; - const double EPS = 5.0e-16; //numeric_limits::epsilon(); - //double fa=func(a),fb=func(b); - double fa,fb; - double fc,p,q,r,s,tol1,xm; - double x1=1.001; - double x2=100000; - - double a = x1,b = x2,c = x2,d = 0.0,e = 0.0; //OK411 - fa = SEA_func(x1); //lower interval - fb = SEA_func(x2); //upper interval - - if ((fa > 0.0 && fb > 0.0) || (fa < 0.0 && fb < 0.0)) //cout << "Error in zbrent, fluid " << fluid << " T: " << TT << " P: " << PP << " b: " << b << "\n"; + const double EPS = 5.0e-16; // numeric_limits::epsilon(); + // double fa=func(a),fb=func(b); + double fa, fb; + double fc, p, q, r, s, tol1, xm; + double x1 = 1.001; + double x2 = 100000; + + double a = x1, b = x2, c = x2, d = 0.0, e = 0.0; // OK411 + fa = SEA_func(x1); // lower interval + fb = SEA_func(x2); // upper interval + + if ((fa > 0.0 && fb > 0.0) || (fa < 0.0 && fb < 0.0)) // cout << "Error in zbrent, fluid " << fluid << " T: " << TT + // << " P: " << PP << " b: " << b << "\n"; std::cout << "."; fc = fb; for (int iter = 0; iter < ITMAX; iter++) @@ -1518,7 +1607,7 @@ double CTimeDiscretization::SEA_zbrent(const double tol) fb = fc; fc = fa; } - tol1 = 2.0* EPS* fabs(b) + 0.5 * tol; + tol1 = 2.0 * EPS * fabs(b) + 0.5 * tol; xm = 0.5 * (c - b); if (fabs(xm) <= tol1 || fb == 0.0) return b; @@ -1563,7 +1652,7 @@ double CTimeDiscretization::SEA_zbrent(const double tol) if (fabs(d) > tol1) b += d; else - b += SEA_SIGN(tol1,xm); //OK411 + b += SEA_SIGN(tol1, xm); // OK411 fb = SEA_func(b); } throw("Maximum number of iterations exceeded in zbrent"); @@ -1571,10 +1660,9 @@ double CTimeDiscretization::SEA_zbrent(const double tol) double CTimeDiscretization::SEA_func(double const c) { - return std::pow(c,1-desired_error)*(max_increase-min_increase)+c*(min_increase-1)-max_increase+1; + return std::pow(c, 1 - desired_error) * (max_increase - min_increase) + c * (min_increase - 1) - max_increase + 1; } - // copied and modified from eos.cpp SIGN() inline double CTimeDiscretization::SEA_SIGN(const double a, const float b) { @@ -1589,11 +1677,11 @@ inline double CTimeDiscretization::SEA_SIGN(const double a, const float b) 03/2008 HS KG Implementation for Groundwater flow and mass transport 10/2010 KG updates **************************************************************************/ -double CTimeDiscretization::SelfAdaptiveTimeControl ( void ) +double CTimeDiscretization::SelfAdaptiveTimeControl(void) { - // First calculate maximum time step according to Neumann and Courant criteria +// First calculate maximum time step according to Neumann and Courant criteria #ifdef GEM_REACT - const double my_max_time_step = MMin(max_time_step,MaxTimeStep()); + const double my_max_time_step = MMin(max_time_step, MaxTimeStep()); std::cout << "Self_Adaptive Time Step: max time step " << my_max_time_step << "\n"; #else const double my_max_time_step = max_time_step; @@ -1602,22 +1690,28 @@ double CTimeDiscretization::SelfAdaptiveTimeControl ( void ) // get iteration number int n_itr = 0; CRFProcess* m_pcs = NULL; - const FiniteElement::ProcessType pcs_type (FiniteElement::convertProcessType (pcs_type_name)); + const FiniteElement::ProcessType pcs_type(FiniteElement::convertProcessType(pcs_type_name)); for (size_t n_p = 0; n_p < pcs_vector.size(); n_p++) { - if (pcs_vector[n_p]->getProcessType() == pcs_type) { + if (pcs_vector[n_p]->getProcessType() == pcs_type) + { m_pcs = pcs_vector[n_p]; - if (adapt_itr_type==IterationType::LINEAR) { + if (adapt_itr_type == IterationType::LINEAR) + { n_itr = std::max(n_itr, m_pcs->iter_lin_max); - } else if (adapt_itr_type==IterationType::NONLINEAR) { + } + else if (adapt_itr_type == IterationType::NONLINEAR) + { n_itr = std::max(n_itr, m_pcs->iter_nlin_max); - } else if (adapt_itr_type==IterationType::COUPLED - || adapt_itr_type==IterationType::COUPLED_STABLE_ERROR) { + } + else if (adapt_itr_type == IterationType::COUPLED || adapt_itr_type == IterationType::COUPLED_STABLE_ERROR) + { n_itr = m_pcs->iter_outer_cpl + 1; } } } - if (!m_pcs) { + if (!m_pcs) + { ScreenMessage("-> ERROR in SelfAdaptiveTimeControl(): PCS not found\n"); return 0.0; } @@ -1626,30 +1720,36 @@ double CTimeDiscretization::SelfAdaptiveTimeControl ( void ) double multiplier = 1.0; if (!time_adapt_coe_vector.empty()) multiplier = time_adapt_coe_vector.back(); - for (std::size_t i=0; icpl_max_relative_error); - if (inverse_error < 2*multiplier) + if (adapt_itr_type == IterationType::COUPLED_STABLE_ERROR) + { + double const inverse_error(1 / m_pcs->cpl_max_relative_error); + if (inverse_error < 2 * multiplier) { double const old_multiplier(multiplier); - multiplier = inverse_error*0.5*0.9; - std::cout << "Adapting multiplier to " << multiplier - << " instead of " << old_multiplier << std::endl; + multiplier = inverse_error * 0.5 * 0.9; + std::cout << "Adapting multiplier to " << multiplier << " instead of " << old_multiplier << std::endl; } } - if (!m_pcs->accepted) { + if (!m_pcs->accepted) + { multiplier = time_adapt_coe_vector.back(); - } else if (stay_steps_after_rejection > 0 && multiplier > 1.0) { + } + else if (stay_steps_after_rejection > 0 && multiplier > 1.0) + { // don't increase time step size if a simulation has experienced rejection recently double consecutive_successful_steps = aktueller_zeitschritt - last_rejected_timestep; - if (consecutive_successful_steps <= stay_steps_after_rejection) { + if (consecutive_successful_steps <= stay_steps_after_rejection) + { multiplier = 1.0; std::cout << "Time step size will not be increased because of rejection experienced in last time steps. \n"; } @@ -1661,33 +1761,31 @@ double CTimeDiscretization::SelfAdaptiveTimeControl ( void ) time_step_length = std::max(time_step_length, min_time_step); #if defined(USE_PETSC) -// synchronice time step size between processes - PetscScalar *gtimp; //used for pointer - PetscReal tresult; - PETSc_Vec gtim; // - PetscInt count; - VecCreate(PETSC_COMM_WORLD, >im); - VecSetSizes(gtim, 1,PETSC_DECIDE); // only one value per mpi-process - VecSetFromOptions(gtim); // - // get range of local variables - VecGetLocalSize(gtim, &count); // reuse count - // get local part of vectors - VecGetArray(gtim, >imp); - gtimp[0]=time_step_length; // assign value...as we have only one value this should work - VecMin(gtim,PETSC_NULL,&tresult); //get minimum value - time_step_length= tresult; // assign to time step size + // synchronice time step size between processes + PetscScalar* gtimp; // used for pointer + PetscReal tresult; + PETSc_Vec gtim; // + PetscInt count; + VecCreate(PETSC_COMM_WORLD, >im); + VecSetSizes(gtim, 1, PETSC_DECIDE); // only one value per mpi-process + VecSetFromOptions(gtim); // + // get range of local variables + VecGetLocalSize(gtim, &count); // reuse count + // get local part of vectors + VecGetArray(gtim, >imp); + gtimp[0] = time_step_length; // assign value...as we have only one value this should work + VecMin(gtim, PETSC_NULL, &tresult); // get minimum value + time_step_length = tresult; // assign to time step size #endif - std::cout << "Self_Adaptive time step size: " << - time_step_length << " max iterations: " << n_itr << "\n"; - if ( Write_tim_discrete ) - *tim_discrete << aktueller_zeitschritt << " " << aktuelle_zeit << " " << - time_step_length << " " << m_pcs->iter_lin << "\n"; + std::cout << "Self_Adaptive time step size: " << time_step_length << " max iterations: " << n_itr << "\n"; + if (Write_tim_discrete) + *tim_discrete << aktueller_zeitschritt << " " << aktuelle_zeit << " " << time_step_length << " " + << m_pcs->iter_lin << "\n"; //} return time_step_length; } - /************************************************************************** FEMLib-Method: Task: @@ -1697,11 +1795,12 @@ double CTimeDiscretization::CheckCourant(void) { long index; long group; - double velocity[3] = {0.,0.,0.}; + double velocity[3] = {0., 0., 0.}; double porosity, vg, advective_velocity, length, courant; CRFProcess* m_pcs = NULL; m_pcs = PCSGetFluxProcess(); - if (!m_pcs) { + if (!m_pcs) + { return 0.0; } int pcs_no = m_pcs->pcs_number; @@ -1721,11 +1820,11 @@ double CTimeDiscretization::CheckCourant(void) m_mmp = mmp_vector[group]; m_mmp->m_pcs = m_pcs; porosity = m_mmp->Porosity(m_mmp->Fem_Ele_Std); - gp_ele = ele_gp_value[index]; //to get gp velocities + gp_ele = ele_gp_value[index]; // to get gp velocities gp_ele->getIPvalue_vec(pcs_no, velocity); - vg = MBtrgVec(velocity,3); + vg = MBtrgVec(velocity, 3); advective_velocity = vg / porosity; - //kg44 avoid zero velocity..otherwise stable_time_step is a problem + // kg44 avoid zero velocity..otherwise stable_time_step is a problem if (advective_velocity < DBL_EPSILON) advective_velocity = DBL_EPSILON; courant = dt * advective_velocity / length; @@ -1741,8 +1840,8 @@ double CTimeDiscretization::CheckCourant(void) critical_element_no = index; } } - std::cout << "Courant time step control, critical element = " << critical_element_no << - " Recomended time step " << recommended_time_step << "\n"; + std::cout << "Courant time step control, critical element = " << critical_element_no << " Recomended time step " + << recommended_time_step << "\n"; return recommended_time_step; } @@ -1754,11 +1853,11 @@ double CTimeDiscretization::CheckCourant(void) **************************************************************************/ double CTimeDiscretization::AdaptiveFirstTimeStepEstimate(void) { - CNumerics* m_num (num_vector[0]); + CNumerics* m_num(num_vector[0]); MeshLib::CElem* elem = NULL; static double Node_p[8]; double p_ini, buff = 0.0; - //WW int no_time_steps; + // WW int no_time_steps; safty_coe = 5.0; p_ini = 1.0e-10; @@ -1770,47 +1869,46 @@ double CTimeDiscretization::AdaptiveFirstTimeStepEstimate(void) // switch(m_pcs->pcs_type_name[0]){ switch (m_pcs->getProcessType()) // TF { - // case 'R': // Richards - case FiniteElement::RICHARDS_FLOW: // TF - { - int idxp = m_pcs->GetNodeValueIndex("PRESSURE1") + 1; - //WW no_time_steps = 1000000000; //OK (int)(1e10); - time_step_length = 1.e10; - for (size_t i = 0; i < m_pcs->m_msh->ele_vector.size(); i++) - { - elem = m_pcs->m_msh->ele_vector[i]; - for (int j = 0; j < elem->GetVertexNumber(); j++) - Node_p[j] - = m_pcs->GetNodeValue(elem->GetNodeIndex(j), idxp); - p_ini = MMax(fabs(fem->interpolate(Node_p)), p_ini); - } - buff = safty_coe * sqrt(m_num->nls_error_tolerance[0] / p_ini); - buff /= m_pcs->time_unit_factor; - time_step_length = MMin(time_step_length, buff); - if (time_step_length < MKleinsteZahl) + // case 'R': // Richards + case FiniteElement::RICHARDS_FLOW: // TF { - std::cout << "Warning : Time Control Step Wrong, dt = 0.0 " << - "\n"; - time_step_length = 1.0e-8; + int idxp = m_pcs->GetNodeValueIndex("PRESSURE1") + 1; + // WW no_time_steps = 1000000000; //OK (int)(1e10); + time_step_length = 1.e10; + for (size_t i = 0; i < m_pcs->m_msh->ele_vector.size(); i++) + { + elem = m_pcs->m_msh->ele_vector[i]; + for (int j = 0; j < elem->GetVertexNumber(); j++) + Node_p[j] = m_pcs->GetNodeValue(elem->GetNodeIndex(j), idxp); + p_ini = MMax(fabs(fem->interpolate(Node_p)), p_ini); + } + buff = safty_coe * sqrt(m_num->nls_error_tolerance[0] / p_ini); + buff /= m_pcs->time_unit_factor; + time_step_length = MMin(time_step_length, buff); + if (time_step_length < MKleinsteZahl) + { + std::cout << "Warning : Time Control Step Wrong, dt = 0.0 " + << "\n"; + time_step_length = 1.0e-8; + } + std::cout << "Error Control Time Step: " << time_step_length << "\n"; + if (Write_tim_discrete) + *tim_discrete << aktueller_zeitschritt << " " << aktuelle_zeit << " " << time_step_length << " " + << m_pcs->iter_lin << "\n"; + break; } - std::cout << "Error Control Time Step: " << time_step_length << "\n"; - if (Write_tim_discrete) - *tim_discrete << aktueller_zeitschritt << " " << aktuelle_zeit - << " " << time_step_length << " " << - m_pcs->iter_lin - << "\n"; - break; - } - // case 'M': // kg44 mass transport - case FiniteElement::MASS_TRANSPORT: // TF - time_step_length = min_time_step; // take min time step as conservative best guess for testing - break; - // case 'G': // kg44 groudnwater flow ---if steady state, time step should be greater zeor...transient flow does not work with adaptive stepping - case FiniteElement::GROUNDWATER_FLOW: // if steady state, time step should be greater zero ... transient flow does not work with adaptive stepping - time_step_length = min_time_step; // take min time step as conservative best guess for testing - break; - default: - break; + // case 'M': // kg44 mass transport + case FiniteElement::MASS_TRANSPORT: // TF + time_step_length = min_time_step; // take min time step as conservative best guess for testing + break; + // case 'G': // kg44 groudnwater flow ---if steady state, time step should be greater zeor...transient + // flow does not work with adaptive stepping + case FiniteElement::GROUNDWATER_FLOW: // if steady state, time step should be greater zero ... transient + // flow does not work with adaptive stepping + time_step_length = min_time_step; // take min time step as conservative best guess for testing + break; + default: + break; } } return time_step_length; @@ -1835,27 +1933,23 @@ double CTimeDiscretization::ErrorControlAdaptiveTimeControl(void) // switch (m_pcs->pcs_type_name[0]) { switch (m_pcs->getProcessType()) // TF { - default: - std::cout << "Fatal error: No valid PCS type" << "\n"; - break; - // case 'R': // Richards, accepted and refused time step - case FiniteElement::RICHARDS_FLOW: // accepted and refused time step - //nonlinear_iteration_error = m_pcs->nonlinear_iteration_error; - if (repeat) - time_step_length *= MMax(safty_coe * sqrt( - m_pcs->m_num->nls_error_tolerance[0] - / nonlinear_iteration_error), rmin); - else - time_step_length *= MMin(safty_coe * sqrt( - m_pcs->m_num->nls_error_tolerance[0] - / nonlinear_iteration_error), rmax); - std::cout << "Error_Self_Adaptive Time Step: " << time_step_length - << "\n"; - if (Write_tim_discrete) - *tim_discrete << aktueller_zeitschritt << " " << aktuelle_zeit - << " " << time_step_length << " " << - m_pcs->iter_lin - << "\n"; + default: + std::cout << "Fatal error: No valid PCS type" + << "\n"; + break; + // case 'R': // Richards, accepted and refused time step + case FiniteElement::RICHARDS_FLOW: // accepted and refused time step + // nonlinear_iteration_error = m_pcs->nonlinear_iteration_error; + if (repeat) + time_step_length *= MMax( + safty_coe * sqrt(m_pcs->m_num->nls_error_tolerance[0] / nonlinear_iteration_error), rmin); + else + time_step_length *= MMin( + safty_coe * sqrt(m_pcs->m_num->nls_error_tolerance[0] / nonlinear_iteration_error), rmax); + std::cout << "Error_Self_Adaptive Time Step: " << time_step_length << "\n"; + if (Write_tim_discrete) + *tim_discrete << aktueller_zeitschritt << " " << aktuelle_zeit << " " << time_step_length << " " + << m_pcs->iter_lin << "\n"; } } return time_step_length; @@ -1868,47 +1962,61 @@ Task: Allow for time step retry if system changed rapidly and non-linearly Programing: 02.2011 JT implementation **************************************************************************/ -bool CTimeDiscretization::isDynamicTimeFailureSuggested(CRFProcess *m_pcs) +bool CTimeDiscretization::isDynamicTimeFailureSuggested(CRFProcess* m_pcs) { - if(m_pcs->iter_nlin > 0 || this->minimum_dt_reached) + if (m_pcs->iter_nlin > 0 || this->minimum_dt_reached) return false; // only checking on zeroth iteration (also do not fail if already at the minimum allowed dt) // // Currently only for use with DYNAMIC_VARIABLE time control - if(time_control_type != TimeControlType::DYNAMIC_VARIABLE) + if (time_control_type != TimeControlType::DYNAMIC_VARIABLE) return false; // - FiniteElement::ErrorMethod method (FiniteElement::convertErrorMethod(this->dynamic_control_error_method)); - if(method == m_pcs->m_num->getNonLinearErrorMethod()){ // Same as NL method, can re-use the values - for(int ii=0; iipcs_num_dof_errors; ii++){ - if(this->dynamic_failure_threshold > m_pcs->pcs_absolute_error[ii]/this->dynamic_control_tolerance[ii]){ + FiniteElement::ErrorMethod method(FiniteElement::convertErrorMethod(this->dynamic_control_error_method)); + if (method == m_pcs->m_num->getNonLinearErrorMethod()) + { // Same as NL method, can re-use the values + for (int ii = 0; ii < m_pcs->pcs_num_dof_errors; ii++) + { + if (this->dynamic_failure_threshold > m_pcs->pcs_absolute_error[ii] / this->dynamic_control_tolerance[ii]) + { return true; } } } - else if(method == m_pcs->m_num->getCouplingErrorMethod()){ // Alright, is different from NLS method. How about CPL method? - for(int ii=0; iicpl_num_dof_errors; ii++){ - if(this->dynamic_failure_threshold > m_pcs->cpl_absolute_error[ii]/this->dynamic_control_tolerance[ii]){ + else if (method == m_pcs->m_num->getCouplingErrorMethod()) + { // Alright, is different from NLS method. How about CPL method? + for (int ii = 0; ii < m_pcs->cpl_num_dof_errors; ii++) + { + if (this->dynamic_failure_threshold > m_pcs->cpl_absolute_error[ii] / this->dynamic_control_tolerance[ii]) + { return true; } } } - else if (time_control_type == TimeControlType::SELF_ADAPTIVE) { + else if (time_control_type == TimeControlType::SELF_ADAPTIVE) + { int n_itr = 0; - if (adapt_itr_type==IterationType::LINEAR) { + if (adapt_itr_type == IterationType::LINEAR) + { n_itr = m_pcs->iter_lin_max; - } else if (adapt_itr_type==IterationType::NONLINEAR) { + } + else if (adapt_itr_type == IterationType::NONLINEAR) + { n_itr = m_pcs->iter_nlin_max; } - if (n_itr>=time_adapt_tim_vector.back()) + if (n_itr >= time_adapt_tim_vector.back()) return true; } #if !defined(USE_PETSC) // && !defined(other parallel libs)//03.3012. WW - else{ // Alright, this is annoying. Unfortunately we have to recalculate the node errors. + else + { // Alright, this is annoying. Unfortunately we have to recalculate the node errors. - m_pcs->CalcIterationNODError(method,false,false); - for(int ii=0; iitemporary_num_dof_errors; ii++){ - if(this->dynamic_failure_threshold > m_pcs->temporary_absolute_error[ii]/this->dynamic_control_tolerance[ii]){ + m_pcs->CalcIterationNODError(method, false, false); + for (int ii = 0; ii < m_pcs->temporary_num_dof_errors; ii++) + { + if (this->dynamic_failure_threshold + > m_pcs->temporary_absolute_error[ii] / this->dynamic_control_tolerance[ii]) + { return true; } } @@ -1935,28 +2043,28 @@ double CTimeDiscretization::CheckTime(double const c_time, const double dt0) double pcs_step; double time_forward; bool ontime = false; - if((int)time_vector.size() == 1) + if ((int)time_vector.size() == 1) return dt0; // - //WW please check +1 - //OK double pcs_step = time_step_vector[step_current+1]; - if(time_step_vector.size() > 0) // 16.09.2008. WW + // WW please check +1 + // OK double pcs_step = time_step_vector[step_current+1]; + if (time_step_vector.size() > 0) // 16.09.2008. WW { - //OK - if(step_current >= (int)time_step_vector.size()) - //OK + // OK + if (step_current >= (int)time_step_vector.size()) + // OK pcs_step = time_step_vector[(int)time_step_vector.size() - 1]; else - //OK + // OK pcs_step = time_step_vector[step_current]; } else - pcs_step = this_stepsize; // 16.09.2008. WW + pcs_step = this_stepsize; // 16.09.2008. WW time_forward = c_time - time_current - pcs_step; - if(time_forward > 0.0 || fabs(time_forward) < MKleinsteZahl) + if (time_forward > 0.0 || fabs(time_forward) < MKleinsteZahl) { time_current += pcs_step; - //WW. 02.02.2009 step_current++; + // WW. 02.02.2009 step_current++; this_stepsize = dt_sum + dt0; ontime = true; dt_sum = 0.0; @@ -1980,16 +2088,16 @@ double CTimeDiscretization::CheckTime(double const c_time, const double dt0) this_stepsize = 0.0; } */ - if((fabs(pcs_step - time_end) < DBL_MIN) && fabs(c_time - time_end) < DBL_MIN) + if ((fabs(pcs_step - time_end) < DBL_MIN) && fabs(c_time - time_end) < DBL_MIN) { this_stepsize = dt_sum + dt0; ontime = true; dt_sum = 0.0; } - if(!ontime) + if (!ontime) dt_sum += dt0; - //this_stepsize = 0.0; //20.03.2009. WW - if(pcs_step > time_end) // make output for other processes + // this_stepsize = 0.0; //20.03.2009. WW + if (pcs_step > time_end) // make output for other processes { dt_sum = 0.0; this_stepsize = 0.0; @@ -2030,7 +2138,7 @@ void CTimeDiscretization::FillCriticalTime() // double val = critical_time[i]; // critical_time[i] = critical_time[j]; // critical_time[j] = val; - std::swap (critical_time[i], critical_time[j]); + std::swap(critical_time[i], critical_time[j]); } /************************************************************************** @@ -2041,10 +2149,10 @@ void CTimeDiscretization::FillCriticalTime() bool IsSynCron() { int i, count = 0; - for(i = 0; i < (int)time_vector.size(); i++) - if(time_vector[i]->dt_sum < DBL_MIN) + for (i = 0; i < (int)time_vector.size(); i++) + if (time_vector[i]->dt_sum < DBL_MIN) count++; - if(count == (int)time_vector.size()) + if (count == (int)time_vector.size()) return true; else return false; @@ -2079,71 +2187,68 @@ bool IsSynCron() double CTimeDiscretization::MaxTimeStep() { long i; - double velocity[3] = {0.,0.,0.}; - double max_diff_time_step = 1.0e+100,Dm,dummy,max_adv_time_step = 1.0e+100, vg, advective_velocity; - double theta = 0.0; // direction zero...no anisotropy - double g[3] = {0.,0.,0.}; + double velocity[3] = {0., 0., 0.}; + double max_diff_time_step = 1.0e+100, Dm, dummy, max_adv_time_step = 1.0e+100, vg, advective_velocity; + double theta = 0.0; // direction zero...no anisotropy + double g[3] = {0., 0., 0.}; CRFProcess* this_pcs = NULL; MeshLib::CElem* melem = NULL; - ElementValue* gp_ele; // for velocities + ElementValue* gp_ele; // for velocities CMediumProperties* m_mat_mp = NULL; // Get the pointer to a proper PCS. ..we assume that all transport processes use the same diffusion coefficient - dummy = CheckCourant(); // courant number + dummy = CheckCourant(); // courant number std::cout << "GEMS3K_Adaptive_Time_stepping: Advective Time Step " << dummy << " "; - //only do if Courant number bigger than zero + // only do if Courant number bigger than zero if (dummy > DBL_EPSILON) max_adv_time_step = std::min(max_diff_time_step, dummy); // pcs for a mass transport process ... - this_pcs = PCSGet ( "MASS_TRANSPORT" ); // is this always the first one? - long nElems = ( long ) this_pcs->m_msh->ele_vector.size(); + this_pcs = PCSGet("MASS_TRANSPORT"); // is this always the first one? + long nElems = (long)this_pcs->m_msh->ele_vector.size(); int component = this_pcs->pcs_component_number; int group; // pcs for flow transport CRFProcess* m_pcs = NULL; m_pcs = PCSGetFluxProcess(); - if (!m_pcs) { + if (!m_pcs) + { return 0.0; } int pcs_no = m_pcs->pcs_number; CompProperties* m_cp = cp_vec[component]; - - // find Neumann for first mass transport process // 15.01.2013 modified to include dispersive transport - for(i = 0; i < nElems; i++) + for (i = 0; i < nElems; i++) { group = this_pcs->m_msh->ele_vector[i]->GetPatchIndex(); m_mat_mp = mmp_vector[group]; - melem = this_pcs->m_msh->ele_vector[i]; + melem = this_pcs->m_msh->ele_vector[i]; // cout << m_mat_mp->Porosity(i,theta) << " " << melem->representative_length << "\n"; // KG44 attention DM needs to be multiplied with porosity! - Dm = m_mat_mp->TortuosityFunction(i,g,theta)* m_mat_mp->Porosity(i,theta) - * m_cp->CalcDiffusionCoefficientCP(i,theta,this_pcs); + Dm = m_mat_mp->TortuosityFunction(i, g, theta) * m_mat_mp->Porosity(i, theta) + * m_cp->CalcDiffusionCoefficientCP(i, theta, this_pcs); // now get magnitude of advective velocity to get an estimate of dispersive transport - gp_ele = ele_gp_value[i]; //to get gp velocities + gp_ele = ele_gp_value[i]; // to get gp velocities gp_ele->getIPvalue_vec(pcs_no, velocity); - vg = MBtrgVec(velocity,3); - advective_velocity = vg / m_mat_mp->Porosity(i,theta); + vg = MBtrgVec(velocity, 3); + advective_velocity = vg / m_mat_mp->Porosity(i, theta); // now get magnitude of dispersion ....take alpha_longitudinal and add it to Dm - Dm=Dm+m_mat_mp->mass_dispersion_longitudinal*advective_velocity; + Dm = Dm + m_mat_mp->mass_dispersion_longitudinal * advective_velocity; // calculation of typical length - dummy = ( 0.5 * (melem->representative_length * melem->representative_length)) / Dm; + dummy = (0.5 * (melem->representative_length * melem->representative_length)) / Dm; max_diff_time_step = std::min(max_diff_time_step, dummy); // std::cout << "Neumann criteria: " << max_diff_time_step << " i " << i << "\n"; } - std::cout << "GEMS3K: maximum Diffusive / Dispersive Time Step " << max_diff_time_step << std::endl; + std::cout << "GEMS3K: maximum Diffusive / Dispersive Time Step " << max_diff_time_step << std::endl; return std::min(max_diff_time_step, max_adv_time_step); } - - -#endif // end of GEM_REACT +#endif // end of GEM_REACT diff --git a/FEM/rf_tim_new.h b/FEM/rf_tim_new.h index fcc9d9123..c01c83e6f 100644 --- a/FEM/rf_tim_new.h +++ b/FEM/rf_tim_new.h @@ -34,70 +34,72 @@ typedef Vec PETSc_Vec; #endif using namespace std; //---------------------------------------------------------------- -class CRFProcess; //21.08.2008. WW +class CRFProcess; // 21.08.2008. WW class CTimeDiscretization { private: double safty_coe; - double dt_sum; // 17.09.2007 WW + double dt_sum; // 17.09.2007 WW // For PI time step control. Aug-Nov.2008. by WW - //Begin of data section for PI Time control ------------------------ -public: //OK + // Begin of data section for PI Time control ------------------------ +public: // OK double this_stepsize; double relative_error; double absolute_error; - double reject_factor; //for automatic timestep control: BG + double reject_factor; // for automatic timestep control: BG private: double h_min; double h_max; double hacc; double erracc; - double dynamic_control_tolerance[DOF_NUMBER_MAX+1]; //JT2012 - std::string dynamic_control_error_method; //JT2012 - int dynamic_time_buffer; //JT2012 - double dynamic_minimum_suggestion; //JT2012 - double dynamic_failure_threshold; //JT2012 -public: //OK + double dynamic_control_tolerance[DOF_NUMBER_MAX + 1]; // JT2012 + std::string dynamic_control_error_method; // JT2012 + int dynamic_time_buffer; // JT2012 + double dynamic_minimum_suggestion; // JT2012 + double dynamic_failure_threshold; // JT2012 +public: // OK int PI_tsize_ctrl_type; + private: std::vector critical_time; - //End of data section for PI Time control ------------------------ - friend bool IsSynCron(); //WW + // End of data section for PI Time control ------------------------ + friend bool IsSynCron(); // WW public: std::string file_base_name; // TIM - std::vectortime_step_vector; + std::vector time_step_vector; std::vector time_adapt_tim_vector; - std::vectortime_adapt_coe_vector; - //WW vectorfixed_point_vector; + std::vector time_adapt_coe_vector; + // WW vectorfixed_point_vector; - //WW vector time_step_target_vector; // kg44 for adaptive steps..intermediate time target that need to be reached + // WW vector time_step_target_vector; // kg44 for adaptive steps..intermediate time target that need to be + // reached double time_start; double time_end; double time_current; - double time_control_manipulate; //CMCD + double time_control_manipulate; // CMCD double next_active_time; double last_active_time; double recommended_time_step; double dt_failure_reduction_factor; int step_current; - bool repeat; //OK/YD - bool time_active; //JT2012 - bool time_independence; //JT2012 - bool last_dt_accepted; //JT2012 - bool minimum_dt_reached; //JT2012 - long accepted_step_count; //JT2012 - long rejected_step_count; //JT2012 + bool repeat; // OK/YD + bool time_active; // JT2012 + bool time_independence; // JT2012 + bool last_dt_accepted; // JT2012 + bool minimum_dt_reached; // JT2012 + long accepted_step_count; // JT2012 + long rejected_step_count; // JT2012 // // PCS - std::string pcs_type_name; //OK + std::string pcs_type_name; // OK // NUM - std::string time_type_name; //OK + std::string time_type_name; // OK TimeControlType::type time_control_type; - std::string time_unit; //WW - double iter_times; //YD - double multiply_coef; //YD - double max_time_step; //YD + std::string time_unit; // WW + double iter_times; // YD + double multiply_coef; // YD + double max_time_step; // YD double min_time_step; double initial_step_size; IterationType::type adapt_itr_type; @@ -111,80 +113,80 @@ class CTimeDiscretization double SEA_a, SEA_b, SEA_c; // - //WW double minish; // JOD - //WW int sub_steps; // JOD 4.7.10 - bool Write_tim_discrete; //YD - std::fstream* tim_discrete; //YD - double nonlinear_iteration_error; //OK/YD - //WW double max_adaptive_factor; // kg44 - //WW double max_adaptive_concentration_change; // kg44 + // WW double minish; // JOD + // WW int sub_steps; // JOD 4.7.10 + bool Write_tim_discrete; // YD + std::fstream* tim_discrete; // YD + double nonlinear_iteration_error; // OK/YD + // WW double max_adaptive_factor; // kg44 + // WW double max_adaptive_concentration_change; // kg44 public: CTimeDiscretization(void); - //21.08.2008. WW + // 21.08.2008. WW CTimeDiscretization(const CTimeDiscretization& a_tim, std::string pcsname); ~CTimeDiscretization(void); std::ios::pos_type Read(std::ifstream*); void Write(std::fstream*); - double time_step_length_neumann; //YD - double time_step_length; //YD + double time_step_length_neumann; // YD + double time_step_length; // YD double CalcTimeStep(double crt_time = 0.0); // Add argument double crt_time. 25.08.2008. WW double FirstTimeStepEstimate(); double AdaptiveFirstTimeStepEstimate(); // For PI time step control. Aug-Nov.2008. by WW - //Begin of function section for PI Time control ------------------------ - int GetPITimeStepCrtlType() const {return PI_tsize_ctrl_type; } - double GetTimeStep() const {return this_stepsize; } + // Begin of function section for PI Time control ------------------------ + int GetPITimeStepCrtlType() const { return PI_tsize_ctrl_type; } + double GetTimeStep() const { return this_stepsize; } double GetEndTime() const { return time_end; } - void SetTimeStep( double hnew) {this_stepsize = hnew; } + void SetTimeStep(double hnew) { this_stepsize = hnew; } double GetRTol() const { return relative_error; } double GetATol() const { return absolute_error; } double GetMaximumTSizeRestric() const { return h_max; } double GetMinimumTSizeRestric() const { return h_min; } double GetHacc() const { return hacc; } double GetErracc() const { return erracc; } - void SetHacc(const double hacc_val) { hacc = hacc_val; } + void SetHacc(const double hacc_val) { hacc = hacc_val; } void setErracc(const double erracc_val) { erracc = erracc_val; } // - //JT: done differently now. // double CheckTime(double const c_time, const double dt0); - void FillCriticalTime(); //21.08.2008. - //Begin of function section for PI Time control ------------------------ + // JT: done differently now. // double CheckTime(double const c_time, const double dt0); + void FillCriticalTime(); // 21.08.2008. + // Begin of function section for PI Time control ------------------------ double ErrorControlAdaptiveTimeControl(); double NeumannTimeControl(); double SelfAdaptiveTimeControl(); - double StableErrorAdaptive( void ); - bool SEA_parameters_are_bad( void ); - void SEA_calc_parameters( void ); + double StableErrorAdaptive(void); + bool SEA_parameters_are_bad(void); + void SEA_calc_parameters(void); double SEA_zbrent(const double tol); double SEA_func(double const c); inline double SEA_SIGN(const double a, const float b); - double DynamicVariableTimeControl(); //JT2012 - double DynamicTimeSmoothing(double suggested_time_step_change); //JT2012 + double DynamicVariableTimeControl(); // JT2012 + double DynamicTimeSmoothing(double suggested_time_step_change); // JT2012 // // Dynamic time control methods JT2012 - bool isDynamicTimeFailureSuggested(CRFProcess *this_pcs=NULL); - // + bool isDynamicTimeFailureSuggested(CRFProcess* this_pcs = NULL); +// #ifdef GEM_REACT double MaxTimeStep(); #endif // - //WW bool GetTimeStepTargetVector(); // kg44 - double CheckCourant(); //CMCD + // WW bool GetTimeStepTargetVector(); // kg44 + double CheckCourant(); // CMCD }; extern std::vector time_vector; extern bool TIMRead(std::string); // extern CTimeDiscretization* TIMGet(const string&); -//kg44 const string made trouble for me +// kg44 const string made trouble for me extern CTimeDiscretization* TIMGet(const std::string& pcs_type_name); extern void TIMWrite(std::string); -extern bool IsSynCron(); //WW +extern bool IsSynCron(); // WW extern void TIMDelete(); extern void TIMDelete(std::string); #define TIM_FILE_EXTENSION ".tim" -//ToDo +// ToDo extern double aktuelle_zeit; extern size_t aktueller_zeitschritt; extern double dt; -extern int rwpt_numsplits; // JT 2010, for specifying sub time step for random walker in .tim input file +extern int rwpt_numsplits; // JT 2010, for specifying sub time step for random walker in .tim input file #endif diff --git a/FEM/rfmat_cp.cpp b/FEM/rfmat_cp.cpp index 4434971f0..680808c53 100644 --- a/FEM/rfmat_cp.cpp +++ b/FEM/rfmat_cp.cpp @@ -18,7 +18,7 @@ */ /**************************************************************************/ #ifdef WIN32 -#pragma warning (disable:4786) /*Visual C++ 6.0*/ +#pragma warning(disable : 4786) /*Visual C++ 6.0*/ #endif // C #include @@ -38,7 +38,7 @@ using namespace std; #include "rf_mmp_new.h" #include "rf_msp_new.h" #include "rf_pcs.h" -#include "rf_pcs.h" //OK_MOD" //GetRFProcess..() +#include "rf_pcs.h" //OK_MOD" //GetRFProcess..() #include "rf_tim_new.h" #include "rfmat_cp.h" #include "tools.h" @@ -52,8 +52,8 @@ using SolidProp::CSolidProperties; /* Vector auf CompProperties , globale Zugriffe */ // vector cp_vec; // do not need this anymore, use global map structure instead. -std::map cp_vec; -std::map cp_name_2_idx; +std::map cp_vec; +std::map cp_name_2_idx; /*========================================================================*/ /* Component Properties */ @@ -65,14 +65,13 @@ std::map cp_name_2_idx; Programing: 02/2004 SB Implementation **************************************************************************/ -CompProperties::CompProperties(/* int n // HS we do not need this. */) - : idx(std::numeric_limits::max()) +CompProperties::CompProperties(/* int n // HS we do not need this. */) : idx(std::numeric_limits::max()) { // if ( idx != std::numeric_limits::max() ) // this means idx is set. // compname = name1; // HS it will be loaded later. - iupac_formula = ""; // CB 0311 check - mobil = 1; // by default, set to mobile species. + iupac_formula = ""; // CB 0311 check + mobil = 1; // by default, set to mobile species. transport_phase = 0; // by default, set to the 1st phase. fluid_phase = 0; // by default, set to water @@ -88,22 +87,22 @@ CompProperties::CompProperties(/* int n // HS we do not need this. */) bubble_velocity_model = -1; bubble_velocity[0] = bubble_velocity[1] = bubble_velocity[2] = 0.0; file_base_name = "nix"; - valence = 0; - a_zero = 0; - mineral_density = 0; - molar_density = 0; - molar_weight = 0; - max_solubility = 0; - -//// CB _ctx_ -// _ctx_ = false; -// ct_substratename = ""; -// _ctx_Coefficient = 0; - - this->setProcessType( FiniteElement::MASS_TRANSPORT ); - this->setProcessPrimaryVariable( FiniteElement::CONCENTRATION ); - - OutputMassOfComponentInModel = 0; // 05/2012 BG + valence = 0; + a_zero = 0; + mineral_density = 0; + molar_density = 0; + molar_weight = 0; + max_solubility = 0; + + //// CB _ctx_ + // _ctx_ = false; + // ct_substratename = ""; + // _ctx_Coefficient = 0; + + this->setProcessType(FiniteElement::MASS_TRANSPORT); + this->setProcessPrimaryVariable(FiniteElement::CONCENTRATION); + + OutputMassOfComponentInModel = 0; // 05/2012 BG } /************************************************************************** @@ -128,7 +127,7 @@ CompProperties::~CompProperties(void) bool CPRead(std::string file_base_name) { //---------------------------------------------------------------------- - //OK MCPDelete(); + // OK MCPDelete(); //---------------------------------------------------------------------- CompProperties* m_cp = NULL; char line[MAX_ZEILE]; @@ -138,33 +137,37 @@ bool CPRead(std::string file_base_name) //======================================================================== // File handling std::string cp_file_name = file_base_name + CP_FILE_EXTENSION; - ifstream cp_file (cp_file_name.data(),ios::in); - if (!cp_file.good()) { - if (pcs_vector[0]->getProcessType() == FiniteElement::TNEQ){ + ifstream cp_file(cp_file_name.data(), ios::in); + if (!cp_file.good()) + { + if (pcs_vector[0]->getProcessType() == FiniteElement::TNEQ) + { DisplayMsgLn("ERROR. TNEQ requires specification of inert and reactive components in mcp file."); exit(1); } - if (pcs_vector[0]->getProcessType() == FiniteElement::TES){ + if (pcs_vector[0]->getProcessType() == FiniteElement::TES) + { DisplayMsgLn("ERROR. TES requires specification of inert and reactive components in mcp file."); exit(1); } return false; } - cp_file.seekg(0L,ios::beg); + cp_file.seekg(0L, ios::beg); //======================================================================== cp_vec.clear(); - cout << "CPRead" << "\n"; + cout << "CPRead" + << "\n"; // Schleife ueber alle Phasen bzw. Komponenten while (!cp_file.eof()) { - cp_file.getline(line,MAX_ZEILE); + cp_file.getline(line, MAX_ZEILE); line_string = line; - if(line_string.find("#STOP") != std::string::npos) + if (line_string.find("#STOP") != std::string::npos) break; //---------------------------------------------------------------------- // keyword found - if(line_string.find("#COMPONENT_PROPERTIES") != std::string::npos) + if (line_string.find("#COMPONENT_PROPERTIES") != std::string::npos) { m_cp = new CompProperties(); m_cp->file_base_name = file_base_name; @@ -175,33 +178,31 @@ bool CPRead(std::string file_base_name) cp_name_2_idx[m_cp->compname] = m_cp->idx; cp_vec[m_cp->idx] = m_cp; m_cp = NULL; - cp_file.seekg(position,ios::beg); - } // keyword found - } // eof + cp_file.seekg(position, ios::beg); + } // keyword found + } // eof // immediately check if enough PCS objects are available size_t pcs_mt_count = 0; size_t pcs_rwpt_count = 0; size_t i; - for ( i = 0; i < pcs_vector.size(); i++ ) + for (i = 0; i < pcs_vector.size(); i++) { - if ( pcs_vector[i]->getProcessType() == FiniteElement::MASS_TRANSPORT ) + if (pcs_vector[i]->getProcessType() == FiniteElement::MASS_TRANSPORT) pcs_mt_count++; - if ( pcs_vector[i]->getProcessType() == FiniteElement::RANDOM_WALK ) + if (pcs_vector[i]->getProcessType() == FiniteElement::RANDOM_WALK) pcs_rwpt_count++; } - if ( pcs_rwpt_count == 0) // HS, no random walk detected. + if (pcs_rwpt_count == 0) // HS, no random walk detected. { if ((pcs_mt_count != cp_vec.size() || pcs_mt_count != cp_name_2_idx.size()) && pcs_vector[0]->getProcessType() != FiniteElement::TNEQ - && pcs_vector[0]->getProcessType() != FiniteElement::TES - ) + && pcs_vector[0]->getProcessType() != FiniteElement::TES) { - DisplayMsgLn( - "Mass transport components and Mass transport processes do not fit!"); + DisplayMsgLn("Mass transport components and Mass transport processes do not fit!"); exit(1); } - else if (cp_vec.size() < 2 - && (pcs_vector[0]->getProcessType() == FiniteElement::TNEQ || pcs_vector[0]->getProcessType() == FiniteElement::TES)) + else if (cp_vec.size() < 2 && (pcs_vector[0]->getProcessType() == FiniteElement::TNEQ + || pcs_vector[0]->getProcessType() == FiniteElement::TES)) { DisplayMsgLn("ERROR. TNEQ/TES requires specification of inert and reactive components in mcp file."); exit(1); @@ -209,31 +210,35 @@ bool CPRead(std::string file_base_name) else { // and then link MCP with the PCS. - std::map ::iterator cp_iter = cp_vec.begin(); - for ( i = 0; i < pcs_vector.size(); i++ ){ - if ( pcs_vector[i]->getProcessType() == FiniteElement::MASS_TRANSPORT ) + std::map::iterator cp_iter = cp_vec.begin(); + for (i = 0; i < pcs_vector.size(); i++) + { + if (pcs_vector[i]->getProcessType() == FiniteElement::MASS_TRANSPORT) { - cp_iter->second->setProcess( pcs_vector[i] ); + cp_iter->second->setProcess(pcs_vector[i]); ++cp_iter; } if (pcs_vector[i]->getProcessType() == FiniteElement::TNEQ || pcs_vector[i]->getProcessType() == FiniteElement::TES) - std::cout << "Warning! For TNEQ/TES, the component order in the mcp file needs to be INERT, REACTIVE!\n"; + std::cout + << "Warning! For TNEQ/TES, the component order in the mcp file needs to be INERT, REACTIVE!\n"; } } // end of else - //Assign fluid id's for use in fluid property calculation + // Assign fluid id's for use in fluid property calculation if (pcs_vector[0]->getProcessType() == FiniteElement::TNEQ || pcs_vector[0]->getProcessType() == FiniteElement::TES) - for (i=0;icompname == "N2") cp_vec[i]->fluid_id = 3; else if (cp_vec[i]->compname == "H2O") cp_vec[i]->fluid_id = 1; - else if (cp_vec[i]->compname == "O2"){ + else if (cp_vec[i]->compname == "O2") + { cp_vec[i]->fluid_id = 5; - std::cout << "Warning: The thermal conductivity critical enhancement model for oxygen has not been implemented. Dilute and residual parts only.\n"; + std::cout << "Warning: The thermal conductivity critical enhancement model for oxygen has not been " + "implemented. Dilute and residual parts only.\n"; } else std::cout << "Warning: Component name unknown to TNEQ/TES.\n"; @@ -273,10 +278,10 @@ ios::pos_type CompProperties::Read(ifstream* rfd_file) // if(!GetLineFromFile(line,rfd_file)) break; // line_string = line; line_string = GetLineFromFile1(rfd_file); - if(line_string.size() < 1) + if (line_string.size() < 1) break; - if(line_string.find(hash) != std::string::npos) + if (line_string.find(hash) != std::string::npos) { new_keyword = true; break; @@ -285,23 +290,24 @@ ios::pos_type CompProperties::Read(ifstream* rfd_file) /* Keywords nacheinander durchsuchen */ //.................................................................... // subkeyword found - if(line_string.find("$NAME") != std::string::npos) + if (line_string.find("$NAME") != std::string::npos) { in.str(GetLineFromFile1(rfd_file)); - in >> compname; //sub_line + in >> compname; // sub_line in.clear(); // compname = (char *) sub_line.c_str(); } //.................................................................... // subkeyword found - if(line_string.find("$FORMULA")!=std::string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> iupac_formula; //sub_line - in.clear(); - } - //.................................................................... - // subkeyword found - if(line_string.find("$MOBILE") != std::string::npos) + if (line_string.find("$FORMULA") != std::string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> iupac_formula; // sub_line + in.clear(); + } + //.................................................................... + // subkeyword found + if (line_string.find("$MOBILE") != std::string::npos) { // rfd_file->getline(line,MAX_ZEILE); // line_string = line; @@ -312,7 +318,7 @@ ios::pos_type CompProperties::Read(ifstream* rfd_file) } //.................................................................... // subkeyword found - if(line_string.find("$TRANSPORT_PHASE") != std::string::npos) + if (line_string.find("$TRANSPORT_PHASE") != std::string::npos) { // rfd_file->getline(line,MAX_ZEILE); // line_string = line; @@ -323,26 +329,25 @@ ios::pos_type CompProperties::Read(ifstream* rfd_file) } //.................................................................... // subkeyword found - if(line_string.find("$FLUID_PHASE") != std::string::npos) + if (line_string.find("$FLUID_PHASE") != std::string::npos) { in.str(GetLineFromFile1(rfd_file)); in >> fluid_phase; in.clear(); // critical constant and corresponding components fluid Property // AKS - if ( mfp_vector[fluid_phase] ) + if (mfp_vector[fluid_phase]) // found corresponding fluid phase. mfp_vector[fluid_phase]->component_vector.push_back(this); else { - cout << - "Error! Corresponding fluid phase not found!!! Terminate program..." + cout << "Error! Corresponding fluid phase not found!!! Terminate program..." << "\n"; exit(0); } } //.................................................................... // subkeyword found - if(line_string.find("$MOL_MASS") != std::string::npos) + if (line_string.find("$MOL_MASS") != std::string::npos) { in.str(GetLineFromFile1(rfd_file)); in >> molar_mass; @@ -350,7 +355,7 @@ ios::pos_type CompProperties::Read(ifstream* rfd_file) } //.................................................................... // subkeyword found - if(line_string.find("$CRITICAL_PRESSURE") != std::string::npos) + if (line_string.find("$CRITICAL_PRESSURE") != std::string::npos) { in.str(GetLineFromFile1(rfd_file)); in >> pc; @@ -358,14 +363,14 @@ ios::pos_type CompProperties::Read(ifstream* rfd_file) } //.................................................................... // subkeyword found - if(line_string.find("$CRITICAL_TEMPERATURE") != std::string::npos) + if (line_string.find("$CRITICAL_TEMPERATURE") != std::string::npos) { in.str(GetLineFromFile1(rfd_file)); in >> Tc; in.clear(); } //.................................................................... - if(line_string.find("$ACENTRIC_FACTOR") != std::string::npos) + if (line_string.find("$ACENTRIC_FACTOR") != std::string::npos) { in.str(GetLineFromFile1(rfd_file)); in >> omega; @@ -373,13 +378,13 @@ ios::pos_type CompProperties::Read(ifstream* rfd_file) } //.................................................................... // subkeyword found - if(line_string.find("$FLUID_ID") != std::string::npos) + if (line_string.find("$FLUID_ID") != std::string::npos) { in.str(GetLineFromFile1(rfd_file)); in >> fluid_id; in.clear(); } - if(line_string.find("$MOLAR_VOLUME") != std::string::npos) + if (line_string.find("$MOLAR_VOLUME") != std::string::npos) { in.str(GetLineFromFile1(rfd_file)); in >> Vm; @@ -387,34 +392,34 @@ ios::pos_type CompProperties::Read(ifstream* rfd_file) } //.................................................................... // subkeyword found - if(line_string.find("$VOLUME_DIFFUSION") != std::string::npos) + if (line_string.find("$VOLUME_DIFFUSION") != std::string::npos) { in.str(GetLineFromFile1(rfd_file)); in >> Vd; in.clear(); } - //.................................................................... - if(line_string.find("$MINERAL_DENSITY")!=std::string::npos) { // subkeyword found [g/cm3]:AB - in.str(GetLineFromFile1(rfd_file)); - in >> mineral_density; - in.clear(); - } + //.................................................................... + if (line_string.find("$MINERAL_DENSITY") != std::string::npos) + { // subkeyword found [g/cm3]:AB + in.str(GetLineFromFile1(rfd_file)); + in >> mineral_density; + in.clear(); + } //.................................................................... // subkeyword found - if(line_string.find("$DIFFUSION") != std::string::npos) + if (line_string.find("$DIFFUSION") != std::string::npos) { in.str(GetLineFromFile1(rfd_file)); in >> diffusion_model; - if(diffusion_model == 0) //read curve + if (diffusion_model == 0) // read curve in >> diffusion_function_name; else { - count_of_diffusion_model_values = - GetNumberDiffusionValuesCompProperties(diffusion_model); + count_of_diffusion_model_values = GetNumberDiffusionValuesCompProperties(diffusion_model); // unknown parameter model - if(count_of_diffusion_model_values < 0) + if (count_of_diffusion_model_values < 0) { DisplayMsgLn(" Unknown Diffusion model - program stops !"); exit(1); @@ -425,7 +430,7 @@ ios::pos_type CompProperties::Read(ifstream* rfd_file) for (j = 0; j < count_of_diffusion_model_values; j++) { - if(in.peek() > 0) + if (in.peek() > 0) /* if(StrTestInv(&sub[p_sub += pos],&pos)) { @@ -439,42 +444,35 @@ ios::pos_type CompProperties::Read(ifstream* rfd_file) // in >> read_help[j]; in >> diffusion_model_values[j]; else - cout << - "Warning: Missing diffusion model values for component " - << this->compname << "\n"; - if((diffusion_model == 1) && (j == 0)) - if((diffusion_model_values[j] < 0.0) || - (diffusion_model_values[j] > 100000.0)) - cout << - "Warning: Funny diffusion model values specified" + cout << "Warning: Missing diffusion model values for component " << this->compname << "\n"; + if ((diffusion_model == 1) && (j == 0)) + if ((diffusion_model_values[j] < 0.0) || (diffusion_model_values[j] > 100000.0)) + cout << "Warning: Funny diffusion model values specified" << "\n"; - } //end for(j...) + } // end for(j...) // diffusion_model_values = read_help; if (diffusion_model < 0) - DisplayMsgLn( - "Error: Diffusion model must be larger than or 0"); + DisplayMsgLn("Error: Diffusion model must be larger than or 0"); } in.clear(); - } // subkeyword found - // subkeyword found - if(line_string.find("$DECAY") != std::string::npos) + } // subkeyword found + // subkeyword found + if (line_string.find("$DECAY") != std::string::npos) { in.str(GetLineFromFile1(rfd_file)); in >> decay_model; - if(decay_model == 0) //curve + if (decay_model == 0) // curve in >> decay_function_name; else { - count_of_decay_model_values = GetNumberDecayValuesCompProperties( - decay_model); + count_of_decay_model_values = GetNumberDecayValuesCompProperties(decay_model); - if(count_of_decay_model_values < 0) // unknown parameter model + if (count_of_decay_model_values < 0) // unknown parameter model { - DisplayMsgLn( - " Unknown Aqueous Decay model - program stops !"); + DisplayMsgLn(" Unknown Aqueous Decay model - program stops !"); exit(1); } @@ -494,29 +492,27 @@ ios::pos_type CompProperties::Read(ifstream* rfd_file) // in >> read_help[j]; in >> decay_model_values[j]; - //end for(j...) + // end for(j...) // decay_model_values = read_help; if (decay_model < -1) - DisplayMsgLn( - "Error: Aqueous decay model must be larger than or 0"); + DisplayMsgLn("Error: Aqueous decay model must be larger than or 0"); } in.clear(); - } // subkeyword found - // subkeyword found - if(line_string.find("$ISOTHERM") != std::string::npos) + } // subkeyword found + // subkeyword found + if (line_string.find("$ISOTHERM") != std::string::npos) { in.str(GetLineFromFile1(rfd_file)); in >> isotherm_model; - if(isotherm_model == 0) + if (isotherm_model == 0) in >> isotherm_function_name; else { - count_of_isotherm_model_values = - GetNumberIsothermValuesCompProperties(isotherm_model); + count_of_isotherm_model_values = GetNumberIsothermValuesCompProperties(isotherm_model); - if(count_of_isotherm_model_values < 0) // unknown parameter model + if (count_of_isotherm_model_values < 0) // unknown parameter model { DisplayMsgLn(" Unknown Isotherm model - program stops !"); exit(1); @@ -538,96 +534,96 @@ ios::pos_type CompProperties::Read(ifstream* rfd_file) // in >> read_help[j]; in >> isotherm_model_values[j]; - //end for(j...) + // end for(j...) // isotherm_model_values = read_help; if (isotherm_model < 0) - DisplayMsgLn( - "Error: Isotherm model must be larger than or 0"); + DisplayMsgLn("Error: Isotherm model must be larger than or 0"); } in.clear(); - } // subkeyword found + } // subkeyword found // subkeyword found - if(line_string.find("$BUBBLE_VELOCITY") != std::string::npos) + if (line_string.find("$BUBBLE_VELOCITY") != std::string::npos) { in.str(GetLineFromFile1(rfd_file)); in >> bubble_velocity_model; - if(bubble_velocity_model == 1) - in >> bubble_velocity[0] >> bubble_velocity[1] >> - bubble_velocity[2]; + if (bubble_velocity_model == 1) + in >> bubble_velocity[0] >> bubble_velocity[1] >> bubble_velocity[2]; in.clear(); - } // subkeyword found + } // subkeyword found //.................................................................... // parameters for NAPL dissolution CB140708 // subkeyword found - if(line_string.find("$MOLAR_DENSITY") != std::string::npos) + if (line_string.find("$MOLAR_DENSITY") != std::string::npos) { in.str(GetLineFromFile1(rfd_file)); in >> molar_density; in.clear(); - if(molar_density <= 0) // unphysical entry + if (molar_density <= 0) // unphysical entry { - DisplayMsgLn( - "Error in MOLAR_DENSITY - setting molar_density to 1.0!"); + DisplayMsgLn("Error in MOLAR_DENSITY - setting molar_density to 1.0!"); molar_density = 1.0; } } // subkeyword found - if(line_string.find("$MOLAR_WEIGHT") != std::string::npos) + if (line_string.find("$MOLAR_WEIGHT") != std::string::npos) { in.str(GetLineFromFile1(rfd_file)); in >> molar_weight; in.clear(); - if(molar_weight <= 0) // unphysical entry + if (molar_weight <= 0) // unphysical entry { DisplayMsgLn("Error in MOLAR_WEIGHT - setting molar_weight to 1.0!"); molar_weight = 1.0; } } // subkeyword found - if(line_string.find("$MAXIMUM_AQUEOUS_SOLUBILITY") != std::string::npos) + if (line_string.find("$MAXIMUM_AQUEOUS_SOLUBILITY") != std::string::npos) { in.str(GetLineFromFile1(rfd_file)); in >> max_solubility; in.clear(); - if(max_solubility <= 0) // unphysical entry + if (max_solubility <= 0) // unphysical entry { - DisplayMsgLn( - ": Error in MAXIMUM_AQUEOUS_SOLUBILITY - setting max_solubility to 1.0!"); + DisplayMsgLn(": Error in MAXIMUM_AQUEOUS_SOLUBILITY - setting max_solubility to 1.0!"); max_solubility = 1.0; } } //.................................................................... // subkeyword found // Output of the Mass of the component within the model if subkeyword is found, BG 05/2012 - if(line_string.find("$OutputMassOfComponentInModel") != std::string::npos) + if (line_string.find("$OutputMassOfComponentInModel") != std::string::npos) { OutputMassOfComponentInModel = 1; } - //.................................................................... - // parameters for MINERAL KINETICS CB0410 - if(line_string.find("$VALENCE")!=std::string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> valence; - in.clear(); - if(fabs(double(valence)) >= 7){ // unphysical entry - DisplayMsgLn("Error in VALENCE - setting valence to 0!"); - valence = 0; - } - } - if(line_string.find("$A_ZERO")!=std::string::npos) { // subkeyword found - in.str(GetLineFromFile1(rfd_file)); - in >> a_zero; - in.clear(); - if(a_zero >= 10){ // unphysical entry - // DisplayMsgLn("Error in A_ZERO - setting valence to 0!"); - //a_zero = 0.0; - } - } - } //end while + //.................................................................... + // parameters for MINERAL KINETICS CB0410 + if (line_string.find("$VALENCE") != std::string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> valence; + in.clear(); + if (fabs(double(valence)) >= 7) + { // unphysical entry + DisplayMsgLn("Error in VALENCE - setting valence to 0!"); + valence = 0; + } + } + if (line_string.find("$A_ZERO") != std::string::npos) + { // subkeyword found + in.str(GetLineFromFile1(rfd_file)); + in >> a_zero; + in.clear(); + if (a_zero >= 10) + { // unphysical entry + // DisplayMsgLn("Error in A_ZERO - setting valence to 0!"); + // a_zero = 0.0; + } + } + } // end while return position; } @@ -637,7 +633,7 @@ ios::pos_type CompProperties::Read(ifstream* rfd_file) Programing: 05/2004 SB Implementation **************************************************************************/ -void CPWrite(std::string base_file_name,int flag) +void CPWrite(std::string base_file_name, int flag) { CompProperties* m_kr = NULL; std::string rfe_file_name; @@ -646,34 +642,36 @@ void CPWrite(std::string base_file_name,int flag) //======================================================================== // File handling - if(flag == 1) + if (flag == 1) { // rfe_file_name = base_file_name + ".rfe"; rfe_file_name = base_file_name; - rfe_file.open(rfe_file_name.data(),ios::app); + rfe_file.open(rfe_file_name.data(), ios::app); } else { rfe_file_name = base_file_name + CP_FILE_EXTENSION; - rfe_file.open(rfe_file_name.data(),ios::trunc | ios::out); + rfe_file.open(rfe_file_name.data(), ios::trunc | ios::out); } if (!rfe_file.good()) return; - if(flag == 1) - rfe_file.seekp(0L,ios::end); // go to end + if (flag == 1) + rfe_file.seekp(0L, ios::end); // go to end //======================================================================== - rfe_file << "\n" << - "; CompProperties ----------------------------------------------------------------- " << - "\n"; + rfe_file << "\n" + << "; CompProperties ----------------------------------------------------------------- " + << "\n"; // Output all components - length = (int) cp_vec.size(); - for(i = 0; i < length; i++) + length = (int)cp_vec.size(); + for (i = 0; i < length; i++) { m_kr = cp_vec[i]; m_kr->Write(&rfe_file); } - rfe_file << "\n" << "#STOP " << "\n"; + rfe_file << "\n" + << "#STOP " + << "\n"; rfe_file.close(); // delete rfe_file; } @@ -689,79 +687,101 @@ void CompProperties::Write(ofstream* rfe_file) int i; // Write Keyword - *rfe_file << "#COMPONENT_PROPERTIES" << "\n"; + *rfe_file << "#COMPONENT_PROPERTIES" + << "\n"; // Name of component - *rfe_file << "$NAME" << "\n" << compname << "\n"; + *rfe_file << "$NAME" + << "\n" + << compname << "\n"; // chemical formula - *rfe_file << "$FORMULA" << "\n" << iupac_formula<< "\n"; + *rfe_file << "$FORMULA" + << "\n" + << iupac_formula << "\n"; // mobile or not? - *rfe_file << "$MOBILE" << "\n" << mobil << "\n"; + *rfe_file << "$MOBILE" + << "\n" + << mobil << "\n"; // TRANSPORT_PHASE - *rfe_file << "$TRANSPORT_PHASE" << "\n" << transport_phase << "\n"; + *rfe_file << "$TRANSPORT_PHASE" + << "\n" + << transport_phase << "\n"; // FLUID_PHASE - *rfe_file << "$FLUID_PHASE" << "\n" << transport_phase << "\n"; + *rfe_file << "$FLUID_PHASE" + << "\n" + << transport_phase << "\n"; // Diffusion - if(diffusion_model > -1 ) + if (diffusion_model > -1) { - *rfe_file << "$DIFFUSION" << "\n"; + *rfe_file << "$DIFFUSION" + << "\n"; *rfe_file << diffusion_model << " "; - for(i = 0; i < count_of_diffusion_model_values; i++) + for (i = 0; i < count_of_diffusion_model_values; i++) *rfe_file << diffusion_model_values[i] << " "; *rfe_file << "\n"; } // DECAY - if(decay_model > -1) + if (decay_model > -1) { - *rfe_file << "$DECAY" << "\n"; + *rfe_file << "$DECAY" + << "\n"; *rfe_file << decay_model << " "; - for(i = 0; i < count_of_decay_model_values; i++) + for (i = 0; i < count_of_decay_model_values; i++) *rfe_file << decay_model_values[i] << " "; *rfe_file << "\n"; } - //Isotherm - if(isotherm_model > -1) + // Isotherm + if (isotherm_model > -1) { - *rfe_file << "$ISOTHERM" << "\n"; + *rfe_file << "$ISOTHERM" + << "\n"; *rfe_file << isotherm_model << " "; - for(i = 0; i < count_of_isotherm_model_values; i++) + for (i = 0; i < count_of_isotherm_model_values; i++) *rfe_file << isotherm_model_values[i] << " "; *rfe_file << "\n"; } - //NAPL Dissolution CB140708 - if(molar_density > 0) + // NAPL Dissolution CB140708 + if (molar_density > 0) { - *rfe_file << "$MOLAR_DENSITY" << "\n"; + *rfe_file << "$MOLAR_DENSITY" + << "\n"; *rfe_file << molar_density << " "; *rfe_file << "\n"; } - if(molar_weight > 0) + if (molar_weight > 0) { - *rfe_file << "$MOLAR_WEIGHT" << "\n"; + *rfe_file << "$MOLAR_WEIGHT" + << "\n"; *rfe_file << molar_weight << " "; *rfe_file << "\n"; } - if(max_solubility > 0) + if (max_solubility > 0) { - *rfe_file << "$MAXIMUM_AQUEOUS_SOLUBILITY" << "\n"; + *rfe_file << "$MAXIMUM_AQUEOUS_SOLUBILITY" + << "\n"; *rfe_file << max_solubility << " "; *rfe_file << "\n"; } -if(a_zero>0){ - *rfe_file << "$A_ZERO" << "\n"; - *rfe_file << a_zero << " "; - *rfe_file << "\n"; -} -if(valence){ - *rfe_file << "$VALENCE" << "\n"; - *rfe_file << valence << " "; - *rfe_file << "\n"; -} -if(mineral_density>0){ - *rfe_file << "$MINERAL_DENSITY" << "\n"; - *rfe_file << mineral_density << " "; - *rfe_file << "\n"; -} - + if (a_zero > 0) + { + *rfe_file << "$A_ZERO" + << "\n"; + *rfe_file << a_zero << " "; + *rfe_file << "\n"; + } + if (valence) + { + *rfe_file << "$VALENCE" + << "\n"; + *rfe_file << valence << " "; + *rfe_file << "\n"; + } + if (mineral_density > 0) + { + *rfe_file << "$MINERAL_DENSITY" + << "\n"; + *rfe_file << mineral_density << " "; + *rfe_file << "\n"; + } *rfe_file << "\n"; } @@ -786,7 +806,7 @@ if(mineral_density>0){ 09/2004 SB Fitted to CP Class Structure, now CompProperties Member function *************************************************************************/ -double CompProperties::CalcDiffusionCoefficientCP(long index,double theta,CRFProcess* m_pcs) +double CompProperties::CalcDiffusionCoefficientCP(long index, double theta, CRFProcess* m_pcs) { (void)theta; int p_idx = -1, t_idx = -1; @@ -798,17 +818,17 @@ double CompProperties::CalcDiffusionCoefficientCP(long index,double theta,CRFPro double* k = NULL; double Dm; // static long *element_nodes; - CRFProcess* t_pcs = NULL; + CRFProcess* t_pcs = NULL; #ifdef GEM_REACT static int count_nodes; // TF unused variable - fix a compiler warning -// static double eta = 0.0; //, theta = 1.0; - double porosity=1.0,saturation=1.0, dummy=0.0; + // static double eta = 0.0; //, theta = 1.0; + double porosity = 1.0, saturation = 1.0, dummy = 0.0; int i, flowflag; CRFProcess* f_pcs = NULL; #endif // static int p_ind, t_ind; - //OK411 + // OK411 diffusion_average = diffusion_average; pressure_average = pressure_average; temperature_average = temperature_average; @@ -816,217 +836,252 @@ double CompProperties::CalcDiffusionCoefficientCP(long index,double theta,CRFPro t_idx = t_idx; #ifdef GEM_REACT - const long group (m_pcs->m_msh->ele_vector[index]->GetPatchIndex()); - CMediumProperties* m_mat_mp (mmp_vector[group]); + const long group(m_pcs->m_msh->ele_vector[index]->GetPatchIndex()); + CMediumProperties* m_mat_mp(mmp_vector[group]); #endif k = diffusion_model_values; switch (diffusion_model) { - case -1: - return 0.0; //no diffusion specified - case 0: /* curve value */ - { - //DisplayMsgLn("Not implemented"); - return 0.0; - } - case 1: /* Konstanter Diffusionswert */ - { - if (count_of_diffusion_model_values < 1) + case -1: + return 0.0; // no diffusion specified + case 0: /* curve value */ + { + // DisplayMsgLn("Not implemented"); return 0.0; - Dm = k[0]; - return Dm; - } - /* all following cases are handled in CalcTracerDiffusionCoefficient1, and the needed parameters are gathered below */ - case 2: - case 3: - case 4: - case 5: - case 6: - case 7: - /*OK411 - { - count_nodes = ElNumberOfNodes[ElGetElementType(index) - 1]; - element_nodes = ElGetElementNodes(index); - p_ind = 1; - sprintf(name_pres,"PRESSURE%ld",transport_phase+1); - // SB:GS4 todo p_idx = m_pcs->PCSGetNODValueIndexNew(name_pres,1); - if (p_ind) { - pressure_average = 0.0; - for (i = 0; i < count_nodes; i++) - pressure_average += GetNodeVal(element_nodes[i], p_idx); - pressure_average /= count_nodes; - } - t_ind = 1; - if (! GetRFProcessHeatReactModel()){ - DisplayMsgLn("No heat transport active, no temperature available for determination of diffusion coefficient "); - break; - }; - - sprintf(name_heat,"TEMPERATURE%ld",transport_phase+1); - // SB:GS4 todo m_pcs->PCSGetNODValueIndexNew(name_heat,1); - if (t_ind) { - temperature_average = 0.0; - for (i = 0; i < count_nodes; i++) - temperature_average += GetNodeVal(element_nodes[i], t_idx); - temperature_average /= count_nodes; - } - eta = mfp_vector[transport_phase]->Viscosity(); //GetFluidViscosity(transport_phase, index, 0., 0., 0., theta); - diffusion_coefficient = CalcDiffusionCoefficientCP_Method1(index, temperature_average, pressure_average, eta); - element_nodes = NULL; - break; - } - */ -#ifdef GEM_REACT - case 8: /* Archies law De = Dp * tau * tau_zero* poros with tau = poros^m/poros0^m ....tortuosity = tau_zero * tau depends on porosity and tau_zero is multiplicated (like porosity) outside this function */ + } + case 1: /* Konstanter Diffusionswert */ + { + if (count_of_diffusion_model_values < 1) + return 0.0; + Dm = k[0]; + return Dm; + } + /* all following cases are handled in CalcTracerDiffusionCoefficient1, and the needed parameters are gathered + * below */ + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: +/*OK411 { - MeshLib::CElem* m_Elem; - - if (count_of_diffusion_model_values < 2) - return 0.0; - - porosity = m_mat_mp->Porosity(index,theta); - - m_Elem = m_pcs->m_msh->ele_vector[index]; - // we average the diffusion coefficient directly - count_nodes = m_Elem->GetNodesNumber ( false ); - diffusion_average = 0.0; - // we need saturation for multi-phase flow: *** attention: *** only coupling to Richards flow implemented so far - flowflag=m_vec_GEM->REACT_GEM::GetFlowType_MT(); - if (flowflag == 3) - f_pcs = PCSGet ( "RICHARDS_FLOW" ); - - for (i = 0; i < count_nodes; i++) //calculate harmonic mean of node based diffusion coefficients - { - // then get the values from nodes - dummy = m_vec_GEM->REACT_GEM::GetNodePorosityValue(m_Elem->GetNodeIndex ( i )); - // for Multi-Phase flow we also have to account for the saturation......the following line would account for element saturatuions all flow types - if ( flowflag == 3) // RICHARDS_FLOW ...get node based saturations - { - saturation=f_pcs->GetNodeValue ( m_Elem->GetNodeIndex ( i ),f_pcs->GetNodeValueIndex ( "SATURATION1" )+1 ); //current volume of water phase after hydraulic step - } - else - { - saturation=1.0; - } - // Attention....this does not work for gas phase/non wetting phase ....tr_phase=10 - dummy *=saturation; // account for "mean element" saturation in Archies law ....better would be to get node saturations! - Dm = k[0] * pow(dummy,k[1]) * dummy; //node based diffusion coefficient---last porosity is for effective diffusion coefficient - // then get the values for initial porosity from nodes - dummy = m_vec_GEM->REACT_GEM::GetNodePorosityValueInitial(m_Elem->GetNodeIndex ( i )); //ATTENTION: This does not include initial saturation different from 1 - Dm /= pow(dummy,k[1]); //node based diffusion coefficient with modified Archies relation - - diffusion_average += 1.0 / Dm; - // cout << "debug: " << Dm << " porosity: " << GetNodePorosityValue_MT(m_Elem->GetNodeIndex ( i ), 0) << endl; - } - Dm = count_nodes / diffusion_average; // This is now harmonic mean of node diffusion coefficients - // end calculation of diffusion coefficient - if ( flowflag == 3) // RICHARDS_FLOW ...get node based saturations - { - saturation = PCSGetEleMeanNodeSecondary_2(index, m_pcs->flow_pcs_type,"SATURATION1", 1); // this line accounts for element saturatuions for all flow types....of course we have a problem if we have saturation ne 1 and not Richards flow - if (saturation <= 1.0e-20) saturation=1.0e-20; // set to an arbitrary small number to avoid divsion by zero... - } - else - { - saturation=1.0; - } - Dm = Dm / (porosity*saturation); //correct for multiplication with element porosities & saturations -> Pore diffusion coefficient - // cout << " CalcDiffusionCoefficientCP: De: " << Dm*porosity*saturation << " saturation " << saturation << " porosity " << endl; - - return Dm; - } - case 9: /* De is calculated independently from element porosity. We use node porosity values with with Archies law De = Dp * poros^m and do a harmonic average of the node diffusion coefficients! as Dp is part of the dispersion tensor, we modify Dp -> Dp=Dp0*poro^(m-1)*/ - { /* Remark: tortuosity is considered as constant factor and does not change with porosity */ - MeshLib::CElem* m_Elem; - - if (count_of_diffusion_model_values < 2) - return 0.0; - - porosity = m_mat_mp->Porosity(index,theta); - - m_Elem = m_pcs->m_msh->ele_vector[index]; - // we average the diffusion coefficient directly - count_nodes = m_Elem->GetNodesNumber ( false ); - diffusion_average = 0.0; - // we need saturation for multi-phase flow: *** attention: *** only coupling to Richards flow implemented so far - flowflag=m_vec_GEM->REACT_GEM::GetFlowType_MT(); - if (flowflag == 3) - f_pcs = PCSGet ( "RICHARDS_FLOW" ); - - for (i = 0; i < count_nodes; i++) //calculate harmonic mean of node based diffusion coefficients - { - // then get the values from nodes - dummy = m_vec_GEM->REACT_GEM::GetNodePorosityValue(m_Elem->GetNodeIndex ( i )); - // for Multi-Phase flow we also have to account for the saturation......the following line would account for element saturatuions all flow types - if ( flowflag == 3) // RICHARDS_FLOW ...get node based saturations - { - saturation=f_pcs->GetNodeValue ( m_Elem->GetNodeIndex ( i ),f_pcs->GetNodeValueIndex ( "SATURATION1" )+1 ); //current volume of water phase after hydraulic step - } - else - { - saturation=1.0; - } - // Attention....this does not work for gas phase/non wetting phase ....tr_phase=10 - dummy *=saturation; // account for "mean element" saturation in Archies law ....better would be to get node saturations! - Dm = k[0] * pow(dummy,k[1]); //node based diffusion coefficient - - diffusion_average += 1.0 / Dm; - // cout << "debug: " << Dm << " porosity: " << GetNodePorosityValue_MT(m_Elem->GetNodeIndex ( i ), 0) << "\n"; - } - Dm = count_nodes / diffusion_average; // This is now harmonic mean of node diffusion coefficients - // end calculation of diffusion coefficient - if ( flowflag == 3) // RICHARDS_FLOW ...get node based saturations - { - saturation = PCSGetEleMeanNodeSecondary_2(index, m_pcs->flow_pcs_type,"SATURATION1", 1); // this line accounts for element saturatuions for all flow types....of course we have a problem if we have saturation ne 1 and not Richards flow - if (saturation <= 1.0e-20) saturation=1.0e-20; // set to an arbitrary small number to avoid divsion by zero... - } - else - { - saturation=1.0; - } - Dm = Dm / (porosity*saturation); //correct for multiplication with element porosities & saturations -> Pore diffusion coefficient - // cout << " CalcDiffusionCoefficientCP: De: " << Dm*porosity*saturation << " saturation " << saturation << " porosity " << "\n"; - - return Dm; - } + count_nodes = ElNumberOfNodes[ElGetElementType(index) - 1]; + element_nodes = ElGetElementNodes(index); + p_ind = 1; + sprintf(name_pres,"PRESSURE%ld",transport_phase+1); + // SB:GS4 todo p_idx = m_pcs->PCSGetNODValueIndexNew(name_pres,1); + if (p_ind) { + pressure_average = 0.0; + for (i = 0; i < count_nodes; i++) + pressure_average += GetNodeVal(element_nodes[i], p_idx); + pressure_average /= count_nodes; + } + t_ind = 1; + if (! GetRFProcessHeatReactModel()){ + DisplayMsgLn("No heat transport active, no temperature available for determination of diffusion coefficient "); + break; + }; + + sprintf(name_heat,"TEMPERATURE%ld",transport_phase+1); + // SB:GS4 todo m_pcs->PCSGetNODValueIndexNew(name_heat,1); + if (t_ind) { + temperature_average = 0.0; + for (i = 0; i < count_nodes; i++) + temperature_average += GetNodeVal(element_nodes[i], t_idx); + temperature_average /= count_nodes; + } + eta = mfp_vector[transport_phase]->Viscosity(); //GetFluidViscosity(transport_phase, index, 0., 0., 0., theta); + diffusion_coefficient = CalcDiffusionCoefficientCP_Method1(index, temperature_average, pressure_average, eta); + element_nodes = NULL; + break; + } + */ +#ifdef GEM_REACT + case 8: /* Archies law De = Dp * tau * tau_zero* poros with tau = poros^m/poros0^m ....tortuosity = tau_zero + * tau depends on porosity and tau_zero is multiplicated (like porosity) outside this function */ + { + MeshLib::CElem* m_Elem; + + if (count_of_diffusion_model_values < 2) + return 0.0; + + porosity = m_mat_mp->Porosity(index, theta); + + m_Elem = m_pcs->m_msh->ele_vector[index]; + // we average the diffusion coefficient directly + count_nodes = m_Elem->GetNodesNumber(false); + diffusion_average = 0.0; + // we need saturation for multi-phase flow: *** attention: *** only coupling to Richards flow implemented + // so far + flowflag = m_vec_GEM->REACT_GEM::GetFlowType_MT(); + if (flowflag == 3) + f_pcs = PCSGet("RICHARDS_FLOW"); + + for (i = 0; i < count_nodes; i++) // calculate harmonic mean of node based diffusion coefficients + { + // then get the values from nodes + dummy = m_vec_GEM->REACT_GEM::GetNodePorosityValue(m_Elem->GetNodeIndex(i)); + // for Multi-Phase flow we also have to account for the saturation......the following line would account + // for element saturatuions all flow types + if (flowflag == 3) // RICHARDS_FLOW ...get node based saturations + { + saturation = f_pcs->GetNodeValue(m_Elem->GetNodeIndex(i), + f_pcs->GetNodeValueIndex("SATURATION1") + + 1); // current volume of water phase after hydraulic step + } + else + { + saturation = 1.0; + } + // Attention....this does not work for gas phase/non wetting phase ....tr_phase=10 + dummy *= saturation; // account for "mean element" saturation in Archies law ....better would be to get + // node saturations! + Dm = k[0] * pow(dummy, k[1]) + * dummy; // node based diffusion coefficient---last porosity is for effective diffusion coefficient + // then get the values for initial porosity from nodes + dummy = m_vec_GEM->REACT_GEM::GetNodePorosityValueInitial( + m_Elem->GetNodeIndex(i)); // ATTENTION: This does not include initial saturation different from 1 + Dm /= pow(dummy, k[1]); // node based diffusion coefficient with modified Archies relation + + diffusion_average += 1.0 / Dm; + // cout << "debug: " << Dm << " porosity: " << GetNodePorosityValue_MT(m_Elem->GetNodeIndex ( i ), 0) + //<< endl; + } + Dm = count_nodes / diffusion_average; // This is now harmonic mean of node diffusion coefficients + // end calculation of diffusion coefficient + if (flowflag == 3) // RICHARDS_FLOW ...get node based saturations + { + saturation = PCSGetEleMeanNodeSecondary_2( + index, m_pcs->flow_pcs_type, "SATURATION1", 1); // this line accounts for element saturatuions for + // all flow types....of course we have a problem if + // we have saturation ne 1 and not Richards flow + if (saturation <= 1.0e-20) + saturation = 1.0e-20; // set to an arbitrary small number to avoid divsion by zero... + } + else + { + saturation = 1.0; + } + Dm = Dm / (porosity * saturation); // correct for multiplication with element porosities & saturations -> + // Pore diffusion coefficient + // cout << " CalcDiffusionCoefficientCP: De: " << Dm*porosity*saturation << " saturation " << + // saturation << " porosity " << endl; + + return Dm; + } + case 9: /* De is calculated independently from element porosity. We use node porosity values with with Archies + law De = Dp * poros^m and do a harmonic average of the node diffusion coefficients! as Dp is part + of the dispersion tensor, we modify Dp -> Dp=Dp0*poro^(m-1)*/ + { /* Remark: tortuosity is considered as constant factor and does not change with porosity */ + MeshLib::CElem* m_Elem; + + if (count_of_diffusion_model_values < 2) + return 0.0; + + porosity = m_mat_mp->Porosity(index, theta); + + m_Elem = m_pcs->m_msh->ele_vector[index]; + // we average the diffusion coefficient directly + count_nodes = m_Elem->GetNodesNumber(false); + diffusion_average = 0.0; + // we need saturation for multi-phase flow: *** attention: *** only coupling to Richards flow implemented + // so far + flowflag = m_vec_GEM->REACT_GEM::GetFlowType_MT(); + if (flowflag == 3) + f_pcs = PCSGet("RICHARDS_FLOW"); + + for (i = 0; i < count_nodes; i++) // calculate harmonic mean of node based diffusion coefficients + { + // then get the values from nodes + dummy = m_vec_GEM->REACT_GEM::GetNodePorosityValue(m_Elem->GetNodeIndex(i)); + // for Multi-Phase flow we also have to account for the saturation......the following line would account + // for element saturatuions all flow types + if (flowflag == 3) // RICHARDS_FLOW ...get node based saturations + { + saturation = f_pcs->GetNodeValue(m_Elem->GetNodeIndex(i), + f_pcs->GetNodeValueIndex("SATURATION1") + + 1); // current volume of water phase after hydraulic step + } + else + { + saturation = 1.0; + } + // Attention....this does not work for gas phase/non wetting phase ....tr_phase=10 + dummy *= saturation; // account for "mean element" saturation in Archies law ....better would be to get + // node saturations! + Dm = k[0] * pow(dummy, k[1]); // node based diffusion coefficient + + diffusion_average += 1.0 / Dm; + // cout << "debug: " << Dm << " porosity: " << GetNodePorosityValue_MT(m_Elem->GetNodeIndex ( i ), 0) + //<< "\n"; + } + Dm = count_nodes / diffusion_average; // This is now harmonic mean of node diffusion coefficients + // end calculation of diffusion coefficient + if (flowflag == 3) // RICHARDS_FLOW ...get node based saturations + { + saturation = PCSGetEleMeanNodeSecondary_2( + index, m_pcs->flow_pcs_type, "SATURATION1", 1); // this line accounts for element saturatuions for + // all flow types....of course we have a problem if + // we have saturation ne 1 and not Richards flow + if (saturation <= 1.0e-20) + saturation = 1.0e-20; // set to an arbitrary small number to avoid divsion by zero... + } + else + { + saturation = 1.0; + } + Dm = Dm / (porosity * saturation); // correct for multiplication with element porosities & saturations -> + // Pore diffusion coefficient + // cout << " CalcDiffusionCoefficientCP: De: " << Dm*porosity*saturation << " saturation " << + // saturation << " porosity " << "\n"; + + return Dm; + } #endif - case 10: // Temperature dependence Yaws - { - if (count_of_diffusion_model_values < 2) - return 0.0; - temperature_average = 0; - size_t nnodes = m_pcs->m_msh->ele_vector[index]->GetNodesNumber(false); - if(REACTINT_vec.size()>0){ - for(size_t i=0; im_msh->ele_vector[index]->GetNodeIndex(i); - temperature_average+= REACTINT_vec[0]->GetTemperature(node)/ double(nnodes); - } - } - else if((t_pcs = PCSGet("HEAT_TRANSPORT"))){ - //t_pcs = PCSGet("HEAT_TRANSPORT"); - int idx_t = t_pcs->GetNodeValueIndex("TEMPERATURE1")+1; - for(size_t i=0; i< nnodes ;i++){ - long node = m_pcs->m_msh->ele_vector[index]->GetNodeIndex(i); - temperature_average+= t_pcs->GetNodeValue(node, idx_t)/ double(nnodes); - } - } - //else - // return 0; - if(temperature_average >0) - Dm = pow(10, (k[0]+k[1]/temperature_average)) / 10000; //cm^2/s -> m^2/s; - else{ - Dm = 0; - DisplayMsgLn("Something wrong in diffusion model 10! T = 0."); - } - //A = -1.4943; //Daq(T) PCE - //B = -1059.0; //Daq(T) PCE - return Dm; - } - - default: - DisplayMsgLn("Unknown diffusion model!"); - break; + case 10: // Temperature dependence Yaws + { + if (count_of_diffusion_model_values < 2) + return 0.0; + temperature_average = 0; + size_t nnodes = m_pcs->m_msh->ele_vector[index]->GetNodesNumber(false); + if (REACTINT_vec.size() > 0) + { + for (size_t i = 0; i < nnodes; i++) + { + long node = m_pcs->m_msh->ele_vector[index]->GetNodeIndex(i); + temperature_average += REACTINT_vec[0]->GetTemperature(node) / double(nnodes); + } + } + else if ((t_pcs = PCSGet("HEAT_TRANSPORT"))) + { + // t_pcs = PCSGet("HEAT_TRANSPORT"); + int idx_t = t_pcs->GetNodeValueIndex("TEMPERATURE1") + 1; + for (size_t i = 0; i < nnodes; i++) + { + long node = m_pcs->m_msh->ele_vector[index]->GetNodeIndex(i); + temperature_average += t_pcs->GetNodeValue(node, idx_t) / double(nnodes); + } + } + // else + // return 0; + if (temperature_average > 0) + Dm = pow(10, (k[0] + k[1] / temperature_average)) / 10000; // cm^2/s -> m^2/s; + else + { + Dm = 0; + DisplayMsgLn("Something wrong in diffusion model 10! T = 0."); + } + // A = -1.4943; //Daq(T) PCE + // B = -1059.0; //Daq(T) PCE + return Dm; + } + + default: + DisplayMsgLn("Unknown diffusion model!"); + break; } /* switch */ @@ -1065,27 +1120,24 @@ double CompProperties::CalcDiffusionCoefficientCP(long index,double theta,CRFPro 09/2004 SB MOved to Class CompProperties as member function */ /**************************************************************************/ -double CompProperties::CalcDiffusionCoefficientCP_Method1(long index, - double T, - double P, - double eta) +double CompProperties::CalcDiffusionCoefficientCP_Method1(long index, double T, double P, double eta) { - int diffusion_model = 0; //SB:cp GetTracerDiffusionModel(index, phase, component); + int diffusion_model = 0; // SB:cp GetTracerDiffusionModel(index, phase, component); double* k = NULL; int count = 0; double t = aktuelle_zeit; double msol, Vs; - double Dm, Daq; //WW, Dg; + double Dm, Daq; // WW, Dg; double Kb, Rm; - //WW int curve; - double mg = 28.97; /* Mol.-Gew. Luft [g/mol] */ - double Vg = 20.1; /* molares Volumen von Luft [cm^3/mol] */ + // WW int curve; + double mg = 28.97; /* Mol.-Gew. Luft [g/mol] */ + double Vg = 20.1; /* molares Volumen von Luft [cm^3/mol] */ - double m; /* Molekulargewicht der diffundierenden Substanz [g/mol] */ - double V; /* molares Volumen der diffundierenden Substanz [cm^3/mol] */ + double m; /* Molekulargewicht der diffundierenden Substanz [g/mol] */ + double V; /* molares Volumen der diffundierenden Substanz [cm^3/mol] */ /* In erster Naeherung: Quotient Mol.-Gew./Dichte */ - double p = P / 101325.; /* Umrechnen P in Pascal in p in atm */ + double p = P / 101325.; /* Umrechnen P in Pascal in p in atm */ index = index; if (t < 0.0 || eta < 0.0) @@ -1095,74 +1147,71 @@ double CompProperties::CalcDiffusionCoefficientCP_Method1(long index, switch (diffusion_model) { - case 0: /* Keine Diffusion */ - { - return 0.0; - } - case 1: /* Konstanter Diffusionswert */ - { - if (count < 1) - return 0.0; - Dm = k[0]; - return Dm; - } - case 2: /* Variabler Diffusionswert (Zeitabhaengig). Abhaegigkeit ueber Kurve */ - { - if (count < 1) - return 0.0; - Dm = k[0]; - //WW curve = (int) k[1]; - return Dm; - } - case 3: /* Worch, 1993 */ - { - if (count < 1) - return 0.0; - m = k[0]; - Daq = 3.595e-7 * T / eta / pow(m, 0.53) * 1.e-4; - return Daq; - } - case 4: /* Hayduk und Laudie, 1974 */ - { - if (count < 1) - return 0.0; - V = k[0]; - Daq = 13.26e-5 / pow(eta, 1.14) / pow(V, 0.589) * 1.e-4; - return Daq; - } - case 5: /* Wilke und Chang, 1955 */ - { - if (count < 2) - return 0.0; - msol = k[0]; - Vs = k[0]; - Daq = 7.4e-8* T* sqrt(msol) / eta / pow(Vs, 0.6) * 1.e-4; - return Daq; - } - case 6: /* Stokes-Einstein (fuer Partikel/Makromolekuele) */ - { - if (count < 1) - return 0.0; - Rm = k[0]; - Kb = 1.38066e-23; /* Boltzmann Konstante [J/K] */ - Daq = Kb * T / 6. / PI / Rm / eta * 1.e-4; - return Daq; - } - case 7: /* FSG-Methode, Lyman et al., 1990 */ - { - if (count < 2) + case 0: /* Keine Diffusion */ + { return 0.0; - m = k[0]; - V = k[1]; - Vg = 20.1; /* Molares Volumen von Luft [cm?/mol] */ - //WW Dg = (0.001 * pow(T, 1.75) * sqrt(1. / mg + 1. / m)) / (p * pow(pow(Vg, 1. / 3.) + pow(V, 1. / 3.), 2.)) * 1.e-4; - return (0.001 * - pow(T, - 1.75) * - sqrt(1. / mg + 1. / - m)) / - (p * MathLib::fastpow(pow(Vg, 1. / 3.) + pow(V, 1. / 3.), 2)) * 1.e-4; //WW - } + } + case 1: /* Konstanter Diffusionswert */ + { + if (count < 1) + return 0.0; + Dm = k[0]; + return Dm; + } + case 2: /* Variabler Diffusionswert (Zeitabhaengig). Abhaegigkeit ueber Kurve */ + { + if (count < 1) + return 0.0; + Dm = k[0]; + // WW curve = (int) k[1]; + return Dm; + } + case 3: /* Worch, 1993 */ + { + if (count < 1) + return 0.0; + m = k[0]; + Daq = 3.595e-7 * T / eta / pow(m, 0.53) * 1.e-4; + return Daq; + } + case 4: /* Hayduk und Laudie, 1974 */ + { + if (count < 1) + return 0.0; + V = k[0]; + Daq = 13.26e-5 / pow(eta, 1.14) / pow(V, 0.589) * 1.e-4; + return Daq; + } + case 5: /* Wilke und Chang, 1955 */ + { + if (count < 2) + return 0.0; + msol = k[0]; + Vs = k[0]; + Daq = 7.4e-8 * T * sqrt(msol) / eta / pow(Vs, 0.6) * 1.e-4; + return Daq; + } + case 6: /* Stokes-Einstein (fuer Partikel/Makromolekuele) */ + { + if (count < 1) + return 0.0; + Rm = k[0]; + Kb = 1.38066e-23; /* Boltzmann Konstante [J/K] */ + Daq = Kb * T / 6. / PI / Rm / eta * 1.e-4; + return Daq; + } + case 7: /* FSG-Methode, Lyman et al., 1990 */ + { + if (count < 2) + return 0.0; + m = k[0]; + V = k[1]; + Vg = 20.1; /* Molares Volumen von Luft [cm?/mol] */ + // WW Dg = (0.001 * pow(T, 1.75) * sqrt(1. / mg + 1. / m)) / (p * pow(pow(Vg, 1. / 3.) + pow(V, 1. / 3.), + // 2.)) * 1.e-4; + return (0.001 * pow(T, 1.75) * sqrt(1. / mg + 1. / m)) + / (p * MathLib::fastpow(pow(Vg, 1. / 3.) + pow(V, 1. / 3.), 2)) * 1.e-4; // WW + } } DisplayMsgLn("Unknown diffusion model specified!"); return 0.; @@ -1195,46 +1244,47 @@ int CompProperties::GetNumberDiffusionValuesCompProperties(int diffusion_model) switch (diffusion_model) { - case -1: - n = 0; - break; /* Keine Diffusion */ - case 0: /* curve */ - n = 1; - case 1: - n = 1; - break; /* Konstanter Diffusionswert */ - case 2: - n = 1; - break; /* Variabler Diffusionswert (Zeitabhaengig) */ - - /* Diffusionskoeffizienten in Wasser Daq [m^2/s] */ - case 3: - n = 1; - break; /* Worch, 1993 */ - case 4: - n = 1; - break; /* Hayduk und Laudie, 1974 */ - case 5: - n = 2; - break; /* Wilke und Chang, 1955 */ - case 6: - n = 1; - break; /* Stokes-Einstein (fuer Partikel/Makromolekuele) */ - - /* Diffusionskoeffizienten in Luft Dg [m^2/s] */ - case 7: - n = 2; - break; /* FSG-Methode, Lyman et al., 1990 */ - case 8: - n = 2; - break; /* Archies Law */ - case 9: - n = 2; - break; /* Archies Law */ - case 10: - n = 2; break; /* Yaws empirical model*/ - - } /* switch */ + case -1: + n = 0; + break; /* Keine Diffusion */ + case 0: /* curve */ + n = 1; + case 1: + n = 1; + break; /* Konstanter Diffusionswert */ + case 2: + n = 1; + break; /* Variabler Diffusionswert (Zeitabhaengig) */ + + /* Diffusionskoeffizienten in Wasser Daq [m^2/s] */ + case 3: + n = 1; + break; /* Worch, 1993 */ + case 4: + n = 1; + break; /* Hayduk und Laudie, 1974 */ + case 5: + n = 2; + break; /* Wilke und Chang, 1955 */ + case 6: + n = 1; + break; /* Stokes-Einstein (fuer Partikel/Makromolekuele) */ + + /* Diffusionskoeffizienten in Luft Dg [m^2/s] */ + case 7: + n = 2; + break; /* FSG-Methode, Lyman et al., 1990 */ + case 8: + n = 2; + break; /* Archies Law */ + case 9: + n = 2; + break; /* Archies Law */ + case 10: + n = 2; + break; /* Yaws empirical model*/ + + } /* switch */ /* switch */ @@ -1268,18 +1318,22 @@ int CompProperties::GetNumberDecayValuesCompProperties(int decay_model) switch (decay_model) { - case -1: n = 0; - break; - case 0: n = 1; - break; /* No Decay */ - case 1: n = 2; - break; /* Any Order Decay with constant Decay Rate */ - case 2: n = 2; - break; /* Monod or Michaelis-Menten kinetics with constant rate coefficients */ - default: - DisplayMsgLn(" Error: Unknown model for decay "); - break; - } /* switch */ + case -1: + n = 0; + break; + case 0: + n = 1; + break; /* No Decay */ + case 1: + n = 2; + break; /* Any Order Decay with constant Decay Rate */ + case 2: + n = 2; + break; /* Monod or Michaelis-Menten kinetics with constant rate coefficients */ + default: + DisplayMsgLn(" Error: Unknown model for decay "); + break; + } /* switch */ return n; } @@ -1311,50 +1365,51 @@ int CompProperties::GetNumberIsothermValuesCompProperties(int isotherm) switch (isotherm) { - case -1: n = 0; /* no isotherm */ - case 0: - n = 1; - break; /* get KD from curve derivative */ - case 1: - n = 1; - break; /* Henry Isotherm */ - case 2: - n = 2; - break; /* Freundlich Isotherm */ - case 3: - n = 2; - break; /* Langmuir Isotherm */ - case 4: - n = 1; - break; /* Linear Isotherm, for fracture surface CMCD */ - case 5: - n = 3; - break; /* two-rate model */ - /* - case 4: - n = 3; break; // Freundlich Langmuir Isotherm - case 5: - n = 4; break; // Double Langmuir Isotherm - case 6: - n = 3; break; // Extented Freundlich Isotherm - case 7: - n = 3; break; // Gunary Isotherm - case 8: - n = 3; break; // Fitter-Sutton Isotherm - case 9: - n = 4; break; // Barry Isotherm - case 10: - n = 2; break; // Power Isotherm - case 11: - n = 2; break; // Modified Kielland Isotherm - */ - /* case 15: - n=1; break; - */ - default: - DisplayMsgLn(" Error - this ISOTHERM model found "); - break; - } /* switch */ + case -1: + n = 0; /* no isotherm */ + case 0: + n = 1; + break; /* get KD from curve derivative */ + case 1: + n = 1; + break; /* Henry Isotherm */ + case 2: + n = 2; + break; /* Freundlich Isotherm */ + case 3: + n = 2; + break; /* Langmuir Isotherm */ + case 4: + n = 1; + break; /* Linear Isotherm, for fracture surface CMCD */ + case 5: + n = 3; + break; /* two-rate model */ + /* + case 4: + n = 3; break; // Freundlich Langmuir Isotherm + case 5: + n = 4; break; // Double Langmuir Isotherm + case 6: + n = 3; break; // Extented Freundlich Isotherm + case 7: + n = 3; break; // Gunary Isotherm + case 8: + n = 3; break; // Fitter-Sutton Isotherm + case 9: + n = 4; break; // Barry Isotherm + case 10: + n = 2; break; // Power Isotherm + case 11: + n = 2; break; // Modified Kielland Isotherm + */ + /* case 15: + n=1; break; + */ + default: + DisplayMsgLn(" Error - this ISOTHERM model found "); + break; + } /* switch */ return n; } @@ -1377,15 +1432,15 @@ int CompProperties::GetNumberIsothermValuesCompProperties(int isotherm) 04/2003 SB Erste Version 09/2004 SB Moved to Class CompProperties as member function **************************************************************************/ -double CompProperties::CalcElementRetardationFactorNew( long index, double* gp, CRFProcess* m_pcs) +double CompProperties::CalcElementRetardationFactorNew(long index, double* gp, CRFProcess* m_pcs) { - static double porosity,density_rock,isotherm; + static double porosity, density_rock, isotherm; static double conc, retard = 0.0; double theta = m_pcs->m_num->ls_theta; int gueltig; - long group = 0; //SB4200 ToDO - double fracture_width = 0.0; //CMCD needed for wall retardation in a fracture - gp = gp; //OK411 + long group = 0; // SB4200 ToDO + double fracture_width = 0.0; // CMCD needed for wall retardation in a fracture + gp = gp; // OK411 group = m_pcs->m_msh->ele_vector[index]->GetPatchIndex(); @@ -1396,75 +1451,76 @@ double CompProperties::CalcElementRetardationFactorNew( long index, double* gp, m_msp = msp_vector[group]; // porosity = GetSoilPorosity(index); - porosity = m_mat_mp->Porosity(index,theta); + porosity = m_mat_mp->Porosity(index, theta); // porosity = 0.5; //SB- set porosity // density_rock = 2000.0; // GetSolidDensity(index); density_rock = fabs(m_msp->Density()); - //SB-todo: CHeck saturatiuon dependence + // SB-todo: CHeck saturatiuon dependence /* Get mean element concentration from last time step */ conc = CalcElementMeanConcNew(index, m_pcs); /* DisplayMsg(" Mean conc: "); DisplayDouble(conc,0,0); DisplayMsgLn(" "); */ - switch(isotherm_model) + switch (isotherm_model) { - case -1: /* no sorption */ - isotherm = 0.0; - //CMCD moved here - retard = 1. + (1. - porosity) * density_rock * isotherm / porosity; - break; - case 0: /* from curve */ - isotherm = 0.0; - isotherm = GetCurveDerivative((int) isotherm_function_name, 0, fabs(conc), &gueltig); - //CB added here 31.10.07 - retard = 1. + (1. - porosity) * density_rock * isotherm / porosity; - break; - case 1: /* linear isotherm */ - isotherm = isotherm_model_values[0]; - // retard = 1. + density_rock*isotherm/porosity;//CMCD moved here - //CMCD moved here - retard = 1. + (1. - porosity) * density_rock * isotherm / porosity; - break; - /* rausgenommen, solange der PRozess linear ist */ - case 2: /* Freundlich Isotherm */ - /* Freundlich is linear */ - if(fabs(isotherm_model_values[1] - 1.0) < MKleinsteZahl) + case -1: /* no sorption */ + isotherm = 0.0; + // CMCD moved here + retard = 1. + (1. - porosity) * density_rock * isotherm / porosity; + break; + case 0: /* from curve */ + isotherm = 0.0; + isotherm = GetCurveDerivative((int)isotherm_function_name, 0, fabs(conc), &gueltig); + // CB added here 31.10.07 + retard = 1. + (1. - porosity) * density_rock * isotherm / porosity; + break; + case 1: /* linear isotherm */ isotherm = isotherm_model_values[0]; - else - if(fabs(conc) < MKleinsteZahl) + // retard = 1. + density_rock*isotherm/porosity;//CMCD moved here + // CMCD moved here + retard = 1. + (1. - porosity) * density_rock * isotherm / porosity; + break; + /* rausgenommen, solange der PRozess linear ist */ + case 2: /* Freundlich Isotherm */ + /* Freundlich is linear */ + if (fabs(isotherm_model_values[1] - 1.0) < MKleinsteZahl) + isotherm = isotherm_model_values[0]; + else if (fabs(conc) < MKleinsteZahl) + isotherm = isotherm_model_values[0]; + else + isotherm = isotherm_model_values[0] * isotherm_model_values[1] + * pow(fabs(conc), isotherm_model_values[1] - 1.0); + // CMCD moved here + retard = 1. + (1. - porosity) * density_rock * isotherm / porosity; + break; + case 3: /* Langmuir Isotherm */ + isotherm = isotherm_model_values[0] * isotherm_model_values[1] + / MathLib::fastpow((1 + isotherm_model_values[0] * fabs(conc)), 2); + // CMCD moved here + retard = 1. + (1. - porosity) * density_rock * isotherm / porosity; + break; + case 4: /* Face retardation model*/ isotherm = isotherm_model_values[0]; - else - isotherm = isotherm_model_values[0] * isotherm_model_values[1] * - pow(fabs(conc),isotherm_model_values[1] - 1.0); - //CMCD moved here - retard = 1. + (1. - porosity) * density_rock * isotherm / porosity; - break; - case 3: /* Langmuir Isotherm */ - isotherm = isotherm_model_values[0] * isotherm_model_values[1] / - MathLib::fastpow((1 + isotherm_model_values[0] * fabs(conc)),2); - //CMCD moved here - retard = 1. + (1. - porosity) * density_rock * isotherm / porosity; - break; - case 4: /* Face retardation model*/ - isotherm = isotherm_model_values[0]; - fracture_width = m_pcs->m_msh->ele_vector[index]->GetFluxArea(); - //Tang et al. 1981, Contaminant transport in fractured porous media, anaylitacl solution for a single fracture, WRR 17, 3, 555-564. - retard = 1 + (isotherm / (fracture_width / 2.0)); - break; - case 5: /* two-rate model */ - break; //YS: the two-rate model is described in the RWPT - // case 15: /* Input by curve */ - // isotherm = 0.0; - // isotherm = GetCurveDerivative((int) isotherm_model_values[0], 0, fabs(conc), &gueltig); - // break; - default: - DisplayMsgLn("Unknown sorption isotherm type. Assuming no sorption"); - isotherm = 0.0; - //CMCD moved here - retard = 1. + (1. - porosity) * density_rock * isotherm / porosity; - break; + fracture_width = m_pcs->m_msh->ele_vector[index]->GetFluxArea(); + // Tang et al. 1981, Contaminant transport in fractured porous media, anaylitacl solution for a single + // fracture, WRR 17, 3, 555-564. + retard = 1 + (isotherm / (fracture_width / 2.0)); + break; + case 5: /* two-rate model */ + break; // YS: the two-rate model is described in the RWPT + // case 15: /* Input by curve */ + // isotherm = 0.0; + // isotherm = GetCurveDerivative((int) isotherm_model_values[0], 0, fabs(conc), &gueltig); + // break; + default: + DisplayMsgLn("Unknown sorption isotherm type. Assuming no sorption"); + isotherm = 0.0; + // CMCD moved here + retard = 1. + (1. - porosity) * density_rock * isotherm / porosity; + break; } - // DisplayMsg(" conc: "); DisplayDouble(conc,0,0);DisplayMsg(" isotherm: "); DisplayDouble(isotherm,0,0); DisplayMsgLn(" "); + // DisplayMsg(" conc: "); DisplayDouble(conc,0,0);DisplayMsg(" isotherm: "); DisplayDouble(isotherm,0,0); + // DisplayMsgLn(" "); // if(conc < 0.0) isotherm = 0.0; // retard = 1. + (1.-porosity)*density_rock*isotherm/porosity; Case 4 doesn't use this function. @@ -1484,18 +1540,18 @@ double CompProperties::CalcElementRetardationFactorNew( long index, double* gp, 04/2003 SB Erste Version 09/2004 SB Moved to Class CompProperties as member function **************************************************************************/ -double CompProperties::CalcElementMeanConcNew (long index, CRFProcess* m_pcs) +double CompProperties::CalcElementMeanConcNew(long index, CRFProcess* m_pcs) { - static long i, nn, idx; + static long i, nn, idx; // static long *element_nodes; static double val, val1, val2; - double theta; //GetNumericalTimeCollocation("TRANSPORT"); + double theta; // GetNumericalTimeCollocation("TRANSPORT"); // CFEMesh* m_msh = m_pcs->m_msh; // Get mesh from Process MeshLib::CElem* elem = NULL; elem = m_pcs->m_msh->ele_vector[index]; nn = elem->GetVertexNumber(); - idx = m_pcs->GetNodeValueIndex((char*) compname.data()); + idx = m_pcs->GetNodeValueIndex((char*)compname.data()); theta = m_pcs->m_num->ls_theta; /* get Value after last iteration */ /* @@ -1513,8 +1569,8 @@ double CompProperties::CalcElementMeanConcNew (long index, CRFProcess* m_pcs) } */ val1 = 0.0; - for(i = 0; i < nn; i++) - val1 += m_pcs->GetNodeValue(elem->GetNodeIndex(i),idx); + for (i = 0; i < nn; i++) + val1 += m_pcs->GetNodeValue(elem->GetNodeIndex(i), idx); val1 /= (double)nn; /* get value from beginning of timestep */ @@ -1533,12 +1589,13 @@ double CompProperties::CalcElementMeanConcNew (long index, CRFProcess* m_pcs) } */ val2 = 0.0; - for(i = 0; i < nn; i++) - val2 += m_pcs->GetNodeValue(elem->GetNodeIndex(i),idx + 1); + for (i = 0; i < nn; i++) + val2 += m_pcs->GetNodeValue(elem->GetNodeIndex(i), idx + 1); val2 /= (double)nn; /* calculate mean value */ - // DisplayMsgLn(" "); DisplayMsg(" val1: "); DisplayDouble(val1,0,0);DisplayMsg(", val2: "); DisplayDouble(val2,0,0); DisplayMsgLn(""); + // DisplayMsgLn(" "); DisplayMsg(" val1: "); DisplayDouble(val1,0,0);DisplayMsg(", val2: "); + // DisplayDouble(val2,0,0); DisplayMsgLn(""); val = theta * val1 + (1.0 - theta) * val2; return val; @@ -1562,7 +1619,7 @@ double CompProperties::CalcElementMeanConcNew (long index, CRFProcess* m_pcs) 04/2003 SB Erste Version 09/2004 SB Moved to Class CompProperties as member function **************************************************************************/ -double CompProperties::CalcElementDecayRateNew( long index, CRFProcess* m_pcs) +double CompProperties::CalcElementDecayRateNew(long index, CRFProcess* m_pcs) { static double conc, lambda = 0.0; int gueltig; @@ -1571,65 +1628,64 @@ double CompProperties::CalcElementDecayRateNew( long index, CRFProcess* m_pcs) /* Get mean element concentration from last time step */ conc = CalcElementMeanConcNew(index, m_pcs); - switch(decay_model) + switch (decay_model) { - case -1: /* no decay */ - lambda = 0.0; - break; - case 0: /* curve - linear interpolation*/ - lambda = 0.0; - lambda = GetCurveValue((int) decay_function_name, 0, fabs(conc), &gueltig); - break; - case 1: /* Any order decay with n > 1 */ - if(fabs(decay_model_values[1] - 1.0) < MKleinsteZahl) - { - /* First order decay */ - lambda = decay_model_values[0]; + case -1: /* no decay */ + lambda = 0.0; break; - } - /* zero - order decay */ - else if(decay_model_values[1] < MKleinsteZahl) - { - if(fabs(conc) < MKleinsteZahl) - lambda = decay_model_values[0]; - else - lambda = decay_model_values[0] / conc; - } - else - { - /* Any order decay with n not equal to one or zero*/ - if(fabs(conc) < MKleinsteZahl) + case 0: /* curve - linear interpolation*/ + lambda = 0.0; + lambda = GetCurveValue((int)decay_function_name, 0, fabs(conc), &gueltig); + break; + case 1: /* Any order decay with n > 1 */ + if (fabs(decay_model_values[1] - 1.0) < MKleinsteZahl) + { + /* First order decay */ lambda = decay_model_values[0]; + break; + } + /* zero - order decay */ + else if (decay_model_values[1] < MKleinsteZahl) + { + if (fabs(conc) < MKleinsteZahl) + lambda = decay_model_values[0]; + else + lambda = decay_model_values[0] / conc; + } else - lambda = decay_model_values[0] * - pow(fabs(conc),decay_model_values[1] - 1.0); - } - break; - case 2: /* Monod-Kinetics */ - lambda = decay_model_values[0] / (decay_model_values[1] + conc); - break; - default: - lambda = 0.0; - break; + { + /* Any order decay with n not equal to one or zero*/ + if (fabs(conc) < MKleinsteZahl) + lambda = decay_model_values[0]; + else + lambda = decay_model_values[0] * pow(fabs(conc), decay_model_values[1] - 1.0); + } + break; + case 2: /* Monod-Kinetics */ + lambda = decay_model_values[0] / (decay_model_values[1] + conc); + break; + default: + lambda = 0.0; + break; } // if(index < 0){DisplayMsg(" Decay Rate lambda: "); DisplayDouble(lambda,0,0); DisplayMsgLn(" ");} return lambda; } -//SB:todo Wie kann ich die gut ersetzen (wird nur in loop_pcs gebraucht, um zu schauen ob der process mobil ist ?? +// SB:todo Wie kann ich die gut ersetzen (wird nur in loop_pcs gebraucht, um zu schauen ob der process mobil ist ?? int CPGetMobil(long comp) { int mobil = -1; CompProperties* cp_single = NULL; cp_single = cp_vec[comp]; - if(cp_single == NULL) + if (cp_single == NULL) { DisplayMsgLn("The requested component properties are not defined!"); return 0; } mobil = cp_single->mobil; - if(mobil < 0) + if (mobil < 0) DisplayMsgLn("Error getting component property"); return mobil; @@ -1684,7 +1740,7 @@ void MCPDelete() { long i; int no_mcp = (int)cp_vec.size(); - for(i = 0; i < no_mcp; i++) + for (i = 0; i < no_mcp; i++) delete cp_vec[i]; cp_vec.clear(); } diff --git a/FEM/rfmat_cp.h b/FEM/rfmat_cp.h index ef7b3e4bf..ec8a44a80 100644 --- a/FEM/rfmat_cp.h +++ b/FEM/rfmat_cp.h @@ -23,7 +23,7 @@ #define rfmat_cp_INC #include "ProcessInfo.h" -#define CP_FILE_EXTENSION ".mcp" /* File extension for component properties input file */ +#define CP_FILE_EXTENSION ".mcp" /* File extension for component properties input file */ #include #include #include @@ -39,63 +39,62 @@ class CompProperties : public ProcessInfo { private: public: - /* constructor */ CompProperties(); /* destructor */ ~CompProperties(void); - size_t idx; /* the unique index of this component. not effective, saved for future*/ - std::string compname; /* component name */ - std::string iupac_formula; // chemical formula - int mobil; /* flag mobil */ - int transport_phase; /* number of phase, in which component is transported */ + size_t idx; /* the unique index of this component. not effective, saved for future*/ + std::string compname; /* component name */ + std::string iupac_formula; // chemical formula + int mobil; /* flag mobil */ + int transport_phase; /* number of phase, in which component is transported */ int fluid_phase; - int valence; // valence of ionic elements /*MX*/ + int valence; // valence of ionic elements /*MX*/ double molar_mass; - double pc; //Critical pressure [Pa] - double omega; // accentric factor [-] - double Tc; // Critical temperature [K] - int fluid_id; // Requred to detect a particular fluid from *.mcp files: 0 for CO2; 1 for H2O; 2 for CH4; 3 for N2 - double Vm; // Vm [m3/kmol]: Molar volume used in interation parameter calculation - double Vd; //[cm3/mol] diffusion volume - int OutputMassOfComponentInModel; // 05/2012 BG + double pc; // Critical pressure [Pa] + double omega; // accentric factor [-] + double Tc; // Critical temperature [K] + int fluid_id; // Requred to detect a particular fluid from *.mcp files: 0 for CO2; 1 for H2O; 2 for CH4; 3 for N2 + double Vm; // Vm [m3/kmol]: Molar volume used in interation parameter calculation + double Vd; //[cm3/mol] diffusion volume + int OutputMassOfComponentInModel; // 05/2012 BG /* Diffusionsmodelle und zugehoerige Beschreibungswerte */ - int diffusion_model; /* Zerfallsmodell in geloester Phase */ - int count_of_diffusion_model_values; /* Anzahl der Parameter zur Spezifikation des Diffusionsmodells */ - double diffusion_model_values[10]; /* Parameter fuer das Diffusionsmodell */ + int diffusion_model; /* Zerfallsmodell in geloester Phase */ + int count_of_diffusion_model_values; /* Anzahl der Parameter zur Spezifikation des Diffusionsmodells */ + double diffusion_model_values[10]; /* Parameter fuer das Diffusionsmodell */ double diffusion_anisotropy_ratio[3]; /* Ratio of three diffusion coefficients */ // PCH int diffusion_function_name; /* Zugriff auf Number of Parameters */ - int GetNumberDiffusionValuesCompProperties(int ); + int GetNumberDiffusionValuesCompProperties(int); /* Zerfallsmodelle und zugehoerige Beschreibungswerte in der geloesten Phase */ - int decay_model; /* Zerfallsmodell in geloester Phase */ - int count_of_decay_model_values; /* Anzahl und Werte zur Spezifikation der */ - double decay_model_values[10]; /* Parameter fuer Zerfallsprozess wie z.B. Zerfallsrate */ + int decay_model; /* Zerfallsmodell in geloester Phase */ + int count_of_decay_model_values; /* Anzahl und Werte zur Spezifikation der */ + double decay_model_values[10]; /* Parameter fuer Zerfallsprozess wie z.B. Zerfallsrate */ int decay_function_name; int GetNumberDecayValuesCompProperties(int); /* Zugriff auf Number of Parameters */ /* Sorption */ - int isotherm_model; /* Isothermen-Typ */ - int count_of_isotherm_model_values; /* Anzahl der Isothermen-Koeffizienten */ - double isotherm_model_values[10]; /* Isothermen-Koeffizienten */ + int isotherm_model; /* Isothermen-Typ */ + int count_of_isotherm_model_values; /* Anzahl der Isothermen-Koeffizienten */ + double isotherm_model_values[10]; /* Isothermen-Koeffizienten */ int isotherm_function_name; /* Zugriff auf Number of Parameters */ int GetNumberIsothermValuesCompProperties(int); /* bubble velocity */ int bubble_velocity_model; - double bubble_velocity[3]; /* velocity of rising bubbles */ + double bubble_velocity[3]; /* velocity of rising bubbles */ /* parameters for NAPL dissolution CB140708 */ double molar_density; double molar_weight; double max_solubility; - /* parameters for mineral kinetics */ - double a_zero; + /* parameters for mineral kinetics */ + double a_zero; - double mineral_density; + double mineral_density; //// CB _ctx_ // bool _ctx_; @@ -103,34 +102,34 @@ class CompProperties : public ProcessInfo // double _ctx_Coefficient; #ifdef GEM_REACT - //kg44 25.11.2008 kinetics...for coupling with GEMS + // kg44 25.11.2008 kinetics...for coupling with GEMS // - int kinetic_model; // only 1 = GEMS implemented right now - int n_activities; // number of species for activities - std::string active_species[10]; // name for species ...maximum 10 names + int kinetic_model; // only 1 = GEMS implemented right now + int n_activities; // number of species for activities + std::string active_species[10]; // name for species ...maximum 10 names double kinetic_parameters[41]; // 0,1,2 double E_acid,E_neutral,E_base; // activation energies // 3-5 double k_acid, k_neutral,k_base; // dissolution/precipitation rate constants // 6-11 double p1,q1,p2,q2,p2,q2; // exponents for omega // 12,13, 14 double n_1, n_2, n_3; // exponents for acidic neutral and base cases for species one // append for each species another set of n_1, n_2, n_3 (up to 10 sets -> up to ten species) - int surface_model; // currently only 1 implemented + int surface_model; // currently only 1 implemented double surface_area[10]; - double GetNodePorosityValue_MT ( long node_Index, int timelevel); + double GetNodePorosityValue_MT(long node_Index, int timelevel); #endif - std::ios::pos_type Read(std::ifstream*); /* Lesefunktion f? eine Instanz von CompProperties */ - void Write(std::ofstream*); /* Schreibfunktion f? eine Instanz von CompProperties */ + std::ios::pos_type Read(std::ifstream*); /* Lesefunktion f? eine Instanz von CompProperties */ + void Write(std::ofstream*); /* Schreibfunktion f? eine Instanz von CompProperties */ /* Member - Functions */ - double CalcDiffusionCoefficientCP(long index,double theta,CRFProcess* m_pcs); + double CalcDiffusionCoefficientCP(long index, double theta, CRFProcess* m_pcs); double CalcDiffusionCoefficientCP_Method1(long index, double T, double P, double eta); - //OK411 double CalcElementRetardationFactor( long index, double*gp, double theta ); - double CalcElementRetardationFactorNew( long index, double* gp, CRFProcess* m_pcs ); + // OK411 double CalcElementRetardationFactor( long index, double*gp, double theta ); + double CalcElementRetardationFactorNew(long index, double* gp, CRFProcess* m_pcs); double CalcElementMeanConc(long index); double CalcElementMeanConcNew(long index, CRFProcess* m_pcs); - double CalcElementDecayRate( long index); - double CalcElementDecayRateNew( long index, CRFProcess* m_pcs); + double CalcElementDecayRate(long index); + double CalcElementDecayRateNew(long index, CRFProcess* m_pcs); // IO std::string file_base_name; }; @@ -141,14 +140,14 @@ class CompProperties : public ProcessInfo * a new cp_vec is introduced with map structure. * cp_vec[i] still points the i-th component. */ -extern std::map cp_vec; +extern std::map cp_vec; /** * also introduce a second map structure, that store the relationship * of component name and its index value. * this will give access to the user who would like to get access * to a particular component by name. */ -extern std::map cp_name_2_idx; +extern std::map cp_name_2_idx; /** * Here is a straight forward example: * cp_vec[cp_name_2_idx["O2"]]; diff --git a/FEM/solver.cpp b/FEM/solver.cpp index 6e1f372a4..d6971ea77 100644 --- a/FEM/solver.cpp +++ b/FEM/solver.cpp @@ -40,7 +40,7 @@ using namespace std; #include "makros.h" #include "mathlib.h" #include "matrix_routines.h" -#include "rf_pcs.h" //OK_MOD" +#include "rf_pcs.h" //OK_MOD" #include "rf_tim_new.h" #include "solver.h" #include "tools.h" @@ -58,9 +58,9 @@ using namespace std; #include #endif /**** Definitionen fuer Preconditioner (Ra, 3/2000) */ -#define VK_Skalierung 1 +#define VK_Skalierung 1 #define VK_Extraktion 10 -#define VK_iLDU 100 +#define VK_iLDU 100 #define VK_Modus(vk) ((int)(vorkond % (vk * 10) / vk)) /* werden am Ende dieser Quelle wieder undefiniert! */ @@ -76,10 +76,9 @@ using namespace std; int loeser_flow = 2, loeser_tran = 2, loeser_temp = 2, loeser_satu = 2; double gls_iter_theta; int vorkond = 1, vorkond_flow = 100, vorkond_tran = 100, vorkond_temp = 100, vorkond_satu = 100; -int speichertechnik_flow = 4, speichertechnik_tran = 4, speichertechnik_temp = 4, - speichertechnik_satu = 4; -int linear_error_type = 6, linear_error_type_flow = 6, linear_error_type_tran = 6, - linear_error_type_temp = 6, linear_error_type_satu = 6; +int speichertechnik_flow = 4, speichertechnik_tran = 4, speichertechnik_temp = 4, speichertechnik_satu = 4; +int linear_error_type = 6, linear_error_type_flow = 6, linear_error_type_tran = 6, linear_error_type_temp = 6, + linear_error_type_satu = 6; double eps_flow = 1.e-10, eps_tran = 1.e-10, eps_temp = 1.e-10, eps_satu = 1.e-10, cg_eps = 1.e-10; int maxiter_flow = -1, maxiter_tran = -1, maxiter_temp = -1, maxiter_satu = -1, cg_maxiter = -1; int repeat_flow = 1, repeat_tran = 1, repeat_temp = 1, repeat_satu = 1, cg_repeat = 1; @@ -124,8 +123,7 @@ double iteration_max_dt; IntFuncDXDXL LinearSolver; IntFuncDXDXLVXL NonlinearSolver; #ifndef USE_MPI -IntFuncDXDXL LoeserFlow = SpBICGSTAB, LoeserTran = SpBICGSTAB, LoeserTemp = SpBICGSTAB, - LoeserSatu = SpBICGSTAB; +IntFuncDXDXL LoeserFlow = SpBICGSTAB, LoeserTran = SpBICGSTAB, LoeserTemp = SpBICGSTAB, LoeserSatu = SpBICGSTAB; #endif /* LU Dekomposition */ @@ -157,7 +155,7 @@ void InitSolverParameter(void) eps_flow = 1.e-10; repeat_flow = -1; vorkond_flow = VK_Extraktion + VK_iLDU; /* Ra, 3/2000 */ - speichertechnik_flow = 4; /* Ra, 3/2000 */ + speichertechnik_flow = 4; /* Ra, 3/2000 */ linear_error_type_flow = 6; /* #LINEAR_SOLVER_SATURATION */ @@ -258,9 +256,9 @@ void InitSolverParameter(void) *************************************************************************/ int SpRichardson(double* b, double* x, long n) { - double* r,* s; + double *r, *s; double eps = cg_eps; - int k = 0; //WW, max_iter = 0; + int k = 0; // WW, max_iter = 0; double r0norm = 1., b0norm = 1., x0norm = 1.; if (linear_error_type == 5) @@ -272,18 +270,18 @@ int SpRichardson(double* b, double* x, long n) if (vorkond) MXVorkond(0, x, b); - //WW if (cg_maxiter > 0) - //WW max_iter = cg_maxiter; +// WW if (cg_maxiter > 0) +// WW max_iter = cg_maxiter; - //OK411 if (cg_maxiter == -1) - //OK411 max_iter = NodeListLength; +// OK411 if (cg_maxiter == -1) +// OK411 max_iter = NodeListLength; #ifdef TESTLOES1 DisplayMsgLn("SpRichard"); #endif - r = (double*) Malloc(n * sizeof(double)); /* MNulleVec(r,n); */ - s = (double*) Malloc(n * sizeof(double)); /* MNulleVec(r,n); */ + r = (double*)Malloc(n * sizeof(double)); /* MNulleVec(r,n); */ + s = (double*)Malloc(n * sizeof(double)); /* MNulleVec(r,n); */ MXResiduum(x, b, r); if (linear_error_type == 0) @@ -316,24 +314,24 @@ int SpRichardson(double* b, double* x, long n) r0norm = VEKNORM_BICGSTAB(r, n); eps = cg_eps * MMax(MMax(x0norm, b0norm), r0norm); } - s = (double*) Free(s); + s = (double*)Free(s); if (VEKNORM_BICGSTAB(r, n) <= eps) { - r = (double*) Free(r); + r = (double*)Free(r); /* Ggf. abschliessen der Vorkonditionierung */ if (vorkond) MXVorkond(1, x, b); return 0; } - for (;; ) + for (;;) { - if VK_Modus - (VK_iLDU) MXVorkond(2, r, r); /* Ra, 3/2000 */ + if + VK_Modus(VK_iLDU) MXVorkond(2, r, r); /* Ra, 3/2000 */ MVekSum(x, gls_iter_theta, r, n); #ifdef SOLVER_SHOW_RESULTS - printf("\n%ld %f %f %f %f %f",(long)k,x[(long)(n * .1)],x[(long)(n * .3)], - x[(long)(n * .5)],x[(long)(n * .7)],x[(long)(n * .9)]); + printf("\n%ld %f %f %f %f %f", (long)k, x[(long)(n * .1)], x[(long)(n * .3)], x[(long)(n * .5)], + x[(long)(n * .7)], x[(long)(n * .9)]); #endif MXResiduum(x, b, r); @@ -347,10 +345,10 @@ int SpRichardson(double* b, double* x, long n) if (k >= cg_maxiter) break; #ifdef SOLVER_SHOW_ERROR - if (k % (int)MMax((cg_maxiter / 10),1.) == 1) + if (k % (int)MMax((cg_maxiter / 10), 1.) == 1) { DisplayMsg(" Iteration-Nr.: "); - DisplayLong((long) k); + DisplayLong((long)k); DisplayMsg(", Fehler = "); DisplayDouble(VEKNORM_BICGSTAB(r, n) / eps, 4, 1); DisplayMsgLn(" "); @@ -358,7 +356,7 @@ int SpRichardson(double* b, double* x, long n) #endif } - r = (double*) Free(r); + r = (double*)Free(r); /* Ggf. abschliessen der Vorkonditionierung */ if (vorkond) MXVorkond(1, x, b); @@ -394,7 +392,7 @@ int SpRichardson(double* b, double* x, long n) *************************************************************************/ int SpJOR(double* b, double* x, long n) { - double* r,* s; + double *r, *s; static double eps; int k = 0, max_iter = 0; static double r0norm, b0norm, x0norm; @@ -407,15 +405,15 @@ int SpJOR(double* b, double* x, long n) if (cg_maxiter > 0) max_iter = cg_maxiter; - //OK411 if (cg_maxiter == -1) - //OK411 max_iter = NodeListLength; +// OK411 if (cg_maxiter == -1) +// OK411 max_iter = NodeListLength; #ifdef TESTLOES1 DisplayMsgLn("SpJacobi"); #endif - r = (double*) Malloc(n * sizeof(double)); /* MNulleVec(r,n); */ - s = (double*) Malloc(n * sizeof(double)); /* MNulleVec(r,n); */ + r = (double*)Malloc(n * sizeof(double)); /* MNulleVec(r,n); */ + s = (double*)Malloc(n * sizeof(double)); /* MNulleVec(r,n); */ MXResiduum(x, b, r); if (linear_error_type == 0) @@ -448,17 +446,17 @@ int SpJOR(double* b, double* x, long n) r0norm = VEKNORM_BICGSTAB(r, n); eps = cg_eps * MMax(MMax(x0norm, b0norm), r0norm); } - s = (double*) Free(s); + s = (double*)Free(s); if (VEKNORM_BICGSTAB(r, n) <= eps) { - r = (double*) Free(r); + r = (double*)Free(r); /* Ggf. abschliessen der Vorkonditionierung */ if (vorkond) MXVorkond(1, x, b); return 0; } - for (;; ) + for (;;) { for (i = 0; i <= n - 1; i++) { @@ -469,7 +467,7 @@ int SpJOR(double* b, double* x, long n) r[i] = r[i] / h; else { - /* Eventuell Zeilenvertauschen */ +/* Eventuell Zeilenvertauschen */ #ifdef TESTLOES1 DisplayMsg("Fehler im Jacobi-Loser: Diagonalelement = 0.0 !!"); DisplayMsgLn(""); @@ -481,12 +479,12 @@ int SpJOR(double* b, double* x, long n) if (k == -1) break; - if VK_Modus - (VK_iLDU) MXVorkond(2, r, r); /* Ra, 3/2000 */ + if + VK_Modus(VK_iLDU) MXVorkond(2, r, r); /* Ra, 3/2000 */ MVekSum(x, gls_iter_theta, r, n); #ifdef SOLVER_SHOW_RESULTS - printf("\n%ld %f %f %f %f %f",(long)k,x[(long)(n * .1)],x[(long)(n * .3)], - x[(long)(n * .5)],x[(long)(n * .7)],x[(long)(n * .9)]); + printf("\n%ld %f %f %f %f %f", (long)k, x[(long)(n * .1)], x[(long)(n * .3)], x[(long)(n * .5)], + x[(long)(n * .7)], x[(long)(n * .9)]); #endif MXResiduum(x, b, r); k++; @@ -500,10 +498,10 @@ int SpJOR(double* b, double* x, long n) break; #ifdef SOLVER_SHOW_ERROR - if (k % (int)MMax((cg_maxiter / 10),1.) == 1) + if (k % (int)MMax((cg_maxiter / 10), 1.) == 1) { DisplayMsg(" Iteration-Nr.: "); - DisplayLong((long) k); + DisplayLong((long)k); DisplayMsg(", Fehler = "); DisplayDouble(VEKNORM_BICGSTAB(r, n) / eps, 4, 1); DisplayMsgLn(" "); @@ -511,7 +509,7 @@ int SpJOR(double* b, double* x, long n) #endif } - r = (double*) Free(r); + r = (double*)Free(r); /* Ggf. abschliessen der Vorkonditionierung */ if (vorkond) MXVorkond(1, x, b); @@ -551,7 +549,7 @@ int SpJOR(double* b, double* x, long n) *************************************************************************/ int SpSOR(double* b, double* x, long n) { - double* r,* s; + double *r, *s; static double eps; int k = 0, max_iter = 0; static double r0norm, b0norm, x0norm; @@ -564,15 +562,15 @@ int SpSOR(double* b, double* x, long n) if (cg_maxiter > 0) max_iter = cg_maxiter; - //OK411 if (cg_maxiter == -1) - //OK411 max_iter = NodeListLength; +// OK411 if (cg_maxiter == -1) +// OK411 max_iter = NodeListLength; #ifdef TESTLOES1 DisplayMsgLn("SpGaussSeidel"); #endif - r = (double*) Malloc(n * sizeof(double)); /* MNulleVec(r,n); */ - s = (double*) Malloc(n * sizeof(double)); /* MNulleVec(r,n); */ + r = (double*)Malloc(n * sizeof(double)); /* MNulleVec(r,n); */ + s = (double*)Malloc(n * sizeof(double)); /* MNulleVec(r,n); */ MXResiduum(x, b, r); if (linear_error_type == 0) @@ -606,17 +604,17 @@ int SpSOR(double* b, double* x, long n) eps = cg_eps * MMax(MMax(x0norm, b0norm), r0norm); } - s = (double*) Free(s); + s = (double*)Free(s); if (VEKNORM_BICGSTAB(r, n) <= eps) { - r = (double*) Free(r); + r = (double*)Free(r); /* Ggf. abschliessen der Vorkonditionierung */ if (vorkond) MXVorkond(1, x, b); return 0; } - for (;; ) + for (;;) { for (i = 0; i <= n - 1; i++) { @@ -627,14 +625,13 @@ int SpSOR(double* b, double* x, long n) ?? Preconditioner ?? */ h = MXGet(i, i); - if (fabs(h) > MKleinsteZahl ) + if (fabs(h) > MKleinsteZahl) x[i] = x[i] - gls_iter_theta * (sum - b[i]) / h; else { - /* Eventuell Zeilenvertauschen */ +/* Eventuell Zeilenvertauschen */ #ifdef TESTLOES1 - DisplayMsg( - "Fehler im Gauss-Seidel-Loeser: Diagonalelement = 0.0 !!"); + DisplayMsg("Fehler im Gauss-Seidel-Loeser: Diagonalelement = 0.0 !!"); DisplayMsgLn(""); #endif k = -1; @@ -642,8 +639,8 @@ int SpSOR(double* b, double* x, long n) } } #ifdef SOLVER_SHOW_RESULTS - printf("\n%ld %f %f %f %f %f",(long)k,x[(long)(n * .1)],x[(long)(n * .3)], - x[(long)(n * .5)],x[(long)(n * .7)],x[(long)(n * .9)]); + printf("\n%ld %f %f %f %f %f", (long)k, x[(long)(n * .1)], x[(long)(n * .3)], x[(long)(n * .5)], + x[(long)(n * .7)], x[(long)(n * .9)]); #endif if (k == -1) break; @@ -659,10 +656,10 @@ int SpSOR(double* b, double* x, long n) break; #ifdef SOLVER_SHOW_ERROR - if (k % (int)MMax((cg_maxiter / 10),1.) == 1) + if (k % (int)MMax((cg_maxiter / 10), 1.) == 1) { DisplayMsg(" Iteration-Nr.: "); - DisplayLong((long) k); + DisplayLong((long)k); DisplayMsg(", Fehler = "); DisplayDouble(VEKNORM_BICGSTAB(r, n) / eps, 4, 1); DisplayMsgLn(" "); @@ -670,7 +667,7 @@ int SpSOR(double* b, double* x, long n) #endif } - r = (double*) Free(r); + r = (double*)Free(r); /* Ggf. abschliessen der Vorkonditionierung */ if (vorkond) MXVorkond(1, x, b); @@ -710,7 +707,7 @@ void Gauss(double* matrix, double* vecb, double* vecx, int g) static int* s; static double z, hilf; register int k, i, j, sk; - s = (int*) Malloc(sizeof(int) * (g - 1)); + s = (int*)Malloc(sizeof(int) * (g - 1)); /* LR-Faktorisierung */ for (k = 0; k < (g - 1); k++) { @@ -732,13 +729,13 @@ void Gauss(double* matrix, double* vecb, double* vecx, int g) for (j = 0; j < g; j++) { z = matrix[k * g + j]; /* matrix[k][j] */ - /* matrix[k][j], matrix[sk][j] */ + /* matrix[k][j], matrix[sk][j] */ matrix[k * g + j] = matrix[sk * g + j]; matrix[sk * g + j] = z; /* matrix[sk][j] */ } /* Berechnung der Eliminationskoeffizienten */ for (i = (k + 1); i < g; i++) - matrix[i * g + k] /= matrix[k * g + k]; /* matrix[i][k], matrix[k][k] */ + matrix[i * g + k] /= matrix[k * g + k]; /* matrix[i][k], matrix[k][k] */ /* Spaltenweise Berechnung der neuen Restmatrix */ for (j = (k + 1); j < g; j++) for (i = (k + 1); i < g; i++) @@ -765,14 +762,14 @@ void Gauss(double* matrix, double* vecb, double* vecx, int g) for (k = (g - 1); k >= 0; k--) { for (j = (k + 1); j < g; j++) - vecb[k] -= (matrix[k * g + j] * vecb[j]); /* matrix[k][j] */ + vecb[k] -= (matrix[k * g + j] * vecb[j]); /* matrix[k][j] */ vecb[k] /= matrix[k * g + k]; /* matrix[k][k] */ } /* Umspeichern des Ergebnisses von vecb nach vecx */ for (k = 0; k < g; k++) vecx[k] = vecb[k]; /* Speicher freigeben */ - s = (int*) Free(s); + s = (int*)Free(s); } /************************************************************************* @@ -798,13 +795,13 @@ int SpAMG1R5(double* b, double* x, long n) { #ifdef AMG1R5 /* Variablen */ - static double* r, * t; + static double *r, *t; long max_iter; int k = 0; static double r0norm, b0norm, x0norm; - double* A, * U, * F; - int* IA, * JA, * IG; + double *A, *U, *F; + int *IA, *JA, *IG; int NDA, NDIA, NDJA, NDU, NDF, NDIG, NNU, NNA; int MATRIX, IFIRST, ISWTCH, IOUT, IPRINT, IERR, MADAPT; double EPS; @@ -819,8 +816,8 @@ int SpAMG1R5(double* b, double* x, long n) static double ja_size_mult = 1.; /* Ermitteln des Residuums */ - r = (double*) Malloc(n * sizeof(double)); - t = (double*) Malloc(n * sizeof(double)); + r = (double*)Malloc(n * sizeof(double)); + t = (double*)Malloc(n * sizeof(double)); /* Ggf. starten der Vorkonditionierung */ if (vorkond) @@ -831,48 +828,48 @@ int SpAMG1R5(double* b, double* x, long n) switch (linear_error_type) { - default: - case 0: - EPS = cg_eps; - break; - case 1: - EPS = cg_eps * VEKNORM_BICGSTAB(b, n); - break; - case 2: - EPS = cg_eps * VEKNORM_BICGSTAB(r, n); - break; - case 3: - if ((r0norm = VEKNORM_BICGSTAB(r, n)) > 1.) - EPS = cg_eps * r0norm; - else + default: + case 0: EPS = cg_eps; - break; - case 4: - EPS = cg_eps * (VEKNORM_BICGSTAB(x, n)); - break; - case 5: - b0norm = VEKNORM_BICGSTAB(b, n); - x0norm = VEKNORM_BICGSTAB(x, n); - r0norm = VEKNORM_BICGSTAB(r, n); - EPS = cg_eps * MMax(MMax(x0norm, b0norm), r0norm); - break; - case 6: - MXMatVek(x, t); - b0norm = VEKNORM_BICGSTAB(b, n); - x0norm = VEKNORM_BICGSTAB(t, n); - r0norm = VEKNORM_BICGSTAB(r, n); - EPS = cg_eps * MMax(MMax(x0norm, b0norm), r0norm); - break; + break; + case 1: + EPS = cg_eps * VEKNORM_BICGSTAB(b, n); + break; + case 2: + EPS = cg_eps * VEKNORM_BICGSTAB(r, n); + break; + case 3: + if ((r0norm = VEKNORM_BICGSTAB(r, n)) > 1.) + EPS = cg_eps * r0norm; + else + EPS = cg_eps; + break; + case 4: + EPS = cg_eps * (VEKNORM_BICGSTAB(x, n)); + break; + case 5: + b0norm = VEKNORM_BICGSTAB(b, n); + x0norm = VEKNORM_BICGSTAB(x, n); + r0norm = VEKNORM_BICGSTAB(r, n); + EPS = cg_eps * MMax(MMax(x0norm, b0norm), r0norm); + break; + case 6: + MXMatVek(x, t); + b0norm = VEKNORM_BICGSTAB(b, n); + x0norm = VEKNORM_BICGSTAB(t, n); + r0norm = VEKNORM_BICGSTAB(r, n); + EPS = cg_eps * MMax(MMax(x0norm, b0norm), r0norm); + break; } switch (cg_maxiter) { - case -1: - max_iter = NodeListLength; - break; - default: - max_iter = cg_maxiter; - break; + case -1: + max_iter = NodeListLength; + break; + default: + max_iter = cg_maxiter; + break; } MATRIX = 22; @@ -882,15 +879,15 @@ int SpAMG1R5(double* b, double* x, long n) IPRINT = 10606; LEVELX = 0; MADAPT = 0; - NCYC = 102 * (long) pow(10.,(double)(1 + (int)log10((double)max_iter))) + max_iter; - NRD = 0; + NCYC = 102 * (long)pow(10., (double)(1 + (int)log10((double)max_iter))) + max_iter; + NRD = 0; NSOLCO = 10; - NRU = 0; - NWT = 2; - NTR = 0; - ECG1 = 0.; - ECG2 = 0.25; - EWT2 = 0.35; + NRU = 0; + NWT = 2; + NTR = 0; + ECG1 = 0.; + ECG2 = 0.25; + EWT2 = 0.35; restart: @@ -914,16 +911,15 @@ int SpAMG1R5(double* b, double* x, long n) MXCopyToAMG1R5Structure(A, IA, JA, NDA, NDIA, NDJA, x, U, b, F); - amg1r5_(A,IA,JA,U,F,IG,&NDA,&NDIA,&NDJA,&NDU,&NDF,&NDIG,&NNU,&MATRIX, - &ISWTCH,&IOUT,&IPRINT,&LEVELX,&IFIRST,&NCYC,&EPS,&MADAPT,&NRD, - &NSOLCO,&NRU,&ECG1,&ECG2,&EWT2,&NWT,&NTR,&IERR); + amg1r5_(A, IA, JA, U, F, IG, &NDA, &NDIA, &NDJA, &NDU, &NDF, &NDIG, &NNU, &MATRIX, &ISWTCH, &IOUT, &IPRINT, &LEVELX, + &IFIRST, &NCYC, &EPS, &MADAPT, &NRD, &NSOLCO, &NRU, &ECG1, &ECG2, &EWT2, &NWT, &NTR, &IERR); /* aux1r5_(A,IA,JA,U,F,IG,&NDA,&NDIA,&NDJA,&NDU,&NDF,&NDIG,&NNU,&MATRIX, &EPS,&IFIRST,&ISWTCH,&IOUT,&IPRINT,&IERR); */ - MKopierVec(U,x,n); + MKopierVec(U, x, n); A = (double*)Free(A); U = (double*)Free(U); @@ -936,38 +932,53 @@ int SpAMG1R5(double* b, double* x, long n) t = (double*)Free(t); r = (double*)Free(r); - switch(IERR) + switch (IERR) { - case 1: a_size_mult *= 1.2; - goto restart; - case 2: ia_size_mult *= 1.2; - goto restart; - case 3: ja_size_mult *= 1.2; - goto restart; - case 4: u_size_mult *= 1.2; - goto restart; - case 5: f_size_mult *= 1.2; - goto restart; - case 6: ig_size_mult *= 1.2; - goto restart; - case -11: printf(" \n AMG-Solver: A-entry missing!\n "); - break; - case -12: printf(" \n AMG-Solver: Parameters erroneous!\n "); - break; - case 13: printf(" \n AMG-Solver: Diagonal not stored first!\n "); - break; - case 14: printf(" \n AMG-Solver: Diagonal not positiv!\n "); - break; - case 15: printf(" \n AMG-Solver: IA erroneous!\n "); - break; - case 16: printf(" \n AMG-Solver: JA erroneous!\n "); - break; - case 17: printf(" \n AMG-Solver: ISWITCH erroneous!\n "); - break; - case 31: printf(" \n AMG-Solver: CG not defined!\n "); - break; - case -32: printf(" \n AMG-Solver: YALE-SMP not possible!\n "); - break; + case 1: + a_size_mult *= 1.2; + goto restart; + case 2: + ia_size_mult *= 1.2; + goto restart; + case 3: + ja_size_mult *= 1.2; + goto restart; + case 4: + u_size_mult *= 1.2; + goto restart; + case 5: + f_size_mult *= 1.2; + goto restart; + case 6: + ig_size_mult *= 1.2; + goto restart; + case -11: + printf(" \n AMG-Solver: A-entry missing!\n "); + break; + case -12: + printf(" \n AMG-Solver: Parameters erroneous!\n "); + break; + case 13: + printf(" \n AMG-Solver: Diagonal not stored first!\n "); + break; + case 14: + printf(" \n AMG-Solver: Diagonal not positiv!\n "); + break; + case 15: + printf(" \n AMG-Solver: IA erroneous!\n "); + break; + case 16: + printf(" \n AMG-Solver: JA erroneous!\n "); + break; + case 17: + printf(" \n AMG-Solver: ISWITCH erroneous!\n "); + break; + case 31: + printf(" \n AMG-Solver: CG not defined!\n "); + break; + case -32: + printf(" \n AMG-Solver: YALE-SMP not possible!\n "); + break; } /* Ggf. abschliessen der Vorkonditionierung */ @@ -1009,16 +1020,16 @@ int SpUMF(double* b, double* x, long n) { #ifdef UMFPACK /* Variablen */ - static double* r, * t; + static double *r, *t; long i, j, k = 0; double r0norm, b0norm, x0norm; double* Ax = NULL; - int* Ap = NULL, * Ai = NULL; + int *Ap = NULL, *Ai = NULL; int NA, NNA, NP, NNP, status; double EPS, a; - double* Control = (double*) NULL, * Info = (double*) NULL; - void* Symbolic = NULL, * Numeric = NULL; + double *Control = (double *)NULL, *Info = (double *)NULL; + void *Symbolic = NULL, *Numeric = NULL; static double a_size_mult = 1.; @@ -1026,46 +1037,46 @@ int SpUMF(double* b, double* x, long n) if (vorkond) MXVorkond(0, x, b); - r = (double*) Malloc(n * sizeof(double)); - t = (double*) Malloc(n * sizeof(double)); + r = (double*)Malloc(n * sizeof(double)); + t = (double*)Malloc(n * sizeof(double)); /* Ermitteln des Residuums */ MXResiduum(x, b, r); switch (linear_error_type) { - default: - case 0: - EPS = cg_eps; - break; - case 1: - EPS = cg_eps * VEKNORM_BICGSTAB(b, n); - break; - case 2: - EPS = cg_eps * VEKNORM_BICGSTAB(r, n); - break; - case 3: - if ((r0norm = VEKNORM_BICGSTAB(r, n)) > 1.) - EPS = cg_eps * r0norm; - else + default: + case 0: EPS = cg_eps; - break; - case 4: - EPS = cg_eps * (VEKNORM_BICGSTAB(x, n)); - break; - case 5: - b0norm = VEKNORM_BICGSTAB(b, n); - x0norm = VEKNORM_BICGSTAB(x, n); - r0norm = VEKNORM_BICGSTAB(r, n); - EPS = cg_eps * MMax(MMax(x0norm, b0norm), r0norm); - break; - case 6: - MXMatVek(x, t); - b0norm = VEKNORM_BICGSTAB(b, n); - x0norm = VEKNORM_BICGSTAB(t, n); - r0norm = VEKNORM_BICGSTAB(r, n); - EPS = cg_eps * MMax(MMax(x0norm, b0norm), r0norm); - break; + break; + case 1: + EPS = cg_eps * VEKNORM_BICGSTAB(b, n); + break; + case 2: + EPS = cg_eps * VEKNORM_BICGSTAB(r, n); + break; + case 3: + if ((r0norm = VEKNORM_BICGSTAB(r, n)) > 1.) + EPS = cg_eps * r0norm; + else + EPS = cg_eps; + break; + case 4: + EPS = cg_eps * (VEKNORM_BICGSTAB(x, n)); + break; + case 5: + b0norm = VEKNORM_BICGSTAB(b, n); + x0norm = VEKNORM_BICGSTAB(x, n); + r0norm = VEKNORM_BICGSTAB(r, n); + EPS = cg_eps * MMax(MMax(x0norm, b0norm), r0norm); + break; + case 6: + MXMatVek(x, t); + b0norm = VEKNORM_BICGSTAB(b, n); + x0norm = VEKNORM_BICGSTAB(t, n); + r0norm = VEKNORM_BICGSTAB(r, n); + EPS = cg_eps * MMax(MMax(x0norm, b0norm), r0norm); + break; } /* Fehler ausgeben */ @@ -1075,8 +1086,8 @@ int SpUMF(double* b, double* x, long n) if (VEKNORM_BICGSTAB(r, n) <= EPS) { - r = (double*) Free(r); - t = (double*) Free(t); + r = (double*)Free(r); + t = (double*)Free(t); /* Ggf. abschliessen der Vorkonditionierung */ if (vorkond) @@ -1106,8 +1117,8 @@ int SpUMF(double* b, double* x, long n) for (i = 0; i < n; i++) { /* Ineffektiv!! Besser auf Sparse-Strukturen zugreifen */ - a = MXGet(i,j); - if(fabs(a) > MFastNull) + a = MXGet(i, j); + if (fabs(a) > MFastNull) { /* Spalteneintraege speichern */ Ax[NNA] = a; @@ -1116,9 +1127,9 @@ int SpUMF(double* b, double* x, long n) if (NNA == NA) { a_size_mult *= 1.2; - Ax = (double*) Free(Ax); - Ai = (int*) Free(Ai); - Ap = (int*) Free(Ap); + Ax = (double*)Free(Ax); + Ai = (int*)Free(Ai); + Ap = (int*)Free(Ap); goto restart; } } @@ -1129,25 +1140,25 @@ int SpUMF(double* b, double* x, long n) NNP++; #ifdef UMFPACK31 - umfpack_i_symbolic (n, Ap, Ai, &Symbolic, Control, Info); - if(Symbolic == NULL) + umfpack_i_symbolic(n, Ap, Ai, &Symbolic, Control, Info); + if (Symbolic == NULL) DisplayMsgLn("UMFPACK: Symbolic ist NULL!"); - umfpack_i_numeric (Ap, Ai, Ax, Symbolic, &Numeric, Control, Info); - if(Numeric == NULL) + umfpack_i_numeric(Ap, Ai, Ax, Symbolic, &Numeric, Control, Info); + if (Numeric == NULL) DisplayMsgLn("UMFPACK: Numeric ist NULL!"); - status = umfpack_i_solve ("Ax=b", Ap, Ai, Ax, x, b, Numeric, Control, Info); - umfpack_i_report_info (Control, Info); - umfpack_i_report_status (Control, status); + status = umfpack_i_solve("Ax=b", Ap, Ai, Ax, x, b, Numeric, Control, Info); + umfpack_i_report_info(Control, Info); + umfpack_i_report_status(Control, status); #endif #ifdef UMFPACK40 - status = umfpack_di_symbolic (n, n, Ap, Ai, &Symbolic, Control, Info); - umfpack_di_report_status (Control, status); + status = umfpack_di_symbolic(n, n, Ap, Ai, &Symbolic, Control, Info); + umfpack_di_report_status(Control, status); if (status == UMFPACK_ERROR_out_of_memory) { a_size_mult *= 1.2; - Ax = (double*) Free(Ax); - Ai = (int*) Free(Ai); - Ap = (int*) Free(Ap); + Ax = (double*)Free(Ax); + Ai = (int*)Free(Ai); + Ap = (int*)Free(Ap); goto restart; } if (status != UMFPACK_OK) @@ -1157,11 +1168,11 @@ int SpUMF(double* b, double* x, long n) MXDumpGLS("ERROR.GLS", 1, b, NULL); exit(1); } - if(Symbolic == NULL) + if (Symbolic == NULL) DisplayMsgLn("UMFPACK: Symbolic ist NULL!"); - status = umfpack_di_numeric (Ap, Ai, Ax, Symbolic, &Numeric, Control, Info); - umfpack_di_report_status (Control, status); + status = umfpack_di_numeric(Ap, Ai, Ax, Symbolic, &Numeric, Control, Info); + umfpack_di_report_status(Control, status); if (status != UMFPACK_OK) { DisplayMsgLn("UMFPACK wird abgebrochen!"); @@ -1169,12 +1180,12 @@ int SpUMF(double* b, double* x, long n) MXDumpGLS("ERROR.GLS", 1, b, NULL); exit(1); } - if(Numeric == NULL) + if (Numeric == NULL) DisplayMsgLn("UMFPACK: Numeric ist NULL!"); - status = umfpack_di_solve (UMFPACK_A, Ap, Ai, Ax, x, b, Numeric, Control, Info); - umfpack_di_report_info (Control, Info); - umfpack_di_report_status (Control, status); + status = umfpack_di_solve(UMFPACK_A, Ap, Ai, Ax, x, b, Numeric, Control, Info); + umfpack_di_report_info(Control, Info); + umfpack_di_report_status(Control, status); if (status != UMFPACK_OK) { DisplayMsgLn("UMFPACK wird abgebrochen!"); @@ -1185,12 +1196,12 @@ int SpUMF(double* b, double* x, long n) #endif #ifdef UMFPACK31 - umfpack_i_free_symbolic (&Symbolic); - umfpack_i_free_numeric (&Numeric); + umfpack_i_free_symbolic(&Symbolic); + umfpack_i_free_numeric(&Numeric); #endif #ifdef UMFPACK40 - umfpack_di_free_symbolic (&Symbolic); - umfpack_di_free_numeric (&Numeric); + umfpack_di_free_symbolic(&Symbolic); + umfpack_di_free_numeric(&Numeric); #endif MXResiduum(x, b, r); @@ -1202,12 +1213,12 @@ int SpUMF(double* b, double* x, long n) if (vorkond) MXVorkond(1, x, b); - Ax = (double*) Free(Ax); - Ai = (int*) Free(Ai); - Ap = (int*) Free(Ap); + Ax = (double*)Free(Ax); + Ai = (int*)Free(Ai); + Ap = (int*)Free(Ap); - r = (double*) Free(r); - t = (double*) Free(t); + r = (double*)Free(r); + t = (double*)Free(t); return k; #else // ifdef UMFPACK @@ -1252,9 +1263,9 @@ int SpUMF(double* b, double* x, long n) int SpBICG(double* b, double* x, long n) { /* Variablen */ - static double* r, * rs, * p, * ps, * v, * tmp; + static double *r, *rs, *p, *ps, *v, *tmp; static double alpha, beta, rho, rho1, eps; - register int i; /* schnellere Vektoroperationen, Ra, 3/2000 */ + register int i; /* schnellere Vektoroperationen, Ra, 3/2000 */ int k = 0, max_iter = 0; static double r0norm, b0norm, x0norm; @@ -1266,15 +1277,15 @@ int SpBICG(double* b, double* x, long n) if (cg_maxiter > 0) max_iter = cg_maxiter; - //OK411 if (cg_maxiter == -1) - //OK411 max_iter = NodeListLength; +// OK411 if (cg_maxiter == -1) +// OK411 max_iter = NodeListLength; #ifdef TESTLOES4 DisplayMsgLn("SpBICG"); #endif - r = (double*) Malloc(n * sizeof(double)); /* MNulleVec(r,n); */ - rs = (double*) Malloc(n * sizeof(double)); + r = (double*)Malloc(n * sizeof(double)); /* MNulleVec(r,n); */ + rs = (double*)Malloc(n * sizeof(double)); MXResiduum(x, b, r); @@ -1317,28 +1328,28 @@ int SpBICG(double* b, double* x, long n) if (VEKNORM_BICG(r, n) <= eps) { - r = (double*) Free(r); - rs = (double*) Free(rs); + r = (double*)Free(r); + rs = (double*)Free(rs); /* Ggf. abschliessen der Vorkonditionierung */ if (vorkond) MXVorkond(1, x, b); return 0; } - p = (double*) Malloc(n * sizeof(double)); - ps = (double*) Malloc(n * sizeof(double)); - v = (double*) Malloc(n * sizeof(double)); - tmp = (double*) Malloc(n * sizeof(double)); + p = (double*)Malloc(n * sizeof(double)); + ps = (double*)Malloc(n * sizeof(double)); + v = (double*)Malloc(n * sizeof(double)); + tmp = (double*)Malloc(n * sizeof(double)); - if VK_Modus - (VK_iLDU) MXVorkond(2, r, r); /* Ra, 3/2000 */ + if + VK_Modus(VK_iLDU) MXVorkond(2, r, r); /* Ra, 3/2000 */ for (i = 0; i < n; i++) { p[i] = ps[i] = 0.0; rs[i] = r[i]; } - for (;; ) + for (;;) { rho = MSkalarprodukt(rs, r, n); beta = rho / rho1; @@ -1349,8 +1360,8 @@ int SpBICG(double* b, double* x, long n) } MXMatVek(p, v); - if VK_Modus - (VK_iLDU) MXVorkond(2, v, v); /* Ra, 3/2000 */ + if + VK_Modus(VK_iLDU) MXVorkond(2, v, v); /* Ra, 3/2000 */ alpha = rho / MSkalarprodukt(ps, v, n); for (i = 0; i < n; i++) { @@ -1359,8 +1370,8 @@ int SpBICG(double* b, double* x, long n) } #ifdef SOLVER_SHOW_RESULTS - printf("\n%ld %f %f %f %f %f",(long)k,x[(long)(n * .1)],x[(long)(n * .3)], - x[(long)(n * .5)],x[(long)(n * .7)],x[(long)(n * .9)]); + printf("\n%ld %f %f %f %f %f", (long)k, x[(long)(n * .1)], x[(long)(n * .3)], x[(long)(n * .5)], + x[(long)(n * .7)], x[(long)(n * .9)]); #endif k++; @@ -1369,14 +1380,14 @@ int SpBICG(double* b, double* x, long n) if (VEKNORM_BICG(r, n) <= eps) break; - if VK_Modus - (VK_iLDU) - { - MXVorkond(3, v, ps); - MXMatTVek(v, tmp); - } + if + VK_Modus(VK_iLDU) + { + MXVorkond(3, v, ps); + MXMatTVek(v, tmp); + } else - MXMatTVek(ps, tmp); /* Ra, 3/2000 */ + MXMatTVek(ps, tmp); /* Ra, 3/2000 */ for (i = 0; i < n; i++) rs[i] -= alpha * tmp[i]; @@ -1384,10 +1395,10 @@ int SpBICG(double* b, double* x, long n) break; #ifdef SOLVER_SHOW_ERROR - if (k % (int)MMax((cg_maxiter / 10),1.) == 1) + if (k % (int)MMax((cg_maxiter / 10), 1.) == 1) { DisplayMsg(" Iteration-Nr.: "); - DisplayLong((long) k); + DisplayLong((long)k); DisplayMsg(", Fehler = "); DisplayDouble(VEKNORM_BICGSTAB(r, n) / eps, 4, 1); DisplayMsgLn(" "); @@ -1397,12 +1408,12 @@ int SpBICG(double* b, double* x, long n) rho1 = rho; } - r = (double*) Free(r); - rs = (double*) Free(rs); - p = (double*) Free(p); - ps = (double*) Free(ps); - v = (double*) Free(v); - tmp = (double*) Free(tmp); + r = (double*)Free(r); + rs = (double*)Free(rs); + p = (double*)Free(p); + ps = (double*)Free(ps); + v = (double*)Free(v); + tmp = (double*)Free(tmp); /* msr: evtl. Speicher immer nur vergroessern, nie ganz freigeben (wie bei masscont geplant) */ @@ -1452,35 +1463,34 @@ int SpBICGSTAB(double* restrict b, double* restrict x, long n) int SpBICGSTAB(double* b, double* x, long n) #endif { - /* Variablen */ +/* Variablen */ #ifdef SX - double* restrict r, * restrict r2, * restrict rs, * restrict p, * restrict s, * restrict t, - * restrict v; + double *restrict r, *restrict r2, *restrict rs, *restrict p, *restrict s, *restrict t, *restrict v; #else - double* r, * r2, * rs, * p, * s, * t, * v; + double *r, *r2, *rs, *p, *s, *t, *v; #endif double alpha, beta, omega, rho, rho1, eps = 0.; - register long i; /* schnellere Vektoroperationen, Ra, 3/2000 */ + register long i; /* schnellere Vektoroperationen, Ra, 3/2000 */ int k = 0, max_iter = 0, repeat = 0; double r0norm = 0., b0norm = 0., x0norm = 0., tt, ts, rsv; - //WW double error_rel; - //MXDumpGLS("rf_pcs.txt",1,b,x); abort(); + // WW double error_rel; + // MXDumpGLS("rf_pcs.txt",1,b,x); abort(); /* Ggf. starten der Vorkonditionierung */ if (vorkond) - //WW cout << " Preconditioning" << "\n"; - MXVorkond(0,x,b); - r = (double*) Malloc(n * sizeof(double)); - r2 = (double*) Malloc(n * sizeof(double)); - rs = (double*) Malloc(n * sizeof(double)); - p = (double*) Malloc(n * sizeof(double)); - s = (double*) Malloc(n * sizeof(double)); - t = (double*) Malloc(n * sizeof(double)); - v = (double*) Malloc(n * sizeof(double)); + // WW cout << " Preconditioning" << "\n"; + MXVorkond(0, x, b); + r = (double*)Malloc(n * sizeof(double)); + r2 = (double*)Malloc(n * sizeof(double)); + rs = (double*)Malloc(n * sizeof(double)); + p = (double*)Malloc(n * sizeof(double)); + s = (double*)Malloc(n * sizeof(double)); + t = (double*)Malloc(n * sizeof(double)); + v = (double*)Malloc(n * sizeof(double)); if (cg_maxiter > 0) max_iter = cg_maxiter; - //OK411 if (cg_maxiter == -1) - //OK411 max_iter = NodeListLength; +// OK411 if (cg_maxiter == -1) +// OK411 max_iter = NodeListLength; restart: @@ -1525,10 +1535,10 @@ int SpBICGSTAB(double* b, double* x, long n) r0norm = VEKNORM_BICGSTAB(r, n); eps = cg_eps * MMax(MMax(x0norm, b0norm), r0norm); } - //OK - r0norm = VEKNORM_BICGSTAB(r,n); - //WW error_rel = r0norm/eps; - //WW cout << "\n SpBICGSTAB iteration: 0/" << max_iter << " Error: " << error_rel << "\n"; + // OK + r0norm = VEKNORM_BICGSTAB(r, n); +// WW error_rel = r0norm/eps; +// WW cout << "\n SpBICGSTAB iteration: 0/" << max_iter << " Error: " << error_rel << "\n"; #ifdef TESTLOES4 DisplayMsg("eps = "); DisplayDouble(eps, 22, 20); @@ -1538,14 +1548,14 @@ int SpBICGSTAB(double* b, double* x, long n) if ((k >= max_iter) || (VEKNORM_BICGSTAB(r, n) <= eps)) goto end; - if VK_Modus - (VK_iLDU) MXVorkond(2, r, r); + if + VK_Modus(VK_iLDU) MXVorkond(2, r, r); - MKopierVec(r,rs,n); - MKopierVec(r,p,n); - MNulleVec(v,n); + MKopierVec(r, rs, n); + MKopierVec(r, p, n); + MNulleVec(v, n); - for (;; ) + for (;;) { /* Zaehler fuer Wiederholungen innerhalb des Loesers */ k++; @@ -1558,7 +1568,7 @@ int SpBICGSTAB(double* b, double* x, long n) /* Bei rho==0 ist eigentlich alles hoffnungslos, wir versuchen einen Restart ... */ goto restart; - if(k > 1) + if (k > 1) { beta = (rho / rho1) * (alpha / omega); #ifdef SX @@ -1569,8 +1579,8 @@ int SpBICGSTAB(double* b, double* x, long n) } MXMatVek(p, v); - if VK_Modus - (VK_iLDU) MXVorkond(2, v, v); /* Ra, 3/2000 */ + if + VK_Modus(VK_iLDU) MXVorkond(2, v, v); /* Ra, 3/2000 */ rsv = MSkalarprodukt(rs, v, n); @@ -1584,7 +1594,7 @@ int SpBICGSTAB(double* b, double* x, long n) /* Erste Abbruchmoeglichkeit */ if (VEKNORM_BICGSTAB(s, n) <= eps) { - /* Die Loesung nochmal updaten */ +/* Die Loesung nochmal updaten */ #ifdef SX #pragma cdir nodep #endif @@ -1595,8 +1605,8 @@ int SpBICGSTAB(double* b, double* x, long n) MXMatVek(s, t); - if VK_Modus - (VK_iLDU) MXVorkond(2, t, t); /* Ra, 3/2000 */ + if + VK_Modus(VK_iLDU) MXVorkond(2, t, t); /* Ra, 3/2000 */ ts = MSkalarprodukt(t, s, n); tt = MSkalarprodukt(t, t, n); @@ -1629,22 +1639,22 @@ int SpBICGSTAB(double* b, double* x, long n) r[i] = s[i] - omega * t[i]; #ifdef SOLVER_SHOW_RESULTS - printf("\n%ld %f %f %f %f %f",(long)k,x[(long)(n * .1)],x[(long)(n * .3)], - x[(long)(n * .5)],x[(long)(n * .7)],x[(long)(n * .9)]); + printf("\n%ld %f %f %f %f %f", (long)k, x[(long)(n * .1)], x[(long)(n * .3)], x[(long)(n * .5)], + x[(long)(n * .7)], x[(long)(n * .9)]); #endif - //OK - //WW error_rel = VEKNORM_BICGSTAB(r2,n)/eps; - //WW printf("\r SpBICGSTAB iteration: %i/%i Error: %f",k,max_iter,error_rel); + // OK + // WW error_rel = VEKNORM_BICGSTAB(r2,n)/eps; + // WW printf("\r SpBICGSTAB iteration: %i/%i Error: %f",k,max_iter,error_rel); if (linear_error_type == 4) eps = cg_eps * (VEKNORM_BICGSTAB(x, n)); if (VEKNORM_BICGSTAB(r2, n) <= eps) break; #ifdef SOLVER_SHOW_ERROR - if (k % (int)MMax((max_iter / 10),1.) == 1) + if (k % (int)MMax((max_iter / 10), 1.) == 1) { DisplayMsg(" Iteration-Nr.: "); - DisplayLong((long) k); + DisplayLong((long)k); DisplayMsg(", Fehler = "); DisplayDouble(VEKNORM_BICGSTAB(r2, n) / eps, 4, 1); DisplayMsgLn(" "); @@ -1661,20 +1671,20 @@ int SpBICGSTAB(double* b, double* x, long n) goto end; end: - r = (double*) Free(r); - r2 = (double*) Free(r2); - rs = (double*) Free(rs); - p = (double*) Free(p); - s = (double*) Free(s); - t = (double*) Free(t); - v = (double*) Free(v); + r = (double*)Free(r); + r2 = (double*)Free(r2); + rs = (double*)Free(rs); + p = (double*)Free(p); + s = (double*)Free(s); + t = (double*)Free(t); + v = (double*)Free(v); /* Ggf. abschliessen der Vorkonditionierung */ if (vorkond) MXVorkond(1, x, b); - //WW - printf("\t SpBICGSTAB iteration: %i/%i \n",k,max_iter); + // WW + printf("\t SpBICGSTAB iteration: %i/%i \n", k, max_iter); return k; } @@ -1711,10 +1721,10 @@ int SpBICGSTAB(double* b, double* x, long n) int SpQMRCGSTAB(double* b, double* x, long n) { /* Variablen */ - static double* r, * rs, * d, * ds, * p, * s, * t, * v, * xs; + static double *r, *rs, *d, *ds, *p, *s, *t, *v, *xs; static double alpha, beta, omega, rho, rho1, eps; static double tau, teta, eta, taus, tetas, etas, c; - register int i; /* schnellere Vektoroperationen, Ra, 3/2000 */ + register int i; /* schnellere Vektoroperationen, Ra, 3/2000 */ int k = 0, max_iter = 0; static double r0norm, b0norm, x0norm; @@ -1729,15 +1739,15 @@ int SpQMRCGSTAB(double* b, double* x, long n) if (cg_maxiter > 0) max_iter = cg_maxiter; - //OK411 if (cg_maxiter == -1) - //OK411 max_iter = NodeListLength; +// OK411 if (cg_maxiter == -1) +// OK411 max_iter = NodeListLength; #ifdef TESTLOES4 DisplayMsgLn("SpQMRCGSTAB"); #endif - r = (double*) Malloc(n * sizeof(double)); /* MNulleVec(r,n); */ - s = (double*) Malloc(n * sizeof(double)); + r = (double*)Malloc(n * sizeof(double)); /* MNulleVec(r,n); */ + s = (double*)Malloc(n * sizeof(double)); MXResiduum(x, b, r); if (linear_error_type == 0) @@ -1774,38 +1784,38 @@ int SpQMRCGSTAB(double* b, double* x, long n) if (VEKNORM_QMRCGSTAB(r, n) <= eps) { - r = (double*) Free(r); - s = (double*) Free(s); + r = (double*)Free(r); + s = (double*)Free(s); /* Ggf. abschliessen der Vorkonditionierung */ if (vorkond) MXVorkond(1, x, b); return 0; } - rs = (double*) Malloc(n * sizeof(double)); - d = (double*) Malloc(n * sizeof(double)); - ds = (double*) Malloc(n * sizeof(double)); - p = (double*) Malloc(n * sizeof(double)); - s = (double*) Malloc(n * sizeof(double)); - t = (double*) Malloc(n * sizeof(double)); - v = (double*) Malloc(n * sizeof(double)); - xs = (double*) Malloc(n * sizeof(double)); + rs = (double*)Malloc(n * sizeof(double)); + d = (double*)Malloc(n * sizeof(double)); + ds = (double*)Malloc(n * sizeof(double)); + p = (double*)Malloc(n * sizeof(double)); + s = (double*)Malloc(n * sizeof(double)); + t = (double*)Malloc(n * sizeof(double)); + v = (double*)Malloc(n * sizeof(double)); + xs = (double*)Malloc(n * sizeof(double)); for (i = 0; i < n; i++) d[i] = p[i] = v[i] = 0.0; - if VK_Modus - (VK_iLDU) MXVorkond(2, r, r); /* Ra, 3/2000 */ + if + VK_Modus(VK_iLDU) MXVorkond(2, r, r); /* Ra, 3/2000 */ for (i = 0; i < n; i++) rs[i] = r[i]; - for (;; ) + for (;;) { rho = MSkalarprodukt(rs, r, n); beta = (rho / rho1) * (alpha / omega); for (i = 0; i < n; i++) p[i] = r[i] + beta * (p[i] - omega * v[i]); MXMatVek(p, v); - if VK_Modus - (VK_iLDU) MXVorkond(2, v, v); /* Ra, 3/2000 */ + if + VK_Modus(VK_iLDU) MXVorkond(2, v, v); /* Ra, 3/2000 */ alpha = rho / MSkalarprodukt(rs, v, n); for (i = 0; i < n; i++) s[i] = r[i] - alpha * v[i]; @@ -1822,8 +1832,8 @@ int SpQMRCGSTAB(double* b, double* x, long n) } /* update r */ MXMatVek(s, t); - if VK_Modus - (VK_iLDU) MXVorkond(2, t, t); /* Ra, 3/2000 */ + if + VK_Modus(VK_iLDU) MXVorkond(2, t, t); /* Ra, 3/2000 */ omega = MSkalarprodukt(t, s, n) / MSkalarprodukt(t, t, n); for (i = 0; i < n; i++) r[i] = s[i] - omega * t[i]; @@ -1841,8 +1851,8 @@ int SpQMRCGSTAB(double* b, double* x, long n) } #ifdef SOLVER_SHOW_RESULTS - printf("\n%ld %f %f %f %f %f",(long)k,x[(long)(n * .1)],x[(long)(n * .3)], - x[(long)(n * .5)],x[(long)(n * .7)],x[(long)(n * .9)]); + printf("\n%ld %f %f %f %f %f", (long)k, x[(long)(n * .1)], x[(long)(n * .3)], x[(long)(n * .5)], + x[(long)(n * .7)], x[(long)(n * .9)]); #endif k++; @@ -1855,10 +1865,10 @@ int SpQMRCGSTAB(double* b, double* x, long n) break; #ifdef SOLVER_SHOW_ERROR - if (k % (int)MMax((cg_maxiter / 10),1.) == 1) + if (k % (int)MMax((cg_maxiter / 10), 1.) == 1) { DisplayMsg(" Iteration-Nr.: "); - DisplayLong((long) k); + DisplayLong((long)k); DisplayMsg(", Fehler = "); DisplayDouble(VEKNORM_BICGSTAB(r, n) / eps, 4, 1); DisplayMsgLn(" "); @@ -1867,15 +1877,15 @@ int SpQMRCGSTAB(double* b, double* x, long n) rho1 = rho; } - r = (double*) Free(r); - rs = (double*) Free(rs); - d = (double*) Free(d); - ds = (double*) Free(ds); - p = (double*) Free(p); - s = (double*) Free(s); - t = (double*) Free(t); - v = (double*) Free(v); - xs = (double*) Free(xs); + r = (double*)Free(r); + rs = (double*)Free(rs); + d = (double*)Free(d); + ds = (double*)Free(ds); + p = (double*)Free(p); + s = (double*)Free(s); + t = (double*)Free(t); + v = (double*)Free(v); + xs = (double*)Free(xs); /* msr: evtl. Speicher immer nur vergroessern, nie ganz freigeben (wie bei masscont geplant) */ @@ -1912,38 +1922,38 @@ int SpQMRCGSTAB(double* b, double* x, long n) int SpMGMRES(double* b, double* x, long n) { #ifdef GMRES_WORKS - double* V, * U, * r, * x0, * y, * c, * cs, * sn, * s, ** v, * w, * help; + double *V, *U, *r, *x0, *y, *c, *cs, *sn, *s, **v, *w, *help; double beta, tol = cg_eps, resid, normb; long max_iter, i, i1, i2, j, k; const long m = 30; double H[31][31]; - if ( n <= 0 ) + if (n <= 0) return -1; - V = MMachVec(n * (m + 1)); - U = MMachVec(m * (m + 1) / 2); - r = MMachVec(n); + V = MMachVec(n * (m + 1)); + U = MMachVec(m * (m + 1) / 2); + r = MMachVec(n); x0 = MMachVec(n); - w = MMachVec(n); + w = MMachVec(n); help = MMachVec(n); - y = MMachVec(m + 1); - c = MMachVec(m); - s = MMachVec(m + 1); - cs = MMachVec(m + 1); - sn = MMachVec(m + 1); - v = (double**)Malloc((m + 1) * sizeof(double*)); /* Pointerfeld auf V */ + y = MMachVec(m + 1); + c = MMachVec(m); + s = MMachVec(m + 1); + cs = MMachVec(m + 1); + sn = MMachVec(m + 1); + v = (double**)Malloc((m + 1) * sizeof(double*)); /* Pointerfeld auf V */ - for (i = 0; i <= m; ++i ) - v[i] = V + i * n; /* Zuweisen */ + for (i = 0; i <= m; ++i) + v[i] = V + i * n; /* Zuweisen */ if (cg_maxiter >= 0) max_iter = cg_maxiter; if (cg_maxiter == -1) max_iter = NodeListLength; - if VK_Modus - (VK_iLDU) MXVorkond(2, b, help); + if + VK_Modus(VK_iLDU) MXVorkond(2, b, help); normb = VEKNORM_BICGSTAB(help, n); if (normb == 0.0) @@ -1960,8 +1970,8 @@ int SpMGMRES(double* b, double* x, long n) r = M.solve(b - A * x); */ MXResiduum(x0, b, r); - if VK_Modus - (VK_iLDU) MXVorkond(2, r, r); + if + VK_Modus(VK_iLDU) MXVorkond(2, r, r); beta = VEKNORM_BICGSTAB(r, n); @@ -1980,8 +1990,8 @@ int SpMGMRES(double* b, double* x, long n) { /* w = M.solve(A * v[i]); */ MXMatVek(v[i], w); - if VK_Modus - (VK_iLDU) MXVorkond(2, w, w); + if + VK_Modus(VK_iLDU) MXVorkond(2, w, w); for (k = 0; k <= i; k++) { @@ -2030,7 +2040,7 @@ int SpMGMRES(double* b, double* x, long n) MLoeschVec(y); MLoeschVec(c); MLoeschVec(s); - v = (double**) Free(v); + v = (double**)Free(v); return max_iter; #else // ifdef GMRES_WORKS @@ -2055,13 +2065,13 @@ void GeneratePlaneRotation(double* dx, double* dy, double* cs, double* sn) else if (abs(*dy) > abs(*dx)) { temp = *dx / *dy; - *sn = 1.0 / sqrt( 1.0 + temp * temp ); + *sn = 1.0 / sqrt(1.0 + temp * temp); *cs = temp * *sn; } else { temp = *dy / *dx; - *cs = 1.0 / sqrt( 1.0 + temp * temp ); + *cs = 1.0 / sqrt(1.0 + temp * temp); *sn = temp * *cs; } } @@ -2069,7 +2079,7 @@ void GeneratePlaneRotation(double* dx, double* dy, double* cs, double* sn) void ApplyPlaneRotation(double* dx, double* dy, double* cs, double* sn) { static double temp; - temp = *cs * *dx + *sn * *dy; + temp = *cs * *dx + *sn * *dy; *dy = -*sn * *dx + *cs * *dy; *dx = temp; } @@ -2101,10 +2111,10 @@ void ApplyPlaneRotation(double* dx, double* dy, double* cs, double* sn) int SpCG(double* b, double* x, long n) { /* Variablen */ - static double* d, * r,* s, * tmp; + static double *d, *r, *s, *tmp; static double alpha, beta, tmpr, eps; int k = 0, max_iter = 0; - register int i; /* schnellere Vektoroperationen, Ra, 3/2000 */ + register int i; /* schnellere Vektoroperationen, Ra, 3/2000 */ static double r0norm, b0norm, x0norm; /* Ggf. starten der Vorkonditionierung */ @@ -2113,15 +2123,15 @@ int SpCG(double* b, double* x, long n) if (cg_maxiter > 0) max_iter = cg_maxiter; - //OK411 if (cg_maxiter == -1) - //OK411 max_iter = NodeListLength; +// OK411 if (cg_maxiter == -1) +// OK411 max_iter = NodeListLength; #ifdef TESTLOES4 DisplayMsgLn("SpCG"); #endif - r = (double*) Malloc(n * sizeof(double)); - s = (double*) Malloc(n * sizeof(double)); + r = (double*)Malloc(n * sizeof(double)); + s = (double*)Malloc(n * sizeof(double)); MXResiduum(x, b, r); if (linear_error_type == 0) @@ -2150,7 +2160,7 @@ int SpCG(double* b, double* x, long n) eps = cg_eps * MMax(MMax(x0norm, b0norm), r0norm); } - s = (double*) Free(s); + s = (double*)Free(s); #ifdef TESTLOES4 DisplayMsg("eps = "); @@ -2160,25 +2170,25 @@ int SpCG(double* b, double* x, long n) if (VEKNORM_CG(r, n) <= eps) { - r = (double*) Free(r); + r = (double*)Free(r); /* Ggf. abschliessen der Vorkonditionierung */ if (vorkond) MXVorkond(1, x, b); return 0; } - tmp = (double*) Malloc(n * sizeof(double)); - d = (double*) Malloc(n * sizeof(double)); + tmp = (double*)Malloc(n * sizeof(double)); + d = (double*)Malloc(n * sizeof(double)); - if VK_Modus - (VK_iLDU) MXVorkond(2, r, r); /* Ra, 3/2000 */ + if + VK_Modus(VK_iLDU) MXVorkond(2, r, r); /* Ra, 3/2000 */ for (i = 0; i < n; i++) d[i] = r[i]; - for (;; ) + for (;;) { MXMatVek(d, tmp); - if VK_Modus - (VK_iLDU) MXVorkond(2, tmp, tmp); /* Ra, 3/2000 */ + if + VK_Modus(VK_iLDU) MXVorkond(2, tmp, tmp); /* Ra, 3/2000 */ alpha = (tmpr = MSkalarprodukt(r, r, n)) / MSkalarprodukt(d, tmp, n); for (i = 0; i < n; i++) @@ -2188,8 +2198,8 @@ int SpCG(double* b, double* x, long n) } #ifdef SOLVER_SHOW_RESULTS - printf("\n%ld %f %f %f %f %f",(long)k,x[(long)(n * .1)],x[(long)(n * .3)], - x[(long)(n * .5)],x[(long)(n * .7)],x[(long)(n * .9)]); + printf("\n%ld %f %f %f %f %f", (long)k, x[(long)(n * .1)], x[(long)(n * .3)], x[(long)(n * .5)], + x[(long)(n * .7)], x[(long)(n * .9)]); #endif k++; @@ -2201,10 +2211,10 @@ int SpCG(double* b, double* x, long n) break; #ifdef SOLVER_SHOW_ERROR - if (k % (int)MMax((cg_maxiter / 10),1.) == 1) + if (k % (int)MMax((cg_maxiter / 10), 1.) == 1) { DisplayMsg(" Iteration-Nr.: "); - DisplayLong((long) k); + DisplayLong((long)k); DisplayMsg(", Fehler = "); DisplayDouble(VEKNORM_BICGSTAB(r, n) / eps, 4, 1); DisplayMsgLn(" "); @@ -2216,15 +2226,15 @@ int SpCG(double* b, double* x, long n) d[i] = r[i] + beta * d[i]; } - r = (double*) Free(r); - tmp = (double*) Free(tmp); - d = (double*) Free(d); + r = (double*)Free(r); + tmp = (double*)Free(tmp); + d = (double*)Free(d); /* Ggf. abschliessen der Vorkonditionierung */ if (vorkond) MXVorkond(1, x, b); - printf("\t SpCG iteration: %i/%i \n",k,max_iter); + printf("\t SpCG iteration: %i/%i \n", k, max_iter); return k; } @@ -2262,10 +2272,10 @@ int SpCG(double* b, double* x, long n) int SpCGNR(double* b, double* x, long n) { /* Variablen */ - static double* d, * r,* s, * tmp, * h = NULL; + static double *d, *r, *s, *tmp, *h = NULL; static double alpha, beta, tmpr, tmpr1, eps; int k = 0, max_iter = 0; - register int i; /* schnellere Vektoroperationen, Ra, 3/2000 */ + register int i; /* schnellere Vektoroperationen, Ra, 3/2000 */ static double r0norm, b0norm, x0norm; /* Ggf. starten der Vorkonditionierung */ @@ -2274,15 +2284,15 @@ int SpCGNR(double* b, double* x, long n) if (cg_maxiter > 0) max_iter = cg_maxiter; - //OK411 if (cg_maxiter == -1) - //OK411 max_iter = NodeListLength; +// OK411 if (cg_maxiter == -1) +// OK411 max_iter = NodeListLength; #ifdef TESTLOES4 DisplayMsgLn("SpCGNE"); #endif - r = (double*) Malloc(n * sizeof(double)); - s = (double*) Malloc(n * sizeof(double)); + r = (double*)Malloc(n * sizeof(double)); + s = (double*)Malloc(n * sizeof(double)); MXResiduum(x, b, r); if (linear_error_type == 0) @@ -2311,28 +2321,28 @@ int SpCGNR(double* b, double* x, long n) eps = cg_eps * MMax(MMax(x0norm, b0norm), r0norm); } - s = (double*) Free(s); + s = (double*)Free(s); if (VEKNORM_CG(r, n) <= eps) { - r = (double*) Free(r); + r = (double*)Free(r); /* Ggf. abschliessen der Vorkonditionierung */ if (vorkond) MXVorkond(1, x, b); return 0; } - tmp = (double*) Malloc(n * sizeof(double)); - d = (double*) Malloc(n * sizeof(double)); - if VK_Modus - (VK_iLDU) h = (double*) Malloc(n * sizeof(double)); + tmp = (double*)Malloc(n * sizeof(double)); + d = (double*)Malloc(n * sizeof(double)); + if + VK_Modus(VK_iLDU) h = (double*)Malloc(n * sizeof(double)); - if VK_Modus - (VK_iLDU) - { - MXVorkond(2, r, r); - MXVorkond(3, h, r); /* Ra, 3/2000 */ - MXMatTVek(h, tmp); - } + if + VK_Modus(VK_iLDU) + { + MXVorkond(2, r, r); + MXVorkond(3, h, r); /* Ra, 3/2000 */ + MXMatTVek(h, tmp); + } else MXMatTVek(r, tmp); @@ -2340,11 +2350,11 @@ int SpCGNR(double* b, double* x, long n) for (i = 0; i < n; i++) d[i] = tmp[i]; - for (;; ) + for (;;) { MXMatVek(d, tmp); - if VK_Modus - (VK_iLDU) MXVorkond(2, tmp, tmp); /* Ra, 3/2000 */ + if + VK_Modus(VK_iLDU) MXVorkond(2, tmp, tmp); /* Ra, 3/2000 */ alpha = tmpr / MSkalarprodukt(tmp, tmp, n); for (i = 0; i < n; i++) @@ -2354,8 +2364,8 @@ int SpCGNR(double* b, double* x, long n) } #ifdef SOLVER_SHOW_RESULTS - printf("\n%ld %f %f %f %f %f",(long)k,x[(long)(n * .1)],x[(long)(n * .3)], - x[(long)(n * .5)],x[(long)(n * .7)],x[(long)(n * .9)]); + printf("\n%ld %f %f %f %f %f", (long)k, x[(long)(n * .1)], x[(long)(n * .3)], x[(long)(n * .5)], + x[(long)(n * .7)], x[(long)(n * .9)]); #endif k++; if (linear_error_type == 4) @@ -2366,22 +2376,22 @@ int SpCGNR(double* b, double* x, long n) break; #ifdef SOLVER_SHOW_ERROR - if (k % (int)MMax((cg_maxiter / 10),1.) == 1) + if (k % (int)MMax((cg_maxiter / 10), 1.) == 1) { DisplayMsg(" Iteration-Nr.: "); - DisplayLong((long) k); + DisplayLong((long)k); DisplayMsg(", Fehler = "); DisplayDouble(VEKNORM_BICGSTAB(r, n) / eps, 4, 1); DisplayMsgLn(" "); } #endif - if VK_Modus - (VK_iLDU) - { - MXVorkond(3, h, r); /* Ra, 3/2000 */ - MXMatTVek(h, tmp); - } + if + VK_Modus(VK_iLDU) + { + MXVorkond(3, h, r); /* Ra, 3/2000 */ + MXMatTVek(h, tmp); + } else MXMatTVek(r, tmp); beta = (tmpr1 = MSkalarprodukt(tmp, tmp, n)) / tmpr; @@ -2390,10 +2400,10 @@ int SpCGNR(double* b, double* x, long n) tmpr = tmpr1; } - r = (double*) Free(r); - tmp = (double*) Free(tmp); - d = (double*) Free(d); - h = (double*) Free(h); + r = (double*)Free(r); + tmp = (double*)Free(tmp); + d = (double*)Free(d); + h = (double*)Free(h); /* Ggf. abschliessen der Vorkonditionierung */ if (vorkond) @@ -2431,11 +2441,11 @@ int SpCGNR(double* b, double* x, long n) int SpCGS(double* b, double* x, long n) { /* Variablen */ - static double* r, * s, * rs, * p, * q, * u, * v, * w, * us, * tmp; + static double *r, *s, *rs, *p, *q, *u, *v, *w, *us, *tmp; static double alpha, beta, rho, rho1; static double eps; static double r0norm, b0norm, x0norm; - register int i; /* schnellere Vektoroperationen, Ra, 3/2000 */ + register int i; /* schnellere Vektoroperationen, Ra, 3/2000 */ int k = 0, max_iter = 0; /* Ggf. starten der Vorkonditionierung */ @@ -2446,15 +2456,15 @@ int SpCGS(double* b, double* x, long n) if (cg_maxiter > 0) max_iter = cg_maxiter; - //OK411 if (cg_maxiter == -1) - //OK411 max_iter = NodeListLength; +// OK411 if (cg_maxiter == -1) +// OK411 max_iter = NodeListLength; #ifdef TESTLOES4 DisplayMsgLn("SpCGS"); #endif - r = (double*) Malloc(n * sizeof(double)); - s = (double*) Malloc(n * sizeof(double)); + r = (double*)Malloc(n * sizeof(double)); + s = (double*)Malloc(n * sizeof(double)); MXResiduum(x, b, r); if (linear_error_type == 0) @@ -2482,31 +2492,31 @@ int SpCGS(double* b, double* x, long n) r0norm = VEKNORM_BICGSTAB(r, n); eps = cg_eps * MMax(MMax(x0norm, b0norm), r0norm); } - s = (double*) Free(s); + s = (double*)Free(s); if (VEKNORM_CG(r, n) <= eps) { - r = (double*) Free(r); + r = (double*)Free(r); /* Ggf. abschliessen der Vorkonditionierung */ if (vorkond) MXVorkond(1, x, b); return 0; } - rs = (double*) Malloc(n * sizeof(double)); - p = (double*) Malloc(n * sizeof(double)); - q = (double*) Malloc(n * sizeof(double)); - u = (double*) Malloc(n * sizeof(double)); - v = (double*) Malloc(n * sizeof(double)); - w = (double*) Malloc(n * sizeof(double)); - us = (double*) Malloc(n * sizeof(double)); - tmp = (double*) Malloc(n * sizeof(double)); - - if VK_Modus - (VK_iLDU) MXVorkond(2, r, r); /* Ra, 3/2000 */ + rs = (double*)Malloc(n * sizeof(double)); + p = (double*)Malloc(n * sizeof(double)); + q = (double*)Malloc(n * sizeof(double)); + u = (double*)Malloc(n * sizeof(double)); + v = (double*)Malloc(n * sizeof(double)); + w = (double*)Malloc(n * sizeof(double)); + us = (double*)Malloc(n * sizeof(double)); + tmp = (double*)Malloc(n * sizeof(double)); + + if + VK_Modus(VK_iLDU) MXVorkond(2, r, r); /* Ra, 3/2000 */ for (i = 0; i < n; i++) rs[i] = r[i]; - for (;; ) + for (;;) { rho = MSkalarprodukt(rs, r, n); beta = rho / rho1; @@ -2517,8 +2527,8 @@ int SpCGS(double* b, double* x, long n) p[i] = u[i] + alpha * p[i] + beta * q[i]; } MXMatVek(p, v); - if VK_Modus - (VK_iLDU) MXVorkond(2, v, v); /* Ra, 3/2000 */ + if + VK_Modus(VK_iLDU) MXVorkond(2, v, v); /* Ra, 3/2000 */ alpha = rho / MSkalarprodukt(rs, v, n); for (i = 0; i < n; i++) { @@ -2527,12 +2537,12 @@ int SpCGS(double* b, double* x, long n) x[i] += alpha * us[i]; } #ifdef SOLVER_SHOW_RESULTS - printf("\n%ld %f %f %f %f %f",(long)k,x[(long)(n * .1)],x[(long)(n * .3)], - x[(long)(n * .5)],x[(long)(n * .7)],x[(long)(n * .9)]); + printf("\n%ld %f %f %f %f %f", (long)k, x[(long)(n * .1)], x[(long)(n * .3)], x[(long)(n * .5)], + x[(long)(n * .7)], x[(long)(n * .9)]); #endif MXMatVek(us, tmp); - if VK_Modus - (VK_iLDU) MXVorkond(2, tmp, tmp); /* Ra, 3/2000 */ + if + VK_Modus(VK_iLDU) MXVorkond(2, tmp, tmp); /* Ra, 3/2000 */ for (i = 0; i < n; i++) r[i] -= alpha * tmp[i]; @@ -2544,10 +2554,10 @@ int SpCGS(double* b, double* x, long n) break; #ifdef SOLVER_SHOW_ERROR - if (k % (int)MMax((cg_maxiter / 10),1.) == 1) + if (k % (int)MMax((cg_maxiter / 10), 1.) == 1) { DisplayMsg(" Iteration-Nr.: "); - DisplayLong((long) k); + DisplayLong((long)k); DisplayMsg(", Fehler = "); DisplayDouble(VEKNORM_QMRCGSTAB(r, n) / eps, 4, 1); DisplayMsgLn(" "); @@ -2559,15 +2569,15 @@ int SpCGS(double* b, double* x, long n) rho1 = rho; } - r = (double*) Free(r); - rs = (double*) Free(rs); - p = (double*) Free(p); - q = (double*) Free(q); - u = (double*) Free(u); - v = (double*) Free(v); - w = (double*) Free(w); - us = (double*) Free(us); - tmp = (double*) Free(tmp); + r = (double*)Free(r); + rs = (double*)Free(rs); + p = (double*)Free(p); + q = (double*)Free(q); + u = (double*)Free(u); + v = (double*)Free(v); + w = (double*)Free(w); + us = (double*)Free(us); + tmp = (double*)Free(tmp); /* Ggf. abschliessen der Vorkonditionierung */ if (vorkond) @@ -2624,7 +2634,7 @@ int SpGauss(double* vecb, double* vecx, long g) #ifdef TESTLOES DisplayMsgLn("SpGAUSS"); #endif - s = (int*) Malloc(sizeof(int) * (g - 1)); + s = (int*)Malloc(sizeof(int) * (g - 1)); /* LR-Faktorisierung */ for (k = 0; k < (g - 1); k++) { @@ -2651,7 +2661,7 @@ int SpGauss(double* vecb, double* vecx, long g) } /* Berechnung der Eliminationskoeffizienten */ for (i = (k + 1); i < g; i++) - MXDiv(i, k, MXGet(k, k)); /* matrix[i][k], matrix[k][k] */ + MXDiv(i, k, MXGet(k, k)); /* matrix[i][k], matrix[k][k] */ /* Spaltenweise Berechnung der neuen Restmatrix */ for (j = (k + 1); j < g; j++) for (i = (k + 1); i < g; i++) @@ -2678,14 +2688,14 @@ int SpGauss(double* vecb, double* vecx, long g) for (k = (g - 1); k >= 0; k--) { for (j = (k + 1); j < g; j++) - vecb[k] -= (MXGet(k, j) * vecb[j]); /* matrix[k][j] */ - vecb[k] /= MXGet(k, k); /* matrix[k][k] */ + vecb[k] -= (MXGet(k, j) * vecb[j]); /* matrix[k][j] */ + vecb[k] /= MXGet(k, k); /* matrix[k][k] */ } /* Umspeichern des Ergebnisses von vecb nach vecx */ for (k = 0; k < g; k++) vecx[k] = vecb[k]; /* Speicher freigeben */ - s = (int*) Free(s); + s = (int*)Free(s); /* Ende */ return 0; } @@ -2743,9 +2753,7 @@ int SpGauss(double* vecb, double* vecx, long g) 10/1997 C.Thorenz Variables Abbruchkriterium fuer CG-Loeser *************************************************************************/ -int NonLinearSolve(long cas, double* b, double* x, long n, void (* f)(double*, - double*, - double), long ind) +int NonLinearSolve(long cas, double* b, double* x, long n, void (*f)(double*, double*, double), long ind) { /* Variablen */ static long iter; @@ -2759,23 +2767,23 @@ int NonLinearSolve(long cas, double* b, double* x, long n, void (* f)(double*, /* Gleichungssystem-Parameter setzen */ switch (loeser_flow) { - case 1: - LinearSolver = SpGauss; - break; - case 2: + case 1: + LinearSolver = SpGauss; + break; + case 2: #ifndef USE_MPI - LinearSolver = SpBICGSTAB; + LinearSolver = SpBICGSTAB; #endif - break; - case 3: - LinearSolver = SpBICG; - break; - case 4: - LinearSolver = SpQMRCGSTAB; - break; - case 5: - LinearSolver = SpCG; - break; + break; + case 3: + LinearSolver = SpBICG; + break; + case 4: + LinearSolver = SpQMRCGSTAB; + break; + case 5: + LinearSolver = SpCG; + break; } cg_maxiter = maxiter_flow; cg_eps = eps_flow; @@ -2785,12 +2793,12 @@ int NonLinearSolve(long cas, double* b, double* x, long n, void (* f)(double*, /* Nichtlinearer-Loeser-Parameter setzen */ switch (nonlinear_method_flow) { - case 1: - NonlinearSolver = SpPICARD; - break; - case 2: - NonlinearSolver = SpNEWTON; - break; + case 1: + NonlinearSolver = SpPICARD; + break; + case 2: + NonlinearSolver = SpNEWTON; + break; } nonlinear_maxiter = nonlinear_maxiter_flow; nonlinear_convergence_type = nonlinear_convergence_type_flow; @@ -2801,12 +2809,12 @@ int NonLinearSolve(long cas, double* b, double* x, long n, void (* f)(double*, #ifdef TESTLOES6 switch (nonlinear_method_flow) { - case 1: - strcpy(text, "SpPICARD"); - break; - case 2: - strcpy(text, "SpNEWTON"); - break; + case 1: + strcpy(text, "SpPICARD"); + break; + case 2: + strcpy(text, "SpNEWTON"); + break; } DisplayMsgLn(text); #endif @@ -2816,23 +2824,23 @@ int NonLinearSolve(long cas, double* b, double* x, long n, void (* f)(double*, /* Gleichungssystem-Parameter setzen */ switch (loeser_tran) { - case 1: - LinearSolver = SpGauss; - break; - case 2: + case 1: + LinearSolver = SpGauss; + break; + case 2: #ifndef USE_MPI - LinearSolver = SpBICGSTAB; + LinearSolver = SpBICGSTAB; #endif - break; - case 3: - LinearSolver = SpBICG; - break; - case 4: - LinearSolver = SpQMRCGSTAB; - break; - case 5: - LinearSolver = SpCG; - break; + break; + case 3: + LinearSolver = SpBICG; + break; + case 4: + LinearSolver = SpQMRCGSTAB; + break; + case 5: + LinearSolver = SpCG; + break; } cg_maxiter = maxiter_tran; cg_eps = eps_tran; @@ -2842,12 +2850,12 @@ int NonLinearSolve(long cas, double* b, double* x, long n, void (* f)(double*, /* Nichtlinearer-Loeser-Parameter setzen */ switch (nonlinear_method_tran) { - case 1: - NonlinearSolver = SpPICARD; - break; - case 2: - NonlinearSolver = SpNEWTON; - break; + case 1: + NonlinearSolver = SpPICARD; + break; + case 2: + NonlinearSolver = SpNEWTON; + break; } nonlinear_maxiter = nonlinear_maxiter_tran; nonlinear_convergence_type = nonlinear_convergence_type_tran; @@ -2859,12 +2867,12 @@ int NonLinearSolve(long cas, double* b, double* x, long n, void (* f)(double*, #ifdef TESTLOES switch (nonlinear_method_tran) { - case 1: - strcpy(text, "SpPICARD"); - break; - case 2: - strcpy(text, "SpNEWTON"); - break; + case 1: + strcpy(text, "SpPICARD"); + break; + case 2: + strcpy(text, "SpNEWTON"); + break; } DisplayMsgLn(text); #endif @@ -2911,23 +2919,22 @@ int NonLinearSolve(long cas, double* b, double* x, long n, void (* f)(double*, */ /**************************************************************************/ -int SpPICARD(double* b, double* x, long n, void (* f)(double* b, - double* x, - double aktuelle_zeit), long ind) +int SpPICARD(double* b, double* x, long n, void (*f)(double* b, double* x, double aktuelle_zeit), long ind) /*int SpPICARD ( double *b, double *x, long n, void (*f)(), long ind ) */ { - ind = ind; //OK411 + ind = ind; // OK411 /* Variablen */ - static double* r, * xs, * rs; + static double *r, *xs, *rs; int k = 0; static long iter; static double error; static double nonlinear_eps; static int iterations_old_timestep = -1; - static double cg_eps_original; /* Hilfsspeicher fuer die urspruengliche Loesungsgenauigkeit */ - static int dirty; /* Kennzeichnet, dass die Iteration trotz unterschreiten der Fehlerschranke nicht abgebrochen werden darf */ - static int rebuild_matrix; /* Kennzeichnet, dass die Systemmatrix neu aufgebaut werden muss */ + static double cg_eps_original; /* Hilfsspeicher fuer die urspruengliche Loesungsgenauigkeit */ + static int dirty; /* Kennzeichnet, dass die Iteration trotz unterschreiten der Fehlerschranke nicht abgebrochen + werden darf */ + static int rebuild_matrix; /* Kennzeichnet, dass die Systemmatrix neu aufgebaut werden muss */ #define GERMAN @@ -2947,19 +2954,19 @@ int SpPICARD(double* b, double* x, long n, void (* f)(double* b, Speicherreservierung fuer temporaere Felder */ if (nonlinear_convergence_type == 1) { - xs = (double*) Malloc(n * sizeof(double)); + xs = (double*)Malloc(n * sizeof(double)); MKopierVec(x, xs, n); } if (nonlinear_convergence_type == 2) { - r = (double*) Malloc(n * sizeof(double)); - rs = (double*) Malloc(n * sizeof(double)); + r = (double*)Malloc(n * sizeof(double)); + rs = (double*)Malloc(n * sizeof(double)); MXResiduum(x, b, r); MKopierVec(r, rs, n); } if (nonlinear_convergence_type == 3) { - xs = (double*) Malloc(n * sizeof(double)); + xs = (double*)Malloc(n * sizeof(double)); MKopierVec(x, xs, n); } /* bs = (double *) Malloc(n*sizeof(double)); @@ -2969,7 +2976,7 @@ int SpPICARD(double* b, double* x, long n, void (* f)(double* b, /****************************************************************************/ /* Loesen des Gleichungssystems und Fehlerberechnung */ - for (;; ) + for (;;) { k++; dirty = 0; @@ -2993,42 +3000,40 @@ int SpPICARD(double* b, double* x, long n, void (* f)(double* b, iter = LinearSolver(b, x, n); /* Speichern des Ergebnisses des Iterationsschritts in nval[ind] */ - //OK411 TransferNodeVals(x, ind); + // OK411 TransferNodeVals(x, ind); /* Fehlerberechnung */ switch (nonlinear_convergence_type) { - case 1: - error = MVekDist(x, xs, n); - nonlinear_eps = nonlinear_abs_eps + \ - nonlinear_rel_eps* VEKNORM_BICG(xs, n); - break; - case 2: - MXResiduum(x, b, r); - error = VEKNORM_BICG(r, n); - nonlinear_eps = nonlinear_abs_eps + \ - nonlinear_rel_eps* VEKNORM_BICG(rs, n); - break; - case 3: - error = MVekDist(x, xs, n); - nonlinear_eps = nonlinear_rel_eps * VEKNORM_BICG(x, n); - break; + case 1: + error = MVekDist(x, xs, n); + nonlinear_eps = nonlinear_abs_eps + nonlinear_rel_eps * VEKNORM_BICG(xs, n); + break; + case 2: + MXResiduum(x, b, r); + error = VEKNORM_BICG(r, n); + nonlinear_eps = nonlinear_abs_eps + nonlinear_rel_eps * VEKNORM_BICG(rs, n); + break; + case 3: + error = MVekDist(x, xs, n); + nonlinear_eps = nonlinear_rel_eps * VEKNORM_BICG(x, n); + break; } #ifdef GERMAN DisplayMsg(" Iteration-Nr.: "); - DisplayLong((long) k); + DisplayLong((long)k); DisplayMsg(", GLS-Iter. = "); - DisplayLong((long) iter); + DisplayLong((long)iter); DisplayMsg(", Fehler/Abbruchf. = "); DisplayDouble(error / nonlinear_eps, 4, 1); DisplayMsgLn(" "); #endif #ifdef ENGLISH DisplayMsg(" Iteration-Nr.: "); - DisplayLong((long) k); + DisplayLong((long)k); DisplayMsg(", Linear solver iterations = "); - DisplayLong((long) iter); + DisplayLong((long)iter); DisplayMsg(", error/errorcrit. = "); DisplayDouble(error / nonlinear_eps, 4, 1); DisplayMsgLn(""); @@ -3044,9 +3049,7 @@ int SpPICARD(double* b, double* x, long n, void (* f)(double* b, cg_eps = cg_eps_original; } else - cg_eps = - (error / - nonlinear_eps) * nonlinear_rel_eps * nonlinear_rel_cg_eps; + cg_eps = (error / nonlinear_eps) * nonlinear_rel_eps * nonlinear_rel_cg_eps; if (cg_eps < cg_eps_original) cg_eps = cg_eps_original; } @@ -3076,11 +3079,11 @@ int SpPICARD(double* b, double* x, long n, void (* f)(double* b, /* Speicherfreigabe */ if ((nonlinear_convergence_type == 1) || (nonlinear_convergence_type == 3)) - xs = (double*) Free(xs); + xs = (double*)Free(xs); else if (nonlinear_convergence_type == 2) { - r = (double*) Free(r); - rs = (double*) Free(rs); + r = (double*)Free(r); + rs = (double*)Free(rs); } /* bs= Free(bs); */ @@ -3121,29 +3124,29 @@ int SpPICARD(double* b, double* x, long n, void (* f)(double* b, *************************************************************************/ #ifdef ksdjfjdshashdhahsfgkfdg -int SpNEWTON(double* b, double* x, long n, void (* f)(double* b, double* x, double dummy), long ind) +int SpNEWTON(double* b, double* x, long n, void (*f)(double* b, double* x, double dummy), long ind) #else int SpNEWTON(double*, double*, long, void (*)(double*, double*, double), long) #endif /*int SpNEWTON ( double *b, double *x, long n, void (*f)(), long ind ) */ { - //WW double ddummy; - //WW long ldummy; - //WW void (*g) (double *b, double *x, double dummy); + // WW double ddummy; + // WW long ldummy; + // WW void (*g) (double *b, double *x, double dummy); DisplayMsgLn("Newton noch nicht implementiert !!! "); - //WW ddummy = b[0]; - //WW ddummy = x[0]; - //WW ldummy = n; - //WW ldummy = ind; - //WW g = f; + // WW ddummy = b[0]; + // WW ddummy = x[0]; + // WW ldummy = n; + // WW ldummy = ind; + // WW g = f; return nonlinear_maxiter; #ifdef ksdjfjdshashdhahsfgkfdg /* Variablen */ - static double* r, * dx, * xs; + static double *r, *dx, *xs; static double eps; int k = 0, max_iter = 0; static float omega = 0.5; @@ -3154,9 +3157,9 @@ int SpNEWTON(double*, double*, long, void (*)(double*, double*, double), long) #endif k = 0; - r = (double*) Malloc(n * sizeof(double)); - dx = (double*) Malloc(n * sizeof(double)); - xs = (double*) Malloc(n * sizeof(double)); + r = (double*)Malloc(n * sizeof(double)); + dx = (double*)Malloc(n * sizeof(double)); + xs = (double*)Malloc(n * sizeof(double)); #ifdef RELATIVE_EPS eps = VEKNORM_BICG(b, n); @@ -3174,12 +3177,12 @@ int SpNEWTON(double*, double*, long, void (*)(double*, double*, double), long) MXResiduum(x, b, r); if (VEKNORM_BICG(r, n) <= eps) { - r = (double*) Free(r); - dx = (double*) Free(r); - xs = (double*) Free(xs); + r = (double*)Free(r); + dx = (double*)Free(r); + xs = (double*)Free(xs); return k; } - for (;; ) + for (;;) { k++; MKopierVec(x, xs, n); @@ -3189,12 +3192,12 @@ int SpNEWTON(double*, double*, long, void (*)(double*, double*, double), long) MXResiduum(x, b, r); switch (nonlinear_convergence_type) { - case 1: - error = MVekDist(x, xs, n); - break; - case 2: - error = VEKNORM_BICG(r, n); - break; + case 1: + error = MVekDist(x, xs, n); + break; + case 2: + error = VEKNORM_BICG(r, n); + break; } if (error <= nonlinear_abs_eps) break; @@ -3204,9 +3207,9 @@ int SpNEWTON(double*, double*, long, void (*)(double*, double*, double), long) f(b, x, ind); } - r = (double*) Free(r); - dx = (double*) Free(dx); - xs = (double*) Free(xs); + r = (double*)Free(r); + dx = (double*)Free(dx); + xs = (double*)Free(xs); return k; #endif diff --git a/FEM/solver.h b/FEM/solver.h index 1516b077a..7c33046fa 100644 --- a/FEM/solver.h +++ b/FEM/solver.h @@ -7,13 +7,13 @@ * */ - /*************************************************************************** - ROCKFLOW - Modul: solver.h +/*************************************************************************** + ROCKFLOW - Modul: solver.h - Aufgabe: - ROCKFLOW-Schnittstelle fuer alle Loeser + Aufgabe: + ROCKFLOW-Schnittstelle fuer alle Loeser - **************************************************************************/ +**************************************************************************/ #ifndef solver_INC #define solver_INC @@ -28,15 +28,15 @@ extern int loeser_flow, loeser_tran, loeser_temp, loeser_satu; extern double gls_iter_theta; extern int vorkond, vorkond_flow, vorkond_tran, vorkond_temp, vorkond_satu; extern int speichertechnik_flow, speichertechnik_tran, speichertechnik_temp, speichertechnik_satu; -extern int linear_error_type,linear_error_type_flow,linear_error_type_tran,linear_error_type_temp, - linear_error_type_satu; +extern int linear_error_type, linear_error_type_flow, linear_error_type_tran, linear_error_type_temp, + linear_error_type_satu; extern double eps_flow, eps_tran, eps_temp, eps_satu, cg_eps; extern int maxiter_flow, maxiter_tran, maxiter_temp, maxiter_satu, cg_maxiter; extern int repeat_flow, repeat_tran, repeat_temp, repeat_satu, cg_repeat; /* Funktionszeiger auf Loeser */ extern IntFuncDXDXL LoeserFlow, LoeserTran, LoeserTemp, LoeserSatu; -extern int sp2_start, sp2_inc; /* Speichertechnik-Feineinstellung */ +extern int sp2_start, sp2_inc; /* Speichertechnik-Feineinstellung */ extern double rel_eps; /* Deklarationen fuer Schluesselwoerter #ITERATION_FLOW und #ITERATION_TRANSPORT */ @@ -51,18 +51,18 @@ extern double nonlinear_abs_eps_flow, nonlinear_abs_eps_tran; /* rel. Abbruchkriterium */ extern double nonlinear_rel_eps_flow, nonlinear_rel_eps_tran; /* rel. Genauigkeit fuer CG-Loeser */ -extern double nonlinear_rel_cg_eps,nonlinear_rel_cg_eps_flow, nonlinear_rel_cg_eps_tran; +extern double nonlinear_rel_cg_eps, nonlinear_rel_cg_eps_flow, nonlinear_rel_cg_eps_tran; /* Wiederaufbau des globalen Systems */ extern int nonlinear_assemble_flow, nonlinear_assemble_tran; /* andere benoetigte globale variablen */ -extern int nonlinear_method; /* Nichtlinear-Gleichungsloeser-Nummern */ -extern int nonlinear_maxiter; /* max. Iterationen fuer Nichtlinear-Loeser */ -extern int nonlinear_convergence_type; /* Konvergenztyp fuer Nichtlinear-Loeser */ -extern double nonlinear_abs_eps; /* abs. Abbruchkriterium */ -extern double nonlinear_rel_eps; /* rel. Abbruchkriterium */ -extern double nonlinear_rel_cg_eps; /* rel. Genauigkeit fuer CG-Loeser */ -extern int nonlinear_assemble; /* Wiederaufbau des globalen Systems */ +extern int nonlinear_method; /* Nichtlinear-Gleichungsloeser-Nummern */ +extern int nonlinear_maxiter; /* max. Iterationen fuer Nichtlinear-Loeser */ +extern int nonlinear_convergence_type; /* Konvergenztyp fuer Nichtlinear-Loeser */ +extern double nonlinear_abs_eps; /* abs. Abbruchkriterium */ +extern double nonlinear_rel_eps; /* rel. Abbruchkriterium */ +extern double nonlinear_rel_cg_eps; /* rel. Genauigkeit fuer CG-Loeser */ +extern int nonlinear_assemble; /* Wiederaufbau des globalen Systems */ /* Deklarationen fuer Schluesselwoerter #ITERATION_TIME_CONTROL */ extern int iteration_min_iter; @@ -75,55 +75,53 @@ extern double iteration_max_dt; /*-----------------------------------------------------------------------*/ /* Objekt-Methoden */ -extern void InitSolverParameter(void); /* ToDo raus */ +extern void InitSolverParameter(void); /* ToDo raus */ extern void ConfigRenumberProperties(void); /* Lineare Solver */ -extern IntFuncDXDXL LinearSolver; /* Funktionszeiger auf linearen Loeser */ -extern int SpRichardson ( double* b, double* x, long n ); +extern IntFuncDXDXL LinearSolver; /* Funktionszeiger auf linearen Loeser */ +extern int SpRichardson(double* b, double* x, long n); /* Richardson-Loeser */ -extern int SpJOR ( double* b, double* x, long n ); +extern int SpJOR(double* b, double* x, long n); /* Jacobi-Loeser */ -extern int SpSOR ( double* b, double* x, long n ); +extern int SpSOR(double* b, double* x, long n); /* SOR-Loeser (Successive Over Relaxation) */ -extern void Gauss ( double* matrix, double* vecb, double* vecx, int g ); +extern void Gauss(double* matrix, double* vecb, double* vecx, int g); /* Gauss-Loeser */ -extern void LU_Decomposition (double* matrix, double* vecb, double* vecx, int g); +extern void LU_Decomposition(double* matrix, double* vecb, double* vecx, int g); /* LU Dekomoposition */ -extern int SpBICG ( double* b, double* x, long n ); +extern int SpBICG(double* b, double* x, long n); /* BICG-Loeser */ -extern int SpBICGSTAB_old ( double* b, double* x, long n ); +extern int SpBICGSTAB_old(double* b, double* x, long n); #ifdef SX int SpBICGSTAB(double* restrict b, double* restrict x, long n); #else -int SpBICGSTAB(double* b, double* x, long n); +int SpBICGSTAB(double* b, double* x, long n); #endif /* BICGSTAB-Loeser */ -extern int SpQMRCGSTAB ( double* b, double* x, long n ); +extern int SpQMRCGSTAB(double* b, double* x, long n); /* QMRCGSTAB-Loeser */ -extern int SpMGMRES ( double* b, double* x, long n ); +extern int SpMGMRES(double* b, double* x, long n); /* MGMRES-Loeser */ -extern int SpCG ( double* b, double* x, long n ); +extern int SpCG(double* b, double* x, long n); /* CG-Loeser */ -extern int SpCGNR ( double* b, double* x, long n ); +extern int SpCGNR(double* b, double* x, long n); /* CGNR-Loeser */ -extern int SpCGS ( double* b, double* x, long n ); +extern int SpCGS(double* b, double* x, long n); /* CGS-Loeser */ -extern int SpGauss ( double* vecb, double* vecx, long g ); +extern int SpGauss(double* vecb, double* vecx, long g); /* Gauss-Loeser */ -extern int SpAMG1R5( double* b, double* x, long n ); +extern int SpAMG1R5(double* b, double* x, long n); /* Algebraischer-Multigrid-Loeser AMG1R5 */ -extern int SpUMF ( double* b, double* x, long n ); +extern int SpUMF(double* b, double* x, long n); /* UMF-Loeser aus UMFPack */ /* Nicht-Lineare Solver */ -extern IntFuncDXDXLVXL NonlinearSolver; /* Funktionszeiger auf nichtlinearen Loeser */ -extern int NonLinearSolve( long cas, double* b, double* x, long n, void (*)(double*, - double*, - double), long ind ); +extern IntFuncDXDXLVXL NonlinearSolver; /* Funktionszeiger auf nichtlinearen Loeser */ +extern int NonLinearSolve(long cas, double* b, double* x, long n, void (*)(double*, double*, double), long ind); /* Initialisierung und Aufruf des NLGS */ -extern int SpPICARD ( double* b, double* x, long n, void (*)(double*,double*,double), long ); +extern int SpPICARD(double* b, double* x, long n, void (*)(double*, double*, double), long); /* PICARD-Loeser */ -extern int SpNEWTON ( double* b, double* x, long n, void (*)(double*,double*,double), long ); +extern int SpNEWTON(double* b, double* x, long n, void (*)(double*, double*, double), long); /* mod-NEWTON-Loeser */ #endif diff --git a/FEM/tools.cpp b/FEM/tools.cpp index 6289eda22..e6b02d8a4 100644 --- a/FEM/tools.cpp +++ b/FEM/tools.cpp @@ -37,7 +37,7 @@ #include "femlib.h" #include "mathlib.h" -#include "rf_fct.h" //NB +#include "rf_fct.h" //NB #include "rf_mmp_new.h" #include "rf_num_new.h" #include "rf_tim_new.h" @@ -51,7 +51,7 @@ using namespace std; Kurven* kurven = NULL; int anz_kurven = 0; -double* fracture_aperture_array = NULL; +double* fracture_aperture_array = NULL; hetfields* hf = NULL; long fracture_aperture_anz = 0l; @@ -121,7 +121,7 @@ double GetCurveValue(int kurve, int methode, double punkt, int* gueltig) } #ifdef ERROR_CONTROL - if((kurve < 0) || (kurve >= anz_kurven)) + if ((kurve < 0) || (kurve >= anz_kurven)) { DisplayMsgLn(""); DisplayMsg("PANIC! Curve "); @@ -140,11 +140,13 @@ double GetCurveValue(int kurve, int methode, double punkt, int* gueltig) i++; // // Check curve bounds - if(punkt < s[0].punkt){ + if (punkt < s[0].punkt) + { *gueltig = 0; return s[0].wert; } - if(punkt > s[anz - 1l].punkt){ + if (punkt > s[anz - 1l].punkt) + { *gueltig = 0; return s[anz - 1l].wert; } @@ -156,12 +158,12 @@ double GetCurveValue(int kurve, int methode, double punkt, int* gueltig) ScreenMessage("ERROR: GetCurveValue() --> Invalid curve.\n"); return 0.0; // - case 0: // Linear Interpolation - return s[i - 1].wert + (s[i].wert - s[i - 1l].wert) / - (s[i].punkt - s[i - 1l].punkt) * (punkt - s[i - 1l].punkt); + case 0: // Linear Interpolation + return s[i - 1].wert + + (s[i].wert - s[i - 1l].wert) / (s[i].punkt - s[i - 1l].punkt) * (punkt - s[i - 1l].punkt); // - case 1: // Piece wise constant - return s[i-1].wert; //BG changed from i to i-1, 2011 + case 1: // Piece wise constant + return s[i - 1].wert; // BG changed from i to i-1, 2011 } } @@ -198,7 +200,7 @@ double GetCurveValueInverse(int kurve, int methode, double wert, int* gueltig) static StuetzStellen* s; #ifdef ERROR_CONTROL - if((kurve < 0) || (kurve >= anz_kurven)) + if ((kurve < 0) || (kurve >= anz_kurven)) { DisplayMsgLn(""); DisplayMsg("PANIC! Curve "); @@ -255,12 +257,12 @@ double GetCurveValueInverse(int kurve, int methode, double wert, int* gueltig) return 0.0; // case 0: // Lineare Interpolation - return s[i - 1].punkt + (s[i].punkt - s[i - 1l].punkt) / - (s[i].wert - s[i - 1l].wert) * (wert - s[i - 1l].wert); + return s[i - 1].punkt + + (s[i].punkt - s[i - 1l].punkt) / (s[i].wert - s[i - 1l].wert) * (wert - s[i - 1l].wert); // case 1: // Piece wise constant return s[i].punkt; - } + } } /************************************************************************** @@ -303,7 +305,7 @@ double GetCurveDerivative(int kurve, int methode, double punkt, int* gueltig) } #ifdef ERROR_CONTROL - if((kurve < 0) || (kurve >= anz_kurven)) + if ((kurve < 0) || (kurve >= anz_kurven)) { DisplayMsgLn(""); DisplayMsg("PANIC! Curve "); @@ -337,35 +339,33 @@ double GetCurveDerivative(int kurve, int methode, double punkt, int* gueltig) switch (methode) { - default: - case 0: - /* Stueckweise konstant */ - if(fabs(s[i].punkt - s[i - 1].punkt) > DBL_MIN) - return (s[i].wert - s[i - 1].wert) / (s[i].punkt - s[i - 1].punkt); - else - return Signum(s[i + 1].wert - s[i].wert) / DBL_EPSILON; - case 1: - /* Gleitend */ - if ((i > 1) && (i < anz - 2)) - { - s1 = (0.5 * s[i].wert - 0.5 * s[i - 2].wert) / - (0.5 * s[i].punkt - 0.5 * s[i - 2].punkt); - - s2 = (0.5 * s[i + 1].wert - 0.5 * s[i - 1].wert) / - (0.5 * s[i + 1].punkt - 0.5 * s[i - 1].punkt); - - w = (punkt - s[i - 1].punkt) / (s[i].punkt - s[i - 1].punkt); - - return (1. - w) * s1 + w * s2; - } - else - { + default: + case 0: /* Stueckweise konstant */ - if(fabs(s[i].punkt - s[i - 1].punkt) > DBL_MIN) + if (fabs(s[i].punkt - s[i - 1].punkt) > DBL_MIN) return (s[i].wert - s[i - 1].wert) / (s[i].punkt - s[i - 1].punkt); else return Signum(s[i + 1].wert - s[i].wert) / DBL_EPSILON; - } + case 1: + /* Gleitend */ + if ((i > 1) && (i < anz - 2)) + { + s1 = (0.5 * s[i].wert - 0.5 * s[i - 2].wert) / (0.5 * s[i].punkt - 0.5 * s[i - 2].punkt); + + s2 = (0.5 * s[i + 1].wert - 0.5 * s[i - 1].wert) / (0.5 * s[i + 1].punkt - 0.5 * s[i - 1].punkt); + + w = (punkt - s[i - 1].punkt) / (s[i].punkt - s[i - 1].punkt); + + return (1. - w) * s1 + w * s2; + } + else + { + /* Stueckweise konstant */ + if (fabs(s[i].punkt - s[i - 1].punkt) > DBL_MIN) + return (s[i].wert - s[i - 1].wert) / (s[i].punkt - s[i - 1].punkt); + else + return Signum(s[i + 1].wert - s[i].wert) / DBL_EPSILON; + } } } @@ -409,7 +409,7 @@ double GetCurveInverseDerivative(int kurve, int methode, double wert, int* guelt } #ifdef ERROR_CONTROL - if((kurve < 0) || (kurve >= anz_kurven)) + if ((kurve < 0) || (kurve >= anz_kurven)) { DisplayMsgLn(""); DisplayMsg("PANIC! Curve "); @@ -439,8 +439,9 @@ double GetCurveInverseDerivative(int kurve, int methode, double wert, int* guelt i = anz - 1; wert = s[anz - 1].wert; } - else{ /* Suchen der Stuetzstelle. Vorraussetzung: Zeitpunkte aufsteigend geordnet */ - while(wert > s[i].wert) + else + { /* Suchen der Stuetzstelle. Vorraussetzung: Zeitpunkte aufsteigend geordnet */ + while (wert > s[i].wert) i++; } } @@ -459,7 +460,8 @@ double GetCurveInverseDerivative(int kurve, int methode, double wert, int* guelt i = anz - 1; wert = s[anz - 1].wert; } - else{ /* Suchen der Stuetzstelle. Vorraussetzung: Zeitpunkte aufsteigend geordnet */ + else + { /* Suchen der Stuetzstelle. Vorraussetzung: Zeitpunkte aufsteigend geordnet */ while (wert < s[i].wert) i++; } @@ -467,35 +469,33 @@ double GetCurveInverseDerivative(int kurve, int methode, double wert, int* guelt switch (methode) { - default: - case 0: - /* Stueckweise konstant */ - if(fabs(s[i].wert - s[i - 1].wert) > DBL_MIN) - return (s[i].punkt - s[i - 1].punkt) / (s[i].wert - s[i - 1].wert); - else - return Signum(s[i + 1].punkt - s[i].punkt) / DBL_EPSILON; - case 1: - /* Gleitend */ - if ((i > 1) && (i < anz - 2)) - { - s1 = (0.5 * s[i].punkt - 0.5 * s[i - 2].punkt) / - (0.5 * s[i].wert - 0.5 * s[i - 2].wert); - - s2 = (0.5 * s[i + 1].punkt - 0.5 * s[i - 1].punkt) / - (0.5 * s[i + 1].wert - 0.5 * s[i - 1].wert); - - w = (wert - s[i - 1].wert) / (s[i].wert - s[i - 1].wert); - - return (1. - w) * s1 + w * s2; - } - else - { + default: + case 0: /* Stueckweise konstant */ - if(fabs(s[i].wert - s[i - 1].wert) > DBL_MIN) + if (fabs(s[i].wert - s[i - 1].wert) > DBL_MIN) return (s[i].punkt - s[i - 1].punkt) / (s[i].wert - s[i - 1].wert); else return Signum(s[i + 1].punkt - s[i].punkt) / DBL_EPSILON; - } + case 1: + /* Gleitend */ + if ((i > 1) && (i < anz - 2)) + { + s1 = (0.5 * s[i].punkt - 0.5 * s[i - 2].punkt) / (0.5 * s[i].wert - 0.5 * s[i - 2].wert); + + s2 = (0.5 * s[i + 1].punkt - 0.5 * s[i - 1].punkt) / (0.5 * s[i + 1].wert - 0.5 * s[i - 1].wert); + + w = (wert - s[i - 1].wert) / (s[i].wert - s[i - 1].wert); + + return (1. - w) * s1 + w * s2; + } + else + { + /* Stueckweise konstant */ + if (fabs(s[i].wert - s[i - 1].wert) > DBL_MIN) + return (s[i].punkt - s[i - 1].punkt) / (s[i].wert - s[i - 1].wert); + else + return Signum(s[i + 1].punkt - s[i].punkt) / DBL_EPSILON; + } } } @@ -539,18 +539,17 @@ int FctCurves(char* data, int found, FILE* f) #endif LineFeed(f); - FilePrintString(f, - "; 9 Functions ----------------------------------------------------------"); + FilePrintString(f, "; 9 Functions ----------------------------------------------------------"); LineFeed(f); /* Erste Konstante 1-Zeitkurve einfuegen (Index 0) - muss vorhanden sein TODO */ - if ( (found == 0) || (found == 1) ) + if ((found == 0) || (found == 1)) { anz_kurven = 1; - stuetz = (StuetzStellen*) Malloc(sizeof(StuetzStellen)); + stuetz = (StuetzStellen*)Malloc(sizeof(StuetzStellen)); stuetz[0].punkt = 1.0; stuetz[0].wert = 1.0; - kurven = (Kurven*) Malloc(sizeof(Kurven)); + kurven = (Kurven*)Malloc(sizeof(Kurven)); kurven[anz_kurven - 1].anz_stuetzstellen = 1; kurven[anz_kurven - 1].stuetzstellen = stuetz; } @@ -565,10 +564,10 @@ int FctCurves(char* data, int found, FILE* f) else { /* CURVES gefunden */ - while (StrTestHash(&data[p],&pos) || (found == 2)) + while (StrTestHash(&data[p], &pos) || (found == 2)) { /* Pruef-Funktion*/ - if ( (found == 2) && (curve_counter >= anz_kurven) ) + if ((found == 2) && (curve_counter >= anz_kurven)) break; FilePrintString(f, "#CURVES"); LineFeed(f); @@ -577,19 +576,13 @@ int FctCurves(char* data, int found, FILE* f) LineFeed(f); FilePrintString(f, "; Das Schluesselwort muss nicht vorhanden sein."); LineFeed(f); - FilePrintString( - f, - "; Es folgen beliebig viele Abschnitte, die jeweils eine eigene Kurve"); + FilePrintString(f, "; Es folgen beliebig viele Abschnitte, die jeweils eine eigene Kurve"); LineFeed(f); - FilePrintString( - f, - "; darstellen und jeweils mit dem Schluesselwort #CURVES eingeleitet werden"); + FilePrintString(f, "; darstellen und jeweils mit dem Schluesselwort #CURVES eingeleitet werden"); LineFeed(f); FilePrintString(f, "; muessen. Jede Dieser Kurven hat folgendes Aussehen:"); LineFeed(f); - FilePrintString( - f, - "; Eine Kurve setzt sich aus Stuetzstellen und Werten an den Stuetzstellen"); + FilePrintString(f, "; Eine Kurve setzt sich aus Stuetzstellen und Werten an den Stuetzstellen"); LineFeed(f); FilePrintString(f, "; zusammen:"); LineFeed(f); @@ -610,10 +603,7 @@ int FctCurves(char* data, int found, FILE* f) ok = (StrReadDouble(&d2, &data[p += pos], f, &pos) && ok); LineFeed(f); anz++; - stuetz = - (StuetzStellen*) Realloc(stuetz, - (anz * - sizeof(StuetzStellen))); + stuetz = (StuetzStellen*)Realloc(stuetz, (anz * sizeof(StuetzStellen))); stuetz[anz - 1].punkt = d1; stuetz[anz - 1].wert = d2; } @@ -621,30 +611,26 @@ int FctCurves(char* data, int found, FILE* f) { /* gueltige Zeitkurve, d.h. mind. 1 gueltige Stuetzstelle */ anz_kurven++; - kurven = - (Kurven*) Realloc(kurven, - (anz_kurven * sizeof(Kurven))); + kurven = (Kurven*)Realloc(kurven, (anz_kurven * sizeof(Kurven))); kurven[anz_kurven - 1].anz_stuetzstellen = anz; kurven[anz_kurven - 1].stuetzstellen = stuetz; } else { - FilePrintString( - f, - "* vorhergehende Zeitkurve unzulaessig, ignoriert !"); + FilePrintString(f, "* vorhergehende Zeitkurve unzulaessig, ignoriert !"); LineFeed(f); - stuetz = (StuetzStellen*) Free(stuetz); + stuetz = (StuetzStellen*)Free(stuetz); /* stuetz = Free(stuetz); MFC */ } } else if (found == 2) - if(curve_counter > 0) /* Dummy-Kurve nicht ausgeben */ + if (curve_counter > 0) /* Dummy-Kurve nicht ausgeben */ { stuetz = kurven[curve_counter].stuetzstellen; - for(i = 0; i < kurven[curve_counter].anz_stuetzstellen; i++) + for (i = 0; i < kurven[curve_counter].anz_stuetzstellen; i++) { - fprintf(f," %e ",stuetz[i].punkt); - fprintf(f," %e ",stuetz[i].wert); + fprintf(f, " %e ", stuetz[i].punkt); + fprintf(f, " %e ", stuetz[i].wert); LineFeed(f); } stuetz = NULL; @@ -672,7 +658,7 @@ int FctCurves(char* data, int found, FILE* f) // 08/2005 MB $NUM_TYPE NEW // */ ///**************************************************************************/ -//int FctReadHeterogeneousFields(char* name_file, CMediumProperties* m_mat_mp) +// int FctReadHeterogeneousFields(char* name_file, CMediumProperties* m_mat_mp) //{ // int ok = 0, method; // double* convertfact, * values, * defaultvalues, ** invals; @@ -813,7 +799,8 @@ int FctCurves(char* data, int found, FILE* f) // //Warning // if(no_values < NumberOfElementsPerLayer) // DisplayMsgLn( -// "Warning! Fewer element values in File for heterogeneous permeability field than elements in element list"); +// "Warning! Fewer element values in File for heterogeneous permeability field than elements in element +// list"); // //------------------------------------------------------------------------ // /* field (int) for helping sort */ // help = (int*) Malloc(NumberOfElements * sizeof(int)); @@ -882,8 +869,12 @@ int FctCurves(char* data, int found, FILE* f) // for(j = 0; j < nof; j++) // values[j] = invals[ihet][j + 3]; // //DisplayMsg(" Het Val for element: "); DisplayLong(i); DisplayMsg(" with coordinates "); -// //DisplayDouble(x,0,0); DisplayMsg(", "); DisplayDouble(y,0,0); DisplayMsg(", "); DisplayDouble(z,0,0); DisplayMsg(" found at: "); -// //DisplayDouble(invals[ihet][0],0,0); DisplayMsg(", "); DisplayDouble(invals[ihet][1],0,0); DisplayMsg(", "); DisplayDouble(invals[ihet][2],0,0); DisplayMsgLn(". "); +// //DisplayDouble(x,0,0); DisplayMsg(", "); DisplayDouble(y,0,0); DisplayMsg(", "); DisplayDouble(z,0,0); +// DisplayMsg(" found at: "); +// //DisplayDouble(invals[ihet][0],0,0); DisplayMsg(", "); DisplayDouble(invals[ihet][1],0,0); +// DisplayMsg(", +//"); +// DisplayDouble(invals[ihet][2],0,0); DisplayMsgLn(". "); // } // //..................................................................... // //Get all values in Element and calculate the geometric mean @@ -984,58 +975,58 @@ double GetAverageHetVal(long EleIndex, CFEMesh* m_msh, long no_values, double** { long i, j, ihet; double average; - double xp[3],yp[3]; + double xp[3], yp[3]; double value; double NumberOfValues; // double InvNumberOfValues; CGLPoint* m_point = NULL; MeshLib::CElem* m_ele = NULL; - j = 0; //only for 1 value + j = 0; // only for 1 value //----------------------------------------------------------------------- - //Get element data + // Get element data m_ele = m_msh->ele_vector[EleIndex]; - for(j = 0; j < 3; j++) + for (j = 0; j < 3; j++) { double const* const pnt(m_ele->GetNode(j)->getData()); xp[j] = pnt[0]; yp[j] = pnt[1]; - //zp[j] = 0.0; + // zp[j] = 0.0; } //----------------------------------------------------------------------- - //Find data points in the element + // Find data points in the element NumberOfValues = 0; - //WW InvNumberOfValues = 0; + // WW InvNumberOfValues = 0; m_point = new CGLPoint; average = -1; value = 0; - for(i = 0; i < no_values; i++) - if(invals[i][4] != -999999.0) //Data point not within an element yet + for (i = 0; i < no_values; i++) + if (invals[i][4] != -999999.0) // Data point not within an element yet { m_point->x = invals[i][0]; m_point->y = invals[i][1]; m_point->z = 0.0; //.................................................................... - //Calculate the product of values in element - //CC 10/05 - if(m_point->IsInTriangleXYProjection(xp,yp)) + // Calculate the product of values in element + // CC 10/05 + if (m_point->IsInTriangleXYProjection(xp, yp)) { value = value + invals[i][3]; NumberOfValues++; - invals[i][4] = -999999.0; //used as marker + invals[i][4] = -999999.0; // used as marker } } - //end for + // end for //........................................................................ - if(NumberOfValues == 0) //if no data points in element --> get neares value + if (NumberOfValues == 0) // if no data points in element --> get neares value { ihet = GetNearestHetVal(EleIndex, m_msh, no_values, invals); - if(ihet < 0) + if (ihet < 0) DisplayMsgLn(" Error getting nearest het_value location"); else average = invals[ihet][j + 3]; } //........................................................................ - else //if data points in element --> Calculate arithmetic mean + else // if data points in element --> Calculate arithmetic mean average = value / NumberOfValues; delete m_point; @@ -1052,35 +1043,35 @@ double GetAverageHetVal(long EleIndex, CFEMesh* m_msh, long no_values, double** long GetNearestHetVal(long EleIndex, CFEMesh* m_msh, long no_values, double** invals) { long i, nextele; - double ex, ey, ez, dist, dist1; //WW, dist2; + double ex, ey, ez, dist, dist1; // WW, dist2; double x, y, z; MeshLib::CElem* m_ele = NULL; //---------------------------------------------------------------------- // MB ToDo - //EleIndex = -1; - //m_msh = NULL; + // EleIndex = -1; + // m_msh = NULL; //---------------------------------------------------------------------- x = 0.0; y = 0.0; z = 0.0; - dist = 10000000.0; //Startwert - //WW dist2 = 0.01; // Abstand zwischen eingelesenen Knoten und Geometrieknoten-RF; + dist = 10000000.0; // Startwert + // WW dist2 = 0.01; // Abstand zwischen eingelesenen Knoten und Geometrieknoten-RF; // Achtung, doppelbelegung möglich bei kleinen Gitterabständen nextele = -1; - //Get element data + // Get element data m_ele = m_msh->ele_vector[EleIndex]; double const* center = m_ele->GetGravityCenter(); x = center[0]; y = center[1]; z = center[2]; - //Calculate distances - for(i = 0; i < no_values; i++) + // Calculate distances + for (i = 0; i < no_values; i++) { ex = invals[i][0]; ey = invals[i][1]; ez = invals[i][2]; dist1 = (ex - x) * (ex - x) + (ey - y) * (ey - y) + (ez - z) * (ez - z); - if(dist1 < dist) + if (dist1 < dist) { dist = dist1; nextele = i; @@ -1110,22 +1101,26 @@ int GetLineFromFile(char* zeile, ifstream* ein) string line; int fertig = 0, i, j; - while(fertig < 1) + while (fertig < 1) { - if(ein->getline(zeile,MAX_ZEILE)) //Zeile lesen + if (ein->getline(zeile, MAX_ZEILE)) // Zeile lesen { - line = zeile; //character in string umwandeln - i = (int) line.find_first_not_of(" ",0); //Anfängliche Leerzeichen überlesen, i=Position des ersten Nichtleerzeichens im string - j = (int) line.find(";",i); //Nach Kommentarzeichen ; suchen. j = Position des Kommentarzeichens, j=-1 wenn es keines gibt. - if(j != i) - fertig = 1; //Wenn das erste nicht-leerzeichen ein Kommentarzeichen ist, zeile überlesen. Sonst ist das eine Datenzeile + line = zeile; // character in string umwandeln + i = (int)line.find_first_not_of( + " ", 0); // Anfängliche Leerzeichen überlesen, i=Position des ersten Nichtleerzeichens im string + j = (int)line.find( + ";", + i); // Nach Kommentarzeichen ; suchen. j = Position des Kommentarzeichens, j=-1 wenn es keines gibt. + if (j != i) + fertig = 1; // Wenn das erste nicht-leerzeichen ein Kommentarzeichen ist, zeile überlesen. Sonst ist das + // eine Datenzeile } - else //end of file found + else // end of file found { ok = 0; fertig = 1; } - } //while + } // while return ok; } @@ -1147,13 +1142,13 @@ hetfields* Createhetfields(int n, char* name_file) int i; hetfields* hf; - hf = (hetfields*) Malloc(sizeof(hetfields)); + hf = (hetfields*)Malloc(sizeof(hetfields)); hf->nof = n; hf->filename = name_file; hf->convertfact = (double*)Malloc(n * sizeof(double)); - hf->names = (char**) Malloc(n * sizeof(char*)); - for(i = 0; i < n; i++) - hf->names[i] = (char*) Malloc(256 * sizeof(char)); + hf->names = (char**)Malloc(n * sizeof(char*)); + for (i = 0; i < n; i++) + hf->names[i] = (char*)Malloc(256 * sizeof(char)); return hf; } @@ -1172,9 +1167,9 @@ hetfields* Createhetfields(int n, char* name_file) 01/2004 SB First Version */ /**************************************************************************/ -void set_hetfields_name(hetfields* hf,int i, char* name) +void set_hetfields_name(hetfields* hf, int i, char* name) { - strcpy( hf->names[i], name); + strcpy(hf->names[i], name); } /**************************************************************************/ @@ -1184,7 +1179,7 @@ void set_hetfields_name(hetfields* hf,int i, char* name) 01/2004 SB First Version */ /**************************************************************************/ -char* get_hetfields_name(hetfields* hf,int i) +char* get_hetfields_name(hetfields* hf, int i) { return hf->names[i]; } @@ -1216,7 +1211,7 @@ int get_hetfields_number(hetfields* hf) 01/2004 SB First Version */ /**************************************************************************/ -double GetHetValue(int ele_no, char* inname ) +double GetHetValue(int ele_no, char* inname) { int i, n; char* name; @@ -1225,14 +1220,14 @@ double GetHetValue(int ele_no, char* inname ) CFEMesh* m_msh = NULL; n = get_hetfields_number(hf); m_msh = FEMGet("GROUNDWATER_FLOW"); - for(i = 0; i < n; i++) + for (i = 0; i < n; i++) { - name = get_hetfields_name(hf,i); - if(strstr(inname, name) && (strcmp(inname,name) == 0)) + name = get_hetfields_name(hf, i); + if (strstr(inname, name) && (strcmp(inname, name) == 0)) { /* found */ // value = ELEGetHetFieldValue(ele_no,i); - value = m_msh->ele_vector[ele_no]->mat_vector(material_properties_index); + value = m_msh->ele_vector[ele_no]->mat_vector(material_properties_index); return value; } } @@ -1248,7 +1243,7 @@ double GetHetValue(int ele_no, char* inname ) Programming: 08/2008 NB ***********************************************************************/ -double interpol (double x1, double x2, double zx1, double zx2, double xn) +double interpol(double x1, double x2, double zx1, double zx2, double xn) { if (x1 == x2) return zx1; @@ -1267,57 +1262,66 @@ returns a value interpolated between both arguments. Programming: 11-2011 NB/TF ***********************************************************************/ -double GetMatrixValue(double var1, double var2, std::string caption, int *gueltig) +double GetMatrixValue(double var1, double var2, std::string caption, int* gueltig) { - CFunction * matrix; - //WW int anz_variables, anz_data; + CFunction* matrix; + // WW int anz_variables, anz_data; int dim_x, dim_y; int i1 = 0; int i2 = 0; int j1 = 0; int j2 = 0; - //JM avoid crash, if nan occurs - if (!(var2==var2)) var2=0.0; - if (!(var1==var1)) var1=288.15; + // JM avoid crash, if nan occurs + if (!(var2 == var2)) + var2 = 0.0; + if (!(var1 == var1)) + var1 = 288.15; matrix = FCTGet(caption); - dim_x = matrix->matrix_dimension[0]; //NB 4.8.01 - dim_y = matrix->matrix_dimension[1]; //NB - + dim_x = matrix->matrix_dimension[0]; // NB 4.8.01 + dim_y = matrix->matrix_dimension[1]; // NB - if (var1 < *matrix->variable_data_vector[0]) //is var1 smaller then the smallest argument? + if (var1 < *matrix->variable_data_vector[0]) // is var1 smaller then the smallest argument? { *gueltig = 0; i1 = i2 = 0; - } else if (var1 > *matrix->variable_data_vector[dim_x - 1]) //is var1 larger then largest argument? + } + else if (var1 > *matrix->variable_data_vector[dim_x - 1]) // is var1 larger then largest argument? { *gueltig = 0; i1 = i2 = dim_x - 1; - } else { + } + else + { i1 = searchElement(var1, 0, dim_x - 1, matrix->variable_data_vector); i2 = i1 + 1; } - if (var2 < *matrix->variable_data_vector[dim_x]) //is var1 smaller then the smallest argument? + if (var2 < *matrix->variable_data_vector[dim_x]) // is var1 smaller then the smallest argument? { *gueltig = 0; j1 = j2 = dim_x; - } else if (var2 > *matrix->variable_data_vector[dim_y + dim_x - 1]) //is var1 larger then largest argument? + } + else if (var2 > *matrix->variable_data_vector[dim_y + dim_x - 1]) // is var1 larger then largest argument? { *gueltig = 0; j1 = j2 = dim_y + dim_x - 1; - } else { + } + else + { j1 = searchElement(var2, dim_x, dim_y + dim_x - 1, matrix->variable_data_vector); j2 = j1 + 1; } - if (fabs(var1 - *matrix->variable_data_vector[i1]) < std::numeric_limits::epsilon()) // var 1 is in the matrix + if (fabs(var1 - *matrix->variable_data_vector[i1]) + < std::numeric_limits::epsilon()) // var 1 is in the matrix { - if (fabs(var2 - *matrix->variable_data_vector[j1]) < std::numeric_limits::epsilon()) // var 2 is in the matrix + if (fabs(var2 - *matrix->variable_data_vector[j1]) + < std::numeric_limits::epsilon()) // var 2 is in the matrix { - return *matrix->variable_data_vector[dim_x + dim_y + i1 + (j1 - dim_x) * dim_x]; - } else // only v1 is in the matrix + } + else // only v1 is in the matrix { double zx1y1, zx1y2; double y1, y2; @@ -1328,10 +1332,11 @@ double GetMatrixValue(double var1, double var2, std::string caption, int *guelti return interpol(y1, y2, zx1y1, zx1y2, var2); } - } else // v1 is not in the matrix + } + else // v1 is not in the matrix { if (fabs(var2 - *matrix->variable_data_vector[dim_x + j1]) - < std::numeric_limits::epsilon()) // only var 2 is in the matrix + < std::numeric_limits::epsilon()) // only var 2 is in the matrix { double zx1y1, zx2y1; double x1, x2; @@ -1366,7 +1371,6 @@ double GetMatrixValue(double var1, double var2, std::string caption, int *guelti } } - /********************************************************************** Function GetMatrixValue (double var1, double var2, int *gueltig) @@ -1378,7 +1382,7 @@ double GetMatrixValue(double var1, double var2, std::string caption, int *guelti Programming: 08/2008 NB ***********************************************************************/ -//double GetMatrixValue(double var1, double var2, std::string caption, int* gueltig) +// double GetMatrixValue(double var1, double var2, std::string caption, int* gueltig) //{ // CFunction* matrix; // //WW int anz_variables, anz_data; @@ -1484,12 +1488,12 @@ double GetMatrixValue(double var1, double var2, std::string caption, int *guelti * Finds and returns the positive minimum of a vector. * Programming: NB Dec 08 *****************************************************************************/ -double FindMin (vectorVec) +double FindMin(vector Vec) { double x = DBL_MAX; int unsigned i; - for(i = 0; i < Vec.size(); i++) + for (i = 0; i < Vec.size(); i++) if ((Vec[i] >= 0) && (Vec[i] < x)) x = Vec[i]; return x; @@ -1499,12 +1503,12 @@ double FindMin (vectorVec) * Finds and returns the maximum of a vector. * Programming: NB Jan 08 *****************************************************************************/ -double FindMax (vectorVec) +double FindMax(vector Vec) { double x = DBL_MIN; int unsigned i; - for(i = 0; i < Vec.size(); i++) + for (i = 0; i < Vec.size(); i++) if (Vec[i] > x) x = Vec[i]; return x; @@ -1517,10 +1521,10 @@ double FindMax (vectorVec) * * Programming: NB, Dec08 *****************************************************************************/ -void NsPol3 (double p, double q, double r, vector* roots) +void NsPol3(double p, double q, double r, vector* roots) { double eps = 7E-15; - double a,b,h,phi,D,z[3]; + double a, b, h, phi, D, z[3]; double pi = 3.1415926535897; double nz; int i; @@ -1533,15 +1537,15 @@ void NsPol3 (double p, double q, double r, vector* roots) if (b < 0) h = -h; - D = MathLib::fastpow(a,3) + b * b; + D = MathLib::fastpow(a, 3) + b * b; if (D <= (-eps)) { nz = 3; - phi = acos(b / MathLib::fastpow(h,3)) / 3; - z[0] = 2* h* cos(pi / 3 - phi) - p / 3; - z[1] = 2* h* cos(pi / 3 + phi) - p / 3; - z[2] = -2* h* cos(phi) - p / 3; + phi = acos(b / MathLib::fastpow(h, 3)) / 3; + z[0] = 2 * h * cos(pi / 3 - phi) - p / 3; + z[1] = 2 * h * cos(pi / 3 + phi) - p / 3; + z[2] = -2 * h * cos(phi) - p / 3; } else if (D < eps) { @@ -1553,27 +1557,27 @@ void NsPol3 (double p, double q, double r, vector* roots) else { nz = 1; - if(a >= eps) + if (a >= eps) { - b = b / MathLib::fastpow(h,3); + b = b / MathLib::fastpow(h, 3); phi = log(b + sqrt(b * b + 1)) / 3; - z[0] = -2* h* sinh(phi) - p / 3; + z[0] = -2 * h * sinh(phi) - p / 3; } - else if(a > (-eps)) + else if (a > (-eps)) { - z[0] = pow((2 * abs(b)),1. / 3.); + z[0] = pow((2 * abs(b)), 1. / 3.); if (b > 0) z[0] = -z[0]; z[0] = z[0] - p / 3; } else { - b = b / MathLib::fastpow(h,3); + b = b / MathLib::fastpow(h, 3); phi = log(b + sqrt(b * b - 1)) / 3; - z[0] = -2* h* cosh(phi) - p / 3; + z[0] = -2 * h * cosh(phi) - p / 3; } } - for(i = 0; i < nz; i++) + for (i = 0; i < nz; i++) roots->push_back(z[i]); } diff --git a/FEM/tools.h b/FEM/tools.h index 73ef9fc27..795c0a1e9 100644 --- a/FEM/tools.h +++ b/FEM/tools.h @@ -20,17 +20,17 @@ #ifndef tools_INC #define tools_INC -#include "rf_mmp_new.h" //MB +#include "rf_mmp_new.h" //MB #include "rf_pcs.h" #include -typedef struct /* fuer Kurven (Stuetzstellen) */ +typedef struct /* fuer Kurven (Stuetzstellen) */ { double punkt; double wert; } StuetzStellen; -typedef struct /* fuer Kurven (Kurven) */ +typedef struct /* fuer Kurven (Kurven) */ { long anz_stuetzstellen; /* Anzahl der Stuetzstellen */ @@ -38,15 +38,15 @@ typedef struct /* fuer Kurven (Kurven) */ /* Feld mit den eingelesenen Stuetzstellen */ } Kurven; -//NB -//extern double GetMatrixValue (double, double, std::string, int*); -double GetMatrixValue(double var1, double var2, std::string caption, int *gueltig); -extern double GetCurveValue ( int kurve, int methode, double punkt, int* gueltig); -extern double GetCurveValueInverse ( int kurve, int methode, double wert, int* gueltig); +// NB +// extern double GetMatrixValue (double, double, std::string, int*); +double GetMatrixValue(double var1, double var2, std::string caption, int* gueltig); +extern double GetCurveValue(int kurve, int methode, double punkt, int* gueltig); +extern double GetCurveValueInverse(int kurve, int methode, double wert, int* gueltig); extern double GetCurveDerivative(int kurve, int methode, double punkt, int* gueltig); -extern double GetCurveInverseDerivative ( int kurve, int methode, double wert, int* gueltig); -extern Kurven* kurven; /* Feld mit Kurven */ -extern int anz_kurven; /* Anzahl der Kurven */ +extern double GetCurveInverseDerivative(int kurve, int methode, double wert, int* gueltig); +extern Kurven* kurven; /* Feld mit Kurven */ +extern int anz_kurven; /* Anzahl der Kurven */ /******************************************************/ /* C1.11 Miscellaneous */ @@ -55,87 +55,90 @@ extern int anz_kurven; /* Anzahl der Kurven */ /* Deklarationen fuer Schluesselwort #FRACTURE_APERTURE_DISTRIBUTION */ extern double* fracture_aperture_array; /* Feld mit Knoten, die ausgegeben werden sollen */ -extern long fracture_aperture_anz; /* Feldgroesse */ +extern long fracture_aperture_anz; /* Feldgroesse */ /* Baut Element-zu-Knoten-Verzeichnis auf (auch adaptiv) */ -extern void ConstructElemsToNodesList ( void ); +extern void ConstructElemsToNodesList(void); /* belegt Loesungsvektor vor --> NULLE_ERGEBNIS */ -extern void PresetErgebnis ( double* ergebnis, int nidx ); +extern void PresetErgebnis(double* ergebnis, int nidx); /* berechnet Anfangszeitschritt --> automat. Zeitschrittsteuerung (aTM) */ -extern double StartTimeStep ( int dtidx ); +extern double StartTimeStep(int dtidx); /* Ermittelt den zulaessigen Courant-Zeitschritt pro Element */ -extern double CalcCourantTimeStep ( long index, long ndx, double dc); +extern double CalcCourantTimeStep(long index, long ndx, double dc); /* Ermittelt den zulaessigen Courant-Zeitschritt im System */ -extern double CalcSystemCourantTimeStep ( long ndx, double dc); +extern double CalcSystemCourantTimeStep(long ndx, double dc); /* Sucht den zulaessigen Courant/Neumann-Zeitschritt im System */ -extern double GetSystemCourantNeumannTimeStep ( long ndx, int dtidx, double acknowledge ); +extern double GetSystemCourantNeumannTimeStep(long ndx, int dtidx, double acknowledge); /* Testet, ob sich Knotenwerte im Element geaendert haben */ -extern int TestElementDirtyness ( long index, long ndx1, long ndx2, double acknowledge); +extern int TestElementDirtyness(long index, long ndx1, long ndx2, double acknowledge); /* Ermittelt das Vorzeichen */ extern int Signum(double); /* Bildet den arithmetischen Mittel einer Elementgroesse durch Interpolation der zugehoerigen Knotenwerte */ -double InterpolateElementNodesValues ( long index, long idx ); -extern int FctCurves ( char* data, int found, FILE* f ); -//SB -//extern int FctReadHeterogeneousPermeabilityField(char* name_file); -//SB -long GetNearestElement(double x,double y,double z, int* help); -//SB +double InterpolateElementNodesValues(long index, long idx); +extern int FctCurves(char* data, int found, FILE* f); +// SB +// extern int FctReadHeterogeneousPermeabilityField(char* name_file); +// SB +long GetNearestElement(double x, double y, double z, int* help); +// SB long GetNearestHetVal(long EleIndex, CFEMesh*, long no_values, double** invals); -//MB +// MB double GetAverageHetVal(long EleIndex, CFEMesh*, long no_values, double** invals); -extern double GetHetValue(int,char*); //SB +extern double GetHetValue(int, char*); // SB typedef struct { - int nof; //number of field values - char* filename; // Name of input file for heterogeneous values - char** names; //Names of field variables - double* convertfact; //conversion factors -}hetfields; //SB - -extern hetfields* hf; //SB - //SB + int nof; // number of field values + char* filename; // Name of input file for heterogeneous values + char** names; // Names of field variables + double* convertfact; // conversion factors +} hetfields; // SB + +extern hetfields* hf; // SB +// SB extern hetfields* Createhetfields(int n, char* name_file); -//SB -extern void set_hetfields_name(hetfields* hf,int i, char* name); -//SB -extern char* get_hetfields_name(hetfields* hf,int i); -extern int get_hetfields_number(hetfields* hf); //SB - //MB +// SB +extern void set_hetfields_name(hetfields* hf, int i, char* name); +// SB +extern char* get_hetfields_name(hetfields* hf, int i); +extern int get_hetfields_number(hetfields* hf); // SB +// MB extern int FctReadHeterogeneousFields(char* name_file, CMediumProperties*); extern long DampOscillations(int ndx1, int oscil_damp_method, double* oscil_damp_parameter, - double (* NodeCalcLumpedMass)(long)); + double (*NodeCalcLumpedMass)(long)); extern int GetLineFromFile(char*, std::ifstream*); -extern double FindMin (std::vectorVec); //NB 4.9.05 -extern double FindMax (std::vectorVec); //NB 4.9.05 +extern double FindMin(std::vector Vec); // NB 4.9.05 +extern double FindMax(std::vector Vec); // NB 4.9.05 /** * Author: NB 4.9.05 * Finds all real roots of a third grade polynomial in the form: * P(x) = x^3 + px^2 + qx + r - * employing the Cardano method + * employing the Cardano + * method * @param p coefficient of cubic equation * @param q coefficient of cubic equation * @param r coefficient of cubic equation * @param t vector contains the roots */ -extern void NsPol3 (double p, double q, double r, std::vector* t); +extern void NsPol3(double p, double q, double r, std::vector* t); /// Release the memory of arrary allocated by using 'new'. WW. 31.08.2010 -template void DeleteArray(num* an_array) +template +void DeleteArray(num* an_array) { - if(an_array) - delete [] an_array; + if (an_array) + delete[] an_array; an_array = NULL; } diff --git a/FEM/vtk.cpp b/FEM/vtk.cpp index 2d95ccdc7..03b0663f8 100644 --- a/FEM/vtk.cpp +++ b/FEM/vtk.cpp @@ -20,7 +20,7 @@ #include #endif #include "Output.h" -#include "fem_ele_std.h" // for element velocity +#include "fem_ele_std.h" // for element velocity #include "makros.h" #include "rf_mmp_new.h" #include "FileTools.h" @@ -29,34 +29,23 @@ using namespace std; const std::string INDEX_STR = " "; -const std::string velocity_name[3][4] = -{ - { - "VELOCITY_X1", "VELOCITY_Y1", "VELOCITY_Z1", "NODAL_VELOCITY1" - } - , - { - "VELOCITY_X2", "VELOCITY_Y2", "VELOCITY_Z2", "NODAL_VELOCITY2" - } - , - { - "VELOCITY1_X", "VELOCITY1_Y", "VELOCITY1_Z", "GL_NODAL_VELOCITY1" - } -}; +const std::string velocity_name[3][4] = {{"VELOCITY_X1", "VELOCITY_Y1", "VELOCITY_Z1", "NODAL_VELOCITY1"}, + {"VELOCITY_X2", "VELOCITY_Y2", "VELOCITY_Z2", "NODAL_VELOCITY2"}, + {"VELOCITY1_X", "VELOCITY1_Y", "VELOCITY1_Z", "GL_NODAL_VELOCITY1"}}; //################################################################################################# // Functions for Paraview Data File (PVD) -bool CVTK::InitializePVD(const string &file_base_name, const string &pcs_type_name, bool binary) +bool CVTK::InitializePVD(const string& file_base_name, const string& pcs_type_name, bool binary) { - //PVD + // PVD vec_dataset.clear(); pvd_file_name = pathJoin(defaultOutputPath, pathBasename(file_base_name)); - // pvd_file_name = file_base_name; +// pvd_file_name = file_base_name; #if defined(USE_PETSC) || defined(USE_MPI) //|| defined(other parallel libs)//03.3012. WW - pvd_file_name += mrank_str; + pvd_file_name += mrank_str; #endif - if(pcs_type_name.size() > 0) // PCS + if (pcs_type_name.size() > 0) // PCS pvd_file_name += "_" + pcs_type_name; pvd_file_name += ".pvd"; @@ -67,57 +56,62 @@ bool CVTK::InitializePVD(const string &file_base_name, const string &pcs_type_na //OK411 if (ibs != (int)string::npos || is != (int)string::npos) { - int ibegin = ibs; - if (is > ibs) - ibegin = is; - ibegin += 1; - this->pvd_vtk_file_name_base = file_base_name.substr(ibegin); - this->pvd_vtk_file_path_base = file_base_name.substr(0, ibegin); + int ibegin = ibs; + if (is > ibs) + ibegin = is; + ibegin += 1; + this->pvd_vtk_file_name_base = file_base_name.substr(ibegin); + this->pvd_vtk_file_path_base = file_base_name.substr(0, ibegin); } else - { - this->pvd_vtk_file_name_base = file_base_name; - this->pvd_vtk_file_path_base = ""; + { + this->pvd_vtk_file_name_base = file_base_name; + this->pvd_vtk_file_path_base = ""; } if (pcs_type_name.size() > 0) // PCS - this->pvd_vtk_file_name_base += "_" + pcs_type_name; + this->pvd_vtk_file_name_base += "_" + pcs_type_name; */ // pvd_vtk_file_path_base = defaultOutputPath; - pvd_vtk_file_name_base = pathBasename(file_base_name) + "_" + pcs_type_name; //WW + pvd_vtk_file_name_base = pathBasename(file_base_name) + "_" + pcs_type_name; // WW useBinary = binary; return true; } -bool CVTK::WriteHeaderOfPVD(std::fstream &fin) +bool CVTK::WriteHeaderOfPVD(std::fstream& fin) { - fin << "" << "\n"; - fin << - "" + fin << "" + << "\n"; + fin << "" + << "\n"; + fin << INDEX_STR << "" << "\n"; - fin << INDEX_STR << "" << "\n"; return true; } -bool CVTK::WriteEndOfPVD(std::fstream &fin) +bool CVTK::WriteEndOfPVD(std::fstream& fin) { - fin << INDEX_STR << "" << "\n"; - fin << "" << "\n"; + fin << INDEX_STR << "" + << "\n"; + fin << "" + << "\n"; return true; } -bool CVTK::WriteDatasetOfPVD(std::fstream &fin, double timestep, const std::string &vtkfile) +bool CVTK::WriteDatasetOfPVD(std::fstream& fin, double timestep, const std::string& vtkfile) { - fin.setf(ios::scientific,std::ios::floatfield); + fin.setf(ios::scientific, std::ios::floatfield); fin.precision(12); - fin << INDEX_STR << INDEX_STR << "" << "\n"; + fin << INDEX_STR << INDEX_STR << "" + << "\n"; return true; } -bool CVTK::UpdatePVD(const string &pvdfile, const vector &vec_vtk) +bool CVTK::UpdatePVD(const string& pvdfile, const vector& vec_vtk) { fstream fin(pvdfile.data(), ios::out); if (!fin.good()) @@ -133,7 +127,7 @@ bool CVTK::UpdatePVD(const string &pvdfile, const vector &vec_vtk) return true; } -bool CVTK::CreateDirOfPVD(const string &pvdfile) +bool CVTK::CreateDirOfPVD(const string& pvdfile) { string pvd_dir_path = pvdfile + ".d"; #if defined(WIN32) @@ -143,7 +137,7 @@ bool CVTK::CreateDirOfPVD(const string &pvdfile) if (mkdir(pvd_dir_path.c_str(), 0777) == -1) { #endif - //error + // error cout << "***ERROR: Fail to create a PVD directory: " << pvd_dir_path << "\n"; return false; } @@ -157,42 +151,42 @@ unsigned char CVTK::GetVTKCellType(const MshElemType::type ele_type) { unsigned char cell_type = 0; - switch(ele_type) + switch (ele_type) { - case MshElemType::LINE: // vtk_line=3 - cell_type = 3; - break; - case MshElemType::QUAD: // quadrilateral=9 - cell_type = 9; - break; - case MshElemType::HEXAHEDRON: // hexahedron=12 - cell_type = 12; - break; - case MshElemType::TRIANGLE: // triangle=5 - cell_type = 5; - break; - case MshElemType::TETRAHEDRON: // tetrahedron=10 - cell_type = 10; - break; - case MshElemType::PRISM: // wedge=13 - cell_type = 13; - break; - case MshElemType::PYRAMID: // pyramid=14 - cell_type = 14; - break; - default: - std::cerr << "***ERROR: NO CORRESPONDING VTK CELL TYPE FOUND. (ELEMENT TYPE=" << - ele_type << ")" << "\n"; + case MshElemType::LINE: // vtk_line=3 + cell_type = 3; + break; + case MshElemType::QUAD: // quadrilateral=9 + cell_type = 9; + break; + case MshElemType::HEXAHEDRON: // hexahedron=12 + cell_type = 12; + break; + case MshElemType::TRIANGLE: // triangle=5 + cell_type = 5; + break; + case MshElemType::TETRAHEDRON: // tetrahedron=10 + cell_type = 10; + break; + case MshElemType::PRISM: // wedge=13 + cell_type = 13; + break; + case MshElemType::PYRAMID: // pyramid=14 + cell_type = 14; + break; + default: + std::cerr << "***ERROR: NO CORRESPONDING VTK CELL TYPE FOUND. (ELEMENT TYPE=" << ele_type << ")" + << "\n"; } return cell_type; } void CVTK::InitializeVTU() { - //if (this->useBinary) { + // if (this->useBinary) { //====================================================================== //# Set machine dependent stuff - //Data type + // Data type if (sizeof(unsigned char) == 1) type_UChar = CVTK::UInt8; else if (sizeof(unsigned char) == 2) @@ -215,43 +209,53 @@ void CVTK::InitializeVTU() type_Double = CVTK::Float64; // SIZE_OF_BLOCK_LENGTH_TAG = sizeof(unsigned int); - //Endian(byte order) + // Endian(byte order) isLittleEndian = IsLittleEndian(); //} this->isInitialized = true; } -bool CVTK::WriteDataArrayHeader(std::fstream &fin, +bool CVTK::WriteDataArrayHeader(std::fstream& fin, VTK_XML_DATA_TYPE data_type, - const std::string &str_name, + const std::string& str_name, int nr_components, - const std::string &str_format, + const std::string& str_format, long offset) { std::string str_data_type; switch (data_type) { - case CVTK::Int8: str_data_type = "Int8"; - break; - case CVTK::UInt8: str_data_type = "UInt8"; - break; - case CVTK::Int16: str_data_type = "Int16"; - break; - case CVTK::UInt16: str_data_type = "UInt16"; - break; - case CVTK::Int32: str_data_type = "Int32"; - break; - case CVTK::UInt32: str_data_type = "UInt32"; - break; - case CVTK::Int64: str_data_type = "Int64"; - break; - case CVTK::UInt64: str_data_type = "UInt64"; - break; - case CVTK::Float32: str_data_type = "Float32"; - break; - case CVTK::Float64: str_data_type = "Float64"; - break; + case CVTK::Int8: + str_data_type = "Int8"; + break; + case CVTK::UInt8: + str_data_type = "UInt8"; + break; + case CVTK::Int16: + str_data_type = "Int16"; + break; + case CVTK::UInt16: + str_data_type = "UInt16"; + break; + case CVTK::Int32: + str_data_type = "Int32"; + break; + case CVTK::UInt32: + str_data_type = "UInt32"; + break; + case CVTK::Int64: + str_data_type = "Int64"; + break; + case CVTK::UInt64: + str_data_type = "UInt64"; + break; + case CVTK::Float32: + str_data_type = "Float32"; + break; + case CVTK::Float64: + str_data_type = "Float64"; + break; } fin << " " << "\n"; + fin << ">" + << "\n"; return true; } -bool CVTK::WriteDataArrayFooter(std::fstream &fin) +bool CVTK::WriteDataArrayFooter(std::fstream& fin) { if (!this->useBinary) - fin << " " << "\n"; + fin << " " + << "\n"; return true; } -bool CVTK::WriteXMLUnstructuredGrid(const std::string &vtkfile, - COutput* out, - const int time_step_number) +bool CVTK::WriteXMLUnstructuredGrid(const std::string& vtkfile, COutput* out, const int time_step_number) { if (!this->isInitialized) this->InitializeVTU(); @@ -298,7 +302,7 @@ bool CVTK::WriteXMLUnstructuredGrid(const std::string &vtkfile, if (!this->useBinary) { - fin.setf(std::ios::scientific,std::ios::floatfield); + fin.setf(std::ios::scientific, std::ios::floatfield); fin.precision(12); } @@ -317,80 +321,97 @@ bool CVTK::WriteXMLUnstructuredGrid(const std::string &vtkfile, bool data_out = !useBinary; //# Header - fin << "" << "\n"; - fin << "" << - "\n"; + fin << "" + << "\n"; + fin << "" + << "\n"; fin << "useBinary || isLittleEndian) fin << " byte_order=\"LittleEndian\""; else fin << " byte_order=\"BigEndian\""; - fin << ">" << "\n"; - // fin << "" << "\n"; + fin << ">" + << "\n"; + // fin << "" << "\n"; //# Unstructured Grid information - fin << " " << "\n"; - fin << " GetNodesNumber(false) << - "\" NumberOfCells=\"" << msh->ele_vector.size() << "\">" << "\n"; + fin << " " + << "\n"; + fin << " GetNodesNumber(false) << "\" NumberOfCells=\"" + << msh->ele_vector.size() << "\">" + << "\n"; //.................................................................... // Nodes - //OK411 CNode *nod = NULL; - fin << " " << "\n"; + // OK411 CNode *nod = NULL; + fin << " " + << "\n"; WriteDataArrayHeader(fin, type_Double, "", 3, str_format, offset); WriteMeshNodes(fin, data_out, msh, offset); WriteDataArrayFooter(fin); - fin << " " << "\n"; + fin << " " + << "\n"; //.................................................................... // Elements - //OK411 CElem * ele = NULL; - fin << " " << "\n"; - //connectivity + // OK411 CElem * ele = NULL; + fin << " " + << "\n"; + // connectivity WriteDataArrayHeader(fin, type_Long, "connectivity", 0, str_format, offset); long sum_ele_components = 0; WriteMeshElementConnectivity(fin, data_out, msh, offset, sum_ele_components); WriteDataArrayFooter(fin); - //offset + // offset WriteDataArrayHeader(fin, type_Long, "offsets", 0, str_format, offset); WriteMeshElementOffset(fin, data_out, msh, offset); WriteDataArrayFooter(fin); - //type + // type WriteDataArrayHeader(fin, type_UChar, "types", 0, str_format, offset); WriteMeshElementType(fin, data_out, msh, offset); WriteDataArrayFooter(fin); - fin << " " << "\n"; + fin << " " + << "\n"; //.................................................................... // Nodal values if (out->_nod_value_vector.size() > 0) - fin << " _nod_value_vector[0] << "\">" << "\n"; + fin << " _nod_value_vector[0] << "\">" + << "\n"; else - fin << " " << "\n"; + fin << " " + << "\n"; WriteNodalValue(fin, data_out, out, msh, offset); - fin << " " << "\n"; + fin << " " + << "\n"; //====================================================================== //.................................................................... // Element values - fin << " " << "\n"; + fin << " " + << "\n"; WriteElementValue(fin, data_out, out, msh, offset); - fin << " " << "\n"; - fin << " " << "\n"; - fin << " " << "\n"; + fin << " " + << "\n"; + fin << " " + << "\n"; + fin << " " + << "\n"; //====================================================================== // Raw data (for binary mode) if (useBinary) { - fin << " " << "\n"; + fin << " " + << "\n"; fin << " _"; - //Node + // Node this->WriteMeshNodes(fin, true, msh, offset); - //Element - //conncectivity + // Element + // conncectivity this->WriteMeshElementConnectivity(fin, true, msh, offset, sum_ele_components); - //offset + // offset this->WriteMeshElementOffset(fin, true, msh, offset); - //type + // type this->WriteMeshElementType(fin, true, msh, offset); // Nodal values this->WriteNodalValue(fin, true, out, msh, offset); @@ -398,10 +419,12 @@ bool CVTK::WriteXMLUnstructuredGrid(const std::string &vtkfile, this->WriteElementValue(fin, true, out, msh, offset); fin << "\n"; - fin << " " << "\n"; + fin << " " + << "\n"; } - fin << "" << "\n"; + fin << "" + << "\n"; fin.close(); return true; @@ -411,17 +434,18 @@ bool CVTK::IsLittleEndian() { int x = 0x00000001; if (*(char*)&x) - return true; //am little + return true; // am little else - return false; //am big + return false; // am big } -template void CVTK::write_value_binary(std::fstream &fin, T val) +template +void CVTK::write_value_binary(std::fstream& fin, T val) { fin.write((const char*)&val, sizeof(T)); } -bool CVTK::WriteMeshNodes(std::fstream &fin, bool output_data, CFEMesh* msh, long &offset) +bool CVTK::WriteMeshNodes(std::fstream& fin, bool output_data, CFEMesh* msh, long& offset) { const size_t n_msh_nodes = msh->GetNodesNumber(false); if (output_data) @@ -429,17 +453,16 @@ bool CVTK::WriteMeshNodes(std::fstream &fin, bool output_data, CFEMesh* msh, lon if (!useBinary) for (size_t i = 0; i < n_msh_nodes; i++) { - double const* const pnt (msh->nod_vector[i]->getData()); - fin << " " << pnt[0] << " " << pnt[1] << " " << pnt[2] << - "\n"; + double const* const pnt(msh->nod_vector[i]->getData()); + fin << " " << pnt[0] << " " << pnt[1] << " " << pnt[2] << "\n"; } else { - //OK411 + // OK411 write_value_binary(fin, sizeof(double) * 3 * n_msh_nodes); for (size_t i = 0; i < n_msh_nodes; i++) { - double const* const pnt (msh->nod_vector[i]->getData()); + double const* const pnt(msh->nod_vector[i]->getData()); write_value_binary(fin, pnt[0]); write_value_binary(fin, pnt[1]); write_value_binary(fin, pnt[2]); @@ -447,17 +470,14 @@ bool CVTK::WriteMeshNodes(std::fstream &fin, bool output_data, CFEMesh* msh, lon } } else if (useBinary) - //OK411 + // OK411 offset += n_msh_nodes * sizeof(double) * 3 + SIZE_OF_BLOCK_LENGTH_TAG; return true; } -bool CVTK::WriteMeshElementConnectivity(std::fstream &fin, - bool output_data, - CFEMesh* msh, - long &offset, - long &sum_ele_components) +bool CVTK::WriteMeshElementConnectivity(std::fstream& fin, bool output_data, CFEMesh* msh, long& offset, + long& sum_ele_components) { if (output_data) { @@ -477,8 +497,7 @@ bool CVTK::WriteMeshElementConnectivity(std::fstream &fin, for (long i = 0; i < (long)msh->ele_vector.size(); i++) { ele = msh->ele_vector[i]; - for (size_t j = 0; j < msh->ele_vector[i]->GetNodesNumber(false); - j++) + for (size_t j = 0; j < msh->ele_vector[i]->GetNodesNumber(false); j++) write_value_binary(fin, ele->GetNodeIndex(j)); } } @@ -494,7 +513,7 @@ bool CVTK::WriteMeshElementConnectivity(std::fstream &fin, return true; } -bool CVTK::WriteMeshElementOffset(std::fstream &fin, bool output_data, CFEMesh* msh, long &offset) +bool CVTK::WriteMeshElementOffset(std::fstream& fin, bool output_data, CFEMesh* msh, long& offset) { if (output_data) { @@ -514,9 +533,8 @@ bool CVTK::WriteMeshElementOffset(std::fstream &fin, bool output_data, CFEMesh* } else { - //OK411 - write_value_binary(fin, - sizeof(long) * (long)msh->ele_vector.size()); + // OK411 + write_value_binary(fin, sizeof(long) * (long)msh->ele_vector.size()); long ele_offset = 0; for (long i = 0; i < (long)msh->ele_vector.size(); i++) { @@ -527,13 +545,13 @@ bool CVTK::WriteMeshElementOffset(std::fstream &fin, bool output_data, CFEMesh* } } else if (useBinary) - //OK411 + // OK411 offset += (long)msh->ele_vector.size() * sizeof(long) + SIZE_OF_BLOCK_LENGTH_TAG; return true; } -bool CVTK::WriteMeshElementType(std::fstream &fin, bool output_data, CFEMesh* msh, long &offset) +bool CVTK::WriteMeshElementType(std::fstream& fin, bool output_data, CFEMesh* msh, long& offset) { if (output_data) { @@ -541,7 +559,7 @@ bool CVTK::WriteMeshElementType(std::fstream &fin, bool output_data, CFEMesh* ms if (!useBinary) { fin << " "; - for(long i = 0; i < (long)msh->ele_vector.size(); i++) + for (long i = 0; i < (long)msh->ele_vector.size(); i++) { ele = msh->ele_vector[i]; fin << (int)this->GetVTKCellType(ele->GetElementType()) << " "; @@ -550,12 +568,9 @@ bool CVTK::WriteMeshElementType(std::fstream &fin, bool output_data, CFEMesh* ms } else { - //OK411 - write_value_binary( - fin, - sizeof(unsigned char) * - (long)msh->ele_vector.size()); - for(long i = 0; i < (long)msh->ele_vector.size(); i++) + // OK411 + write_value_binary(fin, sizeof(unsigned char) * (long)msh->ele_vector.size()); + for (long i = 0; i < (long)msh->ele_vector.size(); i++) { ele = msh->ele_vector[i]; write_value_binary(fin, this->GetVTKCellType(ele->GetElementType())); @@ -563,18 +578,13 @@ bool CVTK::WriteMeshElementType(std::fstream &fin, bool output_data, CFEMesh* ms } } else if (useBinary) - //OK411 - offset += (long)msh->ele_vector.size() * sizeof(unsigned char) + - SIZE_OF_BLOCK_LENGTH_TAG; + // OK411 + offset += (long)msh->ele_vector.size() * sizeof(unsigned char) + SIZE_OF_BLOCK_LENGTH_TAG; return true; } -bool CVTK::WriteNodalValue(std::fstream &fin, - bool output_data, - COutput* out, - CFEMesh* msh, - long &offset) +bool CVTK::WriteNodalValue(std::fstream& fin, bool output_data, COutput* out, CFEMesh* msh, long& offset) { CRFProcess* m_pcs = NULL; std::vector NodeIndex(out->_nod_value_vector.size()); @@ -585,41 +595,40 @@ bool CVTK::WriteNodalValue(std::fstream &fin, if (out->m_pcs != NULL) m_pcs = out->m_pcs; - string str_format; + string str_format; if (!this->useBinary) str_format = "ascii"; else str_format = "appended"; - bool isXZplane = (msh->GetCoordinateFlag()==22); - bool is3D = (msh->GetCoordinateFlag() / 10 == 3); + bool isXZplane = (msh->GetCoordinateFlag() == 22); + bool is3D = (msh->GetCoordinateFlag() / 10 == 3); bool outNodeVelocity = false; - bool outNodeDisplacement = false; - bool outNodePrincipleStressDirections = false; + bool outNodeDisplacement = false; + bool outNodePrincipleStressDirections = false; - //Nodal values - for (int i = 0; i < (int) out->_nod_value_vector.size(); i++) + // Nodal values + for (int i = 0; i < (int)out->_nod_value_vector.size(); i++) { - const string &internal_val_name = out->_nod_value_vector[i]; - const string &external_val_name = out->_alias_nod_value_vector[i]; - //is velocity + const string& internal_val_name = out->_nod_value_vector[i]; + const string& external_val_name = out->_alias_nod_value_vector[i]; + // is velocity if (internal_val_name.find("VELOCITY") != string::npos) { outNodeVelocity = true; continue; } - if (internal_val_name.find("DISPLACEMENT") != string::npos) - { - outNodeDisplacement = true; - continue; - } - - if (internal_val_name.find("NORM_STRESS") != string::npos) - { - outNodePrincipleStressDirections = true; - continue; - } + if (internal_val_name.find("DISPLACEMENT") != string::npos) + { + outNodeDisplacement = true; + continue; + } + if (internal_val_name.find("NORM_STRESS") != string::npos) + { + outNodePrincipleStressDirections = true; + continue; + } // if (out->m_pcs == NULL || out->pcs_type_name.compare("NO_PCS")==0) if (out->m_pcs == NULL || out->getProcessType() == FiniteElement::NO_PCS) @@ -627,11 +636,10 @@ bool CVTK::WriteNodalValue(std::fstream &fin, if (!m_pcs) continue; - NodeIndex[i] = m_pcs->GetNodeValueIndex(internal_val_name,true); //JT: Latest + NodeIndex[i] = m_pcs->GetNodeValueIndex(internal_val_name, true); // JT: Latest if (NodeIndex[i] < 0) continue; - if (!useBinary || !output_data) WriteDataArrayHeader(fin, type_Double, external_val_name, 0, str_format, offset); @@ -639,31 +647,38 @@ bool CVTK::WriteNodalValue(std::fstream &fin, { /* JT: Just get the latest index. No need for all this extra looping. for (size_t j = 0; j < m_pcs->GetPrimaryVNumber(); j++) - if (internal_val_name.compare(m_pcs->pcs_primary_function_name[j]) == 0) { - NodeIndex[i]++; //current step - break; - } + if (internal_val_name.compare(m_pcs->pcs_primary_function_name[j]) == 0) { + NodeIndex[i]++; //current step + break; + } */ - if (!useBinary) { + if (!useBinary) + { fin << " "; - } else { - write_value_binary (fin, sizeof(double)* msh->GetNodesNumber(false)); } - for (size_t j = 0; j < msh->GetNodesNumber(false); j++) { - double v = m_pcs->GetNodeValue(msh->nod_vector[j]->GetIndex(), NodeIndex[i]); - if (!useBinary) { - fin << v << " "; - } else { - write_value_binary(fin, v); - } - } - if (!useBinary) { - fin << "\n"; - } + else + { + write_value_binary(fin, sizeof(double) * msh->GetNodesNumber(false)); + } + for (size_t j = 0; j < msh->GetNodesNumber(false); j++) + { + double v = m_pcs->GetNodeValue(msh->nod_vector[j]->GetIndex(), NodeIndex[i]); + if (!useBinary) + { + fin << v << " "; + } + else + { + write_value_binary(fin, v); + } + } + if (!useBinary) + { + fin << "\n"; + } } else - offset += msh->GetNodesNumber(false) * sizeof(double) - + SIZE_OF_BLOCK_LENGTH_TAG; + offset += msh->GetNodesNumber(false) * sizeof(double) + SIZE_OF_BLOCK_LENGTH_TAG; if (!useBinary || !output_data) WriteDataArrayFooter(fin); @@ -673,25 +688,23 @@ bool CVTK::WriteNodalValue(std::fstream &fin, if (outNodeVelocity) { unsigned int velocity_id = 0; - for (int i = 0; i < (int) out->_nod_value_vector.size(); i++) + for (int i = 0; i < (int)out->_nod_value_vector.size(); i++) { - const string &internal_val_name = out->_nod_value_vector[i]; -// const string &external_val_name = out->_alias_nod_value_vector[i]; + const string& internal_val_name = out->_nod_value_vector[i]; + // const string &external_val_name = out->_alias_nod_value_vector[i]; if (internal_val_name.find("VELOCITY_X1") != string::npos) { if (out->m_pcs == NULL) m_pcs = PCSGet(internal_val_name, true); velocity_id = 0; } - else if (internal_val_name.find("VELOCITY_X2") - != string::npos) + else if (internal_val_name.find("VELOCITY_X2") != string::npos) { if (out->m_pcs == NULL) m_pcs = PCSGet(internal_val_name, true); velocity_id = 1; } - else if (internal_val_name.find("VELOCITY1_X") - != string::npos) + else if (internal_val_name.find("VELOCITY1_X") != string::npos) { if (out->m_pcs == NULL) m_pcs = PCSGet(internal_val_name, true); @@ -703,383 +716,396 @@ bool CVTK::WriteNodalValue(std::fstream &fin, continue; if (!useBinary || !output_data) - WriteDataArrayHeader(fin, - this->type_Double, - velocity_name[velocity_id][3], - 3, - str_format, - offset); + WriteDataArrayHeader(fin, this->type_Double, velocity_name[velocity_id][3], 3, str_format, offset); if (output_data) { int ix, iy, iz; - ix = m_pcs->GetNodeValueIndex(velocity_name[velocity_id][0],true); // JT: Fix. Need latest value. - iy = m_pcs->GetNodeValueIndex(velocity_name[velocity_id][1],true); - iz = m_pcs->GetNodeValueIndex(velocity_name[velocity_id][2],true); + ix = m_pcs->GetNodeValueIndex(velocity_name[velocity_id][0], true); // JT: Fix. Need latest value. + iy = m_pcs->GetNodeValueIndex(velocity_name[velocity_id][1], true); + iz = m_pcs->GetNodeValueIndex(velocity_name[velocity_id][2], true); if (!useBinary) { fin << " "; for (size_t j = 0l; j < msh->GetNodesNumber(false); j++) { - fin << m_pcs->GetNodeValue( - msh->nod_vector[j]->GetIndex(), ix) << " "; - if (m_pcs->getProcessType()==FiniteElement::FLUID_MOMENTUM || !isXZplane) { - fin << m_pcs->GetNodeValue( - msh->nod_vector[j]->GetIndex(), iy) << " "; - fin << m_pcs->GetNodeValue( - msh->nod_vector[j]->GetIndex(), iz) << " "; - } else { - fin << m_pcs->GetNodeValue( - msh->nod_vector[j]->GetIndex(), iz) << " "; - fin << m_pcs->GetNodeValue( - msh->nod_vector[j]->GetIndex(), iy) << " "; - } + fin << m_pcs->GetNodeValue(msh->nod_vector[j]->GetIndex(), ix) << " "; + if (m_pcs->getProcessType() == FiniteElement::FLUID_MOMENTUM || !isXZplane) + { + fin << m_pcs->GetNodeValue(msh->nod_vector[j]->GetIndex(), iy) << " "; + fin << m_pcs->GetNodeValue(msh->nod_vector[j]->GetIndex(), iz) << " "; + } + else + { + fin << m_pcs->GetNodeValue(msh->nod_vector[j]->GetIndex(), iz) << " "; + fin << m_pcs->GetNodeValue(msh->nod_vector[j]->GetIndex(), iy) << " "; + } } fin << "\n"; } else { - write_value_binary (fin, sizeof(double) - * msh->GetNodesNumber( - false) * 3); + write_value_binary(fin, sizeof(double) * msh->GetNodesNumber(false) * 3); for (size_t j = 0l; j < msh->GetNodesNumber(false); j++) { - write_value_binary(fin, m_pcs->GetNodeValue( - msh->nod_vector[j]-> - GetIndex(), ix)); - if (!isXZplane) { - write_value_binary(fin, m_pcs->GetNodeValue( - msh->nod_vector[j]-> - GetIndex(), iy)); - write_value_binary(fin, m_pcs->GetNodeValue( - msh->nod_vector[j]-> - GetIndex(), iz)); - } else { - write_value_binary(fin, m_pcs->GetNodeValue( - msh->nod_vector[j]-> - GetIndex(), iz)); - write_value_binary(fin, m_pcs->GetNodeValue( - msh->nod_vector[j]-> - GetIndex(), iy)); - } + write_value_binary(fin, m_pcs->GetNodeValue(msh->nod_vector[j]->GetIndex(), ix)); + if (!isXZplane) + { + write_value_binary(fin, m_pcs->GetNodeValue(msh->nod_vector[j]->GetIndex(), iy)); + write_value_binary(fin, m_pcs->GetNodeValue(msh->nod_vector[j]->GetIndex(), iz)); + } + else + { + write_value_binary(fin, m_pcs->GetNodeValue(msh->nod_vector[j]->GetIndex(), iz)); + write_value_binary(fin, m_pcs->GetNodeValue(msh->nod_vector[j]->GetIndex(), iy)); + } } } } else - offset += msh->GetNodesNumber(false) * 3 * sizeof( double) + - SIZE_OF_BLOCK_LENGTH_TAG; + offset += msh->GetNodesNumber(false) * 3 * sizeof(double) + SIZE_OF_BLOCK_LENGTH_TAG; + + if (!useBinary || !output_data) + WriteDataArrayFooter(fin); + } + } + + // Displacement + if (outNodeDisplacement) + { + // unsigned int disp_id = 0; + for (int i = 0; i < (int)out->_nod_value_vector.size(); i++) + { + const string& internal_val_name = out->_nod_value_vector[i]; + // const string &external_val_name = out->_alias_nod_value_vector[i]; + if (internal_val_name.find("DISPLACEMENT_X1") != string::npos) + { + if (out->m_pcs == NULL) + m_pcs = PCSGet(internal_val_name, true); + // disp_id = 0; + } + else + continue; + if (!m_pcs) + continue; + + if (!useBinary || !output_data) + WriteDataArrayHeader(fin, this->type_Double, "DISPLACEMENT", 3, str_format, offset); + if (output_data) + { + int var_id[3] = {}; + var_id[0] = m_pcs->GetNodeValueIndex("DISPLACEMENT_X1"); + var_id[1] = m_pcs->GetNodeValueIndex("DISPLACEMENT_Y1"); + var_id[2] = -1; + if (is3D) + { + var_id[2] = m_pcs->GetNodeValueIndex("DISPLACEMENT_Z1"); + } + else if (isXZplane) + { + var_id[1] = -1; + var_id[2] = m_pcs->GetNodeValueIndex("DISPLACEMENT_Y1"); + } + // + if (!useBinary) + { + fin << " "; + } + else + { + write_value_binary(fin, sizeof(double) * msh->GetNodesNumber(false) * 3); + } + double u[3] = {}; + for (size_t j = 0l; j < msh->GetNodesNumber(false); j++) + { + for (size_t k = 0; k < 3; k++) + { + if (var_id[k] < 0) + u[k] = .0; + else + u[k] = m_pcs->GetNodeValue(msh->nod_vector[j]->GetIndex(), var_id[k]); + } + if (!useBinary) + { + for (size_t k = 0; k < 3; k++) + fin << u[k] << " "; + } + else + { + for (size_t k = 0; k < 3; k++) + write_value_binary(fin, u[k]); + } + } + if (!useBinary) + { + fin << "\n"; + } + else + { + write_value_binary(fin, sizeof(double) * msh->GetNodesNumber(false) * 3); + } + } + else + offset += msh->GetNodesNumber(false) * 3 * sizeof(double) + SIZE_OF_BLOCK_LENGTH_TAG; if (!useBinary || !output_data) WriteDataArrayFooter(fin); } } - //Displacement - if (outNodeDisplacement) - { -// unsigned int disp_id = 0; - for (int i = 0; i < (int)out->_nod_value_vector.size(); i++) - { - const string &internal_val_name = out->_nod_value_vector[i]; -// const string &external_val_name = out->_alias_nod_value_vector[i]; - if (internal_val_name.find("DISPLACEMENT_X1") != string::npos) - { - if (out->m_pcs == NULL) - m_pcs = PCSGet(internal_val_name,true); -// disp_id = 0; - } - else - continue; - if(!m_pcs) - continue; - - if (!useBinary || !output_data) - WriteDataArrayHeader(fin, this->type_Double, "DISPLACEMENT", 3, str_format, offset); - if (output_data) - { - int var_id[3] = {}; - var_id[0] = m_pcs->GetNodeValueIndex("DISPLACEMENT_X1"); - var_id[1] = m_pcs->GetNodeValueIndex("DISPLACEMENT_Y1"); - var_id[2] = -1; - if (is3D) { - var_id[2] = m_pcs->GetNodeValueIndex("DISPLACEMENT_Z1"); - } else if (isXZplane) { - var_id[1] = -1; - var_id[2] = m_pcs->GetNodeValueIndex("DISPLACEMENT_Y1"); - } - // - if (!useBinary) { - fin << " "; - } else { - write_value_binary(fin, sizeof(double)*msh->GetNodesNumber(false)*3); - } - double u[3] = {}; - for(size_t j = 0l; j < msh->GetNodesNumber(false); j++) - { - for (size_t k=0; k<3; k++) { - if (var_id[k]<0) - u[k] = .0; - else - u[k] = m_pcs->GetNodeValue(msh->nod_vector[j]->GetIndex(), var_id[k]); - } - - if (!useBinary) { - for (size_t k=0; k<3; k++) - fin << u[k] << " "; - } else { - for (size_t k=0; k<3; k++) - write_value_binary(fin, u[k]); - } - } - if (!useBinary) { - fin << "\n"; - } else { - write_value_binary(fin, sizeof(double)*msh->GetNodesNumber(false)*3); - } - } - else - offset += msh->GetNodesNumber(false) * 3 * sizeof(double) + - SIZE_OF_BLOCK_LENGTH_TAG; - if (!useBinary || !output_data) - WriteDataArrayFooter(fin); - } - } - - - if (outNodePrincipleStressDirections) - { - for (size_t i = 0; i < out->_nod_value_vector.size(); i++) - { - const string &internal_val_name = out->_nod_value_vector[i]; - // const string &external_val_name = out->_alias_nod_value_vector[i]; - if (internal_val_name.find("NORM_STRESS_1_X") != string::npos) - { - if (out->m_pcs == NULL) - m_pcs = PCSGet(internal_val_name,true); - // disp_id = 0; - } - else - continue; - if(!m_pcs) - continue; - - if (!useBinary || !output_data) - WriteDataArrayHeader(fin, this->type_Double, "NORMSTRESS_1", 3, str_format, offset); - if (output_data) - { - int var_id[3] = {}; - var_id[0] = m_pcs->GetNodeValueIndex("NORM_STRESS_1_X"); - var_id[1] = m_pcs->GetNodeValueIndex("NORM_STRESS_1_Y"); - var_id[2] = m_pcs->GetNodeValueIndex("NORM_STRESS_1_Z"); - // - if (!useBinary) { - fin << " "; - } else { - write_value_binary(fin, sizeof(double)*msh->GetNodesNumber(false)*3); - } - double u[3] = {}; - for(size_t j = 0l; j < msh->GetNodesNumber(false); j++) - { - for (size_t k=0; k<3; k++) { - if (var_id[k]<0) - u[k] = .0; - else - u[k] = m_pcs->GetNodeValue(msh->nod_vector[j]->GetIndex(), var_id[k]); - } - - if (!useBinary) { - for (size_t k=0; k<3; k++) - fin << u[k] << " "; - } else { - for (size_t k=0; k<3; k++) - write_value_binary(fin, u[k]); - } - } - if (!useBinary) { - fin << "\n"; - } else { - write_value_binary(fin, sizeof(double)*msh->GetNodesNumber(false)*3); - } - } - else - offset += msh->GetNodesNumber(false) * 3 * sizeof(double) + - SIZE_OF_BLOCK_LENGTH_TAG; - if (!useBinary || !output_data) - WriteDataArrayFooter(fin); - } - for (size_t i = 0; i < out->_nod_value_vector.size(); i++) - { - const string &internal_val_name = out->_nod_value_vector[i]; - // const string &external_val_name = out->_alias_nod_value_vector[i]; - if (internal_val_name.find("NORM_STRESS_2_X") != string::npos) - { - if (out->m_pcs == NULL) - m_pcs = PCSGet(internal_val_name,true); - // disp_id = 0; - } - else - continue; - if(!m_pcs) - continue; - - if (!useBinary || !output_data) - WriteDataArrayHeader(fin, this->type_Double, "NORMSTRESS_2", 3, str_format, offset); - if (output_data) - { - int var_id[3] = {}; - var_id[0] = m_pcs->GetNodeValueIndex("NORM_STRESS_2_X"); - var_id[1] = m_pcs->GetNodeValueIndex("NORM_STRESS_2_Y"); - var_id[2] = m_pcs->GetNodeValueIndex("NORM_STRESS_2_Z"); - // - if (!useBinary) { - fin << " "; - } else { - write_value_binary(fin, sizeof(double)*msh->GetNodesNumber(false)*3); - } - double u[3] = {}; - for(size_t j = 0l; j < msh->GetNodesNumber(false); j++) - { - for (size_t k=0; k<3; k++) { - if (var_id[k]<0) - u[k] = .0; - else - u[k] = m_pcs->GetNodeValue(msh->nod_vector[j]->GetIndex(), var_id[k]); - } - - if (!useBinary) { - for (size_t k=0; k<3; k++) - fin << u[k] << " "; - } else { - for (size_t k=0; k<3; k++) - write_value_binary(fin, u[k]); - } - } - if (!useBinary) { - fin << "\n"; - } else { - write_value_binary(fin, sizeof(double)*msh->GetNodesNumber(false)*3); - } - } - else - offset += msh->GetNodesNumber(false) * 3 * sizeof(double) + - SIZE_OF_BLOCK_LENGTH_TAG; - if (!useBinary || !output_data) - WriteDataArrayFooter(fin); - } - for (size_t i = 0; i < out->_nod_value_vector.size(); i++) - { - const string &internal_val_name = out->_nod_value_vector[i]; - // const string &external_val_name = out->_alias_nod_value_vector[i]; - if (internal_val_name.find("NORM_STRESS_3_X") != string::npos) - { - if (out->m_pcs == NULL) - m_pcs = PCSGet(internal_val_name,true); - // disp_id = 0; - } - else - continue; - if(!m_pcs) - continue; - - if (!useBinary || !output_data) - WriteDataArrayHeader(fin, this->type_Double, "NORMSTRESS_3", 3, str_format, offset); - if (output_data) - { - int var_id[3] = {}; - var_id[0] = m_pcs->GetNodeValueIndex("NORM_STRESS_3_X"); - var_id[1] = m_pcs->GetNodeValueIndex("NORM_STRESS_3_Y"); - var_id[2] = m_pcs->GetNodeValueIndex("NORM_STRESS_3_Z"); - // - if (!useBinary) { - fin << " "; - } else { - write_value_binary(fin, sizeof(double)*msh->GetNodesNumber(false)*3); - } - double u[3] = {}; - for(size_t j = 0l; j < msh->GetNodesNumber(false); j++) - { - for (size_t k=0; k<3; k++) { - if (var_id[k]<0) - u[k] = .0; - else - u[k] = m_pcs->GetNodeValue(msh->nod_vector[j]->GetIndex(), var_id[k]); - } - - if (!useBinary) { - for (size_t k=0; k<3; k++) - fin << u[k] << " "; - } else { - for (size_t k=0; k<3; k++) - write_value_binary(fin, u[k]); - } - } - if (!useBinary) { - fin << "\n"; - } else { - write_value_binary(fin, sizeof(double)*msh->GetNodesNumber(false)*3); - } - } - else - offset += msh->GetNodesNumber(false) * 3 * sizeof(double) + - SIZE_OF_BLOCK_LENGTH_TAG; - if (!useBinary || !output_data) - WriteDataArrayFooter(fin); - } - - - - - } - //MFP - for ( size_t i=0; imfp_value_vector.size(); i++) { - - const std::string &mfp_name = out->mfp_value_vector[i]; - if (!useBinary || !output_data) - { - WriteDataArrayHeader(fin, type_Double, mfp_name, 0, str_format, offset); - } - - if (output_data) - { - if (!useBinary) - { - fin << " "; - for (size_t j = 0; j < msh->GetNodesNumber(false); j++) - { - const double v = MFPGetNodeValue(msh->nod_vector[j]->GetIndex(), mfp_name, atoi(&mfp_name[mfp_name.size() - 1]) - 1); - fin << v << " "; - } - fin << endl; - } - else - { - write_value_binary (fin, sizeof(double) - * msh->GetNodesNumber(false)); - for (size_t j = 0; j < msh->GetNodesNumber(false); j++) - { - const double v = MFPGetNodeValue(msh->nod_vector[j]->GetIndex(), mfp_name, atoi(&mfp_name[mfp_name.size() - 1]) - 1); - write_value_binary(fin, v); - } - } - } - else - { - offset += msh->GetNodesNumber(false) * sizeof(double) - + SIZE_OF_BLOCK_LENGTH_TAG; - } - - if (!useBinary || !output_data) - { - WriteDataArrayFooter(fin); - } - } - return true; + if (outNodePrincipleStressDirections) + { + for (size_t i = 0; i < out->_nod_value_vector.size(); i++) + { + const string& internal_val_name = out->_nod_value_vector[i]; + // const string &external_val_name = out->_alias_nod_value_vector[i]; + if (internal_val_name.find("NORM_STRESS_1_X") != string::npos) + { + if (out->m_pcs == NULL) + m_pcs = PCSGet(internal_val_name, true); + // disp_id = 0; + } + else + continue; + if (!m_pcs) + continue; + + if (!useBinary || !output_data) + WriteDataArrayHeader(fin, this->type_Double, "NORMSTRESS_1", 3, str_format, offset); + if (output_data) + { + int var_id[3] = {}; + var_id[0] = m_pcs->GetNodeValueIndex("NORM_STRESS_1_X"); + var_id[1] = m_pcs->GetNodeValueIndex("NORM_STRESS_1_Y"); + var_id[2] = m_pcs->GetNodeValueIndex("NORM_STRESS_1_Z"); + // + if (!useBinary) + { + fin << " "; + } + else + { + write_value_binary(fin, sizeof(double) * msh->GetNodesNumber(false) * 3); + } + double u[3] = {}; + for (size_t j = 0l; j < msh->GetNodesNumber(false); j++) + { + for (size_t k = 0; k < 3; k++) + { + if (var_id[k] < 0) + u[k] = .0; + else + u[k] = m_pcs->GetNodeValue(msh->nod_vector[j]->GetIndex(), var_id[k]); + } + + if (!useBinary) + { + for (size_t k = 0; k < 3; k++) + fin << u[k] << " "; + } + else + { + for (size_t k = 0; k < 3; k++) + write_value_binary(fin, u[k]); + } + } + if (!useBinary) + { + fin << "\n"; + } + else + { + write_value_binary(fin, sizeof(double) * msh->GetNodesNumber(false) * 3); + } + } + else + offset += msh->GetNodesNumber(false) * 3 * sizeof(double) + SIZE_OF_BLOCK_LENGTH_TAG; + if (!useBinary || !output_data) + WriteDataArrayFooter(fin); + } + for (size_t i = 0; i < out->_nod_value_vector.size(); i++) + { + const string& internal_val_name = out->_nod_value_vector[i]; + // const string &external_val_name = out->_alias_nod_value_vector[i]; + if (internal_val_name.find("NORM_STRESS_2_X") != string::npos) + { + if (out->m_pcs == NULL) + m_pcs = PCSGet(internal_val_name, true); + // disp_id = 0; + } + else + continue; + if (!m_pcs) + continue; + + if (!useBinary || !output_data) + WriteDataArrayHeader(fin, this->type_Double, "NORMSTRESS_2", 3, str_format, offset); + if (output_data) + { + int var_id[3] = {}; + var_id[0] = m_pcs->GetNodeValueIndex("NORM_STRESS_2_X"); + var_id[1] = m_pcs->GetNodeValueIndex("NORM_STRESS_2_Y"); + var_id[2] = m_pcs->GetNodeValueIndex("NORM_STRESS_2_Z"); + // + if (!useBinary) + { + fin << " "; + } + else + { + write_value_binary(fin, sizeof(double) * msh->GetNodesNumber(false) * 3); + } + double u[3] = {}; + for (size_t j = 0l; j < msh->GetNodesNumber(false); j++) + { + for (size_t k = 0; k < 3; k++) + { + if (var_id[k] < 0) + u[k] = .0; + else + u[k] = m_pcs->GetNodeValue(msh->nod_vector[j]->GetIndex(), var_id[k]); + } + + if (!useBinary) + { + for (size_t k = 0; k < 3; k++) + fin << u[k] << " "; + } + else + { + for (size_t k = 0; k < 3; k++) + write_value_binary(fin, u[k]); + } + } + if (!useBinary) + { + fin << "\n"; + } + else + { + write_value_binary(fin, sizeof(double) * msh->GetNodesNumber(false) * 3); + } + } + else + offset += msh->GetNodesNumber(false) * 3 * sizeof(double) + SIZE_OF_BLOCK_LENGTH_TAG; + if (!useBinary || !output_data) + WriteDataArrayFooter(fin); + } + for (size_t i = 0; i < out->_nod_value_vector.size(); i++) + { + const string& internal_val_name = out->_nod_value_vector[i]; + // const string &external_val_name = out->_alias_nod_value_vector[i]; + if (internal_val_name.find("NORM_STRESS_3_X") != string::npos) + { + if (out->m_pcs == NULL) + m_pcs = PCSGet(internal_val_name, true); + // disp_id = 0; + } + else + continue; + if (!m_pcs) + continue; + + if (!useBinary || !output_data) + WriteDataArrayHeader(fin, this->type_Double, "NORMSTRESS_3", 3, str_format, offset); + if (output_data) + { + int var_id[3] = {}; + var_id[0] = m_pcs->GetNodeValueIndex("NORM_STRESS_3_X"); + var_id[1] = m_pcs->GetNodeValueIndex("NORM_STRESS_3_Y"); + var_id[2] = m_pcs->GetNodeValueIndex("NORM_STRESS_3_Z"); + // + if (!useBinary) + { + fin << " "; + } + else + { + write_value_binary(fin, sizeof(double) * msh->GetNodesNumber(false) * 3); + } + double u[3] = {}; + for (size_t j = 0l; j < msh->GetNodesNumber(false); j++) + { + for (size_t k = 0; k < 3; k++) + { + if (var_id[k] < 0) + u[k] = .0; + else + u[k] = m_pcs->GetNodeValue(msh->nod_vector[j]->GetIndex(), var_id[k]); + } + + if (!useBinary) + { + for (size_t k = 0; k < 3; k++) + fin << u[k] << " "; + } + else + { + for (size_t k = 0; k < 3; k++) + write_value_binary(fin, u[k]); + } + } + if (!useBinary) + { + fin << "\n"; + } + else + { + write_value_binary(fin, sizeof(double) * msh->GetNodesNumber(false) * 3); + } + } + else + offset += msh->GetNodesNumber(false) * 3 * sizeof(double) + SIZE_OF_BLOCK_LENGTH_TAG; + if (!useBinary || !output_data) + WriteDataArrayFooter(fin); + } + } + // MFP + for (size_t i = 0; i < out->mfp_value_vector.size(); i++) + { + const std::string& mfp_name = out->mfp_value_vector[i]; + if (!useBinary || !output_data) + { + WriteDataArrayHeader(fin, type_Double, mfp_name, 0, str_format, offset); + } + + if (output_data) + { + if (!useBinary) + { + fin << " "; + for (size_t j = 0; j < msh->GetNodesNumber(false); j++) + { + const double v = MFPGetNodeValue(msh->nod_vector[j]->GetIndex(), mfp_name, + atoi(&mfp_name[mfp_name.size() - 1]) - 1); + fin << v << " "; + } + fin << endl; + } + else + { + write_value_binary(fin, sizeof(double) * msh->GetNodesNumber(false)); + for (size_t j = 0; j < msh->GetNodesNumber(false); j++) + { + const double v = MFPGetNodeValue(msh->nod_vector[j]->GetIndex(), mfp_name, + atoi(&mfp_name[mfp_name.size() - 1]) - 1); + write_value_binary(fin, v); + } + } + } + else + { + offset += msh->GetNodesNumber(false) * sizeof(double) + SIZE_OF_BLOCK_LENGTH_TAG; + } + + if (!useBinary || !output_data) + { + WriteDataArrayFooter(fin); + } + } + return true; } -bool CVTK::WriteElementValue(std::fstream &fin, - bool output_data, - COutput* out, - CFEMesh* msh, - long &offset) +bool CVTK::WriteElementValue(std::fstream& fin, bool output_data, COutput* out, CFEMesh* msh, long& offset) { std::vector ele_value_index_vector(out->getElementValueVector().size()); if (ele_value_index_vector.size() > 0) // GetELEValuesIndexVector() should check this! @@ -1087,7 +1113,7 @@ bool CVTK::WriteElementValue(std::fstream &fin, CRFProcess* m_pcs = NULL; MeshLib::CElem* ele = NULL; - bool isXZplane = (msh->GetCoordinateFlag()==22); + bool isXZplane = (msh->GetCoordinateFlag() == 22); string str_format; if (!this->useBinary) @@ -1097,8 +1123,8 @@ bool CVTK::WriteElementValue(std::fstream &fin, bool outEleVelocity = false; - //Element values - for (int i = 0; i < (int) ele_value_index_vector.size(); i++) + // Element values + for (int i = 0; i < (int)ele_value_index_vector.size(); i++) { if (out->getElementValueVector()[i].find("VELOCITY") != string::npos) { @@ -1108,188 +1134,145 @@ bool CVTK::WriteElementValue(std::fstream &fin, m_pcs = out->GetPCS_ELE(out->getElementValueVector()[i]); if (!useBinary || !output_data) - WriteDataArrayHeader(fin, this->type_Double, - out->getElementValueVector()[i], 0, str_format, offset); + WriteDataArrayHeader(fin, this->type_Double, out->getElementValueVector()[i], 0, str_format, offset); if (output_data) { if (!useBinary) { fin << " "; - for (long j = 0; j < (long) msh->ele_vector.size(); j++) - if (ele_value_index_vector[i]>=0) - fin << m_pcs->GetElementValue(j, ele_value_index_vector[i]) - << " "; + for (long j = 0; j < (long)msh->ele_vector.size(); j++) + if (ele_value_index_vector[i] >= 0) + fin << m_pcs->GetElementValue(j, ele_value_index_vector[i]) << " "; fin << "\n"; } else { - write_value_binary (fin, sizeof(double) - * (long) msh->ele_vector.size()); //OK411 - for (long j = 0; j < (long) msh->ele_vector.size(); j++) - if (ele_value_index_vector[i]>=0) - write_value_binary(fin, - m_pcs->GetElementValue(j,ele_value_index_vector[i])); + write_value_binary(fin, sizeof(double) * (long)msh->ele_vector.size()); // OK411 + for (long j = 0; j < (long)msh->ele_vector.size(); j++) + if (ele_value_index_vector[i] >= 0) + write_value_binary(fin, m_pcs->GetElementValue(j, ele_value_index_vector[i])); } } else - offset += (long) msh->ele_vector.size() * sizeof(double) - + SIZE_OF_BLOCK_LENGTH_TAG; //OK411 + offset += (long)msh->ele_vector.size() * sizeof(double) + SIZE_OF_BLOCK_LENGTH_TAG; // OK411 if (!useBinary || !output_data) WriteDataArrayFooter(fin); } - //Element velocity + // Element velocity if (outEleVelocity) { if (!useBinary || !output_data) - WriteDataArrayHeader(fin, this->type_Double, "ELEMENT_VELOCITY", 3, - str_format, offset); + WriteDataArrayHeader(fin, this->type_Double, "ELEMENT_VELOCITY", 3, str_format, offset); if (output_data) { if (!useBinary) { fin << " "; - static double ele_vel[3] = { 0.0, 0.0, 0.0 }; - for (long i = 0; i < (long) msh->ele_vector.size(); i++) + static double ele_vel[3] = {0.0, 0.0, 0.0}; + for (long i = 0; i < (long)msh->ele_vector.size(); i++) { ele_gp_value[i]->getIPvalue_vec(0, ele_vel); fin << ele_vel[0] << " "; - if (!isXZplane) { - fin << ele_vel[1] << " "; - fin << ele_vel[2] << " "; - } else { - fin << ele_vel[2] << " "; - fin << ele_vel[1] << " "; - } + if (!isXZplane) + { + fin << ele_vel[1] << " "; + fin << ele_vel[2] << " "; + } + else + { + fin << ele_vel[2] << " "; + fin << ele_vel[1] << " "; + } } fin << "\n"; } else { - static double ele_vel[3] = { 0.0, 0.0, 0.0 }; - write_value_binary (fin, sizeof(double) * 3 * - (long )msh->ele_vector.size()); //OK411 - for(long i = 0; i < (long)msh->ele_vector.size(); i++) + static double ele_vel[3] = {0.0, 0.0, 0.0}; + write_value_binary(fin, sizeof(double) * 3 * (long)msh->ele_vector.size()); // OK411 + for (long i = 0; i < (long)msh->ele_vector.size(); i++) { ele_gp_value[i]->getIPvalue_vec(0, ele_vel); - write_value_binary(fin, ele_vel[0]); - if (!isXZplane) { - write_value_binary(fin, ele_vel[1]); - write_value_binary(fin, ele_vel[2]); - } else { - write_value_binary(fin, ele_vel[2]); - write_value_binary(fin, ele_vel[1]); - } + write_value_binary(fin, ele_vel[0]); + if (!isXZplane) + { + write_value_binary(fin, ele_vel[1]); + write_value_binary(fin, ele_vel[2]); + } + else + { + write_value_binary(fin, ele_vel[2]); + write_value_binary(fin, ele_vel[1]); + } } } } else - //OK411 - offset += (long)msh->ele_vector.size() * sizeof(double) * 3 + - SIZE_OF_BLOCK_LENGTH_TAG; + // OK411 + offset += (long)msh->ele_vector.size() * sizeof(double) * 3 + SIZE_OF_BLOCK_LENGTH_TAG; if (!useBinary || !output_data) WriteDataArrayFooter(fin); // if(out->pcs_type_name.compare("FLUID_MOMENTUM")==0) - if(out->getProcessType () == FiniteElement::FLUID_MOMENTUM) + if (out->getProcessType() == FiniteElement::FLUID_MOMENTUM) { if (!useBinary || !output_data) - WriteDataArrayHeader(fin, - this->type_Double, - "GLOBAL_VELOCITY", - 3, - str_format, - offset); + WriteDataArrayHeader(fin, this->type_Double, "GLOBAL_VELOCITY", 3, str_format, offset); if (output_data) { CRFProcess* pch_pcs = PCSGet("FLUID_MOMENTUM"); if (!this->useBinary) { fin << " "; - for(long i = 0; i < (long)msh->ele_vector.size(); i++) + for (long i = 0; i < (long)msh->ele_vector.size(); i++) { - fin << pch_pcs->GetElementValue( - i, - pch_pcs-> - GetElementValueIndex("VELOCITY1_X") + - 1) << " "; - if (!isXZplane) { - fin << pch_pcs->GetElementValue( - i, - pch_pcs-> - GetElementValueIndex("VELOCITY1_Y") + - 1) << " "; - fin << pch_pcs->GetElementValue( - i, - pch_pcs-> - GetElementValueIndex("VELOCITY1_Z") + - 1) << " "; - } else { - fin << pch_pcs->GetElementValue( - i, - pch_pcs-> - GetElementValueIndex("VELOCITY1_Z") + - 1) << " "; - fin << pch_pcs->GetElementValue( - i, - pch_pcs-> - GetElementValueIndex("VELOCITY1_Y") + - 1) << " "; - } + fin << pch_pcs->GetElementValue(i, pch_pcs->GetElementValueIndex("VELOCITY1_X") + 1) << " "; + if (!isXZplane) + { + fin << pch_pcs->GetElementValue(i, pch_pcs->GetElementValueIndex("VELOCITY1_Y") + 1) << " "; + fin << pch_pcs->GetElementValue(i, pch_pcs->GetElementValueIndex("VELOCITY1_Z") + 1) << " "; + } + else + { + fin << pch_pcs->GetElementValue(i, pch_pcs->GetElementValueIndex("VELOCITY1_Z") + 1) << " "; + fin << pch_pcs->GetElementValue(i, pch_pcs->GetElementValueIndex("VELOCITY1_Y") + 1) << " "; + } } fin << "\n"; } else { - //OK411 - write_value_binary(fin, sizeof(double) * 3 * - (long)msh->ele_vector.size()); - for(long i = 0; i < (long)msh->ele_vector.size(); i++) + // OK411 + write_value_binary(fin, sizeof(double) * 3 * (long)msh->ele_vector.size()); + for (long i = 0; i < (long)msh->ele_vector.size(); i++) { - write_value_binary(fin, - pch_pcs->GetElementValue(i, - pch_pcs - -> - GetElementValueIndex( - "VELOCITY1_X") - + 1)); - if (!isXZplane) { - write_value_binary(fin, - pch_pcs->GetElementValue(i, - pch_pcs - -> - GetElementValueIndex( - "VELOCITY1_Y") - + 1)); - write_value_binary(fin, - pch_pcs->GetElementValue(i, - pch_pcs - -> - GetElementValueIndex( - "VELOCITY1_Z") - + 1)); - } else { - write_value_binary(fin, - pch_pcs->GetElementValue(i, - pch_pcs - -> - GetElementValueIndex( - "VELOCITY1_Z") - + 1)); - } + write_value_binary( + fin, pch_pcs->GetElementValue(i, pch_pcs->GetElementValueIndex("VELOCITY1_X") + 1)); + if (!isXZplane) + { + write_value_binary( + fin, pch_pcs->GetElementValue(i, pch_pcs->GetElementValueIndex("VELOCITY1_Y") + 1)); + write_value_binary( + fin, pch_pcs->GetElementValue(i, pch_pcs->GetElementValueIndex("VELOCITY1_Z") + 1)); + } + else + { + write_value_binary( + fin, pch_pcs->GetElementValue(i, pch_pcs->GetElementValueIndex("VELOCITY1_Z") + 1)); + } } } } else - //OK411 - offset += (long)msh->ele_vector.size() * sizeof(double) * 3 + - SIZE_OF_BLOCK_LENGTH_TAG; + // OK411 + offset += (long)msh->ele_vector.size() * sizeof(double) * 3 + SIZE_OF_BLOCK_LENGTH_TAG; if (!useBinary || !output_data) WriteDataArrayFooter(fin); } } - //Material information - if(mmp_vector.size() > 1) + // Material information + if (mmp_vector.size() > 1) { if (!useBinary || !output_data) WriteDataArrayHeader(fin, this->type_Int, "MatGroup", 0, str_format, offset); @@ -1298,7 +1281,7 @@ bool CVTK::WriteElementValue(std::fstream &fin, if (!this->useBinary) { fin << " "; - for(long i = 0; i < (long)msh->ele_vector.size(); i++) + for (long i = 0; i < (long)msh->ele_vector.size(); i++) { ele = msh->ele_vector[i]; fin << ele->GetPatchIndex() << " "; @@ -1307,44 +1290,43 @@ bool CVTK::WriteElementValue(std::fstream &fin, } else { - //OK411 - write_value_binary( - fin, - sizeof(int) * - (long)msh->ele_vector.size()); + // OK411 + write_value_binary(fin, sizeof(int) * (long)msh->ele_vector.size()); for (long i = 0; i < (long)msh->ele_vector.size(); i++) write_value_binary(fin, msh->ele_vector[i]->GetPatchIndex()); } } else - //OK411 - offset += (long)msh->ele_vector.size() * sizeof(int) + - SIZE_OF_BLOCK_LENGTH_TAG; + // OK411 + offset += (long)msh->ele_vector.size() * sizeof(int) + SIZE_OF_BLOCK_LENGTH_TAG; if (!useBinary || !output_data) WriteDataArrayFooter(fin); } - //MMP - if(out->mmp_value_vector.size() > 0) + // MMP + if (out->mmp_value_vector.size() > 0) { - for (size_t i_mmp=0; i_mmpmmp_value_vector.size(); i_mmp++) { - const std::string &mmp_name = out->mmp_value_vector[i_mmp]; + for (size_t i_mmp = 0; i_mmp < out->mmp_value_vector.size(); i_mmp++) + { + const std::string& mmp_name = out->mmp_value_vector[i_mmp]; int mmp_id = ELEMENT_MMP_VALUES::getMMPIndex(mmp_name); - if (mmp_id<0) continue; + if (mmp_id < 0) + continue; if (!useBinary || !output_data) WriteDataArrayHeader(fin, this->type_Double, mmp_name, 0, str_format, offset); if (output_data) { - if (m_pcs==NULL) { + if (m_pcs == NULL) + { m_pcs = PCSGetFlow(); } if (!this->useBinary) { fin << " "; - for(long i_e = 0; i_e < (long)msh->ele_vector.size(); i_e++) + for (long i_e = 0; i_e < (long)msh->ele_vector.size(); i_e++) { ele = msh->ele_vector[i_e]; double mat_value = getElementMMP(mmp_id, ele, m_pcs); @@ -1354,15 +1336,18 @@ bool CVTK::WriteElementValue(std::fstream &fin, } else { - //OK411 + // OK411 write_value_binary(fin, sizeof(int) * (long)msh->ele_vector.size()); - for (long i_e = 0; i_e < (long)msh->ele_vector.size(); i_e++) { + for (long i_e = 0; i_e < (long)msh->ele_vector.size(); i_e++) + { ele = msh->ele_vector[i_e]; double mat_value = getElementMMP(mmp_id, ele, m_pcs); write_value_binary(fin, mat_value); } } - } else { + } + else + { offset += (long)msh->ele_vector.size() * sizeof(double) + SIZE_OF_BLOCK_LENGTH_TAG; } @@ -1371,20 +1356,23 @@ bool CVTK::WriteElementValue(std::fstream &fin, } } - //MFP - if(out->mfp_value_vector.size() > 0) + // MFP + if (out->mfp_value_vector.size() > 0) { - for (size_t i_mfp=0; i_mfpmfp_value_vector.size(); i_mfp++) { - const std::string &mfp_name = out->mfp_value_vector[i_mfp]; + for (size_t i_mfp = 0; i_mfp < out->mfp_value_vector.size(); i_mfp++) + { + const std::string& mfp_name = out->mfp_value_vector[i_mfp]; int mfp_id = ELEMENT_MFP_VALUES::getMFPIndex(mfp_name); - if (mfp_id<0) continue; + if (mfp_id < 0) + continue; if (!useBinary || !output_data) WriteDataArrayHeader(fin, this->type_Double, mfp_name, 0, str_format, offset); if (output_data) { - if (m_pcs==NULL) { + if (m_pcs == NULL) + { m_pcs = PCSGetFlow(); } @@ -1392,7 +1380,7 @@ bool CVTK::WriteElementValue(std::fstream &fin, { fin << " "; int gp_r, gp_s, gp_t; - for(long i_e = 0; i_e < (long)msh->ele_vector.size(); i_e++) + for (long i_e = 0; i_e < (long)msh->ele_vector.size(); i_e++) { ele = msh->ele_vector[i_e]; ele->SetOrder(false); @@ -1410,16 +1398,19 @@ bool CVTK::WriteElementValue(std::fstream &fin, } else { - //OK411 + // OK411 write_value_binary(fin, sizeof(int) * (long)msh->ele_vector.size()); - for (long i_e = 0; i_e < (long)msh->ele_vector.size(); i_e++) { + for (long i_e = 0; i_e < (long)msh->ele_vector.size(); i_e++) + { ele = msh->ele_vector[i_e]; CFluidProperties* mfp = mfp_vector[0]; double mat_value = ELEMENT_MFP_VALUES::getValue(mfp, mfp_id); write_value_binary(fin, mat_value); } } - } else { + } + else + { offset += (long)msh->ele_vector.size() * sizeof(double) + SIZE_OF_BLOCK_LENGTH_TAG; } diff --git a/FEM/vtk.h b/FEM/vtk.h index ce1cf3456..442279d33 100644 --- a/FEM/vtk.h +++ b/FEM/vtk.h @@ -33,14 +33,25 @@ class CVTK std::vector vec_dataset; std::string pvd_file_name; std::string pvd_vtk_file_name_base; - std::string pvd_vtk_file_path_base; + std::string pvd_vtk_file_path_base; double useBinary; - enum VTK_XML_DATA_TYPE { Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64, Float32, - Float64 }; + enum VTK_XML_DATA_TYPE + { + Int8, + UInt8, + Int16, + UInt16, + Int32, + UInt32, + Int64, + UInt64, + Float32, + Float64 + }; protected: - //for binary output + // for binary output bool isInitialized; VTK_XML_DATA_TYPE type_UChar; VTK_XML_DATA_TYPE type_Int; @@ -48,87 +59,62 @@ class CVTK VTK_XML_DATA_TYPE type_Long; VTK_XML_DATA_TYPE type_Double; int SIZE_OF_BLOCK_LENGTH_TAG; - bool isLittleEndian; //Endian(byte order) + bool isLittleEndian; // Endian(byte order) #if defined(USE_PETSC) || defined(USE_MPI) //|| defined(other parallel libs)//03.3012. WW - int mrank; - std::string mrank_str; + int mrank; + std::string mrank_str; #endif public: #if defined(USE_PETSC) || defined(USE_MPI) //|| defined(other parallel libs)//03.3012. WW - CVTK(const int rank, std::string rank_str) - { - isInitialized = false; - mrank = rank; - mrank_str = rank_str; - } + CVTK(const int rank, std::string rank_str) + { + isInitialized = false; + mrank = rank; + mrank_str = rank_str; + } #else - CVTK(void) - { - isInitialized = false; - } + CVTK(void) { isInitialized = false; } #endif - virtual ~CVTK(void){} - + virtual ~CVTK(void) {} protected: - //PVD - bool WriteHeaderOfPVD(std::fstream &fin); - bool WriteEndOfPVD(std::fstream &fin); - bool WriteDatasetOfPVD(std::fstream &fin, double timestep, const std::string &vtkfile); + // PVD + bool WriteHeaderOfPVD(std::fstream& fin); + bool WriteEndOfPVD(std::fstream& fin); + bool WriteDatasetOfPVD(std::fstream& fin, double timestep, const std::string& vtkfile); - //VTU + // VTU void InitializeVTU(); unsigned char GetVTKCellType(const MshElemType::type ele_type); - bool WriteDataArrayHeader(std::fstream &fin, + bool WriteDataArrayHeader(std::fstream& fin, VTK_XML_DATA_TYPE data_type, - const std::string &str_name, + const std::string& str_name, int nr_components, - const std::string &str_format, + const std::string& str_format, long offset = -1); - bool WriteDataArrayFooter(std::fstream &fin); - inline bool WriteMeshNodes(std::fstream &fin, - bool output_data, - MeshLib::CFEMesh* m_msh, - long &offset); - inline bool WriteMeshElementConnectivity(std::fstream &fin, - bool output_data, - MeshLib::CFEMesh* m_msh, - long &offset, - long &sum_ele_components); - inline bool WriteMeshElementOffset(std::fstream &fin, - bool output_data, - MeshLib::CFEMesh* m_msh, - long &offset); - inline bool WriteMeshElementType(std::fstream &fin, - bool output_data, - MeshLib::CFEMesh* m_msh, - long &offset); - inline bool WriteNodalValue(std::fstream &fin, - bool output_data, - COutput* out, - MeshLib::CFEMesh* m_msh, - long &offset); - inline bool WriteElementValue(std::fstream &fin, - bool output_data, - COutput* out, - MeshLib::CFEMesh* m_msh, - long &offset); + bool WriteDataArrayFooter(std::fstream& fin); + inline bool WriteMeshNodes(std::fstream& fin, bool output_data, MeshLib::CFEMesh* m_msh, long& offset); + inline bool WriteMeshElementConnectivity( + std::fstream& fin, bool output_data, MeshLib::CFEMesh* m_msh, long& offset, long& sum_ele_components); + inline bool WriteMeshElementOffset(std::fstream& fin, bool output_data, MeshLib::CFEMesh* m_msh, long& offset); + inline bool WriteMeshElementType(std::fstream& fin, bool output_data, MeshLib::CFEMesh* m_msh, long& offset); + inline bool WriteNodalValue( + std::fstream& fin, bool output_data, COutput* out, MeshLib::CFEMesh* m_msh, long& offset); + inline bool WriteElementValue( + std::fstream& fin, bool output_data, COutput* out, MeshLib::CFEMesh* m_msh, long& offset); - //util - template void write_value_binary(std::fstream &fin, T val); + // util + template + void write_value_binary(std::fstream& fin, T val); bool IsLittleEndian(); public: - //PVD - bool InitializePVD(const std::string &file_base_name, - const std::string &pcs_type_name, - bool binary = false); - bool UpdatePVD(const std::string &pvdfile, const std::vector &vec_vtk); - bool CreateDirOfPVD(const std::string &pvdfile); + // PVD + bool InitializePVD(const std::string& file_base_name, const std::string& pcs_type_name, bool binary = false); + bool UpdatePVD(const std::string& pvdfile, const std::vector& vec_vtk); + bool CreateDirOfPVD(const std::string& pvdfile); - //VTU - bool WriteXMLUnstructuredGrid(const std::string &vtkfile, - COutput* out, - const int time_step_number); + // VTU + bool WriteXMLUnstructuredGrid(const std::string& vtkfile, COutput* out, const int time_step_number); }; #endif diff --git a/FileIO/FEMIO/BoundaryConditionIO.cpp b/FileIO/FEMIO/BoundaryConditionIO.cpp old mode 100755 new mode 100644 index 76d73326d..4bb94149f --- a/FileIO/FEMIO/BoundaryConditionIO.cpp +++ b/FileIO/FEMIO/BoundaryConditionIO.cpp @@ -20,7 +20,7 @@ namespace FileIO { -//CBoundaryCondition* BoundaryConditionIO::read(std::istream& in_str, +// CBoundaryCondition* BoundaryConditionIO::read(std::istream& in_str, // GEOLIB::GEOObjects const& geo_obj, std::string const& unique_fname) //{ // ProcessType pcs_type (INVALID_PROCESS); @@ -205,27 +205,29 @@ namespace FileIO // return NULL; //} -void BoundaryConditionIO::write(std::ostream& out, - CBoundaryCondition const& bc) +void BoundaryConditionIO::write(std::ostream& out, CBoundaryCondition const& bc) { // keyword - out << "#BOUNDARY_CONDITION" << "\n"; + out << "#BOUNDARY_CONDITION" + << "\n"; // process and primary variable - out << "\t$PCS_TYPE" << "\n"; - out << "\t\t" << convertProcessTypeToString(bc.getProcessType()) + out << "\t$PCS_TYPE" << "\n"; + out << "\t\t" << convertProcessTypeToString(bc.getProcessType()) << "\n"; - out << "\t$PRIMARY_VARIABLE" << "\n"; - out << "\t\t" << convertPrimaryVariableToString( - bc.getProcessPrimaryVariable()) << "\n"; + out << "\t$PRIMARY_VARIABLE" + << "\n"; + out << "\t\t" << convertPrimaryVariableToString(bc.getProcessPrimaryVariable()) << "\n"; // geometry - out << "\t$GEO_TYPE" << "\n"; + out << "\t$GEO_TYPE" + << "\n"; out << "\t" << bc.getGeoTypeAsString() << " " << bc.geo_name << "\n"; // distribution type - out << "\t$DIS_TYPE" << "\n"; + out << "\t$DIS_TYPE" + << "\n"; out << "\t\t" << convertDisTypeToString(bc.getProcessDistributionType()); if (bc.getProcessDistributionType() == FiniteElement::CONSTANT) out << "\t\t" << bc.geo_node_value << "\n"; @@ -233,8 +235,7 @@ void BoundaryConditionIO::write(std::ostream& out, { out << "\t\t" << bc._PointsHaveDistribedBC.size() << "\n"; for (size_t i = 0; i < bc._PointsHaveDistribedBC.size(); i++) - out << "\t\t" << bc._PointsHaveDistribedBC[i] << " " - << bc._DistribedBC[i] << "\n"; + out << "\t\t" << bc._PointsHaveDistribedBC[i] << " " << bc._DistribedBC[i] << "\n"; } else out << "\n"; @@ -242,7 +243,8 @@ void BoundaryConditionIO::write(std::ostream& out, // function name if (!bc.fct_name.empty()) { - out << "\t$FCT_TYPE" << "\n"; + out << "\t$FCT_TYPE" + << "\n"; out << "\t\t" << bc.fct_name << "\n"; } } diff --git a/FileIO/FEMIO/BoundaryConditionIO.h b/FileIO/FEMIO/BoundaryConditionIO.h index 92f4e34be..6a356f0b5 100644 --- a/FileIO/FEMIO/BoundaryConditionIO.h +++ b/FileIO/FEMIO/BoundaryConditionIO.h @@ -28,11 +28,11 @@ namespace FileIO class BoundaryConditionIO { public: -// static CBoundaryCondition* read (std::istream& in, -// GEOLIB::GEOObjects const& geo_obj, -// std::string const& unique_fname); + // static CBoundaryCondition* read (std::istream& in, + // GEOLIB::GEOObjects const& geo_obj, + // std::string const& unique_fname); - static void write (std::ostream& out, CBoundaryCondition const& bc); + static void write(std::ostream& out, CBoundaryCondition const& bc); friend class CBoundaryCondition; }; diff --git a/FileIO/FEMIO/GeoIO.cpp b/FileIO/FEMIO/GeoIO.cpp index 899fb4055..901781c41 100644 --- a/FileIO/FEMIO/GeoIO.cpp +++ b/FileIO/FEMIO/GeoIO.cpp @@ -19,8 +19,8 @@ namespace FileIO { -bool GeoIO::readGeoInfo (GeoInfo* geo_info, std::istream& in_str, std::string& geo_name, - const GEOLIB::GEOObjects& geo_obj, const std::string& unique_geo_name) +bool GeoIO::readGeoInfo(GeoInfo* geo_info, std::istream& in_str, std::string& geo_name, + const GEOLIB::GEOObjects& geo_obj, const std::string& unique_geo_name) { std::stringstream strstream; strstream.str(readNonBlankLineFromInputStream(in_str)); @@ -38,15 +38,16 @@ bool GeoIO::readGeoInfo (GeoInfo* geo_info, std::istream& in_str, std::string& g const GEOLIB::Point* pnt(pnt_vec->getElementByName(geo_name)); if (pnt == NULL) { - std::cerr << "ERROR in GeoIO::readGeoInfo: point name \"" - << geo_name << "\" not found!" << "\n"; + std::cerr << "ERROR in GeoIO::readGeoInfo: point name \"" << geo_name << "\" not found!" + << "\n"; exit(1); } geo_info->setGeoObj(pnt); return true; } - std::cerr << "Error in GeoIO::readGeoInfo: point vector not found!" <<"\n"; + std::cerr << "Error in GeoIO::readGeoInfo: point vector not found!" + << "\n"; exit(1); } @@ -60,15 +61,16 @@ bool GeoIO::readGeoInfo (GeoInfo* geo_info, std::istream& in_str, std::string& g const GEOLIB::Polyline* ply(ply_vec->getElementByName(geo_name)); if (ply == NULL) { - std::cerr << "error in GeoIO::readGeoInfo: polyline name \"" - << geo_name << "\" not found!" << "\n"; + std::cerr << "error in GeoIO::readGeoInfo: polyline name \"" << geo_name << "\" not found!" + << "\n"; exit(1); } geo_info->setGeoObj(ply); return true; } - std::cerr << "Error in GeoIO::readGeoInfo: polyline vector not found!" <<"\n"; + std::cerr << "Error in GeoIO::readGeoInfo: polyline vector not found!" + << "\n"; exit(1); } @@ -76,21 +78,22 @@ bool GeoIO::readGeoInfo (GeoInfo* geo_info, std::istream& in_str, std::string& g { geo_info->setGeoType(GEOLIB::SURFACE); strstream >> geo_name; - GEOLIB::SurfaceVec const* sfc_vec (geo_obj.getSurfaceVecObj(unique_geo_name)); + GEOLIB::SurfaceVec const* sfc_vec(geo_obj.getSurfaceVecObj(unique_geo_name)); if (sfc_vec) { const GEOLIB::Surface* sfc(sfc_vec->getElementByName(geo_name)); if (sfc == NULL) { - std::cerr << "Error in GeoIO::readGeoInfo: surface name \"" - << geo_name << "\" not found!" << "\n"; + std::cerr << "Error in GeoIO::readGeoInfo: surface name \"" << geo_name << "\" not found!" + << "\n"; exit(1); } geo_info->setGeoObj(sfc); return true; } - std::cerr << "Error in GeoIO::readGeoInfo: surface vector not found!" <<"\n"; + std::cerr << "Error in GeoIO::readGeoInfo: surface vector not found!" + << "\n"; exit(1); } @@ -112,5 +115,4 @@ bool GeoIO::readGeoInfo (GeoInfo* geo_info, std::istream& in_str, std::string& g return false; } - } diff --git a/FileIO/FEMIO/GeoIO.h b/FileIO/FEMIO/GeoIO.h index 4d2300e6b..f9cd46478 100644 --- a/FileIO/FEMIO/GeoIO.h +++ b/FileIO/FEMIO/GeoIO.h @@ -51,11 +51,11 @@ class GeoIO * @param unique_geo_name identifier of the geometric data within the geometric manager GEOObjects * @return false if an error occured, else true */ - static bool readGeoInfo (GeoInfo* geo_info, - std::istream& in_str, - std::string& geo_name, - const GEOLIB::GEOObjects& geo_obj, - const std::string& unique_geo_name); + static bool readGeoInfo(GeoInfo* geo_info, + std::istream& in_str, + std::string& geo_name, + const GEOLIB::GEOObjects& geo_obj, + const std::string& unique_geo_name); }; } // ned namespace FileIO diff --git a/FileIO/FEMIO/ProcessIO.cpp b/FileIO/FEMIO/ProcessIO.cpp index d645f8f36..ac0d1330f 100644 --- a/FileIO/FEMIO/ProcessIO.cpp +++ b/FileIO/FEMIO/ProcessIO.cpp @@ -19,9 +19,9 @@ namespace FileIO { -bool ProcessIO::readProcessInfo (std::istream& in_str, FiniteElement::ProcessType& pcs_type) +bool ProcessIO::readProcessInfo(std::istream& in_str, FiniteElement::ProcessType& pcs_type) { - std::stringstream ss_in (readNonBlankLineFromInputStream (in_str)); + std::stringstream ss_in(readNonBlankLineFromInputStream(in_str)); std::string tmp; ss_in >> tmp; pcs_type = FiniteElement::convertProcessType(tmp); diff --git a/FileIO/FEMIO/ProcessIO.h b/FileIO/FEMIO/ProcessIO.h index 789b60e30..c8a005db6 100644 --- a/FileIO/FEMIO/ProcessIO.h +++ b/FileIO/FEMIO/ProcessIO.h @@ -39,7 +39,7 @@ class ProcessIO * @return false, if the process is of type INVALID_PROCESS, else true * \sa enum ProcessType for valid values */ - static bool readProcessInfo (std::istream& in_str, FiniteElement::ProcessType& pcs_type); + static bool readProcessInfo(std::istream& in_str, FiniteElement::ProcessType& pcs_type); }; } diff --git a/FileIO/MathIO/CRSIO.h b/FileIO/MathIO/CRSIO.h index f0d6b97a9..4b800fe92 100644 --- a/FileIO/MathIO/CRSIO.h +++ b/FileIO/MathIO/CRSIO.h @@ -15,19 +15,19 @@ namespace FileIO { -template void -writeCompressedStorageFmt (std::ostream &os, unsigned n, unsigned* iA, unsigned* jA, T* A) +template +void writeCompressedStorageFmt(std::ostream& os, unsigned n, unsigned* iA, unsigned* jA, T* A) { - os.write((char*) &n, sizeof(unsigned)); - os.write((char*) iA, (n + 1) * sizeof(unsigned)); - os.write((char*) jA, iA[n] * sizeof(unsigned)); - os.write((char*) A, iA[n] * sizeof(T)); + os.write((char*)&n, sizeof(unsigned)); + os.write((char*)iA, (n + 1) * sizeof(unsigned)); + os.write((char*)jA, iA[n] * sizeof(unsigned)); + os.write((char*)A, iA[n] * sizeof(T)); } -template void readCompressedStorageFmt(std::istream &is, unsigned &n, - unsigned* &iA, unsigned* &jA, T* &A) +template +void readCompressedStorageFmt(std::istream& is, unsigned& n, unsigned*& iA, unsigned*& jA, T*& A) { - is.read((char*) &n, sizeof(unsigned)); + is.read((char*)&n, sizeof(unsigned)); if (iA != NULL) { delete[] iA; @@ -36,36 +36,37 @@ template void readCompressedStorageFmt(std::istream &is, unsigned &n, } iA = new unsigned[n + 1]; assert(iA != NULL); - is.read((char*) iA, (n + 1) * sizeof(unsigned)); + is.read((char*)iA, (n + 1) * sizeof(unsigned)); jA = new unsigned[iA[n]]; assert(jA != NULL); - is.read((char*) jA, iA[n] * sizeof(unsigned)); + is.read((char*)jA, iA[n] * sizeof(unsigned)); A = new T[iA[n]]; assert(A != NULL); - is.read((char*) A, iA[n] * sizeof(T)); + is.read((char*)A, iA[n] * sizeof(T)); #ifndef NDEBUG // do simple checks if (iA[0] != 0) std::cerr << "\n" - << "CRS matrix: array iA doesn't start with 0" << "\n"; + << "CRS matrix: array iA doesn't start with 0" + << "\n"; unsigned i = 0; while (i < iA[n] && jA[i] < n) ++i; if (i < iA[n]) - std::cerr << "\n" << "CRS matrix: the " << i - << "th entry of jA has the value " << jA[i] - << ", which is out of bounds." << "\n"; + std::cerr << "\n" + << "CRS matrix: the " << i << "th entry of jA has the value " << jA[i] << ", which is out of bounds." + << "\n"; #endif } -template void readCompressedStorageFmt(std::istream &is, long &n, - long* &iA, long* &jA, T* &A, T* &rhs) +template +void readCompressedStorageFmt(std::istream& is, long& n, long*& iA, long*& jA, T*& A, T*& rhs) { - is.read((char*) &n, sizeof(long)); + is.read((char*)&n, sizeof(long)); if (iA != NULL) { delete[] iA; @@ -75,33 +76,34 @@ template void readCompressedStorageFmt(std::istream &is, long &n, iA = new long[n + 1]; assert(iA != NULL); - is.read((char*) iA, (n + 1) * sizeof(long)); + is.read((char*)iA, (n + 1) * sizeof(long)); jA = new long[iA[n]]; assert(jA != NULL); - is.read((char*) jA, iA[n] * sizeof(long)); + is.read((char*)jA, iA[n] * sizeof(long)); A = new T[iA[n]]; assert(A != NULL); - is.read((char*) A, iA[n] * sizeof(T)); + is.read((char*)A, iA[n] * sizeof(T)); rhs = new T[n]; assert(rhs != NULL); - is.read((char*) rhs, n * sizeof(T)); + is.read((char*)rhs, n * sizeof(T)); #ifndef NDEBUG // do simple checks if (iA[0] != 0) std::cerr << "\n" - << "CRS matrix: array iA doesn't start with 0" << "\n"; + << "CRS matrix: array iA doesn't start with 0" + << "\n"; long i = 0; while (i < iA[n] && jA[i] < n) ++i; if (i < iA[n]) - std::cerr << "\n" << "CRS matrix: the " << i - << "th entry of jA has the value " << jA[i] - << ", which is out of bounds." << "\n"; + std::cerr << "\n" + << "CRS matrix: the " << i << "th entry of jA has the value " << jA[i] << ", which is out of bounds." + << "\n"; #endif } } // end namespace FileIO diff --git a/FileIO/MeshIO/LegacyVtkInterface.cpp b/FileIO/MeshIO/LegacyVtkInterface.cpp index ac39ad6ce..27a44412d 100644 --- a/FileIO/MeshIO/LegacyVtkInterface.cpp +++ b/FileIO/MeshIO/LegacyVtkInterface.cpp @@ -36,23 +36,24 @@ using namespace std; LegacyVtkInterface::LegacyVtkInterface(MeshLib::CFEMesh* mesh, - std::vector pointArrayNames, - std::vector cellArrayNames, - std::vector materialPropertyArrayNames, - std::string meshTypeName, - ProcessInfo* processInfo) - : _mesh(mesh), - _pointArrayNames(pointArrayNames), - _cellArrayNames(cellArrayNames), - _materialPropertyArrayNames(materialPropertyArrayNames), - _meshTypeName(meshTypeName), - _processInfo(processInfo) + std::vector + pointArrayNames, + std::vector + cellArrayNames, + std::vector + materialPropertyArrayNames, + std::string meshTypeName, + ProcessInfo* processInfo) + : _mesh(mesh), _pointArrayNames(pointArrayNames), _cellArrayNames(cellArrayNames), + _materialPropertyArrayNames(materialPropertyArrayNames), _meshTypeName(meshTypeName), _processInfo(processInfo) { _processType = convertProcessTypeToString(processInfo->getProcessType()); _mesh = FEMGet(_processType); } -LegacyVtkInterface::~LegacyVtkInterface() {} +LegacyVtkInterface::~LegacyVtkInterface() +{ +} #if defined(USE_PETSC) /************************************************************************** @@ -63,13 +64,12 @@ LegacyVtkInterface::~LegacyVtkInterface() {} 09/2006 KG44 Output for MPI - correct OUTPUT not yet implemented 12/2008 NW Remove ios::app, Add PCS name to VTK file name **************************************************************************/ -void LegacyVtkInterface::WriteDataVTKPETSC(int number, double simulation_time, - std::string baseFilename) const +void LegacyVtkInterface::WriteDataVTKPETSC(int number, double simulation_time, std::string baseFilename) const { - - if(!_mesh) + if (!_mesh) { - cout << "Warning in LegacyVtkInterface::WriteVTKNodes - no MSH data" << "\n"; + cout << "Warning in LegacyVtkInterface::WriteVTKNodes - no MSH data" + << "\n"; return; } @@ -84,100 +84,97 @@ void LegacyVtkInterface::WriteDataVTKPETSC(int number, double simulation_time, baseFilename += ".vtk"; // convert filename string to *char - const char * filename = baseFilename.c_str(); + const char* filename = baseFilename.c_str(); -// Open the viewer + // Open the viewer PetscViewer viewer; // PetscViewerASCIIOpen(PETSC_COMM_WORLD, "x.txt", &viewer); PetscViewerCreate(PETSC_COMM_WORLD, &viewer); PetscViewerSetType(viewer, PETSCVIEWERASCII); PetscViewerFileSetName(viewer, filename); PetscViewerSetFormat(viewer, PETSC_VIEWER_ASCII_VTK); -// write header - PetscViewerASCIIPrintf(viewer,"# vtk DataFile Version 3.0\n"); - PetscViewerASCIIPrintf(viewer,"Unstructured Grid from OpenGeoSys-GEM\n"); - PetscViewerASCIIPrintf(viewer,"ASCII\n"); - PetscViewerASCIIPrintf(viewer,"DATASET UNSTRUCTURED_GRID\n"); - PetscViewerASCIIPrintf(viewer,"FIELD TimesAndCycles 2\n"); - PetscViewerASCIIPrintf(viewer,"TIME 1 1 double\n"); - PetscViewerASCIIPrintf(viewer,"%lg\n",simulation_time); - PetscViewerASCIIPrintf(viewer,"CYCLE 1 1 long\n"); - PetscViewerASCIIPrintf(viewer,"%d\n",number); + // write header + PetscViewerASCIIPrintf(viewer, "# vtk DataFile Version 3.0\n"); + PetscViewerASCIIPrintf(viewer, "Unstructured Grid from OpenGeoSys-GEM\n"); + PetscViewerASCIIPrintf(viewer, "ASCII\n"); + PetscViewerASCIIPrintf(viewer, "DATASET UNSTRUCTURED_GRID\n"); + PetscViewerASCIIPrintf(viewer, "FIELD TimesAndCycles 2\n"); + PetscViewerASCIIPrintf(viewer, "TIME 1 1 double\n"); + PetscViewerASCIIPrintf(viewer, "%lg\n", simulation_time); + PetscViewerASCIIPrintf(viewer, "CYCLE 1 1 long\n"); + PetscViewerASCIIPrintf(viewer, "%d\n", number); this->WriteVTKPointDataPETSC(viewer); this->WriteVTKCellDataPETSC(viewer); this->WriteVTKDataArraysPETSC(viewer); -// close viewer + // close viewer PetscViewerDestroy(&viewer); return; } - void LegacyVtkInterface::WriteVTKPointDataPETSC(PetscViewer viewer) const { - - PetscScalar *xp, *yp, *zp; //used for pointer - PetscInt low,high,nn; + PetscScalar *xp, *yp, *zp; // used for pointer + PetscInt low, high, nn; PetscInt count; int i; - VecScatter ctx; + VecScatter ctx; - MeshLib::CFEMesh *mesh = fem_msh_vector[0]; -// const int nn = mesh->getNumNodesGlobal(); //global number of nodes without shadow nodes - const size_t n_linear_pnts (mesh->GetNodesNumber(false)); + MeshLib::CFEMesh* mesh = fem_msh_vector[0]; + // const int nn = mesh->getNumNodesGlobal(); //global number of nodes without shadow nodes + const size_t n_linear_pnts(mesh->GetNodesNumber(false)); // get my petsc rank int myrank; MPI_Comm_rank(PETSC_COMM_WORLD, &myrank); // test vtk output - PETSc_Vec x,y,z,xcoor,ycoor,zcoor; // + PETSc_Vec x, y, z, xcoor, ycoor, zcoor; // VecCreate(PETSC_COMM_WORLD, &x); - VecSetSizes(x,n_linear_pnts ,PETSC_DECIDE); + VecSetSizes(x, n_linear_pnts, PETSC_DECIDE); VecSetFromOptions(x); // // get range of local variables VecGetOwnershipRange(x, &low, &high); VecGetLocalSize(x, &count); - VecGetSize(x,&nn); -// first duplicate x vector - VecDuplicate(x,&y); - VecDuplicate(x,&z); + VecGetSize(x, &nn); + // first duplicate x vector + VecDuplicate(x, &y); + VecDuplicate(x, &z); // get local part of vectors VecGetArray(x, &xp); VecGetArray(y, &yp); VecGetArray(z, &zp); + // write coordinates -// write coordinates - - PetscViewerASCIIPrintf(viewer,"POINTS %d double\n",nn); + PetscViewerASCIIPrintf(viewer, "POINTS %d double\n", nn); const std::vector pointVector = mesh->getNodeVector(); - for(size_t i = 0; i < (size_t)count; i++) + for (size_t i = 0; i < (size_t)count; i++) { - double const* const coords (pointVector[i]->getData()); + double const* const coords(pointVector[i]->getData()); // now fill the vectors // get the pointer to current node; - //copy local coordinates to pointer - xp[i]=coords[0]; - yp[i]=coords[1]; - zp[i]=coords[2]; + // copy local coordinates to pointer + xp[i] = coords[0]; + yp[i] = coords[1]; + zp[i] = coords[2]; } // create a sequential vector and scatter the coordinates -// to this seq. vector on proc 0 + // to this seq. vector on proc 0 VecScatterCreateToZero(x, &ctx, &xcoor); - VecScatterBegin(ctx,x,xcoor,INSERT_VALUES,SCATTER_FORWARD); - VecScatterEnd(ctx,x,xcoor,INSERT_VALUES,SCATTER_FORWARD); + VecScatterBegin(ctx, x, xcoor, INSERT_VALUES, SCATTER_FORWARD); + VecScatterEnd(ctx, x, xcoor, INSERT_VALUES, SCATTER_FORWARD); VecScatterCreateToZero(y, &ctx, &ycoor); - VecScatterBegin(ctx,y,ycoor,INSERT_VALUES,SCATTER_FORWARD); - VecScatterEnd(ctx,y,ycoor,INSERT_VALUES,SCATTER_FORWARD); + VecScatterBegin(ctx, y, ycoor, INSERT_VALUES, SCATTER_FORWARD); + VecScatterEnd(ctx, y, ycoor, INSERT_VALUES, SCATTER_FORWARD); VecScatterCreateToZero(z, &ctx, &zcoor); - VecScatterBegin(ctx,z,zcoor,INSERT_VALUES,SCATTER_FORWARD); - VecScatterEnd(ctx,z,zcoor,INSERT_VALUES,SCATTER_FORWARD); -// now we have the global vector on rank 0 and can write + VecScatterBegin(ctx, z, zcoor, INSERT_VALUES, SCATTER_FORWARD); + VecScatterEnd(ctx, z, zcoor, INSERT_VALUES, SCATTER_FORWARD); + // now we have the global vector on rank 0 and can write if (myrank == 0) { VecGetArray(xcoor, &xp); @@ -185,7 +182,7 @@ void LegacyVtkInterface::WriteVTKPointDataPETSC(PetscViewer viewer) const VecGetArray(zcoor, &zp); for (i = 0; i < nn; i++) { - PetscViewerASCIIPrintf(viewer, "%lg %lg %lg \n",xp[i],yp[i],zp[i] ); + PetscViewerASCIIPrintf(viewer, "%lg %lg %lg \n", xp[i], yp[i], zp[i]); } } @@ -198,243 +195,248 @@ void LegacyVtkInterface::WriteVTKCellDataPETSC(PetscViewer viewer) const // count overall length of element vector long numAllPoints = 0; - for(size_t i = 0; i < nelocal; i++) + for (size_t i = 0; i < nelocal; i++) { MeshLib::CElem* ele = _mesh->ele_vector[i]; numAllPoints = numAllPoints + (ele->GetNodesNumber(false)) + 1; } - PetscScalar *ep,*eglobp; //used for pointer - PetscInt low,high,neglob,nn; + PetscScalar *ep, *eglobp; // used for pointer + PetscInt low, high, neglob, nn; int i; - VecScatter ctx; - + VecScatter ctx; // get my petsc rank int myrank; MPI_Comm_rank(PETSC_COMM_WORLD, &myrank); // test vtk output - PETSc_Vec e, eglob,x; // + PETSc_Vec e, eglob, x; // - - - // vector for elements ...contains number of nodes connected to form a element in first entry and then the node numbers + // vector for elements ...contains number of nodes connected to form a element in first entry and then the node + // numbers VecCreate(PETSC_COMM_WORLD, &e); - VecSetSizes(e, numAllPoints,PETSC_DECIDE); // nummAllPoints is local lenght of the vector we need + VecSetSizes(e, numAllPoints, PETSC_DECIDE); // nummAllPoints is local lenght of the vector we need VecSetFromOptions(e); // // get range of local variables VecGetOwnershipRange(e, &low, &high); VecGetSize(e, &neglob); -// get local part of vector + // get local part of vector VecGetArray(e, &ep); - - // in order to get a global mesh the node numbers have to be corrected.. -// we have to get the position in the global node vector in order to get the correct additive value -// is there a simpler way to do it (as below)? - MeshLib::CFEMesh *mesh = fem_msh_vector[0]; -// const int nn = mesh->getNumNodesGlobal(); //global number of nodes without shadow nodes - const size_t n_linear_pnts (mesh->GetNodesNumber(false)); + // in order to get a global mesh the node numbers have to be corrected.. + // we have to get the position in the global node vector in order to get the correct additive value + // is there a simpler way to do it (as below)? + MeshLib::CFEMesh* mesh = fem_msh_vector[0]; + // const int nn = mesh->getNumNodesGlobal(); //global number of nodes without shadow nodes + const size_t n_linear_pnts(mesh->GetNodesNumber(false)); VecCreate(PETSC_COMM_WORLD, &x); - VecSetSizes(x, n_linear_pnts,PETSC_DECIDE); + VecSetSizes(x, n_linear_pnts, PETSC_DECIDE); VecSetFromOptions(x); // // get range of local variables VecGetOwnershipRange(x, &low, &high); - VecGetSize(x,&nn); -// cout << " " << low << " " << high << " \n"; -// low is now the first node number + VecGetSize(x, &nn); + // cout << " " << low << " " << high << " \n"; + // low is now the first node number // now we can fill the element vector size_t anz_elem = 0; // here a local value - for(size_t i = 0; i < nelocal; i++) + for (size_t i = 0; i < nelocal; i++) { MeshLib::CElem* ele = _mesh->ele_vector[i]; // cout << ele->GetNodesNumber(false)<< " " ; - switch(ele->GetElementType())// first entry: type of element as defined for vtk ..better than number of nodes + switch (ele->GetElementType()) // first entry: type of element as defined for vtk ..better than number of nodes { - case MshElemType::LINE: - ep[anz_elem]=3; - break; - case MshElemType::QUAD: - ep[anz_elem]=9; - break; - case MshElemType::HEXAHEDRON: - ep[anz_elem]=12; - break; - case MshElemType::TRIANGLE: - ep[anz_elem]=5; - break; - case MshElemType::TETRAHEDRON: - ep[anz_elem]=10; - break; - case MshElemType::PRISM: // VTK_WEDGE - ep[anz_elem]=13; - break; - case MshElemType::PYRAMID: - ep[anz_elem]=14; - break; - default: - cerr << "PETSC VTK output::WriteVTKElementData MshElemType not recogniced" << "\n"; - break; + case MshElemType::LINE: + ep[anz_elem] = 3; + break; + case MshElemType::QUAD: + ep[anz_elem] = 9; + break; + case MshElemType::HEXAHEDRON: + ep[anz_elem] = 12; + break; + case MshElemType::TRIANGLE: + ep[anz_elem] = 5; + break; + case MshElemType::TETRAHEDRON: + ep[anz_elem] = 10; + break; + case MshElemType::PRISM: // VTK_WEDGE + ep[anz_elem] = 13; + break; + case MshElemType::PYRAMID: + ep[anz_elem] = 14; + break; + default: + cerr << "PETSC VTK output::WriteVTKElementData MshElemType not recogniced" + << "\n"; + break; } // cout << ele->GetNodesNumber(false)<< " " ; - for(size_t j = 0; j < ele->GetNodesNumber(false); j++) + for (size_t j = 0; j < ele->GetNodesNumber(false); j++) { - ep[anz_elem+j+1]= ele->GetNodeIndeces()[j] + low; // this are the nodes + ep[anz_elem + j + 1] = ele->GetNodeIndeces()[j] + low; // this are the nodes // cout << "DEBUG " << ele->GetNodeIndeces()[j] << " " ; } // cout << " \n"; - anz_elem = anz_elem+(ele->GetNodesNumber(false))+1 ; + anz_elem = anz_elem + (ele->GetNodesNumber(false)) + 1; } -// now scatter the vectors to process rank 0 + // now scatter the vectors to process rank 0 VecScatterCreateToZero(e, &ctx, &eglob); - VecScatterBegin(ctx,e,eglob,INSERT_VALUES,SCATTER_FORWARD); - VecScatterEnd(ctx,e,eglob,INSERT_VALUES,SCATTER_FORWARD); -// count number of elements + VecScatterBegin(ctx, e, eglob, INSERT_VALUES, SCATTER_FORWARD); + VecScatterEnd(ctx, e, eglob, INSERT_VALUES, SCATTER_FORWARD); + // count number of elements if (myrank == 0) { VecGetArray(eglob, &eglobp); anz_elem = 0; // here this es global number of elements - i=0; + i = 0; while (i < neglob) { - anz_elem+=1; // add one for the element - int mswitch= (int) eglobp[i]; - switch(mswitch )// first entry: type of element as defined for vtk ..better than number of nodes + anz_elem += 1; // add one for the element + int mswitch = (int)eglobp[i]; + switch (mswitch) // first entry: type of element as defined for vtk ..better than number of nodes { - case 3: //LINE - i+=2+1; - break; - case 9: //QUAD - i+=4+1; - break; - case 12: //HEXAHEDRON: - i+=6+1; - break; - case 5: // TRIANGLE: - i+=3+1; - break; - case 10:// TETRAHEDRON: - i+=4+1; - break; - case 13: // PRISM: // VTK_WEDGE - i+=6+1; - break; - case 14: // PYRAMID: - i+=5+1; - break; - default: - cerr << "PETSC VTK Output 1::WriteVTKElementData MshElemType not handled, i. anz_elem. ep[i] type " << i << " " << anz_elem << " " << eglobp[i] << "\n"; - exit(1); - break; + case 3: // LINE + i += 2 + 1; + break; + case 9: // QUAD + i += 4 + 1; + break; + case 12: // HEXAHEDRON: + i += 6 + 1; + break; + case 5: // TRIANGLE: + i += 3 + 1; + break; + case 10: // TETRAHEDRON: + i += 4 + 1; + break; + case 13: // PRISM: // VTK_WEDGE + i += 6 + 1; + break; + case 14: // PYRAMID: + i += 5 + 1; + break; + default: + cerr << "PETSC VTK Output 1::WriteVTKElementData MshElemType not handled, i. anz_elem. ep[i] type " + << i << " " << anz_elem << " " << eglobp[i] << "\n"; + exit(1); + break; } } // write elements -// vtk_file << "CELLS " << numCells << " " << numAllPoints << "\n"; - PetscViewerASCIIPrintf(viewer,"CELLS %d %d\n",anz_elem,neglob); - i=0; + // vtk_file << "CELLS " << numCells << " " << numAllPoints << "\n"; + PetscViewerASCIIPrintf(viewer, "CELLS %d %d\n", anz_elem, neglob); + i = 0; while (i < neglob) { - - switch((int) eglobp[i])// first entry: type of element as defined for vtk ..better than number of nodes + switch ((int)eglobp[i]) // first entry: type of element as defined for vtk ..better than number of nodes { - case 3: //LINE - PetscViewerASCIIPrintf(viewer," 2 "); - for(size_t j = 0; j < 2; j++) PetscViewerASCIIPrintf(viewer," %d ",(long) eglobp[i+j+1]); - i+=2+1; - break; - case 9: //QUAD - PetscViewerASCIIPrintf(viewer," 4 "); - for(size_t j = 0; j < 4; j++) PetscViewerASCIIPrintf(viewer," %d ",(long) eglobp[i+j+1]); - i+=4+1; - break; - case 12: //HEXAHEDRON: - PetscViewerASCIIPrintf(viewer," 6 "); - for(size_t j = 0; j < 6; j++) PetscViewerASCIIPrintf(viewer," %d ",(long) eglobp[i+j+1]); - i+=6+1; - break; - case 5: // TRIANGLE: - PetscViewerASCIIPrintf(viewer," 3 "); - for(size_t j = 0; j < 3; j++) PetscViewerASCIIPrintf(viewer," %d ",(long) eglobp[i+j+1]); - i+=3+1; - break; - case 10:// TETRAHEDRON: - PetscViewerASCIIPrintf(viewer," 4 "); - for(size_t j = 0; j < 4; j++) PetscViewerASCIIPrintf(viewer," %d ",(long) eglobp[i+j+1]); - i+=4+1; - break; - case 13: // PRISM: // VTK_WEDGE - PetscViewerASCIIPrintf(viewer," 6 "); - for(size_t j = 0; j < 6; j++) PetscViewerASCIIPrintf(viewer," %d ",(long) eglobp[i+j+1]); - i+=6+1; - break; - case 14: // PYRAMID: - PetscViewerASCIIPrintf(viewer," 5 "); - for(size_t j = 0; j < 5; j++) PetscViewerASCIIPrintf(viewer," %d ",(long) eglobp[i+j+1]); - i+=5+1; - break; - default: - cerr << "PETSC VTK Output 2::WriteVTKElementData MshElemType not handled" << "\n"; - break; + case 3: // LINE + PetscViewerASCIIPrintf(viewer, " 2 "); + for (size_t j = 0; j < 2; j++) + PetscViewerASCIIPrintf(viewer, " %d ", (long)eglobp[i + j + 1]); + i += 2 + 1; + break; + case 9: // QUAD + PetscViewerASCIIPrintf(viewer, " 4 "); + for (size_t j = 0; j < 4; j++) + PetscViewerASCIIPrintf(viewer, " %d ", (long)eglobp[i + j + 1]); + i += 4 + 1; + break; + case 12: // HEXAHEDRON: + PetscViewerASCIIPrintf(viewer, " 6 "); + for (size_t j = 0; j < 6; j++) + PetscViewerASCIIPrintf(viewer, " %d ", (long)eglobp[i + j + 1]); + i += 6 + 1; + break; + case 5: // TRIANGLE: + PetscViewerASCIIPrintf(viewer, " 3 "); + for (size_t j = 0; j < 3; j++) + PetscViewerASCIIPrintf(viewer, " %d ", (long)eglobp[i + j + 1]); + i += 3 + 1; + break; + case 10: // TETRAHEDRON: + PetscViewerASCIIPrintf(viewer, " 4 "); + for (size_t j = 0; j < 4; j++) + PetscViewerASCIIPrintf(viewer, " %d ", (long)eglobp[i + j + 1]); + i += 4 + 1; + break; + case 13: // PRISM: // VTK_WEDGE + PetscViewerASCIIPrintf(viewer, " 6 "); + for (size_t j = 0; j < 6; j++) + PetscViewerASCIIPrintf(viewer, " %d ", (long)eglobp[i + j + 1]); + i += 6 + 1; + break; + case 14: // PYRAMID: + PetscViewerASCIIPrintf(viewer, " 5 "); + for (size_t j = 0; j < 5; j++) + PetscViewerASCIIPrintf(viewer, " %d ", (long)eglobp[i + j + 1]); + i += 5 + 1; + break; + default: + cerr << "PETSC VTK Output 2::WriteVTKElementData MshElemType not handled" + << "\n"; + break; } - PetscViewerASCIIPrintf(viewer," \n "); + PetscViewerASCIIPrintf(viewer, " \n "); } - // write cell types -// vtk_file << "CELL_TYPES " << numCells << "\n"; - PetscViewerASCIIPrintf(viewer,"CELL_TYPES %d \n",anz_elem); - i=0; + // vtk_file << "CELL_TYPES " << numCells << "\n"; + PetscViewerASCIIPrintf(viewer, "CELL_TYPES %d \n", anz_elem); + i = 0; while (i < neglob) { - - switch((int) eglobp[i])// first entry: type of element as defined for vtk ..better than number of nodes + switch ((int)eglobp[i]) // first entry: type of element as defined for vtk ..better than number of nodes { - case 3: //LINE - PetscViewerASCIIPrintf(viewer," 3 \n"); - i+=2+1; - break; - case 9: //QUAD - PetscViewerASCIIPrintf(viewer," 9 \n"); - i+=4+1; - break; - case 12: //HEXAHEDRON: - PetscViewerASCIIPrintf(viewer," 12 \n"); - i+=6+1; - break; - case 5: // TRIANGLE: - PetscViewerASCIIPrintf(viewer," 5 \n"); - i+=3+1; - break; - case 10:// TETRAHEDRON: - PetscViewerASCIIPrintf(viewer," 10 \n"); - i+=4+1; - break; - case 13: // PRISM: // VTK_WEDGE - PetscViewerASCIIPrintf(viewer," 13 \n"); - i+=6+1; - break; - case 14: // PYRAMID: - PetscViewerASCIIPrintf(viewer," 14 \n");; - i+=5+1; - break; - default: - cerr << "COutput::WriteVTKElementData MshElemType not handled" << "\n"; - break; + case 3: // LINE + PetscViewerASCIIPrintf(viewer, " 3 \n"); + i += 2 + 1; + break; + case 9: // QUAD + PetscViewerASCIIPrintf(viewer, " 9 \n"); + i += 4 + 1; + break; + case 12: // HEXAHEDRON: + PetscViewerASCIIPrintf(viewer, " 12 \n"); + i += 6 + 1; + break; + case 5: // TRIANGLE: + PetscViewerASCIIPrintf(viewer, " 5 \n"); + i += 3 + 1; + break; + case 10: // TETRAHEDRON: + PetscViewerASCIIPrintf(viewer, " 10 \n"); + i += 4 + 1; + break; + case 13: // PRISM: // VTK_WEDGE + PetscViewerASCIIPrintf(viewer, " 13 \n"); + i += 6 + 1; + break; + case 14: // PYRAMID: + PetscViewerASCIIPrintf(viewer, " 14 \n"); + ; + i += 5 + 1; + break; + default: + cerr << "COutput::WriteVTKElementData MshElemType not handled" + << "\n"; + break; } -// PetscViewerASCIIPrintf(viewer," \n "); + // PetscViewerASCIIPrintf(viewer," \n "); } } // end myrank == 0 } - /************************************************************************** FEMLib-Method: Task: @@ -446,13 +448,11 @@ void LegacyVtkInterface::WriteVTKCellDataPETSC(PetscViewer viewer) const **************************************************************************/ void LegacyVtkInterface::WriteVTKDataArraysPETSC(PetscViewer viewer) const { - - PetscScalar *xp; //used for pointer - PetscInt low,high; + PetscScalar* xp; // used for pointer + PetscInt low, high; PetscInt count; - - MeshLib::CFEMesh *_mesh = fem_msh_vector[0]; + MeshLib::CFEMesh* _mesh = fem_msh_vector[0]; long numNodes = _mesh->GetNodesNumber(false); // const int nn = mesh->getNumNodesGlobal(); //global number of nodes ..without shadow nodes @@ -460,7 +460,7 @@ void LegacyVtkInterface::WriteVTKDataArraysPETSC(PetscViewer viewer) const // test vtk output PETSc_Vec x; // VecCreate(PETSC_COMM_WORLD, &x); - VecSetSizes(x, numNodes,PETSC_DECIDE); + VecSetSizes(x, numNodes, PETSC_DECIDE); VecSetFromOptions(x); // // get range of local variables VecGetOwnershipRange(x, &low, &high); @@ -468,9 +468,8 @@ void LegacyVtkInterface::WriteVTKDataArraysPETSC(PetscViewer viewer) const // get local part of vectors VecGetArray(x, &xp); - // NODAL DATA -// vtk_file << "POINT_DATA " << numNodes << "\n"; + // vtk_file << "POINT_DATA " << numNodes << "\n"; const size_t numPointArrays = _pointArrayNames.size(); for (size_t k = 0; k < numPointArrays; k++) @@ -493,32 +492,34 @@ void LegacyVtkInterface::WriteVTKDataArraysPETSC(PetscViewer viewer) const { string arrayName = _pointArrayNames[k]; CRFProcess* pcs = PCSGet(arrayName, true); - if (!pcs) { } - else { - const char * carrayName = arrayName.c_str(); + if (!pcs) + { + } + else + { + const char* carrayName = arrayName.c_str(); int indexDataArray = pcs->GetNodeValueIndex(arrayName); - PetscObjectSetName((PetscObject)x,carrayName); + PetscObjectSetName((PetscObject)x, carrayName); for (long j = 0; j < count; j++) - xp[j]= pcs->GetNodeValue(_mesh->nod_vector[j]->GetIndex(), - indexDataArray); + xp[j] = pcs->GetNodeValue(_mesh->nod_vector[j]->GetIndex(), indexDataArray); VecView(x, viewer); } - } } // here is the place to add the GEMS node data #ifdef GEM_REACT - m_vec_GEM->WriteVTKGEMValuesPETSC(viewer); //kg44 export GEM internal variables like speciateion vector , phases etc + m_vec_GEM->WriteVTKGEMValuesPETSC(viewer); // kg44 export GEM internal variables like speciateion vector , phases +// etc #endif -// ELEMENT DATA + // ELEMENT DATA // first create a PETSC vector for storing the data - PetscScalar *ep; //used for pointer + PetscScalar* ep; // used for pointer -// MeshLib::CFEMesh *_mesh = fem_msh_vector[0]; + // MeshLib::CFEMesh *_mesh = fem_msh_vector[0]; long numElem = _mesh->ele_vector.size(); // const int nn = mesh->getNumNodesGlobal(); //global number of nodes ..without shadow nodes @@ -526,11 +527,11 @@ void LegacyVtkInterface::WriteVTKDataArraysPETSC(PetscViewer viewer) const // test vtk output PETSc_Vec e; // VecCreate(PETSC_COMM_WORLD, &e); - VecSetSizes(e, numElem,PETSC_DECIDE); + VecSetSizes(e, numElem, PETSC_DECIDE); VecSetFromOptions(e); // // get range of local variables - VecGetOwnershipRange(e, &low, &high); //reuse low and high from before - VecGetLocalSize(e, &count); // reuse count + VecGetOwnershipRange(e, &low, &high); // reuse low and high from before + VecGetLocalSize(e, &count); // reuse count // get local part of vectors VecGetArray(e, &ep); @@ -545,8 +546,7 @@ void LegacyVtkInterface::WriteVTKDataArraysPETSC(PetscViewer viewer) const std::vector ele_value_index_vector(_cellArrayNames.size()); if (_cellArrayNames[0].size() > 0) for (size_t i = 0; i < _cellArrayNames.size(); i++) - ele_value_index_vector[i] = pcs->GetElementValueIndex( - _cellArrayNames[i]); + ele_value_index_vector[i] = pcs->GetElementValueIndex(_cellArrayNames[i]); //.................................................................... // @@ -555,33 +555,34 @@ void LegacyVtkInterface::WriteVTKDataArraysPETSC(PetscViewer viewer) const // JTARON 2010, "VELOCITY" should only write as vector, scalars handled elswhere if (_cellArrayNames[k].compare("VELOCITY") == 0) { - //kg44 to be done vtk_file << "VECTORS velocity double " << "\n"; + // kg44 to be done vtk_file << "VECTORS velocity double " << "\n"; // this->WriteELEVelocity(vtk_file); //WW/OK } // PRINT CHANGING (OR CONSTANT) PERMEABILITY TENSOR? // JTARON 2010 else if (_cellArrayNames[k].compare("PERMEABILITY") == 0) { /* kg44 to be done vtk_file << "TENSORS permeability double " << endl; - for (long j = 0; j < (long) _mesh->ele_vector.size(); j++) - { - MeshLib::CElem* ele = _mesh->ele_vector[j]; - CMediumProperties* MediaProp = - mmp_vector[ele->GetPatchIndex()]; - // KG44 22.2.2013 this is not working as expected...we need to differenciate for type of permeability_tensor - for (size_t i = 0; i < 9; i++) - vtk_file << - MediaProp->PermeabilityTensor(j)[i] << " "; - //KG44 this is buggy MediaProp->PermeabilityTensor(j)[i * 3 + i] << " "; - vtk_file << "\n"; - } - */ + for (long j = 0; j < (long) _mesh->ele_vector.size(); j++) + { + MeshLib::CElem* ele = _mesh->ele_vector[j]; + CMediumProperties* MediaProp = + mmp_vector[ele->GetPatchIndex()]; + // KG44 22.2.2013 this is not working as expected...we need to differenciate + for type of permeability_tensor + for (size_t i = 0; i < 9; i++) + vtk_file << + MediaProp->PermeabilityTensor(j)[i] << " "; + //KG44 this is buggy MediaProp->PermeabilityTensor(j)[i * 3 + i] << " "; + vtk_file << "\n"; + } + */ } else if (ele_value_index_vector[k] > -1) { - const char * carrayName = _cellArrayNames[k].c_str(); - PetscObjectSetName((PetscObject)e,carrayName); + const char* carrayName = _cellArrayNames[k].c_str(); + PetscObjectSetName((PetscObject)e, carrayName); for (long j = 0; j < count; j++) - ep[j]= pcs->GetElementValue(j, ele_value_index_vector[k]); + ep[j] = pcs->GetElementValue(j, ele_value_index_vector[k]); VecView(e, viewer); } } @@ -597,21 +598,22 @@ void LegacyVtkInterface::WriteVTKDataArraysPETSC(PetscViewer viewer) const mmp_id = 0; // Let's say porosity // write header for cell data -// if (!wroteAnyEleData) -// vtk_file << "CELL_DATA " << _mesh->ele_vector.size() << "\n"; - const char * carrayName = _materialPropertyArrayNames[0].c_str(); - PetscObjectSetName((PetscObject)e,carrayName); + // if (!wroteAnyEleData) + // vtk_file << "CELL_DATA " << _mesh->ele_vector.size() << "\n"; + const char* carrayName = _materialPropertyArrayNames[0].c_str(); + PetscObjectSetName((PetscObject)e, carrayName); for (size_t i = 0; i < (size_t)count; i++) { MeshLib::CElem* ele = _mesh->ele_vector[i]; switch (mmp_id) { - case 0: - ep[i] = mmp_vector[ele->GetPatchIndex()]->Porosity(i, 0.0); - break; - default: - cout << "COutput::WriteVTKValues: no MMP values specified" << "\n"; - break; + case 0: + ep[i] = mmp_vector[ele->GetPatchIndex()]->Porosity(i, 0.0); + break; + default: + cout << "COutput::WriteVTKValues: no MMP values specified" + << "\n"; + break; } } VecView(e, viewer); @@ -620,44 +622,41 @@ void LegacyVtkInterface::WriteVTKDataArraysPETSC(PetscViewer viewer) const if (mmp_vector.size() > 1) { // write header for cell data -// if (!wroteAnyEleData) //NW: check whether the header has been already written -// vtk_file << "CELL_DATA " << _mesh->ele_vector.size() << "\n"; + // if (!wroteAnyEleData) //NW: check whether the header has been already written + // vtk_file << "CELL_DATA " << _mesh->ele_vector.size() << "\n"; - const char * carrayName = "MatGroup"; - PetscObjectSetName((PetscObject)e,carrayName); + const char* carrayName = "MatGroup"; + PetscObjectSetName((PetscObject)e, carrayName); -// vtk_file << "SCALARS " << "MatGroup" << " int 1" << "\n"; -// vtk_file << "LOOKUP_TABLE default" << "\n"; + // vtk_file << "SCALARS " << "MatGroup" << " int 1" << "\n"; + // vtk_file << "LOOKUP_TABLE default" << "\n"; for (size_t i = 0; i < (size_t)count; i++) { MeshLib::CElem* ele = _mesh->ele_vector[i]; - ep[i]=ele->GetPatchIndex(); -// vtk_file << ele->GetPatchIndex() << "\n"; + ep[i] = ele->GetPatchIndex(); + // vtk_file << ele->GetPatchIndex() << "\n"; } VecView(e, viewer); - const char * carrayNameD = "Domain"; - PetscObjectSetName((PetscObject)e,carrayNameD); + const char* carrayNameD = "Domain"; + PetscObjectSetName((PetscObject)e, carrayNameD); -// vtk_file << "SCALARS " << "MatGroup" << " int 1" << "\n"; -// vtk_file << "LOOKUP_TABLE default" << "\n"; - int myrank; - MPI_Comm_rank(PETSC_COMM_WORLD, &myrank); + // vtk_file << "SCALARS " << "MatGroup" << " int 1" << "\n"; + // vtk_file << "LOOKUP_TABLE default" << "\n"; + int myrank; + MPI_Comm_rank(PETSC_COMM_WORLD, &myrank); for (size_t i = 0; i < (size_t)count; i++) { // MeshLib::CElem* ele = _mesh->ele_vector[i]; - ep[i]=myrank; -// vtk_file << ele->GetPatchIndex() << "\n"; - } + ep[i] = myrank; + // vtk_file << ele->GetPatchIndex() << "\n"; + } VecView(e, viewer); - } - return; } - #else // this is the default if petsc is not defined /************************************************************************** @@ -668,18 +667,19 @@ void LegacyVtkInterface::WriteVTKDataArraysPETSC(PetscViewer viewer) const 09/2006 KG44 Output for MPI - correct OUTPUT not yet implemented 12/2008 NW Remove ios::app, Add PCS name to VTK file name **************************************************************************/ -void LegacyVtkInterface::WriteDataVTK(int number, double simulation_time, - std::string baseFilename) const +void LegacyVtkInterface::WriteDataVTK(int number, double simulation_time, std::string baseFilename) const { baseFilename = pathJoin(defaultOutputPath, pathBasename(baseFilename)); #if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) - cout << "Process " << myrank << " in WriteDataVTK" << "\n"; + cout << "Process " << myrank << " in WriteDataVTK" + << "\n"; #endif - if(!_mesh) + if (!_mesh) { - cout << "Warning in LegacyVtkInterface::WriteVTKNodes - no MSH data" << "\n"; + cout << "Warning in LegacyVtkInterface::WriteVTKNodes - no MSH data" + << "\n"; return; } @@ -694,68 +694,73 @@ void LegacyVtkInterface::WriteDataVTK(int number, double simulation_time, baseFilename += ".vtk"; // LB if(!_new_file_opened) remove(baseFilename.c_str()); - fstream vtk_file (baseFilename.c_str(), ios::out); - vtk_file.setf(ios::scientific,ios::floatfield); + fstream vtk_file(baseFilename.c_str(), ios::out); + vtk_file.setf(ios::scientific, ios::floatfield); vtk_file.precision(12); if (!vtk_file.good()) { cout << "Could not open file for writing: " << baseFilename << "\n"; return; } - vtk_file.seekg(0L,ios::beg); + vtk_file.seekg(0L, ios::beg); #ifdef SUPERCOMPUTER -// kg44 buffer the output - char mybuffer [MY_IO_BUFSIZE * MY_IO_BUFSIZE]; - vtk_file.rdbuf()->pubsetbuf(mybuffer,MY_IO_BUFSIZE * MY_IO_BUFSIZE); + // kg44 buffer the output + char mybuffer[MY_IO_BUFSIZE * MY_IO_BUFSIZE]; + vtk_file.rdbuf()->pubsetbuf(mybuffer, MY_IO_BUFSIZE * MY_IO_BUFSIZE); // #endif - this->WriteVTKHeader(vtk_file,number,simulation_time); + this->WriteVTKHeader(vtk_file, number, simulation_time); this->WriteVTKPointData(vtk_file); this->WriteVTKCellData(vtk_file); this->WriteVTKDataArrays(vtk_file); vtk_file.close(); } - -void LegacyVtkInterface::WriteVTKHeader(fstream &vtk_file, - int time_step_number, - double simulation_time) const +void LegacyVtkInterface::WriteVTKHeader(fstream& vtk_file, int time_step_number, double simulation_time) const { - vtk_file << "# vtk DataFile Version 3.0" << "\n"; - vtk_file << "Unstructured Grid from OpenGeoSys" << "\n"; - vtk_file << "ASCII" << "\n"; - vtk_file << "DATASET UNSTRUCTURED_GRID" << "\n"; + vtk_file << "# vtk DataFile Version 3.0" + << "\n"; + vtk_file << "Unstructured Grid from OpenGeoSys" + << "\n"; + vtk_file << "ASCII" + << "\n"; + vtk_file << "DATASET UNSTRUCTURED_GRID" + << "\n"; // time information // see http://www.visitusers.org/index.php?title=Time_and_Cycle_in_VTK_files - vtk_file << "FIELD TimesAndCycles 2" << "\n"; - vtk_file << "TIME 1 1 double" << "\n"; + vtk_file << "FIELD TimesAndCycles 2" + << "\n"; + vtk_file << "TIME 1 1 double" + << "\n"; vtk_file << simulation_time << "\n"; - vtk_file << "CYLCE 1 1 long" << "\n"; + vtk_file << "CYLCE 1 1 long" + << "\n"; vtk_file << time_step_number << "\n"; } -void LegacyVtkInterface::WriteVTKPointData(fstream &vtk_file) const +void LegacyVtkInterface::WriteVTKPointData(fstream& vtk_file) const { const std::vector pointVector = _mesh->getNodeVector(); - const size_t n_linear_pnts (_mesh->GetNodesNumber(false)); - vtk_file << "POINTS " << n_linear_pnts << " double" << "\n"; + const size_t n_linear_pnts(_mesh->GetNodesNumber(false)); + vtk_file << "POINTS " << n_linear_pnts << " double" + << "\n"; - for(size_t i = 0; i < n_linear_pnts; i++) + for (size_t i = 0; i < n_linear_pnts; i++) { - double const* const coords (pointVector[i]->getData()); + double const* const coords(pointVector[i]->getData()); vtk_file << coords[0] << " " << coords[1] << " " << coords[2] << "\n"; } } -void LegacyVtkInterface::WriteVTKCellData(fstream &vtk_file) const +void LegacyVtkInterface::WriteVTKCellData(fstream& vtk_file) const { size_t numCells = _mesh->ele_vector.size(); // count overall length of element vector long numAllPoints = 0; - for(size_t i = 0; i < numCells; i++) + for (size_t i = 0; i < numCells; i++) { MeshLib::CElem* ele = _mesh->ele_vector[i]; numAllPoints = numAllPoints + (ele->GetNodesNumber(false)) + 1; @@ -763,40 +768,41 @@ void LegacyVtkInterface::WriteVTKCellData(fstream &vtk_file) const // write elements vtk_file << "CELLS " << numCells << " " << numAllPoints << "\n"; - for(size_t i = 0; i < numCells; i++) + for (size_t i = 0; i < numCells; i++) { MeshLib::CElem* ele = _mesh->ele_vector[i]; // Write number of points per cell - switch(ele->GetElementType()) + switch (ele->GetElementType()) { - case MshElemType::LINE: - vtk_file << "2"; - break; - case MshElemType::QUAD: - vtk_file << "4"; - break; - case MshElemType::HEXAHEDRON: - vtk_file << "8"; - break; - case MshElemType::TRIANGLE: - vtk_file << "3"; - break; - case MshElemType::TETRAHEDRON: - vtk_file << "4"; - break; - case MshElemType::PRISM: - vtk_file << "6"; - break; - case MshElemType::PYRAMID: - vtk_file << "5"; - break; - default: - cerr << "COutput::WriteVTKElementData MshElemType not handled" << "\n"; - break; + case MshElemType::LINE: + vtk_file << "2"; + break; + case MshElemType::QUAD: + vtk_file << "4"; + break; + case MshElemType::HEXAHEDRON: + vtk_file << "8"; + break; + case MshElemType::TRIANGLE: + vtk_file << "3"; + break; + case MshElemType::TETRAHEDRON: + vtk_file << "4"; + break; + case MshElemType::PRISM: + vtk_file << "6"; + break; + case MshElemType::PYRAMID: + vtk_file << "5"; + break; + default: + cerr << "COutput::WriteVTKElementData MshElemType not handled" + << "\n"; + break; } - for(size_t j = 0; j < ele->GetNodesNumber(false); j++) + for (size_t j = 0; j < ele->GetNodesNumber(false); j++) vtk_file << " " << ele->getNodeIndices()[j]; vtk_file << "\n"; @@ -806,37 +812,45 @@ void LegacyVtkInterface::WriteVTKCellData(fstream &vtk_file) const // write cell types vtk_file << "CELL_TYPES " << numCells << "\n"; - for(size_t i = 0; i < numCells; i++) + for (size_t i = 0; i < numCells; i++) { MeshLib::CElem* ele = _mesh->ele_vector[i]; // Write vtk cell type number (see vtkCellType.h) - switch(ele->GetElementType()) + switch (ele->GetElementType()) { - case MshElemType::LINE: - vtk_file << "3" << "\n"; - break; - case MshElemType::QUAD: - vtk_file << "9" << "\n"; - break; - case MshElemType::HEXAHEDRON: - vtk_file << "12" << "\n"; - break; - case MshElemType::TRIANGLE: - vtk_file << "5" << "\n"; - break; - case MshElemType::TETRAHEDRON: - vtk_file << "10" << "\n"; - break; - case MshElemType::PRISM: // VTK_WEDGE - vtk_file << "13" << "\n"; - break; - case MshElemType::PYRAMID: - vtk_file << "14" << "\n"; - break; - default: - cerr << "COutput::WriteVTKElementData MshElemType not handled" << "\n"; - break; + case MshElemType::LINE: + vtk_file << "3" + << "\n"; + break; + case MshElemType::QUAD: + vtk_file << "9" + << "\n"; + break; + case MshElemType::HEXAHEDRON: + vtk_file << "12" + << "\n"; + break; + case MshElemType::TRIANGLE: + vtk_file << "5" + << "\n"; + break; + case MshElemType::TETRAHEDRON: + vtk_file << "10" + << "\n"; + break; + case MshElemType::PRISM: // VTK_WEDGE + vtk_file << "13" + << "\n"; + break; + case MshElemType::PYRAMID: + vtk_file << "14" + << "\n"; + break; + default: + cerr << "COutput::WriteVTKElementData MshElemType not handled" + << "\n"; + break; } } vtk_file << "\n"; @@ -852,7 +866,7 @@ void LegacyVtkInterface::WriteVTKCellData(fstream &vtk_file) const 06/2009 WW/OK WriteELEVelocity for different coordinate systems 11/2012 WW Rewrite this fucntion in order to have a correct vec/teosor output **************************************************************************/ -void LegacyVtkInterface::WriteVTKDataArrays(fstream &vtk_file) const +void LegacyVtkInterface::WriteVTKDataArrays(fstream& vtk_file) const { long numNodes = _mesh->GetNodesNumber(false); @@ -863,9 +877,8 @@ void LegacyVtkInterface::WriteVTKDataArrays(fstream &vtk_file) const int tensor_com = 4; - if(space_dim == 3) - tensor_com = 6; - + if (space_dim == 3) + tensor_com = 6; // NODAL DATA vtk_file << "POINT_DATA " << numNodes << "\n"; @@ -876,50 +889,48 @@ void LegacyVtkInterface::WriteVTKDataArrays(fstream &vtk_file) const bool toNext = false; // Write X, Y and Z arrays as vectors - //WW. 11.2012. if(k + 1 < numPointArrays) + // WW. 11.2012. if(k + 1 < numPointArrays) { - if (_pointArrayNames[k].find("_X") != string::npos && (k+1getProcessType() == FiniteElement::FLUID_MOMENTUM ) // 23.11.2012. WW + if (pcs->getProcessType() == FiniteElement::FLUID_MOMENTUM) // 23.11.2012. WW { - vec_val_idx[0] = pcs->GetNodeValueIndex(arrayName) + 1; - for(int kk=1; kkGetNodeValueIndex(arrayName) + 1; + for (int kk = 1; kk < space_dim; kk++) { - vec_val_idx[kk] = vec_val_idx[kk-1] + 2; + vec_val_idx[kk] = vec_val_idx[kk - 1] + 2; } } else { - vec_val_idx[0] = pcs->GetNodeValueIndex(arrayName); - for(int kk=1; kkGetNodeValueIndex(arrayName); + for (int kk = 1; kk < space_dim; kk++) { - vec_val_idx[kk] = vec_val_idx[0] + kk; + vec_val_idx[kk] = vec_val_idx[0] + kk; } } - std::cout << "ArrayName: " << arrayName << "\n"; - vtk_file << "VECTORS " << arrayName.substr(0, arrayName.size() - 2) << - " double" << "\n"; + vtk_file << "VECTORS " << arrayName.substr(0, arrayName.size() - 2) << " double" + << "\n"; for (long j = 0l; j < numNodes; j++) { - const long node_id = _mesh->nod_vector[j]->GetIndex(); - for(int kk=0; kkGetNodeValue(node_id, vec_val_idx[kk]) << " " ; + vtk_file << pcs->GetNodeValue(node_id, vec_val_idx[kk]) << " "; } - for(int kk=space_dim; kk<3; kk++) + for (int kk = space_dim; kk < 3; kk++) { - vtk_file << "0.0 " ; + vtk_file << "0.0 "; } vtk_file << "\n"; @@ -930,24 +941,22 @@ void LegacyVtkInterface::WriteVTKDataArrays(fstream &vtk_file) const } // Write tensors as Eigenvectors // XX, XY, YY, ZZ, XZ, YZ must be present in that order - else if(_pointArrayNames[k].find("_XX") != string::npos) + else if (_pointArrayNames[k].find("_XX") != string::npos) { - - string arrayName = _pointArrayNames[k]; - CRFProcess* pcs = PCSGet(arrayName, true); - if (!pcs) - continue; + string arrayName = _pointArrayNames[k]; + CRFProcess* pcs = PCSGet(arrayName, true); + if (!pcs) + continue; tensor_val_idx[0] = pcs->GetNodeValueIndex(arrayName); - for(int kk=1; kk > eigenvectors_1, eigenvectors_2, eigenvectors_3; // Iterate over nodes @@ -956,11 +965,10 @@ void LegacyVtkInterface::WriteVTKDataArrays(fstream &vtk_file) const const long node_id = _mesh->nod_vector[j]->GetIndex(); double vector6[6]; // Iterate over the tensor 6 arrays - for(size_t component = 0; component < tensor_com; ++component) + for (size_t component = 0; component < tensor_com; ++component) { - vector6[component] = pcs->GetNodeValue(node_id, tensor_val_idx[component]); - //std::cout << "vector " << component << " : " << vector6[component] << "\n"; + // std::cout << "vector " << component << " : " << vector6[component] << "\n"; } double* tensor[3]; @@ -971,7 +979,7 @@ void LegacyVtkInterface::WriteVTKDataArrays(fstream &vtk_file) const tensor[1] = tensor1; tensor[2] = tensor2; - if(tensor_com == 6) + if (tensor_com == 6) { tensor0[0] = vector6[0]; tensor0[1] = vector6[1]; @@ -985,8 +993,8 @@ void LegacyVtkInterface::WriteVTKDataArrays(fstream &vtk_file) const } else { - continue; - //std::cout << " To be finished / " << "\n"; + continue; + // std::cout << " To be finished / " << "\n"; } // std::cout << "TensorMat:" << "\n"; // std::cout << tensor0[0] << " " << tensor0[1] << " " << tensor0[2] << "\n"; @@ -994,12 +1002,14 @@ void LegacyVtkInterface::WriteVTKDataArrays(fstream &vtk_file) const // std::cout << tensor2[0] << " " << tensor2[1] << " " << tensor2[2] << "\n"; // std::cout << "\n" << "\n"; - double *eigenvectors[3]; + double* eigenvectors[3]; double eigenvectors0[3]; double eigenvectors1[3]; double eigenvectors2[3]; - eigenvectors[0] = eigenvectors0; eigenvectors[1] = eigenvectors1; eigenvectors[2] = eigenvectors2; + eigenvectors[0] = eigenvectors0; + eigenvectors[1] = eigenvectors1; + eigenvectors[2] = eigenvectors2; double eigenvalues[3]; vtkMath::Jacobi(tensor, eigenvalues, eigenvectors); @@ -1020,24 +1030,30 @@ void LegacyVtkInterface::WriteVTKDataArrays(fstream &vtk_file) const eigenvectors_3.push_back(eigenvector_3); } - vtk_file << "VECTORS " << arrayName.substr(0, arrayName.size() - 3) << - "_Eigenvector_1" << " double" << "\n"; - for(vector >::iterator it = eigenvectors_1.begin(); it != eigenvectors_1.end(); ++it) + vtk_file << "VECTORS " << arrayName.substr(0, arrayName.size() - 3) << "_Eigenvector_1" + << " double" + << "\n"; + for (vector >::iterator it = eigenvectors_1.begin(); it != eigenvectors_1.end(); + ++it) vtk_file << (*it)[0] << " " << (*it)[1] << " " << (*it)[2] << "\n"; - vtk_file << "VECTORS " << arrayName.substr(0, arrayName.size() - 3) << - "_Eigenvector_2" << " double" << "\n"; - for(vector >::iterator it = eigenvectors_2.begin(); it != eigenvectors_2.end(); ++it) + vtk_file << "VECTORS " << arrayName.substr(0, arrayName.size() - 3) << "_Eigenvector_2" + << " double" + << "\n"; + for (vector >::iterator it = eigenvectors_2.begin(); it != eigenvectors_2.end(); + ++it) vtk_file << (*it)[0] << " " << (*it)[1] << " " << (*it)[2] << "\n"; - vtk_file << "VECTORS " << arrayName.substr(0, arrayName.size() - 3) << - "_Eigenvector_3" << " double" << "\n"; - for(vector >::iterator it = eigenvectors_3.begin(); it != eigenvectors_3.end(); ++it) + vtk_file << "VECTORS " << arrayName.substr(0, arrayName.size() - 3) << "_Eigenvector_3" + << " double" + << "\n"; + for (vector >::iterator it = eigenvectors_3.begin(); it != eigenvectors_3.end(); + ++it) vtk_file << (*it)[0] << " " << (*it)[1] << " " << (*it)[2] << "\n"; k += tensor_com; toNext = true; #else - // TBD +// TBD #endif } } @@ -1050,26 +1066,28 @@ void LegacyVtkInterface::WriteVTKDataArrays(fstream &vtk_file) const // Saturation 2 for 1212 pp - scheme. 01.04.2009. WW // --------------------------------------------------------------------- CRFProcess* pcs = NULL; - if (!_pointArrayNames.empty()) //SB added + if (!_pointArrayNames.empty()) // SB added pcs = PCSGet(_pointArrayNames[0], true); if (pcs && pcs->type == 1212) { - size_t i = pcs->GetNodeValueIndex("SATURATION1",true); // JT: Latest - vtk_file << "SCALARS SATURATION2 double 1" << "\n"; - vtk_file << "LOOKUP_TABLE default" << "\n"; + size_t i = pcs->GetNodeValueIndex("SATURATION1", true); // JT: Latest + vtk_file << "SCALARS SATURATION2 double 1" + << "\n"; + vtk_file << "LOOKUP_TABLE default" + << "\n"; for (long j = 0l; j < numNodes; j++) { double val_n = pcs->GetNodeValue(_mesh->nod_vector[j]->GetIndex(), i); vtk_file << 1.0 - val_n << "\n"; } } -//kg44 GEM node data +// kg44 GEM node data #ifdef GEM_REACT - m_vec_GEM->WriteVTKGEMValues(vtk_file); //kg44 export GEM internal variables like speciateion vector , phases etc + m_vec_GEM->WriteVTKGEMValues(vtk_file); // kg44 export GEM internal variables like speciateion vector , phases etc #endif // ELEMENT DATA // --------------------------------------------------------------------- - bool wroteAnyEleData = false; //NW + bool wroteAnyEleData = false; // NW if (!_cellArrayNames.empty()) { CRFProcess* pcs = this->GetPCS_ELE(_cellArrayNames[0]); @@ -1077,10 +1095,9 @@ void LegacyVtkInterface::WriteVTKDataArrays(fstream &vtk_file) const std::vector ele_value_index_vector(_cellArrayNames.size()); if (_cellArrayNames[0].size() > 0) for (size_t i = 0; i < _cellArrayNames.size(); i++) - ele_value_index_vector[i] = pcs->GetElementValueIndex( - _cellArrayNames[i]); + ele_value_index_vector[i] = pcs->GetElementValueIndex(_cellArrayNames[i]); - vtk_file << "CELL_DATA " << (long) _mesh->ele_vector.size() << "\n"; + vtk_file << "CELL_DATA " << (long)_mesh->ele_vector.size() << "\n"; wroteAnyEleData = true; //.................................................................... // @@ -1089,23 +1106,23 @@ void LegacyVtkInterface::WriteVTKDataArrays(fstream &vtk_file) const // JTARON 2010, "VELOCITY" should only write as vector, scalars handled elswhere if (_cellArrayNames[k].compare("VELOCITY") == 0) { - vtk_file << "VECTORS velocity double " << "\n"; - this->WriteELEVelocity(vtk_file); //WW/OK + vtk_file << "VECTORS velocity double " + << "\n"; + this->WriteELEVelocity(vtk_file); // WW/OK } // PRINT CHANGING (OR CONSTANT) PERMEABILITY TENSOR? // JTARON 2010 else if (_cellArrayNames[k].compare("PERMEABILITY") == 0) { vtk_file << "TENSORS permeability double " << endl; - for (long j = 0; j < (long) _mesh->ele_vector.size(); j++) + for (long j = 0; j < (long)_mesh->ele_vector.size(); j++) { MeshLib::CElem* ele = _mesh->ele_vector[j]; - CMediumProperties* MediaProp = - mmp_vector[ele->GetPatchIndex()]; - // KG44 22.2.2013 this is not working as expected...we need to differenciate for type of permeability_tensor + CMediumProperties* MediaProp = mmp_vector[ele->GetPatchIndex()]; + // KG44 22.2.2013 this is not working as expected...we need to differenciate for type of + // permeability_tensor for (size_t i = 0; i < 9; i++) - vtk_file << - MediaProp->PermeabilityTensor(j)[i] << " "; -//KG44 this is buggy MediaProp->PermeabilityTensor(j)[i * 3 + i] << " "; + vtk_file << MediaProp->PermeabilityTensor(j)[i] << " "; + // KG44 this is buggy MediaProp->PermeabilityTensor(j)[i * 3 + i] << " "; vtk_file << "\n"; } } @@ -1113,12 +1130,11 @@ void LegacyVtkInterface::WriteVTKDataArrays(fstream &vtk_file) const { // NOW REMAINING SCALAR DATA // JTARON 2010, reconfig vtk_file << "SCALARS " << _cellArrayNames[k] << " double 1" - << "\n"; - vtk_file << "LOOKUP_TABLE default" << "\n"; + << "\n"; + vtk_file << "LOOKUP_TABLE default" + << "\n"; for (size_t i = 0; i < _mesh->ele_vector.size(); i++) - vtk_file << pcs->GetElementValue(i, - ele_value_index_vector[k]) - << "\n"; + vtk_file << pcs->GetElementValue(i, ele_value_index_vector[k]) << "\n"; } } //-------------------------------------------------------------------- @@ -1142,12 +1158,13 @@ void LegacyVtkInterface::WriteVTKDataArrays(fstream &vtk_file) const double mat_value = 0.0; switch (mmp_id) { - case 0: - mat_value = mmp_vector[ele->GetPatchIndex()]->Porosity(i, 0.0); - break; - default: - cout << "COutput::WriteVTKValues: no MMP values specified" << "\n"; - break; + case 0: + mat_value = mmp_vector[ele->GetPatchIndex()]->Porosity(i, 0.0); + break; + default: + cout << "COutput::WriteVTKValues: no MMP values specified" + << "\n"; + break; } vtk_file << mat_value << "\n"; } @@ -1156,12 +1173,16 @@ void LegacyVtkInterface::WriteVTKDataArrays(fstream &vtk_file) const if (mmp_vector.size() > 1) { // write header for cell data - if (!wroteAnyEleData) //NW: check whether the header has been already written + if (!wroteAnyEleData) // NW: check whether the header has been already written vtk_file << "CELL_DATA " << _mesh->ele_vector.size() << "\n"; wroteAnyEleData = true; - vtk_file << "SCALARS " << "MatGroup" << " int 1" << "\n"; - vtk_file << "LOOKUP_TABLE default" << "\n"; + vtk_file << "SCALARS " + << "MatGroup" + << " int 1" + << "\n"; + vtk_file << "LOOKUP_TABLE default" + << "\n"; for (size_t i = 0; i < _mesh->ele_vector.size(); i++) { MeshLib::CElem* ele = _mesh->ele_vector[i]; @@ -1175,37 +1196,37 @@ void LegacyVtkInterface::WriteVTKDataArrays(fstream &vtk_file) const FEMLib-Method: 06/2009 WW/OK Implementation **************************************************************************/ -inline void LegacyVtkInterface::WriteELEVelocity(fstream &vtk_file) const +inline void LegacyVtkInterface::WriteELEVelocity(fstream& vtk_file) const { int vel_ind[3] = {0, 1, 2}; // 1D - if(_mesh->GetCoordinateFlag() / 10 == 1) + if (_mesh->GetCoordinateFlag() / 10 == 1) { // 0 y 0 - if(_mesh->GetCoordinateFlag() % 10 == 1) + if (_mesh->GetCoordinateFlag() % 10 == 1) { vel_ind[0] = 1; vel_ind[1] = 0; } // 0 0 z - else if(_mesh->GetCoordinateFlag() % 10 == 2) + else if (_mesh->GetCoordinateFlag() % 10 == 2) { vel_ind[0] = 2; vel_ind[2] = 0; } } // 2D - if(_mesh->GetCoordinateFlag() / 10 == 2) + if (_mesh->GetCoordinateFlag() / 10 == 2) { // 0 y z - if(_mesh->GetCoordinateFlag() % 10 == 1) + if (_mesh->GetCoordinateFlag() % 10 == 1) { vel_ind[0] = 1; vel_ind[1] = 2; } // x 0 z - else if(_mesh->GetCoordinateFlag() % 10 == 2) + else if (_mesh->GetCoordinateFlag() % 10 == 2) { vel_ind[0] = 0; vel_ind[1] = 2; @@ -1213,15 +1234,15 @@ inline void LegacyVtkInterface::WriteELEVelocity(fstream &vtk_file) const } } - for(long i = 0; i < (long)_mesh->ele_vector.size(); i++) + for (long i = 0; i < (long)_mesh->ele_vector.size(); i++) { - for(int k = 0; k < 3; k++) - vtk_file << ele_gp_value[i]->Velocity(vel_ind[k],0) << " "; + for (int k = 0; k < 3; k++) + vtk_file << ele_gp_value[i]->Velocity(vel_ind[k], 0) << " "; vtk_file << "\n"; } } -CRFProcess* LegacyVtkInterface::GetPCS_ELE(const string &var_name) const +CRFProcess* LegacyVtkInterface::GetPCS_ELE(const string& var_name) const { string pcs_var_name; CRFProcess* pcs = NULL; @@ -1244,7 +1265,7 @@ CRFProcess* LegacyVtkInterface::GetPCS_ELE(const string &var_name) const return pcs; } -void LegacyVtkInterface::printScalarArray(string arrayName, std::fstream &vtk_file) const +void LegacyVtkInterface::printScalarArray(string arrayName, std::fstream& vtk_file) const { CRFProcess* pcs = PCSGet(arrayName, true); if (!pcs) @@ -1253,23 +1274,26 @@ void LegacyVtkInterface::printScalarArray(string arrayName, std::fstream &vtk_fi int indexDataArray = pcs->GetNodeValueIndex(arrayName); long numNodes = _mesh->GetNodesNumber(false); - vtk_file << "SCALARS " << arrayName << " double 1" << "\n"; - vtk_file << "LOOKUP_TABLE default" << "\n"; + vtk_file << "SCALARS " << arrayName << " double 1" + << "\n"; + vtk_file << "LOOKUP_TABLE default" + << "\n"; for (long j = 0l; j < numNodes; j++) - vtk_file << pcs->GetNodeValue(_mesh->nod_vector[j]->GetIndex(), - indexDataArray) - << "\n"; + vtk_file << pcs->GetNodeValue(_mesh->nod_vector[j]->GetIndex(), indexDataArray) << "\n"; } // round very small and very large numbers in order to avoid read error in paraview // paraview can not read number with exponents bigger/smaller than 300/-300 double LegacyVtkInterface::RoundDoubleVTK(double MyZahl) { - double rnumber; - rnumber=MyZahl; - if(MyZahl > 1.0e200) rnumber=1.0e200; - if(MyZahl < -1.0e200) rnumber=-1.0e200; - if((MyZahl < 1.0e-200)&&(MyZahl >-1.0e-200)) rnumber=0.0; - return rnumber; + double rnumber; + rnumber = MyZahl; + if (MyZahl > 1.0e200) + rnumber = 1.0e200; + if (MyZahl < -1.0e200) + rnumber = -1.0e200; + if ((MyZahl < 1.0e-200) && (MyZahl > -1.0e-200)) + rnumber = 0.0; + return rnumber; } diff --git a/FileIO/MeshIO/LegacyVtkInterface.h b/FileIO/MeshIO/LegacyVtkInterface.h index 433a361d9..acc6e4139 100644 --- a/FileIO/MeshIO/LegacyVtkInterface.h +++ b/FileIO/MeshIO/LegacyVtkInterface.h @@ -36,9 +36,12 @@ class LegacyVtkInterface { public: LegacyVtkInterface(MeshLib::CFEMesh* mesh, - std::vector pointArrayNames, - std::vector cellArrayNames, - std::vector materialPropertyArrayNames, + std::vector + pointArrayNames, + std::vector + cellArrayNames, + std::vector + materialPropertyArrayNames, std::string meshTypeName, ProcessInfo* processInfo); virtual ~LegacyVtkInterface(); @@ -48,22 +51,23 @@ class LegacyVtkInterface void WriteDataVTKPETSC(int number, double simulation_time, std::string baseFilename) const; #endif double RoundDoubleVTK(double MyZahl); + protected: void WriteVTKHeader(std::fstream&, int, double) const; void WriteVTKPointData(std::fstream&) const; void WriteVTKCellData(std::fstream&) const; void WriteVTKDataArrays(std::fstream&) const; - void WriteELEVelocity(std::fstream &vtk_file) const; + void WriteELEVelocity(std::fstream& vtk_file) const; #if defined(USE_PETSC) void WriteVTKPointDataPETSC(PetscViewer) const; void WriteVTKCellDataPETSC(PetscViewer) const; void WriteVTKDataArraysPETSC(PetscViewer) const; #endif - void printScalarArray(std::string arrayName, std::fstream &vtk_file) const; + void printScalarArray(std::string arrayName, std::fstream& vtk_file) const; // Copied from COutput - CRFProcess* GetPCS_ELE(const std::string &var_name) const; + CRFProcess* GetPCS_ELE(const std::string& var_name) const; MeshLib::CFEMesh* _mesh; std::string _processType; diff --git a/FileIO/MeshIO/OGSMeshIO.cpp b/FileIO/MeshIO/OGSMeshIO.cpp index 3d39cc971..4b17128c2 100644 --- a/FileIO/MeshIO/OGSMeshIO.cpp +++ b/FileIO/MeshIO/OGSMeshIO.cpp @@ -20,9 +20,7 @@ namespace FileIO { - -OGSMeshIO::OGSMeshIO() -: _mesh(NULL) +OGSMeshIO::OGSMeshIO() : _mesh(NULL) { } @@ -31,7 +29,7 @@ MeshLib::CFEMesh* OGSMeshIO::loadMeshFromFile(std::string const& fname) std::cout << "FEMRead ... " << std::flush; #ifndef NDEBUG - clock_t start (clock()); + clock_t start(clock()); #endif std::vector mesh_vec; @@ -39,28 +37,27 @@ MeshLib::CFEMesh* OGSMeshIO::loadMeshFromFile(std::string const& fname) if (!mesh_vec.empty()) { - #ifndef NDEBUG clock_t start_construct(clock()); #endif mesh_vec[mesh_vec.size() - 1]->ConstructGrid(); - std::cout << "Nr. Nodes: " << - mesh_vec[mesh_vec.size() - 1]->nod_vector.size() << "\n"; - std::cout << "Nr. Elements: " << - mesh_vec[mesh_vec.size() - 1]->ele_vector.size() << "\n"; + std::cout << "Nr. Nodes: " << mesh_vec[mesh_vec.size() - 1]->nod_vector.size() << "\n"; + std::cout << "Nr. Elements: " << mesh_vec[mesh_vec.size() - 1]->ele_vector.size() << "\n"; #ifndef NDEBUG clock_t end_construct(clock()); - std::cout << "constructGrid time: " << (end_construct - start_construct) / (double)(CLOCKS_PER_SEC) << " s" << "\n"; + std::cout << "constructGrid time: " << (end_construct - start_construct) / (double)(CLOCKS_PER_SEC) << " s" + << "\n"; #endif mesh_vec[mesh_vec.size() - 1]->FillTransformMatrix(); #ifndef NDEBUG clock_t end(clock()); - std::cout << "total loading time: " << (end - start) / (double)(CLOCKS_PER_SEC) << " s" << "\n"; + std::cout << "total loading time: " << (end - start) / (double)(CLOCKS_PER_SEC) << " s" + << "\n"; #endif return mesh_vec[mesh_vec.size() - 1]; @@ -70,70 +67,88 @@ MeshLib::CFEMesh* OGSMeshIO::loadMeshFromFile(std::string const& fname) return NULL; } -int OGSMeshIO::write(std::ostream &out) +int OGSMeshIO::write(std::ostream& out) { - if(!_mesh) + if (!_mesh) { - std::cout << "OGSMeshIO cannot write: no mesh set!" << "\n"; + std::cout << "OGSMeshIO cannot write: no mesh set!" + << "\n"; return 0; } setPrecision(9); - out << "#FEM_MSH" << "\n"; + out << "#FEM_MSH" + << "\n"; - out << "$PCS_TYPE" << "\n" << " " << _mesh->pcs_name << "\n"; + out << "$PCS_TYPE" + << "\n" + << " " << _mesh->pcs_name << "\n"; - out << "$NODES" << "\n" << " "; + out << "$NODES" + << "\n" + << " "; const size_t n_nodes(_mesh->GetNodesNumber(false)); out << n_nodes << "\n"; for (size_t i(0); i < n_nodes; i++) { - double const* const coords (_mesh->nod_vector[i]->getData()); + double const* const coords(_mesh->nod_vector[i]->getData()); out << i << " " << coords[0] << " " << coords[1] << " " << coords[2] << "\n"; } - out << "$ELEMENTS" << "\n" << " "; + out << "$ELEMENTS" + << "\n" + << " "; writeElementsExceptLines(_mesh->ele_vector, out); - out << " $LAYER" << "\n"; + out << " $LAYER" + << "\n"; out << " "; out << _mesh->_n_msh_layer << "\n"; - out << "#STOP" << "\n"; + out << "#STOP" + << "\n"; return 1; } -void OGSMeshIO::writeElementsExceptLines(std::vector const& ele_vec, std::ostream &out) +void OGSMeshIO::writeElementsExceptLines(std::vector const& ele_vec, std::ostream& out) { - const size_t ele_vector_size (ele_vec.size()); - const double epsilon (std::numeric_limits::epsilon()); - std::vector non_line_element (ele_vector_size, true); - std::vector non_null_element (ele_vector_size, true); + const size_t ele_vector_size(ele_vec.size()); + const double epsilon(std::numeric_limits::epsilon()); + std::vector non_line_element(ele_vector_size, true); + std::vector non_null_element(ele_vector_size, true); size_t n_elements(0); - for (size_t i(0); i < ele_vector_size; i++) { - if ((ele_vec[i])->GetElementType() == MshElemType::LINE) { + for (size_t i(0); i < ele_vector_size; i++) + { + if ((ele_vec[i])->GetElementType() == MshElemType::LINE) + { non_line_element[i] = false; non_null_element[i] = false; - } else { - if (ele_vec[i]->calcVolume() < epsilon) { + } + else + { + if (ele_vec[i]->calcVolume() < epsilon) + { non_null_element[i] = false; - } else { + } + else + { n_elements++; } } } out << n_elements << "\n"; - for (size_t i(0), k(0); i < ele_vector_size; i++) { - if (non_line_element[i] && non_null_element[i]) { - const size_t tmp_idx (ele_vec[i]->GetIndex()); + for (size_t i(0), k(0); i < ele_vector_size; i++) + { + if (non_line_element[i] && non_null_element[i]) + { + const size_t tmp_idx(ele_vec[i]->GetIndex()); (const_cast(ele_vec[i]))->SetIndex(k); ele_vec[i]->WriteIndex(out); (const_cast(ele_vec[i]))->SetIndex(tmp_idx); k++; } } - } void OGSMeshIO::setMesh(MeshLib::CFEMesh const* mesh) @@ -141,12 +156,13 @@ void OGSMeshIO::setMesh(MeshLib::CFEMesh const* mesh) _mesh = mesh; } -void OGSMeshIO::writeMeshNodesAsGLIPnts (std::vector const& mesh_node_ids, std::ostream & os) +void OGSMeshIO::writeMeshNodesAsGLIPnts(std::vector const& mesh_node_ids, std::ostream& os) { - std::vector const& nodes (_mesh->getNodeVector()); - for (size_t k(0); k const& nodes(_mesh->getNodeVector()); + for (size_t k(0); k < mesh_node_ids.size(); k++) + { + MeshLib::CNode const& node(*(nodes[mesh_node_ids[k]])); + double const* const coords(node.getData()); _out << k << " " << coords[0] << " " << coords[1] << " " << coords[2] << " $NAME " << node.GetIndex() << "\n"; } diff --git a/FileIO/MeshIO/OGSMeshIO.h b/FileIO/MeshIO/OGSMeshIO.h index 32c69d5df..71df13d9e 100644 --- a/FileIO/MeshIO/OGSMeshIO.h +++ b/FileIO/MeshIO/OGSMeshIO.h @@ -39,14 +39,14 @@ class OGSMeshIO : public Writer /// @brief Sets the mesh. void setMesh(MeshLib::CFEMesh const* mesh); - void writeMeshNodesAsGLIPnts (std::vector const& mesh_node_ids, std::ostream & os); + void writeMeshNodesAsGLIPnts(std::vector const& mesh_node_ids, std::ostream& os); protected: /// @brief Write functionality. - int write(std::ostream &out); + int write(std::ostream& out); private: - void writeElementsExceptLines (std::vector const& ele_vec, std::ostream &out); + void writeElementsExceptLines(std::vector const& ele_vec, std::ostream& out); MeshLib::CFEMesh const* _mesh; }; diff --git a/FileIO/OGSIOVer4.cpp b/FileIO/OGSIOVer4.cpp index dcd32d72c..5056ad69a 100644 --- a/FileIO/OGSIOVer4.cpp +++ b/FileIO/OGSIOVer4.cpp @@ -48,8 +48,8 @@ namespace FileIO **************************************************************************/ /** reads the points inclusive their names from input stream in * using the OGS-4 file format */ -std::string readPoints(std::istream &in, std::vector* pnt_vec, - bool &zero_based_indexing, std::map* pnt_id_name_map) +std::string readPoints(std::istream& in, std::vector* pnt_vec, bool& zero_based_indexing, + std::map* pnt_id_name_map) { std::string line; size_t cnt(0); @@ -64,7 +64,7 @@ std::string readPoints(std::istream &in, std::vector* pnt_vec, size_t id; double x, y, z; inss >> id >> x >> y >> z; - if (!inss.fail ()) + if (!inss.fail()) { if (cnt == 0) { @@ -85,24 +85,22 @@ std::string readPoints(std::istream &in, std::vector* pnt_vec, } // read name of point - size_t pos (line.find("$NAME")); - if (pos != std::string::npos) //OK + size_t pos(line.find("$NAME")); + if (pos != std::string::npos) // OK { - size_t end_pos ((line.substr (pos + 6)).find(" ")); + size_t end_pos((line.substr(pos + 6)).find(" ")); if (end_pos != std::string::npos) - (*pnt_id_name_map)[line.substr (pos + 6, end_pos)] = id; -// std::cout << "* name: " << line.substr (pos+6, end_pos) << ", id: " << id << "\n"; + (*pnt_id_name_map)[line.substr(pos + 6, end_pos)] = id; + // std::cout << "* name: " << line.substr (pos+6, end_pos) << ", id: " << id << "\n"; else - (*pnt_id_name_map)[line.substr (pos + 6)] = id; -// std::cout << "name: " << line.substr (pos+6) << ", id: " << id << "\n"; - + (*pnt_id_name_map)[line.substr(pos + 6)] = id; + // std::cout << "name: " << line.substr (pos+6) << ", id: " << id << "\n"; } - size_t id_pos (line.find("$ID")); + size_t id_pos(line.find("$ID")); if (id_pos != std::string::npos) - std::cout << - "WARNING / ERROR: found tag $ID - please use tag $NAME for reading point names" - << cnt << "\n"; + std::cout << "WARNING / ERROR: found tag $ID - please use tag $NAME for reading point names" << cnt + << "\n"; cnt++; } getline(in, line); @@ -112,14 +110,15 @@ std::string readPoints(std::istream &in, std::vector* pnt_vec, } /** reads points from a vector */ -void readPolylinePointVector(const std::string &fname, std::vector& pnt_vec, - Polyline* ply, const std::string &path, std::vector &errors) +void readPolylinePointVector(const std::string& fname, std::vector& pnt_vec, Polyline* ply, + const std::string& path, std::vector& errors) { // open file std::ifstream in((path + fname).c_str()); - if (!in) { + if (!in) + { std::cerr << "error opening stream from " << fname << "\n"; - errors.push_back ("[readPolylinePointVector] error opening stream from " + fname); + errors.push_back("[readPolylinePointVector] error opening stream from " + fname); return; } @@ -145,25 +144,26 @@ void readPolylinePointVector(const std::string &fname, std::vector& pnt_ 01/2010 TF cleaned method from unused variables **************************************************************************/ /** read a single Polyline from stream in into the ply_vec-vector */ -std::string readPolyline(std::istream &in, +std::string readPolyline(std::istream& in, std::vector* ply_vec, - std::map& ply_vec_names, + std::map& ply_vec_names, std::vector& pnt_vec, bool zero_based_indexing, const std::vector& pnt_id_map, - const std::string &path, - std::vector &errors) + const std::string& path, + std::vector& errors) { std::string line, name_of_ply; Polyline* ply(new Polyline(pnt_vec)); size_t type = 2; // need an initial value // Schleife ueber alle Phasen bzw. Komponenten - do { + do + { in >> line; if (line.find("$ID") != std::string::npos) // subkeyword found CC in >> line; // read value - // id = strtol(line_string.data(), NULL, 0); + // id = strtol(line_string.data(), NULL, 0); //.................................................................... if (line.find("$NAME") != std::string::npos) // subkeyword found { @@ -174,7 +174,7 @@ std::string readPolyline(std::istream &in, if (line.find("$TYPE") != std::string::npos) // subkeyword found { in >> line; // read value - type = static_cast (strtol(line.c_str(), NULL, 0)); + type = static_cast(strtol(line.c_str(), NULL, 0)); } //.................................................................... if (line.find("$EPSILON") != std::string::npos) // subkeyword found @@ -187,28 +187,27 @@ std::string readPolyline(std::istream &in, { // read the point ids in >> line; if (type != 100) - while (!in.eof() && line.size() != 0 && (line.find("#") - == std::string::npos) && - (line.find("$") - == - std::string::npos)) + while (!in.eof() && line.size() != 0 && (line.find("#") == std::string::npos) + && (line.find("$") == std::string::npos)) { - size_t pnt_id(str2number (line)); + size_t pnt_id(str2number(line)); if (!zero_based_indexing) - pnt_id--; // one based indexing - size_t ply_size (ply->getNumberOfPoints()); + pnt_id--; // one based indexing + size_t ply_size(ply->getNumberOfPoints()); if (ply_size > 0) { - if (ply->getPointID (ply_size - 1) != pnt_id_map[pnt_id]) + if (ply->getPointID(ply_size - 1) != pnt_id_map[pnt_id]) ply->addPoint(pnt_id_map[pnt_id]); } else ply->addPoint(pnt_id_map[pnt_id]); in >> line; } - else { - std::cerr << "*** polyline is an arc *** reading not implemented" << "\n"; - errors.push_back ("[readPolyline] reading polyline as an arc is not implemented"); + else + { + std::cerr << "*** polyline is an arc *** reading not implemented" + << "\n"; + errors.push_back("[readPolyline] reading polyline as an arc is not implemented"); } // empty line or the keyword or subkeyword or end of file } @@ -223,7 +222,7 @@ std::string readPolyline(std::istream &in, if (type != 100) { - ply_vec_names.insert (std::pair(name_of_ply, ply_vec->size())); + ply_vec_names.insert(std::pair(name_of_ply, ply_vec->size())); ply_vec->push_back(ply); } @@ -243,33 +242,33 @@ std::string readPolyline(std::istream &in, 01/2010 TF changed signature of function **************************************************************************/ /** reads polylines */ -std::string readPolylines(std::istream &in, std::vector* ply_vec, - std::map& ply_vec_names, std::vector& pnt_vec, - bool zero_based_indexing, const std::vector& pnt_id_map, - const std::string &path, std::vector& errors) +std::string readPolylines(std::istream& in, std::vector* ply_vec, + std::map& ply_vec_names, std::vector& pnt_vec, + bool zero_based_indexing, const std::vector& pnt_id_map, const std::string& path, + std::vector& errors) { - if (!in) { - std::cerr << "*** readPolylines input stream error " << "\n"; + if (!in) + { + std::cerr << "*** readPolylines input stream error " + << "\n"; return std::string(""); } std::string tag("#POLYLINE"); while (!in.eof() && tag.find("#POLYLINE") != std::string::npos) - tag = readPolyline(in, ply_vec, ply_vec_names, pnt_vec, - zero_based_indexing, pnt_id_map, path, errors); + tag = readPolyline(in, ply_vec, ply_vec_names, pnt_vec, zero_based_indexing, pnt_id_map, path, errors); return tag; } -void readTINFile(const std::string &fname, Surface* sfc, - std::vector &pnt_vec, std::vector& errors) +void readTINFile(const std::string& fname, Surface* sfc, std::vector& pnt_vec, std::vector& errors) { // open file std::ifstream in(fname.c_str()); - if (!in) { - std::cerr << "readTINFile error opening stream from " << fname - << "\n"; - errors.push_back ("readTINFile error opening stream from " + fname); + if (!in) + { + std::cerr << "readTINFile error opening stream from " << fname << "\n"; + errors.push_back("readTINFile error opening stream from " + fname); return; } @@ -285,43 +284,44 @@ void readTINFile(const std::string &fname, Surface* sfc, // parse line std::stringstream input(line); // read id - if (!(input >> id)) { + if (!(input >> id)) + { in.close(); delete sfc; sfc = NULL; return; } // read first point - if (!(input >> p0[0] >> p0[1] >> p0[2])) { - std::cerr << "Could not read coords of 1st point of triangle \"" - << id << "\".\n"; - errors.push_back (std::string("readTIN error: ") + - std::string("Could not read coords of 1st point in triangle ") + - number2str(id)); + if (!(input >> p0[0] >> p0[1] >> p0[2])) + { + std::cerr << "Could not read coords of 1st point of triangle \"" << id << "\".\n"; + errors.push_back(std::string("readTIN error: ") + + std::string("Could not read coords of 1st point in triangle ") + + number2str(id)); in.close(); delete sfc; sfc = NULL; return; } // read second point - if (!(input >> p1[0] >> p1[1] >> p1[2])) { - std::cerr << "Could not read coords of 2nd point of triangle \"" - << id << "\".\n"; - errors.push_back (std::string("readTIN error: ") + - std::string("Could not read coords of 2nd point in triangle ") + - number2str(id)); + if (!(input >> p1[0] >> p1[1] >> p1[2])) + { + std::cerr << "Could not read coords of 2nd point of triangle \"" << id << "\".\n"; + errors.push_back(std::string("readTIN error: ") + + std::string("Could not read coords of 2nd point in triangle ") + + number2str(id)); in.close(); delete sfc; sfc = NULL; return; } // read third point - if (!(input >> p2[0] >> p2[1] >> p2[2])) { - std::cerr << "Could not read coords of 3rd point of triangle \"" - << id << "\".\n"; - errors.push_back (std::string("readTIN error: ") + - std::string("Could not read coords of 3rd point in triangle ") + - number2str(id)); + if (!(input >> p2[0] >> p2[1] >> p2[2])) + { + std::cerr << "Could not read coords of 3rd point of triangle \"" << id << "\".\n"; + errors.push_back(std::string("readTIN error: ") + + std::string("Could not read coords of 3rd point in triangle ") + + number2str(id)); in.close(); delete sfc; sfc = NULL; @@ -330,10 +330,10 @@ void readTINFile(const std::string &fname, Surface* sfc, // check area of triangle double const d_eps(std::numeric_limits::epsilon()); - if (MathLib::calcTriangleArea(p0, p1, p2) < d_eps) { + if (MathLib::calcTriangleArea(p0, p1, p2) < d_eps) + { std::cerr << "readTIN: Triangle \"" << id << "\" has zero area.\n"; - errors.push_back (std::string("readTIN: Triangle ") - + number2str(id) + std::string(" has zero area.")); + errors.push_back(std::string("readTIN: Triangle ") + number2str(id) + std::string(" has zero area.")); delete sfc; sfc = NULL; return; @@ -348,10 +348,10 @@ void readTINFile(const std::string &fname, Surface* sfc, sfc->addTriangle(pnt_pos, pnt_pos + 1, pnt_pos + 2); } - if (sfc->getNTriangles() == 0) { - std::cerr << "readTIN(): No triangle found in file \"" << fname << - "\".\n"; - errors.push_back ("readTIN error because of no triangle found"); + if (sfc->getNTriangles() == 0) + { + std::cerr << "readTIN(): No triangle found in file \"" << fname << "\".\n"; + errors.push_back("readTIN error because of no triangle found"); delete sfc; sfc = NULL; } @@ -367,27 +367,24 @@ void readTINFile(const std::string &fname, Surface* sfc, 01/2010 TF signatur modification, reimplementation **************************************************************************/ /** read a single Surface */ -std::string readSurface(std::istream &in, - std::vector &polygon_vec, - std::vector &sfc_vec, - std::map& sfc_names, - const std::vector &ply_vec, - const std::map& ply_vec_names, - std::vector &pnt_vec, +std::string readSurface(std::istream& in, std::vector& polygon_vec, std::vector& sfc_vec, + std::map& sfc_names, const std::vector& ply_vec, + const std::map& ply_vec_names, std::vector& pnt_vec, std::string const& path, std::vector& errors) { std::string line; Surface* sfc(NULL); - int type (-1); + int type(-1); std::string name; - size_t ply_id (0); // std::numeric_limits::max()); + size_t ply_id(0); // std::numeric_limits::max()); - do { + do + { in >> line; if (line.find("$ID") != std::string::npos) // subkeyword found CC in >> line; // read value - // id = strtol(line_string.data(), NULL, 0); + // id = strtol(line_string.data(), NULL, 0); //.................................................................... if (line.find("$NAME") != std::string::npos) // subkeyword found { @@ -411,11 +408,12 @@ std::string readSurface(std::istream &in, sfc = new Surface(pnt_vec); readTINFile(line, sfc, pnt_vec, errors); - if (sfc->getNTriangles() == 0) { + if (sfc->getNTriangles() == 0) + { delete sfc; sfc = NULL; } -// std::cout << "ok" << "\n"; + // std::cout << "ok" << "\n"; } //.................................................................... if (line.find("$MAT_GROUP") != std::string::npos) // subkeyword found @@ -424,29 +422,37 @@ std::string readSurface(std::istream &in, if (line.find("$POLYLINES") != std::string::npos) // subkeyword found { // read the name of the polyline(s) in >> line; - while (!in.eof() && line.size() != 0 - && (line.find("#") == std::string::npos) + while (!in.eof() && line.size() != 0 && (line.find("#") == std::string::npos) && (line.find("$") == std::string::npos)) { // we did read the name of a polyline -> search the id for polyline - std::map::const_iterator it (ply_vec_names.find ( - line)); + std::map::const_iterator it(ply_vec_names.find(line)); if (it != ply_vec_names.end()) ply_id = it->second; else ply_id = ply_vec.size(); - if (ply_id == ply_vec.size()) { - std::cerr << "polyline for surface not found!" << "\n"; + if (ply_id == ply_vec.size()) + { + std::cerr << "polyline for surface not found!" + << "\n"; errors.push_back("[readSurface] polyline for surface not found!"); - } else { - if (type == 3) { - std::cerr << "surface type 3: flat surface with any normal direction - - reading not implemented" - << "\n"; - errors.push_back("[readSurface] surface type 3: flat surface with any normal direction - - reading not implemented"); + } + else + { + if (type == 3) + { + std::cerr + << "surface type 3: flat surface with any normal direction - - reading not implemented" + << "\n"; + errors.push_back( + "[readSurface] surface type 3: flat surface with any normal direction - - reading not " + "implemented"); } - if (type == 2) { - std::cerr << "vertical surface - reading not implemented" << "\n"; + if (type == 2) + { + std::cerr << "vertical surface - reading not implemented" + << "\n"; errors.push_back("[readSurface] vertical surface - reading not implemented"); } } @@ -457,27 +463,27 @@ std::string readSurface(std::istream &in, } while (line.find("#") == std::string::npos && line.size() != 0 && in); if (!name.empty()) - sfc_names.insert(std::pair(name,sfc_vec.size())); + sfc_names.insert(std::pair(name, sfc_vec.size())); if (sfc) // surface create by TIN - sfc_vec.push_back (sfc); + sfc_vec.push_back(sfc); else - { - // surface created by polygon - if (ply_id != std::numeric_limits::max() && ply_id != ply_vec.size()) - { - if (!ply_vec[ply_id]->isClosed()) - { - std::cerr << "\n\tcannot create surface " << name << " from polyline: " - << " polyline is not closed.\n"; - std::cerr << "\tmodify the polyline to make it closed.\n"; - Polyline* ply = const_cast(ply_vec[ply_id]); - ply->addPoint(ply->getPointID(0)); - } - polygon_vec.push_back (new Polygon (*(ply_vec[ply_id]), true)); - } - } + { + // surface created by polygon + if (ply_id != std::numeric_limits::max() && ply_id != ply_vec.size()) + { + if (!ply_vec[ply_id]->isClosed()) + { + std::cerr << "\n\tcannot create surface " << name << " from polyline: " + << " polyline is not closed.\n"; + std::cerr << "\tmodify the polyline to make it closed.\n"; + Polyline* ply = const_cast(ply_vec[ply_id]); + ply->addPoint(ply->getPointID(0)); + } + polygon_vec.push_back(new Polygon(*(ply_vec[ply_id]), true)); + } + } return line; } @@ -490,17 +496,14 @@ std::string readSurface(std::istream &in, 05/2004 CC Modification 01/2010 TF changed signature of function, big modifications **************************************************************************/ -std::string readSurfaces(std::istream &in, - std::vector &sfc_vec, - std::map& sfc_names, - const std::vector &ply_vec, - const std::map& ply_vec_names, - std::vector &pnt_vec, - const std::string &path, std::vector& errors) +std::string readSurfaces(std::istream& in, std::vector& sfc_vec, std::map& sfc_names, + const std::vector& ply_vec, const std::map& ply_vec_names, + std::vector& pnt_vec, const std::string& path, std::vector& errors) { if (!in.good()) { - std::cerr << "*** readSurfaces input stream error " << "\n"; + std::cerr << "*** readSurfaces input stream error " + << "\n"; return std::string(""); } std::string tag("#SURFACE"); @@ -509,136 +512,137 @@ std::string readSurfaces(std::istream &in, while (!in.eof() && tag.find("#SURFACE") != std::string::npos) { - size_t n_polygons (polygon_vec.size()); - tag = readSurface(in, polygon_vec, sfc_vec, sfc_names, ply_vec, ply_vec_names, pnt_vec, - path, errors); - if (n_polygons < polygon_vec.size()) { + size_t n_polygons(polygon_vec.size()); + tag = readSurface(in, polygon_vec, sfc_vec, sfc_names, ply_vec, ply_vec_names, pnt_vec, path, errors); + if (n_polygons < polygon_vec.size()) + { // subdivide polygon in simple polygons - GEOLIB::Surface * sfc(GEOLIB::Surface::createSurface( - *(dynamic_cast (polygon_vec[polygon_vec.size() - 1])))); + GEOLIB::Surface* sfc(GEOLIB::Surface::createSurface( + *(dynamic_cast(polygon_vec[polygon_vec.size() - 1])))); sfc_vec.push_back(sfc); } } for (size_t k(0); k < polygon_vec.size(); k++) delete polygon_vec[k]; -// std::cout << "readSurfaces: number of read polygons " << polygon_vec.size() << "\n"; - -// // subdivide all polygons in simple polygons -// for (std::vector::iterator polygon_it (polygon_vec.begin()); -// polygon_it != polygon_vec.end(); polygon_it++) { -// // compute list of simple polygons -// (*polygon_it)->computeListOfSimplePolygons (); -// } - -// // forest consist of (hierarchy) trees -// std::list polygon_forest; -// // create polygon forest -// for (std::vector::iterator polygon_it (polygon_vec.begin()); -// polygon_it != polygon_vec.end(); polygon_it++) { -// // get the list and insert the elements as SimplePolygonTree items into the forest -// const std::list simple_polygon_list ((*polygon_it)->getListOfSimplePolygons()); -// for (std::list::const_iterator simple_polygon_it (simple_polygon_list.begin()); -// simple_polygon_it != simple_polygon_list.end(); simple_polygon_it++) { -// SimplePolygonTree *spt (new SimplePolygonTree (*simple_polygon_it)); -// polygon_forest.push_back (spt); -// } -// } -// std::cout << "readSurfaces: \"Polygon forest\" consists of " << polygon_forest.size() << " trees" << "\n"; -// -// // create the hierarchy -// createPolygonTree (polygon_forest); -// std::cout << "readSurfaces: \"Polygon forest\" consists of " << polygon_forest.size() << " trees" << "\n"; -// -// std::string out_fname ("GMSHTest.geo"); -// std::cout << "writing input file for GMSH " << out_fname << " ... " << std::flush; -// GMSHInterface gmsh_io (out_fname); -// // writing points -// gmsh_io.writeGMSHPoints(pnt_vec); -// // writing simple polygon tree -// for (std::list::const_iterator polygon_tree_it (polygon_forest.begin()); -// polygon_tree_it != polygon_forest.end(); polygon_tree_it++) { -// (*polygon_tree_it)->visitAndProcessNodes (gmsh_io); -// } -// std::cout << "done" << "\n"; + // std::cout << "readSurfaces: number of read polygons " << polygon_vec.size() << "\n"; + + // // subdivide all polygons in simple polygons + // for (std::vector::iterator polygon_it (polygon_vec.begin()); + // polygon_it != polygon_vec.end(); polygon_it++) { + // // compute list of simple polygons + // (*polygon_it)->computeListOfSimplePolygons (); + // } + + // // forest consist of (hierarchy) trees + // std::list polygon_forest; + // // create polygon forest + // for (std::vector::iterator polygon_it (polygon_vec.begin()); + // polygon_it != polygon_vec.end(); polygon_it++) { + // // get the list and insert the elements as SimplePolygonTree items into the forest + // const std::list simple_polygon_list ((*polygon_it)->getListOfSimplePolygons()); + // for (std::list::const_iterator simple_polygon_it (simple_polygon_list.begin()); + // simple_polygon_it != simple_polygon_list.end(); simple_polygon_it++) { + // SimplePolygonTree *spt (new SimplePolygonTree (*simple_polygon_it)); + // polygon_forest.push_back (spt); + // } + // } + // std::cout << "readSurfaces: \"Polygon forest\" consists of " << polygon_forest.size() << " trees" << "\n"; + // + // // create the hierarchy + // createPolygonTree (polygon_forest); + // std::cout << "readSurfaces: \"Polygon forest\" consists of " << polygon_forest.size() << " trees" << "\n"; + // + // std::string out_fname ("GMSHTest.geo"); + // std::cout << "writing input file for GMSH " << out_fname << " ... " << std::flush; + // GMSHInterface gmsh_io (out_fname); + // // writing points + // gmsh_io.writeGMSHPoints(pnt_vec); + // // writing simple polygon tree + // for (std::list::const_iterator polygon_tree_it (polygon_forest.begin()); + // polygon_tree_it != polygon_forest.end(); polygon_tree_it++) { + // (*polygon_tree_it)->visitAndProcessNodes (gmsh_io); + // } + // std::cout << "done" << "\n"; // create surfaces from simple polygons -// for (std::vector::iterator polygon_it (polygon_vec.begin()); -// polygon_it != polygon_vec.end(); polygon_it++) { -// -// const std::list& list_of_simple_polygons ((*polygon_it)->getListOfSimplePolygons()); -// -// for (std::list::const_iterator simple_polygon_it (list_of_simple_polygons.begin()); -// simple_polygon_it != list_of_simple_polygons.end(); simple_polygon_it++) { -// -// std::list triangles; -// MathLib::earClippingTriangulationOfPolygon(*simple_polygon_it, triangles); -// std::cout << "done - " << triangles.size () << " triangles " << "\n"; -// -// Surface *sfc(new Surface(pnt_vec)); -// // add Triangles to Surface -// std::list::const_iterator it (triangles.begin()); -// while (it != triangles.end()) { -// sfc->addTriangle ((*it)[0], (*it)[1], (*it)[2]); -// it++; -// } -// sfc_vec.push_back (sfc); -// } -// } + // for (std::vector::iterator polygon_it (polygon_vec.begin()); + // polygon_it != polygon_vec.end(); polygon_it++) { + // + // const std::list& list_of_simple_polygons ((*polygon_it)->getListOfSimplePolygons()); + // + // for (std::list::const_iterator simple_polygon_it (list_of_simple_polygons.begin()); + // simple_polygon_it != list_of_simple_polygons.end(); simple_polygon_it++) { + // + // std::list triangles; + // MathLib::earClippingTriangulationOfPolygon(*simple_polygon_it, triangles); + // std::cout << "done - " << triangles.size () << " triangles " << "\n"; + // + // Surface *sfc(new Surface(pnt_vec)); + // // add Triangles to Surface + // std::list::const_iterator it (triangles.begin()); + // while (it != triangles.end()) { + // sfc->addTriangle ((*it)[0], (*it)[1], (*it)[2]); + // it++; + // } + // sfc_vec.push_back (sfc); + // } + // } return tag; } -bool readGLIFileV4(const std::string& fname, GEOObjects* geo, std::string& unique_name, std::vector& errors) +bool readGLIFileV4(const std::string& fname, GEOObjects* geo, std::string& unique_name, + std::vector& errors) { - std::cout << "GEOLIB::readGLIFile open stream from file " << fname - << " ... " << std::flush; + std::cout << "GEOLIB::readGLIFile open stream from file " << fname << " ... " << std::flush; std::ifstream in(fname.c_str()); - if (!in) { + if (!in) + { std::cerr << "error opening stream from " << fname << "\n"; errors.push_back("[readGLIFileV4] error opening stream from " + fname); return false; } - std::cout << "done" << "\n"; + std::cout << "done" + << "\n"; std::string tag; while (tag.find("#POINTS") == std::string::npos && !in.eof()) - getline (in, tag); + getline(in, tag); // read names of points into vector of strings - std::map* pnt_id_names_map (new std::map); + std::map* pnt_id_names_map(new std::map); bool zero_based_idx(true); std::vector* pnt_vec(new std::vector); std::cout << "read points from stream ... " << std::flush; tag = readPoints(in, pnt_vec, zero_based_idx, pnt_id_names_map); - std::cout << " ok, " << pnt_vec->size() << " points read" << "\n"; + std::cout << " ok, " << pnt_vec->size() << " points read" + << "\n"; unique_name = BaseLib::getFileNameFromPath(fname, true); if (!pnt_vec->empty()) - geo->addPointVec(pnt_vec, unique_name, pnt_id_names_map); // KR: insert into GEOObjects if not empty + geo->addPointVec(pnt_vec, unique_name, pnt_id_names_map); // KR: insert into GEOObjects if not empty // extract path for reading external files std::string path; BaseLib::extractPath(fname, path); // read names of plys into temporary string-vec - std::map* ply_names (new std::map); + std::map* ply_names(new std::map); std::vector* ply_vec(new std::vector); if (tag.find("#POLYLINE") != std::string::npos && in) { std::cout << "read polylines from stream ... " << std::flush; - tag = readPolylines(in, ply_vec, *ply_names, *pnt_vec, - zero_based_idx, geo->getPointVecObj( - unique_name)->getIDMap(), path, errors); + tag = readPolylines(in, ply_vec, *ply_names, *pnt_vec, zero_based_idx, + geo->getPointVecObj(unique_name)->getIDMap(), path, errors); std::cout << " ok, " << ply_vec->size() << " polylines read" << "\n"; } else - std::cerr - << "tag #POLYLINE not found or input stream error in GEOObjects" - << "\n"; + std::cerr << "tag #POLYLINE not found or input stream error in GEOObjects" + << "\n"; std::vector* sfc_vec(new std::vector); - std::map* sfc_names (new std::map); + std::map* sfc_names(new std::map); if (tag.find("#SURFACE") != std::string::npos && in) { std::cout << "read surfaces from stream ... " << std::flush; @@ -647,15 +651,14 @@ bool readGLIFileV4(const std::string& fname, GEOObjects* geo, std::string& uniqu << "\n"; } else - std::cerr - << "tag #SURFACE not found or input stream error in GEOObjects" - << "\n"; + std::cerr << "tag #SURFACE not found or input stream error in GEOObjects" + << "\n"; in.close(); if (!ply_vec->empty()) - geo->addPolylineVec(ply_vec, unique_name, ply_names); // KR: insert into GEOObjects if not empty + geo->addPolylineVec(ply_vec, unique_name, ply_names); // KR: insert into GEOObjects if not empty if (!sfc_vec->empty()) - geo->addSurfaceVec(sfc_vec, unique_name, sfc_names); // KR: insert into GEOObjects if not empty + geo->addSurfaceVec(sfc_vec, unique_name, sfc_names); // KR: insert into GEOObjects if not empty if (errors.empty()) return true; @@ -663,23 +666,24 @@ bool readGLIFileV4(const std::string& fname, GEOObjects* geo, std::string& uniqu return false; } -void writeGLIFileV4 (const std::string& fname, - const std::string& geo_name, - const GEOLIB::GEOObjects& geo) +void writeGLIFileV4(const std::string& fname, const std::string& geo_name, const GEOLIB::GEOObjects& geo) { - GEOLIB::PointVec const*const pnt_vec(geo.getPointVecObj(geo_name)); - std::vector const*const pnts (pnt_vec->getVector()); - std::ofstream os (fname.c_str()); - if (pnts) { + GEOLIB::PointVec const* const pnt_vec(geo.getPointVecObj(geo_name)); + std::vector const* const pnts(pnt_vec->getVector()); + std::ofstream os(fname.c_str()); + if (pnts) + { std::string pnt_name; const size_t n_pnts(pnts->size()); - std::cout << "writing " << n_pnts << " points to file " << fname << - "\n"; - os << "#POINTS" << "\n"; - os.precision (20); - for (size_t k(0); k < n_pnts; k++) { + std::cout << "writing " << n_pnts << " points to file " << fname << "\n"; + os << "#POINTS" + << "\n"; + os.precision(20); + for (size_t k(0); k < n_pnts; k++) + { os << k << " " << *((*pnts)[k]) << std::flush; - if (pnt_vec->getNameOfElementByID(k, pnt_name)) { + if (pnt_vec->getNameOfElementByID(k, pnt_name)) + { os << " $NAME " << pnt_name << std::flush; } os << "\n"; @@ -687,18 +691,22 @@ void writeGLIFileV4 (const std::string& fname, } std::cout << "writing " << std::flush; - const GEOLIB::PolylineVec* plys_vec (geo.getPolylineVecObj (geo_name)); + const GEOLIB::PolylineVec* plys_vec(geo.getPolylineVecObj(geo_name)); if (plys_vec) { - const std::vector* plys (plys_vec->getVector()); - std::cout << plys->size () << " polylines to file " << fname << "\n"; + const std::vector* plys(plys_vec->getVector()); + std::cout << plys->size() << " polylines to file " << fname << "\n"; for (size_t k(0); k < plys->size(); k++) { - os << "#POLYLINE" << "\n"; + os << "#POLYLINE" + << "\n"; std::string polyline_name; plys_vec->getNameOfElement((*plys)[k], polyline_name); - os << " $NAME " << "\n" << " " << polyline_name << "\n"; - os << " $POINTS" << "\n"; + os << " $NAME " + << "\n" + << " " << polyline_name << "\n"; + os << " $POINTS" + << "\n"; for (size_t j(0); j < (*plys)[k]->getNumberOfPoints(); j++) os << " " << ((*plys)[k])->getPointID(j) << "\n"; } @@ -707,46 +715,65 @@ void writeGLIFileV4 (const std::string& fname, std::cout << "writing " << std::flush; if (plys_vec) { - const std::vector* plys (plys_vec->getVector()); - std::cout << plys->size () << " closed polylines as surfaces to file " << fname << - "\n"; + const std::vector* plys(plys_vec->getVector()); + std::cout << plys->size() << " closed polylines as surfaces to file " << fname << "\n"; for (size_t k(0); k < plys->size(); k++) if ((*plys)[k]->isClosed()) { - os << "#SURFACE" << "\n"; - os << " $NAME " << "\n" << " " << k << "\n"; //plys_vec->getNameOfElement ((*plys)[k]) << "\n"; - os << " $TYPE " << "\n" << " 0" << "\n"; - os << " $POLYLINES" << "\n" << " " << k << "\n"; //plys_vec->getNameOfElement ((*plys)[k]) << "\n"; + os << "#SURFACE" + << "\n"; + os << " $NAME " + << "\n" + << " " << k << "\n"; // plys_vec->getNameOfElement ((*plys)[k]) << "\n"; + os << " $TYPE " + << "\n" + << " 0" + << "\n"; + os << " $POLYLINES" + << "\n" + << " " << k << "\n"; // plys_vec->getNameOfElement ((*plys)[k]) << "\n"; } } // writing surfaces as TIN files std::string path; BaseLib::extractPath(fname, path); - size_t sfcs_cnt (0); - const GEOLIB::SurfaceVec* sfcs_vec (geo.getSurfaceVecObj (geo_name)); - if (sfcs_vec) { - const std::vector* sfcs (sfcs_vec->getVector()); + size_t sfcs_cnt(0); + const GEOLIB::SurfaceVec* sfcs_vec(geo.getSurfaceVecObj(geo_name)); + if (sfcs_vec) + { + const std::vector* sfcs(sfcs_vec->getVector()); for (size_t k(0); k < sfcs->size(); k++) { - os << "#SURFACE" << "\n"; + os << "#SURFACE" + << "\n"; std::string sfc_name(path); - if (sfcs_vec->getNameOfElementByID (sfcs_cnt, sfc_name)) { - os << "\t$NAME " << "\n" << "\t\t" << sfc_name << "\n"; - } else { - os << "\t$NAME " << "\n" << "\t\t" << sfcs_cnt << "\n"; - sfc_name += number2str (sfcs_cnt); + if (sfcs_vec->getNameOfElementByID(sfcs_cnt, sfc_name)) + { + os << "\t$NAME " + << "\n" + << "\t\t" << sfc_name << "\n"; + } + else + { + os << "\t$NAME " + << "\n" + << "\t\t" << sfcs_cnt << "\n"; + sfc_name += number2str(sfcs_cnt); } sfc_name += ".tin"; - os << "\t$TIN" << "\n"; + os << "\t$TIN" + << "\n"; os << "\t\t" << sfc_name << "\n"; // create tin file - std::ofstream tin_os (sfc_name.c_str()); - GEOLIB::Surface const& sfc (*(*sfcs)[k]); - const size_t n_tris (sfc.getNTriangles()); - for (size_t l(0); l < n_tris; l++) { - GEOLIB::Triangle const& tri (*(sfc[l])); - tin_os << l << " " << *(tri.getPoint(0)) << " " << *(tri.getPoint(1)) << " " << *(tri.getPoint(2)) << "\n"; + std::ofstream tin_os(sfc_name.c_str()); + GEOLIB::Surface const& sfc(*(*sfcs)[k]); + const size_t n_tris(sfc.getNTriangles()); + for (size_t l(0); l < n_tris; l++) + { + GEOLIB::Triangle const& tri(*(sfc[l])); + tin_os << l << " " << *(tri.getPoint(0)) << " " << *(tri.getPoint(1)) << " " << *(tri.getPoint(2)) + << "\n"; } tin_os.close(); @@ -754,83 +781,96 @@ void writeGLIFileV4 (const std::string& fname, } } - os << "#STOP" << "\n"; - os.close (); + os << "#STOP" + << "\n"; + os.close(); } -void writeAllDataToGLIFileV4 (const std::string& fname, const GEOLIB::GEOObjects& geo) +void writeAllDataToGLIFileV4(const std::string& fname, const GEOLIB::GEOObjects& geo) { std::vector geo_names; - geo.getGeometryNames (geo_names); + geo.getGeometryNames(geo_names); // extract path for reading external files std::string path; BaseLib::extractPath(fname, path); - std::ofstream os (fname.c_str()); + std::ofstream os(fname.c_str()); - size_t pnts_offset (0); + size_t pnts_offset(0); std::vector pnts_id_offset; - pnts_id_offset.push_back (0); + pnts_id_offset.push_back(0); // writing all points - os << "#POINTS" << "\n"; + os << "#POINTS" + << "\n"; for (size_t j(0); j < geo_names.size(); j++) { - os.precision (20); - GEOLIB::PointVec const*const pnt_vec(geo.getPointVecObj(geo_names[j])); - std::vector const*const pnts (pnt_vec->getVector()); - if (pnts) { + os.precision(20); + GEOLIB::PointVec const* const pnt_vec(geo.getPointVecObj(geo_names[j])); + std::vector const* const pnts(pnt_vec->getVector()); + if (pnts) + { std::string pnt_name; const size_t n_pnts(pnts->size()); - for (size_t k(0); k < n_pnts; k++) { + for (size_t k(0); k < n_pnts; k++) + { os << pnts_offset + k << " " << *((*pnts)[k]) << std::flush; - if (pnt_vec->getNameOfElementByID(k, pnt_name)) { + if (pnt_vec->getNameOfElementByID(k, pnt_name)) + { os << " $NAME " << pnt_name << std::flush; } os << "\n"; } pnts_offset += pnts->size(); - pnts_id_offset.push_back (pnts_offset); + pnts_id_offset.push_back(pnts_offset); } } - std::cout << "wrote " << pnts_offset << " points" << "\n"; + std::cout << "wrote " << pnts_offset << " points" + << "\n"; // writing all stations std::vector stn_names; - geo.getStationVectorNames (stn_names); + geo.getStationVectorNames(stn_names); for (size_t j(0); j < stn_names.size(); j++) { - os.precision (20); - const std::vector* pnts (geo.getStationVec(stn_names[j])); + os.precision(20); + const std::vector* pnts(geo.getStationVec(stn_names[j])); if (pnts) { for (size_t k(0); k < pnts->size(); k++) - os << k + pnts_offset << " " << *((*pnts)[k]) << " $NAME " << - static_cast((*pnts)[k])->getName() << - "\n"; + os << k + pnts_offset << " " << *((*pnts)[k]) << " $NAME " + << static_cast((*pnts)[k])->getName() << "\n"; pnts_offset += pnts->size(); - pnts_id_offset.push_back (pnts_offset); + pnts_id_offset.push_back(pnts_offset); } } - size_t plys_cnt (0); + size_t plys_cnt(0); // writing all polylines for (size_t j(0); j < geo_names.size(); j++) { - const GEOLIB::PolylineVec* plys_vec (geo.getPolylineVecObj (geo_names[j])); - if (plys_vec) { - const std::vector* plys (plys_vec->getVector()); - for (size_t k(0); k < plys->size(); k++) { - os << "#POLYLINE" << "\n"; + const GEOLIB::PolylineVec* plys_vec(geo.getPolylineVecObj(geo_names[j])); + if (plys_vec) + { + const std::vector* plys(plys_vec->getVector()); + for (size_t k(0); k < plys->size(); k++) + { + os << "#POLYLINE" + << "\n"; std::string ply_name; - if (plys_vec->getNameOfElementByID (plys_cnt, ply_name)) - os << "\t$NAME " << "\n" << "\t\t" << ply_name << "\n"; + if (plys_vec->getNameOfElementByID(plys_cnt, ply_name)) + os << "\t$NAME " + << "\n" + << "\t\t" << ply_name << "\n"; else - os << "\t$NAME " << "\n" << "\t\t" << geo_names[j] << "-" << plys_cnt << "\n"; - os << "\t$POINTS" << "\n"; + os << "\t$NAME " + << "\n" + << "\t\t" << geo_names[j] << "-" << plys_cnt << "\n"; + os << "\t$POINTS" + << "\n"; for (size_t l(0); l < (*plys)[k]->getNumberOfPoints(); l++) os << "\t\t" << pnts_id_offset[j] + ((*plys)[k])->getPointID(l) << "\n"; plys_cnt++; @@ -839,41 +879,54 @@ void writeAllDataToGLIFileV4 (const std::string& fname, const GEOLIB::GEOObjects } // writing surfaces as TIN files - size_t sfcs_cnt (0); + size_t sfcs_cnt(0); for (size_t j(0); j < geo_names.size(); j++) + { + const GEOLIB::SurfaceVec* sfcs_vec(geo.getSurfaceVecObj(geo_names[j])); + if (sfcs_vec) { - const GEOLIB::SurfaceVec* sfcs_vec (geo.getSurfaceVecObj (geo_names[j])); - if (sfcs_vec) { - const std::vector* sfcs (sfcs_vec->getVector()); - for (size_t k(0); k < sfcs->size(); k++) + const std::vector* sfcs(sfcs_vec->getVector()); + for (size_t k(0); k < sfcs->size(); k++) + { + os << "#SURFACE" + << "\n"; + std::string sfc_name(path); + if (sfcs_vec->getNameOfElementByID(sfcs_cnt, sfc_name)) { - os << "#SURFACE" << "\n"; - std::string sfc_name(path); - if (sfcs_vec->getNameOfElementByID (sfcs_cnt, sfc_name)) { - os << "\t$NAME " << "\n" << "\t\t" << sfc_name << "\n"; - } else { - os << "\t$NAME " << "\n" << "\t\t" << sfcs_cnt << "\n"; - sfc_name += number2str (sfcs_cnt); - } - sfc_name += ".tin"; - os << "\t$TIN" << "\n"; - os << "\t\t" << sfc_name << "\n"; - // create tin file - std::ofstream tin_os (sfc_name.c_str()); - GEOLIB::Surface const& sfc (*(*sfcs)[k]); - const size_t n_tris (sfc.getNTriangles()); - for (size_t l(0); l < n_tris; l++) { - GEOLIB::Triangle const& tri (*(sfc[l])); - tin_os << l << " " << *(tri.getPoint(0)) << " " << *(tri.getPoint(1)) << " " << *(tri.getPoint(2)) << "\n"; - } - tin_os.close(); - - sfcs_cnt++; + os << "\t$NAME " + << "\n" + << "\t\t" << sfc_name << "\n"; } + else + { + os << "\t$NAME " + << "\n" + << "\t\t" << sfcs_cnt << "\n"; + sfc_name += number2str(sfcs_cnt); + } + sfc_name += ".tin"; + os << "\t$TIN" + << "\n"; + os << "\t\t" << sfc_name << "\n"; + // create tin file + std::ofstream tin_os(sfc_name.c_str()); + GEOLIB::Surface const& sfc(*(*sfcs)[k]); + const size_t n_tris(sfc.getNTriangles()); + for (size_t l(0); l < n_tris; l++) + { + GEOLIB::Triangle const& tri(*(sfc[l])); + tin_os << l << " " << *(tri.getPoint(0)) << " " << *(tri.getPoint(1)) << " " << *(tri.getPoint(2)) + << "\n"; + } + tin_os.close(); + + sfcs_cnt++; } } + } - os << "#STOP" << "\n"; - os.close (); + os << "#STOP" + << "\n"; + os.close(); } } // end namespace diff --git a/FileIO/OGSIOVer4.h b/FileIO/OGSIOVer4.h index a227b493d..bef7c76f8 100644 --- a/FileIO/OGSIOVer4.h +++ b/FileIO/OGSIOVer4.h @@ -34,13 +34,14 @@ namespace FileIO /** I/O - routines for the OGS-4 gli file format */ /** method reads geometric objects from file in gli format */ -bool readGLIFileV4 (const std::string& fname, GEOLIB::GEOObjects* geo, std::string& unique_name, std::vector& errors); +bool readGLIFileV4(const std::string& fname, + GEOLIB::GEOObjects* geo, + std::string& unique_name, + std::vector& errors); -void writeGLIFileV4 (const std::string& fname, - const std::string& proj_name, - const GEOLIB::GEOObjects& geo); +void writeGLIFileV4(const std::string& fname, const std::string& proj_name, const GEOLIB::GEOObjects& geo); -void writeAllDataToGLIFileV4 (const std::string& fname, const GEOLIB::GEOObjects& geo); +void writeAllDataToGLIFileV4(const std::string& fname, const GEOLIB::GEOObjects& geo); } // end namespace diff --git a/FileIO/Reader.cpp b/FileIO/Reader.cpp index 9b002aba7..8102e5635 100644 --- a/FileIO/Reader.cpp +++ b/FileIO/Reader.cpp @@ -15,7 +15,4 @@ namespace FileIO { - - - } // namespace FileIO diff --git a/FileIO/Reader.h b/FileIO/Reader.h index 1d038ed3d..f84862562 100644 --- a/FileIO/Reader.h +++ b/FileIO/Reader.h @@ -13,7 +13,6 @@ namespace FileIO { - /// @brief Base class which enables reading an object from string, stringstream /// or file. /// @@ -22,7 +21,7 @@ class Reader { public: Reader(); - virtual ~Reader() {}; + virtual ~Reader(){}; /// @brief Reads the object from a string. void readFromString(std::string str); diff --git a/FileIO/StationIO.cpp b/FileIO/StationIO.cpp index f821aa202..689a9be1e 100644 --- a/FileIO/StationIO.cpp +++ b/FileIO/StationIO.cpp @@ -13,15 +13,15 @@ #include "StringTools.h" #include -int StationIO::readStationFile(const std::string &path, - std::string &name, +int StationIO::readStationFile(const std::string& path, + std::string& name, std::vector* stations, - GEOLIB::Station::StationType type ) + GEOLIB::Station::StationType type) { int returnValue = 1; std::string line; - std::ifstream in( path.c_str() ); + std::ifstream in(path.c_str()); if (!in.is_open()) { @@ -31,22 +31,22 @@ int StationIO::readStationFile(const std::string &path, /* try to find a name for the list in the first line of the file */ getline(in, line); - if ((line.substr(0,1)).compare("!") == 0) - name = line.substr( 1, line.length() - 1 ); + if ((line.substr(0, 1)).compare("!") == 0) + name = line.substr(1, line.length() - 1); else - in.seekg(0); // sets stream to the beginning of the file + in.seekg(0); // sets stream to the beginning of the file /* read all stations */ - while ( getline(in, line) ) + while (getline(in, line)) { - GEOLIB::Station* newStation (NULL); + GEOLIB::Station* newStation(NULL); if (type == GEOLIB::Station::STATION) newStation = GEOLIB::Station::createStation(line); if (type == GEOLIB::Station::BOREHOLE) newStation = GEOLIB::StationBorehole::createStation(line); if (newStation) - //newStation->setList(name); + // newStation->setList(name); stations->push_back(newStation); else returnValue = -1; @@ -57,11 +57,10 @@ int StationIO::readStationFile(const std::string &path, return returnValue; } -void StationIO::writeStratigraphyTable(const std::vector* boreholes, - const std::string &filename) +void StationIO::writeStratigraphyTable(const std::vector* boreholes, const std::string& filename) { size_t maxIterations = 1; - std::ofstream out( filename.c_str(), std::ios::out ); + std::ofstream out(filename.c_str(), std::ios::out); for (size_t j = 0; j < boreholes->size(); j++) out << static_cast((*boreholes)[j])->getName() << "\t"; @@ -71,9 +70,7 @@ void StationIO::writeStratigraphyTable(const std::vector* boreho { for (size_t j = 0; j < boreholes->size(); j++) { - std::vector soilNames = - static_cast((*boreholes)[j])-> - getSoilNames(); + std::vector soilNames = static_cast((*boreholes)[j])->getSoilNames(); if (!soilNames.empty()) { if (i == 0 && maxIterations < soilNames.size()) @@ -88,4 +85,3 @@ void StationIO::writeStratigraphyTable(const std::vector* boreho out.close(); } - diff --git a/FileIO/StationIO.h b/FileIO/StationIO.h index 23f173b2e..889335348 100644 --- a/FileIO/StationIO.h +++ b/FileIO/StationIO.h @@ -23,14 +23,13 @@ class StationIO { public: /// Imports a file with station data. - static int readStationFile(const std::string &path, - std::string &name, + static int readStationFile(const std::string& path, + std::string& name, std::vector* stations, GEOLIB::Station::StationType type); /// Writes a file that contains all stratigraphies for the boreholes in the given vector. - static void writeStratigraphyTable(const std::vector* boreholes, - const std::string &filename); + static void writeStratigraphyTable(const std::vector* boreholes, const std::string& filename); private: }; diff --git a/FileIO/Writer.cpp b/FileIO/Writer.cpp index a581847ff..7fd656c55 100644 --- a/FileIO/Writer.cpp +++ b/FileIO/Writer.cpp @@ -17,7 +17,6 @@ namespace FileIO { - Writer::Writer() { } @@ -40,12 +39,13 @@ int Writer::writeToFile(std::string const& filename) if (!file_content.empty()) { std::ofstream fileStream; - fileStream.open (filename.c_str()); + fileStream.open(filename.c_str()); // check file stream if (!fileStream) { - std::cerr << "Could not open file " << filename << " !" << "\n"; + std::cerr << "Could not open file " << filename << " !" + << "\n"; return 0; } diff --git a/FileIO/Writer.h b/FileIO/Writer.h index 8282f124a..68975a415 100644 --- a/FileIO/Writer.h +++ b/FileIO/Writer.h @@ -17,7 +17,6 @@ namespace FileIO { - /// @brief Base class which enables writing an object to string, stringstream /// or file. Also formatting (precision, scientific notation of decimal values) /// can be set. @@ -27,7 +26,7 @@ class Writer { public: Writer(); - virtual ~Writer() {}; + virtual ~Writer(){}; /// @brief Writes the object to a string. std::string writeToString(); @@ -50,7 +49,6 @@ class Writer std::stringstream _out; private: - }; } // namespace FileIO diff --git a/FileIO/XmlIO/RapidXMLInterface.cpp b/FileIO/XmlIO/RapidXMLInterface.cpp index 00b9bbcbb..f020b5089 100644 --- a/FileIO/XmlIO/RapidXMLInterface.cpp +++ b/FileIO/XmlIO/RapidXMLInterface.cpp @@ -8,7 +8,7 @@ * http://www.opengeosys.org/project/license */ -//RapidXML +// RapidXML #include "RapidXMLInterface.h" #include @@ -17,14 +17,14 @@ namespace FileIO { - -std::vector *RapidXMLInterface::readStationFile(const std::string &fileName) +std::vector* RapidXMLInterface::readStationFile(const std::string& fileName) { - std::vector *stations = new std::vector; + std::vector* stations = new std::vector; std::ifstream in(fileName.c_str()); if (in.fail()) { - std::cout << "XmlStnInterface::rapidReadFile() - Can't open xml-file." << "\n"; + std::cout << "XmlStnInterface::rapidReadFile() - Can't open xml-file." + << "\n"; return NULL; } @@ -32,7 +32,7 @@ std::vector *RapidXMLInterface::readStationFile(const std::strin in.seekg(0, std::ios::end); size_t length = in.tellg(); in.seekg(0, std::ios::beg); - char* buffer = new char[length+1]; + char* buffer = new char[length + 1]; in.read(buffer, length); buffer[in.gcount()] = '\0'; in.close(); @@ -44,17 +44,20 @@ std::vector *RapidXMLInterface::readStationFile(const std::strin // parse content if (std::string(doc.first_node()->name()).compare("OpenGeoSysSTN")) { - std::cout << "XmlStnInterface::readFile() - Unexpected XML root." << "\n"; + std::cout << "XmlStnInterface::readFile() - Unexpected XML root." + << "\n"; return NULL; } // iterate over all station lists - for (rapidxml::xml_node<>* station_list = doc.first_node()->first_node(); station_list; station_list = station_list->next_sibling()) + for (rapidxml::xml_node<>* station_list = doc.first_node()->first_node(); station_list; + station_list = station_list->next_sibling()) { std::string stnName("[NN]"); stnName = station_list->first_node("name")->value(); - for (rapidxml::xml_node<>* list_item = station_list->first_node(); list_item; list_item = list_item->next_sibling()) + for (rapidxml::xml_node<>* list_item = station_list->first_node(); list_item; + list_item = list_item->next_sibling()) { std::string b(list_item->name()); if (std::string(list_item->name()).compare("stations") == 0) @@ -65,75 +68,81 @@ std::vector *RapidXMLInterface::readStationFile(const std::strin } doc.clear(); - delete [] buffer; + delete[] buffer; return stations; } /* int RapidXMLInterface::rapidReadFile(const std::string &fileName) { - GEOLIB::GEOObjects* geoObjects = _project->getGEOObjects(); - - std::ifstream in(fileName.c_str()); - if (in.fail()) - { - std::cout << "XmlStnInterface::rapidReadFile() - Can't open xml-file." << "\n"; - return 0; - } - - // buffer file - in.seekg(0, std::ios::end); - size_t length = in.tellg(); - in.seekg(0, std::ios::beg); - char* buffer = new char[length+1]; - in.read(buffer, length); - buffer[in.gcount()] = '\0'; - in.close(); - - // build DOM tree - rapidxml::xml_document<> doc; - doc.parse<0>(buffer); - - // parse content - if (std::string(doc.first_node()->name()).compare("OpenGeoSysSTN")) - { - std::cout << "XmlStnInterface::readFile() - Unexpected XML root." << "\n"; - return 0; - } - - // iterate over all station lists - for (rapidxml::xml_node<>* station_list = doc.first_node()->first_node(); station_list; station_list = station_list->next_sibling()) - { - std::vector* stations = new std::vector; - std::string stnName("[NN]"); - - stnName = station_list->first_node("name")->value(); - for (rapidxml::xml_node<>* list_item = station_list->first_node(); list_item; list_item = list_item->next_sibling()) - { - std::string b(list_item->name()); - if (std::string(list_item->name()).compare("stations") == 0) - XmlStnInterface::rapidReadStations(list_item, stations, fileName); - if (std::string(list_item->name()).compare("boreholes") == 0) - XmlStnInterface::rapidReadStations(list_item, stations, fileName); - } - - if (!stations->empty()) - geoObjects->addStationVec(stations, stnName); - else - delete stations; - } - - doc.clear(); - delete [] buffer; - - return 1; + GEOLIB::GEOObjects* geoObjects = _project->getGEOObjects(); + + std::ifstream in(fileName.c_str()); + if (in.fail()) + { + std::cout << "XmlStnInterface::rapidReadFile() - Can't open xml-file." << "\n"; + return 0; + } + + // buffer file + in.seekg(0, std::ios::end); + size_t length = in.tellg(); + in.seekg(0, std::ios::beg); + char* buffer = new char[length+1]; + in.read(buffer, length); + buffer[in.gcount()] = '\0'; + in.close(); + + // build DOM tree + rapidxml::xml_document<> doc; + doc.parse<0>(buffer); + + // parse content + if (std::string(doc.first_node()->name()).compare("OpenGeoSysSTN")) + { + std::cout << "XmlStnInterface::readFile() - Unexpected XML root." << "\n"; + return 0; + } + + // iterate over all station lists + for (rapidxml::xml_node<>* station_list = doc.first_node()->first_node(); station_list; station_list = +station_list->next_sibling()) + { + std::vector* stations = new std::vector; + std::string stnName("[NN]"); + + stnName = station_list->first_node("name")->value(); + for (rapidxml::xml_node<>* list_item = station_list->first_node(); list_item; list_item = +list_item->next_sibling()) + { + std::string b(list_item->name()); + if (std::string(list_item->name()).compare("stations") == 0) + XmlStnInterface::rapidReadStations(list_item, stations, fileName); + if (std::string(list_item->name()).compare("boreholes") == 0) + XmlStnInterface::rapidReadStations(list_item, stations, fileName); + } + + if (!stations->empty()) + geoObjects->addStationVec(stations, stnName); + else + delete stations; + } + + doc.clear(); + delete [] buffer; + + return 1; } */ -void RapidXMLInterface::readStations(const rapidxml::xml_node<>* station_root, std::vector *stations, const std::string &file_name) +void RapidXMLInterface::readStations(const rapidxml::xml_node<>* station_root, + std::vector* stations, + const std::string& file_name) { - for (rapidxml::xml_node<>* station_node = station_root->first_node(); station_node; station_node = station_node->next_sibling()) + for (rapidxml::xml_node<>* station_node = station_root->first_node(); station_node; + station_node = station_node->next_sibling()) { - if (station_node->first_attribute("id") && station_node->first_attribute("x") && station_node->first_attribute("y")) + if (station_node->first_attribute("id") && station_node->first_attribute("x") + && station_node->first_attribute("y")) { double zVal(0.0); if (station_node->first_attribute("z")) @@ -151,11 +160,10 @@ void RapidXMLInterface::readStations(const rapidxml::xml_node<>* station_root, s if (std::string(station_node->name()).compare("station") == 0) { - GEOLIB::Station* s = new GEOLIB::Station( - strtod(station_node->first_attribute("x")->value(), 0), - strtod(station_node->first_attribute("y")->value(), 0), - zVal, - station_name); + GEOLIB::Station* s = new GEOLIB::Station(strtod(station_node->first_attribute("x")->value(), 0), + strtod(station_node->first_attribute("y")->value(), 0), + zVal, + station_name); s->setStationValue(station_value); if (!sensor_data_file_name.empty()) s->addSensorDataFromCSV(BaseLib::copyPathToFileName(sensor_data_file_name, file_name)); @@ -169,58 +177,61 @@ void RapidXMLInterface::readStations(const rapidxml::xml_node<>* station_root, s bdate_str = station_node->first_node("bdate")->value(); /* add other borehole features here */ - GEOLIB::StationBorehole* s = GEOLIB::StationBorehole::createStation( - station_name, - strtod(station_node->first_attribute("x")->value(), 0), - strtod(station_node->first_attribute("y")->value(), 0), - zVal, - borehole_depth, - bdate_str); + GEOLIB::StationBorehole* s + = GEOLIB::StationBorehole::createStation(station_name, + strtod(station_node->first_attribute("x")->value(), 0), + strtod(station_node->first_attribute("y")->value(), 0), + zVal, + borehole_depth, + bdate_str); s->setStationValue(station_value); if (station_node->first_node("strat")) RapidXMLInterface::readStratigraphy(station_node->first_node("strat"), s); stations->push_back(s); - } } else - std::cout << "XmlStnInterface::rapidReadStations() - Attribute missing in tag ..." << "\n"; + std::cout << "XmlStnInterface::rapidReadStations() - Attribute missing in tag ..." + << "\n"; } } -void RapidXMLInterface::readStratigraphy( const rapidxml::xml_node<>* strat_root, GEOLIB::StationBorehole* borehole ) +void RapidXMLInterface::readStratigraphy(const rapidxml::xml_node<>* strat_root, GEOLIB::StationBorehole* borehole) { double depth_check((*borehole)[2]); - for (rapidxml::xml_node<>* horizon_node = strat_root->first_node("horizon"); horizon_node; horizon_node = horizon_node->next_sibling()) + for (rapidxml::xml_node<>* horizon_node = strat_root->first_node("horizon"); horizon_node; + horizon_node = horizon_node->next_sibling()) { - if (horizon_node->first_attribute("id") && horizon_node->first_attribute("x") && - horizon_node->first_attribute("y") && horizon_node->first_attribute("z")) + if (horizon_node->first_attribute("id") && horizon_node->first_attribute("x") + && horizon_node->first_attribute("y") + && horizon_node->first_attribute("z")) { std::string horizon_name("[NN]"); if (horizon_node->first_node("name")) horizon_name = horizon_node->first_node("name")->value(); /* add other horizon features here */ - double depth (strtod(horizon_node->first_attribute("z")->value(), 0)); - if (fabs(depth - depth_check) > std::numeric_limits::epsilon()) // skip soil-layer if its thickness is zero + double depth(strtod(horizon_node->first_attribute("z")->value(), 0)); + if (fabs(depth - depth_check) + > std::numeric_limits::epsilon()) // skip soil-layer if its thickness is zero { borehole->addSoilLayer(strtod(horizon_node->first_attribute("x")->value(), 0), - strtod(horizon_node->first_attribute("y")->value(), 0), - depth, - horizon_name); + strtod(horizon_node->first_attribute("y")->value(), 0), + depth, + horizon_name); depth_check = depth; } else - std::cout << "Warning: Skipped layer \"" << horizon_name << "\" in borehole \"" - << borehole->getName() << "\" because of thickness 0.0." << "\n"; + std::cout << "Warning: Skipped layer \"" << horizon_name << "\" in borehole \"" << borehole->getName() + << "\" because of thickness 0.0." + << "\n"; } else - std::cout << - "XmlStnInterface::rapidReadStratigraphy() - Attribute missing in tag ..." << "\n"; + std::cout << "XmlStnInterface::rapidReadStratigraphy() - Attribute missing in tag ..." + << "\n"; } } - } diff --git a/FileIO/XmlIO/RapidXMLInterface.h b/FileIO/XmlIO/RapidXMLInterface.h index a242fbf9d..1bf2ed5b5 100644 --- a/FileIO/XmlIO/RapidXMLInterface.h +++ b/FileIO/XmlIO/RapidXMLInterface.h @@ -16,31 +16,32 @@ #include "Point.h" -namespace GEOLIB { - class StationBorehole; +namespace GEOLIB +{ +class StationBorehole; } namespace FileIO { - /** * \brief Base class for writing any information to and from XML files. */ class RapidXMLInterface { public: - /// Reads an xml-file using the RapidXML parser integrated in the source code (i.e. this function is usable without Qt) - //int rapidReadFile(const std::string &fileName); - static std::vector *readStationFile(const std::string &fileName); + /// Reads an xml-file using the RapidXML parser integrated in the source code (i.e. this function is usable without + /// Qt) + // int rapidReadFile(const std::string &fileName); + static std::vector* readStationFile(const std::string& fileName); private: /// Reads GEOLIB::Station- or StationBorehole-objects from an xml-file using the RapidXML parser - static void readStations(const rapidxml::xml_node<>* station_root, std::vector *stations, const std::string &file_name); + static void readStations(const rapidxml::xml_node<>* station_root, std::vector* stations, + const std::string& file_name); /// Reads the stratigraphy of a borehole from an xml-file using the RapidXML parser static void readStratigraphy(const rapidxml::xml_node<>* strat_root, GEOLIB::StationBorehole* borehole); }; - } #endif // RAPIDXMLINTERFACE_H diff --git a/FileIO/readNonBlankLineFromInputStream.cpp b/FileIO/readNonBlankLineFromInputStream.cpp index 621aed6fe..440d86815 100644 --- a/FileIO/readNonBlankLineFromInputStream.cpp +++ b/FileIO/readNonBlankLineFromInputStream.cpp @@ -12,11 +12,11 @@ #include "readNonBlankLineFromInputStream.h" -std::string readNonBlankLineFromInputStream(std::istream & in) +std::string readNonBlankLineFromInputStream(std::istream& in) { std::string line; - bool not_finished (true); + bool not_finished(true); while (not_finished) { // read line @@ -24,9 +24,9 @@ std::string readNonBlankLineFromInputStream(std::istream & in) if (!in.fail()) { // skip initial space characters - std::string::size_type i (line.find_first_not_of(" ", 0)); + std::string::size_type i(line.find_first_not_of(" ", 0)); // search comment symbol ; - std::string::size_type j (line.find(";", i)); + std::string::size_type j(line.find(";", i)); if (j == i) // first non space character is equal to the comment symbol not_finished = true; else diff --git a/FileIO/readNonBlankLineFromInputStream.h b/FileIO/readNonBlankLineFromInputStream.h index 442e56c00..fd512677c 100644 --- a/FileIO/readNonBlankLineFromInputStream.h +++ b/FileIO/readNonBlankLineFromInputStream.h @@ -21,6 +21,6 @@ * @param in the input stream * @return read line into a string */ -std::string readNonBlankLineFromInputStream(std::istream & in); +std::string readNonBlankLineFromInputStream(std::istream& in); #endif /* READNONBLANKLINEFROMINPUTSTREAM_H_ */ diff --git a/GCC/Density.cpp b/GCC/Density.cpp index fa48648ca..2945df944 100644 --- a/GCC/Density.cpp +++ b/GCC/Density.cpp @@ -16,314 +16,466 @@ #include "Density.h" using namespace std; - double density::Ds, density::Vs; -density::density(void){} -density::~density(void){} - - - - -void density::MaoModel(double T, double P, double m, int f){ - - double R=83.14472, N0=6.0221367E+23, pai=3.14159265, qe=1.60217733E-19, kB=1.380658E-23, D0=8.85418781762E-12; - double dP=1.0e-2, dH2O, dH2Oa, dH2Ob, Av, D1000, C, B, DD; - - dH2O =IF97::density(T,P/10.0); - dH2Oa=IF97::density(T,(P-dP)/10.0); - dH2Ob=IF97::density(T,(P+dP)/10.0); - - const double U[10]= - { 0.0, 3.4279e+2, -5.0866e-3, 9.4690e-7, -2.0525, 3.1159e+3, -1.8289e+2, -8.0325e+3, 4.2142e+6, 2.1417 }; - D1000 = U[1]*exp(U[2]*T + U[3]*T*T); - C = U[4]+U[5]/(U[6]+T); - B = U[7]+U[8]/T+U[9]*T; - DD= D1000+C*log((B+P)/(B+1000)); - - //Aphia = 1.0/3.0*pow(2.0*pai*N0*dH2Oa,0.5) * pow(qe*qe/(4.0*pai*D0*Da*kB*T),1.5); - //Aphib = 1.0/3.0*pow(2.0*pai*N0*dH2Ob,0.5) * pow(qe*qe/(4.0*pai*D0*Db*kB*T),1.5); - //Av = -2.0*R*T*(Aphib-Aphia)/dP/10.0; - Av= -4.0*R*T /3.0* pow(2.0*pai*N0,0.5) * pow(qe*qe/(4.0*pai*D0*kB*T),1.5) - *(pow(dH2O,0.5)*(-1.5*pow(DD,-2.5)*C/(B+P))+pow(DD,-1.5)*0.5*pow(dH2O,-0.5)*(dH2Ob-dH2Oa)/(2.0*dP)); - //cout << " Av---- " << Av << endl; - - const double c[7][24]={ - {0.0, 1.17271480E+03, 1.40527916E-01, -5.53962649E-04, 1.72402126E-06, -1.57184556E-01, 8.89959461E-04, - -1.52090064E-06, 0.0, 7.33553879E-04, 4.06701494E-05, -2.38873863E-07, 3.94900863E-10, - -3.56131664E-03, -6.18472877E-07, 3.00484214E-08, -1.02229075E-10, 0.0, 2.35592818E-06, - -2.68117086E-05, -2.17228726E-06, 1.19732313E-08, -1.51104808E-11, 3.83403994E-05}, - {0.0, 1.06607098E+03, -8.39622456E-03, 5.35429127E-04, 7.55373789E-07, -4.19512335E-02, 1.45082899E-04, - -3.47807732E-07, 0.0, 1.10913788E-03, 1.14498252E-04, -5.51181270E-07, 7.05483955E-10, - -5.05734723E-03, -1.32747828E-06, 4.77261581E-08, -1.76888377E-10, 0.0, 6.40541237E-06, - 3.07698827E-05, -1.64042763E-05, 7.06784935E-08, -6.50338372E-11, -4.50906014E-05}, - {0.0, 2.90812061E+02, 6.54111195E+00, -1.61831978E-02, 1.46280384E-05, 1.41397987E+00, -1.07266230E-02, - 2.64506021E-05, -2.19789708E-08, 3.02182158E-03, -2.15621394E-04, 9.24163206E-07, -1.10089434E-09, - 2.87018859E-03, -6.73119697E-06, 1.68332473E-06, -7.99645640E-09, 1.11881560E-11, -6.59292385E-05, - -2.02369103E-04, -1.70609099E-05, 1.00510108E-07, -1.86624642E-10, 1.91919166E-03}, - {0.0, 1.18880927E+03, -1.43194546E+00, 3.87973220E-03, -2.20330377E-06, 6.38745038E-01, -5.51728055E-03, - 1.50231562E-05, -1.35757912E-08, 8.43627549E-04, 5.25365072E-04, -1.87204100E-06, 4.20263897E-09, - -1.18062548E-01, 6.07424747E-06, -1.20268210E-06, 5.23784551E-09, -8.23940319E-12, 9.75167613E-05, - -4.92959181E-05, -2.73642775E-05, 5.42602386E-08, -1.95602825E-10, 1.00921935E-02}, - {0.0, 1.12080057E+03, -2.61669538E-01, 1.52042960E-03, -6.89131095E-07, -5.11802652E-02, 2.22234857E-04, - -5.66464544E-07, 2.92950266E-10, 2.43934633E-03, -1.42746873E-04, 7.35840529E-07, -9.43615480E-10, - -5.18606814E-03, -6.16536928E-07, -1.04523561E-07, 4.52637296E-10, -1.05076158E-12, 2.31544709E-05, - -1.09663211E-04, 1.90836111E-05, -9.25997994E-08, 1.54388261E-10, -1.29354832E-03}, - {0.0, 1.11894213E+03, -7.37321458E-01, 1.77908655E-03, 0.0, 0.0, 0.0, - 0.0, 0.0, 2.21225680E-03, 6.62517291E-05, -2.37296050E-07, 0.0, - 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, - -4.21300430E-04, 0.0, 9.46738388E-09, 0.0, 0.0}, - {0.0, 1.10229139E+03, -7.53497776E-01, 1.92829036E-03, 0.0, 0.0, -1.15406910E-04, - 0.0, 0.0, 2.57437715E-03, 1.64541676E-05, -9.30035886E-08, 0.0, - 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0, 0.0}, +density::density(void) +{ +} +density::~density(void) +{ +} + +void density::MaoModel(double T, double P, double m, int f) +{ + double R = 83.14472, N0 = 6.0221367E+23, pai = 3.14159265, qe = 1.60217733E-19, kB = 1.380658E-23, + D0 = 8.85418781762E-12; + double dP = 1.0e-2, dH2O, dH2Oa, dH2Ob, Av, D1000, C, B, DD; + + dH2O = IF97::density(T, P / 10.0); + dH2Oa = IF97::density(T, (P - dP) / 10.0); + dH2Ob = IF97::density(T, (P + dP) / 10.0); + + const double U[10] + = {0.0, 3.4279e+2, -5.0866e-3, 9.4690e-7, -2.0525, 3.1159e+3, -1.8289e+2, -8.0325e+3, 4.2142e+6, 2.1417}; + D1000 = U[1] * exp(U[2] * T + U[3] * T * T); + C = U[4] + U[5] / (U[6] + T); + B = U[7] + U[8] / T + U[9] * T; + DD = D1000 + C * log((B + P) / (B + 1000)); + + // Aphia = 1.0/3.0*pow(2.0*pai*N0*dH2Oa,0.5) * pow(qe*qe/(4.0*pai*D0*Da*kB*T),1.5); + // Aphib = 1.0/3.0*pow(2.0*pai*N0*dH2Ob,0.5) * pow(qe*qe/(4.0*pai*D0*Db*kB*T),1.5); + // Av = -2.0*R*T*(Aphib-Aphia)/dP/10.0; + Av = -4.0 * R * T / 3.0 * pow(2.0 * pai * N0, 0.5) * pow(qe * qe / (4.0 * pai * D0 * kB * T), 1.5) + * (pow(dH2O, 0.5) * (-1.5 * pow(DD, -2.5) * C / (B + P)) + + pow(DD, -1.5) * 0.5 * pow(dH2O, -0.5) * (dH2Ob - dH2Oa) / (2.0 * dP)); + // cout << " Av---- " << Av << endl; + + const double c[7][24] = { + {0.0, + 1.17271480E+03, + 1.40527916E-01, + -5.53962649E-04, + 1.72402126E-06, + -1.57184556E-01, + 8.89959461E-04, + -1.52090064E-06, + 0.0, + 7.33553879E-04, + 4.06701494E-05, + -2.38873863E-07, + 3.94900863E-10, + -3.56131664E-03, + -6.18472877E-07, + 3.00484214E-08, + -1.02229075E-10, + 0.0, + 2.35592818E-06, + -2.68117086E-05, + -2.17228726E-06, + 1.19732313E-08, + -1.51104808E-11, + 3.83403994E-05}, + {0.0, + 1.06607098E+03, + -8.39622456E-03, + 5.35429127E-04, + 7.55373789E-07, + -4.19512335E-02, + 1.45082899E-04, + -3.47807732E-07, + 0.0, + 1.10913788E-03, + 1.14498252E-04, + -5.51181270E-07, + 7.05483955E-10, + -5.05734723E-03, + -1.32747828E-06, + 4.77261581E-08, + -1.76888377E-10, + 0.0, + 6.40541237E-06, + 3.07698827E-05, + -1.64042763E-05, + 7.06784935E-08, + -6.50338372E-11, + -4.50906014E-05}, + {0.0, + 2.90812061E+02, + 6.54111195E+00, + -1.61831978E-02, + 1.46280384E-05, + 1.41397987E+00, + -1.07266230E-02, + 2.64506021E-05, + -2.19789708E-08, + 3.02182158E-03, + -2.15621394E-04, + 9.24163206E-07, + -1.10089434E-09, + 2.87018859E-03, + -6.73119697E-06, + 1.68332473E-06, + -7.99645640E-09, + 1.11881560E-11, + -6.59292385E-05, + -2.02369103E-04, + -1.70609099E-05, + 1.00510108E-07, + -1.86624642E-10, + 1.91919166E-03}, + {0.0, + 1.18880927E+03, + -1.43194546E+00, + 3.87973220E-03, + -2.20330377E-06, + 6.38745038E-01, + -5.51728055E-03, + 1.50231562E-05, + -1.35757912E-08, + 8.43627549E-04, + 5.25365072E-04, + -1.87204100E-06, + 4.20263897E-09, + -1.18062548E-01, + 6.07424747E-06, + -1.20268210E-06, + 5.23784551E-09, + -8.23940319E-12, + 9.75167613E-05, + -4.92959181E-05, + -2.73642775E-05, + 5.42602386E-08, + -1.95602825E-10, + 1.00921935E-02}, + {0.0, + 1.12080057E+03, + -2.61669538E-01, + 1.52042960E-03, + -6.89131095E-07, + -5.11802652E-02, + 2.22234857E-04, + -5.66464544E-07, + 2.92950266E-10, + 2.43934633E-03, + -1.42746873E-04, + 7.35840529E-07, + -9.43615480E-10, + -5.18606814E-03, + -6.16536928E-07, + -1.04523561E-07, + 4.52637296E-10, + -1.05076158E-12, + 2.31544709E-05, + -1.09663211E-04, + 1.90836111E-05, + -9.25997994E-08, + 1.54388261E-10, + -1.29354832E-03}, + {0.0, + 1.11894213E+03, + -7.37321458E-01, + 1.77908655E-03, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 2.21225680E-03, + 6.62517291E-05, + -2.37296050E-07, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + -4.21300430E-04, + 0.0, + 9.46738388E-09, + 0.0, + 0.0}, + {0.0, + 1.10229139E+03, + -7.53497776E-01, + 1.92829036E-03, + 0.0, + 0.0, + -1.15406910E-04, + 0.0, + 0.0, + 2.57437715E-03, + 1.64541676E-05, + -9.30035886E-08, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0}, }; - const double mr[7]={ 10.0,6.0,6.0,2.0,5.0,2.0,1.5 }; - const double Ms[7]={ 42.394, 58.443, 74.551, 95.236, 110.986, 158.536, 206.286 }; + const double mr[7] = {10.0, 6.0, 6.0, 2.0, 5.0, 2.0, 1.5}; + const double Ms[7] = {42.394, 58.443, 74.551, 95.236, 110.986, 158.536, 206.286}; double Imx, Imrx, hIx, hIrx, CA, CB, CC; - if(f==0 || f==1 || f==2){ + if (f == 0 || f == 1 || f == 2) + { Imx = m; - Imrx= mr[f]; - CA=2.0; - CB=2.0; - CC=2.0; + Imrx = mr[f]; + CA = 2.0; + CB = 2.0; + CC = 2.0; } - else { - Imx = 3.0*m; - Imrx= 3.0*mr[f]; - CA=6.0; - CB=4.0; - CC=8.0; + else + { + Imx = 3.0 * m; + Imrx = 3.0 * mr[f]; + CA = 6.0; + CB = 4.0; + CC = 8.0; } - hIx =log(1.0+1.2*pow(Imx,0.5) )/(2.0*1.2); - hIrx=log(1.0+1.2*pow(Imrx,0.5))/(2.0*1.2); - - if(m==0) density::Ds=dH2O/1000.0; - else density::Ds= - (1000+m*Ms[f])/m/ ((1/m-1/mr[f])*1.0e6/dH2O + CA*Av*( hIx-hIrx ) - +1.0/mr[f]*(c[f][1]+c[f][2]*T+c[f][3]*pow(T,2.0)+c[f][4]*pow(T,3.0) - +P*(c[f][5]+c[f][6]*T+c[f][7]*pow(T,2.0)+c[f][8]*pow(T,3.0))) - +CB*R*T*(m-mr[f])*(c[f][9]/(T-227.0)+c[f][10]+c[f][11]*T - +c[f][12]*pow(T,2.0)+c[f][13]/(647.0-T)+P*(c[f][14]/(T-227.0)+c[f][15]+c[f][16]*T - +c[f][17]*pow(T,2.0)+c[f][18]/(647-T))) - +CC*R*T*(m*m-pow(mr[f],2.0))*(c[f][19]/(T-227.0)+c[f][20]+c[f][21]*T - +c[f][22]*pow(T,2.0) + c[f][23]/(647.0-T))); - density::Vs= - 1.0/mr[f]*(c[f][1]+c[f][2]*T+c[f][3]*pow(T,2.0)+c[f][4]*pow(T,3.0) - + P*(c[f][5]+c[f][6]*T+c[f][7]*pow(T,2.0)+c[f][8]*pow(T,3.0))) - - 1.0e6/mr[f]/dH2O-CA*Av*hIrx - -CB*R*T*mr[f]*(c[f][9] /(T-227.0)+c[f][10]+c[f][11]*T+c[f][12]*pow(T,2.0)+c[f][13]/(647.0-T) - +P*(c[f][14]/(T-227.0)+c[f][15]+c[f][16]*T+c[f][17]*pow(T,2.0)+c[f][18]/(647.0-T))) - -CC*R*T*pow(mr[f],2.0)*(c[f][19]/(T-227.0)+c[f][20]+c[f][21]*T+c[f][22]*pow(T,2.0)+c[f][23]/(647.0-T)); - - + hIx = log(1.0 + 1.2 * pow(Imx, 0.5)) / (2.0 * 1.2); + hIrx = log(1.0 + 1.2 * pow(Imrx, 0.5)) / (2.0 * 1.2); + + if (m == 0) + density::Ds = dH2O / 1000.0; + else + density::Ds = (1000 + m * Ms[f]) / m + / ((1 / m - 1 / mr[f]) * 1.0e6 / dH2O + CA * Av * (hIx - hIrx) + + 1.0 / mr[f] * (c[f][1] + c[f][2] * T + c[f][3] * pow(T, 2.0) + c[f][4] * pow(T, 3.0) + + P * (c[f][5] + c[f][6] * T + c[f][7] * pow(T, 2.0) + c[f][8] * pow(T, 3.0))) + + CB * R * T * (m - mr[f]) + * (c[f][9] / (T - 227.0) + c[f][10] + c[f][11] * T + c[f][12] * pow(T, 2.0) + + c[f][13] / (647.0 - T) + + P * (c[f][14] / (T - 227.0) + c[f][15] + c[f][16] * T + c[f][17] * pow(T, 2.0) + + c[f][18] / (647 - T))) + + CC * R * T * (m * m - pow(mr[f], 2.0)) + * (c[f][19] / (T - 227.0) + c[f][20] + c[f][21] * T + c[f][22] * pow(T, 2.0) + + c[f][23] / (647.0 - T))); + density::Vs + = 1.0 / mr[f] * (c[f][1] + c[f][2] * T + c[f][3] * pow(T, 2.0) + c[f][4] * pow(T, 3.0) + + P * (c[f][5] + c[f][6] * T + c[f][7] * pow(T, 2.0) + c[f][8] * pow(T, 3.0))) + - 1.0e6 / mr[f] / dH2O - CA * Av * hIrx + - CB * R * T * mr[f] + * (c[f][9] / (T - 227.0) + c[f][10] + c[f][11] * T + c[f][12] * pow(T, 2.0) + c[f][13] / (647.0 - T) + + P * (c[f][14] / (T - 227.0) + c[f][15] + c[f][16] * T + c[f][17] * pow(T, 2.0) + + c[f][18] / (647.0 - T))) + - CC * R * T * pow(mr[f], 2.0) + * (c[f][19] / (T - 227.0) + c[f][20] + c[f][21] * T + c[f][22] * pow(T, 2.0) + c[f][23] / (647.0 - T)); } -double density::MultiDensity(double T, double P, vector mv, vector fv){ - - const double Ms[7]={ 42.394, 58.443, 74.551, 95.236, 110.986, 158.536, 206.286 }; - double mz=0,mc=0,mc0=0,Mt=1000.0,Vt=0,Vex,Vw; - int i,fr=1,n=(int)fv.size(); - - density::MaoModel(T,P,0.0,0); - Vw=1000.0/density::Ds; - Vt=Vw; - - for(i=0;imc0) fr=fv[i]; - mc0=mc; - mz+=mc; - Mt+=mv[i]*Ms[fv[i]]; - density::MaoModel(T,P,mv[i],fv[i]); - //cout << " Ds " << tdensity::Ds << endl; - Vt+=mv[i]*density::Vs; +double density::MultiDensity(double T, double P, vector mv, vector fv) +{ + const double Ms[7] = {42.394, 58.443, 74.551, 95.236, 110.986, 158.536, 206.286}; + double mz = 0, mc = 0, mc0 = 0, Mt = 1000.0, Vt = 0, Vex, Vw; + int i, fr = 1, n = (int)fv.size(); + + density::MaoModel(T, P, 0.0, 0); + Vw = 1000.0 / density::Ds; + Vt = Vw; + + for (i = 0; i < n; i++) + { + if (fv[i] == 0 || fv[i] == 1 || fv[i] == 2) + mc = mv[i]; + else + mc = 3.0 * mv[i]; + if (mc > mc0) + fr = fv[i]; + mc0 = mc; + mz += mc; + Mt += mv[i] * Ms[fv[i]]; + density::MaoModel(T, P, mv[i], fv[i]); + // cout << " Ds " << tdensity::Ds << endl; + Vt += mv[i] * density::Vs; } - if(fr!=0 && fr!=1 && fr!=2) mz /=3.0; - density::MaoModel(T,P,mz,fr); - Vex=(1000.0+mz*Ms[fr])/density::Ds - Vw - mz*density::Vs; - Vt+=Vex; - return Mt/Vt; + if (fr != 0 && fr != 1 && fr != 2) + mz /= 3.0; + density::MaoModel(T, P, mz, fr); + Vex = (1000.0 + mz * Ms[fr]) / density::Ds - Vw - mz * density::Vs; + Vt += Vex; + return Mt / Vt; } - - -double density::ExcessM(double mv[]){ - - double mex=0.0; +double density::ExcessM(double mv[]) +{ + double mex = 0.0; mex += mv[0]; mex += mv[1]; mex += mv[2]; - mex += 3.0*mv[3]; - mex += 3.0*mv[4]; + mex += 3.0 * mv[3]; + mex += 3.0 * mv[4]; mex += mv[5]; - mex += 3.0*mv[6]; - mex += 3.0*mv[7]; - return 0.5*mex; + mex += 3.0 * mv[6]; + mex += 3.0 * mv[7]; + return 0.5 * mex; } - -double density::Multi_density(double T, double P, double mv[]){ - +double density::Multi_density(double T, double P, double mv[]) +{ double Vs[8]; - const double Ms[8]={ 6.941, 22.990, 39.098, 24.305, 40.080, 35.453, 96.058, 60.009 }; //moleculer weight - double Mt=1000.0,Vt=0,Vex,Vw,mex; + const double Ms[8] = {6.941, 22.990, 39.098, 24.305, 40.080, 35.453, 96.058, 60.009}; // moleculer weight + double Mt = 1000.0, Vt = 0, Vex, Vw, mex; int i; - //0-Li, 1-Na, 2-K, 3-Mg, 4-Ca, 5-Cl, 6-SO4, 7-CO3 - //calc Partial Moler Volume - //ref solute KCl, set Vs_K = Vs_Cl - density::MaoModel(T,P,0.0,2); - Vs[2]=0.5*density::Vs; - Vs[5]=0.5*density::Vs; - - //Vs_Li = Vs_LiCl - Vs_Cl - density::MaoModel(T,P,0.0,0); - Vs[0]=density::Vs-Vs[5]; - - //Vs_Na - density::MaoModel(T,P,0.0,1); - Vs[1]=density::Vs-Vs[5]; + // 0-Li, 1-Na, 2-K, 3-Mg, 4-Ca, 5-Cl, 6-SO4, 7-CO3 + // calc Partial Moler Volume + // ref solute KCl, set Vs_K = Vs_Cl + density::MaoModel(T, P, 0.0, 2); + Vs[2] = 0.5 * density::Vs; + Vs[5] = 0.5 * density::Vs; + // Vs_Li = Vs_LiCl - Vs_Cl + density::MaoModel(T, P, 0.0, 0); + Vs[0] = density::Vs - Vs[5]; - //Vs_Mg = Vs_Na - Vs[3]=Vs[1]; + // Vs_Na + density::MaoModel(T, P, 0.0, 1); + Vs[1] = density::Vs - Vs[5]; - //Vs_Ca = Vs_K - Vs[4]=Vs[2]; + // Vs_Mg = Vs_Na + Vs[3] = Vs[1]; - Vs[6]=1.5*Vs[5]; - Vs[7]=1.5*Vs[5]; + // Vs_Ca = Vs_K + Vs[4] = Vs[2]; + Vs[6] = 1.5 * Vs[5]; + Vs[7] = 1.5 * Vs[5]; //========= - density::MaoModel(T,P,0.0,0); - Vw=1000.0/density::Ds; - Vt=Vw; + density::MaoModel(T, P, 0.0, 0); + Vw = 1000.0 / density::Ds; + Vt = Vw; - for(i=0;i<=7;i++){ - Mt+=mv[i]*Ms[i]; - Vt+=mv[i]*Vs[i]; + for (i = 0; i <= 7; i++) + { + Mt += mv[i] * Ms[i]; + Vt += mv[i] * Vs[i]; } - mex=density::ExcessM(mv); - density::MaoModel(T,P,mex,1); - Vex=(1000.0+mex*(Ms[1]+Ms[5]))/density::Ds - Vw - mex*density::Vs; + mex = density::ExcessM(mv); + density::MaoModel(T, P, mex, 1); + Vex = (1000.0 + mex * (Ms[1] + Ms[5])) / density::Ds - Vw - mex * density::Vs; - //cout << endl << mex<< " " << (1000.0+mex*(Ms[1]+Ms[5]))/density::Ds << " " << Vw<< " " << Vex << endl; + // cout << endl << mex<< " " << (1000.0+mex*(Ms[1]+Ms[5]))/density::Ds << " " << Vw<< " " << Vex << endl; - Vt+=Vex; + Vt += Vex; - //cout << " " << Mt << " " << Vt << endl; - - return Mt/Vt; + // cout << " " << Mt << " " << Vt << endl; + return Mt / Vt; } - - - double density::CO2brine(double T, double P, double mNaCl, double mCO2) { - double Ps /*,mTot*/,V2,Dens; + double Ps /*,mTot*/, V2, Dens; - if(mNaCl<0.0 || mNaCl>6.0 || mCO2<0.0){ + if (mNaCl < 0.0 || mNaCl > 6.0 || mCO2 < 0.0) + { Dens = -1.0; goto T01; } - if(T<273.15 || T>573.15 || P<0.001 || P>1000.0){ + if (T < 273.15 || T > 573.15 || P < 0.001 || P > 1000.0) + { Dens = -1.0; goto T01; } - Ps=IF97::Psat(T)*10.0; - if(Ps>P){ - Dens = IF97::density(T,P/10.0)/1000.0; + Ps = IF97::Psat(T) * 10.0; + if (Ps > P) + { + Dens = IF97::density(T, P / 10.0) / 1000.0; cout << " Ps " << endl; goto T01; } // mTot = 55.5084 +mNaCl +mCO2; - density::MaoModel(T, P, mNaCl,1); + density::MaoModel(T, P, mNaCl, 1); - V2 = 18.0153/IF97::density(T,P/10.0)*1000.0* - (1.0 + 0.38384020e-3*T*T - 0.55953850 *T + 0.30429268e3 - 0.72044305e5/T + 0.63003388e7/T/T - + (-0.57709332e-5*T*T + 0.82764653e-2*T - 0.43813556e1 + 0.10144907e4/T - 0.86777045e5/T/T)*P/10.0); + V2 = 18.0153 / IF97::density(T, P / 10.0) * 1000.0 + * (1.0 + 0.38384020e-3 * T * T - 0.55953850 * T + 0.30429268e3 - 0.72044305e5 / T + 0.63003388e7 / T / T + + (-0.57709332e-5 * T * T + 0.82764653e-2 * T - 0.43813556e1 + 0.10144907e4 / T - 0.86777045e5 / T / T) * P + / 10.0); - Dens = (1000.0+58.4428*mNaCl+44.0098*mCO2)/((1000.0+58.4428*mNaCl)/density::Ds+V2*mCO2); + Dens = (1000.0 + 58.4428 * mNaCl + 44.0098 * mCO2) / ((1000.0 + 58.4428 * mNaCl) / density::Ds + V2 * mCO2); T01: return Dens; } - -//0-Li, 1-Na, 2-K, 3-Mg, 4-Ca, 5-Cl, 6-SO4, 7-CO3 +// 0-Li, 1-Na, 2-K, 3-Mg, 4-Ca, 5-Cl, 6-SO4, 7-CO3 double density::CO2_MultiBrine_density(double T, double P, double mv[], double mCO2) { - double Ps,V2,Dens,Dens_B,Mt=1000.0; - const double Ms[8]={ 6.941, 22.990, 39.098, 24.305, 40.080, 35.453, 96.058, 60.009 }; //moleculer weight + double Ps, V2, Dens, Dens_B, Mt = 1000.0; + const double Ms[8] = {6.941, 22.990, 39.098, 24.305, 40.080, 35.453, 96.058, 60.009}; // moleculer weight int i; - Ps=IF97::Psat(T)*10.0; - if(Ps>P){ - Dens = IF97::density(T,P/10.0)/1000.0; + Ps = IF97::Psat(T) * 10.0; + if (Ps > P) + { + Dens = IF97::density(T, P / 10.0) / 1000.0; goto T01; } - Dens_B=density::Multi_density(T,P,mv); - for(i=0;i<=7;i++) - Mt += mv[i]*Ms[i]; + Dens_B = density::Multi_density(T, P, mv); + for (i = 0; i <= 7; i++) + Mt += mv[i] * Ms[i]; - V2 = 18.0153/IF97::density(T,P/10.0)*1000.0* - (1.0 + 0.38384020e-3*T*T - 0.55953850 *T + 0.30429268e3 - 0.72044305e5/T + 0.63003388e7/T/T - + (-0.57709332e-5*T*T + 0.82764653e-2*T - 0.43813556e1 + 0.10144907e4/T - 0.86777045e5/T/T)*P/10.0); + V2 = 18.0153 / IF97::density(T, P / 10.0) * 1000.0 + * (1.0 + 0.38384020e-3 * T * T - 0.55953850 * T + 0.30429268e3 - 0.72044305e5 / T + 0.63003388e7 / T / T + + (-0.57709332e-5 * T * T + 0.82764653e-2 * T - 0.43813556e1 + 0.10144907e4 / T - 0.86777045e5 / T / T) * P + / 10.0); - Dens = (Mt+44.0098*mCO2)/(Mt/Dens_B+V2*mCO2); + Dens = (Mt + 44.0098 * mCO2) / (Mt / Dens_B + V2 * mCO2); T01: return Dens; } - -//0-Li, 1-Na, 2-K, 3-Mg, 4-Ca, 5-Cl, 6-SO4, 7-CO3 -double density::concentration_water(double T, double P, double cv[], double cv_CO2) //unit mol/m3 +// 0-Li, 1-Na, 2-K, 3-Mg, 4-Ca, 5-Cl, 6-SO4, 7-CO3 +double density::concentration_water(double T, double P, double cv[], double cv_CO2) // unit mol/m3 { - const double Ms[8]={ 6.941, 22.990, 39.098, 24.305, 40.080, 35.453, 96.058, 60.009 }; //moleculer weight - double mv[8],mCO2,dens,d0,d1,mass,densx,err=1.0e-4; - int i,ix; - - d0=0.8; - d1=1.5; - - for(ix=0;ix<8;ix++){ - dens=0.5*(d0+d1); //unit g/cm3 - mass=dens*1.0e6; //unit (g) - - for(i=0;i<8;i++) - mass -= cv[i]*Ms[i]; - mass -= cv_CO2*44.01; - - for(i=0;i<8;i++){ - mv[i]= 1000.0*cv[i]/mass; - //cout << mv[i] << " " ; + const double Ms[8] = {6.941, 22.990, 39.098, 24.305, 40.080, 35.453, 96.058, 60.009}; // moleculer weight + double mv[8], mCO2, dens, d0, d1, mass, densx, err = 1.0e-4; + int i, ix; + + d0 = 0.8; + d1 = 1.5; + + for (ix = 0; ix < 8; ix++) + { + dens = 0.5 * (d0 + d1); // unit g/cm3 + mass = dens * 1.0e6; // unit (g) + + for (i = 0; i < 8; i++) + mass -= cv[i] * Ms[i]; + mass -= cv_CO2 * 44.01; + + for (i = 0; i < 8; i++) + { + mv[i] = 1000.0 * cv[i] / mass; + // cout << mv[i] << " " ; } - mCO2= 1000.0*cv_CO2/mass; - //cout << mCO2 << endl; + mCO2 = 1000.0 * cv_CO2 / mass; + // cout << mCO2 << endl; - densx=density::CO2_MultiBrine_density(T,P,mv,mCO2); - //cout << " dens " << dens << " densx " << densx << endl; - if( abs(dens-densx) < err ) + densx = density::CO2_MultiBrine_density(T, P, mv, mCO2); + // cout << " dens " << dens << " densx " << densx << endl; + if (abs(dens - densx) < err) break; - else if(dens>densx) - d1=dens; + else if (dens > densx) + d1 = dens; else - d0=dens; - + d0 = dens; } - return mass/18.015; + return mass / 18.015; } diff --git a/GCC/Density.h b/GCC/Density.h index a434f45fb..5235ff44a 100644 --- a/GCC/Density.h +++ b/GCC/Density.h @@ -9,37 +9,34 @@ #include -//using namespace std; +// using namespace std; -//density of electrolyte +// density of electrolyte class density { private: - public: density(void); ~density(void); -/* Data */ - static double Ds, Vs; //storage of the return density (g/cm^3) & infinite dilution apparent molar volume (cm^3/mol) + /* Data */ + static double Ds, Vs; // storage of the return density (g/cm^3) & infinite dilution apparent molar volume (cm^3/mol) -/* Methods */ + /* Methods */ static void MaoModel(double T, double P, double m, int f); - //T (K), P (bar), m (mol/kg) - //flag 0-LiCl, 1-NaCl, 2-KCl, 3-MgCl2, 4-CaCl2, 5-SrCl2, 6-BaCl2 + // T (K), P (bar), m (mol/kg) + // flag 0-LiCl, 1-NaCl, 2-KCl, 3-MgCl2, 4-CaCl2, 5-SrCl2, 6-BaCl2 static double viscosity(double T, double P, double m, int f); - //T (K), P (bar), m (mol/kg) flag 0-LiCl, 1-NaCl, 2-KCl + // T (K), P (bar), m (mol/kg) flag 0-LiCl, 1-NaCl, 2-KCl - static double MultiDensity(double T, double P, std::vector mv, std::vector fv); //mv-molality fv-flag + static double MultiDensity(double T, double P, std::vector mv, std::vector fv); // mv-molality fv-flag void Interface(void); static double CO2brine(double T, double P, double mNaCl, double mCO2); - - - //0-Li, 1-Na, 2-K, 3-Mg, 4-Ca, 5-Cl, 6-SO4, 7-CO3 - //static void PartialVolume(double T, double P, double &Vs[8]); + // 0-Li, 1-Na, 2-K, 3-Mg, 4-Ca, 5-Cl, 6-SO4, 7-CO3 + // static void PartialVolume(double T, double P, double &Vs[8]); static double ExcessM(double mv[8]); static double Multi_density(double T, double P, double mv[8]); @@ -47,5 +44,4 @@ class density static double concentration_water(double T, double P, double cv[8], double cv_CO2); static void entrance(void); - }; diff --git a/GCC/DiffAL.h b/GCC/DiffAL.h index 72f73ade7..e20364c3c 100644 --- a/GCC/DiffAL.h +++ b/GCC/DiffAL.h @@ -10,71 +10,69 @@ #include #include -//using namespace std; +// using namespace std; class DiffusionAL { private: - public: DiffusionAL(void); ~DiffusionAL(void); -/* Data */ + /* Data */ typedef struct { - string N; //name - int Z; //charge - double A; //parameter A or C - double B; //parameter B - double R; //Radii - double M; //molecular weight - double D0;//Self-Diffusion Coefficient - }AqData; + string N; // name + int Z; // charge + double A; // parameter A or C + double B; // parameter B + double R; // Radii + double M; // molecular weight + double D0; // Self-Diffusion Coefficient + } AqData; vector Ions; typedef struct { - string N; //name of solute - double C; //molality of solute - double D; //diffusion coefficient(**final result**) - }Solute; - vector ListS;//initial input condition + string N; // name of solute + double C; // molality of solute + double D; // diffusion coefficient(**final result**) + } Solute; + vector ListS; // initial input condition typedef struct { - string Nc; //name of cation - string Na; //name of anion - double Lc; //number of cation - double La; //number of anion - double S; //number of solvent - double M; //molality - }speciesE; + string Nc; // name of cation + string Na; // name of anion + double Lc; // number of cation + double La; // number of anion + double S; // number of solvent + double M; // molality + } speciesE; typedef struct { - string N; //name of neutral species - double L; //number of neutral species - double S; //number of solvent - double M; //molality - }speciesN; - + string N; // name of neutral species + double L; // number of neutral species + double S; // number of solvent + double M; // molality + } speciesN; -/* Methods */ + /* Methods */ void LoadParameters(void); - std::vector string2vector(string);//split string line to pieces, and store in a vector + std::vector string2vector(string); // split string line to pieces, and store in a vector void SelfDiffCoef(double, double); double SingleElectrolytesDiffCoef(double, double, double, string, string, string); - //temperature(K),pressure(MPa),molality,name of cation,name of anion, - //name of diffusive species(destination)(return its diffusion coefficient + // temperature(K),pressure(MPa),molality,name of cation,name of anion, + // name of diffusive species(destination)(return its diffusion coefficient int GreatestCommonDivisor(int, int); void DivideSolution(std::vector, double&, std::vector&, std::vector&); void MultiDiffCoef(double, double); void CreateListS(void); - //void testDS(double, double); + // void testDS(double, double); void Interface(void); void entrance(void); diff --git a/GCC/DiffOH.cpp b/GCC/DiffOH.cpp index a1d5136ea..3babdcac4 100644 --- a/GCC/DiffOH.cpp +++ b/GCC/DiffOH.cpp @@ -9,23 +9,22 @@ /* References (1).Shock, E. L., Oelkers, E. H., Johnson, J. W., Sverjensky, D. A., and Helgeson, H. C., 1992. - Calculation of the Thermodynamic Properties of Aqueous Species at High-Pressures and Temperatures- - Effective Electrostatic Radii, Dissociation-Constants and Standard Partial Molal Properties to - 1000-Degrees-C and 5-Kbar. - Journal of the Chemical Society-Faraday Transactions 88, 803-826. + Calculation of the Thermodynamic Properties of Aqueous Species at High-Pressures and Temperatures- + Effective Electrostatic Radii, Dissociation-Constants and Standard Partial Molal Properties to + 1000-Degrees-C and 5-Kbar. + Journal of the Chemical Society-Faraday Transactions 88, 803-826. (2).Oelkers, E. H. and Helgeson, H. C., 1988. Calculation of the Thermodynamic and Transport- - Properties of Aqueous Species at High-Pressures and Temperatures - Aqueous Tracer Diffusion- - Coefficients of Ions to 1000-Degrees-C and 5-Kb. - Geochimica Et Cosmochimica Acta 52, 63-85. + Properties of Aqueous Species at High-Pressures and Temperatures - Aqueous Tracer Diffusion- + Coefficients of Ions to 1000-Degrees-C and 5-Kb. + Geochimica Et Cosmochimica Acta 52, 63-85. (4).Helgeson, H. C., 1992. Effects of complex formation in flowing fluids on the hydrothermal - solubilities of minerals as a function of fluid pressure and temperature in the - critical and supercritical regions of the system H2O. - Geochimica Et Cosmochimica Acta 56, 3191-3207. + solubilities of minerals as a function of fluid pressure and temperature in the + critical and supercritical regions of the system H2O. + Geochimica Et Cosmochimica Acta 56, 3191-3207. */ - #include #include #include @@ -42,10 +41,9 @@ using namespace std; - Diffusion::Diffusion(void) { - index1=0; + index1 = 0; } Diffusion::~Diffusion(void) diff --git a/GCC/DiffOH.h b/GCC/DiffOH.h index d0236277c..5a58800c6 100644 --- a/GCC/DiffOH.h +++ b/GCC/DiffOH.h @@ -11,47 +11,46 @@ #include #include -//using namespace std; +// using namespace std; class Diffusion { private: - public: Diffusion(void); ~Diffusion(void); -/* Data */ + /* Data */ int index1; - double t0Na, t0Cl;//transference numbers of Na and Cl ions Eq(52) Ref.(2) - double AeNaCl, AeCaCl2, AeHCl, AeNaOH, AeNaBr, AeNaI, AeMgCl2, AeHBr;//conductance of references electrolyte Eq(46) Ref.(2) + double t0Na, t0Cl; // transference numbers of Na and Cl ions Eq(52) Ref.(2) + double AeNaCl, AeCaCl2, AeHCl, AeNaOH, AeNaBr, AeNaI, AeMgCl2, + AeHBr; // conductance of references electrolyte Eq(46) Ref.(2) typedef struct { - std::string N; //name - int Z; //charge - double A; //conductance - double D; //diffusion coefficient - double S; //entropy - double H; //enthalpy - double G; //Gibbs free energy - std::string M; //name in Helgeson datafile - double C[11]; //parameters - }AqData; + std::string N; // name + int Z; // charge + double A; // conductance + double D; // diffusion coefficient + double S; // entropy + double H; // enthalpy + double G; // Gibbs free energy + std::string M; // name in Helgeson datafile + double C[11]; // parameters + } AqData; std::vector Ions; /* Methods */ - void IonsA(std::string,double);//write Conductance value - void IonsD(std::string,double);//write Diff Coef value - double IonsA(std::string);//return Conductance value - double IonsD(std::string);//return Diff Coef value - double IonsS(std::string);//return entropy value - - void InputIons(void);//add Ions into vector - void TransferenceNumberNaCl(double);//calculate Transference Number NaCl - void ConductancesRef(double, double);//calculate Conductances of Ref electrolytes + void IonsA(std::string, double); // write Conductance value + void IonsD(std::string, double); // write Diff Coef value + double IonsA(std::string); // return Conductance value + double IonsD(std::string); // return Diff Coef value + double IonsS(std::string); // return entropy value - void LoadParameters(void);//load in parameters for every species from database (slop98.dat) + void InputIons(void); // add Ions into vector + void TransferenceNumberNaCl(double); // calculate Transference Number NaCl + void ConductancesRef(double, double); // calculate Conductances of Ref electrolytes + void LoadParameters(void); // load in parameters for every species from database (slop98.dat) void HelgesonEquation(double, double); @@ -69,4 +68,3 @@ double Ufun(double, double); double Nfun(double, double); double Xfun(double, double); double Yfun(double, double); - diff --git a/GCC/HKF.cpp b/GCC/HKF.cpp index eb91483a2..8b7c171da 100644 --- a/GCC/HKF.cpp +++ b/GCC/HKF.cpp @@ -9,25 +9,25 @@ /* References (1).Shock, E. L., Oelkers, E. H., Johnson, J. W., Sverjensky, D. A., and Helgeson, H. C., 1992. - Calculation of the Thermodynamic Properties of Aqueous Species at High-Pressures and Temperatures- - Effective Electrostatic Radii, Dissociation-Constants and Standard Partial Molal Properties to - 1000-Degrees-C and 5-Kbar. - Journal of the Chemical Society-Faraday Transactions 88, 803-826. + Calculation of the Thermodynamic Properties of Aqueous Species at High-Pressures and Temperatures- + Effective Electrostatic Radii, Dissociation-Constants and Standard Partial Molal Properties to + 1000-Degrees-C and 5-Kbar. + Journal of the Chemical Society-Faraday Transactions 88, 803-826. (2).Oelkers, E. H. and Helgeson, H. C., 1988. Calculation of the Thermodynamic and Transport- - Properties of Aqueous Species at High-Pressures and Temperatures - Aqueous Tracer Diffusion- - Coefficients of Ions to 1000-Degrees-C and 5-Kb. - Geochimica Et Cosmochimica Acta 52, 63-85. + Properties of Aqueous Species at High-Pressures and Temperatures - Aqueous Tracer Diffusion- + Coefficients of Ions to 1000-Degrees-C and 5-Kb. + Geochimica Et Cosmochimica Acta 52, 63-85. (3).Duan, Z. H., Moller, N., and Weare, J. H., 1992. - An Equation of State for the Ch4-Co2-H2o System .1. Pure Systems from 0-Degrees-C to 1000-Degrees-C - and 0 to 8000 Bar. - Geochimica Et Cosmochimica Acta 56, 2605-2617. + An Equation of State for the Ch4-Co2-H2o System .1. Pure Systems from 0-Degrees-C to 1000-Degrees-C + and 0 to 8000 Bar. + Geochimica Et Cosmochimica Acta 56, 2605-2617. (4).Helgeson, H. C., 1992. Effects of complex formation in flowing fluids on the hydrothermal - solubilities of minerals as a function of fluid pressure and temperature in the - critical and supercritical regions of the system H2O. - Geochimica Et Cosmochimica Acta 56, 3191-3207. + solubilities of minerals as a function of fluid pressure and temperature in the + critical and supercritical regions of the system H2O. + Geochimica Et Cosmochimica Acta 56, 3191-3207. */ #include @@ -49,20 +49,23 @@ #include "IAPWS-IF97.h" //#include "slop98.h" - using namespace std; +HKF::HKF(void) +{ +} +HKF::~HKF(void) +{ +} -HKF::HKF(void){} -HKF::~HKF(void){} - -int HKF::HKF_OGS_loadparam(std::string species_name0, int &type, double &charge, double param[][4]){ - int i,j; +int HKF::HKF_OGS_loadparam(std::string species_name0, int& type, double& charge, double param[][4]) +{ + int i, j; HKF::SpeciesData spec; vector species_vector; vector name_type, phase_type; - spec.name0=species_name0; + spec.name0 = species_name0; species_vector.clear(); species_vector.push_back(spec); name_type.clear(); @@ -70,463 +73,503 @@ int HKF::HKF_OGS_loadparam(std::string species_name0, int &type, double &charge, phase_type.clear(); phase_type.push_back(-1); - if(HKF::load_param(species_vector, name_type, phase_type) !=1){ - //cout << " warning... " << endl; - //type=-1; - //charge=-99; - //for(i=0;i<9;i++) + if (HKF::load_param(species_vector, name_type, phase_type) != 1) + { + // cout << " warning... " << endl; + // type=-1; + // charge=-99; + // for(i=0;i<9;i++) // for(j=0;j<4;j++) // param[i][j]=-99; return 0; } - else{ - spec=species_vector.back(); - type=spec.type; - charge=spec.charge; - for(i=0;i<9;i++) - for(j=0;j<4;j++) - param[i][j]=spec.param[i][j]; + else + { + spec = species_vector.back(); + type = spec.type; + charge = spec.charge; + for (i = 0; i < 9; i++) + for (j = 0; j < 4; j++) + param[i][j] = spec.param[i][j]; return 1; } } - -int HKF::HKF_OGS_calc(double T, double P, double &G, double &H, double &S, int type, double charge, double param[][4]){ - int i,j,res=1; +int HKF::HKF_OGS_calc(double T, double P, double& G, double& H, double& S, int type, double charge, double param[][4]) +{ + int i, j, res = 1; HKF::SpeciesData spec; vector species_vector; vector name_type, phase_type; - spec.type=type; - spec.charge=charge; - for(i=0;i<9;i++) - for(j=0;j<4;j++) - spec.param[i][j]=param[i][j]; + spec.type = type; + spec.charge = charge; + for (i = 0; i < 9; i++) + for (j = 0; j < 4; j++) + spec.param[i][j] = param[i][j]; species_vector.clear(); species_vector.push_back(spec); - if(HelgesonEquation(T, P, species_vector)==1){ - spec=species_vector.back(); - G=spec.G; - H=spec.H; - S=spec.S; + if (HelgesonEquation(T, P, species_vector) == 1) + { + spec = species_vector.back(); + G = spec.G; + H = spec.H; + S = spec.S; } return res; } -double HKF::HKFcalcw(double T, double P, int ghs){ - double GG,HH,SS,res; - if(ghs>2 || ghs<0) +double HKF::HKFcalcw(double T, double P, int ghs) +{ + double GG, HH, SS, res; + if (ghs > 2 || ghs < 0) exit(0); - HH=(IF97::H(T,P/10.0)/55.51-287.45532)*1000.0/4.18; - SS=(IF97::S(T,P/10.0)/55.51+0.0632944)*1000.0/4.18; - GG= -125005.0-HH; - if(ghs==0) res=GG; - else if(ghs==1) res=HH; - else if(ghs==2) res=SS; + HH = (IF97::H(T, P / 10.0) / 55.51 - 287.45532) * 1000.0 / 4.18; + SS = (IF97::S(T, P / 10.0) / 55.51 + 0.0632944) * 1000.0 / 4.18; + GG = -125005.0 - HH; + if (ghs == 0) + res = GG; + else if (ghs == 1) + res = HH; + else if (ghs == 2) + res = SS; return res; } - -double HKF::HKFcalc(double T, double P, int ghs, std::string name, int sub, int type){ - if(ghs>2 || ghs<0) +double HKF::HKFcalc(double T, double P, int ghs, std::string name, int sub, int type) +{ + if (ghs > 2 || ghs < 0) exit(0); SpeciesData ion; vector Ions; vector ntv, ptv; int is_OK; double res; - ion.name0=name; + ion.name0 = name; Ions.clear(); ntv.clear(); ptv.clear(); Ions.push_back(ion); ntv.push_back(sub); ptv.push_back(type); - is_OK= HKF::load_param(Ions, ntv, ptv); - if(is_OK!=1) + is_OK = HKF::load_param(Ions, ntv, ptv); + if (is_OK != 1) exit(0); - HelgesonEquation(T,P,Ions); - if(ghs==0) res= Ions[0].G; - else if(ghs==1) res= Ions[0].H; - else if(ghs==2) res= Ions[0].S; + HelgesonEquation(T, P, Ions); + if (ghs == 0) + res = Ions[0].G; + else if (ghs == 1) + res = Ions[0].H; + else if (ghs == 2) + res = Ions[0].S; return res; } - - -int HKF::load_param(vector &spec, vector name_type, vector phase_type){ - if((int)spec.size()==(int)name_type.size() && (int)spec.size()==(int)phase_type.size()){ - - int i, j, js, jx, jz, type= -1, is_spec, is_OK=0; - vector pies, piesx, piesz, slop98; - vector id_spec;//storage index of name0, which can be found in the species list. - int cek, cekz; //check species - string first_char; - - id_spec.clear(); - is_OK= IO::file2vector("slop98.dat", slop98); - //for(i=0;i<(int)slop98.size();i++){ - // cin.get(); - // cout << slop98[i] <0){ - if(spec[j].name0==piesx[0]) is_spec=1; - } - else if(name_type[j]==1 && (int)piesx.size()>1){ - if(spec[j].name0==piesx[1]) is_spec=1; - } - else if(name_type[j]==2 && (int)piesz.size()>0){ - if(spec[j].name0==piesz[0]) is_spec=1; - } - else if(name_type[j]==3 && (int)piesz.size()>1){ - if(spec[j].name0==piesz[1]) is_spec=1; +int HKF::load_param(vector& spec, vector name_type, vector phase_type) +{ + if ((int)spec.size() == (int)name_type.size() && (int)spec.size() == (int)phase_type.size()) + { + int i, j, js, jx, jz, type = -1, is_spec, is_OK = 0; + vector pies, piesx, piesz, slop98; + vector id_spec; // storage index of name0, which can be found in the species list. + int cek, cekz; // check species + string first_char; + + id_spec.clear(); + is_OK = IO::file2vector("slop98.dat", slop98); + // for(i=0;i<(int)slop98.size();i++){ + // cin.get(); + // cout << slop98[i] <5) - is_spec=1; - } + piesx = IO::string2vector(slop98[i]); + piesz = IO::string2vector(slop98[i + 1]); - if(is_spec==1){ + for (j = 0; j < (int)spec.size(); j++) + { + // cout << i << " " << slop98[i] << " OK " << endl; + is_spec = 0; + // searching depend on name scform ecform and abbrev + if (name_type[j] == 0 && (int)piesx.size() > 0) + { + if (spec[j].name0 == piesx[0]) + is_spec = 1; + } + else if (name_type[j] == 1 && (int)piesx.size() > 1) + { + if (spec[j].name0 == piesx[1]) + is_spec = 1; + } + else if (name_type[j] == 2 && (int)piesz.size() > 0) + { + if (spec[j].name0 == piesz[0]) + is_spec = 1; + } + else if (name_type[j] == 3 && (int)piesz.size() > 1) + { + if (spec[j].name0 == piesz[1]) + is_spec = 1; + } + else + { + // cout << " OK load " << endl; + for (js = 0; js < (int)piesx.size(); js++) + if (spec[j].name0 == piesx[js]) + is_spec = 1; + for (js = 0; js < (int)piesz.size(); js++) + if (spec[j].name0 == piesz[js]) + is_spec = 1; + } + if (is_spec == 1) + { + // searching depend on phase type - id_spec.push_back(j); - spec[j].name= piesx[0]; - spec[j].scform= piesx[1]; - if((int)piesz.size()>=2){ - spec[j].abbrev= piesz[0]; - spec[j].ecform= piesz[1]; + is_spec = 0; + if (phase_type[j] == type || phase_type[j] < 0 || phase_type[j] > 5) + is_spec = 1; } - else{ - spec[j].abbrev= "N/A"; - spec[j].ecform= piesz[0]; - } - pies = IO::string2vector(slop98[i+2]); - spec[j].ref[0]= pies[0]; - spec[j].ref[1]= pies[1]; - - spec[j].type= type; - switch (type){ - case 0: - case 4: - case 5: - for(jx=0;jx<3;jx++) { - pies=IO::string2vector(slop98[i+jx+3]); - for(jz=0;jz<4;jz++) - if(jz<(int)pies.size()) - spec[j].param[jx][jz]= atof(pies[jz].c_str()); - else - spec[j].param[jx][jz]=0.0; - } - for(jx=3;jx<9;jx++) - for(jz=0;jz<4;jz++) - spec[j].param[jx][jz]=0.0; - spec[j].charge=spec[j].param[2][3]; - break; - - case 1: - pies=IO::string2vector(slop98[i+3]); - for(jz=0;jz<4;jz++) - spec[j].param[0][jz]= atof(pies[jz].c_str()); - - pies=IO::string2vector(slop98[i+4]); - for(jz=0;jz<3;jz++) - spec[j].param[1][jz]= atof(pies[jz].c_str()); - spec[j].param[1][3]= 0.0; - - for(jz=0;jz<4;jz++) - spec[j].param[2][jz]= atof(pies[jz+3].c_str()); - - pies=IO::string2vector(slop98[i+5]); - for(jz=0;jz<3;jz++) - spec[j].param[3][jz]= atof(pies[jz].c_str()); - spec[j].param[3][3]= 0.0; - - spec[j].param[4][0]= atof(slop98[i+6].c_str()); - for(jz=1;jz<4;jz++) - spec[j].param[4][jz]= 0.0; - - for(jx=5;jx<9;jx++) - for(jz=0;jz<4;jz++) - spec[j].param[jx][jz]=0.0; - spec[j].charge=0.0; - break; - - case 2: - pies=IO::string2vector(slop98[i+3]); - for(jz=0;jz<4;jz++) - spec[j].param[0][jz]= atof(pies[jz].c_str()); - - pies=IO::string2vector(slop98[i+4]); - for(jz=0;jz<3;jz++) - spec[j].param[1][jz]= atof(pies[jz].c_str()); - spec[j].param[1][3]= 0.0; - for(jz=0;jz<4;jz++) - spec[j].param[2][jz]= atof(pies[jz+3].c_str()); - - pies=IO::string2vector(slop98[i+5]); - for(jz=0;jz<3;jz++) - spec[j].param[3][jz]= atof(pies[jz].c_str()); - spec[j].param[3][3]= 0.0; - for(jz=0;jz<4;jz++) - spec[j].param[4][jz]= atof(pies[jz+3].c_str()); - - pies=IO::string2vector(slop98[i+6]); - for(jz=0;jz<3;jz++) - spec[j].param[5][jz]= atof(pies[jz].c_str()); - spec[j].param[5][3]= 0.0; - - spec[j].param[6][0]= atof(slop98[i+7].c_str()); - for(jz=1;jz<4;jz++) - spec[j].param[6][jz]= 0.0; - - for(jx=7;jx<9;jx++) - for(jz=0;jz<4;jz++) - spec[j].param[jx][jz]=0.0; - spec[j].charge=0.0; - break; - - case 3: - pies=IO::string2vector(slop98[i+3]); - for(jz=0;jz<4;jz++) - spec[j].param[0][jz]= atof(pies[jz].c_str()); - - pies=IO::string2vector(slop98[i+4]); - for(jz=0;jz<3;jz++) - spec[j].param[1][jz]= atof(pies[jz].c_str()); - spec[j].param[1][3]= 0.0; - for(jz=0;jz<4;jz++) - spec[j].param[2][jz]= atof(pies[jz+3].c_str()); - - pies=IO::string2vector(slop98[i+5]); - for(jz=0;jz<3;jz++) - spec[j].param[3][jz]= atof(pies[jz].c_str()); - spec[j].param[3][3]= 0.0; - for(jz=0;jz<4;jz++) - spec[j].param[4][jz]= atof(pies[jz+3].c_str()); - - pies=IO::string2vector(slop98[i+6]); - for(jz=0;jz<3;jz++) - spec[j].param[5][jz]= atof(pies[jz].c_str()); - spec[j].param[5][3]= 0.0; - for(jz=0;jz<4;jz++) - spec[j].param[6][jz]= atof(pies[jz+3].c_str()); - - pies=IO::string2vector(slop98[i+7]); - for(jz=0;jz<3;jz++) - spec[j].param[7][jz]= atof(pies[jz].c_str()); - spec[j].param[7][3]= 0.0; - - spec[j].param[8][0]= atof(slop98[i+8].c_str()); - for(jz=1;jz<4;jz++) - spec[j].param[8][jz]= 0.0; - spec[j].charge=0.0; - break; - - default: - break; - }//end switch - }//end if - }//end for - - switch (type){ - case 0: - case 4: - case 5: - i+= 5; - break; - case 1: - i+= 6; - break; - case 2: - i+= 7; - break; - case 3: - i+= 8; - break; - default: - break; + + if (is_spec == 1) + { + id_spec.push_back(j); + spec[j].name = piesx[0]; + spec[j].scform = piesx[1]; + if ((int)piesz.size() >= 2) + { + spec[j].abbrev = piesz[0]; + spec[j].ecform = piesz[1]; + } + else + { + spec[j].abbrev = "N/A"; + spec[j].ecform = piesz[0]; + } + pies = IO::string2vector(slop98[i + 2]); + spec[j].ref[0] = pies[0]; + spec[j].ref[1] = pies[1]; + + spec[j].type = type; + switch (type) + { + case 0: + case 4: + case 5: + for (jx = 0; jx < 3; jx++) + { + pies = IO::string2vector(slop98[i + jx + 3]); + for (jz = 0; jz < 4; jz++) + if (jz < (int)pies.size()) + spec[j].param[jx][jz] = atof(pies[jz].c_str()); + else + spec[j].param[jx][jz] = 0.0; + } + for (jx = 3; jx < 9; jx++) + for (jz = 0; jz < 4; jz++) + spec[j].param[jx][jz] = 0.0; + spec[j].charge = spec[j].param[2][3]; + break; + + case 1: + pies = IO::string2vector(slop98[i + 3]); + for (jz = 0; jz < 4; jz++) + spec[j].param[0][jz] = atof(pies[jz].c_str()); + + pies = IO::string2vector(slop98[i + 4]); + for (jz = 0; jz < 3; jz++) + spec[j].param[1][jz] = atof(pies[jz].c_str()); + spec[j].param[1][3] = 0.0; + + for (jz = 0; jz < 4; jz++) + spec[j].param[2][jz] = atof(pies[jz + 3].c_str()); + + pies = IO::string2vector(slop98[i + 5]); + for (jz = 0; jz < 3; jz++) + spec[j].param[3][jz] = atof(pies[jz].c_str()); + spec[j].param[3][3] = 0.0; + + spec[j].param[4][0] = atof(slop98[i + 6].c_str()); + for (jz = 1; jz < 4; jz++) + spec[j].param[4][jz] = 0.0; + + for (jx = 5; jx < 9; jx++) + for (jz = 0; jz < 4; jz++) + spec[j].param[jx][jz] = 0.0; + spec[j].charge = 0.0; + break; + + case 2: + pies = IO::string2vector(slop98[i + 3]); + for (jz = 0; jz < 4; jz++) + spec[j].param[0][jz] = atof(pies[jz].c_str()); + + pies = IO::string2vector(slop98[i + 4]); + for (jz = 0; jz < 3; jz++) + spec[j].param[1][jz] = atof(pies[jz].c_str()); + spec[j].param[1][3] = 0.0; + for (jz = 0; jz < 4; jz++) + spec[j].param[2][jz] = atof(pies[jz + 3].c_str()); + + pies = IO::string2vector(slop98[i + 5]); + for (jz = 0; jz < 3; jz++) + spec[j].param[3][jz] = atof(pies[jz].c_str()); + spec[j].param[3][3] = 0.0; + for (jz = 0; jz < 4; jz++) + spec[j].param[4][jz] = atof(pies[jz + 3].c_str()); + + pies = IO::string2vector(slop98[i + 6]); + for (jz = 0; jz < 3; jz++) + spec[j].param[5][jz] = atof(pies[jz].c_str()); + spec[j].param[5][3] = 0.0; + + spec[j].param[6][0] = atof(slop98[i + 7].c_str()); + for (jz = 1; jz < 4; jz++) + spec[j].param[6][jz] = 0.0; + + for (jx = 7; jx < 9; jx++) + for (jz = 0; jz < 4; jz++) + spec[j].param[jx][jz] = 0.0; + spec[j].charge = 0.0; + break; + + case 3: + pies = IO::string2vector(slop98[i + 3]); + for (jz = 0; jz < 4; jz++) + spec[j].param[0][jz] = atof(pies[jz].c_str()); + + pies = IO::string2vector(slop98[i + 4]); + for (jz = 0; jz < 3; jz++) + spec[j].param[1][jz] = atof(pies[jz].c_str()); + spec[j].param[1][3] = 0.0; + for (jz = 0; jz < 4; jz++) + spec[j].param[2][jz] = atof(pies[jz + 3].c_str()); + + pies = IO::string2vector(slop98[i + 5]); + for (jz = 0; jz < 3; jz++) + spec[j].param[3][jz] = atof(pies[jz].c_str()); + spec[j].param[3][3] = 0.0; + for (jz = 0; jz < 4; jz++) + spec[j].param[4][jz] = atof(pies[jz + 3].c_str()); + + pies = IO::string2vector(slop98[i + 6]); + for (jz = 0; jz < 3; jz++) + spec[j].param[5][jz] = atof(pies[jz].c_str()); + spec[j].param[5][3] = 0.0; + for (jz = 0; jz < 4; jz++) + spec[j].param[6][jz] = atof(pies[jz + 3].c_str()); + + pies = IO::string2vector(slop98[i + 7]); + for (jz = 0; jz < 3; jz++) + spec[j].param[7][jz] = atof(pies[jz].c_str()); + spec[j].param[7][3] = 0.0; + + spec[j].param[8][0] = atof(slop98[i + 8].c_str()); + for (jz = 1; jz < 4; jz++) + spec[j].param[8][jz] = 0.0; + spec[j].charge = 0.0; + break; + + default: + break; + } // end switch + } // end if + } // end for + + switch (type) + { + case 0: + case 4: + case 5: + i += 5; + break; + case 1: + i += 6; + break; + case 2: + i += 7; + break; + case 3: + i += 8; + break; + default: + break; + } } - } - if((int)id_spec.size()>0){ - cekz=1; - for(i=0;i<(int)spec.size();i++){ - cek=0; - for(j=0;j<(int)id_spec.size();j++) - if(id_spec[j]==i) cek=1; - if(cek==0) { - cekz=0; - cout << endl << " Warning! " << spec[i].name0 << " (" << name_type[i] << ") is NOT in the species list!" << endl; + if ((int)id_spec.size() > 0) + { + cekz = 1; + for (i = 0; i < (int)spec.size(); i++) + { + cek = 0; + for (j = 0; j < (int)id_spec.size(); j++) + if (id_spec[j] == i) + cek = 1; + if (cek == 0) + { + cekz = 0; + cout << endl + << " Warning! " << spec[i].name0 << " (" << name_type[i] << ") is NOT in the species list!" + << endl; + } } + if (cekz == 1) + return 1; // OK + else + return -1; // species name is incorrect } - if(cekz==1) - return 1;//OK else - return -1;//species name is incorrect + return -2; // did nothing } else - return -2;//did nothing - } - else - return 0;//can NOT open species list vector + return 0; // can NOT open species list vector } else exit(0); - } - -int HKF::HelgesonEquation(double T, double P, vector &spec){ - - double c1, c2, a1, a2, a3, a4, Z,dG,dH,dS,dV;//aqueous species parameters from database - double Sc1,Sc2, Sa3,Sa4,Sw; - double Hc1,Hc2,Ha1,Ha2,Ha3,Ha4,Hw; - double Gc1,Gc2,Ga1,Ga2,Ga3,Ga4,Gw; - double a0, b0, c0/*, Tmax*/; //gases and minerals parameters from database - - double theta,psi,eta,Tr,Pr,e,er,Yr,Y,g; //independent on species - double rejr,rej,wr,w,X1; //dependent on species - int i, is_aq=0; - - Tr = 298.15; //p819 Ref.(1) - Pr = 1.0; //p819 Ref.(1) - - for(i=0;i<(int)spec.size();i++) - if(spec[i].type==5) is_aq=1; - - if(is_aq==1){ - theta= 228.0; //p819 Ref.(1) - psi= 2600.0; //p819 Ref.(1) - eta= 1.66027E5; //p824 Ref.(1) - - - e = diel_water(T,P);//(C1) p821 Ref.(1) - er = diel_water(Tr,Pr); - Yr = Yfunc(Tr,Pr);//Yr = -5.8E-5; p824 Ref.(1) - Y = Yfunc(T,P);//(A25) Ref.(1) - g = gfunc(T,P);//Eq(24) p807 Ref.(1) - - Sc1 = log(T/Tr); - Sc2 = -(1/(T-theta)-1/(Tr-theta)+1/theta*log(Tr*(T-theta)/T/(Tr-theta)))/theta; - Sa3 = 1/(T-theta)/(T-theta)*(P-Pr); - Sa4 = 1/(T-theta)/(T-theta)*log((psi+P)/(psi+Pr)); +int HKF::HelgesonEquation(double T, double P, vector& spec) +{ + double c1, c2, a1, a2, a3, a4, Z, dG, dH, dS, dV; // aqueous species parameters from database + double Sc1, Sc2, Sa3, Sa4, Sw; + double Hc1, Hc2, Ha1, Ha2, Ha3, Ha4, Hw; + double Gc1, Gc2, Ga1, Ga2, Ga3, Ga4, Gw; + double a0, b0, c0 /*, Tmax*/; // gases and minerals parameters from database + + double theta, psi, eta, Tr, Pr, e, er, Yr, Y, g; // independent on species + double rejr, rej, wr, w, X1; // dependent on species + int i, is_aq = 0; + + Tr = 298.15; // p819 Ref.(1) + Pr = 1.0; // p819 Ref.(1) + + for (i = 0; i < (int)spec.size(); i++) + if (spec[i].type == 5) + is_aq = 1; + + if (is_aq == 1) + { + theta = 228.0; // p819 Ref.(1) + psi = 2600.0; // p819 Ref.(1) + eta = 1.66027E5; // p824 Ref.(1) + + e = diel_water(T, P); //(C1) p821 Ref.(1) + er = diel_water(Tr, Pr); + Yr = Yfunc(Tr, Pr); // Yr = -5.8E-5; p824 Ref.(1) + Y = Yfunc(T, P); //(A25) Ref.(1) + g = gfunc(T, P); // Eq(24) p807 Ref.(1) + + Sc1 = log(T / Tr); + Sc2 = -(1 / (T - theta) - 1 / (Tr - theta) + 1 / theta * log(Tr * (T - theta) / T / (Tr - theta))) / theta; + Sa3 = 1 / (T - theta) / (T - theta) * (P - Pr); + Sa4 = 1 / (T - theta) / (T - theta) * log((psi + P) / (psi + Pr)); //(A20) & (B21) Ref.(1) - Hc1 = T-Tr; - Hc2 = -(1.0/(T-theta)-1.0/(Tr-theta)); - Ha1 = P-Pr; - Ha2 = log((psi+P)/(psi+Pr)); - Ha3 = (2*T-theta)/pow((T-theta),2.0)*(P-Pr); - Ha4 = (2*T-theta)/pow((T-theta),2.0)*log((psi+P)/(psi+Pr)); - //A(22) & B(23) Ref.(1) - - Gc1 = -(T*log(T/Tr)-T+Tr); - Gc2 = -(((1.0/(T-theta))-(1.0/(Tr-theta)))*(theta-T)/theta - T/theta/theta*log(Tr*(T-theta)/T/(Tr-theta))); - Ga1 = P-Pr; - Ga2 = log((psi+P)/(psi+Pr)); - Ga3 = 1.0/(T-theta)*(P-Pr); - Ga4 = 1.0/(T-theta)*log((psi+P)/(psi+Pr)); - //A(24) & B(25) Ref.(1) + Hc1 = T - Tr; + Hc2 = -(1.0 / (T - theta) - 1.0 / (Tr - theta)); + Ha1 = P - Pr; + Ha2 = log((psi + P) / (psi + Pr)); + Ha3 = (2 * T - theta) / pow((T - theta), 2.0) * (P - Pr); + Ha4 = (2 * T - theta) / pow((T - theta), 2.0) * log((psi + P) / (psi + Pr)); + // A(22) & B(23) Ref.(1) + + Gc1 = -(T * log(T / Tr) - T + Tr); + Gc2 = -(((1.0 / (T - theta)) - (1.0 / (Tr - theta))) * (theta - T) / theta + - T / theta / theta * log(Tr * (T - theta) / T / (Tr - theta))); + Ga1 = P - Pr; + Ga2 = log((psi + P) / (psi + Pr)); + Ga3 = 1.0 / (T - theta) * (P - Pr); + Ga4 = 1.0 / (T - theta) * log((psi + P) / (psi + Pr)); + // A(24) & B(25) Ref.(1) } - else{ - Yr=g=e=er=Y=0.0; - Sc1=Sc2=Sa3=Sa4=0.0; - Hc1=Hc2=Ha1=Ha2=Ha3=Ha4=0.0; - Gc1=Gc2=Ga1=Ga2=Ga3=Ga4=0.0; + else + { + Yr = g = e = er = Y = 0.0; + Sc1 = Sc2 = Sa3 = Sa4 = 0.0; + Hc1 = Hc2 = Ha1 = Ha2 = Ha3 = Ha4 = 0.0; + Gc1 = Gc2 = Ga1 = Ga2 = Ga3 = Ga4 = 0.0; } - for(i=0;i<(int)spec.size();i++){ - if(spec[i].type==5){ - dG= spec[i].param[0][0]; - dH= spec[i].param[0][1]; - dS= spec[i].param[0][2]; - a1= spec[i].param[1][0]*1.0E-1; - a2= spec[i].param[1][1]*1.0E+2; - a3= spec[i].param[1][2]; - a4= spec[i].param[1][3]*1.0E+4; - c1= spec[i].param[2][0]; - c2= spec[i].param[2][1]*1.0E+4; - wr= spec[i].param[2][2]*1.0E+5; + for (i = 0; i < (int)spec.size(); i++) + { + if (spec[i].type == 5) + { + dG = spec[i].param[0][0]; + dH = spec[i].param[0][1]; + dS = spec[i].param[0][2]; + a1 = spec[i].param[1][0] * 1.0E-1; + a2 = spec[i].param[1][1] * 1.0E+2; + a3 = spec[i].param[1][2]; + a4 = spec[i].param[1][3] * 1.0E+4; + c1 = spec[i].param[2][0]; + c2 = spec[i].param[2][1] * 1.0E+4; + wr = spec[i].param[2][2] * 1.0E+5; Z = spec[i].charge; - if(Z==0){ - Sw= wr*(Y-Yr); //(A20) Ref.(1) - Gw= wr*(Yr*(T-Tr)+1.0/e-1.0/er);//(A24) Ref.(1) - Hw= wr*(T*Y-Tr*Yr+1.0/e-1.0/er);//(A22) Ref.(1) + if (Z == 0) + { + Sw = wr * (Y - Yr); //(A20) Ref.(1) + Gw = wr * (Yr * (T - Tr) + 1.0 / e - 1.0 / er); //(A24) Ref.(1) + Hw = wr * (T * Y - Tr * Yr + 1.0 / e - 1.0 / er); //(A22) Ref.(1) } - else{ - rejr= Z*Z*(eta*Yr-100.0)/(dS-71.5*abs(Z)); //(D1) Ref.(1) & Eq(29) Ref.(4) - rej = rejr+abs(Z)*g; //Eq(6) Ref.(1) - wr = eta*Z*(Z/rejr-1.0/3.082); //(D5) Ref.(1) - w = eta*Z*(Z/(rejr+abs(Z)*g)-1.0/(3.082+g)); //(D4) Ref.(1) - X1 = -eta*(pow(abs(Z),3.0)*pow(rej,-2.0)-Z*pow((3.082+g),-2.0)); //(B19) Ref.(1) - Sw= w*Y -(1.0/e-1.0)*X1*NR::dfridrX(gfunc,T,P) -wr*Yr; //(B21) & (B14) Ref.(1) - Hw= w*(1.0/e-1.0) +w*T*Y -T*(1.0/e-1.0)*X1*NR::dfridrX(gfunc,T,P) -wr*(1.0/er-1.0) -wr*Tr*Yr; - Gw= w*(1.0/e-1.0) -wr*(1.0/er-1.0) +wr*Yr*(T-Tr); + else + { + rejr = Z * Z * (eta * Yr - 100.0) / (dS - 71.5 * abs(Z)); //(D1) Ref.(1) & Eq(29) Ref.(4) + rej = rejr + abs(Z) * g; // Eq(6) Ref.(1) + wr = eta * Z * (Z / rejr - 1.0 / 3.082); //(D5) Ref.(1) + w = eta * Z * (Z / (rejr + abs(Z) * g) - 1.0 / (3.082 + g)); //(D4) Ref.(1) + X1 = -eta * (pow(abs(Z), 3.0) * pow(rej, -2.0) - Z * pow((3.082 + g), -2.0)); //(B19) Ref.(1) + Sw = w * Y - (1.0 / e - 1.0) * X1 * NR::dfridrX(gfunc, T, P) - wr * Yr; //(B21) & (B14) Ref.(1) + Hw = w * (1.0 / e - 1.0) + w * T * Y - T * (1.0 / e - 1.0) * X1 * NR::dfridrX(gfunc, T, P) + - wr * (1.0 / er - 1.0) - wr * Tr * Yr; + Gw = w * (1.0 / e - 1.0) - wr * (1.0 / er - 1.0) + wr * Yr * (T - Tr); } - spec[i].S= dS +c1*Sc1 +c2*Sc2 + a3*Sa3 +a4*Sa4 +Sw; //(A20) (B21) Ref.(1) - spec[i].G= dG -dS*(T-Tr) +c1*Gc1 +c2*Gc2 +a1*Ga1 +a2*Ga2 +a3*Ga3 +a4*Ga4 +Gw; //(A24) (B25) Ref.(1) - spec[i].H= dH +c1*Hc1 +c2*Hc2 +a1*Ha1 +a2*Ha2 +a3*Ha3 +a4*Ha4 +Hw; //(A22) (B23) Ref.(1) - + spec[i].S = dS + c1 * Sc1 + c2 * Sc2 + a3 * Sa3 + a4 * Sa4 + Sw; //(A20) (B21) Ref.(1) + spec[i].G = dG - dS * (T - Tr) + c1 * Gc1 + c2 * Gc2 + a1 * Ga1 + a2 * Ga2 + a3 * Ga3 + a4 * Ga4 + + Gw; //(A24) (B25) Ref.(1) + spec[i].H = dH + c1 * Hc1 + c2 * Hc2 + a1 * Ha1 + a2 * Ha2 + a3 * Ha3 + a4 * Ha4 + Hw; //(A22) (B23) Ref.(1) } - else{ - dG= spec[i].param[0][0]; - dH= spec[i].param[0][1]; - dS= spec[i].param[0][2]; - dV= spec[i].param[0][3]; - a0= spec[i].param[1][0]; - b0= spec[i].param[1][1]*1.0e-3; - c0= spec[i].param[1][2]*1.0e5; - - switch (spec[i].type){ - case 0: - case 4: - //Tmax= spec[i].param[2][0]; - spec[i].G= dG -dS*(T-Tr) +a0*(T-Tr-T*log(T/Tr)) +(-1.0*c0-b0*T*Tr*Tr)*(T-Tr)*(T-Tr)/(2.0*T*Tr*Tr) + - dV*(P-Pr)*0.1/4.18;//volume, pressure and energy unit convert factor - spec[i].H= dH +a0*(T-Tr) +b0/2.0*(T*T-Tr*Tr) -c0*(1.0/T-1.0/Tr) + - dV*(P-Pr)*0.1/4.18; - spec[i].S= dS +a0*log(T/Tr) +b0*(T-Tr) -c0/2.0*(1.0/T/T-1.0/Tr/Tr); - break; - case 1: - case 2: - case 3: - default: - spec[i].G= 0.0; - spec[i].H= 0.0; - spec[i].S= 0.0; - break; + else + { + dG = spec[i].param[0][0]; + dH = spec[i].param[0][1]; + dS = spec[i].param[0][2]; + dV = spec[i].param[0][3]; + a0 = spec[i].param[1][0]; + b0 = spec[i].param[1][1] * 1.0e-3; + c0 = spec[i].param[1][2] * 1.0e5; + + switch (spec[i].type) + { + case 0: + case 4: + // Tmax= spec[i].param[2][0]; + spec[i].G = dG - dS * (T - Tr) + a0 * (T - Tr - T * log(T / Tr)) + + (-1.0 * c0 - b0 * T * Tr * Tr) * (T - Tr) * (T - Tr) / (2.0 * T * Tr * Tr) + + dV * (P - Pr) * 0.1 / 4.18; // volume, pressure and energy unit convert factor + spec[i].H = dH + a0 * (T - Tr) + b0 / 2.0 * (T * T - Tr * Tr) - c0 * (1.0 / T - 1.0 / Tr) + + dV * (P - Pr) * 0.1 / 4.18; + spec[i].S = dS + a0 * log(T / Tr) + b0 * (T - Tr) - c0 / 2.0 * (1.0 / T / T - 1.0 / Tr / Tr); + break; + case 1: + case 2: + case 3: + default: + spec[i].G = 0.0; + spec[i].H = 0.0; + spec[i].S = 0.0; + break; } } } @@ -534,60 +577,65 @@ int HKF::HelgesonEquation(double T, double P, vector &spec){ return 1; } - - -//calculting the dielectric constant (relative permittivity) of pure water from T,P 1000C 5000bar Ref.(1) Appendix C -double HKF::diel_water(double T, double P){ //T K, P bar - double k0,k1,k2,k3,k4,Tr,z,dens; - double a1,a2,a3,a4,a5,a6,a7,a8,a9,a10; +// calculting the dielectric constant (relative permittivity) of pure water from T,P 1000C 5000bar Ref.(1) Appendix C +double HKF::diel_water(double T, double P) +{ // T K, P bar + double k0, k1, k2, k3, k4, Tr, z, dens; + double a1, a2, a3, a4, a5, a6, a7, a8, a9, a10; Tr = 298.15; - z = T/Tr; - dens= VLE::density_H2O(T,P); //Ref.(3) - a1 = 14.70333593; //Table C1 Ref.(1) - a2 = 212.8462733; - a3 = -115.4445173; - a4 = 19.55210915; - a5 = -83.30347980; - a6 = 32.13240048; - a7 = -6.694098645; - a8 = -37.86202045; - a9 = 68.87359646; - a10= -27.29401652; - k0 = 1.0; //(C2) - k1 = a1/z;//(C3) - k2 = a2/z +a3 +a4*z;//(C4) - k3 = a5/z +a6*z +a7*z*z;//(C5) - k4 = a8/z/z +a9/z +a10;//(C6) - return k0 +k1*dens +k2*dens*dens + k3*pow(dens,3.0) +k4*pow(dens,4.0); //(C1) + z = T / Tr; + dens = VLE::density_H2O(T, P); // Ref.(3) + a1 = 14.70333593; // Table C1 Ref.(1) + a2 = 212.8462733; + a3 = -115.4445173; + a4 = 19.55210915; + a5 = -83.30347980; + a6 = 32.13240048; + a7 = -6.694098645; + a8 = -37.86202045; + a9 = 68.87359646; + a10 = -27.29401652; + k0 = 1.0; //(C2) + k1 = a1 / z; //(C3) + k2 = a2 / z + a3 + a4 * z; //(C4) + k3 = a5 / z + a6 * z + a7 * z * z; //(C5) + k4 = a8 / z / z + a9 / z + a10; //(C6) + return k0 + k1 * dens + k2 * dens * dens + k3 * pow(dens, 3.0) + k4 * pow(dens, 4.0); //(C1) } - - -double HKF::Ydiff(double T, double P){ - return 1.0/diel_water(T,P); +double HKF::Ydiff(double T, double P) +{ + return 1.0 / diel_water(T, P); } -double HKF::Yfunc(double T, double P){ - return -NR::dfridrX(Ydiff,T,P); +double HKF::Yfunc(double T, double P) +{ + return -NR::dfridrX(Ydiff, T, P); } - -double HKF::gfunc(double T, double P){ - double Dw,ag,bg,a1,a2,a3,Tf,Pf; - Dw = VLE::density_H2O(T,P); //Ref.(3) - if(Dw>=1.0) return 0.0;//Fig.6 & p811 Ref.(1) - else{ - T = T-273.15; - ag= -2.037662 +5.747000E-3*T -6.557892E-6*T*T; //Eq(25) Table 3 p807 Ref.(1) - bg= 6.107361 -1.074377E-2*T +1.268348E-5*T*T; //Eq(26) - if(T<155.0 || P>1000.0) return ag*pow((1.0-Dw),bg);//Eq(24) Ref.(1) Fig.6 - else{ - a1= 3.66666E-16; //Table.4 Ref.(1) - a2= -1.504956E-10; - a3= 5.01799E-14; - Tf= (T-155.0)/300.0; - Pf= 1000.0-P; - return ag*pow((1.0-Dw),bg)-(pow(Tf,4.8)+a1*pow(Tf,16))*(a2*pow(Pf,3.0)+a3*pow(Pf,4.0));//Eq(32) & Eq(33) Ref.(1) +double HKF::gfunc(double T, double P) +{ + double Dw, ag, bg, a1, a2, a3, Tf, Pf; + Dw = VLE::density_H2O(T, P); // Ref.(3) + if (Dw >= 1.0) + return 0.0; // Fig.6 & p811 Ref.(1) + else + { + T = T - 273.15; + ag = -2.037662 + 5.747000E-3 * T - 6.557892E-6 * T * T; // Eq(25) Table 3 p807 Ref.(1) + bg = 6.107361 - 1.074377E-2 * T + 1.268348E-5 * T * T; // Eq(26) + if (T < 155.0 || P > 1000.0) + return ag * pow((1.0 - Dw), bg); // Eq(24) Ref.(1) Fig.6 + else + { + a1 = 3.66666E-16; // Table.4 Ref.(1) + a2 = -1.504956E-10; + a3 = 5.01799E-14; + Tf = (T - 155.0) / 300.0; + Pf = 1000.0 - P; + return ag * pow((1.0 - Dw), bg) + - (pow(Tf, 4.8) + a1 * pow(Tf, 16)) + * (a2 * pow(Pf, 3.0) + a3 * pow(Pf, 4.0)); // Eq(32) & Eq(33) Ref.(1) } } } diff --git a/GCC/HKF.h b/GCC/HKF.h index 97da49253..2be890140 100644 --- a/GCC/HKF.h +++ b/GCC/HKF.h @@ -11,58 +11,57 @@ #include #include -//using namespace std; +// using namespace std; class HKF { private: - public: HKF(void); ~HKF(void); -/* Data */ + /* Data */ typedef struct { - //input - std::string name0; //name in Helgeson datafile - //from datafile + // input + std::string name0; // name in Helgeson datafile + // from datafile std::string name; - std::string abbrev; //abbreviation - std::string scform; //structural chemical formula - std::string ecform; //elemental chemical formula + std::string abbrev; // abbreviation + std::string scform; // structural chemical formula + std::string ecform; // elemental chemical formula std::string ref[2]; - double charge; //charge - int type ; //phase flag - //0-minerals that do not undergo phase transitions - //1-minerals that undergo one phase transition - //2-minerals that undergo two phase transitions - //3-minerals that undergo three phase transitions - //4-gases - //5-aqueous species - double param[9][4]; //parameters - //calculating result - double S; //entropy - double H; //enthalpy - double G; //Gibbs free energy - double V; //volume - double Cp;//heat capacity - }SpeciesData; + double charge; // charge + int type; // phase flag + // 0-minerals that do not undergo phase transitions + // 1-minerals that undergo one phase transition + // 2-minerals that undergo two phase transitions + // 3-minerals that undergo three phase transitions + // 4-gases + // 5-aqueous species + double param[9][4]; // parameters + // calculating result + double S; // entropy + double H; // enthalpy + double G; // Gibbs free energy + double V; // volume + double Cp; // heat capacity + } SpeciesData; static std::vector HKFspecies; -/* Methods */ - static int load_param(std::vector &spec, std::vector name_type, std::vector phase_type); - //species storage - //name type: 0-name, 1-scform, 2-abbrev, 3-ecform, others-all - //phase type: 0-5 SpeciesData.type, others- last found in database - static int HelgesonEquation(double T, double P, std::vector &spec); + /* Methods */ + static int load_param(std::vector& spec, std::vector name_type, std::vector phase_type); + // species storage + // name type: 0-name, 1-scform, 2-abbrev, 3-ecform, others-all + // phase type: 0-5 SpeciesData.type, others- last found in database + static int HelgesonEquation(double T, double P, std::vector& spec); static double HKFcalc(double T, double P, int ghs, std::string name, int sub, int type); - //T K, P bar, - //ghs 0-gibbs energy 1-enthalpy 2-entropy, - //name, sub 0-name 1-scform 2-abbrev 3-ecform other-all, - //type 0-min 1-min 2-min 3-min 4-gases 5-aq others-last found in list + // T K, P bar, + // ghs 0-gibbs energy 1-enthalpy 2-entropy, + // name, sub 0-name 1-scform 2-abbrev 3-ecform other-all, + // type 0-min 1-min 2-min 3-min 4-gases 5-aq others-last found in list static double HKFcalcw(double T, double P, int ghs); @@ -77,9 +76,9 @@ class HKF static double Ydiff(double T, double P); static double gfunc(double T, double P); - static int HKF_OGS_loadparam(std::string species_name0, int &type, double &charge, double param[][4]); - static int HKF_OGS_calc(double T, double P, double &G, double &H, double &S, int type, double charge, double param[][4]); + static int HKF_OGS_loadparam(std::string species_name0, int& type, double& charge, double param[][4]); + static int HKF_OGS_calc(double T, double P, double& G, double& H, double& S, int type, double charge, + double param[][4]); static void entrance(void); }; - diff --git a/GCC/IAPWS-IF97.cpp b/GCC/IAPWS-IF97.cpp index d6abbfc3d..1d2cc39f0 100644 --- a/GCC/IAPWS-IF97.cpp +++ b/GCC/IAPWS-IF97.cpp @@ -16,314 +16,339 @@ #include "Brent/brent.hpp" using namespace std; - double IF97::R, IF97::Rm, IF97::M, IF97::Tc, IF97::Pc, IF97::Dc, IF97::Tt, IF97::Pt, IF97::Tb; double IF97::TT, IF97::PP; //----------------------------- -IF97::IF97(void){} -IF97::~IF97(void){} - -void IF97::ReferenceConstants(void){ - R = 0.461526 ;//kJ kg-1 K-1, (1.1) - Rm = 8.31451 ;//kJ kmol-1 K-1, (1.2) - M = 18.015257 ;//kg kmol-1, (1.3) - Tc = 647.096 ;//K , (1.4) - Pc = 22.064 ;//MPa , (1.5) - Dc = 322.0 ;//kg m-3, (1.6) - Tt = 273.16 ;//K , (1.7) - Pt = 611.657 ;//Pa , (1.8) - Tb = 373.1243 ;//K , (1.9) +IF97::IF97(void) +{ +} +IF97::~IF97(void) +{ } +void IF97::ReferenceConstants(void) +{ + R = 0.461526; // kJ kg-1 K-1, (1.1) + Rm = 8.31451; // kJ kmol-1 K-1, (1.2) + M = 18.015257; // kg kmol-1, (1.3) + Tc = 647.096; // K , (1.4) + Pc = 22.064; // MPa , (1.5) + Dc = 322.0; // kg m-3, (1.6) + Tt = 273.16; // K , (1.7) + Pt = 611.657; // Pa , (1.8) + Tb = 373.1243; // K , (1.9) +} -double IF97::Psat(double T){ - double A,B,C,theta,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10; - n1 = 0.11670521452767e+04; +double IF97::Psat(double T) +{ + double A, B, C, theta, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10; + n1 = 0.11670521452767e+04; n2 = -0.72421316703206e+06; n3 = -0.17073846940092e+02; - n4 = 0.12020824702470e+05; + n4 = 0.12020824702470e+05; n5 = -0.32325550322333e+07; - n6 = 0.14915108613530e+02; + n6 = 0.14915108613530e+02; n7 = -0.48232657361591e+04; - n8 = 0.40511340542057e+06; + n8 = 0.40511340542057e+06; n9 = -0.23855557567849e+00; - n10= 0.65017534844798e+03; - theta = T+n9/(T-n10); - A = pow(theta,2.0)+n1*theta+n2; - B = n3*pow(theta,2.0)+n4*theta+n5; - C = n6*pow(theta,2.0)+n7*theta+n8; - return pow(2.0*C/(-B+pow(B*B-4.0*A*C,0.5)),4.0); + n10 = 0.65017534844798e+03; + theta = T + n9 / (T - n10); + A = pow(theta, 2.0) + n1 * theta + n2; + B = n3 * pow(theta, 2.0) + n4 * theta + n5; + C = n6 * pow(theta, 2.0) + n7 * theta + n8; + return pow(2.0 * C / (-B + pow(B * B - 4.0 * A * C, 0.5)), 4.0); } -double IF97::Tsat(double P){ - double D,E,F,G,beta,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10; - n1 = 0.11670521452767e+04; +double IF97::Tsat(double P) +{ + double D, E, F, G, beta, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10; + n1 = 0.11670521452767e+04; n2 = -0.72421316703206e+06; n3 = -0.17073846940092e+02; - n4 = 0.12020824702470e+05; + n4 = 0.12020824702470e+05; n5 = -0.32325550322333e+07; - n6 = 0.14915108613530e+02; + n6 = 0.14915108613530e+02; n7 = -0.48232657361591e+04; - n8 = 0.40511340542057e+06; + n8 = 0.40511340542057e+06; n9 = -0.23855557567849e+00; - n10= 0.65017534844798e+03; - beta=pow(P,0.25); - E = pow(beta,2.0)+n3*beta+n6; - F = n1*pow(beta,2.0)+n4*beta+n7; - G = n2*pow(beta,2.0)+n5*beta+n8; - D = 2.0*G/(-1.0*F-pow(pow(F,2.0)-4.0*E*G,0.5)); - return 0.5*(n10+D-pow(pow(n10+D,2.0)-4.0*(n9+n10*D),0.5)); + n10 = 0.65017534844798e+03; + beta = pow(P, 0.25); + E = pow(beta, 2.0) + n3 * beta + n6; + F = n1 * pow(beta, 2.0) + n4 * beta + n7; + G = n2 * pow(beta, 2.0) + n5 * beta + n8; + D = 2.0 * G / (-1.0 * F - pow(pow(F, 2.0) - 4.0 * E * G, 0.5)); + return 0.5 * (n10 + D - pow(pow(n10 + D, 2.0) - 4.0 * (n9 + n10 * D), 0.5)); } -double IF97::Pb23(double T){ - const double B23_N[6] - = { 0, 0.34805185628969E+03, -0.11671859879975E+01, 0.10192970039326E-02, 0.57254459862746E+03, 0.13918839778870E+02 }; - return B23_N[1]+B23_N[2]*T+B23_N[3]*T*T; +double IF97::Pb23(double T) +{ + const double B23_N[6] = {0, + 0.34805185628969E+03, + -0.11671859879975E+01, + 0.10192970039326E-02, + 0.57254459862746E+03, + 0.13918839778870E+02}; + return B23_N[1] + B23_N[2] * T + B23_N[3] * T * T; } -double IF97::Tb23(double P){ - const double B23_N[6] - = { 0, 0.34805185628969E+03, -0.11671859879975E+01, 0.10192970039326E-02, 0.57254459862746E+03, 0.13918839778870E+02 }; - return B23_N[4]+pow((P-B23_N[5])/B23_N[3],0.5); +double IF97::Tb23(double P) +{ + const double B23_N[6] = {0, + 0.34805185628969E+03, + -0.11671859879975E+01, + 0.10192970039326E-02, + 0.57254459862746E+03, + 0.13918839778870E+02}; + return B23_N[4] + pow((P - B23_N[5]) / B23_N[3], 0.5); } -int IF97::region(double T, double P){ - double Ps,P23; - if (T<=623.15){ - Ps=Psat(T); - if(P==Ps) return 4; - else if(P>Ps) return 1; - else return 2; +int IF97::region(double T, double P) +{ + double Ps, P23; + if (T <= 623.15) + { + Ps = Psat(T); + if (P == Ps) + return 4; + else if (P > Ps) + return 1; + else + return 2; } - else{ - P23=Pb23(T); - if(P>P23) return 3; - else return 2; + else + { + P23 = Pb23(T); + if (P > P23) + return 3; + else + return 2; } } - - - -double IF97::g1PT(double P, double T){ - - // REGION 1 CORRELATION DATA - #define REG1_COUNT 34 - const int REGION1_I[REG1_COUNT] = { - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4, - 4, 4, 5, 8, 8, 21, 23, 29, 30, 31, 32 - }; - const int REGION1_J[REG1_COUNT] = { - -2, -1, 0, 1, 2, 3, 4, 5, -9, -7, -1, 0, 1, 3, -3, 0, 1, 3, 17, -4, - 0, 6, -5, -2, 10, -8, -11, -6, -29, -31, -38, -39, -40, -41 - }; - const double REGION1_N[REG1_COUNT] = { - 0.14632971213167E+00, -0.84548187169114E+00, -0.37563603672040E+01, - 0.33855169168385E+01, -0.95791963387872E+00, 0.15772038513228E+00, -0.16616417199501E-01, - 0.81214629983568E-03, 0.28319080123804E-03, -0.60706301565874E-03, -0.18990068218419E-01, - -0.32529748770505E-01, -0.21841717175414E-01, -0.52838357969930E-04, -0.47184321073267E-03, - -0.30001780793026E-03, 0.47661393906987E-04, -0.44141845330846E-05, -0.72694996297594E-15, - -0.31679644845054E-04, -0.28270797985312E-05, -0.85205128120103E-09, -0.22425281908000E-05, - -0.65171222895601E-06, -0.14341729937924E-12, -0.40516996860117E-06, -0.12734301741641E-08, - -0.17424871230634E-09, -0.68762131295531E-18, 0.14478307828521E-19, 0.26335781662795E-22, - -0.11947622640071E-22, 0.18228094581404E-23, -0.93537087292458E-25 - }; +double IF97::g1PT(double P, double T) +{ +// REGION 1 CORRELATION DATA +#define REG1_COUNT 34 + const int REGION1_I[REG1_COUNT] + = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 8, 8, 21, 23, 29, 30, 31, 32}; + const int REGION1_J[REG1_COUNT] = {-2, -1, 0, 1, 2, 3, 4, 5, -9, -7, -1, 0, 1, 3, -3, 0, 1, + 3, 17, -4, 0, 6, -5, -2, 10, -8, -11, -6, -29, -31, -38, -39, -40, -41}; + const double REGION1_N[REG1_COUNT] + = {0.14632971213167E+00, -0.84548187169114E+00, -0.37563603672040E+01, 0.33855169168385E+01, + -0.95791963387872E+00, 0.15772038513228E+00, -0.16616417199501E-01, 0.81214629983568E-03, + 0.28319080123804E-03, -0.60706301565874E-03, -0.18990068218419E-01, -0.32529748770505E-01, + -0.21841717175414E-01, -0.52838357969930E-04, -0.47184321073267E-03, -0.30001780793026E-03, + 0.47661393906987E-04, -0.44141845330846E-05, -0.72694996297594E-15, -0.31679644845054E-04, + -0.28270797985312E-05, -0.85205128120103E-09, -0.22425281908000E-05, -0.65171222895601E-06, + -0.14341729937924E-12, -0.40516996860117E-06, -0.12734301741641E-08, -0.17424871230634E-09, + -0.68762131295531E-18, 0.14478307828521E-19, 0.26335781662795E-22, -0.11947622640071E-22, + 0.18228094581404E-23, -0.93537087292458E-25}; int i; - double R=0.461526,Px=16.53,Tx=1386.0,Pi,Tau,res=0; - Pi = P/Px; - Tau= Tx/T; - for(i=0;i<34;i++) res += REGION1_N[i]*pow(7.1-Pi,REGION1_I[i])*pow(Tau-1.222,REGION1_J[i]); - return res*R*T; + double R = 0.461526, Px = 16.53, Tx = 1386.0, Pi, Tau, res = 0; + Pi = P / Px; + Tau = Tx / T; + for (i = 0; i < 34; i++) + res += REGION1_N[i] * pow(7.1 - Pi, REGION1_I[i]) * pow(Tau - 1.222, REGION1_J[i]); + return res * R * T; } -double IF97::g2PT(double P, double T){ - - // REGION 2 CORRELATION DATA - // Ideal Gas Series Data - #define REG2I_COUNT 9 - const int REGION2_J0[REG2I_COUNT] = { 0, 1, -5, -4, -3, -2, -1, 2, 3 }; - const double REGION2_N0[REG2I_COUNT] = { - -0.96927686500217E+01, 0.10086655968018E+02, -0.56087911283020E-02, - 0.71452738081455E-01, -0.40710498223928E+00, 0.14240819171444E+01, -0.43839511319450E+01, - -0.28408632460772E+00, 0.21268463753307E-01 - }; - // Residual Series Data - #define REG2R_COUNT 43 - const int REGION2_I[REG2R_COUNT] = { - 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 5, 6, 6, 6, 7, - 7, 7, 8, 8, 9, 10, 10, 10, 16, 16, 18, 20, 20, 20, 21, 22, 23, 24, 24, 24 - }; - const int REGION2_J[REG2R_COUNT] = { - 0, 1, 2, 3, 6, 1, 2, 4, 7, 36, 0, 1, 3, 6, 35, 1, 2, 3, 7, 3, 16, 35, - 0, 11, 25, 8, 36, 13, 4, 10, 14, 29, 50, 57, 20, 35, 48, 21, 53, 39, 26, 40, 58 - }; - const double REGION2_N[REG2R_COUNT] = { - -0.17731742473213E-02, -0.17834862292358E-01, -0.45996013696365E-01, - -0.57581259083432E-01, -0.50325278727930E-01, -0.33032641670203E-04, -0.18948987516315E-03, - -0.39392777243355E-02, -0.43797295650573E-01, -0.26674547914087E-04, 0.20481737692309E-07, - 0.43870667284435E-06, -0.32277677238570E-04, -0.15033924542148E-02, -0.40668253562649E-01, - -0.78847309559367E-09, 0.12790717852285E-07, 0.48225372718507E-06, 0.22922076337661E-05, - -0.16714766451061E-10, -0.21171472321355E-02, -0.23895741934104E+02, -0.59059564324270E-17, - -0.12621808899101E-05, -0.38946842435739E-01, 0.11256211360459E-10, -0.82311340897998E+01, - 0.19809712802088E-07, 0.10406965210174E-18, -0.10234747095929E-12, -0.10018179379511E-08, - -0.80882908646985E-10, 0.10693031879409E+00, -0.33662250574171E+00, 0.89185845355421E-24, - 0.30629316876232E-12, -0.42002467698208E-05, -0.59056029685639E-25, 0.37826947613457E-05, - -0.12768608934681E-14, 0.73087610595061E-28, 0.55414715350778E-16, -0.94369707241210E-06 - }; +double IF97::g2PT(double P, double T) +{ +// REGION 2 CORRELATION DATA +// Ideal Gas Series Data +#define REG2I_COUNT 9 + const int REGION2_J0[REG2I_COUNT] = {0, 1, -5, -4, -3, -2, -1, 2, 3}; + const double REGION2_N0[REG2I_COUNT] = {-0.96927686500217E+01, 0.10086655968018E+02, -0.56087911283020E-02, + 0.71452738081455E-01, -0.40710498223928E+00, 0.14240819171444E+01, + -0.43839511319450E+01, -0.28408632460772E+00, 0.21268463753307E-01}; +// Residual Series Data +#define REG2R_COUNT 43 + const int REGION2_I[REG2R_COUNT] = {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 5, 6, 6, 6, + 7, 7, 7, 8, 8, 9, 10, 10, 10, 16, 16, 18, 20, 20, 20, 21, 22, 23, 24, 24, 24}; + const int REGION2_J[REG2R_COUNT] + = {0, 1, 2, 3, 6, 1, 2, 4, 7, 36, 0, 1, 3, 6, 35, 1, 2, 3, 7, 3, 16, 35, + 0, 11, 25, 8, 36, 13, 4, 10, 14, 29, 50, 57, 20, 35, 48, 21, 53, 39, 26, 40, 58}; + const double REGION2_N[REG2R_COUNT] + = {-0.17731742473213E-02, -0.17834862292358E-01, -0.45996013696365E-01, -0.57581259083432E-01, + -0.50325278727930E-01, -0.33032641670203E-04, -0.18948987516315E-03, -0.39392777243355E-02, + -0.43797295650573E-01, -0.26674547914087E-04, 0.20481737692309E-07, 0.43870667284435E-06, + -0.32277677238570E-04, -0.15033924542148E-02, -0.40668253562649E-01, -0.78847309559367E-09, + 0.12790717852285E-07, 0.48225372718507E-06, 0.22922076337661E-05, -0.16714766451061E-10, + -0.21171472321355E-02, -0.23895741934104E+02, -0.59059564324270E-17, -0.12621808899101E-05, + -0.38946842435739E-01, 0.11256211360459E-10, -0.82311340897998E+01, 0.19809712802088E-07, + 0.10406965210174E-18, -0.10234747095929E-12, -0.10018179379511E-08, -0.80882908646985E-10, + 0.10693031879409E+00, -0.33662250574171E+00, 0.89185845355421E-24, 0.30629316876232E-12, + -0.42002467698208E-05, -0.59056029685639E-25, 0.37826947613457E-05, -0.12768608934681E-14, + 0.73087610595061E-28, 0.55414715350778E-16, -0.94369707241210E-06}; int i; - double R=0.461526,Px=1.0,Tx=540.0,Pi,Tau,resI=0,resR=0; - Pi = P/Px; - Tau= Tx/T; - resI=log(Pi); - for(i=0;i<9; i++) resI += REGION2_N0[i]*pow(Tau,REGION2_J0[i]); - for(i=0;i<43;i++) resR += REGION2_N[i] *pow(Pi,REGION2_I[i])*pow(Tau-0.5,REGION2_J[i]); - return (resI+resR)*R*T; + double R = 0.461526, Px = 1.0, Tx = 540.0, Pi, Tau, resI = 0, resR = 0; + Pi = P / Px; + Tau = Tx / T; + resI = log(Pi); + for (i = 0; i < 9; i++) + resI += REGION2_N0[i] * pow(Tau, REGION2_J0[i]); + for (i = 0; i < 43; i++) + resR += REGION2_N[i] * pow(Pi, REGION2_I[i]) * pow(Tau - 0.5, REGION2_J[i]); + return (resI + resR) * R * T; } -double IF97::f3DT(double D, double T){ - - // CORRELATION DATA - #define REG3_COUNT 40 - const int REGION3_I[REG3_COUNT] = { - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, - 4, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 8, 9, 9, 10, 10, 11 - }; - const int REGION3_J[REG3_COUNT] = { - 0, 0, 1, 2, 7, 10, 12, 23, 2, 6, 15, 17, 0, 2, 6, 7, 22, 26, 0, 2, 4, - 16, 26, 0, 2, 4, 26, 1, 3, 26, 0, 2, 26, 2, 26, 2, 26, 0, 1, 26 - }; - const double REGION3_N[REG3_COUNT] = { - 0.10658070028513E+01, -0.15732845290239E+02, 0.20944396974307E+02, - -0.76867707878716E+01, 0.26185947787954E+01, -0.28080781148620E+01, 0.12053369696517E+01, - -0.84566812812502E-02, -0.12654315477714E+01, -0.11524407806681E+01, 0.88521043984318E+00, - -0.64207765181607E+00, 0.38493460186671E+00, -0.85214708824206E+00, 0.48972281541877E+01, - -0.30502617256965E+01, 0.39420536879154E-01, 0.12558408424308E+00, -0.27999329698710E+00, - 0.13899799569460E+01, -0.20189915023570E+01, -0.82147637173963E-02, -0.47596035734923E+00, - 0.43984074473500E-01, -0.44476435428739E+00, 0.90572070719733E+00, 0.70522450087967E+00, - 0.10770512626332E+00, -0.32913623258954E+00, -0.50871062041158E+00, -0.22175400873096E-01, - 0.94260751665092E-01, 0.16436278447961E+00, -0.13503372241348E-01, -0.14834345352472E-01, - 0.57922953628084E-03, 0.32308904703711E-02, 0.80964802996215E-04, -0.16557679795037E-03, - -0.44923899061815E-04 - }; +double IF97::f3DT(double D, double T) +{ +// CORRELATION DATA +#define REG3_COUNT 40 + const int REGION3_I[REG3_COUNT] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, + 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 8, 9, 9, 10, 10, 11}; + const int REGION3_J[REG3_COUNT] = {0, 0, 1, 2, 7, 10, 12, 23, 2, 6, 15, 17, 0, 2, 6, 7, 22, 26, 0, 2, + 4, 16, 26, 0, 2, 4, 26, 1, 3, 26, 0, 2, 26, 2, 26, 2, 26, 0, 1, 26}; + const double REGION3_N[REG3_COUNT] + = {0.10658070028513E+01, -0.15732845290239E+02, 0.20944396974307E+02, -0.76867707878716E+01, + 0.26185947787954E+01, -0.28080781148620E+01, 0.12053369696517E+01, -0.84566812812502E-02, + -0.12654315477714E+01, -0.11524407806681E+01, 0.88521043984318E+00, -0.64207765181607E+00, + 0.38493460186671E+00, -0.85214708824206E+00, 0.48972281541877E+01, -0.30502617256965E+01, + 0.39420536879154E-01, 0.12558408424308E+00, -0.27999329698710E+00, 0.13899799569460E+01, + -0.20189915023570E+01, -0.82147637173963E-02, -0.47596035734923E+00, 0.43984074473500E-01, + -0.44476435428739E+00, 0.90572070719733E+00, 0.70522450087967E+00, 0.10770512626332E+00, + -0.32913623258954E+00, -0.50871062041158E+00, -0.22175400873096E-01, 0.94260751665092E-01, + 0.16436278447961E+00, -0.13503372241348E-01, -0.14834345352472E-01, 0.57922953628084E-03, + 0.32308904703711E-02, 0.80964802996215E-04, -0.16557679795037E-03, -0.44923899061815E-04}; int i; - double R=0.461526,Dx=322.0,Tx=647.096,Delta,Tau,res=0; - Delta=D/Dx; - Tau=Tx/T; - res=REGION3_N[0]*log(Delta); - for(i=1;i<40;i++) res += REGION3_N[i]*pow(Delta,REGION3_I[i])*pow(Tau,REGION3_J[i]); - return res*R*T; + double R = 0.461526, Dx = 322.0, Tx = 647.096, Delta, Tau, res = 0; + Delta = D / Dx; + Tau = Tx / T; + res = REGION3_N[0] * log(Delta); + for (i = 1; i < 40; i++) + res += REGION3_N[i] * pow(Delta, REGION3_I[i]) * pow(Tau, REGION3_J[i]); + return res * R * T; } -double IF97::dpressure(double ds){ - return IF97::PP-ds*ds*NR::dfridrX(IF97::f3DT, ds, IF97::TT)*1.0e-3; +double IF97::dpressure(double ds) +{ + return IF97::PP - ds * ds * NR::dfridrX(IF97::f3DT, ds, IF97::TT) * 1.0e-3; } - -//Gibbs energy (kJ/kg) (T K, P Mpa) -double IF97::G(double T, double P){ - int rg=region(T,P); - double dens, res=0.0; - if(rg==1 || rg==4) res=IF97::g1PT(P,T); - if(rg==2) res=IF97::g2PT(P,T); - if(rg==3) { - dens=IF97::density(T,P); - res=IF97::f3DT(dens,T)+dens*NR::dfridrX(f3DT, dens, T); +// Gibbs energy (kJ/kg) (T K, P Mpa) +double IF97::G(double T, double P) +{ + int rg = region(T, P); + double dens, res = 0.0; + if (rg == 1 || rg == 4) + res = IF97::g1PT(P, T); + if (rg == 2) + res = IF97::g2PT(P, T); + if (rg == 3) + { + dens = IF97::density(T, P); + res = IF97::f3DT(dens, T) + dens * NR::dfridrX(f3DT, dens, T); } return res; } -//Specific enthalpy (kJ/kg) (T K, P Mpa) -double IF97::H(double T, double P){ - int rg=region(T,P); - double dens,res=0.0; - if(rg==1 || rg==4) res=IF97::g1PT(P,T)-T*NR::dfridrY(g1PT, P, T); - if(rg==2) res=IF97::g2PT(P,T)-T*NR::dfridrY(g2PT, P, T); - if(rg==3) { - dens=IF97::density(T,P); - res=IF97::f3DT(dens,T)-T*NR::dfridrY(f3DT, dens, T)+dens*NR::dfridrX(f3DT, dens, T); +// Specific enthalpy (kJ/kg) (T K, P Mpa) +double IF97::H(double T, double P) +{ + int rg = region(T, P); + double dens, res = 0.0; + if (rg == 1 || rg == 4) + res = IF97::g1PT(P, T) - T * NR::dfridrY(g1PT, P, T); + if (rg == 2) + res = IF97::g2PT(P, T) - T * NR::dfridrY(g2PT, P, T); + if (rg == 3) + { + dens = IF97::density(T, P); + res = IF97::f3DT(dens, T) - T * NR::dfridrY(f3DT, dens, T) + dens * NR::dfridrX(f3DT, dens, T); } return res; } -//Specific entropy (kJ/kg K) (T K, P Mpa) -double IF97::S(double T, double P){ - int rg=region(T,P); - double dens,res=0.0; - if(rg==1 || rg==4) res= -1.0*NR::dfridrY(g1PT, P, T); - if(rg==2) res= -1.0*NR::dfridrY(g2PT, P, T); - if(rg==3) { - dens=IF97::density(T,P); - res= -1.0*NR::dfridrY(f3DT, dens, T); +// Specific entropy (kJ/kg K) (T K, P Mpa) +double IF97::S(double T, double P) +{ + int rg = region(T, P); + double dens, res = 0.0; + if (rg == 1 || rg == 4) + res = -1.0 * NR::dfridrY(g1PT, P, T); + if (rg == 2) + res = -1.0 * NR::dfridrY(g2PT, P, T); + if (rg == 3) + { + dens = IF97::density(T, P); + res = -1.0 * NR::dfridrY(f3DT, dens, T); } return res; } - -//density (kg m^-3) (T K, P Mpa) -double IF97::density(double T, double P){ - int rg=region(T,P); - double res=0.0; - if(rg==1 || rg==4) res=1.0/NR::dfridrX(g1PT, P, T)*1.0e3; - if(rg==2) res=1.0/NR::dfridrX(g2PT, P, T)*1.0e3; - if(rg==3) { - IF97::TT=T; - IF97::PP=P; +// density (kg m^-3) (T K, P Mpa) +double IF97::density(double T, double P) +{ + int rg = region(T, P); + double res = 0.0; + if (rg == 1 || rg == 4) + res = 1.0 / NR::dfridrX(g1PT, P, T) * 1.0e3; + if (rg == 2) + res = 1.0 / NR::dfridrX(g2PT, P, T) * 1.0e3; + if (rg == 3) + { + IF97::TT = T; + IF97::PP = P; brent::local_min(85.0, 750.0, 1e-6, dpressure, res); } return res; } -//viscosity (Pa s) (T K, P Mpa) -double IF97::viscosity(double T, double P){ - - const int VISC_I[21] = { 0, 0, 0, 0, 1 ,1 ,1, 1, 1, 2, 2, 2 ,2, 2, 3, 3, 4, 4, 5, 6, 6 }; - const int VISC_J[21] = { 0, 1, 2, 3, 0, 1, 2, 3, 5, 0, 1, 2, 3, 4, 0, 1, 0, 3, 4, 3, 5 }; - const double VISC_N[21] = { - 0.520094, 0.850895e-1, -0.108374e1, -0.289555, 0.222531, 0.999115, 0.188797e1, 0.126613e1, - 0.120573, -0.281378, -0.906851, -0.772479, -0.489837, -0.257040, 0.161913, 0.257399, -0.325372e-1, - 0.698452e-1, 0.872102e-2, -0.435673e-2, -0.593264e-3 - }; - const double VISC_N0[5] = { 0, 0.167752e-1, 0.220462e-1, 0.6366564e-2, -0.241605e-2 }; +// viscosity (Pa s) (T K, P Mpa) +double IF97::viscosity(double T, double P) +{ + const int VISC_I[21] = {0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 4, 4, 5, 6, 6}; + const int VISC_J[21] = {0, 1, 2, 3, 0, 1, 2, 3, 5, 0, 1, 2, 3, 4, 0, 1, 0, 3, 4, 3, 5}; + const double VISC_N[21] + = {0.520094, 0.850895e-1, -0.108374e1, -0.289555, 0.222531, 0.999115, 0.188797e1, + 0.126613e1, 0.120573, -0.281378, -0.906851, -0.772479, -0.489837, -0.257040, + 0.161913, 0.257399, -0.325372e-1, 0.698452e-1, 0.872102e-2, -0.435673e-2, -0.593264e-3}; + const double VISC_N0[5] = {0, 0.167752e-1, 0.220462e-1, 0.6366564e-2, -0.241605e-2}; ReferenceConstants(); int i; - double Delta, Theta, res0=0, res1=0; - Delta=density(T,P)/Dc; - Theta=T/Tc; - for(i=1;i<=4;i++) res0 += VISC_N0[i]*pow(Theta, 1-i); - res0 = pow(Theta,0.5)*pow(res0,-1.0); - Theta=Tc/T; - for(i=0;i<21;i++) res1 += VISC_N[i]*pow(Delta-1.0, VISC_I[i])*pow(Theta-1.0,VISC_J[i]); - res1 = exp(Delta*res1); - return res0*res1*1.0e-6; + double Delta, Theta, res0 = 0, res1 = 0; + Delta = density(T, P) / Dc; + Theta = T / Tc; + for (i = 1; i <= 4; i++) + res0 += VISC_N0[i] * pow(Theta, 1 - i); + res0 = pow(Theta, 0.5) * pow(res0, -1.0); + Theta = Tc / T; + for (i = 0; i < 21; i++) + res1 += VISC_N[i] * pow(Delta - 1.0, VISC_I[i]) * pow(Theta - 1.0, VISC_J[i]); + res1 = exp(Delta * res1); + return res0 * res1 * 1.0e-6; } -//dielectric constant () -double IF97::dielectric(double T, double P){ - const int DIEL_I[11] = { 1, 1, 1, 2, 3, 3, 4, 5, 6, 7, 10 }; - const double DIEL_J[11] = { 0.25, 1, 2.5, 1.5, 1.5, 2.5, 2, 2, 5, 0.5, 10 }; - const double DIEL_N[12] = { - 0.978224486826, -0.957771379375, 0.237511794148, 0.714692244396, -0.298217036956, -0.108863472196, - 0.949327488264e-1, -0.980469816509e-2, 0.165167634970e-4, 0.937359795772e-4, -0.123179218720e-9, 0.196096504426e-2 - }; +// dielectric constant () +double IF97::dielectric(double T, double P) +{ + const int DIEL_I[11] = {1, 1, 1, 2, 3, 3, 4, 5, 6, 7, 10}; + const double DIEL_J[11] = {0.25, 1, 2.5, 1.5, 1.5, 2.5, 2, 2, 5, 0.5, 10}; + const double DIEL_N[12] = {0.978224486826, -0.957771379375, 0.237511794148, 0.714692244396, + -0.298217036956, -0.108863472196, 0.949327488264e-1, -0.980469816509e-2, + 0.165167634970e-4, 0.937359795772e-4, -0.123179218720e-9, 0.196096504426e-2}; int i; double k, Na, a, eps0, u, Mw; double A, B, g, rho, Delta, Tau, eps; - k = 1.380658e-23; //J K-1 Boltzmann s constant k - Na = 6.0221367e23; //mol-1 Avogadro s number NA - a = 1.636e-40; //C2 J-1 m2 Mean molecular polarizability a - eps0 = 8.854187817e-12; //C2 J-1 m-1 Permittivity of vacuum e 0 - u = 6.138e-30; //C m Molecular dipole moment µ - Mw = 0.018015268; //kg mol-1 Molar mass M - rho = density(T,P); + k = 1.380658e-23; // J K-1 Boltzmann s constant k + Na = 6.0221367e23; // mol-1 Avogadro s number NA + a = 1.636e-40; // C2 J-1 m2 Mean molecular polarizability a + eps0 = 8.854187817e-12; // C2 J-1 m-1 Permittivity of vacuum e 0 + u = 6.138e-30; // C m Molecular dipole moment µ + Mw = 0.018015268; // kg mol-1 Molar mass M + rho = density(T, P); ReferenceConstants(); - Delta= rho/Dc; - Tau = Tc/T; - g=1.0+DIEL_N[11]*Delta*pow((Tc/228.0/Tau-1),-1.2); - for(i=0;i<11;i++) g += DIEL_N[i]*pow(Delta,DIEL_I[i])*pow(Tau,DIEL_J[i]); - A = Na*pow(u,2.0)*rho*g/(Mw*eps0*k*T); - B = Na*a*rho/(3.0*Mw*eps0); - eps=(1.0+A+5.0*B+pow((9.0+2.0*A+18.0*B+pow(A,2.0)+10.0*A*B+9.0*pow(B,2.0)),0.5))/(4.0*(1.0-B)); + Delta = rho / Dc; + Tau = Tc / T; + g = 1.0 + DIEL_N[11] * Delta * pow((Tc / 228.0 / Tau - 1), -1.2); + for (i = 0; i < 11; i++) + g += DIEL_N[i] * pow(Delta, DIEL_I[i]) * pow(Tau, DIEL_J[i]); + A = Na * pow(u, 2.0) * rho * g / (Mw * eps0 * k * T); + B = Na * a * rho / (3.0 * Mw * eps0); + eps = (1.0 + A + 5.0 * B + pow((9.0 + 2.0 * A + 18.0 * B + pow(A, 2.0) + 10.0 * A * B + 9.0 * pow(B, 2.0)), 0.5)) + / (4.0 * (1.0 - B)); return eps; } diff --git a/GCC/IAPWS-IF97.h b/GCC/IAPWS-IF97.h index c2edee4ff..990369efc 100644 --- a/GCC/IAPWS-IF97.h +++ b/GCC/IAPWS-IF97.h @@ -7,20 +7,19 @@ * */ -//IAPWS-IF97 for density and viscosity +// IAPWS-IF97 for density and viscosity class IF97 { private: - public: IF97(void); ~IF97(void); -/* Data */ + /* Data */ static double R, Rm, M, Tc, Pc, Dc, Tt, Pt, Tb; static double TT, PP; -/* Methods */ + /* Methods */ static void ReferenceConstants(void); static double Psat(double); static double Tsat(double); @@ -28,15 +27,13 @@ class IF97 static double Tb23(double); static int region(double, double); - static double G(double, double); //(T K, P Mpa) - static double H(double, double); //(T K, P Mpa) - static double S(double, double); //(T K, P Mpa) - - - static double density(double, double); //density (kg m^-3) (T K, P Mpa) - static double viscosity(double, double); //viscosity (Pa s) (T K, P Mpa) - static double dielectric(double, double);//dielectric constant () + static double G(double, double); //(T K, P Mpa) + static double H(double, double); //(T K, P Mpa) + static double S(double, double); //(T K, P Mpa) + static double density(double, double); // density (kg m^-3) (T K, P Mpa) + static double viscosity(double, double); // viscosity (Pa s) (T K, P Mpa) + static double dielectric(double, double); // dielectric constant () static double g1PT(double, double); static double g2PT(double, double); @@ -44,6 +41,3 @@ class IF97 static double dpressure(double); static void entrance(void); }; - - - diff --git a/GCC/IO.cpp b/GCC/IO.cpp index 4ac4ce961..38abb9b8a 100644 --- a/GCC/IO.cpp +++ b/GCC/IO.cpp @@ -23,13 +23,16 @@ using namespace std; - -IO::IO(void){} -IO::~IO(void){} - +IO::IO(void) +{ +} +IO::~IO(void) +{ +} /* ====database convert subroutin=== */ -int IO::file2code(string datafile_in, string codefile_out){ +int IO::file2code(string datafile_in, string codefile_out) +{ int i; ifstream in; ofstream out; @@ -37,20 +40,24 @@ int IO::file2code(string datafile_in, string codefile_out){ vector pies; cout << endl << " Reading " << datafile_in << " file... ... "; - in.open(datafile_in.c_str(),ios::in); - out.open(codefile_out.c_str(),ios::out); + in.open(datafile_in.c_str(), ios::in); + out.open(codefile_out.c_str(), ios::out); out << "#include " << endl; out << "using namespace std;" << endl; out << "const string " << codefile_out << "[]= {" << endl; - if(in.good()){ - //cout << " OK " << endl; - while(1){ - if(in.eof()) break; + if (in.good()) + { + // cout << " OK " << endl; + while (1) + { + if (in.eof()) + break; getline(in, instr); - pies=IO::string2vector(instr); - if((int)pies.size()>0 && pies[0].substr(0,1)!="*"){ + pies = IO::string2vector(instr); + if ((int)pies.size() > 0 && pies[0].substr(0, 1) != "*") + { out << "\""; - for(i=0;i<(int)pies.size();i++) + for (i = 0; i < (int)pies.size(); i++) out << pies[i] << " "; out << "\"," << endl; } @@ -65,26 +72,29 @@ int IO::file2code(string datafile_in, string codefile_out){ } /*=========================================*/ - - -int IO::file2vector(string datafile_in, vector &vector_out){ +int IO::file2vector(string datafile_in, vector& vector_out) +{ int i; ifstream in; string instr, pies0; vector pies; - //cout << endl << " Reading " << datafile_in << " file... ... " ; - in.open(datafile_in.c_str(),ios::in); - if(in.good()){ - //cout << " OK. " << endl; - while(1){ - if(in.eof()) break; + // cout << endl << " Reading " << datafile_in << " file... ... " ; + in.open(datafile_in.c_str(), ios::in); + if (in.good()) + { + // cout << " OK. " << endl; + while (1) + { + if (in.eof()) + break; getline(in, instr); - pies=IO::string2vector(instr); - if((int)pies.size()>0 && pies[0].substr(0,1)!="*"){ - pies0=""; - for(i=0;i<(int)pies.size();i++) - pies0 += pies[i]+" "; + pies = IO::string2vector(instr); + if ((int)pies.size() > 0 && pies[0].substr(0, 1) != "*") + { + pies0 = ""; + for (i = 0; i < (int)pies.size(); i++) + pies0 += pies[i] + " "; vector_out.push_back(pies0); } } @@ -96,38 +106,41 @@ int IO::file2vector(string datafile_in, vector &vector_out){ return 1; } - -//split string line to pieces, and store in a vector -vector IO::string2vector(string line){ +// split string line to pieces, and store in a vector +vector IO::string2vector(string line) +{ stringstream in; string sp; vector pies; pies.clear(); in.str(line); - while(1){ - if(in.eof()) break; - sp=""; + while (1) + { + if (in.eof()) + break; + sp = ""; in >> sp; - if(sp!="") pies.push_back(sp); + if (sp != "") + pies.push_back(sp); } return pies; } - -//0-Li, 1-Na, 2-K, 3-Mg, 4-Ca, 5-Cl, 6-SO4, 7-CO3 -//convert chemical formula to index -vector IO::formula2index(std::string formula){ - const string Chemical_Element[10]={"Li", "Na", "K", "Mg", "Ca", "Cl", "S", "C", "H", "O"}; - int i,j,n,symb_asc,is_bracket; - vector id_iz,type_x; +// 0-Li, 1-Na, 2-K, 3-Mg, 4-Ca, 5-Cl, 6-SO4, 7-CO3 +// convert chemical formula to index +vector IO::formula2index(std::string formula) +{ + const string Chemical_Element[10] = {"Li", "Na", "K", "Mg", "Ca", "Cl", "S", "C", "H", "O"}; + int i, j, n, symb_asc, is_bracket; + vector id_iz, type_x; vector bracket_ia, bracket_ib, bracket_iz, bracket_ia0, bracket_ib0; // CB clear vector element_ia, element_ib, element_iz; - vector number_ia, number_ib, number_iz; + vector number_ia, number_ib, number_iz; vector element_name; id_iz.clear(); type_x.clear(); - n=int(formula.size()); + n = int(formula.size()); element_ia.clear(); element_ib.clear(); @@ -138,152 +151,165 @@ vector IO::formula2index(std::string formula){ number_ib.clear(); number_iz.clear(); - bracket_ia.clear(); //to store begin position of bracket - bracket_ib.clear(); //to store end position of bracket + bracket_ia.clear(); // to store begin position of bracket + bracket_ib.clear(); // to store end position of bracket bracket_iz.clear(); bracket_ia0.clear(); bracket_ib0.clear(); // 0-A-Z, 1-a-z, 2-0-9, 3-[(, 4-]), 5-others - for(i=0;i=65 && symb_asc<=90) //A-Z + if (symb_asc >= 65 && symb_asc <= 90) // A-Z type_x.push_back(0); - else if(symb_asc>=97 && symb_asc<=122) //a-z + else if (symb_asc >= 97 && symb_asc <= 122) // a-z type_x.push_back(1); - else if(symb_asc>=48 && symb_asc<=57) //0-9 + else if (symb_asc >= 48 && symb_asc <= 57) // 0-9 type_x.push_back(2); - else if(symb_asc==40 || symb_asc==91) // [( + else if (symb_asc == 40 || symb_asc == 91) // [( type_x.push_back(3); - else if(symb_asc==41 || symb_asc==93) // ]) + else if (symb_asc == 41 || symb_asc == 93) // ]) type_x.push_back(4); else type_x.push_back(5); } - type_x.push_back(-1); //set string end mark - + type_x.push_back(-1); // set string end mark // 0-A-Z, 1-a-z, 2-0-9, 3-[(, 4-]), 5-others - //search for chemical elements - for(i=0;i0 && type_x[i-1]!=2) + else if (type_x[i] == 2) + { + if (i > 0 && type_x[i - 1] != 2) number_ia.push_back(i); - if(i>0 && type_x[i]==2 && type_x[i+1]!=2) + if (i > 0 && type_x[i] == 2 && type_x[i + 1] != 2) number_ib.push_back(i); - } - else if(type_x[i]==3) + } + else if (type_x[i] == 3) bracket_ia0.push_back(i); - else if(type_x[i]==4) + else if (type_x[i] == 4) bracket_ib0.push_back(i); } - //to check the bracket symb is correct or not, e.g. (( ... )) - for(i=0;i<(int)bracket_ia0.size();i++){ - is_bracket=0; - for(j=0;j<(int)bracket_ib0.size();j++){ - if(i==(int)bracket_ia0.size()-1){ - if(bracket_ib0[j]>bracket_ia0[i]) - is_bracket=1; + // to check the bracket symb is correct or not, e.g. (( ... )) + for (i = 0; i < (int)bracket_ia0.size(); i++) + { + is_bracket = 0; + for (j = 0; j < (int)bracket_ib0.size(); j++) + { + if (i == (int)bracket_ia0.size() - 1) + { + if (bracket_ib0[j] > bracket_ia0[i]) + is_bracket = 1; } - else{ - if(bracket_ib0[j]>bracket_ia0[i] && bracket_ib0[j] bracket_ia0[i] && bracket_ib0[j] < bracket_ia0[i + 1]) + is_bracket = 1; } } - if(is_bracket==1) + if (is_bracket == 1) bracket_ia.push_back(bracket_ia0[i]); } - for(i=0;i<(int)bracket_ib0.size();i++){ - is_bracket=0; - for(j=0;j<(int)bracket_ia0.size();j++){ - if(i==0){ - if(bracket_ia0[j]bracket_ib0[i-1]) - is_bracket=1; + else + { + if (bracket_ia0[j] < bracket_ib0[i] && bracket_ia0[j] > bracket_ib0[i - 1]) + is_bracket = 1; } } - if(is_bracket==1) + if (is_bracket == 1) bracket_ib.push_back(bracket_ib0[i]); } + for (i = 0; i < (int)number_ia.size(); i++) + number_iz.push_back(atoi(formula.substr(number_ia[i], number_ib[i] - number_ia[i] + 1).c_str())); - - for(i=0;i<(int)number_ia.size();i++) - number_iz.push_back(atoi(formula.substr(number_ia[i],number_ib[i]-number_ia[i]+1).c_str())); - - for(i=0;i<(int)element_name.size();i++) - if(type_x[element_ib[i]+1]==2) - for(j=0;j<(int)number_iz.size();j++){ - if(element_ib[i]+1==number_ia[j]) + for (i = 0; i < (int)element_name.size(); i++) + if (type_x[element_ib[i] + 1] == 2) + for (j = 0; j < (int)number_iz.size(); j++) + { + if (element_ib[i] + 1 == number_ia[j]) element_iz.push_back(number_iz[j]); } else element_iz.push_back(1); - for(i=0;i<(int)bracket_ia.size();i++) - if(type_x[bracket_ib[i]+1]==2) - for(j=0;j<(int)number_iz.size();j++){ - if(bracket_ib[i]+1==number_ia[j]) + for (i = 0; i < (int)bracket_ia.size(); i++) + if (type_x[bracket_ib[i] + 1] == 2) + for (j = 0; j < (int)number_iz.size(); j++) + { + if (bracket_ib[i] + 1 == number_ia[j]) bracket_iz.push_back(number_iz[j]); } else bracket_iz.push_back(1); - for(i=0;i<(int)bracket_ia.size();i++) - for(j=0;j<(int)element_ia.size();j++) - if(element_ia[j]>bracket_ia[i] && element_ib[j] bracket_ia[i] && element_ib[j] < bracket_ib[i]) element_iz[j] *= bracket_iz[i]; - for(i=0;i<10;i++){ + for (i = 0; i < 10; i++) + { id_iz.push_back(0); - for(j=0;j IO::formula2index_total(std::string formula){ - int i,j,n,symb_asc,is_bracket; - vector id_iz,type_x; +// convert chemical formula to index, from total list +vector IO::formula2index_total(std::string formula) +{ + int i, j, n, symb_asc, is_bracket; + vector id_iz, type_x; vector bracket_ia, bracket_ib, bracket_iz, bracket_ia0, bracket_ib0; // CB clear vector element_ia, element_ib, element_iz; - vector number_ia, number_ib, number_iz; + vector number_ia, number_ib, number_iz; vector element_name; - //get Chemical Element list from species.h + // get Chemical Element list from species.h vector Chemical_Element, pies; Chemical_Element.clear(); - for (i=0;(size_t)i<(sizeof(ELEMENTS)/sizeof(ELEMENTS[0]));i++){ - pies= IO::string2vector(ELEMENTS[i]); + for (i = 0; (size_t)i < (sizeof(ELEMENTS) / sizeof(ELEMENTS[0])); i++) + { + pies = IO::string2vector(ELEMENTS[i]); Chemical_Element.push_back(pies[2]); } id_iz.clear(); type_x.clear(); - n=int(formula.size()); + n = int(formula.size()); element_ia.clear(); element_ib.clear(); @@ -294,144 +320,156 @@ vector IO::formula2index_total(std::string formula){ number_ib.clear(); number_iz.clear(); - bracket_ia.clear(); //to store begin position of bracket - bracket_ib.clear(); //to store end position of bracket + bracket_ia.clear(); // to store begin position of bracket + bracket_ib.clear(); // to store end position of bracket bracket_iz.clear(); bracket_ia0.clear(); bracket_ib0.clear(); // 0-A-Z, 1-a-z, 2-0-9, 3-[(, 4-]), 5-others - for(i=0;i=65 && symb_asc<=90) //A-Z + if (symb_asc >= 65 && symb_asc <= 90) // A-Z type_x.push_back(0); - else if(symb_asc>=97 && symb_asc<=122) //a-z + else if (symb_asc >= 97 && symb_asc <= 122) // a-z type_x.push_back(1); - else if(symb_asc>=48 && symb_asc<=57) //0-9 + else if (symb_asc >= 48 && symb_asc <= 57) // 0-9 type_x.push_back(2); - else if(symb_asc==40 || symb_asc==91) // [( + else if (symb_asc == 40 || symb_asc == 91) // [( type_x.push_back(3); - else if(symb_asc==41 || symb_asc==93) // ]) + else if (symb_asc == 41 || symb_asc == 93) // ]) type_x.push_back(4); else type_x.push_back(5); } - type_x.push_back(-1); //set string end mark - + type_x.push_back(-1); // set string end mark // 0-A-Z, 1-a-z, 2-0-9, 3-[(, 4-]), 5-others - //search for chemical elements - for(i=0;i0 && type_x[i-1]!=2) + else if (type_x[i] == 2) + { + if (i > 0 && type_x[i - 1] != 2) number_ia.push_back(i); - if(i>0 && type_x[i]==2 && type_x[i+1]!=2) + if (i > 0 && type_x[i] == 2 && type_x[i + 1] != 2) number_ib.push_back(i); - } - else if(type_x[i]==3) + } + else if (type_x[i] == 3) bracket_ia0.push_back(i); - else if(type_x[i]==4) + else if (type_x[i] == 4) bracket_ib0.push_back(i); } - //to check the bracket symb is correct or not, e.g. (( ... )) - for(i=0;i<(int)bracket_ia0.size();i++){ - is_bracket=0; - for(j=0;j<(int)bracket_ib0.size();j++){ - if(i==(int)bracket_ia0.size()-1){ - if(bracket_ib0[j]>bracket_ia0[i]) - is_bracket=1; + // to check the bracket symb is correct or not, e.g. (( ... )) + for (i = 0; i < (int)bracket_ia0.size(); i++) + { + is_bracket = 0; + for (j = 0; j < (int)bracket_ib0.size(); j++) + { + if (i == (int)bracket_ia0.size() - 1) + { + if (bracket_ib0[j] > bracket_ia0[i]) + is_bracket = 1; } - else{ - if(bracket_ib0[j]>bracket_ia0[i] && bracket_ib0[j] bracket_ia0[i] && bracket_ib0[j] < bracket_ia0[i + 1]) + is_bracket = 1; } } - if(is_bracket==1) + if (is_bracket == 1) bracket_ia.push_back(bracket_ia0[i]); } - for(i=0;i<(int)bracket_ib0.size();i++){ - is_bracket=0; - for(j=0;j<(int)bracket_ia0.size();j++){ - if(i==0){ - if(bracket_ia0[j]bracket_ib0[i-1]) - is_bracket=1; + else + { + if (bracket_ia0[j] < bracket_ib0[i] && bracket_ia0[j] > bracket_ib0[i - 1]) + is_bracket = 1; } } - if(is_bracket==1) + if (is_bracket == 1) bracket_ib.push_back(bracket_ib0[i]); } + for (i = 0; i < (int)number_ia.size(); i++) + number_iz.push_back(atoi(formula.substr(number_ia[i], number_ib[i] - number_ia[i] + 1).c_str())); - - for(i=0;i<(int)number_ia.size();i++) - number_iz.push_back(atoi(formula.substr(number_ia[i],number_ib[i]-number_ia[i]+1).c_str())); - - for(i=0;i<(int)element_name.size();i++) - if(type_x[element_ib[i]+1]==2) - for(j=0;j<(int)number_iz.size();j++){ - if(element_ib[i]+1==number_ia[j]) + for (i = 0; i < (int)element_name.size(); i++) + if (type_x[element_ib[i] + 1] == 2) + for (j = 0; j < (int)number_iz.size(); j++) + { + if (element_ib[i] + 1 == number_ia[j]) element_iz.push_back(number_iz[j]); } else element_iz.push_back(1); - for(i=0;i<(int)bracket_ia.size();i++) - if(type_x[bracket_ib[i]+1]==2) - for(j=0;j<(int)number_iz.size();j++){ - if(bracket_ib[i]+1==number_ia[j]) + for (i = 0; i < (int)bracket_ia.size(); i++) + if (type_x[bracket_ib[i] + 1] == 2) + for (j = 0; j < (int)number_iz.size(); j++) + { + if (bracket_ib[i] + 1 == number_ia[j]) bracket_iz.push_back(number_iz[j]); } else bracket_iz.push_back(1); - for(i=0;i<(int)bracket_ia.size();i++) - for(j=0;j<(int)element_ia.size();j++) - if(element_ia[j]>bracket_ia[i] && element_ib[j] bracket_ia[i] && element_ib[j] < bracket_ib[i]) element_iz[j] *= bracket_iz[i]; - - for(i=0;i<(int)Chemical_Element.size();i++){ + for (i = 0; i < (int)Chemical_Element.size(); i++) + { id_iz.push_back(0); - for(j=0;j IO::formula2index_define(std::string formula, vector Chemical_Element){ - //const string Chemical_Element[10]={"Li", "Na", "K", "Mg", "Ca", "Cl", "S", "C", "H", "O"}; - int i,j,n,symb_asc,is_bracket; - vector id_iz,type_x; +vector IO::formula2index_define(std::string formula, vector Chemical_Element) +{ + // const string Chemical_Element[10]={"Li", "Na", "K", "Mg", "Ca", "Cl", "S", "C", "H", "O"}; + int i, j, n, symb_asc, is_bracket; + vector id_iz, type_x; vector bracket_ia, bracket_ib, bracket_iz, bracket_ia0, bracket_ib0; // CB clear vector element_ia, element_ib, element_iz; - vector number_ia, number_ib, number_iz; + vector number_ia, number_ib, number_iz; vector element_name; id_iz.clear(); type_x.clear(); - n=int(formula.size()); + n = int(formula.size()); element_ia.clear(); element_ib.clear(); @@ -442,166 +480,183 @@ vector IO::formula2index_define(std::string formula, vector Chemica number_ib.clear(); number_iz.clear(); - bracket_ia.clear(); //to store begin position of bracket - bracket_ib.clear(); //to store end position of bracket + bracket_ia.clear(); // to store begin position of bracket + bracket_ib.clear(); // to store end position of bracket bracket_iz.clear(); bracket_ia0.clear(); bracket_ib0.clear(); // 0-A-Z, 1-a-z, 2-0-9, 3-[(, 4-]), 5-others - for(i=0;i=65 && symb_asc<=90) //A-Z + if (symb_asc >= 65 && symb_asc <= 90) // A-Z type_x.push_back(0); - else if(symb_asc>=97 && symb_asc<=122) //a-z + else if (symb_asc >= 97 && symb_asc <= 122) // a-z type_x.push_back(1); - else if(symb_asc>=48 && symb_asc<=57) //0-9 + else if (symb_asc >= 48 && symb_asc <= 57) // 0-9 type_x.push_back(2); - else if(symb_asc==40 || symb_asc==91) // [( + else if (symb_asc == 40 || symb_asc == 91) // [( type_x.push_back(3); - else if(symb_asc==41 || symb_asc==93) // ]) + else if (symb_asc == 41 || symb_asc == 93) // ]) type_x.push_back(4); else type_x.push_back(5); } - type_x.push_back(-1); //set string end mark - + type_x.push_back(-1); // set string end mark // 0-A-Z, 1-a-z, 2-0-9, 3-[(, 4-]), 5-others - //search for chemical elements - for(i=0;i0 && type_x[i-1]!=2) + else if (type_x[i] == 2) + { + if (i > 0 && type_x[i - 1] != 2) number_ia.push_back(i); - if(i>0 && type_x[i]==2 && type_x[i+1]!=2) + if (i > 0 && type_x[i] == 2 && type_x[i + 1] != 2) number_ib.push_back(i); - } - else if(type_x[i]==3) + } + else if (type_x[i] == 3) bracket_ia0.push_back(i); - else if(type_x[i]==4) + else if (type_x[i] == 4) bracket_ib0.push_back(i); } - //to check the bracket symb is correct or not, e.g. (( ... )) - for(i=0;i<(int)bracket_ia0.size();i++){ - is_bracket=0; - for(j=0;j<(int)bracket_ib0.size();j++){ - if(i==(int)bracket_ia0.size()-1){ - if(bracket_ib0[j]>bracket_ia0[i]) - is_bracket=1; + // to check the bracket symb is correct or not, e.g. (( ... )) + for (i = 0; i < (int)bracket_ia0.size(); i++) + { + is_bracket = 0; + for (j = 0; j < (int)bracket_ib0.size(); j++) + { + if (i == (int)bracket_ia0.size() - 1) + { + if (bracket_ib0[j] > bracket_ia0[i]) + is_bracket = 1; } - else{ - if(bracket_ib0[j]>bracket_ia0[i] && bracket_ib0[j] bracket_ia0[i] && bracket_ib0[j] < bracket_ia0[i + 1]) + is_bracket = 1; } } - if(is_bracket==1) + if (is_bracket == 1) bracket_ia.push_back(bracket_ia0[i]); } - for(i=0;i<(int)bracket_ib0.size();i++){ - is_bracket=0; - for(j=0;j<(int)bracket_ia0.size();j++){ - if(i==0){ - if(bracket_ia0[j]bracket_ib0[i-1]) - is_bracket=1; + else + { + if (bracket_ia0[j] < bracket_ib0[i] && bracket_ia0[j] > bracket_ib0[i - 1]) + is_bracket = 1; } } - if(is_bracket==1) + if (is_bracket == 1) bracket_ib.push_back(bracket_ib0[i]); } + for (i = 0; i < (int)number_ia.size(); i++) + number_iz.push_back(atoi(formula.substr(number_ia[i], number_ib[i] - number_ia[i] + 1).c_str())); - - for(i=0;i<(int)number_ia.size();i++) - number_iz.push_back(atoi(formula.substr(number_ia[i],number_ib[i]-number_ia[i]+1).c_str())); - - for(i=0;i<(int)element_name.size();i++) - if(type_x[element_ib[i]+1]==2) - for(j=0;j<(int)number_iz.size();j++){ - if(element_ib[i]+1==number_ia[j]) + for (i = 0; i < (int)element_name.size(); i++) + if (type_x[element_ib[i] + 1] == 2) + for (j = 0; j < (int)number_iz.size(); j++) + { + if (element_ib[i] + 1 == number_ia[j]) element_iz.push_back(number_iz[j]); } else element_iz.push_back(1); - for(i=0;i<(int)bracket_ia.size();i++) - if(type_x[bracket_ib[i]+1]==2) - for(j=0;j<(int)number_iz.size();j++){ - if(bracket_ib[i]+1==number_ia[j]) + for (i = 0; i < (int)bracket_ia.size(); i++) + if (type_x[bracket_ib[i] + 1] == 2) + for (j = 0; j < (int)number_iz.size(); j++) + { + if (bracket_ib[i] + 1 == number_ia[j]) bracket_iz.push_back(number_iz[j]); } else bracket_iz.push_back(1); - for(i=0;i<(int)bracket_ia.size();i++) - for(j=0;j<(int)element_ia.size();j++) - if(element_ia[j]>bracket_ia[i] && element_ib[j] bracket_ia[i] && element_ib[j] < bracket_ib[i]) element_iz[j] *= bracket_iz[i]; - - for(i=0;i<(int)Chemical_Element.size();i++){ + for (i = 0; i < (int)Chemical_Element.size(); i++) + { id_iz.push_back(0); - for(j=0;j IO::vector_reduce(std::vector in_vec){ +vector IO::vector_reduce(std::vector in_vec) +{ int i; vector out_vec; out_vec.clear(); - for(i=0;i<(int)in_vec.size();i++){ - if(IO::string2vector(in_vec[i]).size()>0) + for (i = 0; i < (int)in_vec.size(); i++) + { + if (IO::string2vector(in_vec[i]).size() > 0) out_vec.push_back(in_vec[i]); } return out_vec; diff --git a/GCC/IO.h b/GCC/IO.h index b1f199e34..b6624f71e 100644 --- a/GCC/IO.h +++ b/GCC/IO.h @@ -9,20 +9,19 @@ #include #include -//using namespace std; +// using namespace std; class IO { - private: - public: IO(void); ~IO(void); static int file2code(std::string datafile_in, std::string codefile_out); - static int file2vector(std::string datafile_in, std::vector &vector_out); - static std::vector string2vector(std::string line); //split string line to pieces, and store in a vector + static int file2vector(std::string datafile_in, std::vector& vector_out); + static std::vector string2vector( + std::string line); // split string line to pieces, and store in a vector static std::vector formula2index(std::string formula); static std::vector formula2index_total(std::string formula); @@ -33,4 +32,3 @@ class IO static std::vector vector_reduce(std::vector); static void entrance(void); }; - diff --git a/GCC/NR.cpp b/GCC/NR.cpp index e22dabab4..9fd6d3f9b 100644 --- a/GCC/NR.cpp +++ b/GCC/NR.cpp @@ -16,30 +16,35 @@ #include "NR.h" using namespace std; - -NR::NR(void){} -NR::~NR(void){} +NR::NR(void) +{ +} +NR::~NR(void) +{ +} double dfridr(double func(double), const double /*x*/ /*, const double h, double &err*/) { - (void)func; + (void)func; // Removed std::cout << "Error: NR::dfridr not implemented!" << std::endl; return numeric_limits::min(); } -double NR::dfridrX(double func(double,double), const double /*x*/, const double /*y*/ /*, const double h, double &err*/) +double NR::dfridrX(double func(double, double), const double /*x*/, + const double /*y*/ /*, const double h, double &err*/) { - (void)func; + (void)func; // Removed std::cout << "Error: NR::dfridrX not implemented!" << std::endl; return numeric_limits::min(); } -double NR::dfridrY(double func(double,double), const double /*x*/, const double /*y*/ /*, const double h, double &err*/) +double NR::dfridrY(double func(double, double), const double /*x*/, + const double /*y*/ /*, const double h, double &err*/) { // Removed - (void)func; + (void)func; std::cout << "Error: NR::dfridrY not implemented!" << std::endl; return numeric_limits::min(); } diff --git a/GCC/NR.h b/GCC/NR.h index 97f88841f..18df127a9 100644 --- a/GCC/NR.h +++ b/GCC/NR.h @@ -10,14 +10,11 @@ class NR { private: - public: NR(void); ~NR(void); - static double dfridr (double func(double), const double /*x*/); - static double dfridrX(double func(double,double), const double /*x*/, const double /*y*/); - static double dfridrY(double func(double,double), const double /*x*/, const double /*y*/); - + static double dfridr(double func(double), const double /*x*/); + static double dfridrX(double func(double, double), const double /*x*/, const double /*y*/); + static double dfridrY(double func(double, double), const double /*x*/, const double /*y*/); }; - diff --git a/GCC/PITZdata.cpp b/GCC/PITZdata.cpp index 3550447ec..e2a9de5a8 100644 --- a/GCC/PITZdata.cpp +++ b/GCC/PITZdata.cpp @@ -22,92 +22,97 @@ #include "IO.h" #include "VLE.h" - using namespace std; +PITZdata::PITZdata(void) +{ +} +PITZdata::~PITZdata(void) +{ +} -PITZdata::PITZdata(void){} -PITZdata::~PITZdata(void){} - -double PITZdata::charge(string N){ - int i,flag=0; +double PITZdata::charge(string N) +{ + int i, flag = 0; double res; vector pies; - for (i=0;(size_t)i<(sizeof(SPECIES)/sizeof(SPECIES[0]));i++){ - pies= IO::string2vector(SPECIES[i]); - if(pies[0]==N) { - res= atof(pies[1].c_str()); - flag=1; + for (i = 0; (size_t)i < (sizeof(SPECIES) / sizeof(SPECIES[0])); i++) + { + pies = IO::string2vector(SPECIES[i]); + if (pies[0] == N) + { + res = atof(pies[1].c_str()); + flag = 1; } } - if (flag==0) { + if (flag == 0) + { cout << " No Enough Species In The List " << endl; exit(0); } return res; } +double PITZdata::pitzer_parameters(double T, double P, string param_switch) +{ + double c1 = 0.0, c2 = 0.0, c3 = 0.0, c4 = 0.0, c5 = 0.0, c6 = 0.0, c7 = 0.0, c8 = 0.0, c9 = 0.0, c10 = 0.0; + double c11 = 0.0 /*, c12=0.0, c13=0.0, c14=0.0, c15=0.0, c16=0.0, c17=0.0, c18=0.0, c19=0.0, c20=0.0*/; + // double c21=0.0, c22=0.0, c23=0.0, c24=0.0, c25=0.0, c26=0.0, c27=0.0, c28=0.0, c29=0.0, c30=0.0; + // double DW; + double res = 0.0; -double PITZdata::pitzer_parameters(double T, double P, string param_switch){ - double c1 =0.0, c2 =0.0, c3 =0.0, c4 =0.0, c5 =0.0, c6 =0.0, c7 =0.0, c8 =0.0, c9 =0.0, c10=0.0; - double c11=0.0/*, c12=0.0, c13=0.0, c14=0.0, c15=0.0, c16=0.0, c17=0.0, c18=0.0, c19=0.0, c20=0.0*/; - //double c21=0.0, c22=0.0, c23=0.0, c24=0.0, c25=0.0, c26=0.0, c27=0.0, c28=0.0, c29=0.0, c30=0.0; - //double DW; - double res=0.0; - - - - if(param_switch== "LAMN_CO2_CO2"){ + if (param_switch == "LAMN_CO2_CO2") + { c1 = -8.603471564E-01; - c2 = 3.297141654E-03; - c3 = 6.309267405E+01; + c2 = 3.297141654E-03; + c3 = 6.309267405E+01; c4 = -4.098960500E-06; - c5 = 1.529493614E+01; - c6 = 6.506644253E-03; + c5 = 1.529493614E+01; + c6 = 6.506644253E-03; c7 = -9.637977140E-04; c8 = -3.238222665E-01; - c9 = 1.599113719E-02; - c10= 0.0; - c11= -1.886733300E-05; - return c1+c2*T+c3/T+c4*T*T+c5/(630.0e0-T)+c6*P+ - c7*P*log(T)+c8*P/T+c9*P/(630.0e0-T)+ - c10*P*P/pow((630.0e0-T),2)+c11*T*log(P); - }else - if (param_switch=="LAM_Na_CO2"){ - c1= -2.739092216E-01; - c2= 7.399855859E-04; - c3= 5.552132850E+01; - c4= 0.0; - c5= 0.0; - c6= 0.0; - c7= 0.0; - c8= 5.683638727E-03; - c9= -8.009093476E-04; - c10= 0.0; - c11=-1.745620270E-05; - return c1+c2*T+c3/T+c4*T*T+c5/(630.0e0-T)+c6*P+ - c7*P*log(T)+c8*P/T+c9*P/(630.0e0-T)+ - c10*P*P/pow((630.0e0-T),2)+c11*T*log(P); - }else + c9 = 1.599113719E-02; + c10 = 0.0; + c11 = -1.886733300E-05; + return c1 + c2 * T + c3 / T + c4 * T * T + c5 / (630.0e0 - T) + c6 * P + c7 * P * log(T) + c8 * P / T + + c9 * P / (630.0e0 - T) + c10 * P * P / pow((630.0e0 - T), 2) + c11 * T * log(P); + } + else if (param_switch == "LAM_Na_CO2") + { + c1 = -2.739092216E-01; + c2 = 7.399855859E-04; + c3 = 5.552132850E+01; + c4 = 0.0; + c5 = 0.0; + c6 = 0.0; + c7 = 0.0; + c8 = 5.683638727E-03; + c9 = -8.009093476E-04; + c10 = 0.0; + c11 = -1.745620270E-05; + return c1 + c2 * T + c3 / T + c4 * T * T + c5 / (630.0e0 - T) + c6 * P + c7 * P * log(T) + c8 * P / T + + c9 * P / (630.0e0 - T) + c10 * P * P / pow((630.0e0 - T), 2) + c11 * T * log(P); + } + else - //+++++++++=====test again=======+++++++++++ - if (param_switch=="ZETA_NaCl_CO2"){ //not "ZETA_Na_Cl_CO2", only for CO2 activity coeff - c1= -1.665719188E-02; - c2= 1.391618600E-06; - c3= 0.0; - c4= 0.0; - c5= 0.0; - c6= 0.0; - c7= 0.0; - c8= -1.873812115E-03; - c9= -1.577400757E-03; - c10= 0.0; - c11= 0.0; - return c1+c2*T+c3/T+c4*T*T+c5/(630.0e0-T)+c6*P+ - c7*P*log(T)+c8*P/T+c9*P/(630.0e0-T)+ - c10*P*P/pow((630.0e0-T),2)+c11*T*log(P); + //+++++++++=====test again=======+++++++++++ + if (param_switch == "ZETA_NaCl_CO2") + { // not "ZETA_Na_Cl_CO2", only for CO2 activity coeff + c1 = -1.665719188E-02; + c2 = 1.391618600E-06; + c3 = 0.0; + c4 = 0.0; + c5 = 0.0; + c6 = 0.0; + c7 = 0.0; + c8 = -1.873812115E-03; + c9 = -1.577400757E-03; + c10 = 0.0; + c11 = 0.0; + return c1 + c2 * T + c3 / T + c4 * T * T + c5 / (630.0e0 - T) + c6 * P + c7 * P * log(T) + c8 * P / T + + c9 * P / (630.0e0 - T) + c10 * P * P / pow((630.0e0 - T), 2) + c11 * T * log(P); } - else return res; + else + return res; } - diff --git a/GCC/PITZdata.h b/GCC/PITZdata.h index fff7fab6c..519195cfb 100644 --- a/GCC/PITZdata.h +++ b/GCC/PITZdata.h @@ -9,18 +9,15 @@ #include -//using namespace std; +// using namespace std; class PITZdata { private: - public: PITZdata(void); ~PITZdata(void); -//method + // method static double charge(std::string N); static double pitzer_parameters(double T, double P, std::string param_switch); - }; - diff --git a/GCC/VLE.cpp b/GCC/VLE.cpp index b7cd9761f..cc33b5f1b 100644 --- a/GCC/VLE.cpp +++ b/GCC/VLE.cpp @@ -22,602 +22,677 @@ using namespace std; double VLE::TT; double VLE::PP; -VLE::VLE(void){} -VLE::~VLE(void){} +VLE::VLE(void) +{ +} +VLE::~VLE(void) +{ +} -//unit T K, P MPa -double VLE::Psat(double T){ - double A,B,C,theta,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10; - n1 = 0.11670521452767e4; +// unit T K, P MPa +double VLE::Psat(double T) +{ + double A, B, C, theta, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10; + n1 = 0.11670521452767e4; n2 = -0.72421316703206e6; n3 = -0.17073846940092e2; - n4 = 0.12020824702470e5; + n4 = 0.12020824702470e5; n5 = -0.32325550322333e7; - n6 = 0.14915108613530e2; + n6 = 0.14915108613530e2; n7 = -0.48232657361591e4; - n8 = 0.40511340542057e6; + n8 = 0.40511340542057e6; n9 = -0.23855557567849; - n10= 0.65017534844798e3; - theta = T+n9/(T-n10); - A = pow(theta,2.0)+n1*theta+n2; - B = n3*pow(theta,2.0)+n4*theta+n5; - C = n6*pow(theta,2.0)+n7*theta+n8; - return pow(2.0*C/(-B+pow(B*B-4.0*A*C,0.5)),4.0); + n10 = 0.65017534844798e3; + theta = T + n9 / (T - n10); + A = pow(theta, 2.0) + n1 * theta + n2; + B = n3 * pow(theta, 2.0) + n4 * theta + n5; + C = n6 * pow(theta, 2.0) + n7 * theta + n8; + return pow(2.0 * C / (-B + pow(B * B - 4.0 * A * C, 0.5)), 4.0); } - - //====> solubility section <==== -double VLE::solubility_CO2(double T, double P, double mNaCl){ - return (P-Psat(T)*10.0)/exp(-LnPHI_CO2(T,P)+u0_CO2(T,P)+lnrCO2(T,P,mNaCl)); -} - -double VLE::solubilityNEW_CO2(double T, double P, double mNaCl){ - double a,b,mCO2,dev,err=1.0e-6; - int i,iter_max=100; - mCO2= VLE::solubility_CO2(T,P,mNaCl); - a=mCO2*0.5; - b=mCO2*1.5; - for(i=0;i0.0) b=mCO2; +double VLE::solubility_CO2(double T, double P, double mNaCl) +{ + return (P - Psat(T) * 10.0) / exp(-LnPHI_CO2(T, P) + u0_CO2(T, P) + lnrCO2(T, P, mNaCl)); +} + +double VLE::solubilityNEW_CO2(double T, double P, double mNaCl) +{ + double a, b, mCO2, dev, err = 1.0e-6; + int i, iter_max = 100; + mCO2 = VLE::solubility_CO2(T, P, mNaCl); + a = mCO2 * 0.5; + b = mCO2 * 1.5; + for (i = 0; i < iter_max; i++) + { + mCO2 = (a + b) * 0.5; + dev = mCO2 - (P - Psat(T) * 10.0) / exp(-LnPHI_CO2(T, P) + uNEW_CO2(T, P) + LGAMMA_CO2(T, P, mCO2, mNaCl)); + if (abs(dev) < err) + break; + else if (dev < 0.0) + a = mCO2; + else if (dev > 0.0) + b = mCO2; } return mCO2; } -double VLE::u0_CO2(double T, double P){ - double c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11; - c1 = 2.89447706e+01; +double VLE::u0_CO2(double T, double P) +{ + double c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11; + c1 = 2.89447706e+01; c2 = -3.54581768e-02; c3 = -4.77067077e+03; - c4 = 1.02782768e-05; - c5 = 3.38126098e+01; - c6 = 9.04037140e-03; + c4 = 1.02782768e-05; + c5 = 3.38126098e+01; + c6 = 9.04037140e-03; c7 = -1.14934031e-03; c8 = -3.07405726e-01; c9 = -9.07301486e-02; - c10= 9.32713393e-04; - c11= 0.0; - return c1+c2*T+c3/T+c4*pow(T,2)+c5/(630-T)+c6*P+c7*P*log(T)+c8*P/T+c9*P/(630-T)+c10*pow(P,2)/pow((630-T),2)+c11*T*log(P); -} -double VLE::lnrCO2(double T, double P, double mNaCl){ - double c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,d11,res; - c1 = -4.11370585e-01; - c2 = 6.07632013e-04; - c3 = 97.5347708; - c4 = 0.0; - c5 = 0.0; - c6 = 0.0; - c7 = 0.0; + c10 = 9.32713393e-04; + c11 = 0.0; + return c1 + c2 * T + c3 / T + c4 * pow(T, 2) + c5 / (630 - T) + c6 * P + c7 * P * log(T) + c8 * P / T + + c9 * P / (630 - T) + c10 * pow(P, 2) / pow((630 - T), 2) + c11 * T * log(P); +} +double VLE::lnrCO2(double T, double P, double mNaCl) +{ + double c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, res; + c1 = -4.11370585e-01; + c2 = 6.07632013e-04; + c3 = 97.5347708; + c4 = 0.0; + c5 = 0.0; + c6 = 0.0; + c7 = 0.0; c8 = -2.37622469e-02; - c9 = 1.70656236e-02; - c10= 0.0; - c11= 1.41335834e-05; - d1 = 3.36389723e-04; + c9 = 1.70656236e-02; + c10 = 0.0; + c11 = 1.41335834e-05; + d1 = 3.36389723e-04; d2 = -1.98298980e-05; - d3 = 0.0; - d4 = 0.0; - d5 = 0.0; - d6 = 0.0; - d7 = 0.0; - d8 = 2.12220830e-03; + d3 = 0.0; + d4 = 0.0; + d5 = 0.0; + d6 = 0.0; + d7 = 0.0; + d8 = 2.12220830e-03; d9 = -5.24873303e-03; - d10= 0.0; - d11= 0.0; - res = 2.0*mNaCl* (c1+c2*T+c3/T+c4*pow(T,2)+c5/(630-T)+c6*P+c7*P*log(T)+c8*P/T+c9*P/(630-T)+c10*pow(P,2)/pow((630-T),2)+c11*T*log(P)); - res+= mNaCl*mNaCl* (d1+d2*T+d3/T+d4*pow(T,2)+d5/(630-T)+d6*P+d7*P*log(T)+d8*P/T+d9*P/(630-T)+d10*pow(P,2)/pow((630-T),2)+d11*T*log(P)); + d10 = 0.0; + d11 = 0.0; + res = 2.0 * mNaCl * (c1 + c2 * T + c3 / T + c4 * pow(T, 2) + c5 / (630 - T) + c6 * P + c7 * P * log(T) + c8 * P / T + + c9 * P / (630 - T) + + c10 * pow(P, 2) / pow((630 - T), 2) + + c11 * T * log(P)); + res += mNaCl * mNaCl + * (d1 + d2 * T + d3 / T + d4 * pow(T, 2) + d5 / (630 - T) + d6 * P + d7 * P * log(T) + d8 * P / T + + d9 * P / (630 - T) + + d10 * pow(P, 2) / pow((630 - T), 2) + + d11 * T * log(P)); return res; } -double VLE::LGAMMA_CO2(double T, double P, double mCO2, double mNaCl){ - double LAMN,LAM,ZETA; +double VLE::LGAMMA_CO2(double T, double P, double mCO2, double mNaCl) +{ + double LAMN, LAM, ZETA; PITZdata M; - LAMN = M.pitzer_parameters(T,P,"LAMN_CO2_CO2"); - LAM = M.pitzer_parameters(T,P,"LAM_Na_CO2"); - ZETA = M.pitzer_parameters(T,P,"ZETA_NaCl_CO2"); - return 2.0*LAMN*mCO2+2.0*LAM*mNaCl+ZETA*mNaCl*mNaCl; + LAMN = M.pitzer_parameters(T, P, "LAMN_CO2_CO2"); + LAM = M.pitzer_parameters(T, P, "LAM_Na_CO2"); + ZETA = M.pitzer_parameters(T, P, "ZETA_NaCl_CO2"); + return 2.0 * LAMN * mCO2 + 2.0 * LAM * mNaCl + ZETA * mNaCl * mNaCl; } -double VLE::solubility_CH4(double T, double P, double mNaCl){ - return (P-Psat(T)*10.0)/exp(u0_CH4(T,P)-LnPHI_CH4(T,P)+lnrCH4(T,P,mNaCl)); +double VLE::solubility_CH4(double T, double P, double mNaCl) +{ + return (P - Psat(T) * 10.0) / exp(u0_CH4(T, P) - LnPHI_CH4(T, P) + lnrCH4(T, P, mNaCl)); } -double VLE::u0_CH4(double T, double P){ - double c1,c2,c3,c4,c5,c6,c7,c8,c9; - c1 = 0.83143711e+01; +double VLE::u0_CH4(double T, double P) +{ + double c1, c2, c3, c4, c5, c6, c7, c8, c9; + c1 = 0.83143711e+01; c2 = -0.72772168e-03; - c3 = 0.21489858e+04; + c3 = 0.21489858e+04; c4 = -0.14019672e-04; c5 = -0.66743449e+06; - c6 = 0.76985890e-02; + c6 = 0.76985890e-02; c7 = -0.50253331e-05; c8 = -0.30092013e+01; - c9 = 0.48468502e+03; - return c1+c2*T+c3/T+c4*T*T+c5/T/T+c6*P+c7*P*T+c8*P/T+c9*P/T/T; + c9 = 0.48468502e+03; + return c1 + c2 * T + c3 / T + c4 * T * T + c5 / T / T + c6 * P + c7 * P * T + c8 * P / T + c9 * P / T / T; } -double VLE::lnrCH4(double T, double P, double mNaCl){ - double c1,c2,c3,c4,c5; +double VLE::lnrCH4(double T, double P, double mNaCl) +{ + double c1, c2, c3, c4, c5; c1 = -0.81222036e+00; - c2 = 0.10635172e-02; - c3 = 0.18894036e+03; - c4 = 0.44105635e-04; + c2 = 0.10635172e-02; + c3 = 0.18894036e+03; + c4 = 0.44105635e-04; c5 = -0.46797718e-10; - return 2.0*(c1+c2*T+c3/T+c4*P+c5*P*P*T)*mNaCl-0.29903571e-02*mNaCl*mNaCl; + return 2.0 * (c1 + c2 * T + c3 / T + c4 * P + c5 * P * P * T) * mNaCl - 0.29903571e-02 * mNaCl * mNaCl; } -double VLE::uNEW_CO2(double T, double P){ - double lnkH,Vphi; - lnkH = 1.3999520898e+01 -1.3340507000e-02*T -5.5897820016e+02/T -4.2257732219e+05/T/T; - Vphi = 35.663-5.960e-2*(T-273.15) +6.308e-4*pow((T-273.15),2.0); - return lnkH + Vphi*(P-Psat(T)*10.0)/(83.14471*T); +double VLE::uNEW_CO2(double T, double P) +{ + double lnkH, Vphi; + lnkH = 1.3999520898e+01 - 1.3340507000e-02 * T - 5.5897820016e+02 / T - 4.2257732219e+05 / T / T; + Vphi = 35.663 - 5.960e-2 * (T - 273.15) + 6.308e-4 * pow((T - 273.15), 2.0); + return lnkH + Vphi * (P - Psat(T) * 10.0) / (83.14471 * T); } - - - //========================================== //> EoS section D unit: g/cm^3 < //========================================== -double VLE::density_CO2(double T, double P){ - double x1,x2; - x1=0.8e1*T/P; - x2=2.0e2*T/P; - if(P>20.0){ - x1=2.0e1*T/P; - x2=2.0e2*T/P; +double VLE::density_CO2(double T, double P) +{ + double x1, x2; + x1 = 0.8e1 * T / P; + x2 = 2.0e2 * T / P; + if (P > 20.0) + { + x1 = 2.0e1 * T / P; + x2 = 2.0e2 * T / P; } - if(P>40.0){ - x1=0.75e1*T/P; - x2=9.0e1*T/P; + if (P > 40.0) + { + x1 = 0.75e1 * T / P; + x2 = 9.0e1 * T / P; } - if(P>520.0){ //if(P>600.0){ //DL 2012.03.22 - x1=2.5e1*T/P; - x2=5.0e2*T/P; + if (P > 520.0) + { // if(P>600.0){ //DL 2012.03.22 + x1 = 2.5e1 * T / P; + x2 = 5.0e2 * T / P; } - if(P>1000.0){ - x1=5.0e1*T/P; - x2=5.0e2*T/P; + if (P > 1000.0) + { + x1 = 5.0e1 * T / P; + x2 = 5.0e2 * T / P; } - if(P>3500.0){ - x1=1.5e2*T/P; - x2=2.0e3*T/P; + if (P > 3500.0) + { + x1 = 1.5e2 * T / P; + x2 = 2.0e3 * T / P; } - TT=T; - PP=P; + TT = T; + PP = P; double result; brent::local_min(x1, x2, 1.0e-8, dZ_CO2, result); return 44.01 / result; } -double VLE::density_CH4(double T, double P){ // g/cm^3 - double x1,x2; - x1=2.0e1*T/P; - x2=2.0e2*T/P; - if(P>1000.0){ - x1=5.0e1*T/P; - x2=5.0e2*T/P; +double VLE::density_CH4(double T, double P) +{ // g/cm^3 + double x1, x2; + x1 = 2.0e1 * T / P; + x2 = 2.0e2 * T / P; + if (P > 1000.0) + { + x1 = 5.0e1 * T / P; + x2 = 5.0e2 * T / P; } - if(P>3500.0){ - x1=1.5e2*T/P; - x2=2.0e3*T/P; + if (P > 3500.0) + { + x1 = 1.5e2 * T / P; + x2 = 2.0e3 * T / P; } - TT=T; - PP=P; + TT = T; + PP = P; double result; brent::local_min(x1, x2, 1.0e-8, dZ_CH4, result); return 16.04 / result; } -double VLE::density_H2O(double T, double P){ // g/cm^3 - double x1,x2,Ps; - Ps=Psat(T)*10.0; - x1=0.8e1*T/P; //0.5e1*T/P; - x2=2.0e2*T/P; - if(P>400){ - x1=1.5e1*T/P; - x2=2.0e2*T/P; +double VLE::density_H2O(double T, double P) +{ // g/cm^3 + double x1, x2, Ps; + Ps = Psat(T) * 10.0; + x1 = 0.8e1 * T / P; // 0.5e1*T/P; + x2 = 2.0e2 * T / P; + if (P > 400) + { + x1 = 1.5e1 * T / P; + x2 = 2.0e2 * T / P; + } + if (P > 1000.0) + { + x1 = 5.0e1 * T / P; + x2 = 5.0e2 * T / P; } - if(P>1000.0){ - x1=5.0e1*T/P; - x2=5.0e2*T/P; + if (P > 3500.0) + { + x1 = 1.1e2 * T / P; + x2 = 2.0e3 * T / P; } - if(P>3500.0){ - x1=1.1e2*T/P; - x2=2.0e3*T/P; + if (T < 423.0 && P > Ps) + { + x1 = 1.0e1; + x2 = 2.5e1; } - if(T<423.0 && P>Ps){ - x1=1.0e1; - x2=2.5e1; - }else if(T<630.0 && P>Ps){ - x1=1.5e1; - x2=3.6e1; + else if (T < 630.0 && P > Ps) + { + x1 = 1.5e1; + x2 = 3.6e1; } - TT=T; - PP=P; + TT = T; + PP = P; double result; brent::local_min(x1, x2, 1.0e-8, dZ_H2O, result); - return 18.015 / result; + return 18.015 / result; } -double VLE::dZ_CO2(double V){ - double R,Tc,Pc,Vc,Tr,Pr,Vr; - R = 83.14467; +double VLE::dZ_CO2(double V) +{ + double R, Tc, Pc, Vc, Tr, Pr, Vr; + R = 83.14467; Tc = 304.2; Pc = 73.825; - Vc = R*Tc/Pc; - Tr = TT/Tc; - Pr = PP/Pc; - Vr = V/Vc; - return Z_CO2(TT,PP,V)-Pr*Vr/Tr; -} -double VLE::dZ_CH4(double V){ - double R,Tc,Pc,Vc,Tr,Pr,Vr; - R = 83.14467; + Vc = R * Tc / Pc; + Tr = TT / Tc; + Pr = PP / Pc; + Vr = V / Vc; + return Z_CO2(TT, PP, V) - Pr * Vr / Tr; +} +double VLE::dZ_CH4(double V) +{ + double R, Tc, Pc, Vc, Tr, Pr, Vr; + R = 83.14467; Tc = 190.6; Pc = 46.00; - Vc = R*Tc/Pc; - Tr = TT/Tc; - Pr = PP/Pc; - Vr = V/Vc; - return Z_CH4(TT,PP,V)-Pr*Vr/Tr; -} -double VLE::dZ_H2O(double V){ - double R,Tc,Pc,Vc,Tr,Pr,Vr; - R = 83.14467; + Vc = R * Tc / Pc; + Tr = TT / Tc; + Pr = PP / Pc; + Vr = V / Vc; + return Z_CH4(TT, PP, V) - Pr * Vr / Tr; +} +double VLE::dZ_H2O(double V) +{ + double R, Tc, Pc, Vc, Tr, Pr, Vr; + R = 83.14467; Tc = 647.25; Pc = 221.19; - Vc = R*Tc/Pc; - Tr = TT/Tc; - Pr = PP/Pc; - Vr = V/Vc; - return Z_H2O(TT,PP,V)-Pr*Vr/Tr; + Vc = R * Tc / Pc; + Tr = TT / Tc; + Pr = PP / Pc; + Vr = V / Vc; + return Z_H2O(TT, PP, V) - Pr * Vr / Tr; } - -double VLE::Z_CO2(double T, double /*P*/, double V){ //K, bar, cm^3 - double a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15; - double R,Tc,Pc,Vc,Tr,Vr,B,C,D,E,F; - a1 = 8.99288497E-2; +double VLE::Z_CO2(double T, double /*P*/, double V) +{ // K, bar, cm^3 + double a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15; + double R, Tc, Pc, Vc, Tr, Vr, B, C, D, E, F; + a1 = 8.99288497E-2; a2 = -4.94783127E-1; - a3 = 4.77922245E-2; - a4 = 1.03808883E-2; + a3 = 4.77922245E-2; + a4 = 1.03808883E-2; a5 = -2.82516861E-2; - a6 = 9.49887563E-2; - a7 = 5.20600880E-4; + a6 = 9.49887563E-2; + a7 = 5.20600880E-4; a8 = -2.93540971E-4; a9 = -1.77265112E-3; - a10= -2.51101973E-5; - a11= 8.93353441E-5; - a12= 7.88998563E-5; - a13= -1.66727022E-2; - a14= 1.39800000E-0; - a15= 2.96000000E-2; - R = 83.14467; + a10 = -2.51101973E-5; + a11 = 8.93353441E-5; + a12 = 7.88998563E-5; + a13 = -1.66727022E-2; + a14 = 1.39800000E-0; + a15 = 2.96000000E-2; + R = 83.14467; Tc = 304.2; Pc = 73.825; - Vc = R*Tc/Pc; - Tr = T/Tc; - Vr = V/Vc; - B= a1 +a2/pow(Tr,2) +a3/pow(Tr,3); - C= a4 +a5/pow(Tr,2) +a6/pow(Tr,3); - D= a7 +a8/pow(Tr,2) +a9/pow(Tr,3); - E= a10 +a11/pow(Tr,2) +a12/pow(Tr,3); - F= a13/pow(Tr,3); - return 1.0 + B/Vr + C/pow(Vr,2) + D/pow(Vr,4) + E/pow(Vr,5) + F/pow(Vr,2)*(a14+a15/pow(Vr,2))*exp(-a15/pow(Vr,2)); -} -double VLE::LnPHI_CO2(double T, double P){ - double a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15; - double R,V,Tc,Pc,Vc,Tr,Vr,B,C,D,E,Z; - V = 44.01/density_CO2(T,P); - Z = Z_CO2(T,P,V); - a1 = 8.99288497E-2; + Vc = R * Tc / Pc; + Tr = T / Tc; + Vr = V / Vc; + B = a1 + a2 / pow(Tr, 2) + a3 / pow(Tr, 3); + C = a4 + a5 / pow(Tr, 2) + a6 / pow(Tr, 3); + D = a7 + a8 / pow(Tr, 2) + a9 / pow(Tr, 3); + E = a10 + a11 / pow(Tr, 2) + a12 / pow(Tr, 3); + F = a13 / pow(Tr, 3); + return 1.0 + B / Vr + C / pow(Vr, 2) + D / pow(Vr, 4) + E / pow(Vr, 5) + + F / pow(Vr, 2) * (a14 + a15 / pow(Vr, 2)) * exp(-a15 / pow(Vr, 2)); +} +double VLE::LnPHI_CO2(double T, double P) +{ + double a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15; + double R, V, Tc, Pc, Vc, Tr, Vr, B, C, D, E, Z; + V = 44.01 / density_CO2(T, P); + Z = Z_CO2(T, P, V); + a1 = 8.99288497E-2; a2 = -4.94783127E-1; - a3 = 4.77922245E-2; - a4 = 1.03808883E-2; + a3 = 4.77922245E-2; + a4 = 1.03808883E-2; a5 = -2.82516861E-2; - a6 = 9.49887563E-2; - a7 = 5.20600880E-4; + a6 = 9.49887563E-2; + a7 = 5.20600880E-4; a8 = -2.93540971E-4; a9 = -1.77265112E-3; - a10= -2.51101973E-5; - a11= 8.93353441E-5; - a12= 7.88998563E-5; - a13= -1.66727022E-2; - a14= 1.39800000E-0; - a15= 2.96000000E-2; - R = 83.14467; + a10 = -2.51101973E-5; + a11 = 8.93353441E-5; + a12 = 7.88998563E-5; + a13 = -1.66727022E-2; + a14 = 1.39800000E-0; + a15 = 2.96000000E-2; + R = 83.14467; Tc = 304.2; Pc = 73.825; - Vc = R*Tc/Pc; - Tr = T/Tc; - Vr = V/Vc; - B = a1 +a2/pow(Tr,2) +a3/pow(Tr,3); - C = a4 +a5/pow(Tr,2) +a6/pow(Tr,3); - D = a7 +a8/pow(Tr,2) +a9/pow(Tr,3); - E = a10 +a11/pow(Tr,2) +a12/pow(Tr,3); - return Z-1-log(Z)+B/Vr+C/2/pow(Vr,2)+D/4/pow(Vr,4)+E/5/pow(Vr,5)+a13/(2*pow(Tr,3)*a15)*(a14+1-(a14+1+a15/pow(Vr,2))*exp(-a15/pow(Vr,2))); -} - -double VLE::Z_CH4(double T, double /*P*/, double V){ - double a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15; - double R,Tc,Pc,Vc,Tr,Vr,B,C,D,E,F; - a1 = 8.72553928E-2; - a2 = -7.52599476E-1; - a3 = 3.75419887E-1; - a4 = 1.07291342E-2; - a5 = 5.49626360E-3; - a6 = -1.84772802E-2; - a7 = 3.18993183E-4; - a8 = 2.11079375E-4; - a9 = 2.01682801E-5; + Vc = R * Tc / Pc; + Tr = T / Tc; + Vr = V / Vc; + B = a1 + a2 / pow(Tr, 2) + a3 / pow(Tr, 3); + C = a4 + a5 / pow(Tr, 2) + a6 / pow(Tr, 3); + D = a7 + a8 / pow(Tr, 2) + a9 / pow(Tr, 3); + E = a10 + a11 / pow(Tr, 2) + a12 / pow(Tr, 3); + return Z - 1 - log(Z) + B / Vr + C / 2 / pow(Vr, 2) + D / 4 / pow(Vr, 4) + E / 5 / pow(Vr, 5) + + a13 / (2 * pow(Tr, 3) * a15) * (a14 + 1 - (a14 + 1 + a15 / pow(Vr, 2)) * exp(-a15 / pow(Vr, 2))); +} + +double VLE::Z_CH4(double T, double /*P*/, double V) +{ + double a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15; + double R, Tc, Pc, Vc, Tr, Vr, B, C, D, E, F; + a1 = 8.72553928E-2; + a2 = -7.52599476E-1; + a3 = 3.75419887E-1; + a4 = 1.07291342E-2; + a5 = 5.49626360E-3; + a6 = -1.84772802E-2; + a7 = 3.18993183E-4; + a8 = 2.11079375E-4; + a9 = 2.01682801E-5; a10 = -1.65606189E-5; - a11 = 1.19614546E-4; + a11 = 1.19614546E-4; a12 = -1.08087289E-4; - a13 = 4.48262295E-2; - a14 = 7.53970000E-1; - a15 = 7.71670000E-2; - R = 83.14467; + a13 = 4.48262295E-2; + a14 = 7.53970000E-1; + a15 = 7.71670000E-2; + R = 83.14467; Tc = 190.6; Pc = 46.00; - Vc = R*Tc/Pc; - Tr=T/Tc; - Vr=V/Vc; - B= a1 +a2/pow(Tr,2) +a3/pow(Tr,3); - C= a4 +a5/pow(Tr,2) +a6/pow(Tr,3); - D= a7 +a8/pow(Tr,2) +a9/pow(Tr,3); - E= a10 +a11/pow(Tr,2) +a12/pow(Tr,3); - F= a13/pow(Tr,3); - return 1.0 + B/Vr + C/pow(Vr,2) + D/pow(Vr,4) + E/pow(Vr,5) + F/pow(Vr,2)*(a14+a15/pow(Vr,2))*exp(-a15/pow(Vr,2)); -} -double VLE::LnPHI_CH4(double T, double P){ - double a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15; - double R,V,Tc,Pc,Vc,Tr,Vr,B,C,D,E,Z; - V = 16.04/density_CH4(T,P); - Z = Z_CH4(T,P,V); - a1 = 8.72553928E-2; + Vc = R * Tc / Pc; + Tr = T / Tc; + Vr = V / Vc; + B = a1 + a2 / pow(Tr, 2) + a3 / pow(Tr, 3); + C = a4 + a5 / pow(Tr, 2) + a6 / pow(Tr, 3); + D = a7 + a8 / pow(Tr, 2) + a9 / pow(Tr, 3); + E = a10 + a11 / pow(Tr, 2) + a12 / pow(Tr, 3); + F = a13 / pow(Tr, 3); + return 1.0 + B / Vr + C / pow(Vr, 2) + D / pow(Vr, 4) + E / pow(Vr, 5) + + F / pow(Vr, 2) * (a14 + a15 / pow(Vr, 2)) * exp(-a15 / pow(Vr, 2)); +} +double VLE::LnPHI_CH4(double T, double P) +{ + double a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15; + double R, V, Tc, Pc, Vc, Tr, Vr, B, C, D, E, Z; + V = 16.04 / density_CH4(T, P); + Z = Z_CH4(T, P, V); + a1 = 8.72553928E-2; a2 = -7.52599476E-1; - a3 = 3.75419887E-1; - a4 = 1.07291342E-2; - a5 = 5.49626360E-3; + a3 = 3.75419887E-1; + a4 = 1.07291342E-2; + a5 = 5.49626360E-3; a6 = -1.84772802E-2; - a7 = 3.18993183E-4; - a8 = 2.11079375E-4; - a9 = 2.01682801E-5; - a10= -1.65606189E-5; - a11= 1.19614546E-4; - a12= -1.08087289E-4; - a13= 4.48262295E-2; - a14= 7.53970000E-1; - a15= 7.71670000E-2; - R = 83.14467; + a7 = 3.18993183E-4; + a8 = 2.11079375E-4; + a9 = 2.01682801E-5; + a10 = -1.65606189E-5; + a11 = 1.19614546E-4; + a12 = -1.08087289E-4; + a13 = 4.48262295E-2; + a14 = 7.53970000E-1; + a15 = 7.71670000E-2; + R = 83.14467; Tc = 190.6; Pc = 46.00; - Vc = R*Tc/Pc; - Tr = T/Tc; - Vr = V/Vc; - B = a1 +a2/pow(Tr,2) +a3/pow(Tr,3); - C = a4 +a5/pow(Tr,2) +a6/pow(Tr,3); - D = a7 +a8/pow(Tr,2) +a9/pow(Tr,3); - E = a10 +a11/pow(Tr,2) +a12/pow(Tr,3); - return Z-1-log(Z)+B/Vr+C/2/pow(Vr,2)+D/4/pow(Vr,4)+E/5/pow(Vr,5)+a13/(2*pow(Tr,3)*a15)*(a14+1-(a14+1+a15/pow(Vr,2))*exp(-a15/pow(Vr,2))); -} - -double VLE::Z_H2O(double T, double /*P*/, double V){ - double a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15; - double R,Tc,Pc,Vc,Tr,Vr,B,C,D,E,F; + Vc = R * Tc / Pc; + Tr = T / Tc; + Vr = V / Vc; + B = a1 + a2 / pow(Tr, 2) + a3 / pow(Tr, 3); + C = a4 + a5 / pow(Tr, 2) + a6 / pow(Tr, 3); + D = a7 + a8 / pow(Tr, 2) + a9 / pow(Tr, 3); + E = a10 + a11 / pow(Tr, 2) + a12 / pow(Tr, 3); + return Z - 1 - log(Z) + B / Vr + C / 2 / pow(Vr, 2) + D / 4 / pow(Vr, 4) + E / 5 / pow(Vr, 5) + + a13 / (2 * pow(Tr, 3) * a15) * (a14 + 1 - (a14 + 1 + a15 / pow(Vr, 2)) * exp(-a15 / pow(Vr, 2))); +} + +double VLE::Z_H2O(double T, double /*P*/, double V) +{ + double a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15; + double R, Tc, Pc, Vc, Tr, Vr, B, C, D, E, F; a1 = 8.64449220E-2; - a2 =-3.96918955E-1; - a3 =-5.73334886E-2; - a4 =-2.93893000E-4; - a5 =-4.15775512E-3; + a2 = -3.96918955E-1; + a3 = -5.73334886E-2; + a4 = -2.93893000E-4; + a5 = -4.15775512E-3; a6 = 1.99496791E-2; a7 = 1.18901426E-4; a8 = 1.55212063E-4; - a9 =-1.06855859E-4; - a10=-4.93197687E-6; - a11=-2.73739155E-6; - a12= 2.65571238E-6; - a13= 8.96079018E-3; - a14= 4.02000000; - a15= 2.57000000E-2; - R = 83.14467; + a9 = -1.06855859E-4; + a10 = -4.93197687E-6; + a11 = -2.73739155E-6; + a12 = 2.65571238E-6; + a13 = 8.96079018E-3; + a14 = 4.02000000; + a15 = 2.57000000E-2; + R = 83.14467; Tc = 647.25; Pc = 221.19; - Vc = R*Tc/Pc; - Tr=T/Tc; - Vr=V/Vc; - B= a1 +a2/pow(Tr,2) +a3/pow(Tr,3); - C= a4 +a5/pow(Tr,2) +a6/pow(Tr,3); - D= a7 +a8/pow(Tr,2) +a9/pow(Tr,3); - E= a10 +a11/pow(Tr,2) +a12/pow(Tr,3); - F= a13/pow(Tr,3); - return 1.0 + B/Vr + C/pow(Vr,2) + D/pow(Vr,4) + E/pow(Vr,5) + F/pow(Vr,2)*(a14+a15/pow(Vr,2))*exp(-a15/pow(Vr,2)); -} -double VLE::LnPHI_H2O(double T, double P){ - double a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15; - double R,V,Tc,Pc,Vc,Tr,Vr,B,C,D,E,Z; - V = 18.015/density_H2O(T,P); - Z = Z_H2O(T,P,V); + Vc = R * Tc / Pc; + Tr = T / Tc; + Vr = V / Vc; + B = a1 + a2 / pow(Tr, 2) + a3 / pow(Tr, 3); + C = a4 + a5 / pow(Tr, 2) + a6 / pow(Tr, 3); + D = a7 + a8 / pow(Tr, 2) + a9 / pow(Tr, 3); + E = a10 + a11 / pow(Tr, 2) + a12 / pow(Tr, 3); + F = a13 / pow(Tr, 3); + return 1.0 + B / Vr + C / pow(Vr, 2) + D / pow(Vr, 4) + E / pow(Vr, 5) + + F / pow(Vr, 2) * (a14 + a15 / pow(Vr, 2)) * exp(-a15 / pow(Vr, 2)); +} +double VLE::LnPHI_H2O(double T, double P) +{ + double a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15; + double R, V, Tc, Pc, Vc, Tr, Vr, B, C, D, E, Z; + V = 18.015 / density_H2O(T, P); + Z = Z_H2O(T, P, V); a1 = 8.64449220E-2; - a2 =-3.96918955E-1; - a3 =-5.73334886E-2; - a4 =-2.93893000E-4; - a5 =-4.15775512E-3; + a2 = -3.96918955E-1; + a3 = -5.73334886E-2; + a4 = -2.93893000E-4; + a5 = -4.15775512E-3; a6 = 1.99496791E-2; a7 = 1.18901426E-4; a8 = 1.55212063E-4; - a9 =-1.06855859E-4; - a10=-4.93197687E-6; - a11=-2.73739155E-6; - a12= 2.65571238E-6; - a13= 8.96079018E-3; - a14= 4.02000000; - a15= 2.57000000E-2; - R = 83.14467; + a9 = -1.06855859E-4; + a10 = -4.93197687E-6; + a11 = -2.73739155E-6; + a12 = 2.65571238E-6; + a13 = 8.96079018E-3; + a14 = 4.02000000; + a15 = 2.57000000E-2; + R = 83.14467; Tc = 647.25; Pc = 221.19; - Vc = R*Tc/Pc; - Tr = T/Tc; - Vr = V/Vc; - B = a1 +a2/pow(Tr,2) +a3/pow(Tr,3); - C = a4 +a5/pow(Tr,2) +a6/pow(Tr,3); - D = a7 +a8/pow(Tr,2) +a9/pow(Tr,3); - E = a10 +a11/pow(Tr,2) +a12/pow(Tr,3); - return Z-1-log(Z)+B/Vr+C/2/pow(Vr,2)+D/4/pow(Vr,4)+E/5/pow(Vr,5)+a13/(2*pow(Tr,3)*a15)*(a14+1-(a14+1+a15/pow(Vr,2))*exp(-a15/pow(Vr,2))); + Vc = R * Tc / Pc; + Tr = T / Tc; + Vr = V / Vc; + B = a1 + a2 / pow(Tr, 2) + a3 / pow(Tr, 3); + C = a4 + a5 / pow(Tr, 2) + a6 / pow(Tr, 3); + D = a7 + a8 / pow(Tr, 2) + a9 / pow(Tr, 3); + E = a10 + a11 / pow(Tr, 2) + a12 / pow(Tr, 3); + return Z - 1 - log(Z) + B / Vr + C / 2 / pow(Vr, 2) + D / 4 / pow(Vr, 4) + E / 5 / pow(Vr, 5) + + a13 / (2 * pow(Tr, 3) * a15) * (a14 + 1 - (a14 + 1 + a15 / pow(Vr, 2)) * exp(-a15 / pow(Vr, 2))); } //==MIX of H2O & CO2 fagucity // ln_Phi_H2O -double VLE::PF(double TT, double PP){ - double cPFphi=0.0,lnP; - double d1,d2,d3,d4; - double M,N,P,Q,A,B,C,D,E; - - A = -20.7600738043549+0.0897803300811*TT-0.0000954680712*TT*TT; - B = 3.08284 -0.00956*TT +0.0000092069*TT*TT; - C = -0.38986 +0.00228*TT -0.0000026679*TT*TT; - D = 6.6623328249993 -0.057517079835*TT+0.0000643503862*TT*TT; - E = -0.445272747863 +0.0130486543901*TT -0.000015177905*TT*TT; - - M = A+4.0*B+16.0*C; - N = D+5.0*E; - P = B+8.0*C; +double VLE::PF(double TT, double PP) +{ + double cPFphi = 0.0, lnP; + double d1, d2, d3, d4; + double M, N, P, Q, A, B, C, D, E; + + A = -20.7600738043549 + 0.0897803300811 * TT - 0.0000954680712 * TT * TT; + B = 3.08284 - 0.00956 * TT + 0.0000092069 * TT * TT; + C = -0.38986 + 0.00228 * TT - 0.0000026679 * TT * TT; + D = 6.6623328249993 - 0.057517079835 * TT + 0.0000643503862 * TT * TT; + E = -0.445272747863 + 0.0130486543901 * TT - 0.000015177905 * TT * TT; + + M = A + 4.0 * B + 16.0 * C; + N = D + 5.0 * E; + P = B + 8.0 * C; Q = E; - d4 = -(2.0*M-2.0*N+P+Q)/0.0025; - d3 = (Q-P-0.0225*d4)/2.0; - d2 = P-8.0*d3+d4/16.0; - d1 = M-4.0*d2-16.0*d3-d4/4.0; + d4 = -(2.0 * M - 2.0 * N + P + Q) / 0.0025; + d3 = (Q - P - 0.0225 * d4) / 2.0; + d2 = P - 8.0 * d3 + d4 / 16.0; + d1 = M - 4.0 * d2 - 16.0 * d3 - d4 / 4.0; lnP = log(PP); - if (lnP >= 5.0) cPFphi=D+E*lnP; - if (lnP <= 4.0) cPFphi=A+B*lnP+C*lnP*lnP; - if (lnP > 4.0 && lnP < 5.0) cPFphi=d1+d2*lnP+d3*lnP*lnP+d4/lnP; + if (lnP >= 5.0) + cPFphi = D + E * lnP; + if (lnP <= 4.0) + cPFphi = A + B * lnP + C * lnP * lnP; + if (lnP > 4.0 && lnP < 5.0) + cPFphi = d1 + d2 * lnP + d3 * lnP * lnP + d4 / lnP; return cPFphi; } -double VLE::fraction_H2O(double T, double P, double AW){ - double Z01,Ps_H2O,lnS_phi_H2O; - Ps_H2O= VLE::Psat(T)*10.0; - lnS_phi_H2O= VLE::LnPHI_H2O(T,Ps_H2O*1.00001); - Z01= VLE::PF(T,P); - return exp(Z01)*AW*exp(lnS_phi_H2O)*Ps_H2O/P/P; +double VLE::fraction_H2O(double T, double P, double AW) +{ + double Z01, Ps_H2O, lnS_phi_H2O; + Ps_H2O = VLE::Psat(T) * 10.0; + lnS_phi_H2O = VLE::LnPHI_H2O(T, Ps_H2O * 1.00001); + Z01 = VLE::PF(T, P); + return exp(Z01) * AW * exp(lnS_phi_H2O) * Ps_H2O / P / P; } -double VLE::pressure_CO2(double T, double D){ - double a,b,P,dev,err=1.0e-4; - int i,iter_max=100; - a=5.0e-1; - b=5.0e3; - - for(i=0;i0) a=P; - if(dev<0) b=P; +double VLE::pressure_CO2(double T, double D) +{ + double a, b, P, dev, err = 1.0e-4; + int i, iter_max = 100; + a = 5.0e-1; + b = 5.0e3; + + for (i = 0; i < iter_max; i++) + { + P = (a + b) * 0.5; + dev = D - VLE::density_CO2(T, P); + if (abs(dev) < err) + break; + if (dev > 0) + a = P; + if (dev < 0) + b = P; } return P; } +// m=1000x/((1-x)Mw), if x-->0, ==> m=1000x/Mw, ==> kH=f/x, kM=f/m, ==> kM=kH*x/m, ==> kM=kH*x/(1000x/Mw), ==> +// kM=kH*Mw/1000 +double VLE::Henry_const_CO2(double T) +{ // eq(15) return exp value, ln(kH) + double A, B, C; + double Tr, Tc, Tau, Ps; + Tc = 647.096; + Tr = T / Tc; + Tau = 1.0 - Tr; + A = -8.55445; + B = 4.01195; + C = 9.52345; + Ps = IF97::Psat(T) * 10.0; + return A / Tr + B / Tr * pow(Tau, 0.355) + C * pow(Tr, -0.41) * exp(Tau) + log(Ps) + - log(55.51); //"-log(55.51)" for unit convert from mole fraction to mol/kg water +} -//m=1000x/((1-x)Mw), if x-->0, ==> m=1000x/Mw, ==> kH=f/x, kM=f/m, ==> kM=kH*x/m, ==> kM=kH*x/(1000x/Mw), ==> kM=kH*Mw/1000 -double VLE::Henry_const_CO2(double T){ //eq(15) return exp value, ln(kH) - double A,B,C; - double Tr,Tc,Tau,Ps; - Tc=647.096; - Tr=T/Tc; - Tau=1.0-Tr; - A=-8.55445; - B= 4.01195; - C= 9.52345; - Ps=IF97::Psat(T)*10.0; - return A/Tr +B/Tr*pow(Tau,0.355) +C*pow(Tr,-0.41)*exp(Tau) +log(Ps) -log(55.51); //"-log(55.51)" for unit convert from mole fraction to mol/kg water -} - -double VLE::Henry_const_H2(double T){ //eq(15) return exp value, ln(kH) - double A,B,C; - double Tr,Tc,Tau,Ps; - Tc=647.096; - Tr=T/Tc; - Tau=1.0-Tr; - A=-4.73284; - B= 6.08954; - C= 6.06066; - Ps=IF97::Psat(T)*10.0; - return A/Tr +B/Tr*pow(Tau,0.355) +C*pow(Tr,-0.41)*exp(Tau) +log(Ps) -log(55.51); //"-log(55.51)" for unit convert from mole fraction to mol/kg water -} - -void VLE::EoS_PR_H2(double T, double P, double &V, double &Z, double &lnphi){ - double alpha,beta,q,Psi,Omega,sigma,epsilon,w; - double Tc,Tr,Pc,Pr; - double Znew,Zerr=1.0e-8; - int i,iter_max=20; +double VLE::Henry_const_H2(double T) +{ // eq(15) return exp value, ln(kH) + double A, B, C; + double Tr, Tc, Tau, Ps; + Tc = 647.096; + Tr = T / Tc; + Tau = 1.0 - Tr; + A = -4.73284; + B = 6.08954; + C = 6.06066; + Ps = IF97::Psat(T) * 10.0; + return A / Tr + B / Tr * pow(Tau, 0.355) + C * pow(Tr, -0.41) * exp(Tau) + log(Ps) + - log(55.51); //"-log(55.51)" for unit convert from mole fraction to mol/kg water +} + +void VLE::EoS_PR_H2(double T, double P, double& V, double& Z, double& lnphi) +{ + double alpha, beta, q, Psi, Omega, sigma, epsilon, w; + double Tc, Tr, Pc, Pr; + double Znew, Zerr = 1.0e-8; + int i, iter_max = 20; double I; - w= -0.215; - Tc= 33.3; // K - Pc= 12.97; // bar - Tr= T/Tc; - Pr= P/Pc; - - Omega=0.07780; - Psi=0.45742; - sigma= 1.0+pow(2.0,0.5); - epsilon=1.0-pow(2.0,0.5); - alpha= pow((1.0+(0.37464+1.54226*w-0.26992*w*w)*(1.0-pow(Tr,0.5))),2.0); - - beta= Omega*Pr/Tr; - q=Psi*alpha/Omega/Tr; - - Z=1.0; - Znew=0.0; - for(i=0;i373.15) Ps=IF97::Psat(T)*10.0; - kH+= v0*(P-Ps)/R/T; - return exp(lnphi)*P/exp(kH)/a; -} - -double VLE::density_H2(double T, double P){ - double Z,V,lnphi; //V -cm^3 - double H2_molecular_weight= 2.016; - VLE::EoS_PR_H2(T,P,V,Z,lnphi); - return H2_molecular_weight/V; // unit - g/cm^3 -} - -double VLE::pressure_H2(double T, double dens){ - double a,b,P,dev,err=1.0e-4; - int i,iter_max=100; - a=5.0e-1; - b=5.0e3; - - for(i=0;i0) a=P; - if(dev<0) b=P; + V = Z * 83.14 * T / P; // unit V-cm^3 , P-bar, T-K + I = 1.0 / (sigma - epsilon) * log((Z + sigma * beta) / (Z + epsilon * beta)); + lnphi = Z - 1.0 - log(Z - beta) - q * I; +} + +double VLE::solubility_H2_PR(double T, double P, double a) +{ + double Z, V, lnphi, kH, v0, R, Ps = 1.0; + VLE::EoS_PR_H2(T, P, V, Z, lnphi); + kH = VLE::Henry_const_H2(T); // return ln(kH), unit bar/(mol/kg) + R = 83.14; // unit V-cm^3, P-bar, T-K + // v0 partial moler volume of H2 in water, unit cm^3/mol + v0 = 22.79545 - 0.12791 * (T - 273.15) + + 7.16364e-4 * (T - 273.15) * (T - 273.15); // basd on the Figure 10-2, in J.M. Prausnitz, MTFPE 3rd edition. + if (T > 373.15) + Ps = IF97::Psat(T) * 10.0; + kH += v0 * (P - Ps) / R / T; + return exp(lnphi) * P / exp(kH) / a; +} + +double VLE::density_H2(double T, double P) +{ + double Z, V, lnphi; // V -cm^3 + double H2_molecular_weight = 2.016; + VLE::EoS_PR_H2(T, P, V, Z, lnphi); + return H2_molecular_weight / V; // unit - g/cm^3 +} + +double VLE::pressure_H2(double T, double dens) +{ + double a, b, P, dev, err = 1.0e-4; + int i, iter_max = 100; + a = 5.0e-1; + b = 5.0e3; + + for (i = 0; i < iter_max; i++) + { + P = (a + b) * 0.5; + dev = dens - VLE::density_H2(T, P); + if (abs(dev) < err) + break; + if (dev > 0) + a = P; + if (dev < 0) + b = P; } return P; } diff --git a/GCC/VLE.h b/GCC/VLE.h index c887257b4..29bfba557 100644 --- a/GCC/VLE.h +++ b/GCC/VLE.h @@ -10,62 +10,59 @@ class VLE { private: - public: VLE(void); ~VLE(void); -/* Data */ + /* Data */ static double TT, PP; -/* Methods */ - static double Psat(double T);//unit MPa + /* Methods */ + static double Psat(double T); // unit MPa - //unit T K, P bar, V cm^3, D g/cm^3 - static double density_CO2(double T, double P);//~1300K, 8000bar - static double LnPHI_CO2(double T, double P); - static double Z_CO2(double T, double P, double V); - static double dZ_CO2(double V); - static double density_CH4(double T, double P);//~1300K, 8000bar - static double LnPHI_CH4(double T, double P); - static double Z_CH4(double T, double P, double V); - static double dZ_CH4(double V); - static double density_H2O(double T, double P);//~1300K, 8000bar - static double LnPHI_H2O(double T, double P); - static double Z_H2O(double T, double P, double V); - static double dZ_H2O(double V); + // unit T K, P bar, V cm^3, D g/cm^3 + static double density_CO2(double T, double P); //~1300K, 8000bar + static double LnPHI_CO2(double T, double P); + static double Z_CO2(double T, double P, double V); + static double dZ_CO2(double V); + static double density_CH4(double T, double P); //~1300K, 8000bar + static double LnPHI_CH4(double T, double P); + static double Z_CH4(double T, double P, double V); + static double dZ_CH4(double V); + static double density_H2O(double T, double P); //~1300K, 8000bar + static double LnPHI_H2O(double T, double P); + static double Z_H2O(double T, double P, double V); + static double dZ_H2O(double V); static double density_H2O_CO2(double T, double P, double x); static double LnPHI_H2O_H2O_CO2(double T, double P, double x); static double LnPHI_CO2_H2O_CO2(double T, double P, double x); - static double PF(double T, double P); static double fraction_H2O(double T, double P, double AW); static double pressure_CO2(double T, double D); - //unit CO2 mol/kgw T K, P bar, mNaCl mol/kg + // unit CO2 mol/kgw T K, P bar, mNaCl mol/kg static double solubility_CO2(double T, double P, double mNaCl); - static double u0_CO2(double T, double P); //unit u/RT J/mol - static double lnrCO2(double T, double P, double mNaCl); + static double u0_CO2(double T, double P); // unit u/RT J/mol + static double lnrCO2(double T, double P, double mNaCl); static double solubilityNEW_CO2(double T, double P, double mNaCl); - static double uNEW_CO2(double T, double P); //unit u/RT J/mol + static double uNEW_CO2(double T, double P); // unit u/RT J/mol static double LGAMMA_CO2(double T, double P, double mCO2, double mNaCl); static double solubility_CH4(double T, double P, double mNaCl); - static double u0_CH4(double T, double P); - static double lnrCH4(double T, double P, double mNaCl); + static double u0_CH4(double T, double P); + static double lnrCH4(double T, double P, double mNaCl); static double lamda_CH4_NaCl(double T, double P); static double Henry_const_CO2(double T); static double Henry_const_H2(double T); - static void EoS_PR_H2(double T, double P, double &V, double &Z, double &lnphi); + static void EoS_PR_H2(double T, double P, double& V, double& Z, double& lnphi); static double solubility_H2_PR(double T, double P, double a); static double density_H2(double T, double P); static double pressure_H2(double T, double dens); - static void entrance(void); }; diff --git a/GCC/WATEQdata.h b/GCC/WATEQdata.h index 339c922f4..061571a87 100644 --- a/GCC/WATEQdata.h +++ b/GCC/WATEQdata.h @@ -8,44 +8,18 @@ */ #include -//using namespace std; -const std::string WATEQparam[]= { -"Al Al+3 9 0 ", -"Ba Ba+2 5 0 ", -"Br Br- 3 0 ", -"Ca Ca+2 5 0.165 ", -"CaHCO3 CaHCO3+ 5.4 0 ", -"Cd Cd+2 5.0 0 ", -"Cl Cl- 3.5 0.015 ", -"ClO4 ClO4- 3.5 0 ", -"CO3 CO3-2 5.4 0 ", -"Cu Cu+ 2.5 0 ", -"Cu Cu+2 6 0 ", -"CuOH CuOH+ 4 0 ", -"F F- 3.5 0 ", -"Fe Fe+2 6 0 ", -"Fe Fe+3 9 0 ", -"H H+ 9 0 ", -"H2PO4 H2PO4- 4.5 0 ", -"HCO3 HCO3- 5.4 0 ", -"HPO4 HPO4-2 4 0 ", -"HS HS- 3.5 0 ", -"K K+ 3.5 0.015 ", -"Li Li+ 6 0 ", -"Mg Mg+2 5.5 0.2 ", -"Mn Mn+2 6 0 ", -"Na Na+ 4 0.075 ", -"NH4 NH4+ 2.5 0 ", -"Ni Ni+2 6.0 0 ", -"NO2 NO2- 3 0 ", -"NO3 NO3- 3 0 ", -"OH OH- 3.5 0 ", -"Pb Pb+2 4.5 0 ", -"PO4 PO4-3 4 0 ", -"S S-2 5 0 ", -"SO4 SO4-2 5 -0.04 ", -"Sr Sr+2 5.260 0.121 ", -"SrHCO3 SrHCO3+ 5.4 0 ", -"SrOH SrOH+ 5 0 ", -"Zn Zn+2 5 0 " -}; +// using namespace std; +const std::string WATEQparam[] = { + "Al Al+3 9 0 ", "Ba Ba+2 5 0 ", "Br Br- 3 0 ", + "Ca Ca+2 5 0.165 ", "CaHCO3 CaHCO3+ 5.4 0 ", "Cd Cd+2 5.0 0 ", + "Cl Cl- 3.5 0.015 ", "ClO4 ClO4- 3.5 0 ", "CO3 CO3-2 5.4 0 ", + "Cu Cu+ 2.5 0 ", "Cu Cu+2 6 0 ", "CuOH CuOH+ 4 0 ", + "F F- 3.5 0 ", "Fe Fe+2 6 0 ", "Fe Fe+3 9 0 ", + "H H+ 9 0 ", "H2PO4 H2PO4- 4.5 0 ", "HCO3 HCO3- 5.4 0 ", + "HPO4 HPO4-2 4 0 ", "HS HS- 3.5 0 ", "K K+ 3.5 0.015 ", + "Li Li+ 6 0 ", "Mg Mg+2 5.5 0.2 ", "Mn Mn+2 6 0 ", + "Na Na+ 4 0.075 ", "NH4 NH4+ 2.5 0 ", "Ni Ni+2 6.0 0 ", + "NO2 NO2- 3 0 ", "NO3 NO3- 3 0 ", "OH OH- 3.5 0 ", + "Pb Pb+2 4.5 0 ", "PO4 PO4-3 4 0 ", "S S-2 5 0 ", + "SO4 SO4-2 5 -0.04 ", "Sr Sr+2 5.260 0.121 ", "SrHCO3 SrHCO3+ 5.4 0 ", + "SrOH SrOH+ 5 0 ", "Zn Zn+2 5 0 "}; diff --git a/GCC/eqbrm.h b/GCC/eqbrm.h index 3fbbca74d..64da43ab5 100644 --- a/GCC/eqbrm.h +++ b/GCC/eqbrm.h @@ -18,21 +18,19 @@ #include #include #include -//using namespace std; +// using namespace std; class EQ { - private: - public: EQ(void); ~EQ(void); - static std::vector species; //name of species in the last line of input file (eqbrm.in) + static std::vector species; // name of species in the last line of input file (eqbrm.in) static double T, P; -/* Data */ + /* Data */ typedef struct { std::vector species_name; @@ -40,7 +38,7 @@ class EQ std::vector species_stoi; double logK; double stoi_water; - }ReactionData; + } ReactionData; static std::vector eq_reactions; typedef struct @@ -51,40 +49,39 @@ class EQ int idx_phase; std::vector idx_element; std::vector stoi_element; - }SpeciesData; + } SpeciesData; static std::vector eq_species; - //set chemical system for eqbrm input value + // set chemical system for eqbrm input value int NN, MM; - double **VV; //mass action submatrix - double **GG; //mass balance submatrix --> chemical element - double *ZZ; //charge vector - std::vector chemical_species, chemical_element; //name and index of species and element - - //pass parameters - double *LOGKK; - double *BB; //mass amount --> chemical element - int *xidx_phase; // phase index vector + double** VV; // mass action submatrix + double** GG; // mass balance submatrix --> chemical element + double* ZZ; // charge vector + std::vector chemical_species, chemical_element; // name and index of species and element + + // pass parameters + double* LOGKK; + double* BB; // mass amount --> chemical element + int* xidx_phase; // phase index vector double *AA, *GAMMAA; // concentration and activity coefficent double AAW; - double *xstoi_water; // check "H2O" in reactions, 0 no water, 1 or -1 water stoi number - - int activity_model; //0-9 + double* xstoi_water; // check "H2O" in reactions, 0 no water, 1 or -1 water stoi number + int activity_model; // 0-9 + /* Method */ + void eqbrm(int N, int M, double** V, double* B, double** G, double* LOGK, double* Z, double* A, double* GAMMA, + double& AW); + void eqbrm_multiphases(int N, int M, double** V, double* B, double** G, double* LOGK, double* VW, double* Z, int* P, + double* A, double* GAMMA, double& AW); + void actcof(double N, double* Z, double* A, double* GAMMA, double& AW); + void actcofWATEQ(double N, double* Z, double* A, double* GAMMA, double& AW); - -/* Method */ - void eqbrm(int N, int M, double **V, double *B, double **G, double *LOGK, double *Z, double *A, double *GAMMA, double &AW); - void eqbrm_multiphases(int N, int M, double **V, double *B, double **G, double *LOGK, double *VW, double *Z, int *P, double *A, double *GAMMA, double &AW); - void actcof(double N, double *Z, double *A, double *GAMMA, double &AW); - void actcofWATEQ(double N, double *Z, double *A, double *GAMMA, double &AW); - - void ludcmp(double **a, int n, int *indx, double *d); - void lubksb(double **a, int n, int *indx, double b[]); - double **matrix(int row, int col); - static double **matrix_new(int row, int col); - void matrixdel(double **data); + void ludcmp(double** a, int n, int* indx, double* d); + void lubksb(double** a, int n, int* indx, double b[]); + double** matrix(int row, int col); + static double** matrix_new(int row, int col); + void matrixdel(double** data); void entrance(void); void load_chemical_system(void); @@ -93,8 +90,7 @@ class EQ void reset_estimated_value(void); - void calc_activity(double *A, double *GAMMA, double &AW); - + void calc_activity(double* A, double* GAMMA, double& AW); void batch_calc(void); void batch_calc_pH(void); diff --git a/GCC/logk.cpp b/GCC/logk.cpp index 6b5a686f0..4d99ca8ff 100644 --- a/GCC/logk.cpp +++ b/GCC/logk.cpp @@ -16,121 +16,133 @@ #include "VLE.h" using namespace std; -//calculating ion product of NaCl -double LOGK::KsNaCl(double T, double P){ - return 1.188919E+03-2.636581E+00*T-1.561700E+05/T+1.795657E-03*T*T+3.237887E-03*P+5.409459E-05*T*P+7.200665E-06*P*P-2.992790E-08*T*P*P; - //Knacl=1188.919-2.636581*B1-156170/B1+0.001795657*B1*B1+0.003237887*C1+0.00005409459*B1*C1+0.000007200665*C1*C1-0.0000000299279*B1*C1*C1 +// calculating ion product of NaCl +double LOGK::KsNaCl(double T, double P) +{ + return 1.188919E+03 - 2.636581E+00 * T - 1.561700E+05 / T + 1.795657E-03 * T * T + 3.237887E-03 * P + + 5.409459E-05 * T * P + 7.200665E-06 * P * P - 2.992790E-08 * T * P * P; + // Knacl=1188.919-2.636581*B1-156170/B1+0.001795657*B1*B1+0.003237887*C1+0.00005409459*B1*C1+0.000007200665*C1*C1-0.0000000299279*B1*C1*C1 } -//calculating ion product of pure water -double LOGK::logKw(double T, double P){ - double a1,a2,a3,a4,a5,a6,a7,A,B; - a1 = -4.098; - a2 = -3245.2; - a3 = 2.2362e5; - a4 = -3.984e7; - a5 = 13.957; - a6 = -1262.3; - a7 = 8.5641e5; - A=a1+a2/T+a3/(T*T)+a4/(T*T*T); - B=a5+a6/T+a7/(T*T); - return A+B*log10(IF97::density(T,P/10.0)/1.0e3); +// calculating ion product of pure water +double LOGK::logKw(double T, double P) +{ + double a1, a2, a3, a4, a5, a6, a7, A, B; + a1 = -4.098; + a2 = -3245.2; + a3 = 2.2362e5; + a4 = -3.984e7; + a5 = 13.957; + a6 = -1262.3; + a7 = 8.5641e5; + A = a1 + a2 / T + a3 / (T * T) + a4 / (T * T * T); + B = a5 + a6 / T + a7 / (T * T); + return A + B * log10(IF97::density(T, P / 10.0) / 1.0e3); } - -//calculating logK1 logK2 -double LOGK::logK1(double T, double P){ - double dV1,dk1,lnKs1; - dV1=LOGK::dV1(T); - dk1=LOGK::dk1(T); - lnKs1=LOGK::lnKs1(T); - return LOGK::lnK(T,P,dV1,dk1,lnKs1)/2.302585; +// calculating logK1 logK2 +double LOGK::logK1(double T, double P) +{ + double dV1, dk1, lnKs1; + dV1 = LOGK::dV1(T); + dk1 = LOGK::dk1(T); + lnKs1 = LOGK::lnKs1(T); + return LOGK::lnK(T, P, dV1, dk1, lnKs1) / 2.302585; } -double LOGK::logK2(double T, double P){ - double dV2,dk2,lnKs2; - dV2=LOGK::dV2(T); - dk2=LOGK::dk2(T); - lnKs2=LOGK::lnKs2(T); - return LOGK::lnK(T,P,dV2,dk2,lnKs2)/2.302585; +double LOGK::logK2(double T, double P) +{ + double dV2, dk2, lnKs2; + dV2 = LOGK::dV2(T); + dk2 = LOGK::dk2(T); + lnKs2 = LOGK::lnKs2(T); + return LOGK::lnK(T, P, dV2, dk2, lnKs2) / 2.302585; } -double LOGK::lnK(double T, double P, double dV, double dk, double lnKs){ - double Ps; - if (T>=373.15) - Ps=IF97::Psat(T)*10.0; +double LOGK::lnK(double T, double P, double dV, double dk, double lnKs) +{ + double Ps; + if (T >= 373.15) + Ps = IF97::Psat(T) * 10.0; else - Ps=1.0; - return -1.0/8.314/T*(-1.0*dV/10.0*(P-Ps)+0.5*dk/10000.0*(P-Ps)*(P-Ps))+lnKs; + Ps = 1.0; + return -1.0 / 8.314 / T * (-1.0 * dV / 10.0 * (P - Ps) + 0.5 * dk / 10000.0 * (P - Ps) * (P - Ps)) + lnKs; } -double LOGK::lnKs1(double T){ - double a1,a2,a3,a4,a5; - a1 = 233.5159304; - a2 = 0.0; - a3 = -11974.38348; - a4 = 0.0; - a5 = -36.50633536; - return a1+a2*T+a3/T+a4/T/T+a5*log(T); +double LOGK::lnKs1(double T) +{ + double a1, a2, a3, a4, a5; + a1 = 233.5159304; + a2 = 0.0; + a3 = -11974.38348; + a4 = 0.0; + a5 = -36.50633536; + return a1 + a2 * T + a3 / T + a4 / T / T + a5 * log(T); } -double LOGK::dV1(double T){ - double a1,a2,a3,a4,a5; - a1 = -3748.1678; - a2 = 0.0; - a3 = 177207.90885; - a4 = 0.0; - a5 = 558.25496; - return a1+a2*T+a3/T+a4/T/T+a5*log(T); +double LOGK::dV1(double T) +{ + double a1, a2, a3, a4, a5; + a1 = -3748.1678; + a2 = 0.0; + a3 = 177207.90885; + a4 = 0.0; + a5 = 558.25496; + return a1 + a2 * T + a3 / T + a4 / T / T + a5 * log(T); } -double LOGK::dk1(double T){ - double a1,a2,a3,a4,a5; +double LOGK::dk1(double T) +{ + double a1, a2, a3, a4, a5; a1 = -1395.81946; - a2 = 0.0; - a3 = 66772.55024; - a4 = 0.0; - a5 = 206.23006; - return a1+a2*T+a3/T+a4/T/T+a5*log(T); + a2 = 0.0; + a3 = 66772.55024; + a4 = 0.0; + a5 = 206.23006; + return a1 + a2 * T + a3 / T + a4 / T / T + a5 * log(T); } -double LOGK::lnKs2(double T){ - double a1,a2,a3,a4,a5; - a1 = -151.1815202; - a2 = -0.088695577; - a3 = -1362.259146; - a4 = 0.0; - a5 = 27.79798156; - return a1+a2*T+a3/T+a4/T/T+a5*log(T); +double LOGK::lnKs2(double T) +{ + double a1, a2, a3, a4, a5; + a1 = -151.1815202; + a2 = -0.088695577; + a3 = -1362.259146; + a4 = 0.0; + a5 = 27.79798156; + return a1 + a2 * T + a3 / T + a4 / T / T + a5 * log(T); } -double LOGK::dV2(double T){ - double a1,a2,a3,a4,a5; - a1 = -2453.97326; - a2 = 0.0; - a3 = 115489.29266; - a4 = 0.0; - a5 = 367.46855; - return a1+a2*T+a3/T+a4/T/T+a5*log(T); +double LOGK::dV2(double T) +{ + double a1, a2, a3, a4, a5; + a1 = -2453.97326; + a2 = 0.0; + a3 = 115489.29266; + a4 = 0.0; + a5 = 367.46855; + return a1 + a2 * T + a3 / T + a4 / T / T + a5 * log(T); } -double LOGK::dk2(double T){ - double a1,a2,a3,a4,a5; - a1 = -535.45092; - a2 = 0.0; - a3 = 27345.82051; - a4 = 0.0; - a5 = 78.76586; - return a1+a2*T+a3/T+a4/T/T+a5*log(T); +double LOGK::dk2(double T) +{ + double a1, a2, a3, a4, a5; + a1 = -535.45092; + a2 = 0.0; + a3 = 27345.82051; + a4 = 0.0; + a5 = 78.76586; + return a1 + a2 * T + a3 / T + a4 / T / T + a5 * log(T); } - -double LOGK::logK_CO2(double T, double P){ - double lnkH,Vphi,R,lnphi,Ps=1.0; - if(T>373.15) Ps=IF97::Psat(T)*10.0; - R=83.14471; //unit V-cm^3, P-bar, T-K - lnphi = VLE::LnPHI_CO2(T,P); - lnkH = 1.3999520898E+01 -1.3340507000E-02*T -5.5897820016E+02/T -4.2257732219E+05/T/T; - Vphi = 35.663-5.960e-2*(T-273.15) +6.308e-4*(T-273.15)*(T-273.15); - return log10(exp(lnphi)*P/exp(lnkH + Vphi*(P-Ps)/R/T)); //return eq CO2 activity in aqueous phase +double LOGK::logK_CO2(double T, double P) +{ + double lnkH, Vphi, R, lnphi, Ps = 1.0; + if (T > 373.15) + Ps = IF97::Psat(T) * 10.0; + R = 83.14471; // unit V-cm^3, P-bar, T-K + lnphi = VLE::LnPHI_CO2(T, P); + lnkH = 1.3999520898E+01 - 1.3340507000E-02 * T - 5.5897820016E+02 / T - 4.2257732219E+05 / T / T; + Vphi = 35.663 - 5.960e-2 * (T - 273.15) + 6.308e-4 * (T - 273.15) * (T - 273.15); + return log10(exp(lnphi) * P / exp(lnkH + Vphi * (P - Ps) / R / T)); // return eq CO2 activity in aqueous phase } diff --git a/GCC/logk.h b/GCC/logk.h index 26b8bfa8d..62e10daed 100644 --- a/GCC/logk.h +++ b/GCC/logk.h @@ -7,16 +7,16 @@ * */ - //using namespace std; +// using namespace std; class LOGK { private: public: - static double KsNaCl(double T, double P);//NaCl -> Na + Cl - static double logKw(double T, double P);//H2O -> H + OH - static double logK1(double T, double P);//H2O + CO2 -> HCO3 + H - static double logK2(double T, double P);//HCO3 -> CO3 + H - static double logK_CO2(double T, double P); //CO2.gas -> CO2,aq + static double KsNaCl(double T, double P); // NaCl -> Na + Cl + static double logKw(double T, double P); // H2O -> H + OH + static double logK1(double T, double P); // H2O + CO2 -> HCO3 + H + static double logK2(double T, double P); // HCO3 -> CO3 + H + static double logK_CO2(double T, double P); // CO2.gas -> CO2,aq static double lnKs1(double T); static double dV1(double T); @@ -25,6 +25,4 @@ class LOGK static double dV2(double T); static double dk2(double T); static double lnK(double T, double P, double dV, double dk, double lnKs); - - }; diff --git a/GCC/species.h b/GCC/species.h index 267daac68..1a186eb5e 100644 --- a/GCC/species.h +++ b/GCC/species.h @@ -8,158 +8,41 @@ */ #include -//using namespace std; -const std::string ELEMENTS[]= { -"0 Charge Ea ", -"1 Hydrogen H ", -"2 Helium He ", -"3 Lithium Li ", -"4 Beryllium Be ", -"5 Boron B ", -"6 Carbon C ", -"7 Nitrogen N ", -"8 Oxygen O ", -"9 Fluorine F ", -"10 Neon Ne ", -"11 Sodium Na ", -"12 Magnesium Mg ", -"13 Aluminum Al ", -"14 Silicon Si ", -"15 Phosphorus P ", -"16 Sulfur S ", -"17 Chlorine Cl ", -"18 Argon Ar ", -"19 Potassium K ", -"20 Calcium Ca ", -"21 Scandium Sc ", -"22 Titanium Ti ", -"23 Vanadium V ", -"24 Chromium Cr ", -"25 Manganese Mn ", -"26 Iron Fe ", -"27 Cobalt Co ", -"28 Nickel Ni ", -"29 Copper Cu ", -"30 Zinc Zn ", -"31 Gallium Ga ", -"32 Germanium Ge ", -"33 Arsenic As ", -"34 Selenium Se ", -"35 Bromine Br ", -"36 Krypton Kr ", -"37 Rubidium Rb ", -"38 Strontium Sr ", -"39 Yttrium Y ", -"40 Zirconium Zr ", -"41 Niobium Nb ", -"42 Molybdenum Mo ", -"43 Technetium Tc ", -"44 Ruthenium Ru ", -"45 Rhodium Rh ", -"46 Palladium Pd ", -"47 Silver Ag ", -"48 Cadmium Cd ", -"49 Indium In ", -"50 Tin Sn ", -"51 Antimony Sb ", -"52 Tellurium Te ", -"53 Iodine I ", -"54 Xenon Xe ", -"55 Cesium Cs ", -"56 Barium Ba ", -"57 Lanthanum La ", -"58 Cerium Ce ", -"59 Praseodymium Pr ", -"60 Neodymium Nd ", -"61 Promethium Pm ", -"62 Samarium Sm ", -"63 Europium Eu ", -"64 Gadolinium Gd ", -"65 Terbium Tb ", -"66 Dysprosium Dy ", -"67 Holmium Ho ", -"68 Erbium Er ", -"69 Thulium Tm ", -"70 Ytterbium Yb ", -"71 Lutetium Lu ", -"72 Hafnium Hf ", -"73 Tantalum Ta ", -"74 Tungsten W ", -"75 Rhenium Re ", -"76 Osmium Os ", -"77 Iridium Ir ", -"78 Platinum Pt ", -"79 Gold Au ", -"80 Mercury Hg ", -"81 Thallium Tl ", -"82 Lead Pb ", -"83 Bismuth Bi ", -"84 Polonium Po ", -"85 Astatine At ", -"86 Radon Rn ", -"87 Francium Fr ", -"88 Radium Ra ", -"89 Actinium Ac ", -"90 Thorium Th ", -"91 Protactinium Pa ", -"92 Uranium U ", -"93 Neptunium Np ", -"94 Plutonium Pu ", -"95 Americium Am ", -"96 Curium Cm ", -"97 Berkelium Bk ", -"98 Californium Cf ", -"99 Einsteinium Es ", -"100 Fermium Fm ", -"101 Mendelevium Md ", -"102 Nobelium No ", -"103 Lawrencium Lr ", -"104 Rutherfordium Rf ", -"105 Dubnium Db ", -"106 Seaborgium Sg ", -"107 Bohrium Bh ", -"108 Hassium Hs ", -"109 Meitnerium Mt ", -"110 Darmstadtium Ds ", -"111 Roentgenium Rg ", -"112 Ununbium Uub", -"113 Ununtrium Uut", -"114 Ununquadium Uuq", -"115 Ununpentium Uup", -"116 Ununhexium Uuh", -"117 Ununseptium Uus", -"118 Ununoctium Uuo" -}; -const std::string SPECIES[]= { //in aqueous phase -//"H2O 0", -"H 1", -"OH -1", -"HCO3 -1", -"CO3 -2", -"Li 1", -"Na 1", -"K 1", -"Rb 1", -"Cs 1", -"Ca 2", -"CaCO3 0", -"CO2 0", -"CaHCO3 1", -"Cl -1", -"Br -1", -"I -1", -"HCl 0", -"NaOH 0", -"NaCl 0", -"NaHCO3 0", -"NaCO3 -1", -"CaOH 1", -"CaCl 1", -"CaCl2 0" -}; -const std::string MINERALS[]= { -"CALCITE CaCO3", -"DOLOMITE CaMg(CO3)2", -"HALITE NaCl", -"CO2gas CO2" -}; +// using namespace std; +const std::string ELEMENTS[] + = {"0 Charge Ea ", "1 Hydrogen H ", "2 Helium He ", "3 Lithium Li ", + "4 Beryllium Be ", "5 Boron B ", "6 Carbon C ", "7 Nitrogen N ", + "8 Oxygen O ", "9 Fluorine F ", "10 Neon Ne ", "11 Sodium Na ", + "12 Magnesium Mg ", "13 Aluminum Al ", "14 Silicon Si ", "15 Phosphorus P ", + "16 Sulfur S ", "17 Chlorine Cl ", "18 Argon Ar ", "19 Potassium K ", + "20 Calcium Ca ", "21 Scandium Sc ", "22 Titanium Ti ", "23 Vanadium V ", + "24 Chromium Cr ", "25 Manganese Mn ", "26 Iron Fe ", "27 Cobalt Co ", + "28 Nickel Ni ", "29 Copper Cu ", "30 Zinc Zn ", "31 Gallium Ga ", + "32 Germanium Ge ", "33 Arsenic As ", "34 Selenium Se ", "35 Bromine Br ", + "36 Krypton Kr ", "37 Rubidium Rb ", "38 Strontium Sr ", "39 Yttrium Y ", + "40 Zirconium Zr ", "41 Niobium Nb ", "42 Molybdenum Mo ", "43 Technetium Tc ", + "44 Ruthenium Ru ", "45 Rhodium Rh ", "46 Palladium Pd ", "47 Silver Ag ", + "48 Cadmium Cd ", "49 Indium In ", "50 Tin Sn ", "51 Antimony Sb ", + "52 Tellurium Te ", "53 Iodine I ", "54 Xenon Xe ", "55 Cesium Cs ", + "56 Barium Ba ", "57 Lanthanum La ", "58 Cerium Ce ", "59 Praseodymium Pr ", + "60 Neodymium Nd ", "61 Promethium Pm ", "62 Samarium Sm ", "63 Europium Eu ", + "64 Gadolinium Gd ", "65 Terbium Tb ", "66 Dysprosium Dy ", "67 Holmium Ho ", + "68 Erbium Er ", "69 Thulium Tm ", "70 Ytterbium Yb ", "71 Lutetium Lu ", + "72 Hafnium Hf ", "73 Tantalum Ta ", "74 Tungsten W ", "75 Rhenium Re ", + "76 Osmium Os ", "77 Iridium Ir ", "78 Platinum Pt ", "79 Gold Au ", + "80 Mercury Hg ", "81 Thallium Tl ", "82 Lead Pb ", "83 Bismuth Bi ", + "84 Polonium Po ", "85 Astatine At ", "86 Radon Rn ", "87 Francium Fr ", + "88 Radium Ra ", "89 Actinium Ac ", "90 Thorium Th ", "91 Protactinium Pa ", + "92 Uranium U ", "93 Neptunium Np ", "94 Plutonium Pu ", "95 Americium Am ", + "96 Curium Cm ", "97 Berkelium Bk ", "98 Californium Cf ", "99 Einsteinium Es ", + "100 Fermium Fm ", "101 Mendelevium Md ", "102 Nobelium No ", "103 Lawrencium Lr ", + "104 Rutherfordium Rf ", "105 Dubnium Db ", "106 Seaborgium Sg ", "107 Bohrium Bh ", + "108 Hassium Hs ", "109 Meitnerium Mt ", "110 Darmstadtium Ds ", "111 Roentgenium Rg ", + "112 Ununbium Uub", "113 Ununtrium Uut", "114 Ununquadium Uuq", "115 Ununpentium Uup", + "116 Ununhexium Uuh", "117 Ununseptium Uus", "118 Ununoctium Uuo"}; +const std::string SPECIES[] = { // in aqueous phase + //"H2O 0", + "H 1", "OH -1", "HCO3 -1", "CO3 -2", "Li 1", "Na 1", "K 1", "Rb 1", + "Cs 1", "Ca 2", "CaCO3 0", "CO2 0", "CaHCO3 1", "Cl -1", "Br -1", "I -1", + "HCl 0", "NaOH 0", "NaCl 0", "NaHCO3 0", "NaCO3 -1", "CaOH 1", "CaCl 1", "CaCl2 0"}; +const std::string MINERALS[] = {"CALCITE CaCO3", "DOLOMITE CaMg(CO3)2", "HALITE NaCl", "CO2gas CO2"}; diff --git a/GEO/AxisAlignedBoundingBox.cpp b/GEO/AxisAlignedBoundingBox.cpp index 423273b03..54d3d61a7 100644 --- a/GEO/AxisAlignedBoundingBox.cpp +++ b/GEO/AxisAlignedBoundingBox.cpp @@ -17,32 +17,32 @@ namespace GEOLIB { -AABB::AABB () +AABB::AABB() { for (std::size_t k(0); k < 3; k++) { _min_pnt[k] = std::numeric_limits::max(); - _max_pnt[k] = - std::numeric_limits::max(); + _max_pnt[k] = -std::numeric_limits::max(); } } -AABB::AABB(AABB const& src) : - _min_pnt(src._min_pnt.getData()), _max_pnt(src._max_pnt.getData()) -{} +AABB::AABB(AABB const& src) : _min_pnt(src._min_pnt.getData()), _max_pnt(src._max_pnt.getData()) +{ +} -AABB::AABB ( const std::vector* points ) +AABB::AABB(const std::vector* points) { - size_t nPoints (points->size()); + size_t nPoints(points->size()); for (size_t i = 0; i < nPoints; i++) this->update((*(*points)[i])[0], (*(*points)[i])[1], (*(*points)[i])[2]); } -void AABB::update (GEOLIB::Point const & pnt) +void AABB::update(GEOLIB::Point const& pnt) { - update (pnt[0], pnt[1], pnt[2]); + update(pnt[0], pnt[1], pnt[2]); } -void AABB::update (double x, double y, double z) +void AABB::update(double x, double y, double z) { if (x < _min_pnt[0]) _min_pnt[0] = x; @@ -58,32 +58,40 @@ void AABB::update (double x, double y, double z) _max_pnt[2] = z; } -bool AABB::containsPoint (GEOLIB::Point const & pnt, double eps) const +bool AABB::containsPoint(GEOLIB::Point const& pnt, double eps) const { - return containsPoint (pnt[0], pnt[1], pnt[2], eps); + return containsPoint(pnt[0], pnt[1], pnt[2], eps); } -bool AABB::containsPoint (const double* pnt, double eps) const +bool AABB::containsPoint(const double* pnt, double eps) const { - return containsPoint (pnt[0], pnt[1], pnt[2], eps); + return containsPoint(pnt[0], pnt[1], pnt[2], eps); } -bool AABB::containsPoint (double x, double y, double z, double eps) const +bool AABB::containsPoint(double x, double y, double z, double eps) const { - if ((_min_pnt[0] <= x && x <= _max_pnt[0]) || std::fabs(_min_pnt[0] - x) < eps - || std::fabs(x - _max_pnt[0]) < eps) { + if ((_min_pnt[0] <= x && x <= _max_pnt[0]) || std::fabs(_min_pnt[0] - x) < eps || std::fabs(x - _max_pnt[0]) < eps) + { if ((_min_pnt[1] <= y && y <= _max_pnt[1]) || std::fabs(_min_pnt[1] - y) < eps - || std::fabs(y - _max_pnt[1]) < eps) { + || std::fabs(y - _max_pnt[1]) < eps) + { if ((_min_pnt[2] <= z && z <= _max_pnt[2]) || std::fabs(_min_pnt[2] - z) < eps - || std::fabs(z - _max_pnt[2]) < eps) { + || std::fabs(z - _max_pnt[2]) < eps) + { return true; - } else { + } + else + { return false; } - } else { + } + else + { return false; } - } else return false; + } + else + return false; } } // end namespace GEOLIB diff --git a/GEO/AxisAlignedBoundingBox.h b/GEO/AxisAlignedBoundingBox.h index 0efc0b81f..38eae5a66 100644 --- a/GEO/AxisAlignedBoundingBox.h +++ b/GEO/AxisAlignedBoundingBox.h @@ -31,7 +31,7 @@ class AABB /** * construction of object, initialization the axis aligned bounding box * */ - AABB (); + AABB(); /** * copy constructor. @@ -43,45 +43,37 @@ class AABB /** * construction of object using vector of points * */ - AABB ( const std::vector* points ); + AABB(const std::vector* points); - void update (GEOLIB::Point const & pnt); + void update(GEOLIB::Point const& pnt); /** * update axis aligned bounding box */ - void update (double x, double y, double z); + void update(double x, double y, double z); /** * update axis aligned bounding box */ - void update (const double* pnt) - { - update (pnt[0], pnt[1], pnt[2]); - } - + void update(const double* pnt) { update(pnt[0], pnt[1], pnt[2]); } /** * check if point is in the axis aligned bounding box * (employing containsPoint (double x, double y, double z)) */ - bool containsPoint (GEOLIB::Point const & pnt, - double eps = std::numeric_limits::epsilon()) const; + bool containsPoint(GEOLIB::Point const& pnt, double eps = std::numeric_limits::epsilon()) const; /** * wrapper for GEOLIB::Point */ - bool containsPoint (const double* pnt, double eps = - std::numeric_limits::epsilon()) const; + bool containsPoint(const double* pnt, double eps = std::numeric_limits::epsilon()) const; /** * check if point described by its coordinates x, y, z is in * the axis aligned bounding box */ - bool containsPoint(double x, double y, double z, double eps = - std::numeric_limits::epsilon()) const; - - GEOLIB::Point const& getMinPoint () const { return _min_pnt; } - GEOLIB::Point const& getMaxPoint () const { return _max_pnt; } + bool containsPoint(double x, double y, double z, double eps = std::numeric_limits::epsilon()) const; + GEOLIB::Point const& getMinPoint() const { return _min_pnt; } + GEOLIB::Point const& getMaxPoint() const { return _max_pnt; } protected: GEOLIB::Point _min_pnt; GEOLIB::Point _max_pnt; diff --git a/GEO/BruteForceClosestPair.cpp b/GEO/BruteForceClosestPair.cpp index bf0d88d76..e1ef17a23 100644 --- a/GEO/BruteForceClosestPair.cpp +++ b/GEO/BruteForceClosestPair.cpp @@ -15,17 +15,16 @@ namespace GEOLIB { -BruteForceClosestPair::BruteForceClosestPair( - std::vector const & pnts, size_t& id0, size_t& id1) : - ClosestPair (pnts, id0, id1) +BruteForceClosestPair::BruteForceClosestPair(std::vector const& pnts, size_t& id0, size_t& id1) + : ClosestPair(pnts, id0, id1) { - double sqr_shortest_dist (MathLib::sqrDist (_pnts[0], _pnts[1])); + double sqr_shortest_dist(MathLib::sqrDist(_pnts[0], _pnts[1])); - const size_t n_pnts (_pnts.size()); + const size_t n_pnts(_pnts.size()); for (size_t i(0); i < n_pnts; i++) for (size_t j(i + 1); j < n_pnts; j++) { - double sqr_dist (MathLib::sqrDist (_pnts[i], _pnts[j])); + double sqr_dist(MathLib::sqrDist(_pnts[i], _pnts[j])); if (sqr_dist < sqr_shortest_dist) { sqr_shortest_dist = sqr_dist; diff --git a/GEO/BruteForceClosestPair.h b/GEO/BruteForceClosestPair.h index 3cde4901f..417ef7f76 100644 --- a/GEO/BruteForceClosestPair.h +++ b/GEO/BruteForceClosestPair.h @@ -20,7 +20,7 @@ namespace GEOLIB class BruteForceClosestPair : public ClosestPair { public: - BruteForceClosestPair(std::vector const & pnts, size_t& id0, size_t& id1); + BruteForceClosestPair(std::vector const& pnts, size_t& id0, size_t& id1); }; } // end namespace GEOLIB diff --git a/GEO/ClosestPair.h b/GEO/ClosestPair.h index b4e16f0ce..c3d7a86f3 100644 --- a/GEO/ClosestPair.h +++ b/GEO/ClosestPair.h @@ -24,12 +24,9 @@ namespace GEOLIB class ClosestPair { public: - ClosestPair (std::vector const & pnts, size_t id0, size_t id1) : - _pnts (pnts), _id0 (id0), _id1 (id1) - {} - + ClosestPair(std::vector const& pnts, size_t id0, size_t id1) : _pnts(pnts), _id0(id0), _id1(id1) {} protected: - std::vector const & _pnts; + std::vector const& _pnts; size_t _id0; size_t _id1; }; diff --git a/GEO/Color.cpp b/GEO/Color.cpp index a119a2e36..d6e388dfa 100644 --- a/GEO/Color.cpp +++ b/GEO/Color.cpp @@ -24,19 +24,20 @@ Color* getRandomColor() return new Color((rand() % 5) * 50, (rand() % 5) * 50, (rand() % 5) * 50); } -int readColorLookupTable(std::map &colors, const std::string &filename) +int readColorLookupTable(std::map& colors, const std::string& filename) { std::string id = "", line = ""; - std::ifstream in( filename.c_str() ); + std::ifstream in(filename.c_str()); if (!in.is_open()) { - std::cout << "Color::readLookupTable() - Could not open file..." << "\n"; + std::cout << "Color::readLookupTable() - Could not open file..." + << "\n"; return 0; } - while ( getline(in, line) ) + while (getline(in, line)) { std::list fields = splitString(line, '\t'); Color* c = new Color(); @@ -59,19 +60,19 @@ int readColorLookupTable(std::map &colors, const std::strin return 1; } -const Color* getColor(const std::string &id, std::map &colors) +const Color* getColor(const std::string& id, std::map& colors) { - for (std::map::const_iterator it = colors.begin(); it != colors.end(); - ++it) + for (std::map::const_iterator it = colors.begin(); it != colors.end(); ++it) if (id.compare(it->first) == 0) return it->second; - std::cout << "Key \"" << id << "\" not found in color lookup table..." << "\n"; + std::cout << "Key \"" << id << "\" not found in color lookup table..." + << "\n"; Color* c = getRandomColor(); colors.insert(std::pair(id, c)); return c; } -const Color* getColor(double id, std::map &colors) +const Color* getColor(double id, std::map& colors) { std::ostringstream stream; stream << id; diff --git a/GEO/Color.h b/GEO/Color.h index c15a5e133..e78973a9f 100644 --- a/GEO/Color.h +++ b/GEO/Color.h @@ -27,14 +27,14 @@ typedef TemplatePoint Color; Color* getRandomColor(); /// Reads a color-lookup-table from a file and writes it to a map. -int readColorLookupTable(std::map &colors, const std::string &filename); +int readColorLookupTable(std::map& colors, const std::string& filename); /// Uses a color-lookup-table (in form of a map) to return a colour for a specified name. If the name is not /// in the colortable a new entry is created with the new name and a random colour. -const Color* getColor(const std::string &id, std::map &colors); +const Color* getColor(const std::string& id, std::map& colors); /// Convenience function to use the getColor method with numbers as identifiers. -const Color* getColor(double id, std::map &colors); +const Color* getColor(double id, std::map& colors); } // namespace #endif /* COLOR_H_ */ diff --git a/GEO/GEOObjects.cpp b/GEO/GEOObjects.cpp index 276807888..7ffd10fcf 100644 --- a/GEO/GEOObjects.cpp +++ b/GEO/GEOObjects.cpp @@ -35,7 +35,7 @@ GEOObjects::~GEOObjects() } void GEOObjects::addPointVec(std::vector* points, - std::string &name, + std::string& name, std::map* pnt_id_name_map, double eps) { @@ -43,139 +43,146 @@ void GEOObjects::addPointVec(std::vector* points, _pnt_vecs.push_back(new PointVec(name, points, pnt_id_name_map, PointVec::POINT, eps)); } -bool GEOObjects::appendPointVec(std::vector const& new_points, - std::string const &name, std::vector* ids) +bool GEOObjects::appendPointVec(std::vector const& new_points, std::string const& name, + std::vector* ids) { // search vector int idx = this->exists(name); - if (idx>=0) { - size_t n_new_pnts (new_points.size()); + if (idx >= 0) + { + size_t n_new_pnts(new_points.size()); // append points if (ids) for (size_t k(0); k < n_new_pnts; k++) - ids->push_back (_pnt_vecs[idx]->push_back (new_points[k])); + ids->push_back(_pnt_vecs[idx]->push_back(new_points[k])); else for (size_t k(0); k < n_new_pnts; k++) - _pnt_vecs[idx]->push_back (new_points[k]); + _pnt_vecs[idx]->push_back(new_points[k]); return true; - } else + } + else return false; } -bool GEOObjects::appendPoint(Point* point, std::string const &name, size_t& id) +bool GEOObjects::appendPoint(Point* point, std::string const& name, size_t& id) { // search vector int idx = this->exists(name); - if (idx>=0) { - const size_t size_previous (_pnt_vecs[idx]->size()); - id = _pnt_vecs[idx]->push_back (point); - if (size_previous < _pnt_vecs[idx]->size()) { + if (idx >= 0) + { + const size_t size_previous(_pnt_vecs[idx]->size()); + id = _pnt_vecs[idx]->push_back(point); + if (size_previous < _pnt_vecs[idx]->size()) + { return true; - } else { + } + else + { return false; } - } else { + } + else + { return false; } } -const std::vector* GEOObjects::getPointVec(const std::string &name) const +const std::vector* GEOObjects::getPointVec(const std::string& name) const { int idx = this->exists(name); - if (idx>=0) return _pnt_vecs[idx]->getVector(); -/* - size_t size (_pnt_vecs.size()); - for (size_t i = 0; i < size; i++) - if (_pnt_vecs[i]->getName().compare(name) == 0) - return _pnt_vecs[i]->getVector(); -*/ - std::cout << "GEOObjects::getPointVec() - No entry found with name \"" << name << "\"." << "\n"; + if (idx >= 0) + return _pnt_vecs[idx]->getVector(); + /* + size_t size (_pnt_vecs.size()); + for (size_t i = 0; i < size; i++) + if (_pnt_vecs[i]->getName().compare(name) == 0) + return _pnt_vecs[i]->getVector(); + */ + std::cout << "GEOObjects::getPointVec() - No entry found with name \"" << name << "\"." + << "\n"; return NULL; } -const PointVec* GEOObjects::getPointVecObj(const std::string &name) const +const PointVec* GEOObjects::getPointVecObj(const std::string& name) const { int idx = this->exists(name); - if (idx>=0) return _pnt_vecs[idx]; -/* - size_t size (_pnt_vecs.size()); - for (size_t i = 0; i < size; i++) - if (_pnt_vecs[i]->getName().compare(name) == 0) - return _pnt_vecs[i]; -*/ - std::cout << "GEOObjects::getPointVecObj() - No entry found with name \"" << name << "\"." << "\n"; + if (idx >= 0) + return _pnt_vecs[idx]; + /* + size_t size (_pnt_vecs.size()); + for (size_t i = 0; i < size; i++) + if (_pnt_vecs[i]->getName().compare(name) == 0) + return _pnt_vecs[i]; + */ + std::cout << "GEOObjects::getPointVecObj() - No entry found with name \"" << name << "\"." + << "\n"; return NULL; } -bool GEOObjects::removePointVec(const std::string &name) +bool GEOObjects::removePointVec(const std::string& name) { - if (isPntVecUsed (name)) + if (isPntVecUsed(name)) { - std::cout << - "GEOObjects::removePointVec() - There are still Polylines or Surfaces depending on these points." + std::cout << "GEOObjects::removePointVec() - There are still Polylines or Surfaces depending on these points." << "\n"; return false; } - for (std::vector::iterator it(_pnt_vecs.begin()); - it != _pnt_vecs.end(); it++) + for (std::vector::iterator it(_pnt_vecs.begin()); it != _pnt_vecs.end(); it++) if ((*it)->getName().compare(name) == 0) { delete *it; _pnt_vecs.erase(it); return true; } - std::cout << "GEOObjects::removePointVec() - No entry found with name \"" << name << "." << - "\n"; + std::cout << "GEOObjects::removePointVec() - No entry found with name \"" << name << "." + << "\n"; return false; } -void GEOObjects::addStationVec(std::vector* stations, std::string &name) +void GEOObjects::addStationVec(std::vector* stations, std::string& name) { isUniquePointVecName(name); _pnt_vecs.push_back(new PointVec(name, stations, NULL, PointVec::STATION)); } -std::vector* GEOObjects::filterStationVec(const std::string &name, - const std::vector &bounds) +std::vector* GEOObjects::filterStationVec(const std::string& name, const std::vector& bounds) { - for (std::vector::iterator it(_pnt_vecs.begin()); - it != _pnt_vecs.end(); it++) - if ((*it)->getName().compare(name) == 0 && (*it)->getType() - == PointVec::STATION) + for (std::vector::iterator it(_pnt_vecs.begin()); it != _pnt_vecs.end(); it++) + if ((*it)->getName().compare(name) == 0 && (*it)->getType() == PointVec::STATION) return (*it)->filterStations(bounds); - std::cout << "GEOObjects:: filterStations() - No entry found with name \"" - << name << "." << "\n"; + std::cout << "GEOObjects:: filterStations() - No entry found with name \"" << name << "." + << "\n"; return NULL; } -const std::vector* GEOObjects::getStationVec(const std::string &name) const +const std::vector* GEOObjects::getStationVec(const std::string& name) const { - for (std::vector::const_iterator it(_pnt_vecs.begin()); - it != _pnt_vecs.end(); it++) { - if ((*it)->getName().compare(name) == 0 && (*it)->getType() == PointVec::STATION) { + for (std::vector::const_iterator it(_pnt_vecs.begin()); it != _pnt_vecs.end(); it++) + { + if ((*it)->getName().compare(name) == 0 && (*it)->getType() == PointVec::STATION) + { return (*it)->getVector(); } } - std::cout << "GEOObjects::getStationVec() - No entry found with name \"" - << name << "." << "\n"; + std::cout << "GEOObjects::getStationVec() - No entry found with name \"" << name << "." + << "\n"; return NULL; } -void GEOObjects::addPolylineVec(std::vector* lines, - const std::string &name, std::map* ply_names) +void GEOObjects::addPolylineVec(std::vector* lines, const std::string& name, + std::map* ply_names) { - for (std::vector::iterator it (lines->begin()); - it != lines->end(); ) + for (std::vector::iterator it(lines->begin()); it != lines->end();) { if ((*it)->getNumberOfPoints() < 2) { - std::vector::iterator it_erase (it); - it = lines->erase (it_erase); + std::vector::iterator it_erase(it); + it = lines->erase(it_erase); } else it++; @@ -187,60 +194,59 @@ void GEOObjects::addPolylineVec(std::vector* lines, _ply_vecs.push_back(new PolylineVec(name, lines, ply_names)); } -bool GEOObjects::appendPolylineVec(const std::vector &polylines, const std::string &name) +bool GEOObjects::appendPolylineVec(const std::vector& polylines, const std::string& name) { // search vector - size_t idx (0); - bool nfound (true); + size_t idx(0); + bool nfound(true); for (idx = 0; idx < _ply_vecs.size() && nfound; idx++) - if ( (_ply_vecs[idx]->getName()).compare (name) == 0 ) + if ((_ply_vecs[idx]->getName()).compare(name) == 0) nfound = false; if (!nfound) { idx--; - size_t n_plys (polylines.size()); + size_t n_plys(polylines.size()); // append lines for (size_t k(0); k < n_plys; k++) - _ply_vecs[idx]->push_back (polylines[k]); + _ply_vecs[idx]->push_back(polylines[k]); return true; } else return false; } -const std::vector* GEOObjects::getPolylineVec(const std::string &name) const +const std::vector* GEOObjects::getPolylineVec(const std::string& name) const { - size_t size (_ply_vecs.size()); + size_t size(_ply_vecs.size()); for (size_t i = 0; i < size; i++) if (_ply_vecs[i]->getName().compare(name) == 0) return _ply_vecs[i]->getVector(); #ifndef NDEBUG - std::cout << "DEB: GEOObjects::getPolylineVec() - No entry found with name \"" << name << - "." << "\n"; + std::cout << "DEB: GEOObjects::getPolylineVec() - No entry found with name \"" << name << "." + << "\n"; #endif return NULL; } -const PolylineVec* GEOObjects::getPolylineVecObj(const std::string &name) const +const PolylineVec* GEOObjects::getPolylineVecObj(const std::string& name) const { - size_t size (_ply_vecs.size()); + size_t size(_ply_vecs.size()); for (size_t i = 0; i < size; i++) if (_ply_vecs[i]->getName().compare(name) == 0) return _ply_vecs[i]; #ifndef NDEBUG - std::cout << "DEB: GEOObjects::getPolylineVecObj() - No entry found with name \"" << name << - "\"." << "\n"; + std::cout << "DEB: GEOObjects::getPolylineVecObj() - No entry found with name \"" << name << "\"." + << "\n"; #endif return NULL; } -bool GEOObjects::removePolylineVec(const std::string &name) +bool GEOObjects::removePolylineVec(const std::string& name) { - for (std::vector::iterator it = _ply_vecs.begin(); - it != _ply_vecs.end(); ++it) + for (std::vector::iterator it = _ply_vecs.begin(); it != _ply_vecs.end(); ++it) if ((*it)->getName().compare(name) == 0) { delete *it; @@ -249,81 +255,80 @@ bool GEOObjects::removePolylineVec(const std::string &name) } #ifndef NDEBUG - std::cout << "GEOObjects::removePolylineVec() - No entry found with name \"" - << name << "\"." << "\n"; + std::cout << "GEOObjects::removePolylineVec() - No entry found with name \"" << name << "\"." + << "\n"; #endif return false; } -void GEOObjects::addSurfaceVec(std::vector* sfc, const std::string &name, +void GEOObjects::addSurfaceVec(std::vector* sfc, const std::string& name, std::map* sfc_names) { _sfc_vecs.push_back(new SurfaceVec(name, sfc, sfc_names)); } -bool GEOObjects::appendSurfaceVec(const std::vector &surfaces, const std::string &name) +bool GEOObjects::appendSurfaceVec(const std::vector& surfaces, const std::string& name) { // search vector - size_t idx (0); - bool nfound (true); + size_t idx(0); + bool nfound(true); for (idx = 0; idx < _sfc_vecs.size() && nfound; idx++) - if ( (_sfc_vecs[idx]->getName()).compare (name) == 0 ) + if ((_sfc_vecs[idx]->getName()).compare(name) == 0) nfound = false; if (!nfound) { idx--; - size_t n_sfcs (surfaces.size()); + size_t n_sfcs(surfaces.size()); // append surfaces for (size_t k(0); k < n_sfcs; k++) - _sfc_vecs[idx]->push_back (surfaces[k]); + _sfc_vecs[idx]->push_back(surfaces[k]); return true; } else return false; } -const std::vector* GEOObjects::getSurfaceVec(const std::string &name) const +const std::vector* GEOObjects::getSurfaceVec(const std::string& name) const { - size_t size (_sfc_vecs.size()); + size_t size(_sfc_vecs.size()); for (size_t i = 0; i < size; i++) if (_sfc_vecs[i]->getName().compare(name) == 0) return _sfc_vecs[i]->getVector(); - std::cout << "GEOObjects::getSurfaceVec() - No entry found with name \"" << name << "." << - "\n"; + std::cout << "GEOObjects::getSurfaceVec() - No entry found with name \"" << name << "." + << "\n"; return NULL; } -bool GEOObjects::removeSurfaceVec(const std::string &name) +bool GEOObjects::removeSurfaceVec(const std::string& name) { - for (std::vector::iterator it (_sfc_vecs.begin()); - it != _sfc_vecs.end(); it++) - if ((*it)->getName().compare (name) == 0) + for (std::vector::iterator it(_sfc_vecs.begin()); it != _sfc_vecs.end(); it++) + if ((*it)->getName().compare(name) == 0) { delete *it; - _sfc_vecs.erase (it); + _sfc_vecs.erase(it); return true; } #ifndef NDEBUG - std::cout << "GEOObjects::removeSurfaceVec() - No entry found with name \"" - << name << "\"." << "\n"; + std::cout << "GEOObjects::removeSurfaceVec() - No entry found with name \"" << name << "\"." + << "\n"; #endif return false; } -const SurfaceVec* GEOObjects::getSurfaceVecObj(const std::string &name) const +const SurfaceVec* GEOObjects::getSurfaceVecObj(const std::string& name) const { - size_t size (_sfc_vecs.size()); + size_t size(_sfc_vecs.size()); for (size_t i = 0; i < size; i++) if (_sfc_vecs[i]->getName().compare(name) == 0) return _sfc_vecs[i]; - std::cout << "GEOObjects::getSurfaceVecObj() - No entry found with name \"" << name << - "\"." << "\n"; + std::cout << "GEOObjects::getSurfaceVecObj() - No entry found with name \"" << name << "\"." + << "\n"; return NULL; } -bool GEOObjects::isUniquePointVecName(std::string &name) +bool GEOObjects::isUniquePointVecName(std::string& name) { int count = 0; bool isUnique = false; @@ -341,7 +346,7 @@ bool GEOObjects::isUniquePointVecName(std::string &name) cpName = cpName + "-" + number2str(count); for (size_t i = 0; i < _pnt_vecs.size(); i++) - if ( cpName.compare(_pnt_vecs[i]->getName()) == 0 ) + if (cpName.compare(_pnt_vecs[i]->getName()) == 0) isUnique = false; } @@ -356,18 +361,16 @@ bool GEOObjects::isUniquePointVecName(std::string &name) return isUnique; } -bool GEOObjects::isPntVecUsed (const std::string &name) const +bool GEOObjects::isPntVecUsed(const std::string& name) const { // search dependent data structures (Polyline) - for (std::vector::const_iterator it ( _ply_vecs.begin()); it != _ply_vecs.end(); - it++) + for (std::vector::const_iterator it(_ply_vecs.begin()); it != _ply_vecs.end(); it++) { std::string a = (*it)->getName(); if (((*it)->getName()).compare(name) == 0) return true; } - for (std::vector::const_iterator it ( _sfc_vecs.begin()); it != _sfc_vecs.end(); - it++) + for (std::vector::const_iterator it(_sfc_vecs.begin()); it != _sfc_vecs.end(); it++) { std::string a = (*it)->getName(); if (((*it)->getName()).compare(name) == 0) @@ -379,22 +382,21 @@ bool GEOObjects::isPntVecUsed (const std::string &name) const void GEOObjects::getStationVectorNames(std::vector& names) const { - for (std::vector::const_iterator it(_pnt_vecs.begin()); it != _pnt_vecs.end(); - it++) + for (std::vector::const_iterator it(_pnt_vecs.begin()); it != _pnt_vecs.end(); it++) if ((*it)->getType() == PointVec::STATION) names.push_back((*it)->getName()); } -void GEOObjects::getGeometryNames (std::vector& names) const +void GEOObjects::getGeometryNames(std::vector& names) const { - names.clear (); - for (std::vector::const_iterator it(_pnt_vecs.begin()); it != _pnt_vecs.end(); - it++) + names.clear(); + for (std::vector::const_iterator it(_pnt_vecs.begin()); it != _pnt_vecs.end(); it++) if ((*it)->getType() == PointVec::POINT) names.push_back((*it)->getName()); } -const std::string GEOObjects::getElementNameByID(const std::string &geometry_name, GEOLIB::GEOTYPE type, size_t id) const +const std::string GEOObjects::getElementNameByID(const std::string& geometry_name, GEOLIB::GEOTYPE type, + size_t id) const { std::string name(""); switch (type) @@ -409,84 +411,95 @@ const std::string GEOObjects::getElementNameByID(const std::string &geometry_nam this->getSurfaceVecObj(geometry_name)->getNameOfElementByID(id, name); break; default: - std::cout << "No valid GEOTYPE given." << "\n"; + std::cout << "No valid GEOTYPE given." + << "\n"; } return name; } -void GEOObjects::mergeGeometries (std::vector const & geo_names, - std::string &merged_geo_name) +void GEOObjects::mergeGeometries(std::vector const& geo_names, std::string& merged_geo_name) { const size_t n_geo_names(geo_names.size()); std::vector pnt_offsets(n_geo_names, 0); // *** merge points - std::vector* merged_points (new std::vector); - for (size_t j(0); j < n_geo_names; j++) { - const std::vector* pnts (this->getPointVec(geo_names[j])); - if (pnts) { + std::vector* merged_points(new std::vector); + for (size_t j(0); j < n_geo_names; j++) + { + const std::vector* pnts(this->getPointVec(geo_names[j])); + if (pnts) + { size_t n_pnts(0); // do not consider stations - if (dynamic_cast((*pnts)[0]) == NULL) { + if (dynamic_cast((*pnts)[0]) == NULL) + { n_pnts = pnts->size(); for (size_t k(0); k < n_pnts; k++) - merged_points->push_back (new GEOLIB::Point (((*pnts)[k])->getData())); + merged_points->push_back(new GEOLIB::Point(((*pnts)[k])->getData())); } - if (n_geo_names - 1 > j) { + if (n_geo_names - 1 > j) + { pnt_offsets[j + 1] = n_pnts + pnt_offsets[j]; } } } - addPointVec (merged_points, merged_geo_name, NULL, 1e-6); - std::vector const& id_map (this->getPointVecObj(merged_geo_name)->getIDMap ()); + addPointVec(merged_points, merged_geo_name, NULL, 1e-6); + std::vector const& id_map(this->getPointVecObj(merged_geo_name)->getIDMap()); // *** merge polylines - std::vector* merged_polylines (new std::vector); - for (size_t j(0); j < n_geo_names; j++) { - const std::vector* plys (this->getPolylineVec(geo_names[j])); - if (plys) { - for (size_t k(0); k < plys->size(); k++) { - GEOLIB::Polyline* kth_ply_new(new GEOLIB::Polyline (*merged_points)); - GEOLIB::Polyline const* const kth_ply_old ((*plys)[k]); - const size_t size_of_kth_ply (kth_ply_old->getNumberOfPoints()); + std::vector* merged_polylines(new std::vector); + for (size_t j(0); j < n_geo_names; j++) + { + const std::vector* plys(this->getPolylineVec(geo_names[j])); + if (plys) + { + for (size_t k(0); k < plys->size(); k++) + { + GEOLIB::Polyline* kth_ply_new(new GEOLIB::Polyline(*merged_points)); + GEOLIB::Polyline const* const kth_ply_old((*plys)[k]); + const size_t size_of_kth_ply(kth_ply_old->getNumberOfPoints()); // copy point ids from old ply to new ply (considering the offset) - for (size_t i(0); i < size_of_kth_ply; i++) { - kth_ply_new->addPoint (id_map[pnt_offsets[j] + - kth_ply_old->getPointID(i)]); + for (size_t i(0); i < size_of_kth_ply; i++) + { + kth_ply_new->addPoint(id_map[pnt_offsets[j] + kth_ply_old->getPointID(i)]); } - merged_polylines->push_back (kth_ply_new); + merged_polylines->push_back(kth_ply_new); } } } - this->addPolylineVec (merged_polylines, merged_geo_name); + this->addPolylineVec(merged_polylines, merged_geo_name); // *** merge surfaces - std::vector* merged_sfcs (new std::vector); - for (size_t j(0); j < n_geo_names; j++) { - const std::vector* sfcs (this->getSurfaceVec(geo_names[j])); - if (sfcs) { - for (size_t k(0); k < sfcs->size(); k++) { - GEOLIB::Surface* kth_sfc_new(new GEOLIB::Surface (*merged_points)); - GEOLIB::Surface const* const kth_sfc_old ((*sfcs)[k]); - const size_t size_of_kth_sfc (kth_sfc_old->getNTriangles()); + std::vector* merged_sfcs(new std::vector); + for (size_t j(0); j < n_geo_names; j++) + { + const std::vector* sfcs(this->getSurfaceVec(geo_names[j])); + if (sfcs) + { + for (size_t k(0); k < sfcs->size(); k++) + { + GEOLIB::Surface* kth_sfc_new(new GEOLIB::Surface(*merged_points)); + GEOLIB::Surface const* const kth_sfc_old((*sfcs)[k]); + const size_t size_of_kth_sfc(kth_sfc_old->getNTriangles()); // copy point ids from old ply to new ply (considering the offset) - for (size_t i(0); i < size_of_kth_sfc; i++) { - const GEOLIB::Triangle* tri ((*kth_sfc_old)[i]); - const size_t id0 (id_map[pnt_offsets[j] + (*tri)[0]]); - const size_t id1 (id_map[pnt_offsets[j] + (*tri)[1]]); - const size_t id2 (id_map[pnt_offsets[j] + (*tri)[2]]); - kth_sfc_new->addTriangle (id0, id1, id2); + for (size_t i(0); i < size_of_kth_sfc; i++) + { + const GEOLIB::Triangle* tri((*kth_sfc_old)[i]); + const size_t id0(id_map[pnt_offsets[j] + (*tri)[0]]); + const size_t id1(id_map[pnt_offsets[j] + (*tri)[1]]); + const size_t id2(id_map[pnt_offsets[j] + (*tri)[2]]); + kth_sfc_new->addTriangle(id0, id1, id2); } - merged_sfcs->push_back (kth_sfc_new); + merged_sfcs->push_back(kth_sfc_new); } } } - this->addSurfaceVec (merged_sfcs, merged_geo_name); + this->addSurfaceVec(merged_sfcs, merged_geo_name); } -const GEOLIB::GeoObject* GEOObjects::getGEOObject(const std::string &geo_name, - GEOLIB::GEOTYPE type, - const std::string &obj_name) const +const GEOLIB::GeoObject* GEOObjects::getGEOObject(const std::string& geo_name, + GEOLIB::GEOTYPE type, + const std::string& obj_name) const { if (type == GEOLIB::POINT) return this->getPointVecObj(geo_name)->getElementByName(obj_name); @@ -497,19 +510,18 @@ const GEOLIB::GeoObject* GEOObjects::getGEOObject(const std::string &geo_name, return NULL; } -int GEOObjects::exists(const std::string &geometry_name) const +int GEOObjects::exists(const std::string& geometry_name) const { - size_t size (_pnt_vecs.size()); + size_t size(_pnt_vecs.size()); for (size_t i = 0; i < size; i++) if (_pnt_vecs[i]->getName().compare(geometry_name) == 0) return i; // HACK for enabling conversion of files without loading the associated geometry - if (size>0 && _pnt_vecs[0]->getName().compare("conversionTestRun#1")==0) + if (size > 0 && _pnt_vecs[0]->getName().compare("conversionTestRun#1") == 0) return 1; return -1; } - } // namespace diff --git a/GEO/GEOObjects.h b/GEO/GEOObjects.h index 23c472e82..2064eeec6 100644 --- a/GEO/GEOObjects.h +++ b/GEO/GEOObjects.h @@ -70,7 +70,7 @@ class GEOObjects * @param eps relative tolerance value for testing of point uniqueness */ virtual void addPointVec(std::vector* points, - std::string &name, + std::string& name, std::map* pnt_names = NULL, double eps = sqrt(std::numeric_limits::min())); @@ -84,8 +84,8 @@ class GEOObjects * \return true if the points are appended, false if the a PointVec with the * corresponding name does not exist * */ - virtual bool appendPointVec(const std::vector &points, - std::string const &name, std::vector* ids = NULL); + virtual bool appendPointVec(const std::vector& points, std::string const& name, + std::vector* ids = NULL); /** * Method appends the point the the PointVec object with the name name. The PointVec @@ -97,49 +97,43 @@ class GEOObjects * @return true, if the point could be inserted (i.e. was not already contained in the vector) * else false (the user have to delete the point itself) */ - bool appendPoint(Point* point, std::string const &name, size_t& id); + bool appendPoint(Point* point, std::string const& name, size_t& id); /** * Returns the point vector with the given name. */ - const std::vector* getPointVec(const std::string &name) const; + const std::vector* getPointVec(const std::string& name) const; /** * search and returns the PointVec object with the given name. * @param name the name of the PointVec object * @return the PointVec object stored in GEOObjects */ - const PointVec* getPointVecObj(const std::string &name) const; + const PointVec* getPointVecObj(const std::string& name) const; /// Returns a pointer to a PointVec object for the given name. - PointVec* getPointVecObj(const std::string &name) + PointVec* getPointVecObj(const std::string& name) { - return const_cast(static_cast(*this). - getPointVecObj(name)); + return const_cast(static_cast(*this).getPointVecObj(name)); } /** If there exists no dependencies the point vector with the given * name from GEOObjects will be removed and the method returns true, * else the return value is false. */ - virtual bool removePointVec(const std::string &name); + virtual bool removePointVec(const std::string& name); /// Adds a vector of stations with the given name and colour to GEOObjects. - virtual void addStationVec(std::vector* stations, std::string &name); + virtual void addStationVec(std::vector* stations, std::string& name); /// Filters a list of stations with the given name based on the criteria in PropertyBounds. /// (See property system in Station class for more information.) - std::vector* filterStationVec(const std::string &name, - const std::vector &bounds); + std::vector* filterStationVec(const std::string& name, const std::vector& bounds); /// Returns the station vector with the given name. - const std::vector* getStationVec(const std::string &name) const; + const std::vector* getStationVec(const std::string& name) const; /// Removes the station vector with the given name from GEOObjects - virtual bool removeStationVec(const std::string &name) - { - return removePointVec(name); - } - + virtual bool removeStationVec(const std::string& name) { return removePointVec(name); } /** * Adds a vector of polylines with the given name to GEOObjects. * @param lines The lines vector. @@ -147,8 +141,8 @@ class GEOObjects * @param ply_names vector of the names corresponding to the polylines */ virtual void addPolylineVec(std::vector* lines, - const std::string &name, - std::map* ply_names = NULL); + const std::string& name, + std::map* ply_names = NULL); /** copies the pointers to the polylines in the vector to the PolylineVec with provided name. * the pointers are managed by the GEOObjects, i.e. GEOObjects will delete the Polylines at the @@ -158,26 +152,24 @@ class GEOObjects * \return true if the polylines are appended, false if the PolylineVec with the * corresponding name does not exist * */ - virtual bool appendPolylineVec(const std::vector &polylines, - const std::string &name); + virtual bool appendPolylineVec(const std::vector& polylines, const std::string& name); /** * Returns the polyline vector with the given name. * */ - const std::vector* getPolylineVec(const std::string &name) const; + const std::vector* getPolylineVec(const std::string& name) const; /** * Returns a pointer to a PolylineVec object for the given name as a const. * @param name the name of the vector of polylines * @return PolylineVec object */ - const PolylineVec* getPolylineVecObj(const std::string &name) const; + const PolylineVec* getPolylineVecObj(const std::string& name) const; /// Returns a pointer to a PolylineVec object for the given name. - PolylineVec* getPolylineVecObj(const std::string &name) + PolylineVec* getPolylineVecObj(const std::string& name) { - return const_cast(static_cast(*this). - getPolylineVecObj(name)); + return const_cast(static_cast(*this).getPolylineVecObj(name)); } /** @@ -185,11 +177,11 @@ class GEOObjects * name it will be removed and the method returns true, * else the return value is false. */ - virtual bool removePolylineVec(const std::string &name); + virtual bool removePolylineVec(const std::string& name); /** Adds a vector of surfaces with the given name to GEOObjects. */ virtual void addSurfaceVec(std::vector* surfaces, - const std::string &name, + const std::string& name, std::map* sfc_names = NULL); /** @@ -199,36 +191,34 @@ class GEOObjects * \return true if the surfaces are appended, false if the SurfaceVec with the * corresponding name does not exist * */ - virtual bool appendSurfaceVec(const std::vector &surfaces, - const std::string &name); + virtual bool appendSurfaceVec(const std::vector& surfaces, const std::string& name); /// Returns the surface vector with the given name as a const. - const std::vector* getSurfaceVec(const std::string &name) const; + const std::vector* getSurfaceVec(const std::string& name) const; /// Returns the surface vector with the given name. - SurfaceVec* getSurfaceVecObj(const std::string &name) + SurfaceVec* getSurfaceVecObj(const std::string& name) { - return const_cast(static_cast(*this). - getSurfaceVecObj(name)); + return const_cast(static_cast(*this).getSurfaceVecObj(name)); } /** removes the vector of Surfaces with the given name */ - virtual bool removeSurfaceVec(const std::string &name); + virtual bool removeSurfaceVec(const std::string& name); /** * Returns a pointer to a SurfaceVec object for the given name. The class * SurfaceVec stores the relation between surfaces and the names of the surfaces. * @param name the name of the vector of surfaces (the project name) * @return SurfaceVec object */ - const SurfaceVec* getSurfaceVecObj(const std::string &name) const; + const SurfaceVec* getSurfaceVecObj(const std::string& name) const; /// Returns -1 if no geometry of the given name exists or die index of the geometry in _pnt_vecs otherwise - int exists(const std::string &geometry_name) const; + int exists(const std::string& geometry_name) const; /// Returns the names of all geometry vectors. - void getGeometryNames (std::vector& names) const; + void getGeometryNames(std::vector& names) const; - const std::string getElementNameByID(const std::string &geometry_name, GEOLIB::GEOTYPE type, size_t id) const; + const std::string getElementNameByID(const std::string& geometry_name, GEOLIB::GEOTYPE type, size_t id) const; /// Returns the names of all station vectors. void getStationVectorNames(std::vector& names) const; @@ -239,12 +229,12 @@ class GEOObjects * @param names the names of the geometries that are to be merged * @param merged_geo_name the name of the resulting geometry */ - void mergeGeometries(std::vector const & names, std::string &merged_geo_name); + void mergeGeometries(std::vector const& names, std::string& merged_geo_name); /// Returns the geo object for a geometric item of the given name and type for the associated geometry. - const GEOLIB::GeoObject* getGEOObject(const std::string &geo_name, + const GEOLIB::GeoObject* getGEOObject(const std::string& geo_name, GEOLIB::GEOTYPE type, - const std::string &obj_name) const; + const std::string& obj_name) const; /** constructor */ GEOObjects(); @@ -259,10 +249,10 @@ class GEOObjects * \param name Original name of the list, this name might be changed within this method if necessary. * \return true if the name was unique, false if a new name has been generated */ - bool isUniquePointVecName(std::string &name); + bool isUniquePointVecName(std::string& name); /// Checks if the point vector with the given name is referenced in a polyline- or surface vector. - bool isPntVecUsed (const std::string &name) const; + bool isPntVecUsed(const std::string& name) const; /** * vector manages pointers to PointVec objects diff --git a/GEO/GeoType.cpp b/GEO/GeoType.cpp index 2ab229fb6..7f14a05bd 100644 --- a/GEO/GeoType.cpp +++ b/GEO/GeoType.cpp @@ -14,24 +14,24 @@ namespace GEOLIB { -GEOTYPE convertGeoType (const std::string& geo_type_str) +GEOTYPE convertGeoType(const std::string& geo_type_str) { - if (geo_type_str.compare ("POINT") == 0) + if (geo_type_str.compare("POINT") == 0) return POINT; - if (geo_type_str.compare ("POLYLINE") == 0) + if (geo_type_str.compare("POLYLINE") == 0) return POLYLINE; - if (geo_type_str.compare ("SURFACE") == 0) + if (geo_type_str.compare("SURFACE") == 0) return SURFACE; - if (geo_type_str.compare ("VOLUME") == 0) + if (geo_type_str.compare("VOLUME") == 0) return VOLUME; - if (geo_type_str.compare ("DOMAIN") == 0) + if (geo_type_str.compare("DOMAIN") == 0) return GEODOMAIN; - if (geo_type_str.compare ("GEODOMAIN") == 0) + if (geo_type_str.compare("GEODOMAIN") == 0) return GEODOMAIN; return INVALID; } -std::string convertGeoTypeToString (GEOTYPE geo_type) +std::string convertGeoTypeToString(GEOTYPE geo_type) { if (geo_type == POINT) return "POINT"; diff --git a/GEO/GeoType.h b/GEO/GeoType.h index 80535ea8f..1051a2ba7 100644 --- a/GEO/GeoType.h +++ b/GEO/GeoType.h @@ -21,7 +21,8 @@ namespace GEOLIB * \ingroup GEOLIB */ -enum GEOTYPE { +enum GEOTYPE +{ INVALID = 0, POINT, //!< POINT POLYLINE, //!< POLYLINE @@ -30,9 +31,9 @@ enum GEOTYPE { GEODOMAIN //!< GEODOMAIN }; -GEOTYPE convertGeoType (const std::string& geo_type_str); +GEOTYPE convertGeoType(const std::string& geo_type_str); -std::string convertGeoTypeToString (GEOTYPE geo_type); +std::string convertGeoTypeToString(GEOTYPE geo_type); } // end namespace GEOLIB #endif /* GEOTYPE_H_ */ diff --git a/GEO/Grid.h b/GEO/Grid.h index aeb43b17b..ecc900ad1 100644 --- a/GEO/Grid.h +++ b/GEO/Grid.h @@ -23,8 +23,8 @@ #include "StringTools.h" #endif -namespace GEOLIB { - +namespace GEOLIB +{ template class Grid : public GEOLIB::AABB { @@ -48,11 +48,7 @@ class Grid : public GEOLIB::AABB * This is the destructor of the class. It deletes the internal data structures *not* * including the pointers to the points. */ - virtual ~Grid() - { - delete [] _grid_quad_to_node_map; - } - + virtual ~Grid() { delete[] _grid_quad_to_node_map; } /** * The method calculates the grid cell within the grid to given point is belonging to, i.e., * the (internal) coordinates of the grid are computed. The method searches the actual @@ -65,7 +61,7 @@ class Grid : public GEOLIB::AABB * @param pnt a field that holds the coordinates of the point * @return a point with the smallest distance within the grid cells that are outlined above or NULL */ - POINT const* getNearestPoint(double const*const pnt) const; + POINT const* getNearestPoint(double const* const pnt) const; /** * Method fetchs all points that are located within grid cells that intersects @@ -76,7 +72,7 @@ class Grid : public GEOLIB::AABB * @param pnts (output) all points within grid cells that intersects * the axis aligned cube */ - void getPointsWithinCube(double const*const pnt, double half_len, std::vector& pnts) const; + void getPointsWithinCube(double const* const pnt, double half_len, std::vector& pnts) const; #ifndef NDEBUG /** @@ -95,7 +91,7 @@ class Grid : public GEOLIB::AABB * @param pnt (input) the coordinates of the point * @param coords (output) the coordinates of the grid cell */ - inline void getGridCoords(double const*const pnt, size_t* coords) const; + inline void getGridCoords(double const* const pnt, size_t* coords) const; /** * @@ -125,33 +121,35 @@ class Grid : public GEOLIB::AABB * ordered in the same sequence as above described * @param coords coordinates of the grid cell */ - void getPointCellBorderDistances(double const*const pnt, double dists[6], size_t const* const coords) const; + void getPointCellBorderDistances(double const* const pnt, double dists[6], size_t const* const coords) const; - bool calcNearestPointInGridCell(double const* const pnt, size_t const* const coords, - double &sqr_min_dist, POINT* &nearest_pnt) const; + bool calcNearestPointInGridCell(double const* const pnt, size_t const* const coords, double& sqr_min_dist, + POINT*& nearest_pnt) const; double _step_sizes[3]; double _inverse_step_sizes[3]; size_t _n_steps[3]; std::vector* _grid_quad_to_node_map; }; - template -Grid::Grid(std::vector const& pnts, size_t max_num_per_grid_cell) : - GEOLIB::AABB(), _grid_quad_to_node_map(NULL) +Grid::Grid(std::vector const& pnts, size_t max_num_per_grid_cell) + : GEOLIB::AABB(), _grid_quad_to_node_map(NULL) { // compute axis aligned bounding box const size_t n_pnts(pnts.size()); - for (size_t k(0); k < n_pnts; k++) { + for (size_t k(0); k < n_pnts; k++) + { this->update(pnts[k]->getData()); } - double delta[3] = { 0.0, 0.0, 0.0 }; - for (size_t k(0); k < 3; k++) { + double delta[3] = {0.0, 0.0, 0.0}; + for (size_t k(0); k < 3; k++) + { // make the bounding box a little bit bigger, // such that the node with maximal coordinates fits into the grid _max_pnt[k] += std::abs(_max_pnt[k]) * 1e-6; - if (fabs(_max_pnt[k]) < std::numeric_limits::epsilon()) { + if (fabs(_max_pnt[k]) < std::numeric_limits::epsilon()) + { _max_pnt[k] = (_max_pnt[k] - _min_pnt[k]) * (1.0 + 1e-6); } delta[k] = _max_pnt[k] - _min_pnt[k]; @@ -159,71 +157,92 @@ Grid::Grid(std::vector const& pnts, size_t max_num_per_grid_cell) // *** condition: n_pnts / (_n_steps[0] * _n_steps[1] * _n_steps[2]) < max_num_per_grid_cell // *** with _n_steps[1] = _n_steps[0] * delta[1]/delta[0], _n_steps[2] = _n_steps[0] * delta[2]/delta[0] - if (fabs(delta[1]) < std::numeric_limits::epsilon() || - fabs(delta[2]) < std::numeric_limits::epsilon()) { + if (fabs(delta[1]) < std::numeric_limits::epsilon() + || fabs(delta[2]) < std::numeric_limits::epsilon()) + { // 1d case y = z = 0 - if (fabs(delta[1]) < std::numeric_limits::epsilon() && - fabs(delta[2]) < std::numeric_limits::epsilon()) { - _n_steps[0] = static_cast (ceil(n_pnts / (double) max_num_per_grid_cell)); + if (fabs(delta[1]) < std::numeric_limits::epsilon() + && fabs(delta[2]) < std::numeric_limits::epsilon()) + { + _n_steps[0] = static_cast(ceil(n_pnts / (double)max_num_per_grid_cell)); _n_steps[1] = 1; _n_steps[2] = 1; - } else { + } + else + { // 1d case x = z = 0 - if (fabs(delta[0]) < std::numeric_limits::epsilon() && - fabs(delta[2]) < std::numeric_limits::epsilon()) { + if (fabs(delta[0]) < std::numeric_limits::epsilon() + && fabs(delta[2]) < std::numeric_limits::epsilon()) + { _n_steps[0] = 1; - _n_steps[1] = static_cast (ceil(n_pnts / (double) max_num_per_grid_cell)); + _n_steps[1] = static_cast(ceil(n_pnts / (double)max_num_per_grid_cell)); _n_steps[2] = 1; - } else { + } + else + { // 1d case x = y = 0 - if (fabs(delta[0]) < std::numeric_limits::epsilon() && fabs(delta[1]) - < std::numeric_limits::epsilon()) { + if (fabs(delta[0]) < std::numeric_limits::epsilon() + && fabs(delta[1]) < std::numeric_limits::epsilon()) + { _n_steps[0] = 1; _n_steps[1] = 1; - _n_steps[2] = static_cast (ceil(n_pnts / (double) max_num_per_grid_cell)); - } else { + _n_steps[2] = static_cast(ceil(n_pnts / (double)max_num_per_grid_cell)); + } + else + { // 2d case - if (fabs(delta[1]) < std::numeric_limits::epsilon()) { - _n_steps[0] = static_cast (ceil(sqrt(n_pnts * delta[0] / (max_num_per_grid_cell * delta[2])))); + if (fabs(delta[1]) < std::numeric_limits::epsilon()) + { + _n_steps[0] + = static_cast(ceil(sqrt(n_pnts * delta[0] / (max_num_per_grid_cell * delta[2])))); _n_steps[1] = 1; - _n_steps[2] = static_cast (ceil(_n_steps[0] * delta[2] / delta[0])); - } else { - _n_steps[0] = static_cast (ceil(sqrt(n_pnts * delta[0] / (max_num_per_grid_cell * delta[1])))); - _n_steps[1] = static_cast (ceil(_n_steps[0] * delta[1] / delta[0])); + _n_steps[2] = static_cast(ceil(_n_steps[0] * delta[2] / delta[0])); + } + else + { + _n_steps[0] + = static_cast(ceil(sqrt(n_pnts * delta[0] / (max_num_per_grid_cell * delta[1])))); + _n_steps[1] = static_cast(ceil(_n_steps[0] * delta[1] / delta[0])); _n_steps[2] = 1; } } } } - } else { + } + else + { // 3d case - _n_steps[0] = static_cast (ceil(pow(n_pnts * delta[0] * delta[0] - / (max_num_per_grid_cell * delta[1] * delta[2]), 1. / 3.))); - _n_steps[1] = static_cast (ceil(_n_steps[0] * delta[1] / delta[0])); - _n_steps[2] = static_cast (ceil(_n_steps[0] * delta[2] / delta[0])); + _n_steps[0] = static_cast( + ceil(pow(n_pnts * delta[0] * delta[0] / (max_num_per_grid_cell * delta[1] * delta[2]), 1. / 3.))); + _n_steps[1] = static_cast(ceil(_n_steps[0] * delta[1] / delta[0])); + _n_steps[2] = static_cast(ceil(_n_steps[0] * delta[2] / delta[0])); } const size_t n_plane(_n_steps[0] * _n_steps[1]); _grid_quad_to_node_map = new std::vector[n_plane * _n_steps[2]]; // some frequently used expressions to fill the grid vectors - for (size_t k(0); k < 3; k++) { + for (size_t k(0); k < 3; k++) + { _step_sizes[k] = delta[k] / _n_steps[k]; - if (_step_sizes[k]==0) + if (_step_sizes[k] == 0) _inverse_step_sizes[k] = 1.0; else _inverse_step_sizes[k] = 1.0 / _step_sizes[k]; } // fill the grid vectors - for (size_t l(0); l < n_pnts; l++) { + for (size_t l(0); l < n_pnts; l++) + { double const* const pnt(pnts[l]->getData()); - const size_t i(static_cast ((pnt[0] - _min_pnt[0]) * _inverse_step_sizes[0])); - const size_t j(static_cast ((pnt[1] - _min_pnt[1]) * _inverse_step_sizes[1])); - const size_t k(static_cast ((pnt[2] - _min_pnt[2]) * _inverse_step_sizes[2])); - - if (i >= _n_steps[0] || j >= _n_steps[1] || k >= _n_steps[2]) { - std::cout << "error computing indices " << "\n"; + const size_t i(static_cast((pnt[0] - _min_pnt[0]) * _inverse_step_sizes[0])); + const size_t j(static_cast((pnt[1] - _min_pnt[1]) * _inverse_step_sizes[1])); + const size_t k(static_cast((pnt[2] - _min_pnt[2]) * _inverse_step_sizes[2])); + + if (i >= _n_steps[0] || j >= _n_steps[1] || k >= _n_steps[2]) + { + std::cout << "error computing indices " + << "\n"; } _grid_quad_to_node_map[i + j * _n_steps[0] + k * n_plane].push_back(pnts[l]); @@ -234,71 +253,83 @@ Grid::Grid(std::vector const& pnts, size_t max_num_per_grid_cell) for (size_t k(0); k < n_plane * _n_steps[2]; k++) pnts_cnt += _grid_quad_to_node_map[k].size(); - assert(n_pnts==pnts_cnt); + assert(n_pnts == pnts_cnt); #endif } template -POINT const* Grid::getNearestPoint(double const*const pnt) const +POINT const* Grid::getNearestPoint(double const* const pnt) const { size_t coords[3]; getGridCoords(pnt, coords); - double sqr_min_dist (MathLib::sqrDist(&_min_pnt, &_max_pnt)); + double sqr_min_dist(MathLib::sqrDist(&_min_pnt, &_max_pnt)); POINT* nearest_pnt(NULL); double dists[6]; getPointCellBorderDistances(pnt, dists, coords); - if (calcNearestPointInGridCell(pnt, coords, sqr_min_dist, nearest_pnt)) { + if (calcNearestPointInGridCell(pnt, coords, sqr_min_dist, nearest_pnt)) + { double min_dist(sqrt(sqr_min_dist)); - if (dists[0] >= min_dist - && dists[1] >= min_dist - && dists[2] >= min_dist - && dists[3] >= min_dist - && dists[4] >= min_dist - && dists[5] >= min_dist) { + if (dists[0] >= min_dist && dists[1] >= min_dist && dists[2] >= min_dist && dists[3] >= min_dist + && dists[4] >= min_dist + && dists[5] >= min_dist) + { return nearest_pnt; } - } else { + } + else + { // search in all border cells for at least one neighbor double sqr_min_dist_tmp; POINT* nearest_pnt_tmp(NULL); size_t offset(1); - while (nearest_pnt == NULL) { + while (nearest_pnt == NULL) + { size_t tmp_coords[3]; - for (tmp_coords[0] = coords[0]-offset; tmp_coords[0]getData()))); + double len(sqrt(MathLib::sqrDist(pnt, nearest_pnt->getData()))); // search all other grid cells within the cube with the edge nodes std::vector pnts; getPointsWithinCube(pnt, len, pnts); const size_t n_pnts(pnts.size()); - for (size_t k(0); kgetData())); - if (sqr_dist < sqr_min_dist) { + for (size_t k(0); k < n_pnts; k++) + { + const double sqr_dist(MathLib::sqrDist(pnt, pnts[k]->getData())); + if (sqr_dist < sqr_min_dist) + { sqr_min_dist = sqr_dist; nearest_pnt = pnts[k]; } @@ -308,26 +339,31 @@ POINT const* Grid::getNearestPoint(double const*const pnt) const } template -void Grid::getPointsWithinCube(double const*const pnt, double half_len, std::vector& pnts) const +void Grid::getPointsWithinCube(double const* const pnt, double half_len, std::vector& pnts) const { - double tmp_pnt[3] = {pnt[0]-half_len, pnt[1]-half_len, pnt[2]-half_len}; // min + double tmp_pnt[3] = {pnt[0] - half_len, pnt[1] - half_len, pnt[2] - half_len}; // min size_t min_coords[3]; getGridCoords(tmp_pnt, min_coords); - tmp_pnt[0] = pnt[0]+half_len; - tmp_pnt[1] = pnt[1]+half_len; - tmp_pnt[2] = pnt[2]+half_len; + tmp_pnt[0] = pnt[0] + half_len; + tmp_pnt[1] = pnt[1] + half_len; + tmp_pnt[2] = pnt[2] + half_len; size_t max_coords[3]; getGridCoords(tmp_pnt, max_coords); size_t coords[3], steps0_x_steps1(_n_steps[0] * _n_steps[1]); - for (coords[0] = min_coords[0]; coords[0] < max_coords[0]+1; coords[0]++) { - for (coords[1] = min_coords[1]; coords[1] < max_coords[1]+1; coords[1]++) { - const size_t coords0_p_coords1_x_steps0 (coords[0] + coords[1] * _n_steps[0]); - for (coords[2] = min_coords[2]; coords[2] < max_coords[2]+1; coords[2]++) { + for (coords[0] = min_coords[0]; coords[0] < max_coords[0] + 1; coords[0]++) + { + for (coords[1] = min_coords[1]; coords[1] < max_coords[1] + 1; coords[1]++) + { + const size_t coords0_p_coords1_x_steps0(coords[0] + coords[1] * _n_steps[0]); + for (coords[2] = min_coords[2]; coords[2] < max_coords[2] + 1; coords[2]++) + { // copy pnts - const size_t n_pnts(_grid_quad_to_node_map[coords0_p_coords1_x_steps0 + coords[2] * steps0_x_steps1].size()); - for (size_t k(0); k::createGridGeometry(GEOLIB::GEOObjects* geo_obj) const { std::vector grid_names; - GEOLIB::Point const& llf (getMinPoint()); - GEOLIB::Point const& urb (getMaxPoint()); + GEOLIB::Point const& llf(getMinPoint()); + GEOLIB::Point const& urb(getMaxPoint()); - const double dx ((urb[0]-llf[0])/_n_steps[0]); - const double dy ((urb[1]-llf[1])/_n_steps[1]); - const double dz ((urb[2]-llf[2])/_n_steps[2]); + const double dx((urb[0] - llf[0]) / _n_steps[0]); + const double dy((urb[1] - llf[1]) / _n_steps[1]); + const double dz((urb[2] - llf[2]) / _n_steps[2]); // create grid names and grid boxes as geometry - for (size_t i(0); i<_n_steps[0]; i++) { - for (size_t j(0); j<_n_steps[1]; j++) { - for (size_t k(0); k<_n_steps[2]; k++) { - + for (size_t i(0); i < _n_steps[0]; i++) + { + for (size_t j(0); j < _n_steps[1]; j++) + { + for (size_t k(0); k < _n_steps[2]; k++) + { std::string name("Grid-"); name += number2str(i); - name +="-"; + name += "-"; name += number2str(j); name += "-"; - name += number2str (k); + name += number2str(k); grid_names.push_back(name); - std::vector* points (new std::vector); - points->push_back(new GEOLIB::Point(llf[0]+i*dx, llf[1]+j*dy, llf[2]+k*dz)); - points->push_back(new GEOLIB::Point(llf[0]+i*dx, llf[1]+(j+1)*dy, llf[2]+k*dz)); - points->push_back(new GEOLIB::Point(llf[0]+(i+1)*dx, llf[1]+(j+1)*dy, llf[2]+k*dz)); - points->push_back(new GEOLIB::Point(llf[0]+(i+1)*dx, llf[1]+j*dy, llf[2]+k*dz)); - points->push_back(new GEOLIB::Point(llf[0]+i*dx, llf[1]+j*dy, llf[2]+(k+1)*dz)); - points->push_back(new GEOLIB::Point(llf[0]+i*dx, llf[1]+(j+1)*dy, llf[2]+(k+1)*dz)); - points->push_back(new GEOLIB::Point(llf[0]+(i+1)*dx, llf[1]+(j+1)*dy, llf[2]+(k+1)*dz)); - points->push_back(new GEOLIB::Point(llf[0]+(i+1)*dx, llf[1]+j*dy, llf[2]+(k+1)*dz)); - geo_obj->addPointVec(points, grid_names[grid_names.size()-1], NULL); - - std::vector* plys (new std::vector); - GEOLIB::Polyline* ply0 (new GEOLIB::Polyline(*points)); - for (size_t l(0); l<4; l++) { + std::vector* points(new std::vector); + points->push_back(new GEOLIB::Point(llf[0] + i * dx, llf[1] + j * dy, llf[2] + k * dz)); + points->push_back(new GEOLIB::Point(llf[0] + i * dx, llf[1] + (j + 1) * dy, llf[2] + k * dz)); + points->push_back(new GEOLIB::Point(llf[0] + (i + 1) * dx, llf[1] + (j + 1) * dy, llf[2] + k * dz)); + points->push_back(new GEOLIB::Point(llf[0] + (i + 1) * dx, llf[1] + j * dy, llf[2] + k * dz)); + points->push_back(new GEOLIB::Point(llf[0] + i * dx, llf[1] + j * dy, llf[2] + (k + 1) * dz)); + points->push_back(new GEOLIB::Point(llf[0] + i * dx, llf[1] + (j + 1) * dy, llf[2] + (k + 1) * dz)); + points->push_back( + new GEOLIB::Point(llf[0] + (i + 1) * dx, llf[1] + (j + 1) * dy, llf[2] + (k + 1) * dz)); + points->push_back(new GEOLIB::Point(llf[0] + (i + 1) * dx, llf[1] + j * dy, llf[2] + (k + 1) * dz)); + geo_obj->addPointVec(points, grid_names[grid_names.size() - 1], NULL); + + std::vector* plys(new std::vector); + GEOLIB::Polyline* ply0(new GEOLIB::Polyline(*points)); + for (size_t l(0); l < 4; l++) + { ply0->addPoint(l); } ply0->addPoint(0); plys->push_back(ply0); - GEOLIB::Polyline* ply1 (new GEOLIB::Polyline(*points)); - for (size_t l(4); l<8; l++) { + GEOLIB::Polyline* ply1(new GEOLIB::Polyline(*points)); + for (size_t l(4); l < 8; l++) + { ply1->addPoint(l); } ply1->addPoint(4); plys->push_back(ply1); - GEOLIB::Polyline* ply2 (new GEOLIB::Polyline(*points)); + GEOLIB::Polyline* ply2(new GEOLIB::Polyline(*points)); ply2->addPoint(0); ply2->addPoint(4); plys->push_back(ply2); - GEOLIB::Polyline* ply3 (new GEOLIB::Polyline(*points)); + GEOLIB::Polyline* ply3(new GEOLIB::Polyline(*points)); ply3->addPoint(1); ply3->addPoint(5); plys->push_back(ply3); - GEOLIB::Polyline* ply4 (new GEOLIB::Polyline(*points)); + GEOLIB::Polyline* ply4(new GEOLIB::Polyline(*points)); ply4->addPoint(2); ply4->addPoint(6); plys->push_back(ply4); - GEOLIB::Polyline* ply5 (new GEOLIB::Polyline(*points)); + GEOLIB::Polyline* ply5(new GEOLIB::Polyline(*points)); ply5->addPoint(3); ply5->addPoint(7); plys->push_back(ply5); - geo_obj->addPolylineVec(plys, grid_names[grid_names.size()-1], NULL); + geo_obj->addPolylineVec(plys, grid_names[grid_names.size() - 1], NULL); } } } @@ -418,35 +459,45 @@ void Grid::createGridGeometry(GEOLIB::GEOObjects* geo_obj) const #endif template -void Grid::getGridCoords(double const*const pnt, size_t* coords) const +void Grid::getGridCoords(double const* const pnt, size_t* coords) const { - for (size_t k(0); k<3; k++) { - if (pnt[k] < _min_pnt[k]) { + for (size_t k(0); k < 3; k++) + { + if (pnt[k] < _min_pnt[k]) + { coords[k] = 0; - } else { - if (pnt[k] > _max_pnt[k]) { - coords[k] = _n_steps[k]-1; - } else { - coords[k] = static_cast((pnt[k]-_min_pnt[k]) * _inverse_step_sizes[k]); + } + else + { + if (pnt[k] > _max_pnt[k]) + { + coords[k] = _n_steps[k] - 1; + } + else + { + coords[k] = static_cast((pnt[k] - _min_pnt[k]) * _inverse_step_sizes[k]); } } } } template -bool Grid::calcNearestPointInGridCell(double const* const pnt, size_t const* const coords, - double &sqr_min_dist, POINT*& nearest_pnt) const +bool Grid::calcNearestPointInGridCell(double const* const pnt, size_t const* const coords, double& sqr_min_dist, + POINT*& nearest_pnt) const { - const size_t grid_idx (coords[0] + coords[1] * _n_steps[0] + coords[2] * _n_steps[0] * _n_steps[1]); + const size_t grid_idx(coords[0] + coords[1] * _n_steps[0] + coords[2] * _n_steps[0] * _n_steps[1]); std::vector const& pnts(_grid_quad_to_node_map[grid_idx]); - if (pnts.empty()) return false; + if (pnts.empty()) + return false; const size_t n_pnts(pnts.size()); sqr_min_dist = MathLib::sqrDist(pnts[0]->getData(), pnt); nearest_pnt = pnts[0]; - for (size_t i(1); i < n_pnts; i++) { + for (size_t i(1); i < n_pnts; i++) + { const double sqr_dist(MathLib::sqrDist(pnts[i]->getData(), pnt)); - if (sqr_dist < sqr_min_dist) { + if (sqr_dist < sqr_min_dist) + { sqr_min_dist = sqr_dist; nearest_pnt = pnts[i]; } @@ -455,16 +506,16 @@ bool Grid::calcNearestPointInGridCell(double const* const pnt, size_t con } template -void Grid::getPointCellBorderDistances(double const*const pnt, double dists[6], size_t const* const coords) const +void Grid::getPointCellBorderDistances(double const* const pnt, double dists[6], + size_t const* const coords) const { - - dists[0] = (pnt[2] - _min_pnt[2] + coords[2]*_step_sizes[2]); // bottom + dists[0] = (pnt[2] - _min_pnt[2] + coords[2] * _step_sizes[2]); // bottom dists[5] = (_step_sizes[2] - dists[0]); // top - dists[1] = (pnt[1] - _min_pnt[1] + coords[1]*_step_sizes[1]); // front + dists[1] = (pnt[1] - _min_pnt[1] + coords[1] * _step_sizes[1]); // front dists[3] = (_step_sizes[1] - dists[1]); // back - dists[4] = (pnt[0] - _min_pnt[0] + coords[0]*_step_sizes[0]); // left + dists[4] = (pnt[0] - _min_pnt[0] + coords[0] * _step_sizes[0]); // left dists[2] = (_step_sizes[0] - dists[4]); // right } diff --git a/GEO/OctTree.h b/GEO/OctTree.h index 30148cef4..ecc5f57dd 100644 --- a/GEO/OctTree.h +++ b/GEO/OctTree.h @@ -18,33 +18,40 @@ // MathLib #include "MathTools.h" -namespace GEOLIB { - -template class OctTree { +namespace GEOLIB +{ +template +class OctTree +{ public: - - static OctTree* createOctTree(POINT & ll, POINT & ur, size_t max_points_per_node) + static OctTree* createOctTree(POINT& ll, POINT& ur, size_t max_points_per_node) { const double dx(ur[0] - ll[0]); const double dy(ur[1] - ll[1]); const double dz(ur[2] - ll[2]); - if (dx >= dy && dx >= dz) { - ll[1] -= (dx-dy)/2.0; - ur[1] += (dx-dy)/2.0; - ll[2] -= (dx-dz)/2.0; - ur[2] += (dx-dz)/2.0; - } else { - if (dy >= dx && dy >= dz) { - ll[0] -= (dy-dx)/2.0; - ur[0] += (dy-dx)/2.0; - ll[2] -= (dy-dz)/2.0; - ur[2] += (dy-dz)/2.0; - } else { - ll[0] -= (dz-dx)/2.0; - ur[0] += (dz-dx)/2.0; - ll[1] -= (dz-dy)/2.0; - ur[1] += (dz-dy)/2.0; + if (dx >= dy && dx >= dz) + { + ll[1] -= (dx - dy) / 2.0; + ur[1] += (dx - dy) / 2.0; + ll[2] -= (dx - dz) / 2.0; + ur[2] += (dx - dz) / 2.0; + } + else + { + if (dy >= dx && dy >= dz) + { + ll[0] -= (dy - dx) / 2.0; + ur[0] += (dy - dx) / 2.0; + ll[2] -= (dy - dz) / 2.0; + ur[2] += (dy - dz) / 2.0; + } + else + { + ll[0] -= (dz - dx) / 2.0; + ur[0] += (dz - dx) / 2.0; + ll[1] -= (dz - dy) / 2.0; + ur[1] += (dz - dy) / 2.0; } } @@ -64,37 +71,47 @@ template class OctTree { * @param pnt the point * @return If the point can be inserted the method returns true, else false. */ - bool addPoint (POINT* pnt) + bool addPoint(POINT* pnt) { - if ((*pnt)[0] < _ll[0]) return false; - if ((*pnt)[0] > _ur[0]) return false; - if ((*pnt)[1] < _ll[1]) return false; - if ((*pnt)[1] > _ur[1]) return false; - if ((*pnt)[2] < _ll[2]) return false; - if ((*pnt)[2] > _ur[2]) return false; - - if (!_is_leaf) { - for (size_t k(0); k < 8; k++) { - if (_childs[k]->addPoint (pnt)) { + if ((*pnt)[0] < _ll[0]) + return false; + if ((*pnt)[0] > _ur[0]) + return false; + if ((*pnt)[1] < _ll[1]) + return false; + if ((*pnt)[1] > _ur[1]) + return false; + if ((*pnt)[2] < _ll[2]) + return false; + if ((*pnt)[2] > _ur[2]) + return false; + + if (!_is_leaf) + { + for (size_t k(0); k < 8; k++) + { + if (_childs[k]->addPoint(pnt)) + { return true; } } } // check if point is already in OctTree - bool pnt_in_tree (false); - for (size_t k(0); k < _pnts.size() && !pnt_in_tree; k++) { - const double sqr_dist (MathLib::sqrDist( (_pnts[k])->getData(), pnt->getData() )); + bool pnt_in_tree(false); + for (size_t k(0); k < _pnts.size() && !pnt_in_tree; k++) + { + const double sqr_dist(MathLib::sqrDist((_pnts[k])->getData(), pnt->getData())); if (sqr_dist < std::numeric_limits::epsilon()) pnt_in_tree = true; } if (!pnt_in_tree) - _pnts.push_back (pnt); + _pnts.push_back(pnt); else return false; - if (_pnts.size () > OctTree::_max_points_per_node) - splitNode (); + if (_pnts.size() > OctTree::_max_points_per_node) + splitNode(); return true; } @@ -104,30 +121,42 @@ template class OctTree { * @param max * @param pnts */ - void getPointsInRange(POINT const& min, POINT const& max, std::vector &pnts) const + void getPointsInRange(POINT const& min, POINT const& max, std::vector& pnts) const { - if (_ur[0] < min[0]) return; - if (_ur[1] < min[1]) return; - if (_ur[2] < min[2]) return; - - if (max[0] < _ll[0]) return; - if (max[1] < _ll[1]) return; - if (max[2] < _ll[2]) return; - - if (_is_leaf) { + if (_ur[0] < min[0]) + return; + if (_ur[1] < min[1]) + return; + if (_ur[2] < min[2]) + return; + + if (max[0] < _ll[0]) + return; + if (max[1] < _ll[1]) + return; + if (max[2] < _ll[2]) + return; + + if (_is_leaf) + { typename std::vector::const_iterator it; - for (it = (_pnts.begin()); it != _pnts.end(); it++) { + for (it = (_pnts.begin()); it != _pnts.end(); it++) + { pnts.push_back(*it); } - } else { - for (size_t k(0); k<8; k++) { + } + else + { + for (size_t k(0); k < 8; k++) + { _childs[k]->getPointsInRange(min, max, pnts); } } } private: - enum OctTreeQuadrant { + enum OctTreeQuadrant + { NEL = 0, //!< north east lower NWL, //!< north west lower SWL, //!< south west lower @@ -144,15 +173,14 @@ template class OctTree { * @param ur upper right point * @return */ - OctTree (POINT const& ll, POINT const& ur) : - _ll (ll), _ur (ur), _is_leaf (true) + OctTree(POINT const& ll, POINT const& ur) : _ll(ll), _ur(ur), _is_leaf(true) { // init childs for (size_t k(0); k < 8; k++) _childs[k] = NULL; } - void splitNode () + void splitNode() { const double x_mid((_ur[0] + _ll[0]) / 2.0); const double y_mid((_ur[1] + _ll[1]) / 2.0); @@ -160,25 +188,25 @@ template class OctTree { POINT p0(x_mid, y_mid, _ll[2]), p1(_ur[0], _ur[1], z_mid); // create child NEL - _childs[NEL] = new OctTree (p0, p1); + _childs[NEL] = new OctTree(p0, p1); // create child NWL p0[0] = _ll[0]; p1[0] = x_mid; - _childs[NWL] = new OctTree (p0, p1); + _childs[NWL] = new OctTree(p0, p1); // create child SWL p0[1] = _ll[1]; p1[1] = y_mid; - _childs[SWL] = new OctTree (_ll, p1); + _childs[SWL] = new OctTree(_ll, p1); // create child NEU - _childs[NEU] = new OctTree (p1, _ur); + _childs[NEU] = new OctTree(p1, _ur); // create child SEL p0[0] = x_mid; p1[0] = _ur[0]; - _childs[SEL] = new OctTree (p0, p1); + _childs[SEL] = new OctTree(p0, p1); // create child NWU p0[0] = _ll[0]; @@ -187,26 +215,29 @@ template class OctTree { p1[0] = x_mid; p1[1] = _ur[1]; p1[2] = _ur[2]; - _childs[NWU] = new OctTree (p0, p1); + _childs[NWU] = new OctTree(p0, p1); // create child SWU p0[1] = _ll[1]; p1[1] = y_mid; - _childs[SWU] = new OctTree (p0, p1); + _childs[SWU] = new OctTree(p0, p1); // create child SEU p0[0] = x_mid; p1[0] = _ur[0]; p1[1] = y_mid; p1[2] = _ur[2]; - _childs[SEU] = new OctTree (p0, p1); + _childs[SEU] = new OctTree(p0, p1); // distribute points to sub quadtrees const size_t n_pnts(_pnts.size()); - for (size_t j(0); j < n_pnts; j++) { + for (size_t j(0); j < n_pnts; j++) + { bool nfound(true); - for (size_t k(0); k < 8 && nfound; k++) { - if (_childs[k]->addPoint(_pnts[j])) { + for (size_t k(0); k < 8 && nfound; k++) + { + if (_childs[k]->addPoint(_pnts[j])) + { nfound = false; } } @@ -244,8 +275,8 @@ template class OctTree { static size_t _max_points_per_node; }; -template size_t OctTree::_max_points_per_node = 0; - +template +size_t OctTree::_max_points_per_node = 0; } #endif /* OCTTREE_H_ */ diff --git a/GEO/Point.cpp b/GEO/Point.cpp index c772a682f..3df2e27b6 100644 --- a/GEO/Point.cpp +++ b/GEO/Point.cpp @@ -15,11 +15,11 @@ #include "Point.h" -bool operator<= (const GEOLIB::Point& p0, const GEOLIB::Point& p1) +bool operator<=(const GEOLIB::Point& p0, const GEOLIB::Point& p1) { - double tol (sqrt (std::numeric_limits::min())); + double tol(sqrt(std::numeric_limits::min())); - if (fabs (p0[0] - p1[0]) > tol * fabs(p0[0])) + if (fabs(p0[0] - p1[0]) > tol * fabs(p0[0])) { if (p0[0] < p1[0]) return true; @@ -29,7 +29,7 @@ bool operator<= (const GEOLIB::Point& p0, const GEOLIB::Point& p1) else { // assume p0[0] == p1[0] - if (fabs (p0[1] - p1[1]) > tol * fabs(p0[1])) + if (fabs(p0[1] - p1[1]) > tol * fabs(p0[1])) { if (p0[1] < p1[1]) return true; @@ -49,21 +49,21 @@ bool operator<= (const GEOLIB::Point& p0, const GEOLIB::Point& p1) namespace GEOLIB { -bool lessX (GEOLIB::Point const & p0, GEOLIB::Point const & p1) +bool lessX(GEOLIB::Point const& p0, GEOLIB::Point const& p1) { if (p0[0] <= p1[0]) return true; return false; } -bool lessY (GEOLIB::Point const & p0, GEOLIB::Point const & p1) +bool lessY(GEOLIB::Point const& p0, GEOLIB::Point const& p1) { if (p0[1] <= p1[1]) return true; return false; } -bool lessZ (GEOLIB::Point const & p0, GEOLIB::Point const & p1) +bool lessZ(GEOLIB::Point const& p0, GEOLIB::Point const& p1) { if (p0[2] <= p1[2]) return true; diff --git a/GEO/Point.h b/GEO/Point.h index 8e1ccca0b..78e4e399c 100644 --- a/GEO/Point.h +++ b/GEO/Point.h @@ -28,7 +28,7 @@ typedef TemplatePoint Point; * @param p1 second point * @return true if the x coordinate of p0 is smaller equal the x coordinate of p1, else false */ -bool lessX (Point const & p0, Point const & p1); +bool lessX(Point const& p0, Point const& p1); /** * comparison based on the y coordinate @@ -36,7 +36,7 @@ bool lessX (Point const & p0, Point const & p1); * @param p1 second point * @return true if the y coordinate of p0 is smaller equal the y coordinate of p1, else false */ -bool lessY (Point const & p0, Point const & p1); +bool lessY(Point const& p0, Point const& p1); /** * comparison based on the z coordinate @@ -44,12 +44,12 @@ bool lessY (Point const & p0, Point const & p1); * @param p1 second point * @return true if the z coordinate of p0 is smaller equal the z coordinate of p1, else false */ -bool lessZ (Point const & p0, Point const & p1); +bool lessZ(Point const& p0, Point const& p1); } /** * lexicographic comparison of points */ -bool operator<= (GEOLIB::Point const & p0, GEOLIB::Point const & p1); +bool operator<=(GEOLIB::Point const& p0, GEOLIB::Point const& p1); #endif /* POINT_H_ */ diff --git a/GEO/PointVec.cpp b/GEO/PointVec.cpp index ef1276b4a..61a379a34 100644 --- a/GEO/PointVec.cpp +++ b/GEO/PointVec.cpp @@ -20,67 +20,71 @@ namespace GEOLIB { -PointVec::PointVec (const std::string& name, std::vector* points, - std::map* name_id_map, PointType type, double rel_eps) : - TemplateVec (name, points, name_id_map), - _type(type), _sqr_shortest_dist (std::numeric_limits::max()) +PointVec::PointVec(const std::string& name, std::vector* points, std::map* name_id_map, + PointType type, double rel_eps) + : TemplateVec(name, points, name_id_map), _type(type), _sqr_shortest_dist(std::numeric_limits::max()) { - assert (_data_vec); - size_t number_of_all_input_pnts (_data_vec->size()); + assert(_data_vec); + size_t number_of_all_input_pnts(_data_vec->size()); - calculateAxisAlignedBoundingBox (); - rel_eps *= sqrt(MathLib::sqrDist (&(_aabb.getMinPoint()),&(_aabb.getMaxPoint()))); - makePntsUnique (_data_vec, _pnt_id_map, rel_eps); + calculateAxisAlignedBoundingBox(); + rel_eps *= sqrt(MathLib::sqrDist(&(_aabb.getMinPoint()), &(_aabb.getMaxPoint()))); + makePntsUnique(_data_vec, _pnt_id_map, rel_eps); if (number_of_all_input_pnts - _data_vec->size() > 0) - std::cerr << "WARNING: there are " << number_of_all_input_pnts - - _data_vec->size() << " double points" << "\n"; + std::cerr << "WARNING: there are " << number_of_all_input_pnts - _data_vec->size() << " double points" + << "\n"; } -PointVec::~PointVec () -{} +PointVec::~PointVec() +{ +} -size_t PointVec::push_back (Point* pnt) +size_t PointVec::push_back(Point* pnt) { - _pnt_id_map.push_back (uniqueInsert(pnt)); + _pnt_id_map.push_back(uniqueInsert(pnt)); return _pnt_id_map[_pnt_id_map.size() - 1]; } -void PointVec::push_back (Point* pnt, std::string const*const name) +void PointVec::push_back(Point* pnt, std::string const* const name) { - if (name == NULL) { - _pnt_id_map.push_back (uniqueInsert(pnt)); + if (name == NULL) + { + _pnt_id_map.push_back(uniqueInsert(pnt)); return; } - std::map::const_iterator it (_name_id_map->find (*name)); - if (it != _name_id_map->end()) { - std::cerr << "ERROR: PointVec::push_back (): two points with the same name" << "\n"; + std::map::const_iterator it(_name_id_map->find(*name)); + if (it != _name_id_map->end()) + { + std::cerr << "ERROR: PointVec::push_back (): two points with the same name" + << "\n"; return; } - size_t id (uniqueInsert (pnt)); - _pnt_id_map.push_back (id); + size_t id(uniqueInsert(pnt)); + _pnt_id_map.push_back(id); (*_name_id_map)[*name] = id; } -size_t PointVec::uniqueInsert (Point* pnt) +size_t PointVec::uniqueInsert(Point* pnt) { - size_t n (_data_vec->size()), k; - const double eps (std::numeric_limits::epsilon()); + size_t n(_data_vec->size()), k; + const double eps(std::numeric_limits::epsilon()); for (k = 0; k < n; k++) - if (fabs((*((*_data_vec)[k]))[0] - (*pnt)[0]) < eps - && fabs( (*((*_data_vec)[k]))[1] - (*pnt)[1]) < eps - && fabs( (*((*_data_vec)[k]))[2] - (*pnt)[2]) < eps) + if (fabs((*((*_data_vec)[k]))[0] - (*pnt)[0]) < eps && fabs((*((*_data_vec)[k]))[1] - (*pnt)[1]) < eps + && fabs((*((*_data_vec)[k]))[2] - (*pnt)[2]) < eps) break; - if(k == n) { - _data_vec->push_back (pnt); + if (k == n) + { + _data_vec->push_back(pnt); // update bounding box - _aabb.update (*((*_data_vec)[n])); + _aabb.update(*((*_data_vec)[n])); // update shortest distance - for (size_t i(0); i < n; i++) { - double sqr_dist (MathLib::sqrDist((*_data_vec)[i], (*_data_vec)[n])); + for (size_t i(0); i < n; i++) + { + double sqr_dist(MathLib::sqrDist((*_data_vec)[i], (*_data_vec)[n])); if (sqr_dist < _sqr_shortest_dist) _sqr_shortest_dist = sqr_dist; } @@ -92,83 +96,81 @@ size_t PointVec::uniqueInsert (Point* pnt) return k; } -std::vector* PointVec::filterStations(const std::vector &bounds) const +std::vector* PointVec::filterStations(const std::vector& bounds) const { - std::vector* tmpStations (new std::vector); - size_t size (_data_vec->size()); + std::vector* tmpStations(new std::vector); + size_t size(_data_vec->size()); for (size_t i = 0; i < size; i++) if (static_cast((*_data_vec)[i])->inSelection(bounds)) tmpStations->push_back((*_data_vec)[i]); return tmpStations; } -double PointVec::getShortestPointDistance () const +double PointVec::getShortestPointDistance() const { - return sqrt (_sqr_shortest_dist); + return sqrt(_sqr_shortest_dist); } -void PointVec::makePntsUnique (std::vector* pnt_vec, - std::vector &pnt_id_map, double eps) +void PointVec::makePntsUnique(std::vector* pnt_vec, std::vector& pnt_id_map, double eps) { - size_t n_pnts_in_file (pnt_vec->size()); + size_t n_pnts_in_file(pnt_vec->size()); std::vector perm; - pnt_id_map.reserve (n_pnts_in_file); + pnt_id_map.reserve(n_pnts_in_file); for (size_t k(0); k < n_pnts_in_file; k++) { - perm.push_back (k); + perm.push_back(k); pnt_id_map.push_back(k); } // sort the points - Quicksort (*pnt_vec, 0, n_pnts_in_file, perm); + Quicksort(*pnt_vec, 0, n_pnts_in_file, perm); // unfortunately quicksort is not stable - // sort identical points by id - to make sorting stable // determine intervals with identical points to resort for stability of sorting std::vector identical_pnts_interval; - bool identical (false); + bool identical(false); for (size_t k = 0; k < n_pnts_in_file - 1; k++) { - if ( fabs((*((*pnt_vec)[k + 1]))[0] - (*((*pnt_vec)[k]))[0]) < eps - && fabs( (*((*pnt_vec)[k + 1]))[1] - (*((*pnt_vec)[k]))[1]) < eps - && fabs( (*((*pnt_vec)[k + 1]))[2] - (*((*pnt_vec)[k]))[2]) < eps) + if (fabs((*((*pnt_vec)[k + 1]))[0] - (*((*pnt_vec)[k]))[0]) < eps + && fabs((*((*pnt_vec)[k + 1]))[1] - (*((*pnt_vec)[k]))[1]) < eps + && fabs((*((*pnt_vec)[k + 1]))[2] - (*((*pnt_vec)[k]))[2]) < eps) { // points are identical, sort by id if (!identical) - identical_pnts_interval.push_back (k); + identical_pnts_interval.push_back(k); identical = true; } else { if (identical) - identical_pnts_interval.push_back (k + 1); + identical_pnts_interval.push_back(k + 1); identical = false; } } if (identical) - identical_pnts_interval.push_back (n_pnts_in_file); + identical_pnts_interval.push_back(n_pnts_in_file); for (size_t i(0); i < identical_pnts_interval.size() / 2; i++) { // bubble sort by id - size_t beg (identical_pnts_interval[2 * i]); - size_t end (identical_pnts_interval[2 * i + 1]); - for (size_t j (beg); j < end; j++) - for (size_t k (beg); k < end - 1; k++) + size_t beg(identical_pnts_interval[2 * i]); + size_t end(identical_pnts_interval[2 * i + 1]); + for (size_t j(beg); j < end; j++) + for (size_t k(beg); k < end - 1; k++) if (perm[k] > perm[k + 1]) - std::swap (perm[k], perm[k + 1]); - + std::swap(perm[k], perm[k + 1]); } // check if there are identical points for (size_t k = 0; k < n_pnts_in_file - 1; k++) - if ( fabs((*((*pnt_vec)[k + 1]))[0] - (*((*pnt_vec)[k]))[0]) < eps - && fabs( (*((*pnt_vec)[k + 1]))[1] - (*((*pnt_vec)[k]))[1]) < eps - && fabs( (*((*pnt_vec)[k + 1]))[2] - (*((*pnt_vec)[k]))[2]) < eps) + if (fabs((*((*pnt_vec)[k + 1]))[0] - (*((*pnt_vec)[k]))[0]) < eps + && fabs((*((*pnt_vec)[k + 1]))[1] - (*((*pnt_vec)[k]))[1]) < eps + && fabs((*((*pnt_vec)[k + 1]))[2] - (*((*pnt_vec)[k]))[2]) < eps) pnt_id_map[perm[k + 1]] = pnt_id_map[perm[k]]; // reverse permutation - Quicksort (perm, 0, n_pnts_in_file, *pnt_vec); + Quicksort(perm, 0, n_pnts_in_file, *pnt_vec); // remove the second, third, ... occurrence from vector for (size_t k(0); k < n_pnts_in_file; k++) @@ -178,16 +180,16 @@ void PointVec::makePntsUnique (std::vector* pnt_vec, (*pnt_vec)[k] = NULL; } // remove NULL-ptr from vector - for (std::vector::iterator it(pnt_vec->begin()); it != pnt_vec->end(); ) + for (std::vector::iterator it(pnt_vec->begin()); it != pnt_vec->end();) { if (*it == NULL) - it = pnt_vec->erase (it); + it = pnt_vec->erase(it); else it++; } // renumber id-mapping - size_t cnt (0); + size_t cnt(0); for (size_t k(0); k < n_pnts_in_file; k++) { if (pnt_id_map[k] == k) // point not removed, if necessary: id change @@ -200,35 +202,35 @@ void PointVec::makePntsUnique (std::vector* pnt_vec, } // KR correct renumbering of indices -// size_t cnt(0); -// std::map reg_ids; -// for (size_t k(0); k < n_pnts_in_file; k++) { -// if (pnt_id_map[k] == k) { -// reg_ids.insert(std::pair(k, cnt)); -// cnt++; -// } else reg_ids.insert(std::pair(k, reg_ids[pnt_id_map[k]])); -// } -// for (size_t k(0); k < n_pnts_in_file; k++) -// pnt_id_map[k] = reg_ids[k]; + // size_t cnt(0); + // std::map reg_ids; + // for (size_t k(0); k < n_pnts_in_file; k++) { + // if (pnt_id_map[k] == k) { + // reg_ids.insert(std::pair(k, cnt)); + // cnt++; + // } else reg_ids.insert(std::pair(k, reg_ids[pnt_id_map[k]])); + // } + // for (size_t k(0); k < n_pnts_in_file; k++) + // pnt_id_map[k] = reg_ids[k]; } -void PointVec::calculateShortestDistance () +void PointVec::calculateShortestDistance() { size_t i, j; - BruteForceClosestPair (*_data_vec, i, j); - _sqr_shortest_dist = MathLib::sqrDist ((*_data_vec)[i], (*_data_vec)[j]); + BruteForceClosestPair(*_data_vec, i, j); + _sqr_shortest_dist = MathLib::sqrDist((*_data_vec)[i], (*_data_vec)[j]); } -void PointVec::calculateAxisAlignedBoundingBox () +void PointVec::calculateAxisAlignedBoundingBox() { - const size_t n_pnts (_data_vec->size()); + const size_t n_pnts(_data_vec->size()); for (size_t i(0); i < n_pnts; i++) - _aabb.update (*(*_data_vec)[i]); + _aabb.update(*(*_data_vec)[i]); } -std::vector* PointVec::getSubset(const std::vector &subset) +std::vector* PointVec::getSubset(const std::vector& subset) { - std::vector *new_points (new std::vector(subset.size())); + std::vector* new_points(new std::vector(subset.size())); const size_t nPoints(subset.size()); for (size_t i = 0; i < nPoints; i++) @@ -237,9 +239,9 @@ std::vector* PointVec::getSubset(const std::vector &subs return new_points; } -std::vector* PointVec::deepcopy(const std::vector *pnt_vec) +std::vector* PointVec::deepcopy(const std::vector* pnt_vec) { - std::vector* new_points (new std::vector); + std::vector* new_points(new std::vector); const size_t nPoints(pnt_vec->size()); for (size_t i = 0; i < nPoints; i++) @@ -247,7 +249,4 @@ std::vector* PointVec::deepcopy(const std::vector /// Signals if the vector contains object of type Point or Station enum PointType { - POINT = 0, - STATION = 1 + POINT = 0, + STATION = 1 }; /** @@ -70,12 +69,11 @@ class PointVec : public TemplateVec * \f$|p_1 - p_0| \le tol.\f$ * @return an object of type PointVec */ - PointVec (const std::string& name, std::vector* points, - std::map* name_id_map = NULL, - PointType type = PointVec::POINT, double rel_eps = sqrt(std::numeric_limits::min())); + PointVec(const std::string& name, std::vector* points, std::map* name_id_map = NULL, + PointType type = PointVec::POINT, double rel_eps = sqrt(std::numeric_limits::min())); /** Destructor deletes all Points of this PointVec. */ - virtual ~PointVec (); + virtual ~PointVec(); /** * Method adds a Point to the (internal) standard vector and takes the ownership. @@ -84,49 +82,48 @@ class PointVec : public TemplateVec * @param pnt the pointer to the Point * @return the id of the point within the internal vector */ - size_t push_back (Point* pnt); + size_t push_back(Point* pnt); /** * push_back adds new elements at the end of the vector _data_vec. * @param pnt a pointer to the point, PointVec takes ownership of the point * @param name the name of the point */ - virtual void push_back (Point* pnt, std::string const*const name); + virtual void push_back(Point* pnt, std::string const* const name); /** * get the type of Point, this can be either POINT or STATION * */ PointType getType() const { return _type; } + std::vector* filterStations(const std::vector& bounds) const; - std::vector* filterStations(const std::vector &bounds) const; - - const std::vector& getIDMap () const { return _pnt_id_map; } - - double getShortestPointDistance () const; - const GEOLIB::AABB& getAxisAlignedBoundingBox () const; + const std::vector& getIDMap() const { return _pnt_id_map; } + double getShortestPointDistance() const; + const GEOLIB::AABB& getAxisAlignedBoundingBox() const; /// Creates a real copy of the point vector in memeory. - static std::vector* deepcopy(const std::vector *pnt_vec); + static std::vector* deepcopy(const std::vector* pnt_vec); /// Returns a subset of this point vector containing only the points specified in "subset" as PointWithID-objects - std::vector* getSubset(const std::vector &subset); + std::vector* getSubset(const std::vector& subset); private: - void makePntsUnique (std::vector* pnt_vec, std::vector &pnt_id_map, double eps = sqrt(std::numeric_limits::min())); + void makePntsUnique(std::vector* pnt_vec, std::vector& pnt_id_map, + double eps = sqrt(std::numeric_limits::min())); /** copy constructor doesn't have an implementation */ // compiler does not create a (possible unwanted) copy constructor - PointVec (const PointVec &); + PointVec(const PointVec&); /** standard constructor doesn't have an implementation */ // compiler does not create a (possible unwanted) standard constructor - PointVec (); + PointVec(); /** assignment operator doesn't have an implementation */ // this way the compiler does not create a (possible unwanted) assignment operator - PointVec& operator= (const PointVec& rhs); + PointVec& operator=(const PointVec& rhs); - size_t uniqueInsert (Point* pnt); + size_t uniqueInsert(Point* pnt); /** the type of the point (\sa enum PointType) */ PointType _type; @@ -140,13 +137,13 @@ class PointVec : public TemplateVec /** * method calculates the shortest distance of points inside the _pnt_vec */ - void calculateShortestDistance (); + void calculateShortestDistance(); /** * squared shortest distance - calculated by calculateShortestAndLargestDistance, possible update by uniqueInsert */ double _sqr_shortest_dist; - void calculateAxisAlignedBoundingBox (); + void calculateAxisAlignedBoundingBox(); AABB _aabb; }; } // end namespace diff --git a/GEO/PointWithID.h b/GEO/PointWithID.h index 2cff53e50..c466c966e 100644 --- a/GEO/PointWithID.h +++ b/GEO/PointWithID.h @@ -24,20 +24,10 @@ namespace GEOLIB class PointWithID : public Point { public: - PointWithID (double x0, double x1, double x2, size_t id) : - Point (x0, x1, x2), _id (id) - {} - - PointWithID (double const* const coords, size_t id) : - Point (coords), _id (id) - {} - - PointWithID (GEOLIB::Point const& pnt, size_t id) : - Point (pnt), _id (id) - {} - - size_t getID () const { return _id; } - + PointWithID(double x0, double x1, double x2, size_t id) : Point(x0, x1, x2), _id(id) {} + PointWithID(double const* const coords, size_t id) : Point(coords), _id(id) {} + PointWithID(GEOLIB::Point const& pnt, size_t id) : Point(pnt), _id(id) {} + size_t getID() const { return _id; } protected: size_t _id; }; diff --git a/GEO/Polygon.cpp b/GEO/Polygon.cpp index 55c9df41c..c65f586a6 100644 --- a/GEO/Polygon.cpp +++ b/GEO/Polygon.cpp @@ -30,78 +30,84 @@ namespace GEOLIB { -Polygon::Polygon(const Polyline &ply, bool init) : - Polyline (ply) +Polygon::Polygon(const Polyline& ply, bool init) : Polyline(ply) { if (init) - initialise (); + initialise(); } -Polygon::Polygon (const std::vector& pnt_vec) : - Polyline (pnt_vec) -{} +Polygon::Polygon(const std::vector& pnt_vec) : Polyline(pnt_vec) +{ +} Polygon::~Polygon() { // remove polygons from list - for (std::list::iterator it (_simple_polygon_list.begin()); - it != _simple_polygon_list.end(); it++) + for (std::list::iterator it(_simple_polygon_list.begin()); it != _simple_polygon_list.end(); it++) // the first entry of the list can be a pointer the object itself if (*it != this) delete *it; } -bool Polygon::initialise () +bool Polygon::initialise() { - if (this->isClosed()) { + if (this->isClosed()) + { calculateAxisAlignedBoundingBox(); ensureCWOrientation(); return true; - } else { - std::cerr << "ERROR in Polygon::initialise() - base polyline is not closed" << - "\n"; + } + else + { + std::cerr << "ERROR in Polygon::initialise() - base polyline is not closed" + << "\n"; return false; } } -bool Polygon::isPntInPolygon (GEOLIB::Point const & pnt) const +bool Polygon::isPntInPolygon(GEOLIB::Point const& pnt) const { - GEOLIB::Point const& min_aabb_pnt (_aabb.getMinPoint()); - GEOLIB::Point const& max_aabb_pnt (_aabb.getMaxPoint()); + GEOLIB::Point const& min_aabb_pnt(_aabb.getMinPoint()); + GEOLIB::Point const& max_aabb_pnt(_aabb.getMaxPoint()); - if (pnt[0] < min_aabb_pnt[0] || max_aabb_pnt[0] < pnt[0] || pnt[1] < min_aabb_pnt[1] || - max_aabb_pnt[1] < pnt[1]) + if (pnt[0] < min_aabb_pnt[0] || max_aabb_pnt[0] < pnt[0] || pnt[1] < min_aabb_pnt[1] || max_aabb_pnt[1] < pnt[1]) return false; - size_t n_intersections (0); + size_t n_intersections(0); GEOLIB::Point s; - if (_simple_polygon_list.empty ()) { - const size_t n_nodes (getNumberOfPoints() - 1); - for (size_t k(0); k < n_nodes; k++) { - if (((*(getPoint(k)))[1] <= pnt[1] && pnt[1] <= (*(getPoint(k + 1)))[1]) || - ((*(getPoint(k + 1)))[1] <= pnt[1] && pnt[1] <= (*(getPoint(k)))[1])) { + if (_simple_polygon_list.empty()) + { + const size_t n_nodes(getNumberOfPoints() - 1); + for (size_t k(0); k < n_nodes; k++) + { + if (((*(getPoint(k)))[1] <= pnt[1] && pnt[1] <= (*(getPoint(k + 1)))[1]) + || ((*(getPoint(k + 1)))[1] <= pnt[1] && pnt[1] <= (*(getPoint(k)))[1])) + { switch (getEdgeType(k, pnt)) { - case EdgeType::TOUCHING: - return true; - case EdgeType::CROSSING: - n_intersections++; - break; - case EdgeType::INESSENTIAL: - break; - default: - // do nothing - ; + case EdgeType::TOUCHING: + return true; + case EdgeType::CROSSING: + n_intersections++; + break; + case EdgeType::INESSENTIAL: + break; + default: + // do nothing + ; } } } if (n_intersections % 2 == 1) return true; - } else { - for (std::list::const_iterator it (_simple_polygon_list.begin()); - it != _simple_polygon_list.end(); ++it) { - if ((*it)->isPntInPolygon (pnt)) + } + else + { + for (std::list::const_iterator it(_simple_polygon_list.begin()); it != _simple_polygon_list.end(); + ++it) + { + if ((*it)->isPntInPolygon(pnt)) return true; } return false; @@ -111,15 +117,17 @@ bool Polygon::isPntInPolygon (GEOLIB::Point const & pnt) const bool Polygon::isPntInPolygon(double x, double y, double z) const { - const GEOLIB::Point pnt(x,y,z); - return isPntInPolygon (pnt); + const GEOLIB::Point pnt(x, y, z); + return isPntInPolygon(pnt); } bool Polygon::isPolylineInPolygon(const Polyline& ply) const { - size_t ply_size (ply.getNumberOfPoints()), cnt (0); - for (size_t k(0); k < ply_size; k++) { - if (isPntInPolygon (*(ply[k]))) { + size_t ply_size(ply.getNumberOfPoints()), cnt(0); + for (size_t k(0); k < ply_size; k++) + { + if (isPntInPolygon(*(ply[k]))) + { cnt++; } } @@ -131,20 +139,25 @@ bool Polygon::isPolylineInPolygon(const Polyline& ply) const bool Polygon::isPartOfPolylineInPolygon(const Polyline& ply) const { - const size_t ply_size (ply.getNumberOfPoints()); + const size_t ply_size(ply.getNumberOfPoints()); // check points - for (size_t k(0); k < ply_size; k++) { - if (isPntInPolygon (*(ply[k]))) { + for (size_t k(0); k < ply_size; k++) + { + if (isPntInPolygon(*(ply[k]))) + { return true; } } // check segment intersections - GEOLIB::Point* s (new GEOLIB::Point (0,0,0)); + GEOLIB::Point* s(new GEOLIB::Point(0, 0, 0)); const size_t n_nodes(getNumberOfPoints() - 1); - for (size_t k(0); k < ply_size - 1; k++) { - for (size_t j(0); j < n_nodes; j++) { - if (MathLib::lineSegmentIntersect(*(getPoint(j)), *(getPoint(j + 1)), - *(ply.getPoint(k)), *(ply.getPoint(k + 1)), *s)) { + for (size_t k(0); k < ply_size - 1; k++) + { + for (size_t j(0); j < n_nodes; j++) + { + if (MathLib::lineSegmentIntersect(*(getPoint(j)), *(getPoint(j + 1)), *(ply.getPoint(k)), + *(ply.getPoint(k + 1)), *s)) + { delete s; return true; } @@ -155,26 +168,33 @@ bool Polygon::isPartOfPolylineInPolygon(const Polyline& ply) const return false; } -bool Polygon::getNextIntersectionPointPolygonLine (GEOLIB::Point const & a, - GEOLIB::Point const & b, GEOLIB::Point* intersection_pnt, - size_t& seg_num) const +bool Polygon::getNextIntersectionPointPolygonLine(GEOLIB::Point const& a, GEOLIB::Point const& b, + GEOLIB::Point* intersection_pnt, size_t& seg_num) const { - if (_simple_polygon_list.empty()) { + if (_simple_polygon_list.empty()) + { const size_t n_nodes(getNumberOfPoints() - 1); - for (size_t k(seg_num); k < n_nodes; k++) { - if (MathLib::lineSegmentIntersect(*(getPoint(k)), *(getPoint(k + 1)), a, b, *intersection_pnt)) { + for (size_t k(seg_num); k < n_nodes; k++) + { + if (MathLib::lineSegmentIntersect(*(getPoint(k)), *(getPoint(k + 1)), a, b, *intersection_pnt)) + { seg_num = k; return true; } } - } else { - for (std::list::const_iterator it(_simple_polygon_list.begin()); it - != _simple_polygon_list.end(); ++it) { + } + else + { + for (std::list::const_iterator it(_simple_polygon_list.begin()); it != _simple_polygon_list.end(); + ++it) + { const Polygon* polygon(*it); const size_t n_nodes_simple_polygon(polygon->getNumberOfPoints() - 1); - for (size_t k(0); k < n_nodes_simple_polygon; k++) { - if (MathLib::lineSegmentIntersect(*(polygon->getPoint(k)), *(polygon->getPoint(k + 1)), - a, b, *intersection_pnt)) { + for (size_t k(0); k < n_nodes_simple_polygon; k++) + { + if (MathLib::lineSegmentIntersect(*(polygon->getPoint(k)), *(polygon->getPoint(k + 1)), a, b, + *intersection_pnt)) + { seg_num = k; return true; } @@ -187,70 +207,71 @@ bool Polygon::getNextIntersectionPointPolygonLine (GEOLIB::Point const & a, const std::list& Polygon::getListOfSimplePolygons() { if (_simple_polygon_list.empty()) - _simple_polygon_list.push_back (this); + _simple_polygon_list.push_back(this); return _simple_polygon_list; } -void Polygon::computeListOfSimplePolygons () +void Polygon::computeListOfSimplePolygons() { if (!_simple_polygon_list.empty()) return; - _simple_polygon_list.push_back (this); - splitPolygonAtPoint (_simple_polygon_list.begin()); - splitPolygonAtIntersection (_simple_polygon_list.begin()); + _simple_polygon_list.push_back(this); + splitPolygonAtPoint(_simple_polygon_list.begin()); + splitPolygonAtIntersection(_simple_polygon_list.begin()); - for (std::list::iterator it (_simple_polygon_list.begin()); - it != _simple_polygon_list.end(); it++) - (*it)->initialise (); + for (std::list::iterator it(_simple_polygon_list.begin()); it != _simple_polygon_list.end(); it++) + (*it)->initialise(); } -EdgeType::value Polygon::getEdgeType (size_t k, GEOLIB::Point const & pnt) const +EdgeType::value Polygon::getEdgeType(size_t k, GEOLIB::Point const& pnt) const { switch (getLocationOfPoint(k, pnt)) { - case Location::LEFT: { - const GEOLIB::Point & v (*(getPoint(k))); - const GEOLIB::Point & w (*(getPoint(k + 1))); - if (v[1] < pnt[1] && pnt[1] <= w[1]) - return EdgeType::CROSSING; - else - return EdgeType::INESSENTIAL; - break; - } - case Location::RIGHT: { - const GEOLIB::Point & v (*(getPoint(k))); - const GEOLIB::Point & w (*(getPoint(k + 1))); - if (w[1] < pnt[1] && pnt[1] <= v[1]) - return EdgeType::CROSSING; - else + case Location::LEFT: + { + const GEOLIB::Point& v(*(getPoint(k))); + const GEOLIB::Point& w(*(getPoint(k + 1))); + if (v[1] < pnt[1] && pnt[1] <= w[1]) + return EdgeType::CROSSING; + else + return EdgeType::INESSENTIAL; + break; + } + case Location::RIGHT: + { + const GEOLIB::Point& v(*(getPoint(k))); + const GEOLIB::Point& w(*(getPoint(k + 1))); + if (w[1] < pnt[1] && pnt[1] <= v[1]) + return EdgeType::CROSSING; + else + return EdgeType::INESSENTIAL; + break; + } + case Location::BETWEEN: + case Location::SOURCE: + case Location::DESTINATION: + return EdgeType::TOUCHING; + default: return EdgeType::INESSENTIAL; - break; - } - case Location::BETWEEN: - case Location::SOURCE: - case Location::DESTINATION: - return EdgeType::TOUCHING; - default: - return EdgeType::INESSENTIAL; } } -void Polygon::calculateAxisAlignedBoundingBox () +void Polygon::calculateAxisAlignedBoundingBox() { - size_t n_nodes (getNumberOfPoints()); + size_t n_nodes(getNumberOfPoints()); for (size_t k(0); k < n_nodes; k++) - _aabb.update ((*(getPoint(k)))); + _aabb.update((*(getPoint(k)))); } -void Polygon::ensureCWOrientation () +void Polygon::ensureCWOrientation() { // *** pre processing: rotate points to xy-plan // *** copy points to vector - last point is identical to the first - size_t n_pnts (this->getNumberOfPoints() - 1); + size_t n_pnts(this->getNumberOfPoints() - 1); std::vector tmp_polygon_pnts; for (size_t k(0); k < n_pnts; k++) - tmp_polygon_pnts.push_back (new GEOLIB::Point (*(this->getPoint(k)))); + tmp_polygon_pnts.push_back(new GEOLIB::Point(*(this->getPoint(k)))); // *** calculate supporting plane (plane normal and MathLib::Vector plane_normal; @@ -258,7 +279,7 @@ void Polygon::ensureCWOrientation () MathLib::getNewellPlane(tmp_polygon_pnts, plane_normal, d); // *** rotate if necessary - double tol (sqrt(std::numeric_limits::min())); + double tol(sqrt(std::numeric_limits::min())); if (fabs(plane_normal[0]) > tol || fabs(plane_normal[1]) > tol) // rotate copied points into x-y-plane MathLib::rotatePointsToXY(plane_normal, tmp_polygon_pnts); @@ -267,108 +288,93 @@ void Polygon::ensureCWOrientation () (*(tmp_polygon_pnts[k]))[2] = 0.0; // should be -= d but there are numerical errors // *** get the left most upper point - size_t min_x_max_y_idx (0); // for orientation check + size_t min_x_max_y_idx(0); // for orientation check for (size_t k(0); k < n_pnts; k++) if ((*(tmp_polygon_pnts[k]))[0] <= (*(tmp_polygon_pnts[min_x_max_y_idx]))[0]) { if ((*(tmp_polygon_pnts[k]))[0] < (*(tmp_polygon_pnts[min_x_max_y_idx]))[0]) min_x_max_y_idx = k; - else if ((*(tmp_polygon_pnts[k]))[1] > - (*(tmp_polygon_pnts[min_x_max_y_idx]))[1]) + else if ((*(tmp_polygon_pnts[k]))[1] > (*(tmp_polygon_pnts[min_x_max_y_idx]))[1]) min_x_max_y_idx = k; - } // *** determine orientation MathLib::Orientation orient; if (0 < min_x_max_y_idx && min_x_max_y_idx < n_pnts - 2) - orient = MathLib::getOrientation ( - tmp_polygon_pnts[min_x_max_y_idx - 1], - tmp_polygon_pnts[min_x_max_y_idx], - tmp_polygon_pnts[min_x_max_y_idx + 1]); + orient = MathLib::getOrientation(tmp_polygon_pnts[min_x_max_y_idx - 1], + tmp_polygon_pnts[min_x_max_y_idx], + tmp_polygon_pnts[min_x_max_y_idx + 1]); else { if (0 == min_x_max_y_idx) - orient = MathLib::getOrientation ( - tmp_polygon_pnts[n_pnts - 1], - tmp_polygon_pnts[0], - tmp_polygon_pnts[1]); + orient = MathLib::getOrientation(tmp_polygon_pnts[n_pnts - 1], tmp_polygon_pnts[0], tmp_polygon_pnts[1]); else - orient = MathLib::getOrientation ( - tmp_polygon_pnts[n_pnts - 2], - tmp_polygon_pnts[n_pnts - 1], - tmp_polygon_pnts[0]); + orient = MathLib::getOrientation(tmp_polygon_pnts[n_pnts - 2], tmp_polygon_pnts[n_pnts - 1], + tmp_polygon_pnts[0]); } if (orient == MathLib::CCW) { // switch orientation - size_t tmp_n_pnts (n_pnts); + size_t tmp_n_pnts(n_pnts); tmp_n_pnts++; // include last point of polygon (which is identical to the first) for (size_t k(0); k < tmp_n_pnts / 2; k++) - BASELIB::swap (_ply_pnt_ids[k], _ply_pnt_ids[tmp_n_pnts - 1 - k]); + BASELIB::swap(_ply_pnt_ids[k], _ply_pnt_ids[tmp_n_pnts - 1 - k]); } for (size_t k(0); k < n_pnts; k++) delete tmp_polygon_pnts[k]; } -void Polygon::splitPolygonAtIntersection (std::list::iterator polygon_it) +void Polygon::splitPolygonAtIntersection(std::list::iterator polygon_it) { - size_t idx0 (0), idx1 (0); + size_t idx0(0), idx1(0); while (polygon_it != _simple_polygon_list.end()) { - GEOLIB::Point* intersection_pnt (new GEOLIB::Point); - bool is_simple (!MathLib::lineSegmentsIntersect (*polygon_it, - idx0, - idx1, - *intersection_pnt)); + GEOLIB::Point* intersection_pnt(new GEOLIB::Point); + bool is_simple(!MathLib::lineSegmentsIntersect(*polygon_it, idx0, idx1, *intersection_pnt)); if (!is_simple) { // adding intersection point to pnt_vec - size_t intersection_pnt_id (_ply_pnts.size()); - const_cast& >(_ply_pnts).push_back (intersection_pnt); + size_t intersection_pnt_id(_ply_pnts.size()); + const_cast&>(_ply_pnts).push_back(intersection_pnt); // split Polygon if (idx0 > idx1) - BASELIB::swap (idx0, idx1); + BASELIB::swap(idx0, idx1); - GEOLIB::Polygon* polygon0 (new GEOLIB::Polygon( - (*polygon_it)->getPointsVec(), false)); + GEOLIB::Polygon* polygon0(new GEOLIB::Polygon((*polygon_it)->getPointsVec(), false)); for (size_t k(0); k <= idx0; k++) - polygon0->addPoint ((*polygon_it)->getPointID (k)); - polygon0->addPoint (intersection_pnt_id); + polygon0->addPoint((*polygon_it)->getPointID(k)); + polygon0->addPoint(intersection_pnt_id); for (size_t k(idx1 + 1); k < (*polygon_it)->getNumberOfPoints(); k++) - polygon0->addPoint ((*polygon_it)->getPointID (k)); + polygon0->addPoint((*polygon_it)->getPointID(k)); if (!polygon0->initialise()) { - std::cerr << - "ERROR in Polygon::splitPolygonAtIntersection polygon0" << - "\n"; - exit (1); + std::cerr << "ERROR in Polygon::splitPolygonAtIntersection polygon0" + << "\n"; + exit(1); } - GEOLIB::Polygon* polygon1 (new GEOLIB::Polygon( - (*polygon_it)->getPointsVec(), false)); - polygon1->addPoint (intersection_pnt_id); + GEOLIB::Polygon* polygon1(new GEOLIB::Polygon((*polygon_it)->getPointsVec(), false)); + polygon1->addPoint(intersection_pnt_id); for (size_t k(idx0 + 1); k <= idx1; k++) - polygon1->addPoint ((*polygon_it)->getPointID (k)); - polygon1->addPoint (intersection_pnt_id); + polygon1->addPoint((*polygon_it)->getPointID(k)); + polygon1->addPoint(intersection_pnt_id); if (!polygon1->initialise()) { - std::cerr << - "ERROR in Polygon::splitPolygonAtIntersection polygon1" << - "\n"; - exit (1); + std::cerr << "ERROR in Polygon::splitPolygonAtIntersection polygon1" + << "\n"; + exit(1); } // remove original polyline and add two new polylines - std::list::iterator polygon0_it, polygon1_it; - polygon_it = _simple_polygon_list.erase (polygon_it); - polygon1_it = _simple_polygon_list.insert (polygon_it, polygon1); - polygon0_it = _simple_polygon_list.insert (polygon1_it, polygon0); + std::list::iterator polygon0_it, polygon1_it; + polygon_it = _simple_polygon_list.erase(polygon_it); + polygon1_it = _simple_polygon_list.insert(polygon_it, polygon1); + polygon0_it = _simple_polygon_list.insert(polygon1_it, polygon0); - splitPolygonAtIntersection (polygon0_it); - splitPolygonAtIntersection (polygon1_it); + splitPolygonAtIntersection(polygon0_it); + splitPolygonAtIntersection(polygon1_it); } else delete intersection_pnt; @@ -376,77 +382,75 @@ void Polygon::splitPolygonAtIntersection (std::list::iterator polygon_ } } -void Polygon::splitPolygonAtPoint (std::list::iterator polygon_it) +void Polygon::splitPolygonAtPoint(std::list::iterator polygon_it) { - size_t n ((*polygon_it)->getNumberOfPoints() - 1), idx0 (0), idx1(0); - size_t* id_vec (new size_t[n]), *perm (new size_t[n]); + size_t n((*polygon_it)->getNumberOfPoints() - 1), idx0(0), idx1(0); + size_t *id_vec(new size_t[n]), *perm(new size_t[n]); for (size_t k(0); k < n; k++) { - id_vec[k] = (*polygon_it)->getPointID (k); + id_vec[k] = (*polygon_it)->getPointID(k); perm[k] = k; } - quicksort (id_vec, 0, n, perm); + quicksort(id_vec, 0, n, perm); for (size_t k(0); k < n - 1; k++) if (id_vec[k] == id_vec[k + 1]) { idx0 = perm[k]; idx1 = perm[k + 1]; - delete [] perm; - delete [] id_vec; + delete[] perm; + delete[] id_vec; if (idx0 > idx1) - BASELIB::swap (idx0, idx1); + BASELIB::swap(idx0, idx1); // create two closed polylines - GEOLIB::Polygon* polygon0 (new GEOLIB::Polygon((*polygon_it)->getPointsVec())); + GEOLIB::Polygon* polygon0(new GEOLIB::Polygon((*polygon_it)->getPointsVec())); for (size_t k(0); k <= idx0; k++) - polygon0->addPoint ((*polygon_it)->getPointID (k)); + polygon0->addPoint((*polygon_it)->getPointID(k)); for (size_t k(idx1 + 1); k < (*polygon_it)->getNumberOfPoints(); k++) - polygon0->addPoint ((*polygon_it)->getPointID (k)); + polygon0->addPoint((*polygon_it)->getPointID(k)); polygon0->initialise(); - GEOLIB::Polygon* polygon1 (new GEOLIB::Polygon((*polygon_it)->getPointsVec())); + GEOLIB::Polygon* polygon1(new GEOLIB::Polygon((*polygon_it)->getPointsVec())); for (size_t k(idx0); k <= idx1; k++) - polygon1->addPoint ((*polygon_it)->getPointID (k)); + polygon1->addPoint((*polygon_it)->getPointID(k)); polygon1->initialise(); // remove original polygon and add two new polygons - std::list::iterator polygon0_it, polygon1_it; - polygon1_it = - _simple_polygon_list.insert (_simple_polygon_list.erase ( - polygon_it), polygon1); - polygon0_it = _simple_polygon_list.insert (polygon1_it, polygon0); + std::list::iterator polygon0_it, polygon1_it; + polygon1_it = _simple_polygon_list.insert(_simple_polygon_list.erase(polygon_it), polygon1); + polygon0_it = _simple_polygon_list.insert(polygon1_it, polygon0); - splitPolygonAtPoint (polygon0_it); - splitPolygonAtPoint (polygon1_it); + splitPolygonAtPoint(polygon0_it); + splitPolygonAtPoint(polygon1_it); return; } - delete [] perm; - delete [] id_vec; + delete[] perm; + delete[] id_vec; } -GEOLIB::Polygon* createPolygonFromCircle (GEOLIB::Point const& middle_pnt, double radius, - std::vector & pnts, size_t resolution) +GEOLIB::Polygon* createPolygonFromCircle(GEOLIB::Point const& middle_pnt, double radius, + std::vector& pnts, size_t resolution) { - const size_t off_set (pnts.size()); + const size_t off_set(pnts.size()); // create points - double angle (2.0 * M_PI / resolution); + double angle(2.0 * M_PI / resolution); for (size_t k(0); k < resolution; k++) { - GEOLIB::Point* pnt (new GEOLIB::Point(middle_pnt.getData())); - (*pnt)[0] += radius * cos (k * angle); - (*pnt)[1] += radius * sin (k * angle); - pnts.push_back (pnt); + GEOLIB::Point* pnt(new GEOLIB::Point(middle_pnt.getData())); + (*pnt)[0] += radius * cos(k * angle); + (*pnt)[1] += radius * sin(k * angle); + pnts.push_back(pnt); } // create polygon - GEOLIB::Polygon* polygon (new GEOLIB::Polygon (pnts, false)); + GEOLIB::Polygon* polygon(new GEOLIB::Polygon(pnts, false)); for (size_t k(0); k < resolution; k++) - polygon->addPoint (k + off_set); - polygon->addPoint (off_set); + polygon->addPoint(k + off_set); + polygon->addPoint(off_set); return polygon; } @@ -462,21 +466,27 @@ bool operator==(Polygon const& lhs, Polygon const& rhs) // search start point of first polygon in second polygon bool nfound(true); size_t k(0); - for (; k < n-1 && nfound; k++) { - if (start_pnt == rhs.getPointID(k)) { + for (; k < n - 1 && nfound; k++) + { + if (start_pnt == rhs.getPointID(k)) + { nfound = false; break; } } // case: start point not found in second polygon - if (nfound) return false; + if (nfound) + return false; // *** determine direction // opposite direction - if (k == n-2) { - for (k=1; k0; j--) { - if (lhs.getPointID(k-2-j) != rhs.getPointID(j)) { + if (lhs.getPointID(1) == rhs.getPointID(k - 1)) + { + size_t j(k - 2); + for (; j > 0; j--) + { + if (lhs.getPointID(k - 2 - j) != rhs.getPointID(j)) + { return false; } } // new start point at second polygon - the point n-1 of a polygon is equal to the // first point of the polygon (for this reason: n-2) - j=n-2; - for (; j>k-1; j--) { - if (lhs.getPointID(n-2+j+k-2) != rhs.getPointID(j)) { + j = n - 2; + for (; j > k - 1; j--) + { + if (lhs.getPointID(n - 2 + j + k - 2) != rhs.getPointID(j)) + { return false; } } return true; - } else { + } + else + { return false; } } diff --git a/GEO/Polygon.h b/GEO/Polygon.h index 9e52a9045..d46f863af 100644 --- a/GEO/Polygon.h +++ b/GEO/Polygon.h @@ -32,7 +32,8 @@ namespace GEOLIB class EdgeType { public: - enum value { + enum value + { TOUCHING, //!< TOUCHING CROSSING, //!< CROSSING INESSENTIAL //!< INESSENTIAL @@ -52,9 +53,9 @@ class Polygon : public Polyline * @param init if true, check if polyline is closed, calculate bounding box * @return */ - Polygon(const Polyline &ply, bool init = true); + Polygon(const Polyline& ply, bool init = true); - Polygon (const std::vector& pnt_vec); + Polygon(const std::vector& pnt_vec); virtual ~Polygon(); @@ -62,7 +63,7 @@ class Polygon : public Polyline * * @return */ - bool initialise (); + bool initialise(); /** * Method checks if the given point is inside the polygon. @@ -70,7 +71,7 @@ class Polygon : public Polyline * @param pnt the Point * @return if point is inside the polygon true, else false */ - bool isPntInPolygon (const GEOLIB::Point& pnt) const; + bool isPntInPolygon(const GEOLIB::Point& pnt) const; /** * wrapper for method isPntInPolygon (const GEOLIB::Point&) * @param x x coordinate of point @@ -78,13 +79,13 @@ class Polygon : public Polyline * @param z z coordinate of point * @return if point is inside the polygon true, else false */ - bool isPntInPolygon (double x, double y, double z) const; + bool isPntInPolygon(double x, double y, double z) const; /** * Method checks if all points of the polyline ply are inside of the polygon. * @param ply the polyline that should be checked * @return */ - bool isPolylineInPolygon (const Polyline& ply) const; + bool isPolylineInPolygon(const Polyline& ply) const; /** * Method checks first if at least one (end!) point of a line segment of the polyline * is inside of the polygon. If this test fails each line segment of the polyline will @@ -92,7 +93,7 @@ class Polygon : public Polyline * @param ply the polyline that should be checked * @return true if a part of the polyline is within the polygon */ - bool isPartOfPolylineInPolygon (const Polyline& ply) const; + bool isPartOfPolylineInPolygon(const Polyline& ply) const; /** * Calculates the next intersection point between the line segment (a,b) and the @@ -102,16 +103,16 @@ class Polygon : public Polyline * @param intersection_pnt (output) next intersection point * @param seg_num (input/output) the number of the polygon segment that is intersecting */ - bool getNextIntersectionPointPolygonLine(GEOLIB::Point const & a, - GEOLIB::Point const & b, - GEOLIB::Point* intersection_pnt, - size_t& seg_num) const; + bool getNextIntersectionPointPolygonLine(GEOLIB::Point const& a, + GEOLIB::Point const& b, + GEOLIB::Point* intersection_pnt, + size_t& seg_num) const; - - void computeListOfSimplePolygons (); - const std::list& getListOfSimplePolygons (); + void computeListOfSimplePolygons(); + const std::list& getListOfSimplePolygons(); friend bool operator==(Polygon const& lhs, Polygon const& rhs); + private: /** * from book: Computational Geometry and Computer Graphics in C++, page 119 @@ -120,13 +121,13 @@ class Polygon : public Polyline * @param pnt point that is edge type computed for * @return a value of enum EdgeType */ - EdgeType::value getEdgeType (size_t k, GEOLIB::Point const & pnt) const; + EdgeType::value getEdgeType(size_t k, GEOLIB::Point const& pnt) const; - void calculateAxisAlignedBoundingBox (); - void ensureCWOrientation (); + void calculateAxisAlignedBoundingBox(); + void ensureCWOrientation(); - void splitPolygonAtIntersection (std::list::iterator polygon_it); - void splitPolygonAtPoint (std::list::iterator polygon_it); + void splitPolygonAtIntersection(std::list::iterator polygon_it); + void splitPolygonAtPoint(std::list::iterator polygon_it); std::list _simple_polygon_list; AABB _aabb; }; @@ -139,10 +140,10 @@ class Polygon : public Polyline * @param resolution number of point to use for approximation * @return a pointer to a polygon */ -GEOLIB::Polygon* createPolygonFromCircle (GEOLIB::Point const& middle_pnt, - double radius, - std::vector & pnts, - size_t resolution = 12); +GEOLIB::Polygon* createPolygonFromCircle(GEOLIB::Point const& middle_pnt, + double radius, + std::vector& pnts, + size_t resolution = 12); /** * comparison operator for polygons diff --git a/GEO/Polyline.cpp b/GEO/Polyline.cpp index d0adc3961..0e15a2561 100644 --- a/GEO/Polyline.cpp +++ b/GEO/Polyline.cpp @@ -21,25 +21,22 @@ namespace GEOLIB { -Polyline::Polyline(const std::vector& pnt_vec) : - GeoObject(), _ply_pnts(pnt_vec) +Polyline::Polyline(const std::vector& pnt_vec) : GeoObject(), _ply_pnts(pnt_vec) { - _length.push_back (0.0); + _length.push_back(0.0); } -Polyline::Polyline(const Polyline& ply) : - GeoObject(), _ply_pnts (ply._ply_pnts) +Polyline::Polyline(const Polyline& ply) : GeoObject(), _ply_pnts(ply._ply_pnts) { for (size_t k(0); k < ply.getNumberOfPoints(); ++k) - _ply_pnt_ids.push_back (ply.getPointID (k)); + _ply_pnt_ids.push_back(ply.getPointID(k)); if (ply.getNumberOfPoints() > 0) for (size_t k(0); k < ply.getNumberOfPoints(); ++k) - _length.push_back (ply.getLength (k)); - + _length.push_back(ply.getLength(k)); } -void Polyline::write(std::ostream &os) const +void Polyline::write(std::ostream& os) const { size_t size(_ply_pnt_ids.size()); for (size_t k(0); k < size; k++) @@ -49,17 +46,17 @@ void Polyline::write(std::ostream &os) const void Polyline::addPoint(size_t pnt_id) { assert(pnt_id < _ply_pnts.size()); - size_t n_pnts (_ply_pnt_ids.size()); + size_t n_pnts(_ply_pnt_ids.size()); _ply_pnt_ids.push_back(pnt_id); - if (n_pnts > 0) { - double act_dist (sqrt(MathLib::sqrDist (_ply_pnts[_ply_pnt_ids[n_pnts - 1]], - _ply_pnts[pnt_id]))); - double dist_until_now (0.0); + if (n_pnts > 0) + { + double act_dist(sqrt(MathLib::sqrDist(_ply_pnts[_ply_pnt_ids[n_pnts - 1]], _ply_pnts[pnt_id]))); + double dist_until_now(0.0); if (n_pnts > 1) dist_until_now = _length[n_pnts - 1]; - _length.push_back (dist_until_now + act_dist); + _length.push_back(dist_until_now + act_dist); } } @@ -71,36 +68,46 @@ void Polyline::insertPoint(size_t pos, size_t pnt_id) std::vector::iterator it(_ply_pnt_ids.begin() + pos); _ply_pnt_ids.insert(it, pnt_id); - if (_ply_pnt_ids.size() > 1) { + if (_ply_pnt_ids.size() > 1) + { // update the _length vector - if (pos == 0) { + if (pos == 0) + { // insert at first position double act_dist(sqrt(MathLib::sqrDist(_ply_pnts[_ply_pnt_ids[1]], _ply_pnts[pnt_id]))); _length.insert(_length.begin(), act_dist); const size_t s(_length.size()); - for (size_t k(1); k 2) dist_until_now = _length[_ply_pnt_ids.size() - 2]; - _length.insert(_length.begin()+pos, dist_until_now + act_dist); - } else { + _length.insert(_length.begin() + pos, dist_until_now + act_dist); + } + else + { // insert at arbitrary position within the vector - double dist_until_now (0.0); - if (pos > 1) { - dist_until_now = _length[pos-2]; + double dist_until_now(0.0); + if (pos > 1) + { + dist_until_now = _length[pos - 2]; } - double len_seg0(sqrt(MathLib::sqrDist(_ply_pnts[_ply_pnt_ids[pos-1]], _ply_pnts[pnt_id]))); - double len_seg1(sqrt(MathLib::sqrDist(_ply_pnts[_ply_pnt_ids[pos+1]], _ply_pnts[pnt_id]))); - _length[pos-1] = dist_until_now + len_seg0; - std::vector::iterator it(_length.begin()+pos); - _length.insert(it, _length[pos-1]+len_seg1); + double len_seg0(sqrt(MathLib::sqrDist(_ply_pnts[_ply_pnt_ids[pos - 1]], _ply_pnts[pnt_id]))); + double len_seg1(sqrt(MathLib::sqrDist(_ply_pnts[_ply_pnt_ids[pos + 1]], _ply_pnts[pnt_id]))); + _length[pos - 1] = dist_until_now + len_seg0; + std::vector::iterator it(_length.begin() + pos); + _length.insert(it, _length[pos - 1] + len_seg1); } } } @@ -123,11 +130,13 @@ bool Polyline::isPointIDInPolyline(size_t pnt_id) const { const size_t n_ply_pnt_ids(_ply_pnt_ids.size()); size_t k(0); - while (k const& Polyline::getPointsVec () const +std::vector const& Polyline::getPointsVec() const { return _ply_pnts; } -double Polyline::getLength (size_t k) const +double Polyline::getLength(size_t k) const { assert(k < _length.size()); return _length[k]; } -const std::vector& Polyline::getLengthVec () const +const std::vector& Polyline::getLengthVec() const { return _length; } -Polyline* Polyline::constructPolylineFromSegments(const std::vector &ply_vec, - double prox) +Polyline* Polyline::constructPolylineFromSegments(const std::vector& ply_vec, double prox) { size_t nLines = ply_vec.size(); @@ -189,16 +197,14 @@ Polyline* Polyline::constructPolylineFromSegments(const std::vector & { bool ply_found(false); prox *= prox; // square distance once to save time later - for (std::vector::iterator it = local_ply_vec.begin(); - it != local_ply_vec.end(); ++it) + for (std::vector::iterator it = local_ply_vec.begin(); it != local_ply_vec.end(); ++it) { if (pnt_vec == (*it)->getPointsVec()) { size_t nPoints((*it)->getNumberOfPoints()); - //if (new_ply->getPointID(0) == (*it)->getPointID(0)) - if (pointsAreIdentical(pnt_vec, new_ply->getPointID(0), - (*it)->getPointID(0), prox)) + // if (new_ply->getPointID(0) == (*it)->getPointID(0)) + if (pointsAreIdentical(pnt_vec, new_ply->getPointID(0), (*it)->getPointID(0), prox)) { Polyline* tmp = new Polyline((*it)->getPointsVec()); for (size_t k = 0; k < nPoints; k++) @@ -211,9 +217,8 @@ Polyline* Polyline::constructPolylineFromSegments(const std::vector & new_ply = tmp; ply_found = true; } - //else if (new_ply->getPointID(0) == (*it)->getPointID(nPoints-1)) - else if (pointsAreIdentical(pnt_vec, new_ply->getPointID(0), - (*it)->getPointID(nPoints - 1), prox)) + // else if (new_ply->getPointID(0) == (*it)->getPointID(nPoints-1)) + else if (pointsAreIdentical(pnt_vec, new_ply->getPointID(0), (*it)->getPointID(nPoints - 1), prox)) { Polyline* tmp = new Polyline(**it); size_t new_ply_size(new_ply->getNumberOfPoints()); @@ -223,22 +228,16 @@ Polyline* Polyline::constructPolylineFromSegments(const std::vector & new_ply = tmp; ply_found = true; } - //else if (new_ply->getPointID(new_ply->getNumberOfPoints()-1) == (*it)->getPointID(0)) - else if (pointsAreIdentical(pnt_vec, - new_ply->getPointID(new_ply-> - getNumberOfPoints() - - 1), + // else if (new_ply->getPointID(new_ply->getNumberOfPoints()-1) == (*it)->getPointID(0)) + else if (pointsAreIdentical(pnt_vec, new_ply->getPointID(new_ply->getNumberOfPoints() - 1), (*it)->getPointID(0), prox)) { for (size_t k = 1; k < nPoints; k++) new_ply->addPoint((*it)->getPointID(k)); ply_found = true; } - //else if (new_ply->getPointID(new_ply->getNumberOfPoints()-1) == (*it)->getPointID(nPoints-1)) - else if (pointsAreIdentical(pnt_vec, - new_ply->getPointID(new_ply-> - getNumberOfPoints() - - 1), + // else if (new_ply->getPointID(new_ply->getNumberOfPoints()-1) == (*it)->getPointID(nPoints-1)) + else if (pointsAreIdentical(pnt_vec, new_ply->getPointID(new_ply->getNumberOfPoints() - 1), (*it)->getPointID(nPoints - 1), prox)) { for (size_t k = 1; k < nPoints; k++) @@ -252,18 +251,15 @@ Polyline* Polyline::constructPolylineFromSegments(const std::vector & } } else - std::cout - << - "Error in Polyline::contructPolylineFromSegments() - Line segments use different point vectors..." - << "\n"; + std::cout << "Error in Polyline::contructPolylineFromSegments() - Line segments use different point " + "vectors..." + << "\n"; } if (!ply_found) { - std::cout - << - "Error in Polyline::contructPolylineFromSegments() - Not all segments are connected..." - << "\n"; + std::cout << "Error in Polyline::contructPolylineFromSegments() - Not all segments are connected..." + << "\n"; new_ply = NULL; break; } @@ -271,14 +267,11 @@ Polyline* Polyline::constructPolylineFromSegments(const std::vector & return new_ply; } -bool Polyline::pointsAreIdentical(const std::vector &pnt_vec, - size_t i, - size_t j, - double prox) +bool Polyline::pointsAreIdentical(const std::vector& pnt_vec, size_t i, size_t j, double prox) { if (i == j) return true; - return MathLib::checkDistance( *pnt_vec[i], *pnt_vec[j], prox ); + return MathLib::checkDistance(*pnt_vec[i], *pnt_vec[j], prox); } Polyline* Polyline::closePolyline(const Polyline& ply) @@ -291,22 +284,21 @@ Polyline* Polyline::closePolyline(const Polyline& ply) new_ply->addPoint(new_ply->getPointID(0)); return new_ply; } - std::cout << - "Error in Polyline::closePolyline() - Input polyline needs to be composed of at least three points..." + std::cout << "Error in Polyline::closePolyline() - Input polyline needs to be composed of at least three points..." << "\n"; return NULL; } -Location::type Polyline::getLocationOfPoint (size_t k, GEOLIB::Point const & pnt) const +Location::type Polyline::getLocationOfPoint(size_t k, GEOLIB::Point const& pnt) const { - assert (k < _ply_pnt_ids.size() - 1); + assert(k < _ply_pnt_ids.size() - 1); - GEOLIB::Point const& source (*(_ply_pnts[_ply_pnt_ids[k]])); - GEOLIB::Point const& dest (*(_ply_pnts[_ply_pnt_ids[k + 1]])); + GEOLIB::Point const& source(*(_ply_pnts[_ply_pnt_ids[k]])); + GEOLIB::Point const& dest(*(_ply_pnts[_ply_pnt_ids[k + 1]])); long double a[2] = {dest[0] - source[0], dest[1] - source[1]}; // vector long double b[2] = {pnt[0] - source[0], pnt[1] - source[1]}; // vector - long double det_2x2 (a[0] * b[1] - a[1] * b[0]); + long double det_2x2(a[0] * b[1] - a[1] * b[0]); if (det_2x2 > std::numeric_limits::epsilon()) return Location::LEFT; @@ -314,22 +306,22 @@ Location::type Polyline::getLocationOfPoint (size_t k, GEOLIB::Point const & pnt return Location::RIGHT; if (a[0] * b[0] < 0.0 || a[1] * b[1] < 0.0) return Location::BEHIND; - if (a[0]*a[0]+a[1]*a[1] < b[0]*b[0]+b[1]*b[1]) + if (a[0] * a[0] + a[1] * a[1] < b[0] * b[0] + b[1] * b[1]) return Location::BEYOND; - if (MathLib::sqrDist (&pnt, _ply_pnts[_ply_pnt_ids[k]]) < sqrt(std::numeric_limits::min())) + if (MathLib::sqrDist(&pnt, _ply_pnts[_ply_pnt_ids[k]]) < sqrt(std::numeric_limits::min())) return Location::SOURCE; - if (MathLib::sqrDist (&pnt, _ply_pnts[_ply_pnt_ids[k + 1]]) < sqrt(std::numeric_limits::min())) + if (MathLib::sqrDist(&pnt, _ply_pnts[_ply_pnt_ids[k + 1]]) < sqrt(std::numeric_limits::min())) return Location::DESTINATION; return Location::BETWEEN; } -std::ostream& operator<< (std::ostream &os, const Polyline &pl) +std::ostream& operator<<(std::ostream& os, const Polyline& pl) { - pl.write (os); + pl.write(os); return os; } -bool containsEdge (const Polyline& ply, size_t id0, size_t id1) +bool containsEdge(const Polyline& ply, size_t id0, size_t id1) { if (id0 == id1) { @@ -337,27 +329,28 @@ bool containsEdge (const Polyline& ply, size_t id0, size_t id1) return false; } if (id0 > id1) - BASELIB::swap (id0,id1); - const size_t n (ply.getNumberOfPoints() - 1); + BASELIB::swap(id0, id1); + const size_t n(ply.getNumberOfPoints() - 1); for (size_t k(0); k < n; k++) { - size_t ply_pnt0 (ply.getPointID (k)); - size_t ply_pnt1 (ply.getPointID (k + 1)); + size_t ply_pnt0(ply.getPointID(k)); + size_t ply_pnt1(ply.getPointID(k + 1)); if (ply_pnt0 > ply_pnt1) - BASELIB::swap (ply_pnt0, ply_pnt1); + BASELIB::swap(ply_pnt0, ply_pnt1); if (ply_pnt0 == id0 && ply_pnt1 == id1) return true; } return false; } -bool isLineSegmentIntersecting (const Polyline& ply, GEOLIB::Point const& s0, GEOLIB::Point const& s1) +bool isLineSegmentIntersecting(const Polyline& ply, GEOLIB::Point const& s0, GEOLIB::Point const& s1) { - const size_t n (ply.getNumberOfPoints() - 1); + const size_t n(ply.getNumberOfPoints() - 1); bool intersect(false); GEOLIB::Point intersection_pnt; - for (size_t k(0); k < n && !intersect; k++) { - intersect = MathLib::lineSegmentIntersect (*(ply.getPoint(k)), *(ply.getPoint(k+1)), s0, s1, intersection_pnt); + for (size_t k(0); k < n && !intersect; k++) + { + intersect = MathLib::lineSegmentIntersect(*(ply.getPoint(k)), *(ply.getPoint(k + 1)), s0, s1, intersection_pnt); } return intersect; } @@ -368,7 +361,8 @@ bool operator==(Polyline const& lhs, Polyline const& rhs) return false; const size_t n(lhs.getNumberOfPoints()); - for (size_t k(0); k &ply_vec, - double prox = 0.0); + static Polyline* constructPolylineFromSegments(const std::vector& ply_vec, double prox = 0.0); /** * returns the number of points, @@ -132,22 +131,23 @@ class Polyline : public GeoObject * */ const Point* getPoint(size_t i) const; - std::vector const& getPointsVec () const; + std::vector const& getPointsVec() const; /** * returns the length of the polyline until the k-th line segment * @param k the k-th line segment * @return the length of the polyline until the k-th line segment */ - double getLength (size_t k) const; + double getLength(size_t k) const; /** * get the complete length vector * @return the length vector of the polyline */ - const std::vector& getLengthVec () const; + const std::vector& getLengthVec() const; friend bool operator==(Polyline const& lhs, Polyline const& rhs); + protected: /** * 2D method - ignores z coordinate. It calculates the location @@ -158,15 +158,12 @@ class Polyline : public GeoObject * @param pnt the point * @return a value of enum LOCATION */ - Location::type getLocationOfPoint (size_t k, GEOLIB::Point const & pnt) const; + Location::type getLocationOfPoint(size_t k, GEOLIB::Point const& pnt) const; - static bool pointsAreIdentical(const std::vector &pnt_vec, - size_t i, - size_t j, - double prox); + static bool pointsAreIdentical(const std::vector& pnt_vec, size_t i, size_t j, double prox); /** a reference to the vector of pointers to the geometric points */ - const std::vector &_ply_pnts; + const std::vector& _ply_pnts; /** position of pointers to the geometric points */ std::vector _ply_pnt_ids; /** @@ -176,11 +173,11 @@ class Polyline : public GeoObject }; /** overload the output operator for class Polyline */ -std::ostream& operator<< (std::ostream &os, Polyline const& pl); +std::ostream& operator<<(std::ostream& os, Polyline const& pl); -bool containsEdge (const Polyline& ply, size_t id0, size_t id1); +bool containsEdge(const Polyline& ply, size_t id0, size_t id1); -bool isLineSegmentIntersecting (const Polyline& ply, GEOLIB::Point const& s0, GEOLIB::Point const& s1); +bool isLineSegmentIntersecting(const Polyline& ply, GEOLIB::Point const& s0, GEOLIB::Point const& s1); /** * comparison operator diff --git a/GEO/PolylineWithSegmentMarker.cpp b/GEO/PolylineWithSegmentMarker.cpp index 96a6907fa..d5641da64 100644 --- a/GEO/PolylineWithSegmentMarker.cpp +++ b/GEO/PolylineWithSegmentMarker.cpp @@ -12,21 +12,21 @@ #include "PolylineWithSegmentMarker.h" -namespace GEOLIB { - -PolylineWithSegmentMarker::PolylineWithSegmentMarker(GEOLIB::Polyline const& polyline) - : GEOLIB::Polyline(polyline) +namespace GEOLIB +{ +PolylineWithSegmentMarker::PolylineWithSegmentMarker(GEOLIB::Polyline const& polyline) : GEOLIB::Polyline(polyline) { const size_t n_pnts(getNumberOfPoints()); _marker.resize(n_pnts); - for (size_t k(0); k _marker; }; - } #endif /* POLYLINEWITHSEGMENTMARKER_H_ */ diff --git a/GEO/ProjectData.cpp b/GEO/ProjectData.cpp old mode 100755 new mode 100644 index 497a4fc80..82853547a --- a/GEO/ProjectData.cpp +++ b/GEO/ProjectData.cpp @@ -11,42 +11,42 @@ #include "ProjectData.h" #include "StringTools.h" -ProjectData::ProjectData() -: _geoObjects (NULL) -{} +ProjectData::ProjectData() : _geoObjects(NULL) +{ +} ProjectData::~ProjectData() { delete _geoObjects; - for (std::map::iterator it = _msh_vec.begin(); - it != _msh_vec.end(); ++it) + for (std::map::iterator it = _msh_vec.begin(); it != _msh_vec.end(); ++it) delete it->second; - size_t nCond (_cond_vec.size()); + size_t nCond(_cond_vec.size()); for (size_t i = 0; i < nCond; i++) delete _cond_vec[i]; } -void ProjectData::addMesh(MeshLib::CFEMesh* mesh, std::string &name) +void ProjectData::addMesh(MeshLib::CFEMesh* mesh, std::string& name) { isUniqueMeshName(name); _msh_vec[name] = mesh; } -const MeshLib::CFEMesh* ProjectData::getMesh(const std::string &name) const +const MeshLib::CFEMesh* ProjectData::getMesh(const std::string& name) const { return _msh_vec.find(name)->second; } -bool ProjectData::removeMesh(const std::string &name) +bool ProjectData::removeMesh(const std::string& name) { delete _msh_vec[name]; size_t result = _msh_vec.erase(name); return result > 0; } -bool ProjectData::meshExists(const std::string &name) +bool ProjectData::meshExists(const std::string& name) { - if (_msh_vec.count(name)>0) return true; + if (_msh_vec.count(name) > 0) + return true; return false; } @@ -56,7 +56,8 @@ void ProjectData::addProcess(ProcessInfo* pcs) if ((*it)->getProcessType() == pcs->getProcessType()) { std::cout << "Error in ProjectData::addProcess() - " - << FiniteElement::convertProcessTypeToString(pcs->getProcessType()) << " process already exists." << "\n"; + << FiniteElement::convertProcessTypeToString(pcs->getProcessType()) << " process already exists." + << "\n"; } _pcs_vec.push_back(pcs); @@ -68,8 +69,9 @@ const ProcessInfo* ProjectData::getProcess(FiniteElement::ProcessType type) cons if ((*it)->getProcessType() == type) return *it; - std::cout << "Error in ProjectData::getProcess() - No " - << FiniteElement::convertProcessTypeToString(type) << " process found..." << "\n"; + std::cout << "Error in ProjectData::getProcess() - No " << FiniteElement::convertProcessTypeToString(type) + << " process found..." + << "\n"; return NULL; } @@ -78,14 +80,14 @@ bool ProjectData::removeProcess(FiniteElement::ProcessType type) for (std::vector::iterator it = _pcs_vec.begin(); it != _pcs_vec.end(); ++it) if ((*it)->getProcessType() == type) { - delete *it; _pcs_vec.erase(it); return true; } - std::cout << "Error in ProjectData::removeProcess() - No " - << FiniteElement::convertProcessTypeToString(type) << " process found..." << "\n"; + std::cout << "Error in ProjectData::removeProcess() - No " << FiniteElement::convertProcessTypeToString(type) + << " process found..." + << "\n"; return false; } @@ -100,23 +102,22 @@ void ProjectData::addConditions(std::vector conds) _cond_vec.push_back(conds[i]); } -const FEMCondition* ProjectData::getCondition(const std::string &geo_name, +const FEMCondition* ProjectData::getCondition(const std::string& geo_name, GEOLIB::GEOTYPE type, - const std::string &cond_name) const + const std::string& cond_name) const { for (std::vector::const_iterator it = _cond_vec.begin(); it != _cond_vec.end(); ++it) if ((*it)->getAssociatedGeometryName().compare(geo_name) == 0) - if ( ((*it)->getGeoName().compare(cond_name) == 0) && - ((*it)->getGeoType() == type) ) + if (((*it)->getGeoName().compare(cond_name) == 0) && ((*it)->getGeoType() == type)) return *it; - std::cout << "Error in ProjectData::getCondition() - No condition found with name \"" << - cond_name << "\"..." << "\n"; + std::cout << "Error in ProjectData::getCondition() - No condition found with name \"" << cond_name << "\"..." + << "\n"; return NULL; } const std::vector ProjectData::getConditions(FiniteElement::ProcessType pcs_type, - std::string geo_name, + std::string geo_name, FEMCondition::CondType cond_type) const { // if all @@ -127,31 +128,34 @@ const std::vector ProjectData::getConditions(FiniteElement::Proce std::vector conds; for (std::vector::const_iterator it = _cond_vec.begin(); it != _cond_vec.end(); ++it) { - if ( ((pcs_type == FiniteElement::INVALID_PROCESS) || (pcs_type == ((*it)->getProcessType()))) && - ((geo_name.empty() || ((*it)->getAssociatedGeometryName().compare(geo_name) == 0))) && - ((cond_type == FEMCondition::UNSPECIFIED) || ((*it)->getCondType() == cond_type)) ) - conds.push_back(*it); + if (((pcs_type == FiniteElement::INVALID_PROCESS) || (pcs_type == ((*it)->getProcessType()))) + && ((geo_name.empty() || ((*it)->getAssociatedGeometryName().compare(geo_name) == 0))) + && ((cond_type == FEMCondition::UNSPECIFIED) || ((*it)->getCondType() == cond_type))) + conds.push_back(*it); } return conds; } -void ProjectData::removeConditions(FiniteElement::ProcessType pcs_type, std::string geo_name, FEMCondition::CondType cond_type) +void ProjectData::removeConditions(FiniteElement::ProcessType pcs_type, + std::string geo_name, + FEMCondition::CondType cond_type) { // if all if (pcs_type == FiniteElement::INVALID_PROCESS && geo_name.empty() && cond_type == FEMCondition::UNSPECIFIED) { - for (size_t i=0; i<_cond_vec.size(); i++) delete _cond_vec[i]; + for (size_t i = 0; i < _cond_vec.size(); i++) + delete _cond_vec[i]; _cond_vec.clear(); return; } // else: filter according to parameters - for (std::vector::iterator it = _cond_vec.begin(); it != _cond_vec.end(); ) + for (std::vector::iterator it = _cond_vec.begin(); it != _cond_vec.end();) { - if ( ((pcs_type == FiniteElement::INVALID_PROCESS) || (pcs_type == ((*it)->getProcessType()))) && - ((geo_name.empty() || ((*it)->getAssociatedGeometryName().compare(geo_name) == 0))) && - ((cond_type == FEMCondition::UNSPECIFIED) || ((*it)->getCondType() == cond_type)) ) + if (((pcs_type == FiniteElement::INVALID_PROCESS) || (pcs_type == ((*it)->getProcessType()))) + && ((geo_name.empty() || ((*it)->getAssociatedGeometryName().compare(geo_name) == 0))) + && ((cond_type == FEMCondition::UNSPECIFIED) || ((*it)->getCondType() == cond_type))) { delete *it; it = _cond_vec.erase(it); @@ -161,27 +165,24 @@ void ProjectData::removeConditions(FiniteElement::ProcessType pcs_type, std::str } } -bool ProjectData::removeCondition(const std::string &geo_name, - GEOLIB::GEOTYPE type, - const std::string &cond_name) +bool ProjectData::removeCondition(const std::string& geo_name, GEOLIB::GEOTYPE type, const std::string& cond_name) { for (std::vector::iterator it = _cond_vec.begin(); it != _cond_vec.end(); ++it) { if ((*it)->getAssociatedGeometryName().compare(geo_name) == 0) - if ( ((*it)->getGeoName().compare(cond_name) == 0) && - ((*it)->getGeoType() == type) ) + if (((*it)->getGeoName().compare(cond_name) == 0) && ((*it)->getGeoType() == type)) { delete *it; _cond_vec.erase(it); return true; } } - std::cout << "Error in ProjectData::removeCondition() - No condition found with name \"" << - cond_name << "\"..." << "\n"; + std::cout << "Error in ProjectData::removeCondition() - No condition found with name \"" << cond_name << "\"..." + << "\n"; return false; } -bool ProjectData::isUniqueMeshName(std::string &name) +bool ProjectData::isUniqueMeshName(std::string& name) { int count(0); bool isUnique(false); @@ -198,9 +199,8 @@ bool ProjectData::isUniqueMeshName(std::string &name) if (count > 1) cpName = cpName + "-" + number2str(count); - for (std::map::iterator it = _msh_vec.begin(); - it != _msh_vec.end(); ++it) - if ( cpName.compare(it->first) == 0 ) + for (std::map::iterator it = _msh_vec.begin(); it != _msh_vec.end(); ++it) + if (cpName.compare(it->first) == 0) isUnique = false; } diff --git a/GEO/ProjectData.h b/GEO/ProjectData.h index 6a1389ece..3f5ca710a 100644 --- a/GEO/ProjectData.h +++ b/GEO/ProjectData.h @@ -36,28 +36,25 @@ class ProjectData // Returns the GEOObjects containing all points, polylines and surfaces GEOLIB::GEOObjects* getGEOObjects() { return _geoObjects; } - // Returns the GEOObjects containing all points, polylines and surfaces void setGEOObjects(GEOLIB::GEOObjects* geo_objects) { _geoObjects = geo_objects; } - //** Mesh functionality **// /// Adds a new mesh - virtual void addMesh(MeshLib::CFEMesh* mesh, std::string &name); + virtual void addMesh(MeshLib::CFEMesh* mesh, std::string& name); /// Returns the mesh with the given name. - const MeshLib::CFEMesh* getMesh(const std::string &name) const; + const MeshLib::CFEMesh* getMesh(const std::string& name) const; /// Returns all the meshes with their respective names const std::map& getMeshObjects() const { return _msh_vec; } - /// Removes the mesh with the given name. - virtual bool removeMesh(const std::string &name); + virtual bool removeMesh(const std::string& name); /// Checks if the name of the mesh is already exists, if so it generates a unique name. - bool isUniqueMeshName(std::string &name); + bool isUniqueMeshName(std::string& name); - bool meshExists(const std::string &name); + bool meshExists(const std::string& name); //** Process functionality **// @@ -79,24 +76,22 @@ class ProjectData virtual void addConditions(std::vector conds); /// Returns the FEM Condition set on a GeoObject with the given name and type from a certain geometry. - const FEMCondition* getCondition(const std::string &geo_name, + const FEMCondition* getCondition(const std::string& geo_name, GEOLIB::GEOTYPE type, - const std::string &cond_name) const; + const std::string& cond_name) const; /// Returns all FEM Conditions with the given type from a certain geometry. const std::vector getConditions(FiniteElement::ProcessType pcs_type = FiniteElement::INVALID_PROCESS, - std::string geo_name = "", - FEMCondition::CondType type = FEMCondition::UNSPECIFIED) const; + std::string geo_name = "", + FEMCondition::CondType type = FEMCondition::UNSPECIFIED) const; /// Removes the FEM Condition set on a GeoObject with the given name and type from a certain geometry. - virtual bool removeCondition(const std::string &geo_name, - GEOLIB::GEOTYPE type, - const std::string &cond_name); + virtual bool removeCondition(const std::string& geo_name, GEOLIB::GEOTYPE type, const std::string& cond_name); /// Removes all FEM Conditions with the given type from the given process virtual void removeConditions(FiniteElement::ProcessType pcs_type = FiniteElement::INVALID_PROCESS, - std::string geo_name = "", - FEMCondition::CondType cond_type = FEMCondition::UNSPECIFIED); + std::string geo_name = "", + FEMCondition::CondType cond_type = FEMCondition::UNSPECIFIED); private: GEOLIB::GEOObjects* _geoObjects; @@ -105,4 +100,4 @@ class ProjectData std::vector _cond_vec; }; -#endif //PROJECTDATA_H_ +#endif // PROJECTDATA_H_ diff --git a/GEO/PropertyBounds.h b/GEO/PropertyBounds.h index d7a5a88c0..d76e2cb4e 100644 --- a/GEO/PropertyBounds.h +++ b/GEO/PropertyBounds.h @@ -16,20 +16,16 @@ class PropertyBounds { public: - PropertyBounds(std::string pname, double minVal, - double maxVal ) : _name(pname), _minVal(minVal), _maxVal(maxVal) {} - + PropertyBounds(std::string pname, double minVal, double maxVal) : _name(pname), _minVal(minVal), _maxVal(maxVal) {} std::string getName() const { return _name; } double getMin() const { return _minVal; } double getMax() const { return _maxVal; } - void setMin(double val) { _minVal = val; } void setMax(double val) { _maxVal = val; } - private: std::string _name; double _minVal; double _maxVal; }; -#endif //PROPERTYBOUNDS_H +#endif // PROPERTYBOUNDS_H diff --git a/GEO/QuadTree.h b/GEO/QuadTree.h index b1e6fd76f..f4adea4ae 100644 --- a/GEO/QuadTree.h +++ b/GEO/QuadTree.h @@ -28,10 +28,12 @@ namespace GEOLIB * the access to its coordinates via operator[] and for debugging * purposes operator<<) */ -template class QuadTree +template +class QuadTree { public: - enum Quadrant { + enum Quadrant + { NE = 0, //!< north east NW, //!< north west SW, //!< south west @@ -43,11 +45,10 @@ template class QuadTree * @param ll lower left point of the square * @param ur upper right point of the square */ - QuadTree(POINT const& ll, POINT const& ur, size_t max_points_per_node) : - _father (NULL), _ll (ll), _ur (ur), _depth (0), _is_leaf (true), - _max_points_per_node (max_points_per_node) + QuadTree(POINT const& ll, POINT const& ur, size_t max_points_per_node) + : _father(NULL), _ll(ll), _ur(ur), _depth(0), _is_leaf(true), _max_points_per_node(max_points_per_node) { - assert (_max_points_per_node > 0); + assert(_max_points_per_node > 0); // init childs for (size_t k(0); k < 4; k++) @@ -58,8 +59,8 @@ template class QuadTree else _ur[0] = _ll[0] + _ur[1] - _ll[1]; //#ifndef NDEBUG -// std::cerr << "lower left: " << _ll << ", upper right: " << _ur << ", depth " << _depth << "\n"; -//#endif + // std::cerr << "lower left: " << _ll << ", upper right: " << _ur << ", depth " << _depth << "\n"; + //#endif } /** @@ -78,34 +79,39 @@ template class QuadTree * @param pnt the point * @return If the point can be inserted the method returns true, else false. */ - bool addPoint (POINT const* pnt) + bool addPoint(POINT const* pnt) { - if ((*pnt)[0] < _ll[0]) return false; - if ((*pnt)[0] > _ur[0]) return false; - if ((*pnt)[1] < _ll[1]) return false; - if ((*pnt)[1] > _ur[1]) return false; + if ((*pnt)[0] < _ll[0]) + return false; + if ((*pnt)[0] > _ur[0]) + return false; + if ((*pnt)[1] < _ll[1]) + return false; + if ((*pnt)[1] > _ur[1]) + return false; if (!_is_leaf) for (size_t k(0); k < 4; k++) - if (_childs[k]->addPoint (pnt)) + if (_childs[k]->addPoint(pnt)) return true; // check if point is already in quadtree - bool pnt_in_quadtree (false); - for (size_t k(0); k < _pnts.size() && !pnt_in_quadtree; k++) { + bool pnt_in_quadtree(false); + for (size_t k(0); k < _pnts.size() && !pnt_in_quadtree; k++) + { const double v0((*(_pnts[k]))[0] - (*pnt)[0]); const double v1((*(_pnts[k]))[1] - (*pnt)[1]); - const double sqr_dist (v0*v0 + v1*v1); + const double sqr_dist(v0 * v0 + v1 * v1); if (sqr_dist < std::numeric_limits::epsilon()) pnt_in_quadtree = true; } if (!pnt_in_quadtree) - _pnts.push_back (pnt); + _pnts.push_back(pnt); else return false; - if (_pnts.size () > _max_points_per_node) - splitNode (); + if (_pnts.size() > _max_points_per_node) + splitNode(); return true; } @@ -116,53 +122,52 @@ template class QuadTree * improve the mesh quality. The balance method should be used after * inserting all points. */ - void balance () + void balance() { std::list*> leaf_list; - getLeafs (leaf_list); + getLeafs(leaf_list); while (!leaf_list.empty()) { - QuadTree* node (leaf_list.front()); - leaf_list.pop_front (); + QuadTree* node(leaf_list.front()); + leaf_list.pop_front(); if (node->isLeaf()) - if (needToRefine (node)) + if (needToRefine(node)) { - node->splitNode (); - leaf_list.push_back (node->getChild(NE)); - leaf_list.push_back (node->getChild(NW)); - leaf_list.push_back (node->getChild(SW)); - leaf_list.push_back (node->getChild(SE)); + node->splitNode(); + leaf_list.push_back(node->getChild(NE)); + leaf_list.push_back(node->getChild(NW)); + leaf_list.push_back(node->getChild(SW)); + leaf_list.push_back(node->getChild(SE)); // check if north neighbor has to be refined - QuadTree* north_neighbor (node->getNorthNeighbor()); + QuadTree* north_neighbor(node->getNorthNeighbor()); if (north_neighbor != NULL) - if (north_neighbor->getDepth() < node->getDepth ()) + if (north_neighbor->getDepth() < node->getDepth()) if (north_neighbor->isLeaf()) - leaf_list.push_back (north_neighbor); + leaf_list.push_back(north_neighbor); // check if west neighbor has to be refined - QuadTree* west_neighbor (node->getWestNeighbor()); + QuadTree* west_neighbor(node->getWestNeighbor()); if (west_neighbor != NULL) - if (west_neighbor->getDepth() < node->getDepth ()) + if (west_neighbor->getDepth() < node->getDepth()) if (west_neighbor->isLeaf()) - leaf_list.push_back (west_neighbor); + leaf_list.push_back(west_neighbor); // check if south neighbor has to be refined - QuadTree* south_neighbor (node->getSouthNeighbor()); + QuadTree* south_neighbor(node->getSouthNeighbor()); if (south_neighbor != NULL) - if (south_neighbor->getDepth() < node->getDepth ()) + if (south_neighbor->getDepth() < node->getDepth()) if (south_neighbor->isLeaf()) - leaf_list.push_back (south_neighbor); + leaf_list.push_back(south_neighbor); // check if east neighbor has to be refined - QuadTree* east_neighbor (node->getEastNeighbor()); + QuadTree* east_neighbor(node->getEastNeighbor()); if (east_neighbor != NULL) - if (east_neighbor->getDepth() < node->getDepth ()) + if (east_neighbor->getDepth() < node->getDepth()) if (east_neighbor->isLeaf()) - leaf_list.push_back (east_neighbor); - + leaf_list.push_back(east_neighbor); } } } @@ -171,25 +176,23 @@ template class QuadTree * add all leafs of the quadtree to the list * @param leaf_list list of leafs */ - void getLeafs (std::list*>& leaf_list) + void getLeafs(std::list*>& leaf_list) { if (_is_leaf) - leaf_list.push_back (this); + leaf_list.push_back(this); else for (size_t k(0); k < 4; k++) - _childs[k]->getLeafs (leaf_list); - + _childs[k]->getLeafs(leaf_list); } - const std::vector& getPoints () const { return _pnts; } - - void getSquarePoints (POINT& ll, POINT& ur) const + const std::vector& getPoints() const { return _pnts; } + void getSquarePoints(POINT& ll, POINT& ur) const { ll = _ll; ur = _ur; } - void getLeaf (const POINT& pnt, POINT& ll, POINT& ur) + void getLeaf(const POINT& pnt, POINT& ll, POINT& ur) { if (this->isLeaf()) { @@ -201,42 +204,36 @@ template class QuadTree if (pnt[0] <= 0.5 * (_ur[0] + _ll[0])) // WEST { if (pnt[1] <= 0.5 * (_ur[1] + _ll[1])) // SOUTH - _childs[SW]->getLeaf (pnt, ll, ur); + _childs[SW]->getLeaf(pnt, ll, ur); else // NORTH - _childs[NW]->getLeaf (pnt, ll, ur); + _childs[NW]->getLeaf(pnt, ll, ur); } else // EAST { if (pnt[1] <= 0.5 * (_ur[1] + _ll[1])) // SOUTH - _childs[SE]->getLeaf (pnt, ll, ur); + _childs[SE]->getLeaf(pnt, ll, ur); else // NORTH - _childs[NE]->getLeaf (pnt, ll, ur); + _childs[NE]->getLeaf(pnt, ll, ur); } } } - QuadTree const* getFather () - { - return _father; - } - - QuadTree const* getChild (Quadrant quadrant) const - { - return _childs[quadrant]; - } - + QuadTree const* getFather() { return _father; } + QuadTree const* getChild(Quadrant quadrant) const { return _childs[quadrant]; } /** * Method calculates the maximum depth of the QuadTree instance. It is used within * the method GMSHAdaptiveMeshDensity::getSteinerPoints(). * @param max_depth (input/output) at the entry max_depth contains the maximum depth up to now */ - void getMaxDepth (size_t &max_depth) const + void getMaxDepth(size_t& max_depth) const { if (max_depth < _depth) max_depth = _depth; - for (size_t k(0); k<4; k++) { - if (_childs[k]) { + for (size_t k(0); k < 4; k++) + { + if (_childs[k]) + { _childs[k]->getMaxDepth(max_depth); } } @@ -246,108 +243,103 @@ template class QuadTree * Method returns the depth of the current QuadTree node. * @return the depth of the current QuadTree node */ - size_t getDepth () const { return _depth; } - + size_t getDepth() const { return _depth; } private: - QuadTree* getChild (Quadrant quadrant) + QuadTree* getChild(Quadrant quadrant) { return _childs[quadrant]; } + bool isLeaf() const { return _is_leaf; } + bool isChild(QuadTree const* const tree, Quadrant quadrant) const { - return _childs[quadrant]; - } - - bool isLeaf () const { return _is_leaf; } - - bool isChild (QuadTree const* const tree, Quadrant quadrant) const - { - if (_childs[quadrant] == tree) return true; + if (_childs[quadrant] == tree) + return true; return false; } - QuadTree* getNorthNeighbor () const + QuadTree* getNorthNeighbor() const { if (this->_father == NULL) // root of QuadTree return NULL; - if (this->_father->isChild (this, SW)) - return this->_father->getChild (NW); - if (this->_father->isChild (this, SE)) - return this->_father->getChild (NE); + if (this->_father->isChild(this, SW)) + return this->_father->getChild(NW); + if (this->_father->isChild(this, SE)) + return this->_father->getChild(NE); - QuadTree* north_neighbor (this->_father->getNorthNeighbor ()); + QuadTree* north_neighbor(this->_father->getNorthNeighbor()); if (north_neighbor == NULL) return NULL; if (north_neighbor->isLeaf()) return north_neighbor; - if (this->_father->isChild (this, NW)) - return north_neighbor->getChild (SW); + if (this->_father->isChild(this, NW)) + return north_neighbor->getChild(SW); else - return north_neighbor->getChild (SE); + return north_neighbor->getChild(SE); } - QuadTree* getSouthNeighbor () const + QuadTree* getSouthNeighbor() const { if (this->_father == NULL) // root of QuadTree return NULL; - if (this->_father->isChild (this, NW)) - return this->_father->getChild (SW); - if (this->_father->isChild (this, NE)) - return this->_father->getChild (SE); + if (this->_father->isChild(this, NW)) + return this->_father->getChild(SW); + if (this->_father->isChild(this, NE)) + return this->_father->getChild(SE); - QuadTree* south_neighbor (this->_father->getSouthNeighbor ()); + QuadTree* south_neighbor(this->_father->getSouthNeighbor()); if (south_neighbor == NULL) return NULL; if (south_neighbor->isLeaf()) return south_neighbor; - if (this->_father->isChild (this, SW)) - return south_neighbor->getChild (NW); + if (this->_father->isChild(this, SW)) + return south_neighbor->getChild(NW); else - return south_neighbor->getChild (NE); + return south_neighbor->getChild(NE); } - QuadTree* getEastNeighbor () const + QuadTree* getEastNeighbor() const { if (this->_father == NULL) // root of QuadTree return NULL; - if (this->_father->isChild (this, NW)) - return this->_father->getChild (NE); - if (this->_father->isChild (this, SW)) - return this->_father->getChild (SE); + if (this->_father->isChild(this, NW)) + return this->_father->getChild(NE); + if (this->_father->isChild(this, SW)) + return this->_father->getChild(SE); - QuadTree* east_neighbor (this->_father->getEastNeighbor ()); + QuadTree* east_neighbor(this->_father->getEastNeighbor()); if (east_neighbor == NULL) return NULL; if (east_neighbor->isLeaf()) return east_neighbor; - if (this->_father->isChild (this, SE)) - return east_neighbor->getChild (SW); + if (this->_father->isChild(this, SE)) + return east_neighbor->getChild(SW); else - return east_neighbor->getChild (NW); + return east_neighbor->getChild(NW); } - QuadTree* getWestNeighbor () const + QuadTree* getWestNeighbor() const { if (this->_father == NULL) // root of QuadTree return NULL; - if (this->_father->isChild (this, NE)) - return this->_father->getChild (NW); - if (this->_father->isChild (this, SE)) - return this->_father->getChild (SW); + if (this->_father->isChild(this, NE)) + return this->_father->getChild(NW); + if (this->_father->isChild(this, SE)) + return this->_father->getChild(SW); - QuadTree* west_neighbor (this->_father->getWestNeighbor ()); + QuadTree* west_neighbor(this->_father->getWestNeighbor()); if (west_neighbor == NULL) return NULL; if (west_neighbor->isLeaf()) return west_neighbor; - if (this->_father->isChild (this, SW)) - return west_neighbor->getChild (SE); + if (this->_father->isChild(this, SW)) + return west_neighbor->getChild(SE); else - return west_neighbor->getChild (NE); + return west_neighbor->getChild(NE); } /** @@ -358,55 +350,51 @@ template class QuadTree * @param depth depth of the node * @return */ - QuadTree (POINT const& ll, - POINT const& ur, - QuadTree* father, - size_t depth, - size_t max_points_per_node) : - _father (father), _ll (ll), _ur (ur), _depth (depth), _is_leaf (true), - _max_points_per_node (max_points_per_node) + QuadTree(POINT const& ll, POINT const& ur, QuadTree* father, size_t depth, size_t max_points_per_node) + : _father(father), _ll(ll), _ur(ur), _depth(depth), _is_leaf(true), _max_points_per_node(max_points_per_node) { // init childs for (size_t k(0); k < 4; k++) _childs[k] = NULL; } - void splitNode () + void splitNode() { // create childs POINT mid_point(_ll); mid_point[0] += (_ur[0] - _ll[0]) / 2.0; mid_point[1] += (_ur[1] - _ll[1]) / 2.0; - _childs[0] = new QuadTree (mid_point, _ur, this, _depth + 1, _max_points_per_node); // north east + _childs[0] = new QuadTree(mid_point, _ur, this, _depth + 1, _max_points_per_node); // north east POINT h_ll(mid_point), h_ur(mid_point); h_ll[0] = _ll[0]; h_ur[1] = _ur[1]; - _childs[1] = new QuadTree (h_ll, h_ur, this, _depth + 1, _max_points_per_node); // north west - _childs[2] = new QuadTree (_ll, mid_point, this, _depth + 1, _max_points_per_node); // south west + _childs[1] = new QuadTree(h_ll, h_ur, this, _depth + 1, _max_points_per_node); // north west + _childs[2] = new QuadTree(_ll, mid_point, this, _depth + 1, _max_points_per_node); // south west h_ll = _ll; h_ll[0] = mid_point[0]; h_ur = _ur; h_ur[1] = mid_point[1]; - _childs[3] = new QuadTree (h_ll, h_ur, this, _depth + 1, _max_points_per_node); // south east + _childs[3] = new QuadTree(h_ll, h_ur, this, _depth + 1, _max_points_per_node); // south east // distribute points to sub quadtrees - for (size_t j(0); j < _pnts.size(); j++) { + for (size_t j(0); j < _pnts.size(); j++) + { bool nfound(true); for (size_t k(0); k < 4 && nfound; k++) - if (_childs[k]->addPoint(_pnts[j])) nfound = false; - + if (_childs[k]->addPoint(_pnts[j])) + nfound = false; } _pnts.clear(); _is_leaf = false; } - bool needToRefine (QuadTree* node) + bool needToRefine(QuadTree* node) { - QuadTree* north_neighbor (node->getNorthNeighbor ()); + QuadTree* north_neighbor(node->getNorthNeighbor()); if (north_neighbor != NULL) { if (north_neighbor->getDepth() == node->getDepth()) - if (!north_neighbor->isLeaf ()) + if (!north_neighbor->isLeaf()) { if (!(north_neighbor->getChild(SW))->isLeaf()) return true; @@ -415,11 +403,11 @@ template class QuadTree } } - QuadTree* west_neighbor (node->getWestNeighbor ()); + QuadTree* west_neighbor(node->getWestNeighbor()); if (west_neighbor != NULL) { if (west_neighbor->getDepth() == node->getDepth()) - if (!west_neighbor->isLeaf ()) + if (!west_neighbor->isLeaf()) { if (!(west_neighbor->getChild(SE))->isLeaf()) return true; @@ -428,7 +416,7 @@ template class QuadTree } } - QuadTree* south_neighbor (node->getSouthNeighbor ()); + QuadTree* south_neighbor(node->getSouthNeighbor()); if (south_neighbor != NULL) { if (south_neighbor->getDepth() == node->getDepth()) @@ -441,11 +429,11 @@ template class QuadTree } } - QuadTree* east_neighbor (node->getEastNeighbor ()); + QuadTree* east_neighbor(node->getEastNeighbor()); if (east_neighbor != NULL) { if (east_neighbor->getDepth() == node->getDepth()) - if (!east_neighbor->isLeaf ()) + if (!east_neighbor->isLeaf()) { if (!(east_neighbor->getChild(NW))->isLeaf()) return true; diff --git a/GEO/Raster.cpp b/GEO/Raster.cpp index d8d0e1e87..1da59c8ee 100644 --- a/GEO/Raster.cpp +++ b/GEO/Raster.cpp @@ -14,8 +14,7 @@ namespace GEOLIB { -Raster::Raster(double cell_size, double no_data_val) : - _cell_size(cell_size), _no_data_val(no_data_val) +Raster::Raster(double cell_size, double no_data_val) : _cell_size(cell_size), _no_data_val(no_data_val) { } @@ -24,39 +23,37 @@ void Raster::setCellSize(double cell_size) _cell_size = cell_size; } -void Raster::setNoDataVal (double no_data_val) +void Raster::setNoDataVal(double no_data_val) { _no_data_val = no_data_val; } -double* Raster::getRasterFromSurface(Surface const& sfc, size_t &n_x_pnts, size_t &n_y_pnts) const +double* Raster::getRasterFromSurface(Surface const& sfc, size_t& n_x_pnts, size_t& n_y_pnts) const { - Point const& ll (sfc.getAABB().getMinPoint()); - Point const& ur (sfc.getAABB().getMaxPoint()); + Point const& ll(sfc.getAABB().getMinPoint()); + Point const& ur(sfc.getAABB().getMaxPoint()); n_x_pnts = static_cast(fabs(ur[0] - ll[0]) / _cell_size) + 1; n_y_pnts = static_cast(fabs(ur[1] - ll[1]) / _cell_size) + 1; - const size_t n_triangles (sfc.getNTriangles()); - double* z_vals (new double[n_x_pnts * n_y_pnts]); + const size_t n_triangles(sfc.getNTriangles()); + double* z_vals(new double[n_x_pnts * n_y_pnts]); if (!z_vals) - std::cout << "DEBUG: CreateRaster::getRaster " << n_x_pnts << " x " << n_y_pnts << - " to big" << "\n"; + std::cout << "DEBUG: CreateRaster::getRaster " << n_x_pnts << " x " << n_y_pnts << " to big" + << "\n"; size_t k(0); for (size_t r(0); r < n_x_pnts; r++) for (size_t c(0); c < n_y_pnts; c++) { - const double test_pnt[3] = { ll[0] + r * _cell_size, ll[1] + c * _cell_size, 0}; + const double test_pnt[3] = {ll[0] + r * _cell_size, ll[1] + c * _cell_size, 0}; for (k = 0; k < n_triangles; k++) if (sfc[k]->containsPoint2D(test_pnt)) { - Triangle const* const tri (sfc[k]); + Triangle const* const tri(sfc[k]); // compute coefficients c0, c1, c2 for the plane f(x,y) = c0 x + c1 y + c2 double coeff[3] = {0.0, 0.0, 0.0}; GEOLIB::getPlaneCoefficients(*tri, coeff); - z_vals[r * n_y_pnts + - c] = coeff[0] * test_pnt[0] + coeff[1] * - test_pnt[1] + coeff[2]; + z_vals[r * n_y_pnts + c] = coeff[0] * test_pnt[0] + coeff[1] * test_pnt[1] + coeff[2]; break; } if (k == n_triangles) @@ -67,5 +64,6 @@ double* Raster::getRasterFromSurface(Surface const& sfc, size_t &n_x_pnts, size_ } Raster::~Raster() -{} +{ +} } diff --git a/GEO/Raster.h b/GEO/Raster.h index 915675831..4ccac5476 100644 --- a/GEO/Raster.h +++ b/GEO/Raster.h @@ -22,9 +22,10 @@ class Raster public: Raster(double cell_size = 1, double no_data_val = 9999); void setCellSize(double cell_size); - void setNoDataVal (double no_data_val); - double* getRasterFromSurface (Surface const& sfc, size_t &n_x_pnts, size_t &n_y_pnts) const; + void setNoDataVal(double no_data_val); + double* getRasterFromSurface(Surface const& sfc, size_t& n_x_pnts, size_t& n_y_pnts) const; virtual ~Raster(); + private: double _cell_size; double _no_data_val; diff --git a/GEO/SensorData.cpp b/GEO/SensorData.cpp index 34bc447ae..4e4fd725e 100644 --- a/GEO/SensorData.cpp +++ b/GEO/SensorData.cpp @@ -16,25 +16,25 @@ #include #include - -SensorData::SensorData(const std::string &file_name) -: _start(0), _end(0), _step_size(0), _time_unit(TimeStepType::NONE) +SensorData::SensorData(const std::string& file_name) : _start(0), _end(0), _step_size(0), _time_unit(TimeStepType::NONE) { this->readDataFromFile(file_name); } SensorData::SensorData(std::vector time_steps) -: _start(time_steps[0]), _end(time_steps[time_steps.size()-1]), _step_size(0), _time_unit(TimeStepType::NONE), _time_steps(time_steps) + : _start(time_steps[0]), _end(time_steps[time_steps.size() - 1]), _step_size(0), _time_unit(TimeStepType::NONE), + _time_steps(time_steps) { - for (size_t i=1; i=time_steps[i]) - std::cout << "Error in SensorData() - Time series has no order!" << "\n"; + if (time_steps[i - 1] >= time_steps[i]) + std::cout << "Error in SensorData() - Time series has no order!" + << "\n"; } } SensorData::SensorData(size_t first_timestep, size_t last_timestep, size_t step_size) -: _start(first_timestep), _end(last_timestep), _step_size(step_size), _time_unit(TimeStepType::NONE) + : _start(first_timestep), _end(last_timestep), _step_size(step_size), _time_unit(TimeStepType::NONE) { } @@ -42,55 +42,62 @@ SensorData::~SensorData() { } - -void SensorData::addTimeSeries( const std::string &data_name, std::vector *data, const std::string &data_unit_string ) +void SensorData::addTimeSeries(const std::string& data_name, std::vector* data, + const std::string& data_unit_string) { this->addTimeSeries(SensorData::convertString2SensorDataType(data_name), data, data_unit_string); } -void SensorData::addTimeSeries( SensorDataType::type data_name, std::vector *data, const std::string &data_unit_string ) +void SensorData::addTimeSeries(SensorDataType::type data_name, std::vector* data, + const std::string& data_unit_string) { - if (_step_size>0) + if (_step_size > 0) { - if (((_end-_start)/_step_size) != data->size()) - std::cout << "Warning in SensorData::addTimeSeries() - Lengths of time series does not match number of time steps." << "\n"; + if (((_end - _start) / _step_size) != data->size()) + std::cout << "Warning in SensorData::addTimeSeries() - Lengths of time series does not match number of " + "time steps." + << "\n"; } - else if (data->size() != _time_steps.size()) - std::cout << "Warning in SensorData::addTimeSeries() - Lengths of time series does not match number of time steps." << "\n"; + else if (data->size() != _time_steps.size()) + std::cout + << "Warning in SensorData::addTimeSeries() - Lengths of time series does not match number of time steps." + << "\n"; else { _vec_names.push_back(data_name); _data_vecs.push_back(data); _data_unit_string.push_back(data_unit_string); - _data_type_index.insert( std::pair(data_name, _data_type_index.size()) ); + _data_type_index.insert(std::pair(data_name, _data_type_index.size())); } } const std::vector* SensorData::getTimeSeries(SensorDataType::type time_series_name) const { - for (size_t i=0; i<_vec_names.size(); i++) + for (size_t i = 0; i < _vec_names.size(); i++) { if (time_series_name == _vec_names[i]) return _data_vecs[i]; } - std::cout << "Error in SensorData::getTimeSeries() - Time series \"" << time_series_name << "\" not found." << "\n"; + std::cout << "Error in SensorData::getTimeSeries() - Time series \"" << time_series_name << "\" not found." + << "\n"; return NULL; } const std::string SensorData::getDataUnit(SensorDataType::type time_series_name) const { - for (size_t i=0; i<_vec_names.size(); i++) + for (size_t i = 0; i < _vec_names.size(); i++) { if (time_series_name == _vec_names[i]) return _data_unit_string[i]; } - std::cout << "Error in SensorData::getDataUnit() - Time series \"" << time_series_name << "\" not found." << "\n"; + std::cout << "Error in SensorData::getDataUnit() - Time series \"" << time_series_name << "\" not found." + << "\n"; return ""; } -int SensorData::readDataFromFile(const std::string &file_name) +int SensorData::readDataFromFile(const std::string& file_name) { - std::ifstream in( file_name.c_str() ); + std::ifstream in(file_name.c_str()); if (!in.is_open()) { @@ -103,25 +110,26 @@ int SensorData::readDataFromFile(const std::string &file_name) /* first line contains field names */ getline(in, line); std::list fields = splitString(line, '\t'); - std::list::const_iterator it (fields.begin()); + std::list::const_iterator it(fields.begin()); size_t nFields = fields.size(); - if (nFields<2) + if (nFields < 2) return 0; - size_t nDataArrays(nFields-1); + size_t nDataArrays(nFields - 1); - //create vectors necessary to hold the data - for (size_t i=0; i_vec_names.push_back(SensorData::convertString2SensorDataType(*++it)); this->_data_unit_string.push_back(""); - std::vector *data = new std::vector; + std::vector* data = new std::vector; this->_data_vecs.push_back(data); - this->_data_type_index.insert( std::pair(_vec_names.back(), _data_type_index.size()) ); + this->_data_type_index.insert( + std::pair(_vec_names.back(), _data_type_index.size())); } - while ( getline(in, line) ) + while (getline(in, line)) { fields = splitString(line, '\t'); @@ -132,7 +140,7 @@ int SensorData::readDataFromFile(const std::string &file_name) size_t current_time_step = (pos == std::string::npos) ? atoi((it++)->c_str()) : strDate2int(*it++); this->_time_steps.push_back(current_time_step); - for (size_t i=0; i_data_vecs[i]->push_back(static_cast(strtod((it++)->c_str(), 0))); } else @@ -142,30 +150,33 @@ int SensorData::readDataFromFile(const std::string &file_name) in.close(); this->_start = this->_time_steps[0]; - this->_end = this->_time_steps[this->_time_steps.size()-1]; + this->_end = this->_time_steps[this->_time_steps.size() - 1]; return 1; } float SensorData::getData(SensorDataType::type t, double time, bool lin_int) const { - std::map::const_iterator it (this->_data_type_index.find(t)); + std::map::const_iterator it(this->_data_type_index.find(t)); if (it != _data_type_index.end()) { const size_t data_index = it->second; - std::vector &data (*_data_vecs[data_index]); + std::vector& data(*_data_vecs[data_index]); if (time <= this->_start) // check if current time smaller than first time value in time series return data[0]; - else if (time >= this->_end) // check if current time is larger than last time value in time series + else if (time >= this->_end) // check if current time is larger than last time value in time series { return data.back(); } - else // find value for given time and interpolate if necessary + else // find value for given time and interpolate if necessary { - size_t idx (getLargestIndexSmallerThanElement(static_cast(time), 0, data.size(), data)); + size_t idx(getLargestIndexSmallerThanElement(static_cast(time), 0, data.size(), data)); if (lin_int) - return static_cast(data[idx] + (data[idx+1]-data[idx])/(_time_steps[idx+1]-this->_time_steps[idx]) * (time-this->_time_steps[idx])); + return static_cast(data[idx] + + (data[idx + 1] - data[idx]) + / (_time_steps[idx + 1] - this->_time_steps[idx]) + * (time - this->_time_steps[idx])); else return data[idx]; } @@ -175,20 +186,29 @@ float SensorData::getData(SensorDataType::type t, double time, bool lin_int) con std::string SensorData::convertSensorDataType2String(SensorDataType::type t) { - if (SensorDataType::EVAPORATION == t) return "Evaporation"; - else if (SensorDataType::PRECIPITATION == t) return "Precipitation"; - else if (SensorDataType::RECHARGE == t) return "Recharge"; - else if (SensorDataType::TEMPERATURE == t) return "Temperature"; + if (SensorDataType::EVAPORATION == t) + return "Evaporation"; + else if (SensorDataType::PRECIPITATION == t) + return "Precipitation"; + else if (SensorDataType::RECHARGE == t) + return "Recharge"; + else if (SensorDataType::TEMPERATURE == t) + return "Temperature"; // pls leave this as last choice - else return "Unknown"; + else + return "Unknown"; } -SensorDataType::type SensorData::convertString2SensorDataType(const std::string &s) +SensorDataType::type SensorData::convertString2SensorDataType(const std::string& s) { - if ((s.compare("Evaporation")==0) || (s.compare("EVAPORATION")==0)) return SensorDataType::EVAPORATION; - else if ((s.compare("Precipitation")==0) || (s.compare("PRECIPITATION")==0)) return SensorDataType::PRECIPITATION; - else if ((s.compare("Recharge")==0) || (s.compare("RECHARGE")==0)) return SensorDataType::RECHARGE; - else if ((s.compare("Temperature")==0) || (s.compare("TEMPERATURE")==0)) return SensorDataType::TEMPERATURE; - else return SensorDataType::OTHER; + if ((s.compare("Evaporation") == 0) || (s.compare("EVAPORATION") == 0)) + return SensorDataType::EVAPORATION; + else if ((s.compare("Precipitation") == 0) || (s.compare("PRECIPITATION") == 0)) + return SensorDataType::PRECIPITATION; + else if ((s.compare("Recharge") == 0) || (s.compare("RECHARGE") == 0)) + return SensorDataType::RECHARGE; + else if ((s.compare("Temperature") == 0) || (s.compare("TEMPERATURE") == 0)) + return SensorDataType::TEMPERATURE; + else + return SensorDataType::OTHER; } - diff --git a/GEO/SensorData.h b/GEO/SensorData.h index 3013161a1..2f19549b8 100644 --- a/GEO/SensorData.h +++ b/GEO/SensorData.h @@ -8,7 +8,6 @@ * http://www.opengeosys.org/project/license */ - #ifndef SENSORDATA_H #define SENSORDATA_H @@ -25,7 +24,8 @@ */ struct SensorDataType { - enum type { + enum type + { OTHER = 0, PRECIPITATION, RECHARGE, @@ -43,7 +43,8 @@ struct SensorDataType */ struct TimeStepType { - enum type { + enum type + { NONE = 0, SECONDS, MINUTES, @@ -51,7 +52,7 @@ struct TimeStepType WEEKS, MONTHS, YEARS, - DATE, // time series is given as a vector of dates + DATE, // time series is given as a vector of dates DATETIME // time series is given as a vector of date + time }; }; @@ -66,7 +67,7 @@ class SensorData { public: /// Constructor using file name (automatically reads the file and fills all data structures) - SensorData(const std::string &file_name); + SensorData(const std::string& file_name); /// Constructor using a time step vector valid for all time series that will be added later SensorData(std::vector time_steps); @@ -79,36 +80,31 @@ class SensorData /// Adds a time series that needs to conform to the time step vector specified in the constructor. /// Optionally a unit for the time series can be given. /// The name is converted to SensorDataType enum. - void addTimeSeries( const std::string &data_name, std::vector *data, const std::string &data_unit_string = "" ); + void addTimeSeries(const std::string& data_name, std::vector* data, + const std::string& data_unit_string = ""); /// Adds a time series that needs to conform to the time step vector specified in the constructor. /// Optionally a unit for the time series can be given. - void addTimeSeries( SensorDataType::type data_name, std::vector *data, const std::string &data_unit_string = "" ); + void addTimeSeries(SensorDataType::type data_name, std::vector* data, + const std::string& data_unit_string = ""); /// Returns the time series with the given name const std::vector* getTimeSeries(SensorDataType::type time_series_name) const; /// Returns all time series names contained in this container const std::vector& getTimeSeriesNames() const { return _vec_names; }; - /// Returns the time step vector (if it exists) const std::vector& getTimeSteps() const { return _time_steps; }; - /// Returns the first time step size_t getStartTime() const { return _start; }; - /// Returns the last time step size_t getEndTime() const { return _end; }; - /// Returns the interval between time steps (Returns "0" if a vector is given!) size_t getStepSize() const { return _step_size; }; - /// Allows to set a unit for the time steps void setTimeUnit(TimeStepType::type t) { _time_unit = t; }; - /// Returns the unit the time steps TimeStepType::type getTimeUnit() const { return _time_unit; }; - /// Returns the data unit of the given time series const std::string getDataUnit(SensorDataType::type t) const; @@ -119,11 +115,11 @@ class SensorData static std::string convertSensorDataType2String(SensorDataType::type t); /// Converts Strings to Sensor Data Types - static SensorDataType::type convertString2SensorDataType(const std::string &s); + static SensorDataType::type convertString2SensorDataType(const std::string& s); private: /// Reads a CSV-file with time series data and fills the container. - int readDataFromFile(const std::string &file_name); + int readDataFromFile(const std::string& file_name); size_t _start; size_t _end; @@ -132,9 +128,8 @@ class SensorData std::vector _data_unit_string; std::vector _time_steps; std::vector _vec_names; - std::vector< std::vector* > _data_vecs; + std::vector*> _data_vecs; std::map _data_type_index; }; -#endif //SENSORDATA_H - +#endif // SENSORDATA_H diff --git a/GEO/SimplePolygonTree.cpp b/GEO/SimplePolygonTree.cpp index 88c9e69a1..66047a59a 100644 --- a/GEO/SimplePolygonTree.cpp +++ b/GEO/SimplePolygonTree.cpp @@ -14,26 +14,29 @@ namespace GEOLIB { -SimplePolygonTree::SimplePolygonTree(Polygon * polygon, SimplePolygonTree * parent) : - _node_polygon (polygon), _parent (parent) -{} +SimplePolygonTree::SimplePolygonTree(Polygon* polygon, SimplePolygonTree* parent) + : _node_polygon(polygon), _parent(parent) +{ +} SimplePolygonTree::~SimplePolygonTree() { delete _node_polygon; - for (std::list::const_iterator it (_childs.begin()); - it != _childs.end(); ++it) { + for (std::list::const_iterator it(_childs.begin()); it != _childs.end(); ++it) + { delete *it; } } -bool SimplePolygonTree::isPolygonInside (const SimplePolygonTree* polygon_hierarchy) const +bool SimplePolygonTree::isPolygonInside(const SimplePolygonTree* polygon_hierarchy) const { - const Polygon* polygon (polygon_hierarchy->getPolygon()); + const Polygon* polygon(polygon_hierarchy->getPolygon()); // check *all* points of polygon - size_t n_pnts_polygon (polygon->getNumberOfPoints() - 1), cnt(0); - for (size_t k(0); k < n_pnts_polygon && cnt == k; k++) { - if (_node_polygon->isPntInPolygon (*(polygon->getPoint(k)))) { + size_t n_pnts_polygon(polygon->getNumberOfPoints() - 1), cnt(0); + for (size_t k(0); k < n_pnts_polygon && cnt == k; k++) + { + if (_node_polygon->isPntInPolygon(*(polygon->getPoint(k)))) + { cnt++; } } @@ -45,32 +48,36 @@ bool SimplePolygonTree::isPolygonInside (const SimplePolygonTree* polygon_hierar return false; } -void SimplePolygonTree::insertSimplePolygonTree (SimplePolygonTree* polygon_hierarchy) +void SimplePolygonTree::insertSimplePolygonTree(SimplePolygonTree* polygon_hierarchy) { - const Polygon* polygon (polygon_hierarchy->getPolygon()); - bool nfound (true); - for (std::list::const_iterator it (_childs.begin()); - it != _childs.end() && nfound; ++it) { + const Polygon* polygon(polygon_hierarchy->getPolygon()); + bool nfound(true); + for (std::list::const_iterator it(_childs.begin()); it != _childs.end() && nfound; ++it) + { // check all points of polygon - size_t n_pnts_polygon (polygon->getNumberOfPoints()), cnt(0); - for (size_t k(0); k < n_pnts_polygon && cnt == k; k++) { - if (((*it)->getPolygon())->isPntInPolygon (*(polygon->getPoint(k)))) { + size_t n_pnts_polygon(polygon->getNumberOfPoints()), cnt(0); + for (size_t k(0); k < n_pnts_polygon && cnt == k; k++) + { + if (((*it)->getPolygon())->isPntInPolygon(*(polygon->getPoint(k)))) + { cnt++; } } // all points of the given polygon are contained in the current polygon - if (cnt == n_pnts_polygon) { - (*it)->insertSimplePolygonTree (polygon_hierarchy); + if (cnt == n_pnts_polygon) + { + (*it)->insertSimplePolygonTree(polygon_hierarchy); nfound = false; } } - if (nfound) { - _childs.push_back (polygon_hierarchy); + if (nfound) + { + _childs.push_back(polygon_hierarchy); polygon_hierarchy->setParent(this); } } -const Polygon* SimplePolygonTree::getPolygon () const +const Polygon* SimplePolygonTree::getPolygon() const { return _node_polygon; } diff --git a/GEO/SimplePolygonTree.h b/GEO/SimplePolygonTree.h index a2d64b0b9..ad1014be5 100644 --- a/GEO/SimplePolygonTree.h +++ b/GEO/SimplePolygonTree.h @@ -31,14 +31,14 @@ class SimplePolygonTree SimplePolygonTree(Polygon* polygon, SimplePolygonTree* parent); virtual ~SimplePolygonTree(); - bool isPolygonInside (const SimplePolygonTree* polygon_tree) const; - void insertSimplePolygonTree (SimplePolygonTree* polygon_tree); + bool isPolygonInside(const SimplePolygonTree* polygon_tree) const; + void insertSimplePolygonTree(SimplePolygonTree* polygon_tree); /** * get the polygon represented by the tree node * @return the polygon */ - const Polygon* getPolygon () const; + const Polygon* getPolygon() const; protected: /** @@ -55,11 +55,9 @@ class SimplePolygonTree * in the _node_polygon */ std::list _childs; + private: - void setParent(SimplePolygonTree* parent) - { - _parent = parent; - } + void setParent(SimplePolygonTree* parent) { _parent = parent; } }; /** @@ -67,18 +65,24 @@ class SimplePolygonTree * @param list_of_simple_polygon_trees */ template -void createPolygonTrees (std::list& list_of_simple_polygon_hierarchies) +void createPolygonTrees(std::list& list_of_simple_polygon_hierarchies) { - typename std::list::iterator it0 (list_of_simple_polygon_hierarchies.begin()), it1; - while (it0 != list_of_simple_polygon_hierarchies.end()) { + typename std::list::iterator it0(list_of_simple_polygon_hierarchies.begin()), it1; + while (it0 != list_of_simple_polygon_hierarchies.end()) + { it1 = it0; it1++; - while (it1 != list_of_simple_polygon_hierarchies.end()) { - if ((*it0)->isPolygonInside(*it1)) { + while (it1 != list_of_simple_polygon_hierarchies.end()) + { + if ((*it0)->isPolygonInside(*it1)) + { (*it0)->insertSimplePolygonTree(*it1); it1 = list_of_simple_polygon_hierarchies.erase(it1); - } else { - if ((*it1)->isPolygonInside(*it0)) { + } + else + { + if ((*it1)->isPolygonInside(*it0)) + { (*it1)->insertSimplePolygonTree(*it0); it0 = list_of_simple_polygon_hierarchies.erase(it0); } @@ -90,7 +94,6 @@ void createPolygonTrees (std::list& list_of_simple_polygon_hie } } - } // end namespace GEOLIB #endif /* SIMPLEPOLYGONTREE_H_ */ diff --git a/GEO/Station.cpp b/GEO/Station.cpp index 02db9340b..7e5e8f358 100644 --- a/GEO/Station.cpp +++ b/GEO/Station.cpp @@ -20,32 +20,32 @@ namespace GEOLIB { -Station::Station(double x, double y, double z, std::string name) : - Point (x,y,z), _name(name), _type(Station::STATION), _station_value(0.0), _sensor_data(NULL) +Station::Station(double x, double y, double z, std::string name) + : Point(x, y, z), _name(name), _type(Station::STATION), _station_value(0.0), _sensor_data(NULL) { addProperty("x", &getX, &Station::setX); addProperty("y", &getY, &Station::setY); addProperty("z", &getZ, &Station::setZ); } -Station::Station(Point* coords, std::string name) : - Point (*coords), _name(name), _type(Station::STATION), _station_value(0.0), _sensor_data(NULL) +Station::Station(Point* coords, std::string name) + : Point(*coords), _name(name), _type(Station::STATION), _station_value(0.0), _sensor_data(NULL) { addProperty("x", &getX, &Station::setX); addProperty("y", &getY, &Station::setY); addProperty("z", &getZ, &Station::setZ); } -Station::Station(Station const& src) : - Point(src.getData()), _name(src._name), _type(src._type), - _station_value(src._station_value), _sensor_data(src._sensor_data) +Station::Station(Station const& src) + : Point(src.getData()), _name(src._name), _type(src._type), _station_value(src._station_value), + _sensor_data(src._sensor_data) { addProperty("x", &getX, &Station::setX); addProperty("y", &getY, &Station::setY); addProperty("z", &getZ, &Station::setZ); } -void Station::addProperty(std::string pname, double (* getFct)(void*), void (* set)(void*, double)) +void Station::addProperty(std::string pname, double (*getFct)(void*), void (*set)(void*, double)) { STNProperty p; p.name = pname; @@ -59,7 +59,7 @@ Station::~Station() delete this->_sensor_data; } -Station* Station::createStation(const std::string & line) +Station* Station::createStation(const std::string& line) { std::list::const_iterator it; Station* station = new Station(); @@ -68,22 +68,23 @@ Station* Station::createStation(const std::string & line) if (fields.size() >= 3) { it = fields.begin(); - station->_name = *it; - (*station)[0] = strtod((replaceString(",", ".", *(++it))).c_str(), NULL); - (*station)[1] = strtod((replaceString(",", ".", *(++it))).c_str(), NULL); + station->_name = *it; + (*station)[0] = strtod((replaceString(",", ".", *(++it))).c_str(), NULL); + (*station)[1] = strtod((replaceString(",", ".", *(++it))).c_str(), NULL); if (++it != fields.end()) (*station)[2] = strtod((replaceString(",", ".", *it)).c_str(), NULL); } else { - std::cout << "Station::createStation() - Unexpected file format..." << "\n"; + std::cout << "Station::createStation() - Unexpected file format..." + << "\n"; delete station; return NULL; } return station; } -Station* Station::createStation(const std::string &name, double x, double y, double z) +Station* Station::createStation(const std::string& name, double x, double y, double z) { Station* station = new Station(); station->_name = name; @@ -99,15 +100,15 @@ const std::map Station::getProperties() for (int i = 0; i < static_cast(_properties.size()); i++) { - double (* getFct)(void*) = _properties[i].get; - //setFct set = _properties[i].set; + double (*getFct)(void*) = _properties[i].get; + // setFct set = _properties[i].set; propertyMap[_properties[i].name] = (*getFct)((void*)this); } return propertyMap; } -bool Station::inSelection(const std::vector &bounds) +bool Station::inSelection(const std::vector& bounds) { double value; for (size_t i = 0; i < bounds.size(); i++) @@ -115,7 +116,7 @@ bool Station::inSelection(const std::vector &bounds) for (size_t j = 0; j < _properties.size(); j++) if (_properties[j].name.compare(bounds[i].getName()) == 0) { - double (* get)(void*) = _properties[j].get; + double (*get)(void*) = _properties[j].get; value = (*get)((void*)this); if (!(value >= bounds[i].getMin() && value <= bounds[i].getMax())) return false; @@ -128,8 +129,7 @@ bool Station::inSelection(const std::vector &bounds) // The Borehole class // //////////////////////// -StationBorehole::StationBorehole(double x, double y, double z) : - Station (x,y,z), _zCoord(0), _depth(0), _date(0) +StationBorehole::StationBorehole(double x, double y, double z) : Station(x, y, z), _zCoord(0), _depth(0), _date(0) { _type = Station::BOREHOLE; addProperty("date", &StationBorehole::getDate, &StationBorehole::setDate); @@ -148,7 +148,7 @@ StationBorehole::~StationBorehole(void) delete _profilePntVec[k]; } -int StationBorehole::find(const std::string &str) +int StationBorehole::find(const std::string& str) { size_t size = _soilName.size(); for (size_t i = 0; i < size; i++) @@ -157,20 +157,19 @@ int StationBorehole::find(const std::string &str) return 0; } -int StationBorehole::readStratigraphyFile(const std::string &path, - std::vector > &data) +int StationBorehole::readStratigraphyFile(const std::string& path, std::vector >& data) { std::string line; - std::ifstream in( path.c_str() ); + std::ifstream in(path.c_str()); if (!in.is_open()) { - std::cout << "StationBorehole::readStratigraphyFile() - Could not open file..." << - "\n"; + std::cout << "StationBorehole::readStratigraphyFile() - Could not open file..." + << "\n"; return 0; } - while ( getline(in, line) ) + while (getline(in, line)) { std::list fields = splitString(line, '\t'); data.push_back(fields); @@ -181,7 +180,7 @@ int StationBorehole::readStratigraphyFile(const std::string &path, return 1; } -int StationBorehole::addStratigraphy(const std::string &path, StationBorehole* borehole) +int StationBorehole::addStratigraphy(const std::string& path, StationBorehole* borehole) { std::vector > data; if (readStratigraphyFile(path, data)) @@ -192,7 +191,8 @@ int StationBorehole::addStratigraphy(const std::string &path, StationBorehole* b // check if a layer is missing size = borehole->_soilName.size(); - std::cout << "StationBorehole::addStratigraphy ToDo" << "\n"; + std::cout << "StationBorehole::addStratigraphy ToDo" + << "\n"; // for (size_t i=0; i_soilLayerThickness[i] == -1) ||(borehole->_soilName[i].compare("") == 0)) @@ -200,7 +200,9 @@ int StationBorehole::addStratigraphy(const std::string &path, StationBorehole* b // borehole->_soilLayerThickness.clear(); // borehole->_soilName.clear(); // - // cout << "StationBorehole::addStratigraphy() - Profile incomplete (Borehole " << borehole->_name << ", Layer " << (i+1) << " missing).\n"; + // cout << "StationBorehole::addStratigraphy() - Profile incomplete (Borehole " << borehole->_name << + //", + // Layer " << (i+1) << " missing).\n"; // // return 0; // } @@ -216,15 +218,16 @@ int StationBorehole::addLayer(std::list fields, StationBorehole* bo { if (fields.size() >= 4) /* check if there are enough fields to create a borehole object */ { - if (fields.front().compare(borehole->_name) == 0) /* check if the name of the borehole matches the name in the data */ + if (fields.front().compare(borehole->_name) + == 0) /* check if the name of the borehole matches the name in the data */ { fields.pop_front(); // int layer = atoi(fields.front().c_str()); fields.pop_front(); - std::cerr << "StationBorehole::addLayer - assuming correct order" << - "\n"; + std::cerr << "StationBorehole::addLayer - assuming correct order" + << "\n"; double thickness(strtod(replaceString(",", ".", fields.front()).c_str(), 0)); fields.pop_front(); borehole->addSoilLayer(thickness, fields.front()); @@ -232,33 +235,34 @@ int StationBorehole::addLayer(std::list fields, StationBorehole* bo } else { - std::cout - << "StationBorehole::addLayer() - Unexpected file format (Borehole " - << borehole->_name << ")..." << "\n"; + std::cout << "StationBorehole::addLayer() - Unexpected file format (Borehole " << borehole->_name << ")..." + << "\n"; return 0; } return 1; } -int StationBorehole::addStratigraphy(const std::vector &profile, const std::vector soil_names) +int StationBorehole::addStratigraphy( + const std::vector& profile, const std::vector soil_names) { - if (((profile.size()-1) == soil_names.size()) && (soil_names.size()>0)) + if (((profile.size() - 1) == soil_names.size()) && (soil_names.size() > 0)) { this->_profilePntVec.push_back(profile[0]); size_t nLayers = soil_names.size(); - for (size_t i=0; i_profilePntVec.push_back(profile[i+1]); + this->_profilePntVec.push_back(profile[i + 1]); this->_soilName.push_back(soil_names[i]); } return 1; } - std::cout << "Error in StationBorehole::addStratigraphy() - Length of parameter vectors does not match." << "\n"; + std::cout << "Error in StationBorehole::addStratigraphy() - Length of parameter vectors does not match." + << "\n"; return 0; } -int StationBorehole::addStratigraphies(const std::string &path, std::vector* boreholes) +int StationBorehole::addStratigraphies(const std::string& path, std::vector* boreholes) { std::vector > data; @@ -275,27 +279,23 @@ int StationBorehole::addStratigraphies(const std::string &path, std::vector= 4) { name = static_cast((*boreholes)[it])->_name; - if ( fields.front().compare(name) != 0 ) + if (fields.front().compare(name) != 0) if (it < boreholes->size() - 1) it++; fields.pop_front(); - //the method just assumes that layers are read in correct order + // the method just assumes that layers are read in correct order fields.pop_front(); - double thickness (strtod(replaceString(",", ".", - fields.front()).c_str(), 0)); + double thickness(strtod(replaceString(",", ".", fields.front()).c_str(), 0)); fields.pop_front(); - std::string soil_name (fields.front()); + std::string soil_name(fields.front()); fields.pop_front(); - static_cast((*boreholes)[it])->addSoilLayer( - thickness, - soil_name); + static_cast((*boreholes)[it])->addSoilLayer(thickness, soil_name); } else - std::cout << - "StationBorehole::addStratigraphies() - Unexpected file format..." + std::cout << "StationBorehole::addStratigraphies() - Unexpected file format..." << "\n"; - //return 0; + // return 0; } } else @@ -304,22 +304,22 @@ int StationBorehole::addStratigraphies(const std::string &path, std::vector fields = splitString(line, '\t'); - if (fields.size() >= 5) + if (fields.size() >= 5) { - borehole->_name = fields.front(); + borehole->_name = fields.front(); fields.pop_front(); - (*borehole)[0] = strtod((replaceString(",", ".", fields.front())).c_str(), NULL); + (*borehole)[0] = strtod((replaceString(",", ".", fields.front())).c_str(), NULL); fields.pop_front(); - (*borehole)[1] = strtod((replaceString(",", ".", fields.front())).c_str(), NULL); + (*borehole)[1] = strtod((replaceString(",", ".", fields.front())).c_str(), NULL); fields.pop_front(); - (*borehole)[2] = strtod((replaceString(",", ".", fields.front())).c_str(), NULL); + (*borehole)[2] = strtod((replaceString(",", ".", fields.front())).c_str(), NULL); fields.pop_front(); - borehole->_depth = strtod((replaceString(",", ".", fields.front())).c_str(), NULL); + borehole->_depth = strtod((replaceString(",", ".", fields.front())).c_str(), NULL); fields.pop_front(); if (fields.empty()) borehole->_date = 0; @@ -331,28 +331,25 @@ StationBorehole* StationBorehole::createStation(const std::string &line) } else { - std::cout << "Station::createStation() - Unexpected file format..." << "\n"; + std::cout << "Station::createStation() - Unexpected file format..." + << "\n"; delete borehole; return NULL; } return borehole; } -StationBorehole* StationBorehole::createStation(const std::string &name, - double x, - double y, - double z, - double depth, - std::string date) +StationBorehole* StationBorehole::createStation( + const std::string& name, double x, double y, double z, double depth, std::string date) { StationBorehole* station = new StationBorehole(); - station->_name = name; - (*station)[0] = x; - (*station)[1] = y; - (*station)[2] = z; + station->_name = name; + (*station)[0] = x; + (*station)[1] = y; + (*station)[2] = z; station->_depth = depth; if (date.compare("0000-00-00") != 0) - station->_date = xmlDate2int(date); + station->_date = xmlDate2int(date); return station; } @@ -366,7 +363,7 @@ void StationBorehole::createSurrogateStratigraphies(std::vector* borehol } } -void StationBorehole::addSoilLayer ( double thickness, const std::string &soil_name) +void StationBorehole::addSoilLayer(double thickness, const std::string& soil_name) { /* // TF - Altmark @@ -384,18 +381,18 @@ void StationBorehole::addSoilLayer ( double thickness, const std::string &soil_n // KR - Bode if (_profilePntVec.empty()) - addSoilLayer ((*this)[0], (*this)[1], (*this)[2], ""); + addSoilLayer((*this)[0], (*this)[1], (*this)[2], ""); - size_t idx (_profilePntVec.size()); + size_t idx(_profilePntVec.size()); double x((*_profilePntVec[idx - 1])[0]); double y((*_profilePntVec[idx - 1])[1]); double z((*_profilePntVec[0])[2] - thickness); - addSoilLayer (x, y, z, soil_name); + addSoilLayer(x, y, z, soil_name); } -void StationBorehole::addSoilLayer ( double x, double y, double z, const std::string &soil_name) +void StationBorehole::addSoilLayer(double x, double y, double z, const std::string& soil_name) { - _profilePntVec.push_back (new Point (x, y, z)); + _profilePntVec.push_back(new Point(x, y, z)); _soilName.push_back(soil_name); } } // namespace diff --git a/GEO/Station.h b/GEO/Station.h index d5a38c6c3..6fb586fcf 100644 --- a/GEO/Station.h +++ b/GEO/Station.h @@ -34,7 +34,8 @@ namespace GEOLIB * time series data from data loggers (as a SensorData-object), etc. * * Notes concerning the property-system used in this class: - * Variables of Station and derived classes can be defined to be "properties" of this class (this is entirely optional!). + * Variables of Station and derived classes can be defined to be "properties" of this class (this is entirely + *optional!). * Certain functions in the GUI allow you to modify aspects of the visualisation based on these * properties (e.g. filtering operations such as "display only boreholes drilled after 1990 with a * depth between 400-800m"). @@ -50,9 +51,8 @@ namespace GEOLIB class Station : public Point { protected: - - //typedef double (Station::*getFct)(); - //typedef void (Station::*setFct)(double); + // typedef double (Station::*getFct)(); + // typedef void (Station::*setFct)(double); /** * \brief Container for station-properties. @@ -62,15 +62,15 @@ class Station : public Point struct STNProperty { std::string name; - double (* get)(void*); - void (* set)(void*, double); + double (*get)(void*); + void (*set)(void*, double); }; public: /// Signals if the object is a "simple" Station or a Borehole (i.e. containing borehole-specific information). enum StationType { - STATION = 1, + STATION = 1, BOREHOLE = 2 }; @@ -84,10 +84,7 @@ class Station : public Point * \param name The name of the station. * \param color The color of the station in visualisation. */ - Station(double x = 0.0, - double y = 0.0, - double z = 0.0, - std::string name = ""); + Station(double x = 0.0, double y = 0.0, double z = 0.0, std::string name = ""); Station(Point* coords, std::string name = ""); @@ -118,44 +115,39 @@ class Station : public Point * \param set A function pointer to a static write function for the variable referred to by pname * \return */ - void addProperty(std::string pname, double (* get)(void*), void (* set)(void*, double)); + void addProperty(std::string pname, double (*get)(void*), void (*set)(void*, double)); /// Returns a map containing all the properties of that station type. const std::map getProperties(); - /// Determines if the station's parameters are within the the bounds of the current selection (see property system for details) - bool inSelection(const std::vector &bounds); + /// Determines if the station's parameters are within the the bounds of the current selection (see property system + /// for details) + bool inSelection(const std::vector& bounds); - /// Returns true if all properties of this stations are within the boundaries given by \param bounds and false otherwise + /// Returns true if all properties of this stations are within the boundaries given by \param bounds and false + /// otherwise bool inSelection(std::map properties) const; /// Returns the name of the station. std::string const& getName() const { return _name; } - /// Returns the GeoSys-station-type for the station. int type() const { return _type; } - /// Creates a Station-object from information contained in a string (assuming the string has the right format) - static Station* createStation(const std::string &line); + static Station* createStation(const std::string& line); /// Creates a new station object based on the given parameters. - static Station* createStation(const std::string &name, double x, double y, double z); + static Station* createStation(const std::string& name, double x, double y, double z); /// Returns the specific value for this station double getStationValue() { return this->_station_value; }; - /// Allows to set a specific value for this station (e.g. for classification) void setStationValue(double station_value) { this->_station_value = station_value; }; - /// Allows to add a SensorData to the observation site void addSensorData(SensorData* sensor_data) { this->_sensor_data = sensor_data; }; - /// Allows to add sensor data from a CSV file to the observation site - void addSensorDataFromCSV(const std::string &file_name) { this->_sensor_data = new SensorData(file_name); }; - + void addSensorDataFromCSV(const std::string& file_name) { this->_sensor_data = new SensorData(file_name); }; /// Returns all the sensor data for this observation site const SensorData* getSensorData() { return this->_sensor_data; }; - protected: /** * \brief Returns the x-coordinate of this station. See the detailed documentation for getX() concerning the syntax. @@ -166,26 +158,45 @@ class Station : public Point * related to the function pointer associated with this function. Therefore, this function needs to be * called "getX((void*)this);". It is highly recommended to define this function as protected because it * does not actually make sense for these functions to be static except in the context of function pointers. - * \param stnObject A pointer to the station object for which the x-coordinate should be returned, usually (void*)this will work fine. + * \param stnObject A pointer to the station object for which the x-coordinate should be returned, usually + *(void*)this will work fine. * \return The x-coordinate for this station. */ - static double getX(void* stnObject) { Station* stn = (Station*)stnObject; - return (*stn)[0]; } + static double getX(void* stnObject) + { + Station* stn = (Station*)stnObject; + return (*stn)[0]; + } /// Returns the y-coordinate of this station. See the detailed documentation for getX concerning the syntax. - static double getY(void* stnObject) { Station* stn = (Station*)stnObject; - return (*stn)[1]; } + static double getY(void* stnObject) + { + Station* stn = (Station*)stnObject; + return (*stn)[1]; + } /// Returns the z-coordinate of this station. See the detailed documentation for getX concerning the syntax. - static double getZ(void* stnObject) { Station* stn = (Station*)stnObject; - return (*stn)[2]; } + static double getZ(void* stnObject) + { + Station* stn = (Station*)stnObject; + return (*stn)[2]; + } /// Sets the x-coordinate for this station. See the detailed documentation for getX concerning the syntax. - static void setX(void* stnObject, double val) { Station* stn = (Station*)stnObject; - (*stn)[0] = val; } + static void setX(void* stnObject, double val) + { + Station* stn = (Station*)stnObject; + (*stn)[0] = val; + } /// Sets the y-coordinate for this station. See the detailed documentation for getX concerning the syntax. - static void setY(void* stnObject, double val) { Station* stn = (Station*)stnObject; - (*stn)[1] = val; } + static void setY(void* stnObject, double val) + { + Station* stn = (Station*)stnObject; + (*stn)[1] = val; + } /// Sets the z-coordinate for this station. See the detailed documentation for getX concerning the syntax. - static void setZ(void* stnObject, double val) { Station* stn = (Station*)stnObject; - (*stn)[2] = val; } + static void setZ(void* stnObject, double val) + { + Station* stn = (Station*)stnObject; + (*stn)[2] = val; + } std::string _name; StationType _type; // GeoSys Station Type @@ -194,7 +205,6 @@ class Station : public Point private: double _station_value; SensorData* _sensor_data; - }; /********* Boreholes *********/ @@ -212,21 +222,18 @@ class StationBorehole : public Station ~StationBorehole(void); /// Creates a StationBorehole-object from a string (assuming the string has the right format) - static StationBorehole* createStation(const std::string &line); + static StationBorehole* createStation(const std::string& line); /// Creates a new borehole object based on the given parameters. - static StationBorehole* createStation(const std::string &name, - double x, - double y, - double z, - double depth, + static StationBorehole* createStation(const std::string& name, double x, double y, double z, double depth, std::string date = ""); - /// Adds a stratigraphy to a borehole given a vector of points of length "n" and a vector of soil names of length "n-1". - int addStratigraphy(const std::vector &profile, const std::vector soil_names); + /// Adds a stratigraphy to a borehole given a vector of points of length "n" and a vector of soil names of length + /// "n-1". + int addStratigraphy(const std::vector& profile, const std::vector soil_names); /// Reads the stratigraphy for a specified station from a file - static int addStratigraphy(const std::string &path, StationBorehole* borehole); + static int addStratigraphy(const std::string& path, StationBorehole* borehole); /** * \brief Reads all stratigraphy information from a file in one go. @@ -235,28 +242,24 @@ class StationBorehole : public Station * Be very careful when using this method -- it is pretty fast but it checks nothing and just * assumes that everything is in right order and will work out fine! */ - static int addStratigraphies(const std::string &path, std::vector* boreholes); + static int addStratigraphies(const std::string& path, std::vector* boreholes); /// Finds the given string in the vector of soil-names - int find(const std::string &str); + int find(const std::string& str); // Returns the depth of the borehole double getDepth() const { return _depth; } - /// Returns the date entry for the borehole double getDate() const { return _date; } - - /// Returns a reference to a vector of Points representing the stratigraphy of the borehole (incl. the station-point itself) - const std::vector &getProfile() const { return _profilePntVec; } - + /// Returns a reference to a vector of Points representing the stratigraphy of the borehole (incl. the station-point + /// itself) + const std::vector& getProfile() const { return _profilePntVec; } /// Returns a reference to a vector of soil names for the stratigraphy of the borehole - const std::vector &getSoilNames() const { return _soilName; } - + const std::vector& getSoilNames() const { return _soilName; } /// Sets the depth of the borehole - void setDepth( double depth ) { _depth = depth; } - + void setDepth(double depth) { _depth = depth; } /// Add a soil layer to the boreholes stratigraphy. - void addSoilLayer ( double thickness, const std::string &soil_name); + void addSoilLayer(double thickness, const std::string& soil_name); /** * Add a soil layer to the boreholes stratigraphy. @@ -266,21 +269,37 @@ class StationBorehole : public Station * a seperate entry in the profile vector for the end of the borehole which in the given notation * is just the coordinate given for the last soil layer (i.e. the end of that layer). */ - void addSoilLayer ( double x, double y, double z, const std::string &soil_name); + void addSoilLayer(double x, double y, double z, const std::string& soil_name); protected: - /// Returns the depth of this borehole. Please see the documentation for Station::getX for details concerning the syntax. - static double getDepth(void* stnObject) { StationBorehole* stn = - (StationBorehole*)stnObject; - return stn->_depth; } - /// Returns the date this borehole has been drilled. Please see the documentation for Station::getX for details concerning the syntax. - static double getDate(void* stnObject) { StationBorehole* stn = (StationBorehole*)stnObject; return stn->_date; } - /// Sets the depth of this borehole. Please see the documentation for Station::getX for details concerning the syntax. - static void setDepth(void* stnObject, double val) { StationBorehole* stn = - (StationBorehole*)stnObject; - stn->_depth = val; } - /// Sets the date when this borehole has been drilled. Please see the documentation for Station::getX for details concerning the syntax. - static void setDate(void* stnObject, double val) { StationBorehole* stn = (StationBorehole*)stnObject; stn->_date = static_cast(val); } + /// Returns the depth of this borehole. Please see the documentation for Station::getX for details concerning the + /// syntax. + static double getDepth(void* stnObject) + { + StationBorehole* stn = (StationBorehole*)stnObject; + return stn->_depth; + } + /// Returns the date this borehole has been drilled. Please see the documentation for Station::getX for details + /// concerning the syntax. + static double getDate(void* stnObject) + { + StationBorehole* stn = (StationBorehole*)stnObject; + return stn->_date; + } + /// Sets the depth of this borehole. Please see the documentation for Station::getX for details concerning the + /// syntax. + static void setDepth(void* stnObject, double val) + { + StationBorehole* stn = (StationBorehole*)stnObject; + stn->_depth = val; + } + /// Sets the date when this borehole has been drilled. Please see the documentation for Station::getX for details + /// concerning the syntax. + static void setDate(void* stnObject, double val) + { + StationBorehole* stn = (StationBorehole*)stnObject; + stn->_date = static_cast(val); + } private: /// Adds a layer for the specified borehole profile based on the information given in the stringlist @@ -290,11 +309,10 @@ class StationBorehole : public Station static void createSurrogateStratigraphies(std::vector* boreholes); /// Reads the specified file containing borehole stratigraphies into an vector of stringlists - static int readStratigraphyFile(const std::string &path, - std::vector > &data); + static int readStratigraphyFile(const std::string& path, std::vector >& data); - //long profile_type; - //std::vector _soilType; + // long profile_type; + // std::vector _soilType; double _zCoord; // height at which the borehole officially begins (this might _not_ be the actual elevation) double _depth; // depth of the borehole int _date; // date when the borehole has been drilled diff --git a/GEO/Surface.cpp b/GEO/Surface.cpp index f02e43947..b8c240ede 100644 --- a/GEO/Surface.cpp +++ b/GEO/Surface.cpp @@ -23,34 +23,33 @@ namespace GEOLIB { -Surface::Surface (const std::vector &pnt_vec) : - GeoObject(), _sfc_pnts(pnt_vec), _bv(), _sfc_grid(NULL) -{} +Surface::Surface(const std::vector& pnt_vec) : GeoObject(), _sfc_pnts(pnt_vec), _bv(), _sfc_grid(NULL) +{ +} -Surface::~Surface () +Surface::~Surface() { delete _sfc_grid; for (size_t k(0); k < _sfc_triangles.size(); k++) delete _sfc_triangles[k]; } -void Surface::addTriangle (size_t pnt_a, size_t pnt_b, size_t pnt_c) +void Surface::addTriangle(size_t pnt_a, size_t pnt_b, size_t pnt_c) { - assert (pnt_a < _sfc_pnts.size() && pnt_b < _sfc_pnts.size() && pnt_c < _sfc_pnts.size()); - _sfc_triangles.push_back (new Triangle(_sfc_pnts, pnt_a, pnt_b, pnt_c)); - _bv.update (*_sfc_pnts[pnt_a]); - _bv.update (*_sfc_pnts[pnt_b]); - _bv.update (*_sfc_pnts[pnt_c]); + assert(pnt_a < _sfc_pnts.size() && pnt_b < _sfc_pnts.size() && pnt_c < _sfc_pnts.size()); + _sfc_triangles.push_back(new Triangle(_sfc_pnts, pnt_a, pnt_b, pnt_c)); + _bv.update(*_sfc_pnts[pnt_a]); + _bv.update(*_sfc_pnts[pnt_b]); + _bv.update(*_sfc_pnts[pnt_c]); delete _sfc_grid; - _sfc_grid=NULL; + _sfc_grid = NULL; } -Surface* Surface::createSurface(const Polyline &ply) +Surface* Surface::createSurface(const Polyline& ply) { if (!ply.isClosed()) { - std::cout << "Error in Surface::createSurface() - Polyline is not closed..." << - std::endl; + std::cout << "Error in Surface::createSurface() - Polyline is not closed..." << std::endl; return NULL; } @@ -59,26 +58,26 @@ Surface* Surface::createSurface(const Polyline &ply) // create empty surface Surface* sfc(new Surface(ply.getPointsVec())); - Polygon* polygon (new Polygon (ply)); - polygon->computeListOfSimplePolygons (); + Polygon* polygon(new Polygon(ply)); + polygon->computeListOfSimplePolygons(); // create surfaces from simple polygons - const std::list& list_of_simple_polygons ( - polygon->getListOfSimplePolygons()); - for (std::list::const_iterator simple_polygon_it ( - list_of_simple_polygons.begin()); - simple_polygon_it != list_of_simple_polygons.end(); ++simple_polygon_it) + const std::list& list_of_simple_polygons(polygon->getListOfSimplePolygons()); + for (std::list::const_iterator simple_polygon_it(list_of_simple_polygons.begin()); + simple_polygon_it != list_of_simple_polygons.end(); + ++simple_polygon_it) { std::list triangles; std::cout << "triangulation of surface: ... " << std::flush; MathLib::EarClippingTriangulation(*simple_polygon_it, triangles); - std::cout << "done - " << triangles.size () << " triangles " << "\n"; + std::cout << "done - " << triangles.size() << " triangles " + << "\n"; // add Triangles to Surface - std::list::const_iterator it (triangles.begin()); + std::list::const_iterator it(triangles.begin()); while (it != triangles.end()) { - sfc->addTriangle ((*it)[0], (*it)[1], (*it)[2]); + sfc->addTriangle((*it)[0], (*it)[1], (*it)[2]); it++; } } @@ -87,37 +86,38 @@ Surface* Surface::createSurface(const Polyline &ply) } else { - std::cout << - "Error in Surface::createSurface() - Polyline consists of less than three points and therefore cannot be triangulated..." + std::cout << "Error in Surface::createSurface() - Polyline consists of less than three points and therefore " + "cannot be triangulated..." << std::endl; return NULL; } } -size_t Surface::getNTriangles () const +size_t Surface::getNTriangles() const { return _sfc_triangles.size(); } -const Triangle* Surface::operator[] (size_t i) const +const Triangle* Surface::operator[](size_t i) const { - assert (i < _sfc_triangles.size()); + assert(i < _sfc_triangles.size()); return _sfc_triangles[i]; } -bool Surface::isPntInBV (const double* pnt, double eps) const +bool Surface::isPntInBV(const double* pnt, double eps) const { - return _bv.containsPoint (pnt, eps); + return _bv.containsPoint(pnt, eps); } void Surface::initSurfaceGrid() { - if (_sfc_grid == NULL) { + if (_sfc_grid == NULL) + { _sfc_grid = new SurfaceGrid(this); } } -bool Surface::isPntInSfc (const double* pnt, double eps) const +bool Surface::isPntInSfc(const double* pnt, double eps) const { return _sfc_grid->isPntInSurface(pnt, eps); } @@ -139,11 +139,10 @@ int Surface::getTriangleIDOfPoint(const double* pnt) const { for (std::size_t i = 0; i < this->_sfc_triangles.size(); i++) { - if (_sfc_triangles[i]->containsPoint(pnt,0.1)) + if (_sfc_triangles[i]->containsPoint(pnt, 0.1)) return i; } return -1; } - } // end namespace diff --git a/GEO/Surface.h b/GEO/Surface.h index cb0069336..a1b419c8e 100644 --- a/GEO/Surface.h +++ b/GEO/Surface.h @@ -34,47 +34,44 @@ namespace GEOLIB class Surface : public GeoObject { public: - Surface (const std::vector &pnt_vec); - virtual ~Surface (); + Surface(const std::vector& pnt_vec); + virtual ~Surface(); /** * adds three indices describing a triangle and updates the bounding box * */ - void addTriangle (size_t pnt_a, size_t pnt_b, size_t pnt_c); + void addTriangle(size_t pnt_a, size_t pnt_b, size_t pnt_c); /// Triangulates a new surface based on closed polyline. - static Surface* createSurface(const Polyline &ply); + static Surface* createSurface(const Polyline& ply); /** * returns the number of triangles describing the Surface * */ - size_t getNTriangles () const; + size_t getNTriangles() const; /** \brief const access operator for the access to the i-th Triangle of the surface. */ - const Triangle* operator[] (size_t i) const; + const Triangle* operator[](size_t i) const; /** * is the given point in the bounding volume of the surface */ - bool isPntInBV (const double* pnt, double eps = std::numeric_limits::epsilon()) const; + bool isPntInBV(const double* pnt, double eps = std::numeric_limits::epsilon()) const; /** * is the given point pnt located in the surface * @param pnt the point * @return true if the point is contained in the surface */ - bool isPntInSfc (const double* pnt, - double eps = std::numeric_limits::epsilon()) const; + bool isPntInSfc(const double* pnt, double eps = std::numeric_limits::epsilon()) const; const std::vector* getPointVec() const { return &_sfc_pnts; } - /** * method allows access to the internal axis aligned bounding box * @return axis aligned bounding box */ - AABB const & getAABB () const { return _bv; } - + AABB const& getAABB() const { return _bv; } void initSurfaceGrid(); void calculateTriangleNormals() const; double const* getTriangleNormal(const std::size_t triangle_id) const; @@ -82,7 +79,7 @@ class Surface : public GeoObject protected: /** a vector of pointers to Points */ - const std::vector &_sfc_pnts; + const std::vector& _sfc_pnts; /** position of pointers to the geometric points */ std::vector _sfc_triangles; /** bounding volume is an axis aligned bounding box */ diff --git a/GEO/SurfaceGrid.cpp b/GEO/SurfaceGrid.cpp index 2c56c408e..f9438c84f 100644 --- a/GEO/SurfaceGrid.cpp +++ b/GEO/SurfaceGrid.cpp @@ -24,37 +24,41 @@ #include "StringTools.h" #endif -namespace GEOLIB { - -SurfaceGrid::SurfaceGrid(Surface const*const sfc) : - AABB(sfc->getAABB()), _triangles_in_grid_box(NULL) +namespace GEOLIB +{ +SurfaceGrid::SurfaceGrid(Surface const* const sfc) : AABB(sfc->getAABB()), _triangles_in_grid_box(NULL) { double delta[3] = {0.0, 0.0, 0.0}; - for (size_t k(0); k<3; k++) { + for (size_t k(0); k < 3; k++) + { // make the bounding box a little bit bigger, // such that the node with maximal coordinates fits into the grid _max_pnt[k] += std::abs(_max_pnt[k]) * 1e-6; - if (fabs(_max_pnt[k]) < std::numeric_limits::epsilon()) { + if (fabs(_max_pnt[k]) < std::numeric_limits::epsilon()) + { _max_pnt[k] = (_max_pnt[k] - _min_pnt[k]) * (1.0 + 1e-6); } delta[k] = _max_pnt[k] - _min_pnt[k]; } - if (delta[0] < std::numeric_limits::epsilon()) { + if (delta[0] < std::numeric_limits::epsilon()) + { const double max_delta(std::max(delta[1], delta[2])); _min_pnt[0] -= max_delta * 0.5e-3; _max_pnt[0] += max_delta * 0.5e-3; delta[0] = _max_pnt[0] - _min_pnt[0]; } - if (delta[1] < std::numeric_limits::epsilon()) { + if (delta[1] < std::numeric_limits::epsilon()) + { const double max_delta(std::max(delta[0], delta[2])); _min_pnt[1] -= max_delta * 0.5e-3; _max_pnt[1] += max_delta * 0.5e-3; delta[1] = _max_pnt[1] - _min_pnt[1]; } - if (delta[2] < std::numeric_limits::epsilon()) { + if (delta[2] < std::numeric_limits::epsilon()) + { const double max_delta(std::max(delta[0], delta[1])); _min_pnt[2] -= max_delta * 0.5e-3; _max_pnt[2] += max_delta * 0.5e-3; @@ -66,60 +70,87 @@ SurfaceGrid::SurfaceGrid(Surface const*const sfc) : // *** condition: n_triangles / (_n_steps[0] * _n_steps[1] * _n_steps[2]) < n_tris_per_box // *** with _n_steps[1] = _n_steps[0] * delta[1]/delta[0], _n_steps[2] = _n_steps[0] * delta[2]/delta[0] if (fabs(delta[0]) < std::numeric_limits::epsilon() - || fabs(delta[1]) < std::numeric_limits::epsilon() - || fabs(delta[2]) < std::numeric_limits::epsilon()) { + || fabs(delta[1]) < std::numeric_limits::epsilon() + || fabs(delta[2]) < std::numeric_limits::epsilon()) + { // 1d case y = z = 0 - if (fabs(delta[1]) < std::numeric_limits::epsilon() && fabs(delta[2]) < std::numeric_limits::epsilon()) { + if (fabs(delta[1]) < std::numeric_limits::epsilon() + && fabs(delta[2]) < std::numeric_limits::epsilon()) + { _n_steps[0] = static_cast(ceil(n_triangles / (double)n_tris_per_box)); _n_steps[1] = 1; _n_steps[2] = 1; - } else { + } + else + { // 1d case x = z = 0 - if (fabs(delta[0]) < std::numeric_limits::epsilon() && fabs(delta[2]) < std::numeric_limits::epsilon()) { + if (fabs(delta[0]) < std::numeric_limits::epsilon() + && fabs(delta[2]) < std::numeric_limits::epsilon()) + { _n_steps[0] = 1; _n_steps[1] = static_cast(ceil(n_triangles / (double)n_tris_per_box)); _n_steps[2] = 1; - } else { + } + else + { // 1d case x = y = 0 - if (fabs(delta[0]) < std::numeric_limits::epsilon() && fabs(delta[1]) < std::numeric_limits::epsilon()) { + if (fabs(delta[0]) < std::numeric_limits::epsilon() + && fabs(delta[1]) < std::numeric_limits::epsilon()) + { _n_steps[0] = 1; _n_steps[1] = 1; _n_steps[2] = static_cast(ceil(n_triangles / (double)n_tris_per_box)); - } else { + } + else + { // 2d cases // y = 0 - if (fabs(delta[1]) < std::numeric_limits::epsilon()) { - _n_steps[0] = static_cast(ceil(sqrt(n_triangles * delta[0] / (n_tris_per_box*delta[2])))); + if (fabs(delta[1]) < std::numeric_limits::epsilon()) + { + _n_steps[0] + = static_cast(ceil(sqrt(n_triangles * delta[0] / (n_tris_per_box * delta[2])))); _n_steps[1] = 1; _n_steps[2] = static_cast(ceil(_n_steps[0] * delta[2] / delta[0])); - } else { + } + else + { // z = 0 - if (fabs(delta[2]) < std::numeric_limits::epsilon()) { - _n_steps[0] = static_cast(ceil(sqrt(n_triangles * delta[0] / (n_tris_per_box*delta[1])))); + if (fabs(delta[2]) < std::numeric_limits::epsilon()) + { + _n_steps[0] + = static_cast(ceil(sqrt(n_triangles * delta[0] / (n_tris_per_box * delta[1])))); _n_steps[1] = static_cast(ceil(_n_steps[0] * delta[1] / delta[0])); _n_steps[2] = 1; - } else { + } + else + { // x = 0 _n_steps[0] = 1; - _n_steps[1] = static_cast(ceil(sqrt((double)n_triangles/n_tris_per_box * delta[1] / delta[2]))); - _n_steps[2] = static_cast(ceil(n_triangles * delta[2] / (n_tris_per_box*delta[1]))); + _n_steps[1] = static_cast( + ceil(sqrt((double)n_triangles / n_tris_per_box * delta[1] / delta[2]))); + _n_steps[2] + = static_cast(ceil(n_triangles * delta[2] / (n_tris_per_box * delta[1]))); } } } } } - } else { + } + else + { // 3d case - _n_steps[0] = static_cast(ceil(pow(n_triangles * delta[0]*delta[0] / (n_tris_per_box*delta[1]*delta[2]), 1. / 3.))); + _n_steps[0] = static_cast( + ceil(pow(n_triangles * delta[0] * delta[0] / (n_tris_per_box * delta[1] * delta[2]), 1. / 3.))); _n_steps[1] = static_cast(ceil(_n_steps[0] * std::min(delta[1] / delta[0], 100.0))); _n_steps[2] = static_cast(ceil(_n_steps[0] * std::min(delta[2] / delta[0], 100.0))); } - const size_t n_plane (_n_steps[0]*_n_steps[1]); - _triangles_in_grid_box = new std::vector [n_plane*_n_steps[2]]; + const size_t n_plane(_n_steps[0] * _n_steps[1]); + _triangles_in_grid_box = new std::vector[n_plane * _n_steps[2]]; // some frequently used expressions to fill the grid vectors - for (size_t k(0); k<3; k++) { + for (size_t k(0); k < 3; k++) + { _step_sizes[k] = delta[k] / _n_steps[k]; _inverse_step_sizes[k] = 1.0 / _step_sizes[k]; } @@ -136,39 +167,54 @@ SurfaceGrid::SurfaceGrid(Surface const*const sfc) : // fill the grid vectors size_t i_min, i_max, j_min, j_max, k_min, k_max; - for (size_t l(0); lgetPoint(0))); - i_min = i_max = static_cast((pnt[0]-_min_pnt[0]) * _inverse_step_sizes[0]); - j_min = j_max = static_cast((pnt[1]-_min_pnt[1]) * _inverse_step_sizes[1]); - k_min = k_max = static_cast((pnt[2]-_min_pnt[2]) * _inverse_step_sizes[2]); + for (size_t l(0); l < n_triangles; l++) + { + Triangle const* const tri((*sfc)[l]); + Point const& pnt(*(tri->getPoint(0))); + i_min = i_max = static_cast((pnt[0] - _min_pnt[0]) * _inverse_step_sizes[0]); + j_min = j_max = static_cast((pnt[1] - _min_pnt[1]) * _inverse_step_sizes[1]); + k_min = k_max = static_cast((pnt[2] - _min_pnt[2]) * _inverse_step_sizes[2]); - if (i_min >= _n_steps[0] || j_min >= _n_steps[1] || k_min >= _n_steps[2]) { - std::cout << "error computing indices " << "\n"; + if (i_min >= _n_steps[0] || j_min >= _n_steps[1] || k_min >= _n_steps[2]) + { + std::cout << "error computing indices " + << "\n"; } - for (size_t m(1); m<3; m++) { - Point const& pnt (*(tri->getPoint(m))); - const size_t i (static_cast((pnt[0]-_min_pnt[0]) * _inverse_step_sizes[0])); - const size_t j (static_cast((pnt[1]-_min_pnt[1]) * _inverse_step_sizes[1])); - const size_t k (static_cast((pnt[2]-_min_pnt[2]) * _inverse_step_sizes[2])); + for (size_t m(1); m < 3; m++) + { + Point const& pnt(*(tri->getPoint(m))); + const size_t i(static_cast((pnt[0] - _min_pnt[0]) * _inverse_step_sizes[0])); + const size_t j(static_cast((pnt[1] - _min_pnt[1]) * _inverse_step_sizes[1])); + const size_t k(static_cast((pnt[2] - _min_pnt[2]) * _inverse_step_sizes[2])); - if (i >= _n_steps[0] || j >= _n_steps[1] || k >= _n_steps[2]) { - std::cout << "error computing indices " << "\n"; + if (i >= _n_steps[0] || j >= _n_steps[1] || k >= _n_steps[2]) + { + std::cout << "error computing indices " + << "\n"; } - if (i < i_min) i_min = i; - if (i_max < i) i_max = i; - if (j < j_min) j_min = j; - if (j_max < j) j_max = j; - if (k < k_min) k_min = k; - if (k_max < k) k_max = k; + if (i < i_min) + i_min = i; + if (i_max < i) + i_max = i; + if (j < j_min) + j_min = j; + if (j_max < j) + j_max = j; + if (k < k_min) + k_min = k; + if (k_max < k) + k_max = k; } - for (size_t i(i_min); i<=i_max; i++) { - for (size_t j(j_min); j<=j_max; j++) { - for (size_t k(k_min); k<=k_max; k++) { - _triangles_in_grid_box[i + j*_n_steps[0]+k*n_plane].push_back (tri); + for (size_t i(i_min); i <= i_max; i++) + { + for (size_t j(j_min); j <= j_max; j++) + { + for (size_t k(k_min); k <= k_max; k++) + { + _triangles_in_grid_box[i + j * _n_steps[0] + k * n_plane].push_back(tri); } } } @@ -177,14 +223,15 @@ SurfaceGrid::SurfaceGrid(Surface const*const sfc) : #ifndef NDEBUG #ifdef DEBUGMESHNODESEARCH // write the triangles per grid cell as gli - if (_n_steps[2]*_n_steps[1]*_n_steps[0] > 1000) + if (_n_steps[2] * _n_steps[1] * _n_steps[0] > 1000) return; - for (std::size_t k(0); k<_n_steps[2]; k++) { - for (std::size_t j(0); j<_n_steps[1]; j++) { - for (std::size_t i(0); i<_n_steps[0]; i++) { - const std::size_t cell_id( - k*_n_steps[0]*_n_steps[1] + j*_n_steps[0] + i - ); + for (std::size_t k(0); k < _n_steps[2]; k++) + { + for (std::size_t j(0); j < _n_steps[1]; j++) + { + for (std::size_t i(0); i < _n_steps[0]; i++) + { + const std::size_t cell_id(k * _n_steps[0] * _n_steps[1] + j * _n_steps[0] + i); if (_triangles_in_grid_box[cell_id].empty()) continue; std::string fname("SurfaceGrid-"); @@ -193,71 +240,73 @@ SurfaceGrid::SurfaceGrid(Surface const*const sfc) : fname += number2str(j) + "-"; fname += number2str(k) + ".tin"; std::ofstream os_tri(fname.c_str()); - writeTrianglesInGridCell(i,j,k,os_tri); + writeTrianglesInGridCell(i, j, k, os_tri); os_tri.close(); } } } #endif #endif - } #ifndef NDEBUG #ifdef DEBUGMESHNODESEARCH -void SurfaceGrid::writeSurfaceGridData(std::ostream & os) const +void SurfaceGrid::writeSurfaceGridData(std::ostream& os) const { - const std::size_t n_grid_plane((_n_steps[0]+1)*(_n_steps[1]+1)); + const std::size_t n_grid_plane((_n_steps[0] + 1) * (_n_steps[1] + 1)); os << "#POINTS\n"; - for (std::size_t k=0; k<=_n_steps[2]; k++) { - for (std::size_t j=0; j<=_n_steps[1]; j++) { - for (std::size_t i=0; i<=_n_steps[0]; i++) { - os << k*n_grid_plane + j*(_n_steps[0]+1) + i << " " - << _min_pnt[0] + i * _step_sizes[0] << " " - << _min_pnt[1] + j * _step_sizes[1] << " " - << _min_pnt[2] + k * _step_sizes[2] << "\n"; + for (std::size_t k = 0; k <= _n_steps[2]; k++) + { + for (std::size_t j = 0; j <= _n_steps[1]; j++) + { + for (std::size_t i = 0; i <= _n_steps[0]; i++) + { + os << k * n_grid_plane + j * (_n_steps[0] + 1) + i << " " << _min_pnt[0] + i * _step_sizes[0] << " " + << _min_pnt[1] + j * _step_sizes[1] << " " << _min_pnt[2] + k * _step_sizes[2] << "\n"; } } } - const std::size_t n_steps_0(_n_steps[0]+1); - for (std::size_t k=0; k<_n_steps[2]; k++) { - for (std::size_t j=0; j<_n_steps[1]; j++) { - for (std::size_t i=0; i<_n_steps[0]; i++) { + const std::size_t n_steps_0(_n_steps[0] + 1); + for (std::size_t k = 0; k < _n_steps[2]; k++) + { + for (std::size_t j = 0; j < _n_steps[1]; j++) + { + for (std::size_t i = 0; i < _n_steps[0]; i++) + { os << "#POLYLINE\n"; os << " $NAME\n"; - os << " QUAD-" << k*n_grid_plane+j*n_steps_0+i << "\n"; + os << " QUAD-" << k * n_grid_plane + j * n_steps_0 + i << "\n"; os << " $POINTS\n"; - os << " " << k*n_grid_plane + j*n_steps_0 + i << "\n"; - os << " " << k*n_grid_plane + j*n_steps_0 + i+1 << "\n"; - os << " " << k*n_grid_plane + (j+1)*n_steps_0 + i+1 << "\n"; - os << " " << k*n_grid_plane + (j+1)*n_steps_0 + i << "\n"; - os << " " << k*n_grid_plane + j*n_steps_0 + i << "\n"; - os << " " << (k+1)*n_grid_plane + j*n_steps_0 + i << "\n"; - os << " " << (k+1)*n_grid_plane + j*n_steps_0 + i+1 << "\n"; - os << " " << k*n_grid_plane + j*n_steps_0 + i+1 << "\n"; - os << " " << (k+1)*n_grid_plane + j*n_steps_0 + i+1 << "\n"; - os << " " << (k+1)*n_grid_plane + (j+1)*n_steps_0 + i+1 << "\n"; - os << " " << k*n_grid_plane + (j+1)*n_steps_0 + i+1 << "\n"; - os << " " << (k+1)*n_grid_plane + (j+1)*n_steps_0 + i+1 << "\n"; - os << " " << (k+1)*n_grid_plane + (j+1)*n_steps_0 + i << "\n"; - os << " " << k*n_grid_plane + (j+1)*n_steps_0 + i << "\n"; - os << " " << (k+1)*n_grid_plane + (j+1)*n_steps_0 + i << "\n"; - os << " " << (k+1)*n_grid_plane + j*n_steps_0 + i << "\n"; + os << " " << k * n_grid_plane + j * n_steps_0 + i << "\n"; + os << " " << k * n_grid_plane + j * n_steps_0 + i + 1 << "\n"; + os << " " << k * n_grid_plane + (j + 1) * n_steps_0 + i + 1 << "\n"; + os << " " << k * n_grid_plane + (j + 1) * n_steps_0 + i << "\n"; + os << " " << k * n_grid_plane + j * n_steps_0 + i << "\n"; + os << " " << (k + 1) * n_grid_plane + j * n_steps_0 + i << "\n"; + os << " " << (k + 1) * n_grid_plane + j * n_steps_0 + i + 1 << "\n"; + os << " " << k * n_grid_plane + j * n_steps_0 + i + 1 << "\n"; + os << " " << (k + 1) * n_grid_plane + j * n_steps_0 + i + 1 << "\n"; + os << " " << (k + 1) * n_grid_plane + (j + 1) * n_steps_0 + i + 1 << "\n"; + os << " " << k * n_grid_plane + (j + 1) * n_steps_0 + i + 1 << "\n"; + os << " " << (k + 1) * n_grid_plane + (j + 1) * n_steps_0 + i + 1 << "\n"; + os << " " << (k + 1) * n_grid_plane + (j + 1) * n_steps_0 + i << "\n"; + os << " " << k * n_grid_plane + (j + 1) * n_steps_0 + i << "\n"; + os << " " << (k + 1) * n_grid_plane + (j + 1) * n_steps_0 + i << "\n"; + os << " " << (k + 1) * n_grid_plane + j * n_steps_0 + i << "\n"; } } } os << "#STOP\n"; } -void SurfaceGrid::writeTrianglesInGridCell( - std::size_t i, std::size_t j, std::size_t k, - std::ostream & os) const +void SurfaceGrid::writeTrianglesInGridCell(std::size_t i, std::size_t j, std::size_t k, std::ostream& os) const { - const std::size_t cell_id(k*_n_steps[0]*_n_steps[1] + j*_n_steps[0] + i); + const std::size_t cell_id(k * _n_steps[0] * _n_steps[1] + j * _n_steps[0] + i); std::vector const& tris(_triangles_in_grid_box[cell_id]); - if (! tris.empty()) { - for(std::size_t k(0); k((pnt[0]-_min_pnt[0]) * _inverse_step_sizes[0])); - const size_t j (static_cast((pnt[1]-_min_pnt[1]) * _inverse_step_sizes[1])); - const size_t k (static_cast((pnt[2]-_min_pnt[2]) * _inverse_step_sizes[2])); + const size_t i(static_cast((pnt[0] - _min_pnt[0]) * _inverse_step_sizes[0])); + const size_t j(static_cast((pnt[1] - _min_pnt[1]) * _inverse_step_sizes[1])); + const size_t k(static_cast((pnt[2] - _min_pnt[2]) * _inverse_step_sizes[2])); - if (i >= _n_steps[0] || j >= _n_steps[1] || k >= _n_steps[2]) { + if (i >= _n_steps[0] || j >= _n_steps[1] || k >= _n_steps[2]) + { return false; } - std::vector const& triangles(_triangles_in_grid_box[i + j*_n_steps[0]+k*_n_steps[0]*_n_steps[1]]); - bool nfound (true); + std::vector const& triangles( + _triangles_in_grid_box[i + j * _n_steps[0] + k * _n_steps[0] * _n_steps[1]]); + bool nfound(true); const size_t n_triangles(triangles.size()); - for (size_t k(0); k < n_triangles && nfound; k++) { - if (triangles[k]->containsPoint (pnt, eps)) { + for (size_t k(0); k < n_triangles && nfound; k++) + { + if (triangles[k]->containsPoint(pnt, eps)) + { nfound = false; } } @@ -288,7 +341,7 @@ bool SurfaceGrid::isPntInSurface(const double* pnt, double eps) const SurfaceGrid::~SurfaceGrid() { - delete [] _triangles_in_grid_box; + delete[] _triangles_in_grid_box; } } // end namespace GEOLIB diff --git a/GEO/SurfaceGrid.h b/GEO/SurfaceGrid.h index 128840992..b72441f03 100644 --- a/GEO/SurfaceGrid.h +++ b/GEO/SurfaceGrid.h @@ -18,15 +18,16 @@ // GEOLIB #include "AxisAlignedBoundingBox.h" -namespace GEOLIB { - +namespace GEOLIB +{ // forward declaration class Surface; class Triangle; -class SurfaceGrid : public AABB { +class SurfaceGrid : public AABB +{ public: - SurfaceGrid(Surface const*const sfc); + SurfaceGrid(Surface const* const sfc); virtual ~SurfaceGrid(); bool isPntInSurface(const double* pnt, double eps = 0) const; @@ -34,9 +35,8 @@ class SurfaceGrid : public AABB { private: #ifndef NDEBUG #ifdef DEBUGMESHNODESEARCH - void writeSurfaceGridData(std::ostream &os) const; - void writeTrianglesInGridCell(std::size_t i, std::size_t j, std::size_t k, - std::ostream & os) const; + void writeSurfaceGridData(std::ostream& os) const; + void writeTrianglesInGridCell(std::size_t i, std::size_t j, std::size_t k, std::ostream& os) const; #endif #endif double _step_sizes[3]; diff --git a/GEO/TemplatePoint.h b/GEO/TemplatePoint.h index c7e834ae8..f7fd832dc 100644 --- a/GEO/TemplatePoint.h +++ b/GEO/TemplatePoint.h @@ -28,34 +28,34 @@ namespace GEOLIB * \brief class-template for points can be instantiated by a numeric type. * \param T the coordinate type */ -template class TemplatePoint : public GeoObject +template +class TemplatePoint : public GeoObject { public: /** default constructor */ - TemplatePoint (); + TemplatePoint(); /** constructor - constructs a TemplatePoint object \param x1 value for the first coordinate \param x2 value for the second coordinate \param x3 value for the third coordinate */ - TemplatePoint (T x1, T x2, T x3); + TemplatePoint(T x1, T x2, T x3); /** constructor - constructs a TemplatePoint object \param x values for three coordinates */ - TemplatePoint (T const* x); + TemplatePoint(T const* x); /** * copy constructor - constructs a copy of the source object * @param src the source object * @return */ - TemplatePoint (TemplatePoint const& src); + TemplatePoint(TemplatePoint const& src); /** virtual destructor */ virtual ~TemplatePoint() {} - /** \brief const access operator * The access to the point coordinates is like the access to a field. Code example: * \code @@ -63,93 +63,80 @@ template class TemplatePoint : public GeoObject * double sqrNrm2 = point[0] * point[0] + point[1] * point[1] + point[2] + point[2]; * \endcode */ - const T& operator[] (size_t idx) const + const T& operator[](size_t idx) const { - assert (idx <= 2); + assert(idx <= 2); return _x[idx]; } /** \brief access operator (see book Effektiv C++ programmieren - subsection 1.3.2 ). * \sa const T& operator[] (size_t idx) const */ - T& operator[] (size_t idx) - { - return const_cast (static_cast (*this)[idx]); - } - + T& operator[](size_t idx) { return const_cast(static_cast(*this)[idx]); } /** returns an array containing the coordinates of the point */ - const T* getData () const { return _x; } - + const T* getData() const { return _x; } /** write point coordinates into stream (used from operator<<) * \param os a standard output stream */ - virtual void write (std::ostream &os) const - { - os << _x[0] << " " << _x[1] << " " << _x[2] << std::flush; - } - -// /** -// * write point coordinates into string -// */ -// virtual std::string write () const -// { -// std::ostringstream strStream; -// strStream << _x[0] << " " << _x[1] << " " << _x[2]; -// return strStream.str(); -// } + virtual void write(std::ostream& os) const { os << _x[0] << " " << _x[1] << " " << _x[2] << std::flush; } + // /** + // * write point coordinates into string + // */ + // virtual std::string write () const + // { + // std::ostringstream strStream; + // strStream << _x[0] << " " << _x[1] << " " << _x[2]; + // return strStream.str(); + // } /** read point coordinates into stream (used from operator>>) */ - virtual void read (std::istream &is) - { - is >> _x[0] >> _x[1] >> _x[2]; - } - + virtual void read(std::istream& is) { is >> _x[0] >> _x[1] >> _x[2]; } protected: T _x[3]; }; -template TemplatePoint::TemplatePoint() : - GeoObject() +template +TemplatePoint::TemplatePoint() : GeoObject() { _x[0] = static_cast(0); _x[1] = static_cast(0); _x[2] = static_cast(0); } -template TemplatePoint::TemplatePoint(T x1, T x2, T x3) : - GeoObject() +template +TemplatePoint::TemplatePoint(T x1, T x2, T x3) : GeoObject() { _x[0] = x1; _x[1] = x2; _x[2] = x3; } -template TemplatePoint::TemplatePoint (T const* x) : - GeoObject() +template +TemplatePoint::TemplatePoint(T const* x) : GeoObject() { for (size_t k(0); k < 3; k++) _x[k] = x[k]; } -template TemplatePoint::TemplatePoint (TemplatePoint const& src) : - GeoObject() +template +TemplatePoint::TemplatePoint(TemplatePoint const& src) : GeoObject() { - for (size_t k(0); k<3; k++) + for (size_t k(0); k < 3; k++) _x[k] = src._x[k]; } /** overload the output operator for class Point */ template -std::ostream& operator<< (std::ostream &os, const TemplatePoint &p) +std::ostream& operator<<(std::ostream& os, const TemplatePoint& p) { - p.write (os); + p.write(os); return os; } /** overload the input operator for class Point */ template -std::istream& operator>> (std::istream &is, TemplatePoint &p) +std::istream& operator>>(std::istream& is, TemplatePoint& p) { - p.read (is); + p.read(is); return is; } } // end namespace GEO diff --git a/GEO/TemplateVec.h b/GEO/TemplateVec.h index e2abe93f0..a39e1e556 100644 --- a/GEO/TemplateVec.h +++ b/GEO/TemplateVec.h @@ -23,7 +23,8 @@ namespace GEOLIB * * Instances are classes PolylineVec and SurfaceVec. * */ -template class TemplateVec +template +class TemplateVec { public: /** @@ -37,17 +38,18 @@ template class TemplateVec * the data_vec. */ - TemplateVec (const std::string &name, std::vector* data_vec, - std::map* elem_name_map = NULL) : - _name(name), _data_vec(data_vec), _name_id_map (elem_name_map) - {} + TemplateVec(const std::string& name, std::vector* data_vec, std::map* elem_name_map = NULL) + : _name(name), _data_vec(data_vec), _name_id_map(elem_name_map) + { + } /** * destructor, deletes all data elements */ - virtual ~TemplateVec () + virtual ~TemplateVec() { - for (size_t k(0); k < size(); k++) delete (*_data_vec)[k]; + for (size_t k(0); k < size(); k++) + delete (*_data_vec)[k]; delete _data_vec; delete _name_id_map; } @@ -55,47 +57,45 @@ template class TemplateVec /** sets the name of the vector of geometric objects * the data elements belonging to * \param n the name as standard string */ - void setName (const std::string & n) { _name = n; } + void setName(const std::string& n) { _name = n; } /** * the name, the data element belonging to * @return the name of the object */ - std::string getName () const { return _name; } - + std::string getName() const { return _name; } /** * @return the number of data elements */ - size_t size () const { return _data_vec->size(); } - + size_t size() const { return _data_vec->size(); } /** * get a pointer to a standard vector containing the data elements * @return the data elements */ - const std::vector* getVector () const { return _data_vec; } - + const std::vector* getVector() const { return _data_vec; } /** * search the vector of names for the ID of the geometric element with the given name * @param name the name of the geometric element * @param id the id of the geometric element * @return */ - bool getElementIDByName (const std::string& name, size_t &id) const + bool getElementIDByName(const std::string& name, size_t& id) const { - std::map::const_iterator it (_name_id_map->find (name)); + std::map::const_iterator it(_name_id_map->find(name)); if (it != _name_id_map->end()) { id = it->second; return true; } - else return false; + else + return false; } /// Returns an element with the given name. - const T* getElementByName (const std::string& name) const + const T* getElementByName(const std::string& name) const { size_t id; - bool ret (getElementIDByName (name, id)); + bool ret(getElementIDByName(name, id)); if (ret) return (*_data_vec)[id]; else @@ -111,11 +111,12 @@ template class TemplateVec * @return if there is name associated with the given id: * true, else false */ - bool getNameOfElementByID (size_t id, std::string& element_name) const + bool getNameOfElementByID(size_t id, std::string& element_name) const { - if (!_name_id_map) return false; + if (!_name_id_map) + return false; // search in map for id - std::map::const_iterator it (_name_id_map->begin()); + std::map::const_iterator it(_name_id_map->begin()); while (it != _name_id_map->end()) { if (it->second == id) @@ -129,10 +130,11 @@ template class TemplateVec } /// Return the name of an element based on its ID. - void setNameOfElementByID (size_t id, std::string& element_name) + void setNameOfElementByID(size_t id, std::string& element_name) { - if (!_name_id_map) return; - _name_id_map->insert( std::pair(element_name, id) ); + if (!_name_id_map) + return; + _name_id_map->insert(std::pair(element_name, id)); } /** @@ -143,25 +145,26 @@ template class TemplateVec * found and the data element has a name) * @return if element is found and has a name: true, else false */ - bool getNameOfElement (const T* data, std::string& name) const + bool getNameOfElement(const T* data, std::string& name) const { for (size_t k(0); k < _data_vec->size(); k++) if ((*_data_vec)[k] == data) - return getNameOfElementByID (k, name); + return getNameOfElementByID(k, name); return false; } /// Adds a new element to the vector. - virtual void push_back (T* data_element, std::string const* const name = NULL) + virtual void push_back(T* data_element, std::string const* const name = NULL) { - _data_vec->push_back (data_element); - if (name == NULL) return; + _data_vec->push_back(data_element); + if (name == NULL) + return; if (!name->empty()) { if (_name_id_map == NULL) - _name_id_map = new std::map ; - _name_id_map->insert (std::pair(*name, _data_vec->size() - 1)); + _name_id_map = new std::map; + _name_id_map->insert(std::pair(*name, _data_vec->size() - 1)); } } @@ -171,17 +174,18 @@ template class TemplateVec if (_name_id_map == NULL) _name_id_map = new std::map; - if ( !_name_id_map->empty()) + if (!_name_id_map->empty()) { for (std::map::iterator it = _name_id_map->begin(); it != _name_id_map->end(); ++it) if (it->second == id) { - _name_id_map->erase(it); //check if old name already exists and delete it + _name_id_map->erase(it); // check if old name already exists and delete it break; } } - if (!name.empty()) { - //insert new or revised name + if (!name.empty()) + { + // insert new or revised name _name_id_map->insert(std::pair(name, id)); } } @@ -189,10 +193,10 @@ template class TemplateVec protected: /** copy constructor doesn't have an implementation */ // compiler does not create a (possible unwanted) copy constructor - TemplateVec (const TemplateVec &); + TemplateVec(const TemplateVec&); /** assignment operator doesn't have an implementation */ // this way the compiler does not create a (possible unwanted) assignment operator - TemplateVec& operator= (const TemplateVec& rhs); + TemplateVec& operator=(const TemplateVec& rhs); /** the name of the object */ std::string _name; @@ -200,7 +204,7 @@ template class TemplateVec /** * pointer to a vector of data elements */ - std::vector * _data_vec; + std::vector* _data_vec; /** * store names associated with the element ids */ diff --git a/GEO/Triangle.cpp b/GEO/Triangle.cpp index abf7f6201..9b3c681eb 100644 --- a/GEO/Triangle.cpp +++ b/GEO/Triangle.cpp @@ -22,8 +22,7 @@ namespace GEOLIB { -Triangle::Triangle (std::vector const &pnt_vec) : - _pnts(pnt_vec), _initialized (false), _longest_edge (0.0) +Triangle::Triangle(std::vector const& pnt_vec) : _pnts(pnt_vec), _initialized(false), _longest_edge(0.0) { _pnt_ids[0] = std::numeric_limits::max(); _pnt_ids[1] = std::numeric_limits::max(); @@ -32,98 +31,93 @@ Triangle::Triangle (std::vector const &pnt_vec) : _normal_vector[i] = std::numeric_limits::max(); } -Triangle::Triangle (std::vector const &pnt_vec, size_t pnt_a, size_t pnt_b, size_t pnt_c) : - _pnts(pnt_vec), _initialized (true), _longest_edge (0.0) +Triangle::Triangle(std::vector const& pnt_vec, size_t pnt_a, size_t pnt_b, size_t pnt_c) + : _pnts(pnt_vec), _initialized(true), _longest_edge(0.0) { _pnt_ids[0] = pnt_a; _pnt_ids[1] = pnt_b; _pnt_ids[2] = pnt_c; - _longest_edge = MathLib::sqrDist (_pnts[_pnt_ids[0]], _pnts[_pnt_ids[1]]); - double tmp (MathLib::sqrDist (_pnts[_pnt_ids[1]], _pnts[_pnt_ids[2]])); + _longest_edge = MathLib::sqrDist(_pnts[_pnt_ids[0]], _pnts[_pnt_ids[1]]); + double tmp(MathLib::sqrDist(_pnts[_pnt_ids[1]], _pnts[_pnt_ids[2]])); if (tmp > _longest_edge) _longest_edge = tmp; - tmp = MathLib::sqrDist (_pnts[_pnt_ids[0]], _pnts[_pnt_ids[2]]); + tmp = MathLib::sqrDist(_pnts[_pnt_ids[0]], _pnts[_pnt_ids[2]]); if (tmp > _longest_edge) _longest_edge = tmp; - _longest_edge = sqrt (_longest_edge); + _longest_edge = sqrt(_longest_edge); calculateNormal(); } -void Triangle::setTriangle (size_t pnt_a, size_t pnt_b, size_t pnt_c) +void Triangle::setTriangle(size_t pnt_a, size_t pnt_b, size_t pnt_c) { - assert (pnt_a < _pnts.size() && pnt_b < _pnts.size() && pnt_c < _pnts.size()); + assert(pnt_a < _pnts.size() && pnt_b < _pnts.size() && pnt_c < _pnts.size()); _pnt_ids[0] = pnt_a; _pnt_ids[1] = pnt_b; _pnt_ids[2] = pnt_c; - _longest_edge = MathLib::sqrDist (_pnts[_pnt_ids[0]], _pnts[_pnt_ids[1]]); - double tmp (MathLib::sqrDist (_pnts[_pnt_ids[1]], _pnts[_pnt_ids[2]])); + _longest_edge = MathLib::sqrDist(_pnts[_pnt_ids[0]], _pnts[_pnt_ids[1]]); + double tmp(MathLib::sqrDist(_pnts[_pnt_ids[1]], _pnts[_pnt_ids[2]])); if (tmp > _longest_edge) _longest_edge = tmp; - tmp = MathLib::sqrDist (_pnts[_pnt_ids[0]], _pnts[_pnt_ids[2]]); + tmp = MathLib::sqrDist(_pnts[_pnt_ids[0]], _pnts[_pnt_ids[2]]); if (tmp > _longest_edge) _longest_edge = tmp; - _longest_edge = sqrt (_longest_edge); + _longest_edge = sqrt(_longest_edge); } -bool Triangle::containsPoint (const double* pnt, double eps) const +bool Triangle::containsPoint(const double* pnt, double eps) const { GEOLIB::Point const p(pnt); - return MathLib::isPointInTriangle(&p, - _pnts[_pnt_ids[0]], - _pnts[_pnt_ids[1]], - _pnts[_pnt_ids[2]], - eps); + return MathLib::isPointInTriangle(&p, _pnts[_pnt_ids[0]], _pnts[_pnt_ids[1]], _pnts[_pnt_ids[2]], eps); } -bool Triangle::containsPoint2D (const double* pnt) const +bool Triangle::containsPoint2D(const double* pnt) const { - GEOLIB::Point const& a (*(_pnts[_pnt_ids[0]])); - GEOLIB::Point const& b (*(_pnts[_pnt_ids[1]])); - GEOLIB::Point const& c (*(_pnts[_pnt_ids[2]])); + GEOLIB::Point const& a(*(_pnts[_pnt_ids[0]])); + GEOLIB::Point const& b(*(_pnts[_pnt_ids[1]])); + GEOLIB::Point const& c(*(_pnts[_pnt_ids[2]])); // criterion: p-a = u0 * (b-a) + u1 * (c-a); 0 <= u0, u1 <= 1, u0+u1 <= 1 - MathLib::Matrix mat (2,2); - mat(0,0) = b[0] - a[0]; - mat(0,1) = c[0] - a[0]; - mat(1,0) = b[1] - a[1]; - mat(1,1) = c[1] - a[1]; + MathLib::Matrix mat(2, 2); + mat(0, 0) = b[0] - a[0]; + mat(0, 1) = c[0] - a[0]; + mat(1, 0) = b[1] - a[1]; + mat(1, 1) = c[1] - a[1]; double y[2] = {pnt[0] - a[0], pnt[1] - a[1]}; - MathLib::GaussAlgorithm gauss (mat); - gauss.execute (y); + MathLib::GaussAlgorithm gauss(mat); + gauss.execute(y); - const double delta (std::numeric_limits::epsilon()); - const double upper (1 + delta); + const double delta(std::numeric_limits::epsilon()); + const double upper(1 + delta); // check if u0 and u1 fulfills the condition (with some delta) - if (-delta <= y[0] && y[0] <= upper && -delta <= y[1] && y[1] <= upper && y[0] + y[1] <= - upper) + if (-delta <= y[0] && y[0] <= upper && -delta <= y[1] && y[1] <= upper && y[0] + y[1] <= upper) return true; return false; } void getPlaneCoefficients(Triangle const& tri, double c[3]) { - GEOLIB::Point const& p0 (*(tri.getPoint(0))); - GEOLIB::Point const& p1 (*(tri.getPoint(1))); - GEOLIB::Point const& p2 (*(tri.getPoint(2))); - MathLib::Matrix mat (3,3); - mat(0,0) = p0[0]; - mat(0,1) = p0[1]; - mat(0,2) = 1.0; - mat(1,0) = p1[0]; - mat(1,1) = p1[1]; - mat(1,2) = 1.0; - mat(2,0) = p2[0]; - mat(2,1) = p2[1]; - mat(2,2) = 1.0; + GEOLIB::Point const& p0(*(tri.getPoint(0))); + GEOLIB::Point const& p1(*(tri.getPoint(1))); + GEOLIB::Point const& p2(*(tri.getPoint(2))); + MathLib::Matrix mat(3, 3); + mat(0, 0) = p0[0]; + mat(0, 1) = p0[1]; + mat(0, 2) = 1.0; + mat(1, 0) = p1[0]; + mat(1, 1) = p1[1]; + mat(1, 2) = 1.0; + mat(2, 0) = p2[0]; + mat(2, 1) = p2[1]; + mat(2, 2) = 1.0; c[0] = p0[2]; c[1] = p1[2]; c[2] = p2[2]; - MathLib::GaussAlgorithm gauss (mat); - gauss.execute (c); + MathLib::GaussAlgorithm gauss(mat); + gauss.execute(c); } void Triangle::calculateNormal() @@ -132,15 +126,15 @@ void Triangle::calculateNormal() GEOLIB::Point const& b(*(_pnts[_pnt_ids[1]])); GEOLIB::Point const& c(*(_pnts[_pnt_ids[2]])); - const double v1[3] = { b[0] - a[0], b[1] - a[1], b[2] - a[2] }; - const double v2[3] = { c[0] - a[0], c[1] - a[1], c[2] - a[2] }; + const double v1[3] = {b[0] - a[0], b[1] - a[1], b[2] - a[2]}; + const double v2[3] = {c[0] - a[0], c[1] - a[1], c[2] - a[2]}; MathLib::crossProd(v1, v2, _normal_vector); - //normalize normal vector + // normalize normal vector NormalizeVector(_normal_vector, 3); } -std::ostream & operator<<(std::ostream & out, GEOLIB::Triangle const& tri) +std::ostream& operator<<(std::ostream& out, GEOLIB::Triangle const& tri) { out << *tri.getPoint(0) << " " << *tri.getPoint(1) << " " << *tri.getPoint(2); return out; diff --git a/GEO/Triangle.h b/GEO/Triangle.h index bd5f443ba..62a3956fb 100644 --- a/GEO/Triangle.h +++ b/GEO/Triangle.h @@ -31,42 +31,42 @@ class Triangle /** * construction of object, initialization of reference to point vector */ - Triangle (std::vector const &pnt_vec); + Triangle(std::vector const& pnt_vec); /** * construction of object, initialization of reference to point vector, * saves the three indices describing a triangle */ - Triangle (std::vector const &pnt_vec, size_t pnt_a, size_t pnt_b, size_t pnt_c); + Triangle(std::vector const& pnt_vec, size_t pnt_a, size_t pnt_b, size_t pnt_c); /** * saves three indices describing a triangle * */ - void setTriangle (size_t pnt_a, size_t pnt_b, size_t pnt_c); + void setTriangle(size_t pnt_a, size_t pnt_b, size_t pnt_c); /** \brief const access operator to access the index * of the i-th triangle point */ - const size_t& operator[] (size_t i) const + const size_t& operator[](size_t i) const { - assert (i < 3); + assert(i < 3); return _pnt_ids[i]; } -// /** \brief access operator to access the index -// * of the i-th triangle point -// * */ -// size_t& operator[] (size_t i) { -// assert (i < 3); -// return _pnt_ids[i]; -// } + // /** \brief access operator to access the index + // * of the i-th triangle point + // * */ + // size_t& operator[] (size_t i) { + // assert (i < 3); + // return _pnt_ids[i]; + // } /** * \brief const access operator to access the i-th triangle Point */ - const Point* getPoint (size_t i) const + const Point* getPoint(size_t i) const { - assert (i < 3); + assert(i < 3); return _pnts[_pnt_ids[i]]; } @@ -77,27 +77,19 @@ class Triangle */ bool containsPoint(const double* pnt, double eps = 0) const; - bool containsPoint (const Point &pnt, double eps = 0) const - { - return containsPoint (pnt.getData(), eps); - } - + bool containsPoint(const Point& pnt, double eps = 0) const { return containsPoint(pnt.getData(), eps); } /** * projects the triangle points to the x-y-plane and * checks if point pnt is contained into the triangle * @param pnt the point to test for * @return true, if the point is into the projected triangle */ - bool containsPoint2D (const double* pnt) const; + bool containsPoint2D(const double* pnt) const; void calculateNormal(); - double const* getNormal() const - { - return _normal_vector; - } - + double const* getNormal() const { return _normal_vector; } protected: /** a vector of pointers to points */ - const std::vector &_pnts; + const std::vector& _pnts; /** position of pointers to the geometric points */ size_t _pnt_ids[3]; bool _initialized; @@ -105,9 +97,9 @@ class Triangle double _normal_vector[3]; }; -void getPlaneCoefficients(Triangle const & tri, double c[3]); +void getPlaneCoefficients(Triangle const& tri, double c[3]); -std::ostream & operator<<(std::ostream & out, GEOLIB::Triangle const& tri); +std::ostream& operator<<(std::ostream& out, GEOLIB::Triangle const& tri); } // end namespace GEOLIB diff --git a/GEO/geo_dom.cpp b/GEO/geo_dom.cpp index 6e54d296d..10706186b 100644 --- a/GEO/geo_dom.cpp +++ b/GEO/geo_dom.cpp @@ -21,7 +21,7 @@ #include "files0.h" #include "geo_dom.h" // Vector -std::vector domain_vector; //CC +std::vector domain_vector; // CC /************************************************************************** GeoLib-Method: CGLDomain::Insert @@ -61,9 +61,9 @@ CGLDomain::~CGLDomain(void) Programing: 07/2003 OK Implementation **************************************************************************/ -int CGLDomain::Read(char* data,FILE* f) +int CGLDomain::Read(char* data, FILE* f) { - int pos = 0,pos_s = 0; + int pos = 0, pos_s = 0; int p = 0; char* sub; int begin; @@ -73,20 +73,20 @@ int CGLDomain::Read(char* data,FILE* f) double ddummy; LineFeed(f); - FilePrintString(f,"; ------------------------------------------"); + FilePrintString(f, "; ------------------------------------------"); LineFeed(f); - FilePrintString(f,"; GeoLib - Domain"); + FilePrintString(f, "; GeoLib - Domain"); LineFeed(f); //--------------------------------------------------------------------- // Loop over all volumes - while (StrTestHash(&data[p += pos],&pos)) + while (StrTestHash(&data[p += pos], &pos)) { CGLDomain* m_domain = NULL; m_domain = new CGLDomain; /* Write keyword */ LineFeed(f); - FilePrintString(f,"#DOMAIN"); + FilePrintString(f, "#DOMAIN"); LineFeed(f); //------------------------------------------------------------------- // Check sub keywords @@ -98,7 +98,7 @@ int CGLDomain::Read(char* data,FILE* f) //----------------------------------------------------------------- if (!strcmp(name, "$NAME")) { - ok = (StrReadStr(name,&sub[p_sub],f,/*TFString,*/ &pos) && ok); + ok = (StrReadStr(name, &sub[p_sub], f, /*TFString,*/ &pos) && ok); LineFeed(f); m_domain->name = name; } @@ -106,13 +106,13 @@ int CGLDomain::Read(char* data,FILE* f) if (!strcmp(name, "$COORDINATES")) { pos_s = 0; - ok = (StrReadDouble(&ddummy,&sub[p_sub += pos_s],f,&pos_s) && ok); + ok = (StrReadDouble(&ddummy, &sub[p_sub += pos_s], f, &pos_s) && ok); m_domain->x_min = ddummy; - ok = (StrReadDouble(&ddummy,&sub[p_sub += pos_s],f,&pos_s) && ok); + ok = (StrReadDouble(&ddummy, &sub[p_sub += pos_s], f, &pos_s) && ok); m_domain->x_max = ddummy; - ok = (StrReadDouble(&ddummy,&sub[p_sub += pos_s],f,&pos_s) && ok); + ok = (StrReadDouble(&ddummy, &sub[p_sub += pos_s], f, &pos_s) && ok); m_domain->y_min = ddummy; - ok = (StrReadDouble(&ddummy,&sub[p_sub += pos_s],f,&pos_s) && ok); + ok = (StrReadDouble(&ddummy, &sub[p_sub += pos_s], f, &pos_s) && ok); m_domain->y_max = ddummy; LineFeed(f); } @@ -126,12 +126,12 @@ int CGLDomain::Read(char* data,FILE* f) return 1; } -int GEOReadDomain(char* data,int found,FILE* f) +int GEOReadDomain(char* data, int found, FILE* f) { CGLDomain* m_domain = NULL; - m_domain->Read(data,f); + m_domain->Read(data, f); found = found; - //delete(m_domain); + // delete(m_domain); return 1; } /************************************************************************** @@ -143,11 +143,11 @@ int GEOReadDomain(char* data,int found,FILE* f) CGLDomain* CGLDomain::Get(std::string name) { CGLDomain* m_domain; - std::vector::iterator p = domain_vector.begin(); //CC - while(p != domain_vector.end()) + std::vector::iterator p = domain_vector.begin(); // CC + while (p != domain_vector.end()) { m_domain = *p; - if(m_domain->name == name) + if (m_domain->name == name) return m_domain; ++p; } diff --git a/GEO/geo_dom.h b/GEO/geo_dom.h index ed9421cee..35b713878 100644 --- a/GEO/geo_dom.h +++ b/GEO/geo_dom.h @@ -34,17 +34,18 @@ class CGLDomain std::string name; long Insert(CGLDomain*); std::vector GetVector(void); + public: - double x_min,x_max; - double y_min,y_max; - double z_min,z_max; + double x_min, x_max; + double y_min, y_max; + double z_min, z_max; // constructor CGLDomain(void); // destructor ~CGLDomain(void); - int Read(char*,FILE*); + int Read(char*, FILE*); CGLDomain* Get(std::string); }; extern std::vector domain_vector; -extern int GEOReadDomain(char*,int,FILE*); +extern int GEOReadDomain(char*, int, FILE*); #endif diff --git a/GEO/geo_lib.cpp b/GEO/geo_lib.cpp index 63d6e5d53..92c08d0bd 100644 --- a/GEO/geo_lib.cpp +++ b/GEO/geo_lib.cpp @@ -32,12 +32,15 @@ using namespace std; extern void remove_white_space(string* buffer); -enum GEO_TYPES {GEO_POINT = 'P', \ - GEO_LINE = 'L', - GEO_POLYLINE = 'O', - GEO_SURFACE = 'S', - GEO_VOLUME = 'V', - GEO_DOMAIN = 'D'}; +enum GEO_TYPES +{ + GEO_POINT = 'P', + GEO_LINE = 'L', + GEO_POLYLINE = 'O', + GEO_SURFACE = 'S', + GEO_VOLUME = 'V', + GEO_DOMAIN = 'D' +}; /************************************************************************** GeoLib- Funktion: GEOLIB_Read_GeoLib @@ -50,11 +53,11 @@ enum GEO_TYPES {GEO_POINT = 'P', \ 10/2004 OK path_name_slash 09/2005 CC delete line lesen function **************************************************************************/ -void GEOLIB_Read_GeoLib(const std::string &file_name_path_base) +void GEOLIB_Read_GeoLib(const std::string& file_name_path_base) { // Points GEORemoveAllPoints(); - GEOReadPoints (file_name_path_base); + GEOReadPoints(file_name_path_base); // Polylines GEORemoveAllPolylines(); GEOReadPolylines(file_name_path_base); @@ -66,7 +69,7 @@ void GEOLIB_Read_GeoLib(const std::string &file_name_path_base) GEOReadVolumes(file_name_path_base); // Determine dependencies between GEO objects GEOSurfaceTopology(); - GEOCreateSurfacePointVector(); //OK + GEOCreateSurfacePointVector(); // OK } /************************************************************************* @@ -78,13 +81,13 @@ void GEOLIB_Read_GeoLib(const std::string &file_name_path_base) 09/2003 TK Erste Version 01/2005 OK GEORemovePolylines, GEORemoveAllSurfaces, GEORemoveVolumes **************************************************************************/ -void GEOLIB_Clear_GeoLib_Data () +void GEOLIB_Clear_GeoLib_Data() { GEORemoveAllPoints(); Clear_LineVector(); - GEORemoveAllPolylines(); //OK41 - GEORemoveAllSurfaces(); //OK41 CC change - GEORemoveAllVolumes(); //OK41 + GEORemoveAllPolylines(); // OK41 + GEORemoveAllSurfaces(); // OK41 CC change + GEORemoveAllVolumes(); // OK41 } /**************************************************************************/ /* GEOLIB - Funktion: GEO_Delete_DoublePoints @@ -101,21 +104,21 @@ void GEO_Delete_DoublePoints() { int j = 0, k = 0; long pointsvectorsize; - //WW long pointsvectorsize, linesvectorsize; + // WW long pointsvectorsize, linesvectorsize; long number_of_polylinepoints; long check_point; vector gli_points_vector; gli_points_vector = GetPointsVector(); - pointsvectorsize = (long) gli_points_vector.size(); + pointsvectorsize = (long)gli_points_vector.size(); vector gli_lines_vector; gli_lines_vector = GEOLIB_GetGLILines_Vector(); - //WW linesvectorsize = (long) gli_lines_vector.size(); + // WW linesvectorsize = (long) gli_lines_vector.size(); CGLPolyline* gl_polyline = NULL; vector polyline_vector; polyline_vector = GetPolylineVector(); - size_t polylinesvectorsize (polyline_vector.size()); + size_t polylinesvectorsize(polyline_vector.size()); vector::const_iterator p = polyline_vector.begin(); string Name; @@ -126,18 +129,18 @@ void GEO_Delete_DoublePoints() gl_polyline = *p; Name = gl_polyline->getName(); - number_of_polylinepoints = (long) gl_polyline->point_vector.size(); + number_of_polylinepoints = (long)gl_polyline->point_vector.size(); for (j = 0; j < number_of_polylinepoints; j++) { - //check_point = gl_polyline->point_vector[j]->old_id; - //gl_polyline->point_vector[j]->id = gli_points_vector[check_point]->new_id; + // check_point = gl_polyline->point_vector[j]->old_id; + // gl_polyline->point_vector[j]->id = gli_points_vector[check_point]->new_id; check_point = gl_polyline->point_vector[j]->id; check_point = gli_points_vector[check_point]->old_id; check_point = gli_points_vector[check_point]->new_id; gl_polyline->point_vector[j]->id = check_point; - //check_point = gli_points_vector[check_point]->old_id; + // check_point = gli_points_vector[check_point]->old_id; } for (j = 0; j < number_of_polylinepoints - 1; j++) @@ -145,14 +148,11 @@ void GEO_Delete_DoublePoints() for (k = 0; k < number_of_polylinepoints; k++) check_point = gl_polyline->point_vector[k]->id; - if (gl_polyline->point_vector[j]->id == gl_polyline->point_vector[j - + 1]->id) + if (gl_polyline->point_vector[j]->id == gl_polyline->point_vector[j + 1]->id) { - gl_polyline->point_vector.erase( - gl_polyline->point_vector.begin() + j + 1); + gl_polyline->point_vector.erase(gl_polyline->point_vector.begin() + j + 1); j--; - number_of_polylinepoints - = (long) gl_polyline->point_vector.size(); + number_of_polylinepoints = (long)gl_polyline->point_vector.size(); } } ++p; @@ -166,21 +166,19 @@ void GEO_Delete_DoublePoints() check_point = gli_points_vector[j]->first_identical_id; check_point = gli_points_vector[j]->id; - if (gli_points_vector[j]->old_id - != gli_points_vector[j]->first_identical_id) + if (gli_points_vector[j]->old_id != gli_points_vector[j]->first_identical_id) { gli_points_vector.erase(gli_points_vector.begin() + j); - pointsvectorsize = (long) gli_points_vector.size(); + pointsvectorsize = (long)gli_points_vector.size(); j--; } else gli_points_vector[j]->id = gli_points_vector[j]->new_id; - } GEOLIB_SetGLIPoints_Vector(gli_points_vector); gli_points_vector = GetPointsVector(); - pointsvectorsize = (long) gli_points_vector.size(); + pointsvectorsize = (long)gli_points_vector.size(); } /**************************************************************************/ @@ -251,17 +249,14 @@ void GEO_Serialize_Point_Numbers() for (j = 0; j < number_of_polylinepoints; j++) { check_point = gl_polyline->point_vector[j]->old_id; - //check_point = gl_polyline->point_vector[j]->new_id; - //check_point = gl_polyline->point_vector[j]->id; + // check_point = gl_polyline->point_vector[j]->new_id; + // check_point = gl_polyline->point_vector[j]->id; for (k = 0; k < pointsvectorsize; k++) if (check_point == gli_points_vector[k]->old_id) { - gl_polyline->point_vector[j]->id = - gli_points_vector[k]->new_id; - gl_polyline->point_vector[j]->old_id = - gli_points_vector[k]->new_id; - gl_polyline->point_vector[j]->new_id = - gli_points_vector[k]->new_id; + gl_polyline->point_vector[j]->id = gli_points_vector[k]->new_id; + gl_polyline->point_vector[j]->old_id = gli_points_vector[k]->new_id; + gl_polyline->point_vector[j]->new_id = gli_points_vector[k]->new_id; break; } } @@ -286,15 +281,15 @@ void GEO_Serialize_Point_Numbers() void GEO_Get_Min_Max_Distance_of_polyline_neighbor_points() { int i = 0, j = 0, l = 0; - //WW long pointsvectorsize + // WW long pointsvectorsize long polylinesvectorsize; long number_of_polylinepoints; - //WW long check_point; - double x1 = 0.0,y1 = 0.0,z1 = 0.0,seg_length = 0.0; - double x2 = 0.0,y2 = 0.0,z2 = 0.0; + // WW long check_point; + double x1 = 0.0, y1 = 0.0, z1 = 0.0, seg_length = 0.0; + double x2 = 0.0, y2 = 0.0, z2 = 0.0; vector gli_points_vector; gli_points_vector = GetPointsVector(); - //WW pointsvectorsize =(long)gli_points_vector.size(); + // WW pointsvectorsize =(long)gli_points_vector.size(); CGLPolyline* gl_polyline = NULL; vector polyline_vector; @@ -321,71 +316,49 @@ void GEO_Get_Min_Max_Distance_of_polyline_neighbor_points() number_of_polylinepoints = (long)gl_polyline->point_vector.size(); for (j = 0; j < number_of_polylinepoints; j++) - if (gli_points_vector[i]->id == gl_polyline->point_vector[j]->id) + if (gli_points_vector[i]->id == gl_polyline->point_vector[j]->id) { if (j < number_of_polylinepoints - 1) { - //WW check_point = gl_polyline->point_vector[j]->id; + // WW check_point = gl_polyline->point_vector[j]->id; x1 = gl_polyline->point_vector[j]->x; y1 = gl_polyline->point_vector[j]->y; z1 = gl_polyline->point_vector[j]->z; - //WW check_point = gl_polyline->point_vector[j+1]->id; + // WW check_point = gl_polyline->point_vector[j+1]->id; x2 = gl_polyline->point_vector[j + 1]->x; y2 = gl_polyline->point_vector[j + 1]->y; z2 = gl_polyline->point_vector[j + 1]->z; - seg_length = EuklVek3dDistCoor ( x1, - y1, - z1, - x2, - y2, - z2 ); + seg_length = EuklVek3dDistCoor(x1, y1, z1, x2, y2, z2); if (gli_points_vector[i]->min_seg_length == 0.0) - gli_points_vector[i]->min_seg_length = - seg_length; + gli_points_vector[i]->min_seg_length = seg_length; if (gli_points_vector[i]->max_seg_length == 0.0) - gli_points_vector[i]->max_seg_length = - seg_length; - - if (gli_points_vector[i]->min_seg_length > - seg_length) - gli_points_vector[i]->min_seg_length = - seg_length; - if (gli_points_vector[i]->max_seg_length < - seg_length) - gli_points_vector[i]->max_seg_length = - seg_length; + gli_points_vector[i]->max_seg_length = seg_length; + + if (gli_points_vector[i]->min_seg_length > seg_length) + gli_points_vector[i]->min_seg_length = seg_length; + if (gli_points_vector[i]->max_seg_length < seg_length) + gli_points_vector[i]->max_seg_length = seg_length; } if (j > 0) { - //WW check_point = gl_polyline->point_vector[j]->id; + // WW check_point = gl_polyline->point_vector[j]->id; x1 = gl_polyline->point_vector[j]->x; y1 = gl_polyline->point_vector[j]->y; z1 = gl_polyline->point_vector[j]->z; - //WW check_point = gl_polyline->point_vector[j-1]->id; + // WW check_point = gl_polyline->point_vector[j-1]->id; x2 = gl_polyline->point_vector[j - 1]->x; y2 = gl_polyline->point_vector[j - 1]->y; z2 = gl_polyline->point_vector[j - 1]->z; - seg_length = EuklVek3dDistCoor ( x1, - y1, - z1, - x2, - y2, - z2 ); + seg_length = EuklVek3dDistCoor(x1, y1, z1, x2, y2, z2); if (gli_points_vector[i]->min_seg_length == 0.0) - gli_points_vector[i]->min_seg_length = - seg_length; + gli_points_vector[i]->min_seg_length = seg_length; if (gli_points_vector[i]->max_seg_length == 0.0) - gli_points_vector[i]->max_seg_length = - seg_length; - - if (gli_points_vector[i]->min_seg_length > - seg_length) - gli_points_vector[i]->min_seg_length = - seg_length; - if (gli_points_vector[i]->max_seg_length < - seg_length) - gli_points_vector[i]->max_seg_length = - seg_length; + gli_points_vector[i]->max_seg_length = seg_length; + + if (gli_points_vector[i]->min_seg_length > seg_length) + gli_points_vector[i]->min_seg_length = seg_length; + if (gli_points_vector[i]->max_seg_length < seg_length) + gli_points_vector[i]->max_seg_length = seg_length; } } @@ -408,38 +381,35 @@ void GEO_Get_Min_Max_Distance_of_polyline_neighbor_points() void GEO_Get_Min_Distance_of_neighbor_points() { int i = 0, j = 0; - //WW long check_point; - double x1 = 0.0,y1 = 0.0,z1 = 0.0,seg_length = 0.0; - double x2 = 0.0,y2 = 0.0,z2 = 0.0; + // WW long check_point; + double x1 = 0.0, y1 = 0.0, z1 = 0.0, seg_length = 0.0; + double x2 = 0.0, y2 = 0.0, z2 = 0.0; vector gli_points_vector; gli_points_vector = GetPointsVector(); for (i = 0; i < (long)gli_points_vector.size(); i++) gli_points_vector[i]->min_seg_length = 0.0; - for (i = 0; i < (long)gli_points_vector.size(); i++) { for (j = 0; j < (long)gli_points_vector.size(); j++) - if (gli_points_vector[i]->id != gli_points_vector[j]->id) + if (gli_points_vector[i]->id != gli_points_vector[j]->id) { - //WW check_point = gli_points_vector[i]->id; + // WW check_point = gli_points_vector[i]->id; x1 = gli_points_vector[i]->x; y1 = gli_points_vector[i]->y; z1 = gli_points_vector[i]->z; - //WW check_point = gli_points_vector[j]->id; + // WW check_point = gli_points_vector[j]->id; x2 = gli_points_vector[j]->x; y2 = gli_points_vector[j]->y; z2 = gli_points_vector[j]->z; - seg_length = EuklVek3dDistCoor ( x1, y1, z1, x2, y2, z2 ); + seg_length = EuklVek3dDistCoor(x1, y1, z1, x2, y2, z2); if (gli_points_vector[i]->min_seg_length == 0.0) gli_points_vector[i]->min_seg_length = seg_length; if (gli_points_vector[i]->min_seg_length > seg_length) gli_points_vector[i]->min_seg_length = seg_length; } - - } } @@ -468,7 +438,6 @@ void GEO_Copy_Min_Distance_Of_Neighbor_Points_To_Mesh_Density() for (i = 0; i < (long)gli_points_vector.size(); i++) if (gli_points_vector[i]->mesh_density > gli_points_vector[i]->min_seg_length) gli_points_vector[i]->mesh_density = gli_points_vector[i]->min_seg_length; - } /**************************************************************************/ @@ -506,15 +475,15 @@ void GEO_Mesh_Density_BiSect() double GEO_Get_Min_PolySeg_length() { int j = 0, l = 0, hit = 0; - //WW long pointsvectorsize, + // WW long pointsvectorsize, long polylinesvectorsize; long number_of_polylinepoints; - //WW long check_point; - double x1 = 0.0,y1 = 0.0,z1 = 0.0,seg_length = 0.0; - double x2 = 0.0,y2 = 0.0,z2 = 0.0,seg_length_saved = 0.0; + // WW long check_point; + double x1 = 0.0, y1 = 0.0, z1 = 0.0, seg_length = 0.0; + double x2 = 0.0, y2 = 0.0, z2 = 0.0, seg_length_saved = 0.0; vector gli_points_vector; gli_points_vector = GetPointsVector(); - //WW pointsvectorsize =(long)gli_points_vector.size(); + // WW pointsvectorsize =(long)gli_points_vector.size(); CGLPolyline* gl_polyline = NULL; vector polyline_vector; @@ -532,17 +501,17 @@ double GEO_Get_Min_PolySeg_length() number_of_polylinepoints = (long)gl_polyline->point_vector.size(); for (j = 0; j < number_of_polylinepoints - 1; j++) { - //WW check_point = gl_polyline->point_vector[j]->id; + // WW check_point = gl_polyline->point_vector[j]->id; x1 = gl_polyline->point_vector[j]->x; y1 = gl_polyline->point_vector[j]->y; z1 = gl_polyline->point_vector[j]->z; - //WW check_point = gl_polyline->point_vector[j+1]->id; + // WW check_point = gl_polyline->point_vector[j+1]->id; x2 = gl_polyline->point_vector[j + 1]->x; y2 = gl_polyline->point_vector[j + 1]->y; z2 = gl_polyline->point_vector[j + 1]->z; - seg_length = EuklVek3dDistCoor ( x1, y1, z1, x2, y2, z2 ); + seg_length = EuklVek3dDistCoor(x1, y1, z1, x2, y2, z2); if (j == 0 && hit == 0) { @@ -571,15 +540,15 @@ double GEO_Get_Min_PolySeg_length() double GEO_Get_Max_PolySeg_length() { int j = 0, l = 0, hit = 0; - //WW long pointsvectorsize, + // WW long pointsvectorsize, long polylinesvectorsize; long number_of_polylinepoints; - //WW long check_point; - double x1 = 0.0,y1 = 0.0,z1 = 0.0,seg_length = 0.0; - double x2 = 0.0,y2 = 0.0,z2 = 0.0,seg_length_saved = 0.0; + // WW long check_point; + double x1 = 0.0, y1 = 0.0, z1 = 0.0, seg_length = 0.0; + double x2 = 0.0, y2 = 0.0, z2 = 0.0, seg_length_saved = 0.0; vector gli_points_vector; gli_points_vector = GetPointsVector(); - //WW pointsvectorsize =(long)gli_points_vector.size(); + // WW pointsvectorsize =(long)gli_points_vector.size(); CGLPolyline* gl_polyline = NULL; vector polyline_vector; @@ -597,17 +566,17 @@ double GEO_Get_Max_PolySeg_length() number_of_polylinepoints = (long)gl_polyline->point_vector.size(); for (j = 0; j < number_of_polylinepoints - 1; j++) { - //WW check_point = gl_polyline->point_vector[j]->id; + // WW check_point = gl_polyline->point_vector[j]->id; x1 = gl_polyline->point_vector[j]->x; y1 = gl_polyline->point_vector[j]->y; z1 = gl_polyline->point_vector[j]->z; - //WW check_point = gl_polyline->point_vector[j+1]->id; + // WW check_point = gl_polyline->point_vector[j+1]->id; x2 = gl_polyline->point_vector[j + 1]->x; y2 = gl_polyline->point_vector[j + 1]->y; z2 = gl_polyline->point_vector[j + 1]->z; - seg_length = EuklVek3dDistCoor ( x1, y1, z1, x2, y2, z2 ); + seg_length = EuklVek3dDistCoor(x1, y1, z1, x2, y2, z2); if (j == 0 && hit == 0) { @@ -637,13 +606,13 @@ void GEO_Polylines_per_Point() { int j = 0, l = 0; int nb_of_ply; - //WW long pointsvectorsize, + // WW long pointsvectorsize, long polylinesvectorsize; long number_of_polylinepoints; long check_point; vector gli_points_vector; gli_points_vector = GetPointsVector(); - //WW pointsvectorsize =(long)gli_points_vector.size(); + // WW pointsvectorsize =(long)gli_points_vector.size(); CGLPolyline* gl_polyline = NULL; vector polyline_vector; @@ -656,7 +625,6 @@ void GEO_Polylines_per_Point() for (l = 0; l < (long)gli_points_vector.size(); l++) gli_points_vector[l]->nb_of_ply = 0; - for (l = 0; l < polylinesvectorsize; l++) { gl_polyline = *p; @@ -668,8 +636,7 @@ void GEO_Polylines_per_Point() nb_of_ply = gli_points_vector[check_point]->nb_of_ply; nb_of_ply = gli_points_vector[check_point]->nb_of_ply = nb_of_ply + 1; - if(gl_polyline->point_vector[j]->id == gl_polyline->point_vector[0]->id && - j != 0) + if (gl_polyline->point_vector[j]->id == gl_polyline->point_vector[0]->id && j != 0) gli_points_vector[check_point]->nb_of_ply = nb_of_ply - 1; nb_of_ply = gli_points_vector[check_point]->nb_of_ply; @@ -693,19 +660,19 @@ void GEO_Set_Poly_Seg_Length(double min_seg_length, double max_seg_length) { int j = 0, l = 0, k = 0, i = 0; int j_old = 0; - //long pointsvectorsize, + // long pointsvectorsize, long polylinesvectorsize; - //WW long number_of_polylinepoints; + // WW long number_of_polylinepoints; long check_point; int nb_of_ply, nb_of_ply_1st, nb_of_ply_2nd; - double x1 = 0.0,y1 = 0.0,z1 = 0.0,seg_length = 0.0,seg_length_old = 0.0; - double x2 = 0.0,y2 = 0.0,z2 = 0.0; - double e_x,e_y,e_z,pmax_x,pmax_y,pmax_z; //WW ,pmin_x,pmin_y,pmin_z; - long check_point_id_1,check_point_id_2,check_point_id_3,check_point_id_4; + double x1 = 0.0, y1 = 0.0, z1 = 0.0, seg_length = 0.0, seg_length_old = 0.0; + double x2 = 0.0, y2 = 0.0, z2 = 0.0; + double e_x, e_y, e_z, pmax_x, pmax_y, pmax_z; // WW ,pmin_x,pmin_y,pmin_z; + long check_point_id_1, check_point_id_2, check_point_id_3, check_point_id_4; CGLPoint* m_point = NULL; vector gli_points_vector; gli_points_vector = GetPointsVector(); - //WW pointsvectorsize =(long)gli_points_vector.size(); + // WW pointsvectorsize =(long)gli_points_vector.size(); CGLPolyline* gl_polyline = NULL; vector polyline_vector; @@ -735,7 +702,7 @@ void GEO_Set_Poly_Seg_Length(double min_seg_length, double max_seg_length) x2 = gl_polyline->point_vector[j + 1]->x; y2 = gl_polyline->point_vector[j + 1]->y; z2 = gl_polyline->point_vector[j + 1]->z; - seg_length = EuklVek3dDistCoor ( x1, y1, z1, x2, y2, z2 ); + seg_length = EuklVek3dDistCoor(x1, y1, z1, x2, y2, z2); if (seg_length_old == seg_length && j_old == j) break; @@ -750,50 +717,40 @@ void GEO_Set_Poly_Seg_Length(double min_seg_length, double max_seg_length) pmax_y = y1 + (max_seg_length * e_y); pmax_z = z1 + (max_seg_length * e_z); /*Calculation Point with min distance*/ - //pmin_x = x1+(min_seg_length* e_x); - //pmin_y = y1+(min_seg_length* e_y); - //pmin_z = z1+(min_seg_length* e_z); + // pmin_x = x1+(min_seg_length* e_x); + // pmin_y = y1+(min_seg_length* e_y); + // pmin_z = z1+(min_seg_length* e_z); if (seg_length < min_seg_length) /*Delete */ { - if (gl_polyline->point_vector[j + 1]->id != - gl_polyline->point_vector[0]->id) + if (gl_polyline->point_vector[j + 1]->id != gl_polyline->point_vector[0]->id) { check_point = gl_polyline->point_vector[j + 1]->id; nb_of_ply = gli_points_vector[check_point]->nb_of_ply; - gl_polyline->point_vector.erase( - gl_polyline->point_vector.begin() + j + 1); + gl_polyline->point_vector.erase(gl_polyline->point_vector.begin() + j + 1); j--; - //WW number_of_polylinepoints = (long)gl_polyline->point_vector.size(); + // WW number_of_polylinepoints = (long)gl_polyline->point_vector.size(); } else { check_point = gl_polyline->point_vector[j]->id; nb_of_ply = gli_points_vector[check_point]->nb_of_ply; - gl_polyline->point_vector.erase( - gl_polyline->point_vector.begin() + j); + gl_polyline->point_vector.erase(gl_polyline->point_vector.begin() + j); j--; - //WW number_of_polylinepoints = (long)gl_polyline->point_vector.size(); + // WW number_of_polylinepoints = (long)gl_polyline->point_vector.size(); } if (nb_of_ply > 1) { - vector::const_iterator pp = - polyline_vector.begin(); + vector::const_iterator pp = polyline_vector.begin(); for (i = 0; i < (long)polyline_vector.size(); i++) { gl_polyline = *pp; - for (k = 0; - k < (long)gl_polyline->point_vector.size(); - k++) - if (gl_polyline->point_vector[k]->id == - check_point) + for (k = 0; k < (long)gl_polyline->point_vector.size(); k++) + if (gl_polyline->point_vector[k]->id == check_point) { - gl_polyline->point_vector.erase( - gl_polyline->point_vector. - begin() + - k); + gl_polyline->point_vector.erase(gl_polyline->point_vector.begin() + k); k--; } pp++; @@ -820,63 +777,36 @@ void GEO_Set_Poly_Seg_Length(double min_seg_length, double max_seg_length) m_point->nb_of_ply = 1; gli_points_vector.push_back(m_point); - gl_polyline->point_vector.insert( - gl_polyline->point_vector.begin() + j + 1, - gli_points_vector.end() - 1,gli_points_vector.end()); + gl_polyline->point_vector.insert(gl_polyline->point_vector.begin() + j + 1, gli_points_vector.end() - 1, + gli_points_vector.end()); - //WW number_of_polylinepoints = (long)gl_polyline->point_vector.size(); + // WW number_of_polylinepoints = (long)gl_polyline->point_vector.size(); if (nb_of_ply_1st > 1 && nb_of_ply_2nd > 1) { - vector::const_iterator pp = - polyline_vector.begin(); + vector::const_iterator pp = polyline_vector.begin(); for (i = 0; i < (long)polyline_vector.size(); i++) { gl_polyline = *pp; - for (k = 0; - k < (long)gl_polyline->point_vector.size() - 1; - k++) + for (k = 0; k < (long)gl_polyline->point_vector.size() - 1; k++) { - check_point_id_3 = - gl_polyline->point_vector[k]->id; - check_point_id_4 = - gl_polyline->point_vector[k + - 1]->id; - - if ((check_point_id_3 == - check_point_id_1 && - check_point_id_4 == - check_point_id_2) || - (check_point_id_3 == - check_point_id_2 && - check_point_id_4 == check_point_id_1)) + check_point_id_3 = gl_polyline->point_vector[k]->id; + check_point_id_4 = gl_polyline->point_vector[k + 1]->id; + + if ((check_point_id_3 == check_point_id_1 && check_point_id_4 == check_point_id_2) + || (check_point_id_3 == check_point_id_2 && check_point_id_4 == check_point_id_1)) { - gl_polyline->point_vector.insert( - gl_polyline->point_vector. - begin() + - k + 1, - gli_points_vector.end() - 1, - gli_points_vector.end()); - - check_point = - (long)gli_points_vector. - size() - 1; - check_point = - gli_points_vector[ - check_point]->id; - check_point = - (long)gli_points_vector. - size() - 1; - nb_of_ply = - gli_points_vector[ - check_point]-> - nb_of_ply; - check_point = - (long)gli_points_vector. - size() - 1; - gli_points_vector[check_point]-> - nb_of_ply = nb_of_ply++; + gl_polyline->point_vector.insert(gl_polyline->point_vector.begin() + k + 1, + gli_points_vector.end() - 1, + gli_points_vector.end()); + + check_point = (long)gli_points_vector.size() - 1; + check_point = gli_points_vector[check_point]->id; + check_point = (long)gli_points_vector.size() - 1; + nb_of_ply = gli_points_vector[check_point]->nb_of_ply; + check_point = (long)gli_points_vector.size() - 1; + gli_points_vector[check_point]->nb_of_ply = nb_of_ply++; k--; } @@ -886,8 +816,7 @@ void GEO_Set_Poly_Seg_Length(double min_seg_length, double max_seg_length) } gl_polyline = *p; j--; - if((pmax_x == x2 && pmax_y == y2 && - pmax_z == z2) || (pmax_x == x1 && pmax_y == y1 && pmax_z == z1)) + if ((pmax_x == x2 && pmax_y == y2 && pmax_z == z2) || (pmax_x == x1 && pmax_y == y1 && pmax_z == z1)) j++; } } @@ -925,8 +854,8 @@ void GEO_Write_GMSH_Input_File(const char* file_name) geo_file = fopen(file_name, "w+t"); /*GMSH-Properties:*/ - //fprintf(geo_file,"%s\n","Mesh.Algorithm = 3;"); - fprintf(geo_file,"%s\n","Mesh.Smoothing = 8;"); + // fprintf(geo_file,"%s\n","Mesh.Algorithm = 3;"); + fprintf(geo_file, "%s\n", "Mesh.Smoothing = 8;"); /*Points:*/ long pointsvectorsize; @@ -935,20 +864,20 @@ void GEO_Write_GMSH_Input_File(const char* file_name) vector gli_points_vector; gli_points_vector = GetPointsVector(); pointsvectorsize = (long)gli_points_vector.size(); - fprintf(geo_file,"%s\n","//Points"); + fprintf(geo_file, "%s\n", "//Points"); for (i = 0; i < pointsvectorsize; i++) { - fprintf(geo_file,"%s","Point("); - fprintf(geo_file,"%i",i); - fprintf(geo_file,"%s",") = {"); - fprintf(geo_file,"%g",gli_points_vector[i]->x); - fprintf(geo_file,"%s",", "); - fprintf(geo_file,"%g",gli_points_vector[i]->y); - fprintf(geo_file,"%s",", "); - fprintf(geo_file,"%g",gli_points_vector[i]->z); - fprintf(geo_file,"%s",", "); - fprintf(geo_file,"%g",gli_points_vector[i]->mesh_density); - fprintf(geo_file,"%s\n","};"); + fprintf(geo_file, "%s", "Point("); + fprintf(geo_file, "%i", i); + fprintf(geo_file, "%s", ") = {"); + fprintf(geo_file, "%g", gli_points_vector[i]->x); + fprintf(geo_file, "%s", ", "); + fprintf(geo_file, "%g", gli_points_vector[i]->y); + fprintf(geo_file, "%s", ", "); + fprintf(geo_file, "%g", gli_points_vector[i]->z); + fprintf(geo_file, "%s", ", "); + fprintf(geo_file, "%g", gli_points_vector[i]->mesh_density); + fprintf(geo_file, "%s\n", "};"); } /*Lines:*/ long linesvectorsize; @@ -956,22 +885,21 @@ void GEO_Write_GMSH_Input_File(const char* file_name) vector gli_lines_vector; gli_lines_vector = GEOLIB_GetGLILines_Vector(); linesvectorsize = (long)gli_lines_vector.size(); - fprintf(geo_file,"%s\n","//Lines"); + fprintf(geo_file, "%s\n", "//Lines"); /*Polylines:*/ long check_point; - long polylinesvectorsize, number_of_polylinepoints, number_of_polylinelines, - surfacepolyline_vectorlength; + long polylinesvectorsize, number_of_polylinepoints, number_of_polylinelines, surfacepolyline_vectorlength; int line_id_counter = 0; int line_id_counter_begin = 0; string Name; CGLPolyline* gl_polyline = NULL; - vector polyline_vector; //CC - polyline_vector = GetPolylineVector(); //CC - polylinesvectorsize = (long)polyline_vector.size(); //CC - vector::iterator p = polyline_vector.begin(); //CC - fprintf(geo_file,"%s\n","//Polylines"); + vector polyline_vector; // CC + polyline_vector = GetPolylineVector(); // CC + polylinesvectorsize = (long)polyline_vector.size(); // CC + vector::iterator p = polyline_vector.begin(); // CC + fprintf(geo_file, "%s\n", "//Polylines"); for (i = 0; i < polylinesvectorsize; i++) { @@ -989,51 +917,51 @@ void GEO_Write_GMSH_Input_File(const char* file_name) line_id_counter_begin = line_id_counter; point1 = gl_polyline->point_vector[j]->id; point2 = gl_polyline->point_vector[j + 1]->id; - fprintf(geo_file,"%s","Line("); - fprintf(geo_file,"%i",line_id_counter); - fprintf(geo_file,"%s",") = {"); - fprintf(geo_file,"%ld",point1); - fprintf(geo_file,"%s",", "); - fprintf(geo_file,"%ld",point2); - fprintf(geo_file,"%s\n","};"); + fprintf(geo_file, "%s", "Line("); + fprintf(geo_file, "%i", line_id_counter); + fprintf(geo_file, "%s", ") = {"); + fprintf(geo_file, "%ld", point1); + fprintf(geo_file, "%s", ", "); + fprintf(geo_file, "%ld", point2); + fprintf(geo_file, "%s\n", "};"); } - fprintf(geo_file,"%s","Line Loop("); - fprintf(geo_file,"%i",i); - fprintf(geo_file,"%s",") = {"); + fprintf(geo_file, "%s", "Line Loop("); + fprintf(geo_file, "%i", i); + fprintf(geo_file, "%s", ") = {"); line_id_counter = line_id_counter_begin; gl_polyline->setID(i); for (j = 0; j < number_of_polylinepoints - 1; j++) { - fprintf(geo_file,"%i",line_id_counter); + fprintf(geo_file, "%i", line_id_counter); line_id_counter++; if (j < number_of_polylinepoints - 2) - fprintf(geo_file,"%s",", "); + fprintf(geo_file, "%s", ", "); } - fprintf(geo_file,"%s\n","};"); + fprintf(geo_file, "%s\n", "};"); } - /*if $Lines*/ //Todo: benchmark test + /*if $Lines*/ // Todo: benchmark test if (number_of_polylinelines > 0) { for (j = 0; j < linesvectorsize; j++) { - fprintf(geo_file,"%s","Line("); - fprintf(geo_file,"%ld",gli_lines_vector[i]->gli_line_id); - fprintf(geo_file,"%s",") = {"); - fprintf(geo_file,"%ld",gli_lines_vector[i]->point1); - fprintf(geo_file,"%s",", "); - fprintf(geo_file,"%ld",gli_lines_vector[i]->point2); - fprintf(geo_file,"%s\n","};"); + fprintf(geo_file, "%s", "Line("); + fprintf(geo_file, "%ld", gli_lines_vector[i]->gli_line_id); + fprintf(geo_file, "%s", ") = {"); + fprintf(geo_file, "%ld", gli_lines_vector[i]->point1); + fprintf(geo_file, "%s", ", "); + fprintf(geo_file, "%ld", gli_lines_vector[i]->point2); + fprintf(geo_file, "%s\n", "};"); } for (j = 0; j < number_of_polylinelines; j++) { check_point = (gl_polyline->getLineVector())[j]->gli_line_id; - fprintf(geo_file,"%ld",check_point); + fprintf(geo_file, "%ld", check_point); if (j < number_of_polylinelines - 1) - fprintf(geo_file,"%s",", "); + fprintf(geo_file, "%s", ", "); } - fprintf(geo_file,"%s\n","};"); + fprintf(geo_file, "%s\n", "};"); } ++p; } @@ -1044,22 +972,22 @@ void GEO_Write_GMSH_Input_File(const char* file_name) Surface* gl_surface = NULL; vector surface_vector; CGLPolyline* sfc_polyline = NULL; - surface_vector = GetSurfaceVector(); //CC - surfacesvectorsize = (long)surface_vector.size(); //CC + surface_vector = GetSurfaceVector(); // CC + surfacesvectorsize = (long)surface_vector.size(); // CC vector::iterator ps = surface_vector.begin(); - fprintf(geo_file,"%s\n","//Surfaces"); + fprintf(geo_file, "%s\n", "//Surfaces"); for (i = 0; i < surfacesvectorsize; i++) { gl_surface = *ps; - fprintf(geo_file,"%s","Plane Surface("); - fprintf(geo_file,"%i",i); - fprintf(geo_file,"%s",") = {"); + fprintf(geo_file, "%s", "Plane Surface("); + fprintf(geo_file, "%i", i); + fprintf(geo_file, "%s", ") = {"); - //list::const_iterator pp = gl_surface->polyline_of_surface_list.begin();//CC + // list::const_iterator pp = gl_surface->polyline_of_surface_list.begin();//CC vector::iterator pp = gl_surface->polyline_of_surface_vector.begin(); - surfacepolyline_vectorlength = (long)gl_surface->polyline_of_surface_vector.size(); //CC - vector::iterator p2 = polyline_vector.begin(); //CC + surfacepolyline_vectorlength = (long)gl_surface->polyline_of_surface_vector.size(); // CC + vector::iterator p2 = polyline_vector.begin(); // CC sfc_polyline = *pp; for (j = 0; j < surfacepolyline_vectorlength; j++) { @@ -1067,16 +995,15 @@ void GEO_Write_GMSH_Input_File(const char* file_name) { gl_polyline = *p2; if (sfc_polyline->getName() == gl_polyline->getName()) - fprintf(geo_file,"%ld", - static_cast(gl_polyline->getID())); + fprintf(geo_file, "%ld", static_cast(gl_polyline->getID())); ++p2; } if (j < surfacepolyline_vectorlength - 1) - fprintf(geo_file,"%s",", "); + fprintf(geo_file, "%s", ", "); ++pp; } - fprintf(geo_file,"%s\n","};"); + fprintf(geo_file, "%s\n", "};"); ++ps; } @@ -1096,11 +1023,11 @@ void GEO_Write_GMSH_Input_File(const char* file_name) void GEOWrite(string file_name) { char file_name_char[1024]; - strcpy(file_name_char,file_name.c_str()); + strcpy(file_name_char, file_name.c_str()); // Points - GEOWritePoints(file_name_char); //CC + GEOWritePoints(file_name_char); // CC // Polylines - GEOWritePolylines(file_name_char); //CC + GEOWritePolylines(file_name_char); // CC // Surfaces GEOWriteSurfaces(file_name); // Volumes @@ -1113,6 +1040,6 @@ void GEOWrite(string file_name) const char* gli_file_name_char = 0; gli_file_name_char = gli_file_name.data(); gli_file = fopen(gli_file_name_char, "a"); - fprintf(gli_file,"%s","#STOP"); + fprintf(gli_file, "%s", "#STOP"); fclose(gli_file); } diff --git a/GEO/geo_lib.h b/GEO/geo_lib.h index ee8e3c6cb..8ad56a676 100644 --- a/GEO/geo_lib.h +++ b/GEO/geo_lib.h @@ -20,7 +20,13 @@ #ifndef geolib_INC #define geolib_INC -enum GEO_TYPE {GS_POINT,GS_POLYLINE,GS_SURFACE,GS_VOLUME}; +enum GEO_TYPE +{ + GS_POINT, + GS_POLYLINE, + GS_SURFACE, + GS_VOLUME +}; // C++ STL #include @@ -35,9 +41,9 @@ class GeoLib friend class Surface; }; -extern void GEOLIB_Read_GeoLib (const std::string &file_name_path_base); -extern void GEOLIB_Clear_GeoLib_Data (); -//OK +extern void GEOLIB_Read_GeoLib(const std::string& file_name_path_base); +extern void GEOLIB_Clear_GeoLib_Data(); +// OK #define GLI_FILE_EXTENSION ".gli" extern void GEO_Delete_DoublePoints(); // TODO: Implement new function from TK @@ -46,7 +52,7 @@ extern double GEO_Get_Min_PolySeg_length(); extern double GEO_Get_Max_PolySeg_length(); extern void GEO_Set_Poly_Seg_Length(double min_seg_length, double max_seg_length); extern void GEO_Write_GMSH_Input_File(const char* file_name); -extern void GEOWrite(std::string); //OK4.1 +extern void GEOWrite(std::string); // OK4.1 extern void GEO_Get_Min_Max_Distance_of_polyline_neighbor_points(); extern void GEO_Copy_Min_Distance_Of_Neighbor_Points_To_Mesh_Density(); extern void GEO_Get_Min_Distance_of_neighbor_points(); diff --git a/GEO/geo_lin.cpp b/GEO/geo_lin.cpp index 23b50d07a..8037435ca 100644 --- a/GEO/geo_lin.cpp +++ b/GEO/geo_lin.cpp @@ -95,7 +95,7 @@ CGLLine* CGLLine::GEOGetLine(long number) CGLLine* CGLLine::Exists() { long i = 0; - long node1,node2,node3,node4; + long node1, node2, node3, node4; long line_vector_length = (long)gli_lines_vector.size(); for (i = 0; i < line_vector_length; i++) @@ -104,7 +104,7 @@ CGLLine* CGLLine::Exists() node2 = gli_lines_vector[i]->point2; node3 = point1; node4 = point2; - if ( (node1 == node3) && (node2 == node4) ) + if ((node1 == node3) && (node2 == node4)) { gli_line_id = gli_lines_vector[i]->gli_line_id; m_point1 = gli_lines_vector[i]->m_point1; @@ -114,8 +114,8 @@ CGLLine* CGLLine::Exists() orientation = 1; return gli_lines_vector[i]; } - //if ( ((node1==point1)&&(node2==point2))||((node2==point1)&&(node1==point2)) ) - //return gli_lines_vector[i]; + // if ( ((node1==point1)&&(node2==point2))||((node2==point1)&&(node1==point2)) ) + // return gli_lines_vector[i]; } return NULL; } @@ -135,12 +135,10 @@ CGLLine* CGLLine::CheckLineOutPut() for (int j = 0; j < Size; j++) { CGLn = gli_lines_vector[j]; - if(CGLn->marked) // Already being output + if (CGLn->marked) // Already being output - if( ((m_point1->PointDis(CGLn->m_point1) < DistTol) - && (m_point2->PointDis(CGLn->m_point2) < DistTol)) - || ((m_point1->PointDis(CGLn->m_point2) < DistTol) - && (m_point2->PointDis(CGLn->m_point1) < DistTol))) + if (((m_point1->PointDis(CGLn->m_point1) < DistTol) && (m_point2->PointDis(CGLn->m_point2) < DistTol)) + || ((m_point1->PointDis(CGLn->m_point2) < DistTol) && (m_point2->PointDis(CGLn->m_point1) < DistTol))) return CGLn; } return NULL; diff --git a/GEO/geo_lin.h b/GEO/geo_lin.h index 69d0917ff..54abea519 100644 --- a/GEO/geo_lin.h +++ b/GEO/geo_lin.h @@ -17,7 +17,7 @@ class CGLLine { private: bool marked; // For mesh - friend class Surface; //WW + friend class Surface; // WW // kg44 needed for domain decomposition with PETSC bool for_ic; @@ -36,17 +36,17 @@ class CGLLine long no_msh_nodes; int mat_group; int display_mode; - //MSH + // MSH std::vector nodes_coor_vector; // kg44 needed for domain decomposition with PETSC - void SetConditionTypeIC(const bool value) { for_ic=value;} ; - bool GetConditionTypeIC() const {return for_ic;} ; - //Method + void SetConditionTypeIC(const bool value) { for_ic = value; }; + bool GetConditionTypeIC() const { return for_ic; }; + // Method CGLLine* GEOGetLine(long); CGLLine* CheckLineOutPut(); CGLLine* Exists(); // void SetRFIPointsClose();//MSH + geomathlib - //void CreateMSHLines(void);//MSH + // void CreateMSHLines(void);//MSH }; extern std::vector GEOLIB_GetGLILines_Vector(void); diff --git a/GEO/geo_mathlib.cpp b/GEO/geo_mathlib.cpp index 994271e27..936df2d65 100644 --- a/GEO/geo_mathlib.cpp +++ b/GEO/geo_mathlib.cpp @@ -37,9 +37,9 @@ 09/1997 AH Einbau der Funktion */ /**************************************************************************/ -double EuklVek3dDist ( double* x, double* y) +double EuklVek3dDist(double* x, double* y) { - return EuklVek3dDistCoor(x[0],x[1],x[2],y[0],y[1],y[2]); + return EuklVek3dDistCoor(x[0], x[1], x[2], y[0], y[1], y[2]); } /**************************************************************************/ @@ -62,8 +62,7 @@ double EuklVek3dDist ( double* x, double* y) */ /**************************************************************************/ -double EuklVek3dDistCoor ( double x1, double y1, double z1, \ - double x2, double y2, double z2 ) +double EuklVek3dDistCoor(double x1, double y1, double z1, double x2, double y2, double z2) { return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + (z2 - z1) * (z2 - z1)); } @@ -86,28 +85,28 @@ double EuklVek3dDistCoor ( double x1, double y1, double z1, \ 08/1998 AH Einbau der Funktion */ /**************************************************************************/ -double Vek3dDistCoor ( double x1, double y1, double z1, \ - double x2, double y2, double z2, int norm ) +double Vek3dDistCoor(double x1, double y1, double z1, double x2, double y2, double z2, int norm) { double d; switch (norm) { - case 0: - d = fabs(x2 - x1); - if ( fabs(y2 - y1) > d ) - d = fabs(y2 - y1); - if ( fabs(z2 - z1) > d ) - d = fabs(z2 - z1); - return d; - - case 1: - return fabs(x2 - x1) + fabs(y2 - y1) + fabs(z2 - z1); - - case 2: - return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + (z2 - z1) * (z2 - z1)); - - default: return -1.; + case 0: + d = fabs(x2 - x1); + if (fabs(y2 - y1) > d) + d = fabs(y2 - y1); + if (fabs(z2 - z1) > d) + d = fabs(z2 - z1); + return d; + + case 1: + return fabs(x2 - x1) + fabs(y2 - y1) + fabs(z2 - z1); + + case 2: + return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + (z2 - z1) * (z2 - z1)); + + default: + return -1.; } } /************************************************************************** @@ -162,7 +161,7 @@ double MSkalarprodukt(double* vec1, double* vec2, long g) #else return cblas_ddot(g, vec1, 1, vec2, 1); #endif -} /* extern double MSkalarprodukt */ +} /* extern double MSkalarprodukt */ /*************************************************************************** GEO MathLib - Funktion: M4Determinante Aufgabe: @@ -179,7 +178,7 @@ double MSkalarprodukt(double* vec1, double* vec2, long g) double M4Determinante(double* m) { double determinante = 0.0; - double A11[9],A12[9],A13[9],A14[9]; + double A11[9], A12[9], A13[9], A14[9]; A11[0] = m[5]; A11[1] = m[6]; @@ -221,26 +220,24 @@ double M4Determinante(double* m) A14[7] = m[10]; A14[8] = m[11]; - determinante = +1.0 * M3Determinante(A11) \ - - 1.0 * M3Determinante(A12) \ - + 1.0 * M3Determinante(A13) \ + determinante = +1.0 * M3Determinante(A11) - 1.0 * M3Determinante(A12) + 1.0 * M3Determinante(A13) - 1.0 * M3Determinante(A14); return determinante; } -double CalcTetraederVolume(double* x,double* y,double* z) +double CalcTetraederVolume(double* x, double* y, double* z) { static double mat4x4[16]; - mat4x4[0] = 1.0; - mat4x4[1] = x[0]; - mat4x4[2] = y[0]; - mat4x4[3] = z[0]; - mat4x4[4] = 1.0; - mat4x4[5] = x[1]; - mat4x4[6] = y[1]; - mat4x4[7] = z[1]; - mat4x4[8] = 1.0; - mat4x4[9] = x[2]; + mat4x4[0] = 1.0; + mat4x4[1] = x[0]; + mat4x4[2] = y[0]; + mat4x4[3] = z[0]; + mat4x4[4] = 1.0; + mat4x4[5] = x[1]; + mat4x4[6] = y[1]; + mat4x4[7] = z[1]; + mat4x4[8] = 1.0; + mat4x4[9] = x[2]; mat4x4[10] = y[2]; mat4x4[11] = z[2]; mat4x4[12] = 1.0; @@ -249,19 +246,19 @@ double CalcTetraederVolume(double* x,double* y,double* z) mat4x4[15] = z[3]; return fabs(M4Determinante(mat4x4)) / 6.; } -double CalcPyramidVolume(double* x,double* y,double* z) +double CalcPyramidVolume(double* x, double* y, double* z) { -/* - x[0]=1.0; y[0]=-1.0; z[0]=0.0; - x[1]=1.0; y[1]=1.0; z[1]=0.0; - x[2]=-1.0; y[2]=1.0; z[2]=0.0; - x[3]=-1.0; y[3]=-1.0; z[3]=0.0; - x[4]=0.0; y[4]=0.0; z[4]=1.0; - */ - //double hight + /* + x[0]=1.0; y[0]=-1.0; z[0]=0.0; + x[1]=1.0; y[1]=1.0; z[1]=0.0; + x[2]=-1.0; y[2]=1.0; z[2]=0.0; + x[3]=-1.0; y[3]=-1.0; z[3]=0.0; + x[4]=0.0; y[4]=0.0; z[4]=1.0; + */ + // double hight double volume; - double p1[3],p2[3],p3[3],p5[3],proj[3]; + double p1[3], p2[3], p3[3], p5[3], proj[3]; //-------------------------------------------------------------- // tet version p1[0] = x[0]; @@ -277,10 +274,10 @@ double CalcPyramidVolume(double* x,double* y,double* z) p5[1] = y[4]; p5[2] = z[4]; - //WW hight = - MCalcProjectionOfPointOnPlane(p5,p1,p2,p3,proj); - double xt[4],yt[4],zt[4]; - double volume1,volume2,volume3,volume4; + // WW hight = + MCalcProjectionOfPointOnPlane(p5, p1, p2, p3, proj); + double xt[4], yt[4], zt[4]; + double volume1, volume2, volume3, volume4; xt[0] = x[0]; xt[1] = x[1]; xt[2] = x[4]; @@ -293,7 +290,7 @@ double CalcPyramidVolume(double* x,double* y,double* z) zt[1] = z[1]; zt[2] = z[4]; zt[3] = proj[2]; - volume1 = CalcTetraederVolume(xt,yt,zt); + volume1 = CalcTetraederVolume(xt, yt, zt); xt[0] = x[1]; xt[1] = x[2]; xt[2] = x[4]; @@ -306,7 +303,7 @@ double CalcPyramidVolume(double* x,double* y,double* z) zt[1] = z[2]; zt[2] = z[4]; zt[3] = proj[2]; - volume2 = CalcTetraederVolume(xt,yt,zt); + volume2 = CalcTetraederVolume(xt, yt, zt); xt[0] = x[2]; xt[1] = x[3]; xt[2] = x[4]; @@ -319,7 +316,7 @@ double CalcPyramidVolume(double* x,double* y,double* z) zt[1] = z[3]; zt[2] = z[4]; zt[3] = proj[2]; - volume3 = CalcTetraederVolume(xt,yt,zt); + volume3 = CalcTetraederVolume(xt, yt, zt); xt[0] = x[3]; xt[1] = x[0]; xt[2] = x[4]; @@ -332,24 +329,24 @@ double CalcPyramidVolume(double* x,double* y,double* z) zt[1] = z[0]; zt[2] = z[4]; zt[3] = proj[2]; - volume4 = CalcTetraederVolume(xt,yt,zt); + volume4 = CalcTetraederVolume(xt, yt, zt); volume = fabs(volume1) + fabs(volume2) + fabs(volume3) + fabs(volume4); return volume; } -double CalcPrismVolume(double* x,double* y,double* z) +double CalcPrismVolume(double* x, double* y, double* z) { - double tet1,tet2,tet3,prism; + double tet1, tet2, tet3, prism; double mat4x4[16]; - mat4x4[0] = 1.0; - mat4x4[1] = x[0]; - mat4x4[2] = y[0]; - mat4x4[3] = z[0]; - mat4x4[4] = 1.0; - mat4x4[5] = x[1]; - mat4x4[6] = y[1]; - mat4x4[7] = z[1]; - mat4x4[8] = 1.0; - mat4x4[9] = x[2]; + mat4x4[0] = 1.0; + mat4x4[1] = x[0]; + mat4x4[2] = y[0]; + mat4x4[3] = z[0]; + mat4x4[4] = 1.0; + mat4x4[5] = x[1]; + mat4x4[6] = y[1]; + mat4x4[7] = z[1]; + mat4x4[8] = 1.0; + mat4x4[9] = x[2]; mat4x4[10] = y[2]; mat4x4[11] = z[2]; mat4x4[12] = 1.0; @@ -357,16 +354,16 @@ double CalcPrismVolume(double* x,double* y,double* z) mat4x4[14] = y[3]; mat4x4[15] = z[3]; tet1 = fabs(M4Determinante(mat4x4)) / 6.; - mat4x4[0] = 1.0; - mat4x4[1] = x[1]; - mat4x4[2] = y[1]; - mat4x4[3] = z[1]; - mat4x4[4] = 1.0; - mat4x4[5] = x[2]; - mat4x4[6] = y[2]; - mat4x4[7] = z[2]; - mat4x4[8] = 1.0; - mat4x4[9] = x[3]; + mat4x4[0] = 1.0; + mat4x4[1] = x[1]; + mat4x4[2] = y[1]; + mat4x4[3] = z[1]; + mat4x4[4] = 1.0; + mat4x4[5] = x[2]; + mat4x4[6] = y[2]; + mat4x4[7] = z[2]; + mat4x4[8] = 1.0; + mat4x4[9] = x[3]; mat4x4[10] = y[3]; mat4x4[11] = z[3]; mat4x4[12] = 1.0; @@ -374,16 +371,16 @@ double CalcPrismVolume(double* x,double* y,double* z) mat4x4[14] = y[4]; mat4x4[15] = z[4]; tet2 = fabs(M4Determinante(mat4x4)) / 6.; - mat4x4[0] = 1.0; - mat4x4[1] = x[2]; - mat4x4[2] = y[2]; - mat4x4[3] = z[2]; - mat4x4[4] = 1.0; - mat4x4[5] = x[3]; - mat4x4[6] = y[3]; - mat4x4[7] = z[3]; - mat4x4[8] = 1.0; - mat4x4[9] = x[4]; + mat4x4[0] = 1.0; + mat4x4[1] = x[2]; + mat4x4[2] = y[2]; + mat4x4[3] = z[2]; + mat4x4[4] = 1.0; + mat4x4[5] = x[3]; + mat4x4[6] = y[3]; + mat4x4[7] = z[3]; + mat4x4[8] = 1.0; + mat4x4[9] = x[4]; mat4x4[10] = y[4]; mat4x4[11] = z[4]; mat4x4[12] = 1.0; @@ -419,15 +416,15 @@ double MCalcProjectionOfPointOnPlane(double* pt, double* e1, double* e2, double* double vec1[3], vec2[3], vec3[3], normal[3], abstand, volume, area; /* 1. Ebenen-Vektor */ - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) vec1[i] = e2[i] - e1[i]; /* 2. Ebenen-Vektor */ - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) vec2[i] = e3[i] - e1[i]; /* Ebene-Punkt-Vektor */ - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) vec3[i] = pt[i] - e1[i]; /* Normalenvektor */ @@ -451,14 +448,14 @@ double MCalcProjectionOfPointOnPlane(double* pt, double* e1, double* e2, double* abstand = volume / (area + MKleinsteZahlen); /* Normierter Normalen-Vektor */ - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) normal[i] /= (area + MKleinsteZahlen); if (MSkalarprodukt(normal, vec3, 3) > 0.) - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) proj[i] = pt[i] - fabs(abstand) * normal[i]; else - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) proj[i] = pt[i] + fabs(abstand) * normal[i]; return abstand; @@ -479,11 +476,11 @@ double MCalcProjectionOfPointOnPlane(double* pt, double* e1, double* e2, double* double M3Determinante(double* m) { - return m[0] * m[4] * m[8] + m[1] * m[5] * m[6] + m[2] * m[3] * m[7] - - m[2] * m[4] * m[6] - m[0] * m[5] * m[7] - m[1] * m[3] * m[8]; + return m[0] * m[4] * m[8] + m[1] * m[5] * m[6] + m[2] * m[3] * m[7] - m[2] * m[4] * m[6] - m[0] * m[5] * m[7] + - m[1] * m[3] * m[8]; } -double MCalcDistancePointToPoint(double* pt1,double* pt2) +double MCalcDistancePointToPoint(double* pt1, double* pt2) { double vec[3]; @@ -491,7 +488,7 @@ double MCalcDistancePointToPoint(double* pt1,double* pt2) vec[1] = pt1[1] - pt2[1]; vec[2] = pt1[2] - pt2[2]; - return MBtrgVec(vec,3); + return MBtrgVec(vec, 3); } /************************************************************************** @@ -517,11 +514,12 @@ long* TOLSortNodes1(long* nodes, double* criterium, int anz) long tempnode; double temp; - do { + do + { flag = 0; nummer++; for (i = 0; i < (anz - nummer); i++) - if ( criterium[i] < criterium[i + 1]) + if (criterium[i] < criterium[i + 1]) { flag = 1; tempnode = nodes[i]; @@ -583,29 +581,28 @@ int MPhi2D(double* vf, double r, double s) Programmaenderungen: 05/2005 RFW Implementierung ***************************************************************************/ -bool LineSegmentIntersection(vector xline1, vector yline1, - vector xline2, vector yline2, +bool LineSegmentIntersection(vector xline1, vector yline1, vector xline2, vector yline2, vector& intercept) { - double determinant, t1; //WW, t2; + double determinant, t1; // WW, t2; bool crosses = false; - determinant = ( (yline2[1] - yline2[0]) * (xline1[1] - xline1[0]) - - (xline2[1] - xline2[0]) * (yline1[1] - yline1[0]) ); - if(determinant == 0) + determinant + = ((yline2[1] - yline2[0]) * (xline1[1] - xline1[0]) - (xline2[1] - xline2[0]) * (yline1[1] - yline1[0])); + if (determinant == 0) crosses = false; else { - t1 = ( (xline2[1] - xline2[0]) * (yline1[0] - yline2[0]) - - (yline2[1] - yline2[0]) * (xline1[0] - xline2[0]) ) / determinant; + t1 = ((xline2[1] - xline2[0]) * (yline1[0] - yline2[0]) - (yline2[1] - yline2[0]) * (xline1[0] - xline2[0])) + / determinant; - if(t1 < 0 || t1 > 1) + if (t1 < 0 || t1 > 1) crosses = false; else { crosses = true; - intercept.push_back( xline1[0] + t1 * (xline1[1] - xline1[0]) ); - intercept.push_back( yline1[0] + t1 * (yline1[1] - yline1[0]) ); + intercept.push_back(xline1[0] + t1 * (xline1[1] - xline1[0])); + intercept.push_back(yline1[0] + t1 * (yline1[1] - yline1[0])); } } diff --git a/GEO/geo_mathlib.h b/GEO/geo_mathlib.h index cd4ad63cc..149ace9dd 100644 --- a/GEO/geo_mathlib.h +++ b/GEO/geo_mathlib.h @@ -24,36 +24,28 @@ #define CSV_FILE_EXTENSIONS ".csv" #define TEC_FILE_EXTENSIONS ".tec" -extern double EuklVek3dDist( double* x, double* y ); -extern double EuklVek3dDistCoor(double x1,double y1,double z1,double x2,double y2,double z2); -extern double Vek3dDistCoor(double x1,double y1,double z1,double x2,double y2,double z2,int norm); -extern int M3KreuzProdukt( double* vec1, double* vec2, double* vec); +extern double EuklVek3dDist(double* x, double* y); +extern double EuklVek3dDistCoor(double x1, double y1, double z1, double x2, double y2, double z2); +extern double Vek3dDistCoor(double x1, double y1, double z1, double x2, double y2, double z2, int norm); +extern int M3KreuzProdukt(double* vec1, double* vec2, double* vec); extern double MBtrgVec(double* vec, long n); -extern double MSkalarprodukt ( double* vec1, double* vec2, long g ); -extern double M3Determinante ( double* m ); -extern double M4Determinante ( double* m ); -extern double CalcTetraederVolume(double* x,double* y,double* z); //CC -extern double CalcPyramidVolume(double* x,double* y,double* z); //CC -extern double CalcPrismVolume(double* x,double* y,double* z); //CC -extern double MCalcProjectionOfPointOnPlane(double* pt, - double* e1, - double* e2, - double* e3, - double* proj); -extern double MCalcProjectionOfPointOnPlane(double* pt, - double* e1, - double* e2, - double* e3, - double* proj); -extern double MCalcDistancePointToPoint(double* pt1,double* pt2); +extern double MSkalarprodukt(double* vec1, double* vec2, long g); +extern double M3Determinante(double* m); +extern double M4Determinante(double* m); +extern double CalcTetraederVolume(double* x, double* y, double* z); // CC +extern double CalcPyramidVolume(double* x, double* y, double* z); // CC +extern double CalcPrismVolume(double* x, double* y, double* z); // CC +extern double MCalcProjectionOfPointOnPlane(double* pt, double* e1, double* e2, double* e3, double* proj); +extern double MCalcProjectionOfPointOnPlane(double* pt, double* e1, double* e2, double* e3, double* proj); +extern double MCalcDistancePointToPoint(double* pt1, double* pt2); extern long* TOLSortNodes1(long*, double*, int); -extern int MPhi2D(double* vf,double r, double s); +extern int MPhi2D(double* vf, double r, double s); #ifdef RFW_FRACTURE extern bool LineSegmentIntersection(vector, vector, vector, vector, - vector&); //RFW 04/2005 + vector&); // RFW 04/2005 #endif #endif diff --git a/GEO/geo_ply.cpp b/GEO/geo_ply.cpp index 54045d664..15d6c8e6e 100644 --- a/GEO/geo_ply.cpp +++ b/GEO/geo_ply.cpp @@ -21,28 +21,27 @@ using namespace std; -//GSP +// GSP std::vector polyline_vector; int ply_max = -1; std::vector column_vector; -std::vector profile_vector; //YD +std::vector profile_vector; // YD /*----------------------------------------------------------------------*/ // constructor -CGLPolyline::CGLPolyline(void) - : _set_eps(false), epsilon(0.01) +CGLPolyline::CGLPolyline(void) : _set_eps(false), epsilon(0.01) { name = "POLYLINE"; -// closed = false; + // closed = false; type = 2; computeline = false; mat_group = -1; data_type = 0; -// minDis = 0; - ply_max++; //OK + // minDis = 0; + ply_max++; // OK id = ply_max; -// mesh_density = 100.0; + // mesh_density = 100.0; } /************************************************************************** @@ -51,16 +50,15 @@ CGLPolyline::CGLPolyline(void) Programing: 11/2005 OK Implementation **************************************************************************/ -CGLPolyline::CGLPolyline(const std::string &ply_name) : - name(ply_name), _set_eps(false), epsilon(0.01) +CGLPolyline::CGLPolyline(const std::string& ply_name) : name(ply_name), _set_eps(false), epsilon(0.01) { -// closed = false; + // closed = false; type = 2; computeline = false; mat_group = -1; data_type = 0; -// minDis = 0; - ply_max++; //OK + // minDis = 0; + ply_max++; // OK id = ply_max; } @@ -73,22 +71,22 @@ CGLPolyline::~CGLPolyline(void) msh_nodes_vector.clear(); } -const std::string& CGLPolyline::getName () const +const std::string& CGLPolyline::getName() const { return name; } -void CGLPolyline::setName (const std::string& nname) +void CGLPolyline::setName(const std::string& nname) { name = nname; } -size_t CGLPolyline::getID () const +size_t CGLPolyline::getID() const { return id; } -void CGLPolyline::setID (size_t nid) +void CGLPolyline::setID(size_t nid) { id = nid; } @@ -103,7 +101,8 @@ CGLPolyline* GEOGetPLYByName(const std::string& name) { for (std::vector::iterator it = polyline_vector.begin(); it != polyline_vector.end(); ++it) { - if ((*it)->getName() == name) return *it; + if ((*it)->getName() == name) + return *it; } return NULL; } @@ -116,7 +115,7 @@ CGLPolyline* GEOGetPLYByName(const std::string& name) **************************************************************************/ CGLPolyline* GEOGetPLYById(size_t number) { - std::vector::iterator p = polyline_vector.begin(); //CC + std::vector::iterator p = polyline_vector.begin(); // CC while (p != polyline_vector.end()) { if ((*p)->getID() == number) @@ -139,17 +138,17 @@ CGLPolyline* GEOGetPLYById(size_t number) void GEORemoveAllPolylines() { int i; - //CGLPolyline * m_ply = NULL; - for (i = 0; i < (int) polyline_vector.size(); i++) + // CGLPolyline * m_ply = NULL; + for (i = 0; i < (int)polyline_vector.size(); i++) { - //m_ply = polyline_vector[0]; //TK: What's that Cui? - //delete m_ply; + // m_ply = polyline_vector[0]; //TK: What's that Cui? + // delete m_ply; delete polyline_vector[i]; polyline_vector[i] = NULL; } - polyline_vector.clear(); //CC + polyline_vector.clear(); // CC - for (i = 0; i < (int) gli_lines_vector.size(); i++) + for (i = 0; i < (int)gli_lines_vector.size(); i++) { delete gli_lines_vector[i]; gli_lines_vector[i] = NULL; @@ -196,7 +195,7 @@ std::vector GetPolylineVector(void) void GEOPolylineGLI2GEO(FILE* geo_file) { int i; - //vector gli_lines_vector; + // vector gli_lines_vector; std::vector gli_Points_vector; long gli_lines_vector_size; gli_Points_vector = GetPointsVector(); @@ -212,15 +211,15 @@ void GEOPolylineGLI2GEO(FILE* geo_file) LineFeed(geo_file); //---------------------------------------------------------------------- // Compute lines - gli_lines_vector_size = (long) gli_lines_vector.size(); + gli_lines_vector_size = (long)gli_lines_vector.size(); if (gli_lines_vector_size == 0) { CGLPolyline* p_pline = NULL; - std::vector::iterator p = polyline_vector.begin(); //CC + std::vector::iterator p = polyline_vector.begin(); // CC while (p != polyline_vector.end()) { p_pline = *p; - if (p_pline->getLineVector().size() == 0) //CC + if (p_pline->getLineVector().size() == 0) // CC p_pline->ComputeLines(); p++; } @@ -231,17 +230,16 @@ void GEOPolylineGLI2GEO(FILE* geo_file) int l_counter = 0; int s_counter = 0; int pl_counter = 0; - for (i = 0; i < (int) surface_vector.size(); i++) + for (i = 0; i < (int)surface_vector.size(); i++) { - if (!surface_vector[i]->meshing_allowed) //OK/TK + if (!surface_vector[i]->meshing_allowed) // OK/TK continue; s_counter++; - surface_vector[i]->output(geo_file, p_counter, l_counter, pl_counter, - s_counter); + surface_vector[i]->output(geo_file, p_counter, l_counter, pl_counter, s_counter); } //---------------------------------------------------------------------- // Null the index - long gli_point_vector_size = (long) gli_Points_vector.size(); + long gli_point_vector_size = (long)gli_Points_vector.size(); for (i = 0; i < gli_point_vector_size; i++) gli_Points_vector[i]->SetIndex(-1); for (i = 0; i < gli_lines_vector_size; i++) @@ -263,18 +261,18 @@ void CGLPolyline::Write(char* file_name) const char* filename = 0; std::string gli_file_name; long i; - //sprintf(gli_file_name,"%s.%s",file_name,"gli"); - gli_file_name = (string) file_name + ".gli"; + // sprintf(gli_file_name,"%s.%s",file_name,"gli"); + gli_file_name = (string)file_name + ".gli"; filename = gli_file_name.data(); f = fopen(filename, "a"); fprintf(f, "#POLYLINE\n"); - fprintf(f, " $ID\n"); //CC - fprintf(f, " %ld\n", static_cast(id)); //CC + fprintf(f, " $ID\n"); // CC + fprintf(f, " %ld\n", static_cast(id)); // CC fprintf(f, " $NAME\n"); - if (data_type == 1) //CC8888 - fprintf(f, " POLYLINE\n"); //CC8888 + if (data_type == 1) // CC8888 + fprintf(f, " POLYLINE\n"); // CC8888 else - //CC8888 + // CC8888 fprintf(f, " %s\n", name.c_str()); fprintf(f, " $TYPE\n"); fprintf(f, " %d\n", type); @@ -285,16 +283,16 @@ void CGLPolyline::Write(char* file_name) if (data_type == 0) { fprintf(f, " $POINTS\n"); - for (i = 0; i < (long) point_vector.size(); i++) + for (i = 0; i < (long)point_vector.size(); i++) fprintf(f, " %ld\n", point_vector[i]->id); } else if (data_type == 1) { fprintf(f, " $POINT_VECTOR\n"); - std::string ply_file_name ("POLYLINE"); + std::string ply_file_name("POLYLINE"); ply_file_name += PLY_FILE_EXTENSION; - fprintf(f, " %s\n", ply_file_name.data()); //TK + fprintf(f, " %s\n", ply_file_name.data()); // TK } fclose(f); } @@ -309,14 +307,12 @@ bool CGLPolyline::PointExists(CGLPoint* point, CGLPoint* point1) long i; double dist; long dist2; - long ply_points_vector_length = (long) point_vector.size(); + long ply_points_vector_length = (long)point_vector.size(); for (i = 0; i < ply_points_vector_length; i++) { - dist2 = ((point_vector[i]->x_pix - point->x_pix) - * (point_vector[i]->x_pix - point->x_pix) - + (point_vector[i]->y_pix - point->y_pix) - * (point_vector[i]->y_pix - point->y_pix)); - dist = sqrt((double) dist2); + dist2 = ((point_vector[i]->x_pix - point->x_pix) * (point_vector[i]->x_pix - point->x_pix) + + (point_vector[i]->y_pix - point->y_pix) * (point_vector[i]->y_pix - point->y_pix)); + dist = sqrt((double)dist2); if (dist < point->circle_pix) { point1->x_pix = point_vector[i]->x_pix; @@ -338,10 +334,10 @@ bool CGLPolyline::PointExists(CGLPoint* point, CGLPoint* point1) CGLPoint* CGLPolyline::CenterPoint(void) { CGLPoint* m_point = NULL; - int polyline_point_vector_length = (long) point_vector.size(); + int polyline_point_vector_length = (long)point_vector.size(); if (polyline_point_vector_length == 0) return NULL; - int center_point = (int) polyline_point_vector_length / 2; + int center_point = (int)polyline_point_vector_length / 2; m_point = point_vector[center_point]; return m_point; } @@ -353,21 +349,21 @@ CGLPoint* CGLPolyline::CenterPoint(void) 01/2005 OK File handling 08/2005 CC **************************************************************************/ -void CGLPolyline::WritePointVector(const std::string & base) +void CGLPolyline::WritePointVector(const std::string& base) { - (void) base; + (void)base; string ply_path; string ply_path_base_type; long i; //---------------------------------------------------------------------- - long no_points = (long) point_vector.size(); + long no_points = (long)point_vector.size(); if (no_points > 0) { //---------------------------------------------------------------------- // File handling std::string ply_file_name = "POLYLINE"; - ply_file_name += PLY_FILE_EXTENSION; //CC + ply_file_name += PLY_FILE_EXTENSION; // CC ply_path_base_type = ply_path + ply_file_name; std::fstream ply_file(ply_path_base_type.data(), std::ios::trunc | std::ios::out); ply_file.setf(std::ios::scientific, std::ios::floatfield); @@ -377,8 +373,7 @@ void CGLPolyline::WritePointVector(const std::string & base) return; ply_file.seekg(0L, std::ios::beg); for (i = 0; i < no_points; i++) - ply_file << point_vector[i]->x << " " << point_vector[i]->y << " " - << point_vector[i]->z << "\n"; + ply_file << point_vector[i]->x << " " << point_vector[i]->y << " " << point_vector[i]->z << "\n"; } } @@ -390,7 +385,7 @@ void CGLPolyline::WritePointVector(const std::string & base) 08/2005 CC file_path 10/2005 OK Path **************************************************************************/ -void CGLPolyline::ReadPointVector(const std::string &base) +void CGLPolyline::ReadPointVector(const std::string& base) { std::string cut_string; std::string delimiter_type(" "); @@ -405,8 +400,8 @@ void CGLPolyline::ReadPointVector(const std::string &base) std::ifstream ply_file(base.c_str()); //,std::ios::in); if (!ply_file.is_open()) { - std::cout << "*** Warning in CGLPolyline::ReadPointVector: File " - << ply_file_name << " not found" << "\n"; + std::cout << "*** Warning in CGLPolyline::ReadPointVector: File " << ply_file_name << " not found" + << "\n"; return; } ply_file.seekg(0L, std::ios::beg); @@ -467,15 +462,15 @@ void CGLPolyline::ComputeLines() m_line_exist = m_line->Exists(); if (m_line_exist) - line_vector.push_back(m_line_exist); //CC + line_vector.push_back(m_line_exist); // CC else { m_line2 = m_line; gli_lines_vector.push_back(m_line2); - //m_line2->line_index =(long)gli_lines_vector.size(); - m_line2->gli_line_id = (long) gli_lines_vector.size(); + // m_line2->line_index =(long)gli_lines_vector.size(); + m_line2->gli_line_id = (long)gli_lines_vector.size(); m_line2->orientation = 1; - line_vector.push_back(m_line2); //CC + line_vector.push_back(m_line2); // CC } } computeline = true; @@ -493,7 +488,7 @@ void CGLPolyline::ComputeLines() 07/2005 CC read ID of polyline 08/2005 CC parameter **************************************************************************/ -void GEOReadPolylines(const std::string &file_name_path_base) +void GEOReadPolylines(const std::string& file_name_path_base) { CGLPolyline* m_polyline = NULL; char line[MAX_ZEILEN]; @@ -506,11 +501,12 @@ void GEOReadPolylines(const std::string &file_name_path_base) // File handling gli_file_name = file_name_path_base + ".gli"; // pos = (int)file_name_path_base.rfind('\\'); //CC remove - //path_name = file_name_path_base.substr(0,(pos+1));//CC remove + // path_name = file_name_path_base.substr(0,(pos+1));//CC remove std::ifstream gli_file(gli_file_name.data(), std::ios::in); if (!gli_file.good()) { - std::cerr << "stream error GEOReadPolylines " << "\n"; + std::cerr << "stream error GEOReadPolylines " + << "\n"; return; } gli_file.seekg(0L, std::ios::beg); // rewind? @@ -521,7 +517,7 @@ void GEOReadPolylines(const std::string &file_name_path_base) gli_file.getline(line, MAX_ZEILEN); line_string = line; - if(line_string.find("#STOP") != string::npos) //11.08.2011. WW + if (line_string.find("#STOP") != string::npos) // 11.08.2011. WW break; //---------------------------------------------------------------------- @@ -533,11 +529,11 @@ void GEOReadPolylines(const std::string &file_name_path_base) gli_file.seekg(position, std::ios::beg); // OK->CC encapsulate function //.................................................................. -// m_polyline->CalcMinimumPointDistance(); + // m_polyline->CalcMinimumPointDistance(); //.................................................................. } // keyword found } // eof - gli_file.close(); //OK41 + gli_file.close(); // OK41 } /************************************************************************** @@ -550,7 +546,7 @@ void GEOReadPolylines(const std::string &file_name_path_base) 08/2005 CC parameter 09/2005 CC itoa - convert integer to string **************************************************************************/ -ios::pos_type CGLPolyline::Read(std::ifstream &gli_file) //CC8888 +ios::pos_type CGLPolyline::Read(std::ifstream& gli_file) // CC8888 { char line[MAX_ZEILEN]; std::string line_string; @@ -588,7 +584,7 @@ ios::pos_type CGLPolyline::Read(std::ifstream &gli_file) //CC8888 name = line_string.substr(0); continue; } // subkeyword found - //.................................................................... + //.................................................................... if (line_string.find("$TYPE") != string::npos) // subkeyword found { gli_file.getline(line, MAX_ZEILEN); @@ -596,7 +592,7 @@ ios::pos_type CGLPolyline::Read(std::ifstream &gli_file) //CC8888 type = strtol(line_string.data(), NULL, 0); continue; } // subkeyword found - //.................................................................... + //.................................................................... if (line_string.find("$EPSILON") != string::npos) // subkeyword found { gli_file.getline(line, MAX_ZEILEN); @@ -606,7 +602,7 @@ ios::pos_type CGLPolyline::Read(std::ifstream &gli_file) //CC8888 _set_eps = true; continue; } // subkeyword found - //.................................................................... + //.................................................................... if (line_string.find("$MAT_GROUP") != string::npos) // subkeyword found { gli_file.getline(line, MAX_ZEILEN); @@ -614,57 +610,58 @@ ios::pos_type CGLPolyline::Read(std::ifstream &gli_file) //CC8888 mat_group = strtol(line_string.data(), NULL, 0); continue; } // subkeyword found - //.................................................................... + //.................................................................... if (line_string.find("$POINTS") != string::npos) // subkeyword found { gli_file.getline(line, MAX_ZEILEN); line_string = line; -// ply_data = "POINTS";//CC8888 + // ply_data = "POINTS";//CC8888 long lvalue = strtol(line_string.data(), NULL, 0); int i = 1; while (i == 1) { - m_point = GEOGetPointById(lvalue); //CC wrong get point by id + m_point = GEOGetPointById(lvalue); // CC wrong get point by id if (m_point) AddPoint(m_point); - //CC--------------------------- + // CC--------------------------- else { - std::cout << "Error: point " << lvalue << " not found" << - "\n"; + std::cout << "Error: point " << lvalue << " not found" + << "\n"; //-------------------------------------------------- std::string m_strname = name + ": Point not found: point "; char m_strnameid[10]; - sprintf(m_strnameid, "%li", lvalue); //OK - //itoa((int)lvalue,m_strnameid,10); //CC 09/05 convert integer to string ultoa convert unsigned long to string + sprintf(m_strnameid, "%li", lvalue); // OK + // itoa((int)lvalue,m_strnameid,10); //CC 09/05 convert integer to string ultoa convert unsigned + // long to string std::string error_str = m_strname + m_strnameid; return position; } gli_file.getline(line, MAX_ZEILEN); line_string = line; - if ((line_string.find("#") != string::npos) \ + if ((line_string.find("#") != string::npos) - || (line_string.find("$") != string::npos)) //OK bugfix + || (line_string.find("$") != string::npos)) // OK bugfix { i = 0; new_keyword = true; } else lvalue = strtol(line_string.data(), NULL, 0); - } //end of while + } // end of while data_type = 0; } // subkeyword found - //.................................................................... + //.................................................................... if (line_string.find("$POINT_VECTOR") != string::npos) // subkeyword found { gli_file.getline(line, MAX_ZEILEN); line_string = line; remove_white_space(&line_string); - ReadPointVector(line_string.substr(0)); //CC - data_type = 1; //OK41 -// ply_data = line_string; + ReadPointVector(line_string.substr(0)); // CC + data_type = 1; // OK41 + // ply_data = line_string; } // subkeyword found - //======================================================================== + //======================================================================== } return position; } @@ -677,7 +674,7 @@ ios::pos_type CGLPolyline::Read(std::ifstream &gli_file) //CC8888 **************************************************************************/ void CGLPolyline::AddPoint(CGLPoint* m_point) { - //point_list.push_back(m_point);//CC remove + // point_list.push_back(m_point);//CC remove point_vector.push_back(m_point); } /************************************************************************** @@ -687,7 +684,7 @@ void CGLPolyline::AddPoint(CGLPoint* m_point) 05/2004 CC Implementation Assign randam color to polyline last modification: **************************************************************************/ -//void CGLPolyline::AssignColor() { +// void CGLPolyline::AssignColor() { // long r_number = rand(); // m_color[0] = (long) (r_number / (double) RAND_MAX * 256); // r_number = rand(); @@ -706,7 +703,7 @@ void CGLPolyline::AddPoint(CGLPoint* m_point) **************************************************************************/ void InterpolationAlongPolyline(CGLPolyline* plyL, std::vector& bcNodalValue) { - //Obtain fem node for groupvector + // Obtain fem node for groupvector const size_t SizeCGLPoint(plyL->point_vector.size()); double xp(0.0), yp(0.0), zp(0.0); @@ -721,7 +718,7 @@ void InterpolationAlongPolyline(CGLPolyline* plyL, std::vector& bcNodalV xp = CGPb->x - CGPa->x; yp = CGPb->y - CGPa->y; zp = CGPb->z - CGPa->z; - //NW: why checking zero value? Zero could also be used for BC/ST. + // NW: why checking zero value? Zero could also be used for BC/ST. if (fabs(plyL->point_vector[i]->getPropert()) > MKleinsteZahlen) { bVal.push_back(plyL->point_vector[i]->getPropert()); @@ -730,8 +727,7 @@ void InterpolationAlongPolyline(CGLPolyline* plyL, std::vector& bcNodalV sl += sqrt(xp * xp + yp * yp + zp * zp); } // Last point - if (fabs(plyL->point_vector[SizeCGLPoint - 1]->getPropert()) - > MKleinsteZahlen) + if (fabs(plyL->point_vector[SizeCGLPoint - 1]->getPropert()) > MKleinsteZahlen) { ss0.push_back(sl); bVal.push_back(plyL->point_vector[SizeCGLPoint - 1]->getPropert()); @@ -739,32 +735,34 @@ void InterpolationAlongPolyline(CGLPolyline* plyL, std::vector& bcNodalV if (ss0.size() == 0) { - std::cout - << - "Error in CGLPolyline::InterpolationAlongPolyline: no PNT data found for Spline interpolation" - << "\n"; + std::cout << "Error in CGLPolyline::InterpolationAlongPolyline: no PNT data found for Spline interpolation" + << "\n"; return; } // Spline interpolation - std::cout << "MathLib::CubicSpline input data: " << "\n"; + std::cout << "MathLib::CubicSpline input data: " + << "\n"; for (size_t k(0); k < ss0.size(); k++) std::cout << "\t" << ss0[k] << " " << bVal[k] << "\n"; - std::cout << "end MathLib::CubicSpline input data" << "\n"; + std::cout << "end MathLib::CubicSpline input data" + << "\n"; MathLib::CubicSpline* csp = new MathLib::CubicSpline(ss0, bVal); // Interpolate size_t number_of_nodes(bcNodalValue.size()), i; for (i = 0; i < number_of_nodes; i++) - bcNodalValue[plyL->getOrderedPoints()[i]] = csp->interpolation( - plyL->getSBuffer()[i]); - std::cout << "MathLib::CubicSpline results: " << "\n"; + bcNodalValue[plyL->getOrderedPoints()[i]] = csp->interpolation(plyL->getSBuffer()[i]); + std::cout << "MathLib::CubicSpline results: " + << "\n"; for (size_t k(0); k < plyL->getSBuffer().size(); k++) - std::cout << "\t" << plyL->getOrderedPoints()[k] << " " << plyL->getSBuffer()[k] << - " " << bcNodalValue[plyL->getOrderedPoints()[k]] << " (bcNodalValue[" << - plyL->getOrderedPoints()[k] << "])" << "\n"; - std::cout << "end MathLib::CubicSpline results" << "\n"; + std::cout << "\t" << plyL->getOrderedPoints()[k] << " " << plyL->getSBuffer()[k] << " " + << bcNodalValue[plyL->getOrderedPoints()[k]] << " (bcNodalValue[" << plyL->getOrderedPoints()[k] + << "])" + << "\n"; + std::cout << "end MathLib::CubicSpline results" + << "\n"; // Release the memory delete csp; @@ -784,7 +782,7 @@ void InterpolationAlongPolyline(CGLPolyline* plyL, std::vector& bcNodalV 08/2005 CC file_path last modification: **************************************************************************/ -void CGLPolyline::WriteTecplot(const std::string &file_path) +void CGLPolyline::WriteTecplot(const std::string& file_path) { long i; //---------------------------------------------------------------------- @@ -795,24 +793,28 @@ void CGLPolyline::WriteTecplot(const std::string &file_path) tec_path = m_gsp->path; */ std::string tec_file_name = file_path + name + ".tec"; - //string tec_file_name = tec_path + name + ".tec"; + // string tec_file_name = tec_path + name + ".tec"; std::fstream tec_file(tec_file_name.data(), ios::trunc | ios::out); tec_file.setf(std::ios::scientific, std::ios::floatfield); tec_file.precision(12); // Write header - tec_file << "VARIABLES = X,Y,Z" << "\n"; - long no_nodes = (long) point_vector.size(); + tec_file << "VARIABLES = X,Y,Z" + << "\n"; + long no_nodes = (long)point_vector.size(); long no_elements = no_nodes - 1; - tec_file << "ZONE T = " << name << ", " << "N = " << no_nodes << ", " - << "E = " << no_elements << ", " << "F = FEPOINT" << ", " - << "ET = TRIANGLE" << "\n"; + tec_file << "ZONE T = " << name << ", " + << "N = " << no_nodes << ", " + << "E = " << no_elements << ", " + << "F = FEPOINT" + << ", " + << "ET = TRIANGLE" + << "\n"; // Write data for (i = 0; i < no_nodes; i++) - tec_file << point_vector[i]->x << " " << point_vector[i]->y << " " - << point_vector[i]->z << " " << "\n"; + tec_file << point_vector[i]->x << " " << point_vector[i]->y << " " << point_vector[i]->z << " " + << "\n"; for (i = 0; i < no_elements; i++) tec_file << i + 1 << " " << i + 1 + 1 << " " << i + 1 << "\n"; - } /************************************************************************** FEMLib-Method: @@ -822,7 +824,7 @@ void CGLPolyline::WriteTecplot(const std::string &file_path) **************************************************************************/ void CGLPolyline::SortPointVectorByDistance() { - long no_points = (long) point_vector.size(); + long no_points = (long)point_vector.size(); if (no_points == 0) return; long i; @@ -873,10 +875,10 @@ void CGLPolyline::SortPointVectorByDistance() **************************************************************************/ void CGLPolyline::GetPointOrderByDistance() { -// std::cout << "CGLPolyline::GetPointOrderByDistance() polyline " << getName() << "\n"; -// for (size_t k(0); kx - CGPa->x; @@ -973,9 +975,10 @@ void CGLPolyline::GetPointOrderByDistance() } } // std::cout << "CGLPolyline::GetPointOrderByDistance() polyline " << getName() << "\n"; -// for (size_t k(0); k::const_iterator p_ply; // p_ply = polyline_vector.begin(); @@ -1003,20 +1006,20 @@ void CGLPolyline::GetPointOrderByDistance() void CGLPolyline::SetPointOrderByDistance(CGLPoint* m_pnt) { int i; - //OK double eps = 1e-3; + // OK double eps = 1e-3; //---------------------------------------------------------------------- CGLPoint* m_pnt_i = NULL; std::vector point_vector_aux; - for (i = 0; i < (int) point_vector.size(); i++) + for (i = 0; i < (int)point_vector.size(); i++) { m_pnt_i = point_vector[i]; - //OK if(m_pnt->PointDisXY(m_pnt_i)PointDisXY(m_pnt_i)PointDis(m_pnt_i) < epsilon) point_vector_aux.push_back(m_pnt_i); } - if ((int) point_vector_aux.size() == 0) + if ((int)point_vector_aux.size() == 0) return; - for (i = 0; i < (int) point_vector.size(); i++) + for (i = 0; i < (int)point_vector.size(); i++) { m_pnt_i = point_vector[i]; if (m_pnt_i == point_vector_aux[0]) @@ -1051,7 +1054,7 @@ void CGLPolyline::SetPointOrderByDistance(CGLPoint* m_pnt) void GEOWritePolylines(char* file_name) { CGLPolyline* m_ply = NULL; - for (int i = 0; i < (int) polyline_vector.size(); i++) + for (int i = 0; i < (int)polyline_vector.size(); i++) { m_ply = polyline_vector[i]; m_ply->Write(file_name); @@ -1067,15 +1070,15 @@ void GEOWritePolylines(char* file_name) void GEORemovePLY(CGLPolyline* m_ply) { CGLPolyline* m_ply_this = NULL; - //WW std::vector::const_iterator p_ply = polyline_vector.begin(); - for (int i = 0; i < (int) polyline_vector.size(); i++) + // WW std::vector::const_iterator p_ply = polyline_vector.begin(); + for (int i = 0; i < (int)polyline_vector.size(); i++) { m_ply_this = polyline_vector[i]; if (m_ply_this->getName().compare(m_ply->getName()) == 0) { delete m_ply_this; polyline_vector.erase(polyline_vector.begin() + i); - //i--; + // i--; return; } } @@ -1085,7 +1088,7 @@ void GEORemovePLY(CGLPolyline* m_ply) GeoLib-Method: 01/2006 OK Implementation based on CCs version **************************************************************************/ -//void CGLPolyline::CalcMinimumPointDistance() { +// void CGLPolyline::CalcMinimumPointDistance() { // CGLPoint* start_point = NULL; // CGLPoint* end_point = NULL; // double m_dXMin = 1.e+19; @@ -1093,7 +1096,8 @@ void GEORemovePLY(CGLPolyline* m_ply) // for (int i = 0; i < (int) point_vector.size() - 1; i++) { // start_point = point_vector[i]; // end_point = point_vector[i + 1]; -// //min = sqrt((start_point->x-end_point->x)*(start_point->x-end_point->x)+(start_point->y-end_point->y)*(start_point->y-end_point->y)); +// //min = +// sqrt((start_point->x-end_point->x)*(start_point->x-end_point->x)+(start_point->y-end_point->y)*(start_point->y-end_point->y)); // min = start_point->PointDis(end_point); // if (min < m_dXMin) // m_dXMin = min; @@ -1113,7 +1117,7 @@ CColumn::~CColumn() line_vector.clear(); } -void CColumn::deleteLines () +void CColumn::deleteLines() { for (size_t j = 0; j < line_vector.size(); j++) delete line_vector[j]; @@ -1128,7 +1132,7 @@ void CColumn::deleteLines () void COLDelete() { CColumn* m_col = NULL; - for (int i = 0; i < (int) column_vector.size(); i++) + for (int i = 0; i < (int)column_vector.size(); i++) { m_col = column_vector[i]; delete m_col; @@ -1142,8 +1146,8 @@ void COLDelete() **************************************************************************/ void COLDeleteLines() { - for (int i = 0; i < (int) column_vector.size(); i++) - column_vector[i]->deleteLines (); + for (int i = 0; i < (int)column_vector.size(); i++) + column_vector[i]->deleteLines(); } /************************************************************************** @@ -1168,7 +1172,7 @@ CColumn* COLGet(int col_id) Programing: 12/2005 OK Implementation **************************************************************************/ -CColumn* COLGet(const std::string &col_name) +CColumn* COLGet(const std::string& col_name) { for (size_t i = 0; i < column_vector.size(); i++) if (column_vector[i]->getName().compare(col_name) == 0) @@ -1180,7 +1184,7 @@ CColumn* COLGet(const std::string &col_name) Programing: 08/2006 YD Implementation **************************************************************************/ -CSoilProfile::CSoilProfile() //YD +CSoilProfile::CSoilProfile() // YD { } /************************************************************************** @@ -1188,11 +1192,11 @@ CSoilProfile::CSoilProfile() //YD Programing: 08/2006 YD Implementation **************************************************************************/ -CSoilProfile::~CSoilProfile() //YD +CSoilProfile::~CSoilProfile() // YD { - for (int i = 0; i < (int) soil_type.size(); i++) + for (int i = 0; i < (int)soil_type.size(); i++) soil_type[i] = 0; - for (int i = 0; i < (int) soil_layer_thickness.size(); i++) + for (int i = 0; i < (int)soil_layer_thickness.size(); i++) soil_layer_thickness[i] = 0.; soil_type.clear(); soil_layer_thickness.clear(); @@ -1214,7 +1218,7 @@ double CGLPolyline::CalcPolylineLength() { double dx, dy, dz, dist = 0, poly_length = 0; - for(int j = 0; j < (int)point_vector.size() - 1; j++) + for (int j = 0; j < (int)point_vector.size() - 1; j++) { dx = point_vector[j]->x - point_vector[j + 1]->x; dy = point_vector[j]->y - point_vector[j + 1]->y; diff --git a/GEO/geo_ply.h b/GEO/geo_ply.h index 1fad2e9f3..0319bd00e 100644 --- a/GEO/geo_ply.h +++ b/GEO/geo_ply.h @@ -21,7 +21,7 @@ #include #include #define PLY_FILE_EXTENSION ".ply" -//enum PLY_TYPES {GEO,MSH,IC,BC,ST}; +// enum PLY_TYPES {GEO,MSH,IC,BC,ST}; class CGLPolyline { @@ -31,131 +31,121 @@ class CGLPolyline std::vector ibuffer; // TF 10/2010 - made attributes private - //properties - size_t id; //CC + // properties + size_t id; // CC std::string name; int type; int data_type; int mat_group; -// std::string ply_data;//CC9999 -// double minDis; -// double mesh_density;//CC9999 ply density -// bool closed; -// double min_plg_Dis; - //components + // std::string ply_data;//CC9999 + // double minDis; + // double mesh_density;//CC9999 ply density + // bool closed; + // double min_plg_Dis; + // components bool computeline; -// std::string ply_file_name; + // std::string ply_file_name; std::vector OrderedPoint; /// is the epsilon value set external or is it on default value bool _set_eps; + protected: std::vector line_vector; public: // constructor CGLPolyline(void); - CGLPolyline(const std::string &); //OK + CGLPolyline(const std::string&); // OK // destructor ~CGLPolyline(void); /// is the epsilon value set external or is it on default value /// used in mesh node search algorithms bool isSetEps() const { return _set_eps; } - const std::string& getName () const; - void setName (const std::string& nname); - size_t getID () const; - void setID (size_t nid); - //properties - size_t getType () const { return type; } + const std::string& getName() const; + void setName(const std::string& nname); + size_t getID() const; + void setID(size_t nid); + // properties + size_t getType() const { return type; } /** * if the data is read from the gli-file, data_type is 0 * if the data is read from an external file or is generated by OpenGeoSys, data_type is 1 * @return the data type */ - int getDataType () const { return data_type; } - void setDataType (int ndata_type) { data_type = ndata_type; } - - int getMatGroup () const { return mat_group; } - + int getDataType() const { return data_type; } + void setDataType(int ndata_type) { data_type = ndata_type; } + int getMatGroup() const { return mat_group; } double epsilon; - //components - const std::vector& getLineVector () const { return line_vector; } - std::vector& getLineVector () { return line_vector; } - - const std::vector& getOrderedPoints () const { return OrderedPoint; } - + // components + const std::vector& getLineVector() const { return line_vector; } + std::vector& getLineVector() { return line_vector; } + const std::vector& getOrderedPoints() const { return OrderedPoint; } std::vector point_vector; - std::vector& getSBuffer () - { - return sbuffer; - } - std::vector& getIBuffer () - { - return ibuffer; - } - - //I/O + std::vector& getSBuffer() { return sbuffer; } + std::vector& getIBuffer() { return ibuffer; } + // I/O std::ios::pos_type Read(std::ifstream&); // TF , const std::string &);//CC void Write(char* file_name); - //display -// void AssignColor();//CC - //method + // display + // void AssignColor();//CC + // method void ComputeLines(); - bool PointExists(CGLPoint* point,CGLPoint* point1); + bool PointExists(CGLPoint* point, CGLPoint* point1); void AddPoint(CGLPoint* m_point); CGLPoint* CenterPoint(void); - //point vector - void WritePointVector(const std::string &); //CC - void ReadPointVector(const std::string &); //CC + // point vector + void WritePointVector(const std::string&); // CC + void ReadPointVector(const std::string&); // CC void SortPointVectorByDistance(); - //write tecplot file - void WriteTecplot(const std::string &); //CC + // write tecplot file + void WriteTecplot(const std::string&); // CC // Meshing std::vector msh_nodes_vector; std::vector msh_coor_vector; void GetPointOrderByDistance(); - void SetPointOrderByDistance(CGLPoint*); //OK + void SetPointOrderByDistance(CGLPoint*); // OK // void CalcMinimumPointDistance(); //OK #ifdef RFW_FRACTURE - double CalcPolylineLength(); //RFW + double CalcPolylineLength(); // RFW #endif }; -extern std::vector polyline_vector; //CC -extern std::vector GetPolylineVector(void); //CC -//Access +extern std::vector polyline_vector; // CC +extern std::vector GetPolylineVector(void); // CC +// Access extern CGLPolyline* GEOGetPLYByName(const std::string&); extern CGLPolyline* GEOGetPLYById(long); // CC -//methods +// methods extern void GEOPolylineGLI2GEO(FILE* geo_file); -//extern void GEOUnselectPLY(); //OK -//Remove -extern void GEORemoveAllPolylines(); //CC -extern void GEORemovePolyline(long); //CC 03/06 -extern void GEORemovePLY(CGLPolyline*); //OK -//I/O -extern void GEOReadPolylines(const std::string &file_name_path_base); -extern void GEOWritePolylines(char* file_name); //CC -//RF +// extern void GEOUnselectPLY(); //OK +// Remove +extern void GEORemoveAllPolylines(); // CC +extern void GEORemovePolyline(long); // CC 03/06 +extern void GEORemovePLY(CGLPolyline*); // OK +// I/O +extern void GEOReadPolylines(const std::string& file_name_path_base); +extern void GEOWritePolylines(char* file_name); // CC +// RF extern void InterpolationAlongPolyline(CGLPolyline* plyL, std::vector& bcNodalValue); -class CColumn : public CGLPolyline //OK +class CColumn : public CGLPolyline // OK { private: CGLLine* m_lin; public: ~CColumn(); - void deleteLines (); + void deleteLines(); double geo_area; double center_point[3]; }; -class CSoilProfile : public CGLPolyline //YD +class CSoilProfile : public CGLPolyline // YD { public: CSoilProfile(); @@ -163,14 +153,14 @@ class CSoilProfile : public CGLPolyline //YD long profile_type; std::string soil_name; std::vector soil_type; - std::vectorsoil_layer_thickness; + std::vector soil_layer_thickness; }; extern void COLDeleteLines(); extern void COLDelete(); extern CColumn* COLGet(int); -extern CColumn* COLGet(const std::string &); +extern CColumn* COLGet(const std::string&); -extern std::vectorcolumn_vector; -extern std::vectorprofile_vector; //YD +extern std::vector column_vector; +extern std::vector profile_vector; // YD #endif diff --git a/GEO/geo_pnt.cpp b/GEO/geo_pnt.cpp index 44228dab9..55a5b0f95 100644 --- a/GEO/geo_pnt.cpp +++ b/GEO/geo_pnt.cpp @@ -41,10 +41,10 @@ long pnt_id_last = 0; Programing: 10/2005 OK PNT name **************************************************************************/ -CGLPoint::CGLPoint(void) : x (data[0]), y(data[1]), z(data[2]), _propert (0.0) +CGLPoint::CGLPoint(void) : x(data[0]), y(data[1]), z(data[2]), _propert(0.0) { index_msh = -1; - circle_pix = 3; //CC + circle_pix = 3; // CC mesh_density = 100.; value = 0.0; data[0] = 0.0; @@ -56,27 +56,27 @@ CGLPoint::CGLPoint(void) : x (data[0]), y(data[1]), z(data[2]), _propert (0.0) // m_color[2] = 0; x_pix = 0; y_pix = 0; - mat = -1; //CC9999 // material properties + mat = -1; // CC9999 // material properties // PNT name //OK //...................................................................... name = "POINT"; std::ostringstream os; // TF 01/2010 if (gli_points_vector.size() > 0) - os << (*(--gli_points_vector.end()))->id + 1; // TF 01/2010 + os << (*(--gli_points_vector.end()))->id + 1; // TF 01/2010 else - os << 0; // TF 01/2010 + os << 0; // TF 01/2010 name += os.str(); // TF 01/2010 //...................................................................... } -CGLPoint::CGLPoint (double x1, double y1, double z1) : x (data[0]), y(data[1]), z(data[2]) +CGLPoint::CGLPoint(double x1, double y1, double z1) : x(data[0]), y(data[1]), z(data[2]) { data[0] = x1; data[1] = y1; data[2] = z1; } -CGLPoint::CGLPoint (const double* coordinates) : x (data[0]), y(data[1]), z(data[2]) +CGLPoint::CGLPoint(const double* coordinates) : x(data[0]), y(data[1]), z(data[2]) { for (size_t k(0); k < 3; k++) data[k] = coordinates[k]; @@ -105,15 +105,13 @@ int CGLPoint::IsPointExist() int YesThereIs = -100; // Set this to mean there is no duplicate in the file int sizeOfPointList = (int)gli_points_vector.size(); - for(int i = 0; i < sizeOfPointList; ++i) + for (int i = 0; i < sizeOfPointList; ++i) { - double Same = sqrt ( - (gli_points_vector[i]->x - x) * (gli_points_vector[i]->x - x) + - (gli_points_vector[i]->y - - y) * (gli_points_vector[i]->y - y) + - (gli_points_vector[i]->z - z) * (gli_points_vector[i]->z - z) ); + double Same = sqrt((gli_points_vector[i]->x - x) * (gli_points_vector[i]->x - x) + + (gli_points_vector[i]->y - y) * (gli_points_vector[i]->y - y) + + (gli_points_vector[i]->z - z) * (gli_points_vector[i]->z - z)); // If the tolerance is bigger than same, - if(Same < tolerance) + if (Same < tolerance) YesThereIs = gli_points_vector[i]->id; } @@ -129,10 +127,8 @@ int CGLPoint::IsPointExist() **************************************************************************/ double CGLPoint::PointDis(CGLPoint* m_p2) { - return sqrt((x - - m_p2->x) * - (x - m_p2->x) + (y - m_p2->y) * (y - m_p2->y) + (z - m_p2->z) * (z - m_p2->z)); - //return sqrt((x-m_p2->x)*(x-m_p2->x)+(y-m_p2->y)*(y-m_p2->y)); //CC + return sqrt((x - m_p2->x) * (x - m_p2->x) + (y - m_p2->y) * (y - m_p2->y) + (z - m_p2->z) * (z - m_p2->z)); + // return sqrt((x-m_p2->x)*(x-m_p2->x)+(y-m_p2->y)*(y-m_p2->y)); //CC } /************************************************************************** GeoLib-Method: Get @@ -142,16 +138,16 @@ double CGLPoint::PointDis(CGLPoint* m_p2) **************************************************************************/ CGLPoint* GEOGetPointById(long number) { - if(number < 0) + if (number < 0) return NULL; else { std::vector::iterator p = gli_points_vector.begin(); CGLPoint* m_point = NULL; - while(p != gli_points_vector.end()) + while (p != gli_points_vector.end()) { m_point = *p; - if(m_point->id == number) + if (m_point->id == number) return m_point; ++p; } @@ -166,7 +162,7 @@ CGLPoint* GEOGetPointById(long number) 10/2005 OK Test **************************************************************************/ //// 06/2010 TF REMOVE CANDIDATE -//CGLPoint* GEOGetPointByName(const std::string &point_name) +// CGLPoint* GEOGetPointByName(const std::string &point_name) //{ // //CGLPoint *m_pnt = NULL; // std::vector::iterator it (gli_points_vector.begin()); @@ -207,42 +203,42 @@ std::vector GEOLIB_SetGLIPoints_Vector(std::vector gl_poin Aufgabe: Lesen der GLI Points und schreiben in einen Vector 08/2005 CC Implementation **************************************************************************/ -void GEOReadPoints(const std::string &file_name_path_base) +void GEOReadPoints(const std::string& file_name_path_base) { string gli_file_name; char line[MAX_ZEILEN]; string line_string; gli_file_name = file_name_path_base + ".gli"; int ok = 1; - std::stringstream in; //OK + std::stringstream in; // OK ios::pos_type position; CGLPoint* m_gli_points = NULL; - ifstream dat_in (gli_file_name.data(),ios::in); + ifstream dat_in(gli_file_name.data(), ios::in); if (!dat_in.good()) return; - dat_in.seekg(0L,ios::beg); // rewind? + dat_in.seekg(0L, ios::beg); // rewind? //---------------------------------------------------------------------- while (!dat_in.eof()) { - dat_in.getline(line,MAX_ZEILEN); + dat_in.getline(line, MAX_ZEILEN); line_string = line; - if(line_string.find("#STOP") != string::npos) //11.08.2011. WW + if (line_string.find("#STOP") != string::npos) // 11.08.2011. WW break; - if(line_string.find("#POINTS") != string::npos) + if (line_string.find("#POINTS") != string::npos) while (ok) { m_gli_points = new CGLPoint(); - position = m_gli_points->Read(&dat_in,ok); - if(ok && m_gli_points->id >= 0) //CC8888 + position = m_gli_points->Read(&dat_in, ok); + if (ok && m_gli_points->id >= 0) // CC8888 gli_points_vector.push_back(m_gli_points); - else //CC8888 - delete m_gli_points; //CC8888 - dat_in.seekg(position,ios::beg); + else // CC8888 + delete m_gli_points; // CC8888 + dat_in.seekg(position, ios::beg); } } //---------------------------------------------------------------------- - dat_in.close(); //OK41 + dat_in.close(); // OK41 } /************************************************************************** @@ -277,7 +273,7 @@ ios::pos_type CGLPoint::Read(ifstream* gli_file, int& ok) in.str(line_string.substr(pos1 + 2, std::string::npos)); in >> mesh_density; } - if (line_string.find("$ID") != std::string::npos) //OK + if (line_string.find("$ID") != std::string::npos) // OK { pos1 = line_string.find_first_of("I"); in.str(line_string.substr(pos1 + 2, std::string::npos)); @@ -299,11 +295,11 @@ ios::pos_type CGLPoint::Read(ifstream* gli_file, int& ok) **************************************************************************/ void GEORemoveAllPoints() { - //CGLPoint * m_pnt = NULL; - for (int i = 0; i < (int) gli_points_vector.size(); i++) + // CGLPoint * m_pnt = NULL; + for (int i = 0; i < (int)gli_points_vector.size(); i++) { - //m_pnt = gli_points_vector[0]; TK What's that? - //delete m_pnt; + // m_pnt = gli_points_vector[0]; TK What's that? + // delete m_pnt; delete gli_points_vector[i]; gli_points_vector[i] = NULL; } @@ -339,15 +335,15 @@ void GEO_Search_DoublePoints(double tolerance) int j = 0, k = 0; long pointsvectorsize; long first_id, double_id; - double x2check = 0.0,y2check = 0.0,z2check = 0.0; - double x2check0 = 0.0,y2check0 = 0.0,z2check0 = 0.0; - long hits = 0,allhits = 0; + double x2check = 0.0, y2check = 0.0, z2check = 0.0; + double x2check0 = 0.0, y2check0 = 0.0, z2check0 = 0.0; + long hits = 0, allhits = 0; long numbering = 0; double point_distance; string coordinate; string new_coordinate; vector gli_points_vector; - gli_points_vector = GetPointsVector(); //CC + gli_points_vector = GetPointsVector(); // CC pointsvectorsize = (long)gli_points_vector.size(); if (tolerance < MKleinsteZahlen) tolerance = 0.0000000000000001; @@ -365,12 +361,7 @@ void GEO_Search_DoublePoints(double tolerance) y2check0 = gli_points_vector[k]->y; z2check0 = gli_points_vector[k]->z; - point_distance = EuklVek3dDistCoor ( x2check, - y2check, - z2check, - x2check0, - y2check0, - z2check0 ); + point_distance = EuklVek3dDistCoor(x2check, y2check, z2check, x2check0, y2check0, z2check0); if (point_distance < tolerance) { @@ -378,8 +369,7 @@ void GEO_Search_DoublePoints(double tolerance) hits++; allhits++; } - if (hits > 0 && fabs( x2check0 - x2check) < MKleinsteZahlen && - fabs(y2check0 - y2check) < MKleinsteZahlen + if (hits > 0 && fabs(x2check0 - x2check) < MKleinsteZahlen && fabs(y2check0 - y2check) < MKleinsteZahlen && fabs(z2check0 - z2check) < MKleinsteZahlen) if (hits > 1) { @@ -410,7 +400,7 @@ void GEO_Search_DoublePoints(double tolerance) 08/2004 OK/JG Implementation 03/2005 OK Extensions **************************************************************************/ -void GEOReadPointProperties(const std::string &file_name_base) +void GEOReadPointProperties(const std::string& file_name_base) { CGLPoint* m_pnt = NULL; char line[MAX_ZEILEN]; @@ -419,31 +409,32 @@ void GEOReadPointProperties(const std::string &file_name_base) // ios::pos_type position; std::vector pnt_properties_name_vector; string delimiter_type(";"); - int pos1,pos2; + int pos1, pos2; char pnt_name[80]; - cout << "Read PNT properties from " << file_name_base << "_springs" << "\n"; + cout << "Read PNT properties from " << file_name_base << "_springs" + << "\n"; //======================================================================== // File handling - string csv_file_name = file_name_base + CSV_FILE_EXTENSIONS; //OK4105 - ifstream csv_file (csv_file_name.data(),ios::in); + string csv_file_name = file_name_base + CSV_FILE_EXTENSIONS; // OK4105 + ifstream csv_file(csv_file_name.data(), ios::in); if (!csv_file.good()) return; - csv_file.seekg(0L,ios::beg); + csv_file.seekg(0L, ios::beg); //======================================================================== // Keyword loop - csv_file.getline(line,MAX_ZEILEN); + csv_file.getline(line, MAX_ZEILEN); line_string = line; //---------------------------------------------------------------------- // evaluate header //---------------------------------------------------------------------- while (!csv_file.eof()) { - csv_file.getline(line,MAX_ZEILEN); + csv_file.getline(line, MAX_ZEILEN); line_string = line; - if(line_string.empty()) + if (line_string.empty()) return; - sprintf(pnt_name,"PNT_PROPERTY_%i",(int)gli_points_vector.size()); + sprintf(pnt_name, "PNT_PROPERTY_%i", (int)gli_points_vector.size()); m_pnt = new CGLPoint(); m_pnt->name = (string)pnt_name; gli_points_vector.push_back(m_pnt); @@ -451,34 +442,34 @@ void GEOReadPointProperties(const std::string &file_name_base) // lese zeile No Name X Y Z m3/s ... // No pos1 = 0; - sub_string = get_sub_string(line_string,delimiter_type,pos1,&pos2); - sub_string = line_string.substr(pos1,pos2 - pos1); + sub_string = get_sub_string(line_string, delimiter_type, pos1, &pos2); + sub_string = line_string.substr(pos1, pos2 - pos1); m_pnt->name = sub_string; // X pos1 = pos2 + 1; - sub_string = get_sub_string(line_string,delimiter_type,pos1,&pos2); - sub_string = line_string.substr(pos1,pos2 - pos1); - m_pnt->x = strtod(sub_string.data(),NULL); + sub_string = get_sub_string(line_string, delimiter_type, pos1, &pos2); + sub_string = line_string.substr(pos1, pos2 - pos1); + m_pnt->x = strtod(sub_string.data(), NULL); // Y pos1 = pos2 + 1; - sub_string = get_sub_string(line_string,delimiter_type,pos1,&pos2); - sub_string = line_string.substr(pos1,pos2 - pos1); - m_pnt->y = strtod(sub_string.data(),NULL); + sub_string = get_sub_string(line_string, delimiter_type, pos1, &pos2); + sub_string = line_string.substr(pos1, pos2 - pos1); + m_pnt->y = strtod(sub_string.data(), NULL); // Z pos1 = pos2 + 1; - sub_string = get_sub_string(line_string,delimiter_type,pos1,&pos2); - sub_string = line_string.substr(pos1,pos2 - pos1); - m_pnt->z = strtod(sub_string.data(),NULL); + sub_string = get_sub_string(line_string, delimiter_type, pos1, &pos2); + sub_string = line_string.substr(pos1, pos2 - pos1); + m_pnt->z = strtod(sub_string.data(), NULL); // LENGTH pos1 = pos2 + 1; - sub_string = get_sub_string(line_string,delimiter_type,pos1,&pos2); - sub_string = line_string.substr(pos1,pos2 - pos1); - m_pnt->length = strtod(sub_string.data(),NULL); + sub_string = get_sub_string(line_string, delimiter_type, pos1, &pos2); + sub_string = line_string.substr(pos1, pos2 - pos1); + m_pnt->length = strtod(sub_string.data(), NULL); // ST pos1 = pos2 + 1; - sub_string = get_sub_string(line_string,delimiter_type,pos1,&pos2); - sub_string = line_string.substr(pos1,pos2 - pos1); - m_pnt->value = strtod(sub_string.data(),NULL); + sub_string = get_sub_string(line_string, delimiter_type, pos1, &pos2); + sub_string = line_string.substr(pos1, pos2 - pos1); + m_pnt->value = strtod(sub_string.data(), NULL); m_pnt->value /= m_pnt->length; // pnt_properties_vector.push_back(m_pnt); @@ -500,23 +491,23 @@ void GEOCalcPointMinMaxCoordinates() pnt_z_max = -1.e+19; double value; //---------------------------------------------------------------------- - size_t size (gli_points_vector.size()); - for(size_t i = 0; i < size; i++) + size_t size(gli_points_vector.size()); + for (size_t i = 0; i < size; i++) { value = gli_points_vector[i]->x; - if(value < pnt_x_min) + if (value < pnt_x_min) pnt_x_min = value; - if(value > pnt_x_max) + if (value > pnt_x_max) pnt_x_max = value; value = gli_points_vector[i]->y; - if(value < pnt_y_min) + if (value < pnt_y_min) pnt_y_min = value; - if(value > pnt_y_max) + if (value > pnt_y_max) pnt_y_max = value; value = gli_points_vector[i]->z; - if(value < pnt_z_min) + if (value < pnt_z_min) pnt_z_min = value; - if(value > pnt_z_max) + if (value > pnt_z_max) pnt_z_max = value; } } @@ -527,7 +518,7 @@ void GEOCalcPointMinMaxCoordinates() 10/1998 AH Erste Version 08/2005 CC Modification **************************************************************************/ -bool CGLPoint:: IsInsidePolygonPlain(double* xp, double* yp, double* zp, long np) +bool CGLPoint::IsInsidePolygonPlain(double* xp, double* yp, double* zp, long np) { long k; double dp[3], dn[3]; @@ -557,7 +548,7 @@ bool CGLPoint:: IsInsidePolygonPlain(double* xp, double* yp, double* zp, long np norm_dn = MBtrgVec(dn, 3); norm_dp = MBtrgVec(dp, 3); if (norm_dn <= d_eps || norm_dp <= d_eps) - return true; /* auf Rand */ + return true; /* auf Rand */ cosphi = MSkalarprodukt(dn, dp, 3) / norm_dn / norm_dp; phi = acos(cosphi); M3KreuzProdukt(dn, dp, nxp); @@ -572,9 +563,9 @@ bool CGLPoint:: IsInsidePolygonPlain(double* xp, double* yp, double* zp, long np } if (fabs(sumphi - 2. * pi) <= a_eps) - return true; /* Im Gebiet */ + return true; /* Im Gebiet */ else if (fabs(sumphi - pi) <= a_eps) - return true; /* auf Rand */ + return true; /* auf Rand */ else return false; } @@ -585,10 +576,10 @@ bool CGLPoint:: IsInsidePolygonPlain(double* xp, double* yp, double* zp, long np 11/2003 OK Implementation 08/2005 CC Modification CGLPoint* **************************************************************************/ -bool CGLPoint::IsInsideTriangle(double* xv,double* yv,double* zv) +bool CGLPoint::IsInsideTriangle(double* xv, double* yv, double* zv) { - double vec1[3],vec2[3],vec3[3]; - double area,area1,area2,area3; + double vec1[3], vec2[3], vec3[3]; + double area, area1, area2, area3; bool ok = false; double eps; double dist; @@ -599,8 +590,8 @@ bool CGLPoint::IsInsideTriangle(double* xv,double* yv,double* zv) vec2[0] = xv[0] - xv[2]; vec2[1] = yv[0] - yv[2]; vec2[2] = zv[0] - zv[2]; - M3KreuzProdukt(vec1,vec2,vec3); - area = fabs(0.5 * MBtrgVec(vec3,3)); + M3KreuzProdukt(vec1, vec2, vec3); + area = fabs(0.5 * MBtrgVec(vec3, 3)); eps = area * 1e-2; // partial area1 vec1[0] = xv[0] - x; @@ -609,8 +600,8 @@ bool CGLPoint::IsInsideTriangle(double* xv,double* yv,double* zv) vec2[0] = xv[1] - x; vec2[1] = yv[1] - y; vec2[2] = zv[1] - z; - M3KreuzProdukt(vec1,vec2,vec3); - area1 = fabs(0.5 * MBtrgVec(vec3,3)); + M3KreuzProdukt(vec1, vec2, vec3); + area1 = fabs(0.5 * MBtrgVec(vec3, 3)); // partial area2 vec1[0] = xv[1] - x; vec1[1] = yv[1] - y; @@ -618,8 +609,8 @@ bool CGLPoint::IsInsideTriangle(double* xv,double* yv,double* zv) vec2[0] = xv[2] - x; vec2[1] = yv[2] - y; vec2[2] = zv[2] - z; - M3KreuzProdukt(vec1,vec2,vec3); - area2 = fabs(0.5 * MBtrgVec(vec3,3)); + M3KreuzProdukt(vec1, vec2, vec3); + area2 = fabs(0.5 * MBtrgVec(vec3, 3)); // partial area vec1[0] = xv[2] - x; vec1[1] = yv[2] - y; @@ -627,11 +618,11 @@ bool CGLPoint::IsInsideTriangle(double* xv,double* yv,double* zv) vec2[0] = xv[0] - x; vec2[1] = yv[0] - y; vec2[2] = zv[0] - z; - M3KreuzProdukt(vec1,vec2,vec3); - area3 = fabs(0.5 * MBtrgVec(vec3,3)); + M3KreuzProdukt(vec1, vec2, vec3); + area3 = fabs(0.5 * MBtrgVec(vec3, 3)); // check dist = fabs(area - area1 - area2 - area3); - if(dist < eps) + if (dist < eps) ok = true; return ok; } @@ -642,10 +633,10 @@ bool CGLPoint::IsInsideTriangle(double* xv,double* yv,double* zv) 11/2003 OK Implementation 08/2005 CC Modification CGLPoint* **************************************************************************/ -bool CGLPoint::IsInsideRectangle(double* xv,double* yv,double* zv) +bool CGLPoint::IsInsideRectangle(double* xv, double* yv, double* zv) { - double vec1[3],vec2[3],vec3[3]; - double area,area1,area2,area3,area4; + double vec1[3], vec2[3], vec3[3]; + double area, area1, area2, area3, area4; bool ok = false; double eps; double dist; @@ -656,16 +647,16 @@ bool CGLPoint::IsInsideRectangle(double* xv,double* yv,double* zv) vec2[0] = xv[0] - xv[2]; vec2[1] = yv[0] - yv[2]; vec2[2] = zv[0] - zv[2]; - M3KreuzProdukt(vec1,vec2,vec3); - area = fabs(0.5 * MBtrgVec(vec3,3)); + M3KreuzProdukt(vec1, vec2, vec3); + area = fabs(0.5 * MBtrgVec(vec3, 3)); vec1[0] = xv[2] - xv[0]; vec1[1] = yv[2] - yv[0]; vec1[2] = zv[2] - zv[0]; vec2[0] = xv[0] - xv[3]; vec2[1] = yv[0] - yv[3]; vec2[2] = zv[0] - zv[3]; - M3KreuzProdukt(vec1,vec2,vec3); - area += fabs(0.5 * MBtrgVec(vec3,3)); + M3KreuzProdukt(vec1, vec2, vec3); + area += fabs(0.5 * MBtrgVec(vec3, 3)); eps = area * 1e-2; // partial area1 vec1[0] = xv[0] - x; @@ -674,8 +665,8 @@ bool CGLPoint::IsInsideRectangle(double* xv,double* yv,double* zv) vec2[0] = xv[1] - x; vec2[1] = yv[1] - y; vec2[2] = zv[1] - z; - M3KreuzProdukt(vec1,vec2,vec3); - area1 = fabs(0.5 * MBtrgVec(vec3,3)); + M3KreuzProdukt(vec1, vec2, vec3); + area1 = fabs(0.5 * MBtrgVec(vec3, 3)); // partial area2 vec1[0] = xv[1] - x; vec1[1] = yv[1] - y; @@ -683,8 +674,8 @@ bool CGLPoint::IsInsideRectangle(double* xv,double* yv,double* zv) vec2[0] = xv[2] - x; vec2[1] = yv[2] - y; vec2[2] = zv[2] - z; - M3KreuzProdukt(vec1,vec2,vec3); - area2 = fabs(0.5 * MBtrgVec(vec3,3)); + M3KreuzProdukt(vec1, vec2, vec3); + area2 = fabs(0.5 * MBtrgVec(vec3, 3)); // partial area3 vec1[0] = xv[2] - x; vec1[1] = yv[2] - y; @@ -692,8 +683,8 @@ bool CGLPoint::IsInsideRectangle(double* xv,double* yv,double* zv) vec2[0] = xv[3] - x; vec2[1] = yv[3] - y; vec2[2] = zv[3] - z; - M3KreuzProdukt(vec1,vec2,vec3); - area3 = fabs(0.5 * MBtrgVec(vec3,3)); + M3KreuzProdukt(vec1, vec2, vec3); + area3 = fabs(0.5 * MBtrgVec(vec3, 3)); // partial area4 vec1[0] = xv[3] - x; vec1[1] = yv[3] - y; @@ -701,11 +692,11 @@ bool CGLPoint::IsInsideRectangle(double* xv,double* yv,double* zv) vec2[0] = xv[0] - x; vec2[1] = yv[0] - y; vec2[2] = zv[0] - z; - M3KreuzProdukt(vec1,vec2,vec3); - area4 = fabs(0.5 * MBtrgVec(vec3,3)); + M3KreuzProdukt(vec1, vec2, vec3); + area4 = fabs(0.5 * MBtrgVec(vec3, 3)); // check dist = fabs(area - area1 - area2 - area3 - area4); - if(dist < eps) + if (dist < eps) ok = true; return ok; } @@ -716,14 +707,14 @@ bool CGLPoint::IsInsideRectangle(double* xv,double* yv,double* zv) 11/2003 OK Implementation 08/2005 CC Modification CGLPoint* - Move from GeoLib to MSHLib **************************************************************************/ -bool CGLPoint::IsInsidePrism(double* xv,double* yv,double* zv) +bool CGLPoint::IsInsidePrism(double* xv, double* yv, double* zv) { bool ok = false; double t_vol1, t_vol2; double p_vol1, p_vol2, p_vol3; - double sum,prism; + double sum, prism; - double xt[4],yt[4],zt[4]; + double xt[4], yt[4], zt[4]; xt[0] = xv[0]; xt[1] = xv[1]; xt[2] = xv[2]; @@ -736,7 +727,7 @@ bool CGLPoint::IsInsidePrism(double* xv,double* yv,double* zv) zt[1] = zv[1]; zt[2] = zv[2]; zt[3] = z; - t_vol1 = CalcTetraederVolume(xt,yt,zt); + t_vol1 = CalcTetraederVolume(xt, yt, zt); xt[0] = xv[3]; xt[1] = xv[4]; xt[2] = xv[5]; @@ -749,9 +740,9 @@ bool CGLPoint::IsInsidePrism(double* xv,double* yv,double* zv) zt[1] = zv[4]; zt[2] = zv[5]; zt[3] = z; - t_vol2 = CalcTetraederVolume(xt,yt,zt); + t_vol2 = CalcTetraederVolume(xt, yt, zt); - double xp[5],yp[5],zp[5]; + double xp[5], yp[5], zp[5]; xp[0] = xv[0]; xp[1] = xv[1]; xp[2] = xv[4]; @@ -767,7 +758,7 @@ bool CGLPoint::IsInsidePrism(double* xv,double* yv,double* zv) zp[2] = zv[4]; zp[3] = zv[3]; zp[4] = z; - p_vol1 = CalcPyramidVolume(xp,yp,zp); + p_vol1 = CalcPyramidVolume(xp, yp, zp); xp[0] = xv[1]; xp[1] = xv[2]; xp[2] = xv[5]; @@ -783,7 +774,7 @@ bool CGLPoint::IsInsidePrism(double* xv,double* yv,double* zv) zp[2] = zv[5]; zp[3] = zv[4]; zp[4] = z; - p_vol2 = CalcPyramidVolume(xp,yp,zp); + p_vol2 = CalcPyramidVolume(xp, yp, zp); xp[0] = xv[2]; xp[1] = xv[0]; xp[2] = xv[3]; @@ -799,12 +790,12 @@ bool CGLPoint::IsInsidePrism(double* xv,double* yv,double* zv) zp[2] = zv[3]; zp[3] = zv[5]; zp[4] = z; - p_vol3 = CalcPyramidVolume(xp,yp,zp); + p_vol3 = CalcPyramidVolume(xp, yp, zp); sum = t_vol1 + t_vol2 + p_vol1 + p_vol2 + p_vol3; - prism = CalcPrismVolume(xv,yv,zv); - double eps = pow(prism,0.33) * 1e-3; - if(fabs(sum - prism) < eps) + prism = CalcPrismVolume(xv, yv, zv); + double eps = pow(prism, 0.33) * 1e-3; + if (fabs(sum - prism) < eps) ok = true; return ok; @@ -816,9 +807,9 @@ bool CGLPoint::IsInsidePrism(double* xv,double* yv,double* zv) 11/2003 OK Implementation 08/2005 CC Modification Move **************************************************************************/ -bool CGLPoint::IsInTriangleXYProjection(double* xv,double* yv) +bool CGLPoint::IsInTriangleXYProjection(double* xv, double* yv) { - double area,area1,area2,area3; + double area, area1, area2, area3; bool ok = false; double eps; double dist; @@ -870,7 +861,7 @@ bool CGLPoint::IsInTriangleXYProjection(double* xv,double* yv) area3 = fabs(0.5 * M3Determinante(mat3x3)); // check dist = fabs(area - area1 - area2 - area3); - if(dist < eps) + if (dist < eps) ok = true; return ok; } @@ -893,7 +884,7 @@ double CGLPoint::PointDisXY(CGLPoint* m_pnt) CGLPoint* CGLPoint::Exist() { double tolerance = 1e-3; - return isPointInPointVector (gli_points_vector, this, tolerance); + return isPointInPointVector(gli_points_vector, this, tolerance); } /************************************************************************** @@ -905,10 +896,10 @@ int GEOMaxPointID() { int max_pnt_id = -1; CGLPoint* m_pnt = NULL; - for(int i = 0; i < (long)gli_points_vector.size(); i++) + for (int i = 0; i < (long)gli_points_vector.size(); i++) { m_pnt = gli_points_vector[i]; - if(m_pnt->id > max_pnt_id) + if (m_pnt->id > max_pnt_id) max_pnt_id = m_pnt->id; } return max_pnt_id; @@ -930,21 +921,16 @@ void GEOWritePoints(char* file_name) // File handling gli_file_name = (string)file_name + ".gli"; gli_file_name_char = gli_file_name.data(); - f = fopen(gli_file_name_char,"w+"); - if(f) + f = fopen(gli_file_name_char, "w+"); + if (f) { - fprintf(f,"#POINTS\n"); + fprintf(f, "#POINTS\n"); gli_points_vector_size = (long)gli_points_vector.size(); - for(i = 0; i < gli_points_vector_size; i++) - if(gli_points_vector[i]->id > -1) //OK - fprintf(f, - " %ld %#16.11g %#16.11g %#16.11g $MD %g $ID %s\n", \ - gli_points_vector[i]->id, \ - gli_points_vector[i]->x, - gli_points_vector[i]->y, - gli_points_vector[i]->z, \ - gli_points_vector[i]->mesh_density, \ - gli_points_vector[i]->name.c_str()); + for (i = 0; i < gli_points_vector_size; i++) + if (gli_points_vector[i]->id > -1) // OK + fprintf(f, " %ld %#16.11g %#16.11g %#16.11g $MD %g $ID %s\n", gli_points_vector[i]->id, + gli_points_vector[i]->x, gli_points_vector[i]->y, gli_points_vector[i]->z, + gli_points_vector[i]->mesh_density, gli_points_vector[i]->name.c_str()); fclose(f); } else @@ -958,18 +944,14 @@ void GEOWritePoints(char* file_name) Programing: 09/2005 TK Implementation **************************************************************************/ -double AngleSumPointInsideTriangle(double* point, - double* tri_p1, - double* tri_p2, - double* tri_p3, - double tolerance) +double AngleSumPointInsideTriangle(double* point, double* tri_p1, double* tri_p2, double* tri_p3, double tolerance) { double sum = 0.0; - //OK char sum_check[56]; + // OK char sum_check[56]; double pi = 3.14159265359; - double a_quantum,b_quantum,c_quantum; - double cos_alpha[3],alpha_rad[3],alpha_deg[3]; - double a[3],b[3],c[3]; + double a_quantum, b_quantum, c_quantum; + double cos_alpha[3], alpha_rad[3], alpha_deg[3]; + double a[3], b[3], c[3]; /* a-Vektor-Coordinates (a = P0P1)*/ a[0] = tri_p1[0] - point[0]; @@ -993,31 +975,32 @@ double AngleSumPointInsideTriangle(double* point, cos_alpha[0] = 1.0; if (cos_alpha[0] < -1.0) cos_alpha[0] = -1.0; - alpha_rad[0] = acos( cos_alpha[0]); - alpha_deg[0] = ( 180 / pi ) * acos( cos_alpha[0]); + alpha_rad[0] = acos(cos_alpha[0]); + alpha_deg[0] = (180 / pi) * acos(cos_alpha[0]); /*Angle: at P0 -P2P3*/ cos_alpha[1] = ((b[0] * c[0]) + (b[1] * c[1]) + (b[2] * c[2])) / (b_quantum * c_quantum); if (cos_alpha[1] > 1.0) cos_alpha[1] = 1.0; if (cos_alpha[1] < -1.0) cos_alpha[1] = -1.0; - alpha_rad[1] = acos( cos_alpha[1]); - alpha_deg[1] = ( 180 / pi ) * acos( cos_alpha[1]); + alpha_rad[1] = acos(cos_alpha[1]); + alpha_deg[1] = (180 / pi) * acos(cos_alpha[1]); /*Angle: at P0 -P3P1*/ cos_alpha[2] = ((c[0] * a[0]) + (c[1] * a[1]) + (c[2] * a[2])) / (c_quantum * a_quantum); if (cos_alpha[2] > 1.0) cos_alpha[2] = 1.0; if (cos_alpha[2] < -1.0) cos_alpha[2] = -1.0; - alpha_rad[2] = acos( cos_alpha[2]); - alpha_deg[2] = ( 180 / pi ) * acos( cos_alpha[2]); + alpha_rad[2] = acos(cos_alpha[2]); + alpha_deg[2] = (180 / pi) * acos(cos_alpha[2]); sum = (cos_alpha[0] + cos_alpha[1] + cos_alpha[2]); sum = (alpha_rad[0] + alpha_rad[1] + alpha_rad[2]); sum = (alpha_deg[0] + alpha_deg[1] + alpha_deg[2]); - if (cos_alpha[0] == 1.0 || cos_alpha[1] == 1.0 || cos_alpha[2] == 1.0 || - cos_alpha[0] == -1.0 || cos_alpha[0] == -1.0 || cos_alpha[0] == -1.0 ) + if (cos_alpha[0] == 1.0 || cos_alpha[1] == 1.0 || cos_alpha[2] == 1.0 || cos_alpha[0] == -1.0 + || cos_alpha[0] == -1.0 + || cos_alpha[0] == -1.0) { if (cos_alpha[0] == 1.0 || cos_alpha[1] == 1.0 || cos_alpha[2] == 1.0) sum = 180; @@ -1025,63 +1008,61 @@ double AngleSumPointInsideTriangle(double* point, sum = 360; } - if ((point[0] == tri_p1[0] && point[1] == tri_p1[1] && point[2] == tri_p1[2]) || - (point[0] == tri_p2[0] && point[1] == tri_p2[1] && point[2] == tri_p2[2]) || - (point[0] == tri_p3[0] && point[1] == tri_p3[1] && point[2] == tri_p3[2])) + if ((point[0] == tri_p1[0] && point[1] == tri_p1[1] && point[2] == tri_p1[2]) + || (point[0] == tri_p2[0] && point[1] == tri_p2[1] && point[2] == tri_p2[2]) + || (point[0] == tri_p3[0] && point[1] == tri_p3[1] && point[2] == tri_p3[2])) sum = 360; if (a_quantum < tolerance || b_quantum < tolerance || c_quantum < tolerance) sum = 360; - //if (alpha_deg[0]<1 || alpha_deg[1]<1 || alpha_deg[2]<1)sum=360; - return sum; //359.99999999997630 + // if (alpha_deg[0]<1 || alpha_deg[1]<1 || alpha_deg[2]<1)sum=360; + return sum; // 359.99999999997630 } double sqrDist(const CGLPoint* p0, const CGLPoint* p1) { - double v[3] = { p1->getX() - p0->getX(), p1->getY() - p0->getY(), p1->getZ() - p0->getZ() }; - return MathLib::scpr (v, v, 3); + double v[3] = {p1->getX() - p0->getX(), p1->getY() - p0->getY(), p1->getZ() - p0->getZ()}; + return MathLib::scpr(v, v, 3); } -CGLPoint* isPointInPointVector( const std::vector &vec, - const CGLPoint* const p, - double tol) +CGLPoint* isPointInPointVector(const std::vector& vec, const CGLPoint* const p, double tol) { - size_t size (vec.size()); + size_t size(vec.size()); for (size_t i = 0; i < size; ++i) - if (sqrDist (p, vec[i]) < tol) + if (sqrDist(p, vec[i]) < tol) return vec[i]; return NULL; } // LB TODO: trunk transition hack -string get_sub_string(string buffer,string delimiter,int pos1,int* pos2) +string get_sub_string(string buffer, string delimiter, int pos1, int* pos2) { int pos = 0; string empty_string(""); - //string sub_string_this; - *pos2 = (int)buffer.find(delimiter,pos1); - if(*pos2 < 0) + // string sub_string_this; + *pos2 = (int)buffer.find(delimiter, pos1); + if (*pos2 < 0) return empty_string; - while(*pos2 <= pos1) + while (*pos2 <= pos1) { pos1++; - *pos2 = (int)buffer.find(delimiter,pos1); - if(*pos2 < 0) + *pos2 = (int)buffer.find(delimiter, pos1); + if (*pos2 < 0) { *pos2 = (int)buffer.size(); break; } - if(pos1 >= (int)buffer.size()) + if (pos1 >= (int)buffer.size()) break; } - string sub_string_this = buffer.substr(pos1,*pos2); + string sub_string_this = buffer.substr(pos1, *pos2); while (pos >= 0) { pos = (int)sub_string_this.find_first_of(" "); if (pos < 0) break; - sub_string_this.erase(pos,1); + sub_string_this.erase(pos, 1); } return sub_string_this; } diff --git a/GEO/geo_pnt.h b/GEO/geo_pnt.h index 01456a5fa..8694b2dac 100644 --- a/GEO/geo_pnt.h +++ b/GEO/geo_pnt.h @@ -37,60 +37,58 @@ class CGLPoint double data[3]; public: - double getPropert () const { return _propert; } - void setPropert (double propert) { _propert = propert; } - + double getPropert() const { return _propert; } + void setPropert(double propert) { _propert = propert; } //---------------------------------------------------------------------- // Properties // ID std::string name; - long id; //CC + long id; // CC /* *** get and set *** */ /** get the x coordinate of the point */ - double getX () const {return data[0]; } + double getX() const { return data[0]; } /** get the y coordinate of the point */ - double getY () const {return data[1]; } + double getY() const { return data[1]; } /** get the z coordinate of the point */ - double getZ () const {return data[2]; } + double getZ() const { return data[2]; } /** set the x coordinate of the point */ - void setX (double v) { data[0] = v; } + void setX(double v) { data[0] = v; } /** set the y coordinate of the point */ - void setY (double v) { data[1] = v; } + void setY(double v) { data[1] = v; } /** set the z coordinate of the point */ - void setZ (double v) { data[2] = v; } + void setZ(double v) { data[2] = v; } /** get the x,y and z coordinate of the point */ - const double* getPoint () const { return data; } - + const double* getPoint() const { return data; } // do not use this attributes directly - use the getter and setter methods!!! double& x; double& y; double& z; - //double epsilon; - double length; //OK well bore depth in 2D modells - long first_identical_id; //TK - long old_id, new_id; //TK - int nb_of_ply; //TK Number of Polylines using this point - long number_of_doubled_points; //TK + // double epsilon; + double length; // OK well bore depth in 2D modells + long first_identical_id; // TK + long old_id, new_id; // TK + int nb_of_ply; // TK Number of Polylines using this point + long number_of_doubled_points; // TK // Meshing - int index_msh; //WW - double min_seg_length; //TK for polylines - double max_seg_length; //TK + int index_msh; // WW + double min_seg_length; // TK for polylines + double max_seg_length; // TK double mesh_density; // Properties - int type; //OK4801 - long node; //OK - int mat; //CC9999 + int type; // OK4801 + long node; // OK + int mat; // CC9999 double value; // Display - //bool highlighted; + // bool highlighted; int x_pix, y_pix; int circle_pix; - //int display_mode; + // int display_mode; int m_color[3]; - //bool selected; + // bool selected; int plg_hightlight_seg; //---------------------------------------------------------------------- // Methods @@ -103,64 +101,61 @@ class CGLPoint * @param y the second coordinate * @param z the third coordinate */ - CGLPoint (double x, double y, double z); + CGLPoint(double x, double y, double z); /** * constructor for CGLPoint object * @param coordinates the field contains the coordinates */ - CGLPoint (const double* coordinates); + CGLPoint(const double* coordinates); ~CGLPoint(void); // Access - void SetIndex(int L_index) {index_msh = L_index; } - int GetIndex() {return index_msh; } + void SetIndex(int L_index) { index_msh = L_index; } + int GetIndex() { return index_msh; } // I/O // void Write(char*); - std::ios::pos_type Read(std::ifstream*, int&); //CC + std::ios::pos_type Read(std::ifstream*, int&); // CC // GEO - int IsPointExist(); //CC - CGLPoint* Exist(); //OK - double PointDis(CGLPoint*); //CC - double PointDisXY(CGLPoint*); //OK - bool IsInsidePolygonPlain(double*,double*,double*,long); //CC IsPointInsideSurface()? - bool IsInsideTriangle(double*,double*,double*); //CC - bool IsInTriangleXYProjection(double*,double*); //CC - bool IsInsideRectangle(double*,double*,double*); //CC - bool IsInsidePrism(double*,double*,double*); //CC + int IsPointExist(); // CC + CGLPoint* Exist(); // OK + double PointDis(CGLPoint*); // CC + double PointDisXY(CGLPoint*); // OK + bool IsInsidePolygonPlain(double*, double*, double*, long); // CC IsPointInsideSurface()? + bool IsInsideTriangle(double*, double*, double*); // CC + bool IsInTriangleXYProjection(double*, double*); // CC + bool IsInsideRectangle(double*, double*, double*); // CC + bool IsInsidePrism(double*, double*, double*); // CC private: double _propert; }; //------------------------------------------------------------------------ // Properties -extern std::vector GetPointsVector(void); //CC +extern std::vector GetPointsVector(void); // CC extern std::vector gli_points_vector; -extern std::vector pnt_properties_vector; //OK +extern std::vector pnt_properties_vector; // OK //------------------------------------------------------------------------ // Remove extern void GEORemoveAllPoints(); -extern void GEORemovePoint(long); //CC +extern void GEORemovePoint(long); // CC //........................................................................ // I/O -extern void GEOReadPoints(const std::string &file_name_path_base); //CC -extern void GEOReadPointProperties(const std::string &); -extern void GEOWritePoints(char* file_name); //CC +extern void GEOReadPoints(const std::string& file_name_path_base); // CC +extern void GEOReadPointProperties(const std::string&); +extern void GEOWritePoints(char* file_name); // CC //........................................................................ // Access -//extern CGLPoint* GEOGetPointByName(const std::string &);//CC -extern CGLPoint* GEOGetPointById(long); //CC +// extern CGLPoint* GEOGetPointByName(const std::string &);//CC +extern CGLPoint* GEOGetPointById(long); // CC //........................................................................ // GEO extern long GEOPointID(); -extern void GEO_Search_DoublePoints(double); //TK -extern std::vector GEOLIB_SetGLIPoints_Vector(std::vector gl_point); //TK -extern double AngleSumPointInsideTriangle(double* point, - double* tri_p1, - double* tri_p2, - double* tri_p3, +extern void GEO_Search_DoublePoints(double); // TK +extern std::vector GEOLIB_SetGLIPoints_Vector(std::vector gl_point); // TK +extern double AngleSumPointInsideTriangle(double* point, double* tri_p1, double* tri_p2, double* tri_p3, double tolerance); -extern void GEOCalcPointMinMaxCoordinates(); //OK +extern void GEOCalcPointMinMaxCoordinates(); // OK /** tests if the point p is near by a point of the vector vec * \param vec the point vector @@ -168,17 +163,16 @@ extern void GEOCalcPointMinMaxCoordinates(); //OK * \param tol value for stopping criterion (||vec[i] - p||^2 < tol) * \returns pointer to the point * */ -CGLPoint* isPointInPointVector(const std::vector &vec, - const CGLPoint* const p, double tol = 1e-3); +CGLPoint* isPointInPointVector(const std::vector& vec, const CGLPoint* const p, double tol = 1e-3); //........................................................................ -//variables +// variables extern double pnt_x_min; extern double pnt_x_max; extern double pnt_y_min; extern double pnt_y_max; extern double pnt_z_min; extern double pnt_z_max; -//Id +// Id extern long pnt_id_last; #endif diff --git a/GEO/geo_sfc.cpp b/GEO/geo_sfc.cpp index c8611c423..055509e35 100644 --- a/GEO/geo_sfc.cpp +++ b/GEO/geo_sfc.cpp @@ -19,9 +19,9 @@ 03/2004 OK TINs 09/2005 CC GeoLib2 **************************************************************************/ -//MFC +// MFC #include -//GEOLib +// GEOLib #include "files0.h" #include "geo_lib.h" #include "geo_mathlib.h" @@ -34,11 +34,11 @@ using namespace std; -//GSP +// GSP /*----------------------------------------------------------------------*/ -//vector -std::vectorsurface_vector; //CC -int sfc_ID_max = 0; //OK +// vector +std::vector surface_vector; // CC +int sfc_ID_max = 0; // OK /*constructor*/ Surface::Surface(void) : Radius(0.0) { @@ -50,9 +50,9 @@ Surface::Surface(void) : Radius(0.0) mat_group = -1; TIN = NULL; createtins = false; - epsilon = 1e-5; //OK + epsilon = 1e-5; // OK highlighted = false; // CC - meshing_allowed = 0; //OK + meshing_allowed = 0; // OK data_name = "DOMAIN"; type_name = "POLYLINE"; mesh_density = 100; @@ -65,7 +65,7 @@ Surface::~Surface() { int i; - while(polyline_of_surface_vector.size()) //CC + while (polyline_of_surface_vector.size()) // CC polyline_of_surface_vector.pop_back(); for (i = 0; i < (int)nodes_coor_vector.size(); i++) @@ -76,13 +76,13 @@ CTIN::~CTIN() { int i; int no_triangles = (int)Triangles.size(); - //name.empty(); + // name.empty(); name.clear(); - for(i = 0; i < no_triangles; i++) + for (i = 0; i < no_triangles; i++) delete Triangles[i]; - while(Triangles.size()) + while (Triangles.size()) Triangles.pop_back(); - //this == NULL; + // this == NULL; } /************************************************************************** GeoLib-Method: Surface::output(FILE* geo_file, const int index) @@ -93,14 +93,13 @@ CTIN::~CTIN() 08/2004 CC see version: Geosys3909_ac10ww.zip 07/2005 CC .gli to .geo for multi polylines of one surface **************************************************************************/ -void Surface::output(FILE* geo_file, int &p_index, int &l_index, - int &pl_index, int &s_index) +void Surface::output(FILE* geo_file, int& p_index, int& l_index, int& pl_index, int& s_index) { int orient = 1; int i, j, Size0, Size, count, ortL0 = 0, ortL; double dist = 0.0; const double DistTol = 1.0e-10; - //bool firstPline = true; + // bool firstPline = true; std::vector lineIndex; CGLPolyline* p_pline = NULL; @@ -108,25 +107,25 @@ void Surface::output(FILE* geo_file, int &p_index, int &l_index, CGLPoint* CGPnt = NULL; CGLPoint* CGPnt0 = NULL; CGLLine* CGLn0 = NULL; - //WW CGLLine *CGLn1 = NULL; + // WW CGLLine *CGLn1 = NULL; CGLLine* CGLn = NULL; - //First entity: points + // First entity: points // list::const_iterator p = polyline_of_surface_list.begin();//CC std::vector::iterator p = polyline_of_surface_vector.begin(); FilePrintString(geo_file, "// Points"); - LineFeed (geo_file); - while (p != polyline_of_surface_vector.end()) //CC + LineFeed(geo_file); + while (p != polyline_of_surface_vector.end()) // CC { p_pline = *p; Size = (int)p_pline->point_vector.size(); - for(i = 0; i < Size; i++) + for (i = 0; i < Size; i++) { CGPnt = p_pline->point_vector[i]; // Unique the indeces - if(CGPnt->GetIndex() < 0) + if (CGPnt->GetIndex() < 0) { // Compare with other points Size0 = (int)gli_points_vector.size(); @@ -134,14 +133,14 @@ void Surface::output(FILE* geo_file, int &p_index, int &l_index, { CGPnt0 = gli_points_vector[j]; dist = CGPnt->PointDis(CGPnt0); - if(dist < DistTol && CGPnt0->GetIndex() >= 0) + if (dist < DistTol && CGPnt0->GetIndex() >= 0) { CGPnt->SetIndex(CGPnt0->GetIndex()); break; } } // If the mesh index of the point is still not prescribed - if(CGPnt->GetIndex() < 0) + if (CGPnt->GetIndex() < 0) { p_index++; CGPnt->SetIndex(p_index); @@ -155,9 +154,9 @@ void Surface::output(FILE* geo_file, int &p_index, int &l_index, FilePrintDouble(geo_file, CGPnt->z); FilePrintString(geo_file, ", "); FilePrintDouble(geo_file, CGPnt->mesh_density); - //FilePrintString(geo_file, "DensityScale"); + // FilePrintString(geo_file, "DensityScale"); FilePrintString(geo_file, "};"); - LineFeed (geo_file); + LineFeed(geo_file); } } } @@ -165,60 +164,54 @@ void Surface::output(FILE* geo_file, int &p_index, int &l_index, } // Second entity: lines FilePrintString(geo_file, "// Lines"); - LineFeed (geo_file); - p = polyline_of_surface_vector.begin(); //CC - while (p != polyline_of_surface_vector.end()) //CC + LineFeed(geo_file); + p = polyline_of_surface_vector.begin(); // CC + while (p != polyline_of_surface_vector.end()) // CC { p_pline = *p; - std::vector::iterator pl //CC - = p_pline->line_vector.begin(); - while (pl != p_pline->line_vector.end()) //CC + std::vector::iterator pl // CC + = p_pline->line_vector.begin(); + while (pl != p_pline->line_vector.end()) // CC { CGLn = *pl; - //OK test 11.09.2004 - if(!CGLn->m_point1 && !CGLn->m_point2) + // OK test 11.09.2004 + if (!CGLn->m_point1 && !CGLn->m_point2) { - std::cout << "Error in Surface::output: no line points" << - "\n"; - FilePrintString(geo_file, - "Error in Surface::output: no line points"); + std::cout << "Error in Surface::output: no line points" + << "\n"; + FilePrintString(geo_file, "Error in Surface::output: no line points"); return; } - if(CGLn->mesh_index < 0) + if (CGLn->mesh_index < 0) { Size0 = (int)gli_lines_vector.size(); for (j = 0; j < Size0; j++) { CGLn0 = gli_lines_vector[j]; - if(CGLn0->mesh_index >= 0) - if( ((CGLn->m_point1->PointDis(CGLn0->m_point1) < - DistTol) - && (CGLn->m_point2->PointDis(CGLn0->m_point2) - < DistTol)) - || ((CGLn->m_point1->PointDis(CGLn0->m_point2) - < DistTol) - && (CGLn->m_point2->PointDis(CGLn0-> - m_point1) < - DistTol))) + if (CGLn0->mesh_index >= 0) + if (((CGLn->m_point1->PointDis(CGLn0->m_point1) < DistTol) + && (CGLn->m_point2->PointDis(CGLn0->m_point2) < DistTol)) + || ((CGLn->m_point1->PointDis(CGLn0->m_point2) < DistTol) + && (CGLn->m_point2->PointDis(CGLn0->m_point1) < DistTol))) { - CGLn->mesh_index = CGLn0->mesh_index; + CGLn->mesh_index = CGLn0->mesh_index; break; } } // If the mesh index of the line is still not prescribed - if(CGLn->mesh_index < 0) + if (CGLn->mesh_index < 0) { l_index++; CGLn->mesh_index = l_index; FilePrintString(geo_file, "Line("); - FilePrintLong(geo_file,l_index); + FilePrintLong(geo_file, l_index); FilePrintString(geo_file, ")= {"); - FilePrintInt(geo_file,CGLn->m_point1->GetIndex()); + FilePrintInt(geo_file, CGLn->m_point1->GetIndex()); FilePrintString(geo_file, ", "); FilePrintInt(geo_file, CGLn->m_point2->GetIndex()); FilePrintString(geo_file, "};"); - LineFeed (geo_file); + LineFeed(geo_file); CGLn->marked = true; } } @@ -229,55 +222,53 @@ void Surface::output(FILE* geo_file, int &p_index, int &l_index, // Third entity: curves FilePrintString(geo_file, "// Curve"); - LineFeed (geo_file); - p = polyline_of_surface_vector.begin(); //CC + LineFeed(geo_file); + p = polyline_of_surface_vector.begin(); // CC int LocalPLyIndex = 0; - while(p != polyline_of_surface_vector.end()) //CC + while (p != polyline_of_surface_vector.end()) // CC { pl_index++; lineIndex.push_back(pl_index); p_pline = *p; FilePrintString(geo_file, "Line Loop("); - FilePrintInt(geo_file,pl_index); + FilePrintInt(geo_file, pl_index); FilePrintString(geo_file, ")={"); orient = polyline_of_surface_orient[LocalPLyIndex]; - std::vector::iterator pl = p_pline->line_vector.begin(); //WW NULL; - if(orient > 0) + std::vector::iterator pl = p_pline->line_vector.begin(); // WW NULL; + if (orient > 0) { pl = p_pline->line_vector.begin(); count = 0; CGLn0 = NULL; - //WW CGLn1 = NULL; - while(pl != p_pline->line_vector.end()) + // WW CGLn1 = NULL; + while (pl != p_pline->line_vector.end()) { CGLn = *pl; - //Determine the local orentation of this line + // Determine the local orentation of this line ortL = 1; // CGLn = CGLn->CheckLineOutPut(); - if(count == 0) + if (count == 0) { CGPnt = p_pline->point_vector[0]; - if(CGLn->m_point2->PointDis(CGPnt) < DistTol) + if (CGLn->m_point2->PointDis(CGPnt) < DistTol) ortL = -1; } else { - if(ortL0 > 0) + if (ortL0 > 0) { - if( CGLn0->m_point2->PointDis(CGLn->m_point1) < - DistTol) + if (CGLn0->m_point2->PointDis(CGLn->m_point1) < DistTol) ortL = 1; else ortL = -1; } else { - if( CGLn0->m_point1->PointDis(CGLn->m_point1) < - DistTol) + if (CGLn0->m_point1->PointDis(CGLn->m_point1) < DistTol) ortL = 1; else ortL = -1; @@ -288,58 +279,56 @@ void Surface::output(FILE* geo_file, int &p_index, int &l_index, FilePrintInt(geo_file, ortL * CGLn->mesh_index); ++pl; - if(pl != p_pline->line_vector.end()) + if (pl != p_pline->line_vector.end()) FilePrintString(geo_file, ", "); count++; } } else { - pl = p_pline->line_vector.end(); //CC - count = (int)p_pline->line_vector.size(); //CC + pl = p_pline->line_vector.end(); // CC + count = (int)p_pline->line_vector.size(); // CC Size0 = (int)p_pline->point_vector.size(); CGLn0 = NULL; - //WW CGLn1 = NULL; - while(pl != p_pline->line_vector.begin()) //CC + // WW CGLn1 = NULL; + while (pl != p_pline->line_vector.begin()) // CC { --pl; count--; - //Determine the local orentation of this line + // Determine the local orentation of this line ortL = 1; // CGLn = *pl; CGLn = CGLn->CheckLineOutPut(); - int p_pline_line_list_size = (int)p_pline->line_vector.size(); //CC - if(count == p_pline_line_list_size - 1) + int p_pline_line_list_size = (int)p_pline->line_vector.size(); // CC + if (count == p_pline_line_list_size - 1) CGPnt = p_pline->point_vector[Size0 - 1]; - // if(CGLn->m_point1->PointDis(CGPnt)m_point1->PointDis(CGPnt) 0) + if (ortL0 > 0) { - if( CGLn0->m_point2->PointDis(CGLn->m_point1) < - DistTol) + if (CGLn0->m_point2->PointDis(CGLn->m_point1) < DistTol) ortL = 1; - //else ortL = -1;//CC + // else ortL = -1;//CC } - else if( CGLn0->m_point1->PointDis(CGLn->m_point1) < - DistTol) + else if (CGLn0->m_point1->PointDis(CGLn->m_point1) < DistTol) ortL = 1; - //else ortL = -1;//CC + // else ortL = -1;//CC } ortL0 = ortL; CGLn0 = CGLn; FilePrintInt(geo_file, ortL * orient * CGLn->mesh_index); - if(pl != p_pline->line_vector.begin()) - FilePrintString(geo_file, ", "); //CC + if (pl != p_pline->line_vector.begin()) + FilePrintString(geo_file, ", "); // CC } } FilePrintString(geo_file, "};"); - LineFeed (geo_file); + LineFeed(geo_file); LocalPLyIndex++; ++p; @@ -347,31 +336,31 @@ void Surface::output(FILE* geo_file, int &p_index, int &l_index, // Write surface FilePrintString(geo_file, "// Surface"); - LineFeed (geo_file); + LineFeed(geo_file); FilePrintString(geo_file, "Plane Surface("); FilePrintInt(geo_file, s_index); FilePrintString(geo_file, ")={"); int lineIndex_size = (int)lineIndex.size(); - for(i = 0; i < lineIndex_size; i++) + for (i = 0; i < lineIndex_size; i++) { FilePrintInt(geo_file, lineIndex[i]); int lineIndex_size = (int)lineIndex.size(); - if(i != lineIndex_size - 1) + if (i != lineIndex_size - 1) FilePrintString(geo_file, ", "); } FilePrintString(geo_file, "};"); - LineFeed (geo_file); + LineFeed(geo_file); FilePrintString(geo_file, "// Physical Surface"); - LineFeed (geo_file); + LineFeed(geo_file); FilePrintString(geo_file, "Physical Surface("); FilePrintInt(geo_file, s_index); FilePrintString(geo_file, ")={"); FilePrintInt(geo_file, s_index); FilePrintString(geo_file, "};"); - LineFeed (geo_file); + LineFeed(geo_file); } -//OKmsh +// OKmsh /************************************************************************** GeoLib-Method: GEOSurfaceGLI2GEO Task: convert PLI to GEO data @@ -382,34 +371,34 @@ void Surface::output(FILE* geo_file, int &p_index, int &l_index, **************************************************************************/ void GEOSurfaceGLI2GEO(FILE* geo_file) { -//OK3908 - int mesh_surface (0); + // OK3908 + int mesh_surface(0); CGLPolyline* polyline; /* Write the forth entity, surface */ - std::vector::iterator p = polyline_vector.begin(); //CC - while(p != polyline_vector.end()) + std::vector::iterator p = polyline_vector.begin(); // CC + while (p != polyline_vector.end()) { polyline = *p; - if(polyline->getType() == 2) + if (polyline->getType() == 2) { mesh_surface++; FilePrintString(geo_file, "// Surface"); - LineFeed (geo_file); + LineFeed(geo_file); FilePrintString(geo_file, "Plane Surface("); FilePrintInt(geo_file, mesh_surface); FilePrintString(geo_file, ")={"); FilePrintInt(geo_file, mesh_surface); FilePrintString(geo_file, "};"); - LineFeed (geo_file); + LineFeed(geo_file); FilePrintString(geo_file, "// Physical Surface"); - LineFeed (geo_file); + LineFeed(geo_file); FilePrintString(geo_file, "Physical Surface("); FilePrintInt(geo_file, mesh_surface); FilePrintString(geo_file, ")={"); FilePrintInt(geo_file, mesh_surface); FilePrintString(geo_file, "};"); - LineFeed (geo_file); + LineFeed(geo_file); } ++p; } @@ -424,7 +413,7 @@ void GEOSurfaceGLI2GEO(FILE* geo_file) 09/2005 CC move from Geo_lib to geo_sfc 11/05 CC Write function **************************************************************************/ -void Surface::Write(const std::string &path_name) +void Surface::Write(const std::string& path_name) { const char* char_string; //----------------------------------------------------------------------- @@ -435,50 +424,50 @@ void Surface::Write(const std::string &path_name) const char* gli_file_name_char = 0; gli_file_name_char = gli_file_name.data(); gli_file = fopen(gli_file_name_char, "a"); - if(gli_file == NULL) + if (gli_file == NULL) return; else { - fprintf(gli_file,"%s\n","#SURFACE"); + fprintf(gli_file, "%s\n", "#SURFACE"); //----------------------------------------------------------------- - fprintf(gli_file," %s\n","$ID"); - fprintf(gli_file," %ld\n",id); - fprintf(gli_file," %s\n","$NAME"); + fprintf(gli_file, " %s\n", "$ID"); + fprintf(gli_file, " %ld\n", id); + fprintf(gli_file, " %s\n", "$NAME"); char_string = name.data(); - fprintf(gli_file," %s\n",char_string); + fprintf(gli_file, " %s\n", char_string); //----------------------------------------------------------------- - //OK fprintf(gli_file," %s\n","$TYPE"); - //OK fprintf(gli_file," %i\n",m_surface->type); + // OK fprintf(gli_file," %s\n","$TYPE"); + // OK fprintf(gli_file," %i\n",m_surface->type); //----------------------------------------------------------------- - fprintf(gli_file," %s\n","$MAT_GROUP"); - fprintf(gli_file," %i\n",mat_group); + fprintf(gli_file, " %s\n", "$MAT_GROUP"); + fprintf(gli_file, " %i\n", mat_group); //----------------------------------------------------------------- - int polyline_of_surface_list_length = (int)polyline_of_surface_vector.size(); //CC - if(polyline_of_surface_list_length > 0) + int polyline_of_surface_list_length = (int)polyline_of_surface_vector.size(); // CC + if (polyline_of_surface_list_length > 0) { - fprintf(gli_file," %s\n","$POLYLINES"); + fprintf(gli_file, " %s\n", "$POLYLINES"); CGLPolyline* m_polyline = NULL; // list::iterator p = m_surface->polyline_of_surface_list.begin();//CC std::vector::iterator p = polyline_of_surface_vector.begin(); - while(p != polyline_of_surface_vector.end()) //CC + while (p != polyline_of_surface_vector.end()) // CC { m_polyline = *p; - fprintf(gli_file," %s\n",m_polyline->name.c_str()); + fprintf(gli_file, " %s\n", m_polyline->name.c_str()); ++p; } } //----------------------------------------------------------------- - if(TIN) + if (TIN) { int surface_TIN_length = (int)TIN->Triangles.size(); - if(surface_TIN_length > 0) + if (surface_TIN_length > 0) { - fprintf(gli_file," %s\n","$TIN"); - fprintf(gli_file," %s.tin\n",TIN->name.c_str()); + fprintf(gli_file, " %s\n", "$TIN"); + fprintf(gli_file, " %s.tin\n", TIN->name.c_str()); } } //----------------------------------------------------------------- - } //dat_in + } // dat_in fclose(gli_file); } /************************************************************************** @@ -503,31 +492,31 @@ void Surface::ReArrangePolylineList() std::vector buff; int ite = 0; int ite2 = 0; - //list::const_iterator p = polyline_of_surface_list.begin();//CC + // list::const_iterator p = polyline_of_surface_list.begin();//CC std::vector::iterator p = polyline_of_surface_vector.begin(); // The first polyline p_pline = *p; - if(p_pline->data_type == 1) // OK not a toplogical polyline + if (p_pline->data_type == 1) // OK not a toplogical polyline return; buff.push_back(p_pline); - //polyline_of_surface_vector.remove(p_pline);//CC + // polyline_of_surface_vector.remove(p_pline);//CC polyline_of_surface_vector.erase(polyline_of_surface_vector.begin() + ite); - while(polyline_of_surface_vector.size()) + while (polyline_of_surface_vector.size()) { p = polyline_of_surface_vector.begin(); - while(p != polyline_of_surface_vector.end()) + while (p != polyline_of_surface_vector.end()) { top = (int)buff.size() - 1; p_pline = *p; -//OK - if(p_pline->line_vector.size() == 0) //CC + // OK + if (p_pline->line_vector.size() == 0) // CC return; - line_begin = *p_pline->line_vector.begin(); //CC - //line_end = *(--p_pline->line_vector.end()); //CC + line_begin = *p_pline->line_vector.begin(); // CC + // line_end = *(--p_pline->line_vector.end()); //CC long sizea = (long)p_pline->line_vector.size(); line_end = p_pline->line_vector[sizea - 1]; @@ -537,54 +526,51 @@ void Surface::ReArrangePolylineList() long sizeb = (long)pline_b->line_vector.size(); line_b_1 = pline_b->line_vector[sizeb - 1]; - if(Firstply == true) + if (Firstply == true) { - if( - (abs(line_begin->point1) == abs(line_b_1->point2)) - || (abs(line_end->point2) == abs(line_b_1->point2))) + if ((abs(line_begin->point1) == abs(line_b_1->point2)) + || (abs(line_end->point2) == abs(line_b_1->point2))) { buff.push_back(p_pline); // Strike out the compared polylines // polyline_of_surface_vector.remove(p_pline); - polyline_of_surface_vector.erase( - polyline_of_surface_vector.begin() + ite2); + polyline_of_surface_vector.erase(polyline_of_surface_vector.begin() + ite2); ite2 = 0; Firstply = false; break; } - } //end of if Firstply - else if((abs(line_begin->point1) == abs(line_b_1->point2)) - || (abs(line_end->point2) == abs(line_b_1->point2)) - || (abs(line_begin->point1) == abs(line_b_0->point1)) - || (abs(line_end->point2) == abs(line_b_0->point1))) + } // end of if Firstply + else if ((abs(line_begin->point1) == abs(line_b_1->point2)) + || (abs(line_end->point2) == abs(line_b_1->point2)) + || (abs(line_begin->point1) == abs(line_b_0->point1)) + || (abs(line_end->point2) == abs(line_b_0->point1))) { buff.push_back(p_pline); // Strike out the compared polylines -// polyline_of_surface_vector.remove(p_pline); - polyline_of_surface_vector.erase( - polyline_of_surface_vector.begin() + ite2); + // polyline_of_surface_vector.remove(p_pline); + polyline_of_surface_vector.erase(polyline_of_surface_vector.begin() + ite2); ite2 = 0; break; } ++ite2; ++p; - } //end of while - } //end of while - // + } // end of while + } // end of while + // -//////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// long buff_size = (long)buff.size(); - for(int i = 0; i < buff_size; i++) + for (int i = 0; i < buff_size; i++) { pline_b = buff[i]; polyline_of_surface_vector.push_back(pline_b); } // Release the buff - while(buff.size()) + while (buff.size()) buff.pop_back(); } @@ -603,31 +589,28 @@ void Surface::PolylineOrientation() CGLLine* m_line = NULL; CGLLine* line_end = NULL; - //WW CGLLine *line_begin=NULL; + // WW CGLLine *line_begin=NULL; // list::const_iterator p = polyline_of_surface_list.begin(); std::vector::iterator p = polyline_of_surface_vector.begin(); p_pline = *p; - if(p_pline->data_type == 1) // OK not a toplogical polyline + if (p_pline->data_type == 1) // OK not a toplogical polyline return; - while(p != polyline_of_surface_vector.end()) + while (p != polyline_of_surface_vector.end()) { p_pline = *p; - std::vector::iterator pl - = p_pline->line_vector.begin(); //CC + std::vector::iterator pl = p_pline->line_vector.begin(); // CC - //Determine the orientation - if(!firstPline) + // Determine the orientation + if (!firstPline) { m_line = *pl; - if( - m_line->point1 == line_end->point2 || m_line->point1 == - line_end->point1 + if (m_line->point1 == line_end->point2 || m_line->point1 == line_end->point1 - ) + ) orient = 1; else @@ -635,10 +618,10 @@ void Surface::PolylineOrientation() } polyline_of_surface_orient.push_back(orient); -//if it is the first polyline - //WW line_begin = *pl; - if(orient == 1) - while(pl != p_pline->line_vector.end()) //CC + // if it is the first polyline + // WW line_begin = *pl; + if (orient == 1) + while (pl != p_pline->line_vector.end()) // CC { m_line = *pl; @@ -646,10 +629,9 @@ void Surface::PolylineOrientation() } else { - std::vector::iterator pl2 - = p_pline->line_vector.end(); //CC + std::vector::iterator pl2 = p_pline->line_vector.end(); // CC --pl2; - while(pl2 != p_pline->line_vector.begin()) //CC + while (pl2 != p_pline->line_vector.begin()) // CC { m_line = *pl2; @@ -662,7 +644,7 @@ void Surface::PolylineOrientation() firstPline = false; ++p; - } //end of while + } // end of while } /************************************************************************** GeoLib-Method: GEORemoveAllSurfaces() @@ -677,7 +659,7 @@ void Surface::PolylineOrientation() **************************************************************************/ void GEORemoveAllSurfaces() { - for (int i = 0; i < (int) surface_vector.size(); i++) + for (int i = 0; i < (int)surface_vector.size(); i++) { delete surface_vector[i]; surface_vector[i] = NULL; @@ -725,7 +707,7 @@ void GEOSurfaceTopology(void) CGLPolyline* ply = sfc->polyline_of_surface_vector[j]; if (ply->getDataType() == 1) // OK not a toplogical polyline continue; - //compute lines and put into polyline line, here all orientation is 1 + // compute lines and put into polyline line, here all orientation is 1 ply->ComputeLines(); } //.................................................................. @@ -734,7 +716,7 @@ void GEOSurfaceTopology(void) //.................................................................. // Check start and end point of polyline, change the orientation value sfc->PolylineOrientation(); - //surface polyline --point rearrangement + // surface polyline --point rearrangement sfc->order = false; } //---------------------------------------------------------------------- @@ -807,7 +789,7 @@ void Surface::CalcCenterPoint(void) center_point[0] = 0.0; center_point[1] = 0.0; center_point[2] = 0.0; - for(i = 0; i < polygon_point_vector_length; i++) + for (i = 0; i < polygon_point_vector_length; i++) { center_point[0] += polygon_point_vector[i]->x; center_point[1] += polygon_point_vector[i]->y; @@ -847,13 +829,13 @@ void Surface::CreateTIN(void) TIN = new CTIN(); TIN->name = name; //---------------------------------------------------------------------- -//OK41 - if(type == 1) // TIN based on 2 layer polylines + // OK41 + if (type == 1) // TIN based on 2 layer polylines { // list::const_iterator p = polyline_of_surface_list.begin(); std::vector::iterator p = polyline_of_surface_vector.begin(); CGLPolyline* m_polyline1 = NULL; CGLPolyline* m_polyline2 = NULL; - while(p != polyline_of_surface_vector.end()) + while (p != polyline_of_surface_vector.end()) { m_polyline1 = *p; ++p; @@ -861,8 +843,8 @@ void Surface::CreateTIN(void) break; } long no_points = (long)m_polyline1->point_vector.size(); - double xp[3],yp[3],zp[3]; - for(i = 0; i < no_points - 1; i++) + double xp[3], yp[3], zp[3]; + for (i = 0; i < no_points - 1; i++) { // first triangle of quad xp[0] = m_polyline1->point_vector[i]->x; @@ -876,7 +858,7 @@ void Surface::CreateTIN(void) zp[2] = m_polyline2->point_vector[i]->z; m_triangle = new CTriangle; m_triangle->number = (long)TIN->Triangles.size(); - for(j = 0; j < 3; j++) + for (j = 0; j < 3; j++) { m_triangle->x[j] = xp[j]; m_triangle->y[j] = yp[j]; @@ -895,7 +877,7 @@ void Surface::CreateTIN(void) zp[2] = m_polyline1->point_vector[i + 1]->z; m_triangle = new CTriangle; m_triangle->number = (long)TIN->Triangles.size(); - for(j = 0; j < 3; j++) + for (j = 0; j < 3; j++) { m_triangle->x[j] = xp[j]; m_triangle->y[j] = yp[j]; @@ -907,7 +889,7 @@ void Surface::CreateTIN(void) //---------------------------------------------------------------------- // Memory - if(TIN->Triangles.size() == 0) + if (TIN->Triangles.size() == 0) delete TIN; } /************************************************************************** @@ -921,10 +903,10 @@ void GEOWriteSurfaceTINs(string file_path) { vector::iterator ps = surface_vector.begin(); Surface* m_surface = NULL; - while(ps != surface_vector.end()) + while (ps != surface_vector.end()) { m_surface = *ps; - if(!m_surface->TIN) + if (!m_surface->TIN) { ++ps; continue; @@ -948,10 +930,10 @@ void GEOWriteSurfaceTINsTecplot(string file_path) { vector::iterator ps = surface_vector.begin(); Surface* m_surface = NULL; - while(ps != surface_vector.end()) + while (ps != surface_vector.end()) { m_surface = *ps; - if(!m_surface->TIN) + if (!m_surface->TIN) { ++ps; continue; @@ -978,7 +960,7 @@ void GEOWriteSurfaceTINsTecplot(string file_path) 03/2004 OK Implementation 05/2004 CC Modification **************************************************************************/ -void GEOReadSurfaces(const std::string &file_name_path_base) +void GEOReadSurfaces(const std::string& file_name_path_base) { Surface* m_surface = NULL; char line[MAX_ZEILEN]; @@ -989,28 +971,28 @@ void GEOReadSurfaces(const std::string &file_name_path_base) //======================================================================== // File handling gli_file_name = file_name_path_base + ".gli"; - ifstream gli_file (gli_file_name.data(),ios::in); + ifstream gli_file(gli_file_name.data(), ios::in); if (!gli_file.good()) return; - gli_file.seekg(0L,ios::beg); // rewind? + gli_file.seekg(0L, ios::beg); // rewind? //======================================================================== // Keyword loop while (!gli_file.eof()) { - gli_file.getline(line,MAX_ZEILEN); + gli_file.getline(line, MAX_ZEILEN); line_string = line; - if(line_string.find("#STOP") != string::npos) //11.08.2011. WW + if (line_string.find("#STOP") != string::npos) // 11.08.2011. WW break; //---------------------------------------------------------------------- - if(line_string.find("#SURFACE") != string::npos) // keyword found + if (line_string.find("#SURFACE") != string::npos) // keyword found { m_surface = new Surface(); m_surface->AssignColor(); - //OK not here m_surface->TIN = new CTIN; + // OK not here m_surface->TIN = new CTIN; position = m_surface->Read(&gli_file); surface_vector.push_back(m_surface); - gli_file.seekg(position,ios::beg); + gli_file.seekg(position, ios::beg); } // keyword found } // eof gli_file.close(); @@ -1034,7 +1016,7 @@ std::ios::pos_type Surface::Read(std::ifstream* gli_file) CGLPolyline* m_polyline = NULL; CGLPoint* m_point = NULL; bool ok_true = true; - type_name = "POLYLINE"; //CC8888 + type_name = "POLYLINE"; // CC8888 //======================================================================== // Schleife ueber alle Phasen bzw. Komponenten while (!new_keyword) @@ -1065,7 +1047,7 @@ std::ios::pos_type Surface::Read(std::ifstream* gli_file) name = line_string.substr(0); continue; } // subkeyword found - //.................................................................... + //.................................................................... if (line_string.find("$EPSILON") != string::npos) // subkeyword found { gli_file->getline(line, MAX_ZEILEN); @@ -1074,7 +1056,7 @@ std::ios::pos_type Surface::Read(std::ifstream* gli_file) epsilon = strtod(line_string.data(), NULL); continue; } // subkeyword found - //.................................................................... + //.................................................................... if (line_string.find("$TYPE") != string::npos) // subkeyword found { gli_file->getline(line, MAX_ZEILEN); @@ -1086,37 +1068,37 @@ std::ios::pos_type Surface::Read(std::ifstream* gli_file) int p_index; polygon_point_vector.clear(); *gli_file >> p_index; // Center of top surface of cylinder - m_point = GEOGetPointById(p_index); //CC + m_point = GEOGetPointById(p_index); // CC polygon_point_vector.push_back(m_point); *gli_file >> p_index; // Center of bottom surface of cylinder - m_point = GEOGetPointById(p_index); //CC + m_point = GEOGetPointById(p_index); // CC polygon_point_vector.push_back(m_point); *gli_file >> Radius >> epsilon; gli_file->ignore(MAX_ZEILEN, '\n'); } } // subkeyword found - //.................................................................... + //.................................................................... if (line_string.find("$TIN") != string::npos) // subkeyword found { (*gli_file) >> line_string; remove_white_space(&line_string); TIN = new CTIN(); - //TIN->name = name; + // TIN->name = name; ReadTIN(line_string); std::string cut_string; TIN->name = get_sub_string2(line_string, ".", &cut_string); - type = 1; //OK41 - type_name = "TIN"; //CC8888 - data_name = line_string; //CC8888 + type = 1; // OK41 + type_name = "TIN"; // CC8888 + data_name = line_string; // CC8888 } // subkeyword found - //.................................................................... + //.................................................................... if (line_string.find("$MAT_GROUP") != string::npos) // subkeyword found { gli_file->getline(line, MAX_ZEILEN); line_string = line; mat_group = strtol(line_string.data(), NULL, 0); } // subkeyword found - //.................................................................... + //.................................................................... if (line_string.find("$POLYLINES") != string::npos) // subkeyword found // int pos1 = 0, pos2 = 0; while (ok_true) @@ -1124,7 +1106,7 @@ std::ios::pos_type Surface::Read(std::ifstream* gli_file) position = gli_file->tellg(); gli_file->getline(line, MAX_ZEILEN); line_string = line; - type = 0; + type = 0; remove_white_space(&line_string); if (line_string.find("#") != string::npos) return position; @@ -1133,13 +1115,12 @@ std::ios::pos_type Surface::Read(std::ifstream* gli_file) gli_file->seekg(position, ios::beg); break; } - m_polyline = GEOGetPLYByName(line_string); //CC + m_polyline = GEOGetPLYByName(line_string); // CC if (m_polyline) polyline_of_surface_vector.push_back(m_polyline); - //type = m_polyline->data_type; //MB Please set surface type with surface type, not polyline type + // type = m_polyline->data_type; //MB Please set surface type with surface type, not polyline type else - cout << "Warning in Surface::Read, polyline not found: " - << line_string << "\n"; + cout << "Warning in Surface::Read, polyline not found: " << line_string << "\n"; } } return position; @@ -1153,7 +1134,7 @@ std::ios::pos_type Surface::Read(std::ifstream* gli_file) 09/2005 CC file_path_base 10/2005 OK Path 2nd **************************************************************************/ -void Surface::ReadTIN(const std::string &tin_file_name) +void Surface::ReadTIN(const std::string& tin_file_name) { string cut_string; string delimiter_type(" "); @@ -1181,58 +1162,58 @@ void Surface::ReadTIN(const std::string &tin_file_name) */ tin_file_name_path = FilePath + tin_file_name; // 11.08.2011. WW - ifstream tin_file (tin_file_name_path.data(),ios::in); + ifstream tin_file(tin_file_name_path.data(), ios::in); if (!tin_file.good()) return; - tin_file.seekg(0L,ios::beg); + tin_file.seekg(0L, ios::beg); //======================================================================== while (!tin_file.eof()) { - tin_file.getline(line,MAX_ZEILEN); + tin_file.getline(line, MAX_ZEILEN); buffer = line; - if(buffer.size() == 0) + if (buffer.size() == 0) continue; // m_triangle = new CTriangle; // triangle number - sub_string = get_sub_string2(buffer,delimiter_type,&cut_string); - m_triangle->number = strtol(sub_string.data(),NULL,0); + sub_string = get_sub_string2(buffer, delimiter_type, &cut_string); + m_triangle->number = strtol(sub_string.data(), NULL, 0); // point 1 buffer = cut_string; - sub_string = get_sub_string2(buffer,delimiter_type,&cut_string); - m_triangle->x[0] = strtod(sub_string.data(),NULL); + sub_string = get_sub_string2(buffer, delimiter_type, &cut_string); + m_triangle->x[0] = strtod(sub_string.data(), NULL); // buffer = cut_string; - sub_string = get_sub_string2(buffer,delimiter_type,&cut_string); - m_triangle->y[0] = strtod(sub_string.data(),NULL); + sub_string = get_sub_string2(buffer, delimiter_type, &cut_string); + m_triangle->y[0] = strtod(sub_string.data(), NULL); // buffer = cut_string; - sub_string = get_sub_string2(buffer,delimiter_type,&cut_string); - m_triangle->z[0] = strtod(sub_string.data(),NULL); + sub_string = get_sub_string2(buffer, delimiter_type, &cut_string); + m_triangle->z[0] = strtod(sub_string.data(), NULL); // point 2 buffer = cut_string; - sub_string = get_sub_string2(buffer,delimiter_type,&cut_string); - m_triangle->x[1] = strtod(sub_string.data(),NULL); + sub_string = get_sub_string2(buffer, delimiter_type, &cut_string); + m_triangle->x[1] = strtod(sub_string.data(), NULL); // buffer = cut_string; - sub_string = get_sub_string2(buffer,delimiter_type,&cut_string); - m_triangle->y[1] = strtod(sub_string.data(),NULL); + sub_string = get_sub_string2(buffer, delimiter_type, &cut_string); + m_triangle->y[1] = strtod(sub_string.data(), NULL); // buffer = cut_string; - sub_string = get_sub_string2(buffer,delimiter_type,&cut_string); - m_triangle->z[1] = strtod(sub_string.data(),NULL); + sub_string = get_sub_string2(buffer, delimiter_type, &cut_string); + m_triangle->z[1] = strtod(sub_string.data(), NULL); // point 3 buffer = cut_string; - sub_string = get_sub_string2(buffer,delimiter_type,&cut_string); - m_triangle->x[2] = strtod(sub_string.data(),NULL); + sub_string = get_sub_string2(buffer, delimiter_type, &cut_string); + m_triangle->x[2] = strtod(sub_string.data(), NULL); // buffer = cut_string; - sub_string = get_sub_string2(buffer,delimiter_type,&cut_string); - m_triangle->y[2] = strtod(sub_string.data(),NULL); + sub_string = get_sub_string2(buffer, delimiter_type, &cut_string); + m_triangle->y[2] = strtod(sub_string.data(), NULL); // buffer = cut_string; - sub_string = get_sub_string2(buffer,delimiter_type,&cut_string); - m_triangle->z[2] = strtod(sub_string.data(),NULL); + sub_string = get_sub_string2(buffer, delimiter_type, &cut_string); + m_triangle->z[2] = strtod(sub_string.data(), NULL); // TIN->Triangles.push_back(m_triangle); } @@ -1246,12 +1227,12 @@ void Surface::ReadTIN(const std::string &tin_file_name) 01/2005 OK File handling 08/2005 CC string file_path **************************************************************************/ -void Surface::WriteTIN(const std::string &file_path) +void Surface::WriteTIN(const std::string& file_path) { string delimiter(" "); long i; //---------------------------------------------------------------------- - if(TIN && ((long)TIN->Triangles.size() == 0)) + if (TIN && ((long)TIN->Triangles.size() == 0)) return; //---------------------------------------------------------------------- // File handling @@ -1259,26 +1240,20 @@ void Surface::WriteTIN(const std::string &file_path) tin_path = file_path; string tin_file_name = TIN->name + TIN_FILE_EXTENSION; string tin_path_base_type = tin_path + tin_file_name; - fstream tin_file (tin_path_base_type.data(),ios::trunc | ios::out); - tin_file.setf(ios::scientific,ios::floatfield); + fstream tin_file(tin_path_base_type.data(), ios::trunc | ios::out); + tin_file.setf(ios::scientific, ios::floatfield); tin_file.precision(12); //---------------------------------------------------------------------- if (!tin_file.good()) return; - tin_file.seekg(0L,ios::beg); - for(i = 0; i < (long)TIN->Triangles.size(); i++) - tin_file \ - << TIN->Triangles[i]->number << delimiter \ - << TIN->Triangles[i]->x[0] << delimiter \ - << TIN->Triangles[i]->y[0] << delimiter \ - << TIN->Triangles[i]->z[0] << delimiter \ - << TIN->Triangles[i]->x[1] << delimiter \ - << TIN->Triangles[i]->y[1] << delimiter \ - << TIN->Triangles[i]->z[1] << delimiter \ - << TIN->Triangles[i]->x[2] << delimiter \ - << TIN->Triangles[i]->y[2] << delimiter \ - << TIN->Triangles[i]->z[2] << "\n"; - //tin_file.close(); + tin_file.seekg(0L, ios::beg); + for (i = 0; i < (long)TIN->Triangles.size(); i++) + tin_file << TIN->Triangles[i]->number << delimiter << TIN->Triangles[i]->x[0] << delimiter + << TIN->Triangles[i]->y[0] << delimiter << TIN->Triangles[i]->z[0] << delimiter + << TIN->Triangles[i]->x[1] << delimiter << TIN->Triangles[i]->y[1] << delimiter + << TIN->Triangles[i]->z[1] << delimiter << TIN->Triangles[i]->x[2] << delimiter + << TIN->Triangles[i]->y[2] << delimiter << TIN->Triangles[i]->z[2] << "\n"; + // tin_file.close(); } /************************************************************************** @@ -1290,36 +1265,36 @@ void Surface::WriteTIN(const std::string &file_path) **************************************************************************/ void GEOCreateLayerSurfaceTINs(int nb_prism_layers, double thickness_prism_layers) { - long i,j; + long i, j; long no_TIN_Triangles; vector::iterator ps = surface_vector.begin(); Surface* m_surface = NULL; Surface* m_surface_new = NULL; char layer_number[10]; CTriangle* m_triangle = NULL; - vectornew_surfaces; + vector new_surfaces; // Go through the existing surfaces (GEO_type) - while(ps != surface_vector.end()) + while (ps != surface_vector.end()) { m_surface = *ps; - if(!m_surface->TIN) + if (!m_surface->TIN) { ++ps; continue; } no_TIN_Triangles = (long)m_surface->TIN->Triangles.size(); - if(m_surface->type == 0) + if (m_surface->type == 0) // Go through the layers - for(i = 0; i < nb_prism_layers; i++) + for (i = 0; i < nb_prism_layers; i++) { m_surface_new = new Surface; - sprintf(layer_number,"%ld",i + 1); + sprintf(layer_number, "%ld", i + 1); m_surface_new->name = m_surface->name + "_L" + layer_number; m_surface_new->type = m_surface->type; m_surface_new->TIN = new CTIN; m_surface_new->TIN->name = m_surface_new->name; - for(j = 0; j < no_TIN_Triangles; j++) + for (j = 0; j < no_TIN_Triangles; j++) { m_triangle = new CTriangle; m_triangle->number = m_surface->TIN->Triangles[j]->number; @@ -1329,12 +1304,9 @@ void GEOCreateLayerSurfaceTINs(int nb_prism_layers, double thickness_prism_layer m_triangle->y[0] = m_surface->TIN->Triangles[j]->y[0]; m_triangle->y[1] = m_surface->TIN->Triangles[j]->y[1]; m_triangle->y[2] = m_surface->TIN->Triangles[j]->y[2]; - m_triangle->z[0] = m_surface->TIN->Triangles[j]->z[0] - - (i + 1) * thickness_prism_layers; - m_triangle->z[1] = m_surface->TIN->Triangles[j]->z[1] - - (i + 1) * thickness_prism_layers; - m_triangle->z[2] = m_surface->TIN->Triangles[j]->z[2] - - (i + 1) * thickness_prism_layers; + m_triangle->z[0] = m_surface->TIN->Triangles[j]->z[0] - (i + 1) * thickness_prism_layers; + m_triangle->z[1] = m_surface->TIN->Triangles[j]->z[1] - (i + 1) * thickness_prism_layers; + m_triangle->z[2] = m_surface->TIN->Triangles[j]->z[2] - (i + 1) * thickness_prism_layers; m_surface_new->TIN->Triangles.push_back(m_triangle); } new_surfaces.push_back(m_surface_new); @@ -1343,7 +1315,7 @@ void GEOCreateLayerSurfaceTINs(int nb_prism_layers, double thickness_prism_layer } // int new_surfaces_vector_length = (int)new_surfaces.size(); - for(i = 0; i < new_surfaces_vector_length; i++) + for (i = 0; i < new_surfaces_vector_length; i++) { m_surface_new = new_surfaces[i]; surface_vector.push_back(m_surface_new); @@ -1358,49 +1330,45 @@ void GEOCreateLayerSurfaceTINs(int nb_prism_layers, double thickness_prism_layer last modification: 09/2005 CC file_path **************************************************************************/ -void Surface::WriteTINTecplot(const std::string &file_path) +void Surface::WriteTINTecplot(const std::string& file_path) { string delimiter(", "); long i; - if(TIN && (TIN->Triangles.size() > 0)) + if (TIN && (TIN->Triangles.size() > 0)) { //-------------------------------------------------------------------- // File handling string tin_path; // CGSProject* m_gsp = GSPGetMember("gli"); // if(m_gsp) - tin_path = file_path; //CC + tin_path = file_path; // CC string tin_file_name = TIN->name + TEC_FILE_EXTENSIONS; string tin_path_base_type = tin_path + tin_file_name; - fstream tin_file (tin_path_base_type.data(),ios::trunc | ios::out); - tin_file.setf(ios::scientific,ios::floatfield); + fstream tin_file(tin_path_base_type.data(), ios::trunc | ios::out); + tin_file.setf(ios::scientific, ios::floatfield); tin_file.precision(12); //-------------------------------------------------------------------- if (!tin_file.good()) return; - tin_file.seekg(0L,ios::beg); - tin_file << "VARIABLES = X,Y,Z" << "\n"; + tin_file.seekg(0L, ios::beg); + tin_file << "VARIABLES = X,Y,Z" + << "\n"; long no_triangles = (long)TIN->Triangles.size(); long no_nodes = 3 * no_triangles; - tin_file << "ZONE T = " << TIN->name << delimiter \ - << "N = " << no_nodes << delimiter \ - << "E = " << no_triangles << delimiter \ - << "F = FEPOINT" << delimiter << "ET = TRIANGLE" << "\n"; - for(i = 0; i < no_triangles; i++) + tin_file << "ZONE T = " << TIN->name << delimiter << "N = " << no_nodes << delimiter << "E = " << no_triangles + << delimiter << "F = FEPOINT" << delimiter << "ET = TRIANGLE" + << "\n"; + for (i = 0; i < no_triangles; i++) { - tin_file \ - << TIN->Triangles[i]->x[0] << " " << TIN->Triangles[i]->y[0] << " " << - TIN->Triangles[i]->z[0] << "\n"; - tin_file \ - << TIN->Triangles[i]->x[1] << " " << TIN->Triangles[i]->y[1] << " " << - TIN->Triangles[i]->z[1] << "\n"; - tin_file \ - << TIN->Triangles[i]->x[2] << " " << TIN->Triangles[i]->y[2] << " " << - TIN->Triangles[i]->z[2] << "\n"; + tin_file << TIN->Triangles[i]->x[0] << " " << TIN->Triangles[i]->y[0] << " " << TIN->Triangles[i]->z[0] + << "\n"; + tin_file << TIN->Triangles[i]->x[1] << " " << TIN->Triangles[i]->y[1] << " " << TIN->Triangles[i]->z[1] + << "\n"; + tin_file << TIN->Triangles[i]->x[2] << " " << TIN->Triangles[i]->y[2] << " " << TIN->Triangles[i]->z[2] + << "\n"; } - for(i = 0; i < no_triangles; i++) - tin_file \ - << 3 * i + 1 << " " << 3 * i + 2 << " " << 3 * i + 3 << "\n"; + for (i = 0; i < no_triangles; i++) + tin_file << 3 * i + 1 << " " << 3 * i + 2 << " " << 3 * i + 3 << "\n"; } } @@ -1562,62 +1530,58 @@ void Surface::WriteTecplot(fstream* tec_file) long i; CGLPolyline* m_polyline1 = NULL; CGLPolyline* m_polyline2 = NULL; - //list::const_iterator p; + // list::const_iterator p; vector::iterator p; long no_points = 0; - vectortriangle_vector; + vector triangle_vector; //---------------------------------------------------------------------- // Write header - *tec_file << "VARIABLES = X,Y,Z" << "\n"; + *tec_file << "VARIABLES = X,Y,Z" + << "\n"; - switch(type) + switch (type) { - case 22: - p = polyline_of_surface_vector.begin(); - while(p != polyline_of_surface_vector.end()) - { - m_polyline1 = *p; - ++p; - m_polyline2 = *p; + case 22: + p = polyline_of_surface_vector.begin(); + while (p != polyline_of_surface_vector.end()) + { + m_polyline1 = *p; + ++p; + m_polyline2 = *p; + break; + } + no_points = (long)m_polyline1->point_vector.size(); break; - } - no_points = (long)m_polyline1->point_vector.size(); - break; } long no_nodes = 2 * no_points; - //long no_elements = triangle_vector.size(); + // long no_elements = triangle_vector.size(); long no_elements = 2 * (no_points - 1); // Write - *tec_file << "ZONE T = " << name << ", " \ - << "N = " << no_nodes << ", " \ - << "E = " << no_elements << ", " \ - << "F = FEPOINT" << ", " << "ET = TRIANGLE" << "\n"; + *tec_file << "ZONE T = " << name << ", " + << "N = " << no_nodes << ", " + << "E = " << no_elements << ", " + << "F = FEPOINT" + << ", " + << "ET = TRIANGLE" + << "\n"; //---------------------------------------------------------------------- // Write data - if(m_polyline1) - for(i = 0; i < no_points; i++) - *tec_file \ - << m_polyline1->point_vector[i]->x << " " << - m_polyline1->point_vector[i]->y << " " << - m_polyline1->point_vector[i]->z << - " " \ - << "\n"; - - if(m_polyline2) - for(i = 0; i < no_points; i++) - *tec_file \ - << m_polyline2->point_vector[i]->x << " " << - m_polyline2->point_vector[i]->y << " " << - m_polyline2->point_vector[i]->z << - " " \ - << "\n"; - - for(i = 0; i < no_points - 1; i++) - *tec_file \ - << i + 1 << " " << i + 1 + 1 << " " << no_points + i + 1 << "\n"; - for(i = 0; i < no_points - 1; i++) - *tec_file \ - << no_points + i + 1 << " " << no_points + i + 1 + 1 << " " << i + 1 + 1 << "\n"; + if (m_polyline1) + for (i = 0; i < no_points; i++) + *tec_file << m_polyline1->point_vector[i]->x << " " << m_polyline1->point_vector[i]->y << " " + << m_polyline1->point_vector[i]->z << " " + << "\n"; + + if (m_polyline2) + for (i = 0; i < no_points; i++) + *tec_file << m_polyline2->point_vector[i]->x << " " << m_polyline2->point_vector[i]->y << " " + << m_polyline2->point_vector[i]->z << " " + << "\n"; + + for (i = 0; i < no_points - 1; i++) + *tec_file << i + 1 << " " << i + 1 + 1 << " " << no_points + i + 1 << "\n"; + for (i = 0; i < no_points - 1; i++) + *tec_file << no_points + i + 1 << " " << no_points + i + 1 + 1 << " " << i + 1 + 1 << "\n"; } /************************************************************************** @@ -1626,14 +1590,14 @@ void Surface::WriteTecplot(fstream* tec_file) Programing: 08/2005 CC Implementation **************************************************************************/ -Surface* GEOGetSFCByName(const std::string &name) +Surface* GEOGetSFCByName(const std::string& name) { Surface* m_sfc = NULL; - vector::iterator p = surface_vector.begin(); //CC - while(p != surface_vector.end()) + vector::iterator p = surface_vector.begin(); // CC + while (p != surface_vector.end()) { m_sfc = *p; - if(m_sfc->name.compare(name) == 0) + if (m_sfc->name.compare(name) == 0) return m_sfc; ++p; } @@ -1652,21 +1616,21 @@ Surface* GEOGetSFCByName(const std::string &name) void Surface::PolygonPointVector() { int LocalPlyIndex = 0; - if(type == 100) // Cylinder surface WW + if (type == 100) // Cylinder surface WW return; polygon_point_vector.clear(); long i = 0; CGLLine* gl_line = NULL; CGLPoint* gl_point = NULL; CGLPolyline* gl_polyline = NULL; - //CC 02/2008-----------------------------------------------begin + // CC 02/2008-----------------------------------------------begin vector::iterator p1 = polyline_of_surface_vector.begin(); if (polyline_of_surface_vector.size() == 1) { -//Closed polyline + // Closed polyline gl_polyline = *p1; vector::iterator pt = gl_polyline->point_vector.begin(); - while(pt != gl_polyline->point_vector.end()) + while (pt != gl_polyline->point_vector.end()) { gl_point = *pt; @@ -1679,37 +1643,33 @@ void Surface::PolygonPointVector() } else { - //CC-------------------------------------------------------end + // CC-------------------------------------------------------end vector::iterator p1 = polyline_of_surface_vector.begin(); //---------------------------------------------------------------------- - while(p1 != polyline_of_surface_vector.end()) + while (p1 != polyline_of_surface_vector.end()) { gl_polyline = *p1; //.................................................................... - if(gl_polyline->line_vector.size() > 0) + if (gl_polyline->line_vector.size() > 0) { vector::iterator pb = gl_polyline->line_vector.begin(); vector::iterator pe = gl_polyline->line_vector.end(); - if(gl_polyline->line_vector.size() == 0) + if (gl_polyline->line_vector.size() == 0) return; - if(polyline_of_surface_orient[LocalPlyIndex] == 1) - while(pb != gl_polyline->line_vector.end()) + if (polyline_of_surface_orient[LocalPlyIndex] == 1) + while (pb != gl_polyline->line_vector.end()) { gl_line = *pb; - polygon_point_vector.push_back(GEOGetPointById( - gl_line-> - point2)); + polygon_point_vector.push_back(GEOGetPointById(gl_line->point2)); ++i; ++pb; } else - while(pe != gl_polyline->line_vector.begin()) + while (pe != gl_polyline->line_vector.begin()) { gl_line = *(--pe); - polygon_point_vector.push_back(GEOGetPointById( - gl_line-> - point1)); + polygon_point_vector.push_back(GEOGetPointById(gl_line->point1)); ++i; } } @@ -1720,7 +1680,7 @@ void Surface::PolygonPointVector() while (pv != gl_polyline->point_vector.end()) { gl_point = *pv; - polygon_point_vector.push_back( gl_point); + polygon_point_vector.push_back(gl_point); ++pv; ++i; } @@ -1728,9 +1688,9 @@ void Surface::PolygonPointVector() ++p1; LocalPlyIndex++; } - //CC--------------------------------------------------------begin + // CC--------------------------------------------------------begin } - //CC--------------------------------------------------------end + // CC--------------------------------------------------------end } /************************************************************************** GeoLib-Method: @@ -1743,10 +1703,10 @@ void GEOCreateSurfacePointVector(void) { vector::iterator ps = surface_vector.begin(); Surface* m_surface = NULL; - while(ps != surface_vector.end()) + while (ps != surface_vector.end()) { m_surface = *ps; - m_surface->PolygonPointVector(); //CC + m_surface->PolygonPointVector(); // CC ++ps; } } @@ -1757,7 +1717,7 @@ void GEOCreateSurfacePointVector(void) 01/2004 OK Implementation **************************************************************************/ // REMOVE CANDIDATE -//bool Surface::PointInSurface(CGLPoint *m_point) +// bool Surface::PointInSurface(CGLPoint *m_point) //{ // bool ok = false; // m_point = m_point; @@ -1775,7 +1735,7 @@ void GEOUnselectSFC() Surface* m_sfc = NULL; vector::const_iterator p_sfc; p_sfc = surface_vector.begin(); - while(p_sfc != surface_vector.end()) + while (p_sfc != surface_vector.end()) { m_sfc = *p_sfc; m_sfc->highlighted = false; @@ -1788,10 +1748,10 @@ void GEOUnselectSFC() Programing: 11/2005 CC Modification **************************************************************************/ -void GEOWriteSurfaces(const std::string &path_name) +void GEOWriteSurfaces(const std::string& path_name) { Surface* m_sfc = NULL; - for(int i = 0; i < (int)surface_vector.size(); i++) + for (int i = 0; i < (int)surface_vector.size(); i++) { m_sfc = surface_vector[i]; m_sfc->Write(path_name); @@ -1807,15 +1767,15 @@ void GEOWriteSurfaces(const std::string &path_name) void GEORemoveSFC(Surface* m_sfc) { Surface* m_sfc_this = NULL; - //WW vector::const_iterator p_sfc = surface_vector.begin(); - for(int i = 0; i < (int)surface_vector.size(); i++) + // WW vector::const_iterator p_sfc = surface_vector.begin(); + for (int i = 0; i < (int)surface_vector.size(); i++) { m_sfc_this = surface_vector[i]; - if(m_sfc_this->name.compare(m_sfc->name) == 0) + if (m_sfc_this->name.compare(m_sfc->name) == 0) { delete m_sfc_this; surface_vector.erase(surface_vector.begin() + i); - //i--; + // i--; return; } } @@ -1847,7 +1807,7 @@ void MSHUnselectSFC() Surface* m_sfc = NULL; vector::const_iterator p_sfc; p_sfc = surface_vector.begin(); - while(p_sfc != surface_vector.end()) + while (p_sfc != surface_vector.end()) { m_sfc = *p_sfc; m_sfc->meshing_allowed = 0; @@ -1864,10 +1824,10 @@ int SFCGetMaxMATGroupNumber() { int sfc_max_mat_group_number = -1; Surface* m_sfc = NULL; - for(int i = 0; i < (int)surface_vector.size(); i++) + for (int i = 0; i < (int)surface_vector.size(); i++) { m_sfc = surface_vector[i]; - if(m_sfc->mat_group > sfc_max_mat_group_number) + if (m_sfc->mat_group > sfc_max_mat_group_number) sfc_max_mat_group_number = m_sfc->mat_group; } return sfc_max_mat_group_number; @@ -1882,11 +1842,11 @@ int SFCGetMaxMATGroupNumber() void SFCAssignMATColors() { long r_number; - vectoraux_vector; + vector aux_vector; long* m_color; //---------------------------------------------------------------------- int sfc_max_mat_group_number = SFCGetMaxMATGroupNumber(); - for(int i = 0; i < (int)sfc_max_mat_group_number + 1; i++) + for (int i = 0; i < (int)sfc_max_mat_group_number + 1; i++) { m_color = new long[3]; r_number = rand(); @@ -1899,10 +1859,10 @@ void SFCAssignMATColors() } //---------------------------------------------------------------------- Surface* m_sfc = NULL; - for(int i = 0; i < (int)surface_vector.size(); i++) + for (int i = 0; i < (int)surface_vector.size(); i++) { m_sfc = surface_vector[i]; - if(m_sfc->mat_group > 0) + if (m_sfc->mat_group > 0) { m_color = aux_vector[m_sfc->mat_group]; m_sfc->m_color[0] = m_color[0]; @@ -1911,7 +1871,7 @@ void SFCAssignMATColors() } } //---------------------------------------------------------------------- - for(int i = 0; i < (int)aux_vector.size(); i++) + for (int i = 0; i < (int)aux_vector.size(); i++) { m_color = aux_vector[i]; delete m_color; @@ -1929,7 +1889,7 @@ void SFCAssignMATColors() void SFCAssignColors() { Surface* m_sfc = NULL; - for(int i = 0; i < (int)surface_vector.size(); i++) + for (int i = 0; i < (int)surface_vector.size(); i++) { m_sfc = surface_vector[i]; m_sfc->AssignColor(); diff --git a/GEO/geo_sfc.h b/GEO/geo_sfc.h index bc62af058..679426ee3 100644 --- a/GEO/geo_sfc.h +++ b/GEO/geo_sfc.h @@ -27,7 +27,7 @@ class CTriangle class CTIN { public: - CTIN(){} + CTIN() {} ~CTIN(); std::string name; std::vector Triangles; @@ -39,96 +39,95 @@ class Surface public: Surface(); ~Surface(); - //ID - long id; //CC + // ID + long id; // CC std::string name; - //Properties + // Properties int type; std::string type_name; std::string data_name; - //int data_type; + // int data_type; double epsilon; double mesh_density; int mat_group; // MMP std::string mat_group_name; double Radius; // Radius of cylinder. WW - //display + // display int m_color[3]; int display_mode_2d; int display_mode_3d; int display_mode_bc; bool highlighted; // CC - //topology + // topology bool order; bool createtins; double center_point[3]; - //TIN + // TIN CTIN* TIN; - //point vector - std::vectorpolygon_point_vector; + // point vector + std::vector polygon_point_vector; // polylines // list polyline_of_surface_list; std::vector polyline_of_surface_vector; std::vector polyline_of_surface_orient; - std::vectornodes_coor_vector; + std::vector nodes_coor_vector; // MSH - int meshing_allowed; //TK + int meshing_allowed; // TK //---------------------------------------------------------------- - //Method + // Method // I/O - void output(FILE* geo_file, int &p_index, int &l_index, - int &pl_index,int &s_index); - void Write(const std::string &); + void output(FILE* geo_file, int& p_index, int& l_index, int& pl_index, int& s_index); + void Write(const std::string&); std::ios::pos_type Read(std::ifstream*); - //Topology - void PolylineOrientation(); //CC + // Topology + void PolylineOrientation(); // CC void ReArrangePolylineList(); - void PolygonPointVector(); //OK/CC - //point + void PolygonPointVector(); // OK/CC + // point void CalcCenterPoint(void); - //display - void AssignColor(); //CC + // display + void AssignColor(); // CC // TIN void CreateTIN(void); - void ReadTIN(const std::string &); //CC - void WriteTIN(const std::string &); //CC - void WriteTINTecplot(const std::string &); //CC - //Tecplot + void ReadTIN(const std::string&); // CC + void WriteTIN(const std::string&); // CC + void WriteTINTecplot(const std::string&); // CC + // Tecplot void WriteTecplot(std::fstream*); - bool PointInSurface(CGLPoint*); //OK - //material - long profile_code; //YD + bool PointInSurface(CGLPoint*); // OK + // material + long profile_code; // YD private: - // - friend class CGLLine; //WW + // + friend class CGLLine; // WW }; -//vector -extern std::vector surface_vector; //CC -extern std::vector GetSurfaceVector(void); //CC -extern void GEOCreateSurfacePointVector(void); //CC -//Access -extern Surface* GEOGetSFCByName(const std::string &); -//I/O -extern void GEOReadSurfaces(const std::string & file_name_path_base); -extern void GEOWriteSurfaces(const std::string &); //C -//Remove -extern void GEORemoveAllSurfaces(); //CC -extern void GEORemoveSurface(long); //CC +// vector +extern std::vector surface_vector; // CC +extern std::vector GetSurfaceVector(void); // CC +extern void GEOCreateSurfacePointVector(void); // CC +// Access +extern Surface* GEOGetSFCByName(const std::string&); +// I/O +extern void GEOReadSurfaces(const std::string& file_name_path_base); +extern void GEOWriteSurfaces(const std::string&); // C +// Remove +extern void GEORemoveAllSurfaces(); // CC +extern void GEORemoveSurface(long); // CC extern void GEORemoveSFC(Surface* m_sfc); -//Topology +// Topology extern void GEOSurfaceTopology(void); -extern void GEOUnselectSFC(); //OK -//TIN +extern void GEOUnselectSFC(); // OK +// TIN #define TIN_FILE_EXTENSION ".tin" -extern void GEOWriteSurfaceTINs(const std::string &); //TIN -extern void GEOCreateLayerSurfaceTINs(int,double); //TIN -extern void GEOWriteSurfaceTINsTecplot(const std::string &); +extern void GEOWriteSurfaceTINs(const std::string&); // TIN +extern void GEOCreateLayerSurfaceTINs(int, double); // TIN +extern void GEOWriteSurfaceTINsTecplot(const std::string&); extern int sfc_ID_max; // MSH -void MSHUnselectSFC(); //OK -extern int SFCGetMaxMATGroupNumber(); //OK -extern void SFCAssignMATColors(); //OK -extern void SFCAssignColors(); //OK +void MSHUnselectSFC(); // OK +extern int SFCGetMaxMATGroupNumber(); // OK +extern void SFCAssignMATColors(); // OK +extern void SFCAssignColors(); // OK #endif diff --git a/GEO/geo_vol.cpp b/GEO/geo_vol.cpp index 160ef594e..d7b88fb91 100644 --- a/GEO/geo_vol.cpp +++ b/GEO/geo_vol.cpp @@ -23,9 +23,9 @@ #include "geo_sfc.h" #include "geo_vol.h" -using namespace std; //11.08.2011. WW +using namespace std; // 11.08.2011. WW //------------------------------------------------------------------------ -std::vector volume_vector; //CC +std::vector volume_vector; // CC ////////////////////////////////////////////////////////////////////////// // Construction CGLVolume::CGLVolume(void) @@ -43,7 +43,7 @@ CGLVolume::CGLVolume(void) CGLVolume::~CGLVolume(void) { surface_vector.clear(); - //surface_name_list.clear(); + // surface_name_list.clear(); } ////////////////////////////////////////////////////////////////////////// // I/O @@ -64,26 +64,26 @@ void GEOReadVolumes(std::string file_name_path_base) //======================================================================== // File handling gli_file_name = file_name_path_base + ".gli"; - std::ifstream gli_file (gli_file_name.data(),std::ios::in); + std::ifstream gli_file(gli_file_name.data(), std::ios::in); if (!gli_file.good()) return; - gli_file.seekg(0L,std::ios::beg); // rewind? + gli_file.seekg(0L, std::ios::beg); // rewind? //======================================================================== // Keyword loop while (!gli_file.eof()) { - gli_file.getline(line,MAX_ZEILEN); + gli_file.getline(line, MAX_ZEILEN); line_string = line; - if(line_string.find("#STOP") != string::npos) //11.08.2011. WW + if (line_string.find("#STOP") != string::npos) // 11.08.2011. WW break; //---------------------------------------------------------------------- - if(line_string.find("#VOLUME") != std::string::npos) // keyword found + if (line_string.find("#VOLUME") != std::string::npos) // keyword found { m_volume = new CGLVolume(); position = m_volume->Read(&gli_file); volume_vector.push_back(m_volume); - gli_file.seekg(position,std::ios::beg); + gli_file.seekg(position, std::ios::beg); } // keyword found } // eof gli_file.close(); @@ -119,69 +119,69 @@ std::ios::pos_type CGLVolume::Read(std::ifstream* gli_file) while (!new_keyword) { position = gli_file->tellg(); - gli_file->getline(line,MAX_ZEILEN); + gli_file->getline(line, MAX_ZEILEN); line_string = line; - if(line_string.find(hash) != std::string::npos) + if (line_string.find(hash) != std::string::npos) { new_keyword = true; break; } //.................................................................... - if(line_string.find("$NAME") != std::string::npos) // subkeyword found + if (line_string.find("$NAME") != std::string::npos) // subkeyword found { - gli_file->getline(line,MAX_ZEILEN); + gli_file->getline(line, MAX_ZEILEN); line_string = line; remove_white_space(&line_string); name = line_string.substr(0); } // subkeyword found - //.................................................................... - if(line_string.find("$TYPE") != std::string::npos) // subkeyword found + //.................................................................... + if (line_string.find("$TYPE") != std::string::npos) // subkeyword found { - gli_file->getline(line,MAX_ZEILEN); + gli_file->getline(line, MAX_ZEILEN); line_string = line; remove_white_space(&line_string); type_name = line_string; - type = strtol(line_string.data(),NULL,0); + type = strtol(line_string.data(), NULL, 0); } // subkeyword found - //.................................................................... - if(line_string.find("$SURFACES") != std::string::npos) // subkeyword found - while(ok_true) + //.................................................................... + if (line_string.find("$SURFACES") != std::string::npos) // subkeyword found + while (ok_true) { line_string = GetLineFromFile1(gli_file); in.str(line_string); - if(line_string.find("$") != std::string::npos) + if (line_string.find("$") != std::string::npos) { in.clear(); break; } - if(line_string.find("#") != std::string::npos) + if (line_string.find("#") != std::string::npos) { in.clear(); return position; } in >> sfc_name; - m_surface = GEOGetSFCByName(sfc_name); //CC - if(m_surface) + m_surface = GEOGetSFCByName(sfc_name); // CC + if (m_surface) surface_vector.push_back(m_surface); in.clear(); } // subkeyword found //.................................................................... - if(line_string.find("$MAT_GROUP") != std::string::npos) // subkeyword found + if (line_string.find("$MAT_GROUP") != std::string::npos) // subkeyword found { - gli_file->getline(line,MAX_ZEILEN); + gli_file->getline(line, MAX_ZEILEN); line_string = line; - //OK mat_group = strtol(line_string.data(),NULL,0); + // OK mat_group = strtol(line_string.data(),NULL,0); remove_white_space(&line_string); mat_group_name = line_string; } // subkeyword found - //.................................................................... - if(line_string.find("$LAYER") != std::string::npos) // subkeyword found + //.................................................................... + if (line_string.find("$LAYER") != std::string::npos) // subkeyword found { - gli_file->getline(line,MAX_ZEILEN); + gli_file->getline(line, MAX_ZEILEN); line_string = line; - layer = strtol(line_string.data(),NULL,0); - if(layer > 0) + layer = strtol(line_string.data(), NULL, 0); + if (layer > 0) type_name = "LAYER"; } // subkeyword found } @@ -210,30 +210,30 @@ void CGLVolume::Write(std::string path_name) const char* gli_file_name_char = 0; gli_file_name_char = gli_file_name.data(); gli_file = fopen(gli_file_name_char, "a"); - if(gli_file == NULL) + if (gli_file == NULL) return; else { - fprintf(gli_file,"%s\n","#VOLUME"); + fprintf(gli_file, "%s\n", "#VOLUME"); //----------------------------------------------------------------- - fprintf(gli_file," %s\n","$NAME"); + fprintf(gli_file, " %s\n", "$NAME"); char_string = name.data(); - fprintf(gli_file," %s\n",char_string); + fprintf(gli_file, " %s\n", char_string); // Instead of the lines above, the following lines are added by PCH - int surface_list_size = (int)surface_vector.size(); //CC - if(surface_list_size > 0) + int surface_list_size = (int)surface_vector.size(); // CC + if (surface_list_size > 0) { - fprintf(gli_file," %s\n","$SURFACES"); - std::vector::iterator p_sfc = surface_vector.begin(); //CC - while(p_sfc != surface_vector.end()) //CC + fprintf(gli_file, " %s\n", "$SURFACES"); + std::vector::iterator p_sfc = surface_vector.begin(); // CC + while (p_sfc != surface_vector.end()) // CC { m_sfc = *p_sfc; - fprintf(gli_file," %s\n",m_sfc->name.c_str()); + fprintf(gli_file, " %s\n", m_sfc->name.c_str()); ++p_sfc; } } - } //dat_in + } // dat_in fclose(gli_file); //----------------------------------------------------------------- } @@ -250,11 +250,11 @@ void CGLVolume::Write(std::string path_name) CGLVolume* GEOGetVOL(std::string name) { CGLVolume* m_volume = NULL; - std::vector::iterator p = volume_vector.begin(); //CC - while(p != volume_vector.end()) + std::vector::iterator p = volume_vector.begin(); // CC + while (p != volume_vector.end()) { m_volume = *p; - if(m_volume->name == name) + if (m_volume->name == name) return m_volume; ++p; } @@ -270,7 +270,7 @@ CGLVolume* GEOGetVOL(std::string name) 03/2004 OK Implementation 08/2005 CC **************************************************************************/ -bool CGLVolume::PointInVolume(CGLPoint* m_point,int dim_type) +bool CGLVolume::PointInVolume(CGLPoint* m_point, int dim_type) { std::vector::iterator p_sfc; std::string surface_name; @@ -278,63 +278,63 @@ bool CGLVolume::PointInVolume(CGLPoint* m_point,int dim_type) bool ok = false; long i; CGLPoint m_element_point; - std::vectorprism_triangles; + std::vector prism_triangles; long surface_TIN_length; - double xp[6],yp[6],zp[6]; + double xp[6], yp[6], zp[6]; CTriangle* m_triangle = NULL; bool found = false; //======================================================================= switch (dim_type) { - //--------------------------------------------------------------------- - case 0: // 2.5z-D (vertical extension) - //................................................................... - // check x-y - p_sfc = surface_vector.begin(); //CC - while(p_sfc != surface_vector.end()) - { - m_surface = *p_sfc; - surface_TIN_length = (long)m_surface->TIN->Triangles.size(); - for(i = 0; i < surface_TIN_length; i++) + //--------------------------------------------------------------------- + case 0: // 2.5z-D (vertical extension) + //................................................................... + // check x-y + p_sfc = surface_vector.begin(); // CC + while (p_sfc != surface_vector.end()) { - m_triangle = m_surface->TIN->Triangles[i]; - xp[0] = m_triangle->x[0]; - yp[0] = m_triangle->y[0]; - zp[0] = m_triangle->z[0]; - xp[1] = m_triangle->x[1]; - yp[1] = m_triangle->y[1]; - zp[1] = m_triangle->z[1]; - xp[2] = m_triangle->x[2]; - yp[2] = m_triangle->y[2]; - zp[2] = m_triangle->z[2]; - if(m_point->IsInTriangleXYProjection(xp,yp)) + m_surface = *p_sfc; + surface_TIN_length = (long)m_surface->TIN->Triangles.size(); + for (i = 0; i < surface_TIN_length; i++) { - found = true; - prism_triangles.push_back(m_triangle); - continue; + m_triangle = m_surface->TIN->Triangles[i]; + xp[0] = m_triangle->x[0]; + yp[0] = m_triangle->y[0]; + zp[0] = m_triangle->z[0]; + xp[1] = m_triangle->x[1]; + yp[1] = m_triangle->y[1]; + zp[1] = m_triangle->z[1]; + xp[2] = m_triangle->x[2]; + yp[2] = m_triangle->y[2]; + zp[2] = m_triangle->z[2]; + if (m_point->IsInTriangleXYProjection(xp, yp)) + { + found = true; + prism_triangles.push_back(m_triangle); + continue; + } } + ++p_sfc; } - ++p_sfc; - } - if(!found) - return false; - // should be 2 triangles - int triangles_vector_length = (int)prism_triangles.size(); - for(i = 0; i < triangles_vector_length; i++) - { - xp[0 + 3 * i] = prism_triangles[i]->x[0]; - yp[0 + 3 * i] = prism_triangles[i]->y[0]; - zp[0 + 3 * i] = prism_triangles[i]->z[0]; - xp[1 + 3 * i] = prism_triangles[i]->x[1]; - yp[1 + 3 * i] = prism_triangles[i]->y[1]; - zp[1 + 3 * i] = prism_triangles[i]->z[1]; - xp[2 + 3 * i] = prism_triangles[i]->x[2]; - yp[2 + 3 * i] = prism_triangles[i]->y[2]; - zp[2 + 3 * i] = prism_triangles[i]->z[2]; - } - ok = m_point->IsInsidePrism(xp,yp,zp); - break; + if (!found) + return false; + // should be 2 triangles + int triangles_vector_length = (int)prism_triangles.size(); + for (i = 0; i < triangles_vector_length; i++) + { + xp[0 + 3 * i] = prism_triangles[i]->x[0]; + yp[0 + 3 * i] = prism_triangles[i]->y[0]; + zp[0 + 3 * i] = prism_triangles[i]->z[0]; + xp[1 + 3 * i] = prism_triangles[i]->x[1]; + yp[1 + 3 * i] = prism_triangles[i]->y[1]; + zp[1 + 3 * i] = prism_triangles[i]->z[1]; + xp[2 + 3 * i] = prism_triangles[i]->x[2]; + yp[2 + 3 * i] = prism_triangles[i]->y[2]; + zp[2 + 3 * i] = prism_triangles[i]->z[2]; + } + ok = m_point->IsInsidePrism(xp, yp, zp); + break; } // Memory prism_triangles.clear(); @@ -357,7 +357,7 @@ long CGLVolume::GEOInsertVolume2List(CGLVolume* m_volume) } void CGLVolume::AddSurface(Surface* P_Surface) { - surface_vector.push_back(P_Surface); //CC + surface_vector.push_back(P_Surface); // CC } /************************************************************************** GeoLib-Method: GEOGetVolumes @@ -381,7 +381,7 @@ std::vector GEOGetVolumes(void) CGLVolume* GetVolume(long nsel) { CGLVolume* m_volume = NULL; - std::vector::iterator p = volume_vector.begin(); //CC + std::vector::iterator p = volume_vector.begin(); // CC long iter = 0; while (p != volume_vector.end()) { @@ -410,7 +410,7 @@ void GEOWriteVolumes2TecplotV1(std::string file_base_name) (void)file_base_name; long i; CGLVolume* m_volume = NULL; - std::vector::iterator p_vol = volume_vector.begin(); //CC + std::vector::iterator p_vol = volume_vector.begin(); // CC std::string name; Surface* m_surface = NULL; std::vector::iterator p_vol_sfc; @@ -418,108 +418,92 @@ void GEOWriteVolumes2TecplotV1(std::string file_base_name) long no_nodes; std::string delimiter(", "); - while(p_vol != volume_vector.end()) + while (p_vol != volume_vector.end()) { m_volume = *p_vol; //-------------------------------------------------------------------- // file handling std::string vol_file_name = "VOL_" + m_volume->name + TEC_FILE_EXTENSIONS; - std::fstream vol_file (vol_file_name.data(),std::ios::trunc | std::ios::out); - vol_file.setf(std::ios::scientific,std::ios::floatfield); + std::fstream vol_file(vol_file_name.data(), std::ios::trunc | std::ios::out); + vol_file.setf(std::ios::scientific, std::ios::floatfield); vol_file.precision(12); if (!vol_file.good()) return; - vol_file.seekg(0L,std::ios::beg); + vol_file.seekg(0L, std::ios::beg); //-------------------------------------------------------------------- - vol_file << "VARIABLES = X,Y,Z" << "\n"; + vol_file << "VARIABLES = X,Y,Z" + << "\n"; //-------------------------------------------------------------------- - p_vol_sfc = m_volume->surface_vector.begin(); //CC - while(p_vol_sfc != m_volume->surface_vector.end()) //CC + p_vol_sfc = m_volume->surface_vector.begin(); // CC + while (p_vol_sfc != m_volume->surface_vector.end()) // CC { m_surface = *p_vol_sfc; //.................................................................. - if(m_surface->TIN && (m_surface->TIN->Triangles.size() > 0)) + if (m_surface->TIN && (m_surface->TIN->Triangles.size() > 0)) { no_triangles = (long)m_surface->TIN->Triangles.size(); no_nodes = 3 * no_triangles; - vol_file << "ZONE T = " << m_surface->TIN->name << delimiter \ - << "N = " << no_nodes << delimiter \ - << "E = " << no_triangles << delimiter \ - << "F = FEPOINT" << delimiter << "ET = TRIANGLE" << - "\n"; - for(i = 0; i < no_triangles; i++) + vol_file << "ZONE T = " << m_surface->TIN->name << delimiter << "N = " << no_nodes << delimiter + << "E = " << no_triangles << delimiter << "F = FEPOINT" << delimiter << "ET = TRIANGLE" + << "\n"; + for (i = 0; i < no_triangles; i++) { - vol_file \ - << m_surface->TIN->Triangles[i]->x[0] << " " << - m_surface->TIN->Triangles[i]->y[0] << " " << - m_surface->TIN->Triangles[i]->z[0] << "\n"; - vol_file \ - << m_surface->TIN->Triangles[i]->x[1] << " " << - m_surface->TIN->Triangles[i]->y[1] << " " << - m_surface->TIN->Triangles[i]->z[1] << "\n"; - vol_file \ - << m_surface->TIN->Triangles[i]->x[2] << " " << - m_surface->TIN->Triangles[i]->y[2] << " " << - m_surface->TIN->Triangles[i]->z[2] << "\n"; + vol_file << m_surface->TIN->Triangles[i]->x[0] << " " << m_surface->TIN->Triangles[i]->y[0] << " " + << m_surface->TIN->Triangles[i]->z[0] << "\n"; + vol_file << m_surface->TIN->Triangles[i]->x[1] << " " << m_surface->TIN->Triangles[i]->y[1] << " " + << m_surface->TIN->Triangles[i]->z[1] << "\n"; + vol_file << m_surface->TIN->Triangles[i]->x[2] << " " << m_surface->TIN->Triangles[i]->y[2] << " " + << m_surface->TIN->Triangles[i]->z[2] << "\n"; } - for(i = 0; i < no_triangles; i++) - vol_file \ - << 3 * i + 1 << " " << 3 * i + 2 << " " << 3 * i + 3 << - "\n"; + for (i = 0; i < no_triangles; i++) + vol_file << 3 * i + 1 << " " << 3 * i + 2 << " " << 3 * i + 3 << "\n"; } ++p_vol_sfc; } //-------------------------------------------------------------------- // bounding surface // 1 - write header - p_vol_sfc = m_volume->surface_vector.begin(); //CC - while(p_vol_sfc != m_volume->surface_vector.end()) + p_vol_sfc = m_volume->surface_vector.begin(); // CC + while (p_vol_sfc != m_volume->surface_vector.end()) { m_surface = *p_vol_sfc; //.................................................................. no_nodes = (long)m_surface->polygon_point_vector.size(); long no_elements = (long)m_surface->polygon_point_vector.size() - 1; - vol_file << "ZONE T = " << m_surface->TIN->name << delimiter \ - << "N = " << 2 * no_nodes << delimiter \ - << "E = " << no_elements << delimiter \ - << "F = FEPOINT" << delimiter << "ET = QUADRILATERAL" << "\n"; + vol_file << "ZONE T = " << m_surface->TIN->name << delimiter << "N = " << 2 * no_nodes << delimiter + << "E = " << no_elements << delimiter << "F = FEPOINT" << delimiter << "ET = QUADRILATERAL" + << "\n"; //++p_vol_sfc; break; } //-------------------------------------------------------------------- // 2 - write nodes p_vol_sfc = m_volume->surface_vector.begin(); - while(p_vol_sfc != m_volume->surface_vector.end()) + while (p_vol_sfc != m_volume->surface_vector.end()) { m_surface = *p_vol_sfc; //.................................................................. no_nodes = (long)m_surface->polygon_point_vector.size(); - for(i = 0; i < no_nodes; i++) - vol_file \ - << m_surface->polygon_point_vector[i]->x << " " << - m_surface->polygon_point_vector[i]->y << " " << - m_surface->polygon_point_vector[i]->z << "\n"; + for (i = 0; i < no_nodes; i++) + vol_file << m_surface->polygon_point_vector[i]->x << " " << m_surface->polygon_point_vector[i]->y << " " + << m_surface->polygon_point_vector[i]->z << "\n"; //++p_vol_sfc; - for(i = 0; i < no_nodes; i++) - vol_file \ - << m_surface->polygon_point_vector[i]->x << " " << - m_surface->polygon_point_vector[i]->y << " " << - m_surface->polygon_point_vector[i]->z - 1000. << "\n"; + for (i = 0; i < no_nodes; i++) + vol_file << m_surface->polygon_point_vector[i]->x << " " << m_surface->polygon_point_vector[i]->y << " " + << m_surface->polygon_point_vector[i]->z - 1000. << "\n"; break; } //-------------------------------------------------------------------- // 3 - write elements p_vol_sfc = m_volume->surface_vector.begin(); - while(p_vol_sfc != m_volume->surface_vector.end()) + while (p_vol_sfc != m_volume->surface_vector.end()) { m_surface = *p_vol_sfc; //.................................................................. no_nodes = (long)m_surface->polygon_point_vector.size(); long no_elements = (long)m_surface->polygon_point_vector.size() - 1; - for(i = 0; i < no_elements; i++) - vol_file \ - << i + 1 << " " << i + 2 << " " << i + no_nodes + 2 << " " << i + - no_nodes + 1 << "\n"; + for (i = 0; i < no_elements; i++) + vol_file << i + 1 << " " << i + 2 << " " << i + no_nodes + 2 << " " << i + no_nodes + 1 << "\n"; //++ps; break; } @@ -538,7 +522,7 @@ void GEOWriteVolumes2TecplotV1(std::string file_base_name) void GEOWriteVolumes(std::string path_name) { CGLVolume* m_vol = NULL; - for(int i = 0; i < (int)volume_vector.size(); i++) + for (int i = 0; i < (int)volume_vector.size(); i++) { m_vol = volume_vector[i]; m_vol->Write(path_name); @@ -573,10 +557,10 @@ void GEORemoveAllVolumes() void GEORemoveVOL(CGLVolume* m_vol) { CGLVolume* m_vol_this = NULL; - for(int i = 0; i < (int)volume_vector.size(); i++) + for (int i = 0; i < (int)volume_vector.size(); i++) { m_vol_this = volume_vector[i]; - if(m_vol_this->name.compare(m_vol->name) == 0) + if (m_vol_this->name.compare(m_vol->name) == 0) { delete m_vol_this; volume_vector.erase(volume_vector.begin() + i); @@ -584,4 +568,3 @@ void GEORemoveVOL(CGLVolume* m_vol) } } } - diff --git a/GEO/geo_vol.h b/GEO/geo_vol.h index 141a39524..023308be2 100644 --- a/GEO/geo_vol.h +++ b/GEO/geo_vol.h @@ -32,9 +32,9 @@ class CGLVolume int display_mode; int data_type; Surface* m_sfc; - std::vectorsurface_vector; //CC - //list surface_name_list;// todo CC - int layer; //OK + std::vector surface_vector; // CC + // list surface_name_list;// todo CC + int layer; // OK // MAT int mat_group; std::string mat_group_name; @@ -54,25 +54,25 @@ class CGLVolume void AddSurface(Surface* P_Surface); // I/O std::ios::pos_type Read(std::ifstream*); - void Write(std::string); //CC + void Write(std::string); // CC // GEO - bool PointInVolume(CGLPoint*,int); + bool PointInVolume(CGLPoint*, int); // kg44 needed for domain decomposition with PETSC - void SetConditionTypeIC(const bool value) { for_ic=value;} ; - bool GetConditionTypeIC() const {return for_ic;} ; + void SetConditionTypeIC(const bool value) { for_ic = value; }; + bool GetConditionTypeIC() const { return for_ic; }; //---------------------------------------------------------------------- }; -extern std::vector volume_vector; //CC +extern std::vector volume_vector; // CC extern std::vector GEOGetVolumes(void); // I/O extern void GEOReadVolumes(std::string file_name_path_base); -extern void GEOWriteVolumes(std::string); //CC +extern void GEOWriteVolumes(std::string); // CC void GEOWriteVOL(FILE*); -//Access -extern CGLVolume* GEOGetVOL(std::string); //CC//OK -extern CGLVolume* GetVolume(long nsel); //CC -//Remove +// Access +extern CGLVolume* GEOGetVOL(std::string); // CC//OK +extern CGLVolume* GetVolume(long nsel); // CC +// Remove extern void GEORemoveAllVolumes(); -extern void GEORemoveVOL(CGLVolume*); //OK +extern void GEORemoveVOL(CGLVolume*); // OK #endif diff --git a/MSH/GridAdapter.cpp b/MSH/GridAdapter.cpp index 3a48931c5..b47568ec1 100644 --- a/MSH/GridAdapter.cpp +++ b/MSH/GridAdapter.cpp @@ -16,45 +16,42 @@ #include #include -GridAdapter::GridAdapter(const MeshLib::CFEMesh* mesh) : - _name(""), _nodes(new std::vector), _elems(new std::vector), - _mesh(mesh) +GridAdapter::GridAdapter(const MeshLib::CFEMesh* mesh) + : _name(""), _nodes(new std::vector), _elems(new std::vector), _mesh(mesh) { if (mesh) this->convertCFEMesh(mesh); } -GridAdapter::GridAdapter(const std::string &filename) : - _name(""), _nodes(new std::vector), _elems(new std::vector), - _mesh(NULL) +GridAdapter::GridAdapter(const std::string& filename) + : _name(""), _nodes(new std::vector), _elems(new std::vector), _mesh(NULL) { readMeshFromFile(filename); } -GridAdapter::GridAdapter(const GridAdapter* grid) : - _name(""), _nodes(new std::vector), _elems(new std::vector), - _mesh(NULL) +GridAdapter::GridAdapter(const GridAdapter* grid) + : _name(""), _nodes(new std::vector), _elems(new std::vector), _mesh(NULL) { if (grid) { this->_name = grid->getName(); - const std::vector *nodes = grid->getNodes(); + const std::vector* nodes = grid->getNodes(); const size_t nNodes(nodes->size()); - for (size_t i=0; igetData())); + GEOLIB::Point* pnt(new GEOLIB::Point((*nodes)[i]->getData())); this->addNode(pnt); } - const std::vector *elements = grid->getElements(); + const std::vector* elements = grid->getElements(); const size_t nElems(elements->size()); - for (size_t i=0; imaterial = (*elements)[i]->material; - const size_t nElemNodes ((*elements)[i]->nodes.size()); - for (size_t j=0; jnodes.size()); + for (size_t j = 0; j < nElemNodes; j++) elem->nodes.push_back((*elements)[i]->nodes[j]); elem->type = (*elements)[i]->type; this->addElement(elem); @@ -104,7 +101,8 @@ int GridAdapter::convertCFEMesh(const MeshLib::CFEMesh* mesh) _elems->push_back(newElem); } else - std::cout << "GridAdapter::convertCFEMesh() - Error recognising element type..." << "\n"; + std::cout << "GridAdapter::convertCFEMesh() - Error recognising element type..." + << "\n"; } return 1; @@ -126,7 +124,7 @@ const MeshLib::CFEMesh* GridAdapter::getCFEMesh() const MeshLib::CFEMesh* GridAdapter::toCFEMesh() const { - MeshLib::CFEMesh* mesh (new MeshLib::CFEMesh()); + MeshLib::CFEMesh* mesh(new MeshLib::CFEMesh()); std::cout << "Converting mesh object ... "; // set mesh nodes @@ -150,27 +148,28 @@ const MeshLib::CFEMesh* GridAdapter::toCFEMesh() const } mesh->ConstructGrid(); - std::cout << "done." << "\n"; + std::cout << "done." + << "\n"; return mesh; } -int GridAdapter::readMeshFromFile(const std::string &filename) +int GridAdapter::readMeshFromFile(const std::string& filename) { std::string line; std::list::const_iterator it; - std::ifstream in( filename.c_str() ); + std::ifstream in(filename.c_str()); if (!in.is_open()) { - std::cout << "GridAdapter::readMeshFromFile() - Could not open file..." << - "\n"; + std::cout << "GridAdapter::readMeshFromFile() - Could not open file..." + << "\n"; return 0; } // try to find the start of the nodes list - while ( getline(in, line) ) + while (getline(in, line)) { trim(line); if (line.compare("$NODES") == 0) @@ -182,7 +181,7 @@ int GridAdapter::readMeshFromFile(const std::string &filename) trim(line); // read all nodes - while ( getline(in, line) ) + while (getline(in, line)) { trim(line); if (line.compare("$ELEMENTS") == 0) @@ -205,14 +204,12 @@ int GridAdapter::readMeshFromFile(const std::string &filename) _nodes->push_back(pnt); } else - std::cout << - "GridAdapter::readMeshFromFile() - Index error while reading nodes..." + std::cout << "GridAdapter::readMeshFromFile() - Index error while reading nodes..." << "\n"; } else - std::cout << - "GridAdapter::readMeshFromFile() - Error reading node format..." << - "\n"; + std::cout << "GridAdapter::readMeshFromFile() - Error reading node format..." + << "\n"; } if (line.compare("$ELEMENTS") == 0) @@ -224,7 +221,7 @@ int GridAdapter::readMeshFromFile(const std::string &filename) trim(line); // read all elements - while ( getline(in, line) ) + while (getline(in, line)) { trim(line); if (line.compare("$LAYER") == 0) @@ -259,39 +256,36 @@ int GridAdapter::readMeshFromFile(const std::string &filename) } else { - std::cout << - "GridAdapter::readMeshFromFile() - Error recognising element type..." + std::cout << "GridAdapter::readMeshFromFile() - Error recognising element type..." << "\n"; return 0; } } else { - std::cout << - "GridAdapter::readMeshFromFile() - Index error while reading element " << *it << "... " + std::cout << "GridAdapter::readMeshFromFile() - Index error while reading element " << *it << "... " << "\n"; return 0; } } else { - std::cout << - "GridAdapter::readMeshFromFile() - Error reading element format..." + std::cout << "GridAdapter::readMeshFromFile() - Error reading element format..." << "\n"; return 0; } } } else - std::cout << - "GridAdapter::readMeshFromFile() - Index error after reading nodes..." << "\n"; + std::cout << "GridAdapter::readMeshFromFile() - Index error after reading nodes..." + << "\n"; in.close(); return 1; } -MshElemType::type GridAdapter::getElementType(const std::string &t) const +MshElemType::type GridAdapter::getElementType(const std::string& t) const { if (t.compare("tri") == 0) return MshElemType::TRIANGLE; diff --git a/MSH/GridAdapter.h b/MSH/GridAdapter.h index 768755229..f16c1510a 100644 --- a/MSH/GridAdapter.h +++ b/MSH/GridAdapter.h @@ -42,7 +42,7 @@ class GridAdapter GridAdapter(const MeshLib::CFEMesh* mesh); /// Constructor using a MSH-file as source - GridAdapter(const std::string &filename); + GridAdapter(const std::string& filename); /// Copy Constructor GridAdapter(const GridAdapter* grid = NULL); @@ -51,19 +51,15 @@ class GridAdapter /// Adds a node to the grid void addNode(GEOLIB::Point* node) { _nodes->push_back(node); }; - /// Adds an element to the grid void addElement(Element* element) { _elems->push_back(element); }; - /// Returns the total number of unique material IDs. size_t getNumberOfMaterials() const; /// Returns the vector of nodes. const std::vector* getNodes() const { return _nodes; } - /// Returns the vector of elements. const std::vector* getElements() const { return _elems; } - /// Return a vector of elements for one material group only. const std::vector* getElements(size_t matID) const; @@ -75,25 +71,21 @@ class GridAdapter /// Returns the name of the mesh. std::string getName() const { return _name; } - /// Sets the element vector of the grid - void setElements(std::vector *elements) { _elems=elements; }; - + void setElements(std::vector* elements) { _elems = elements; }; /// Sets the name for the mesh. - void setName(const std::string &name) { _name = name; } - + void setName(const std::string& name) { _name = name; } /// Sets the node vector of the grid - void setNodeVector(std::vector *nodes) { _nodes=nodes; }; - + void setNodeVector(std::vector* nodes) { _nodes = nodes; }; private: /// Converts an FEM Mesh to a list of nodes and elements. int convertCFEMesh(const MeshLib::CFEMesh* mesh); /// Reads a MSH file into a list of nodes and elements. - int readMeshFromFile(const std::string &filename); + int readMeshFromFile(const std::string& filename); /// Converts a string to a MshElemType - MshElemType::type getElementType(const std::string &t) const; + MshElemType::type getElementType(const std::string& t) const; /// Converts a GridAdapter into an CFEMesh. const MeshLib::CFEMesh* toCFEMesh() const; diff --git a/MSH/MSHEnums.cpp b/MSH/MSHEnums.cpp index 4fa16da3f..119ba4ffe 100644 --- a/MSH/MSHEnums.cpp +++ b/MSH/MSHEnums.cpp @@ -30,17 +30,17 @@ const std::string MshElemType2String(const MshElemType::type t) return "none"; } -MshElemType::type String2MshElemType(const std::string &s) +MshElemType::type String2MshElemType(const std::string& s) { if (s.compare("line") == 0) return MshElemType::LINE; if (s.compare("quad") == 0) return MshElemType::QUAD; - if (s.compare("hex") == 0) + if (s.compare("hex") == 0) return MshElemType::HEXAHEDRON; - if (s.compare("tri") == 0) + if (s.compare("tri") == 0) return MshElemType::TRIANGLE; - if (s.compare("tet") == 0) + if (s.compare("tet") == 0) return MshElemType::TETRAHEDRON; if (s.compare("pris") == 0) return MshElemType::PRISM; diff --git a/MSH/MSHEnums.h b/MSH/MSHEnums.h index ae8b00c46..ba3e24542 100644 --- a/MSH/MSHEnums.h +++ b/MSH/MSHEnums.h @@ -21,7 +21,8 @@ */ struct MshElemType { - enum type { + enum type + { LINE = 1, QUAD = 2, HEXAHEDRON = 3, @@ -35,7 +36,8 @@ struct MshElemType struct MshQualityType { - enum type { + enum type + { INVALID = 0, AREA, VOLUME, @@ -48,8 +50,8 @@ struct MshQualityType const std::string MshElemType2String(const MshElemType::type t); /// Given a string describing an element type this returns the corresponding MshElemType. -MshElemType::type String2MshElemType(const std::string &s); +MshElemType::type String2MshElemType(const std::string& s); const std::string MshQualityType2String(const MshQualityType::type t); -#endif //MSHENUMS_H +#endif // MSHENUMS_H diff --git a/MSH/MeshNodesAlongPolyline.cpp b/MSH/MeshNodesAlongPolyline.cpp old mode 100755 new mode 100644 index 28ec0c2c2..f59904fbe --- a/MSH/MeshNodesAlongPolyline.cpp +++ b/MSH/MeshNodesAlongPolyline.cpp @@ -21,22 +21,21 @@ namespace MeshLib { -MeshNodesAlongPolyline::MeshNodesAlongPolyline( - GEOLIB::Polyline const* const ply, MeshLib::CFEMesh const* mesh, - double search_radius) : - _ply(ply), _mesh(mesh), _linear_nodes (0) +MeshNodesAlongPolyline::MeshNodesAlongPolyline(GEOLIB::Polyline const* const ply, MeshLib::CFEMesh const* mesh, + double search_radius) + : _ply(ply), _mesh(mesh), _linear_nodes(0) { - std::vector const& mesh_nodes (mesh->getNodeVector()); + std::vector const& mesh_nodes(mesh->getNodeVector()); - size_t n_linear_order_nodes (mesh->GetNodesNumber (false)); - size_t n_nodes (mesh->GetNodesNumber (true)); + size_t n_linear_order_nodes(mesh->GetNodesNumber(false)); + size_t n_nodes(mesh->GetNodesNumber(true)); std::vector msh_node_higher_order_ids; std::vector dist_of_proj_higher_order_node_from_ply_start; - //We need exactly defined polyline for DDC. If there is not any node located within the + // We need exactly defined polyline for DDC. If there is not any node located within the // threhold the ployline, we do not forced to fill the _msh_node_ids. - //Therefore, the repeating loop is skipped. + // Therefore, the repeating loop is skipped. // repeat until at least one relevant node was found // WW while (_msh_node_ids.empty()) { @@ -44,9 +43,9 @@ MeshNodesAlongPolyline::MeshNodesAlongPolyline( for (size_t k = 0; k < ply->getNumberOfPoints() - 1; k++) { double act_length_of_ply(ply->getLength(k)); - double seg_length (sqrt(MathLib::sqrDist(_ply->getPoint(k), _ply->getPoint(k + 1)))); - double lower_lambda (- search_radius / seg_length); - double upper_lambda (1 + search_radius / seg_length); + double seg_length(sqrt(MathLib::sqrDist(_ply->getPoint(k), _ply->getPoint(k + 1)))); + double lower_lambda(-search_radius / seg_length); + double upper_lambda(1 + search_radius / seg_length); // loop over all nodes for (size_t j = 0; j < n_nodes; j++) @@ -56,26 +55,32 @@ MeshNodesAlongPolyline::MeshNodesAlongPolyline( // is the orthogonal projection of the j-th node to the // line g(lambda) = _ply->getPoint(k) + lambda * (_ply->getPoint(k+1) - _ply->getPoint(k)) // at the k-th line segment of the polyline, i.e. 0 <= lambda <= 1? - if (MathLib::calcProjPntToLineAndDists(mesh_nodes[j]->getData(), - (_ply->getPoint(k))->getData(), (_ply->getPoint(k + 1))->getData(), - lambda, dist) <= search_radius) { - if (lower_lambda <= lambda && lambda <= upper_lambda) { - if (mesh_nodes[j]->GetIndex() < n_linear_order_nodes) { + if (MathLib::calcProjPntToLineAndDists(mesh_nodes[j]->getData(), (_ply->getPoint(k))->getData(), + (_ply->getPoint(k + 1))->getData(), lambda, dist) + <= search_radius) + { + if (lower_lambda <= lambda && lambda <= upper_lambda) + { + if (mesh_nodes[j]->GetIndex() < n_linear_order_nodes) + { // check if node id is already in the vector - if (std::find(_msh_node_ids.begin(), _msh_node_ids.end(), - mesh_nodes[j]->GetIndex()) == _msh_node_ids.end()) { - _msh_node_ids.push_back(mesh_nodes[j] ->GetIndex()); - _dist_of_proj_node_from_ply_start. push_back(act_length_of_ply + dist); + if (std::find(_msh_node_ids.begin(), _msh_node_ids.end(), mesh_nodes[j]->GetIndex()) + == _msh_node_ids.end()) + { + _msh_node_ids.push_back(mesh_nodes[j]->GetIndex()); + _dist_of_proj_node_from_ply_start.push_back(act_length_of_ply + dist); _linear_nodes++; } - } else { + } + else + { // check if node id is already in the vector - if (std::find(msh_node_higher_order_ids.begin(), - msh_node_higher_order_ids.end(), mesh_nodes[j]->GetIndex()) - == msh_node_higher_order_ids.end()) { + if (std::find(msh_node_higher_order_ids.begin(), msh_node_higher_order_ids.end(), + mesh_nodes[j]->GetIndex()) + == msh_node_higher_order_ids.end()) + { msh_node_higher_order_ids.push_back(mesh_nodes[j]->GetIndex()); - dist_of_proj_higher_order_node_from_ply_start .push_back(act_length_of_ply - + dist); + dist_of_proj_higher_order_node_from_ply_start.push_back(act_length_of_ply + dist); } } } // end if lambda @@ -83,15 +88,14 @@ MeshNodesAlongPolyline::MeshNodesAlongPolyline( } // end node loop } // end line segment loop - //We need exactly defined polyline for DDC. - //Therefore, the following two line should be dropped. - //if (_msh_node_ids.empty()) + // We need exactly defined polyline for DDC. + // Therefore, the following two line should be dropped. + // if (_msh_node_ids.empty()) // search_radius *= 2.0; } // sort the (linear) nodes along the polyline according to their distances - Quicksort (_dist_of_proj_node_from_ply_start, 0, - _dist_of_proj_node_from_ply_start.size(), _msh_node_ids); + Quicksort(_dist_of_proj_node_from_ply_start, 0, _dist_of_proj_node_from_ply_start.size(), _msh_node_ids); #ifndef NDEBUG // std::cout << "[DEBUG-INFO] " << "\n"; @@ -114,23 +118,23 @@ MeshNodesAlongPolyline::MeshNodesAlongPolyline( #endif // assign/append higher order nodes at the end of vector _msh_node_ids for (size_t k(0); k < msh_node_higher_order_ids.size(); k++) - _msh_node_ids.push_back (msh_node_higher_order_ids[k]); + _msh_node_ids.push_back(msh_node_higher_order_ids[k]); // append distances for higher order nodes at the end of vector _dist_of_proj_node_from_ply_start for (size_t k(0); k < dist_of_proj_higher_order_node_from_ply_start.size(); k++) _dist_of_proj_node_from_ply_start.push_back(dist_of_proj_higher_order_node_from_ply_start[k]); } -const std::vector& MeshNodesAlongPolyline::getNodeIDs () const +const std::vector& MeshNodesAlongPolyline::getNodeIDs() const { return _msh_node_ids; } -const GEOLIB::Polyline* MeshNodesAlongPolyline::getPolyline () const +const GEOLIB::Polyline* MeshNodesAlongPolyline::getPolyline() const { return _ply; } -size_t MeshNodesAlongPolyline::getNumberOfLinearNodes () const +size_t MeshNodesAlongPolyline::getNumberOfLinearNodes() const { return _linear_nodes; } diff --git a/MSH/MeshNodesAlongPolyline.h b/MSH/MeshNodesAlongPolyline.h old mode 100755 new mode 100644 index 8461f9b41..56f9a5884 --- a/MSH/MeshNodesAlongPolyline.h +++ b/MSH/MeshNodesAlongPolyline.h @@ -30,12 +30,11 @@ class CFEMesh; class MeshNodesAlongPolyline { public: - MeshNodesAlongPolyline(GEOLIB::Polyline const* const ply, - CFEMesh const* mesh, double search_radius); - const std::vector& getNodeIDs () const; - const GEOLIB::Polyline* getPolyline () const; - size_t getNumberOfLinearNodes () const; - std::vector const & getDistOfProjNodeFromPlyStart() const; + MeshNodesAlongPolyline(GEOLIB::Polyline const* const ply, CFEMesh const* mesh, double search_radius); + const std::vector& getNodeIDs() const; + const GEOLIB::Polyline* getPolyline() const; + size_t getNumberOfLinearNodes() const; + std::vector const& getDistOfProjNodeFromPlyStart() const; private: const GEOLIB::Polyline* _ply; diff --git a/MSH/MshEditor.cpp b/MSH/MshEditor.cpp index 05fd4a1ef..bbe479225 100644 --- a/MSH/MshEditor.cpp +++ b/MSH/MshEditor.cpp @@ -13,22 +13,21 @@ #include "msh_mesh.h" #include "GridAdapter.h" - -void MshEditor::getNodeAreas(const MeshLib::CFEMesh* mesh, std::vector &node_area_vec) +void MshEditor::getNodeAreas(const MeshLib::CFEMesh* mesh, std::vector& node_area_vec) { - double total_area (0); + double total_area(0); // for each node, a vector containing all the element idget every element - const size_t nNodes ( mesh->nod_vector.size() ); - for (size_t n=0; nnod_vector.size()); + for (size_t n = 0; n < nNodes; n++) { - double node_area (0); + double node_area(0); - std::vector connected_elements (mesh->nod_vector[n]->getConnectedElementIDs()); + std::vector connected_elements(mesh->nod_vector[n]->getConnectedElementIDs()); - for (size_t i=0; iele_vector[connected_elements[i]]); + MeshLib::CElem* Element(mesh->ele_vector[connected_elements[i]]); // get nodes of this element std::vector ElementNodes; @@ -37,36 +36,38 @@ void MshEditor::getNodeAreas(const MeshLib::CFEMesh* mesh, std::vector & // get area of this Element // first, get coordinates for each node - GEOLIB::Point A (ElementNodes[0]->getData()); - GEOLIB::Point B (ElementNodes[1]->getData()); - GEOLIB::Point C (ElementNodes[2]->getData()); + GEOLIB::Point A(ElementNodes[0]->getData()); + GEOLIB::Point B(ElementNodes[1]->getData()); + GEOLIB::Point C(ElementNodes[2]->getData()); // distances of AB, BC, and AC - const double a = sqrt((A[0]-B[0])*(A[0]-B[0]) + (A[1]-B[1])*(A[1]-B[1]) + (A[2]-B[2])*(A[2]-B[2])); - const double b = sqrt((C[0]-B[0])*(C[0]-B[0]) + (C[1]-B[1])*(C[1]-B[1]) + (C[2]-B[2])*(C[2]-B[2])); - const double c2= (A[0]-C[0])*(A[0]-C[0]) + (A[1]-C[1])*(A[1]-C[1]) + (A[2]-C[2])*(A[2]-C[2]); + const double a + = sqrt((A[0] - B[0]) * (A[0] - B[0]) + (A[1] - B[1]) * (A[1] - B[1]) + (A[2] - B[2]) * (A[2] - B[2])); + const double b + = sqrt((C[0] - B[0]) * (C[0] - B[0]) + (C[1] - B[1]) * (C[1] - B[1]) + (C[2] - B[2]) * (C[2] - B[2])); + const double c2 + = (A[0] - C[0]) * (A[0] - C[0]) + (A[1] - C[1]) * (A[1] - C[1]) + (A[2] - C[2]) * (A[2] - C[2]); // angle AC-BC - const double cos_gamma = (c2-a*a-b*b)/(-2*a*b); + const double cos_gamma = (c2 - a * a - b * b) / (-2 * a * b); // Area of tri-element - const double Area = 0.5*a*b*sin(acos(cos_gamma)); + const double Area = 0.5 * a * b * sin(acos(cos_gamma)); - node_area += Area/3.0; // the third part of the area of each connected element adds up to the nodal area of n - total_area += Area/3.0; + node_area + += Area / 3.0; // the third part of the area of each connected element adds up to the nodal area of n + total_area += Area / 3.0; } node_area_vec.push_back(node_area); } - std::cout<< "Total surface Area: " << total_area << "\n"; + std::cout << "Total surface Area: " << total_area << "\n"; } - -MeshLib::CFEMesh* MshEditor::removeMeshNodes(MeshLib::CFEMesh* mesh, - const std::vector &nodes) +MeshLib::CFEMesh* MshEditor::removeMeshNodes(MeshLib::CFEMesh* mesh, const std::vector& nodes) { - MeshLib::CFEMesh* new_mesh (new MeshLib::CFEMesh(*mesh)); + MeshLib::CFEMesh* new_mesh(new MeshLib::CFEMesh(*mesh)); // delete nodes and their connected elements and replace them with null pointers size_t delNodes = nodes.size(); @@ -100,8 +101,7 @@ MeshLib::CFEMesh* MshEditor::removeMeshNodes(MeshLib::CFEMesh* mesh, } // erase null pointers from node- and element vectors - for (std::vector::iterator it = new_mesh->ele_vector.begin(); - it != new_mesh->ele_vector.end(); ) + for (std::vector::iterator it = new_mesh->ele_vector.begin(); it != new_mesh->ele_vector.end();) { if (*it) ++it; @@ -109,8 +109,7 @@ MeshLib::CFEMesh* MshEditor::removeMeshNodes(MeshLib::CFEMesh* mesh, it = new_mesh->ele_vector.erase(it); } - for (std::vector::iterator it = new_mesh->nod_vector.begin(); - it != new_mesh->nod_vector.end(); ) + for (std::vector::iterator it = new_mesh->nod_vector.begin(); it != new_mesh->nod_vector.end();) { if (*it) ++it; @@ -131,108 +130,106 @@ MeshLib::CFEMesh* MshEditor::removeMeshNodes(MeshLib::CFEMesh* mesh, return new_mesh; } -std::vector MshEditor::getSurfaceNodes(const MeshLib::CFEMesh &mesh) +std::vector MshEditor::getSurfaceNodes(const MeshLib::CFEMesh& mesh) { - std::cout << "Extracting surface nodes..." << "\n"; + std::cout << "Extracting surface nodes..." + << "\n"; // Sort points lexicographically - size_t nNodes (mesh.nod_vector.size()); + size_t nNodes(mesh.nod_vector.size()); std::vector nodes; std::vector perm; - for (size_t j(0); jgetData(), j)); perm.push_back(j); } - Quicksort (nodes, 0, nodes.size(), perm); + Quicksort(nodes, 0, nodes.size(), perm); // Extract surface points - double eps (std::numeric_limits::epsilon()); + double eps(std::numeric_limits::epsilon()); std::vector surface_pnts; for (size_t k(1); k < nNodes; k++) { - const GEOLIB::PointWithID& p0 (*(nodes[k - 1])); - const GEOLIB::PointWithID& p1 (*(nodes[k])); - if (fabs (p0[0] - p1[0]) > eps || fabs (p0[1] - p1[1]) > eps) - surface_pnts.push_back (nodes[k - 1]); + const GEOLIB::PointWithID& p0(*(nodes[k - 1])); + const GEOLIB::PointWithID& p1(*(nodes[k])); + if (fabs(p0[0] - p1[0]) > eps || fabs(p0[1] - p1[1]) > eps) + surface_pnts.push_back(nodes[k - 1]); } // Add last point - surface_pnts.push_back (nodes[nNodes - 1]); + surface_pnts.push_back(nodes[nNodes - 1]); return surface_pnts; } - -void MshEditor::sortNodesLexicographically(MeshLib::CFEMesh *mesh) +void MshEditor::sortNodesLexicographically(MeshLib::CFEMesh* mesh) { - - if(mesh->nodes_are_sorted) + if (mesh->nodes_are_sorted) return; - const std::vector &mesh_nodes(mesh->getNodeVector()); + const std::vector& mesh_nodes(mesh->getNodeVector()); - const size_t nNodes (mesh_nodes.size()); + const size_t nNodes(mesh_nodes.size()); std::vector nodes; std::vector perm; - for (size_t j(0); jgetData(), mesh_nodes[j]->GetIndex())); perm.push_back(j); } - Quicksort (nodes, 0, nodes.size(), perm); + Quicksort(nodes, 0, nodes.size(), perm); - std::vectortest; - for (size_t j(0); j test; + for (size_t j(0); j < nNodes; j++) { mesh->sorted_nodes.push_back(nodes[j]->getID()); } // get x-y-coordinate intervals - const double eps (std::numeric_limits::epsilon()); - mesh->xy_change.push_back(-1); //virtual last top node for reference to first bottom node + const double eps(std::numeric_limits::epsilon()); + mesh->xy_change.push_back(-1); // virtual last top node for reference to first bottom node for (size_t k(1); k < nNodes; k++) { - const GEOLIB::PointWithID& p0 (*(nodes[k - 1])); - const GEOLIB::PointWithID& p1 (*(nodes[k])); - if (fabs (p0[0] - p1[0]) > eps || fabs (p0[1] - p1[1]) > eps) + const GEOLIB::PointWithID& p0(*(nodes[k - 1])); + const GEOLIB::PointWithID& p1(*(nodes[k])); + if (fabs(p0[0] - p1[0]) > eps || fabs(p0[1] - p1[1]) > eps) mesh->xy_change.push_back(k - 1); } // Add last point mesh->xy_change.push_back(nNodes - 1); - mesh->nodes_are_sorted=true; + mesh->nodes_are_sorted = true; const std::size_t size(nodes.size()); - for (std::size_t j(0); j sfc_points = MshEditor::getSurfaceNodes(mesh); - const size_t nSurfacePoints (sfc_points.size()); + const size_t nSurfacePoints(sfc_points.size()); - std::vector *elements = new std::vector; + std::vector* elements = new std::vector; const size_t nElements = mesh.ele_vector.size(); - for (size_t j=0; j elem_nodes; - bool is_surface (true); - for (size_t i=0; i<4; i++) + bool is_surface(true); + for (size_t i = 0; i < 4; i++) { size_t node_index = elem->GetNodeIndex(i); bool node_found(false), one_node(true); - for (size_t k=0; kgetID() == node_index) { - node_found=true; + node_found = true; elem_nodes.push_back(k); break; } @@ -258,8 +255,8 @@ MeshLib::CFEMesh* MshEditor::getMeshSurface(const MeshLib::CFEMesh &mesh) } } - std::vector *nodes = new std::vector(nSurfacePoints); - for (size_t j=0; j* nodes = new std::vector(nSurfacePoints); + for (size_t j = 0; j < nSurfacePoints; j++) //(*nodes)[sfc_points[j]->getID()]=sfc_points[j]; (*nodes)[j] = sfc_points[j]; @@ -269,4 +266,3 @@ MeshLib::CFEMesh* MshEditor::getMeshSurface(const MeshLib::CFEMesh &mesh) MeshLib::CFEMesh* sfc_mesh = new MeshLib::CFEMesh(*surface.getCFEMesh()); return sfc_mesh; } - diff --git a/MSH/MshEditor.h b/MSH/MshEditor.h index d4a2b5568..37baacd00 100644 --- a/MSH/MshEditor.h +++ b/MSH/MshEditor.h @@ -14,8 +14,9 @@ #include #include -namespace GEOLIB { - class PointWithID; +namespace GEOLIB +{ +class PointWithID; } namespace MeshLib @@ -33,24 +34,22 @@ class MshEditor public: MshEditor() {} ~MshEditor() {} - /// Returns the area assigned to each node on a surface mesh. - static void getNodeAreas(const MeshLib::CFEMesh* mesh, std::vector &node_area_vec); + static void getNodeAreas(const MeshLib::CFEMesh* mesh, std::vector& node_area_vec); /// Removes the mesh nodes (and connected elements) given in the nodes-list from the mesh. - static MeshLib::CFEMesh* removeMeshNodes(MeshLib::CFEMesh* mesh, - const std::vector &nodes); + static MeshLib::CFEMesh* removeMeshNodes(MeshLib::CFEMesh* mesh, const std::vector& nodes); /// Returns the surface nodes of a layered mesh. - static std::vector getSurfaceNodes(const MeshLib::CFEMesh &mesh); + static std::vector getSurfaceNodes(const MeshLib::CFEMesh& mesh); /// MW: populate sort nodes vector - static void sortNodesLexicographically(MeshLib::CFEMesh *mesh); + static void sortNodesLexicographically(MeshLib::CFEMesh* mesh); /// Returns the 2d-element mesh representing the surface of the given layered mesh. - static MeshLib::CFEMesh* getMeshSurface(const MeshLib::CFEMesh &mesh); + static MeshLib::CFEMesh* getMeshSurface(const MeshLib::CFEMesh& mesh); private: }; -#endif //MSHEDITOR_H +#endif // MSHEDITOR_H diff --git a/MSH/msh_core.cpp b/MSH/msh_core.cpp index e6393e44b..36a39f027 100644 --- a/MSH/msh_core.cpp +++ b/MSH/msh_core.cpp @@ -25,7 +25,7 @@ namespace MeshLib 06/2005 WW Implementation 03/2010 TF initialization in initialization list **************************************************************************/ -CCore::CCore(size_t id) : - index (id), boundary_type ('I'), mark (true), quadratic (false) -{} -} // namespace MeshLib +CCore::CCore(size_t id) : index(id), boundary_type('I'), mark(true), quadratic(false) +{ +} +} // namespace MeshLib diff --git a/MSH/msh_core.h b/MSH/msh_core.h index c382205a4..e46ef4816 100644 --- a/MSH/msh_core.h +++ b/MSH/msh_core.h @@ -39,17 +39,10 @@ class CCore // Methods CCore(size_t id); virtual ~CCore() {} - // Get members size_t GetIndex() const { return index; } - - bool GetMark() const - { - return mark; - } - + bool GetMark() const { return mark; } bool GetOrder() const { return quadratic; } - bool Interior() const { if (boundary_type == 'I') @@ -59,43 +52,19 @@ class CCore } // Set members - void SetBoundaryType(char type) - { - boundary_type = type; - } - - char GetBoundaryType() const - { - return boundary_type; - } // 18.02.2009. WW - - void SetOrder(bool order) - { - quadratic = order; - } - - void SetMark(bool state) - { - mark = state; - } - - void SetIndex(size_t lvalue) - { - index = lvalue; - } //OK - + void SetBoundaryType(char type) { boundary_type = type; } + char GetBoundaryType() const { return boundary_type; } // 18.02.2009. WW + void SetOrder(bool order) { quadratic = order; } + void SetMark(bool state) { mark = state; } + void SetIndex(size_t lvalue) { index = lvalue; } // OK // Output - virtual void Write(std::ostream& os = std::cout) const - { - os << "\n"; - } - + virtual void Write(std::ostream& os = std::cout) const { os << "\n"; } protected: // Properties size_t index; char boundary_type; - bool mark; // e.g. marked to be refined or active - bool quadratic; // higher order + bool mark; // e.g. marked to be refined or active + bool quadratic; // higher order }; -} // namespace MeshLib +} // namespace MeshLib #endif diff --git a/MSH/msh_edge.cpp b/MSH/msh_edge.cpp index a72159056..b72115071 100644 --- a/MSH/msh_edge.cpp +++ b/MSH/msh_edge.cpp @@ -18,7 +18,7 @@ // C++ #include // MSHLib -#include "mathlib.h" //OK +#include "mathlib.h" //OK #include "msh_edge.h" //======================================================================== @@ -31,12 +31,11 @@ namespace MeshLib 06/2005 WW Implementation 03/2010 TF moved initialization of attributes to initialization list, added docu **************************************************************************/ -CEdge::CEdge(size_t Index, bool quadr) - : CCore(Index), nodes_of_edges(3), joint (0), velocity (NULL) +CEdge::CEdge(size_t Index, bool quadr) : CCore(Index), nodes_of_edges(3), joint(0), velocity(NULL) { quadratic = quadr; // Assume that each edge has three nodes, third node is middle point - for(size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; i++) nodes_of_edges[i] = NULL; } @@ -49,7 +48,7 @@ CEdge::CEdge(size_t Index, bool quadr) CEdge::~CEdge() { nodes_of_edges.resize(0); - delete [] velocity; + delete[] velocity; } /************************************************************************** MSHLib-Method: @@ -57,12 +56,12 @@ CEdge::~CEdge() Programing: 06/2005 WW Implementation **************************************************************************/ -void CEdge::operator = (CEdge& ed) +void CEdge::operator=(CEdge& ed) { boundary_type = ed.boundary_type; index = ed.index; mark = ed.mark; - for(size_t i = 0; i < nodes_of_edges.Size(); i++) + for (size_t i = 0; i < nodes_of_edges.Size(); i++) nodes_of_edges[i] = ed.nodes_of_edges[i]; } @@ -76,7 +75,7 @@ double CEdge::getLength() const { double const* const pnt0(nodes_of_edges[0]->getData()); double const* const pnt1(nodes_of_edges[1]->getData()); - double const dx (pnt1[0] - pnt0[0]), dy(pnt1[1] - pnt0[1]), dz(pnt1[2] - pnt0[2]); + double const dx(pnt1[0] - pnt0[0]), dy(pnt1[1] - pnt0[1]), dz(pnt1[2] - pnt0[2]); return sqrt(dx * dx + dy * dy + dz * dz); } @@ -86,23 +85,23 @@ double CEdge::getLength() const Programing: 06/2005 WW Implementation **************************************************************************/ -bool CEdge::operator == (CEdge& ed) +bool CEdge::operator==(CEdge& ed) { int identical; // Compare two ends identical = 0; - for(int i = 0; i < 2; i++) - if(nodes_of_edges[i] == ed.nodes_of_edges[i]) + for (int i = 0; i < 2; i++) + if (nodes_of_edges[i] == ed.nodes_of_edges[i]) identical++; - if(identical == 2) + if (identical == 2) return true; identical = 0; - for(int i = 0; i < 2; i++) - if(nodes_of_edges[1 - i] == ed.nodes_of_edges[i]) + for (int i = 0; i < 2; i++) + if (nodes_of_edges[1 - i] == ed.nodes_of_edges[i]) identical++; - if(identical == 2) + if (identical == 2) return true; return false; @@ -117,7 +116,7 @@ bool CEdge::operator == (CEdge& ed) void CEdge::Write(std::ostream& osm) const { osm << "Edge: " << index << "\n"; - for(size_t i = 0; i < nodes_of_edges.Size(); i++) + for (size_t i = 0; i < nodes_of_edges.Size(); i++) { osm << "Node: " << i << "\n"; nodes_of_edges[i]->Write(osm); @@ -129,15 +128,15 @@ void CEdge::Write(std::ostream& osm) const MSHLib-Method: 08/2006 OK Implementation **************************************************************************/ -void CEdge::SetNormalVector(double* ele_normal_vector,double* normal_vector) +void CEdge::SetNormalVector(double* ele_normal_vector, double* normal_vector) { // Element normal vector // Edge vector double edge_vector[3]; GetEdgeVector(edge_vector); // Edge normal vector - CrossProduction(edge_vector,ele_normal_vector,normal_vector); - NormalizeVector(normal_vector,3); + CrossProduction(edge_vector, ele_normal_vector, normal_vector); + NormalizeVector(normal_vector, 3); } /************************************************************************** @@ -165,4 +164,4 @@ void CEdge::GetEdgeMidPoint(double* edge_vector) edge_vector[1] = 0.5 * (pnt1[1] + pnt0[1]); edge_vector[2] = 0.5 * (pnt1[2] + pnt0[2]); } -} // namespace MeshLib +} // namespace MeshLib diff --git a/MSH/msh_edge.h b/MSH/msh_edge.h index 9cbeb7093..dbb176450 100644 --- a/MSH/msh_edge.h +++ b/MSH/msh_edge.h @@ -33,7 +33,7 @@ namespace MeshLib class CEdge : public CCore { public: - std::vector connected_elements; // PCH + std::vector connected_elements; // PCH // Methods CEdge(size_t Index, bool quadr = false); ~CEdge(); @@ -45,70 +45,53 @@ class CEdge : public CCore Nodes[i] = nodes_of_edges[i]; } - CNode* GetNode(int l_index) - { - return nodes_of_edges[l_index]; - } - + CNode* GetNode(int l_index) { return nodes_of_edges[l_index]; } double getLength() const; - int GetJoint() const - { - return joint; - } // PCH - - double GetVelocity(size_t index) - { - return velocity[index]; - } // PCH - + int GetJoint() const { return joint; } // PCH + double GetVelocity(size_t index) { return velocity[index]; } // PCH // Set functions void SetNodes(Math_Group::vec& Nodes) { for (int i = 0; i < 3; i++) nodes_of_edges[i] = Nodes[i]; } - void SetNode(int index, CNode* aNode) - { - nodes_of_edges[index] = aNode; - } - void SetJoint(int i) - { - joint = i; - } // PCH - + void SetNode(int index, CNode* aNode) { nodes_of_edges[index] = aNode; } + void SetJoint(int i) { joint = i; } // PCH void AllocateMeomoryforV() { - if (!velocity) velocity = new double[3]; + if (!velocity) + velocity = new double[3]; } void SetVelocity(double* v) { velocity[0] = v[0]; velocity[1] = v[1]; velocity[2] = v[2]; - } // PCH + } // PCH // Operator - void operator =(CEdge& edg); - bool operator ==(CEdge& edg); + void operator=(CEdge& edg); + bool operator==(CEdge& edg); // Output void Write(std::ostream& osm = std::cout) const; // - //OK + // OK void SetNormalVector(double* ele_normal_vector, double* normal_vector); - void GetEdgeVector(double* edge_vector); //OK - //OK + void GetEdgeVector(double* edge_vector); // OK + // OK void GetEdgeMidPoint(double* edge_vector); + private: /** * three mesh nodes are stored in this vector, * the third is not really a mesh node, it is the middle point */ Math_Group::vec nodes_of_edges; - int joint; // PCH - double* velocity; // PCH + int joint; // PCH + double* velocity; // PCH friend class CElem; }; -} // namespace MeshLib +} // namespace MeshLib #endif diff --git a/MSH/msh_elem.cpp b/MSH/msh_elem.cpp old mode 100755 new mode 100644 index bc288ebe9..83e0277b4 --- a/MSH/msh_elem.cpp +++ b/MSH/msh_elem.cpp @@ -17,10 +17,10 @@ #include "mathlib.h" #include -#include //WW -#include //WW +#include //WW +#include //WW // MSHLib -//WW#include "MSHEnums.h" // KR 2010/11/15 +// WW#include "MSHEnums.h" // KR 2010/11/15 #include "msh_elem.h" namespace MeshLib @@ -32,9 +32,8 @@ namespace MeshLib 06/2005 WW Implementation **************************************************************************/ CElem::CElem(size_t Index) -: CCore(Index), normal_vector(NULL), /*geo_type(t), */owner(NULL), ele_dim(1), - nnodes(0), nnodesHQ(0), nodes(nnodes), nodes_index(nnodes), - patch_index(0), transform_tensor(NULL), angle(NULL) + : CCore(Index), normal_vector(NULL), /*geo_type(t), */ owner(NULL), ele_dim(1), nnodes(0), nnodesHQ(0), + nodes(nnodes), nodes_index(nnodes), patch_index(0), transform_tensor(NULL), angle(NULL) { grid_adaptation = -1; volume = 0.0; @@ -42,14 +41,12 @@ CElem::CElem(size_t Index) no_faces_on_surface = 0; gravity_center[0] = gravity_center[1] = gravity_center[2] = 0.0; normal_vector = NULL; - area = 1.0; //WW - excavated = -1; //WX + area = 1.0; // WW + excavated = -1; // WX #if defined(USE_PETSC) // || defined(using other parallel scheme). WW - g_index = NULL; + g_index = NULL; #endif - - } /************************************************************************** MSHLib-Method: @@ -60,29 +57,28 @@ CElem::CElem(size_t Index) CElem::CElem() : CCore(0), normal_vector(NULL) { selected = 0; - //matgroup_view = 0; + // matgroup_view = 0; grid_adaptation = -1; nnodes = 0; nnodesHQ = 0; - ele_dim = 1; // Dimension of element + ele_dim = 1; // Dimension of element patch_index = 0; // volume = 0.0; face_index = -1; no_faces_on_surface = 0; owner = NULL; - nodes.resize(8); // Nodes of face + nodes.resize(8); // Nodes of face transform_tensor = NULL; angle = NULL; gravity_center[0] = gravity_center[1] = gravity_center[2] = 0.0; - area = 1.0; //WW area = 1.0 + area = 1.0; // WW area = 1.0 normal_vector = NULL; - excavated = -1; //WX + excavated = -1; // WX #if defined(USE_PETSC) // || defined(using other parallel scheme). WW - g_index = NULL; + g_index = NULL; #endif - } /************************************************************************** @@ -91,8 +87,7 @@ CElem::CElem() : CCore(0), normal_vector(NULL) Programing: 06/2005 WW Implementation **************************************************************************/ -CElem::CElem(size_t Index, CElem* onwer, int Face) : - CCore(Index), normal_vector(NULL), owner(onwer) +CElem::CElem(size_t Index, CElem* onwer, int Face) : CCore(Index), normal_vector(NULL), owner(onwer) { int i, j, k, n, ne; int faceIndex_loc[10]; @@ -104,52 +99,52 @@ CElem::CElem(size_t Index, CElem* onwer, int Face) : transform_tensor = NULL; angle = NULL; normal_vector = NULL; - excavated = -1; //WX + excavated = -1; // WX // - switch(owner->geo_type) + switch (owner->geo_type) { - //case MshElemType::LINE: // 1-D bar element //KR need not be processed - case MshElemType::QUAD: // 2-D quadrilateral element - this->setElementProperties(MshElemType::LINE, true); - break; - case MshElemType::HEXAHEDRON: // 3-D hexahedral element - this->setElementProperties(MshElemType::QUAD, true); - break; - case MshElemType::TRIANGLE: // 2-D triagular element - this->setElementProperties(MshElemType::LINE, true); - break; - case MshElemType::TETRAHEDRON: // 3-D tetrahedral element - this->setElementProperties(MshElemType::TRIANGLE, true); - break; - case MshElemType::PRISM: // 3-D prismatic element - if (Face < 2) // top or bottom face of the prism - this->setElementProperties(MshElemType::TRIANGLE, true); - else // side of the prism - this->setElementProperties(MshElemType::QUAD, true); - break; - case MshElemType::PYRAMID: // 3-D pyramid element - if (Face < 1) // bottom face + // case MshElemType::LINE: // 1-D bar element //KR need not be processed + case MshElemType::QUAD: // 2-D quadrilateral element + this->setElementProperties(MshElemType::LINE, true); + break; + case MshElemType::HEXAHEDRON: // 3-D hexahedral element this->setElementProperties(MshElemType::QUAD, true); - else // side faces + break; + case MshElemType::TRIANGLE: // 2-D triagular element + this->setElementProperties(MshElemType::LINE, true); + break; + case MshElemType::TETRAHEDRON: // 3-D tetrahedral element this->setElementProperties(MshElemType::TRIANGLE, true); - break; - default: - std::cerr << "CElem::CElem MshElemType not handled" << "\n"; + break; + case MshElemType::PRISM: // 3-D prismatic element + if (Face < 2) // top or bottom face of the prism + this->setElementProperties(MshElemType::TRIANGLE, true); + else // side of the prism + this->setElementProperties(MshElemType::QUAD, true); + break; + case MshElemType::PYRAMID: // 3-D pyramid element + if (Face < 1) // bottom face + this->setElementProperties(MshElemType::QUAD, true); + else // side faces + this->setElementProperties(MshElemType::TRIANGLE, true); + break; + default: + std::cerr << "CElem::CElem MshElemType not handled" + << "\n"; } - patch_index = owner->patch_index; + patch_index = owner->patch_index; quadratic = owner->quadratic; nodes_index.resize(n); nodes.resize(n); boundary_type = 'B'; - for(i = 0; i < n; i++) + for (i = 0; i < n; i++) { - nodes_index[i] = - owner->nodes_index[faceIndex_loc[i]]; + nodes_index[i] = owner->nodes_index[faceIndex_loc[i]]; nodes[i] = owner->nodes[faceIndex_loc[i]]; - //18.02.2009. cf. changes in mapping & generation. WW - if((nodes[i]->GetBoundaryType() != '0') && (nodes[i]->GetBoundaryType() != '1')) + // 18.02.2009. cf. changes in mapping & generation. WW + if ((nodes[i]->GetBoundaryType() != '0') && (nodes[i]->GetBoundaryType() != '1')) nodes[i]->SetBoundaryType('B'); } // Face edges @@ -157,20 +152,17 @@ CElem::CElem(size_t Index, CElem* onwer, int Face) : edges.resize(nnodes); edges_orientation.resize(nnodes); edges_orientation = 1; - for(i = 0; i < nnodes; i++) + for (i = 0; i < nnodes; i++) { k = (i + 1) % nnodes; - for(j = 0; j < ne; j++) + for (j = 0; j < ne; j++) { owner->GetLocalIndicesOfEdgeNodes(j, edgeIndex_loc); - if( (faceIndex_loc[i] == edgeIndex_loc[0] && - faceIndex_loc[k] == edgeIndex_loc[1]) || - (faceIndex_loc[i] == edgeIndex_loc[1] && - faceIndex_loc[k] == edgeIndex_loc[0]) ) + if ((faceIndex_loc[i] == edgeIndex_loc[0] && faceIndex_loc[k] == edgeIndex_loc[1]) + || (faceIndex_loc[i] == edgeIndex_loc[1] && faceIndex_loc[k] == edgeIndex_loc[0])) { edges[i] = owner->edges[j]; - if(faceIndex_loc[i] == edgeIndex_loc[1] && - faceIndex_loc[k] == edgeIndex_loc[0] ) + if (faceIndex_loc[i] == edgeIndex_loc[1] && faceIndex_loc[k] == edgeIndex_loc[0]) edges_orientation[i] = -1; edges[i]->boundary_type = 'B'; break; @@ -179,10 +171,8 @@ CElem::CElem(size_t Index, CElem* onwer, int Face) : } #if defined(USE_PETSC) // || defined(using other parallel scheme). WW - g_index = NULL; + g_index = NULL; #endif - - } /************************************************************************** @@ -191,8 +181,7 @@ CElem::CElem(size_t Index, CElem* onwer, int Face) : Programing: 06/2005 WW/OK Implementation **************************************************************************/ -CElem::CElem(size_t Index, CElem* m_ele_parent) : - CCore(Index), normal_vector(NULL) +CElem::CElem(size_t Index, CElem* m_ele_parent) : CCore(Index), normal_vector(NULL) { // static int faceIndex_loc[10]; // static int edgeIndex_loc[10]; @@ -201,57 +190,40 @@ CElem::CElem(size_t Index, CElem* m_ele_parent) : angle = NULL; this->setElementProperties(m_ele_parent->geo_type); - patch_index = m_ele_parent->patch_index; + patch_index = m_ele_parent->patch_index; quadratic = m_ele_parent->quadratic; boundary_type = 'I'; // Initialize topological properties neighbors.resize(nfaces); - for(size_t i = 0; i < nfaces; i++) + for (size_t i = 0; i < nfaces; i++) neighbors[i] = NULL; edges.resize(nedges); edges_orientation.resize(nedges); - for(size_t i = 0; i < nedges; i++) + for (size_t i = 0; i < nedges; i++) { edges[i] = NULL; edges_orientation[i] = 1; } - area = 1.0; //WW + area = 1.0; // WW - excavated = -1; //12.08.2011. WW + excavated = -1; // 12.08.2011. WW #if defined(USE_PETSC) // || defined(using other parallel scheme). WW - g_index = NULL; + g_index = NULL; #endif } -CElem::CElem(CElem const &elem) : - CCore(elem.GetIndex()), - mat_vector (elem.mat_vector), - //matgroup_view (elem.matgroup_view), - selected (elem.selected), - normal_vector(new double[3]), - representative_length (elem.representative_length), - courant (elem.courant), - neumann (elem.neumann), - geo_type (elem.geo_type), - owner (elem.owner), - ele_dim (elem.ele_dim), - nnodes (elem.nnodes), - nnodesHQ (elem.nnodesHQ), - nodes (elem.nodes), - nedges (elem.nedges), - edges (elem.edges), - edges_orientation (elem.edges_orientation), - nfaces (elem.nfaces), - no_faces_on_surface (elem.no_faces_on_surface), - face_index (elem.face_index), - volume (elem.volume), - grid_adaptation (elem.grid_adaptation), - patch_index (elem.patch_index), - area (elem.area), - angle (new double(*(elem.angle))) +CElem::CElem(CElem const& elem) + : CCore(elem.GetIndex()), mat_vector(elem.mat_vector), + // matgroup_view (elem.matgroup_view), + selected(elem.selected), normal_vector(new double[3]), representative_length(elem.representative_length), + courant(elem.courant), neumann(elem.neumann), geo_type(elem.geo_type), owner(elem.owner), ele_dim(elem.ele_dim), + nnodes(elem.nnodes), nnodesHQ(elem.nnodesHQ), nodes(elem.nodes), nedges(elem.nedges), edges(elem.edges), + edges_orientation(elem.edges_orientation), nfaces(elem.nfaces), no_faces_on_surface(elem.no_faces_on_surface), + face_index(elem.face_index), volume(elem.volume), grid_adaptation(elem.grid_adaptation), + patch_index(elem.patch_index), area(elem.area), angle(new double(*(elem.angle))) { for (size_t k(0); k < 3; k++) { @@ -260,60 +232,56 @@ CElem::CElem(CElem const &elem) : } // copy nodes - nodes.resize ((int)((elem.nodes).Size())); + nodes.resize((int)((elem.nodes).Size())); for (size_t k(0); k < (elem.nodes).Size(); k++) - nodes[k] = new CNode ((elem.nodes[k])->GetIndex(), (elem.nodes[k])->getData()); + nodes[k] = new CNode((elem.nodes[k])->GetIndex(), (elem.nodes[k])->getData()); - // copy edges +// copy edges // edges = vec ((elem.edges).Size()); // for (size_t k(0); k<(elem.edges).Size() ; k++) { -// edges[k] = new CNode ((elem.nodes[k])->GetIndex(), (elem.nodes[k])->X(), (elem.nodes[k])->Y(), (elem.nodes[k])->Z()); +// edges[k] = new CNode ((elem.nodes[k])->GetIndex(), (elem.nodes[k])->X(), (elem.nodes[k])->Y(), +//(elem.nodes[k])->Z()); // } - //*angle = *(elem.angle); - // copy transform tensor +//*angle = *(elem.angle); +// copy transform tensor // Matrix * transform_tensor; - // copy neighbors +// copy neighbors // vec neighbors; #if defined(USE_PETSC) // || defined(using other parallel scheme). WW - g_index = elem.g_index; + g_index = elem.g_index; #endif - } - -CElem::CElem (MshElemType::type t, size_t node0, size_t node1, size_t node2, int mat) : - CCore(0), normal_vector(NULL), geo_type(t), owner(NULL), ele_dim(2), - nnodes(3), nnodesHQ(6), nodes(nnodes), nodes_index(nnodes), - nedges(3), edges(nedges), edges_orientation(nedges), - nfaces(3), patch_index(mat), transform_tensor(NULL), neighbors(nfaces), angle(NULL) +CElem::CElem(MshElemType::type t, size_t node0, size_t node1, size_t node2, int mat) + : CCore(0), normal_vector(NULL), geo_type(t), owner(NULL), ele_dim(2), nnodes(3), nnodesHQ(6), nodes(nnodes), + nodes_index(nnodes), nedges(3), edges(nedges), edges_orientation(nedges), nfaces(3), patch_index(mat), + transform_tensor(NULL), neighbors(nfaces), angle(NULL) { nodes_index[0] = node0; nodes_index[1] = node1; nodes_index[2] = node2; // Initialize topological properties - for(size_t i = 0; i < nfaces; i++) + for (size_t i = 0; i < nfaces; i++) neighbors[i] = NULL; - for(size_t i = 0; i < nedges; i++) + for (size_t i = 0; i < nedges; i++) { edges[i] = NULL; edges_orientation[i] = 1; } #if defined(USE_PETSC) // || defined(using other parallel scheme). WW - g_index = NULL; + g_index = NULL; #endif - } -CElem::CElem (MshElemType::type t, size_t node0, size_t node1, size_t node2, size_t node3, int mat) : - CCore(0), normal_vector(NULL), geo_type(t), owner(NULL), ele_dim(2), - nnodes(4), nnodesHQ(9), nodes(nnodes), nodes_index(nnodes), - nedges(4), edges(nedges), edges_orientation(nedges), - nfaces(4), patch_index(mat), transform_tensor(NULL), neighbors(nfaces), angle(NULL) +CElem::CElem(MshElemType::type t, size_t node0, size_t node1, size_t node2, size_t node3, int mat) + : CCore(0), normal_vector(NULL), geo_type(t), owner(NULL), ele_dim(2), nnodes(4), nnodesHQ(9), nodes(nnodes), + nodes_index(nnodes), nedges(4), edges(nedges), edges_orientation(nedges), nfaces(4), patch_index(mat), + transform_tensor(NULL), neighbors(nfaces), angle(NULL) { nodes_index[0] = node0; nodes_index[1] = node1; @@ -321,17 +289,16 @@ CElem::CElem (MshElemType::type t, size_t node0, size_t node1, size_t node2, siz nodes_index[3] = node3; // Initialize topological properties - for(size_t i = 0; i < nfaces; i++) + for (size_t i = 0; i < nfaces; i++) neighbors[i] = NULL; - for(size_t i = 0; i < nedges; i++) + for (size_t i = 0; i < nedges; i++) { edges[i] = NULL; edges_orientation[i] = 1; } #if defined(USE_PETSC) // || defined(using other parallel scheme). WW - g_index = NULL; + g_index = NULL; #endif - } /************************************************************************** @@ -351,24 +318,23 @@ CElem::~CElem() mat_vector.resize(0); edges_orientation.resize(0); owner = NULL; - if(transform_tensor) + if (transform_tensor) delete transform_tensor; transform_tensor = NULL; - if(angle) - delete [] angle; + if (angle) + delete[] angle; angle = NULL; transform_tensor = NULL; if (normal_vector) - delete [] normal_vector; + delete[] normal_vector; normal_vector = NULL; - delete [] angle; + delete[] angle; #if defined(USE_PETSC) // || defined(using other parallel scheme). WW - if(g_index) - delete [] g_index; - g_index = NULL; + if (g_index) + delete[] g_index; + g_index = NULL; #endif - } /************************************************************************** MSHLib-Method: @@ -378,13 +344,13 @@ CElem::~CElem() **************************************************************************/ void CElem::FillTransformMatrix() { - if(transform_tensor) + if (transform_tensor) return; double xx[3]; double yy[3]; double zz[3]; - transform_tensor = new Math_Group::Matrix(3,3); + transform_tensor = new Math_Group::Matrix(3, 3); if (geo_type == MshElemType::LINE) { // x"_vec @@ -397,7 +363,7 @@ void CElem::FillTransformMatrix() // an arbitrary vector for (size_t i = 0; i < 3; i++) yy[i] = 0.0; - //WW. 06.11.2007 + // WW. 06.11.2007 if (fabs(xx[0]) > 0.0 && fabs(xx[1]) + fabs(xx[2]) < DBL_MIN) yy[2] = 1.0; else if (fabs(xx[1]) > 0.0 && fabs(xx[0]) + fabs(xx[2]) < DBL_MIN) @@ -423,9 +389,9 @@ void CElem::FillTransformMatrix() else if (geo_type == MshElemType::QUAD || geo_type == MshElemType::TRIANGLE) { // x"_vec -// xx[0] = nodes[1]->X() - nodes[0]->X(); -// xx[1] = nodes[1]->Y() - nodes[0]->Y(); -// xx[2] = nodes[1]->Z() - nodes[0]->Z(); + // xx[0] = nodes[1]->X() - nodes[0]->X(); + // xx[1] = nodes[1]->Y() - nodes[0]->Y(); + // xx[2] = nodes[1]->Z() - nodes[0]->Z(); double const* const pnt0(nodes[0]->getData()); double const* const pnt1(nodes[1]->getData()); xx[0] = pnt1[0] - pnt0[0]; @@ -433,9 +399,9 @@ void CElem::FillTransformMatrix() xx[2] = pnt1[2] - pnt0[2]; NormalizeVector(xx, 3); // a vector on the plane -// yy[0] = nodes[2]->X() - nodes[1]->X(); -// yy[1] = nodes[2]->Y() - nodes[1]->Y(); -// yy[2] = nodes[2]->Z() - nodes[1]->Z(); + // yy[0] = nodes[2]->X() - nodes[1]->X(); + // yy[1] = nodes[2]->Y() - nodes[1]->Y(); + // yy[2] = nodes[2]->Z() - nodes[1]->Z(); double const* const pnt2(nodes[2]->getData()); yy[0] = pnt2[0] - pnt1[0]; yy[1] = pnt2[1] - pnt1[1]; @@ -462,11 +428,11 @@ void CElem::FillTransformMatrix() **************************************************************************/ double CElem::getTransformTensor(int idx) { - //WW + // WW int i = idx % 3; int j = idx / 3; - return (*transform_tensor)(i,j); - //return MatT[idx]; + return (*transform_tensor)(i, j); + // return MatT[idx]; } /************************************************************************** @@ -487,43 +453,44 @@ void CElem::SetFace() Programing: 06/2005 WW Implementation **************************************************************************/ -void CElem:: SetFace(CElem* onwer, const int Face) +void CElem::SetFace(CElem* onwer, const int Face) { static int nodeIndex_loc[8]; no_faces_on_surface = 0; owner = onwer; size_t n = owner->GetElementFaceNodes(Face, nodeIndex_loc); face_index = Face; - switch(owner->geo_type) + switch (owner->geo_type) { - //case MshElemType::LINE: // 1-D bar element - case MshElemType::QUAD: // 2-D quadrilateral element - this->setElementProperties(MshElemType::LINE, true); // JOD 2014-11-10 - break; - case MshElemType::HEXAHEDRON: // 3-D hexahedral element - this->setElementProperties(MshElemType::QUAD, true); - break; - //case MshElemType::TRIANGLE: // 2-D triagular element - case MshElemType::TETRAHEDRON: // 3-D tetrahedral element - this->setElementProperties(MshElemType::TRIANGLE, true); - break; - case MshElemType::PRISM: - if(Face < 2) - this->setElementProperties(MshElemType::TRIANGLE, true); - else - this->setElementProperties(MshElemType::QUAD, true); - break; // 3-D prismatic element - case MshElemType::PYRAMID: - if(Face < 1) + // case MshElemType::LINE: // 1-D bar element + case MshElemType::QUAD: // 2-D quadrilateral element + this->setElementProperties(MshElemType::LINE, true); // JOD 2014-11-10 + break; + case MshElemType::HEXAHEDRON: // 3-D hexahedral element this->setElementProperties(MshElemType::QUAD, true); - else + break; + // case MshElemType::TRIANGLE: // 2-D triagular element + case MshElemType::TETRAHEDRON: // 3-D tetrahedral element this->setElementProperties(MshElemType::TRIANGLE, true); - break; // 3-D pyramid element - default: - std::cerr << "CElem::SetFace MshElemType not handled" << "\n"; + break; + case MshElemType::PRISM: + if (Face < 2) + this->setElementProperties(MshElemType::TRIANGLE, true); + else + this->setElementProperties(MshElemType::QUAD, true); + break; // 3-D prismatic element + case MshElemType::PYRAMID: + if (Face < 1) + this->setElementProperties(MshElemType::QUAD, true); + else + this->setElementProperties(MshElemType::TRIANGLE, true); + break; // 3-D pyramid element + default: + std::cerr << "CElem::SetFace MshElemType not handled" + << "\n"; } - for(size_t i = 0; i < n; i++) + for (size_t i = 0; i < n; i++) nodes[i] = owner->nodes[nodeIndex_loc[i]]; } /************************************************************************** @@ -547,139 +514,139 @@ std::string CElem::GetName() const **************************************************************************/ void CElem::Read(std::istream& is, int fileType) { - //fileType=0: msh - //fileType=1: rfi - //fileType=2: gmsh - //fileType=3: GMS - //fileType=4: SOL - //fileType=5: FLAC 3D. WW - //fileType=5x: FLAC3D //MR - //fileType=6: FEFLOW //OK - //fileType=7: GMSH 2008 Version//TK + // fileType=0: msh + // fileType=1: rfi + // fileType=2: gmsh + // fileType=3: GMS + // fileType=4: SOL + // fileType=5: FLAC 3D. WW + // fileType=5x: FLAC3D //MR + // fileType=6: FEFLOW //OK + // fileType=7: GMSH 2008 Version//TK int idummy(-1), et(-1); std::string name(""); - int gmsh_patch_index; //TKOK + int gmsh_patch_index; // TKOK // is.ignore(numeric_limits::max(), '\n'); //---------------------------------------------------------------------- // 1 Reading element type data switch (fileType) { - //.................................................................... - case 0: // msh - { - std::string buffer(""); - is >> index >> patch_index; - is >> buffer; - - if (buffer.find("-1") != std::string::npos) + //.................................................................... + case 0: // msh { - grid_adaptation = strtol(buffer.data(), NULL, 0); - is >> name; - } - else - name = buffer; + std::string buffer(""); + is >> index >> patch_index; + is >> buffer; - geo_type = String2MshElemType(name); - break; - } - //.................................................................... - case 1: // rfi - is >> index >> patch_index >> name; - geo_type = String2MshElemType(name); - break; - //.................................................................... - case 2: // gmsh - is >> index >> et >> gmsh_patch_index >> idummy >> nnodes; - patch_index = gmsh_patch_index - 1; //OK - switch (et) - { - case 1: - geo_type = MshElemType::LINE; - break; - case 2: - geo_type = MshElemType::TRIANGLE; - break; - case 3: - geo_type = MshElemType::QUAD; - break; - case 4: - geo_type = MshElemType::TETRAHEDRON; - break; - case 5: - geo_type = MshElemType::HEXAHEDRON; + if (buffer.find("-1") != std::string::npos) + { + grid_adaptation = strtol(buffer.data(), NULL, 0); + is >> name; + } + else + name = buffer; + + geo_type = String2MshElemType(name); break; - case 6: - geo_type = MshElemType::PRISM; + } + //.................................................................... + case 1: // rfi + is >> index >> patch_index >> name; + geo_type = String2MshElemType(name); break; - case 7: - geo_type = MshElemType::PYRAMID; + //.................................................................... + case 2: // gmsh + is >> index >> et >> gmsh_patch_index >> idummy >> nnodes; + patch_index = gmsh_patch_index - 1; // OK + switch (et) + { + case 1: + geo_type = MshElemType::LINE; + break; + case 2: + geo_type = MshElemType::TRIANGLE; + break; + case 3: + geo_type = MshElemType::QUAD; + break; + case 4: + geo_type = MshElemType::TETRAHEDRON; + break; + case 5: + geo_type = MshElemType::HEXAHEDRON; + break; + case 6: + geo_type = MshElemType::PRISM; + break; + case 7: + geo_type = MshElemType::PYRAMID; + break; + } + index--; break; - } - index--; - break; - case 7: // GMSH 2008 - size_t nb_tags; - - is >> index >> et >> nb_tags >> idummy >> gmsh_patch_index; - patch_index = gmsh_patch_index; - for (size_t j = 2; j < nb_tags; j++) - is >> idummy; - switch (et) - { - case 1: - geo_type = MshElemType::LINE; - patch_index = 0; // KR: can line elements have material ids? - nnodes = 2; + case 7: // GMSH 2008 + size_t nb_tags; + + is >> index >> et >> nb_tags >> idummy >> gmsh_patch_index; + patch_index = gmsh_patch_index; + for (size_t j = 2; j < nb_tags; j++) + is >> idummy; + switch (et) + { + case 1: + geo_type = MshElemType::LINE; + patch_index = 0; // KR: can line elements have material ids? + nnodes = 2; + break; + case 2: + geo_type = MshElemType::TRIANGLE; + nnodes = 3; + break; + case 3: + geo_type = MshElemType::QUAD; + nnodes = 4; + break; + case 4: + geo_type = MshElemType::TETRAHEDRON; + nnodes = 4; + break; + case 5: + geo_type = MshElemType::HEXAHEDRON; + nnodes = 8; + break; + case 6: + geo_type = MshElemType::PRISM; + nnodes = 6; + break; + case 7: + geo_type = MshElemType::PYRAMID; + break; + case 15: + geo_type = MshElemType::INVALID; + nnodes = 1; + break; + default: + geo_type = MshElemType::INVALID; + } + index--; break; - case 2: + //.................................................................... + case 3: // GMS geo_type = MshElemType::TRIANGLE; - nnodes = 3; - break; - case 3: - geo_type = MshElemType::QUAD; - nnodes = 4; break; - case 4: - geo_type = MshElemType::TETRAHEDRON; - nnodes = 4; + //.................................................................... + case 4: // gmsh + geo_type = MshElemType::TRIANGLE; break; - case 5: + //.................................................................... + case 5: // FLAC 3D. 14.01.2008 WW geo_type = MshElemType::HEXAHEDRON; - nnodes = 8; - break; - case 6: - geo_type = MshElemType::PRISM; - nnodes = 6; - break; - case 7: - geo_type = MshElemType::PYRAMID; break; - case 15: - geo_type = MshElemType::INVALID; - nnodes = 1; - break; - default: - geo_type = MshElemType::INVALID; - } - index--; - break; - //.................................................................... - case 3: // GMS - geo_type = MshElemType::TRIANGLE; - break; - //.................................................................... - case 4: // gmsh - geo_type = MshElemType::TRIANGLE; - break; - //.................................................................... - case 5: // FLAC 3D. 14.01.2008 WW - geo_type = MshElemType::HEXAHEDRON; - break; - case 56: // FLAC3D - pri (Wedge) //MR - geo_type = MshElemType::PRISM; //MR - fileType = 5; //MR - break; //MR + case 56: // FLAC3D - pri (Wedge) //MR + geo_type = MshElemType::PRISM; // MR + fileType = 5; // MR + break; // MR } // TF @@ -699,74 +666,74 @@ void CElem::Read(std::istream& is, int fileType) // 3 Reading element node data switch (fileType) { - case 0: // msh - for (int i = 0; i < nnodes; i++) - is >> nodes_index[i]; - break; - case 1: // rfi - for (int i = 0; i < nnodes; i++) - is >> nodes_index[i]; - break; - case 2: // gmsh - for (int i = 0; i < nnodes; i++) - { - is >> nodes_index[i]; - nodes_index[i] -= 1; - } - break; - case 7: // GMSH 2008 - if (et != 15) + case 0: // msh + for (int i = 0; i < nnodes; i++) + is >> nodes_index[i]; + break; + case 1: // rfi + for (int i = 0; i < nnodes; i++) + is >> nodes_index[i]; + break; + case 2: // gmsh for (int i = 0; i < nnodes; i++) { is >> nodes_index[i]; nodes_index[i] -= 1; } - else - { - // eat rest of line - std::string dummy; - is >> dummy; - } - break; - case 3: // GMS - for (int i = 0; i < nnodes; i++) - { - is >> nodes_index[i]; - nodes_index[i] -= 1; - } - break; - case 4: // SOL - for (int i = 0; i < nnodes; i++) - { - is >> nodes_index[i]; - nodes_index[i] -= 1; - } - is >> patch_index; - break; - case 5: // FLAC 3D. 14.01.2008. WW - for (int i = 0; i < nnodes; i++) - { - is >> nodes_index[i]; - nodes_index[i] -= 1; - } - break; - case 6: // FEFLOLW - for (int i = 0; i < nnodes; i++) - { - is >> nodes_index[i]; - nodes_index[i] -= 1; - } - break; - case 8: // GMS_3DM - is >> idummy; - for (int i = 0; i < nnodes; i++) - { - is >> nodes_index[i]; - nodes_index[i] -= 1; - } - is >> patch_index; - patch_index -= 1; - break; + break; + case 7: // GMSH 2008 + if (et != 15) + for (int i = 0; i < nnodes; i++) + { + is >> nodes_index[i]; + nodes_index[i] -= 1; + } + else + { + // eat rest of line + std::string dummy; + is >> dummy; + } + break; + case 3: // GMS + for (int i = 0; i < nnodes; i++) + { + is >> nodes_index[i]; + nodes_index[i] -= 1; + } + break; + case 4: // SOL + for (int i = 0; i < nnodes; i++) + { + is >> nodes_index[i]; + nodes_index[i] -= 1; + } + is >> patch_index; + break; + case 5: // FLAC 3D. 14.01.2008. WW + for (int i = 0; i < nnodes; i++) + { + is >> nodes_index[i]; + nodes_index[i] -= 1; + } + break; + case 6: // FEFLOLW + for (int i = 0; i < nnodes; i++) + { + is >> nodes_index[i]; + nodes_index[i] -= 1; + } + break; + case 8: // GMS_3DM + is >> idummy; + for (int i = 0; i < nnodes; i++) + { + is >> nodes_index[i]; + nodes_index[i] -= 1; + } + is >> patch_index; + patch_index -= 1; + break; } is >> std::ws; //---------------------------------------------------------------------- @@ -787,11 +754,11 @@ void CElem::InitializeMembers() { // Initialize topological properties neighbors.resize(nfaces); - for(size_t i = 0; i < nfaces; i++) + for (size_t i = 0; i < nfaces; i++) neighbors[i] = NULL; edges.resize(nedges); edges_orientation.resize(nedges); - for(size_t i = 0; i < nedges; i++) + for (size_t i = 0; i < nedges; i++) { edges[i] = NULL; edges_orientation[i] = 1; @@ -804,11 +771,11 @@ void CElem::InitializeMembers() Programing: 06/2005 WW Implementation **************************************************************************/ -void CElem::WriteIndex(std::ostream &os) const +void CElem::WriteIndex(std::ostream& os) const { - //Comment for GUI WW if(quadratic) nn = nnodesHQ; + // Comment for GUI WW if(quadratic) nn = nnodesHQ; os << index << " " << patch_index << " " << GetName() << " "; - for(int i = 0; i < nnodes - 1; i++) + for (int i = 0; i < nnodes - 1; i++) os << nodes_index[i] << " "; os << nodes_index[nnodes - 1] << "\n"; } @@ -819,31 +786,29 @@ void CElem::WriteIndex(std::ostream &os) const Programing: 06/2005 WW Implementation **************************************************************************/ -void CElem::WriteIndex_TEC(std::ostream &os) const +void CElem::WriteIndex_TEC(std::ostream& os) const { std::string deli = " "; - if(geo_type == MshElemType::LINE) - os << nodes_index[0] + 1 << deli << nodes_index[1] + 1 << deli << nodes_index[1] + - 1 << deli << nodes_index[0] + 1; - - else if(geo_type == MshElemType::TRIANGLE) - os << nodes_index[0] + 1 << deli << nodes_index[1] + 1 << deli << nodes_index[2] + - 1 << deli << nodes_index[0] + 1; - else if(geo_type == MshElemType::PRISM) - os << nodes_index[0] + 1 << deli << nodes_index[0] + 1 << deli << nodes_index[1] + - 1 << deli << nodes_index[2] + 1 << deli - << nodes_index[3] + 1 << deli << nodes_index[3] + 1 << deli << nodes_index[4] + - 1 << deli << nodes_index[5] + 1 << deli; - else if(geo_type == MshElemType::PYRAMID) - os << nodes_index[0] + 1 << deli << nodes_index[1] + 1 << deli << nodes_index[2] + - 1 << deli << nodes_index[3] + 1 << deli - << nodes_index[4] + 1 << deli << nodes_index[4] + 1 << deli << nodes_index[4] + - 1 << deli << nodes_index[4] + 1 << deli; + if (geo_type == MshElemType::LINE) + os << nodes_index[0] + 1 << deli << nodes_index[1] + 1 << deli << nodes_index[1] + 1 << deli + << nodes_index[0] + 1; + + else if (geo_type == MshElemType::TRIANGLE) + os << nodes_index[0] + 1 << deli << nodes_index[1] + 1 << deli << nodes_index[2] + 1 << deli + << nodes_index[0] + 1; + else if (geo_type == MshElemType::PRISM) + os << nodes_index[0] + 1 << deli << nodes_index[0] + 1 << deli << nodes_index[1] + 1 << deli + << nodes_index[2] + 1 << deli << nodes_index[3] + 1 << deli << nodes_index[3] + 1 << deli + << nodes_index[4] + 1 << deli << nodes_index[5] + 1 << deli; + else if (geo_type == MshElemType::PYRAMID) + os << nodes_index[0] + 1 << deli << nodes_index[1] + 1 << deli << nodes_index[2] + 1 << deli + << nodes_index[3] + 1 << deli << nodes_index[4] + 1 << deli << nodes_index[4] + 1 << deli + << nodes_index[4] + 1 << deli << nodes_index[4] + 1 << deli; else - for(int i = 0; i < nnodes; i++) + for (int i = 0; i < nnodes; i++) os << nodes_index[i] + 1 << deli; - os << '\n'; // GK44 for io performance do not flush buffer with endl... + os << '\n'; // GK44 for io performance do not flush buffer with endl... } /************************************************************************** MSHLib-Method: @@ -851,16 +816,16 @@ void CElem::WriteIndex_TEC(std::ostream &os) const Programing: 06/2005 WW Implementation **************************************************************************/ -void CElem::WriteAll(std::ostream &os) const +void CElem::WriteAll(std::ostream& os) const { std::string deli = " "; os << index << deli << patch_index << deli << GetName() << deli; - os << "Index X Y Z: " << "\n"; + os << "Index X Y Z: " + << "\n"; for (size_t i = 0; i < nodes.Size(); i++) { double const* const pnt_i(nodes[i]->getData()); - os << nodes_index[i] << deli << pnt_i[0] << deli << pnt_i[1] - << deli << pnt_i[2] << "\n"; + os << nodes_index[i] << deli << pnt_i[0] << deli << pnt_i[1] << deli << pnt_i[2] << "\n"; } } @@ -870,12 +835,13 @@ void CElem::WriteAll(std::ostream &os) const Programing: 06/2005 WW Implementation **************************************************************************/ -void CElem::WriteNeighbors(std::ostream &os) const +void CElem::WriteNeighbors(std::ostream& os) const { os << "Neighbors of " << index << "\n"; - for(size_t i = 0; i < nfaces; i++) + for (size_t i = 0; i < nfaces; i++) neighbors[i]->WriteAll(os); - os << "End neighbors of " << index << "\n" << "\n"; + os << "End neighbors of " << index << "\n" + << "\n"; } /************************************************************************** @@ -884,11 +850,11 @@ void CElem::WriteNeighbors(std::ostream &os) const Programing: 06/2005 WW Implementation **************************************************************************/ -void CElem:: MarkingAll(bool makop) +void CElem::MarkingAll(bool makop) { this->mark = makop; int SizeV = nnodes; - if(quadratic) + if (quadratic) SizeV = nnodesHQ; for (int i = 0; i < SizeV; i++) nodes[i]->SetMark(makop); @@ -903,12 +869,12 @@ void CElem:: MarkingAll(bool makop) Programing: 06/2005 WW Implementation **************************************************************************/ -void CElem::SetNodes(Math_Group::vec& ele_nodes, bool ReSize) +void CElem::SetNodes(Math_Group::vec& ele_nodes, bool ReSize) { int SizeV = nnodes; - if(quadratic) + if (quadratic) SizeV = nnodesHQ; - if(ReSize) + if (ReSize) { nodes.resize(SizeV); #if !defined(USE_PETSC) // && !defined (other parallel linear solver lib). //WW. 05.2013 @@ -947,72 +913,72 @@ void CElem::setNodes(std::vector const& ele_nodes) **************************************************************************/ void CElem::GetLocalIndicesOfEdgeNodes(const int Edge, int* EdgeNodes) { - switch(geo_type) + switch (geo_type) { - case MshElemType::LINE: - EdgeNodes[0] = 0; - EdgeNodes[1] = 1; - break; // 1-D bar element - case MshElemType::QUAD: // 2-D quadrilateral element - EdgeNodes[0] = Edge; - EdgeNodes[1] = (Edge + 1) % 4; - break; - case MshElemType::HEXAHEDRON: // 3-D hexahedral element - if(Edge < 8) - { + case MshElemType::LINE: + EdgeNodes[0] = 0; + EdgeNodes[1] = 1; + break; // 1-D bar element + case MshElemType::QUAD: // 2-D quadrilateral element EdgeNodes[0] = Edge; - EdgeNodes[1] = (Edge + 1) % 4 + 4 * (int)(Edge / 4); - } - else - { - EdgeNodes[0] = Edge % 4; - EdgeNodes[1] = Edge % 4 + 4; - } - break; - case MshElemType::TRIANGLE: // 2-D triagular element - EdgeNodes[0] = Edge; - EdgeNodes[1] = (Edge + 1) % 3; - break; - case MshElemType::TETRAHEDRON: // 3-D tetrahedra - if(Edge < 3) - { + EdgeNodes[1] = (Edge + 1) % 4; + break; + case MshElemType::HEXAHEDRON: // 3-D hexahedral element + if (Edge < 8) + { + EdgeNodes[0] = Edge; + EdgeNodes[1] = (Edge + 1) % 4 + 4 * (int)(Edge / 4); + } + else + { + EdgeNodes[0] = Edge % 4; + EdgeNodes[1] = Edge % 4 + 4; + } + break; + case MshElemType::TRIANGLE: // 2-D triagular element EdgeNodes[0] = Edge; EdgeNodes[1] = (Edge + 1) % 3; - } - else - { - EdgeNodes[0] = 3; - EdgeNodes[1] = (Edge + 1) % 3; - } + break; + case MshElemType::TETRAHEDRON: // 3-D tetrahedra + if (Edge < 3) + { + EdgeNodes[0] = Edge; + EdgeNodes[1] = (Edge + 1) % 3; + } + else + { + EdgeNodes[0] = 3; + EdgeNodes[1] = (Edge + 1) % 3; + } - break; - case MshElemType::PRISM: // 3-D prismatic element - if(Edge < 6) - { - EdgeNodes[0] = Edge; - EdgeNodes[1] = (Edge + 1) % 3 + 3 * (int)(Edge / 3); - } - else - { - EdgeNodes[0] = Edge % 3; - EdgeNodes[1] = Edge % 3 + 3; - } - break; - case MshElemType::PYRAMID: // 3-D pyramid element - if(Edge < 4) - { - EdgeNodes[0] = Edge; - EdgeNodes[1] = (Edge + 1) % 4; - } - else - { - EdgeNodes[0] = Edge % 4; - EdgeNodes[1] = 4; - } - break; - default: - std::cerr << "CElem::GetLocalIndicesOfEdgeNodes() - MshElemType not handled" << - "\n"; + break; + case MshElemType::PRISM: // 3-D prismatic element + if (Edge < 6) + { + EdgeNodes[0] = Edge; + EdgeNodes[1] = (Edge + 1) % 3 + 3 * (int)(Edge / 3); + } + else + { + EdgeNodes[0] = Edge % 3; + EdgeNodes[1] = Edge % 3 + 3; + } + break; + case MshElemType::PYRAMID: // 3-D pyramid element + if (Edge < 4) + { + EdgeNodes[0] = Edge; + EdgeNodes[1] = (Edge + 1) % 4; + } + else + { + EdgeNodes[0] = Edge % 4; + EdgeNodes[1] = 4; + } + break; + default: + std::cerr << "CElem::GetLocalIndicesOfEdgeNodes() - MshElemType not handled" + << "\n"; } } /************************************************************************** @@ -1041,7 +1007,7 @@ int CElem::GetElementFaces1D(int* FaceNode) **************************************************************************/ int CElem::GetElementFacesTri(int Face, int* FaceNode) { - if(!quadratic) + if (!quadratic) { FaceNode[0] = Face; FaceNode[1] = (Face + 1) % 3; @@ -1068,7 +1034,7 @@ int CElem::GetElementFacesTri(int Face, int* FaceNode) **************************************************************************/ int CElem::GetElementFacesQuad(int Face, int* FaceNode) { - if(!quadratic) + if (!quadratic) { FaceNode[0] = Face; FaceNode[1] = (Face + 1) % 4; @@ -1096,77 +1062,77 @@ int CElem::GetElementFacesQuad(int Face, int* FaceNode) int CElem::GetElementFacesHex(int Face, int* FaceNode) { int nn = 4, k = 0; - if(quadratic) + if (quadratic) nn = 8; - switch(Face) + switch (Face) { - case 0: - for(k = 0; k < 4; k++) - FaceNode[k] = k; - if(quadratic) - for(k = 0; k < 4; k++) - FaceNode[k + 4] = k + 8; - break; - case 1: - for(k = 0; k < 4; k++) - FaceNode[k] = k + 4; - if(quadratic) - for(k = 0; k < 4; k++) - FaceNode[k + 4] = k + 12; - break; - case 2: - FaceNode[0] = 0; - FaceNode[1] = 4; - FaceNode[2] = 5; - FaceNode[3] = 1; - if(quadratic) - { - FaceNode[4] = 16; - FaceNode[5] = 12; - FaceNode[6] = 17; - FaceNode[7] = 8; - } - break; - case 3: - FaceNode[0] = 1; - FaceNode[1] = 5; - FaceNode[2] = 6; - FaceNode[3] = 2; - if(quadratic) - { - FaceNode[4] = 17; - FaceNode[5] = 13; - FaceNode[6] = 18; - FaceNode[7] = 9; - } + case 0: + for (k = 0; k < 4; k++) + FaceNode[k] = k; + if (quadratic) + for (k = 0; k < 4; k++) + FaceNode[k + 4] = k + 8; + break; + case 1: + for (k = 0; k < 4; k++) + FaceNode[k] = k + 4; + if (quadratic) + for (k = 0; k < 4; k++) + FaceNode[k + 4] = k + 12; + break; + case 2: + FaceNode[0] = 0; + FaceNode[1] = 4; + FaceNode[2] = 5; + FaceNode[3] = 1; + if (quadratic) + { + FaceNode[4] = 16; + FaceNode[5] = 12; + FaceNode[6] = 17; + FaceNode[7] = 8; + } + break; + case 3: + FaceNode[0] = 1; + FaceNode[1] = 5; + FaceNode[2] = 6; + FaceNode[3] = 2; + if (quadratic) + { + FaceNode[4] = 17; + FaceNode[5] = 13; + FaceNode[6] = 18; + FaceNode[7] = 9; + } - break; - case 4: - FaceNode[0] = 2; - FaceNode[1] = 6; - FaceNode[2] = 7; - FaceNode[3] = 3; - if(quadratic) - { - FaceNode[4] = 18; - FaceNode[5] = 14; - FaceNode[6] = 19; - FaceNode[7] = 10; - } - break; - case 5: - FaceNode[0] = 0; - FaceNode[1] = 3; - FaceNode[2] = 7; - FaceNode[3] = 4; - if(quadratic) - { - FaceNode[4] = 11; - FaceNode[5] = 19; - FaceNode[6] = 15; - FaceNode[7] = 16; - } - break; + break; + case 4: + FaceNode[0] = 2; + FaceNode[1] = 6; + FaceNode[2] = 7; + FaceNode[3] = 3; + if (quadratic) + { + FaceNode[4] = 18; + FaceNode[5] = 14; + FaceNode[6] = 19; + FaceNode[7] = 10; + } + break; + case 5: + FaceNode[0] = 0; + FaceNode[1] = 3; + FaceNode[2] = 7; + FaceNode[3] = 4; + if (quadratic) + { + FaceNode[4] = 11; + FaceNode[5] = 19; + FaceNode[6] = 15; + FaceNode[7] = 16; + } + break; } return nn; } @@ -1184,54 +1150,54 @@ int CElem::GetElementFacesHex(int Face, int* FaceNode) int CElem::GetElementFacesTet(int Face, int* FaceNode) { int nn = 3; - if(quadratic) + if (quadratic) nn = 6; - switch(Face) + switch (Face) { - case 0: - FaceNode[0] = 1; - FaceNode[1] = 2; - FaceNode[2] = 3; - if(quadratic) - { - FaceNode[3] = 5; - FaceNode[4] = 8; - FaceNode[5] = 7; - } - break; - case 1: - FaceNode[0] = 3; - FaceNode[1] = 2; - FaceNode[2] = 0; - if(quadratic) - { - FaceNode[3] = 8; - FaceNode[4] = 6; - FaceNode[5] = 9; - } - break; - case 2: - FaceNode[0] = 1; - FaceNode[1] = 3; - FaceNode[2] = 0; - if(quadratic) - { - FaceNode[3] = 7; - FaceNode[4] = 9; - FaceNode[5] = 4; - } - break; - case 3: - FaceNode[0] = 0; - FaceNode[1] = 2; - FaceNode[2] = 1; - if(quadratic) - { - FaceNode[3] = 6; - FaceNode[4] = 5; - FaceNode[5] = 4; - } - break; + case 0: + FaceNode[0] = 1; + FaceNode[1] = 2; + FaceNode[2] = 3; + if (quadratic) + { + FaceNode[3] = 5; + FaceNode[4] = 8; + FaceNode[5] = 7; + } + break; + case 1: + FaceNode[0] = 3; + FaceNode[1] = 2; + FaceNode[2] = 0; + if (quadratic) + { + FaceNode[3] = 8; + FaceNode[4] = 6; + FaceNode[5] = 9; + } + break; + case 2: + FaceNode[0] = 1; + FaceNode[1] = 3; + FaceNode[2] = 0; + if (quadratic) + { + FaceNode[3] = 7; + FaceNode[4] = 9; + FaceNode[5] = 4; + } + break; + case 3: + FaceNode[0] = 0; + FaceNode[1] = 2; + FaceNode[2] = 1; + if (quadratic) + { + FaceNode[3] = 6; + FaceNode[4] = 5; + FaceNode[5] = 4; + } + break; } return nn; } @@ -1249,75 +1215,75 @@ int CElem::GetElementFacesTet(int Face, int* FaceNode) int CElem::GetElementFacesPri(int Face, int* FaceNode) { int nn = 3, k = 0; - switch(Face) + switch (Face) { - case 0: - nn = 3; - for(k = 0; k < 3; k++) - FaceNode[k] = k; - if(quadratic) - { - for(k = 0; k < 3; k++) - FaceNode[k + 3] = k + 6; - nn = 6; - } - break; - case 1: - for(k = 0; k < 3; k++) - FaceNode[k] = k + 3; - nn = 3; - if(quadratic) - { - for(k = 0; k < 3; k++) - FaceNode[k + 3] = k + 9; - nn = 6; - } - break; - case 2: - FaceNode[0] = 1; - FaceNode[1] = 2; - FaceNode[2] = 5; - FaceNode[3] = 4; - nn = 4; - if(quadratic) - { - FaceNode[4] = 7; - FaceNode[5] = 14; - FaceNode[6] = 10; - FaceNode[7] = 13; - nn = 8; - } - break; - case 3: - FaceNode[0] = 5; - FaceNode[1] = 2; - FaceNode[2] = 0; - FaceNode[3] = 3; - nn = 4; - if(quadratic) - { - FaceNode[4] = 14; - FaceNode[5] = 8; - FaceNode[6] = 12; - FaceNode[7] = 11; - nn = 8; - } - break; - case 4: - FaceNode[0] = 0; - FaceNode[1] = 1; - FaceNode[2] = 4; - FaceNode[3] = 3; - nn = 4; - if(quadratic) - { - FaceNode[4] = 6; - FaceNode[5] = 13; - FaceNode[6] = 9; - FaceNode[7] = 12; - nn = 8; - } - break; + case 0: + nn = 3; + for (k = 0; k < 3; k++) + FaceNode[k] = k; + if (quadratic) + { + for (k = 0; k < 3; k++) + FaceNode[k + 3] = k + 6; + nn = 6; + } + break; + case 1: + for (k = 0; k < 3; k++) + FaceNode[k] = k + 3; + nn = 3; + if (quadratic) + { + for (k = 0; k < 3; k++) + FaceNode[k + 3] = k + 9; + nn = 6; + } + break; + case 2: + FaceNode[0] = 1; + FaceNode[1] = 2; + FaceNode[2] = 5; + FaceNode[3] = 4; + nn = 4; + if (quadratic) + { + FaceNode[4] = 7; + FaceNode[5] = 14; + FaceNode[6] = 10; + FaceNode[7] = 13; + nn = 8; + } + break; + case 3: + FaceNode[0] = 5; + FaceNode[1] = 2; + FaceNode[2] = 0; + FaceNode[3] = 3; + nn = 4; + if (quadratic) + { + FaceNode[4] = 14; + FaceNode[5] = 8; + FaceNode[6] = 12; + FaceNode[7] = 11; + nn = 8; + } + break; + case 4: + FaceNode[0] = 0; + FaceNode[1] = 1; + FaceNode[2] = 4; + FaceNode[3] = 3; + nn = 4; + if (quadratic) + { + FaceNode[4] = 6; + FaceNode[5] = 13; + FaceNode[6] = 9; + FaceNode[7] = 12; + nn = 8; + } + break; } return nn; } @@ -1335,71 +1301,71 @@ int CElem::GetElementFacesPri(int Face, int* FaceNode) int CElem::GetElementFacesPyramid(const int Face, int* FaceNode) { int nn = 3, k = 0; - switch(Face) + switch (Face) { - case 0: - nn = 4; - for(k = 0; k < nn; k++) - FaceNode[k] = k; - if(quadratic) - { - for(k = 0; k < nn; k++) - FaceNode[k + 4] = k + 5; - nn = 8; - } - break; - case 1: - FaceNode[0] = 0; - FaceNode[1] = 1; - FaceNode[2] = 4; - nn = 3; - if(quadratic) - { - FaceNode[3] = 5; - FaceNode[4] = 10; - FaceNode[5] = 9; - nn = 6; - } - break; - case 2: - FaceNode[0] = 1; - FaceNode[1] = 2; - FaceNode[2] = 4; - nn = 3; - if(quadratic) - { - FaceNode[3] = 6; - FaceNode[4] = 11; - FaceNode[5] = 10; - nn = 6; - } - break; - case 3: - FaceNode[0] = 2; - FaceNode[1] = 3; - FaceNode[2] = 4; - nn = 3; - if(quadratic) - { - FaceNode[3] = 7; - FaceNode[4] = 12; - FaceNode[5] = 11; - nn = 6; - } - break; - case 4: - FaceNode[0] = 3; - FaceNode[1] = 0; - FaceNode[2] = 4; - nn = 3; - if(quadratic) - { - FaceNode[3] = 8; - FaceNode[4] = 9; - FaceNode[5] = 12; - nn = 6; - } - break; + case 0: + nn = 4; + for (k = 0; k < nn; k++) + FaceNode[k] = k; + if (quadratic) + { + for (k = 0; k < nn; k++) + FaceNode[k + 4] = k + 5; + nn = 8; + } + break; + case 1: + FaceNode[0] = 0; + FaceNode[1] = 1; + FaceNode[2] = 4; + nn = 3; + if (quadratic) + { + FaceNode[3] = 5; + FaceNode[4] = 10; + FaceNode[5] = 9; + nn = 6; + } + break; + case 2: + FaceNode[0] = 1; + FaceNode[1] = 2; + FaceNode[2] = 4; + nn = 3; + if (quadratic) + { + FaceNode[3] = 6; + FaceNode[4] = 11; + FaceNode[5] = 10; + nn = 6; + } + break; + case 3: + FaceNode[0] = 2; + FaceNode[1] = 3; + FaceNode[2] = 4; + nn = 3; + if (quadratic) + { + FaceNode[3] = 7; + FaceNode[4] = 12; + FaceNode[5] = 11; + nn = 6; + } + break; + case 4: + FaceNode[0] = 3; + FaceNode[1] = 0; + FaceNode[2] = 4; + nn = 3; + if (quadratic) + { + FaceNode[3] = 8; + FaceNode[4] = 9; + FaceNode[5] = 12; + nn = 6; + } + break; } return nn; } @@ -1416,25 +1382,26 @@ int CElem::GetElementFacesPyramid(const int Face, int* FaceNode) **************************************************************************/ int CElem::GetElementFaceNodes(int Face, int* FacesNode) { - switch(geo_type) + switch (geo_type) { - case MshElemType::LINE: // 1-D bar element - return GetElementFaces1D(FacesNode); - case MshElemType::QUAD: // 2-D quadrilateral element - return GetElementFacesQuad(Face, FacesNode); - case MshElemType::HEXAHEDRON: // 3-D hexahedral element - return GetElementFacesHex(Face, FacesNode); - case MshElemType::TRIANGLE: // 2-D triagular element - return GetElementFacesTri(Face, FacesNode); - case MshElemType::TETRAHEDRON: // 3-D tetrahedral element - return GetElementFacesTet(Face, FacesNode); - case MshElemType::PRISM: - return GetElementFacesPri(Face, FacesNode); - // 3-D prismatic element - case MshElemType::PYRAMID: // 3-D pyramid element - return GetElementFacesPyramid(Face, FacesNode); - default: - std::cerr << "CElem::GetElementFaceNodes MshElemType not handled" << "\n"; + case MshElemType::LINE: // 1-D bar element + return GetElementFaces1D(FacesNode); + case MshElemType::QUAD: // 2-D quadrilateral element + return GetElementFacesQuad(Face, FacesNode); + case MshElemType::HEXAHEDRON: // 3-D hexahedral element + return GetElementFacesHex(Face, FacesNode); + case MshElemType::TRIANGLE: // 2-D triagular element + return GetElementFacesTri(Face, FacesNode); + case MshElemType::TETRAHEDRON: // 3-D tetrahedral element + return GetElementFacesTet(Face, FacesNode); + case MshElemType::PRISM: + return GetElementFacesPri(Face, FacesNode); + // 3-D prismatic element + case MshElemType::PYRAMID: // 3-D pyramid element + return GetElementFacesPyramid(Face, FacesNode); + default: + std::cerr << "CElem::GetElementFaceNodes MshElemType not handled" + << "\n"; } return 0; } @@ -1450,95 +1417,72 @@ void CElem::ComputeVolume() { volume = calcVolume(); - if (this->geo_type == MshElemType::LINE) // Line + if (this->geo_type == MshElemType::LINE) // Line representative_length = volume; else if (this->geo_type == MshElemType::TRIANGLE) representative_length = sqrt(volume) * 4.0; else if (this->geo_type == MshElemType::QUAD) - representative_length = sqrt(volume); //kg44 reactivated + representative_length = sqrt(volume); // kg44 reactivated else if (this->geo_type == MshElemType::TETRAHEDRON) representative_length = sqrt(volume) * 6.0; else if (this->geo_type == MshElemType::HEXAHEDRON) - representative_length = pow(volume,1. / 3.); + representative_length = pow(volume, 1. / 3.); else if (this->geo_type == MshElemType::PRISM) - representative_length = pow(volume,1. / 3.); + representative_length = pow(volume, 1. / 3.); else if (this->geo_type == MshElemType::PYRAMID) - representative_length = 0.0; //NW set zero because I don't know what is the representative_length. + representative_length = 0.0; // NW set zero because I don't know what is the representative_length. else - std::cerr << "Error in CElem::ComputeVolume() - MshElemType not found" << "\n"; + std::cerr << "Error in CElem::ComputeVolume() - MshElemType not found" + << "\n"; } -double CElem::calcVolume () const +double CElem::calcVolume() const { double elemVolume = 0.0; - if (this->geo_type == MshElemType::LINE) // Line + if (this->geo_type == MshElemType::LINE) // Line { - double const* const pnt0 (nodes[0]->getData()); - double const* const pnt (nodes[nnodes - 1]->getData()); + double const* const pnt0(nodes[0]->getData()); + double const* const pnt(nodes[nnodes - 1]->getData()); double xDiff = pnt[0] - pnt0[0]; double yDiff = pnt[1] - pnt0[1]; double zDiff = pnt[2] - pnt0[2]; - elemVolume = sqrt(xDiff * xDiff + yDiff * yDiff + zDiff * zDiff); //CMCD kg44 reactivated + elemVolume = sqrt(xDiff * xDiff + yDiff * yDiff + zDiff * zDiff); // CMCD kg44 reactivated } else if (this->geo_type == MshElemType::TRIANGLE) - elemVolume = ComputeDetTri(nodes[0]->getData(), - nodes[1]->getData(), nodes[2]->getData()); //kg44 reactivated + elemVolume = ComputeDetTri(nodes[0]->getData(), nodes[1]->getData(), nodes[2]->getData()); // kg44 reactivated else if (this->geo_type == MshElemType::QUAD) - elemVolume = ComputeDetTri(nodes[0]->getData(), - nodes[1]->getData(), nodes[2]->getData()) - + ComputeDetTri(nodes[2]->getData(), - nodes[3]->getData(), nodes[0]->getData()); + elemVolume = ComputeDetTri(nodes[0]->getData(), nodes[1]->getData(), nodes[2]->getData()) + + ComputeDetTri(nodes[2]->getData(), nodes[3]->getData(), nodes[0]->getData()); else if (this->geo_type == MshElemType::TETRAHEDRON) - elemVolume = ComputeDetTex(nodes[0]->getData(), - nodes[1]->getData(), - nodes[2]->getData(), nodes[3]->getData()); //kg44 reactivated + elemVolume = ComputeDetTex(nodes[0]->getData(), nodes[1]->getData(), nodes[2]->getData(), + nodes[3]->getData()); // kg44 reactivated else if (this->geo_type == MshElemType::HEXAHEDRON) { - elemVolume = ComputeDetTex(nodes[4]->getData(), - nodes[7]->getData(), - nodes[5]->getData(), nodes[0]->getData()); - elemVolume += ComputeDetTex(nodes[5]->getData(), - nodes[3]->getData(), - nodes[1]->getData(), nodes[0]->getData()); - elemVolume += ComputeDetTex(nodes[5]->getData(), - nodes[7]->getData(), - nodes[3]->getData(), nodes[0]->getData()); - elemVolume += ComputeDetTex(nodes[5]->getData(), - nodes[7]->getData(), - nodes[6]->getData(), nodes[2]->getData()); - elemVolume += ComputeDetTex(nodes[1]->getData(), - nodes[3]->getData(), - nodes[5]->getData(), nodes[2]->getData()); - elemVolume += ComputeDetTex(nodes[3]->getData(), - nodes[7]->getData(), - nodes[5]->getData(), nodes[2]->getData()); - //kg44 reactivated + elemVolume = ComputeDetTex(nodes[4]->getData(), nodes[7]->getData(), nodes[5]->getData(), nodes[0]->getData()); + elemVolume += ComputeDetTex(nodes[5]->getData(), nodes[3]->getData(), nodes[1]->getData(), nodes[0]->getData()); + elemVolume += ComputeDetTex(nodes[5]->getData(), nodes[7]->getData(), nodes[3]->getData(), nodes[0]->getData()); + elemVolume += ComputeDetTex(nodes[5]->getData(), nodes[7]->getData(), nodes[6]->getData(), nodes[2]->getData()); + elemVolume += ComputeDetTex(nodes[1]->getData(), nodes[3]->getData(), nodes[5]->getData(), nodes[2]->getData()); + elemVolume += ComputeDetTex(nodes[3]->getData(), nodes[7]->getData(), nodes[5]->getData(), nodes[2]->getData()); + // kg44 reactivated } else if (this->geo_type == MshElemType::PRISM) { - elemVolume = ComputeDetTex(nodes[0]->getData(), - nodes[1]->getData(), - nodes[2]->getData(), nodes[3]->getData()); - elemVolume += ComputeDetTex(nodes[1]->getData(), - nodes[4]->getData(), - nodes[2]->getData(), nodes[3]->getData()); - elemVolume += ComputeDetTex(nodes[2]->getData(), - nodes[4]->getData(), - nodes[5]->getData(), nodes[3]->getData()); - // kg44 reactivated ---------Here the direction of flow needs to be taken into account, we need rep length in x,y,z direction + elemVolume = ComputeDetTex(nodes[0]->getData(), nodes[1]->getData(), nodes[2]->getData(), nodes[3]->getData()); + elemVolume += ComputeDetTex(nodes[1]->getData(), nodes[4]->getData(), nodes[2]->getData(), nodes[3]->getData()); + elemVolume += ComputeDetTex(nodes[2]->getData(), nodes[4]->getData(), nodes[5]->getData(), nodes[3]->getData()); + // kg44 reactivated ---------Here the direction of flow needs to be taken into account, we need rep length in + // x,y,z direction } else if (this->geo_type == MshElemType::PYRAMID) { - elemVolume = ComputeDetTex(nodes[0]->getData(), - nodes[1]->getData(), - nodes[2]->getData(), nodes[4]->getData()); - elemVolume += ComputeDetTex(nodes[2]->getData(), - nodes[3]->getData(), - nodes[0]->getData(), nodes[4]->getData()); + elemVolume = ComputeDetTex(nodes[0]->getData(), nodes[1]->getData(), nodes[2]->getData(), nodes[4]->getData()); + elemVolume += ComputeDetTex(nodes[2]->getData(), nodes[3]->getData(), nodes[0]->getData(), nodes[4]->getData()); } else - std::cerr << "Error in CElem::ComputeVolume() - MshElemType not found" << "\n"; + std::cerr << "Error in CElem::ComputeVolume() - MshElemType not found" + << "\n"; return elemVolume; } @@ -1567,31 +1511,31 @@ void CElem::FaceNormal(int index0, int index1, double* face) face[2] = pnt1[2] - pnt0[2]; // x"_vec -// xx[0] = nodes[1]->X()-nodes[0]->X(); -// xx[1] = nodes[1]->Y()-nodes[0]->Y(); -// xx[2] = nodes[1]->Z()-nodes[0]->Z(); + // xx[0] = nodes[1]->X()-nodes[0]->X(); + // xx[1] = nodes[1]->Y()-nodes[0]->Y(); + // xx[2] = nodes[1]->Z()-nodes[0]->Z(); pnt0 = nodes[0]->getData(); pnt1 = nodes[1]->getData(); xx[0] = pnt1[0] - pnt0[0]; xx[1] = pnt1[1] - pnt0[1]; xx[2] = pnt1[2] - pnt0[2]; - //NormalizeVector(xx,3); + // NormalizeVector(xx,3); // a vector on the plane -// yy[0] = nodes[2]->X()-nodes[1]->X(); -// yy[1] = nodes[2]->Y()-nodes[1]->Y(); -// yy[2] = nodes[2]->Z()-nodes[1]->Z(); + // yy[0] = nodes[2]->X()-nodes[1]->X(); + // yy[1] = nodes[2]->Y()-nodes[1]->Y(); + // yy[2] = nodes[2]->Z()-nodes[1]->Z(); double const* pnt2(nodes[2]->getData()); yy[0] = pnt2[0] - pnt1[0]; yy[1] = pnt2[1] - pnt1[1]; yy[2] = pnt2[2] - pnt1[2]; // z"_vec - CrossProduction(xx,yy,zz); - NormalizeVector(zz,3); + CrossProduction(xx, yy, zz); + NormalizeVector(zz, 3); // y"_vec - CrossProduction(face,zz,yy); - NormalizeVector(yy,3); - for(size_t i = 0; i < 3; i++) + CrossProduction(face, zz, yy); + NormalizeVector(yy, 3); + for (size_t i = 0; i < 3; i++) face[i] = yy[i]; } } @@ -1602,119 +1546,118 @@ void CElem::FaceNormal(int index0, int index1, double* face) **************************************************************************/ void CElem::SetNormalVector() { - - if(!normal_vector) - normal_vector = new double[3]; //WW + if (!normal_vector) + normal_vector = new double[3]; // WW if (this->GetElementType() == MshElemType::LINE) // JOD 2014-11-10 { - double const* const p0(nodes[0]->getData()); double const* const p1(nodes[1]->getData()); - double v1[3] = { p1[0] - p0[0], p1[1] - p0[1], p1[2] - p0[2] }; - if ( fabs(v1[2]) > 1.e-20) { + double v1[3] = {p1[0] - p0[0], p1[1] - p0[1], p1[2] - p0[2]}; + if (fabs(v1[2]) > 1.e-20) + { double buffer = v1[1]; v1[1] = v1[2]; v1[2] = buffer; } - const double v2[3] = { 0, 0 , 1 }; // fluxes are on xy plane + const double v2[3] = {0, 0, 1}; // fluxes are on xy plane CrossProduction(v1, v2, normal_vector); NormalizeVector(normal_vector, 3); if (normal_vector[0] < 0) normal_vector[0] = -normal_vector[0]; - } if (this->GetElementType() == MshElemType::TRIANGLE) { - double const* const p0 (nodes[0]->getData()); - double const* const p1 (nodes[1]->getData()); - double const* const p2 (nodes[2]->getData()); + double const* const p0(nodes[0]->getData()); + double const* const p1(nodes[1]->getData()); + double const* const p2(nodes[2]->getData()); const double v1[3] = {p1[0] - p0[0], p1[1] - p0[1], p1[2] - p0[2]}; const double v2[3] = {p2[0] - p0[0], p2[1] - p0[1], p2[2] - p0[2]}; - CrossProduction(v1,v2,normal_vector); - NormalizeVector(normal_vector,3); + CrossProduction(v1, v2, normal_vector); + NormalizeVector(normal_vector, 3); } - if (this->GetElementType() == MshElemType::QUAD) //BG 04/2011: calculation of the normal vector of a quad element - { - double const* const p0 (nodes[0]->getData()); - double const* const p1 (nodes[1]->getData()); -// double const* const p2 (nodes[2]->getData()); // TF unused variable - double const* const p3 (nodes[3]->getData()); - const double v1[3] = {p1[0] - p0[0], p1[1] - p0[1], p1[2] - p0[2]}; + if (this->GetElementType() == MshElemType::QUAD) // BG 04/2011: calculation of the normal vector of a quad element + { + double const* const p0(nodes[0]->getData()); + double const* const p1(nodes[1]->getData()); + // double const* const p2 (nodes[2]->getData()); // TF unused variable + double const* const p3(nodes[3]->getData()); + const double v1[3] = {p1[0] - p0[0], p1[1] - p0[1], p1[2] - p0[2]}; const double v2[3] = {p3[0] - p0[0], p3[1] - p0[1], p3[2] - p0[2]}; - //v1[0] = nodes[1]->X() - nodes[0]->X(); - //v1[1] = nodes[1]->Y() - nodes[0]->Y(); - //v1[2] = nodes[1]->Z() - nodes[0]->Z(); - //v2[0] = nodes[3]->X() - nodes[0]->X(); - //v2[1] = nodes[3]->Y() - nodes[0]->Y(); - //v2[2] = nodes[3]->Z() - nodes[0]->Z(); - CrossProduction(v1,v2,normal_vector); - NormalizeVector(normal_vector,3); - } + // v1[0] = nodes[1]->X() - nodes[0]->X(); + // v1[1] = nodes[1]->Y() - nodes[0]->Y(); + // v1[2] = nodes[1]->Z() - nodes[0]->Z(); + // v2[0] = nodes[3]->X() - nodes[0]->X(); + // v2[1] = nodes[3]->Y() - nodes[0]->Y(); + // v2[2] = nodes[3]->Z() - nodes[0]->Z(); + CrossProduction(v1, v2, normal_vector); + NormalizeVector(normal_vector, 3); + } } // KR 2010/11/16 void CElem::setElementProperties(MshElemType::type t, bool isFace) { - switch(t) + switch (t) { - case MshElemType::LINE: - nnodes = 2; - nnodesHQ = 3; - ele_dim = 1; - geo_type = MshElemType::LINE; - nfaces = 2; - nedges = 1; - break; - case MshElemType::QUAD: - nnodes = 4; - nnodesHQ = (isFace) ? 8 : 9; // if a QUAD is the face of a hex it has 8 nodes, otherwise it has 9 - ele_dim = 2; - geo_type = MshElemType::QUAD; - nfaces = 4; - nedges = 4; - break; - case MshElemType::HEXAHEDRON: - nnodes = 8; - nnodesHQ = 20; - ele_dim = 3; - nfaces = 6; - nedges = 12; - geo_type = MshElemType::HEXAHEDRON; - break; - case MshElemType::TRIANGLE: - nnodes = 3; - nnodesHQ = 6; - ele_dim = 2; - geo_type = MshElemType::TRIANGLE; - nfaces = 3; - nedges = 3; - break; - case MshElemType::TETRAHEDRON: - nnodes = 4; - nnodesHQ = 10; - ele_dim = 3; - geo_type = MshElemType::TETRAHEDRON; - nfaces = 4; - nedges = 6; - break; - case MshElemType::PRISM: - nnodes = 6; - nnodesHQ = 15; - ele_dim = 3; - geo_type = MshElemType::PRISM; - nfaces = 5; - nedges = 9; - break; - case MshElemType::PYRAMID: - nnodes = 5; - nnodesHQ = 13; - ele_dim = 3; - geo_type = MshElemType::PYRAMID; - nfaces = 5; - nedges = 8; - break; - default: - std::cerr << "CElem::setElementProperties MshElemType not handled" << "\n"; + case MshElemType::LINE: + nnodes = 2; + nnodesHQ = 3; + ele_dim = 1; + geo_type = MshElemType::LINE; + nfaces = 2; + nedges = 1; + break; + case MshElemType::QUAD: + nnodes = 4; + nnodesHQ = (isFace) ? 8 : 9; // if a QUAD is the face of a hex it has 8 nodes, otherwise it has 9 + ele_dim = 2; + geo_type = MshElemType::QUAD; + nfaces = 4; + nedges = 4; + break; + case MshElemType::HEXAHEDRON: + nnodes = 8; + nnodesHQ = 20; + ele_dim = 3; + nfaces = 6; + nedges = 12; + geo_type = MshElemType::HEXAHEDRON; + break; + case MshElemType::TRIANGLE: + nnodes = 3; + nnodesHQ = 6; + ele_dim = 2; + geo_type = MshElemType::TRIANGLE; + nfaces = 3; + nedges = 3; + break; + case MshElemType::TETRAHEDRON: + nnodes = 4; + nnodesHQ = 10; + ele_dim = 3; + geo_type = MshElemType::TETRAHEDRON; + nfaces = 4; + nedges = 6; + break; + case MshElemType::PRISM: + nnodes = 6; + nnodesHQ = 15; + ele_dim = 3; + geo_type = MshElemType::PRISM; + nfaces = 5; + nedges = 9; + break; + case MshElemType::PYRAMID: + nnodes = 5; + nnodesHQ = 13; + ele_dim = 3; + geo_type = MshElemType::PYRAMID; + nfaces = 5; + nedges = 8; + break; + default: + std::cerr << "CElem::setElementProperties MshElemType not handled" + << "\n"; } this->nodes_index.resize(nnodes); } @@ -1723,16 +1666,16 @@ void CElem::setElementProperties(MshElemType::type t, bool isFace) double* CElem::ComputeGravityCenter() { const size_t nnodes0 = this->nnodes; - for (size_t i = 0; i < nnodes0; i++) // Nodes + for (size_t i = 0; i < nnodes0; i++) // Nodes { - double const* const pnt (nodes[i]->getData()); + double const* const pnt(nodes[i]->getData()); gravity_center[0] += pnt[0]; gravity_center[1] += pnt[1]; gravity_center[2] += pnt[2]; } - gravity_center[0] /= (double) nnodes0; - gravity_center[1] /= (double) nnodes0; - gravity_center[2] /= (double) nnodes0; + gravity_center[0] /= (double)nnodes0; + gravity_center[1] /= (double)nnodes0; + gravity_center[2] /= (double)nnodes0; return gravity_center; } @@ -1742,11 +1685,9 @@ MSHLib-Method: **************************************************************************/ void CElem::DirectNormalVector() { - for (int i = 0; i < 3; i++) - if (normal_vector[i] < 0) - InvertNormalVector(); - + if (normal_vector[i] < 0) + InvertNormalVector(); } /************************************************************************** @@ -1755,11 +1696,9 @@ MSHLib-Method: **************************************************************************/ void CElem::InvertNormalVector() { - normal_vector[0] = -normal_vector[0]; normal_vector[1] = -normal_vector[1]; normal_vector[2] = -normal_vector[2]; - } -} // namespace MeshLib +} // namespace MeshLib diff --git a/MSH/msh_elem.h b/MSH/msh_elem.h index 2d640ccc6..82ef1a92b 100644 --- a/MSH/msh_elem.h +++ b/MSH/msh_elem.h @@ -17,10 +17,12 @@ // PCSLib namespace process -{class CRFProcessDeformation; +{ +class CRFProcessDeformation; } namespace Math_Group -{class Matrix; +{ +class Matrix; } class CRFProcess; @@ -37,12 +39,12 @@ class CElem : public CCore CElem(size_t Index); // For Faces: Face, local face index CElem(size_t Index, CElem* onwer, int Face); - CElem(size_t Index, CElem* m_ele_parent); //WWOK + CElem(size_t Index, CElem* m_ele_parent); // WWOK /** * copy constructor */ - CElem (CElem const &elem); + CElem(CElem const& elem); /** * constructor for a triangle element @@ -53,7 +55,7 @@ class CElem : public CCore * @param mat number of material * @return a mesh element object */ - CElem (MshElemType::type t, size_t node0, size_t node1, size_t node2, int mat); + CElem(MshElemType::type t, size_t node0, size_t node1, size_t node2, int mat); /** * constructor for a quad element @@ -65,7 +67,7 @@ class CElem : public CCore * @param mat number of material * @return a mesh element object */ - CElem (MshElemType::type t, size_t node0, size_t node1, size_t node2, size_t node3, int mat); + CElem(MshElemType::type t, size_t node0, size_t node1, size_t node2, size_t node3, int mat); ~CElem(); @@ -74,7 +76,8 @@ class CElem : public CCore /** * \brief Sets the default properties for the given element type. * \param t The element type of this element. - * \param isFace Signals if the element is initialised as a face of an owner element, some properties of the element might change in this case. + * \param isFace Signals if the element is initialised as a face of an owner element, some properties of the element + * might change in this case. */ void setElementProperties(MshElemType::type t, bool isFace = false); @@ -83,110 +86,74 @@ class CElem : public CCore * material to the element. * @param pidx an identifier for material */ - void setPatchIndex (size_t pidx) { patch_index = pidx; } - + void setPatchIndex(size_t pidx) { patch_index = pidx; } /// Depricated method kept for backward compatibility. Use setElementProperties(MshElemType::type t) instead. void Config(MshElemType::type t) { setElementProperties(t); } - // Geometry - int GetDimension() const - { - return ele_dim; - } + int GetDimension() const { return ele_dim; } // 09/2011 TF made method const - double const* GetGravityCenter() const - { - return gravity_center; - } + double const* GetGravityCenter() const { return gravity_center; } double* ComputeGravityCenter(); - size_t GetPatchIndex() const - { - return patch_index; - } //MatGroup - void SetPatchIndex(int value) - { - patch_index = value; - } + size_t GetPatchIndex() const { return patch_index; } // MatGroup + void SetPatchIndex(int value) { patch_index = value; } void ComputeVolume(); - void SetFluxArea(double fluxarea) - { - area = fluxarea; - } //CMCD for <3D elements with varying area - double GetFluxArea() - { - return area; - } //CMCD for <3D elements with varying area - - double calcVolume () const; + void SetFluxArea(double fluxarea) { area = fluxarea; } // CMCD for <3D elements with varying area + double GetFluxArea() { return area; } // CMCD for <3D elements with varying area + double calcVolume() const; - double GetVolume() const - { - return volume; - } - void SetVolume(double Vol) - { - volume = Vol; - } + double GetVolume() const { return volume; } + void SetVolume(double Vol) { volume = Vol; } // This will be activated after m_tim->CheckCourant() is ready to work // kg44 21042010 activated - void SetCourant(double Cour) //CMCD + void SetCourant(double Cour) // CMCD { courant = Cour; } - double GetCourant() //CMCD + double GetCourant() // CMCD { return courant; } - void SetNeumann(double Neum) //CMCD + void SetNeumann(double Neum) // CMCD { neumann = Neum; } - double GetNeumann() //CMCD + double GetNeumann() // CMCD { return neumann; } - double GetRepLength() //CMCD + double GetRepLength() // CMCD { return representative_length; } //------------------------------------------------------------------ // ID MshElemType::type GetElementType() const { return geo_type; } - void SetElementType( MshElemType::type type) { geo_type = type; } - + void SetElementType(MshElemType::type type) { geo_type = type; } void MarkingAll(bool makop); std::string GetName() const; //------------------------------------------------------------------ // Nodes void GetNodeIndeces(Math_Group::vec& node_index) const { - for (int i = 0; i < (int) nodes_index.Size(); i++) + for (int i = 0; i < (int)nodes_index.Size(); i++) node_index[i] = nodes_index[i]; } void getNodeIndices(std::vector& node_indices) { for (size_t i = 0; i < nodes_index.Size(); i++) - node_indices.push_back (nodes_index[i]); + node_indices.push_back(nodes_index[i]); } - Math_Group::vec & getNodeIndices() { return nodes_index; } + Math_Group::vec& getNodeIndices() { return nodes_index; } Math_Group::vec const& getNodeIndices() const { return nodes_index; } /** * const access to the vector nodes_index * @return a const reference to the vector */ - const Math_Group::vec& GetNodeIndeces () const { return nodes_index; } - - long GetNodeIndex(int index) const - { - return nodes_index[index]; - } - void SetNodeIndex(int index, long g_index) - { - nodes_index[index] = g_index; - } - + const Math_Group::vec& GetNodeIndeces() const { return nodes_index; } + long GetNodeIndex(int index) const { return nodes_index[index]; } + void SetNodeIndex(int index, long g_index) { nodes_index[index] = g_index; } void GetNodes(Math_Group::vec& ele_nodes) { for (size_t i = 0; i < nodes.Size(); i++) @@ -199,24 +166,13 @@ class CElem : public CCore nodesVec.push_back(nodes[i]); } - CNode* GetNode(int index) - { - return nodes[index]; - } - - CNode const* GetNode(int index) const - { - return nodes[index]; - } - + CNode* GetNode(int index) { return nodes[index]; } + CNode const* GetNode(int index) const { return nodes[index]; } void SetNodes(Math_Group::vec& ele_nodes, bool ReSize = false); void setNodes(std::vector const& ele_nodes); - int GetNodesNumber_H() const - { - return nnodesHQ; - } + int GetNodesNumber_H() const { return nnodesHQ; } size_t GetNodesNumber(bool quad) const { if (quad) @@ -224,19 +180,9 @@ class CElem : public CCore else return (size_t)nnodes; } - int GetVertexNumber() const - { - return nnodes; - } - void SetNodesNumber(int ivalue) - { - nnodes = ivalue; - } //OK - CElem* GetOwner() - { - return owner; - } //YD - + int GetVertexNumber() const { return nnodes; } + void SetNodesNumber(int ivalue) { nnodes = ivalue; } // OK + CElem* GetOwner() { return owner; } // YD // Initialize topological properties void InitializeMembers(); //------------------------------------------------------------------ @@ -246,10 +192,7 @@ class CElem : public CCore for (size_t i = 0; i < nedges; i++) ele_edges[i] = edges[i]; } - CEdge* GetEdge(int index) - { - return edges[index]; - } + CEdge* GetEdge(int index) { return edges[index]; } void SetEdges(Math_Group::vec& ele_edges) { for (size_t i = 0; i < nedges; i++) @@ -261,33 +204,20 @@ class CElem : public CCore for (size_t i = 0; i < nedges; i++) edges_orientation[i] = ori_edg[i]; } - void FreeEdgeMemory() // 09.2012. WW + void FreeEdgeMemory() // 09.2012. WW { edges.resize(0); edges_orientation.resize(0); } void GetLocalIndicesOfEdgeNodes(const int Edge, int* EdgeNodes); - size_t GetEdgesNumber() const - { - return nedges; - } + size_t GetEdgesNumber() const { return nedges; } //------------------------------------------------------------------ // Faces - size_t GetFacesNumber() const - { - return nfaces; - } - + size_t GetFacesNumber() const { return nfaces; } void SetFace(); void SetFace(CElem* onwer, const int Face); - int GetSurfaceFacesNumber() const - { - return no_faces_on_surface; - } - int GetLocalFaceIndex() const - { - return face_index; - } + int GetSurfaceFacesNumber() const { return no_faces_on_surface; } + int GetLocalFaceIndex() const { return face_index; } int GetElementFaceNodes(int Face, int* FacesNode); //------------------------------------------------------------------ @@ -297,20 +227,13 @@ class CElem : public CCore for (size_t i = 0; i < nfaces; i++) neighbors[i] = ele_neighbors[i]; } - void SetNeighbor(const int LocalIndex, CElem* ele_neighbor) - { - neighbors[LocalIndex] = ele_neighbor; - } + void SetNeighbor(const int LocalIndex, CElem* ele_neighbor) { neighbors[LocalIndex] = ele_neighbor; } void GetNeighbors(Math_Group::vec& ele_neighbors) { for (size_t i = 0; i < nfaces; i++) ele_neighbors[i] = neighbors[i]; } - CElem* GetNeighbor(int index) - { - return neighbors[index]; - } - + CElem* GetNeighbor(int index) { return neighbors[index]; } //------------------------------------------------------------------ // Coordinates transform void FillTransformMatrix(); @@ -320,15 +243,9 @@ class CElem : public CCore { if (!angle) angle = new double[3]; - } // WW - double GetAngle(int i) const - { - return angle[i]; - } // PCH - void SetAngle(int i, double value) - { - angle[i] = value; - } // PCH + } // WW + double GetAngle(int i) const { return angle[i]; } // PCH + void SetAngle(int i, double value) { angle[i] = value; } // PCH //------------------------------------------------------------------ // I/O void Read(std::istream& is = std::cin, int fileType = 0); @@ -340,37 +257,37 @@ class CElem : public CCore //------------------------------------------------------------------ // MAT - Math_Group::Vec mat_vector; //OKWW - //WWint matgroup_view; //TK + Math_Group::Vec mat_vector; // OKWW + // WWint matgroup_view; //TK //------------------------------------------------------------------ // Operator // virtual void operator = (const CElem& elem); //------------------------------------------------------------------- int selected; - //YD + // YD void FaceNormal(const int index0, const int index1, double*); - double* normal_vector; //WW normal_vector[3]; //OK - void SetNormalVector(); //OK - void DirectNormalVector(); //JOD 2014-11-10 - void InvertNormalVector(); //JOD 2014-11-10 + double* normal_vector; // WW normal_vector[3]; //OK + void SetNormalVector(); // OK + void DirectNormalVector(); // JOD 2014-11-10 + void InvertNormalVector(); // JOD 2014-11-10 // Since m_tim->CheckCourant() is deactivated, the following member are // put in comment. // kg44 21042010 reactivated - double representative_length; //For stability calculations + double representative_length; // For stability calculations double courant; - double neumann; // MSH topology + double neumann; // MSH topology - int GetExcavState() {return excavated; } //WX:01.2011 get excavation state - void SetExcavState(const int ExcavState) {excavated = ExcavState; } //WX:01.2011 set excavation state + int GetExcavState() { return excavated; } // WX:01.2011 get excavation state + void SetExcavState(const int ExcavState) { excavated = ExcavState; } // WX:01.2011 set excavation state private: // Members // ID - MshElemType::type geo_type; //KR: See MSHEnums.h - 1 Line, 2 Quad, 3 Hex, 4 Tri, 5 Tet, 6 Pris + MshElemType::type geo_type; // KR: See MSHEnums.h - 1 Line, 2 Quad, 3 Hex, 4 Tri, 5 Tet, 6 Pris CElem* owner; // Geometrical properties - int ele_dim; // Dimension of element + int ele_dim; // Dimension of element int nnodes; int nnodesHQ; @@ -378,20 +295,19 @@ class CElem : public CCore Math_Group::vec nodes_index; #if defined(USE_PETSC) // || defined(using other parallel scheme). WW - int *g_index; + int* g_index; #endif - size_t nedges; Math_Group::vec edges; Math_Group::vec edges_orientation; size_t nfaces; int no_faces_on_surface; - int face_index; // Local face index for the instance for face + int face_index; // Local face index for the instance for face double volume; double gravity_center[3]; - int grid_adaptation; // Flag for grid adapting. + int grid_adaptation; // Flag for grid adapting. size_t patch_index; /* // Since m_tim->CheckCourant() is deactivated, the following member are @@ -400,19 +316,19 @@ class CElem : public CCore double courant; double neumann; // MSH topology */ - double area; //Flux area + double area; // Flux area // // MSH topology Math_Group::Matrix* transform_tensor; Math_Group::vec neighbors; - //vec sons; + // vec sons; // double angle[3]; // PCH, angle[0] rotation along y axis // angle[1] rotation along x' axis // angle[2] translation along z'' axis. - double* angle; // Dymanic allocate memory. WW - //WW double MatT[9]; + double* angle; // Dymanic allocate memory. WW + // WW double MatT[9]; - int excavated; //WX:01.2011 excavation state + int excavated; // WX:01.2011 excavation state // -- Methods int GetElementFaces1D(int* FaceNode); diff --git a/MSH/msh_faces.cpp b/MSH/msh_faces.cpp index 6993eca91..19eb320f3 100644 --- a/MSH/msh_faces.cpp +++ b/MSH/msh_faces.cpp @@ -36,12 +36,12 @@ void CPlaneEquation::CalculatePlaneEquationFrom3Points(const double Point1[3], const double Point2[3], const double Point3[3]) { - //Set the initial point + // Set the initial point this->Point[0] = Point1[0]; this->Point[1] = Point1[1]; this->Point[2] = Point1[2]; - //Calculate vectors + // Calculate vectors this->vector1[0] = Point2[0] - Point1[0]; this->vector1[1] = Point2[1] - Point1[1]; this->vector1[2] = Point2[2] - Point1[2]; @@ -50,25 +50,22 @@ void CPlaneEquation::CalculatePlaneEquationFrom3Points(const double Point1[3], this->vector2[1] = Point3[1] - Point1[1]; this->vector2[2] = Point3[2] - Point1[2]; - //Calculate Normal vector - this->normal_vector[0] = this->vector1[1] * this->vector2[2] - this->vector1[2] * - this->vector2[1]; - this->normal_vector[1] = this->vector1[2] * this->vector2[0] - this->vector1[0] * - this->vector2[2]; - this->normal_vector[2] = this->vector1[0] * this->vector2[1] - this->vector1[1] * - this->vector2[0]; + // Calculate Normal vector + this->normal_vector[0] = this->vector1[1] * this->vector2[2] - this->vector1[2] * this->vector2[1]; + this->normal_vector[1] = this->vector1[2] * this->vector2[0] - this->vector1[0] * this->vector2[2]; + this->normal_vector[2] = this->vector1[0] * this->vector2[1] - this->vector1[1] * this->vector2[0]; - //norm the normal vector to 1 + // norm the normal vector to 1 double norm = sqrt(MathLib::scpr(this->normal_vector, this->normal_vector, 3)); this->normal_vector[0] = 1. / norm * this->normal_vector[0]; this->normal_vector[1] = 1. / norm * this->normal_vector[1]; this->normal_vector[2] = 1. / norm * this->normal_vector[2]; - //cout << Point1[0] << ", " << Point1[1] << ", " << Point1[2] << " " << Point2[0] << ", " << Point2[1] << ", " << Point2[2] << " " << Point3[0] << ", " << Point3[1] << ", " << Point3[2]; - //Calculate Lambda for Normal equation of the plane (= scalar product of normal vector and one point of the plane) - this->Lambda_NormalEquation = this->Point[0] * this->normal_vector[0] + this->Point[1] * - this->normal_vector[1] + this->Point[2] * - this->normal_vector[2]; + // cout << Point1[0] << ", " << Point1[1] << ", " << Point1[2] << " " << Point2[0] << ", " << Point2[1] << ", " << + // Point2[2] << " " << Point3[0] << ", " << Point3[1] << ", " << Point3[2]; + // Calculate Lambda for Normal equation of the plane (= scalar product of normal vector and one point of the plane) + this->Lambda_NormalEquation = this->Point[0] * this->normal_vector[0] + this->Point[1] * this->normal_vector[1] + + this->Point[2] * this->normal_vector[2]; } /*------------------------------------------------------------------------- GeoSys - Function: CheckIfPointInPlane @@ -80,9 +77,10 @@ void CPlaneEquation::CalculatePlaneEquationFrom3Points(const double Point1[3], bool CPlaneEquation::CheckIfPointInPlane(const double Point[3]) { (void)Point; - //the point is included in the normal equation of the plane, it is part of the plane if the equation is fullfilled - if (this->Lambda_NormalEquation == this->Point[0] * this->normal_vector[0] + - this->Point[1] * this->normal_vector[1] + this->Point[2] * this->normal_vector[2]) + // the point is included in the normal equation of the plane, it is part of the plane if the equation is fullfilled + if (this->Lambda_NormalEquation + == this->Point[0] * this->normal_vector[0] + this->Point[1] * this->normal_vector[1] + + this->Point[2] * this->normal_vector[2]) return 1; else return 0; @@ -96,15 +94,15 @@ CFaces::CFaces(int number_phases) this->gravity_centre[1] = 0.; this->gravity_centre[2] = 0.; this->nnodes = 0; - //this->phases.resize(number_phases); + // this->phases.resize(number_phases); for (int i = 0; i < number_phases; i++) { m_FlowData = new CFlowData; this->phases.push_back(m_FlowData); - //this->phases[i]->q_norm = 0.0; - //this->phases[i]->q[0] = 0.0; - //this->phases[i]->q[1] = 0.0; - //this->phases[i]->q[2] = 0.0; + // this->phases[i]->q_norm = 0.0; + // this->phases[i]->q[0] = 0.0; + // this->phases[i]->q[1] = 0.0; + // this->phases[i]->q[2] = 0.0; } } @@ -113,7 +111,8 @@ CFaces::~CFaces(void) } /*------------------------------------------------------------------------- GeoSys - Function: FaceCentre - Task: Calculates the coordinates of the centre of each face of a EclipseBlock; Assumes at the moment regular hexahedron + Task: Calculates the coordinates of the centre of each face of a EclipseBlock; Assumes at the moment regular + hexahedron Return: nothing Programming: 09/2009 BG Modification: @@ -123,17 +122,18 @@ bool CFaces::Calculate_FaceGravityCentre(const double Point1[3], const double Point3[3], const double Point4[3]) { - //Order of the faces: 0..left(x); 1..right(x); 2..front(y); 3..back(y); 4..bottom(z); 5..top(z) + // Order of the faces: 0..left(x); 1..right(x); 2..front(y); 3..back(y); 4..bottom(z); 5..top(z) if (this->connected_nodes.size() > 4) { - std::cout << "Error: The face has more than 4 corner points!" << "\n"; + std::cout << "Error: The face has more than 4 corner points!" + << "\n"; exit(1); } - //FaceGravityCentre is calculated for quadrilateral element by calculating the gravitycentre for each triangle - //the gravity-centre of the quadrilateral is the area weighted average of both centres of the triangles - //https://lists.cs.columbia.edu/pipermail/acis-alliance/2003-September/000171.html - //http://www.matheboard.de/archive/51412/thread.html + // FaceGravityCentre is calculated for quadrilateral element by calculating the gravitycentre for each triangle + // the gravity-centre of the quadrilateral is the area weighted average of both centres of the triangles + // https://lists.cs.columbia.edu/pipermail/acis-alliance/2003-September/000171.html + // http://www.matheboard.de/archive/51412/thread.html // Centroid of the first triangle double xc1 = (Point1[0] + Point2[0] + Point3[0]) / 3.; double yc1 = (Point1[1] + Point2[1] + Point3[1]) / 3.; @@ -150,13 +150,9 @@ bool CFaces::Calculate_FaceGravityCentre(const double Point1[3], vec_b[2] = Point3[2] - Point1[2]; // Area of the first triangle = half of the cross product of the 2 vectors - double a1 = 0.5 * - sqrt((vec_a[1] * vec_b[2] - vec_a[2] * - vec_b[1]) * (vec_a[1] * vec_b[2] - vec_a[2] * vec_b[1]) - + (vec_a[2] * vec_b[0] - vec_a[0] * - vec_b[2]) * (vec_a[2] * vec_b[0] - vec_a[0] * vec_b[2]) - + (vec_a[0] * vec_b[1] - vec_a[1] * - vec_b[0]) * (vec_a[0] * vec_b[1] - vec_a[1] * vec_b[0])); + double a1 = 0.5 * sqrt((vec_a[1] * vec_b[2] - vec_a[2] * vec_b[1]) * (vec_a[1] * vec_b[2] - vec_a[2] * vec_b[1]) + + (vec_a[2] * vec_b[0] - vec_a[0] * vec_b[2]) * (vec_a[2] * vec_b[0] - vec_a[0] * vec_b[2]) + + (vec_a[0] * vec_b[1] - vec_a[1] * vec_b[0]) * (vec_a[0] * vec_b[1] - vec_a[1] * vec_b[0])); // Centroid of the second triangle @@ -171,13 +167,9 @@ bool CFaces::Calculate_FaceGravityCentre(const double Point1[3], vec_c[2] = Point4[2] - Point1[2]; // Area of the second triangle - double a2 = 0.5 * - sqrt((vec_c[1] * vec_b[2] - vec_c[2] * - vec_b[1]) * (vec_c[1] * vec_b[2] - vec_c[2] * vec_b[1]) - + (vec_c[2] * vec_b[0] - vec_c[0] * - vec_b[2]) * (vec_c[2] * vec_b[0] - vec_c[0] * vec_b[2]) - + (vec_c[0] * vec_b[1] - vec_c[1] * - vec_b[0]) * (vec_c[0] * vec_b[1] - vec_c[1] * vec_b[0])); + double a2 = 0.5 * sqrt((vec_c[1] * vec_b[2] - vec_c[2] * vec_b[1]) * (vec_c[1] * vec_b[2] - vec_c[2] * vec_b[1]) + + (vec_c[2] * vec_b[0] - vec_c[0] * vec_b[2]) * (vec_c[2] * vec_b[0] - vec_c[0] * vec_b[2]) + + (vec_c[0] * vec_b[1] - vec_c[1] * vec_b[0]) * (vec_c[0] * vec_b[1] - vec_c[1] * vec_b[0])); // Centroid of the 4-sided polygon if ((a1 + a2) > 0) @@ -198,10 +190,7 @@ bool CFaces::Calculate_FaceGravityCentre(const double Point1[3], Programming: 09/2009 BG Modification: -------------------------------------------------------------------------*/ -void CFaces::SetNodes(MeshLib::CNode* Point1, - MeshLib::CNode* Point2, - MeshLib::CNode* Point3, - MeshLib::CNode* Point4) +void CFaces::SetNodes(MeshLib::CNode* Point1, MeshLib::CNode* Point2, MeshLib::CNode* Point3, MeshLib::CNode* Point4) { this->connected_nodes.push_back(Point1); this->connected_nodes.push_back(Point2); @@ -216,7 +205,7 @@ void CFaces::SetNodes(MeshLib::CNode* Point1, Programming: 09/2009 BG Modification: -------------------------------------------------------------------------*/ -void CFaces::SetElements(std::vector element_indices) +void CFaces::SetElements(std::vector element_indices) { this->connected_elements = element_indices; } @@ -234,43 +223,40 @@ void CFaces::Calculate_components_of_a_vector(int flag, int phase_index, bool Ra // contoll that normalvector is positiv in all directions, is only valid if it is no radial model if (Radialmodell == false) { - if((this->model_axis == "I+") || (this->model_axis == "I-")) - if(normal_vector[0] < 0.0) + if ((this->model_axis == "I+") || (this->model_axis == "I-")) + if (normal_vector[0] < 0.0) { - std::cout << - "Error at the normal vector. The i-component is not positiv!" << - "\n"; - //system("Pause"); + std::cout << "Error at the normal vector. The i-component is not positiv!" + << "\n"; + // system("Pause"); exit(1); } - if((this->model_axis == "J+") || (this->model_axis == "J-")) - if(normal_vector[1] < 0.0) + if ((this->model_axis == "J+") || (this->model_axis == "J-")) + if (normal_vector[1] < 0.0) { - std::cout << - "Error at the normal vector. The j-component is not positiv!" << - "\n"; - //system("Pause"); + std::cout << "Error at the normal vector. The j-component is not positiv!" + << "\n"; + // system("Pause"); exit(1); } } - if((this->model_axis == "K+") || (this->model_axis == "K-")) - if(normal_vector[2] < 0.0) + if ((this->model_axis == "K+") || (this->model_axis == "K-")) + if (normal_vector[2] < 0.0) { - std::cout << - "Error at the normal vector. The k-component is not positiv!" << "\n"; - //system("Pause"); + std::cout << "Error at the normal vector. The k-component is not positiv!" + << "\n"; + // system("Pause"); exit(1); } for (int i = 0; i < 3; i++) { - //cout << this->q[i] << " " << normal_vector[i] << " "; - if(flag == 0) - this->phases[phase_index]->q[i] = this->phases[phase_index]->q_norm * - normal_vector[i]; - if(flag == 1) + // cout << this->q[i] << " " << normal_vector[i] << " "; + if (flag == 0) + this->phases[phase_index]->q[i] = this->phases[phase_index]->q_norm * normal_vector[i]; + if (flag == 1) this->vel[i] = this->v_norm * fabs(normal_vector[i]); - //cout << this->q[i] << "\n"; + // cout << this->q[i] << "\n"; } } @@ -281,33 +267,27 @@ void CFaces::Calculate_components_of_a_vector(int flag, int phase_index, bool Ra Programming: 09/2009 BG Modification: -------------------------------------------------------------------------*/ -bool CFaces::CreateFace(MeshLib::CNode* Point1, - MeshLib::CNode* Point2, - MeshLib::CNode* Point3, - MeshLib::CNode* Point4) +bool CFaces::CreateFace(MeshLib::CNode* Point1, MeshLib::CNode* Point2, MeshLib::CNode* Point3, MeshLib::CNode* Point4) { - //Set nodes of the face + // Set nodes of the face this->SetNodes(Point1, Point2, Point3, Point4); - //Calculate the plane equation - double const* const coord_Point1 (this->connected_nodes[0]->getData()); - double const* const coord_Point2 (this->connected_nodes[1]->getData()); - double const* const coord_Point3 (this->connected_nodes[2]->getData()); - double const* const coord_Point4 (this->connected_nodes[3]->getData()); + // Calculate the plane equation + double const* const coord_Point1(this->connected_nodes[0]->getData()); + double const* const coord_Point2(this->connected_nodes[1]->getData()); + double const* const coord_Point3(this->connected_nodes[2]->getData()); + double const* const coord_Point4(this->connected_nodes[3]->getData()); this->PlaneEquation = new CPlaneEquation(); - this->PlaneEquation->CalculatePlaneEquationFrom3Points(coord_Point1, - coord_Point2, - coord_Point3); + this->PlaneEquation->CalculatePlaneEquationFrom3Points(coord_Point1, coord_Point2, coord_Point3); - //check if 4. point lies within the plane + // check if 4. point lies within the plane if (this->PlaneEquation->CheckIfPointInPlane(coord_Point4) == false) return false; - //Calculate gravity centre of the face - //the order of the point was changed to calculate the correct gravity centre - if (this->Calculate_FaceGravityCentre(coord_Point1, coord_Point2, coord_Point4, - coord_Point3) == false) + // Calculate gravity centre of the face + // the order of the point was changed to calculate the correct gravity centre + if (this->Calculate_FaceGravityCentre(coord_Point1, coord_Point2, coord_Point4, coord_Point3) == false) return false; return true; diff --git a/MSH/msh_faces.h b/MSH/msh_faces.h index 55be36f17..ed6603eed 100644 --- a/MSH/msh_faces.h +++ b/MSH/msh_faces.h @@ -25,12 +25,9 @@ class CPlaneEquation CPlaneEquation(); ~CPlaneEquation(); - void CalculatePlaneEquationFrom3Points(const double Point1[3], - const double Point2[3], - const double Point3[3]); - - double* GetNormalVector() {return normal_vector; } + void CalculatePlaneEquationFrom3Points(const double Point1[3], const double Point2[3], const double Point3[3]); + double* GetNormalVector() { return normal_vector; } bool CheckIfPointInPlane(const double Point[3]); }; @@ -39,10 +36,13 @@ class CFlowData public: double q[3]; double q_norm; - CFlowData() {q_norm = 0; - q[0] = 0; - q[1] = 0; - q[2] = 0; } + CFlowData() + { + q_norm = 0; + q[0] = 0; + q[1] = 0; + q[2] = 0; + } ~CFlowData() {} }; @@ -52,20 +52,20 @@ class CFaces // necessary for coupling with Eclipse private: double gravity_centre[3]; long nnodes; - std::vector connected_nodes; + std::vector connected_nodes; public: CPlaneEquation* PlaneEquation; long index; - std::vector connected_elements; + std::vector connected_elements; std::string model_axis; - //double q[3]; - //double q_norm; + // double q[3]; + // double q_norm; double v_norm; double vel[3]; - std::vector phases; + std::vector phases; double face_area; @@ -77,19 +77,12 @@ class CFaces // necessary for coupling with Eclipse const double Point3[3], const double Point4[3]); - double* GetFaceGravityCentre() {return gravity_centre; } - - void SetNodes(MeshLib::CNode* Point1, - MeshLib::CNode* Point2, - MeshLib::CNode* Point3, - MeshLib::CNode* Point4); + double* GetFaceGravityCentre() { return gravity_centre; } + void SetNodes(MeshLib::CNode* Point1, MeshLib::CNode* Point2, MeshLib::CNode* Point3, MeshLib::CNode* Point4); - void SetElements(std::vector element_indices); + void SetElements(std::vector element_indices); - bool CreateFace(MeshLib::CNode* Point1, - MeshLib::CNode* Point2, - MeshLib::CNode* Point3, - MeshLib::CNode* Point4); + bool CreateFace(MeshLib::CNode* Point1, MeshLib::CNode* Point2, MeshLib::CNode* Point3, MeshLib::CNode* Point4); void Calculate_components_of_a_vector(int flag, int phase_index, bool Radialmodell); }; diff --git a/MSH/msh_lib.cpp b/MSH/msh_lib.cpp index 420777a7e..8f7eecb66 100644 --- a/MSH/msh_lib.cpp +++ b/MSH/msh_lib.cpp @@ -28,23 +28,23 @@ #include "msh_lib.h" // PCSLib #include "mathlib.h" -#include "rf_mmp_new.h" //OK411 +#include "rf_mmp_new.h" //OK411 // WW extern void RFConfigRenumber(void); -#ifndef NEW_EQS //WW. 07.11.2008 +#ifndef NEW_EQS // WW. 07.11.2008 extern void ConfigRenumberProperties(void); #endif extern int ReadRFIFile(std::string g_strFileNameBase); #include "rf_pcs.h" -std::vectorfem_msh_vector; +std::vector fem_msh_vector; #define FEM_FILE_EXTENSION ".msh" -//KR double msh_x_min,msh_x_max; //OK -//KR double msh_y_min,msh_y_max; //OK -//KR double msh_z_min,msh_z_max; //OK -//KR double msh_x_mid,msh_y_mid,msh_z_mid; //OK +// KR double msh_x_min,msh_x_max; //OK +// KR double msh_y_min,msh_y_max; //OK +// KR double msh_z_min,msh_z_max; //OK +// KR double msh_x_mid,msh_y_mid,msh_z_mid; //OK //#define MSH_SIZE 1e5 @@ -60,10 +60,10 @@ void MSHDelete(std::string m_msh_name) { CFEMesh* m_fem_msh = NULL; size_t fem_msh_vector_size = fem_msh_vector.size(); - for(size_t i = 0; i < fem_msh_vector_size; i++) + for (size_t i = 0; i < fem_msh_vector_size; i++) { m_fem_msh = fem_msh_vector[i]; - if(m_fem_msh->pcs_name.compare(m_msh_name) == 0) + if (m_fem_msh->pcs_name.compare(m_msh_name) == 0) { delete m_fem_msh; fem_msh_vector.erase((fem_msh_vector.begin() + i)); @@ -79,7 +79,7 @@ void MSHDelete(std::string m_msh_name) **************************************************************************/ void FEMDeleteAll() { - for(int i = 0; i < (int)fem_msh_vector.size(); i++) + for (int i = 0; i < (int)fem_msh_vector.size(); i++) { delete fem_msh_vector[i]; fem_msh_vector[i] = NULL; @@ -100,48 +100,49 @@ void FEMDeleteAll() 08/2011 WW Recovery multi-mesh 09/2011 TF changed signature of function in order to read more than one mesh **************************************************************************/ -void FEMRead(const std::string &file_base_name, - std::vector& mesh_vec, GEOLIB::GEOObjects* geo_obj, std::string* unique_name) +void FEMRead(const std::string& file_base_name, std::vector& mesh_vec, GEOLIB::GEOObjects* geo_obj, + std::string* unique_name) { - CFEMesh* mesh (NULL); - std::string msh_file_name (file_base_name + FEM_FILE_EXTENSION); + CFEMesh* mesh(NULL); + std::string msh_file_name(file_base_name + FEM_FILE_EXTENSION); - std::ifstream msh_file_ascii (msh_file_name.data(),std::ios::in); + std::ifstream msh_file_ascii(msh_file_name.data(), std::ios::in); if (!msh_file_ascii.is_open()) std::cout << "CFEMesh::FEMRead() - Could not open file...\n"; - std::cout << "MSHRead: ASCII file" << "\n"; - std::string line_string (""); + std::cout << "MSHRead: ASCII file" + << "\n"; + std::string line_string(""); getline(msh_file_ascii, line_string); - bool more_mesh = false; //12.08.2011. WW - if(line_string.find("#FEM_MSH") != std::string::npos) // OGS mesh file + bool more_mesh = false; // 12.08.2011. WW + if (line_string.find("#FEM_MSH") != std::string::npos) // OGS mesh file { mesh = new CFEMesh(geo_obj, unique_name); more_mesh = mesh->Read(&msh_file_ascii); mesh_vec.push_back(mesh); // TF - //Multi-mesh 12.08.2011 WW - if(more_mesh) - while(!msh_file_ascii.eof()) + // Multi-mesh 12.08.2011 WW + if (more_mesh) + while (!msh_file_ascii.eof()) { - //getline(msh_file_ascii, line_string); + // getline(msh_file_ascii, line_string); // if(line_string.find("#FEM_MSH")!=std::string::npos) mesh = new CFEMesh(geo_obj, unique_name); more_mesh = mesh->Read(&msh_file_ascii); mesh_vec.push_back(mesh); // TF - if(!more_mesh) + if (!more_mesh) break; } - // if(line_string.find("#STOP")!=std::string::npos) - // break; + // if(line_string.find("#STOP")!=std::string::npos) + // break; } else // RFI mesh file { - msh_file_ascii.seekg(0L,std::ios::beg); + msh_file_ascii.seekg(0L, std::ios::beg); mesh = new CFEMesh(geo_obj, unique_name); Read_RFI(msh_file_ascii, mesh); - mesh_vec.push_back(mesh); //12.08.2011 WW + mesh_vec.push_back(mesh); // 12.08.2011 WW } msh_file_ascii.close(); @@ -154,14 +155,14 @@ void FEMRead(const std::string &file_base_name, Programing: 08/2005 WW Re-implememtation **************************************************************************/ -void Read_RFI(std::istream& msh_file,CFEMesh* m_msh) +void Read_RFI(std::istream& msh_file, CFEMesh* m_msh) { long id; long i = 0; int NumNodes = 0; int NumElements = 0; int End = 1; - double x,y,z; + double x, y, z; std::string strbuffer; MeshLib::CNode* node = NULL; @@ -169,17 +170,17 @@ void Read_RFI(std::istream& msh_file,CFEMesh* m_msh) //---------------------------------------------------------------------- while (End) { - getline(msh_file, strbuffer); // The first line + getline(msh_file, strbuffer); // The first line msh_file >> i >> NumNodes >> NumElements >> std::ws; //.................................................................... // Node data - for(i = 0; i < NumNodes; i++) + for (i = 0; i < NumNodes; i++) { msh_file >> id >> x >> y >> z >> std::ws; - node = new MeshLib::CNode(id,x,y,z); + node = new MeshLib::CNode(id, x, y, z); m_msh->nod_vector.push_back(node); } - for(i = 0; i < NumElements; i++) + for (i = 0; i < NumElements; i++) { elem = new MeshLib::CElem(i); elem->Read(msh_file, 1); @@ -195,7 +196,7 @@ void Read_RFI(std::istream& msh_file,CFEMesh* m_msh) **************************************************************************/ void CompleteMesh() { - for(int i = 0; i < (int)fem_msh_vector.size(); i++) + for (int i = 0; i < (int)fem_msh_vector.size(); i++) { fem_msh_vector[i]->ConstructGrid(); fem_msh_vector[i]->FillTransformMatrix(); @@ -215,12 +216,12 @@ void MSHWrite(std::string file_base_name) { // File handling std::string fem_msh_file_name = file_base_name + FEM_FILE_EXTENSION; - std::ofstream fem_msh_file (fem_msh_file_name.c_str(),std::ios::trunc | std::ios::out); + std::ofstream fem_msh_file(fem_msh_file_name.c_str(), std::ios::trunc | std::ios::out); - if(!fem_msh_file.good()) + if (!fem_msh_file.good()) return; - for(size_t i = 0; i < fem_msh_vector.size(); i++) + for (size_t i = 0; i < fem_msh_vector.size(); i++) { FileIO::OGSMeshIO meshIO; meshIO.setPrecision(12); @@ -239,14 +240,14 @@ void MSHWrite(std::string file_base_name) 03/2005 OK Implementation last modification: **************************************************************************/ -MeshLib::CFEMesh* FEMGet(const std::string &msh_name) +MeshLib::CFEMesh* FEMGet(const std::string& msh_name) { size_t no_msh = fem_msh_vector.size(); // If there is only one msh file available, use it for all process. WW if (no_msh == 1) - return fem_msh_vector[0]; //WW - for(size_t i = 0; i < no_msh; i++) - if ( fem_msh_vector[i]->pcs_name.compare(msh_name) == 0 ) + return fem_msh_vector[0]; // WW + for (size_t i = 0; i < no_msh; i++) + if (fem_msh_vector[i]->pcs_name.compare(msh_name) == 0) return fem_msh_vector[i]; return NULL; } @@ -302,7 +303,7 @@ MeshLib::CFEMesh* FEMGet(const std::string &msh_name) } */ -#ifdef ObsoleteGUI //WW 03.2012 +#ifdef ObsoleteGUI // WW 03.2012 /************************************************************************** GeoLib-Method: Task: @@ -314,19 +315,19 @@ MeshLib::CFEMesh* FEMGet(const std::string &msh_name) **************************************************************************/ void MSHWriteVOL2TEC(std::string m_msh_name) { - long i,j; + long i, j; CGLVolume* m_vol = NULL; std::vector::const_iterator p_vol; std::string name("VOLUMES"); std::vector::const_iterator p_sfc; - double x,y,z; + double x, y, z; // CGLPoint m_point; // TF std::ios::pos_type position; int vol_number = -1; Surface* m_sfc = NULL; //-------------------------------------------------------------------- - MeshLib::CFEMesh* m_msh (FEMGet(m_msh_name)); - if(!m_msh) + MeshLib::CFEMesh* m_msh(FEMGet(m_msh_name)); + if (!m_msh) return; long no_nodes = (long)m_msh->nod_vector.size(); long ep_layer = (long)m_msh->ele_vector.size() / m_msh->getNumberOfMeshLayers(); @@ -334,21 +335,21 @@ void MSHWriteVOL2TEC(std::string m_msh_name) // File handling std::string tec_path; CGSProject* m_gsp = GSPGetMember("gli"); - if(m_gsp) + if (m_gsp) tec_path = m_gsp->path; //====================================================================== p_vol = volume_vector.begin(); - while(p_vol != volume_vector.end()) + while (p_vol != volume_vector.end()) { m_vol = *p_vol; - if(m_vol->layer == 0) //OK + if (m_vol->layer == 0) // OK { p_vol++; continue; } p_sfc = m_vol->surface_vector.begin(); m_sfc = *p_sfc; - if(!m_sfc) + if (!m_sfc) return; //-------------------------------------------------------------------- long jb = (m_vol->layer - 1) * ep_layer; @@ -357,32 +358,32 @@ void MSHWriteVOL2TEC(std::string m_msh_name) //-------------------------------------------------------------------- // file handling std::string vol_file_name = tec_path + "VOL_" + m_vol->name + TEC_FILE_EXTENSION; - std::fstream vol_file (vol_file_name.data(),std::ios::trunc | std::ios::out); - vol_file.setf(std::ios::scientific,std::ios::floatfield); + std::fstream vol_file(vol_file_name.data(), std::ios::trunc | std::ios::out); + vol_file.setf(std::ios::scientific, std::ios::floatfield); vol_file.precision(12); if (!vol_file.good()) return; - vol_file.seekg(0L,std::ios::beg); + vol_file.seekg(0L, std::ios::beg); //-------------------------------------------------------------------- - vol_file << "VARIABLES = X,Y,Z,VOL" << "\n"; + vol_file << "VARIABLES = X,Y,Z,VOL" + << "\n"; //-------------------------------------------------------------------- long no_mat_elements = 0; MeshLib::CElem* m_ele = NULL; - vecnode_indeces(6); - for(i = jb; i < je; i++) + vec node_indeces(6); + for (i = jb; i < je; i++) { m_ele = m_msh->ele_vector[i]; if (m_ele->GetElementType() == MshElemType::PRISM) { m_ele->GetNodeIndeces(node_indeces); - //nodes = m_msh->ele_vector[i]->nodes; + // nodes = m_msh->ele_vector[i]->nodes; x = 0.0; y = 0.0; z = 0.0; - for(j = 0; j < 6; j++) + for (j = 0; j < 6; j++) { - double const* const pnt ( - m_msh->nod_vector[node_indeces[j]]->getData()); + double const* const pnt(m_msh->nod_vector[node_indeces[j]]->getData()); x += pnt[0]; y += pnt[1]; z += pnt[2]; @@ -401,29 +402,30 @@ void MSHWriteVOL2TEC(std::string m_msh_name) } //-------------------------------------------------------------------- position = vol_file.tellg(); - vol_file << "ZONE T = " << m_vol->name << ", " \ - << "N = " << no_nodes << ", " \ - << "E = " << no_mat_elements << ", " \ - << "F = FEPOINT" << ", " << "ET = BRICK" << "\n"; - for(i = 0; i < no_nodes; i++) + vol_file << "ZONE T = " << m_vol->name << ", " + << "N = " << no_nodes << ", " + << "E = " << no_mat_elements << ", " + << "F = FEPOINT" + << ", " + << "ET = BRICK" + << "\n"; + for (i = 0; i < no_nodes; i++) { double const* const pnt_i(m_msh->nod_vector[i]->getData()); - vol_file << pnt_i[0] << " " << pnt_i[1] << " " << pnt_i[2] << " " << - vol_number << "\n"; + vol_file << pnt_i[0] << " " << pnt_i[1] << " " << pnt_i[2] << " " << vol_number << "\n"; } - for(long i = jb; i < je; i++) + for (long i = jb; i < je; i++) { m_ele = m_msh->ele_vector[i]; - if(m_ele->GetElementType() == MshElemType::PRISM) + if (m_ele->GetElementType() == MshElemType::PRISM) { m_ele->GetNodeIndeces(node_indeces); x = 0.0; y = 0.0; z = 0.0; - for(j = 0; j < 6; j++) + for (j = 0; j < 6; j++) { - double const* const pnt_j( - m_msh->nod_vector[node_indeces[j]]->getData()); + double const* const pnt_j(m_msh->nod_vector[node_indeces[j]]->getData()); x += pnt_j[0]; y += pnt_j[1]; z += pnt_j[2]; @@ -437,8 +439,10 @@ void MSHWriteVOL2TEC(std::string m_msh_name) // m_point.z = z; // if(m_sfc->PointInSurface(&m_point)){ // vol_file - // << node_indeces[0]+1 << " " << node_indeces[0]+1 << " " << node_indeces[1]+1 << " " << node_indeces[2]+1 << " " - // << node_indeces[3]+1 << " " << node_indeces[3]+1 << " " << node_indeces[4]+1 << " " << node_indeces[5]+1 << "\n"; + // << node_indeces[0]+1 << " " << node_indeces[0]+1 << " " << node_indeces[1]+1 << " " << + // node_indeces[2]+1 << " " + // << node_indeces[3]+1 << " " << node_indeces[3]+1 << " " << node_indeces[4]+1 << " " << + // node_indeces[5]+1 << "\n"; // } } } @@ -456,7 +460,7 @@ void MSHWriteVOL2TEC(std::string m_msh_name) void MSHLayerWriteTecplot() { MshElemType::type ele_type = MshElemType::INVALID; - //WW long no_nodes; + // WW long no_nodes; long no_elements; std::string delimiter(", "); MeshLib::CElem* m_ele = NULL; @@ -472,16 +476,15 @@ void MSHLayerWriteTecplot() file_path = m_gsp->path; //---------------------------------------------------------------------- MeshLib::CFEMesh* m_msh = NULL; - for (int j = 0; j < (int) fem_msh_vector.size(); j++) + for (int j = 0; j < (int)fem_msh_vector.size(); j++) { m_msh = fem_msh_vector[j]; for (size_t k = 0; k < m_msh->getNumberOfMeshLayers(); k++) { sprintf(no_layer_char, "%lu", static_cast(k) + 1); no_layer_str = no_layer_char; - //WW no_nodes = (long) m_msh->nod_vector.size() / (m_msh->getNumberOfMeshLayers() + 1); - no_elements = (long) m_msh->ele_vector.size() / - m_msh->getNumberOfMeshLayers(); + // WW no_nodes = (long) m_msh->nod_vector.size() / (m_msh->getNumberOfMeshLayers() + 1); + no_elements = (long)m_msh->ele_vector.size() / m_msh->getNumberOfMeshLayers(); // Test ele_type if (no_elements > 0) { @@ -489,331 +492,314 @@ void MSHLayerWriteTecplot() ele_type = m_ele->GetElementType(); } // File handling - std::string msh_file_name = file_path + "MSH_LAYER" + no_layer_str + "_" - + m_msh->pcs_name + TEC_FILE_EXTENSION; + std::string msh_file_name + = file_path + "MSH_LAYER" + no_layer_str + "_" + m_msh->pcs_name + TEC_FILE_EXTENSION; std::fstream msh_file(msh_file_name.data(), std::ios::trunc | std::ios::out); msh_file.setf(std::ios::scientific, std::ios::floatfield); msh_file.precision(12); if (!msh_file.good()) return; msh_file.seekg(0L, std::ios::beg); - msh_file << "VARIABLES = X,Y,Z" << "\n"; - msh_file << "ZONE T = " << m_msh->pcs_name << delimiter << "N = " - << (long) m_msh->nod_vector.size() << delimiter << "E = " - << no_elements << delimiter; + msh_file << "VARIABLES = X,Y,Z" + << "\n"; + msh_file << "ZONE T = " << m_msh->pcs_name << delimiter << "N = " << (long)m_msh->nod_vector.size() + << delimiter << "E = " << no_elements << delimiter; msh_file << "F = FEPOINT" << delimiter; switch (ele_type) { + //.................................................................. + case MshElemType::LINE: + msh_file << "ET = QUADRILATERAL" + << "\n"; + for (size_t i = 0; i < m_msh->nod_vector.size(); i++) + { + double const* const pnt_i(m_msh->nod_vector[i]->getData()); + msh_file << pnt_i[0] << " " << pnt_i[1] << " " << pnt_i[2] << "\n"; + } + for (size_t i = k * no_elements; i < (k + 1) * no_elements; i++) + { + m_ele = m_msh->ele_vector[i]; + m_ele->GetNodeIndeces(node_indeces); + msh_file << node_indeces[0] + 1 << " " << node_indeces[1] + 1 << " " << node_indeces[1] + 1 + << " " << node_indeces[0] + 1 << "\n"; + } + break; + //.................................................................. + case MshElemType::QUAD: + msh_file << "ET = QUADRILATERAL" + << "\n"; + for (size_t i = 0; i < m_msh->nod_vector.size(); i++) + { + double const* const pnt_i(m_msh->nod_vector[i]->getData()); + msh_file << pnt_i[0] << " " << pnt_i[1] << " " << pnt_i[2] << "\n"; + } + for (size_t i = k * no_elements; i < (k + 1) * no_elements; i++) + { + m_ele = m_msh->ele_vector[i]; + m_ele->GetNodeIndeces(node_indeces); + msh_file << node_indeces[0] + 1 << " " << node_indeces[1] + 1 << " " << node_indeces[2] + 1 + << " " << node_indeces[3] + 1 << "\n"; + } + break; + //.................................................................. + case MshElemType::HEXAHEDRON: + msh_file << "ET = BRICK" + << "\n"; + for (size_t i = 0; i < m_msh->nod_vector.size(); i++) + { + double const* const pnt_i(m_msh->nod_vector[i]->getData()); + msh_file << pnt_i[0] << " " << pnt_i[1] << " " << pnt_i[2] << "\n"; + } + for (size_t i = k * no_elements; i < (k + 1) * no_elements; i++) + { + m_ele = m_msh->ele_vector[i]; + m_ele->GetNodeIndeces(node_indeces); + msh_file << node_indeces[0] + 1 << " " << node_indeces[1] + 1 << " " << node_indeces[2] + 1 + << " " << node_indeces[3] + 1 << " " << node_indeces[4] + 1 << " " + << node_indeces[5] + 1 << " " << node_indeces[6] + 1 << " " << node_indeces[7] + 1 + << "\n"; + } + break; + //.................................................................. + case MshElemType::TRIANGLE: + msh_file << "ET = TRIANGLE" + << "\n"; + for (size_t i = 0; i < m_msh->nod_vector.size(); i++) + { + double const* const pnt_i(m_msh->nod_vector[i]->getData()); + msh_file << pnt_i[0] << " " << pnt_i[1] << " " << pnt_i[2] << "\n"; + } + for (size_t i = k * no_elements; i < (k + 1) * no_elements; i++) + { + m_ele = m_msh->ele_vector[i]; + m_ele->GetNodeIndeces(node_indeces); + msh_file << node_indeces[0] + 1 << " " << node_indeces[1] + 1 << " " << node_indeces[2] + 1 + << "\n"; + } + break; + //.................................................................. + case MshElemType::TETRAHEDRON: + msh_file << "ET = TETRAHEDRON" + << "\n"; + for (size_t i = 0; i < m_msh->nod_vector.size(); i++) + { + double const* const pnt_i(m_msh->nod_vector[i]->getData()); + msh_file << pnt_i[0] << " " << pnt_i[1] << " " << pnt_i[2] << "\n"; + } + for (size_t i = k * no_elements; i < (k + 1) * no_elements; i++) + { + m_ele = m_msh->ele_vector[i]; + m_ele->GetNodeIndeces(node_indeces); + msh_file << node_indeces[0] + 1 << " " << node_indeces[1] + 1 << " " << node_indeces[2] + 1 + << " " << node_indeces[3] + 1 << "\n"; + } + break; + //.................................................................. + case MshElemType::PRISM: + msh_file << "ET = BRICK" + << "\n"; + for (size_t i = 0; i < m_msh->nod_vector.size(); i++) + { + double const* const pnt_i(m_msh->nod_vector[i]->getData()); + msh_file << pnt_i[0] << " " << pnt_i[1] << " " << pnt_i[2] << "\n"; + } + for (size_t i = k * no_elements; i < (k + 1) * no_elements; i++) + { + m_ele = m_msh->ele_vector[i]; + m_ele->GetNodeIndeces(node_indeces); + msh_file << node_indeces[0] + 1 << " " << node_indeces[1] + 1 << " " << node_indeces[2] + 1 + << " " << node_indeces[2] + 1 << " " << node_indeces[3] + 1 << " " + << node_indeces[4] + 1 << " " << node_indeces[5] + 1 << " " << node_indeces[5] + 1 + << "\n"; + } + break; + default: + std::cerr << "MSHLayerWriteTecplot MshElemType not handled" + << "\n"; + } + } // layer + } +} +#endif //#ifdef ObsoleteGUI //WW 03.2012 + +/************************************************************************** + GeoLib-Method: + Task: + Programing: + 04/2005 OK Implementation + 11/2005 OK OO-ELE +**************************************************************************/ +void MSHWriteTecplot() +{ + MshElemType::type ele_type = MshElemType::INVALID; + long no_nodes; + long no_elements; + std::string delimiter(", "); + long i; + MeshLib::CElem* m_ele = NULL; + vec node_indeces(8); + //---------------------------------------------------------------------- + // File handling + std::string file_path = "MSH"; + //---------------------------------------------------------------------- + MeshLib::CFEMesh* m_msh = NULL; + for (int j = 0; j < (int)fem_msh_vector.size(); j++) + { + m_msh = fem_msh_vector[j]; + no_nodes = (long)m_msh->nod_vector.size(); + no_elements = (long)m_msh->ele_vector.size(); + // Test ele_type + if (no_elements > 0) + { + m_ele = m_msh->ele_vector[0]; + ele_type = m_ele->GetElementType(); + } + // File handling + std::string msh_file_name = file_path + "_" + m_msh->pcs_name + TEC_FILE_EXTENSION; + std::fstream msh_file(msh_file_name.data(), std::ios::trunc | std::ios::out); + msh_file.setf(std::ios::scientific, std::ios::floatfield); + msh_file.precision(12); + if (!msh_file.good()) + return; + msh_file.seekg(0L, std::ios::beg); + msh_file << "VARIABLES = X,Y,Z" + << "\n"; + msh_file << "ZONE T = " << m_msh->pcs_name << delimiter << "N = " << no_nodes << delimiter + << "E = " << no_elements << delimiter; + msh_file << "F = FEPOINT" << delimiter; + switch (ele_type) + { //.................................................................. case MshElemType::LINE: - msh_file << "ET = QUADRILATERAL" << "\n"; - for (size_t i = 0; i < m_msh->nod_vector.size(); i++) + msh_file << "ET = QUADRILATERAL" + << "\n"; + for (i = 0; i < no_nodes; i++) { double const* const pnt_i(m_msh->nod_vector[i]->getData()); - msh_file << pnt_i[0] << " " << pnt_i[1] << " " << - pnt_i[2] << "\n"; + msh_file << pnt_i[0] << " " << pnt_i[1] << " " << pnt_i[2] << "\n"; } - for (size_t i = k * no_elements; i < (k + 1) * no_elements; i++) + for (i = 0; i < no_elements; i++) { m_ele = m_msh->ele_vector[i]; m_ele->GetNodeIndeces(node_indeces); - msh_file << node_indeces[0] + 1 << " " << node_indeces[1] - + 1 << " " << node_indeces[1] + 1 << " " + msh_file << node_indeces[0] + 1 << " " << node_indeces[1] + 1 << " " << node_indeces[1] + 1 << " " << node_indeces[0] + 1 << "\n"; } break; //.................................................................. case MshElemType::QUAD: - msh_file << "ET = QUADRILATERAL" << "\n"; - for (size_t i = 0; i < m_msh->nod_vector.size(); i++) + msh_file << "ET = QUADRILATERAL" + << "\n"; + for (i = 0; i < no_nodes; i++) { double const* const pnt_i(m_msh->nod_vector[i]->getData()); - msh_file << pnt_i[0] << " " << pnt_i[1] << " " << - pnt_i[2] << "\n"; + msh_file << pnt_i[0] << " " << pnt_i[1] << " " << pnt_i[2] << "\n"; } - for (size_t i = k * no_elements; i < (k + 1) * no_elements; i++) + for (i = 0; i < no_elements; i++) { m_ele = m_msh->ele_vector[i]; m_ele->GetNodeIndeces(node_indeces); - msh_file << node_indeces[0] + 1 << " " << node_indeces[1] - + 1 << " " << node_indeces[2] + 1 << " " + msh_file << node_indeces[0] + 1 << " " << node_indeces[1] + 1 << " " << node_indeces[2] + 1 << " " << node_indeces[3] + 1 << "\n"; } break; //.................................................................. case MshElemType::HEXAHEDRON: - msh_file << "ET = BRICK" << "\n"; - for (size_t i = 0; i < m_msh->nod_vector.size(); i++) + msh_file << "ET = BRICK" + << "\n"; + for (i = 0; i < no_nodes; i++) { double const* const pnt_i(m_msh->nod_vector[i]->getData()); - msh_file << pnt_i[0] << " " << pnt_i[1] << " " << - pnt_i[2] << "\n"; + msh_file << pnt_i[0] << " " << pnt_i[1] << " " << pnt_i[2] << "\n"; } - for (size_t i = k * no_elements; i < (k + 1) * no_elements; i++) + for (i = 0; i < no_elements; i++) { m_ele = m_msh->ele_vector[i]; m_ele->GetNodeIndeces(node_indeces); - msh_file << node_indeces[0] + 1 << " " << node_indeces[1] - + 1 << " " << node_indeces[2] + 1 << " " - << node_indeces[3] + 1 << " " << node_indeces[4] - + 1 << " " << node_indeces[5] + 1 << " " - << node_indeces[6] + 1 << " " << node_indeces[7] - + 1 << "\n"; + msh_file << node_indeces[0] + 1 << " " << node_indeces[1] + 1 << " " << node_indeces[2] + 1 << " " + << node_indeces[3] + 1 << " " << node_indeces[4] + 1 << " " << node_indeces[5] + 1 << " " + << node_indeces[6] + 1 << " " << node_indeces[7] + 1 << "\n"; } break; //.................................................................. case MshElemType::TRIANGLE: - msh_file << "ET = TRIANGLE" << "\n"; - for (size_t i = 0; i < m_msh->nod_vector.size(); i++) + msh_file << "ET = TRIANGLE" + << "\n"; + for (i = 0; i < no_nodes; i++) { double const* const pnt_i(m_msh->nod_vector[i]->getData()); - msh_file << pnt_i[0] << " " << pnt_i[1] << " " << - pnt_i[2] << "\n"; + msh_file << pnt_i[0] << " " << pnt_i[1] << " " << pnt_i[2] << "\n"; } - for (size_t i = k * no_elements; i < (k + 1) * no_elements; i++) + for (i = 0; i < no_elements; i++) { m_ele = m_msh->ele_vector[i]; m_ele->GetNodeIndeces(node_indeces); - msh_file << node_indeces[0] + 1 << " " << node_indeces[1] - + 1 << " " << node_indeces[2] + 1 << "\n"; + msh_file << node_indeces[0] + 1 << " " << node_indeces[1] + 1 << " " << node_indeces[2] + 1 << "\n"; } break; //.................................................................. case MshElemType::TETRAHEDRON: - msh_file << "ET = TETRAHEDRON" << "\n"; - for (size_t i = 0; i < m_msh->nod_vector.size(); i++) + msh_file << "ET = TETRAHEDRON" + << "\n"; + for (i = 0; i < no_nodes; i++) { double const* const pnt_i(m_msh->nod_vector[i]->getData()); - msh_file << pnt_i[0] << " " << pnt_i[1] << " " << - pnt_i[2] << "\n"; + msh_file << pnt_i[0] << " " << pnt_i[1] << " " << pnt_i[2] << "\n"; } - for (size_t i = k * no_elements; i < (k + 1) * no_elements; i++) + for (i = 0; i < no_elements; i++) { m_ele = m_msh->ele_vector[i]; m_ele->GetNodeIndeces(node_indeces); - msh_file << node_indeces[0] + 1 << " " << node_indeces[1] - + 1 << " " << node_indeces[2] + 1 << " " + msh_file << node_indeces[0] + 1 << " " << node_indeces[1] + 1 << " " << node_indeces[2] + 1 << " " << node_indeces[3] + 1 << "\n"; } break; //.................................................................. case MshElemType::PRISM: - msh_file << "ET = BRICK" << "\n"; - for (size_t i = 0; i < m_msh->nod_vector.size(); i++) + msh_file << "ET = BRICK" + << "\n"; + for (i = 0; i < no_nodes; i++) { double const* const pnt_i(m_msh->nod_vector[i]->getData()); - msh_file << pnt_i[0] << " " << pnt_i[1] << " " << - pnt_i[2] << "\n"; + msh_file << pnt_i[0] << " " << pnt_i[1] << " " << pnt_i[2] << "\n"; } - for (size_t i = k * no_elements; i < (k + 1) * no_elements; i++) + for (i = 0; i < no_elements; i++) { m_ele = m_msh->ele_vector[i]; m_ele->GetNodeIndeces(node_indeces); - msh_file << node_indeces[0] + 1 << " " << node_indeces[1] - + 1 << " " << node_indeces[2] + 1 << " " - << node_indeces[2] + 1 << " " << node_indeces[3] - + 1 << " " << node_indeces[4] + 1 << " " - << node_indeces[5] + 1 << " " << node_indeces[5] - + 1 << "\n"; + if (m_ele->GetElementType() == MshElemType::PRISM) + msh_file << node_indeces[0] + 1 << " " << node_indeces[1] + 1 << " " << node_indeces[2] + 1 + << " " << node_indeces[2] + 1 << " " << node_indeces[3] + 1 << " " + << node_indeces[4] + 1 << " " << node_indeces[5] + 1 << " " << node_indeces[5] + 1 + << "\n"; + if (m_ele->GetElementType() == MshElemType::HEXAHEDRON) + msh_file << node_indeces[0] + 1 << " " << node_indeces[1] + 1 << " " << node_indeces[2] + 1 + << " " << node_indeces[3] + 1 << " " << node_indeces[4] + 1 << " " + << node_indeces[5] + 1 << " " << node_indeces[6] + 1 << " " << node_indeces[7] + 1 + << "\n"; } break; default: - std::cerr << "MSHLayerWriteTecplot MshElemType not handled" << - "\n"; - } - } // layer - } -} -#endif //#ifdef ObsoleteGUI //WW 03.2012 - -/************************************************************************** - GeoLib-Method: - Task: - Programing: - 04/2005 OK Implementation - 11/2005 OK OO-ELE -**************************************************************************/ -void MSHWriteTecplot() -{ - MshElemType::type ele_type = MshElemType::INVALID; - long no_nodes; - long no_elements; - std::string delimiter(", "); - long i; - MeshLib::CElem* m_ele = NULL; - vec node_indeces(8); - //---------------------------------------------------------------------- - // File handling - std::string file_path = "MSH"; - //---------------------------------------------------------------------- - MeshLib::CFEMesh* m_msh = NULL; - for (int j = 0; j < (int) fem_msh_vector.size(); j++) - { - m_msh = fem_msh_vector[j]; - no_nodes = (long) m_msh->nod_vector.size(); - no_elements = (long) m_msh->ele_vector.size(); - // Test ele_type - if (no_elements > 0) - { - m_ele = m_msh->ele_vector[0]; - ele_type = m_ele->GetElementType(); - } - // File handling - std::string msh_file_name = file_path + "_" + m_msh->pcs_name - + TEC_FILE_EXTENSION; - std::fstream msh_file(msh_file_name.data(), std::ios::trunc | std::ios::out); - msh_file.setf(std::ios::scientific, std::ios::floatfield); - msh_file.precision(12); - if (!msh_file.good()) - return; - msh_file.seekg(0L, std::ios::beg); - msh_file << "VARIABLES = X,Y,Z" << "\n"; - msh_file << "ZONE T = " << m_msh->pcs_name << delimiter << "N = " - << no_nodes << delimiter << "E = " << no_elements << delimiter; - msh_file << "F = FEPOINT" << delimiter; - switch (ele_type) - { - //.................................................................. - case MshElemType::LINE: - msh_file << "ET = QUADRILATERAL" << "\n"; - for (i = 0; i < no_nodes; i++) - { - double const* const pnt_i(m_msh->nod_vector[i]->getData()); - msh_file << pnt_i[0] << " " << pnt_i[1] << " " << pnt_i[2] << - "\n"; - } - for (i = 0; i < no_elements; i++) - { - m_ele = m_msh->ele_vector[i]; - m_ele->GetNodeIndeces(node_indeces); - msh_file << node_indeces[0] + 1 << " " << node_indeces[1] + 1 - << " " << node_indeces[1] + 1 << " " << node_indeces[0] - + 1 << "\n"; - } - break; - //.................................................................. - case MshElemType::QUAD: - msh_file << "ET = QUADRILATERAL" << "\n"; - for (i = 0; i < no_nodes; i++) - { - double const* const pnt_i(m_msh->nod_vector[i]->getData()); - msh_file << pnt_i[0] << " " << pnt_i[1] << " " << pnt_i[2] << - "\n"; - } - for (i = 0; i < no_elements; i++) - { - m_ele = m_msh->ele_vector[i]; - m_ele->GetNodeIndeces(node_indeces); - msh_file << node_indeces[0] + 1 << " " << node_indeces[1] + 1 - << " " << node_indeces[2] + 1 << " " << node_indeces[3] - + 1 << "\n"; - } - break; - //.................................................................. - case MshElemType::HEXAHEDRON: - msh_file << "ET = BRICK" << "\n"; - for (i = 0; i < no_nodes; i++) - { - double const* const pnt_i(m_msh->nod_vector[i]->getData()); - msh_file << pnt_i[0] << " " << pnt_i[1] << " " << pnt_i[2] << - "\n"; - } - for (i = 0; i < no_elements; i++) - { - m_ele = m_msh->ele_vector[i]; - m_ele->GetNodeIndeces(node_indeces); - msh_file << node_indeces[0] + 1 << " " << node_indeces[1] + 1 - << " " << node_indeces[2] + 1 << " " << node_indeces[3] - + 1 << " " << node_indeces[4] + 1 << " " - << node_indeces[5] + 1 << " " << node_indeces[6] + 1 - << " " << node_indeces[7] + 1 << "\n"; - } - break; - //.................................................................. - case MshElemType::TRIANGLE: - msh_file << "ET = TRIANGLE" << "\n"; - for (i = 0; i < no_nodes; i++) - { - double const* const pnt_i(m_msh->nod_vector[i]->getData()); - msh_file << pnt_i[0] << " " << pnt_i[1] << " " << pnt_i[2] << - "\n"; - } - for (i = 0; i < no_elements; i++) - { - m_ele = m_msh->ele_vector[i]; - m_ele->GetNodeIndeces(node_indeces); - msh_file << node_indeces[0] + 1 << " " << node_indeces[1] + 1 - << " " << node_indeces[2] + 1 << "\n"; - } - break; - //.................................................................. - case MshElemType::TETRAHEDRON: - msh_file << "ET = TETRAHEDRON" << "\n"; - for (i = 0; i < no_nodes; i++) - { - double const* const pnt_i(m_msh->nod_vector[i]->getData()); - msh_file << pnt_i[0] << " " << pnt_i[1] << " " << pnt_i[2] << - "\n"; - } - for (i = 0; i < no_elements; i++) - { - m_ele = m_msh->ele_vector[i]; - m_ele->GetNodeIndeces(node_indeces); - msh_file << node_indeces[0] + 1 << " " << node_indeces[1] + 1 - << " " << node_indeces[2] + 1 << " " << node_indeces[3] - + 1 << "\n"; - } - break; - //.................................................................. - case MshElemType::PRISM: - msh_file << "ET = BRICK" << "\n"; - for (i = 0; i < no_nodes; i++) - { - double const* const pnt_i(m_msh->nod_vector[i]->getData()); - msh_file << pnt_i[0] << " " << pnt_i[1] << " " << pnt_i[2] << - "\n"; - } - for (i = 0; i < no_elements; i++) - { - m_ele = m_msh->ele_vector[i]; - m_ele->GetNodeIndeces(node_indeces); - if (m_ele->GetElementType() == MshElemType::PRISM) - msh_file << node_indeces[0] + 1 << " " << node_indeces[1] - + 1 << " " << node_indeces[2] + 1 << " " - << node_indeces[2] + 1 << " " << node_indeces[3] - + 1 << " " << node_indeces[4] + 1 << " " - << node_indeces[5] + 1 << " " << node_indeces[5] - + 1 << "\n"; - if (m_ele->GetElementType() == MshElemType::HEXAHEDRON) - msh_file << node_indeces[0] + 1 << " " << node_indeces[1] - + 1 << " " << node_indeces[2] + 1 << " " - << node_indeces[3] + 1 << " " << node_indeces[4] - + 1 << " " << node_indeces[5] + 1 << " " - << node_indeces[6] + 1 << " " << node_indeces[7] - + 1 << "\n"; - } - break; - default: - std::cerr << "MSHWriteTecplot MshElemType not handled" << "\n"; + std::cerr << "MSHWriteTecplot MshElemType not handled" + << "\n"; } } } - /************************************************************************** MSHLib-Method: 12/2005 OK Implementation 07/2007 OK PCS **************************************************************************/ -MeshLib::CFEMesh* MSHGet(const std::string &geo_name) +MeshLib::CFEMesh* MSHGet(const std::string& geo_name) { MeshLib::CFEMesh* m_msh = NULL; - for(int i = 0; i < (int)fem_msh_vector.size(); i++) + for (int i = 0; i < (int)fem_msh_vector.size(); i++) { m_msh = fem_msh_vector[i]; - if(m_msh->geo_name.compare(geo_name) == 0) + if (m_msh->geo_name.compare(geo_name) == 0) return m_msh; - if(m_msh->pcs_name.compare(geo_name) == 0) + if (m_msh->pcs_name.compare(geo_name) == 0) return m_msh; } return NULL; @@ -825,14 +811,13 @@ MeshLib::CFEMesh* MSHGet(const std::string &geo_name) Programing: 12/2005 OK Implementation **************************************************************************/ -MeshLib::CFEMesh* MSHGet(const std::string &pcs_type_name,const std::string &geo_name) +MeshLib::CFEMesh* MSHGet(const std::string& pcs_type_name, const std::string& geo_name) { MeshLib::CFEMesh* m_msh = NULL; - for(int i = 0; i < (int)fem_msh_vector.size(); i++) + for (int i = 0; i < (int)fem_msh_vector.size(); i++) { m_msh = fem_msh_vector[i]; - if((m_msh->pcs_name.compare(pcs_type_name) == 0) && \ - (m_msh->geo_name.compare(geo_name) == 0)) \ + if ((m_msh->pcs_name.compare(pcs_type_name) == 0) && (m_msh->geo_name.compare(geo_name) == 0)) return m_msh; } return NULL; @@ -847,13 +832,13 @@ MeshLib::CFEMesh* MSHGetGEO(std::string geo_name) int no_msh = (int)fem_msh_vector.size(); // If there is only one msh file available, use it for all process. WW if (no_msh == 1) - return fem_msh_vector[0]; //WW + return fem_msh_vector[0]; // WW //---------------------------------------------------------------------- MeshLib::CFEMesh* m_msh = NULL; - for(int i = 0; i < no_msh; i++) + for (int i = 0; i < no_msh; i++) { m_msh = fem_msh_vector[i]; - if(m_msh->geo_name.compare(geo_name) == 0) + if (m_msh->geo_name.compare(geo_name) == 0) return m_msh; } //---------------------------------------------------------------------- @@ -867,8 +852,8 @@ MeshLib::CFEMesh* MSHGetGEO(std::string geo_name) bool CompleteMesh(std::string pcs_name) { bool succeed = false; - for(int i = 0; i < (int)fem_msh_vector.size(); i++) - if(fem_msh_vector[i]->pcs_name.compare(pcs_name) == 0) + for (int i = 0; i < (int)fem_msh_vector.size(); i++) + if (fem_msh_vector[i]->pcs_name.compare(pcs_name) == 0) { fem_msh_vector[i]->ConstructGrid(); fem_msh_vector[i]->FillTransformMatrix(); @@ -894,10 +879,10 @@ bool CompleteMesh(std::string pcs_name) 08/2005 MB */ /**************************************************************************/ -long MSHGetNextNode (long startnode, MeshLib::CFEMesh* m_msh) +long MSHGetNextNode(long startnode, MeshLib::CFEMesh* m_msh) { - size_t NumberOfNodes (m_msh->nod_vector.size()); - long NumberOfNodesPerLayer = NumberOfNodes / (m_msh->getNumberOfMeshLayers () + 1); + size_t NumberOfNodes(m_msh->nod_vector.size()); + long NumberOfNodesPerLayer = NumberOfNodes / (m_msh->getNumberOfMeshLayers() + 1); return startnode + NumberOfNodesPerLayer; } @@ -920,11 +905,10 @@ long MSHGetNextNode (long startnode, MeshLib::CFEMesh* m_msh) 08/2005 MB msh */ /**************************************************************************/ -void MSHSelectFreeSurfaceNodes (MeshLib::CFEMesh* m_msh) +void MSHSelectFreeSurfaceNodes(MeshLib::CFEMesh* m_msh) { // Number of nodes per node layer - size_t NumberOfNodesPerLayer = m_msh->nod_vector.size() - / (m_msh->getNumberOfMeshLayers() + 1); + size_t NumberOfNodesPerLayer = m_msh->nod_vector.size() / (m_msh->getNumberOfMeshLayers() + 1); size_t no_unconfined_layer = 0; // create array with nodes in vertical column size_t* strang(new size_t[m_msh->getNumberOfMeshLayers()]); @@ -948,7 +932,7 @@ void MSHSelectFreeSurfaceNodes (MeshLib::CFEMesh* m_msh) else continue; } - } //endif free_surface==4 + } // endif free_surface==4 // mark start of vertical column with 1 - end of column with 2 // this is than used in MSHMoveNODUcFlow @@ -975,66 +959,66 @@ void MSHDefineMobile(CRFProcess* m_pcs) // Define mobile MSH nodes //---------------------------------------------------------------------- // MMP Groups - if(mmp_vector.size() == 0) + if (mmp_vector.size() == 0) return; ////Schleife �ber alle Gruppen - for(size_t i = 0; i < mmp_vector.size(); i++) + for (size_t i = 0; i < mmp_vector.size(); i++) { - CMediumProperties const*const m_mat_mp (mmp_vector[i]); + CMediumProperties const* const m_mat_mp(mmp_vector[i]); - //WW int test = m_pcs->m_msh->GetMaxElementDim(); - //m_pcs->m_msh->cross_section + // WW int test = m_pcs->m_msh->GetMaxElementDim(); + // m_pcs->m_msh->cross_section - //if (m_mat_mp->unconfined_flow_group ==1 && m_pcs->m_msh->GetMaxElementDim() == 3){ - if ((m_mat_mp->unconfined_flow_group == 1 && m_pcs->m_msh->GetMaxElementDim() == - 3) || m_pcs->m_msh->hasCrossSection()) + // if (m_mat_mp->unconfined_flow_group ==1 && m_pcs->m_msh->GetMaxElementDim() == 3){ + if ((m_mat_mp->unconfined_flow_group == 1 && m_pcs->m_msh->GetMaxElementDim() == 3) + || m_pcs->m_msh->hasCrossSection()) { - //if (m_mat_mp->unconfined_flow_group ==1){ - //if (m_pcs->m_msh->cross_section){ + // if (m_mat_mp->unconfined_flow_group ==1){ + // if (m_pcs->m_msh->cross_section){ //.................................................................... - //DOMAIN -// if(m_mat_mp->geo_type_name.find("DOMAIN") != std::string::npos) - if(m_mat_mp->getGeoType() == GEOLIB::GEODOMAIN) + // DOMAIN + // if(m_mat_mp->geo_type_name.find("DOMAIN") != std::string::npos) + if (m_mat_mp->getGeoType() == GEOLIB::GEODOMAIN) { - //CGLDomain *m_domain = NULL; - //m_domain = m_domain->Get(m_mat_mp->geo_name); - //mobile_nodes = m_domain->GetPointsIn(&no_mobile_nodes); - //ToDo einlesen von domains ???? - for(size_t nodes = 0; nodes < m_pcs->m_msh->nod_vector.size(); nodes++) + // CGLDomain *m_domain = NULL; + // m_domain = m_domain->Get(m_mat_mp->geo_name); + // mobile_nodes = m_domain->GetPointsIn(&no_mobile_nodes); + // ToDo einlesen von domains ???? + for (size_t nodes = 0; nodes < m_pcs->m_msh->nod_vector.size(); nodes++) { - mobile_nodes = (long*) Realloc(mobile_nodes,sizeof(long) * (nodes + 1)); + mobile_nodes = (long*)Realloc(mobile_nodes, sizeof(long) * (nodes + 1)); mobile_nodes[nodes] = nodes; } i = m_pcs->m_msh->nod_vector.size(); no_mobile_nodes = (long)m_pcs->m_msh->nod_vector.size(); } - //SURFACE -// if(m_mat_mp->geo_type_name.find("SURFACE") != std::string::npos) - if(m_mat_mp->getGeoType() == GEOLIB::SURFACE) + // SURFACE + // if(m_mat_mp->geo_type_name.find("SURFACE") != std::string::npos) + if (m_mat_mp->getGeoType() == GEOLIB::SURFACE) { Surface* m_surface = NULL; - //CC + // CC m_surface = GEOGetSFCByName(m_mat_mp->geo_name); - //CC - mobile_nodes = GetPointsIn(m_surface,&no_mobile_nodes); + // CC + mobile_nodes = GetPointsIn(m_surface, &no_mobile_nodes); } - //VOLUME -// if(m_mat_mp->geo_type_name.find("VOLUME") != std::string::npos) - if(m_mat_mp->getGeoType() == GEOLIB::VOLUME) + // VOLUME + // if(m_mat_mp->geo_type_name.find("VOLUME") != std::string::npos) + if (m_mat_mp->getGeoType() == GEOLIB::VOLUME) { - //WW CGLVolume *m_volume = NULL; - //CC 10/05 - //WW m_volume = GEOGetVOL(m_mat_mp->geo_name); - //ToDo TK - //OK411 mobile_nodes =GetPointsInVolume(m_volume,&no_mobile_nodes);//CC 10/05 + // WW CGLVolume *m_volume = NULL; + // CC 10/05 + // WW m_volume = GEOGetVOL(m_mat_mp->geo_name); + // ToDo TK + // OK411 mobile_nodes =GetPointsInVolume(m_volume,&no_mobile_nodes);//CC 10/05 } - } //end if unconfined flow group - } //end for mmp vector + } // end if unconfined flow group + } // end for mmp vector // Set mobile MSH nodes flag - for(long i = 0; i < no_mobile_nodes; i++) + for (long i = 0; i < no_mobile_nodes; i++) m_pcs->m_msh->nod_vector[i]->free_surface = 4; if (no_mobile_nodes > 0) @@ -1068,11 +1052,11 @@ long* MSHGetNodesInColumn(long nextnode, int anz_zeilen, MeshLib::CFEMesh* m_msh for (i = 0; i < anz_zeilen + 1; i++) { - strang = (long*) Realloc(strang,(i + 1) * sizeof(long)); + strang = (long*)Realloc(strang, (i + 1) * sizeof(long)); strang[i] = nextnode; startnode = nextnode; - //nextnode = MSHGetNextNode (startnode, direction); - nextnode = MSHGetNextNode (startnode, m_msh); + // nextnode = MSHGetNextNode (startnode, direction); + nextnode = MSHGetNextNode(startnode, m_msh); } return strang; } @@ -1095,7 +1079,7 @@ long* MSHGetNodesInColumn(long nextnode, int anz_zeilen, MeshLib::CFEMesh* m_msh 09/2004 MB PCS 08/2005 MB m_msh */ /**************************************************************************/ -void MSHMoveNODUcFlow (CRFProcess* m_pcs) +void MSHMoveNODUcFlow(CRFProcess* m_pcs) { long nextnode = -1; long startnode; @@ -1108,10 +1092,9 @@ void MSHMoveNODUcFlow (CRFProcess* m_pcs) int xxflag; int nidy; // Number of nodes per node layer - const size_t NumberOfNodesPerLayer ( - m_pcs->m_msh->nod_vector.size() / (m_pcs->m_msh->getNumberOfMeshLayers() + 1)); - double MinThickness = 1e-1; //OKMB - double z_bottom; //OKMB + const size_t NumberOfNodesPerLayer(m_pcs->m_msh->nod_vector.size() / (m_pcs->m_msh->getNumberOfMeshLayers() + 1)); + double MinThickness = 1e-1; // OKMB + double z_bottom; // OKMB for (size_t node = 0; node < NumberOfNodesPerLayer; node++) @@ -1124,12 +1107,12 @@ void MSHMoveNODUcFlow (CRFProcess* m_pcs) do { startnode = nextnode; - nextnode = MSHGetNextNode (startnode, m_pcs->m_msh); + nextnode = MSHGetNextNode(startnode, m_pcs->m_msh); /* Test2: Geh�rt der n�chste Knoten zu unterer Reihe ==> Abbruch */ if (m_pcs->m_msh->nod_vector[nextnode]->free_surface == 2) xxflag = 1; - anz_zeilen++; /* Anzahl der beweglichen Zeilen (ohne die feste untere Zeile) */ + anz_zeilen++; /* Anzahl der beweglichen Zeilen (ohne die feste untere Zeile) */ } while (xxflag != 1); /** Ende Z�hlen der Zeilen zwischen den oberen free surface node etc... und den Unteren **/ @@ -1142,17 +1125,17 @@ void MSHMoveNODUcFlow (CRFProcess* m_pcs) nidy = m_pcs->GetNodeValueIndex("HEAD") + 1; if (GetRFProcessDensityFlow()) /* mit Dichteunterschiede */ { - //OK_MOD head = MODCalcHeadInColumn_MB(strang, anz_zeilen); + // OK_MOD head = MODCalcHeadInColumn_MB(strang, anz_zeilen); } else /* ohne Dichteunterschiede */ - head = m_pcs->GetNodeValue(strang[0],nidy); + head = m_pcs->GetNodeValue(strang[0], nidy); /* nicht �ber surface elevation */ CRFProcess* m_pcs_OLF = NULL; m_pcs_OLF = PCSGet("OVERLAND_FLOW"); double SurfaceZ; - if(m_pcs_OLF != NULL) + if (m_pcs_OLF != NULL) { SurfaceZ = m_pcs_OLF->m_msh->nod_vector[strang[0]]->getData()[2]; if (head > SurfaceZ) @@ -1161,7 +1144,7 @@ void MSHMoveNODUcFlow (CRFProcess* m_pcs) /* Set minimum thickness */ z_bottom = m_pcs->m_msh->nod_vector[strang[anz_zeilen]]->getData()[2]; - if(head - z_bottom < MinThickness) + if (head - z_bottom < MinThickness) head = z_bottom + MinThickness; /* Berechnung der Differenz */ @@ -1169,14 +1152,13 @@ void MSHMoveNODUcFlow (CRFProcess* m_pcs) spanne_rel = spanne_ges / anz_zeilen; m_pcs->m_msh->nod_vector[strang[0]]->SetZ(head); - if(spanne_ges != 0) + if (spanne_ges != 0) /* Setzen der neuen Z-Werte entlang eines Stranges */ for (i = 1; i < anz_zeilen; i++) /* Schleife �ber Anzahl der Zeilen */ - m_pcs->m_msh->nod_vector[strang[i]]->SetZ( - head - i * spanne_rel); + m_pcs->m_msh->nod_vector[strang[i]]->SetZ(head - i * spanne_rel); - strang = (long*) Free(strang); - } /*endif index ==1 */ + strang = (long*)Free(strang); + } /*endif index ==1 */ /* end for Schleife �ber alle Knoten */ } @@ -1194,67 +1176,65 @@ void CFEMesh::DefineMobileNodes(CRFProcess* m_pcs) { long* mobile_nodes = NULL; long no_mobile_nodes = -1; - long i,j; + long i, j; //---------------------------------------------------------------------- // Define mobile MSH nodes //---------------------------------------------------------------------- //...................................................................... - //DOMAIN - if(m_pcs->geo_type.find("DOMAIN") != std::string::npos) + // DOMAIN + if (m_pcs->geo_type.find("DOMAIN") != std::string::npos) { - for(i = 0; i < (long)nod_vector.size(); i++) + for (i = 0; i < (long)nod_vector.size(); i++) { - mobile_nodes = (long*) Realloc(mobile_nodes,sizeof(long) * (i + 1)); + mobile_nodes = (long*)Realloc(mobile_nodes, sizeof(long) * (i + 1)); mobile_nodes[i] = i; } no_mobile_nodes = (long)m_pcs->m_msh->nod_vector.size(); } //...................................................................... - //LAYER - if(m_pcs->geo_type.find("LAYER") != std::string::npos) + // LAYER + if (m_pcs->geo_type.find("LAYER") != std::string::npos) { std::string m_string; long no_nodes_per_layer = (long)nod_vector.size() / (getNumberOfMeshLayers() + 1); int pos = 0; - int layer_start = 0,layer_end = 0; - if(m_pcs->geo_type_name.find("-") != std::string::npos) + int layer_start = 0, layer_end = 0; + if (m_pcs->geo_type_name.find("-") != std::string::npos) { pos = m_pcs->geo_type_name.find("-") != std::string::npos; - m_string = m_pcs->geo_type_name.substr(0,pos); - layer_start = strtol(m_string.c_str(),NULL,0); - m_string = m_pcs->geo_type_name.substr(pos + 1,std::string::npos); - layer_end = strtol(m_string.c_str(),NULL,0); + m_string = m_pcs->geo_type_name.substr(0, pos); + layer_start = strtol(m_string.c_str(), NULL, 0); + m_string = m_pcs->geo_type_name.substr(pos + 1, std::string::npos); + layer_end = strtol(m_string.c_str(), NULL, 0); } else { - layer_start = strtol(m_pcs->geo_type_name.c_str(),NULL,0); + layer_start = strtol(m_pcs->geo_type_name.c_str(), NULL, 0); layer_end = layer_start; } int no_layers = layer_end - layer_start + 1; no_mobile_nodes = (no_layers + 1) * no_nodes_per_layer; mobile_nodes = new long[no_mobile_nodes]; - for(i = 0; i < no_layers + 1; i++) - for(j = 0; j < no_nodes_per_layer; j++) - mobile_nodes[i * no_nodes_per_layer + - j] = j + (layer_start - 1 + i) * no_nodes_per_layer; - + for (i = 0; i < no_layers + 1; i++) + for (j = 0; j < no_nodes_per_layer; j++) + mobile_nodes[i * no_nodes_per_layer + j] = j + (layer_start - 1 + i) * no_nodes_per_layer; } //...................................................................... - //SURFACE - if(m_pcs->geo_type.find("SURFACE") != std::string::npos) + // SURFACE + if (m_pcs->geo_type.find("SURFACE") != std::string::npos) { Surface* m_sfc = NULL; - //CC + // CC m_sfc = GEOGetSFCByName(m_pcs->geo_type_name); - if(m_sfc) - //CC - mobile_nodes = GetPointsIn(m_sfc,&no_mobile_nodes); + if (m_sfc) + // CC + mobile_nodes = GetPointsIn(m_sfc, &no_mobile_nodes); else - std::cout << "Warning in CFEMesh::DefineMobileNodes - no GEO data" << - "\n"; + std::cout << "Warning in CFEMesh::DefineMobileNodes - no GEO data" + << "\n"; } //...................................................................... - //VOLUME + // VOLUME /*OK411 if(m_pcs->geo_type.find("VOLUME")!=std::string::npos) { @@ -1269,11 +1249,11 @@ void CFEMesh::DefineMobileNodes(CRFProcess* m_pcs) //---------------------------------------------------------------------- // Set mobile MSH nodes flag //---------------------------------------------------------------------- - for(i = 0; i < (long)nod_vector.size(); i++) + for (i = 0; i < (long)nod_vector.size(); i++) nod_vector[i]->free_surface = -1; - for(i = 0; i < no_mobile_nodes; i++) + for (i = 0; i < no_mobile_nodes; i++) nod_vector[i]->free_surface = 4; - //nod_vector[mobile_nodes[i]]->free_surface = 4; + // nod_vector[mobile_nodes[i]]->free_surface = 4; //---------------------------------------------------------------------- if (no_mobile_nodes > 0) { @@ -1281,7 +1261,7 @@ void CFEMesh::DefineMobileNodes(CRFProcess* m_pcs) MSHSelectFreeSurfaceNodes(this); } //---------------------------------------------------------------------- - delete [] mobile_nodes; + delete[] mobile_nodes; mobile_nodes = NULL; } @@ -1293,7 +1273,7 @@ void CFEMesh::DefineMobileNodes(CRFProcess* m_pcs) ToDo evtl. vector 08/2005 CC Modification: CGLPoint* e_pnt - Move from GeoLib to MshLib **************************************************************************/ -void MSHGetNodesClose(std::vector&msh_point_vector,CGLPoint* e_pnt) +void MSHGetNodesClose(std::vector& msh_point_vector, CGLPoint* e_pnt) { e_pnt = e_pnt; msh_point_vector.size(); @@ -1450,7 +1430,7 @@ long* MSHGetNodesClose(long* number_of_nodes, CGLPolyline* m_ply) 01/2004 OK Implementation 08/2005 CC Modification Move from Geolib to Mshlib **************************************************************************/ -long* GetPointsIn(Surface* m_sfc,long* number_of_nodes) +long* GetPointsIn(Surface* m_sfc, long* number_of_nodes) { long* nodes = NULL; number_of_nodes = number_of_nodes; @@ -1559,29 +1539,26 @@ void GEOGetNodesInMaterialDomain(const int MatIndex, std::vector& Nodes) 10/2004 WW Implementation 06/2012 NW Made this function faster using std::set for large data set **************************************************************************/ -void GEOGetNodesInMaterialDomain(CFEMesh const*const msh, - int MatIndex, - std::vector& Nodes, - bool Order) +void GEOGetNodesInMaterialDomain(CFEMesh const* const msh, int MatIndex, std::vector& Nodes, bool Order) { Nodes.resize(0); std::set set_nodes; - const size_t n_ele (msh->ele_vector.size()); + const size_t n_ele(msh->ele_vector.size()); for (size_t e = 0; e < n_ele; e++) { - MeshLib::CElem const*const elem (msh->ele_vector[e]); - //if (elem->GetMark()) // Marked for use + MeshLib::CElem const* const elem(msh->ele_vector[e]); + // if (elem->GetMark()) // Marked for use { - const int nn (elem->GetNodesNumber(Order)); - if(elem->GetPatchIndex() == static_cast(MatIndex)) + const int nn(elem->GetNodesNumber(Order)); + if (elem->GetPatchIndex() == static_cast(MatIndex)) { - for(int i = 0; i < nn; i++) + for (int i = 0; i < nn; i++) { set_nodes.insert(elem->GetNodeIndex(i)); } } - } // if - } //For + } // if + } // For Nodes.assign(set_nodes.begin(), set_nodes.end()); } @@ -1714,7 +1691,7 @@ void SetRFIPointsClose(CGLLine* m_lin) 01/2004 OK Implementation 09/2005 CC Modification No MFC function **************************************************************************/ -//bool IsPointInSurface(Surface* m_fsc, CGLPoint *m_point) +// bool IsPointInSurface(Surface* m_fsc, CGLPoint *m_point) //{ // bool ok = false; // m_point = m_point; @@ -1723,9 +1700,6 @@ void SetRFIPointsClose(CGLLine* m_lin) // return ok; //} - - - /************************************************************************** MSHLib-Method: 01/2006 OK Implementation @@ -1738,19 +1712,19 @@ int MSHSetMaxMMPGroups() CFEMesh* m_msh = NULL; //---------------------------------------------------------------------- size_t msh_max_mmp_groups; - for (i = 0; i < (int) fem_msh_vector.size(); i++) + for (i = 0; i < (int)fem_msh_vector.size(); i++) { m_msh = fem_msh_vector[i]; m_msh->max_mmp_groups = 0; msh_max_mmp_groups = 0; - for (j = 0; j < (long) m_msh->ele_vector.size(); j++) + for (j = 0; j < (long)m_msh->ele_vector.size(); j++) if ((m_msh->ele_vector[j]->GetPatchIndex() + 1) > msh_max_mmp_groups) msh_max_mmp_groups++; m_msh->max_mmp_groups = msh_max_mmp_groups; } //---------------------------------------------------------------------- size_t g_msh_max_mmp_groups = 0; - for (i = 0; i < (int) fem_msh_vector.size(); i++) + for (i = 0; i < (int)fem_msh_vector.size(); i++) if (m_msh->max_mmp_groups > g_msh_max_mmp_groups) g_msh_max_mmp_groups++; //---------------------------------------------------------------------- @@ -1776,11 +1750,10 @@ size_t MSHGetMaxPatchIndex(const CFEMesh* m_msh) bool MSHTestMATGroups() { int g_max_mmp_groups = MSHSetMaxMMPGroups(); - if (g_max_mmp_groups > (int) mmp_vector.size()) + if (g_max_mmp_groups > (int)mmp_vector.size()) { std::cout << "Error: not enough MMP data"; - return false; //abort(); + return false; // abort(); } return true; } - diff --git a/MSH/msh_lib.h b/MSH/msh_lib.h old mode 100755 new mode 100644 index 2a2618280..5a6b5dd80 --- a/MSH/msh_lib.h +++ b/MSH/msh_lib.h @@ -20,11 +20,11 @@ #include "msh_mesh.h" extern std::vector fem_msh_vector; -extern MeshLib::CFEMesh* FEMGet(const std::string &msh_name); -//OK +extern MeshLib::CFEMesh* FEMGet(const std::string& msh_name); +// OK extern void MSHCreateNOD2ELERelations(MeshLib::CFEMesh*); -//MeshLib::CFEMesh* FEMRead(const std::string& fname, +// MeshLib::CFEMesh* FEMRead(const std::string& fname, // GEOLIB::GEOObjects* geo_obj = NULL, // std::string* unique_name = NULL); @@ -45,51 +45,46 @@ void FEMRead(const std::string& mesh_fname, GEOLIB::GEOObjects* geo_obj = NULL, std::string* unique_name = NULL); #if defined(USE_PETSC) // || defined(using other parallel scheme) -void FEMRead_ASCII(const int msize, const int mrank, - const std::string& file_base_name, - std::vector& mesh_vec, - GEOLIB::GEOObjects* geo_obj = NULL, - std::string* unique_name = NULL); -void FEMRead_BIN(const int msize, const int mrank, - const std::string& file_base_name, - std::vector& mesh_vec, - GEOLIB::GEOObjects* geo_obj = NULL, - std::string* unique_name = NULL); +void FEMRead_ASCII(const int msize, const int mrank, const std::string& file_base_name, + std::vector& mesh_vec, GEOLIB::GEOObjects* geo_obj = NULL, + std::string* unique_name = NULL); +void FEMRead_BIN(const int msize, const int mrank, const std::string& file_base_name, + std::vector& mesh_vec, GEOLIB::GEOObjects* geo_obj = NULL, + std::string* unique_name = NULL); #endif - extern void MSHWrite(std::string); -extern void CompleteMesh(); //WW -extern bool CompleteMesh(std::string); //OK +extern void CompleteMesh(); // WW +extern bool CompleteMesh(std::string); // OK extern void FEMDeleteAll(); -//KR extern void MSHCalcMinMaxMidCoordinates(); //OK -//KR extern double msh_x_min,msh_x_max; //OK -//KR extern double msh_y_min,msh_y_max; //OK -//KR extern double msh_z_min,msh_z_max; //OK -//KR extern double msh_x_mid,msh_y_mid,msh_z_mid; //OK +// KR extern void MSHCalcMinMaxMidCoordinates(); //OK +// KR extern double msh_x_min,msh_x_max; //OK +// KR extern double msh_y_min,msh_y_max; //OK +// KR extern double msh_z_min,msh_z_max; //OK +// KR extern double msh_x_mid,msh_y_mid,msh_z_mid; //OK // Might be removed void Read_RFI(std::istream& msh_file, MeshLib::CFEMesh* m_msh); extern void GMSH2MSH(const char*, MeshLib::CFEMesh*); -extern int MSHSetMaxMMPGroups(); //OK -extern bool MSHTestMATGroups(); //OK +extern int MSHSetMaxMMPGroups(); // OK +extern bool MSHTestMATGroups(); // OK extern size_t MSHGetMaxPatchIndex(const MeshLib::CFEMesh* m_msh); -extern void GEOGetNodesInMaterialDomain(MeshLib::CFEMesh const*const, int, std::vector&, bool); +extern void GEOGetNodesInMaterialDomain(MeshLib::CFEMesh const* const, int, std::vector&, bool); -extern void MSHDefineMobile(CRFProcess*); //OK411 -extern void MSHMoveNODUcFlow (CRFProcess*); //OK411 -extern MeshLib::CFEMesh* MSHGet(const std::string &mat_type_name); -extern void DATWriteParticleFile(int); // PCH -extern long* GetPointsIn(Surface*,long*); //OK411 -extern long* MSHGetNodesClose(long*,CGLPolyline*); //OK411 - //OK411 -#ifdef ObsoleteGUI //WW 03.2012 -extern void MSHWriteVOL2TEC(std::string); //OK -extern void MSHLayerWriteTecplot(); //OK +extern void MSHDefineMobile(CRFProcess*); // OK411 +extern void MSHMoveNODUcFlow(CRFProcess*); // OK411 +extern MeshLib::CFEMesh* MSHGet(const std::string& mat_type_name); +extern void DATWriteParticleFile(int); // PCH +extern long* GetPointsIn(Surface*, long*); // OK411 +extern long* MSHGetNodesClose(long*, CGLPolyline*); // OK411 +// OK411 +#ifdef ObsoleteGUI // WW 03.2012 +extern void MSHWriteVOL2TEC(std::string); // OK +extern void MSHLayerWriteTecplot(); // OK #endif -#ifdef Obsolete //WW 03.2012 +#ifdef Obsolete // WW 03.2012 extern void MSHAssignMATGroup2Elements(std::string); -extern void MSHCreateQuadsFromPLY(CGLPolyline*,int); -//OK411 extern void MSHCreatePrismsFromTriangles(); +extern void MSHCreateQuadsFromPLY(CGLPolyline*, int); +// OK411 extern void MSHCreatePrismsFromTriangles(); extern void MSHCreateNodes(); extern void MSHDeleteDoubleElements(int); extern long MSHMarkDoubleElementsType(int); @@ -106,24 +101,24 @@ extern void MSHAssignMATGroup2HexsElements(); extern void MSHDestroy(); extern void MSHDelete(std::string); extern void DATWriteRFIFile(const char* file_name); -//KR extern bool msh_file_binary; //OK -//TK +// KR extern bool msh_file_binary; //OK +// TK extern void Mesh_Single_Surface(std::string surface_name, const char* file_name_const_char); -//extern void Select_Nodes_Elements_by_TINFile(const char *file_name_const_char); +// extern void Select_Nodes_Elements_by_TINFile(const char *file_name_const_char); extern void Clear_Selected_Nodes_Elements(); extern void GMSH2TIN(const char* file_name_const_char); -//OK -extern MeshLib::CFEMesh* MSHGet(const std::string &mat_type_name); -//OK -extern MeshLib::CFEMesh* MSHGet(const std::string &pcs_type_name,const std::string &mat_type_name); -extern MeshLib::CFEMesh* MSHGetGEO(std::string); //OK +// OK +extern MeshLib::CFEMesh* MSHGet(const std::string& mat_type_name); +// OK +extern MeshLib::CFEMesh* MSHGet(const std::string& pcs_type_name, const std::string& mat_type_name); +extern MeshLib::CFEMesh* MSHGetGEO(std::string); // OK -//extern bool IsPointInSurface(Surface*,CGLPoint*); //OK411 +// extern bool IsPointInSurface(Surface*,CGLPoint*); //OK411 -extern void SetRFIPointsClose(CGLLine*); //OK411 - //OK411 -extern void MSHGetNodesClose(std::vector&,CGLPoint*); +extern void SetRFIPointsClose(CGLLine*); // OK411 +// OK411 +extern void MSHGetNodesClose(std::vector&, CGLPoint*); #endif //#ifdef Obsolete //WW 03.2012 #endif diff --git a/MSH/msh_lib_ext.cpp b/MSH/msh_lib_ext.cpp old mode 100755 new mode 100644 index 8ae44d537..d1ebc4c29 --- a/MSH/msh_lib_ext.cpp +++ b/MSH/msh_lib_ext.cpp @@ -7,7 +7,7 @@ * */ - //************************************************************************** +//************************************************************************** /*! \file msh_lib_ext.cpp @@ -21,7 +21,7 @@ #include "msh_lib.h" //#ifdef USET_PETSC -//kg44 included for memcpy needed by petsc +// kg44 included for memcpy needed by petsc #include #include #include "petscksp.h" @@ -39,505 +39,471 @@ using namespace std; using namespace MeshLib; -void BuildNodeStruc(MeshNodes *anode, MPI_Datatype *MPI_Node_ptr); - +void BuildNodeStruc(MeshNodes* anode, MPI_Datatype* MPI_Node_ptr); -void FEMRead(const string& file_base_name, - vector& mesh_vec, - GEOLIB::GEOObjects* geo_obj, string* unique_name) +void FEMRead(const string& file_base_name, vector& mesh_vec, GEOLIB::GEOObjects* geo_obj, + string* unique_name) { - int msize; - int mrank; + int msize; + int mrank; - MPI_Comm_size(MPI_COMM_WORLD,&msize); - MPI_Comm_rank(MPI_COMM_WORLD,&mrank); + MPI_Comm_size(MPI_COMM_WORLD, &msize); + MPI_Comm_rank(MPI_COMM_WORLD, &mrank); - PetscLogDouble v1,v2; - // #define PETSC34 - //kg44 quick fix to compile PETSC with version PETSCV3.4 + PetscLogDouble v1, v2; +// #define PETSC34 +// kg44 quick fix to compile PETSC with version PETSCV3.4 #ifdef USEPETSC34 - PetscTime(&v1); + PetscTime(&v1); #else - PetscGetTime(&v1); + PetscGetTime(&v1); #endif - // - string s_msize = number2str(msize); - - string fname_new_base; - MPI_File fh; - int rc = 0; + // + string s_msize = number2str(msize); - // Always try binary file first - fname_new_base = file_base_name+"_partitioned_msh_cfg"+s_msize+".bin"; + string fname_new_base; + MPI_File fh; + int rc = 0; - rc = MPI_File_open(MPI_COMM_WORLD, &fname_new_base[0], - MPI_MODE_RDONLY, MPI_INFO_NULL, &fh); - if (rc ) - { + // Always try binary file first + fname_new_base = file_base_name + "_partitioned_msh_cfg" + s_msize + ".bin"; - if(mrank == 0) - printf("-->Reading ASCII mesh file ..."); - - FEMRead_ASCII(msize, mrank, file_base_name, mesh_vec, geo_obj, unique_name); - // return; + rc = MPI_File_open(MPI_COMM_WORLD, &fname_new_base[0], MPI_MODE_RDONLY, MPI_INFO_NULL, &fh); + if (rc) + { + if (mrank == 0) + printf("-->Reading ASCII mesh file ..."); - } + FEMRead_ASCII(msize, mrank, file_base_name, mesh_vec, geo_obj, unique_name); + // return; + } else { - MPI_File_close(&fh); - if(mrank == 0) - printf("-->Reading binary mesh file ..."); + MPI_File_close(&fh); + if (mrank == 0) + printf("-->Reading binary mesh file ..."); - FEMRead_BIN(msize, mrank, file_base_name, mesh_vec, geo_obj, unique_name); + FEMRead_BIN(msize, mrank, file_base_name, mesh_vec, geo_obj, unique_name); } - // #define PETSC34 - //kg44 quick fix to compile PETSC with version PETSCV3.4 +// #define PETSC34 +// kg44 quick fix to compile PETSC with version PETSCV3.4 #ifdef USEPETSC34 - PetscTime(&v2); + PetscTime(&v2); #else - PetscGetTime(&v2); + PetscGetTime(&v2); #endif - if(mrank == 0) - printf("\t\n>>Total elapsed time in reading mesh:%f s\n",v2-v1); + if (mrank == 0) + printf("\t\n>>Total elapsed time in reading mesh:%f s\n", v2 - v1); - MPI_Barrier (MPI_COMM_WORLD); - - //PetscFinalize(); - //exit(0); + MPI_Barrier(MPI_COMM_WORLD); + // PetscFinalize(); + // exit(0); } -void FEMRead_BIN(const int msize, const int mrank, - const string& file_base_name, - vector& mesh_vec, - GEOLIB::GEOObjects* geo_obj, string* unique_name) +void FEMRead_BIN(const int msize, const int mrank, const string& file_base_name, vector& mesh_vec, + GEOLIB::GEOObjects* geo_obj, string* unique_name) { + // 0 long size_sbd_nodes = 0; + // 1 long size_sbd_nodes_l = 0; + // 2 ong size_sbd_nodes_h = 0; + // 3 long size_sbd_elems = 0; + // 4 long size_g_elems = 0; + const MyInt nheaders = 13; + MyInt mesh_header[nheaders]; + + MeshNodes* s_nodes = 0; + MyInt* elem_info = 0; + + // + string s_msize; + stringstream ss; + ss << msize; + ss >> s_msize; + ss.clear(); + + MPI_File fh; + string ftype = "native"; + int rc = 0; + MPI_Offset offset_new; + + CFEMesh* mesh = new CFEMesh(geo_obj, unique_name); + mesh_vec.push_back(mesh); + + //-------------------------------------------------------------------------- + // Header + string fname_new_base = file_base_name + "_partitioned_msh_cfg" + s_msize + ".bin"; + rc = MPI_File_open(MPI_COMM_WORLD, &fname_new_base[0], MPI_MODE_RDONLY, MPI_INFO_NULL, &fh); + if (rc) + { + MPI_Finalize(); + if (mrank == 0) + printf("! File %s does not exist.", &fname_new_base[0]); + exit(0); + } + + // + offset_new = 0; + offset_new = mrank * nheaders * sizeof(MyInt); + MPI_File_set_view(fh, offset_new, MPI_LONG, MPI_LONG, &ftype[0], MPI_INFO_NULL); + MPI_File_read(fh, mesh_header, nheaders, MPI_LONG, MPI_STATUS_IGNORE); //_all + MPI_File_close(&fh); + + //-------------------------------------------------------------------------- + // Node + MPI_Datatype MPI_node; + fname_new_base = file_base_name + "_partitioned_msh_nod" + s_msize + ".bin"; + rc = MPI_File_open(MPI_COMM_WORLD, &fname_new_base[0], MPI_MODE_RDONLY, MPI_INFO_NULL, &fh); + if (rc) + { + MPI_Finalize(); + if (mrank == 0) + printf("! File %s does not exist.", &fname_new_base[0]); + exit(0); + } + + s_nodes = (MeshNodes*)realloc(s_nodes, sizeof(MeshNodes) * mesh_header[0]); + BuildNodeStruc(s_nodes, &MPI_node); + + offset_new = mesh_header[10]; + MPI_File_set_view(fh, offset_new, MPI_node, MPI_node, &ftype[0], MPI_INFO_NULL); + MPI_File_read(fh, s_nodes, mesh_header[0], MPI_node, MPI_STATUS_IGNORE); + MPI_File_close(&fh); + + mesh->setSubdomainNodes(mesh_header, s_nodes); + free(s_nodes); + s_nodes = NULL; + MPI_Type_free(&MPI_node); + + //-------------------------------------------------------------------------- + // Element + fname_new_base = file_base_name + "_partitioned_msh_ele" + s_msize + ".bin"; + rc = MPI_File_open(MPI_COMM_WORLD, &fname_new_base[0], MPI_MODE_RDONLY, MPI_INFO_NULL, &fh); + if (rc) + { + MPI_Finalize(); + if (mrank == 0) + printf("! File %s does not exist.", &fname_new_base[0]); + exit(0); + } + + MyInt size_elem_info = mesh_header[2] + mesh_header[8]; + elem_info = (MyInt*)realloc(elem_info, sizeof(MyInt) * size_elem_info); + offset_new = mesh_header[11]; + MPI_File_set_view(fh, offset_new, MPI_LONG, MPI_LONG, &ftype[0], MPI_INFO_NULL); + MPI_File_read(fh, elem_info, size_elem_info, MPI_LONG, MPI_STATUS_IGNORE); + MPI_File_close(&fh); + + mesh->setSubdomainElements(mesh_header, elem_info, true); + + free(elem_info); + elem_info = NULL; + + //-------------------------------------------------------------------------- + // Ghost element + fname_new_base = file_base_name + "_partitioned_msh_ele_g" + s_msize + ".bin"; + rc = MPI_File_open(MPI_COMM_WORLD, &fname_new_base[0], MPI_MODE_RDONLY, MPI_INFO_NULL, &fh); + if (rc) + { + MPI_Finalize(); + if (mrank == 0) + printf("! File %s does not exist.", &fname_new_base[0]); + exit(0); + } + size_elem_info = mesh_header[3] + mesh_header[9]; + elem_info = (MyInt*)realloc(elem_info, sizeof(MyInt) * size_elem_info); + offset_new = mesh_header[12]; + MPI_File_set_view(fh, offset_new, MPI_LONG, MPI_LONG, &ftype[0], MPI_INFO_NULL); + MPI_File_read(fh, elem_info, size_elem_info, MPI_LONG, MPI_STATUS_IGNORE); + MPI_File_close(&fh); - //0 long size_sbd_nodes = 0; - //1 long size_sbd_nodes_l = 0; - //2 ong size_sbd_nodes_h = 0; - //3 long size_sbd_elems = 0; - //4 long size_g_elems = 0; - const MyInt nheaders = 13; - MyInt mesh_header[ nheaders]; - - MeshNodes *s_nodes = 0; - MyInt *elem_info = 0; - - // - string s_msize; - stringstream ss; - ss << msize; - ss >> s_msize; - ss.clear(); - - MPI_File fh; - string ftype = "native"; - int rc = 0; - MPI_Offset offset_new; - - - CFEMesh *mesh = new CFEMesh(geo_obj, unique_name); - mesh_vec.push_back(mesh); - - //-------------------------------------------------------------------------- - // Header - string fname_new_base = file_base_name+"_partitioned_msh_cfg"+s_msize+".bin"; - rc = MPI_File_open(MPI_COMM_WORLD, &fname_new_base[0], MPI_MODE_RDONLY, - MPI_INFO_NULL, &fh); - if (rc ) - { - - MPI_Finalize(); - if(mrank == 0 ) - printf("! File %s does not exist.", &fname_new_base[0]); - exit(0); - } - - // - offset_new = 0; - offset_new = mrank * nheaders * sizeof(MyInt); - MPI_File_set_view(fh, offset_new, MPI_LONG, MPI_LONG, &ftype[0], MPI_INFO_NULL); - MPI_File_read(fh, mesh_header, nheaders, MPI_LONG, MPI_STATUS_IGNORE); //_all - MPI_File_close(&fh); - - - //-------------------------------------------------------------------------- - //Node - MPI_Datatype MPI_node; - fname_new_base = file_base_name+"_partitioned_msh_nod"+s_msize+".bin"; - rc = MPI_File_open(MPI_COMM_WORLD, &fname_new_base[0], MPI_MODE_RDONLY, - MPI_INFO_NULL, &fh); - if (rc ) - { - - MPI_Finalize(); - if(mrank == 0 ) - printf("! File %s does not exist.", &fname_new_base[0]); - exit(0); - } - - s_nodes = (MeshNodes *)realloc(s_nodes, sizeof(MeshNodes) * mesh_header[0]); - BuildNodeStruc(s_nodes, &MPI_node); - - offset_new = mesh_header[10]; - MPI_File_set_view(fh, offset_new, MPI_node, MPI_node, &ftype[0], MPI_INFO_NULL); - MPI_File_read(fh, s_nodes, mesh_header[0], MPI_node, MPI_STATUS_IGNORE); - MPI_File_close(&fh); - - mesh->setSubdomainNodes(mesh_header, s_nodes); - free(s_nodes); - s_nodes = NULL; - MPI_Type_free(&MPI_node); - - //-------------------------------------------------------------------------- - //Element - fname_new_base = file_base_name+"_partitioned_msh_ele"+s_msize+".bin"; - rc = MPI_File_open(MPI_COMM_WORLD, &fname_new_base[0], MPI_MODE_RDONLY, - MPI_INFO_NULL, &fh); - if (rc ) - { - - MPI_Finalize(); - if(mrank == 0 ) - printf("! File %s does not exist.", &fname_new_base[0]); - exit(0); - } - - - MyInt size_elem_info = mesh_header[2] + mesh_header[8]; - elem_info = (MyInt *)realloc(elem_info, sizeof(MyInt) * size_elem_info ); - offset_new = mesh_header[11]; - MPI_File_set_view(fh, offset_new, MPI_LONG, MPI_LONG, &ftype[0], MPI_INFO_NULL); - MPI_File_read(fh, elem_info, size_elem_info, MPI_LONG, MPI_STATUS_IGNORE); - MPI_File_close(&fh); - - mesh->setSubdomainElements(mesh_header, elem_info, true); - - free(elem_info); - elem_info = NULL; - - - //-------------------------------------------------------------------------- - //Ghost element - fname_new_base = file_base_name+"_partitioned_msh_ele_g"+s_msize+".bin"; - rc = MPI_File_open(MPI_COMM_WORLD, &fname_new_base[0], MPI_MODE_RDONLY, - MPI_INFO_NULL, &fh); - if (rc ) - { - - MPI_Finalize(); - if(mrank == 0 ) - printf("! File %s does not exist.", &fname_new_base[0]); - exit(0); - } - - - size_elem_info = mesh_header[3] + mesh_header[9]; - elem_info = (MyInt *)realloc(elem_info, sizeof(MyInt) * size_elem_info ); - offset_new = mesh_header[12]; - MPI_File_set_view(fh, offset_new, MPI_LONG, MPI_LONG, &ftype[0], MPI_INFO_NULL); - MPI_File_read(fh, elem_info, size_elem_info, MPI_LONG, MPI_STATUS_IGNORE); - MPI_File_close(&fh); - - mesh->setSubdomainElements(mesh_header, elem_info, false); - - free(elem_info); - elem_info = NULL; - - - //MPI_Barrier (MPI_COMM_WORLD); - mesh->ConstructGrid(); - mesh->FillTransformMatrix(); - //mesh->calMaximumConnectedNodes(); + mesh->setSubdomainElements(mesh_header, elem_info, false); + free(elem_info); + elem_info = NULL; + // MPI_Barrier (MPI_COMM_WORLD); + mesh->ConstructGrid(); + mesh->FillTransformMatrix(); + // mesh->calMaximumConnectedNodes(); } -void FEMRead_ASCII(const int msize, const int mrank, - const string& file_base_name, - vector& mesh_vec, - GEOLIB::GEOObjects* geo_obj, string* unique_name) +void FEMRead_ASCII(const int msize, const int mrank, const string& file_base_name, vector& mesh_vec, + GEOLIB::GEOObjects* geo_obj, string* unique_name) { - //0 long size_sbd_nodes = 0; - //1 long size_sbd_nodes_l = 0; - //2 ong size_sbd_nodes_h = 0; - //3 long size_sbd_elems = 0; - //4 long size_g_elems = 0; - const int nheaders = 10; - long mesh_header[ nheaders]; - - MeshNodes *s_nodes = (MeshNodes *)malloc(sizeof(MeshNodes)); - long *elem_info = (long *)malloc(1); - - - string str_var = ""; - - MPI_Datatype MPI_node; - int tag[] = {0, 1, 2}; - //int ierr; - //MPI_Request send_request, recv_request; - MPI_Status status; - - // - string s_msize; - stringstream ss; - ss << msize; - ss >> s_msize; - ss.clear(); - - ifstream is_cfg; - ifstream is_node; - ifstream is_elem; + // 0 long size_sbd_nodes = 0; + // 1 long size_sbd_nodes_l = 0; + // 2 ong size_sbd_nodes_h = 0; + // 3 long size_sbd_elems = 0; + // 4 long size_g_elems = 0; + const int nheaders = 10; + long mesh_header[nheaders]; + + MeshNodes* s_nodes = (MeshNodes*)malloc(sizeof(MeshNodes)); + long* elem_info = (long*)malloc(1); + + string str_var = ""; + + MPI_Datatype MPI_node; + int tag[] = {0, 1, 2}; + // int ierr; + // MPI_Request send_request, recv_request; + MPI_Status status; + + // + string s_msize; + stringstream ss; + ss << msize; + ss >> s_msize; + ss.clear(); + + ifstream is_cfg; + ifstream is_node; + ifstream is_elem; #ifdef MULTI_MESH_FILE - stringstream ss (stringstream::in | stringstream::out); + stringstream ss(stringstream::in | stringstream::out); #endif - if(mrank == 0) - { - str_var = file_base_name+"_partitioned_cfg"+ s_msize + ".msh"; // "_partitioned.msh"; - is_cfg.open(str_var.c_str()); - if( !is_cfg.good() ) - { - std::cout << "Cannot open file "<< str_var << " Quit now! "<< std::endl; - exit(1); - } - - str_var = file_base_name + "_partitioned_nodes_" + s_msize + ".msh"; // "_partitioned.msh"; - is_node.open(str_var.c_str()); - if( !is_node.good() ) - { - std::cout << "Cannot open file "<< str_var << " Quit now! "<< std::endl; - exit(1); - } - - str_var = file_base_name + "_partitioned_elems_" + s_msize + ".msh"; // "_partitioned.msh"; - is_elem.open(str_var.c_str()); - if( !is_elem.good() ) - { - std::cout << "Cannot open file "<< str_var << " Quit now! "<< std::endl; - exit(1); - } - - getline(is_cfg, str_var); - int num_parts; - is_cfg >> num_parts >>ws; - if(num_parts != msize) - { - string str_m = "Sorry, I have to quit the simulation now because that " - " the number of the requested computer cores " - "is not identical to the number of subdomains."; - cout<Parallel reading the partitioned mesh: "<> mesh_header[j]; - is_cfg >> ws; - } - MPI_Bcast(mesh_header, nheaders, MPI_LONG, 0, MPI_COMM_WORLD); - - //cout<<"\ncccccccccc "<0) - BuildNodeStruc(s_nodes, &MPI_node); - - if(mrank == 0) - { - // Nodes - for(long k=0; k> anode->index; - - is_node >> anode->x >> anode->y >> anode->z >> ws; - } - - if(i==0) - { - mesh->setSubdomainNodes(&mesh_header[0], s_nodes); - } - else - { - MPI_Send(s_nodes, mesh_header[0], MPI_node, i, tag[0], MPI_COMM_WORLD); - } - } - - if(i>0) - { - if(mrank == i) - { - MPI_Recv(s_nodes, mesh_header[0], MPI_node, 0, tag[0], MPI_COMM_WORLD, &status); - mesh->setSubdomainNodes(mesh_header, s_nodes); - } - - } - free(s_nodes); - s_nodes = NULL; - - //------------------------------------------------------------------------- - // Element - const long size_elem_info = mesh_header[2] + mesh_header[8]; - elem_info = (long *)realloc(elem_info, sizeof(long) * size_elem_info ); - if(mrank == 0) - { - long counter = mesh_header[2]; - for(long j=0; j> elem_info[counter]; //mat. idx - counter++; - is_elem >> elem_info[counter]; //type - counter++; - is_elem >> elem_info[counter]; //nnodes - const int nn_e = elem_info[counter]; - counter++; - for(int k=0; k> elem_info[counter]; - counter++; - } - } - - if(i==0) - { - mesh->setSubdomainElements(mesh_header, elem_info, true); - } - else - { - MPI_Send(elem_info, size_elem_info, MPI_LONG, i, tag[1], MPI_COMM_WORLD); - } - - } - if(i>0) - { - if(mrank == i) - { - MPI_Recv(elem_info, size_elem_info, MPI_LONG, 0, tag[1], MPI_COMM_WORLD, &status); - mesh->setSubdomainElements(mesh_header, elem_info, true); - } - } - - //if(elem_info) - // { - free(elem_info); - elem_info = NULL; - // } - - //------------------------------------------------------------------------- - // Ghost element - const long size_elem_g_info = mesh_header[3] + mesh_header[9]; - elem_info = (long *)realloc(elem_info, sizeof(long) * size_elem_g_info ); - if(mrank == 0) - { - long counter = mesh_header[3]; - for(long j=0; j> elem_info[counter]; //mat. idx - counter++; - is_elem >> elem_info[counter]; //type - counter++; - is_elem >> elem_info[counter]; //nnodes - const int nn_e = elem_info[counter]; - counter++; - for(int k=0; k> elem_info[counter]; - counter++; - } - is_elem >> elem_info[counter]; - // const int nn_e_g = elem_info[counter]; - counter++; - // ghost nodes for linear element - is_elem >> elem_info[counter]; - const int nn_e_g = elem_info[counter]; - counter++; - for(int k=0; k> elem_info[counter]; - counter++; - } - } - - if(i==0) - { - mesh->setSubdomainElements(mesh_header, elem_info, false); - } - else - { - MPI_Send(elem_info, size_elem_g_info, MPI_LONG, i, tag[2], MPI_COMM_WORLD); - } - - } - if(i>0) - { - if(mrank == i) - { - MPI_Recv(elem_info, size_elem_g_info, MPI_LONG, 0, tag[2], MPI_COMM_WORLD, &status); - mesh->setSubdomainElements(mesh_header, elem_info, false); - } - } - - free(elem_info); - elem_info = NULL; - } - - if(s_nodes) - { - free(s_nodes); - s_nodes = NULL; - } - if(elem_info) - { - free(elem_info); - elem_info = NULL; - } - - if(mrank == 0) - { - is_cfg.close(); - is_node.close(); - is_elem.close(); - } - - MPI_Type_free(&MPI_node); - - MPI_Barrier (MPI_COMM_WORLD); - mesh->ConstructGrid(); - mesh->FillTransformMatrix(); - //mesh->calMaximumConnectedNodes(); - MPI_Barrier (MPI_COMM_WORLD); - - //PetscFinalize(); - //exit(0); -} + if (mrank == 0) + { + str_var = file_base_name + "_partitioned_cfg" + s_msize + ".msh"; // "_partitioned.msh"; + is_cfg.open(str_var.c_str()); + if (!is_cfg.good()) + { + std::cout << "Cannot open file " << str_var << " Quit now! " << std::endl; + exit(1); + } + + str_var = file_base_name + "_partitioned_nodes_" + s_msize + ".msh"; // "_partitioned.msh"; + is_node.open(str_var.c_str()); + if (!is_node.good()) + { + std::cout << "Cannot open file " << str_var << " Quit now! " << std::endl; + exit(1); + } + + str_var = file_base_name + "_partitioned_elems_" + s_msize + ".msh"; // "_partitioned.msh"; + is_elem.open(str_var.c_str()); + if (!is_elem.good()) + { + std::cout << "Cannot open file " << str_var << " Quit now! " << std::endl; + exit(1); + } + + getline(is_cfg, str_var); + int num_parts; + is_cfg >> num_parts >> ws; + if (num_parts != msize) + { + string str_m + = "Sorry, I have to quit the simulation now because that " + " the number of the requested computer cores " + "is not identical to the number of subdomains."; + cout << str_m << endl; + MPI_Finalize(); + exit(1); + } + } + + CFEMesh* mesh = new CFEMesh(geo_obj, unique_name); + mesh_vec.push_back(mesh); + + for (int i = 0; i < msize; i++) + { + if (mrank == 0) + { + cout << "-->Parallel reading the partitioned mesh: " << i << endl; + + for (int j = 0; j < nheaders; j++) + is_cfg >> mesh_header[j]; + is_cfg >> ws; + } + MPI_Bcast(mesh_header, nheaders, MPI_LONG, 0, MPI_COMM_WORLD); + + // cout<<"\ncccccccccc "< 0) + BuildNodeStruc(s_nodes, &MPI_node); + + if (mrank == 0) + { + // Nodes + for (long k = 0; k < mesh_header[0]; k++) + { + MeshNodes* anode = &s_nodes[k]; + is_node >> anode->index; + + is_node >> anode->x >> anode->y >> anode->z >> ws; + } + + if (i == 0) + { + mesh->setSubdomainNodes(&mesh_header[0], s_nodes); + } + else + { + MPI_Send(s_nodes, mesh_header[0], MPI_node, i, tag[0], MPI_COMM_WORLD); + } + } + + if (i > 0) + { + if (mrank == i) + { + MPI_Recv(s_nodes, mesh_header[0], MPI_node, 0, tag[0], MPI_COMM_WORLD, &status); + mesh->setSubdomainNodes(mesh_header, s_nodes); + } + } + free(s_nodes); + s_nodes = NULL; + + //------------------------------------------------------------------------- + // Element + const long size_elem_info = mesh_header[2] + mesh_header[8]; + elem_info = (long*)realloc(elem_info, sizeof(long) * size_elem_info); + if (mrank == 0) + { + long counter = mesh_header[2]; + for (long j = 0; j < mesh_header[2]; j++) + { + elem_info[j] = counter; + is_elem >> elem_info[counter]; // mat. idx + counter++; + is_elem >> elem_info[counter]; // type + counter++; + is_elem >> elem_info[counter]; // nnodes + const int nn_e = elem_info[counter]; + counter++; + for (int k = 0; k < nn_e; k++) + { + is_elem >> elem_info[counter]; + counter++; + } + } + + if (i == 0) + { + mesh->setSubdomainElements(mesh_header, elem_info, true); + } + else + { + MPI_Send(elem_info, size_elem_info, MPI_LONG, i, tag[1], MPI_COMM_WORLD); + } + } + if (i > 0) + { + if (mrank == i) + { + MPI_Recv(elem_info, size_elem_info, MPI_LONG, 0, tag[1], MPI_COMM_WORLD, &status); + mesh->setSubdomainElements(mesh_header, elem_info, true); + } + } + + // if(elem_info) + // { + free(elem_info); + elem_info = NULL; + // } + + //------------------------------------------------------------------------- + // Ghost element + const long size_elem_g_info = mesh_header[3] + mesh_header[9]; + elem_info = (long*)realloc(elem_info, sizeof(long) * size_elem_g_info); + if (mrank == 0) + { + long counter = mesh_header[3]; + for (long j = 0; j < mesh_header[3]; j++) + { + elem_info[j] = counter; + is_elem >> elem_info[counter]; // mat. idx + counter++; + is_elem >> elem_info[counter]; // type + counter++; + is_elem >> elem_info[counter]; // nnodes + const int nn_e = elem_info[counter]; + counter++; + for (int k = 0; k < nn_e; k++) + { + is_elem >> elem_info[counter]; + counter++; + } + is_elem >> elem_info[counter]; + // const int nn_e_g = elem_info[counter]; + counter++; + // ghost nodes for linear element + is_elem >> elem_info[counter]; + const int nn_e_g = elem_info[counter]; + counter++; + for (int k = 0; k < nn_e_g; k++) + { + is_elem >> elem_info[counter]; + counter++; + } + } + + if (i == 0) + { + mesh->setSubdomainElements(mesh_header, elem_info, false); + } + else + { + MPI_Send(elem_info, size_elem_g_info, MPI_LONG, i, tag[2], MPI_COMM_WORLD); + } + } + if (i > 0) + { + if (mrank == i) + { + MPI_Recv(elem_info, size_elem_g_info, MPI_LONG, 0, tag[2], MPI_COMM_WORLD, &status); + mesh->setSubdomainElements(mesh_header, elem_info, false); + } + } + + free(elem_info); + elem_info = NULL; + } + + if (s_nodes) + { + free(s_nodes); + s_nodes = NULL; + } + if (elem_info) + { + free(elem_info); + elem_info = NULL; + } + + if (mrank == 0) + { + is_cfg.close(); + is_node.close(); + is_elem.close(); + } + MPI_Type_free(&MPI_node); + + MPI_Barrier(MPI_COMM_WORLD); + mesh->ConstructGrid(); + mesh->FillTransformMatrix(); + // mesh->calMaximumConnectedNodes(); + MPI_Barrier(MPI_COMM_WORLD); + + // PetscFinalize(); + // exit(0); +} namespace MeshLib { - /*! Fill data for subdomain mesh @@ -546,28 +512,27 @@ namespace MeshLib WW. 02~03.2012 */ -void CFEMesh::setSubdomainNodes(MyInt *header, const MeshNodes *s_nodes) +void CFEMesh::setSubdomainNodes(MyInt* header, const MeshNodes* s_nodes) { - int k; - - NodesNumber_Quadratic = header[0]; - NodesNumber_Linear = header[1]; + int k; - loc_NodesNumber_Linear = header[4]; - loc_NodesNumber_Quadratic = header[5]; - glb_NodesNumber_Linear =header[6]; - glb_NodesNumber_Quadratic =header[7]; + NodesNumber_Quadratic = header[0]; + NodesNumber_Linear = header[1]; - for(k=0; kx, anode->y, anode->z); + loc_NodesNumber_Linear = header[4]; + loc_NodesNumber_Quadratic = header[5]; + glb_NodesNumber_Linear = header[6]; + glb_NodesNumber_Quadratic = header[7]; - new_node->SetEquationIndex(anode->index); + for (k = 0; k < header[0]; k++) + { + const MeshNodes* anode = &s_nodes[k]; + CNode* new_node = new CNode(k, anode->x, anode->y, anode->z); - nod_vector.push_back(new_node); + new_node->SetEquationIndex(anode->index); - } + nod_vector.push_back(new_node); + } } /*! @@ -578,127 +543,125 @@ void CFEMesh::setSubdomainNodes(MyInt *header, const MeshNodes *s_nodes) @param inside : indicator for inside domain WW. 02~03.2012 */ -void CFEMesh::setSubdomainElements(MyInt *header, const MyInt *elem_info, const bool inside ) +void CFEMesh::setSubdomainElements(MyInt* header, const MyInt* elem_info, const bool inside) { - MyInt i; - MyInt k; - MyInt counter; - int mat_idx; - int e_type; - int nnodes; - - MyInt ne = 0; - if(inside) - ne = header[2]; - else - ne = header[3]; - - - // Element - for(i=0; innodesHQ = nnodes; - new_elem->nodes_index.resize(new_elem->nnodesHQ); - for(k=0; knnodesHQ; k++) - { - new_elem->nodes_index[k] = elem_info[counter]; - counter++; - } - - if(!inside) - { - const int nn_gl = elem_info[counter]; - counter++; - const int nn_g = elem_info[counter]; - counter++; - - new_elem->g_index = new int[nn_g+2]; - int *ele_gnidx = new_elem->g_index; - ele_gnidx[0] = nn_gl; - ele_gnidx[1] = nn_g; - for(k=2; kpatch_index = static_cast (mat_idx); - - // element type - switch(e_type) - { - case 1: - new_elem->geo_type = MshElemType::LINE; - new_elem->nnodes = 2; - new_elem->ele_dim = 1; - new_elem->nfaces = 2; - new_elem->nedges = 0; - break; - case 2: - new_elem->geo_type = MshElemType::QUAD; - new_elem->nnodes = 4; - new_elem->ele_dim = 2; - new_elem->nfaces = 4; - new_elem->nedges = 4; - - break; - case 3: - new_elem->geo_type = MshElemType::HEXAHEDRON; - new_elem->nnodes = 8; - new_elem->ele_dim = 3; - new_elem->nfaces = 6; - new_elem->nedges = 12; - break; - case 4: - new_elem->geo_type = MshElemType::TRIANGLE; - new_elem->nnodes = 3; - new_elem->ele_dim = 2; - new_elem->nfaces = 3; - new_elem->nedges = 3; - break; - case 5: - new_elem->geo_type = MshElemType::TETRAHEDRON; - new_elem->nnodes = 4; - new_elem->ele_dim = 3; - new_elem->nfaces = 4; - new_elem->nedges = 6; - break; - case 6: - new_elem->geo_type = MshElemType::PRISM; - new_elem->nnodes = 6; - new_elem->ele_dim = 3; - new_elem->nfaces = 5; - new_elem->nedges = 9; - break; - case 7://:PYRAMID: - new_elem->geo_type = MshElemType::PYRAMID; - new_elem->nnodes = 5; - new_elem->ele_dim = 3; - new_elem->nfaces = 5; - new_elem->nedges = 8; - break; - default: - break; - } - - new_elem->InitializeMembers(); - - //new_elem->WriteIndex(); - } + MyInt i; + MyInt k; + MyInt counter; + int mat_idx; + int e_type; + int nnodes; + + MyInt ne = 0; + if (inside) + ne = header[2]; + else + ne = header[3]; + + // Element + for (i = 0; i < ne; i++) + { + CElem* new_elem = new CElem(ele_vector.size()); + ele_vector.push_back(new_elem); + + counter = elem_info[i]; + + mat_idx = elem_info[counter]; + counter++; + e_type = elem_info[counter]; + counter++; + nnodes = elem_info[counter]; + counter++; + + new_elem->nnodesHQ = nnodes; + new_elem->nodes_index.resize(new_elem->nnodesHQ); + for (k = 0; k < new_elem->nnodesHQ; k++) + { + new_elem->nodes_index[k] = elem_info[counter]; + counter++; + } + + if (!inside) + { + const int nn_gl = elem_info[counter]; + counter++; + const int nn_g = elem_info[counter]; + counter++; + + new_elem->g_index = new int[nn_g + 2]; + int* ele_gnidx = new_elem->g_index; + ele_gnidx[0] = nn_gl; + ele_gnidx[1] = nn_g; + for (k = 2; k < nn_g + 2; k++) + { + ele_gnidx[k] = elem_info[counter]; + counter++; + } + } + + new_elem->patch_index = static_cast(mat_idx); + + // element type + switch (e_type) + { + case 1: + new_elem->geo_type = MshElemType::LINE; + new_elem->nnodes = 2; + new_elem->ele_dim = 1; + new_elem->nfaces = 2; + new_elem->nedges = 0; + break; + case 2: + new_elem->geo_type = MshElemType::QUAD; + new_elem->nnodes = 4; + new_elem->ele_dim = 2; + new_elem->nfaces = 4; + new_elem->nedges = 4; + + break; + case 3: + new_elem->geo_type = MshElemType::HEXAHEDRON; + new_elem->nnodes = 8; + new_elem->ele_dim = 3; + new_elem->nfaces = 6; + new_elem->nedges = 12; + break; + case 4: + new_elem->geo_type = MshElemType::TRIANGLE; + new_elem->nnodes = 3; + new_elem->ele_dim = 2; + new_elem->nfaces = 3; + new_elem->nedges = 3; + break; + case 5: + new_elem->geo_type = MshElemType::TETRAHEDRON; + new_elem->nnodes = 4; + new_elem->ele_dim = 3; + new_elem->nfaces = 4; + new_elem->nedges = 6; + break; + case 6: + new_elem->geo_type = MshElemType::PRISM; + new_elem->nnodes = 6; + new_elem->ele_dim = 3; + new_elem->nfaces = 5; + new_elem->nedges = 9; + break; + case 7: //:PYRAMID: + new_elem->geo_type = MshElemType::PYRAMID; + new_elem->nnodes = 5; + new_elem->ele_dim = 3; + new_elem->nfaces = 5; + new_elem->nedges = 8; + break; + default: + break; + } + + new_elem->InitializeMembers(); + + // new_elem->WriteIndex(); + } } /*! @@ -708,227 +671,208 @@ void CFEMesh::setSubdomainElements(MyInt *header, const MyInt *elem_info, const */ void CFEMesh::ConfigHighOrderElements() { - int k; - size_t i, kk; - - CEdge *edge = NULL; - CElem *elem = NULL; - - int egde_line[] = {2}; - int egde_tri[] = {3, 4, 5}; - int egde_quad[] = {4, 5, 6, 7}; - int egde_tet[] = {4, 5, 6, 7, 8, 9}; - int egde_hex[] = {8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}; - int egde_pri[] = {6, 7, 8, 9, 10, 11, 12, 13, 14}; - - int *middle_node = NULL; - - - //TEST - //int myrank; - //MPI_Comm_rank(MPI_COMM_WORLD,&myrank); - - /* - for(i=0; iSetMark(false); - } - */ - - const size_t e_size = ele_vector.size(); - - for(i=0; inodes.resize(elem->nnodesHQ); - for(k=0; knnodesHQ; k++) - elem->nodes[k] = nod_vector[elem->nodes_index[k]]; - - switch(elem->geo_type) - { - case MshElemType::LINE: - middle_node = egde_line; - break; - case MshElemType::QUAD: - middle_node = egde_quad; - break; - case MshElemType::HEXAHEDRON: - middle_node = egde_hex; - break; - case MshElemType::TRIANGLE: - middle_node = egde_tri; - break; - case MshElemType::TETRAHEDRON: - middle_node = egde_tet; - break; - case MshElemType::PRISM: - middle_node = egde_pri; - break; - case MshElemType::PYRAMID: - break; - default: - break; - } - - - //Edges - for(kk=0; kknedges; kk++) - { - edge = elem->edges[kk]; - - // if(edge->GetMark()) - // continue; - - - edge->SetNode(2, elem->nodes[middle_node[kk]]); - - //TEST - //if(myrank == 0) - // edge->Write(); - // edge->SetMark(true); - } - - } - /* - for(i=0; iSetMark(false); - } - */ - - CNode *node = NULL; - for (size_t e = 0; e < e_size; e++) - { - elem = ele_vector[e]; - for (int i = elem->nnodes; i < elem->nnodesHQ; i++) - { - bool done = false; - node = elem->GetNode(i); - for (int k = 0; k < (int) node->getConnectedElementIDs().size(); k++) - if (e == node->getConnectedElementIDs()[k]) - { - done = true; - break; - } - if (!done) - node->getConnectedElementIDs().push_back(e); - } - } - - // For sparse matrix - ConnectedNodes(true); - ConnectedElements2Node(true); - -} -// -int CFEMesh::calMaximumConnectedNodes() -{ - int max_connected_nodes = 0; - for(size_t i=0; i(nod_vector[i]->getNumConnectedNodes()); - if(k > max_connected_nodes) - max_connected_nodes = k; - } + CEdge* edge = NULL; + CElem* elem = NULL; - int msize; - //int mrank; - int *i_cnt; - int *i_disp; - int *i_recv; + int egde_line[] = {2}; + int egde_tri[] = {3, 4, 5}; + int egde_quad[] = {4, 5, 6, 7}; + int egde_tet[] = {4, 5, 6, 7, 8, 9}; + int egde_hex[] = {8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}; + int egde_pri[] = {6, 7, 8, 9, 10, 11, 12, 13, 14}; + int* middle_node = NULL; - MPI_Comm_size(MPI_COMM_WORLD,&msize); - //MPI_Comm_rank(MPI_COMM_WORLD,&mrank); + // TEST + // int myrank; + // MPI_Comm_rank(MPI_COMM_WORLD,&myrank); - i_cnt = (int*)malloc(msize*sizeof(int)); - i_disp = (int*)malloc(msize*sizeof(int)); - i_recv = (int*)malloc(msize*sizeof(int)); - - for(int i=0; iSetMark(false); + } + */ - max_connected_nodes = 0; - for(int i=0; i max_connected_nodes) - max_connected_nodes = i_recv[i]; + for (i = 0; i < e_size; i++) + { + elem = ele_vector[i]; + + // Nodes + elem->nodes.resize(elem->nnodesHQ); + for (k = 0; k < elem->nnodesHQ; k++) + elem->nodes[k] = nod_vector[elem->nodes_index[k]]; + + switch (elem->geo_type) + { + case MshElemType::LINE: + middle_node = egde_line; + break; + case MshElemType::QUAD: + middle_node = egde_quad; + break; + case MshElemType::HEXAHEDRON: + middle_node = egde_hex; + break; + case MshElemType::TRIANGLE: + middle_node = egde_tri; + break; + case MshElemType::TETRAHEDRON: + middle_node = egde_tet; + break; + case MshElemType::PRISM: + middle_node = egde_pri; + break; + case MshElemType::PYRAMID: + break; + default: + break; + } + + // Edges + for (kk = 0; kk < elem->nedges; kk++) + { + edge = elem->edges[kk]; + + // if(edge->GetMark()) + // continue; + + edge->SetNode(2, elem->nodes[middle_node[kk]]); + + // TEST + // if(myrank == 0) + // edge->Write(); + // edge->SetMark(true); + } + } + /* + for(i=0; iSetMark(false); + } + */ - } - free(i_cnt); - free(i_recv); - free(i_disp); + CNode* node = NULL; + for (size_t e = 0; e < e_size; e++) + { + elem = ele_vector[e]; + for (int i = elem->nnodes; i < elem->nnodesHQ; i++) + { + bool done = false; + node = elem->GetNode(i); + for (int k = 0; k < (int)node->getConnectedElementIDs().size(); k++) + if (e == node->getConnectedElementIDs()[k]) + { + done = true; + break; + } + if (!done) + node->getConnectedElementIDs().push_back(e); + } + } - return max_connected_nodes; + // For sparse matrix + ConnectedNodes(true); + ConnectedElements2Node(true); } - - -} //end namespace - - -void BuildNodeStruc(MeshNodes *anode, MPI_Datatype *MPI_Node_ptr) +// +int CFEMesh::calMaximumConnectedNodes() { - MPI_Datatype my_comp_type[4]; - int nblocklen[4]; - MPI_Aint disp[4], base; - int j; - - my_comp_type[0] = MPI_LONG; - my_comp_type[1] = MPI_DOUBLE; - my_comp_type[2] = MPI_DOUBLE; - my_comp_type[3] = MPI_DOUBLE; - nblocklen[0] = 1; - nblocklen[1] = 1; - nblocklen[2] = 1; - nblocklen[3] = 1; + int max_connected_nodes = 0; + for (size_t i = 0; i < nod_vector.size(); i++) + { + const int k = static_cast(nod_vector[i]->getNumConnectedNodes()); + if (k > max_connected_nodes) + max_connected_nodes = k; + } + int msize; + // int mrank; + int* i_cnt; + int* i_disp; + int* i_recv; - // Compute displacement of struct MeshNodes + MPI_Comm_size(MPI_COMM_WORLD, &msize); + // MPI_Comm_rank(MPI_COMM_WORLD,&mrank); - /* - disp[0] = 0; - MPI_Get_address(&(anode.nnodes),&base); - MPI_Get_address(&(anode.index), disp+1); - disp[1] -= base; - MPI_Get_address(&(anode.coord),disp+2); - disp[2] -= base; + i_cnt = (int*)malloc(msize * sizeof(int)); + i_disp = (int*)malloc(msize * sizeof(int)); + i_recv = (int*)malloc(msize * sizeof(int)); - for (j=0; j <3; j++) - { + for (int i = 0; i < msize; i++) + { + i_cnt[i] = 1; + i_disp[i] = i; + } - cout<<"j=" < max_connected_nodes) + max_connected_nodes = i_recv[i]; + } + free(i_cnt); + free(i_recv); + free(i_disp); + return max_connected_nodes; +} - MPI_Get_address(anode, disp); - MPI_Get_address(&(anode[0].x), disp+1); - MPI_Get_address(&(anode[0].y), disp+2); - MPI_Get_address(&(anode[0].z), disp+3); - base = disp[0]; - for (j=0; j <4; j++) - { - disp[j] -= base; +} // end namespace - // cout<<"j=" < #include #include -#include //WW +#include //WW #include #include #include @@ -34,7 +34,7 @@ // MathLib #include "MathTools.h" #include "Vector3.h" -//WW #include "msh_lib.h" +// WW #include "msh_lib.h" #include "rf_mmp_new.h" // MSHLib @@ -58,11 +58,11 @@ extern std::string GetLineFromFile1(std::ifstream*); #define noMSH_CHECK -size_t max_dim = 0; //OK411 +size_t max_dim = 0; // OK411 -//class ThreadParameter +// class ThreadParameter //{ -//public: +// public: // ThreadParameter(GEOLIB::Point const* const pnt, size_t start, size_t end, // std::vector const& nod_vector, size_t id) : // _pnt(pnt), _start(start), _end(end), _nod_vector(nod_vector), _number( @@ -79,8 +79,8 @@ size_t max_dim = 0; //OK411 // size_t _id; //}; -//extern "C" { -//void* threadGetDist(void* ptr) +// extern "C" { +// void* threadGetDist(void* ptr) //{ // ThreadParameter* thread_param((ThreadParameter*) (ptr)); // size_t start(thread_param->_start); @@ -121,38 +121,35 @@ namespace MeshLib Programing: 03/2005 OK Implementation **************************************************************************/ -CFEMesh::CFEMesh(GEOLIB::GEOObjects* geo_obj, std::string* geo_name) : - max_mmp_groups(0), msh_max_dim(0), _geo_obj(geo_obj), _geo_name(geo_name), - _ele_type(MshElemType::INVALID), _n_msh_layer(0), _cross_section( - false), _msh_n_lines(0), _msh_n_quads(0), _msh_n_hexs(0), - _msh_n_tris(0), _msh_n_tets(0), _msh_n_prisms(0), _msh_n_pyras(0), - _min_edge_length(1e-3), _search_length(0.0), NodesNumber_Linear(0), - NodesNumber_Quadratic(0), useQuadratic(false), _axisymmetry(false), ncols(0), nrows(0), - x0(0.0), y0(0.0), csize(0.0), ndata_v(0.0), _mesh_grid(NULL) +CFEMesh::CFEMesh(GEOLIB::GEOObjects* geo_obj, std::string* geo_name) + : max_mmp_groups(0), msh_max_dim(0), _geo_obj(geo_obj), _geo_name(geo_name), _ele_type(MshElemType::INVALID), + _n_msh_layer(0), _cross_section(false), _msh_n_lines(0), _msh_n_quads(0), _msh_n_hexs(0), _msh_n_tris(0), + _msh_n_tets(0), _msh_n_prisms(0), _msh_n_pyras(0), _min_edge_length(1e-3), _search_length(0.0), + NodesNumber_Linear(0), NodesNumber_Quadratic(0), useQuadratic(false), _axisymmetry(false), ncols(0), nrows(0), + x0(0.0), y0(0.0), csize(0.0), ndata_v(0.0), _mesh_grid(NULL) { coordinate_system = 1; - max_ele_dim = 0; //NW - pcs_name = "NotSpecified"; //WW + max_ele_dim = 0; // NW + pcs_name = "NotSpecified"; // WW PT = NULL; // WW+TK - fm_pcs = NULL; //WW - // 1.11.2007 WW + fm_pcs = NULL; // WW +// 1.11.2007 WW #ifdef NEW_EQS sparse_graph = NULL; sparse_graph_H = NULL; #endif - map_counter = 0; //21.01.2009 WW - mapping_check = false; //23.01.2009 WW - has_multi_dim_ele = false; //NW + map_counter = 0; // 21.01.2009 WW + mapping_check = false; // 23.01.2009 WW + has_multi_dim_ele = false; // NW top_surface_checked = false; // 07.06.2010. WW - nodes_are_sorted=false; + nodes_are_sorted = false; } // Copy-Constructor for CFEMeshes. // Programming: 2010/11/10 KR -CFEMesh::CFEMesh(CFEMesh const& old_mesh) : - PT(NULL), _search_length(old_mesh._search_length), _mesh_grid(NULL) +CFEMesh::CFEMesh(CFEMesh const& old_mesh) : PT(NULL), _search_length(old_mesh._search_length), _mesh_grid(NULL) { std::cout << "Copying mesh object ... "; @@ -160,10 +157,10 @@ CFEMesh::CFEMesh(CFEMesh const& old_mesh) : size_t nNodes = old_mesh.nod_vector.size(); for (size_t i = 0; i < nNodes; i++) // MeshLib::CNode* node = new MeshLib::CNode(i); - // double coords[3] = { old_mesh.nod_vector[i]->X(), old_mesh.nod_vector[i]->Y(), old_mesh.nod_vector[i]->Z() }; + // double coords[3] = { old_mesh.nod_vector[i]->X(), old_mesh.nod_vector[i]->Y(), + // old_mesh.nod_vector[i]->Z() }; // node->SetCoordinates(coords); - this->nod_vector.push_back(new MeshLib::CNode(i, - old_mesh.nod_vector[i]->getData())); + this->nod_vector.push_back(new MeshLib::CNode(i, old_mesh.nod_vector[i]->getData())); // mesh elements size_t nElems = old_mesh.ele_vector.size(); @@ -184,7 +181,8 @@ CFEMesh::CFEMesh(CFEMesh const& old_mesh) : this->setNumberOfMeshLayers(old_mesh.getNumberOfMeshLayers()); this->ConstructGrid(); - std::cout << "done." << "\n"; + std::cout << "done." + << "\n"; } /************************************************************************** @@ -228,13 +226,13 @@ CFEMesh::~CFEMesh(void) delete face_normal[i]; face_normal.clear(); - if(PT) //WW + if (PT) // WW { - delete PT; // PCH - PT = NULL; + delete PT; // PCH + PT = NULL; } - // 1.11.2007 WW +// 1.11.2007 WW #ifdef NEW_EQS delete sparse_graph; delete sparse_graph_H; @@ -242,10 +240,10 @@ CFEMesh::~CFEMesh(void) sparse_graph_H = NULL; #endif - if(_mesh_grid) + if (_mesh_grid) { - delete _mesh_grid; - _mesh_grid = NULL; + delete _mesh_grid; + _mesh_grid = NULL; } } @@ -319,8 +317,7 @@ void CFEMesh::computeMinEdgeLength() { const double kth_edge_length(edge_vector[k]->getLength()); if (kth_edge_length < _min_edge_length) - _min_edge_length - = kth_edge_length; + _min_edge_length = kth_edge_length; } } } @@ -339,26 +336,30 @@ void CFEMesh::computeSearchLength(double c) { const size_t n(edge_vector.size()); - if (n==0) { - std::cerr << "[CFEMesh::computeSearchLength] no edges found for computing _search_length, setting _search_lenght to " << 1e-3 << "\n"; + if (n == 0) + { + std::cerr + << "[CFEMesh::computeSearchLength] no edges found for computing _search_length, setting _search_lenght to " + << 1e-3 << "\n"; _search_length = 1e-3; return; } - double sum (0); - double sum_of_sqr (0); + double sum(0); + double sum_of_sqr(0); - for (size_t k(0); k < n; k++) { - const double x_k (edge_vector[k]->getLength()); + for (size_t k(0); k < n; k++) + { + const double x_k(edge_vector[k]->getLength()); sum += x_k; sum_of_sqr += (x_k * x_k); } // criterion: mu - c times s, where mu is the average and s is standard deviation - const double mu (sum/n); + const double mu(sum / n); - const double diff = fabs(sum_of_sqr - (sum*sum)/n); - if(diff < std::numeric_limits::epsilon()) + const double diff = fabs(sum_of_sqr - (sum * sum) / n); + if (diff < std::numeric_limits::epsilon()) { // In case all edges have the same length _search_length = 0.5 * mu; @@ -366,14 +367,17 @@ void CFEMesh::computeSearchLength(double c) } else { - const double s (sqrt(1.0/(n-1) * diff)); - while (mu < c * s) { + const double s(sqrt(1.0 / (n - 1) * diff)); + while (mu < c * s) + { c *= 0.9; } _search_length = mu - c * s; #ifndef NDEBUG - if (c < 2) { - std::cerr << "[CFEMesh::computeSearchLength] computed _search_length = " << _search_length << ", the average value is: " << mu << ", standard deviation is: " << s << "\n"; + if (c < 2) + { + std::cerr << "[CFEMesh::computeSearchLength] computed _search_length = " << _search_length + << ", the average value is: " << mu << ", standard deviation is: " << s << "\n"; } #endif } @@ -394,7 +398,7 @@ bool CFEMesh::Read(std::ifstream* fem_file) { std::string line_string; - bool more_mesh = false; //12.08.2011. WW + bool more_mesh = false; // 12.08.2011. WW while (!fem_file->eof()) { @@ -403,19 +407,19 @@ bool CFEMesh::Read(std::ifstream* fem_file) // check keywords if (line_string.find("#STOP") != std::string::npos) { - more_mesh = false; //12.08.2011. WW + more_mesh = false; // 12.08.2011. WW break; } - if (line_string.find("#FEM_MSH") != std::string::npos) //12.08.2011. WW + if (line_string.find("#FEM_MSH") != std::string::npos) // 12.08.2011. WW { more_mesh = true; break; } else if (line_string.find("$PCS_TYPE") != std::string::npos) - *fem_file >> pcs_name >> std::ws; //WW + *fem_file >> pcs_name >> std::ws; // WW else if (line_string.find("$GEO_NAME") != std::string::npos) - *fem_file >> geo_name >> std::ws; //WW + *fem_file >> geo_name >> std::ws; // WW else if (line_string.find("$GEO_TYPE") != std::string::npos) *fem_file >> geo_type_name >> geo_name >> std::ws; else if (line_string.find("$AXISYMMETRY") != std::string::npos) @@ -451,13 +455,12 @@ bool CFEMesh::Read(std::ifstream* fem_file) { CElem* newElem(new CElem(i)); newElem->Read(*fem_file); - setElementType(newElem->geo_type); //CC02/2006 + setElementType(newElem->geo_type); // CC02/2006 if (newElem->GetPatchIndex() > max_mmp_groups) max_mmp_groups = newElem->GetPatchIndex(); - //NW + // NW if (newElem->GetDimension() > this->max_ele_dim) - this->max_ele_dim - = newElem->GetDimension(); + this->max_ele_dim = newElem->GetDimension(); ele_vector.push_back(newElem); } } @@ -488,9 +491,7 @@ void CFEMesh::ConnectedElements2Node(bool quadratic) if (!elem->GetMark()) continue; - size_t - nElemNodes( - static_cast (elem->GetNodesNumber(quadratic))); + size_t nElemNodes(static_cast(elem->GetNodesNumber(quadratic))); for (size_t i = 0; i < nElemNodes; i++) { MeshLib::CNode* node(nod_vector[elem->GetNodeIndex(i)]); @@ -538,7 +539,8 @@ void CFEMesh::ConstructGrid() // 2011-11-21 TF // initializing attributes of objects - why is this not done in the constructor? - for (size_t e = 0; e < e_size; e++) { + for (size_t e = 0; e < e_size; e++) + { ele_vector[e]->InitializeMembers(); } @@ -552,7 +554,7 @@ void CFEMesh::ConstructGrid() for (size_t i = 0; i < nnodes0; i++) // Nodes e_nodes0[i] = nod_vector[node_index[i]]; - size_t nFaces = static_cast (elem->GetFacesNumber()); + size_t nFaces = static_cast(elem->GetFacesNumber()); // neighbors for (size_t i = 0; i < nFaces; i++) // Faces { @@ -561,47 +563,32 @@ void CFEMesh::ConstructGrid() done = false; int faceIndex_loc0[10]; - size_t nFaceNodes = static_cast (elem->GetElementFaceNodes( - i, faceIndex_loc0)); - for (size_t k = 0; k < nFaceNodes; k++) //face nodes + size_t nFaceNodes = static_cast(elem->GetElementFaceNodes(i, faceIndex_loc0)); + for (size_t k = 0; k < nFaceNodes; k++) // face nodes { - size_t - nConnElems( - e_nodes0[faceIndex_loc0[k]]->getConnectedElementIDs().size()); + size_t nConnElems(e_nodes0[faceIndex_loc0[k]]->getConnectedElementIDs().size()); for (size_t ei = 0; ei < nConnElems; ei++) // elements connected to face node { - size_t - ee( - static_cast (e_nodes0[faceIndex_loc0[k]]-> - getConnectedElementIDs()[ei])); + size_t ee(static_cast(e_nodes0[faceIndex_loc0[k]]->getConnectedElementIDs()[ei])); if (ee == e) continue; CElem* connElem(ele_vector[ee]); - const Math_Group::vec& node_index_glb( - connElem->GetNodeIndeces()); + const Math_Group::vec& node_index_glb(connElem->GetNodeIndeces()); connElem->GetNeighbors(Neighbors); - size_t nFacesConnElem = - static_cast (connElem->GetFacesNumber()); + size_t nFacesConnElem = static_cast(connElem->GetFacesNumber()); int faceIndex_loc[10]; for (size_t ii = 0; ii < nFacesConnElem; ii++) // faces of elements connected to face node { - size_t - nFaceNodesConnElem( - static_cast (connElem-> - GetElementFaceNodes( - ii, - faceIndex_loc))); + size_t nFaceNodesConnElem( + static_cast(connElem->GetElementFaceNodes(ii, faceIndex_loc))); if (nFaceNodes != nFaceNodesConnElem) continue; size_t counter(0); for (size_t j = 0; j < nFaceNodes; j++) { - for (size_t jj = 0; jj < nFaceNodesConnElem; - jj++) - if (node_index[faceIndex_loc0[j]] - == node_index_glb[faceIndex_loc - [jj]]) + for (size_t jj = 0; jj < nFaceNodesConnElem; jj++) + if (node_index[faceIndex_loc0[j]] == node_index_glb[faceIndex_loc[jj]]) { counter++; break; @@ -625,7 +612,7 @@ void CFEMesh::ConstructGrid() } elem->SetNeighbors(Neighbors0); - if (elem->geo_type == MshElemType::LINE) //YD + if (elem->geo_type == MshElemType::LINE) // YD { size_t ii(0); for (size_t i = 0; i < nFaces; i++) @@ -634,19 +621,12 @@ void CFEMesh::ConstructGrid() size_t n0 = elem->GetElementFaceNodes(i, faceIndex_loc0); for (size_t k = 0; k < n0; k++) { - size_t - e_size_l = - e_nodes0[faceIndex_loc0[k]]->getConnectedElementIDs() - .size(); + size_t e_size_l = e_nodes0[faceIndex_loc0[k]]->getConnectedElementIDs().size(); for (size_t ei = 0; ei < e_size_l; ei++) { - size_t - ee = - e_nodes0[faceIndex_loc0[k]]-> - getConnectedElementIDs()[ei]; + size_t ee = e_nodes0[faceIndex_loc0[k]]->getConnectedElementIDs()[ei]; CElem* connElem = ele_vector[ee]; - if (e_size_l == 2 && connElem->GetIndex() - != elem->GetIndex()) + if (e_size_l == 2 && connElem->GetIndex() != elem->GetIndex()) { Neighbors0[i] = connElem; Neighbors[ii] = connElem; @@ -671,48 +651,35 @@ void CFEMesh::ConstructGrid() done = false; for (size_t k = 0; k < 2; k++) // beginning and end of edge { - size_t - nConnElem( - e_nodes0[edgeIndex_loc0[k]]->getConnectedElementIDs().size()); + size_t nConnElem(e_nodes0[edgeIndex_loc0[k]]->getConnectedElementIDs().size()); for (size_t ei = 0; ei < nConnElem; ei++) // elements connected to edge node { - size_t - ee( - e_nodes0[edgeIndex_loc0[k]]->getConnectedElementIDs( - )[ei]); + size_t ee(e_nodes0[edgeIndex_loc0[k]]->getConnectedElementIDs()[ei]); if (ee == e) continue; CElem* connElem(ele_vector[ee]); - const Math_Group::vec& node_index_glb( - connElem->GetNodeIndeces()); + const Math_Group::vec& node_index_glb(connElem->GetNodeIndeces()); size_t nedges(connElem->GetEdgesNumber()); connElem->GetEdges(Edges); // Edges of neighbors int edgeIndex_loc[2]; for (size_t ii = 0; ii < nedges; ii++) // edges of element connected to edge node { - connElem->GetLocalIndicesOfEdgeNodes(ii, - edgeIndex_loc); - - if ((node_index[edgeIndex_loc0[0]] - == node_index_glb[edgeIndex_loc[0]] - && node_index[edgeIndex_loc0[1]] - == node_index_glb[edgeIndex_loc[1]]) - || (node_index[edgeIndex_loc0[0]] - == node_index_glb[edgeIndex_loc[1]] + connElem->GetLocalIndicesOfEdgeNodes(ii, edgeIndex_loc); + + if ((node_index[edgeIndex_loc0[0]] == node_index_glb[edgeIndex_loc[0]] + && node_index[edgeIndex_loc0[1]] == node_index_glb[edgeIndex_loc[1]]) + || (node_index[edgeIndex_loc0[0]] == node_index_glb[edgeIndex_loc[1]] && node_index[edgeIndex_loc0[1]] - == node_index_glb[edgeIndex_loc[0]])) // check if elements share edge + == node_index_glb[edgeIndex_loc[0]])) // check if elements share edge if (Edges[ii]) { Edges0[i] = Edges[ii]; Edges[ii]->GetNodes(e_edgeNodes); - if ((size_t) node_index[ - edgeIndex_loc0[0]] - == e_edgeNodes[1]->GetIndex() - && (size_t) node_index[ - edgeIndex_loc0[1]] - == e_edgeNodes[0]->GetIndex()) // check direction of edge + if ((size_t)node_index[edgeIndex_loc0[0]] == e_edgeNodes[1]->GetIndex() + && (size_t)node_index[edgeIndex_loc0[1]] + == e_edgeNodes[0]->GetIndex()) // check direction of edge Edge_Orientation[i] = -1; done = true; break; @@ -723,10 +690,10 @@ void CFEMesh::ConstructGrid() } // for(ei=0; eiSetOrder(false); e_edgeNodes0[0] = e_nodes0[edgeIndex_loc0[0]]; e_edgeNodes0[1] = e_nodes0[edgeIndex_loc0[1]]; @@ -735,8 +702,8 @@ void CFEMesh::ConstructGrid() edge_vector.push_back(Edges0[i]); } // new edges } // for(i=0; iSetOrder(false); elem->SetEdgesOrientation(Edge_Orientation); elem->SetEdges(Edges0); @@ -757,36 +724,36 @@ void CFEMesh::ConstructGrid() CElem* elem(ele_vector[e]); switch (elem->GetElementType()) { - case MshElemType::LINE: - _msh_n_lines++; - break; - case MshElemType::QUAD: - _msh_n_quads++; - break; - case MshElemType::HEXAHEDRON: - _msh_n_hexs++; - break; - case MshElemType::TRIANGLE: - _msh_n_tris++; - break; - case MshElemType::TETRAHEDRON: - _msh_n_tets++; - break; - case MshElemType::PRISM: - _msh_n_prisms++; - break; - case MshElemType::PYRAMID: - _msh_n_pyras++; - break; - default: - std::cerr << "CFEMesh::ConstructGrid MshElemType not handled" - << "\n"; + case MshElemType::LINE: + _msh_n_lines++; + break; + case MshElemType::QUAD: + _msh_n_quads++; + break; + case MshElemType::HEXAHEDRON: + _msh_n_hexs++; + break; + case MshElemType::TRIANGLE: + _msh_n_tris++; + break; + case MshElemType::TETRAHEDRON: + _msh_n_tets++; + break; + case MshElemType::PRISM: + _msh_n_prisms++; + break; + case MshElemType::PYRAMID: + _msh_n_pyras++; + break; + default: + std::cerr << "CFEMesh::ConstructGrid MshElemType not handled" + << "\n"; } // Compute volume meanwhile elem->ComputeVolume(); if (elem->GetElementType() == MshElemType::LINE) - continue; // line element + continue; // line element // thisElem0->GetNodeIndeces(node_index_glb0); // const vec& node_index_glb0 (thisElem0->GetNodeIndeces()); // compiler said: unused variable // TF elem->GetNeighbors(Neighbors0); @@ -797,7 +764,7 @@ void CFEMesh::ConstructGrid() { if (Neighbors0[i]) continue; - CElem* newFace = new CElem((long) face_vector.size(), elem, i); + CElem* newFace = new CElem((long)face_vector.size(), elem, i); // thisElem0->boundary_type='B'; elem->no_faces_on_surface++; face_vector.push_back(newFace); @@ -806,7 +773,7 @@ void CFEMesh::ConstructGrid() elem->SetNeighbors(Neighbors0); } #if !defined(USE_PETSC) // &&! defined(USE_OTHER Parallel solver lib) //WW 06.2013 - NodesNumber_Quadratic = (long) nod_vector.size(); + NodesNumber_Quadratic = (long)nod_vector.size(); #endif if ((_msh_n_hexs + _msh_n_tets + _msh_n_prisms + _msh_n_pyras) > 0) max_ele_dim = 3; @@ -816,11 +783,10 @@ void CFEMesh::ConstructGrid() max_ele_dim = 1; // check if this mesh includes multi-dimensional elements - if (max_ele_dim == 2 && _msh_n_lines > 0) //NW + if (max_ele_dim == 2 && _msh_n_lines > 0) // NW this->has_multi_dim_ele = true; - else if (max_ele_dim == 3 && (_msh_n_quads + _msh_n_tris + _msh_n_lines) - > 0) + else if (max_ele_dim == 3 && (_msh_n_quads + _msh_n_tris + _msh_n_lines) > 0) this->has_multi_dim_ele = true; //---------------------------------------------------------------------- @@ -829,10 +795,10 @@ void CFEMesh::ConstructGrid() // 2. Coordiate system flag double x_sum(0.0), y_sum(0.0), z_sum(0.0); Eqs2Global_NodeIndex.clear(); - double xyz_max[3] = //NW - { -DBL_MAX, -DBL_MAX, -DBL_MAX }; - double xyz_min[3] = //NW - { DBL_MAX, DBL_MAX, DBL_MAX }; + double xyz_max[3] = // NW + {-DBL_MAX, -DBL_MAX, -DBL_MAX}; + double xyz_min[3] = // NW + {DBL_MAX, DBL_MAX, DBL_MAX}; for (size_t e = 0; e < nod_vector.size(); e++) { @@ -859,50 +825,44 @@ void CFEMesh::ConstructGrid() if (coords[2] < xyz_min[2]) xyz_min[2] = coords[2]; } - double xyz_dim[3]; //NW + double xyz_dim[3]; // NW xyz_dim[0] = xyz_max[0] - xyz_min[0]; xyz_dim[1] = xyz_max[1] - xyz_min[1]; xyz_dim[2] = xyz_max[2] - xyz_min[2]; - //check dimension of the domain to select appropriate coordinate system - if (xyz_dim[0] > 0.0 && xyz_dim[1] < MKleinsteZahl && xyz_dim[2] - < MKleinsteZahl) // only x-direction + // check dimension of the domain to select appropriate coordinate system + if (xyz_dim[0] > 0.0 && xyz_dim[1] < MKleinsteZahl && xyz_dim[2] < MKleinsteZahl) // only x-direction coordinate_system = 10; - else if (xyz_dim[1] > 0.0 && xyz_dim[0] < MKleinsteZahl && xyz_dim[2] - < MKleinsteZahl) // only y-direction + else if (xyz_dim[1] > 0.0 && xyz_dim[0] < MKleinsteZahl && xyz_dim[2] < MKleinsteZahl) // only y-direction coordinate_system = 11; - else if (xyz_dim[2] > 0.0 && xyz_dim[0] < MKleinsteZahl && xyz_dim[1] - < MKleinsteZahl) // only z-direction + else if (xyz_dim[2] > 0.0 && xyz_dim[0] < MKleinsteZahl && xyz_dim[1] < MKleinsteZahl) // only z-direction coordinate_system = 12; else if (xyz_dim[0] > 0.0 && xyz_dim[1] > 0.0 && xyz_dim[2] < MKleinsteZahl) - coordinate_system = 21; // x & y direction + coordinate_system = 21; // x & y direction else if (xyz_dim[0] > 0.0 && xyz_dim[2] > 0.0 && xyz_dim[1] < MKleinsteZahl) - coordinate_system = 22; // x & z direction + coordinate_system = 22; // x & z direction else if (xyz_dim[1] > 0.0 && xyz_dim[2] > 0.0 && xyz_dim[0] < MKleinsteZahl) - coordinate_system = 23; // y & z direction - else if (xyz_dim[0] > 0.0 && xyz_dim[1] > 0.0 && xyz_dim[2] > 0.0) // x, y & z direction - coordinate_system - = 32; + coordinate_system = 23; // y & z direction + else if (xyz_dim[0] > 0.0 && xyz_dim[1] > 0.0 && xyz_dim[2] > 0.0) // x, y & z direction + coordinate_system = 32; // 1D in 2D if (_msh_n_lines > 0) { if (xyz_dim[0] > 0.0 && xyz_dim[1] > 0.0 && xyz_dim[2] < MKleinsteZahl) - coordinate_system - = 32; + coordinate_system = 32; if (xyz_dim[0] > 0.0 && xyz_dim[2] > 0.0 && xyz_dim[1] < MKleinsteZahl) - coordinate_system - = 32; + coordinate_system = 32; } max_dim = coordinate_system / 10 - 1; //---------------------------------------------------------------------- // Gravity center for (size_t e = 0; e < e_size; e++) - ele_vector[e]->ComputeGravityCenter(); //NW + ele_vector[e]->ComputeGravityCenter(); // NW //---------------------------------------------------------------------- - //TEST WW + // TEST WW // For sparse matrix ConnectedNodes(false); // @@ -916,9 +876,10 @@ void CFEMesh::ConstructGrid() Neighbors0.resize(0); e_edgeNodes0.resize(0); e_edgeNodes.resize(0); - std::cout << " done." << "\n"; + std::cout << " done." + << "\n"; - //computeSearchLength(); + // computeSearchLength(); computeMinEdgeLength(); setSearchLength(_min_edge_length / 2); constructMeshGrid(); @@ -926,16 +887,16 @@ void CFEMesh::ConstructGrid() void CFEMesh::constructMeshGrid() { -//#ifndef NDEBUG -// std::cout << "CFEMesh::constructMeshGrid() ... " << std::flush; -// clock_t start(clock()); -//#endif + //#ifndef NDEBUG + // std::cout << "CFEMesh::constructMeshGrid() ... " << std::flush; + // clock_t start(clock()); + //#endif if (_mesh_grid == NULL) _mesh_grid = new GEOLIB::Grid(this->getNodeVector(), 511); -//#ifndef NDEBUG -// clock_t end(clock()); -// std::cout << "done, took " << (end-start)/(double)(CLOCKS_PER_SEC) << " s -- " << std::flush; -//#endif + //#ifndef NDEBUG + // clock_t end(clock()); + // std::cout << "done, took " << (end-start)/(double)(CLOCKS_PER_SEC) << " s -- " << std::flush; + //#endif } /************************************************************************** @@ -952,10 +913,10 @@ void CFEMesh::GenerateHighOrderNodes() long e, ei, ee, e_size_l; int edgeIndex_loc0[2]; bool done; - double x0 = 0.0, y0 = 0.0, z0 = 0.0; //OK411 + double x0 = 0.0, y0 = 0.0, z0 = 0.0; // OK411 // Set neighbors of node. All elements, even in deactivated subdomains, are taken into account here. - for (e = 0; e < (long) nod_vector.size(); e++) + for (e = 0; e < (long)nod_vector.size(); e++) nod_vector[e]->getConnectedElementIDs().clear(); done = false; size_t ele_vector_size(ele_vector.size()); @@ -966,8 +927,7 @@ void CFEMesh::GenerateHighOrderNodes() { done = false; long ni = thisElem0->GetNodeIndex(i); - size_t n_connected_elements( - nod_vector[ni]->getConnectedElementIDs().size()); + size_t n_connected_elements(nod_vector[ni]->getConnectedElementIDs().size()); for (size_t j = 0; j < n_connected_elements; j++) if (e == nod_vector[ni]->getConnectedElementIDs()[j]) { @@ -993,7 +953,7 @@ void CFEMesh::GenerateHighOrderNodes() { thisElem0 = ele_vector[e]; if (thisElem0->GetElementType() == MshElemType::LINE) - continue; //NW + continue; // NW nnodes0 = thisElem0->nnodes; // Number of nodes for linear element // thisElem0->GetNodeIndeces(node_index_glb0); @@ -1011,15 +971,10 @@ void CFEMesh::GenerateHighOrderNodes() done = false; for (k = 0; k < 2; k++) { - e_size_l - = (long) e_nodes0[edgeIndex_loc0[k]]-> - getConnectedElementIDs().size(); + e_size_l = (long)e_nodes0[edgeIndex_loc0[k]]->getConnectedElementIDs().size(); for (ei = 0; ei < e_size_l; ei++) { - size_t - ee( - e_nodes0[edgeIndex_loc0[k]]->getConnectedElementIDs( - )[ei]); + size_t ee(e_nodes0[edgeIndex_loc0[k]]->getConnectedElementIDs()[ei]); if (ee == e) continue; thisElem = ele_vector[ee]; @@ -1045,20 +1000,16 @@ void CFEMesh::GenerateHighOrderNodes() } // for(ei=0; eiGetNode(0)->getData()); double const* const pnt1(thisEdge0->GetNode(1)->getData()); - aNode = - new CNode( - (long) nod_vector.size(), 0.5 * - (pnt0[0] + - pnt1[0]), 0.5 * - (pnt0[1] + pnt1[1]), 0.5 * (pnt0[2] + pnt1[2])); -// aNode->SetX(0.5 * (pnt0[0] + pnt1[0])); -// aNode->SetY(0.5 * (pnt0[1] + pnt1[1])); -// aNode->SetZ(0.5 * (pnt0[2] + pnt1[2])); + aNode = new CNode((long)nod_vector.size(), 0.5 * (pnt0[0] + pnt1[0]), 0.5 * (pnt0[1] + pnt1[1]), + 0.5 * (pnt0[2] + pnt1[2])); + // aNode->SetX(0.5 * (pnt0[0] + pnt1[0])); + // aNode->SetY(0.5 * (pnt0[1] + pnt1[1])); + // aNode->SetZ(0.5 * (pnt0[2] + pnt1[2])); e_nodes0[nnodes0] = aNode; thisEdge0->SetNode(2, aNode); nnodes0++; @@ -1072,7 +1023,7 @@ void CFEMesh::GenerateHighOrderNodes() if (thisElem0->GetElementType() == MshElemType::QUAD) { x0 = y0 = z0 = 0.0; - aNode = new CNode((long) nod_vector.size()); + aNode = new CNode((long)nod_vector.size()); e_nodes0[nnodes0] = aNode; nnodes0 = thisElem0->nnodes; for (int i = 0; i < nnodes0; i++) // Nodes @@ -1082,9 +1033,9 @@ void CFEMesh::GenerateHighOrderNodes() y0 += pnt_i[1]; z0 += pnt_i[2]; } - x0 /= (double) nnodes0; - y0 /= (double) nnodes0; - z0 /= (double) nnodes0; + x0 /= (double)nnodes0; + y0 /= (double)nnodes0; + z0 /= (double)nnodes0; aNode->SetX(x0); aNode->SetY(y0); aNode->SetZ(z0); @@ -1128,18 +1079,14 @@ void CFEMesh::GenerateHighOrderNodes() // Check neighbors for (k = 0; k < 2; k++) { - //OK411 CNode *tmp_nod = e_nodes[edgeIndex_loc0[k]]; - e_size_l - = (long) e_nodes[edgeIndex_loc0[k]]-> - getConnectedElementIDs().size(); + // OK411 CNode *tmp_nod = e_nodes[edgeIndex_loc0[k]]; + e_size_l = (long)e_nodes[edgeIndex_loc0[k]]->getConnectedElementIDs().size(); for (ei = 0; ei < e_size_l; ei++) { - ee - = e_nodes[edgeIndex_loc0[k]]-> - getConnectedElementIDs()[ei]; + ee = e_nodes[edgeIndex_loc0[k]]->getConnectedElementIDs()[ei]; if (ele_vector[ee] != thisElem0) continue; - //the edge is found now + // the edge is found now aNode = thisEdge->GetNode(2); if (aNode) // The middle point exist { @@ -1153,7 +1100,7 @@ void CFEMesh::GenerateHighOrderNodes() } // for(ei=0; eigetData()); @@ -1170,9 +1117,9 @@ void CFEMesh::GenerateHighOrderNodes() y0 += pnt_i[1]; z0 += pnt_i[2]; } - x0 /= (double) nnodes0; - y0 /= (double) nnodes0; - z0 /= (double) nnodes0; + x0 /= (double)nnodes0; + y0 /= (double)nnodes0; + z0 /= (double)nnodes0; aNode->SetX(x0); aNode->SetY(y0); aNode->SetZ(z0); @@ -1184,8 +1131,8 @@ void CFEMesh::GenerateHighOrderNodes() thisElem0->SetNodes(e_nodes0, true); } // - NodesNumber_Quadratic = (long) nod_vector.size(); - for (e = NodesNumber_Linear; (size_t) e < NodesNumber_Quadratic; e++) + NodesNumber_Quadratic = (long)nod_vector.size(); + for (e = NodesNumber_Linear; (size_t)e < NodesNumber_Quadratic; e++) { #if !defined(USE_PETSC) // && !defined(USE_OTHER Parallel solver lib) nod_vector[e]->SetEquationIndex(e); @@ -1199,7 +1146,7 @@ void CFEMesh::GenerateHighOrderNodes() { done = false; aNode = thisElem0->GetNode(i); - for (k = 0; k < (int) aNode->getConnectedElementIDs().size(); k++) + for (k = 0; k < (int)aNode->getConnectedElementIDs().size(); k++) if (e == aNode->getConnectedElementIDs()[k]) { done = true; @@ -1239,19 +1186,17 @@ void CFEMesh::FillTransformMatrix() // PCH CRFProcess* m_pcs = PCSGet("FLUID_MOMENTUM"); // - if ((_msh_n_hexs + _msh_n_tets + _msh_n_prisms + _msh_n_pyras) - == ele_vector.size()) + if ((_msh_n_hexs + _msh_n_tets + _msh_n_prisms + _msh_n_pyras) == ele_vector.size()) return; else if (coordinate_system != 32 && !this->has_multi_dim_ele) { if (m_pcs) - ; // Need to do FillTransformMatrix // PCH + ; // Need to do FillTransformMatrix // PCH else return; } bool tilted = false; - if (coordinate_system == 32 || coordinate_system == 21 || coordinate_system - == 22) + if (coordinate_system == 32 || coordinate_system == 21 || coordinate_system == 22) tilted = true; if (!tilted) return; @@ -1265,8 +1210,7 @@ void CFEMesh::FillTransformMatrix() if (elem->GetElementType() == MshElemType::LINE) elem->FillTransformMatrix(); } - else if (elem->GetElementType() == MshElemType::LINE - || elem->GetElementType() == MshElemType::QUAD + else if (elem->GetElementType() == MshElemType::LINE || elem->GetElementType() == MshElemType::QUAD || elem->GetElementType() == MshElemType::TRIANGLE) elem->FillTransformMatrix(); } @@ -1408,76 +1352,78 @@ void CFEMesh::RenumberNodesForGlobalAssembly() long CFEMesh::GetNODOnPNT(const GEOLIB::Point* const pnt) const { #if defined(USE_PETSC) // || defined (other parallel linear solver lib). //WW. 05.2012 - long node_id = -1; - - const size_t id_act_l_max = static_cast(getNumNodesLocal()); - const size_t id_act_h_min = GetNodesNumber(false); - const size_t id_act_h_max = getLargestActiveNodeID_Quadratic(); - - double sqr_dist = 0.0; - double distmin = getMinEdgeLength()/10.0; - if(distmin < 0.) - distmin = DBL_EPSILON; - - for (size_t i = 0; i < id_act_l_max; i++) - { - sqr_dist = MathLib::sqrDist (nod_vector[i]->getData(), pnt->getData()); - if ( sqrt(sqr_dist) < distmin) - { - node_id = i; - break; - } - } - - if(!useQuadratic) - return node_id; - - for (size_t i = id_act_h_min; i < id_act_h_max; i++) - { - sqr_dist = MathLib::sqrDist (nod_vector[i]->getData(), pnt->getData()); - if (sqrt(sqr_dist) < distmin) - { - node_id = i; - break; - } - } - return node_id; + long node_id = -1; + + const size_t id_act_l_max = static_cast(getNumNodesLocal()); + const size_t id_act_h_min = GetNodesNumber(false); + const size_t id_act_h_max = getLargestActiveNodeID_Quadratic(); + + double sqr_dist = 0.0; + double distmin = getMinEdgeLength() / 10.0; + if (distmin < 0.) + distmin = DBL_EPSILON; + + for (size_t i = 0; i < id_act_l_max; i++) + { + sqr_dist = MathLib::sqrDist(nod_vector[i]->getData(), pnt->getData()); + if (sqrt(sqr_dist) < distmin) + { + node_id = i; + break; + } + } + + if (!useQuadratic) + return node_id; + + for (size_t i = id_act_h_min; i < id_act_h_max; i++) + { + sqr_dist = MathLib::sqrDist(nod_vector[i]->getData(), pnt->getData()); + if (sqrt(sqr_dist) < distmin) + { + node_id = i; + break; + } + } + return node_id; #else - MeshLib::CNode const*const node (_mesh_grid->getNearestPoint(pnt->getData())); + MeshLib::CNode const* const node(_mesh_grid->getNearestPoint(pnt->getData())); return node->GetIndex(); #endif // END: if use_petsc -// const size_t nodes_in_usage(static_cast (NodesInUsage())); -// double sqr_dist(0.0), distmin(MathLib::sqrDist (nod_vector[0]->getData(), pnt->getData())); -// size_t number(0); -// for (size_t i = 1; i < nodes_in_usage; i++) -// { -// sqr_dist = MathLib::sqrDist (nod_vector[i]->getData(), pnt->getData()); -// if (sqr_dist < distmin) -// { -// distmin = sqr_dist; -// number = i; -// } -// } -// -// if (number != node_idx) { -// double const*const data0(nod_vector[node_idx]->getData()); -// double const*const data1(nod_vector[number]->getData()); -// std::cout << "pnt: "<< *pnt << " mesh grid node " << nod_vector[node_idx]->GetIndex() << ": " -// << data0[0] << " " << data0[1] << " " << data0[2] << -// ", mesh grid node (old algorithm) " << nod_vector[number]->GetIndex() << ": " -// << data1[0] << " " << data1[1] << " " << data1[2] << "\n"; -// std::cout << "bbx: " << _mesh_grid->getMinPoint() << " x " << _mesh_grid->getMaxPoint() << "\n"; -// size_t coords[3]; -// _mesh_grid->getGridCoords(pnt->getData(), coords); -// std::cout << "grid coords: " << coords[0] << " " << coords[1] << " " << coords[2] << "\n"; -// double llf[3], urb[3]; -// _mesh_grid->getGridCornerPoints(pnt->getData(), llf, urb); -// std::cout << "local bbx: " << llf[0] << " " << llf[1] << " " << llf[2] << " x " << urb[0] << " " << urb[1] << " " << urb[2] << "\n"; -// } -// -// return number; + // const size_t nodes_in_usage(static_cast (NodesInUsage())); + // double sqr_dist(0.0), distmin(MathLib::sqrDist (nod_vector[0]->getData(), pnt->getData())); + // size_t number(0); + // for (size_t i = 1; i < nodes_in_usage; i++) + // { + // sqr_dist = MathLib::sqrDist (nod_vector[i]->getData(), pnt->getData()); + // if (sqr_dist < distmin) + // { + // distmin = sqr_dist; + // number = i; + // } + // } + // + // if (number != node_idx) { + // double const*const data0(nod_vector[node_idx]->getData()); + // double const*const data1(nod_vector[number]->getData()); + // std::cout << "pnt: "<< *pnt << " mesh grid node " << nod_vector[node_idx]->GetIndex() << ": " + // << data0[0] << " " << data0[1] << " " << data0[2] << + // ", mesh grid node (old algorithm) " << nod_vector[number]->GetIndex() << ": " + // << data1[0] << " " << data1[1] << " " << data1[2] << "\n"; + // std::cout << "bbx: " << _mesh_grid->getMinPoint() << " x " << _mesh_grid->getMaxPoint() << "\n"; + // size_t coords[3]; + // _mesh_grid->getGridCoords(pnt->getData(), coords); + // std::cout << "grid coords: " << coords[0] << " " << coords[1] << " " << coords[2] << "\n"; + // double llf[3], urb[3]; + // _mesh_grid->getGridCornerPoints(pnt->getData(), llf, urb); + // std::cout << "local bbx: " << llf[0] << " " << llf[1] << " " << llf[2] << " x " << urb[0] << " " << urb[1] + //<< + //" " << urb[2] << "\n"; + // } + // + // return number; } /************************************************************************** @@ -1507,12 +1453,10 @@ long CFEMesh::GetNearestELEOnPNT(const GEOLIB::Point* const pnt) const return nextele; } -//WW. (x1-x0).(x2-x0) -inline double dotProduction(const double* x1, const double* x2, - const double* x0) +// WW. (x1-x0).(x2-x0) +inline double dotProduction(const double* x1, const double* x2, const double* x0) { - return (x1[0] - x0[0]) * (x2[0] - x0[0]) + (x1[1] - x0[1]) - * (x2[1] - x0[1]) + (x1[2] - x0[2]) * (x2[2] - x0[2]); + return (x1[0] - x0[0]) * (x2[0] - x0[0]) + (x1[1] - x0[1]) * (x2[1] - x0[1]) + (x1[2] - x0[2]) * (x2[2] - x0[2]); } /************************************************************************** @@ -1533,8 +1477,7 @@ void CFEMesh::GetNODOnPLY(const GEOLIB::Polyline* const ply, msh_nod_vector.clear(); // search for nodes along polyline in previous computed polylines - std::vector::const_iterator it( - _mesh_nodes_along_polylines.begin()); + std::vector::const_iterator it(_mesh_nodes_along_polylines.begin()); for (; it != _mesh_nodes_along_polylines.end(); it++) { if (it->getPolyline() == ply) @@ -1551,44 +1494,41 @@ void CFEMesh::GetNODOnPLY(const GEOLIB::Polyline* const ply, msh_nod_vector.push_back(node_ids[k]); #ifndef NDEBUG std::string ply_name; - if (! getGEOObjects()->getPolylineVecObj(*(getProjectName()))->getNameOfElement(ply, ply_name)) { + if (!getGEOObjects()->getPolylineVecObj(*(getProjectName()))->getNameOfElement(ply, ply_name)) + { ply_name = "unknown-ply"; } - std::cout << "[DEBUG-INFO] access " << msh_nod_vector.size() - << " buffered nodes for polyline " << ply_name << "\n"; + std::cout << "[DEBUG-INFO] access " << msh_nod_vector.size() << " buffered nodes for polyline " << ply_name + << "\n"; #endif return; } } // compute nodes (and supporting points) along polyline - double search_radius (this->getMinEdgeLength()); // getSearchLength()); + double search_radius(this->getMinEdgeLength()); // getSearchLength()); if (!automatic) search_radius = eps; - _mesh_nodes_along_polylines.push_back(MeshNodesAlongPolyline(ply, this, - search_radius)); - const std::vector - node_ids( - _mesh_nodes_along_polylines[_mesh_nodes_along_polylines.size() - - 1].getNodeIDs()); + _mesh_nodes_along_polylines.push_back(MeshNodesAlongPolyline(ply, this, search_radius)); + const std::vector node_ids( + _mesh_nodes_along_polylines[_mesh_nodes_along_polylines.size() - 1].getNodeIDs()); size_t n_valid_nodes(0); if (useQuadratic) n_valid_nodes = node_ids.size(); else - n_valid_nodes - = _mesh_nodes_along_polylines[_mesh_nodes_along_polylines.size() - - 1].getNumberOfLinearNodes(); + n_valid_nodes = _mesh_nodes_along_polylines[_mesh_nodes_along_polylines.size() - 1].getNumberOfLinearNodes(); for (size_t k(0); k < n_valid_nodes; k++) msh_nod_vector.push_back(node_ids[k]); #ifndef NDEBUG std::string ply_name; - if (! getGEOObjects()->getPolylineVecObj(*(getProjectName()))->getNameOfElement(ply, ply_name)) { + if (!getGEOObjects()->getPolylineVecObj(*(getProjectName()))->getNameOfElement(ply, ply_name)) + { ply_name = "unknown-ply"; } - std::cout << "[DEBUG-INFO] computed " << n_valid_nodes << " nodes for polyline " - << ply_name << " - " << NodesInUsage() << "\n"; + std::cout << "[DEBUG-INFO] computed " << n_valid_nodes << " nodes for polyline " << ply_name << " - " + << NodesInUsage() << "\n"; // std::string fname ("MeshNodeIDsAlongPolyline"+ply_name+".txt"); // std::ofstream os (fname.c_str()); @@ -1598,28 +1538,23 @@ void CFEMesh::GetNODOnPLY(const GEOLIB::Polyline* const ply, #endif } -const MeshNodesAlongPolyline& CFEMesh::GetMeshNodesAlongPolyline( - const GEOLIB::Polyline* const ply) +const MeshNodesAlongPolyline& CFEMesh::GetMeshNodesAlongPolyline(const GEOLIB::Polyline* const ply) { // search for nodes along polyline in previous computed polylines - std::vector::const_iterator it( - _mesh_nodes_along_polylines.begin()); + std::vector::const_iterator it(_mesh_nodes_along_polylines.begin()); for (; it != _mesh_nodes_along_polylines.end(); it++) if (it->getPolyline() == ply) return *it; - // compute nodes (and supporting points for interpolation) along polyline - double search_radius (this->getMinEdgeLength()); // getSearchLength()); - _mesh_nodes_along_polylines.push_back(MeshNodesAlongPolyline(ply, this, - search_radius)); + // compute nodes (and supporting points for interpolation) along polyline + double search_radius(this->getMinEdgeLength()); // getSearchLength()); + _mesh_nodes_along_polylines.push_back(MeshNodesAlongPolyline(ply, this, search_radius)); return _mesh_nodes_along_polylines[_mesh_nodes_along_polylines.size() - 1]; } -void CFEMesh::getPointsForInterpolationAlongPolyline( - const GEOLIB::Polyline* const ply, std::vector& points) +void CFEMesh::getPointsForInterpolationAlongPolyline(const GEOLIB::Polyline* const ply, std::vector& points) { // search for nodes along polyline in previous computed polylines - std::vector::const_iterator it( - _mesh_nodes_along_polylines.begin()); + std::vector::const_iterator it(_mesh_nodes_along_polylines.begin()); for (; it != _mesh_nodes_along_polylines.end(); it++) if (it->getPolyline() == ply) { @@ -1630,13 +1565,10 @@ void CFEMesh::getPointsForInterpolationAlongPolyline( } // compute nodes (and points according the nodes) along polyline - double search_radius (this->getMinEdgeLength()); // getSearchLength()); - _mesh_nodes_along_polylines.push_back( - MeshNodesAlongPolyline(ply, this, search_radius) - ); + double search_radius(this->getMinEdgeLength()); // getSearchLength()); + _mesh_nodes_along_polylines.push_back(MeshNodesAlongPolyline(ply, this, search_radius)); // copy supporting points from object into vector - for (size_t k(0); k - < (_mesh_nodes_along_polylines.back()).getDistOfProjNodeFromPlyStart().size(); k++) + for (size_t k(0); k < (_mesh_nodes_along_polylines.back()).getDistOfProjNodeFromPlyStart().size(); k++) points.push_back(it->getDistOfProjNodeFromPlyStart()[k]); } @@ -1653,31 +1585,31 @@ void CFEMesh::GetNODOnPLY(const GEOLIB::Polyline* const ply, msh_nod_vector.clear(); // JOD 2014-11-10 //---------------------------------------------------------------------- std::vector tmp_msh_node_vector; - if (automatic) { - search_radius = this->getMinEdgeLength()/2; + if (automatic) + { + search_radius = this->getMinEdgeLength() / 2; } GetNODOnPLY(ply, tmp_msh_node_vector, automatic, search_radius); #if defined(USE_PETSC) // || defined (other parallel linear solver lib). //WW. 08.2014 - if(for_s_term) - { - for(size_t k(0); k < tmp_msh_node_vector.size(); k++) - msh_nod_vector.push_back(tmp_msh_node_vector[k]); - } - else - { - const size_t start_act_node_h = NodesNumber_Linear; - const size_t end_act_node_h = NodesNumber_Linear - + static_cast(loc_NodesNumber_Quadratic - loc_NodesNumber_Linear); - for(size_t k(0); k < tmp_msh_node_vector.size(); k++) - { - const size_t n_id = nod_vector[tmp_msh_node_vector[k]]->GetIndex(); - if( n_id < static_cast(loc_NodesNumber_Linear) - || ( n_id >= start_act_node_h && n_id < end_act_node_h ) - ) - msh_nod_vector.push_back(tmp_msh_node_vector[k]); - } - } + if (for_s_term) + { + for (size_t k(0); k < tmp_msh_node_vector.size(); k++) + msh_nod_vector.push_back(tmp_msh_node_vector[k]); + } + else + { + const size_t start_act_node_h = NodesNumber_Linear; + const size_t end_act_node_h + = NodesNumber_Linear + static_cast(loc_NodesNumber_Quadratic - loc_NodesNumber_Linear); + for (size_t k(0); k < tmp_msh_node_vector.size(); k++) + { + const size_t n_id = nod_vector[tmp_msh_node_vector[k]]->GetIndex(); + if (n_id < static_cast(loc_NodesNumber_Linear) + || (n_id >= start_act_node_h && n_id < end_act_node_h)) + msh_nod_vector.push_back(tmp_msh_node_vector[k]); + } + } #else for (size_t k(0); k < tmp_msh_node_vector.size(); k++) msh_nod_vector.push_back(tmp_msh_node_vector[k]); @@ -1691,35 +1623,35 @@ void CFEMesh::GetNODOnPLY(const GEOLIB::Polyline* const ply, 04/2005 OK last modification: **************************************************************************/ -void CFEMesh::GetNODOnSFC(Surface* m_sfc, std::vector&msh_nod_vector, const bool for_s_term) +void CFEMesh::GetNODOnSFC(Surface* m_sfc, std::vector& msh_nod_vector, const bool for_s_term) { msh_nod_vector.clear(); //---------------------------------------------------------------------- switch (m_sfc->type) { - //.................................................................... - case 0: // Surface polygon - GetNODOnSFC_PLY(m_sfc, msh_nod_vector, for_s_term); - break; - case 1: // TIN - if (!m_sfc->TIN) - return; - GetNODOnSFC_TIN(m_sfc, msh_nod_vector); - break; - //.................................................................... - case 2: // 2 vertical polylines - GetNODOnSFC_Vertical(m_sfc, msh_nod_vector); - break; - case 3: // projection on xy plane (all mesh points above and below the surface) //MB - GetNODOnSFC_PLY_XY(m_sfc, msh_nod_vector); - break; - //.................................................................... - case 100: - GetNodesOnCylindricalSurface(m_sfc, msh_nod_vector); - break; - case 4: // layer polyline, all z - GetNODOnSFC_PLY_Z(m_sfc, msh_nod_vector); - break; + //.................................................................... + case 0: // Surface polygon + GetNODOnSFC_PLY(m_sfc, msh_nod_vector, for_s_term); + break; + case 1: // TIN + if (!m_sfc->TIN) + return; + GetNODOnSFC_TIN(m_sfc, msh_nod_vector); + break; + //.................................................................... + case 2: // 2 vertical polylines + GetNODOnSFC_Vertical(m_sfc, msh_nod_vector); + break; + case 3: // projection on xy plane (all mesh points above and below the surface) //MB + GetNODOnSFC_PLY_XY(m_sfc, msh_nod_vector); + break; + //.................................................................... + case 100: + GetNodesOnCylindricalSurface(m_sfc, msh_nod_vector); + break; + case 4: // layer polyline, all z + GetNODOnSFC_PLY_Z(m_sfc, msh_nod_vector); + break; } } @@ -1731,13 +1663,13 @@ void CFEMesh::GetNODOnSFC(Surface* m_sfc, std::vector&msh_nod_vector, cons last modification: **************************************************************************/ void CFEMesh::GetNODOnSFC(const GEOLIB::Surface* sfc, - std::vector& msh_nod_vector, + std::vector& msh_nod_vector, #ifdef USE_PETSC - const bool for_s_term + const bool for_s_term #else - const bool + const bool #endif - ) const + ) const { msh_nod_vector.clear(); @@ -1749,54 +1681,67 @@ void CFEMesh::GetNODOnSFC(const GEOLIB::Surface* sfc, const_cast(sfc)->initSurfaceGrid(); #ifdef TIME_MEASUREMENT end = clock(); - std::cout << "done, took " << (end-begin)/(double)(CLOCKS_PER_SEC) << " s" << "\n"; + std::cout << "done, took " << (end - begin) / (double)(CLOCKS_PER_SEC) << " s" + << "\n"; std::cout << "[CFEMesh::GetNODOnSFC] search with new algorithm ... " << std::flush; begin = clock(); #endif #if defined(USE_PETSC) // || defined (other parallel linear solver lib). //WW. 05.2012 - if(for_s_term) - { - const size_t nodes_in_usage = (size_t) NodesInUsage(); - for (size_t j(0); j < nodes_in_usage; j++) { - if (sfc->isPntInBV((nod_vector[j])->getData(), _search_length / 2.0)) { - if (sfc->isPntInSfc((nod_vector[j])->getData(), _search_length/2.0)) { - msh_nod_vector.push_back(nod_vector[j]->GetIndex()); + if (for_s_term) + { + const size_t nodes_in_usage = (size_t)NodesInUsage(); + for (size_t j(0); j < nodes_in_usage; j++) + { + if (sfc->isPntInBV((nod_vector[j])->getData(), _search_length / 2.0)) + { + if (sfc->isPntInSfc((nod_vector[j])->getData(), _search_length / 2.0)) + { + msh_nod_vector.push_back(nod_vector[j]->GetIndex()); + } + } + } + } + else + { + const size_t id_act_l_max = static_cast(getNumNodesLocal()); + const size_t id_act_h_min = GetNodesNumber(false); + const size_t id_act_h_max = getLargestActiveNodeID_Quadratic(); + + for (size_t j = 0; j < id_act_l_max; j++) + { + if (sfc->isPntInBV((nod_vector[j])->getData(), _search_length / 2.0)) + { + if (sfc->isPntInSfc((nod_vector[j])->getData(), _search_length / 2.0)) + { + msh_nod_vector.push_back(nod_vector[j]->GetIndex()); + } + } + } + + if (!useQuadratic) + return; + + for (size_t j = id_act_h_min; j < id_act_h_max; j++) + { + if (sfc->isPntInBV((nod_vector[j])->getData(), _search_length / 2.0)) + { + if (sfc->isPntInSfc((nod_vector[j])->getData(), _search_length / 2.0)) + { + msh_nod_vector.push_back(nod_vector[j]->GetIndex()); + } } } } - } - else - { - const size_t id_act_l_max = static_cast(getNumNodesLocal()); - const size_t id_act_h_min = GetNodesNumber(false); - const size_t id_act_h_max = getLargestActiveNodeID_Quadratic(); - - for (size_t j=0; j < id_act_l_max; j++) { - if (sfc->isPntInBV((nod_vector[j])->getData(), _search_length / 2.0)) { - if (sfc->isPntInSfc((nod_vector[j])->getData(), _search_length/2.0)) { - msh_nod_vector.push_back(nod_vector[j]->GetIndex()); - } - } - } - - if (!useQuadratic) - return; - - for (size_t j=id_act_h_min; j < id_act_h_max; j++) { - if (sfc->isPntInBV((nod_vector[j])->getData(), _search_length / 2.0)) { - if (sfc->isPntInSfc((nod_vector[j])->getData(), _search_length / 2.0)) { - msh_nod_vector.push_back(nod_vector[j]->GetIndex()); - } - } - } - } #else - const size_t nodes_in_usage((size_t) NodesInUsage()); - for (size_t j(0); j < nodes_in_usage; j++) { - if (sfc->isPntInBV((nod_vector[j])->getData(), _search_length*0.375)) { - if (sfc->isPntInSfc((nod_vector[j])->getData(), _search_length*0.375)) { + const size_t nodes_in_usage((size_t)NodesInUsage()); + for (size_t j(0); j < nodes_in_usage; j++) + { + if (sfc->isPntInBV((nod_vector[j])->getData(), _search_length * 0.375)) + { + if (sfc->isPntInSfc((nod_vector[j])->getData(), _search_length * 0.375)) + { msh_nod_vector.push_back(nod_vector[j]->GetIndex()); } } @@ -1805,42 +1750,42 @@ void CFEMesh::GetNODOnSFC(const GEOLIB::Surface* sfc, #ifdef TIME_MEASUREMENT end = clock(); - std::cout << "done, took " << (end-begin)/(double)(CLOCKS_PER_SEC) << " s, " << msh_nod_vector.size() << "nodes found" << "\n"; + std::cout << "done, took " << (end - begin) / (double)(CLOCKS_PER_SEC) << " s, " << msh_nod_vector.size() + << "nodes found" + << "\n"; #endif } -void CFEMesh::findNodesInPolygon(const double area_orig, const double tol, - const size_t start_id, const size_t end_id, - const CGLPolyline *ply, - std::vector &node_id_vector) const +void CFEMesh::findNodesInPolygon(const double area_orig, const double tol, const size_t start_id, const size_t end_id, + const CGLPolyline* ply, std::vector& node_id_vector) const { - double x1[3]; - double x2[3]; - const size_t np = ply->point_vector.size(); - for (size_t j = start_id; j < end_id; j++) - { - double area_calculated = 0.0; - for (size_t i = 0; i < np; i++) - { - CGLPoint *point = ply->point_vector[i]; - x1[0] = point->x; - x1[1] = point->y; - x1[2] = point->z; - - size_t k = i + 1; - if (i == np - 1) - k = 0; - point = ply->point_vector[k]; - x2[0] = point->x; - x2[1] = point->y; - x2[2] = point->z; - - area_calculated += fabs(ComputeDetTri(x1, nod_vector[j]->getData(), x2)); - } - - if (fabs(area_orig - area_calculated) < tol) - node_id_vector.push_back( nod_vector[j]->GetIndex()); - } + double x1[3]; + double x2[3]; + const size_t np = ply->point_vector.size(); + for (size_t j = start_id; j < end_id; j++) + { + double area_calculated = 0.0; + for (size_t i = 0; i < np; i++) + { + CGLPoint* point = ply->point_vector[i]; + x1[0] = point->x; + x1[1] = point->y; + x1[2] = point->z; + + size_t k = i + 1; + if (i == np - 1) + k = 0; + point = ply->point_vector[k]; + x2[0] = point->x; + x2[1] = point->y; + x2[2] = point->z; + + area_calculated += fabs(ComputeDetTri(x1, nod_vector[j]->getData(), x2)); + } + + if (fabs(area_orig - area_calculated) < tol) + node_id_vector.push_back(nod_vector[j]->GetIndex()); + } }; /************************************************************************** @@ -1855,7 +1800,7 @@ void CFEMesh::findNodesInPolygon(const double area_orig, const double tol, last modification: **************************************************************************/ void CFEMesh::GetNODOnSFC_PLY(Surface const* m_sfc, - std::vector&msh_nod_vector, + std::vector& msh_nod_vector, #ifdef USE_PETSC const bool for_s_term #else @@ -1869,8 +1814,7 @@ void CFEMesh::GetNODOnSFC_PLY(Surface const* m_sfc, double Area1; double Tol = m_sfc->epsilon; CGLPolyline* m_ply = NULL; - std::vector::const_iterator p_ply( - m_sfc->polyline_of_surface_vector.begin()); //CC + std::vector::const_iterator p_ply(m_sfc->polyline_of_surface_vector.begin()); // CC // Init msh_nod_vector.clear(); @@ -1878,7 +1822,7 @@ void CFEMesh::GetNODOnSFC_PLY(Surface const* m_sfc, while (p_ply != m_sfc->polyline_of_surface_vector.end()) { m_ply = *p_ply; - nPointsPly = (int) m_ply->point_vector.size(); + nPointsPly = (int)m_ply->point_vector.size(); if (m_ply->point_vector.front() == m_ply->point_vector.back()) nPointsPly -= 1; //.................................................................... @@ -1892,7 +1836,7 @@ void CFEMesh::GetNODOnSFC_PLY(Surface const* m_sfc, gC[2] += m_ply->point_vector[i]->z; } for (i = 0; i < 3; i++) - gC[i] /= (double) nPointsPly; + gC[i] /= (double)nPointsPly; //.................................................................... // Area of this polygon by the grativity center Area1 = 0.0; @@ -1915,30 +1859,25 @@ void CFEMesh::GetNODOnSFC_PLY(Surface const* m_sfc, } Area1 += fabs(ComputeDetTri(p1, gC, p2)); } - //.................................................................... - // Check nodes by comparing area +//.................................................................... +// Check nodes by comparing area #if defined(USE_PETSC) // || defined (other parallel linear solver lib). //WW. 05.2012 - if(for_s_term) + if (for_s_term) { - findNodesInPolygon(Area1, Tol, 0, NodesInUsage(), - m_ply, msh_nod_vector); + findNodesInPolygon(Area1, Tol, 0, NodesInUsage(), m_ply, msh_nod_vector); } else { - findNodesInPolygon(Area1, Tol, 0, getNumNodesLocal(), - m_ply, msh_nod_vector); + findNodesInPolygon(Area1, Tol, 0, getNumNodesLocal(), m_ply, msh_nod_vector); - if(useQuadratic) + if (useQuadratic) { - findNodesInPolygon(Area1, Tol, GetNodesNumber(false), - getLargestActiveNodeID_Quadratic(), - m_ply, msh_nod_vector); - + findNodesInPolygon(Area1, Tol, GetNodesNumber(false), getLargestActiveNodeID_Quadratic(), m_ply, + msh_nod_vector); } } #else - findNodesInPolygon(Area1, Tol, 0, NodesInUsage(), - m_ply, msh_nod_vector); + findNodesInPolygon(Area1, Tol, 0, NodesInUsage(), m_ply, msh_nod_vector); #endif p_ply++; } @@ -1955,8 +1894,7 @@ void CFEMesh::GetNODOnSFC_PLY(Surface const* m_sfc, 03/2009 WW Efficiency improvement last modification: **************************************************************************/ -void CFEMesh::GetNODOnSFC_PLY_XY(Surface* m_sfc, - std::vector&msh_nod_vector, bool givenNodesOnSurface) +void CFEMesh::GetNODOnSFC_PLY_XY(Surface* m_sfc, std::vector& msh_nod_vector, bool givenNodesOnSurface) { long i, k; size_t j; @@ -1965,7 +1903,7 @@ void CFEMesh::GetNODOnSFC_PLY_XY(Surface* m_sfc, double Area1, Area2; double Tol = m_sfc->epsilon; CGLPolyline* m_ply = NULL; - std::vector::iterator p_ply; //CC + std::vector::iterator p_ply; // CC // Init //----19.03.2009. WW CNode* a_node = NULL; @@ -1973,7 +1911,7 @@ void CFEMesh::GetNODOnSFC_PLY_XY(Surface* m_sfc, // if (givenNodesOnSurface) { - temp_v.resize((long) msh_nod_vector.size()); + temp_v.resize((long)msh_nod_vector.size()); temp_v = msh_nod_vector; } p1[2] = p2[2] = 0.; @@ -1982,13 +1920,13 @@ void CFEMesh::GetNODOnSFC_PLY_XY(Surface* m_sfc, msh_nod_vector.clear(); //---------------------------------------------------------------------- // nodes close to first polyline - //CC + // CC p_ply = m_sfc->polyline_of_surface_vector.begin(); - //CC + // CC while (p_ply != m_sfc->polyline_of_surface_vector.end()) { m_ply = *p_ply; - nPointsPly = (int) m_ply->point_vector.size(); + nPointsPly = (int)m_ply->point_vector.size(); if (m_ply->point_vector.front() == m_ply->point_vector.back()) nPointsPly -= 1; //.................................................................... @@ -2001,7 +1939,7 @@ void CFEMesh::GetNODOnSFC_PLY_XY(Surface* m_sfc, gC[1] += m_ply->point_vector[i]->y; } for (i = 0; i < 3; i++) - gC[i] /= (double) nPointsPly; + gC[i] /= (double)nPointsPly; //.................................................................... // Area of this polygon by the grativity center Area1 = 0.0; @@ -2038,15 +1976,14 @@ void CFEMesh::GetNODOnSFC_PLY_XY(Surface* m_sfc, Area2 += fabs(ComputeDetTri(p1, a_node->getData(), p2)); } if (fabs(Area1 - Area2) < Tol) - msh_nod_vector.push_back( - a_node->GetIndex()); + msh_nod_vector.push_back(a_node->GetIndex()); } //----------------------------------------------- else for (j = 0; j < NodesInUsage(); j++) { Area2 = 0.0; - a_node = nod_vector[j]; //19.03.2009. WW + a_node = nod_vector[j]; // 19.03.2009. WW // // gC[0] = a_node->X(); // gC[1] = a_node->Y(); @@ -2062,13 +1999,12 @@ void CFEMesh::GetNODOnSFC_PLY_XY(Surface* m_sfc, Area2 += fabs(ComputeDetTri(p1, a_node->getData(), p2)); } if (fabs(Area1 - Area2) < Tol) - msh_nod_vector.push_back( - a_node->GetIndex()); + msh_nod_vector.push_back(a_node->GetIndex()); } p_ply++; } // - if (givenNodesOnSurface) //19.03.2009. WW + if (givenNodesOnSurface) // 19.03.2009. WW temp_v.clear(); } @@ -2082,22 +2018,22 @@ void CFEMesh::GetNODOnSFC_PLY_XY(Surface* m_sfc, 01/2010 NW use epsilon specified in GEO as tolerance last modification: **************************************************************************/ -void CFEMesh::GetNODOnSFC_TIN(Surface* m_sfc, std::vector&msh_nod_vector) +void CFEMesh::GetNODOnSFC_TIN(Surface* m_sfc, std::vector& msh_nod_vector) { double dist; double tolerance = 0.001; double min_mesh_dist = 0.0; double tri_point1[3], tri_point2[3], tri_point3[3], checkpoint[3]; - double sfc_min[3] = { m_sfc->TIN->Triangles[0]->x[0], - m_sfc->TIN->Triangles[0]->y[0], m_sfc->TIN->Triangles[0]->z[0] }; - double sfc_max[3] = { m_sfc->TIN->Triangles[0]->x[0], - m_sfc->TIN->Triangles[0]->y[0], m_sfc->TIN->Triangles[0]->z[0] }; + double sfc_min[3] + = {m_sfc->TIN->Triangles[0]->x[0], m_sfc->TIN->Triangles[0]->y[0], m_sfc->TIN->Triangles[0]->z[0]}; + double sfc_max[3] + = {m_sfc->TIN->Triangles[0]->x[0], m_sfc->TIN->Triangles[0]->y[0], m_sfc->TIN->Triangles[0]->z[0]}; CTriangle* m_triangle = NULL; //---------------------------------------------------------------------- // Create Bounding BOX = MIN/MAX of X/Y/Z //---------------------------------------------------------------------- - //Loop over all generated triangles of surface + // Loop over all generated triangles of surface for (size_t m = 0; m < m_sfc->TIN->Triangles.size(); m++) { m_triangle = m_sfc->TIN->Triangles[m]; @@ -2202,7 +2138,7 @@ void CFEMesh::GetNODOnSFC_TIN(Surface* m_sfc, std::vector&msh_nod_vector) CFEMesh* m_msh_aux(new CFEMesh(_geo_obj, _geo_name)); - tolerance = m_sfc->epsilon; //NW + tolerance = m_sfc->epsilon; // NW // NW commented out below. Minimum edge length doesn't work for some cases ////Loop over all edges // for(i=0;i<(long)edge_vector.size();i++) @@ -2224,12 +2160,13 @@ void CFEMesh::GetNODOnSFC_TIN(Surface* m_sfc, std::vector&msh_nod_vector) sfc_max[k] += tolerance; } - //Loop over all mesh nodes - const size_t n_nodes(static_cast (NodesInUsage())); - for (size_t i = 0; i < n_nodes; i++) { + // Loop over all mesh nodes + const size_t n_nodes(static_cast(NodesInUsage())); + for (size_t i = 0; i < n_nodes; i++) + { double const* const pnt(nod_vector[i]->getData()); - if ((pnt[0] >= sfc_min[0] && pnt[0] <= sfc_max[0]) && (pnt[1] >= sfc_min[1] && pnt[1] - <= sfc_max[1]) && (pnt[2] >= sfc_min[2] && pnt[2] <= sfc_max[2])) + if ((pnt[0] >= sfc_min[0] && pnt[0] <= sfc_max[0]) && (pnt[1] >= sfc_min[1] && pnt[1] <= sfc_max[1]) + && (pnt[2] >= sfc_min[2] && pnt[2] <= sfc_max[2])) m_msh_aux->nod_vector.push_back(new CNode(i, pnt)); } @@ -2248,15 +2185,13 @@ void CFEMesh::GetNODOnSFC_TIN(Surface* m_sfc, std::vector&msh_nod_vector) tri_point3[0] = m_triangle->x[2]; tri_point3[1] = m_triangle->y[2]; tri_point3[2] = m_triangle->z[2]; - //Loop over all preselected mesh nodes + // Loop over all preselected mesh nodes for (size_t i = 0; i < m_msh_aux->nod_vector.size(); i++) { double const* const pnt_i(m_msh_aux->nod_vector[i]->getData()); - dist = MCalcDistancePointToPlane(pnt_i, tri_point1, tri_point2, - tri_point3); + dist = MCalcDistancePointToPlane(pnt_i, tri_point1, tri_point2, tri_point3); if (dist <= tolerance && dist >= -tolerance) - AngleSumPointInsideTriangle(checkpoint, tri_point1, tri_point2, - tri_point3, min_mesh_dist); + AngleSumPointInsideTriangle(checkpoint, tri_point1, tri_point2, tri_point3, min_mesh_dist); } } @@ -2265,19 +2200,17 @@ void CFEMesh::GetNODOnSFC_TIN(Surface* m_sfc, std::vector&msh_nod_vector) // TODO: Works only for one mesh!!! //---------------------------------------------------------------------- int index; - //Loop over selected nodes + // Loop over selected nodes for (size_t i = 0; i < m_msh_aux->nod_vector.size(); i++) { index = m_msh_aux->nod_vector[i]->GetIndex(); double const* const pnt_index(nod_vector[index]->getData()); double const* const pnt_i(m_msh_aux->nod_vector[i]->getData()); - if (index < (int) nod_vector.size()) - if ((m_msh_aux->nod_vector[i]->GetIndex() == nod_vector[index]->GetIndex()) - && (pnt_i[0] == pnt_index[0]) - && (pnt_i[1] == pnt_index[1]) - && (pnt_i[2] == pnt_index[2])) + if (index < (int)nod_vector.size()) + if ((m_msh_aux->nod_vector[i]->GetIndex() == nod_vector[index]->GetIndex()) && (pnt_i[0] == pnt_index[0]) + && (pnt_i[1] == pnt_index[1]) + && (pnt_i[2] == pnt_index[2])) msh_nod_vector.push_back(nod_vector[index]->GetIndex()); - } //---------------------------------------------------------------------- @@ -2309,7 +2242,7 @@ void CFEMesh::GetNodesOnCylindricalSurface(Surface* m_sfc, std::vector& No CElem* elem = NULL; CNode* cnode = NULL; NodesS.clear(); - //m_sfc->epsilon = 1.0e-6; + // m_sfc->epsilon = 1.0e-6; p1[0] = m_sfc->polygon_point_vector[0]->x; p1[1] = m_sfc->polygon_point_vector[0]->y; p1[2] = m_sfc->polygon_point_vector[0]->z; @@ -2318,25 +2251,20 @@ void CFEMesh::GetNodesOnCylindricalSurface(Surface* m_sfc, std::vector& No p2[1] = m_sfc->polygon_point_vector[1]->y; p2[2] = m_sfc->polygon_point_vector[1]->z; - dist = sqrt((p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - - p2[1]) + - (p1[2] - p2[2]) * (p1[2] - p2[2])); + dist = sqrt((p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]) + + (p1[2] - p2[2]) * (p1[2] - p2[2])); // Check nodes by comparing area for (j = 0; j < nNodes; j++) { cnode = nod_vector[j]; - double const* const gc (cnode->getData()); + double const* const gc(cnode->getData()); // gC[0] = cnode->X(); // gC[1] = cnode->Y(); // gC[2] = cnode->Z(); - dc1 = (p2[0] - p1[0]) * (gc[0] - p1[0]) + (p2[1] - p1[1]) * (gc[1] - - p1[1]) + - (p2[2] - p1[2]) * (gc[2] - p1[2]); - dc2 = (p2[0] - p1[0]) * (gc[0] - p2[0]) + (p2[1] - p1[1]) * (gc[1] - - p2[1]) + - (p2[2] - p1[2]) * (gc[2] - p2[2]); + dc1 = (p2[0] - p1[0]) * (gc[0] - p1[0]) + (p2[1] - p1[1]) * (gc[1] - p1[1]) + (p2[2] - p1[2]) * (gc[2] - p1[2]); + dc2 = (p2[0] - p1[0]) * (gc[0] - p2[0]) + (p2[1] - p1[1]) * (gc[1] - p2[1]) + (p2[2] - p1[2]) * (gc[2] - p2[2]); if (dc1 < 0.0) continue; if (dc2 > 0.0) @@ -2350,21 +2278,21 @@ void CFEMesh::GetNodesOnCylindricalSurface(Surface* m_sfc, std::vector& No bool done = false; int counter = 0; int hs; - long NodesS_size = (long) NodesS.size(); + long NodesS_size = (long)NodesS.size(); // if (useQuadratic) // Face elements are only in quadrilaterals or triangles for (i = 0; i < NodesS_size; i++) { cnode = nod_vector[NodesS[i]]; - for (j = 0; j < (long) cnode->getConnectedElementIDs().size(); j++) + for (j = 0; j < (long)cnode->getConnectedElementIDs().size(); j++) { elem = ele_vector[cnode->getConnectedElementIDs()[j]]; for (size_t k = 0; k < elem->GetFacesNumber(); k++) { nf = elem->GetElementFaceNodes(k, faceIndex_loc); counter = 0; - hs = (int) (nf / 2); + hs = (int)(nf / 2); for (l = 0; l < hs; l++) // loop over face vertices { fnode = elem->GetNodeIndex(faceIndex_loc[l]); @@ -2379,7 +2307,7 @@ void CFEMesh::GetNodesOnCylindricalSurface(Surface* m_sfc, std::vector& No { fnode = elem->GetNodeIndex(faceIndex_loc[l]); done = false; - for (m = 0; m < (long) NodesS.size(); m++) + for (m = 0; m < (long)NodesS.size(); m++) if (fnode == NodesS[m]) { done = true; @@ -2401,17 +2329,17 @@ void CFEMesh::GetNodesOnCylindricalSurface(Surface* m_sfc, std::vector& No last modification: 07/2010 TF small modifications concerning coding style **************************************************************************/ -void CFEMesh::GetNODOnSFC_Vertical(Surface* m_sfc, std::vector&msh_nod_vector) +void CFEMesh::GetNODOnSFC_Vertical(Surface* m_sfc, std::vector& msh_nod_vector) { long* nodes_array = NULL; long no_nodes = 0; // nodes close to first polyline - std::vector::const_iterator p_ply (m_sfc->polyline_of_surface_vector.begin()); + std::vector::const_iterator p_ply(m_sfc->polyline_of_surface_vector.begin()); while (p_ply != m_sfc->polyline_of_surface_vector.end()) { - //OK41 nodes_array = m_polyline->MSHGetNodesCloseXY(&no_nodes); - //CC 10/05 + // OK41 nodes_array = m_polyline->MSHGetNodesCloseXY(&no_nodes); + // CC 10/05 nodes_array = MSHGetNodesClose(&no_nodes, *p_ply); break; } @@ -2427,16 +2355,16 @@ void CFEMesh::GetNODOnSFC_Vertical(Surface* m_sfc, std::vector&msh_nod_vec m_polyline2 = *p_ply; break; } - long no_points = (long) m_polyline1->point_vector.size(); + long no_points = (long)m_polyline1->point_vector.size(); CGLPoint m_node; double xp[3], yp[3], zp[3]; long i, j; for (j = 0; j < no_nodes; j++) - //OK m_node.x = GetNodeX(nodes_array[j]); - //OK m_node.y = GetNodeY(nodes_array[j]); - //OK m_node.z = GetNodeZ(nodes_array[j]); + // OK m_node.x = GetNodeX(nodes_array[j]); + // OK m_node.y = GetNodeY(nodes_array[j]); + // OK m_node.z = GetNodeZ(nodes_array[j]); for (i = 0; i < no_points - 1; i++) { // first triangle of quad @@ -2449,7 +2377,7 @@ void CFEMesh::GetNODOnSFC_Vertical(Surface* m_sfc, std::vector&msh_nod_vec xp[2] = m_polyline2->point_vector[i]->x; yp[2] = m_polyline2->point_vector[i]->y; zp[2] = m_polyline2->point_vector[i]->z; - //CC 10/05 + // CC 10/05 if (m_node.IsInsideTriangle(xp, yp, zp)) msh_nod_vector.push_back(nodes_array[j]); // second triangle of quad @@ -2462,11 +2390,11 @@ void CFEMesh::GetNODOnSFC_Vertical(Surface* m_sfc, std::vector&msh_nod_vec xp[2] = m_polyline1->point_vector[i + 1]->x; yp[2] = m_polyline1->point_vector[i + 1]->y; zp[2] = m_polyline1->point_vector[i + 1]->z; - //CC 10/05 + // CC 10/05 if (m_node.IsInsideTriangle(xp, yp, zp)) msh_nod_vector.push_back(nodes_array[j]); } // no_points - // no_nodes + // no_nodes } /************************************************************************** FEMLib-Method: @@ -2475,18 +2403,18 @@ void CFEMesh::GetNODOnSFC_Vertical(Surface* m_sfc, std::vector&msh_nod_vec 03/2005 OK Implementation (based on ExecuteSourceSinkMethod11 by CT) last modification: **************************************************************************/ -void CFEMesh::GetNODOnPLY_XY(CGLPolyline* m_ply, std::vector&msh_nod_vector) +void CFEMesh::GetNODOnPLY_XY(CGLPolyline* m_ply, std::vector& msh_nod_vector) { long j, k, l; - double pt1[3], line1[3], line2[3]; //WW , pt0[3]; + double pt1[3], line1[3], line2[3]; // WW , pt0[3]; double mult_eps = 1.0; - double dist1p, dist2p, * length, laenge; + double dist1p, dist2p, *length, laenge; long anz_relevant = 0; typedef struct { long knoten; double laenge; - }INFO; + } INFO; INFO* relevant = NULL; int weiter; double w1, w2; @@ -2496,13 +2424,12 @@ void CFEMesh::GetNODOnPLY_XY(CGLPolyline* m_ply, std::vector&msh_nod_vecto m_ply->getIBuffer().clear(); msh_nod_vector.clear(); // - length = (double*) Malloc(sizeof(double) - * (long) m_ply->point_vector.size()); - //WW pt0[0] = m_ply->point_vector[0]->x; - //WW pt0[1] = m_ply->point_vector[0]->y; - //WW pt0[2] = 0.0; + length = (double*)Malloc(sizeof(double) * (long)m_ply->point_vector.size()); + // WW pt0[0] = m_ply->point_vector[0]->x; + // WW pt0[1] = m_ply->point_vector[0]->y; + // WW pt0[2] = 0.0; /* */ - for (k = 0; k < (long) m_ply->point_vector.size() - 1; k++) + for (k = 0; k < (long)m_ply->point_vector.size() - 1; k++) { line1[0] = m_ply->point_vector[k]->x; line1[1] = m_ply->point_vector[k]->y; @@ -2516,11 +2443,11 @@ void CFEMesh::GetNODOnPLY_XY(CGLPolyline* m_ply, std::vector&msh_nod_vecto while (anz_relevant == 0) { /* Schleife ueber alle Knoten */ - for (j = 0; j < (long) nod_vector.size(); j++) + for (j = 0; j < (long)nod_vector.size(); j++) { - double const* const pnt_j (nod_vector[j]->getData()); + double const* const pnt_j(nod_vector[j]->getData()); /* Schleife ueber alle Punkte des Polygonzuges */ - for (k = 0; k < (long) m_ply->point_vector.size() - 1; k++) + for (k = 0; k < (long)m_ply->point_vector.size() - 1; k++) { /* ??? */ // TF can be moved out of the k loop in case MCalcDistancePointToLine, @@ -2535,8 +2462,7 @@ void CFEMesh::GetNODOnPLY_XY(CGLPolyline* m_ply, std::vector&msh_nod_vecto line2[1] = m_ply->point_vector[k + 1]->y; line2[2] = 0.0; /* Ist der Knoten nah am Polygonabschnitt? */ - if (MCalcDistancePointToLine(pt1, line1, line2) <= mult_eps - * m_ply->epsilon) + if (MCalcDistancePointToLine(pt1, line1, line2) <= mult_eps * m_ply->epsilon) { /* Im folgenden wird mit der Projektion weitergearbeitet */ MCalcProjectionOfPointOnLine(pt1, line1, line2, pt1); @@ -2545,20 +2471,19 @@ void CFEMesh::GetNODOnPLY_XY(CGLPolyline* m_ply, std::vector&msh_nod_vecto /* Abstand des Punktes zum zweiten Punkt des Polygonabschnitts */ dist2p = MCalcDistancePointToPoint(line2, pt1); /* Ist der Knoten innerhalb des Intervalls? */ - /* bis rf3807: if ((length[k] - dist1p - dist2p + MKleinsteZahl)/(length[k] + dist1p + dist2p + MKleinsteZahl) > -MKleinsteZahl){ */ - if ((dist1p + dist2p - length[k]) <= mult_eps - * m_ply->epsilon) + /* bis rf3807: if ((length[k] - dist1p - dist2p + MKleinsteZahl)/(length[k] + dist1p + dist2p + + * MKleinsteZahl) > -MKleinsteZahl){ */ + if ((dist1p + dist2p - length[k]) <= mult_eps * m_ply->epsilon) { // For boundara conditions. WW m_ply->getSBuffer().push_back(dist1p); m_ply->getIBuffer().push_back(k); anz_relevant++; /* Feld anpassen */ - //nodes_all = (long *) Realloc(nodes_all,sizeof(long)*anz_relevant); - relevant = (INFO*) Realloc(relevant, sizeof(INFO) - * anz_relevant); + // nodes_all = (long *) Realloc(nodes_all,sizeof(long)*anz_relevant); + relevant = (INFO*)Realloc(relevant, sizeof(INFO) * anz_relevant); /* Ablegen von Knotennummer und Position */ - //nodes_all[anz_relevant-1] = j; + // nodes_all[anz_relevant-1] = j; msh_nod_vector.push_back(j); /* Position ermitteln */ laenge = 0.; @@ -2568,7 +2493,7 @@ void CFEMesh::GetNODOnPLY_XY(CGLPolyline* m_ply, std::vector&msh_nod_vecto relevant[anz_relevant - 1].knoten = j; relevant[anz_relevant - 1].laenge = laenge + dist1p; /* Suche am Polygon abbrechen, naechster Knoten */ - k = (long) m_ply->point_vector.size(); + k = (long)m_ply->point_vector.size(); } } /* endif */ } /* Ende Schleife ueber Polygonabschnitte */ @@ -2577,7 +2502,8 @@ void CFEMesh::GetNODOnPLY_XY(CGLPolyline* m_ply, std::vector&msh_nod_vecto mult_eps *= 2.; } /* Ende Schleife Wiederholungen */ if (mult_eps > 1.) - std::cout << "!!! Epsilon increased in sources!" << "\n"; + std::cout << "!!! Epsilon increased in sources!" + << "\n"; /* Schleife ueber alle Knoten; sortieren nach Reihenfolge auf dem Abschnitt (zyklisches Vertauschen, sehr lahm)*/ do { @@ -2598,7 +2524,7 @@ void CFEMesh::GetNODOnPLY_XY(CGLPolyline* m_ply, std::vector&msh_nod_vecto } } } while (weiter); - relevant = (INFO*) Free(relevant); + relevant = (INFO*)Free(relevant); } /************************************************************************** @@ -2618,13 +2544,13 @@ void CFEMesh::CreateLayerPolylines(CGLPolyline* m_ply) //--------------------------------------------------------------------- // Delete existing layer polylines std::string ply_lay_name = m_ply->getName() + "_L"; - for (int k = 0; k < (int) polyline_vector.size(); k++) + for (int k = 0; k < (int)polyline_vector.size(); k++) { m_polyline = polyline_vector[k]; if (m_polyline->getName().find(ply_lay_name) != std::string::npos) { GEORemovePLY(m_polyline); - //GEORemovePolyline(polyline_vector.begin()+(k-l)); + // GEORemovePolyline(polyline_vector.begin()+(k-l)); k--; } } @@ -2633,15 +2559,15 @@ void CFEMesh::CreateLayerPolylines(CGLPolyline* m_ply) std::vector ply_nod_vector; std::vector ply_nod_vector_dummy; GetNODOnPLY_XY(m_ply, ply_nod_vector); - //nodes = MSHGetNodesCloseXY(&no_nodes); //OK41 - long nodes_per_layer = (long) nod_vector.size() / (_n_msh_layer + 1); - int ply_nod_vector_layer = (int) ply_nod_vector.size() / (_n_msh_layer + 1); + // nodes = MSHGetNodesCloseXY(&no_nodes); //OK41 + long nodes_per_layer = (long)nod_vector.size() / (_n_msh_layer + 1); + int ply_nod_vector_layer = (int)ply_nod_vector.size() / (_n_msh_layer + 1); //--------------------------------------------------------------------- // Create layer polylines - //polyline id CC8888--------------------------------------------------- + // polyline id CC8888--------------------------------------------------- long size = 0; CGLPolyline* ms_polyline = NULL; - long number_of_polylines = (long) polyline_vector.size(); + long number_of_polylines = (long)polyline_vector.size(); if (number_of_polylines == 0) size = 0; else @@ -2663,33 +2589,33 @@ void CFEMesh::CreateLayerPolylines(CGLPolyline* m_ply) //...................................................................... m_polyline = new CGLPolyline; sprintf(layer_number, "%ld", 0L); - //CString names = m_ply->name + "_L" + layer_number; + // CString names = m_ply->name + "_L" + layer_number; // m_polyline->name = names; // 10/2010 TF // m_polyline->ply_name = m_ply->getName(); //CC/TK8888 // m_polyline->ply_name.append("_L"); //CC/TK8888 // m_polyline->ply_name.append(layer_number);//CC/TK8888 - std::string tmp_name (m_ply->getName() + "_L"); - tmp_name.append (layer_number); + std::string tmp_name(m_ply->getName() + "_L"); + tmp_name.append(layer_number); // m_polyline->name = m_polyline->ply_name.data();//CC/TK8888 // TF - m_polyline->setName (tmp_name); // TF + m_polyline->setName(tmp_name); // TF - m_polyline->setDataType (1); - m_polyline->setID(size); //CC8888 / TF - m_polyline->epsilon = m_ply->epsilon; //OK + m_polyline->setDataType(1); + m_polyline->setID(size); // CC8888 / TF + m_polyline->epsilon = m_ply->epsilon; // OK // m_polyline->ply_data = m_polyline->getName () + ".ply";//CC for (i = 0; i < ply_nod_vector_layer; i++) { - CGLPoint* point (new CGLPoint(nod_vector[ply_nod_vector[i]]->getData())); + CGLPoint* point(new CGLPoint(nod_vector[ply_nod_vector[i]]->getData())); m_polyline->point_vector.push_back(point); } m_polyline->SetPointOrderByDistance(m_ply->point_vector[0]); polyline_vector.push_back(m_polyline); m_polyline->WritePointVector(m_polyline->getName()); - m_polyline->WriteTecplot(" "); //OK41 + m_polyline->WriteTecplot(" "); // OK41 //...................................................................... for (size_t j = 1; j < (_n_msh_layer + 1); j++) { @@ -2700,25 +2626,23 @@ void CFEMesh::CreateLayerPolylines(CGLPolyline* m_ply) // m_polyline->ply_name.append(layer_number);//CC/TK8888 // m_polyline->name = m_polyline->ply_name.data();//CC/TK8888 - std::string tmp_name (m_ply->getName() + "_L"); - tmp_name.append (layer_number); - m_polyline->setName (tmp_name); + std::string tmp_name(m_ply->getName() + "_L"); + tmp_name.append(layer_number); + m_polyline->setName(tmp_name); - m_polyline->setDataType (1); - //OK + m_polyline->setDataType(1); + // OK m_polyline->epsilon = _min_edge_length / 2.; for (i = 0; i < ply_nod_vector_layer; i++) { - CGLPoint* point (new CGLPoint ( - nod_vector[ply_nod_vector[i] + j * - nodes_per_layer]->getData())); + CGLPoint* point(new CGLPoint(nod_vector[ply_nod_vector[i] + j * nodes_per_layer]->getData())); m_polyline->point_vector.push_back(point); } - //OK m_polyline->SortPointVectorByDistance(); + // OK m_polyline->SortPointVectorByDistance(); m_polyline->SetPointOrderByDistance(m_ply->point_vector[0]); polyline_vector.push_back(m_polyline); - m_polyline->WritePointVector(m_polyline->getName ()); - m_polyline->WriteTecplot(" "); //OK41 + m_polyline->WritePointVector(m_polyline->getName()); + m_polyline->WriteTecplot(" "); // OK41 } } @@ -2729,7 +2653,7 @@ void CFEMesh::CreateLayerPolylines(CGLPolyline* m_ply) **************************************************************************/ void CFEMesh::GetELEOnPLY(const GEOLIB::Polyline* ply, std::vector& ele_vector_ply, bool With1DElements) { - //WW EEMath_Group::vec ele_edges_vector(15); + // WW EEMath_Group::vec ele_edges_vector(15); int loc_edge_nidx[3]; Math_Group::vec edge_nodes(3); @@ -2744,7 +2668,7 @@ void CFEMesh::GetELEOnPLY(const GEOLIB::Polyline* ply, std::vector& ele_ // loop over all elements for (size_t i = 0; i < ele_vector.size(); i++) { - CElem *elem = ele_vector[i]; //WW + CElem* elem = ele_vector[i]; // WW // WW ele_vector[i]->GetEdges (ele_edges_vector); size_t n_edges = elem->GetEdgesNumber(); // Add 1D Elements for models with mixed 1D/2D Elements BG, 11/2011 @@ -2753,23 +2677,23 @@ void CFEMesh::GetELEOnPLY(const GEOLIB::Polyline* ply, std::vector& ele_ for (size_t k = 0; k < nodes_near_ply.size(); k++) { if ((static_cast(elem->GetNodeIndex(0)) == nodes_near_ply[k]) - || (static_cast(elem->GetNodeIndex(1)) == nodes_near_ply[k])) + || (static_cast(elem->GetNodeIndex(1)) == nodes_near_ply[k])) ele_vector_ply.push_back(elem->GetIndex()); } } // loop over all edges of the i-th element for (size_t j = 0; j < n_edges; j++) { - //WWele_edges_vector[j]->GetNodes(edge_nodes); - elem->GetLocalIndicesOfEdgeNodes(j, loc_edge_nidx); //WW - size_t selected (0); + // WWele_edges_vector[j]->GetNodes(edge_nodes); + elem->GetLocalIndicesOfEdgeNodes(j, loc_edge_nidx); // WW + size_t selected(0); // get all elements having an edge in common with ply for (size_t k = 0; k < nodes_near_ply.size(); k++) { - //if (edge_nodes[0]->GetIndex() == nodes_near_ply[k]) + // if (edge_nodes[0]->GetIndex() == nodes_near_ply[k]) if (elem->GetNodeIndex(loc_edge_nidx[0]) == static_cast(nodes_near_ply[k])) selected++; - //if (edge_nodes[1]->GetIndex() == nodes_near_ply[k]) + // if (edge_nodes[1]->GetIndex() == nodes_near_ply[k]) if (elem->GetNodeIndex(loc_edge_nidx[1]) == static_cast(nodes_near_ply[k])) selected++; } @@ -2783,17 +2707,17 @@ void CFEMesh::GetELEOnPLY(const GEOLIB::Polyline* ply, std::vector& ele_ Task: All nodes vertical to a polyline 02/2009 OK **************************************************************************/ -void CFEMesh::GetNODOnSFC_PLY_Z(Surface* m_sfc,std::vector&msh_nod_vector) +void CFEMesh::GetNODOnSFC_PLY_Z(Surface* m_sfc, std::vector& msh_nod_vector) { std::vector::iterator p_ply; CGLPolyline* m_ply = NULL; // ................................................................. // nodes close to first polyline p_ply = m_sfc->polyline_of_surface_vector.begin(); - while(p_ply != m_sfc->polyline_of_surface_vector.end()) + while (p_ply != m_sfc->polyline_of_surface_vector.end()) { m_ply = *p_ply; - GetNODOnPLY_XY(m_ply,msh_nod_vector); + GetNODOnPLY_XY(m_ply, msh_nod_vector); break; } } @@ -2820,7 +2744,7 @@ std::ios::pos_type CFEMesh::GMSReadTIN(std::ifstream* tin_file) //======================================================================== while (sub_line.compare("ENDT")) { - getline(*tin_file, s_buff); //WW + getline(*tin_file, s_buff); // WW in.str(s_buff); in >> sub_line; //................................................................ @@ -2836,7 +2760,7 @@ std::ios::pos_type CFEMesh::GMSReadTIN(std::ifstream* tin_file) for (i = 0; i < no_vertexes; i++) { m_nod = new CNode(i); - getline(*tin_file, s_buff); //WW + getline(*tin_file, s_buff); // WW in.str(s_buff); in >> xyz[0] >> xyz[1] >> xyz[2]; m_nod->SetCoordinates(xyz); @@ -2888,7 +2812,7 @@ std::ios::pos_type CFEMesh::GMSReadTIN(std::ifstream* tin_file) return position; } -#ifdef ObsoleteGUI //WW 03.2012 +#ifdef ObsoleteGUI // WW 03.2012 /************************************************************************** GeoSys-Method: Task: @@ -2898,13 +2822,13 @@ std::ios::pos_type CFEMesh::GMSReadTIN(std::ifstream* tin_file) 08/2005 WW Changes due to geometry objects applied see also: BuildActiveElementsArray **************************************************************************/ -void CFEMesh::SetActiveElements(std::vector&elements_active) +void CFEMesh::SetActiveElements(std::vector& elements_active) { const size_t ele_vector_size(this->ele_vector.size()); for (size_t i = 0; i < ele_vector_size; i++) ele_vector[i]->MarkingAll(false); - const size_t elements_active_size (elements_active.size()); + const size_t elements_active_size(elements_active.size()); for (size_t i = 0; i < elements_active_size; i++) ele_vector[elements_active[i]]->MarkingAll(true); } @@ -2925,30 +2849,30 @@ void CFEMesh::PrismRefine(int Layer, int subdivision) const size_t nn = 6; int j, nes; size_t* element_nodes = NULL; - //WW double nx[6], ny[6], + // WW double nx[6], ny[6], double nz[6]; - //WW double dx[3], dy[3],; + // WW double dx[3], dy[3],; double dz[3]; double newz; - int row (Layer); + int row(Layer); int NRowsToShift; - int NRows (_n_msh_layer + 1); + int NRows(_n_msh_layer + 1); int CountNLayers; CNode* m_nod = NULL; - const int NSubLayers = subdivision + 1; //OK - const size_t NumElement0 (ele_vector.size()); - //NodeListSize() / (NLayers+1); - size_t NNodesPerRow (nod_vector.size() / (_n_msh_layer + 1)); - //msh_no_pris / NLayers; + const int NSubLayers = subdivision + 1; // OK + const size_t NumElement0(ele_vector.size()); + // NodeListSize() / (NLayers+1); + size_t NNodesPerRow(nod_vector.size() / (_n_msh_layer + 1)); + // msh_no_pris / NLayers; // int NElementsPerLayer = ele_vector.size() / _n_msh_layer; - size_t nod_vector_size_add (NNodesPerRow * subdivision); + size_t nod_vector_size_add(NNodesPerRow * subdivision); for (size_t i = 0; i < nod_vector_size_add; i++) { m_nod = new CNode(i); nod_vector.push_back(m_nod); } - //nod_vector.resize(nod_vector_size_new); + // nod_vector.resize(nod_vector_size_new); // Initialisierung der Knoten flags const size_t nod_vector_size(nod_vector.size()); @@ -2962,86 +2886,64 @@ void CFEMesh::PrismRefine(int Layer, int subdivision) m_ele = ele_vector[ne]; if (m_ele->GetElementType() == MshElemType::PRISM) { - //element_nodes = m_ele->nodes; + // element_nodes = m_ele->nodes; CountNLayers = _n_msh_layer; for (size_t i = 0; i < nn; i++) - //WW nx[i] = nod_vector[m_ele->nodes_index[i]]->X(); - //WW ny[i] = nod_vector[m_ele->nodes_index[i]]->Y(); + // WW nx[i] = nod_vector[m_ele->nodes_index[i]]->X(); + // WW ny[i] = nod_vector[m_ele->nodes_index[i]]->Y(); nz[i] = nod_vector[m_ele->nodes_index[i]]->getData()[2]; nes = 0; for (size_t i = 0; i < 3; i++) - if (element_nodes[i] >= (row - 1) * NNodesPerRow - && element_nodes[i] <= (row * NNodesPerRow) - 1) + if (element_nodes[i] >= (row - 1) * NNodesPerRow && element_nodes[i] <= (row * NNodesPerRow) - 1) nes++; if (nes == 3) { for (size_t i = 0; i < 3; i++) - //WW dx[i] = (nx[i + 3] - nx[i]) / (float) NSubLayers; - //WW dy[i] = (ny[i + 3] - ny[i]) / (float) NSubLayers; - dz[i] = (nz[i + 3] - nz[i]) / (float) NSubLayers; + // WW dx[i] = (nx[i + 3] - nx[i]) / (float) NSubLayers; + // WW dy[i] = (ny[i + 3] - ny[i]) / (float) NSubLayers; + dz[i] = (nz[i + 3] - nz[i]) / (float)NSubLayers; // Create new nodes // Loop over SubLayers for (int iii = 0; iii < NSubLayers - 1; iii++) { // neue Knoten ganz unten for (size_t i = 0; i < 3; i++) - //if(NODGetFreeSurfaceFlag(element_nodes[i])==0){ + // if(NODGetFreeSurfaceFlag(element_nodes[i])==0){ if (nod_vector[element_nodes[i]]->GetMark()) { - //m_nod = new CMSHNodes(); //kno = (Knoten *)CreateNodeGeometry(); - m_nod = nod_vector[(m_ele->nodes_index[i] - + ((CountNLayers + - 2) - row) - * NNodesPerRow)]; - -// TF xyz[0] = nod_vector[m_ele->nodes_index[i] -// TF + ((CountNLayers + 1) - row) * NNodesPerRow]->X(); -// TF xyz[1] = nod_vector[m_ele->nodes_index[i] -// TF + ((CountNLayers + 1) - row) -// TF * NNodesPerRow]->Y(); -// TF xyz[2] = nod_vector[m_ele->nodes_index[i] -// TF + ((CountNLayers + 1) - row) + // m_nod = new CMSHNodes(); //kno = (Knoten *)CreateNodeGeometry(); + m_nod = nod_vector[(m_ele->nodes_index[i] + ((CountNLayers + 2) - row) * NNodesPerRow)]; + + // TF xyz[0] = nod_vector[m_ele->nodes_index[i] + // TF + ((CountNLayers + 1) - row) * NNodesPerRow]->X(); + // TF xyz[1] = nod_vector[m_ele->nodes_index[i] + // TF + ((CountNLayers + 1) - row) + // TF * NNodesPerRow]->Y(); + // TF xyz[2] = nod_vector[m_ele->nodes_index[i] + // TF + ((CountNLayers + 1) - row) // * NNodesPerRow]->Z(); - //PlaceNode(kno,(element_nodes[i] + ((CountNLayers+2) - row) * NNodesPerRow)); -// TF m_nod->SetCoordinates(xyz); - m_nod->SetCoordinates(nod_vector[m_ele-> - nodes_index - [i] + - (( - CountNLayers - + - 1) - - - row) * - NNodesPerRow]->getData()); - nod_vector[(m_ele->nodes_index[i] + - ((CountNLayers - + 2) - - row) * - NNodesPerRow)] = m_nod; + // PlaceNode(kno,(element_nodes[i] + ((CountNLayers+2) - row) * NNodesPerRow)); + // TF m_nod->SetCoordinates(xyz); + m_nod->SetCoordinates( + nod_vector[m_ele->nodes_index[i] + ((CountNLayers + 1) - row) * NNodesPerRow] + ->getData()); + nod_vector[(m_ele->nodes_index[i] + ((CountNLayers + 2) - row) * NNodesPerRow)] = m_nod; } // neues Element ganz unten m_ele_new = new CElem(); - //m_ele_new = m_ele; + // m_ele_new = m_ele; m_ele_new->nnodes = m_ele->nnodes; m_ele_new->patch_index = m_ele->GetPatchIndex(); m_ele_new->SetElementType(m_ele->GetElementType()); // KR memory leak! knoten = new long[6]; for (j = 0; j < 3; j++) { - m_ele_new->nodes_index[j] = element_nodes[j] + - ((CountNLayers + - 1) - - row) * NNodesPerRow; - m_ele_new->nodes_index[j + - 3] = element_nodes[j] + - ((CountNLayers + - 2) - - row) * NNodesPerRow; + m_ele_new->nodes_index[j] = element_nodes[j] + ((CountNLayers + 1) - row) * NNodesPerRow; + m_ele_new->nodes_index[j + 3] = element_nodes[j] + ((CountNLayers + 2) - row) * NNodesPerRow; } // KR fixed memory leak, knoten not needed - //for (j = 0; j < 6; j++) { + // for (j = 0; j < 6; j++) { // m_ele_new->nodes_index[j] = knoten[j]; //} ele_vector.push_back(m_ele_new); @@ -3053,59 +2955,32 @@ void CFEMesh::PrismRefine(int Layer, int subdivision) if (i != 1) { for (j = 0; j < 3; j++) - //if(NODGetFreeSurfaceFlag(element_nodes[j])==0){ - if (nod_vector[element_nodes[j]]-> - GetMark()) + // if(NODGetFreeSurfaceFlag(element_nodes[j])==0){ + if (nod_vector[element_nodes[j]]->GetMark()) { - m_nod = - nod_vector[ - element_nodes - [j + 3] - + - NNodesPerRow - * - (iii + - i - 1)]; + m_nod = nod_vector[element_nodes[j + 3] + NNodesPerRow * (iii + i - 1)]; m_nod->SetZ( - nod_vector[ - element_nodes - [j] - + - NNodesPerRow - * - (iii + i - - - 1)]-> - getData()[2]); - //SetNodeZ(element_nodes[j+3] + NNodesPerRow*(iii+i-1), GetNodeZ(element_nodes[j] + NNodesPerRow*(iii+i-1))); + nod_vector[element_nodes[j] + NNodesPerRow * (iii + i - 1)]->getData()[2]); + // SetNodeZ(element_nodes[j+3] + NNodesPerRow*(iii+i-1), GetNodeZ(element_nodes[j] + + // NNodesPerRow*(iii+i-1))); } } else { for (j = 0; j < 3; j++) - //if(NODGetFreeSurfaceFlag(element_nodes[j])==0) { - if (nod_vector[element_nodes[j]]-> - GetMark()) + // if(NODGetFreeSurfaceFlag(element_nodes[j])==0) { + if (nod_vector[element_nodes[j]]->GetMark()) { - newz = - nod_vector[ - element_nodes - [j]]-> - getData()[2] - + (dz[j] * (iii + 1)); - //newz = GetNodeZ(element_nodes[j]) + (dz[j]*(iii+1)); - nod_vector[element_nodes[j] - + (i) - * NNodesPerRow * - (iii + 1)]->SetZ( - newz); - //SetNodeZ(element_nodes[j] + (i) * NNodesPerRow *(iii+1), newz); + newz = nod_vector[element_nodes[j]]->getData()[2] + (dz[j] * (iii + 1)); + // newz = GetNodeZ(element_nodes[j]) + (dz[j]*(iii+1)); + nod_vector[element_nodes[j] + (i)*NNodesPerRow * (iii + 1)]->SetZ(newz); + // SetNodeZ(element_nodes[j] + (i) * NNodesPerRow *(iii+1), newz); } } } /* end for Rows to shift */ if (iii == NSubLayers - 2) for (j = 0; j < 3; j++) - //NODSetFreeSurfaceFlag(element_nodes[j], 33); + // NODSetFreeSurfaceFlag(element_nodes[j], 33); nod_vector[element_nodes[j]]->SetMark(false); CountNLayers++; @@ -3125,14 +3000,14 @@ void CFEMesh::PrismRefine(int Layer, int subdivision) **************************************************************************/ bool CFEMesh::NodeExists(size_t node) { - size_t no_nodes (nod_vector.size()); + size_t no_nodes(nod_vector.size()); for (size_t i = 0; i < no_nodes; i++) if (node == (size_t)Eqs2Global_NodeIndex[i]) return true; return false; } -#endif //end ObsoleteGUI +#endif // end ObsoleteGUI /************************************************************************** MSHLib-Method: @@ -3149,31 +3024,30 @@ void CFEMesh::ConnectedNodes(bool quadratic) const for (size_t i = 0; i < nod_vector.size(); i++) { CNode* nod = nod_vector[i]; - size_t n_connected_elements (nod->getConnectedElementIDs().size()); + size_t n_connected_elements(nod->getConnectedElementIDs().size()); for (size_t j = 0; j < n_connected_elements; j++) { CElem* ele = ele_vector[nod->getConnectedElementIDs()[j]]; - size_t n_quadratic_node (static_cast(ele->GetNodesNumber(quadratic))); + size_t n_quadratic_node(static_cast(ele->GetNodesNumber(quadratic))); for (size_t l = 0; l < n_quadratic_node; l++) { exist = false; - size_t n_connected_nodes (nod->getConnectedNodes().size()); - //WW + size_t n_connected_nodes(nod->getConnectedNodes().size()); + // WW for (size_t k = 0; k < n_connected_nodes; k++) - if (nod->getConnectedNodes()[k] == - static_cast(ele->nodes_index[l])) + if (nod->getConnectedNodes()[k] == static_cast(ele->nodes_index[l])) { exist = true; break; } - if (!exist) //WW + if (!exist) // WW nod->getConnectedNodes().push_back(ele->nodes_index[l]); } } } // Sorting. WW - //WW + // WW for (size_t i = 0; i < nod_vector.size(); i++) { CNode* nod = nod_vector[i]; @@ -3183,19 +3057,19 @@ void CFEMesh::ConnectedNodes(bool quadratic) const for (size_t l = k; l < n_connected_nodes; l++) if (nod->getConnectedNodes()[l] < nod->getConnectedNodes()[k]) { - const size_t n (nod->getConnectedNodes()[k]); + const size_t n(nod->getConnectedNodes()[k]); nod->getConnectedNodes()[k] = nod->getConnectedNodes()[l]; nod->getConnectedNodes()[l] = n; } } } - //---------------------------------------------------------------------- +//---------------------------------------------------------------------- #ifdef TestConnectedNodes - for(i = 0; i < (long)nod_vector.size(); i++) + for (i = 0; i < (long)nod_vector.size(); i++) { nod = nod_vector[i]; cout << (int)nod->connected_nodes.size() << ": "; - for(m = 0; m < (int)nod->connected_nodes.size(); m++) + for (m = 0; m < (int)nod->connected_nodes.size(); m++) cout << nod->connected_nodes[m] << " "; cout << "\n"; } @@ -3212,11 +3086,11 @@ void CFEMesh::FaceNormal() { int idx0_face, idx1_face, idx_owner, index0 = 0, index1 = 0; - CElem* elem (NULL); - CElem* elem_face (NULL); + CElem* elem(NULL); + CElem* elem_face(NULL); if (!face_normal.empty()) - return; //WW + return; // WW //------------------------ for (size_t i = 0; i < face_vector.size(); i++) { @@ -3226,7 +3100,7 @@ void CFEMesh::FaceNormal() if (elem->GetElementType() == MshElemType::LINE) return; - //WW int no_face_vertex = face_vector[i]->GetVertexNumber(); + // WW int no_face_vertex = face_vector[i]->GetVertexNumber(); int no_owner_vertex = face_vector[i]->GetOwner()->GetVertexNumber(); idx0_face = face_vector[i]->GetNodeIndex(0); idx1_face = face_vector[i]->GetNodeIndex(1); @@ -3270,7 +3144,7 @@ void CFEMesh::SetNODPatchAreas() CNode* m_nod = NULL; CElem* m_ele = NULL; //---------------------------------------------------------------------- - size_t nNodes (nod_vector.size()); + size_t nNodes(nod_vector.size()); for (size_t i = 0; i < nNodes; i++) { m_nod = nod_vector[i]; // this node @@ -3286,29 +3160,29 @@ void CFEMesh::SetNODPatchAreas() { switch (k) { - case 0: - n1 = 2; - n2 = 1; - break; - case 1: - n1 = 0; - n2 = 2; - break; - case 2: - n1 = 1; - n2 = 0; - break; + case 0: + n1 = 2; + n2 = 1; + break; + case 1: + n1 = 0; + n2 = 2; + break; + case 2: + n1 = 1; + n2 = 0; + break; } } //.................................................................. double const* gravity_center(m_ele->GetGravityCenter()); - double const* const pnt (m_nod->getData()); + double const* const pnt(m_nod->getData()); v2[0] = gravity_center[0] - pnt[0]; v2[1] = gravity_center[1] - pnt[1]; v2[2] = gravity_center[2] - pnt[2]; //.................................................................. -// m_nod1 = nod_vector[m_ele->GetNodeIndex(n1)]; - double const* const pnt1 (nod_vector[m_ele->GetNodeIndex(n1)]->getData()); + // m_nod1 = nod_vector[m_ele->GetNodeIndex(n1)]; + double const* const pnt1(nod_vector[m_ele->GetNodeIndex(n1)]->getData()); x0 = 0.5 * (pnt1[0] - pnt[0]); y0 = 0.5 * (pnt1[1] - pnt[1]); z0 = 0.5 * (pnt1[2] - pnt[2]); @@ -3318,8 +3192,8 @@ void CFEMesh::SetNODPatchAreas() CrossProduction(v1, v2, v3); patch_area += 0.5 * MBtrgVec(v3, 3); //.................................................................. -// m_nod2 = nod_vector[m_ele->GetNodeIndex(n2)]; - double const* const pnt2 (nod_vector[m_ele->GetNodeIndex(n2)]->getData()); + // m_nod2 = nod_vector[m_ele->GetNodeIndex(n2)]; + double const* const pnt2(nod_vector[m_ele->GetNodeIndex(n2)]->getData()); x0 = 0.5 * (pnt2[0] - pnt[0]); y0 = 0.5 * (pnt2[1] - pnt[1]); z0 = 0.5 * (pnt2[2] - pnt[2]); @@ -3344,27 +3218,27 @@ void CFEMesh::SetNetworkIntersectionNodes() long i, e; int j, k; double v3[3], nr1[3], nr2[3]; - //WW double* gravity_center; + // WW double* gravity_center; CNode* m_nod = NULL; CElem* m_ele = NULL; CElem* m_ele1 = NULL; //---------------------------------------------------------------------- // Is node intersection node - for (i = 0; i < (long) nod_vector.size(); i++) + for (i = 0; i < (long)nod_vector.size(); i++) m_nod = nod_vector[i]; - // KR m_nod->selected = false; - //KR double eps = 1e-3; - for (i = 0; i < (long) nod_vector.size(); i++) + // KR m_nod->selected = false; + // KR double eps = 1e-3; + for (i = 0; i < (long)nod_vector.size(); i++) { m_nod = nod_vector[i]; // this node - if ((int) m_nod->getConnectedElementIDs().size() == 0) + if ((int)m_nod->getConnectedElementIDs().size() == 0) continue; m_ele = ele_vector[m_nod->getConnectedElementIDs()[0]]; for (k = 0; k < 3; k++) nr1[k] = (*m_ele->transform_tensor)(2, k); //.................................................................... // Compare element normal vectors - for (j = 1; j < (int) m_nod->getConnectedElementIDs().size(); j++) + for (j = 1; j < (int)m_nod->getConnectedElementIDs().size(); j++) { e = m_nod->getConnectedElementIDs()[j]; m_ele1 = ele_vector[e]; @@ -3389,7 +3263,7 @@ void CFEMesh::SetNetworkIntersectionNodes() // } } -#ifdef NEW_EQS // 1.11.2007 WW +#ifdef NEW_EQS // 1.11.2007 WW /************************************************************************** MSHLib-Method: Programing: @@ -3400,8 +3274,8 @@ void CFEMesh::CreateSparseTable() { Math_Group::StorageType stype; stype = Math_Group::JDS; - for(int i = 0; i < (int)num_vector.size(); i++) - if(num_vector[i]->ls_storage_method == 100) + for (int i = 0; i < (int)num_vector.size(); i++) + if (num_vector[i]->ls_storage_method == 100) { stype = Math_Group::CRS; break; @@ -3409,12 +3283,12 @@ void CFEMesh::CreateSparseTable() // Symmetry case is skipped. // 1. Sparse_graph_H for high order interpolation. Up to now, deformation - if(NodesNumber_Linear != NodesNumber_Quadratic) + if (NodesNumber_Linear != NodesNumber_Quadratic) sparse_graph_H = new SparseTable(this, true, false, stype); // 2. M coupled with other processes with linear element - if(sparse_graph_H) + if (sparse_graph_H) { - if((int)pcs_vector.size() > 1) + if ((int)pcs_vector.size() > 1) sparse_graph = new SparseTable(this, false, false, stype); } // 3. For process with linear elements @@ -3424,10 +3298,10 @@ void CFEMesh::CreateSparseTable() // sparse_graph->Write(); // sparse_graph_H->Write(); // - //ofstream Dum("sparse.txt", ios::out); - //sparse_graph_H->Write(Dum); + // ofstream Dum("sparse.txt", ios::out); + // sparse_graph_H->Write(Dum); } -#endif //#ifndef NEW_EQS // 05.03.2010 WW +#endif //#ifndef NEW_EQS // 05.03.2010 WW //--------------------------------------------------------------------------- /*! @@ -3443,7 +3317,7 @@ void CFEMesh::CreateSparseTable() * improved implementation a little bit (still a lot to do) */ //--------------------------------------------------------------------------- -void CFEMesh::ImportMODFlowGrid(std::string const & fname) +void CFEMesh::ImportMODFlowGrid(std::string const& fname) { size_t nrows; size_t nlayers; @@ -3471,7 +3345,7 @@ void CFEMesh::ImportMODFlowGrid(std::string const & fname) ins >> zz[l]; ins >> std::ws; - //getline(ins, aline); + // getline(ins, aline); bool flag; for (size_t i = 0; i < nlayers; i++) { @@ -3571,7 +3445,7 @@ void CFEMesh::ImportMODFlowGrid(std::string const & fname) { if (layer_act_flag[counter]) { - elem = new CElem((long) ele_vector.size()); + elem = new CElem((long)ele_vector.size()); ele_vector.push_back(elem); elem->setElementProperties(MshElemType::HEXAHEDRON); @@ -3606,8 +3480,7 @@ void CFEMesh::ImportMODFlowGrid(std::string const & fname) for (ii = 0; ii < 8; ii++) { elem->SetNodeIndex(ii, marked_nodes[nn[ii]]); - elem->nodes[ii] = - nod_vector[elem->GetNodeIndex(ii)]; + elem->nodes[ii] = nod_vector[elem->GetNodeIndex(ii)]; } ri = nrows - l; @@ -3616,10 +3489,7 @@ void CFEMesh::ImportMODFlowGrid(std::string const & fname) li = nrows * ncols * (i + jj) + k * nrows + ri; for (ii = 4 * jj; ii < 4 * (jj + 1); ii++) { - z = - nod_vector[marked_nodes[nn[ii]]]-> - getData() - [2] + eval[li]; + z = nod_vector[marked_nodes[nn[ii]]]->getData()[2] + eval[li]; nod_vector[marked_nodes[nn[ii]]]->SetZ(z); } } @@ -3633,7 +3503,7 @@ void CFEMesh::ImportMODFlowGrid(std::string const & fname) marked_nodes.clear(); ConstructGrid(); - for(l = 0; l < nod_vector.size(); l++) + for (l = 0; l < nod_vector.size(); l++) { node = nod_vector[l]; z = node->getData()[2] / (double)node->getConnectedElementIDs().size(); @@ -3656,7 +3526,7 @@ void CFEMesh::ImportMODFlowGrid(std::string const & fname) added several std:: in order to avoid name space pollution */ //--------------------------------------------------------------------------- -void CFEMesh::ConvertShapeCells(std::string const & fname) +void CFEMesh::ConvertShapeCells(std::string const& fname) { size_t i; long counter; @@ -3674,33 +3544,32 @@ void CFEMesh::ConvertShapeCells(std::string const & fname) CElem* elem; CNode* point = NULL; - for(size_t l = 0; l < nsize; l++) + for (size_t l = 0; l < nsize; l++) { mark[l] = false; node_index[l] = -1; } - for(size_t l = 0; l < nrows; l++) + for (size_t l = 0; l < nrows; l++) { ll = nrows - 1 - l; - for(size_t k = 0; k < ncols; k++) + for (size_t k = 0; k < ncols; k++) { counter = l * ncols + k; - if(fabs(zz[counter] - ndata_v) > DBL_MIN) + if (fabs(zz[counter] - ndata_v) > DBL_MIN) { elem = new CElem((long)ele_vector.size()); ele_vector.push_back(elem); // Boundary - if(!(k == 0 || (k == ncols - 1) || l == 0 || (l == nrows - 1))) + if (!(k == 0 || (k == ncols - 1) || l == 0 || (l == nrows - 1))) { neighbor[0] = l * ncols + k - 1; neighbor[1] = l * ncols + k + 1; neighbor[2] = (l - 1) * ncols + k; neighbor[3] = (l + 1) * ncols + k; - for(i = 0; i < 4; i++) - if(fabs(zz[ neighbor[i]] - ndata_v) < DBL_MIN) + for (i = 0; i < 4; i++) + if (fabs(zz[neighbor[i]] - ndata_v) < DBL_MIN) break; - } elem->nnodes = 4; @@ -3720,11 +3589,11 @@ void CFEMesh::ConvertShapeCells(std::string const & fname) elem->boundary_type = 'I'; // Initialize topological properties elem->neighbors.resize(elem->nfaces); - for(i = 0; i < elem->nfaces; i++) + for (i = 0; i < elem->nfaces; i++) elem->neighbors[i] = NULL; elem->edges.resize(elem->nedges); elem->edges_orientation.resize(elem->nedges); - for(i = 0; i < elem->nedges; i++) + for (i = 0; i < elem->nedges; i++) { elem->edges[i] = NULL; elem->edges_orientation[i] = 1; @@ -3737,7 +3606,7 @@ void CFEMesh::ConvertShapeCells(std::string const & fname) neighbor[1] = (l + 1) * (ncols + 1) + k; neighbor[2] = (l + 1) * (ncols + 1) + k + 1; neighbor[3] = l * (ncols + 1) + k + 1; - for(i = 0; i < 4; i++) + for (i = 0; i < 4; i++) { elem->SetNodeIndex(i, neighbor[i]); mark[neighbor[i]] = true; @@ -3747,13 +3616,13 @@ void CFEMesh::ConvertShapeCells(std::string const & fname) } // Nodes - for(size_t l = 0; l <= nrows; l++) + for (size_t l = 0; l <= nrows; l++) { ll = nrows - l; - for(size_t k = 0; k <= ncols; k++) + for (size_t k = 0; k <= ncols; k++) { counter = l * (ncols + 1) + k; - if(mark[counter]) + if (mark[counter]) { x = x0 + csize * k; y = y0 + csize * ll; @@ -3764,17 +3633,17 @@ void CFEMesh::ConvertShapeCells(std::string const & fname) } } - for(size_t l = 0; l < ele_vector.size(); l++) + for (size_t l = 0; l < ele_vector.size(); l++) { elem = ele_vector[l]; - for(size_t i = 0; i < 4; i++) + for (size_t i = 0; i < 4; i++) { elem->nodes[i] = nod_vector[node_index[elem->GetNodeIndex(i)]]; elem->SetNodeIndex(i, elem->nodes[i]->GetIndex()); } } - /// To Karsten: If tri elements, activate the following +/// To Karsten: If tri elements, activate the following #ifndef need_quad //------------------------------------------------------------- // Up here is the quadrilateral elements @@ -3784,7 +3653,7 @@ void CFEMesh::ConvertShapeCells(std::string const & fname) std::vector ele_tri_v; std::vector nodes_e(3); CElem* ele_tri; - for(size_t l = 0; l < ele_vector.size(); l++) + for (size_t l = 0; l < ele_vector.size(); l++) { elem = ele_vector[l]; @@ -3805,18 +3674,18 @@ void CFEMesh::ConvertShapeCells(std::string const & fname) ele_tri->boundary_type = 'I'; // Initialize topological properties ele_tri->neighbors.resize(ele_tri->nfaces); - for(i = 0; i < ele_tri->nfaces; i++) + for (i = 0; i < ele_tri->nfaces; i++) ele_tri->neighbors[i] = NULL; ele_tri->edges.resize(ele_tri->nedges); ele_tri->edges_orientation.resize(ele_tri->nedges); - for(i = 0; i < ele_tri->nedges; i++) + for (i = 0; i < ele_tri->nedges; i++) { ele_tri->edges[i] = NULL; ele_tri->edges_orientation[i] = 1; } ele_tri->area = 1.0; - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) { ele_tri->nodes[i] = elem->nodes[i]; ele_tri->nodes_index[i] = ele_tri->nodes[i]->GetIndex(); @@ -3839,30 +3708,30 @@ void CFEMesh::ConvertShapeCells(std::string const & fname) elem->boundary_type = 'I'; // Initialize topological properties elem->neighbors.resize(elem->nfaces); - for(i = 0; i < elem->nfaces; i++) + for (i = 0; i < elem->nfaces; i++) elem->neighbors[i] = NULL; elem->edges.resize(elem->nedges); elem->edges_orientation.resize(elem->nedges); - for(i = 0; i < elem->nedges; i++) + for (i = 0; i < elem->nedges; i++) { elem->edges[i] = NULL; elem->edges_orientation[i] = 1; } elem->area = 1.0; - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) { elem->nodes[i] = nodes_e[i]; elem->nodes_index[i] = elem->nodes[i]->GetIndex(); } } - for(size_t l = 0; l < ele_tri_v.size(); l++) + for (size_t l = 0; l < ele_tri_v.size(); l++) ele_vector.push_back(ele_tri_v[l]); ele_tri_v.clear(); - //------------------------------------------------------------- - /// To Karsten: If quad elements, comment ends here -#endif //ifndef need_quad +//------------------------------------------------------------- +/// To Karsten: If quad elements, comment ends here +#endif // ifndef need_quad ConstructGrid(); node_index.clear(); mark.clear(); @@ -3875,7 +3744,7 @@ void CFEMesh::ConvertShapeCells(std::string const & fname) 03/2010 WW */ -void CFEMesh::ReadShapeFile(std::string const & fname) +void CFEMesh::ReadShapeFile(std::string const& fname) { long l; @@ -3885,9 +3754,10 @@ void CFEMesh::ReadShapeFile(std::string const & fname) zz.clear(); std::ifstream ins(fname.c_str()); - if(!ins.good()) + if (!ins.good()) { - std::cout << "Can not find file " << "\n"; + std::cout << "Can not find file " + << "\n"; return; } @@ -3922,7 +3792,7 @@ void CFEMesh::ReadShapeFile(std::string const & fname) ss.clear(); zz.resize(nrows * ncols); - for(l = 0; l < (long)zz.size(); l++) + for (l = 0; l < (long)zz.size(); l++) ins >> zz[l]; ins.close(); } @@ -3941,9 +3811,7 @@ void CFEMesh::ReadShapeFile(std::string const & fname) 03/2010 WW */ -void CFEMesh::Precipitation2NeumannBC(std::string const & fname, - std::string const & ofname, - double ratio) +void CFEMesh::Precipitation2NeumannBC(std::string const& fname, std::string const& ofname, double ratio) { int k; long nx, ny; @@ -3956,8 +3824,8 @@ void CFEMesh::Precipitation2NeumannBC(std::string const & fname, std::vector val; val.resize(NodesNumber_Linear); - const size_t nod_vector_size (nod_vector.size()); - for(size_t i = 0; i < nod_vector_size; i++) + const size_t nod_vector_size(nod_vector.size()); + for (size_t i = 0; i < nod_vector_size; i++) { nod_vector[i]->SetMark(false); val[i] = 0.0; @@ -3968,49 +3836,49 @@ void CFEMesh::Precipitation2NeumannBC(std::string const & fname, // std::ofstream ofile_bin(ofname.c_str(), std::ios::trunc | std::ios::binary); - ofile_bin.setf(std::ios::scientific,std::ios::floatfield); + ofile_bin.setf(std::ios::scientific, std::ios::floatfield); ofile_bin.precision(14); // CElem *elem (face_vector[i]); // CElem *own_elem (elem->owner); // - for(size_t i = 0; i < face_vector.size(); i++) + for (size_t i = 0; i < face_vector.size(); i++) { elem = face_vector[i]; - if(!elem->GetMark()) + if (!elem->GetMark()) continue; - for(k = 0; k < elem->nnodes; k++) + for (k = 0; k < elem->nnodes; k++) node_val[k] = 0.0; - for(k = 0; k < elem->nnodes; k++) + for (k = 0; k < elem->nnodes; k++) { node = elem->nodes[k]; - double const* const pnt_k (elem->nodes[k]->getData()); + double const* const pnt_k(elem->nodes[k]->getData()); nx = (long)((pnt_k[0] - x0) / csize); ny = (long)((pnt_k[1] - y0) / csize); ny = nrows - ny; - if(ny < 0) + if (ny < 0) ny = 0; - if(ny > static_cast(nrows)) + if (ny > static_cast(nrows)) ny = nrows; - if(nx * csize + x0 >= pnt_k[0]) + if (nx * csize + x0 >= pnt_k[0]) nx -= 1; - if(ny * csize + y0 >= pnt_k[1]) + if (ny * csize + y0 >= pnt_k[1]) ny -= 1; - if(nx >= static_cast(ncols) - 1) + if (nx >= static_cast(ncols) - 1) nx = ncols - 2; - if(ny >= static_cast(nrows) - 1) + if (ny >= static_cast(nrows) - 1) ny = nrows - 2; - if(nx < 0) + if (nx < 0) nx = 0; - if(ny < 0) + if (ny < 0) ny = 0; node_val[k] = zz[ncols * ny + nx]; - if(fabs(node_val[k] - ndata_v) < DBL_MIN) + if (fabs(node_val[k] - ndata_v) < DBL_MIN) node_val[k] = 0.; } @@ -4018,7 +3886,7 @@ void CFEMesh::Precipitation2NeumannBC(std::string const & fname, fem->setOrder(getOrder() + 1); fem->ConfigElement(elem, 3); fem->FaceIntegration(node_val); - for(k = 0; k < elem->nnodes; k++) + for (k = 0; k < elem->nnodes; k++) { node = elem->nodes[k]; node->SetMark(true); @@ -4027,19 +3895,19 @@ void CFEMesh::Precipitation2NeumannBC(std::string const & fname, } long counter = 0; - for(size_t i = 0; i < nod_vector_size; i++) + for (size_t i = 0; i < nod_vector_size; i++) { - if(!nod_vector[i]->GetMark()) + if (!nod_vector[i]->GetMark()) continue; counter++; val[i] *= ratio * 1e-3; // Assuming the unit of precipitation is mm/day } ofile_bin.write((char*)(&counter), sizeof(counter)); - for(size_t i = 0; i < nod_vector_size; i++) + for (size_t i = 0; i < nod_vector_size; i++) { node = nod_vector[i]; - if(!node->GetMark()) + if (!node->GetMark()) continue; nx = node->GetIndex(); ofile_bin.write((char*)(&nx), sizeof(nx)); @@ -4071,11 +3939,11 @@ void CFEMesh::MarkInterface_mHM_Hydro_3D() /// For output z coordinate of all nodes on the top surface /// 13.08.2010. WW vector node_mark(NodesNumber_Linear); - for(i = 0; i < NodesNumber_Linear; i++) + for (i = 0; i < NodesNumber_Linear; i++) node_mark[i] = false; #endif - for(i = 0; i < (long)face_vector.size(); i++) + for (i = 0; i < (long)face_vector.size(); i++) { elem = face_vector[i]; own_elem = elem->owner; @@ -4084,74 +3952,74 @@ void CFEMesh::MarkInterface_mHM_Hydro_3D() // // compute center of mass cent[0] = cent[1] = cent[2] = 0.; // const int nodes_number_of_element (own_elem->GetNodesNumber(false)); - for(k = 0; k < own_elem->GetNodesNumber(false); k++) + for (k = 0; k < own_elem->GetNodesNumber(false); k++) { -// node = own_elem->nodes[k]; + // node = own_elem->nodes[k]; double const* const pnt_k(own_elem->nodes[k]->getData()); cent[0] += pnt_k[0]; cent[1] += pnt_k[1]; cent[2] += pnt_k[2]; } - for(k = 0; k < 3; k++) + for (k = 0; k < 3; k++) cent[k] /= (double)own_elem->GetNodesNumber(false); -// node = elem->nodes[0]; + // node = elem->nodes[0]; double const* const pnt_0(elem->nodes[0]->getData()); cent[0] -= pnt_0[0]; cent[1] -= pnt_0[1]; cent[2] -= pnt_0[2]; - NormalizeVector(cent,3); + NormalizeVector(cent, 3); elem->ComputeVolume(); elem->FillTransformMatrix(); /// Compute the normal to this surface element - fac = cent[0] * (*elem->transform_tensor)(0,2) - + cent[1] * (*elem->transform_tensor)(1,2) - + cent[2] * (*elem->transform_tensor)(2,2); - if(fac > 0.0) + fac = cent[0] * (*elem->transform_tensor)(0, 2) + cent[1] * (*elem->transform_tensor)(1, 2) + + cent[2] * (*elem->transform_tensor)(2, 2); + if (fac > 0.0) fac = -1.0; else fac = 1.0; ////// /// If n.z>0 - if((*elem->transform_tensor)(2,2) * fac > tol) + if ((*elem->transform_tensor)(2, 2) * fac > tol) { elem->SetMark(true); - for(k = 0; k < 3; k++) - (*elem->transform_tensor)(k,2) *= fac; + for (k = 0; k < 3; k++) + (*elem->transform_tensor)(k, 2) *= fac; #ifdef output_top_z - for(k = 0; k < elem->nnodes; k++) + for (k = 0; k < elem->nnodes; k++) node_mark[elem->nodes[k]->GetIndex()] = true; #endif } - else if ((*elem->transform_tensor)(2,2)*fac<-tol) - { - elem->SetMark(false); - for(k=0; k<3; k++) - (*elem->transform_tensor)(k,2) *= fac; + else if ((*elem->transform_tensor)(2, 2) * fac < -tol) + { + elem->SetMark(false); + for (k = 0; k < 3; k++) + (*elem->transform_tensor)(k, 2) *= fac; #ifdef output_top_z - for(k=0; kGetNodesNumber(quad); k++) - node_mark[elem->nodes[k]->GetIndex()] = bottom; + for (k = 0; k < elem->GetNodesNumber(quad); k++) + node_mark[elem->nodes[k]->GetIndex()] = bottom; #endif - } - else - elem->SetMark(false); + } + else + elem->SetMark(false); } #ifdef output_top_z string ccc = FileName + "_top_head.asc"; ofstream ofile_asci(ccc.c_str(), ios::trunc); - for(i = 0; i < (long)nod_vector.size(); i++) + for (i = 0; i < (long)nod_vector.size(); i++) { node = nod_vector[i]; - if(!node_mark[i]) + if (!node_mark[i]) continue; ofile_asci << node->GetIndex() << " " << node->Z() << "\n"; } - ofile_asci << "#STOP" << "\n"; + ofile_asci << "#STOP" + << "\n"; #endif } @@ -4174,7 +4042,7 @@ void CFEMesh::mHM2NeumannBC() std::string fname = *_geo_name + ".pcp"; std::ifstream ins(fname.c_str()); - if(!ins.good()) + if (!ins.good()) { std::cout << "Can not open file " << fname << "\n"; return; @@ -4185,7 +4053,7 @@ void CFEMesh::mHM2NeumannBC() MarkInterface_mHM_Hydro_3D(); std::string key, uname, ofname; - //char stro[1024]; + // char stro[1024]; getline(ins, aline); ss.str(aline); @@ -4203,41 +4071,43 @@ void CFEMesh::mHM2NeumannBC() infiltration_files = *_geo_name + ".ifl"; std::ofstream infil(infiltration_files.c_str(), std::ios::trunc); - std::basic_string ::size_type indexChWin, indexChLinux; + std::basic_string::size_type indexChWin, indexChLinux; indexChWin = indexChLinux = 0; - indexChWin = _geo_name->find_last_of('\\'); + indexChWin = _geo_name->find_last_of('\\'); indexChLinux = _geo_name->find_last_of('/'); // - std::string file_path; - if(indexChWin != std::string::npos) - file_path = _geo_name->substr(0,indexChWin) + "\\"; - else if(indexChLinux != std::string::npos) - file_path = _geo_name->substr(0,indexChLinux) + "/"; + std::string file_path; + if (indexChWin != std::string::npos) + file_path = _geo_name->substr(0, indexChWin) + "\\"; + else if (indexChLinux != std::string::npos) + file_path = _geo_name->substr(0, indexChLinux) + "/"; - while(!ins.eof()) + while (!ins.eof()) { getline(ins, aline); ss.str(aline); ss >> key; ss.clear(); - if(key.size() == 0) // An empty line + if (key.size() == 0) // An empty line continue; - if(key.find("#STOP") != std::string::npos) + if (key.find("#STOP") != std::string::npos) break; - //sprintf(stro, "%f",step); + // sprintf(stro, "%f",step); // ofname = stro; ofname = file_path + key + ".bin"; - infil << step << " " << key + ".bin" << "\n"; + infil << step << " " << key + ".bin" + << "\n"; key = file_path + key; Precipitation2NeumannBC(key, ofname, ratio); step += 1.0; } - infil << "#STOP" << "\n"; + infil << "#STOP" + << "\n"; infil.close(); } @@ -4262,31 +4132,31 @@ void CFEMesh::TopSurfaceIntegration() fem = new CElement(GetCoordinateFlag()); std::vector val; val.resize(NodesNumber_Linear); - for(i = 0; i < (long)nod_vector.size(); i++) + for (i = 0; i < (long)nod_vector.size(); i++) { nod_vector[i]->SetMark(false); val[i] = 0.0; } - std::string ofname = *_geo_name + "_top_surface_Neumann_BC.txt"; + std::string ofname = *_geo_name + "_top_surface_Neumann_BC.txt"; std::ofstream ofile_asci(ofname.c_str(), std::ios::trunc); - ofile_asci.setf(std::ios::scientific,std::ios::floatfield); + ofile_asci.setf(std::ios::scientific, std::ios::floatfield); ofile_asci.precision(14); - for(i = 0; i < (long)face_vector.size(); i++) + for (i = 0; i < (long)face_vector.size(); i++) { elem = face_vector[i]; - if(!elem->GetMark()) + if (!elem->GetMark()) continue; - for(k = 0; k < elem->nnodes; k++) + for (k = 0; k < elem->nnodes; k++) node_val[k] = 1.0; elem->ComputeVolume(); fem->setOrder(getOrder() + 1); fem->ConfigElement(elem, 3); fem->FaceIntegration(node_val); - for(k = 0; k < elem->nnodes; k++) + for (k = 0; k < elem->nnodes; k++) { node = elem->nodes[k]; node->SetMark(true); @@ -4294,16 +4164,17 @@ void CFEMesh::TopSurfaceIntegration() } } - for(i = 0; i < (long)nod_vector.size(); i++) + for (i = 0; i < (long)nod_vector.size(); i++) { node = nod_vector[i]; - if(!node->GetMark()) + if (!node->GetMark()) continue; nx = node->GetIndex(); ofile_asci << nx << " " << val[i] << "\n"; } - ofile_asci << "#STOP " << "\n"; + ofile_asci << "#STOP " + << "\n"; ofile_asci.close(); delete fem; @@ -4324,10 +4195,7 @@ GEOLIB::Grid const* CFEMesh::getGrid() const Task: 05/2009 WW **************************************************************************/ -void CFEMesh::HydroSysMeshGenerator(string fname, - const int nlayers, - const double thickness, - int mapping) +void CFEMesh::HydroSysMeshGenerator(string fname, const int nlayers, const double thickness, int mapping) { fstream gs_out; int k, mat_num; @@ -4342,55 +4210,55 @@ void CFEMesh::HydroSysMeshGenerator(string fname, setw(14); gs_out.precision(14); - if(mapping) + if (mapping) { // To do } - gs_out << "#FEM_MSH\n$PCS_TYPE\nOVERLAND_FLOW\n$NODES" << "\n"; + gs_out << "#FEM_MSH\n$PCS_TYPE\nOVERLAND_FLOW\n$NODES" + << "\n"; gs_out << (long)nod_vector.size() << "\n"; - for(i = 0; i < (long)nod_vector.size(); i++) + for (i = 0; i < (long)nod_vector.size(); i++) nod_vector[i]->Write(gs_out); - gs_out << "$ELEMENTS" << "\n"; + gs_out << "$ELEMENTS" + << "\n"; gs_out << (long)ele_vector.size() << "\n"; mat_num = 0; - for(i = 0; i < (long)ele_vector.size(); i++) + for (i = 0; i < (long)ele_vector.size(); i++) { an_ele = ele_vector[i]; an_ele->WriteGSmsh(gs_out); k = an_ele->GetPatchIndex(); - if(k > mat_num) + if (k > mat_num) mat_num = k; } mat_num++; - gs_out << - "#FEM_MSH\n$PCS_TYPE\n RICHARDS_FLOW\n$GEO_TYPE\nPOLYLINE REGIONAL\n$GEO_NAME\nREGIONAL" + gs_out << "#FEM_MSH\n$PCS_TYPE\n RICHARDS_FLOW\n$GEO_TYPE\nPOLYLINE REGIONAL\n$GEO_NAME\nREGIONAL" << "\n"; gs_out << "$NODES\n" << (nlayers + 1) * (long)nod_vector.size() << "\n"; double seg = thickness / (double)nlayers; double depth; long l, size_nodes_msh_t; size_nodes_msh_t = (long)nod_vector.size(); - for(i = 0; i < size_nodes_msh_t; i++) - for(k = 0; k <= nlayers; k++) + for (i = 0; i < size_nodes_msh_t; i++) + for (k = 0; k <= nlayers; k++) { depth = seg * (double)k; a_node = nod_vector[i]; - gs_out << k + i * (nlayers + 1) << deli - << a_node->X() << deli - << a_node->Y() << deli - << a_node->Z() - depth << deli << "\n"; + gs_out << k + i * (nlayers + 1) << deli << a_node->X() << deli << a_node->Y() << deli << a_node->Z() - depth + << deli << "\n"; } - gs_out << "$ELEMENTS" << "\n"; + gs_out << "$ELEMENTS" + << "\n"; gs_out << size_nodes_msh_t * nlayers << "\n"; l = 0; int mat_index; - for(i = 0; i < size_nodes_msh_t; i++) + for (i = 0; i < size_nodes_msh_t; i++) { // mat_index = ele_vector[nod_vector[i]->connected_elements[0]]->GetPatchIndex(); mat_index = mat_num; - for(k = 0; k < nlayers; k++) + for (k = 0; k < nlayers; k++) { l = k + (nlayers + 1) * i; gs_out << k + nlayers * i << deli << mat_index << deli << "line" << deli; @@ -4400,38 +4268,43 @@ void CFEMesh::HydroSysMeshGenerator(string fname, } gs_out << "$LAYER\n" << nlayers << "\n"; // - gs_out << "$BORDERS" << "\n"; + gs_out << "$BORDERS" + << "\n"; gs_out << "SECTOR_GROUND\n" << size_nodes_msh_t << "\n"; - for(i = 0; i < size_nodes_msh_t; i++) + for (i = 0; i < size_nodes_msh_t; i++) { k = nlayers; gs_out << k + i * (nlayers + 1) << deli << "\n"; } mat_num += nlayers; - gs_out << "#FEM_MSH\n$PCS_TYPE\nGROUNDWATER_FLOW\n$NODES" << "\n"; + gs_out << "#FEM_MSH\n$PCS_TYPE\nGROUNDWATER_FLOW\n$NODES" + << "\n"; gs_out << (long)nod_vector.size() << "\n"; - for(i = 0; i < (long)nod_vector.size(); i++) + for (i = 0; i < (long)nod_vector.size(); i++) { a_node = nod_vector[i]; a_node->SetZ(a_node->Z() - thickness); a_node->Write(gs_out); a_node->SetZ(a_node->Z() + thickness); } - gs_out << "$ELEMENTS" << "\n"; + gs_out << "$ELEMENTS" + << "\n"; gs_out << (long)ele_vector.size() << "\n"; - for(i = 0; i < (long)ele_vector.size(); i++) + for (i = 0; i < (long)ele_vector.size(); i++) { an_ele = ele_vector[i]; an_ele->SetPatchIndex(an_ele->GetPatchIndex() + mat_num); an_ele->WriteGSmsh(gs_out); } - gs_out << "$BORDERS" << "\n"; + gs_out << "$BORDERS" + << "\n"; gs_out << "SECTOR_SOIL\n" << (long)nod_vector.size() << "\n"; - for(i = 0; i < (long)nod_vector.size(); i++) + for (i = 0; i < (long)nod_vector.size(); i++) gs_out << i << deli << "\n"; - gs_out << "#STOP" << "\n"; + gs_out << "#STOP" + << "\n"; gs_out.close(); } #endif @@ -4442,233 +4315,239 @@ void CFEMesh::HydroSysMeshGenerator(string fname, */ size_t CFEMesh::FindElementByPoint(const double* xyz) { - double x1[3], x2[3], x3[3], x4[3], x5[3], x6[3], x7[3], x8[3]; - double a, a_sub[12]; - CNode *a_node; - CElem *n_ele; - double tol = 1e-9; - - const size_t ne = ele_vector.size(); - for(size_t i=0; iGetVolume(); - - a_node = n_ele->GetNode(0); - x1[0] = a_node->X(); - x1[1] = a_node->Y(); - x1[2] = a_node->Z(); - a_node = n_ele->GetNode(1); - x2[0] = a_node->X(); - x2[1] = a_node->Y(); - x2[2] = a_node->Z(); - - if(n_ele->GetElementType()!=MshElemType::LINE ) - { - a_node = n_ele->GetNode(2); - x3[0] = a_node->X(); - x3[1] = a_node->Y(); - x3[2] = a_node->Z(); - } - - if(n_ele->GetElementType()==MshElemType::QUAD || n_ele->GetElementType()==MshElemType::TETRAHEDRON) - { - a_node = n_ele->GetNode(3); - x4[0] = a_node->X(); - x4[1] = a_node->Y(); - x4[2] = a_node->Z(); - } - - if(n_ele->GetElementType()==MshElemType::PYRAMID) - { - a_node = n_ele->GetNode(3); - x4[0] = a_node->X(); - x4[1] = a_node->Y(); - x4[2] = a_node->Z(); - a_node = n_ele->GetNode(4); - x5[0] = a_node->X(); - x5[1] = a_node->Y(); - x5[2] = a_node->Z(); - } - - if(n_ele->GetElementType()==MshElemType::PRISM) - { - a_node = n_ele->GetNode(3); - x4[0] = a_node->X(); - x4[1] = a_node->Y(); - x4[2] = a_node->Z(); - a_node = n_ele->GetNode(4); - x5[0] = a_node->X(); - x5[1] = a_node->Y(); - x5[2] = a_node->Z(); - a_node = n_ele->GetNode(5); - x6[0] = a_node->X(); - x6[1] = a_node->Y(); - x6[2] = a_node->Z(); - } - - if(n_ele->GetElementType()==MshElemType::HEXAHEDRON) - { - a_node = n_ele->GetNode(3); - x4[0] = a_node->X(); - x4[1] = a_node->Y(); - x4[2] = a_node->Z(); - a_node = n_ele->GetNode(4); - x5[0] = a_node->X(); - x5[1] = a_node->Y(); - x5[2] = a_node->Z(); - a_node = n_ele->GetNode(5); - x6[0] = a_node->X(); - x6[1] = a_node->Y(); - x6[2] = a_node->Z(); - a_node = n_ele->GetNode(6); - x7[0] = a_node->X(); - x7[1] = a_node->Y(); - x7[2] = a_node->Z(); - a_node = n_ele->GetNode(7); - x8[0] = a_node->X(); - x8[1] = a_node->Y(); - x8[2] = a_node->Z(); - } - - switch(n_ele->GetElementType()) - { - case MshElemType::LINE: - double d1, d2, d3; - d1 = 0.; - d2 = 0.; - d3 = 0.; - for(int kk=0; kk<3; kk++) - { - d1 += (x1[kk] - xyz[kk]) * (x1[kk] - xyz[kk]); - d2 += (x2[kk] - xyz[kk]) * (x2[kk] - xyz[kk]); - d3 += (x1[kk] - x2[kk]) * (x1[kk] - x2[kk]); - } - d1 = sqrt(d1); - d2 = sqrt(d2); - d3 = sqrt(d3); - - if(fabs((d1+d2-d3)/d3)GetVolume(); + + a_node = n_ele->GetNode(0); + x1[0] = a_node->X(); + x1[1] = a_node->Y(); + x1[2] = a_node->Z(); + a_node = n_ele->GetNode(1); + x2[0] = a_node->X(); + x2[1] = a_node->Y(); + x2[2] = a_node->Z(); + + if (n_ele->GetElementType() != MshElemType::LINE) + { + a_node = n_ele->GetNode(2); + x3[0] = a_node->X(); + x3[1] = a_node->Y(); + x3[2] = a_node->Z(); + } + + if (n_ele->GetElementType() == MshElemType::QUAD || n_ele->GetElementType() == MshElemType::TETRAHEDRON) + { + a_node = n_ele->GetNode(3); + x4[0] = a_node->X(); + x4[1] = a_node->Y(); + x4[2] = a_node->Z(); + } + + if (n_ele->GetElementType() == MshElemType::PYRAMID) + { + a_node = n_ele->GetNode(3); + x4[0] = a_node->X(); + x4[1] = a_node->Y(); + x4[2] = a_node->Z(); + a_node = n_ele->GetNode(4); + x5[0] = a_node->X(); + x5[1] = a_node->Y(); + x5[2] = a_node->Z(); + } + + if (n_ele->GetElementType() == MshElemType::PRISM) + { + a_node = n_ele->GetNode(3); + x4[0] = a_node->X(); + x4[1] = a_node->Y(); + x4[2] = a_node->Z(); + a_node = n_ele->GetNode(4); + x5[0] = a_node->X(); + x5[1] = a_node->Y(); + x5[2] = a_node->Z(); + a_node = n_ele->GetNode(5); + x6[0] = a_node->X(); + x6[1] = a_node->Y(); + x6[2] = a_node->Z(); + } + + if (n_ele->GetElementType() == MshElemType::HEXAHEDRON) + { + a_node = n_ele->GetNode(3); + x4[0] = a_node->X(); + x4[1] = a_node->Y(); + x4[2] = a_node->Z(); + a_node = n_ele->GetNode(4); + x5[0] = a_node->X(); + x5[1] = a_node->Y(); + x5[2] = a_node->Z(); + a_node = n_ele->GetNode(5); + x6[0] = a_node->X(); + x6[1] = a_node->Y(); + x6[2] = a_node->Z(); + a_node = n_ele->GetNode(6); + x7[0] = a_node->X(); + x7[1] = a_node->Y(); + x7[2] = a_node->Z(); + a_node = n_ele->GetNode(7); + x8[0] = a_node->X(); + x8[1] = a_node->Y(); + x8[2] = a_node->Z(); + } + + switch (n_ele->GetElementType()) + { + case MshElemType::LINE: + double d1, d2, d3; + d1 = 0.; + d2 = 0.; + d3 = 0.; + for (int kk = 0; kk < 3; kk++) + { + d1 += (x1[kk] - xyz[kk]) * (x1[kk] - xyz[kk]); + d2 += (x2[kk] - xyz[kk]) * (x2[kk] - xyz[kk]); + d3 += (x1[kk] - x2[kk]) * (x1[kk] - x2[kk]); + } + d1 = sqrt(d1); + d2 = sqrt(d2); + d3 = sqrt(d3); + + if (fabs((d1 + d2 - d3) / d3) < tol) + { + return i; + } + break; + + case MshElemType::TRIANGLE: + a_sub[0] = ComputeDetTri(x1, x2, xyz); + a_sub[1] = ComputeDetTri(x2, x3, xyz); + a_sub[2] = ComputeDetTri(x3, x1, xyz); + + if (fabs((a_sub[0] + a_sub[1] + a_sub[2] - a) / a) < tol) + { + return i; + } + break; + + case MshElemType::QUAD: + a_sub[0] = ComputeDetTri(x1, x2, xyz); + a_sub[1] = ComputeDetTri(x2, x3, xyz); + a_sub[2] = ComputeDetTri(x3, x4, xyz); + a_sub[3] = ComputeDetTri(x4, x1, xyz); + + if (fabs((a_sub[0] + a_sub[1] + a_sub[2] + a_sub[3] - a) / a) < tol) + { + return i; + } + break; + + case MshElemType::TETRAHEDRON: + a_sub[0] = ComputeDetTex(x2, x4, x3, xyz); + a_sub[1] = ComputeDetTex(x1, x3, x4, xyz); + a_sub[2] = ComputeDetTex(x2, x1, x4, xyz); + a_sub[3] = ComputeDetTex(x2, x3, x1, xyz); + + if (fabs((a_sub[0] + a_sub[1] + a_sub[2] + a_sub[3] - a) / a) < tol) + { + return i; + } + break; + + case MshElemType::PYRAMID: + a_sub[0] = ComputeDetTex(x1, x2, x4, xyz); + a_sub[1] = ComputeDetTex(x2, x3, x4, xyz); + a_sub[2] = ComputeDetTex(x1, x5, x2, xyz); + a_sub[3] = ComputeDetTex(x2, x5, x4, xyz); + a_sub[4] = ComputeDetTex(x3, x5, x4, xyz); + a_sub[5] = ComputeDetTex(x4, x5, x1, xyz); + + if (fabs((a_sub[0] + a_sub[1] + a_sub[2] + a_sub[3] + a_sub[4] + a_sub[5] - a) / a) < tol) + { + return i; + } + break; + + case MshElemType::PRISM: + a_sub[0] = ComputeDetTex(x1, x2, x3, xyz); + a_sub[1] = ComputeDetTex(x4, x6, x5, xyz); + a_sub[2] = ComputeDetTex(x1, x4, x2, xyz); + a_sub[3] = ComputeDetTex(x2, x4, x5, xyz); + a_sub[4] = ComputeDetTex(x2, x5, x3, xyz); + a_sub[5] = ComputeDetTex(x3, x5, x6, xyz); + a_sub[6] = ComputeDetTex(x3, x6, x1, xyz); + a_sub[7] = ComputeDetTex(x1, x6, x4, xyz); + + if (fabs((a_sub[0] + a_sub[1] + a_sub[2] + a_sub[3] + a_sub[4] + a_sub[5] + a_sub[6] + a_sub[7] - a) + / a) + < tol) + { + return i; + } + break; + + case MshElemType::HEXAHEDRON: + a_sub[0] = ComputeDetTex(x1, x2, x4, xyz); + a_sub[1] = ComputeDetTex(x4, x2, x3, xyz); + a_sub[2] = ComputeDetTex(x2, x6, x3, xyz); + a_sub[3] = ComputeDetTex(x3, x6, x7, xyz); + a_sub[4] = ComputeDetTex(x3, x7, x4, xyz); + a_sub[5] = ComputeDetTex(x4, x7, x8, xyz); + a_sub[6] = ComputeDetTex(x4, x8, x1, xyz); + a_sub[7] = ComputeDetTex(x1, x8, x5, xyz); + a_sub[8] = ComputeDetTex(x1, x5, x2, xyz); + a_sub[9] = ComputeDetTex(x2, x5, x6, xyz); + a_sub[10] = ComputeDetTex(x5, x8, x6, xyz); + a_sub[11] = ComputeDetTex(x6, x8, x7, xyz); + + if (fabs((a_sub[0] + a_sub[1] + a_sub[2] + a_sub[3] + a_sub[4] + a_sub[5] + a_sub[6] + a_sub[7] + + a_sub[8] + + a_sub[9] + + a_sub[10] + + a_sub[11] + - a) + / a) + < tol) + { + return i; + } + break; + + default: + // do nothing with other elements + break; + } + } + // Not find + return -1; } // 09. 2012 WW /// Free the memory occupied by edges void CFEMesh::FreeEdgeMemory() { - while(edge_vector.size()) - { - delete edge_vector[edge_vector.size() -1 ]; - edge_vector[edge_vector.size() -1 ] = NULL; - edge_vector.pop_back(); - } + while (edge_vector.size()) + { + delete edge_vector[edge_vector.size() - 1]; + edge_vector[edge_vector.size() - 1] = NULL; + edge_vector.pop_back(); + } - const size_t ne = ele_vector.size(); - for(size_t i=0; iFreeEdgeMemory(); - } + const size_t ne = ele_vector.size(); + for (size_t i = 0; i < ne; i++) + { + ele_vector[i]->FreeEdgeMemory(); + } } - - /************************************************************************** MSHLib-Method: Task: For TOTAL_FLUX calculation @@ -4676,32 +4555,31 @@ Task: For TOTAL_FLUX calculation 11/2014 JOD last modification: **************************************************************************/ -void CFEMesh::GetConnectedElements(std::vector&nodes_on_sfc, std::vector&vec_elements) +void CFEMesh::GetConnectedElements(std::vector& nodes_on_sfc, std::vector& vec_elements) { - std::set set_nodes_on_sfc; + std::set set_nodes_on_sfc; long i, j, k, l; //---------------------------------------------------------------------- // -->PETSC - // init - for (i = 0; i < (long)ele_vector.size(); i++) { - ele_vector[i]->selected = 0; //TODO can use a new variable + for (i = 0; i < (long)ele_vector.size(); i++) + { + ele_vector[i]->selected = 0; // TODO can use a new variable } // ---- search elements ------------------------------------------------------------------ - for (i = 0; i < (long)nodes_on_sfc.size(); i++) { + for (i = 0; i < (long)nodes_on_sfc.size(); i++) + { k = nodes_on_sfc[i]; - for (j = 0; j < (long)nod_vector[k]->getConnectedElementIDs().size(); j++) { + for (j = 0; j < (long)nod_vector[k]->getConnectedElementIDs().size(); j++) + { l = nod_vector[k]->getConnectedElementIDs()[j]; if (ele_vector[l]->selected == 0) vec_elements.push_back(l); ele_vector[l]->selected += 1; // number of elements at surface } } - - } - } // namespace MeshLib diff --git a/MSH/msh_mesh.h b/MSH/msh_mesh.h index 8bf884cc2..35af09cd7 100644 --- a/MSH/msh_mesh.h +++ b/MSH/msh_mesh.h @@ -7,9 +7,9 @@ * */ - /** - * \file msh_mesh.h - */ +/** +* \file msh_mesh.h +*/ /************************************************************************** MSHLib - Object: @@ -38,7 +38,7 @@ #include "Grid.h" // MSHLib -#include "MSHEnums.h" // KR 2010/11/15 +#include "MSHEnums.h" // KR 2010/11/15 #include "MeshNodesAlongPolyline.h" // FileIO @@ -51,9 +51,10 @@ class CFluidMomentum; class Problem; -#ifdef NEW_EQS //1.11.2007 WW +#ifdef NEW_EQS // 1.11.2007 WW namespace Math_Group -{class SparseTable; +{ +class SparseTable; } using Math_Group::SparseTable; #endif @@ -69,19 +70,19 @@ namespace MeshLib class GridsTopo { private: - long* local_indices; // of border nodes in local node array of a grid - //double *comm_data; // data for communication + long* local_indices; // of border nodes in local node array of a grid + // double *comm_data; // data for communication std::string neighbor_name; long bnodes; friend class CFEMesh; friend class ::CRFProcess; -public: - GridsTopo(std::istream &in, std::string sec_name); - std::string getNeighbor_Name() const {return neighbor_name; } - long* getBorderNodeIndicies() const {return local_indices; } - long getBorderNodeNumber() const {return bnodes; } - //void Write(std::ostream &os=cout); +public: + GridsTopo(std::istream& in, std::string sec_name); + std::string getNeighbor_Name() const { return neighbor_name; } + long* getBorderNodeIndicies() const { return local_indices; } + long getBorderNodeNumber() const { return bnodes; } + // void Write(std::ostream &os=cout); ~GridsTopo(); }; @@ -90,10 +91,10 @@ class GridsTopo typedef long MyInt; struct MeshNodes { - MyInt index; - double x; - double y; - double z; + MyInt index; + double x; + double y; + double z; }; #endif @@ -103,38 +104,36 @@ struct MeshNodes class CFEMesh { public: - /// Constructor using geometric information. CFEMesh(GEOLIB::GEOObjects* geo_obj = NULL, std::string* unique_name = NULL); /// Copy-Constructor. - /// Note that this is not a real copy-constructor. It copies only nodes and elements and calls ConstructGrid() afterwards. + /// Note that this is not a real copy-constructor. It copies only nodes and elements and calls ConstructGrid() + /// afterwards. CFEMesh(CFEMesh const& mesh); /// Destructor ~CFEMesh(); - GEOLIB::GEOObjects* getGEOObjects () const { return _geo_obj; } - - std::string* getProjectName () const { return _geo_name; } - + GEOLIB::GEOObjects* getGEOObjects() const { return _geo_obj; } + std::string* getProjectName() const { return _geo_name; } /** * sets the value for element type * @param ele_type */ - void setElementType (MshElemType::type ele_type); + void setElementType(MshElemType::type ele_type); /** * set the number of mesh layer * @param n_msh_layer */ - void setNumberOfMeshLayers (size_t n_msh_layer); + void setNumberOfMeshLayers(size_t n_msh_layer); /** * returns the number of mesh layers * @return the number of mesh layers */ - size_t getNumberOfMeshLayers () const; // TF + size_t getNumberOfMeshLayers() const; // TF /** * @@ -142,23 +141,23 @@ class CFEMesh */ bool hasCrossSection() const; - size_t getNumberOfLines () const; - size_t getNumberOfQuads () const; - size_t getNumberOfHexs () const; - size_t getNumberOfTris () const; - size_t getNumberOfTets () const; - size_t getNumberOfPrisms () const; - size_t getNumberOfPyramids () const; - double getMinEdgeLength () const; - CNode* const* getNodes() const //WW 05.2012. - { - return &nod_vector[0]; - } + size_t getNumberOfLines() const; + size_t getNumberOfQuads() const; + size_t getNumberOfHexs() const; + size_t getNumberOfTris() const; + size_t getNumberOfTets() const; + size_t getNumberOfPrisms() const; + size_t getNumberOfPyramids() const; + double getMinEdgeLength() const; + CNode* const* getNodes() const // WW 05.2012. + { + return &nod_vector[0]; + } /** * do not use this method REMOVE CANDIDATE * @param val */ - void setMinEdgeLength (double val) // TF temporary + void setMinEdgeLength(double val) // TF temporary { _min_edge_length = val; } @@ -186,12 +185,12 @@ class CFEMesh */ void computeSearchLength(double c = 2); - /*! + /*! \brief Read mesh data. - \param fem_file Stream for input, which has to read a line before calling this function + \param fem_file Stream for input, which has to read a line before calling this function \return Return true if there are other mesh to be read. */ - bool Read(std::ifstream *fem_file); + bool Read(std::ifstream* fem_file); friend class FileIO::OGSMeshIO; std::ios::pos_type GMSReadTIN(std::ifstream*); @@ -204,67 +203,42 @@ class CFEMesh /*! Fill data for subdomain mesh - @param header : mesh header - @param s_nodes : mesh nodes + @param header : mesh header + @param s_nodes : mesh nodes */ - void setSubdomainNodes(MyInt *header, const MeshNodes *s_nodes); + void setSubdomainNodes(MyInt* header, const MeshNodes* s_nodes); /*! Fill data for subdomain mesh - @param header : mesh header - @param elem_info : element information - @param inside : indicator for elements that are inside the subdomain + @param header : mesh header + @param elem_info : element information + @param inside : indicator for elements that are inside the subdomain */ - void setSubdomainElements(MyInt *header, const MyInt *elem_info, const bool inside); + void setSubdomainElements(MyInt* header, const MyInt* elem_info, const bool inside); int calMaximumConnectedNodes(); - /// Get number of nodes of the entire mesh - int getNumNodesGlobal() const - { - return glb_NodesNumber_Linear; - } - /// Get number of nodes of the entire mesh of quadratic elements - int getNumNodesGlobal_Q() const - { - return glb_NodesNumber_Quadratic; - } - /// Get number of nodes of the subdomain mesh - int getNumNodesLocal() const - { - return loc_NodesNumber_Linear; - } - /// Get number of nodes of the subdomain mesh of quadratic elements - int getNumNodesLocal_Q() const - { - return loc_NodesNumber_Quadratic; - } - /// Get the largest ID of active nodes for higher order interpolation - size_t getLargestActiveNodeID_Quadratic() const - { - return static_cast ( NodesNumber_Linear + loc_NodesNumber_Quadratic - - loc_NodesNumber_Linear ); - } + /// Get number of nodes of the entire mesh + int getNumNodesGlobal() const { return glb_NodesNumber_Linear; } + /// Get number of nodes of the entire mesh of quadratic elements + int getNumNodesGlobal_Q() const { return glb_NodesNumber_Quadratic; } + /// Get number of nodes of the subdomain mesh + int getNumNodesLocal() const { return loc_NodesNumber_Linear; } + /// Get number of nodes of the subdomain mesh of quadratic elements + int getNumNodesLocal_Q() const { return loc_NodesNumber_Quadratic; } + /// Get the largest ID of active nodes for higher order interpolation + size_t getLargestActiveNodeID_Quadratic() const + { + return static_cast(NodesNumber_Linear + loc_NodesNumber_Quadratic - loc_NodesNumber_Linear); + } #endif // -// void RenumberNodesForGlobalAssembly(); + // void RenumberNodesForGlobalAssembly(); // For number of nodes - int GetMaxElementDim() const - { - return max_ele_dim; - } - void SwitchOnQuadraticNodes(bool quad) - { - useQuadratic = quad; - } - bool getOrder() const - { - return useQuadratic; - } - bool isAxisymmetry() const - { - return _axisymmetry; - } + int GetMaxElementDim() const { return max_ele_dim; } + void SwitchOnQuadraticNodes(bool quad) { useQuadratic = quad; } + bool getOrder() const { return useQuadratic; } + bool isAxisymmetry() const { return _axisymmetry; } // Get number of nodes - //CMCD int to long + // CMCD int to long size_t GetNodesNumber(const bool quadr) const { if (quadr) @@ -281,34 +255,31 @@ class CFEMesh return NodesNumber_Linear; } - void InitialNodesNumber() //WW + void InitialNodesNumber() // WW { NodesNumber_Quadratic = NodesNumber_Linear = nod_vector.size(); } - void setNumberOfNodesFromNodesVectorSize () - { - NodesNumber_Linear = nod_vector.size(); - } + void setNumberOfNodesFromNodesVectorSize() { NodesNumber_Linear = nod_vector.size(); } /// Free the memory occupied by edges - void FreeEdgeMemory(); // 09.2012. WW + void FreeEdgeMemory(); // 09.2012. WW /** * @{ * */ - /*! - brief Find the element by a point + /*! + brief Find the element by a point */ - size_t FindElementByPoint(const double* xyz); + size_t FindElementByPoint(const double* xyz); /** * \brief depreciated method - uses old surface class */ - void GetNODOnPLY_XY(CGLPolyline* m_ply, std::vector&msh_nod_vector); + void GetNODOnPLY_XY(CGLPolyline* m_ply, std::vector& msh_nod_vector); // /** // * \brief depreciated method - uses old surface class // */ - void GetNODOnSFC_Vertical(Surface* m_sfc, std::vector&msh_nod_vector); + void GetNODOnSFC_Vertical(Surface* m_sfc, std::vector& msh_nod_vector); /** * \brief depreciated method @@ -317,17 +288,17 @@ class CFEMesh /** * \brief depreciated method */ - void CreateLayerPolylines(CGLPolyline*); //OK + void CreateLayerPolylines(CGLPolyline*); // OK // GEO-SFC /** * \brief depreciated method */ - void GetNODOnSFC(Surface* m_sfc, std::vector&msh_nod_vector, const bool for_s_term = false); + void GetNODOnSFC(Surface* m_sfc, std::vector& msh_nod_vector, const bool for_s_term = false); /** * \brief depreciated method */ - void GetNODOnSFC_PLY(Surface const* m_sfc, std::vector&msh_nod_vector, const bool for_s_term = false) const; + void GetNODOnSFC_PLY(Surface const* m_sfc, std::vector& msh_nod_vector, const bool for_s_term = false) const; /** * \brief depreciated method */ @@ -371,8 +342,8 @@ class CFEMesh * */ void GetNODOnPLY(const GEOLIB::Polyline* const ply, std::vector& msh_nod_vector, - bool automatic = true, - double eps = std::numeric_limits::epsilon()); + bool automatic = true, + double eps = std::numeric_limits::epsilon()); /** * @@ -386,41 +357,40 @@ class CFEMesh * @param ply * @param points */ - void getPointsForInterpolationAlongPolyline (const GEOLIB::Polyline* const ply, - std::vector& points); + void getPointsForInterpolationAlongPolyline(const GEOLIB::Polyline* const ply, std::vector& points); /** * GetNODOnPLY search the nearest nodes to the Polyline * */ void GetNODOnPLY(const GEOLIB::Polyline* const ply, - std::vector& msh_nod_vector, - const bool for_s_term = false, - bool automatic = true, - double search_radius = std::numeric_limits::epsilon()); + std::vector& msh_nod_vector, + const bool for_s_term = false, + bool automatic = true, + double search_radius = std::numeric_limits::epsilon()); /** * \brief gives the indices of CElement elements, which have an edge * in common with the polyline. */ - void GetELEOnPLY(const GEOLIB::Polyline*, std::vector&, bool With1DElements); // 11/2011 BG + void GetELEOnPLY(const GEOLIB::Polyline*, std::vector&, bool With1DElements); // 11/2011 BG /** * \brief gives the indices of nodes, which are contained in the surface */ void GetNODOnSFC(const GEOLIB::Surface* sfc, - std::vector& msh_nod_vector, - const bool for_s_term = false) const; + std::vector& msh_nod_vector, + const bool for_s_term = false) const; - /** @} */ // close doxygen group + /** @} */ // close doxygen group - //.................................................................... -#ifdef ObsoleteGUI //WW 03.2012 +//.................................................................... +#ifdef ObsoleteGUI // WW 03.2012 // QUAD->HEX void CreateHexELEFromQuad(int, double); // QUAD->LINE void CreateLineELEFromQuad(int, double, int); void SetActiveElements(std::vector&); - //MB + // MB void SetMSHPart(std::vector&, long); bool NodeExists(size_t node); // LINE->LINE @@ -440,8 +410,7 @@ class CFEMesh * returns the vector storing pointers to all nodes (class CNode) of the mesh * @return */ - const std::vector& getNodeVector () const { return nod_vector; } - + const std::vector& getNodeVector() const { return nod_vector; } // All nodes - should be private!!! std::vector nod_vector; @@ -450,9 +419,9 @@ class CFEMesh // All surface faces std::vector face_vector; // All surface normal - std::vector face_normal; //YD + std::vector face_normal; // YD - const std::vector& getElementVector () const { return ele_vector; } + const std::vector& getElementVector() const { return ele_vector; } /** * all elements stored in this vector * */ @@ -461,58 +430,62 @@ class CFEMesh // To record eqs_index->global node index std::vector Eqs2Global_NodeIndex; - //OK + // OK void PrismRefine(int Layer, int subdivision); void ConnectedNodes(bool quadratic) const; - //WW + // WW void ConnectedElements2Node(bool quadratic = false); - //OK + // OK std::vector mat_names_vector; - void DefineMobileNodes(CRFProcess*); //OK - void FaceNormal(); // YD - void SetNODPatchAreas(); //OK4310 - void SetNetworkIntersectionNodes(); //OK4319->PCH + void DefineMobileNodes(CRFProcess*); // OK + void FaceNormal(); // YD + void SetNODPatchAreas(); // OK4310 + void SetNetworkIntersectionNodes(); // OK4319->PCH - void GetConnectedElements(std::vector&nodes_on_sfc, std::vector&vec_elements); + void GetConnectedElements(std::vector& nodes_on_sfc, std::vector& vec_elements); -#ifdef NEW_EQS // 1.11.2007 WW +#ifdef NEW_EQS // 1.11.2007 WW // Compute the graph of the sparse matrix related to this mesh. 1.11.2007 WW void CreateSparseTable(); // Get the sparse graph 1.11.2007 WW - SparseTable* GetSparseTable(bool quad = false) - const {if(!quad) return sparse_graph; - else return sparse_graph_H; } + SparseTable* GetSparseTable(bool quad = false) const + { + if (!quad) + return sparse_graph; + else + return sparse_graph_H; + } #endif std::string pcs_name; - std::string geo_name; //MB - std::string geo_type_name; //OK10_4310 + std::string geo_name; // MB + std::string geo_type_name; // OK10_4310 - size_t max_mmp_groups; //OKCC + size_t max_mmp_groups; // OKCC int msh_max_dim; - RandomWalk* PT; // PCH + RandomWalk* PT; // PCH - CFluidMomentum* fm_pcs; // by PCH + CFluidMomentum* fm_pcs; // by PCH std::vector sorted_nodes; std::vector xy_change; bool nodes_are_sorted; /// Import MODFlow grid. 10.2009 WW - void ImportMODFlowGrid(std::string const & fname); + void ImportMODFlowGrid(std::string const& fname); /// Convert raster cells into grid. 12.2009 WW - void ConvertShapeCells(std::string const & fname); + void ConvertShapeCells(std::string const& fname); #ifdef USE_HydSysMshGen // Be activated if it is still needed. // WWmesh_header /// Generate Column-surface grid system for the modeling of surafce-subsuface coupled processes - //15.05.2009. WW // removed useless const TF + // 15.05.2009. WW // removed useless const TF void HydroSysMeshGenerator(std::string fname, int nlayers, double thickness, int mapping); #endif - void MarkInterface_mHM_Hydro_3D(); //07.06.2010. WW + void MarkInterface_mHM_Hydro_3D(); // 07.06.2010. WW void mHM2NeumannBC(); /// Comptute int {f} a dA on top surface. void TopSurfaceIntegration(); @@ -539,7 +512,7 @@ class CFEMesh std::vector _mesh_nodes_along_polylines; MshElemType::type _ele_type; - size_t _n_msh_layer; //OK + size_t _n_msh_layer; // OK bool _cross_section; size_t _msh_n_lines; size_t _msh_n_quads; @@ -553,7 +526,7 @@ class CFEMesh * method initializes the minimal edge length that is used in search algorithms */ void computeMinEdgeLength(); - double _min_edge_length; //TK + double _min_edge_length; // TK /** * length for geometrical search algorithms, calculated in method @@ -568,16 +541,16 @@ class CFEMesh size_t NodesNumber_Quadratic; /// For parallel computing. 03.2012. WW #if defined(USE_PETSC) // || defined(using other parallel scheme) - //int n_sub_elements; + // int n_sub_elements; int glb_NodesNumber_Linear; int glb_NodesNumber_Quadratic; - int loc_NodesNumber_Linear; //index of shadow nodes starts from this number + int loc_NodesNumber_Linear; // index of shadow nodes starts from this number int loc_NodesNumber_Quadratic; #endif bool useQuadratic; bool _axisymmetry; - bool top_surface_checked; // 07.06.2010. WW + bool top_surface_checked; // 07.06.2010. WW // Coordinate indicator // 10: X component only @@ -590,43 +563,40 @@ class CFEMesh int coordinate_system; bool has_multi_dim_ele; int max_ele_dim; - int map_counter; //21.01.2009 WW + int map_counter; // 21.01.2009 WW - bool mapping_check; //23.01.2009 WW + bool mapping_check; // 23.01.2009 WW /// Import shape file. 16.03.2026. WW size_t ncols, nrows; /// (x_0, y_0): coordinate of the left down corner double x0, y0, csize, ndata_v; - std::vector zz; //Elevation - inline void ReadShapeFile(std::string const & fname); + std::vector zz; // Elevation + inline void ReadShapeFile(std::string const& fname); // 03.2010. WW - inline void Precipitation2NeumannBC(std::string const & fname, - std::string const & ofname, - double ratio = 0.8); + inline void Precipitation2NeumannBC(std::string const& fname, std::string const& ofname, double ratio = 0.8); /// Store border nodes among different grids. std::vector grid_neighbors; friend class ::Problem; - // - // Sparse graph of this mesh. 1.11.2007 WW +// +// Sparse graph of this mesh. 1.11.2007 WW #ifdef NEW_EQS SparseTable* sparse_graph; - SparseTable* sparse_graph_H; // For high order interpolation + SparseTable* sparse_graph_H; // For high order interpolation #endif - void CreateLineElementsFromMarkedEdges(CFEMesh* m_msh_ply, - std::vector &ele_vector_at_ply); //NW + void CreateLineElementsFromMarkedEdges(CFEMesh* m_msh_ply, std::vector& ele_vector_at_ply); // NW + + /// Find nodes in convex polygon + void findNodesInPolygon(const double area_orig, const double tol, const size_t start_id, const size_t end_id, + const CGLPolyline* ply, std::vector& node_id_vector) const; - /// Find nodes in convex polygon - void findNodesInPolygon(const double area_orig, const double tol, - const size_t start_id, const size_t end_id, - const CGLPolyline *ply, - std::vector &node_id_vector) const; public: void constructMeshGrid(); + private: - GEOLIB::Grid *_mesh_grid; + GEOLIB::Grid* _mesh_grid; }; } // namespace MeshLib diff --git a/MSH/msh_node.cpp b/MSH/msh_node.cpp index bf91cd033..da28e90fe 100644 --- a/MSH/msh_node.cpp +++ b/MSH/msh_node.cpp @@ -30,9 +30,7 @@ namespace MeshLib Programing: 08/2011 NW Implementation **************************************************************************/ -CNode::CNode(size_t Index) : - CCore(Index), free_surface (-1), - patch_area (-1.0), crossroad (0), eqs_index(-1) +CNode::CNode(size_t Index) : CCore(Index), free_surface(-1), patch_area(-1.0), crossroad(0), eqs_index(-1) { coordinate[0] = 0.0; coordinate[1] = 0.0; @@ -45,32 +43,31 @@ CNode::CNode(size_t Index) : Programing: 06/2005 WW Implementation **************************************************************************/ -CNode::CNode(size_t Index, double x, double y, double z) : - CCore(Index), free_surface (-1), patch_area (-1.0), crossroad (false), eqs_index (-1) +CNode::CNode(size_t Index, double x, double y, double z) + : CCore(Index), free_surface(-1), patch_area(-1.0), crossroad(false), eqs_index(-1) { coordinate[0] = x; coordinate[1] = y; coordinate[2] = z; } -CNode::CNode(size_t Index, double const* coordinates) : - CCore(Index), free_surface (-1), patch_area (-1.0), crossroad (false), eqs_index (-1) +CNode::CNode(size_t Index, double const* coordinates) + : CCore(Index), free_surface(-1), patch_area(-1.0), crossroad(false), eqs_index(-1) { coordinate[0] = coordinates[0]; coordinate[1] = coordinates[1]; coordinate[2] = coordinates[2]; } -CNode::CNode(double x, double y, double z) : - CCore(0), free_surface (-1), patch_area (-1.0), crossroad (false), eqs_index (-1) +CNode::CNode(double x, double y, double z) + : CCore(0), free_surface(-1), patch_area(-1.0), crossroad(false), eqs_index(-1) { coordinate[0] = x; coordinate[1] = y; coordinate[2] = z; } -CNode::CNode(double const*const coords) : - CCore(0), free_surface (-1), patch_area (-1.0), crossroad (false), eqs_index (-1) +CNode::CNode(double const* const coords) : CCore(0), free_surface(-1), patch_area(-1.0), crossroad(false), eqs_index(-1) { coordinate[0] = coords[0]; coordinate[1] = coords[1]; @@ -83,8 +80,8 @@ CNode::CNode(double const*const coords) : Programing: 10/2009 NW Implementation **************************************************************************/ -CNode::CNode(size_t Index, const CNode* parent) : - CCore(Index), free_surface (-1), patch_area (-1.0), crossroad (false), eqs_index (-1) +CNode::CNode(size_t Index, const CNode* parent) + : CCore(Index), free_surface(-1), patch_area(-1.0), crossroad(false), eqs_index(-1) { coordinate[0] = parent->coordinate[0]; coordinate[1] = parent->coordinate[1]; @@ -97,7 +94,7 @@ CNode::CNode(size_t Index, const CNode* parent) : Programing: 06/2005 WW Implementation **************************************************************************/ -void CNode::operator = (const CNode& n) +void CNode::operator=(const CNode& n) { boundary_type = n.boundary_type; index = n.index; @@ -113,9 +110,9 @@ void CNode::operator = (const CNode& n) Programing: 06/2005 WW Implementation **************************************************************************/ -bool CNode::operator == (const CNode& n) +bool CNode::operator==(const CNode& n) { - if(index == n.index) + if (index == n.index) return true; else return false; @@ -131,12 +128,9 @@ void CNode::Write(std::ostream& osm) const std::string deli(" "); std::setw(14); osm.precision(14); - osm << index << deli - << coordinate[0] << deli - << coordinate[1] << deli - << coordinate[2] << deli; + osm << index << deli << coordinate[0] << deli << coordinate[1] << deli << coordinate[2] << deli; - if(patch_area > 0.0) + if (patch_area > 0.0) osm << "$AREA" << deli << patch_area; osm << "\n"; } @@ -153,10 +147,10 @@ void CNode::SetCoordinates(const double* argCoord) coordinate[2] = argCoord[2]; } -std::ostream& operator<< (std::ostream &os, MeshLib::CNode const &node) +std::ostream& operator<<(std::ostream& os, MeshLib::CNode const& node) { - node.write (os); + node.write(os); return os; } -} // namespace MeshLib +} // namespace MeshLib diff --git a/MSH/msh_node.h b/MSH/msh_node.h index 03368fa29..76c39f55b 100644 --- a/MSH/msh_node.h +++ b/MSH/msh_node.h @@ -32,157 +32,104 @@ namespace MeshLib class CNode : public CCore { public: - int free_surface; //MB ??? mobile + int free_surface; // MB ??? mobile // The vector to store the representative element index. // This can be used to extract the norm of the plane that the element lies on. // Establishing this vector is done in the Fluid Momentum // since this is bounded by velocity. std::vector connected_planes; // PCH - //GUI control variables - double patch_area; //OK4310 - bool crossroad; //KR changed to bool // PCH: Make theses privates can be done later on. - std::vector connected_faces; // BG, 09/2010, necessary for coupling to Eclipse, index of faces where the node is part of it + // GUI control variables + double patch_area; // OK4310 + bool crossroad; // KR changed to bool // PCH: Make theses privates can be done later on. + std::vector + connected_faces; // BG, 09/2010, necessary for coupling to Eclipse, index of faces where the node is part of it std::vector distance_to_connected_faces; // BG, 09/2010, necessary for coupling to Eclipse /** constructor */ CNode(size_t Index); CNode(double x, double y, double z); - CNode(double const*const coords); + CNode(double const* const coords); CNode(size_t Index, double x, double y, double z = 0.0); CNode(size_t Index, double const* coordinates); - CNode(size_t Index, const CNode* parent); //NW - ~CNode() - { - } - + CNode(size_t Index, const CNode* parent); // NW + ~CNode() {} // Operator - void operator =(const CNode& n); - bool operator ==(const CNode& n); + void operator=(const CNode& n); + bool operator==(const CNode& n); // Get functions /** \brief const access operator * The access to the coordinates is like the access to a field. */ - double const& operator[] (size_t idx) const + double const& operator[](size_t idx) const { - assert (idx <= 2); + assert(idx <= 2); return coordinate[idx]; } /** \brief access operator (see book Effektiv C++ programmieren - subsection 1.3.2 ). * \sa const T& operator[] (size_t idx) const */ - double& operator[] (size_t idx) - { - return const_cast (static_cast (*this)[idx]); - } - + double& operator[](size_t idx) { return const_cast(static_cast(*this)[idx]); } /** write mesh node coordinates into stream (used from operator<<) * \param os a standard output stream */ - virtual void write (std::ostream &os) const + virtual void write(std::ostream& os) const { os << coordinate[0] << " " << coordinate[1] << " " << coordinate[2] << std::flush; } - double X() const { return coordinate[0]; }; - double Y() const { return coordinate[1]; }; - double Z() const { return coordinate[2]; }; - -// void Coordinates(double *xyz) const -// { -// for (size_t i = 0; i < 3; i++) -// xyz[i] = coordinate[i]; -// } + double X() const { return coordinate[0]; }; + double Y() const { return coordinate[1]; }; + double Z() const { return coordinate[2]; }; + // void Coordinates(double *xyz) const + // { + // for (size_t i = 0; i < 3; i++) + // xyz[i] = coordinate[i]; + // } // 04/2010 TF /** * returns the coordinates of the mesh node * @return the coordinates of this mesh node */ - inline double const* getData() const - { - return coordinate; - } - + inline double const* getData() const { return coordinate; } // Set functions - void SetX(double argX) - { - coordinate[0] = argX; - } - - void SetY(double argY) - { - coordinate[1] = argY; - } - - void SetZ(double argZ) - { - coordinate[2] = argZ; - } - + void SetX(double argX) { coordinate[0] = argX; } + void SetY(double argY) { coordinate[1] = argY; } + void SetZ(double argZ) { coordinate[2] = argZ; } void SetCoordinates(const double* argCoord); - int GetEquationIndex() const - { - return eqs_index; - } - - void SetEquationIndex(long eqIndex) - { - eqs_index = eqIndex; - } - + int GetEquationIndex() const { return eqs_index; } + void SetEquationIndex(long eqIndex) { eqs_index = eqIndex; } // Output void Write(std::ostream& os = std::cout) const; - std::vector const & getConnectedElementIDs() const - { - return _connected_elements; - } - - std::vector & getConnectedElementIDs() - { - return _connected_elements; - } - - std::vector const& getConnectedNodes() const - { - return _connected_nodes; - } - - std::vector & getConnectedNodes() - { - return _connected_nodes; - } - - size_t getNumConnectedNodes() const - { - return _connected_nodes.size(); - } - + std::vector const& getConnectedElementIDs() const { return _connected_elements; } + std::vector& getConnectedElementIDs() { return _connected_elements; } + std::vector const& getConnectedNodes() const { return _connected_nodes; } + std::vector& getConnectedNodes() { return _connected_nodes; } + size_t getNumConnectedNodes() const { return _connected_nodes.size(); } /*! * \brief Check whether the node is non-ghost * \param id_max_act_l Maximum node ID of the non-ghost node for linear element. * \param id_max_l Maximum node ID of the node of linear element. * \param id_max_act_h Maximum node ID of the non-ghost node for quadratic element. */ - bool isNonGhost(const size_t id_max_act_l, const size_t id_max_l, - const size_t id_max_act_h) + bool isNonGhost(const size_t id_max_act_l, const size_t id_max_l, const size_t id_max_act_h) { - return (index < id_max_act_l) || (index >= id_max_l && index < id_max_act_h); + return (index < id_max_act_l) || (index >= id_max_l && index < id_max_act_h); } private: double coordinate[3]; long eqs_index; // renumber - std::vector _connected_nodes; //OK + std::vector _connected_nodes; // OK std::vector _connected_elements; }; -std::ostream& operator<< (std::ostream &os, MeshLib::CNode const &node); - -} // namespace MeshLib +std::ostream& operator<<(std::ostream& os, MeshLib::CNode const& node); +} // namespace MeshLib #endif diff --git a/MSH/msh_pnt.cpp b/MSH/msh_pnt.cpp index 4e7f92ae6..23262cd86 100644 --- a/MSH/msh_pnt.cpp +++ b/MSH/msh_pnt.cpp @@ -33,7 +33,7 @@ using namespace std; Programing: 05/2004 TK Implementation **************************************************************************/ -void TriCircumcenter3d(double a[3],double b[3],double c[3],double circumcenter[3]) +void TriCircumcenter3d(double a[3], double b[3], double c[3], double circumcenter[3]) { double xba, yba, zba, xca, yca, zca; double balength, calength; @@ -52,7 +52,7 @@ void TriCircumcenter3d(double a[3],double b[3],double c[3],double circumcenter[3 balength = xba * xba + yba * yba + zba * zba; calength = xca * xca + yca * yca + zca * zca; - /* Cross product of these edges. */ +/* Cross product of these edges. */ #ifdef EXACT /* Use orient2d() from http://www.cs.cmu.edu/~quake/robust.html */ /* to ensure a correctly signed (and reasonably accurate) result, */ @@ -68,18 +68,16 @@ void TriCircumcenter3d(double a[3],double b[3],double c[3],double circumcenter[3 #endif /* Calculate the denominator of the formulae. */ - denominator = 0.5 / (xcrossbc * xcrossbc + ycrossbc * ycrossbc + - zcrossbc * zcrossbc); + denominator = 0.5 / (xcrossbc * xcrossbc + ycrossbc * ycrossbc + zcrossbc * zcrossbc); /* Calculate offset (from `a') of circumcenter. */ - xcirca = ((balength * yca - calength * yba) * zcrossbc - - (balength * zca - calength * zba) * ycrossbc) * denominator; - ycirca = ((balength * zca - calength * zba) * xcrossbc - - (balength * xca - calength * xba) * zcrossbc) * denominator; - zcirca = ((balength * xca - calength * xba) * ycrossbc - - (balength * yca - calength * yba) * xcrossbc) * denominator; + xcirca + = ((balength * yca - calength * yba) * zcrossbc - (balength * zca - calength * zba) * ycrossbc) * denominator; + ycirca + = ((balength * zca - calength * zba) * xcrossbc - (balength * xca - calength * xba) * zcrossbc) * denominator; + zcirca + = ((balength * xca - calength * xba) * ycrossbc - (balength * yca - calength * yba) * xcrossbc) * denominator; circumcenter[0] = xcirca + a[0]; circumcenter[1] = ycirca + a[1]; circumcenter[2] = zcirca + a[2]; } - diff --git a/MSHGEOTOOLS/ExtractMeshNodes.cpp b/MSHGEOTOOLS/ExtractMeshNodes.cpp index 0f5fb0760..e5b01a96f 100644 --- a/MSHGEOTOOLS/ExtractMeshNodes.cpp +++ b/MSHGEOTOOLS/ExtractMeshNodes.cpp @@ -26,26 +26,23 @@ namespace MeshLib { -ExtractMeshNodes::ExtractMeshNodes(const CFEMesh* msh) : - _msh (msh), _gli_pnt_offset (0) +ExtractMeshNodes::ExtractMeshNodes(const CFEMesh* msh) : _msh(msh), _gli_pnt_offset(0) { } -void ExtractMeshNodes::writeMeshNodeIDs (std::ostream& os, - std::ostream& gli_out, - const GEOLIB::Polygon& polygon) +void ExtractMeshNodes::writeMeshNodeIDs(std::ostream& os, std::ostream& gli_out, const GEOLIB::Polygon& polygon) { // get all nodes of mesh - const std::vector& msh_nodes (_msh->getNodeVector()); + const std::vector& msh_nodes(_msh->getNodeVector()); std::vector node_indices; for (size_t j(0); j < msh_nodes.size(); j++) if (msh_nodes[j]->Interior()) { - GEOLIB::Point pnt (msh_nodes[j]->getData()); + GEOLIB::Point pnt(msh_nodes[j]->getData()); if (polygon.isPntInPolygon(pnt)) - node_indices.push_back (j); + node_indices.push_back(j); } // write data for (size_t k(0); k < node_indices.size(); k++) @@ -53,87 +50,86 @@ void ExtractMeshNodes::writeMeshNodeIDs (std::ostream& os, for (size_t k(0); k < node_indices.size(); k++) { - double const* const coords (msh_nodes[node_indices[k]]->getData()); - gli_out << k + _gli_pnt_offset << " " << coords[0] << " " << coords[1] << " " << - coords[2] << "\n"; + double const* const coords(msh_nodes[node_indices[k]]->getData()); + gli_out << k + _gli_pnt_offset << " " << coords[0] << " " << coords[1] << " " << coords[2] << "\n"; } _gli_pnt_offset += node_indices.size(); } -void ExtractMeshNodes::writeTopSurfaceMeshNodeIDs (std::ostream& os, - std::ostream& gli_out, - const GEOLIB::Polygon& polygon) +void ExtractMeshNodes::writeTopSurfaceMeshNodeIDs(std::ostream& os, + std::ostream& gli_out, + const GEOLIB::Polygon& polygon) { // get all nodes of mesh - const std::vector& msh_nodes (_msh->getNodeVector()); + const std::vector& msh_nodes(_msh->getNodeVector()); std::vector nodes_as_points; - for (size_t j(0); j < msh_nodes.size(); j++) { - GEOLIB::Point pnt (msh_nodes[j]->getData()); + for (size_t j(0); j < msh_nodes.size(); j++) + { + GEOLIB::Point pnt(msh_nodes[j]->getData()); if (polygon.isPntInPolygon(pnt)) - nodes_as_points.push_back (GEOLIB::PointWithID (msh_nodes[j]->getData(), j)); + nodes_as_points.push_back(GEOLIB::PointWithID(msh_nodes[j]->getData(), j)); } std::vector perm; for (size_t k(0); k < nodes_as_points.size(); k++) perm.push_back(k); - Quicksort (nodes_as_points, 0, nodes_as_points.size(), perm); + Quicksort(nodes_as_points, 0, nodes_as_points.size(), perm); - double eps (sqrt(std::numeric_limits::min())); + double eps(sqrt(std::numeric_limits::min())); // write data for (size_t k(1); k < nodes_as_points.size(); k++) { - const GEOLIB::PointWithID& p0 (nodes_as_points[k - 1]); - const GEOLIB::PointWithID& p1 (nodes_as_points[k]); - if (fabs (p0[0] - p1[0]) > eps || fabs (p0[1] - p1[1]) > eps) + const GEOLIB::PointWithID& p0(nodes_as_points[k - 1]); + const GEOLIB::PointWithID& p1(nodes_as_points[k]); + if (fabs(p0[0] - p1[0]) > eps || fabs(p0[1] - p1[1]) > eps) os << p0.getID() << "\n"; } // write last point os << nodes_as_points[nodes_as_points.size() - 1].getID() << "\n"; - size_t n_nodes (0); - gli_out.precision (14); + size_t n_nodes(0); + gli_out.precision(14); for (size_t k(1); k < nodes_as_points.size(); k++) { - const GEOLIB::PointWithID& p0 (nodes_as_points[k - 1]); - const GEOLIB::PointWithID& p1 (nodes_as_points[k]); - if (fabs (p0[0] - p1[0]) > eps || fabs (p0[1] - p1[1]) > eps) + const GEOLIB::PointWithID& p0(nodes_as_points[k - 1]); + const GEOLIB::PointWithID& p1(nodes_as_points[k]); + if (fabs(p0[0] - p1[0]) > eps || fabs(p0[1] - p1[1]) > eps) { - gli_out << n_nodes + _gli_pnt_offset << " " << std::scientific << p0 << - " $NAME " << p0.getID() << "\n"; + gli_out << n_nodes + _gli_pnt_offset << " " << std::scientific << p0 << " $NAME " << p0.getID() << "\n"; n_nodes++; } } // write last point - gli_out << n_nodes + _gli_pnt_offset << " " << std::scientific << - nodes_as_points[nodes_as_points.size() - 1] << " $NAME " << - nodes_as_points[nodes_as_points.size() - 1].getID() << "\n"; + gli_out << n_nodes + _gli_pnt_offset << " " << std::scientific << nodes_as_points[nodes_as_points.size() - 1] + << " $NAME " << nodes_as_points[nodes_as_points.size() - 1].getID() << "\n"; n_nodes++; _gli_pnt_offset += n_nodes; } -void ExtractMeshNodes::getOrthogonalProjectedMeshNodesAlongPolyline ( - GEOLIB::Polyline const& polyline, - std::vector& nodes_as_points) const +void ExtractMeshNodes::getOrthogonalProjectedMeshNodesAlongPolyline( + GEOLIB::Polyline const& polyline, std::vector& nodes_as_points) const { // get all nodes of mesh - std::vector const & msh_nodes (_msh->getNodeVector()); - size_t number_of_msh_nodes (msh_nodes.size()); + std::vector const& msh_nodes(_msh->getNodeVector()); + size_t number_of_msh_nodes(msh_nodes.size()); - size_t number_of_ply_pnts (polyline.getNumberOfPoints()); + size_t number_of_ply_pnts(polyline.getNumberOfPoints()); if (polyline.isClosed()) number_of_ply_pnts--; const double eps(_msh->getMinEdgeLength()); - for (size_t k(0); k < number_of_ply_pnts; k++) { + for (size_t k(0); k < number_of_ply_pnts; k++) + { GEOLIB::Point proj_ply_pnt((*(polyline.getPoint(k)))[0], (*(polyline.getPoint(k)))[1], 0.0); - for (size_t j(0); j < number_of_msh_nodes; j++) { + for (size_t j(0); j < number_of_msh_nodes; j++) + { GEOLIB::Point mesh_pnt(msh_nodes[j]->getData()); mesh_pnt[2] = 0.0; - if (MathLib::sqrDist(&mesh_pnt,&proj_ply_pnt) < eps) + if (MathLib::sqrDist(&mesh_pnt, &proj_ply_pnt) < eps) nodes_as_points.push_back(GEOLIB::PointWithID(msh_nodes[j]->getData(), j)); } } @@ -141,82 +137,80 @@ void ExtractMeshNodes::getOrthogonalProjectedMeshNodesAlongPolyline ( std::vector perm; for (size_t k(0); k < nodes_as_points.size(); k++) perm.push_back(k); - Quicksort (nodes_as_points, 0, nodes_as_points.size(), perm); + Quicksort(nodes_as_points, 0, nodes_as_points.size(), perm); } -void ExtractMeshNodes::getTopMeshNodesAlongPolylineAsPoints( - const GEOLIB::Polyline& polyline, - std::vector& top_points) const +void ExtractMeshNodes::getTopMeshNodesAlongPolylineAsPoints(const GEOLIB::Polyline& polyline, + std::vector& top_points) const { std::vector nodes_as_points; - this->getOrthogonalProjectedMeshNodesAlongPolyline (polyline, nodes_as_points); + this->getOrthogonalProjectedMeshNodesAlongPolyline(polyline, nodes_as_points); - double eps (std::numeric_limits::epsilon()); + double eps(std::numeric_limits::epsilon()); // collect data (lowest points with same x and y coodinates) - size_t upper_bound (nodes_as_points.size() - 1); + size_t upper_bound(nodes_as_points.size() - 1); for (size_t k(0); k < upper_bound; k++) { - const GEOLIB::PointWithID& p0 (nodes_as_points[k]); - const GEOLIB::PointWithID& p1 (nodes_as_points[k + 1]); - if (fabs (p0[0] - p1[0]) > eps || fabs (p0[1] - p1[1]) > eps) - top_points.push_back (new GEOLIB::Point (nodes_as_points[k].getData())); + const GEOLIB::PointWithID& p0(nodes_as_points[k]); + const GEOLIB::PointWithID& p1(nodes_as_points[k + 1]); + if (fabs(p0[0] - p1[0]) > eps || fabs(p0[1] - p1[1]) > eps) + top_points.push_back(new GEOLIB::Point(nodes_as_points[k].getData())); } - top_points.push_back (new GEOLIB::Point (nodes_as_points[upper_bound].getData())); + top_points.push_back(new GEOLIB::Point(nodes_as_points[upper_bound].getData())); } -void ExtractMeshNodes::getBottomMeshNodesAlongPolylineAsPoints( - const GEOLIB::Polyline& polyline, - std::vector& bottom_points) const +void ExtractMeshNodes::getBottomMeshNodesAlongPolylineAsPoints(const GEOLIB::Polyline& polyline, + std::vector& bottom_points) const { std::vector nodes_as_points; - this->getOrthogonalProjectedMeshNodesAlongPolyline (polyline, nodes_as_points); + this->getOrthogonalProjectedMeshNodesAlongPolyline(polyline, nodes_as_points); - double eps (std::numeric_limits::epsilon()); + double eps(std::numeric_limits::epsilon()); // collect data (lowest points with same x and y coodinates) - bottom_points.push_back (new GEOLIB::Point (nodes_as_points[0].getData())); - size_t upper_bound (nodes_as_points.size() - 1); + bottom_points.push_back(new GEOLIB::Point(nodes_as_points[0].getData())); + size_t upper_bound(nodes_as_points.size() - 1); for (size_t k(0); k < upper_bound; k++) { - const GEOLIB::PointWithID& p0 (nodes_as_points[k]); - const GEOLIB::PointWithID& p1 (nodes_as_points[k + 1]); - if (fabs (p0[0] - p1[0]) > eps || fabs (p0[1] - p1[1]) > eps) - bottom_points.push_back (new GEOLIB::Point (nodes_as_points[k + 1].getData())); + const GEOLIB::PointWithID& p0(nodes_as_points[k]); + const GEOLIB::PointWithID& p1(nodes_as_points[k + 1]); + if (fabs(p0[0] - p1[0]) > eps || fabs(p0[1] - p1[1]) > eps) + bottom_points.push_back(new GEOLIB::Point(nodes_as_points[k + 1].getData())); } } -void ExtractMeshNodes::getPolygonFromPolyline (const GEOLIB::Polyline& polyline, - GEOLIB::GEOObjects* geo_obj, - std::string const& name, - GEOLIB::Polygon* & polygon) const +void ExtractMeshNodes::getPolygonFromPolyline(const GEOLIB::Polyline& polyline, + GEOLIB::GEOObjects* geo_obj, + std::string const& name, + GEOLIB::Polygon*& polygon) const { std::vector top_polygon_pnts; - this->getTopMeshNodesAlongPolylineAsPoints (polyline, top_polygon_pnts); + this->getTopMeshNodesAlongPolylineAsPoints(polyline, top_polygon_pnts); std::vector bottom_polygon_pnts; - this->getBottomMeshNodesAlongPolylineAsPoints (polyline, bottom_polygon_pnts); + this->getBottomMeshNodesAlongPolylineAsPoints(polyline, bottom_polygon_pnts); // append new points to the end of the points vector - std::vector* top_ids (new std::vector); - geo_obj->appendPointVec (top_polygon_pnts, name, top_ids); - std::vector* bottom_ids (new std::vector); - geo_obj->appendPointVec (bottom_polygon_pnts, name, bottom_ids); + std::vector* top_ids(new std::vector); + geo_obj->appendPointVec(top_polygon_pnts, name, top_ids); + std::vector* bottom_ids(new std::vector); + geo_obj->appendPointVec(bottom_polygon_pnts, name, bottom_ids); // create (an empty) polygon - polygon = new GEOLIB::Polygon (*(geo_obj->getPointVec (name))); + polygon = new GEOLIB::Polygon(*(geo_obj->getPointVec(name))); - std::vector const* orig_pnts (geo_obj->getPointVec(name)); + std::vector const* orig_pnts(geo_obj->getPointVec(name)); // *** add ids of new points to polygon // for top polyline sort points along polyline - size_t s (top_ids->size()); + size_t s(top_ids->size()); for (size_t j(0); j < polyline.getNumberOfPoints(); j++) for (size_t k(0); k < s; k++) { - GEOLIB::Point* test_pnt (new GEOLIB::Point (*(*orig_pnts)[(*top_ids)[k]])); + GEOLIB::Point* test_pnt(new GEOLIB::Point(*(*orig_pnts)[(*top_ids)[k]])); (*test_pnt)[2] = 0.0; - if (MathLib::sqrDist(polyline.getPoint(j),test_pnt) - < std::numeric_limits::epsilon()) { - polygon->addPoint ((*top_ids)[k]); + if (MathLib::sqrDist(polyline.getPoint(j), test_pnt) < std::numeric_limits::epsilon()) + { + polygon->addPoint((*top_ids)[k]); k = s; } delete test_pnt; @@ -225,13 +219,15 @@ void ExtractMeshNodes::getPolygonFromPolyline (const GEOLIB::Polyline& polyline, // for bottom polyline sort points along polyline in reverse order s = bottom_ids->size(); GEOLIB::Point test_pnt(0.0, 0.0, 0.0); - for (int j(polyline.getNumberOfPoints() - 1); j > -1; j--) { - for (size_t k(0); k < s; k++) { + for (int j(polyline.getNumberOfPoints() - 1); j > -1; j--) + { + for (size_t k(0); k < s; k++) + { test_pnt[0] = (*(*orig_pnts)[(*bottom_ids)[k]])[0]; test_pnt[1] = (*(*orig_pnts)[(*bottom_ids)[k]])[1]; test_pnt[2] = 0.0; - if (MathLib::sqrDist(polyline.getPoint(j), &test_pnt) - < std::numeric_limits::epsilon()) { + if (MathLib::sqrDist(polyline.getPoint(j), &test_pnt) < std::numeric_limits::epsilon()) + { polygon->addPoint((*bottom_ids)[k]); k = s; } @@ -239,100 +235,102 @@ void ExtractMeshNodes::getPolygonFromPolyline (const GEOLIB::Polyline& polyline, } // close polygon - polygon->addPoint (polygon->getPointID(0)); + polygon->addPoint(polygon->getPointID(0)); polygon->initialise(); delete top_ids; delete bottom_ids; } -void ExtractMeshNodes::getProjectedPolylineFromPolyline(GEOLIB::Polyline const& ply_in, - GEOLIB::GEOObjects* geo_obj, std::string const& name, - GEOLIB::Polyline* &ply_out, size_t layer) const +void ExtractMeshNodes::getProjectedPolylineFromPolyline(GEOLIB::Polyline const& ply_in, GEOLIB::GEOObjects* geo_obj, + std::string const& name, GEOLIB::Polyline*& ply_out, + size_t layer) const { std::vector all_projected_ply_pnts; getOrthogonalProjectedMeshNodesAlongPolyline(ply_in, all_projected_ply_pnts); - if (! all_projected_ply_pnts.empty()) { + if (!all_projected_ply_pnts.empty()) + { // determine the mesh nodes from the right layer std::vector pnt_limits; pnt_limits.push_back(0); - size_t upper_bound (all_projected_ply_pnts.size() - 1); - const double eps (std::numeric_limits::epsilon()); - for (size_t k(0); k < upper_bound; k++) { - const GEOLIB::PointWithID& p0 (all_projected_ply_pnts[k]); - const GEOLIB::PointWithID& p1 (all_projected_ply_pnts[k + 1]); - if (fabs (p0[0] - p1[0]) > eps || fabs (p0[1] - p1[1]) > eps) - pnt_limits.push_back(k+1); + size_t upper_bound(all_projected_ply_pnts.size() - 1); + const double eps(std::numeric_limits::epsilon()); + for (size_t k(0); k < upper_bound; k++) + { + const GEOLIB::PointWithID& p0(all_projected_ply_pnts[k]); + const GEOLIB::PointWithID& p1(all_projected_ply_pnts[k + 1]); + if (fabs(p0[0] - p1[0]) > eps || fabs(p0[1] - p1[1]) > eps) + pnt_limits.push_back(k + 1); } std::vector selected_projected_ply_pnts; const size_t n(pnt_limits.size()); - for (size_t k(0); k pnt_ids_of_mesh_nodes; - geo_obj->appendPointVec (selected_projected_ply_pnts, name, &pnt_ids_of_mesh_nodes); + geo_obj->appendPointVec(selected_projected_ply_pnts, name, &pnt_ids_of_mesh_nodes); // create (an empty) polyline ply_out = new GEOLIB::Polyline(*(geo_obj->getPointVec(name))); // add ids to polyline const size_t size(pnt_ids_of_mesh_nodes.size()); - for (size_t k(0); kaddPoint(pnt_ids_of_mesh_nodes[k]); } - } else { - std::cout << "[ExtractMeshNodes::getProjectedPolylineFromPolyline] did not find any mesh nodes" << "\n"; + } + else + { + std::cout << "[ExtractMeshNodes::getProjectedPolylineFromPolyline] did not find any mesh nodes" + << "\n"; } } -void ExtractMeshNodes::writeMesh2DNodeIDAndArea (std::ostream& os, - std::ostream& gli_out, - const GEOLIB::Polygon& polygon) +void ExtractMeshNodes::writeMesh2DNodeIDAndArea(std::ostream& os, std::ostream& gli_out, const GEOLIB::Polygon& polygon) { // get all nodes of mesh - const std::vector& msh_nodes (_msh->getNodeVector()); + const std::vector& msh_nodes(_msh->getNodeVector()); // store node id std::vector node_ids; for (size_t j(0); j < msh_nodes.size(); j++) { - GEOLIB::Point pnt (msh_nodes[j]->getData()); + GEOLIB::Point pnt(msh_nodes[j]->getData()); if (polygon.isPntInPolygon(pnt)) - node_ids.push_back (j); + node_ids.push_back(j); } - std::sort (node_ids.begin(), node_ids.end()); + std::sort(node_ids.begin(), node_ids.end()); - size_t n_nodes (node_ids.size()); - std::vector areas (n_nodes, 0.0); + size_t n_nodes(node_ids.size()); + std::vector areas(n_nodes, 0.0); // in order to compute the area we need the mesh elements - const std::vector& msh_elem (_msh->getElementVector()); + const std::vector& msh_elem(_msh->getElementVector()); for (size_t k(0); k < n_nodes; k++) { // get all associated mesh elements - std::vector const & mesh_elem_ids( - msh_nodes[node_ids[k]]->getConnectedElementIDs()); - size_t n_mesh_elem_ids (mesh_elem_ids.size()); + std::vector const& mesh_elem_ids(msh_nodes[node_ids[k]]->getConnectedElementIDs()); + size_t n_mesh_elem_ids(mesh_elem_ids.size()); // get areas for mesh elements - double area (0.0); + double area(0.0); for (size_t j(0); j < n_mesh_elem_ids; j++) { // check if all mesh nodes of the element are inside the polygon std::vector mesh_element_node_indices; - msh_elem[mesh_elem_ids[j]]->getNodeIndices (mesh_element_node_indices); - size_t n_of_nodes_of_element (mesh_element_node_indices.size()); - bool found (true); + msh_elem[mesh_elem_ids[j]]->getNodeIndices(mesh_element_node_indices); + size_t n_of_nodes_of_element(mesh_element_node_indices.size()); + bool found(true); for (size_t i(0); i < n_of_nodes_of_element && found; i++) { - std::vector::iterator it(std::find ( - node_ids.begin(), - node_ids.end(), - mesh_element_node_indices[ - i])); + std::vector::iterator it( + std::find(node_ids.begin(), node_ids.end(), mesh_element_node_indices[i])); if (it == node_ids.end()) found = false; } @@ -348,73 +346,68 @@ void ExtractMeshNodes::writeMesh2DNodeIDAndArea (std::ostream& os, os << node_ids[k] << " " << areas[k] << "\n"; n_nodes = 0; - gli_out.precision (14); - for (std::vector::const_iterator it (node_ids.begin()); it != node_ids.end(); it++) + gli_out.precision(14); + for (std::vector::const_iterator it(node_ids.begin()); it != node_ids.end(); it++) { - double const* const pnt (msh_nodes[*it]->getData()); - gli_out << n_nodes + _gli_pnt_offset << " " << std::scientific - << pnt[0] << " " << pnt[1] << " " << pnt[2] << " $NAME " << *it << - "\n"; + double const* const pnt(msh_nodes[*it]->getData()); + gli_out << n_nodes + _gli_pnt_offset << " " << std::scientific << pnt[0] << " " << pnt[1] << " " << pnt[2] + << " $NAME " << *it << "\n"; n_nodes++; } _gli_pnt_offset += n_nodes; } -void ExtractMeshNodes::writeMesh2DNodeIDAndArea (std::ostream& os, - std::ostream& gli_out, - const GEOLIB::Polygon& bounding_polygon, - std::vector const& holes) +void ExtractMeshNodes::writeMesh2DNodeIDAndArea(std::ostream& os, + std::ostream& gli_out, + const GEOLIB::Polygon& bounding_polygon, + std::vector const& holes) { // get all nodes of mesh - const std::vector& msh_nodes (_msh->getNodeVector()); + const std::vector& msh_nodes(_msh->getNodeVector()); // store node id std::vector node_ids; - const size_t n_holes (holes.size()); + const size_t n_holes(holes.size()); for (size_t j(0); j < msh_nodes.size(); j++) { - GEOLIB::Point pnt (msh_nodes[j]->getData()); + GEOLIB::Point pnt(msh_nodes[j]->getData()); if (bounding_polygon.isPntInPolygon(pnt)) { - bool is_not_in_hole (true); + bool is_not_in_hole(true); for (size_t k(0); k < n_holes && is_not_in_hole; k++) if ((holes[k])->isPntInPolygon(pnt)) is_not_in_hole = false; if (is_not_in_hole) - node_ids.push_back (j); + node_ids.push_back(j); } } - std::sort (node_ids.begin(), node_ids.end()); + std::sort(node_ids.begin(), node_ids.end()); - size_t n_nodes (node_ids.size()); - std::vector areas (n_nodes, 0.0); + size_t n_nodes(node_ids.size()); + std::vector areas(n_nodes, 0.0); // in order to compute the area we need the mesh elements - const std::vector& msh_elem (_msh->getElementVector()); + const std::vector& msh_elem(_msh->getElementVector()); for (size_t k(0); k < n_nodes; k++) { // get all associated mesh elements - std::vector const & mesh_elem_ids( - msh_nodes[node_ids[k]]->getConnectedElementIDs()); - size_t n_mesh_elem_ids (mesh_elem_ids.size()); + std::vector const& mesh_elem_ids(msh_nodes[node_ids[k]]->getConnectedElementIDs()); + size_t n_mesh_elem_ids(mesh_elem_ids.size()); // get areas for mesh elements - double area (0.0); + double area(0.0); for (size_t j(0); j < n_mesh_elem_ids; j++) { // check if all mesh nodes of the element are inside the polygon std::vector mesh_element_node_indices; - msh_elem[mesh_elem_ids[j]]->getNodeIndices (mesh_element_node_indices); - size_t n_of_nodes_of_element (mesh_element_node_indices.size()); - bool found (true); + msh_elem[mesh_elem_ids[j]]->getNodeIndices(mesh_element_node_indices); + size_t n_of_nodes_of_element(mesh_element_node_indices.size()); + bool found(true); for (size_t i(0); i < n_of_nodes_of_element && found; i++) { - std::vector::iterator it(std::find ( - node_ids.begin(), - node_ids.end(), - mesh_element_node_indices[ - i])); + std::vector::iterator it( + std::find(node_ids.begin(), node_ids.end(), mesh_element_node_indices[i])); if (it == node_ids.end()) found = false; } @@ -430,44 +423,41 @@ void ExtractMeshNodes::writeMesh2DNodeIDAndArea (std::ostream& os, os << node_ids[k] << " " << areas[k] << "\n"; n_nodes = 0; - gli_out.precision (14); - for (std::vector::const_iterator it (node_ids.begin()); it != node_ids.end(); it++) + gli_out.precision(14); + for (std::vector::const_iterator it(node_ids.begin()); it != node_ids.end(); it++) { - double const* const pnt (msh_nodes[*it]->getData()); - gli_out << n_nodes + _gli_pnt_offset << " " << std::scientific - << pnt[0] << " " << pnt[1] << " " << pnt[2] << " $NAME " << *it << - "\n"; + double const* const pnt(msh_nodes[*it]->getData()); + gli_out << n_nodes + _gli_pnt_offset << " " << std::scientific << pnt[0] << " " << pnt[1] << " " << pnt[2] + << " $NAME " << *it << "\n"; n_nodes++; } _gli_pnt_offset += n_nodes; } -void ExtractMeshNodes::writeNearestMeshNodeToPoint (std::ostream& os, - std::ostream& gli_out, - GEOLIB::Point const & pnt) +void ExtractMeshNodes::writeNearestMeshNodeToPoint(std::ostream& os, std::ostream& gli_out, GEOLIB::Point const& pnt) { - size_t node_id (_msh->GetNODOnPNT (&pnt)); + size_t node_id(_msh->GetNODOnPNT(&pnt)); os << node_id << "\n"; - double const* const coords ((_msh->getNodeVector()[node_id])->getData()); + double const* const coords((_msh->getNodeVector()[node_id])->getData()); - gli_out.precision (14); - gli_out << _gli_pnt_offset << " " << std::scientific - << coords[0] << " " << coords[1] << " " << coords[2] << "\n"; + gli_out.precision(14); + gli_out << _gli_pnt_offset << " " << std::scientific << coords[0] << " " << coords[1] << " " << coords[2] << "\n"; _gli_pnt_offset++; } -void ExtractMeshNodes::getMeshNodeIDsWithinPolygon(GEOLIB::Polygon const& polygon, - std::vector & node_ids) const +void ExtractMeshNodes::getMeshNodeIDsWithinPolygon(GEOLIB::Polygon const& polygon, std::vector& node_ids) const { // get all nodes of the mesh const std::vector& mesh_nodes(_msh->getNodeVector()); // check if nodes (projected to x-y-plane) are inside the polygon const size_t number_of_mesh_nodes(mesh_nodes.size()); - for (size_t j(0); j < number_of_mesh_nodes; j++) { - if (polygon.isPntInPolygon(mesh_nodes[j]->getData())) { + for (size_t j(0); j < number_of_mesh_nodes; j++) + { + if (polygon.isPntInPolygon(mesh_nodes[j]->getData())) + { node_ids.push_back(j); } } diff --git a/MSHGEOTOOLS/ExtractMeshNodes.h b/MSHGEOTOOLS/ExtractMeshNodes.h index d33c99e52..c5c8d9b3e 100644 --- a/MSHGEOTOOLS/ExtractMeshNodes.h +++ b/MSHGEOTOOLS/ExtractMeshNodes.h @@ -48,9 +48,7 @@ class ExtractMeshNodes * @param gli_out output stream for points * @param polygon the polygon that have to be located in the x-y-plane (z=0) */ - void writeMeshNodeIDs (std::ostream& os, - std::ostream& gli_out, - const GEOLIB::Polygon& polygon); + void writeMeshNodeIDs(std::ostream& os, std::ostream& gli_out, const GEOLIB::Polygon& polygon); /** * This method first projects all mesh nodes into the x-y-plane (z=0). * Then it checks if mesh nodes are within the given polygon @@ -64,13 +62,9 @@ class ExtractMeshNodes * @param gli_out output stream for points * @param polygon the polygon that have to be located in the x-y-plane (z=0) */ - void writeTopSurfaceMeshNodeIDs (std::ostream& os, - std::ostream& gli_out, - const GEOLIB::Polygon& polygon); + void writeTopSurfaceMeshNodeIDs(std::ostream& os, std::ostream& gli_out, const GEOLIB::Polygon& polygon); - void writeMesh2DNodeIDAndArea (std::ostream& os, - std::ostream& gli_out, - const GEOLIB::Polygon& polygon); + void writeMesh2DNodeIDAndArea(std::ostream& os, std::ostream& gli_out, const GEOLIB::Polygon& polygon); /** * Method computes the ids of mesh nodes that are inside the bounding polygon @@ -80,14 +74,12 @@ class ExtractMeshNodes * @param bounding_polygon the bounding polygon (all mesh nodes inside this polygon are candidates) * @param holes mesh nodes insides these polygons are excluded from the output */ - void writeMesh2DNodeIDAndArea (std::ostream& os, - std::ostream& gli_out, - const GEOLIB::Polygon& bounding_polygon, - std::vector const& holes); + void writeMesh2DNodeIDAndArea(std::ostream& os, + std::ostream& gli_out, + const GEOLIB::Polygon& bounding_polygon, + std::vector const& holes); - void writeNearestMeshNodeToPoint (std::ostream& os, - std::ostream& gli_out, - GEOLIB::Point const & pnt); + void writeNearestMeshNodeToPoint(std::ostream& os, std::ostream& gli_out, GEOLIB::Point const& pnt); /** * computes the mesh nodes along a polyline belonging to the bottom surface @@ -95,16 +87,15 @@ class ExtractMeshNodes * @param bottom_points the bottom mesh nodes as points */ void getBottomMeshNodesAlongPolylineAsPoints(const GEOLIB::Polyline& ply, - std::vector& bottom_points) const; + std::vector& bottom_points) const; /** * computes the mesh nodes along a polyline belonging to the top surface * @param polyline computation along the polyline ply * @param top_points the top mesh nodes as points */ - void getTopMeshNodesAlongPolylineAsPoints( - const GEOLIB::Polyline& polyline, - std::vector& top_points) const; + void getTopMeshNodesAlongPolylineAsPoints(const GEOLIB::Polyline& polyline, + std::vector& top_points) const; /** * Method computes the polygon to a given polyline that is consisting of the projection @@ -116,9 +107,8 @@ class ExtractMeshNodes * @param polygon pointer to the resulting polygon * warning: the pointer to an already existing polygon will be destroyed */ - void getPolygonFromPolyline(const GEOLIB::Polyline& polyline, - GEOLIB::GEOObjects* geo_obj, std::string const& name, - GEOLIB::Polygon* &polygon) const; + void getPolygonFromPolyline(const GEOLIB::Polyline& polyline, GEOLIB::GEOObjects* geo_obj, std::string const& name, + GEOLIB::Polygon*& polygon) const; /** * get a polyline that is projected to the appropriate "layer" into the mesh @@ -129,9 +119,8 @@ class ExtractMeshNodes * the z-coordinate is set from the layer * @param layer "layer" of the mesh */ - void getProjectedPolylineFromPolyline(GEOLIB::Polyline const& ply_in, - GEOLIB::GEOObjects* geo_obj, std::string const& name, - GEOLIB::Polyline* &ply_out, size_t layer = 0) const; + void getProjectedPolylineFromPolyline(GEOLIB::Polyline const& ply_in, GEOLIB::GEOObjects* geo_obj, + std::string const& name, GEOLIB::Polyline*& ply_out, size_t layer = 0) const; /** * Method searchs the mesh nodes within a given volume described by a @@ -142,8 +131,8 @@ class ExtractMeshNodes * @param node_ids [output] the ids of the mesh nodes which \f$x\f$ and \f$y\f$ * coordinates are inside the boundary polygon */ - void getMeshNodeIDsWithinPolygon(GEOLIB::Polygon const& polygon, - std::vector & node_ids) const; + void getMeshNodeIDsWithinPolygon(GEOLIB::Polygon const& polygon, std::vector& node_ids) const; + private: /** * This method searchs all mesh nodes with the same x and y coordinates @@ -153,9 +142,8 @@ class ExtractMeshNodes * @param polyline the "defining" polyline * @param nodes_as_points vector of GEOLIB::Point objects */ - void getOrthogonalProjectedMeshNodesAlongPolyline ( - GEOLIB::Polyline const& polyline, - std::vector& nodes_as_points) const; + void getOrthogonalProjectedMeshNodesAlongPolyline(GEOLIB::Polyline const& polyline, + std::vector& nodes_as_points) const; const CFEMesh* _msh; /** * offset for gli point index diff --git a/MathLib/AnalyticalGeometry.cpp b/MathLib/AnalyticalGeometry.cpp index c3a851214..a4c8679db 100644 --- a/MathLib/AnalyticalGeometry.cpp +++ b/MathLib/AnalyticalGeometry.cpp @@ -34,15 +34,14 @@ namespace MathLib { -Orientation getOrientation (const double& p0_x, const double& p0_y, - const double& p1_x, const double& p1_y, - const double& p2_x, const double& p2_y) +Orientation getOrientation(const double& p0_x, const double& p0_y, const double& p1_x, const double& p1_y, + const double& p2_x, const double& p2_y) { - double h1 ((p1_x - p0_x) * (p2_y - p0_y)); - double h2 ((p2_x - p0_x) * (p1_y - p0_y)); + double h1((p1_x - p0_x) * (p2_y - p0_y)); + double h2((p2_x - p0_x) * (p1_y - p0_y)); - double tol (sqrt(std::numeric_limits::min())); - if (fabs (h1 - h2) <= tol * max (fabs(h1), fabs(h2))) + double tol(sqrt(std::numeric_limits::min())); + if (fabs(h1 - h2) <= tol * max(fabs(h1), fabs(h2))) return COLLINEAR; if (h1 - h2 > 0.0) return CCW; @@ -50,16 +49,13 @@ Orientation getOrientation (const double& p0_x, const double& p0_y, return CW; } -Orientation getOrientation (const GEOLIB::Point* p0, - const GEOLIB::Point* p1, - const GEOLIB::Point* p2) +Orientation getOrientation(const GEOLIB::Point* p0, const GEOLIB::Point* p1, const GEOLIB::Point* p2) { - return getOrientation ((*p0)[0], (*p0)[1], (*p1)[0], (*p1)[1], (*p2)[0], (*p2)[1]); + return getOrientation((*p0)[0], (*p0)[1], (*p1)[0], (*p1)[1], (*p2)[0], (*p2)[1]); } -bool lineSegmentIntersect (const GEOLIB::Point& a, const GEOLIB::Point& b, - const GEOLIB::Point& c, const GEOLIB::Point& d, - GEOLIB::Point& s) +bool lineSegmentIntersect(const GEOLIB::Point& a, const GEOLIB::Point& b, const GEOLIB::Point& c, + const GEOLIB::Point& d, GEOLIB::Point& s) { //*** in order to make the intersection test more stable // compute bounding box for the points @@ -69,70 +65,73 @@ bool lineSegmentIntersect (const GEOLIB::Point& a, const GEOLIB::Point& b, aabb.update(c); aabb.update(d); // transforming coordinates to interval [0,1]x[0,1]x[0,1] - double delta(aabb.getMaxPoint()[0]-aabb.getMinPoint()[0]); - const double tmp (aabb.getMaxPoint()[1]-aabb.getMinPoint()[1]); - if (delta < tmp) { + double delta(aabb.getMaxPoint()[0] - aabb.getMinPoint()[0]); + const double tmp(aabb.getMaxPoint()[1] - aabb.getMinPoint()[1]); + if (delta < tmp) + { delta = tmp; } - GEOLIB::Point a_cpy((a[0] - aabb.getMinPoint()[0])/delta, (a[1] - aabb.getMinPoint()[1])/delta, 0.0); - GEOLIB::Point b_cpy((b[0] - aabb.getMinPoint()[0])/delta, (b[1] - aabb.getMinPoint()[1])/delta, 0.0); - GEOLIB::Point c_cpy((c[0] - aabb.getMinPoint()[0])/delta, (c[1] - aabb.getMinPoint()[1])/delta, 0.0); - GEOLIB::Point d_cpy((d[0] - aabb.getMinPoint()[0])/delta, (d[1] - aabb.getMinPoint()[1])/delta, 0.0); + GEOLIB::Point a_cpy((a[0] - aabb.getMinPoint()[0]) / delta, (a[1] - aabb.getMinPoint()[1]) / delta, 0.0); + GEOLIB::Point b_cpy((b[0] - aabb.getMinPoint()[0]) / delta, (b[1] - aabb.getMinPoint()[1]) / delta, 0.0); + GEOLIB::Point c_cpy((c[0] - aabb.getMinPoint()[0]) / delta, (c[1] - aabb.getMinPoint()[1]) / delta, 0.0); + GEOLIB::Point d_cpy((d[0] - aabb.getMinPoint()[0]) / delta, (d[1] - aabb.getMinPoint()[1]) / delta, 0.0); - Matrix mat(2,2); - mat(0,0) = b_cpy[0] - a_cpy[0]; - mat(1,0) = b_cpy[1] - a_cpy[1]; - mat(0,1) = c_cpy[0] - d_cpy[0]; - mat(1,1) = c_cpy[1] - d_cpy[1]; + Matrix mat(2, 2); + mat(0, 0) = b_cpy[0] - a_cpy[0]; + mat(1, 0) = b_cpy[1] - a_cpy[1]; + mat(0, 1) = c_cpy[0] - d_cpy[0]; + mat(1, 1) = c_cpy[1] - d_cpy[1]; // check if vectors are parallel - double eps (sqrt(std::numeric_limits::min())); - if (fabs(mat(1,1)) < eps) + double eps(sqrt(std::numeric_limits::min())); + if (fabs(mat(1, 1)) < eps) { // vector (D-C) is parallel to x-axis - if (fabs(mat(0,1)) < eps) + if (fabs(mat(0, 1)) < eps) // vector (B-A) is parallel to x-axis return false; - } else { + } + else + { // vector (D-C) is not parallel to x-axis - if (fabs(mat(0,1)) >= eps) + if (fabs(mat(0, 1)) >= eps) // vector (B-A) is not parallel to x-axis // \f$(B-A)\f$ and \f$(D-C)\f$ are parallel iff there exists // a constant \f$c\f$ such that \f$(B-A) = c (D-C)\f$ - if (fabs (mat(0,0) / mat(0,1) - mat(1,0) / mat(1,1)) < eps * fabs (mat(0,0) / mat(0,1))) + if (fabs(mat(0, 0) / mat(0, 1) - mat(1, 0) / mat(1, 1)) < eps * fabs(mat(0, 0) / mat(0, 1))) return false; } - double* rhs (new double[2]); + double* rhs(new double[2]); rhs[0] = c_cpy[0] - a_cpy[0]; rhs[1] = c_cpy[1] - a_cpy[1]; - GaussAlgorithm lu_solver (mat); - lu_solver.execute (rhs); - if (0 <= rhs[0] && rhs[0] <= 1.0 && 0 <= rhs[1] && rhs[1] <= 1.0) { + GaussAlgorithm lu_solver(mat); + lu_solver.execute(rhs); + if (0 <= rhs[0] && rhs[0] <= 1.0 && 0 <= rhs[1] && rhs[1] <= 1.0) + { s[0] = a[0] + rhs[0] * (b[0] - a[0]); s[1] = a[1] + rhs[0] * (b[1] - a[1]); s[2] = a[2] + rhs[0] * (b[2] - a[2]); // check z component - double z0 (a[2] - d[2]), z1(rhs[0] * (b[2] - a[2]) + rhs[1] * (d[2] - c[2])); - delete [] rhs; - if (std::fabs (z0 - z1) < eps) + double z0(a[2] - d[2]), z1(rhs[0] * (b[2] - a[2]) + rhs[1] * (d[2] - c[2])); + delete[] rhs; + if (std::fabs(z0 - z1) < eps) return true; else return false; - } else { - delete [] rhs; + } + else + { + delete[] rhs; } return false; } -bool lineSegmentsIntersect (const GEOLIB::Polyline* ply, - size_t &idx0, - size_t &idx1, - GEOLIB::Point& intersection_pnt) +bool lineSegmentsIntersect(const GEOLIB::Polyline* ply, size_t& idx0, size_t& idx1, GEOLIB::Point& intersection_pnt) { - size_t n_segs (ply->getNumberOfPoints() - 1); + size_t n_segs(ply->getNumberOfPoints() - 1); /** * computing the intersections of all possible pairs of line segments of the given polyline * as follows: @@ -141,9 +140,12 @@ bool lineSegmentsIntersect (const GEOLIB::Polyline* ply, * \f$j+1\f$-st point of the polyline, \f$j>k+1\f$ */ for (size_t k(0); k < n_segs - 2; k++) - for (size_t j(k + 2); j < n_segs; j++) { - if (k != 0 || j < n_segs - 1) { - if (lineSegmentIntersect(*(*ply)[k], *(*ply)[k + 1],*(*ply)[j], *(*ply)[j + 1], intersection_pnt)) { + for (size_t j(k + 2); j < n_segs; j++) + { + if (k != 0 || j < n_segs - 1) + { + if (lineSegmentIntersect(*(*ply)[k], *(*ply)[k + 1], *(*ply)[j], *(*ply)[j + 1], intersection_pnt)) + { idx0 = k; idx1 = j; return true; @@ -153,52 +155,45 @@ bool lineSegmentsIntersect (const GEOLIB::Polyline* ply, return false; } -double calcTriangleArea(GEOLIB::Point const& a, - GEOLIB::Point const& b, GEOLIB::Point const& c) +double calcTriangleArea(GEOLIB::Point const& a, GEOLIB::Point const& b, GEOLIB::Point const& c) { - double const u[3] = {c[0]-a[0], c[1]-a[1], c[2]-a[2]}; - double const v[3] = {b[0]-a[0], b[1]-a[1], b[2]-a[2]}; + double const u[3] = {c[0] - a[0], c[1] - a[1], c[2] - a[2]}; + double const v[3] = {b[0] - a[0], b[1] - a[1], b[2] - a[2]}; double w[3]; MathLib::crossProd(u, v, w); - return 0.5 * (sqrt(MathLib::scpr(w,w,3))); + return 0.5 * (sqrt(MathLib::scpr(w, w, 3))); } -bool isPointInTriangle (const double q[3], const double a[3], - const double b[3], const double c[3], double eps) +bool isPointInTriangle(const double q[3], const double a[3], const double b[3], const double c[3], double eps) { - if (sqrt(MathLib::sqrDist(q, a)) < eps || - sqrt(MathLib::sqrDist(q, b)) < eps || - sqrt(MathLib::sqrDist(q, c)) < eps) { + if (sqrt(MathLib::sqrDist(q, a)) < eps || sqrt(MathLib::sqrDist(q, b)) < eps || sqrt(MathLib::sqrDist(q, c)) < eps) + { return true; } - MathLib::Vector const v(a,b); - MathLib::Vector const w(a,c); - - MathLib::Matrix mat (2,2); - mat(0,0) = v[0]*v[0] + v[1]*v[1] + v[2]*v[2]; - mat(0,1) = v[0]*w[0] + v[1]*w[1] + v[2]*w[2]; - mat(1,0) = mat(0,1); - mat(1,1) = w[0]*w[0] + w[1]*w[1] + w[2]*w[2]; - double y[2] = { - v[0] * (q[0] - a[0]) + v[1] * (q[1] - a[1]) + v[2] * (q[2] - a[2]), - w[0] * (q[0] - a[0]) + w[1] * (q[1] - a[1]) + w[2] * (q[2] - a[2]) - }; - - MathLib::GaussAlgorithm gauss (mat); - gauss.execute (y); - - const double lower (-eps); - const double upper (1 + eps); - - if (lower <= y[0] && y[0] <= upper && lower <= y[1] && y[1] <= upper && y[0] + y[1] <= - upper) { - double const q_projected[3] = { - a[0] + y[0] * v[0] + y[1] * w[0], - a[1] + y[0] * v[1] + y[1] * w[1], - a[2] + y[0] * v[2] + y[1] * w[2] - }; - if (sqrt(MathLib::sqrDist(q, q_projected)) < eps) { + MathLib::Vector const v(a, b); + MathLib::Vector const w(a, c); + + MathLib::Matrix mat(2, 2); + mat(0, 0) = v[0] * v[0] + v[1] * v[1] + v[2] * v[2]; + mat(0, 1) = v[0] * w[0] + v[1] * w[1] + v[2] * w[2]; + mat(1, 0) = mat(0, 1); + mat(1, 1) = w[0] * w[0] + w[1] * w[1] + w[2] * w[2]; + double y[2] = {v[0] * (q[0] - a[0]) + v[1] * (q[1] - a[1]) + v[2] * (q[2] - a[2]), + w[0] * (q[0] - a[0]) + w[1] * (q[1] - a[1]) + w[2] * (q[2] - a[2])}; + + MathLib::GaussAlgorithm gauss(mat); + gauss.execute(y); + + const double lower(-eps); + const double upper(1 + eps); + + if (lower <= y[0] && y[0] <= upper && lower <= y[1] && y[1] <= upper && y[0] + y[1] <= upper) + { + double const q_projected[3] + = {a[0] + y[0] * v[0] + y[1] * w[0], a[1] + y[0] * v[1] + y[1] * w[1], a[2] + y[0] * v[2] + y[1] * w[2]}; + if (sqrt(MathLib::sqrDist(q, q_projected)) < eps) + { return true; } } @@ -206,29 +201,26 @@ bool isPointInTriangle (const double q[3], const double a[3], return false; } -bool isPointInTriangle (const GEOLIB::Point* p, const GEOLIB::Point* a, - const GEOLIB::Point* b, const GEOLIB::Point* c, - double eps) +bool isPointInTriangle(const GEOLIB::Point* p, const GEOLIB::Point* a, const GEOLIB::Point* b, const GEOLIB::Point* c, + double eps) { - return isPointInTriangle (p->getData(), - a->getData(), b->getData(), c->getData(), eps); + return isPointInTriangle(p->getData(), a->getData(), b->getData(), c->getData(), eps); } // NewellPlane from book Real-Time Collision detection p. 494 -void getNewellPlane(const std::vector& pnts, Vector &plane_normal, - double& d) +void getNewellPlane(const std::vector& pnts, Vector& plane_normal, double& d) { d = 0; Vector centroid; - size_t n_pnts (pnts.size()); + size_t n_pnts(pnts.size()); for (size_t i(n_pnts - 1), j(0); j < n_pnts; i = j, j++) { - plane_normal[0] += ((*(pnts[i]))[1] - (*(pnts[j]))[1]) - * ((*(pnts[i]))[2] + (*(pnts[j]))[2]); // projection on yz - plane_normal[1] += ((*(pnts[i]))[2] - (*(pnts[j]))[2]) - * ((*(pnts[i]))[0] + (*(pnts[j]))[0]); // projection on xz - plane_normal[2] += ((*(pnts[i]))[0] - (*(pnts[j]))[0]) - * ((*(pnts[i]))[1] + (*(pnts[j]))[1]); // projection on xy + plane_normal[0] + += ((*(pnts[i]))[1] - (*(pnts[j]))[1]) * ((*(pnts[i]))[2] + (*(pnts[j]))[2]); // projection on yz + plane_normal[1] + += ((*(pnts[i]))[2] - (*(pnts[j]))[2]) * ((*(pnts[i]))[0] + (*(pnts[j]))[0]); // projection on xz + plane_normal[2] + += ((*(pnts[i]))[0] - (*(pnts[j]))[0]) * ((*(pnts[i]))[1] + (*(pnts[j]))[1]); // projection on xy centroid += *(pnts[j]); } @@ -237,17 +229,15 @@ void getNewellPlane(const std::vector& pnts, Vector &plane_norma d = centroid.Dot(plane_normal) / n_pnts; } -void rotatePointsToXY(Vector &plane_normal, - std::vector &pnts) +void rotatePointsToXY(Vector& plane_normal, std::vector& pnts) { - double small_value (sqrt (std::numeric_limits::min())); + double small_value(sqrt(std::numeric_limits::min())); if (fabs(plane_normal[0]) < small_value && fabs(plane_normal[1]) < small_value) return; // *** some frequently used terms *** // sqrt (v_1^2 + v_2^2) - double h0(sqrt(plane_normal[0] * plane_normal[0] + plane_normal[1] - * plane_normal[1])); + double h0(sqrt(plane_normal[0] * plane_normal[0] + plane_normal[1] * plane_normal[1])); // 1 / sqrt (v_1^2 + v_2^2) double h1(1 / h0); // 1 / sqrt (h0 + v_3^2) @@ -265,26 +255,26 @@ void rotatePointsToXY(Vector &plane_normal, rot_mat(2, 1) = plane_normal[1] * h2; rot_mat(2, 2) = plane_normal[2] * h2; - double* tmp (NULL); + double* tmp(NULL); size_t n_pnts(pnts.size()); for (size_t k(0); k < n_pnts; k++) { tmp = rot_mat * pnts[k]->getData(); for (size_t j(0); j < 3; j++) (*(pnts[k]))[j] = tmp[j]; - delete [] tmp; + delete[] tmp; } tmp = rot_mat * plane_normal.getData(); for (size_t j(0); j < 3; j++) plane_normal[j] = tmp[j]; - delete [] tmp; + delete[] tmp; } -void rotatePointsToXZ(Vector &n, std::vector &pnts) +void rotatePointsToXZ(Vector& n, std::vector& pnts) { - double small_value (sqrt (std::numeric_limits::min())); + double small_value(sqrt(std::numeric_limits::min())); if (fabs(n[0]) < small_value && fabs(n[1]) < small_value) return; @@ -299,29 +289,30 @@ void rotatePointsToXZ(Vector &n, std::vector &pnts) Matrix rot_mat(3, 3); // calc rotation matrix rot_mat(0, 0) = n[1] * h1; - rot_mat(0, 1) = - n[0] * h1; + rot_mat(0, 1) = -n[0] * h1; rot_mat(0, 2) = 0.0; rot_mat(1, 0) = n[0] * h2; rot_mat(1, 1) = n[1] * h2; rot_mat(1, 2) = n[2] * h2; rot_mat(2, 0) = n[0] * n[2] * h1 * h2; rot_mat(2, 1) = n[1] * n[2] * h1 * h2; - rot_mat(2, 2) = - sqrt(h0) * h2; + rot_mat(2, 2) = -sqrt(h0) * h2; - double* tmp (NULL); + double* tmp(NULL); size_t n_pnts(pnts.size()); - for (size_t k(0); k < n_pnts; k++) { + for (size_t k(0); k < n_pnts; k++) + { tmp = rot_mat * pnts[k]->getData(); for (size_t j(0); j < 3; j++) (*(pnts[k]))[j] = tmp[j]; - delete [] tmp; + delete[] tmp; } tmp = rot_mat * n.getData(); for (size_t j(0); j < 3; j++) n[j] = tmp[j]; - delete [] tmp; + delete[] tmp; } } // end namespace MathLib diff --git a/MathLib/AnalyticalGeometry.h b/MathLib/AnalyticalGeometry.h index c5932cfd3..9a1785eb3 100644 --- a/MathLib/AnalyticalGeometry.h +++ b/MathLib/AnalyticalGeometry.h @@ -25,7 +25,8 @@ class Polyline; namespace MathLib { -enum Orientation { +enum Orientation +{ CW = 1, CCW = 2, COLLINEAR = 3 @@ -36,16 +37,13 @@ enum Orientation { * p0_x, p0_y, p1_x, p1_y, p2_x and p2_y * \returns CW (clockwise), CCW (counterclockwise) or COLLINEAR (points are on a line) */ -Orientation getOrientation (const double& p0_x, const double& p0_y, - const double& p1_x, const double& p1_y, - const double& p2_x, const double& p2_y); +Orientation getOrientation(const double& p0_x, const double& p0_y, const double& p1_x, const double& p1_y, + const double& p2_x, const double& p2_y); /** * wrapper for getOrientation () */ -Orientation getOrientation (const GEOLIB::Point* p0, - const GEOLIB::Point* p1, - const GEOLIB::Point* p2); +Orientation getOrientation(const GEOLIB::Point* p0, const GEOLIB::Point* p1, const GEOLIB::Point* p2); /** * compute a supporting plane (represented by plane_normal and the value d) for the polygon @@ -55,16 +53,14 @@ Orientation getOrientation (const GEOLIB::Point* p0, * @param plane_normal the normal of the plane the polygon is located in * @param d parameter from the plane equation */ -void getNewellPlane (const std::vector& pnts, - MathLib::Vector &plane_normal, - double& d); +void getNewellPlane(const std::vector& pnts, MathLib::Vector& plane_normal, double& d); /** * * @param plane_normal * @param pnts */ -void rotatePointsToXY(MathLib::Vector &plane_normal, std::vector &pnts); +void rotatePointsToXY(MathLib::Vector& plane_normal, std::vector& pnts); /** * The vector plane_normal should be the surface normal of the plane surface described @@ -73,10 +69,9 @@ void rotatePointsToXY(MathLib::Vector &plane_normal, std::vector * @param plane_normal * @param pnts */ -void rotatePointsToXZ(MathLib::Vector &plane_normal, std::vector &pnts); +void rotatePointsToXZ(MathLib::Vector& plane_normal, std::vector& pnts); -double calcTriangleArea(GEOLIB::Point const& a, - GEOLIB::Point const& b, GEOLIB::Point const& c); +double calcTriangleArea(GEOLIB::Point const& a, GEOLIB::Point const& b, GEOLIB::Point const& c); /** * Tests if the given point p is within the triangle, defined by its edge nodes a, b and c. @@ -89,9 +84,8 @@ double calcTriangleArea(GEOLIB::Point const& a, * spaned by triangle) * @return true if the test point p is within the 'epsilon'-neighbourhood of the triangle */ -bool isPointInTriangle (const GEOLIB::Point* p, const GEOLIB::Point* a, - const GEOLIB::Point* b, const GEOLIB::Point* c, - double eps = std::numeric_limits::epsilon()); +bool isPointInTriangle(const GEOLIB::Point* p, const GEOLIB::Point* a, const GEOLIB::Point* b, const GEOLIB::Point* c, + double eps = std::numeric_limits::epsilon()); /** * test for intersections of the line segments of the Polyline @@ -101,10 +95,7 @@ bool isPointInTriangle (const GEOLIB::Point* p, const GEOLIB::Point* a, * @param intersection_pnt the intersection point if the line segments intersect * @return true, if the polyline contains intersections */ -bool lineSegmentsIntersect (const GEOLIB::Polyline* ply, - size_t &idx0, - size_t &idx1, - GEOLIB::Point& intersection_pnt); +bool lineSegmentsIntersect(const GEOLIB::Polyline* ply, size_t& idx0, size_t& idx1, GEOLIB::Point& intersection_pnt); /** * A line segment is given by its two end-points. The function checks, @@ -117,8 +108,8 @@ bool lineSegmentsIntersect (const GEOLIB::Polyline* ply, * @param s the intersection point * @return true, if the line segments intersect, else false */ -bool lineSegmentIntersect (const GEOLIB::Point& a, const GEOLIB::Point& b, - const GEOLIB::Point& c, const GEOLIB::Point& d, GEOLIB::Point& s); +bool lineSegmentIntersect(const GEOLIB::Point& a, const GEOLIB::Point& b, const GEOLIB::Point& c, + const GEOLIB::Point& d, GEOLIB::Point& s); } // end namespace MathLib #endif /* MATHTOOLS_H_ */ diff --git a/MathLib/EarClippingTriangulation.cpp b/MathLib/EarClippingTriangulation.cpp index 9c13145f8..970610364 100644 --- a/MathLib/EarClippingTriangulation.cpp +++ b/MathLib/EarClippingTriangulation.cpp @@ -24,43 +24,43 @@ namespace MathLib { EarClippingTriangulation::EarClippingTriangulation(const GEOLIB::Polygon* polygon, - std::list &triangles, bool rot) + std::list& triangles, bool rot) { - if (polygon->getNumberOfPoints()<4) + if (polygon->getNumberOfPoints() < 4) return; - copyPolygonPoints (polygon); + copyPolygonPoints(polygon); if (rot) { - rotate (); - ensureCWOrientation (); + rotate(); + ensureCWOrientation(); } - initVertexList (); - initLists (); - clipEars (); + initVertexList(); + initLists(); + clipEars(); - std::vector const& ref_pnts_vec (polygon->getPointsVec()); - std::list::const_iterator it (_triangles.begin()); + std::vector const& ref_pnts_vec(polygon->getPointsVec()); + std::list::const_iterator it(_triangles.begin()); if (_original_orient == MathLib::CW) while (it != _triangles.end()) { - const size_t i0 (polygon->getPointID ((*it)[0])); - const size_t i1 (polygon->getPointID ((*it)[1])); - const size_t i2 (polygon->getPointID ((*it)[2])); - triangles.push_back (GEOLIB::Triangle (ref_pnts_vec, i0, i1, i2)); + const size_t i0(polygon->getPointID((*it)[0])); + const size_t i1(polygon->getPointID((*it)[1])); + const size_t i2(polygon->getPointID((*it)[2])); + triangles.push_back(GEOLIB::Triangle(ref_pnts_vec, i0, i1, i2)); it++; } else { - size_t n_pnts (_pnts.size() - 1); + size_t n_pnts(_pnts.size() - 1); while (it != _triangles.end()) { - const size_t i0 (polygon->getPointID (n_pnts - (*it)[0])); - const size_t i1 (polygon->getPointID (n_pnts - (*it)[1])); - const size_t i2 (polygon->getPointID (n_pnts - (*it)[2])); - triangles.push_back (GEOLIB::Triangle (ref_pnts_vec, i0, i1, i2)); + const size_t i0(polygon->getPointID(n_pnts - (*it)[0])); + const size_t i1(polygon->getPointID(n_pnts - (*it)[1])); + const size_t i2(polygon->getPointID(n_pnts - (*it)[2])); + triangles.push_back(GEOLIB::Triangle(ref_pnts_vec, i0, i1, i2)); it++; } } @@ -68,20 +68,20 @@ EarClippingTriangulation::EarClippingTriangulation(const GEOLIB::Polygon* polygo EarClippingTriangulation::~EarClippingTriangulation() { - const size_t n_pnts (_pnts.size()); + const size_t n_pnts(_pnts.size()); for (size_t k(0); k < n_pnts; k++) delete _pnts[k]; } -void EarClippingTriangulation::copyPolygonPoints (const GEOLIB::Polygon* polygon) +void EarClippingTriangulation::copyPolygonPoints(const GEOLIB::Polygon* polygon) { // copy points - last point is identical to the first - size_t n_pnts (polygon->getNumberOfPoints() - 1); + size_t n_pnts(polygon->getNumberOfPoints() - 1); for (size_t k(0); k < n_pnts; k++) - _pnts.push_back (new GEOLIB::Point (*(polygon->getPoint(k)))); + _pnts.push_back(new GEOLIB::Point(*(polygon->getPoint(k)))); } -void EarClippingTriangulation::rotate () +void EarClippingTriangulation::rotate() { // calculate supporting plane Vector plane_normal; @@ -89,20 +89,20 @@ void EarClippingTriangulation::rotate () // compute the plane normal getNewellPlane(_pnts, plane_normal, d); - double tol (sqrt(std::numeric_limits::min())); + double tol(sqrt(std::numeric_limits::min())); if (fabs(plane_normal[0]) > tol || fabs(plane_normal[1]) > tol) // rotate copied points into x-y-plane rotatePointsToXY(plane_normal, _pnts); for (size_t k(0); k < _pnts.size(); k++) - (*(_pnts[k]))[2] = 0.0; // should be -= d but there are numerical errors + (*(_pnts[k]))[2] = 0.0; // should be -= d but there are numerical errors } -void EarClippingTriangulation::ensureCWOrientation () +void EarClippingTriangulation::ensureCWOrientation() { - size_t n_pnts (_pnts.size()); + size_t n_pnts(_pnts.size()); // get the left most upper point - size_t min_x_max_y_idx (0); // for orientation check + size_t min_x_max_y_idx(0); // for orientation check for (size_t k(0); k < n_pnts; k++) if ((*(_pnts[k]))[0] <= (*(_pnts[min_x_max_y_idx]))[0]) { @@ -110,73 +110,64 @@ void EarClippingTriangulation::ensureCWOrientation () min_x_max_y_idx = k; else if ((*(_pnts[k]))[1] > (*(_pnts[min_x_max_y_idx]))[1]) min_x_max_y_idx = k; - } // determine orientation if (0 < min_x_max_y_idx && min_x_max_y_idx < n_pnts - 1) - _original_orient = MathLib::getOrientation ( - _pnts[min_x_max_y_idx - 1], _pnts[min_x_max_y_idx], - _pnts[min_x_max_y_idx + 1]); + _original_orient + = MathLib::getOrientation(_pnts[min_x_max_y_idx - 1], _pnts[min_x_max_y_idx], _pnts[min_x_max_y_idx + 1]); else { if (0 == min_x_max_y_idx) - _original_orient = MathLib::getOrientation (_pnts[n_pnts - 1], - _pnts[0], - _pnts[1]); + _original_orient = MathLib::getOrientation(_pnts[n_pnts - 1], _pnts[0], _pnts[1]); else - _original_orient = - MathLib::getOrientation (_pnts[n_pnts - 2], - _pnts[n_pnts - 1], - _pnts[0]); + _original_orient = MathLib::getOrientation(_pnts[n_pnts - 2], _pnts[n_pnts - 1], _pnts[0]); } if (_original_orient == MathLib::CCW) // switch orientation for (size_t k(0); k < n_pnts / 2; k++) - BASELIB::swap (_pnts[k], _pnts[n_pnts - 1 - k]); - + BASELIB::swap(_pnts[k], _pnts[n_pnts - 1 - k]); } bool EarClippingTriangulation::isEar(size_t v0, size_t v1, size_t v2) const { - for (std::list::const_iterator it (_vertex_list.begin ()); - it != _vertex_list.end(); ++it) + for (std::list::const_iterator it(_vertex_list.begin()); it != _vertex_list.end(); ++it) if (*it != v0 && *it != v1 && *it != v2) - if (isPointInTriangle (_pnts[*it], _pnts[v0], _pnts[v1], _pnts[v2])) + if (isPointInTriangle(_pnts[*it], _pnts[v0], _pnts[v1], _pnts[v2])) return false; return true; } -void EarClippingTriangulation::initVertexList () +void EarClippingTriangulation::initVertexList() { - size_t n_pnts (_pnts.size()); + size_t n_pnts(_pnts.size()); for (size_t k(0); k < n_pnts; k++) - _vertex_list.push_back (k); + _vertex_list.push_back(k); } -void EarClippingTriangulation::initLists () +void EarClippingTriangulation::initLists() { // go through points checking ccw, cw or collinear order and identifying ears - std::list::iterator it (_vertex_list.begin()), prev(_vertex_list.end()), next; + std::list::iterator it(_vertex_list.begin()), prev(_vertex_list.end()), next; prev--; next = it; next++; MathLib::Orientation orientation; while (next != _vertex_list.end()) { - orientation = getOrientation (_pnts[*prev], _pnts[*it], _pnts[*next]); + orientation = getOrientation(_pnts[*prev], _pnts[*it], _pnts[*next]); if (orientation == COLLINEAR) { - it = _vertex_list.erase (it); + it = _vertex_list.erase(it); next++; } else { if (orientation == CW) { - _convex_vertex_list.push_back (*it); - if (isEar (*prev, *it, *next)) - _ear_list.push_back (*it); + _convex_vertex_list.push_back(*it); + if (isEar(*prev, *it, *next)) + _ear_list.push_back(*it); } prev = it; it = next; @@ -185,14 +176,14 @@ void EarClippingTriangulation::initLists () } next = _vertex_list.begin(); - orientation = getOrientation (_pnts[*prev], _pnts[*it], _pnts[*next]); + orientation = getOrientation(_pnts[*prev], _pnts[*it], _pnts[*next]); if (orientation == COLLINEAR) - it = _vertex_list.erase (it); + it = _vertex_list.erase(it); if (orientation == CW) { - _convex_vertex_list.push_back (*it); - if (isEar (*prev, *it, *next)) - _ear_list.push_back (*it); + _convex_vertex_list.push_back(*it); + if (isEar(*prev, *it, *next)) + _ear_list.push_back(*it); } } @@ -238,9 +229,7 @@ void EarClippingTriangulation::clipEars() prevprev--; // apply changes to _convex_vertex_list and _ear_list looking "backward" - MathLib::Orientation orientation = getOrientation(_pnts[*prevprev], - _pnts[*prev], - _pnts[*next]); + MathLib::Orientation orientation = getOrientation(_pnts[*prevprev], _pnts[*prev], _pnts[*next]); if (orientation == CW) { BASELIB::uniqueListInsert(_convex_vertex_list, *prev); @@ -271,8 +260,7 @@ void EarClippingTriangulation::clipEars() } // check the orientation of prev, next, nextnext - std::list::iterator nextnext, - help_it(_vertex_list.end()); + std::list::iterator nextnext, help_it(_vertex_list.end()); help_it--; if (next == help_it) nextnext = _vertex_list.begin(); @@ -283,8 +271,7 @@ void EarClippingTriangulation::clipEars() } // apply changes to _convex_vertex_list and _ear_list looking "forward" - orientation = getOrientation(_pnts[*prev], _pnts[*next], - _pnts[*nextnext]); + orientation = getOrientation(_pnts[*prev], _pnts[*next], _pnts[*nextnext]); if (orientation == CW) { BASELIB::uniqueListInsert(_convex_vertex_list, *next); diff --git a/MathLib/EarClippingTriangulation.h b/MathLib/EarClippingTriangulation.h index c166f229a..3db252c6f 100644 --- a/MathLib/EarClippingTriangulation.h +++ b/MathLib/EarClippingTriangulation.h @@ -28,23 +28,22 @@ namespace MathLib class EarClippingTriangulation { public: - EarClippingTriangulation(const GEOLIB::Polygon* ply, - std::list &triangles, - bool rot = true); + EarClippingTriangulation(const GEOLIB::Polygon* ply, std::list& triangles, bool rot = true); virtual ~EarClippingTriangulation(); + private: /** * copies the points of the polygon to the vector _pnts */ - inline void copyPolygonPoints (const GEOLIB::Polygon* polygon); - inline void rotate (); - inline void ensureCWOrientation (); + inline void copyPolygonPoints(const GEOLIB::Polygon* polygon); + inline void rotate(); + inline void ensureCWOrientation(); inline bool isEar(size_t v0, size_t v1, size_t v2) const; - inline void initVertexList (); - inline void initLists (); - inline void clipEars (); + inline void initVertexList(); + inline void initLists(); + inline void clipEars(); /** * a copy of the polygon points diff --git a/MathLib/InterpolationAlgorithms/CubicSpline.cpp b/MathLib/InterpolationAlgorithms/CubicSpline.cpp index d777c39c6..91fca348e 100644 --- a/MathLib/InterpolationAlgorithms/CubicSpline.cpp +++ b/MathLib/InterpolationAlgorithms/CubicSpline.cpp @@ -19,8 +19,8 @@ namespace MathLib { -CubicSpline::CubicSpline(const std::vector& s, const std::vector& val) : - n (s.size()), bb (new double[n]), cc (new double[n]), dd (new double[n]) +CubicSpline::CubicSpline(const std::vector& s, const std::vector& val) + : n(s.size()), bb(new double[n]), cc(new double[n]), dd(new double[n]) { xx = s; yy = val; @@ -29,9 +29,9 @@ CubicSpline::CubicSpline(const std::vector& s, const std::vector CubicSpline::~CubicSpline() { - delete [] bb; - delete [] cc; - delete [] dd; + delete[] bb; + delete[] cc; + delete[] dd; bb = NULL; cc = NULL; dd = NULL; @@ -48,13 +48,13 @@ double CubicSpline::interpolation(double x) const if (x >= xx[i] && x < xx[i + 1]) { // 07/2010 TF -// val = yy[i] + bb[i] * (x - xx[i]) + cc[i] * pow(x - xx[i], 2.0) -// + dd[i] * pow(x - xx[i], 3.0); - double t (x - xx[i]); + // val = yy[i] + bb[i] * (x - xx[i]) + cc[i] * pow(x - xx[i], 2.0) + // + dd[i] * pow(x - xx[i], 3.0); + double t(x - xx[i]); // employing Horner-Schema in order to save multiplications val = yy[i] + t * (bb[i] + t * (cc[i] + t * dd[i])); - //Check the local range + // Check the local range if (yy[i] > y_max) y_max = yy[i]; if (yy[i + 1] > y_max) @@ -184,12 +184,9 @@ void CubicSpline::computeCoefficents() if (n > 3) { cc[0] = cc[2] / (xx[3] - xx[1]) - cc[1] / (xx[2] - xx[0]); - cc[n - 1] = cc[n - 2] / (xx[n - 1] - xx[n - 3]) - cc[n - 3] / (xx[n - - 2] - - xx[n - 4]); + cc[n - 1] = cc[n - 2] / (xx[n - 1] - xx[n - 3]) - cc[n - 3] / (xx[n - 2] - xx[n - 4]); cc[0] = cc[0] * fastpow(dd[0], 2) / (xx[3] - xx[0]); - cc[n - 1] = -cc[n - 1] * fastpow(dd[n - 2], 2) / (xx[n - 1] - xx[n - - 4]); + cc[n - 1] = -cc[n - 1] * fastpow(dd[n - 2], 2) / (xx[n - 1] - xx[n - 4]); } // *** forward elimination @@ -212,12 +209,10 @@ void CubicSpline::computeCoefficents() // // compute polynomial coefficients // - bb[n - 1] = (yy[n - 1] - yy[n - 1 - 1]) / dd[n - 1 - 1] + dd[n - 1 - 1] - * (cc[n - 1 - 1] + 2.0 * cc[n - 1]); + bb[n - 1] = (yy[n - 1] - yy[n - 1 - 1]) / dd[n - 1 - 1] + dd[n - 1 - 1] * (cc[n - 1 - 1] + 2.0 * cc[n - 1]); for (size_t i = 0; i < n - 1; i++) { - bb[i] = (yy[i + 1] - yy[i]) / dd[i] - dd[i] * (cc[i + 1] + 2.0 - * cc[i]); + bb[i] = (yy[i + 1] - yy[i]) / dd[i] - dd[i] * (cc[i + 1] + 2.0 * cc[i]); dd[i] = (cc[i + 1] - cc[i]) / dd[i]; cc[i] = 3.0 * cc[i]; } diff --git a/MathLib/InterpolationAlgorithms/CubicSpline.h b/MathLib/InterpolationAlgorithms/CubicSpline.h index a47336ef7..fa7d99fc1 100644 --- a/MathLib/InterpolationAlgorithms/CubicSpline.h +++ b/MathLib/InterpolationAlgorithms/CubicSpline.h @@ -21,7 +21,7 @@ namespace MathLib class CubicSpline { public: - CubicSpline(const std::vector&s, const std::vector&val); + CubicSpline(const std::vector& s, const std::vector& val); ~CubicSpline(); double interpolation(double x) const; diff --git a/MathLib/InterpolationAlgorithms/InverseDistanceInterpolation.h b/MathLib/InterpolationAlgorithms/InverseDistanceInterpolation.h index 2e921a2f8..7d7645591 100644 --- a/MathLib/InterpolationAlgorithms/InverseDistanceInterpolation.h +++ b/MathLib/InterpolationAlgorithms/InverseDistanceInterpolation.h @@ -20,18 +20,16 @@ namespace MathLib { - /** * Inverse distance interpolation, calculating distances from all domain points to * all supporting points. * The template classes T1 and T2 are expecting GEOLIB::Point Types. */ -template +template class InverseDistanceInterpolation { public: - InverseDistanceInterpolation(const std::vector domain_points, - const std::vector supporting_points); + InverseDistanceInterpolation(const std::vector domain_points, const std::vector supporting_points); virtual ~InverseDistanceInterpolation(); @@ -42,16 +40,11 @@ class InverseDistanceInterpolation double getSumOfDistances(size_t pnt_idx) const; const T1 getDomainPoint(size_t pnt_idx) const { return _domain_points[pnt_idx]; }; - const T2 getSupportingPoint(size_t support_idx) const { return _supporting_points[support_idx]; }; - size_t getNDomainPoints() const { return _domain_points.size(); }; - size_t getNSupportingPoints() const { return _supporting_points.size(); }; - /// Allows the change the interpolation exponent (default value is 2). void setInterpolationExponent(double exponent) { _interpolation_exponent = exponent; }; - private: /// Calculates the distances from all domain points to all supporting points. void calculateDistancesToSupportingPoints(); @@ -61,65 +54,69 @@ class InverseDistanceInterpolation const std::vector _supporting_points; std::vector _sum_of_distances; Matrix _distances; - }; -template InverseDistanceInterpolation::InverseDistanceInterpolation(const std::vector domain_points, - const std::vector supporting_points) - : _interpolation_exponent(2.0), - _domain_points (domain_points), - _supporting_points (supporting_points), - _sum_of_distances ( std::vector(_domain_points.size(), 0.0) ), - _distances ( Matrix(_domain_points.size(), _supporting_points.size()) ) +template +InverseDistanceInterpolation::InverseDistanceInterpolation( + const std::vector domain_points, const std::vector supporting_points) + : _interpolation_exponent(2.0), _domain_points(domain_points), _supporting_points(supporting_points), + _sum_of_distances(std::vector(_domain_points.size(), 0.0)), + _distances(Matrix(_domain_points.size(), _supporting_points.size())) { calculateDistancesToSupportingPoints(); } -template InverseDistanceInterpolation::~InverseDistanceInterpolation() -{} +template +InverseDistanceInterpolation::~InverseDistanceInterpolation() +{ +} -template double InverseDistanceInterpolation::getDistance(size_t pnt_idx, size_t support_idx) const +template +double InverseDistanceInterpolation::getDistance(size_t pnt_idx, size_t support_idx) const { - if ( pnt_idx < _domain_points.size() && support_idx < _supporting_points.size() ) + if (pnt_idx < _domain_points.size() && support_idx < _supporting_points.size()) return _distances(pnt_idx, support_idx); return -1; } -template double InverseDistanceInterpolation::getSumOfDistances(size_t pnt_idx) const +template +double InverseDistanceInterpolation::getSumOfDistances(size_t pnt_idx) const { - if ( pnt_idx < _domain_points.size() ) + if (pnt_idx < _domain_points.size()) return _sum_of_distances[pnt_idx]; return -1; } -template void InverseDistanceInterpolation::calculateDistancesToSupportingPoints() +template +void InverseDistanceInterpolation::calculateDistancesToSupportingPoints() { - const size_t nPoints (_domain_points.size()); - for (size_t n=0; ngetData()); + const double* coords(_domain_points[n]->getData()); - double sum (0.0); + double sum(0.0); std::vector dummy; - //DistanceToWeatherStation foo; + // DistanceToWeatherStation foo; - double x (coords[0]); - double y (coords[1]); + double x(coords[0]); + double y(coords[1]); - const size_t nSupportingPoints (_supporting_points.size()); - for (size_t i=0; i_sum_of_distances[n] = sum; } - } } // end namespace MathLib diff --git a/MathLib/InterpolationAlgorithms/LinearIntervalInterpolation.h b/MathLib/InterpolationAlgorithms/LinearIntervalInterpolation.h index 252c85cb1..15c325dd4 100644 --- a/MathLib/InterpolationAlgorithms/LinearIntervalInterpolation.h +++ b/MathLib/InterpolationAlgorithms/LinearIntervalInterpolation.h @@ -15,8 +15,8 @@ #include -namespace MathLib { - +namespace MathLib +{ /** * @brief Class (template) LinearIntervalInterpolation is a functional object performing * an interval mapping \f$f: [a,b] \to [c,d]\f$. @@ -28,7 +28,8 @@ namespace MathLib { * \f$[c, d]\f$, i.e., \f$f: [a,b] \to [c,d]\f$. */ template -class LinearIntervalInterpolation { +class LinearIntervalInterpolation +{ public: /** * Constructor of class template for a linear map \f$y = m \cdot x + n\f$. @@ -45,7 +46,7 @@ class LinearIntervalInterpolation { * @param x the point the interpolation value is searched for * @return the interpolation value at point \f$x\f$ */ - inline NUMERIC_TYPE operator() (NUMERIC_TYPE x) const; + inline NUMERIC_TYPE operator()(NUMERIC_TYPE x) const; private: /** @@ -59,19 +60,20 @@ class LinearIntervalInterpolation { }; template -LinearIntervalInterpolation::LinearIntervalInterpolation(NUMERIC_TYPE a, NUMERIC_TYPE b, - NUMERIC_TYPE c, NUMERIC_TYPE d) : - _m (d-c), _n(0.0) +LinearIntervalInterpolation::LinearIntervalInterpolation(NUMERIC_TYPE a, NUMERIC_TYPE b, NUMERIC_TYPE c, + NUMERIC_TYPE d) + : _m(d - c), _n(0.0) { - if (b == a) { + if (b == a) + { throw std::runtime_error("LinearIntervalInterpolation::LinearIntervalInterpolation: a == b, empty interval"); } - _m /= (b-a); + _m /= (b - a); _n = c - _m * a; } template -inline NUMERIC_TYPE LinearIntervalInterpolation::operator() (NUMERIC_TYPE x) const +inline NUMERIC_TYPE LinearIntervalInterpolation::operator()(NUMERIC_TYPE x) const { return _m * x + _n; } diff --git a/MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.cpp b/MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.cpp index abbff84fe..ea353b38f 100644 --- a/MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.cpp +++ b/MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.cpp @@ -19,49 +19,47 @@ namespace MathLib { PiecewiseLinearInterpolation::PiecewiseLinearInterpolation(const std::vector& supporting_points, - const std::vector& values_at_supp_pnts) - : _supporting_points (supporting_points), _values_at_supp_pnts (values_at_supp_pnts) -{} + const std::vector& values_at_supp_pnts) + : _supporting_points(supporting_points), _values_at_supp_pnts(values_at_supp_pnts) +{ +} PiecewiseLinearInterpolation::PiecewiseLinearInterpolation(const std::vector& supporting_points, - const std::vector& values_at_supp_pnts, - const std::vector& points_to_interpolate, - std::vector& values_at_interpol_pnts) - : _supporting_points (supporting_points), _values_at_supp_pnts (values_at_supp_pnts) + const std::vector& values_at_supp_pnts, + const std::vector& points_to_interpolate, + std::vector& values_at_interpol_pnts) + : _supporting_points(supporting_points), _values_at_supp_pnts(values_at_supp_pnts) { -// std::cout << "PiecewiseLinearInterpolation::PiecewiseLinearInterpolation support_points, values_at_supp_pnts: " << "\n"; -// for (size_t k(0); kgetValue (points_to_interpolate[k])); + values_at_interpol_pnts.push_back(this->getValue(points_to_interpolate[k])); } PiecewiseLinearInterpolation::~PiecewiseLinearInterpolation() -{} +{ +} -double PiecewiseLinearInterpolation::getValue ( double pnt_to_interpolate ) +double PiecewiseLinearInterpolation::getValue(double pnt_to_interpolate) { // search interval that has the point inside - size_t interval_idx (std::numeric_limits::max()); - for (size_t k(1); - k < _supporting_points.size() && interval_idx == std::numeric_limits::max(); - k++) - if (_supporting_points[k - 1] <= pnt_to_interpolate && pnt_to_interpolate <= - _supporting_points[k]) + size_t interval_idx(std::numeric_limits::max()); + for (size_t k(1); k < _supporting_points.size() && interval_idx == std::numeric_limits::max(); k++) + if (_supporting_points[k - 1] <= pnt_to_interpolate && pnt_to_interpolate <= _supporting_points[k]) interval_idx = k - 1; // compute linear interpolation polynom: y = m * x + n - long double m ( - (_values_at_supp_pnts[interval_idx + - 1] - - _values_at_supp_pnts[interval_idx]) / - (_supporting_points[interval_idx + 1] - _supporting_points[interval_idx])); -// double m ((_values_at_supp_pnts[interval_idx] - _values_at_supp_pnts[interval_idx+1]) / (_supporting_points[interval_idx] - _supporting_points[interval_idx+1])); -// double n (_values_at_supp_pnts[interval_idx+1] - m * _supporting_points[interval_idx+1]); - long double n (_values_at_supp_pnts[interval_idx] - m * _supporting_points[interval_idx]); + long double m((_values_at_supp_pnts[interval_idx + 1] - _values_at_supp_pnts[interval_idx]) + / (_supporting_points[interval_idx + 1] - _supporting_points[interval_idx])); + // double m ((_values_at_supp_pnts[interval_idx] - _values_at_supp_pnts[interval_idx+1]) / + //(_supporting_points[interval_idx] - _supporting_points[interval_idx+1])); + // double n (_values_at_supp_pnts[interval_idx+1] - m * _supporting_points[interval_idx+1]); + long double n(_values_at_supp_pnts[interval_idx] - m * _supporting_points[interval_idx]); return m * pnt_to_interpolate + n; } diff --git a/MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.h b/MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.h index 9cb2a88c1..3b1d5b921 100644 --- a/MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.h +++ b/MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.h @@ -22,14 +22,14 @@ class PiecewiseLinearInterpolation { public: PiecewiseLinearInterpolation(const std::vector& supporting_points, - const std::vector& values_at_supp_pnts); + const std::vector& values_at_supp_pnts); PiecewiseLinearInterpolation(const std::vector& supporting_points, - const std::vector& values_at_supp_pnts, - const std::vector& points_to_interpolate, - std::vector& values_at_interpol_pnts); + const std::vector& values_at_supp_pnts, + const std::vector& points_to_interpolate, + std::vector& values_at_interpol_pnts); virtual ~PiecewiseLinearInterpolation(); - double getValue ( double pnt_to_interpolate ); + double getValue(double pnt_to_interpolate); private: const std::vector& _supporting_points; diff --git a/MathLib/LinAlg/GaussAlgorithm.cpp b/MathLib/LinAlg/GaussAlgorithm.cpp index 09043280d..d63bb3048 100644 --- a/MathLib/LinAlg/GaussAlgorithm.cpp +++ b/MathLib/LinAlg/GaussAlgorithm.cpp @@ -16,10 +16,9 @@ namespace MathLib { -GaussAlgorithm::GaussAlgorithm (Matrix &A) : - _mat (A), _n(_mat.getNRows()), _perm (new size_t [_n]) +GaussAlgorithm::GaussAlgorithm(Matrix& A) : _mat(A), _n(_mat.getNRows()), _perm(new size_t[_n]) { - size_t k, i, j, nr (_mat.getNRows()), nc(_mat.getNCols()); + size_t k, i, j, nr(_mat.getNRows()), nc(_mat.getNCols()); double l; for (k = 0; k < nc; k++) @@ -28,41 +27,41 @@ GaussAlgorithm::GaussAlgorithm (Matrix &A) : double t = fabs(_mat(k, k)); _perm[k] = k; for (i = k + 1; i < nr; i++) - if (std::abs(_mat(i,k)) > t) + if (std::abs(_mat(i, k)) > t) { - t = std::abs(_mat(i,k)); + t = std::abs(_mat(i, k)); _perm[k] = i; } // exchange rows if (_perm[k] != k) for (j = 0; j < nc; j++) - BASELIB::swap (_mat(_perm[k],j), _mat(k,j)); + BASELIB::swap(_mat(_perm[k], j), _mat(k, j)); // eliminate for (i = k + 1; i < nr; i++) { - l = _mat(i,k) / _mat(k,k); + l = _mat(i, k) / _mat(k, k); for (j = k; j < nc; j++) - _mat(i,j) -= _mat(k,j) * l; - _mat(i,k) = l; + _mat(i, j) -= _mat(k, j) * l; + _mat(i, k) = l; } } } GaussAlgorithm::~GaussAlgorithm() { - delete [] _perm; + delete[] _perm; } -void GaussAlgorithm::execute (double* b) const +void GaussAlgorithm::execute(double* b) const { - permuteRHS (b); - forwardSolve (_mat, b); // L z = b, b will be overwritten by z - backwardSolve (_mat, b); // U x = z, b (z) will be overwritten by x + permuteRHS(b); + forwardSolve(_mat, b); // L z = b, b will be overwritten by z + backwardSolve(_mat, b); // U x = z, b (z) will be overwritten by x } -void GaussAlgorithm::permuteRHS (double* b) const +void GaussAlgorithm::permuteRHS(double* b) const { for (size_t i = 0; i < _n; i++) if (_perm[i] != i) diff --git a/MathLib/LinAlg/GaussAlgorithm.h b/MathLib/LinAlg/GaussAlgorithm.h index 92491ae8a..3d797b789 100644 --- a/MathLib/LinAlg/GaussAlgorithm.h +++ b/MathLib/LinAlg/GaussAlgorithm.h @@ -46,55 +46,57 @@ class GaussAlgorithm : public MathLib::DenseDirectLinearSolver * Attention: the given matrix will be destroyed! * @return a object of type GaussAlgorithm */ - GaussAlgorithm(Matrix &A) : - _mat (A), _n(_mat.getNRows()), _perm (new size_t [_n]) + GaussAlgorithm(Matrix& A) : _mat(A), _n(_mat.getNRows()), _perm(new size_t[_n]) { - size_t k, i, j, nr (_mat.getNRows()), nc(_mat.getNCols()); + size_t k, i, j, nr(_mat.getNRows()), nc(_mat.getNCols()); - for (k = 0; k < nc; k++) { + for (k = 0; k < nc; k++) + { // search pivot FLOAT_TYPE t = fabs(_mat(k, k)); _perm[k] = k; - for (i = k + 1; i < nr; i++) { - if (fabs(_mat(i,k)) > t) { - t = _mat(i,k); + for (i = k + 1; i < nr; i++) + { + if (fabs(_mat(i, k)) > t) + { + t = _mat(i, k); _perm[k] = i; } } // exchange rows - if (_perm[k] != k) { - for (j = 0; j < nc; j++) { - BASELIB::swap (_mat(_perm[k],j), _mat(k,j)); + if (_perm[k] != k) + { + for (j = 0; j < nc; j++) + { + BASELIB::swap(_mat(_perm[k], j), _mat(k, j)); } } // eliminate - for (i = k + 1; i < nr; i++) { - const FLOAT_TYPE l (_mat(i,k) / _mat(k,k)); - for (j = k; j < nc; j++) { - _mat(i,j) -= _mat(k,j) * l; + for (i = k + 1; i < nr; i++) + { + const FLOAT_TYPE l(_mat(i, k) / _mat(k, k)); + for (j = k; j < nc; j++) + { + _mat(i, j) -= _mat(k, j) * l; } - _mat(i,k) = l; + _mat(i, k) = l; } } } /** * destructor, deletes the permutation */ - ~GaussAlgorithm() - { - delete [] _perm; - } - + ~GaussAlgorithm() { delete[] _perm; } /** * Method solves the linear system \f$A x = b\f$ (based on the LU factorization) * using forward solve and backward solve * @param b at the beginning the right hand side, at the end the solution */ - void execute (FLOAT_TYPE* b) const + void execute(FLOAT_TYPE* b) const { - permuteRHS (b); + permuteRHS(b); forwardSolve(_mat, b); // L z = b, b will be overwritten by z backwardSolve(_mat, b); // U x = z, b (z) will be overwritten by x } @@ -105,10 +107,12 @@ class GaussAlgorithm : public MathLib::DenseDirectLinearSolver * row permutations of the LU factorization * @param b the entries of the vector b are permuted */ - void permuteRHS (FLOAT_TYPE* b) const + void permuteRHS(FLOAT_TYPE* b) const { - for (size_t i = 0; i < _n; i++) { - if (_perm[i] != i) { + for (size_t i = 0; i < _n; i++) + { + if (_perm[i] != i) + { BASELIB::swap(b[i], b[_perm[i]]); } } diff --git a/MathLib/LinAlg/TriangularSolve.cpp b/MathLib/LinAlg/TriangularSolve.cpp index 572fa63eb..405b73a97 100644 --- a/MathLib/LinAlg/TriangularSolve.cpp +++ b/MathLib/LinAlg/TriangularSolve.cpp @@ -14,42 +14,42 @@ namespace MathLib { -void forwardSolve (const Matrix &L, double* b) +void forwardSolve(const Matrix& L, double* b) { - size_t m (L.getNRows()); + size_t m(L.getNRows()); double t; for (size_t r = 0; r < m; r++) { t = 0.0; for (size_t c = 0; c < r; c++) - t += L(r,c) * b[c]; + t += L(r, c) * b[c]; b[r] = b[r] - t; } } -void backwardSolve (const Matrix &mat, double* b) +void backwardSolve(const Matrix& mat, double* b) { double t; - size_t m (mat.getNRows()), n(mat.getNCols()); + size_t m(mat.getNRows()), n(mat.getNCols()); for (int r = m - 1; r >= 0; r--) { t = 0.0; for (size_t c = r + 1; c < n; c++) - t += mat(r,c) * b[c]; - b[r] = (b[r] - t) / mat(r,r); + t += mat(r, c) * b[c]; + b[r] = (b[r] - t) / mat(r, r); } } -void backwardSolve ( Matrix const& mat, double* x, double* b) +void backwardSolve(Matrix const& mat, double* x, double* b) { - size_t n_cols (mat.getNCols()); + size_t n_cols(mat.getNCols()); for (int r = (n_cols - 1); r >= 0; r--) { double t = 0.0; for (size_t c = r + 1; c < n_cols; c++) - t += mat(r,c) * b[c]; + t += mat(r, c) * b[c]; x[r] = (b[r] - t) / mat(r, r); } } diff --git a/MathLib/LinAlg/TriangularSolve.h b/MathLib/LinAlg/TriangularSolve.h index f4c0ea33a..3bb54aa2d 100644 --- a/MathLib/LinAlg/TriangularSolve.h +++ b/MathLib/LinAlg/TriangularSolve.h @@ -24,14 +24,15 @@ namespace MathLib * @param b at beginning the right hand side vector, at the end the solution vector */ template -void forwardSolve (const Matrix &L, FLOAT_TYPE* b) +void forwardSolve(const Matrix& L, FLOAT_TYPE* b) { - size_t m (L.getNRows()); + size_t m(L.getNRows()); - for (size_t r = 0; r < m; r++) { + for (size_t r = 0; r < m; r++) + { FLOAT_TYPE t(0.0); for (size_t c = 0; c < r; c++) - t += L(r,c) * b[c]; + t += L(r, c) * b[c]; b[r] = b[r] - t; } } @@ -43,15 +44,17 @@ void forwardSolve (const Matrix &L, FLOAT_TYPE* b) * @param z at beginning the right hand side, at the end the solution */ template -void backwardSolve (const Matrix &U, FLOAT_TYPE* z) +void backwardSolve(const Matrix& U, FLOAT_TYPE* z) { - size_t m (U.getNRows()), n(U.getNCols()); - for (int r = m - 1; r >= 0; r--) { + size_t m(U.getNRows()), n(U.getNCols()); + for (int r = m - 1; r >= 0; r--) + { FLOAT_TYPE t(0.0); - for (size_t c = r + 1; c < n; c++) { - t += U(r,c) * z[c]; + for (size_t c = r + 1; c < n; c++) + { + t += U(r, c) * z[c]; } - z[r] = (z[r] - t) / U(r,r); + z[r] = (z[r] - t) / U(r, r); } } @@ -64,15 +67,15 @@ void backwardSolve (const Matrix &U, FLOAT_TYPE* z) * @param b the right hand side */ template -void backwardSolve ( Matrix const& mat, FLOAT_TYPE* x, FLOAT_TYPE* b) +void backwardSolve(Matrix const& mat, FLOAT_TYPE* x, FLOAT_TYPE* b) { - size_t n_cols (mat.getNCols()); + size_t n_cols(mat.getNCols()); for (int r = (n_cols - 1); r >= 0; r--) { FLOAT_TYPE t(0.0); for (size_t c = r + 1; c < n_cols; c++) - t += mat(r,c) * b[c]; + t += mat(r, c) * b[c]; x[r] = (b[r] - t) / mat(r, r); } } diff --git a/MathLib/LinAlg/VectorNorms.h b/MathLib/LinAlg/VectorNorms.h index e78b8a7c4..185c02718 100644 --- a/MathLib/LinAlg/VectorNorms.h +++ b/MathLib/LinAlg/VectorNorms.h @@ -19,9 +19,9 @@ namespace MathLib { -double normEuklid (double const* const vec, size_t n) +double normEuklid(double const* const vec, size_t n) { - return sqrt (scpr (vec, vec, n)); + return sqrt(scpr(vec, vec, n)); } } // end namespace MathLib diff --git a/MathLib/LinkedTriangle.cpp b/MathLib/LinkedTriangle.cpp index 331f7fe18..da20c65f2 100644 --- a/MathLib/LinkedTriangle.cpp +++ b/MathLib/LinkedTriangle.cpp @@ -14,10 +14,9 @@ namespace MathLib { -LinkedTriangle::LinkedTriangle(std::vector const &pnt_vec, - size_t pnt_a, size_t pnt_b, size_t pnt_c, LinkedTriangle* tri_a, - LinkedTriangle* tri_b, LinkedTriangle* tri_c) : - GEOLIB::Triangle(pnt_vec, pnt_a, pnt_b, pnt_c) +LinkedTriangle::LinkedTriangle(std::vector const& pnt_vec, size_t pnt_a, size_t pnt_b, size_t pnt_c, + LinkedTriangle* tri_a, LinkedTriangle* tri_b, LinkedTriangle* tri_c) + : GEOLIB::Triangle(pnt_vec, pnt_a, pnt_b, pnt_c) { if (tri_a) _neighbor_triangles[0] = tri_a; @@ -39,16 +38,16 @@ void LinkedTriangle::setNeighborTriangle(size_t idx, LinkedTriangle* tri) _neighbor_triangles[idx] = tri; } -void LinkedTriangle::setNeighborTriangleByPointIdx (size_t idx, LinkedTriangle* tri) +void LinkedTriangle::setNeighborTriangleByPointIdx(size_t idx, LinkedTriangle* tri) { if (idx == _pnt_ids[0]) - setNeighborTriangle (0, tri); + setNeighborTriangle(0, tri); else { if (idx == _pnt_ids[1]) - setNeighborTriangle (1, tri); + setNeighborTriangle(1, tri); else - setNeighborTriangle (2, tri); + setNeighborTriangle(2, tri); } } @@ -69,7 +68,7 @@ size_t LinkedTriangle::getIdxOfNeighborTriangle(LinkedTriangle* tri) return 3; } -size_t LinkedTriangle::getIdxOfPoint (size_t i) const +size_t LinkedTriangle::getIdxOfPoint(size_t i) const { if (_pnt_ids[0] == i) return 0; @@ -80,12 +79,12 @@ size_t LinkedTriangle::getIdxOfPoint (size_t i) const return 3; } -void LinkedTriangle::writeNeighbor (std::ostream &os, size_t idx) const +void LinkedTriangle::writeNeighbor(std::ostream& os, size_t idx) const { if (_neighbor_triangles[idx]) { os << "["; - (_neighbor_triangles[idx])->write (os); + (_neighbor_triangles[idx])->write(os); os << "]"; } else @@ -97,9 +96,9 @@ LinkedTriangle::~LinkedTriangle() // TODO Auto-generated destructor stub } -std::ostream& operator<< (std::ostream &os, const LinkedTriangle &tri) +std::ostream& operator<<(std::ostream& os, const LinkedTriangle& tri) { - tri.write (os); + tri.write(os); return os; } } // end namespace MathLib diff --git a/MathLib/LinkedTriangle.h b/MathLib/LinkedTriangle.h index 8a29c9fe3..978ca009b 100644 --- a/MathLib/LinkedTriangle.h +++ b/MathLib/LinkedTriangle.h @@ -25,25 +25,20 @@ namespace MathLib class LinkedTriangle : public GEOLIB::Triangle { public: - LinkedTriangle(std::vector const&pnt_vec, size_t pnt_a, - size_t pnt_b, size_t pnt_c, LinkedTriangle* tri_a, - LinkedTriangle* tri_b, LinkedTriangle* tri_c); + LinkedTriangle(std::vector const& pnt_vec, size_t pnt_a, size_t pnt_b, size_t pnt_c, + LinkedTriangle* tri_a, LinkedTriangle* tri_b, LinkedTriangle* tri_c); virtual ~LinkedTriangle(); - void setNeighborTriangle (size_t idx, LinkedTriangle* tri); - void setNeighborTriangleByPointIdx (size_t idx, LinkedTriangle* tri); + void setNeighborTriangle(size_t idx, LinkedTriangle* tri); + void setNeighborTriangleByPointIdx(size_t idx, LinkedTriangle* tri); - LinkedTriangle* getNeighborTriangle (size_t idx); + LinkedTriangle* getNeighborTriangle(size_t idx); size_t getIdxOfNeighborTriangle(LinkedTriangle* tri); - size_t getIdxOfPoint (size_t i) const; + size_t getIdxOfPoint(size_t i) const; - void write (std::ostream &os) const - { - os << _pnt_ids[0] << " " << _pnt_ids[1] << " " << _pnt_ids[2]; - } - - void writeNeighbor (std::ostream &os, size_t idx) const; + void write(std::ostream& os) const { os << _pnt_ids[0] << " " << _pnt_ids[1] << " " << _pnt_ids[2]; } + void writeNeighbor(std::ostream& os, size_t idx) const; private: /** @@ -53,7 +48,7 @@ class LinkedTriangle : public GEOLIB::Triangle }; /** overload the output operator for class LinkedTriangle */ -std::ostream& operator<< (std::ostream &os, const LinkedTriangle &tri); +std::ostream& operator<<(std::ostream& os, const LinkedTriangle& tri); } // end namespace MathLib #endif /* LINKEDTRIANGLE_H_ */ diff --git a/MathLib/MathTools.cpp b/MathLib/MathTools.cpp index fe3c0cca6..eb44f5cf4 100644 --- a/MathLib/MathTools.cpp +++ b/MathLib/MathTools.cpp @@ -21,37 +21,36 @@ void crossProd(const double u[3], const double v[3], double r[3]) r[2] = u[0] * v[1] - u[1] * v[0]; } -double calcProjPntToLineAndDists(const double p[3], const double a[3], - const double b[3], double &lambda, double &d0) +double calcProjPntToLineAndDists(const double p[3], const double a[3], const double b[3], double& lambda, double& d0) { // g (lambda) = a + lambda v, v = b-a double v[3] = {b[0] - a[0], b[1] - a[1], b[2] - a[2]}; // orthogonal projection: (g(lambda)-p) * v = 0 => in order to compute lambda we define a help vector u double u[3] = {p[0] - a[0], p[1] - a[1], p[2] - a[2]}; - lambda = scpr (u, v, 3) / scpr (v, v, 3); + lambda = scpr(u, v, 3) / scpr(v, v, 3); // compute projected point double proj_pnt[3]; for (size_t k(0); k < 3; k++) proj_pnt[k] = a[k] + lambda * v[k]; - d0 = sqrt (sqrDist (proj_pnt, a)); + d0 = sqrt(sqrDist(proj_pnt, a)); - return sqrt (sqrDist (p, proj_pnt)); + return sqrt(sqrDist(p, proj_pnt)); } -double sqrNrm2 (const GEOLIB::Point* p0) +double sqrNrm2(const GEOLIB::Point* p0) { - return scpr (p0->getData(), p0->getData(), 3); + return scpr(p0->getData(), p0->getData(), 3); } -double sqrDist (const GEOLIB::Point* p0, const GEOLIB::Point* p1) +double sqrDist(const GEOLIB::Point* p0, const GEOLIB::Point* p1) { const double v[3] = {(*p1)[0] - (*p0)[0], (*p1)[1] - (*p0)[1], (*p1)[2] - (*p0)[2]}; - return scpr (v, v, 3); + return scpr(v, v, 3); } -bool checkDistance(GEOLIB::Point const &p0, GEOLIB::Point const &p1, double squaredDistance) +bool checkDistance(GEOLIB::Point const& p0, GEOLIB::Point const& p1, double squaredDistance) { return sqrDist(&p0, &p1) < squaredDistance; } @@ -61,12 +60,12 @@ float normalize(float min, float max, float val) return (val - min) / static_cast(max - min); } -double getAngle (const double p0[3], const double p1[3], const double p2[3]) +double getAngle(const double p0[3], const double p1[3], const double p2[3]) { const double v0[3] = {p0[0] - p1[0], p0[1] - p1[1], p0[2] - p1[2]}; const double v1[3] = {p2[0] - p1[0], p2[1] - p1[1], p2[2] - p1[2]}; // apply Cauchy Schwarz inequality - return acos (scpr (v0,v1,3) / (sqrt(scpr(v0,v0,3)) * sqrt(scpr (v1,v1,3)))); + return acos(scpr(v0, v1, 3) / (sqrt(scpr(v0, v0, 3)) * sqrt(scpr(v1, v1, 3)))); } } // namespace diff --git a/MathLib/MathTools.h b/MathLib/MathTools.h index 48655acb2..47ae9ebef 100644 --- a/MathLib/MathTools.h +++ b/MathLib/MathTools.h @@ -26,20 +26,20 @@ namespace MathLib * \param v1 array of type T representing the vector * \param n the size of the array * */ -template inline -double scpr(const T* v0, const T* v1, size_t n) +template +inline double scpr(const T* v0, const T* v1, size_t n) { long double res(0.0); for (size_t k(0); k < n; k++) res += v0[k] * v1[k]; - return (double) res; + return (double)res; } /** * computes the cross (or vector) product of the 3d vectors u and v * the result is given in the vector r */ -void crossProd (const double u[3], const double v[3], double r[3]); +void crossProd(const double u[3], const double v[3], double r[3]); /** * calcProjPntToLineAndDists computes the orthogonal projection @@ -55,8 +55,7 @@ void crossProd (const double u[3], const double v[3], double r[3]); * \param d0 distance to the line point a * \returns the distance between p and the orthogonal projection of p */ -double calcProjPntToLineAndDists(const double p[3], const double a[3], - const double b[3], double &lambda, double &d0); +double calcProjPntToLineAndDists(const double p[3], const double a[3], const double b[3], double& lambda, double& d0); /** * Checks if two points are within a given distance of each other @@ -65,7 +64,7 @@ double calcProjPntToLineAndDists(const double p[3], const double a[3], * @param squaredDistance The square of the distance within which the two points should be * @return true if p1 and p2 are within the given distance of each other, false otherwise */ -bool checkDistance(GEOLIB::Point const &p0, GEOLIB::Point const &p1, double squaredDistance); +bool checkDistance(GEOLIB::Point const& p0, GEOLIB::Point const& p1, double squaredDistance); /** squared euklid norm of the vector p0 */ double sqrNrm2(const GEOLIB::Point* const p0); @@ -77,7 +76,7 @@ double sqrDist(const GEOLIB::Point* p0, const GEOLIB::Point* p1); inline double sqrDist(double const* p0, double const* p1) { const double v[3] = {p1[0] - p0[0], p1[1] - p0[1], p1[2] - p0[2]}; - return scpr (v, v, 3); + return scpr(v, v, 3); } /** linear normalisation of val from [min, max] into [0,1] */ @@ -91,7 +90,7 @@ float normalize(float min, float max, float val); * @param p2 end point of edge 1 * @return the angle between the edges */ -double getAngle (const double p0[3], const double p1[3], const double p2[3]); +double getAngle(const double p0[3], const double p1[3], const double p2[3]); /** * simple power function that takes as a second argument an integer instead of a float @@ -99,10 +98,10 @@ double getAngle (const double p0[3], const double p1[3], const double p2[3]); * @param exp exponent of the expression * @return base^exp */ -template inline -T fastpow (T base, size_t exp) +template +inline T fastpow(T base, size_t exp) { - T result (base); + T result(base); if (exp == 0) result = static_cast(1); for (size_t k(1); k < exp; k++) diff --git a/MathLib/Matrix.h b/MathLib/Matrix.h index 4004dd866..839d72e71 100644 --- a/MathLib/Matrix.h +++ b/MathLib/Matrix.h @@ -25,47 +25,48 @@ namespace MathLib /** * Matrix represents a dense matrix for a numeric data type. */ -template class Matrix +template +class Matrix { public: - Matrix (size_t rows, size_t cols); - Matrix (size_t rows, size_t cols, const T& val); - Matrix (const Matrix &src); + Matrix(size_t rows, size_t cols); + Matrix(size_t rows, size_t cols, const T& val); + Matrix(const Matrix& src); - ~Matrix (); + ~Matrix(); - size_t getNRows () const { return nrows; } - size_t getNCols () const { return ncols; } + size_t getNRows() const { return nrows; } + size_t getNCols() const { return ncols; } /** * \f$ y = \alpha \cdot A x + \beta y\f$ */ - void axpy ( T alpha, const T* x, T beta, T* y) const; + void axpy(T alpha, const T* x, T beta, T* y) const; /** * Matrix vector multiplication * @param x * @return */ - T* operator* (const T* x) const; + T* operator*(const T* x) const; /** * Matrix matrix addition. * @param mat * @return */ - Matrix* operator+ (const Matrix& mat) const throw (std::range_error); + Matrix* operator+(const Matrix& mat) const throw(std::range_error); /** * Matrix matrix subtraction * @param mat * @return */ - Matrix* operator- (const Matrix& mat) const throw (std::range_error); + Matrix* operator-(const Matrix& mat) const throw(std::range_error); /** * Matrix matrix multiplication \f$ C = A \cdot B\f$ * @param mat the matrix \f$ B \f$ * @return the matrix \f$ C \f$ */ - Matrix* operator* (const Matrix& mat) const throw (std::range_error); + Matrix* operator*(const Matrix& mat) const throw(std::range_error); /** * matrix transpose @@ -73,8 +74,7 @@ template class Matrix */ Matrix* transpose() const; // HB & ZC - Matrix* getSubMatrix (size_t b_row, size_t b_col, size_t e_row, - size_t e_col) const throw (std::range_error); + Matrix* getSubMatrix(size_t b_row, size_t b_col, size_t e_row, size_t e_col) const throw(std::range_error); /** * overwrites values of the matrix with the given sub matrix @@ -82,61 +82,62 @@ template class Matrix * @param b_col the first column * @param sub_mat the sub matrix */ - void setSubMatrix (size_t b_row, size_t b_col, - const Matrix& sub_mat) throw (std::range_error); + void setSubMatrix(size_t b_row, size_t b_col, const Matrix& sub_mat) throw(std::range_error); - inline T & operator() (size_t row, size_t col) throw (std::range_error); - inline T & operator() (size_t row, size_t col) const throw (std::range_error); + inline T& operator()(size_t row, size_t col) throw(std::range_error); + inline T& operator()(size_t row, size_t col) const throw(std::range_error); /** * writes the matrix entries into the output stream * @param out the output stream */ - void write (std::ostream& out) const; - - T const* getData () { return data; } + void write(std::ostream& out) const; + T const* getData() { return data; } private: // zero based addressing, but Fortran storage layout - //inline size_t address(size_t i, size_t j) const { return j*rows+i; }; + // inline size_t address(size_t i, size_t j) const { return j*rows+i; }; // zero based addressing, C storage layout inline size_t address(size_t i, size_t j) const { return i * ncols + j; } - size_t nrows; size_t ncols; T* data; }; -template Matrix::Matrix (size_t rows, size_t cols) - : nrows (rows), ncols (cols), data (new T[nrows * ncols]) -{} +template +Matrix::Matrix(size_t rows, size_t cols) : nrows(rows), ncols(cols), data(new T[nrows * ncols]) +{ +} -template Matrix::Matrix (const Matrix& src) : - nrows (src.getNRows ()), ncols (src.getNCols ()), data (new T[nrows * ncols]) +template +Matrix::Matrix(const Matrix& src) : nrows(src.getNRows()), ncols(src.getNCols()), data(new T[nrows * ncols]) { for (size_t i = 0; i < nrows; i++) for (size_t j = 0; j < ncols; j++) - data[address(i,j)] = src (i, j); + data[address(i, j)] = src(i, j); } -template Matrix::~Matrix () +template +Matrix::~Matrix() { - delete [] data; + delete[] data; } -template void Matrix::axpy ( T alpha, const T* x, T beta, T* y) const +template +void Matrix::axpy(T alpha, const T* x, T beta, T* y) const { for (size_t i(0); i < nrows; i++) { y[i] += beta * y[i]; for (size_t j(0); j < ncols; j++) - y[i] += alpha * data[address(i,j)] * x[j]; + y[i] += alpha * data[address(i, j)] * x[j]; } } -template T* Matrix::operator* (const T* x) const +template +T* Matrix::operator*(const T* x) const { - T* y (new T[nrows]); + T* y(new T[nrows]); for (size_t i(0); i < nrows; i++) { y[i] = 0.0; @@ -148,14 +149,14 @@ template T* Matrix::operator* (const T* x) const } // HS initial implementation -template Matrix* Matrix::operator+ (const Matrix& mat) const throw (std:: - range_error) +template +Matrix* Matrix::operator+(const Matrix& mat) const throw(std::range_error) { // make sure the two matrices have the same dimension. if (nrows != mat.getNRows() || ncols != mat.getNCols()) throw std::range_error("Matrix::operator+, illegal matrix size!"); - Matrix* y(new Matrix (nrows, ncols)); + Matrix* y(new Matrix(nrows, ncols)); for (size_t i = 0; i < nrows; i++) for (size_t j = 0; j < ncols; j++) (*y)(i, j) = data[address(i, j)] + mat(i, j); @@ -164,14 +165,14 @@ template Matrix* Matrix::operator+ (const Matrix& mat) const t } // HS initial implementation -template Matrix* Matrix::operator- (const Matrix& mat) const throw (std:: - range_error) +template +Matrix* Matrix::operator-(const Matrix& mat) const throw(std::range_error) { // make sure the two matrices have the same dimension. if (nrows != mat.getNRows() || ncols != mat.getNCols()) throw std::range_error("Matrix::operator-, illegal matrix size!"); - Matrix* y(new Matrix (nrows, ncols)); + Matrix* y(new Matrix(nrows, ncols)); for (size_t i = 0; i < nrows; i++) for (size_t j = 0; j < ncols; j++) (*y)(i, j) = data[address(i, j)] - mat(i, j); @@ -180,16 +181,15 @@ template Matrix* Matrix::operator- (const Matrix& mat) const t } // HS initial implementation -template Matrix* Matrix::operator* (const Matrix& mat) const throw (std:: - range_error) +template +Matrix* Matrix::operator*(const Matrix& mat) const throw(std::range_error) { // make sure the two matrices have the same dimension. if (ncols != mat.getNRows()) - throw std::range_error( - "Matrix::operator*, number of rows and cols should be the same!"); + throw std::range_error("Matrix::operator*, number of rows and cols should be the same!"); size_t y_cols(mat.getNCols()); - Matrix* y(new Matrix (nrows, y_cols, T(0))); + Matrix* y(new Matrix(nrows, y_cols, T(0))); for (size_t i = 0; i < nrows; i++) for (size_t j = 0; j < y_cols; j++) @@ -200,28 +200,28 @@ template Matrix* Matrix::operator* (const Matrix& mat) const t } // HS initial implementation -template Matrix* Matrix::transpose() const +template +Matrix* Matrix::transpose() const { - Matrix* y(new Matrix (ncols, nrows)); + Matrix* y(new Matrix(ncols, nrows)); for (size_t i = 0; i < nrows; i++) for (size_t j = 0; j < ncols; j++) -// y->data[y->address(j, i)] = data[address(i, j)]; - (*y)(j,i) = data[address(i, j)]; + // y->data[y->address(j, i)] = data[address(i, j)]; + (*y)(j, i) = data[address(i, j)]; return y; } -template Matrix* Matrix::getSubMatrix( - size_t b_row, size_t b_col, - size_t e_row, size_t e_col) const throw (std::range_error) +template +Matrix* Matrix::getSubMatrix(size_t b_row, size_t b_col, size_t e_row, size_t e_col) const throw(std::range_error) { if (b_row >= e_row | b_col >= e_col) - throw std::range_error ("Matrix::getSubMatrix() illegal sub matrix"); + throw std::range_error("Matrix::getSubMatrix() illegal sub matrix"); if (e_row > nrows | e_col > ncols) - throw std::range_error ("Matrix::getSubMatrix() illegal sub matrix"); + throw std::range_error("Matrix::getSubMatrix() illegal sub matrix"); - Matrix* y(new Matrix (e_row - b_row, e_col - b_col)); + Matrix* y(new Matrix(e_row - b_row, e_col - b_col)); for (size_t i = b_row; i < e_row; i++) for (size_t j = b_col; j < e_col; j++) (*y)(i - b_row, j - b_col) = data[address(i, j)]; @@ -229,35 +229,35 @@ template Matrix* Matrix::getSubMatrix( return y; } -template void Matrix::setSubMatrix( - size_t b_row, size_t b_col, const Matrix& sub_mat) throw (std::range_error) +template +void Matrix::setSubMatrix(size_t b_row, size_t b_col, const Matrix& sub_mat) throw(std::range_error) { if (b_row + sub_mat.getNRows() > nrows | b_col + sub_mat.getNCols() > ncols) - throw std::range_error ("Matrix::setSubMatrix() sub matrix to big"); + throw std::range_error("Matrix::setSubMatrix() sub matrix to big"); for (size_t i = 0; i < sub_mat.getNRows(); i++) for (size_t j = 0; j < sub_mat.getNCols(); j++) - data[address(i + b_row, j + b_col)] = sub_mat(i,j); - + data[address(i + b_row, j + b_col)] = sub_mat(i, j); } -template T& Matrix::operator() (size_t row, size_t col) -throw (std::range_error) +template +T& Matrix::operator()(size_t row, size_t col) throw(std::range_error) { - if ( (row >= nrows) | ( col >= ncols) ) - throw std::range_error ("Matrix: op() const range error"); - return data [address(row,col)]; + if ((row >= nrows) | (col >= ncols)) + throw std::range_error("Matrix: op() const range error"); + return data[address(row, col)]; } -template T& Matrix::operator() (size_t row, size_t col) const -throw (std::range_error) +template +T& Matrix::operator()(size_t row, size_t col) const throw(std::range_error) { - if ( (row >= nrows) | ( col >= ncols) ) - throw std::range_error ("Matrix: op() const range error"); - return data [address(row,col)]; + if ((row >= nrows) | (col >= ncols)) + throw std::range_error("Matrix: op() const range error"); + return data[address(row, col)]; } -template void Matrix::write (std::ostream &out) const +template +void Matrix::write(std::ostream& out) const { for (size_t i = 0; i < nrows; i++) { @@ -267,22 +267,23 @@ template void Matrix::write (std::ostream &out) const } } -template T sqrFrobNrm (const Matrix &mat) +template +T sqrFrobNrm(const Matrix& mat) { - T nrm ((T)(0)); - size_t i,j; + T nrm((T)(0)); + size_t i, j; for (j = 0; j < mat.getNCols(); j++) for (i = 0; i < mat.getNRows(); i++) - nrm += mat(i,j) * mat(i,j); + nrm += mat(i, j) * mat(i, j); return nrm; } /** overload the output operator for class Matrix */ template -std::ostream& operator<< (std::ostream &os, const Matrix &mat) +std::ostream& operator<<(std::ostream& os, const Matrix& mat) { - mat.write (os); + mat.write(os); return os; } } // end namespace MathLib diff --git a/MathLib/PETSC/PETScLinearSolver.cpp b/MathLib/PETSC/PETScLinearSolver.cpp index 7fb785496..367b8da4a 100644 --- a/MathLib/PETSC/PETScLinearSolver.cpp +++ b/MathLib/PETSC/PETScLinearSolver.cpp @@ -15,57 +15,54 @@ */ #include "PETScLinearSolver.h" -#include - +#include namespace petsc_group { +PETScLinearSolver::PETScLinearSolver(const int size) + : A(NULL), b(NULL), x(NULL), lsolver(NULL), prec(NULL), i_start(0), i_end(0), global_x(NULL) +{ + ltolerance = 1.e-10; + m_size = size; + time_elapsed = 0.0; + d_nz = 10; + o_nz = 10; + nz = 10; + m_size_loc = PETSC_DECIDE; + mpi_size = 0; + rank = 0; +} - PETScLinearSolver :: PETScLinearSolver (const int size) - : A(NULL), b(NULL), x(NULL), lsolver(NULL), prec(NULL), - i_start(0), i_end(0), global_x(NULL) - { - ltolerance = 1.e-10; - m_size = size; - time_elapsed = 0.0; - d_nz = 10; - o_nz = 10; - nz = 10; - m_size_loc = PETSC_DECIDE; - mpi_size = 0; - rank = 0; - } - -PETScLinearSolver:: ~PETScLinearSolver() +PETScLinearSolver::~PETScLinearSolver() { - VecDestroy(&b); - VecDestroy(&x); - MatDestroy(&A); - if(lsolver) KSPDestroy(&lsolver); - // if(prec) PCDestroy(&prec); + VecDestroy(&b); + VecDestroy(&x); + MatDestroy(&A); + if (lsolver) + KSPDestroy(&lsolver); + // if(prec) PCDestroy(&prec); - if(global_x) - delete [] global_x; + if (global_x) + delete[] global_x; - PetscPrintf(PETSC_COMM_WORLD,"\tNumber of Unknows: %d", m_size); - PetscPrintf(PETSC_COMM_WORLD,"\n\tElapsed time in linear solver: %f s\n", time_elapsed); + PetscPrintf(PETSC_COMM_WORLD, "\tNumber of Unknows: %d", m_size); + PetscPrintf(PETSC_COMM_WORLD, "\n\tElapsed time in linear solver: %f s\n", time_elapsed); } -void PETScLinearSolver::Init(const int *sparse_index) +void PETScLinearSolver::Init(const int* sparse_index) { - if(sparse_index) - { - d_nz = sparse_index[0]; - o_nz = sparse_index[1]; - nz = sparse_index[2]; - m_size_loc = sparse_index[3]; - } - - VectorCreate(m_size); - MatrixCreate(m_size, m_size); + if (sparse_index) + { + d_nz = sparse_index[0]; + o_nz = sparse_index[1]; + nz = sparse_index[2]; + m_size_loc = sparse_index[3]; + } - global_x = new PetscScalar[m_size]; + VectorCreate(m_size); + MatrixCreate(m_size, m_size); + global_x = new PetscScalar[m_size]; } /*! @@ -148,268 +145,261 @@ void PETScLinearSolver::Init(const int *sparse_index) PCGAMG "gamg" */ -void PETScLinearSolver::Config(const PetscReal tol, const PetscInt maxits, const KSPType lsol, - const PCType prec_type, const std::string &prefix) +void PETScLinearSolver::Config(const PetscReal tol, const PetscInt maxits, const KSPType lsol, const PCType prec_type, + const std::string& prefix) { - ltolerance = tol; - sol_type = lsol; - pc_type = prec_type; + ltolerance = tol; + sol_type = lsol; + pc_type = prec_type; - KSPCreate(PETSC_COMM_WORLD,&lsolver); + KSPCreate(PETSC_COMM_WORLD, &lsolver); #if (PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR > 4) - KSPSetOperators(lsolver, A, A); + KSPSetOperators(lsolver, A, A); #else - KSPSetOperators(lsolver, A, A, DIFFERENT_NONZERO_PATTERN); + KSPSetOperators(lsolver, A, A, DIFFERENT_NONZERO_PATTERN); #endif - KSPSetType(lsolver,lsol); + KSPSetType(lsolver, lsol); - KSPGetPC(lsolver, &prec); - PCSetType(prec, prec_type); // PCJACOBI); //PCNONE); - KSPSetTolerances(lsolver,ltolerance, PETSC_DEFAULT, PETSC_DEFAULT, maxits); + KSPGetPC(lsolver, &prec); + PCSetType(prec, prec_type); // PCJACOBI); //PCNONE); + KSPSetTolerances(lsolver, ltolerance, PETSC_DEFAULT, PETSC_DEFAULT, maxits); - if( !prefix.empty() ) - { - KSPSetOptionsPrefix(lsolver, prefix.c_str()); - PCSetOptionsPrefix(prec, prefix.c_str()); - } + if (!prefix.empty()) + { + KSPSetOptionsPrefix(lsolver, prefix.c_str()); + PCSetOptionsPrefix(prec, prefix.c_str()); + } - KSPSetFromOptions(lsolver); + KSPSetFromOptions(lsolver); } //----------------------------------------------------------------- void PETScLinearSolver::VectorCreate(PetscInt m) { - //PetscErrorCode ierr; // returned value from PETSc functions - VecCreate(PETSC_COMM_WORLD, &b); - ////VecCreateMPI(PETSC_COMM_WORLD,m_size_loc, m, &b); - //VecSetSizes(b, m_size_loc, m); - VecSetSizes(b, PETSC_DECIDE, m); - VecSetFromOptions(b); - VecSetOption(b, VEC_IGNORE_NEGATIVE_INDICES,PETSC_TRUE); - VecSetUp(b); //kg44 for PETSC 3.3 - VecDuplicate(b, &x); - VecSetOption(x, VEC_IGNORE_NEGATIVE_INDICES,PETSC_TRUE); + // PetscErrorCode ierr; // returned value from PETSc functions + VecCreate(PETSC_COMM_WORLD, &b); + ////VecCreateMPI(PETSC_COMM_WORLD,m_size_loc, m, &b); + // VecSetSizes(b, m_size_loc, m); + VecSetSizes(b, PETSC_DECIDE, m); + VecSetFromOptions(b); + VecSetOption(b, VEC_IGNORE_NEGATIVE_INDICES, PETSC_TRUE); + VecSetUp(b); // kg44 for PETSC 3.3 + VecDuplicate(b, &x); + VecSetOption(x, VEC_IGNORE_NEGATIVE_INDICES, PETSC_TRUE); - VecGetLocalSize(x, &m_size_loc); + VecGetLocalSize(x, &m_size_loc); - //VecGetOwnershipRange(b, &i_start,&i_end); + // VecGetOwnershipRange(b, &i_start,&i_end); } - -void PETScLinearSolver::MatrixCreate( PetscInt m, PetscInt n) +void PETScLinearSolver::MatrixCreate(PetscInt m, PetscInt n) { - MatCreate(PETSC_COMM_WORLD, &A); - // TEST MatSetSizes(A, m_size_loc, PETSC_DECIDE, m, n); - MatSetSizes(A, PETSC_DECIDE, PETSC_DECIDE, m, n); - //MatSetSizes(A, m_size_loc, PETSC_DECIDE, m, n); + MatCreate(PETSC_COMM_WORLD, &A); + // TEST MatSetSizes(A, m_size_loc, PETSC_DECIDE, m, n); + MatSetSizes(A, PETSC_DECIDE, PETSC_DECIDE, m, n); + // MatSetSizes(A, m_size_loc, PETSC_DECIDE, m, n); - MatSetType(A, MATMPIAIJ); - MatSetFromOptions(A); + MatSetType(A, MATMPIAIJ); + MatSetFromOptions(A); - MatSeqAIJSetPreallocation(A, d_nz, PETSC_NULL); - MatMPIAIJSetPreallocation(A, d_nz, PETSC_NULL, o_nz, PETSC_NULL); - MatSetOption(A,MAT_NEW_NONZERO_ALLOCATION_ERR,PETSC_FALSE); + MatSeqAIJSetPreallocation(A, d_nz, PETSC_NULL); + MatMPIAIJSetPreallocation(A, d_nz, PETSC_NULL, o_nz, PETSC_NULL); + MatSetOption(A, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE); - MatSetUp(A); // KG44 this seems to work with petsc 3.3 ..the commands below result in problems when assembling the matrix with version 3.3 + MatSetUp(A); // KG44 this seems to work with petsc 3.3 ..the commands below result in problems when assembling the + // matrix with version 3.3 - MatGetOwnershipRange(A, &i_start, &i_end); + MatGetOwnershipRange(A, &i_start, &i_end); } -void PETScLinearSolver::getLocalRowColumnSizes(int *m, int *n) +void PETScLinearSolver::getLocalRowColumnSizes(int* m, int* n) { - MatGetLocalSize(A, m, n); + MatGetLocalSize(A, m, n); } -void PETScLinearSolver::getOwnerRange(int *start_r, int *end_r) +void PETScLinearSolver::getOwnerRange(int* start_r, int* end_r) { - *start_r = i_start; - *end_r = i_end; + *start_r = i_start; + *end_r = i_end; } void PETScLinearSolver::Solver() { - - //TEST +// TEST #ifdef TEST_MEM_PETSC - PetscLogDouble mem1, mem2; - PetscMemoryGetCurrentUsage(&mem1); + PetscLogDouble mem1, mem2; + PetscMemoryGetCurrentUsage(&mem1); #endif - /* - //TEST - PetscViewer viewer; - PetscViewerASCIIOpen(PETSC_COMM_WORLD, "x.txt", &viewer); - PetscViewerPushFormat(viewer,PETSC_VIEWER_ASCII_MATLAB); - PetscObjectSetName((PetscObject)x,"Solution"); - VecView(x, viewer); - */ - - - int its; - PetscLogDouble v1,v2; - KSPConvergedReason reason; - - // #define PETSC34 - //kg44 quick fix to compile PETSC with version PETSCV3.4 + /* + //TEST + PetscViewer viewer; + PetscViewerASCIIOpen(PETSC_COMM_WORLD, "x.txt", &viewer); + PetscViewerPushFormat(viewer,PETSC_VIEWER_ASCII_MATLAB); + PetscObjectSetName((PetscObject)x,"Solution"); + VecView(x, viewer); + */ + + int its; + PetscLogDouble v1, v2; + KSPConvergedReason reason; + +// #define PETSC34 +// kg44 quick fix to compile PETSC with version PETSCV3.4 #ifdef USEPETSC34 - PetscTime(&v1); + PetscTime(&v1); #else - PetscGetTime(&v1); + PetscGetTime(&v1); #endif #if (PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR > 4) - KSPSetOperators(lsolver, A, A); + KSPSetOperators(lsolver, A, A); #else - KSPSetOperators(lsolver, A, A, DIFFERENT_NONZERO_PATTERN); + KSPSetOperators(lsolver, A, A, DIFFERENT_NONZERO_PATTERN); #endif - KSPSolve(lsolver, b, x); - - KSPGetConvergedReason(lsolver,&reason); //CHKERRQ(ierr); - if (reason==KSP_DIVERGED_INDEFINITE_PC) - { - PetscPrintf(PETSC_COMM_WORLD,"\nDivergence because of indefinite preconditioner;\n"); - PetscPrintf(PETSC_COMM_WORLD,"Run the executable again but with -pc_factor_shift_positive_definite option.\n"); - } - else if (reason<0) - { - PetscPrintf(PETSC_COMM_WORLD,"\nOther kind of divergence: this should not happen.\n"); - } - else - { - const char *slv_type; - const char *prc_type; - KSPGetType(lsolver, &slv_type); - PCGetType(prec, &prc_type); - - PetscPrintf(PETSC_COMM_WORLD,"\n================================================"); - PetscPrintf(PETSC_COMM_WORLD, "\nLinear solver %s with %s preconditioner", - slv_type, prc_type); - KSPGetIterationNumber(lsolver,&its); //CHKERRQ(ierr); - PetscPrintf(PETSC_COMM_WORLD,"\nConvergence in %d iterations.\n",(int)its); - PetscPrintf(PETSC_COMM_WORLD,"\n================================================"); - } - PetscPrintf(PETSC_COMM_WORLD,"\n"); - - //VecAssemblyBegin(x); - //VecAssemblyEnd(x); - - //kg44 quick fix to compile PETSC with version PETSCV3.4 + KSPSolve(lsolver, b, x); + + KSPGetConvergedReason(lsolver, &reason); // CHKERRQ(ierr); + if (reason == KSP_DIVERGED_INDEFINITE_PC) + { + PetscPrintf(PETSC_COMM_WORLD, "\nDivergence because of indefinite preconditioner;\n"); + PetscPrintf(PETSC_COMM_WORLD, "Run the executable again but with -pc_factor_shift_positive_definite option.\n"); + } + else if (reason < 0) + { + PetscPrintf(PETSC_COMM_WORLD, "\nOther kind of divergence: this should not happen.\n"); + } + else + { + const char* slv_type; + const char* prc_type; + KSPGetType(lsolver, &slv_type); + PCGetType(prec, &prc_type); + + PetscPrintf(PETSC_COMM_WORLD, "\n================================================"); + PetscPrintf(PETSC_COMM_WORLD, "\nLinear solver %s with %s preconditioner", slv_type, prc_type); + KSPGetIterationNumber(lsolver, &its); // CHKERRQ(ierr); + PetscPrintf(PETSC_COMM_WORLD, "\nConvergence in %d iterations.\n", (int)its); + PetscPrintf(PETSC_COMM_WORLD, "\n================================================"); + } + PetscPrintf(PETSC_COMM_WORLD, "\n"); + +// VecAssemblyBegin(x); +// VecAssemblyEnd(x); + +// kg44 quick fix to compile PETSC with version PETSCV3.4 #ifdef USEPETSC34 - PetscTime(&v2); + PetscTime(&v2); #else - PetscGetTime(&v2); + PetscGetTime(&v2); #endif - time_elapsed += v2-v1; + time_elapsed += v2 - v1; #define nonTEST_OUT #ifdef TEST_OUT - //TEST - PetscViewer viewer; - PetscViewerASCIIOpen(PETSC_COMM_WORLD, "matrix_vector.txt", &viewer); - PetscViewerPushFormat(viewer,PETSC_VIEWER_ASCII_MATLAB); - PetscObjectSetName((PetscObject)A,"Matrix"); - MatView(A, viewer); - PetscObjectSetName((PetscObject)x,"Solution"); - VecView(x, viewer); - PetscObjectSetName((PetscObject)b,"RHS"); - VecView(b, viewer); - /* - VecDestroy(&b); - VecDestroy(&x); - MatDestroy(&A); - if(lsolver) KSPDestroy(&lsolver); - if(global_x) - delete [] global_x; - - PetscFinalize(); - exit(0); - */ + // TEST + PetscViewer viewer; + PetscViewerASCIIOpen(PETSC_COMM_WORLD, "matrix_vector.txt", &viewer); + PetscViewerPushFormat(viewer, PETSC_VIEWER_ASCII_MATLAB); + PetscObjectSetName((PetscObject)A, "Matrix"); + MatView(A, viewer); + PetscObjectSetName((PetscObject)x, "Solution"); + VecView(x, viewer); + PetscObjectSetName((PetscObject)b, "RHS"); + VecView(b, viewer); +/* +VecDestroy(&b); +VecDestroy(&x); +MatDestroy(&A); +if(lsolver) KSPDestroy(&lsolver); +if(global_x) + delete [] global_x; + + PetscFinalize(); + exit(0); + */ #endif - #ifdef TEST_MEM_PETSC - //TEST - PetscMemoryGetCurrentUsage(&mem2); - PetscPrintf(PETSC_COMM_WORLD, "###Memory usage by solver. Before :%f After:%f Increase:%d\n", mem1, mem2, (int)(mem2 - mem1)); + // TEST + PetscMemoryGetCurrentUsage(&mem2); + PetscPrintf(PETSC_COMM_WORLD, "###Memory usage by solver. Before :%f After:%f Increase:%d\n", mem1, mem2, + (int)(mem2 - mem1)); #endif } - void PETScLinearSolver::AssembleRHS_PETSc() +void PETScLinearSolver::AssembleRHS_PETSc() { - VecAssemblyBegin(b); - VecAssemblyEnd(b); + VecAssemblyBegin(b); + VecAssemblyEnd(b); } void PETScLinearSolver::AssembleUnkowns_PETSc() { - VecAssemblyBegin(x); - VecAssemblyEnd(x); + VecAssemblyBegin(x); + VecAssemblyEnd(x); } void PETScLinearSolver::AssembleMatrixPETSc(const MatAssemblyType type) { - MatAssemblyBegin(A, type); - MatAssemblyEnd(A, type); + MatAssemblyBegin(A, type); + MatAssemblyEnd(A, type); } - -void PETScLinearSolver::UpdateSolutions(PetscScalar *u) +void PETScLinearSolver::UpdateSolutions(PetscScalar* u) { - #ifdef TEST_MEM_PETSC - //TEST - PetscLogDouble mem1, mem2; - PetscMemoryGetCurrentUsage(&mem1); + // TEST + PetscLogDouble mem1, mem2; + PetscMemoryGetCurrentUsage(&mem1); #endif - PetscScalar *xp = NULL; //nullptr; - VecGetArray(x, &xp); + PetscScalar* xp = NULL; // nullptr; + VecGetArray(x, &xp); - gatherLocalVectors(xp, u); + gatherLocalVectors(xp, u); - //MPI_Barrier(PETSC_COMM_WORLD); + // MPI_Barrier(PETSC_COMM_WORLD); - VecRestoreArray(x, &xp); + VecRestoreArray(x, &xp); - //TEST +// TEST #ifdef TEST_MEM_PETSC - PetscMemoryGetCurrentUsage(&mem2); - PetscPrintf(PETSC_COMM_WORLD, "### Memory usage by Updating. Before :%f After:%f Increase:%d\n", mem1, mem2, (int)(mem2 - mem1)); + PetscMemoryGetCurrentUsage(&mem2); + PetscPrintf(PETSC_COMM_WORLD, "### Memory usage by Updating. Before :%f After:%f Increase:%d\n", mem1, mem2, + (int)(mem2 - mem1)); #endif - } void PETScLinearSolver::MappingSolution() { - UpdateSolutions(global_x); + UpdateSolutions(global_x); } - -int PETScLinearSolver::GetLocalSolution(PetscScalar *x_l) +int PETScLinearSolver::GetLocalSolution(PetscScalar* x_l) { - PetscInt count; - VecGetLocalSize(x, &count); + PetscInt count; + VecGetLocalSize(x, &count); - VecGetArray(x, &x_l); + VecGetArray(x, &x_l); - return count; + return count; } - -int PETScLinearSolver::GetLocalRHS(PetscScalar *rhs_l) +int PETScLinearSolver::GetLocalRHS(PetscScalar* rhs_l) { - PetscInt count; - VecGetLocalSize(b, &count); + PetscInt count; + VecGetLocalSize(b, &count); - VecGetArray(b, &rhs_l); + VecGetArray(b, &rhs_l); - return count; + return count; } -double *PETScLinearSolver::GetGlobalSolution() const +double* PETScLinearSolver::GetGlobalSolution() const { - return global_x; + return global_x; } /*! @@ -419,13 +409,12 @@ double *PETScLinearSolver::GetGlobalSolution() const @param ni - number of elements to get @param ix - indices where to get them from (in global 1d numbering) */ -void PETScLinearSolver::GetVecValues(const int v_type, PetscInt ni,const PetscInt ix[], - PetscScalar y[]) const +void PETScLinearSolver::GetVecValues(const int v_type, PetscInt ni, const PetscInt ix[], PetscScalar y[]) const { - if(v_type == 0) - VecGetValues(x, ni, ix, y); - else - VecGetValues(b, ni, ix, y); + if (v_type == 0) + VecGetValues(x, ni, ix, y); + else + VecGetValues(b, ni, ix, y); } /*! @@ -436,11 +425,11 @@ void PETScLinearSolver::GetVecValues(const int v_type, PetscInt ni,const PetscI NORM_INFINITY denotes max_i |x_i| 06.2012. WW */ -PetscReal PETScLinearSolver::GetVecNormRHS(NormType nmtype) +PetscReal PETScLinearSolver::GetVecNormRHS(NormType nmtype) { - PetscReal norm = 0.; - VecNorm(b, nmtype, &norm); - return norm; + PetscReal norm = 0.; + VecNorm(b, nmtype, &norm); + return norm; } /*! Get norm of x @@ -450,155 +439,137 @@ PetscReal PETScLinearSolver::GetVecNormRHS(NormType nmtype) NORM_INFINITY denotes max_i |x_i| 06.2012. WW */ -PetscReal PETScLinearSolver::GetVecNormX(NormType nmtype) +PetscReal PETScLinearSolver::GetVecNormX(NormType nmtype) { - PetscReal norm = 0.; - VecNorm(x, nmtype, &norm); - return norm; + PetscReal norm = 0.; + VecNorm(x, nmtype, &norm); + return norm; } - -void PETScLinearSolver::RestoreLocalSolutionArray(PetscScalar *x_l) +void PETScLinearSolver::RestoreLocalSolutionArray(PetscScalar* x_l) { - VecRestoreArray(x, &x_l); + VecRestoreArray(x, &x_l); } -void PETScLinearSolver::RestoreLocalRHSArray(PetscScalar *rhs_l) +void PETScLinearSolver::RestoreLocalRHSArray(PetscScalar* rhs_l) { - VecRestoreArray(b, &rhs_l); + VecRestoreArray(b, &rhs_l); } -void PETScLinearSolver::set_bVectorEntry(const int i, const double value ) +void PETScLinearSolver::set_bVectorEntry(const int i, const double value) { - - VecSetValues(b,1,&i,&value,INSERT_VALUES); + VecSetValues(b, 1, &i, &value, INSERT_VALUES); } void PETScLinearSolver::set_xVectorEntry(const int i, const double value) { - - VecSetValues(x,1,&i,&value,INSERT_VALUES); + VecSetValues(x, 1, &i, &value, INSERT_VALUES); } -void PETScLinearSolver::setArrayValues(int arr_idx, PetscInt ni, const PetscInt ix[], - const PetscScalar y[],InsertMode iora) +void PETScLinearSolver::setArrayValues(int arr_idx, PetscInt ni, const PetscInt ix[], const PetscScalar y[], + InsertMode iora) { - if(arr_idx == 0) - VecSetValues(x, ni, ix, y, iora); - else if(arr_idx == 1) - VecSetValues(b, ni, ix, y, iora); + if (arr_idx == 0) + VecSetValues(x, ni, ix, y, iora); + else if (arr_idx == 1) + VecSetValues(b, ni, ix, y, iora); } - - -void PETScLinearSolver::add_bVectorEntry(const int i, const double value,InsertMode mode ) +void PETScLinearSolver::add_bVectorEntry(const int i, const double value, InsertMode mode) { - - VecSetValue(b, i, value, mode); + VecSetValue(b, i, value, mode); } void PETScLinearSolver::add_xVectorEntry(const int i, const double value, InsertMode mode) { - - VecSetValue(x, i, value,mode); + VecSetValue(x, i, value, mode); } - -void PETScLinearSolver::Initialize( ) +void PETScLinearSolver::Initialize() { - - VecSet(b, 0.0); - VecSet(x, 0.0); - MatZeroEntries(A); + VecSet(b, 0.0); + VecSet(x, 0.0); + MatZeroEntries(A); } - - void PETScLinearSolver::addMatrixEntry(const int i, const int j, const double value) { - - MatSetValue(A, i, j, value, ADD_VALUES); + MatSetValue(A, i, j, value, ADD_VALUES); } -void PETScLinearSolver::addMatrixEntries(const int m,const int idxm[], const int n, - const int idxn[],const PetscScalar v[]) +void PETScLinearSolver::addMatrixEntries(const int m, const int idxm[], const int n, const int idxn[], + const PetscScalar v[]) { - MatSetValues(A, m, idxm, n, idxn, v, ADD_VALUES); + MatSetValues(A, m, idxm, n, idxn, v, ADD_VALUES); } - - - -void PETScLinearSolver::zeroRows_in_Matrix(const int nrows, const PetscInt *rows) +void PETScLinearSolver::zeroRows_in_Matrix(const int nrows, const PetscInt* rows) { - PetscScalar one = 1.0; - // Each process indicates only rows it owns that are to be zeroed - // MatSetOption(A, MAT_NO_OFF_PROC_ZERO_ROWS,PETSC_TRUE); - if(nrows>0) - MatZeroRows (A, nrows, rows, one, PETSC_NULL, PETSC_NULL); - else - MatZeroRows(A, 0, PETSC_NULL, one, PETSC_NULL, PETSC_NULL); + PetscScalar one = 1.0; + // Each process indicates only rows it owns that are to be zeroed + // MatSetOption(A, MAT_NO_OFF_PROC_ZERO_ROWS,PETSC_TRUE); + if (nrows > 0) + MatZeroRows(A, nrows, rows, one, PETSC_NULL, PETSC_NULL); + else + MatZeroRows(A, 0, PETSC_NULL, one, PETSC_NULL, PETSC_NULL); } -void PETScLinearSolver::gatherLocalVectors( PetscScalar local_array[], - PetscScalar global_array[]) +void PETScLinearSolver::gatherLocalVectors(PetscScalar local_array[], PetscScalar global_array[]) { - // Collect vectors from processors. - int size_rank; - MPI_Comm_size(PETSC_COMM_WORLD, &size_rank); - - // number of elements to be sent for each rank - std::vector i_cnt(size_rank); - // offset in the receive vector of the data from each rank - std::vector i_disp(size_rank); + // Collect vectors from processors. + int size_rank; + MPI_Comm_size(PETSC_COMM_WORLD, &size_rank); - MPI_Allgather(&m_size_loc, 1, MPI_INT, &i_cnt[0], 1, MPI_INT, PETSC_COMM_WORLD); + // number of elements to be sent for each rank + std::vector i_cnt(size_rank); + // offset in the receive vector of the data from each rank + std::vector i_disp(size_rank); - // colloect local array - PetscInt offset = 0; - for(PetscInt i=0; i #include -//kg needed for memcpy in petsc libs +// kg needed for memcpy in petsc libs #include #include @@ -34,120 +34,108 @@ typedef Vec PETSc_Vec; namespace petsc_group { - class PETScLinearSolver { public: - PETScLinearSolver (const int size); - ~PETScLinearSolver(); - - void Config(const PetscReal tol, const PetscInt maxits, const KSPType lsol, - const PCType prec_type, const std::string &prefix = ""); - - void Init(const int *sparse_index = NULL); - - void Solver(); - void AssembleRHS_PETSc(); - void AssembleUnkowns_PETSc(); - void AssembleMatrixPETSc(const MatAssemblyType type = MAT_FINAL_ASSEMBLY); //MAT_FLUSH_ASSEMBLY - - void MappingSolution(); - - int GetLocalSolution(PetscScalar *x_l); - int GetLocalRHS(PetscScalar *rhs_l); - double *GetGlobalSolution() const; - void GetVecValues(const int v_type, PetscInt ni, const PetscInt ix[], - PetscScalar y[]) const; - PetscReal GetVecNormRHS(NormType nmtype= NORM_2); - PetscReal GetVecNormX(NormType nmtype= NORM_2); - - void RestoreLocalSolutionArray(PetscScalar *x_l); - void RestoreLocalRHSArray(PetscScalar *rhs_l); - void getLocalRowColumnSizes(int *m, int *n); - void getOwnerRange(int *start_r, int *end_r); - - int Size() const {return m_size;} - - void set_xVectorEntry(const int i, const double value); - void set_bVectorEntry(const int i, const double value); - void setArrayValues(int arr_idx, PetscInt ni,const PetscInt ix[], - const PetscScalar y[], InsertMode iora = ADD_VALUES); - - void add_xVectorEntry(const int i, const double value, InsertMode mode); - void add_bVectorEntry(const int i, const double value, InsertMode mode); - void addMatrixEntry(const int i, const int j, const double value); - void addMatrixEntries(const int m,const int idxm[], const int n, - const int idxn[],const PetscScalar v[]); - - void Initialize(); - - void zeroRows_in_Matrix(const int nrow, const PetscInt *rows); - void zeroMatrix() - { - MatZeroEntries(A); - } - - void set_rank_size(const int m_rank, const int size) - { - mpi_size = size; - rank = m_rank; - } - - PetscInt getStartRow() const {return i_start;} - PetscInt getEndRow() const {return i_end;} - - PetscInt getMPI_Size() const {return mpi_size;} - PetscInt getMPI_Rank() const {return rank;} - - void EQSV_Viewer(std::string file_name); - - private: - PETSc_Mat A; - PETSc_Vec b; - PETSc_Vec x; - KSP lsolver; - PC prec; - PetscInt i_start; - PetscInt i_end; - - PetscScalar *global_x; - - // Slover and preconditioner names, only for log - std::string sol_type; - std::string pc_type; - - PetscLogDouble time_elapsed; - - PetscInt m_size; - PetscInt m_size_loc; - float ltolerance; - // Number of nonzeros per row in DIAGONAL portion of - // local submatrix (same value is used for all local rows) - PetscInt d_nz; - // Number of nonzeros per row in the OFF-DIAGONAL portion of - // local submatrix (same value is used for all local rows). - PetscInt o_nz; - // Number of nonzeros per row (same for all rows) - PetscInt nz; - - int mpi_size; - int rank; - - void VectorCreate(PetscInt m); - void MatrixCreate(PetscInt m, PetscInt n); - - /*! - \brief collect local vectors - \param local_array local array - \param global_array global array - */ - void gatherLocalVectors(PetscScalar local_array[], - PetscScalar global_array[]); - - void UpdateSolutions(PetscScalar *u); - + PETScLinearSolver(const int size); + ~PETScLinearSolver(); + + void Config(const PetscReal tol, const PetscInt maxits, const KSPType lsol, const PCType prec_type, + const std::string& prefix = ""); + + void Init(const int* sparse_index = NULL); + + void Solver(); + void AssembleRHS_PETSc(); + void AssembleUnkowns_PETSc(); + void AssembleMatrixPETSc(const MatAssemblyType type = MAT_FINAL_ASSEMBLY); // MAT_FLUSH_ASSEMBLY + + void MappingSolution(); + + int GetLocalSolution(PetscScalar* x_l); + int GetLocalRHS(PetscScalar* rhs_l); + double* GetGlobalSolution() const; + void GetVecValues(const int v_type, PetscInt ni, const PetscInt ix[], PetscScalar y[]) const; + PetscReal GetVecNormRHS(NormType nmtype = NORM_2); + PetscReal GetVecNormX(NormType nmtype = NORM_2); + + void RestoreLocalSolutionArray(PetscScalar* x_l); + void RestoreLocalRHSArray(PetscScalar* rhs_l); + void getLocalRowColumnSizes(int* m, int* n); + void getOwnerRange(int* start_r, int* end_r); + + int Size() const { return m_size; } + void set_xVectorEntry(const int i, const double value); + void set_bVectorEntry(const int i, const double value); + void setArrayValues(int arr_idx, PetscInt ni, const PetscInt ix[], const PetscScalar y[], + InsertMode iora = ADD_VALUES); + + void add_xVectorEntry(const int i, const double value, InsertMode mode); + void add_bVectorEntry(const int i, const double value, InsertMode mode); + void addMatrixEntry(const int i, const int j, const double value); + void addMatrixEntries(const int m, const int idxm[], const int n, const int idxn[], const PetscScalar v[]); + + void Initialize(); + + void zeroRows_in_Matrix(const int nrow, const PetscInt* rows); + void zeroMatrix() { MatZeroEntries(A); } + void set_rank_size(const int m_rank, const int size) + { + mpi_size = size; + rank = m_rank; + } + + PetscInt getStartRow() const { return i_start; } + PetscInt getEndRow() const { return i_end; } + PetscInt getMPI_Size() const { return mpi_size; } + PetscInt getMPI_Rank() const { return rank; } + void EQSV_Viewer(std::string file_name); + +private: + PETSc_Mat A; + PETSc_Vec b; + PETSc_Vec x; + KSP lsolver; + PC prec; + PetscInt i_start; + PetscInt i_end; + + PetscScalar* global_x; + + // Slover and preconditioner names, only for log + std::string sol_type; + std::string pc_type; + + PetscLogDouble time_elapsed; + + PetscInt m_size; + PetscInt m_size_loc; + float ltolerance; + // Number of nonzeros per row in DIAGONAL portion of + // local submatrix (same value is used for all local rows) + PetscInt d_nz; + // Number of nonzeros per row in the OFF-DIAGONAL portion of + // local submatrix (same value is used for all local rows). + PetscInt o_nz; + // Number of nonzeros per row (same for all rows) + PetscInt nz; + + int mpi_size; + int rank; + + void VectorCreate(PetscInt m); + void MatrixCreate(PetscInt m, PetscInt n); + + /*! + \brief collect local vectors + \param local_array local array + \param global_array global array + */ + void gatherLocalVectors(PetscScalar local_array[], PetscScalar global_array[]); + + void UpdateSolutions(PetscScalar* u); }; - // extern std::vector EQS_Vector; +// extern std::vector EQS_Vector; } // end namespace #endif diff --git a/MathLib/Vector3.h b/MathLib/Vector3.h index b2f15c891..f4e23c9e3 100644 --- a/MathLib/Vector3.h +++ b/MathLib/Vector3.h @@ -34,46 +34,45 @@ class TemplateVector : public GEOLIB::TemplatePoint public: TemplateVector() : GEOLIB::TemplatePoint() {} TemplateVector(T x1, T x2, T x3) : GEOLIB::TemplatePoint(x1, x2, x3) {} - TemplateVector(const GEOLIB::TemplatePoint & rhs) : - GEOLIB::TemplatePoint(rhs[0], rhs[1], rhs[2]) - {} + TemplateVector(const GEOLIB::TemplatePoint& rhs) : GEOLIB::TemplatePoint(rhs[0], rhs[1], rhs[2]) {} /** constructs a vector from the gien points */ - TemplateVector(const GEOLIB::TemplatePoint &a, const GEOLIB::TemplatePoint &b) : - GEOLIB::TemplatePoint(b[0] - a[0], b[1] - a[1], b[2] - a[2]) - {} + TemplateVector(const GEOLIB::TemplatePoint& a, const GEOLIB::TemplatePoint& b) + : GEOLIB::TemplatePoint(b[0] - a[0], b[1] - a[1], b[2] - a[2]) + { + } ~TemplateVector() {} - // vector arithmetic - TemplateVector operator+(const TemplateVector & pV) const + TemplateVector operator+(const TemplateVector& pV) const { - return TemplateVector(this->_x[0] + pV[0], this->_x[1] + pV[1], this->_x[2] + pV[2] ); + return TemplateVector(this->_x[0] + pV[0], this->_x[1] + pV[1], this->_x[2] + pV[2]); } - TemplateVector operator-(const TemplateVector & pV) const + TemplateVector operator-(const TemplateVector& pV) const { - TemplateVector out( this->_x[0] - pV[0], this->_x[1] - pV[1], this->_x[2] - pV[2] ); + TemplateVector out(this->_x[0] - pV[0], this->_x[1] - pV[1], this->_x[2] - pV[2]); return out; } - TemplateVector operator-() const - { return TemplateVector (-this->x[0], -this->x[1], -this->x[2]); } - - TemplateVector& operator+=(const TemplateVector & pV) + TemplateVector operator-() const { return TemplateVector(-this->x[0], -this->x[1], -this->x[2]); } + TemplateVector& operator+=(const TemplateVector& pV) { - for (size_t i(0); i < 3; i++) this->_x[i] += pV[i]; + for (size_t i(0); i < 3; i++) + this->_x[i] += pV[i]; return *this; } TemplateVector& operator+=(const GEOLIB::TemplatePoint& pnt) { - for (size_t i(0); i < 3; i++) this->_x[i] += pnt[i]; + for (size_t i(0); i < 3; i++) + this->_x[i] += pnt[i]; return *this; } - TemplateVector& operator-=(const TemplateVector & pV) + TemplateVector& operator-=(const TemplateVector& pV) { - for (size_t i(0); i < 3; i++) this->_x[i] -= pV[i]; + for (size_t i(0); i < 3; i++) + this->_x[i] -= pV[i]; return *this; } @@ -84,81 +83,68 @@ class TemplateVector : public GEOLIB::TemplatePoint void setX(T value) { this->_x[0] = value; } void setY(T value) { this->_x[1] = value; } void setZ(T value) { this->_x[2] = value; } - /// Dot product with another vector - double Dot(const TemplateVector & pV) const + double Dot(const TemplateVector& pV) const { return this->_x[0] * pV[0] + this->_x[1] * pV[1] + this->_x[2] * pV[2]; } /// Cross product as the multiplication operator - TemplateVector operator*(const TemplateVector & pV) const + TemplateVector operator*(const TemplateVector& pV) const { - return TemplateVector ( - this->_x[1] * pV[2] - this->_x[2] * pV[1], - this->_x[2] * pV[0] - this->_x[0] * pV[2], - this->_x[0] * pV[1] - this->_x[1] * pV[0] ); + return TemplateVector(this->_x[1] * pV[2] - this->_x[2] * pV[1], + this->_x[2] * pV[0] - this->_x[0] * pV[2], + this->_x[0] * pV[1] - this->_x[1] * pV[0]); } /// Cross product with another vector - TemplateVector Cross( const TemplateVector & pV ) const - { return *this * pV; } - - friend double Dot( const TemplateVector & p1, const TemplateVector & p2 ) - { return p1.Dot(p2); } - - friend TemplateVector Cross( const TemplateVector & p1, const TemplateVector & p2 ) - { return p1 * p2; } - - TemplateVector operator*(double pR) const // * a scalar + TemplateVector Cross(const TemplateVector& pV) const { return *this * pV; } + friend double Dot(const TemplateVector& p1, const TemplateVector& p2) { return p1.Dot(p2); } + friend TemplateVector Cross(const TemplateVector& p1, const TemplateVector& p2) { return p1 * p2; } + TemplateVector operator*(double pR) const // * a scalar { return TemplateVector(this->x[0] * pR, this->x[1] * pR, this->x[2] * pR); } - friend TemplateVector operator*(double pR, const TemplateVector & pV) + friend TemplateVector operator*(double pR, const TemplateVector& pV) { - return TemplateVector ( pV[0] * pR, pV[1] * pR, pV[2] * pR ); + return TemplateVector(pV[0] * pR, pV[1] * pR, pV[2] * pR); } TemplateVector& operator*=(double pR) { - for (size_t i(0); i < 3; i++) this->_x[i] *= pR; + for (size_t i(0); i < 3; i++) + this->_x[i] *= pR; return *this; } /// Returns the squared length - double LenSqr(void) const - { - return scpr (this->getData (), this->getData (), 3); - } - + double LenSqr(void) const { return scpr(this->getData(), this->getData(), 3); } /// Returns the length - double Length(void) const - { return sqrt(LenSqr()); } - + double Length(void) const { return sqrt(LenSqr()); } /// Projection (component of *this parallel to pV). /// Note: component perpendicular to pV is: *this - Proj(pV) - TemplateVector Proj(const TemplateVector & pV) - { TemplateVector out( pV * (this->Dot(pV) / pV.LenSqr()) ); - return out; } + TemplateVector Proj(const TemplateVector& pV) + { + TemplateVector out(pV * (this->Dot(pV) / pV.LenSqr())); + return out; + } /// Cosine of the angle between two vectors: - double CosAng(const TemplateVector& pV) - { return this->Dot(pV) / (Length() * pV.Length()); } - + double CosAng(const TemplateVector& pV) { return this->Dot(pV) / (Length() * pV.Length()); } /// Comparison if equal - bool operator==( const TemplateVector & pV) const + bool operator==(const TemplateVector& pV) const { - return std::fabs(this->_x[0] - pV[0]) < sqrt(std::numeric_limits::min()) && - std::fabs(this->_x[1] - pV[1]) < sqrt(std::numeric_limits::min()) && - std::fabs(this->_x[2] - pV[2]) < sqrt(std::numeric_limits::min()); + return std::fabs(this->_x[0] - pV[0]) < sqrt(std::numeric_limits::min()) + && std::fabs(this->_x[1] - pV[1]) < sqrt(std::numeric_limits::min()) + && std::fabs(this->_x[2] - pV[2]) < sqrt(std::numeric_limits::min()); } /// Comparison if not equal - bool operator!=( const TemplateVector & pV) const + bool operator!=(const TemplateVector& pV) const { return !(pV == this); -// this->_x[0]!=pV[0] || this->_x[1]!=pV[1] || this->_x[2]!=pV[2]; + // this->_x[0]!=pV[0] || this->_x[1]!=pV[1] || this->_x[2]!=pV[2]; } }; diff --git a/MathLib/max.h b/MathLib/max.h index 04931298b..15772d147 100644 --- a/MathLib/max.h +++ b/MathLib/max.h @@ -16,7 +16,8 @@ /** * max returns the maximum of its arguments */ -template T max(const T& arg0, const T& arg1) +template +T max(const T& arg0, const T& arg1) { if (arg0 < arg1) return arg1; diff --git a/OGS/ogs_display.cpp b/OGS/ogs_display.cpp index 9a5918514..f57edc15f 100644 --- a/OGS/ogs_display.cpp +++ b/OGS/ogs_display.cpp @@ -33,7 +33,7 @@ 01/2010 NW Automatic centering of the version information */ /**************************************************************************/ -void DisplayStartMsg ( void ) +void DisplayStartMsg(void) { int i, pad_len; char buf[128]; @@ -54,7 +54,7 @@ void DisplayStartMsg ( void ) printf(" ## German Research Centre for Geosciences (GFZ) ##\n"); printf(" ## ##\n"); - //align the version information to center of the line + // align the version information to center of the line printf(" ## "); sprintf(buf, "Version %s Date %s", BuildInfo::OGS_VERSION.c_str(), BuildInfo::OGS_DATE.c_str()); pad_len = 45 - (int)strlen(buf); @@ -86,7 +86,7 @@ void DisplayStartMsg ( void ) 03/1994 MSR Erste Version */ /**************************************************************************/ -void DisplayEndMsg ( void ) +void DisplayEndMsg(void) { printf("\n Programm beendet!\n\n\n"); } diff --git a/OGS/ogs_display.h b/OGS/ogs_display.h index 2df6c243c..a82d76c8b 100644 --- a/OGS/ogs_display.h +++ b/OGS/ogs_display.h @@ -14,8 +14,8 @@ /* Andere oeffentlich benutzte Module */ /* Deklarationen */ -extern void DisplayStartMsg ( void ); +extern void DisplayStartMsg(void); /* Gibt Eroeffnungsbildschirm aus */ -extern void DisplayEndMsg ( void ); +extern void DisplayEndMsg(void); /* Schreibt Laufzeitmeldung auf Standardausgabe */ #endif diff --git a/OGS/rf.cpp b/OGS/rf.cpp old mode 100755 new mode 100644 index 8e192f394..5f8c9dd9b --- a/OGS/rf.cpp +++ b/OGS/rf.cpp @@ -28,8 +28,8 @@ * */ #include "BuildInfo.h" -#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || \ - defined(USE_MPI_GEMS) || defined(USE_MPI_KRC) +#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_GEMS) \ + || defined(USE_MPI_KRC) #include "par_ddc.h" #include #endif @@ -47,7 +47,7 @@ /* Benutzte Module */ #include "break.h" #include "timer.h" -//16.12.2008. WW #include "rf_apl.h" +// 16.12.2008. WW #include "rf_apl.h" #include "FileTools.h" #include "files0.h" #ifdef SUPERCOMPUTER @@ -59,19 +59,18 @@ #include "problem.h" /* Deklarationen */ -int main ( int argc, char* argv[] ); -void ShowSwitches ( void ); +int main(int argc, char* argv[]); +void ShowSwitches(void); // LB,string FileName; //WW // LB,string FilePath; //23.02.2009. WW // ------ 12.09.2007 WW: -#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || \ - defined(USE_MPI_GEMS) || defined(USE_MPI_KRC) +#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_GEMS) \ + || defined(USE_MPI_KRC) double elapsed_time_mpi; #include "SplitMPI_Communicator.h" // ------ #endif - // Use PETSc. WW #ifdef USE_PETSC #include "petscksp.h" @@ -83,7 +82,6 @@ double elapsed_time_mpi; // declaration of defaultOutputPath #include "rf_out_new.h" - /* Definitionen */ /**************************************************************************/ @@ -104,30 +102,31 @@ double elapsed_time_mpi; 08/1999 OK RF-FEM Applikation */ /**************************************************************************/ -int main ( int argc, char* argv[] ) +int main(int argc, char* argv[]) { /* parse command line arguments */ std::string anArg; std::string modelRoot; -#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || \ - defined(USE_MPI_GEMS) || defined(USE_MPI_KRC) - int nb_ddc=0; //number of cores for DDC related processes +#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_GEMS) \ + || defined(USE_MPI_KRC) + int nb_ddc = 0; // number of cores for DDC related processes #endif - for( int i = 1; i < argc; i++ ) + for (int i = 1; i < argc; i++) { - anArg = std::string( argv[i] ); - if( anArg == "--help" || anArg == "-h") + anArg = std::string(argv[i]); + if (anArg == "--help" || anArg == "-h") { std::cout << "Usage: ogs [MODEL_ROOT] [OPTIONS]\n" << "Where OPTIONS are:\n" << " -h [--help] print this message and exit\n" << " -b [--build-info] print build info and exit\n" << " --output-directory DIR put output files into DIR\n" - << " --version print ogs version and exit" << "\n"; + << " --version print ogs version and exit" + << "\n"; continue; } - if( anArg == "--build-info" || anArg == "-b" ) + if (anArg == "--build-info" || anArg == "-b") { std::cout << "ogs version: " << BuildInfo::OGS_VERSION << "\n" << "ogs date: " << BuildInfo::OGS_DATE << "\n"; @@ -135,87 +134,89 @@ int main ( int argc, char* argv[] ) std::cout << "build timestamp: " << BuildInfo::BUILD_TIMESTAMP << "\n"; continue; } - if( anArg == "--version" ) + if (anArg == "--version") { std::cout << BuildInfo::OGS_VERSION << "\n"; continue; } - if( anArg == "--model-root" || anArg == "-m" ) + if (anArg == "--model-root" || anArg == "-m") { - if (i+1 >= argc) { + if (i + 1 >= argc) + { std::cerr << "Error: Parameter " << anArg << " needs an additional argument" << std::endl; std::exit(EXIT_FAILURE); } - modelRoot = std::string( argv[++i] ); + modelRoot = std::string(argv[++i]); continue; } if (anArg == "--output-directory") { - if (i+1 >= argc) { + if (i + 1 >= argc) + { std::cerr << "Error: Parameter " << anArg << " needs an additional argument" << std::endl; std::exit(EXIT_FAILURE); } std::string path = argv[++i]; - if (! path.empty()) defaultOutputPath = path; + if (!path.empty()) + defaultOutputPath = path; continue; } -#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || \ - defined(USE_MPI_GEMS) || defined(USE_MPI_KRC) +#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_GEMS) \ + || defined(USE_MPI_KRC) std::string decompositions; - if( anArg == "--domain-decomposition" || anArg == "-ddc" ) + if (anArg == "--domain-decomposition" || anArg == "-ddc") { - decompositions = std::string( argv[++i] ); + decompositions = std::string(argv[++i]); nb_ddc = atoi(decompositions.c_str()); continue; } #endif // anything left over must be the model root, unless already found - if ( modelRoot == "" ) - modelRoot = std::string( argv[i] ); + if (modelRoot == "") + modelRoot = std::string(argv[i]); } // end of parse argc loop - if( argc > 1 && modelRoot == "" ) // non-interactive mode and no model given - exit(0); // e.g. just wanted the build info + if (argc > 1 && modelRoot == "") // non-interactive mode and no model given + exit(0); // e.g. just wanted the build info std::string solver_pkg_name = BuildInfo::SOLVER_PACKAGE_NAME; // No default linear solver package is in use. - if(solver_pkg_name.find("Default") == std::string::npos) + if (solver_pkg_name.find("Default") == std::string::npos) { - std::cout << "\nWarning: " << solver_pkg_name - << " other than the OGS default one is in use." < 0) -// bufstd = malloc(bsize); + // according to documentation the buffer is flushed when full. + // If we have a lot of output, increasing buffer is usefull. + if (bsize > 0) + // bufstd = malloc(bsize); setvbuf(stdout, buf, _IOFBF, bsize); - //********************************************************************** +//********************************************************************** #endif /*---------- MPI Initialization ----------------------------------*/ -#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || \ - defined(USE_MPI_GEMS) || defined(USE_MPI_KRC) +#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_GEMS) \ + || defined(USE_MPI_KRC) printf("Before MPI_Init\n"); #if defined(USE_MPI_GEMS) int prov; - MPI_Init_thread(&argc,&argv,MPI_THREAD_FUNNELED, &prov); + MPI_Init_thread(&argc, &argv, MPI_THREAD_FUNNELED, &prov); #else - MPI_Init(&argc,&argv); + MPI_Init(&argc, &argv); #endif - MPI_Barrier (MPI_COMM_WORLD); // 12.09.2007 WW + MPI_Barrier(MPI_COMM_WORLD); // 12.09.2007 WW elapsed_time_mpi = -MPI_Wtime(); // 12.09.2007 WW bool splitcomm_flag; int np; @@ -225,18 +226,17 @@ int main ( int argc, char* argv[] ) #endif /*---------- MPI Initialization ----------------------------------*/ - #ifdef USE_PETSC int rank, r_size; - PetscLogDouble v1,v2; + PetscLogDouble v1, v2; char help[] = "OGS with PETSc \n"; - //PetscInitialize(argc, argv, help); - PetscInitialize(&argc,&argv,(char *)0,help); - //kg44 quick fix to compile PETSC with version PETSCV3.4 + // PetscInitialize(argc, argv, help); + PetscInitialize(&argc, &argv, (char*)0, help); +// kg44 quick fix to compile PETSC with version PETSCV3.4 #ifdef USEPETSC34 - PetscTime(&v1); + PetscTime(&v1); #else - PetscGetTime(&v1); + PetscGetTime(&v1); #endif MPI_Comm_rank(PETSC_COMM_WORLD, &rank); MPI_Comm_size(PETSC_COMM_WORLD, &r_size); @@ -246,24 +246,24 @@ int main ( int argc, char* argv[] ) /*---------- LIS solver -----------------------------------------*/ #ifdef LIS - //Initialization of the lis solver. + // Initialization of the lis solver. lis_initialize(&argc, &argv); #endif /*========================================================================*/ /* Kommunikation mit Betriebssystem */ - /* Timer fuer Gesamtzeit starten */ +/* Timer fuer Gesamtzeit starten */ #ifdef TESTTIME TStartTimer(0); #endif - /* Intro ausgeben */ -#if defined(USE_MPI) //WW - if(myrank == 0) +/* Intro ausgeben */ +#if defined(USE_MPI) // WW + if (myrank == 0) #endif #ifdef USE_PETSC - if(rank == 0 ) + if (rank == 0) #endif - DisplayStartMsg(); + DisplayStartMsg(); /* Speicherverwaltung initialisieren */ if (!InitMemoryTest()) { @@ -271,39 +271,40 @@ int main ( int argc, char* argv[] ) DisplayErrorMsg(" Programm vorzeitig beendet!"); return 1; // LB changed from 0 to 1 because 0 is indicating success } - if( argc == 1 ) // interactive mode + if (argc == 1) // interactive mode dateiname = ReadString(); - else // non-interactive mode + else // non-interactive mode { - if ( argc == 2 ) // a model root was supplied + if (argc == 2) // a model root was supplied { - dateiname = (char*) Malloc((int)strlen(argv[1]) + 1); - dateiname = strcpy(dateiname,argv[1]); + dateiname = (char*)Malloc((int)strlen(argv[1]) + 1); + dateiname = strcpy(dateiname, argv[1]); } - else // several args supplied - if( modelRoot != "") + else // several args supplied + if (modelRoot != "") { - dateiname = (char*) Malloc( (int) modelRoot.size() + 1 ); - dateiname = strcpy( dateiname, modelRoot.c_str() ); + dateiname = (char*)Malloc((int)modelRoot.size() + 1); + dateiname = strcpy(dateiname, modelRoot.c_str()); } DisplayMsgLn(dateiname); } - //WW DisplayMsgLn(""); - //WW DisplayMsgLn(""); + // WW DisplayMsgLn(""); + // WW DisplayMsgLn(""); // ----------23.02.2009. WW----------------- // LB Check if file exists std::string tmpFilename = dateiname; tmpFilename.append(".pcs"); - if(!IsFileExisting(tmpFilename)) + if (!IsFileExisting(tmpFilename)) { std::cout << " Error: Cannot find file " << dateiname << "\n"; return 1; } // If no option is given, output files are placed in the same directory as the input files - if (defaultOutputPath.empty()) defaultOutputPath = pathDirname(std::string(dateiname)); + if (defaultOutputPath.empty()) + defaultOutputPath = pathDirname(std::string(dateiname)); FileName = dateiname; size_t indexChWin, indexChLinux; @@ -311,32 +312,36 @@ int main ( int argc, char* argv[] ) indexChWin = FileName.find_last_of('\\'); indexChLinux = FileName.find_last_of('/'); // - if(indexChWin != std::string::npos) - FilePath = FileName.substr(0,indexChWin) + "\\"; - else if(indexChLinux != std::string::npos) - FilePath = FileName.substr(0,indexChLinux) + "/"; + if (indexChWin != std::string::npos) + FilePath = FileName.substr(0, indexChWin) + "\\"; + else if (indexChLinux != std::string::npos) + FilePath = FileName.substr(0, indexChLinux) + "/"; // ---------------------------WW Problem* aproblem = new Problem(dateiname); #ifdef USE_PETSC aproblem->setRankandSize(rank, r_size); #endif -#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_GEMS) || defined(USE_MPI_KRC) +#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_GEMS) \ + || defined(USE_MPI_KRC) aproblem->setRankandSize(myrank, mysize); if (myrank != MPI_UNDEFINED) { #endif - aproblem->Euler_TimeDiscretize(); - delete aproblem; - aproblem = NULL; -#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_GEMS) || defined(USE_MPI_KRC) + aproblem->Euler_TimeDiscretize(); + delete aproblem; + aproblem = NULL; +#if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_GEMS) \ + || defined(USE_MPI_KRC) } - //sending killing signals to ranks of group_IPQC, only when the group exists - if (splitcomm_flag == true){ -#ifdef OGS_FEM_IPQC + // sending killing signals to ranks of group_IPQC, only when the group exists + if (splitcomm_flag == true) + { +#ifdef OGS_FEM_IPQC int signal = -1, rank_IPQC, mysize_IPQC = np - nb_ddc; - for (int i=0; i< mysize_IPQC; i++){ + for (int i = 0; i < mysize_IPQC; i++) + { rank_IPQC = mysize + i; MPI_Send(&signal, 1, MPI_INT, rank_IPQC, 0, MPI_COMM_WORLD); } @@ -345,25 +350,24 @@ int main ( int argc, char* argv[] ) #endif - - if(ClockTimeVec.size()>0) - ClockTimeVec[0]->PrintTimes(); //CB time + if (ClockTimeVec.size() > 0) + ClockTimeVec[0]->PrintTimes(); // CB time DestroyClockTime(); #ifdef TESTTIME #if defined(USE_MPI) - if(myrank == 0) + if (myrank == 0) #endif #if defined(USE_PETSC) - if(rank == 0) + if (rank == 0) #endif - std::cout << "Simulation time: " << TGetTimer(0) << "s" << "\n"; + std::cout << "Simulation time: " << TGetTimer(0) << "s" + << "\n"; #endif - /* Abspann ausgeben */ +/* Abspann ausgeben */ /*--------- MPI Finalize ------------------*/ #if defined(USE_MPI) || defined(USE_MPI_PARPROC) || defined(USE_MPI_REGSOIL) || defined(USE_MPI_KRC) elapsed_time_mpi += MPI_Wtime(); // 12.09.2007 WW - std::cout << "\n *** Total CPU time of parallel modeling: " << elapsed_time_mpi << - "\n"; //WW + std::cout << "\n *** Total CPU time of parallel modeling: " << elapsed_time_mpi << "\n"; // WW // Count CPU time of post time loop WW MPI_Finalize(); #endif @@ -372,22 +376,21 @@ int main ( int argc, char* argv[] ) #ifdef LIS lis_finalize(); #endif -/*--------- LIS Finalize ------------------*/ + /*--------- LIS Finalize ------------------*/ free(dateiname); #ifdef USE_PETSC - //kg44 quick fix to compile PETSC with version PETSCV3.4 +// kg44 quick fix to compile PETSC with version PETSCV3.4 #ifdef USEPETSC34 - PetscTime(&v2); + PetscTime(&v2); #else - PetscGetTime(&v2); + PetscGetTime(&v2); #endif + PetscPrintf(PETSC_COMM_WORLD, "\t\n>>Total elapsed time by using PETSC:%f s\n", v2 - v1); - PetscPrintf(PETSC_COMM_WORLD,"\t\n>>Total elapsed time by using PETSC:%f s\n",v2-v1); - - PetscFinalize(); + PetscFinalize(); #endif return 0; diff --git a/UTL/GIS2FEM/main.cpp b/UTL/GIS2FEM/main.cpp index be0dceead..32e7eedec 100644 --- a/UTL/GIS2FEM/main.cpp +++ b/UTL/GIS2FEM/main.cpp @@ -21,126 +21,124 @@ using namespace MeshLib; void DisplayMessage() { - string _infor = - "\nData pre-process tool for the finite element analysis of subsurface flow problems.\n " - "By Wenqing Wang\n\n" - "Command: fem_toolkits -opt [Option] [File name with extension]\n" - "Option:\n" - " 1: Generation OGS Neumman BC from the recharge data in GIS raster file,\n" - " 2: Top surface integration for 3D mesh,\n" - " 3: Convert GIS raster cells into FE mesh\n"; - cout<<_infor<1) - { - for(int i=1; i>s_buff; - if(s_buff.find("-opt")!=string::npos) - { - ss >> opt; - } - if( s_buff[0] != '-') - { - file_name = s_buff; - } - } - ss.clear(); - - } - - int option; - ss.str(opt); - ss >> option; - ss.clear(); - - basic_string ::size_type indexChWin, indexChLinux; + string s_buff; + string opt; + stringstream ss; + string file_name; + if (argc > 1) + { + for (int i = 1; i < argc; i++) + { + s_buff = argv[i]; + if (s_buff.find("--version") != string::npos) + { + DisplayMessage(); + exit(0); + } + + if (s_buff.find("-opt") != string::npos) + { + opt = argv[i + 1]; + } + + if (!(s_buff.find("-") != string::npos || s_buff.find("--") != string::npos)) + { + file_name = s_buff; + } + } + } + else // terminal + { + DisplayMessage(); + cout << "\nInput options and file name (non extension):\n "; + + getline(cin, s_buff); + ss.str(s_buff); + while (!ss.eof()) + { + ss >> s_buff; + if (s_buff.find("-opt") != string::npos) + { + ss >> opt; + } + if (s_buff[0] != '-') + { + file_name = s_buff; + } + } + ss.clear(); + } + + int option; + ss.str(opt); + ss >> option; + ss.clear(); + + basic_string::size_type indexChWin, indexChLinux; indexChWin = indexChLinux = 0; indexChWin = file_name.find_last_of('\\'); indexChLinux = file_name.find_last_of('/'); // - string file_path; - if(indexChWin != string::npos) - file_path = file_name.substr(0,indexChWin) + "\\"; - else if(indexChLinux != string::npos) - file_path = file_name.substr(0,indexChLinux) + "/"; + string file_path; + if (indexChWin != string::npos) + file_path = file_name.substr(0, indexChWin) + "\\"; + else if (indexChLinux != string::npos) + file_path = file_name.substr(0, indexChLinux) + "/"; CFEMesh* a_mesh = NULL; - if(option != 3) + if (option != 3) { - string fname = file_name + ".msh"; + string fname = file_name + ".msh"; ifstream is_mesh(fname.c_str(), ios::in); std::getline(is_mesh, s_buff); - if(s_buff.find("#FEM_MSH") != std::string::npos) + if (s_buff.find("#FEM_MSH") != std::string::npos) { - a_mesh = new CFEMesh(NULL, &file_name); - a_mesh->Read(&is_mesh); + a_mesh = new CFEMesh(NULL, &file_name); + a_mesh->Read(&is_mesh); } else { - std::cout<<"Cannot open mesh file "<< fname << endl; - return EXIT_FAILURE; + std::cout << "Cannot open mesh file " << fname << endl; + return EXIT_FAILURE; } } - switch(option) + switch (option) { - case 1: - a_mesh->mHM2NeumannBC(); - break; - case 2: - a_mesh->TopSurfaceIntegration(); - break; - case 3: - a_mesh = new CFEMesh(); - a_mesh->ConvertShapeCells(file_name + ".asc"); - break; - default: - break; + case 1: + a_mesh->mHM2NeumannBC(); + break; + case 2: + a_mesh->TopSurfaceIntegration(); + break; + case 3: + a_mesh = new CFEMesh(); + a_mesh->ConvertShapeCells(file_name + ".asc"); + break; + default: + break; } - if(a_mesh) + if (a_mesh) { - delete a_mesh; - a_mesh = NULL; + delete a_mesh; + a_mesh = NULL; } return EXIT_SUCCESS; } diff --git a/UTL/GIS2FEM/misc.cpp b/UTL/GIS2FEM/misc.cpp index 3d3d3eae5..ba14af497 100644 --- a/UTL/GIS2FEM/misc.cpp +++ b/UTL/GIS2FEM/misc.cpp @@ -15,35 +15,35 @@ using namespace std; -void writeOGSMesh(const MeshLib::CFEMesh &mesh, const std::string file_base_name) +void writeOGSMesh(const MeshLib::CFEMesh& mesh, const std::string file_base_name) { - const string fname = file_base_name + "_mesh_converted_from_GIS_shape_data.msh"; + const string fname = file_base_name + "_mesh_converted_from_GIS_shape_data.msh"; ofstream os(fname.c_str(), ios::trunc); - os.setf(ios::scientific, ios::floatfield); - setw(14); - os.precision(10); + os.setf(ios::scientific, ios::floatfield); + setw(14); + os.precision(10); - os << "#FEM_MSH \n $PCS_TYPE\n NO_PCS\n $NODES" <getData(); - os<< n_ptr->GetIndex() <<" "<getData(); + os << n_ptr->GetIndex() << " " << xyz_ptr[0] << " " << xyz_ptr[1] << " " << xyz_ptr[2] << "\n"; } - os << "$ELEMENTS" <WriteIndex(os); - } + MeshLib::CElem* e_ptr = mesh.ele_vector[i]; + e_ptr->WriteIndex(os); + } - os << "#STOP" < -namespace MeshLib +namespace MeshLib { - class CFEMesh; +class CFEMesh; } -void writeOGSMesh(const MeshLib::CFEMesh &mesh, const std::string file_base_name); +void writeOGSMesh(const MeshLib::CFEMesh& mesh, const std::string file_base_name); #endif diff --git a/UTL/MSHGEOTOOLS/ModifyMeshProperties.cpp b/UTL/MSHGEOTOOLS/ModifyMeshProperties.cpp index 378d83e4a..5fad57cb7 100644 --- a/UTL/MSHGEOTOOLS/ModifyMeshProperties.cpp +++ b/UTL/MSHGEOTOOLS/ModifyMeshProperties.cpp @@ -39,100 +39,105 @@ namespace MeshLib { -ModifyMeshProperties::ModifyMeshProperties(CFEMesh* msh) : - _mesh (msh) -{} +ModifyMeshProperties::ModifyMeshProperties(CFEMesh* msh) : _mesh(msh) +{ +} ModifyMeshProperties::~ModifyMeshProperties() -{} +{ +} -void ModifyMeshProperties::setMaterial (const GEOLIB::Polygon& polygon, size_t mat_id) +void ModifyMeshProperties::setMaterial(const GEOLIB::Polygon& polygon, size_t mat_id) { // get all nodes of mesh - const std::vector& msh_nodes (_mesh->getNodeVector()); + const std::vector& msh_nodes(_mesh->getNodeVector()); // *** rotate polygon to xy_plane // 1 copy all points std::vector polygon_points; for (size_t k(0); k < polygon.getNumberOfPoints(); k++) - polygon_points.push_back (new GEOLIB::Point (*(polygon[k]))); + polygon_points.push_back(new GEOLIB::Point(*(polygon[k]))); // 2 rotate points MathLib::Vector plane_normal_polygon(0.0, 0.0, 0.0); - double d_polygon (0.0); - MathLib::getNewellPlane (polygon_points, plane_normal_polygon, d_polygon); + double d_polygon(0.0); + MathLib::getNewellPlane(polygon_points, plane_normal_polygon, d_polygon); -// std::cout << "plane normal: " << plane_normal_polygon << std::endl; - MathLib::Vector tmp_plane_normal_polygon(plane_normal_polygon); //NW need to keep plane_normal_polygon for later use + // std::cout << "plane normal: " << plane_normal_polygon << std::endl; + MathLib::Vector tmp_plane_normal_polygon(plane_normal_polygon); // NW need to keep plane_normal_polygon for later + // use MathLib::rotatePointsToXY(tmp_plane_normal_polygon, polygon_points); // 3 create new polygon - GEOLIB::Polyline rot_polyline (polygon_points); + GEOLIB::Polyline rot_polyline(polygon_points); for (size_t k(0); k < polygon.getNumberOfPoints(); k++) - rot_polyline.addPoint (k); - rot_polyline.addPoint (0); - GEOLIB::Polygon rot_polygon (rot_polyline); - -// std::cout << "Polygon: " << std::endl; -// for (size_t k(0); k mesh_nodes_as_points; for (size_t j(0); j < msh_nodes.size(); j++) - mesh_nodes_as_points.push_back (new GEOLIB::Point (msh_nodes[j]->getData())); + mesh_nodes_as_points.push_back(new GEOLIB::Point(msh_nodes[j]->getData())); // 2 rotate the Points MathLib::rotatePointsToXY(plane_normal_polygon, mesh_nodes_as_points); // get all elements of mesh - const std::vector& msh_elem (_mesh->getElementVector()); + const std::vector& msh_elem(_mesh->getElementVector()); // *** perform search and modify mesh - const size_t msh_elem_size (msh_elem.size()); + const size_t msh_elem_size(msh_elem.size()); for (size_t j(0); j < msh_elem_size; j++) { // indices of nodes of the j-th element - const Math_Group::vec& nodes_indices (msh_elem[j]->GetNodeIndeces ()); -// size_t k; -// for (k = 0; ksetPatchIndex (mat_id); -// } - -// size_t cnt (0); -// for (k = 0; k < nodes_indices.Size(); k++) -// if (rot_polygon.isPntInPolygon(*(mesh_nodes_as_points[nodes_indices[k]]))) -// cnt++; -// -// if (cnt >= 2) -// msh_elem[j]->setPatchIndex (mat_id); + const Math_Group::vec& nodes_indices(msh_elem[j]->GetNodeIndeces()); + // size_t k; + // for (k = 0; ksetPatchIndex (mat_id); + // } + + // size_t cnt (0); + // for (k = 0; k < nodes_indices.Size(); k++) + // if (rot_polygon.isPntInPolygon(*(mesh_nodes_as_points[nodes_indices[k]]))) + // cnt++; + // + // if (cnt >= 2) + // msh_elem[j]->setPatchIndex (mat_id); double center[3] = {0.0, 0.0, 0.0}; - for (size_t k(0); k < nodes_indices.Size(); k++) { + for (size_t k(0); k < nodes_indices.Size(); k++) + { center[0] += (*(mesh_nodes_as_points[nodes_indices[k]]))[0]; center[1] += (*(mesh_nodes_as_points[nodes_indices[k]]))[1]; -// center[2] += (*(mesh_nodes_as_points[nodes_indices[k]]))[2]; + // center[2] += (*(mesh_nodes_as_points[nodes_indices[k]]))[2]; } center[0] /= nodes_indices.Size(); center[1] /= nodes_indices.Size(); -// center[2] /= nodes_indices.Size(); + // center[2] /= nodes_indices.Size(); -// std::cout << "center of element " << j << ": " << center[0] << ", " << center[1] << ", " << center[2] << std::endl; + // std::cout << "center of element " << j << ": " << center[0] << ", " << center[1] << ", " << center[2] << + // std::endl; - if (rot_polygon.isPntInPolygon(center[0], center[1], center[2])) { - msh_elem[j]->setPatchIndex (mat_id); + if (rot_polygon.isPntInPolygon(center[0], center[1], center[2])) + { + msh_elem[j]->setPatchIndex(mat_id); } } @@ -142,7 +147,7 @@ void ModifyMeshProperties::setMaterial (const GEOLIB::Polygon& polygon, size_t m delete mesh_nodes_as_points[j]; } -void ModifyMeshProperties::substituteMaterialID (GEOLIB::Polygon const& polygon, size_t old_mat_id, size_t new_mat_id) +void ModifyMeshProperties::substituteMaterialID(GEOLIB::Polygon const& polygon, size_t old_mat_id, size_t new_mat_id) { MeshLib::ExtractMeshNodes mesh_node_extractor(_mesh); std::vector mesh_node_ids; @@ -150,39 +155,47 @@ void ModifyMeshProperties::substituteMaterialID (GEOLIB::Polygon const& polygon, const size_t n_mesh_node_ids(mesh_node_ids.size()); std::vector perm(n_mesh_node_ids); // init permutation for sorting - for (size_t k(0); k (mesh_node_ids, 0, n_mesh_node_ids, perm); + Quicksort(mesh_node_ids, 0, n_mesh_node_ids, perm); -//#ifndef NDEBUG -// std::ofstream test_out ("Points.gli"); -// test_out << "#POINTS" << std::endl; -// FileIO::OGSMeshIO mesh_io; -// mesh_io.setMesh(_mesh); -// mesh_io.writeMeshNodesAsGLIPnts(mesh_node_ids, test_out); -// test_out << "#STOP" << std::endl; -//#endif + //#ifndef NDEBUG + // std::ofstream test_out ("Points.gli"); + // test_out << "#POINTS" << std::endl; + // FileIO::OGSMeshIO mesh_io; + // mesh_io.setMesh(_mesh); + // mesh_io.writeMeshNodesAsGLIPnts(mesh_node_ids, test_out); + // test_out << "#STOP" << std::endl; + //#endif // get all nodes of the mesh - const std::vector& mesh_nodes (_mesh->getNodeVector()); + const std::vector& mesh_nodes(_mesh->getNodeVector()); // get all elements of the mesh - const std::vector& mesh_elements (_mesh->getElementVector()); + const std::vector& mesh_elements(_mesh->getElementVector()); - for (size_t k(0); k const& connected_element_ids (mesh_nodes[mesh_node_ids[k]]->getConnectedElementIDs()); - for (size_t j(0); jGetPatchIndex() == old_mat_id) { + for (size_t k(0); k < n_mesh_node_ids; k++) + { + std::vector const& connected_element_ids(mesh_nodes[mesh_node_ids[k]]->getConnectedElementIDs()); + for (size_t j(0); j < connected_element_ids.size(); j++) + { + if (mesh_elements[connected_element_ids[j]]->GetPatchIndex() == old_mat_id) + { std::vector connected_nodes; // check if all nodes of element are in the mesh_node_ids vector mesh_elements[connected_element_ids[j]]->getNodeIndices(connected_nodes); bool all_found(true); const size_t n_connected_nodes(connected_nodes.size()); - for (size_t i(0); i::max()) { + for (size_t i(0); i < n_connected_nodes && all_found; i++) + { + if (searchElement(connected_nodes[i], 0, n_mesh_node_ids, mesh_node_ids) + == std::numeric_limits::max()) + { all_found = false; } } - if (all_found) { + if (all_found) + { mesh_elements[connected_element_ids[j]]->setPatchIndex(new_mat_id); } } diff --git a/UTL/MSHGEOTOOLS/ModifyMeshProperties.h b/UTL/MSHGEOTOOLS/ModifyMeshProperties.h index a15832515..a4b88071e 100644 --- a/UTL/MSHGEOTOOLS/ModifyMeshProperties.h +++ b/UTL/MSHGEOTOOLS/ModifyMeshProperties.h @@ -25,7 +25,7 @@ class ModifyMeshProperties ModifyMeshProperties(CFEMesh* msh); virtual ~ModifyMeshProperties(); - void setMaterial (const GEOLIB::Polygon& polygon, size_t mat_id); + void setMaterial(const GEOLIB::Polygon& polygon, size_t mat_id); /** * Method substitutes material ids within the given volume. The volume is described * by three surfaces, the first and second surfaces are the parts of bottom and the top @@ -36,7 +36,7 @@ class ModifyMeshProperties * @param old_mat_id [input] the old material id (which is changed) * @param new_mat_id [input] the value of the new material id that is set */ - void substituteMaterialID (GEOLIB::Polygon const& polygon, size_t old_mat_id, size_t new_mat_id); + void substituteMaterialID(GEOLIB::Polygon const& polygon, size_t old_mat_id, size_t new_mat_id); private: CFEMesh* _mesh; diff --git a/UTL/MSHGEOTOOLS/filterMeshNodes.cpp b/UTL/MSHGEOTOOLS/filterMeshNodes.cpp index 97b549880..a96700322 100644 --- a/UTL/MSHGEOTOOLS/filterMeshNodes.cpp +++ b/UTL/MSHGEOTOOLS/filterMeshNodes.cpp @@ -28,7 +28,7 @@ Problem* aproblem = NULL; #include "binarySearch.h" #include "quicksort.h" -int main (int argc, char* argv[]) +int main(int argc, char* argv[]) { if (argc < 7) { @@ -40,22 +40,22 @@ int main (int argc, char* argv[]) return -1; } - std::string tmp (argv[1]); - if (tmp.find ("--nodes-with-area") == std::string::npos) + std::string tmp(argv[1]); + if (tmp.find("--nodes-with-area") == std::string::npos) { std::cout << "could not find switch nodes_with_area" << std::endl; return -1; } tmp = argv[3]; - if (tmp.find ("--nodes-in-polygon") == std::string::npos) + if (tmp.find("--nodes-in-polygon") == std::string::npos) { std::cout << "could not find switch nodes-in-polygon" << std::endl; return -1; } tmp = argv[5]; - if (tmp.find ("--output") == std::string::npos) + if (tmp.find("--output") == std::string::npos) { std::cout << "missing switch output" << std::endl; return -1; @@ -65,9 +65,9 @@ int main (int argc, char* argv[]) std::string path; BaseLib::extractPath(argv[2], path); tmp = argv[2]; - std::ifstream in0 (tmp.c_str()); + std::ifstream in0(tmp.c_str()); tmp = argv[4]; - std::ifstream in1 (tmp.c_str()); + std::ifstream in1(tmp.c_str()); if (!in0 || !in1) std::cout << "could not open one of the input files" << std::endl; @@ -78,22 +78,25 @@ int main (int argc, char* argv[]) double tmp_area_val; /*** load first input file */ - bool all_ok (true); - while (!in0.eof() && all_ok) { + bool all_ok(true); + while (!in0.eof() && all_ok) + { in0 >> tmp_id; if (in0.fail()) all_ok = false; - if (all_ok) { + if (all_ok) + { in0 >> tmp_area_val; - if (in0.fail ()) + if (in0.fail()) all_ok = false; - else { - ids0.push_back (tmp_id); - areas.push_back (tmp_area_val); + else + { + ids0.push_back(tmp_id); + areas.push_back(tmp_area_val); } } } - in0.close (); + in0.close(); std::cout << "read " << ids0.size() << " ids and " << areas.size() << " areas from file " << argv[2] << std::endl; all_ok = true; @@ -102,20 +105,20 @@ int main (int argc, char* argv[]) { in1 >> tmp_id; if (!in1.fail()) - ids1.push_back (tmp_id); + ids1.push_back(tmp_id); else all_ok = false; } - in1.close (); + in1.close(); std::cout << "read " << ids1.size() << " ids from file " << argv[4] << std::endl; std::vector perm; for (size_t k(0); k < ids0.size(); k++) perm.push_back(k); - Quicksort (ids0, 0, ids0.size(), perm); + Quicksort(ids0, 0, ids0.size(), perm); // apply permutation to areas - std::vector sorted_areas (areas.size()); + std::vector sorted_areas(areas.size()); for (size_t k(0); k < perm.size(); k++) sorted_areas[k] = areas[perm[k]]; @@ -123,48 +126,57 @@ int main (int argc, char* argv[]) std::vector not_found_ids_within_ids0(ids0.size(), true); // per default std::vector not_found_ids; - std::ofstream out (argv[6]); - if (!out) { + std::ofstream out(argv[6]); + if (!out) + { std::cout << "could not open file " << argv[6] << " for output" << std::endl; return -1; } - out.precision (12); - for (size_t k(0); k < ids1.size(); k++) { - size_t idx (searchElement (ids1[k], 0, ids0.size(), ids0)); - if (idx != std::numeric_limits::max()) { + out.precision(12); + for (size_t k(0); k < ids1.size(); k++) + { + size_t idx(searchElement(ids1[k], 0, ids0.size(), ids0)); + if (idx != std::numeric_limits::max()) + { out << ids0[idx] << " " << sorted_areas[idx] << std::endl; not_found_ids_within_ids0[idx] = false; - } else { - not_found_ids.push_back (ids1[k]); + } + else + { + not_found_ids.push_back(ids1[k]); } } - out.close (); + out.close(); - std::string fname_remaining (path+input_base_fname + "-Remaining.txt"); - std::ofstream os_remaining (fname_remaining.c_str()); + std::string fname_remaining(path + input_base_fname + "-Remaining.txt"); + std::ofstream os_remaining(fname_remaining.c_str()); std::cout << "writing to " << fname_remaining << " ... " << std::flush; - for (size_t k(0); k 8) { + if (argc > 8) + { tmp = argv[7]; - if (tmp.find ("--mesh") != std::string::npos) + if (tmp.find("--mesh") != std::string::npos) { tmp = argv[8]; - if (tmp.find (".msh") != std::string::npos) - tmp = tmp.substr (0, tmp.size() - 4); + if (tmp.find(".msh") != std::string::npos) + tmp = tmp.substr(0, tmp.size() - 4); std::cout << "reading mesh " << tmp << " ... " << std::flush; @@ -176,14 +188,16 @@ int main (int argc, char* argv[]) return -1; } std::cout << "done" << std::endl; - MeshLib::CFEMesh* mesh (mesh_vec[mesh_vec.size() - 1]); + MeshLib::CFEMesh* mesh(mesh_vec[mesh_vec.size() - 1]); - std::ofstream out_mesh_nodes_as_pnts ("MeshNodesAsPnts.gli"); - if (out_mesh_nodes_as_pnts) { + std::ofstream out_mesh_nodes_as_pnts("MeshNodesAsPnts.gli"); + if (out_mesh_nodes_as_pnts) + { out_mesh_nodes_as_pnts << "#POINTS" << std::endl; - const size_t ids0_size (ids0.size()); - for (size_t k(0); k < ids0_size; k++) { - double const* const pnt (mesh->getNodeVector()[ids0[k]]->getData()); + const size_t ids0_size(ids0.size()); + for (size_t k(0); k < ids0_size; k++) + { + double const* const pnt(mesh->getNodeVector()[ids0[k]]->getData()); out_mesh_nodes_as_pnts << k << " " << pnt[0] << " " << pnt[1] << " " << pnt[2] << std::endl; } out_mesh_nodes_as_pnts << "#STOP" << std::endl; @@ -192,4 +206,3 @@ int main (int argc, char* argv[]) } } } - diff --git a/UTL/MSHGEOTOOLS/mainConvertGLIVerticalSurfaceToPolygon.cpp b/UTL/MSHGEOTOOLS/mainConvertGLIVerticalSurfaceToPolygon.cpp index 3ec0d45a2..ce125f9eb 100644 --- a/UTL/MSHGEOTOOLS/mainConvertGLIVerticalSurfaceToPolygon.cpp +++ b/UTL/MSHGEOTOOLS/mainConvertGLIVerticalSurfaceToPolygon.cpp @@ -31,20 +31,24 @@ int main(int argc, char* argv[]) { - if (argc < 5) { + if (argc < 5) + { std::cout << "Program " << argv[0] - << " converts a vertical surface described by a polyline embedded in a mesh to a polygon" - << std::endl; + << " converts a vertical surface described by a polyline embedded in a mesh to a polygon" + << std::endl; std::cout << "For this reason the polyline is projected to the bottom surface and top surface " - "of the mesh. The resulting two polylines are linked to a closed polyline, i.e., a polygon." << std::endl; - std::cout << "Usage: " << argv[0] - << " --mesh ogs_meshfile --geometry ogs_geometry_as_gli_file [--polyline-id-lower ply_id_lower --polyline-id-upper ply_id_upper]" << std::endl; + "of the mesh. The resulting two polylines are linked to a closed polyline, i.e., a polygon." + << std::endl; + std::cout << "Usage: " << argv[0] << " --mesh ogs_meshfile --geometry ogs_geometry_as_gli_file " + "[--polyline-id-lower ply_id_lower --polyline-id-upper ply_id_upper]" + << std::endl; return -1; } // *** read mesh std::string tmp(argv[1]); - if (tmp.find("--mesh") == std::string::npos) { + if (tmp.find("--mesh") == std::string::npos) + { std::cout << "could not extract mesh file name" << std::endl; return -1; } @@ -56,16 +60,18 @@ int main(int argc, char* argv[]) std::vector mesh_vec; FEMRead(file_base_name, mesh_vec); - if (mesh_vec.empty()) { + if (mesh_vec.empty()) + { std::cerr << "could not read mesh from file " << std::endl; return -1; } - MeshLib::CFEMesh * mesh(mesh_vec[mesh_vec.size() - 1]); + MeshLib::CFEMesh* mesh(mesh_vec[mesh_vec.size() - 1]); mesh->ConstructGrid(); // *** read geometry tmp = argv[3]; - if (tmp.find("--geometry") == std::string::npos) { + if (tmp.find("--geometry") == std::string::npos) + { std::cout << "could not extract geometry file name" << std::endl; return -1; } @@ -79,7 +85,8 @@ int main(int argc, char* argv[]) // *** get Polygon const std::vector* plys(geo->getPolylineVec(unique_name)); std::cout << "fetched polylines: " << std::flush << plys->size() << std::endl; - if (!plys) { + if (!plys) + { std::cout << "could not get vector of polylines" << std::endl; delete mesh; delete geo; @@ -92,19 +99,21 @@ int main(int argc, char* argv[]) // *** generate a polygon from polyline size_t ply_id_upper(plys->size()); size_t ply_id_lower(0); - if (argc == 9) { + if (argc == 9) + { ply_id_lower = str2number(argv[6]); ply_id_upper = std::min(str2number(argv[8]), ply_id_upper); } - for (size_t k(ply_id_lower); k < ply_id_upper; k++) { + for (size_t k(ply_id_lower); k < ply_id_upper; k++) + { bool closed((*plys)[k]->isClosed()); - if (!closed) { - std::cout << "converting polyline " << k << " to polygon (closed polyline) " - << std::endl; + if (!closed) + { + std::cout << "converting polyline " << k << " to polygon (closed polyline) " << std::endl; GEOLIB::Polygon* polygon(NULL); extract_mesh_nodes.getPolygonFromPolyline(*((*plys)[k]), geo, unique_name, polygon); - std::string *polygon_name(new std::string); + std::string* polygon_name(new std::string); geo->getPolylineVecObj(unique_name)->getNameOfElementByID(k, *polygon_name); (*polygon_name) += "-Polygon"; geo->getPolylineVecObj(unique_name)->push_back(polygon, polygon_name); diff --git a/UTL/MSHGEOTOOLS/mainExtractMeshNodeIDs.cpp b/UTL/MSHGEOTOOLS/mainExtractMeshNodeIDs.cpp index 157726d99..c4267d09d 100644 --- a/UTL/MSHGEOTOOLS/mainExtractMeshNodeIDs.cpp +++ b/UTL/MSHGEOTOOLS/mainExtractMeshNodeIDs.cpp @@ -37,28 +37,30 @@ Problem* aproblem = NULL; #include "Matrix.h" #include "Vector3.h" -int main (int argc, char* argv[]) +int main(int argc, char* argv[]) { if (argc < 5) { - std::cout << "program " << argv[0] << " takes a *layered* mesh file and closed polylines from a geometry and computes the surface mesh nodes within the closed polyline" << std::endl; - std::cout << "Usage: " << std::endl << argv[0] << - "\n\t--mesh ogs_meshfile\n\t--geometry ogs_geometry_as_gli_file" << std::endl; + std::cout << "program " << argv[0] << " takes a *layered* mesh file and closed polylines from a geometry and " + "computes the surface mesh nodes within the closed polyline" + << std::endl; + std::cout << "Usage: " << std::endl + << argv[0] << "\n\t--mesh ogs_meshfile\n\t--geometry ogs_geometry_as_gli_file" << std::endl; return -1; } // *** read mesh - std::string tmp (argv[1]); - if (tmp.find ("--mesh") == std::string::npos) + std::string tmp(argv[1]); + if (tmp.find("--mesh") == std::string::npos) { std::cout << "could not extract mesh file name" << std::endl; return -1; } tmp = argv[2]; - std::string file_base_name (tmp); - if (tmp.find (".msh") != std::string::npos) - file_base_name = tmp.substr (0, tmp.size() - 4); + std::string file_base_name(tmp); + if (tmp.find(".msh") != std::string::npos) + file_base_name = tmp.substr(0, tmp.size() - 4); std::vector mesh_vec; FEMRead(file_base_name, mesh_vec); @@ -67,7 +69,7 @@ int main (int argc, char* argv[]) std::cerr << "could not read mesh from file " << std::endl; return -1; } - MeshLib::CFEMesh* mesh (mesh_vec[mesh_vec.size() - 1]); + MeshLib::CFEMesh* mesh(mesh_vec[mesh_vec.size() - 1]); mesh->ConstructGrid(); // extract path @@ -76,41 +78,41 @@ int main (int argc, char* argv[]) // *** read geometry tmp = argv[3]; - if (tmp.find ("--geometry") == std::string::npos) + if (tmp.find("--geometry") == std::string::npos) { std::cout << "could not extract geometry file name" << std::endl; return -1; } - GEOLIB::GEOObjects* geo (new GEOLIB::GEOObjects); + GEOLIB::GEOObjects* geo(new GEOLIB::GEOObjects); tmp = argv[4]; std::string unique_name; std::vector error_strings; FileIO::readGLIFileV4(tmp, geo, unique_name, error_strings); -// { -// const std::vector* pnts (geo->getPointVec (tmp)); -// if (pnts) { -// std::string fname ("MeshIDs.txt"); -// std::ofstream out (fname.c_str()); -// -// std::string fname_gli ("MeshNodesAsPnts.gli"); -// std::ofstream pnt_out (fname_gli.c_str()); -// pnt_out << "#POINTS" << std::endl; -// -// MeshLib::ExtractMeshNodes extract_mesh_nodes (mesh); -// -// const size_t n_pnts (pnts->size()); -// for (size_t k(0); k* pnts (geo->getPointVec (tmp)); + // if (pnts) { + // std::string fname ("MeshIDs.txt"); + // std::ofstream out (fname.c_str()); + // + // std::string fname_gli ("MeshNodesAsPnts.gli"); + // std::ofstream pnt_out (fname_gli.c_str()); + // pnt_out << "#POINTS" << std::endl; + // + // MeshLib::ExtractMeshNodes extract_mesh_nodes (mesh); + // + // const size_t n_pnts (pnts->size()); + // for (size_t k(0); k* plys (geo->getPolylineVec (unique_name)); + const std::vector* plys(geo->getPolylineVec(unique_name)); if (!plys) { std::cout << "could not get vector of polylines" << std::endl; @@ -120,54 +122,58 @@ int main (int argc, char* argv[]) } std::vector mesh_ids; -// size_t ply_id (0); -// size_t layer(1); -// getMeshNodesFromLayerAlongPolyline(mesh, geo, unique_name, ply_id, layer, mesh_ids); -// writeMeshNodes(mesh, mesh_ids, "MeshIDs.txt", "MeshNodesAsPoints.gli", true); + // size_t ply_id (0); + // size_t layer(1); + // getMeshNodesFromLayerAlongPolyline(mesh, geo, unique_name, ply_id, layer, mesh_ids); + // writeMeshNodes(mesh, mesh_ids, "MeshIDs.txt", "MeshNodesAsPoints.gli", true); //*** extract surface out of mesh - MeshLib::ExtractMeshNodes extract_mesh_nodes (mesh); - -// // *** generate a polygon from polyline -//// std::vector polylines; -// const size_t n_plys (plys->size()); -// for (size_t k(0); k < n_plys; k++) -// { -// bool closed ((*plys)[k]->isClosed()); -// if (!closed) -// { -// std::cout << "converting polyline " << k << " to closed polyline" << std::endl; -// GEOLIB::Polygon* polygon(NULL); -// extract_mesh_nodes.getPolygonFromPolyline(*((*plys)[k]), geo, unique_name, polygon); -//// polylines.push_back (polygon); -//// geo->appendPolylineVec (polylines, unique_name); -// std::string *polygon_name(new std::string); -// geo->getPolylineVecObj(unique_name)->getNameOfElementByID(k, *polygon_name); -// (*polygon_name) += "-Polygon"; -// geo->getPolylineVecObj(unique_name)->push_back(polygon, polygon_name); -//// polylines.clear(); -// } -// } -// -// FileIO::writeGLIFileV4 ("New.gli", unique_name, *geo); + MeshLib::ExtractMeshNodes extract_mesh_nodes(mesh); + + // // *** generate a polygon from polyline + //// std::vector polylines; + // const size_t n_plys (plys->size()); + // for (size_t k(0); k < n_plys; k++) + // { + // bool closed ((*plys)[k]->isClosed()); + // if (!closed) + // { + // std::cout << "converting polyline " << k << " to closed polyline" << std::endl; + // GEOLIB::Polygon* polygon(NULL); + // extract_mesh_nodes.getPolygonFromPolyline(*((*plys)[k]), geo, unique_name, polygon); + //// polylines.push_back (polygon); + //// geo->appendPolylineVec (polylines, unique_name); + // std::string *polygon_name(new std::string); + // geo->getPolylineVecObj(unique_name)->getNameOfElementByID(k, *polygon_name); + // (*polygon_name) += "-Polygon"; + // geo->getPolylineVecObj(unique_name)->push_back(polygon, polygon_name); + //// polylines.clear(); + // } + // } + // + // FileIO::writeGLIFileV4 ("New.gli", unique_name, *geo); // *** search mesh nodes for direct assigning bc, st or ic - const size_t n_plys (plys->size()); - for (size_t k(0); kisClosed()); - if (!closed) { + const size_t n_plys(plys->size()); + for (size_t k(0); k < n_plys; k++) + { + bool closed((*plys)[k]->isClosed()); + if (!closed) + { std::cout << "polyline " << k << " is not closed" << std::endl; - } else { - std::string fname (path + "MeshIDs.txt"); - std::ofstream out (fname.c_str()); - std::string fname_gli (path + "MeshNodesAsPnts.gli"); - std::ofstream pnt_out (fname_gli.c_str()); + } + else + { + std::string fname(path + "MeshIDs.txt"); + std::ofstream out(fname.c_str()); + std::string fname_gli(path + "MeshNodesAsPnts.gli"); + std::ofstream pnt_out(fname_gli.c_str()); pnt_out << "#POINTS" << std::endl; - GEOLIB::Polygon polygon (*((*plys)[k])); -// extract_mesh_nodes.writeMesh2DNodeIDAndArea (out, pnt_out, polygon); - extract_mesh_nodes.writeTopSurfaceMeshNodeIDs (out, pnt_out, polygon); + GEOLIB::Polygon polygon(*((*plys)[k])); + // extract_mesh_nodes.writeMesh2DNodeIDAndArea (out, pnt_out, polygon); + extract_mesh_nodes.writeTopSurfaceMeshNodeIDs(out, pnt_out, polygon); // write all nodes - not only the surface nodes -// extract_mesh_nodes.writeMeshNodeIDs (out, pnt_out, polygon); + // extract_mesh_nodes.writeMeshNodeIDs (out, pnt_out, polygon); pnt_out << "#STOP" << std::endl; out.close(); pnt_out.close(); @@ -175,30 +181,31 @@ int main (int argc, char* argv[]) } // *** for Model Pipiripau -// std::vector holes; -// size_t bounding_polygon_id(0); -// while (bounding_polygon_id < n_plys && ! (*plys)[bounding_polygon_id]->isClosed()) { -// bounding_polygon_id++; -// } -// -// for (size_t k(bounding_polygon_id+1); kisClosed()); -// if (!closed) { -// std::cout << "polyline " << k << " is not closed" << std::endl; -// } else { -// holes.push_back (new GEOLIB::Polygon(*(((*plys)[k])))); -// } -// } -// extract_mesh_nodes.writeMesh2DNodeIDAndArea (out, pnt_out, GEOLIB::Polygon((*((*plys)[bounding_polygon_id]))), holes); -// for (size_t k(0); k holes; + // size_t bounding_polygon_id(0); + // while (bounding_polygon_id < n_plys && ! (*plys)[bounding_polygon_id]->isClosed()) { + // bounding_polygon_id++; + // } + // + // for (size_t k(bounding_polygon_id+1); kisClosed()); + // if (!closed) { + // std::cout << "polyline " << k << " is not closed" << std::endl; + // } else { + // holes.push_back (new GEOLIB::Polygon(*(((*plys)[k])))); + // } + // } + // extract_mesh_nodes.writeMesh2DNodeIDAndArea (out, pnt_out, GEOLIB::Polygon((*((*plys)[bounding_polygon_id]))), + // holes); + // for (size_t k(0); k mesh_vec; FEMRead(file_base_name, mesh_vec); @@ -65,7 +65,7 @@ int main (int argc, char* argv[]) std::cerr << "could not read mesh from file " << std::endl; return -1; } - MeshLib::CFEMesh* mesh (mesh_vec[mesh_vec.size() - 1]); + MeshLib::CFEMesh* mesh(mesh_vec[mesh_vec.size() - 1]); // extract path std::string path; @@ -73,26 +73,27 @@ int main (int argc, char* argv[]) // *** read mesh ids tmp = argv[3]; - if (tmp.find ("--mesh-ids") == std::string::npos) + if (tmp.find("--mesh-ids") == std::string::npos) { std::cout << "could not extract mesh node id file name" << std::endl; return -1; } std::cout << "read mesh ids from file " << argv[4] << " ... " << std::flush; - std::ifstream in (argv[4]); + std::ifstream in(argv[4]); std::vector mesh_ids; std::string id_as_str; size_t tmp_id; - while (std::getline(in, id_as_str)) { + while (std::getline(in, id_as_str)) + { std::stringstream strstr(id_as_str); strstr >> tmp_id; mesh_ids.push_back(tmp_id); } std::cout << "done, " << mesh_ids.size() << " ids read" << std::endl; - std::string out_fname(file_base_name+"-MeshNodesAsPoints.gli"); - std::ofstream os (out_fname.c_str()); + std::string out_fname(file_base_name + "-MeshNodesAsPoints.gli"); + std::ofstream os(out_fname.c_str()); std::cout << "writing points to " << out_fname << " ... " << std::flush; FileIO::OGSMeshIO mesh_io; mesh_io.setMesh(mesh); diff --git a/UTL/MSHGEOTOOLS/mainModifyMeshProperties.cpp b/UTL/MSHGEOTOOLS/mainModifyMeshProperties.cpp index 81a06d362..86fbd051e 100644 --- a/UTL/MSHGEOTOOLS/mainModifyMeshProperties.cpp +++ b/UTL/MSHGEOTOOLS/mainModifyMeshProperties.cpp @@ -31,8 +31,8 @@ Problem* aproblem = NULL; -char program_description[] = -"This program reads an OpenGeoSys (OGS) mesh, a geometry (in OGS gli format) and\n\ +char program_description[] + = "This program reads an OpenGeoSys (OGS) mesh, a geometry (in OGS gli format) and\n\ an id of a polygon described inside of the geometry. With the help of the\n\ referenced polygon a volume is described. First the polygon is projected to\n\ the bottom and top surface of the mesh and we obtain parts of the bottom and\n\ @@ -41,33 +41,38 @@ via a third surface. The volume is defined as the part of the mesh that is\n\ inside the three surfaces. Within this volume the material ids of the elements\n\ are modified. Programmed by Tom (thomas.fischer@ufz.de)"; -int main (int argc, char* argv[]) +int main(int argc, char* argv[]) { - if (!(argc == 9 || argc == 11)) { + if (!(argc == 9 || argc == 11)) + { std::cout << "********************************************************************************" << std::endl; std::cout << program_description << std::endl; std::cout << "********************************************************************************" << std::endl; std::cout << "Usage: " << std::endl; - std::cout << argv[0] << "\n\t--mesh ogs_meshfile\n\t--geometry ogs_geometry\n\t--polygon_id id\n\t--material_id id" << std::endl; + std::cout << argv[0] + << "\n\t--mesh ogs_meshfile\n\t--geometry ogs_geometry\n\t--polygon_id id\n\t--material_id id" + << std::endl; std::cout << "*** or ***" << std::endl; - std::cout << argv[0] << "\n\t--mesh ogs_meshfile\n\t--geometry ogs_geometry\n\t--polygon_id id\n\t--old_material_id old_id\n\t--new_material_id new_id" << std::endl; + std::cout << argv[0] << "\n\t--mesh ogs_meshfile\n\t--geometry ogs_geometry\n\t--polygon_id " + "id\n\t--old_material_id old_id\n\t--new_material_id new_id" + << std::endl; return -1; } // *** read mesh - std::string tmp (argv[1]); - if (tmp.find ("--mesh") == std::string::npos) + std::string tmp(argv[1]); + if (tmp.find("--mesh") == std::string::npos) { std::cout << "could not extract mesh file name" << std::endl; return -1; } tmp = argv[2]; - std::string file_base_name (tmp); + std::string file_base_name(tmp); std::string path; BaseLib::extractPath(file_base_name, path); - if (tmp.find (".msh") != std::string::npos) - file_base_name = tmp.substr (0, tmp.size() - 4); + if (tmp.find(".msh") != std::string::npos) + file_base_name = tmp.substr(0, tmp.size() - 4); std::vector mesh_vec; FEMRead(file_base_name, mesh_vec); @@ -76,19 +81,19 @@ int main (int argc, char* argv[]) std::cerr << "could not read mesh from file " << std::endl; return -1; } - MeshLib::CFEMesh* mesh (mesh_vec[mesh_vec.size() - 1]); + MeshLib::CFEMesh* mesh(mesh_vec[mesh_vec.size() - 1]); mesh->ConstructGrid(); // *** read geometry tmp = argv[3]; - if (tmp.find ("--geometry") == std::string::npos) + if (tmp.find("--geometry") == std::string::npos) { std::cout << "could not extract geometry file name" << std::endl; return -1; } - GEOLIB::GEOObjects* geo (new GEOLIB::GEOObjects); + GEOLIB::GEOObjects* geo(new GEOLIB::GEOObjects); tmp = argv[4]; std::string unique_name; std::vector error_strings; @@ -96,7 +101,7 @@ int main (int argc, char* argv[]) // *** get polygons tmp = BaseLib::getFileNameFromPath(tmp, true); - const std::vector* plys (geo->getPolylineVec (tmp)); + const std::vector* plys(geo->getPolylineVec(tmp)); if (!plys) { std::cout << "could not get vector of polylines" << std::endl; @@ -107,23 +112,24 @@ int main (int argc, char* argv[]) // *** get polygon id tmp = argv[5]; - if (tmp.find ("--polygon_id") == std::string::npos) + if (tmp.find("--polygon_id") == std::string::npos) { std::cout << "could not read polygon id" << std::endl; delete mesh; delete geo; return -1; } - size_t polygon_id (atoi (argv[6])); + size_t polygon_id(atoi(argv[6])); - if (plys->size() <= polygon_id) { + if (plys->size() <= polygon_id) + { std::cout << "polyline for id " << polygon_id << " not found" << std::endl; delete mesh; delete geo; return -1; } - bool closed ((*plys)[polygon_id]->isClosed()); + bool closed((*plys)[polygon_id]->isClosed()); if (!closed) { std::cout << "polyline with id " << polygon_id << " is not closed" << std::endl; @@ -133,54 +139,59 @@ int main (int argc, char* argv[]) } size_t old_material_id(0), new_material_id(0); - if (argc == 9) { + if (argc == 9) + { // *** get material id tmp = argv[7]; - if (tmp.find ("--material") == std::string::npos) + if (tmp.find("--material") == std::string::npos) { std::cout << "could not read material id" << std::endl; delete mesh; delete geo; return -1; } - new_material_id = atoi (argv[8]); + new_material_id = atoi(argv[8]); } - if (argc == 11) { + if (argc == 11) + { // *** get old material id tmp = argv[7]; - if (tmp.find ("--old_material_id") == std::string::npos) + if (tmp.find("--old_material_id") == std::string::npos) { std::cout << "could not read old material id" << std::endl; delete mesh; delete geo; return -1; } - old_material_id = atoi (argv[8]); + old_material_id = atoi(argv[8]); tmp = argv[9]; - if (tmp.find ("--new_material_id") == std::string::npos) + if (tmp.find("--new_material_id") == std::string::npos) { std::cout << "could not read new material id" << std::endl; delete mesh; delete geo; return -1; } - new_material_id = atoi (argv[10]); + new_material_id = atoi(argv[10]); } - GEOLIB::Polygon polygon (*((*plys)[polygon_id])); - MeshLib::ModifyMeshProperties modify_mesh_nodes (mesh); + GEOLIB::Polygon polygon(*((*plys)[polygon_id])); + MeshLib::ModifyMeshProperties modify_mesh_nodes(mesh); - if (argc == 9) { - modify_mesh_nodes.setMaterial (polygon, new_material_id); - } else { - modify_mesh_nodes.substituteMaterialID (polygon, old_material_id, new_material_id); + if (argc == 9) + { + modify_mesh_nodes.setMaterial(polygon, new_material_id); + } + else + { + modify_mesh_nodes.substituteMaterialID(polygon, old_material_id, new_material_id); } - std::string mesh_out_fname(path+"MeshWithMaterial.msh"); + std::string mesh_out_fname(path + "MeshWithMaterial.msh"); std::cout << "write " << mesh_out_fname << " ... " << std::flush; FileIO::OGSMeshIO mesh_io; mesh_io.setMesh(mesh); - mesh_io.writeToFile (mesh_out_fname); + mesh_io.writeToFile(mesh_out_fname); std::cout << "ok" << std::endl; return 0; diff --git a/UTL/MSHGEOTOOLS/testMeshSearchAlgorithms.cpp b/UTL/MSHGEOTOOLS/testMeshSearchAlgorithms.cpp index b7bfe0322..a454a6356 100644 --- a/UTL/MSHGEOTOOLS/testMeshSearchAlgorithms.cpp +++ b/UTL/MSHGEOTOOLS/testMeshSearchAlgorithms.cpp @@ -36,20 +36,23 @@ // we need this for using the xml functions of Qt //#include -void testOctTreeGlobalQueries (GEOLIB::OctTree const& oct_tree, double const*const min, double const*const max) +void testOctTreeGlobalQueries(GEOLIB::OctTree const& oct_tree, + double const* const min, + double const* const max) { std::vector pnts_in_range; MeshLib::CNode q_min(min); MeshLib::CNode q_max(max); -// std::vector pnts_in_range; -// GEOLIB::Point q_min(min); -// GEOLIB::Point q_max(max); + // std::vector pnts_in_range; + // GEOLIB::Point q_min(min); + // GEOLIB::Point q_max(max); clock_t start, stop; start = clock(); oct_tree.getPointsInRange(q_min, q_max, pnts_in_range); stop = clock(); - std::cout << "query all: " << pnts_in_range.size() << " points in range " << q_min << " x " << q_max << " took " << (stop-start)/(double)(CLOCKS_PER_SEC) << " seconds" < const& oct_tree, start = clock(); oct_tree.getPointsInRange(q_min, q_max, pnts_in_range); stop = clock(); - std::cout << "query NEU: " << pnts_in_range.size() << " points in range " << q_min << " x " << q_max << " took " << (stop-start)/(double)(CLOCKS_PER_SEC) << " seconds" < const& oct_tree, start = clock(); oct_tree.getPointsInRange(q_min, q_max, pnts_in_range); stop = clock(); - std::cout << "query NWU: " << pnts_in_range.size() << " points in range " << q_min << " x " << q_max << " took " << (stop-start)/(double)(CLOCKS_PER_SEC) << " seconds" < const& oct_tree, q_min[2] = min[2]; q_max[0] = (max[0] + min[0]) / 2.0; q_max[1] = max[1]; - q_max[2] = (max[2]+min[2])/2.0; + q_max[2] = (max[2] + min[2]) / 2.0; start = clock(); oct_tree.getPointsInRange(q_min, q_max, pnts_in_range); stop = clock(); - std::cout << "query NWL: " << pnts_in_range.size() << " points in range " << q_min << " x " << q_max << " took " << (stop-start)/(double)(CLOCKS_PER_SEC) << " seconds" < const& oct_tree, q_min[2] = min[2]; q_max[0] = (max[0] + min[0]) / 2.0; q_max[1] = (max[1] + min[1]) / 2.0; - q_max[2] = (max[2]+min[2])/2.0; + q_max[2] = (max[2] + min[2]) / 2.0; start = clock(); oct_tree.getPointsInRange(q_min, q_max, pnts_in_range); stop = clock(); - std::cout << "query SWL: " << pnts_in_range.size() << " points in range " << q_min << " x " << q_max << " took " << (stop-start)/(double)(CLOCKS_PER_SEC) << " seconds" < const& oct_tree, } void testOctTreePointQueries(GEOLIB::OctTree const& oct_tree, - std::vector const& pnts_for_search, - std::vector &idx_found_nodes) -//void testOctTreePointQueries(GEOLIB::OctTree const& oct_tree, + std::vector const& pnts_for_search, + std::vector& idx_found_nodes) +// void testOctTreePointQueries(GEOLIB::OctTree const& oct_tree, // std::vector const& pnts_for_search, // std::vector &idx_found_nodes) { const size_t n_pnts(pnts_for_search.size()); std::vector pnts_in_range; -// std::vector pnts_in_range; - for(size_t k(0); kgetData()); - MeshLib::CNode q_max (pnts_for_search[k]->getData()); -// GEOLIB::Point q_min (pnts_for_search[k]->getData()); -// GEOLIB::Point q_max (pnts_for_search[k]->getData()); - for (size_t d(0); d<3; d++) { - q_min[d] -= 1; //fabs(q_min[d]) * std::numeric_limits::epsilon(); + // std::vector pnts_in_range; + for (size_t k(0); k < n_pnts; k++) + { + MeshLib::CNode q_min(pnts_for_search[k]->getData()); + MeshLib::CNode q_max(pnts_for_search[k]->getData()); + // GEOLIB::Point q_min (pnts_for_search[k]->getData()); + // GEOLIB::Point q_max (pnts_for_search[k]->getData()); + for (size_t d(0); d < 3; d++) + { + q_min[d] -= 1; // fabs(q_min[d]) * std::numeric_limits::epsilon(); q_max[d] += 1; // fabs(q_max[d]) * std::numeric_limits::epsilon(); } oct_tree.getPointsInRange(q_min, q_max, pnts_in_range); - if (! pnts_in_range.empty()) { + if (!pnts_in_range.empty()) + { const size_t n_pnts_in_range(pnts_in_range.size()); double sqr_dist(0.0); - double distmin(MathLib::sqrDist (pnts_in_range[0]->getData(), pnts_for_search[k]->getData())); + double distmin(MathLib::sqrDist(pnts_in_range[0]->getData(), pnts_for_search[k]->getData())); size_t idx(pnts_in_range[0]->GetIndex()); - for (size_t j(1); jgetData(), pnts_for_search[k]->getData()); - if (sqr_dist < distmin) { + for (size_t j(1); j < n_pnts_in_range; j++) + { + sqr_dist = MathLib::sqrDist(pnts_in_range[j]->getData(), pnts_for_search[k]->getData()); + if (sqr_dist < distmin) + { distmin = sqr_dist; idx = pnts_in_range[j]->GetIndex(); } } idx_found_nodes.push_back(idx); - } else { + } + else + { std::cout << "no node found for point " << *(pnts_for_search[k]) << std::endl; } pnts_in_range.clear(); } } -void testOctTree(MeshLib::CFEMesh const*const mesh, std::vector& pnts_for_search, std::vector &idx_found_nodes) +void testOctTree(MeshLib::CFEMesh const* const mesh, + std::vector& pnts_for_search, + std::vector& idx_found_nodes) { // get the mesh node vector std::vector const& nodes_oct_tree(mesh->getNodeVector()); std::vector nodes_as_pnts; const size_t n_nodes_oct_tree(nodes_oct_tree.size()); MeshLib::CNode min(0, nodes_oct_tree[0]->getData()), max(1, nodes_oct_tree[0]->getData()); -// GEOLIB::Point min(nodes_oct_tree[0]->getData()), max(nodes_oct_tree[0]->getData()); + // GEOLIB::Point min(nodes_oct_tree[0]->getData()), max(nodes_oct_tree[0]->getData()); // determine bounding box - for (size_t k(0); kgetData())); } @@ -226,47 +252,52 @@ void testOctTree(MeshLib::CFEMesh const*const mesh, std::vector& BaseLib::MemWatch mem_watch; unsigned long mem_before = mem_watch.getVirtMemUsage(); #endif - GEOLIB::OctTree *oct_tree (GEOLIB::OctTree::createOctTree(min, max, 128)); + GEOLIB::OctTree* oct_tree(GEOLIB::OctTree::createOctTree(min, max, 128)); std::cout << "done" << std::endl; -// GEOLIB::OctTree oct_tree(min, max, 2); + // GEOLIB::OctTree oct_tree(min, max, 2); std::cout << "\tinserting " << n_nodes_oct_tree << " points ... " << std::flush; clock_t start(clock()); - for (size_t k(0); kaddPoint(nodes_oct_tree[k]); -// oct_tree->addPoint(nodes_as_pnts[k]); + // oct_tree->addPoint(nodes_as_pnts[k]); } clock_t stop(clock()); #ifndef WIN32 unsigned long mem_after = mem_watch.getVirtMemUsage(); - std::cout << "done, " << (stop-start)/(double)(CLOCKS_PER_SEC) << " seconds, " << (mem_after-mem_before)/(1024*1024) << " MBytes" << std::endl; + std::cout << "done, " << (stop - start) / (double)(CLOCKS_PER_SEC) << " seconds, " + << (mem_after - mem_before) / (1024 * 1024) << " MBytes" << std::endl; #endif std::cout << "\tsearching " << pnts_for_search.size() << " points ... " << std::flush; start = clock(); testOctTreePointQueries(*oct_tree, pnts_for_search, idx_found_nodes); stop = clock(); - std::cout << "done, " << (stop-start)/(double)(CLOCKS_PER_SEC) << " seconds" << std::endl; + std::cout << "done, " << (stop - start) / (double)(CLOCKS_PER_SEC) << " seconds" << std::endl; } -void testNaiveAlgorithm (MeshLib::CFEMesh const*const mesh, - std::vector& pnts_for_search, - std::vector &idx_found_nodes) +void testNaiveAlgorithm(MeshLib::CFEMesh const* const mesh, + std::vector& pnts_for_search, + std::vector& idx_found_nodes) { - const size_t nodes_in_usage(static_cast (mesh->NodesInUsage())); - std::vector const& nodes (mesh->getNodeVector()); + const size_t nodes_in_usage(static_cast(mesh->NodesInUsage())); + std::vector const& nodes(mesh->getNodeVector()); const size_t n_pnts_for_search(pnts_for_search.size()); std::cout << "[LinearSearchAlgorithm] searching " << pnts_for_search.size() << " points ... " << std::flush; clock_t start = clock(); - for (size_t k(0); kgetData()); - double sqr_dist(0.0), distmin(MathLib::sqrDist (nodes[0]->getData(), k_th_pnt)); + for (size_t k(0); k < n_pnts_for_search; k++) + { + double const* const k_th_pnt(pnts_for_search[k]->getData()); + double sqr_dist(0.0), distmin(MathLib::sqrDist(nodes[0]->getData(), k_th_pnt)); size_t idx(0); - for (size_t i = 1; i < nodes_in_usage; i++) { - double const*const i_th_node(nodes[i]->getData()); -// sqr_dist = MathLib::sqrDist (i_th_node, k_th_pnt); - sqr_dist = (i_th_node[0]-k_th_pnt[0])*(i_th_node[0]-k_th_pnt[0]); - sqr_dist += (i_th_node[1]-k_th_pnt[1])*(i_th_node[1]-k_th_pnt[1]); - sqr_dist += (i_th_node[2]-k_th_pnt[2])*(i_th_node[2]-k_th_pnt[2]); - if (sqr_dist < distmin) { + for (size_t i = 1; i < nodes_in_usage; i++) + { + double const* const i_th_node(nodes[i]->getData()); + // sqr_dist = MathLib::sqrDist (i_th_node, k_th_pnt); + sqr_dist = (i_th_node[0] - k_th_pnt[0]) * (i_th_node[0] - k_th_pnt[0]); + sqr_dist += (i_th_node[1] - k_th_pnt[1]) * (i_th_node[1] - k_th_pnt[1]); + sqr_dist += (i_th_node[2] - k_th_pnt[2]) * (i_th_node[2] - k_th_pnt[2]); + if (sqr_dist < distmin) + { distmin = sqr_dist; idx = i; } @@ -274,52 +305,55 @@ void testNaiveAlgorithm (MeshLib::CFEMesh const*const mesh, idx_found_nodes.push_back(idx); } clock_t stop = clock(); - std::cout << "done, " << (stop-start)/(double)(CLOCKS_PER_SEC) << " seconds" << std::endl; + std::cout << "done, " << (stop - start) / (double)(CLOCKS_PER_SEC) << " seconds" << std::endl; } -void testMeshGridAlgorithm(MeshLib::CFEMesh const*const mesh, - std::vector& pnts_for_search, - std::vector &idx_found_nodes) +void testMeshGridAlgorithm(MeshLib::CFEMesh const* const mesh, + std::vector& pnts_for_search, + std::vector& idx_found_nodes) { const size_t n_pnts_for_search(pnts_for_search.size()); std::cout << "[MeshGridAlgorithm] searching " << pnts_for_search.size() << " points ... " << std::flush; clock_t start = clock(); - for (size_t k(0); k(mesh->GetNODOnPNT(pnts_for_search[k]))); } clock_t stop = clock(); - std::cout << "done, " << (stop-start)/(double)(CLOCKS_PER_SEC) << " seconds" << std::endl; + std::cout << "done, " << (stop - start) / (double)(CLOCKS_PER_SEC) << " seconds" << std::endl; } -int main (int argc, char* argv[]) +int main(int argc, char* argv[]) { // Creating a non-gui (console) Qt application -// QApplication app(argc, argv, false); + // QApplication app(argc, argv, false); - if (argc < 3) { - std::cout << "Usage: " << argv[0] << " --mesh-in meshfile " - << std::flush; + if (argc < 3) + { + std::cout << "Usage: " << argv[0] << " --mesh-in meshfile " << std::flush; std::cout << "--number-of-search-points number " << std::flush; - std::cout << "[--geo-in geo-file --geo-out geo-out-file]" - << std::endl; + std::cout << "[--geo-in geo-file --geo-out geo-out-file]" << std::endl; return -1; } // *** parsing mesh options from command line // *** parsing mesh in file name std::string tmp(argv[1]); - if (tmp.find("--mesh-in") == std::string::npos) { + if (tmp.find("--mesh-in") == std::string::npos) + { std::cout << "could not find switch for reading mesh file name" << std::endl; return -1; } tmp = argv[2]; std::string file_base_name(tmp); - if (tmp.find(".msh") != std::string::npos) file_base_name = tmp.substr(0, tmp.size() - 4); + if (tmp.find(".msh") != std::string::npos) + file_base_name = tmp.substr(0, tmp.size() - 4); // *** parsing number of search points tmp = argv[3]; size_t n(0); - if (tmp.find("--number-of-search-points") == std::string::npos) { + if (tmp.find("--number-of-search-points") == std::string::npos) + { std::cout << "could not find switch for reading number of points to search for" << std::endl; return -1; } @@ -327,9 +361,11 @@ int main (int argc, char* argv[]) // *** parsing geometry options from command line std::string geo_fname_in, geo_fname_out; - if (argc > 5) { + if (argc > 5) + { tmp = argv[5]; - if (tmp.find("--geo-in") == std::string::npos) { + if (tmp.find("--geo-in") == std::string::npos) + { std::cout << "could not find switch for reading geometry file name" << std::endl; return -1; } @@ -337,7 +373,8 @@ int main (int argc, char* argv[]) // *** parsing geo output name tmp = argv[7]; - if (tmp.find("--geo-out") == std::string::npos) { + if (tmp.find("--geo-out") == std::string::npos) + { std::cout << "could not find switch for file name for writing the geometry" << std::endl; return -1; } @@ -348,49 +385,52 @@ int main (int argc, char* argv[]) std::vector mesh_vec; #ifndef WIN32 BaseLib::MemWatch mem_watch; - clock_t start (clock()); - unsigned long mem_without_mesh (mem_watch.getVirtMemUsage()); + clock_t start(clock()); + unsigned long mem_without_mesh(mem_watch.getVirtMemUsage()); #endif FEMRead(file_base_name, mesh_vec); #ifndef WIN32 - unsigned long mem_with_mesh (mem_watch.getVirtMemUsage()); + unsigned long mem_with_mesh(mem_watch.getVirtMemUsage()); #endif - if (mesh_vec.empty()) { + if (mesh_vec.empty()) + { std::cerr << "could not read mesh from file " << std::endl; return -1; } #ifndef WIN32 - std::cout << "mem for pure mesh data structures: " << (mem_with_mesh-mem_without_mesh) / (1024*1024) << " MB" << std::endl; + std::cout << "mem for pure mesh data structures: " << (mem_with_mesh - mem_without_mesh) / (1024 * 1024) << " MB" + << std::endl; clock_t stop = clock(); - std::cout << "reading mesh took " << (stop-start)/(double)(CLOCKS_PER_SEC) << " s" << std::endl; + std::cout << "reading mesh took " << (stop - start) / (double)(CLOCKS_PER_SEC) << " s" << std::endl; #endif - MeshLib::CFEMesh* mesh (mesh_vec[mesh_vec.size() - 1]); + MeshLib::CFEMesh* mesh(mesh_vec[mesh_vec.size() - 1]); mesh->setNumberOfNodesFromNodesVectorSize(); // *** read geometry -// ProjectData* project_data (new ProjectData); -// if (argc > 5) { -// GEOLIB::GEOObjects* geo_objs (new GEOLIB::GEOObjects); -// project_data->setGEOObjects (geo_objs); -// -// std::string schema_name("./OpenGeoSysGLI.xsd"); -// FileIO::XmlGmlInterface xml(project_data, schema_name); -// xml.readFile(QString::fromStdString (geo_fname_in)); -// std::vector original_geo_names; -// geo_objs->getGeometryNames(original_geo_names); -// } + // ProjectData* project_data (new ProjectData); + // if (argc > 5) { + // GEOLIB::GEOObjects* geo_objs (new GEOLIB::GEOObjects); + // project_data->setGEOObjects (geo_objs); + // + // std::string schema_name("./OpenGeoSysGLI.xsd"); + // FileIO::XmlGmlInterface xml(project_data, schema_name); + // xml.readFile(QString::fromStdString (geo_fname_in)); + // std::vector original_geo_names; + // geo_objs->getGeometryNames(original_geo_names); + // } // *** preparing test data std::vector const& nodes(mesh->getNodeVector()); std::vector pnts_for_search; n = std::min(n, nodes.size()); - for (size_t k(0); kgetData()); + for (size_t k(0); k < n; k++) + { + double const* const c(nodes[k]->getData()); // perturb the coordinates a little bit pnts_for_search.push_back(new GEOLIB::Point(c[0], c[1], c[2])); } - // *** test linear algorithm +// *** test linear algorithm // std::vector idx_found_nodes_linear_alg; // testNaiveAlgorithm(mesh, pnts_for_search, idx_found_nodes_linear_alg); @@ -401,43 +441,44 @@ int main (int argc, char* argv[]) mesh->constructMeshGrid(); #ifndef WIN32 unsigned mem_with_mesh_grid(mem_watch.getVirtMemUsage()); - std::cout << "MeshGrid Mem: " << (mem_with_mesh_grid-mem_without_mesh_grid)/(1024*1024) << " MB" << std::endl; + std::cout << "MeshGrid Mem: " << (mem_with_mesh_grid - mem_without_mesh_grid) / (1024 * 1024) << " MB" << std::endl; #endif // *** test mesh grid algorithm std::vector idx_found_nodes_mesh_grid_alg; testMeshGridAlgorithm(mesh, pnts_for_search, idx_found_nodes_mesh_grid_alg); -// std::cout << "compare results of linear algorithm with MeshGrid ... " << std::flush; -// for (size_t k(0); k idx_found_nodes_oct_tree; -// testOctTree(mesh, pnts_for_search, idx_found_nodes_oct_tree); + // std::vector idx_found_nodes_oct_tree; + // testOctTree(mesh, pnts_for_search, idx_found_nodes_oct_tree); // *** compare results -// std::cout << "compare results of linear algorithm with OctTree ... " << std::flush; -// for (size_t k(0); k errors; @@ -38,26 +38,33 @@ TEST(GEO, PointInPolygon) GEOLIB::Polygon polygon(*((*plys)[0])); std::cout << "creating test points ... " << std::flush; std::vector pnts; - for (size_t j(0); j < 320; j++) { - for (size_t k(0); k < 920; k++) { + for (size_t j(0); j < 320; j++) + { + for (size_t k(0); k < 920; k++) + { pnts.push_back(new GEOLIB::Point(0.9 + k / 100.0, -1.1 + j / 100.0, 0.0)); } } std::cout << pnts.size() << " created" << std::endl; - ASSERT_EQ (static_cast(pnts.size()), 294400); + ASSERT_EQ(static_cast(pnts.size()), 294400); - std::cout << "testing points ..." << std::endl; + std::cout << "testing points ..." << std::endl; const size_t size(pnts.size()); - for (size_t k(0); k < size; k++) { - if (polygon.isPntInPolygon(*(pnts[k]))) { + for (size_t k(0); k < size; k++) + { + if (polygon.isPntInPolygon(*(pnts[k]))) + { pnts_in_polygon->push_back(pnts[k]); - } else { + } + else + { pnts_outside_of_polygon->push_back(pnts[k]); } } - ASSERT_EQ (static_cast(pnts.size()), static_cast(pnts_in_polygon->size() + pnts_outside_of_polygon->size())); - ASSERT_EQ (static_cast(pnts_in_polygon->size()), 95511); - ASSERT_EQ (static_cast(pnts_outside_of_polygon->size()), 198889); + ASSERT_EQ(static_cast(pnts.size()), + static_cast(pnts_in_polygon->size() + pnts_outside_of_polygon->size())); + ASSERT_EQ(static_cast(pnts_in_polygon->size()), 95511); + ASSERT_EQ(static_cast(pnts_outside_of_polygon->size()), 198889); } diff --git a/tests/GEO/TestPointInTriangle.cpp b/tests/GEO/TestPointInTriangle.cpp index fbc20da23..7e998f90b 100644 --- a/tests/GEO/TestPointInTriangle.cpp +++ b/tests/GEO/TestPointInTriangle.cpp @@ -21,20 +21,26 @@ TEST(GEO, PointInTriangle) { - GEOLIB::Point pnt_a (0.0, 0.0, 0.0); - GEOLIB::Point pnt_b (1.0, 0.0, 0.0); - GEOLIB::Point pnt_c (0.0, 1.0, 0.0); + GEOLIB::Point pnt_a(0.0, 0.0, 0.0); + GEOLIB::Point pnt_b(1.0, 0.0, 0.0); + GEOLIB::Point pnt_c(0.0, 1.0, 0.0); - size_t n_x (10); - size_t n_y (10); + size_t n_x(10); + size_t n_y(10); - for (size_t i(0); i(i) - n_x/2.0)/n_x, (static_cast(j) - n_y/2.0)/n_y, 0.0); + for (size_t i(0); i < n_x; i++) + { + for (size_t j(0); j < n_y; j++) + { + GEOLIB::Point pnt_p((static_cast(i) - n_x / 2.0) / n_x, (static_cast(j) - n_y / 2.0) / n_y, + 0.0); std::cout << "(" << pnt_p[0] << ", " << pnt_p[1] << ") is " << std::flush; - if (MathLib::isPointInTriangle (&pnt_p, &pnt_a, &pnt_b, &pnt_c)) { + if (MathLib::isPointInTriangle(&pnt_p, &pnt_a, &pnt_b, &pnt_c)) + { std::cout << " in [(0.0, 0.0), (1.0, 0.0), (0.0, 1.0)]" << std::endl; - } else { + } + else + { std::cout << " *not* in [(0.0, 0.0), (1.0, 0.0), (0.0, 1.0)]" << std::endl; } } diff --git a/tests/Matrix/testMatrix.cpp b/tests/Matrix/testMatrix.cpp index 9e676cb3b..6927e4064 100644 --- a/tests/Matrix/testMatrix.cpp +++ b/tests/Matrix/testMatrix.cpp @@ -28,180 +28,179 @@ using Math_Group::Vec; TEST(MATRIX, test_class_Matrix) { - Matrix m(3,3); - - m(0, 0) = 1.; - m(0, 1) = 2.; - m(0, 2) = 3.; - // - m(1, 0) = 4.; - m(1, 1) = 5.; - m(1, 2) = 6.; - // - m(2, 0) = 7.; - m(2, 1) = 8.; - m(2, 2) = 9.; - - double x[3]; - double b[3]; - - x[0] = 1.0; - x[1] = 2.0; - x[2] = 3.0; - - b[0] = 0.0; - b[1] = 0.0; - b[2] = 0.0; - - m.multi(x, b); - ASSERT_EQ ( 14., b[0]); - ASSERT_EQ ( 32., b[1]); - ASSERT_EQ ( 50, b[2]); - - // Copy constructor - Matrix m1(m); - b[0] = 0.0; - b[1] = 0.0; - b[2] = 0.0; - m1.multi(x, b); - ASSERT_EQ ( 14., b[0]); - ASSERT_EQ ( 32., b[1]); - ASSERT_EQ ( 50, b[2]); - - Matrix m2(3,3); - m2 = 0.; - m1 = 1.0; - m.multi(m1, m2); - ASSERT_EQ ( 6., m2(0,1)); - ASSERT_EQ ( 15., m2(1,2)); - ASSERT_EQ ( 24., m2(2,0)); - - Matrix m3(3,3); - m2 = 1.0; - m3 = 0.; - m.multi(m1, m2, m3); - ASSERT_EQ ( 3*6., m3(0,1)); - ASSERT_EQ ( 3*15., m3(1,2)); - ASSERT_EQ ( 3*24., m3(2,0)); - - // Transpose - m.GetTranspose(m1); - x[0] = 1.0; - x[1] = 1.0; - x[2] = 1.0; - b[0] = 0.0; - b[1] = 0.0; - b[2] = 0.0; - m1.multi(x, b); - ASSERT_EQ ( 12., b[0]); - ASSERT_EQ ( 15., b[1]); - ASSERT_EQ ( 18., b[2]); - - // - m = 1.0; - m *= 10.; - m /=2.0; - m += 5.0; - b[0] = 0.0; - b[1] = 0.0; - b[2] = 0.0; - m.multi(x, b); - ASSERT_EQ ( 30., b[0]); - ASSERT_EQ ( 30., b[1]); - ASSERT_EQ ( 30., b[2]); - - m1 = m; - m1 += m; - m1 -= m; - b[0] = 0.0; - b[1] = 0.0; - b[2] = 0.0; - m1.multi(x, b); - ASSERT_EQ ( 30., b[0]); - ASSERT_EQ ( 30., b[1]); - ASSERT_EQ ( 30., b[2]); + Matrix m(3, 3); + + m(0, 0) = 1.; + m(0, 1) = 2.; + m(0, 2) = 3.; + // + m(1, 0) = 4.; + m(1, 1) = 5.; + m(1, 2) = 6.; + // + m(2, 0) = 7.; + m(2, 1) = 8.; + m(2, 2) = 9.; + + double x[3]; + double b[3]; + + x[0] = 1.0; + x[1] = 2.0; + x[2] = 3.0; + + b[0] = 0.0; + b[1] = 0.0; + b[2] = 0.0; + + m.multi(x, b); + ASSERT_EQ(14., b[0]); + ASSERT_EQ(32., b[1]); + ASSERT_EQ(50, b[2]); + + // Copy constructor + Matrix m1(m); + b[0] = 0.0; + b[1] = 0.0; + b[2] = 0.0; + m1.multi(x, b); + ASSERT_EQ(14., b[0]); + ASSERT_EQ(32., b[1]); + ASSERT_EQ(50, b[2]); + + Matrix m2(3, 3); + m2 = 0.; + m1 = 1.0; + m.multi(m1, m2); + ASSERT_EQ(6., m2(0, 1)); + ASSERT_EQ(15., m2(1, 2)); + ASSERT_EQ(24., m2(2, 0)); + + Matrix m3(3, 3); + m2 = 1.0; + m3 = 0.; + m.multi(m1, m2, m3); + ASSERT_EQ(3 * 6., m3(0, 1)); + ASSERT_EQ(3 * 15., m3(1, 2)); + ASSERT_EQ(3 * 24., m3(2, 0)); + + // Transpose + m.GetTranspose(m1); + x[0] = 1.0; + x[1] = 1.0; + x[2] = 1.0; + b[0] = 0.0; + b[1] = 0.0; + b[2] = 0.0; + m1.multi(x, b); + ASSERT_EQ(12., b[0]); + ASSERT_EQ(15., b[1]); + ASSERT_EQ(18., b[2]); + + // + m = 1.0; + m *= 10.; + m /= 2.0; + m += 5.0; + b[0] = 0.0; + b[1] = 0.0; + b[2] = 0.0; + m.multi(x, b); + ASSERT_EQ(30., b[0]); + ASSERT_EQ(30., b[1]); + ASSERT_EQ(30., b[2]); + + m1 = m; + m1 += m; + m1 -= m; + b[0] = 0.0; + b[1] = 0.0; + b[2] = 0.0; + m1.multi(x, b); + ASSERT_EQ(30., b[0]); + ASSERT_EQ(30., b[1]); + ASSERT_EQ(30., b[2]); } TEST(MATRIX, test_class_SymMatrix) { - SymMatrix m(3); - - m(0, 0) = 1.; - // - m(1, 0) = 4.; - m(1, 1) = 5.; - // - m(2, 0) = 7.; - m(2, 1) = 8.; - m(2, 2) = 9.; - - ASSERT_EQ ( 4., m(0,1)); - ASSERT_EQ ( 7., m(0,2)); - ASSERT_EQ ( 8., m(1,2)); - - Vec x(3); - Vec b(3); - - x = 1.0; - b = 0.0; - m.multi(x.getEntryArray(), b.getEntryArray()); - ASSERT_EQ ( 12., b[0]); - ASSERT_EQ ( 17., b[1]); - ASSERT_EQ ( 24., b[2]); - - // Copy constructor - SymMatrix m1(m); - b = 0.0; - m1.multi(x.getEntryArray(), b.getEntryArray()); - ASSERT_EQ ( 12., b[0]); - ASSERT_EQ ( 17., b[1]); - ASSERT_EQ ( 24., b[2]); - - Matrix m2(3, 3); - m2 = 0.; - m1 = 1.0; - m.multi(m1, m2); - ASSERT_EQ ( 12., m2(0,1)); - ASSERT_EQ ( 17., m2(1,2)); - ASSERT_EQ ( 24., m2(2,0)); - - Matrix m3(3, 3); - m2 = 1.0; - m3 = 0.; - m.multi(m1, m2, m3); - ASSERT_EQ ( 3*12., m3(0,1)); - ASSERT_EQ ( 3*17., m3(1,2)); - ASSERT_EQ ( 3*24., m3(2,0)); + SymMatrix m(3); + + m(0, 0) = 1.; + // + m(1, 0) = 4.; + m(1, 1) = 5.; + // + m(2, 0) = 7.; + m(2, 1) = 8.; + m(2, 2) = 9.; + + ASSERT_EQ(4., m(0, 1)); + ASSERT_EQ(7., m(0, 2)); + ASSERT_EQ(8., m(1, 2)); + + Vec x(3); + Vec b(3); + + x = 1.0; + b = 0.0; + m.multi(x.getEntryArray(), b.getEntryArray()); + ASSERT_EQ(12., b[0]); + ASSERT_EQ(17., b[1]); + ASSERT_EQ(24., b[2]); + + // Copy constructor + SymMatrix m1(m); + b = 0.0; + m1.multi(x.getEntryArray(), b.getEntryArray()); + ASSERT_EQ(12., b[0]); + ASSERT_EQ(17., b[1]); + ASSERT_EQ(24., b[2]); + + Matrix m2(3, 3); + m2 = 0.; + m1 = 1.0; + m.multi(m1, m2); + ASSERT_EQ(12., m2(0, 1)); + ASSERT_EQ(17., m2(1, 2)); + ASSERT_EQ(24., m2(2, 0)); + + Matrix m3(3, 3); + m2 = 1.0; + m3 = 0.; + m.multi(m1, m2, m3); + ASSERT_EQ(3 * 12., m3(0, 1)); + ASSERT_EQ(3 * 17., m3(1, 2)); + ASSERT_EQ(3 * 24., m3(2, 0)); } TEST(MATRIX, test_class_Vec) { - Vec a(3); + Vec a(3); - a = 1.; - ASSERT_EQ ( 1., a[2]); + a = 1.; + ASSERT_EQ(1., a[2]); - a[2] = 5; - ASSERT_EQ ( 5., a[2]); + a[2] = 5; + ASSERT_EQ(5., a[2]); - a *= 2.; - ASSERT_EQ ( 10., a[2]); + a *= 2.; + ASSERT_EQ(10., a[2]); - a /= 5.; - ASSERT_EQ ( 2., a[2]); + a /= 5.; + ASSERT_EQ(2., a[2]); - a += 5.; - ASSERT_EQ ( 7., a[2]); + a += 5.; + ASSERT_EQ(7., a[2]); - Vec b(3); + Vec b(3); - b = a; - ASSERT_EQ ( 7., b[2]); + b = a; + ASSERT_EQ(7., b[2]); - b += a; - ASSERT_EQ ( 14., b[2]); + b += a; + ASSERT_EQ(14., b[2]); - b -= a; - ASSERT_EQ ( 7., b[2]); + b -= a; + ASSERT_EQ(7., b[2]); } - diff --git a/tests/logging.h b/tests/logging.h index f28f2937d..ce8d45515 100644 --- a/tests/logging.h +++ b/tests/logging.h @@ -4,29 +4,25 @@ #ifndef NERROR #define PRINT_ERROR(x) #else -#define PRINT_ERROR(x) \ - cout << "Error! : " << x ; // Note: No endl, for flexibility +#define PRINT_ERROR(x) cout << "Error! : " << x; // Note: No endl, for flexibility #endif #ifndef NDEBUG #define PRINT_DEBUG(x) #else -#define PRINT_DEBUG(x) \ - cout << "Debug : " << #x << ":\t" << x << endl; +#define PRINT_DEBUG(x) cout << "Debug : " << #x << ":\t" << x << endl; #endif #ifndef NWARNING #define PRINT_WARNING(x) #else -#define PRINT_WARNING(x) \ - cout << "Warning! : " << x ; // Note: No endl, for flexibility +#define PRINT_WARNING(x) cout << "Warning! : " << x; // Note: No endl, for flexibility #endif #ifndef NINFO #define PRINT_INFO(x) #else -#define PRINT_INFO(x) \ - cout << "Info :"x ; // Note: No endl, for flexibility +#define PRINT_INFO(x) cout << "Info :" x; // Note: No endl, for flexibility #endif #endif // LOGGING_INCLUDE diff --git a/tests/testBase.cpp b/tests/testBase.cpp index 3430daef2..b54a3cf21 100644 --- a/tests/testBase.cpp +++ b/tests/testBase.cpp @@ -15,26 +15,29 @@ #include "swap.h" -TEST(Base, SwapInt) { +TEST(Base, SwapInt) +{ int arg0 = 5; int arg1 = 10; - BASELIB::swap(arg0, arg1); - ASSERT_EQ ( arg0, 10 ); - ASSERT_EQ ( arg1, 5 ); + BASELIB::swap(arg0, arg1); + ASSERT_EQ(arg0, 10); + ASSERT_EQ(arg1, 5); } -TEST(Base, SwapDouble) { +TEST(Base, SwapDouble) +{ double arg0 = 5.0; double arg1 = 10.0; BASELIB::swap(arg0, arg1); - ASSERT_EQ ( arg0, 10.0 ); - ASSERT_EQ ( arg1, 5.0 ); + ASSERT_EQ(arg0, 10.0); + ASSERT_EQ(arg1, 5.0); } -TEST(Base, SwapString) { +TEST(Base, SwapString) +{ std::string arg0 = "5"; std::string arg1 = "10"; BASELIB::swap(arg0, arg1); - ASSERT_EQ ( arg0, std::string("10") ); - ASSERT_EQ ( arg1, std::string("5") ); + ASSERT_EQ(arg0, std::string("10")); + ASSERT_EQ(arg1, std::string("5")); } diff --git a/tests/testGeo.cpp b/tests/testGeo.cpp index 5856ff983..99a424657 100644 --- a/tests/testGeo.cpp +++ b/tests/testGeo.cpp @@ -27,7 +27,7 @@ TEST(GEO, PointInPolygon) { - GEOLIB::GEOObjects* _geo (new GEOLIB::GEOObjects); + GEOLIB::GEOObjects* _geo(new GEOLIB::GEOObjects); std::string fname(BuildInfo::SOURCEPATH); fname += "/tests/data/GEO/TestDataPointInPolygon.gli"; FileIO::readGLIFileV4(fname, _geo); @@ -37,26 +37,33 @@ TEST(GEO, PointInPolygon) GEOLIB::Polygon polygon(*((*plys)[0])); std::cout << "creating test points ... " << std::flush; std::vector pnts; - for (size_t j(0); j < 320; j++) { - for (size_t k(0); k < 920; k++) { + for (size_t j(0); j < 320; j++) + { + for (size_t k(0); k < 920; k++) + { pnts.push_back(new GEOLIB::Point(0.9 + k / 100.0, -1.1 + j / 100.0, 0.0)); } } std::cout << pnts.size() << " created" << std::endl; - ASSERT_EQ (static_cast(pnts.size()), 294400); + ASSERT_EQ(static_cast(pnts.size()), 294400); - std::cout << "testing points ..." << std::endl; + std::cout << "testing points ..." << std::endl; const size_t size(pnts.size()); - for (size_t k(0); k < size; k++) { - if (polygon.isPntInPolygon(*(pnts[k]))) { + for (size_t k(0); k < size; k++) + { + if (polygon.isPntInPolygon(*(pnts[k]))) + { pnts_in_polygon->push_back(pnts[k]); - } else { + } + else + { pnts_outside_of_polygon->push_back(pnts[k]); } } - ASSERT_EQ (static_cast(pnts.size()), static_cast(pnts_in_polygon->size() + pnts_outside_of_polygon->size())); - ASSERT_EQ (static_cast(pnts_in_polygon->size()), 95512); - ASSERT_EQ (static_cast(pnts_outside_of_polygon->size()), 198888); + ASSERT_EQ(static_cast(pnts.size()), + static_cast(pnts_in_polygon->size() + pnts_outside_of_polygon->size())); + ASSERT_EQ(static_cast(pnts_in_polygon->size()), 95512); + ASSERT_EQ(static_cast(pnts_outside_of_polygon->size()), 198888); } diff --git a/tests/testrunner.cpp b/tests/testrunner.cpp index f8e80c810..dbab04d13 100644 --- a/tests/testrunner.cpp +++ b/tests/testrunner.cpp @@ -15,6 +15,6 @@ int main(int argc, char* argv[]) { - testing::InitGoogleTest ( &argc, argv ); - return RUN_ALL_TESTS(); + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); }