private static void FrameElementForce(double[] s, List <Vec3Float> xyz, double L, double Le, int n1, int n2, float Ax, float Asy, float Asz, float J, float Iy, float Iz, float E, float G, float p, double[] fT, double[] fM, double[] D, bool shear, bool geom, double axialStrain)//return s { double d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, delta = 0.0, /* stretch in the frame element */ Ksy, Ksz, Dsy, Dsz, /* shear deformation coeff's */ T = 0.0; /* axial force for geometric stiffness */ double f1 = 0, f2 = 0, f3 = 0, f4 = 0, f5 = 0, f6 = 0, f7 = 0, f8 = 0, f9 = 0, f10 = 0, f11 = 0, f12 = 0; double[] t = Coordtrans.coordTrans(xyz, L, n1, n2, p); n1 = 6 * n1; n2 = 6 * n2; d1 = D[n1 + 0]; d2 = D[n1 + 1]; d3 = D[n1 + 2]; d4 = D[n1 + 3]; d5 = D[n1 + 4]; d6 = D[n1 + 5]; d7 = D[n2 + 0]; d8 = D[n2 + 1]; d9 = D[n2 + 2]; d10 = D[n2 + 3]; d11 = D[n2 + 4]; d12 = D[n2 + 5]; if (shear) { Ksy = 12.0 * E * Iz / (G * Asy * Le * Le); Ksz = 12.0 * E * Iy / (G * Asz * Le * Le); Dsy = (1 + Ksy) * (1 + Ksy); Dsz = (1 + Ksz) * (1 + Ksz); } else { Ksy = Ksz = 0.0; Dsy = Dsz = 1.0; } delta = (d7 - d1) * t[0] + (d8 - d2) * t[1] + (d9 - d3) * t[2]; axialStrain = delta / Le; // log(Ls/Le); s[0] = -(Ax * E / Le) * ((d7 - d1) * t[0] + (d8 - d2) * t[1] + (d9 - d3) * t[2]); if (geom) { T = -s[0]; } s[1] = -(12.0 * E * Iz / (Le * Le * Le * (1.0 + Ksy)) + T / L * (1.2 + 2.0 * Ksy + Ksy * Ksy) / Dsy) * ((d7 - d1) * t[3] + (d8 - d2) * t[4] + (d9 - d3) * t[5]) + (6.0 * E * Iz / (Le * Le * (1.0 + Ksy)) + T / 10.0 / Dsy) * ((d4 + d10) * t[6] + (d5 + d11) * t[7] + (d6 + d12) * t[8]); s[2] = -(12.0 * E * Iy / (Le * Le * Le * (1.0 + Ksz)) + T / L * (1.2 + 2.0 * Ksz + Ksz * Ksz) / Dsz) * ((d7 - d1) * t[6] + (d8 - d2) * t[7] + (d9 - d3) * t[8]) - (6.0 * E * Iy / (Le * Le * (1.0 + Ksz)) + T / 10.0 / Dsz) * ((d4 + d10) * t[3] + (d5 + d11) * t[4] + (d6 + d12) * t[5]); s[3] = -(G * J / Le) * ((d10 - d4) * t[0] + (d11 - d5) * t[1] + (d12 - d6) * t[2]); s[4] = (6.0 * E * Iy / (Le * Le * (1.0 + Ksz)) + T / 10.0 / Dsz) * ((d7 - d1) * t[6] + (d8 - d2) * t[7] + (d9 - d3) * t[8]) + ((4.0 + Ksz) * E * Iy / (Le * (1.0 + Ksz)) + T * L * (2.0 / 15.0 + Ksz / 6.0 + Ksz * Ksz / 12.0) / Dsz) * (d4 * t[3] + d5 * t[4] + d6 * t[5]) + ((2.0 - Ksz) * E * Iy / (Le * (1.0 + Ksz)) - T * L * (1.0 / 30.0 + Ksz / 6.0 + Ksz * Ksz / 12.0) / Dsz) * (d10 * t[3] + d11 * t[4] + d12 * t[5]); s[5] = -(6.0 * E * Iz / (Le * Le * (1.0 + Ksy)) + T / 10.0 / Dsy) * ((d7 - d1) * t[3] + (d8 - d2) * t[4] + (d9 - d3) * t[5]) + ((4.0 + Ksy) * E * Iz / (Le * (1.0 + Ksy)) + T * L * (2.0 / 15.0 + Ksy / 6.0 + Ksy * Ksy / 12.0) / Dsy) * (d4 * t[6] + d5 * t[7] + d6 * t[8]) + ((2.0 - Ksy) * E * Iz / (Le * (1.0 + Ksy)) - T * L * (1.0 / 30.0 + Ksy / 6.0 + Ksy * Ksy / 12.0) / Dsy) * (d10 * t[6] + d11 * t[7] + d12 * t[8]); s[6] = -s[0]; s[7] = -s[1]; s[8] = -s[2]; s[9] = -s[3]; s[10] = (6.0 * E * Iy / (Le * Le * (1.0 + Ksz)) + T / 10.0 / Dsz) * ((d7 - d1) * t[6] + (d8 - d2) * t[7] + (d9 - d3) * t[8]) + ((4.0 + Ksz) * E * Iy / (Le * (1.0 + Ksz)) + T * L * (2.0 / 15.0 + Ksz / 6.0 + Ksz * Ksz / 12.0) / Dsz) * (d10 * t[3] + d11 * t[4] + d12 * t[5]) + ((2.0 - Ksz) * E * Iy / (Le * (1.0 + Ksz)) - T * L * (1.0 / 30.0 + Ksz / 6.0 + Ksz * Ksz / 12.0) / Dsz) * (d4 * t[3] + d5 * t[4] + d6 * t[5]); s[11] = -(6.0 * E * Iz / (Le * Le * (1.0 + Ksy)) + T / 10.0 / Dsy) * ((d7 - d1) * t[3] + (d8 - d2) * t[4] + (d9 - d3) * t[5]) + ((4.0 + Ksy) * E * Iz / (Le * (1.0 + Ksy)) + T * L * (2.0 / 15.0 + Ksy / 6.0 + Ksy * Ksy / 12.0) / Dsy) * (d10 * t[6] + d11 * t[7] + d12 * t[8]) + ((2.0 - Ksy) * E * Iz / (Le * (1.0 + Ksy)) - T * L * (1.0 / 30.0 + Ksy / 6.0 + Ksy * Ksy / 12.0) / Dsy) * (d4 * t[6] + d5 * t[7] + d6 * t[8]); // add fixed end forces to internal element forces // 18oct[1]012, 14may1204, 15may2014 // add temperature fixed-end-forces to variables f1-f12 // add mechanical load fixed-end-forces to variables f1-f12 // f1 ... f12 are in the global element coordinate system f1 = fT[0] + fM[0]; f2 = fT[1] + fM[1]; f3 = fT[2] + fM[2]; f4 = fT[3] + fM[3]; f5 = fT[4] + fM[4]; f6 = fT[5] + fM[5]; f7 = fT[6] + fM[6]; f8 = fT[7] + fM[7]; f9 = fT[8] + fM[8]; f10 = fT[9] + fM[9]; f11 = fT[10] + fM[10]; f12 = fT[11] + fM[11]; // transform f1 ... f12 to local element coordinate system and // add local fixed end forces (-equivalent loads) to internal loads // {Q} = [T]{f} s[0] -= (f1 * t[0] + f2 * t[1] + f3 * t[2]); s[1] -= (f1 * t[3] + f2 * t[4] + f3 * t[5]); s[2] -= (f1 * t[6] + f2 * t[7] + f3 * t[8]); s[3] -= (f4 * t[0] + f5 * t[1] + f6 * t[2]); s[4] -= (f4 * t[3] + f5 * t[4] + f6 * t[5]); s[5] -= (f4 * t[6] + f5 * t[7] + f6 * t[8]); s[6] -= (f7 * t[0] + f8 * t[1] + f9 * t[2]); s[7] -= (f7 * t[3] + f8 * t[4] + f9 * t[5]); s[8] -= (f7 * t[6] + f8 * t[7] + f9 * t[8]); s[9] -= (f10 * t[0] + f11 * t[1] + f12 * t[2]); s[10] -= (f10 * t[3] + f11 * t[4] + f12 * t[5]); s[11] -= (f10 * t[6] + f11 * t[7] + f12 * t[8]); }
public static void ElasticK(double[,] k, List <Vec3Float> xyz, float[] r, double L, double Le, int n1, int n2, double Ax, double Asy, double Asz, double J, double Iy, double Iz, double E, double G, float p, bool shear) { double Ksy, Ksz; /* shear deformatn coefficients */ int i, j; double[] t = Coordtrans.coordTrans(xyz, L, n1, n2, p); for (i = 0; i < 12; i++) { for (j = 0; j < 12; j++) { k[i, j] = 0.0; } } if (shear) { Ksy = 12.0 * E * Iz / (G * Asy * Le * Le); Ksz = 12.0 * E * Iy / (G * Asz * Le * Le); } else { Ksy = Ksz = 0.0; } k[0, 0] = k[6, 6] = E * Ax / Le; k[1, 1] = k[7, 7] = 12.0 * E * Iz / (Le * Le * Le * (1.0 + Ksy)); k[2, 2] = k[8, 8] = 12.0 * E * Iy / (Le * Le * Le * (1.0 + Ksz)); k[3, 3] = k[9, 9] = G * J / Le; k[4, 4] = k[10, 10] = (4.0 + Ksz) * E * Iy / (Le * (1.0 + Ksz)); k[5, 5] = k[11, 11] = (4.0 + Ksy) * E * Iz / (Le * (1.0 + Ksy)); k[4, 2] = k[2, 4] = -6.0 * E * Iy / (Le * Le * (1.0 + Ksz)); k[5, 1] = k[1, 5] = 6.0 * E * Iz / (Le * Le * (1.0 + Ksy)); k[6, 0] = k[0, 6] = -k[0, 0]; k[11, 7] = k[7, 11] = k[7, 5] = k[5, 7] = -k[5, 1]; k[10, 8] = k[8, 10] = k[8, 4] = k[4, 8] = -k[4, 2]; k[9, 3] = k[3, 9] = -k[3, 3]; k[10, 2] = k[2, 10] = k[4, 2]; k[11, 1] = k[1, 11] = k[5, 1]; k[7, 1] = k[1, 7] = -k[1, 1]; k[8, 2] = k[2, 8] = -k[2, 2]; k[10, 4] = k[4, 10] = (2.0 - Ksz) * E * Iy / (Le * (1.0 + Ksz)); k[11, 5] = k[5, 11] = (2.0 - Ksy) * E * Iz / (Le * (1.0 + Ksy)); k = Coordtrans.Atma(t, k, r[n1], r[n2]); for (i = 0; i < 12; i++) { for (j = i + 1; j < 12; j++) { if (k[i, j] != k[j, i]) { if (Math.Abs(k[i, j] / k[j, i] - 1.0) > 1.0e-6 && (Math.Abs(k[i, j] / k[i, i]) > 1e-6 || Math.Abs(k[j, i] / k[i, i]) > 1e-6 ) ) { Console.WriteLine($"elastic_K: element stiffness matrix not symetric ..."); Console.WriteLine($" ... k[{i}][{j}] = {k[i, j]} "); Console.WriteLine($" ... k[{j}][{i}] = {k[j, i]} "); Console.WriteLine($" ... relative error = {Math.Abs(k[i, j] / k[j, i] - 1.0)} "); Console.WriteLine($" ... element matrix saved in file 'kt'"); } k[i, j] = k[j, i] = 0.5 * (k[i, j] + k[j, i]); } } } }
public Output Solve(Input input) { //Fixed values int ok = 1; double rmsResid = 1.0; double error = 1.0; int axialStrainWarning = 0; int axialSign = 1; int writeMatrix = 0; string title = input.Title; IReadOnlyList <Node> nodes = input.Nodes; IReadOnlyList <FrameElement> frameElements = input.FrameElements; int nN = input.Nodes.Count; List <float> rj = input.Nodes.Select(n => n.Radius).ToList(); List <Vec3Float> xyz = input.Nodes.Select(n => n.Position).ToList(); int DoF = 6 * nN; int nR = input.ReactionInputs.Count; double[] q = new double[DoF]; float[] r = new float[DoF]; for (int i = 0; i < nR; i++) { int j = input.ReactionInputs[i].Number; //This index number is decreased by 1 when importing r[j * 6 + 0] = input.ReactionInputs[i].Position.X; r[j * 6 + 1] = input.ReactionInputs[i].Position.Y; r[j * 6 + 2] = input.ReactionInputs[i].Position.Z; r[j * 6 + 3] = input.ReactionInputs[i].R.X; r[j * 6 + 4] = input.ReactionInputs[i].R.Y; r[j * 6 + 5] = input.ReactionInputs[i].R.Z; } for (int i = 0; i < DoF; i++) { q[i] = (r[i] == (double)1) ? 0 : 1; } int nE = input.FrameElements.Count; List <double> L = input.FrameElements.Select(f => Coordtrans.CalculateSQDistance(input.Nodes[f.NodeIdx1].Position, input.Nodes[f.NodeIdx2].Position)) .ToList(); List <double> Le = new List <double>(); for (int i = 0; i < L.Count; i++) { Le.Add(L[i] - input.Nodes[input.FrameElements[i].NodeIdx1].Radius - input.Nodes[input.FrameElements[i].NodeIdx2].Radius); } List <int> N1 = input.FrameElements.Select(f => f.NodeIdx1).ToList(); List <int> N2 = input.FrameElements.Select(f => f.NodeIdx2).ToList(); List <float> Ax = input.FrameElements.Select(f => f.Ax).ToList(); List <float> Asy = input.FrameElements.Select(f => f.Asy).ToList(); List <float> Asz = input.FrameElements.Select(f => f.Asz).ToList(); List <float> Jx = input.FrameElements.Select(f => f.Jx).ToList(); List <float> Iy = input.FrameElements.Select(f => f.Iy).ToList(); List <float> Iz = input.FrameElements.Select(f => f.Iz).ToList(); List <float> E = input.FrameElements.Select(f => f.E).ToList(); List <float> G = input.FrameElements.Select(f => f.G).ToList(); List <float> p = input.FrameElements.Select(f => f.Roll).ToList(); List <float> d = input.FrameElements.Select(f => f.Density).ToList(); int nL = input.LoadCases.Count; List <float> gX = input.LoadCases.Select(l => l.Gravity.X).ToList(); List <float> gY = input.LoadCases.Select(l => l.Gravity.Y).ToList(); List <float> gZ = input.LoadCases.Select(l => l.Gravity.Z).ToList(); List <int> nF = input.LoadCases.Select(l => l.NodeLoads.Count).ToList(); List <int> nU = input.LoadCases.Select(l => l.UniformLoads.Count).ToList(); List <int> nW = input.LoadCases.Select(l => l.TrapLoads.Count).ToList(); float[,,] U = new float[nL, nE, 4]; for (int i = 0; i < nL; i++) { for (int j = 0; j < nE; j++) { //U[i, j, 0] will store node index, but not all of them will be assigned a value. //For those not assigned, they are the same value for node index 0. //This will cause some trouble later, so have to be initialized with another value. //The problem is caused by converting from 1 based array in the C code to 0 based array in C# here. U[i, j, 0] = -1; } } float[,,] W = new float[nL, nE *10, 13]; for (int i = 0; i < nL; i++) { for (int j = 0; j < nE * 10; j++) { W[i, j, 0] = -1;//Same reason for array U } } double[,,] eqFMech = new double[nL, nE, 12]; double[,] FMech = new double[nL, DoF]; bool shear = input.IncludeShearDeformation; bool geom = input.IncludeGeometricStiffness; float dx = input.XAxisIncrementForInternalForces; double[] F = new double[DoF]; double[] dF = new double[DoF]; double[] D = new double[DoF]; double[] dD = new double[DoF]; double[] R = new double[DoF]; double[] dR = new double[DoF]; double[,] Q = new double[nE, 12]; double[,] K = new double[DoF, DoF]; ////These are not used int[] nT = new int[nL]; int[] nP = new int[nL]; int[] nD = new int[nL]; double[,] FTemp = new double[nL, DoF]; double[,,] eqFTemp = new double[nL, nE, 12]; int iter = 0; double tol = 1.0e-9; float[,,] P = new float[nL, 10 * nE, 5]; double[,] Dp = new double[nL, DoF]; //// IReadOnlyList <LoadCase> loadCases = input.LoadCases; Frame3ddIO.AssembleLoads(nN, nE, nL, DoF, xyz, L, Le, N1, N2, Ax, Asy, Asz, Iy, Iz, E, G, p, d, gX, gY, gZ, shear, nF, nU, nW, FMech, eqFMech, U, W, loadCases); //ReadMassData()--Not implemented //ReadCondensationData()--Not implemented string outputText = Frame3ddIO.InputDataToString(title, nN, nE, nL, nD, nR, nF, nU, nW, nP, nT, xyz, rj, N1, N2, Ax, Asy, Asz, Jx, Iy, Iz, E, G, p, d, gX, gY, gZ, FMech, Dp, r, U, W, P, shear, geom); ////Start anlyz /* begin load case analysis loop */ List <LoadCaseOutput> loadCaseOutputs = new List <LoadCaseOutput>(); for (int lc = 0; lc < nL; lc++) { /* initialize displacements and displ. increment to {0} */ /* initialize reactions and react. increment to {0} */ for (int i = 0; i < DoF; i++) { D[i] = dD[i] = R[i] = dR[i] = 0.0; } /* initialize internal element end forces Q = {0} */ for (int i = 0; i < nE; i++) { for (int j = 0; j < 11; j++) { Q[i, j] = 0.0; } } K = Frame3dd.AssembleK(DoF, nE, xyz, r, L, Le, N1, N2, Ax, Asy, Asz, Jx, Iy, Iz, E, G, p, shear, geom, Q); //if (nT[lc] > 0){ //Aplly temperature loads only --Not implemented //} if (nF[lc] > 0 || nU[lc] > 0 || nW[lc] > 0 || nP[lc] > 0 || nD[lc] > 0 || gX[lc] != 0 || gY[lc] != 0 || gZ[lc] != 0) { for (int i = 0; i < DoF; i++) { if (!Common.IsDoubleZero(r[i])) { dD[i] = Dp[lc, i]; } } } double[] tempLoadMech = Common.GetRow(FMech, lc); var solveSystemResult = Frame3dd.SolveSystem(K, dD, tempLoadMech, dR, DoF, q, r, ok, rmsResid); ok = solveSystemResult.ok; rmsResid = solveSystemResult.rmsResid; for (int i = 0; i < DoF; i++) { FMech[lc, i] = tempLoadMech[i]; } for (int i = 0; i < DoF; i++) { if (!Common.IsDoubleZero(q[i])) { D[i] += dD[i]; } else { D[i] = Dp[lc, i]; dD[i] = 0.0; } } for (int i = 0; i < DoF; i++) { if (!Common.IsDoubleZero(r[i])) { R[i] += dR[i]; } } /* combine {F} = {F_t} + {F_m} */ for (int i = 0; i < DoF; i++) { F[i] = FTemp[lc, i] + FMech[lc, i]; } double[,] tempTArray = Common.GetArray(eqFTemp, lc); double[,] tempMArray = Common.GetArray(eqFMech, lc); Frame3dd.ElementEndForces(Q, nE, xyz, L, Le, N1, N2, Ax, Asy, Asz, Jx, Iy, Iz, E, G, p, tempTArray, tempMArray, D, shear, geom, axialStrainWarning); error = Frame3dd.EquilibriumError(dF, F, K, D, DoF, q, r); //if (geom && verbose) // fprintf(stdout, "\n Non-Linear Elastic Analysis ...\n"); if (geom) { //Not implemented } while (geom && error > tol && iter < 500 && ok >= 0) { //Not implemented } //Not implemented /* strain limit failure ... */ //if (axial_strain_warning > 0 && ExitCode == 0) ExitCode = 182; /* strain limit _and_ buckling failure ... */ //if (axial_strain_warning > 0 && ExitCode == 181) ExitCode = 183; //if (geom) compute_reaction_forces(R, F, K, D, DoF, r); if (writeMatrix != 0)/* write static stiffness matrix */ { //save_ut_dmatrix("Ks", K, DoF, "w");//Not implemented } /* display RMS equilibrium error */ //if (verbose && ok >= 0) // evaluate(error, rms_resid, tol, geom); var staticResults = Frame3ddIO.GetStaticResults(nN, nE, nL, lc, DoF, N1, N2, F, D, R, r, Q, error, ok, axialSign); ////Not implemented //if (filetype == 1) //{ // .CSV format output // write_static_csv(OUT_file, title, // nN, nE, nL, lc, DoF, N1, N2, F, D, R, r, Q, error, ok); //} //if (filetype == 2) //{ // .m matlab format output // write_static_mfile(OUT_file, title, nN, nE, nL, lc, DoF, // N1, N2, F, D, R, r, Q, error, ok); //} float[,] tempU2DArray = Common.GetArray(U, lc); float[,] tempW2DArray = Common.GetArray(W, lc); float[,] tempP2DArray = Common.GetArray(P, lc); List <PeakFrameElementInternalForce> internalForce = Frame3ddIO.GetInternalForces(lc, nL, title, dx, xyz, Q, nN, nE, L, N1, N2, Ax, Asy, Asz, Jx, Iy, Iz, E, G, p, d, gX[lc], gY[lc], gZ[lc], nU[lc], tempU2DArray, nW[lc], tempW2DArray, nP[lc], tempP2DArray, D, shear, error); loadCaseOutputs.Add(new LoadCaseOutput(error, staticResults.nodeDisplacements, staticResults.frameElementEndForces, staticResults.reactionOutputs, internalForce)); //static_mesh () //... } outputText += Frame3ddIO.OutputDataToString(loadCaseOutputs); Output output = new Output(outputText, loadCaseOutputs); return(output); }