|
[Sponsors] |
Export matrix of coefficients into a .txt file |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
September 8, 2020, 06:45 |
Export matrix of coefficients into a .txt file
|
#1 |
New Member
Join Date: Sep 2020
Posts: 9
Rep Power: 6 |
Dear members,
I am new to OpenFoam and I am trying to modify the icoFoam solver to export the matrix of coefficients UEqn into a text file readable by Matlab. What is the easiest way? I am really new to C++ too and I can't compile the solver without errors. May you help? Thanks in advance, Andrea |
|
September 8, 2020, 09:17 |
|
#2 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
Quote:
Changing any solver to simply dump out a matrix of coefficients is really not a good idea. It falls apart when you want to try the same for a different field, for a slightly different solver, or when you upgrade versions. Provided that you do not yet wish to examine the coefficients for the pressure equation, you can implement your writing routine as a matrix constraint that does not modify the coefficients, but only prints them out. If you are new to OpenFOAM and to C++, it will not be completely easy in any case. You need to walk the OpenFOAM sparse matrix storage, and also handle processor-to-processor connections. If you want a bit of code to start from, I have revived some old code (temporarily?) that probably does most of what you want, or at least can give you some ideas. It dumps coefficients in a MatrixMarket format. Although it is from 2018, it should compile OK with OpenFOAM-v1906,1912,2006. I cannot remember if there is anything missing or broken in it. https://develop.openfoam.com/modules...src/dumpMatrix |
||
September 9, 2020, 22:28 |
|
#3 | |
New Member
Duc Anh
Join Date: Dec 2018
Posts: 22
Rep Power: 8 |
Quote:
To start, the document below will give you some simple suggestions https://www.foamacademy.com/wp-conte...2018matrix.pdf |
||
September 10, 2020, 13:30 |
|
#4 | |
New Member
Join Date: Sep 2020
Posts: 9
Rep Power: 6 |
Quote:
thanks for the useful documentation. I tried to write the code as follows: Code:
fvVectorMatrix UEqn ( fvm::laplacian(nu, U)- fvm::div(phi_zero, U)- fvc::div(phi,U_zero) ); label NC = mesh.nCells(); //Number of cells simpleMatrix<scalar> A(NC); //Coeff.matrix // Initialization of matrix for(label i=0; i<NC; i++) { A.source()[i] = 0.0; for(label j=0; j<NC; j++) { A[i][j] = 0.0; } } // Assigning diagonal coefficients for(label i=0; i<NC; i++) { A[i][i] = UEqn.diag()[i]; } // Assigning off-diagonal coefficients for(label faceI=0; faceI<UEqn.lduAddr().lowerAddr().size(); faceI++) { label l = UEqn.lduAddr().lowerAddr()[faceI]; label u = UEqn.lduAddr().upperAddr()[faceI]; A[l][u] = UEqn.upper()[faceI]; A[u][l] = UEqn.upper()[faceI]; } // Assigning contribution from BC forAll(U.boundaryField(), patchI) { const fvPatch &pp = U.boundaryField()[patchI].patch(); forAll(pp, faceI) { label cellI = pp.faceCells()[faceI]; A[cellI][cellI] += UEqn.internalCoeffs()[patchI][faceI]; A.source()[cellI] += UEqn.boundaryCoeffs()[patchI][faceI]; } } Info << "\n==Coefficients of Matrix A=="<< endl; for(label i=0; i<NC; i++) { for(label j=0; j<NC; j++) { Info<< A[i][j] << " "; } Info<< A.source()[i] << endl; } [/CODE] error: no match for ‘operator+=’ (operand types are ‘double’ and ‘Foam::Vector<double>’) A[cellI][cellI] += UEqn.internalCoeffs()[patchI][faceI]; [/CODE] How do I overcome it? Thanks in Advance Andrea |
||
September 11, 2020, 03:55 |
|
#5 |
Senior Member
|
||
August 10, 2022, 14:54 |
|
#6 |
New Member
Join Date: Jun 2022
Posts: 19
Rep Power: 4 |
@Mr. Olesen, The link you provided is broken. Was there a problem with the code?
@Mr. Lahaye, can gdbOf print the coefficients in a parallel run? |
|
August 11, 2022, 03:51 |
|
#7 |
Senior Member
|
@tommyJ: not sure.
Possibly yes: gdb seems to support parallel runs. Possibly no: in parallel, OpenFoam stores the matrix per processor in separate (diagonal and off-diagonal blocks), and the macros provided in OFgdb might not extend to this situation. Possibly OFgdb can be extended to treat this case. |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[swak4Foam] Installation Problem with OF 6 version | Aurel | OpenFOAM Community Contributions | 14 | November 18, 2020 17:18 |
[foam-extend.org] Problems installing foam-extend-4.0 on openSUSE 42.2 and Ubuntu 16.04 | ordinary | OpenFOAM Installation | 19 | September 3, 2019 19:13 |
A CFX-POST error (ver 14.5.7) | wangyflp88 | CFX | 2 | July 22, 2017 01:17 |
[swak4Foam] swak4foam building problem | GGerber | OpenFOAM Community Contributions | 54 | April 24, 2015 17:02 |
[swak4Foam] build problem swak4Foam OF 2.2.0 | mcathela | OpenFOAM Community Contributions | 14 | April 23, 2013 14:59 |