41 const dictionary& options,
54 labelList objFuncFaceSources;
55 labelList objFuncCellSources;
56 options.readEntry<labelList>(
"objFuncFaceSources", objFuncFaceSources);
57 options.readEntry<labelList>(
"objFuncCellSources", objFuncCellSources);
70 MatSetFromOptions(jacMat);
71 MatMPIAIJSetPreallocation(jacMat, 200, NULL, 200, NULL);
72 MatSeqAIJSetPreallocation(jacMat, 200, NULL);
75 MatZeroEntries(jacMat);
76 Info <<
"Partial derivative matrix created. " <<
mesh_.time().elapsedClockTime() <<
" s" << endl;
80 const dictionary& options,
106 label transposed = 0;
110 VecCreate(PETSC_COMM_WORLD, &coloredColumn);
112 VecSetFromOptions(coloredColumn);
113 VecZeroEntries(coloredColumn);
115 word objFuncName, objFuncPart;
116 dictionary objFuncSubDictPart = options.subDict(
"objFuncSubDictPart");
117 options.readEntry<word>(
"objFuncName", objFuncName);
118 options.readEntry<word>(
"objFuncPart", objFuncPart);
120 autoPtr<DAObjFunc> daObjFunc(
133 MatZeroEntries(jacMat);
136 VecDuplicate(wVec, &wVecNew);
137 VecCopy(wVec, wVecNew);
141 VecDuplicate(coloredColumn, &fVec);
142 VecDuplicate(coloredColumn, &fVecRef);
143 VecZeroEntries(fVec);
144 VecZeroEntries(fVecRef);
147 Vec normStatePerturbVec;
151 mOptions.set(
"updateState", 1);
152 mOptions.set(
"updateMesh", 0);
153 daObjFunc->masterFunction(mOptions, xvVec, wVec);
154 const scalarList& objFuncFaceValues = daObjFunc->getObjFuncFaceValues();
155 const scalarList& objFuncCellValues = daObjFunc->getObjFuncCellValues();
163 daObjFunc->calcRefCoeffs = 0;
167 scalar scalingKS = 1.0;
168 PetscScalar scalingKSValue = 0.0;
169 if (objFuncSubDictPart.getWord(
"type") ==
"vonMisesStressKS")
171 scalar coeffKS = objFuncSubDictPart.getScalar(
"coeffKS");
174 scalingKS = 1.0 / daObjFunc->expSumKS / coeffKS;
179 scalar rDelta = 1.0 / delta;
180 PetscScalar rDeltaValue = 0.0;
186 for (label color = 0; color < nColors; color++)
188 label eTime =
mesh_.time().elapsedClockTime();
190 if (color % printInterval == 0 or color == nColors - 1)
192 Info <<
modelType_ <<
": " << color <<
" of " << nColors
193 <<
", ExecutionTime: " << eTime <<
" s" << endl;
205 daObjFunc->masterFunction(mOptions, xvVec, wVecNew);
209 VecCopy(wVec, wVecNew);
212 VecAXPY(fVec, -1.0, fVecRef);
213 VecScale(fVec, rDeltaValue);
216 VecScale(fVec, scalingKSValue);
224 daObjFunc->calcRefCoeffs = 1;
227 scalar fRef = daObjFunc->masterFunction(mOptions, xvVec, wVec);
231 Info << objFuncName <<
": " << fRef << endl;
234 MatAssemblyBegin(jacMat, MAT_FINAL_ASSEMBLY);
235 MatAssemblyEnd(jacMat, MAT_FINAL_ASSEMBLY);