Skip to content

Commit

Permalink
calc fitness based on inversed deformation energy
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilPoulsen committed Jul 24, 2018
1 parent ebec5b1 commit b095996
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 19 deletions.
2 changes: 2 additions & 0 deletions Frixel.Core/AnalysisResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public AnalysisResults()
public Dictionary<int, NodeResult> NodeResults;
public Dictionary<int, ElementResult> ElementResults;
public Dictionary<int, PixelResult> PixelResults;

public double ElasticEnergy { get; set; }
}

public class AnalysisSummary
Expand Down
72 changes: 53 additions & 19 deletions Frixel.Optimizer/Analysis/FrixelAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public AnalysisResults AnalyzeModel(FiniteElementModel model) {
});
i++;
}
pixResults.ElasticEnergy = CalcElasticEnergy(model, results);

//CalcElementResults(model);

return pixResults;
Expand All @@ -59,34 +61,41 @@ public DisplacementVector GetDisplacement(IFiniteElementNode node, FiniteElement
return disp;
}

public List<ElementResult> CalcElementResults(FiniteElementModel model, FiniteElementResults results) {
List<ElementResult> output = new List<ElementResult>();
public double CalcElasticEnergy(FiniteElementModel model, FiniteElementResults results) {
double totalWork = 0;

//1. Calculate for frames
foreach (var elem in model.Elements) {

if (elem is LinearTruss) {

var truss = elem as LinearTruss;
var startLoc = truss.StartNode.Location;
var endLoc = truss.EndNode.Location;

var startDisp = GetDisplacement(truss.StartNode, results);
var endDisp = GetDisplacement(truss.EndNode, results);
double dx = CalcDx(truss, results);

double E = truss.Material.YoungsModulus;
double A = truss.CrossSection.Area;

double work = 0.5 * E * A * Math.Pow(dx, 2);
totalWork += work;

}
}
return totalWork;
}

public List<ElementResult> CalcElementResults(FiniteElementModel model, FiniteElementResults results) {
List<ElementResult> output = new List<ElementResult>();

var dispStartLoc = new CartesianPoint(
truss.StartNode.X + startDisp.X,
truss.StartNode.Y + startDisp.Y,
truss.StartNode.Z + startDisp.Z);
var dispEndLoc = new CartesianPoint(
truss.EndNode.X + endDisp.X,
truss.EndNode.Y + endDisp.Y,
truss.EndNode.Z + endDisp.Z);
//1. Calculate for frames
foreach (var elem in model.Elements) {

double initialDist = Distance(startLoc, endLoc);
double deformedDist = Distance(dispStartLoc, dispEndLoc);
if (elem is LinearTruss) {
var truss = elem as LinearTruss;

double dx = deformedDist - initialDist;
var axialForce = truss.Material.YoungsModulus * truss.CrossSection.Area * dx;
double dx = CalcDx(truss, results);
double E = truss.Material.YoungsModulus;
double A = truss.CrossSection.Area;
var axialForce = E * A * dx;

output.Add(new ElementResult() { AxialForce = axialForce });
}
Expand All @@ -95,6 +104,31 @@ public List<ElementResult> CalcElementResults(FiniteElementModel model, FiniteEl
return output;
}

public double CalcDx(LinearTruss truss, FiniteElementResults results) {
var startLoc = truss.StartNode.Location;
var endLoc = truss.EndNode.Location;

var startDisp = GetDisplacement(truss.StartNode, results);
var endDisp = GetDisplacement(truss.EndNode, results);

var dispStartLoc = new CartesianPoint(
truss.StartNode.X + startDisp.X,
truss.StartNode.Y + startDisp.Y,
truss.StartNode.Z + startDisp.Z);
var dispEndLoc = new CartesianPoint(
truss.EndNode.X + endDisp.X,
truss.EndNode.Y + endDisp.Y,
truss.EndNode.Z + endDisp.Z);

double initialDist = Distance(startLoc, endLoc);
double deformedDist = Distance(dispStartLoc, dispEndLoc);

double dx = deformedDist - initialDist;

return dx;

}

public List<ElementResult> CalculatePixelResult() {
//2. Calculate for bracings
return null;
Expand Down

0 comments on commit b095996

Please sign in to comment.