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
Adding parsing for double indexed/separated fields #6459
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -649,6 +649,9 @@ template<> | |
void Parser::setVectorParameter<VariableName>(const std::string & full_name, const std::string & short_name, | ||
InputParameters::Parameter<std::vector<VariableName> > * param, bool in_global, GlobalParamsAction * global_block); | ||
|
||
template<> | ||
void Parser::setDoubleIndexParameter<VariableName>(const std::string & full_name, const std::string & short_name, | ||
InputParameters::Parameter<std::vector<std::vector<VariableName> > >* param, bool /*in_global*/, GlobalParamsAction * /*global_block*/); | ||
|
||
// Macros for parameter extraction | ||
#define dynamicCastAndExtractScalar(type, param, full_name, short_name, in_global, global_block) \ | ||
|
@@ -675,6 +678,14 @@ void Parser::setVectorParameter<VariableName>(const std::string & full_name, con | |
setVectorParameter<type>(full_name, short_name, vector_p, in_global, global_block); \ | ||
} while (0) | ||
|
||
#define dynamicCastAndExtractDoubleIndex(type, param, full_name, short_name, in_global, global_block) \ | ||
do \ | ||
{ \ | ||
InputParameters::Parameter<std::vector<std::vector<type> > > * double_index_p = dynamic_cast<InputParameters::Parameter<std::vector<std::vector<type> > > *>(param); \ | ||
if (double_index_p) \ | ||
setDoubleIndexParameter<type>(full_name, short_name, double_index_p, in_global, global_block); \ | ||
} while (0) | ||
|
||
void | ||
Parser::extractParams(const std::string & prefix, InputParameters &p) | ||
{ | ||
|
@@ -834,6 +845,41 @@ Parser::extractParams(const std::string & prefix, InputParameters &p) | |
dynamicCastAndExtractVector(OutputName , it->second, full_name, it->first, in_global, global_params_block); | ||
dynamicCastAndExtractVector(MaterialPropertyName , it->second, full_name, it->first, in_global, global_params_block); | ||
dynamicCastAndExtractVector(DiscreteMaterialName , it->second, full_name, it->first, in_global, global_params_block); | ||
|
||
/** | ||
* Double indexed types | ||
*/ | ||
// built-ins | ||
dynamicCastAndExtractDoubleIndex(Real , it->second, full_name, it->first, in_global, global_params_block); | ||
dynamicCastAndExtractDoubleIndex(int , it->second, full_name, it->first, in_global, global_params_block); | ||
dynamicCastAndExtractDoubleIndex(long , it->second, full_name, it->first, in_global, global_params_block); | ||
dynamicCastAndExtractDoubleIndex(unsigned int , it->second, full_name, it->first, in_global, global_params_block); | ||
// See vector type explanation | ||
#if LIBMESH_DOF_ID_BYTES == 8 | ||
dynamicCastAndExtractDoubleIndex(uint64_t , it->second, full_name, it->first, in_global, global_params_block); | ||
#endif | ||
|
||
dynamicCastAndExtractDoubleIndex(SubdomainID , it->second, full_name, it->first, in_global, global_params_block); | ||
dynamicCastAndExtractDoubleIndex(BoundaryID , it->second, full_name, it->first, in_global, global_params_block); | ||
|
||
// Moose String-derived vectors | ||
dynamicCastAndExtractDoubleIndex(/*std::*/string , it->second, full_name, it->first, in_global, global_params_block); | ||
dynamicCastAndExtractDoubleIndex(FileName , it->second, full_name, it->first, in_global, global_params_block); | ||
dynamicCastAndExtractDoubleIndex(FileNameNoExtension , it->second, full_name, it->first, in_global, global_params_block); | ||
dynamicCastAndExtractDoubleIndex(MeshFileName , it->second, full_name, it->first, in_global, global_params_block); | ||
dynamicCastAndExtractDoubleIndex(SubdomainName , it->second, full_name, it->first, in_global, global_params_block); | ||
dynamicCastAndExtractDoubleIndex(BoundaryName , it->second, full_name, it->first, in_global, global_params_block); | ||
// reading double indexed Variable name is problematic because Coupleable assumes they come as vectors | ||
// therefore they not included in this list | ||
dynamicCastAndExtractDoubleIndex(FunctionName , it->second, full_name, it->first, in_global, global_params_block); | ||
dynamicCastAndExtractDoubleIndex(UserObjectName , it->second, full_name, it->first, in_global, global_params_block); | ||
dynamicCastAndExtractDoubleIndex(IndicatorName , it->second, full_name, it->first, in_global, global_params_block); | ||
dynamicCastAndExtractDoubleIndex(MarkerName , it->second, full_name, it->first, in_global, global_params_block); | ||
dynamicCastAndExtractDoubleIndex(MultiAppName , it->second, full_name, it->first, in_global, global_params_block); | ||
dynamicCastAndExtractDoubleIndex(PostprocessorName , it->second, full_name, it->first, in_global, global_params_block); | ||
dynamicCastAndExtractDoubleIndex(VectorPostprocessorName, it->second, full_name, it->first, in_global, global_params_block); | ||
dynamicCastAndExtractDoubleIndex(OutputName , it->second, full_name, it->first, in_global, global_params_block); | ||
dynamicCastAndExtractDoubleIndex(MaterialPropertyName , it->second, full_name, it->first, in_global, global_params_block); | ||
} | ||
} | ||
|
||
|
@@ -931,6 +977,45 @@ void Parser::setVectorParameter(const std::string & full_name, const std::string | |
} | ||
} | ||
|
||
|
||
template<typename T> | ||
void Parser::setDoubleIndexParameter(const std::string & full_name, const std::string & short_name, InputParameters::Parameter<std::vector<std::vector<T> > >* param, bool in_global, GlobalParamsAction * global_block) | ||
{ | ||
GetPot *gp; | ||
|
||
// See if this variable was passed on the command line | ||
// if it was then we will retrieve the value from the command line instead of the file | ||
if (_app.commandLine() && _app.commandLine()->haveVariable(full_name.c_str())) | ||
gp = _app.commandLine()->getPot(); | ||
else | ||
gp = &_getpot_file; | ||
|
||
// Get the full string assigned to the variable full_name | ||
std::string buffer = gp->get_value_no_default(full_name, ""); | ||
|
||
// split vector at delim ; | ||
// NOTE: the substrings are _not_ of type T yet | ||
std::vector<std::string> first_tokenized_vector; | ||
MooseUtils::tokenize(buffer, first_tokenized_vector, 1, ";"); | ||
param->set().resize(first_tokenized_vector.size()); | ||
|
||
for (unsigned j = 0; j < first_tokenized_vector.size(); ++j) | ||
if (!MooseUtils::tokenizeAndConvert<T>(first_tokenized_vector[j], param->set()[j])) | ||
mooseError("Reading parameter " << short_name << " failed."); | ||
|
||
if (in_global) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this is a WIP but this will definitely need to be filled out before you are done. |
||
global_block->remove(short_name); | ||
global_block->setDoubleIndexParam<T>(short_name).resize(first_tokenized_vector.size()); | ||
for (unsigned j = 0; j < first_tokenized_vector.size(); ++j) | ||
{ | ||
global_block->setDoubleIndexParam<T>(short_name)[j].resize(param->get()[j].size()); | ||
for (unsigned int i = 0; i < param->get()[j].size(); ++i) | ||
global_block->setDoubleIndexParam<T>(short_name)[j][i] = param->get()[j][i]; | ||
} | ||
} | ||
} | ||
|
||
template<typename T> | ||
void Parser::setScalarComponentParameter(const std::string & full_name, const std::string & short_name, InputParameters::Parameter<T> * param, bool in_global, GlobalParamsAction * global_block) | ||
{ | ||
|
@@ -1204,6 +1289,8 @@ void Parser::setVectorParameter<VariableName>(const std::string & full_name, con | |
|
||
// If we are able to convert this value into a Real, then set a default coupled value | ||
if (ss >> real_value && ss.eof()) | ||
// FIXME: the real_value is assigned to defaultCoupledValue overriding the value assigned before. | ||
// Currently there is no functionality to separately assign the correct "real_value[i]" in InputParameters | ||
_current_params->defaultCoupledValue(short_name, real_value); | ||
else | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/****************************************************************/ | ||
/* DO NOT MODIFY THIS HEADER */ | ||
/* MOOSE - Multiphysics Object Oriented Simulation Environment */ | ||
/* */ | ||
/* (c) 2010 Battelle Energy Alliance, LLC */ | ||
/* ALL RIGHTS RESERVED */ | ||
/* */ | ||
/* Prepared by Battelle Energy Alliance, LLC */ | ||
/* Under Contract No. DE-AC07-05ID14517 */ | ||
/* With the U. S. Department of Energy */ | ||
/* */ | ||
/* See COPYRIGHT for full restrictions */ | ||
/****************************************************************/ | ||
|
||
#ifndef READDOUBLEINDEX_H | ||
#define READDOUBLEINDEX_H | ||
|
||
#include "GeneralUserObject.h" | ||
|
||
class ReadDoubleIndex; | ||
|
||
template<> | ||
InputParameters validParams<ReadDoubleIndex>(); | ||
|
||
|
||
/** | ||
* User Object for testing double index parsing | ||
*/ | ||
class ReadDoubleIndex : public GeneralUserObject | ||
{ | ||
public: | ||
ReadDoubleIndex(const InputParameters & params); | ||
|
||
virtual void initialize() {}; | ||
virtual void execute(); | ||
virtual void finalize() {}; | ||
|
||
protected: | ||
const std::vector<std::vector<Real> > & _real_di; | ||
const std::vector<std::vector<unsigned int> > & _uint_di; | ||
const std::vector<std::vector<int> > & _int_di; | ||
const std::vector<std::vector<long> > & _long_di; | ||
const std::vector<std::vector<SubdomainID> > & _subid_di; | ||
const std::vector<std::vector<BoundaryID> > & _bid_di; | ||
|
||
const std::vector<std::vector<std::string> > & _str_di; | ||
const std::vector<std::vector<FileName> > & _file_di; | ||
const std::vector<std::vector<FileNameNoExtension> > & _file_no_di; | ||
|
||
const std::vector<std::vector<MeshFileName> > & _mesh_file_di; | ||
const std::vector<std::vector<SubdomainName> > & _subdomain_name_di; | ||
const std::vector<std::vector<BoundaryName> > & _boundary_name_di; | ||
const std::vector<std::vector<FunctionName> > & _function_name_di; | ||
const std::vector<std::vector<UserObjectName> > & _userobject_name_di; | ||
const std::vector<std::vector<IndicatorName> > & _indicator_name_di; | ||
|
||
const std::vector<std::vector<MarkerName> > & _marker_name_di; | ||
const std::vector<std::vector<MultiAppName> > & _multiapp_name_di; | ||
const std::vector<std::vector<PostprocessorName> > & _postprocessor_name_di; | ||
const std::vector<std::vector<VectorPostprocessorName> > & _vector_postprocessor_name_di; | ||
const std::vector<std::vector<OutputName> > & _output_name_di; | ||
const std::vector<std::vector<MaterialPropertyName> > & _material_property_name_di; | ||
|
||
}; | ||
|
||
|
||
#endif /* ReadDoubleIndex_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I want to support every type in the double syntax. It's unlikely that we'll use very many of them. I'd suggest we add the types you want and leave the rest out until there's a use case and better yet, a test case to support them.