MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
solver.cpp
Go to the documentation of this file.
1// Copyright (C) 2024 The m-AIA AUTHORS
2//
3// This file is part of m-AIA (https://git.rwth-aachen.de/aia/m-AIA/m-AIA)
4//
5// SPDX-License-Identifier: LGPL-3.0-only
6
7#include "solver.h"
8#include "IO/context.h"
9
10using namespace std;
11
12std::map<MInt, MString> Solver::m_aliases;
13
14//---------------------------------------------------------------------------
15//
20Solver::Solver(const MInt solverId, const MPI_Comm comm, const MBool isActive)
21 : m_mpiComm(comm), m_noDim(read_nDim()), m_solverId(solverId) {
22 TRACE();
23
24 if(isActive) {
25 // Determine domainId and number of domains if this solver is active
26 MPI_Comm_rank(mpiComm(), &m_domainId);
27 MPI_Comm_size(mpiComm(), &m_noDomains);
28 } else {
29 m_domainId = -1;
30 m_noDomains = -1;
31 }
32
33 // Find aliases, default is solverId
34 if(Context::solverPropertyExists("solverAlias", solverId)) {
35 MString solverAlias = std::to_string(m_solverId);
36 solverAlias = Context::getSolverProperty<MString>("solverAlias", m_solverId, AT_, &solverAlias);
37 m_aliases[m_solverId] = solverAlias;
38 }
39
40 // Get output and restart directories
41 MString testcaseDir = "./";
42 m_testcaseDir = Context::getSolverProperty<MString>("testcaseDir", m_solverId, AT_, &testcaseDir);
43 m_outputDir = Context::getSolverProperty<MString>("outputDir", m_solverId, AT_, &testcaseDir);
44 m_restartDir = Context::getSolverProperty<MString>("restartDir", m_solverId, AT_, &m_outputDir);
45 m_solutionOutput =
46 Context::getSolverProperty<MString>("solutionOutput", m_solverId, AT_, &m_outputDir); // Naming a la FV
47 // Context::getSolverProperty<MString>("solutionDir", m_solverId, AT_, &m_outputDir); // TODO: unify?
48 m_outputDir = testcaseDir + m_outputDir;
49 m_restartDir = testcaseDir + m_restartDir;
50 m_solutionOutput = testcaseDir + m_solutionOutput;
51
63 m_restartFile = false;
64 m_restartFile = Context::getSolverProperty<MBool>("restartFile", m_solverId, AT_, &m_restartFile);
65
77 m_restart = false;
78 m_restart = Context::getSolverProperty<MBool>("restartFile", m_solverId, AT_, &m_restart);
79
91 m_residualInterval = Context::getSolverProperty<MInt>("residualInterval", m_solverId, AT_);
92
103 m_restartInterval = -1;
104 m_restartInterval = Context::getSolverProperty<MInt>("restartInterval", m_solverId, AT_, &m_restartInterval);
105
106 m_restartOffset = 0;
117 m_restartOffset = Context::getSolverProperty<MInt>("restartOffset", m_solverId, AT_, &m_restartOffset);
118
119 m_useNonSpecifiedRestartFile = false;
120 m_useNonSpecifiedRestartFile =
121 Context::getSolverProperty<MBool>("useNonSpecifiedRestartFile", m_solverId, AT_, &m_useNonSpecifiedRestartFile);
122
134 m_initFromRestartFile = false;
135 m_initFromRestartFile =
136 Context::getSolverProperty<MBool>("initFromRestartFile", m_solverId, AT_, &m_initFromRestartFile);
137
138 if(!m_restart && !m_initFromRestartFile) {
139 m_restartTimeStep = 0;
140 } else {
141 if(!m_useNonSpecifiedRestartFile) {
142 m_restartTimeStep = Context::getSolverProperty<MInt>("restartTimeStep", m_solverId, AT_);
143 } else {
144 m_restartTimeStep = 0;
145 }
146 }
147
148 m_solutionInterval = Context::getSolverProperty<MInt>("solutionInterval", m_solverId, AT_);
149
160 m_solverType = Context::getSolverProperty<MString>("solvertype", m_solverId, AT_);
161
162 MString solverMethod = "defaultMethod";
163 m_solverMethod = Context::getSolverProperty<MString>("solverMethod", m_solverId, AT_, &solverMethod);
164}
165
167MInt Solver::readSolverSamplingVarNames(std::vector<MString>& varNames, const MString featureName) const {
168 MInt noVars = 0;
169 MString propName = "samplingVariables"; // default property
170 if(featureName != ""
171 && Context::propertyExists("samplingVariables" + featureName, m_solverId)) { // feature specific property
172 propName += featureName;
173 }
174
175 if(Context::propertyExists(propName, m_solverId)) {
176 // Number of sampling variables
177 noVars = Context::propertyLength(propName, solverId());
178
179 varNames.clear();
180 for(MInt i = 0; i < noVars; i++) {
181 const MString samplingVarName = Context::getSolverProperty<MString>(propName, solverId(), AT_, i);
182 varNames.push_back(samplingVarName);
183 }
184 }
185 return noVars;
186}
187
188MString Solver::getIdentifier(const MBool useSolverId, const MString preString, const MString postString) {
189 if(Context::solverPropertyExists("solverAlias", m_solverId)) {
190 return preString + m_aliases.at(m_solverId) + postString;
191 } else if(useSolverId) {
192 return preString + std::to_string(m_solverId) + postString;
193 } else {
194 return "";
195 }
196}
static MInt propertyLength(const MString &name, MInt solverId=m_noSolvers)
Returns the number of elements of a property.
Definition: context.cpp:538
static MBool solverPropertyExists(const MString &name, MInt solver)
Checks existence of a solver property details This function returns true, if the solver property with...
Definition: context.cpp:519
static MBool propertyExists(const MString &name, MInt solver=m_noSolvers)
This function checks if a property exists in general.
Definition: context.cpp:494
MInt readSolverSamplingVarNames(std::vector< MString > &varNames, const MString featureName="") const
Read sampling variables names, store in vector and return the number of sampling variables.
Definition: solver.cpp:167
static std::map< MInt, MString > m_aliases
Definition: solver.h:64
MInt solverId() const
Return the solverId.
Definition: solver.h:425
MString getIdentifier(const MBool useSolverId=false, const MString preString="", const MString postString="_")
Definition: solver.cpp:188
const MInt m_solverId
a unique solver identifier
Definition: solver.h:90
Solver(const MInt solverId, const MPI_Comm comm, const MBool isActive=true)
int32_t MInt
Definition: maiatypes.h:62
std::basic_string< char > MString
Definition: maiatypes.h:55
bool MBool
Definition: maiatypes.h:58