Skip to content

Automatic Import of Shading from a CSV File#6388

Merged
Myoldmopar merged 14 commits intodevelopfrom
AutoImportExtShading
Feb 20, 2018
Merged

Automatic Import of Shading from a CSV File#6388
Myoldmopar merged 14 commits intodevelopfrom
AutoImportExtShading

Conversation

@xuanluo113
Copy link
Copy Markdown
Contributor

Pull request overview

EnergyPlus version 8.8 added features to export the calculated shading results to an external CSV file, and allow to use shading schedules to replace internal shading calculations for exterior surfaces.
Although the shading schedules can be imported from external CSV files, there needs to define all these schedules in IDF files explicitly as well as adding SurfaceProperty:LocalEnvironment objects for all exterior surfaces, which can be a significant burden for users especially for a model with many exterior surfaces. The proposed new feature will fully automate the process.

Work Checklist

Add to this list or remove from it as applicable. This is a simple templated set of guidelines.

  • Title of PR should be user-synopsis style (clearly understandable in a standalone changelog context)
  • At least one of the following appropriate labels must be added to this PR to be consumed into the changelog:
    • Defect: This pull request repairs a github defect issue. The github issue should be referenced in the PR description
    • Refactoring: This pull request includes code changes that don't change the functionality of the program, just perform refactoring
    • NewFeature: This pull request includes code to add a new feature to EnergyPlus
    • Performance: This pull request includes code changes that are directed at improving the runtime performance of EnergyPlus
    • DoNoPublish: This pull request includes changes that shouldn't be included in the changelog

Review Checklist

This will not be exhaustively relevant to every PR.

  • Code style (parentheses padding, variable names)
  • Functional code review (it has to work!)
  • If defect, results of running current develop vs this branch should exhibit the fix
  • CI status: all green or justified
  • Performance: CI Linux results include performance check -- verify this
  • Unit Test(s)
  • C++ checks:
    • Argument types
    • If any virtual classes, ensure virtual destructor included, other things
  • IDD changes:
    • Verify naming conventions and styles, memos and notes and defaults
    • Open windows IDF Editor with modified IDD to check for errors
    • If transition, add rules to spreadsheet
    • If transition, add transition source
    • If transition, update idfs
  • If new idf included, locally check the err file and other outputs
  • Documentation changes in place
  • Changed docs build successfully
  • ExpandObjects changes?
  • If output changes, including tabular output structure, add to output rules file for interfaces

@nealkruis
Copy link
Copy Markdown
Member

@XuanLuoLBL @hongtz68

  1. I think we should have a brainstorm on the best file format for caching shading results and consider something that can be transferred between tools (e.g., importing shading calculations performed in an external tool). CSV is easy to understand, but it is not as easy to standardize. Maybe something like JSON/CBOR that can be validated against a schema.
  2. I assume the proposed time series values are intended to represent shading of direct beam radiation. What about the values of diffuse shading from the various grid points in the sky dome?

@xuanluo113
Copy link
Copy Markdown
Contributor Author

@nealkruis

  1. CSV files are used in EnergyPlus to import schedules. We prefer to using the same approach. In future other formats can be added as needed.
  2. We are propoping to overwrite both direct and diffused solar gains using SunlitFrac:
    For direct solar gain
// Incident direct (unreflected) beam
QRadSWOutIncidentBeam( SurfNum ) = BeamSolar * SunlitFrac( TimeStep, HourOfDay, SurfNum2 ) * CosInc;

For diffused solar gain:
https://www.energyplus.net/sites/default/files/docs/site_v8.3.0/EngineeringReference/05-Climate/index.html#shadowing-of-sky-diffuse-solar-radiation

Wondering if that's right.

@nealkruis
Copy link
Copy Markdown
Member

@XuanLuoLBL. Yes, that is the right section for diffuse solar shading (though a more up-to-date version is here). In order to cache shading for a surface, you'll need:

  • direct solar shading fractions for each timestep and each calculation period (e.g., every 30 days). Potentially, one for each timestep of the year (~50,000 for 10 min. timesteps and daily calculations).
  • diffuse shading fractions for each grid in the sky model (24 azimuths x 6 altitudes). Note: these are independent of timestep

There's also an additional question about whether you'll need to handle exterior reflections (though I'd suggest continue performing those calculations internally).

For the large models where caching would be really beneficial, you'll potentially need to cache on the order of 52 million double precision values (1,000 exterior surfaces x 144 diffuse shading fractions + 1,000 surfaces x ~50,000 timestep solar fractions). I would like to have a better sense of the storage and IO read performance implications of different file storage formats (namely CSV vs. binary) for this magnitude of data.

@Myoldmopar
Copy link
Copy Markdown
Member

@nealkruis For those huge cases, where you are talking on the order of 50 million values to be stored, the storage doesn't bother me too much. Users should understand that when they do big models, they will need storage. I guess we could try to warn them by estimating the size of the cached file and checking available file system capacity...

Processing that file makes me cringe a little, but not to the point of requiring a binary format. By using the cached shading values, the user should experience a major improvement in runtime compared to recalculation. Any additional gains from a switch to binary during reading should pale in comparison to the overall gain. And I really don't want EnergyPlus to have to manage our own binary files when it's not a necessary step.

My main concern is when you mentioned standardizing. @XuanLuoLBL, yeah E+ does currently read schedules from CSV. But we are trying to move forward in the world, with the impending JSON input format, and now the JSON-based G-Function caching for ground heat exchangers. My strong preference here would be to create a nicely structured JSON format for these values, such that we don't have to rely on a predetermined column order in a huge csv file during export/import. I do understand that raw JSON will carry some additional burden over CSV, but as long as we are smart with the JSON structure, the read time penalty should still be small compared to the overall massive gains of this project.

@mjwitte mjwitte added NewFeature Includes code to add a new feature to EnergyPlus IDDChange Code changes impact the IDD file (cannot be merged after IO freeze) labels Dec 11, 2017
@nrel-bot-3
Copy link
Copy Markdown

@XuanLuoLBL @lgentile it has been 14 days since this pull request was last updated.

@nrel-bot
Copy link
Copy Markdown

@XuanLuoLBL @lgentile it has been 16 days since this pull request was last updated.

@nrel-bot
Copy link
Copy Markdown

nrel-bot commented Feb 7, 2018

@XuanLuoLBL @lgentile it has been 17 days since this pull request was last updated.

@xuanluo113 xuanluo113 self-assigned this Feb 7, 2018
Copy link
Copy Markdown
Member

@Myoldmopar Myoldmopar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@XuanLuoLBL This is pretty close, but I made a few comments that should be addressed. The main one is the JSON comments. I was hoping the code would be set up so that we could easily add JSON to this at a later date. It is added to the IDD and docs in this pull request, appearing to indicate it is already available and implemented, which I don't think it is. We should remove it from those user-facing interfaces until we actually have JSON available. If you can clean that up and address my other comments, this should be good to go in. Testing now...

A2 ; \field File Format
\type choice
\key CSV
\key JSON
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, what? Can this do JSON?? If this is just a placeholder option for later that isn't implemented, then it needs to go away.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It's a placeholder as we discussed for the NFP. I can remove it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During the NFP stage, I wanted the code to be written so that later it would be easy to add JSON. We can't have things in the IDD that the user sees that aren't true. Sorry for the confusion.


Schedule:File:Shading,
\min-fields 1
\memo A Schedule:File:Shading points to a text computer file that has
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably want to reword this, don't need to say "computer file". And instead of text file, how about CSV file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is word for Schedule:File object and confused me as well... Modified.

Schedule:File:Shading,
\min-fields 1
\memo A Schedule:File:Shading points to a text computer file that has
\memo hourly/sub-hourly sunlit fraction data for all exterior surfaces.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not really for "all" exterior surfaces though, right? In the design/documentation it says that if surfaces are missing, they are simply not shaded.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@XuanLuoLBL If sub-hourly data are allowed, do you force fixed time interval step or allow flexible time interval. Please specify it clearly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lgu1234 Sorry not sub-hourly... Not necessary for sunlit fraction. Modified the text.

ShowContinueError( "Try again with putting full path and file name in the field." );
ErrorsFound = true;
} else {
SchdFile = GetNewUnitNumber();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is how it's done in other places of the code, but I wish I would've seen this earlier and directed to not use this approach. This file reading approach is simply a carryover from the Fortran days, and using C++ file streams would've been a nice thing to do instead. But it's a bit late now and not worth holding this up.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I wish I could see this earlier. I thought I should use familiar code to keep the same pattern, as we do everything else.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@XuanLuoLBL @Myoldmopar See #6482 followup issue to revise this.

}
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I didn't see in there where you actually added JSON. What I had requested previously was for the code to be set up so that once we added JSON, it would be very easy to modify this code to also read JSON inputs. But as the JSON world isn't in here yet, we need to remove the option from the IDD and docs. (Unless I somehow missed the JSON reading in here and it actually does work...)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Not ready. My misunderstanding. But yes here it is for when we can actually add JSON in the future.


// C++ Headers
#include <map>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there a reason you needed to include this here? I don't see any of your changes needing it. If you need it in the .cc file, go ahead and put it over there, not in the .hh file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right.

using DataSystemVariables::iUnicode_end;
using DataSystemVariables::TempFullFileName;
using DataSystemVariables::CheckForActualFileName;
using DataSystemVariables::UseImportedSunlitFrac;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't being used in this function and is throwing the build warning. That will clean up CI some.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaned.

@Myoldmopar
Copy link
Copy Markdown
Member

Regarding CI:

  • I commented about the build warning. That will be easy to fix.
  • The test failure is because your example file for importing scheduled shading is expecting to find those files next to the test file during the run, but CI doesn't know that it needs to bring that file along when it sets up the run folders. You will have to modify the CMake run script at cmake/ProjectMacros.cmake to bring in that external file dependency. It's a very lightweight file, so as a first pass, you could just add the CMake code to always bring it in, regardless of the file being tested. Then if that works, you could add a CMake option so it only does it for your particular file.

Also, I built locally, and just ran the ExternalShading example file, and my eplusshading.csv is empty. Is that normal?

Schedule:File:Shading,
\min-fields 1
\memo A Schedule:File:Shading points to a text computer file that has
\memo hourly/sub-hourly sunlit fraction data for all exterior surfaces.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@XuanLuoLBL If sub-hourly data are allowed, do you force fixed time interval step or allow flexible time interval. Please specify it clearly.

// create string of which day of year
++iDay;
++hDay;
if ( iDay > 366 ) break;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@XuanLuoLBL Do you allow data with 6 month? For example, the run period is from Jan. 1 to Jun 60. Can I have a data file with hourly values in 6 months?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No... Not specified here. I added in the doc it has to be 8760-8764.

@Myoldmopar Myoldmopar added this to the EnergyPlus 8.9.0 milestone Feb 14, 2018
@Myoldmopar
Copy link
Copy Markdown
Member

@XuanLuoLBL

@lgu1234 and myself made a number of requested changes to this branch 3 days ago. You have not responded to any of them. Considering we are so late, this is in danger of not making the cutoff unless you address them right away.

@Myoldmopar Myoldmopar modified the milestones: EnergyPlus 8.9.0, EnergyPlus Next Feb 17, 2018
@xuanluo113
Copy link
Copy Markdown
Contributor Author

@Myoldmopar I'm not very familiar with the this CI CMake. Would you mind using some more specific word for "bring in that external file dependency". I don't see any chunk does similar things.

@xuanluo113
Copy link
Copy Markdown
Contributor Author

The example file for this PR is _ImportShading. Not ExternalShading.

@mjwitte mjwitte modified the milestones: EnergyPlus Next, EnergyPlus 8.9.0 Feb 19, 2018
…ExtShading

Conflicts:
	src/EnergyPlus/DataSystemVariables.cc
	src/EnergyPlus/DataSystemVariables.hh
	src/EnergyPlus/SolarShading.cc
	testfiles/CMakeLists.txt
Copy link
Copy Markdown
Contributor

@mjwitte mjwitte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be ready to merge if CI comes back clean.

ShowContinueError( "Try again with putting full path and file name in the field." );
ErrorsFound = true;
} else {
SchdFile = GetNewUnitNumber();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@XuanLuoLBL @Myoldmopar See #6482 followup issue to revise this.

ErrorsFound = true;
} else {
SchdFile = GetNewUnitNumber();
{ IOFlags flags; flags.ACTION( "read" ); gio::open( SchdFile, ShadingSunlitFracFileName, flags ); read_stat = flags.ios(); }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@XuanLuoLBL This needs to use TempFullFileName here because the file could be in a number of different places. I'll fix this.

@mjwitte
Copy link
Copy Markdown
Contributor

mjwitte commented Feb 20, 2018

This needs a clear_state (well, the other shading thing need it, but adding it here). Will push shortly. Then this should be ready to drop in.

@Myoldmopar
Copy link
Copy Markdown
Member

👍 Thanks @mjwitte

@Myoldmopar
Copy link
Copy Markdown
Member

And develop just moved with the other PRs. I considered saying just push your changes and we'll merge it but I think since clear_states can cause issues, we should let CI play this one all the way out. Make sure to pull develop before pushing and when CI is totally happy it can drop in.

@xuanluo113
Copy link
Copy Markdown
Contributor Author

Thanks so much! @mjwitte

@mjwitte
Copy link
Copy Markdown
Contributor

mjwitte commented Feb 20, 2018

@XuanLuoLBL If you can, please review the file diffs on this PR. I had to resolve some merge conflicts after the other shading feature dropped in. It would be good if you can make sure I didn't break anything when resolving the conflicts.

@xuanluo113
Copy link
Copy Markdown
Contributor Author

@mjwitte Sure.

@xuanluo113
Copy link
Copy Markdown
Contributor Author

@mjwitte Seems good. I don't see anything missed conflict in IDD and code. All data sys vars are still there.

@mjwitte
Copy link
Copy Markdown
Contributor

mjwitte commented Feb 20, 2018

Thanks for checking. This will drop in once CI finishes.

@mjwitte
Copy link
Copy Markdown
Contributor

mjwitte commented Feb 20, 2018

Ack - the new test file is failing on linux debug. @Myoldmopar please run on linux and see what's up.

@mjwitte
Copy link
Copy Markdown
Contributor

mjwitte commented Feb 20, 2018

@Myoldmopar @XuanLuoLBL Found the problem - nan's when checking the file max/min. Leap year logic needs review - see #6482 . For now, data file lengthened to 8784 data rows.

@Myoldmopar
Copy link
Copy Markdown
Member

All good now, merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

IDDChange Code changes impact the IDD file (cannot be merged after IO freeze) NewFeature Includes code to add a new feature to EnergyPlus

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants