code
stringlengths
1
2.01M
repo_name
stringlengths
3
62
path
stringlengths
1
267
language
stringclasses
231 values
license
stringclasses
13 values
size
int64
1
2.01M
using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; using DevExpress.XtraEditors; using BUS; using DTO; namespace Control { public partial class ctrlLapPhieuThuTienPhat : DevExpress.XtraEditors.XtraUserControl { public ctrlLapPhieuThuTienPhat() { InitializeComponent(); //setting date ngày thu this.dateNgayThu.Properties.DisplayFormat.FormatString = "dd/MM/yyyy"; this.dateNgayThu.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime; this.dateNgayThu.Properties.EditFormat.FormatString = "dd/MM/yyyy"; this.dateNgayThu.Properties.EditFormat.FormatType = DevExpress.Utils.FormatType.DateTime; this.dateNgayThu.Properties.Mask.EditMask = "dd/MM/yyyy"; //chỉ cho nhập số trên textbox thu tiền this.txtTienThu.Properties.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.Numeric; } private void ctrlLapPhieuThuTienPhat_Load(object sender, EventArgs e) { //load ds độc giả lookUpMaTheDocGia.Properties.DataSource = DocGiaBUS.DocDanhSach(); lookUpMaTheDocGia.Properties.DisplayMember = "MaDocGia"; lookUpMaTheDocGia.Properties.ValueMember = "MaDocGia"; //ngày thu là ngày hiện hành dateNgayThu.DateTime = DateTime.Today; //hiển thị nhân viên txtTenNhanVien.Text = session.tenNhanVien; } private void lookUpMaThe_EditValueChanged(object sender, EventArgs e) { try { //Lấy thông tin từ lookup DocGiaDTO dto = (DocGiaDTO)lookUpMaTheDocGia.GetSelectedDataRow(); //gán vào text họ tên độc giả txtHoTenDocGia.Text = dto.TenDocGia; //tiền độc giả đang nợ txtTienDangNo.Text = dto.TienNo.ToString(); //set lại tiền thu txtTienThu.Text = "0"; //set tiền còn lại txtConLai.Text = (float.Parse(txtTienDangNo.Text) - float.Parse(txtTienThu.Text)).ToString(); } catch { } } private void LamMoi() { //ngày thu dateNgayThu.DateTime = DateTime.Today; //refresh lookup lookUpMaThe_EditValueChanged(null, null); } private void txtTienThu_EditValueChanged(object sender, EventArgs e) { //set tiền còn lại txtConLai.Text = (float.Parse(txtTienDangNo.Text) - float.Parse(txtTienThu.Text)).ToString(); } private void btnLapPhieu_Click(object sender, EventArgs e) { if (KiemTra() == false) return; try { //Lấy thông tin từ lookup DocGiaDTO dtoDocGia = (DocGiaDTO)lookUpMaTheDocGia.GetSelectedDataRow(); //cập nhật lại tiền nợ mới của độc giả dtoDocGia.TienNo = float.Parse(txtConLai.Text); //đưa xuống csdl DocGiaBUS.CapNhatTienNo(dtoDocGia); //tạo mới phiếu thu tiền phạt PhieuThuTienPhatDTO dtoPhieuThu = new PhieuThuTienPhatDTO { MaDocGia = dtoDocGia.MaDocGia, MaNhanVien = session.maNhanVien, MaPhieuThu = 0, NgayThu = dateNgayThu.DateTime, TienNo = float.Parse(txtTienDangNo.Text), SoTienThu = float.Parse(txtTienThu.Text), ConLai = dtoDocGia.TienNo }; //đưa xuống csdl PhieuThuTienPhatBUS.Them(dtoPhieuThu); //refresh LamMoi(); //thành công MessageBox.Show("Thêm thành công!!!"); } catch (Exception ex) { //báo lỗi MessageBox.Show(ex.Message, "Lỗi!!!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private bool KiemTra() { //MessageBox.Show("", "Lỗi!!!", MessageBoxButtons.OK, MessageBoxIcon.Error); //return false; if (lookUpMaTheDocGia.ItemIndex == -1) { MessageBox.Show("Chưa chọn thẻ độc giả", "Lỗi!!!", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } if (float.Parse(txtTienThu.Text) == 0) { MessageBox.Show("Số tiền thu không để trống", "Lỗi!!!", MessageBoxButtons.OK, MessageBoxIcon.Error); txtTienThu.Focus(); return false; } if (float.Parse(txtTienDangNo.Text) < float.Parse(txtTienThu.Text)) { MessageBox.Show("Số tiền thu không được vượt quá tiền đang nợ", "Lỗi!!!", MessageBoxButtons.OK, MessageBoxIcon.Error); txtTienThu.Focus(); return false; } return true; } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/Control/ctrlLapPhieuThuTienPhat.cs
C#
asf20
5,565
using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; using DevExpress.XtraEditors; using CrystalDecisions.CrystalReports.Engine; using CrystalDecisions.Shared; namespace Control { public partial class ctrlSachTraTre : DevExpress.XtraEditors.XtraUserControl { public ctrlSachTraTre() { InitializeComponent(); //format date this.dateThoiGian.Properties.DisplayFormat.FormatString = "dd/MM/yyyy"; this.dateThoiGian.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime; this.dateThoiGian.Properties.EditFormat.FormatString = "dd/MM/yyyy"; this.dateThoiGian.Properties.EditFormat.FormatType = DevExpress.Utils.FormatType.DateTime; this.dateThoiGian.Properties.Mask.EditMask = "dd/MM/yyyy"; } private void ctrlSachTraTre_Load(object sender, EventArgs e) { dateThoiGian.DateTime = DateTime.Today; } private void btnXemBaoCao_Click(object sender, EventArgs e) { rptSachTraTre rpt = new rptSachTraTre(); rpt.SetParameterValue("Ngay", dateThoiGian.DateTime); crystalReportViewer1.ReportSource = rpt; } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/Control/ctrlSachTraTre.cs
C#
asf20
1,395
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DTO; using DAO; namespace BUS { public class LyDoThanhLyBUS { public static List<LyDoThanhLyDTO> DocDanhSach() { return LyDoThanhLyDAO.DocDanhSach(); } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/BUS/LyDoThanhLyBUS.cs
C#
asf20
319
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DAO; using DTO; namespace BUS { public class LoaiDocGiaBUS { public static List<DTO.LoaiDocGiaDTO> DocDanhSach() { return LoaiDocGiaDAO.DocDanhSach(); } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/BUS/LoaiDocGiaBUS.cs
C#
asf20
320
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace BUS { public class ChiTietPhieuTraBUS { } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/BUS/ChiTietPhieuTraBUS.cs
C#
asf20
167
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DAO; using DTO; namespace BUS { public class PhieuGhiNhanMatSachBUS { public static bool Them(DTO.PhieuGhiNhanMatSachDTO dtoPhieu) { PhieuGhiNhanMatSachDAO.Them(dtoPhieu); return true; } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/BUS/PhieuGhiNhanMatSachBUS.cs
C#
asf20
367
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DAO; using DTO; namespace BUS { public class PhieuThuTienPhatBUS { public static bool Them(PhieuThuTienPhatDTO dtoPhieuThu) { PhieuThuTienPhatDAO.Them(dtoPhieuThu); return true; } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/BUS/PhieuThuTienPhatBUS.cs
C#
asf20
360
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DAO; using DTO; namespace BUS { public class PhieuThanhLyBUS { public static bool Them(DTO.PhieuThanhLyDTO dtoPhieu, List<DTO.ChiTietPhieuThanhLyDTO> listSachThanhLy) { PhieuThanhLyDAO.Them(dtoPhieu, listSachThanhLy); return true; } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/BUS/PhieuThanhLyBUS.cs
C#
asf20
413
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DAO; using DTO; namespace BUS { public class TheLoaiSachBUS { public static List<TheLoaiSachDTO> DocDanhSach() { return TheLoaiSachDAO.DocDanhSach(); } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/BUS/TheLoaiSachBUS.cs
C#
asf20
319
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace BUS { public class ChiTietPhieuMuonBUS { } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/BUS/ChiTietPhieuMuonBUS.cs
C#
asf20
168
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DAO; using DTO; namespace BUS { public class BangCapBUS { public static List<BangCapDTO> DocDanhSach() { return BangCapDAO.DocDanhSach(); } public static bool Them(BangCapDTO dto,List<BangCapDTO> list) { //tạo chuỗi thông báo lỗi string thongBaoLoi = ""; //kiểm tra lỗi if (KiemTra(dto,list,ref thongBaoLoi) == false) //đẩy lỗi lên tầng giao diện throw new Exception(thongBaoLoi); //đẩy xuống dao BangCapDAO.Them(dto); return true; } private static bool KiemTra(BangCapDTO dto, List<BangCapDTO> list,ref string thongBaoLoi) { //kiểm tra xem tên bằng cấp đã có hay chưa foreach(BangCapDTO bangcap in list) { if (bangcap.TenBangCap == dto.TenBangCap) { thongBaoLoi = "Tên bằng cấp đã tồn tại"; return false; } } return true; } public static bool Xoa(BangCapDTO dto) { BangCapDAO.Xoa(dto); return true; } public static bool CapNhat(BangCapDTO dto, List<BangCapDTO> list) { //tạo chuỗi thông báo lỗi string thongBaoLoi = ""; //kiểm tra lỗi if (KiemTra(dto, list, ref thongBaoLoi) == false) //đẩy lỗi lên tầng giao diện throw new Exception(thongBaoLoi); //đẩy xuống dao BangCapDAO.CapNhat(dto); return true; } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/BUS/BangCapBUS.cs
C#
asf20
1,908
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DAO; using DTO; namespace BUS { public class PhieuTraSachBUS { public static List<ChiTietPhieuTraDTO> SachDangMuon(int maDocGia) { return PhieuTraSachDAO.SachDangMuon(maDocGia); } public static bool Them(PhieuTraSachDTO dtoPhieuTra, List<ChiTietPhieuTraDTO> listSachTra) { PhieuTraSachDAO.Them(dtoPhieuTra, listSachTra); return true; } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/BUS/PhieuTraSachBUS.cs
C#
asf20
556
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DAO; using DTO; namespace BUS { public class ChucVuBUS { public static List<ChucVuDTO> DocDanhSach() { return ChucVuDAO.DocDanhSach(); } public static bool Them(ChucVuDTO dto, List<ChucVuDTO> list) { //tạo chuỗi thông báo lỗi string thongBaoLoi = ""; //kiểm tra lỗi if (KiemTra(dto, list, ref thongBaoLoi) == false) //đẩy lỗi lên tầng giao diện throw new Exception(thongBaoLoi); //đẩy xuống dao ChucVuDAO.Them(dto); return true; } private static bool KiemTra(ChucVuDTO dto, List<ChucVuDTO> list, ref string thongBaoLoi) { //kiểm tra xem tên bằng cấp đã có hay chưa foreach (ChucVuDTO ChucVu in list) { if (ChucVu.TenChucVu == dto.TenChucVu) { thongBaoLoi = "Tên bằng cấp đã tồn tại"; return false; } } return true; } public static bool Xoa(ChucVuDTO dto) { ChucVuDAO.Xoa(dto); return true; } public static bool CapNhat(ChucVuDTO dto, List<ChucVuDTO> list) { //tạo chuỗi thông báo lỗi string thongBaoLoi = ""; //kiểm tra lỗi if (KiemTra(dto, list, ref thongBaoLoi) == false) //đẩy lỗi lên tầng giao diện throw new Exception(thongBaoLoi); //đẩy xuống dao ChucVuDAO.CapNhat(dto); return true; } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/BUS/ChucVuBUS.cs
C#
asf20
1,895
using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("BUS")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("SUPEZCHICKEN")] [assembly: AssemblyProduct("BUS")] [assembly: AssemblyCopyright("Copyright © SUPEZCHICKEN 2011")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("4cb2147b-6b10-450f-96f5-3b3ab9f140bd")] // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/BUS/Properties/AssemblyInfo.cs
C#
asf20
1,442
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DAO; using DTO; namespace BUS { public class PhieuMuonSachBUS { public static List<SachDTO> SachDangMuon(int maDocGia) { return PhieuMuonSachDAO.SachDangMuon(maDocGia); } public static List<SachDTO> SachMuonQuaHan(int maDocGia) { return PhieuMuonSachDAO.SachMuonQuaHan(maDocGia); } public static bool Them(PhieuMuonSachDTO dto, List<SachDTO> listSachMuon) { PhieuMuonSachDAO.Them(dto, listSachMuon); return true; } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/BUS/PhieuMuonSachBUS.cs
C#
asf20
679
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DAO; using DTO; namespace BUS { public class TinhTrangBUS { public static List<TinhTrangDTO> DocDanhSach() { return TinhTrangDAO.DocDanhSach(); } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/BUS/TinhTrangBUS.cs
C#
asf20
313
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DAO; using DTO; namespace BUS { public class SachBUS { public static bool Them(DTO.SachDTO dto) { //tạo chuỗi thông báo lỗi string thongBaoLoi = ""; //kiểm tra hợp lệ if (KiemTra(dto, ref thongBaoLoi) == false) { throw new Exception(thongBaoLoi); } //thực hiện thêm SachDAO.Them(dto); return true; } private static bool KiemTra(SachDTO dto, ref string thongBaoLoi) { //đọc tham số int khoangCachNamXuatBan = (int)ThamSoBUS.KhoangCachNamXuatBan().GiaTri; //kiểm tra khoảng cách năm xuất bản if (DateTime.Today.Year < dto.NamXuatBan) { thongBaoLoi = "Chưa tới năm xuất bản sách này"; return false; } //kiểm tra khoảng cách năm xuất bản if ((DateTime.Today.Year - dto.NamXuatBan) > khoangCachNamXuatBan) { thongBaoLoi = "Chỉ nhận sách xuất bản trong " + khoangCachNamXuatBan + " năm"; return false; } return true; } public static List<SachDTO> DocDanhSach(int trangThai) { return SachDAO.DocDanhSach(trangThai); } public static List<SachDTO> TraCuu(SachDTO s) { return SachDAO.TraCuu(s); } public static bool GhiNhanMatSach(SachDTO dtoSach) { SachDAO.GhiNhanMatSach(dtoSach); return true; } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/BUS/SachBUS.cs
C#
asf20
1,831
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DAO; using DTO; namespace BUS { public class NhanVienBUS { public static bool DangNhap(NhanVienDTO dto) { //nếu không tìm thấy nhân viên trong csdl thì thảy ex lên giao diện if (NhanVienDAO.DangNhap(dto) == false) throw new Exception("Sai tên hoặc mật khẩu"); return true; } public static bool KiemTraTaiKhoan(string p) { //true : đã tồn tại //false : chưa tồn tại if (NhanVienDAO.KiemTraTaiKhoan(p) == false) return false; return true; } public static bool Them(NhanVienDTO dto) { //tạo chuỗi thông báo lỗi string thongBaoLoi = ""; //kiểm tra hợp lệ if (KiemTra(dto, ref thongBaoLoi) == false) { throw new Exception(thongBaoLoi); } //thực hiện thêm xuống data NhanVienDAO.Them(dto); return true; } private static bool KiemTra(NhanVienDTO dto, ref string thongBaoLoi) { return true; } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/BUS/NhanVienBUS.cs
C#
asf20
1,357
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace BUS { public class ChiTietPhieuThanhLyBUS { } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/BUS/ChiTietPhieuThanhLyBUS.cs
C#
asf20
171
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DAO; using DTO; using System.Text.RegularExpressions; namespace BUS { public class DocGiaBUS { public static bool Them(DocGiaDTO dto) { //tạo chuỗi thông báo lỗi string thongBaoLoi = ""; //kiểm tra hợp lệ if (KiemTra(dto, ref thongBaoLoi) == false) { throw new Exception(thongBaoLoi); } //thêm độc giả DocGiaDAO.Them(dto); return true; } private static bool KiemTra(DocGiaDTO dto, ref string thongBaoLoi) { //đọc tuổi tối đa, tuổi tối thiểu int tuoiToiDa = (int)ThamSoBUS.TuoiToiDa().GiaTri; int tuoiToiThieu = (int)ThamSoBUS.TuoiToiThieu().GiaTri; //tính số tuổi int soTuoi = dto.NgaySinh.Year; soTuoi = DateTime.Now.Year - soTuoi; //kiểm tra hợp lệ if (soTuoi > tuoiToiDa || soTuoi < tuoiToiThieu) { thongBaoLoi = "Số tuổi không phù hợp quy định"; return false; } //kiểm tra email if (IsValidEmail(dto.Email) == false) { thongBaoLoi = "Email không hợp lệ"; return false; } return true; } /// <summary> /// http://www.dreamincode.net/code/snippet1374.htm /// method for determining is the user provided a valid email address /// We use regular expressions in this check, as it is a more thorough /// way of checking the address provided /// </summary> /// <param name="email">email address to validate</param> /// <returns>true is valid, false if not valid</returns> private static bool IsValidEmail(string email) { //regular expression pattern for valid email //addresses, allows for the following domains: //com,edu,info,gov,int,mil,net,org,biz,name,museum,coop,aero,pro,tv string pattern = @"^[-a-zA-Z0-9][-.a-zA-Z0-9]*@[-.a-zA-Z0-9]+(\.[-.a-zA-Z0-9]+)*\. (com|edu|info|gov|int|mil|net|org|biz|name|museum|coop|aero|pro|tv|[a-zA-Z]{2})$"; //Regular expression object Regex check = new Regex(pattern, RegexOptions.IgnorePatternWhitespace); //boolean variable to return to calling method bool valid = false; //make sure an email address was provided if (string.IsNullOrEmpty(email)) { valid = false; } else { //use IsMatch to validate the address valid = check.IsMatch(email); } //return the value to the calling method return valid; } public static List<DocGiaDTO> DocDanhSach() { return DocGiaDAO.DocDanhSach(); } public static bool CapNhatTienNo(DocGiaDTO dto) { DocGiaDAO.CapNhatTienNo(dto); return true; } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/BUS/DocGiaBUS.cs
C#
asf20
3,346
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DAO; using DTO; namespace BUS { public class BoPhanBUS { public static List<BoPhanDTO> DocDanhSach() { return BoPhanDAO.DocDanhSach(); } public static bool Them(BoPhanDTO dto, List<BoPhanDTO> list) { //tạo chuỗi thông báo lỗi string thongBaoLoi = ""; //kiểm tra lỗi if (KiemTra(dto, list, ref thongBaoLoi) == false) //đẩy lỗi lên tầng giao diện throw new Exception(thongBaoLoi); //đẩy xuống dao BoPhanDAO.Them(dto); return true; } private static bool KiemTra(BoPhanDTO dto, List<BoPhanDTO> list, ref string thongBaoLoi) { //kiểm tra xem tên bằng cấp đã có hay chưa foreach (BoPhanDTO BoPhan in list) { if (BoPhan.TenBoPhan == dto.TenBoPhan) { thongBaoLoi = "Tên bằng cấp đã tồn tại"; return false; } } return true; } public static bool Xoa(BoPhanDTO dto) { BoPhanDAO.Xoa(dto); return true; } public static bool CapNhat(BoPhanDTO dto, List<BoPhanDTO> list) { //tạo chuỗi thông báo lỗi string thongBaoLoi = ""; //kiểm tra lỗi if (KiemTra(dto, list, ref thongBaoLoi) == false) //đẩy lỗi lên tầng giao diện throw new Exception(thongBaoLoi); //đẩy xuống dao BoPhanDAO.CapNhat(dto); return true; } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/BUS/BoPhanBUS.cs
C#
asf20
1,895
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DAO; using DTO; namespace BUS { public class ThamSoBUS { //phần đọc tham số public static ThamSoDTO TuoiToiDa() { return ThamSoDAO.DocThamSo("TuoiToiDa"); } public static ThamSoDTO TuoiToiThieu() { return ThamSoDAO.DocThamSo("TuoiToiThieu"); } public static ThamSoDTO HanSuDung() { return ThamSoDAO.DocThamSo("HanSuDung"); } public static ThamSoDTO KhoangCachNamXuatBan() { return ThamSoDAO.DocThamSo("KhoangCachNamXuatBan"); } public static ThamSoDTO SoSachMuonToiDa() { return ThamSoDAO.DocThamSo("SoSachMuonToiDa"); } public static ThamSoDTO ThoiGianMuonToiDa() { return ThamSoDAO.DocThamSo("ThoiGianMuonToiDa"); } public static ThamSoDTO TienPhatTraTre() { return ThamSoDAO.DocThamSo("TienPhatTraTre"); } public static ThamSoDTO DoDaiMatKhauToiThieu() { return ThamSoDAO.DocThamSo("DoDaiMatKhauToiThieu"); } public static ThamSoDTO DoDaiMatKhauToiDa() { return ThamSoDAO.DocThamSo("DoDaiMatKhauToiDa"); } //phần cập nhật public static bool CapNhat_TuoiToiDa(float giaTri) { ThamSoDAO.CapNhap("TuoiToiDa",giaTri); return true; } public static bool CapNhat_TuoiToiThieu(float giaTri) { ThamSoDAO.CapNhap("TuoiToiThieu", giaTri); return true; } public static bool CapNhat_HanSuDung(float giaTri) { ThamSoDAO.CapNhap("HanSuDung", giaTri); return true; } public static bool CapNhat_KhoangCachNamXuatBan(float giaTri) { ThamSoDAO.CapNhap("KhoangCachNamXuatBan", giaTri); return true; } public static bool CapNhat_SoSachMuonToiDa(float giaTri) { ThamSoDAO.CapNhap("SoSachMuonToiDa", giaTri); return true; } public static bool CapNhat_ThoiGianMuonToiDa(float giaTri) { ThamSoDAO.CapNhap("ThoiGianMuonToiDa", giaTri); return true; } public static bool CapNhat_TienPhatTraTre(float giaTri) { ThamSoDAO.CapNhap("TienPhatTraTre", giaTri); return true; } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/BUS/ThamSoBUS.cs
C#
asf20
2,679
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using DevExpress.XtraEditors; using DTO; using BUS; namespace QuanLyThuVien { public partial class frmDangNhap : DevExpress.XtraEditors.XtraForm { public frmDangNhap() { InitializeComponent(); //gán textbox tên tài khoản = khach txtTenTaiKhoan.Text = "..."; } private void frmDangNhap_Load(object sender, EventArgs e) { } private void btnThoat_Click(object sender, EventArgs e) { Close(); } private void btnDangNhap_Click(object sender, EventArgs e) { //kiểm tra các textbox if (KiemTra() == false) return; try { //lấy thông tin từ textbox NhanVienDTO dto = new NhanVienDTO { TenTaiKhoan = txtTenTaiKhoan.Text.Trim(), MatKhau = txtMatKhau.Text.Trim() }; //đưa xuống kiểm tra NhanVienBUS.DangNhap(dto); //gán lại session bằng thông tin nhân viên vừa đăng nhập session.tenTaiKhoan = dto.TenTaiKhoan; session.matKhau = dto.MatKhau; session.maNhanVien = dto.MaNhanVien; session.tenNhanVien = dto.TenNhanVien; session.maBoPhan = dto.MaBoPhan; //gán lại dialogresult this.DialogResult = DialogResult.OK; } catch (Exception ex) { //không tồn tại nhân viên sẽ hiển thị ex MessageBox.Show(ex.Message, "Lỗi!!!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private bool KiemTra() { //kiểm tra rỗng các textbox if (txtTenTaiKhoan.Text.Trim() == "" || txtMatKhau.Text.Trim() == "") { MessageBox.Show("Tên tài khoản và Mật khẩu không được để trống", "Lỗi!!!", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } return true; } //sau khi load form sẽ focus textbox luôn tên tài khoảng private void frmDangNhap_Shown(object sender, EventArgs e) { txtTenTaiKhoan.Focus(); //để tránh mất thời gian đăng nhập mỗi lần test //txtTenTaiKhoan.Text = "admin"; //txtMatKhau.Text = "1"; //btnDangNhap_Click(null, null); } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/QuanLyThuVien/frmDangNhap.cs
C#
asf20
2,842
using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("QuanLyThuVien")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("SUPEZCHICKEN")] [assembly: AssemblyProduct("QuanLyThuVien")] [assembly: AssemblyCopyright("Copyright © SUPEZCHICKEN 2011")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("2f233fa4-23c5-4347-8fff-dd3482ab04d9")] // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/QuanLyThuVien/Properties/AssemblyInfo.cs
C#
asf20
1,462
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using DevExpress.XtraBars; using Control; using DTO; namespace QuanLyThuVien { public partial class GUI : DevExpress.XtraBars.Ribbon.RibbonForm { public GUI() { InitializeComponent(); //Config login session.tenTaiKhoan = ""; session.matKhau = ""; session.maNhanVien = 0; session.tenNhanVien = ""; session.maBoPhan = 0; session.trangThai = false; //hide ribbon Page ribbonPage_HideAll(); } private void GUI_Load(object sender, EventArgs e) { //chọn page đầu tiên mặc định là page 0 ribbon.SelectedPage = ribbon.Pages[0]; ribbon_SelectedPageChanged(null, null); } //hide tất cả ribbonPage private void ribbonPage_HideAll() { rbpBaoCaoThongKe.Visible = false; rbpQuanLy.Visible = false; rbpThuKho.Visible = false; rbpThuQuy.Visible = false; rbpThuThu.Visible = false; } //Show ribbon private void ribbonPage_ShowAll() { rbpBaoCaoThongKe.Visible = true; rbpQuanLy.Visible = true; rbpThuKho.Visible = true; rbpThuQuy.Visible = true; rbpThuThu.Visible = true; } private void ribbonPage_Show_Quanly() { rbpBaoCaoThongKe.Visible = true; rbpQuanLy.Visible = true; } private void ribbonPage_Show_ThuKho() { rbpBaoCaoThongKe.Visible = true; rbpThuKho.Visible = true; } private void ribbonPage_Show_ThuQuy() { rbpBaoCaoThongKe.Visible = true; rbpThuQuy.Visible = true; } private void ribbonPage_Show_ThuThu() { rbpBaoCaoThongKe.Visible = true; rbpThuThu.Visible = true; } //Tùy theo từng loại nhân viên sẽ hiển thị nhưng phần được phép private void ribbonPage_Show() { switch (session.maBoPhan) { case 1: { ribbonPage_Show_ThuThu(); break; } case 2: { ribbonPage_Show_ThuKho(); break; } case 3: { ribbonPage_Show_ThuQuy(); break; } case 4: { ribbonPage_Show_Quanly(); break; } default: break; } } private void btnDangNhap_ItemClick(object sender, ItemClickEventArgs e) { //nếu chưa đăng nhập if (session.trangThai == false) { frmDangNhap frm = new frmDangNhap(); if (frm.ShowDialog() == DialogResult.OK) { session.trangThai = true; ribbonPage_Show(); btnDangNhap.Caption = "Đăng xuất"; } } //ngược lại else { //ghi nhận lại là chưa đăng nhập session.trangThai = false; //ẩn hết các ribbonPage ribbonPage_HideAll(); //đóng hết các tabpage đã mở while (tabControlChinh.TabPages.Count > 1) { tabControlChinh.TabPages.RemoveAt(tabControlChinh.TabPages.Count - 1); } btnDangNhap.Caption = "Đăng nhập"; } } //sự kiện nhấn vào button thoát trên menu private void btnThoat_ItemClick(object sender, ItemClickEventArgs e) { this.Close(); } //Khi form chính vừa hiển thị lên thì form đăng nhập hiển thị private void GUI_Shown(object sender, EventArgs e) { btnDangNhap_ItemClick(null, null); } //Đóng một tab trong tabControlChinh private void tabControlChinh_CloseButtonClick(object sender, EventArgs e) { DevExpress.XtraTab.XtraTabControl tabControl = (DevExpress.XtraTab.XtraTabControl) sender; //Lấy ra vị trí tab vừa nhấn x int vitri = tabControl.SelectedTabPageIndex; //Nếu là = 0 thì return để né bug if (vitri == 0) return; //Chọn tab là tab liền trước tabControl.SelectedTabPageIndex = vitri - 1; //Loại bỏ khỏi tab control tabControl.TabPages.RemoveAt(vitri); } /* Khi chọn một ribbon page thì bên dưới * tab control sẽ tạo một tab page tương ứng */ private void ribbon_SelectedPageChanged(object sender, EventArgs e) { //Lấy ra ribbon page DevExpress.XtraBars.Ribbon.RibbonPage rbp = ribbon.SelectedPage; //Tạo tab page tương ứng với rbp Tao_tabPage(rbp.Text, rbp.Name, tabControlChinh,rbp.ImageIndex); } //Tạo tab page cho control private DevExpress.XtraTab.XtraTabPage Tao_tabPage(string text, string name, DevExpress.XtraTab.XtraTabControl tabControl,int imageindex) { //Kiểm tra xem tab page có tồn tại hay không int vitri = KiemTraTonTai_tabPage(name, tabControl); if (vitri >= 0) { //tabpage đã tồn tại nên chọn luôn tabControl.SelectedTabPageIndex = vitri; return tabControl.SelectedTabPage; } //Tạo tabPage mới vào tabControl DevExpress.XtraTab.XtraTabPage tabPage_new = new DevExpress.XtraTab.XtraTabPage { Text = text, Name = "tabPage" + name, Tag = name }; tabControl.TabPages.Add(tabPage_new); tabControl.SelectedTabPage = tabPage_new; //thêm index hình để hiển thị tabPage_new.ImageIndex = imageindex; //phần return này phục vụ cho mục đích tái sử dụng hàm khi tạo tab con return tabPage_new; } /* Kiểm tra sự tồn tại của một tabpage trong tab control * nếu trả về vị trí >= 0 là có tồn tại * -1 là không tồn tại */ private int KiemTraTonTai_tabPage(string tentabPage, DevExpress.XtraTab.XtraTabControl tabControl) { for (int i = 0; i < tabControl.TabPages.Count; i++) if (tentabPage == (string)tabControl.TabPages[i].Tag) return i; return -1; } /* Chọn tab page trong tab control chính * thì trên ribbon sẽ chọn ribbon page tương ứng */ private void tabControlChinh_SelectedPageChanged(object sender, DevExpress.XtraTab.TabPageChangedEventArgs e) { for (int i = 0; i < ribbon.Pages.Count; i++) if ((string)e.Page.Tag == ribbon.Pages[i].Name) { ribbon.SelectedPage = ribbon.Pages[i]; return; } } //Tạo tab control con bên trong tabpage của tab control chính private DevExpress.XtraTab.XtraTabControl Tao_tabControl() { DevExpress.XtraTab.XtraTabControl tabControl = null; try { //Kiểm tra xem có tạo tab control chưa tabControl = (DevExpress.XtraTab.XtraTabControl)tabControlChinh.SelectedTabPage.Controls[0]; } catch { //Tạo mới tab control bên trong tab page DevExpress.XtraBars.Ribbon.RibbonPage rbp = ribbon.SelectedPage; tabControl = new DevExpress.XtraTab.XtraTabControl { Name = "tabctrl" + rbp.Name, Tag = rbp.Name }; tabControl.ClosePageButtonShowMode = DevExpress.XtraTab.ClosePageButtonShowMode.InActiveTabPageHeader; tabControl.Dock = DockStyle.Fill; tabControl.HeaderLocation = DevExpress.XtraTab.TabHeaderLocation.Top; //Thêm sự kiện closebuttonclick cho tab control tabControl.CloseButtonClick += new EventHandler(tabControl_CloseButtonClick); //thêm vào tab page tabControlChinh.SelectedTabPage.Controls.Add(tabControl); //embed thêm thư viện hình tabControl.Images = hinh1616; } return tabControl; } //Nhấn vào nút đóng x trong một tab control private void tabControl_CloseButtonClick(object sender, EventArgs e) { DevExpress.XtraTab.XtraTabControl tabControl = (DevExpress.XtraTab.XtraTabControl) sender; //Lấy ra vị trí tab vừa nhấn x int vitri = tabControl.SelectedTabPageIndex; ////Nếu là = 0 thì return để né bug //if (vitri == 0) return; ////Chọn tab là tab liền trước //tabControl.SelectedTabPageIndex = vitri - 1; ////Loại bỏ khỏi tab control //tabControl.TabPages.RemoveAt(vitri); tabControl.TabPages.RemoveAt(vitri); //Loại bỏ tabcontrol nếu bên trong không chứa tab page nào nữa if (tabControl.TabPages.Count == 0) { DevExpress.XtraTab.XtraTabPage parent = (DevExpress.XtraTab.XtraTabPage)tabControl.Parent; parent.Controls.RemoveAt(0); return; } tabControl.SelectedTabPageIndex = vitri - 1; } //Đưa user control vào bên trong tab page private void Tao_control(DevExpress.XtraTab.XtraTabPage tabPage, UserControl UsrControl) { UsrControl.Dock = DockStyle.Fill; //add vào tabpage tabPage.Controls.Add(UsrControl); } //Gom tất cả các hàm xử lý chung của sự kiện click vào barbutton private void btnXuLyClick(DevExpress.XtraBars.BarButtonItem btn_clicked, UserControl UsrControl) { //tạo tab control DevExpress.XtraTab.XtraTabControl tabControl = Tao_tabControl(); //tạo tab page DevExpress.XtraTab.XtraTabPage tabPage = Tao_tabPage(btn_clicked.Caption, btn_clicked.Name, tabControl, btn_clicked.LargeImageIndex); //đưa user control vào tab page Tao_control(tabPage, UsrControl); } private void btnTraCuu_ItemClick(object sender, ItemClickEventArgs e) { btnXuLyClick((DevExpress.XtraBars.BarButtonItem)e.Item, new ctrlTraCuu()); } private void btnLapTheDocGia_ItemClick(object sender, ItemClickEventArgs e) { btnXuLyClick((DevExpress.XtraBars.BarButtonItem)e.Item, new ctrlLapTheDocGia()); } private void btnQuanLyDocGia_ItemClick(object sender, ItemClickEventArgs e) { btnXuLyClick((DevExpress.XtraBars.BarButtonItem)e.Item, new ctrlQuanLyDocGia()); } private void btnChoMuonSach_ItemClick(object sender, ItemClickEventArgs e) { btnXuLyClick((DevExpress.XtraBars.BarButtonItem)e.Item, new ctrlChoMuonSach()); } private void btnNhanTraSach_ItemClick(object sender, ItemClickEventArgs e) { btnXuLyClick((DevExpress.XtraBars.BarButtonItem)e.Item, new ctrlNhanTraSach()); } private void btnGhiNhanMatSach_ItemClick(object sender, ItemClickEventArgs e) { btnXuLyClick((DevExpress.XtraBars.BarButtonItem)e.Item, new ctrlGhiNhanMatSach()); } private void btnThayDoiQuyDinh_ItemClick(object sender, ItemClickEventArgs e) { btnXuLyClick((DevExpress.XtraBars.BarButtonItem)e.Item, new ctrlThayDoiQuyDinh()); } private void btnLoaiDocGia_ItemClick(object sender, ItemClickEventArgs e) { btnXuLyClick((DevExpress.XtraBars.BarButtonItem)e.Item, new ctrlLoaiDocGia()); } private void btnTheLoaiSach_ItemClick(object sender, ItemClickEventArgs e) { btnXuLyClick((DevExpress.XtraBars.BarButtonItem)e.Item, new ctrlTheLoaiSach()); } private void btnLyDoThanhLy_ItemClick(object sender, ItemClickEventArgs e) { btnXuLyClick((DevExpress.XtraBars.BarButtonItem)e.Item, new ctrlLyDoThanhLy()); } private void btnTiepNhanSachMoi_ItemClick(object sender, ItemClickEventArgs e) { btnXuLyClick((DevExpress.XtraBars.BarButtonItem)e.Item, new ctrlTiepNhanSachMoi()); } private void btnThanhLySach_ItemClick(object sender, ItemClickEventArgs e) { btnXuLyClick((DevExpress.XtraBars.BarButtonItem)e.Item, new ctrlThanhLySach()); } private void btnLapPhieuThuTienPhat_ItemClick(object sender, ItemClickEventArgs e) { btnXuLyClick((DevExpress.XtraBars.BarButtonItem)e.Item, new ctrlLapPhieuThuTienPhat()); } private void btnTiepNhanNhanVien_ItemClick(object sender, ItemClickEventArgs e) { btnXuLyClick((DevExpress.XtraBars.BarButtonItem)e.Item, new ctrlTiepNhanNhanVien()); } private void btnQuanLyNhanVien_ItemClick(object sender, ItemClickEventArgs e) { btnXuLyClick((DevExpress.XtraBars.BarButtonItem)e.Item, new ctrlQuanLyNhanVien()); } private void btnChucVu_ItemClick(object sender, ItemClickEventArgs e) { btnXuLyClick((DevExpress.XtraBars.BarButtonItem)e.Item, new ctrlChucVu()); } private void btnBoPhan_ItemClick(object sender, ItemClickEventArgs e) { btnXuLyClick((DevExpress.XtraBars.BarButtonItem)e.Item, new ctrlBoPhan()); } private void btnBangCap_ItemClick(object sender, ItemClickEventArgs e) { btnXuLyClick((DevExpress.XtraBars.BarButtonItem)e.Item, new ctrlBangCap()); } private void btnTinhHinhMuonSachTheoTheLoai_ItemClick(object sender, ItemClickEventArgs e) { btnXuLyClick((DevExpress.XtraBars.BarButtonItem)e.Item, new ctrlTinhHinhMuonSachTheoTheLoai()); } private void btnSachTraTre_ItemClick(object sender, ItemClickEventArgs e) { btnXuLyClick((DevExpress.XtraBars.BarButtonItem)e.Item, new ctrlSachTraTre()); } private void btnDocGiaNoTienPhat_ItemClick(object sender, ItemClickEventArgs e) { btnXuLyClick((DevExpress.XtraBars.BarButtonItem)e.Item, new ctrlDocGiaNoTienPhat()); } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/QuanLyThuVien/GUI.cs
C#
asf20
15,306
<Configurations active="Default"><Configuration name="Default"><Command val=""></Command><RunMode val="a host path through a shared folder"></RunMode><ShareFolders val=""></ShareFolders><RemoteDebugMonitor val="C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\Remote Debugger\x86\msvsmon.exe"></RemoteDebugMonitor><MonitorName val="VMDebug"></MonitorName><RemoteVM val=""></RemoteVM><StartMode val="No"></StartMode><TerminationMode val="No operation"></TerminationMode><CopyFiles val=""></CopyFiles><PreCommandLine val=""></PreCommandLine><PostCommandLine val=""></PostCommandLine><RecordingToReplay val=""></RecordingToReplay><ReplayVM val=""></ReplayVM><BaseSnapshotForRecording val=""></BaseSnapshotForRecording><HostDllPath val=""></HostDllPath></Configuration></Configurations>
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/QuanLyThuVien/QuanLyThuVien.idc
C
asf20
792
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace QuanLyThuVien { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new GUI()); } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/QuanLyThuVien/Program.cs
C#
asf20
503
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DTO { public class PhieuThuTienPhatDTO { int m_MaPhieuThu; public int MaPhieuThu { get { return m_MaPhieuThu; } set { m_MaPhieuThu = value; } } float m_SoTienThu; public float SoTienThu { get { return m_SoTienThu; } set { m_SoTienThu = value; } } float m_ConLai; public float ConLai { get { return m_ConLai; } set { m_ConLai = value; } } float m_TienNo; public float TienNo { get { return m_TienNo; } set { m_TienNo = value; } } DateTime m_NgayThu; public DateTime NgayThu { get { return m_NgayThu; } set { m_NgayThu = value; } } int m_MaNhanVien; public int MaNhanVien { get { return m_MaNhanVien; } set { m_MaNhanVien = value; } } int m_MaDocGia; public int MaDocGia { get { return m_MaDocGia; } set { m_MaDocGia = value; } } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DTO/PhieuThuTienPhatDTO.cs
C#
asf20
1,303
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DTO { public class LyDoThanhLyDTO { int m_MaLyDo; public int MaLyDo { get { return m_MaLyDo; } set { m_MaLyDo = value; } } string m_TenLyDo; public string TenLyDo { get { return m_TenLyDo; } set { m_TenLyDo = value; } } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DTO/LyDoThanhLyDTO.cs
C#
asf20
475
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DTO { public class ChiTietPhieuTraDTO { int m_MaChiTietPhieuTra; public int MaChiTietPhieuTra { get { return m_MaChiTietPhieuTra; } set { m_MaChiTietPhieuTra = value; } } DateTime m_NgayMuon; public DateTime NgayMuon { get { return m_NgayMuon; } set { m_NgayMuon = value; } } int m_SoNgayMuon; public int SoNgayMuon { get { return m_SoNgayMuon; } set { m_SoNgayMuon = value; } } int m_SoNgayTraTre; public int SoNgayTraTre { get { return m_SoNgayTraTre; } set { m_SoNgayTraTre = value; } } float m_TienPhat; public float TienPhat { get { return m_TienPhat; } set { m_TienPhat = value; } } int m_MaPhieuTraSach; public int MaPhieuTraSach { get { return m_MaPhieuTraSach; } set { m_MaPhieuTraSach = value; } } int m_MaSach; public int MaSach { get { return m_MaSach; } set { m_MaSach = value; } } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DTO/ChiTietPhieuTraDTO.cs
C#
asf20
1,374
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DTO { public class DocGiaDTO { int m_MaDocGia; public int MaDocGia { get { return m_MaDocGia; } set { m_MaDocGia = value; } } string m_TenDocGia; public string TenDocGia { get { return m_TenDocGia; } set { m_TenDocGia = value; } } int m_MaloaiDocGia; public int MaloaiDocGia { get { return m_MaloaiDocGia; } set { m_MaloaiDocGia = value; } } DateTime m_NgaySinh; public DateTime NgaySinh { get { return m_NgaySinh; } set { m_NgaySinh = value; } } string m_DiaChi; public string DiaChi { get { return m_DiaChi; } set { m_DiaChi = value; } } string m_Email; public string Email { get { return m_Email; } set { m_Email = value; } } DateTime m_NgayLapThe; public DateTime NgayLapThe { get { return m_NgayLapThe; } set { m_NgayLapThe = value; } } DateTime m_NgayHetHan; public DateTime NgayHetHan { get { return m_NgayHetHan; } set { m_NgayHetHan = value; } } int m_MaNhanVien; public int MaNhanVien { get { return m_MaNhanVien; } set { m_MaNhanVien = value; } } float m_TienNo; public float TienNo { get { return m_TienNo; } set { m_TienNo = value; } } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DTO/DocGiaDTO.cs
C#
asf20
1,820
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DTO { public class BangCapDTO { int m_MaBangCap; public int MaBangCap { get { return m_MaBangCap; } set { m_MaBangCap = value; } } string m_TenBangCap; public string TenBangCap { get { return m_TenBangCap; } set { m_TenBangCap = value; } } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DTO/BangCapDTO.cs
C#
asf20
495
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DTO { public class NhanVienDTO { int m_MaNhanVien; public int MaNhanVien { get { return m_MaNhanVien; } set { m_MaNhanVien = value; } } string m_TenNhanVien; public string TenNhanVien { get { return m_TenNhanVien; } set { m_TenNhanVien = value; } } DateTime m_NgaySinh; public DateTime NgaySinh { get { return m_NgaySinh; } set { m_NgaySinh = value; } } string m_DiaChi; public string DiaChi { get { return m_DiaChi; } set { m_DiaChi = value; } } string m_DienThoai; public string DienThoai { get { return m_DienThoai; } set { m_DienThoai = value; } } int m_MaBangCap; public int MaBangCap { get { return m_MaBangCap; } set { m_MaBangCap = value; } } int m_MaChucVu; public int MaChucVu { get { return m_MaChucVu; } set { m_MaChucVu = value; } } int m_MaBoPhan; public int MaBoPhan { get { return m_MaBoPhan; } set { m_MaBoPhan = value; } } string m_TenTaiKhoan; public string TenTaiKhoan { get { return m_TenTaiKhoan; } set { m_TenTaiKhoan = value; } } string m_MatKhau; public string MatKhau { get { return m_MatKhau; } set { m_MatKhau = value; } } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DTO/NhanVienDTO.cs
C#
asf20
1,822
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DTO { public class ChiTietPhieuThanhLyDTO { int m_MaChiTietPhieuThanhLy; public int MaChiTietPhieuThanhLy { get { return m_MaChiTietPhieuThanhLy; } set { m_MaChiTietPhieuThanhLy = value; } } int m_MaPhieuThanhLy; public int MaPhieuThanhLy { get { return m_MaPhieuThanhLy; } set { m_MaPhieuThanhLy = value; } } int m_MaSach; public int MaSach { get { return m_MaSach; } set { m_MaSach = value; } } int m_MaLyDo; public int MaLyDo { get { return m_MaLyDo; } set { m_MaLyDo = value; } } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DTO/ChiTietPhieuThanhLyDTO.cs
C#
asf20
867
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DTO { public class ChucVuDTO { int m_MaChucVu; public int MaChucVu { get { return m_MaChucVu; } set { m_MaChucVu = value; } } string m_TenChucVu; public string TenChucVu { get { return m_TenChucVu; } set { m_TenChucVu = value; } } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DTO/ChucVuDTO.cs
C#
asf20
486
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DTO { public class PhieuGhiNhanMatSachDTO { int m_MaPhieuGhiNhan; public int MaPhieuGhiNhan { get { return m_MaPhieuGhiNhan; } set { m_MaPhieuGhiNhan = value; } } DateTime m_NgayGhiNhan; public DateTime NgayGhiNhan { get { return m_NgayGhiNhan; } set { m_NgayGhiNhan = value; } } float m_Tienphat; public float Tienphat { get { return m_Tienphat; } set { m_Tienphat = value; } } int m_MaSach; public int MaSach { get { return m_MaSach; } set { m_MaSach = value; } } int m_MaDocGia; public int MaDocGia { get { return m_MaDocGia; } set { m_MaDocGia = value; } } int m_MaNhanVien; public int MaNhanVien { get { return m_MaNhanVien; } set { m_MaNhanVien = value; } } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DTO/PhieuGhiNhanMatSachDTO.cs
C#
asf20
1,175
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DTO { public class SachDTO { int m_MaSach; public int MaSach { get { return m_MaSach; } set { m_MaSach = value; } } string m_TenSach; public string TenSach { get { return m_TenSach; } set { m_TenSach = value; } } int m_MaTheLoai; public int MaTheLoai { get { return m_MaTheLoai; } set { m_MaTheLoai = value; } } string m_TenTacGia; public string TenTacGia { get { return m_TenTacGia; } set { m_TenTacGia = value; } } int m_NamXuatBan; public int NamXuatBan { get { return m_NamXuatBan; } set { m_NamXuatBan = value; } } string m_NhaXuatBan; public string NhaXuatBan { get { return m_NhaXuatBan; } set { m_NhaXuatBan = value; } } DateTime m_NgayNhap; public DateTime NgayNhap { get { return m_NgayNhap; } set { m_NgayNhap = value; } } float m_TriGia; public float TriGia { get { return m_TriGia; } set { m_TriGia = value; } } int m_MaTinhTrang; public int MaTinhTrang { get { return m_MaTinhTrang; } set { m_MaTinhTrang = value; } } int m_MaNhanVien; public int MaNhanVien { get { return m_MaNhanVien; } set { m_MaNhanVien = value; } } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DTO/SachDTO.cs
C#
asf20
1,802
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DTO { public class TheLoaiSachDTO { int m_MaTheLoai; public int MaTheLoai { get { return m_MaTheLoai; } set { m_MaTheLoai = value; } } string m_TenTheLoai; public string TenTheLoai { get { return m_TenTheLoai; } set { m_TenTheLoai = value; } } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DTO/TheLoaiSachDTO.cs
C#
asf20
499
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DTO { public static class session { public static string tenTaiKhoan; public static string matKhau; public static int maNhanVien; public static string tenNhanVien; public static int maBoPhan; public static bool trangThai; } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DTO/session.cs
C#
asf20
403
using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("DTO")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("SUPEZCHICKEN")] [assembly: AssemblyProduct("DTO")] [assembly: AssemblyCopyright("Copyright © SUPEZCHICKEN 2011")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("d8b221a3-461a-483e-8f28-22fd5359b447")] // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DTO/Properties/AssemblyInfo.cs
C#
asf20
1,442
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DTO { public class PhieuTraSachDTO { int m_MaPhieuTraSach; public int MaPhieuTraSach { get { return m_MaPhieuTraSach; } set { m_MaPhieuTraSach = value; } } DateTime m_NgayTraSach; public DateTime NgayTraSach { get { return m_NgayTraSach; } set { m_NgayTraSach = value; } } float m_TienPhatKyNay; public float TienPhatKyNay { get { return m_TienPhatKyNay; } set { m_TienPhatKyNay = value; } } int m_MaDocGia; public int MaDocGia { get { return m_MaDocGia; } set { m_MaDocGia = value; } } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DTO/PhieuTraSachDTO.cs
C#
asf20
870
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DTO { public class LoaiDocGiaDTO { int m_MaLoaiDocGia; public int MaLoaiDocGia { get { return m_MaLoaiDocGia; } set { m_MaLoaiDocGia = value; } } string m_TenLoaiDocGia; public string TenLoaiDocGia { get { return m_TenLoaiDocGia; } set { m_TenLoaiDocGia = value; } } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DTO/LoaiDocGiaDTO.cs
C#
asf20
522
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DTO { public class PhieuMuonSachDTO { int m_MaPhieuMuon; public int MaPhieuMuon { get { return m_MaPhieuMuon; } set { m_MaPhieuMuon = value; } } DateTime m_NgayMuon; public DateTime NgayMuon { get { return m_NgayMuon; } set { m_NgayMuon = value; } } int m_MaDocGia; public int MaDocGia { get { return m_MaDocGia; } set { m_MaDocGia = value; } } DateTime m_NgayHetHan; public DateTime NgayHetHan { get { return m_NgayHetHan; } set { m_NgayHetHan = value; } } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DTO/PhieuMuonSachDTO.cs
C#
asf20
841
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DTO { public class PhieuThanhLyDTO { int m_MaPhieuThanhLy; public int MaPhieuThanhLy { get { return m_MaPhieuThanhLy; } set { m_MaPhieuThanhLy = value; } } DateTime m_NgayThanhLy; public DateTime NgayThanhLy { get { return m_NgayThanhLy; } set { m_NgayThanhLy = value; } } int m_MaNhanVien; public int MaNhanVien { get { return m_MaNhanVien; } set { m_MaNhanVien = value; } } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DTO/PhieuThanhLyDTO.cs
C#
asf20
695
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DTO { public class ThamSoDTO { int m_MaThamSo; public int MaThamSo { get { return m_MaThamSo; } set { m_MaThamSo = value; } } string m_TenThamSo; public string TenThamSo { get { return m_TenThamSo; } set { m_TenThamSo = value; } } float m_GiaTri; public float GiaTri { get { return m_GiaTri; } set { m_GiaTri = value; } } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DTO/ThamSoDTO.cs
C#
asf20
641
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DTO { public class BoPhanDTO { int m_MaBoPhan; public int MaBoPhan { get { return m_MaBoPhan; } set { m_MaBoPhan = value; } } string m_TenBoPhan; public string TenBoPhan { get { return m_TenBoPhan; } set { m_TenBoPhan = value; } } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DTO/BoPhanDTO.cs
C#
asf20
486
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DTO { public class ChiTietPhieuMuonDTO { int m_MaChiTietPhieuMuon; public int MaChiTietPhieuMuon { get { return m_MaChiTietPhieuMuon; } set { m_MaChiTietPhieuMuon = value; } } int m_MaPhieuMuon; public int MaPhieuMuon { get { return m_MaPhieuMuon; } set { m_MaPhieuMuon = value; } } int m_MaSach; public int MaSach { get { return m_MaSach; } set { m_MaSach = value; } } int m_DanhDau; public int DanhDau { get { return m_DanhDau; } set { m_DanhDau = value; } } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DTO/ChiTietPhieuMuonDTO.cs
C#
asf20
846
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DTO { public class TinhTrangDTO { int m_MaTinhTrang; public int MaTinhTrang { get { return m_MaTinhTrang; } set { m_MaTinhTrang = value; } } string m_TenTinhTrang; public string TenTinhTrang { get { return m_TenTinhTrang; } set { m_TenTinhTrang = value; } } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DTO/TinhTrangDTO.cs
C#
asf20
513
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Transactions; using AutoMapper; using DTO; namespace DAO { public class DocGiaDAO { public static bool Them(DocGiaDTO dto) { using (TransactionScope scope = new TransactionScope()) { //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); //tạo đối tượng DocGia dg = new DocGia(); //mapping Mapper.CreateMap<DocGiaDTO, DocGia>(); dg = Mapper.Map<DocGiaDTO, DocGia>(dto); //thêm vào ds khi nhấn submit context.DocGias.InsertOnSubmit(dg); //thực hiện thay đổi context.SubmitChanges(); //Đọc dòng vừa ghi để lưu lại mã lên trên //dto.MaDocGia = dg.MaDocGia; //transaction thành công scope.Complete(); } return true; } public static List<DocGiaDTO> DocDanhSach() { //tạo list List<DocGiaDTO> list = new List<DocGiaDTO>(); //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); var ds = from n in context.DocGias select n; //duyệt danh sách foreach (DocGia n in ds) { //mapping từ linQ vào dto DocGiaDTO dto = new DocGiaDTO(); Mapper.CreateMap<DocGia, DocGiaDTO>(); dto = Mapper.Map<DocGia, DocGiaDTO>(n); //thêm vào list list.Add(dto); } //trả về kq return list; } public static bool CapNhatTienNo(DocGiaDTO dto) { using (TransactionScope scope = new TransactionScope()) { //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); //đọc thôn tin độc giả từ csdl DocGia dg = context.DocGias.Single(c => c.MaDocGia == dto.MaDocGia); //cập nhật tiền nợ dg.TienNo = dto.TienNo; //thực hiện thay đổi context.SubmitChanges(); //transaction thành công scope.Complete(); } return true; } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DAO/DocGiaDAO.cs
C#
asf20
2,709
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DTO; using AutoMapper; using System.Transactions; namespace DAO { public class BangCapDAO { public static List<BangCapDTO> DocDanhSach() { //tạo list List<BangCapDTO> list = new List<BangCapDTO>(); //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); var ds = from n in context.BangCaps select n; //duyệt danh sách foreach(BangCap n in ds) { //mapping từ linQ vào dto BangCapDTO dto = new BangCapDTO(); Mapper.CreateMap<BangCap, BangCapDTO>(); dto = Mapper.Map<BangCap, BangCapDTO>(n); //thêm vào list list.Add(dto); } //trả về kq return list; } public static bool Them(BangCapDTO dto) { using (TransactionScope scope = new TransactionScope()) { //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); //tạo đối tượng BangCap bangcap = new BangCap(); //mapping Mapper.CreateMap<BangCapDTO, BangCap>(); bangcap = Mapper.Map<BangCapDTO, BangCap>(dto); //thêm vào ds khi nhấn submit context.BangCaps.InsertOnSubmit(bangcap); //thực hiện thay đổi context.SubmitChanges(); //Đọc dòng vừa ghi để lưu lại mã lên trên dto.MaBangCap = bangcap.MaBangCap; //transaction thành công scope.Complete(); } return true; } public static bool Xoa(BangCapDTO dto) { using (TransactionScope scope = new TransactionScope()) { //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); //Lấy dữ liệu phù hợp với dto BangCap bangcap = context.BangCaps.Single(c => c.MaBangCap == dto.MaBangCap); //Xóa context.BangCaps.DeleteOnSubmit(bangcap); //thực hiện thay đổi context.SubmitChanges(); //transaction thành công scope.Complete(); } return true; } public static bool CapNhat(BangCapDTO dto) { using (TransactionScope scope = new TransactionScope()) { //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); //Lấy dữ liệu phù hợp với dto BangCap bangcap = context.BangCaps.Single(c => c.MaBangCap == dto.MaBangCap); bangcap.TenBangCap = dto.TenBangCap; //thực hiện thay đổi context.SubmitChanges(); //transaction thành công scope.Complete(); } return true; } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DAO/BangCapDAO.cs
C#
asf20
3,521
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DTO; using AutoMapper; using System.Transactions; namespace DAO { public class PhieuGhiNhanMatSachDAO { public static bool Them(DTO.PhieuGhiNhanMatSachDTO dtoPhieu) { using (TransactionScope scope = new TransactionScope()) { //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); //tạo đối tượng PhieuGhiNhanMatSach p = new PhieuGhiNhanMatSach(); //mapping Mapper.CreateMap<PhieuGhiNhanMatSachDTO, PhieuGhiNhanMatSach>(); p = Mapper.Map<PhieuGhiNhanMatSachDTO, PhieuGhiNhanMatSach>(dtoPhieu); //thêm vào ds khi nhấn submit context.PhieuGhiNhanMatSaches.InsertOnSubmit(p); foreach (ChiTietPhieuMuon ctpm in context.ChiTietPhieuMuons) { if (ctpm.MaSach == dtoPhieu.MaSach) ctpm.DanhDau = 1; } //thực hiện thay đổi context.SubmitChanges(); //transaction thành công scope.Complete(); } return true; } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DAO/PhieuGhiNhanMatSachDAO.cs
C#
asf20
1,410
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Transactions; using AutoMapper; using DTO; namespace DAO { public class NhanVienDAO { public static bool DangNhap(NhanVienDTO dto) { //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); //Lấy dữ liệu phù hợp với dto NhanVien nv = context.NhanViens.SingleOrDefault(c => c.TenTaiKhoan == dto.TenTaiKhoan && c.MatKhau == dto.MatKhau); //không tồn tại nhân viên tức tên tài khoản & mật khẩu bị sai //trả về false if (nv == null) return false; //gán lại thông tin vào dto đưa lên dto.MaNhanVien = nv.MaNhanVien; dto.TenNhanVien = nv.TenNhanVien; dto.MaBoPhan = nv.MaBoPhan; //nhân viên có tồn tại và nhập đúng thông tin return true; } public static bool KiemTraTaiKhoan(string p) { //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); //Lấy dữ liệu phù hợp với string NhanVien nhanvien = context.NhanViens.SingleOrDefault(c => c.TenTaiKhoan == p); //tên tài khoản chưa tồn tại return false if (nhanvien == null) return false; //tên tài khoản đã tồn tại return true return true; //true : đã tồn tại //false : chưa tồn tại } public static bool Them(NhanVienDTO dto) { using (TransactionScope scope = new TransactionScope()) { //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); //tạo đối tượng NhanVien n = new NhanVien(); //mapping Mapper.CreateMap<NhanVienDTO, NhanVien>(); n = Mapper.Map<NhanVienDTO, NhanVien>(dto); //thêm vào ds khi nhấn submit context.NhanViens.InsertOnSubmit(n); //thực hiện thay đổi context.SubmitChanges(); //Đọc dòng vừa ghi để lưu lại mã lên trên //dto.MaNhanVien = n.MaNhanVien; //transaction thành công scope.Complete(); } return true; } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DAO/NhanVienDAO.cs
C#
asf20
2,717
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DTO; using System.Transactions; using AutoMapper; namespace DAO { public class ThamSoDAO { public static ThamSoDTO DocThamSo(string p) { //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); //Lấy dữ liệu phù hợp với chuỗi ThamSo thamso = context.ThamSos.Single(c => c.TenThamSo == p); //tạo mới tham số dto ThamSoDTO dto = new ThamSoDTO(); //mapping thông tin sang dto Mapper.CreateMap<ThamSo, ThamSoDTO>(); dto = Mapper.Map<ThamSo, ThamSoDTO>(thamso); return dto; } public static bool CapNhap(string thamSo, float giaTri) { using (TransactionScope scope = new TransactionScope()) { //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); //Lấy dữ liệu phù hợp với dto ThamSo ts = context.ThamSos.Single(c => c.TenThamSo == thamSo); ts.GiaTri = giaTri; //thực hiện thay đổi context.SubmitChanges(); //transaction thành công scope.Complete(); } return true; } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DAO/ThamSoDAO.cs
C#
asf20
1,513
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DTO; using AutoMapper; using System.Transactions; namespace DAO { public class BoPhanDAO { public static List<BoPhanDTO> DocDanhSach() { //tạo list List<BoPhanDTO> list = new List<BoPhanDTO>(); //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); var ds = from n in context.BoPhans select n; //duyệt danh sách foreach (BoPhan n in ds) { //mapping từ linQ vào dto BoPhanDTO dto = new BoPhanDTO(); Mapper.CreateMap<BoPhan, BoPhanDTO>(); dto = Mapper.Map<BoPhan, BoPhanDTO>(n); //thêm vào list list.Add(dto); } //trả về kq return list; } public static bool Them(BoPhanDTO dto) { using (TransactionScope scope = new TransactionScope()) { //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); //tạo đối tượng BoPhan BoPhan = new BoPhan(); //mapping Mapper.CreateMap<BoPhanDTO, BoPhan>(); BoPhan = Mapper.Map<BoPhanDTO, BoPhan>(dto); //thêm vào ds khi nhấn submit context.BoPhans.InsertOnSubmit(BoPhan); //thực hiện thay đổi context.SubmitChanges(); //Đọc dòng vừa ghi để lưu lại mã lên trên dto.MaBoPhan = BoPhan.MaBoPhan; //transaction thành công scope.Complete(); } return true; } public static bool Xoa(BoPhanDTO dto) { using (TransactionScope scope = new TransactionScope()) { //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); //Lấy dữ liệu phù hợp với dto BoPhan BoPhan = context.BoPhans.Single(c => c.MaBoPhan == dto.MaBoPhan); //Xóa context.BoPhans.DeleteOnSubmit(BoPhan); //thực hiện thay đổi context.SubmitChanges(); //transaction thành công scope.Complete(); } return true; } public static bool CapNhat(BoPhanDTO dto) { using (TransactionScope scope = new TransactionScope()) { //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); //Lấy dữ liệu phù hợp với dto BoPhan BoPhan = context.BoPhans.Single(c => c.MaBoPhan == dto.MaBoPhan); BoPhan.TenBoPhan = dto.TenBoPhan; //thực hiện thay đổi context.SubmitChanges(); //transaction thành công scope.Complete(); } return true; } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DAO/BoPhanDAO.cs
C#
asf20
3,409
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DTO; using AutoMapper; using System.Transactions; namespace DAO { public class LyDoThanhLyDAO { public static List<DTO.LyDoThanhLyDTO> DocDanhSach() { //tạo list List<LyDoThanhLyDTO> list = new List<LyDoThanhLyDTO>(); //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); var ds = from n in context.LyDoThanhLies select n; //duyệt danh sách foreach (LyDoThanhLy n in ds) { //mapping từ linQ vào dto LyDoThanhLyDTO dto = new LyDoThanhLyDTO(); Mapper.CreateMap<LyDoThanhLy, LyDoThanhLyDTO>(); dto = Mapper.Map<LyDoThanhLy, LyDoThanhLyDTO>(n); //thêm vào list list.Add(dto); } //trả về kq return list; } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DAO/LyDoThanhLyDAO.cs
C#
asf20
1,077
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DAO { public class ChiTietPhieuMuonDAO { } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DAO/ChiTietPhieuMuonDAO.cs
C#
asf20
168
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DAO { public class ChiTietPhieuTraDAO { } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DAO/ChiTietPhieuTraDAO.cs
C#
asf20
167
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DTO; using AutoMapper; using System.Transactions; namespace DAO { public class ChucVuDAO { public static List<ChucVuDTO> DocDanhSach() { //tạo list List<ChucVuDTO> list = new List<ChucVuDTO>(); //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); var ds = from n in context.ChucVus select n; //duyệt danh sách foreach (ChucVu n in ds) { //mapping từ linQ vào dto ChucVuDTO dto = new ChucVuDTO(); Mapper.CreateMap<ChucVu, ChucVuDTO>(); dto = Mapper.Map<ChucVu, ChucVuDTO>(n); //thêm vào list list.Add(dto); } //trả về kq return list; } public static bool Them(ChucVuDTO dto) { using (TransactionScope scope = new TransactionScope()) { //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); //tạo đối tượng ChucVu ChucVu = new ChucVu(); //mapping Mapper.CreateMap<ChucVuDTO, ChucVu>(); ChucVu = Mapper.Map<ChucVuDTO, ChucVu>(dto); //thêm vào ds khi nhấn submit context.ChucVus.InsertOnSubmit(ChucVu); //thực hiện thay đổi context.SubmitChanges(); //Đọc dòng vừa ghi để lưu lại mã lên trên dto.MaChucVu = ChucVu.MaChucVu; //transaction thành công scope.Complete(); } return true; } public static bool Xoa(ChucVuDTO dto) { using (TransactionScope scope = new TransactionScope()) { //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); //Lấy dữ liệu phù hợp với dto ChucVu ChucVu = context.ChucVus.Single(c => c.MaChucVu == dto.MaChucVu); //Xóa context.ChucVus.DeleteOnSubmit(ChucVu); //thực hiện thay đổi context.SubmitChanges(); //transaction thành công scope.Complete(); } return true; } public static bool CapNhat(ChucVuDTO dto) { using (TransactionScope scope = new TransactionScope()) { //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); //Lấy dữ liệu phù hợp với dto ChucVu ChucVu = context.ChucVus.Single(c => c.MaChucVu == dto.MaChucVu); ChucVu.TenChucVu = dto.TenChucVu; //thực hiện thay đổi context.SubmitChanges(); //transaction thành công scope.Complete(); } return true; } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DAO/ChucVuDAO.cs
C#
asf20
3,409
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DTO; using System.Transactions; using AutoMapper; namespace DAO { public class PhieuMuonSachDAO { public static List<SachDTO> SachDangMuon(int maDocGia) { //tạo list List<SachDTO> list = new List<SachDTO>(); //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); //đọc lên danh sách phiếu mượn của độc giả var ds = context.PhieuMuonSaches.Where(c => c.MaDocGia == maDocGia); //duyệt danh sách các phiếu mượn sách của độc giả foreach (PhieuMuonSach pms in ds) { //duyệt các chi tiết phiếu mượn foreach (ChiTietPhieuMuon ctpm in pms.ChiTietPhieuMuons) { //nếu chưa đánh dấu xóa thì mới đọc if (ctpm.DanhDau == 1) continue; //đọc từng cuốn sách Sach n = context.Saches.SingleOrDefault(c => c.MaSach == ctpm.MaSach && c.MaTinhTrang == 2); //trường hợp không tin thấy như điều kiện thì tiếp tục tìm cuốn sách khác if (n == null) continue; //mapping từ linQ vào dto SachDTO dto = new SachDTO(); Mapper.CreateMap<Sach, SachDTO>(); dto = Mapper.Map<Sach, SachDTO>(n); //thêm vào danh sách list.Add(dto); } } return list; } public static List<SachDTO> SachMuonQuaHan(int maDocGia) { //tạo list List<SachDTO> list = new List<SachDTO>(); //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); //đọc lên danh sách phiếu mượn của độc giả var ds = context.PhieuMuonSaches.Where(c => c.MaDocGia == maDocGia); //duyệt danh sách các phiếu mượn sách của độc giả foreach (PhieuMuonSach pms in ds) { //public static int Compare( //DateTime t1, //DateTime t2 //) //Condition //Less than zero => t1 is earlier than t2. //Zero => t1 is the same as t2. //Greater than zero => t1 is later than t2. //nếu phiếu mượn quá hạn if (DateTime.Compare(pms.NgayHetHan, DateTime.Today) < 0) //duyệt các chi tiết của phiếu mượn foreach (ChiTietPhieuMuon ctpm in pms.ChiTietPhieuMuons) { //nếu chưa đánh dấu xóa thì mới đọc if (ctpm.DanhDau == 1) continue; //đọc từng cuốn sách Sach n = context.Saches.SingleOrDefault(c => c.MaSach == ctpm.MaSach && c.MaTinhTrang == 2); if (n == null) continue; //mapping từ linQ vào dto SachDTO dto = new SachDTO(); Mapper.CreateMap<Sach, SachDTO>(); dto = Mapper.Map<Sach, SachDTO>(n); //thêm vào danh sách list.Add(dto); } } return list; } public static bool Them(PhieuMuonSachDTO dto, List<SachDTO> listSachMuon) { using (TransactionScope scope = new TransactionScope()) { //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); //tạo phieumuonsach entity PhieuMuonSach pms = new PhieuMuonSach(); //mapping từ dto sang entity Mapper.CreateMap<PhieuMuonSachDTO, PhieuMuonSach>(); pms = Mapper.Map<PhieuMuonSachDTO, PhieuMuonSach>(dto); //duyệt danh sách sách foreach (SachDTO sach in listSachMuon) { //Danh dau = 0: chưa xóa //Danh dau = 1: đã xóa //tao đối tượng chi tiết có mã sách là mã sách của sachdto ChiTietPhieuMuon ctpm = new ChiTietPhieuMuon { MaSach = sach.MaSach, DanhDau = 0 }; //thêm chi tiết cho phiếu mượn sách pms.ChiTietPhieuMuons.Add(ctpm); //đọc sách lên và cập nhật lại tình trạng của sách Sach s = context.Saches.Single(c => c.MaSach == sach.MaSach); s.MaTinhTrang = 2; } //thêm entity phieumuonsach vào context context.PhieuMuonSaches.InsertOnSubmit(pms); //thực thi context.SubmitChanges(); //kết thúc scope.Complete(); } return true; } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DAO/PhieuMuonSachDAO.cs
C#
asf20
5,562
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DTO; using System.Transactions; using AutoMapper; namespace DAO { public class PhieuThuTienPhatDAO { public static bool Them(PhieuThuTienPhatDTO dtoPhieuThu) { using (TransactionScope scope = new TransactionScope()) { //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); //tạo đối tượng PhieuThuTienPhat pt = new PhieuThuTienPhat(); //mapping Mapper.CreateMap<PhieuThuTienPhatDTO, PhieuThuTienPhat>(); pt = Mapper.Map<PhieuThuTienPhatDTO, PhieuThuTienPhat>(dtoPhieuThu); //thêm vào ds khi nhấn submit context.PhieuThuTienPhats.InsertOnSubmit(pt); //thực hiện thay đổi context.SubmitChanges(); //transaction thành công scope.Complete(); } return true; } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DAO/PhieuThuTienPhatDAO.cs
C#
asf20
1,153
using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("DAO")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("SUPEZCHICKEN")] [assembly: AssemblyProduct("DAO")] [assembly: AssemblyCopyright("Copyright © SUPEZCHICKEN 2011")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("3deb4d07-eac7-46f5-a25a-826f7f1f6640")] // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DAO/Properties/AssemblyInfo.cs
C#
asf20
1,442
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Transactions; using DTO; using AutoMapper; namespace DAO { public class SachDAO { public static bool Them(SachDTO dto) { using (TransactionScope scope = new TransactionScope()) { //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); //tạo đối tượng Sach n = new Sach(); //mapping Mapper.CreateMap<SachDTO, Sach>(); n = Mapper.Map<SachDTO, Sach>(dto); //thêm vào ds khi nhấn submit context.Saches.InsertOnSubmit(n); //thực hiện thay đổi context.SubmitChanges(); //Đọc dòng vừa ghi để lưu lại mã lên trên //dto.MaSach = n.MaSach; //transaction thành công scope.Complete(); } return true; } public static List<SachDTO> DocDanhSach(int trangThai) { //tạo list List<SachDTO> list = new List<SachDTO>(); //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); var query = from n in context.Saches select n; //trạng thái //1: mặc định đọc tất cả //chỉ đọc lên sách còn có thể sử dụng if (trangThai == 2) query = query.Where(p => p.MaTinhTrang == 1 || p.MaTinhTrang == 2); //đọc lên sách chưa thanh lý if (trangThai == 3) query = query.Where(p => p.MaTinhTrang != 6); //duyệt danh sách foreach (Sach n in query) { //mapping từ linQ vào dto SachDTO dto = new SachDTO(); Mapper.CreateMap<Sach, SachDTO>(); dto = Mapper.Map<Sach, SachDTO>(n); //thêm vào list list.Add(dto); } //trả về kq return list; } public static List<SachDTO> TraCuu(SachDTO s) { //tạo list List<SachDTO> list = new List<SachDTO>(); //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); //// set up the "main query" //var test = from p in _db.test select _db.test; //// if str1 is not null, add a where-condition //if (str1 != null) //{ // test = test.Where(p => p.test == str); //} //truy vấn var query = from n in context.Saches select n; //kiểm tra & thêm điều kiệt tra cứu if (s.MaTheLoai != 0) query = query.Where(p => p.MaTheLoai == s.MaTheLoai); if (s.MaTinhTrang != 0) query = query.Where(p => p.MaTinhTrang == s.MaTinhTrang); if (s.NamXuatBan != 0) query = query.Where(p => p.NamXuatBan == s.NamXuatBan); if (s.NhaXuatBan != "") query = query.Where(p => p.NhaXuatBan.Contains(s.NhaXuatBan)); if (s.TenSach != "") query = query.Where(p => p.TenSach.Contains(s.TenSach)); if (s.TenTacGia != "") query = query.Where(p => p.TenTacGia.Contains(s.TenTacGia)); //duyệt danh sách foreach (Sach n in query) { //mapping từ linQ vào dto SachDTO dto = new SachDTO(); Mapper.CreateMap<Sach, SachDTO>(); dto = Mapper.Map<Sach, SachDTO>(n); //thêm vào list list.Add(dto); } //trả về kq return list; } public static bool GhiNhanMatSach(SachDTO dtoSach) { using (TransactionScope scope = new TransactionScope()) { //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); //đọc thông tin sách từ csdl Sach s = context.Saches.Single(c => c.MaSach == dtoSach.MaSach); //cập nhật tình trạng s.MaTinhTrang = 4; //đưa thông tin vào dto dtoSach.MaTinhTrang = s.MaTinhTrang; //thực hiện thay đổi context.SubmitChanges(); //transaction thành công scope.Complete(); } return true; } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DAO/SachDAO.cs
C#
asf20
5,037
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DTO; using AutoMapper; using System.Transactions; namespace DAO { public class PhieuThanhLyDAO { public static bool Them(DTO.PhieuThanhLyDTO dtoPhieu, List<DTO.ChiTietPhieuThanhLyDTO> listSachThanhLy) { using (TransactionScope scope = new TransactionScope()) { //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); //tạo phiếu thanh lý PhieuThanhLy ptl = new PhieuThanhLy(); //mapping Mapper.CreateMap<PhieuThanhLyDTO, PhieuThanhLy>(); ptl = Mapper.Map<PhieuThanhLyDTO, PhieuThanhLy>(dtoPhieu); //duyệt danh sách chi tiết foreach (ChiTietPhieuThanhLyDTO dtoChiTiet in listSachThanhLy) { //tạo chi tiết ChiTietPhieuThanhLy ct = new ChiTietPhieuThanhLy(); //mapping Mapper.CreateMap<ChiTietPhieuThanhLyDTO, ChiTietPhieuThanhLy>(); ct = Mapper.Map<ChiTietPhieuThanhLyDTO, ChiTietPhieuThanhLy>(dtoChiTiet); //thêm vào phiếu ptl.ChiTietPhieuThanhLies.Add(ct); //cập nhật tình trạng sách đã thanh lý Sach n = context.Saches.Single(c => c.MaSach == dtoChiTiet.MaSach); n.MaTinhTrang = 6; } //thêm vào danh sách phiếu context.PhieuThanhLies.InsertOnSubmit(ptl); //thực hiện thay đổi context.SubmitChanges(); //transaction thành công scope.Complete(); } return true; } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DAO/PhieuThanhLyDAO.cs
C#
asf20
1,983
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DTO; using AutoMapper; using System.Transactions; namespace DAO { public class TinhTrangDAO { public static List<TinhTrangDTO> DocDanhSach() { //tạo list List<TinhTrangDTO> list = new List<TinhTrangDTO>(); //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); var ds = from n in context.TinhTrangs select n; //duyệt danh sách foreach (TinhTrang n in ds) { //mapping từ linQ vào dto TinhTrangDTO dto = new TinhTrangDTO(); Mapper.CreateMap<TinhTrang, TinhTrangDTO>(); dto = Mapper.Map<TinhTrang, TinhTrangDTO>(n); //thêm vào list list.Add(dto); } //trả về kq return list; } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DAO/TinhTrangDAO.cs
C#
asf20
1,052
using System; using System.Collections.Generic; using System.Linq; using System.Text; using AutoMapper; using DTO; using System.Transactions; namespace DAO { public class PhieuTraSachDAO { public static List<ChiTietPhieuTraDTO> SachDangMuon(int maDocGia) { //tạo list chi tiết List<ChiTietPhieuTraDTO> listSachMuon = new List<ChiTietPhieuTraDTO>(); //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); //đọc tham số int tienTraTre = (int)context.ThamSos.Single(c => c.TenThamSo == "TienPhatTraTre").GiaTri; //đọc dữ liệu var query = from pms in context.PhieuMuonSaches join ctpm in context.ChiTietPhieuMuons on pms.MaPhieuMuon equals ctpm.MaPhieuMuon join s in context.Saches on ctpm.MaSach equals s.MaSach where pms.MaDocGia == maDocGia && s.MaTinhTrang == 2 && ctpm.DanhDau == 0 select new { MaChiTietPhieuTra = 0, MaPhieuTraSach = 0, MaSach = ctpm.MaSach, NgayMuon = pms.NgayMuon, SoNgayMuon = DateTime.Today.Subtract(pms.NgayMuon).TotalDays, SoNgayTraTre = DateTime.Today.Subtract(pms.NgayHetHan).TotalDays, TienPhat = 0 } ; //duyệt từng phần tử foreach (var n in query) { //tạo chi tiết phiếu trả dto ChiTietPhieuTraDTO ctpt = new ChiTietPhieuTraDTO(); //gán dữ liệu ctpt.MaChiTietPhieuTra = n.MaChiTietPhieuTra; ctpt.MaPhieuTraSach = n.MaPhieuTraSach; ctpt.MaSach = n.MaSach; ctpt.NgayMuon = n.NgayMuon; ctpt.SoNgayMuon = (int)n.SoNgayMuon; ctpt.SoNgayTraTre = (int)n.SoNgayTraTre; ctpt.TienPhat = (int)n.SoNgayTraTre * tienTraTre; //nếu không có sách quá hạn if (ctpt.TienPhat < 0) ctpt.TienPhat = 0; //thêm vào list listSachMuon.Add(ctpt); } return listSachMuon; } public static bool Them(PhieuTraSachDTO dtoPhieuTra, List<ChiTietPhieuTraDTO> listSachTra) { using (TransactionScope scope = new TransactionScope()) { //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); //Thêm phiếu trả PhieuTraSach pts = new PhieuTraSach(); //mapping Mapper.CreateMap<PhieuTraSachDTO, PhieuTraSach>(); pts = Mapper.Map<PhieuTraSachDTO, PhieuTraSach>(dtoPhieuTra); //duyệt danh sách sách trả foreach (ChiTietPhieuTraDTO dtoctpt in listSachTra) { //tạo mới chi tiết ChiTietPhieuTra ctpt = new ChiTietPhieuTra(); //mapping Mapper.CreateMap<ChiTietPhieuTraDTO, ChiTietPhieuTra>(); ctpt = Mapper.Map<ChiTietPhieuTraDTO, ChiTietPhieuTra>(dtoctpt); //thêm vào phiếu trả sách pts.ChiTietPhieuTras.Add(ctpt); //cập nhật tình trạng sách về chưa cho mượn Sach n = context.Saches.Single(c => c.MaSach == dtoctpt.MaSach); n.MaTinhTrang = 1; //đánh dấu xóa cho chi tiết phiếu mượn foreach (ChiTietPhieuMuon ctpm in context.ChiTietPhieuMuons) { if (ctpm.MaSach == n.MaSach) ctpm.DanhDau = 1; } } //thêm phiếu trả vào csdl context.PhieuTraSaches.InsertOnSubmit(pts); //thực hiện thay đổi context.SubmitChanges(); //transaction thành công scope.Complete(); } return true; } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DAO/PhieuTraSachDAO.cs
C#
asf20
4,594
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DTO; using System.Transactions; using AutoMapper; namespace DAO { public class TheLoaiSachDAO { public static List<TheLoaiSachDTO> DocDanhSach() { //tạo list List<TheLoaiSachDTO> list = new List<TheLoaiSachDTO>(); //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); var ds = from n in context.TheLoaiSaches select n; //duyệt danh sách foreach (TheLoaiSach n in ds) { //mapping từ linQ vào dto TheLoaiSachDTO dto = new TheLoaiSachDTO(); Mapper.CreateMap<TheLoaiSach, TheLoaiSachDTO>(); dto = Mapper.Map<TheLoaiSach, TheLoaiSachDTO>(n); //thêm vào list list.Add(dto); } //trả về kq return list; } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DAO/TheLoaiSachDAO.cs
C#
asf20
1,077
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DAO { public class ChiTietPhieuThanhLyDAO { } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DAO/ChiTietPhieuThanhLyDAO.cs
C#
asf20
171
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DTO; using AutoMapper; namespace DAO { public class LoaiDocGiaDAO { public static List<DTO.LoaiDocGiaDTO> DocDanhSach() { //tạo list List<LoaiDocGiaDTO> list = new List<LoaiDocGiaDTO>(); //khởi tạo datacontext QuanLyThuVienDataContext context = new QuanLyThuVienDataContext(); var ds = from n in context.LoaiDocGias select n; //duyệt danh sách foreach (LoaiDocGia n in ds) { //mapping từ linQ vào dto LoaiDocGiaDTO dto = new LoaiDocGiaDTO(); Mapper.CreateMap<LoaiDocGia, LoaiDocGiaDTO>(); dto = Mapper.Map<LoaiDocGia, LoaiDocGiaDTO>(n); //thêm vào list list.Add(dto); } //trả về kq return list; } } }
1042044-1042122-nmcnpm
trunk/Source/QuanLyThuVien/DAO/LoaiDocGiaDAO.cs
C#
asf20
1,043
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using Coffee_Service_v._2._1.presentation; using Coffee_Service_v._2._1.presentation.other; namespace Coffee_Service_v._2._1 { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); } } }
1259219-git-demo-project
Program.cs
C#
lgpl
611
pushd in cp 17x17_y.bmp 17x17.bmp popd pushd src cp flags_poiseuille_gravity_y.h flags.h popd make ./lb2d_prime ./in/params_poiseuille_gravity_y.in
111pjb-one
poiseuille_gravity_y.sh
Shell
gpl3
148
pushd src cp flags_poiseuille_pressure_y.h flags.h popd make ./lb2d_prime ./in/params_poiseuille_pressure_y.in
111pjb-one
poiseuille_pressure_y.sh
Shell
gpl3
111
################################################################################ # # Copyright (C), 2005, Michael Sukop and Danny Thorne # # Makefile # EXE=lb2d_prime CFLAGS = #CFLAGS+=-g ${EXE}: ./src/*.h ./src/*.c gcc ${CFLAGS} -DOSTYPE=default -o ${EXE} ./src/lb2d_prime.c -lm ostype: ./src/*.h ./src/*.c gcc -DOSTYPE=${OSTYPE} -o ${EXE} ./src/lb2d_prime.c -lm par: ./src/*.h ./src/*.c mpicc -DPARALLEL -o ${EXE} ./src/lb2d_prime.c -lm #mpicc -DPARALLEL -DOSTYPE=${OSTYPE} -o ${EXE} ./src/lb2d_prime.c -L/sw/lib -I/sw/include/ -lmpich -lm swap: ./src/*.h ./src/*.c gcc -DSWAP_BYTE_ORDER -o ${EXE} ./src/lb2d_prime.c -lm swap_byte_order: ./src/*.h ./src/*.c gcc -DSWAP_BYTE_ORDER -o ${EXE} ./src/lb2d_prime.c -lm par_swap: ./src/*.h ./src/*.c gcc -DPARALLEL -DSWAP_BYTE_ORDER -DOSTYPE=${OSTYPE} -o ${EXE} ./src/lb2d_prime.c -L/sw/lib -I/sw/include/ -lmpi -llam -lm warn: ./src/*.h ./src/*.c gcc -pedantic -Wall -Wunused-variable -o ${EXE} ./src/lb2d_prime.c -lm nocygwin: ./src/*.h ./src/*.c gcc -mno-cygwin -o ${EXE} ./src/lb2d_prime.c -lm slice: new_slice.c lbio.c gcc -o slice ./src/new_slice.c -lm spy: ./src/spy.c gcc -o spy ./src/spy.c -lm ascii: ./src/ascii_view_density.c gcc -o ascii_view_density ./src/ascii_view_density.c -lm sweep: /bin/rm -f ./out/*.dat /bin/rm -f ./out/rho*.txt /bin/rm -f ./out/u*.txt /bin/rm -f ./out/force*.txt /bin/rm -f ./out/f*.txt /bin/rm -f ./out/*.txt /bin/rm -f ./out/rho*.bmp /bin/rm -f ./out/ueq*.bmp /bin/rm -f ./out/u*.bmp /bin/rm -f ./out/vor*.bmp /bin/rm -f ./out/force*.bmp /bin/rm -f ./out/sforce*.bmp /bin/rm -f *~ .*.sw* /bin/rm -f ./out/*~ ./out/.*.sw* /bin/rm -f ./in/*~ ./in/.*.sw* /bin/rm -f ./src/*~ ./src/.*.sw* /bin/rm -f ./out/slice*.m /bin/rm -f ./out/new_slice*.m clean: /bin/rm -f ${EXE}.exe slice.exe ${EXE}.exe* *.stackdump dump*.* xclean: /bin/rm -f ${EXE} slice core dump*.*
111pjb-one
Makefile
Makefile
gpl3
1,890
pushd in cp 17x17_x.bmp 17x17.bmp popd pushd src cp flags_poiseuille_gravity_x.h flags.h popd make ./lb2d_prime ./in/params_poiseuille_gravity_x.in
111pjb-one
poiseuille_gravity_x.sh
Shell
gpl3
148
pushd src cp flags_taylor_pressure.h flags.h popd make ./lb2d_prime ./in/params_taylor_pressure.in
111pjb-one
taylor_pressure.sh
Shell
gpl3
99
//############################################################################## // // Copyright (C), 2005, Michael Sukop and Danny Thorne // // collide.c // #if POROUS_MEDIA void collide( lattice_ptr lattice) { double *f; double omega; int *bc_type; int n, a; int subs; double ns; double *ftemp; int i, j; int ip, jp, in, jn; int ni = lattice->param.LX, nj = lattice->param.LY; #if SAY_HI printf("collide() -- Hi!\n"); #endif /* SAY_HI */ for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { //dump_pdf( lattice, 998); f = lattice->pdf[subs][0].f; bc_type = &( lattice->bc[subs][0].bc_type); for( n=0; n<lattice->NumNodes; n++, f+=18, bc_type++) { if( !( *bc_type & BC_SOLID_NODE)) { // if( *bc_type == 0) // { // C O L L I D E for( a=0; a<=8; a++, f++) { // f = f - (1/tau[subs])( ftemp - feq) //printf("collide() -- (Before): n = %2d, a = %d, " // "*f = %10.7f, *(f+9) = %10.7f, *(f-9) = %10.7f\n", // n, a, *(f), *(f+9), *(f-9)); #if 1 *f = *(f+9) - ( ( *(f+9) / lattice->param.tau[subs] ) - ( *(f-9) / lattice->param.tau[subs] ) ); #else *f = *(f+9) - ( ( *(f+9) ) - ( *(f-9) ) ) / lattice->param.tau[subs]; #endif #if 0//PERTURBATIONS //if( n%lattice->NumNodes == n/lattice->NumNodes && a==5) //if( n/lattice->NumNodes == lattice->param.LY/2 && a==1) if( a==1) { //*f+=.0001*(n%lattice->NumNodes)*( rand()/(double)RAND_MAX - .5); *f+=.000001*(n%lattice->NumNodes)*( rand()/(double)RAND_MAX); } #endif /* PERTURBATIONS */ #if PUKE_NEGATIVE_DENSITIES if( *f < 0.) { printf("\n"); printf( "collide() -- Node %d (%d,%d), subs %d, " "has negative density %20.17f " "in direction %d " "at timestep %d. Exiting!\n", n, n%lattice->param.LX, n/lattice->param.LX, subs, *f, a, lattice->time ); printf("\n"); process_exit(1); } #endif /* PUKE_NEGATIVE_DENSITIES */ //printf("collide() -- (After ): n = %2d, a = %d, " // "*f = %10.7f, *(f+9) = %10.7f, *(f-9) = %10.7f\n", // n, a, *(f-1), *(f-1+9), *(f-1-9)); } /* for( a=0; a<=8; a++) */ // } // else // { //printf("collide() -- Skipping bc %d at n = %d\n", *bc_type, n); // *f++ = *( f + 9); // *f++ = *( f + 9); // *f++ = *( f + 9); // *f++ = *( f + 9); // *f++ = *( f + 9); // *f++ = *( f + 9); // *f++ = *( f + 9); // *f++ = *( f + 9); // *f++ = *( f + 9); // } } /* if( !( *bc_type++ & BC_SOLID_NODE)) */ else // *bc_type++ & BC_SOLID_NODE { // B O U N C E B A C K f++; // Skip rest particle. *f++ = *( f + 9 + 2); //f++; // f[1] = ftemp[3] *f++ = *( f + 9 + 2); //f++; // f[2] = ftemp[4] *f++ = *( f + 9 - 2); //f++; // f[3] = ftemp[1] *f++ = *( f + 9 - 2); //f++; // f[4] = ftemp[2] *f++ = *( f + 9 + 2); //f++; // f[5] = ftemp[7] *f++ = *( f + 9 + 2); //f++; // f[6] = ftemp[8] *f++ = *( f + 9 - 2); //f++; // f[7] = ftemp[5] *f++ = *( f + 9 - 2); //f++; // f[8] = ftemp[6] //printf("collide() -- Bncback: n = %2d\n", n); } /* if( !( *bc_type++ & BC_SOLID_NODE)) else */ } /* for( n=0; n<lattice_NumNodes; n++) */ if( subs==0) { // Compute the solid density term for fluid component. ftemp = lattice->pdf[subs][0].ftemp; bc_type = &( lattice->bc[subs][0].bc_type); for( n=0; n<lattice->NumNodes; n++, ftemp+=18, bc_type++) { i = n%ni; j = n/ni; jp = ( j<nj-1)?( j+1):( 0 ); jn = ( j>0 )?( j-1):( nj-1); ip = ( i<ni-1)?( i+1):( 0 ); in = ( i>0 )?( i-1):( ni-1); if( !( *bc_type & BC_SOLID_NODE)) { if( lattice->param.ns >= 0.) { ns = lattice->param.ns; /* 0 */ ftemp++; /* 1 */ *ftemp++ = ns*( lattice->pdf[subs][ j *ni + ip].f[3] - lattice->pdf[subs][ j *ni + i ].f[1]); /* 2 */ *ftemp++ = ns*( lattice->pdf[subs][ jp*ni + i ].f[4] - lattice->pdf[subs][ j *ni + i ].f[2]); /* 3 */ *ftemp++ = ns*( lattice->pdf[subs][ j *ni + in].f[1] - lattice->pdf[subs][ j *ni + i ].f[3]); /* 4 */ *ftemp++ = ns*( lattice->pdf[subs][ jn*ni + i ].f[2] - lattice->pdf[subs][ j *ni + i ].f[4]); /* 5 */ *ftemp++ = ns*( lattice->pdf[subs][ jp*ni + ip].f[7] - lattice->pdf[subs][ j *ni + i ].f[5]); /* 6 */ *ftemp++ = ns*( lattice->pdf[subs][ jp*ni + in].f[8] - lattice->pdf[subs][ j *ni + i ].f[6]); /* 7 */ *ftemp++ = ns*( lattice->pdf[subs][ jn*ni + in].f[5] - lattice->pdf[subs][ j *ni + i ].f[7]); /* 8 */ *ftemp++ = ns*( lattice->pdf[subs][ jn*ni + ip].f[6] - lattice->pdf[subs][ j *ni + i ].f[8]); } else { // TODO: Variable solid density. } } /* if( !( *bc_type++ & BC_SOLID_NODE)) */ else { ftemp+=9; } } /* for( n=0; n<lattice_NumNodes; n++) */ f = lattice->pdf[subs][0].f; bc_type = &( lattice->bc[subs][0].bc_type); for( n=0; n<lattice->NumNodes; n++, f+=18, bc_type++) { if( !( *bc_type & BC_SOLID_NODE)) { f++; for( a=1; a<9; a++, f++) { *f += *(f+9); } /* for( a=1; a<9; a++) */ } else { f+=9; } } /* for( n=0; n<lattice->NumNodes; n++, f+=18) */ } /* if( subs==0) */ //dump_pdf( lattice, 999); } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ #if SAY_HI printf("collide() -- Bye!\n"); #endif /* SAY_HI */ } /* void collide( lattice_ptr lattice) */ #else /* !( POROUS_MEDIA) */ void collide( lattice_ptr lattice) { double *f; double omega; int *bc_type; int n, a; int subs; #if SAY_HI printf("collide() -- Hi!\n"); #endif /* SAY_HI */ for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { //dump_pdf( lattice, 998); f = lattice->pdf[subs][0].f; bc_type = &( lattice->bc[subs][0].bc_type); for( n=0; n<lattice->NumNodes; n++, f+=18, bc_type++) { if( !( *bc_type & BC_SOLID_NODE)) { // if( *bc_type == 0) // { // C O L L I D E for( a=0; a<=8; a++, f++) { // f = f - (1/tau[subs])( ftemp - feq) //printf("collide() -- (Before): n = %2d, a = %d, " // "*f = %10.7f, *(f+9) = %10.7f, *(f-9) = %10.7f\n", // n, a, *(f), *(f+9), *(f-9)); #if 1 *f = *(f+9) - ( ( *(f+9) / lattice->param.tau[subs] ) - ( *(f-9) / lattice->param.tau[subs] ) ); #else *f = *(f+9) - ( ( *(f+9) ) - ( *(f-9) ) ) / lattice->param.tau[subs]; #endif #if 0//PERTURBATIONS //if( n%lattice->NumNodes == n/lattice->NumNodes && a==5) //if( n/lattice->NumNodes == lattice->param.LY/2 && a==1) if( a==1) { //*f+=.0001*(n%lattice->NumNodes)*( rand()/(double)RAND_MAX - .5); *f+=.000001*(n%lattice->NumNodes)*( rand()/(double)RAND_MAX); } #endif /* PERTURBATIONS */ #if PUKE_NEGATIVE_DENSITIES if( *f < 0.) { printf("\n"); printf( "collide() -- Node %d (%d,%d), subs %d, " "has negative density %20.17f " "in direction %d " "at timestep %d. Exiting!\n", n, n%lattice->param.LX, n/lattice->param.LX, subs, *f, a, lattice->time ); printf("\n"); process_exit(1); } #endif /* PUKE_NEGATIVE_DENSITIES */ //printf("collide() -- (After ): n = %2d, a = %d, " // "*f = %10.7f, *(f+9) = %10.7f, *(f-9) = %10.7f\n", // n, a, *(f-1), *(f-1+9), *(f-1-9)); } /* for( a=0; a<=8; a++) */ // } // else // { //printf("collide() -- Skipping bc %d at n = %d\n", *bc_type, n); // *f++ = *( f + 9); // *f++ = *( f + 9); // *f++ = *( f + 9); // *f++ = *( f + 9); // *f++ = *( f + 9); // *f++ = *( f + 9); // *f++ = *( f + 9); // *f++ = *( f + 9); // *f++ = *( f + 9); // } } /* if( !( *bc_type++ & BC_SOLID_NODE)) */ else // *bc_type++ & BC_SOLID_NODE { // B O U N C E B A C K f++; // Skip rest particle. if( lattice->param.bc_slip_north && n >= lattice->NumNodes - lattice->param.LX) { // Slip condition on north boundary. *f++;// = *( f + 9 + 2); //f++; // f[1] = ftemp[3] *f++ = *( f + 9 + 2); //f++; // f[2] = ftemp[4] *f++;// = *( f + 9 - 2); //f++; // f[3] = ftemp[1] *f++ = *( f + 9 - 2); //f++; // f[4] = ftemp[2] *f++ = *( f + 9 + 3); //f++; // f[5] = ftemp[8] *f++ = *( f + 9 + 1); //f++; // f[6] = ftemp[7] *f++ = *( f + 9 - 1); //f++; // f[7] = ftemp[6] *f++ = *( f + 9 - 3); //f++; // f[8] = ftemp[5] } else { // Usual non-slip bounce-back condition. *f++ = *( f + 9 + 2); //f++; // f[1] = ftemp[3] *f++ = *( f + 9 + 2); //f++; // f[2] = ftemp[4] *f++ = *( f + 9 - 2); //f++; // f[3] = ftemp[1] *f++ = *( f + 9 - 2); //f++; // f[4] = ftemp[2] *f++ = *( f + 9 + 2); //f++; // f[5] = ftemp[7] *f++ = *( f + 9 + 2); //f++; // f[6] = ftemp[8] *f++ = *( f + 9 - 2); //f++; // f[7] = ftemp[5] *f++ = *( f + 9 - 2); //f++; // f[8] = ftemp[6] } #if 0 // C O L L I D E f-=9; for( a=0; a<=8; a++, f++) { // f = f - (1/tau[subs])( ftemp - feq) //printf("collide() -- (Before): n = %2d, a = %d, " // "*f = %10.7f, *(f+9) = %10.7f, *(f-9) = %10.7f\n", // n, a, *(f), *(f+9), *(f-9)); #if 1 *f = *(f+9) - ( ( *(f+9) / lattice->param.tau[subs] ) - ( *(f-9) / lattice->param.tau[subs] ) ); #else *f = *(f+9) - ( ( *(f+9) ) - ( *(f-9) ) ) / lattice->param.tau[subs]; #endif #if 0//PERTURBATIONS //if( n%lattice->NumNodes == n/lattice->NumNodes && a==5) //if( n/lattice->NumNodes == lattice->param.LY/2 && a==1) if( a==1) { //*f+=.0001*(n%lattice->NumNodes)*( rand()/(double)RAND_MAX - .5); *f+=.000001*(n%lattice->NumNodes)*( rand()/(double)RAND_MAX); } #endif /* PERTURBATIONS */ #if PUKE_NEGATIVE_DENSITIES if( *f < 0.) { printf("\n"); printf( "collide() -- Node %d (%d,%d), subs %d, " "has negative density %20.17f " "in direction %d " "at timestep %d. Exiting!\n", n, n%lattice->param.LX, n/lattice->param.LX, subs, *f, a, lattice->time ); printf("\n"); process_exit(1); } #endif /* PUKE_NEGATIVE_DENSITIES */ //printf("collide() -- (After ): n = %2d, a = %d, " // "*f = %10.7f, *(f+9) = %10.7f, *(f-9) = %10.7f\n", // n, a, *(f-1), *(f-1+9), *(f-1-9)); } /* for( a=0; a<=8; a++) */ #endif //printf("collide() -- Bncback: n = %2d\n", n); } /* if( !( *bc_type++ & BC_SOLID_NODE)) else */ } /* for( n=0; n<lattice_NumNodes; n++) */ //dump_pdf( lattice, 999); } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ #if SAY_HI printf("collide() -- Bye!\n"); #endif /* SAY_HI */ } /* void collide( lattice_ptr lattice) */ #endif /* POROUS_MEDIA */
111pjb-one
src/collide_bak.c
C
gpl3
11,883
void collide( lattice_ptr lattice) { double *feq; double *f; double *ftemp; #if ZHANG_AND_CHEN_ENERGY_TRANSPORT double *force; #endif /* ZHANG_AND_CHEN_ENERGY_TRANSPORT */ double omega; int bc_type; int n, a; int subs; #if SAY_HI printf("collide() -- Hi!\n"); #endif /* SAY_HI */ for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { for( n=0; n<lattice->NumNodes; n++) { feq = lattice->pdf[subs][n].feq; f = lattice->pdf[subs][n].f; ftemp = lattice->pdf[subs][n].ftemp; bc_type = lattice->bc[subs][n].bc_type; #if ZHANG_AND_CHEN_ENERGY_TRANSPORT force = lattice->force[subs][n].force; #endif /* ZHANG_AND_CHEN_ENERGY_TRANSPORT */ #if INAMURO_SIGMA_COMPONENT if( ( get_bc_sigma_walls(lattice) && subs==1) || !( bc_type & BC_SOLID_NODE)) #else /* !(INAMURO_SIGMA_COMPONENT) */ if( !( bc_type & BC_SOLID_NODE)) #endif /* (INAMURO_SIGMA_COMPONENT) */ { // C O L L I D E // f = ftemp - (1/tau[subs])( ftemp - feq) for( a=0; a<=8; a++) { #if 1 f[a] = ftemp[a] - ( ( ftemp[a] / lattice->param.tau[subs] ) - ( feq[a] / lattice->param.tau[subs] ) ); #else f[a] = ftemp[a] - ( ( ftemp[a] ) - ( feq[a] ) ) / lattice->param.tau[subs]; #endif } /* for( a=0; a<=8; a++) */ #if ZHANG_AND_CHEN_ENERGY_TRANSPORT if( subs==0) { // // Add the body force term, equation (8), // // f_i = f_i + \Delta f_i // // = f_i + \frac{w_i}{T_0} c_i \dot F // // Assuming the weights, w_i, are the ones from compute_feq. // // Zhang & Chen state T_0 to be 1/3 for D3Q19. The same in D2Q9. // f[1] += .00032*(vx[1]*3.*2.*force[0]); f[2] += .00032*(vy[2]*3.*2.*force[1]); f[3] += .00032*(vx[3]*3.*2.*force[0]); f[4] += .00032*(vy[4]*3.*2.*force[1]); f[5] += .00032*( 3.*( vx[5]*force[0] + vy[5]*force[1])); f[6] += .00032*( 3.*( vx[6]*force[0] + vy[6]*force[1])); f[7] += .00032*( 3.*( vx[7]*force[0] + vy[7]*force[1])); f[8] += .00032*( 3.*( vx[8]*force[0] + vy[8]*force[1])); } #endif /* ZHANG_AND_CHEN_ENERGY_TRANSPORT */ #if PUKE_NEGATIVE_DENSITIES for( a=0; a<=8; a++) { if( *f < 0.) { printf("\n"); printf( "collide() -- Node %d (%d,%d), subs %d, " "has negative density %20.17f " "in direction %d " "at timestep %d. Exiting!\n", n, n%lattice->param.LX, n/lattice->param.LX, subs, f[a], a, lattice->time ); printf("\n"); process_exit(1); } } /* for( a=0; a<=8; a++) */ #endif /* PUKE_NEGATIVE_DENSITIES */ } /* if( !( bc_type & BC_SOLID_NODE)) */ else // bc_type & BC_SOLID_NODE { // B O U N C E B A C K if( lattice->param.bc_slip_north && n >= lattice->NumNodes - lattice->param.LX) { // Slip condition on north boundary. /* // A B C // \|/ \|/ // D-o-E --> D-o-E // /|\ /|\ // A B C */ f[1] = ftemp[1]; f[2] = ftemp[4]; f[3] = ftemp[3]; f[4] = ftemp[2]; f[5] = ftemp[8]; f[6] = ftemp[7]; f[7] = ftemp[6]; f[8] = ftemp[5]; } /* if( lattice->param.bc_slip_north && ... ) */ else { if( subs==0) { // Usual non-slip bounce-back condition. /* // A B C H G F // \|/ \|/ // D-o-E --> E-o-D // /|\ /|\ // F G H C B A */ f[1] = ftemp[3]; f[2] = ftemp[4]; f[3] = ftemp[1]; f[4] = ftemp[2]; f[5] = ftemp[7]; f[6] = ftemp[8]; f[7] = ftemp[5]; f[8] = ftemp[6]; } /* if( subs==0) */ #if NUM_FLUID_COMPONENTS==2 else // subs==1 { #if INAMURO_SIGMA_COMPONENT if( lattice->param.bc_sigma_slip) { // // Slip BC for solute on side walls. // Will this make a difference on Taylor dispersion? // if( lattice->FlowDir == /*Vertical*/2) { if( /*west*/(n )%lattice->param.LX == 0 || /*east*/(n+1)%lattice->param.LX == 0) { // Slip condition on east/west boundary. /* // A B C C B A // \|/ \|/ // D-o-E --> E-o-D // /|\ /|\ // F G H H G F */ f[1] = ftemp[3]; f[2] = ftemp[2]; f[3] = ftemp[1]; f[4] = ftemp[4]; f[5] = ftemp[6]; f[6] = ftemp[5]; f[7] = ftemp[8]; f[8] = ftemp[7]; } } else if( lattice->FlowDir == /*Horizontal*/1) { if( /*north*/ n >= lattice->NumNodes - lattice->param.LX || /*south*/ n < lattice->param.LX ) { // Slip condition on north/south boundary. /* // A B C F G H // \|/ \|/ // D-o-E --> D-o-E // /|\ /|\ // F G H A B C */ f[1] = ftemp[1]; f[2] = ftemp[4]; f[3] = ftemp[3]; f[4] = ftemp[2]; f[5] = ftemp[8]; f[6] = ftemp[7]; f[7] = ftemp[6]; f[8] = ftemp[5]; } else { // ERROR: Solid exists somewhere other than as side walls. printf("%s (%d) >> " "ERROR: " "bc_sigma_slip is on. " "FlowDir is determined to be horizontal. " "Encountered solid node somewhere other than side walls. " "That situation is not supported. " "Exiting!", __FILE__, __LINE__); process_exit(1); } } else { printf("%s (%d) >> " "FlowDir is indeterminate. " "Cannot apply slip BC (bc_sigma_slip). " "Exiting!", __FILE__, __LINE__); process_exit(1); } } /* if( lattice->param.bc_sigma_slip) */ else { #endif /* INAMURO_SIGMA_COMPONENT */ // Usual non-slip bounce-back condition. /* // A B C H G F // \|/ \|/ // D-o-E --> E-o-D // /|\ /|\ // F G H C B A */ f[1] = ftemp[3]; f[2] = ftemp[4]; f[3] = ftemp[1]; f[4] = ftemp[2]; f[5] = ftemp[7]; f[6] = ftemp[8]; f[7] = ftemp[5]; f[8] = ftemp[6]; #if INAMURO_SIGMA_COMPONENT } /* if( lattice->param.bc_sigma_slip) else */ #endif /* INAMURO_SIGMA_COMPONENT */ } /* if( subs==0) else*/ #endif /* NUM_FLUID_COMPONENTS==2 */ } /* if( lattice->param.bc_slip_north && ... ) else */ } /* if( !( bc_type & BC_SOLID_NODE)) else */ } /* for( n=0; n<lattice_NumNodes; n++) */ } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ #if SAY_HI printf("collide() -- Bye!\n"); #endif /* SAY_HI */ } /* void collide( lattice_ptr lattice) */
111pjb-one
src/b.c
C
gpl3
8,004
//############################################################################## // // Copyright (C), 2005, Michael Sukop and Danny Thorne // // collide.c // #if 0//POROUS_MEDIA //############################################################################## // // void collide( lattice_ptr lattice) // void collide( lattice_ptr lattice) { double *f; double omega; int bc_type; int n, a; int subs; double ns; double *ftemp, *feq; double *nsterm; int i, j; int ip, jp, in, jn; int LX = lattice->param.LX, LY = lattice->param.LY; #if SAY_HI printf("collide() -- Hi!\n"); #endif /* SAY_HI */ for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { for( n=0; n<lattice->NumNodes; n++) { feq = lattice->pdf[subs][n].feq; f = lattice->pdf[subs][n].f; ftemp = lattice->pdf[subs][n].ftemp; bc_type = lattice->bc[subs][n].bc_type; #if ZHANG_AND_CHEN_ENERGY_TRANSPORT force = lattice->force[subs][n].force; #endif /* ZHANG_AND_CHEN_ENERGY_TRANSPORT */ if( !( bc_type & BC_SOLID_NODE)) { // C O L L I D E // f = ftemp - (1/tau[subs])( ftemp - feq) for( a=0; a<=8; a++) { #if 1 f[a] = ftemp[a] - ( ( ftemp[a] / lattice->param.tau[subs] ) - ( feq[a] / lattice->param.tau[subs] ) ); #else f[a] = ftemp[a] - ( ( ftemp[a] ) - ( feq[a] ) ) / lattice->param.tau[subs]; #endif } /* for( a=0; a<=8; a++) */ #if ZHANG_AND_CHEN_ENERGY_TRANSPORT if( subs==0) { // // Add the body force term, equation (8), // // f_i = f_i + \Delta f_i // // = f_i + \frac{w_i}{T_0} c_i \dot F // // Assuming the weights, w_i, are the ones from compute_feq. // // Zhang & Chen state T_0 to be 1/3 for D3Q19. The same in D2Q9. // f[1] += .00032*(vx[1]*3.*2.*force[0]); f[2] += .00032*(vy[2]*3.*2.*force[1]); f[3] += .00032*(vx[3]*3.*2.*force[0]); f[4] += .00032*(vy[4]*3.*2.*force[1]); f[5] += .00032*( 3.*( vx[5]*force[0] + vy[5]*force[1])); f[6] += .00032*( 3.*( vx[6]*force[0] + vy[6]*force[1])); f[7] += .00032*( 3.*( vx[7]*force[0] + vy[7]*force[1])); f[8] += .00032*( 3.*( vx[8]*force[0] + vy[8]*force[1])); } #endif /* ZHANG_AND_CHEN_ENERGY_TRANSPORT */ #if PUKE_NEGATIVE_DENSITIES for( a=0; a<=8; a++) { if( *f < 0.) { printf("\n"); printf( "collide() -- Node %d (%d,%d), subs %d, " "has negative density %20.17f " "in direction %d " "at timestep %d. Exiting!\n", n, n%lattice->param.LX, n/lattice->param.LX, subs, f[a], a, lattice->time ); printf("\n"); process_exit(1); } } /* for( a=0; a<=8; a++) */ #endif /* PUKE_NEGATIVE_DENSITIES */ } /* if( !( bc_type & BC_SOLID_NODE)) */ else // bc_type & BC_SOLID_NODE { // B O U N C E B A C K if( lattice->param.bc_slip_north && n >= lattice->NumNodes - lattice->param.LX) { // Slip condition on north boundary. /* // A B C // \|/ \|/ // D-o-E --> D-o-E // /|\ /|\ // A B C */ f[1] = ftemp[1]; f[2] = ftemp[4]; f[3] = ftemp[3]; f[4] = ftemp[2]; f[5] = ftemp[8]; f[6] = ftemp[7]; f[7] = ftemp[6]; f[8] = ftemp[5]; } /* if( lattice->param.bc_slip_north && ... ) */ else { if( subs==0) { // Usual non-slip bounce-back condition. /* // A B C H G F // \|/ \|/ // D-o-E --> E-o-D // /|\ /|\ // F G H C B A */ f[1] = ftemp[3]; f[2] = ftemp[4]; f[3] = ftemp[1]; f[4] = ftemp[2]; f[5] = ftemp[7]; f[6] = ftemp[8]; f[7] = ftemp[5]; f[8] = ftemp[6]; } /* if( subs==0) */ #if NUM_FLUID_COMPONENTS==2 else // subs==1 { #if INAMURO_SIGMA_COMPONENT if( lattice->param.bc_sigma_slip) { // // Slip BC for solute on side walls. // Will this make a difference on Taylor dispersion? // if( lattice->FlowDir == /*Vertical*/2) { if( /*west*/(n )%lattice->param.LX == 0 || /*east*/(n+1)%lattice->param.LX == 0) { // Slip condition on east/west boundary. /* // A B C C B A // \|/ \|/ // D-o-E --> E-o-D // /|\ /|\ // F G H H G F */ f[1] = ftemp[3]; f[2] = ftemp[2]; f[3] = ftemp[1]; f[4] = ftemp[4]; f[5] = ftemp[6]; f[6] = ftemp[5]; f[7] = ftemp[8]; f[8] = ftemp[7]; } } else if( lattice->FlowDir == /*Horizontal*/1) { if( /*north*/ n >= lattice->NumNodes - lattice->param.LX || /*south*/ n < lattice->param.LX ) { // Slip condition on north/south boundary. /* // A B C F G H // \|/ \|/ // D-o-E --> D-o-E // /|\ /|\ // F G H A B C */ f[1] = ftemp[1]; f[2] = ftemp[4]; f[3] = ftemp[3]; f[4] = ftemp[2]; f[5] = ftemp[8]; f[6] = ftemp[7]; f[7] = ftemp[6]; f[8] = ftemp[5]; } else { // ERROR: Solid exists somewhere other than as side walls. printf("%s (%d) >> " "ERROR: " "bc_sigma_slip is on. " "FlowDir is determined to be horizontal. " "Encountered solid node somewhere other than side walls. " "That situation is not supported. " "Exiting!", __FILE__, __LINE__); process_exit(1); } } else { printf("%s (%d) >> " "FlowDir is indeterminate. " "Cannot apply slip BC (bc_sigma_slip). " "Exiting!", __FILE__, __LINE__); process_exit(1); } } /* if( lattice->param.bc_sigma_slip) */ else { #endif /* INAMURO_SIGMA_COMPONENT */ // Usual non-slip bounce-back condition. /* // A B C H G F // \|/ \|/ // D-o-E --> E-o-D // /|\ /|\ // F G H C B A */ f[1] = ftemp[3]; f[2] = ftemp[4]; f[3] = ftemp[1]; f[4] = ftemp[2]; f[5] = ftemp[7]; f[6] = ftemp[8]; f[7] = ftemp[5]; f[8] = ftemp[6]; #if INAMURO_SIGMA_COMPONENT } /* if( lattice->param.bc_sigma_slip) else */ #endif /* INAMURO_SIGMA_COMPONENT */ } /* if( subs==0) else*/ #endif /* NUM_FLUID_COMPONENTS==2 */ } /* if( lattice->param.bc_slip_north && ... ) else */ } /* if( !( bc_type & BC_SOLID_NODE)) else */ } /* for( n=0; n<lattice_NumNodes; n++) */ if( INAMURO_SIGMA_COMPONENT!=0 || subs==0) { // Need separate temp space for this? nsterm = (double*)malloc( 9*lattice->NumNodes*sizeof(double)); // Compute the solid density term for fluid component. for( n=0; n<lattice->NumNodes; n++) { bc_type = lattice->bc [subs][n].bc_type; i = n%LX; j = n/LX; jp = ( j<LY-1)?( j+1):( 0 ); jn = ( j>0 )?( j-1):( LY-1); ip = ( i<LX-1)?( i+1):( 0 ); in = ( i>0 )?( i-1):( LX-1); if( !( bc_type & BC_SOLID_NODE)) { if( lattice->param.ns_flag == 0) { ns = lattice->param.ns; /* 1 */ nsterm[9*n+1] = ns*( lattice->pdf[subs][ j *LX + ip].f[3] - lattice->pdf[subs][ j *LX + i ].f[1]); /* 2 */ nsterm[9*n+2] = ns*( lattice->pdf[subs][ jp*LX + i ].f[4] - lattice->pdf[subs][ j *LX + i ].f[2]); /* 3 */ nsterm[9*n+3] = ns*( lattice->pdf[subs][ j *LX + in].f[1] - lattice->pdf[subs][ j *LX + i ].f[3]); /* 4 */ nsterm[9*n+4] = ns*( lattice->pdf[subs][ jn*LX + i ].f[2] - lattice->pdf[subs][ j *LX + i ].f[4]); /* 5 */ nsterm[9*n+5] = ns*( lattice->pdf[subs][ jp*LX + ip].f[7] - lattice->pdf[subs][ j *LX + i ].f[5]); /* 6 */ nsterm[9*n+6] = ns*( lattice->pdf[subs][ jp*LX + in].f[8] - lattice->pdf[subs][ j *LX + i ].f[6]); /* 7 */ nsterm[9*n+7] = ns*( lattice->pdf[subs][ jn*LX + in].f[5] - lattice->pdf[subs][ j *LX + i ].f[7]); /* 8 */ nsterm[9*n+8] = ns*( lattice->pdf[subs][ jn*LX + ip].f[6] - lattice->pdf[subs][ j *LX + i ].f[8]); } else /* ns_flag==1 || ns_flag==2 */ { // Variable solid density. ns = lattice->ns[n].ns; //printf("%s %d >> ns = %f\n",__FILE__,__LINE__,ns); /* 1 */ nsterm[9*n+1] = ns*( lattice->pdf[subs][ j *LX + ip].f[3] - lattice->pdf[subs][ j *LX + i ].f[1]); /* 2 */ nsterm[9*n+2] = ns*( lattice->pdf[subs][ jp*LX + i ].f[4] - lattice->pdf[subs][ j *LX + i ].f[2]); /* 3 */ nsterm[9*n+3] = ns*( lattice->pdf[subs][ j *LX + in].f[1] - lattice->pdf[subs][ j *LX + i ].f[3]); /* 4 */ nsterm[9*n+4] = ns*( lattice->pdf[subs][ jn*LX + i ].f[2] - lattice->pdf[subs][ j *LX + i ].f[4]); /* 5 */ nsterm[9*n+5] = ns*( lattice->pdf[subs][ jp*LX + ip].f[7] - lattice->pdf[subs][ j *LX + i ].f[5]); /* 6 */ nsterm[9*n+6] = ns*( lattice->pdf[subs][ jp*LX + in].f[8] - lattice->pdf[subs][ j *LX + i ].f[6]); /* 7 */ nsterm[9*n+7] = ns*( lattice->pdf[subs][ jn*LX + in].f[5] - lattice->pdf[subs][ j *LX + i ].f[7]); /* 8 */ nsterm[9*n+8] = ns*( lattice->pdf[subs][ jn*LX + ip].f[6] - lattice->pdf[subs][ j *LX + i ].f[8]); } } /* if( !( *bc_type++ & BC_SOLID_NODE)) */ } /* for( n=0; n<lattice_NumNodes; n++) */ for( n=0; n<lattice->NumNodes; n++) { f = lattice->pdf[subs][n].f; bc_type = lattice->bc [subs][n].bc_type; if( !( bc_type & BC_SOLID_NODE)) { for( a=1; a<9; a++) { // Store f in ftemp, because the compute_macro vars before // output_frames needs to have the pre-ns version of f. if( is_last_step_of_frame(lattice)) { // This temp copy of f in ftemp prior to application // of ns only needs to be done before outputting a frame, // not after each timestep. lattice->pdf[subs][n].ftemp[a] = f[a]; } f[a] += nsterm[9*n+a]; } /* for( a=1; a<9; a++) */ } /* if( !( bc_type & BC_SOLID_NODE)) */ } /* for( n=0; n<lattice->NumNodes; n++, f+=18) */ free( nsterm); } /* if( INAMURO_SIGMA_COMPONENT!=0 || subs==0) */ } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ #if SAY_HI printf("collide() -- Bye!\n"); #endif /* SAY_HI */ } /* void collide( lattice_ptr lattice) */ #else /* !( POROUS_MEDIA) */ //############################################################################## // // void collide( lattice_ptr lattice) // void collide( lattice_ptr lattice) { double *feq; double *f; double *ftemp; #if ZHANG_AND_CHEN_ENERGY_TRANSPORT double *force; #endif /* ZHANG_AND_CHEN_ENERGY_TRANSPORT */ double omega; int bc_type; int n, a; int subs; int i, j; #if POROUS_MEDIA double ns; double *nsterm; int ip, jp, in, jn; int LX = lattice->param.LX, LY = lattice->param.LY; #endif #if GUO_ZHENG_SHI_BODY_FORCE double Fx, Fy, F; double vx, vy; double ex, ey, edotv; double rho; #if INAMURO_SIGMA_COMPONENT double conc; #endif #endif double rho_diff; #if SAY_HI printf("collide() -- Hi!\n"); #endif /* SAY_HI */ for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { #if SIGMA_BULK_FLAG if(subs == 0 || lattice->time > lattice->param.sigma_bulk_on) { #endif #if INAMURO_SIGMA_COMPONENT if( subs==1) { compute_macro_vars( lattice, 2); compute_feq( lattice, 0); } #endif for( n=0; n<lattice->NumNodes; n++) { i = N2I(n); j = N2J(n); feq = lattice->pdf[subs][n].feq; f = lattice->pdf[subs][n].f; ftemp = lattice->pdf[subs][n].ftemp; bc_type = lattice->bc[subs][n].bc_type; #if ZHANG_AND_CHEN_ENERGY_TRANSPORT force = lattice->force[subs][n].force; #endif /* ZHANG_AND_CHEN_ENERGY_TRANSPORT */ #if INAMURO_SIGMA_COMPONENT if( ( bc_sigma_walls(lattice) && subs==1) || is_not_solid_node( lattice, subs, n) #if 1 || ( subs==1 && ( i==0 || i==get_LX(lattice)-1) && ( j==0 || j==get_LY(lattice)-1) ) #endif ) #else /* !(INAMURO_SIGMA_COMPONENT) */ if( is_not_solid_node( lattice, subs, n)) #endif /* (INAMURO_SIGMA_COMPONENT) */ { // C O L L I D E #if 0//INAMURO_SIGMA_COMPONENT // Testing alternative way of applying body force... if( subs==0) { feq[4] += -(1./3.)*lattice->param.gval[0][1] * (lattice->macro_vars[1][n].rho) ; } #endif // f = ftemp - (1/tau[subs])( ftemp - feq) for( a=0; a<=8; a++) { #if TAU_ZHANG_ANISOTROPIC_DISPERSION if( subs==1 && ns > 1e-12) { f[a] = ftemp[a] - ( ( ftemp[a] / lattice->tau_zhang[a] ) - ( feq[a] / lattice->tau_zhang[a] ) ); } else { f[a] = ftemp[a] - ( ( ftemp[a] / lattice->param.tau[subs] ) - ( feq[a] / lattice->param.tau[subs] ) ); } #else f[a] = ftemp[a] - ( ( ftemp[a] / lattice->param.tau[subs] ) - ( feq[a] / lattice->param.tau[subs] ) ); //f[a] = ftemp[a] - ( ( ftemp[a] ) // - ( feq[a] ) ) / lattice->param.tau[subs]; #endif } /* for( a=0; a<=8; a++) */ #if GUO_ZHENG_SHI_BODY_FORCE if( subs==0) { // Guo, Zheng & Shi: PRE 65 2002 // Equations (4), (19) & (20) #if INAMURO_SIGMA_COMPONENT //conc = lattice->pdf[/*sigma*/ 1 ][n].ftemp[0] // + lattice->pdf[/*sigma*/ 1 ][n].ftemp[1] // + lattice->pdf[/*sigma*/ 1 ][n].ftemp[2] // + lattice->pdf[/*sigma*/ 1 ][n].ftemp[3] // + lattice->pdf[/*sigma*/ 1 ][n].ftemp[4] // + lattice->pdf[/*sigma*/ 1 ][n].ftemp[5] // + lattice->pdf[/*sigma*/ 1 ][n].ftemp[6] // + lattice->pdf[/*sigma*/ 1 ][n].ftemp[7] // + lattice->pdf[/*sigma*/ 1 ][n].ftemp[8] // + lattice->pdf[/*sigma*/ 1 ][n].ftemp[9]; conc = lattice->macro_vars[1][n].rho; #endif rho = f[0] + f[1] + f[2] + f[3] + f[4] + f[5] + f[6] + f[7] + f[8]; Fx = lattice->param.gval[subs][0]*rho #if INAMURO_SIGMA_COMPONENT *( 1. + ( get_buoyancy(lattice)) *( get_beta(lattice)) *( (conc) - get_C0(lattice))) #endif ; Fy = lattice->param.gval[subs][1]*rho #if INAMURO_SIGMA_COMPONENT *( 1. + ( get_buoyancy(lattice)) *( get_beta(lattice)) *( (conc) - get_C0(lattice))) #endif ; vx = ( 1.*f[1] - 1.*f[3] + 1.*f[5] - 1.*f[6] - 1.*f[7] + 1.*f[8] + .5*Fx ) / rho; vy = ( 1.*f[2] - 1.*f[4] + 1.*f[5] + 1.*f[6] - 1.*f[7] - 1.*f[8] + .5*Fy ) / rho; // Major directions --------------------------------------------------- a = 3.*(1.-1./(2.*get_tau(lattice,0)))*WM; /* e=( 1, 0) */ ex = 1.; ey = 0.; edotv = ex*vx + ey*vy; F = a*( ( (ex-vx) + 3.*(edotv)*ex)*Fx + ( (ey-vy) + 3.*(edotv)*ey)*Fy); f[1] += F; /* e=( 0, 1) */ ex = 0.; ey = 1.; edotv = ex*vx + ey*vy; F = a*( ( (ex-vx) + 3.*(edotv)*ex)*Fx + ( (ey-vy) + 3.*(edotv)*ey)*Fy); f[2] += F; /* e=(-1, 0) */ ex =-1.; ey = 0.; edotv = ex*vx + ey*vy; F = a*( ( (ex-vx) + 3.*(edotv)*ex)*Fx + ( (ey-vy) + 3.*(edotv)*ey)*Fy); f[3] += F; /* e=( 0,-1) */ ex = 0.; ey =-1.; edotv = ex*vx + ey*vy; F = a*( ( (ex-vx) + 3.*(edotv)*ex)*Fx + ( (ey-vy) + 3.*(edotv)*ey)*Fy); f[4] += F; // Diagonal directions ------------------------------------------------ a = 3.*(1.-1./(2.*get_tau(lattice,0)))*WD; /* e=( 1, 1) */ ex = 1.; ey = 1.; edotv = ex*vx + ey*vy; F = a*( ( (ex-vx) + 3.*(edotv)*ex)*Fx + ( (ey-vy) + 3.*(edotv)*ey)*Fy); f[5] += F; /* e=(-1, 1) */ ex =-1.; ey = 1.; edotv = ex*vx + ey*vy; F = a*( ( (ex-vx) + 3.*(edotv)*ex)*Fx + ( (ey-vy) + 3.*(edotv)*ey)*Fy); f[6] += F; /* e=(-1,-1) */ ex =-1.; ey =-1.; edotv = ex*vx + ey*vy; F = a*( ( (ex-vx) + 3.*(edotv)*ex)*Fx + ( (ey-vy) + 3.*(edotv)*ey)*Fy); f[7] += F; /* e=( 1,-1) */ ex = 1.; ey =-1.; edotv = ex*vx + ey*vy; F = a*( ( (ex-vx) + 3.*(edotv)*ex)*Fx + ( (ey-vy) + 3.*(edotv)*ey)*Fy); f[8] += F; } #endif #if ZHANG_AND_CHEN_ENERGY_TRANSPORT if( subs==0) { // // Add the body force term, equation (8), // // f_i = f_i + \Delta f_i // // = f_i + \frac{w_i}{T_0} c_i \dot F // // Assuming the weights, w_i, are the ones from compute_feq. // // Zhang & Chen state T_0 to be 1/3 for D3Q19. The same in D2Q9. // f[1] += .00032*(vx[1]*3.*2.*force[0]); f[2] += .00032*(vy[2]*3.*2.*force[1]); f[3] += .00032*(vx[3]*3.*2.*force[0]); f[4] += .00032*(vy[4]*3.*2.*force[1]); f[5] += .00032*( 3.*( vx[5]*force[0] + vy[5]*force[1])); f[6] += .00032*( 3.*( vx[6]*force[0] + vy[6]*force[1])); f[7] += .00032*( 3.*( vx[7]*force[0] + vy[7]*force[1])); f[8] += .00032*( 3.*( vx[8]*force[0] + vy[8]*force[1])); } #endif /* ZHANG_AND_CHEN_ENERGY_TRANSPORT */ #if PUKE_NEGATIVE_DENSITIES for( a=0; a<=8; a++) { if( *f < 0.) { printf("\n"); printf( "collide() -- Node %d (%d,%d), subs %d, " "has negative density %20.17f " "in direction %d " "at timestep %d. Exiting!\n", n, n%lattice->param.LX, n/lattice->param.LX, subs, f[a], a, lattice->time ); printf("\n"); process_exit(1); } } /* for( a=0; a<=8; a++) */ #endif /* PUKE_NEGATIVE_DENSITIES */ } /* if( !( bc_type & BC_SOLID_NODE)) */ else // bc_type & BC_SOLID_NODE { // B O U N C E B A C K if( lattice->param.bc_slip_north && ( n >= lattice->NumNodes - lattice->param.LX ||n < get_LX(lattice) )) { // Slip condition on north boundary. /* // A B C // \|/ \|/ // D-o-E --> D-o-E // /|\ /|\ // A B C */ f[1] = ftemp[1]; f[2] = ftemp[4]; f[3] = ftemp[3]; f[4] = ftemp[2]; f[5] = ftemp[8]; f[6] = ftemp[7]; f[7] = ftemp[6]; f[8] = ftemp[5]; } /* if( lattice->param.bc_slip_north && ... ) */ else { if( subs==0) { #define APPLY_DEL_FEQ 0 #define APPLY_DEL_FEQ_HIGH_ORDER 0 // Usual non-slip bounce-back condition. /* // A B C H G F // \|/ \|/ // D-o-E --> E-o-D // /|\ /|\ // F G H C B A */ #if !( APPLY_DEL_FEQ || APPLY_DEL_FEQ_HIGH_ORDER) #if 1 #if 1 f[1] = ftemp[3]; f[2] = ftemp[4]; f[3] = ftemp[1]; f[4] = ftemp[2]; f[5] = ftemp[7]; f[6] = ftemp[8]; f[7] = ftemp[5]; f[8] = ftemp[6]; #else // Try doing regular collision on the solid before applying // bounce-back double ftemptemp[9]; for( a=1; a<9; a++) { ftemptemp[a] = ftemp[a] - ( ( ftemp[a] / get_tau(lattice,subs) ) - ( feq[a] / get_tau(lattice,subs) ) ); } f[1] = ftemptemp[3]; f[2] = ftemptemp[4]; f[3] = ftemptemp[1]; f[4] = ftemptemp[2]; f[5] = ftemptemp[7]; f[6] = ftemptemp[8]; f[7] = ftemptemp[5]; f[8] = ftemptemp[6]; #endif #else // Experimenting: Trying to compensate for loss of mass into // the solid nodes. compute_ave_rho( lattice, &rho_diff, 0); rho_diff -= lattice->param.rho_A[0]; if( j==0) { f[1] = ( ftemp[3]); f[2] = ( ftemp[4] - .50*rho_diff/2./get_LX(lattice)); f[3] = ( ftemp[1]); f[4] = ( ftemp[2]); f[5] = ( ftemp[7] - .25*rho_diff/2./get_LX(lattice)); f[6] = ( ftemp[8] - .25*rho_diff/2./get_LX(lattice)); f[7] = ( ftemp[5]); f[8] = ( ftemp[6]); } else if( j==get_LY(lattice)-1) { f[1] = ( ftemp[3]); f[2] = ( ftemp[4]); f[3] = ( ftemp[1]); f[4] = ( ftemp[2] - .50*rho_diff/2./get_LX(lattice)); f[5] = ( ftemp[7]); f[6] = ( ftemp[8]); f[7] = ( ftemp[5] - .25*rho_diff/2./get_LX(lattice)); f[8] = ( ftemp[6] - .25*rho_diff/2./get_LX(lattice)); } else { printf("ERROR: Experimental bounceback only works on top and " "bottom of domain."); process_exit(1); } #endif #else f[1] = ftemp[3]; f[2] = #if APPLY_DEL_FEQ #if 1 ftemp[4] - (1./2.) #else ( .25 *lattice->param.gval[subs][1] + .25 *lattice->param.gval[subs][1] *lattice->param.gval[subs][1] ) + (1.)//2.) #endif * ( (-1.) *lattice->param.gval[subs][1] #if APPLY_DEL_FEQ_HIGH_ORDER + (1.) *lattice->param.gval[subs][1] *lattice->param.gval[subs][1] #endif ) #else ftemp[4] #endif ; f[3] = ftemp[1]; f[4] = ftemp[2] #if APPLY_DEL_FEQ - (1./2.) * ( (1.) *lattice->param.gval[subs][1] #if APPLY_DEL_FEQ_HIGH_ORDER + (1.) *lattice->param.gval[subs][1] *lattice->param.gval[subs][1] #endif ) #endif ; f[5] = ftemp[7] #if APPLY_DEL_FEQ - (1./2.) * ( (-1./12.) *lattice->param.gval[subs][1] #if APPLY_DEL_FEQ_HIGH_ORDER + (1./8.) *lattice->param.gval[subs][1] *lattice->param.gval[subs][1] + (-1./24.) *lattice->param.gval[subs][1] *lattice->param.gval[subs][1] *lattice->param.gval[subs][1] *lattice->param.gval[subs][1] #endif ) #endif ; f[6] = ftemp[8] #if APPLY_DEL_FEQ - (1./2.) * ( (-1./12.) *lattice->param.gval[subs][1] #if APPLY_DEL_FEQ_HIGH_ORDER + (1./8.) *lattice->param.gval[subs][1] *lattice->param.gval[subs][1] + (-1./24.) *lattice->param.gval[subs][1] *lattice->param.gval[subs][1] *lattice->param.gval[subs][1] *lattice->param.gval[subs][1] #endif ) #endif ; f[7] = ftemp[5] #if APPLY_DEL_FEQ - (1./2.) * ( (1./12.) *lattice->param.gval[subs][1] #if APPLY_DEL_FEQ_HIGH_ORDER + (1./8.) *lattice->param.gval[subs][1] *lattice->param.gval[subs][1] + (-1./24.) *lattice->param.gval[subs][1] *lattice->param.gval[subs][1] *lattice->param.gval[subs][1] *lattice->param.gval[subs][1] #endif ) #endif ; f[8] = ftemp[6] #if APPLY_DEL_FEQ - (1./2.) * ( (1./12.) *lattice->param.gval[subs][1] #if APPLY_DEL_FEQ_HIGH_ORDER + (1./8.) *lattice->param.gval[subs][1] *lattice->param.gval[subs][1] + (-1./24.) *lattice->param.gval[subs][1] *lattice->param.gval[subs][1] *lattice->param.gval[subs][1] *lattice->param.gval[subs][1] #endif ) #endif ; #endif } /* if( subs==0) */ #if NUM_FLUID_COMPONENTS==2 else // subs==1 { #if INAMURO_SIGMA_COMPONENT if( lattice->param.bc_sigma_slip) { // // Slip BC for solute on side walls. // Will this make a difference on Taylor dispersion? // if( flow_dir_is_vertical( lattice)) { if( on_the_east_or_west( lattice, n)) { // Slip condition on east/west boundary. /* // A B C C B A // \|/ \|/ // D-o-E --> E-o-D // /|\ /|\ // F G H H G F */ f[1] = ftemp[3]; f[2] = ftemp[2]; f[3] = ftemp[1]; f[4] = ftemp[4]; f[5] = ftemp[6]; f[6] = ftemp[5]; f[7] = ftemp[8]; f[8] = ftemp[7]; } } else if( flow_dir_is_horizontal( lattice)) { if( on_the_north_or_south( lattice, n)) { // Slip condition on north/south boundary. /* // A B C F G H // \|/ \|/ // D-o-E --> D-o-E // /|\ /|\ // F G H A B C */ f[1] = ftemp[1]; f[2] = ftemp[4]; f[3] = ftemp[3]; f[4] = ftemp[2]; f[5] = ftemp[8]; f[6] = ftemp[7]; f[7] = ftemp[6]; f[8] = ftemp[5]; } else { // ERROR: Solid exists somewhere other than as side walls. printf("%s (%d) >> " "ERROR: " "bc_sigma_slip is on. " "FlowDir is determined to be horizontal. " "Encountered solid node somewhere other than side walls. " "That situation is not supported. " "Exiting!", __FILE__, __LINE__); process_exit(1); } } else { // Bail printf("%s (%d) >> " "FlowDir is indeterminate. " "Cannot apply slip BC (bc_sigma_slip). " "Exiting!", __FILE__, __LINE__); process_exit(1); } } /* if( lattice->param.bc_sigma_slip) */ else { #endif /* INAMURO_SIGMA_COMPONENT */ // Usual non-slip bounce-back condition. /* // A B C H G F // \|/ \|/ // D-o-E --> E-o-D // /|\ /|\ // F G H C B A */ f[1] = ftemp[3]; f[2] = ftemp[4]; f[3] = ftemp[1]; f[4] = ftemp[2]; f[5] = ftemp[7]; f[6] = ftemp[8]; f[7] = ftemp[5]; f[8] = ftemp[6]; #if INAMURO_SIGMA_COMPONENT } /* if( lattice->param.bc_sigma_slip) else */ #endif /* INAMURO_SIGMA_COMPONENT */ } /* if( subs==0) else*/ #endif /* NUM_FLUID_COMPONENTS==2 */ } /* if( lattice->param.bc_slip_north && ... ) else */ } /* if( !( bc_type & BC_SOLID_NODE)) else */ } /* for( n=0; n<lattice_NumNodes; n++) */ #if POROUS_MEDIA if( INAMURO_SIGMA_COMPONENT!=0 || subs==0) { // Need separate temp space for this? nsterm = (double*)malloc( 9*lattice->NumNodes*sizeof(double)); // Compute the solid density term for fluid component. for( n=0; n<lattice->NumNodes; n++) { bc_type = lattice->bc [subs][n].bc_type; i = n%LX; j = n/LX; jp = ( j<LY-1)?( j+1):( 0 ); jn = ( j>0 )?( j-1):( LY-1); ip = ( i<LX-1)?( i+1):( 0 ); in = ( i>0 )?( i-1):( LX-1); if( is_not_solid_node(lattice, subs, n)) { if( lattice->param.ns_flag == 0) { ns = lattice->param.ns; #if 0 // OLD POROUS_MEDIA TERM /* 1 */ nsterm[9*n+1] = ns*( lattice->pdf[subs][ j *LX + ip].f[3] - lattice->pdf[subs][ j *LX + i ].f[1]); /* 2 */ nsterm[9*n+2] = ns*( lattice->pdf[subs][ jp*LX + i ].f[4] - lattice->pdf[subs][ j *LX + i ].f[2]); /* 3 */ nsterm[9*n+3] = ns*( lattice->pdf[subs][ j *LX + in].f[1] - lattice->pdf[subs][ j *LX + i ].f[3]); /* 4 */ nsterm[9*n+4] = ns*( lattice->pdf[subs][ jn*LX + i ].f[2] - lattice->pdf[subs][ j *LX + i ].f[4]); /* 5 */ nsterm[9*n+5] = ns*( lattice->pdf[subs][ jp*LX + ip].f[7] - lattice->pdf[subs][ j *LX + i ].f[5]); /* 6 */ nsterm[9*n+6] = ns*( lattice->pdf[subs][ jp*LX + in].f[8] - lattice->pdf[subs][ j *LX + i ].f[6]); /* 7 */ nsterm[9*n+7] = ns*( lattice->pdf[subs][ jn*LX + in].f[5] - lattice->pdf[subs][ j *LX + i ].f[7]); /* 8 */ nsterm[9*n+8] = ns*( lattice->pdf[subs][ jn*LX + ip].f[6] - lattice->pdf[subs][ j *LX + i ].f[8]); #else /* 1 */ nsterm[9*n+1] = ns*( lattice->pdf[subs][ j*LX + i].ftemp[3] - lattice->pdf[subs][ j*LX + i].f [1]); /* 2 */ nsterm[9*n+2] = ns*( lattice->pdf[subs][ j*LX + i].ftemp[4] - lattice->pdf[subs][ j*LX + i].f [2]); /* 3 */ nsterm[9*n+3] = ns*( lattice->pdf[subs][ j*LX + i].ftemp[1] - lattice->pdf[subs][ j*LX + i].f [3]); /* 4 */ nsterm[9*n+4] = ns*( lattice->pdf[subs][ j*LX + i].ftemp[2] - lattice->pdf[subs][ j*LX + i].f [4]); /* 5 */ nsterm[9*n+5] = ns*( lattice->pdf[subs][ j*LX + i].ftemp[7] - lattice->pdf[subs][ j*LX + i].f [5]); /* 6 */ nsterm[9*n+6] = ns*( lattice->pdf[subs][ j*LX + i].ftemp[8] - lattice->pdf[subs][ j*LX + i].f [6]); /* 7 */ nsterm[9*n+7] = ns*( lattice->pdf[subs][ j*LX + i].ftemp[5] - lattice->pdf[subs][ j*LX + i].f [7]); /* 8 */ nsterm[9*n+8] = ns*( lattice->pdf[subs][ j*LX + i].ftemp[6] - lattice->pdf[subs][ j*LX + i].f [8]); #endif } else /* ns_flag==1 || ns_flag==2 */ { // Variable solid density. ns = lattice->ns[n].ns; //printf("%s %d >> ns = %f\n",__FILE__,__LINE__,ns); #if 0 // OLD POROUS_MEDIA TERM /* 1 */ nsterm[9*n+1] = ns*( lattice->pdf[subs][ j *LX + ip].f[3] - lattice->pdf[subs][ j *LX + i ].f[1]); /* 2 */ nsterm[9*n+2] = ns*( lattice->pdf[subs][ jp*LX + i ].f[4] - lattice->pdf[subs][ j *LX + i ].f[2]); /* 3 */ nsterm[9*n+3] = ns*( lattice->pdf[subs][ j *LX + in].f[1] - lattice->pdf[subs][ j *LX + i ].f[3]); /* 4 */ nsterm[9*n+4] = ns*( lattice->pdf[subs][ jn*LX + i ].f[2] - lattice->pdf[subs][ j *LX + i ].f[4]); /* 5 */ nsterm[9*n+5] = ns*( lattice->pdf[subs][ jp*LX + ip].f[7] - lattice->pdf[subs][ j *LX + i ].f[5]); /* 6 */ nsterm[9*n+6] = ns*( lattice->pdf[subs][ jp*LX + in].f[8] - lattice->pdf[subs][ j *LX + i ].f[6]); /* 7 */ nsterm[9*n+7] = ns*( lattice->pdf[subs][ jn*LX + in].f[5] - lattice->pdf[subs][ j *LX + i ].f[7]); /* 8 */ nsterm[9*n+8] = ns*( lattice->pdf[subs][ jn*LX + ip].f[6] - lattice->pdf[subs][ j *LX + i ].f[8]); #else /* 1 */ nsterm[9*n+1] = ns*( lattice->pdf[subs][ j*LX + i].ftemp[3] - lattice->pdf[subs][ j*LX + i].f [1]); /* 2 */ nsterm[9*n+2] = ns*( lattice->pdf[subs][ j*LX + i].ftemp[4] - lattice->pdf[subs][ j*LX + i].f [2]); /* 3 */ nsterm[9*n+3] = ns*( lattice->pdf[subs][ j*LX + i].ftemp[1] - lattice->pdf[subs][ j*LX + i].f [3]); /* 4 */ nsterm[9*n+4] = ns*( lattice->pdf[subs][ j*LX + i].ftemp[2] - lattice->pdf[subs][ j*LX + i].f [4]); /* 5 */ nsterm[9*n+5] = ns*( lattice->pdf[subs][ j*LX + i].ftemp[7] - lattice->pdf[subs][ j*LX + i].f [5]); /* 6 */ nsterm[9*n+6] = ns*( lattice->pdf[subs][ j*LX + i].ftemp[8] - lattice->pdf[subs][ j*LX + i].f [6]); /* 7 */ nsterm[9*n+7] = ns*( lattice->pdf[subs][ j*LX + i].ftemp[5] - lattice->pdf[subs][ j*LX + i].f [7]); /* 8 */ nsterm[9*n+8] = ns*( lattice->pdf[subs][ j*LX + i].ftemp[6] - lattice->pdf[subs][ j*LX + i].f [8]); #endif } } /* if( !( *bc_type++ & BC_SOLID_NODE)) */ } /* for( n=0; n<lattice_NumNodes; n++) */ for( n=0; n<lattice->NumNodes; n++) { f = lattice->pdf[subs][n].f; bc_type = lattice->bc [subs][n].bc_type; if( !( bc_type & BC_SOLID_NODE)) { for( a=1; a<9; a++) { #if 0 // Store f in ftemp, because the compute_macro vars before // output_frames needs to have the pre-ns version of f. if( is_last_step_of_frame(lattice)) { // This temp copy of f in ftemp prior to application // of ns only needs to be done before outputting a frame, // not after each timestep. lattice->pdf[subs][n].ftemp[a] = f[a]; } #endif // OLD: fout = fc + ns*( fc_(x+cdt) - fc(x)) // f += ns*( f_(x+cdt) - f(x)) // // - - - >o< - - - <------o------> <--<---o--->--> // 1 2 3 4 3 5 6 4 // ------>o<------ // 5 6 // // CUR: fout = fc + ns*( fc_(x) - fc(x)) = (1-ns)*fc + ns*fc_(x) // f += ns*( f_(x) - f(x)) // // - - - >o< - - - <------o------> <--<---o--->--> // 1 2 3 4 3 4 3 4 // // NEW: fout = fc + ns*( fin_(x) - fc(x)) = (1-ns)*fc + ns*fin_(x) // f += ns*( ftemp_(x) - f(x)) // // - - - >o< - - - <------o------> <--<- -o- ->--> // 1 2 3 4 3 1 2 4 // // c.f., Walsh, et al., Computers and Geosciences f[a] += nsterm[9*n+a]; } /* for( a=1; a<9; a++) */ } /* if( !( bc_type & BC_SOLID_NODE)) */ } /* for( n=0; n<lattice->NumNodes; n++, f+=18) */ free( nsterm); } /* if( INAMURO_SIGMA_COMPONENT!=0 || subs==0) */ #endif #if SIGMA_BULK_FLAG } #endif } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ #if SAY_HI printf("collide() -- Bye!\n"); #endif /* SAY_HI */ } /* void collide( lattice_ptr lattice) */ #endif /* POROUS_MEDIA */
111pjb-one
src/collide.c
C
gpl3
37,655
//############################################################################## // // Copyright (C), 2005, Michael Sukop and Danny Thorne // // flags.h // // - Preprocessor flags for lb2d_prime. // #ifndef FLAGS_H #define FLAGS_H // Set VERBOSITY_LEVEL to correspond to how deep into nested loops to // print debug and related output. Stuff will be printed down to // loops nested VERBOSITY_LEVEL-1 deep. For example, // // VERBOSITY_LEVEL 0 ==> Nothing is printed, even outside of loops. // VERBOSITY_LEVEL 1 ==> Only stuff outside of loops is printed. // VERBOSITY_LEVEL 2 ==> Stuff inside the first level of loops is printed. // VERBOSITY_LEVEL 3 ==> Stuff inside the second level of loops is printed. // // Flag: VERBOSITY_LEVEL #define VERBOSITY_LEVEL 1 // If SAY_HI is on, some routines will display "hi" and "bye" messages // to stdout. // Flag: SAY_HI #define SAY_HI 0 // NUM_FLUID_COMPONENTS specifies the number of fluid components. // Flag: NUM_FLUID_COMPONENTS #define NUM_FLUID_COMPONENTS 2 // If NUM_FLUID_COMPONENTS is 2, the second component can be the sigma // component for solute (or thermal) transport as in Inamuro & Yoshino // by turning on INAMURO_SIGMA_COMPONENT . // Flag: INAMURO_SIGMA_COMPONENT #define INAMURO_SIGMA_COMPONENT ( 1 && NUM_FLUID_COMPONENTS==2) // SOURCE_ON activates zero-order (constant) source term to fluid 0 #define SOURCE_ON 0 // SINK_ON activates first-order (proportional to f) sink term // to fluid 1 as a solute (i.e. INAMURO_SIGMA_COMPONENT on) #define SINK_ON (0 && (INAMURO_SIGMA_COMPONENT)) // SIGMA_BULK_FLAG enables introduction of a solute into the bulk // at a timestep given by sigma_bulk_on #define SIGMA_BULK_FLAG (1 && (INAMURO_SIGMA_COMPONENT)) // PEST_OUTPUT_ON enables the output of a concentration list at various // timesteps and coordinates for use with PEST #define PEST_OUTPUT_ON 1 // Toggle Zhang & Chen energy transport method, PRE 67, 0066711 (2003). // Supposed to give thermodynamic consistency unlike old Shan & Chen method. // And supports general equation of state P = P(rho,T). // Utilizes the Inamuro component for evolution of the energy transport // equation. Employs modified compute_phase_force routine to compute // body force term representing non-local interaction potential U among // particles. // Flag: ZHANG_AND_CHEN_ENERGY_TRANSPORT #define ZHANG_AND_CHEN_ENERGY_TRANSPORT ( 0 && (INAMURO_SIGMA_COMPONENT)) // Simulate POROUS_MEDIA via a solid density parameter // as proposed by Dardis and McCloskey, // Phys Rev E, 57, 4, 4834-4837, 1998 // Flag: POROUS_MEDIA #define POROUS_MEDIA 0 // Simulate porous media as a body force. #define FREED_POROUS_MEDIA 0 // Toggle Tau & Zhang anisotropic dispersion. #define TAU_ZHANG_ANISOTROPIC_DISPERSION ( 0 \ && INAMURO_SIGMA_COMPONENT \ && POROUS_MEDIA ) // Guo, Zheng & Shi: PRE 65 2002, Body force #define GUO_ZHENG_SHI_BODY_FORCE 0 // Body force macros #if GUO_ZHENG_SHI_BODY_FORCE #if INAMURO_SIGMA_COMPONENT #define F(dir_,rho_,conc_) \ ( lattice->param.gval[0][(dir_)] \ /*+ lattice->param.gval[subs][(dir_)] */\ /* *(rho_) */\ *( 1. + get_buoyancy(lattice) \ *( get_beta(lattice)) \ *( (conc_) - get_C0(lattice))) \ ) #else #define F(dir_) lattice->param.gval[subs][(dir_)] #endif #else #if INAMURO_SIGMA_COMPONENT #define F(dir_,rho_,conc_) \ ( lattice->param.gval[0][(dir_)] \ /*+ lattice->param.gval[1][(dir_)] */\ /* *(rho_) */\ *( 1. + ( get_buoyancy(lattice)) \ *( get_beta(lattice)) \ *( (conc_) - get_C0(lattice))) ) #else #define F(dir_,rho_) \ lattice->param.gval[subs][(dir_)] \ *((lattice->param.incompressible)?(rho_):(1.)) #endif #endif // When there are two (or more) fluid components, a single velocity is // sometimes (always?) used to compute the equilibrium distribution // function. This single velocity will be called upr, and the // STORE_U_COMPOSITE flag will toggle its use. // Flag: STORE_U_COMPOSITE #define STORE_U_COMPOSITE ( 1 && ( (NUM_FLUID_COMPONENTS)==2 \ &&!((INAMURO_SIGMA_COMPONENT)))) // If DO_NOT_STORE_SOLIDS is on, then only the nodes necessary to flow are // stored. In this case, extra storage is needed for geometry information // (e.g. node neighbors). If the ratio of fluid nodes to solid nodes is // small (<~.7), this results in lower storage requirements. // Flag: DO_NOT_STORE_SOLIDS #define DO_NOT_STORE_SOLIDS 0 // If COMPUTE_ON_SOLIDS is on, macroscopic variables and feq will be computed // on solid nodes, even though they are not conceptually meaningful there. // This can be helpful for debugging purposes. #define COMPUTE_ON_SOLIDS 1 // NON_LOCAL_FORCES toggles any mechanisms for computing and storing // non-local (interaction) forces. // Flag: NON_LOCAL_FORCES #define NON_LOCAL_FORCES ( 0 && !(INAMURO_SIGMA_COMPONENT&&!ZHANG_AND_CHEN_ENERGY_TRANSPORT)) // The phase force weighting factors: // WM = weights in the direction of major axes // WD = weights in the direction of diagonals // According to Raskinmaki, it should be WM=2 and WD=1. // According to Chen (via correspondence) it should be WM=4 and WD=1. // According to Sukop and Thorne, it should be WM=1/9 and WD=1/36. // The corresonding G values (a.k.a. G, as in params.in) for the usual // equation of state that we like are -5, -10/3, and -120, respectively. // Flag: WM #define WM (1./ 9.) // Flag: WD #define WD (1./36.) #define Q 9 // Toggle manage_body_force call at beginning of time loop for // gradually increasing/decreasing gravity. // Flag: MANAGE_BODY_FORCE #define MANAGE_BODY_FORCE 0 // Toggle break through curve (BTC) mechanism for sigma component. // Flag: STORE_BTC #define STORE_BTC ( 1 && INAMURO_SIGMA_COMPONENT) // // Toggle DETERMINE_FLOW_DIRECTION to attempt to determine the direction of // flow. // // Assigns FlowDir = { 0, 1, 2} = { indeterminate, vertical, horizontal} // // NOTE: This determination informs the breakthrough curve mechanism which // should be used in a simple situation with either pressure/velocity // boundaries driving the flow in one direction or gravity driving the flow // in one direction. If the direction of flow cannot be determined, FlowDir // will be set to indeterminate (=0) and a BTC will not be stored. // // NOTE: This determination also informs the sigma slip boundary which // should only be used in the simple situation of flow through a channel // where the geometry is trivial and the direction of flow is obvious. // // Flag: DETERMINE_FLOW_DIRECTION #define DETERMINE_FLOW_DIRECTION 1 // Toggle mechanism to initialize domain with ux_in or uy_in. This is // useful for setting a velocity in a periodic domain without using // fluid boundary conditions. // Flag: INITIALIZE_WITH_UX_IN #define INITIALIZE_WITH_UX_IN 0 // Flag: INITIALIZE_WITH_UY_IN #define INITIALIZE_WITH_UY_IN 0 // Dumping the density and velocity data to files can be time consuming and // take up a lot of disk space. If all that is needed is the BMP files, then // turn WRITE_MACRO_VAR_DAT_FILES off to save time and space. // Flag: WRITE_MACRO_VAR_DAT_FILES #define WRITE_MACRO_VAR_DAT_FILES 1 // Usually the density and velocity are written only for the active nodes // and in a way designed for post-processing. Additional files with the // variables written in a readable grid of all lattice nodes will be // generated when WRITE_RHO_AND_U_TO_TXT is on. This is done in an // inefficient way and is intended only for debugging purposes on tiny // lattices. Note that if WRITE_MACRO_VAR_DAT_FILES is off, this flag // has no effect. // Flag: WRITE_RHO_AND_U_TO_TXT #define WRITE_RHO_AND_U_TO_TXT 0 // WRITE_PDF_DAT_FILES is analogous to WRITE_MACRO_VAR_DAT_FILES. // Flag: WRITE_PDF_DAT_FILES #define WRITE_PDF_DAT_FILES 0 // WRITE_PDF_TO_TXT is analogous to WRITE_RHO_AND_U_TO_TXT. // Flag: WRITE_PDF_TO_TXT #define WRITE_PDF_TO_TXT 0 // Value used to represent an INACTIVE_NODE . This is used in the list // of neighbors ( struct node_struct::nn). It is also used in the // map from (i,j) space onto n index space in rho2bmp() and u2bmp(). // Flag: INACTIVE_NODE #define INACTIVE_NODE -1 // Negative densities (f_a) generally signify impending doom. The code // will die "gracefully" when this happens if PUKE_NEGATIVE_DENSITIES is on. // Might want to turn this off to boost performance on big, long runs that // are expected to survive without such instabilities. // Flag: PUKE_NEGATIVE_DENSITIES #define PUKE_NEGATIVE_DENSITIES 0 // Turn one of these on for coloring of the solids in bmp files. // Flag: SOLID_COLOR_IS_CHECKERBOARD #define SOLID_COLOR_IS_CHECKERBOARD 0 // Flag: SOLID_COLOR_IS_BLACK #define SOLID_COLOR_IS_BLACK 1 // Flag: DELAY #define DELAY 0 // Flag: END_GRAV #define END_GRAV 2000 // A single white pixel will be placed in at the (0,0) lattice node if // MARK_ORIGIN_FOR_REFERENCE is turned on. This is good for assisting with the // problem of tracking orientation of the results between regimes (e.g. C, BMP, // Matlab...). // Flag: MARK_ORIGIN_FOR_REFERENCE #define MARK_ORIGIN_FOR_REFERENCE 0 // Flag: PERTURBATIONS #define PERTURBATIONS 0 // If WRITE_CHEN_DAT_FILES is on, the code will output old style chen_*.dat // files to be processed by the old lb_rho_v*.m matlab scripts. // Flag: WRITE_CHEN_DAT_FILES #define WRITE_CHEN_DAT_FILES 0 // NEW_PARAMS_INPUT_ROUTINE is a temporary flag to switch between the old // params input routine and the new one under development. When the new // one is ready, it should be used exclusively. #define NEW_PARAMS_INPUT_ROUTINE 1 #endif /* FLAGS_H */
111pjb-one
src/flags.h
C
gpl3
9,665
//############################################################################## // // Copyright (C), 2005, Michael Sukop and Danny Thorne // // flags.h // // - Preprocessor flags for lb2d_prime. // #ifndef FLAGS_H #define FLAGS_H // Set VERBOSITY_LEVEL to correspond to how deep into nested loops to // print debug and related output. Stuff will be printed down to // loops nested VERBOSITY_LEVEL-1 deep. For example, // // VERBOSITY_LEVEL 0 ==> Nothing is printed, even outside of loops. // VERBOSITY_LEVEL 1 ==> Only stuff outside of loops is printed. // VERBOSITY_LEVEL 2 ==> Stuff inside the first level of loops is printed. // VERBOSITY_LEVEL 3 ==> Stuff inside the second level of loops is printed. // // Flag: VERBOSITY_LEVEL #define VERBOSITY_LEVEL 1 // If SAY_HI is on, some routines will display "hi" and "bye" messages // to stdout. // Flag: SAY_HI #define SAY_HI 0 // NUM_FLUID_COMPONENTS specifies the number of fluid components. // Flag: NUM_FLUID_COMPONENTS #define NUM_FLUID_COMPONENTS 1 // If NUM_FLUID_COMPONENTS is 2, the second component can be the sigma // component for solute (or thermal) transport as in Inamuro & Yoshino // by turning on INAMURO_SIGMA_COMPONENT . // Flag: INAMURO_SIGMA_COMPONENT #define INAMURO_SIGMA_COMPONENT ( 0 && NUM_FLUID_COMPONENTS==2) // Toggle Zhang & Chen energy transport method, PRE 67, 0066711 (2003). // Supposed to give thermodynamic consistency unlike old Shan & Chen method. // And supports general equation of state P = P(rho,T). // Utilizes the Inamuro component for evolution of the energy transport // equation. Employs modified compute_phase_force routine to compute // body force term representing non-local interaction potential U among // particles. // Flag: ZHANG_AND_CHEN_ENERGY_TRANSPORT #define ZHANG_AND_CHEN_ENERGY_TRANSPORT ( 0 && (INAMURO_SIGMA_COMPONENT)) // Simulate POROUS_MEDIA via a solid density parameter // as proposed by Dardis and McCloskey, // Phys Rev E, 57, 4, 4834-4837, 1998 // Flag: POROUS_MEDIA #define POROUS_MEDIA 0 // When there are two (or more) fluid components, a single velocity is // sometimes (always?) used to compute the equilibrium distribution // function. This single velocity will be called upr, and the // STORE_U_COMPOSITE flag will toggle its use. // Flag: STORE_U_COMPOSITE #define STORE_U_COMPOSITE ( 1 && ( (NUM_FLUID_COMPONENTS)==2 \ &&!((INAMURO_SIGMA_COMPONENT)))) // If DO_NOT_STORE_SOLIDS is on, then only the nodes necessary to flow are // stored. In this case, extra storage is needed for geometry information // (e.g. node neighbors). If the ratio of fluid nodes to solid nodes is // small (<~.7), this results in lower storage requirements. // Flag: DO_NOT_STORE_SOLIDS #define DO_NOT_STORE_SOLIDS 0 // NON_LOCAL_FORCES toggles any mechanisms for computing and storing // non-local (interaction) forces. // Flag: NON_LOCAL_FORCES #define NON_LOCAL_FORCES ( 0 && !(INAMURO_SIGMA_COMPONENT&&!ZHANG_AND_CHEN_ENERGY_TRANSPORT)) // The phase force weighting factors: // WM = weights in the direction of major axes // WD = weights in the direction of diagonals // According to Raskinmaki, it should be WM=2 and WD=1. // According to Chen (via correspondence) it should be WM=4 and WD=1. // According to Sukop and Thorne, it should be WM=1/9 and WD=1/36. // The corresonding G values (a.k.a. G, as in params.in) for the usual // equation of state that we like are -5, -10/3, and -120, respectively. // Flag: WM #define WM (1./ 9.) // Flag: WD #define WD (1./36.) // Toggle manage_body_force call at beginning of time loop for // gradually increasing/decreasing gravity. // Flag: MANAGE_BODY_FORCE #define MANAGE_BODY_FORCE 0 // Toggle break through curve (BTC) mechanism for sigma component. // Flag: STORE_BTC #define STORE_BTC ( 1 && INAMURO_SIGMA_COMPONENT) // // Toggle DETERMINE_FLOW_DIRECTION to attempt to determine the direction of // flow. // // Assigns FlowDir = { 0, 1, 2} = { indeterminate, vertical, horizontal} // // NOTE: This determination informs the breakthrough curve mechanism which // should be used in a simple situation with either pressure/velocity // boundaries driving the flow in one direction or gravity driving the flow // in one direction. If the direction of flow cannot be determined, FlowDir // will be set to indeterminate (=0) and a BTC will not be stored. // // NOTE: This determination also informs the sigma slip boundary which // should only be used in the simple situation of flow through a channel // where the geometry is trivial and the direction of flow is obvious. // // Flag: DETERMINE_FLOW_DIRECTION #define DETERMINE_FLOW_DIRECTION 1 // Toggle mechanism to initialize domain with ux_in or uy_in. This is // useful for setting a velocity in a periodic domain without using // fluid boundary conditions. // Flag: INITIALIZE_WITH_UX_IN #define INITIALIZE_WITH_UX_IN 0 // Flag: INITIALIZE_WITH_UY_IN #define INITIALIZE_WITH_UY_IN 0 // Dumping the density and velocity data to files can be time consuming and // take up a lot of disk space. If all that is needed is the BMP files, then // turn WRITE_MACRO_VAR_DAT_FILES off to save time and space. // Flag: WRITE_MACRO_VAR_DAT_FILES #define WRITE_MACRO_VAR_DAT_FILES 0 // Usually the density and velocity are written only for the active nodes // and in a way designed for post-processing. Additional files with the // variables written in a readable grid of all lattice nodes will be // generated when WRITE_RHO_AND_U_TO_TXT is on. This is done in an // inefficient way and is intended only for debugging purposes on tiny // lattices. Note that if WRITE_MACRO_VAR_DAT_FILES is off, this flag // has no effect. // Flag: WRITE_RHO_AND_U_TO_TXT #define WRITE_RHO_AND_U_TO_TXT 0 // WRITE_PDF_DAT_FILES is analogous to WRITE_MACRO_VAR_DAT_FILES. // Flag: WRITE_PDF_DAT_FILES #define WRITE_PDF_DAT_FILES 0 // WRITE_PDF_TO_TXT is analogous to WRITE_RHO_AND_U_TO_TXT. // Flag: WRITE_PDF_TO_TXT #define WRITE_PDF_TO_TXT 0 // Value used to represent an INACTIVE_NODE . This is used in the list // of neighbors ( struct node_struct::nn). It is also used in the // map from (i,j) space onto n index space in rho2bmp() and u2bmp(). // Flag: INACTIVE_NODE #define INACTIVE_NODE -1 // Negative densities (f_a) generally signify impending doom. The code // will die "gracefully" when this happens if PUKE_NEGATIVE_DENSITIES is on. // Might want to turn this off to boost performance on big, long runs that // are expected to survive without such instabilities. // Flag: PUKE_NEGATIVE_DENSITIES #define PUKE_NEGATIVE_DENSITIES 0 // Turn one of these on for coloring of the solids in bmp files. // Flag: SOLID_COLOR_IS_CHECKERBOARD #define SOLID_COLOR_IS_CHECKERBOARD 0 // Flag: SOLID_COLOR_IS_BLACK #define SOLID_COLOR_IS_BLACK 1 // Flag: DELAY #define DELAY 0 // Flag: END_GRAV #define END_GRAV 2000 // A single white pixel will be placed in at the (0,0) lattice node if // MARK_ORIGIN_FOR_REFERENCE is turned on. This is good for assisting with the // problem of tracking orientation of the results between regimes (e.g. C, BMP, // Matlab...). // Flag: MARK_ORIGIN_FOR_REFERENCE #define MARK_ORIGIN_FOR_REFERENCE 0 // Flag: PERTURBATIONS #define PERTURBATIONS 0 // If WRITE_CHEN_DAT_FILES is on, the code will output old style chen_*.dat // files to be processed by the old lb_rho_v*.m matlab scripts. // Flag: WRITE_CHEN_DAT_FILES #define WRITE_CHEN_DAT_FILES 0 // NEW_PARAMS_INPUT_ROUTINE is a temporary flag to switch between the old // params input routine and the new one under development. When the new // one is ready, it should be used exclusively. #define NEW_PARAMS_INPUT_ROUTINE 1 #endif /* FLAGS_H */
111pjb-one
src/flags_bak08032005_01.h
C
gpl3
7,705
//############################################################################## // // Copyright (C), 2005, Michael Sukop and Danny Thorne // // lbio.c // // - Lattice Boltzmann I/O routines. // // - Mainly, dump the data to files that can be read by Matlab. // // - Also, output routines for facilitating debugging. // // - Should have a routine that dumps a matlab script? // // Some compilers, e.g., VC++, don't have the usual round() function // in their math library. Alternatively, ROUND can be defined as // ceil or floor or some other rounding function. It is used in // the below routines for converting the real number valued of // quantities at a lattice node into integer RGB values for writing // to BMP files. #define ROUND floor //void output_frame( lattice_ptr lattice) //############################################################################## // // O U T P U T F R A M E // void output_frame( lattice_ptr lattice) { double s, u[2]; double nu; double L; #if VERBOSITY_LEVEL > 0 printf("\n"); printf( "========================================" "========================================\n"); printf("Begin file I/O at time = %d, frame = %d.\n", lattice->time, lattice->time/lattice->param.FrameRate); printf("\n"); #endif /* VERBOSITY_LEVEL > 0 */ dump_frame_summary( lattice); #if WRITE_MACRO_VAR_DAT_FILES dump_macro_vars( lattice, lattice->time); #endif /* WRITE_MACRO_VAR_DAT_FILES */ #if WRITE_PDF_DAT_FILES dump_pdf( lattice, lattice->time); #endif /* WRITE_PDF_DAT_FILES */ if( lattice->param.dump_rho) { rho2bmp( lattice, lattice->time);} if( lattice->param.dump_u ) { u2bmp( lattice, lattice->time);} if( lattice->param.dump_vor) { vor2bmp( lattice, lattice->time);} #if NON_LOCAL_FORCES if( lattice->param.G != 0.) { if( lattice->param.dump_force) { force2bmp( lattice);} } if( lattice->param.Gads[0] != 0. || lattice->param.Gads[0] != 0.) { if( lattice->param.dump_force) { sforce2bmp( lattice);} } #endif /* NON_LOCAL_FORCES */ slice( lattice); #if WRITE_CHEN_DAT_FILES chen_output( lattice); #endif /* WRITE_CHEN_DAT_FILES */ #if VERBOSITY_LEVEL > 0 printf("\n"); printf("File I/O done.\n"); printf("--\n"); #endif /* VERBOSITY_LEVEL > 0 */ nu = (1./3.)*(lattice->param.tau[0] - .5); L = lattice->param.length_scale; compute_ave_u( lattice, u, 0); s = sqrt( u[0]*u[0] + u[1]*u[1]); printf("subs 0: Re = ux_ave*L/nu = %f * %f / %f = %f\n", u[0], L, nu, u[0]*L/nu ); printf("subs 0: Re = uy_ave*L/nu = %f * %f / %f = %f\n", u[1], L, nu, u[1]*L/nu ); printf("subs 0: Re = u_ave*L/nu = %f * %f / %f = %f\n", s, L, nu, s*L/nu ); #if NUM_FLUID_COMPONENTS == 2 compute_ave_u( lattice, u, 1); s = sqrt( u[0]*u[0] + u[1]*u[1]); printf("subs 1: Re = ux_ave*L/nu = %f * %f / %f = %f\n", u[0], L, nu, u[0]*L/nu ); printf("subs 1: Re = uy_ave*L/nu = %f * %f / %f = %f\n", u[1], L, nu, u[1]*L/nu ); printf("subs 1: Re = u_ave*L/nu = %f * %f / %f = %f\n", s, L, nu, s*L/nu ); #endif /* NUM_FLUID_COMPONENTS == 2 */ #if STORE_UEQ compute_ave_ueq( lattice, u); s = sqrt( u[0]*u[0] + u[1]*u[1]); printf("eq: Re = ux_ave*L/nu = %f * %f / %f = %f\n", u[0], L, nu, u[0]*L/nu ); printf("eq: Re = uy_ave*L/nu = %f * %f / %f = %f\n", u[1], L, nu, u[1]*L/nu ); printf("eq: Re = u_ave*L/nu = %f * %f / %f = %f\n", s, L, nu, s*L/nu ); #endif /* STORE_UEQ */ } /* void output_frame( lattice_ptr lattice) */ // void dump_frame_info( struct lattice_struct *lattice) //############################################################################## // // D U M P F R A M E I N F O // void dump_frame_summary( struct lattice_struct *lattice) { char filename[1024]; FILE *o; double min_u[5], max_u[5], ave_u[5], flux[3]; double min_rho, max_rho, ave_rho; double rho_ratio, u_x_ratio, u_y_ratio; int subs; for( subs = 0; subs < NUM_FLUID_COMPONENTS; subs++) { sprintf( filename, "./out/frames%dx%d_subs%02d.dat", lattice->param.LX, lattice->param.LY, subs); // On the first timestep, make sure we start with a new file. if( lattice->time==0) { if( !( o = fopen(filename,"w+"))) { printf("ERROR: fopen(\"%s\",\"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } else { // Put a header on the file. fprintf( o, "\n"); fprintf( o, " time " " |j| " " j_x " " j_y " " ave |u| " " ave |u_x| " " ave |u_y| " " ave u_x " " ave u_y " " min |u| " " min |u_x| " " min |u_y| " " min u_x " " min u_y " " max |u| " " max |u_x| " " max |u_y| " " max u_x " " max u_y " " max/ave_x " " max/ave_y " " min rho " " max rho " " ave rho " " max/ave " "\n"); fprintf( o, " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" "\n"); fclose(o); } } if( !( o = fopen(filename,"a+"))) { printf("ERROR: fopen(\"%s\",\"a+\") = NULL. Bye, bye!\n", filename); process_exit(1); } compute_min_u_all( lattice, min_u, subs); compute_max_u_all( lattice, max_u, subs); compute_ave_u_all( lattice, ave_u, subs); compute_min_rho( lattice, &min_rho, subs); compute_max_rho( lattice, &max_rho, subs); compute_ave_rho( lattice, &ave_rho, subs); rho_ratio = ( ave_rho != 0.) ? ( max_rho /ave_rho ):( 1.); u_x_ratio = ( ave_u[1] != 0.) ? ( max_u[1]/ave_u[0]):( 1.); u_y_ratio = ( ave_u[2] != 0.) ? ( max_u[2]/ave_u[1]):( 1.); compute_flux( lattice, flux, subs); fprintf( o, "%12d " "%12.7f %12.7f %12.7f %12.7f %12.7f %12.7f %12.7f %12.7f %12.7f " "%12.7f %12.7f %12.7f %12.7f %12.7f %12.7f %12.7f %12.7f %12.7f " "%12.7f %12.7f %12.7f %12.7f %12.7f %12.7f\n", lattice->time, flux [0], flux [1], flux [2], ave_u[0], ave_u[1], ave_u[2], ave_u[3], ave_u[4], min_u[0], min_u[1], min_u[2], min_u[3], min_u[4], max_u[0], max_u[1], max_u[2], max_u[3], max_u[4], (u_x_ratio<=9999.)?(u_x_ratio):(9999.), (u_y_ratio<=9999.)?(u_y_ratio):(9999.), min_rho, max_rho, ave_rho, (rho_ratio<=9999.)?(rho_ratio):(9999.) ); fclose(o); #if VERBOSITY_LEVEL > 0 printf("dump_frame_info() -- Wrote file \"%s\"\n", filename); #endif /* VERBOSITY_LEVEL > 0 */ #if VERBOSITY_LEVEL > 0 printf("dump_frame_info() -- frame = %d/%d = %d\n", lattice->time, lattice->param.FrameRate, (int)((double)lattice->time/(double)lattice->param.FrameRate)); #endif /* VERBOSITY_LEVEL > 0 */ } } /* void dump_frame_info( struct lattice_struct *lattice) */ // void dump_macro_vars( struct lattice_struct *lattice) //############################################################################## // // D U M P M A C R O S C O P I C // // - Output the macro_vars variables to files. // void dump_macro_vars( struct lattice_struct *lattice, int time) { char filename[1024]; FILE *o, *o_u, *o_rho, *o_ux, *o_uy, *o_ueq, *o_ueq_x, *o_ueq_y; int *node_ptr; int n; double *macro_vars_ptr; double *ueq; int frame; #if WRITE_RHO_AND_U_TO_TXT int i, j; #endif /* WRITE_RHO_AND_U_TO_TXT */ double min_u[2], max_u[2], ave_u[2]; double min_rho, max_rho, ave_rho; double rho_ratio, u_x_ratio, u_y_ratio; int subs; frame = (int)((double)lattice->time/(double)lattice->param.FrameRate); for( subs = 0; subs < NUM_FLUID_COMPONENTS; subs++) { // W R I T E R H O A N D U // // - Write the density and velocity values at the active nodes to // the rho and u dat files. // sprintf( filename, "./out/rho_frame%04d_subs%02d.dat", frame, subs); if( !( o_rho = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/u_frame%04d_subs%02d.dat", frame, subs); if( !( o_u = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } #if STORE_UEQ sprintf( filename, "./out/ueq_frame%04d_subs%02d.dat", frame, subs); if( !( o_ueq = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } ueq = lattice->ueq[0].u; #endif /* STORE_UEQ */ macro_vars_ptr = &( lattice->macro_vars[subs][0].rho); for( n=0; n<lattice->NumNodes; n++) { fprintf( o_rho, "%20.17f\n", *macro_vars_ptr++); fprintf( o_u, "%20.17f ", *macro_vars_ptr++); fprintf( o_u, "%20.17f\n", *macro_vars_ptr++); #if STORE_UEQ fprintf( o_ueq, "%20.17f ", *ueq++); fprintf( o_ueq, "%20.17f\n", *ueq++); #endif /* STORE_UEQ */ } fclose(o_u); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/u_frame%04d_subs%02d.dat", frame, subs); #endif /* VERBOSITY_LEVEL > 0 */ printf("dump_macro_vars() -- Wrote file \"%s\"\n", filename); fclose(o_rho); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/rho_frame%04d_subs%02d.dat", frame, subs); #endif /* VERBOSITY_LEVEL > 0 */ printf("dump_macro_vars() -- Wrote file \"%s\"\n", filename); #if STORE_UEQ fclose(o_ueq); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/ueq_frame%04d_subs%02d.dat", frame, subs); #endif /* VERBOSITY_LEVEL > 0 */ printf("dump_macro_vars() -- Wrote file \"%s\"\n", filename); #endif /* STORE_UEQ */ #if WRITE_RHO_AND_U_TO_TXT // NOTE: This is very inefficient. But it's only intended // for debugging purposes on small problems. sprintf( filename, "./out/rho_frame%04d_subs%02d.txt", frame, subs); if( !( o_rho = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/ux_frame%04d_subs%02d.txt", frame, subs); if( !( o_ux = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/uy_frame%04d_subs%02d.txt", frame, subs); if( !( o_uy = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } #if STORE_UEQ sprintf( filename, "./out/ueq_x_frame%04d_subs%02d.txt", frame, subs); if( !( o_ueq_x = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/ueq_y_frame%04d_subs%02d.txt", frame, subs); if( !( o_ueq_y = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } #endif /* STORE_UEQ */ for( j=lattice->param.LY-1; j>=0; j--) { n = j*lattice->param.LX; for( i=0; i<lattice->param.LX; i++, n++) { fprintf( o_rho, "%12.7f ", lattice->macro_vars[subs][n].rho); fprintf( o_ux, "%12.7f ", lattice->macro_vars[subs][n].u[0]); fprintf( o_uy, "%12.7f ", lattice->macro_vars[subs][n].u[1]); #if STORE_UEQ fprintf( o_ueq_x, "%12.7f ", lattice->ueq[n].u[0]); fprintf( o_ueq_y, "%12.7f ", lattice->ueq[n].u[1]); #endif /* STORE_UEQ */ if( n==lattice->NumNodes) { fprintf( o_rho, "%12.7f ", 0.); fprintf( o_ux, "%12.7f ", 0.); fprintf( o_uy, "%12.7f ", 0.); #if STORE_UEQ fprintf( o_ueq_x, "%12.7f ", 0.); fprintf( o_ueq_y, "%12.7f ", 0.); #endif /* STORE_UEQ */ } } fprintf( o_rho, "\n"); fprintf( o_ux, "\n"); fprintf( o_uy, "\n"); #if STORE_UEQ fprintf( o_ueq_x, "\n"); fprintf( o_ueq_y, "\n"); #endif /* STORE_UEQ */ } fclose(o_ux); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/ux_frame%04d_subs%02d.txt", frame, subs); #endif /* VERBOSITY_LEVEL > 0 */ printf("dump_macro_vars() -- Wrote file \"%s\"\n", filename); fclose(o_uy); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/uy_frame%04d_subs%02d.txt", frame, subs); #endif /* VERBOSITY_LEVEL > 0 */ printf("dump_macro_vars() -- Wrote file \"%s\"\n", filename); fclose(o_rho); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/rho_frame%04d_subs%02d.txt", frame, subs); #endif /* VERBOSITY_LEVEL > 0 */ printf("dump_macro_vars() -- Wrote file \"%s\"\n", filename); #if STORE_UEQ fclose(o_ueq_x); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/ueq_x_frame%04d_subs%02d.txt", frame, subs); #endif /* VERBOSITY_LEVEL > 0 */ printf("dump_macro_vars() -- Wrote file \"%s\"\n", filename); fclose(o_ueq_y); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/ueq_y_frame%04d_subs%02d.txt", frame, subs); #endif /* VERBOSITY_LEVEL > 0 */ printf("dump_macro_vars() -- Wrote file \"%s\"\n", filename); #endif /* STORE_UEQ */ #endif /* WRITE_RHO_AND_U_TO_TXT */ } /* for( subs = 0; subs < NUM_FLUID_COMPONENTS; subs++) */ } /* void dump_macro_vars( struct lattice_struct *lattice, int time) */ #if 1 // void read_macro_vars( struct lattice_struct *lattice) //############################################################################## // // R E A D M A C R O S C O P I C // // - Read the macro_vars variables from files. // void read_macro_vars( struct lattice_struct *lattice, int time) { char filename[1024]; FILE *in, *rho_in, *u_in; int *node_ptr; int n; double *macro_vars_ptr; int frame; double max_u[2], ave_u[2]; double max_rho, ave_rho; double rho_ratio, u_x_ratio, u_y_ratio; int subs; for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { frame = (int)((double)time/(double)lattice->param.FrameRate); #if VERBOSITY_LEVEL > 0 printf("read_macro_vars() -- frame = %d/%d = %d\n", time, lattice->param.FrameRate, frame); #endif /* VERBOSITY_LEVEL > 0 */ // R E A D R H O A N D U // // - Read the density and velocity values at the active nodes to // the rho and u dat files. // sprintf( filename, "./out/rho_frame%04d_subs%02d.dat", frame, subs); if( !( rho_in = fopen( filename, "r+"))) { printf("ERROR: fopen( \"%s\", \"r+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/u_frame%04d_subs%02d.dat", frame, subs); if( !( u_in = fopen( filename, "r+"))) { printf("ERROR: fopen( \"%s\", \"r+\") = NULL. Bye, bye!\n", filename); process_exit(1); } macro_vars_ptr = &( lattice->macro_vars[subs][0].rho); for( n=0; n<lattice->NumNodes; n++) { fscanf( rho_in, "%lf\n", macro_vars_ptr++); fscanf( u_in, "%lf ", macro_vars_ptr++); fscanf( u_in, "%lf\n", macro_vars_ptr++); } fclose(u_in); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/u_frame%04d_subs%02d.dat", frame, subs); #endif /* VERBOSITY_LEVEL > 0 */ printf("read_macro_vars() -- Read file \"%s\"\n", filename); fclose(rho_in); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/rho_frame%04d_subs%02d.dat", frame, subs); #endif /* VERBOSITY_LEVEL > 0 */ printf("read_macro_vars() -- Read file \"%s\"\n", filename); } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ } /* void read_macro_vars( struct lattice_struct *lattice, int time) */ #endif // void dump_pdf( struct lattice_struct *lattice, int time) //############################################################################## // // D U M P P D F // // - Output the particle distribution functions to a text file. // // - This is useful mainly for debugging with small problems. // void dump_pdf( struct lattice_struct *lattice, int time) { char filename[1024]; FILE *o_feq, *o_f, *o_ftemp; double *fptr, *end_ptr; bc_ptr bc; int frame; int subs; #if WRITE_PDF_TO_TXT int i, j, n; #endif /* WRITE_PDF_TO_TXT */ for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { frame = time/lattice->param.FrameRate; sprintf( filename, "./out/feq_frame%04d_subs%02d.dat", frame, subs); if( !( o_feq = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/f_frame%04d_subs%02d.dat", frame, subs); if( !( o_f = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/ftemp_frame%04d_subs%02d.dat", frame, subs); if( !( o_ftemp = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } bc = lattice->bc[subs]; fptr = lattice->pdf[subs][0].feq; end_ptr = &(lattice->pdf[subs][ lattice->NumNodes-1].ftemp[8]) + 1; while( fptr!=end_ptr) { if( 1 || !( bc++->bc_type & BC_SOLID_NODE)) { fprintf( o_feq , "%10.7f ", *fptr++); fprintf( o_feq , "%10.7f ", *fptr++); fprintf( o_feq , "%10.7f ", *fptr++); fprintf( o_feq , "%10.7f ", *fptr++); fprintf( o_feq , "%10.7f ", *fptr++); fprintf( o_feq , "%10.7f ", *fptr++); fprintf( o_feq , "%10.7f ", *fptr++); fprintf( o_feq , "%10.7f ", *fptr++); fprintf( o_feq , "%10.7f ", *fptr++); } else { fprintf( o_feq , "%10.7f ", 0.); fprintf( o_feq , "%10.7f ", 0.); fprintf( o_feq , "%10.7f ", 0.); fprintf( o_feq , "%10.7f ", 0.); fprintf( o_feq , "%10.7f ", 0.); fprintf( o_feq , "%10.7f ", 0.); fprintf( o_feq , "%10.7f ", 0.); fprintf( o_feq , "%10.7f ", 0.); fprintf( o_feq , "%10.7f ", 0.); fptr+=9; } fprintf( o_feq , "\n"); fprintf( o_f , "%10.7f ", *fptr++); fprintf( o_f , "%10.7f ", *fptr++); fprintf( o_f , "%10.7f ", *fptr++); fprintf( o_f , "%10.7f ", *fptr++); fprintf( o_f , "%10.7f ", *fptr++); fprintf( o_f , "%10.7f ", *fptr++); fprintf( o_f , "%10.7f ", *fptr++); fprintf( o_f , "%10.7f ", *fptr++); fprintf( o_f , "%10.7f ", *fptr++); fprintf( o_f , "\n"); fprintf( o_ftemp, "%10.7f ", *fptr++); fprintf( o_ftemp, "%10.7f ", *fptr++); fprintf( o_ftemp, "%10.7f ", *fptr++); fprintf( o_ftemp, "%10.7f ", *fptr++); fprintf( o_ftemp, "%10.7f ", *fptr++); fprintf( o_ftemp, "%10.7f ", *fptr++); fprintf( o_ftemp, "%10.7f ", *fptr++); fprintf( o_ftemp, "%10.7f ", *fptr++); fprintf( o_ftemp, "%10.7f ", *fptr++); fprintf( o_ftemp, "\n"); } /* while( fptr!=end_ptr) */ fclose( o_feq); fclose( o_f); fclose( o_ftemp); } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ #if WRITE_PDF_TO_TXT for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { frame = time/lattice->param.FrameRate; sprintf( filename, "./out/feq_frame%04d_subs%02d.txt", frame, subs); if( !( o_feq = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/f_frame%04d_subs%02d.txt", frame, subs); if( !( o_f = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/ftemp_frame%04d_subs%02d.txt", frame, subs); if( !( o_ftemp = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } for( i=0; i<lattice->param.LX; i++) { fprintf( o_feq , "-----------"); fprintf( o_feq , "-----------"); fprintf( o_feq , "----------|"); fprintf( o_f , "-----------"); fprintf( o_f , "-----------"); fprintf( o_f , "----------|"); fprintf( o_ftemp, "-----------"); fprintf( o_ftemp, "-----------"); fprintf( o_ftemp, "----------|"); } fprintf( o_feq , "\n"); fprintf( o_f , "\n"); fprintf( o_ftemp, "\n"); for( j=lattice->param.LY-1; j>=0; j--) { n = j*lattice->param.LX; for( i=0; i<lattice->param.LX; i++, n++) { fprintf( o_feq, "%10.6f ", lattice->pdf[subs][n].feq[6] ); fprintf( o_feq, "%10.6f ", lattice->pdf[subs][n].feq[2] ); fprintf( o_feq, "%10.6f|", lattice->pdf[subs][n].feq[5] ); fprintf( o_f, "%10.6f ", lattice->pdf[subs][n].f[6] ); fprintf( o_f, "%10.6f ", lattice->pdf[subs][n].f[2] ); fprintf( o_f, "%10.6f|", lattice->pdf[subs][n].f[5] ); fprintf( o_ftemp,"%10.6f ", lattice->pdf[subs][n].ftemp[6]); fprintf( o_ftemp,"%10.6f ", lattice->pdf[subs][n].ftemp[2]); fprintf( o_ftemp,"%10.6f|", lattice->pdf[subs][n].ftemp[5]); } /* for( i=0; i<lattice->param.LX; i++, n++) */ fprintf( o_feq, "\n"); fprintf( o_f, "\n"); fprintf( o_ftemp,"\n"); n = j*lattice->param.LX; for( i=0; i<lattice->param.LX; i++, n++) { fprintf( o_feq, "%10.6f ", lattice->pdf[subs][n].feq[3] ); fprintf( o_feq, "%10.6f ", lattice->pdf[subs][n].feq[0] ); fprintf( o_feq, "%10.6f|", lattice->pdf[subs][n].feq[1] ); fprintf( o_f, "%10.6f ", lattice->pdf[subs][n].f[3] ); fprintf( o_f, "%10.6f ", lattice->pdf[subs][n].f[0] ); fprintf( o_f, "%10.6f|", lattice->pdf[subs][n].f[1] ); fprintf( o_ftemp,"%10.6f ", lattice->pdf[subs][n].ftemp[3]); fprintf( o_ftemp,"%10.6f ", lattice->pdf[subs][n].ftemp[0]); fprintf( o_ftemp,"%10.6f|", lattice->pdf[subs][n].ftemp[1]); } /* for( i=0; i<lattice->param.LX; i++, n++) */ fprintf( o_feq, "\n"); fprintf( o_f, "\n"); fprintf( o_ftemp,"\n"); n = j*lattice->param.LX; for( i=0; i<lattice->param.LX; i++, n++) { fprintf( o_feq, "%10.6f ", lattice->pdf[subs][n].feq[7] ); fprintf( o_feq, "%10.6f ", lattice->pdf[subs][n].feq[4] ); fprintf( o_feq, "%10.6f|", lattice->pdf[subs][n].feq[8] ); fprintf( o_f, "%10.6f ", lattice->pdf[subs][n].f[7] ); fprintf( o_f, "%10.6f ", lattice->pdf[subs][n].f[4] ); fprintf( o_f, "%10.6f|", lattice->pdf[subs][n].f[8] ); fprintf( o_ftemp,"%10.6f ", lattice->pdf[subs][n].ftemp[7]); fprintf( o_ftemp,"%10.6f ", lattice->pdf[subs][n].ftemp[4]); fprintf( o_ftemp,"%10.6f|", lattice->pdf[subs][n].ftemp[8]); } /* for( i=0; i<lattice->param.LX; i++, n++) */ fprintf( o_feq, "\n"); fprintf( o_f, "\n"); fprintf( o_ftemp,"\n"); for( i=0; i<lattice->param.LX; i++) { fprintf( o_feq , "-----------"); fprintf( o_feq , "-----------"); fprintf( o_feq , "----------|"); fprintf( o_f , "-----------"); fprintf( o_f , "-----------"); fprintf( o_f , "----------|"); fprintf( o_ftemp, "-----------"); fprintf( o_ftemp, "-----------"); fprintf( o_ftemp, "----------|"); } fprintf( o_feq , "\n"); fprintf( o_f , "\n"); fprintf( o_ftemp, "\n"); } /* for( j=lattice->param.LY-1; j>=0; j--) */ fclose( o_feq); fclose( o_f); fclose( o_ftemp); } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ #endif /* WRITE_PDF_TO_TXT */ } /* void dump_pdf( struct lattice_struct *lattice, int time) */ #if NON_LOCAL_FORCES // void dump_forces( struct lattice_struct *lattice) //############################################################################## // // D U M P F O R C E S // // - Output the interactive force values to file. // void dump_forces( struct lattice_struct *lattice) { char filename[1024]; FILE *ox, *oy; int n; double *force; int frame; #if WRITE_RHO_AND_U_TO_TXT int i, j; #endif /* WRITE_RHO_AND_U_TO_TXT */ int subs; for( subs = 0; subs < NUM_FLUID_COMPONENTS; subs++) { frame = (int)((double)lattice->time/(double)lattice->param.FrameRate); #if VERBOSITY_LEVEL > 0 printf("dump_forces() -- frame = %d/%d = %d\n", lattice->time, lattice->param.FrameRate, frame); #endif /* VERBOSITY_LEVEL > 0 */ sprintf( filename, "./out/force_x_frame%04d_subs%02d.dat", frame, subs); if( !( ox = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/force_y_frame%04d_subs%02d.dat", frame, subs); if( !( oy = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } force = lattice->force[subs][0].force; for( n=0; n<lattice->NumNodes; n++) { fprintf( ox, "%20.17f\n", *force++); fprintf( oy, "%20.17f\n", *force++); force += ( sizeof( struct force_struct)/8 - 2); } fclose(ox); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/force_x_frame%04d_subs%02d.dat", frame, subs); #endif /* VERBOSITY_LEVEL > 0 */ printf("dump_forces() -- Wrote file \"%s\"\n", filename); fclose(oy); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/force_y_frame%04d_subs%02d.dat", frame, subs); #endif /* VERBOSITY_LEVEL > 0 */ printf("dump_forces() -- Wrote file \"%s\"\n", filename); #if WRITE_RHO_AND_U_TO_TXT // NOTE: This is very inefficient. But it's only intended // for debugging purposes on small problems. sprintf( filename, "./out/force_x_frame%04d_subs%02d.txt", frame, subs); if( !( ox = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/force_y_frame%04d_subs%02d.txt", frame, subs); if( !( oy = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } for( j=0; j<lattice->param.LY; j++) { n = j*lattice->param.LX; for( i=0; i<lattice->param.LX; i++, n++) { fprintf( ox, "%10.7f ", lattice->force[subs][n].force[0]); fprintf( oy, "%10.7f ", lattice->force[subs][n].force[1]); if( n==lattice->NumNodes) { fprintf( ox, "%10.7f ", 0.); fprintf( oy, "%10.7f ", 0.); } } fprintf( ox, "\n"); fprintf( oy, "\n"); } fclose(ox); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/force_x_frame%04d_subs%02d.txt", frame, subs); #endif /* VERBOSITY_LEVEL > 0 */ printf("dump_forces() -- Wrote file \"%s\"\n", filename); fclose(oy); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/force_y_frame%04d_subs%02d.txt", frame, subs); #endif /* VERBOSITY_LEVEL > 0 */ printf("dump_forces() -- Wrote file \"%s\"\n", filename); #endif /* WRITE_RHO_AND_U_TO_TXT */ } /* for( subs = 0; subs < NUM_FLUID_COMPONENTS; subs++) */ } /* void dump_forces( struct lattice_struct *lattice) */ #endif /* NON_LOCAL_FORCES */ // void dump_checkpoint( struct lattice_struct *lattice, int time, char *fn) //############################################################################## // // D U M P C H E C K P O I N T // // - Write lattice to a checkpoint file. // // - Should be binary and store all information necessary to // restart the current run at this point. // void dump_checkpoint( struct lattice_struct *lattice, int time, char *fn) { } /* void dump_checkpoint( struct lattice_struct *lattice, ...) */ // void read_checkpoint( struct lattice_struct *lattice) //############################################################################## // // R E A D C H E C K P O I N T // // - Read lattice from a checkpoint file (as written by dump_checkpoint). // // - With this information, should be able to restart where // the previous run stopped. // void read_checkpoint( struct lattice_struct *lattice) { } /* void read_checkpoint( struct lattice_struct *lattice) */ // void spy_bmp( char *filename, int ***spy) //############################################################################## // // S P Y B M P // // - Returns matrix 'spy' of ones and zeros. // // - Zeros for white pixels. // // - Ones for non-white pixels. // void spy_bmp( char *filename, lattice_ptr lattice, int **spy) { FILE *in, *o; int i, j, n, m; int pad, bytes_per_row; char k; char b, g, r; struct bitmap_file_header bmfh; struct bitmap_info_header bmih; struct rgb_quad rgb; int *int_ptr; short int *short_int_ptr; int *width_ptr; int *height_ptr; short int *bitcount_ptr; printf("spy_bmp() -- Hi!\n"); // Clear the spy array. for( j=0; j<lattice->param.LY; j++) { for( i=0; i<lattice->param.LX; i++) { spy[j][i] = 0; } } if( !( in = fopen( filename, "r"))) { #if 1 printf("spy_bmp() -- Error opening file \"%s\".\n", filename); process_exit(1); #else printf(" %s::spy_bmp() %d >> File \"%s\" cannot be opened for reading.\n", __FILE__, __LINE__, filename); if( !( o = fopen( filename, "w+"))) { // TODO: Write blank bmp file. } printf(" %s::spy_bmp() %d >> Wrote a blank \"%s\" file.\n", __FILE__, __LINE__, filename); printf(" %s::spy_bmp() %d >> Returning all zeros!\n", __FILE__, __LINE__); fclose( o); return; #endif } // n = fread( void *BUF, size_t SIZE, size_t COUNT, FILE *FP); n = fread( &bmfh, sizeof(struct bitmap_file_header), 1, in ); if( strncmp(bmfh.bfType,"BM",2)) { printf("ERROR: Can't process this file type. Exiting!\n"); printf("\n"); process_exit(1); } n = fread( &bmih, sizeof(struct bitmap_info_header), 1, in ); int_ptr = (int*)bmih.biCompression; if( *int_ptr != 0) { printf("%s %d >> ERROR: Can't handle compressed BMP files. Exiting!\n", __FILE__,__LINE__); printf("\n"); process_exit(1); } width_ptr = (int*)bmih.biWidth; height_ptr = (int*)bmih.biHeight; bitcount_ptr = (short int*)bmih.biBitCount; if( *width_ptr != lattice->param.LX) { printf("%s %d >> ERROR: LX %d does not match the " "width %d of the BMP file. Exiting!\n", __FILE__, __LINE__, lattice->param.LX, *width_ptr); process_exit(1); } if( *height_ptr != lattice->param.LY) { printf("%s %d >> ERROR: LY %d does not match the " "height %d of the BMP file. Exiting!\n", __FILE__, __LINE__, lattice->param.LY, *height_ptr); process_exit(1); } if( *bitcount_ptr < 24) { n = (int)pow(2.,(double)*bitcount_ptr); // Num palette entries. for( i=0; i<n; i++) { k = fread( &rgb, sizeof(struct rgb_quad), 1, in ); if( k!=1) { printf("Error reading palette entry %d. Exiting!\n", i); process_exit(1); } } } // Bytes per row of the bitmap. bytes_per_row = ((int)ceil(( (((double)(*width_ptr))*((double)(*bitcount_ptr)))/8.))); // Bitmaps pad rows to preserve 4-byte boundaries. // The length of a row in the file will be bytes_per_row + pad . pad = ((4) - bytes_per_row%4)%4; n = 0; m = 0; n+=( k = fread( &b, 1, 1, in )); i = 0; j = 0; while( !feof(in)) { switch(*bitcount_ptr) { case 1: // Monochrome. printf("spy_bmp() -- " "Support for Monochrome BMPs is pending. " "Exiting!\n"); process_exit(1); if( i < *width_ptr) { (spy)[j][i] = ( (b & 0x80) == 0); } i++; if( i < *width_ptr) { (spy)[j][i] = ( (b & 0x40) == 0); } i++; if( i < *width_ptr) { (spy)[j][i] = ( (b & 0x20) == 0); } i++; if( i < *width_ptr) { (spy)[j][i] = ( (b & 0x10) == 0); } i++; if( i < *width_ptr) { (spy)[j][i] = ( (b & 0x08) == 0); } i++; if( i < *width_ptr) { (spy)[j][i] = ( (b & 0x04) == 0); } i++; if( i < *width_ptr) { (spy)[j][i] = ( (b & 0x02) == 0); } i++; if( i < *width_ptr) { (spy)[j][i] = ( (b & 0x01) == 0); } i++; break; case 4: // 16 colors. printf("spy_bmp() -- " "Support for 16 color BMPs is pending. " "Exiting!\n"); process_exit(1); if( i < *width_ptr) { (spy)[j][i] = ( (b&0xf0)>>4 != 15); } i++; if( i < *width_ptr) { (spy)[j][i] = ( (b&0x0f) != 15); } i++; break; case 8: // 256 colors. printf("spy_bmp() -- " "Support for 256 color BMPs is pending. " "Exiting!\n"); process_exit(1); if( i < *width_ptr) { (spy)[j][i] = ( (b&0xff) != 255); } i++; break; case 24: // 24-bit colors. if( i < 3*(*width_ptr)) { i++; n+=( k = fread( &g, 1, 1, in )); i++; n+=( k = fread( &r, 1, 1, in )); if( ( (b&0xff) == 0) &&( (g&0xff) == 0) &&( (r&0xff) == 0) ) { (spy)[j][(int)floor((double)i/3.)] = 1; } #if 0 if( ( (b&0xff) == 0) &&( (g&0xff) == 0) &&( (r&0xff) == 255) ) { // Red ==> Inflow, Pressure boundaries. if( (int)floor((double)i/3.) == 0 || (int)floor((double)i/3.) == lattice->param.LX-1 ) { if( !( j==0 || j == lattice->param.LY-1)) { lattice->periodic_x[subs] = 0; } } if( j == 0 || j == lattice->param.LY-1 ) { if( !( (int)floor((double)i/3.) == 0 || (int)floor((double)i/3.) == lattice->param.LX-1)) { lattice->periodic_y[subs] = 0; } } } if( ( (b&0xff) == 0) &&( (g&0xff) == 255) &&( (r&0xff) == 0) ) { // Green ==> Outflow, Pressure boundaries. if( (int)floor((double)i/3.) == 0 || (int)floor((double)i/3.) == lattice->param.LX-1 ) { if( !( j==0 || j == lattice->param.LY-1)) { lattice->periodic_x[subs] = 0; } } if( j == 0 || j == lattice->param.LY-1 ) { if( !( (int)floor((double)i/3.) == 0 || (int)floor((double)i/3.) == lattice->param.LX-1)) { lattice->periodic_y[subs] = 0; } } } #endif } i++; break; default: // 32-bit colors? printf("ERROR: Unhandled color depth, " "BitCount = %d. Exiting!\n", *bitcount_ptr); process_exit(1); break; } /* switch(*(bmih.biBitCount)) */ if( !(n%(bytes_per_row+pad))) { m++; i=0; j++;} n+=( k = fread( &b, 1, 1, in )); } /* while( !feof(in)) */ if( (bytes_per_row+pad)*m!=n) { printf("WARNING: Num bytes read = %d versus num bytes predicted = %d .\n", n, (bytes_per_row+pad)*m); } if( m != *height_ptr) { printf("WARNING: m (%d) != bmih.biHeight (%d).\n", m, *height_ptr); } fclose(in); printf("spy_bmp() -- Bye!\n"); printf("\n"); } /* spy_bmp( char *filename, int **spy) */ // void read_bcs( char *filename, int **bcs) //############################################################################## // // R E A D B C S // // - Read boundary condition information from file. // void read_bcs( lattice_ptr lattice, int **bcs) { FILE *in; char filename[1024]; int i, j, n, m; int ei, ej; int pad, bytes_per_row; char k; char b, g, r; struct bitmap_file_header bmfh; struct bitmap_info_header bmih; struct rgb_quad rgb; int *int_ptr; short int *short_int_ptr; int *width_ptr; int *height_ptr; short int *bitcount_ptr; int subs; printf("read_bcs() -- Hi!\n"); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { // Clear the bcs array. for( j=0; j<lattice->param.LY; j++) { for( i=0; i<lattice->param.LX; i++) { bcs[j][i] = 0; } } sprintf( filename, "./in/%dx%dbc_subs%02d.bmp", lattice->param.LX, lattice->param.LY, subs); if( !( in = fopen( filename, "r"))) { printf("read_bcs() -- Error opening file \"%s\".\n", filename); process_exit(1); } // Read the headers. n = fread( &bmfh, sizeof(struct bitmap_file_header), 1, in ); if( strncmp(bmfh.bfType,"BM",2)) { printf("ERROR: Can't process this file type. Exiting!\n"); printf("\n"); process_exit(1); } n = fread( &bmih, sizeof(struct bitmap_info_header), 1, in ); int_ptr = (int*)bmih.biCompression; if( *int_ptr != 0) { printf("ERROR: Can't handle compression. Exiting!\n"); printf("\n"); process_exit(1); } width_ptr = (int*)bmih.biWidth; height_ptr = (int*)bmih.biHeight; bitcount_ptr = (short int*)bmih.biBitCount; if( *height_ptr != lattice->param.LY) { printf("ERROR: Lattice height does not match " "soil matrix data \"%s\". (%d!=%d) Exiting!\n", filename, lattice->param.LY, *height_ptr ); printf("\n"); process_exit(1); } if( *width_ptr != lattice->param.LX) { printf("ERROR: Lattice width does not match " "soil matrix data \"%s\". (%d!=%d) Exiting!\n", filename, lattice->param.LX, *width_ptr ); printf("\n"); process_exit(1); } // Read the palette, if necessary. if( *bitcount_ptr < 24) { n = (int)pow(2.,(double)*bitcount_ptr); // Num palette entries. for( i=0; i<n; i++) { k = fread( &rgb, sizeof(struct rgb_quad), 1, in ); if( k!=1) { printf("Error reading palette entry %d. Exiting!\n", i); process_exit(1); } } } // Bytes per row of the bitmap. bytes_per_row = ((int)ceil(( (((double)(*width_ptr))*((double)(*bitcount_ptr)))/8.))); // Bitmaps pad rows to preserve 4-byte boundaries. // The length of a row in the file will be bytes_per_row + pad . pad = ((4) - bytes_per_row%4)%4; n = 0; m = 0; n+=( k = fread( &b, 1, 1, in )); i = 0; //j = *height_ptr-1; j = 0;//*height_ptr-1; while( !feof(in)) { switch(*bitcount_ptr) { case 1: // Monochrome. printf("read_bcs() -- " "Support for Monochrome BMPs is pending. " "Exiting!\n"); process_exit(1); if( i < *width_ptr) { (bcs)[j][i] = ( (b & 0x80) == 0); } i++; if( i < *width_ptr) { (bcs)[j][i] = ( (b & 0x40) == 0); } i++; if( i < *width_ptr) { (bcs)[j][i] = ( (b & 0x20) == 0); } i++; if( i < *width_ptr) { (bcs)[j][i] = ( (b & 0x10) == 0); } i++; if( i < *width_ptr) { (bcs)[j][i] = ( (b & 0x08) == 0); } i++; if( i < *width_ptr) { (bcs)[j][i] = ( (b & 0x04) == 0); } i++; if( i < *width_ptr) { (bcs)[j][i] = ( (b & 0x02) == 0); } i++; if( i < *width_ptr) { (bcs)[j][i] = ( (b & 0x01) == 0); } i++; break; case 4: // 16 colors. printf("read_bcs() -- " "Support for 16 color BMPs is pending. " "Exiting!\n"); process_exit(1); if( i < *width_ptr) { (bcs)[j][i] = ( (b&0xf0)>>4 != 15); } i++; if( i < *width_ptr) { (bcs)[j][i] = ( (b&0x0f) != 15); } i++; break; case 8: // 256 colors. printf("read_bcs() -- " "Support for 256 color BMPs is pending. " "Exiting!\n"); process_exit(1); if( i < *width_ptr) { (bcs)[j][i] = ( (b&0xff) != 255); } i++; break; case 24: // 24-bit colors. if( i < 3*(*width_ptr)) { i++; n+=( k = fread( &g, 1, 1, in )); i++; n+=( k = fread( &r, 1, 1, in )); if( ( (b&0xff) == 0) &&( (g&0xff) == 0) &&( (r&0xff) == 255) ) { // R E D ==> Inflow, Pressure boundaries. bcs[j][(int)floor((double)i/3.)] = 1; } if( ( (b&0xff) == 0) &&( (g&0xff) == 255) &&( (r&0xff) == 0) ) { // G R E E N ==> Outflow, Pressure boundaries. bcs[j][(int)floor((double)i/3.)] = 2; } } i++; break; default: // 32-bit colors? printf("ERROR: Unhandled color depth, " "BitCount = %d. Exiting!\n", *bitcount_ptr); process_exit(1); break; } /* switch(*(bmih.biBitCount)) */ if( !(n%(bytes_per_row+pad))) { m++; i=0; j++;} n+=( k = fread( &b, 1, 1, in )); } /* while( !feof(in)) */ if( (bytes_per_row+pad)*m!=n) { printf("WARNING: Num bytes read = %d versus num bytes predicted = %d .\n", n, (bytes_per_row+pad)*m); } if( m != *height_ptr) { printf("WARNING: m (%d) != bmih.biHeight (%d).\n", m, *height_ptr); } fclose(in); ei = lattice->param.LX-1; ej = lattice->param.LY-1; for( n=0; n<lattice->NumNodes; n++) { i = n%lattice->param.LX; j = n/lattice->param.LX; if( bcs[ j][ i] != 0) { //printf("read_bcs() -- n = %d, ( %d, %d) of ( %d, %d).\n", n, i, j, ei, ej); #if 0 if( ( i==0 && j==0 ) || ( i==ei && j==0 ) || ( i==ei && j==ej) || ( i==0 && j==ej) ) { // Skip corners for now. printf("read_bcs() -- WARNING: Skipping corner ( %d, %d).", i, j); } else { #endif #if 0 if( i==0) { // West if( bcs[ j][ i] == 1) { // Inflow lattice->bc[n].bc_type |= BC_PRESSURE_W_IN; //lattice->periodic_x = 0; } else if( bcs[ j][ i] == 2) { // Outflow lattice->bc[n].bc_type |= BC_PRESSURE_W_OUT; //lattice->periodic_x = 0; } else { // Unhandled case. printf("read_bcs() -- Unhandled case: " "bcs[ %d][ %d] = %d . Exiting!\n", i, j, bcs[j][i]); process_exit(1); } } else if( i==ei) { // East if( bcs[ j][ i] == 1) { // Inflow lattice->bc[n].bc_type |= BC_PRESSURE_E_IN; //lattice->periodic_x = 0; } else if( bcs[ j][ i] == 2) { // Outflow lattice->bc[n].bc_type |= BC_PRESSURE_E_OUT; //lattice->periodic_x = 0; } else { // Unhandled case. printf("read_bcs() -- Unhandled case: " "bcs[ %d][ %d] = %d . Exiting!\n", i, j, bcs[j][i]); process_exit(1); } } else #endif if( j==0) { //printf("read_bcs() -- South at i=%d\n", i); // South if( bcs[ j][ i] == 1) { // Inflow lattice->bc[subs][n].bc_type |= BC_PRESSURE_S_IN; //lattice->periodic_y = 0; } else if( bcs[ j][ i] == 2) { // Outflow lattice->bc[subs][n].bc_type |= BC_PRESSURE_S_OUT; //lattice->periodic_y = 0; } else { // Unhandled case. printf("read_bcs() -- Unhandled case: " "bcs[ %d][ %d] = %d . Exiting!\n", i, j, bcs[j][i]); process_exit(1); } } else if( j==ej) { //printf("read_bcs() -- North at i=%d\n", i); // North if( bcs[ j][ i] == 1) { // Inflow lattice->bc[subs][n].bc_type |= BC_PRESSURE_N_IN; //lattice->periodic_y = 0; } else if( bcs[ j][ i] == 2) { // Outflow lattice->bc[subs][n].bc_type |= BC_PRESSURE_N_OUT; //lattice->periodic_y = 0; } else { // Unhandled case. printf("read_bcs() -- Unhandled case: " "bcs[ %d][ %d] = %d . Exiting!\n", i, j, bcs[j][i]); process_exit(1); } } else { // Unhandled case. printf("read_bcs() -- WARNING: " "Support for interior flow bcs is pending! " "Skipping ( i, j) = ( %d, %d).\n", i, j); } #if 0 } #endif } } } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ printf("read_bcs() -- Bye!\n"); printf("\n"); } /* read_bcs( char *filename, int ***bcs, int *height, int *width) */ // void rho2bmp( char *filename, int time) //############################################################################## // // R H O 2 B M P // #if 1 void rho2bmp( lattice_ptr lattice, int time) { FILE *in, *o; int i, j, n, m; int pad, bytes_per_row; int frame; char k; char b; struct bitmap_file_header bmfh; struct bitmap_info_header bmih; struct rgb_quad rgb; int *int_ptr; short int *short_int_ptr; int *width_ptr; int *height_ptr; short int *bitcount_ptr; char filename[1024]; char red_val, green_val, blue_val, val; double fval; double min_rho, max_rho; int subs; double **colormap; int num_colors; #if SAY_HI printf("rho2bmp() -- Hi!\n"); #endif /* SAY_HI */ if( lattice->param.use_colormap) { count_colormap( &num_colors); allocate_colormap( &colormap, num_colors); read_colormap( colormap, num_colors); } for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { frame = time/lattice->param.FrameRate; sprintf( filename, "./in/%dx%d.bmp", lattice->param.LX, lattice->param.LY); if( !( in = fopen( filename, "r"))) { printf("rho2bmp() -- Error opening file \"%s\".\n", filename); process_exit(1); } // n = fread( void *BUF, size_t SIZE, size_t COUNT, FILE *FP); n = fread( &bmfh, sizeof(struct bitmap_file_header), 1, in ); if( strncmp(bmfh.bfType,"BM",2)) { printf("ERROR: Can't process this file type. Exiting!\n"); printf("\n"); process_exit(1); } n = fread( &bmih, sizeof(struct bitmap_info_header), 1, in ); int_ptr = (int*)bmih.biCompression; if( *int_ptr != 0) { printf("ERROR: Can't handle compression. Exiting!\n"); printf("\n"); process_exit(1); } width_ptr = (int*)bmih.biWidth; height_ptr = (int*)bmih.biHeight; bitcount_ptr = (short int*)bmih.biBitCount; // Read palette entries, if applicable. if( *bitcount_ptr < 24) { n = (int)pow(2.,(double)*bitcount_ptr); // Num palette entries. for( i=0; i<n; i++) { k = fread( &rgb, sizeof(struct rgb_quad), 1, in ); if( k!=1) { printf("Error reading palette entry %d. Exiting!\n", i); process_exit(1); } } } fclose(in); // Bytes per row of the bitmap. bytes_per_row = ((int)ceil(( (((double)(*width_ptr))*((double)(*bitcount_ptr)))/8.))); // Bitmaps pad rows to preserve 4-byte boundaries. // The length of a row in the file will be bytes_per_row + pad . pad = ((4) - bytes_per_row%4)%4; compute_min_rho( lattice, &min_rho, subs); compute_max_rho( lattice, &max_rho, subs); sprintf( filename, "./out/rho%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); if( !( o = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } fwrite( &bmfh, sizeof(struct bitmap_file_header), 1, o ); fwrite( &bmih, sizeof(struct bitmap_info_header), 1, o ); for( j=0; j<lattice->param.LY; j++) { n = j*lattice->param.LX; for( i=0; i<lattice->param.LX; i++, n++) { if( lattice->bc[subs][ n].bc_type == /*FLUID_NODE*/0) { if( lattice->param.use_colormap) { if( lattice->param.plot_scale_dynamic) { if( max_rho!=min_rho) { get_color( colormap, num_colors, (lattice->macro_vars[subs][ n].rho - min_rho)/(max_rho-min_rho), &red_val, &green_val, &blue_val ); } else { get_color( colormap, num_colors, 1., &red_val, &green_val, &blue_val ); } } else { get_color( colormap, num_colors, (lattice->macro_vars[subs][ n].rho /( (lattice->param.rho_A[subs]>lattice->param.rho_B[subs]) ?(lattice->param.rho_A[subs]) :(lattice->param.rho_B[subs]) )), &red_val, &green_val, &blue_val ); } } else { if( subs==0) { if( lattice->param.plot_scale_dynamic) { if( max_rho!=min_rho) { fval = ROUND( 255.*( lattice->macro_vars[subs][ n].rho - min_rho) /( max_rho-min_rho)); } else { fval = 255.; } } else { fval = ROUND( 255.*(lattice->macro_vars[subs][ n].rho /( (lattice->param.rho_A[subs]>lattice->param.rho_B[subs]) ?(lattice->param.rho_A[subs]) :(lattice->param.rho_B[subs]) ) )); } if( fval >= 0.) { if( fval <= 255.) { red_val = (char)((int)(255. - fval)%256); green_val = (char)((int)(255. - fval)%256); blue_val = (char)255; } else { red_val = (char)0; green_val = (char)0; blue_val = (char)255; } } else { red_val = (char)((int)(255. + fval)%256); green_val = (char)((int)(255. + fval)%256); blue_val = (char)((int)(255. + fval)%256); // TODO: Issue warning or something? Potential instability? } } /* if( subs==0) */ else // subs == 1 { if( lattice->param.plot_scale_dynamic) { if( max_rho!=min_rho) { fval = ROUND( 255.*( lattice->macro_vars[subs][ n].rho - min_rho) /( max_rho-min_rho)); } else { fval = 0.; } } else { //printf("%s (%d) >> fval = %f -> ", __FILE__, __LINE__, fval); #if INAMURO_SIGMA_COMPONENT fval = ROUND( 255.*(lattice->macro_vars[subs][ n].rho) /(lattice->param.rho_sigma)); #else /* !( INAMURO_SIGMA_COMPONENT) */ fval = ROUND( 255.*(lattice->macro_vars[subs][ n].rho /(lattice->param.rho_A[subs]))); #endif /* INAMURO_SIGMA_COMPONENT */ //printf("%f\n", fval); } if( fval >= 0.) { if( fval <= 255.) { red_val = (char)255; green_val = (char)((int)(255. - fval)%256); blue_val = (char)((int)(255. - fval)%256); } else { red_val = (char)255;//((int)(255. - (fval - 255.))%256); green_val = (char) 0;//((int)(255. - (fval - 255.))%256); blue_val = (char) 0;//((int)(255. - (fval - 255.))%256); } } else { red_val = (char)((int)(255. + fval)%256); green_val = (char)((int)(255. + fval)%256); blue_val = (char)((int)(255. + fval)%256); // TODO: Issue a warning or something? Potential instability? } } /* if( subs==0) else */ } } /* if( lattice->bc[subs][ n].bc_type == 0) */ else // lattice->bc[subs][ n].bc_type != 0 { #if SOLID_COLOR_IS_CHECKERBOARD // Checkerboard pattern over the solids and boundary conditions. if( (i+j)%2) { red_val = (char)200; green_val = (char)200; blue_val = (char)200; val = (char)200; } else { red_val = (char)184; green_val = (char)184; blue_val = (char)184; val = (char)184; } #else /* !( SOLID_COLOR_IS_CHECKERBOARD) */ #if SOLID_COLOR_IS_BLACK red_val = (char)0; green_val = (char)0; blue_val = (char)0; val = (char)0; #else /* !( SOLID_COLOR_IS_BLACK) */ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; #endif /* SOLID_COLOR_IS_BLACK */ #endif /* SOLID_COLOR_IS_CHECKERBOARD */ } /* if( lattice->bc[subs][ n].bc_type == 0) else */ //printf("blue_val( %d, %d) = %d\n", i, j, (int)blue_val); if( fwrite( &blue_val, 1, 1, o) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} //printf("BING %d %d\n", i, j); if( fwrite( &green_val, 1, 1, o) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} //printf("BING %d %d\n", i, j); if( fwrite( &red_val, 1, 1, o) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} //printf("BING %d %d\n", i, j); } /* for( i=0; i<lattice->param.LX; i++) */ // Pad for 4-byte boundaries. val = (char)0; for( i=0; i<pad; i++) { if( fwrite( &val, 1, 1, o) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} } } /* for( j=0; j<lattice->param.LY; j++) */ fclose(o); #if VERBOSITY_LEVEL > 0 printf("rho2bmp() -- Wrote file \"%s\".\n", filename); #endif /* VERBOSITY_LEVEL > 0 */ } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ if( lattice->param.use_colormap) { deallocate_colormap( &colormap, num_colors); } #if SAY_HI printf("rho2bmp() -- Bye!\n"); printf("\n"); #endif /* SAY_HI */ } /* rho2bmp( lattice_ptr lattice, int time) */ #else void rho2bmp( lattice_ptr lattice, int time) { FILE *in, *o; int i, j, n, m; int pad, bytes_per_row; int frame; char k; char b; struct bitmap_file_header bmfh; struct bitmap_info_header bmih; struct rgb_quad rgb; int *int_ptr; short int *short_int_ptr; int *width_ptr; int *height_ptr; short int *bitcount_ptr; char filename[1024]; char red_val, green_val, blue_val, val; double min_rho, max_rho; int subs; #if SAY_HI printf("rho2bmp() -- Hi!\n"); #endif /* SAY_HI */ compute_max_rho( lattice, &min_rho, 0); compute_max_rho( lattice, &max_rho, 1); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { frame = time/lattice->param.FrameRate; sprintf( filename, "./in/%dx%d.bmp", lattice->param.LX, lattice->param.LY); if( !( in = fopen( filename, "r"))) { printf("rho2bmp() -- Error opening file \"%s\".\n", filename); process_exit(1); } // n = fread( void *BUF, size_t SIZE, size_t COUNT, FILE *FP); n = fread( &bmfh, sizeof(struct bitmap_file_header), 1, in ); if( strncmp(bmfh.bfType,"BM",2)) { printf("ERROR: Can't process this file type. Exiting!\n"); printf("\n"); process_exit(1); } n = fread( &bmih, sizeof(struct bitmap_info_header), 1, in ); int_ptr = (int*)bmih.biCompression; if( *int_ptr != 0) { printf("ERROR: Can't handle compression. Exiting!\n"); printf("\n"); process_exit(1); } width_ptr = (int*)bmih.biWidth; height_ptr = (int*)bmih.biHeight; bitcount_ptr = (short int*)bmih.biBitCount; // Read palette entries, if applicable. if( *bitcount_ptr < 24) { n = (int)pow(2.,(double)*bitcount_ptr); // Num palette entries. for( i=0; i<n; i++) { k = fread( &rgb, sizeof(struct rgb_quad), 1, in ); if( k!=1) { printf("Error reading palette entry %d. Exiting!\n", i); process_exit(1); } } } fclose(in); // Bytes per row of the bitmap. bytes_per_row = ((int)ceil(( (((double)(*width_ptr))*((double)(*bitcount_ptr)))/8.))); // Bitmaps pad rows to preserve 4-byte boundaries. // The length of a row in the file will be bytes_per_row + pad . pad = ((4) - bytes_per_row%4)%4; sprintf( filename, "./out/rho%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); if( !( o = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } fwrite( &bmfh, sizeof(struct bitmap_file_header), 1, o ); fwrite( &bmih, sizeof(struct bitmap_info_header), 1, o ); for( j=0; j<lattice->param.LY; j++) { n = j*lattice->param.LX; for( i=0; i<lattice->param.LX; i++, n++) { if( lattice->bc[subs][ n].bc_type == /*FLUID_NODE*/0) { red_val = (char)0; green_val = (char)0; red_val = (char)ROUND( 255.*(lattice->macro_vars[subs][ n].rho - min_rho)/(max_rho-min_rho)); blue_val = (char)255-red_val; } /* if( lattice->bc[subs][ n].bc_type == 0) */ else // lattice->bc[subs][ n].bc_type != 0 { #if SOLID_COLOR_IS_CHECKERBOARD // Checkerboard pattern over the solids and boundary conditions. if( (i+j)%2) { red_val = (char)200; green_val = (char)200; blue_val = (char)200; val = (char)200; } else { red_val = (char)184; green_val = (char)184; blue_val = (char)184; val = (char)184; } #else /* !( SOLID_COLOR_IS_CHECKERBOARD) */ #if SOLID_COLOR_IS_BLACK red_val = (char)0; green_val = (char)0; blue_val = (char)0; val = (char)0; #else /* !( SOLID_COLOR_IS_BLACK) */ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; #endif /* SOLID_COLOR_IS_BLACK */ #endif /* SOLID_COLOR_IS_CHECKERBOARD */ } /* if( lattice->bc[subs][ n].bc_type == 0) else */ //printf("blue_val( %d, %d) = %d\n", i, j, (int)blue_val); if( fwrite( &blue_val, 1, 1, o) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} //printf("BING %d %d\n", i, j); if( fwrite( &green_val, 1, 1, o) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} //printf("BING %d %d\n", i, j); if( fwrite( &red_val, 1, 1, o) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} //printf("BING %d %d\n", i, j); } /* for( i=0; i<lattice->param.LX; i++) */ // Pad for 4-byte boundaries. val = (char)0; for( i=0; i<pad; i++) { if( fwrite( &val, 1, 1, o) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} } } /* for( j=0; j<lattice->param.LY; j++) */ fclose(o); #if VERBOSITY_LEVEL > 0 printf("rho2bmp() -- Wrote file \"%s\".\n", filename); #endif /* VERBOSITY_LEVEL > 0 */ } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ #if SAY_HI printf("rho2bmp() -- Bye!\n"); printf("\n"); #endif /* SAY_HI */ } /* rho2bmp( lattice_ptr lattice, int time) */ #endif // void u2bmp( char *filename, int time) //############################################################################## // // U 2 B M P // void u2bmp( lattice_ptr lattice, int time) { FILE *in, *o_u, *o_ux, *o_uy; int i, j, n, m; int pad, bytes_per_row; int frame; char k; char b; struct bitmap_file_header bmfh; struct bitmap_info_header bmih; struct rgb_quad rgb; int *int_ptr; short int *short_int_ptr; int *width_ptr; int *height_ptr; short int *bitcount_ptr; char filename[1024]; char red_val, green_val, blue_val, val; double max_u[2], maxu; double u_x, u_y, u; int subs; #if SAY_HI printf("u2bmp() -- Hi!\n"); #endif /* SAY_HI */ for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { frame = time/lattice->param.FrameRate; sprintf( filename, "./in/%dx%d.bmp", lattice->param.LX, lattice->param.LY); if( !( in = fopen( filename, "r"))) { printf("u2bmp() -- Error opening file \"%s\".\n", filename); process_exit(1); } // n = fread( void *BUF, size_t SIZE, size_t COUNT, FILE *FP); n = fread( &bmfh, sizeof(struct bitmap_file_header), 1, in ); if( strncmp(bmfh.bfType,"BM",2)) { printf("ERROR: Can't process this file type. Exiting!\n"); printf("\n"); process_exit(1); } n = fread( &bmih, sizeof(struct bitmap_info_header), 1, in ); int_ptr = (int*)bmih.biCompression; if( *int_ptr != 0) { printf("ERROR: Can't handle compression. Exiting!\n"); printf("\n"); process_exit(1); } width_ptr = (int*)bmih.biWidth; height_ptr = (int*)bmih.biHeight; bitcount_ptr = (short int*)bmih.biBitCount; // Read palette entries, if applicable. if( *bitcount_ptr < 24) { n = (int)pow(2.,(double)*bitcount_ptr); // Num palette entries. for( i=0; i<n; i++) { k = fread( &rgb, sizeof(struct rgb_quad), 1, in ); if( k!=1) { printf("Error reading palette entry %d. Exiting!\n", i); process_exit(1); } } } fclose(in); // Bytes per row of the bitmap. bytes_per_row = ((int)ceil(( (((double)(*width_ptr))*((double)(*bitcount_ptr)))/8.))); // Bitmaps pad rows to preserve 4-byte boundaries. // The length of a row in the file will be bytes_per_row + pad . pad = ((4) - bytes_per_row%4)%4; compute_max_u( lattice, max_u, subs); sprintf( filename, "./out/u%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); if( !( o_u = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/u_x%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); if( !( o_ux = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/u_y%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); if( !( o_uy = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } fwrite( &bmfh, sizeof(struct bitmap_file_header), 1, o_u ); fwrite( &bmih, sizeof(struct bitmap_info_header), 1, o_u ); fwrite( &bmfh, sizeof(struct bitmap_file_header), 1, o_ux ); fwrite( &bmih, sizeof(struct bitmap_info_header), 1, o_ux ); fwrite( &bmfh, sizeof(struct bitmap_file_header), 1, o_uy); fwrite( &bmih, sizeof(struct bitmap_info_header), 1, o_uy); //for( j=lattice->param.LY-1; j>=0; j--) for( j=0; j<lattice->param.LY; j++) { n = j*lattice->param.LX; for( i=0; i<lattice->param.LX; i++, n++) { if( lattice->bc[subs][ n].bc_type == /*FLUID_NODE*/0) { #if 1 blue_val = (char)0; green_val = (char)0; red_val = (char)0; u_x = (lattice->macro_vars[subs][ n].u[0]); u_y = (lattice->macro_vars[subs][ n].u[1]); u = sqrt(u_x*u_x + u_y*u_y); maxu = sqrt( max_u[0]*max_u[0] + max_u[1]*max_u[1]); if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { blue_val = (char)ROUND( 128.*fabs(u_x)/max_u[0]); green_val = (char)ROUND( 128.*fabs(u_y)/max_u[1]); } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) */ else // !( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { #if 0 blue_val = (char)ROUND( 255.*fabs(u_x)/max_u[0]); green_val = (char)ROUND( 255.*fabs(u_y)/max_u[1]); red_val = 0.;//(char)ROUND( 128.*fabs(u)/maxu); #else blue_val = (char)ROUND( 255.*((fabs(u_x)!=0.)?(fabs(u_x)/maxu):(0.))); green_val = (char)ROUND( 255.*((fabs(u_y)!=0.)?(fabs(u_y)/maxu):(0.))); red_val = 0.;//(char)ROUND( 128.*((fabs(u )!=0.)?(fabs(u )/maxu):(0.))); #endif } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) else */ #else blue_val = (char)255; green_val = (char)255; red_val = (char)255; u = sqrt(u_x*u_x + u_y*u_y); maxu = sqrt( max_u[0]*max_u[0] + max_u[1]*max_u[1]); //if( fabs(u) > .1*maxu) //{ green_val = (char)ROUND( 255.-255.*fabs(u)/maxu); red_val = (char)ROUND( 255.-255.*fabs(u)/maxu); blue_val = (char)ROUND( 255.-255.*fabs(u)/maxu); //} //else //{ // green_val = (char)0; // red_val = (char)0; // blue_val = (char)0; //} #endif val = (char)0; } /* if( lattice->bc[subs][ n].bc_type == 0) */ else // lattice->bc[subs][ n].bc_type != 0 { #if SOLID_COLOR_IS_CHECKERBOARD // Checkerboard pattern over the solids and boundary conditions. if( (i+j)%2) { red_val = (char)200; green_val = (char)200; blue_val = (char)200; val = (char)200; } else { red_val = (char)184; green_val = (char)184; blue_val = (char)184; val = (char)184; } #else /* !( SOLID_COLOR_IS_CHECKERBOARD) */ #if SOLID_COLOR_IS_BLACK red_val = (char)0; green_val = (char)0; blue_val = (char)0; val = (char)0; #else /* !( SOLID_COLOR_IS_BLACK) */ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; #endif /* SOLID_COLOR_IS_BLACK */ #endif /* SOLID_COLOR_IS_CHECKERBOARD */ } /* if( lattice->bc[subs][ n].bc_type == 0) else */ #if MARK_ORIGIN_FOR_REFERENCE // Mark the origin for reference. if( ( i == 0 && j == 0)) { red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; } #endif /* MARK_ORIGIN_FOR_REFERENCE */ if( fwrite( &blue_val, 1, 1, o_u ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &green_val, 1, 1, o_u ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &red_val, 1, 1, o_u ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( lattice->bc[subs][ n].bc_type == /*FLUID_NODE*/0) { blue_val = (char)0; green_val = (char)0; red_val = (char)0; u_x = (lattice->macro_vars[subs][ n].u[0]); u_y = (lattice->macro_vars[subs][ n].u[1]); val = (char)0; if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { if( u_x > 0) { red_val = val; blue_val = (char)ROUND( 128.*fabs(u_x)/max_u[0]); } else { red_val = (char)ROUND( 128.*fabs(u_x)/max_u[0]); blue_val = val; } } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) */ else // !( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { if( u_x > 0) { red_val = val; blue_val = (char)ROUND( 255.*((fabs(u_x)!=0.)?(fabs(u_x)/max_u[0]):(0.))); } else { red_val = (char)ROUND( 255.*((fabs(u_x)!=0.)?(fabs(u_x)/max_u[0]):(0.))); blue_val = val; } //printf("%s %d >> %f %f %d %d\n",__FILE__,__LINE__, fabs(u_x), max_u[0], (int)red_val, (int)blue_val); } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) else */ } /* if( lattice->bc[subs][ n].bc_type == 0) */ else // lattice->bc[subs][ n].bc_type != 0 { #if SOLID_COLOR_IS_CHECKERBOARD // Checkerboard pattern over the solids and boundary conditions. if( (i+j)%2) { red_val = (char)200; green_val = (char)200; blue_val = (char)200; val = (char)200; } else { red_val = (char)184; green_val = (char)184; blue_val = (char)184; val = (char)184; } #else /* !( SOLID_COLOR_IS_CHECKERBOARD) */ #if SOLID_COLOR_IS_BLACK red_val = (char)0; green_val = (char)0; blue_val = (char)0; val = (char)0; #else /* !( SOLID_COLOR_IS_BLACK) */ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; #endif /* SOLID_COLOR_IS_BLACK */ #endif /* SOLID_COLOR_IS_CHECKERBOARD */ } /* if( lattice->bc[subs][ n].bc_type == 0) else */ #if MARK_ORIGIN_FOR_REFERENCE // Mark the origin for reference. if( ( i == 0 && j == 0)) { red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; } #endif /* MARK_ORIGIN_FOR_REFERENCE */ if( fwrite( &blue_val, 1, 1, o_ux) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &val, 1, 1, o_ux) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &red_val, 1, 1, o_ux) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( lattice->bc[subs][ n].bc_type == /*FLUID_NODE*/0) { blue_val = (char)0; green_val = (char)0; red_val = (char)0; u_x = (lattice->macro_vars[subs][ n].u[0]); u_y = (lattice->macro_vars[subs][ n].u[1]); val = (char)0; if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { if( u_y > 0) { red_val = val; green_val = (char)ROUND( 128.*((fabs(u_y)!=0.)?(fabs(u_y)/max_u[1]):(0.))); } else { red_val = (char)ROUND( 128.*((fabs(u_y)!=0.)?(fabs(u_y)/max_u[1]):(0.))); green_val = val; } } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) */ else // !( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { if( u_y > 0) { blue_val = (char)ROUND( 255.*((fabs(u_y)!=0.)?(fabs(u_y)/max_u[1]):(0.))); green_val = val; } else { blue_val = val; green_val = (char)ROUND( 255.*((fabs(u_y)!=0.)?(fabs(u_y)/max_u[1]):(0.))); } } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) else */ } /* if( lattice->bc[subs][ n].bc_type == 0) */ else // lattice->bc[subs][ n].bc_type != 0 { #if SOLID_COLOR_IS_CHECKERBOARD // Checkerboard pattern over the solids and boundary conditions. if( (i+j)%2) { red_val = (char)200; green_val = (char)200; blue_val = (char)200; val = (char)200; } else { red_val = (char)184; green_val = (char)184; blue_val = (char)184; val = (char)184; } #else /* !( SOLID_COLOR_IS_CHECKERBOARD) */ #if SOLID_COLOR_IS_BLACK red_val = (char)0; green_val = (char)0; blue_val = (char)0; val = (char)0; #else /* !( SOLID_COLOR_IS_BLACK) */ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; #endif /* SOLID_COLOR_IS_BLACK */ #endif /* SOLID_COLOR_IS_CHECKERBOARD */ } /* if( lattice->bc[subs][ n].bc_type == 0) else */ #if MARK_ORIGIN_FOR_REFERENCE // Mark the origin for reference. if( ( i == 0 && j == 0)) { red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; } #endif /* MARK_ORIGIN_FOR_REFERENCE */ if( fwrite( &blue_val, 1, 1, o_uy) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &green_val, 1, 1, o_uy) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &red_val, 1, 1, o_uy) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} } /* for( i=0; i<lattice->param.LY; i++) */ // Pad for 4-byte boundaries. val = (char)0; for( i=0; i<pad; i++) { if( fwrite( &val, 1, 1, o_u ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &val, 1, 1, o_ux) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &val, 1, 1, o_uy) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} } } /* for( j=0; j<lattice->param.LY; j++) */ fclose(o_u ); fclose(o_ux); fclose(o_uy); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/u%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); printf("u2bmp() -- Wrote file \"%s\".\n", filename); sprintf( filename, "./out/u_x%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); printf("u2bmp() -- Wrote file \"%s\".\n", filename); sprintf( filename, "./out/u_y%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); printf("u2bmp() -- Wrote file \"%s\".\n", filename); #endif /* VERBOSITY_LEVEL > 0 */ } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ #if STORE_UEQ frame = time/lattice->param.FrameRate; sprintf( filename, "./in/%dx%d.bmp", lattice->param.LX, lattice->param.LY); if( !( in = fopen( filename, "r"))) { printf("u2bmp() -- Error opening file \"%s\".\n", filename); process_exit(1); } // n = fread( void *BUF, size_t SIZE, size_t COUNT, FILE *FP); n = fread( &bmfh, sizeof(struct bitmap_file_header), 1, in ); if( strncmp(bmfh.bfType,"BM",2)) { printf("ERROR: Can't process this file type. Exiting!\n"); printf("\n"); process_exit(1); } n = fread( &bmih, sizeof(struct bitmap_info_header), 1, in ); int_ptr = (int*)bmih.biCompression; if( *int_ptr != 0) { printf("ERROR: Can't handle compression. Exiting!\n"); printf("\n"); process_exit(1); } width_ptr = (int*)bmih.biWidth; height_ptr = (int*)bmih.biHeight; bitcount_ptr = (short int*)bmih.biBitCount; // Read palette entries, if applicable. if( *bitcount_ptr < 24) { n = (int)pow(2.,(double)*bitcount_ptr); // Num palette entries. for( i=0; i<n; i++) { k = fread( &rgb, sizeof(struct rgb_quad), 1, in ); if( k!=1) { printf("Error reading palette entry %d. Exiting!\n", i); process_exit(1); } } } fclose(in); // Bytes per row of the bitmap. bytes_per_row = ((int)ceil(( (((double)(*width_ptr))*((double)(*bitcount_ptr)))/8.))); // Bitmaps pad rows to preserve 4-byte boundaries. // The length of a row in the file will be bytes_per_row + pad . pad = ((4) - bytes_per_row%4)%4; compute_max_ueq( lattice, max_u); sprintf( filename, "./out/ueq%dx%d_frame%04d.bmp", lattice->param.LX, lattice->param.LY, frame); if( !( o_u = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/ueq_x%dx%d_frame%04d.bmp", lattice->param.LX, lattice->param.LY, frame); if( !( o_ux = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/ueq_y%dx%d_frame%04d.bmp", lattice->param.LX, lattice->param.LY, frame); if( !( o_uy = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } fwrite( &bmfh, sizeof(struct bitmap_file_header), 1, o_u ); fwrite( &bmih, sizeof(struct bitmap_info_header), 1, o_u ); fwrite( &bmfh, sizeof(struct bitmap_file_header), 1, o_ux ); fwrite( &bmih, sizeof(struct bitmap_info_header), 1, o_ux ); fwrite( &bmfh, sizeof(struct bitmap_file_header), 1, o_uy); fwrite( &bmih, sizeof(struct bitmap_info_header), 1, o_uy); //for( j=lattice->param.LY-1; j>=0; j--) for( j=0; j<lattice->param.LY; j++) { n = j*lattice->param.LX; for( i=0; i<lattice->param.LX; i++, n++) { if( lattice->bc[0][ n].bc_type == /*FLUID_NODE*/0) { #if 1 blue_val = (char)0; green_val = (char)0; red_val = (char)0; u_x = (lattice->ueq[ n].u[0]); u_y = (lattice->ueq[ n].u[1]); u = sqrt(u_x*u_x + u_y*u_y); maxu = sqrt( max_u[0]*max_u[0] + max_u[1]*max_u[1]); if( lattice->bc[0][ n].bc_type & BC_SOLID_NODE) { blue_val = (char)ROUND( 128.*fabs(u_x)/max_u[0]); green_val = (char)ROUND( 128.*fabs(u_y)/max_u[1]); } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) */ else // !( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { blue_val = (char)ROUND( 255.*fabs(u_x)/max_u[0]); green_val = (char)ROUND( 255.*fabs(u_y)/max_u[1]); //red_val = (char)ROUND( 128.*fabs(u)/maxu); } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) else */ #else blue_val = (char)255; green_val = (char)255; red_val = (char)255; u = sqrt(u_x*u_x + u_y*u_y); maxu = sqrt( max_u[0]*max_u[0] + max_u[1]*max_u[1]); //if( fabs(u) > .1*maxu) //{ green_val = (char)ROUND( 255.-255.*fabs(u)/maxu); red_val = (char)ROUND( 255.-255.*fabs(u)/maxu); blue_val = (char)ROUND( 255.-255.*fabs(u)/maxu); //} //else //{ // green_val = (char)0; // red_val = (char)0; // blue_val = (char)0; //} #endif val = (char)0; } /* if( lattice->bc[subs][ n].bc_type == 0) */ else // lattice->bc[subs][ n].bc_type != 0 { #if SOLID_COLOR_IS_CHECKERBOARD // Checkerboard pattern over the solids and boundary conditions. if( (i+j)%2) { red_val = (char)200; green_val = (char)200; blue_val = (char)200; val = (char)200; } else { red_val = (char)184; green_val = (char)184; blue_val = (char)184; val = (char)184; } #else /* !( SOLID_COLOR_IS_CHECKERBOARD) */ #if SOLID_COLOR_IS_BLACK red_val = (char)0; green_val = (char)0; blue_val = (char)0; val = (char)0; #else /* !( SOLID_COLOR_IS_BLACK) */ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; #endif /* SOLID_COLOR_IS_BLACK */ #endif /* SOLID_COLOR_IS_CHECKERBOARD */ } /* if( lattice->bc[subs][ n].bc_type == 0) else */ #if MARK_ORIGIN_FOR_REFERENCE // Mark the origin for reference. if( ( i == 0 && j == 0)) { red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; } #endif /* MARK_ORIGIN_FOR_REFERENCE */ if( fwrite( &blue_val, 1, 1, o_u ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &green_val, 1, 1, o_u ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &red_val, 1, 1, o_u ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( lattice->bc[0][ n].bc_type == /*FLUID_NODE*/0) { blue_val = (char)0; green_val = (char)0; red_val = (char)0; u_x = (lattice->ueq[ n].u[0]); u_y = (lattice->ueq[ n].u[1]); val = (char)0; if( lattice->bc[0][ n].bc_type & BC_SOLID_NODE) { if( u_x > 0) { red_val = val; blue_val = (char)ROUND( 128.*fabs(u_x)/max_u[0]); } else { red_val = (char)ROUND( 128.*fabs(u_x)/max_u[0]); blue_val = val; } } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) */ else // !( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { if( u_x > 0) { red_val = val; blue_val = (char)ROUND( 255.*fabs(u_x)/max_u[0]); } else { red_val = (char)ROUND( 255.*fabs(u_x)/max_u[0]); blue_val = val; } } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) else */ } /* if( lattice->bc[subs][ n].bc_type == 0) */ else // lattice->bc[subs][ n].bc_type != 0 { #if SOLID_COLOR_IS_CHECKERBOARD // Checkerboard pattern over the solids and boundary conditions. if( (i+j)%2) { red_val = (char)200; green_val = (char)200; blue_val = (char)200; val = (char)200; } else { red_val = (char)184; green_val = (char)184; blue_val = (char)184; val = (char)184; } #else /* !( SOLID_COLOR_IS_CHECKERBOARD) */ #if SOLID_COLOR_IS_BLACK red_val = (char)0; green_val = (char)0; blue_val = (char)0; val = (char)0; #else /* !( SOLID_COLOR_IS_BLACK) */ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; #endif /* SOLID_COLOR_IS_BLACK */ #endif /* SOLID_COLOR_IS_CHECKERBOARD */ } /* if( lattice->bc[subs][ n].bc_type == 0) else */ #if MARK_ORIGIN_FOR_REFERENCE // Mark the origin for reference. if( ( i == 0 && j == 0)) { red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; } #endif /* MARK_ORIGIN_FOR_REFERENCE */ if( fwrite( &blue_val, 1, 1, o_ux) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &val, 1, 1, o_ux) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &red_val, 1, 1, o_ux) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( lattice->bc[0][ n].bc_type == /*FLUID_NODE*/0) { blue_val = (char)0; green_val = (char)0; red_val = (char)0; u_x = (lattice->ueq[ n].u[0]); u_y = (lattice->ueq[ n].u[1]); val = (char)0; if( lattice->bc[0][ n].bc_type & BC_SOLID_NODE) { if( u_y > 0) { red_val = val; green_val = (char)ROUND( 128.*fabs(u_y)/max_u[1]); } else { red_val = (char)ROUND( 128.*fabs(u_y)/max_u[1]); green_val = val; } } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) */ else // !( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { if( u_y > 0) { blue_val = (char)ROUND( 255.*fabs(u_y)/max_u[1]); green_val = val; } else { blue_val = val; green_val = (char)ROUND( 255.*fabs(u_y)/max_u[1]); } } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) else */ } /* if( lattice->bc[subs][ n].bc_type == 0) */ else // lattice->bc[subs][ n].bc_type != 0 { #if SOLID_COLOR_IS_CHECKERBOARD // Checkerboard pattern over the solids and boundary conditions. if( (i+j)%2) { red_val = (char)200; green_val = (char)200; blue_val = (char)200; val = (char)200; } else { red_val = (char)184; green_val = (char)184; blue_val = (char)184; val = (char)184; } #else /* !( SOLID_COLOR_IS_CHECKERBOARD) */ #if SOLID_COLOR_IS_BLACK red_val = (char)0; green_val = (char)0; blue_val = (char)0; val = (char)0; #else /* !( SOLID_COLOR_IS_BLACK) */ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; #endif /* SOLID_COLOR_IS_BLACK */ #endif /* SOLID_COLOR_IS_CHECKERBOARD */ } /* if( lattice->bc[subs][ n].bc_type == 0) else */ #if MARK_ORIGIN_FOR_REFERENCE // Mark the origin for reference. if( ( i == 0 && j == 0)) { red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; } #endif /* MARK_ORIGIN_FOR_REFERENCE */ if( fwrite( &blue_val, 1, 1, o_uy) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &green_val, 1, 1, o_uy) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &red_val, 1, 1, o_uy) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} } /* for( i=0; i<lattice->param.LY; i++) */ // Pad for 4-byte boundaries. val = (char)0; for( i=0; i<pad; i++) { if( fwrite( &val, 1, 1, o_u ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &val, 1, 1, o_ux) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &val, 1, 1, o_uy) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} } } /* for( j=0; j<lattice->param.LY; j++) */ fclose(o_u ); fclose(o_ux); fclose(o_uy); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/ueq%dx%d_frame%04d.bmp", lattice->param.LX, lattice->param.LY, frame); printf("u2bmp() -- Wrote file \"%s\".\n", filename); sprintf( filename, "./out/ueq_x%dx%d_frame%04d.bmp", lattice->param.LX, lattice->param.LY, frame); printf("u2bmp() -- Wrote file \"%s\".\n", filename); sprintf( filename, "./out/ueq_y%dx%d_frame%04d.bmp", lattice->param.LX, lattice->param.LY, frame); printf("u2bmp() -- Wrote file \"%s\".\n", filename); #endif /* VERBOSITY_LEVEL > 0 */ #endif /* STORE_UEQ */ #if SAY_HI printf("u2bmp() -- Bye!\n"); printf("\n"); #endif /* SAY_HI */ } /* u2bmp( lattice_ptr lattice, int time) */ // void vor2bmp( char *filename, int time) //############################################################################## // // V O R 2 B M P // void vor2bmp( lattice_ptr lattice, int time) { FILE *in, *o_vor; int i, j, n, m; int pad, bytes_per_row; int frame; char k; char b; struct bitmap_file_header bmfh; struct bitmap_info_header bmih; struct rgb_quad rgb; int *int_ptr; short int *short_int_ptr; int *width_ptr; int *height_ptr; short int *bitcount_ptr; char filename[1024]; char red_val, green_val, blue_val, val; double max_vor_p, max_vor_n; double ave_vor_p, ave_vor_n; double vor; int subs; #if SAY_HI printf("vor2bmp() -- Hi!\n"); #endif /* SAY_HI */ for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { frame = time/lattice->param.FrameRate; sprintf( filename, "./in/%dx%d.bmp", lattice->param.LX, lattice->param.LY); if( !( in = fopen( filename, "r"))) { printf("vor2bmp() -- Error opening file \"%s\".\n", filename); process_exit(1); } // n = fread( void *BUF, size_t SIZE, size_t COUNT, FILE *FP); n = fread( &bmfh, sizeof(struct bitmap_file_header), 1, in ); if( strncmp(bmfh.bfType,"BM",2)) { printf("ERROR: Can't process this file type. Exiting!\n"); printf("\n"); process_exit(1); } n = fread( &bmih, sizeof(struct bitmap_info_header), 1, in ); int_ptr = (int*)bmih.biCompression; if( *int_ptr != 0) { printf("ERROR: Can't handle compression. Exiting!\n"); printf("\n"); process_exit(1); } width_ptr = (int*)bmih.biWidth; height_ptr = (int*)bmih.biHeight; bitcount_ptr = (short int*)bmih.biBitCount; // Read palette entries, if applicable. if( *bitcount_ptr < 24) { n = (int)pow(2.,(double)*bitcount_ptr); // Num palette entries. for( i=0; i<n; i++) { k = fread( &rgb, sizeof(struct rgb_quad), 1, in ); if( k!=1) { printf("Error reading palette entry %d. Exiting!\n", i); process_exit(1); } } } fclose(in); // Bytes per row of the bitmap. bytes_per_row = ((int)ceil(( (((double)(*width_ptr))*((double)(*bitcount_ptr)))/8.))); // Bitmaps pad rows to preserve 4-byte boundaries. // The length of a row in the file will be bytes_per_row + pad . pad = ((4) - bytes_per_row%4)%4; compute_max_vor( lattice, &max_vor_p, &max_vor_n, subs); #if 0 && VERBOSITY_LEVEL > 0 printf("vor2bmp() -- max_vor_p = %f\n", max_vor_p); printf("vor2bmp() -- max_vor_n = %f\n", max_vor_n); #endif /* 0 && VERBOSITY_LEVEL > 0 */ compute_ave_vor( lattice, &ave_vor_p, &ave_vor_n, subs); #if 0 && VERBOSITY_LEVEL > 0 printf("vor2bmp() -- ave_vor_p = %f\n", ave_vor_p); printf("vor2bmp() -- ave_vor_n = %f\n", ave_vor_n); #endif /* 0 && VERBOSITY_LEVEL > 0 */ sprintf( filename, "./out/vor%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); if( !( o_vor = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } fwrite( &bmfh, sizeof(struct bitmap_file_header), 1, o_vor ); fwrite( &bmih, sizeof(struct bitmap_info_header), 1, o_vor ); //for( j=lattice->param.LY-1; j>=0; j--) for( j=0; j<lattice->param.LY; j++) { n = j*lattice->param.LX; for( i=0; i<lattice->param.LX; i++, n++) { if( lattice->bc[subs][ n].bc_type == /*FLUID_NODE*/0) { //u_x = (lattice->macro_vars[subs][ n].u[0]); //u_y = (lattice->macro_vars[subs][ n].u[1]); compute_vorticity( lattice, i, j, n, &vor, subs); //if( fabs(vor)/max_vor_p > .5) //{ // printf("vor2bmp() -- vor/max_vor_p = %f/%f = %f\n", vor, max_vor_p, vor/max_vor_p); //} #if 0 blue_val = (char)255; green_val = (char)255; red_val = (char)255; if( vor > 0) { if( 100.*vor/ave_vor_p > 1.) { //printf("vor2bmp() -- vor/ave_vor_p = %f > 1.\n", vor/ave_vor_p); red_val = (char)0; green_val = (char)0; } else { //printf("vor2bmp() -- vor/ave_vor_p = %f <= 1.\n", vor/ave_vor_p); red_val = (char)ROUND( 255.*( 1. - 10000.*(vor/ave_vor_p)*(vor/ave_vor_p))); green_val = (char)ROUND( 255.*( 1. - 10000.*(vor/ave_vor_p)*(vor/ave_vor_p))); } } else { if( 100.*vor/ave_vor_n > 1.) { //printf("vor2bmp() -- vor/ave_vor_n = %f > 1.\n", vor/ave_vor_n); red_val = (char)0; blue_val = (char)0; } else { //printf("vor2bmp() -- vor/ave_vor_n = %f <= 1.\n", vor/ave_vor_n); red_val = (char)ROUND( 255.*( 1. - 10000.*(vor/ave_vor_n)*(vor/ave_vor_n))); blue_val = (char)ROUND( 255.*( 1. - 10000.*(vor/ave_vor_n)*(vor/ave_vor_n))); } } #else #if 0 blue_val = (char)0; green_val = (char)0; red_val = (char)0; // blue_val = //(char)ROUND( 255.*(vor - max_vor_n)/(max_vor_p-max_vor_n)); if( vor >= 0.) { blue_val = (char)ROUND( 255.*(vor)/(max_vor_p)); } else { red_val = (char)ROUND( 255.*(vor)/(max_vor_n)); } #else red_val = (char)ROUND( 255.*(vor - max_vor_n)/(max_vor_p-max_vor_n)); green_val = (char)ROUND( 255.*(vor - max_vor_n)/(max_vor_p-max_vor_n)); blue_val = (char)ROUND( 255.*(vor - max_vor_n)/(max_vor_p-max_vor_n)); #endif #endif val = (char)0; } /* if( lattice->bc[subs][ n].bc_type == 0) */ else // lattice->bc[subs][ n].bc_type != 0 { #if SOLID_COLOR_IS_CHECKERBOARD // Checkerboard pattern over the solids and boundary conditions. if( (i+j)%2) { red_val = (char)200; green_val = (char)200; blue_val = (char)200; val = (char)200; } else { red_val = (char)184; green_val = (char)184; blue_val = (char)184; val = (char)184; } #else /* !( SOLID_COLOR_IS_CHECKERBOARD) */ //#if SOLID_COLOR_IS_BLACK // red_val = (char)0; // green_val = (char)0; // blue_val = (char)0; // val = (char)0; //#else /* !( SOLID_COLOR_IS_BLACK) */ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; //#endif /* SOLID_COLOR_IS_BLACK */ #endif /* SOLID_COLOR_IS_CHECKERBOARD */ } /* if( lattice->bc[subs][ n].bc_type == 0) else */ #if MARK_ORIGIN_FOR_REFERENCE // Mark the origin for reference. if( ( i == 0 && j == 0)) { red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; } #endif /* MARK_ORIGIN_FOR_REFERENCE */ if( fwrite( &blue_val, 1, 1, o_vor ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &green_val, 1, 1, o_vor ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &red_val, 1, 1, o_vor ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} } /* for( i=0; i<lattice->param.LY; i++) */ // Pad for 4-byte boundaries. val = (char)0; for( i=0; i<pad; i++) { if( fwrite( &val, 1, 1, o_vor ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} } } /* for( j=0; j<lattice->param.LY; j++) */ fclose(o_vor ); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/vor%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); printf("vor2bmp() -- Wrote file \"%s\".\n", filename); #endif /* VERBOSITY_LEVEL > 0 */ } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ #if SAY_HI printf("vor2bmp() -- Bye!\n"); printf("\n"); #endif /* SAY_HI */ } /* vor2bmp( lattice_ptr lattice, int time) */ #if NON_LOCAL_FORCES // void force2bmp( char *filename, int time) //############################################################################## // // F O R C E 2 B M P // void force2bmp( lattice_ptr lattice) { FILE *in, *o_u, *o_ux, *o_uy; int i, j, n, m; int pad, bytes_per_row; int frame; char k; char b; struct bitmap_file_header bmfh; struct bitmap_info_header bmih; struct rgb_quad rgb; int *int_ptr; short int *short_int_ptr; int *width_ptr; int *height_ptr; short int *bitcount_ptr; char filename[1024]; char red_val, green_val, blue_val, val; double max_u[2], maxu; double u_x, u_y, u; int subs; #if SAY_HI printf("force2bmp() -- Hi!\n"); #endif /* SAY_HI */ for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { frame = lattice->time/lattice->param.FrameRate; sprintf( filename, "./in/%dx%d.bmp", lattice->param.LX, lattice->param.LY); if( !( in = fopen( filename, "r"))) { printf("force2bmp() -- Error opening file \"%s\".\n", filename); process_exit(1); } // n = fread( void *BUF, size_t SIZE, size_t COUNT, FILE *FP); n = fread( &bmfh, sizeof(struct bitmap_file_header), 1, in ); if( strncmp(bmfh.bfType,"BM",2)) { printf("ERROR: Can't process this file type. Exiting!\n"); printf("\n"); process_exit(1); } n = fread( &bmih, sizeof(struct bitmap_info_header), 1, in ); int_ptr = (int*)bmih.biCompression; if( *int_ptr != 0) { printf("ERROR: Can't handle compression. Exiting!\n"); printf("\n"); process_exit(1); } width_ptr = (int*)bmih.biWidth; height_ptr = (int*)bmih.biHeight; bitcount_ptr = (short int*)bmih.biBitCount; // Read palette entries, if applicable. if( *bitcount_ptr < 24) { n = (int)pow(2.,(double)*bitcount_ptr); // Num palette entries. for( i=0; i<n; i++) { k = fread( &rgb, sizeof(struct rgb_quad), 1, in ); if( k!=1) { printf("Error reading palette entry %d. Exiting!\n", i); process_exit(1); } } } fclose(in); // Bytes per row of the bitmap. bytes_per_row = ((int)ceil(( (((double)(*width_ptr))*((double)(*bitcount_ptr)))/8.))); // Bitmaps pad rows to preserve 4-byte boundaries. // The length of a row in the file will be bytes_per_row + pad . pad = ((4) - bytes_per_row%4)%4; compute_max_u( lattice, max_u, subs); sprintf( filename, "./out/force_%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); if( !( o_u = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/force_x_%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); if( !( o_ux = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/force_y_%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); if( !( o_uy = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } fwrite( &bmfh, sizeof(struct bitmap_file_header), 1, o_u ); fwrite( &bmih, sizeof(struct bitmap_info_header), 1, o_u ); fwrite( &bmfh, sizeof(struct bitmap_file_header), 1, o_ux ); fwrite( &bmih, sizeof(struct bitmap_info_header), 1, o_ux ); fwrite( &bmfh, sizeof(struct bitmap_file_header), 1, o_uy); fwrite( &bmih, sizeof(struct bitmap_info_header), 1, o_uy); //for( j=lattice->param.LY-1; j>=0; j--) for( j=0; j<lattice->param.LY; j++) { n = j*lattice->param.LX; for( i=0; i<lattice->param.LX; i++, n++) { if( lattice->bc[subs][ n].bc_type == /*FLUID_NODE*/0) { #if 1 blue_val = (char)0; green_val = (char)0; red_val = (char)0; u_x = (lattice->force[subs][ n].force[0]); u_y = (lattice->force[subs][ n].force[1]); u = sqrt(u_x*u_x + u_y*u_y); maxu = sqrt( max_u[0]*max_u[0] + max_u[1]*max_u[1]); if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { blue_val = (char)ROUND( 128.*fabs(u_x)/max_u[0]); green_val = (char)ROUND( 128.*fabs(u_y)/max_u[1]); } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) */ else // !( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { blue_val = (char)ROUND( 255.*fabs(u_x)/max_u[0]); green_val = (char)ROUND( 255.*fabs(u_y)/max_u[1]); red_val = (char)ROUND( 128.*fabs(u)/maxu); } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) else */ #else blue_val = (char)255; green_val = (char)255; red_val = (char)255; u = sqrt(u_x*u_x + u_y*u_y); maxu = sqrt( max_u[0]*max_u[0] + max_u[1]*max_u[1]); //if( fabs(u) > .1*maxu) //{ green_val = (char)ROUND( 255.-255.*fabs(u)/maxu); red_val = (char)ROUND( 255.-255.*fabs(u)/maxu); blue_val = (char)ROUND( 255.-255.*fabs(u)/maxu); //} //else //{ // green_val = (char)0; // red_val = (char)0; // blue_val = (char)0; //} #endif val = (char)0; } /* if( lattice->bc[subs][ n].bc_type == 0) */ else // lattice->bc[subs][ n].bc_type != 0 { #if SOLID_COLOR_IS_CHECKERBOARD // Checkerboard pattern over the solids and boundary conditions. if( (i+j)%2) { red_val = (char)200; green_val = (char)200; blue_val = (char)200; val = (char)200; } else { red_val = (char)184; green_val = (char)184; blue_val = (char)184; val = (char)184; } #else /* !( SOLID_COLOR_IS_CHECKERBOARD) */ #if SOLID_COLOR_IS_BLACK red_val = (char)0; green_val = (char)0; blue_val = (char)0; val = (char)0; #else /* !( SOLID_COLOR_IS_BLACK) */ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; #endif /* SOLID_COLOR_IS_BLACK */ #endif /* SOLID_COLOR_IS_CHECKERBOARD */ } /* if( lattice->bc[subs][ n].bc_type == 0) else */ #if MARK_ORIGIN_FOR_REFERENCE // Mark the origin for reference. if( ( i == 0 && j == 0)) { red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; } #endif /* MARK_ORIGIN_FOR_REFERENCE */ if( fwrite( &blue_val, 1, 1, o_u ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &green_val, 1, 1, o_u ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &red_val, 1, 1, o_u ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( lattice->bc[subs][ n].bc_type == /*FLUID_NODE*/0) { blue_val = (char)0; green_val = (char)0; red_val = (char)0; u_x = (lattice->force[subs][ n].force[0]); u_y = (lattice->force[subs][ n].force[1]); val = (char)0; if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { if( u_x > 0) { red_val = val; blue_val = (char)ROUND( 128.*fabs(u_x)/max_u[0]); } else { red_val = (char)ROUND( 128.*fabs(u_x)/max_u[0]); blue_val = val; } } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) */ else // !( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { if( u_x > 0) { red_val = val; blue_val = (char)ROUND( 255.*fabs(u_x)/max_u[0]); } else { red_val = (char)ROUND( 255.*fabs(u_x)/max_u[0]); blue_val = val; } } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) else */ } /* if( lattice->bc[subs][ n].bc_type == 0) */ else // lattice->bc[subs][ n].bc_type != 0 { #if SOLID_COLOR_IS_CHECKERBOARD // Checkerboard pattern over the solids and boundary conditions. if( (i+j)%2) { red_val = (char)200; green_val = (char)200; blue_val = (char)200; val = (char)200; } else { red_val = (char)184; green_val = (char)184; blue_val = (char)184; val = (char)184; } #else /* !( SOLID_COLOR_IS_CHECKERBOARD) */ #if SOLID_COLOR_IS_BLACK red_val = (char)0; green_val = (char)0; blue_val = (char)0; val = (char)0; #else /* !( SOLID_COLOR_IS_BLACK) */ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; #endif /* SOLID_COLOR_IS_BLACK */ #endif /* SOLID_COLOR_IS_CHECKERBOARD */ } /* if( lattice->bc[subs][ n].bc_type == 0) else */ #if MARK_ORIGIN_FOR_REFERENCE // Mark the origin for reference. if( ( i == 0 && j == 0)) { red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; } #endif /* MARK_ORIGIN_FOR_REFERENCE */ if( fwrite( &blue_val, 1, 1, o_ux) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &val, 1, 1, o_ux) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &red_val, 1, 1, o_ux) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( lattice->bc[subs][ n].bc_type == /*FLUID_NODE*/0) { blue_val = (char)0; green_val = (char)0; red_val = (char)0; u_x = (lattice->force[subs][ n].force[0]); u_y = (lattice->force[subs][ n].force[1]); val = (char)0; if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { if( u_y > 0) { red_val = val; green_val = (char)ROUND( 128.*fabs(u_y)/max_u[1]); } else { red_val = (char)ROUND( 128.*fabs(u_y)/max_u[1]); green_val = val; } } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) */ else // !( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { if( u_y > 0) { blue_val = (char)ROUND( 255.*fabs(u_y)/max_u[1]); green_val = val; } else { blue_val = val; green_val = (char)ROUND( 255.*fabs(u_y)/max_u[1]); } } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) else */ } /* if( lattice->bc[subs][ n].bc_type == 0) */ else // lattice->bc[subs][ n].bc_type != 0 { #if SOLID_COLOR_IS_CHECKERBOARD // Checkerboard pattern over the solids and boundary conditions. if( (i+j)%2) { red_val = (char)200; green_val = (char)200; blue_val = (char)200; val = (char)200; } else { red_val = (char)184; green_val = (char)184; blue_val = (char)184; val = (char)184; } #else /* !( SOLID_COLOR_IS_CHECKERBOARD) */ #if SOLID_COLOR_IS_BLACK red_val = (char)0; green_val = (char)0; blue_val = (char)0; val = (char)0; #else /* !( SOLID_COLOR_IS_BLACK) */ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; #endif /* SOLID_COLOR_IS_BLACK */ #endif /* SOLID_COLOR_IS_CHECKERBOARD */ } /* if( lattice->bc[subs][ n].bc_type == 0) else */ #if MARK_ORIGIN_FOR_REFERENCE // Mark the origin for reference. if( ( i == 0 && j == 0)) { red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; } #endif /* MARK_ORIGIN_FOR_REFERENCE */ if( fwrite( &blue_val, 1, 1, o_uy) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &green_val, 1, 1, o_uy) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &red_val, 1, 1, o_uy) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} } /* for( i=0; i<lattice->param.LY; i++) */ // Pad for 4-byte boundaries. val = (char)0; for( i=0; i<pad; i++) { if( fwrite( &val, 1, 1, o_u ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &val, 1, 1, o_ux) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &val, 1, 1, o_uy) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} } } /* for( j=0; j<lattice->param.LY; j++) */ fclose(o_u ); fclose(o_ux); fclose(o_uy); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/force_%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); printf("force2bmp() -- Wrote file \"%s\".\n", filename); sprintf( filename, "./out/force_x_%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); printf("force2bmp() -- Wrote file \"%s\".\n", filename); sprintf( filename, "./out/force_y_%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); printf("force2bmp() -- Wrote file \"%s\".\n", filename); #endif /* VERBOSITY_LEVEL > 0 */ } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ #if SAY_HI printf("force2bmp() -- Bye!\n"); printf("\n"); #endif /* SAY_HI */ } /* void force2bmp( lattice_ptr lattice) */ // void sforce2bmp( char *filename, int time) //############################################################################## // // F O R C E 2 B M P // void sforce2bmp( lattice_ptr lattice) { FILE *in, *o_u, *o_ux, *o_uy; int i, j, n, m; int pad, bytes_per_row; int frame; char k; char b; struct bitmap_file_header bmfh; struct bitmap_info_header bmih; struct rgb_quad rgb; int *int_ptr; short int *short_int_ptr; int *width_ptr; int *height_ptr; short int *bitcount_ptr; char filename[1024]; char red_val, green_val, blue_val, val; double max_u[2], maxu; double u_x, u_y, u; int subs; #if SAY_HI printf("sforce2bmp() -- Hi!\n"); #endif /* SAY_HI */ for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { frame = lattice->time/lattice->param.FrameRate; sprintf( filename, "./in/%dx%d.bmp", lattice->param.LX, lattice->param.LY); if( !( in = fopen( filename, "r"))) { printf("sforce2bmp() -- Error opening file \"%s\".\n", filename); process_exit(1); } // n = fread( void *BUF, size_t SIZE, size_t COUNT, FILE *FP); n = fread( &bmfh, sizeof(struct bitmap_file_header), 1, in ); if( strncmp(bmfh.bfType,"BM",2)) { printf("ERROR: Can't process this file type. Exiting!\n"); printf("\n"); process_exit(1); } n = fread( &bmih, sizeof(struct bitmap_info_header), 1, in ); int_ptr = (int*)bmih.biCompression; if( *int_ptr != 0) { printf("ERROR: Can't handle compression. Exiting!\n"); printf("\n"); process_exit(1); } width_ptr = (int*)bmih.biWidth; height_ptr = (int*)bmih.biHeight; bitcount_ptr = (short int*)bmih.biBitCount; // Read palette entries, if applicable. if( *bitcount_ptr < 24) { n = (int)pow(2.,(double)*bitcount_ptr); // Num palette entries. for( i=0; i<n; i++) { k = fread( &rgb, sizeof(struct rgb_quad), 1, in ); if( k!=1) { printf("Error reading palette entry %d. Exiting!\n", i); process_exit(1); } } } fclose(in); // Bytes per row of the bitmap. bytes_per_row = ((int)ceil(( (((double)(*width_ptr))*((double)(*bitcount_ptr)))/8.))); // Bitmaps pad rows to preserve 4-byte boundaries. // The length of a row in the file will be bytes_per_row + pad . pad = ((4) - bytes_per_row%4)%4; compute_max_u( lattice, max_u, subs); sprintf( filename, "./out/sforce_%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); if( !( o_u = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/sforce_x_%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); if( !( o_ux = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/sforce_y_%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); if( !( o_uy = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } fwrite( &bmfh, sizeof(struct bitmap_file_header), 1, o_u ); fwrite( &bmih, sizeof(struct bitmap_info_header), 1, o_u ); fwrite( &bmfh, sizeof(struct bitmap_file_header), 1, o_ux ); fwrite( &bmih, sizeof(struct bitmap_info_header), 1, o_ux ); fwrite( &bmfh, sizeof(struct bitmap_file_header), 1, o_uy); fwrite( &bmih, sizeof(struct bitmap_info_header), 1, o_uy); //for( j=lattice->param.LY-1; j>=0; j--) for( j=0; j<lattice->param.LY; j++) { n = j*lattice->param.LX; for( i=0; i<lattice->param.LX; i++, n++) { if( lattice->bc[subs][ n].bc_type == /*FLUID_NODE*/0) { #if 1 blue_val = (char)0; green_val = (char)0; red_val = (char)0; u_x = (lattice->force[subs][ n].sforce[0]); u_y = (lattice->force[subs][ n].sforce[1]); u = sqrt(u_x*u_x + u_y*u_y); maxu = sqrt( max_u[0]*max_u[0] + max_u[1]*max_u[1]); if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { blue_val = (char)ROUND( 128.*fabs(u_x)/max_u[0]); green_val = (char)ROUND( 128.*fabs(u_y)/max_u[1]); } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) */ else // !( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { blue_val = (char)ROUND( 255.*fabs(u_x)/max_u[0]); green_val = (char)ROUND( 255.*fabs(u_y)/max_u[1]); red_val = (char)ROUND( 128.*fabs(u)/maxu); } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) else */ #else blue_val = (char)255; green_val = (char)255; red_val = (char)255; u = sqrt(u_x*u_x + u_y*u_y); maxu = sqrt( max_u[0]*max_u[0] + max_u[1]*max_u[1]); //if( fabs(u) > .1*maxu) //{ green_val = (char)ROUND( 255.-255.*fabs(u)/maxu); red_val = (char)ROUND( 255.-255.*fabs(u)/maxu); blue_val = (char)ROUND( 255.-255.*fabs(u)/maxu); //} //else //{ // green_val = (char)0; // red_val = (char)0; // blue_val = (char)0; //} #endif val = (char)0; } /* if( lattice->bc[subs][ n].bc_type == 0) */ else // lattice->bc[subs][ n].bc_type != 0 { #if SOLID_COLOR_IS_CHECKERBOARD // Checkerboard pattern over the solids and boundary conditions. if( (i+j)%2) { red_val = (char)200; green_val = (char)200; blue_val = (char)200; val = (char)200; } else { red_val = (char)184; green_val = (char)184; blue_val = (char)184; val = (char)184; } #else /* !( SOLID_COLOR_IS_CHECKERBOARD) */ #if SOLID_COLOR_IS_BLACK red_val = (char)0; green_val = (char)0; blue_val = (char)0; val = (char)0; #else /* !( SOLID_COLOR_IS_BLACK) */ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; #endif /* SOLID_COLOR_IS_BLACK */ #endif /* SOLID_COLOR_IS_CHECKERBOARD */ } /* if( lattice->bc[subs][ n].bc_type == 0) else */ #if MARK_ORIGIN_FOR_REFERENCE // Mark the origin for reference. if( ( i == 0 && j == 0)) { red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; } #endif /* MARK_ORIGIN_FOR_REFERENCE */ if( fwrite( &blue_val, 1, 1, o_u ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &green_val, 1, 1, o_u ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &red_val, 1, 1, o_u ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( lattice->bc[subs][ n].bc_type == /*FLUID_NODE*/0) { blue_val = (char)0; green_val = (char)0; red_val = (char)0; u_x = (lattice->force[subs][ n].sforce[0]); u_y = (lattice->force[subs][ n].sforce[1]); val = (char)0; if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { if( u_x > 0) { red_val = val; blue_val = (char)ROUND( 128.*fabs(u_x)/max_u[0]); } else { red_val = (char)ROUND( 128.*fabs(u_x)/max_u[0]); blue_val = val; } } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) */ else // !( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { if( u_x > 0) { red_val = val; blue_val = (char)ROUND( 255.*fabs(u_x)/max_u[0]); } else { red_val = (char)ROUND( 255.*fabs(u_x)/max_u[0]); blue_val = val; } } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) else */ } /* if( lattice->bc[subs][ n].bc_type == 0) */ else // lattice->bc[subs][ n].bc_type != 0 { #if SOLID_COLOR_IS_CHECKERBOARD // Checkerboard pattern over the solids and boundary conditions. if( (i+j)%2) { red_val = (char)200; green_val = (char)200; blue_val = (char)200; val = (char)200; } else { red_val = (char)184; green_val = (char)184; blue_val = (char)184; val = (char)184; } #else /* !( SOLID_COLOR_IS_CHECKERBOARD) */ #if SOLID_COLOR_IS_BLACK red_val = (char)0; green_val = (char)0; blue_val = (char)0; val = (char)0; #else /* !( SOLID_COLOR_IS_BLACK) */ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; #endif /* SOLID_COLOR_IS_BLACK */ #endif /* SOLID_COLOR_IS_CHECKERBOARD */ } /* if( lattice->bc[subs][ n].bc_type == 0) else */ #if MARK_ORIGIN_FOR_REFERENCE // Mark the origin for reference. if( ( i == 0 && j == 0)) { red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; } #endif /* MARK_ORIGIN_FOR_REFERENCE */ if( fwrite( &blue_val, 1, 1, o_ux) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &val, 1, 1, o_ux) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &red_val, 1, 1, o_ux) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( lattice->bc[subs][ n].bc_type == /*FLUID_NODE*/0) { blue_val = (char)0; green_val = (char)0; red_val = (char)0; u_x = (lattice->force[subs][ n].sforce[0]); u_y = (lattice->force[subs][ n].sforce[1]); val = (char)0; if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { if( u_y > 0) { red_val = val; green_val = (char)ROUND( 128.*fabs(u_y)/max_u[1]); } else { red_val = (char)ROUND( 128.*fabs(u_y)/max_u[1]); green_val = val; } } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) */ else // !( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { if( u_y > 0) { blue_val = (char)ROUND( 255.*fabs(u_y)/max_u[1]); green_val = val; } else { blue_val = val; green_val = (char)ROUND( 255.*fabs(u_y)/max_u[1]); } } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) else */ } /* if( lattice->bc[subs][ n].bc_type == 0) */ else // lattice->bc[subs][ n].bc_type != 0 { #if SOLID_COLOR_IS_CHECKERBOARD // Checkerboard pattern over the solids and boundary conditions. if( (i+j)%2) { red_val = (char)200; green_val = (char)200; blue_val = (char)200; val = (char)200; } else { red_val = (char)184; green_val = (char)184; blue_val = (char)184; val = (char)184; } #else /* !( SOLID_COLOR_IS_CHECKERBOARD) */ #if SOLID_COLOR_IS_BLACK red_val = (char)0; green_val = (char)0; blue_val = (char)0; val = (char)0; #else /* !( SOLID_COLOR_IS_BLACK) */ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; #endif /* SOLID_COLOR_IS_BLACK */ #endif /* SOLID_COLOR_IS_CHECKERBOARD */ } /* if( lattice->bc[subs][ n].bc_type == 0) else */ #if MARK_ORIGIN_FOR_REFERENCE // Mark the origin for reference. if( ( i == 0 && j == 0)) { red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; } #endif /* MARK_ORIGIN_FOR_REFERENCE */ if( fwrite( &blue_val, 1, 1, o_uy) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &green_val, 1, 1, o_uy) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &red_val, 1, 1, o_uy) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} } /* for( i=0; i<lattice->param.LY; i++) */ // Pad for 4-byte boundaries. val = (char)0; for( i=0; i<pad; i++) { if( fwrite( &val, 1, 1, o_u ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &val, 1, 1, o_ux) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &val, 1, 1, o_uy) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} } } /* for( j=0; j<lattice->param.LY; j++) */ fclose(o_u ); fclose(o_ux); fclose(o_uy); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/sforce_%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); printf("sforce2bmp() -- Wrote file \"%s\".\n", filename); sprintf( filename, "./out/sforce_x_%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); printf("sforce2bmp() -- Wrote file \"%s\".\n", filename); sprintf( filename, "./out/sforce_y_%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); printf("sforce2bmp() -- Wrote file \"%s\".\n", filename); #endif /* VERBOSITY_LEVEL > 0 */ } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ #if SAY_HI printf("sforce2bmp() -- Bye!\n"); printf("\n"); #endif /* SAY_HI */ } /* void sforce2bmp( lattice_ptr lattice) */ #endif /* NON_LOCAL_FORCES */ // void pdf2bmp( char *filename, int time) //############################################################################## // // P D F 2 B M P // void pdf2bmp( lattice_ptr lattice, int time) { FILE *in, *o; int i, j, n, m; int pad, bytes_per_row; int frame; char k; char b; struct bitmap_file_header bmfh; struct bitmap_info_header bmih; struct rgb_quad rgb; int *int_ptr; short int *short_int_ptr; int *width_ptr; int *height_ptr; short int *bitcount_ptr; char filename[1024]; char red_val, green_val, blue_val, val; double fval; double min_rho, max_rho; int subs; double **colormap; int num_colors; int fx=2, fy=2; // Number of pixels to use to represent a pdf value. #if SAY_HI printf("pdf2bmp() -- Hi!\n"); #endif /* SAY_HI */ // TODO: Implement pdf2bmp() printf("%s (%d) >> pdf2bmp() is not yet implemented. Exiting!\n", __FILE__, __LINE__); process_exit(1); #if SAY_HI printf("pdf2bmp() -- Bye!\n"); printf("\n"); #endif /* SAY_HI */ } /* pdf2bmp( lattice_ptr lattice, int time) */ //void slice( lattice_ptr lattice) //############################################################################## // // - Extract slice (i0,j0)..(i1,j1) from the macroscopic variables. // // - Write to matlab scripts for easy processing. // void slice( lattice_ptr lattice) { int i0, j0, i1, j1; int i, j, n; int len; double *rho_slice; double *u_x_slice; double *u_y_slice; char filename[1024]; FILE *in, *o; int subs; if( use_slice_dot_in_file( lattice)) { printf("%s %d >> Using slice.in file.\n",__FILE__,__LINE__); if( !( in = fopen( "./in/slice.in", "r"))) { // Default slice. i0 = 0; j0 = (int)floor((double)lattice->param.LY/2.); i1 = lattice->param.LX-1; j1 = (int)floor((double)lattice->param.LY/2.); } else { // Read slice from file. fscanf( in, "%d", &i0); fscanf( in, "%d", &j0); fscanf( in, "%d", &i1); fscanf( in, "%d", &j1); fclose( in); } private_slice( lattice, "slice", i0, j0, i1, j1); } else { if( get_slice_x( lattice) >= 0) { private_slice( lattice, "slice_x", get_slice_x( lattice), 0, get_slice_x( lattice), get_LY( lattice) ); } if( get_slice_y( lattice) >= 0) { private_slice( lattice, "slice_y", 0, get_slice_y( lattice), get_LX( lattice), get_slice_y( lattice) ); } } } /* void slice( lattice_ptr lattice) */ //void private_slice( lattice_ptr lattice, int i0, int j0, int i1, int j1) //############################################################################## // // - Extract slice (i0,j0)..(i1,j1) from the macroscopic variables. // // - Write to matlab scripts for easy processing. // void private_slice( lattice_ptr lattice, char *root_word, int i0, int j0, int i1, int j1) { int i, j, k, n; int len, wid; double *rho_slice; double *rho_ave; double *u_x_slice; double *u_x_ave; double *u_y_slice; double *u_y_ave; char filename[1024]; FILE *in, *o; double ave_rho; int subs; char plot_specs[2][4] = { { '\'', 'b', '\'', '\x0'}, { '\'', 'r', '\'', '\x0'} }; if( i0 == i1) { if( i0 < 0 || i0 >= get_LX( lattice)) { printf("lbio.c: private_slice() -- " "ERROR: Can't take slice at " "i0 = i1 = %d.\n", i0 ); i0 = lattice->param.LX/2; i1 = lattice->param.LX/2; printf("lbio.c: private_slice() -- Defaulting to i0 = i1 = %d.\n", i0); return; } len = j1 - j0 + 1; if( len > lattice->param.LY) { len = lattice->param.LY; } rho_slice = (double*)malloc( len*sizeof(double)); rho_ave = (double*)malloc( len*sizeof(double)); u_x_slice = (double*)malloc( len*sizeof(double)); u_x_ave = (double*)malloc( len*sizeof(double)); u_y_slice = (double*)malloc( len*sizeof(double)); u_y_ave = (double*)malloc( len*sizeof(double)); // Generate matlab script to plot the slices. sprintf( filename, "./out/%s%dx%d_frame%04d.m", root_word, lattice->param.LX, lattice->param.LY, lattice->time/lattice->param.FrameRate); if( !( o = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } fprintf( o, "%% function [ slice_data] = slice%dx%d_frame%04d( plot_stuff)\n", lattice->param.LX, lattice->param.LY, lattice->time/lattice->param.FrameRate); fprintf( o, "function [ slice_data] = slice%dx%d_frame%04d( plot_stuff)\n\n", lattice->param.LX, lattice->param.LY, lattice->time/lattice->param.FrameRate); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { // Slice. len = 0; for( j=j0; j<=j1; j++) { n = j*lattice->param.LX + i0; if( j>=0 && j<lattice->param.LY) { rho_slice[ len] = lattice->macro_vars[subs][ n].rho; u_x_slice[ len] = lattice->macro_vars[subs][ n].u[0]; u_y_slice[ len] = lattice->macro_vars[subs][ n].u[1]; rho_ave[ len] = 0.; u_x_ave[ len] = 0.; u_y_ave[ len] = 0.; wid = 0; for( i=0; i<lattice->param.LX; i++) { if( !( lattice->bc[subs][ j*lattice->param.LX + i].bc_type & BC_SOLID_NODE)) { rho_ave[ len] += lattice->macro_vars[subs][ j*lattice->param.LX+i].rho; u_x_ave[ len] += lattice->macro_vars[subs][ j*lattice->param.LX+i].u[0]; u_y_ave[ len] += lattice->macro_vars[subs][ j*lattice->param.LX+i].u[1]; wid++; } } rho_ave[ len] /= wid; u_x_ave[ len] /= wid; u_y_ave[ len] /= wid; len++; } } fprintf( o, "rho_slice%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", rho_slice[ n]); } fprintf( o, "];\n"); fprintf( o, "rho_ave%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", rho_ave[ n]); } fprintf( o, "];\n"); fprintf( o, "u_x_slice%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", u_x_slice[ n]); } fprintf( o, "];\n"); fprintf( o, "u_x_ave%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", u_x_ave[ n]); } fprintf( o, "];\n"); fprintf( o, "u_y_slice%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", u_y_slice[ n]); } fprintf( o, "];\n"); fprintf( o, "u_y_ave%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", u_y_ave[ n]); } fprintf( o, "];\n"); } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ fprintf( o, "slice_data = zeros(%d,%d,%d);\n", len, 6, NUM_FLUID_COMPONENTS); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( o, "slice_data(:,1,%d) = rho_slice%02d;\n", subs+1, subs); fprintf( o, "slice_data(:,2,%d) = rho_ave%02d;\n" , subs+1, subs); fprintf( o, "slice_data(:,3,%d) = u_x_slice%02d;\n", subs+1, subs); fprintf( o, "slice_data(:,4,%d) = u_x_ave%02d;\n" , subs+1, subs); fprintf( o, "slice_data(:,5,%d) = u_y_slice%02d;\n", subs+1, subs); fprintf( o, "slice_data(:,6,%d) = u_y_ave%02d;\n" , subs+1, subs); fprintf( o, "disp('slice_data(:,1,%d) = rho_slice%02d');\n", subs+1, subs); fprintf( o, "disp('slice_data(:,2,%d) = rho_ave%02d' );\n", subs+1, subs); fprintf( o, "disp('slice_data(:,3,%d) = u_x_slice%02d');\n", subs+1, subs); fprintf( o, "disp('slice_data(:,4,%d) = u_x_ave%02d' );\n", subs+1, subs); fprintf( o, "disp('slice_data(:,5,%d) = u_y_slice%02d');\n", subs+1, subs); fprintf( o, "disp('slice_data(:,6,%d) = u_y_ave%02d' );\n", subs+1, subs); } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ } /* if( i0 == i1) */ else if( j0 == j1) { if( j0 < 0 || j0 >= lattice->param.LY) { printf("lbio.c: private_slice() -- " "ERROR: Can't take slice at " "j0 = j1 = %d.\n", j0 ); j0 = lattice->param.LY/2; j1 = lattice->param.LY/2; printf("lbio.c: private_slice() -- Defaulting to j0 = j1 = %d.\n", j0); return; } len = i1 - i0 + 1; if( len > lattice->param.LX) { len = lattice->param.LX; } rho_slice = (double*)malloc( len*sizeof(double)); rho_ave = (double*)malloc( len*sizeof(double)); u_x_slice = (double*)malloc( len*sizeof(double)); u_x_ave = (double*)malloc( len*sizeof(double)); u_y_slice = (double*)malloc( len*sizeof(double)); u_y_ave = (double*)malloc( len*sizeof(double)); // Generate matlab script to plot the slices. sprintf( filename, "./out/%s%dx%d_frame%04d.m", root_word, lattice->param.LX, lattice->param.LY, lattice->time/lattice->param.FrameRate); if( !( o = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } fprintf( o, "%% function [ slice_data] = slice%dx%d_frame%04d( plot_stuff)\n", lattice->param.LX, lattice->param.LY, lattice->time/lattice->param.FrameRate); fprintf( o, "function [ slice_data] = slice%dx%d_frame%04d( plot_stuff)\n\n", lattice->param.LX, lattice->param.LY, lattice->time/lattice->param.FrameRate); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { // Slice. len = 0; for( i=i0; i<=i1; i++) { n = j0*lattice->param.LX + i; if( i>=0 && i<lattice->param.LX) { rho_slice[ len] = lattice->macro_vars[subs][ n].rho; u_x_slice[ len] = lattice->macro_vars[subs][ n].u[0]; u_y_slice[ len] = lattice->macro_vars[subs][ n].u[1]; rho_ave[ len] = 0.; u_x_ave[ len] = 0.; u_y_ave[ len] = 0.; wid = 0; for( j=0; j<lattice->param.LY; j++) { if( !( lattice->bc[subs][ j*lattice->param.LX + i].bc_type & BC_SOLID_NODE)) { rho_ave[ len] += lattice->macro_vars[subs][ j*lattice->param.LX+i].rho; u_x_ave[ len] += lattice->macro_vars[subs][ j*lattice->param.LX+i].u[0]; u_y_ave[ len] += lattice->macro_vars[subs][ j*lattice->param.LX+i].u[1]; wid++; } } rho_ave[ len] /= wid; u_x_ave[ len] /= wid; u_y_ave[ len] /= wid; len++; } } fprintf( o, "rho_slice%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", rho_slice[ n]); } fprintf( o, "];\n"); fprintf( o, "rho_ave%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", rho_ave[ n]); } fprintf( o, "];\n"); fprintf( o, "u_x_slice%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", u_x_slice[ n]); } fprintf( o, "];\n"); fprintf( o, "u_x_ave%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", u_x_ave[ n]); } fprintf( o, "];\n"); if(1) { fprintf( o, "u_y_slice%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", u_y_slice[ n]); } fprintf( o, "];\n"); } else { // // Output a series of slices showing entry length effects. // len = 0; // fprintf( o, "u_y_slice%02d_j%d = [ ", subs, j); // for( i=i0; i<=i1; i++) // { // n = j0*lattice->param.LX + i; // if( i>=0 && i<lattice->param.LX) // { // for( j=1; // j<lattice->param.LY-1; // j+=(int)floor(((double)lattice->param.LY/10.)) ) // { // fprintf( o, " %20.17f ", lattice->macro_vars[subs][ n].u[1]); // } // } // } // fprintf( o, "];\n"); } fprintf( o, "u_y_ave%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", u_y_ave[ n]); } fprintf( o, "];\n"); } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ fprintf( o, "slice_data = zeros(%d,%d,%d);\n", len, 6, NUM_FLUID_COMPONENTS); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( o, "slice_data(:,1,%d) = rho_slice%02d;\n", subs+1, subs); fprintf( o, "slice_data(:,2,%d) = rho_ave%02d;\n" , subs+1, subs); fprintf( o, "slice_data(:,3,%d) = u_x_slice%02d;\n", subs+1, subs); fprintf( o, "slice_data(:,4,%d) = u_x_ave%02d;\n" , subs+1, subs); fprintf( o, "slice_data(:,5,%d) = u_y_slice%02d;\n", subs+1, subs); fprintf( o, "slice_data(:,6,%d) = u_y_ave%02d;\n" , subs+1, subs); fprintf( o, "disp('slice_data(:,1,%d) = rho_slice%02d');\n", subs+1, subs); fprintf( o, "disp('slice_data(:,2,%d) = rho_ave%02d' );\n", subs+1, subs); fprintf( o, "disp('slice_data(:,3,%d) = u_x_slice%02d');\n", subs+1, subs); fprintf( o, "disp('slice_data(:,4,%d) = u_x_ave%02d' );\n", subs+1, subs); fprintf( o, "disp('slice_data(:,5,%d) = u_y_slice%02d');\n", subs+1, subs); fprintf( o, "disp('slice_data(:,6,%d) = u_y_ave%02d' );\n", subs+1, subs); } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ } /* if( i0 == i1) else if( j0 == j1) */ else { // Count. len = 0; for( i=i0; i<=i1; i++) { if( i>=0 && i<lattice->param.LX) { j = j0 + (i-i0)*((j1-j0)/(i1-i0)); if( j>=0 && j<lattice->param.LY) { len++; } } } rho_slice = (double*)malloc( len*sizeof(double)); rho_ave = (double*)malloc( len*sizeof(double)); u_x_slice = (double*)malloc( len*sizeof(double)); u_x_ave = (double*)malloc( len*sizeof(double)); u_y_slice = (double*)malloc( len*sizeof(double)); u_y_ave = (double*)malloc( len*sizeof(double)); // Generate matlab script to plot the slices. sprintf( filename, "./out/%s%dx%d_frame%04d.m", root_word, lattice->param.LX, lattice->param.LY, lattice->time/lattice->param.FrameRate); if( !( o = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { // Slice. len = 0; for( i=i0; i<=i1; i++) { if( i>=0 && i<lattice->param.LX) { j = j0 + (i-i0)*((j1-j0)/(i1-i0)); if( j>=0 && j<lattice->param.LY) { n = j*lattice->param.LX + i; if( n != -1) { rho_slice[ len] = lattice->macro_vars[subs][ n].rho; u_x_slice[ len] = lattice->macro_vars[subs][ n].u[0]; u_y_slice[ len] = lattice->macro_vars[subs][ n].u[1]; rho_ave[ len] = 0.; u_x_ave[ len] = 0.; u_y_ave[ len] = 0.; wid = 0; for( k=0; k<lattice->param.LY; k++) { if( !( lattice->bc[subs][ j*lattice->param.LX + i].bc_type & BC_SOLID_NODE)) { rho_ave[ len] += lattice->macro_vars[subs][ k*lattice->param.LX+i].rho; u_x_ave[ len] += lattice->macro_vars[subs][ k*lattice->param.LX+i].u[0]; u_y_ave[ len] += lattice->macro_vars[subs][ k*lattice->param.LX+i].u[1]; wid++; } } rho_ave[ len] /= wid; u_x_ave[ len] /= wid; u_y_ave[ len] /= wid; } else { rho_slice[ len] = 0.; rho_ave[ len] = 0.; u_x_slice[ len] = 0.; u_x_ave[ len] = 0.; u_y_slice[ len] = 0.; u_y_ave[ len] = 0.; } len++; } } } fprintf( o, "rho_slice%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", rho_slice[ n]); } fprintf( o, "];\n"); fprintf( o, "rho_ave%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", rho_ave[ n]); } fprintf( o, "];\n"); fprintf( o, "u_x_slice%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", u_x_slice[ n]); } fprintf( o, "];\n"); fprintf( o, "u_x_ave%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", u_x_ave[ n]); } fprintf( o, "];\n"); fprintf( o, "u_y_slice%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", u_y_slice[ n]); } fprintf( o, "];\n"); fprintf( o, "u_y_ave%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", u_y_ave[ n]); } fprintf( o, "];\n"); } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ } /* if( i0 == i1) else if( j0 == j1) else */ free( rho_slice); free( rho_ave ); free( u_x_slice); free( u_x_ave ); free( u_y_slice); free( u_y_ave ); fprintf( o, "if( plot_stuff)\n"); // Plot density. fprintf( o, "figure;"); fprintf( o, "hold on;"); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( o, "plot( rho_slice%02d, %s);", subs, plot_specs[subs]); } fprintf( o, "warning off;"); fprintf( o, "title('\\rho slice (%d,%d)..(%d,%d)');\n", i0, j0, i1, j1); fprintf( o, "warning on;"); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( o, "figure;"); fprintf( o, "plot( rho_slice%02d, %s);", subs, plot_specs[subs]); fprintf( o, "warning off;"); fprintf( o, "title('\\rho slice (%d,%d)..(%d,%d), subs %d');\n", i0, j0, i1, j1, subs); fprintf( o, "warning on;"); } // Plot average density. fprintf( o, "figure;"); fprintf( o, "hold on;"); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( o, "plot( rho_ave%02d, %s);", subs, plot_specs[subs]); } fprintf( o, "warning off;"); fprintf( o, "title('\\rho_{ave} slice (%d,%d)..(%d,%d)');\n", i0, j0, i1, j1); fprintf( o, "warning on;"); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( o, "figure;"); fprintf( o, "plot( rho_ave%02d, %s);", subs, plot_specs[subs]); fprintf( o, "warning off;"); fprintf( o, "title('\\rho_{ave} slice (%d,%d)..(%d,%d), subs %d');\n", i0, j0, i1, j1, subs); fprintf( o, "warning on;"); } // Plot x velocity. fprintf( o, "figure;"); fprintf( o, "hold on;"); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( o, "plot( u_x_slice%02d, %s);", subs, plot_specs[subs]); } fprintf( o, "warning off;"); fprintf( o, "title('u_x slice (%d,%d)..(%d,%d)');\n", i0, j0, i1, j1); fprintf( o, "warning on;"); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( o, "figure;"); fprintf( o, "plot( u_x_slice%02d, %s);", subs, plot_specs[subs]); fprintf( o, "warning off;"); fprintf( o, "title('u_x slice (%d,%d)..(%d,%d), subs %d');\n", i0, j0, i1, j1, subs); fprintf( o, "warning on;"); } // Plot average x-velocity. fprintf( o, "figure;"); fprintf( o, "hold on;"); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( o, "plot( u_x_ave%02d, %s);", subs, plot_specs[subs]); } fprintf( o, "warning off;"); fprintf( o, "title('ux_{ave} slice (%d,%d)..(%d,%d)');\n", i0, j0, i1, j1); fprintf( o, "warning on;"); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( o, "figure;"); fprintf( o, "plot( u_x_ave%02d, %s);", subs, plot_specs[subs]); fprintf( o, "warning off;"); fprintf( o, "title('ux_{ave} slice (%d,%d)..(%d,%d), subs %d');\n", i0, j0, i1, j1, subs); fprintf( o, "warning on;"); } // Plot y velocity. fprintf( o, "figure;"); fprintf( o, "hold on;"); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( o, "plot( u_y_slice%02d, %s);", subs, plot_specs[subs]); } fprintf( o, "warning off;"); fprintf( o, "title('u_y slice (%d,%d)..(%d,%d)');\n", i0, j0, i1, j1); fprintf( o, "warning on;"); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( o, "figure;"); fprintf( o, "plot( u_y_slice%02d, %s);", subs, plot_specs[subs]); fprintf( o, "warning off;"); fprintf( o, "title('u_y slice (%d,%d)..(%d,%d), subs %d');\n", i0, j0, i1, j1, subs); fprintf( o, "warning on;"); } // Plot average y-velocity. fprintf( o, "figure;"); fprintf( o, "hold on;"); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( o, "plot( u_y_ave%02d, %s);", subs, plot_specs[subs]); } fprintf( o, "warning off;"); fprintf( o, "title('uy_{ave} slice (%d,%d)..(%d,%d)');\n", i0, j0, i1, j1); fprintf( o, "warning on;"); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( o, "figure;"); fprintf( o, "plot( u_y_ave%02d, %s);", subs, plot_specs[subs]); fprintf( o, "warning off;"); fprintf( o, "title('uy_{ave} slice (%d,%d)..(%d,%d), subs %d');\n", i0, j0, i1, j1, subs); fprintf( o, "warning on;"); } #if 1 // Compare with analytical poissuille flow profile. for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { if( lattice->param.gforce[subs][0] == 0 && lattice->param.gforce[subs][1] != 0 ) { // Poisseuille in y direction. fprintf( o, "disp(sprintf('\\nPoisseuille in y direction:'));\n"); fprintf( o, "figure;\n"); fprintf( o, "i0 = %d;\n", i0); fprintf( o, "i1 = %d;\n", i1); fprintf( o, "disp(sprintf(' [ i0 i1] = [ %%d %%d]',i0,i1));\n"); fprintf( o, "H = i1 - i0 + 1;\n"); fprintf( o, "disp(sprintf(' H = %%d', H));\n"); fprintf( o, "R = H/2;\n"); fprintf( o, "disp(sprintf(' R = H/2 = %%20.17f', R));\n"); fprintf( o, "nu = 1/6;\n"); fprintf( o, "disp(sprintf(' nu = %%20.17f', nu));\n"); compute_ave_rho( lattice, &ave_rho, subs); fprintf( o, "rho_ave = %20.17f;\n", ave_rho); fprintf( o, "disp(sprintf(' rho_ave = %%20.17f', rho_ave));\n"); //fprintf( o, "mu = nu*%20.17f;\n", ave_rho); //fprintf( o, "disp(sprintf(' mu = %%20.17f', mu));\n"); fprintf( o, "gforceval = %20.17f;\n", lattice->param.gforce[subs][1]/lattice->param.tau[subs]); fprintf( o, "disp(sprintf(' gforceval = %%20.17f', gforceval));\n"); fprintf( o, "i = [i0:.1:i1];\n" "ucalc = " "( gforceval / (2*nu)) * " "( R^2 - ( abs( i - (i1+i0)/2 ).^2));\n" ); fprintf( o, "disp(sprintf(' size(ucalc) = %%dx%%d\\n',size(ucalc,1),size(ucalc,2)));\n"); fprintf( o, "plot( i, ucalc, 'k');"); fprintf( o, "title('analytical Poiseuille profile');\n"); fprintf( o, "figure;\n"); fprintf( o, "hold on;\n"); fprintf( o, "plot( i, ucalc, 'k');\n"); fprintf( o, "plot( u_y_slice%02d, 'bo');", subs); fprintf( o, "title('LB results overlaying analytical Poiseuille profile');\n"); fprintf( o, "hold off;\n"); } /* if( lattice->param.gforce[subs][0] == 0 && lattice->param.gforce... */ else if( lattice->param.gforce[subs][1] == 0 && lattice->param.gforce[subs][0] != 0 ) { // Poisseuille in x direction. fprintf( o, "disp(sprintf('\\nPoisseuille in x direction:'));\n"); fprintf( o, "figure;\n"); fprintf( o, "j0 = %d;\n", j0); fprintf( o, "j1 = %d;\n", j1); fprintf( o, "disp(sprintf(' [ j0 j1] = [ %%d %%d]',j0,j1));\n"); fprintf( o, "H = j1 - j0 + 1;\n"); fprintf( o, "disp(sprintf(' H = %%d', H));\n"); fprintf( o, "R = H/2;\n"); fprintf( o, "disp(sprintf(' R = H/2 = %%20.17f', R));\n"); fprintf( o, "nu = 1/6;\n"); fprintf( o, "disp(sprintf(' nu = %%20.17f', nu));\n"); compute_ave_rho( lattice, &ave_rho, subs); fprintf( o, "rho_ave = %20.17f;\n", ave_rho); fprintf( o, "disp(sprintf(' rho_ave = %%20.17f', rho_ave));\n"); //fprintf( o, "mu = nu*%20.17f;\n", ave_rho); //fprintf( o, "disp(sprintf(' mu = %%20.17f', mu));\n"); fprintf( o, "gforceval = %20.17f;\n", lattice->param.gforce[subs][0]/lattice->param.tau[subs]); fprintf( o, "disp(sprintf(' gforceval = %%20.17f', gforceval));\n"); fprintf( o, "j = [j0:.1:j1];" "ucalc = " "( gforceval / (2*nu)) * " "( R^2 - ( abs( j - (j1+j0)/2 ).^2));\n" ); fprintf( o, "disp(sprintf(' size(ucalc) = %%dx%%d\\n'," "size(ucalc,1),size(ucalc,2)));\n"); fprintf( o, "plot( j, ucalc, 'k');"); fprintf( o, "title('analytical Poiseuille profile');\n"); fprintf( o, "figure;\n"); fprintf( o, "hold on;\n"); fprintf( o, "plot( j, ucalc, 'k');\n"); fprintf( o, "plot( u_x_slice%02d, 'bo');", subs); fprintf( o, "title('LB results overlaying analytical " "Poiseuille profile');\n"); fprintf( o, "hold off;\n"); //printf( o, "figure;\n"); //fprintf( o, "plot( ucalc(j0+1:10:10*j1+1) - u_x_slice%02d, 'r');", subs); //fprintf( o, "title( 'ucalc - u_x_slice%02d');\n", subs); } /* if( lattice->param.gforce[subs][0] == 0 && lattice->param.gforce... */ // Slice key. (Shows where in the domain the slice cuts.) fprintf( o, "figure; plot( [ %d %d], [ %d %d], 'r-.');", i0, i1, j0, j1); fprintf( o, "axis equal;"); fprintf( o, "axis([ %d %d %d %d]);", 0, lattice->param.LX-1, 0, lattice->param.LY-1); fprintf( o, "title('Slice key.');\n"); #if VERBOSITY_LEVEL > 0 printf("private_slice() -- Wrote file \"%s\".\n", filename); #endif /* VERBOSITY_LEVEL > 0 */ } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ #endif fprintf( o, "end\n"); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( o, "disp(sprintf('q_x = %%f',rho_slice%02d*u_x_slice%02d'/max(size(rho_slice%02d))'));\n", subs, subs, subs); fprintf( o, "disp(sprintf('q_y = %%f',rho_slice%02d*u_y_slice%02d'/max(size(rho_slice%02d))'));\n", subs, subs, subs); } fclose(o); } /* void private_slice( lattice_ptr lattice, int i0, int j0, int i1, int j1) */ #if INAMURO_SIGMA_COMPONENT && STORE_BTC void dump_sigma_btc( lattice_ptr lattice) { FILE *o; char fn[1024]; int n; double D; int btc_spot, start_time; if( lattice->param.sigma_btc_rate <= 0 || lattice->FlowDir==0) { return; } btc_spot = (lattice->param.sigma_btc_spot >= 0) ? (lattice->param.sigma_btc_spot-1) : (((lattice->FlowDir==1)?(lattice->param.LX):(lattice->param.LY))-2-1); start_time = (lattice->param.sigma_start>0) ?(lattice->param.sigma_start) :(0); sprintf( fn, "./out/sigma_btc.m"); o = fopen( fn, "w+"); // Timesteps where measurements are taken. fprintf( o, "ts = [\n"); for( n=1; n<lattice->SizeBTC; n++) { fprintf( o, "%20.17f\n", lattice->param.sigma_btc[5*n+0]-start_time); } fprintf( o, "];\n"); // Break through curve at sigma_spot-1. fprintf( o, "btc01 = [\n"); for( n=1; n<lattice->SizeBTC; n++) { fprintf( o, "%20.17f\n", lattice->param.sigma_btc[5*n+1]); } fprintf( o, "];\n"); // Break through curve at sigma_spot. fprintf( o, "btc02 = [\n"); for( n=1; n<lattice->SizeBTC; n++) { fprintf( o, "%20.17f\n", lattice->param.sigma_btc[5*n+2]); } fprintf( o, "];\n"); // Break through curve at sigma_spot+1. fprintf( o, "btc03 = [\n"); for( n=1; n<lattice->SizeBTC; n++) { fprintf( o, "%20.17f\n", lattice->param.sigma_btc[5*n+3]); } fprintf( o, "];\n"); // Velocity at sigma_spot. fprintf( o, "btc_v = [\n"); for( n=1; n<lattice->SizeBTC; n++) { fprintf( o, "%20.17f\n", lattice->param.sigma_btc[5*n+4]); } fprintf( o, "];\n"); // Concentration gradient. fprintf( o, "dcdx = [\n"); for( n=1; n<lattice->SizeBTC; n++) { fprintf( o, "%20.17f\n", .5*( lattice->param.sigma_btc[5*n+3] - lattice->param.sigma_btc[5*n+1]) ); } fprintf( o, "];\n"); // C*v. fprintf( o, "Cv = [\n"); for( n=1; n<lattice->SizeBTC; n++) { fprintf( o, "%20.17f\n", //lattice->param.sigma_btc[4*n+1]*lattice->param.sigma_btc[4*n+3] ); ( lattice->param.sigma_btc[5*n+2]*lattice->param.sigma_btc[5*n+4]) ); } fprintf( o, "];\n"); // Cf = ( C*v - D*dcdx) / v. D = (1./3.)*(lattice->param.tau[1] - .5); fprintf( o, "Cf = [\n"); for( n=1; n<lattice->SizeBTC; n++) { fprintf( o, "%20.17f\n", ( ( lattice->param.sigma_btc[5*n+2]*lattice->param.sigma_btc[5*n+4]) - ( D)*.5*( lattice->param.sigma_btc[5*n+3] - lattice->param.sigma_btc[5*n+1]) ) / ( lattice->param.sigma_btc[5*n+4]) ); } fprintf( o, "];\n"); fprintf( o, "D = %20.17f;\n", D); fprintf( o, "disp(sprintf('D = %%20.17f',D));\n"); // Plot btc01. //fprintf( o, "figure; plot(btc01);\n"); //fprintf( o, "axis([ %d %d 0 max(max(btc01),%20.17f)])\n", // 1, lattice->SizeBTC+1, lattice->param.rho_sigma); //fprintf( o, "title('BTC at L=%d, t=%d:%d:%d');\n", // btc_spot-1, start_time, // lattice->param.sigma_btc_rate, // lattice->NumTimeSteps ); fprintf( o, "figure;\n"); // SubPlot btc0{1,2,3}. fprintf( o, "subplot(2,2,1);\n"); fprintf( o, "hold on; plot(btc01);\n"); fprintf( o, "hnd = get(gca,'Children');\n"); fprintf( o, "set( hnd(1), 'Color', [ .8 .8 .8]);\n"); fprintf( o, "hold on; plot(btc03);\n"); fprintf( o, "hnd = get(gca,'Children');\n"); fprintf( o, "set( hnd(1), 'Color', [ .8 .8 .8]);\n"); fprintf( o, "hold on; plot(btc02);\n"); fprintf( o, "set(gca,'Xlim',[ 0 size(btc02,1)])\n"); //fprintf( o, "axis([ %d %d 0 max(max(btc02),%20.17f)])\n", // 1, lattice->SizeBTC+1, lattice->param.rho_sigma); fprintf( o, "title('BTC at L\\in\\{%d,%d,%d\\}, t=%d:%d:%d');\n", btc_spot-1, btc_spot, btc_spot+1, start_time, lattice->param.sigma_btc_rate, lattice->NumTimeSteps ); // Plot btc03. //fprintf( o, "figure; plot(btc03);\n"); //fprintf( o, "axis([ %d %d 0 max(max(btc03),%20.17f)])\n", // 1, lattice->SizeBTC+1, lattice->param.rho_sigma); //fprintf( o, "title('BTC at L=%d, t=%d:%d:%d');\n", // btc_spot+1, start_time, // lattice->param.sigma_btc_rate, // lattice->NumTimeSteps ); // SubPlot C*v. fprintf( o, "subplot(2,2,2);\n"); fprintf( o, "plot(Cv);\n"); fprintf( o, "set(gca,'Xlim',[ 0 size(btc02,1)]);\n"); fprintf( o, "title('C*v at L=%d, t=%d:%d:%d');\n", btc_spot, start_time, lattice->param.sigma_btc_rate, lattice->NumTimeSteps ); // SubPlot dcdx. fprintf( o, "subplot(2,2,3);\n"); fprintf( o, "plot(dcdx);\n"); fprintf( o, "set(gca,'Xlim',[ 0 size(btc02,1)]);\n"); fprintf( o, "title('dc/dx at L=%d, t=%d:%d:%d');\n", btc_spot, start_time, lattice->param.sigma_btc_rate, lattice->NumTimeSteps ); // SubPlot Cf. fprintf( o, "subplot(2,2,4);\n"); fprintf( o, "plot(Cf);\n"); fprintf( o, "set(gca,'Xlim',[ 0 size(btc02,1)]);\n"); fprintf( o, "title('Cf=(C*v-D*(dC/dx))/v at L=%d, t=%d:%d:%d');\n", btc_spot, start_time, lattice->param.sigma_btc_rate, lattice->NumTimeSteps ); // Give figure a name (shows up in title bar). fprintf( o, "set(gcf,'Name','Breakthrough curve data at t=%d:%d:%d');\n", start_time, lattice->param.sigma_btc_rate, lattice->NumTimeSteps ); // Plot [Cr(x),'r'][Cr(x-dx),'m'][Cv(x),'g'][Cf(x),'b'] fprintf( o, "figure;\n"); fprintf( o, "hold on;\n"); fprintf( o, "plot( btc02, 'rx');\n"); fprintf( o, "plot(Cf, 'bo');\n"); fprintf( o, "hold off;\n"); fprintf( o, "set(gca,'Xlim',[ 0 size(btc02,1)]);\n"); fprintf( o, "title('Cr=''rx'', Cf=''bo''');\n"); // Give figure a name (shows up in title bar). fprintf( o, "set(gcf,'Name','Resident C_r and flux averaged C_f concentrations " "at t=%d:%d:%d');\n", start_time, lattice->param.sigma_btc_rate, lattice->NumTimeSteps ); // Turn off figure number in title bar. fprintf( o, "set(gcf,'NumberTitle','off');\n"); fprintf( o, "%% FlowDir = %d;\n", lattice->FlowDir); fclose(o); printf("\nBTC (size=%d) stored in file \"%s\".\n", lattice->SizeBTC, fn); } /* void dump_sigma_btc( lattice_ptr lattice) */ #endif /* INAMURO_SIGMA_COMPONENT && STORE_BTC */ //void count_colormap( int *num_colors) //############################################################################## // // C O U N T C O L O R M A P // // - Count colormap entries in file colormap.rgb . // void count_colormap( int *num_colors) { FILE *in; char filename[1024]; double r, g, b; // First, count the number of entries. sprintf( filename, "%s", "./in/colormap.rgb"); if( !( in = fopen( filename, "r+"))) { printf("Error opening file \"%s\" for reading. Exiting!\n", filename); process_exit(1); } *num_colors = 0; fscanf( in, "%lf %lf %lf", &r, &g, &b); while( !feof(in)) { (*num_colors)++; fscanf( in, "%lf %lf %lf", &r, &g, &b); } fclose(in); } /* void count_colormap( int *num_colors) */ //void allocate_colormap( double ***colormap, int *num_colors) //############################################################################## // // A L L O C A T E C O L O R M A P // void allocate_colormap( double ***colormap, int num_colors) { int i; *colormap = (double**)malloc( num_colors*sizeof(double*)); for( i=0; i<num_colors; i++) { (*colormap)[i] = (double*)malloc( 3*sizeof(double)); } } /* void allocate_colormap( double ***colormap, int num_colors) */ //void read_colormap( double **colormap, int num_colors) //############################################################################## // // R E A D C O L O R M A P // // - Read colormap from file colormap.rgb . // // - Color map values are stored with one set of rgb values per line. // // - RGB values are stored between 0 and 1 . // // - Colormap values could come from Matlab, e.g. // // >> cm = colormap; // >> save 'colormap.rgb' cm -ascii; // void read_colormap( double **colormap, int num_colors) { FILE *in; char filename[1024]; double r, g, b; int n; sprintf( filename, "%s", "./in/colormap.rgb"); if( !( in = fopen( filename, "r+"))) { printf("Error opening file \"%s\" for reading. Exiting!\n", filename); process_exit(1); } n = 0; fscanf( in, "%lf %lf %lf", &r, &g, &b); while( !feof(in)) { assert( n!=num_colors); colormap[n][0] = r; colormap[n][1] = g; colormap[n][2] = b; n++; fscanf( in, "%lf %lf %lf", &r, &g, &b); } fclose(in); } /* void read_colormap( double **colormap, int num_colors) */ //void deallocate_colormap( double ***colormap, int num_colors) //############################################################################## // // D E A L L O C A T E C O L O R M A P // void deallocate_colormap( double ***colormap, int num_colors) { int i; for( i=0; i<num_colors; i++) { free( (*colormap)[i]); } free( *colormap); } /* void deallocate_colormap( double ***colormap, int num_colors) */ void get_color( double **colormap, int num_colors, double c, char *r, char *g, char *b) { int n; double n1, n2; double w1, w2; if( c>=0. && c<=1.) { #if 1 n = (int)ROUND( c*((double)num_colors-1.)); // printf("get_color() -- c = %f, num_colors = %d, n = %d\n", c, num_colors, n); *r = (char)ROUND(255.*colormap[ n][0]); *g = (char)ROUND(255.*colormap[ n][1]); *b = (char)ROUND(255.*colormap[ n][2]); // printf("get_color() -- n = %d, (%f,%f,%f)\n", n, (double)*r, (double)*g, (double)*b); #else n1 = floor( c*((double)num_colors-1.)); n2 = ceil( c*((double)num_colors-1.)); w1 = c-n1; w2 = n2-c; *r = (char)ROUND(255.* ( w1*colormap[ (int)n1][0] + w2*colormap[ (int)n2][0])); *g = (char)ROUND(255.* ( w1*colormap[ (int)n1][1] + w2*colormap[ (int)n2][1])); *b = (char)ROUND(255.* ( w1*colormap[ (int)n1][2] + w2*colormap[ (int)n2][2])); #endif } else { *r = (char)(255.); *g = (char)(255.); *b = (char)(255.); } } /* void get_color( double **colormap, int num_colors, double c, ... */ #if WRITE_CHEN_DAT_FILES void chen_output( lattice_ptr lattice) { int x, y; int LX = lattice->param.LX, LY = lattice->param.LY; double *u, *rho[NUM_FLUID_COMPONENTS]; double ux_sum, uy_sum, rho_in, rho_out; FILE *app7, *app8, *app9; char filename[1024]; double sum_mass[NUM_FLUID_COMPONENTS]; int subs; ux_sum = 0.; uy_sum = 0.; for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { sum_mass[ subs] = 0.; } sprintf( filename, "%s", "./out/chen_xyrho.dat"); if( !( app7 = fopen( filename,"a"))) { printf("Error opening \"%s\" for reading. Exiting!\n", filename); process_exit(1); } sprintf( filename, "%s", "./out/chen_xy_ux_uy.dat"); if( !( app8 = fopen( filename,"a"))) { printf("Error opening \"%s\" for reading. Exiting!\n", filename); process_exit(1); } sprintf( filename, "%s", "./out/chen_time.dat"); if( !( app9 = fopen( filename,"a"))) { printf("Error opening \"%s\" for reading. Exiting!\n", filename); process_exit(1); } #if STORE_UEQ u = lattice->ueq[0].u; #else /* !( STORE_UEQ) */ u = lattice->macro_vars[0][0].u; #endif /* STORE_UEQ */ for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { rho[subs] = &( lattice->macro_vars[subs][0].rho); } for( y = 0; y < LY; y++) { for( x = 0; x < LX; x++) { fprintf( app8, " %9.1f %9.1f %13.5e %13.5e\n", (double)(x+1.), (double)(y+1.), *u, *(u+1)); if( !( lattice->bc[0][ y*LX + x].bc_type & BC_SOLID_NODE)) { ux_sum = ux_sum + *u; uy_sum = uy_sum + *(u+1); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { sum_mass[subs] = sum_mass[subs] + *rho[subs]; } } /* if( !obst[y][x]) */ #if STORE_UEQ u+=2; #else /* !( STORE_UEQ) */ u+=3; #endif /* STORE_UEQ */ for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { rho[subs]+=3; } } /* for( x = 1; x <= LX; x++) */ } /* for( y = 1; y <= LY; y++) */ fprintf( app9, "%10d %15.7f %15.7f ", lattice->time, ux_sum, uy_sum); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( app9, "%15.7f ", sum_mass[subs]); } fprintf( app9, "\n"); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { rho[subs] = &( lattice->macro_vars[subs][0].rho); } for( y = 0; y < LY; y++) { for( x = 0; x < LX; x++) { if( !( lattice->bc[0][ y*LX + x].bc_type & BC_SOLID_NODE)) { for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( app7, "%f ", *rho[subs]); } fprintf( app7, "\n"); } else { for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( app7, "%f ", 0.); } fprintf( app7, "\n"); } for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { rho[subs]+=3; } } /* for( x = 1; x <= LX; x++) */ } /* for( y = 1; y <= LY; y++) */ fclose( app7); fclose( app8); fclose( app9); #if VERBOSITY_LEVEL > 0 sprintf( filename, "%s", "./out/chen_xyrho.dat"); printf("chen_output() -- Wrote file \"%s\".\n", filename); sprintf( filename, "%s", "./out/chen_xy_ux_uy.dat"); printf("chen_output() -- Wrote file \"%s\".\n", filename); sprintf( filename, "%s", "./out/chen_time.dat"); printf("chen_output() -- Wrote file \"%s\".\n", filename); #endif /* VERBOSITY_LEVEL > 0 */ } /* void chen_output( lattice_ptr lattice) */ #endif /* WRITE_CHEN_DAT_FILES */ //void bmp_read_header( FILE *in) //############################################################################## // // B M P R E A D H E A D E R // void bmp_read_header( FILE *in, struct bitmap_info_header *bmih) { char filename[1024]; int i, j, n, m; int ei, ej; int pad, bytes_per_row; char k; char b, g, r; struct bitmap_file_header bmfh; struct rgb_quad rgb; int *int_ptr; short int *short_int_ptr; int *width_ptr; int *height_ptr; short int *bitcount_ptr; int subs; // Read the headers. n = fread( &bmfh, sizeof(struct bitmap_file_header), 1, in ); if( strncmp(bmfh.bfType,"BM",2)) { printf("ERROR: Can't process this file type. Exiting!\n"); printf("\n"); process_exit(1); } n = fread( bmih, sizeof(struct bitmap_info_header), 1, in ); int_ptr = (int*)bmih->biCompression; if( *int_ptr != 0) { printf("ERROR: Can't handle compression. Exiting!\n"); printf("\n"); process_exit(1); } width_ptr = (int*)bmih->biWidth; height_ptr = (int*)bmih->biHeight; bitcount_ptr = (short int*)bmih->biBitCount; // Read the palette, if necessary. if( *bitcount_ptr < 24) { n = (int)pow(2.,(double)*bitcount_ptr); // Num palette entries. for( i=0; i<n; i++) { k = fread( &rgb, sizeof(struct rgb_quad), 1, in ); if( k!=1) { printf("Error reading palette entry %d. Exiting!\n", i); process_exit(1); } } } // Bytes per row of the bitmap. bytes_per_row = ((int)ceil(( (((double)(*width_ptr))*((double)(*bitcount_ptr)))/8.))); // Bitmaps pad rows to preserve 4-byte boundaries. // The length of a row in the file will be bytes_per_row + pad . pad = ((4) - bytes_per_row%4)%4; } /* void bmp_read_header( FILE *in) */ //void bmp_read_entry( FILE *in, char *r, char *g, char *b) //############################################################################## // // B M P R E A D E N T R Y // void bmp_read_entry( FILE *in, struct bitmap_info_header bmih, char *r, char *g, char *b) { char filename[1024]; int i, j, m; static int n=0; int ei, ej; int pad, bytes_per_row; char k, p; struct bitmap_file_header bmfh; struct rgb_quad rgb; int *int_ptr; short int *short_int_ptr; int *width_ptr; int *height_ptr; short int *bitcount_ptr; int subs; width_ptr = (int*)bmih.biWidth; height_ptr = (int*)bmih.biHeight; bitcount_ptr = (short int*)bmih.biBitCount; // Bytes per row of the bitmap. bytes_per_row = ((int)ceil(( (((double)(*width_ptr))*((double)(*bitcount_ptr)))/8.))); // Bitmaps pad rows to preserve 4-byte boundaries. // The length of a row in the file will be bytes_per_row + pad . pad = ((4) - bytes_per_row%4)%4; if( (n%(bytes_per_row+pad)) == 3*(*width_ptr)) { // Read pad bytes first. for( i=1; i<=pad; i++) { if( !feof(in)) { n+=( k = fread( &p, 1, 1, in ));} } } if( feof(in)) { printf( "bmp_read_entry() -- ERROR:" "Attempt to read past the end of file. " "Exiting!\n"); process_exit(1); } switch(*bitcount_ptr) { case 1: // Monochrome. printf("read_bcs() -- " "Support for Monochrome BMPs is pending. " "Exiting!\n"); process_exit(1); case 4: // 16 colors. printf("read_bcs() -- " "Support for 16 color BMPs is pending. " "Exiting!\n"); process_exit(1); case 8: // 256 colors. printf("read_bcs() -- " "Support for 256 color BMPs is pending. " "Exiting!\n"); process_exit(1); case 24: // 24-bit colors. if( !feof(in)) { n+=( k = fread( b, 1, 1, in ));} if( !feof(in)) { n+=( k = fread( g, 1, 1, in ));} if( !feof(in)) { n+=( k = fread( r, 1, 1, in ));} break; default: // 32-bit colors? printf("ERROR: Unhandled color depth, " "BitCount = %d. Exiting!\n", *bitcount_ptr); process_exit(1); break; } /* switch(*(bmih.biBitCount)) */ if( feof(in)) { printf( "bmp_read_entry() -- ERROR:" "Attempt to read past the end of file. " "Exiting!\n"); process_exit(1); } } /* void bmp_read_entry( FILE *in, char *r, char *g, char *b) */ void report_open( report_ptr report, char *name) { sprintf( report->name, "%s.txt", name); #if VERBOSITY_LEVEL >=1 printf( "\n"); printf( "%s\n", HRULE1); printf( " R E P O R T\n"); printf( "%s\n", HRULE1); printf( "\n"); #endif /* VERBOSITY_LEVEL > 1 */ if( !( report->file = fopen( report->name, "w+"))) { printf("%s %d: ERROR: fopen( %s, \"w+\") = %d\n", __FILE__, __LINE__, report->name, (int)(report->file)); } else { fprintf( report->file, "\n"); fprintf( report->file, "%s\n", HRULE1); fprintf( report->file, " R E P O R T\n"); fprintf( report->file, "%s\n", HRULE1); fprintf( report->file, "\n"); } } /* void report_open( report_ptr report, char *name) */ void report_close( report_ptr report) { #if VERBOSITY_LEVEL >=1 printf( "%s\n", HRULE1); printf( "\n"); #endif /* VERBOSITY_LEVEL >=1 */ if( report->file) { //fprintf( report->file, ""); fprintf( report->file, "\n"); fclose( report->file); #if VERBOSITY_LEVEL >=1 printf( "See file \"%s\".\n", report->name); #endif /* VERBOSITY_LEVEL >=1 */ } /* if( report->file) */ } /* void report_close( report_ptr report) */ void report_entry( report_ptr report, char *entry_left, char *entry_right) { char dots[80]; const int left_col_width = 50; int n; // Fill with dots between columns. Careful if length of left // entry is too long. if( left_col_width > strlen(entry_left) + 2) { dots[ 0] = ' '; for( n=1; n<left_col_width-strlen(entry_left); n++) { dots[n]='.'; } dots[ n ] = ' '; dots[ n+1] = (char)NULL; } else if( left_col_width > strlen(entry_left)) { dots[ 0] = ' '; dots[ left_col_width-strlen(entry_left)-1] = ' '; dots[ left_col_width-strlen(entry_left) ] = ' '; dots[ left_col_width-strlen(entry_left)+1] = (char)NULL; } else { dots[0] = ' '; dots[1] = (char)NULL; } #if VERBOSITY_LEVEL >=1 printf(" %s%s%s\n", entry_left, dots, entry_right); //printf("\n"); #endif /* VERBOSITY_LEVEL >=1 */ if( report->file) { fprintf( report->file, " %s%s%s\n", entry_left, dots, entry_right); //fprintf( report->file, "\n"); } } /* void report_entry( char *entry_left, char *entry_right) */ void report_integer_entry( report_ptr report, char *label, int value, char *units) { char entry[1024]; sprintf( entry, "%d %s", value, units); report_entry( report, label, entry); } /* void report_integer_entry( char *label, int value, char *units) */ void report_ratio_entry( report_ptr report, char *label, double num, double den, char *units) { char entry[1024]; if( den!=0) { sprintf( entry, "%f %s", num/den, units); } else { sprintf( entry, "UNDEF %s", units); } report_entry( report, label, entry); } /* void report_integer_entry( char *label, int value, char *units) */ void report_partition( report_ptr report) { printf( "%s\n", HRULE0); printf( "\n"); if( report->file) { fprintf( report->file, "%s\n", HRULE0); fprintf( report->file, "\n"); } } /* void report_partition( report_ptr report) */ //
111pjb-one
src/lbio_bak04062005_01.c
C
gpl3
171,090
//############################################################################## // // user_stuff.h // // - This file includes a definition of the struct user_struct, which the // user should fill in with whatever they want. It will be accessed // from the lattice structure as lattice->user_stuff->whatever // // - This file also has forward declarations for the user_stuff functions. // These functions are defined in user_stuff.c. The user should put in // them whatever they want. See user_stuff.c for more information. // // struct user_stuff_struct { double rho_c; double rho_c_start; double rho_c_inc; double rho_c_reverse; double rho_ave; double rho_ave_prev; double u_ave[2]; double u_ave_prev[2]; double tol; FILE *o; }; typedef struct user_stuff_struct *user_stuff_ptr; void user_stuff_pre_frames( lattice_ptr lattice); void user_stuff_frame( lattice_ptr lattice); void user_stuff_post_frames( lattice_ptr lattice); void user_stuff_pre_times( lattice_ptr lattice); void user_stuff_time( lattice_ptr lattice); void user_stuff_post_times( lattice_ptr lattice);
111pjb-one
src/user_stuff_20070615_scmp_contact_angles.h
C
gpl3
1,116
//############################################################################## // // user_stuff.c // // - This file has function definitions of functions that will be called // at specified times (see individual function documentation) if the // lattice->param.do_user_stuff flag is on. // // - The user can fill these routines with whatever they want. // // void compute_drop( lattice_ptr lattice) // // Compute the width and height of the drop. // void compute_drop( lattice_ptr lattice) { int i, j; double rho; const double rho_v=85.7042; const double rho_l=524.3905; const double rho_min=100.; //const double rho_cut=450.; const double rho_cut=(rho_v+rho_l)/2.; //const double rho_cut=212.36; //psi(rho_l)=4.*exp(-200/524.3905) //psi(rho_v)=4.*exp(-200/85.7042) int width=0, width_temp=0, max_width=0; int height=0; double theta; double max_rho=0.; for( j=get_LY(lattice)-1; j>=0; j--) { max_rho=0.; for( i=0; i<get_LX( lattice); i++) //for( i=0; i<170; i++) { //printf("%f ",get_rho(lattice,i,/*j=*/2,/*subs=*/0)); if( max_rho < fabs( get_rho(lattice,i,/*j=*/j,/*subs=*/0))) { max_rho = fabs( get_rho(lattice,i,/*j=*/j,/*subs=*/0)); } } if( max_rho > rho_min) { if( max_rho >= rho_cut){ height++;} width_temp=0; for( i=0; i<get_LX( lattice); i++) //for( i=0; i<170; i++) { if(/*ascii display of the drop*/0) { if( is_solid_node( lattice, /*subs=*/0, IJ2N(i,j))) { printf("%%"); if( j!=0) { printf("%s %d >> WARNING: " "Function compute_drop() is designed to compute the " "width and height of a drop forming on a " "surface at the bottom of the domain. " "Solid detected at (%d,%d) does not conform to that " "configuration.\n", __FILE__, __LINE__, i, j ); } } else { if(get_rho(lattice,i,/*j=*/j,/*subs=*/0) > rho_cut) { printf("X"); width_temp++;} else if(get_rho(lattice,i,/*j=*/j,/*subs=*/0) > rho_min) { printf("x"); } else { printf("-"); } } } else { if(get_rho(lattice,i,/*j=*/j,/*subs=*/0) > rho_cut) { width_temp++;} } } if( width_temp > 0) { width = width_temp; if( max_width < width) { max_width = width; } } if(/*ascii display of the drop*/0) { printf("\n");} } } printf("width=%d, height=%d, ", width, height); printf("width/height=%f\n", (double)width/(double)height); printf("max_width=%d\n", max_width); printf("\n"); if( height > width) { // TODO: Need to double check this formula: theta = PI/2. + atan( ((double)height/(double)width) - ((double)width/(4.*(double)height))); } else if( height < width) { // TODO: Need to double check this formula: theta = atan( 1./( ((double)width/(4.*(double)height)) - ((double)height/(double)width) )); } else if( height == width) { theta = PI/2.; } else { printf("%s %d >> Unhandled case: height=%d, width=%d\n", __FILE__, __LINE__, height, width); theta = 999.; } printf("theta = %f\n", theta); printf("\n"); printf("rho_cut = %f\n", rho_cut); printf("psi(rho_cut) = %f\n", 4.*exp(-200./rho_cut)); printf("psi(rho_v) = %f\n", 4.*exp(-200./85.7042)); printf("psi(rho_l) = %f\n", 4.*exp(-200./524.3905)); printf("psi((rho_l+rho_v)/2.) = %f\n", 4.*exp(-200./((85.7042+524.3905)/2.))); printf("(psi(rho_v)+psi(rho_l))/2. = %f\n", (4.*exp(-200./85.7042)+4.*exp(-200./524.3905))/2.); rho = 212.36; printf("psi(%f) = %f\n", rho, 4.*exp(-200./rho)); //4.*exp(-200/524.3905) //4.*exp(-200/85.7042) } /* void compute_drop( lattice_ptr lattice) */ // void user_stuff_pre_frames( lattice_ptr lattice) // // This function is called before the frame loop in lb2d_prime.c. // void user_stuff_pre_frames( lattice_ptr lattice) { compute_drop( lattice); } /* void user_stuff_pre_frames( lattice_ptr lattice) */ // void user_stuff_frame( lattice_ptr lattice) // // If lattice->param.do_user_stuff is on, this function is called at the // end of each frame in lb2d_prime.c. // void user_stuff_frame( lattice_ptr lattice) { } /* void user_stuff_frame( lattice_ptr lattice) */ // void user_stuff_post_frames( lattice_ptr lattice) // // If lattice->param.do_user_stuff is on, this function is called after // the frame loop in lb2d_prime.c. // void user_stuff_post_frames( lattice_ptr lattice) { compute_drop( lattice); } /* void user_stuff_post_frames( lattice_ptr lattice) */ // void user_stuff_pre_times( lattice_ptr lattice) // // If lattice->param.do_user_stuff is on, this function is called before // the time loop in lb2d_prime.c. // void user_stuff_pre_times( lattice_ptr lattice) { } /* void user_stuff_pre_times( lattice_ptr lattice) */ // void user_stuff_time( lattice_ptr lattice) // // If lattice->param.do_user_stuff is on, this function is called at the // end of each time loop in lb2d_prime.c. // void user_stuff_time( lattice_ptr lattice) { } /* void user_stuff_time( lattice_ptr lattice) */ // void user_stuff_post_times( lattice_ptr lattice) // // If lattice->param.do_user_stuff is on, this function is called after // the time loop in lb2d_prime.c. // void user_stuff_post_times( lattice_ptr lattice) { compute_drop( lattice); } /* void user_stuff_post_times( lattice_ptr lattice) */
111pjb-one
src/user_stuff_20070320_contact_angles.c
C
gpl3
5,681
#include <stdio.h> #include <stdlib.h> #include <memory.h> int ni=100; int nj=100; int nf=23; #define ij2n(i_,j_) ((j_)*ni+(i_)) void alloc_rho( double **rho_a, double ***rho_a2d); void read_rho_file( char *filename, double **rho, double *max, double *min); void display_density_plot( FILE *o, double *rho_a, int max_width); void write_rho_profile( FILE *o, double *rho_a, int i); int main( int argc, char **argv) { FILE *o; char filename[1024]; double **rho_a2d; double *rho_a; double **rho_b2d; double *rho_b; double rho_a_max; double rho_a_min; double rho_b_max; double rho_b_min; int i, j; int iprof; if( argc > 1) { nf = atoi( argv[1]); if( argc > 2) { iprof = atoi( argv[2]); } else { iprof = ni/2; } } alloc_rho( &rho_a, &rho_a2d); alloc_rho( &rho_b, &rho_b2d); sprintf(filename,"../out/rho%dx%d_frame%04d_subs00.dat",ni,nj,nf); read_rho_file( filename, &rho_a, &rho_a_max, &rho_a_min); sprintf(filename,"../out/rho%dx%d_frame%04d_subs01.dat",ni,nj,nf); read_rho_file( filename, &rho_b, &rho_b_max, &rho_b_min); display_density_plot( stdout, rho_b, /*max_width*/85); printf("\n"); display_density_plot( stdout, rho_a, /*max_width*/85); printf("\n"); sprintf(filename,"../out/rho%dx%d_frame%04d_subs00_profile%04d.dat", ni,nj,nf,iprof); o = fopen(filename,"w+"); write_rho_profile( o, rho_a, iprof); fclose(o); sprintf(filename,"../out/rho%dx%d_frame%04d_subs01_profile%04d.dat", ni,nj,nf,iprof); o = fopen(filename,"w+"); write_rho_profile( o, rho_b, iprof); fclose(o); printf("rho_a_max = %f, ", rho_a_max); printf("rho_a_min = %f, ", rho_a_min); printf("rho_b_max = %f, ", rho_b_max); printf("rho_b_min = %f, ", rho_b_min); printf("Wrote profile at i = %d.\n", iprof); free( rho_a); free( rho_b); return 0; } void alloc_rho( double **rho, double ***rho2d) { int j; *rho = (double*)malloc( ni*nj*sizeof(double)); *rho2d = (double**)malloc( nj*sizeof(double*)); for( j=0; j<nj; j++) { (*rho2d)[j] = &((*rho)[j*ni]); } } void read_rho_file( char *filename, double **rho, double *max, double *min) { FILE *in; int i, j; if( !( in = fopen(filename,"r"))) { printf("ERROR: Error opening file \"%s\". Exiting.\n",filename); process_exit(1); } j = 0; i = 0; fscanf( in, "%lf ", ((*rho + ij2n(i,j)))); *max = *(*rho + ij2n(i,j)); *min = *(*rho + ij2n(i,j)); for( i=1; i<ni; i++) { fscanf( in, "%lf ", ((*rho + ij2n(i,j)))); if( *max < *(*rho + ij2n(i,j))) { *max = *(*rho + ij2n(i,j));} if( *min > *(*rho + ij2n(i,j))) { *min = *(*rho + ij2n(i,j));} } for( j=1; j<nj; j++) { for( i=0; i<ni; i++) { fscanf( in, "%lf ", ((*rho + ij2n(i,j)))); if( *max < *(*rho + ij2n(i,j))) { *max = *(*rho + ij2n(i,j));} if( *min > *(*rho + ij2n(i,j))) { *min = *(*rho + ij2n(i,j));} } } fclose( in); } void display_density_plot( FILE *o, double *rho_a, int max_width) { int i, j; for( j=nj-1; j>=0; j--) { for( i=0; i<((ni<=max_width)?(ni):(max_width)); i++) { fprintf( o, " %c", (char)((rho_a[ij2n(i,j)]>1./5.) ?((rho_a[ij2n(i,j)]>2./5.) ?((rho_a[ij2n(i,j)]>3./5.) ?((rho_a[ij2n(i,j)]>4./5.) ?('#') :('X')) :('O')) :('+')) :('.'))); //printf("%.1f ", rho_a2d[ij2n(i,j)]); } printf("\n"); } for( i=0; i<((ni<=max_width)?(ni):(max_width)); i++) { fprintf( o, "%2d", i%100); } } void write_rho_profile( FILE *o, double *rho_a, int i) { int j; for( j=0; j<nj; j++) { fprintf( o, "%f\n", rho_a[ ij2n(i,j)]); } }
111pjb-one
src/integrate_drhos_mcmp.c
C
gpl3
3,721
//############################################################################## // // user_stuff.c // // - This file has function definitions of functions that will be called // at specified times (see individual function documentation) if the // lattice->param.do_user_stuff flag is on. // // - The user can fill these routines with whatever they want. // double theta_of_height_width( const double height, const double width) { double theta; if( height > width/2.) { // TODO: Need to double check this formula: theta = PI/2. + atan( ((double)height/(double)width) - ((double)width/(4.*(double)height))); } else if( height < width/2.) { // TODO: Need to double check this formula: theta = atan( 1./( ((double)width/(4.*(double)height)) - ((double)height/(double)width) )); } else if( height == width/2.) { theta = PI/2.; } else { printf("%s %d >> Unhandled case: height=%d, width=%d\n", __FILE__, __LINE__, height, width); theta = 999.; // Bogus value instead of process_exiting. } return theta; } // double theta_of_height_width( const double height, const double width) void ascii_display_of_the_drop( lattice_ptr lattice, int j, int rho_cut, int rho_min) { double rho; const double rho_v=85.7042; const double rho_l=524.3905; int i, max_i = 80; max_i = (max_i > get_LX(lattice))?( get_LX(lattice)):(max_i); for( i=0; i<max_i; i++) { if( is_solid_node( lattice, /*subs=*/0, IJ2N(i,j))) { printf("%2d",i%100); if( j!=0) { printf("%s %d >> WARNING: " "Function compute_drop() is designed to compute the " "width and height of a drop forming on a " "surface at the bottom of the domain. " "Solid detected at (%d,%d) does not conform to that " "configuration.\n", __FILE__, __LINE__, i, j ); } } else { rho = get_rho(lattice,i,j,/*subs=*/0); if( rho > rho_l) { printf("++"); } else if( rho > rho_cut) { printf("Xx"); } else if( rho > rho_min) { printf("o "); } else if( rho < rho_v) { printf("--"); } else { printf(". "); } } } printf("%3d\n",j); } // void ascii_display_of_the_drop( lattice_ptr lattice, int j, ... // void compute_drop( lattice_ptr lattice) // // Compute the width and height of the drop. (SCMP) // void compute_drop( lattice_ptr lattice, int do_ascii_display_of_the_drop, int output_to_file, int jbase) { int i, j; double rho; const double rho_v=85.7042; const double rho_l=524.3905; const double psi_v = 4.*exp(-200./(rho_v)); const double psi_l = 4.*exp(-200./(rho_l)); const double psi_cut=(psi_v+psi_l)/2.; //const double rho_cut=(rho_v+rho_l)/2.; const double rho_cut= -200./log(.25*psi_cut); //const double rho_cut=450.; //const double rho_cut=100.; double i1, i2, icut_left, icut_right; double j1, j2, jcut; double rho1, rho2; // INPUTE PARAM NOW: const int jbase = 4; // jbase frame_rate theta_low theta theta_high // ----- ---------- ---------- ---------- ---------- // 1 100 91.909683 93.327450 94.732496 // 1 1000 90.947016 92.357518 93.755755 // 2 100 90.962932 92.396963 93.818305 // 2 1000 90.000000 91.426377 92.840531 // 3 100 89.037068 90.479460 91.909683 // 3 1000 89.037068 90.479460 91.909683 // 4 100 88.057956 89.516494 90.962932 // 4 1000 88.057956 89.516494 90.962932 const double rho_min=100.; //const double rho_min=rho_v; // INPUT PARAM NOW: const int do_ascii_display_of_the_drop = 1; //psi(rho_l)=4.*exp(-200/524.3905) //psi(rho_v)=4.*exp(-200/85.7042) int width=0, width_temp=0, max_width=0, max_width_j=0; int height=0; double theta; double max_rho=0.; int imax; int imax1; int imax2; double G = get_G( lattice); double Gads = get_Gads( lattice, /*subs*/0); jcut = -1.; // Flag value. for( j=get_LY(lattice)-1; j>=0; j--) { max_rho=0.; for( i=0; i<get_LX( lattice); i++) { rho = get_rho(lattice,i,/*j=*/j,/*subs=*/0); if( max_rho < fabs(rho)) { max_rho = fabs(rho); imax = i; } } if( /*row j crosses the drop*/ max_rho > rho_min) { if( max_rho > rho_cut && jcut < 0.) { // rho1 was assigned max_rho from row j-1. // j1 was assigned max_rho from row j-1. rho2 = max_rho; imax2 = imax; j2 = j; // Linear interpolation of jcut: jcut = j1 + ((j2-j1)/(rho2-rho1))*( rho_cut - rho1); } if( j>jbase) { if( max_rho >= rho_cut){ height++;} width_temp=0; icut_left = -1; icut_right = -1; for( i=0; i<get_LX(lattice); i++) { rho = get_rho(lattice,i,j,/*subs=*/0); if( rho > rho_cut) { if( icut_left < 0. ) { // i1 and rho1 were set at i-1. rho2 = rho; i2 = i; // Linear interpolation of icut_left: icut_left = i1 + ((i2-i1)/(rho2-rho1))*( rho_cut - rho1); } else { rho1 = rho; i1 = i; /*save for interp of icut_right*/} width_temp++; } else { if( icut_left < 0.) { i1 = i; rho1 = rho; /*save for interp of icut_left*/ } else { if( icut_right < 0.) { // i1 and rho1 were set at i-1. rho2 = rho; i2 = i; // Linear interpolation of icut_right: icut_right = i1 + ((i2-i1)/(rho2-rho1))*( rho_cut - rho1); } } } } if( width_temp > 0) { width = width_temp; if( max_width < width) { max_width = width; max_width_j = j;} } } if( do_ascii_display_of_the_drop) { ascii_display_of_the_drop( lattice, j, rho_cut, rho_min); } } else { rho1 = max_rho; // save rho1 to use for interpolation of jcut. imax1 = imax; j1 = j; } } for( i=0; i<get_LX( lattice); i++) { printf("%f ",get_rho(lattice,i,/*j=*/max_width_j,/*subs=*/0)); } printf("\n"); printf("jbase = %d\n", jbase); printf("width=%d, height=%d, ", width, height); printf("width/height=%f, ", (double)width/(double)height); printf("max_width=%d at j=%d, ", max_width, max_width_j); theta = theta_of_height_width( jcut-jbase, icut_right-icut_left); printf("%f = %f^o ", theta, theta*(180./PI)); theta = theta_of_height_width( height-1, width+1); printf("theta_low = %f = %f^o, ", theta, theta*(180./PI)); theta = theta_of_height_width( height, width); printf("theta = %f = %f^o, ", theta, theta*(180./PI)); theta = theta_of_height_width( height+1, width-1); printf("theta_high = %f = %f^o, ", theta, theta*(180./PI)); theta = acos( ( ( psi_v - Gads/G) - ( Gads/G - psi_l) )/(psi_v-psi_l)); printf("theta_predicted_youngs = %f = %f^o ", theta, theta*(180./PI)); //theta = PI*( ( Gads/G - psi_l) / ( psi_v - psi_l)); //printf("theta_predicted_combination = %f = %f^o ", theta, theta*(180./PI)); if( output_to_file) { FILE *o; o = fopen( "compute_drop.dat", "a+"); fprintf( o, "%d ", get_NumFrames( lattice)); fprintf( o, "%d ", get_FrameRate( lattice)); fprintf( o, "%8.4f ", get_G( lattice)); fprintf( o, "%8.4f ", get_Gads( lattice, /*subs*/0)); fprintf( o, "%d ", jbase); fprintf( o, "%d ", width); fprintf( o, "%d ", height); theta = theta_of_height_width( jcut-jbase, icut_right-icut_left); fprintf( o, "%20.17f ", theta*(180./PI)); theta = theta_of_height_width( height-1, width+1); fprintf( o, "%20.17f ", theta*(180./PI)); theta = theta_of_height_width( height, width); fprintf( o, "%20.17f ", theta*(180./PI)); theta = theta_of_height_width( height+1, width-1); fprintf( o, "%20.17f ", theta*(180./PI)); theta = acos( ( ( psi_v - Gads/G) - ( Gads/G - psi_l) )/(psi_v-psi_l)); //fprintf( o, "acos(%20.17f) = ", ( ( psi_v - Gads/G) - ( Gads/G - psi_l) )/(psi_v-psi_l)); fprintf( o, "%20.17f ", theta*(180./PI)); //theta = PI*( ( Gads/G - psi_l) / ( psi_v - psi_l)); //fprintf( o, "%20.17f ", theta*(180./PI)); fprintf( o, "\n"); fclose(o); } printf("\n"); printf("rho_cut = %f\n", rho_cut); printf("(icut_left,icut_right,jcut) = ( %9.6f, %9.6f, %9.6f); " "(imax1,imax2)=(%d,%d); (icut_left+icut_right)/2 = %9.6f\n", icut_left, icut_right, jcut, imax1, imax2,(icut_left+icut_right)/2.); printf("psi(rho_cut) = %f\n", 4.*exp(-200./rho_cut)); printf("psi(rho_v) = %f\n", 4.*exp(-200./85.7042)); printf("psi(rho_l) = %f\n", 4.*exp(-200./524.3905)); printf("psi((rho_l+rho_v)/2.) = %f\n", 4.*exp(-200./((85.7042+524.3905)/2.))); printf("(psi(rho_v)+psi(rho_l))/2. = %f\n", (4.*exp(-200./85.7042)+4.*exp(-200./524.3905))/2.); rho = 212.36; printf("psi(%f) = %f\n", rho, 4.*exp(-200./rho)); //4.*exp(-200/524.3905) //4.*exp(-200/85.7042) } /* void compute_drop( lattice_ptr lattice, bool output_to_file) */ // void user_stuff_pre_frames( lattice_ptr lattice) // // This function is called before the frame loop in lb2d_prime.c. // void user_stuff_pre_frames( lattice_ptr lattice) { compute_drop( lattice, /*ascii*/1, /*file-io*/0, /*jbase*/1); compute_drop( lattice, /*ascii*/0, /*file-io*/0, /*jbase*/2); compute_drop( lattice, /*ascii*/0, /*file-io*/0, /*jbase*/3); compute_drop( lattice, /*ascii*/0, /*file-io*/0, /*jbase*/4); compute_drop( lattice, /*ascii*/0, /*file-io*/0, /*jbase*/5); compute_drop( lattice, /*ascii*/0, /*file-io*/0, /*jbase*/6); } /* void user_stuff_pre_frames( lattice_ptr lattice) */ // void user_stuff_frame( lattice_ptr lattice) // // If lattice->param.do_user_stuff is on, this function is called at the // end of each frame in lb2d_prime.c. // void user_stuff_frame( lattice_ptr lattice) { } /* void user_stuff_frame( lattice_ptr lattice) */ // void user_stuff_post_frames( lattice_ptr lattice) // // If lattice->param.do_user_stuff is on, this function is called after // the frame loop in lb2d_prime.c. // void user_stuff_post_frames( lattice_ptr lattice) { compute_drop( lattice, /*ascii*/1, /*file-io*/1, /*jbase*/1); compute_drop( lattice, /*ascii*/0, /*file-io*/1, /*jbase*/2); compute_drop( lattice, /*ascii*/0, /*file-io*/1, /*jbase*/3); compute_drop( lattice, /*ascii*/0, /*file-io*/1, /*jbase*/4); compute_drop( lattice, /*ascii*/0, /*file-io*/1, /*jbase*/5); compute_drop( lattice, /*ascii*/0, /*file-io*/1, /*jbase*/6); } /* void user_stuff_post_frames( lattice_ptr lattice) */ // void user_stuff_pre_times( lattice_ptr lattice) // // If lattice->param.do_user_stuff is on, this function is called before // the time loop in lb2d_prime.c. // void user_stuff_pre_times( lattice_ptr lattice) { } /* void user_stuff_pre_times( lattice_ptr lattice) */ // void user_stuff_time( lattice_ptr lattice) // // If lattice->param.do_user_stuff is on, this function is called at the // end of each time loop in lb2d_prime.c. // void user_stuff_time( lattice_ptr lattice) { } /* void user_stuff_time( lattice_ptr lattice) */ // void user_stuff_post_times( lattice_ptr lattice) // // If lattice->param.do_user_stuff is on, this function is called after // the time loop in lb2d_prime.c. // void user_stuff_post_times( lattice_ptr lattice) { compute_drop( lattice, /*ascii*/1, /*file-io*/0, /*jbase*/1); compute_drop( lattice, /*ascii*/0, /*file-io*/0, /*jbase*/2); compute_drop( lattice, /*ascii*/0, /*file-io*/0, /*jbase*/3); compute_drop( lattice, /*ascii*/0, /*file-io*/0, /*jbase*/4); compute_drop( lattice, /*ascii*/0, /*file-io*/0, /*jbase*/5); compute_drop( lattice, /*ascii*/0, /*file-io*/0, /*jbase*/6); } /* void user_stuff_post_times( lattice_ptr lattice) */
111pjb-one
src/user_stuff_20070615_scmp_contact_angles.c
C
gpl3
12,106
//############################################################################## // // Copyright (C), 2005, Michael Sukop and Danny Thorne // // lbio.c // // - Lattice Boltzmann I/O routines. // // - Mainly, dump the data to files that can be read by Matlab. // // - Also, output routines for facilitating debugging. // // - Should have a routine that dumps a matlab script? // // Some compilers, e.g., VC++, don't have the usual round() function // in their math library. Alternatively, ROUND can be defined as // ceil or floor or some other rounding function. It is used in // the below routines for converting the real number valued of // quantities at a lattice node into integer RGB values for writing // to BMP files. #define ROUND floor //void output_frame( lattice_ptr lattice) //############################################################################## // // O U T P U T F R A M E // void output_frame( lattice_ptr lattice) { double s, u[2]; double nu; double L; #if VERBOSITY_LEVEL > 0 printf("\n"); printf( "========================================" "========================================\n"); printf("Begin file I/O at time = %d, frame = %d.\n", lattice->time, lattice->time/lattice->param.FrameRate); printf("\n"); #endif /* VERBOSITY_LEVEL > 0 */ dump_frame_summary( lattice); #if WRITE_MACRO_VAR_DAT_FILES dump_macro_vars( lattice, lattice->time); #endif /* WRITE_MACRO_VAR_DAT_FILES */ #if WRITE_PDF_DAT_FILES dump_pdf( lattice, lattice->time); #endif /* WRITE_PDF_DAT_FILES */ if( lattice->param.dump_rho) { rho2bmp( lattice, lattice->time);} if( lattice->param.dump_u ) { u2bmp( lattice, lattice->time);} if( lattice->param.dump_vor) { vor2bmp( lattice, lattice->time);} #if NON_LOCAL_FORCES if( lattice->param.G != 0.) { if( lattice->param.dump_force) { force2bmp( lattice);} } if( lattice->param.Gads[0] != 0. || lattice->param.Gads[0] != 0.) { if( lattice->param.dump_force) { sforce2bmp( lattice);} } #endif /* NON_LOCAL_FORCES */ slice( lattice); #if WRITE_CHEN_DAT_FILES chen_output( lattice); #endif /* WRITE_CHEN_DAT_FILES */ #if VERBOSITY_LEVEL > 0 printf("\n"); printf("File I/O done.\n"); printf("--\n"); #endif /* VERBOSITY_LEVEL > 0 */ nu = (1./3.)*(lattice->param.tau[0] - .5); L = lattice->param.length_scale; compute_ave_u( lattice, u, 0); s = sqrt( u[0]*u[0] + u[1]*u[1]); printf("subs 0: Re = ux_ave*L/nu = %f * %f / %f = %f\n", u[0], L, nu, u[0]*L/nu ); printf("subs 0: Re = uy_ave*L/nu = %f * %f / %f = %f\n", u[1], L, nu, u[1]*L/nu ); printf("subs 0: Re = u_ave*L/nu = %f * %f / %f = %f\n", s, L, nu, s*L/nu ); #if NUM_FLUID_COMPONENTS == 2 compute_ave_u( lattice, u, 1); s = sqrt( u[0]*u[0] + u[1]*u[1]); printf("subs 1: Re = ux_ave*L/nu = %f * %f / %f = %f\n", u[0], L, nu, u[0]*L/nu ); printf("subs 1: Re = uy_ave*L/nu = %f * %f / %f = %f\n", u[1], L, nu, u[1]*L/nu ); printf("subs 1: Re = u_ave*L/nu = %f * %f / %f = %f\n", s, L, nu, s*L/nu ); #endif /* NUM_FLUID_COMPONENTS == 2 */ #if STORE_UEQ compute_ave_ueq( lattice, u); s = sqrt( u[0]*u[0] + u[1]*u[1]); printf("eq: Re = ux_ave*L/nu = %f * %f / %f = %f\n", u[0], L, nu, u[0]*L/nu ); printf("eq: Re = uy_ave*L/nu = %f * %f / %f = %f\n", u[1], L, nu, u[1]*L/nu ); printf("eq: Re = u_ave*L/nu = %f * %f / %f = %f\n", s, L, nu, s*L/nu ); #endif /* STORE_UEQ */ } /* void output_frame( lattice_ptr lattice) */ // void dump_frame_info( struct lattice_struct *lattice) //############################################################################## // // D U M P F R A M E I N F O // void dump_frame_summary( struct lattice_struct *lattice) { char filename[1024]; FILE *o; double min_u[5], max_u[5], ave_u[5], flux[3]; double min_rho, max_rho, ave_rho; double rho_ratio, u_x_ratio, u_y_ratio; int subs; for( subs = 0; subs < NUM_FLUID_COMPONENTS; subs++) { sprintf( filename, "./out/frames%dx%d_subs%02d.dat", lattice->param.LX, lattice->param.LY, subs); // On the first timestep, make sure we start with a new file. if( lattice->time==0) { if( !( o = fopen(filename,"w+"))) { printf("ERROR: fopen(\"%s\",\"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } else { // Put a header on the file. fprintf( o, "\n"); fprintf( o, " time " " |j| " " j_x " " j_y " " ave |u| " " ave |u_x| " " ave |u_y| " " ave u_x " " ave u_y " " min |u| " " min |u_x| " " min |u_y| " " min u_x " " min u_y " " max |u| " " max |u_x| " " max |u_y| " " max u_x " " max u_y " " max/ave_x " " max/ave_y " " min rho " " max rho " " ave rho " " max/ave " "\n"); fprintf( o, " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" " ------------" "\n"); fclose(o); } } if( !( o = fopen(filename,"a+"))) { printf("ERROR: fopen(\"%s\",\"a+\") = NULL. Bye, bye!\n", filename); process_exit(1); } compute_min_u_all( lattice, min_u, subs); compute_max_u_all( lattice, max_u, subs); compute_ave_u_all( lattice, ave_u, subs); compute_min_rho( lattice, &min_rho, subs); compute_max_rho( lattice, &max_rho, subs); compute_ave_rho( lattice, &ave_rho, subs); rho_ratio = ( ave_rho != 0.) ? ( max_rho /ave_rho ):( 1.); u_x_ratio = ( ave_u[1] != 0.) ? ( max_u[1]/ave_u[0]):( 1.); u_y_ratio = ( ave_u[2] != 0.) ? ( max_u[2]/ave_u[1]):( 1.); compute_flux( lattice, flux, subs); fprintf( o, "%12d " "%12.7f %12.7f %12.7f %12.7f %12.7f %12.7f %12.7f %12.7f %12.7f " "%12.7f %12.7f %12.7f %12.7f %12.7f %12.7f %12.7f %12.7f %12.7f " "%12.7f %12.7f %12.7f %12.7f %12.7f %12.7f\n", lattice->time, flux [0], flux [1], flux [2], ave_u[0], ave_u[1], ave_u[2], ave_u[3], ave_u[4], min_u[0], min_u[1], min_u[2], min_u[3], min_u[4], max_u[0], max_u[1], max_u[2], max_u[3], max_u[4], (u_x_ratio<=9999.)?(u_x_ratio):(9999.), (u_y_ratio<=9999.)?(u_y_ratio):(9999.), min_rho, max_rho, ave_rho, (rho_ratio<=9999.)?(rho_ratio):(9999.) ); fclose(o); #if VERBOSITY_LEVEL > 0 printf("dump_frame_info() -- Wrote file \"%s\"\n", filename); #endif /* VERBOSITY_LEVEL > 0 */ #if VERBOSITY_LEVEL > 0 printf("dump_frame_info() -- frame = %d/%d = %d\n", lattice->time, lattice->param.FrameRate, (int)((double)lattice->time/(double)lattice->param.FrameRate)); #endif /* VERBOSITY_LEVEL > 0 */ } } /* void dump_frame_info( struct lattice_struct *lattice) */ // void dump_macro_vars( struct lattice_struct *lattice) //############################################################################## // // D U M P M A C R O S C O P I C // // - Output the macro_vars variables to files. // void dump_macro_vars( struct lattice_struct *lattice, int time) { char filename[1024]; FILE *o, *o_u, *o_rho, *o_ux, *o_uy, *o_ueq, *o_ueq_x, *o_ueq_y; int *node_ptr; int n; double *macro_vars_ptr; double *ueq; int frame; #if WRITE_RHO_AND_U_TO_TXT int i, j; #endif /* WRITE_RHO_AND_U_TO_TXT */ double min_u[2], max_u[2], ave_u[2]; double min_rho, max_rho, ave_rho; double rho_ratio, u_x_ratio, u_y_ratio; int subs; frame = (int)((double)lattice->time/(double)lattice->param.FrameRate); for( subs = 0; subs < NUM_FLUID_COMPONENTS; subs++) { // W R I T E R H O A N D U // // - Write the density and velocity values at the active nodes to // the rho and u dat files. // sprintf( filename, "./out/rho_frame%04d_subs%02d.dat", frame, subs); if( !( o_rho = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/u_frame%04d_subs%02d.dat", frame, subs); if( !( o_u = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } #if STORE_UEQ sprintf( filename, "./out/ueq_frame%04d_subs%02d.dat", frame, subs); if( !( o_ueq = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } ueq = lattice->ueq[0].u; #endif /* STORE_UEQ */ macro_vars_ptr = &( lattice->macro_vars[subs][0].rho); for( n=0; n<lattice->NumNodes; n++) { fprintf( o_rho, "%20.17f\n", *macro_vars_ptr++); fprintf( o_u, "%20.17f ", *macro_vars_ptr++); fprintf( o_u, "%20.17f\n", *macro_vars_ptr++); #if STORE_UEQ fprintf( o_ueq, "%20.17f ", *ueq++); fprintf( o_ueq, "%20.17f\n", *ueq++); #endif /* STORE_UEQ */ } fclose(o_u); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/u_frame%04d_subs%02d.dat", frame, subs); #endif /* VERBOSITY_LEVEL > 0 */ printf("dump_macro_vars() -- Wrote file \"%s\"\n", filename); fclose(o_rho); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/rho_frame%04d_subs%02d.dat", frame, subs); #endif /* VERBOSITY_LEVEL > 0 */ printf("dump_macro_vars() -- Wrote file \"%s\"\n", filename); #if STORE_UEQ fclose(o_ueq); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/ueq_frame%04d_subs%02d.dat", frame, subs); #endif /* VERBOSITY_LEVEL > 0 */ printf("dump_macro_vars() -- Wrote file \"%s\"\n", filename); #endif /* STORE_UEQ */ #if WRITE_RHO_AND_U_TO_TXT // NOTE: This is very inefficient. But it's only intended // for debugging purposes on small problems. sprintf( filename, "./out/rho_frame%04d_subs%02d.txt", frame, subs); if( !( o_rho = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/ux_frame%04d_subs%02d.txt", frame, subs); if( !( o_ux = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/uy_frame%04d_subs%02d.txt", frame, subs); if( !( o_uy = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } #if STORE_UEQ sprintf( filename, "./out/ueq_x_frame%04d_subs%02d.txt", frame, subs); if( !( o_ueq_x = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/ueq_y_frame%04d_subs%02d.txt", frame, subs); if( !( o_ueq_y = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } #endif /* STORE_UEQ */ for( j=lattice->param.LY-1; j>=0; j--) { n = j*lattice->param.LX; for( i=0; i<lattice->param.LX; i++, n++) { fprintf( o_rho, "%12.7f ", lattice->macro_vars[subs][n].rho); fprintf( o_ux, "%12.7f ", lattice->macro_vars[subs][n].u[0]); fprintf( o_uy, "%12.7f ", lattice->macro_vars[subs][n].u[1]); #if STORE_UEQ fprintf( o_ueq_x, "%12.7f ", lattice->ueq[n].u[0]); fprintf( o_ueq_y, "%12.7f ", lattice->ueq[n].u[1]); #endif /* STORE_UEQ */ if( n==lattice->NumNodes) { fprintf( o_rho, "%12.7f ", 0.); fprintf( o_ux, "%12.7f ", 0.); fprintf( o_uy, "%12.7f ", 0.); #if STORE_UEQ fprintf( o_ueq_x, "%12.7f ", 0.); fprintf( o_ueq_y, "%12.7f ", 0.); #endif /* STORE_UEQ */ } } fprintf( o_rho, "\n"); fprintf( o_ux, "\n"); fprintf( o_uy, "\n"); #if STORE_UEQ fprintf( o_ueq_x, "\n"); fprintf( o_ueq_y, "\n"); #endif /* STORE_UEQ */ } fclose(o_ux); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/ux_frame%04d_subs%02d.txt", frame, subs); #endif /* VERBOSITY_LEVEL > 0 */ printf("dump_macro_vars() -- Wrote file \"%s\"\n", filename); fclose(o_uy); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/uy_frame%04d_subs%02d.txt", frame, subs); #endif /* VERBOSITY_LEVEL > 0 */ printf("dump_macro_vars() -- Wrote file \"%s\"\n", filename); fclose(o_rho); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/rho_frame%04d_subs%02d.txt", frame, subs); #endif /* VERBOSITY_LEVEL > 0 */ printf("dump_macro_vars() -- Wrote file \"%s\"\n", filename); #if STORE_UEQ fclose(o_ueq_x); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/ueq_x_frame%04d_subs%02d.txt", frame, subs); #endif /* VERBOSITY_LEVEL > 0 */ printf("dump_macro_vars() -- Wrote file \"%s\"\n", filename); fclose(o_ueq_y); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/ueq_y_frame%04d_subs%02d.txt", frame, subs); #endif /* VERBOSITY_LEVEL > 0 */ printf("dump_macro_vars() -- Wrote file \"%s\"\n", filename); #endif /* STORE_UEQ */ #endif /* WRITE_RHO_AND_U_TO_TXT */ } /* for( subs = 0; subs < NUM_FLUID_COMPONENTS; subs++) */ } /* void dump_macro_vars( struct lattice_struct *lattice, int time) */ #if 1 // void read_macro_vars( struct lattice_struct *lattice) //############################################################################## // // R E A D M A C R O S C O P I C // // - Read the macro_vars variables from files. // void read_macro_vars( struct lattice_struct *lattice, int time) { char filename[1024]; FILE *in, *rho_in, *u_in; int *node_ptr; int n; double *macro_vars_ptr; int frame; double max_u[2], ave_u[2]; double max_rho, ave_rho; double rho_ratio, u_x_ratio, u_y_ratio; int subs; for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { frame = (int)((double)time/(double)lattice->param.FrameRate); #if VERBOSITY_LEVEL > 0 printf("read_macro_vars() -- frame = %d/%d = %d\n", time, lattice->param.FrameRate, frame); #endif /* VERBOSITY_LEVEL > 0 */ // R E A D R H O A N D U // // - Read the density and velocity values at the active nodes to // the rho and u dat files. // sprintf( filename, "./out/rho_frame%04d_subs%02d.dat", frame, subs); if( !( rho_in = fopen( filename, "r+"))) { printf("ERROR: fopen( \"%s\", \"r+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/u_frame%04d_subs%02d.dat", frame, subs); if( !( u_in = fopen( filename, "r+"))) { printf("ERROR: fopen( \"%s\", \"r+\") = NULL. Bye, bye!\n", filename); process_exit(1); } macro_vars_ptr = &( lattice->macro_vars[subs][0].rho); for( n=0; n<lattice->NumNodes; n++) { fscanf( rho_in, "%lf\n", macro_vars_ptr++); fscanf( u_in, "%lf ", macro_vars_ptr++); fscanf( u_in, "%lf\n", macro_vars_ptr++); } fclose(u_in); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/u_frame%04d_subs%02d.dat", frame, subs); #endif /* VERBOSITY_LEVEL > 0 */ printf("read_macro_vars() -- Read file \"%s\"\n", filename); fclose(rho_in); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/rho_frame%04d_subs%02d.dat", frame, subs); #endif /* VERBOSITY_LEVEL > 0 */ printf("read_macro_vars() -- Read file \"%s\"\n", filename); } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ } /* void read_macro_vars( struct lattice_struct *lattice, int time) */ #endif // void dump_pdf( struct lattice_struct *lattice, int time) //############################################################################## // // D U M P P D F // // - Output the particle distribution functions to a text file. // // - This is useful mainly for debugging with small problems. // void dump_pdf( struct lattice_struct *lattice, int time) { char filename[1024]; FILE *o_feq, *o_f, *o_ftemp; double *fptr, *end_ptr; bc_ptr bc; int frame; int subs; #if WRITE_PDF_TO_TXT int i, j, n; #endif /* WRITE_PDF_TO_TXT */ for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { frame = time/lattice->param.FrameRate; sprintf( filename, "./out/feq_frame%04d_subs%02d.dat", frame, subs); if( !( o_feq = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/f_frame%04d_subs%02d.dat", frame, subs); if( !( o_f = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/ftemp_frame%04d_subs%02d.dat", frame, subs); if( !( o_ftemp = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } bc = lattice->bc[subs]; fptr = lattice->pdf[subs][0].feq; end_ptr = &(lattice->pdf[subs][ lattice->NumNodes-1].ftemp[8]) + 1; while( fptr!=end_ptr) { if( 1 || !( bc++->bc_type & BC_SOLID_NODE)) { fprintf( o_feq , "%10.7f ", *fptr++); fprintf( o_feq , "%10.7f ", *fptr++); fprintf( o_feq , "%10.7f ", *fptr++); fprintf( o_feq , "%10.7f ", *fptr++); fprintf( o_feq , "%10.7f ", *fptr++); fprintf( o_feq , "%10.7f ", *fptr++); fprintf( o_feq , "%10.7f ", *fptr++); fprintf( o_feq , "%10.7f ", *fptr++); fprintf( o_feq , "%10.7f ", *fptr++); } else { fprintf( o_feq , "%10.7f ", 0.); fprintf( o_feq , "%10.7f ", 0.); fprintf( o_feq , "%10.7f ", 0.); fprintf( o_feq , "%10.7f ", 0.); fprintf( o_feq , "%10.7f ", 0.); fprintf( o_feq , "%10.7f ", 0.); fprintf( o_feq , "%10.7f ", 0.); fprintf( o_feq , "%10.7f ", 0.); fprintf( o_feq , "%10.7f ", 0.); fptr+=9; } fprintf( o_feq , "\n"); fprintf( o_f , "%10.7f ", *fptr++); fprintf( o_f , "%10.7f ", *fptr++); fprintf( o_f , "%10.7f ", *fptr++); fprintf( o_f , "%10.7f ", *fptr++); fprintf( o_f , "%10.7f ", *fptr++); fprintf( o_f , "%10.7f ", *fptr++); fprintf( o_f , "%10.7f ", *fptr++); fprintf( o_f , "%10.7f ", *fptr++); fprintf( o_f , "%10.7f ", *fptr++); fprintf( o_f , "\n"); fprintf( o_ftemp, "%10.7f ", *fptr++); fprintf( o_ftemp, "%10.7f ", *fptr++); fprintf( o_ftemp, "%10.7f ", *fptr++); fprintf( o_ftemp, "%10.7f ", *fptr++); fprintf( o_ftemp, "%10.7f ", *fptr++); fprintf( o_ftemp, "%10.7f ", *fptr++); fprintf( o_ftemp, "%10.7f ", *fptr++); fprintf( o_ftemp, "%10.7f ", *fptr++); fprintf( o_ftemp, "%10.7f ", *fptr++); fprintf( o_ftemp, "\n"); } /* while( fptr!=end_ptr) */ fclose( o_feq); fclose( o_f); fclose( o_ftemp); } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ #if WRITE_PDF_TO_TXT for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { frame = time/lattice->param.FrameRate; sprintf( filename, "./out/feq_frame%04d_subs%02d.txt", frame, subs); if( !( o_feq = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/f_frame%04d_subs%02d.txt", frame, subs); if( !( o_f = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/ftemp_frame%04d_subs%02d.txt", frame, subs); if( !( o_ftemp = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } for( i=0; i<lattice->param.LX; i++) { fprintf( o_feq , "-----------"); fprintf( o_feq , "-----------"); fprintf( o_feq , "----------|"); fprintf( o_f , "-----------"); fprintf( o_f , "-----------"); fprintf( o_f , "----------|"); fprintf( o_ftemp, "-----------"); fprintf( o_ftemp, "-----------"); fprintf( o_ftemp, "----------|"); } fprintf( o_feq , "\n"); fprintf( o_f , "\n"); fprintf( o_ftemp, "\n"); for( j=lattice->param.LY-1; j>=0; j--) { n = j*lattice->param.LX; for( i=0; i<lattice->param.LX; i++, n++) { fprintf( o_feq, "%10.6f ", lattice->pdf[subs][n].feq[6] ); fprintf( o_feq, "%10.6f ", lattice->pdf[subs][n].feq[2] ); fprintf( o_feq, "%10.6f|", lattice->pdf[subs][n].feq[5] ); fprintf( o_f, "%10.6f ", lattice->pdf[subs][n].f[6] ); fprintf( o_f, "%10.6f ", lattice->pdf[subs][n].f[2] ); fprintf( o_f, "%10.6f|", lattice->pdf[subs][n].f[5] ); fprintf( o_ftemp,"%10.6f ", lattice->pdf[subs][n].ftemp[6]); fprintf( o_ftemp,"%10.6f ", lattice->pdf[subs][n].ftemp[2]); fprintf( o_ftemp,"%10.6f|", lattice->pdf[subs][n].ftemp[5]); } /* for( i=0; i<lattice->param.LX; i++, n++) */ fprintf( o_feq, "\n"); fprintf( o_f, "\n"); fprintf( o_ftemp,"\n"); n = j*lattice->param.LX; for( i=0; i<lattice->param.LX; i++, n++) { fprintf( o_feq, "%10.6f ", lattice->pdf[subs][n].feq[3] ); fprintf( o_feq, "%10.6f ", lattice->pdf[subs][n].feq[0] ); fprintf( o_feq, "%10.6f|", lattice->pdf[subs][n].feq[1] ); fprintf( o_f, "%10.6f ", lattice->pdf[subs][n].f[3] ); fprintf( o_f, "%10.6f ", lattice->pdf[subs][n].f[0] ); fprintf( o_f, "%10.6f|", lattice->pdf[subs][n].f[1] ); fprintf( o_ftemp,"%10.6f ", lattice->pdf[subs][n].ftemp[3]); fprintf( o_ftemp,"%10.6f ", lattice->pdf[subs][n].ftemp[0]); fprintf( o_ftemp,"%10.6f|", lattice->pdf[subs][n].ftemp[1]); } /* for( i=0; i<lattice->param.LX; i++, n++) */ fprintf( o_feq, "\n"); fprintf( o_f, "\n"); fprintf( o_ftemp,"\n"); n = j*lattice->param.LX; for( i=0; i<lattice->param.LX; i++, n++) { fprintf( o_feq, "%10.6f ", lattice->pdf[subs][n].feq[7] ); fprintf( o_feq, "%10.6f ", lattice->pdf[subs][n].feq[4] ); fprintf( o_feq, "%10.6f|", lattice->pdf[subs][n].feq[8] ); fprintf( o_f, "%10.6f ", lattice->pdf[subs][n].f[7] ); fprintf( o_f, "%10.6f ", lattice->pdf[subs][n].f[4] ); fprintf( o_f, "%10.6f|", lattice->pdf[subs][n].f[8] ); fprintf( o_ftemp,"%10.6f ", lattice->pdf[subs][n].ftemp[7]); fprintf( o_ftemp,"%10.6f ", lattice->pdf[subs][n].ftemp[4]); fprintf( o_ftemp,"%10.6f|", lattice->pdf[subs][n].ftemp[8]); } /* for( i=0; i<lattice->param.LX; i++, n++) */ fprintf( o_feq, "\n"); fprintf( o_f, "\n"); fprintf( o_ftemp,"\n"); for( i=0; i<lattice->param.LX; i++) { fprintf( o_feq , "-----------"); fprintf( o_feq , "-----------"); fprintf( o_feq , "----------|"); fprintf( o_f , "-----------"); fprintf( o_f , "-----------"); fprintf( o_f , "----------|"); fprintf( o_ftemp, "-----------"); fprintf( o_ftemp, "-----------"); fprintf( o_ftemp, "----------|"); } fprintf( o_feq , "\n"); fprintf( o_f , "\n"); fprintf( o_ftemp, "\n"); } /* for( j=lattice->param.LY-1; j>=0; j--) */ fclose( o_feq); fclose( o_f); fclose( o_ftemp); } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ #endif /* WRITE_PDF_TO_TXT */ } /* void dump_pdf( struct lattice_struct *lattice, int time) */ #if NON_LOCAL_FORCES // void dump_forces( struct lattice_struct *lattice) //############################################################################## // // D U M P F O R C E S // // - Output the interactive force values to file. // void dump_forces( struct lattice_struct *lattice) { char filename[1024]; FILE *ox, *oy; int n; double *force; int frame; #if WRITE_RHO_AND_U_TO_TXT int i, j; #endif /* WRITE_RHO_AND_U_TO_TXT */ int subs; for( subs = 0; subs < NUM_FLUID_COMPONENTS; subs++) { frame = (int)((double)lattice->time/(double)lattice->param.FrameRate); #if VERBOSITY_LEVEL > 0 printf("dump_forces() -- frame = %d/%d = %d\n", lattice->time, lattice->param.FrameRate, frame); #endif /* VERBOSITY_LEVEL > 0 */ sprintf( filename, "./out/force_x_frame%04d_subs%02d.dat", frame, subs); if( !( ox = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/force_y_frame%04d_subs%02d.dat", frame, subs); if( !( oy = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } force = lattice->force[subs][0].force; for( n=0; n<lattice->NumNodes; n++) { fprintf( ox, "%20.17f\n", *force++); fprintf( oy, "%20.17f\n", *force++); force += ( sizeof( struct force_struct)/8 - 2); } fclose(ox); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/force_x_frame%04d_subs%02d.dat", frame, subs); #endif /* VERBOSITY_LEVEL > 0 */ printf("dump_forces() -- Wrote file \"%s\"\n", filename); fclose(oy); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/force_y_frame%04d_subs%02d.dat", frame, subs); #endif /* VERBOSITY_LEVEL > 0 */ printf("dump_forces() -- Wrote file \"%s\"\n", filename); #if WRITE_RHO_AND_U_TO_TXT // NOTE: This is very inefficient. But it's only intended // for debugging purposes on small problems. sprintf( filename, "./out/force_x_frame%04d_subs%02d.txt", frame, subs); if( !( ox = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/force_y_frame%04d_subs%02d.txt", frame, subs); if( !( oy = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } for( j=0; j<lattice->param.LY; j++) { n = j*lattice->param.LX; for( i=0; i<lattice->param.LX; i++, n++) { fprintf( ox, "%10.7f ", lattice->force[subs][n].force[0]); fprintf( oy, "%10.7f ", lattice->force[subs][n].force[1]); if( n==lattice->NumNodes) { fprintf( ox, "%10.7f ", 0.); fprintf( oy, "%10.7f ", 0.); } } fprintf( ox, "\n"); fprintf( oy, "\n"); } fclose(ox); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/force_x_frame%04d_subs%02d.txt", frame, subs); #endif /* VERBOSITY_LEVEL > 0 */ printf("dump_forces() -- Wrote file \"%s\"\n", filename); fclose(oy); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/force_y_frame%04d_subs%02d.txt", frame, subs); #endif /* VERBOSITY_LEVEL > 0 */ printf("dump_forces() -- Wrote file \"%s\"\n", filename); #endif /* WRITE_RHO_AND_U_TO_TXT */ } /* for( subs = 0; subs < NUM_FLUID_COMPONENTS; subs++) */ } /* void dump_forces( struct lattice_struct *lattice) */ #endif /* NON_LOCAL_FORCES */ // void dump_checkpoint( struct lattice_struct *lattice, int time, char *fn) //############################################################################## // // D U M P C H E C K P O I N T // // - Write lattice to a checkpoint file. // // - Should be binary and store all information necessary to // restart the current run at this point. // void dump_checkpoint( struct lattice_struct *lattice, int time, char *fn) { } /* void dump_checkpoint( struct lattice_struct *lattice, ...) */ // void read_checkpoint( struct lattice_struct *lattice) //############################################################################## // // R E A D C H E C K P O I N T // // - Read lattice from a checkpoint file (as written by dump_checkpoint). // // - With this information, should be able to restart where // the previous run stopped. // void read_checkpoint( struct lattice_struct *lattice) { } /* void read_checkpoint( struct lattice_struct *lattice) */ // void spy_bmp( char *filename, int ***spy) //############################################################################## // // S P Y B M P // // - Returns matrix 'spy' of ones and zeros. // // - Zeros for white pixels. // // - Ones for non-white pixels. // void spy_bmp( char *filename, lattice_ptr lattice, int **spy) { FILE *in, *o; int i, j, n, m; int pad, bytes_per_row; char k; char b, g, r; struct bitmap_file_header bmfh; struct bitmap_info_header bmih; struct rgb_quad rgb; int *int_ptr; short int *short_int_ptr; int *width_ptr; int *height_ptr; short int *bitcount_ptr; printf("spy_bmp() -- Hi!\n"); // Clear the spy array. for( j=0; j<lattice->param.LY; j++) { for( i=0; i<lattice->param.LX; i++) { spy[j][i] = 0; } } if( !( in = fopen( filename, "r"))) { #if 1 printf("spy_bmp() -- Error opening file \"%s\".\n", filename); process_exit(1); #else printf(" %s::spy_bmp() %d >> File \"%s\" cannot be opened for reading.\n", __FILE__, __LINE__, filename); if( !( o = fopen( filename, "w+"))) { // TODO: Write blank bmp file. } printf(" %s::spy_bmp() %d >> Wrote a blank \"%s\" file.\n", __FILE__, __LINE__, filename); printf(" %s::spy_bmp() %d >> Returning all zeros!\n", __FILE__, __LINE__); fclose( o); return; #endif } // n = fread( void *BUF, size_t SIZE, size_t COUNT, FILE *FP); n = fread( &bmfh, sizeof(struct bitmap_file_header), 1, in ); if( strncmp(bmfh.bfType,"BM",2)) { printf("ERROR: Can't process this file type. Exiting!\n"); printf("\n"); process_exit(1); } n = fread( &bmih, sizeof(struct bitmap_info_header), 1, in ); int_ptr = (int*)bmih.biCompression; if( *int_ptr != 0) { printf("ERROR: Can't handle compression. Exiting!\n"); printf("\n"); process_exit(1); } width_ptr = (int*)bmih.biWidth; height_ptr = (int*)bmih.biHeight; bitcount_ptr = (short int*)bmih.biBitCount; if( *width_ptr != lattice->param.LX) { printf("%s %d >> ERROR: LX %d does not match the " "width %d of the BMP file. Exiting!\n", __FILE__, __LINE__, lattice->param.LX, *width_ptr); process_exit(1); } if( *height_ptr != lattice->param.LY) { printf("%s %d >> ERROR: LY %d does not match the " "height %d of the BMP file. Exiting!\n", __FILE__, __LINE__, lattice->param.LY, *height_ptr); process_exit(1); } if( *bitcount_ptr < 24) { n = (int)pow(2.,(double)*bitcount_ptr); // Num palette entries. for( i=0; i<n; i++) { k = fread( &rgb, sizeof(struct rgb_quad), 1, in ); if( k!=1) { printf("Error reading palette entry %d. Exiting!\n", i); process_exit(1); } } } // Bytes per row of the bitmap. bytes_per_row = ((int)ceil(( (((double)(*width_ptr))*((double)(*bitcount_ptr)))/8.))); // Bitmaps pad rows to preserve 4-byte boundaries. // The length of a row in the file will be bytes_per_row + pad . pad = ((4) - bytes_per_row%4)%4; n = 0; m = 0; n+=( k = fread( &b, 1, 1, in )); i = 0; j = 0; while( !feof(in)) { switch(*bitcount_ptr) { case 1: // Monochrome. printf("spy_bmp() -- " "Support for Monochrome BMPs is pending. " "Exiting!\n"); process_exit(1); if( i < *width_ptr) { (spy)[j][i] = ( (b & 0x80) == 0); } i++; if( i < *width_ptr) { (spy)[j][i] = ( (b & 0x40) == 0); } i++; if( i < *width_ptr) { (spy)[j][i] = ( (b & 0x20) == 0); } i++; if( i < *width_ptr) { (spy)[j][i] = ( (b & 0x10) == 0); } i++; if( i < *width_ptr) { (spy)[j][i] = ( (b & 0x08) == 0); } i++; if( i < *width_ptr) { (spy)[j][i] = ( (b & 0x04) == 0); } i++; if( i < *width_ptr) { (spy)[j][i] = ( (b & 0x02) == 0); } i++; if( i < *width_ptr) { (spy)[j][i] = ( (b & 0x01) == 0); } i++; break; case 4: // 16 colors. printf("spy_bmp() -- " "Support for 16 color BMPs is pending. " "Exiting!\n"); process_exit(1); if( i < *width_ptr) { (spy)[j][i] = ( (b&0xf0)>>4 != 15); } i++; if( i < *width_ptr) { (spy)[j][i] = ( (b&0x0f) != 15); } i++; break; case 8: // 256 colors. printf("spy_bmp() -- " "Support for 256 color BMPs is pending. " "Exiting!\n"); process_exit(1); if( i < *width_ptr) { (spy)[j][i] = ( (b&0xff) != 255); } i++; break; case 24: // 24-bit colors. if( i < 3*(*width_ptr)) { i++; n+=( k = fread( &g, 1, 1, in )); i++; n+=( k = fread( &r, 1, 1, in )); if( ( (b&0xff) == 0) &&( (g&0xff) == 0) &&( (r&0xff) == 0) ) { (spy)[j][(int)floor((double)i/3.)] = 1; } #if 0 if( ( (b&0xff) == 0) &&( (g&0xff) == 0) &&( (r&0xff) == 255) ) { // Red ==> Inflow, Pressure boundaries. if( (int)floor((double)i/3.) == 0 || (int)floor((double)i/3.) == lattice->param.LX-1 ) { if( !( j==0 || j == lattice->param.LY-1)) { lattice->periodic_x[subs] = 0; } } if( j == 0 || j == lattice->param.LY-1 ) { if( !( (int)floor((double)i/3.) == 0 || (int)floor((double)i/3.) == lattice->param.LX-1)) { lattice->periodic_y[subs] = 0; } } } if( ( (b&0xff) == 0) &&( (g&0xff) == 255) &&( (r&0xff) == 0) ) { // Green ==> Outflow, Pressure boundaries. if( (int)floor((double)i/3.) == 0 || (int)floor((double)i/3.) == lattice->param.LX-1 ) { if( !( j==0 || j == lattice->param.LY-1)) { lattice->periodic_x[subs] = 0; } } if( j == 0 || j == lattice->param.LY-1 ) { if( !( (int)floor((double)i/3.) == 0 || (int)floor((double)i/3.) == lattice->param.LX-1)) { lattice->periodic_y[subs] = 0; } } } #endif } i++; break; default: // 32-bit colors? printf("ERROR: Unhandled color depth, " "BitCount = %d. Exiting!\n", *bitcount_ptr); process_exit(1); break; } /* switch(*(bmih.biBitCount)) */ if( !(n%(bytes_per_row+pad))) { m++; i=0; j++;} n+=( k = fread( &b, 1, 1, in )); } /* while( !feof(in)) */ if( (bytes_per_row+pad)*m!=n) { printf("WARNING: Num bytes read = %d versus num bytes predicted = %d .\n", n, (bytes_per_row+pad)*m); } if( m != *height_ptr) { printf("WARNING: m (%d) != bmih.biHeight (%d).\n", m, *height_ptr); } fclose(in); printf("spy_bmp() -- Bye!\n"); printf("\n"); } /* spy_bmp( char *filename, int **spy) */ // void read_bcs( char *filename, int **bcs) //############################################################################## // // R E A D B C S // // - Read boundary condition information from file. // void read_bcs( lattice_ptr lattice, int **bcs) { FILE *in; char filename[1024]; int i, j, n, m; int ei, ej; int pad, bytes_per_row; char k; char b, g, r; struct bitmap_file_header bmfh; struct bitmap_info_header bmih; struct rgb_quad rgb; int *int_ptr; short int *short_int_ptr; int *width_ptr; int *height_ptr; short int *bitcount_ptr; int subs; printf("read_bcs() -- Hi!\n"); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { // Clear the bcs array. for( j=0; j<lattice->param.LY; j++) { for( i=0; i<lattice->param.LX; i++) { bcs[j][i] = 0; } } sprintf( filename, "./in/%dx%dbc_subs%02d.bmp", lattice->param.LX, lattice->param.LY, subs); if( !( in = fopen( filename, "r"))) { printf("read_bcs() -- Error opening file \"%s\".\n", filename); process_exit(1); } // Read the headers. n = fread( &bmfh, sizeof(struct bitmap_file_header), 1, in ); if( strncmp(bmfh.bfType,"BM",2)) { printf("ERROR: Can't process this file type. Exiting!\n"); printf("\n"); process_exit(1); } n = fread( &bmih, sizeof(struct bitmap_info_header), 1, in ); int_ptr = (int*)bmih.biCompression; if( *int_ptr != 0) { printf("ERROR: Can't handle compression. Exiting!\n"); printf("\n"); process_exit(1); } width_ptr = (int*)bmih.biWidth; height_ptr = (int*)bmih.biHeight; bitcount_ptr = (short int*)bmih.biBitCount; if( *height_ptr != lattice->param.LY) { printf("ERROR: Lattice height does not match " "soil matrix data \"%s\". (%d!=%d) Exiting!\n", filename, lattice->param.LY, *height_ptr ); printf("\n"); process_exit(1); } if( *width_ptr != lattice->param.LX) { printf("ERROR: Lattice width does not match " "soil matrix data \"%s\". (%d!=%d) Exiting!\n", filename, lattice->param.LX, *width_ptr ); printf("\n"); process_exit(1); } // Read the palette, if necessary. if( *bitcount_ptr < 24) { n = (int)pow(2.,(double)*bitcount_ptr); // Num palette entries. for( i=0; i<n; i++) { k = fread( &rgb, sizeof(struct rgb_quad), 1, in ); if( k!=1) { printf("Error reading palette entry %d. Exiting!\n", i); process_exit(1); } } } // Bytes per row of the bitmap. bytes_per_row = ((int)ceil(( (((double)(*width_ptr))*((double)(*bitcount_ptr)))/8.))); // Bitmaps pad rows to preserve 4-byte boundaries. // The length of a row in the file will be bytes_per_row + pad . pad = ((4) - bytes_per_row%4)%4; n = 0; m = 0; n+=( k = fread( &b, 1, 1, in )); i = 0; //j = *height_ptr-1; j = 0;//*height_ptr-1; while( !feof(in)) { switch(*bitcount_ptr) { case 1: // Monochrome. printf("read_bcs() -- " "Support for Monochrome BMPs is pending. " "Exiting!\n"); process_exit(1); if( i < *width_ptr) { (bcs)[j][i] = ( (b & 0x80) == 0); } i++; if( i < *width_ptr) { (bcs)[j][i] = ( (b & 0x40) == 0); } i++; if( i < *width_ptr) { (bcs)[j][i] = ( (b & 0x20) == 0); } i++; if( i < *width_ptr) { (bcs)[j][i] = ( (b & 0x10) == 0); } i++; if( i < *width_ptr) { (bcs)[j][i] = ( (b & 0x08) == 0); } i++; if( i < *width_ptr) { (bcs)[j][i] = ( (b & 0x04) == 0); } i++; if( i < *width_ptr) { (bcs)[j][i] = ( (b & 0x02) == 0); } i++; if( i < *width_ptr) { (bcs)[j][i] = ( (b & 0x01) == 0); } i++; break; case 4: // 16 colors. printf("read_bcs() -- " "Support for 16 color BMPs is pending. " "Exiting!\n"); process_exit(1); if( i < *width_ptr) { (bcs)[j][i] = ( (b&0xf0)>>4 != 15); } i++; if( i < *width_ptr) { (bcs)[j][i] = ( (b&0x0f) != 15); } i++; break; case 8: // 256 colors. printf("read_bcs() -- " "Support for 256 color BMPs is pending. " "Exiting!\n"); process_exit(1); if( i < *width_ptr) { (bcs)[j][i] = ( (b&0xff) != 255); } i++; break; case 24: // 24-bit colors. if( i < 3*(*width_ptr)) { i++; n+=( k = fread( &g, 1, 1, in )); i++; n+=( k = fread( &r, 1, 1, in )); if( ( (b&0xff) == 0) &&( (g&0xff) == 0) &&( (r&0xff) == 255) ) { // R E D ==> Inflow, Pressure boundaries. bcs[j][(int)floor((double)i/3.)] = 1; } if( ( (b&0xff) == 0) &&( (g&0xff) == 255) &&( (r&0xff) == 0) ) { // G R E E N ==> Outflow, Pressure boundaries. bcs[j][(int)floor((double)i/3.)] = 2; } } i++; break; default: // 32-bit colors? printf("ERROR: Unhandled color depth, " "BitCount = %d. Exiting!\n", *bitcount_ptr); process_exit(1); break; } /* switch(*(bmih.biBitCount)) */ if( !(n%(bytes_per_row+pad))) { m++; i=0; j++;} n+=( k = fread( &b, 1, 1, in )); } /* while( !feof(in)) */ if( (bytes_per_row+pad)*m!=n) { printf("WARNING: Num bytes read = %d versus num bytes predicted = %d .\n", n, (bytes_per_row+pad)*m); } if( m != *height_ptr) { printf("WARNING: m (%d) != bmih.biHeight (%d).\n", m, *height_ptr); } fclose(in); ei = lattice->param.LX-1; ej = lattice->param.LY-1; for( n=0; n<lattice->NumNodes; n++) { i = n%lattice->param.LX; j = n/lattice->param.LX; if( bcs[ j][ i] != 0) { //printf("read_bcs() -- n = %d, ( %d, %d) of ( %d, %d).\n", n, i, j, ei, ej); #if 0 if( ( i==0 && j==0 ) || ( i==ei && j==0 ) || ( i==ei && j==ej) || ( i==0 && j==ej) ) { // Skip corners for now. printf("read_bcs() -- WARNING: Skipping corner ( %d, %d).", i, j); } else { #endif #if 0 if( i==0) { // West if( bcs[ j][ i] == 1) { // Inflow lattice->bc[n].bc_type |= BC_PRESSURE_W_IN; //lattice->periodic_x = 0; } else if( bcs[ j][ i] == 2) { // Outflow lattice->bc[n].bc_type |= BC_PRESSURE_W_OUT; //lattice->periodic_x = 0; } else { // Unhandled case. printf("read_bcs() -- Unhandled case: " "bcs[ %d][ %d] = %d . Exiting!\n", i, j, bcs[j][i]); process_exit(1); } } else if( i==ei) { // East if( bcs[ j][ i] == 1) { // Inflow lattice->bc[n].bc_type |= BC_PRESSURE_E_IN; //lattice->periodic_x = 0; } else if( bcs[ j][ i] == 2) { // Outflow lattice->bc[n].bc_type |= BC_PRESSURE_E_OUT; //lattice->periodic_x = 0; } else { // Unhandled case. printf("read_bcs() -- Unhandled case: " "bcs[ %d][ %d] = %d . Exiting!\n", i, j, bcs[j][i]); process_exit(1); } } else #endif if( j==0) { //printf("read_bcs() -- South at i=%d\n", i); // South if( bcs[ j][ i] == 1) { // Inflow lattice->bc[subs][n].bc_type |= BC_PRESSURE_S_IN; //lattice->periodic_y = 0; } else if( bcs[ j][ i] == 2) { // Outflow lattice->bc[subs][n].bc_type |= BC_PRESSURE_S_OUT; //lattice->periodic_y = 0; } else { // Unhandled case. printf("read_bcs() -- Unhandled case: " "bcs[ %d][ %d] = %d . Exiting!\n", i, j, bcs[j][i]); process_exit(1); } } else if( j==ej) { //printf("read_bcs() -- North at i=%d\n", i); // North if( bcs[ j][ i] == 1) { // Inflow lattice->bc[subs][n].bc_type |= BC_PRESSURE_N_IN; //lattice->periodic_y = 0; } else if( bcs[ j][ i] == 2) { // Outflow lattice->bc[subs][n].bc_type |= BC_PRESSURE_N_OUT; //lattice->periodic_y = 0; } else { // Unhandled case. printf("read_bcs() -- Unhandled case: " "bcs[ %d][ %d] = %d . Exiting!\n", i, j, bcs[j][i]); process_exit(1); } } else { // Unhandled case. printf("read_bcs() -- WARNING: " "Support for interior flow bcs is pending! " "Skipping ( i, j) = ( %d, %d).\n", i, j); } #if 0 } #endif } } } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ printf("read_bcs() -- Bye!\n"); printf("\n"); } /* read_bcs( char *filename, int ***bcs, int *height, int *width) */ // void rho2bmp( char *filename, int time) //############################################################################## // // R H O 2 B M P // #if 1 void rho2bmp( lattice_ptr lattice, int time) { FILE *in, *o; int i, j, n, m; int pad, bytes_per_row; int frame; char k; char b; struct bitmap_file_header bmfh; struct bitmap_info_header bmih; struct rgb_quad rgb; int *int_ptr; short int *short_int_ptr; int *width_ptr; int *height_ptr; short int *bitcount_ptr; char filename[1024]; char red_val, green_val, blue_val, val; double fval; double min_rho, max_rho; int subs; double **colormap; int num_colors; #if SAY_HI printf("rho2bmp() -- Hi!\n"); #endif /* SAY_HI */ if( lattice->param.use_colormap) { count_colormap( &num_colors); allocate_colormap( &colormap, num_colors); read_colormap( colormap, num_colors); } for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { frame = time/lattice->param.FrameRate; sprintf( filename, "./in/%dx%d.bmp", lattice->param.LX, lattice->param.LY); if( !( in = fopen( filename, "r"))) { printf("rho2bmp() -- Error opening file \"%s\".\n", filename); process_exit(1); } // n = fread( void *BUF, size_t SIZE, size_t COUNT, FILE *FP); n = fread( &bmfh, sizeof(struct bitmap_file_header), 1, in ); if( strncmp(bmfh.bfType,"BM",2)) { printf("ERROR: Can't process this file type. Exiting!\n"); printf("\n"); process_exit(1); } n = fread( &bmih, sizeof(struct bitmap_info_header), 1, in ); int_ptr = (int*)bmih.biCompression; if( *int_ptr != 0) { printf("ERROR: Can't handle compression. Exiting!\n"); printf("\n"); process_exit(1); } width_ptr = (int*)bmih.biWidth; height_ptr = (int*)bmih.biHeight; bitcount_ptr = (short int*)bmih.biBitCount; // Read palette entries, if applicable. if( *bitcount_ptr < 24) { n = (int)pow(2.,(double)*bitcount_ptr); // Num palette entries. for( i=0; i<n; i++) { k = fread( &rgb, sizeof(struct rgb_quad), 1, in ); if( k!=1) { printf("Error reading palette entry %d. Exiting!\n", i); process_exit(1); } } } fclose(in); // Bytes per row of the bitmap. bytes_per_row = ((int)ceil(( (((double)(*width_ptr))*((double)(*bitcount_ptr)))/8.))); // Bitmaps pad rows to preserve 4-byte boundaries. // The length of a row in the file will be bytes_per_row + pad . pad = ((4) - bytes_per_row%4)%4; compute_min_rho( lattice, &min_rho, subs); compute_max_rho( lattice, &max_rho, subs); sprintf( filename, "./out/rho%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); if( !( o = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } fwrite( &bmfh, sizeof(struct bitmap_file_header), 1, o ); fwrite( &bmih, sizeof(struct bitmap_info_header), 1, o ); for( j=0; j<lattice->param.LY; j++) { n = j*lattice->param.LX; for( i=0; i<lattice->param.LX; i++, n++) { if( lattice->bc[subs][ n].bc_type == /*FLUID_NODE*/0) { if( lattice->param.use_colormap) { if( lattice->param.plot_scale_dynamic) { if( max_rho!=min_rho) { get_color( colormap, num_colors, (lattice->macro_vars[subs][ n].rho - min_rho)/(max_rho-min_rho), &red_val, &green_val, &blue_val ); } else { get_color( colormap, num_colors, 1., &red_val, &green_val, &blue_val ); } } else { get_color( colormap, num_colors, (lattice->macro_vars[subs][ n].rho /( (lattice->param.rho_A[subs]>lattice->param.rho_B[subs]) ?(lattice->param.rho_A[subs]) :(lattice->param.rho_B[subs]) )), &red_val, &green_val, &blue_val ); } } else { if( subs==0) { if( lattice->param.plot_scale_dynamic) { if( max_rho!=min_rho) { fval = ROUND( 255.*( lattice->macro_vars[subs][ n].rho - min_rho) /( max_rho-min_rho)); } else { fval = 255.; } } else { fval = ROUND( 255.*(lattice->macro_vars[subs][ n].rho /( (lattice->param.rho_A[subs]>lattice->param.rho_B[subs]) ?(lattice->param.rho_A[subs]) :(lattice->param.rho_B[subs]) ) )); } if( fval >= 0.) { if( fval <= 255.) { red_val = (char)((int)(255. - fval)%256); green_val = (char)((int)(255. - fval)%256); blue_val = (char)255; } else { red_val = (char)0; green_val = (char)0; blue_val = (char)255; } } else { red_val = (char)((int)(255. + fval)%256); green_val = (char)((int)(255. + fval)%256); blue_val = (char)((int)(255. + fval)%256); // TODO: Issue warning or something? Potential instability? } } /* if( subs==0) */ else // subs == 1 { if( lattice->param.plot_scale_dynamic) { if( max_rho!=min_rho) { fval = ROUND( 255.*( lattice->macro_vars[subs][ n].rho - min_rho) /( max_rho-min_rho)); } else { fval = 0.; } } else { //printf("%s (%d) >> fval = %f -> ", __FILE__, __LINE__, fval); #if INAMURO_SIGMA_COMPONENT fval = ROUND( 255.*(lattice->macro_vars[subs][ n].rho) /(lattice->param.rho_sigma)); #else /* !( INAMURO_SIGMA_COMPONENT) */ fval = ROUND( 255.*(lattice->macro_vars[subs][ n].rho /(lattice->param.rho_A[subs]))); #endif /* INAMURO_SIGMA_COMPONENT */ //printf("%f\n", fval); } if( fval >= 0.) { if( fval <= 255.) { red_val = (char)255; green_val = (char)((int)(255. - fval)%256); blue_val = (char)((int)(255. - fval)%256); } else { red_val = (char)255;//((int)(255. - (fval - 255.))%256); green_val = (char) 0;//((int)(255. - (fval - 255.))%256); blue_val = (char) 0;//((int)(255. - (fval - 255.))%256); } } else { red_val = (char)((int)(255. + fval)%256); green_val = (char)((int)(255. + fval)%256); blue_val = (char)((int)(255. + fval)%256); // TODO: Issue a warning or something? Potential instability? } } /* if( subs==0) else */ } } /* if( lattice->bc[subs][ n].bc_type == 0) */ else // lattice->bc[subs][ n].bc_type != 0 { #if SOLID_COLOR_IS_CHECKERBOARD // Checkerboard pattern over the solids and boundary conditions. if( (i+j)%2) { red_val = (char)200; green_val = (char)200; blue_val = (char)200; val = (char)200; } else { red_val = (char)184; green_val = (char)184; blue_val = (char)184; val = (char)184; } #else /* !( SOLID_COLOR_IS_CHECKERBOARD) */ #if SOLID_COLOR_IS_BLACK red_val = (char)0; green_val = (char)0; blue_val = (char)0; val = (char)0; #else /* !( SOLID_COLOR_IS_BLACK) */ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; #endif /* SOLID_COLOR_IS_BLACK */ #endif /* SOLID_COLOR_IS_CHECKERBOARD */ } /* if( lattice->bc[subs][ n].bc_type == 0) else */ //printf("blue_val( %d, %d) = %d\n", i, j, (int)blue_val); if( fwrite( &blue_val, 1, 1, o) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} //printf("BING %d %d\n", i, j); if( fwrite( &green_val, 1, 1, o) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} //printf("BING %d %d\n", i, j); if( fwrite( &red_val, 1, 1, o) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} //printf("BING %d %d\n", i, j); } /* for( i=0; i<lattice->param.LX; i++) */ // Pad for 4-byte boundaries. val = (char)0; for( i=0; i<pad; i++) { if( fwrite( &val, 1, 1, o) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} } } /* for( j=0; j<lattice->param.LY; j++) */ fclose(o); #if VERBOSITY_LEVEL > 0 printf("rho2bmp() -- Wrote file \"%s\".\n", filename); #endif /* VERBOSITY_LEVEL > 0 */ } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ if( lattice->param.use_colormap) { deallocate_colormap( &colormap, num_colors); } #if SAY_HI printf("rho2bmp() -- Bye!\n"); printf("\n"); #endif /* SAY_HI */ } /* rho2bmp( lattice_ptr lattice, int time) */ #else void rho2bmp( lattice_ptr lattice, int time) { FILE *in, *o; int i, j, n, m; int pad, bytes_per_row; int frame; char k; char b; struct bitmap_file_header bmfh; struct bitmap_info_header bmih; struct rgb_quad rgb; int *int_ptr; short int *short_int_ptr; int *width_ptr; int *height_ptr; short int *bitcount_ptr; char filename[1024]; char red_val, green_val, blue_val, val; double min_rho, max_rho; int subs; #if SAY_HI printf("rho2bmp() -- Hi!\n"); #endif /* SAY_HI */ compute_max_rho( lattice, &min_rho, 0); compute_max_rho( lattice, &max_rho, 1); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { frame = time/lattice->param.FrameRate; sprintf( filename, "./in/%dx%d.bmp", lattice->param.LX, lattice->param.LY); if( !( in = fopen( filename, "r"))) { printf("rho2bmp() -- Error opening file \"%s\".\n", filename); process_exit(1); } // n = fread( void *BUF, size_t SIZE, size_t COUNT, FILE *FP); n = fread( &bmfh, sizeof(struct bitmap_file_header), 1, in ); if( strncmp(bmfh.bfType,"BM",2)) { printf("ERROR: Can't process this file type. Exiting!\n"); printf("\n"); process_exit(1); } n = fread( &bmih, sizeof(struct bitmap_info_header), 1, in ); int_ptr = (int*)bmih.biCompression; if( *int_ptr != 0) { printf("ERROR: Can't handle compression. Exiting!\n"); printf("\n"); process_exit(1); } width_ptr = (int*)bmih.biWidth; height_ptr = (int*)bmih.biHeight; bitcount_ptr = (short int*)bmih.biBitCount; // Read palette entries, if applicable. if( *bitcount_ptr < 24) { n = (int)pow(2.,(double)*bitcount_ptr); // Num palette entries. for( i=0; i<n; i++) { k = fread( &rgb, sizeof(struct rgb_quad), 1, in ); if( k!=1) { printf("Error reading palette entry %d. Exiting!\n", i); process_exit(1); } } } fclose(in); // Bytes per row of the bitmap. bytes_per_row = ((int)ceil(( (((double)(*width_ptr))*((double)(*bitcount_ptr)))/8.))); // Bitmaps pad rows to preserve 4-byte boundaries. // The length of a row in the file will be bytes_per_row + pad . pad = ((4) - bytes_per_row%4)%4; sprintf( filename, "./out/rho%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); if( !( o = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } fwrite( &bmfh, sizeof(struct bitmap_file_header), 1, o ); fwrite( &bmih, sizeof(struct bitmap_info_header), 1, o ); for( j=0; j<lattice->param.LY; j++) { n = j*lattice->param.LX; for( i=0; i<lattice->param.LX; i++, n++) { if( lattice->bc[subs][ n].bc_type == /*FLUID_NODE*/0) { red_val = (char)0; green_val = (char)0; red_val = (char)ROUND( 255.*(lattice->macro_vars[subs][ n].rho - min_rho)/(max_rho-min_rho)); blue_val = (char)255-red_val; } /* if( lattice->bc[subs][ n].bc_type == 0) */ else // lattice->bc[subs][ n].bc_type != 0 { #if SOLID_COLOR_IS_CHECKERBOARD // Checkerboard pattern over the solids and boundary conditions. if( (i+j)%2) { red_val = (char)200; green_val = (char)200; blue_val = (char)200; val = (char)200; } else { red_val = (char)184; green_val = (char)184; blue_val = (char)184; val = (char)184; } #else /* !( SOLID_COLOR_IS_CHECKERBOARD) */ #if SOLID_COLOR_IS_BLACK red_val = (char)0; green_val = (char)0; blue_val = (char)0; val = (char)0; #else /* !( SOLID_COLOR_IS_BLACK) */ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; #endif /* SOLID_COLOR_IS_BLACK */ #endif /* SOLID_COLOR_IS_CHECKERBOARD */ } /* if( lattice->bc[subs][ n].bc_type == 0) else */ //printf("blue_val( %d, %d) = %d\n", i, j, (int)blue_val); if( fwrite( &blue_val, 1, 1, o) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} //printf("BING %d %d\n", i, j); if( fwrite( &green_val, 1, 1, o) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} //printf("BING %d %d\n", i, j); if( fwrite( &red_val, 1, 1, o) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} //printf("BING %d %d\n", i, j); } /* for( i=0; i<lattice->param.LX; i++) */ // Pad for 4-byte boundaries. val = (char)0; for( i=0; i<pad; i++) { if( fwrite( &val, 1, 1, o) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} } } /* for( j=0; j<lattice->param.LY; j++) */ fclose(o); #if VERBOSITY_LEVEL > 0 printf("rho2bmp() -- Wrote file \"%s\".\n", filename); #endif /* VERBOSITY_LEVEL > 0 */ } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ #if SAY_HI printf("rho2bmp() -- Bye!\n"); printf("\n"); #endif /* SAY_HI */ } /* rho2bmp( lattice_ptr lattice, int time) */ #endif // void u2bmp( char *filename, int time) //############################################################################## // // U 2 B M P // void u2bmp( lattice_ptr lattice, int time) { FILE *in, *o_u, *o_ux, *o_uy; int i, j, n, m; int pad, bytes_per_row; int frame; char k; char b; struct bitmap_file_header bmfh; struct bitmap_info_header bmih; struct rgb_quad rgb; int *int_ptr; short int *short_int_ptr; int *width_ptr; int *height_ptr; short int *bitcount_ptr; char filename[1024]; char red_val, green_val, blue_val, val; double max_u[2], maxu; double u_x, u_y, u; int subs; #if SAY_HI printf("u2bmp() -- Hi!\n"); #endif /* SAY_HI */ for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { frame = time/lattice->param.FrameRate; sprintf( filename, "./in/%dx%d.bmp", lattice->param.LX, lattice->param.LY); if( !( in = fopen( filename, "r"))) { printf("u2bmp() -- Error opening file \"%s\".\n", filename); process_exit(1); } // n = fread( void *BUF, size_t SIZE, size_t COUNT, FILE *FP); n = fread( &bmfh, sizeof(struct bitmap_file_header), 1, in ); if( strncmp(bmfh.bfType,"BM",2)) { printf("ERROR: Can't process this file type. Exiting!\n"); printf("\n"); process_exit(1); } n = fread( &bmih, sizeof(struct bitmap_info_header), 1, in ); int_ptr = (int*)bmih.biCompression; if( *int_ptr != 0) { printf("ERROR: Can't handle compression. Exiting!\n"); printf("\n"); process_exit(1); } width_ptr = (int*)bmih.biWidth; height_ptr = (int*)bmih.biHeight; bitcount_ptr = (short int*)bmih.biBitCount; // Read palette entries, if applicable. if( *bitcount_ptr < 24) { n = (int)pow(2.,(double)*bitcount_ptr); // Num palette entries. for( i=0; i<n; i++) { k = fread( &rgb, sizeof(struct rgb_quad), 1, in ); if( k!=1) { printf("Error reading palette entry %d. Exiting!\n", i); process_exit(1); } } } fclose(in); // Bytes per row of the bitmap. bytes_per_row = ((int)ceil(( (((double)(*width_ptr))*((double)(*bitcount_ptr)))/8.))); // Bitmaps pad rows to preserve 4-byte boundaries. // The length of a row in the file will be bytes_per_row + pad . pad = ((4) - bytes_per_row%4)%4; compute_max_u( lattice, max_u, subs); sprintf( filename, "./out/u%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); if( !( o_u = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/u_x%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); if( !( o_ux = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/u_y%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); if( !( o_uy = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } fwrite( &bmfh, sizeof(struct bitmap_file_header), 1, o_u ); fwrite( &bmih, sizeof(struct bitmap_info_header), 1, o_u ); fwrite( &bmfh, sizeof(struct bitmap_file_header), 1, o_ux ); fwrite( &bmih, sizeof(struct bitmap_info_header), 1, o_ux ); fwrite( &bmfh, sizeof(struct bitmap_file_header), 1, o_uy); fwrite( &bmih, sizeof(struct bitmap_info_header), 1, o_uy); //for( j=lattice->param.LY-1; j>=0; j--) for( j=0; j<lattice->param.LY; j++) { n = j*lattice->param.LX; for( i=0; i<lattice->param.LX; i++, n++) { if( lattice->bc[subs][ n].bc_type == /*FLUID_NODE*/0) { #if 1 blue_val = (char)0; green_val = (char)0; red_val = (char)0; u_x = (lattice->macro_vars[subs][ n].u[0]); u_y = (lattice->macro_vars[subs][ n].u[1]); u = sqrt(u_x*u_x + u_y*u_y); maxu = sqrt( max_u[0]*max_u[0] + max_u[1]*max_u[1]); if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { blue_val = (char)ROUND( 128.*fabs(u_x)/max_u[0]); green_val = (char)ROUND( 128.*fabs(u_y)/max_u[1]); } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) */ else // !( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { #if 0 blue_val = (char)ROUND( 255.*fabs(u_x)/max_u[0]); green_val = (char)ROUND( 255.*fabs(u_y)/max_u[1]); red_val = 0.;//(char)ROUND( 128.*fabs(u)/maxu); #else blue_val = (char)ROUND( 255.*fabs(u_x)/maxu); green_val = (char)ROUND( 255.*fabs(u_y)/maxu); red_val = 0.;//(char)ROUND( 128.*fabs(u)/maxu); #endif } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) else */ #else blue_val = (char)255; green_val = (char)255; red_val = (char)255; u = sqrt(u_x*u_x + u_y*u_y); maxu = sqrt( max_u[0]*max_u[0] + max_u[1]*max_u[1]); //if( fabs(u) > .1*maxu) //{ green_val = (char)ROUND( 255.-255.*fabs(u)/maxu); red_val = (char)ROUND( 255.-255.*fabs(u)/maxu); blue_val = (char)ROUND( 255.-255.*fabs(u)/maxu); //} //else //{ // green_val = (char)0; // red_val = (char)0; // blue_val = (char)0; //} #endif val = (char)0; } /* if( lattice->bc[subs][ n].bc_type == 0) */ else // lattice->bc[subs][ n].bc_type != 0 { #if SOLID_COLOR_IS_CHECKERBOARD // Checkerboard pattern over the solids and boundary conditions. if( (i+j)%2) { red_val = (char)200; green_val = (char)200; blue_val = (char)200; val = (char)200; } else { red_val = (char)184; green_val = (char)184; blue_val = (char)184; val = (char)184; } #else /* !( SOLID_COLOR_IS_CHECKERBOARD) */ #if SOLID_COLOR_IS_BLACK red_val = (char)0; green_val = (char)0; blue_val = (char)0; val = (char)0; #else /* !( SOLID_COLOR_IS_BLACK) */ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; #endif /* SOLID_COLOR_IS_BLACK */ #endif /* SOLID_COLOR_IS_CHECKERBOARD */ } /* if( lattice->bc[subs][ n].bc_type == 0) else */ #if MARK_ORIGIN_FOR_REFERENCE // Mark the origin for reference. if( ( i == 0 && j == 0)) { red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; } #endif /* MARK_ORIGIN_FOR_REFERENCE */ if( fwrite( &blue_val, 1, 1, o_u ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &green_val, 1, 1, o_u ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &red_val, 1, 1, o_u ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( lattice->bc[subs][ n].bc_type == /*FLUID_NODE*/0) { blue_val = (char)0; green_val = (char)0; red_val = (char)0; u_x = (lattice->macro_vars[subs][ n].u[0]); u_y = (lattice->macro_vars[subs][ n].u[1]); val = (char)0; if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { if( u_x > 0) { red_val = val; blue_val = (char)ROUND( 128.*fabs(u_x)/max_u[0]); } else { red_val = (char)ROUND( 128.*fabs(u_x)/max_u[0]); blue_val = val; } } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) */ else // !( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { if( u_x > 0) { red_val = val; blue_val = (char)ROUND( 255.*fabs(u_x)/max_u[0]); } else { red_val = (char)ROUND( 255.*fabs(u_x)/max_u[0]); blue_val = val; } } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) else */ } /* if( lattice->bc[subs][ n].bc_type == 0) */ else // lattice->bc[subs][ n].bc_type != 0 { #if SOLID_COLOR_IS_CHECKERBOARD // Checkerboard pattern over the solids and boundary conditions. if( (i+j)%2) { red_val = (char)200; green_val = (char)200; blue_val = (char)200; val = (char)200; } else { red_val = (char)184; green_val = (char)184; blue_val = (char)184; val = (char)184; } #else /* !( SOLID_COLOR_IS_CHECKERBOARD) */ #if SOLID_COLOR_IS_BLACK red_val = (char)0; green_val = (char)0; blue_val = (char)0; val = (char)0; #else /* !( SOLID_COLOR_IS_BLACK) */ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; #endif /* SOLID_COLOR_IS_BLACK */ #endif /* SOLID_COLOR_IS_CHECKERBOARD */ } /* if( lattice->bc[subs][ n].bc_type == 0) else */ #if MARK_ORIGIN_FOR_REFERENCE // Mark the origin for reference. if( ( i == 0 && j == 0)) { red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; } #endif /* MARK_ORIGIN_FOR_REFERENCE */ if( fwrite( &blue_val, 1, 1, o_ux) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &val, 1, 1, o_ux) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &red_val, 1, 1, o_ux) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( lattice->bc[subs][ n].bc_type == /*FLUID_NODE*/0) { blue_val = (char)0; green_val = (char)0; red_val = (char)0; u_x = (lattice->macro_vars[subs][ n].u[0]); u_y = (lattice->macro_vars[subs][ n].u[1]); val = (char)0; if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { if( u_y > 0) { red_val = val; green_val = (char)ROUND( 128.*fabs(u_y)/max_u[1]); } else { red_val = (char)ROUND( 128.*fabs(u_y)/max_u[1]); green_val = val; } } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) */ else // !( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { if( u_y > 0) { blue_val = (char)ROUND( 255.*fabs(u_y)/max_u[1]); green_val = val; } else { blue_val = val; green_val = (char)ROUND( 255.*fabs(u_y)/max_u[1]); } } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) else */ } /* if( lattice->bc[subs][ n].bc_type == 0) */ else // lattice->bc[subs][ n].bc_type != 0 { #if SOLID_COLOR_IS_CHECKERBOARD // Checkerboard pattern over the solids and boundary conditions. if( (i+j)%2) { red_val = (char)200; green_val = (char)200; blue_val = (char)200; val = (char)200; } else { red_val = (char)184; green_val = (char)184; blue_val = (char)184; val = (char)184; } #else /* !( SOLID_COLOR_IS_CHECKERBOARD) */ #if SOLID_COLOR_IS_BLACK red_val = (char)0; green_val = (char)0; blue_val = (char)0; val = (char)0; #else /* !( SOLID_COLOR_IS_BLACK) */ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; #endif /* SOLID_COLOR_IS_BLACK */ #endif /* SOLID_COLOR_IS_CHECKERBOARD */ } /* if( lattice->bc[subs][ n].bc_type == 0) else */ #if MARK_ORIGIN_FOR_REFERENCE // Mark the origin for reference. if( ( i == 0 && j == 0)) { red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; } #endif /* MARK_ORIGIN_FOR_REFERENCE */ if( fwrite( &blue_val, 1, 1, o_uy) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &green_val, 1, 1, o_uy) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &red_val, 1, 1, o_uy) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} } /* for( i=0; i<lattice->param.LY; i++) */ // Pad for 4-byte boundaries. val = (char)0; for( i=0; i<pad; i++) { if( fwrite( &val, 1, 1, o_u ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &val, 1, 1, o_ux) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &val, 1, 1, o_uy) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} } } /* for( j=0; j<lattice->param.LY; j++) */ fclose(o_u ); fclose(o_ux); fclose(o_uy); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/u%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); printf("u2bmp() -- Wrote file \"%s\".\n", filename); sprintf( filename, "./out/u_x%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); printf("u2bmp() -- Wrote file \"%s\".\n", filename); sprintf( filename, "./out/u_y%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); printf("u2bmp() -- Wrote file \"%s\".\n", filename); #endif /* VERBOSITY_LEVEL > 0 */ } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ #if STORE_UEQ frame = time/lattice->param.FrameRate; sprintf( filename, "./in/%dx%d.bmp", lattice->param.LX, lattice->param.LY); if( !( in = fopen( filename, "r"))) { printf("u2bmp() -- Error opening file \"%s\".\n", filename); process_exit(1); } // n = fread( void *BUF, size_t SIZE, size_t COUNT, FILE *FP); n = fread( &bmfh, sizeof(struct bitmap_file_header), 1, in ); if( strncmp(bmfh.bfType,"BM",2)) { printf("ERROR: Can't process this file type. Exiting!\n"); printf("\n"); process_exit(1); } n = fread( &bmih, sizeof(struct bitmap_info_header), 1, in ); int_ptr = (int*)bmih.biCompression; if( *int_ptr != 0) { printf("ERROR: Can't handle compression. Exiting!\n"); printf("\n"); process_exit(1); } width_ptr = (int*)bmih.biWidth; height_ptr = (int*)bmih.biHeight; bitcount_ptr = (short int*)bmih.biBitCount; // Read palette entries, if applicable. if( *bitcount_ptr < 24) { n = (int)pow(2.,(double)*bitcount_ptr); // Num palette entries. for( i=0; i<n; i++) { k = fread( &rgb, sizeof(struct rgb_quad), 1, in ); if( k!=1) { printf("Error reading palette entry %d. Exiting!\n", i); process_exit(1); } } } fclose(in); // Bytes per row of the bitmap. bytes_per_row = ((int)ceil(( (((double)(*width_ptr))*((double)(*bitcount_ptr)))/8.))); // Bitmaps pad rows to preserve 4-byte boundaries. // The length of a row in the file will be bytes_per_row + pad . pad = ((4) - bytes_per_row%4)%4; compute_max_ueq( lattice, max_u); sprintf( filename, "./out/ueq%dx%d_frame%04d.bmp", lattice->param.LX, lattice->param.LY, frame); if( !( o_u = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/ueq_x%dx%d_frame%04d.bmp", lattice->param.LX, lattice->param.LY, frame); if( !( o_ux = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/ueq_y%dx%d_frame%04d.bmp", lattice->param.LX, lattice->param.LY, frame); if( !( o_uy = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } fwrite( &bmfh, sizeof(struct bitmap_file_header), 1, o_u ); fwrite( &bmih, sizeof(struct bitmap_info_header), 1, o_u ); fwrite( &bmfh, sizeof(struct bitmap_file_header), 1, o_ux ); fwrite( &bmih, sizeof(struct bitmap_info_header), 1, o_ux ); fwrite( &bmfh, sizeof(struct bitmap_file_header), 1, o_uy); fwrite( &bmih, sizeof(struct bitmap_info_header), 1, o_uy); //for( j=lattice->param.LY-1; j>=0; j--) for( j=0; j<lattice->param.LY; j++) { n = j*lattice->param.LX; for( i=0; i<lattice->param.LX; i++, n++) { if( lattice->bc[0][ n].bc_type == /*FLUID_NODE*/0) { #if 1 blue_val = (char)0; green_val = (char)0; red_val = (char)0; u_x = (lattice->ueq[ n].u[0]); u_y = (lattice->ueq[ n].u[1]); u = sqrt(u_x*u_x + u_y*u_y); maxu = sqrt( max_u[0]*max_u[0] + max_u[1]*max_u[1]); if( lattice->bc[0][ n].bc_type & BC_SOLID_NODE) { blue_val = (char)ROUND( 128.*fabs(u_x)/max_u[0]); green_val = (char)ROUND( 128.*fabs(u_y)/max_u[1]); } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) */ else // !( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { blue_val = (char)ROUND( 255.*fabs(u_x)/max_u[0]); green_val = (char)ROUND( 255.*fabs(u_y)/max_u[1]); //red_val = (char)ROUND( 128.*fabs(u)/maxu); } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) else */ #else blue_val = (char)255; green_val = (char)255; red_val = (char)255; u = sqrt(u_x*u_x + u_y*u_y); maxu = sqrt( max_u[0]*max_u[0] + max_u[1]*max_u[1]); //if( fabs(u) > .1*maxu) //{ green_val = (char)ROUND( 255.-255.*fabs(u)/maxu); red_val = (char)ROUND( 255.-255.*fabs(u)/maxu); blue_val = (char)ROUND( 255.-255.*fabs(u)/maxu); //} //else //{ // green_val = (char)0; // red_val = (char)0; // blue_val = (char)0; //} #endif val = (char)0; } /* if( lattice->bc[subs][ n].bc_type == 0) */ else // lattice->bc[subs][ n].bc_type != 0 { #if SOLID_COLOR_IS_CHECKERBOARD // Checkerboard pattern over the solids and boundary conditions. if( (i+j)%2) { red_val = (char)200; green_val = (char)200; blue_val = (char)200; val = (char)200; } else { red_val = (char)184; green_val = (char)184; blue_val = (char)184; val = (char)184; } #else /* !( SOLID_COLOR_IS_CHECKERBOARD) */ #if SOLID_COLOR_IS_BLACK red_val = (char)0; green_val = (char)0; blue_val = (char)0; val = (char)0; #else /* !( SOLID_COLOR_IS_BLACK) */ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; #endif /* SOLID_COLOR_IS_BLACK */ #endif /* SOLID_COLOR_IS_CHECKERBOARD */ } /* if( lattice->bc[subs][ n].bc_type == 0) else */ #if MARK_ORIGIN_FOR_REFERENCE // Mark the origin for reference. if( ( i == 0 && j == 0)) { red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; } #endif /* MARK_ORIGIN_FOR_REFERENCE */ if( fwrite( &blue_val, 1, 1, o_u ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &green_val, 1, 1, o_u ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &red_val, 1, 1, o_u ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( lattice->bc[0][ n].bc_type == /*FLUID_NODE*/0) { blue_val = (char)0; green_val = (char)0; red_val = (char)0; u_x = (lattice->ueq[ n].u[0]); u_y = (lattice->ueq[ n].u[1]); val = (char)0; if( lattice->bc[0][ n].bc_type & BC_SOLID_NODE) { if( u_x > 0) { red_val = val; blue_val = (char)ROUND( 128.*fabs(u_x)/max_u[0]); } else { red_val = (char)ROUND( 128.*fabs(u_x)/max_u[0]); blue_val = val; } } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) */ else // !( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { if( u_x > 0) { red_val = val; blue_val = (char)ROUND( 255.*fabs(u_x)/max_u[0]); } else { red_val = (char)ROUND( 255.*fabs(u_x)/max_u[0]); blue_val = val; } } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) else */ } /* if( lattice->bc[subs][ n].bc_type == 0) */ else // lattice->bc[subs][ n].bc_type != 0 { #if SOLID_COLOR_IS_CHECKERBOARD // Checkerboard pattern over the solids and boundary conditions. if( (i+j)%2) { red_val = (char)200; green_val = (char)200; blue_val = (char)200; val = (char)200; } else { red_val = (char)184; green_val = (char)184; blue_val = (char)184; val = (char)184; } #else /* !( SOLID_COLOR_IS_CHECKERBOARD) */ #if SOLID_COLOR_IS_BLACK red_val = (char)0; green_val = (char)0; blue_val = (char)0; val = (char)0; #else /* !( SOLID_COLOR_IS_BLACK) */ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; #endif /* SOLID_COLOR_IS_BLACK */ #endif /* SOLID_COLOR_IS_CHECKERBOARD */ } /* if( lattice->bc[subs][ n].bc_type == 0) else */ #if MARK_ORIGIN_FOR_REFERENCE // Mark the origin for reference. if( ( i == 0 && j == 0)) { red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; } #endif /* MARK_ORIGIN_FOR_REFERENCE */ if( fwrite( &blue_val, 1, 1, o_ux) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &val, 1, 1, o_ux) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &red_val, 1, 1, o_ux) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( lattice->bc[0][ n].bc_type == /*FLUID_NODE*/0) { blue_val = (char)0; green_val = (char)0; red_val = (char)0; u_x = (lattice->ueq[ n].u[0]); u_y = (lattice->ueq[ n].u[1]); val = (char)0; if( lattice->bc[0][ n].bc_type & BC_SOLID_NODE) { if( u_y > 0) { red_val = val; green_val = (char)ROUND( 128.*fabs(u_y)/max_u[1]); } else { red_val = (char)ROUND( 128.*fabs(u_y)/max_u[1]); green_val = val; } } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) */ else // !( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { if( u_y > 0) { blue_val = (char)ROUND( 255.*fabs(u_y)/max_u[1]); green_val = val; } else { blue_val = val; green_val = (char)ROUND( 255.*fabs(u_y)/max_u[1]); } } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) else */ } /* if( lattice->bc[subs][ n].bc_type == 0) */ else // lattice->bc[subs][ n].bc_type != 0 { #if SOLID_COLOR_IS_CHECKERBOARD // Checkerboard pattern over the solids and boundary conditions. if( (i+j)%2) { red_val = (char)200; green_val = (char)200; blue_val = (char)200; val = (char)200; } else { red_val = (char)184; green_val = (char)184; blue_val = (char)184; val = (char)184; } #else /* !( SOLID_COLOR_IS_CHECKERBOARD) */ #if SOLID_COLOR_IS_BLACK red_val = (char)0; green_val = (char)0; blue_val = (char)0; val = (char)0; #else /* !( SOLID_COLOR_IS_BLACK) */ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; #endif /* SOLID_COLOR_IS_BLACK */ #endif /* SOLID_COLOR_IS_CHECKERBOARD */ } /* if( lattice->bc[subs][ n].bc_type == 0) else */ #if MARK_ORIGIN_FOR_REFERENCE // Mark the origin for reference. if( ( i == 0 && j == 0)) { red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; } #endif /* MARK_ORIGIN_FOR_REFERENCE */ if( fwrite( &blue_val, 1, 1, o_uy) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &green_val, 1, 1, o_uy) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &red_val, 1, 1, o_uy) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} } /* for( i=0; i<lattice->param.LY; i++) */ // Pad for 4-byte boundaries. val = (char)0; for( i=0; i<pad; i++) { if( fwrite( &val, 1, 1, o_u ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &val, 1, 1, o_ux) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &val, 1, 1, o_uy) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} } } /* for( j=0; j<lattice->param.LY; j++) */ fclose(o_u ); fclose(o_ux); fclose(o_uy); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/ueq%dx%d_frame%04d.bmp", lattice->param.LX, lattice->param.LY, frame); printf("u2bmp() -- Wrote file \"%s\".\n", filename); sprintf( filename, "./out/ueq_x%dx%d_frame%04d.bmp", lattice->param.LX, lattice->param.LY, frame); printf("u2bmp() -- Wrote file \"%s\".\n", filename); sprintf( filename, "./out/ueq_y%dx%d_frame%04d.bmp", lattice->param.LX, lattice->param.LY, frame); printf("u2bmp() -- Wrote file \"%s\".\n", filename); #endif /* VERBOSITY_LEVEL > 0 */ #endif /* STORE_UEQ */ #if SAY_HI printf("u2bmp() -- Bye!\n"); printf("\n"); #endif /* SAY_HI */ } /* u2bmp( lattice_ptr lattice, int time) */ // void vor2bmp( char *filename, int time) //############################################################################## // // V O R 2 B M P // void vor2bmp( lattice_ptr lattice, int time) { FILE *in, *o_vor; int i, j, n, m; int pad, bytes_per_row; int frame; char k; char b; struct bitmap_file_header bmfh; struct bitmap_info_header bmih; struct rgb_quad rgb; int *int_ptr; short int *short_int_ptr; int *width_ptr; int *height_ptr; short int *bitcount_ptr; char filename[1024]; char red_val, green_val, blue_val, val; double max_vor_p, max_vor_n; double ave_vor_p, ave_vor_n; double vor; int subs; #if SAY_HI printf("vor2bmp() -- Hi!\n"); #endif /* SAY_HI */ for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { frame = time/lattice->param.FrameRate; sprintf( filename, "./in/%dx%d.bmp", lattice->param.LX, lattice->param.LY); if( !( in = fopen( filename, "r"))) { printf("vor2bmp() -- Error opening file \"%s\".\n", filename); process_exit(1); } // n = fread( void *BUF, size_t SIZE, size_t COUNT, FILE *FP); n = fread( &bmfh, sizeof(struct bitmap_file_header), 1, in ); if( strncmp(bmfh.bfType,"BM",2)) { printf("ERROR: Can't process this file type. Exiting!\n"); printf("\n"); process_exit(1); } n = fread( &bmih, sizeof(struct bitmap_info_header), 1, in ); int_ptr = (int*)bmih.biCompression; if( *int_ptr != 0) { printf("ERROR: Can't handle compression. Exiting!\n"); printf("\n"); process_exit(1); } width_ptr = (int*)bmih.biWidth; height_ptr = (int*)bmih.biHeight; bitcount_ptr = (short int*)bmih.biBitCount; // Read palette entries, if applicable. if( *bitcount_ptr < 24) { n = (int)pow(2.,(double)*bitcount_ptr); // Num palette entries. for( i=0; i<n; i++) { k = fread( &rgb, sizeof(struct rgb_quad), 1, in ); if( k!=1) { printf("Error reading palette entry %d. Exiting!\n", i); process_exit(1); } } } fclose(in); // Bytes per row of the bitmap. bytes_per_row = ((int)ceil(( (((double)(*width_ptr))*((double)(*bitcount_ptr)))/8.))); // Bitmaps pad rows to preserve 4-byte boundaries. // The length of a row in the file will be bytes_per_row + pad . pad = ((4) - bytes_per_row%4)%4; compute_max_vor( lattice, &max_vor_p, &max_vor_n, subs); #if 0 && VERBOSITY_LEVEL > 0 printf("vor2bmp() -- max_vor_p = %f\n", max_vor_p); printf("vor2bmp() -- max_vor_n = %f\n", max_vor_n); #endif /* 0 && VERBOSITY_LEVEL > 0 */ compute_ave_vor( lattice, &ave_vor_p, &ave_vor_n, subs); #if 0 && VERBOSITY_LEVEL > 0 printf("vor2bmp() -- ave_vor_p = %f\n", ave_vor_p); printf("vor2bmp() -- ave_vor_n = %f\n", ave_vor_n); #endif /* 0 && VERBOSITY_LEVEL > 0 */ sprintf( filename, "./out/vor%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); if( !( o_vor = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } fwrite( &bmfh, sizeof(struct bitmap_file_header), 1, o_vor ); fwrite( &bmih, sizeof(struct bitmap_info_header), 1, o_vor ); //for( j=lattice->param.LY-1; j>=0; j--) for( j=0; j<lattice->param.LY; j++) { n = j*lattice->param.LX; for( i=0; i<lattice->param.LX; i++, n++) { if( lattice->bc[subs][ n].bc_type == /*FLUID_NODE*/0) { //u_x = (lattice->macro_vars[subs][ n].u[0]); //u_y = (lattice->macro_vars[subs][ n].u[1]); compute_vorticity( lattice, i, j, n, &vor, subs); //if( fabs(vor)/max_vor_p > .5) //{ // printf("vor2bmp() -- vor/max_vor_p = %f/%f = %f\n", vor, max_vor_p, vor/max_vor_p); //} #if 0 blue_val = (char)255; green_val = (char)255; red_val = (char)255; if( vor > 0) { if( 100.*vor/ave_vor_p > 1.) { //printf("vor2bmp() -- vor/ave_vor_p = %f > 1.\n", vor/ave_vor_p); red_val = (char)0; green_val = (char)0; } else { //printf("vor2bmp() -- vor/ave_vor_p = %f <= 1.\n", vor/ave_vor_p); red_val = (char)ROUND( 255.*( 1. - 10000.*(vor/ave_vor_p)*(vor/ave_vor_p))); green_val = (char)ROUND( 255.*( 1. - 10000.*(vor/ave_vor_p)*(vor/ave_vor_p))); } } else { if( 100.*vor/ave_vor_n > 1.) { //printf("vor2bmp() -- vor/ave_vor_n = %f > 1.\n", vor/ave_vor_n); red_val = (char)0; blue_val = (char)0; } else { //printf("vor2bmp() -- vor/ave_vor_n = %f <= 1.\n", vor/ave_vor_n); red_val = (char)ROUND( 255.*( 1. - 10000.*(vor/ave_vor_n)*(vor/ave_vor_n))); blue_val = (char)ROUND( 255.*( 1. - 10000.*(vor/ave_vor_n)*(vor/ave_vor_n))); } } #else #if 0 blue_val = (char)0; green_val = (char)0; red_val = (char)0; // blue_val = //(char)ROUND( 255.*(vor - max_vor_n)/(max_vor_p-max_vor_n)); if( vor >= 0.) { blue_val = (char)ROUND( 255.*(vor)/(max_vor_p)); } else { red_val = (char)ROUND( 255.*(vor)/(max_vor_n)); } #else red_val = (char)ROUND( 255.*(vor - max_vor_n)/(max_vor_p-max_vor_n)); green_val = (char)ROUND( 255.*(vor - max_vor_n)/(max_vor_p-max_vor_n)); blue_val = (char)ROUND( 255.*(vor - max_vor_n)/(max_vor_p-max_vor_n)); #endif #endif val = (char)0; } /* if( lattice->bc[subs][ n].bc_type == 0) */ else // lattice->bc[subs][ n].bc_type != 0 { #if SOLID_COLOR_IS_CHECKERBOARD // Checkerboard pattern over the solids and boundary conditions. if( (i+j)%2) { red_val = (char)200; green_val = (char)200; blue_val = (char)200; val = (char)200; } else { red_val = (char)184; green_val = (char)184; blue_val = (char)184; val = (char)184; } #else /* !( SOLID_COLOR_IS_CHECKERBOARD) */ //#if SOLID_COLOR_IS_BLACK // red_val = (char)0; // green_val = (char)0; // blue_val = (char)0; // val = (char)0; //#else /* !( SOLID_COLOR_IS_BLACK) */ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; //#endif /* SOLID_COLOR_IS_BLACK */ #endif /* SOLID_COLOR_IS_CHECKERBOARD */ } /* if( lattice->bc[subs][ n].bc_type == 0) else */ #if MARK_ORIGIN_FOR_REFERENCE // Mark the origin for reference. if( ( i == 0 && j == 0)) { red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; } #endif /* MARK_ORIGIN_FOR_REFERENCE */ if( fwrite( &blue_val, 1, 1, o_vor ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &green_val, 1, 1, o_vor ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &red_val, 1, 1, o_vor ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} } /* for( i=0; i<lattice->param.LY; i++) */ // Pad for 4-byte boundaries. val = (char)0; for( i=0; i<pad; i++) { if( fwrite( &val, 1, 1, o_vor ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} } } /* for( j=0; j<lattice->param.LY; j++) */ fclose(o_vor ); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/vor%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); printf("vor2bmp() -- Wrote file \"%s\".\n", filename); #endif /* VERBOSITY_LEVEL > 0 */ } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ #if SAY_HI printf("vor2bmp() -- Bye!\n"); printf("\n"); #endif /* SAY_HI */ } /* vor2bmp( lattice_ptr lattice, int time) */ #if NON_LOCAL_FORCES // void force2bmp( char *filename, int time) //############################################################################## // // F O R C E 2 B M P // void force2bmp( lattice_ptr lattice) { FILE *in, *o_u, *o_ux, *o_uy; int i, j, n, m; int pad, bytes_per_row; int frame; char k; char b; struct bitmap_file_header bmfh; struct bitmap_info_header bmih; struct rgb_quad rgb; int *int_ptr; short int *short_int_ptr; int *width_ptr; int *height_ptr; short int *bitcount_ptr; char filename[1024]; char red_val, green_val, blue_val, val; double max_u[2], maxu; double u_x, u_y, u; int subs; #if SAY_HI printf("force2bmp() -- Hi!\n"); #endif /* SAY_HI */ for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { frame = lattice->time/lattice->param.FrameRate; sprintf( filename, "./in/%dx%d.bmp", lattice->param.LX, lattice->param.LY); if( !( in = fopen( filename, "r"))) { printf("force2bmp() -- Error opening file \"%s\".\n", filename); process_exit(1); } // n = fread( void *BUF, size_t SIZE, size_t COUNT, FILE *FP); n = fread( &bmfh, sizeof(struct bitmap_file_header), 1, in ); if( strncmp(bmfh.bfType,"BM",2)) { printf("ERROR: Can't process this file type. Exiting!\n"); printf("\n"); process_exit(1); } n = fread( &bmih, sizeof(struct bitmap_info_header), 1, in ); int_ptr = (int*)bmih.biCompression; if( *int_ptr != 0) { printf("ERROR: Can't handle compression. Exiting!\n"); printf("\n"); process_exit(1); } width_ptr = (int*)bmih.biWidth; height_ptr = (int*)bmih.biHeight; bitcount_ptr = (short int*)bmih.biBitCount; // Read palette entries, if applicable. if( *bitcount_ptr < 24) { n = (int)pow(2.,(double)*bitcount_ptr); // Num palette entries. for( i=0; i<n; i++) { k = fread( &rgb, sizeof(struct rgb_quad), 1, in ); if( k!=1) { printf("Error reading palette entry %d. Exiting!\n", i); process_exit(1); } } } fclose(in); // Bytes per row of the bitmap. bytes_per_row = ((int)ceil(( (((double)(*width_ptr))*((double)(*bitcount_ptr)))/8.))); // Bitmaps pad rows to preserve 4-byte boundaries. // The length of a row in the file will be bytes_per_row + pad . pad = ((4) - bytes_per_row%4)%4; compute_max_u( lattice, max_u, subs); sprintf( filename, "./out/force_%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); if( !( o_u = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/force_x_%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); if( !( o_ux = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/force_y_%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); if( !( o_uy = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } fwrite( &bmfh, sizeof(struct bitmap_file_header), 1, o_u ); fwrite( &bmih, sizeof(struct bitmap_info_header), 1, o_u ); fwrite( &bmfh, sizeof(struct bitmap_file_header), 1, o_ux ); fwrite( &bmih, sizeof(struct bitmap_info_header), 1, o_ux ); fwrite( &bmfh, sizeof(struct bitmap_file_header), 1, o_uy); fwrite( &bmih, sizeof(struct bitmap_info_header), 1, o_uy); //for( j=lattice->param.LY-1; j>=0; j--) for( j=0; j<lattice->param.LY; j++) { n = j*lattice->param.LX; for( i=0; i<lattice->param.LX; i++, n++) { if( lattice->bc[subs][ n].bc_type == /*FLUID_NODE*/0) { #if 1 blue_val = (char)0; green_val = (char)0; red_val = (char)0; u_x = (lattice->force[subs][ n].force[0]); u_y = (lattice->force[subs][ n].force[1]); u = sqrt(u_x*u_x + u_y*u_y); maxu = sqrt( max_u[0]*max_u[0] + max_u[1]*max_u[1]); if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { blue_val = (char)ROUND( 128.*fabs(u_x)/max_u[0]); green_val = (char)ROUND( 128.*fabs(u_y)/max_u[1]); } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) */ else // !( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { blue_val = (char)ROUND( 255.*fabs(u_x)/max_u[0]); green_val = (char)ROUND( 255.*fabs(u_y)/max_u[1]); red_val = (char)ROUND( 128.*fabs(u)/maxu); } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) else */ #else blue_val = (char)255; green_val = (char)255; red_val = (char)255; u = sqrt(u_x*u_x + u_y*u_y); maxu = sqrt( max_u[0]*max_u[0] + max_u[1]*max_u[1]); //if( fabs(u) > .1*maxu) //{ green_val = (char)ROUND( 255.-255.*fabs(u)/maxu); red_val = (char)ROUND( 255.-255.*fabs(u)/maxu); blue_val = (char)ROUND( 255.-255.*fabs(u)/maxu); //} //else //{ // green_val = (char)0; // red_val = (char)0; // blue_val = (char)0; //} #endif val = (char)0; } /* if( lattice->bc[subs][ n].bc_type == 0) */ else // lattice->bc[subs][ n].bc_type != 0 { #if SOLID_COLOR_IS_CHECKERBOARD // Checkerboard pattern over the solids and boundary conditions. if( (i+j)%2) { red_val = (char)200; green_val = (char)200; blue_val = (char)200; val = (char)200; } else { red_val = (char)184; green_val = (char)184; blue_val = (char)184; val = (char)184; } #else /* !( SOLID_COLOR_IS_CHECKERBOARD) */ #if SOLID_COLOR_IS_BLACK red_val = (char)0; green_val = (char)0; blue_val = (char)0; val = (char)0; #else /* !( SOLID_COLOR_IS_BLACK) */ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; #endif /* SOLID_COLOR_IS_BLACK */ #endif /* SOLID_COLOR_IS_CHECKERBOARD */ } /* if( lattice->bc[subs][ n].bc_type == 0) else */ #if MARK_ORIGIN_FOR_REFERENCE // Mark the origin for reference. if( ( i == 0 && j == 0)) { red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; } #endif /* MARK_ORIGIN_FOR_REFERENCE */ if( fwrite( &blue_val, 1, 1, o_u ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &green_val, 1, 1, o_u ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &red_val, 1, 1, o_u ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( lattice->bc[subs][ n].bc_type == /*FLUID_NODE*/0) { blue_val = (char)0; green_val = (char)0; red_val = (char)0; u_x = (lattice->force[subs][ n].force[0]); u_y = (lattice->force[subs][ n].force[1]); val = (char)0; if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { if( u_x > 0) { red_val = val; blue_val = (char)ROUND( 128.*fabs(u_x)/max_u[0]); } else { red_val = (char)ROUND( 128.*fabs(u_x)/max_u[0]); blue_val = val; } } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) */ else // !( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { if( u_x > 0) { red_val = val; blue_val = (char)ROUND( 255.*fabs(u_x)/max_u[0]); } else { red_val = (char)ROUND( 255.*fabs(u_x)/max_u[0]); blue_val = val; } } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) else */ } /* if( lattice->bc[subs][ n].bc_type == 0) */ else // lattice->bc[subs][ n].bc_type != 0 { #if SOLID_COLOR_IS_CHECKERBOARD // Checkerboard pattern over the solids and boundary conditions. if( (i+j)%2) { red_val = (char)200; green_val = (char)200; blue_val = (char)200; val = (char)200; } else { red_val = (char)184; green_val = (char)184; blue_val = (char)184; val = (char)184; } #else /* !( SOLID_COLOR_IS_CHECKERBOARD) */ #if SOLID_COLOR_IS_BLACK red_val = (char)0; green_val = (char)0; blue_val = (char)0; val = (char)0; #else /* !( SOLID_COLOR_IS_BLACK) */ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; #endif /* SOLID_COLOR_IS_BLACK */ #endif /* SOLID_COLOR_IS_CHECKERBOARD */ } /* if( lattice->bc[subs][ n].bc_type == 0) else */ #if MARK_ORIGIN_FOR_REFERENCE // Mark the origin for reference. if( ( i == 0 && j == 0)) { red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; } #endif /* MARK_ORIGIN_FOR_REFERENCE */ if( fwrite( &blue_val, 1, 1, o_ux) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &val, 1, 1, o_ux) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &red_val, 1, 1, o_ux) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( lattice->bc[subs][ n].bc_type == /*FLUID_NODE*/0) { blue_val = (char)0; green_val = (char)0; red_val = (char)0; u_x = (lattice->force[subs][ n].force[0]); u_y = (lattice->force[subs][ n].force[1]); val = (char)0; if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { if( u_y > 0) { red_val = val; green_val = (char)ROUND( 128.*fabs(u_y)/max_u[1]); } else { red_val = (char)ROUND( 128.*fabs(u_y)/max_u[1]); green_val = val; } } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) */ else // !( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { if( u_y > 0) { blue_val = (char)ROUND( 255.*fabs(u_y)/max_u[1]); green_val = val; } else { blue_val = val; green_val = (char)ROUND( 255.*fabs(u_y)/max_u[1]); } } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) else */ } /* if( lattice->bc[subs][ n].bc_type == 0) */ else // lattice->bc[subs][ n].bc_type != 0 { #if SOLID_COLOR_IS_CHECKERBOARD // Checkerboard pattern over the solids and boundary conditions. if( (i+j)%2) { red_val = (char)200; green_val = (char)200; blue_val = (char)200; val = (char)200; } else { red_val = (char)184; green_val = (char)184; blue_val = (char)184; val = (char)184; } #else /* !( SOLID_COLOR_IS_CHECKERBOARD) */ #if SOLID_COLOR_IS_BLACK red_val = (char)0; green_val = (char)0; blue_val = (char)0; val = (char)0; #else /* !( SOLID_COLOR_IS_BLACK) */ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; #endif /* SOLID_COLOR_IS_BLACK */ #endif /* SOLID_COLOR_IS_CHECKERBOARD */ } /* if( lattice->bc[subs][ n].bc_type == 0) else */ #if MARK_ORIGIN_FOR_REFERENCE // Mark the origin for reference. if( ( i == 0 && j == 0)) { red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; } #endif /* MARK_ORIGIN_FOR_REFERENCE */ if( fwrite( &blue_val, 1, 1, o_uy) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &green_val, 1, 1, o_uy) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &red_val, 1, 1, o_uy) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} } /* for( i=0; i<lattice->param.LY; i++) */ // Pad for 4-byte boundaries. val = (char)0; for( i=0; i<pad; i++) { if( fwrite( &val, 1, 1, o_u ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &val, 1, 1, o_ux) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &val, 1, 1, o_uy) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} } } /* for( j=0; j<lattice->param.LY; j++) */ fclose(o_u ); fclose(o_ux); fclose(o_uy); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/force_%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); printf("force2bmp() -- Wrote file \"%s\".\n", filename); sprintf( filename, "./out/force_x_%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); printf("force2bmp() -- Wrote file \"%s\".\n", filename); sprintf( filename, "./out/force_y_%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); printf("force2bmp() -- Wrote file \"%s\".\n", filename); #endif /* VERBOSITY_LEVEL > 0 */ } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ #if SAY_HI printf("force2bmp() -- Bye!\n"); printf("\n"); #endif /* SAY_HI */ } /* void force2bmp( lattice_ptr lattice) */ // void sforce2bmp( char *filename, int time) //############################################################################## // // F O R C E 2 B M P // void sforce2bmp( lattice_ptr lattice) { FILE *in, *o_u, *o_ux, *o_uy; int i, j, n, m; int pad, bytes_per_row; int frame; char k; char b; struct bitmap_file_header bmfh; struct bitmap_info_header bmih; struct rgb_quad rgb; int *int_ptr; short int *short_int_ptr; int *width_ptr; int *height_ptr; short int *bitcount_ptr; char filename[1024]; char red_val, green_val, blue_val, val; double max_u[2], maxu; double u_x, u_y, u; int subs; #if SAY_HI printf("sforce2bmp() -- Hi!\n"); #endif /* SAY_HI */ for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { frame = lattice->time/lattice->param.FrameRate; sprintf( filename, "./in/%dx%d.bmp", lattice->param.LX, lattice->param.LY); if( !( in = fopen( filename, "r"))) { printf("sforce2bmp() -- Error opening file \"%s\".\n", filename); process_exit(1); } // n = fread( void *BUF, size_t SIZE, size_t COUNT, FILE *FP); n = fread( &bmfh, sizeof(struct bitmap_file_header), 1, in ); if( strncmp(bmfh.bfType,"BM",2)) { printf("ERROR: Can't process this file type. Exiting!\n"); printf("\n"); process_exit(1); } n = fread( &bmih, sizeof(struct bitmap_info_header), 1, in ); int_ptr = (int*)bmih.biCompression; if( *int_ptr != 0) { printf("ERROR: Can't handle compression. Exiting!\n"); printf("\n"); process_exit(1); } width_ptr = (int*)bmih.biWidth; height_ptr = (int*)bmih.biHeight; bitcount_ptr = (short int*)bmih.biBitCount; // Read palette entries, if applicable. if( *bitcount_ptr < 24) { n = (int)pow(2.,(double)*bitcount_ptr); // Num palette entries. for( i=0; i<n; i++) { k = fread( &rgb, sizeof(struct rgb_quad), 1, in ); if( k!=1) { printf("Error reading palette entry %d. Exiting!\n", i); process_exit(1); } } } fclose(in); // Bytes per row of the bitmap. bytes_per_row = ((int)ceil(( (((double)(*width_ptr))*((double)(*bitcount_ptr)))/8.))); // Bitmaps pad rows to preserve 4-byte boundaries. // The length of a row in the file will be bytes_per_row + pad . pad = ((4) - bytes_per_row%4)%4; compute_max_u( lattice, max_u, subs); sprintf( filename, "./out/sforce_%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); if( !( o_u = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/sforce_x_%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); if( !( o_ux = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } sprintf( filename, "./out/sforce_y_%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); if( !( o_uy = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } fwrite( &bmfh, sizeof(struct bitmap_file_header), 1, o_u ); fwrite( &bmih, sizeof(struct bitmap_info_header), 1, o_u ); fwrite( &bmfh, sizeof(struct bitmap_file_header), 1, o_ux ); fwrite( &bmih, sizeof(struct bitmap_info_header), 1, o_ux ); fwrite( &bmfh, sizeof(struct bitmap_file_header), 1, o_uy); fwrite( &bmih, sizeof(struct bitmap_info_header), 1, o_uy); //for( j=lattice->param.LY-1; j>=0; j--) for( j=0; j<lattice->param.LY; j++) { n = j*lattice->param.LX; for( i=0; i<lattice->param.LX; i++, n++) { if( lattice->bc[subs][ n].bc_type == /*FLUID_NODE*/0) { #if 1 blue_val = (char)0; green_val = (char)0; red_val = (char)0; u_x = (lattice->force[subs][ n].sforce[0]); u_y = (lattice->force[subs][ n].sforce[1]); u = sqrt(u_x*u_x + u_y*u_y); maxu = sqrt( max_u[0]*max_u[0] + max_u[1]*max_u[1]); if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { blue_val = (char)ROUND( 128.*fabs(u_x)/max_u[0]); green_val = (char)ROUND( 128.*fabs(u_y)/max_u[1]); } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) */ else // !( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { blue_val = (char)ROUND( 255.*fabs(u_x)/max_u[0]); green_val = (char)ROUND( 255.*fabs(u_y)/max_u[1]); red_val = (char)ROUND( 128.*fabs(u)/maxu); } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) else */ #else blue_val = (char)255; green_val = (char)255; red_val = (char)255; u = sqrt(u_x*u_x + u_y*u_y); maxu = sqrt( max_u[0]*max_u[0] + max_u[1]*max_u[1]); //if( fabs(u) > .1*maxu) //{ green_val = (char)ROUND( 255.-255.*fabs(u)/maxu); red_val = (char)ROUND( 255.-255.*fabs(u)/maxu); blue_val = (char)ROUND( 255.-255.*fabs(u)/maxu); //} //else //{ // green_val = (char)0; // red_val = (char)0; // blue_val = (char)0; //} #endif val = (char)0; } /* if( lattice->bc[subs][ n].bc_type == 0) */ else // lattice->bc[subs][ n].bc_type != 0 { #if SOLID_COLOR_IS_CHECKERBOARD // Checkerboard pattern over the solids and boundary conditions. if( (i+j)%2) { red_val = (char)200; green_val = (char)200; blue_val = (char)200; val = (char)200; } else { red_val = (char)184; green_val = (char)184; blue_val = (char)184; val = (char)184; } #else /* !( SOLID_COLOR_IS_CHECKERBOARD) */ #if SOLID_COLOR_IS_BLACK red_val = (char)0; green_val = (char)0; blue_val = (char)0; val = (char)0; #else /* !( SOLID_COLOR_IS_BLACK) */ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; #endif /* SOLID_COLOR_IS_BLACK */ #endif /* SOLID_COLOR_IS_CHECKERBOARD */ } /* if( lattice->bc[subs][ n].bc_type == 0) else */ #if MARK_ORIGIN_FOR_REFERENCE // Mark the origin for reference. if( ( i == 0 && j == 0)) { red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; } #endif /* MARK_ORIGIN_FOR_REFERENCE */ if( fwrite( &blue_val, 1, 1, o_u ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &green_val, 1, 1, o_u ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &red_val, 1, 1, o_u ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( lattice->bc[subs][ n].bc_type == /*FLUID_NODE*/0) { blue_val = (char)0; green_val = (char)0; red_val = (char)0; u_x = (lattice->force[subs][ n].sforce[0]); u_y = (lattice->force[subs][ n].sforce[1]); val = (char)0; if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { if( u_x > 0) { red_val = val; blue_val = (char)ROUND( 128.*fabs(u_x)/max_u[0]); } else { red_val = (char)ROUND( 128.*fabs(u_x)/max_u[0]); blue_val = val; } } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) */ else // !( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { if( u_x > 0) { red_val = val; blue_val = (char)ROUND( 255.*fabs(u_x)/max_u[0]); } else { red_val = (char)ROUND( 255.*fabs(u_x)/max_u[0]); blue_val = val; } } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) else */ } /* if( lattice->bc[subs][ n].bc_type == 0) */ else // lattice->bc[subs][ n].bc_type != 0 { #if SOLID_COLOR_IS_CHECKERBOARD // Checkerboard pattern over the solids and boundary conditions. if( (i+j)%2) { red_val = (char)200; green_val = (char)200; blue_val = (char)200; val = (char)200; } else { red_val = (char)184; green_val = (char)184; blue_val = (char)184; val = (char)184; } #else /* !( SOLID_COLOR_IS_CHECKERBOARD) */ #if SOLID_COLOR_IS_BLACK red_val = (char)0; green_val = (char)0; blue_val = (char)0; val = (char)0; #else /* !( SOLID_COLOR_IS_BLACK) */ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; #endif /* SOLID_COLOR_IS_BLACK */ #endif /* SOLID_COLOR_IS_CHECKERBOARD */ } /* if( lattice->bc[subs][ n].bc_type == 0) else */ #if MARK_ORIGIN_FOR_REFERENCE // Mark the origin for reference. if( ( i == 0 && j == 0)) { red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; } #endif /* MARK_ORIGIN_FOR_REFERENCE */ if( fwrite( &blue_val, 1, 1, o_ux) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &val, 1, 1, o_ux) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &red_val, 1, 1, o_ux) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( lattice->bc[subs][ n].bc_type == /*FLUID_NODE*/0) { blue_val = (char)0; green_val = (char)0; red_val = (char)0; u_x = (lattice->force[subs][ n].sforce[0]); u_y = (lattice->force[subs][ n].sforce[1]); val = (char)0; if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { if( u_y > 0) { red_val = val; green_val = (char)ROUND( 128.*fabs(u_y)/max_u[1]); } else { red_val = (char)ROUND( 128.*fabs(u_y)/max_u[1]); green_val = val; } } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) */ else // !( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) { if( u_y > 0) { blue_val = (char)ROUND( 255.*fabs(u_y)/max_u[1]); green_val = val; } else { blue_val = val; green_val = (char)ROUND( 255.*fabs(u_y)/max_u[1]); } } /* if( lattice->bc[subs][ n].bc_type & BC_SOLID_NODE) else */ } /* if( lattice->bc[subs][ n].bc_type == 0) */ else // lattice->bc[subs][ n].bc_type != 0 { #if SOLID_COLOR_IS_CHECKERBOARD // Checkerboard pattern over the solids and boundary conditions. if( (i+j)%2) { red_val = (char)200; green_val = (char)200; blue_val = (char)200; val = (char)200; } else { red_val = (char)184; green_val = (char)184; blue_val = (char)184; val = (char)184; } #else /* !( SOLID_COLOR_IS_CHECKERBOARD) */ #if SOLID_COLOR_IS_BLACK red_val = (char)0; green_val = (char)0; blue_val = (char)0; val = (char)0; #else /* !( SOLID_COLOR_IS_BLACK) */ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; #endif /* SOLID_COLOR_IS_BLACK */ #endif /* SOLID_COLOR_IS_CHECKERBOARD */ } /* if( lattice->bc[subs][ n].bc_type == 0) else */ #if MARK_ORIGIN_FOR_REFERENCE // Mark the origin for reference. if( ( i == 0 && j == 0)) { red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255; } #endif /* MARK_ORIGIN_FOR_REFERENCE */ if( fwrite( &blue_val, 1, 1, o_uy) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &green_val, 1, 1, o_uy) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &red_val, 1, 1, o_uy) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} } /* for( i=0; i<lattice->param.LY; i++) */ // Pad for 4-byte boundaries. val = (char)0; for( i=0; i<pad; i++) { if( fwrite( &val, 1, 1, o_u ) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &val, 1, 1, o_ux) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} if( fwrite( &val, 1, 1, o_uy) != 1) { printf("%s %d >> BOOM!\n", __FILE__, __LINE__); process_exit(1);} } } /* for( j=0; j<lattice->param.LY; j++) */ fclose(o_u ); fclose(o_ux); fclose(o_uy); #if VERBOSITY_LEVEL > 0 sprintf( filename, "./out/sforce_%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); printf("sforce2bmp() -- Wrote file \"%s\".\n", filename); sprintf( filename, "./out/sforce_x_%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); printf("sforce2bmp() -- Wrote file \"%s\".\n", filename); sprintf( filename, "./out/sforce_y_%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); printf("sforce2bmp() -- Wrote file \"%s\".\n", filename); #endif /* VERBOSITY_LEVEL > 0 */ } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ #if SAY_HI printf("sforce2bmp() -- Bye!\n"); printf("\n"); #endif /* SAY_HI */ } /* void sforce2bmp( lattice_ptr lattice) */ #endif /* NON_LOCAL_FORCES */ // void pdf2bmp( char *filename, int time) //############################################################################## // // P D F 2 B M P // void pdf2bmp( lattice_ptr lattice, int time) { FILE *in, *o; int i, j, n, m; int pad, bytes_per_row; int frame; char k; char b; struct bitmap_file_header bmfh; struct bitmap_info_header bmih; struct rgb_quad rgb; int *int_ptr; short int *short_int_ptr; int *width_ptr; int *height_ptr; short int *bitcount_ptr; char filename[1024]; char red_val, green_val, blue_val, val; double fval; double min_rho, max_rho; int subs; double **colormap; int num_colors; int fx=2, fy=2; // Number of pixels to use to represent a pdf value. #if SAY_HI printf("pdf2bmp() -- Hi!\n"); #endif /* SAY_HI */ // TODO: Implement pdf2bmp() printf("%s (%d) >> pdf2bmp() is not yet implemented. Exiting!\n", __FILE__, __LINE__); process_exit(1); #if SAY_HI printf("pdf2bmp() -- Bye!\n"); printf("\n"); #endif /* SAY_HI */ } /* pdf2bmp( lattice_ptr lattice, int time) */ //void slice( lattice_ptr lattice) //############################################################################## // // - Extract slice (i0,j0)..(i1,j1) from the macroscopic variables. // // - Write to matlab scripts for easy processing. // void slice( lattice_ptr lattice) { int i0, j0, i1, j1; int i, j, n; int len; double *rho_slice; double *u_x_slice; double *u_y_slice; char filename[1024]; FILE *in, *o; int subs; if( use_slice_dot_in_file( lattice)) { printf("%s %d >> Using slice.in file.\n",__FILE__,__LINE__); if( !( in = fopen( "./in/slice.in", "r"))) { // Default slice. i0 = 0; j0 = (int)floor((double)lattice->param.LY/2.); i1 = lattice->param.LX-1; j1 = (int)floor((double)lattice->param.LY/2.); } else { // Read slice from file. fscanf( in, "%d", &i0); fscanf( in, "%d", &j0); fscanf( in, "%d", &i1); fscanf( in, "%d", &j1); fclose( in); } private_slice( lattice, "slice", i0, j0, i1, j1); } else { if( get_slice_x( lattice) >= 0) { private_slice( lattice, "slice_x", get_slice_x( lattice), 0, get_slice_x( lattice), get_LY( lattice) ); } if( get_slice_y( lattice) >= 0) { private_slice( lattice, "slice_y", 0, get_slice_y( lattice), get_LX( lattice), get_slice_y( lattice) ); } } } /* void slice( lattice_ptr lattice) */ //void private_slice( lattice_ptr lattice, int i0, int j0, int i1, int j1) //############################################################################## // // - Extract slice (i0,j0)..(i1,j1) from the macroscopic variables. // // - Write to matlab scripts for easy processing. // void private_slice( lattice_ptr lattice, char *root_word, int i0, int j0, int i1, int j1) { int i, j, k, n; int len, wid; double *rho_slice; double *rho_ave; double *u_x_slice; double *u_x_ave; double *u_y_slice; double *u_y_ave; char filename[1024]; FILE *in, *o; double ave_rho; int subs; char plot_specs[2][4] = { { '\'', 'b', '\'', '\x0'}, { '\'', 'r', '\'', '\x0'} }; if( i0 == i1) { if( i0 < 0 || i0 >= get_LX( lattice)) { printf("lbio.c: private_slice() -- " "ERROR: Can't take slice at " "i0 = i1 = %d.\n", i0 ); i0 = lattice->param.LX/2; i1 = lattice->param.LX/2; printf("lbio.c: private_slice() -- Defaulting to i0 = i1 = %d.\n", i0); return; } len = j1 - j0 + 1; if( len > lattice->param.LY) { len = lattice->param.LY; } rho_slice = (double*)malloc( len*sizeof(double)); rho_ave = (double*)malloc( len*sizeof(double)); u_x_slice = (double*)malloc( len*sizeof(double)); u_x_ave = (double*)malloc( len*sizeof(double)); u_y_slice = (double*)malloc( len*sizeof(double)); u_y_ave = (double*)malloc( len*sizeof(double)); // Generate matlab script to plot the slices. sprintf( filename, "./out/%s%dx%d_frame%04d.m", root_word, lattice->param.LX, lattice->param.LY, lattice->time/lattice->param.FrameRate); if( !( o = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } fprintf( o, "%% function [ slice_data] = slice%dx%d_frame%04d( plot_stuff)\n", lattice->param.LX, lattice->param.LY, lattice->time/lattice->param.FrameRate); fprintf( o, "function [ slice_data] = slice%dx%d_frame%04d( plot_stuff)\n\n", lattice->param.LX, lattice->param.LY, lattice->time/lattice->param.FrameRate); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { // Slice. len = 0; for( j=j0; j<=j1; j++) { n = j*lattice->param.LX + i0; if( j>=0 && j<lattice->param.LY) { rho_slice[ len] = lattice->macro_vars[subs][ n].rho; u_x_slice[ len] = lattice->macro_vars[subs][ n].u[0]; u_y_slice[ len] = lattice->macro_vars[subs][ n].u[1]; rho_ave[ len] = 0.; u_x_ave[ len] = 0.; u_y_ave[ len] = 0.; wid = 0; for( i=0; i<lattice->param.LX; i++) { if( !( lattice->bc[subs][ j*lattice->param.LX + i].bc_type & BC_SOLID_NODE)) { rho_ave[ len] += lattice->macro_vars[subs][ j*lattice->param.LX+i].rho; u_x_ave[ len] += lattice->macro_vars[subs][ j*lattice->param.LX+i].u[0]; u_y_ave[ len] += lattice->macro_vars[subs][ j*lattice->param.LX+i].u[1]; wid++; } } rho_ave[ len] /= wid; u_x_ave[ len] /= wid; u_y_ave[ len] /= wid; len++; } } fprintf( o, "rho_slice%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", rho_slice[ n]); } fprintf( o, "];\n"); fprintf( o, "rho_ave%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", rho_ave[ n]); } fprintf( o, "];\n"); fprintf( o, "u_x_slice%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", u_x_slice[ n]); } fprintf( o, "];\n"); fprintf( o, "u_x_ave%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", u_x_ave[ n]); } fprintf( o, "];\n"); fprintf( o, "u_y_slice%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", u_y_slice[ n]); } fprintf( o, "];\n"); fprintf( o, "u_y_ave%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", u_y_ave[ n]); } fprintf( o, "];\n"); } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ fprintf( o, "slice_data = zeros(%d,%d,%d);\n", len, 6, NUM_FLUID_COMPONENTS); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( o, "slice_data(:,1,%d) = rho_slice%02d;\n", subs+1, subs); fprintf( o, "slice_data(:,2,%d) = rho_ave%02d;\n" , subs+1, subs); fprintf( o, "slice_data(:,3,%d) = u_x_slice%02d;\n", subs+1, subs); fprintf( o, "slice_data(:,4,%d) = u_x_ave%02d;\n" , subs+1, subs); fprintf( o, "slice_data(:,5,%d) = u_y_slice%02d;\n", subs+1, subs); fprintf( o, "slice_data(:,6,%d) = u_y_ave%02d;\n" , subs+1, subs); fprintf( o, "disp('slice_data(:,1,%d) = rho_slice%02d');\n", subs+1, subs); fprintf( o, "disp('slice_data(:,2,%d) = rho_ave%02d' );\n", subs+1, subs); fprintf( o, "disp('slice_data(:,3,%d) = u_x_slice%02d');\n", subs+1, subs); fprintf( o, "disp('slice_data(:,4,%d) = u_x_ave%02d' );\n", subs+1, subs); fprintf( o, "disp('slice_data(:,5,%d) = u_y_slice%02d');\n", subs+1, subs); fprintf( o, "disp('slice_data(:,6,%d) = u_y_ave%02d' );\n", subs+1, subs); } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ } /* if( i0 == i1) */ else if( j0 == j1) { if( j0 < 0 || j0 >= lattice->param.LY) { printf("lbio.c: private_slice() -- " "ERROR: Can't take slice at " "j0 = j1 = %d.\n", j0 ); j0 = lattice->param.LY/2; j1 = lattice->param.LY/2; printf("lbio.c: private_slice() -- Defaulting to j0 = j1 = %d.\n", j0); return; } len = i1 - i0 + 1; if( len > lattice->param.LX) { len = lattice->param.LX; } rho_slice = (double*)malloc( len*sizeof(double)); rho_ave = (double*)malloc( len*sizeof(double)); u_x_slice = (double*)malloc( len*sizeof(double)); u_x_ave = (double*)malloc( len*sizeof(double)); u_y_slice = (double*)malloc( len*sizeof(double)); u_y_ave = (double*)malloc( len*sizeof(double)); // Generate matlab script to plot the slices. sprintf( filename, "./out/%s%dx%d_frame%04d.m", root_word, lattice->param.LX, lattice->param.LY, lattice->time/lattice->param.FrameRate); if( !( o = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } fprintf( o, "%% function [ slice_data] = slice%dx%d_frame%04d( plot_stuff)\n", lattice->param.LX, lattice->param.LY, lattice->time/lattice->param.FrameRate); fprintf( o, "function [ slice_data] = slice%dx%d_frame%04d( plot_stuff)\n\n", lattice->param.LX, lattice->param.LY, lattice->time/lattice->param.FrameRate); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { // Slice. len = 0; for( i=i0; i<=i1; i++) { n = j0*lattice->param.LX + i; if( i>=0 && i<lattice->param.LX) { rho_slice[ len] = lattice->macro_vars[subs][ n].rho; u_x_slice[ len] = lattice->macro_vars[subs][ n].u[0]; u_y_slice[ len] = lattice->macro_vars[subs][ n].u[1]; rho_ave[ len] = 0.; u_x_ave[ len] = 0.; u_y_ave[ len] = 0.; wid = 0; for( j=0; j<lattice->param.LY; j++) { if( !( lattice->bc[subs][ j*lattice->param.LX + i].bc_type & BC_SOLID_NODE)) { rho_ave[ len] += lattice->macro_vars[subs][ j*lattice->param.LX+i].rho; u_x_ave[ len] += lattice->macro_vars[subs][ j*lattice->param.LX+i].u[0]; u_y_ave[ len] += lattice->macro_vars[subs][ j*lattice->param.LX+i].u[1]; wid++; } } rho_ave[ len] /= wid; u_x_ave[ len] /= wid; u_y_ave[ len] /= wid; len++; } } fprintf( o, "rho_slice%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", rho_slice[ n]); } fprintf( o, "];\n"); fprintf( o, "rho_ave%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", rho_ave[ n]); } fprintf( o, "];\n"); fprintf( o, "u_x_slice%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", u_x_slice[ n]); } fprintf( o, "];\n"); fprintf( o, "u_x_ave%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", u_x_ave[ n]); } fprintf( o, "];\n"); if(1) { fprintf( o, "u_y_slice%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", u_y_slice[ n]); } fprintf( o, "];\n"); } else { // // Output a series of slices showing entry length effects. // len = 0; // fprintf( o, "u_y_slice%02d_j%d = [ ", subs, j); // for( i=i0; i<=i1; i++) // { // n = j0*lattice->param.LX + i; // if( i>=0 && i<lattice->param.LX) // { // for( j=1; // j<lattice->param.LY-1; // j+=(int)floor(((double)lattice->param.LY/10.)) ) // { // fprintf( o, " %20.17f ", lattice->macro_vars[subs][ n].u[1]); // } // } // } // fprintf( o, "];\n"); } fprintf( o, "u_y_ave%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", u_y_ave[ n]); } fprintf( o, "];\n"); } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ fprintf( o, "slice_data = zeros(%d,%d,%d);\n", len, 6, NUM_FLUID_COMPONENTS); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( o, "slice_data(:,1,%d) = rho_slice%02d;\n", subs+1, subs); fprintf( o, "slice_data(:,2,%d) = rho_ave%02d;\n" , subs+1, subs); fprintf( o, "slice_data(:,3,%d) = u_x_slice%02d;\n", subs+1, subs); fprintf( o, "slice_data(:,4,%d) = u_x_ave%02d;\n" , subs+1, subs); fprintf( o, "slice_data(:,5,%d) = u_y_slice%02d;\n", subs+1, subs); fprintf( o, "slice_data(:,6,%d) = u_y_ave%02d;\n" , subs+1, subs); fprintf( o, "disp('slice_data(:,1,%d) = rho_slice%02d');\n", subs+1, subs); fprintf( o, "disp('slice_data(:,2,%d) = rho_ave%02d' );\n", subs+1, subs); fprintf( o, "disp('slice_data(:,3,%d) = u_x_slice%02d');\n", subs+1, subs); fprintf( o, "disp('slice_data(:,4,%d) = u_x_ave%02d' );\n", subs+1, subs); fprintf( o, "disp('slice_data(:,5,%d) = u_y_slice%02d');\n", subs+1, subs); fprintf( o, "disp('slice_data(:,6,%d) = u_y_ave%02d' );\n", subs+1, subs); } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ } /* if( i0 == i1) else if( j0 == j1) */ else { // Count. len = 0; for( i=i0; i<=i1; i++) { if( i>=0 && i<lattice->param.LX) { j = j0 + (i-i0)*((j1-j0)/(i1-i0)); if( j>=0 && j<lattice->param.LY) { len++; } } } rho_slice = (double*)malloc( len*sizeof(double)); rho_ave = (double*)malloc( len*sizeof(double)); u_x_slice = (double*)malloc( len*sizeof(double)); u_x_ave = (double*)malloc( len*sizeof(double)); u_y_slice = (double*)malloc( len*sizeof(double)); u_y_ave = (double*)malloc( len*sizeof(double)); // Generate matlab script to plot the slices. sprintf( filename, "./out/%s%dx%d_frame%04d.m", root_word, lattice->param.LX, lattice->param.LY, lattice->time/lattice->param.FrameRate); if( !( o = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); process_exit(1); } for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { // Slice. len = 0; for( i=i0; i<=i1; i++) { if( i>=0 && i<lattice->param.LX) { j = j0 + (i-i0)*((j1-j0)/(i1-i0)); if( j>=0 && j<lattice->param.LY) { n = j*lattice->param.LX + i; if( n != -1) { rho_slice[ len] = lattice->macro_vars[subs][ n].rho; u_x_slice[ len] = lattice->macro_vars[subs][ n].u[0]; u_y_slice[ len] = lattice->macro_vars[subs][ n].u[1]; rho_ave[ len] = 0.; u_x_ave[ len] = 0.; u_y_ave[ len] = 0.; wid = 0; for( k=0; k<lattice->param.LY; k++) { if( !( lattice->bc[subs][ j*lattice->param.LX + i].bc_type & BC_SOLID_NODE)) { rho_ave[ len] += lattice->macro_vars[subs][ k*lattice->param.LX+i].rho; u_x_ave[ len] += lattice->macro_vars[subs][ k*lattice->param.LX+i].u[0]; u_y_ave[ len] += lattice->macro_vars[subs][ k*lattice->param.LX+i].u[1]; wid++; } } rho_ave[ len] /= wid; u_x_ave[ len] /= wid; u_y_ave[ len] /= wid; } else { rho_slice[ len] = 0.; rho_ave[ len] = 0.; u_x_slice[ len] = 0.; u_x_ave[ len] = 0.; u_y_slice[ len] = 0.; u_y_ave[ len] = 0.; } len++; } } } fprintf( o, "rho_slice%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", rho_slice[ n]); } fprintf( o, "];\n"); fprintf( o, "rho_ave%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", rho_ave[ n]); } fprintf( o, "];\n"); fprintf( o, "u_x_slice%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", u_x_slice[ n]); } fprintf( o, "];\n"); fprintf( o, "u_x_ave%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", u_x_ave[ n]); } fprintf( o, "];\n"); fprintf( o, "u_y_slice%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", u_y_slice[ n]); } fprintf( o, "];\n"); fprintf( o, "u_y_ave%02d = [ ", subs); for( n=0; n<len; n++) { fprintf( o, " %20.17f ", u_y_ave[ n]); } fprintf( o, "];\n"); } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ } /* if( i0 == i1) else if( j0 == j1) else */ free( rho_slice); free( rho_ave ); free( u_x_slice); free( u_x_ave ); free( u_y_slice); free( u_y_ave ); fprintf( o, "if( plot_stuff)\n"); // Plot density. fprintf( o, "figure;"); fprintf( o, "hold on;"); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( o, "plot( rho_slice%02d, %s);", subs, plot_specs[subs]); } fprintf( o, "warning off;"); fprintf( o, "title('\\rho slice (%d,%d)..(%d,%d)');\n", i0, j0, i1, j1); fprintf( o, "warning on;"); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( o, "figure;"); fprintf( o, "plot( rho_slice%02d, %s);", subs, plot_specs[subs]); fprintf( o, "warning off;"); fprintf( o, "title('\\rho slice (%d,%d)..(%d,%d), subs %d');\n", i0, j0, i1, j1, subs); fprintf( o, "warning on;"); } // Plot average density. fprintf( o, "figure;"); fprintf( o, "hold on;"); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( o, "plot( rho_ave%02d, %s);", subs, plot_specs[subs]); } fprintf( o, "warning off;"); fprintf( o, "title('\\rho_{ave} slice (%d,%d)..(%d,%d)');\n", i0, j0, i1, j1); fprintf( o, "warning on;"); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( o, "figure;"); fprintf( o, "plot( rho_ave%02d, %s);", subs, plot_specs[subs]); fprintf( o, "warning off;"); fprintf( o, "title('\\rho_{ave} slice (%d,%d)..(%d,%d), subs %d');\n", i0, j0, i1, j1, subs); fprintf( o, "warning on;"); } // Plot x velocity. fprintf( o, "figure;"); fprintf( o, "hold on;"); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( o, "plot( u_x_slice%02d, %s);", subs, plot_specs[subs]); } fprintf( o, "warning off;"); fprintf( o, "title('u_x slice (%d,%d)..(%d,%d)');\n", i0, j0, i1, j1); fprintf( o, "warning on;"); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( o, "figure;"); fprintf( o, "plot( u_x_slice%02d, %s);", subs, plot_specs[subs]); fprintf( o, "warning off;"); fprintf( o, "title('u_x slice (%d,%d)..(%d,%d), subs %d');\n", i0, j0, i1, j1, subs); fprintf( o, "warning on;"); } // Plot average x-velocity. fprintf( o, "figure;"); fprintf( o, "hold on;"); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( o, "plot( u_x_ave%02d, %s);", subs, plot_specs[subs]); } fprintf( o, "warning off;"); fprintf( o, "title('ux_{ave} slice (%d,%d)..(%d,%d)');\n", i0, j0, i1, j1); fprintf( o, "warning on;"); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( o, "figure;"); fprintf( o, "plot( u_x_ave%02d, %s);", subs, plot_specs[subs]); fprintf( o, "warning off;"); fprintf( o, "title('ux_{ave} slice (%d,%d)..(%d,%d), subs %d');\n", i0, j0, i1, j1, subs); fprintf( o, "warning on;"); } // Plot y velocity. fprintf( o, "figure;"); fprintf( o, "hold on;"); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( o, "plot( u_y_slice%02d, %s);", subs, plot_specs[subs]); } fprintf( o, "warning off;"); fprintf( o, "title('u_y slice (%d,%d)..(%d,%d)');\n", i0, j0, i1, j1); fprintf( o, "warning on;"); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( o, "figure;"); fprintf( o, "plot( u_y_slice%02d, %s);", subs, plot_specs[subs]); fprintf( o, "warning off;"); fprintf( o, "title('u_y slice (%d,%d)..(%d,%d), subs %d');\n", i0, j0, i1, j1, subs); fprintf( o, "warning on;"); } // Plot average y-velocity. fprintf( o, "figure;"); fprintf( o, "hold on;"); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( o, "plot( u_y_ave%02d, %s);", subs, plot_specs[subs]); } fprintf( o, "warning off;"); fprintf( o, "title('uy_{ave} slice (%d,%d)..(%d,%d)');\n", i0, j0, i1, j1); fprintf( o, "warning on;"); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( o, "figure;"); fprintf( o, "plot( u_y_ave%02d, %s);", subs, plot_specs[subs]); fprintf( o, "warning off;"); fprintf( o, "title('uy_{ave} slice (%d,%d)..(%d,%d), subs %d');\n", i0, j0, i1, j1, subs); fprintf( o, "warning on;"); } #if 1 // Compare with analytical poissuille flow profile. for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { if( lattice->param.gforce[subs][0] == 0 && lattice->param.gforce[subs][1] != 0 ) { // Poisseuille in y direction. fprintf( o, "disp(sprintf('\\nPoisseuille in y direction:'));\n"); fprintf( o, "figure;\n"); fprintf( o, "i0 = %d;\n", i0); fprintf( o, "i1 = %d;\n", i1); fprintf( o, "disp(sprintf(' [ i0 i1] = [ %%d %%d]',i0,i1));\n"); fprintf( o, "H = i1 - i0 + 1;\n"); fprintf( o, "disp(sprintf(' H = %%d', H));\n"); fprintf( o, "R = H/2;\n"); fprintf( o, "disp(sprintf(' R = H/2 = %%20.17f', R));\n"); fprintf( o, "nu = 1/6;\n"); fprintf( o, "disp(sprintf(' nu = %%20.17f', nu));\n"); compute_ave_rho( lattice, &ave_rho, subs); fprintf( o, "rho_ave = %20.17f;\n", ave_rho); fprintf( o, "disp(sprintf(' rho_ave = %%20.17f', rho_ave));\n"); //fprintf( o, "mu = nu*%20.17f;\n", ave_rho); //fprintf( o, "disp(sprintf(' mu = %%20.17f', mu));\n"); fprintf( o, "gforceval = %20.17f;\n", lattice->param.gforce[subs][1]/lattice->param.tau[subs]); fprintf( o, "disp(sprintf(' gforceval = %%20.17f', gforceval));\n"); fprintf( o, "i = [i0:.1:i1];\n" "ucalc = " "( gforceval / (2*nu)) * " "( R^2 - ( abs( i - (i1+i0)/2 ).^2));\n" ); fprintf( o, "disp(sprintf(' size(ucalc) = %%dx%%d\\n',size(ucalc,1),size(ucalc,2)));\n"); fprintf( o, "plot( i, ucalc, 'k');"); fprintf( o, "title('analytical Poiseuille profile');\n"); fprintf( o, "figure;\n"); fprintf( o, "hold on;\n"); fprintf( o, "plot( i, ucalc, 'k');\n"); fprintf( o, "plot( u_y_slice%02d, 'bo');", subs); fprintf( o, "title('LB results overlaying analytical Poiseuille profile');\n"); fprintf( o, "hold off;\n"); } /* if( lattice->param.gforce[subs][0] == 0 && lattice->param.gforce... */ else if( lattice->param.gforce[subs][1] == 0 && lattice->param.gforce[subs][0] != 0 ) { // Poisseuille in x direction. fprintf( o, "disp(sprintf('\\nPoisseuille in x direction:'));\n"); fprintf( o, "figure;\n"); fprintf( o, "j0 = %d;\n", j0); fprintf( o, "j1 = %d;\n", j1); fprintf( o, "disp(sprintf(' [ j0 j1] = [ %%d %%d]',j0,j1));\n"); fprintf( o, "H = j1 - j0 + 1;\n"); fprintf( o, "disp(sprintf(' H = %%d', H));\n"); fprintf( o, "R = H/2;\n"); fprintf( o, "disp(sprintf(' R = H/2 = %%20.17f', R));\n"); fprintf( o, "nu = 1/6;\n"); fprintf( o, "disp(sprintf(' nu = %%20.17f', nu));\n"); compute_ave_rho( lattice, &ave_rho, subs); fprintf( o, "rho_ave = %20.17f;\n", ave_rho); fprintf( o, "disp(sprintf(' rho_ave = %%20.17f', rho_ave));\n"); //fprintf( o, "mu = nu*%20.17f;\n", ave_rho); //fprintf( o, "disp(sprintf(' mu = %%20.17f', mu));\n"); fprintf( o, "gforceval = %20.17f;\n", lattice->param.gforce[subs][0]/lattice->param.tau[subs]); fprintf( o, "disp(sprintf(' gforceval = %%20.17f', gforceval));\n"); fprintf( o, "j = [j0:.1:j1];" "ucalc = " "( gforceval / (2*nu)) * " "( R^2 - ( abs( j - (j1+j0)/2 ).^2));\n" ); fprintf( o, "disp(sprintf(' size(ucalc) = %%dx%%d\\n'," "size(ucalc,1),size(ucalc,2)));\n"); fprintf( o, "plot( j, ucalc, 'k');"); fprintf( o, "title('analytical Poiseuille profile');\n"); fprintf( o, "figure;\n"); fprintf( o, "hold on;\n"); fprintf( o, "plot( j, ucalc, 'k');\n"); fprintf( o, "plot( u_x_slice%02d, 'bo');", subs); fprintf( o, "title('LB results overlaying analytical " "Poiseuille profile');\n"); fprintf( o, "hold off;\n"); //printf( o, "figure;\n"); //fprintf( o, "plot( ucalc(j0+1:10:10*j1+1) - u_x_slice%02d, 'r');", subs); //fprintf( o, "title( 'ucalc - u_x_slice%02d');\n", subs); } /* if( lattice->param.gforce[subs][0] == 0 && lattice->param.gforce... */ // Slice key. (Shows where in the domain the slice cuts.) fprintf( o, "figure; plot( [ %d %d], [ %d %d], 'r-.');", i0, i1, j0, j1); fprintf( o, "axis equal;"); fprintf( o, "axis([ %d %d %d %d]);", 0, lattice->param.LX-1, 0, lattice->param.LY-1); fprintf( o, "title('Slice key.');\n"); #if VERBOSITY_LEVEL > 0 printf("private_slice() -- Wrote file \"%s\".\n", filename); #endif /* VERBOSITY_LEVEL > 0 */ } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ #endif fprintf( o, "end\n"); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( o, "disp(sprintf('q_x = %%f',rho_slice%02d*u_x_slice%02d'/max(size(rho_slice%02d))'));\n", subs, subs, subs); fprintf( o, "disp(sprintf('q_y = %%f',rho_slice%02d*u_y_slice%02d'/max(size(rho_slice%02d))'));\n", subs, subs, subs); } fclose(o); } /* void private_slice( lattice_ptr lattice, int i0, int j0, int i1, int j1) */ #if INAMURO_SIGMA_COMPONENT && STORE_BTC void dump_sigma_btc( lattice_ptr lattice) { FILE *o; char fn[1024]; int n; double D; int btc_spot, start_time; if( lattice->param.sigma_btc_rate <= 0 || lattice->FlowDir==0) { return; } btc_spot = (lattice->param.sigma_btc_spot >= 0) ? (lattice->param.sigma_btc_spot-1) : (((lattice->FlowDir==1)?(lattice->param.LX):(lattice->param.LY))-2-1); start_time = (lattice->param.sigma_start>0) ?(lattice->param.sigma_start) :(0); sprintf( fn, "./out/sigma_btc.m"); o = fopen( fn, "w+"); // Timesteps where measurements are taken. fprintf( o, "ts = [\n"); for( n=1; n<lattice->SizeBTC; n++) { fprintf( o, "%20.17f\n", lattice->param.sigma_btc[5*n+0]-start_time); } fprintf( o, "];\n"); // Break through curve at sigma_spot-1. fprintf( o, "btc01 = [\n"); for( n=1; n<lattice->SizeBTC; n++) { fprintf( o, "%20.17f\n", lattice->param.sigma_btc[5*n+1]); } fprintf( o, "];\n"); // Break through curve at sigma_spot. fprintf( o, "btc02 = [\n"); for( n=1; n<lattice->SizeBTC; n++) { fprintf( o, "%20.17f\n", lattice->param.sigma_btc[5*n+2]); } fprintf( o, "];\n"); // Break through curve at sigma_spot+1. fprintf( o, "btc03 = [\n"); for( n=1; n<lattice->SizeBTC; n++) { fprintf( o, "%20.17f\n", lattice->param.sigma_btc[5*n+3]); } fprintf( o, "];\n"); // Velocity at sigma_spot. fprintf( o, "btc_v = [\n"); for( n=1; n<lattice->SizeBTC; n++) { fprintf( o, "%20.17f\n", lattice->param.sigma_btc[5*n+4]); } fprintf( o, "];\n"); // Concentration gradient. fprintf( o, "dcdx = [\n"); for( n=1; n<lattice->SizeBTC; n++) { fprintf( o, "%20.17f\n", .5*( lattice->param.sigma_btc[5*n+3] - lattice->param.sigma_btc[5*n+1]) ); } fprintf( o, "];\n"); // C*v. fprintf( o, "Cv = [\n"); for( n=1; n<lattice->SizeBTC; n++) { fprintf( o, "%20.17f\n", //lattice->param.sigma_btc[4*n+1]*lattice->param.sigma_btc[4*n+3] ); ( lattice->param.sigma_btc[5*n+2]*lattice->param.sigma_btc[5*n+4]) ); } fprintf( o, "];\n"); // Cf = ( C*v - D*dcdx) / v. D = (1./3.)*(lattice->param.tau[1] - .5); fprintf( o, "Cf = [\n"); for( n=1; n<lattice->SizeBTC; n++) { fprintf( o, "%20.17f\n", ( ( lattice->param.sigma_btc[5*n+2]*lattice->param.sigma_btc[5*n+4]) - ( D)*.5*( lattice->param.sigma_btc[5*n+3] - lattice->param.sigma_btc[5*n+1]) ) / ( lattice->param.sigma_btc[5*n+4]) ); } fprintf( o, "];\n"); fprintf( o, "D = %20.17f;\n", D); fprintf( o, "disp(sprintf('D = %%20.17f',D));\n"); // Plot btc01. //fprintf( o, "figure; plot(btc01);\n"); //fprintf( o, "axis([ %d %d 0 max(max(btc01),%20.17f)])\n", // 1, lattice->SizeBTC+1, lattice->param.rho_sigma); //fprintf( o, "title('BTC at L=%d, t=%d:%d:%d');\n", // btc_spot-1, start_time, // lattice->param.sigma_btc_rate, // lattice->NumTimeSteps ); fprintf( o, "figure;\n"); // SubPlot btc0{1,2,3}. fprintf( o, "subplot(2,2,1);\n"); fprintf( o, "hold on; plot(btc01);\n"); fprintf( o, "hnd = get(gca,'Children');\n"); fprintf( o, "set( hnd(1), 'Color', [ .8 .8 .8]);\n"); fprintf( o, "hold on; plot(btc03);\n"); fprintf( o, "hnd = get(gca,'Children');\n"); fprintf( o, "set( hnd(1), 'Color', [ .8 .8 .8]);\n"); fprintf( o, "hold on; plot(btc02);\n"); fprintf( o, "set(gca,'Xlim',[ 0 size(btc02,1)])\n"); //fprintf( o, "axis([ %d %d 0 max(max(btc02),%20.17f)])\n", // 1, lattice->SizeBTC+1, lattice->param.rho_sigma); fprintf( o, "title('BTC at L\\in\\{%d,%d,%d\\}, t=%d:%d:%d');\n", btc_spot-1, btc_spot, btc_spot+1, start_time, lattice->param.sigma_btc_rate, lattice->NumTimeSteps ); // Plot btc03. //fprintf( o, "figure; plot(btc03);\n"); //fprintf( o, "axis([ %d %d 0 max(max(btc03),%20.17f)])\n", // 1, lattice->SizeBTC+1, lattice->param.rho_sigma); //fprintf( o, "title('BTC at L=%d, t=%d:%d:%d');\n", // btc_spot+1, start_time, // lattice->param.sigma_btc_rate, // lattice->NumTimeSteps ); // SubPlot C*v. fprintf( o, "subplot(2,2,2);\n"); fprintf( o, "plot(Cv);\n"); fprintf( o, "set(gca,'Xlim',[ 0 size(btc02,1)]);\n"); fprintf( o, "title('C*v at L=%d, t=%d:%d:%d');\n", btc_spot, start_time, lattice->param.sigma_btc_rate, lattice->NumTimeSteps ); // SubPlot dcdx. fprintf( o, "subplot(2,2,3);\n"); fprintf( o, "plot(dcdx);\n"); fprintf( o, "set(gca,'Xlim',[ 0 size(btc02,1)]);\n"); fprintf( o, "title('dc/dx at L=%d, t=%d:%d:%d');\n", btc_spot, start_time, lattice->param.sigma_btc_rate, lattice->NumTimeSteps ); // SubPlot Cf. fprintf( o, "subplot(2,2,4);\n"); fprintf( o, "plot(Cf);\n"); fprintf( o, "set(gca,'Xlim',[ 0 size(btc02,1)]);\n"); fprintf( o, "title('Cf=(C*v-D*(dC/dx))/v at L=%d, t=%d:%d:%d');\n", btc_spot, start_time, lattice->param.sigma_btc_rate, lattice->NumTimeSteps ); // Give figure a name (shows up in title bar). fprintf( o, "set(gcf,'Name','Breakthrough curve data at t=%d:%d:%d');\n", start_time, lattice->param.sigma_btc_rate, lattice->NumTimeSteps ); // Plot [Cr(x),'r'][Cr(x-dx),'m'][Cv(x),'g'][Cf(x),'b'] fprintf( o, "figure;\n"); fprintf( o, "hold on;\n"); fprintf( o, "plot( btc02, 'rx');\n"); fprintf( o, "plot(Cf, 'bo');\n"); fprintf( o, "hold off;\n"); fprintf( o, "set(gca,'Xlim',[ 0 size(btc02,1)]);\n"); fprintf( o, "title('Cr=''rx'', Cf=''bo''');\n"); // Give figure a name (shows up in title bar). fprintf( o, "set(gcf,'Name','Resident C_r and flux averaged C_f concentrations " "at t=%d:%d:%d');\n", start_time, lattice->param.sigma_btc_rate, lattice->NumTimeSteps ); // Turn off figure number in title bar. fprintf( o, "set(gcf,'NumberTitle','off');\n"); fprintf( o, "%% FlowDir = %d;\n", lattice->FlowDir); fclose(o); printf("\nBTC (size=%d) stored in file \"%s\".\n", lattice->SizeBTC, fn); } /* void dump_sigma_btc( lattice_ptr lattice) */ #endif /* INAMURO_SIGMA_COMPONENT && STORE_BTC */ //void count_colormap( int *num_colors) //############################################################################## // // C O U N T C O L O R M A P // // - Count colormap entries in file colormap.rgb . // void count_colormap( int *num_colors) { FILE *in; char filename[1024]; double r, g, b; // First, count the number of entries. sprintf( filename, "%s", "./in/colormap.rgb"); if( !( in = fopen( filename, "r+"))) { printf("Error opening file \"%s\" for reading. Exiting!\n", filename); process_exit(1); } *num_colors = 0; fscanf( in, "%lf %lf %lf", &r, &g, &b); while( !feof(in)) { (*num_colors)++; fscanf( in, "%lf %lf %lf", &r, &g, &b); } fclose(in); } /* void count_colormap( int *num_colors) */ //void allocate_colormap( double ***colormap, int *num_colors) //############################################################################## // // A L L O C A T E C O L O R M A P // void allocate_colormap( double ***colormap, int num_colors) { int i; *colormap = (double**)malloc( num_colors*sizeof(double*)); for( i=0; i<num_colors; i++) { (*colormap)[i] = (double*)malloc( 3*sizeof(double)); } } /* void allocate_colormap( double ***colormap, int num_colors) */ //void read_colormap( double **colormap, int num_colors) //############################################################################## // // R E A D C O L O R M A P // // - Read colormap from file colormap.rgb . // // - Color map values are stored with one set of rgb values per line. // // - RGB values are stored between 0 and 1 . // // - Colormap values could come from Matlab, e.g. // // >> cm = colormap; // >> save 'colormap.rgb' cm -ascii; // void read_colormap( double **colormap, int num_colors) { FILE *in; char filename[1024]; double r, g, b; int n; sprintf( filename, "%s", "./in/colormap.rgb"); if( !( in = fopen( filename, "r+"))) { printf("Error opening file \"%s\" for reading. Exiting!\n", filename); process_exit(1); } n = 0; fscanf( in, "%lf %lf %lf", &r, &g, &b); while( !feof(in)) { assert( n!=num_colors); colormap[n][0] = r; colormap[n][1] = g; colormap[n][2] = b; n++; fscanf( in, "%lf %lf %lf", &r, &g, &b); } fclose(in); } /* void read_colormap( double **colormap, int num_colors) */ //void deallocate_colormap( double ***colormap, int num_colors) //############################################################################## // // D E A L L O C A T E C O L O R M A P // void deallocate_colormap( double ***colormap, int num_colors) { int i; for( i=0; i<num_colors; i++) { free( (*colormap)[i]); } free( *colormap); } /* void deallocate_colormap( double ***colormap, int num_colors) */ void get_color( double **colormap, int num_colors, double c, char *r, char *g, char *b) { int n; double n1, n2; double w1, w2; if( c>=0. && c<=1.) { #if 1 n = (int)ROUND( c*((double)num_colors-1.)); // printf("get_color() -- c = %f, num_colors = %d, n = %d\n", c, num_colors, n); *r = (char)ROUND(255.*colormap[ n][0]); *g = (char)ROUND(255.*colormap[ n][1]); *b = (char)ROUND(255.*colormap[ n][2]); // printf("get_color() -- n = %d, (%f,%f,%f)\n", n, (double)*r, (double)*g, (double)*b); #else n1 = floor( c*((double)num_colors-1.)); n2 = ceil( c*((double)num_colors-1.)); w1 = c-n1; w2 = n2-c; *r = (char)ROUND(255.* ( w1*colormap[ (int)n1][0] + w2*colormap[ (int)n2][0])); *g = (char)ROUND(255.* ( w1*colormap[ (int)n1][1] + w2*colormap[ (int)n2][1])); *b = (char)ROUND(255.* ( w1*colormap[ (int)n1][2] + w2*colormap[ (int)n2][2])); #endif } else { *r = (char)(255.); *g = (char)(255.); *b = (char)(255.); } } /* void get_color( double **colormap, int num_colors, double c, ... */ #if WRITE_CHEN_DAT_FILES void chen_output( lattice_ptr lattice) { int x, y; int LX = lattice->param.LX, LY = lattice->param.LY; double *u, *rho[NUM_FLUID_COMPONENTS]; double ux_sum, uy_sum, rho_in, rho_out; FILE *app7, *app8, *app9; char filename[1024]; double sum_mass[NUM_FLUID_COMPONENTS]; int subs; ux_sum = 0.; uy_sum = 0.; for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { sum_mass[ subs] = 0.; } sprintf( filename, "%s", "./out/chen_xyrho.dat"); if( !( app7 = fopen( filename,"a"))) { printf("Error opening \"%s\" for reading. Exiting!\n", filename); process_exit(1); } sprintf( filename, "%s", "./out/chen_xy_ux_uy.dat"); if( !( app8 = fopen( filename,"a"))) { printf("Error opening \"%s\" for reading. Exiting!\n", filename); process_exit(1); } sprintf( filename, "%s", "./out/chen_time.dat"); if( !( app9 = fopen( filename,"a"))) { printf("Error opening \"%s\" for reading. Exiting!\n", filename); process_exit(1); } #if STORE_UEQ u = lattice->ueq[0].u; #else /* !( STORE_UEQ) */ u = lattice->macro_vars[0][0].u; #endif /* STORE_UEQ */ for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { rho[subs] = &( lattice->macro_vars[subs][0].rho); } for( y = 0; y < LY; y++) { for( x = 0; x < LX; x++) { fprintf( app8, " %9.1f %9.1f %13.5e %13.5e\n", (double)(x+1.), (double)(y+1.), *u, *(u+1)); if( !( lattice->bc[0][ y*LX + x].bc_type & BC_SOLID_NODE)) { ux_sum = ux_sum + *u; uy_sum = uy_sum + *(u+1); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { sum_mass[subs] = sum_mass[subs] + *rho[subs]; } } /* if( !obst[y][x]) */ #if STORE_UEQ u+=2; #else /* !( STORE_UEQ) */ u+=3; #endif /* STORE_UEQ */ for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { rho[subs]+=3; } } /* for( x = 1; x <= LX; x++) */ } /* for( y = 1; y <= LY; y++) */ fprintf( app9, "%10d %15.7f %15.7f ", lattice->time, ux_sum, uy_sum); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( app9, "%15.7f ", sum_mass[subs]); } fprintf( app9, "\n"); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { rho[subs] = &( lattice->macro_vars[subs][0].rho); } for( y = 0; y < LY; y++) { for( x = 0; x < LX; x++) { if( !( lattice->bc[0][ y*LX + x].bc_type & BC_SOLID_NODE)) { for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( app7, "%f ", *rho[subs]); } fprintf( app7, "\n"); } else { for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { fprintf( app7, "%f ", 0.); } fprintf( app7, "\n"); } for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { rho[subs]+=3; } } /* for( x = 1; x <= LX; x++) */ } /* for( y = 1; y <= LY; y++) */ fclose( app7); fclose( app8); fclose( app9); #if VERBOSITY_LEVEL > 0 sprintf( filename, "%s", "./out/chen_xyrho.dat"); printf("chen_output() -- Wrote file \"%s\".\n", filename); sprintf( filename, "%s", "./out/chen_xy_ux_uy.dat"); printf("chen_output() -- Wrote file \"%s\".\n", filename); sprintf( filename, "%s", "./out/chen_time.dat"); printf("chen_output() -- Wrote file \"%s\".\n", filename); #endif /* VERBOSITY_LEVEL > 0 */ } /* void chen_output( lattice_ptr lattice) */ #endif /* WRITE_CHEN_DAT_FILES */ //void bmp_read_header( FILE *in) //############################################################################## // // B M P R E A D H E A D E R // void bmp_read_header( FILE *in, struct bitmap_info_header *bmih) { char filename[1024]; int i, j, n, m; int ei, ej; int pad, bytes_per_row; char k; char b, g, r; struct bitmap_file_header bmfh; struct rgb_quad rgb; int *int_ptr; short int *short_int_ptr; int *width_ptr; int *height_ptr; short int *bitcount_ptr; int subs; // Read the headers. n = fread( &bmfh, sizeof(struct bitmap_file_header), 1, in ); if( strncmp(bmfh.bfType,"BM",2)) { printf("ERROR: Can't process this file type. Exiting!\n"); printf("\n"); process_exit(1); } n = fread( bmih, sizeof(struct bitmap_info_header), 1, in ); int_ptr = (int*)bmih->biCompression; if( *int_ptr != 0) { printf("ERROR: Can't handle compression. Exiting!\n"); printf("\n"); process_exit(1); } width_ptr = (int*)bmih->biWidth; height_ptr = (int*)bmih->biHeight; bitcount_ptr = (short int*)bmih->biBitCount; // Read the palette, if necessary. if( *bitcount_ptr < 24) { n = (int)pow(2.,(double)*bitcount_ptr); // Num palette entries. for( i=0; i<n; i++) { k = fread( &rgb, sizeof(struct rgb_quad), 1, in ); if( k!=1) { printf("Error reading palette entry %d. Exiting!\n", i); process_exit(1); } } } // Bytes per row of the bitmap. bytes_per_row = ((int)ceil(( (((double)(*width_ptr))*((double)(*bitcount_ptr)))/8.))); // Bitmaps pad rows to preserve 4-byte boundaries. // The length of a row in the file will be bytes_per_row + pad . pad = ((4) - bytes_per_row%4)%4; } /* void bmp_read_header( FILE *in) */ //void bmp_read_entry( FILE *in, char *r, char *g, char *b) //############################################################################## // // B M P R E A D E N T R Y // void bmp_read_entry( FILE *in, struct bitmap_info_header bmih, char *r, char *g, char *b) { char filename[1024]; int i, j, m; static int n=0; int ei, ej; int pad, bytes_per_row; char k, p; struct bitmap_file_header bmfh; struct rgb_quad rgb; int *int_ptr; short int *short_int_ptr; int *width_ptr; int *height_ptr; short int *bitcount_ptr; int subs; width_ptr = (int*)bmih.biWidth; height_ptr = (int*)bmih.biHeight; bitcount_ptr = (short int*)bmih.biBitCount; // Bytes per row of the bitmap. bytes_per_row = ((int)ceil(( (((double)(*width_ptr))*((double)(*bitcount_ptr)))/8.))); // Bitmaps pad rows to preserve 4-byte boundaries. // The length of a row in the file will be bytes_per_row + pad . pad = ((4) - bytes_per_row%4)%4; if( (n%(bytes_per_row+pad)) == 3*(*width_ptr)) { // Read pad bytes first. for( i=1; i<=pad; i++) { if( !feof(in)) { n+=( k = fread( &p, 1, 1, in ));} } } if( feof(in)) { printf( "bmp_read_entry() -- ERROR:" "Attempt to read past the end of file. " "Exiting!\n"); process_exit(1); } switch(*bitcount_ptr) { case 1: // Monochrome. printf("read_bcs() -- " "Support for Monochrome BMPs is pending. " "Exiting!\n"); process_exit(1); case 4: // 16 colors. printf("read_bcs() -- " "Support for 16 color BMPs is pending. " "Exiting!\n"); process_exit(1); case 8: // 256 colors. printf("read_bcs() -- " "Support for 256 color BMPs is pending. " "Exiting!\n"); process_exit(1); case 24: // 24-bit colors. if( !feof(in)) { n+=( k = fread( b, 1, 1, in ));} if( !feof(in)) { n+=( k = fread( g, 1, 1, in ));} if( !feof(in)) { n+=( k = fread( r, 1, 1, in ));} break; default: // 32-bit colors? printf("ERROR: Unhandled color depth, " "BitCount = %d. Exiting!\n", *bitcount_ptr); process_exit(1); break; } /* switch(*(bmih.biBitCount)) */ if( feof(in)) { printf( "bmp_read_entry() -- ERROR:" "Attempt to read past the end of file. " "Exiting!\n"); process_exit(1); } } /* void bmp_read_entry( FILE *in, char *r, char *g, char *b) */ void report_open( report_ptr report, char *name) { sprintf( report->name, "%s.txt", name); #if VERBOSITY_LEVEL >=1 printf( "\n"); printf( "%s\n", HRULE1); printf( " R E P O R T\n"); printf( "%s\n", HRULE1); printf( "\n"); #endif /* VERBOSITY_LEVEL > 1 */ if( !( report->file = fopen( report->name, "w+"))) { printf("%s %d: ERROR: fopen( %s, \"w+\") = %d\n", __FILE__, __LINE__, report->name, (int)(report->file)); } else { fprintf( report->file, "\n"); fprintf( report->file, "%s\n", HRULE1); fprintf( report->file, " R E P O R T\n"); fprintf( report->file, "%s\n", HRULE1); fprintf( report->file, "\n"); } } /* void report_open( report_ptr report, char *name) */ void report_close( report_ptr report) { #if VERBOSITY_LEVEL >=1 printf( "%s\n", HRULE1); printf( "\n"); #endif /* VERBOSITY_LEVEL >=1 */ if( report->file) { //fprintf( report->file, ""); fprintf( report->file, "\n"); fclose( report->file); #if VERBOSITY_LEVEL >=1 printf( "See file \"%s\".\n", report->name); #endif /* VERBOSITY_LEVEL >=1 */ } /* if( report->file) */ } /* void report_close( report_ptr report) */ void report_entry( report_ptr report, char *entry_left, char *entry_right) { char dots[80]; const int left_col_width = 50; int n; // Fill with dots between columns. Careful if length of left // entry is too long. if( left_col_width > strlen(entry_left) + 2) { dots[ 0] = ' '; for( n=1; n<left_col_width-strlen(entry_left); n++) { dots[n]='.'; } dots[ n ] = ' '; dots[ n+1] = (char)NULL; } else if( left_col_width > strlen(entry_left)) { dots[ 0] = ' '; dots[ left_col_width-strlen(entry_left)-1] = ' '; dots[ left_col_width-strlen(entry_left) ] = ' '; dots[ left_col_width-strlen(entry_left)+1] = (char)NULL; } else { dots[0] = ' '; dots[1] = (char)NULL; } #if VERBOSITY_LEVEL >=1 printf(" %s%s%s\n", entry_left, dots, entry_right); //printf("\n"); #endif /* VERBOSITY_LEVEL >=1 */ if( report->file) { fprintf( report->file, " %s%s%s\n", entry_left, dots, entry_right); //fprintf( report->file, "\n"); } } /* void report_entry( char *entry_left, char *entry_right) */ void report_integer_entry( report_ptr report, char *label, int value, char *units) { char entry[1024]; sprintf( entry, "%d %s", value, units); report_entry( report, label, entry); } /* void report_integer_entry( char *label, int value, char *units) */ void report_ratio_entry( report_ptr report, char *label, double num, double den, char *units) { char entry[1024]; if( den!=0) { sprintf( entry, "%f %s", num/den, units); } else { sprintf( entry, "UNDEF %s", units); } report_entry( report, label, entry); } /* void report_integer_entry( char *label, int value, char *units) */ void report_partition( report_ptr report) { printf( "%s\n", HRULE0); printf( "\n"); if( report->file) { fprintf( report->file, "%s\n", HRULE0); fprintf( report->file, "\n"); } } /* void report_partition( report_ptr report) */ //
111pjb-one
src/lbio_03082005.c
C
gpl3
170,714
//############################################################################## // // Copyright (C), 2005, Michael Sukop and Danny Thorne // // flags.h // // - Preprocessor flags for lb2d_prime. // // Set VERBOSITY_LEVEL to correspond to how deep into nested loops to // print debug and related output. Stuff will be printed down to // loops nested VERBOSITY_LEVEL-1 deep. For example, // // VERBOSITY_LEVEL 0 ==> Nothing is printed, even outside of loops. // VERBOSITY_LEVEL 1 ==> Only stuff outside of loops is printed. // VERBOSITY_LEVEL 2 ==> Stuff inside the first level of loops is printed. // VERBOSITY_LEVEL 3 ==> Stuff inside the second level of loops is printed. // #define VERBOSITY_LEVEL 1 // If SAY_HI is on, some routines will display "hi" and "bye" messages // to stdout. #define SAY_HI 0 // NUM_FLUID_COMPONENTS specifies the number of fluid components. #define NUM_FLUID_COMPONENTS 2 // If NUM_FLUID_COMPONENTS is 2, the second component can be the sigma // component for solute (or thermal) transport as in Inamuro & Yoshino // by turning on INAMURO_SIGMA_COMPONENT . #define INAMURO_SIGMA_COMPONENT ( 1 && NUM_FLUID_COMPONENTS==2) // Toggle Zhang & Chen energy transport method, PRE 67, 0066711 (2003). // Supposed to give thermodynamic consistency unlike old Shan & Chen method. // And supports general equation of state P = P(rho,T). // Utilizes the Inamuro component for evolution of the energy transport // equation. Employs modified compute_phase_force routine to compute // body force term representing non-local interaction potential U among // particles. #define ZHANG_AND_CHEN_ENERGY_TRANSPORT ( 0 && (INAMURO_SIGMA_COMPONENT)) // Simulate POROUS_MEDIA via a solid density parameter // as proposed by Dardis and McCloskey, // Phys Rev E, 57, 4, 4834-4837, 1998 #define POROUS_MEDIA 0 // When there are two (or more) fluid components, a single velocity is // sometimes (always?) used to compute the equilibrium distribution // function. This single velocity will be called upr, and the // STORE_U_COMPOSITE flag will toggle its use. #define STORE_U_COMPOSITE ( 1 && ( (NUM_FLUID_COMPONENTS)==2 \ &&!((INAMURO_SIGMA_COMPONENT)))) // If DO_NOT_STORE_SOLIDS is on, then only the nodes necessary to flow are // stored. In this case, extra storage is needed for geometry information // (e.g. node neighbors). If the ratio of fluid nodes to solid nodes is // small (<~.7), this results in lower storage requirements. #define DO_NOT_STORE_SOLIDS 0 // NON_LOCAL_FORCES toggles any mechanisms for computing and storing // non-local (interaction) forces. #define NON_LOCAL_FORCES ( 1 && !(INAMURO_SIGMA_COMPONENT&&!ZHANG_AND_CHEN_ENERGY_TRANSPORT)) // Toggle manage_body_force call at beginning of time loop for // gradually increasing/decreasing gravity. #define MANAGE_BODY_FORCE 0 // Toggle break through curve (BTC) mechanism for sigma component. #define STORE_BTC ( 1 && INAMURO_SIGMA_COMPONENT) // // Toggle DETERMINE_FLOW_DIRECTION to attempt to determine the direction of // flow. // // Assigns FlowDir = { 0, 1, 2} = { indeterminate, vertical, horizontal} // // NOTE: This determination informs the breakthrough curve mechanism which // should be used in a simple situation with either pressure/velocity // boundaries driving the flow in one direction or gravity driving the flow // in one direction. If the direction of flow cannot be determined, FlowDir // will be set to indeterminate (=0) and a BTC will not be stored. // // NOTE: This determination also informs the sigma slip boundary which // should only be used in the simple situation of flow through a channel // where the geometry is trivial and the direction of flow is obvious. // #define DETERMINE_FLOW_DIRECTION 1 // Toggle mechanism to initialize domain with ux_in or uy_in. This is // useful for setting a velocity in a periodic domain without using // fluid boundary conditions. #define INITIALIZE_WITH_UX_IN 1 //#define INITIALIZE_WITH_UY_IN ( 0 && !(INITIALIZE_WITH_UX_IN)) #define INITIALIZE_WITH_UY_IN 0 // BC_XXX flags are for boundary conditions. // Used to set struct bc_struct::bc_type. // Should be powers of two so that multiple boundary types can be // checked easily via bitwise and (&). // For instance, bc_type & BC_SOLID_NODE & BC_SLIP_NODE to specify // a slip boundary. (Non-slip is the default for solid boundaries.) #define BC_SOLID_NODE 0x00000001 #define BC_FLUID_NODE 0x00000000 #define BC_SLIP_NODE 0x80000000 #define BC_FILM_NODE 0x40000000 #define BC_PRESSURE_N_IN 0x00000010 #define BC_PRESSURE_S_IN 0x00000020 #define BC_PRESSURE_E_IN 0x00000040 #define BC_PRESSURE_W_IN 0x00000080 #define BC_PRESSURE_N_OUT 0x00000100 #define BC_PRESSURE_S_OUT 0x00000200 #define BC_PRESSURE_E_OUT 0x00000400 #define BC_PRESSURE_W_OUT 0x00000800 #define BC_VELOCITY_N_IN 0x00001000 #define BC_VELOCITY_S_IN 0x00002000 #define BC_VELOCITY_E_IN 0x00004000 #define BC_VELOCITY_W_IN 0x00008000 #define BC_VELOCITY_N_OUT 0x00010000 #define BC_VELOCITY_S_OUT 0x00020000 #define BC_VELOCITY_E_OUT 0x00040000 #define BC_VELOCITY_W_OUT 0x00080000 // Dumping the density and velocity data to files can be time consuming and // take up a lot of disk space. If all that is needed is the BMP files, then // turn WRITE_MACRO_VAR_DAT_FILES off to save time and space. #define WRITE_MACRO_VAR_DAT_FILES 1 // Usually the density and velocity are written only for the active nodes // and in a way designed for post-processing. Additional files with the // variables written in a readable grid of all lattice nodes will be // generated when WRITE_RHO_AND_U_TO_TXT is on. This is done in an // inefficient way and is intended only for debugging purposes on tiny // lattices. Note that if WRITE_MACRO_VAR_DAT_FILES is off, this flag // has no effect. #define WRITE_RHO_AND_U_TO_TXT 0 // WRITE_PDF_DAT_FILES is analogous to WRITE_MACRO_VAR_DAT_FILES. #define WRITE_PDF_DAT_FILES 0 // WRITE_PDF_TO_TXT is analogous to WRITE_RHO_AND_U_TO_TXT. #define WRITE_PDF_TO_TXT 0 // Value used to represent an INACTIVE_NODE . This is used in the list // of neighbors ( struct node_struct::nn). It is also used in the // map from (i,j) space onto n index space in rho2bmp() and u2bmp(). #define INACTIVE_NODE -1 // Negative densities (f_a) generally signify impending doom. The code // will die "gracefully" when this happens if PUKE_NEGATIVE_DENSITIES is on. // Might want to turn this off to boost performance on big, long runs that // are expected to survive without such instabilities. #define PUKE_NEGATIVE_DENSITIES 0 // Turn one of these on for coloring of the solids in bmp files. #define SOLID_COLOR_IS_CHECKERBOARD 0 #define SOLID_COLOR_IS_BLACK 1 #define DELAY 0 #define END_GRAV 2000 // A single white pixel will be placed in at the (0,0) lattice node if // MARK_ORIGIN_FOR_REFERENCE is turned on. This is good for assisting with the // problem of tracking orientation of the results between regimes (e.g. C, BMP, // Matlab...). #define MARK_ORIGIN_FOR_REFERENCE 0 #define PERTURBATIONS 0 // If WRITE_CHEN_DAT_FILES is on, the code will output old style chen_*.dat // files to be processed by the old lb_rho_v*.m matlab scripts. #define WRITE_CHEN_DAT_FILES 0 // IC_* flags are for initial conditions. Used in switch statement in // init_problem() in latmat.c . Set the initial_condition parameter // in params.in . #define IC_UNIFORM_RHO_A 1 #define IC_UNIFORM_RHO_B 2 #define IC_UNIFORM_RHO_IN 3 #define IC_BUBBLE 4 #define IC_DIAGONAL 5 #define IC_2X2_CHECKERS 6 #define IC_STATIC 7 #define IC_RECTANGLE 8 #define IC_DOT 9 #define IC_WOLF_GLADROW_DIFFUSION 10 #define IC_YIN_YANG 11 #define IC_HYDROSTATIC 12
111pjb-one
src/flags_disk.h
C
gpl3
7,854
//############################################################################## // // user_stuff.c // // - This file has function definitions of functions that will be called // at specified times (see individual function documentation) if the // lattice->param.do_user_stuff flag is on. // // - The user can fill these routines with whatever they want. // // void user_stuff_pre_frames( lattice_ptr lattice) // // This function is called before the frame loop in lb2d_prime.c. // void user_stuff_pre_frames( lattice_ptr lattice) { lattice->user_stuff->rho_c_start = 83.70420; lattice->user_stuff->rho_c_reverse = 85.70420; lattice->user_stuff->rho_c_inc = ( lattice->user_stuff->rho_c_reverse - lattice->user_stuff->rho_c_start )/15.;//0.2138; lattice->user_stuff->tol = .000001; compute_ave_rho( lattice, &(lattice->user_stuff->rho_ave_prev), 0); compute_ave_u ( lattice, lattice->user_stuff->u_ave_prev , 0); lattice->user_stuff->rho_c = lattice->user_stuff->rho_c_start; lattice->param.rho_in = lattice->user_stuff->rho_c; lattice->param.rho_out = lattice->user_stuff->rho_c; lattice->user_stuff->o = fopen( "rho_c_frames.txt", "w+"); fprintf( lattice->user_stuff->o, "%04d %f %f\n", /*frames*/0, lattice->user_stuff->rho_c, lattice->user_stuff->rho_c); fclose(lattice->user_stuff->o); printf("\n\n%s %d >> frame %4d: Boundary pressure, rho_c = %f\n\n", __FILE__, __LINE__, lattice->frame, lattice->param.rho_in); } /* void user_stuff_pre_frames( lattice_ptr lattice) */ // void user_stuff_frame( lattice_ptr lattice) // // If lattice->param.do_user_stuff is on, this function is called at the // end of each frame in lb2d_prime.c. // void user_stuff_frame( lattice_ptr lattice) { double drho_ave; double du_ave[2]; double rho_c0; compute_ave_rho( lattice, &(lattice->user_stuff->rho_ave), 0); compute_ave_u ( lattice, lattice->user_stuff->u_ave, 0); printf("\n"); printf(" rho_ave = %f\n", lattice->user_stuff->rho_ave); printf(" rho_ave_prev = %f\n", lattice->user_stuff->rho_ave_prev); drho_ave = fabs( lattice->user_stuff->rho_ave - lattice->user_stuff->rho_ave_prev); du_ave[0] = fabs( lattice->user_stuff->u_ave[0] - lattice->user_stuff->u_ave_prev[0]); du_ave[1] = fabs( lattice->user_stuff->u_ave[1] - lattice->user_stuff->u_ave_prev[1]); printf("| rho_ave - rho_ave_prev | = %f\n", drho_ave); printf("| u_ave[0] - u_ave_prev[0] | = %f\n", du_ave[0]); printf("| u_ave[1] - u_ave_prev[1] | = %f\n", du_ave[1]); if( drho_ave < lattice->user_stuff->tol && du_ave[0] < lattice->user_stuff->tol && du_ave[1] < lattice->user_stuff->tol) { rho_c0 = lattice->user_stuff->rho_c; if( lattice->user_stuff->rho_c < lattice->user_stuff->rho_c_reverse) { printf("\n\n%s %d >> Bing! Incrementing rho_c.\n\n", __FILE__, __LINE__); lattice->user_stuff->rho_c += lattice->user_stuff->rho_c_inc; } else if( lattice->user_stuff->rho_c_reverse > 0.) { printf("\n\n%s %d >> Bing! Decrementing rho_c.\n\n", __FILE__, __LINE__); lattice->user_stuff->rho_c_reverse = 0.; lattice->user_stuff->rho_c -= lattice->user_stuff->rho_c_inc; } else { if( lattice->user_stuff->rho_c >= lattice->user_stuff->rho_c_reverse) { printf("\n\n%s %d >> Bing! Decrementing rho_c.\n\n", __FILE__, __LINE__); lattice->user_stuff->rho_c -= lattice->user_stuff->rho_c_inc; } else { printf("\n\n%s %d >> WARNING: rho_c == 0.\n\n", __FILE__, __LINE__); lattice->user_stuff->rho_c = 0.; } } lattice->param.rho_in = lattice->user_stuff->rho_c; lattice->param.rho_out = lattice->user_stuff->rho_c; lattice->user_stuff->o = fopen( "rho_c_frames.txt", "a+"); fprintf( lattice->user_stuff->o, "%04d %f %f\n", get_frame( lattice), rho_c0, lattice->user_stuff->rho_c); fclose( lattice->user_stuff->o); } /* if( drho_ave < lattice->user_stuff->tol && ... */ lattice->user_stuff->rho_ave_prev = lattice->user_stuff->rho_ave; lattice->user_stuff->u_ave_prev[0] = lattice->user_stuff->u_ave[0]; lattice->user_stuff->u_ave_prev[1] = lattice->user_stuff->u_ave[1]; printf(" rho_ave = %f\n", lattice->user_stuff->rho_ave); printf(" rho_ave_prev = %f\n", lattice->user_stuff->rho_ave_prev); //t1 = ((double)clock() - (double)tic)/(double)CLK_TCK; //printf("Resuming at time %f\n", t1); printf("\n\n%s %d >> frame %4d: Boundary pressure, rho_c = %f\n\n", __FILE__, __LINE__, lattice->frame, lattice->param.rho_in); } /* void user_stuff_frame( lattice_ptr lattice) */ // void user_stuff_post_frames( lattice_ptr lattice) // // If lattice->param.do_user_stuff is on, this function is called after // the frame loop in lb2d_prime.c. // void user_stuff_post_frames( lattice_ptr lattice) { } /* void user_stuff_post_frames( lattice_ptr lattice) */ // void user_stuff_pre_times( lattice_ptr lattice) // // If lattice->param.do_user_stuff is on, this function is called before // the time loop in lb2d_prime.c. // void user_stuff_pre_times( lattice_ptr lattice) { } /* void user_stuff_pre_times( lattice_ptr lattice) */ // void user_stuff_time( lattice_ptr lattice) // // If lattice->param.do_user_stuff is on, this function is called at the // end of each time loop in lb2d_prime.c. // void user_stuff_time( lattice_ptr lattice) { if( is_last_step_of_frame( lattice)) { compute_ave_rho( lattice, &(lattice->user_stuff->rho_ave_prev), 0); compute_ave_u ( lattice, lattice->user_stuff->u_ave_prev, 0); printf(" rho_ave_prev = %f\n", lattice->user_stuff->rho_ave_prev); } } /* void user_stuff_time( lattice_ptr lattice) */ // void user_stuff_post_times( lattice_ptr lattice) // // If lattice->param.do_user_stuff is on, this function is called after // the time loop in lb2d_prime.c. // void user_stuff_post_times( lattice_ptr lattice) { } /* void user_stuff_post_times( lattice_ptr lattice) */
111pjb-one
src/user_stuff_bak20070317_dijoining_pressure.c
C
gpl3
6,098
#ifndef FLAGS_H #define FLAGS_H //############################################################################## // // flags.h // // - Preprocessor flags for lb2d_prime. // // Set VERBOSITY_LEVEL to correspond to how deep into nested loops to // print debug and related output. Stuff will be printed down to // loops nested VERBOSITY_LEVEL-1 deep. For example, // // VERBOSITY_LEVEL 0 ==> Nothing is printed, even outside of loops. // VERBOSITY_LEVEL 1 ==> Only stuff outside of loops is printed. // VERBOSITY_LEVEL 2 ==> Stuff inside the first level of loops is printed. // VERBOSITY_LEVEL 3 ==> Stuff inside the second level of loops is printed. // // Flag: VERBOSITY_LEVEL #define VERBOSITY_LEVEL 1 // If SAY_HI is on, some routines will display "hi" and "bye" messages // to stdout. // Flag: SAY_HI #define SAY_HI 0 // NUM_FLUID_COMPONENTS specifies the number of fluid components. // Flag: NUM_FLUID_COMPONENTS #define NUM_FLUID_COMPONENTS 2 // If NUM_FLUID_COMPONENTS is 2, the second component can be the sigma // component for solute (or thermal) transport as in Inamuro & Yoshino // by turning on INAMURO_SIGMA_COMPONENT . // Flag: INAMURO_SIGMA_COMPONENT #define INAMURO_SIGMA_COMPONENT ( 0 && NUM_FLUID_COMPONENTS==2) // Toggle Zhang & Chen energy transport method, PRE 67, 0066711 (2003). // Supposed to give thermodynamic consistency unlike old Shan & Chen method. // And supports general equation of state P = P(rho,T). // Utilizes the Inamuro component for evolution of the energy transport // equation. Employs modified compute_phase_force routine to compute // body force term representing non-local interaction potential U among // particles. // Flag: ZHANG_AND_CHEN_ENERGY_TRANSPORT #define ZHANG_AND_CHEN_ENERGY_TRANSPORT ( 0 && (INAMURO_SIGMA_COMPONENT)) // Simulate POROUS_MEDIA via a solid density parameter // as proposed by Dardis and McCloskey, // Phys Rev E, 57, 4, 4834-4837, 1998 // Flag: POROUS_MEDIA #define POROUS_MEDIA 0 // When there are two (or more) fluid components, a single velocity is // sometimes (always?) used to compute the equilibrium distribution // function. This single velocity will be called upr, and the // STORE_U_COMPOSITE flag will toggle its use. // Flag: STORE_U_COMPOSITE #define STORE_U_COMPOSITE ( 1 && ( (NUM_FLUID_COMPONENTS)==2 \ &&!((INAMURO_SIGMA_COMPONENT)))) // If DO_NOT_STORE_SOLIDS is on, then only the nodes necessary to flow are // stored. In this case, extra storage is needed for geometry information // (e.g. node neighbors). If the ratio of fluid nodes to solid nodes is // small (<~.7), this results in lower storage requirements. // Flag: DO_NOT_STORE_SOLIDS #define DO_NOT_STORE_SOLIDS 0 // If COMPUTE_ON_SOLIDS is on, macroscopic variables and feq will be computed // on solid nodes, even though they are not conceptually meaningful there. // This can be helpful for debugging purposes. #define COMPUTE_ON_SOLIDS 1 // NON_LOCAL_FORCES toggles any mechanisms for computing and storing // non-local (interaction) forces. // Flag: NON_LOCAL_FORCES #define NON_LOCAL_FORCES ( 1 && !(INAMURO_SIGMA_COMPONENT&&!ZHANG_AND_CHEN_ENERGY_TRANSPORT)) // The phase force weighting factors: // WM = weights in the direction of major axes // WD = weights in the direction of diagonals // According to Raskinmaki, it should be WM=2 and WD=1. // According to Chen (via correspondence) it should be WM=4 and WD=1. // According to Sukop and Thorne, it should be WM=1/9 and WD=1/36. // The corresonding G values (a.k.a. G, as in params.in) for the usual // equation of state that we like are -5, -10/3, and -120, respectively. // Flag: WM #define WM (1./ 9.) // Flag: WD #define WD (1./36.) // Toggle manage_body_force call at beginning of time loop for // gradually increasing/decreasing gravity. // Flag: MANAGE_BODY_FORCE #define MANAGE_BODY_FORCE 0 // Toggle break through curve (BTC) mechanism for sigma component. // Flag: STORE_BTC #define STORE_BTC ( 1 && INAMURO_SIGMA_COMPONENT) // // Toggle DETERMINE_FLOW_DIRECTION to attempt to determine the direction of // flow. // // Assigns FlowDir = { 0, 1, 2} = { indeterminate, vertical, horizontal} // // NOTE: This determination informs the breakthrough curve mechanism which // should be used in a simple situation with either pressure/velocity // boundaries driving the flow in one direction or gravity driving the flow // in one direction. If the direction of flow cannot be determined, FlowDir // will be set to indeterminate (=0) and a BTC will not be stored. // // NOTE: This determination also informs the sigma slip boundary which // should only be used in the simple situation of flow through a channel // where the geometry is trivial and the direction of flow is obvious. // // Flag: DETERMINE_FLOW_DIRECTION #define DETERMINE_FLOW_DIRECTION 0 // Toggle mechanism to initialize domain with ux_in or uy_in. This is // useful for setting a velocity in a periodic domain without using // fluid boundary conditions. // Flag: INITIALIZE_WITH_UX_IN #define INITIALIZE_WITH_UX_IN 0 // Flag: INITIALIZE_WITH_UY_IN #define INITIALIZE_WITH_UY_IN 0 // Dumping the density and velocity data to files can be time consuming and // take up a lot of disk space. If all that is needed is the BMP files, then // turn WRITE_MACRO_VAR_DAT_FILES off to save time and space. // Flag: WRITE_MACRO_VAR_DAT_FILES #define WRITE_MACRO_VAR_DAT_FILES 1 // Usually the density and velocity are written only for the active nodes // and in a way designed for post-processing. Additional files with the // variables written in a readable grid of all lattice nodes will be // generated when WRITE_RHO_AND_U_TO_TXT is on. This is done in an // inefficient way and is intended only for debugging purposes on tiny // lattices. Note that if WRITE_MACRO_VAR_DAT_FILES is off, this flag // has no effect. // Flag: WRITE_RHO_AND_U_TO_TXT #define WRITE_RHO_AND_U_TO_TXT 0 // WRITE_PDF_DAT_FILES is analogous to WRITE_MACRO_VAR_DAT_FILES. // Flag: WRITE_PDF_DAT_FILES #define WRITE_PDF_DAT_FILES 0 // WRITE_PDF_TO_TXT is analogous to WRITE_RHO_AND_U_TO_TXT. // Flag: WRITE_PDF_TO_TXT #define WRITE_PDF_TO_TXT 0 // Value used to represent an INACTIVE_NODE . This is used in the list // of neighbors ( struct node_struct::nn). It is also used in the // map from (i,j) space onto n index space in rho2bmp() and u2bmp(). // Flag: INACTIVE_NODE #define INACTIVE_NODE -1 // Negative densities (f_a) generally signify impending doom. The code // will die "gracefully" when this happens if PUKE_NEGATIVE_DENSITIES is on. // Might want to turn this off to boost performance on big, long runs that // are expected to survive without such instabilities. // Flag: PUKE_NEGATIVE_DENSITIES #define PUKE_NEGATIVE_DENSITIES 0 // Turn one of these on for coloring of the solids in bmp files. // Flag: SOLID_COLOR_IS_CHECKERBOARD #define SOLID_COLOR_IS_CHECKERBOARD 0 // Flag: SOLID_COLOR_IS_BLACK #define SOLID_COLOR_IS_BLACK 1 // Flag: DELAY #define DELAY 0 // Flag: END_GRAV #define END_GRAV 2000 // A single white pixel will be placed in at the (0,0) lattice node if // MARK_ORIGIN_FOR_REFERENCE is turned on. This is good for assisting with the // problem of tracking orientation of the results between regimes (e.g. C, BMP, // Matlab...). // Flag: MARK_ORIGIN_FOR_REFERENCE #define MARK_ORIGIN_FOR_REFERENCE 0 // Flag: PERTURBATIONS #define PERTURBATIONS 0 // If WRITE_CHEN_DAT_FILES is on, the code will output old style chen_*.dat // files to be processed by the old lb_rho_v*.m matlab scripts. // Flag: WRITE_CHEN_DAT_FILES #define WRITE_CHEN_DAT_FILES 0 #endif /* FLAGS_H */
111pjb-one
src/flags_bak20061222.h
C
gpl3
7,644
//############################################################################## // // Copyright (C), 2005, Michael Sukop and Danny Thorne // // stream.c // void stream( lattice_ptr lattice) { double *f; int i, j, n, a; int nx, ny, ip, in, jp, jn; int subs; #if SAY_HI printf("stream() -- Hi!\n"); #endif /* SAY_HI */ // substance 0 subs = 0; #if 0 // Get pointer to distribution functions. f = lattice->pdf[subs]->f; // Traverse nodes. for( n=0; n<lattice->NumNodes; n++) { // Copy the rest particle f[0] to ftemp[0]. *(f+9) = *f++; #if 0 for( a=1; a<=8; a++) { // S T R E A M // // - f[a] streams to ftemp[a] of its neighboring node. // if( *nn != INACTIVE_NODE) { pdf[ *nn].ftemp[a] = *f; //printf("STREAM: %d from %d to %d.\n", a, n, *nn); } /* if( *nn != INACTIVE_NODE) */ else { //printf("STREAM: Skipping %d at %d.\n", a, n); } // Move nn to neighbor of next element of f. nn++; // Move next element of f. f++; } /* for( a=1; a<=8; a++) */ #else pdf[].ftemp[ 1] = *f++; pdf[].ftemp[ 2] = *f++; pdf[].ftemp[ 3] = *f++; pdf[].ftemp[ 4] = *f++; pdf[].ftemp[ 5] = *f++; pdf[].ftemp[ 6] = *f++; pdf[].ftemp[ 7] = *f++; pdf[].ftemp[ 8] = *f++; #endif // Advance nn to neighbor of first element of next node. nn+=3; // Advance to the next node. f+=18; } /* for( n=0; n<NumNodes; n++) */ #else nx = lattice->param.LX; ny = lattice->param.LY; #if 0 //-------------------------------------------------------------[ TEST ]--------- f = lattice->pdf[subs]->ftemp; for( j=0; j<ny; j++) { for( i=0; i<nx; i++) { for( a=0; a<9; a++) { *f++ = 0.; } f+=18; } } //-------------------------------------------------------------[ TEST ]--------- #endif #if 1 //if(subs == 0 || lattice->time > 30){ process_send_recv_begin( lattice, subs); n = 0; for( j=0; j<ny; j++) { jp = ( j<ny-1)?( j+1):( 0 ); jn = ( j>0 )?( j-1):( ny-1); for( i=0; i<nx; i++) { ip = ( i<nx-1)?( i+1):( 0 ); in = ( i>0 )?( i-1):( nx-1); f = lattice->pdf[subs][n].f; n++; lattice->pdf[subs][ j *nx + i ].ftemp[ 0] = f[ 0]; lattice->pdf[subs][ j *nx + ip].ftemp[ 1] = f[ 1]; lattice->pdf[subs][ jp*nx + i ].ftemp[ 2] = f[ 2]; lattice->pdf[subs][ j *nx + in].ftemp[ 3] = f[ 3]; lattice->pdf[subs][ jn*nx + i ].ftemp[ 4] = f[ 4]; lattice->pdf[subs][ jp*nx + ip].ftemp[ 5] = f[ 5]; lattice->pdf[subs][ jp*nx + in].ftemp[ 6] = f[ 6]; lattice->pdf[subs][ jn*nx + in].ftemp[ 7] = f[ 7]; lattice->pdf[subs][ jn*nx + ip].ftemp[ 8] = f[ 8]; } /* if( i=0; i<nx; i++, n++) */ } /* if( j=0; j<lattice->param.LY; j++) */ process_send_recv_end( lattice, subs); #endif #endif // substance 1 #if NUM_FLUID_COMPONENTS == 2 subs = 1; #if 0 // Get pointer to distribution functions. f = lattice->pdf[subs]->f; // Traverse nodes. for( n=0; n<lattice->NumNodes; n++) { // Copy the rest particle f[0] to ftemp[0]. *(f+9) = *f++; #if 0 for( a=1; a<=8; a++) { // S T R E A M // // - f[a] streams to ftemp[a] of its neighboring node. // if( *nn != INACTIVE_NODE) { pdf[ *nn].ftemp[a] = *f; //printf("STREAM: %d from %d to %d.\n", a, n, *nn); } /* if( *nn != INACTIVE_NODE) */ else { //printf("STREAM: Skipping %d at %d.\n", a, n); } // Move nn to neighbor of next element of f. nn++; // Move next element of f. f++; } /* for( a=1; a<=8; a++) */ #else pdf[].ftemp[ 1] = *f++; pdf[].ftemp[ 2] = *f++; pdf[].ftemp[ 3] = *f++; pdf[].ftemp[ 4] = *f++; pdf[].ftemp[ 5] = *f++; pdf[].ftemp[ 6] = *f++; pdf[].ftemp[ 7] = *f++; pdf[].ftemp[ 8] = *f++; #endif // Advance nn to neighbor of first element of next node. nn+=3; // Advance to the next node. f+=18; } /* for( n=0; n<NumNodes; n++) */ #else // nx = lattice->param.LX; // ny = lattice->param.LY; #if 0 //-------------------------------------------------------------[ TEST ]--------- f = lattice->pdf[subs]->ftemp; for( j=0; j<ny; j++) { for( i=0; i<nx; i++) { for( a=0; a<9; a++) { *f++ = 0.; } f+=18; } } //-------------------------------------------------------------[ TEST ]--------- #endif #if SIGMA_BULK_FLAG if(lattice->time > lattice->param.sigma_bulk_on) { #endif //if(subs == 0 || lattice->time > 30){ process_send_recv_begin( lattice, subs); n = 0; for( j=0; j<ny; j++) { jp = ( j<ny-1)?( j+1):( 0 ); jn = ( j>0 )?( j-1):( ny-1); for( i=0; i<nx; i++) { ip = ( i<nx-1)?( i+1):( 0 ); in = ( i>0 )?( i-1):( nx-1); f = lattice->pdf[subs][n].f; n++; lattice->pdf[subs][ j *nx + i ].ftemp[ 0] = f[ 0]; lattice->pdf[subs][ j *nx + ip].ftemp[ 1] = f[ 1]; lattice->pdf[subs][ jp*nx + i ].ftemp[ 2] = f[ 2]; lattice->pdf[subs][ j *nx + in].ftemp[ 3] = f[ 3]; lattice->pdf[subs][ jn*nx + i ].ftemp[ 4] = f[ 4]; lattice->pdf[subs][ jp*nx + ip].ftemp[ 5] = f[ 5]; lattice->pdf[subs][ jp*nx + in].ftemp[ 6] = f[ 6]; lattice->pdf[subs][ jn*nx + in].ftemp[ 7] = f[ 7]; lattice->pdf[subs][ jn*nx + ip].ftemp[ 8] = f[ 8]; } /* if( i=0; i<nx; i++, n++) */ } /* if( j=0; j<lattice->param.LY; j++) */ process_send_recv_end( lattice, subs); #if SIGMA_BULK_FLAG } #endif #endif #endif #if SAY_HI printf("stream() -- Bye!\n"); #endif /* SAY_HI */ } /* void stream( lattice_ptr lattice) */
111pjb-one
src/stream.c
C
gpl3
5,742
//############################################################################## // // Copyright (C), 2005, Michael Sukop and Danny Thorne // // params.h // // - Routines for reading and writing params. // // - Reads from params.in // // - Writes to params.dat // // void assign_default_param_vals( lattice_ptr lattice) void assign_default_param_vals( lattice_ptr lattice) { #if 1 lattice->param.LX = 0; lattice->param.LY = 0; //LBMPI #if PARALLEL //LBMPI lattice->lbmpi->NPX = 0; //LBMPI lattice->lbmpi->NPY = 0; //LBMPI #endif /* PARALLEL */ lattice->param.length_scale = 0; lattice->param.NumFrames = 0; lattice->param.FrameRate = 0; lattice->param.tau[0] = 0.; lattice->param.gval[0][0] = 0.; lattice->param.gval[0][1] = 0.; lattice->param.end_grav[0] = 0; #if NUM_FLUID_COMPONENTS==2 lattice->param.tau[1] = 0.; lattice->param.gval[1][0] = 0.; lattice->param.gval[1][1] = 0.; lattice->param.end_grav[1] = 0; #endif /* NUM_FLUID_COMPONENTS==2 */ lattice->param.buoyancy = 0; lattice->param.buoy_subs = 0; lattice->param.incompressible = 0; lattice->param.simple_diffusion = 0; lattice->param.rho_A[0] = 0.; lattice->param.rho_B[0] = 0.; #if SOURCE_ON lattice->param.source_strength = 0.; #endif /*SOURCE_ON*/ #if SINK_ON lattice->param.sink_strength = 0.; #endif /*SINK_ON*/ #if INAMURO_SIGMA_COMPONENT lattice->param.rho_sigma = 0.; lattice->param.beta = 0.; lattice->param.C0 = 0.; lattice->param.rho0 = 0.; lattice->param.drhodC = 0.; lattice->param.rho_sigma_in = 0.; lattice->param.C_in = 0.; lattice->param.rho_sigma_out = 0.; lattice->param.C_out = 0.; lattice->param.u_sigma = 0.; lattice->param.u_sigma_in = 0.; lattice->param.u_sigma_out = 0.; #if SIGMA_BULK_FLAG lattice->param.sigma_bulk_on = 0; #endif /*SIGMA_BULK_FLAG*/ lattice->param.sigma_start = 0; lattice->param.sigma_stop = 0; lattice->param.sigma_btc_rate = 0; lattice->param.sigma_btc_spot = 0; #endif /* INAMURO_SIGMA_COMPONENT */ lattice->param.rho_in = 0.; lattice->param.rho_out = 0.; lattice->param.ux_in = 0.; lattice->param.ux_out = 0.; lattice->param.uy_in = 0.; lattice->param.uy_out = 0.; lattice->param.G = 0.; lattice->param.Gads[0] = 0.; #if NUM_FLUID_COMPONENTS==2 lattice->param.Gads[1] = 0.; #endif /* NUM_FLUID_COMPONENTS==2 */ lattice->param.ns_flag = 0; lattice->param.ns = 0.; lattice->param.slice_x = 0; lattice->param.slice_y = 0; lattice->param.ic_poiseuille = 0; lattice->param.bc_poiseuille = 0; lattice->param.bc_slip_north = 0; #if INAMURO_SIGMA_COMPONENT lattice->param.bc_sigma_slip = 0; lattice->param.bc_sigma_walls = 0; #if TAU_ZHANG_ANISOTROPIC_DISPERSION lattice->param.Dl = 1.; lattice->param.Dt = 1.; #endif #endif /* INAMURO_SIGMA_COMPONENT */ lattice->param.pressure_n_in[0] = 0; lattice->param.pressure_s_in[0] = 0; lattice->param.pressure_n_out[0] = 0; lattice->param.pressure_s_out[0] = 0; lattice->param.velocity_n_in[0] = 0; lattice->param.velocity_s_in[0] = 0; lattice->param.velocity_n_out[0] = 0; lattice->param.velocity_s_out[0] = 0; lattice->param.pressure_e_in[0] = 0; lattice->param.pressure_w_in[0] = 0; lattice->param.pressure_e_out[0] = 0; lattice->param.pressure_w_out[0] = 0; lattice->param.velocity_e_in[0] = 0; lattice->param.velocity_w_in[0] = 0; lattice->param.velocity_e_out[0] = 0; lattice->param.velocity_w_out[0] = 0; #if NUM_FLUID_COMPONENTS==2 lattice->param.pressure_n_in[1] = 0; lattice->param.pressure_s_in[1] = 0; lattice->param.pressure_n_out[1] = 0; lattice->param.pressure_s_out[1] = 0; lattice->param.velocity_n_in[1] = 0; lattice->param.velocity_s_in[1] = 0; lattice->param.velocity_n_out[1] = 0; lattice->param.velocity_s_out[1] = 0; lattice->param.pressure_e_in[1] = 0; lattice->param.pressure_w_in[1] = 0; lattice->param.pressure_e_out[1] = 0; lattice->param.pressure_w_out[1] = 0; lattice->param.velocity_e_in[1] = 0; lattice->param.velocity_w_in[1] = 0; lattice->param.velocity_e_out[1] = 0; lattice->param.velocity_w_out[1] = 0; lattice->param.constcon_n_in = 0; lattice->param.constcon_s_in = 0; lattice->param.constcon_n_out = 0; lattice->param.constcon_s_out = 0; lattice->param.constflx_n_in = 0; lattice->param.constflx_s_in = 0; lattice->param.constflx_n_out = 0; lattice->param.constflx_s_out = 0; lattice->param.constcon_e_in = 0; lattice->param.constcon_w_in = 0; lattice->param.constcon_e_out = 0; lattice->param.constcon_w_out = 0; lattice->param.constflx_e_in = 0; lattice->param.constflx_w_in = 0; lattice->param.constflx_e_out = 0; lattice->param.constflx_w_out = 0; lattice->param.zeroconcgrad_n = 0; lattice->param.zeroconcgrad_s = 0; lattice->param.zeroconcgrad_e = 0; lattice->param.zeroconcgrad_w = 0; lattice->param.zeroconcgrad_full = 0; #endif /* NUM_FLUID_COMPONENTS==2 */ lattice->param.plot_scale_dynamic = 0; lattice->param.use_colormap = 0; lattice->param.initial_condition = 0; lattice->param.x0 = 0.; lattice->param.y0 = 0.; lattice->param.r0 = 0.; lattice->param.cut = 0.; lattice->param.x1 = 0; lattice->param.x2 = 0; lattice->param.y1 = 0; lattice->param.y2 = 0; lattice->param.rel_x1 = 0.; lattice->param.rel_x2 = 0.; lattice->param.rel_y1 = 0.; lattice->param.rel_y2 = 0.; lattice->param.dump_rho = 0; lattice->param.dump_u = 0; lattice->param.dump_force = 0; lattice->param.dump_vor = 0; lattice->param.do_user_stuff = 0; lattice->param.make_octave_scripts = 0; strncpy(lattice->param.out_path,"./out",1024); #endif } /* void assign_default_param_vals( lattice_ptr lattice) */ // void skip_label( FILE *in) //############################################################################## // // S K I P L A B E L // void skip_label( FILE *in) { char c; c = fgetc( in); if( ( c >= '0' && c <='9') || c == '-' || c == '.') { // Digit or Sign or Decimal ungetc( c, in); } else { while( ( c = fgetc( in)) != ' '); while( ( c = fgetc( in)) == ' '); ungetc( c, in); } } /* void skip_label( FILE *in) */ void get_rest_of_line_as_string( FILE *in, char **str, int maxstrlen) { int n; char c; n = 0; c = fgetc(in); while( n< maxstrlen && c!='\n') { printf("%c",c); (*str)[n] = c; n++; c = fgetc(in); } printf("%c",c); } // void skip_rest_of_line( FILE *in) //############################################################################## // // S K I P R E S T O F L I N E // void skip_rest_of_line( FILE *in) { char c; c = fgetc( in); while( ( c = fgetc( in)) != '\n'); } /* void skip_rest_of_line( FILE *in) */ // void read_param_label( const char *infile, char *param_label, int max_length) //############################################################################## // // R E A D P A R A M L A B E L // // - Read parameter label from parameter input file. // // - Returns non-zero if label successfully read. // // - Returns zero if end of file. // // - Aborts with error message otherwise. // int read_param_label( FILE *in, char *param_label, int max_length) { char c; int i; if( max_length<=0) { printf("%s %d >> ERROR: max_length<=0 .\n",__FILE__,__LINE__); process_exit(1); } c = fgetc( in); if( feof(in)) { return 0;} if( ( c >= '0' && c <='9') || c == '-' || c == '.') { // Digit or Sign or Decimal. Labels cannot begin with these. // TODO: Check for other illegal initial characters. printf("%s %d >> Error reading label from parameters input file. " "Exiting!\n",__FILE__,__LINE__); fclose(in); process_exit(1); } /* if( ( c >= '0' && c <='9') || c == '-' || c == '.') */ else { i = 0; param_label[i] = c; // Read label consisting of a string of non-whitespace characters. while( ( c = fgetc( in)) != ' ') { if( feof(in)) { return 0;} i++; if( i+1 > max_length) { printf("%s %d >> ERROR: i+1 > max_length .\n",__FILE__,__LINE__); process_exit(1); } param_label[i] = c; } // Terminate the string. i++; param_label[i] = '\x0'; // Discard whitespace between label and its value. Calling routine // will read the value. while( ( c = fgetc( in)) == ' ') { if( feof(in)) { return 0;} } ungetc( c, in); //printf("%s %d >> Read label \"%s\"\n",__FILE__,__LINE__,param_label); return 1; } /* if( ( c >= '0' && c <='9') || c == '-' || c == '.') else */ } /* void read_param_label( FILE *in, char *param_label, int ... ) */ // void read_params( struct lattice_struct *lattice) //############################################################################## // // R E A D P A R A M S // // - Read the problem parameters from a file. // void read_params( lattice_ptr lattice, const char *infile) { FILE *in; int blank; double dblank; int subs; char param_label[81]; if( !( in = fopen( infile, "r"))) { printf("ERROR: fopen(\"%s\",\"r\") = NULL. Bye, bye!\n", infile); process_exit(1); } #if NEW_PARAMS_INPUT_ROUTINE // First assign default values to the parameters since this new mechanism // doesn't require all parameters to be specified. assign_default_param_vals( lattice); while( read_param_label( in, param_label, 80)) { #if 1 printf("param_label = \"%s\"\n", param_label); #endif if( !strncmp(param_label,"LX",80)) { fscanf( in, "%d\n", &(lattice->param.LX)); printf("%s %d >> LX = %d\n",__FILE__,__LINE__, lattice->param.LX); } else if( !strncmp(param_label,"LY",80)) { fscanf( in, "%d\n", &(lattice->param.LY)); printf("%s %d >> LY = %d\n",__FILE__,__LINE__, lattice->param.LY); } else if( !strncmp(param_label,"NPX",80)) { //LBMPI #if PARALLEL //LBMPI fscanf( in, "%d\n", &(lattice->lbmpi->NPX)); //LBMPI printf("%s %d >> NPX = %d\n",__FILE__,__LINE__, lattice->lbmpi->NPX); //LBMPI #else /* !(PARALLEL) */ //LBMPI fscanf( in, "%d\n", &(blank)); //LBMPI printf("%s %d >> NPX = %d // unused: not PARALELL\n", //LBMPI __FILE__,__LINE__, blank); //LBMPI #endif /* (PARALLEL) */ } else if( !strncmp(param_label,"NPY",80)) { //LBMPI #if PARALLEL //LBMPI fscanf( in, "%d\n", &(lattice->lbmpi->NPY)); //LBMPI printf("%s %d >> NPY = %d\n",__FILE__,__LINE__, lattice->lbmpi->NPY); //LBMPI #else /* !(PARALLEL) */ //LBMPI fscanf( in, "%d\n", &(blank)); //LBMPI printf("%s %d >> NPY = %d // unused: not PARALELL\n", //LBMPI __FILE__,__LINE__, blank); //LBMPI #endif /* (PARALLEL) */ } else if( !strncmp(param_label,"characteristic_length",80)) { fscanf( in, "%d\n", &(lattice->param.length_scale)); printf("%s %d >> characteristic_length = %d\n",__FILE__,__LINE__, lattice->param.length_scale); } else if( !strncmp(param_label,"NumFrames",80)) { fscanf( in, "%d\n", &(lattice->param.NumFrames)); printf("%s %d >> NumFrames = %d\n",__FILE__,__LINE__, lattice->param.NumFrames); } else if( !strncmp(param_label,"FrameRate",80)) { fscanf( in, "%d\n", &(lattice->param.FrameRate)); printf("%s %d >> FrameRate = %d\n",__FILE__,__LINE__, lattice->param.FrameRate); } else if( !strncmp(param_label,"tau[0]",80)) { fscanf( in, "%lf\n", &(lattice->param.tau[0])); printf("%s %d >> tau[0] = %f\n",__FILE__,__LINE__, lattice->param.tau[0]); } else if( !strncmp(param_label,"gval_x[0]",80)) { fscanf( in, "%lf\n", &(lattice->param.gval[0][0])); printf("%s %d >> gval_x[0] = %f\n",__FILE__,__LINE__, lattice->param.gval[0][0]); } else if( !strncmp(param_label,"gval_y[0]",80)) { fscanf( in, "%lf\n", &(lattice->param.gval[0][1])); printf("%s %d >> gval_y[0] = %f\n",__FILE__,__LINE__, lattice->param.gval[0][1]); } else if( !strncmp(param_label,"end_grav[0]",80)) { fscanf( in, "%d\n", &(lattice->param.end_grav[0])); printf("%s %d >> end_grav[0] = %d\n",__FILE__,__LINE__, lattice->param.end_grav[0]); } else if( !strncmp(param_label,"tau[1]",80)) { if( NUM_FLUID_COMPONENTS==2) { fscanf( in, "%lf\n", &(lattice->param.tau[1])); printf("%s %d >> tau[1] = %f\n",__FILE__,__LINE__, lattice->param.tau[1]); } else { fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> tau[1] = %f // unused: NUM_FLUID_COMPONENTS==1\n",__FILE__,__LINE__, dblank); } } else if( !strncmp(param_label,"gval_x[1]",80)) { if( NUM_FLUID_COMPONENTS==2) { fscanf( in, "%lf\n", &(lattice->param.gval[1][0])); printf("%s %d >> gval_x[1] = %f\n",__FILE__,__LINE__, lattice->param.gval[1][0]); } else { fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> gval_y[0] = %f // unused: NUM_FLUID_COMPONENTS==1\n",__FILE__,__LINE__, dblank); } } else if( !strncmp(param_label,"gval_y[1]",80)) { if( NUM_FLUID_COMPONENTS==2) { fscanf( in, "%lf\n", &(lattice->param.gval[1][1])); printf("%s %d >> gval_y[1] = %f\n",__FILE__,__LINE__, lattice->param.gval[1][1]); } else { fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> gval_y[1] = %f // unused: NUM_FLUID_COMPONENTS==1\n",__FILE__,__LINE__, dblank); } } else if( !strncmp(param_label,"end_grav[1]",80)) { if( NUM_FLUID_COMPONENTS==2) { fscanf( in, "%d\n", &(lattice->param.end_grav[1])); printf("%s %d >> end_grav[1] = %d\n",__FILE__,__LINE__, lattice->param.end_grav[1]); } else { fscanf( in, "%d\n", &(blank)); printf("%s %d >> end_grav[1] = %d // unused: NUM_FLUID_COMPONENTS==1\n",__FILE__,__LINE__, blank); } } else if( !strncmp(param_label,"buoyancy",80)) { fscanf( in, "%d\n", &(lattice->param.buoyancy)); printf("%s %d >> buoyancy = %d\n",__FILE__,__LINE__, lattice->param.buoyancy); } else if( !strncmp(param_label,"buoy_subs",80)) { fscanf( in, "%d\n", &(lattice->param.buoy_subs)); printf("%s %d >> buoy_subs = %d\n",__FILE__,__LINE__, lattice->param.buoy_subs); } else if( !strncmp(param_label,"incompressible",80)) { fscanf( in, "%d\n", &(lattice->param.incompressible)); printf("%s %d >> incompressible = %d\n",__FILE__,__LINE__, lattice->param.incompressible); } else if( !strncmp(param_label,"simple_diffusion",80)) { fscanf( in, "%d\n", &(lattice->param.simple_diffusion)); printf("%s %d >> simple_diffusion = %d\n",__FILE__,__LINE__, lattice->param.simple_diffusion); } else if( !strncmp(param_label,"rho_A",80)) { fscanf( in, "%lf\n", &(lattice->param.rho_A[0])); printf("%s %d >> rho_A = %f\n",__FILE__,__LINE__, lattice->param.rho_A[0]); } else if( !strncmp(param_label,"rho_B",80)) { fscanf( in, "%lf\n", &(lattice->param.rho_B[0])); printf("%s %d >> rho_B = %f\n",__FILE__,__LINE__, lattice->param.rho_B[0]); } else if( !strncmp(param_label,"source_strength",80)) { #if SOURCE_ON fscanf( in, "%lf\n", &(lattice->param.source_strength)); printf("%s %d >> source_strength = %f\n",__FILE__,__LINE__, lattice->param.source_strength); #else /* !(SOURCE_ON) */ fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> source_strength = %f " "// unused: not SOURCE_ON\n", __FILE__,__LINE__, dblank); #endif /* (SOURCE_ON) */ } else if( !strncmp(param_label,"sink_strength",80)) { #if SINK_ON fscanf( in, "%lf\n", &(lattice->param.sink_strength)); printf("%s %d >> sink_strength = %f\n",__FILE__,__LINE__, lattice->param.sink_strength); #else /* !(SINK_ON) */ fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> sink_strength = %f " "// unused: not SINK_ON\n", __FILE__,__LINE__, dblank); #endif /* (SINK_ON) */ } else if( !strncmp(param_label,"rho_sigma",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%lf\n", &(lattice->param.rho_sigma)); printf("%s %d >> rho_sigma = %f\n",__FILE__,__LINE__, lattice->param.rho_sigma); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> rho_sigma = %f " "// unused: not INAMURO_SIGMA_COMPONENT\n", __FILE__,__LINE__, dblank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"beta",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%lf\n", &(lattice->param.beta)); printf("%s %d >> beta = %f\n",__FILE__,__LINE__, lattice->param.beta); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> beta = %f " "// unused: not INAMURO_SIGMA_COMPONENT\n", __FILE__,__LINE__, dblank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"C0",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%lf\n", &(lattice->param.C0)); printf("%s %d >> C0 = %f\n",__FILE__,__LINE__, lattice->param.C0); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> C0 = %f " "// unused: not INAMURO_SIGMA_COMPONENT\n", __FILE__,__LINE__, dblank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"rho0",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%lf\n", &(lattice->param.rho0)); printf("%s %d >> rho0 = %f\n",__FILE__,__LINE__, lattice->param.rho0); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> rho0 = %f " "// unused: not INAMURO_SIGMA_COMPONENT\n", __FILE__,__LINE__, dblank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"drhodC",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%lf\n", &(lattice->param.drhodC)); printf("%s %d >> drhodC = %f\n",__FILE__,__LINE__, lattice->param.drhodC); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> drhodC = %f " "// unused: not INAMURO_SIGMA_COMPONENT\n", __FILE__,__LINE__, dblank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"rho_sigma_in",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%lf\n", &(lattice->param.rho_sigma_in)); printf("%s %d >> rho_sigma_in = %f\n",__FILE__,__LINE__, lattice->param.rho_sigma_in); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> rho_sigma_in = %f " "// unused: not INAMURO_SIGMA_COMPONENT\n", __FILE__,__LINE__, dblank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"C_in",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%lf\n", &(lattice->param.C_in)); printf("%s %d >> C_in = %f\n",__FILE__,__LINE__, lattice->param.C_in); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> C_in = %f " "// unused: not INAMURO_SIGMA_COMPONENT\n", __FILE__,__LINE__, dblank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"rho_sigma_out",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%lf\n", &(lattice->param.rho_sigma_out)); printf("%s %d >> rho_sigma_out = %f\n",__FILE__,__LINE__, lattice->param.rho_sigma_out); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> rho_sigma_out = %f " "// unused: not INAMURO_SIGMA_COMPONENT\n", __FILE__,__LINE__, dblank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"C_out",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%lf\n", &(lattice->param.C_out)); printf("%s %d >> C_out = %f\n",__FILE__,__LINE__, lattice->param.C_out); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> C_out = %f " "// unused: not INAMURO_SIGMA_COMPONENT\n", __FILE__,__LINE__, dblank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"u_sigma",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%lf\n", &(lattice->param.u_sigma)); printf("%s %d >> u_sigma = %f\n",__FILE__,__LINE__, lattice->param.u_sigma); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> u_sigma = %f " "// unused: not INAMURO_SIGMA_COMPONENT\n", __FILE__,__LINE__, dblank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"u_sigma_in",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%lf\n", &(lattice->param.u_sigma_in)); printf("%s %d >> u_sigma_in = %f\n",__FILE__,__LINE__, lattice->param.u_sigma_in); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> u_sigma_in = %f " "// unused: not INAMURO_SIGMA_COMPONENT\n", __FILE__,__LINE__, dblank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"u_sigma_out",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%lf\n", &(lattice->param.u_sigma_out)); printf("%s %d >> u_sigma_out = %f\n",__FILE__,__LINE__, lattice->param.u_sigma_out); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> u_sigma_out = %f " "// unused: not INAMURO_SIGMA_COMPONENT\n", __FILE__,__LINE__, dblank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"sigma_bulk_on",80)) { #if SIGMA_BULK_FLAG fscanf( in, "%d\n", &(lattice->param.sigma_bulk_on)); printf("%s %d >> sigma_bulk_on = %d\n",__FILE__,__LINE__, lattice->param.sigma_bulk_on); #else /* !(SIGMA_BULK_FLAG) */ fscanf( in, "%d\n", &(blank)); printf("%s %d >> sigma_bulk_on = %d " "// unused: not SIGMA_BULK_FLAG\n", __FILE__,__LINE__, blank); #endif /* (SIGMA_BULK_FLAG) */ } else if( !strncmp(param_label,"sigma_start",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%d\n", &(lattice->param.sigma_start)); printf("%s %d >> sigma_start = %d\n",__FILE__,__LINE__, lattice->param.sigma_start); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%d\n", &(blank)); printf("%s %d >> sigma_start = %d " "// unused: not INAMURO_SIGMA_COMPONENT\n", __FILE__,__LINE__, blank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"sigma_stop",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%d\n", &(lattice->param.sigma_stop)); printf("%s %d >> sigma_stop = %d\n",__FILE__,__LINE__, lattice->param.sigma_stop); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%d\n", &(blank)); printf("%s %d >> sigma_stop = %d " "// unused: not INAMURO_SIGMA_COMPONENT\n", __FILE__,__LINE__, blank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"sigma_btc_rate",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%d\n", &(lattice->param.sigma_btc_rate)); printf("%s %d >> sigma_btc_rate = %d\n",__FILE__,__LINE__, lattice->param.sigma_btc_rate); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%d\n", &(blank)); printf("%s %d >> sigma_btc_rate = %d " "// unused: not INAMURO_SIGMA_COMPONENT\n", __FILE__,__LINE__, blank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"sigma_btc_spot",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%d\n", &(lattice->param.sigma_btc_spot)); printf("%s %d >> sigma_btc_spot = %d\n",__FILE__,__LINE__, lattice->param.sigma_btc_spot); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%d\n", &(blank)); printf("%s %d >> sigma_btc_spot = %d " "// unused: not INAMURO_SIGMA_COMPONENT\n", __FILE__,__LINE__, blank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"rho_in",80)) { fscanf( in, "%lf\n", &(lattice->param.rho_in)); printf("%s %d >> rho_in = %f\n",__FILE__,__LINE__, lattice->param.rho_in); } else if( !strncmp(param_label,"rho_out",80)) { fscanf( in, "%lf\n", &(lattice->param.rho_out)); printf("%s %d >> rho_out = %f\n",__FILE__,__LINE__, lattice->param.rho_out); } else if( !strncmp(param_label,"ux_in",80)) { fscanf( in, "%lf\n", &(lattice->param.ux_in)); printf("%s %d >> ux_in = %f\n",__FILE__,__LINE__, lattice->param.ux_in); } else if( !strncmp(param_label,"ux_out",80)) { fscanf( in, "%lf\n", &(lattice->param.ux_out)); printf("%s %d >> ux_out = %f\n",__FILE__,__LINE__, lattice->param.ux_out); } else if( !strncmp(param_label,"uy_in",80)) { fscanf( in, "%lf\n", &(lattice->param.uy_in)); printf("%s %d >> uy_in = %f\n",__FILE__,__LINE__, lattice->param.uy_in); } else if( !strncmp(param_label,"uy_out",80)) { fscanf( in, "%lf\n", &(lattice->param.uy_out)); printf("%s %d >> uy_out = %f\n",__FILE__,__LINE__, lattice->param.uy_out); } else if( !strncmp(param_label,"G",80)) { fscanf( in, "%lf\n", &(lattice->param.G)); printf("%s %d >> G = %f\n",__FILE__,__LINE__, lattice->param.G); } else if( !strncmp(param_label,"Gads[0]",80)) { fscanf( in, "%lf\n", &(lattice->param.Gads[0])); printf("%s %d >> Gads[0] = %f\n",__FILE__,__LINE__, lattice->param.Gads[0]); } else if( !strncmp(param_label,"Gads[1]",80)) { if( NUM_FLUID_COMPONENTS==2) { fscanf( in, "%lf\n", &(lattice->param.Gads[1])); printf("%s %d >> Gads[1] = %f\n",__FILE__,__LINE__, lattice->param.Gads[1]); } else { fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> Gads[1] = %f // unused: NUM_FLUID_COMPONENTS==1\n",__FILE__,__LINE__, dblank); } } else if( !strncmp(param_label,"ns_flag",80)) { fscanf( in, "%d\n", &(lattice->param.ns_flag)); printf("%s %d >> ns_flag = %d\n",__FILE__,__LINE__, lattice->param.ns_flag); } else if( !strncmp(param_label,"ns",80)) { fscanf( in, "%lf\n", &(lattice->param.ns)); printf("%s %d >> ns = %f\n",__FILE__,__LINE__, lattice->param.ns); } else if( !strncmp(param_label,"slice_x",80)) { fscanf( in, "%d\n", &(lattice->param.slice_x)); printf("%s %d >> slice_x = %d\n",__FILE__,__LINE__, lattice->param.slice_x); } else if( !strncmp(param_label,"slice_y",80)) { fscanf( in, "%d\n", &(lattice->param.slice_y)); printf("%s %d >> slice_y = %d\n",__FILE__,__LINE__, lattice->param.slice_y); } else if( !strncmp(param_label,"ic_poiseuille",80)) { fscanf( in, "%d\n", &(lattice->param.ic_poiseuille)); printf("%s %d >> ic_poiseuille = %d\n",__FILE__,__LINE__, lattice->param.ic_poiseuille); } // Including mispelling for backward compatibility. else if( !strncmp(param_label,"ic_poisseuille",80)) { fscanf( in, "%d\n", &(lattice->param.ic_poiseuille)); printf("%s %d >> ic_poiseuille = %d\n",__FILE__,__LINE__, lattice->param.ic_poiseuille); } else if( !strncmp(param_label,"bc_poiseuille",80)) { fscanf( in, "%d\n", &(lattice->param.bc_poiseuille)); printf("%s %d >> bc_poiseuille = %d\n",__FILE__,__LINE__, lattice->param.bc_poiseuille); } // Including mispelling for backward compatibility. else if( !strncmp(param_label,"bc_poisseuille",80)) { fscanf( in, "%d\n", &(lattice->param.bc_poiseuille)); printf("%s %d >> bc_poiseuille = %d\n",__FILE__,__LINE__, lattice->param.bc_poiseuille); } else if( !strncmp(param_label,"bc_slip_north",80)) { fscanf( in, "%d\n", &(lattice->param.bc_slip_north)); printf("%s %d >> bc_slip_north = %d\n",__FILE__,__LINE__, lattice->param.bc_slip_north); } else if( !strncmp(param_label,"bc_sigma_slip",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%d\n", &(lattice->param.bc_sigma_slip)); printf("%s %d >> bc_sigma_slip = %d\n",__FILE__,__LINE__, lattice->param.bc_sigma_slip); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%d\n", &(blank)); printf("%s %d >> bc_sigma_slip = %d " "// unused: not INAMURO_SIGMA_COMPONENT\n", __FILE__,__LINE__, blank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"bc_sigma_walls",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%d\n", &(lattice->param.bc_sigma_walls)); printf("%s %d >> bc_sigma_walls = %d\n",__FILE__,__LINE__, lattice->param.bc_sigma_walls); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%d\n", &(blank)); printf("%s %d >> bc_sigma_walls = %d " "// unused: not INAMURO_SIGMA_COMPONENT\n", __FILE__,__LINE__, blank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"Dl",80)) { #if TAU_ZHANG_ANISOTROPIC_DISPERSION fscanf( in, "%f\n", &(lattice->param.Dl)); printf("%s %d >> Dl = %f\n",__FILE__,__LINE__, lattice->param.Dl); #else fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> Dl = %f " "// unused: not INAMURO_SIGMA_COMPONENT\n", __FILE__,__LINE__, dblank); #endif } else if( !strncmp(param_label,"Dt",80)) { #if TAU_ZHANG_ANISOTROPIC_DISPERSION fscanf( in, "%f\n", &(lattice->param.Dt)); printf("%s %d >> Dt = %f\n",__FILE__,__LINE__, lattice->param.Dt); #else fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> Dt = %f " "// unused: not INAMURO_SIGMA_COMPONENT\n", __FILE__,__LINE__, dblank); #endif } else if( !strncmp(param_label,"pressure_n_in[0]",80)) { fscanf( in, "%d\n", &(lattice->param.pressure_n_in[0])); printf("%s %d >> pressure_n_in[0] = %d\n",__FILE__,__LINE__, lattice->param.pressure_n_in[0]); } else if( !strncmp(param_label,"pressure_s_in[0]",80)) { fscanf( in, "%d\n", &(lattice->param.pressure_s_in[0])); printf("%s %d >> pressure_s_in[0] = %d\n",__FILE__,__LINE__, lattice->param.pressure_s_in[0]); } else if( !strncmp(param_label,"pressure_n_out[0]",80)) { fscanf( in, "%d\n", &(lattice->param.pressure_n_out[0])); printf("%s %d >> pressure_n_out[0] = %d\n",__FILE__,__LINE__, lattice->param.pressure_n_out[0]); } else if( !strncmp(param_label,"pressure_s_out[0]",80)) { fscanf( in, "%d\n", &(lattice->param.pressure_s_out[0])); printf("%s %d >> pressure_s_out[0] = %d\n",__FILE__,__LINE__, lattice->param.pressure_s_out[0]); } else if( !strncmp(param_label,"velocity_n_in[0]",80)) { fscanf( in, "%d\n", &(lattice->param.velocity_n_in[0])); printf("%s %d >> velocity_n_in[0] = %d\n",__FILE__,__LINE__, lattice->param.velocity_n_in[0]); } else if( !strncmp(param_label,"velocity_s_in[0]",80)) { fscanf( in, "%d\n", &(lattice->param.velocity_s_in[0])); printf("%s %d >> velocity_s_in[0] = %d\n",__FILE__,__LINE__, lattice->param.velocity_s_in[0]); } else if( !strncmp(param_label,"velocity_n_out[0]",80)) { fscanf( in, "%d\n", &(lattice->param.velocity_n_out[0])); printf("%s %d >> velocity_n_out[0] = %d\n",__FILE__,__LINE__, lattice->param.velocity_n_out[0]); } else if( !strncmp(param_label,"velocity_s_out[0]",80)) { fscanf( in, "%d\n", &(lattice->param.velocity_s_out[0])); printf("%s %d >> velocity_s_out[0] = %d\n",__FILE__,__LINE__, lattice->param.velocity_s_out[0]); } else if( !strncmp(param_label,"pressure_e_in[0]",80)) { fscanf( in, "%d\n", &(lattice->param.pressure_e_in[0])); printf("%s %d >> pressure_e_in[0] = %d\n",__FILE__,__LINE__, lattice->param.pressure_e_in[0]); } else if( !strncmp(param_label,"pressure_w_in[0]",80)) { fscanf( in, "%d\n", &(lattice->param.pressure_w_in[0])); printf("%s %d >> pressure_w_in[0] = %d\n",__FILE__,__LINE__, lattice->param.pressure_w_in[0]); } else if( !strncmp(param_label,"pressure_e_out[0]",80)) { fscanf( in, "%d\n", &(lattice->param.pressure_e_out[0])); printf("%s %d >> pressure_e_out[0] = %d\n",__FILE__,__LINE__, lattice->param.pressure_e_out[0]); } else if( !strncmp(param_label,"pressure_w_out[0]",80)) { fscanf( in, "%d\n", &(lattice->param.pressure_w_out[0])); printf("%s %d >> pressure_w_out[0] = %d\n",__FILE__,__LINE__, lattice->param.pressure_w_out[0]); } else if( !strncmp(param_label,"velocity_e_in[0]",80)) { fscanf( in, "%d\n", &(lattice->param.velocity_e_in[0])); printf("%s %d >> velocity_e_in[0] = %d\n",__FILE__,__LINE__, lattice->param.velocity_e_in[0]); } else if( !strncmp(param_label,"velocity_w_in[0]",80)) { fscanf( in, "%d\n", &(lattice->param.velocity_w_in[0])); printf("%s %d >> velocity_w_in[0] = %d\n",__FILE__,__LINE__, lattice->param.velocity_w_in[0]); } else if( !strncmp(param_label,"velocity_e_out[0]",80)) { fscanf( in, "%d\n", &(lattice->param.velocity_e_out[0])); printf("%s %d >> velocity_e_out[0] = %d\n",__FILE__,__LINE__, lattice->param.velocity_e_out[0]); } else if( !strncmp(param_label,"velocity_w_out[0]",80)) { fscanf( in, "%d\n", &(lattice->param.velocity_w_out[0])); printf("%s %d >> velocity_w_out[0] = %d\n",__FILE__,__LINE__, lattice->param.velocity_w_out[0]); } else if( !strncmp(param_label,"pressure_n_in[1]",80)) { if( NUM_FLUID_COMPONENTS==2) { fscanf( in, "%d\n", &(lattice->param.pressure_n_in[1])); printf("%s %d >> pressure_n_in[1] = %d\n",__FILE__,__LINE__, lattice->param.pressure_n_in[1]); } else { fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> pressure_n_in[1] = %f // unused: NUM_FLUID_COMPONENTS==1\n",__FILE__,__LINE__, dblank); } } else if( !strncmp(param_label,"pressure_s_in[1]",80)) { if( NUM_FLUID_COMPONENTS==2) { fscanf( in, "%d\n", &(lattice->param.pressure_s_in[1])); printf("%s %d >> pressure_s_in[1] = %d\n",__FILE__,__LINE__, lattice->param.pressure_s_in[1]); } else { fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> pressure_s_in[1] = %f // unused: NUM_FLUID_COMPONENTS==1\n",__FILE__,__LINE__, dblank); } } else if( !strncmp(param_label,"pressure_n_out[1]",80)) { if( NUM_FLUID_COMPONENTS==2) { fscanf( in, "%d\n", &(lattice->param.pressure_n_out[1])); printf("%s %d >> pressure_n_out[1] = %d\n",__FILE__,__LINE__, lattice->param.pressure_n_out[1]); } else { fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> pressure_n_out[1] = %f // unused: NUM_FLUID_COMPONENTS==1\n",__FILE__,__LINE__, dblank); } } else if( !strncmp(param_label,"pressure_s_out[1]",80)) { if( NUM_FLUID_COMPONENTS==2) { fscanf( in, "%d\n", &(lattice->param.pressure_s_out[1])); printf("%s %d >> pressure_s_out[1] = %d\n",__FILE__,__LINE__, lattice->param.pressure_s_out[1]); } else { fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> pressure_s_out[1] = %f // unused: NUM_FLUID_COMPONENTS==1\n",__FILE__,__LINE__, dblank); } } else if( !strncmp(param_label,"velocity_n_in[1]",80)) { if( NUM_FLUID_COMPONENTS==2) { fscanf( in, "%d\n", &(lattice->param.velocity_n_in[1])); printf("%s %d >> velocity_n_in[1] = %d\n",__FILE__,__LINE__, lattice->param.velocity_n_in[1]); } else { fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> velocity_n_in[1] = %f // unused: NUM_FLUID_COMPONENTS==1\n",__FILE__,__LINE__, dblank); } } else if( !strncmp(param_label,"velocity_s_in[1]",80)) { if( NUM_FLUID_COMPONENTS==2) { fscanf( in, "%d\n", &(lattice->param.velocity_s_in[1])); printf("%s %d >> velocity_s_in[1] = %d\n",__FILE__,__LINE__, lattice->param.velocity_s_in[1]); } else { fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> velocity_s_in[1] = %f // unused: NUM_FLUID_COMPONENTS==1\n",__FILE__,__LINE__, dblank); } } else if( !strncmp(param_label,"velocity_n_out[1]",80)) { if( NUM_FLUID_COMPONENTS==2) { fscanf( in, "%d\n", &(lattice->param.velocity_n_out[1])); printf("%s %d >> velocity_n_out[1] = %d\n",__FILE__,__LINE__, lattice->param.velocity_n_out[1]); } else { fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> velocity_n_out[1] = %f // unused: NUM_FLUID_COMPONENTS==1\n",__FILE__,__LINE__, dblank); } } else if( !strncmp(param_label,"velocity_s_out[1]",80)) { if( NUM_FLUID_COMPONENTS==2) { fscanf( in, "%d\n", &(lattice->param.velocity_s_out[1])); printf("%s %d >> velocity_s_out[1] = %d\n",__FILE__,__LINE__, lattice->param.velocity_s_out[1]); } else { fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> velocity_s_out[1] = %f // unused: NUM_FLUID_COMPONENTS==1\n",__FILE__,__LINE__, dblank); } } else if( !strncmp(param_label,"pressure_e_in[1]",80)) { if( NUM_FLUID_COMPONENTS==2) { fscanf( in, "%d\n", &(lattice->param.pressure_e_in[1])); printf("%s %d >> pressure_e_in[1] = %d\n",__FILE__,__LINE__, lattice->param.pressure_e_in[1]); } else { fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> pressure_e_in[1] = %f // unused: NUM_FLUID_COMPONENTS==1\n",__FILE__,__LINE__, dblank); } } else if( !strncmp(param_label,"pressure_w_in[1]",80)) { if( NUM_FLUID_COMPONENTS==2) { fscanf( in, "%d\n", &(lattice->param.pressure_w_in[1])); printf("%s %d >> pressure_w_in[1] = %d\n",__FILE__,__LINE__, lattice->param.pressure_w_in[1]); } else { fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> pressure_w_in[1] = %f // unused: NUM_FLUID_COMPONENTS==1\n",__FILE__,__LINE__, dblank); } } else if( !strncmp(param_label,"pressure_e_out[1]",80)) { if( NUM_FLUID_COMPONENTS==2) { fscanf( in, "%d\n", &(lattice->param.pressure_e_out[1])); printf("%s %d >> pressure_e_out[1] = %d\n",__FILE__,__LINE__, lattice->param.pressure_e_out[1]); } else { fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> pressure_e_out[1] = %f // unused: NUM_FLUID_COMPONENTS==1\n",__FILE__,__LINE__, dblank); } } else if( !strncmp(param_label,"pressure_w_out[1]",80)) { if( NUM_FLUID_COMPONENTS==2) { fscanf( in, "%d\n", &(lattice->param.pressure_w_out[1])); printf("%s %d >> pressure_w_out[1] = %d\n",__FILE__,__LINE__, lattice->param.pressure_w_out[1]); } else { fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> pressure_w_out[1] = %f // unused: NUM_FLUID_COMPONENTS==1\n",__FILE__,__LINE__, dblank); } } else if( !strncmp(param_label,"velocity_e_in[1]",80)) { if( NUM_FLUID_COMPONENTS==2) { fscanf( in, "%d\n", &(lattice->param.velocity_e_in[1])); printf("%s %d >> velocity_e_in[1] = %d\n",__FILE__,__LINE__, lattice->param.velocity_e_in[1]); } else { fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> velocity_e_in[1] = %f // unused: NUM_FLUID_COMPONENTS==1\n",__FILE__,__LINE__, dblank); } } else if( !strncmp(param_label,"velocity_w_in[1]",80)) { if( NUM_FLUID_COMPONENTS==2) { fscanf( in, "%d\n", &(lattice->param.velocity_w_in[1])); printf("%s %d >> velocity_w_in[1] = %d\n",__FILE__,__LINE__, lattice->param.velocity_w_in[1]); } else { fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> velocity_w_in[1] = %f // unused: NUM_FLUID_COMPONENTS==1\n",__FILE__,__LINE__, dblank); } } else if( !strncmp(param_label,"velocity_e_out[1]",80)) { if( NUM_FLUID_COMPONENTS==2) { fscanf( in, "%d\n", &(lattice->param.velocity_e_out[1])); printf("%s %d >> velocity_e_out[1] = %d\n",__FILE__,__LINE__, lattice->param.velocity_e_out[1]); } else { fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> velocity_e_out[1] = %f // unused: NUM_FLUID_COMPONENTS==1\n",__FILE__,__LINE__, dblank); } } else if( !strncmp(param_label,"velocity_w_out[1]",80)) { if( NUM_FLUID_COMPONENTS==2) { fscanf( in, "%d\n", &(lattice->param.velocity_w_out[1])); printf("%s %d >> velocity_w_out[1] = %d\n",__FILE__,__LINE__, lattice->param.velocity_w_out[1]); } else { fscanf( in, "%lf\n", &(dblank)); printf("%s %d >> velocity_w_out[1] = %f // unused: NUM_FLUID_COMPONENTS==1\n",__FILE__,__LINE__, dblank); } } else if( !strncmp(param_label,"constcon_n_in",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%d\n", &(lattice->param.constcon_n_in)); printf("%s %d >> constcon_n_in = %d\n",__FILE__,__LINE__, lattice->param.constcon_n_in); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%d\n", &(blank)); printf("%s %d >> constcon_n_in = %d // unused: not INAMURO_SIGMA_COMPONENT\n",__FILE__,__LINE__, blank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"constcon_s_in",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%d\n", &(lattice->param.constcon_s_in)); printf("%s %d >> constcon_s_in = %d\n",__FILE__,__LINE__, lattice->param.constcon_s_in); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%d\n", &(blank)); printf("%s %d >> constcon_s_in = %d // unused: not INAMURO_SIGMA_COMPONENT\n",__FILE__,__LINE__, blank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"constcon_n_out",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%d\n", &(lattice->param.constcon_n_out)); printf("%s %d >> constcon_n_out = %d\n",__FILE__,__LINE__, lattice->param.constcon_n_out); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%d\n", &(blank)); printf("%s %d >> constcon_n_out = %d // unused: not INAMURO_SIGMA_COMPONENT\n",__FILE__,__LINE__, blank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"constcon_s_out",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%d\n", &(lattice->param.constcon_s_out)); printf("%s %d >> constcon_s_out = %d\n",__FILE__,__LINE__, lattice->param.constcon_s_out); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%d\n", &(blank)); printf("%s %d >> constcon_s_out = %d // unused: not INAMURO_SIGMA_COMPONENT\n",__FILE__,__LINE__, blank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"constflx_n_in",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%d\n", &(lattice->param.constflx_n_in)); printf("%s %d >> constflx_n_in = %d\n",__FILE__,__LINE__, lattice->param.constflx_n_in); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%d\n", &(blank)); printf("%s %d >> constflx_n_in = %d // unused: not INAMURO_SIGMA_COMPONENT\n",__FILE__,__LINE__, blank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"constflx_s_in",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%d\n", &(lattice->param.constflx_s_in)); printf("%s %d >> constflx_s_in = %d\n",__FILE__,__LINE__, lattice->param.constflx_s_in); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%d\n", &(blank)); printf("%s %d >> constflx_s_in = %d // unused: not INAMURO_SIGMA_COMPONENT\n",__FILE__,__LINE__, blank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"constflx_n_out",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%d\n", &(lattice->param.constflx_n_out)); printf("%s %d >> constflx_n_out = %d\n",__FILE__,__LINE__, lattice->param.constflx_n_out); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%d\n", &(blank)); printf("%s %d >> constflx_n_out = %d // unused: not INAMURO_SIGMA_COMPONENT\n",__FILE__,__LINE__, blank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"constflx_s_out",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%d\n", &(lattice->param.constflx_s_out)); printf("%s %d >> constflx_s_out = %d\n",__FILE__,__LINE__, lattice->param.constflx_s_out); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%d\n", &(blank)); printf("%s %d >> constflx_s_out = %d // unused: not INAMURO_SIGMA_COMPONENT\n",__FILE__,__LINE__, blank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"constcon_e_in",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%d\n", &(lattice->param.constcon_e_in)); printf("%s %d >> constcon_e_in = %d\n",__FILE__,__LINE__, lattice->param.constcon_e_in); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%d\n", &(blank)); printf("%s %d >> constcon_e_in = %d // unused: not INAMURO_SIGMA_COMPONENT\n",__FILE__,__LINE__, blank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"constcon_w_in",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%d\n", &(lattice->param.constcon_w_in)); printf("%s %d >> constcon_w_in = %d\n",__FILE__,__LINE__, lattice->param.constcon_w_in); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%d\n", &(blank)); printf("%s %d >> constcon_w_in = %d // unused: not INAMURO_SIGMA_COMPONENT\n",__FILE__,__LINE__, blank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"constcon_e_out",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%d\n", &(lattice->param.constcon_e_out)); printf("%s %d >> constcon_e_out = %d\n",__FILE__,__LINE__, lattice->param.constcon_e_out); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%d\n", &(blank)); printf("%s %d >> constcon_e_out = %d // unused: not INAMURO_SIGMA_COMPONENT\n",__FILE__,__LINE__, blank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"constcon_w_out",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%d\n", &(lattice->param.constcon_w_out)); printf("%s %d >> constcon_w_out = %d\n",__FILE__,__LINE__, lattice->param.constcon_w_out); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%d\n", &(blank)); printf("%s %d >> constcon_w_out = %d // unused: not INAMURO_SIGMA_COMPONENT\n",__FILE__,__LINE__, blank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"constflx_e_in",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%d\n", &(lattice->param.constflx_e_in)); printf("%s %d >> constflx_e_in = %d\n",__FILE__,__LINE__, lattice->param.constflx_e_in); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%d\n", &(blank)); printf("%s %d >> constflx_e_in = %d // unused: not INAMURO_SIGMA_COMPONENT\n",__FILE__,__LINE__, blank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"constflx_w_in",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%d\n", &(lattice->param.constflx_w_in)); printf("%s %d >> constflx_w_in = %d\n",__FILE__,__LINE__, lattice->param.constflx_w_in); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%d\n", &(blank)); printf("%s %d >> constflx_w_in = %d // unused: not INAMURO_SIGMA_COMPONENT\n",__FILE__,__LINE__, blank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"constflx_e_out",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%d\n", &(lattice->param.constflx_e_out)); printf("%s %d >> constflx_e_out = %d\n",__FILE__,__LINE__, lattice->param.constflx_e_out); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%d\n", &(blank)); printf("%s %d >> constflx_e_out = %d // unused: not INAMURO_SIGMA_COMPONENT\n",__FILE__,__LINE__, blank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"constflx_w_out",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%d\n", &(lattice->param.constflx_w_out)); printf("%s %d >> constflx_w_out = %d\n",__FILE__,__LINE__, lattice->param.constflx_w_out); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%d\n", &(blank)); printf("%s %d >> constflx_w_out = %d // unused: not INAMURO_SIGMA_COMPONENT\n",__FILE__,__LINE__, blank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"zeroconcgrad_n",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%d\n", &(lattice->param.zeroconcgrad_n)); printf("%s %d >> zeroconcgrad_n = %d\n",__FILE__,__LINE__, lattice->param.zeroconcgrad_n); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%d\n", &(blank)); printf("%s %d >> zeroconcgrad_n = %d // unused: not INAMURO_SIGMA_COMPONENT\n",__FILE__,__LINE__, blank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"zeroconcgrad_s",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%d\n", &(lattice->param.zeroconcgrad_s)); printf("%s %d >> zeroconcgrad_s = %d\n",__FILE__,__LINE__, lattice->param.zeroconcgrad_s); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%d\n", &(blank)); printf("%s %d >> zeroconcgrad_s = %d // unused: not INAMURO_SIGMA_COMPONENT\n",__FILE__,__LINE__, blank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"zeroconcgrad_e",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%d\n", &(lattice->param.zeroconcgrad_e)); printf("%s %d >> zeroconcgrad_e = %d\n",__FILE__,__LINE__, lattice->param.zeroconcgrad_e); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%d\n", &(blank)); printf("%s %d >> zeroconcgrad_e = %d // unused: not INAMURO_SIGMA_COMPONENT\n",__FILE__,__LINE__, blank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"zeroconcgrad_w",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%d\n", &(lattice->param.zeroconcgrad_w)); printf("%s %d >> zeroconcgrad_w = %d\n",__FILE__,__LINE__, lattice->param.zeroconcgrad_w); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%d\n", &(blank)); printf("%s %d >> zeroconcgrad_w = %d // unused: not INAMURO_SIGMA_COMPONENT\n",__FILE__,__LINE__, blank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"zeroconcgrad_full",80)) { #if INAMURO_SIGMA_COMPONENT fscanf( in, "%d\n", &(lattice->param.zeroconcgrad_full)); printf("%s %d >> zeroconcgrad_full = %d\n",__FILE__,__LINE__, lattice->param.zeroconcgrad_full); #else /* !(INAMURO_SIGMA_COMPONENT) */ fscanf( in, "%d\n", &(blank)); printf("%s %d >> zeroconcgrad_full = %d // unused: not INAMURO_SIGMA_COMPONENT\n",__FILE__,__LINE__, blank); #endif /* (INAMURO_SIGMA_COMPONENT) */ } else if( !strncmp(param_label,"plot_scale_dynamic",80)) { fscanf( in, "%d\n", &(lattice->param.plot_scale_dynamic)); printf("%s %d >> plot_scale_dynamic = %d\n",__FILE__,__LINE__, lattice->param.plot_scale_dynamic); } else if( !strncmp(param_label,"use_colormap",80)) { fscanf( in, "%d\n", &(lattice->param.use_colormap)); printf("%s %d >> use_colormap = %d\n",__FILE__,__LINE__, lattice->param.use_colormap); } else if( !strncmp(param_label,"initial_condition",80)) { fscanf( in, "%d\n", &(lattice->param.initial_condition)); printf("%s %d >> initial_condition = %d\n",__FILE__,__LINE__, lattice->param.initial_condition); } else if( !strncmp(param_label,"x0",80)) { fscanf( in, "%lf\n", &(lattice->param.x0)); printf("%s %d >> x0 = %f\n",__FILE__,__LINE__, lattice->param.x0); } else if( !strncmp(param_label,"y0",80)) { fscanf( in, "%lf\n", &(lattice->param.y0)); printf("%s %d >> y0 = %f\n",__FILE__,__LINE__, lattice->param.y0); } else if( !strncmp(param_label,"r0",80)) { fscanf( in, "%lf\n", &(lattice->param.r0)); printf("%s %d >> r0 = %f\n",__FILE__,__LINE__, lattice->param.r0); } else if( !strncmp(param_label,"cut",80)) { fscanf( in, "%lf\n", &(lattice->param.cut)); printf("%s %d >> cut = %f\n",__FILE__,__LINE__, lattice->param.cut); } else if( !strncmp(param_label,"x1",80)) { fscanf( in, "%lf\n", &(lattice->param.x1)); printf("%s %d >> x1 = %f\n",__FILE__,__LINE__, lattice->param.x1); } else if( !strncmp(param_label,"x2",80)) { fscanf( in, "%lf\n", &(lattice->param.x2)); printf("%s %d >> x2 = %f\n",__FILE__,__LINE__, lattice->param.x2); } else if( !strncmp(param_label,"y1",80)) { fscanf( in, "%lf\n", &(lattice->param.y1)); printf("%s %d >> y1 = %f\n",__FILE__,__LINE__, lattice->param.y1); } else if( !strncmp(param_label,"y2",80)) { fscanf( in, "%lf\n", &(lattice->param.y2)); printf("%s %d >> y2 = %f\n",__FILE__,__LINE__, lattice->param.y2); } else if( !strncmp(param_label,"rel_x1",80)) { fscanf( in, "%lf\n", &(lattice->param.rel_x1)); printf("%s %d >> rel_x1 = %f\n",__FILE__,__LINE__, lattice->param.rel_x1); } else if( !strncmp(param_label,"rel_x2",80)) { fscanf( in, "%lf\n", &(lattice->param.rel_x2)); printf("%s %d >> rel_x2 = %f\n",__FILE__,__LINE__, lattice->param.rel_x2); } else if( !strncmp(param_label,"rel_y1",80)) { fscanf( in, "%lf\n", &(lattice->param.rel_y1)); printf("%s %d >> rel_y1 = %f\n",__FILE__,__LINE__, lattice->param.rel_y1); } else if( !strncmp(param_label,"rel_y2",80)) { fscanf( in, "%lf\n", &(lattice->param.rel_y2)); printf("%s %d >> rel_y2 = %f\n",__FILE__,__LINE__, lattice->param.rel_y2); } else if( !strncmp(param_label,"dump_rho",80)) { fscanf( in, "%d\n", &(lattice->param.dump_rho)); printf("%s %d >> dump_rho = %d\n",__FILE__,__LINE__, lattice->param.dump_rho); } else if( !strncmp(param_label,"dump_u",80)) { fscanf( in, "%d\n", &(lattice->param.dump_u)); printf("%s %d >> dump_u = %d\n",__FILE__,__LINE__, lattice->param.dump_u); } else if( !strncmp(param_label,"dump_force",80)) { fscanf( in, "%d\n", &(lattice->param.dump_force)); printf("%s %d >> dump_force = %d\n",__FILE__,__LINE__, lattice->param.dump_force); } else if( !strncmp(param_label,"dump_vor",80)) { fscanf( in, "%d\n", &(lattice->param.dump_vor)); printf("%s %d >> dump_vor = %d\n",__FILE__,__LINE__, lattice->param.dump_vor); } else if( !strncmp(param_label,"do_user_stuff",80)) { fscanf( in, "%d\n", &(lattice->param.do_user_stuff)); printf("%s %d >> do_user_stuff = %d\n",__FILE__,__LINE__, lattice->param.do_user_stuff); } else if( !strncmp(param_label,"out_path",80)) { //fscanf( in, "%s\n", &(lattice->param.out_path)); char *str; str = (char*)malloc( 1024*sizeof(char)); get_rest_of_line_as_string( in, &str, 1024); strncpy( lattice->param.out_path, str, 1024); free(str); printf("%s %d >> out_path = %s\n",__FILE__,__LINE__, lattice->param.out_path); } else if( !strncmp(param_label,"make_octave_scripts",80)) { fscanf( in, "%d\n", &(lattice->param.make_octave_scripts)); printf("%s %d >> make_octave_scripts = %d\n",__FILE__,__LINE__, lattice->param.make_octave_scripts); } else { printf("%s %d >> WARNING: Unhandled parameter \"%s\".\n", __FILE__,__LINE__,param_label); skip_rest_of_line( in); } } #else /* !(NEW_PARAMS_INPUT_ROUTINE) */ skip_label( in); fscanf( in, "%d", &( lattice->param.LX) ); skip_label( in); fscanf( in, "%d", &( lattice->param.LY) ); skip_label( in); fscanf( in, "%d", &( lattice->param.length_scale )); skip_label( in); fscanf( in, "%d", &( lattice->param.NumFrames) ); skip_label( in); fscanf( in, "%d", &( lattice->param.FrameRate) ); skip_label( in); fscanf( in, "%lf",&( lattice->param.tau[0]) ); skip_label( in); fscanf( in, "%lf", lattice->param.gval[0] ); skip_label( in); fscanf( in, "%lf", lattice->param.gval[0]+1 ); skip_label( in); fscanf( in, "%d", lattice->param.end_grav ); if( NUM_FLUID_COMPONENTS==2) { skip_label( in); fscanf( in, "%lf",&( lattice->param.tau[1]) ); skip_label( in); fscanf( in, "%lf", lattice->param.gval[1] ); skip_label( in); fscanf( in, "%lf", lattice->param.gval[1]+1 ); skip_label( in); fscanf( in, "%d", lattice->param.end_grav+1 ); } else if( NUM_FLUID_COMPONENTS==1) { skip_label( in); fscanf( in, "%lf", &dblank ); skip_label( in); fscanf( in, "%lf", &dblank ); skip_label( in); fscanf( in, "%lf", &dblank ); skip_label( in); fscanf( in, "%d", &blank ); } else { printf( "read_params() -- " "Unhandled case " "NUM_FLUID_COMPONENTS = %d . " "Exiting!\n", NUM_FLUID_COMPONENTS); process_exit(1); } skip_label( in); fscanf( in, "%d ", &(lattice->param.buoyancy ) ); skip_label( in); fscanf( in, "%d ", &(lattice->param.buoy_subs ) ); skip_label( in); fscanf( in, "%d ", &(lattice->param.incompressible) ); skip_label( in); fscanf( in, "%d ", &(lattice->param.simple_diffusion) ); skip_label( in); fscanf( in, "%lf", lattice->param.rho_A ); skip_label( in); fscanf( in, "%lf", lattice->param.rho_B ); #if SOURCE_ON skip_label( in); fscanf( in, "%lf", lattice->param.source_strength ); #endif /*SOURCE_ON*/ #if SINK_ON skip_label( in); fscanf( in, "%lf", lattice->param.sink_strength ); #endif /*SINK_ON*/ #if INAMURO_SIGMA_COMPONENT skip_label( in); fscanf( in, "%lf",&( lattice->param.rho_sigma) ); skip_label( in); fscanf( in, "%lf",&( lattice->param.beta ) ); skip_label( in); fscanf( in, "%lf",&( lattice->param.C0) ); skip_label( in); fscanf( in, "%lf",&( lattice->param.rho0) ); skip_label( in); fscanf( in, "%lf",&( lattice->param.drhodC) ); skip_label( in); fscanf( in, "%lf",&( lattice->param.rho_sigma_in) ); skip_label( in); fscanf( in, "%lf",&( lattice->param.C_in) ); skip_label( in); fscanf( in, "%lf",&( lattice->param.rho_sigma_out) ); skip_label( in); fscanf( in, "%lf",&( lattice->param.C_out) ); skip_label( in); fscanf( in, "%lf",&( lattice->param.u_sigma) ); skip_label( in); fscanf( in, "%lf",&( lattice->param.u_sigma_in) ); skip_label( in); fscanf( in, "%lf",&( lattice->param.u_sigma_out) ); #if SIGMA_BULK_FLAG skip_label( in); fscanf( in, "%d ",&( lattice->param.sigma_bulk_on) ); #else/*!(SIGMA_BULK_FLAG)*/ skip_label( in); fscanf( in, "%d ", &blank ); #endif /*SIGMA_BULK_FLAG*/ skip_label( in); fscanf( in, "%d ",&( lattice->param.sigma_start) ); skip_label( in); fscanf( in, "%d ",&( lattice->param.sigma_stop ) ); skip_label( in); fscanf( in, "%d ",&( lattice->param.sigma_btc_rate )); skip_label( in); fscanf( in, "%d ",&( lattice->param.sigma_btc_spot )); #else /* !( INAMURO_SIGMA_COMPONENT) */ skip_label( in); fscanf( in, "%lf", &dblank ); skip_label( in); fscanf( in, "%lf", &dblank ); skip_label( in); fscanf( in, "%lf", &dblank ); skip_label( in); fscanf( in, "%lf", &dblank ); skip_label( in); fscanf( in, "%lf", &dblank ); skip_label( in); fscanf( in, "%lf", &dblank ); skip_label( in); fscanf( in, "%d ", &blank ); skip_label( in); fscanf( in, "%d ", &blank ); skip_label( in); fscanf( in, "%d ", &blank ); skip_label( in); fscanf( in, "%d ", &blank ); skip_label( in); fscanf( in, "%d ", &blank ); #endif /* INAMURO_SIGMA_COMPONENT */ skip_label( in); fscanf( in, "%lf",&( lattice->param.rho_in) ); skip_label( in); fscanf( in, "%lf",&( lattice->param.rho_out) ); skip_label( in); fscanf( in, "%lf",&( lattice->param.ux_in) ); skip_label( in); fscanf( in, "%lf",&( lattice->param.ux_out) ); //printf(" %s %d >> %f\n",__FILE__,__LINE__, // lattice->param.ux_out); skip_label( in); fscanf( in, "%lf",&( lattice->param.uy_in) ); skip_label( in); fscanf( in, "%lf",&( lattice->param.uy_out) ); skip_label( in); fscanf( in, "%lf",&( lattice->param.G) ); skip_label( in); fscanf( in, "%lf", lattice->param.Gads+0 ); if( NUM_FLUID_COMPONENTS==2) { skip_label( in); fscanf( in, "%lf", lattice->param.Gads+1 ); } else if( NUM_FLUID_COMPONENTS==1) { skip_label( in); fscanf( in, "%lf", &dblank ); } else { printf( "read_params() -- " "Unhandled case " "NUM_FLUID_COMPONENTS = %d . " "Exiting!\n", NUM_FLUID_COMPONENTS); process_exit(1); } skip_label( in); fscanf( in, "%d", &( lattice->param.ns_flag) ); skip_label( in); fscanf( in, "%lf",&( lattice->param.ns) ); skip_label( in); fscanf( in, "%d", &( lattice->param.slice_x ) ); skip_label( in); fscanf( in, "%d", &( lattice->param.slice_y ) ); skip_label( in); fscanf( in, "%d", &( lattice->param.ic_poiseuille) ); skip_label( in); fscanf( in, "%d", &( lattice->param.bc_poiseuille) ); skip_label( in); fscanf( in, "%d", &( lattice->param.bc_slip_north ) ); #if INAMURO_SIGMA_COMPONENT skip_label( in); fscanf( in, "%d", &( lattice->param.bc_sigma_slip ) ); skip_label( in); fscanf( in, "%d", &( lattice->param.bc_sigma_walls) ); #if TAU_ZHANG_ANISOTROPIC_DISPERSION skip_label( in); fscanf( in, "%lf",&( lattice->param.Dl ) ); skip_label( in); fscanf( in, "%lf",&( lattice->param.Dt ) ); #endif #else /* !( INAMURO_SIGMA_COMPONENT) */ skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); #if TAU_ZHANG_ANISOTROPIC_DISPERSION skip_label( in); fscanf( in, "%lf", &dblank ); skip_label( in); fscanf( in, "%lf", &dblank ); #endif #endif /* INAMURO_SIGMA_COMPONENT */ skip_label( in); fscanf( in, "%d", lattice->param.pressure_n_in+0 ); skip_label( in); fscanf( in, "%d", lattice->param.pressure_s_in+0 ); skip_label( in); fscanf( in, "%d", lattice->param.pressure_n_out+0); skip_label( in); fscanf( in, "%d", lattice->param.pressure_s_out+0); skip_label( in); fscanf( in, "%d", lattice->param.velocity_n_in+0 ); skip_label( in); fscanf( in, "%d", lattice->param.velocity_s_in+0 ); skip_label( in); fscanf( in, "%d", lattice->param.velocity_n_out+0); skip_label( in); fscanf( in, "%d", lattice->param.velocity_s_out+0); skip_label( in); fscanf( in, "%d", lattice->param.pressure_e_in+0 ); skip_label( in); fscanf( in, "%d", lattice->param.pressure_w_in+0 ); skip_label( in); fscanf( in, "%d", lattice->param.pressure_e_out+0); skip_label( in); fscanf( in, "%d", lattice->param.pressure_w_out+0); skip_label( in); fscanf( in, "%d", lattice->param.velocity_e_in+0 ); skip_label( in); fscanf( in, "%d", lattice->param.velocity_w_in+0 ); skip_label( in); fscanf( in, "%d", lattice->param.velocity_e_out+0); skip_label( in); fscanf( in, "%d", lattice->param.velocity_w_out+0); if( NUM_FLUID_COMPONENTS==2) { skip_label( in); fscanf( in, "%d", lattice->param.pressure_n_in+1 ); skip_label( in); fscanf( in, "%d", lattice->param.pressure_s_in+1 ); skip_label( in); fscanf( in, "%d", lattice->param.pressure_n_out+1); skip_label( in); fscanf( in, "%d", lattice->param.pressure_s_out+1); skip_label( in); fscanf( in, "%d", lattice->param.velocity_n_in+1 ); skip_label( in); fscanf( in, "%d", lattice->param.velocity_s_in+1 ); skip_label( in); fscanf( in, "%d", lattice->param.velocity_n_out+1); skip_label( in); fscanf( in, "%d", lattice->param.velocity_s_out+1); skip_label( in); fscanf( in, "%d", lattice->param.pressure_e_in+1 ); skip_label( in); fscanf( in, "%d", lattice->param.pressure_w_in+1 ); skip_label( in); fscanf( in, "%d", lattice->param.pressure_e_out+1); skip_label( in); fscanf( in, "%d", lattice->param.pressure_w_out+1); skip_label( in); fscanf( in, "%d", lattice->param.velocity_e_in+1 ); skip_label( in); fscanf( in, "%d", lattice->param.velocity_w_in+1 ); skip_label( in); fscanf( in, "%d", lattice->param.velocity_e_out+1); skip_label( in); fscanf( in, "%d", lattice->param.velocity_w_out+1); } else if( NUM_FLUID_COMPONENTS==1) { skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); } else { printf( "read_params() -- " "Unhandled case " "NUM_FLUID_COMPONENTS = %d . " "Exiting!\n", NUM_FLUID_COMPONENTS); process_exit(1); } if( INAMURO_SIGMA_COMPONENT) { skip_label( in); fscanf( in, "%d", &lattice->param.constcon_n_in ); skip_label( in); fscanf( in, "%d", &lattice->param.constcon_s_in ); skip_label( in); fscanf( in, "%d", &lattice->param.constcon_n_out ); skip_label( in); fscanf( in, "%d", &lattice->param.constcon_s_out ); skip_label( in); fscanf( in, "%d", &lattice->param.constflx_n_in ); skip_label( in); fscanf( in, "%d", &lattice->param.constflx_s_in ); skip_label( in); fscanf( in, "%d", &lattice->param.constflx_n_out ); skip_label( in); fscanf( in, "%d", &lattice->param.constflx_s_out ); skip_label( in); fscanf( in, "%d", &lattice->param.constcon_e_in ); skip_label( in); fscanf( in, "%d", &lattice->param.constcon_w_in ); skip_label( in); fscanf( in, "%d", &lattice->param.constcon_e_out ); skip_label( in); fscanf( in, "%d", &lattice->param.constcon_w_out ); skip_label( in); fscanf( in, "%d", &lattice->param.constflx_e_in ); skip_label( in); fscanf( in, "%d", &lattice->param.constflx_w_in ); skip_label( in); fscanf( in, "%d", &lattice->param.constflx_e_out ); skip_label( in); fscanf( in, "%d", &lattice->param.constflx_w_out ); skip_label( in); fscanf( in, "%d", &lattice->param.zeroconcgrad_n ); skip_label( in); fscanf( in, "%d", &lattice->param.zeroconcgrad_s ); skip_label( in); fscanf( in, "%d", &lattice->param.zeroconcgrad_e ); skip_label( in); fscanf( in, "%d", &lattice->param.zeroconcgrad_w ); skip_label( in); fscanf( in, "%d", &lattice->param.zeroconcgrad_full ); } else { skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); skip_label( in); fscanf( in, "%d", &blank ); } skip_label( in); fscanf( in, "%d", &( lattice->param.plot_scale_dynamic) ); skip_label( in); fscanf( in, "%d", &( lattice->param.use_colormap ) ); skip_label( in); fscanf( in, "%d", &( lattice->param.initial_condition ) ); skip_label( in); fscanf( in, "%lf",&( lattice->param.x0 ) ); skip_label( in); fscanf( in, "%lf",&( lattice->param.y0 ) ); skip_label( in); fscanf( in, "%lf",&( lattice->param.r0 ) ); skip_label( in); fscanf( in, "%lf",&( lattice->param.cut ) ); skip_label( in); fscanf( in, "%lf",&( lattice->param.x1 ) ); skip_label( in); fscanf( in, "%lf",&( lattice->param.x2 ) ); skip_label( in); fscanf( in, "%lf",&( lattice->param.y1 ) ); skip_label( in); fscanf( in, "%lf",&( lattice->param.y2 ) ); skip_label( in); fscanf( in, "%lf",&( lattice->param.rel_x1 ) ); skip_label( in); fscanf( in, "%lf",&( lattice->param.rel_x2 ) ); skip_label( in); fscanf( in, "%lf",&( lattice->param.rel_y1 ) ); skip_label( in); fscanf( in, "%lf",&( lattice->param.rel_y2 ) ); skip_label( in); fscanf( in, "%d", &( lattice->param.dump_rho ) ); skip_label( in); fscanf( in, "%d", &( lattice->param.dump_u ) ); skip_label( in); fscanf( in, "%d", &( lattice->param.dump_force ) ); skip_label( in); fscanf( in, "%d", &( lattice->param.dump_vor ) ); skip_label( in); fscanf( in, "%d", &( lattice->param.do_user_stuff ) ); skip_label( in); fscanf( in, "%s", &( lattice->param.out_path ) ); skip_label( in); fscanf( in, "%s", &( lattice->param.make_octave_scripts) ); #endif /* (NEW_PARAMS_INPUT_ROUTINE) */ //LBMPI #if PARALLEL //LBMPI // Determine local domain size. //LBMPI compute_LX( lattice, lattice->lbmpi); //LBMPI compute_LY( lattice, lattice->lbmpi); //LBMPI printf("%s %d >> (GLX,GLY)=(%d,%d)\n", //LBMPI __FILE__,__LINE__, //LBMPI get_GLX(lattice->lbmpi), //LBMPI get_GLY(lattice->lbmpi)); //LBMPI printf("%s %d >> (LX,LY)=(%d,%d)\n", //LBMPI __FILE__,__LINE__, //LBMPI get_LX(lattice), //LBMPI get_LY(lattice)); //LBMPI //LBMPI // Determine global coordinates of local domain. //LBMPI compute_global_coords( lattice); //LBMPI //LBMPI #endif /* (PARALLEL) */ lattice->NumTimeSteps = lattice->param.NumFrames * lattice->param.FrameRate; #if 0 for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { lattice->param.gval[subs][0] *= lattice->param.tau[subs]; lattice->param.gval[subs][1] *= lattice->param.tau[subs]; } #endif if( NUM_FLUID_COMPONENTS==2) { lattice->param.rho_A[1] = lattice->param.rho_B[0]; lattice->param.rho_B[1] = lattice->param.rho_A[0]; } if( lattice->param.incompressible) { if( INAMURO_SIGMA_COMPONENT==0 && NUM_FLUID_COMPONENTS > 1) { printf("\n"); printf("\n"); printf("%s (%d) -- ERROR: " "Support for incompressible flow with " "two fluid components (as opposed to Inamuro solute component) " "is pending. (Exiting!)\n", __FILE__, __LINE__); printf("\n"); printf("\n"); process_exit(1); } } if( lattice->param.simple_diffusion && NUM_FLUID_COMPONENTS > 1) { if( INAMURO_SIGMA_COMPONENT==0) { printf("\n"); printf("\n"); printf("%s (%d) -- ERROR: " "Support for simplified diffusion with " "two fluid components (as opposed to Inamuro solute component) " "is pending. (Exiting!)\n", __FILE__, __LINE__); printf("\n"); printf("\n"); process_exit(1); } } // Set default values for x0, y0 and r0 if they are negative. if( lattice->param.x0 < 0.) { lattice->param.x0 = lattice->param.LX/2.; } if( lattice->param.y0 < 0.) { lattice->param.y0 = lattice->param.LY/2.; } if( lattice->param.r0 < 0.) { lattice->param.r0 = (lattice->param.LX+lattice->param.LY)/8.; } // Set default value for cut if it is negative. if( lattice->param.cut < 0.) { lattice->param.cut = .4; } // Set default values for x1, x2, y1, y2 if they are negative. if( lattice->param.x1 < 0.) { if( lattice->param.rel_x1 < 0.) { lattice->param.x1 = lattice->param.LX/4.-1; } else { lattice->param.x1 = lattice->param.rel_x1*lattice->param.LX-1; } } if( lattice->param.x2 < 0.) { if( lattice->param.rel_x2 < 0.) { lattice->param.x2 = lattice->param.LX/2.-1; } else { lattice->param.x2 = lattice->param.rel_x2*lattice->param.LX-1; } } if( lattice->param.y1 < 0.) { if( lattice->param.rel_y1 < 0.) { lattice->param.y1 = lattice->param.LY/4.-1; } else { lattice->param.y1 = lattice->param.rel_y1*lattice->param.LY-1; } } if( lattice->param.y2 < 0.) { if( lattice->param.rel_y2 < 0.) { lattice->param.y2 = lattice->param.LY/2.-1; } else { lattice->param.y2 = lattice->param.rel_y2*lattice->param.LY-1; } } #if INAMURO_SIGMA_COMPONENT if( lattice->param.beta != 0.) { if( lattice->param.rho0 != 0. || lattice->param.drhodC != 0.) { printf("ERROR: beta nonzero and rho0,drhodC nonzero. " "Choose on or the other."); process_exit(1); } } else { if( lattice->param.rho0 != 0. && lattice->param.drhodC != 0.) { lattice->param.beta = (1./lattice->param.rho0)*(lattice->param.drhodC); } } if( lattice->param.rho_sigma_in != 0.) { if( lattice->param.C_in != 0.) { if( lattice->param.rho_sigma_in != lattice->param.C_in) { printf("%s %d >> ERROR: 0.!=rho_sigma_in!=C_in. Exiting.",__FILE__,__LINE__); process_exit(1); } } else { lattice->param.C_in = lattice->param.rho_sigma_in; } } if( lattice->param.rho_sigma_out != 0.) { if( lattice->param.C_out != 0.) { if( lattice->param.rho_sigma_out != lattice->param.C_out) { printf("%s %d >> ERROR: 0.!=rho_sigma_out!=C_out. Exiting.",__FILE__,__LINE__); process_exit(1); } } else { lattice->param.C_out = lattice->param.rho_sigma_out; } } #endif fclose(in); #if VERBOSITY_LEVEL >= 1 printf("lbio.c: read_params() -- Read file \"params.in\".\n"); #endif /* VERBOSITY_LEVEL >= 1 */ } /* void read_params( struct lattice_struct *lattice) */ // void dump_params( struct lattice_struct *lattice) //############################################################################## // // D U M P P A R A M S // // - Output the problem parameters to a file. // void dump_params( struct lattice_struct *lattice) { FILE *o; char filename[1024]; sprintf( filename , "%s/params%dx%d_proc%04d.dat" , get_out_path(lattice) , get_LX(lattice), get_LY(lattice), get_proc_id(lattice) ); if( !( o = fopen(filename,"w+"))) { printf("\n%s %d >> ERROR: fopen(\"%s\",\"w+\") = NULL.\n", __FILE__, __LINE__, filename); printf("\n%s %d >> NOTE: You might need to create directory \"%s\"\n", __FILE__, __LINE__, get_out_path(lattice)); printf("%s %d >> " "If the directory just shown is not \"./out\" and does not\n" "look familiar as a custom directory you requested, edit\n" "\"./in/params.in\" and either change the \"out_path\" parameter or\n" "delete it. (Deleting the \"out_path\" entry in \"params.in\" will\n" "cause the code to revert to the default \"./out\" folder.)", __FILE__, __LINE__); process_exit(1); } fprintf( o, "LX %d\n", lattice->param.LX ); fprintf( o, "LY %d\n", lattice->param.LY ); fprintf( o, "length_scale %d\n", lattice->param.length_scale ); fprintf( o, "NumNodes %d\n", lattice->NumNodes ); fprintf( o, "NumFrames %d\n", lattice->param.NumFrames ); fprintf( o, "FrameRate %d\n", lattice->param.FrameRate ); fprintf( o, "NumTimeSteps %d\n", lattice->NumTimeSteps ); fprintf( o, "tau[0] %f\n", lattice->param.tau[0] ); fprintf( o, "gval[0][0] %f\n", lattice->param.gval[0][0] ); fprintf( o, "gval[0][1] %f\n", lattice->param.gval[0][1] ); fprintf( o, "end_grav[0] %d\n", lattice->param.end_grav[0] ); if( NUM_FLUID_COMPONENTS==2) { fprintf( o, "tau[1] %f\n", lattice->param.tau[1] ); fprintf( o, "gval[1][0] %f\n", lattice->param.gval[1][0] ); fprintf( o, "gval[1][1] %f\n", lattice->param.gval[1][1] ); fprintf( o, "end_grav[1] %d\n", lattice->param.end_grav[1] ); } else if( NUM_FLUID_COMPONENTS==1) { fprintf( o, "tau[1] %s\n", "--" ); fprintf( o, "gval[1][0] %s\n", "--" ); fprintf( o, "gval[1][1] %s\n", "--" ); fprintf( o, "end_grav[1] %s\n", "--" ); } else { printf( "read_params() -- " "Unhandled case " "NUM_FLUID_COMPONENTS = %d . " "Exiting!\n", NUM_FLUID_COMPONENTS); process_exit(1); } fprintf( o, "buoyancy %d\n", lattice->param.buoyancy ); fprintf( o, "buoy_subs %d\n", lattice->param.buoy_subs ); fprintf( o, "incompressible %d\n", lattice->param.incompressible ); fprintf( o, "simple_diffusion %d\n", lattice->param.simple_diffusion); fprintf( o, "rho_A[0] %f\n", lattice->param.rho_A[0] ); fprintf( o, "rho_B[0] %f\n", lattice->param.rho_B[0] ); if( NUM_FLUID_COMPONENTS==2) { fprintf( o, "rho_A[1] %f\n", lattice->param.rho_A[1] ); fprintf( o, "rho_B[1] %f\n", lattice->param.rho_B[1] ); } else if( NUM_FLUID_COMPONENTS==1) { fprintf( o, "rho_A[1] %s\n", "--" ); fprintf( o, "rho_B[1] %s\n", "--" ); } else { printf( "read_params() -- " "Unhandled case " "NUM_FLUID_COMPONENTS = %d . " "Exiting!\n", NUM_FLUID_COMPONENTS); process_exit(1); } #if SOURCE_ON fprintf( o, "source_strength %f\n", lattice->param.source_strength ); #else /*if !(SOURCE_ON)*/ fprintf( o, "source_strength %s\n", "--" ); #endif /*SOURCE_ON*/ #if SINK_ON fprintf( o, "sink_strength %f\n", lattice->param.sink_strength ); #else /*if !(SINK_ON)*/ fprintf( o, "sink_strength %s\n", "--" ); #endif /*SINK_ON*/ #if INAMURO_SIGMA_COMPONENT fprintf( o, "rho_sigma %f\n", lattice->param.rho_sigma ); fprintf( o, "beta %f\n", lattice->param.beta ); fprintf( o, "C0 %f\n", lattice->param.C0 ); fprintf( o, "rho0 %f\n", lattice->param.rho0 ); fprintf( o, "drhodC %f\n", lattice->param.drhodC ); fprintf( o, "rho_sigma_in %f\n", lattice->param.rho_sigma_in ); fprintf( o, "C_in %f\n", lattice->param.C_in ); fprintf( o, "rho_sigma_out %f\n", lattice->param.rho_sigma_out ); fprintf( o, "C_out %f\n", lattice->param.C_out ); fprintf( o, "u_sigma %f\n", lattice->param.u_sigma ); fprintf( o, "u_sigma_in %f\n", lattice->param.u_sigma_in ); fprintf( o, "u_sigma_out %f\n", lattice->param.u_sigma_out ); #if SIGMA_BULK_FLAG fprintf( o, "sigma_bulk_on %d\n", lattice->param.sigma_bulk_on); #else /*!(SIGMA_BULK_FLAG)*/ fprintf( o, "sigma_bulk_on %s\n", "--" ); #endif /*SIGMA_BULK_FLAG*/ fprintf( o, "sigma_start %d\n", lattice->param.sigma_start ); fprintf( o, "sigma_stop %d\n", lattice->param.sigma_stop ); fprintf( o, "sigma_btc_rate %d\n", lattice->param.sigma_btc_rate ); fprintf( o, "sigma_btc_spot %d\n", lattice->param.sigma_btc_spot ); #else /* !( INAMURO_SIGMA_COMPONENT) */ fprintf( o, "rho_sigma %s\n", "--" ); fprintf( o, "beta %s\n", "--" ); fprintf( o, "C0 %s\n", "--" ); fprintf( o, "rho0 %s\n", "--" ); fprintf( o, "drhodC %s\n", "--" ); fprintf( o, "rho_sigma_in %s\n", "--" ); fprintf( o, "C_in %s\n", "--" ); fprintf( o, "rho_sigma_out %s\n", "--" ); fprintf( o, "C_out %s\n", "--" ); fprintf( o, "u_sigma %s\n", "--" ); fprintf( o, "u_sigma_in %s\n", "--" ); fprintf( o, "u_sigma_out %s\n", "--" ); fprintf( o, "sigma_bulk_on %s\n", "--" ); fprintf( o, "sigma_start %s\n", "--" ); fprintf( o, "sigma_stop %s\n", "--" ); fprintf( o, "sigma_btc_rate %s\n", "--" ); fprintf( o, "sigma_btc_spot %s\n", "--" ); #endif /* INAMURO_SIGMA_COMPONENT */ fprintf( o, "rho_in %f\n", lattice->param.rho_in ); fprintf( o, "rho_out %f\n", lattice->param.rho_out ); fprintf( o, "ux_in %f\n", lattice->param.ux_in ); fprintf( o, "ux_out %f\n", lattice->param.ux_out ); fprintf( o, "uy_in %f\n", lattice->param.uy_in ); fprintf( o, "uy_out %f\n", lattice->param.uy_out ); fprintf( o, "G %f\n", lattice->param.G ); fprintf( o, "Gads[0] %f\n", lattice->param.Gads[0]); if( NUM_FLUID_COMPONENTS==2) { fprintf( o, "Gads[1] %f\n", lattice->param.Gads[1]); } else if( NUM_FLUID_COMPONENTS==1) { fprintf( o, "Gads[1] %s\n", "--" ); } else { printf( "read_params() -- " "Unhandled case " "NUM_FLUID_COMPONENTS = %d . " "Exiting!\n", NUM_FLUID_COMPONENTS); process_exit(1); } fprintf( o, "periodic_x[0] %d\n", lattice->periodic_x[0] ); fprintf( o, "periodic_y[0] %d\n", lattice->periodic_y[0] ); if( NUM_FLUID_COMPONENTS==2) { fprintf( o, "periodic_x[1] %d\n", lattice->periodic_x[1] ); fprintf( o, "periodic_y[1] %d\n", lattice->periodic_y[1] ); } else if( NUM_FLUID_COMPONENTS==1) { fprintf( o, "periodic_x[1] %s\n", "--" ); fprintf( o, "periodic_y[1] %s\n", "--" ); } else { printf( "read_params() -- " "Unhandled case " "NUM_FLUID_COMPONENTS = %d . " "Exiting!\n", NUM_FLUID_COMPONENTS); process_exit(1); } fprintf( o, "ns %d\n", lattice->param.ns_flag ); fprintf( o, "ns %f\n", lattice->param.ns ); fprintf( o, "slice_x %d\n", lattice->param.slice_x ); fprintf( o, "slice_y %d\n", lattice->param.slice_y ); fprintf( o, "ic_poiseuille %d\n", lattice->param.ic_poiseuille ); fprintf( o, "bc_poiseuille %d\n", lattice->param.bc_poiseuille ); fprintf( o, "bc_slip_north %d\n", lattice->param.bc_slip_north ); #if INAMURO_SIGMA_COMPONENT fprintf( o, "bc_sigma_slip %d\n", lattice->param.bc_sigma_slip ); fprintf( o, "bc_sigma_walls %d\n", lattice->param.bc_sigma_walls ); #else /* !( INAMURO_SIGMA_COMPONENT) */ fprintf( o, "bc_sigma_slip %s\n", "--" ); fprintf( o, "bc_sigma_walls %s\n", "--" ); #endif /* INAMURO_SIGMA_COMPONENT */ fprintf( o, "pressure_n_in[0] %d\n", lattice->param.pressure_n_in[0] ); fprintf( o, "pressure_s_in[0] %d\n", lattice->param.pressure_s_in[0] ); fprintf( o, "pressure_n_out[0] %d\n", lattice->param.pressure_n_out[0] ); fprintf( o, "pressure_s_out[0] %d\n", lattice->param.pressure_s_out[0] ); fprintf( o, "velocity_n_in[0] %d\n", lattice->param.velocity_n_in[0] ); fprintf( o, "velocity_s_in[0] %d\n", lattice->param.velocity_s_in[0] ); fprintf( o, "velocity_n_out[0] %d\n", lattice->param.velocity_n_out[0] ); fprintf( o, "velocity_s_out[0] %d\n", lattice->param.velocity_s_out[0] ); fprintf( o, "pressure_e_in[0] %d\n", lattice->param.pressure_e_in[0] ); fprintf( o, "pressure_w_in[0] %d\n", lattice->param.pressure_w_in[0] ); fprintf( o, "pressure_e_out[0] %d\n", lattice->param.pressure_e_out[0] ); fprintf( o, "pressure_w_out[0] %d\n", lattice->param.pressure_w_out[0] ); fprintf( o, "velocity_e_in[0] %d\n", lattice->param.velocity_e_in[0] ); fprintf( o, "velocity_w_in[0] %d\n", lattice->param.velocity_w_in[0] ); fprintf( o, "velocity_e_out[0] %d\n", lattice->param.velocity_e_out[0] ); fprintf( o, "velocity_w_out[0] %d\n", lattice->param.velocity_w_out[0] ); if( NUM_FLUID_COMPONENTS==2) { fprintf( o, "pressure_n_in[1] %d\n", lattice->param.pressure_n_in[1] ); fprintf( o, "pressure_s_in[1] %d\n", lattice->param.pressure_s_in[1] ); fprintf( o, "pressure_n_out[1] %d\n", lattice->param.pressure_n_out[1] ); fprintf( o, "pressure_s_out[1] %d\n", lattice->param.pressure_s_out[1] ); fprintf( o, "velocity_n_in[1] %d\n", lattice->param.velocity_n_in[1] ); fprintf( o, "velocity_s_in[1] %d\n", lattice->param.velocity_s_in[1] ); fprintf( o, "velocity_n_out[1] %d\n", lattice->param.velocity_n_out[1] ); fprintf( o, "velocity_s_out[1] %d\n", lattice->param.velocity_s_out[1] ); fprintf( o, "pressure_e_in[1] %d\n", lattice->param.pressure_e_in[1] ); fprintf( o, "pressure_w_in[1] %d\n", lattice->param.pressure_w_in[1] ); fprintf( o, "pressure_e_out[1] %d\n", lattice->param.pressure_e_out[1] ); fprintf( o, "pressure_w_out[1] %d\n", lattice->param.pressure_w_out[1] ); fprintf( o, "velocity_e_in[1] %d\n", lattice->param.velocity_e_in[1] ); fprintf( o, "velocity_w_in[1] %d\n", lattice->param.velocity_w_in[1] ); fprintf( o, "velocity_e_out[1] %d\n", lattice->param.velocity_e_out[1] ); fprintf( o, "velocity_w_out[1] %d\n", lattice->param.velocity_w_out[1] ); } else if( NUM_FLUID_COMPONENTS==1) { fprintf( o, "pressure_n_in[1] %s\n", "--" ); fprintf( o, "pressure_s_in[1] %s\n", "--" ); fprintf( o, "pressure_n_out[1] %s\n", "--" ); fprintf( o, "pressure_s_out[1] %s\n", "--" ); fprintf( o, "velocity_n_in[1] %s\n", "--" ); fprintf( o, "velocity_s_in[1] %s\n", "--" ); fprintf( o, "velocity_n_out[1] %s\n", "--" ); fprintf( o, "velocity_s_out[1] %s\n", "--" ); fprintf( o, "pressure_e_in[1] %s\n", "--" ); fprintf( o, "pressure_w_in[1] %s\n", "--" ); fprintf( o, "pressure_e_out[1] %s\n", "--" ); fprintf( o, "pressure_w_out[1] %s\n", "--" ); fprintf( o, "velocity_e_in[1] %s\n", "--" ); fprintf( o, "velocity_w_in[1] %s\n", "--" ); fprintf( o, "velocity_e_out[1] %s\n", "--" ); fprintf( o, "velocity_w_out[1] %s\n", "--" ); } else { printf( "read_params() -- " "Unhandled case " "NUM_FLUID_COMPONENTS = %d . " "Exiting!\n", NUM_FLUID_COMPONENTS); process_exit(1); } if( INAMURO_SIGMA_COMPONENT) { fprintf( o, "constcon_n_in %d\n", lattice->param.constcon_n_in ); fprintf( o, "constcon_s_in %d\n", lattice->param.constcon_s_in ); fprintf( o, "constcon_n_out %d\n", lattice->param.constcon_n_out ); fprintf( o, "constcon_s_out %d\n", lattice->param.constcon_s_out ); fprintf( o, "constflx_n_in %d\n", lattice->param.constflx_n_in ); fprintf( o, "constflx_s_in %d\n", lattice->param.constflx_s_in ); fprintf( o, "constflx_n_out %d\n", lattice->param.constflx_n_out ); fprintf( o, "constflx_s_out %d\n", lattice->param.constflx_s_out ); fprintf( o, "constcon_n_in %d\n", lattice->param.constcon_e_in ); fprintf( o, "constcon_s_in %d\n", lattice->param.constcon_w_in ); fprintf( o, "constcon_n_out %d\n", lattice->param.constcon_e_out ); fprintf( o, "constcon_s_out %d\n", lattice->param.constcon_w_out ); fprintf( o, "constflx_n_in %d\n", lattice->param.constflx_e_in ); fprintf( o, "constflx_s_in %d\n", lattice->param.constflx_w_in ); fprintf( o, "constflx_n_out %d\n", lattice->param.constflx_e_out ); fprintf( o, "constflx_s_out %d\n", lattice->param.constflx_w_out ); fprintf( o, "zeroconcgrad_n %d\n", lattice->param.zeroconcgrad_n ); fprintf( o, "zeroconcgrad_s %d\n", lattice->param.zeroconcgrad_s ); fprintf( o, "zeroconcgrad_n %d\n", lattice->param.zeroconcgrad_e ); fprintf( o, "zeroconcgrad_s %d\n", lattice->param.zeroconcgrad_w ); fprintf( o, "zeroconcgrad_full %d\n", lattice->param.zeroconcgrad_full ); } else { fprintf( o, "constcon_n_in %s\n", "--" ); fprintf( o, "constcon_s_in %s\n", "--" ); fprintf( o, "constcon_n_out %s\n", "--" ); fprintf( o, "constcon_s_out %s\n", "--" ); fprintf( o, "constflx_n_in %s\n", "--" ); fprintf( o, "constflx_s_in %s\n", "--" ); fprintf( o, "constflx_n_out %s\n", "--" ); fprintf( o, "constflx_s_out %s\n", "--" ); fprintf( o, "constcon_e_in %s\n", "--" ); fprintf( o, "constcon_w_in %s\n", "--" ); fprintf( o, "constcon_e_out %s\n", "--" ); fprintf( o, "constcon_w_out %s\n", "--" ); fprintf( o, "constflx_e_in %s\n", "--" ); fprintf( o, "constflx_w_in %s\n", "--" ); fprintf( o, "constflx_e_out %s\n", "--" ); fprintf( o, "constflx_w_out %s\n", "--" ); fprintf( o, "zeroconcgrad_n %s\n", "--" ); fprintf( o, "zeroconcgrad_s %s\n", "--" ); fprintf( o, "zeroconcgrad_e %s\n", "--" ); fprintf( o, "zeroconcgrad_w %s\n", "--" ); fprintf( o, "zeroconcgrad_full %s\n", "--" ); } fprintf( o, "plot_scale_dynamic %d\n", lattice->param.plot_scale_dynamic); fprintf( o, "use_colormap %d\n", lattice->param.use_colormap ); fprintf( o, "initial_condition %d\n", lattice->param.initial_condition ); fprintf( o, "x0 %f\n", lattice->param.x0 ); fprintf( o, "y0 %f\n", lattice->param.y0 ); fprintf( o, "r0 %f\n", lattice->param.r0 ); fprintf( o, "cut %f\n", lattice->param.cut ); fprintf( o, "x1 %f\n", lattice->param.x1 ); fprintf( o, "x2 %f\n", lattice->param.x2 ); fprintf( o, "y1 %f\n", lattice->param.y1 ); fprintf( o, "y2 %f\n", lattice->param.y2 ); fprintf( o, "rel_x1 %f\n", lattice->param.rel_x1 ); fprintf( o, "rel_x2 %f\n", lattice->param.rel_x2 ); fprintf( o, "rel_y1 %f\n", lattice->param.rel_y1 ); fprintf( o, "rel_y2 %f\n", lattice->param.rel_y2 ); fprintf( o, "dump_rho %d\n", lattice->param.dump_rho ); fprintf( o, "dump_u %d\n", lattice->param.dump_u ); fprintf( o, "dump_force %d\n", lattice->param.dump_force ); fprintf( o, "dump_vor %d\n", lattice->param.dump_vor ); fprintf( o, "do_user_stuff %d\n", lattice->param.do_user_stuff ); fprintf( o, "out_path %s\n", lattice->param.out_path ); fprintf( o, "make_octave_scripts %d\n", lattice->param.make_octave_scripts); fclose(o); #if VERBOSITY_LEVEL >= 1 printf("lbio.c: dump_params() -- Wrote file \"%s\".\n",filename); #endif /* VERBOSITY_LEVEL >= 1 */ } /* void dump_params( struct lattice_struct *lattice) */
111pjb-one
src/params.h
C
gpl3
97,223
//############################################################################## // // Copyright (C), 2005, Danny Thorne // // spy.c // // - "spy" a bitmap file and print info about it. // // - If it is small, print matrix of pixel values. // #include <stdio.h> #include <math.h> //#if SWAP_BYTE_ORDER || OSTYPE==darwin #if SWAP_BYTE_ORDER // Swap byte order. #define ENDIAN2(w) ((((w)&0x00ff)<<8)|(((w)&0xff00)>>8)) #define ENDIAN4(w) ((((w)&0x000000ff)<<24)|(((w)&0xff000000)>>24)|(((w)&0x0000ff00)<<8)|(((w)&0x00ff0000)>>8)) #else /* !( SWAP_BYTE_ORDER) */ #define ENDIAN2(w) (w) #define ENDIAN4(w) (w) #endif /* SWAP_BYTE_ORDER */ // Reference: // http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html // (See text at bottom of this file.) struct bitmap_file_header { // 1 2 bfType 19778 must always be set to 'BM' to declare that this is // a .bmp-file. char bfType[2]; // 3 4 bfSize ?? specifies the size of the file in bytes. char bfSize[4]; // 7 2 bfReserved1 0 must always be set to zero. char bfReserved1[2]; // 9 2 bfReserved2 0 must always be set to zero. char bfReserved2[2]; // 11 4 bfOffBits 1078 specifies the offset from the beginning of the // file to the bitmap data. char bfOffBits[4]; }; struct bitmap_info_header { // 15 4 biSize 40 specifies the size of the BITMAPINFOHEADER structure, // in bytes. char biSize[4]; // 19 4 biWidth 100 specifies the width of the image, in pixels. char biWidth[4]; // 23 4 biHeight 100 specifies the height of the image, in pixels. char biHeight[4]; // 27 2 biPlanes 1 specifies the number of planes of the target device, // must be set to zero. [DT: Should be set to one, right? Not zero.] char biPlanes[2]; // 29 2 biBitCount 8 specifies the number of bits per pixel. char biBitCount[2]; // 31 4 biCompression 0 Specifies the type of compression, usually set // to zero (no compression). char biCompression[4]; // 35 4 biSizeImage 0 specifies the size of the image data, in bytes. // If there is no compression, it is valid to set this member to zero. char biSizeImage[4]; // 39 4 biXPelsPerMeter 0 specifies the the horizontal pixels per meter // on the designated targer device, usually set to zero. char biXPelsPerMeter[4]; // 43 4 biYPelsPerMeter 0 specifies the the vertical pixels per meter // on the designated targer device, usually set to zero. char biYPelsPerMeter[4]; // 47 4 biClrUsed 0 specifies the number of colors used in the bitmap, // if set to zero the number of colors is calculated using the biBitCount // member. char biClrUsed[4]; // 51 4 biClrImportant 0 specifies the number of color that are // 'important' for the bitmap, if set to zero, all colors are important. char biClrImportant[4]; }; struct rgb_quad { // 1 1 rgbBlue - specifies the blue part of the color. char Blue; // 2 1 rgbGreen - specifies the green part of the color. char Green; // 3 1 rgbRed - specifies the red part of the color. char Red; // 4 1 rgbReserved - must always be set to zero. char Reserved; }; main( int argc, int **argv) { int **spy, height, width, i, j; char filename[1024]; FILE *o; //printf("\n"); //printf("main() -- Hi!\n"); if( argc == 1) { printf("\n"); printf("usage>> ./spy [ input_file_name [output_file_name]]\n"); printf("\n"); process_exit(1); } else { sprintf( filename, "%s", *(argv+1)); printf("\n"); printf("Input filename is \"%s\".\n", filename); } read_bmp( filename); spy_bmp( filename, &spy, &height, &width); printf(">> spy( 1:%d, 1:%d)\n", height, width); printf("\n"); if( height <= 10 && width <= 40) { for( j=0; j<height; j++) { for( i=0; i<width; i++) { printf(" %d", spy[j][i]); } printf("\n"); } printf("\n"); } if( argc > 2) { if( argc != 3) { printf("usage>> spy [ input_file_name [output_file_name]]\n"); } sprintf( filename, "%s", *(argv+2)); if( !( o = fopen( filename, "w+"))) { printf("Error opening \"%s\".\n", filename); } else { printf("Outputting spy results to \"%s\".\n", filename); for( j=0; j<height; j++) { for( i=0; i<width; i++) { fprintf( o, " %d", spy[j][i]); } fprintf( o, "\n"); } fclose(o); } } // Deallocate memory used by the spy matrix. for( j=0; j<height; j++) { free( spy[j]); } free( spy); printf("\n"); printf("Done.\n"); printf("\n"); return 0; } /* main( int argc, int **argv) */ // read_bmp( char *filename) //############################################################################## // // R E A D B M P // read_bmp( char *filename) { FILE *in; int i, n, m; int pad, bytes_per_row; char k; char b; struct bitmap_file_header bmfh; struct bitmap_info_header bmih; struct rgb_quad rgb; int *int_ptr; short int *short_int_ptr; int *width_ptr; int *height_ptr; short int *bitcount_ptr; int width, height, depth; printf("\n"); printf("read_bmp() -- Hi!\n"); printf("\n"); //printf("sizeof(char) = %d\n", sizeof(char)); //printf("sizeof(int) = %d\n", sizeof(int)); //printf("\n"); //printf("sizeof( struct bitmap_file_header) = %d\n", // sizeof(struct bitmap_file_header)); //printf("sizeof( struct bitmap_info_header) = %d\n", // sizeof(struct bitmap_info_header)); //printf("\n"); //in = fopen( "junk.bmp", "r"); in = fopen( filename, "r"); // n = fread( void *BUF, size_t SIZE, size_t COUNT, FILE *FP); n = fread( &bmfh, sizeof(struct bitmap_file_header), 1, in ); if( strncmp(bmfh.bfType,"BM",2)) { printf("ERROR: Can't process this file type. Exiting!\n"); printf("\n"); process_exit(1); } printf("struct bitmap_file_header:\n"); //char bfType[2]; printf(" bfType: \"%c%c\"\n", bmfh.bfType[0], bmfh.bfType[1]); //char bfSize[4]; //int_ptr = ENDIAN4(((int)(*((int*)(bmfh.bfSize))))); printf(" bfSize: %d bytes\n", ENDIAN4(((int)(*((int*)(bmfh.bfSize)))))); //char bfReserved1[2]; short_int_ptr = (short int*)bmfh.bfReserved1; printf(" bfReserved1: %d\n", *short_int_ptr); //char bfReserved2[2]; short_int_ptr = (short int*)bmfh.bfReserved2; printf(" bfReserved2: %d\n", *short_int_ptr); //char bfOffBits[4]; //int_ptr = ENDIAN4(((int)(*((int*)(bmfh.bfOffBits))))); printf(" bfOffBits: %d\n", ENDIAN4(((int)(*((int*)(bmfh.bfOffBits)))))); printf("\n"); n = fread( &bmih, sizeof(struct bitmap_info_header), 1, in ); int_ptr = (int*)bmih.biCompression; if( *int_ptr != 0) { printf("ERROR: Can't handle compression. Exiting!\n"); printf("\n"); process_exit(1); } printf("struct bitmap_info_header:\n"); // char biSize[4] //int_ptr = (int*)bmih.biSize; printf(" biSize: %d bytes\n", ENDIAN4(((int)(*((int*)(bmih.biSize)))))); // char biWidth[4] //int_ptr = (int*)bmih.biWidth; printf(" biWidth: %d pixels\n", ENDIAN4(((int)(*((int*)(bmih.biWidth)))))); // char biHeight[4] //int_ptr = (int*)bmih.biHeight; //printf(" biHeight: %d pixels\n", *int_ptr); printf(" biHeight: %d pixels\n", ENDIAN4(((int)(*((int*)(bmih.biHeight)))))); // char biPlanes[2] //short_int_ptr = (short int*)bmih.biPlanes; printf(" biPlanes: %d\n", ENDIAN2(((int)(*((int*)(bmih.biPlanes)))))); // char biBitCount[2] //short_int_ptr = (short int*)bmih.biBitCount; printf(" biBitCount: %d bits per pixel\n", ENDIAN2(((int)(*((int*)(bmih.biBitCount)))))); // char biCompression[4] int_ptr = (int*)bmih.biCompression; printf(" biCompression: %d\n", *int_ptr); // char biSizeImage[4] int_ptr = (int*)bmih.biSizeImage; printf(" biSizeImage: %d bytes\n", *int_ptr); // char biXPelsPerMeter[4] int_ptr = (int*)bmih.biXPelsPerMeter; printf(" biXPelsPerMeter: %d\n", *int_ptr); // char biYPelsPerMeter[4] int_ptr = (int*)bmih.biYPelsPerMeter; printf(" biYPelsPerMeter: %d\n", *int_ptr); // char biClrUsed[4] int_ptr = (int*)bmih.biClrUsed; printf(" biClrUsed: %d\n", *int_ptr); // char biClrImportant[4] int_ptr = (int*)bmih.biClrImportant; printf(" biClrImportant: %d\n", *int_ptr); printf("\n"); width = ENDIAN4(((int)(*((int*)(bmih.biWidth))))); height = ENDIAN4(((int)(*((int*)(bmih.biHeight))))); depth = ENDIAN4(((int)(*((int*)(bmih.biBitCount))))); if( depth < 24) { //printf("(double)*(bmih.biBitCount) = %f\n", (double)*(bmih.biBitCount)); n = (double)pow(2.,depth); printf("n = %d entries in palette.\n", n); for( i=0; i<n; i++) { k = fread( &rgb, sizeof(struct rgb_quad), 1, in ); if( k!=1) { printf("Error reading palette entry %d. Exiting!\n", i); process_exit(1); } #if 0 printf("%4d: [ \"%c\" \"%c\" \"%c\"] (\"%c\")\n", i, rgb.Red, rgb.Green, rgb.Blue, rgb.Reserved ); #else printf("%4d: #", i); printf("%1x%1x", (rgb.Red & 0xf0)>>4, (rgb.Red & 0x0f)); printf("%1x%1x", (rgb.Green & 0xf0)>>4, (rgb.Green & 0x0f)); printf("%1x%1x", (rgb.Blue & 0xf0)>>4, (rgb.Blue & 0x0f)); printf(" "); printf("( %3d, %3d, %3d)", (rgb.Red+256)%256, (rgb.Green+256)%256, (rgb.Blue+256)%256 ); printf("\n"); #endif } } else { printf("BitCount = %d, so no color table.\n",(int)*(bmih.biBitCount)); } printf("\n"); width_ptr = (int*)bmih.biWidth; height_ptr = (int*)bmih.biHeight; bitcount_ptr = (short int*)bmih.biBitCount; // Bytes per row of the bitmap. bytes_per_row = ((int)ceil(( (((double)width)*((double)depth))/8.))); // Bitmaps pad rows to preserve 4-byte boundaries. // The length of a row in the file will be bytes_per_row + pad . pad = ((4) - bytes_per_row%4)%4; printf("----------------------------------------\n"); printf("Pixel Data: "); if( !( width <= 10 && height <= 20)) { printf("<Too large to display.>\n"); } else { printf("\n"); } n = 0; m = 0; n+=( k = fread( &b, 1, 1, in )); while( !feof(in)) { #if 0 printf("%d", (b & 0x80) != 0); printf("%d", (b & 0x40) != 0); printf("%d", (b & 0x20) != 0); printf("%d", (b & 0x10) != 0); printf("%d", (b & 0x08) != 0); printf("%d", (b & 0x04) != 0); printf("%d", (b & 0x02) != 0); printf("%d", (b & 0x01) != 0); printf(" (%3d)", (b+256)%256); printf(" (%2d,%2d) |", (b&0xf0)>>4, b&0x0f); #else if( width <= 10 && height <= 20) { printf(" "); switch(depth) { case 1: // Monochrome. printf("%d", (b & 0x80) != 0); printf("%d", (b & 0x40) != 0); printf("%d", (b & 0x20) != 0); printf("%d", (b & 0x10) != 0); printf("%d", (b & 0x08) != 0); printf("%d", (b & 0x04) != 0); printf("%d", (b & 0x02) != 0); printf("%d", (b & 0x01) != 0); break; case 4: // 16 colors. printf("%2d", (b&0xf0)>>4); printf(" "); printf("%2d", b&0x0f); break; case 8: // 256 colors. printf("%3d", (b+256)%256); break; case 24: // 24-bit colors. printf("%d", (b & 0x80) != 0); printf("%d", (b & 0x40) != 0); printf("%d", (b & 0x20) != 0); printf("%d", (b & 0x10) != 0); printf("%d", (b & 0x08) != 0); printf("%d", (b & 0x04) != 0); printf("%d", (b & 0x02) != 0); printf("%d", (b & 0x01) != 0); break; default: // 32-bit colors? printf("ERROR: Unhandled color depth, " "BitCount = %d. Exiting!\n", depth); process_exit(1); break; } printf(" |"); } #endif if( !(n%(bytes_per_row+pad))) { if( width <= 5 && width <= 10) { printf("\n");} m++; } n+=( k = fread( &b, 1, 1, in )); } /* while( !feof(in)) */ if( width <= 5 && width <= 10) { printf("\n");} printf("----------------------------------------\n"); printf("\n"); printf("%d bytes.\n", n); printf("%d rows.\n", m); printf("%d bytes containing data per row.\n", bytes_per_row); printf("%d bytes of padding per row.\n", pad); printf("( %d + %d) * %d = %d\n", bytes_per_row, pad, m, (bytes_per_row+pad)*m); printf("\n"); if( (bytes_per_row+pad)*m!=n) { printf("WARNING: Num bytes read = %d versus num bytes predicted = %d .\n", n, (bytes_per_row+pad)*m); } if( m != height) { printf("WARNING: m (%d) != bmih.biHeight (%d).\n", m, height); } fclose(in); printf("read_bmp() -- Bye!\n"); printf("\n"); } /* read_bmp( char *filename) */ // spy_bmp( char *filename, int ***spy) //############################################################################## // // S P Y B M P // spy_bmp( char *filename, int ***spy, int *arg_height, int *arg_width) { FILE *in; int i, j, n, m; int pad, bytes_per_row; char k; char b; struct bitmap_file_header bmfh; struct bitmap_info_header bmih; struct rgb_quad rgb; int *int_ptr; short int *short_int_ptr; int *width_ptr; int *height_ptr; short int *bitcount_ptr; int width, height, depth; printf("spy_bmp() -- Hi!\n"); in = fopen( filename, "r"); // n = fread( void *BUF, size_t SIZE, size_t COUNT, FILE *FP); n = fread( &bmfh, sizeof(struct bitmap_file_header), 1, in ); if( strncmp(bmfh.bfType,"BM",2)) { printf("ERROR: Can't process this file type. Exiting!\n"); printf("\n"); process_exit(1); } n = fread( &bmih, sizeof(struct bitmap_info_header), 1, in ); int_ptr = (int*)bmih.biCompression; if( *int_ptr != 0) { printf("ERROR: Can't handle compression. Exiting!\n"); printf("\n"); process_exit(1); } width_ptr = (int*)bmih.biWidth; height_ptr = (int*)bmih.biHeight; bitcount_ptr = (short int*)bmih.biBitCount; width = ENDIAN4(((int)(*((int*)(bmih.biWidth))))); *arg_width = width; height = ENDIAN4(((int)(*((int*)(bmih.biHeight))))); *arg_height = height; depth = ENDIAN4(((int)(*((int*)(bmih.biBitCount))))); if( depth < 24) { n = (double)pow(2.,(double)depth); // Num palette entries. for( i=0; i<n; i++) { k = fread( &rgb, sizeof(struct rgb_quad), 1, in ); if( k!=1) { printf("Error reading palette entry %d. Exiting!\n", i); process_exit(1); } } } // Allocate memory for the spy matrix. *spy = (int**)malloc( (height)*sizeof(int*)); for( m=0; m<height; m++) { (*spy)[m] = (int*)malloc( (width)*sizeof(int)); } #if 0 memset( &((*spy)[0][0]), 0, (*width)*(*height)*sizeof(int)); #else for( j=0; j<height; j++) { for( i=0; i<width; i++) { (*spy)[j][i] = 0; } } #endif // Bytes per row of the bitmap. bytes_per_row = ((int)ceil(( (((double)(width))*((double)(depth)))/8.))); // Bitmaps pad rows to preserve 4-byte boundaries. // The length of a row in the file will be bytes_per_row + pad . pad = ((4) - bytes_per_row%4)%4; n = 0; m = 0; n+=( k = fread( &b, 1, 1, in )); i = 0; j = height-1; while( !feof(in)) { switch(depth) { case 1: // Monochrome. if( i < width) { (*spy)[j][i] = ( (b & 0x80) == 0); } i++; if( i < width) { (*spy)[j][i] = ( (b & 0x40) == 0); } i++; if( i < width) { (*spy)[j][i] = ( (b & 0x20) == 0); } i++; if( i < width) { (*spy)[j][i] = ( (b & 0x10) == 0); } i++; if( i < width) { (*spy)[j][i] = ( (b & 0x08) == 0); } i++; if( i < width) { (*spy)[j][i] = ( (b & 0x04) == 0); } i++; if( i < width) { (*spy)[j][i] = ( (b & 0x02) == 0); } i++; if( i < width) { (*spy)[j][i] = ( (b & 0x01) == 0); } i++; break; case 4: // 16 colors. if( i < width) { (*spy)[j][i] = ( (b&0xf0)>>4 != 15); } i++; if( i < width) { (*spy)[j][i] = ( (b&0x0f) != 15); } i++; break; case 8: // 256 colors. if( i < width) { (*spy)[j][i] = ( (b&0xff) != 255); } i++; break; case 24: // 24-bit colors. if( i < 3*(width)) { //printf("(*spy)[%d][%d] = %d -> ", j, (int)floor((double)i/3.), // (*spy)[j][(int)floor((double)i/3.)]); (*spy)[j][(int)floor((double)i/3.)] |= ( (b&0xff) != 255); //printf("%d\n", (*spy)[j][(int)floor((double)i/3.)]); //printf("( (%d&0xff) != 255) = %d\n", b, ( (b&0xff) != 255)); } i++; break; default: // 32-bit colors? printf("ERROR: Unhandled color depth, " "BitCount = %d. Exiting!\n", depth); process_exit(1); break; } /* switch(*(bmih.biBitCount)) */ if( !(n%(bytes_per_row+pad))) { m++; i=0; j--;} n+=( k = fread( &b, 1, 1, in )); } /* while( !feof(in)) */ if( (bytes_per_row+pad)*m!=n) { printf("WARNING: Num bytes read = %d versus num bytes predicted = %d .\n", n, (bytes_per_row+pad)*m); } if( m != height) { printf("WARNING: m (%d) != bmih.biHeight (%d).\n", m, height); } fclose(in); printf("spy_bmp() -- Bye!\n"); printf("\n"); } /* spy_bmp( char *filename, int ***spy, int *height, int *width) */ /* <http://www.fortunecity.com> web hosting <http://www.fortunecity.com/> domain names <http://www.fortunecity.com/> email addresses <http://www.v3.com/> search <http://www.fortunecity.com/marketplace/> <http://ads.fortunecity.com/RealMedia/ads/click_nx.cgi/en/m_computers_and_internet/410390@Top> The .bmp file format Introduction: The .bmp file format (sometimes also saved as .dib) is the standard for a Windows 3.0 or later DIB(device independent bitmap) <bmsinwin.html> file. It may use compression (though I never came across a compressed .bmp-file) and is (by itself) not capable of storing animation. However, you can animate a bitmap using different methods but you have to write the code which performs the animation. There are different ways to compress a .bmp-file, but I won't explain them here because they are so rarely used. The image data itself can either contain pointers to entries in a color table or literal RGB values (this is explained later). Basic structure: A .bmp file contains of the following data structures: BITMAPFILEHEADER bmfh; BITMAPINFOHEADER bmih; RGBQUAD aColors[]; BYTE aBitmapBits[]; /bmfh/ contains some information about the bitmap file (about the file, not about the bitmap itself). /bmih/ contains information about the bitmap such as size, colors,... The /aColors array/ contains a color table. The rest is the image data, which format is specified by the /bmih/ structure. Exact structure: The following tables give exact information about the data structures and also contain the settings for a bitmap with the following dimensions: size 100x100, 256 colors, no compression. The /start/-value is the position of the byte in the file at which the explained data element of the structure starts, the /size/-value contains the nuber of bytes used by this data element, the /name/-value is the name assigned to this data element by the Microsoft API documentation. /Stdvalue/ stands for standard value. There actually is no such a thing as a standard value but this is the value Paint assigns to the data element if using the bitmap dimensions specified above (100x100x256). The /meaning/-column gives a short explanation of the purpose of this data element. The BITMAPFILEHEADER: *start* *size* *name* *stdvalue* *purpose* 1 2 bfType 19778 must always be set to 'BM' to declare that this is a .bmp-file. 3 4 bfSize ?? specifies the size of the file in bytes. 7 2 bfReserved1 0 must always be set to zero. 9 2 bfReserved2 0 must always be set to zero. 11 4 bfOffBits 1078 specifies the offset from the beginning of the file to the bitmap data. The BITMAPINFOHEADER: start size name stdvalue purpose 15 4 biSize 40 specifies the size of the BITMAPINFOHEADER structure, in bytes. 19 4 biWidth 100 specifies the width of the image, in pixels. 23 4 biHeight 100 specifies the height of the image, in pixels. 27 2 biPlanes 1 specifies the number of planes of the target device, must be set to zero. 29 2 biBitCount 8 specifies the number of bits per pixel. 31 4 biCompression 0 Specifies the type of compression, usually set to zero (no compression). 35 4 biSizeImage 0 specifies the size of the image data, in bytes. If there is no compression, it is valid to set this member to zero. 39 4 biXPelsPerMeter 0 specifies the the horizontal pixels per meter on the designated targer device, usually set to zero. 43 4 biYPelsPerMeter 0 specifies the the vertical pixels per meter on the designated targer device, usually set to zero. 47 4 biClrUsed 0 specifies the number of colors used in the bitmap, if set to zero the number of colors is calculated using the biBitCount member. 51 4 biClrImportant 0 specifies the number of color that are 'important' for the bitmap, if set to zero, all colors are important. Note that /biBitCount/ actually specifies the color resolution of the bitmap. The possible values are: 1 (black/white); 4 (16 colors); 8 (256 colors); 24 (16.7 million colors). The biBitCount data element also decides if there is a color table in the file and how it looks like. In 1-bit mode the color table has to contain 2 entries (usually white and black). If a bit in the image data is clear, it points to the first palette entry. If the bit is set, it points to the second. In 4-bit mode the color table must contain 16 colors. Every byte in the image data represents two pixels. The byte is split into the higher 4 bits and the lower 4 bits and each value of them points to a palette entry. There are also standard colors for 16 colors mode (16 out of Windows 20 reserved colors <rescolrs.html> (without the entries 8, 9, 246, 247)). Note that you do not need to use this standard colors if the bitmap is to be displayed on a screen which support 256 colors or more, however (nearly) every 4-bit image uses this standard colors. In 8-bit mode every byte represents a pixel. The value points to an entry in the color table which contains 256 entries (for details see Palettes in Windows <palinwin.html>. In 24-bit mode three bytes represent one pixel. The first byte represents the red part, the second the green and the third the blue part. There is no need for a palette because every pixel contains a literal RGB-value, so the palette is omitted. The RGBQUAD array: The following table shows a single RGBQUAD structure: start size name stdvalue purpose 1 1 rgbBlue - specifies the blue part of the color. 2 1 rgbGreen - specifies the green part of the color. 3 1 rgbRed - specifies the red part of the color. 4 1 rgbReserved - must always be set to zero. Note that the term /palette/ does not refer to a RGBQUAD array, which is called /color table/ instead. Also note that, in a color table (RGBQUAD), the specification for a color starts with the blue byte. In a palette a color always starts with the red byte. There is no simple way to map the whole color table into a LOGPALETTE structure, which you will need to display the bitmap. You will have to write a function that copies byte after byte. The pixel data: It depens on the BITMAPINFOHEADER structure how the pixel data is to be interpreted (see above <bmpffrmt.html#bmih>). It is important to know that the rows of a DIB are stored upside down. That means that the uppest row which appears on the screen actually is the lowest row stored in the bitmap, a short example: pixels displayed on the screen pixels stored in .bmp-file You do not need to turn around the rows manually. The API functions which also display the bitmap will do that for you automatically. Another important thing is that the number of bytes in one row must always be adjusted to fit into the border of a multiple of four. You simply append zero bytes until the number of bytes in a row reaches a multiple of four, an example: 6 bytes that represent a row in the bitmap: A0 37 F2 8B 31 C4 must be saved as: A0 37 F2 8B 31 C4 *00 00* to reach the multiple of four which is the next higher after six (eight). If you keep these few rules in mind while working with .bmp files it should be easy for you, to master it. Back to the main page <index.html> ------------------------------------------------------------------------ Copyright 1998 Stefan Hetzl. If you have questions or comments or have discovered an error, send mail <mailto:hetzl@teleweb.at> to hetzl@teleweb.at. You may forward this document or publish it on your webpage as long as you don't change it and leave this notice at the end. <http://www.fortunecity.com/?sid=fcfootergif> web hosting <http://www.fortunecity.com/?sid=fcfooterhosting> ? domain names <http://www.fortunecity.com/?sid=fcfooterdomains> ? web design <http://www.fortunecity.com/web-design.shtml?sid=fcfooterdesign> online games <http://www.hotgames.com/> ? digital cameras <http://www.onlinereviewguide.com/> ? photo album <http://www.myphotoalbum.com/> advertising online <http://www.ampiramedia.com/> ? online casino <http://www.newyorkscasinos.com/> */
111pjb-one
src/spy.c
C
gpl3
25,343
//############################################################################## // // Copyright (C), 2005, Michael Sukop and Danny Thorne // // flags.h // // - Preprocessor flags for lb2d_prime. // #ifndef FLAGS_H #define FLAGS_H // Set VERBOSITY_LEVEL to correspond to how deep into nested loops to // print debug and related output. Stuff will be printed down to // loops nested VERBOSITY_LEVEL-1 deep. For example, // // VERBOSITY_LEVEL 0 ==> Nothing is printed, even outside of loops. // VERBOSITY_LEVEL 1 ==> Only stuff outside of loops is printed. // VERBOSITY_LEVEL 2 ==> Stuff inside the first level of loops is printed. // VERBOSITY_LEVEL 3 ==> Stuff inside the second level of loops is printed. // // Flag: VERBOSITY_LEVEL #define VERBOSITY_LEVEL 1 // If SAY_HI is on, some routines will display "hi" and "bye" messages // to stdout. // Flag: SAY_HI #define SAY_HI 0 // NUM_FLUID_COMPONENTS specifies the number of fluid components. // Flag: NUM_FLUID_COMPONENTS #define NUM_FLUID_COMPONENTS 1 // If NUM_FLUID_COMPONENTS is 2, the second component can be the sigma // component for solute (or thermal) transport as in Inamuro & Yoshino // by turning on INAMURO_SIGMA_COMPONENT . // Flag: INAMURO_SIGMA_COMPONENT #define INAMURO_SIGMA_COMPONENT ( 1 && NUM_FLUID_COMPONENTS==2) // Toggle Zhang & Chen energy transport method, PRE 67, 0066711 (2003). // Supposed to give thermodynamic consistency unlike old Shan & Chen method. // And supports general equation of state P = P(rho,T). // Utilizes the Inamuro component for evolution of the energy transport // equation. Employs modified compute_phase_force routine to compute // body force term representing non-local interaction potential U among // particles. // Flag: ZHANG_AND_CHEN_ENERGY_TRANSPORT #define ZHANG_AND_CHEN_ENERGY_TRANSPORT ( 0 && (INAMURO_SIGMA_COMPONENT)) // Simulate POROUS_MEDIA via a solid density parameter // as proposed by Dardis and McCloskey, // Phys Rev E, 57, 4, 4834-4837, 1998 // Flag: POROUS_MEDIA #define POROUS_MEDIA 0 // Simulate porous media as a body force. #define FREED_POROUS_MEDIA 0 // Toggle Tau & Zhang anisotropic dispersion. #define TAU_ZHANG_ANISOTROPIC_DISPERSION ( 1 \ && INAMURO_SIGMA_COMPONENT \ && POROUS_MEDIA ) // Guo, Zheng & Shi: PRE 65 2002, Body force #define GUO_ZHENG_SHI_BODY_FORCE 0 // Body force macros #if GUO_ZHENG_SHI_BODY_FORCE #if INAMURO_SIGMA_COMPONENT #define F(dir_,rho_,conc_) \ ( lattice->param.gval[0][(dir_)] \ /*+ lattice->param.gval[subs][(dir_)] */\ /* *(rho_) */\ *( 1. + get_buoyancy(lattice) \ *( get_beta(lattice)) \ *( (conc_) - get_C0(lattice))) \ ) #else #define F(dir_) lattice->param.gval[subs][(dir_)] #endif #else #if INAMURO_SIGMA_COMPONENT #define F(dir_,rho_,conc_) \ ( lattice->param.gval[0][(dir_)] \ /*+ lattice->param.gval[1][(dir_)] */\ /* *(rho_) */\ *( 1. + ( get_buoyancy(lattice)) \ *( get_beta(lattice)) \ *( (conc_) - get_C0(lattice))) ) #else #define F(dir_,rho_) \ lattice->param.gval[subs][(dir_)] \ *((lattice->param.incompressible)?(rho_):(1.)) #endif #endif // When there are two (or more) fluid components, a single velocity is // sometimes (always?) used to compute the equilibrium distribution // function. This single velocity will be called upr, and the // STORE_U_COMPOSITE flag will toggle its use. // Flag: STORE_U_COMPOSITE #define STORE_U_COMPOSITE ( 1 && ( (NUM_FLUID_COMPONENTS)==2 \ &&!((INAMURO_SIGMA_COMPONENT)))) // If DO_NOT_STORE_SOLIDS is on, then only the nodes necessary to flow are // stored. In this case, extra storage is needed for geometry information // (e.g. node neighbors). If the ratio of fluid nodes to solid nodes is // small (<~.7), this results in lower storage requirements. // Flag: DO_NOT_STORE_SOLIDS #define DO_NOT_STORE_SOLIDS 0 // If COMPUTE_ON_SOLIDS is on, macroscopic variables and feq will be computed // on solid nodes, even though they are not conceptually meaningful there. // This can be helpful for debugging purposes. #define COMPUTE_ON_SOLIDS 1 // NON_LOCAL_FORCES toggles any mechanisms for computing and storing // non-local (interaction) forces. // Flag: NON_LOCAL_FORCES #define NON_LOCAL_FORCES ( 0 && !(INAMURO_SIGMA_COMPONENT&&!ZHANG_AND_CHEN_ENERGY_TRANSPORT)) // The phase force weighting factors: // WM = weights in the direction of major axes // WD = weights in the direction of diagonals // According to Raskinmaki, it should be WM=2 and WD=1. // According to Chen (via correspondence) it should be WM=4 and WD=1. // According to Sukop and Thorne, it should be WM=1/9 and WD=1/36. // The corresonding G values (a.k.a. G, as in params.in) for the usual // equation of state that we like are -5, -10/3, and -120, respectively. // Flag: WM #define WM (1./ 9.) // Flag: WD #define WD (1./36.) #define Q 9 // Toggle manage_body_force call at beginning of time loop for // gradually increasing/decreasing gravity. // Flag: MANAGE_BODY_FORCE #define MANAGE_BODY_FORCE 0 // Toggle break through curve (BTC) mechanism for sigma component. // Flag: STORE_BTC #define STORE_BTC ( 1 && INAMURO_SIGMA_COMPONENT) // // Toggle DETERMINE_FLOW_DIRECTION to attempt to determine the direction of // flow. // // Assigns FlowDir = { 0, 1, 2} = { indeterminate, vertical, horizontal} // // NOTE: This determination informs the breakthrough curve mechanism which // should be used in a simple situation with either pressure/velocity // boundaries driving the flow in one direction or gravity driving the flow // in one direction. If the direction of flow cannot be determined, FlowDir // will be set to indeterminate (=0) and a BTC will not be stored. // // NOTE: This determination also informs the sigma slip boundary which // should only be used in the simple situation of flow through a channel // where the geometry is trivial and the direction of flow is obvious. // // Flag: DETERMINE_FLOW_DIRECTION #define DETERMINE_FLOW_DIRECTION 1 // Toggle mechanism to initialize domain with ux_in or uy_in. This is // useful for setting a velocity in a periodic domain without using // fluid boundary conditions. // Flag: INITIALIZE_WITH_UX_IN #define INITIALIZE_WITH_UX_IN 0 // Flag: INITIALIZE_WITH_UY_IN #define INITIALIZE_WITH_UY_IN 0 // Dumping the density and velocity data to files can be time consuming and // take up a lot of disk space. If all that is needed is the BMP files, then // turn WRITE_MACRO_VAR_DAT_FILES off to save time and space. // Flag: WRITE_MACRO_VAR_DAT_FILES #define WRITE_MACRO_VAR_DAT_FILES 1 // Usually the density and velocity are written only for the active nodes // and in a way designed for post-processing. Additional files with the // variables written in a readable grid of all lattice nodes will be // generated when WRITE_RHO_AND_U_TO_TXT is on. This is done in an // inefficient way and is intended only for debugging purposes on tiny // lattices. Note that if WRITE_MACRO_VAR_DAT_FILES is off, this flag // has no effect. // Flag: WRITE_RHO_AND_U_TO_TXT #define WRITE_RHO_AND_U_TO_TXT 0 // WRITE_PDF_DAT_FILES is analogous to WRITE_MACRO_VAR_DAT_FILES. // Flag: WRITE_PDF_DAT_FILES #define WRITE_PDF_DAT_FILES 0 // WRITE_PDF_TO_TXT is analogous to WRITE_RHO_AND_U_TO_TXT. // Flag: WRITE_PDF_TO_TXT #define WRITE_PDF_TO_TXT 0 // Value used to represent an INACTIVE_NODE . This is used in the list // of neighbors ( struct node_struct::nn). It is also used in the // map from (i,j) space onto n index space in rho2bmp() and u2bmp(). // Flag: INACTIVE_NODE #define INACTIVE_NODE -1 // Negative densities (f_a) generally signify impending doom. The code // will die "gracefully" when this happens if PUKE_NEGATIVE_DENSITIES is on. // Might want to turn this off to boost performance on big, long runs that // are expected to survive without such instabilities. // Flag: PUKE_NEGATIVE_DENSITIES #define PUKE_NEGATIVE_DENSITIES 0 // Turn one of these on for coloring of the solids in bmp files. // Flag: SOLID_COLOR_IS_CHECKERBOARD #define SOLID_COLOR_IS_CHECKERBOARD 0 // Flag: SOLID_COLOR_IS_BLACK #define SOLID_COLOR_IS_BLACK 1 // Flag: DELAY #define DELAY 0 // Flag: END_GRAV #define END_GRAV 2000 // A single white pixel will be placed in at the (0,0) lattice node if // MARK_ORIGIN_FOR_REFERENCE is turned on. This is good for assisting with the // problem of tracking orientation of the results between regimes (e.g. C, BMP, // Matlab...). // Flag: MARK_ORIGIN_FOR_REFERENCE #define MARK_ORIGIN_FOR_REFERENCE 0 // Flag: PERTURBATIONS #define PERTURBATIONS 0 // If WRITE_CHEN_DAT_FILES is on, the code will output old style chen_*.dat // files to be processed by the old lb_rho_v*.m matlab scripts. // Flag: WRITE_CHEN_DAT_FILES #define WRITE_CHEN_DAT_FILES 0 // NEW_PARAMS_INPUT_ROUTINE is a temporary flag to switch between the old // params input routine and the new one under development. When the new // one is ready, it should be used exclusively. #define NEW_PARAMS_INPUT_ROUTINE 1 #endif /* FLAGS_H */
111pjb-one
src/flags_poiseuille_pressure_y.h
C
gpl3
9,094
#include <stdio.h> main() { char str[1024]; sprintf( str, "ab"); printf("strlen(\"%s\") = %d\n", str, strlen(str)); if( 1 - strlen(str) > 0) { printf("1 - strlen(\"%s\") > 0 = TRUE\n", str); } else { printf("1 - strlen(\"%s\") > 0 = FALSE\n", str); } if( 1 > strlen(str)) { printf("1 > strlen(\"%s\") = TRUE\n", str); } else { printf("1 > strlen(\"%s\") = FALSE\n", str); } }
111pjb-one
src/test_inequality.c
C
gpl3
426
#include <stdio.h> #include <math.h> main() { int i, j; printf("\n"); for( i=-5; i<5; i++) { for( j=-5; j<-1; j++) { printf("i/j = %2d/%2d = %3d (%10.7f) (%10.7f)\n", i, j, i/j, (double)i/(double)j, floor((double)i/(double)j) ); //printf("i/j = %2d/%2d = %3d (%10.7f)\n", i, j, i/j, (double)i/(double)j); } for( j=1; j<5; j++) { printf("i/j = %2d/%2d = %3d (%10.7f) (%10.7f)\n", i, j, i/j, (double)i/(double)j, floor((double)i/(double)j) ); //printf("i/j = %2d/%2d = %3d (%10.7f)\n", i, j, i/j, (double)i/(double)j); } } printf("\n"); }
111pjb-one
src/int_frac_test.c
C
gpl3
679
//############################################################################## // // user_stuff.h // // - This file includes a definition of the struct user_struct, which the // user should fill in with whatever they want. It will be accessed // from the lattice structure as lattice->user_stuff->whatever // // - This file also has forward declarations for the user_stuff functions. // These functions are defined in user_stuff.c. The user should put in // them whatever they want. See user_stuff.c for more information. // // struct user_stuff_struct { double rho_c; double rho_c_start; double rho_c_inc; double rho_c_reverse; double rho_ave; double rho_ave_prev; double u_ave[2]; double u_ave_prev[2]; double tol; FILE *o; }; typedef struct user_stuff_struct *user_stuff_ptr; void user_stuff_pre_frames( lattice_ptr lattice); void user_stuff_frame( lattice_ptr lattice); void user_stuff_post_frames( lattice_ptr lattice); void user_stuff_pre_times( lattice_ptr lattice); void user_stuff_time( lattice_ptr lattice); void user_stuff_post_times( lattice_ptr lattice);
111pjb-one
src/user_stuff_bak20070317_dijoining_pressure.h
C
gpl3
1,116
#include <stdio.h> #define N 3 main() { int i; int *stuff[2]; stuff[0] = (int*)malloc( N*sizeof(int)); stuff[1] = (int*)malloc( N*sizeof(int)); for( i=0; i<N; i++) { stuff[0][i] = i+1; stuff[1][i] = 2*(i+1); } for( i=0; i<N; i++) { printf("stuff[0][%d] = %d\n", i, stuff[0][i]); printf("stuff[1][%d] = %d\n", i, stuff[1][i]); printf("\n"); } }
111pjb-one
src/test.c
C
gpl3
390
//############################################################################## // // Copyright (C), 2005, Michael Sukop and Danny Thorne // // lbmpi.h // // - Note that this is adapted from a previous implementation in an // old mcmp code from last summer (2004). // #ifndef LBMPI_H #define LBMPI_H struct lbmpi_struct { //############################################################################ // // P A R A L L E L V A R I A B L E S // // 1 ... PX // ------------------------- // | | | | // 1 | | | | // | | | | // ------------------------- // . | | | | // . | | | | // . | |1 .. LX| | // ------------------------- // | 1|-|-|-|-| | // PY | ...|-|-|-|-| | // | LY|-|-|-|-| | // ------------------------- // // 06222004 For now, assume PX (and PY) are evenly divisible by LX (and LY). // // 06222004 As a first step, assume periodic boundaries everywhere... // (See the TODO file...) // int NumProcs, // Number of processes. ProcID; // ID of my (this proc's) process. // Param: NPX // Param: NPY // Type: int // Comments: NPX is the number of processes in the x-direction. NPY is the // number of processes in the y-direction. // int NPX, NPY; // Param: PX // Param: PY // Type: int // Comments: Coordinates of process' subdomain in the 2D array of subdomains. // int PX, PY; // Param: GLX // Param: GLY // Type: int // Comments: GLX-by-GLY is the global domain size (number of lattice nodes in // each direction). This is copied from LX and LY before LX and LY are // computed to store the local domain size of each process based on NPX and // NPY. // int GLX, GLY; // Param: GSX // Param: GSY // Param: GEX // Param: GEY // Type: int // Comments: Global starting and ending coordinates of process' piece of // the domain. Process owns nodes from (GSX,GSY) to (GEX,GEY). // int GSX, GSY, GEX, GEY; int NorthID; // ID of proc with sub-domain to the north. int SouthID; // ID of proc with sub-domain to the south. int EastID; // ID of proc with sub-domain to the east. int WestID; // ID of proc with sub-domain to the west. char filename[1024]; MPI_Status status; int ierr; double tic, toc; // Need a string for accumulating output to send through printf... // Outputting elements of an array (e.g. IndicesEW) individually // will result in a mess under MPI. Better to output them to a // string first and then dump the string all at once... Note that // this is just for small scale debugging. For visualizing // contents of larger arrays, write to a file... char iobuf[1024]; double sendtmp, recvtmp; // For debugging... // Stuff for generating type struct for east/west communication. int *BlockLengthsEW; MPI_Aint *AddrsEW; MPI_Aint *IndicesEW; MPI_Datatype *TypesEW; MPI_Datatype MPI_West2East; MPI_Datatype MPI_East2West; // Stuff for generating type struct for north/south communication. int *BlockLengthsNS; MPI_Aint *AddrsNS; MPI_Aint *IndicesNS; MPI_Datatype *TypesNS; MPI_Datatype MPI_South2North; MPI_Datatype MPI_North2South; MPI_Aint Index0; #if DUMP_AFTER_COMM || DUMP_BEFORE_COMM double **fmat; #endif /* DUMP_AFTER_COMM || DUMP_BEFORE_COMM */ }; //typedef struct lbmpi_struct *lbmpi_ptr; #endif LBMPI_H
111pjb-one
src/lbmpi.h
C
gpl3
3,694
//############################################################################## // // Copyright (C), 2005, Michael Sukop and Danny Thorne // // lattice.h // // - Lattice structure and supporting structures for lb2d_prime. // // struct pdf_struct // // - Structure to hold the particle distribution functions. // #ifndef LATTICE_H #define LATTICE_H struct pdf_struct { double feq[ /*NUM_DIRS*/ 9]; double f[ /*NUM_DIRS*/ 9]; double ftemp[ /*NUM_DIRS*/ 9]; }; typedef struct pdf_struct *pdf_ptr; // struct macro_vars_struct // // - Structure to hold the macroscopic variables. // struct macro_vars_struct { double rho; double u[ /*NUM_DIMS*/ 2]; }; #if PEST_OUTPUT_ON // struct conc_data_struct // // - Structure to hold concentration data from an experiment. // struct conc_data_struct { int countervar; int timestep; int x_coord; int y_coord; double norm_conc; }; #endif #if STORE_U_COMPOSITE // struct upr_struct // // - Structure to hold the composite velocity used to compute feq. // struct upr_struct { double u[ /*NUM_DIMS*/ 2]; }; #endif /* STORE_U_COMPOSITE */ // struct bc_struct // // - Structure to hold boundary condition information. // // - Currently it is just an integer flag. I'm putting it inside // a struct in case we want a more complicated boundary // conditions mechanism later. // struct bc_struct { int bc_type; }; typedef struct bc_struct *bc_ptr; // struct bcs_in_struct // // - Structure to hold input values for boundary conditions. // // - These are activated by setting the corresponding flag to 2 in the // params.in file. There must be a file with the corresponding name and // suffix 'dat' in the 'in' folder, e.g., pressure_n_in0.in. The values // in the input file will be used for the boundary conditions, successive // values on successive time steps. If there are more timesteps than input // values, the input values will be cycled. This is particularly useful for // imposing temporally periodic boundary conditions, e.g., to simulate tidal // periods. // struct bcs_in_struct { double* pressure_n_in0; int num_pressure_n_in0; double* pressure_s_in0; int num_pressure_s_in0; #if 0 double* pressure_s_in0; double* pressure_n_out0; double* pressure_s_out0; double* velocity_n_in0; double* velocity_s_in0; double* velocity_n_out0; double* velocity_s_out0; double* pressure_e_in0; double* pressure_w_in0; double* pressure_e_out0; double* pressure_w_out0; double* velocity_e_in0; double* velocity_w_in0; double* velocity_e_out0; double* velocity_w_out0; double* pressure_n_in1; double* pressure_s_in1; double* pressure_n_out1; double* pressure_s_out1; double* velocity_n_in1; double* velocity_s_in1; double* velocity_n_out1; double* velocity_s_out1; double* pressure_e_in1; double* pressure_w_in1; double* pressure_e_out1; double* pressure_w_out1; double* velocity_e_in1; double* velocity_w_in1; double* velocity_e_out1; double* velocity_w_out1; double* constcon_n_in; double* constcon_s_in; double* constcon_n_out; double* constcon_s_out; double* constflx_n_in; double* constflx_s_in; double* constflx_n_out; double* constflx_s_out; double* constcon_e_in; double* constcon_w_in; double* constcon_e_out; double* constcon_w_out; double* constflx_e_in; double* constflx_w_in; double* constflx_e_out; double* constflx_w_out; #endif }; typedef struct bcs_in_struct* bcs_in_ptr; #if DO_NOT_STORE_SOLIDS // struct node_struct // // - Structure to hold node information. // struct node_struct { int i, j; // Lattice coordinates of node. int n; // Node index. int nn[8]; // Indices of neighboring nodes. }; typedef struct node_struct *node_ptr; #endif /* DO_NOT_STORE_SOLIDS */ #if NON_LOCAL_FORCES struct force_struct { double force[ /*NUM_DIMS*/2]; double sforce[ /*NUM_DIMS*/2]; }; #endif /* NON_LOCAL_FORCES */ #if POROUS_MEDIA || FREED_POROUS_MEDIA struct ns_struct { double ns; }; #endif /* POROUS_MEDIA */ struct process_struct { int id; int num_procs; #if PARALLEL int g_LX; int g_LY; //3D int g_LZ; int g_NumNodes; int g_SX, g_EX; int g_SY, g_EY; //3D int g_SZ, g_EZ; int g_StartNode; double *y_pos_pdf_to_send; double *y_pos_pdf_to_recv; double *y_neg_pdf_to_send; double *y_neg_pdf_to_recv; MPI_Request send_req_0; MPI_Request recv_req_0; MPI_Request send_req_1; MPI_Request recv_req_1; MPI_Status mpi_status; int mpierr; #endif }; typedef struct process_struct *process_ptr; // struct param_struct // // Structure to hold parameters that specify the configuration of the problem // to solve. // // Values for these parameters are read from file "./in/params.in". (Note that // there are also some compile-time configuration options in file // "./in/flags.h".) // // Each parameter is preceeded by documentation consisting of three kinds of // fields: "Param", "Type", and "Comments". There may be multiple "Param" // fields for sets of related parameters, e.g. LX and LY. There is only one // occurance of the "Type" field and "Comments" field for each (set of) // parameter(s). The "Param" field(s) and the "Type" field are each one line. // The "Comments" field can be multiple lines. // // Distinct fluids are referred to both as components and as substances. // Normally in conversation we talk about fluid components, but variables are // indexed by "subs". The term "component" can be used to refer to a fluid // component or a solute component (c.f. Inamuro) as well as the more broadly // conventional mathematical usage of a vector component. The reader should be // wary of context, therefore. // // In the "Param" field(s) of the documentation preceeding each parameter, the // parameters that are arrays are stated with typical and/or suggestive index // names between square brackets. For example, tau[subs] is written to suggest // the fact that tau contains an array of values, one for each substance or // fluid component, where "subs" is a typical index name for indexing fluid // components. The commentary section ("Comments" field) for each parameter is // explicit about the meaning of the indices. // // A common mistake made when configuring a problem is to specify in the file // "params.in" an integer number for a type double parameter or vice versa. // This can cause mystifying symptoms. Be careful to include a decimal point in // all type double parameter values in "params.in" regardless of whether there // is a fractional part to the value. Likewise, do not include decimal points // in type integer parameter values. Remember! If things have been going // smoothly and then suddenly go bad in weird ways (sorry I can't recollect any // specific examples) be sure to check this issue in "params.in". Note that // file "params.dat" is output by the code mostly as a sanity check: if values // in "params.dat" do not match values in "params.in", the double versus // integer parameter type issue may be the reason. // // Here are some useful Unix/Linux command lines for processing this // documentation (the "params.txt" file): // // >> grep Param params.txt // // >> grep Comment params.txt // // >> TODO // // >> TODO // // Here is the command line that generates the "params.txt" file from the // "lattice.h" file: // // >> cat ./src/lattice.h | \ // sed -n '/^\/\/ struct param_struct/,/\/\* struct param_struct/p' | \ // grep "\/\/" | \ // sed 's/[ ]*\/\/ //; s/[ ]*\/\/$//' > ./doc/params.txt // // If you are developing under Windows, I recommend Cygwin // // http://www.cygwin.com // // or something comparable. The Unix/Linux command line is indispensable. See // // http://www.cs.usfca.edu/~parrt/course/601/lectures/unix.util.html // http://www.student.northpark.edu/pemente/sed/sed1line.txt // // for example. // // ----------------------------------------------------------------------------- // struct param_struct { // Param: LX // Param: LY // Type: int // Comments: LX is the number of lattice nodes in x-direction. LY is the // number of lattice nodes in y-direction. These are be used to construct // the file name of the BMP file "<LX>x<LY>.bmp" containing the domain. For // example, if LX=160 and LY=120, then the file name is "160x120.bmp". // int LX, LY; // Param: length_scale // Type: int // Comments: length_scale is a characteristic length. This is used for // computing Re. // int length_scale; // Param: NumFrames // Type: int // Comments: NumFrames is the number of frames to output. // int NumFrames; // Param: FrameRate // Type: int // Comments: FrameRate is the number of timesteps per frame. // int FrameRate; // Param: NumTimeSteps // Type: int // Comments: NumTimeSteps is the number of time steps computed as // NumFrames*FrameRate. // int NumTimeSteps; // Param: tau[subs] // Type: double* // Comments: tau is the relaxation time(s). If NUM_FLUID_COMPONENTS==1, then // tau[0] is the relaxation time. If NUM_FLUID_COMPONENTS==2, then tau[0] is // the relaxation time for component 0 and tau[1] is the relaxation time for // component 1. // double tau[ NUM_FLUID_COMPONENTS]; // Param: gval[subs][dir] // Type: double** // Comments: gval[subs][dir] is the gravitational (body) force(s). If // NUM_FLUID_COMPONENTS==1, then gval[0][dir] holds the gravitational force. // If NUM_FLUID_COMPONENTS==2, then gval[0][dir] holds the gravitational // force for component 0 and gval[1][dir] holds the gravitational force for // component 1. In either case, gval[subs][0] is the gravitational force // in the x-direction and gval[subs][1] is the gravitational force in the // y-direction. // double gval[ NUM_FLUID_COMPONENTS][2]; // Param: end_grav[subs] // Type: int // Comments: end_grav[subs] is the timestep at which to end the gravitational // force. If NUM_FLUID_COMPONENTS==1, then end_grav[0] holds the ending // timestep. If NUM_FLUID_COMPONENTS==2, then end_grav[0] holds the ending // timestep for fluid compenent 0 and end_grav[1] holds the ending timestep // for fluid component 1. This mechanism is only enforced when the // MANAGE_BODY_FORCE flag is turned on in "flags.h". It is implemented as a // call to the "manage_body_force()" function at each time step, so it is a // special feature that should generally be turned off. In the future this // mechanism should mature. // int end_grav[ NUM_FLUID_COMPONENTS]; // Param: buoyancy // Type: int // Comments: The "buoyancy" flag toggles buoyancy effects due to the density // of solute. This flag is only relevant when INAMURO_SIGMA_COMPONENT is // turned on in "flags.h". More recently, the buoyancy flag can be +1 or -1 // to switch between solute induced buoyancy effects and temperature induced // buoyancy effects. Use the accessor functions get_buoyancy_flag(lattice), // get_buoyancy_sign(lattice) and get_buoyancy(lattice). // // NOTE: Deprecated. Should just use beta for this mechanism now, right? // int buoyancy; // Param: buoy_subs // Type int // Comment: Which substances gravity value to use in the buoyance term. // Originally we used subs 0, the fluid, gravity. Then we switched to using // the solutes gravity (subs 1) to avoid fluid compressibility effects. int buoy_subs; // Param: incompressible // Type: int // Comments: The "incompressible" flag toggles an incompressible lattice // Boltzmann method (c.f. TODO: cite). The usual method that we experiment // with is the common "weakly" compressible BGK method. For some things // (e.g., TODO) an incompressible model is desired. // int incompressible; // Param: simple_diffusion // Type: int Comments: The simple_diffusion flag toggles a simplified // diffusion computation. It simplifies the computation of feq for the solute // component. It is based on the observation that the process of diffusion // requires less symmetry than flow (c.f. TODO: cite). // int simple_diffusion; // Param: rho_A[subs] // Param: rho_B[subs] // Type: double* // Comments: rho_A[subs] and rho_B[subs] are the initial density values. The // usage of these values varies with respect to the chosen initial condition // (see the initial_condition parameter below). If NUM_FLUID_COMPONENTS==1, // then rho_A[0] and/or rho_B[0] are used to initialize the fluid density. // If NUM_FLUID_COMPONENTS==2, then rho_A[0] and/or rho_B[0] are used to // initialize density of fluid component 0 and rho_A[1] and/or rho_B[1] are // used to initialize density of fluid component 1. All the values are not // necessarily required for all the initial conditions. See the documentation // related to the initial_condition parameter for specifics. // double rho_A[ NUM_FLUID_COMPONENTS]; double rho_B[ NUM_FLUID_COMPONENTS]; #if SOURCE_ON double source_strength; #endif /*SOURCE_ON*/ #if SINK_ON double sink_strength; #endif /*SINK_ON*/ #if INAMURO_SIGMA_COMPONENT // Initial/boundary condition values for solute component. double rho_sigma; double C0; double rho0; double drhodC; double rho_sigma_in; double C_in; double rho_sigma_out; double C_out; double beta; double u_sigma; double u_sigma_in; double u_sigma_out; //int sigma_bulk_on //timestep at which solute in the bulk will begin evolution. #if SIGMA_BULK_FLAG int sigma_bulk_on; #endif /*SIGMA_BULK_FLAG*/ // Param: sigma_start; // Type: int sigma_start; // Comments: Timestep at which solute is activated. If sigma_start == 0, solute will be activated from the beginning. The reason for this option is to make it easy to allow the fluid to equilibrate before introducing solute into the flow. // int sigma_start; // Param: sigma_stop; // Type: int sigma_stop; // Comments: Timestep at which solute is deactivated. If sigma_stop < 0 then the solute will never stop. WARNING: if 0 < sigma_stop < sigma_start, solute will never start. This option is useful, for instance, if it is desired to observe how a solute washes out of the domain. // int sigma_stop; // Param: sigma_btc_rate; // Type: int sigma_btc_rate; // Comments: Rate at which to accumulate temporal breakthrough curve. If sigma_btc_rate <= 0, no btc is stored. // int sigma_btc_rate; // Param: sigma_btc_spot; // Type: int sigma_btc_spot; // Comments: The spot in the domain (as distance from inflow) for measuring btc. If sigma_btc_spot is greater than the length of the domain or <0 then the btc will be measured at the outflow. // int sigma_btc_spot; // Param: *sigma_btc; // Type: double *sigma_btc; // Comments: Pointer to array for storing break through curve. If sigma_btc_rate <= 0, this will remain unallocated. // double *sigma_btc; #endif /* INAMURO_SIGMA_COMPONENT */ // Inflow and outflow conditions for density and velocity. double rho_in, rho_out; double ux_in, ux_out; double uy_in, uy_out; // Param: G; // Type: double G; // Comments: Interaction parameter. // double G; // Param: Gads[NUM_FLUID_COMPONENTS]; // Type: double Gads[NUM_FLUID_COMPONENTS]; // Comments: Adsorption parameters. // double Gads[NUM_FLUID_COMPONENTS]; // Param: ns_flag; // Type: int ns_flag; // Comments: Flag for how to use the solid density parameter. // If ns_flag = 0, then initialize the domain uniformly with ns. // If ns_flag = 1, then read ns values from the ns<LX>x<LY>.bmp file. // If ns_flag = 2, then read ns mask from ns<LX>x<LY>.bmp -- that is, // initialize the domain with ns where there are black pixels in the // ns<LX>x<LY>.bmp file and 0 otherwise. // int ns_flag; // Param: ns; // Type: double ns; // Comments: Solid density parameter for porous media. // double ns; // Param: slice_x // Param: slice_y // Type: int // Comments: Positions of x and y slices to be output to the slice*.m files. // These override the old slice.in file unless both are set to -1. int slice_x; int slice_y; // Param: ic_poiseuille; // Param: bc_poiseuille; // Type: int ic_poiseuille; // Comments: Flags for poiseuille flow initial condition (ic) and boundary condition (bc). // int ic_poiseuille; int bc_poiseuille; // Param: bc_slip_north; // Type: int bc_slip_north; // Comments: Toggle slip condition on north wall. // int bc_slip_north; #if INAMURO_SIGMA_COMPONENT // Param: bc_sigma_slip; // Type: int bc_sigma_slip; // Comments: Slip BC for solute on side walls. Will this make a difference on Taylor dispersion results? NOTE: Only use this for flow through a channel. Slip BC is not implemented for arbitrary geometries. // int bc_sigma_slip; // Param: bc_sigma_walls; // Type: int bc_sigma_walls; // Comments: Enforce concentration (sigma component) boundary conditions on walls. This will mean skipping bounce back for the sigma component on solids. WARNING: Should only be used for walls on the sides of the domain! // int bc_sigma_walls; #if TAU_ZHANG_ANISOTROPIC_DISPERSION double Dl; double Dt; #endif #endif /* INAMURO_SIGMA_COMPONENT */ // Flags for pressure and velocity boundaries. int pressure_n_in[ NUM_FLUID_COMPONENTS]; int pressure_s_in[ NUM_FLUID_COMPONENTS]; int pressure_n_out[ NUM_FLUID_COMPONENTS]; int pressure_s_out[ NUM_FLUID_COMPONENTS]; int velocity_n_in[ NUM_FLUID_COMPONENTS]; int velocity_s_in[ NUM_FLUID_COMPONENTS]; int velocity_n_out[ NUM_FLUID_COMPONENTS]; int velocity_s_out[ NUM_FLUID_COMPONENTS]; int pressure_e_in[ NUM_FLUID_COMPONENTS]; int pressure_w_in[ NUM_FLUID_COMPONENTS]; int pressure_e_out[ NUM_FLUID_COMPONENTS]; int pressure_w_out[ NUM_FLUID_COMPONENTS]; int velocity_e_in[ NUM_FLUID_COMPONENTS]; int velocity_w_in[ NUM_FLUID_COMPONENTS]; int velocity_e_out[ NUM_FLUID_COMPONENTS]; int velocity_w_out[ NUM_FLUID_COMPONENTS]; // Flags for (inamuro) concentration boundaries. int constcon_n_in; int constcon_s_in; int constcon_n_out; int constcon_s_out; int constflx_n_in; int constflx_s_in; int constflx_n_out; int constflx_s_out; int constcon_e_in; int constcon_w_in; int constcon_e_out; int constcon_w_out; int constflx_e_in; int constflx_w_in; int constflx_e_out; int constflx_w_out; // Flags for zero concentration gradient boundaries. // These differ from inamuro's concentration flux boundaries // in that they allow advective flux of the concentration // across the boundary. int zeroconcgrad_n; int zeroconcgrad_s; int zeroconcgrad_e; int zeroconcgrad_w; // Param: zeroconcgrad_full; // Type: int zeroconcgrad_full; // Comments: The zero concentration gradient can be computed by copying (from the adjacent interior neighbor) either just the unknown distribution functions after streaming or all the distributions after streaming. This flag toggles between those methods (where "full" denotes the latter method). // int zeroconcgrad_full; // Param: use_colormap; // Type: int use_colormap; // Comments: See the colormap routines in lbio.c to learn about colormap support. // int use_colormap; // Param: plot_scale_dynamic; // Type: int plot_scale_dynamic; // Comments: Toggle dynamic scaling of the plots. If this is on, color values to be plotted will be dynamically scaled to range between the minimum and maximum values of the data for the current plot. If this is off, color values will be scaled only by the initial value for that quantity (e.g. rho_sigma, rho_A[subs], etc...). NOTE: This is only implemented in rho2bmp() as of 10/15/2004. // int plot_scale_dynamic; // Param: initial_condition; // Type: int initial_condition; // Comments: See bottom of flags.h for listing/description of initial conditions. // int initial_condition; // Center and radius of a circle. Used in the initial conditions for // initializing a bubble in the domain, for instance. double x0; double y0; double r0; // Param: cut; // Type: double cut; // Comments: Cut-off value. Used in the initial conditions for generating static in the two-component case. Sometimes the static needs to be biased toward one component in order for it to evolve stabily. // double cut; // Corner coordinates for a rectangle. Used by initial conditions for // initializing a square-shaped region in the domain. double x1, x2; double y1, y2; // Factors for setting coordinates relative to the domain size. If // the absolute coordinates are negative, use these values to set // the coordinates, e.g. x1 = rel_x1*LX. If these rel_* values are // also negative, then revert to some default absolute coordinates. double rel_x1, rel_x2; double rel_y1, rel_y2; // Param: dump_rho; // Type: int dump_rho; // Comments: Flag to toggle output of the macroscopic density. // int dump_rho; // Param: dump_u; // Type: int dump_u; // Comments: Flag to toggle output of the macroscopic velocity. // int dump_u; // Param: dump_force; // Type: int dump_force; // Comments: Flag to toggle output of the interaction and adsorption forces. // int dump_force; // Param: dump_vor; // Type: int dump_vor; // Comments: Flag to toggle output of vorticity. // int dump_vor; // Param: do_user_stuff; // Type: int do_user_stuff; // Comments: Flag to toggle use of user defined stuff. The user can // define a user_stuff_struct in user_stuff.h and can put stuff in // routines // void do_user_stuff_pre_frames( lattice_ptr lattice); // void do_user_stuff_frame( lattice_ptr lattice); // void do_user_stuff_post_frames( lattice_ptr lattice); // void do_user_stuff_pre_times( lattice_ptr lattice); // void do_user_stuff_time( lattice_ptr lattice); // void do_user_stuff_post_times( lattice_ptr lattice); // which are called in lb2d_prime.c. // int do_user_stuff; char out_path[1024]; // Param: make_octave_scripts; // Type: int make_octave_scripts; // Comments: Flag to toggle generation of Octave scripts instead of Matlab // scripts. If make_octave_scripts is off (=0) then Matlab scripts will be // generated by default. If make_octave_scripts is on (=1) then Octave // scripts will be generated. Currently (06162005) Octave scripts are // minimal -- just a few plots. This will be extended in the future. // int make_octave_scripts; }; /* struct param_struct */ // struct user_stuff_struct; // - Forward declaration for user_stuff_struct. If do_user_stuff is // on in param_struct, then the user will need to have defined the // user_stuff_struct in user_stuff.h. struct user_stuff_struct; // struct lattice_struct // // - Structure with all the lattice information. // // - Contains arrays of the previously defined structures. // struct lattice_struct { int NumNodes; int NumTimeSteps; int time; int frame; int periodic_x[ NUM_FLUID_COMPONENTS]; int periodic_y[ NUM_FLUID_COMPONENTS]; #if TAU_ZHANG_ANISOTROPIC_DISPERSION double *tau_zhang; #endif #if INAMURO_SIGMA_COMPONENT int SizeBTC; // Number of BTC measurements to store. int FlowDir; // Direction {1,2} ==> {Horiz,Vert} of flow. #endif /* INAMURO_SIGMA_COMPONENT */ struct param_struct param; #if DO_NOT_STORE_SOLIDS struct node_struct *node; #endif /* DO_NOT_STORE_SOLIDS */ struct pdf_struct *pdf[ NUM_FLUID_COMPONENTS]; struct macro_vars_struct *macro_vars[ NUM_FLUID_COMPONENTS]; #if PEST_OUTPUT_ON int array_position; int conc_array_size; struct conc_data_struct *concentration_data; #endif struct bc_struct *bc[ NUM_FLUID_COMPONENTS]; struct bcs_in_struct bcs_in[ NUM_FLUID_COMPONENTS]; #if NON_LOCAL_FORCES struct force_struct *force[ NUM_FLUID_COMPONENTS]; #endif /* NON_LOCAL_FORCES */ #if STORE_U_COMPOSITE struct upr_struct *upr; #endif /* STORE_U_COMPOSITE */ #if POROUS_MEDIA || FREED_POROUS_MEDIA struct ns_struct *ns; #endif /* POROUS_MEDIA */ //LBMPI #if PARALLEL //LBMPI lbmpi_ptr lbmpi; //LBMPI #endif /* (PARALLEL) */ struct user_stuff_struct *user_stuff; struct process_struct process; }; //typedef struct lattice_struct *lattice_ptr; struct report_struct { FILE *file; char name[1024]; }; //typedef struct report_struct *report_ptr; struct bitmap_file_header { // 1 2 bfType 19778 must always be set to 'BM' to declare that this is // a .bmp-file. char bfType[2]; // 3 4 bfSize ?? specifies the size of the file in bytes. char bfSize[4]; // 7 2 bfReserved1 0 must always be set to zero. char bfReserved1[2]; // 9 2 bfReserved2 0 must always be set to zero. char bfReserved2[2]; // 11 4 bfOffBits 1078 specifies the offset from the beginning of the // file to the bitmap data. char bfOffBits[4]; }; struct bitmap_info_header { // 15 4 biSize 40 specifies the size of the BITMAPINFOHEADER structure, // in bytes. char biSize[4]; // 19 4 biWidth 100 specifies the width of the image, in pixels. char biWidth[4]; // 23 4 biHeight 100 specifies the height of the image, in pixels. char biHeight[4]; // 27 2 biPlanes 1 specifies the number of planes of the target device, // must be set to zero. [DT: Should be set to one, right? Not zero.] char biPlanes[2]; // 29 2 biBitCount 8 specifies the number of bits per pixel. char biBitCount[2]; // 31 4 biCompression 0 Specifies the type of compression, usually set // to zero (no compression). char biCompression[4]; // 35 4 biSizeImage 0 specifies the size of the image data, in bytes. // If there is no compression, it is valid to set this member to zero. char biSizeImage[4]; // 39 4 biXPelsPerMeter 0 specifies the the horizontal pixels per meter // on the designated targer device, usually set to zero. char biXPelsPerMeter[4]; // 43 4 biYPelsPerMeter 0 specifies the the vertical pixels per meter // on the designated targer device, usually set to zero. char biYPelsPerMeter[4]; // 47 4 biClrUsed 0 specifies the number of colors used in the bitmap, // if set to zero the number of colors is calculated using the biBitCount // member. char biClrUsed[4]; // 51 4 biClrImportant 0 specifies the number of color that are // 'important' for the bitmap, if set to zero, all colors are important. char biClrImportant[4]; }; struct bmp_hdr_struct { char type[2]; // 'BM' char size[4]; // Size of file in bytes. char rsvd[4]; // 0 char dptr[4]; // Offset of data in bytes. char forty[4]; // Size of info header (=40). char width[4]; // Width of image in pixels char height[4];// Height of image in pixels. char planes[2];// Must be set to one. char depth[2]; // Color depth: bits per pixel. char zeros[24];// Unused parameters. }; /* struct bmp_hdr_struct */ struct test_struct { char type[2]; // 'BM' int size; // Size of file in bytes. #if 0 int rsvd; // 0 int dptr; // Offset of data in bytes. int forty; // Size of info header (=40). int width; // Width of image in pixels int height;// Height of image in pixels. short int planes;// Must be set to one. short int depth; // Color depth: bits per pixel. int zeros[6];// Unused parameters. #endif }; /* struct test_struct*/ struct rgb_quad { // 1 1 rgbBlue - specifies the blue part of the color. char Blue; // 2 1 rgbGreen - specifies the green part of the color. char Green; // 3 1 rgbRed - specifies the red part of the color. char Red; // 4 1 rgbReserved - must always be set to zero. char Reserved; }; #include "lattice.c" #endif
111pjb-one
src/lattice.h
C
gpl3
28,013
//############################################################################## // // process.h // #ifndef PROCESS_H #define PROCESS_H #if PARALLEL #include <mpi.h> #endif #include "lattice.h" void process_init( lattice_ptr lattice, int argc, char **argv); void process_compute_local_params( lattice_ptr lattice); void process_send_recv_begin( lattice_ptr lattice, const int subs); void process_send_recv_end( lattice_ptr lattice, const int subs); void process_dump_pdfs_to_recv( lattice_ptr lattice, char *comment_str); void process_dump_pdfs_to_send( lattice_ptr lattice, char *comment_str); void process_dump_pdfs( lattice_ptr lattice, char *comment_str, double *pdfs); void gather_north_pointing_pdfs( lattice_ptr lattice, double *north, const int subs, const int k, const int which_pdf); void gather_south_pointing_pdfs( lattice_ptr lattice, double *south, const int subs, const int k, const int which_pdf); void process_reduce_double_sum( lattice_ptr lattice, double *arg_x); void process_reduce_int_sum( lattice_ptr lattice, int *arg_n); void process_barrier(); void process_finalize(); void process_exit( int exit_val); //############################################################################## // // Accessor methods for process struct. // int get_proc_id( lattice_ptr lattice); int get_num_procs( lattice_ptr lattice); int is_on_root_proc( lattice_ptr lattice); int get_g_LX( lattice_ptr lattice); int get_g_LY( lattice_ptr lattice); //3D int get_g_LZ( lattice_ptr lattice); int get_g_SX( lattice_ptr lattice); int get_g_SY( lattice_ptr lattice); //3D int get_g_SZ( lattice_ptr lattice); int get_g_EX( lattice_ptr lattice); int get_g_EY( lattice_ptr lattice); //3D int get_g_EZ( lattice_ptr lattice); int get_g_NumNodes( lattice_ptr lattice); int get_g_StartNode( lattice_ptr lattice); double g2lx( lattice_ptr lattice, double g_x); double g2ly( lattice_ptr lattice, double g_y); #if PARALLEL int get_g_SX( lattice_ptr lattice); int get_g_SY( lattice_ptr lattice); //3D int get_g_SZ( lattice_ptr lattice); int get_g_EX( lattice_ptr lattice); int get_g_EY( lattice_ptr lattice); //3D int get_g_EZ( lattice_ptr lattice); void set_g_LX( lattice_ptr lattice, const int arg_LX); void set_g_LY( lattice_ptr lattice, const int arg_LY); //3D void set_g_LZ( lattice_ptr lattice, const int arg_LZ); void set_g_SX( lattice_ptr lattice, const int arg_SX); void set_g_SY( lattice_ptr lattice, const int arg_SY); //3D void set_g_SZ( lattice_ptr lattice, const int arg_SZ); void set_g_EX( lattice_ptr lattice, const int arg_EX); void set_g_EY( lattice_ptr lattice, const int arg_EY); //3D void set_g_EZ( lattice_ptr lattice, const int arg_EZ); void set_g_NumNodes( lattice_ptr lattice, const int arg_NumNodes); void set_g_StartNode( lattice_ptr lattice, const int arg_n); #endif #endif
111pjb-one
src/process.h
C
gpl3
2,870
//############################################################################## // // Copyright (C), 2005, Michael Sukop and Danny Thorne // // runman.c // // - Run-time management // //void manage_body_force( lattice_ptr lattice) //############################################################################## // // M A N A G E B O D Y F O R C E // // - Reduce gravity to avoid run-away velocities and numerical // instability, if lattice->param.end_grav is specified. // inline void manage_body_force( lattice_ptr lattice) { #if MANAGE_BODY_FORCE int subs; double u[2]; double s; compute_ave_u( lattice, u, 0); s = sqrt( u[0]*u[0] + u[1]*u[1]); if( s > .0091 ) { lattice->param.gval[0][0] = 0.; } else { lattice->param.gval[0][0] = 0.00001; } for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { if( lattice->param.end_grav[subs] > 0.) { if( lattice->time >= lattice->param.end_grav[subs]) { if( lattice->param.gval[subs][0]<EPS) { lattice->param.gval[subs][0] = 0.; } else { lattice->param.gval[subs][0]/=2.; #if VERBOSITY_LEVEL>0 printf("subs %02d: gval_x = %f\n", subs, lattice->param.gval[subs][0]); #endif /* VERBOSITY_LEVEL>0 */ } if( lattice->param.gval[subs][1]<EPS) { lattice->param.gval[subs][1] = 0.; } else { lattice->param.gval[subs][1]/=2.; #if VERBOSITY_LEVEL>0 printf("subs %02d: gval_y = %f\n", subs, lattice->param.gval[subs][1]); #endif /* VERBOSITY_LEVEL>0 */ } } /* if( lattice->time>=lattice->param.end_grav[subs]) */ } /* if( lattice->param.end_grav[subs] > 0.) */ } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ #endif /* MANAGE_BODY_FORCE */ } /* void manage_body_force( lattice_ptr lattice) */ inline void run_man( lattice_ptr lattice) { manage_body_force( lattice); #if INAMURO_SIGMA_COMPONENT && STORE_BTC sigma_stuff( lattice); #endif /* INAMURO_SIGMA_COMPONENT && STORE_BTC */ } inline void dump( lattice_ptr lattice, int dump_num) { #if WRITE_PDF_DAT_FILES int time=get_time(lattice); if( 1 && time>=DELAY && !(time%get_FrameRate(lattice))) { dump_pdf( lattice, get_FrameRate(lattice)*1000*dump_num + time); } #endif /* WRITE_PDF_DAT_FILES */ }
111pjb-one
src/runman.c
C
gpl3
2,283