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

General Vector Transfer Support V3 #92

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
7ab53db
Revert "Merge pull request #79 from aurora-multiphysics/revert-75-Edw…
Feb 1, 2024
fc1454f
Renamed "ApolloApp" namespace to "Apollo" to avoid clashes with Apoll…
Feb 1, 2024
88e0f73
Revert "Renamed "ApolloApp" namespace to "Apollo" to avoid clashes wi…
Feb 1, 2024
e91bbc5
Renaemd "ApolloApp" namespace to "Apollo" to avoid clashes.
Feb 1, 2024
17ee6c2
Fixed incorrect subapp specified in input file.
Feb 1, 2024
2e22547
Registered MultiAppShapeEvaluationTransferVector.
Feb 1, 2024
381f177
Added push/pull test cases for shape evaluation transfers.
Feb 2, 2024
b52d488
Added MultiAppGeneralFieldShapeEvaluationTransfer vector support.
Feb 2, 2024
6e90101
Converted ShapeEvaluationTransfer tests to GeneralFieldShapeEvaluatio…
Feb 2, 2024
43a09e2
Removed support for deprecated MultiAppShapeEvaluationTransfer.
Feb 2, 2024
c36620f
Removed support for MultiAppCopyTransfer since it can now support vec…
Feb 2, 2024
b19e349
Merge branch 'master' into EdwardPalmer99/MultiApp-Vector-Transfer-Ac…
alexanderianblair Mar 5, 2024
4f2a5ae
Merge branch 'master' into EdwardPalmer99/MultiApp-Vector-Transfer-Ac…
EdwardPalmer99 Apr 9, 2024
b21cbb1
Fixed a nasty bug where the incorrect factory was used to create auxk…
May 16, 2024
8d58a5e
Purged use of _factory which could result in incorrect input paramete…
May 16, 2024
35d9455
Merged master; updated hephaestus version.
May 16, 2024
7de4772
Merge branch 'master' into EdwardPalmer99/MultiApp-Vector-Transfer-Ac…
May 16, 2024
c2a2cf8
Removed csv files accidentally added to src directory.
May 17, 2024
0d89309
Renamed test/tests/unit/actions to test/tests/unit/vector_transfers.
May 17, 2024
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
227 changes: 227 additions & 0 deletions include/actions/AddVectorTransferAction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
#pragma once

#include "MooseObjectAction.h"
#include "AuxiliarySystem.h"

class AddVectorTransferAction : public MooseObjectAction
{
public:
static InputParameters validParams();

AddVectorTransferAction(const InputParameters & params);

virtual void act() override;

protected:
/**
* Returns a shared pointer to or from the multiapp.
*/
const std::shared_ptr<MultiApp> getFromMultiApp() const;
const std::shared_ptr<MultiApp> getToMultiApp() const;

/**
* Returns to/from problem variable names.
*/
const std::vector<VariableName> & getFromVarNames() const;
const std::vector<AuxVariableName> & getToVarNames() const;

const std::vector<VariableName> & getFromVarNamesConverted();
const std::vector<AuxVariableName> & getToVarNamesConverted();

/**
* An enumeration used internally to specify the component of a vector variable.
*/
enum class VectorComponent
{
X,
Y,
Z
};

/**
* An enumeration used to specify the auxkernel to build.
*/
enum class VectorAuxKernelType
{
PREPARE_VECTOR_FOR_TRANSFER,
RECOVER_VECTOR_POST_TRANSFER
};

/**
* Finds the FEProblemBase depending on the direction.
*/
FEProblemBase & getFromProblem() const;
FEProblemBase & getToProblem() const;

/**
* Returns references to the auxsystem.
*/
AuxiliarySystem & getFromAuxSystem() const;
AuxiliarySystem & getToAuxSystem() const;

/**
* Adds a vector auxkernel to the problem.
*/
void
addVectorAuxKernel(FEProblemBase & problem, std::string & vector_name, VectorAuxKernelType type);

/**
* This method is called internally to locate all vector variables. For each vector variable
* it locates, it will create standard scalar variables. When the methods getFromVarNames()
* and getToVarNames() are called, they will return a vector containing only the standard
* variable names.
*/
void convertAllVariables();

/**
* This method will iterate through the variable names. If the variable associated with the name
* happens to be a vector variable, the standard variables for its components will be created.
* Returns a vector containing the updated variable names (adding all new standard variables and
* removing any vector variables).
*/
template <class VariableNameClassType>
std::vector<VariableNameClassType>
convertVariables(FEProblemBase & problem,
std::vector<VariableNameClassType> & input_variable_names);

/**
* This method verifies that source_type is a valid parameter. If it is and there is at least one
* vector variable supplied then we need to duplicate its source type for the new standard
* variable components.
*/
void convertSourceTypes();

/**
* Returns true is "source_type" is a valid parameter.
*/
bool hasSourceTypesParameter() const;

/**
* Returns a reference to a vector of converted source types.
*/
std::vector<MooseEnum> & getSourceTypeConverted();

/**
* Returns all vector source variable names.
*/
std::set<std::string> & getVectorSourceNames();

/**
* Returns true if variable name corresponds to a source vector variable.
*/
bool isSourceVectorVariable(const std::string & var_name);

/**
* Creates component standard variables for the x, y and z components of a vector variable.
*/
void buildVectorComponents(FEProblemBase & problem, MooseVariableFEBase & vector_variable);

/**
* Returns the extension for a given vector component.
*/
std::string buildVectorComponentExtension(VectorComponent component) const;
/**
* Creates the FEType of a variable corresponding to a component of a vector variable.
*/
InputParameters buildInputParametersForComponents(FEProblemBase & problem,
MooseVariableFEBase & vector_variable) const;

/**
* Check whether the variable is a vector variable of the supported family/order.
*/
bool isSupportedVectorVariable(MooseVariableFEBase & vector_variable) const;

/**
* Check whether the component variable is of a valid family.
*/
bool isSupportedComponentVariable(MooseVariableFEBase & variable) const;

/**
* Checks whether a vector variable is compatible with a component variable.
*/
bool areCompatibleVariables(MooseVariableFEBase & vector_variable,
MooseVariableFEBase & component_variable) const;

bool isPushTransfer() const;
bool isPullTransfer() const;
bool isSupportedTransfer() const;

/**
* Helper methods.
*/
MooseVariableFEBase &
getVariable(FEProblemBase & problem,
std::string & variable_name,
Moose::VarFieldType type = Moose::VarFieldType::VAR_FIELD_ANY) const;

/**
* Returns components of the enum class. This allows iterating over the components.
*/
std::array<VectorComponent, 3> getAllComponents() const;

/**
* Creates the name of the variable corresponding to a component of a vector variable.
*/
inline std::string buildVectorComponentName(const std::string & vector_name,
VectorComponent component) const;

/**
* Creates the type name of the transfer suitable for vector variables.
*/
inline std::string buildVectorTransferTypeName(const std::string & transfer_type) const;

/**
* Returns family/order of variable.
*/
inline libMesh::FEFamily getVariableFamily(const MooseVariableFEBase & variable) const;
inline libMesh::Order getVariableOrder(const MooseVariableFEBase & variable) const;

private:
// Names of all source vector variables.
std::set<std::string> _vector_source_names;

// New variable names.
std::vector<VariableName> _from_var_names_converted;
std::vector<AuxVariableName> _to_var_names_converted;

// New source types (if present).
std::vector<MooseEnum> _source_type_converted;

bool _has_converted_variables;
bool _has_converted_source_types;
};

inline std::string
AddVectorTransferAction::buildVectorComponentName(const std::string & vector_name,
VectorComponent component) const
{
return (vector_name + buildVectorComponentExtension(component));
}

inline std::string
AddVectorTransferAction::buildVectorTransferTypeName(const std::string & transfer_type) const
{
return (transfer_type + "Vector");
}

inline std::array<AddVectorTransferAction::VectorComponent, 3>
AddVectorTransferAction::getAllComponents() const
{

std::array<VectorComponent, 3> components = {
VectorComponent::X, VectorComponent::Y, VectorComponent::Z};

return components;
}

inline libMesh::FEFamily
AddVectorTransferAction::getVariableFamily(const MooseVariableFEBase & variable) const
{
return variable.feType().family;
}

inline libMesh::Order
AddVectorTransferAction::getVariableOrder(const MooseVariableFEBase & variable) const
{
return variable.order();
}
21 changes: 8 additions & 13 deletions include/auxkernels/VectorVariableFromComponentsAux.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,13 @@ class VectorVariableFromComponentsAux : public WritableVectorAuxKernel

VectorVariableFromComponentsAux(const InputParameters & parameters);

protected:
virtual void compute() override;

MooseVariable & _component_x;
MooseVariable & _component_y;
MooseVariable & _component_z;
void compute() override;

const Order _vector_order;
const FEFamily _vector_family;

private:
void checkVectorVariable() const;
void checkVectorComponents() const;
void checkVectorComponent(const MooseVariable & component_variable) const;
protected:
/**
* Non-writable references to the component variables.
*/
const MooseVariable & _component_x;
const MooseVariable & _component_y;
const MooseVariable & _component_z;
};
13 changes: 10 additions & 3 deletions include/auxkernels/VectorVariableToComponentsAux.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
#pragma once

#include "VectorVariableFromComponentsAux.h"
#include "WritableVectorAuxKernel.h"

/**
* Set 3 standard variables from a vector variable.
*/
class VectorVariableToComponentsAux : public VectorVariableFromComponentsAux
class VectorVariableToComponentsAux : public WritableVectorAuxKernel
{
public:
static InputParameters validParams();

VectorVariableToComponentsAux(const InputParameters & parameters);

void compute() override;

protected:
virtual void compute() override;
/**
* Writable references to component variables.
*/
MooseVariable & _component_x;
MooseVariable & _component_y;
MooseVariable & _component_z;
};
35 changes: 32 additions & 3 deletions include/auxkernels/WritableVectorAuxKernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,41 @@ class WritableVectorAuxKernel : public VectorAuxKernel
public:
static InputParameters validParams() { return VectorAuxKernel::validParams(); }

WritableVectorAuxKernel(const InputParameters & parameters) : VectorAuxKernel(parameters) {}
WritableVectorAuxKernel(const InputParameters & parameters);

protected:
// NB: not used.
virtual RealVectorValue computeValue() override { mooseError("Unused"); }

// NB: see "writableVariable" method defined in "Coupleable.h".
MooseVariable & writableVariable(const std::string & var_name, unsigned int comp = 0);
const Order _vector_order;
const FEFamily _vector_family;

/**
* This method is based on "writableVariable" defined in "Coupleable.h". Due to a limitation of
* MOOSE it is not possible to call this from a VectorAuxKernel class.
*
* NB: only a single AuxKernel can obtain a writable reference to a variable. This becomes a
* problem for transfers where we need to push and pull the same variable using the auxkernels
* inheriting from this class.
*
* For VectorVariableToComponentsAux, we require writable references.
*/
MooseVariable & getWritableCoupledVariable(const std::string & var_name, unsigned int comp = 0);

/**
* Returns a const-qualified reference to the coupled variable. This is required for
* VectorVariableFromComponentsAux since we don't need to update the values of the component
* variables.
*/
const MooseVariable & getNonWritableCoupledVariable(const std::string & var_name,
unsigned int comp = 0);

/**
* Check component variables are consistent with the vector variable.
*/
void checkVectorVariable() const;
void checkVectorComponent(const MooseVariable & component_variable) const;
void checkVectorComponents(const MooseVariable & component_x,
const MooseVariable & component_y,
const MooseVariable & component_z) const;
};
9 changes: 9 additions & 0 deletions include/base/ApolloVectorTransferFlags.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include "Moose.h"

namespace Apollo
{
extern const ExecFlagType EXEC_PREPARE_VECTOR_FOR_TRANSFER;
extern const ExecFlagType EXEC_RECOVER_VECTOR_POST_TRANSFER;
}
41 changes: 41 additions & 0 deletions include/transfers/MultiAppGeneralVectorTransfer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#pragma once

/**
* Include headers of all MultiApp Transfers we would like.
*/
#include "AuxKernel.h"
#include "AuxiliarySystem.h"

// Forwards declaration.
template <typename MultiAppTransferClassType>
class MultiAppVectorTransferTemplate;

class MultiAppGeneralFieldNearestLocationTransfer;
class MultiAppGeneralFieldShapeEvaluationTransfer;

/**
* Create all transfer types using template here. Don't forget to register them in .C file.
*/
typedef MultiAppVectorTransferTemplate<MultiAppGeneralFieldNearestLocationTransfer>
MultiAppGeneralFieldNearestLocationTransferVector;
typedef MultiAppVectorTransferTemplate<MultiAppGeneralFieldShapeEvaluationTransfer>
MultiAppGeneralFieldShapeEvaluationTransferVector;

template <typename MultiAppTransferClassType>
class MultiAppVectorTransferTemplate : public MultiAppTransferClassType
{
public:
static InputParameters validParams();

MultiAppVectorTransferTemplate(const InputParameters & parameters);

void execute() override final;

protected:
inline AuxiliarySystem & getFromAuxSystem() const { return _from_aux_system; }
inline AuxiliarySystem & getToAuxSystem() const { return _to_aux_system; }

private:
AuxiliarySystem & _from_aux_system;
AuxiliarySystem & _to_aux_system;
};
Loading
Loading