Skip to content

Commit

Permalink
release due to publication
Browse files Browse the repository at this point in the history
  • Loading branch information
MarlonFranke committed Dec 21, 2023
1 parent 7ffab5f commit 0e411b1
Show file tree
Hide file tree
Showing 62 changed files with 2,556 additions and 101 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# moofeKIT (matlab object-oriented finite element kit)

### changelog
https://git.scc.kit.edu/ifm/moofeKIT/-/blob/master/changelog.md
https://gitlab.kit.edu/marlon.franke/moofekit/-/blob/master/changelog.md
- meetings are scheduled approximately every three weeks (the upcoming meeting is scheduled in the changelog)
- the users are encouraged to merge all feature branches (**if well-engineered, useful to others and intended for the public**) to masterExperimental branch generously before the upcoming meeting
- masterExperimental branch will be merged to master branch
- main changes will be logged
- **only the master branch will be merged to master branch of public github repo** https://github.com/kit-ifm/moofeKIT
### git howto and workflow idea
git howto and workflow idea is provided via https://git.scc.kit.edu/ifm/anleitungen/software/-/blob/master/git/simple_cheat_sheet.md
git howto and workflow idea is provided via https://gitlab.kit.edu/kit/ifm/anleitungen/software/-/blob/master/git/simple_cheat_sheet.md

see also https://training.github.com/downloads/github-git-cheat-sheet.pdf and https://rhoenerlebnis.de/_upl/de/_pdf-seite/git_cheatsheet_de_white.pdf
### best practice for clean code
Expand All @@ -20,17 +20,17 @@ see also https://training.github.com/downloads/github-git-cheat-sheet.pdf and ht
- A function should do one thing, and only one thing (modularity)!
- Use external toolbox https://github.com/davidvarga/MBeautifier for source code formatting. It is already included via submodule 'git submodule add https://github.com/davidvarga/MBeautifier.git externalToolboxes/MBeautifier'. In matlab the code in current editor can be 'beautified' via command 'MBeautify.formatCurrentEditorPage()'. A shortcut can be created via 'Home', 'Favorites', 'New Favorite' by adding the command 'MBeautify.formatCurrentEditorPage()'.
### handling issues
- please list issues https://git.scc.kit.edu/franke/moofeKIT/-/issues
- please list issues https://gitlab.kit.edu/marlon.franke/moofekit/-/issues
- if the problem could be devided into small parts **use checklist** in markdown
- assign it (if possible) to a member
- set due date (if possible)
### howto comment/manual
a dedicated manual is not planned, all scritps/classes/functions/methods should be documented via commented help text immediately below the function definition line, see
a dedicated manual is not planned, all scripts/classes/functions/methods should be documented via commented help text immediately below the function definition line, see
https://de.mathworks.com/help/matlab/matlab_prog/add-help-for-your-program.html
- example files
- script: https://git.scc.kit.edu/ifm/moofeKIT/-/blob/master/scripts/pre/LShapeElectroThermoMechanics.m
- class: https://git.scc.kit.edu/ifm/moofeKIT/-/blob/master/coreClasses/@solidSuperClass/solidSuperClass.m
- function: https://git.scc.kit.edu/ifm/moofeKIT/-/blob/master/continuumClasses/@solidClass/displacementSCSaintVenantEndpoint.m
- script: https://gitlab.kit.edu/marlon.franke/moofekit/-/blob/master/scripts/pre/LShapeElectroThermoMechanics.m
- class: https://gitlab.kit.edu/marlon.franke/moofekit/-/blob/master/coreClasses/@solidSuperClass/solidSuperClass.m
- function: https://gitlab.kit.edu/marlon.franke/moofekit/-/blob/master/continuumClasses/@solidClass/displacementSCSaintVenantEndpoint.m
- useful matlab code
- for help of a function/class type _>> help function-name_
or _>> doc function-name_
Expand All @@ -48,4 +48,4 @@ matlab specific object-oriented programming can be found at https://de.mathworks

for a simple matlab example https://de.mathworks.com/company/newsletters/articles/introduction-to-object-oriented-programming-in-matlab.html might be helpful
### gitlab runner for continuous integration
a short manual for gitlab runner for continous integration (CI) with testing code in matlab can be found at https://git.scc.kit.edu/franke/ubuntuinstallationmitarbeiterrechnerifm/-/blob/master/gitlabRunner.txt
a short manual for gitlab runner for continous integration (CI) with testing code in matlab can be found at https://gitlab.kit.edu/marlon.franke/ubuntuinstallationmitarbeiterrechnerifm/-/blob/master/gitlabRunner.txt?ref_type=heads
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
if isa(obj.masterObject, 'stringClass')
dimension = size(obj.masterObject.qR,2);
else
dimension = 1;
dimension = obj.masterObject.dimension;;
end
edof = obj.masterObject.meshObject.edof;
DT = setupObject.timeStepSize;
Expand Down
12 changes: 11 additions & 1 deletion continuumClasses/@bodyForceClass/deadLoadEndpoint.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,27 @@
numberOfGausspoints = shapeFunctionObject.numberOfGausspoints;
N_k_I = shapeFunctionObject.N_k_I;
dN_xi_k_I = shapeFunctionObject.dN_xi_k_I;
dimension = obj.masterObject.dimension;

if isa(obj.masterObject, 'stringClass')
dimension = size(obj.masterObject.qR,2);
else
dimension = obj.masterObject.dimension;
end
edof = obj.masterObject.meshObject.edof;
timeFunction = obj.timeFunction(obj.time);
loadFunction = obj.loadFunction;
edR = obj.masterObject.qR(edof(e,:), 1:dimension)';
edN = obj.masterObject.qN(edof(e,:), 1:dimension)';
edN1 = obj.masterObject.qN1(edof(e,:), 1:dimension)';
edN05 = 1/2*(edN+ edN1);

elementEnergy.externalEnergy = 0;
for k = 1:numberOfGausspoints
dN_xi_I = reshape(dN_xi_k_I(:,k,:),[size(dN_xi_k_I,1),size(dN_xi_k_I,3)]);
[~,detJ] = computeJacobian(edR,dN_xi_I,setupObject.toleranceDetJ,setupObject.computePostData);
%position and bodyforce
Xh = kron(N_k_I(k,:),eye(dimension))*edR(:);
xh = kron(N_k_I(k,:),eye(dimension))*edN1(:);
if isa(loadFunction,'function_handle')
B0 = loadFunction(Xh(1),Xh(2),Xh(3));
else
Expand Down
2 changes: 1 addition & 1 deletion continuumClasses/@bodyForceClass/deadLoadMidpoint.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
if isa(obj.masterObject, 'stringClass')
dimension = size(obj.masterObject.qR,2);
else
dimension = 1;
dimension = obj.masterObject.dimension;;
end
edof = obj.masterObject.meshObject.edof;
DT = setupObject.timeStepSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,7 @@
CN05 = 1/2 *(CN + CN1);

% material data
lambda = materialObject.lambda;
mu = materialObject.mu;

if dimension == 1
if isfield(materialObject, 'E')
EA = materialObject.E;
else
EA = mu * (3 * lambda + 2 * mu) / (lambda + mu);
end
else
error('Wrong dimension for this elementroutine. (only dim=1)')
end
EA = materialObject.EA;

selectMapVoigt(mapVoigtObject, dimension, 'symmetric');

Expand Down
13 changes: 1 addition & 12 deletions continuumClasses/@stringClass/mixedPHCHyperelasticMidpoint.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,7 @@
CN05 = 1/2 *(CN + CN1);

% material data
lambda = materialObject.lambda;
mu = materialObject.mu;

if dimension == 1
if isfield(materialObject, 'E')
EA = materialObject.E;
else
EA = mu * (3 * lambda + 2 * mu) / (lambda + mu);
end
else
error('Wrong dimension for this elementroutine. (only dim=1)')
end
EA = materialObject.EA;

% Voigt notation
selectMapVoigt(mapVoigtObject, dimension, 'symmetric');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
function [rData, kData, elementEnergy, array] = mixedPHCHyperelasticViscoDiscreteGradient(obj, setupObject, computePostData, e, rData, kData, dofs, array, stressTensor, flagNumericalTangent)
% MIXEDPHHYPERELASTICDISCRETEGRADIENT Element routine of class solidClass.
%
% FORMULATION
% This is a 'mixed'-based finite element routine with linear elastic
% material (St.-Venant Kirchhoff material for large displacements).
% This is a port-Hamiltonian formulation with independent velocities, and
% strains.
% The routine is suitable for dynamic simulation where the midpoint
% rule is applied.
%
% CALL
% mixedPHStVenantMidpoint(obj,setupObject,computePostData)
% obj: The first argument is expected to be an object of type solidClass,
% e.g. solidObject.
% setupObject: The second argument is expected to be an object of type
% setupClass, e.g. setupObject which cotains informations like
% time step size or plotting informations.
% computePostData: Logical data type which is true for computing stress
% only and false for computing residual and tangent.
% e: current element number
% rData: cell-array of size [totalNumberOfFields,1] for residual data of
% every field, here: (...)
% kData: cell-array of size [totalNumberOfFields, totalNumberOfFields] for
% tangent data of every field, here: (...)
% dofs: degrees of freedom (dofs) optionally manipulated data (numerical
% tangent)
% array: structure for storage fe-data, for more information see
% storageFEObject.initializeArrayStress
% stressTensor: structure for storage stress tensors (postprocessing), for
% more information see storageFEObject.initializeArrayStress
% flagNumericalTangent: flag that indicates whether the function call
% happens during the computation of the numerical
% tangent or not.
%
% REFERENCE
% ...
%
% SEE ALSO
% mixedPHCStVenantMidpoint, mixedPHCHyperelasticMidpoint
%
% CREATOR(S)
% Philipp Kinon

%% SETUP
% load objects
shapeFunctionObject = obj.shapeFunctionObject;
materialObject = obj.materialObject;
mixedFEObject = obj.mixedFEObject;
mapVoigtObject = obj.mapVoigtObject;
meshObject = obj.meshObject;
h = setupObject.timeStepSize;
% element degree of freedom tables and more
edof = meshObject.edof;
dimension = obj.dimension;

% data for displacement dofs
N_k_I = shapeFunctionObject.N_k_I;
dN_xi_k_I = shapeFunctionObject.dN_xi_k_I;
gaussWeight = shapeFunctionObject.gaussWeight;
numberOfGausspoints = shapeFunctionObject.numberOfGausspoints;

% aquire the nodal values of the variables for the current element
dimAbs = size(obj.qR,2);
edR = obj.qR(edof(e, :), 1:dimAbs).';
edN = obj.qN(edof(e, :), 1:dimAbs).';
edN1 = dofs.edN1;

% position vectors
rN = edN(:);
rN1 = edN1(:);
rN05 = 1/2*(rN+rN1);

% mixed FE data
Phi = mixedFEObject.shapeFunctionObject.N_k_I;
CN = mixedFEObject.qN(e,:)';
CN1 = dofs.edAlphaN1;
CN05 = 1/2 *(CN + CN1);

% material data
EA = materialObject.EA;
etaA = materialObject.etaA;

selectMapVoigt(mapVoigtObject, dimension, 'symmetric');

%% Create residual and tangent
% initialize
elementEnergy.strainEnergy = 0;
elementEnergy.dissipatedEnergy = 0;
Ms = zeros(1,1);
K = zeros(2*dimAbs,1);
DKDr = zeros(2*dimAbs,2*dimAbs);
DHDC = 0;
D2HDC2 = 0;
A = zeros(2*dimAbs,2*dimAbs);
A2 = zeros(2*dimAbs,2*dimAbs);
DADr = zeros(2*dimAbs,2*dimAbs);
DADC = zeros(2*dimAbs,2*dimAbs);

% compute Jacobian
JAll = computeJacobianForAllGausspoints(edR, dN_xi_k_I);
% Run through all Gauss points
for k = 1:numberOfGausspoints

[J, detJ] = extractJacobianForGausspoint(JAll, k, setupObject, dimension);
dN_X_I = computedN_X_I(dN_xi_k_I, J, k);

B = [dN_X_I(1)*eye(dimAbs) dN_X_I(2)*eye(dimAbs)];

if ~computePostData

% mass and stiffness matrix
Ms = Ms + Phi(k, :)' * Phi(k, :) * detJ * gaussWeight(k);
K = K + B'*B*rN05*Phi(k, :) * detJ * gaussWeight(k);
DKDr = DKDr + B'*B*Phi(k, :) * detJ * gaussWeight(k);
% visco
A = A + etaA/CN05 * (B'*B)*(rN05*rN05')*(B'*B) * detJ * gaussWeight(k);
A2 = A2 + etaA/CN05 * (B'*B)*(rN05*(rN1-rN)')*(B'*B) * detJ * gaussWeight(k);
DADr = DADr + etaA/CN05 * (B'*B)*((B'*B*rN05)'*(rN1-rN)) * detJ * gaussWeight(k);
DADC = DADC + -etaA/CN05^2*1/2*Phi(k,:) * (B'*B)*(rN05*rN05')*(B'*B) * detJ * gaussWeight(k);

%current strains
CN = Phi(k,:)*CN;
CN1 = Phi(k,:)*CN1;
CN05 = Phi(k,:)*CN05;

% discrete gradient evaluation
if (abs(CN1 - CN) <= 1e-4)
% use midpoint rule if CN1 \approx CN
DHDC = DHDC + Phi(k,:)'*getStrainEnergyDerivative(EA,CN05) * detJ * gaussWeight(k);
D2HDC2 = D2HDC2 + Phi(k,:)'*getStrainEnergyHessian(EA,CN05)* 1/2 * detJ * gaussWeight(k);
else
WN = getStrainEnergy(EA, CN);
WN1 = getStrainEnergy(EA, CN1);
DHDC = DHDC + Phi(k,:)'*(WN1 - WN)/(CN1 -CN) * detJ * gaussWeight(k);
D2HDC2 = D2HDC2 + Phi(k,:)'*(getStrainEnergyDerivative(EA,CN1)/(CN1-CN)-(WN1 - WN)/(CN1 -CN)^2) * detJ * gaussWeight(k);
end

% stored strain energy
elementEnergy.strainEnergy = elementEnergy.strainEnergy + getStrainEnergy(EA,CN1) * detJ * gaussWeight(k);
elementEnergy.dissipatedEnergy = elementEnergy.dissipatedEnergy + etaA/(h*CN05) * ((rN1-rN)'*(B'*B)*rN05)^2 * detJ * gaussWeight(k);

else
% stress at gausspoint
[~, detJStruct, ~, ~] = computeAllJacobian(edR,edN,edN1,dN_xi_k_I,k,setupObject);
SN1_V = 2*getStrainEnergyDerivative(EA,CN1);
SN1 = voigtToMatrix(SN1_V, 'stress');
stressTensor.Cauchy = SN1;
array = postStressComputation(array,N_k_I,k,gaussWeight,detJStruct,stressTensor,setupObject,dimension);
end
end

if ~computePostData

% residual
MsInv = Ms \ eye(size(Ms));
Rv = 2 * K * MsInv * DHDC + A * (rN1-rN)/h;
Reps = Ms * (CN1 - CN) - 2 * K' * (rN1-rN) ;
rData{1} = Rv;
rData{2} = Reps;

% tangent
kData{1,1} = 2 * DKDr * MsInv * DHDC * 1/2 + A/h + 1/2 * DADr / h + 1/2* A2/h;
kData{1,2} = 2 * K * MsInv * D2HDC2 + DADC* (rN1-rN)/h;
kData{2,1} = -2 * K' - 2*1/2*(DKDr*(rN1-rN))';
kData{2,2} = Ms;

end

end

%% Constitutive model
function W = getStrainEnergy(EA, C)

W = 1/4*EA*(C-log(C)-1);

end

function DWC = getStrainEnergyDerivative(EA, C)

DWC = 1/4*EA*(1-1/C);

end

function DWC = getStrainEnergyHessian(EA, C)

DWC = 1/4*EA*1/(C^2);

end
Loading

0 comments on commit 0e411b1

Please sign in to comment.