public void UpdateBubbleFieldValueValuesFromNodeValues( uint valueId, FieldDerivativeType dt, double[] nodeValues) { System.Diagnostics.Debug.Assert(FieldValueArray.IsObjectId(valueId)); FieldValue fv = FieldValueArray.GetObject(valueId); uint quantityId = fv.QuantityId; uint dof = fv.Dof; System.Diagnostics.Debug.Assert(fv.Dof == GetDof(quantityId)); double[] values = fv.GetDoubleValues(dt); uint coCnt = GetCoordCount(quantityId); uint offsetNode = 0; for (uint qId = 0; qId < quantityId; qId++) { offsetNode += GetNodeCount(qId) * GetDof(qId); } IList <uint> feIds = GetTriangleFEIds(quantityId); foreach (uint feId in feIds) { TriangleFE triFE = GetTriangleFE(quantityId, feId); int[] coIds = triFE.NodeCoordIds; uint elemNodeCnt = triFE.NodeCount; double[] bubbleValue = new double[dof]; for (int iNode = 0; iNode < elemNodeCnt; iNode++) { int coId = coIds[iNode]; int nodeId = Coord2Node(quantityId, coId); if (nodeId == -1) { //for (int iDof = 0; iDof < dof; iDof++) //{ // bubbleValue[iDof] += 0; //} } else { for (int iDof = 0; iDof < dof; iDof++) { bubbleValue[iDof] += nodeValues[offsetNode + nodeId * dof + iDof]; } } } for (int iDof = 0; iDof < dof; iDof++) { bubbleValue[iDof] /= (double)elemNodeCnt; } for (int iDof = 0; iDof < dof; iDof++) { values[(feId - 1) * dof + iDof] = bubbleValue[iDof]; } } }
public void UpdateFieldValueValuesFromCoordValues( uint valueId, FieldDerivativeType dt, double[] coordValues) { System.Diagnostics.Debug.Assert(FieldValueArray.IsObjectId(valueId)); FieldValue fv = FieldValueArray.GetObject(valueId); //uint quantityId = fv.QuantityId; //uint dof = fv.Dof; double[] values = fv.GetDoubleValues(dt); System.Diagnostics.Debug.Assert(values.Length == coordValues.Length); coordValues.CopyTo(values, 0); }
public void UpdateBubbleFieldValueValuesFromCoordValues( uint valueId, FieldDerivativeType dt, double[] coordValues) { System.Diagnostics.Debug.Assert(FieldValueArray.IsObjectId(valueId)); FieldValue fv = FieldValueArray.GetObject(valueId); uint quantityId = fv.QuantityId; uint dof = fv.Dof; double[] values = fv.GetDoubleValues(dt); uint coCnt = GetCoordCount(quantityId); System.Diagnostics.Debug.Assert(coCnt * dof == coordValues.Length); IList <uint> feIds = GetTriangleFEIds(quantityId); foreach (uint feId in feIds) { TriangleFE triFE = GetTriangleFE(quantityId, feId); int[] coIds = triFE.NodeCoordIds; uint elemNodeCnt = triFE.NodeCount; double[] bubbleValue = new double[dof]; for (int iNode = 0; iNode < elemNodeCnt; iNode++) { int coId = coIds[iNode]; for (int iDof = 0; iDof < dof; iDof++) { bubbleValue[iDof] += coordValues[coId * dof + iDof]; } } for (int iDof = 0; iDof < dof; iDof++) { bubbleValue[iDof] /= (double)elemNodeCnt; } for (int iDof = 0; iDof < dof; iDof++) { values[(feId - 1) * dof + iDof] = bubbleValue[iDof]; } } }
public void UpdateFieldValueValuesFromNodeValues( uint valueId, FieldDerivativeType dt, double[] nodeValues) { System.Diagnostics.Debug.Assert(FieldValueArray.IsObjectId(valueId)); FieldValue fv = FieldValueArray.GetObject(valueId); uint quantityId = fv.QuantityId; uint dof = fv.Dof; System.Diagnostics.Debug.Assert(fv.Dof == GetDof(quantityId)); double[] values = fv.GetDoubleValues(dt); uint coCnt = GetCoordCount(quantityId); uint offsetNode = 0; for (uint qId = 0; qId < quantityId; qId++) { offsetNode += GetNodeCount(qId) * GetDof(qId); } for (int coId = 0; coId < coCnt; coId++) { int nodeId = Coord2Node(quantityId, coId); if (nodeId == -1) { for (int iDof = 0; iDof < dof; iDof++) { values[coId * dof + iDof] = 0; } } else { for (int iDof = 0; iDof < dof; iDof++) { values[coId * dof + iDof] = nodeValues[offsetNode + nodeId * dof + iDof]; } } } }
// Linear / Saint Venant public void SetStressValue( uint displacementValueId, uint stressValueId, uint equivStressValueId) { System.Diagnostics.Debug.Assert(World.IsFieldValueId(displacementValueId)); FieldValue uFV = World.GetFieldValue(displacementValueId); uint uQuantityId = uFV.QuantityId; FieldValue sigmaFV = null; if (stressValueId != 0) { System.Diagnostics.Debug.Assert(World.IsFieldValueId(stressValueId)); sigmaFV = World.GetFieldValue(stressValueId); System.Diagnostics.Debug.Assert(sigmaFV.Type == FieldValueType.SymmetricTensor2); System.Diagnostics.Debug.Assert(sigmaFV.Dof == 3); } FieldValue eqSigmaFV = null; if (equivStressValueId != 0) { System.Diagnostics.Debug.Assert(World.IsFieldValueId(equivStressValueId)); eqSigmaFV = World.GetFieldValue(equivStressValueId); System.Diagnostics.Debug.Assert(eqSigmaFV.Type == FieldValueType.Scalar); System.Diagnostics.Debug.Assert(eqSigmaFV.Dof == 1); } IList <uint> feIds = World.GetTriangleFEIds(uQuantityId); foreach (uint feId in feIds) { TriangleFE triFE = World.GetTriangleFE(uQuantityId, feId); int[] coIds = triFE.NodeCoordIds; Material ma = World.GetMaterial(triFE.MaterialId); double lambda = 0; double mu = 0; if (ma is LinearElasticMaterial) { var ma1 = ma as LinearElasticMaterial; lambda = ma1.LameLambda; mu = ma1.LameMu; } else if (ma is SaintVenantHyperelasticMaterial) { var ma1 = ma as SaintVenantHyperelasticMaterial; lambda = ma1.LameLambda; mu = ma1.LameMu; } else { System.Diagnostics.Debug.Assert(false); throw new NotImplementedException(); } var ip = TriangleFE.GetIntegrationPoints(TriangleIntegrationPointCount.Point1); System.Diagnostics.Debug.Assert(ip.PointCount == 1); double[] L = ip.Ls[0]; double[][] Nu = triFE.CalcNu(L); double[] Nx = Nu[0]; double[] Ny = Nu[1]; double[,] uu = new double[2, 2]; for (int iNode = 0; iNode < coIds.Length; iNode++) { int coId = coIds[iNode]; double[] u = uFV.GetDoubleValue(coId, FieldDerivativeType.Value); uu[0, 0] += u[0] * Nx[iNode]; uu[0, 1] += u[0] * Ny[iNode]; uu[1, 0] += u[1] * Nx[iNode]; uu[1, 1] += u[1] * Ny[iNode]; } //ε strain double[,] eps = new double[2, 2]; if (ma is LinearElasticMaterial) { eps[0, 0] = (1.0 / 2.0) * (uu[0, 0] + uu[0, 0]); eps[0, 1] = (1.0 / 2.0) * (uu[0, 1] + uu[1, 0]); eps[1, 0] = (1.0 / 2.0) * (uu[1, 0] + uu[0, 1]); eps[1, 1] = (1.0 / 2.0) * (uu[1, 1] + uu[1, 1]); } else if (ma is SaintVenantHyperelasticMaterial) { eps[0, 0] = (1.0 / 2.0) * (uu[0, 0] + uu[0, 0] + uu[0, 0] * uu[0, 0] + uu[1, 0] * uu[1, 0]); eps[0, 1] = (1.0 / 2.0) * (uu[0, 1] + uu[1, 0] + uu[0, 0] * uu[0, 1] + uu[1, 1] * uu[1, 0]); eps[1, 0] = (1.0 / 2.0) * (uu[1, 0] + uu[0, 1] + uu[0, 1] * uu[0, 0] + uu[1, 0] * uu[1, 1]); eps[1, 1] = (1.0 / 2.0) * (uu[1, 1] + uu[1, 1] + uu[0, 1] * uu[0, 1] + uu[1, 1] * uu[1, 1]); } else { System.Diagnostics.Debug.Assert(false); } // σ stress double[,] sigma = new double[2, 2]; { sigma[0, 0] = mu * eps[0, 0]; sigma[0, 1] = mu * eps[0, 1]; sigma[1, 0] = mu * eps[1, 0]; sigma[1, 1] = mu * eps[1, 1]; double tmp = lambda * (eps[0, 0] + eps[1, 1]); sigma[0, 0] += tmp; sigma[1, 1] += tmp; } double misesStress = Math.Sqrt( (1.0 / 2.0) * ( sigma[0, 0] * sigma[0, 0] + sigma[1, 1] * sigma[1, 1] + (sigma[1, 1] - sigma[0, 0]) * (sigma[1, 1] - sigma[0, 0]) ) + 3.0 * sigma[0, 1] * sigma[0, 1]); if (stressValueId != 0) { double[] Sigma = sigmaFV.GetDoubleValues(FieldDerivativeType.Value); uint dof = sigmaFV.Dof; Sigma[(feId - 1) * dof + 0] = sigma[0, 0]; // σxx Sigma[(feId - 1) * dof + 1] = sigma[1, 1]; // σyy Sigma[(feId - 1) * dof + 2] = sigma[0, 1]; // τxy } if (equivStressValueId != 0) { double[] EqSigma = eqSigmaFV.GetDoubleValues(FieldDerivativeType.Value); EqSigma[feId - 1] = misesStress; } } }