├── Levelset+AdaptiveMeshRefine ├── 1.gif ├── MTO_SolidDisplacement_levelset │ ├── LinearElasticity.H │ ├── MTO_levelset.C │ ├── Make │ │ ├── files │ │ └── options │ ├── costfunction.H │ ├── createFields.H │ ├── levelset.H │ ├── opt_initialization.H │ ├── readMechanicalProperties.H │ ├── sensitivity.H │ ├── tractionDisplacement │ │ ├── tractionDisplacementFvPatchVectorField.C │ │ └── tractionDisplacementFvPatchVectorField.H │ └── update.H ├── app │ ├── 0 │ │ ├── D │ │ └── x │ ├── constant │ │ ├── dynamicMeshDict │ │ ├── mechanicalProperties │ │ ├── mechanicalProperties~ │ │ └── optProperties │ └── system │ │ ├── blockMeshDict │ │ ├── blockMeshDict~ │ │ ├── controlDict │ │ ├── controlDict~ │ │ ├── decomposeParDict │ │ ├── fvSchemes │ │ ├── fvSchemes~ │ │ ├── fvSolution │ │ └── fvSolution~ └── meshRefinement2D_of6 │ ├── README │ └── src │ ├── Allwmake │ ├── dynamicFvMesh │ ├── Make │ │ ├── files │ │ ├── linux64GccDPInt32Opt │ │ │ ├── dynamicRefineFvMesh2D │ │ │ │ ├── dynamicRefineFvMesh2D.C.dep │ │ │ │ └── dynamicRefineFvMesh2D.o │ │ │ ├── options │ │ │ ├── sourceFiles │ │ │ └── variables │ │ └── options │ ├── dynamicRefineFvMesh2D │ │ ├── dynamicRefineFvMesh2D.C │ │ └── dynamicRefineFvMesh2D.H │ └── lnInclude │ │ ├── dynamicRefineFvMesh2D.C │ │ └── dynamicRefineFvMesh2D.H │ └── dynamicMesh │ ├── Make │ ├── files │ ├── linux64GccDPInt32Opt │ │ ├── options │ │ ├── polyTopoChange │ │ │ └── polyTopoChange │ │ │ │ └── hexRef2D │ │ │ │ ├── hexRef2D.C.dep │ │ │ │ └── hexRef2D.o │ │ ├── sourceFiles │ │ └── variables │ └── options │ ├── lnInclude │ ├── hexRef2D.C │ └── hexRef2D.H │ └── polyTopoChange │ └── polyTopoChange │ └── hexRef2D │ ├── hexRef2D.C │ └── hexRef2D.H ├── Levelset_without_AdaptiveMeshRefine ├── MTO_SolidDisplacement_levelset │ ├── LinearElasticity.H │ ├── MTO_levelset.C │ ├── Make │ │ ├── files │ │ └── options │ ├── costfunction.H │ ├── createFields.H │ ├── levelset.H │ ├── opt_initialization.H │ ├── readMechanicalProperties.H │ ├── sensitivity.H │ ├── tractionDisplacement │ │ ├── tractionDisplacementFvPatchVectorField.C │ │ └── tractionDisplacementFvPatchVectorField.H │ └── update.H └── app │ ├── 0 │ ├── D │ └── x │ ├── constant │ ├── mechanicalProperties │ └── optProperties │ └── system │ ├── blockMeshDict │ ├── controlDict │ ├── decomposeParDict │ ├── fvSchemes │ └── fvSolution └── README.md /Levelset+AdaptiveMeshRefine/1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MTopOpt/Levelset_AdaptiveMesh/147499dcf029686887d878d45f9302924915715a/Levelset+AdaptiveMeshRefine/1.gif -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/MTO_SolidDisplacement_levelset/LinearElasticity.H: -------------------------------------------------------------------------------- 1 | Info<< "\nslove linear elasticity equation\n" << endl; 2 | initialResidual = 0; 3 | iCorr=0; 4 | //D=0*D; 5 | do 6 | { 7 | { 8 | fvVectorMatrix DEqn 9 | ( 10 | - fvm::laplacian(2*mu + lambda, D, "laplacian(DD,D)") 11 | - divSigmaExp 12 | //- fvc::grad(threeKalpha*T) 13 | ); 14 | 15 | initialResidual = DEqn.solve().max().initialResidual(); 16 | 17 | if (!compactNormalStress) 18 | { 19 | divSigmaExp = fvc::div(DEqn.flux()); 20 | } 21 | } 22 | 23 | { 24 | volTensorField gradD(fvc::grad(D)); 25 | sigmaD = mu*twoSymm(gradD) + (lambda*I)*tr(gradD); 26 | 27 | if (compactNormalStress) 28 | { 29 | divSigmaExp = fvc::div 30 | ( 31 | sigmaD - (2*mu + lambda)*gradD, 32 | "div(sigmaD)" 33 | ); 34 | } 35 | else 36 | { 37 | divSigmaExp += fvc::div(sigmaD); 38 | } 39 | } 40 | 41 | } while (initialResidual > convergenceTolerance && ++iCorr < nCorr); 42 | //D.storePrevIter(); -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/MTO_SolidDisplacement_levelset/MTO_levelset.C: -------------------------------------------------------------------------------- 1 | //Author: Yu Minghao Updated: May 2020 2 | 3 | #include "fvCFD.H" 4 | #include "dynamicFvMesh.H" 5 | int main(int argc, char *argv[]) 6 | { 7 | #include "setRootCase.H" 8 | #include "createTime.H" 9 | //#include "createMesh.H" 10 | #include "createDynamicFvMesh.H" 11 | #include "createControl.H" 12 | #include "createFields.H" 13 | #include "readMechanicalProperties.H" 14 | #include "opt_initialization.H" 15 | while (runTime.loop()) 16 | { 17 | #include "update.H" 18 | #include "LinearElasticity.H" 19 | #include "costfunction.H" 20 | #include "sensitivity.H" 21 | #include "levelset.H" 22 | } 23 | Info<< " \n" << "ExecutionTime = " << runTime.elapsedCpuTime() << " s" 24 | << " ClockTime = " << runTime.elapsedClockTime() << " s" 25 | << nl << endl; 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/MTO_SolidDisplacement_levelset/Make/files: -------------------------------------------------------------------------------- 1 | 2 | tractionDisplacement/tractionDisplacementFvPatchVectorField.C 3 | 4 | MTO_levelset.C 5 | EXE = $(FOAM_USER_APPBIN)/MTO_levelset 6 | -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/MTO_SolidDisplacement_levelset/Make/options: -------------------------------------------------------------------------------- 1 | EXE_INC = \ 2 | -I$(LIB_SRC)/finiteVolume/lnInclude \ 3 | -I$(LIB_SRC)/meshTools/lnInclude \ 4 | -I$(LIB_SRC)/dynamicFvMesh/lnInclude \ 5 | -I$(LIB_SRC)/dynamicMesh/lnInclude 6 | EXE_LIBS = \ 7 | -lfiniteVolume \ 8 | -lmeshTools \ 9 | -lfvOptions \ 10 | -ldynamicFvMesh \ 11 | -ltopoChangerFvMesh \ 12 | -ldynamicMesh -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/MTO_SolidDisplacement_levelset/costfunction.H: -------------------------------------------------------------------------------- 1 | Info<<"cost function"<1) 15 | {x[i]=1;} 16 | if(x[i]<-1) 17 | {x[i]=-1;} 18 | 19 | if(x[i]>e) 20 | {xh[i]=1;} 21 | else if(x[i]<-e) 22 | {xh[i]=0;} 23 | else 24 | {xh[i]=3.0/4*(x[i]/e-x[i]*x[i]*x[i]/3.0/e/e/e)+0.5;} 25 | } 26 | 27 | mesh.update(); 28 | 29 | runTime.write(); 30 | n=x.size();//n:length of x in the i-th core 31 | N=x.size();//N:design freedom 32 | reduce(N, sumOp()); 33 | -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/MTO_SolidDisplacement_levelset/opt_initialization.H: -------------------------------------------------------------------------------- 1 | Info<< "Initialization\n" << endl; 2 | std::remove("Voluse.txt"); 3 | std::remove("Time.txt"); 4 | std::remove("Compliance.txt"); 5 | 6 | int i=0; 7 | double opt=0; 8 | scalar n(0),N(0),lam(0.1),C(0),V(0),Vmax(0),area=gSum(mesh.V()); 9 | n=x.size();//n:length of x in the i-th core 10 | N=x.size();//N:design freedom 11 | reduce(N, sumOp()); 12 | double e=0.5; 13 | for(i=0;i1) 16 | {x[i]=1;} 17 | if(x[i]<-1) 18 | {x[i]=-1;} 19 | 20 | if(x[i]>e) 21 | {xh[i]=1;} 22 | else if(x[i]<-e) 23 | {xh[i]=0;} 24 | else 25 | {xh[i]=3.0/4*(x[i]/e-x[i]*x[i]*x[i]/3.0/e/e/e)+0.5;} 26 | } 27 | -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/MTO_SolidDisplacement_levelset/readMechanicalProperties.H: -------------------------------------------------------------------------------- 1 | Info<< "Reading mechanical properties\n" << endl; 2 | IOdictionary mechanicalProperties 3 | ( 4 | IOobject 5 | ( 6 | "mechanicalProperties", 7 | runTime.constant(), 8 | mesh, 9 | IOobject::MUST_READ_IF_MODIFIED, 10 | IOobject::NO_WRITE 11 | ) 12 | ); 13 | int iCorr=0,nCorr=300; 14 | scalar convergenceTolerance(1e-5),initialResidual(0); 15 | 16 | Switch planeStress(mechanicalProperties.lookup("planeStress")); 17 | dimensionedScalar rhoE("rhoE", dimMass/dimLength/sqr(dimTime),readScalar(mechanicalProperties.lookup("rhoE"))); 18 | dimensionedScalar rho("rho", dimMass/dimVolume,readScalar(mechanicalProperties.lookup("rho"))); 19 | scalar Po(readScalar(mechanicalProperties.lookup("Po"))); 20 | dimensionedScalar E(rhoE/rho); 21 | dimensionedScalar Emin(E*1e-4); 22 | volScalarField mu(xh*xh*xh*E/(2.0*(1.0 + Po))); 23 | volScalarField lambda(xh*xh*xh*Po*E/((1.0 + Po)*(1.0 - 2.0*Po))); 24 | 25 | Info<< "Reading field D\n" << endl; 26 | volVectorField D 27 | ( 28 | IOobject 29 | ( 30 | "D", 31 | runTime.timeName(), 32 | mesh, 33 | IOobject::MUST_READ, 34 | IOobject::NO_WRITE 35 | ), 36 | mesh 37 | ); 38 | volVectorField D2(D); 39 | volTensorField gradD 40 | ( 41 | IOobject 42 | ( 43 | "gradD", 44 | runTime.timeName(), 45 | mesh, 46 | IOobject::NO_READ, 47 | IOobject::NO_WRITE 48 | ), 49 | fvc::grad(D) 50 | ); 51 | 52 | Info<< "Calculating stress field sigmaD\n" << endl; 53 | volSymmTensorField sigmaD 54 | ( 55 | IOobject 56 | ( 57 | "sigmaD", 58 | runTime.timeName(), 59 | mesh, 60 | IOobject::NO_READ, 61 | IOobject::NO_WRITE 62 | ), 63 | mu*twoSymm(gradD) + (lambda*I)*tr(gradD) 64 | ); 65 | 66 | Info<< "Calculating explicit part of div(sigma) divSigmaExp\n" << endl; 67 | volVectorField divSigmaExp 68 | ( 69 | IOobject 70 | ( 71 | "divSigmaExp", 72 | runTime.timeName(), 73 | mesh, 74 | IOobject::NO_READ, 75 | IOobject::NO_WRITE 76 | ), 77 | fvc::div(sigmaD) 78 | ); 79 | 80 | Switch compactNormalStress("yes"); 81 | 82 | if (compactNormalStress) 83 | { 84 | divSigmaExp -= fvc::laplacian(2*mu + lambda, D, "laplacian(DD,D)"); 85 | } 86 | else 87 | { 88 | divSigmaExp -= fvc::div((2*mu + lambda)*fvc::grad(D), "div(sigmaD)"); 89 | } 90 | mesh.setFluxRequired(D.name()); 91 | 92 | volScalarField fsensh 93 | ( 94 | IOobject 95 | ( 96 | "fsensh", 97 | runTime.timeName(), 98 | mesh, 99 | IOobject::NO_READ, 100 | IOobject::NO_WRITE 101 | ), 102 | -gradD&&(rho*(3*xh*xh*(E-Emin)/(2.0*(1.0 + Po))*twoSymm(gradD))), 103 | zeroGradientFvPatchScalarField::typeName 104 | ); 105 | 106 | volScalarField gsensh(xh); 107 | -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/MTO_SolidDisplacement_levelset/sensitivity.H: -------------------------------------------------------------------------------- 1 | 2 | Info<<"sensitivity analysis"<. 23 | 24 | \*---------------------------------------------------------------------------*/ 25 | 26 | #include "tractionDisplacementFvPatchVectorField.H" 27 | #include "addToRunTimeSelectionTable.H" 28 | #include "volFields.H" 29 | 30 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 31 | 32 | namespace Foam 33 | { 34 | 35 | // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // 36 | 37 | tractionDisplacementFvPatchVectorField:: 38 | tractionDisplacementFvPatchVectorField 39 | ( 40 | const fvPatch& p, 41 | const DimensionedField& iF 42 | ) 43 | : 44 | fixedGradientFvPatchVectorField(p, iF), 45 | traction_(p.size(), Zero), 46 | pressure_(p.size(), 0.0) 47 | { 48 | fvPatchVectorField::operator=(patchInternalField()); 49 | gradient() = Zero; 50 | } 51 | 52 | 53 | tractionDisplacementFvPatchVectorField:: 54 | tractionDisplacementFvPatchVectorField 55 | ( 56 | const tractionDisplacementFvPatchVectorField& tdpvf, 57 | const fvPatch& p, 58 | const DimensionedField& iF, 59 | const fvPatchFieldMapper& mapper 60 | ) 61 | : 62 | fixedGradientFvPatchVectorField(tdpvf, p, iF, mapper), 63 | traction_(tdpvf.traction_, mapper), 64 | pressure_(tdpvf.pressure_, mapper) 65 | {} 66 | 67 | 68 | tractionDisplacementFvPatchVectorField:: 69 | tractionDisplacementFvPatchVectorField 70 | ( 71 | const fvPatch& p, 72 | const DimensionedField& iF, 73 | const dictionary& dict 74 | ) 75 | : 76 | fixedGradientFvPatchVectorField(p, iF), 77 | traction_("traction", dict, p.size()), 78 | pressure_("pressure", dict, p.size()) 79 | { 80 | fvPatchVectorField::operator=(patchInternalField()); 81 | gradient() = Zero; 82 | } 83 | 84 | 85 | tractionDisplacementFvPatchVectorField:: 86 | tractionDisplacementFvPatchVectorField 87 | ( 88 | const tractionDisplacementFvPatchVectorField& tdpvf 89 | ) 90 | : 91 | fixedGradientFvPatchVectorField(tdpvf), 92 | traction_(tdpvf.traction_), 93 | pressure_(tdpvf.pressure_) 94 | {} 95 | 96 | 97 | tractionDisplacementFvPatchVectorField:: 98 | tractionDisplacementFvPatchVectorField 99 | ( 100 | const tractionDisplacementFvPatchVectorField& tdpvf, 101 | const DimensionedField& iF 102 | ) 103 | : 104 | fixedGradientFvPatchVectorField(tdpvf, iF), 105 | traction_(tdpvf.traction_), 106 | pressure_(tdpvf.pressure_) 107 | {} 108 | 109 | 110 | // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // 111 | 112 | void tractionDisplacementFvPatchVectorField::autoMap 113 | ( 114 | const fvPatchFieldMapper& m 115 | ) 116 | { 117 | fixedGradientFvPatchVectorField::autoMap(m); 118 | traction_.autoMap(m); 119 | pressure_.autoMap(m); 120 | } 121 | 122 | 123 | void tractionDisplacementFvPatchVectorField::rmap 124 | ( 125 | const fvPatchVectorField& ptf, 126 | const labelList& addr 127 | ) 128 | { 129 | fixedGradientFvPatchVectorField::rmap(ptf, addr); 130 | 131 | const tractionDisplacementFvPatchVectorField& dmptf = 132 | refCast(ptf); 133 | 134 | traction_.rmap(dmptf.traction_, addr); 135 | pressure_.rmap(dmptf.pressure_, addr); 136 | } 137 | 138 | 139 | void tractionDisplacementFvPatchVectorField::updateCoeffs() 140 | { 141 | if (updated()) 142 | { 143 | return; 144 | } 145 | const dictionary& mechanicalProperties = 146 | db().lookupObject("mechanicalProperties"); 147 | 148 | 149 | const fvPatchField& xh = 150 | patch().lookupPatchField("xh"); 151 | 152 | scalar rhoE(readScalar(mechanicalProperties.lookup("rhoE"))); 153 | scalar Po(readScalar(mechanicalProperties.lookup("Po"))); 154 | scalar rho(readScalar(mechanicalProperties.lookup("rho"))); 155 | scalar E(rhoE/rho); 156 | scalar Emin(E*1e-4); 157 | Switch planeStress(mechanicalProperties.lookup("planeStress")); 158 | 159 | scalarField mu((Emin+xh*(E-Emin))/(2.0*(1.0 + Po))); 160 | scalarField lambda((Emin+xh*(E-Emin))*Po/((1.0 + Po)*(1.0 - 2.0*Po))); 161 | if (planeStress) 162 | { 163 | lambda=(Emin+xh*(E-Emin))*Po/((1.0 + Po)*(1.0 - Po)); 164 | } 165 | scalarField twoMuLambda(2*mu + lambda); 166 | 167 | vectorField n(patch().nf()); 168 | //vectorField mm(patch().Cf()); 169 | //vector m(0,0,1); 170 | const fvPatchField& sigmaD = 171 | patch().lookupPatchField("sigmaD"); 172 | 173 | gradient() = 174 | ( 175 | //(traction_ - pressure_*(n^mm))/rho 176 | (traction_ - pressure_*n)/rho 177 | + twoMuLambda*fvPatchField::snGrad() - (n & sigmaD) 178 | )/twoMuLambda; 179 | fixedGradientFvPatchVectorField::updateCoeffs(); 180 | } 181 | 182 | void tractionDisplacementFvPatchVectorField::write(Ostream& os) const 183 | { 184 | fvPatchVectorField::write(os); 185 | traction_.writeEntry("traction", os); 186 | pressure_.writeEntry("pressure", os); 187 | writeEntry("value", os); 188 | } 189 | 190 | 191 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 192 | 193 | makePatchTypeField 194 | ( 195 | fvPatchVectorField, 196 | tractionDisplacementFvPatchVectorField 197 | ); 198 | 199 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 200 | 201 | } // End namespace Foam 202 | 203 | // ************************************************************************* // 204 | -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/MTO_SolidDisplacement_levelset/tractionDisplacement/tractionDisplacementFvPatchVectorField.H: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------------*\ 2 | ========= | 3 | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 4 | \\ / O peration | 5 | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation 6 | \\/ M anipulation | 7 | ------------------------------------------------------------------------------- 8 | License 9 | This file is part of OpenFOAM. 10 | 11 | OpenFOAM is free software: you can redistribute it and/or modify it 12 | under the terms of the GNU General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | OpenFOAM is distributed in the hope that it will be useful, but WITHOUT 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with OpenFOAM. If not, see . 23 | 24 | Class 25 | Foam::tractionDisplacementFvPatchVectorField 26 | 27 | Description 28 | Fixed traction boundary condition for the standard linear elastic, fixed 29 | coefficient displacement equation. 30 | 31 | SourceFiles 32 | tractionDisplacementFvPatchVectorField.C 33 | 34 | \*---------------------------------------------------------------------------*/ 35 | 36 | #ifndef tractionDisplacementFvPatchVectorField_H 37 | #define tractionDisplacementFvPatchVectorField_H 38 | 39 | #include "fvPatchFields.H" 40 | #include "fixedGradientFvPatchFields.H" 41 | 42 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 43 | 44 | namespace Foam 45 | { 46 | 47 | /*---------------------------------------------------------------------------*\ 48 | Class tractionDisplacementFvPatch Declaration 49 | \*---------------------------------------------------------------------------*/ 50 | 51 | class tractionDisplacementFvPatchVectorField 52 | : 53 | public fixedGradientFvPatchVectorField 54 | { 55 | 56 | // Private Data 57 | 58 | vectorField traction_; 59 | scalarField pressure_; 60 | 61 | 62 | public: 63 | 64 | //- Runtime type information 65 | TypeName("tractionDisplacement"); 66 | 67 | 68 | // Constructors 69 | 70 | //- Construct from patch and internal field 71 | tractionDisplacementFvPatchVectorField 72 | ( 73 | const fvPatch&, 74 | const DimensionedField& 75 | ); 76 | 77 | //- Construct from patch, internal field and dictionary 78 | tractionDisplacementFvPatchVectorField 79 | ( 80 | const fvPatch&, 81 | const DimensionedField&, 82 | const dictionary& 83 | ); 84 | 85 | //- Construct by mapping given 86 | // tractionDisplacementFvPatchVectorField onto a new patch 87 | tractionDisplacementFvPatchVectorField 88 | ( 89 | const tractionDisplacementFvPatchVectorField&, 90 | const fvPatch&, 91 | const DimensionedField&, 92 | const fvPatchFieldMapper& 93 | ); 94 | 95 | //- Construct as copy 96 | tractionDisplacementFvPatchVectorField 97 | ( 98 | const tractionDisplacementFvPatchVectorField& 99 | ); 100 | 101 | //- Construct and return a clone 102 | virtual tmp clone() const 103 | { 104 | return tmp 105 | ( 106 | new tractionDisplacementFvPatchVectorField(*this) 107 | ); 108 | } 109 | 110 | //- Construct as copy setting internal field reference 111 | tractionDisplacementFvPatchVectorField 112 | ( 113 | const tractionDisplacementFvPatchVectorField&, 114 | const DimensionedField& 115 | ); 116 | 117 | //- Construct and return a clone setting internal field reference 118 | virtual tmp clone 119 | ( 120 | const DimensionedField& iF 121 | ) const 122 | { 123 | return tmp 124 | ( 125 | new tractionDisplacementFvPatchVectorField(*this, iF) 126 | ); 127 | } 128 | 129 | 130 | // Member functions 131 | 132 | // Access 133 | 134 | virtual const vectorField& traction() const 135 | { 136 | return traction_; 137 | } 138 | 139 | virtual vectorField& traction() 140 | { 141 | return traction_; 142 | } 143 | 144 | virtual const scalarField& pressure() const 145 | { 146 | return pressure_; 147 | } 148 | 149 | virtual scalarField& pressure() 150 | { 151 | return pressure_; 152 | } 153 | 154 | 155 | // Mapping functions 156 | 157 | //- Map (and resize as needed) from self given a mapping object 158 | virtual void autoMap 159 | ( 160 | const fvPatchFieldMapper& 161 | ); 162 | 163 | //- Reverse map the given fvPatchField onto this fvPatchField 164 | virtual void rmap 165 | ( 166 | const fvPatchVectorField&, 167 | const labelList& 168 | ); 169 | 170 | 171 | //- Update the coefficients associated with the patch field 172 | virtual void updateCoeffs(); 173 | 174 | //- Write 175 | virtual void write(Ostream&) const; 176 | }; 177 | 178 | 179 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 180 | 181 | } // End namespace Foam 182 | 183 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 184 | 185 | #endif 186 | 187 | // ************************************************************************* // 188 | -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/MTO_SolidDisplacement_levelset/update.H: -------------------------------------------------------------------------------- 1 | //***********************************//update mu and lambda 2 | opt=opt+1; 3 | 4 | if(solid_area) 5 | { 6 | forAll(cells, i) 7 | { 8 | xh[cells[i]]=1.0; 9 | } 10 | } 11 | xh.correctBoundaryConditions(); 12 | if(runTime.writeTime()) 13 | { 14 | xh.write(); 15 | //x.write(); 16 | } 17 | 18 | mu=(Emin+xh*(E-Emin))/(2.0*(1.0 + Po)); 19 | lambda=(Emin+xh*(E-Emin))*Po/((1.0 + Po)*(1.0 - 2.0*Po)); 20 | if (planeStress) 21 | { 22 | lambda=(Emin+xh*(E-Emin))*Po/((1.0 + Po)*(1.0 - Po)); 23 | } 24 | -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/app/0/D: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 5 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volVectorField; 13 | object D; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 1 0 0 0 0 0]; 18 | 19 | internalField uniform (0 0 0); 20 | 21 | boundaryField 22 | { 23 | left 24 | { 25 | type fixedValue; 26 | value uniform (0 0 0); 27 | } 28 | none 29 | { 30 | type tractionDisplacement; 31 | traction uniform (0 0 0); 32 | pressure uniform 0; 33 | value uniform (0 0 0); 34 | } 35 | force 36 | { 37 | type tractionDisplacement; 38 | traction uniform (0 1 0); 39 | pressure uniform 0; 40 | value uniform (0 0 0); 41 | } 42 | frontAndBack 43 | { 44 | type empty; 45 | } 46 | } 47 | 48 | // ************************************************************************* // 49 | -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/app/0/x: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 5 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class volScalarField; 13 | object x; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | dimensions [0 0 0 0 0 0 0]; 18 | 19 | internalField uniform 1; 20 | 21 | boundaryField 22 | { 23 | left 24 | { 25 | type fixedValue; 26 | value uniform 0; 27 | } 28 | none 29 | { 30 | type fixedValue; 31 | value uniform 0; 32 | } 33 | force 34 | { 35 | type fixedValue; 36 | value uniform 0; 37 | } 38 | frontAndBack 39 | { 40 | type empty; 41 | } 42 | } 43 | 44 | // ************************************************************************* // 45 | -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/app/constant/dynamicMeshDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 5.x | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "constant"; 14 | object dynamicMeshDict; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | dynamicFvMesh dynamicRefineFvMesh2D; 19 | 20 | // How often to refine 21 | refineInterval 1; 22 | 23 | // Field to be refinement on 24 | field x; 25 | 26 | // Refine field in between lower..upper 27 | lowerRefineLevel -0.1; 28 | upperRefineLevel 0.1; 29 | 30 | // If value < unrefineLevel unrefine 31 | unrefineLevel 1; 32 | 33 | // Have slower than 2:1 refinement 34 | nBufferLayers 1; 35 | 36 | nBufferLayersR 1; 37 | 38 | // Refine cells only up to maxRefinement levels 39 | maxRefinement 2; 40 | 41 | // Stop refinement if maxCells reached 42 | maxCells 50000; 43 | 44 | // Flux field and corresponding velocity field. Fluxes on changed 45 | // faces get recalculated by interpolating the velocity. Use 'none' 46 | // on surfaceScalarFields that do not need to be reinterpolated. 47 | correctFluxes 48 | ( 49 | (phi none) 50 | (phib none) 51 | (phic none) 52 | ); 53 | 54 | // Write the refinement level as a volScalarField 55 | dumpLevel true; 56 | 57 | 58 | // ************************************************************************* // 59 | -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/app/constant/mechanicalProperties: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 5 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "constant"; 14 | object mechanicalProperties; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | rho 1; 19 | rhoE 1; 20 | Po 0.3; 21 | planeStress yes; 22 | 23 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 24 | -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/app/constant/mechanicalProperties~: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 5 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "constant"; 14 | object mechanicalProperties; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | raa0 raa0 [0 0 0 0 0 0 0] 0.00005; 18 | asyinit asyinit [0 0 0 0 0 0 0] 0.3; 19 | filter_R filter_R [0 0 0 0 0 0 0] 2; 20 | non_design non_design [0 0 0 0 0 0 0] 0; 21 | Heaviside_filter Heaviside_filter [0 0 0 0 0 0 0] 0; 22 | rho 23 | { 24 | type uniform; 25 | value 1; 26 | } 27 | 28 | nu 29 | { 30 | type uniform; 31 | value 0.3; 32 | } 33 | 34 | E 35 | { 36 | type uniform; 37 | value 2e+11; 38 | } 39 | 40 | planeStress yes; 41 | 42 | 43 | // ************************************************************************* // 44 | -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/app/constant/optProperties: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 5 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "constant"; 14 | object optProperties; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | voluse 0.4; 19 | niter 100; 20 | ep 2e-4; 21 | solid_area no; 22 | 23 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 24 | -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/app/system/blockMeshDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 5 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | object blockMeshDict; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | convertToMeters 1; 18 | /* 19 | vertices 20 | ( 21 | (0 0 0) 22 | (1.5 0 0) 23 | (0 0.49 0) 24 | (1.5 0.49 0) 25 | (0 0.51 0) 26 | (1.5 0.51 0) 27 | (0 1 0) 28 | (1.5 1 0) 29 | 30 | (0 0 0.01) 31 | (1.5 0 0.01) 32 | (0 0.49 0.01) 33 | (1.5 0.49 0.01) 34 | (0 0.51 0.01) 35 | (1.5 0.51 0.01) 36 | (0 1 0.01) 37 | (1.5 1 0.01) 38 | ); 39 | 40 | blocks 41 | ( 42 | hex (0 1 3 2 8 9 11 10) (66 25 1) simpleGrading (1 1 1) 43 | hex (2 3 5 4 10 11 13 12) (66 1 1) simpleGrading (1 1 1) 44 | hex (4 5 7 6 12 13 15 14) (66 25 1) simpleGrading (1 1 1) 45 | ); 46 | */ 47 | /**/ 48 | vertices 49 | ( 50 | (0 0 0) 51 | (2 0 0) 52 | (0 0.49 0) 53 | (2 0.49 0) 54 | (0 0.51 0) 55 | (2 0.51 0) 56 | (0 1 0) 57 | (2 1 0) 58 | 59 | (0 0 0.01) 60 | (2 0 0.01) 61 | (0 0.49 0.01) 62 | (2 0.49 0.01) 63 | (0 0.51 0.01) 64 | (2 0.51 0.01) 65 | (0 1 0.01) 66 | (2 1 0.01) 67 | ); 68 | 69 | blocks 70 | ( 71 | hex (0 1 3 2 8 9 11 10) (100 25 1) simpleGrading (1 1 1) 72 | hex (2 3 5 4 10 11 13 12) (100 1 1) simpleGrading (1 1 1) 73 | hex (4 5 7 6 12 13 15 14) (100 25 1) simpleGrading (1 1 1) 74 | ); 75 | 76 | edges 77 | ( 78 | ); 79 | 80 | boundary 81 | ( 82 | left 83 | { 84 | type patch; 85 | faces 86 | ( 87 | (2 0 8 10) 88 | (4 2 10 12) 89 | (6 4 12 14) 90 | ); 91 | } 92 | none 93 | { 94 | type patch; 95 | faces 96 | ( 97 | (0 1 9 8) 98 | (6 7 15 14) 99 | (1 3 11 9) 100 | (5 7 15 13) 101 | ); 102 | } 103 | force 104 | { 105 | type patch; 106 | faces 107 | ( 108 | (3 5 13 11) 109 | ); 110 | } 111 | frontAndBack 112 | { 113 | type empty; 114 | faces 115 | ( 116 | (0 2 3 1) 117 | (2 4 5 3) 118 | (4 6 7 5) 119 | (8 9 11 10) 120 | (10 11 13 12) 121 | (12 13 15 14) 122 | ); 123 | } 124 | ); 125 | 126 | mergePatchPairs 127 | ( 128 | ); 129 | 130 | // ************************************************************************* // 131 | -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/app/system/blockMeshDict~: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 5 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | object blockMeshDict; 14 | } 15 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 16 | 17 | convertToMeters 100; 18 | 19 | vertices 20 | ( 21 | (0 0 0) 22 | (2 0 0) 23 | (0 0.49 0) 24 | (2 0.49 0) 25 | (0 0.51 0) 26 | (2 0.51 0) 27 | (0 1 0) 28 | (2 1 0) 29 | 30 | (0 0 1) 31 | (2 0 1) 32 | (0 0.49 1) 33 | (2 0.49 1) 34 | (0 0.51 1) 35 | (2 0.51 1) 36 | (0 1 1) 37 | (2 1 1) 38 | ); 39 | 40 | blocks 41 | ( 42 | hex (0 1 3 2 8 9 11 10) (200 49 1) simpleGrading (1 1 1) 43 | hex (2 3 5 4 10 11 13 12) (200 2 1) simpleGrading (1 1 1) 44 | hex (4 5 7 6 12 13 15 14) (200 49 1) simpleGrading (1 1 1) 45 | ); 46 | 47 | edges 48 | ( 49 | ); 50 | 51 | boundary 52 | ( 53 | left 54 | { 55 | type patch; 56 | faces 57 | ( 58 | (2 0 8 10) 59 | (4 2 10 12) 60 | (6 4 12 14) 61 | ); 62 | } 63 | none 64 | { 65 | type patch; 66 | faces 67 | ( 68 | (0 1 9 8) 69 | (6 7 15 14) 70 | (1 3 11 9) 71 | (5 7 15 13) 72 | ); 73 | } 74 | force 75 | { 76 | type patch; 77 | faces 78 | ( 79 | (3 5 13 11) 80 | ); 81 | } 82 | frontAndBack 83 | { 84 | type empty; 85 | faces 86 | ( 87 | (0 2 3 1) 88 | (2 4 5 3) 89 | (4 6 7 5) 90 | (8 9 11 10) 91 | (10 11 13 12) 92 | (12 13 15 14) 93 | ); 94 | } 95 | ); 96 | 97 | mergePatchPairs 98 | ( 99 | ); 100 | 101 | // ************************************************************************* // 102 | -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/app/system/controlDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 5 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object controlDict; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | application solidDisplacementFoam; 19 | 20 | startFrom startTime; 21 | 22 | startTime 0; 23 | 24 | stopAt endTime; 25 | 26 | endTime 120; 27 | 28 | deltaT 0.4; 29 | 30 | writeControl timeStep; 31 | 32 | writeInterval 2; 33 | 34 | purgeWrite 0; 35 | 36 | writeFormat ascii; 37 | 38 | writePrecision 7; 39 | 40 | writeCompression off; 41 | 42 | timeFormat general; 43 | 44 | timePrecision 6; 45 | 46 | graphFormat raw; 47 | 48 | runTimeModifiable true; 49 | libs ( "libOpenFOAM.so" "libgroovyBC.so" "libdynamicFvMeshUser.so") ; 50 | 51 | // ************************************************************************* // 52 | -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/app/system/controlDict~: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 5 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object controlDict; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | application solidDisplacementFoam; 19 | 20 | startFrom startTime; 21 | 22 | startTime 0; 23 | 24 | stopAt endTime; 25 | 26 | endTime 100000; 27 | 28 | deltaT 1; 29 | 30 | writeControl timeStep; 31 | 32 | writeInterval 1000; 33 | 34 | purgeWrite 0; 35 | 36 | writeFormat ascii; 37 | 38 | writePrecision 10; 39 | 40 | writeCompression off; 41 | 42 | timeFormat general; 43 | 44 | timePrecision 6; 45 | 46 | graphFormat raw; 47 | 48 | runTimeModifiable true; 49 | 50 | 51 | // ************************************************************************* // 52 | -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/app/system/decomposeParDict: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 5 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object decomposeParDict; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | numberOfSubdomains 16; 19 | 20 | method simple; 21 | 22 | simpleCoeffs 23 | { 24 | n (4 4 1); 25 | delta 0.001; 26 | } 27 | 28 | hierarchicalCoeffs 29 | { 30 | n (1 1 1); 31 | delta 0.001; 32 | order xyz; 33 | } 34 | 35 | manualCoeffs 36 | { 37 | dataFile ""; 38 | } 39 | 40 | distributed no; 41 | 42 | roots ( ); 43 | 44 | 45 | // ************************************************************************* // 46 | -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/app/system/fvSchemes: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 5 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object fvSchemes; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | d2dt2Schemes 19 | { 20 | default steadyState; 21 | } 22 | 23 | ddtSchemes 24 | { 25 | default Euler; 26 | } 27 | 28 | gradSchemes 29 | { 30 | default Gauss linear; 31 | grad(D) leastSquares; 32 | } 33 | 34 | divSchemes 35 | { 36 | default Gauss linear; 37 | div(sigmaD) Gauss linear; 38 | } 39 | 40 | laplacianSchemes 41 | { 42 | default Gauss linear corrected; 43 | laplacian(DD,D) Gauss linear corrected; 44 | } 45 | 46 | interpolationSchemes 47 | { 48 | default linear; 49 | } 50 | 51 | snGradSchemes 52 | { 53 | default corrected; 54 | } 55 | fluxRequired 56 | { 57 | default no; 58 | } 59 | wallDist 60 | { 61 | method meshWave; 62 | } 63 | // ************************************************************************* // 64 | -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/app/system/fvSchemes~: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 5 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object fvSchemes; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | d2dt2Schemes 19 | { 20 | default steadyState; 21 | } 22 | 23 | ddtSchemes 24 | { 25 | default Euler; 26 | } 27 | 28 | gradSchemes 29 | { 30 | default leastSquares; 31 | grad(D) leastSquares; 32 | grad(T) leastSquares; 33 | } 34 | 35 | divSchemes 36 | { 37 | default none; 38 | div(sigmaD) Gauss cubic; 39 | } 40 | 41 | laplacianSchemes 42 | { 43 | default none; 44 | laplacian(DD,D) Gauss linear corrected; 45 | laplacian(DT,T) Gauss linear corrected; 46 | } 47 | 48 | interpolationSchemes 49 | { 50 | default linear; 51 | } 52 | 53 | snGradSchemes 54 | { 55 | default none; 56 | } 57 | 58 | // ************************************************************************* // 59 | -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/app/system/fvSolution: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 5 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object fvSolution; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | solvers 19 | { 20 | D 21 | { 22 | solver GAMG; 23 | tolerance 1e-7; 24 | relTol 0.9; 25 | smoother GaussSeidel; 26 | nCellsInCoarsestLevel 20; 27 | } 28 | 29 | x 30 | { 31 | solver PCG; 32 | preconditioner DIC; 33 | tolerance 1e-06; 34 | relTol 0; 35 | } 36 | 37 | } 38 | 39 | // ************************************************************************* // 40 | -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/app/system/fvSolution~: -------------------------------------------------------------------------------- 1 | /*--------------------------------*- C++ -*----------------------------------*\ 2 | | ========= | | 3 | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | 4 | | \\ / O peration | Version: 5 | 5 | | \\ / A nd | Web: www.OpenFOAM.org | 6 | | \\/ M anipulation | | 7 | \*---------------------------------------------------------------------------*/ 8 | FoamFile 9 | { 10 | version 2.0; 11 | format ascii; 12 | class dictionary; 13 | location "system"; 14 | object fvSolution; 15 | } 16 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 17 | 18 | solvers 19 | { 20 | "(D|T)" 21 | { 22 | solver GAMG; 23 | tolerance 1e-08; 24 | relTol 0.9; 25 | smoother GaussSeidel; 26 | nCellsInCoarsestLevel 20; 27 | } 28 | } 29 | 30 | stressAnalysis 31 | { 32 | compactNormalStress yes; 33 | nCorrectors 1; 34 | D 1e-06; 35 | } 36 | 37 | 38 | // ************************************************************************* // 39 | -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/meshRefinement2D_of6/README: -------------------------------------------------------------------------------- 1 | copy src folder into $WM_PROJECT_USER_DIR folder and compile the code by running ./Allwmake script 2 | The structure of src folder traces the OpenFOAM src folder. 3 | 4 | damBreak_test folder has two tests based on interFoam damBreak tutorial . 5 | One is for axial simmetryical geometry (damBreakCylinder) the other for a planar configuration (damBreakPlanar). 6 | -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/meshRefinement2D_of6/src/Allwmake: -------------------------------------------------------------------------------- 1 | wmake dynamicMesh 2 | wmake dynamicFvMesh 3 | -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/meshRefinement2D_of6/src/dynamicFvMesh/Make/files: -------------------------------------------------------------------------------- 1 | dynamicRefineFvMesh2D/dynamicRefineFvMesh2D.C 2 | 3 | LIB = $(FOAM_USER_LIBBIN)/libdynamicFvMeshUser 4 | -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/meshRefinement2D_of6/src/dynamicFvMesh/Make/linux64GccDPInt32Opt/dynamicRefineFvMesh2D/dynamicRefineFvMesh2D.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MTopOpt/Levelset_AdaptiveMesh/147499dcf029686887d878d45f9302924915715a/Levelset+AdaptiveMeshRefine/meshRefinement2D_of6/src/dynamicFvMesh/Make/linux64GccDPInt32Opt/dynamicRefineFvMesh2D/dynamicRefineFvMesh2D.o -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/meshRefinement2D_of6/src/dynamicFvMesh/Make/linux64GccDPInt32Opt/options: -------------------------------------------------------------------------------- 1 | # 1 "Make/options" 2 | # 1 "" 3 | # 1 "" 4 | # 8 "" 5 | # 1 "/usr/include/stdc-predef.h" 1 3 4 6 | 7 | # 17 "/usr/include/stdc-predef.h" 3 4 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | # 8 "" 2 52 | # 1 "Make/options" 53 | EXE_INC = -I$(LIB_SRC)/triSurface/lnInclude -I$(LIB_SRC)/meshTools/lnInclude -I$(LIB_SRC)/dynamicMesh/lnInclude -I$(LIB_SRC)/dynamicFvMesh/lnInclude -I$(LIB_SRC)/finiteVolume/lnInclude -I$(WM_PROJECT_USER_DIR)/src/dynamicMesh/lnInclude 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | LIB_LIBS = -ltriSurface -lmeshTools -ldynamicMesh -L$(FOAM_USER_LIBBIN) -ldynamicMeshUser -lfiniteVolume 62 | -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/meshRefinement2D_of6/src/dynamicFvMesh/Make/linux64GccDPInt32Opt/sourceFiles: -------------------------------------------------------------------------------- 1 | SOURCE = \ 2 | dynamicRefineFvMesh2D/dynamicRefineFvMesh2D.C 3 | -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/meshRefinement2D_of6/src/dynamicFvMesh/Make/linux64GccDPInt32Opt/variables: -------------------------------------------------------------------------------- 1 | LIB = $(FOAM_USER_LIBBIN)/libdynamicFvMeshUser 2 | -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/meshRefinement2D_of6/src/dynamicFvMesh/Make/options: -------------------------------------------------------------------------------- 1 | EXE_INC = \ 2 | -I$(LIB_SRC)/triSurface/lnInclude \ 3 | -I$(LIB_SRC)/meshTools/lnInclude \ 4 | -I$(LIB_SRC)/dynamicMesh/lnInclude \ 5 | -I$(LIB_SRC)/dynamicFvMesh/lnInclude \ 6 | -I$(LIB_SRC)/finiteVolume/lnInclude \ 7 | -I$(WM_PROJECT_USER_DIR)/src/dynamicMesh/lnInclude 8 | 9 | LIB_LIBS = \ 10 | -ltriSurface \ 11 | -lmeshTools \ 12 | -ldynamicMesh \ 13 | -L$(FOAM_USER_LIBBIN) -ldynamicMeshUser \ 14 | -lfiniteVolume 15 | -------------------------------------------------------------------------------- /Levelset+AdaptiveMeshRefine/meshRefinement2D_of6/src/dynamicFvMesh/dynamicRefineFvMesh2D/dynamicRefineFvMesh2D.C: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------------*\ 2 | ========= | 3 | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 4 | \\ / O peration | Website: https://openfoam.org 5 | \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation 6 | \\/ M anipulation | 7 | ------------------------------------------------------------------------------- 8 | License 9 | This file is part of OpenFOAM. 10 | 11 | OpenFOAM is free software: you can redistribute it and/or modify it 12 | under the terms of the GNU General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | OpenFOAM is distributed in the hope that it will be useful, but WITHOUT 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with OpenFOAM. If not, see . 23 | 24 | \*---------------------------------------------------------------------------*/ 25 | 26 | #include "dynamicRefineFvMesh2D.H" 27 | #include "addToRunTimeSelectionTable.H" 28 | #include "surfaceInterpolate.H" 29 | #include "volFields.H" 30 | #include "polyTopoChange.H" 31 | #include "surfaceFields.H" 32 | #include "syncTools.H" 33 | #include "pointFields.H" 34 | #include "sigFpe.H" 35 | #include "cellSet.H" 36 | 37 | // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // 38 | 39 | namespace Foam 40 | { 41 | defineTypeNameAndDebug(dynamicRefineFvMesh2D, 0); 42 | addToRunTimeSelectionTable(dynamicFvMesh, dynamicRefineFvMesh2D, IOobject); 43 | } 44 | 45 | // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // 46 | 47 | // the PackedBoolList::count method would probably be faster 48 | // since we are only checking for 'true' anyhow 49 | Foam::label Foam::dynamicRefineFvMesh2D::count 50 | ( 51 | const PackedBoolList& l, 52 | const unsigned int val 53 | ) 54 | { 55 | label n = 0; 56 | forAll(l, i) 57 | { 58 | if (l.get(i) == val) 59 | { 60 | n++; 61 | } 62 | 63 | // debug also serves to get-around Clang compiler trying to optimsie 64 | // out this forAll loop under O3 optimisation 65 | if (debug) 66 | { 67 | Info<< "n=" << n << endl; 68 | } 69 | } 70 | 71 | return n; 72 | } 73 | 74 | 75 | void Foam::dynamicRefineFvMesh2D::calculateProtectedCells 76 | ( 77 | PackedBoolList& unrefineableCell 78 | ) const 79 | { 80 | if (protectedCell_.empty()) 81 | { 82 | unrefineableCell.clear(); 83 | return; 84 | } 85 | 86 | const labelList& cellLevel = meshCutter_.cellLevel(); 87 | 88 | unrefineableCell = protectedCell_; 89 | 90 | // Get neighbouring cell level 91 | labelList neiLevel(nFaces()-nInternalFaces()); 92 | 93 | for (label facei = nInternalFaces(); facei < nFaces(); facei++) 94 | { 95 | neiLevel[facei-nInternalFaces()] = cellLevel[faceOwner()[facei]]; 96 | } 97 | syncTools::swapBoundaryFaceList(*this, neiLevel); 98 | 99 | 100 | while (true) 101 | { 102 | // Pick up faces on border of protected cells 103 | boolList seedFace(nFaces(), false); 104 | 105 | forAll(faceNeighbour(), facei) 106 | { 107 | label own = faceOwner()[facei]; 108 | bool ownProtected = unrefineableCell.get(own); 109 | label nei = faceNeighbour()[facei]; 110 | bool neiProtected = unrefineableCell.get(nei); 111 | 112 | if (ownProtected && (cellLevel[nei] > cellLevel[own])) 113 | { 114 | seedFace[facei] = true; 115 | } 116 | else if (neiProtected && (cellLevel[own] > cellLevel[nei])) 117 | { 118 | seedFace[facei] = true; 119 | } 120 | } 121 | for (label facei = nInternalFaces(); facei < nFaces(); facei++) 122 | { 123 | label own = faceOwner()[facei]; 124 | bool ownProtected = unrefineableCell.get(own); 125 | if 126 | ( 127 | ownProtected 128 | && (neiLevel[facei-nInternalFaces()] > cellLevel[own]) 129 | ) 130 | { 131 | seedFace[facei] = true; 132 | } 133 | } 134 | 135 | syncTools::syncFaceList(*this, seedFace, orEqOp()); 136 | 137 | 138 | // Extend unrefineableCell 139 | bool hasExtended = false; 140 | 141 | for (label facei = 0; facei < nInternalFaces(); facei++) 142 | { 143 | if (seedFace[facei]) 144 | { 145 | label own = faceOwner()[facei]; 146 | if (unrefineableCell.get(own) == 0) 147 | { 148 | unrefineableCell.set(own, 1); 149 | hasExtended = true; 150 | } 151 | 152 | label nei = faceNeighbour()[facei]; 153 | if (unrefineableCell.get(nei) == 0) 154 | { 155 | unrefineableCell.set(nei, 1); 156 | hasExtended = true; 157 | } 158 | } 159 | } 160 | for (label facei = nInternalFaces(); facei < nFaces(); facei++) 161 | { 162 | if (seedFace[facei]) 163 | { 164 | label own = faceOwner()[facei]; 165 | if (unrefineableCell.get(own) == 0) 166 | { 167 | unrefineableCell.set(own, 1); 168 | hasExtended = true; 169 | } 170 | } 171 | } 172 | 173 | if (!returnReduce(hasExtended, orOp())) 174 | { 175 | break; 176 | } 177 | } 178 | } 179 | 180 | 181 | void Foam::dynamicRefineFvMesh2D::readDict() 182 | { 183 | dictionary refineDict 184 | ( 185 | IOdictionary 186 | ( 187 | IOobject 188 | ( 189 | "dynamicMeshDict", 190 | time().constant(), 191 | *this, 192 | IOobject::MUST_READ_IF_MODIFIED, 193 | IOobject::NO_WRITE, 194 | false 195 | ) 196 | ).optionalSubDict(typeName + "Coeffs") 197 | ); 198 | 199 | List> fluxVelocities = List> 200 | ( 201 | refineDict.lookup("correctFluxes") 202 | ); 203 | // Rework into hashtable. 204 | correctFluxes_.resize(fluxVelocities.size()); 205 | forAll(fluxVelocities, i) 206 | { 207 | correctFluxes_.insert(fluxVelocities[i][0], fluxVelocities[i][1]); 208 | } 209 | 210 | dumpLevel_ = Switch(refineDict.lookup("dumpLevel")); 211 | } 212 | 213 | 214 | // Refines cells, maps fields and recalculates (an approximate) flux 215 | Foam::autoPtr 216 | Foam::dynamicRefineFvMesh2D::refine 217 | ( 218 | const labelList& cellsToRefine 219 | ) 220 | { 221 | // Mesh changing engine. 222 | polyTopoChange meshMod(*this); 223 | 224 | // Play refinement commands into mesh changer. 225 | meshCutter_.setRefinement(cellsToRefine, meshMod); 226 | 227 | // Create mesh (with inflation), return map from old to new mesh. 228 | // autoPtr map = meshMod.changeMesh(*this, true); 229 | autoPtr map = meshMod.changeMesh(*this, false); 230 | 231 | Info<< "Refined from " 232 | << returnReduce(map().nOldCells(), sumOp