public double CalculateFz(ovf2 mRef, ovf2 m) { int Ny = mRef.header.ynodes; double fz = 0; double vol = mRef.header.xstepsize * mRef.header.ystepsize * mRef.header.zstepsize; double mom = vol * MaterialMs; for (int i = 0; i < Ny; i++) { Vector[] row0 = mRef.GetRow(i, 0); Vector[] rowf = m.GetRow(i, 0); Vector[] dm = vecSub(rowf, row0); for (int j = 0; j < dm.Count(); j++) { Vector mf = new Vector(dm[j].x * mom, dm[j].y * mom, dm[j].z * mom); //Vector mf = new Vector(0, 0, dm[j].z * mom); Vector r = m.GetPos(j, i, 0); //double fzi = dipole.Fz(mf, r); double fzi = dipole.Fz_ip(mf, r); //if (fzi > 0) // Console.WriteLine(fzi.ToString()); fz += fzi; } } return(fz); }
private void PlotRow(ovf2 m, Chart chart, int RowNumber) { chart.Series[0].ChartType = SeriesChartType.Line; Vector[] vecM = m.GetRow(RowNumber, 0); chart.Series[0].Points.Clear(); for (int i = 0; i < vecM.Count(); i++) { double dV = 0; if (componentNum == 1) { dV = (vecM[i].x); } else if (componentNum == 2) { dV = (vecM[i].y); } else if (componentNum == 3) { dV = (vecM[i].z); } chart.Series[0].Points.AddXY(i, dV); } }
private void ExportCurrFile(System.IO.StreamWriter sw, ovf2 m0, ovf2 mf, bool inseries, int index) { double factor = 1.0; int Nx = m0.header.xnodes; int Ny = m0.header.ynodes; int startK = 0; int endK = (m0.GetRow(0, 0)).Count(); double vcomp = 0; if (inseries) { if (index > 0 && index < Convert.ToInt32(tb_packn.Text)) { sw.Write("##\n"); } } for (int i = 0; i < Ny; i++) { Vector[] vrow0 = m0.GetRow(i, 0); Vector[] vrowf; if (mf != null) { vrowf = mf.GetRow(i, 0); } else { vrowf = new Vector[vrow0.Count()]; } Vector[] vsub = new Vector[vrow0.Count()]; int colStart = vrow0.Count() / 2; for (int k = startK; k < endK; k++) { if (mf != null) { vsub[k] = vrow0[k] - vrowf[k]; } else { vsub[k] = vrow0[k]; } //which component to plot (x, y or z) string itxt = tb_CompInfo.Text; string[] sitxt = itxt.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); //ovf2 mf = new ovf2(baseName + "f1-0.ovf"); this.componentNum = Convert.ToInt16(sitxt[0]); if (this.componentNum == 1) { vcomp = vsub[k].x; } else if (this.componentNum == 2) { vcomp = vsub[k].y; } else if (this.componentNum == 3) { vcomp = vsub[k].z; } sw.Write((factor * vcomp).ToString()); if (k < endK - 1) { sw.Write(" "); } else { sw.Write("\n"); } } } sw.Close(); }
public double CalculateFzConditional(ovf2 mRef, ovf2 m, CalcCondition ccond, MagnetizationByPosition MsAtPos, List <int> plotChoice, string cond) { //int Ny = mRef.header.ynodes; int Ny = m.header.ynodes; double fz = 0; //double vol = mRef.header.xstepsize * mRef.header.ystepsize * mRef.header.zstepsize; double vol = m.header.xstepsize * m.header.ystepsize * m.header.zstepsize; for (int i = 0; i < Ny; i++) { Vector[] dm = m.GetRow(i, 0); if (mRef != null) { Vector[] row0 = mRef.GetRow(i, 0); dm = vecSub(dm, row0); } for (int j = 0; j < dm.Count(); j++) { //Vector mf = new Vector(dm[j].x * mom, dm[j].y * mom, dm[j].z * mom); Vector r = m.GetPos(j, i, 0); //Vector mf = new Vector(0, 0, dm[j].z * MsAtPos(r) * vol); Vector mf = new Vector(dm[j].x * MsAtPos(r) * vol, dm[j].y * MsAtPos(r) * vol, dm[j].z * MsAtPos(r) * vol); double fzi = 0; if (plotChoice[0] == 0) { if (plotChoice[1] == 1) { fzi = dipole.Fz(mf, r); } else if (plotChoice[1] == 2) { fzi = dipole.Fz_ip(mf, r); } else if (plotChoice[1] == 3) { fzi = dipole.Fz_ipy(mf, r); } } if (plotChoice[0] == 1) { if (plotChoice[1] == 1) { fzi = dm[j].z; } else if (plotChoice[1] == 2) { fzi = dm[j].x; } else if (plotChoice[1] == 3) { fzi = dm[j].y; } } //double fzi = dipole.Fz(mf, r); //double fzi = dipole.Fz_ip(mf, r); if (ccond(r, cond)) { fz += fzi; } } } return(fz); }