Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / applications / solvers / solidMechanics / deprecatedSolvers / materialModels / fvPatchFields / cohesiveLaw / cohesiveLawFvPatchVectorField.C
blobad387f24677c541aee4f7b3925842621eec84271
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation, either version 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 Description
26 \*---------------------------------------------------------------------------*/
28 #include "cohesiveLawFvPatchVectorField.H"
29 #include "addToRunTimeSelectionTable.H"
30 #include "volFields.H"
31 #include "rheologyModel.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 namespace Foam
38 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
40 cohesiveLawFvPatchVectorField::cohesiveLawFvPatchVectorField
42     const fvPatch& p,
43     const DimensionedField<vector, volMesh>& iF
46     fixedGradientFvPatchVectorField(p, iF),
47     cohesiveLawPtr_(NULL),
48     relaxationFactor_(1.0),
49     traction_(p.size(), vector::zero)
53 cohesiveLawFvPatchVectorField::cohesiveLawFvPatchVectorField
55     const fvPatch& p,
56     const DimensionedField<vector, volMesh>& iF,
57     const dictionary& dict
60     fixedGradientFvPatchVectorField(p, iF),
61     cohesiveLawPtr_
62     (
63         cohesiveLaw::New(dict.lookup("cohesiveLaw"), dict).ptr()
64     ),
65     relaxationFactor_(readScalar(dict.lookup("relaxationFactor"))),
66     traction_(p.size(), vector::zero)
68     fvPatchVectorField::operator=(patchInternalField());
69     gradient() = vector::zero;
73 cohesiveLawFvPatchVectorField::cohesiveLawFvPatchVectorField
75     const cohesiveLawFvPatchVectorField& cpf
78     fixedGradientFvPatchVectorField(cpf),
79     cohesiveLawPtr_(cpf.cohesiveLawPtr_->clone().ptr()),
80     relaxationFactor_(cpf.relaxationFactor_),
81     traction_(cpf.traction_)
85 cohesiveLawFvPatchVectorField::cohesiveLawFvPatchVectorField
87     const cohesiveLawFvPatchVectorField& cpf,
88     const fvPatch& p,
89     const DimensionedField<vector, volMesh>& iF,
90     const fvPatchFieldMapper& mapper
93     fixedGradientFvPatchVectorField(cpf, p, iF, mapper),
94     cohesiveLawPtr_(cpf.cohesiveLawPtr_->clone().ptr()),
95     relaxationFactor_(cpf.relaxationFactor_),
96     traction_(cpf.traction_, mapper)
100 cohesiveLawFvPatchVectorField::cohesiveLawFvPatchVectorField
102     const cohesiveLawFvPatchVectorField& cpf,
103     const DimensionedField<vector, volMesh>& iF
106     fixedGradientFvPatchVectorField(cpf, iF),
107     cohesiveLawPtr_(cpf.cohesiveLawPtr_->clone().ptr()),
108     relaxationFactor_(cpf.relaxationFactor_),
109     traction_(cpf.traction_)
113 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
115 const cohesiveLaw& cohesiveLawFvPatchVectorField::law() const
117     if (!cohesiveLawPtr_)
118     {
119         FatalErrorIn
120         (
121             "const cohesiveLaw& cohesiveLawFvPatchVectorField::law() const"
122         )   << "Law pointer not set" << abort(FatalError);
123     }
125     return *cohesiveLawPtr_;
129 void cohesiveLawFvPatchVectorField::autoMap
131     const fvPatchFieldMapper& m
134     if (cohesiveLawPtr_ == NULL)
135     {
136         FatalErrorIn("cohesiveFvPatchVectorField::autoMap")
137             << "NULL cohesive law"
138             << abort(FatalError);
139     }
141     fixedGradientFvPatchVectorField::autoMap(m);
143     traction_.autoMap(m);
147 // Reverse-map the given fvPatchField onto this fvPatchField
148 void cohesiveLawFvPatchVectorField::rmap
150     const fvPatchVectorField& ptf,
151     const labelList& addr
154     fixedGradientFvPatchVectorField::rmap(ptf, addr);
156     const cohesiveLawFvPatchVectorField& dmptf =
157         refCast<const cohesiveLawFvPatchVectorField>(ptf);
159     // No need to grab the cohesive zone pointer more than once
160     if (!cohesiveLawPtr_)
161     {
162         cohesiveLawPtr_ = dmptf.cohesiveLawPtr_->clone().ptr();
164         relaxationFactor_ = dmptf.relaxationFactor_;
165     }
167     traction_.rmap(dmptf.traction_, addr);
171 // Update the coefficients associated with the patch field
172 void cohesiveLawFvPatchVectorField::updateCoeffs()
174     if (updated())
175     {
176         return;
177     }
179     // Looking up rheology
181     const fvPatchField<scalar>& mu =
182         patch().lookupPatchField<volScalarField, scalar>("mu");
184     const fvPatchField<scalar>& lambda =
185       patch().lookupPatchField<volScalarField, scalar>("lambda");
187     vectorField n = patch().nf();
189     const fvPatchField<tensor>& gradU =
190         patch().lookupPatchField<volTensorField, tensor>("grad(U)");
192     // Patch displacement
193     const vectorField& U = *this;
195     // Patch stress
196     tensorField sigma = mu*(gradU + gradU.T()) + I*(lambda*tr(gradU));
198     // Normal stress component
199     scalarField sigmaN = (n & (n & sigma));
201     scalarField delta = -(n & U);
203     label sizeByTwo = patch().size()/2;
205     for(label i = 0; i < sizeByTwo; i++)
206     {
207         scalar tmp = delta[i];
208         delta[i] += delta[sizeByTwo + i];
209         delta[sizeByTwo + i] += tmp;
210     }
212     forAll (traction_, faceI)
213     {
214         if (delta[faceI] < 0)
215         {
216             // Return from traction to symmetryPlane??
217             traction_[faceI] = law().sigmaMax().value()*n[faceI];
218         }
219         else if(delta[faceI] > law().deltaC().value())
220         {
221             // Traction free
222             traction_[faceI] = vector::zero;
223         }
224         else
225         {
226             // Calculate cohesive traction from cohesive zone model
227             traction_[faceI] = law().traction(delta[faceI])*n[faceI];
228         }
229     }
231     gradient() =
232     (
233         traction_
234       - (n & (mu*gradU.T() - (mu + lambda)*gradU))
235       - n*lambda*tr(gradU)
236     )/(2.0*mu + lambda);
238     fixedGradientFvPatchVectorField::updateCoeffs();
242 // Write
243 void cohesiveLawFvPatchVectorField::write(Ostream& os) const
245     fvPatchVectorField::write(os);
246     traction_.writeEntry("traction", os);
247     os.writeKeyword("cohesiveLaw") << law().type()
248         << token::END_STATEMENT << nl;
249     os.writeKeyword("relaxationFactor") << relaxationFactor_
250         << token::END_STATEMENT << nl;
251     law().writeDict(os);
252     writeEntry("value", os);
256 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
258 makePatchTypeField(fvPatchVectorField, cohesiveLawFvPatchVectorField);
260 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
262 } // End namespace Foam
264 // ************************************************************************* //