Skip to content

Commit fed2f32

Browse files
committed
Adding Kokkos user objects to the problem #30655
1 parent e2e10c3 commit fed2f32

14 files changed

+558
-25
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//* This file is part of the MOOSE framework
2+
//* https://mooseframework.inl.gov
3+
//*
4+
//* All rights reserved, see COPYRIGHT for full restrictions
5+
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6+
//*
7+
//* Licensed under LGPL 2.1, please see LICENSE for details
8+
//* https://www.gnu.org/licenses/lgpl-2.1.html
9+
10+
#pragma once
11+
12+
#include "KokkosObjectAction.h"
13+
14+
/**
15+
* Adds a Kokkos postprocessor
16+
* Associated with the [KokkosPostprocessors] syntax
17+
*/
18+
class AddKokkosPostprocessorAction : public KokkosObjectAction
19+
{
20+
public:
21+
static InputParameters validParams();
22+
23+
AddKokkosPostprocessorAction(const InputParameters & params);
24+
25+
virtual void act() override;
26+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//* This file is part of the MOOSE framework
2+
//* https://mooseframework.inl.gov
3+
//*
4+
//* All rights reserved, see COPYRIGHT for full restrictions
5+
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6+
//*
7+
//* Licensed under LGPL 2.1, please see LICENSE for details
8+
//* https://www.gnu.org/licenses/lgpl-2.1.html
9+
10+
#pragma once
11+
12+
#include "KokkosObjectAction.h"
13+
14+
/**
15+
* Adds a Kokkos reporter
16+
* Associated with the [KokkosReporters] syntax
17+
*/
18+
class AddKokkosReporterAction : public KokkosObjectAction
19+
{
20+
public:
21+
static InputParameters validParams();
22+
23+
AddKokkosReporterAction(const InputParameters & params);
24+
25+
virtual void act() override;
26+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//* This file is part of the MOOSE framework
2+
//* https://mooseframework.inl.gov
3+
//*
4+
//* All rights reserved, see COPYRIGHT for full restrictions
5+
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6+
//*
7+
//* Licensed under LGPL 2.1, please see LICENSE for details
8+
//* https://www.gnu.org/licenses/lgpl-2.1.html
9+
10+
#pragma once
11+
12+
#include "KokkosObjectAction.h"
13+
14+
/**
15+
* Adds a Kokkos user object
16+
* Associated with the [KokkosUserObjects] syntax
17+
*/
18+
class AddKokkosUserObjectAction : public KokkosObjectAction
19+
{
20+
public:
21+
static InputParameters validParams();
22+
23+
AddKokkosUserObjectAction(const InputParameters & params);
24+
25+
virtual void act() override;
26+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//* This file is part of the MOOSE framework
2+
//* https://mooseframework.inl.gov
3+
//*
4+
//* All rights reserved, see COPYRIGHT for full restrictions
5+
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6+
//*
7+
//* Licensed under LGPL 2.1, please see LICENSE for details
8+
//* https://www.gnu.org/licenses/lgpl-2.1.html
9+
10+
#pragma once
11+
12+
#include "KokkosObjectAction.h"
13+
14+
/**
15+
* Adds a Kokkos vector postprocessor
16+
* Associated with the [KokkosVectorPostprocessors] syntax
17+
*/
18+
class AddKokkosVectorPostprocessorAction : public KokkosObjectAction
19+
{
20+
public:
21+
static InputParameters validParams();
22+
23+
AddKokkosVectorPostprocessorAction(const InputParameters & params);
24+
25+
virtual void act() override;
26+
};

framework/include/problems/FEProblemBase.h

Lines changed: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class KernelBase;
9191
class IntegratedBCBase;
9292
class LineSearch;
9393
class UserObject;
94+
class UserObjectBase;
9495
class AutomaticMortarGeneration;
9596
class VectorPostprocessor;
9697
class Convergence;
@@ -108,6 +109,7 @@ namespace Moose::Kokkos
108109
{
109110
class MaterialPropertyStorage;
110111
class Function;
112+
class UserObject;
111113
}
112114
#endif
113115

@@ -1285,6 +1287,18 @@ class FEProblemBase : public SubProblem, public Restartable
12851287
virtual void
12861288
addReporter(const std::string & type, const std::string & name, InputParameters & parameters);
12871289

1290+
#ifdef MOOSE_KOKKOS_ENABLED
1291+
virtual void addKokkosPostprocessor(const std::string & pp_name,
1292+
const std::string & name,
1293+
InputParameters & parameters);
1294+
virtual void addKokkosVectorPostprocessor(const std::string & pp_name,
1295+
const std::string & name,
1296+
InputParameters & parameters);
1297+
virtual void addKokkosReporter(const std::string & type,
1298+
const std::string & name,
1299+
InputParameters & parameters);
1300+
#endif
1301+
12881302
/**
12891303
* Provides const access the ReporterData object.
12901304
*
@@ -1332,6 +1346,7 @@ class FEProblemBase : public SubProblem, public Restartable
13321346
mooseError("Unable to find user object with name '" + name + "'");
13331347
return *(objs[0]);
13341348
}
1349+
13351350
/**
13361351
* Get the user object by its name
13371352
* @param name The name of the user object being retrieved
@@ -1340,20 +1355,59 @@ class FEProblemBase : public SubProblem, public Restartable
13401355
*/
13411356
const UserObject & getUserObjectBase(const std::string & name, const THREAD_ID tid = 0) const;
13421357

1343-
/**
1344-
* Get the Positions object by its name
1345-
* @param name The name of the Positions object being retrieved
1346-
* @return Const reference to the Positions object
1347-
*/
1348-
const Positions & getPositionsObject(const std::string & name) const;
1349-
13501358
/**
13511359
* Check if there if a user object of given name
13521360
* @param name The name of the user object being checked for
13531361
* @return true if the user object exists, false otherwise
13541362
*/
13551363
bool hasUserObject(const std::string & name) const;
13561364

1365+
#ifdef MOOSE_KOKKOS_ENABLED
1366+
virtual void addKokkosUserObject(const std::string & user_object_name,
1367+
const std::string & name,
1368+
InputParameters & parameters);
1369+
1370+
/**
1371+
* Get the Kokkos user object by its name
1372+
* @param name The name of the Kokkos user object being retrieved
1373+
* @return Const reference to the Kokkos user object
1374+
*/
1375+
template <class T>
1376+
T & getKokkosUserObject(const std::string & name) const
1377+
{
1378+
std::vector<T *> objs;
1379+
theWarehouse()
1380+
.query()
1381+
.condition<AttribSystem>("KokkosUserObject")
1382+
.condition<AttribName>(name)
1383+
.queryInto(objs);
1384+
if (objs.empty())
1385+
mooseError("Unable to find Kokkos user object with name '" + name + "'");
1386+
return *(objs[0]);
1387+
}
1388+
1389+
/**
1390+
* Check if there if a Kokkos user object of given name
1391+
* @param name The name of the Kokkos user object being checked for
1392+
* @return true if the Kokkos user object exists, false otherwise
1393+
*/
1394+
bool hasKokkosUserObject(const std::string & name) const;
1395+
#endif
1396+
1397+
/**
1398+
* Check for name collision between different user objects
1399+
* @param name The object name being added
1400+
* @param type The object type being added
1401+
*/
1402+
void checkUserObjectNameCollision(const std::string & name, const std::string & type) const;
1403+
1404+
/**
1405+
* Get the Positions object by its name
1406+
* @param name The name of the Positions object being retrieved
1407+
* @return Const reference to the Positions object
1408+
*/
1409+
const Positions & getPositionsObject(const std::string & name) const;
1410+
13571411
/**
13581412
* Whether or not a Postprocessor value exists by a given name.
13591413
* @param name The name of the Postprocessor
@@ -3043,6 +3097,12 @@ class FEProblemBase : public SubProblem, public Restartable
30433097
const Moose::AuxGroup & group,
30443098
TheWarehouse::Query & query);
30453099

3100+
#ifdef MOOSE_KOKKOS_ENABLED
3101+
void computeKokkosUserObjectsInternal(const ExecFlagType & type,
3102+
const Moose::AuxGroup & group,
3103+
TheWarehouse::Query & query);
3104+
#endif
3105+
30463106
/// Verify that SECOND order mesh uses SECOND order displacements.
30473107
void checkDisplacementOrders();
30483108

@@ -3287,6 +3347,10 @@ class FEProblemBase : public SubProblem, public Restartable
32873347

32883348
void joinAndFinalize(TheWarehouse::Query query, bool isgen = false);
32893349

3350+
#ifdef MOOSE_KOKKOS_ENABLED
3351+
void kokkosJoinAndFinalize(const std::vector<Moose::Kokkos::UserObject *> & userobjs);
3352+
#endif
3353+
32903354
/**
32913355
* Reset state of this object in preparation for the next evaluation.
32923356
*/

framework/src/auxkernels/AuxKernel.C

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ AuxKernelTempl<ComputeValueType>::validParams()
3434
if (typeid(AuxKernelTempl<ComputeValueType>).name() == typeid(ArrayAuxKernel).name())
3535
params.registerBase("ArrayAuxKernel");
3636

37+
params.registerSystemAttributeName("AuxKernel");
38+
3739
return params;
3840
}
3941

framework/src/auxkernels/AuxKernelBase.C

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ AuxKernelBase::validParams()
6060
Moose::RelationshipManagerType::ALGEBRAIC);
6161

6262
params.declareControllable("enable"); // allows Control to enable/disable this type of object
63-
params.registerSystemAttributeName("AuxKernel");
6463

6564
return params;
6665
}

framework/src/base/Moose.C

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ addActionTypes(Syntax & syntax)
203203
registerMooseObjectTask("add_mesh_division", MeshDivision, false);
204204
registerMooseObjectTask("add_user_object", UserObject, false);
205205
appendMooseObjectTask ("add_user_object", Postprocessor);
206+
#ifdef MOOSE_KOKKOS_ENABLED
207+
appendMooseObjectTask("add_user_object", KokkosUserObject);
208+
appendMooseObjectTask("add_user_object", KokkosPostprocessor);
209+
#endif
206210
appendDeprecatedMooseObjectTask("add_user_object", Corrector);
207211
registerMooseObjectTask("add_corrector", Corrector, false);
208212
appendDeprecatedMooseObjectTask("add_user_object", MeshModifier);
@@ -211,6 +215,11 @@ addActionTypes(Syntax & syntax)
211215
registerMooseObjectTask("add_postprocessor", Postprocessor, false);
212216
registerMooseObjectTask("add_vector_postprocessor", VectorPostprocessor, false);
213217
registerMooseObjectTask("add_reporter", Reporter, false);
218+
#ifdef MOOSE_KOKKOS_ENABLED
219+
appendMooseObjectTask("add_postprocessor", KokkosPostprocessor);
220+
appendMooseObjectTask("add_vector_postprocessor", KokkosVectorPostprocessor);
221+
appendMooseObjectTask("add_reporter", KokkosReporter);
222+
#endif
214223
registerMooseObjectTask("add_positions", Positions, false);
215224
registerMooseObjectTask("add_times", Times, false);
216225

@@ -652,6 +661,18 @@ associateSyntaxInner(Syntax & syntax, ActionFactory & /*action_factory*/)
652661
registerSyntax("AddReporterAction", "Reporters/*");
653662
syntax.registerSyntaxType("Reporters/*", "ReporterName");
654663

664+
#ifdef MOOSE_KOKKOS_ENABLED
665+
registerSyntax("AddKokkosPostprocessorAction", "KokkosPostprocessors/*");
666+
syntax.registerSyntaxType("KokkosPostprocessors/*", "PostprocessorName");
667+
syntax.registerSyntaxType("KokkosPostprocessors/*", "UserObjectName");
668+
669+
registerSyntax("AddKokkosVectorPostprocessorAction", "KokkosVectorPostprocessors/*");
670+
syntax.registerSyntaxType("KokkosVectorPostprocessors/*", "VectorPostprocessorName");
671+
672+
registerSyntax("AddKokkosReporterAction", "KokkosReporters/*");
673+
syntax.registerSyntaxType("KokkosReporters/*", "ReporterName");
674+
#endif
675+
655676
registerSyntax("AddPositionsAction", "Positions/*");
656677
syntax.registerSyntaxType("Positions/*", "PositionsName");
657678

@@ -714,8 +735,15 @@ associateSyntaxInner(Syntax & syntax, ActionFactory & /*action_factory*/)
714735
// UserObject and some derived classes
715736
registerSyntax("AddUserObjectAction", "UserObjects/*");
716737
syntax.registerSyntaxType("UserObjects/*", "UserObjectName");
738+
739+
#ifdef MOOSE_KOKKOS_ENABLED
740+
registerSyntax("AddKokkosUserObjectAction", "KokkosUserObjects/*");
741+
syntax.registerSyntaxType("KokkosUserObjects/*", "UserObjectName");
742+
#endif
743+
717744
registerSyntax("AddCorrectorAction", "Correctors/*");
718745
syntax.registerSyntaxType("Correctors/*", "UserObjectName");
746+
719747
registerSyntax("AddMeshModifiersAction", "MeshModifiers/*");
720748
syntax.registerSyntaxType("MeshModifiers/*", "UserObjectName");
721749

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//* This file is part of the MOOSE framework
2+
//* https://mooseframework.inl.gov
3+
//*
4+
//* All rights reserved, see COPYRIGHT for full restrictions
5+
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6+
//*
7+
//* Licensed under LGPL 2.1, please see LICENSE for details
8+
//* https://www.gnu.org/licenses/lgpl-2.1.html
9+
10+
#include "AddKokkosPostprocessorAction.h"
11+
#include "FEProblem.h"
12+
13+
registerMooseAction("MooseApp", AddKokkosPostprocessorAction, "add_postprocessor");
14+
15+
InputParameters
16+
AddKokkosPostprocessorAction::validParams()
17+
{
18+
InputParameters params = KokkosObjectAction::validParams();
19+
params.addClassDescription("Add a Kokkos Postprocessor object to the simulation.");
20+
return params;
21+
}
22+
23+
AddKokkosPostprocessorAction::AddKokkosPostprocessorAction(const InputParameters & params)
24+
: KokkosObjectAction(params, "Postprocessor")
25+
{
26+
}
27+
28+
void
29+
AddKokkosPostprocessorAction::act()
30+
{
31+
_problem->addKokkosPostprocessor(_type, _name, _moose_object_pars);
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//* This file is part of the MOOSE framework
2+
//* https://mooseframework.inl.gov
3+
//*
4+
//* All rights reserved, see COPYRIGHT for full restrictions
5+
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6+
//*
7+
//* Licensed under LGPL 2.1, please see LICENSE for details
8+
//* https://www.gnu.org/licenses/lgpl-2.1.html
9+
10+
#include "AddKokkosReporterAction.h"
11+
#include "FEProblem.h"
12+
13+
registerMooseAction("MooseApp", AddKokkosReporterAction, "add_postprocessor");
14+
15+
InputParameters
16+
AddKokkosReporterAction::validParams()
17+
{
18+
InputParameters params = KokkosObjectAction::validParams();
19+
params.addClassDescription("Add a Kokkos Postprocessor object to the simulation.");
20+
return params;
21+
}
22+
23+
AddKokkosReporterAction::AddKokkosReporterAction(const InputParameters & params)
24+
: KokkosObjectAction(params, "Reporter")
25+
{
26+
}
27+
28+
void
29+
AddKokkosReporterAction::act()
30+
{
31+
_problem->addKokkosReporter(_type, _name, _moose_object_pars);
32+
}

0 commit comments

Comments
 (0)