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

Allow data probes to sample with temporal freq #56

Merged
merged 1 commit into from
Nov 14, 2018
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
11 changes: 10 additions & 1 deletion include/DataProbePostProcessing.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class Realm;
class Transfer;
class Transfers;

enum class DataProbeSampleType{
STEPCOUNT,
APRXFREQUENCY
};

class DataProbeInfo {
public:
DataProbeInfo() { }
Expand Down Expand Up @@ -130,7 +135,7 @@ class DataProbePostProcessing
Realm &realm_;

// frequency of output
int outputFreq_;
double outputFreq_;

// width for output
int w_;
Expand All @@ -150,9 +155,13 @@ class DataProbePostProcessing
// hold the transfers
Transfers *transfers_;


DataProbeSampleType probeType_;

private:
std::unique_ptr<stk::io::StkMeshIoBroker> io;

double previousTime_;
bool useExo_{false};
std::string exoName_;
size_t fileIndex_;
Expand Down
32 changes: 29 additions & 3 deletions src/DataProbePostProcessing.C
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ DataProbePostProcessing::DataProbePostProcessing(
searchMethodName_("none"),
searchTolerance_(1.0e-4),
searchExpansionFactor_(1.5),
probeType_(DataProbeSampleType::STEPCOUNT),
previousTime_(0.0),
exoName_("data_probes.exo")
{
// load the data
Expand Down Expand Up @@ -133,6 +135,18 @@ DataProbePostProcessing::load(

get_if_present(y_dataProbe, "output_frequency", outputFreq_, outputFreq_);

get_if_present(y_dataProbe, "begin_sampling_after", previousTime_, previousTime_);

bool sampleInTime = false;
get_if_present(y_dataProbe, "sample_based_on_time", sampleInTime, sampleInTime);
probeType_ = sampleInTime ? DataProbeSampleType::APRXFREQUENCY : DataProbeSampleType::STEPCOUNT;

if(outputFreq_ != static_cast<int>(outputFreq_)
&& probeType_==DataProbeSampleType::STEPCOUNT)
{
throw std::runtime_error("output_frequency must be an integer unless sample_based_on_time: on");
}

// transfer specifications
get_if_present(y_dataProbe, "search_method", searchMethodName_, searchMethodName_);
get_if_present(y_dataProbe, "search_tolerance", searchTolerance_, searchTolerance_);
Expand Down Expand Up @@ -205,7 +219,7 @@ DataProbePostProcessing::load(
// name; which is the part name of choice
const YAML::Node nameNode = y_los["name"];
if ( nameNode )
probeInfo->partName_[ilos] = nameNode.as<std::string>() ;
probeInfo->partName_[ilos] = nameNode.as<std::string>() ;
else
throw std::runtime_error("DataProbePostProcessing: lacking the name");

Expand Down Expand Up @@ -468,7 +482,7 @@ DataProbePostProcessing::initialize()

const int numPoints = probeInfo->numPoints_[j];
for ( int p = 0; p < nDim; ++p )
dx[p] = (tipC[p] - tailC[p])/(double)(numPoints-1);
dx[p] = (tipC[p] - tailC[p])/(double)(std::max(numPoints-1,1));

// now populate the coordinates; can use a simple loop rather than buckets
for ( size_t n = 0; n < nodeVec.size(); ++n ) {
Expand Down Expand Up @@ -626,7 +640,19 @@ DataProbePostProcessing::execute()
// only do work if this is an output step
const double currentTime = realm_.get_current_time();
const int timeStepCount = realm_.get_time_step_count();
const bool isOutput = timeStepCount % outputFreq_ == 0;
bool isOutput = false;
switch (probeType_){
case DataProbeSampleType::STEPCOUNT:
isOutput = timeStepCount % static_cast<int>(outputFreq_) == 0;
break;
case DataProbeSampleType::APRXFREQUENCY:
isOutput = currentTime>=previousTime_+outputFreq_;
previousTime_ = isOutput ? currentTime : previousTime_;
break;
default:
std::runtime_error("A DataProbe was not assigned a type.");
break;
}

if ( isOutput ) {
// execute and provide results...
Expand Down