|
[Sponsors] |
In least square gradient method, which step solve the least square problem. |
![]() |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
![]() |
![]() |
#1 |
Senior Member
|
I Cann't find the step to solve the least square problem Ax=b for the gradient. Could you give me some suggestions
Code:
template<class Type> Foam::tmp < Foam::GeometricField < typename Foam::outerProduct<Foam::vector, Type>::type, Foam::fvPatchField, Foam::volMesh > > Foam::fv::leastSquaresGrad<Type>::calcGrad ( const GeometricField<Type, fvPatchField, volMesh>& vsf, const word& name ) const { typedef typename outerProduct<vector, Type>::type GradType; const fvMesh& mesh = vsf.mesh(); tmp<GeometricField<GradType, fvPatchField, volMesh>> tlsGrad ( new GeometricField<GradType, fvPatchField, volMesh> ( IOobject ( name, vsf.instance(), mesh, IOobject::NO_READ, IOobject::NO_WRITE ), mesh, dimensioned<GradType>(vsf.dimensions()/dimLength, Zero), extrapolatedCalculatedFvPatchField<GradType>::typeName ) ); GeometricField<GradType, fvPatchField, volMesh>& lsGrad = tlsGrad.ref(); // Get reference to least square vectors const leastSquaresVectors& lsv = leastSquaresVectors::New(mesh); const surfaceVectorField& ownLs = lsv.pVectors(); const surfaceVectorField& neiLs = lsv.nVectors(); const labelUList& own = mesh.owner(); const labelUList& nei = mesh.neighbour(); forAll(own, facei) { label ownFacei = own[facei]; label neiFacei = nei[facei]; Type deltaVsf = vsf[neiFacei] - vsf[ownFacei]; lsGrad[ownFacei] += ownLs[facei]*deltaVsf; lsGrad[neiFacei] -= neiLs[facei]*deltaVsf; } // Boundary faces forAll(vsf.boundaryField(), patchi) { const fvsPatchVectorField& patchOwnLs = ownLs.boundaryField()[patchi]; const labelUList& faceCells = vsf.boundaryField()[patchi].patch().faceCells(); if (vsf.boundaryField()[patchi].coupled()) { const Field<Type> neiVsf ( vsf.boundaryField()[patchi].patchNeighbourField() ); forAll(neiVsf, patchFacei) { lsGrad[faceCells[patchFacei]] += patchOwnLs[patchFacei] *(neiVsf[patchFacei] - vsf[faceCells[patchFacei]]); } } else { const fvPatchField<Type>& patchVsf = vsf.boundaryField()[patchi]; forAll(patchVsf, patchFacei) { lsGrad[faceCells[patchFacei]] += patchOwnLs[patchFacei] *(patchVsf[patchFacei] - vsf[faceCells[patchFacei]]); } } } lsGrad.correctBoundaryConditions(); gaussGrad<Type>::correctBoundaryConditions(vsf, lsGrad); return tlsGrad; } |
|
![]() |
![]() |
![]() |
![]() |
#2 |
Senior Member
Join Date: Aug 2015
Posts: 494
Rep Power: 15 ![]() |
Is it not in leastSquaresVectors? A quick look at that code reveals that it contains an inversion step. Note I've not done a deep dive into the code, but it looks like a good place to start.
Caelan |
|
![]() |
![]() |
![]() |
![]() |
#3 |
Senior Member
|
Thanks a lot, i have find it. It was calculated in the constructor().
|
|
![]() |
![]() |
![]() |
![]() |
#4 |
Senior Member
Santiago Marquez Damian
Join Date: Aug 2009
Location: Santa Fe, Santa Fe, Argentina
Posts: 452
Rep Power: 24 ![]() |
Hi, its is done in two steps, the geometrical part (this not change if mesh is static) is precomputed in leastSquaresVectors, then the gradient is finally computed in calcGrad method.
Regards!
__________________
Santiago MÁRQUEZ DAMIÁN, Ph.D. Research Scientist Research Center for Computational Methods (CIMEC) - CONICET/UNL Tel: 54-342-4511594 Int. 7032 Colectora Ruta Nac. 168 / Paraje El Pozo (3000) Santa Fe - Argentina. http://www.cimec.org.ar |
|
![]() |
![]() |
![]() |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
courant number increases to rather large values | 6863523 | OpenFOAM Running, Solving & CFD | 22 | July 5, 2023 23:48 |
p_rgh initial residual no change with different settings | manuc | OpenFOAM Running, Solving & CFD | 3 | June 26, 2018 15:53 |
Stuck in a Rut- interDyMFoam! | xoitx | OpenFOAM Running, Solving & CFD | 14 | March 25, 2016 07:09 |
extremely simple problem... can you solve it properly? | Mikhail | Main CFD Forum | 40 | September 9, 1999 09:11 |
use of MAC method to solve sloshing problem. | S.R.SAHI | Main CFD Forum | 1 | April 15, 1999 22:28 |