Fixing indentation in applications/solvers/solidMechanics
[foam-extend-3.2.git] / applications / solvers / solidMechanics / elasticIncrAcpSolidFoam / createCrack.H
blobffbd5a14c5456d55f78c613256737789769c441e
1     label cohesivePatchID = -1;
3     solidCohesiveFvPatchVectorField* cohesivePatchDUPtr = NULL;
4     solidCohesiveFixedModeMixFvPatchVectorField* cohesivePatchDUFixedModePtr = NULL;
6     forAll (DU.boundaryField(), patchI)
7     {
8         if (isA<solidCohesiveFvPatchVectorField>(DU.boundaryField()[patchI]))
9         {
10             cohesivePatchID = patchI;
11             cohesivePatchDUPtr =
12                 &refCast<solidCohesiveFvPatchVectorField>
13                 (
14                     DU.boundaryField()[cohesivePatchID]
15                 );
16             break;
17         }
18         else if (isA<solidCohesiveFixedModeMixFvPatchVectorField>(DU.boundaryField()[patchI]))
19         {
20             cohesivePatchID = patchI;
21             cohesivePatchDUFixedModePtr =
22                 &refCast<solidCohesiveFixedModeMixFvPatchVectorField>
23                 (
24                     DU.boundaryField()[cohesivePatchID]
25                 );
26             break;
27         }
28     }
30     if(cohesivePatchID == -1)
31     {
32         FatalErrorIn(args.executable())
33             << "Can't find cohesiveLawFvPatch" << nl
34             << "One of the boundary patches in " << DU.name() << ".boundaryField() "
35             << "should be of type " << solidCohesiveFvPatchVectorField::typeName
36             << "or " << solidCohesiveFixedModeMixFvPatchVectorField::typeName
37             << abort(FatalError);
38     }
40     // solidCohesiveFvPatchVectorField& cohesivePatchDU =
41     //     refCast<solidCohesiveFvPatchVectorField>
42     //     (
43     //         DU.boundaryField()[cohesivePatchID]
44     //     );
46     // philipc: I have moved cohesive stuff to constitutiveModel
47     // cohesiveZone is an index field
48     // which allows the user to limit the crack to certain areas at runtime
49     // 1 for faces within cohesiveZone
50     // 0 for faces outside cohesiveZone
51     surfaceScalarField cohesiveZone
52     (
53         IOobject
54         (
55             "cohesiveZone",
56             runTime.timeName(),
57             mesh,
58             IOobject::READ_IF_PRESENT,
59             IOobject::AUTO_WRITE
60         ),
61         mesh,
62         dimensionedScalar("zero", dimless, 0.0)
63      );
65     // limit crack to specified boxes
66     {
67         const dictionary& stressControl =
68             mesh.solutionDict().subDict("solidMechanics");
70         List<boundBox> userBoxes(stressControl.lookup("crackLimitingBoxes"));
71         const surfaceVectorField& Cf = mesh.Cf();
72         //int numPossibleCrackFaces = 0;
73         forAll(cohesiveZone.internalField(), faceI)
74         {
75             bool faceInsideBox = false;
77             forAll(userBoxes, boxi)
78             {
79                 if(userBoxes[boxi].contains(Cf.internalField()[faceI])) faceInsideBox = true;
80             }
82             if(faceInsideBox)
83             {
84                 cohesiveZone.internalField()[faceI] = 1.0;
85                 //numPossibleCrackFaces++;
86             }
87         }
88         //reduce(numPossibleCrackFaces, sumOp<int>());
90         forAll(cohesiveZone.boundaryField(), patchI)
91         {
92             // cracks may go along proc boundaries
93             if(mesh.boundaryMesh()[patchI].type() == processorPolyPatch::typeName)
94             {
95                 forAll(cohesiveZone.boundaryField()[patchI], faceI)
96                 {
97                     bool faceInsideBox = false;
99                     forAll(userBoxes, boxi)
100                     {
101                         if(userBoxes[boxi].contains(Cf.boundaryField()[patchI][faceI])) faceInsideBox = true;
102                     }
104                     if(faceInsideBox)
105                     {
106                         cohesiveZone.boundaryField()[patchI][faceI] = 1.0;
107                     }
108                 }
110         // numPossibleCrackFaces += int(sum(cohesiveZone.boundaryField()[patchI]));
111         // philipc multiMat cracks not working on proc boundaries yet... disable for now
112         // found the problem: solidInterface needs to know about mesh changes so
113         // I make a new one each time there is a crack
114         // int numProcFaces = int(sum(cohesiveZone.boundaryField()[patchI]));
115 //           if(numProcFaces > 0)
116 //           {
117 //               cohesiveZone.boundaryField()[patchI] = 0.0;
118 //               Warning << "Processor boundary cracking is "
119 //                << "disabled because it is not working yet for multi-materials." << nl
120 //                << "There are " << numProcFaces << " possible cracks "
121 //                << "faces on processor boundary " << mesh.boundary()[patchI].name()
122 //                   << ", which are not allowed to crack." << endl;
123 //           }
124             }
125         }
127         //       Info << "\nNumber of possible cracking faces is " << numPossibleCrackFaces << endl;
128         Info << "\nThere are " << gSum(cohesiveZone.internalField()) << " potential internal crack faces" << nl << endl;
129         Info << "\nThere are " << gSum(cohesiveZone.boundaryField())/2 << " potential coupled boundary crack faces" << nl << endl;
131         // write field for visualisation
132         volScalarField cohesiveZoneVol
133         (
134             IOobject
135             (
136                 "cohesiveZoneVol",
137                 runTime.timeName(),
138                 mesh,
139                 IOobject::NO_READ,
140                 IOobject::AUTO_WRITE
141             ),
142             mesh,
143             dimensionedScalar("zero", dimless, 0.0)
144         );
146         forAll(cohesiveZone.internalField(), facei)
147         {
148             if(cohesiveZone.internalField()[facei])
149             {
150                 cohesiveZoneVol.internalField()[mesh.owner()[facei]] = 1.0;
151                 cohesiveZoneVol.internalField()[mesh.neighbour()[facei]] = 1.0;
152             }
153         }
155         forAll(cohesiveZone.boundaryField(), patchi)
156         {
157             forAll(cohesiveZone.boundaryField()[patchi], facei)
158             {
159                 if(cohesiveZone.boundaryField()[patchi][facei] > 0.0)
160                 {
161                     cohesiveZoneVol.boundaryField()[patchi][facei] = 1.0;
162                 }
163             }
164         }
165         Info << "Writing cohesiveZone field" << endl;
166         cohesiveZoneVol.write();
167     }
170     Switch initialiseSolution(false);
172     if
173     (
174         mesh.solutionDict().subDict("solidMechanics")
175        .found("initialiseSolution")
176     )
177     {
178         initialiseSolution =
179             Switch
180             (
181                 mesh.solutionDict().subDict("solidMechanics").lookup
182                 (
183                     "initialiseSolution"
184                 )
185             );
186     }
189     Switch breakOnlyOneFacePerTopologyChange(true);
191     if
192     (
193         mesh.solutionDict().subDict("solidMechanics")
194        .found("breakOnlyOneFacePerTopologyChange")
195     )
196     {
197         breakOnlyOneFacePerTopologyChange =
198             Switch
199             (
200                 mesh.solutionDict().subDict("solidMechanics").lookup
201                 (
202                     "breakOnlyOneFacePerTopologyChange"
203                 )
204             );
205     }
208     Switch crackPropagationFromSpecifiedPatches
209     (
210         mesh.solutionDict().subDict("solidMechanics").lookup
211         (
212             "crackPropagationFromSpecifiedPatches"
213         )
214     );
216     wordList crackPropagationPatchNames
217     (
218         mesh.solutionDict().subDict("solidMechanics").lookup
219         (
220             "crackPropagationPatches"
221         )
222     );
224     labelList crackPropagationPatches(crackPropagationPatchNames.size(), -1);
226     forAll(crackPropagationPatchNames, patchI)
227     {
228         crackPropagationPatches[patchI] =
229             mesh.boundaryMesh().findPatchID
230             (
231                 crackPropagationPatchNames[patchI]
232             );
234         if(crackPropagationPatches[patchI] == -1)
235         {
236             FatalErrorIn(args.executable())
237                 << "Can't find " << crackPropagationPatchNames[patchI]
238                 << " patch" << abort(FatalError);
239         }
240     }
242     // Internal faces next to selected crack propagation patches
243     labelList crackPropagationPatchesInternalFaces;
245 #   include "updateCrackPropagationPatchesInternalFaces.H"