Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include group information in sampling_info for native sampling #1454

Merged
merged 9 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions amr-wind/utilities/sampling/Sampling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ void Sampling::impl_write_native()
return p.id() > 0;
});

const std::string info_name = name + "/sampling_info";
const std::string info_name = name + "/sampling_info.yaml";
write_info_file(info_name);

const std::string header_name = name + "/Header";
Expand Down Expand Up @@ -441,7 +441,15 @@ void Sampling::write_info_file(const std::string& fname)
amrex::FileOpenFailed(fname);
}

fh << "time " << m_sim.time().new_time() << std::endl;
// YAML formatting
fh << "time: " << m_sim.time().new_time() << std::endl;
fh << "samplers:" << std::endl;
for (int i = 0; i < m_samplers.size(); ++i) {
fh << " - index: " << i << std::endl;
fh << " label: " << m_samplers[i]->label() << std::endl;
fh << " type: " << m_samplers[i]->sampletype() << std::endl;
}

fh.close();
}

Expand Down
2 changes: 1 addition & 1 deletion docs/sphinx/user/inputs_Sampling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ input order), ``probe_id`` is the local probe id to this label,
``*co`` are the coordinates of the probe, and the other columns are
the user requested sampled fields. The same labels are seeing by other
visualization tools such as ParaView. The directory also contains a
``sampling_info`` file where additional information (e.g., time) is
``sampling_info.yaml`` YAML file where additional information (e.g., time) is
stored. This file is automatically parse by the provided particle
reader tool and the information is stored in a dictionary that is a
member variable of the class.
Expand Down
14 changes: 8 additions & 6 deletions tools/amrex_particle.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from pathlib import Path
import numpy as np
import pandas as pd
import yaml

class AmrexParticleFile:
"""AmrexParticleFile reader
Expand All @@ -36,7 +37,8 @@ def __init__(self, pdir):
pdir (path): Directory path
"""
self.pdir = Path(pdir)
assert self.pdir.exists()
if not self.pdir.exists():
raise ValueError(f'Path {self.pdir} does not exist.')

def __call__(self):
"""Parse the header and load all binary files
Expand Down Expand Up @@ -82,11 +84,11 @@ def parse_header(self):

def parse_info(self):
"""Parse the sampling info file"""
self.info = {}
with open(self.pdir.parent / "sampling_info", 'r') as fh:
for line in fh:
(key, val) = line.split()
self.info[key] = float(val)
with open(self.pdir.parent / "sampling_info.yaml", 'r') as fh:
try:
self.info = yaml.safe_load(fh)
except yaml.YAMLError as exc:
print(exc)

def load_binary_data(self):
"""Read binary data into memory"""
Expand Down